Example usage for java.lang StringBuilder delete

List of usage examples for java.lang StringBuilder delete

Introduction

In this page you can find the example usage for java.lang StringBuilder delete.

Prototype

@Override
public StringBuilder delete(int start, int end) 

Source Link

Usage

From source file:cn.jcenterhome.web.action.CpAction.java

private boolean getParametersParseKey(StringBuilder operatingKey, Map<String, Object> supMap, String[] value,
        boolean isCheckBox) {
    int tempI = operatingKey.indexOf("[");
    int tempII = operatingKey.indexOf("]");
    if (tempI < 0) {
        putValue(supMap, operatingKey.toString(), value, isCheckBox);
        return true;
    } else if (tempII < tempI) {
        return false;
    }//from  www.ja v a  2s.co  m
    String subKey = operatingKey.substring(0, tempI);
    Map<String, Object> subMap = (Map<String, Object>) supMap.get(subKey);
    if (subMap == null) {
        subMap = new HashMap<String, Object>();
        supMap.put(subKey, subMap);
    }
    operatingKey.deleteCharAt(tempII);
    operatingKey.delete(0, tempI + 1);
    return getParametersParseKey(operatingKey, subMap, value, isCheckBox);
}

From source file:com.tmwsoft.sns.web.action.MainAction.java

public ActionForward cp_magic(HttpServletRequest request, HttpServletResponse response) {
    Map<String, Object> sGlobal = (Map<String, Object>) request.getAttribute("sGlobal");
    Map<String, Object> sConfig = (Map<String, Object>) request.getAttribute("sConfig");
    Map<Integer, String> sNames = (Map<Integer, String>) request.getAttribute("sNames");
    String op = request.getParameter("op");
    op = Common.empty(op) ? "view" : op;
    String mid = Common.trim(request.getParameter("mid"));
    int supe_uid = (Integer) sGlobal.get("supe_uid");
    int timestamp = (Integer) sGlobal.get("timestamp");
    Map<String, Object> space = Common.getSpace(request, sGlobal, sConfig, supe_uid);
    if (!Common.checkPerm(request, response, "allowmagic")) {
        MessageVO msgVO = Common.ckSpaceLog(request);
        if (msgVO != null) {
            return showMessage(request, response, msgVO);
        }/*from www .  j ava2  s  . c  om*/
        return showMessage(request, response, "magic_groupid_not_allowed");
    }
    Map<String, Object> magic = null;
    if (!mid.equals("")) {
        Object result = propsService.magic_get(mid);
        if (result instanceof MessageVO) {
            return showMessage(request, response, (MessageVO) result);
        }
        magic = (Map<String, Object>) result;
    }
    boolean sc_buysubmit = false;
    boolean sc_presentsubmit = false;
    try {
        sc_buysubmit = submitCheck(request, "buysubmit");
        if (!sc_buysubmit) {
            sc_presentsubmit = submitCheck(request, "presentsubmit");
        }
    } catch (Exception e) {
        return showMessage(request, response, e.getMessage());
    }
    if (sc_buysubmit) {
        if (mid.equals("")) {
            return showMessage(request, response, "unknown_magic");
        }
        Object result = propsService.magic_buy_get(request, response, magic, sGlobal, space);
        if (result instanceof MessageVO) {
            return showMessage(request, response, (MessageVO) result);
        }
        Map<String, Object> datas = (Map<String, Object>) result;
        Map<String, Object> magicstore = (Map<String, Object>) datas.get("magicstore");
        Map<String, Object> coupon = (Map<String, Object>) datas.get("coupon");
        result = propsService.magic_buy_post(request, response, sGlobal, space, magic, magicstore, coupon);
        if (result instanceof MessageVO) {
            return showMessage(request, response, (MessageVO) result);
        }
        int charge = (Integer) result;
        if ((Integer) magic.get("experience") != 0) {
            String buynumS = request.getParameter("buynum");
            int buynum = buynumS != null ? Common.intval(buynumS.trim()) : 0;
            return showMessage(request, response, "magicbuy_success_with_experence",
                    request.getParameter("refer"), 0, charge + "",
                    ((Integer) magic.get("experience") * buynum) + "");
        } else {
            return showMessage(request, response, "magicbuy_success", request.getParameter("refer"), 0,
                    charge + "");
        }
    } else if (sc_presentsubmit) {
        if (mid.equals("")) {
            return showMessage(request, response, "unknown_magic");
        }
        if (mid.equals("license")) {
            return showMessage(request, response, "magic_can_not_be_presented");
        }
        String fusername = request.getParameter("fusername");
        fusername = fusername == null ? fusername : fusername.trim();
        if (Common.empty(fusername)) {
            return showMessage(request, response, "bad_friend_username_given");
        }
        try {
            fusername = Common.getStr(fusername, 15, false, false, false, 0, 0, request, response);
        } catch (Exception e) {
            e.printStackTrace();
            return showMessage(request, response, e.getMessage());
        }
        List<Map<String, Object>> query = dataBaseService.executeQuery(
                "SELECT * FROM sns_friend WHERE uid = '" + supe_uid + "' AND fusername='" + fusername + "'");
        Map<String, Object> value = query.size() > 0 ? query.get(0) : null;
        if (value == null) {
            return showMessage(request, response, "bad_friend_username_given");
        }
        int fuid = (Integer) value.get("fuid");
        Map<String, Map<String, Object>> usermagics = new HashMap<String, Map<String, Object>>();
        query = dataBaseService.executeQuery("SELECT * FROM sns_usermagic WHERE uid='" + supe_uid
                + "' AND mid IN('license', '" + mid + "')");
        for (Map<String, Object> value_ : query) {
            usermagics.put((String) value_.get("mid"), value_);
        }
        Map<String, Object> tempMap = usermagics.get("license");
        if (tempMap == null || (Integer) tempMap.get("count") == 0) {
            return showMessage(request, response, "has_no_more_present_magic");
        }
        tempMap = usermagics.get(mid);
        if (tempMap == null || (Integer) tempMap.get("count") == 0) {
            return showMessage(request, response, "has_no_more_magic", null, 0, (String) magic.get("name"),
                    "a_buy_" + mid, "main.action?ac=magic&op=buy&mid=" + mid);
        }
        dataBaseService.execute("UPDATE sns_usermagic SET count = count - 1 WHERE uid = '" + supe_uid
                + "' AND mid IN ('license', '" + mid + "')");
        query = dataBaseService
                .executeQuery("SELECT * FROM sns_usermagic WHERE uid='" + fuid + "' AND mid='" + mid + "'");
        value = query.size() > 0 ? query.get(0) : null;
        int count = value != null ? (Integer) value.get("count") + 1 : 1;
        Map<String, Object> insertData = new HashMap<String, Object>();
        insertData.put("uid", fuid);
        insertData.put("username", fusername);
        insertData.put("mid", mid);
        insertData.put("count", count);
        dataBaseService.insertTable("sns_usermagic", insertData, false, true);
        insertData.clear();
        insertData.put("uid", fuid);
        insertData.put("username", fusername);
        insertData.put("mid", mid);
        insertData.put("count", 1);
        insertData.put("type", 2);
        insertData.put("fromid", supe_uid);
        insertData.put("credit", 0);
        insertData.put("dateline", timestamp);
        dataBaseService.insertTable("sns_magicinlog", insertData, false, false);
        String note = Common.getMessage(request, "cp_magic_present_note", (String) magic.get("name"),
                "main.action?ac=magic&view=me&mid=" + mid);
        note = note == null ? "magic_present_note" : note;
        mainService.addNotification(request, sGlobal, sConfig, fuid, "magic", note, false);
        return showMessage(request, response, "magicpresent_success", request.getParameter("refer"), 0,
                fusername);
    }
    if ("buy".equals(op)) {
        Object result = propsService.magic_buy_get(request, response, magic, sGlobal, space);
        if (result instanceof MessageVO) {
            return showMessage(request, response, (MessageVO) result);
        }
        Map<String, Object> datas = (Map<String, Object>) result;
        Map<String, Object> magicstore = (Map<String, Object>) datas.get("magicstore");
        Map<String, Object> coupon = (Map<String, Object>) datas.get("coupon");
        request.setAttribute("mid", mid);
        request.setAttribute("magicstore", magicstore);
        request.setAttribute("coupon", coupon);
        request.setAttribute("discount", datas.get("discount"));
        request.setAttribute("charge", datas.get("charge"));
        String ac = request.getParameter("ac");
        request.setAttribute("ac", ac != null ? ac.trim() : "");
        request.setAttribute("magic", magic);
    } else if ("present".equals(op)) {
        if (mid.equals("license")) {
            return showMessage(request, response, "magic_can_not_be_presented");
        }
        Map<String, Map<String, Object>> usermagics = new HashMap<String, Map<String, Object>>();
        List<Map<String, Object>> query = dataBaseService.executeQuery("SELECT * FROM sns_usermagic WHERE uid='"
                + supe_uid + "' AND mid IN('license', '" + mid + "')");
        for (Map<String, Object> value : query) {
            usermagics.put((String) value.get("mid"), value);
        }
        Map<String, Object> tempMap = usermagics.get("license");
        if (tempMap == null || (Integer) tempMap.get("count") == 0) {
            return showMessage(request, response, "has_no_more_present_magic");
        }
        tempMap = usermagics.get(mid);
        if (tempMap == null || (Integer) tempMap.get("count") == 0) {
            return showMessage(request, response, "has_no_more_magic", null, 0, (String) magic.get("name"),
                    "a_buy_" + mid, "main.action?ac=magic&op=buy&mid=" + mid);
        }
        request.setAttribute("mid", mid);
        request.setAttribute("magic", magic);
    } else if ("showusage".equals(op)) {
        if (mid.equals("")) {
            return showMessage(request, response, "unknown_magic");
        }
        request.setAttribute("mid", mid);
    } else if ("receive".equals(op)) {
        String uidS = request.getParameter("uid");
        int uid = uidS != null ? Common.intval(uidS.trim()) : 0;
        List<Map<String, Object>> query = dataBaseService
                .executeQuery("SELECT * FROM sns_magicuselog WHERE uid='" + uid + "' AND mid='gift' LIMIT 1");
        Map<String, Object> value = query.size() > 0 ? query.get(0) : null;
        String value_data;
        if (value != null && (value_data = (String) value.get("data")) != null && !value_data.equals("")) {
            Map<String, Object> data = Serializer.unserialize(value_data, false);
            if ((Integer) data.get("left") <= 0) {
                return showMessage(request, response, "magic_gift_already_given_out");
            }
            Map<Integer, Integer> receiver = (Map<Integer, Integer>) data.get("receiver");
            if (receiver == null) {
                receiver = new HashMap<Integer, Integer>();
                data.put("receiver", receiver);
            }
            int receiverIndex = 0;
            for (Entry<Integer, Integer> entry : receiver.entrySet()) {
                if (entry.getValue() == supe_uid) {
                    return showMessage(request, response, "magic_had_got_gift");
                }
                receiverIndex = Math.max(receiverIndex, entry.getKey());
            }
            int data_left = (Integer) data.get("left");
            int data_chunk = (Integer) data.get("chunk");
            int credit = Math.min(data_chunk, data_left);
            receiver.put(++receiverIndex, supe_uid);
            data_left = data_left - credit;
            data.put("left", data_left);
            if (data_left > 0) {
                Map<String, Object> setData = new HashMap<String, Object>();
                setData.put("data", Serializer.serialize(data));
                Map<String, Object> whereData = new HashMap<String, Object>();
                whereData.put("logid", value.get("logid"));
                dataBaseService.updateTable("sns_magicuselog", setData, whereData);
            } else {
                dataBaseService
                        .execute("DELETE FROM sns_magicuselog WHERE logid = '" + value.get("logid") + "'");
            }
            dataBaseService.execute(
                    "UPDATE sns_space SET credit = credit + '" + credit + "' WHERE uid='" + supe_uid + "'");
            return showMessage(request, response, "magic_got_gift", null, 0, credit + "");
        } else {
            return showMessage(request, response, "magic_has_no_gift");
        }
    } else if ("appear".equals(op)) {
        Map<String, Object> session_member = (Map<String, Object>) sGlobal.get("session");
        if (session_member == null || (Integer) session_member.get("magichidden") == 0) {
            return showMessage(request, response, "magic_not_hidden_yet");
        }
        boolean scb = false;
        try {
            scb = submitCheck(request, "appearsubmit");
        } catch (Exception e) {
            e.printStackTrace();
            return showMessage(request, response, e.getMessage());
        }
        if (scb) {
            Map<String, Object> setData = new HashMap<String, Object>();
            Map<String, Object> whereData = new HashMap<String, Object>();
            setData.put("magichidden", "0");
            whereData.put("uid", supe_uid);
            dataBaseService.updateTable("sns_session", setData, whereData);
            setData.clear();
            setData.put("expire", timestamp);
            whereData.put("mid", "invisible");
            dataBaseService.updateTable("sns_magicuselog", setData, whereData);
            return showMessage(request, response, "do_success", request.getParameter("refer"), 0);
        }
    } else if ("retrieve".equals(op)) {
        List<Map<String, Object>> query = dataBaseService
                .executeQuery("SELECT * FROM sns_magicuselog WHERE uid = '" + supe_uid + "' AND mid = 'gift'");
        Map<String, Object> value = query.size() > 0 ? query.get(0) : null;
        int leftcredit = 0;
        String dataS = null;
        if (value == null) {
            return showMessage(request, response, "not_set_gift");
        } else if ((dataS = (String) value.get("data")) != null && !dataS.equals("")) {
            Map<String, Object> data = Serializer.unserialize(dataS, false);
            leftcredit = (Integer) data.get("left");
        }
        boolean scb = false;
        try {
            scb = submitCheck(request, "retrievesubmit");
        } catch (Exception e) {
            e.printStackTrace();
            return showMessage(request, response, e.getMessage());
        }
        if (scb) {
            dataBaseService
                    .execute("DELETE FROM sns_magicuselog WHERE uid = '" + supe_uid + "' AND mid = 'gift'");
            dataBaseService.execute(
                    "UPDATE sns_space SET credit = credit + " + leftcredit + " WHERE uid = '" + supe_uid + "'");
            return showMessage(request, response, "do_success", request.getParameter("refer"), 0);
        }
        request.setAttribute("leftcredit", leftcredit);
    } else if ("cancelsuperstar".equals(op)) {
        mid = "superstar";
        List<Map<String, Object>> query = dataBaseService
                .executeQuery("SELECT * FROM sns_spacefield WHERE uid = '" + supe_uid + "'");
        Map<String, Object> value = query.size() > 0 ? query.get(0) : null;
        Integer magicstar;
        if (value == null || (magicstar = (Integer) value.get("magicstar")) == null || magicstar == 0) {
            return showMessage(request, response, "not_superstar_yet");
        }
        boolean scb = false;
        try {
            scb = submitCheck(request, "cancelsubmit");
        } catch (Exception e) {
            e.printStackTrace();
            return showMessage(request, response, e.getMessage());
        }
        if (scb) {
            Map<String, Object> setData = new HashMap<String, Object>();
            Map<String, Object> whereData = new HashMap<String, Object>();
            setData.put("magicstar", 0);
            whereData.put("uid", supe_uid);
            dataBaseService.updateTable("sns_spacefield", setData, whereData);
            setData.clear();
            setData.put("expire", timestamp);
            whereData.put("mid", "superstar");
            dataBaseService.updateTable("sns_magicuselog", setData, whereData);
            return showMessage(request, response, "do_success", request.getParameter("refer"), 0);
        }
    } else if ("cancelflicker".equals(op)) {
        mid = "flicker";
        String idtype = "cid";
        String idS = request.getParameter("id");
        int id = idS != null ? Common.intval(idS.trim()) : 0;
        List<Map<String, Object>> query = dataBaseService.executeQuery(
                "SELECT * FROM sns_comment WHERE cid = '" + id + "' AND authorid = '" + supe_uid + "'");
        Map<String, Object> value = query.size() > 0 ? query.get(0) : null;
        Integer magicflicker;
        if (value == null || (magicflicker = (Integer) value.get("magicflicker")) == null
                || magicflicker == 0) {
            return showMessage(request, response, "no_flicker_yet");
        }
        boolean scb = false;
        try {
            scb = submitCheck(request, "cancelsubmit");
        } catch (Exception e) {
            e.printStackTrace();
            return showMessage(request, response, e.getMessage());
        }
        if (scb) {
            Map<String, Object> setData = new HashMap<String, Object>();
            setData.put("magicflicker", 0);
            Map<String, Object> whereData = new HashMap<String, Object>();
            whereData.put("cid", id);
            whereData.put("authorid", supe_uid);
            dataBaseService.updateTable("sns_comment", setData, whereData);
            return showMessage(request, response, "do_success", request.getParameter("refer"), 0);
        }
        request.setAttribute("id", id);
        request.setAttribute("idtype", idtype);
        request.setAttribute("mid", mid);
    } else if ("cancelcolor".equals(op)) {
        mid = "color";
        String idS = request.getParameter("id");
        int id = idS != null ? Common.intval(idS.trim()) : 0;
        String idtype = request.getParameter("idtype");
        if (idtype == null) {
            return showMessage(request, response, "access error : 00001");
        }
        idtype = idtype.trim();
        Map<String, String> mapping = new HashMap<String, String>();
        mapping.put("blogid", "sns_blogfield");
        mapping.put("tid", "sns_thread");
        String tablename = mapping.get(idtype);
        if (Common.empty(tablename)) {
            return showMessage(request, response, "no_color_yet");
        }
        List<Map<String, Object>> query = dataBaseService.executeQuery("SELECT * FROM " + tablename + " WHERE "
                + idtype + " = '" + id + "' AND uid = '" + supe_uid + "'");
        Map<String, Object> value = query.size() > 0 ? query.get(0) : null;
        Integer magiccolor;
        if (value == null || (magiccolor = (Integer) value.get("magiccolor")) == null || magiccolor == 0) {
            return showMessage(request, response, "no_color_yet");
        }
        boolean scb = false;
        try {
            scb = submitCheck(request, "cancelsubmit");
        } catch (Exception e) {
            e.printStackTrace();
            return showMessage(request, response, e.getMessage());
        }
        if (scb) {
            Map<String, Object> setData = new HashMap<String, Object>();
            setData.put("magiccolor", 0);
            Map<String, Object> whereData = new HashMap<String, Object>();
            whereData.put(idtype, id);
            dataBaseService.updateTable(tablename, setData, whereData);
            query = dataBaseService.executeQuery(
                    "SELECT * FROM sns_feed WHERE id = '" + id + "' AND idtype = '" + idtype + "'");
            Map<String, Object> feed = query.size() > 0 ? query.get(0) : null;
            if (feed != null) {
                String body_data = (String) feed.get("body_data");
                Map body_data_subMap = Serializer.unserialize(body_data, false);
                body_data_subMap.remove("magic_color");
                body_data = Serializer.serialize(body_data_subMap);
                setData.clear();
                whereData.clear();
                setData.put("body_data", body_data);
                whereData.put("feedid", feed.get("feedid"));
                dataBaseService.updateTable("sns_feed", setData, whereData);
            }
            return showMessage(request, response, "do_success", request.getParameter("refer"), 0);
        }
        request.setAttribute("id", id);
        request.setAttribute("idtype", idtype);
        request.setAttribute("mid", mid);
    } else if ("cancelframe".equals(op)) {
        mid = "frame";
        String idtype = "picid";
        String idS = request.getParameter("id");
        int id = idS != null ? Common.intval(idS.trim()) : 0;
        List<Map<String, Object>> query = dataBaseService
                .executeQuery("SELECT * FROM sns_pic WHERE picid = '" + id + "' AND uid = '" + supe_uid + "'");
        Map<String, Object> value = query.size() > 0 ? query.get(0) : null;
        Integer magicframe;
        if (value == null || (magicframe = (Integer) value.get("magicframe")) == null || magicframe == 0) {
            return showMessage(request, response, "no_frame_yet");
        }
        boolean scb = false;
        try {
            scb = submitCheck(request, "cancelsubmit");
        } catch (Exception e) {
            e.printStackTrace();
            return showMessage(request, response, e.getMessage());
        }
        if (scb) {
            Map<String, Object> setData = new HashMap<String, Object>();
            setData.put("magicframe", 0);
            Map<String, Object> whereData = new HashMap<String, Object>();
            whereData.put("picid", id);
            dataBaseService.updateTable("sns_pic", setData, whereData);
            return showMessage(request, response, "do_success", request.getParameter("refer"), 0);
        }
        request.setAttribute("id", id);
        request.setAttribute("idtype", idtype);
        request.setAttribute("mid", mid);
    } else if ("cancelbgimage".equals(op)) {
        mid = "bgimage";
        String idtype = "blogid";
        String idS = request.getParameter("id");
        int id = idS != null ? Common.intval(idS.trim()) : 0;
        List<Map<String, Object>> query = dataBaseService.executeQuery(
                "SELECT * FROM sns_blogfield WHERE blogid = '" + id + "' AND uid = '" + supe_uid + "'");
        Map<String, Object> value = query.size() > 0 ? query.get(0) : null;
        Integer magicpaper;
        if (value == null || (magicpaper = (Integer) value.get("magicpaper")) == null || magicpaper == 0) {
            return showMessage(request, response, "no_bgimage_yet");
        }
        boolean scb = false;
        try {
            scb = submitCheck(request, "cancelsubmit");
        } catch (Exception e) {
            e.printStackTrace();
            return showMessage(request, response, e.getMessage());
        }
        if (scb) {
            Map<String, Object> setData = new HashMap<String, Object>();
            setData.put("magicpaper", 0);
            Map<String, Object> whereData = new HashMap<String, Object>();
            whereData.put("blogid", id);
            dataBaseService.updateTable("sns_blogfield", setData, whereData);
            return showMessage(request, response, "do_success", request.getParameter("refer"), 0);
        }
        request.setAttribute("id", id);
        request.setAttribute("idtype", idtype);
        request.setAttribute("mid", mid);
    } else {
        String view = request.getParameter("view");
        if (view != null) {
            view = view.trim();
        }
        if ("me".equals(view)) {
            Map<String, String> types = new HashMap<String, String>();
            types.put("list", " class=\"active\"");
            request.setAttribute("types", types);
            Map<String, Map<String, Object>> list = null;
            StringBuilder ids = new StringBuilder();
            Map<String, Map<String, Object>> magics = new HashMap<String, Map<String, Object>>();
            List<Map<String, Object>> query = null;
            if (!mid.equals("")) {
                magics.put(mid, magic);
                ids.append("'");
                ids.append(mid);
                ids.append("'");
            } else {
                query = dataBaseService.executeQuery("SELECT * FROM sns_magic WHERE close = '0'");
                String tempS;
                Pattern pattern = Pattern.compile(",");
                boolean existMid = false;
                for (Map<String, Object> value : query) {
                    tempS = (String) value.get("forbiddengid");
                    if (tempS != null) {
                        value.put("forbiddengid", pattern.split(tempS));
                    } else {
                        value.put("forbiddengid", new String[0]);
                    }
                    tempS = (String) value.get("mid");
                    magics.put(tempS, value);
                    if (existMid) {
                        ids.append(",");
                    } else {
                        existMid = true;
                    }
                    ids.append("'");
                    ids.append(tempS);
                    ids.append("'");
                }
            }
            query = dataBaseService.executeQuery("SELECT * FROM sns_usermagic WHERE uid='" + supe_uid
                    + "' AND mid IN (" + ids.toString() + ") AND count > 0");
            if (query.size() > 0) {
                list = new LinkedHashMap<String, Map<String, Object>>();
                for (Map<String, Object> value : query) {
                    list.put((String) value.get("mid"), value);
                }
            }
            request.setAttribute("list", list);
            request.setAttribute("magics", magics);
            request.setAttribute("mid", mid);
        } else if ("log".equals(view)) {
            String type = request.getParameter("type");
            type = type != null
                    && ((type = type.trim()).equals("in") || type.equals("out") || type.equals("present"))
                            ? type
                            : "in";
            request.setAttribute("gType", type);
            Map<String, String> types = new HashMap<String, String>();
            types.put(type, " class=\"active\"");
            request.setAttribute("types", types);
            int perpage = 20;
            String pageGet = request.getParameter("page");
            int page = Common.empty(pageGet) ? 0 : Common.intval(pageGet);
            if (page < 1)
                page = 1;
            int start = (page - 1) * perpage;
            int maxPage = (Integer) sConfig.get("maxpage");
            String result = Common.ckStart(start, perpage, maxPage);
            if (result != null) {
                return showMessage(request, response, result);
            }
            List<Map<String, Object>> list = null;
            List<Map<String, Object>> query = null;
            int count = 0;
            if ("in".equals(type)) {
                List<Integer> uids = null;
                query = dataBaseService.executeQuery(
                        "SELECT COUNT(*) AS cont FROM sns_magicinlog WHERE uid = '" + supe_uid + "'");
                count = query.size() > 0 ? (Integer) query.get(0).get("cont") : 0;
                if (count != 0) {
                    query = dataBaseService.executeQuery("SELECT * FROM sns_magicinlog WHERE uid = '" + supe_uid
                            + "' ORDER BY dateline DESC LIMIT " + start + ", " + perpage);
                    list = query.size() > 0 ? query : null;
                    uids = new ArrayList<Integer>();
                    for (Map<String, Object> value : query) {
                        value.put("dateline",
                                Common.sgmdate(request, "MM-dd HH:mm", (Integer) value.get("dateline"), true));
                        if ((Integer) value.get("type") == 2) {
                            uids.add((Integer) value.get("fromid"));
                        }
                    }
                }
                if (uids != null && uids.size() > 0) {
                    query = dataBaseService.executeQuery(
                            "SELECT * FROM sns_member WHERE uid IN (" + Common.sImplode(uids) + ")");
                }
            } else if ("present".equals(type)) {
                query = dataBaseService.executeQuery(
                        "SELECT COUNT(*) AS cont FROM sns_magicinlog WHERE type = 2 AND fromid = '" + supe_uid
                                + "'");
                count = query.size() > 0 ? (Integer) query.get(0).get("cont") : 0;
                if (count != 0) {
                    query = dataBaseService
                            .executeQuery("SELECT * FROM sns_magicinlog WHERE type = 2 AND fromid = '"
                                    + supe_uid + "' ORDER BY dateline DESC LIMIT " + start + ", " + perpage);
                    list = query.size() > 0 ? query : null;
                    for (Map<String, Object> value : query) {
                        value.put("dateline",
                                Common.sgmdate(request, "MM-dd HH:mm", (Integer) value.get("dateline"), true));
                    }
                }
            } else {
                query = dataBaseService.executeQuery(
                        "SELECT COUNT(*) AS cont FROM sns_magicuselog WHERE uid = '" + supe_uid + "'");
                count = query.size() > 0 ? (Integer) query.get(0).get("cont") : 0;
                if (count != 0) {
                    query = dataBaseService.executeQuery("SELECT * FROM sns_magicuselog WHERE uid = '"
                            + supe_uid + "' ORDER BY dateline DESC LIMIT " + start + ", " + perpage);
                    list = query.size() > 0 ? query : null;
                    for (Map<String, Object> value : query) {
                        value.put("dateline",
                                Common.sgmdate(request, "MM-dd HH:mm", (Integer) value.get("dateline"), true));
                        value.put("data", Serializer.unserialize((String) value.get("data"), false));
                        value.put("expire",
                                Common.sgmdate(request, "MM-dd HH:mm", (Integer) value.get("expire"), false));
                    }
                }
            }
            String theurl = "main.action?ac=magic&view=log&type=" + type;
            String multi = Common.multi(request, count, perpage, page, maxPage, theurl, "", "");
            request.setAttribute("multi", multi);
            request.setAttribute("list", list);
        } else {
            view = "store";
            String order = request.getParameter("order");
            if (order != null) {
                order = order.trim();
            }
            order = "hot".equals(order) ? order : "default";
            Map<String, String> orders = new HashMap<String, String>();
            orders.put(order, " class=\"active\"");
            request.setAttribute("orders", orders);
            List<Map<String, Object>> query;
            Map<String, Map<String, Object>> magics = new HashMap<String, Map<String, Object>>();
            List<String> ids = null;
            Map<String, Map<String, Object>> list = new LinkedHashMap<String, Map<String, Object>>();
            String[] blacklist = { "coupon" };
            if (!mid.equals("")) {
                magics.put(mid, magic);
                ids = new ArrayList<String>(1);
                ids.add(mid);
            } else {
                String orderby = order.equals("hot") ? "" : " ORDER BY displayorder";
                query = dataBaseService.executeQuery("SELECT * FROM sns_magic" + orderby);
                String tempS;
                Pattern pattern = Pattern.compile(",");
                ids = new ArrayList<String>(query.size());
                for (Map<String, Object> value : query) {
                    if ((Integer) value.get("close") == 1 || Common.in_array(blacklist, value.get("mid"))) {
                        continue;
                    }
                    tempS = (String) value.get("forbiddengid");
                    if (tempS != null) {
                        value.put("forbiddengid", pattern.split(tempS));
                    } else {
                        value.put("forbiddengid", new String[0]);
                    }
                    tempS = (String) value.get("mid");
                    magics.put(tempS, value);
                    ids.add(tempS);
                }
            }
            if (Common.empty(magics)) {
                return showMessage(request, response, "magic_store_is_closed");
            }
            String orderby = order.equals("hot") ? " ORDER BY sellcount DESC" : "";
            query = dataBaseService.executeQuery(
                    "SELECT * FROM sns_magicstore WHERE mid IN (" + Common.sImplode(ids) + ")" + orderby);
            String[] oldids = new String[query.size()];
            int ti = 0;
            int providecount;
            String ts;
            for (Map<String, Object> value : query) {
                ts = (String) value.get("mid");
                list.put(ts, value);
                oldids[ti++] = ts;
                providecount = (Integer) magics.get(ts).get("providecount");
                if ((Integer) value.get("storage") < providecount && (Integer) value.get("lastprovide")
                        + (Integer) magics.get(ts).get("provideperoid") < timestamp) {
                    dataBaseService.execute("UPDATE sns_magicstore SET storage = '" + providecount
                            + "', lastprovide = '" + timestamp + "' WHERE mid = '" + ts + "'");
                    list.get(ts).put("storage", providecount);
                }
            }
            List<String> newids = new ArrayList<String>();
            for (String id : ids) {
                if (!Common.in_array(oldids, id)) {
                    newids.add(id);
                }
            }
            int newidsSize = newids.size();
            if (newidsSize > 0) {
                String[] inserts = new String[newidsSize];
                ti = 0;
                StringBuilder builder = new StringBuilder();
                Map<String, Object> listValue;
                for (String id : newids) {
                    builder.delete(0, builder.length());
                    builder.append("('");
                    builder.append(id);
                    builder.append("', '");
                    builder.append(magics.get(id).get("providecount"));
                    builder.append("', '");
                    builder.append(timestamp);
                    builder.append("')");
                    inserts[ti++] = builder.toString();
                    listValue = new HashMap<String, Object>();
                    listValue.put("mid", id);
                    listValue.put("storage", magics.get(id).get("providecount"));
                    listValue.put("lastprovide", timestamp);
                    list.put(id, listValue);
                }
                dataBaseService.execute("INSERT INTO sns_magicstore (mid, storage, lastprovide) VALUES "
                        + Common.implode(inserts, ","));
            }
            if (order.equals("default")) {
                Map<String, Map<String, Object>> tempMap = new LinkedHashMap<String, Map<String, Object>>();
                for (String id : ids) {
                    tempMap.put(id, list.get(id));
                }
                list = tempMap;
            }
            request.setAttribute("space", space);
            request.setAttribute("blacklist", blacklist);
            request.setAttribute("magics", magics);
            request.setAttribute("mid", mid);
            request.setAttribute("list", list);
        }
        Map<String, String> actives = new HashMap<String, String>();
        actives.put(view, " class=\"active\"");
        request.setAttribute("actives", actives);
    }
    request.setAttribute("op", op);
    return include(request, response, sConfig, sGlobal, "cp_magic.jsp");
}

From source file:cn.jcenterhome.web.action.CpAction.java

public ActionForward cp_magic(HttpServletRequest request, HttpServletResponse response) {
    Map<String, Object> sGlobal = (Map<String, Object>) request.getAttribute("sGlobal");
    Map<String, Object> sConfig = (Map<String, Object>) request.getAttribute("sConfig");
    Map<Integer, String> sNames = (Map<Integer, String>) request.getAttribute("sNames");
    String op = request.getParameter("op");
    op = Common.empty(op) ? "view" : op;
    String mid = Common.trim(request.getParameter("mid"));
    int supe_uid = (Integer) sGlobal.get("supe_uid");
    int timestamp = (Integer) sGlobal.get("timestamp");
    Map<String, Object> space = Common.getSpace(request, sGlobal, sConfig, supe_uid);
    if (!Common.checkPerm(request, response, "allowmagic")) {
        MessageVO msgVO = Common.ckSpaceLog(request);
        if (msgVO != null) {
            return showMessage(request, response, msgVO);
        }/*from w ww  .  j av a  2 s  . c om*/
        return showMessage(request, response, "magic_groupid_not_allowed");
    }
    Map<String, Object> magic = null;
    if (!mid.equals("")) {
        Object result = magicService.magic_get(mid);
        if (result instanceof MessageVO) {
            return showMessage(request, response, (MessageVO) result);
        }
        magic = (Map<String, Object>) result;
    }
    boolean sc_buysubmit = false;
    boolean sc_presentsubmit = false;
    try {
        sc_buysubmit = submitCheck(request, "buysubmit");
        if (!sc_buysubmit) {
            sc_presentsubmit = submitCheck(request, "presentsubmit");
        }
    } catch (Exception e) {
        return showMessage(request, response, e.getMessage());
    }
    if (sc_buysubmit) {
        if (mid.equals("")) {
            return showMessage(request, response, "unknown_magic");
        }
        Object result = magicService.magic_buy_get(request, response, magic, sGlobal, space);
        if (result instanceof MessageVO) {
            return showMessage(request, response, (MessageVO) result);
        }
        Map<String, Object> datas = (Map<String, Object>) result;
        Map<String, Object> magicstore = (Map<String, Object>) datas.get("magicstore");
        Map<String, Object> coupon = (Map<String, Object>) datas.get("coupon");
        result = magicService.magic_buy_post(request, response, sGlobal, space, magic, magicstore, coupon);
        if (result instanceof MessageVO) {
            return showMessage(request, response, (MessageVO) result);
        }
        int charge = (Integer) result;
        if ((Integer) magic.get("experience") != 0) {
            String buynumS = request.getParameter("buynum");
            int buynum = buynumS != null ? Common.intval(buynumS.trim()) : 0;
            return showMessage(request, response, "magicbuy_success_with_experence",
                    request.getParameter("refer"), 0, charge + "",
                    ((Integer) magic.get("experience") * buynum) + "");
        } else {
            return showMessage(request, response, "magicbuy_success", request.getParameter("refer"), 0,
                    charge + "");
        }
    } else if (sc_presentsubmit) {
        if (mid.equals("")) {
            return showMessage(request, response, "unknown_magic");
        }
        if (mid.equals("license")) {
            return showMessage(request, response, "magic_can_not_be_presented");
        }
        String fusername = request.getParameter("fusername");
        fusername = fusername == null ? fusername : fusername.trim();
        if (Common.empty(fusername)) {
            return showMessage(request, response, "bad_friend_username_given");
        }
        try {
            fusername = Common.getStr(fusername, 15, false, false, false, 0, 0, request, response);
        } catch (Exception e) {
            e.printStackTrace();
            return showMessage(request, response, e.getMessage());
        }
        List<Map<String, Object>> query = dataBaseService
                .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("friend") + " WHERE uid = '"
                        + supe_uid + "' AND fusername='" + fusername + "'");
        Map<String, Object> value = query.size() > 0 ? query.get(0) : null;
        if (value == null) {
            return showMessage(request, response, "bad_friend_username_given");
        }
        int fuid = (Integer) value.get("fuid");
        Map<String, Map<String, Object>> usermagics = new HashMap<String, Map<String, Object>>();
        query = dataBaseService.executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("usermagic")
                + " WHERE uid='" + supe_uid + "' AND mid IN('license', '" + mid + "')");
        for (Map<String, Object> value_ : query) {
            usermagics.put((String) value_.get("mid"), value_);
        }
        Map<String, Object> tempMap = usermagics.get("license");
        if (tempMap == null || (Integer) tempMap.get("count") == 0) {
            return showMessage(request, response, "has_no_more_present_magic");
        }
        tempMap = usermagics.get(mid);
        if (tempMap == null || (Integer) tempMap.get("count") == 0) {
            return showMessage(request, response, "has_no_more_magic", null, 0, (String) magic.get("name"),
                    "a_buy_" + mid, "cp.jsp?ac=magic&op=buy&mid=" + mid);
        }
        dataBaseService.execute(
                "UPDATE " + JavaCenterHome.getTableName("usermagic") + " SET count = count - 1 WHERE uid = '"
                        + supe_uid + "' AND mid IN ('license', '" + mid + "')");
        query = dataBaseService.executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("usermagic")
                + " WHERE uid='" + fuid + "' AND mid='" + mid + "'");
        value = query.size() > 0 ? query.get(0) : null;
        int count = value != null ? (Integer) value.get("count") + 1 : 1;
        Map<String, Object> insertData = new HashMap<String, Object>();
        insertData.put("uid", fuid);
        insertData.put("username", fusername);
        insertData.put("mid", mid);
        insertData.put("count", count);
        dataBaseService.insertTable("usermagic", insertData, false, true);
        insertData.clear();
        insertData.put("uid", fuid);
        insertData.put("username", fusername);
        insertData.put("mid", mid);
        insertData.put("count", 1);
        insertData.put("type", 2);
        insertData.put("fromid", supe_uid);
        insertData.put("credit", 0);
        insertData.put("dateline", timestamp);
        dataBaseService.insertTable("magicinlog", insertData, false, false);
        String note = Common.getMessage(request, "cp_magic_present_note", (String) magic.get("name"),
                "cp.jsp?ac=magic&view=me&mid=" + mid);
        note = note == null ? "magic_present_note" : note;
        cpService.addNotification(request, sGlobal, sConfig, fuid, "magic", note, false);
        return showMessage(request, response, "magicpresent_success", request.getParameter("refer"), 0,
                fusername);
    }
    if ("buy".equals(op)) {
        Object result = magicService.magic_buy_get(request, response, magic, sGlobal, space);
        if (result instanceof MessageVO) {
            return showMessage(request, response, (MessageVO) result);
        }
        Map<String, Object> datas = (Map<String, Object>) result;
        Map<String, Object> magicstore = (Map<String, Object>) datas.get("magicstore");
        Map<String, Object> coupon = (Map<String, Object>) datas.get("coupon");
        request.setAttribute("mid", mid);
        request.setAttribute("magicstore", magicstore);
        request.setAttribute("coupon", coupon);
        request.setAttribute("discount", datas.get("discount"));
        request.setAttribute("charge", datas.get("charge"));
        String ac = request.getParameter("ac");
        request.setAttribute("ac", ac != null ? ac.trim() : "");
        request.setAttribute("magic", magic);
    } else if ("present".equals(op)) {
        if (mid.equals("license")) {
            return showMessage(request, response, "magic_can_not_be_presented");
        }
        Map<String, Map<String, Object>> usermagics = new HashMap<String, Map<String, Object>>();
        List<Map<String, Object>> query = dataBaseService
                .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("usermagic") + " WHERE uid='"
                        + supe_uid + "' AND mid IN('license', '" + mid + "')");
        for (Map<String, Object> value : query) {
            usermagics.put((String) value.get("mid"), value);
        }
        Map<String, Object> tempMap = usermagics.get("license");
        if (tempMap == null || (Integer) tempMap.get("count") == 0) {
            return showMessage(request, response, "has_no_more_present_magic");
        }
        tempMap = usermagics.get(mid);
        if (tempMap == null || (Integer) tempMap.get("count") == 0) {
            return showMessage(request, response, "has_no_more_magic", null, 0, (String) magic.get("name"),
                    "a_buy_" + mid, "cp.jsp?ac=magic&op=buy&mid=" + mid);
        }
        request.setAttribute("mid", mid);
        request.setAttribute("magic", magic);
    } else if ("showusage".equals(op)) {
        if (mid.equals("")) {
            return showMessage(request, response, "unknown_magic");
        }
        request.setAttribute("mid", mid);
    } else if ("receive".equals(op)) {
        String uidS = request.getParameter("uid");
        int uid = uidS != null ? Common.intval(uidS.trim()) : 0;
        List<Map<String, Object>> query = dataBaseService
                .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("magicuselog") + " WHERE uid='"
                        + uid + "' AND mid='gift' LIMIT 1");
        Map<String, Object> value = query.size() > 0 ? query.get(0) : null;
        String value_data;
        if (value != null && (value_data = (String) value.get("data")) != null && !value_data.equals("")) {
            Map<String, Object> data = Serializer.unserialize(value_data, false);
            if ((Integer) data.get("left") <= 0) {
                return showMessage(request, response, "magic_gift_already_given_out");
            }
            Map<Integer, Integer> receiver = (Map<Integer, Integer>) data.get("receiver");
            if (receiver == null) {
                receiver = new HashMap<Integer, Integer>();
                data.put("receiver", receiver);
            }
            int receiverIndex = 0;
            for (Entry<Integer, Integer> entry : receiver.entrySet()) {
                if (entry.getValue() == supe_uid) {
                    return showMessage(request, response, "magic_had_got_gift");
                }
                receiverIndex = Math.max(receiverIndex, entry.getKey());
            }
            int data_left = (Integer) data.get("left");
            int data_chunk = (Integer) data.get("chunk");
            int credit = Math.min(data_chunk, data_left);
            receiver.put(++receiverIndex, supe_uid);
            data_left = data_left - credit;
            data.put("left", data_left);
            if (data_left > 0) {
                Map<String, Object> setData = new HashMap<String, Object>();
                setData.put("data", Serializer.serialize(data));
                Map<String, Object> whereData = new HashMap<String, Object>();
                whereData.put("logid", value.get("logid"));
                dataBaseService.updateTable("magicuselog", setData, whereData);
            } else {
                dataBaseService.execute("DELETE FROM " + JavaCenterHome.getTableName("magicuselog")
                        + " WHERE logid = '" + value.get("logid") + "'");
            }
            dataBaseService.execute("UPDATE " + JavaCenterHome.getTableName("space")
                    + " SET credit = credit + '" + credit + "' WHERE uid='" + supe_uid + "'");
            return showMessage(request, response, "magic_got_gift", null, 0, credit + "");
        } else {
            return showMessage(request, response, "magic_has_no_gift");
        }
    } else if ("appear".equals(op)) {
        Map<String, Object> session_member = (Map<String, Object>) sGlobal.get("session");
        if (session_member == null || (Integer) session_member.get("magichidden") == 0) {
            return showMessage(request, response, "magic_not_hidden_yet");
        }
        boolean scb = false;
        try {
            scb = submitCheck(request, "appearsubmit");
        } catch (Exception e) {
            e.printStackTrace();
            return showMessage(request, response, e.getMessage());
        }
        if (scb) {
            Map<String, Object> setData = new HashMap<String, Object>();
            Map<String, Object> whereData = new HashMap<String, Object>();
            setData.put("magichidden", "0");
            whereData.put("uid", supe_uid);
            dataBaseService.updateTable("session", setData, whereData);
            setData.clear();
            setData.put("expire", timestamp);
            whereData.put("mid", "invisible");
            dataBaseService.updateTable("magicuselog", setData, whereData);
            return showMessage(request, response, "do_success", request.getParameter("refer"), 0);
        }
    } else if ("retrieve".equals(op)) {
        List<Map<String, Object>> query = dataBaseService
                .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("magicuselog") + " WHERE uid = '"
                        + supe_uid + "' AND mid = 'gift'");
        Map<String, Object> value = query.size() > 0 ? query.get(0) : null;
        int leftcredit = 0;
        String dataS = null;
        if (value == null) {
            return showMessage(request, response, "not_set_gift");
        } else if ((dataS = (String) value.get("data")) != null && !dataS.equals("")) {
            Map<String, Object> data = Serializer.unserialize(dataS, false);
            leftcredit = (Integer) data.get("left");
        }
        boolean scb = false;
        try {
            scb = submitCheck(request, "retrievesubmit");
        } catch (Exception e) {
            e.printStackTrace();
            return showMessage(request, response, e.getMessage());
        }
        if (scb) {
            dataBaseService.execute("DELETE FROM " + JavaCenterHome.getTableName("magicuselog")
                    + " WHERE uid = '" + supe_uid + "' AND mid = 'gift'");
            dataBaseService.execute("UPDATE " + JavaCenterHome.getTableName("space") + " SET credit = credit + "
                    + leftcredit + " WHERE uid = '" + supe_uid + "'");
            return showMessage(request, response, "do_success", request.getParameter("refer"), 0);
        }
        request.setAttribute("leftcredit", leftcredit);
    } else if ("cancelsuperstar".equals(op)) {
        mid = "superstar";
        List<Map<String, Object>> query = dataBaseService.executeQuery("SELECT * FROM "
                + JavaCenterHome.getTableName("spacefield") + " WHERE uid = '" + supe_uid + "'");
        Map<String, Object> value = query.size() > 0 ? query.get(0) : null;
        Integer magicstar;
        if (value == null || (magicstar = (Integer) value.get("magicstar")) == null || magicstar == 0) {
            return showMessage(request, response, "not_superstar_yet");
        }
        boolean scb = false;
        try {
            scb = submitCheck(request, "cancelsubmit");
        } catch (Exception e) {
            e.printStackTrace();
            return showMessage(request, response, e.getMessage());
        }
        if (scb) {
            Map<String, Object> setData = new HashMap<String, Object>();
            Map<String, Object> whereData = new HashMap<String, Object>();
            setData.put("magicstar", 0);
            whereData.put("uid", supe_uid);
            dataBaseService.updateTable("spacefield", setData, whereData);
            setData.clear();
            setData.put("expire", timestamp);
            whereData.put("mid", "superstar");
            dataBaseService.updateTable("magicuselog", setData, whereData);
            return showMessage(request, response, "do_success", request.getParameter("refer"), 0);
        }
    } else if ("cancelflicker".equals(op)) {
        mid = "flicker";
        String idtype = "cid";
        String idS = request.getParameter("id");
        int id = idS != null ? Common.intval(idS.trim()) : 0;
        List<Map<String, Object>> query = dataBaseService
                .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("comment") + " WHERE cid = '" + id
                        + "' AND authorid = '" + supe_uid + "'");
        Map<String, Object> value = query.size() > 0 ? query.get(0) : null;
        Integer magicflicker;
        if (value == null || (magicflicker = (Integer) value.get("magicflicker")) == null
                || magicflicker == 0) {
            return showMessage(request, response, "no_flicker_yet");
        }
        boolean scb = false;
        try {
            scb = submitCheck(request, "cancelsubmit");
        } catch (Exception e) {
            e.printStackTrace();
            return showMessage(request, response, e.getMessage());
        }
        if (scb) {
            Map<String, Object> setData = new HashMap<String, Object>();
            setData.put("magicflicker", 0);
            Map<String, Object> whereData = new HashMap<String, Object>();
            whereData.put("cid", id);
            whereData.put("authorid", supe_uid);
            dataBaseService.updateTable("comment", setData, whereData);
            return showMessage(request, response, "do_success", request.getParameter("refer"), 0);
        }
        request.setAttribute("id", id);
        request.setAttribute("idtype", idtype);
        request.setAttribute("mid", mid);
    } else if ("cancelcolor".equals(op)) {
        mid = "color";
        String idS = request.getParameter("id");
        int id = idS != null ? Common.intval(idS.trim()) : 0;
        String idtype = request.getParameter("idtype");
        if (idtype == null) {
            return showMessage(request, response, "access error : 00001");
        }
        idtype = idtype.trim();
        Map<String, String> mapping = new HashMap<String, String>();
        mapping.put("blogid", "blogfield");
        mapping.put("tid", "thread");
        String tablename = mapping.get(idtype);
        if (Common.empty(tablename)) {
            return showMessage(request, response, "no_color_yet");
        }
        List<Map<String, Object>> query = dataBaseService
                .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName(tablename) + " WHERE " + idtype
                        + " = '" + id + "' AND uid = '" + supe_uid + "'");
        Map<String, Object> value = query.size() > 0 ? query.get(0) : null;
        Integer magiccolor;
        if (value == null || (magiccolor = (Integer) value.get("magiccolor")) == null || magiccolor == 0) {
            return showMessage(request, response, "no_color_yet");
        }
        boolean scb = false;
        try {
            scb = submitCheck(request, "cancelsubmit");
        } catch (Exception e) {
            e.printStackTrace();
            return showMessage(request, response, e.getMessage());
        }
        if (scb) {
            Map<String, Object> setData = new HashMap<String, Object>();
            setData.put("magiccolor", 0);
            Map<String, Object> whereData = new HashMap<String, Object>();
            whereData.put(idtype, id);
            dataBaseService.updateTable(tablename, setData, whereData);
            query = dataBaseService.executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("feed")
                    + " WHERE id = '" + id + "' AND idtype = '" + idtype + "'");
            Map<String, Object> feed = query.size() > 0 ? query.get(0) : null;
            if (feed != null) {
                String body_data = (String) feed.get("body_data");
                Map body_data_subMap = Serializer.unserialize(body_data, false);
                body_data_subMap.remove("magic_color");
                body_data = Serializer.serialize(body_data_subMap);
                setData.clear();
                whereData.clear();
                setData.put("body_data", body_data);
                whereData.put("feedid", feed.get("feedid"));
                dataBaseService.updateTable("feed", setData, whereData);
            }
            return showMessage(request, response, "do_success", request.getParameter("refer"), 0);
        }
        request.setAttribute("id", id);
        request.setAttribute("idtype", idtype);
        request.setAttribute("mid", mid);
    } else if ("cancelframe".equals(op)) {
        mid = "frame";
        String idtype = "picid";
        String idS = request.getParameter("id");
        int id = idS != null ? Common.intval(idS.trim()) : 0;
        List<Map<String, Object>> query = dataBaseService
                .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("pic") + " WHERE picid = '" + id
                        + "' AND uid = '" + supe_uid + "'");
        Map<String, Object> value = query.size() > 0 ? query.get(0) : null;
        Integer magicframe;
        if (value == null || (magicframe = (Integer) value.get("magicframe")) == null || magicframe == 0) {
            return showMessage(request, response, "no_frame_yet");
        }
        boolean scb = false;
        try {
            scb = submitCheck(request, "cancelsubmit");
        } catch (Exception e) {
            e.printStackTrace();
            return showMessage(request, response, e.getMessage());
        }
        if (scb) {
            Map<String, Object> setData = new HashMap<String, Object>();
            setData.put("magicframe", 0);
            Map<String, Object> whereData = new HashMap<String, Object>();
            whereData.put("picid", id);
            dataBaseService.updateTable("pic", setData, whereData);
            return showMessage(request, response, "do_success", request.getParameter("refer"), 0);
        }
        request.setAttribute("id", id);
        request.setAttribute("idtype", idtype);
        request.setAttribute("mid", mid);
    } else if ("cancelbgimage".equals(op)) {
        mid = "bgimage";
        String idtype = "blogid";
        String idS = request.getParameter("id");
        int id = idS != null ? Common.intval(idS.trim()) : 0;
        List<Map<String, Object>> query = dataBaseService
                .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("blogfield") + " WHERE blogid = '"
                        + id + "' AND uid = '" + supe_uid + "'");
        Map<String, Object> value = query.size() > 0 ? query.get(0) : null;
        Integer magicpaper;
        if (value == null || (magicpaper = (Integer) value.get("magicpaper")) == null || magicpaper == 0) {
            return showMessage(request, response, "no_bgimage_yet");
        }
        boolean scb = false;
        try {
            scb = submitCheck(request, "cancelsubmit");
        } catch (Exception e) {
            e.printStackTrace();
            return showMessage(request, response, e.getMessage());
        }
        if (scb) {
            Map<String, Object> setData = new HashMap<String, Object>();
            setData.put("magicpaper", 0);
            Map<String, Object> whereData = new HashMap<String, Object>();
            whereData.put("blogid", id);
            dataBaseService.updateTable("blogfield", setData, whereData);
            return showMessage(request, response, "do_success", request.getParameter("refer"), 0);
        }
        request.setAttribute("id", id);
        request.setAttribute("idtype", idtype);
        request.setAttribute("mid", mid);
    } else {
        String view = request.getParameter("view");
        if (view != null) {
            view = view.trim();
        }
        if ("me".equals(view)) {
            Map<String, String> types = new HashMap<String, String>();
            types.put("list", " class=\"active\"");
            request.setAttribute("types", types);
            Map<String, Map<String, Object>> list = null;
            StringBuilder ids = new StringBuilder();
            Map<String, Map<String, Object>> magics = new HashMap<String, Map<String, Object>>();
            List<Map<String, Object>> query = null;
            if (!mid.equals("")) {
                magics.put(mid, magic);
                ids.append("'");
                ids.append(mid);
                ids.append("'");
            } else {
                query = dataBaseService.executeQuery(
                        "SELECT * FROM " + JavaCenterHome.getTableName("magic") + " WHERE close = '0'");
                String tempS;
                Pattern pattern = Pattern.compile(",");
                boolean existMid = false;
                for (Map<String, Object> value : query) {
                    tempS = (String) value.get("forbiddengid");
                    if (tempS != null) {
                        value.put("forbiddengid", pattern.split(tempS));
                    } else {
                        value.put("forbiddengid", new String[0]);
                    }
                    tempS = (String) value.get("mid");
                    magics.put(tempS, value);
                    if (existMid) {
                        ids.append(",");
                    } else {
                        existMid = true;
                    }
                    ids.append("'");
                    ids.append(tempS);
                    ids.append("'");
                }
            }
            query = dataBaseService.executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("usermagic")
                    + " WHERE uid='" + supe_uid + "' AND mid IN (" + ids.toString() + ") AND count > 0");
            if (query.size() > 0) {
                list = new LinkedHashMap<String, Map<String, Object>>();
                for (Map<String, Object> value : query) {
                    list.put((String) value.get("mid"), value);
                }
            }
            request.setAttribute("list", list);
            request.setAttribute("magics", magics);
            request.setAttribute("mid", mid);
        } else if ("log".equals(view)) {
            String type = request.getParameter("type");
            type = type != null
                    && ((type = type.trim()).equals("in") || type.equals("out") || type.equals("present"))
                            ? type
                            : "in";
            request.setAttribute("gType", type);
            Map<String, String> types = new HashMap<String, String>();
            types.put(type, " class=\"active\"");
            request.setAttribute("types", types);
            int perpage = 20;
            String pageGet = request.getParameter("page");
            int page = Common.empty(pageGet) ? 0 : Common.intval(pageGet);
            if (page < 1)
                page = 1;
            int start = (page - 1) * perpage;
            int maxPage = (Integer) sConfig.get("maxpage");
            String result = Common.ckStart(start, perpage, maxPage);
            if (result != null) {
                return showMessage(request, response, result);
            }
            List<Map<String, Object>> list = null;
            List<Map<String, Object>> query = null;
            int count = 0;
            if ("in".equals(type)) {
                List<Integer> uids = null;
                query = dataBaseService.executeQuery("SELECT COUNT(*) AS cont FROM "
                        + JavaCenterHome.getTableName("magicinlog") + " WHERE uid = '" + supe_uid + "'");
                count = query.size() > 0 ? (Integer) query.get(0).get("cont") : 0;
                if (count != 0) {
                    query = dataBaseService.executeQuery(
                            "SELECT * FROM " + JavaCenterHome.getTableName("magicinlog") + " WHERE uid = '"
                                    + supe_uid + "' ORDER BY dateline DESC LIMIT " + start + ", " + perpage);
                    list = query.size() > 0 ? query : null;
                    uids = new ArrayList<Integer>();
                    for (Map<String, Object> value : query) {
                        value.put("dateline",
                                Common.sgmdate(request, "MM-dd HH:mm", (Integer) value.get("dateline"), true));
                        if ((Integer) value.get("type") == 2) {
                            uids.add((Integer) value.get("fromid"));
                        }
                    }
                }
                if (uids != null && uids.size() > 0) {
                    query = dataBaseService
                            .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("member")
                                    + " WHERE uid IN (" + Common.sImplode(uids) + ")");
                    for (Map<String, Object> value : query) {
                        Common.realname_set(sGlobal, sConfig, sNames, (Integer) value.get("uid"),
                                (String) value.get("username"), "", 0);
                    }
                    Common.realname_get(sGlobal, sConfig, sNames, space);
                }
            } else if ("present".equals(type)) {
                query = dataBaseService.executeQuery(
                        "SELECT COUNT(*) AS cont FROM " + JavaCenterHome.getTableName("magicinlog")
                                + " WHERE type = 2 AND fromid = '" + supe_uid + "'");
                count = query.size() > 0 ? (Integer) query.get(0).get("cont") : 0;
                if (count != 0) {
                    query = dataBaseService.executeQuery("SELECT * FROM "
                            + JavaCenterHome.getTableName("magicinlog") + " WHERE type = 2 AND fromid = '"
                            + supe_uid + "' ORDER BY dateline DESC LIMIT " + start + ", " + perpage);
                    list = query.size() > 0 ? query : null;
                    for (Map<String, Object> value : query) {
                        value.put("dateline",
                                Common.sgmdate(request, "MM-dd HH:mm", (Integer) value.get("dateline"), true));
                        Common.realname_set(sGlobal, sConfig, sNames, (Integer) value.get("uid"),
                                (String) value.get("username"), "", 0);
                    }
                }
                Common.realname_get(sGlobal, sConfig, sNames, space);
            } else {
                query = dataBaseService.executeQuery("SELECT COUNT(*) AS cont FROM "
                        + JavaCenterHome.getTableName("magicuselog") + " WHERE uid = '" + supe_uid + "'");
                count = query.size() > 0 ? (Integer) query.get(0).get("cont") : 0;
                if (count != 0) {
                    query = dataBaseService.executeQuery(
                            "SELECT * FROM " + JavaCenterHome.getTableName("magicuselog") + " WHERE uid = '"
                                    + supe_uid + "' ORDER BY dateline DESC LIMIT " + start + ", " + perpage);
                    list = query.size() > 0 ? query : null;
                    for (Map<String, Object> value : query) {
                        value.put("dateline",
                                Common.sgmdate(request, "MM-dd HH:mm", (Integer) value.get("dateline"), true));
                        value.put("data", Serializer.unserialize((String) value.get("data"), false));
                        value.put("expire",
                                Common.sgmdate(request, "MM-dd HH:mm", (Integer) value.get("expire"), false));
                    }
                }
            }
            String theurl = "cp.jsp?ac=magic&view=log&type=" + type;
            String multi = Common.multi(request, count, perpage, page, maxPage, theurl, "", "");
            request.setAttribute("multi", multi);
            request.setAttribute("list", list);
        } else {
            view = "store";
            String order = request.getParameter("order");
            if (order != null) {
                order = order.trim();
            }
            order = "hot".equals(order) ? order : "default";
            Map<String, String> orders = new HashMap<String, String>();
            orders.put(order, " class=\"active\"");
            request.setAttribute("orders", orders);
            List<Map<String, Object>> query;
            Map<String, Map<String, Object>> magics = new HashMap<String, Map<String, Object>>();
            List<String> ids = null;
            Map<String, Map<String, Object>> list = new LinkedHashMap<String, Map<String, Object>>();
            String[] blacklist = { "coupon" };
            if (!mid.equals("")) {
                magics.put(mid, magic);
                ids = new ArrayList<String>(1);
                ids.add(mid);
            } else {
                String orderby = order.equals("hot") ? "" : " ORDER BY displayorder";
                query = dataBaseService
                        .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("magic") + orderby);
                String tempS;
                Pattern pattern = Pattern.compile(",");
                ids = new ArrayList<String>(query.size());
                for (Map<String, Object> value : query) {
                    if ((Integer) value.get("close") == 1 || Common.in_array(blacklist, value.get("mid"))) {
                        continue;
                    }
                    tempS = (String) value.get("forbiddengid");
                    if (tempS != null) {
                        value.put("forbiddengid", pattern.split(tempS));
                    } else {
                        value.put("forbiddengid", new String[0]);
                    }
                    tempS = (String) value.get("mid");
                    magics.put(tempS, value);
                    ids.add(tempS);
                }
            }
            if (Common.empty(magics)) {
                return showMessage(request, response, "magic_store_is_closed");
            }
            String orderby = order.equals("hot") ? " ORDER BY sellcount DESC" : "";
            query = dataBaseService.executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("magicstore")
                    + " WHERE mid IN (" + Common.sImplode(ids) + ")" + orderby);
            String[] oldids = new String[query.size()];
            int ti = 0;
            int providecount;
            String ts;
            for (Map<String, Object> value : query) {
                ts = (String) value.get("mid");
                list.put(ts, value);
                oldids[ti++] = ts;
                providecount = (Integer) magics.get(ts).get("providecount");
                if ((Integer) value.get("storage") < providecount && (Integer) value.get("lastprovide")
                        + (Integer) magics.get(ts).get("provideperoid") < timestamp) {
                    dataBaseService.execute("UPDATE " + JavaCenterHome.getTableName("magicstore")
                            + " SET storage = '" + providecount + "', lastprovide = '" + timestamp
                            + "' WHERE mid = '" + ts + "'");
                    list.get(ts).put("storage", providecount);
                }
            }
            List<String> newids = new ArrayList<String>();
            for (String id : ids) {
                if (!Common.in_array(oldids, id)) {
                    newids.add(id);
                }
            }
            int newidsSize = newids.size();
            if (newidsSize > 0) {
                String[] inserts = new String[newidsSize];
                ti = 0;
                StringBuilder builder = new StringBuilder();
                Map<String, Object> listValue;
                for (String id : newids) {
                    builder.delete(0, builder.length());
                    builder.append("('");
                    builder.append(id);
                    builder.append("', '");
                    builder.append(magics.get(id).get("providecount"));
                    builder.append("', '");
                    builder.append(timestamp);
                    builder.append("')");
                    inserts[ti++] = builder.toString();
                    listValue = new HashMap<String, Object>();
                    listValue.put("mid", id);
                    listValue.put("storage", magics.get(id).get("providecount"));
                    listValue.put("lastprovide", timestamp);
                    list.put(id, listValue);
                }
                dataBaseService.execute("INSERT INTO " + JavaCenterHome.getTableName("magicstore")
                        + "(mid, storage, lastprovide) VALUES " + Common.implode(inserts, ","));
            }
            if (order.equals("default")) {
                Map<String, Map<String, Object>> tempMap = new LinkedHashMap<String, Map<String, Object>>();
                for (String id : ids) {
                    tempMap.put(id, list.get(id));
                }
                list = tempMap;
            }
            request.setAttribute("space", space);
            request.setAttribute("blacklist", blacklist);
            request.setAttribute("magics", magics);
            request.setAttribute("mid", mid);
            request.setAttribute("list", list);
        }
        Map<String, String> actives = new HashMap<String, String>();
        actives.put(view, " class=\"active\"");
        request.setAttribute("actives", actives);
    }
    request.setAttribute("op", op);
    return include(request, response, sConfig, sGlobal, "cp_magic.jsp");
}

From source file:com.flexive.shared.scripting.groovy.GroovyScriptExporterTools.java

/**
 * Write the script code to update a property assignment, or to create a derived assignment
 * <p/>/*w w w .  jav  a2  s .c om*/
 * "acl", "defaultValue", "hint", "label", "multilang", "multiline", "multiplicity"
 *
 * @param pa                          the FxPropertyAssignment to be updated
 * @param isDerived                   the Assignment is derived
 * @param differences                 the List of differences (map keys f. the builder)
 * @param defaultsOnly                use only default settings provided by the GTB, no analysis of assignments will be performed
 * @param tabCount                    the number of tabs to be added to the code's left hand side
 * @param withoutDependencies         true = do not create assignment:xPath code
 * @param differingDerivedAssignments the List of assignment ids for derived assignments differing from their base assignments
 * @return returns the partial script as a StringBuilder instance
 */
public static String updatePropertyAssignment(FxPropertyAssignment pa, boolean isDerived,
        List<String> differences, boolean defaultsOnly, int tabCount, boolean withoutDependencies,
        List<Long> differingDerivedAssignments) {
    StringBuilder script = new StringBuilder(500);
    final FxProperty prop = pa.getProperty();
    final String dataType = pa.getProperty().getDataType() + "";

    // use the alias as the reference name
    script.append(Indent.tabs(tabCount));
    boolean createProp = false;
    if (!isDerived
            || (isDerived && differingDerivedAssignments != null
                    && !differingDerivedAssignments.contains(pa.getId()))
            || (isDerived && differences.size() > 0) || (isDerived && !withoutDependencies))
        createProp = true;

    if (createProp) {
        final String propAlias = keyWordNameCheck(pa.getAlias().toLowerCase(), true);
        script.append(propAlias).append("( "); // opening parenthesis + 1x \s

    }
    // ASSIGNMENT
    if (isDerived && !withoutDependencies || (isDerived && !withoutDependencies
            && differingDerivedAssignments != null && !differingDerivedAssignments.contains(pa.getId()))) {
        final String assignmentPath = CacheAdmin.getEnvironment().getAssignment(pa.getBaseAssignmentId())
                .getXPath();
        script.append("assignment: \"").append(assignmentPath).append("\",");
    }

    if (!defaultsOnly && differences.size() > 0) {
        tabCount++;
        script.append("\n");
        // label and hint
        if (differences.contains("hint") || differences.contains("label"))
            script.append(getLabelAndHintAssignment(pa, differences.contains("label"),
                    differences.contains("hint"), tabCount));

        // sopts - a map for "simple" GroovyTypeBuilder options
        Map<String, String> sopts = new LinkedHashMap<String, String>();
        final String multiLang = pa.isMultiLang() + "";

        if (differences.contains("multilang")) {
            if (prop.mayOverrideMultiLang()) {
                sopts.put("multilang", multiLang + "");
            }
        }

        if (differences.contains("acl")) {
            if (prop.mayOverrideACL())
                sopts.put("acl", "CacheAdmin.getEnvironment().getACL(ACLCategory." + pa.getACL().getCategory()
                        + ".getDefaultId())");
        }

        if (differences.contains("multiplicity")) {
            if (prop.mayOverrideBaseMultiplicity())
                sopts.put("multiplicity", "new FxMultiplicity(" + pa.getMultiplicity().getMin() + ","
                        + pa.getMultiplicity().getMax() + ")");
        }

        if (differences.contains("maxLength")) {
            if (prop.mayOverrideMaxLength())
                sopts.put("maxLength", pa.getMaxLength() + "");
        }

        if (differences.contains("inOverview")) {
            if (prop.mayOverrideInOverview())
                sopts.put("inOverview", pa.isInOverview() + "");
        }

        if (differences.contains("useHtmlEditor")) {
            if (prop.mayOverrideUseHTMLEditor())
                sopts.put("useHtmlEditor", pa.isUseHTMLEditor() + "");
        }

        if (differences.contains("multilang")) {
            if (pa.isMultiLang()) {
                sopts.put("", pa.getDefaultLanguage() + "");
            }
        }

        if (differences.contains("multiline")) {
            if (prop.mayOverrideMultiLine())
                sopts.put("multiline", pa.isMultiLine() + "");
        }

        // FxStructureOptions via the GroovyOptionbuilder
        if (differences.contains("structureoptions"))
            script.append(getStructureOptions(pa, tabCount));

        if (differences.contains("searchable")) {
            if (prop.mayOverrideSearchable())
                sopts.put("searchable", pa.isSearchable() + "");
        }

        // options valid for derived assignments only **********************
        if (differences.contains("defaultMultiplicity"))
            sopts.put("defaultMultiplicity", pa.getDefaultMultiplicity() + "");

        if (differences.contains("alias"))
            sopts.put("alias", "\"" + pa.getAlias() + "\"");

        if (differences.contains("enabled"))
            sopts.put("enabled", pa.isEnabled() + "");

        if (differences.contains("defaultLanguage"))
            sopts.put("defaultLanguage", pa.getDefaultLanguage() + "L");
        // *****************************************************************

        // DEFAULT VALUES
        if (differences.contains("defaultValue")) {
            if (pa.getDefaultValue() != null) {
                final FxValue val = pa.getDefaultValue();
                String defaultValue = val.toString();
                StringBuilder out = new StringBuilder(100);

                if (DATATYPES.contains(dataType)) {
                    // SELECT LIST DATATYPES
                    if ("SelectOne".equals(dataType) || "SelectMany".equals(dataType)) {
                        final FxSelectList list = pa.getProperty().getReferencedList();
                        final String refListName = "CacheAdmin.getEnvironment().getSelectList(\""
                                + list.getName();
                        sopts.put("referencedList", refListName + "\"),\n");

                        if ("SelectOne".equals(dataType)) {
                            for (FxSelectListItem item : list.getItems()) {
                                if (defaultValue.equals(item.getLabel().toString())) {
                                    defaultValue = item.getName(); // reassign
                                }
                            }
                            out.append("new FxSelectOne(").append(multiLang)
                                    .append(", CacheAdmin.getEnvironment().getSelectListItem(")
                                    .append(refListName).append("\"), \"").append(defaultValue).append("\"))");

                        } else if ("SelectMany".equals(dataType)) {
                            String[] defaults = FxSharedUtils.splitLiterals(defaultValue);
                            for (int i = 0; i < defaults.length; i++) {
                                for (FxSelectListItem item : list.getItems()) {
                                    if (defaults[i].equals(item.getLabel().toString())) {
                                        defaults[i] = item.getName(); // reassign
                                    }
                                }
                            }
                            out.append("new FxSelectMany(").append(multiLang).append(", new SelectMany(")
                                    .append(refListName).append("\"))");
                            // traverse renamed defaults and append them to the script
                            for (String d : defaults) {
                                out.append(".selectItem(CacheAdmin.getEnvironment().getSelectListItem(")
                                        .append(refListName).append("\"), \"").append(d).append("\"))");
                            }
                            out.append(")");
                        }
                    } else if ("Date".equals(dataType) || "DateTime".equals(dataType)
                            || "DateRange".equals(dataType) || "DateTimeRange".equals(dataType)) {
                        final String df = "\"MMM dd, yyyy\"";
                        final String dtf = "\"MMM dd, yyyy h:mm:ss a\"";
                        if ("Date".equals(dataType)) {
                            out.append("new FxDate(").append(multiLang).append(", new SimpleDateFormat(")
                                    .append(df).append(").parse(\"").append(defaultValue).append("\"))");
                        } else if ("DateTime".equals(dataType)) {
                            out.append("new FxDateTime(").append(multiLang).append(", new SimpleDateFormat(")
                                    .append(dtf).append(").parse(\"").append(defaultValue).append("\"))");
                        } else if ("DateRange".equals(dataType)) {
                            final String lower = stripToEmpty(
                                    defaultValue.substring(0, defaultValue.indexOf("-")));
                            final String upper = stripToEmpty(
                                    defaultValue.substring(defaultValue.indexOf("-") + 1));
                            out.append("new FxDateRange(").append(multiLang)
                                    .append(", new DateRange(new SimpleDateFormat(").append(df)
                                    .append(").parse(\"").append(lower).append("\"), new SimpleDateFormat(")
                                    .append(df).append(").parse(\"").append(upper).append("\")))");
                        } else if ("DateTimeRange".equals(dataType)) {
                            final String lower = stripToEmpty(
                                    defaultValue.substring(0, defaultValue.indexOf("-")));
                            final String upper = stripToEmpty(
                                    defaultValue.substring(defaultValue.indexOf("-") + 1));
                            out.append("new FxDateTimeRange(").append(multiLang)
                                    .append(", new DateRange(new SimpleDateFormat(").append(dtf)
                                    .append(").parse(\"").append(lower).append("\"), new SimpleDateFormat(")
                                    .append(dtf).append(").parse(\"").append(upper).append("\")))");
                        }
                    } else if ("Reference".equals(dataType)) {
                        final FxPK pk = FxPK.fromString(defaultValue);
                        out.append("new FxReference(").append(multiLang).append(", new ReferencedContent(")
                                .append(pk.getId()).append(", ").append(pk.getVersion()).append("))");

                    } else if ("InlineReference".equals(dataType)) {
                        // ignore for now, doesn't work paerly as of yet
                    } else if ("Binary".equals(dataType)) {
                        // TODO: impl!
                        // uses a new BinaryDescriptor( .. )
                    }
                }

                // "SIMPLE" dataTYPES
                if (DATATYPESSIMPLE.keySet().contains(dataType)) {
                    for (String d : DATATYPESSIMPLE.keySet()) {
                        if (d.equals(dataType)) {
                            out.append(DATATYPESSIMPLE.get(d)).append("(").append(multiLang).append(", ");
                            if (d.equals("Float") || d.equals("Double") || d.equals("LargeNumber")
                                    || d.equals("Boolean")) {
                                out.append(defaultValue);
                            } else {
                                out.append("\"").append(defaultValue).append("\"");
                            }
                            out.append(")");
                        }
                    }
                }
                out.trimToSize();
                sopts.put("defaultValue", out.toString() + ",");
            }
        }

        // append options to script
        if (sopts.size() > 0) {
            for (String option : sopts.keySet()) {
                script.append(simpleOption(option, sopts.get(option), tabCount));
            }
        }

        script.trimToSize();
        if (script.indexOf(",\n", script.length() - 2) != -1)
            script.delete(script.length() - 2, script.length());
    }
    script.trimToSize();
    if (script.indexOf(",", script.length() - 1) != -1) // remove last "," if written
        script.delete(script.length() - 1, script.length());

    if (createProp)
        script.append(")\n"); // closing parenthesis

    return script.toString();
}

From source file:forge.game.card.Card.java

private StringBuilder abilityTextInstantSorcery(CardState state) {
    final StringBuilder sb = new StringBuilder();

    // Give spellText line breaks for easier reading
    sb.append(text.replaceAll("\\\\r\\\\n", "\r\n"));

    // NOTE://from   www . j a  v a  2 s. c o m
    if (sb.toString().contains(" (NOTE: ")) {
        sb.insert(sb.indexOf("(NOTE: "), "\r\n");
    }
    if (sb.toString().contains("(NOTE: ") && sb.toString().endsWith(".)") && !sb.toString().endsWith("\r\n")) {
        sb.append("\r\n");
    }

    // I think SpellAbilities should be displayed after Keywords
    // Add SpellAbilities
    for (final SpellAbility element : state.getSpellAbilities()) {
        sb.append(formatSpellAbility(element));
    }

    // Add Keywords
    final List<String> kw = getKeywords(state);

    // Triggered abilities
    for (final Trigger trig : state.getTriggers()) {
        if (!trig.isSecondary()) {
            sb.append(trig.toString()).append("\r\n");
        }
    }

    // Replacement effects
    for (final ReplacementEffect replacementEffect : state.getReplacementEffects()) {
        sb.append(replacementEffect.toString()).append("\r\n");
    }

    // static abilities
    for (final StaticAbility stAb : state.getStaticAbilities()) {
        final String stAbD = stAb.toString();
        if (!stAbD.equals("")) {
            sb.append(stAbD).append("\r\n");
        }
    }

    // TODO A lot of these keywords should really show up before the SAs
    // keyword descriptions
    for (final String keyword : kw) {
        if ((keyword.startsWith("Ripple") && !sb.toString().contains("Ripple"))
                || (keyword.startsWith("Dredge") && !sb.toString().contains("Dredge"))
                || (keyword.startsWith("CARDNAME is ") && !sb.toString().contains("CARDNAME is "))) {
            sb.append(keyword.replace(":", " ")).append("\r\n");
        } else if ((keyword.startsWith("Madness") && !sb.toString().contains("Madness"))
                || (keyword.startsWith("Recover") && !sb.toString().contains("Recover"))
                || (keyword.startsWith("Miracle") && !sb.toString().contains("Miracle"))) {
            String[] parts = keyword.split(":");
            sb.append(parts[0]).append(" ").append(ManaCostParser.parse(parts[1])).append("\r\n");
        } else if (keyword.equals("CARDNAME can't be countered.") || keyword.startsWith("May be played")
                || keyword.startsWith("Conspire") || keyword.startsWith("Cascade")
                || keyword.startsWith("Wither")
                || (keyword.startsWith("Epic") && !sb.toString().contains("Epic"))
                || (keyword.startsWith("Split second") && !sb.toString().contains("Split second"))
                || (keyword.startsWith("Devoid"))) {
            sb.append(keyword).append("\r\n");
        } else if (keyword
                .equals("You may cast CARDNAME as though it had flash if you pay 2 more to cast it.")) {
            sb.append(keyword).append("\r\n");
        } else if (keyword.startsWith("Flashback")) {
            sb.append("Flashback");
            if (keyword.contains(" ")) {
                final Cost fbCost = new Cost(keyword.substring(10), true);
                if (!fbCost.isOnlyManaCost()) {
                    sb.append(" -");
                }
                sb.append(" ").append(fbCost.toString()).delete(sb.length() - 2, sb.length());
                if (!fbCost.isOnlyManaCost()) {
                    sb.append(".");
                }
            }
            sb.append("\r\n");
        } else if (keyword.startsWith("Splice")) {
            final Cost cost = new Cost(keyword.substring(19), false);
            sb.append("Splice onto Arcane ").append(cost.toSimpleString()).append("\r\n");
        } else if (keyword.startsWith("Buyback")) {
            final Cost cost = new Cost(keyword.substring(8), false);
            sb.append("Buyback ").append(cost.toSimpleString());
            sb.append(
                    " (You may pay an additional cost as you cast CARDNAME. If you do, put CARDNAME back into your hand as it resolves.)");
            sb.append("\r\n");
        } else if (keyword.startsWith("Entwine")) {
            final Cost cost = new Cost(keyword.substring(8), false);
            sb.append("Entwine ").append(cost.toSimpleString());
            sb.append(" (Choose both if you pay the entwine cost.)");
            sb.append("\r\n");
        } else if (keyword.startsWith("Multikicker")) {
            if (!keyword.endsWith("Generic")) {
                final Cost cost = new Cost(keyword.substring(7), false);
                sb.append("Multikicker ").append(cost.toSimpleString()).append("\r\n");
            }
        } else if (keyword.startsWith("Kicker")) {
            if (!keyword.endsWith("Generic")) {
                final Cost cost = new Cost(keyword.substring(7), false);
                sb.append("Kicker ").append(cost.toSimpleString()).append("\r\n");
            }
        } else if (keyword.startsWith("AlternateAdditionalCost")) {
            final String costString1 = keyword.split(":")[1];
            final String costString2 = keyword.split(":")[2];
            final Cost cost1 = new Cost(costString1, false);
            final Cost cost2 = new Cost(costString2, false);
            sb.append("As an additional cost to cast ").append(state.getName()).append(", ")
                    .append(cost1.toSimpleString()).append(" or pay ").append(cost2.toSimpleString())
                    .append(".\r\n");
        } else if (keyword.startsWith("Storm")) {
            if (sb.toString().contains("Target") || sb.toString().contains("target")) {
                sb.insert(sb.indexOf(
                        "Storm (When you cast this spell, copy it for each spell cast before it this turn.")
                        + 81, " You may choose new targets for the copies.");
            }
        } else if (keyword.startsWith("Replicate") && !sb.toString().contains("you paid its replicate cost.")) {
            if (sb.toString().endsWith("\r\n\r\n")) {
                sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3);
            }
            sb.append(keyword);
            sb.append(" (When you cast this spell, copy it for each time you paid its replicate cost.");
            if (sb.toString().contains("Target") || sb.toString().contains("target")) {
                sb.append(" You may choose new targets for the copies.");
            }
            sb.append(")\r\n");
        } else if (keyword.startsWith("Haunt")) {
            if (sb.toString().endsWith("\r\n\r\n")) {
                sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3);
            }
            sb.append("Haunt (");
            if (state.getType().isCreature()) {
                sb.append("When this creature dies, exile it haunting target creature.");
            } else {
                sb.append("When this spell card is put into a graveyard after resolving, ");
                sb.append("exile it haunting target creature.");
            }
            sb.append(")\r\n");
        } else if (keyword.equals("Convoke")) {
            if (sb.toString().endsWith("\r\n\r\n")) {
                sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3);
            }
            sb.append(
                    "Convoke (Each creature you tap while casting this spell pays for {1} or one mana of that creature's color.)\r\n");
        } else if (keyword.equals("Delve")) {
            if (sb.toString().endsWith("\r\n\r\n")) {
                sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3);
            }
            sb.append(
                    "Delve (Each card you exile from your graveyard while casting this spell pays for {1}.)\r\n");
        } else if (keyword.endsWith(" offering")) {
            if (sb.toString().endsWith("\r\n\r\n")) {
                sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3);
            }
            String offeringType = keyword.split(" ")[0];
            sb.append(keyword);
            sb.append(" (You may cast this card any time you could cast an instant by sacrificing a ");
            sb.append(offeringType);
            sb.append("and paying the difference in mana costs between this and the sacrificed ");
            sb.append(offeringType);
            sb.append(". Mana cost includes color.)");
        } else if (keyword
                .equals("Remove CARDNAME from your deck before playing if you're not playing for ante.")) {
            if (sb.toString().endsWith("\r\n\r\n")) {
                sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3);
            }
            sb.append("Remove CARDNAME from your deck before playing if you're not playing for ante.\r\n");
        } else if (keyword.equals("Rebound")) {
            sb.append(keyword).append(
                    " (If you cast this spell from your hand, exile it as it resolves. At the beginning of your next upkeep, you may cast this card from exile without paying its mana cost.)\r\n");
        }
    }
    return sb;
}

From source file:com.tmwsoft.sns.web.action.MainAction.java

public ActionForward cp_event(HttpServletRequest request, HttpServletResponse response) {
    Map<String, Object> sGlobal = (Map<String, Object>) request.getAttribute("sGlobal");
    Map<String, Object> sConfig = (Map<String, Object>) request.getAttribute("sConfig");
    Map<String, Object> space = (Map<String, Object>) request.getAttribute("space");
    Map<Integer, String> sNames = (Map<Integer, String>) request.getAttribute("sNames");
    int supe_uid = (Integer) sGlobal.get("supe_uid");
    String supe_username = (String) sGlobal.get("supe_username");
    int timestamp = (Integer) sGlobal.get("timestamp");
    int eventid = 0;
    String tempS = request.getParameter("id");
    if (tempS != null) {
        eventid = Common.intval(tempS);/*from w  w w.j  av  a  2s.  c  o  m*/
    }
    tempS = request.getParameter("op");
    String op = Common.empty(tempS) ? "edit" : tempS;
    Map<String, String> menus = new HashMap<String, String>();
    menus.put(op, " class='active'");
    boolean allowmanage = false;
    List<Map<String, Object>> query;
    Map<String, Object> event = null;
    if (eventid != 0) {
        query = dataBaseService.executeQuery("SELECT e.*, ef.* FROM sns_event e LEFT JOIN "
                + " sns_eventfield ef ON e.eventid=ef.eventid WHERE e.eventid='" + eventid + "'");
        event = query.size() > 0 ? query.get(0) : null;
        if (event == null) {
            return showMessage(request, response, "event_does_not_exist");
        }
        int eventGrade = (Integer) event.get("grade");
        int eventUid = (Integer) event.get("uid");
        if ((eventGrade == -1 || eventGrade == 0) && eventUid != supe_uid
                && !Common.checkPerm(request, response, "manageevent")) {
            return showMessage(request, response, "event_under_verify");
        }
        query = dataBaseService.executeQuery(
                "SELECT * FROM sns_userevent WHERE eventid='" + eventid + "' AND uid='" + supe_uid + "'");
        Map<String, Object> value = query.size() > 0 ? query.get(0) : new HashMap<String, Object>();
        sGlobal.put("supe_userevent", value);
        Integer status = (Integer) value.get("status");
        if ((status != null && status >= 3) || Common.checkPerm(request, response, "manageevent")) {
            allowmanage = true;
        }
    }
    Map<Integer, Map<String, Object>> globalEventClass = Common.getCacheDate(request, response,
            "cache/cache_eventclass.jsp", "globalEventClass");
    if (Common.empty(globalEventClass)) {
        try {
            cacheService.eventclass_cache();
        } catch (IOException e) {
            e.printStackTrace();
            return showMessage(request, response, e.getMessage());
        }
        globalEventClass = Common.getCacheDate(request, response, "cache/cache_eventclass.jsp",
                "globalEventClass");
    }
    FileUploadUtil upload;
    try {
        upload = getParsedFileUploadUtil(request);
        if (submitCheckForMulti(request, upload, "eventsubmit")) {
            if (Common.checkPerm(request, response, "seccode") && !mainService.checkSeccode(request, response,
                    sGlobal, sConfig, upload.getParameter("seccode"))) {
                return showMessage(request, response, "incorrect_code");
            }
            Map<String, Object> arr1 = new HashMap<String, Object>();
            String arr1Title;
            try {
                arr1Title = Common.getStr(upload.getParameter("title"), 80, true, true, true, 0, 0, request,
                        response);
            } catch (Exception exception) {
                return showMessage(request, response, exception.getMessage());
            }
            arr1.put("title", arr1Title);
            arr1.put("classid", Common.intval(upload.getParameter("classid")));
            try {
                arr1.put("province", Common.getStr(upload.getParameter("province"), 20, true, true, false, 0, 0,
                        request, response));
            } catch (Exception exception) {
                return showMessage(request, response, exception.getMessage());
            }
            try {
                arr1.put("city", Common.getStr(upload.getParameter("city"), 20, true, true, false, 0, 0,
                        request, response));
            } catch (Exception exception) {
                return showMessage(request, response, exception.getMessage());
            }
            try {
                arr1.put("location", Common.getStr(upload.getParameter("location"), 80, true, true, true, 0, 0,
                        request, response));
            } catch (Exception exception) {
                return showMessage(request, response, exception.getMessage());
            }
            String timeoffset = Common.getTimeOffset(sGlobal, sConfig);
            int arr1Starttime = Common.strToTime(upload.getParameter("starttime"), timeoffset,
                    "yyyy-MM-dd HH:mm");
            arr1.put("starttime", arr1Starttime);
            int arr1Endtime = Common.strToTime(upload.getParameter("endtime"), timeoffset, "yyyy-MM-dd HH:mm");
            arr1.put("endtime", arr1Endtime);
            int arr1Deadline = Common.strToTime(upload.getParameter("deadline"), timeoffset,
                    "yyyy-MM-dd HH:mm");
            arr1.put("deadline", arr1Deadline);
            arr1.put("public", Common.intval(upload.getParameter("public")));
            Map<String, Object> arr2 = new HashMap<String, Object>();
            try {
                arr2.put("detail", Common.getStr(upload.getParameter("detail"), 0, true, true, true, 0, 1,
                        request, response));
            } catch (Exception exception) {
                return showMessage(request, response, exception.getMessage());
            }
            arr2.put("limitnum", Common.intval(upload.getParameter("limitnum")));
            arr2.put("verify", Common.intval(upload.getParameter("verify")));
            arr2.put("allowpost", Common.intval(upload.getParameter("allowpost")));
            arr2.put("allowpic", Common.intval(upload.getParameter("allowpic")));
            arr2.put("allowfellow", Common.intval(upload.getParameter("allowfellow")));
            arr2.put("allowinvite", Common.intval(upload.getParameter("allowinvite")));
            try {
                arr2.put("template", Common.getStr(upload.getParameter("template"), 255, true, true, true, 0, 0,
                        request, response));
            } catch (Exception exception) {
                return showMessage(request, response, exception.getMessage());
            }
            if (Common.empty(arr1.get("title"))) {
                return showMessage(request, response, "event_title_empty");
            } else if (Common.empty(arr1.get("classid"))) {
                return showMessage(request, response, "event_classid_empty");
                // } else if (Common.empty(arr1.get("city"))) {
                // return showMessage(request, response,
                // "event_city_empty");
            } else if (Common.empty(arr2.get("detail"))) {
                return showMessage(request, response, "event_detail_empty");
            } else if (arr1Endtime - arr1Starttime > 60 * 24 * 3600) {
                return showMessage(request, response, "event_bad_time_range");
            } else if (arr1Endtime < arr1Starttime) {
                return showMessage(request, response, "event_bad_endtime");
            } else if (arr1Deadline > arr1Endtime) {
                return showMessage(request, response, "event_bad_deadline");
            } else if (eventid == 0 && arr1Starttime < timestamp) {
                return showMessage(request, response, "event_bad_starttime");
            }
            Map<String, Object> pic = null;
            if (upload.isMultipart()) {
                FileItem fileItem = upload.getFileItem("poster");
                Object picob = mainService.savePic(request, response, fileItem, "-1", arr1Title, 0);
                if (Common.isArray(picob)) {
                    pic = (Map<String, Object>) picob;
                    if (!Common.empty(pic.get("filepath"))) {
                        arr1.put("poster", pic.get("filepath"));
                        arr1.put("thumb", pic.get("thumb"));
                        arr1.put("remote", pic.get("remote"));
                    }
                }
            }
            String tagidString = upload.getParameter("tagid");
            int tagid = 0;
            if (!Common.empty(tagidString) && (eventid == 0 || ((Integer) event.get("uid") == supe_uid)
                    && !tagidString.equals(String.valueOf(event.get("tagid"))))) {
                tagid = Common.intval(tagidString);
                query = dataBaseService.executeQuery("SELECT * FROM sns_tagspace WHERE tagid='" + tagid
                        + "' AND uid='" + supe_uid + "' LIMIT 1");
                Map<String, Object> value = query.size() > 0 ? query.get(0) : null;
                if (value != null) {
                    if ((Integer) value.get("grade") == 9) {
                        arr1.put("tagid", value.get("tagid"));
                    }
                }
            }
            if (eventid != 0) {
                if (allowmanage) {
                    if ((Integer) event.get("grade") == -1 && (Integer) event.get("uid") == supe_uid) {
                        arr1.put("grade", 0);
                    }
                    Map<String, Object> whereData = new HashMap<String, Object>();
                    whereData.put("eventid", eventid);
                    dataBaseService.updateTable("sns_event", arr1, whereData);
                    dataBaseService.updateTable("sns_eventfield", arr2, whereData);
                    tempS = upload.getParameter("sharepic");
                    if (!Common.empty(tempS) && pic != null && !Common.empty(pic.get("picid"))) {
                        Map<String, Object> arr = new HashMap<String, Object>();
                        arr.put("eventid", eventid);
                        arr.put("picid", pic.get("picid"));
                        arr.put("uid", supe_uid);
                        arr.put("username", supe_username);
                        arr.put("dateline", timestamp);
                        dataBaseService.insertTable("sns_eventpic", arr, false, false);
                    }
                    return showMessage(request, response, "do_success", "zone.action?do=event&id=" + eventid,
                            0);
                } else {
                    return showMessage(request, response, "no_privilege_edit_event");
                }
            } else {
                if (!mainService.checkRealName(request, "event")) {
                    return showMessage(request, response, "no_privilege_realname");
                }
                if (!mainService.checkVideoPhoto(request, response, "event")) {
                    return showMessage(request, response, "no_privilege_videophoto");
                }
                switch (mainService.checkNewUser(request, response)) {
                case 1:
                    break;
                case 2:
                    return showMessage(request, response, "no_privilege_newusertime", "", 1,
                            String.valueOf(sConfig.get("newusertime")));
                case 3:
                    return showMessage(request, response, "no_privilege_avatar");
                case 4:
                    return showMessage(request, response, "no_privilege_friendnum", "", 1,
                            String.valueOf(sConfig.get("need_friendnum")));
                case 5:
                    return showMessage(request, response, "no_privilege_email");
                }
                int topicid = mainService.checkTopic(request, Common.intval(upload.getParameter("topicid")),
                        "event");
                arr1.put("topicid", topicid);
                arr1.put("uid", supe_uid);
                arr1.put("username", supe_username);
                arr1.put("dateline", timestamp);
                arr1.put("updatetime", timestamp);
                arr1.put("membernum", 1);
                arr1.put("grade",
                        !Common.empty(Common.checkPerm(request, response, sGlobal, "verifyevent")) ? 0 : 1);
                eventid = dataBaseService.insertTable("sns_event", arr1, true, false);
                if (eventid == 0) {
                    return showMessage(request, response, "event_create_failed");
                }
                arr2.put("eventid", eventid);
                arr2.put("hotuser", "");
                dataBaseService.insertTable("sns_eventfield", arr2, false, false);
                tempS = upload.getParameter("sharepic");
                if (!Common.empty(tempS) && pic != null && !Common.empty(pic.get("picid"))) {
                    Map<String, Object> arr = new HashMap<String, Object>();
                    arr.put("eventid", eventid);
                    arr.put("picid", pic.get("picid"));
                    arr.put("uid", supe_uid);
                    arr.put("username", supe_username);
                    arr.put("dateline", timestamp);
                    dataBaseService.insertTable("sns_eventpic", arr, false, false);
                }
                Map<String, Object> arr3 = new HashMap<String, Object>();
                arr3.put("eventid", eventid);
                arr3.put("uid", supe_uid);
                arr3.put("username", supe_username);
                arr3.put("status", 4);
                arr3.put("fellow", 0);
                tempS = (String) arr1.get("template");
                tempS = tempS == null ? "" : tempS;
                arr3.put("template", tempS);
                arr3.put("dateline", timestamp);
                dataBaseService.insertTable("sns_userevent", arr3, false, false);
                if ((Integer) arr1.get("grade") > 0) {
                    tempS = upload.getParameter("makefeed");
                    if (!Common.empty(tempS)) {
                        feedService.feedPublish(request, response, eventid, "eventid", true);
                    }
                }
                mainService.updateStat(request, "event", false);
                String eventnumsql;
                if (Common.empty(space.get("eventnum"))) {
                    Map<String, Object> whereArr = new HashMap<String, Object>();
                    whereArr.put("uid", space.get("uid"));
                    space.put("eventnum", Common.getCount("sns_event", whereArr, null));
                    eventnumsql = "eventnum=" + space.get("eventnum");
                } else {
                    eventnumsql = "eventnum=eventnum+1";
                }
                Map<String, Integer> reward = Common.getReward("createevent", false, 0, "", true, request,
                        response);
                dataBaseService.executeUpdate("UPDATE sns_space SET " + eventnumsql + ", lastpost='" + timestamp
                        + "', updatetime='" + timestamp + "', credit=credit+" + reward.get("credit")
                        + ", experience=experience+" + reward.get("experience") + " WHERE uid='" + supe_uid
                        + "'");
                String url;
                if (topicid != 0) {
                    mainService.topicJoin(request, topicid, supe_uid, supe_username);
                    url = "zone.action?do=topic&topicid=" + topicid + "&view=event";
                } else {
                    url = "zone.action?do=event&id=" + eventid;
                }
                return showMessage(request, response, "do_success", url, 0);
            }
        }
        if ("invite".equals(op)) {
            Map<String, Object> supeUserEvent = (Map<String, Object>) sGlobal.get("supe_userevent");
            if (((event == null || Common.empty(event.get("allowinvite")))
                    && (supeUserEvent == null || (Integer) supeUserEvent.get("status") < 3))
                    || (supeUserEvent == null || (Integer) supeUserEvent.get("status") < 2)) {
                return showMessage(request, response, "no_privilege_do_eventinvite");
            }
            if (submitCheck(request, "invitesubmit")) {
                Map<String, Object> arr = new LinkedHashMap<String, Object>();
                arr.put("uid", supe_uid);
                arr.put("username", supe_username);
                arr.put("eventid", eventid);
                arr.put("dateline", timestamp);
                List<String> inserts = new ArrayList<String>();
                List<Integer> touids = new ArrayList<Integer>();
                String[] ids = request.getParameterValues("ids[]");
                if (ids != null) {
                    try {
                        StringBuilder builder = new StringBuilder();
                        int touid;
                        for (int i = 0; i < ids.length; i++) {
                            touid = Common.intval(ids[i]);
                            arr.put("touid", touid);
                            arr.put("tousername", Common.getStr(request.getParameterValues("names[]")[i], 15,
                                    true, true, false, 0, 0, request, response));
                            builder.append("(");
                            builder.append(Common.sImplode(arr));
                            builder.append(")");
                            inserts.add(builder.toString());
                            touids.add(touid);
                            builder.delete(0, builder.length());
                        }
                    } catch (Exception exception) {
                        return showMessage(request, response, exception.getMessage());
                    }
                }
                if (!Common.empty(inserts)) {
                    dataBaseService.execute(
                            "INSERT INTO sns_eventinvite (uid, username, eventid, dateline, touid, tousername) VALUES "
                                    + Common.implode(inserts, ","));
                    dataBaseService
                            .executeUpdate("UPDATE sns_space SET eventinvitenum=eventinvitenum+1 WHERE uid IN ("
                                    + Common.sImplode(touids) + ")");
                }
                tempS = request.getParameter("group");
                int getGroup = !Common.empty(tempS) ? Common.intval(tempS) : -1;
                tempS = request.getParameter("page");
                int getPage = Common.empty(tempS) ? 0 : Common.intval(tempS);
                return showMessage(request, response, "do_success", "main.action?ac=event&op=invite&id="
                        + eventid + "&group=" + getGroup + "&page=" + getPage, 2);
            }
            int perpage = 21;
            tempS = request.getParameter("page");
            int page = Common.empty(tempS) ? 0 : Common.intval(tempS);
            if (page < 1)
                page = 1;
            int start = (page - 1) * perpage;
            int maxPage = (Integer) sConfig.get("maxpage");
            if ((tempS = Common.ckStart(start, perpage, maxPage)) != null) {
                return showMessage(request, response, tempS);
            }
            List<String> wherearr = new ArrayList<String>();
            String key = Common.stripSearchKey(request.getParameter("key"));
            if (!Common.empty(key)) {
                wherearr.add(" fusername LIKE '%" + key + "%' ");
            }
            tempS = request.getParameter("group");
            int group = !Common.empty(tempS) ? Common.intval(tempS) : -1;
            if (group >= 0) {
                wherearr.add(" gid='" + group + "'");
            }
            String sql = wherearr.size() > 0 ? "AND" + Common.implode(wherearr, " AND ") : "";
            query = dataBaseService.executeQuery("SELECT COUNT(*) AS cont FROM sns_friend WHERE uid='"
                    + supe_uid + "' AND status='1' " + sql);
            int count = query.size() > 0 ? (Integer) (query.get(0).get("cont")) : 0;
            List<Integer> fuids = new ArrayList<Integer>();
            List<Map<String, Object>> list = null;
            if (count != 0) {
                query = dataBaseService
                        .executeQuery("SELECT * FROM sns_friend WHERE uid='" + supe_uid + "' AND status='1' "
                                + sql + " ORDER BY num DESC, dateline DESC LIMIT " + start + "," + perpage);
                int fuid;
                for (Map<String, Object> value : query) {
                    fuid = (Integer) value.get("fuid");
                    fuids.add(fuid);
                }
                list = query;
            }
            Map<Integer, Integer> joins = new HashMap<Integer, Integer>();
            if (fuids.size() > 0) {
                query = dataBaseService.executeQuery("SELECT uid FROM sns_userevent WHERE eventid='" + eventid
                        + "' AND uid IN (" + Common.sImplode(fuids) + ") AND status > 1");
                int vuid;
                for (Map<String, Object> value : query) {
                    vuid = (Integer) value.get("uid");
                    joins.put(vuid, vuid);
                }
                query = dataBaseService.executeQuery("SELECT touid FROM sns_eventinvite WHERE eventid='"
                        + eventid + "' AND touid IN (" + Common.sImplode(fuids) + ")");
                for (Map<String, Object> value : query) {
                    vuid = (Integer) value.get("touid");
                    joins.put(vuid, vuid);
                }
            }
            Map<Integer, String> groups = Common.getFriendGroup(request);
            Map<Integer, String> groupselect = new HashMap<Integer, String>();
            groupselect.put(group, " selected");
            String multi = Common.multi(request, count, perpage, page, maxPage,
                    "main.action?ac=event&op=invite&id=" + eventid + "&group=" + group + "&key=" + key, null,
                    null);
            request.setAttribute("group", group);
            request.setAttribute("page", page);
            request.setAttribute("list", list);
            request.setAttribute("joins", joins);
            request.setAttribute("multi", multi);
            request.setAttribute("groups", groups);
        } else if ("members".equals(op)) {
            Map<String, Object> supeUserEvent = (Map<String, Object>) sGlobal.get("supe_userevent");
            if (supeUserEvent == null || (Integer) supeUserEvent.get("status") < 3) {
                return showMessage(request, response, "no_privilege_manage_event_members");
            }
            if (submitCheck(request, "memberssubmit")) {
                String[] ids = request.getParameterValues("ids[]");
                boolean rz;
                if (!Common.empty(ids)) {
                    Object object = verify_eventmembers(request, sGlobal, event, ids,
                            request.getParameter("newstatus"));
                    if (object instanceof MessageVO) {
                        return showMessage(request, response, (MessageVO) object);
                    }
                    rz = !Common.empty(object);
                } else {
                    rz = false;
                }
                String status = request.getParameter("status");
                status = status == null ? "" : status;
                if (rz) {
                    return showMessage(request, response, "do_success",
                            "main.action?ac=event&op=members&id=" + eventid + "&status=" + status, 2);
                } else {
                    return showMessage(request, response, "choose_right_eventmember",
                            "main.action?ac=event&op=members&id=" + eventid + "&status=" + status, 5);
                }
            }
            int perpage = 24;
            tempS = request.getParameter("start");
            int start = Common.empty(tempS) ? 0 : Common.intval(tempS);
            int count = 0;
            String wheresql;
            String key = request.getParameter("key");
            String status = request.getParameter("status");
            if (!Common.empty(key)) {
                key = Common.stripSearchKey(key);
                wheresql = " AND username LIKE '%" + key + "%' ";
            } else {
                status = Common.intval(status) + "";
                wheresql = " AND status='" + status + "'";
            }
            int maxPage = (Integer) sConfig.get("maxpage");
            if ((tempS = Common.ckStart(start, perpage, maxPage)) != null) {
                return showMessage(request, response, tempS);
            }
            query = dataBaseService.executeQuery("SELECT * FROM sns_userevent WHERE eventid='" + eventid + "' "
                    + wheresql + " LIMIT " + start + "," + perpage);
            for (Map<String, Object> value : query) {
                tempS = (String) value.get("template");
                if (tempS != null) {
                    value.put("template", Common.nl2br(Common.htmlSpecialChars(tempS)));
                } else {
                    value.put("template", "");
                }
                count++;
            }
            List<Map<String, Object>> list = query;
            if (!Common.empty(key)) {
                if (list.size() > 0) {
                    status = String.valueOf(list.get(0).get("status"));
                } else {
                    status = "";
                }
            }
            String multi;
            try {
                multi = Common.smulti(sGlobal, start, perpage, count,
                        "main.action?ac=event&op=members&id=" + eventid + "&status=" + status + "&key=" + key,
                        null);
            } catch (Exception e) {
                return showMessage(request, response, e.getMessage());
            }
            request.setAttribute("status", status);
            request.setAttribute("list", list);
            request.setAttribute("multi", multi);
        } else if ("member".equals(op)) {
            Map<String, Object> supeUserEvent = (Map<String, Object>) sGlobal.get("supe_userevent");
            if (supeUserEvent == null || (Integer) supeUserEvent.get("status") < 3) {
                return showMessage(request, response, "no_privilege_manage_event_members");
            }
            try {
                if (submitCheck(request, "membersubmit")) {
                    String statusString = request.getParameter("status");
                    int status = Common.intval(statusString);
                    boolean rz;
                    String uid = request.getParameter("uid");
                    if (!Common.empty(uid)) {
                        Object object = verify_eventmembers(request, sGlobal, event, new String[] { uid },
                                statusString);
                        if (object instanceof MessageVO) {
                            return showMessage(request, response, (MessageVO) object);
                        }
                        rz = !Common.empty(object);
                    } else {
                        rz = false;
                    }
                    if (rz) {
                        String refer = request.getParameter("refer");
                        refer = Common.empty(refer)
                                ? "zone.action?do=event&id=" + eventid + "&view=member&status=" + status
                                : refer;
                        return showMessage(request, response, "do_success", refer, 0);
                    } else {
                        return showMessage(request, response, "choose_right_eventmember");
                    }
                }
            } catch (Exception e) {
                return showMessage(request, response, e.getMessage());
            }
            int uid = Common.intval(request.getParameter("uid"));
            query = dataBaseService.executeQuery(
                    "SELECT * FROM sns_userevent WHERE uid='" + uid + "' AND eventid='" + eventid + "'");
            Map<String, Object> userevent = query.size() > 0 ? query.get(0) : null;
            if (Common.empty(userevent)) {
                return showMessage(request, response, "choose_right_eventmember");
            }
            try {
                tempS = Common.nl2br(Common.getStr((String) userevent.get("template"), 255, true, false, true,
                        0, 0, request, response));
            } catch (Exception e) {
                return showMessage(request, response, e.getMessage());
            }
            userevent.put("template", tempS);
            request.setAttribute("uid", uid);
            request.setAttribute("userevent", userevent);
        } else if ("pic".equals(op)) {
            if (!allowmanage) {
                return showMessage(request, response, "no_privilege_manage_event_pic");
            }
            if (submitCheck(request, "deletepicsubmit")) {
                String[] ids = request.getParameterValues("ids[]");
                if (!Common.empty(ids)) {
                    dataBaseService.execute("DELETE FROM sns_eventpic WHERE eventid='" + eventid
                            + "' AND picid IN (" + Common.sImplode(ids) + ")");
                    dataBaseService.executeUpdate(
                            "UPDATE sns_event SET picnum = (SELECT COUNT(*) FROM sns_eventpic WHERE eventid='"
                                    + eventid + "') WHERE eventid = '" + eventid + "'");
                    return showMessage(request, response, "do_success",
                            "main.action?ac=event&op=pic&id=" + eventid, 0);
                } else {
                    return showMessage(request, response, "choose_event_pic");
                }
            }
            int perpage = 16;
            tempS = request.getParameter("page");
            int page = Common.empty(tempS) ? 1 : Common.intval(tempS);
            if (page < 1)
                page = 1;
            int start = (page - 1) * perpage;
            int maxPage = (Integer) sConfig.get("maxpage");
            if ((tempS = Common.ckStart(start, perpage, maxPage)) != null) {
                return showMessage(request, response, tempS);
            }
            String theurl = "main.action?ac=event&id=" + eventid + "&op=pic";
            List<Map<String, Object>> photolist = null;
            int count = 0;
            query = dataBaseService.executeQuery(
                    "SELECT COUNT(*) AS cont FROM sns_eventpic WHERE eventid = '" + eventid + "'");
            if (query.size() > 0) {
                count = (Integer) query.get(0).get("cont");
            }
            if (count != 0) {
                query = dataBaseService.executeQuery("SELECT pic.* FROM sns_eventpic ep LEFT JOIN "
                        + " sns_pic pic ON ep.picid=pic.picid WHERE ep.eventid='" + eventid
                        + "' ORDER BY ep.picid DESC LIMIT " + start + ", " + perpage);
                for (Map<String, Object> value : query) {
                    value.put("pic", Common.pic_get(sConfig, (String) value.get("filepath"),
                            (Integer) value.get("thumb"), (Integer) value.get("remote"), true));
                }
                photolist = query;
            }
            String multi = Common.multi(request, count, perpage, page, maxPage, theurl, null, null);
            int photolistSize = photolist == null ? 0 : photolist.size();
            request.setAttribute("photolistSize", photolistSize);
            request.setAttribute("photolist", photolist);
            request.setAttribute("multi", multi);
        } else if ("thread".equals(op)) {
            if (!allowmanage) {
                return showMessage(request, response, "no_privilege_manage_event_thread");
            }
            if (Common.empty(event.get("tagid"))) {
                return showMessage(request, response, "event_has_not_mtag");
            }
            try {
                if (submitCheck(request, "delthreadsubmit")) {
                    String[] ids = request.getParameterValues("ids[]");
                    if (!Common.empty(ids)) {
                        dataBaseService.execute("DELETE FROM sns_thread WHERE eventid='" + eventid
                                + "' AND tid IN (" + Common.sImplode(ids) + ")");
                        dataBaseService.executeUpdate(
                                "UPDATE sns_event SET threadnum = (SELECT COUNT(*) FROM sns_thread WHERE eventid='"
                                        + eventid + "') WHERE eventid = '" + eventid + "'");
                        return showMessage(request, response, "do_success",
                                "main.action?ac=event&id=" + eventid + "&op=thread", 0);
                    } else {
                        return showMessage(request, response, "choose_event_thread");
                    }
                }
            } catch (Exception e) {
                return showMessage(request, response, e.getMessage());
            }
            int perpage = 20;
            tempS = request.getParameter("page");
            int page = Common.empty(tempS) ? 1 : Common.intval(tempS);
            if (page < 1)
                page = 1;
            int start = (page - 1) * perpage;
            int maxPage = (Integer) sConfig.get("maxpage");
            if ((tempS = Common.ckStart(start, perpage, maxPage)) != null) {
                return showMessage(request, response, tempS);
            }
            List<Map<String, Object>> threadlist = null;
            int count = 0;
            query = dataBaseService
                    .executeQuery("SELECT COUNT(*) AS cont FROM sns_thread WHERE eventid = '" + eventid + "'");
            if (query.size() > 0) {
                count = (Integer) query.get(0).get("cont");
            }
            if (count != 0) {
                query = dataBaseService.executeQuery("SELECT * FROM sns_thread WHERE eventid='" + eventid
                        + "' ORDER BY lastpost DESC LIMIT " + start + ", " + perpage);
                threadlist = query;
            }
            String multi = Common.multi(request, count, perpage, page, maxPage,
                    "main.action?ac=event&id=" + eventid + "&op=thread", null, null);
            request.setAttribute("threadlist", threadlist);
        } else if ("join".equals(op)) {
            boolean popupmenu_box;
            if (mainService.isBlackList((Integer) event.get("uid"), supe_uid) != 0) {
                popupmenu_box = true;
                return showMessage(request, response, "is_blacklist");
            }
            if (Common.empty(sGlobal.get("supe_userevent"))) {
                popupmenu_box = true;
                if (timestamp > (Integer) event.get("endtime")) {
                    return showMessage(request, response, "event_is_over");
                }
                if (timestamp > (Integer) event.get("deadline")) {
                    return showMessage(request, response, "event_meet_deadline");
                }
                if ((Integer) event.get("limitnum") > 0
                        && (Integer) event.get("membernum") >= (Integer) event.get("limitnum")) {
                    return showMessage(request, response, "event_already_full");
                }
                if ((Integer) event.get("public") < 2) {
                    query = dataBaseService.executeQuery("SELECT * FROM sns_eventinvite WHERE eventid = '"
                            + event.get("eventid") + "' AND touid = '" + supe_uid + "' LIMIT 1");
                    Map<String, Object> value = query.size() > 0 ? query.get(0) : null;
                    if (Common.empty(value)) {
                        return showMessage(request, response, "event_join_limit");
                    }
                }
            }
            if (submitCheck(request, "joinsubmit")) {
                Map<String, Object> supe_userevent = (Map<String, Object>) sGlobal.get("supe_userevent");
                boolean supe_usereventNotEmpty = !Common.empty(supe_userevent);
                Integer supe_usereventStatus = supe_usereventNotEmpty ? (Integer) supe_userevent.get("status")
                        : null;
                if (supe_usereventStatus != null && supe_usereventStatus == 0) {
                    Map<String, Object> arr = new HashMap<String, Object>();
                    tempS = request.getParameter("fellow");
                    if (tempS != null) {
                        arr.put("fellow", Common.intval(tempS));
                    }
                    tempS = request.getParameter("template");
                    if (!Common.empty(tempS)) {
                        try {
                            tempS = Common.getStr(tempS, 255, true, true, true, 0, 0, request, response);
                        } catch (Exception e) {
                            return showMessage(request, response, e.getMessage());
                        }
                        arr.put("template", tempS);
                    }
                    if (!Common.empty(arr)) {
                        Map<String, Object> whereData = new HashMap<String, Object>();
                        whereData.put("eventid", eventid);
                        whereData.put("uid", supe_uid);
                        dataBaseService.updateTable("sns_userevent", arr, whereData);
                    }
                    return showMessage(request, response, "do_success", "zone.action?do=event&id=" + eventid,
                            2);
                }
                if (supe_usereventStatus != null && supe_usereventStatus > 1) {
                    Map<String, Object> arr = new HashMap<String, Object>();
                    int num = 0;
                    tempS = request.getParameter("fellow");
                    if (tempS != null) {
                        int fellow = Common.intval(tempS);
                        arr.put("fellow", fellow);
                        Integer supe_usereventFellow = (Integer) supe_userevent.get("fellow");
                        supe_usereventFellow = supe_usereventFellow == null ? 0 : supe_usereventFellow;
                        num = fellow - supe_usereventFellow;
                        int eventLimitnum = (Integer) event.get("limitnum");
                        if (eventLimitnum > 0 && num + (Integer) event.get("membernum") > eventLimitnum) {
                            return showMessage(request, response, "event_already_full");
                        }
                    }
                    tempS = request.getParameter("template");
                    if (!Common.empty(tempS)) {
                        arr.put("template", tempS);
                    }
                    if (!Common.empty(arr)) {
                        Map<String, Object> whereData = new HashMap<String, Object>();
                        whereData.put("eventid", eventid);
                        whereData.put("uid", supe_uid);
                        dataBaseService.updateTable("sns_userevent", arr, whereData);
                    }
                    if (num != 0) {
                        dataBaseService.executeUpdate("UPDATE sns_event SET membernum = membernum + " + num
                                + " WHERE eventid=" + eventid);
                    }
                    return showMessage(request, response, "do_success", "zone.action?do=event&id=" + eventid,
                            0);
                }
                int arrStatus = 2;
                Map<String, Object> arr = new HashMap<String, Object>();
                arr.put("eventid", eventid);
                arr.put("uid", supe_uid);
                arr.put("username", supe_username);
                arr.put("template", event.get("template"));
                arr.put("fellow", 0);
                arr.put("dateline", timestamp);
                int num = 1;
                String numsql;
                tempS = request.getParameter("fellow");
                if (!Common.empty(tempS)) {
                    int fellow = Common.intval(tempS);
                    arr.put("fellow", fellow);
                    num += fellow;
                }
                tempS = request.getParameter("template");
                if (!Common.empty(tempS)) {
                    try {
                        tempS = Common.getStr(tempS, 255, true, true, true, 0, 0, request, response);
                    } catch (Exception e) {
                        return showMessage(request, response, e.getMessage());
                    }
                    arr.put("template", tempS);
                }
                int eventLimitnum = (Integer) event.get("limitnum");
                if (eventLimitnum > 0 && num + (Integer) event.get("membernum") > eventLimitnum) {
                    return showMessage(request, response, "event_will_full");
                }
                numsql = " membernum = membernum + " + num + " ";
                query = dataBaseService.executeQuery("SELECT * FROM sns_eventinvite WHERE eventid='" + eventid
                        + "' AND touid='" + supe_uid + "'");
                Map<String, Object> eventinvite = query.size() > 0 ? query.get(0) : null;
                if (!Common.empty(event.get("verify")) && Common.empty(eventinvite)) {
                    arrStatus = 0;
                }
                arr.put("status", arrStatus);
                if (supe_usereventStatus != null && supe_usereventStatus == 1) {
                    Map<String, Object> whereData = new HashMap<String, Object>();
                    whereData.put("uid", supe_uid);
                    whereData.put("eventid", eventid);
                    dataBaseService.updateTable("sns_userevent", arr, whereData);
                    numsql += ",follownum = follownum - 1 ";
                } else {
                    dataBaseService.insertTable("sns_userevent", arr, false, false);
                }
                int eventUid = (Integer) event.get("uid");
                if (arrStatus == 2) {
                    dataBaseService
                            .execute("UPDATE sns_event SET " + numsql + " WHERE eventid = '" + eventid + "'");
                    if (Common.ckPrivacy(sGlobal, sConfig, space, "join", 0)) {
                        Map<String, Object> title_data = new HashMap<String, Object>();
                        title_data.put("title", event.get("title"));
                        title_data.put("eventid", event.get("eventid"));
                        title_data.put("uid", eventUid);
                        title_data.put("username", sNames.get(eventUid));
                        mainService.addFeed(sGlobal, "event", Common.getMessage(request, "cp_event_join"),
                                title_data, "", null, "", null, null, "", 0, 0, 0, "", false);
                    }
                } else if (arrStatus == 0) {
                    if (supe_usereventStatus != null && supe_usereventStatus == 1) {
                        dataBaseService.executeUpdate(
                                "UPDATE sns_event SET follownum = follownum - 1 WHERE eventid = '" + eventid
                                        + "'");
                    }
                    List<Integer> note_ids = new ArrayList<Integer>();
                    List<String> note_inserts = new ArrayList<String>();
                    int eventEventid = (Integer) event.get("eventid");
                    String note_msg = Common.getMessage(request, "cp_event_join_verify",
                            "zone.action?do=event&id=" + eventEventid, event.get("title"),
                            "main.action?ac=event&id=" + eventEventid + "&op=members&status=0&key="
                                    + supe_username);
                    query = dataBaseService.executeQuery(
                            "SELECT ue.*, sf.* FROM sns_userevent ue LEFT JOIN sns_spacefield sf ON ue.uid=sf.uid WHERE ue.eventid='"
                                    + eventid + "' AND ue.status >= 3");
                    Map<String, Object> privacyM;
                    Set<String> filter;
                    Map<String, Object> filter_noteM;
                    Map<String, Object> note = new HashMap<String, Object>();
                    note.put("type", "eventmember");
                    note.put("authorid", supe_uid);
                    StringBuilder builder = new StringBuilder();
                    int valueUid;
                    for (Map<String, Object> value : query) {
                        tempS = (String) value.get("privacy");
                        privacyM = Common.empty(tempS) ? new HashMap<String, Object>()
                                : (Map<String, Object>) Serializer.unserialize(tempS);
                        value.put("privacy", privacyM);
                        filter_noteM = (Map<String, Object>) privacyM.get("filter_note");
                        filter = Common.empty(filter_noteM) ? new HashSet<String>() : filter_noteM.keySet();
                        if (mainService.checkNoteUid(note, filter)) {
                            valueUid = (Integer) value.get("uid");
                            note_ids.add(valueUid);
                            builder.append("('");
                            builder.append(valueUid);
                            builder.append("', 'eventmember', '1', '");
                            builder.append(supe_uid);
                            builder.append("', '");
                            builder.append(supe_username);
                            builder.append("', '");
                            builder.append(Common.addSlashes(note_msg));
                            builder.append("', '");
                            builder.append(timestamp);
                            builder.append("')");
                            note_inserts.add(builder.toString());
                            builder.delete(0, builder.length());
                        }
                    }
                    if (!Common.empty(note_inserts)) {
                        dataBaseService.execute(
                                "INSERT INTO sns_notification (`uid`, `type`, `new`, `authorid`, `author`, `note`, `dateline`) VALUES "
                                        + Common.implode(note_inserts, ","));
                        dataBaseService.executeUpdate("UPDATE sns_space SET notenum=notenum+1 WHERE uid IN ("
                                + Common.sImplode(note_ids) + ")");
                    }
                    try {
                        mainService.sendMail(request, response, eventUid, "",
                                Common.getMessage(request, "event_application"), note_msg, "event");
                    } catch (Exception e) {
                        return showMessage(request, response, e.getMessage());
                    }
                }
                Common.getReward("joinevent", true, 0, eventid + "", true, request, response);
                mainService.updateStat(request, "eventjoin", false);
                if (!Common.empty(eventinvite)) {
                    dataBaseService.execute("DELETE FROM sns_eventinvite WHERE eventid='" + eventid
                            + "' AND touid='" + supe_uid + "'");
                    dataBaseService
                            .executeUpdate("UPDATE sns_space SET eventinvitenum=eventinvitenum-1 WHERE uid = '"
                                    + supe_uid + "' AND eventinvitenum>0");
                }
                return showMessage(request, response, "do_success", "zone.action?do=event&id=" + eventid, 0);
            }
        } else if ("quit".equals(op)) {
            if (eventid == 0) {
                return showMessage(request, response, "event_does_not_exist");
            }
            if (submitCheck(request, "quitsubmit")) {
                String tourl = "zone.action?do=event&id=" + eventid;
                int uid = supe_uid;
                Map<String, Object> userevent = (Map<String, Object>) sGlobal.get("supe_userevent");
                if (!Common.empty(userevent) && (Integer) event.get("uid") != uid) {
                    dataBaseService.execute(
                            "DELETE FROM sns_userevent WHERE eventid='" + eventid + "' AND uid='" + uid + "'");
                    if ((Integer) userevent.get("status") >= 2) {
                        int num = 1 + (Integer) userevent.get("fellow");
                        dataBaseService.executeUpdate("UPDATE sns_event SET membernum = membernum - " + num
                                + " WHERE eventid='" + eventid + "'");
                    }
                    return showMessage(request, response, "do_success", tourl, 0);
                } else {
                    return showMessage(request, response, "cannot_quit_event", tourl, 2);
                }
            }
        } else if ("follow".equals(op)) {
            if (eventid == 0) {
                return showMessage(request, response, "event_does_not_exist");
            }
            Map<String, Object> supe_userevent = (Map<String, Object>) sGlobal.get("supe_userevent");
            boolean popupmenu_box = false;
            if (!Common.empty(supe_userevent)) {
                popupmenu_box = true;
                if ((Integer) supe_userevent.get("status") <= 1) {
                    return showMessage(request, response, "event_has_followed");
                } else {
                    return showMessage(request, response, "event_has_joint");
                }
            }
            if (submitCheck(request, "followsubmit")) {
                Map<String, Object> arr = new HashMap<String, Object>();
                arr.put("eventid", eventid);
                arr.put("uid", supe_uid);
                arr.put("username", supe_username);
                arr.put("status", 1);
                arr.put("fellow", 0);
                arr.put("template", event.get("template"));
                dataBaseService.insertTable("sns_userevent", arr, false, false);
                dataBaseService.executeUpdate(
                        "UPDATE sns_event SET follownum = follownum + 1 WHERE eventid='" + eventid + "'");
                return showMessage(request, response, "do_success", "zone.action?do=event&id=" + eventid, 0);
            }
        } else if ("cancelfollow".equals(op)) {
            if (eventid == 0) {
                return showMessage(request, response, "event_does_not_exist");
            }
            if (submitCheck(request, "cancelfollowsubmit")) {
                Map<String, Object> supe_userevent = (Map<String, Object>) sGlobal.get("supe_userevent");
                if (!Common.empty(supe_userevent) && (Integer) supe_userevent.get("status") == 1) {
                    dataBaseService.execute("DELETE FROM sns_userevent WHERE uid='" + supe_uid
                            + "' AND eventid='" + eventid + "'");
                    dataBaseService.executeUpdate(
                            "UPDATE sns_event SET follownum = follownum - 1 WHERE eventid='" + eventid + "'");
                }
                return showMessage(request, response, "do_success", "zone.action?do=event&id=" + eventid, 0);
            }
        } else if ("eventinvite".equals(op)) {
            if (!Common.empty(request.getParameter("r"))) {
                tempS = request.getParameter("page");
                String tourl = "main.action?ac=event&op=eventinvite"
                        + (tempS != null ? "&page=" + Common.intval(tempS) : "");
                if (eventid != 0) {
                    dataBaseService.execute("DELETE FROM sns_eventinvite WHERE eventid = '" + eventid
                            + "' AND touid = '" + supe_uid + "'");
                    dataBaseService
                            .executeUpdate("UPDATE sns_space SET eventinvitenum=eventinvitenum-1 WHERE uid = '"
                                    + supe_uid + "' AND eventinvitenum>0");
                } else {
                    dataBaseService.execute("DELETE FROM sns_eventinvite WHERE touid = '" + supe_uid + "'");
                    dataBaseService.executeUpdate(
                            "UPDATE sns_space SET eventinvitenum=0 WHERE uid = '" + supe_uid + "'");
                }
                return showMessage(request, response, "do_success", tourl, 0);
            }
            int perpage = 20;
            tempS = request.getParameter("page");
            int page = Common.empty(tempS) ? 1 : Common.intval(tempS);
            if (page < 1)
                page = 1;
            int start = (page - 1) * perpage;
            int maxPage = (Integer) sConfig.get("maxpage");
            if ((tempS = Common.ckStart(start, perpage, maxPage)) != null) {
                return showMessage(request, response, tempS);
            }
            String theurl = "main.action?ac=event&op=eventinvite";
            Map<String, Object> whereArr = new HashMap<String, Object>();
            whereArr.put("touid", supe_uid);
            int count = Common.intval(Common.getCount("sns_eventinvite", whereArr, null));
            if (count != (Integer) space.get("eventinvitenum")) {
                Map<String, Object> setData = new HashMap<String, Object>();
                setData.put("eventinvitenum", count);
                Map<String, Object> whereData = new HashMap<String, Object>();
                whereData.put("uid", space.get("uid"));
                dataBaseService.updateTable("sns_space", setData, whereData);
            }
            List<Map<String, Object>> eventinvites = null;
            if (count > 0) {
                query = dataBaseService.executeQuery(
                        "SELECT ei.*, e.*, ei.dateline as invitetime FROM sns_eventinvite ei LEFT JOIN sns_event e ON ei.eventid=e.eventid WHERE ei.touid='"
                                + supe_uid + "' limit " + start + ", " + perpage);
                for (Map<String, Object> value : query) {
                    if (!Common.empty(value.get("poster"))) {
                        value.put("pic", Common.pic_get(sConfig, (String) value.get("poster"),
                                (Integer) value.get("thumb"), (Integer) value.get("remote"), true));
                    } else {
                        value.put("pic", globalEventClass.get(value.get("classid")).get("poster"));
                    }
                }
                eventinvites = query;
            }
            String multi = Common.multi(request, count, perpage, page, maxPage, theurl, null, null);
            request.setAttribute("eventinvites", eventinvites);
            request.setAttribute("multi", multi);
        } else if ("acceptinvite".equals(op)) {
            if (eventid == 0) {
                return showMessage(request, response, "event_does_not_exist");
            }
            query = dataBaseService.executeQuery("SELECT * FROM sns_eventinvite WHERE eventid='" + eventid
                    + "' AND touid='" + supe_uid + "' LIMIT 1");
            Map<String, Object> eventinvite = query.size() > 0 ? query.get(0) : null;
            if (Common.empty(eventinvite)) {
                return showMessage(request, response, "eventinvite_does_not_exist");
            }
            dataBaseService.execute(
                    "DELETE FROM sns_eventinvite WHERE eventid='" + eventid + "' AND touid='" + supe_uid + "'");
            dataBaseService.executeUpdate("UPDATE sns_space SET eventinvitenum=eventinvitenum-1 WHERE uid = '"
                    + supe_uid + "' AND eventinvitenum>0");
            if (mainService.isBlackList((Integer) event.get("uid"), supe_uid) != 0) {
                return showMessage(request, response, "is_blacklist");
            }
            if (timestamp > (Integer) event.get("endtime")) {
                return showMessage(request, response, "event_is_over");
            }
            if (timestamp > (Integer) event.get("deadline")) {
                return showMessage(request, response, "event_meet_deadline");
            }
            int eventLimitnum = (Integer) event.get("limitnum");
            int eventMembernum = (Integer) event.get("membernum");
            if (eventLimitnum > 0 && eventMembernum >= eventLimitnum) {
                return showMessage(request, response, "event_already_full");
            }
            String numsql = "membernum = membernum + 1";
            Map<String, Object> supe_userevent = (Map<String, Object>) sGlobal.get("supe_userevent");
            if (Common.empty(supe_userevent)) {
                Map<String, Object> arr = new HashMap<String, Object>();
                arr.put("eventid", eventid);
                arr.put("uid", supe_uid);
                arr.put("username", supe_username);
                arr.put("status", 2);
                arr.put("template", event.get("template"));
                arr.put("fellow", 0);
                arr.put("dateline", timestamp);
                dataBaseService.insertTable("sns_userevent", arr, false, false);
                dataBaseService
                        .executeUpdate("UPDATE sns_event SET " + numsql + " WHERE eventid = '" + eventid + "'");
                if (Common.ckPrivacy(sGlobal, sConfig, space, "join", 0)) {
                    int eventUid = (Integer) event.get("uid");
                    Map<String, Object> title_data = new HashMap<String, Object>();
                    title_data.put("title", event.get("title"));
                    title_data.put("eventid", event.get("eventid"));
                    title_data.put("uid", eventUid);
                    title_data.put("username", sNames.get(eventUid));
                    mainService.addFeed(sGlobal, "event", Common.getMessage(request, "cp_event_join"),
                            title_data, "", null, "", null, null, "", 0, 0, 0, "", false);
                }
            } else if ((Integer) supe_userevent.get("status") < 2) {
                Map<String, Object> arr = new HashMap<String, Object>();
                arr.put("status", 2);
                if ((Integer) supe_userevent.get("status") == 1) {
                    numsql += ",follownum = follownum - 1 ";
                }
                if (eventLimitnum > 0
                        && eventMembernum + (Integer) supe_userevent.get("fellow") > eventLimitnum) {
                    arr.put("fellow", 0);
                }
                Map<String, Object> whereData = new HashMap<String, Object>();
                whereData.put("uid", supe_uid);
                whereData.put("eventid", eventid);
                dataBaseService.updateTable("sns_userevent", arr, whereData);
                dataBaseService
                        .executeUpdate("UPDATE sns_event SET " + numsql + " WHERE eventid = '" + eventid + "'");
                if (Common.ckPrivacy(sGlobal, sConfig, space, "join", 0)) {
                    int eventUid = (Integer) event.get("uid");
                    Map<String, Object> title_data = new HashMap<String, Object>();
                    title_data.put("title", event.get("title"));
                    title_data.put("eventid", event.get("eventid"));
                    title_data.put("uid", eventUid);
                    title_data.put("username", event.get("username"));
                    mainService.addFeed(sGlobal, "event", Common.getMessage(request, "cp_event_join"),
                            title_data, "", null, "", null, null, "", 0, 0, 0, "", false);
                }
            }
            return showMessage(request, response, Common.getMessage(request, "cp_event_accept_success",
                    "zone.action?do=event&id=" + event.get("eventid")));
        } else if ("delete".equals(op)) {
            if (eventid == 0) {
                return showMessage(request, response, "event_does_not_exist");
            }
            if (!allowmanage) {
                return showMessage(request, response, "no_privilege");
            }
            if (submitCheck(request, "deletesubmit")) {
                adminDeleteService.deleteEvents(request, response, sGlobal, new Integer[] { eventid });
                return showMessage(request, response, "do_success", "zone.action?do=event", 2);
            }
        } else if ("print".equals(op)) {
            if (eventid == 0) {
                return showMessage(request, response, "event_does_not_exist");
            }
            if (submitCheck(request, "printsubmit")) {
                List<Map<String, Object>> members;
                List uid;
                if (!Common.empty(request.getParameter("admin"))) {
                    query = dataBaseService.executeQuery("SELECT * FROM sns_userevent WHERE eventid='" + eventid
                            + "' AND status > 1 ORDER BY status DESC, dateline ASC");
                } else {
                    query = dataBaseService.executeQuery("SELECT * FROM sns_userevent WHERE eventid='" + eventid
                            + "' AND status = 2 ORDER BY dateline ASC");
                }
                for (Map<String, Object> value : query) {
                    value.put("template",
                            Common.nl2br(Common.htmlSpecialChars((String) value.get("template"))));
                }
                members = query;
                request.setAttribute("event", event);
                request.setAttribute("members", members);
                return include(request, response, sConfig, sGlobal, "cp_event_sheet.jsp");
            }
        } else if ("close".equals(op)) {
            if (eventid == 0) {
                return showMessage(request, response, "event_does_not_exist");
            }
            if (!allowmanage) {
                return showMessage(request, response, "no_privilege");
            }
            if ((Integer) event.get("grade") < 1 || (Integer) event.get("endtime") > timestamp) {
                return showMessage(request, response, "event_can_not_be_closed");
            }
            if (submitCheck(request, "closesubmit")) {
                Map<String, Object> setData = new HashMap<String, Object>();
                setData.put("grade", -2);
                Map<String, Object> whereData = new HashMap<String, Object>();
                whereData.put("eventid", eventid);
                dataBaseService.updateTable("sns_event", setData, whereData);
                return showMessage(request, response, "do_success", "zone.action?do=event&id=" + eventid, 0);
            }
        } else if ("open".equals(op)) {
            if (eventid == 0) {
                return showMessage(request, response, "event_does_not_exist");
            }
            if (!allowmanage) {
                return showMessage(request, response, "no_privilege");
            }
            if ((Integer) event.get("grade") != -2 || (Integer) event.get("endtime") > timestamp) {
                return showMessage(request, response, "event_can_not_be_opened");
            }
            if (submitCheck(request, "opensubmit")) {
                Map<String, Object> setData = new HashMap<String, Object>();
                setData.put("grade", 1);
                Map<String, Object> whereData = new HashMap<String, Object>();
                whereData.put("eventid", eventid);
                dataBaseService.updateTable("sns_event", setData, whereData);
                return showMessage(request, response, "do_success", "zone.action?do=event&id=" + eventid, 0);
            }
        } else if ("calendar".equals(op)) {
            List<String> match = null;
            String monthGet = request.getParameter("month");
            String dateGet = request.getParameter("date");
            if (Common.empty(monthGet)) {
                match = Common.pregMatch(dateGet, "^(\\d{4}-\\d{1,2})");
                if (!Common.empty(match)) {
                    monthGet = match.get(1);
                }
            }
            if (monthGet != null) {
                match = Common.pregMatch(monthGet, "^(\\d{4})-(\\d{1,2})$");
            }
            int year;
            int month;
            if (!Common.empty(match)) {
                year = Common.intval(match.get(1));
                month = Common.intval(match.get(2));
            } else {
                year = Common.intval(Common.sgmdate(request, "yyyy", timestamp));
                month = Common.intval(Common.sgmdate(request, "MM", timestamp));
            }
            String nextmonth;
            String premonth;
            if (month == 12) {
                nextmonth = (year + 1) + "-1";
                premonth = year + "-11";
            } else if (month == 1) {
                nextmonth = year + "-2";
                premonth = (year - 1) + "-12";
            } else {
                nextmonth = year + "-" + (month + 1);
                premonth = year + "-" + (month - 1);
            }
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MONTH, month - 1);
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            calendar.set(Calendar.YEAR, year);
            int daystart = (int) (calendar.getTimeInMillis() / 1000);
            int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
            int dayscount = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
            calendar.add(Calendar.MONTH, 1);
            int dayend = (int) (calendar.getTimeInMillis() / 1000);
            Map<Integer, Map<String, Object>> days = new LinkedHashMap<Integer, Map<String, Object>>();
            Map<String, Object> subM;
            for (int i = 1; i <= dayscount; i++) {
                subM = new HashMap<String, Object>();
                subM.put("count", 0);
                subM.put("events", new ArrayList<Map<String, Object>>());
                subM.put("class", "");
                days.put(i, subM);
            }
            query = dataBaseService.executeQuery("SELECT * FROM sns_event WHERE starttime < " + dayend
                    + " AND endtime > " + daystart + " ORDER BY eventid DESC LIMIT 100");
            int tempInt;
            int start;
            int end;
            List<Map<String, Object>> subList;
            for (Map<String, Object> value : query) {
                if ((Integer) value.get("public") < 1 || (tempInt = (Integer) value.get("grade")) == 0
                        || tempInt == -1) {
                    continue;
                }
                tempInt = (Integer) value.get("starttime");
                if (tempInt < daystart) {
                    start = 1;
                } else {
                    calendar.setTimeInMillis(tempInt * 1000L);
                    start = calendar.get(Calendar.DAY_OF_MONTH);
                }
                tempInt = (Integer) value.get("endtime");
                if (tempInt > dayend) {
                    end = dayscount;
                } else {
                    calendar.setTimeInMillis(tempInt * 1000L);
                    end = calendar.get(Calendar.DAY_OF_MONTH);
                }
                for (int i = start; i <= end; i++) {
                    subM = days.get(i);
                    tempInt = (Integer) subM.get("count");
                    if (tempInt < 10) {
                        subList = (List<Map<String, Object>>) subM.get("events");
                        subList.add(value);
                        subM.put("count", tempInt + 1);
                        subM.put("class", " on_link");
                    }
                }
            }
            int d = 0;
            if (month == Common.intval(Common.sgmdate(request, "MM", timestamp))
                    && year == Common.intval(Common.sgmdate(request, "yyyy", timestamp))) {
                d = Common.intval(Common.sgmdate(request, "dd", timestamp));
                subM = days.get(d);
                subM.put("class", "on_today");
            }
            if (!Common.empty(dateGet)) {
                int t = Common.strToTime(dateGet, Common.getTimeOffset(sGlobal, sConfig));
                if (month == Common.intval(Common.sgmdate(request, "MM", t))
                        && year == Common.intval(Common.sgmdate(request, "yyyy", t))) {
                    d = Common.intval(Common.sgmdate(request, "dd", t));
                    subM = days.get(d);
                    subM.put("class", "on_select");
                }
            }
            String url = request.getParameter("url");
            url = !Common.empty(url) ? url.replaceAll("date=[\\d\\-]+", "") : "zone.action?do=event";
            request.setAttribute("premonth", premonth);
            request.setAttribute("nextmonth", nextmonth);
            request.setAttribute("year", year);
            request.setAttribute("month", month);
            request.setAttribute("week", week);
            request.setAttribute("days", days);
            request.setAttribute("url", url);
        } else if ("edithot".equals(op)) {
            if (!Common.checkPerm(request, response, "manageevent")) {
                return showMessage(request, response, "no_privilege");
            }
            if (submitCheck(request, "hotsubmit")) {
                int hot = Common.intval(request.getParameter("hot"));
                Map<String, Object> setData = new HashMap<String, Object>();
                setData.put("hot", hot);
                Map<String, Object> whereData = new HashMap<String, Object>();
                whereData.put("eventid", eventid);
                dataBaseService.updateTable("sns_event", setData, whereData);
                if (hot > 0) {
                    feedService.feedPublish(request, response, eventid, "eventid", false);
                } else {
                    whereData.clear();
                    whereData.put("id", eventid);
                    whereData.put("idtype", eventid);
                    dataBaseService.updateTable("sns_feed", setData, whereData);
                }
                return showMessage(request, response, "do_success",
                        "zone.action?uid=" + event.get("uid") + "&do=event&id=" + eventid, 0);
            }
        } else if ("edit".equals(op)) {
            if (eventid != 0) {
                if (!allowmanage) {
                    return showMessage(request, response, "no_privilege_edit_event");
                }
            } else {
                if (!Common.checkPerm(request, response, "allowevent")) {
                    return showMessage(request, response, "no_privilege_add_event");
                }
                if (!mainService.checkRealName(request, "event")) {
                    return showMessage(request, response, "no_privilege_realname");
                }
                if (!mainService.checkVideoPhoto(request, response, "event")) {
                    return showMessage(request, response, "no_privilege_videophoto");
                }
                switch (mainService.checkNewUser(request, response)) {
                case 1:
                    break;
                case 2:
                    return showMessage(request, response, "no_privilege_newusertime", "", 1,
                            String.valueOf(sConfig.get("newusertime")));
                case 3:
                    return showMessage(request, response, "no_privilege_avatar");
                case 4:
                    return showMessage(request, response, "no_privilege_friendnum", "", 1,
                            String.valueOf(sConfig.get("need_friendnum")));
                case 5:
                    return showMessage(request, response, "no_privilege_email");
                }
                event = new HashMap<String, Object>();
                event.put("eventid", "");
                int starttime = (int) (Math.ceil(timestamp / 3600D) * 3600 + 7200);
                event.put("starttime", starttime);
                event.put("endtime", starttime + 14400);
                event.put("deadline", starttime);
                event.put("allowinvite", 1);
                event.put("allowpost", 1);
                event.put("allowpic", 1);
                event.put("allowfellow", 0);
                event.put("verify", 0);
                event.put("public", 2);
                event.put("limitnum", 0);
                event.put("province", space.get("resideprovince"));
                event.put("city", space.get("residecity"));
                Map<String, Object> topic = null;
                int topicid = Common.intval(request.getParameter("topicid"));
                if (topicid != 0) {
                    topic = Common.getTopic(request, topicid);
                }
                Map<String, String> actives = null;
                if (!Common.empty(topic)) {
                    actives = new HashMap<String, String>();
                    actives.put("event", " class=\"active\"");
                }
                request.setAttribute("topicid", topicid);
                request.setAttribute("topic", topic);
            }
            List<Map<String, Object>> mtags = null;
            Integer eventUid = (Integer) event.get("uid");
            if (eventid == 0 || (eventUid != null && eventUid.intValue() == supe_uid)) {
                query = dataBaseService.executeQuery("SELECT mtag.* FROM sns_tagspace st LEFT JOIN "
                        + " sns_mtag mtag ON st.tagid=mtag.tagid WHERE st.uid='" + supe_uid
                        + "' AND st.grade=9");
                mtags = query;
            }
            int tagid = Common.intval(request.getParameter("tagid"));
            if (tagid != 0 && Common.empty(event.get("tagid"))) {
                event.put("tagid", tagid);
            }
            Map<String, Object> subM;
            Object tempOb;
            for (Entry<Integer, Map<String, Object>> entry : globalEventClass.entrySet()) {
                subM = entry.getValue();
                tempOb = subM.get("template");
                if (tempOb != null) {
                    subM.put("template", String.valueOf(tempOb).replace("\r\n", "<br>").replace("\r", "<br>")
                            .replace("\n", "<br>"));
                }
            }
            request.setAttribute("globalEventClass", globalEventClass);
            request.setAttribute("mtags", mtags);
            request.setAttribute("ckPrivacy", Common.ckPrivacy(sGlobal, sConfig, space, "event", 1));
        }
    } catch (Exception e) {
        return showMessage(request, response, e.getMessage());
    }
    request.setAttribute("op", op);
    request.setAttribute("eventid", eventid);
    request.setAttribute("allowmanage", allowmanage);
    request.setAttribute("event", event);
    request.setAttribute("menus", menus);
    return include(request, response, sConfig, sGlobal, "cp_event.jsp");
}

From source file:cn.jcenterhome.web.action.CpAction.java

public ActionForward cp_event(HttpServletRequest request, HttpServletResponse response) {
    Map<String, Object> sGlobal = (Map<String, Object>) request.getAttribute("sGlobal");
    Map<String, Object> sConfig = (Map<String, Object>) request.getAttribute("sConfig");
    Map<String, Object> space = (Map<String, Object>) request.getAttribute("space");
    Map<Integer, String> sNames = (Map<Integer, String>) request.getAttribute("sNames");
    int supe_uid = (Integer) sGlobal.get("supe_uid");
    String supe_username = (String) sGlobal.get("supe_username");
    int timestamp = (Integer) sGlobal.get("timestamp");
    int eventid = 0;
    String tempS = request.getParameter("id");
    if (tempS != null) {
        eventid = Common.intval(tempS);/*from w ww .  j  a v  a  2 s  .  c o  m*/
    }
    tempS = request.getParameter("op");
    String op = Common.empty(tempS) ? "edit" : tempS;
    Map<String, String> menus = new HashMap<String, String>();
    menus.put(op, " class='active'");
    boolean allowmanage = false;
    List<Map<String, Object>> query;
    Map<String, Object> event = null;
    if (eventid != 0) {
        query = dataBaseService.executeQuery("SELECT e.*, ef.* FROM " + JavaCenterHome.getTableName("event")
                + " e LEFT JOIN " + JavaCenterHome.getTableName("eventfield")
                + " ef ON e.eventid=ef.eventid WHERE e.eventid='" + eventid + "'");
        event = query.size() > 0 ? query.get(0) : null;
        if (event == null) {
            return showMessage(request, response, "event_does_not_exist");
        }
        int eventGrade = (Integer) event.get("grade");
        int eventUid = (Integer) event.get("uid");
        if ((eventGrade == -1 || eventGrade == 0) && eventUid != supe_uid
                && !Common.checkPerm(request, response, "manageevent")) {
            return showMessage(request, response, "event_under_verify");
        }
        query = dataBaseService.executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("userevent")
                + " WHERE eventid='" + eventid + "' AND uid='" + supe_uid + "'");
        Map<String, Object> value = query.size() > 0 ? query.get(0) : new HashMap<String, Object>();
        sGlobal.put("supe_userevent", value);
        Integer status = (Integer) value.get("status");
        if ((status != null && status >= 3) || Common.checkPerm(request, response, "manageevent")) {
            allowmanage = true;
        }
    }
    Map<Integer, Map<String, Object>> globalEventClass = Common.getCacheDate(request, response,
            "/data/cache/cache_eventclass.jsp", "globalEventClass");
    if (Common.empty(globalEventClass)) {
        try {
            cacheService.eventclass_cache();
        } catch (IOException e) {
            e.printStackTrace();
            return showMessage(request, response, e.getMessage());
        }
        globalEventClass = Common.getCacheDate(request, response, "/data/cache/cache_eventclass.jsp",
                "globalEventClass");
    }
    FileUploadUtil upload;
    try {
        upload = getParsedFileUploadUtil(request);
        if (submitCheckForMulti(request, upload, "eventsubmit")) {
            if (Common.checkPerm(request, response, "seccode") && !cpService.checkSeccode(request, response,
                    sGlobal, sConfig, upload.getParameter("seccode"))) {
                return showMessage(request, response, "incorrect_code");
            }
            Map<String, Object> arr1 = new HashMap<String, Object>();
            String arr1Title;
            try {
                arr1Title = Common.getStr(upload.getParameter("title"), 80, true, true, true, 0, 0, request,
                        response);
            } catch (Exception exception) {
                return showMessage(request, response, exception.getMessage());
            }
            arr1.put("title", arr1Title);
            arr1.put("classid", Common.intval(upload.getParameter("classid")));
            try {
                arr1.put("province", Common.getStr(upload.getParameter("province"), 20, true, true, false, 0, 0,
                        request, response));
            } catch (Exception exception) {
                return showMessage(request, response, exception.getMessage());
            }
            try {
                arr1.put("city", Common.getStr(upload.getParameter("city"), 20, true, true, false, 0, 0,
                        request, response));
            } catch (Exception exception) {
                return showMessage(request, response, exception.getMessage());
            }
            try {
                arr1.put("location", Common.getStr(upload.getParameter("location"), 80, true, true, true, 0, 0,
                        request, response));
            } catch (Exception exception) {
                return showMessage(request, response, exception.getMessage());
            }
            String timeoffset = Common.getTimeOffset(sGlobal, sConfig);
            int arr1Starttime = Common.strToTime(upload.getParameter("starttime"), timeoffset,
                    "yyyy-MM-dd HH:mm");
            arr1.put("starttime", arr1Starttime);
            int arr1Endtime = Common.strToTime(upload.getParameter("endtime"), timeoffset, "yyyy-MM-dd HH:mm");
            arr1.put("endtime", arr1Endtime);
            int arr1Deadline = Common.strToTime(upload.getParameter("deadline"), timeoffset,
                    "yyyy-MM-dd HH:mm");
            arr1.put("deadline", arr1Deadline);
            arr1.put("public", Common.intval(upload.getParameter("public")));
            Map<String, Object> arr2 = new HashMap<String, Object>();
            try {
                arr2.put("detail", Common.getStr(upload.getParameter("detail"), 0, true, true, true, 0, 1,
                        request, response));
            } catch (Exception exception) {
                return showMessage(request, response, exception.getMessage());
            }
            arr2.put("limitnum", Common.intval(upload.getParameter("limitnum")));
            arr2.put("verify", Common.intval(upload.getParameter("verify")));
            arr2.put("allowpost", Common.intval(upload.getParameter("allowpost")));
            arr2.put("allowpic", Common.intval(upload.getParameter("allowpic")));
            arr2.put("allowfellow", Common.intval(upload.getParameter("allowfellow")));
            arr2.put("allowinvite", Common.intval(upload.getParameter("allowinvite")));
            try {
                arr2.put("template", Common.getStr(upload.getParameter("template"), 255, true, true, true, 0, 0,
                        request, response));
            } catch (Exception exception) {
                return showMessage(request, response, exception.getMessage());
            }
            if (Common.empty(arr1.get("title"))) {
                return showMessage(request, response, "event_title_empty");
            } else if (Common.empty(arr1.get("classid"))) {
                return showMessage(request, response, "event_classid_empty");
            } else if (Common.empty(arr1.get("city"))) {
                return showMessage(request, response, "event_city_empty");
            } else if (Common.empty(arr2.get("detail"))) {
                return showMessage(request, response, "event_detail_empty");
            } else if (arr1Endtime - arr1Starttime > 60 * 24 * 3600) {
                return showMessage(request, response, "event_bad_time_range");
            } else if (arr1Endtime < arr1Starttime) {
                return showMessage(request, response, "event_bad_endtime");
            } else if (arr1Deadline > arr1Endtime) {
                return showMessage(request, response, "event_bad_deadline");
            } else if (eventid == 0 && arr1Starttime < timestamp) {
                return showMessage(request, response, "event_bad_starttime");
            }
            Map<String, Object> pic = null;
            if (upload.isMultipart()) {
                FileItem fileItem = upload.getFileItem("poster");
                Object picob = cpService.savePic(request, response, fileItem, "-1", arr1Title, 0);
                if (Common.isArray(picob)) {
                    pic = (Map<String, Object>) picob;
                    if (!Common.empty(pic.get("filepath"))) {
                        arr1.put("poster", pic.get("filepath"));
                        arr1.put("thumb", pic.get("thumb"));
                        arr1.put("remote", pic.get("remote"));
                    }
                }
            }
            String tagidString = upload.getParameter("tagid");
            int tagid = 0;
            if (!Common.empty(tagidString) && (eventid == 0 || ((Integer) event.get("uid") == supe_uid)
                    && !tagidString.equals(String.valueOf(event.get("tagid"))))) {
                tagid = Common.intval(tagidString);
                query = dataBaseService.executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("tagspace")
                        + " WHERE tagid='" + tagid + "' AND uid='" + supe_uid + "' LIMIT 1");
                Map<String, Object> value = query.size() > 0 ? query.get(0) : null;
                if (value != null) {
                    if ((Integer) value.get("grade") == 9) {
                        arr1.put("tagid", value.get("tagid"));
                    }
                }
            }
            if (eventid != 0) {
                if (allowmanage) {
                    if ((Integer) event.get("grade") == -1 && (Integer) event.get("uid") == supe_uid) {
                        arr1.put("grade", 0);
                    }
                    Map<String, Object> whereData = new HashMap<String, Object>();
                    whereData.put("eventid", eventid);
                    dataBaseService.updateTable("event", arr1, whereData);
                    dataBaseService.updateTable("eventfield", arr2, whereData);
                    tempS = upload.getParameter("sharepic");
                    if (!Common.empty(tempS) && pic != null && !Common.empty(pic.get("picid"))) {
                        Map<String, Object> arr = new HashMap<String, Object>();
                        arr.put("eventid", eventid);
                        arr.put("picid", pic.get("picid"));
                        arr.put("uid", supe_uid);
                        arr.put("username", supe_username);
                        arr.put("dateline", timestamp);
                        dataBaseService.insertTable("eventpic", arr, false, false);
                    }
                    return showMessage(request, response, "do_success", "space.jsp?do=event&id=" + eventid, 0);
                } else {
                    return showMessage(request, response, "no_privilege_edit_event");
                }
            } else {
                if (!cpService.checkRealName(request, "event")) {
                    return showMessage(request, response, "no_privilege_realname");
                }
                if (!cpService.checkVideoPhoto(request, response, "event")) {
                    return showMessage(request, response, "no_privilege_videophoto");
                }
                switch (cpService.checkNewUser(request, response)) {
                case 1:
                    break;
                case 2:
                    return showMessage(request, response, "no_privilege_newusertime", "", 1,
                            String.valueOf(sConfig.get("newusertime")));
                case 3:
                    return showMessage(request, response, "no_privilege_avatar");
                case 4:
                    return showMessage(request, response, "no_privilege_friendnum", "", 1,
                            String.valueOf(sConfig.get("need_friendnum")));
                case 5:
                    return showMessage(request, response, "no_privilege_email");
                }
                int topicid = cpService.checkTopic(request, Common.intval(upload.getParameter("topicid")),
                        "event");
                arr1.put("topicid", topicid);
                arr1.put("uid", supe_uid);
                arr1.put("username", supe_username);
                arr1.put("dateline", timestamp);
                arr1.put("updatetime", timestamp);
                arr1.put("membernum", 1);
                arr1.put("grade",
                        !Common.empty(Common.checkPerm(request, response, sGlobal, "verifyevent")) ? 0 : 1);
                eventid = dataBaseService.insertTable("event", arr1, true, false);
                if (eventid == 0) {
                    return showMessage(request, response, "event_create_failed");
                }
                arr2.put("eventid", eventid);
                arr2.put("hotuser", "");
                dataBaseService.insertTable("eventfield", arr2, false, false);
                tempS = upload.getParameter("sharepic");
                if (!Common.empty(tempS) && pic != null && !Common.empty(pic.get("picid"))) {
                    Map<String, Object> arr = new HashMap<String, Object>();
                    arr.put("eventid", eventid);
                    arr.put("picid", pic.get("picid"));
                    arr.put("uid", supe_uid);
                    arr.put("username", supe_username);
                    arr.put("dateline", timestamp);
                    dataBaseService.insertTable("eventpic", arr, false, false);
                }
                Map<String, Object> arr3 = new HashMap<String, Object>();
                arr3.put("eventid", eventid);
                arr3.put("uid", supe_uid);
                arr3.put("username", supe_username);
                arr3.put("status", 4);
                arr3.put("fellow", 0);
                tempS = (String) arr1.get("template");
                tempS = tempS == null ? "" : tempS;
                arr3.put("template", tempS);
                arr3.put("dateline", timestamp);
                dataBaseService.insertTable("userevent", arr3, false, false);
                if ((Integer) arr1.get("grade") > 0) {
                    tempS = upload.getParameter("makefeed");
                    if (!Common.empty(tempS)) {
                        feedService.feedPublish(request, response, eventid, "eventid", true);
                    }
                }
                cpService.updateStat(request, "event", false);
                String eventnumsql;
                if (Common.empty(space.get("eventnum"))) {
                    Map<String, Object> whereArr = new HashMap<String, Object>();
                    whereArr.put("uid", space.get("uid"));
                    space.put("eventnum", Common.getCount("event", whereArr, null));
                    eventnumsql = "eventnum=" + space.get("eventnum");
                } else {
                    eventnumsql = "eventnum=eventnum+1";
                }
                Map<String, Integer> reward = Common.getReward("createevent", false, 0, "", true, request,
                        response);
                dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("space") + " SET "
                        + eventnumsql + ", lastpost='" + timestamp + "', updatetime='" + timestamp
                        + "', credit=credit+" + reward.get("credit") + ", experience=experience+"
                        + reward.get("experience") + " WHERE uid='" + supe_uid + "'");
                String url;
                if (topicid != 0) {
                    cpService.topicJoin(request, topicid, supe_uid, supe_username);
                    url = "space.jsp?do=topic&topicid=" + topicid + "&view=event";
                } else {
                    url = "space.jsp?do=event&id=" + eventid;
                }
                return showMessage(request, response, "do_success", url, 0);
            }
        }
        if ("invite".equals(op)) {
            Map<String, Object> supeUserEvent = (Map<String, Object>) sGlobal.get("supe_userevent");
            if (((event == null || Common.empty(event.get("allowinvite")))
                    && (supeUserEvent == null || (Integer) supeUserEvent.get("status") < 3))
                    || (supeUserEvent == null || (Integer) supeUserEvent.get("status") < 2)) {
                return showMessage(request, response, "no_privilege_do_eventinvite");
            }
            if (submitCheck(request, "invitesubmit")) {
                Map<String, Object> arr = new LinkedHashMap<String, Object>();
                arr.put("uid", supe_uid);
                arr.put("username", supe_username);
                arr.put("eventid", eventid);
                arr.put("dateline", timestamp);
                List<String> inserts = new ArrayList<String>();
                List<Integer> touids = new ArrayList<Integer>();
                String[] ids = request.getParameterValues("ids[]");
                if (ids != null) {
                    try {
                        StringBuilder builder = new StringBuilder();
                        int touid;
                        for (int i = 0; i < ids.length; i++) {
                            touid = Common.intval(ids[i]);
                            arr.put("touid", touid);
                            arr.put("tousername", Common.getStr(request.getParameterValues("names[]")[i], 15,
                                    true, true, false, 0, 0, request, response));
                            builder.append("(");
                            builder.append(Common.sImplode(arr));
                            builder.append(")");
                            inserts.add(builder.toString());
                            touids.add(touid);
                            builder.delete(0, builder.length());
                        }
                    } catch (Exception exception) {
                        return showMessage(request, response, exception.getMessage());
                    }
                }
                if (!Common.empty(inserts)) {
                    dataBaseService.execute("INSERT INTO " + JavaCenterHome.getTableName("eventinvite")
                            + "(uid, username, eventid, dateline, touid, tousername) VALUES "
                            + Common.implode(inserts, ","));
                    dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("space")
                            + " SET eventinvitenum=eventinvitenum+1 WHERE uid IN (" + Common.sImplode(touids)
                            + ")");
                }
                tempS = request.getParameter("group");
                int getGroup = !Common.empty(tempS) ? Common.intval(tempS) : -1;
                tempS = request.getParameter("page");
                int getPage = Common.empty(tempS) ? 0 : Common.intval(tempS);
                return showMessage(request, response, "do_success",
                        "cp.jsp?ac=event&op=invite&id=" + eventid + "&group=" + getGroup + "&page=" + getPage,
                        2);
            }
            int perpage = 21;
            tempS = request.getParameter("page");
            int page = Common.empty(tempS) ? 0 : Common.intval(tempS);
            if (page < 1)
                page = 1;
            int start = (page - 1) * perpage;
            int maxPage = (Integer) sConfig.get("maxpage");
            if ((tempS = Common.ckStart(start, perpage, maxPage)) != null) {
                return showMessage(request, response, tempS);
            }
            List<String> wherearr = new ArrayList<String>();
            String key = Common.stripSearchKey(request.getParameter("key"));
            if (!Common.empty(key)) {
                wherearr.add(" fusername LIKE '%" + key + "%' ");
            }
            tempS = request.getParameter("group");
            int group = !Common.empty(tempS) ? Common.intval(tempS) : -1;
            if (group >= 0) {
                wherearr.add(" gid='" + group + "'");
            }
            String sql = wherearr.size() > 0 ? "AND" + Common.implode(wherearr, " AND ") : "";
            query = dataBaseService
                    .executeQuery("SELECT COUNT(*) AS cont FROM " + JavaCenterHome.getTableName("friend")
                            + " WHERE uid='" + supe_uid + "' AND status='1' " + sql);
            int count = query.size() > 0 ? (Integer) (query.get(0).get("cont")) : 0;
            List<Integer> fuids = new ArrayList<Integer>();
            List<Map<String, Object>> list = null;
            if (count != 0) {
                query = dataBaseService.executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("friend")
                        + " WHERE uid='" + supe_uid + "' AND status='1' " + sql
                        + " ORDER BY num DESC, dateline DESC LIMIT " + start + "," + perpage);
                int fuid;
                for (Map<String, Object> value : query) {
                    fuid = (Integer) value.get("fuid");
                    Common.realname_set(sGlobal, sConfig, sNames, fuid, (String) value.get("fusername"), "", 0);
                    fuids.add(fuid);
                }
                list = query;
            }
            Map<Integer, Integer> joins = new HashMap<Integer, Integer>();
            if (fuids.size() > 0) {
                query = dataBaseService.executeQuery(
                        "SELECT uid FROM " + JavaCenterHome.getTableName("userevent") + " WHERE eventid='"
                                + eventid + "' AND uid IN (" + Common.sImplode(fuids) + ") AND status > 1");
                int vuid;
                for (Map<String, Object> value : query) {
                    vuid = (Integer) value.get("uid");
                    joins.put(vuid, vuid);
                }
                query = dataBaseService.executeQuery(
                        "SELECT touid FROM " + JavaCenterHome.getTableName("eventinvite") + " WHERE eventid='"
                                + eventid + "' AND touid IN (" + Common.sImplode(fuids) + ")");
                for (Map<String, Object> value : query) {
                    vuid = (Integer) value.get("touid");
                    joins.put(vuid, vuid);
                }
            }
            Map<Integer, String> groups = Common.getFriendGroup(request);
            Map<Integer, String> groupselect = new HashMap<Integer, String>();
            groupselect.put(group, " selected");
            String multi = Common.multi(request, count, perpage, page, maxPage,
                    "cp.jsp?ac=event&op=invite&id=" + eventid + "&group=" + group + "&key=" + key, null, null);
            request.setAttribute("group", group);
            request.setAttribute("page", page);
            request.setAttribute("list", list);
            request.setAttribute("joins", joins);
            request.setAttribute("multi", multi);
            request.setAttribute("groups", groups);
        } else if ("members".equals(op)) {
            Map<String, Object> supeUserEvent = (Map<String, Object>) sGlobal.get("supe_userevent");
            if (supeUserEvent == null || (Integer) supeUserEvent.get("status") < 3) {
                return showMessage(request, response, "no_privilege_manage_event_members");
            }
            if (submitCheck(request, "memberssubmit")) {
                String[] ids = request.getParameterValues("ids[]");
                boolean rz;
                if (!Common.empty(ids)) {
                    Object object = verify_eventmembers(request, sGlobal, event, ids,
                            request.getParameter("newstatus"));
                    if (object instanceof MessageVO) {
                        return showMessage(request, response, (MessageVO) object);
                    }
                    rz = !Common.empty(object);
                } else {
                    rz = false;
                }
                String status = request.getParameter("status");
                status = status == null ? "" : status;
                if (rz) {
                    return showMessage(request, response, "do_success",
                            "cp.jsp?ac=event&op=members&id=" + eventid + "&status=" + status, 2);
                } else {
                    return showMessage(request, response, "choose_right_eventmember",
                            "cp.jsp?ac=event&op=members&id=" + eventid + "&status=" + status, 5);
                }
            }
            int perpage = 24;
            tempS = request.getParameter("start");
            int start = Common.empty(tempS) ? 0 : Common.intval(tempS);
            int count = 0;
            String wheresql;
            String key = request.getParameter("key");
            String status = request.getParameter("status");
            if (!Common.empty(key)) {
                key = Common.stripSearchKey(key);
                wheresql = " AND username LIKE '%" + key + "%' ";
            } else {
                status = Common.intval(status) + "";
                wheresql = " AND status='" + status + "'";
            }
            int maxPage = (Integer) sConfig.get("maxpage");
            if ((tempS = Common.ckStart(start, perpage, maxPage)) != null) {
                return showMessage(request, response, tempS);
            }
            query = dataBaseService.executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("userevent")
                    + " WHERE eventid='" + eventid + "' " + wheresql + " LIMIT " + start + "," + perpage);
            for (Map<String, Object> value : query) {
                Common.realname_set(sGlobal, sConfig, sNames, (Integer) value.get("uid"),
                        (String) value.get("username"), "", 0);
                tempS = (String) value.get("template");
                if (tempS != null) {
                    value.put("template", Common.nl2br(Common.htmlSpecialChars(tempS)));
                } else {
                    value.put("template", "");
                }
                count++;
            }
            List<Map<String, Object>> list = query;
            if (!Common.empty(key)) {
                if (list.size() > 0) {
                    status = String.valueOf(list.get(0).get("status"));
                } else {
                    status = "";
                }
            }
            String multi;
            try {
                multi = Common.smulti(sGlobal, start, perpage, count,
                        "cp.jsp?ac=event&op=members&id=" + eventid + "&status=" + status + "&key=" + key, null);
            } catch (Exception e) {
                return showMessage(request, response, e.getMessage());
            }
            request.setAttribute("status", status);
            request.setAttribute("list", list);
            request.setAttribute("multi", multi);
        } else if ("member".equals(op)) {
            Map<String, Object> supeUserEvent = (Map<String, Object>) sGlobal.get("supe_userevent");
            if (supeUserEvent == null || (Integer) supeUserEvent.get("status") < 3) {
                return showMessage(request, response, "no_privilege_manage_event_members");
            }
            try {
                if (submitCheck(request, "membersubmit")) {
                    String statusString = request.getParameter("status");
                    int status = Common.intval(statusString);
                    boolean rz;
                    String uid = request.getParameter("uid");
                    if (!Common.empty(uid)) {
                        Object object = verify_eventmembers(request, sGlobal, event, new String[] { uid },
                                statusString);
                        if (object instanceof MessageVO) {
                            return showMessage(request, response, (MessageVO) object);
                        }
                        rz = !Common.empty(object);
                    } else {
                        rz = false;
                    }
                    if (rz) {
                        String refer = request.getParameter("refer");
                        refer = Common.empty(refer)
                                ? "space.jsp?do=event&id=" + eventid + "&view=member&status=" + status
                                : refer;
                        return showMessage(request, response, "do_success", refer, 0);
                    } else {
                        return showMessage(request, response, "choose_right_eventmember");
                    }
                }
            } catch (Exception e) {
                return showMessage(request, response, e.getMessage());
            }
            int uid = Common.intval(request.getParameter("uid"));
            query = dataBaseService.executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("userevent")
                    + " WHERE uid='" + uid + "' AND eventid='" + eventid + "'");
            Map<String, Object> userevent = query.size() > 0 ? query.get(0) : null;
            if (Common.empty(userevent)) {
                return showMessage(request, response, "choose_right_eventmember");
            }
            try {
                tempS = Common.nl2br(Common.getStr((String) userevent.get("template"), 255, true, false, true,
                        0, 0, request, response));
            } catch (Exception e) {
                return showMessage(request, response, e.getMessage());
            }
            userevent.put("template", tempS);
            request.setAttribute("uid", uid);
            request.setAttribute("userevent", userevent);
        } else if ("pic".equals(op)) {
            if (!allowmanage) {
                return showMessage(request, response, "no_privilege_manage_event_pic");
            }
            if (submitCheck(request, "deletepicsubmit")) {
                String[] ids = request.getParameterValues("ids[]");
                if (!Common.empty(ids)) {
                    dataBaseService.execute("DELETE FROM " + JavaCenterHome.getTableName("eventpic")
                            + " WHERE eventid='" + eventid + "' AND picid IN (" + Common.sImplode(ids) + ")");
                    dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("event")
                            + " SET picnum = (SELECT COUNT(*) FROM " + JavaCenterHome.getTableName("eventpic")
                            + " WHERE eventid='" + eventid + "') WHERE eventid = '" + eventid + "'");
                    return showMessage(request, response, "do_success", "cp.jsp?ac=event&op=pic&id=" + eventid,
                            0);
                } else {
                    return showMessage(request, response, "choose_event_pic");
                }
            }
            int perpage = 16;
            tempS = request.getParameter("page");
            int page = Common.empty(tempS) ? 1 : Common.intval(tempS);
            if (page < 1)
                page = 1;
            int start = (page - 1) * perpage;
            int maxPage = (Integer) sConfig.get("maxpage");
            if ((tempS = Common.ckStart(start, perpage, maxPage)) != null) {
                return showMessage(request, response, tempS);
            }
            String theurl = "cp.jsp?ac=event&id=" + eventid + "&op=pic";
            List<Map<String, Object>> photolist = null;
            int count = 0;
            query = dataBaseService.executeQuery("SELECT COUNT(*) AS cont FROM "
                    + JavaCenterHome.getTableName("eventpic") + " WHERE eventid = '" + eventid + "'");
            if (query.size() > 0) {
                count = (Integer) query.get(0).get("cont");
            }
            if (count != 0) {
                query = dataBaseService.executeQuery("SELECT pic.* FROM "
                        + JavaCenterHome.getTableName("eventpic") + " ep LEFT JOIN "
                        + JavaCenterHome.getTableName("pic") + " pic ON ep.picid=pic.picid WHERE ep.eventid='"
                        + eventid + "' ORDER BY ep.picid DESC LIMIT " + start + ", " + perpage);
                for (Map<String, Object> value : query) {
                    value.put("pic", Common.pic_get(sConfig, (String) value.get("filepath"),
                            (Integer) value.get("thumb"), (Integer) value.get("remote"), true));
                }
                photolist = query;
            }
            String multi = Common.multi(request, count, perpage, page, maxPage, theurl, null, null);
            int photolistSize = photolist == null ? 0 : photolist.size();
            request.setAttribute("photolistSize", photolistSize);
            request.setAttribute("photolist", photolist);
            request.setAttribute("multi", multi);
        } else if ("thread".equals(op)) {
            if (!allowmanage) {
                return showMessage(request, response, "no_privilege_manage_event_thread");
            }
            if (Common.empty(event.get("tagid"))) {
                return showMessage(request, response, "event_has_not_mtag");
            }
            try {
                if (submitCheck(request, "delthreadsubmit")) {
                    String[] ids = request.getParameterValues("ids[]");
                    if (!Common.empty(ids)) {
                        dataBaseService.execute("DELETE FROM " + JavaCenterHome.getTableName("thread")
                                + " WHERE eventid='" + eventid + "' AND tid IN (" + Common.sImplode(ids) + ")");
                        dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("event")
                                + " SET threadnum = (SELECT COUNT(*) FROM "
                                + JavaCenterHome.getTableName("thread") + " WHERE eventid='" + eventid
                                + "') WHERE eventid = '" + eventid + "'");
                        return showMessage(request, response, "do_success",
                                "cp.jsp?ac=event&id=" + eventid + "&op=thread", 0);
                    } else {
                        return showMessage(request, response, "choose_event_thread");
                    }
                }
            } catch (Exception e) {
                return showMessage(request, response, e.getMessage());
            }
            int perpage = 20;
            tempS = request.getParameter("page");
            int page = Common.empty(tempS) ? 1 : Common.intval(tempS);
            if (page < 1)
                page = 1;
            int start = (page - 1) * perpage;
            int maxPage = (Integer) sConfig.get("maxpage");
            if ((tempS = Common.ckStart(start, perpage, maxPage)) != null) {
                return showMessage(request, response, tempS);
            }
            List<Map<String, Object>> threadlist = null;
            int count = 0;
            query = dataBaseService.executeQuery("SELECT COUNT(*) AS cont FROM "
                    + JavaCenterHome.getTableName("thread") + " WHERE eventid = '" + eventid + "'");
            if (query.size() > 0) {
                count = (Integer) query.get(0).get("cont");
            }
            if (count != 0) {
                query = dataBaseService.executeQuery(
                        "SELECT * FROM " + JavaCenterHome.getTableName("thread") + " WHERE eventid='" + eventid
                                + "' ORDER BY lastpost DESC LIMIT " + start + ", " + perpage);
                for (Map<String, Object> value : query) {
                    Common.realname_set(sGlobal, sConfig, sNames, (Integer) value.get("uid"),
                            (String) value.get("username"), "", 0);
                    Common.realname_set(sGlobal, sConfig, sNames, (Integer) value.get("lastauthorid"),
                            (String) value.get("lastauthor"), "", 0);
                }
                threadlist = query;
            }
            String multi = Common.multi(request, count, perpage, page, maxPage,
                    "cp.jsp?ac=event&id=" + eventid + "&op=thread", null, null);
            request.setAttribute("threadlist", threadlist);
        } else if ("join".equals(op)) {
            boolean popupmenu_box;
            if (cpService.isBlackList((Integer) event.get("uid"), supe_uid) != 0) {
                popupmenu_box = true;
                return showMessage(request, response, "is_blacklist");
            }
            if (Common.empty(sGlobal.get("supe_userevent"))) {
                popupmenu_box = true;
                if (timestamp > (Integer) event.get("endtime")) {
                    return showMessage(request, response, "event_is_over");
                }
                if (timestamp > (Integer) event.get("deadline")) {
                    return showMessage(request, response, "event_meet_deadline");
                }
                if ((Integer) event.get("limitnum") > 0
                        && (Integer) event.get("membernum") >= (Integer) event.get("limitnum")) {
                    return showMessage(request, response, "event_already_full");
                }
                if ((Integer) event.get("public") < 2) {
                    query = dataBaseService.executeQuery(
                            "SELECT * FROM " + JavaCenterHome.getTableName("eventinvite") + " WHERE eventid = '"
                                    + event.get("eventid") + "' AND touid = '" + supe_uid + "' LIMIT 1");
                    Map<String, Object> value = query.size() > 0 ? query.get(0) : null;
                    if (Common.empty(value)) {
                        return showMessage(request, response, "event_join_limit");
                    }
                }
            }
            if (submitCheck(request, "joinsubmit")) {
                Map<String, Object> supe_userevent = (Map<String, Object>) sGlobal.get("supe_userevent");
                boolean supe_usereventNotEmpty = !Common.empty(supe_userevent);
                Integer supe_usereventStatus = supe_usereventNotEmpty ? (Integer) supe_userevent.get("status")
                        : null;
                if (supe_usereventStatus != null && supe_usereventStatus == 0) {
                    Map<String, Object> arr = new HashMap<String, Object>();
                    tempS = request.getParameter("fellow");
                    if (tempS != null) {
                        arr.put("fellow", Common.intval(tempS));
                    }
                    tempS = request.getParameter("template");
                    if (!Common.empty(tempS)) {
                        try {
                            tempS = Common.getStr(tempS, 255, true, true, true, 0, 0, request, response);
                        } catch (Exception e) {
                            return showMessage(request, response, e.getMessage());
                        }
                        arr.put("template", tempS);
                    }
                    if (!Common.empty(arr)) {
                        Map<String, Object> whereData = new HashMap<String, Object>();
                        whereData.put("eventid", eventid);
                        whereData.put("uid", supe_uid);
                        dataBaseService.updateTable("userevent", arr, whereData);
                    }
                    return showMessage(request, response, "do_success", "space.jsp?do=event&id=" + eventid, 2);
                }
                if (supe_usereventStatus != null && supe_usereventStatus > 1) {
                    Map<String, Object> arr = new HashMap<String, Object>();
                    int num = 0;
                    tempS = request.getParameter("fellow");
                    if (tempS != null) {
                        int fellow = Common.intval(tempS);
                        arr.put("fellow", fellow);
                        Integer supe_usereventFellow = (Integer) supe_userevent.get("fellow");
                        supe_usereventFellow = supe_usereventFellow == null ? 0 : supe_usereventFellow;
                        num = fellow - supe_usereventFellow;
                        int eventLimitnum = (Integer) event.get("limitnum");
                        if (eventLimitnum > 0 && num + (Integer) event.get("membernum") > eventLimitnum) {
                            return showMessage(request, response, "event_already_full");
                        }
                    }
                    tempS = request.getParameter("template");
                    if (!Common.empty(tempS)) {
                        arr.put("template", tempS);
                    }
                    if (!Common.empty(arr)) {
                        Map<String, Object> whereData = new HashMap<String, Object>();
                        whereData.put("eventid", eventid);
                        whereData.put("uid", supe_uid);
                        dataBaseService.updateTable("userevent", arr, whereData);
                    }
                    if (num != 0) {
                        dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("event")
                                + " SET membernum = membernum + " + num + " WHERE eventid=" + eventid);
                    }
                    return showMessage(request, response, "do_success", "space.jsp?do=event&id=" + eventid, 0);
                }
                int arrStatus = 2;
                Map<String, Object> arr = new HashMap<String, Object>();
                arr.put("eventid", eventid);
                arr.put("uid", supe_uid);
                arr.put("username", supe_username);
                arr.put("template", event.get("template"));
                arr.put("fellow", 0);
                arr.put("dateline", timestamp);
                int num = 1;
                String numsql;
                tempS = request.getParameter("fellow");
                if (!Common.empty(tempS)) {
                    int fellow = Common.intval(tempS);
                    arr.put("fellow", fellow);
                    num += fellow;
                }
                tempS = request.getParameter("template");
                if (!Common.empty(tempS)) {
                    try {
                        tempS = Common.getStr(tempS, 255, true, true, true, 0, 0, request, response);
                    } catch (Exception e) {
                        return showMessage(request, response, e.getMessage());
                    }
                    arr.put("template", tempS);
                }
                int eventLimitnum = (Integer) event.get("limitnum");
                if (eventLimitnum > 0 && num + (Integer) event.get("membernum") > eventLimitnum) {
                    return showMessage(request, response, "event_will_full");
                }
                numsql = " membernum = membernum + " + num + " ";
                query = dataBaseService
                        .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("eventinvite")
                                + " WHERE eventid='" + eventid + "' AND touid='" + supe_uid + "'");
                Map<String, Object> eventinvite = query.size() > 0 ? query.get(0) : null;
                if (!Common.empty(event.get("verify")) && Common.empty(eventinvite)) {
                    arrStatus = 0;
                }
                arr.put("status", arrStatus);
                if (supe_usereventStatus != null && supe_usereventStatus == 1) {
                    Map<String, Object> whereData = new HashMap<String, Object>();
                    whereData.put("uid", supe_uid);
                    whereData.put("eventid", eventid);
                    dataBaseService.updateTable("userevent", arr, whereData);
                    numsql += ",follownum = follownum - 1 ";
                } else {
                    dataBaseService.insertTable("userevent", arr, false, false);
                }
                int eventUid = (Integer) event.get("uid");
                if (arrStatus == 2) {
                    dataBaseService.execute("UPDATE " + JavaCenterHome.getTableName("event") + " SET " + numsql
                            + " WHERE eventid = '" + eventid + "'");
                    if (Common.ckPrivacy(sGlobal, sConfig, space, "join", 0)) {
                        Common.realname_set(sGlobal, sConfig, sNames, eventUid, (String) event.get("username"),
                                "", 0);
                        Common.realname_get(sGlobal, sConfig, sNames, space);
                        Map<String, Object> title_data = new HashMap<String, Object>();
                        title_data.put("title", event.get("title"));
                        title_data.put("eventid", event.get("eventid"));
                        title_data.put("uid", eventUid);
                        title_data.put("username", sNames.get(eventUid));
                        cpService.addFeed(sGlobal, "event", Common.getMessage(request, "cp_event_join"),
                                title_data, "", null, "", null, null, "", 0, 0, 0, "", false);
                    }
                } else if (arrStatus == 0) {
                    if (supe_usereventStatus != null && supe_usereventStatus == 1) {
                        dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("event")
                                + " SET follownum = follownum - 1 WHERE eventid = '" + eventid + "'");
                    }
                    List<Integer> note_ids = new ArrayList<Integer>();
                    List<String> note_inserts = new ArrayList<String>();
                    int eventEventid = (Integer) event.get("eventid");
                    String note_msg = Common.getMessage(request, "cp_event_join_verify",
                            "space.jsp?do=event&id=" + eventEventid, event.get("title"),
                            "cp.jsp?ac=event&id=" + eventEventid + "&op=members&status=0&key=" + supe_username);
                    query = dataBaseService.executeQuery("SELECT ue.*, sf.* FROM "
                            + JavaCenterHome.getTableName("userevent") + " ue LEFT JOIN "
                            + JavaCenterHome.getTableName("spacefield")
                            + " sf ON ue.uid=sf.uid WHERE ue.eventid='" + eventid + "' AND ue.status >= 3");
                    Map<String, Object> privacyM;
                    Set<String> filter;
                    Map<String, Object> filter_noteM;
                    Map<String, Object> note = new HashMap<String, Object>();
                    note.put("type", "eventmember");
                    note.put("authorid", supe_uid);
                    StringBuilder builder = new StringBuilder();
                    int valueUid;
                    for (Map<String, Object> value : query) {
                        tempS = (String) value.get("privacy");
                        privacyM = Common.empty(tempS) ? new HashMap<String, Object>()
                                : (Map<String, Object>) Serializer.unserialize(tempS);
                        value.put("privacy", privacyM);
                        filter_noteM = (Map<String, Object>) privacyM.get("filter_note");
                        filter = Common.empty(filter_noteM) ? new HashSet<String>() : filter_noteM.keySet();
                        if (cpService.checkNoteUid(note, filter)) {
                            valueUid = (Integer) value.get("uid");
                            note_ids.add(valueUid);
                            builder.append("('");
                            builder.append(valueUid);
                            builder.append("', 'eventmember', '1', '");
                            builder.append(supe_uid);
                            builder.append("', '");
                            builder.append(supe_username);
                            builder.append("', '");
                            builder.append(Common.addSlashes(note_msg));
                            builder.append("', '");
                            builder.append(timestamp);
                            builder.append("')");
                            note_inserts.add(builder.toString());
                            builder.delete(0, builder.length());
                        }
                    }
                    if (!Common.empty(note_inserts)) {
                        dataBaseService.execute("INSERT INTO " + JavaCenterHome.getTableName("notification")
                                + " (`uid`, `type`, `new`, `authorid`, `author`, `note`, `dateline`) VALUES "
                                + Common.implode(note_inserts, ","));
                        dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("space")
                                + " SET notenum=notenum+1 WHERE uid IN (" + Common.sImplode(note_ids) + ")");
                    }
                    try {
                        cpService.sendMail(request, response, eventUid, "",
                                Common.getMessage(request, "event_application"), note_msg, "event");
                    } catch (Exception e) {
                        return showMessage(request, response, e.getMessage());
                    }
                }
                Common.getReward("joinevent", true, 0, eventid + "", true, request, response);
                cpService.updateStat(request, "eventjoin", false);
                if (!Common.empty(eventinvite)) {
                    dataBaseService.execute("DELETE FROM " + JavaCenterHome.getTableName("eventinvite")
                            + " WHERE eventid='" + eventid + "' AND touid='" + supe_uid + "'");
                    dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("space")
                            + " SET eventinvitenum=eventinvitenum-1 WHERE uid = '" + supe_uid
                            + "' AND eventinvitenum>0");
                }
                return showMessage(request, response, "do_success", "space.jsp?do=event&id=" + eventid, 0);
            }
        } else if ("quit".equals(op)) {
            if (eventid == 0) {
                return showMessage(request, response, "event_does_not_exist");
            }
            if (submitCheck(request, "quitsubmit")) {
                String tourl = "space.jsp?do=event&id=" + eventid;
                int uid = supe_uid;
                Map<String, Object> userevent = (Map<String, Object>) sGlobal.get("supe_userevent");
                if (!Common.empty(userevent) && (Integer) event.get("uid") != uid) {
                    dataBaseService.execute("DELETE FROM " + JavaCenterHome.getTableName("userevent")
                            + " WHERE eventid='" + eventid + "' AND uid='" + uid + "'");
                    if ((Integer) userevent.get("status") >= 2) {
                        int num = 1 + (Integer) userevent.get("fellow");
                        dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("event")
                                + " SET membernum = membernum - " + num + " WHERE eventid='" + eventid + "'");
                    }
                    return showMessage(request, response, "do_success", tourl, 0);
                } else {
                    return showMessage(request, response, "cannot_quit_event", tourl, 2);
                }
            }
        } else if ("follow".equals(op)) {
            if (eventid == 0) {
                return showMessage(request, response, "event_does_not_exist");
            }
            Map<String, Object> supe_userevent = (Map<String, Object>) sGlobal.get("supe_userevent");
            boolean popupmenu_box = false;
            if (!Common.empty(supe_userevent)) {
                popupmenu_box = true;
                if ((Integer) supe_userevent.get("status") <= 1) {
                    return showMessage(request, response, "event_has_followed");
                } else {
                    return showMessage(request, response, "event_has_joint");
                }
            }
            if (submitCheck(request, "followsubmit")) {
                Map<String, Object> arr = new HashMap<String, Object>();
                arr.put("eventid", eventid);
                arr.put("uid", supe_uid);
                arr.put("username", supe_username);
                arr.put("status", 1);
                arr.put("fellow", 0);
                arr.put("template", event.get("template"));
                dataBaseService.insertTable("userevent", arr, false, false);
                dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("event")
                        + " SET follownum = follownum + 1 WHERE eventid='" + eventid + "'");
                return showMessage(request, response, "do_success", "space.jsp?do=event&id=" + eventid, 0);
            }
        } else if ("cancelfollow".equals(op)) {
            if (eventid == 0) {
                return showMessage(request, response, "event_does_not_exist");
            }
            if (submitCheck(request, "cancelfollowsubmit")) {
                Map<String, Object> supe_userevent = (Map<String, Object>) sGlobal.get("supe_userevent");
                if (!Common.empty(supe_userevent) && (Integer) supe_userevent.get("status") == 1) {
                    dataBaseService.execute("DELETE FROM " + JavaCenterHome.getTableName("userevent")
                            + " WHERE uid='" + supe_uid + "' AND eventid='" + eventid + "'");
                    dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("event")
                            + " SET follownum = follownum - 1 WHERE eventid='" + eventid + "'");
                }
                return showMessage(request, response, "do_success", "space.jsp?do=event&id=" + eventid, 0);
            }
        } else if ("eventinvite".equals(op)) {
            if (!Common.empty(request.getParameter("r"))) {
                tempS = request.getParameter("page");
                String tourl = "cp.jsp?ac=event&op=eventinvite"
                        + (tempS != null ? "&page=" + Common.intval(tempS) : "");
                if (eventid != 0) {
                    dataBaseService.execute("DELETE FROM " + JavaCenterHome.getTableName("eventinvite")
                            + " WHERE eventid = '" + eventid + "' AND touid = '" + supe_uid + "'");
                    dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("space")
                            + " SET eventinvitenum=eventinvitenum-1 WHERE uid = '" + supe_uid
                            + "' AND eventinvitenum>0");
                } else {
                    dataBaseService.execute("DELETE FROM " + JavaCenterHome.getTableName("eventinvite")
                            + " WHERE touid = '" + supe_uid + "'");
                    dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("space")
                            + " SET eventinvitenum=0 WHERE uid = '" + supe_uid + "'");
                }
                return showMessage(request, response, "do_success", tourl, 0);
            }
            int perpage = 20;
            tempS = request.getParameter("page");
            int page = Common.empty(tempS) ? 1 : Common.intval(tempS);
            if (page < 1)
                page = 1;
            int start = (page - 1) * perpage;
            int maxPage = (Integer) sConfig.get("maxpage");
            if ((tempS = Common.ckStart(start, perpage, maxPage)) != null) {
                return showMessage(request, response, tempS);
            }
            String theurl = "cp.jsp?ac=event&op=eventinvite";
            Map<String, Object> whereArr = new HashMap<String, Object>();
            whereArr.put("touid", supe_uid);
            int count = Common.intval(Common.getCount("eventinvite", whereArr, null));
            if (count != (Integer) space.get("eventinvitenum")) {
                Map<String, Object> setData = new HashMap<String, Object>();
                setData.put("eventinvitenum", count);
                Map<String, Object> whereData = new HashMap<String, Object>();
                whereData.put("uid", space.get("uid"));
                dataBaseService.updateTable("space", setData, whereData);
            }
            List<Map<String, Object>> eventinvites = null;
            if (count > 0) {
                query = dataBaseService.executeQuery("SELECT ei.*, e.*, ei.dateline as invitetime FROM "
                        + JavaCenterHome.getTableName("eventinvite") + " ei LEFT JOIN "
                        + JavaCenterHome.getTableName("event") + " e ON ei.eventid=e.eventid WHERE ei.touid='"
                        + supe_uid + "' limit " + start + ", " + perpage);
                for (Map<String, Object> value : query) {
                    Common.realname_set(sGlobal, sConfig, sNames, (Integer) value.get("uid"),
                            (String) value.get("username"), "", 0);
                    if (!Common.empty(value.get("poster"))) {
                        value.put("pic", Common.pic_get(sConfig, (String) value.get("poster"),
                                (Integer) value.get("thumb"), (Integer) value.get("remote"), true));
                    } else {
                        value.put("pic", globalEventClass.get(value.get("classid")).get("poster"));
                    }
                }
                eventinvites = query;
            }
            String multi = Common.multi(request, count, perpage, page, maxPage, theurl, null, null);
            request.setAttribute("eventinvites", eventinvites);
            request.setAttribute("multi", multi);
        } else if ("acceptinvite".equals(op)) {
            if (eventid == 0) {
                return showMessage(request, response, "event_does_not_exist");
            }
            query = dataBaseService.executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("eventinvite")
                    + " WHERE eventid='" + eventid + "' AND touid='" + supe_uid + "' LIMIT 1");
            Map<String, Object> eventinvite = query.size() > 0 ? query.get(0) : null;
            if (Common.empty(eventinvite)) {
                return showMessage(request, response, "eventinvite_does_not_exist");
            }
            dataBaseService.execute("DELETE FROM " + JavaCenterHome.getTableName("eventinvite")
                    + " WHERE eventid='" + eventid + "' AND touid='" + supe_uid + "'");
            dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("space")
                    + " SET eventinvitenum=eventinvitenum-1 WHERE uid = '" + supe_uid
                    + "' AND eventinvitenum>0");
            if (cpService.isBlackList((Integer) event.get("uid"), supe_uid) != 0) {
                return showMessage(request, response, "is_blacklist");
            }
            if (timestamp > (Integer) event.get("endtime")) {
                return showMessage(request, response, "event_is_over");
            }
            if (timestamp > (Integer) event.get("deadline")) {
                return showMessage(request, response, "event_meet_deadline");
            }
            int eventLimitnum = (Integer) event.get("limitnum");
            int eventMembernum = (Integer) event.get("membernum");
            if (eventLimitnum > 0 && eventMembernum >= eventLimitnum) {
                return showMessage(request, response, "event_already_full");
            }
            String numsql = "membernum = membernum + 1";
            Map<String, Object> supe_userevent = (Map<String, Object>) sGlobal.get("supe_userevent");
            if (Common.empty(supe_userevent)) {
                Map<String, Object> arr = new HashMap<String, Object>();
                arr.put("eventid", eventid);
                arr.put("uid", supe_uid);
                arr.put("username", supe_username);
                arr.put("status", 2);
                arr.put("template", event.get("template"));
                arr.put("fellow", 0);
                arr.put("dateline", timestamp);
                dataBaseService.insertTable("userevent", arr, false, false);
                dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("event") + " SET "
                        + numsql + " WHERE eventid = '" + eventid + "'");
                if (Common.ckPrivacy(sGlobal, sConfig, space, "join", 0)) {
                    int eventUid = (Integer) event.get("uid");
                    Common.realname_set(sGlobal, sConfig, sNames, (Integer) eventUid,
                            (String) event.get("username"), "", 0);
                    Common.realname_get(sGlobal, sConfig, sNames, space);
                    Map<String, Object> title_data = new HashMap<String, Object>();
                    title_data.put("title", event.get("title"));
                    title_data.put("eventid", event.get("eventid"));
                    title_data.put("uid", eventUid);
                    title_data.put("username", sNames.get(eventUid));
                    cpService.addFeed(sGlobal, "event", Common.getMessage(request, "cp_event_join"), title_data,
                            "", null, "", null, null, "", 0, 0, 0, "", false);
                }
            } else if ((Integer) supe_userevent.get("status") < 2) {
                Map<String, Object> arr = new HashMap<String, Object>();
                arr.put("status", 2);
                if ((Integer) supe_userevent.get("status") == 1) {
                    numsql += ",follownum = follownum - 1 ";
                }
                if (eventLimitnum > 0
                        && eventMembernum + (Integer) supe_userevent.get("fellow") > eventLimitnum) {
                    arr.put("fellow", 0);
                }
                Map<String, Object> whereData = new HashMap<String, Object>();
                whereData.put("uid", supe_uid);
                whereData.put("eventid", eventid);
                dataBaseService.updateTable("userevent", arr, whereData);
                dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("event") + " SET "
                        + numsql + " WHERE eventid = '" + eventid + "'");
                if (Common.ckPrivacy(sGlobal, sConfig, space, "join", 0)) {
                    int eventUid = (Integer) event.get("uid");
                    Map<String, Object> title_data = new HashMap<String, Object>();
                    title_data.put("title", event.get("title"));
                    title_data.put("eventid", event.get("eventid"));
                    title_data.put("uid", eventUid);
                    title_data.put("username", event.get("username"));
                    cpService.addFeed(sGlobal, "event", Common.getMessage(request, "cp_event_join"), title_data,
                            "", null, "", null, null, "", 0, 0, 0, "", false);
                }
            }
            return showMessage(request, response, Common.getMessage(request, "cp_event_accept_success",
                    "space.jsp?do=event&id=" + event.get("eventid")));
        } else if ("delete".equals(op)) {
            if (eventid == 0) {
                return showMessage(request, response, "event_does_not_exist");
            }
            if (!allowmanage) {
                return showMessage(request, response, "no_privilege");
            }
            if (submitCheck(request, "deletesubmit")) {
                adminDeleteService.deleteEvents(request, response, sGlobal, new Integer[] { eventid });
                return showMessage(request, response, "do_success", "space.jsp?do=event", 2);
            }
        } else if ("print".equals(op)) {
            if (eventid == 0) {
                return showMessage(request, response, "event_does_not_exist");
            }
            if (submitCheck(request, "printsubmit")) {
                List<Map<String, Object>> members;
                List uid;
                if (!Common.empty(request.getParameter("admin"))) {
                    query = dataBaseService.executeQuery(
                            "SELECT * FROM " + JavaCenterHome.getTableName("userevent") + " WHERE eventid='"
                                    + eventid + "' AND status > 1 ORDER BY status DESC, dateline ASC");
                } else {
                    query = dataBaseService
                            .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("userevent")
                                    + " WHERE eventid='" + eventid + "' AND status = 2 ORDER BY dateline ASC");
                }
                for (Map<String, Object> value : query) {
                    value.put("template",
                            Common.nl2br(Common.htmlSpecialChars((String) value.get("template"))));
                    Common.realname_set(sGlobal, sConfig, sNames, (Integer) value.get("uid"),
                            (String) value.get("username"), "", 0);
                }
                members = query;
                Common.realname_get(sGlobal, sConfig, sNames, space);
                request.setAttribute("event", event);
                request.setAttribute("members", members);
                return include(request, response, sConfig, sGlobal, "cp_event_sheet.jsp");
            }
        } else if ("close".equals(op)) {
            if (eventid == 0) {
                return showMessage(request, response, "event_does_not_exist");
            }
            if (!allowmanage) {
                return showMessage(request, response, "no_privilege");
            }
            if ((Integer) event.get("grade") < 1 || (Integer) event.get("endtime") > timestamp) {
                return showMessage(request, response, "event_can_not_be_closed");
            }
            if (submitCheck(request, "closesubmit")) {
                Map<String, Object> setData = new HashMap<String, Object>();
                setData.put("grade", -2);
                Map<String, Object> whereData = new HashMap<String, Object>();
                whereData.put("eventid", eventid);
                dataBaseService.updateTable("event", setData, whereData);
                return showMessage(request, response, "do_success", "space.jsp?do=event&id=" + eventid, 0);
            }
        } else if ("open".equals(op)) {
            if (eventid == 0) {
                return showMessage(request, response, "event_does_not_exist");
            }
            if (!allowmanage) {
                return showMessage(request, response, "no_privilege");
            }
            if ((Integer) event.get("grade") != -2 || (Integer) event.get("endtime") > timestamp) {
                return showMessage(request, response, "event_can_not_be_opened");
            }
            if (submitCheck(request, "opensubmit")) {
                Map<String, Object> setData = new HashMap<String, Object>();
                setData.put("grade", 1);
                Map<String, Object> whereData = new HashMap<String, Object>();
                whereData.put("eventid", eventid);
                dataBaseService.updateTable("event", setData, whereData);
                return showMessage(request, response, "do_success", "space.jsp?do=event&id=" + eventid, 0);
            }
        } else if ("calendar".equals(op)) {
            List<String> match = null;
            String monthGet = request.getParameter("month");
            String dateGet = request.getParameter("date");
            if (Common.empty(monthGet)) {
                match = Common.pregMatch(dateGet, "^(\\d{4}-\\d{1,2})");
                if (!Common.empty(match)) {
                    monthGet = match.get(1);
                }
            }
            if (monthGet != null) {
                match = Common.pregMatch(monthGet, "^(\\d{4})-(\\d{1,2})$");
            }
            int year;
            int month;
            if (!Common.empty(match)) {
                year = Common.intval(match.get(1));
                month = Common.intval(match.get(2));
            } else {
                year = Common.intval(Common.sgmdate(request, "yyyy", timestamp));
                month = Common.intval(Common.sgmdate(request, "MM", timestamp));
            }
            String nextmonth;
            String premonth;
            if (month == 12) {
                nextmonth = (year + 1) + "-" + "1";
                premonth = year + "-11";
            } else if (month == 1) {
                nextmonth = year + "-2";
                premonth = (year - 1) + "-12";
            } else {
                nextmonth = year + "-" + (month + 1);
                premonth = year + "-" + (month - 1);
            }
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MONTH, month - 1);
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            calendar.set(Calendar.YEAR, year);
            int daystart = (int) (calendar.getTimeInMillis() / 1000);
            int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
            int dayscount = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
            calendar.add(Calendar.MONTH, 1);
            int dayend = (int) (calendar.getTimeInMillis() / 1000);
            Map<Integer, Map<String, Object>> days = new LinkedHashMap<Integer, Map<String, Object>>();
            Map<String, Object> subM;
            for (int i = 1; i <= dayscount; i++) {
                subM = new HashMap<String, Object>();
                subM.put("count", 0);
                subM.put("events", new ArrayList<Map<String, Object>>());
                subM.put("class", "");
                days.put(i, subM);
            }
            query = dataBaseService.executeQuery(
                    "SELECT * FROM " + JavaCenterHome.getTableName("event") + " WHERE starttime < " + dayend
                            + " AND endtime > " + daystart + " ORDER BY eventid DESC LIMIT 100");
            int tempInt;
            int start;
            int end;
            List<Map<String, Object>> subList;
            for (Map<String, Object> value : query) {
                if ((Integer) value.get("public") < 1 || (tempInt = (Integer) value.get("grade")) == 0
                        || tempInt == -1) {
                    continue;
                }
                tempInt = (Integer) value.get("starttime");
                if (tempInt < daystart) {
                    start = 1;
                } else {
                    calendar.setTimeInMillis(tempInt * 1000L);
                    start = calendar.get(Calendar.DAY_OF_MONTH);
                }
                tempInt = (Integer) value.get("endtime");
                if (tempInt > dayend) {
                    end = dayscount;
                } else {
                    calendar.setTimeInMillis(tempInt * 1000L);
                    end = calendar.get(Calendar.DAY_OF_MONTH);
                }
                for (int i = start; i <= end; i++) {
                    subM = days.get(i);
                    tempInt = (Integer) subM.get("count");
                    if (tempInt < 10) {
                        subList = (List<Map<String, Object>>) subM.get("events");
                        subList.add(value);
                        subM.put("count", tempInt + 1);
                        subM.put("class", " on_link");
                    }
                }
            }
            int d = 0;
            if (month == Common.intval(Common.sgmdate(request, "MM", timestamp))
                    && year == Common.intval(Common.sgmdate(request, "yyyy", timestamp))) {
                d = Common.intval(Common.sgmdate(request, "dd", timestamp));
                subM = days.get(d);
                subM.put("class", "on_today");
            }
            if (!Common.empty(dateGet)) {
                int t = Common.strToTime(dateGet, Common.getTimeOffset(sGlobal, sConfig));
                if (month == Common.intval(Common.sgmdate(request, "MM", t))
                        && year == Common.intval(Common.sgmdate(request, "yyyy", t))) {
                    d = Common.intval(Common.sgmdate(request, "dd", t));
                    subM = days.get(d);
                    subM.put("class", "on_select");
                }
            }
            String url = request.getParameter("url");
            url = !Common.empty(url) ? url.replaceAll("date=[\\d\\-]+", "") : "space.jsp?do=event";
            request.setAttribute("premonth", premonth);
            request.setAttribute("nextmonth", nextmonth);
            request.setAttribute("year", year);
            request.setAttribute("month", month);
            request.setAttribute("week", week);
            request.setAttribute("days", days);
            request.setAttribute("url", url);
        } else if ("edithot".equals(op)) {
            if (!Common.checkPerm(request, response, "manageevent")) {
                return showMessage(request, response, "no_privilege");
            }
            if (submitCheck(request, "hotsubmit")) {
                int hot = Common.intval(request.getParameter("hot"));
                Map<String, Object> setData = new HashMap<String, Object>();
                setData.put("hot", hot);
                Map<String, Object> whereData = new HashMap<String, Object>();
                whereData.put("eventid", eventid);
                dataBaseService.updateTable("event", setData, whereData);
                if (hot > 0) {
                    feedService.feedPublish(request, response, eventid, "eventid", false);
                } else {
                    whereData.clear();
                    whereData.put("id", eventid);
                    whereData.put("idtype", eventid);
                    dataBaseService.updateTable("feed", setData, whereData);
                }
                return showMessage(request, response, "do_success",
                        "space.jsp?uid=" + event.get("uid") + "&do=event&id=" + eventid, 0);
            }
        } else if ("edit".equals(op)) {
            if (eventid != 0) {
                if (!allowmanage) {
                    return showMessage(request, response, "no_privilege_edit_event");
                }
            } else {
                if (!Common.checkPerm(request, response, "allowevent")) {
                    return showMessage(request, response, "no_privilege_add_event");
                }
                if (!cpService.checkRealName(request, "event")) {
                    return showMessage(request, response, "no_privilege_realname");
                }
                if (!cpService.checkVideoPhoto(request, response, "event")) {
                    return showMessage(request, response, "no_privilege_videophoto");
                }
                switch (cpService.checkNewUser(request, response)) {
                case 1:
                    break;
                case 2:
                    return showMessage(request, response, "no_privilege_newusertime", "", 1,
                            String.valueOf(sConfig.get("newusertime")));
                case 3:
                    return showMessage(request, response, "no_privilege_avatar");
                case 4:
                    return showMessage(request, response, "no_privilege_friendnum", "", 1,
                            String.valueOf(sConfig.get("need_friendnum")));
                case 5:
                    return showMessage(request, response, "no_privilege_email");
                }
                event = new HashMap<String, Object>();
                event.put("eventid", "");
                int starttime = (int) (Math.ceil(timestamp / 3600D) * 3600 + 7200);
                event.put("starttime", starttime);
                event.put("endtime", starttime + 14400);
                event.put("deadline", starttime);
                event.put("allowinvite", 1);
                event.put("allowpost", 1);
                event.put("allowpic", 1);
                event.put("allowfellow", 0);
                event.put("verify", 0);
                event.put("public", 2);
                event.put("limitnum", 0);
                event.put("province", space.get("resideprovince"));
                event.put("city", space.get("residecity"));
                Map<String, Object> topic = null;
                int topicid = Common.intval(request.getParameter("topicid"));
                if (topicid != 0) {
                    topic = Common.getTopic(request, topicid);
                }
                Map<String, String> actives = null;
                if (!Common.empty(topic)) {
                    actives = new HashMap<String, String>();
                    actives.put("event", " class=\"active\"");
                }
                request.setAttribute("topicid", topicid);
                request.setAttribute("topic", topic);
            }
            List<Map<String, Object>> mtags = null;
            Integer eventUid = (Integer) event.get("uid");
            if (eventid == 0 || (eventUid != null && eventUid.intValue() == supe_uid)) {
                query = dataBaseService.executeQuery("SELECT mtag.* FROM "
                        + JavaCenterHome.getTableName("tagspace") + " st LEFT JOIN "
                        + JavaCenterHome.getTableName("mtag") + " mtag ON st.tagid=mtag.tagid WHERE st.uid='"
                        + supe_uid + "' AND st.grade=9");
                mtags = query;
            }
            int tagid = Common.intval(request.getParameter("tagid"));
            if (tagid != 0 && Common.empty(event.get("tagid"))) {
                event.put("tagid", tagid);
            }
            Map<String, Object> subM;
            Object tempOb;
            for (Entry<Integer, Map<String, Object>> entry : globalEventClass.entrySet()) {
                subM = entry.getValue();
                tempOb = subM.get("template");
                if (tempOb != null) {
                    subM.put("template", String.valueOf(tempOb).replace("\r\n", "<br>").replace("\r", "<br>")
                            .replace("\n", "<br>"));
                }
            }
            request.setAttribute("globalEventClass", globalEventClass);
            request.setAttribute("mtags", mtags);
            request.setAttribute("ckPrivacy", Common.ckPrivacy(sGlobal, sConfig, space, "event", 1));
        }
    } catch (Exception e) {
        return showMessage(request, response, e.getMessage());
    }
    Common.realname_get(sGlobal, sConfig, sNames, space);
    request.setAttribute("op", op);
    request.setAttribute("eventid", eventid);
    request.setAttribute("allowmanage", allowmanage);
    request.setAttribute("event", event);
    request.setAttribute("menus", menus);
    return include(request, response, sConfig, sGlobal, "cp_event.jsp");
}

From source file:com.tmwsoft.sns.web.action.MainAction.java

private Object verify_eventmembers(HttpServletRequest request, Map<String, Object> sGlobal,
        Map<String, Object> event, String[] uids, String statusString) {
    int supe_uid = (Integer) sGlobal.get("supe_uid");
    int timestamp = (Integer) sGlobal.get("timestamp");
    String supe_username = (String) sGlobal.get("supe_username");
    Map<String, Object> supeUserEvent = (Map<String, Object>) sGlobal.get("supe_userevent");
    if (supeUserEvent == null || (Integer) supeUserEvent.get("status") < 3) {
        return new MessageVO("no_privilege_manage_event_members");
    }/*from  ww  w .  j a  v a2  s .  c o m*/
    int eventid = (Integer) supeUserEvent.get("eventid");
    List<Map<String, Object>> query;
    if (event == null || eventid != (Integer) event.get("eventid")) {
        query = dataBaseService.executeQuery("SELECT * FROM sns_event WHERE eventid='" + eventid + "'");
        try {
            event = query.get(0);
        } catch (IndexOutOfBoundsException exception) {
            return new MessageVO(exception.getMessage());
        }
    }
    int status = Common.intval(statusString);
    if (status < -1 || status > 3) {
        return new MessageVO("bad_userevent_status");
    }
    if ((Integer) event.get("verify") == 0 && status == 0) {
        return new MessageVO("event_not_set_verify");
    }
    int eventUid = (Integer) event.get("uid");
    if (status == 3 && supe_uid != eventUid) {
        return new MessageVO("only_creator_can_set_admin");
    }
    List<Integer> newids = new ArrayList<Integer>();
    Map<Integer, Map<String, Object>> userevents = new HashMap<Integer, Map<String, Object>>();
    Map<Integer, String> actions = new HashMap<Integer, String>();
    int num = 0;
    query = dataBaseService.executeQuery(
            "SELECT ue.*, sf.* FROM sns_userevent ue LEFT JOIN sns_spacefield sf ON ue.uid=sf.uid WHERE ue.uid IN ("
                    + Common.sImplode(uids) + ") AND ue.eventid='" + eventid + "'");
    int valueStatus;
    int valueUid;
    for (Map<String, Object> value : query) {
        valueStatus = (Integer) value.get("status");
        valueUid = (Integer) value.get("uid");
        if (valueStatus == status || eventUid == valueUid || valueStatus == 1) {
            continue;
        }
        if (status == 2 || status == 3 || status == 0 || status == -1) {
            newids.add(valueUid);
            userevents.put(valueUid, value);
            if (status == 2) {
                if (valueStatus == 0) {
                    actions.put(valueUid, "set_verify");
                    num += ((Integer) value.get("fellow") + 1);
                } else if (valueStatus == 3) {
                    actions.put(valueUid, "unset_admin");
                }
            } else if (status == 3) {
                actions.put(valueUid, "set_admin");
                if (valueStatus == 0) {
                    num += ((Integer) value.get("fellow") + 1);
                }
            } else if (status == 0) {
                actions.put(valueUid, "unset_verify");
                if (valueStatus >= 2) {
                    num -= ((Integer) value.get("fellow") + 1);
                }
            } else if (status == -1) {
                actions.put(valueUid, "set_delete");
                if (valueStatus >= 2) {
                    num -= ((Integer) value.get("fellow") + 1);
                }
            }
        }
    }
    if (Common.empty(newids))
        return newids;
    int eventLimitnum = (Integer) event.get("limitnum");
    if (eventLimitnum > 0 && (Integer) event.get("membernum") + num > eventLimitnum) {
        return new MessageVO("event_will_full");
    }
    List<String> note_inserts = new ArrayList<String>();
    List<String> feed_inserts = new ArrayList<String>();
    List<Integer> note_ids = new ArrayList<Integer>();
    Map<String, Object> subMap = new HashMap<String, Object>();
    subMap.put("title", event.get("title"));
    subMap.put("eventid", event.get("eventid"));
    subMap.put("uid", event.get("uid"));
    subMap.put("username", event.get("username"));
    Map<String, Object> feedarr = new HashMap<String, Object>();
    feedarr.put("appid", SysConstants.snsConfig.get("SNS_APPID"));
    feedarr.put("icon", "event");
    feedarr.put("uid", "");
    feedarr.put("username", "");
    feedarr.put("dateline", timestamp);
    feedarr.put("title_template", Common.getMessage(request, "cp_event_join"));
    feedarr.put("title_data", subMap);
    feedarr.put("body_template", "");
    feedarr.put("body_data", new HashMap());
    feedarr.put("body_general", "");
    feedarr.put("image_1", "");
    feedarr.put("image_1_link", "");
    feedarr.put("image_2", "");
    feedarr.put("image_2_link", "");
    feedarr.put("image_3", "");
    feedarr.put("image_3_link", "");
    feedarr.put("image_4", "");
    feedarr.put("image_4_link", "");
    feedarr.put("target_ids", "");
    feedarr.put("friend", "friend");
    feedarr = (Map<String, Object>) Common.sStripSlashes(feedarr);
    feedarr.put("title_data", Serializer.serialize(Common.sStripSlashes(feedarr.get("title_data"))));
    feedarr.put("body_data", Serializer.serialize(Common.sStripSlashes(feedarr.get("body_data"))));
    feedarr.put("hash_template",
            Common.md5(feedarr.get("title_template") + "\t" + feedarr.get("body_template")));
    feedarr.put("hash_data", Common.md5(feedarr.get("title_template") + "\t" + feedarr.get("title_data") + "\t"
            + feedarr.get("body_template") + "\t" + feedarr.get("body_data")));
    feedarr = (Map<String, Object>) Common.sAddSlashes(feedarr);
    Map<String, Object> mapInUserevents;
    StringBuilder builder = new StringBuilder();
    for (int id : newids) {
        mapInUserevents = userevents.get(id);
        if (status > 1 && (Integer) mapInUserevents.get("status") == 0) {
            feedarr.put("uid", mapInUserevents.get("uid"));
            feedarr.put("username", mapInUserevents.get("username"));
            builder.append("('");
            builder.append(feedarr.get("appid"));
            builder.append("', 'event', '");
            builder.append(feedarr.get("uid"));
            builder.append("', '");
            builder.append(feedarr.get("username"));
            builder.append("', '");
            builder.append(feedarr.get("dateline"));
            builder.append("', '0', '");
            builder.append(feedarr.get("hash_template"));
            builder.append("', '");
            builder.append(feedarr.get("hash_data"));
            builder.append("', '");
            builder.append(feedarr.get("title_template"));
            builder.append("', '");
            builder.append(feedarr.get("title_data"));
            builder.append("', '");
            builder.append(feedarr.get("body_template"));
            builder.append("', '");
            builder.append(feedarr.get("body_data"));
            builder.append("', '");
            builder.append(feedarr.get("body_general"));
            builder.append("', '");
            builder.append(feedarr.get("image_1"));
            builder.append("', '");
            builder.append(feedarr.get("image_1_link"));
            builder.append("', '");
            builder.append(feedarr.get("image_2"));
            builder.append("', '");
            builder.append(feedarr.get("image_2_link"));
            builder.append("', '");
            builder.append(feedarr.get("image_3"));
            builder.append("', '");
            builder.append(feedarr.get("image_3_link"));
            builder.append("', '");
            builder.append(feedarr.get("image_4"));
            builder.append("', '");
            builder.append(feedarr.get("image_4_link"));
            builder.append("')");
            feed_inserts.add(builder.toString());
            builder.delete(0, builder.length());
        }
        mapInUserevents.put("privacy",
                Common.empty(mapInUserevents.get("privacy")) ? new HashMap<String, Object>()
                        : Serializer.unserialize((String) mapInUserevents.get("privacy")));
        Map<String, Object> tempM = (Map<String, Object>) ((Map<String, Object>) mapInUserevents.get("privacy"))
                .get("filter_note");
        Set<String> filter = Common.empty(tempM) ? new HashSet<String>() : tempM.keySet();
        if (tempM == null) {
            tempM = new HashMap<String, Object>();
        } else {
            tempM.clear();
        }
        tempM.put("type", "eventmemberstatus");
        tempM.put("authorid", supe_uid);
        if (mainService.checkNoteUid(tempM, filter)) {
            note_ids.add(id);
            String actionsValue = actions.get(id);
            actionsValue = actionsValue == null ? "" : actionsValue;
            String note_msg = Common.getMessage(request, "cp_eventmember_" + actionsValue,
                    "zone.action?do=event&id=" + event.get("eventid"), event.get("title"));
            builder.append("('");
            builder.append(id);
            builder.append("', 'eventmemberstatus', '1', '");
            builder.append(supe_uid);
            builder.append("', '");
            builder.append(supe_username);
            builder.append("', '");
            builder.append(Common.addSlashes(note_msg));
            builder.append("', '");
            builder.append(timestamp);
            builder.append("')");
            note_inserts.add(builder.toString());
            builder.delete(0, builder.length());
        }
    }
    if (!Common.empty(note_ids)) {
        dataBaseService.execute(
                "INSERT INTO sns_notification (`uid`, `type`, `new`, `authorid`, `author`, `note`, `dateline`) VALUES "
                        + Common.implode(note_inserts, ","));
        dataBaseService.executeUpdate(
                "UPDATE sns_space SET notenum=notenum+1 WHERE uid IN (" + Common.sImplode(note_ids) + ")");
    }
    if (!Common.empty(feed_inserts)) {
        dataBaseService.execute(
                "INSERT INTO sns_feed (`appid` ,`icon` ,`uid` ,`username` ,`dateline` ,`friend` ,`hash_template` ,`hash_data` ,`title_template` ,`title_data` ,`body_template` ,`body_data` ,`body_general` ,`image_1` ,`image_1_link` ,`image_2` ,`image_2_link` ,`image_3` ,`image_3_link` ,`image_4` ,`image_4_link`)  VALUES "
                        + Common.implode(feed_inserts, ","));
    }
    if (status == -1) {
        dataBaseService.execute("DELETE FROM sns_userevent WHERE uid IN (" + Common.sImplode(newids)
                + ") AND eventid='" + eventid + "'");
    } else {
        dataBaseService.executeUpdate("UPDATE sns_userevent SET status='" + status + "' WHERE uid IN ("
                + Common.sImplode(newids) + ") AND eventid='" + eventid + "'");
    }
    if (num != 0) {
        dataBaseService.executeUpdate(
                "UPDATE sns_event SET membernum = membernum + " + num + " WHERE eventid='" + eventid + "'");
    }
    return newids;
}

From source file:cn.jcenterhome.web.action.CpAction.java

private Object verify_eventmembers(HttpServletRequest request, Map<String, Object> sGlobal,
        Map<String, Object> event, String[] uids, String statusString) {
    int supe_uid = (Integer) sGlobal.get("supe_uid");
    int timestamp = (Integer) sGlobal.get("timestamp");
    String supe_username = (String) sGlobal.get("supe_username");
    Map<String, Object> supeUserEvent = (Map<String, Object>) sGlobal.get("supe_userevent");
    if (supeUserEvent == null || (Integer) supeUserEvent.get("status") < 3) {
        return new MessageVO("no_privilege_manage_event_members");
    }/*from  w  ww.j  a v a 2  s .c  o  m*/
    int eventid = (Integer) supeUserEvent.get("eventid");
    List<Map<String, Object>> query;
    if (event == null || eventid != (Integer) event.get("eventid")) {
        query = dataBaseService.executeQuery(
                "SELECT * FROM " + JavaCenterHome.getTableName("event") + " WHERE eventid='" + eventid + "'");
        try {
            event = query.get(0);
        } catch (IndexOutOfBoundsException exception) {
            return new MessageVO(exception.getMessage());
        }
    }
    int status = Common.intval(statusString);
    if (status < -1 || status > 3) {
        return new MessageVO("bad_userevent_status");
    }
    if ((Integer) event.get("verify") == 0 && status == 0) {
        return new MessageVO("event_not_set_verify");
    }
    int eventUid = (Integer) event.get("uid");
    if (status == 3 && supe_uid != eventUid) {
        return new MessageVO("only_creator_can_set_admin");
    }
    List<Integer> newids = new ArrayList<Integer>();
    Map<Integer, Map<String, Object>> userevents = new HashMap<Integer, Map<String, Object>>();
    Map<Integer, String> actions = new HashMap<Integer, String>();
    int num = 0;
    query = dataBaseService.executeQuery(
            "SELECT ue.*, sf.* FROM " + JavaCenterHome.getTableName("userevent") + " ue LEFT JOIN "
                    + JavaCenterHome.getTableName("spacefield") + " sf ON ue.uid=sf.uid WHERE ue.uid IN ("
                    + Common.sImplode(uids) + ") AND ue.eventid='" + eventid + "'");
    int valueStatus;
    int valueUid;
    for (Map<String, Object> value : query) {
        valueStatus = (Integer) value.get("status");
        valueUid = (Integer) value.get("uid");
        if (valueStatus == status || eventUid == valueUid || valueStatus == 1) {
            continue;
        }
        if (status == 2 || status == 3 || status == 0 || status == -1) {
            newids.add(valueUid);
            userevents.put(valueUid, value);
            if (status == 2) {
                if (valueStatus == 0) {
                    actions.put(valueUid, "set_verify");
                    num += ((Integer) value.get("fellow") + 1);
                } else if (valueStatus == 3) {
                    actions.put(valueUid, "unset_admin");
                }
            } else if (status == 3) {
                actions.put(valueUid, "set_admin");
                if (valueStatus == 0) {
                    num += ((Integer) value.get("fellow") + 1);
                }
            } else if (status == 0) {
                actions.put(valueUid, "unset_verify");
                if (valueStatus >= 2) {
                    num -= ((Integer) value.get("fellow") + 1);
                }
            } else if (status == -1) {
                actions.put(valueUid, "set_delete");
                if (valueStatus >= 2) {
                    num -= ((Integer) value.get("fellow") + 1);
                }
            }
        }
    }
    if (Common.empty(newids))
        return newids;
    int eventLimitnum = (Integer) event.get("limitnum");
    if (eventLimitnum > 0 && (Integer) event.get("membernum") + num > eventLimitnum) {
        return new MessageVO("event_will_full");
    }
    List<String> note_inserts = new ArrayList<String>();
    List<String> feed_inserts = new ArrayList<String>();
    List<Integer> note_ids = new ArrayList<Integer>();
    Map<String, Object> subMap = new HashMap<String, Object>();
    subMap.put("title", event.get("title"));
    subMap.put("eventid", event.get("eventid"));
    subMap.put("uid", event.get("uid"));
    subMap.put("username", event.get("username"));
    Map<String, Object> feedarr = new HashMap<String, Object>();
    feedarr.put("appid", JavaCenterHome.jchConfig.get("JC_APPID"));
    feedarr.put("icon", "event");
    feedarr.put("uid", "");
    feedarr.put("username", "");
    feedarr.put("dateline", timestamp);
    feedarr.put("title_template", Common.getMessage(request, "cp_event_join"));
    feedarr.put("title_data", subMap);
    feedarr.put("body_template", "");
    feedarr.put("body_data", new HashMap());
    feedarr.put("body_general", "");
    feedarr.put("image_1", "");
    feedarr.put("image_1_link", "");
    feedarr.put("image_2", "");
    feedarr.put("image_2_link", "");
    feedarr.put("image_3", "");
    feedarr.put("image_3_link", "");
    feedarr.put("image_4", "");
    feedarr.put("image_4_link", "");
    feedarr.put("target_ids", "");
    feedarr.put("friend", "friend");
    feedarr = (Map<String, Object>) Common.sStripSlashes(feedarr);
    feedarr.put("title_data", Serializer.serialize(Common.sStripSlashes(feedarr.get("title_data"))));
    feedarr.put("body_data", Serializer.serialize(Common.sStripSlashes(feedarr.get("body_data"))));
    feedarr.put("hash_template",
            Common.md5(feedarr.get("title_template") + "\t" + feedarr.get("body_template")));
    feedarr.put("hash_data", Common.md5(feedarr.get("title_template") + "\t" + feedarr.get("title_data") + "\t"
            + feedarr.get("body_template") + "\t" + feedarr.get("body_data")));
    feedarr = (Map<String, Object>) Common.sAddSlashes(feedarr);
    Map<String, Object> mapInUserevents;
    StringBuilder builder = new StringBuilder();
    for (int id : newids) {
        mapInUserevents = userevents.get(id);
        if (status > 1 && (Integer) mapInUserevents.get("status") == 0) {
            feedarr.put("uid", mapInUserevents.get("uid"));
            feedarr.put("username", mapInUserevents.get("username"));
            builder.append("('");
            builder.append(feedarr.get("appid"));
            builder.append("', 'event', '");
            builder.append(feedarr.get("uid"));
            builder.append("', '");
            builder.append(feedarr.get("username"));
            builder.append("', '");
            builder.append(feedarr.get("dateline"));
            builder.append("', '0', '");
            builder.append(feedarr.get("hash_template"));
            builder.append("', '");
            builder.append(feedarr.get("hash_data"));
            builder.append("', '");
            builder.append(feedarr.get("title_template"));
            builder.append("', '");
            builder.append(feedarr.get("title_data"));
            builder.append("', '");
            builder.append(feedarr.get("body_template"));
            builder.append("', '");
            builder.append(feedarr.get("body_data"));
            builder.append("', '");
            builder.append(feedarr.get("body_general"));
            builder.append("', '");
            builder.append(feedarr.get("image_1"));
            builder.append("', '");
            builder.append(feedarr.get("image_1_link"));
            builder.append("', '");
            builder.append(feedarr.get("image_2"));
            builder.append("', '");
            builder.append(feedarr.get("image_2_link"));
            builder.append("', '");
            builder.append(feedarr.get("image_3"));
            builder.append("', '");
            builder.append(feedarr.get("image_3_link"));
            builder.append("', '");
            builder.append(feedarr.get("image_4"));
            builder.append("', '");
            builder.append(feedarr.get("image_4_link"));
            builder.append("')");
            feed_inserts.add(builder.toString());
            builder.delete(0, builder.length());
        }
        mapInUserevents.put("privacy",
                Common.empty(mapInUserevents.get("privacy")) ? new HashMap<String, Object>()
                        : Serializer.unserialize((String) mapInUserevents.get("privacy")));
        Map<String, Object> tempM = (Map<String, Object>) ((Map<String, Object>) mapInUserevents.get("privacy"))
                .get("filter_note");
        Set<String> filter = Common.empty(tempM) ? new HashSet<String>() : tempM.keySet();
        if (tempM == null) {
            tempM = new HashMap<String, Object>();
        } else {
            tempM.clear();
        }
        tempM.put("type", "eventmemberstatus");
        tempM.put("authorid", supe_uid);
        if (cpService.checkNoteUid(tempM, filter)) {
            note_ids.add(id);
            String actionsValue = actions.get(id);
            actionsValue = actionsValue == null ? "" : actionsValue;
            String note_msg = Common.getMessage(request, "cp_eventmember_" + actionsValue,
                    "space.jsp?do=event&id=" + event.get("eventid"), event.get("title"));
            builder.append("('");
            builder.append(id);
            builder.append("', 'eventmemberstatus', '1', '");
            builder.append(supe_uid);
            builder.append("', '");
            builder.append(supe_username);
            builder.append("', '");
            builder.append(Common.addSlashes(note_msg));
            builder.append("', '");
            builder.append(timestamp);
            builder.append("')");
            note_inserts.add(builder.toString());
            builder.delete(0, builder.length());
        }
    }
    if (!Common.empty(note_ids)) {
        dataBaseService.execute("INSERT INTO " + JavaCenterHome.getTableName("notification")
                + " (`uid`, `type`, `new`, `authorid`, `author`, `note`, `dateline`) VALUES "
                + Common.implode(note_inserts, ","));
        dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("space")
                + " SET notenum=notenum+1 WHERE uid IN (" + Common.sImplode(note_ids) + ")");
    }
    if (!Common.empty(feed_inserts)) {
        dataBaseService.execute("INSERT INTO " + JavaCenterHome.getTableName("feed")
                + " (`appid` ,`icon` ,`uid` ,`username` ,`dateline` ,`friend` ,`hash_template` ,`hash_data` ,`title_template` ,`title_data` ,`body_template` ,`body_data` ,`body_general` ,`image_1` ,`image_1_link` ,`image_2` ,`image_2_link` ,`image_3` ,`image_3_link` ,`image_4` ,`image_4_link`)  VALUES "
                + Common.implode(feed_inserts, ","));
    }
    if (status == -1) {
        dataBaseService.execute("DELETE FROM " + JavaCenterHome.getTableName("userevent") + " WHERE uid IN ("
                + Common.sImplode(newids) + ") AND eventid='" + eventid + "'");
    } else {
        dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("userevent") + " SET status='"
                + status + "' WHERE uid IN (" + Common.sImplode(newids) + ") AND eventid='" + eventid + "'");
    }
    if (num != 0) {
        dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("event")
                + " SET membernum = membernum + " + num + " WHERE eventid='" + eventid + "'");
    }
    return newids;
}