Example usage for java.util Map equals

List of usage examples for java.util Map equals

Introduction

In this page you can find the example usage for java.util Map equals.

Prototype

boolean equals(Object o);

Source Link

Document

Compares the specified object with this map for equality.

Usage

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

public ActionForward cp_profile(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");
    String[] ops = { "base", "contact", "edu", "work", "info" };
    String op = request.getParameter("op");
    if (!Common.in_array(ops, op)) {
        op = "base";
    }/*from w ww  .  j  av  a  2  s .c  om*/
    Object uid = space.get("uid");
    String tname = JavaCenterHome.getTableName("spaceinfo");
    try {
        if (op.equals("base")) {
            if (submitCheck(request, "profilesubmit") || submitCheck(request, "nextsubmit")) {
                Map<String, Object> setData = new HashMap<String, Object>();
                setData.put("birthyear", Common.intval(request.getParameter("birthyear")));
                setData.put("birthmonth", Common.intval(request.getParameter("birthmonth")));
                setData.put("birthday", Common.intval(request.getParameter("birthday")));
                setData.put("blood", Common.getStr(request.getParameter("blood"), 5, true, true, false, 0, 0,
                        request, response));
                setData.put("marry", Common.intval(request.getParameter("marry")));
                setData.put("birthprovince", Common.getStr(request.getParameter("birthprovince"), 20, true,
                        true, false, 0, 0, request, response));
                setData.put("birthcity", Common.getStr(request.getParameter("birthcity"), 20, true, true, false,
                        0, 0, request, response));
                setData.put("resideprovince", Common.getStr(request.getParameter("resideprovince"), 20, true,
                        true, false, 0, 0, request, response));
                setData.put("residecity", Common.getStr(request.getParameter("residecity"), 20, true, true,
                        false, 0, 0, request, response));
                int sex = Common.intval(request.getParameter("sex"));
                if (!Common.empty(sex) && Common.empty(space.get("sex"))) {
                    setData.put("sex", sex);
                }
                File profileCache = new File(JavaCenterHome.jchRoot + "data/cache/cache_profilefield.jsp");
                if (!profileCache.exists()) {
                    cacheService.profilefield_cache();
                }
                Map<Integer, Map> profileFields = Common.getCacheDate(request, response,
                        "/data/cache/cache_profilefield.jsp", "globalProfilefield");
                Set<Entry<Integer, Map>> entrys = profileFields.entrySet();
                for (Entry<Integer, Map> entry : entrys) {
                    int key = entry.getKey();
                    Map value = entry.getValue();
                    if ("select".equals(value.get("formtype"))) {
                        value.put("maxsize", 255);
                    }
                    setData.put("field_" + key, Common.getStr(request.getParameter("field_" + key),
                            (Integer) value.get("maxsize"), true, true, false, 0, 0, request, response));
                    if (!Common.empty(value.get("required")) && Common.empty(setData.get("field_" + key))) {
                        return showMessage(request, response, "field_required", null, 1, value.get("title"));
                    }
                }
                Map whereData = new HashMap();
                whereData.put("uid", sGlobal.get("supe_uid"));
                dataBaseService.updateTable("spacefield", setData, whereData);
                List<String> inserts = new ArrayList<String>();
                Pattern p = Pattern.compile("friend\\[(.*)\\]");
                for (Enumeration<String> e = request.getParameterNames(); e.hasMoreElements();) {
                    String paramName = e.nextElement();
                    if (paramName.startsWith("friend[")) {
                        String key = p.matcher(paramName).replaceAll("$1");
                        int value = Common.intval(request.getParameter(paramName));
                        inserts.add("('base','" + key + "','" + uid + "','','" + value + "')");
                    }
                }
                if (inserts.size() > 0) {
                    dataBaseService
                            .executeUpdate("DELETE FROM " + tname + " WHERE uid='" + uid + "' AND type='base'");
                    dataBaseService.executeUpdate("INSERT INTO " + tname
                            + " (type,subtype,uid,title,friend) VALUES " + Common.implode(inserts, ","));
                }
                setData = new HashMap();
                setData.put("name", Common.getStr(request.getParameter("name"), 10, true, true, true, 0, 0,
                        request, response));
                setData.put("namestatus", Common.empty(sConfig.get("namecheck")) ? 1 : 0);
                boolean manageName = Common.checkPerm(request, response, "managename");
                if (manageName) {
                    setData.put("namestatus", 1);
                }
                int length = Common.strlen((String) setData.get("name"));
                if (length > 0 && length < 4) {
                    return showMessage(request, response, "realname_too_short");
                }
                String newName = (String) setData.get("name");
                String oldName = (String) space.get("name");
                boolean autoCheck = (Integer) setData.get("namestatus") == 1 ? true : false;
                if (!newName.equals(oldName) || autoCheck) {
                    boolean realNameCheck = !Common.empty(sConfig.get("realname")) ? true : false;
                    if (realNameCheck && Common.empty(oldName) && !newName.equals(oldName) && autoCheck) {
                        Map reward = Common.getReward("realname", false, 0, "", true, request, response);
                        int credit = (Integer) reward.get("credit");
                        int experience = (Integer) reward.get("experience");
                        if (credit != 0) {
                            setData.put("credit", (Integer) space.get("credit") + credit);
                        }
                        if (experience != 0) {
                            setData.put("experience", (Integer) space.get("experience") + experience);
                        }
                    } else if (realNameCheck && !Common.empty(space.get("namestatus")) && !manageName) {
                        Map reward = Common.getReward("editrealname", false, 0, "", true, request, response);
                        int credit = (Integer) reward.get("credit");
                        int experience = (Integer) reward.get("experience");
                        if (!Common.empty(oldName) && !newName.equals(oldName)
                                && (credit != 0 || experience != 0)) {
                            int spaceExperience = (Integer) space.get("experience");
                            if (spaceExperience >= experience) {
                                setData.put("experience", spaceExperience - experience);
                            } else {
                                String[] args = { String.valueOf(spaceExperience), String.valueOf(experience) };
                                return showMessage(request, response, "experience_inadequate", null, 1, args);
                            }
                            int spaceCredit = (Integer) space.get("credit");
                            if (spaceCredit >= credit) {
                                setData.put("credit", spaceCredit - credit);
                            } else {
                                String[] args = { String.valueOf(spaceCredit), String.valueOf(credit) };
                                return showMessage(request, response, "integral_inadequate", null, 1, args);
                            }
                        }
                    }
                    whereData = new HashMap();
                    whereData.put("uid", sGlobal.get("supe_uid"));
                    dataBaseService.updateTable("space", setData, whereData);
                }
                if (!Common.empty(sConfig.get("my_status"))) {
                    Map insertData = new HashMap();
                    insertData.put("uid", sGlobal.get("supe_uid"));
                    insertData.put("action", "update");
                    insertData.put("dateline", sGlobal.get("timestamp"));
                    insertData.put("type", 0);
                    dataBaseService.insertTable("userlog", insertData, false, true);
                }
                if (Common.ckPrivacy(sGlobal, sConfig, space, "profile", 1)) {
                    cpService.addFeed(sGlobal, "profile",
                            Common.getMessage(request, "cp_feed_profile_update_base"), null, "", null, "", null,
                            null, "", 0, 0, 0, "", false);
                }
                String url = null;
                if (submitCheck(request, "nextsubmit")) {
                    url = "cp.jsp?ac=profile&op=contact";
                } else {
                    url = "cp.jsp?ac=profile&op=base";
                }
                return showMessage(request, response, "update_on_successful_individuals", url);
            }
            Map sexmap = new HashMap();
            sexmap.put(String.valueOf(space.get("sex")), " checked");
            StringBuffer birthYearHtml = new StringBuffer();
            int nowYear = Common.intval(Common.sgmdate(request, "yyyy", (Integer) sGlobal.get("timestamp")));
            for (int i = 0; i < 100; i++) {
                int they = nowYear - i;
                String selected = they == (Integer) space.get("birthyear") ? "selected" : "";
                birthYearHtml.append("<option value=\"" + they + "\" " + selected + ">" + they + "</option>");
            }
            StringBuffer birthMonthHtml = new StringBuffer();
            for (int i = 1; i < 13; i++) {
                String selected = i == (Integer) space.get("birthmonth") ? "selected" : "";
                birthMonthHtml.append("<option value=\"" + i + "\" " + selected + ">" + i + "</option>");
            }
            StringBuffer birthDayHtml = new StringBuffer();
            for (int i = 1; i < 32; i++) {
                String selected = i == (Integer) space.get("birthday") ? "selected" : "";
                birthDayHtml.append("<option value=\"" + i + "\" " + selected + ">" + i + "</option>");
            }
            StringBuffer bloodHtml = new StringBuffer();
            String[] blood = { "A", "B", "O", "AB" };
            for (String value : blood) {
                String selected = value.equals(space.get("blood")) ? "selected" : "";
                bloodHtml.append("<option value=\"" + value + "\" " + selected + ">" + value + "</option>");
            }
            Map marriagemap = new HashMap();
            marriagemap.put(String.valueOf(space.get("marry")), " selected");
            List profileFields = new ArrayList();
            List<Map<String, Object>> query = dataBaseService.executeQuery(
                    "SELECT * FROM " + JavaCenterHome.getTableName("profilefield") + " ORDER BY displayorder");
            for (Map field : query) {
                int fieldId = (Integer) field.get("fieldid");
                if ("text".equals(field.get("formtype"))) {
                    field.put("formhtml", "<input type=\"text\" name=\"field_" + fieldId + "\" value=\""
                            + space.get("field_" + fieldId) + "\" class=\"t_input\">");
                } else {
                    StringBuffer formHtml = new StringBuffer();
                    formHtml.append("<select name=\"field_" + fieldId + "\">");
                    if (Common.empty(field.get("required"))) {
                        formHtml.append("<option value=\"\"></option>");
                    }
                    String[] options = ((String) field.get("choice")).split("\n");
                    for (String option : options) {
                        option = option.trim();
                        if (option.length() != 0) {
                            String selected = option.equals(space.get("field_" + fieldId)) ? "selected" : "";
                            formHtml.append("<option value=\"" + option + "\" " + selected + ">" + option
                                    + "</option>");
                        }
                    }
                    formHtml.append("</select>");
                    field.put("formhtml", formHtml.toString());
                }
                profileFields.add(field);
            }
            Map friendmap = new HashMap();
            List<Map<String, Object>> infoList = dataBaseService.executeQuery(
                    "SELECT * FROM " + tname + " WHERE uid='" + space.get("uid") + "' AND type='base'");
            for (Map info : infoList) {
                Map value = new HashMap();
                value.put(String.valueOf(info.get("friend")), " selected");
                friendmap.put(info.get("subtype"), value);
            }
            request.setAttribute("username", Common.stripSlashes((String) space.get("username")));
            request.setAttribute("name", Common.stripSlashes((String) space.get("name")));
            request.setAttribute("namechange",
                    Common.empty(sConfig.get("namechange")) ? 0 : request.getParameter("namechange"));
            request.setAttribute("sexmap", sexmap);
            request.setAttribute("marriagemap", marriagemap);
            request.setAttribute("friendmap", friendmap);
            request.setAttribute("birthyearhtml", birthYearHtml.toString());
            request.setAttribute("birthmonthhtml", birthMonthHtml.toString());
            request.setAttribute("birthdayhtml", birthDayHtml.toString());
            request.setAttribute("bloodhtml", bloodHtml.toString());
            request.setAttribute("profilefields", profileFields);
        } else if (op.equals("contact")) {
            if ("1".equals(request.getParameter("resend"))) {
                String toEmail = !Common.empty(space.get("newemail")) ? (String) space.get("newemail")
                        : (String) space.get("email");
                cpService.sendEmailCheck(request, response, (Integer) space.get("uid"), toEmail);
                return showMessage(request, response, "do_success", "cp.jsp?ac=profile&op=contact");
            }
            if (submitCheck(request, "profilesubmit") || submitCheck(request, "nextsubmit")) {
                Map setmap = new HashMap();
                setmap.put("mobile", Common.getStr(request.getParameter("mobile"), 40, true, true, false, 0, 0,
                        request, response));
                setmap.put("qq", Common.getStr(request.getParameter("qq"), 20, true, true, false, 0, 0, request,
                        response));
                setmap.put("msn", Common.getStr(request.getParameter("msn"), 80, true, true, false, 0, 0,
                        request, response));
                String newEmail = request.getParameter("email");
                String oldEmail = (String) space.get("email");
                if (newEmail != null && Common.isEmail(newEmail) && !newEmail.equals(oldEmail)) {
                    if (!Common.empty(sConfig.get("uniqueemail"))) {
                        Map where = new HashMap();
                        where.put("email", newEmail);
                        where.put("emailcheck", 1);
                        if (!Common.empty(Common.getCount("spacefield", where, null))) {
                            return showMessage(request, response, "uniqueemail_check");
                        }
                    }
                    String password = request.getParameter("password");
                    List<Map<String, Object>> members = dataBaseService
                            .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("member")
                                    + " WHERE uid = '" + sGlobal.get("supe_uid") + "'");
                    if (members.size() != 0) {
                        Map<String, Object> member = members.get(0);
                        password = Common.md5(Common.md5(password) + member.get("salt"));
                        if (!password.equals(member.get("password"))) {
                            return showMessage(request, response, "password_is_not_passed");
                        }
                    } else {
                        return showMessage(request, response, "password_is_not_passed");
                    }
                    if (newEmail == null || newEmail.length() == 0) {
                        setmap.put("email", "");
                        setmap.put("emailcheck", 0);
                    } else if (!newEmail.equals(oldEmail)) {
                        if (!Common.empty(space.get("emailcheck"))) {
                            setmap.put("newemail", newEmail);
                        } else {
                            setmap.put("email", newEmail);
                        }
                        cpService.sendEmailCheck(request, response, (Integer) space.get("uid"), newEmail);
                    }
                }
                Map wheremap = new HashMap();
                wheremap.put("uid", sGlobal.get("supe_uid"));
                dataBaseService.updateTable("spacefield", setmap, wheremap);
                List inserts = new ArrayList();
                Pattern p = Pattern.compile("friend\\[(.*)\\]");
                for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
                    String paramName = (String) e.nextElement();
                    if (paramName.startsWith("friend[")) {
                        String key = p.matcher(paramName).replaceAll("$1");
                        int value = Common.intval(request.getParameter(paramName));
                        inserts.add("('contact','" + key + "','" + space.get("uid") + "','','" + value + "')");
                    }
                }
                if (inserts.size() != 0) {
                    dataBaseService.executeUpdate("DELETE FROM " + tname + " WHERE uid='" + space.get("uid")
                            + "' AND type='contact'");
                    dataBaseService.executeUpdate("INSERT INTO " + tname
                            + " (type,subtype,uid,title,friend) VALUES " + Common.implode(inserts, ","));
                }
                if (!Common.empty(sConfig.get("my_status"))) {
                    Map insertmap = new HashMap();
                    insertmap.put("uid", sGlobal.get("supe_uid"));
                    insertmap.put("action", "update");
                    insertmap.put("dateline", sGlobal.get("timestamp"));
                    insertmap.put("type", 2);
                    dataBaseService.insertTable("userlog", insertmap, false, true);
                }
                if (Common.ckPrivacy(sGlobal, sConfig, space, "profile", 1)) {
                    cpService.addFeed(sGlobal, "profile",
                            Common.getMessage(request, "cp_feed_profile_update_contact"), null, "", null, "",
                            null, null, "", 0, 0, 0, "", false);
                }
                if (submitCheck(request, "nextsubmit")) {
                    return showMessage(request, response, "update_on_successful_individuals",
                            "cp.jsp?ac=profile&op=edu");
                } else {
                    return showMessage(request, response, "update_on_successful_individuals",
                            "cp.jsp?ac=profile&op=contact");
                }
            }
            Map friendmap = new HashMap();
            List<Map<String, Object>> infoList = dataBaseService.executeQuery(
                    "SELECT * FROM " + tname + " WHERE uid='" + space.get("uid") + "' AND type='contact'");
            for (Map info : infoList) {
                Map value = new HashMap();
                value.put(String.valueOf(info.get("friend")), " selected");
                friendmap.put(info.get("subtype"), value);
            }
            request.setAttribute("friendmap", friendmap);
        } else if (op.equals("edu")) {
            if ("delete".equals(request.getParameter("subop"))) {
                int infoId = Common.intval(request.getParameter("infoid"));
                if (infoId != 0) {
                    dataBaseService.executeUpdate("DELETE FROM " + tname + " WHERE infoid='" + infoId
                            + "' AND uid='" + uid + "' AND type='edu'");
                }
            }
            if (submitCheck(request, "profilesubmit") || submitCheck(request, "nextsubmit")) {
                List inserts = new ArrayList();
                String[] title = request.getParameterValues("title[]");
                String[] subTitle = request.getParameterValues("subtitle[]");
                String[] startYear = request.getParameterValues("startyear[]");
                String[] friend = request.getParameterValues("friend[]");
                int groupCount = title.length;
                for (int i = 0; i < groupCount; i++) {
                    title[i] = Common.getStr(title[i], 100, true, true, false, 0, 0, request, response);
                    if (title[i].length() != 0) {
                        subTitle[i] = Common.getStr(subTitle[i], 20, true, true, false, 0, 0, request,
                                response);
                        startYear[i] = String.valueOf(Common.intval(startYear[i]));
                        friend[i] = String.valueOf(Common.intval(friend[i]));
                        inserts.add("('" + uid + "','edu','" + title[i] + "','" + subTitle[i] + "','"
                                + startYear[i] + "','" + friend[i] + "')");
                    }
                }
                if (inserts.size() != 0) {
                    dataBaseService.executeUpdate(
                            "INSERT INTO " + tname + " (uid,type,title,subtitle,startyear,friend) VALUES "
                                    + Common.implode(inserts, ","));
                }
                if (!Common.empty(sConfig.get("my_status"))) {
                    Map insertmap = new HashMap();
                    insertmap.put("uid", sGlobal.get("supe_uid"));
                    insertmap.put("action", "update");
                    insertmap.put("dateline", sGlobal.get("timestamp"));
                    insertmap.put("type", 2);
                    dataBaseService.insertTable("userlog", insertmap, false, true);
                }
                if (Common.ckPrivacy(sGlobal, sConfig, space, "profile", 1)) {
                    cpService.addFeed(sGlobal, "profile",
                            Common.getMessage(request, "cp_feed_profile_update_edu"), null, "", null, "", null,
                            null, "", 0, 0, 0, "", false);
                }
                if (submitCheck(request, "nextsubmit")) {
                    return showMessage(request, response, "update_on_successful_individuals",
                            "cp.jsp?ac=profile&op=work");
                } else {
                    return showMessage(request, response, "update_on_successful_individuals",
                            "cp.jsp?ac=profile&op=edu");
                }
            }
            List<Map<String, Object>> list = dataBaseService.executeQuery(
                    "SELECT * FROM " + tname + " WHERE uid='" + uid + "' AND type='edu' ORDER BY startyear");
            for (Map<String, Object> value : list) {
                value.put("title_s", Common.urlEncode((String) value.get("title")));
                value.put("friend", String.valueOf(value.get("friend")));
            }
            request.setAttribute("list", list);
        } else if (op.equals("work")) {
            if ("delete".equals(request.getParameter("subop"))) {
                int infoId = Common.intval(request.getParameter("infoid"));
                if (infoId != 0) {
                    dataBaseService.executeUpdate("DELETE FROM " + tname + " WHERE infoid='" + infoId
                            + "' AND uid='" + uid + "' AND type='work'");
                }
            }
            if (submitCheck(request, "profilesubmit") || submitCheck(request, "nextsubmit")) {
                List inserts = new ArrayList();
                String[] title = request.getParameterValues("title[]");
                String[] subTitle = request.getParameterValues("subtitle[]");
                String[] startYear = request.getParameterValues("startyear[]");
                String[] startMonth = request.getParameterValues("startmonth[]");
                String[] endYear = request.getParameterValues("endyear[]");
                String[] endMonth = request.getParameterValues("endmonth[]");
                String[] friend = request.getParameterValues("friend[]");
                int groupCount = title.length;
                for (int i = 0; i < groupCount; i++) {
                    title[i] = Common.getStr(title[i], 100, true, true, false, 0, 0, request, response);
                    if (title[i].length() != 0) {
                        subTitle[i] = Common.getStr(subTitle[i], 20, true, true, false, 0, 0, request,
                                response);
                        startYear[i] = String.valueOf(Common.intval(startYear[i]));
                        startMonth[i] = String.valueOf(Common.intval(startMonth[i]));
                        endYear[i] = String.valueOf(Common.intval(endYear[i]));
                        endMonth[i] = endYear[i].equals("0") == false
                                ? String.valueOf(Common.intval(endMonth[i]))
                                : "0";
                        friend[i] = String.valueOf(Common.intval(friend[i]));
                        inserts.add("('" + uid + "','work','" + title[i] + "','" + subTitle[i] + "','"
                                + startYear[i] + "','" + startMonth[i] + "','" + endYear[i] + "','"
                                + endMonth[i] + "','" + friend[i] + "')");
                    }
                }
                if (inserts.size() != 0) {
                    dataBaseService.executeUpdate("INSERT INTO " + tname
                            + " (uid,type,title,subtitle,startyear,startmonth,endyear,endmonth,friend) VALUES "
                            + Common.implode(inserts, ","));
                }
                if (!Common.empty(sConfig.get("my_status"))) {
                    Map insertmap = new HashMap();
                    insertmap.put("uid", sGlobal.get("supe_uid"));
                    insertmap.put("action", "update");
                    insertmap.put("dateline", sGlobal.get("timestamp"));
                    insertmap.put("type", 2);
                    dataBaseService.insertTable("userlog", insertmap, false, true);
                }
                if (Common.ckPrivacy(sGlobal, sConfig, space, "profile", 1)) {
                    cpService.addFeed(sGlobal, "profile",
                            Common.getMessage(request, "cp_feed_profile_update_work"), null, "", null, "", null,
                            null, "", 0, 0, 0, "", false);
                }
                if (submitCheck(request, "nextsubmit")) {
                    return showMessage(request, response, "update_on_successful_individuals",
                            "cp.jsp?ac=profile&op=info");
                } else {
                    return showMessage(request, response, "update_on_successful_individuals",
                            "cp.jsp?ac=profile&op=work");
                }
            }
            List<Map<String, Object>> list = dataBaseService
                    .executeQuery("SELECT * FROM " + tname + " WHERE uid='" + uid
                            + "' AND type='work' ORDER BY startyear,startmonth,endyear,endmonth");
            for (Map<String, Object> value : list) {
                value.put("title_s", Common.urlEncode((String) value.get("title")));
                value.put("friend", String.valueOf(value.get("friend")));
            }
            request.setAttribute("list", list);
        } else if (op.equals("info")) {
            if (submitCheck(request, "profilesubmit")) {
                Pattern p = Pattern.compile("info\\[(.+)\\]");
                List inserts = new ArrayList();
                for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
                    String elementName = (String) e.nextElement();
                    if (elementName.startsWith("info[")) {
                        String key = p.matcher(elementName).replaceAll("$1");
                        String value = Common.getStr(request.getParameter(elementName), 500, true, true, false,
                                0, 0, request, response);
                        String friend = request.getParameter("info_friend[" + key + "]");
                        inserts.add("('" + uid + "','info','" + key + "','" + value + "','" + friend + "')");
                    }
                }
                if (inserts.isEmpty() == false) {
                    dataBaseService
                            .executeUpdate("DELETE FROM " + tname + " WHERE uid='" + uid + "' AND type='info'");
                    dataBaseService.executeUpdate("INSERT INTO " + tname
                            + " (uid,type,subtype,title,friend) VALUES " + Common.implode(inserts, ","));
                }
                if (!Common.empty(sConfig.get("my_status"))) {
                    Map insert = new HashMap();
                    insert.put("uid", sGlobal.get("supe_uid"));
                    insert.put("action", "update");
                    insert.put("dateline", sGlobal.get("timestamp"));
                    insert.put("type", 2);
                    dataBaseService.insertTable("userlog", insert, false, true);
                }
                if (Common.ckPrivacy(sGlobal, sConfig, space, "profile", 1)) {
                    cpService.addFeed(sGlobal, "profile",
                            Common.getMessage(request, "cp_feed_profile_update_info"), null, "", null, "", null,
                            null, "", 0, 0, 0, "", false);
                }
                return showMessage(request, response, "update_on_successful_individuals",
                        "cp.jsp?ac=profile&op=info");
            }
            Map infoarr = new LinkedHashMap();
            infoarr.put("trainwith", "");
            infoarr.put("interest", "");
            infoarr.put("book", "?");
            infoarr.put("movie", "");
            infoarr.put("tv", "");
            infoarr.put("music", "?");
            infoarr.put("game", "?");
            infoarr.put("sport", "?");
            infoarr.put("idol", "??");
            infoarr.put("motto", "?");
            infoarr.put("wish", "");
            infoarr.put("intro", "");
            Map list = new HashMap();
            Map friends = new HashMap();
            List<Map<String, Object>> query = dataBaseService
                    .executeQuery("SELECT * FROM " + tname + " WHERE uid='" + uid + "' AND type='info'");
            for (Map<String, Object> value : query) {
                list.put(value.get("subtype"), value);
                Map map = new HashMap();
                map.put(String.valueOf(value.get("friend")), " selected");
                friends.put(value.get("subtype"), map);
            }
            request.setAttribute("list", list);
            request.setAttribute("friends", friends);
            request.setAttribute("infoarr", infoarr);
        }
    } catch (Exception e) {
        return showMessage(request, response, e.getMessage());
    }
    if (op.equals("edu") || op.equals("work")) {
        StringBuffer yearHtml = new StringBuffer();
        int nowYear = Common.intval(Common.sgmdate(request, "yyyy", (Integer) sGlobal.get("timestamp")));
        for (int i = 0; i < 50; i++) {
            int they = nowYear - i;
            yearHtml.append("<option value=\"" + they + "\">" + they + "</option>");
        }
        StringBuffer monthHtml = new StringBuffer();
        for (int i = 1; i < 13; i++) {
            monthHtml.append("<option value=\"" + i + "\">" + i + "</option>");
        }
        request.setAttribute("yearhtml", yearHtml);
        request.setAttribute("monthhtml", monthHtml);
    }
    String theUrl = "cp.jsp?ac=profile&op=" + op;
    Map farr = new HashMap();
    farr.put("0", "");
    farr.put("1", "?");
    farr.put("3", "");
    request.setAttribute("cat_actives_" + op, " class=\"active\"");
    request.setAttribute("farr", farr);
    request.setAttribute("theurl", theUrl);
    request.setAttribute("op", op);
    return include(request, response, sConfig, sGlobal, "cp_profile.jsp");
}

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

public ActionForward cp_profile(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");
    String[] ops = { "base", "contact", "edu", "work", "info" };
    String op = request.getParameter("op");
    if (!Common.in_array(ops, op)) {
        op = "base";
    }/* w w w  .ja  va  2s  .  co m*/
    Integer uid = (Integer) space.get("uid");
    String tname = " sns_spaceinfo";
    try {
        if (op.equals("base")) {
            if (submitCheck(request, "profilesubmit") || submitCheck(request, "nextsubmit")) {
                Map<String, Object> setData = new HashMap<String, Object>();
                setData.put("birthyear", Common.intval(request.getParameter("birthyear")));
                setData.put("birthmonth", Common.intval(request.getParameter("birthmonth")));
                setData.put("birthday", Common.intval(request.getParameter("birthday")));
                setData.put("blood", Common.getStr(request.getParameter("blood"), 5, true, true, false, 0, 0,
                        request, response));
                setData.put("marry", Common.intval(request.getParameter("marry")));
                setData.put("birthprovince", Common.getStr(request.getParameter("birthprovince"), 20, true,
                        true, false, 0, 0, request, response));
                setData.put("birthcity", Common.getStr(request.getParameter("birthcity"), 20, true, true, false,
                        0, 0, request, response));
                setData.put("resideprovince", Common.getStr(request.getParameter("resideprovince"), 20, true,
                        true, false, 0, 0, request, response));
                setData.put("residecity", Common.getStr(request.getParameter("residecity"), 20, true, true,
                        false, 0, 0, request, response));
                int sex = Common.intval(request.getParameter("sex"));
                if (!Common.empty(sex) && Common.empty(space.get("sex"))) {
                    setData.put("sex", sex);
                }
                File profileCache = new File(SysConstants.snsRoot + "/data/cache/cache_profilefield.jsp");
                if (!profileCache.exists()) {
                    cacheService.profilefield_cache();
                }
                Map<Integer, Map> profileFields = Common.getCacheDate(request, response,
                        "cache/cache_profilefield.jsp", "globalProfilefield");
                Set<Entry<Integer, Map>> entrys = profileFields.entrySet();
                for (Entry<Integer, Map> entry : entrys) {
                    int key = entry.getKey();
                    Map value = entry.getValue();
                    if ("select".equals(value.get("formtype"))) {
                        value.put("maxsize", 255);
                    }
                    setData.put("field_" + key, Common.getStr(request.getParameter("field_" + key),
                            (Integer) value.get("maxsize"), true, true, false, 0, 0, request, response));
                    if (!Common.empty(value.get("required")) && Common.empty(setData.get("field_" + key))) {
                        return showMessage(request, response, "field_required", null, 1, value.get("title"));
                    }
                }
                Map whereData = new HashMap();
                whereData.put("uid", sGlobal.get("supe_uid"));
                dataBaseService.updateTable("sns_spacefield", setData, whereData);
                List<String> inserts = new ArrayList<String>();
                Pattern p = Pattern.compile("friend\\[(.*)\\]");
                for (Enumeration<String> e = request.getParameterNames(); e.hasMoreElements();) {
                    String paramName = e.nextElement();
                    if (paramName.startsWith("friend[")) {
                        String key = p.matcher(paramName).replaceAll("$1");
                        int value = Common.intval(request.getParameter(paramName));
                        inserts.add("('base','" + key + "','" + uid + "','','" + value + "')");
                    }
                }
                if (inserts.size() > 0) {
                    dataBaseService
                            .executeUpdate("DELETE FROM " + tname + " WHERE uid='" + uid + "' AND type='base'");
                    dataBaseService.executeUpdate("INSERT INTO " + tname
                            + " (type,subtype,uid,title,friend) VALUES " + Common.implode(inserts, ","));
                }
                setData = new HashMap();
                setData.put("name", Common.getStr(request.getParameter("name"), 10, true, true, true, 0, 0,
                        request, response));
                setData.put("nickname", Common.getStr(request.getParameter("nickname"), 10, true, true, true, 0,
                        0, request, response));
                setData.put("namestatus", Common.empty(sConfig.get("namecheck")) ? 1 : 0);
                boolean manageName = Common.checkPerm(request, response, "managename");
                if (manageName) {
                    setData.put("namestatus", 1);
                }
                int length = Common.strlen((String) setData.get("name"));
                if (length > 0 && length < 4) {
                    return showMessage(request, response, "realname_too_short");
                }
                String username = (String) space.get("username");
                String newNickname = (String) setData.get("nickname");
                String oldNickname = (String) space.get("nickname");
                String newName = (String) setData.get("name");
                String oldName = (String) space.get("name");
                Integer namestatus = (Integer) setData.get("namestatus");
                boolean autoCheck = namestatus == 1 ? true : false;
                Map<Integer, String> sNames = (Map<Integer, String>) request.getAttribute("sNames");
                if (!newName.equals(oldName) || autoCheck) {
                    // ??
                    boolean realNameCheck = !Common.empty(sConfig.get("realname")) ? true : false;
                    if (realNameCheck && Common.empty(oldName) && !newName.equals(oldName) && autoCheck) {
                        Map reward = Common.getReward("realname", false, 0, "", true, request, response);
                        int credit = (Integer) reward.get("credit");
                        int experience = (Integer) reward.get("experience");
                        if (credit != 0) {
                            setData.put("credit", (Integer) space.get("credit") + credit);
                        }
                        if (experience != 0) {
                            setData.put("experience", (Integer) space.get("experience") + experience);
                        }
                    } else if (realNameCheck && !Common.empty(space.get("namestatus")) && !manageName) {
                        Map reward = Common.getReward("editrealname", false, 0, "", true, request, response);
                        int credit = (Integer) reward.get("credit");
                        int experience = (Integer) reward.get("experience");
                        if (!Common.empty(oldName) && !newName.equals(oldName)
                                && (credit != 0 || experience != 0)) {
                            int spaceExperience = (Integer) space.get("experience");
                            if (spaceExperience >= experience) {
                                setData.put("experience", spaceExperience - experience);
                            } else {
                                String[] args = { String.valueOf(spaceExperience), String.valueOf(experience) };
                                return showMessage(request, response, "experience_inadequate", null, 1, args);
                            }
                            int spaceCredit = (Integer) space.get("credit");
                            if (spaceCredit >= credit) {
                                setData.put("credit", spaceCredit - credit);
                            } else {
                                String[] args = { String.valueOf(spaceCredit), String.valueOf(credit) };
                                return showMessage(request, response, "integral_inadequate", null, 1, args);
                            }
                        }
                    }
                    whereData = new HashMap();
                    whereData.put("uid", sGlobal.get("supe_uid"));
                    dataBaseService.updateTable("sns_space", setData, whereData);
                    Common.realname_set(sNames, uid, username, newNickname, newName, namestatus);// ??????
                } else if (!newNickname.equals(oldNickname)) {
                    // ?
                    setData.remove("name");
                    setData.remove("namestatus");
                    whereData = new HashMap();
                    whereData.put("uid", sGlobal.get("supe_uid"));
                    dataBaseService.updateTable("sns_space", setData, whereData);
                    Common.realname_set(sNames, uid, username, newNickname, newName, namestatus);
                }
                if (!Common.empty(sConfig.get("my_status"))) {
                    Map insertData = new HashMap();
                    insertData.put("uid", sGlobal.get("supe_uid"));
                    insertData.put("action", "update");
                    insertData.put("dateline", sGlobal.get("timestamp"));
                    insertData.put("type", 0);
                    dataBaseService.insertTable("sns_userlog", insertData, false, true);
                }
                if (Common.ckPrivacy(sGlobal, sConfig, space, "profile", 1)) {
                    mainService.addFeed(sGlobal, "profile",
                            Common.getMessage(request, "cp_feed_profile_update_base"), null, "", null, "", null,
                            null, "", 0, 0, 0, "", false);
                }
                String url = null;
                if (submitCheck(request, "nextsubmit")) {
                    url = "main.action?ac=profile&op=contact";
                } else {
                    url = "main.action?ac=profile&op=base";
                }
                return showMessage(request, response, "update_on_successful_individuals", url);
            }
            Map sexmap = new HashMap();
            sexmap.put(String.valueOf(space.get("sex")), " checked");
            StringBuffer birthYearHtml = new StringBuffer();
            int nowYear = Common.intval(Common.sgmdate(request, "yyyy", (Integer) sGlobal.get("timestamp")));
            for (int i = 0; i < 100; i++) {
                int they = nowYear - i;
                String selected = they == (Integer) space.get("birthyear") ? "selected" : "";
                birthYearHtml.append("<option value=\"" + they + "\" " + selected + ">" + they + "</option>");
            }
            StringBuffer birthMonthHtml = new StringBuffer();
            for (int i = 1; i < 13; i++) {
                String selected = i == (Integer) space.get("birthmonth") ? "selected" : "";
                birthMonthHtml.append("<option value=\"" + i + "\" " + selected + ">" + i + "</option>");
            }
            StringBuffer birthDayHtml = new StringBuffer();
            for (int i = 1; i < 32; i++) {
                String selected = i == (Integer) space.get("birthday") ? "selected" : "";
                birthDayHtml.append("<option value=\"" + i + "\" " + selected + ">" + i + "</option>");
            }
            StringBuffer bloodHtml = new StringBuffer();
            String[] blood = { "A", "B", "O", "AB" };
            for (String value : blood) {
                String selected = value.equals(space.get("blood")) ? "selected" : "";
                bloodHtml.append("<option value=\"" + value + "\" " + selected + ">" + value + "</option>");
            }
            Map marriagemap = new HashMap();
            marriagemap.put(String.valueOf(space.get("marry")), " selected");
            List profileFields = new ArrayList();
            List<Map<String, Object>> query = dataBaseService
                    .executeQuery("SELECT * FROM sns_profilefield ORDER BY displayorder");
            for (Map field : query) {
                int fieldId = (Integer) field.get("fieldid");
                if ("text".equals(field.get("formtype"))) {
                    field.put("formhtml", "<input type=\"text\" name=\"field_" + fieldId + "\" value=\""
                            + space.get("field_" + fieldId) + "\" class=\"t_input\">");
                } else {
                    StringBuffer formHtml = new StringBuffer();
                    formHtml.append("<select name=\"field_" + fieldId + "\">");
                    if (Common.empty(field.get("required"))) {
                        formHtml.append("<option value=\"\"></option>");
                    }
                    String[] options = ((String) field.get("choice")).split("\n");
                    for (String option : options) {
                        option = option.trim();
                        if (option.length() != 0) {
                            String selected = option.equals(space.get("field_" + fieldId)) ? "selected" : "";
                            formHtml.append("<option value=\"" + option + "\" " + selected + ">" + option
                                    + "</option>");
                        }
                    }
                    formHtml.append("</select>");
                    field.put("formhtml", formHtml.toString());
                }
                profileFields.add(field);
            }
            Map friendmap = new HashMap();
            List<Map<String, Object>> infoList = dataBaseService.executeQuery(
                    "SELECT * FROM " + tname + " WHERE uid='" + space.get("uid") + "' AND type='base'");
            for (Map info : infoList) {
                Map value = new HashMap();
                value.put(String.valueOf(info.get("friend")), " selected");
                friendmap.put(info.get("subtype"), value);
            }
            request.setAttribute("username", Common.stripSlashes((String) space.get("username")));
            request.setAttribute("name", Common.stripSlashes((String) space.get("name")));
            request.setAttribute("nickname", Common.stripSlashes((String) space.get("nickname")));
            request.setAttribute("namechange",
                    Common.empty(sConfig.get("namechange")) ? 0 : request.getParameter("namechange"));
            request.setAttribute("sexmap", sexmap);
            request.setAttribute("marriagemap", marriagemap);
            request.setAttribute("friendmap", friendmap);
            request.setAttribute("birthyearhtml", birthYearHtml.toString());
            request.setAttribute("birthmonthhtml", birthMonthHtml.toString());
            request.setAttribute("birthdayhtml", birthDayHtml.toString());
            request.setAttribute("bloodhtml", bloodHtml.toString());
            request.setAttribute("profilefields", profileFields);
        } else if (op.equals("contact")) {
            if ("1".equals(request.getParameter("resend"))) {
                String toEmail = !Common.empty(space.get("newemail")) ? (String) space.get("newemail")
                        : (String) space.get("email");
                mainService.sendEmailCheck(request, response, (Integer) space.get("uid"), toEmail);
                return showMessage(request, response, "do_success", "main.action?ac=profile&op=contact");
            }

            // ???
            if (submitCheck(request, "getmobilevalidatecode")) {
                String mobile = (String) request.getParameter("mobile");
                if (Common.empty(mobile)) {
                    return showMessage(request, response, "?");
                }
                String validatecode = Common.createSeccode();
                request.getSession().setAttribute("validatemobile", mobile);
                request.getSession().setAttribute("validatecode", validatecode);
                // ??
                String smsContent = ""
                        + (Common.empty(space.get("name")) ? space.get("username") : space.get("name"))
                        + "??" + validatecode + "";
                long sendresult = MobileSms.sendNote(smsContent, mobile);
                if (sendresult != -1) {
                    return showMessage(request, response,
                            "????");
                } else {
                    return showMessage(request, response, "??????");
                }
            }

            if (submitCheck(request, "profilesubmit") || submitCheck(request, "nextsubmit")) {
                Map setmap = new HashMap();
                setmap.put("mobile", Common.getStr(request.getParameter("mobile"), 40, true, true, false, 0, 0,
                        request, response));
                setmap.put("qq", Common.getStr(request.getParameter("qq"), 20, true, true, false, 0, 0, request,
                        response));
                setmap.put("msn", Common.getStr(request.getParameter("msn"), 80, true, true, false, 0, 0,
                        request, response));

                // ?
                Integer mobilestatus = (Integer) space.get("mobilestatus");
                String mobile = (String) request.getParameter("mobile");
                String mobilevalidatecode = (String) request.getParameter("mobilevalidatecode");
                if (mobilestatus == 0 && !Common.empty(mobile) && !Common.empty(mobilevalidatecode)) {
                    String validatemobile = (String) request.getSession().getAttribute("validatemobile");
                    String validatecode = (String) request.getSession().getAttribute("validatecode");
                    if (mobile.equals(validatemobile) && mobilevalidatecode.equalsIgnoreCase(validatecode)) {
                        // mobilestatus1?
                        String sql = "UPDATE sns_space SET mobilestatus = '1' WHERE uid='" + uid + "'";
                        dataBaseService.executeUpdate(sql);
                    } else {
                        return showMessage(request, response,
                                "?????");
                    }
                }

                String newEmail = request.getParameter("email");
                String oldEmail = (String) space.get("email");
                if (newEmail != null && Common.isEmail(newEmail) && !newEmail.equals(oldEmail)) {
                    if (!Common.empty(sConfig.get("uniqueemail"))) {
                        Map where = new HashMap();
                        where.put("email", newEmail);
                        where.put("emailcheck", 1);
                        if (!Common.empty(Common.getCount("sns_spacefield", where, null))) {
                            return showMessage(request, response, "uniqueemail_check");
                        }
                    }
                    String password = request.getParameter("password");
                    List<Map<String, Object>> members = dataBaseService.executeQuery(
                            "SELECT * FROM sns_member WHERE uid = '" + sGlobal.get("supe_uid") + "'");
                    if (members.size() != 0) {
                        Map<String, Object> member = members.get(0);
                        password = Common.md5(Common.md5(password) + member.get("salt"));
                        if (!password.equals(member.get("password"))) {
                            return showMessage(request, response, "password_is_not_passed");
                        }
                    } else {
                        return showMessage(request, response, "password_is_not_passed");
                    }
                    if (newEmail == null || newEmail.length() == 0) {
                        setmap.put("email", "");
                        setmap.put("emailcheck", 0);
                    } else if (!newEmail.equals(oldEmail)) {
                        if (!Common.empty(space.get("emailcheck"))) {
                            setmap.put("newemail", newEmail);
                        } else {
                            setmap.put("email", newEmail);
                        }
                        mainService.sendEmailCheck(request, response, (Integer) space.get("uid"), newEmail);
                    }
                }
                Map wheremap = new HashMap();
                wheremap.put("uid", sGlobal.get("supe_uid"));
                dataBaseService.updateTable("sns_spacefield", setmap, wheremap);
                List inserts = new ArrayList();
                Pattern p = Pattern.compile("friend\\[(.*)\\]");
                for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
                    String paramName = (String) e.nextElement();
                    if (paramName.startsWith("friend[")) {
                        String key = p.matcher(paramName).replaceAll("$1");
                        int value = Common.intval(request.getParameter(paramName));
                        inserts.add("('contact','" + key + "','" + space.get("uid") + "','','" + value + "')");
                    }
                }
                if (inserts.size() != 0) {
                    dataBaseService.executeUpdate("DELETE FROM " + tname + " WHERE uid='" + space.get("uid")
                            + "' AND type='contact'");
                    dataBaseService.executeUpdate("INSERT INTO " + tname
                            + " (type,subtype,uid,title,friend) VALUES " + Common.implode(inserts, ","));
                }
                if (!Common.empty(sConfig.get("my_status"))) {
                    Map insertmap = new HashMap();
                    insertmap.put("uid", sGlobal.get("supe_uid"));
                    insertmap.put("action", "update");
                    insertmap.put("dateline", sGlobal.get("timestamp"));
                    insertmap.put("type", 2);
                    dataBaseService.insertTable("sns_userlog", insertmap, false, true);
                }
                if (Common.ckPrivacy(sGlobal, sConfig, space, "profile", 1)) {
                    mainService.addFeed(sGlobal, "profile",
                            Common.getMessage(request, "cp_feed_profile_update_contact"), null, "", null, "",
                            null, null, "", 0, 0, 0, "", false);
                }
                if (submitCheck(request, "nextsubmit")) {
                    return showMessage(request, response, "update_on_successful_individuals",
                            "main.action?ac=profile&op=edu");
                } else {
                    return showMessage(request, response, "update_on_successful_individuals",
                            "main.action?ac=profile&op=contact");
                }
            }
            Map friendmap = new HashMap();
            List<Map<String, Object>> infoList = dataBaseService.executeQuery(
                    "SELECT * FROM " + tname + " WHERE uid='" + space.get("uid") + "' AND type='contact'");
            for (Map info : infoList) {
                Map value = new HashMap();
                value.put(String.valueOf(info.get("friend")), " selected");
                friendmap.put(info.get("subtype"), value);
            }
            request.setAttribute("friendmap", friendmap);
        } else if (op.equals("edu")) {
            if ("delete".equals(request.getParameter("subop"))) {
                int infoId = Common.intval(request.getParameter("infoid"));
                if (infoId != 0) {
                    dataBaseService.executeUpdate("DELETE FROM " + tname + " WHERE infoid='" + infoId
                            + "' AND uid='" + uid + "' AND type='edu'");
                }
            }
            if (submitCheck(request, "profilesubmit") || submitCheck(request, "nextsubmit")) {
                List inserts = new ArrayList();
                String[] title = request.getParameterValues("title[]");
                String[] subTitle = request.getParameterValues("subtitle[]");
                String[] startYear = request.getParameterValues("startyear[]");
                String[] friend = request.getParameterValues("friend[]");
                int groupCount = title.length;
                for (int i = 0; i < groupCount; i++) {
                    title[i] = Common.getStr(title[i], 100, true, true, false, 0, 0, request, response);
                    if (title[i].length() != 0) {
                        subTitle[i] = Common.getStr(subTitle[i], 20, true, true, false, 0, 0, request,
                                response);
                        startYear[i] = String.valueOf(Common.intval(startYear[i]));
                        friend[i] = String.valueOf(Common.intval(friend[i]));
                        inserts.add("('" + uid + "','edu','" + title[i] + "','" + subTitle[i] + "','"
                                + startYear[i] + "','" + friend[i] + "')");
                    }
                }
                if (inserts.size() != 0) {
                    dataBaseService.executeUpdate(
                            "INSERT INTO " + tname + " (uid,type,title,subtitle,startyear,friend) VALUES "
                                    + Common.implode(inserts, ","));
                }
                if (!Common.empty(sConfig.get("my_status"))) {
                    Map insertmap = new HashMap();
                    insertmap.put("uid", sGlobal.get("supe_uid"));
                    insertmap.put("action", "update");
                    insertmap.put("dateline", sGlobal.get("timestamp"));
                    insertmap.put("type", 2);
                    dataBaseService.insertTable("sns_userlog", insertmap, false, true);
                }
                if (Common.ckPrivacy(sGlobal, sConfig, space, "profile", 1)) {
                    mainService.addFeed(sGlobal, "profile",
                            Common.getMessage(request, "cp_feed_profile_update_edu"), null, "", null, "", null,
                            null, "", 0, 0, 0, "", false);
                }
                if (submitCheck(request, "nextsubmit")) {
                    return showMessage(request, response, "update_on_successful_individuals",
                            "main.action?ac=profile&op=work");
                } else {
                    return showMessage(request, response, "update_on_successful_individuals",
                            "main.action?ac=profile&op=edu");
                }
            }
            List<Map<String, Object>> list = dataBaseService.executeQuery(
                    "SELECT * FROM " + tname + " WHERE uid='" + uid + "' AND type='edu' ORDER BY startyear");
            for (Map<String, Object> value : list) {
                value.put("title_s", Common.urlEncode((String) value.get("title")));
                value.put("friend", String.valueOf(value.get("friend")));
            }
            request.setAttribute("list", list);
        } else if (op.equals("work")) {
            if ("delete".equals(request.getParameter("subop"))) {
                int infoId = Common.intval(request.getParameter("infoid"));
                if (infoId != 0) {
                    dataBaseService.executeUpdate("DELETE FROM " + tname + " WHERE infoid='" + infoId
                            + "' AND uid='" + uid + "' AND type='work'");
                }
            }
            if (submitCheck(request, "profilesubmit") || submitCheck(request, "nextsubmit")) {
                List inserts = new ArrayList();
                String[] title = request.getParameterValues("title[]");
                String[] subTitle = request.getParameterValues("subtitle[]");
                String[] startYear = request.getParameterValues("startyear[]");
                String[] startMonth = request.getParameterValues("startmonth[]");
                String[] endYear = request.getParameterValues("endyear[]");
                String[] endMonth = request.getParameterValues("endmonth[]");
                String[] friend = request.getParameterValues("friend[]");
                int groupCount = title.length;
                for (int i = 0; i < groupCount; i++) {
                    title[i] = Common.getStr(title[i], 100, true, true, false, 0, 0, request, response);
                    if (title[i].length() != 0) {
                        subTitle[i] = Common.getStr(subTitle[i], 20, true, true, false, 0, 0, request,
                                response);
                        startYear[i] = String.valueOf(Common.intval(startYear[i]));
                        startMonth[i] = String.valueOf(Common.intval(startMonth[i]));
                        endYear[i] = String.valueOf(Common.intval(endYear[i]));
                        endMonth[i] = endYear[i].equals("0") == false
                                ? String.valueOf(Common.intval(endMonth[i]))
                                : "0";
                        friend[i] = String.valueOf(Common.intval(friend[i]));
                        inserts.add("('" + uid + "','work','" + title[i] + "','" + subTitle[i] + "','"
                                + startYear[i] + "','" + startMonth[i] + "','" + endYear[i] + "','"
                                + endMonth[i] + "','" + friend[i] + "')");
                    }
                }
                if (inserts.size() != 0) {
                    dataBaseService.executeUpdate("INSERT INTO " + tname
                            + " (uid,type,title,subtitle,startyear,startmonth,endyear,endmonth,friend) VALUES "
                            + Common.implode(inserts, ","));
                }
                if (!Common.empty(sConfig.get("my_status"))) {
                    Map insertmap = new HashMap();
                    insertmap.put("uid", sGlobal.get("supe_uid"));
                    insertmap.put("action", "update");
                    insertmap.put("dateline", sGlobal.get("timestamp"));
                    insertmap.put("type", 2);
                    dataBaseService.insertTable("sns_userlog", insertmap, false, true);
                }
                if (Common.ckPrivacy(sGlobal, sConfig, space, "profile", 1)) {
                    mainService.addFeed(sGlobal, "profile",
                            Common.getMessage(request, "cp_feed_profile_update_work"), null, "", null, "", null,
                            null, "", 0, 0, 0, "", false);
                }
                if (submitCheck(request, "nextsubmit")) {
                    return showMessage(request, response, "update_on_successful_individuals",
                            "main.action?ac=profile&op=info");
                } else {
                    return showMessage(request, response, "update_on_successful_individuals",
                            "main.action?ac=profile&op=work");
                }
            }
            List<Map<String, Object>> list = dataBaseService
                    .executeQuery("SELECT * FROM " + tname + " WHERE uid='" + uid
                            + "' AND type='work' ORDER BY startyear,startmonth,endyear,endmonth");
            for (Map<String, Object> value : list) {
                value.put("title_s", Common.urlEncode((String) value.get("title")));
                value.put("friend", String.valueOf(value.get("friend")));
            }
            request.setAttribute("list", list);
        } else if (op.equals("info")) {
            if (submitCheck(request, "profilesubmit")) {
                Pattern p = Pattern.compile("info\\[(.+)\\]");
                List inserts = new ArrayList();
                for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
                    String elementName = (String) e.nextElement();
                    if (elementName.startsWith("info[")) {
                        String key = p.matcher(elementName).replaceAll("$1");
                        String value = Common.getStr(request.getParameter(elementName), 500, true, true, false,
                                0, 0, request, response);
                        String friend = request.getParameter("info_friend[" + key + "]");
                        inserts.add("('" + uid + "','info','" + key + "','" + value + "','" + friend + "')");
                    }
                }
                if (inserts.isEmpty() == false) {
                    dataBaseService
                            .executeUpdate("DELETE FROM " + tname + " WHERE uid='" + uid + "' AND type='info'");
                    dataBaseService.executeUpdate("INSERT INTO " + tname
                            + " (uid,type,subtype,title,friend) VALUES " + Common.implode(inserts, ","));
                }
                if (!Common.empty(sConfig.get("my_status"))) {
                    Map insert = new HashMap();
                    insert.put("uid", sGlobal.get("supe_uid"));
                    insert.put("action", "update");
                    insert.put("dateline", sGlobal.get("timestamp"));
                    insert.put("type", 2);
                    dataBaseService.insertTable("sns_userlog", insert, false, true);
                }
                if (Common.ckPrivacy(sGlobal, sConfig, space, "profile", 1)) {
                    mainService.addFeed(sGlobal, "profile",
                            Common.getMessage(request, "cp_feed_profile_update_info"), null, "", null, "", null,
                            null, "", 0, 0, 0, "", false);
                }
                return showMessage(request, response, "update_on_successful_individuals",
                        "main.action?ac=profile&op=info");
            }
            Map infoarr = new LinkedHashMap();
            infoarr.put("trainwith", "");
            infoarr.put("interest", "");
            infoarr.put("book", "?");
            infoarr.put("movie", "");
            infoarr.put("tv", "");
            infoarr.put("music", "?");
            infoarr.put("game", "?");
            infoarr.put("sport", "?");
            infoarr.put("idol", "??");
            infoarr.put("motto", "?");
            infoarr.put("wish", "");
            infoarr.put("intro", "");
            Map list = new HashMap();
            Map friends = new HashMap();
            List<Map<String, Object>> query = dataBaseService
                    .executeQuery("SELECT * FROM " + tname + " WHERE uid='" + uid + "' AND type='info'");
            for (Map<String, Object> value : query) {
                list.put(value.get("subtype"), value);
                Map map = new HashMap();
                map.put(String.valueOf(value.get("friend")), " selected");
                friends.put(value.get("subtype"), map);
            }
            request.setAttribute("list", list);
            request.setAttribute("friends", friends);
            request.setAttribute("infoarr", infoarr);
        }
    } catch (Exception e) {
        return showMessage(request, response, e.getMessage());
    }
    if (op.equals("edu") || op.equals("work")) {
        StringBuffer yearHtml = new StringBuffer();
        int nowYear = Common.intval(Common.sgmdate(request, "yyyy", (Integer) sGlobal.get("timestamp")));
        for (int i = 0; i < 50; i++) {
            int they = nowYear - i;
            yearHtml.append("<option value=\"" + they + "\">" + they + "</option>");
        }
        StringBuffer monthHtml = new StringBuffer();
        for (int i = 1; i < 13; i++) {
            monthHtml.append("<option value=\"" + i + "\">" + i + "</option>");
        }
        request.setAttribute("yearhtml", yearHtml);
        request.setAttribute("monthhtml", monthHtml);
    }
    String theUrl = "main.action?ac=profile&op=" + op;
    Map farr = new HashMap();
    farr.put("0", "");
    farr.put("1", "?");
    farr.put("3", "");
    request.setAttribute("cat_actives_" + op, " class=\"active\"");
    request.setAttribute("farr", farr);
    request.setAttribute("theurl", theUrl);
    request.setAttribute("op", op);
    return include(request, response, sConfig, sGlobal, "cp_profile.jsp");
}

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 ww w  .  ja  v a  2 s  . c o m*/
        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);
        }/*  w w  w  .j a va2  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.tmwsoft.sns.web.action.MainAction.java

public ActionForward cp_friend(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");
    String op = request.getParameter("op");
    int uid = Common.intval(request.getParameter("uid"));
    space.put("key", Common.spaceKey(space, sConfig, 0));
    Map<String, String> actives = new HashMap<String, String>();
    actives.put(op, " class=\"active\"");
    request.setAttribute("actives", actives);
    try {//from  w  ww . jav a  2 s.  c  o  m
        if ("add".equals(op)) {
            if (!Common.checkPerm(request, response, "allowfriend")) {
                MessageVO msgVO = Common.ckSpaceLog(request);
                if (msgVO != null) {
                    return showMessage(request, response, msgVO);
                }
                return showMessage(request, response, "no_privilege");
            }
            if (uid == (Integer) sGlobal.get("supe_uid")) {
                return showMessage(request, response, "friend_self_error");
            }
            if (Common.in_array((String[]) space.get("friends"), uid)) {
                return showMessage(request, response, "you_have_friends");
            }
            if (!mainService.checkRealName(request, "friend")) {
                return showMessage(request, response, "no_privilege_realname");
            }
            Map<String, Object> toSpace = Common.getSpace(request, sGlobal, sConfig, uid);
            if (Common.empty(toSpace)) {
                return showMessage(request, response, "space_does_not_exist");
            }
            if (mainService.isBlackList((Integer) toSpace.get("uid"), (Integer) sGlobal.get("supe_uid")) != 0) {
                return showMessage(request, response, "is_blacklist");
            }
            Map<Integer, String> groups = Common.getFriendGroup(request);
            int status = Common.getFriendStatus((Integer) sGlobal.get("supe_uid"), uid);
            if (status == 1) {
                return showMessage(request, response, "you_have_friends");
            } else {
                int maxFriendNum = (Integer) Common.checkPerm(request, response, sGlobal, "maxfriendnum");
                if (maxFriendNum != 0 && (Integer) space.get("friendnum") >= maxFriendNum
                        + (Integer) space.get("addfriend")) {
                    Map globalMagic = Common.getCacheDate(request, response, "cache/cache_magic.jsp",
                            "globalMagic");
                    if (!Common.empty(globalMagic.get("friendnum"))) {
                        return showMessage(request, response, "enough_of_the_number_of_friends_with_magic");
                    } else {
                        return showMessage(request, response, "enough_of_the_number_of_friends");
                    }
                }

                int fStatus = Common.getFriendStatus(uid, (Integer) sGlobal.get("supe_uid"));
                int fu_requestfriendauditing = 0;

                try {
                    fu_requestfriendauditing = ((Integer) ((Map) ((Map) toSpace.get("privacy")).get("view"))
                            .get("requestfriendauditing")).intValue();
                    if (fu_requestfriendauditing == 1) {
                        fStatus = 0;
                        Map<String, String> parames = new HashMap<String, String>();
                        parames.put("op", "add");
                        parames.put("add2submit", "true");
                        parames.put("gid", "0");
                        parames.put("uid", uid + "");
                        request = new AddFriendHttpServletRequestWrapper(request, parames);
                    }
                } catch (Exception ex) {
                    ;
                }

                if (fStatus == -1) {
                    if (status == -1) {
                        if (!Common.empty(toSpace.get("videostatus"))) {
                            if (!mainService.checkVideoPhoto(request, response, "friend", toSpace)) {
                                return showMessage(request, response, "no_privilege_videophoto");
                            }
                        }
                        if (submitCheck(request, "addsubmit")) {
                            Map<String, Object> serArr = new HashMap<String, Object>();
                            serArr.put("uid", sGlobal.get("supe_uid"));
                            serArr.put("fuid", uid);
                            serArr.put("fusername", Common.addSlashes((String) toSpace.get("username")));
                            serArr.put("gid", Common.intval(request.getParameter("gid")));
                            serArr.put("note", Common.getStr(request.getParameter("note"), 50, true, true,
                                    false, 0, 0, request, response));
                            serArr.put("dateline", sGlobal.get("timestamp"));
                            dataBaseService.insertTable("sns_friend", serArr, false, false);
                            mainService.sendMail(request, response, uid, "",
                                    Common.getMessage(request, "cp_friend_subject",
                                            new String[] { sNames.get(space.get("uid")),
                                                    Common.getSiteUrl(request)
                                                            + "main.action?ac=friend&amp;op=request" }),
                                    "", "friend_add");
                            dataBaseService.executeUpdate(
                                    "UPDATE sns_space SET addfriendnum=addfriendnum+1 WHERE uid='" + uid + "'");
                            return showMessage(request, response, "request_has_been_sent");
                        } else {
                            request.setAttribute("op", op);
                            request.setAttribute("tospace", toSpace);
                            request.setAttribute("groups", groups);
                            return include(request, response, sConfig, sGlobal, "cp_friend.jsp");
                        }
                    } else {
                        return showMessage(request, response, "waiting_for_the_other_test");
                    }
                } else {
                    boolean result = false;
                    if (fu_requestfriendauditing == 0) {
                        result = submitCheck(request, "add2submit");
                    } else {
                        result = true;
                    }
                    if (result) {
                        int gid = Common.intval(request.getParameter("gid"));
                        if (fu_requestfriendauditing == 0) {
                            mainService.updateFriend(request, sGlobal, sConfig, (Integer) space.get("uid"),
                                    (String) space.get("username"), (Integer) toSpace.get("uid"),
                                    (String) toSpace.get("username"), "add", gid);
                        } else {
                            mainService.updateFriend(request, sGlobal, sConfig, (Integer) space.get("uid"),
                                    (String) space.get("username"), (Integer) toSpace.get("uid"),
                                    (String) toSpace.get("username"), "invite", gid);
                        }
                        if (Common.ckPrivacy(sGlobal, sConfig, space, "friend", 1)) {
                            Map<String, String> fs = new HashMap<String, String>();
                            fs.put("icon", "friend");
                            fs.put("title_template", Common.getMessage(request, "cp_feed_friend_title"));
                            fs.put("body_template", "");
                            fs.put("body_general", "");
                            Map titleData = new HashMap();
                            titleData.put("touser", "<a href=\"zone.action?uid=" + toSpace.get("uid") + "\">"
                                    + sNames.get(toSpace.get("uid")) + "</a>");
                            mainService.addFeed(sGlobal, fs.get("icon"), fs.get("title_template"), titleData,
                                    fs.get("body_template"), null, fs.get("body_general"), null, null, "", 0, 0,
                                    0, "", false);
                        }
                        dataBaseService
                                .executeUpdate("UPDATE sns_space SET addfriendnum=addfriendnum-1 WHERE uid='"
                                        + space.get("uid") + "' AND addfriendnum>0");
                        mainService.addNotification(request, sGlobal, sConfig, uid, "friend",
                                Common.getMessage(request, "cp_note_friend_add"), false);
                        return showMessage(request, response, "friends_add", request.getParameter("refer"), 1,
                                new String[] { sNames.get(toSpace.get("uid")) });
                    } else {
                        op = "add2";
                        request.setAttribute("op", op);
                        request.setAttribute("tospace", toSpace);
                        request.setAttribute("groups", groups);
                        return include(request, response, sConfig, sGlobal, "cp_friend.jsp");
                    }
                }
            }
        } else if ("ignore".equals(op)) {
            if (uid > 0) {
                if (submitCheck(request, "friendsubmit")) {
                    int fStatus = Common.getFriendStatus(uid, (Integer) space.get("uid"));
                    if (fStatus == 1) {
                        mainService.updateFriend(request, sGlobal, sConfig, (Integer) sGlobal.get("supe_uid"),
                                (String) sGlobal.get("supe_username"), uid, "", "ignore", 0);
                    } else if (fStatus == 0) {
                        mainService.ignoreRequest(space, sConfig, uid);
                    }
                    return showMessage(request, response, "do_success", "main.action?ac=friend&op=request", 0);
                }
            } else if (space.get("key").toString().equals(request.getParameter("key"))) {
                List<Map<String, Object>> fUids = dataBaseService
                        .executeQuery("SELECT uid FROM sns_friend WHERE fuid='" + space.get("uid")
                                + "' AND status='0' LIMIT 0,1");
                if (fUids.size() > 0) {
                    Map<String, Object> value = fUids.get(0);
                    uid = (Integer) value.get("uid");
                    Map whereArr = new HashMap();
                    whereArr.put("uid", uid);
                    String userName = Common.getCount("sns_space", whereArr, "username");
                    mainService.ignoreRequest(space, sConfig, uid);
                    return showMessage(request, response, "friend_ignore_next",
                            "main.action?ac=friend&op=ignore&confirm=1&key=" + space.get("key"), 1, userName);
                } else {
                    return showMessage(request, response, "do_success", "main.action?ac=friend&op=request", 0);
                }
            } else {
                return showMessage(request, response, "specified_user_is_not_your_friend");
            }
        } else if ("addconfirm".equals(op)) {
            if (space.get("key").toString().equals(request.getParameter("key"))) {
                int maxFriendNum = (Integer) Common.checkPerm(request, response, sGlobal, "maxfriendnum");
                if (maxFriendNum != 0 && (Integer) space.get("friendnum") >= maxFriendNum
                        + (Integer) space.get("addfriend")) {
                    Map globalMagic = Common.getCacheDate(request, response, "cache/cache_magic.jsp",
                            "globalMagic");
                    if (!Common.empty(globalMagic.get("friendnum"))) {
                        return showMessage(request, response, "enough_of_the_number_of_friends_with_magic");
                    } else {
                        return showMessage(request, response, "enough_of_the_number_of_friends");
                    }
                }
                List<Map<String, Object>> uids = dataBaseService
                        .executeQuery("SELECT uid FROM sns_friend WHERE fuid='" + space.get("uid")
                                + "' AND status='0' LIMIT 0,1");
                if (uids.size() > 0) {
                    Map<String, Object> value = uids.get(0);
                    uid = (Integer) value.get("uid");
                    Map whereArr = new HashMap();
                    whereArr.put("uid", uid);
                    String userName = Common.getCount("sns_space", whereArr, "username");
                    mainService.updateFriend(request, sGlobal, sConfig, (Integer) space.get("uid"),
                            (String) space.get("username"), uid, userName, "add", 0);
                    dataBaseService.executeUpdate("UPDATE sns_space SET addfriendnum=addfriendnum-1 WHERE uid='"
                            + space.get("uid") + "' AND addfriendnum>0");
                    return showMessage(request, response, "friend_addconfirm_next",
                            "main.action?ac=friend&op=addconfirm&key=" + space.get("key"), 1, userName);
                }
            }
            return showMessage(request, response, "do_success", "main.action?ac=friend&op=request", 0);
        } else if ("syn".equals(op)) {
            return null;
        } else if ("find".equals(op)) {
            int maxNum = 18;
            List noUids = new ArrayList();
            if (space.get("friends") != null) {
                CollectionUtils.addAll(noUids, (String[]) space.get("friends"));
            }
            noUids.add(space.get("uid").toString());
            List<Map<String, Object>> nearList = new ArrayList<Map<String, Object>>(maxNum);
            int i = 0;
            String myIp = Common.getOnlineIP(request, true);
            List<Map<String, Object>> sessionList = dataBaseService
                    .executeQuery("SELECT * FROM sns_session WHERE ip='" + myIp + "' LIMIT 0,200");
            for (Map<String, Object> value : sessionList) {
                if (!noUids.contains(value.get("uid").toString())) {
                    nearList.add(value);
                    i++;
                    if (i >= maxNum) {
                        break;
                    }
                }
            }
            request.setAttribute("nearList", nearList);
            i = 0;
            if (!Common.empty(space.get("feedfriend"))) {
                Map friendList = new HashMap(maxNum);
                List<Map<String, Object>> friends = dataBaseService
                        .executeQuery("SELECT fuid AS uid, fusername AS username FROM "
                                + " sns_friend WHERE uid IN (" + space.get("feedfriend") + ") LIMIT 0,200");
                for (Map<String, Object> value : friends) {
                    if (!noUids.contains(value.get("uid").toString()) && !Common.empty(value.get("username"))) {
                        friendList.put(value.get("uid"), value);
                        i++;
                        if (i >= maxNum) {
                            break;
                        }
                    }
                }
                request.setAttribute("friendList", friendList);
            }
            i = 0;
            List<Map<String, Object>> onLineList = new ArrayList<Map<String, Object>>(maxNum);
            List<Map<String, Object>> onLines = dataBaseService
                    .executeQuery("SELECT * FROM sns_session LIMIT 0,200");
            for (Map<String, Object> value : onLines) {
                if (!noUids.contains(value.get("uid").toString())) {
                    onLineList.add(value);
                    i++;
                    if (i >= maxNum) {
                        break;
                    }
                }
            }
            request.setAttribute("onLineList", onLineList);
        } else if ("changegroup".equals(op)) {
            if (submitCheck(request, "changegroupsubmit")) {
                dataBaseService.executeUpdate(
                        "UPDATE sns_friend SET gid='" + Common.intval(request.getParameter("group"))
                                + "' WHERE uid='" + sGlobal.get("supe_uid") + "' AND fuid='" + uid + "'");
                mainService.friendCache(request, sGlobal, sConfig, (Integer) sGlobal.get("supe_uid"));
                return showMessage(request, response, "do_success", (String) sGlobal.get("refer"));
            }
            List<Map<String, Object>> friends = dataBaseService
                    .executeQuery("SELECT * FROM sns_friend WHERE uid='" + sGlobal.get("supe_uid")
                            + "' AND fuid='" + uid + "'");
            if (friends.isEmpty()) {
                return showMessage(request, response, "specified_user_is_not_your_friend");
            }
            Map<String, Object> friend = friends.get(0);
            Map groupSelect = new HashMap();
            groupSelect.put(friend.get("gid"), " checked");
            Map<Integer, String> groups = Common.getFriendGroup(request);
            request.setAttribute("groups", groups);
            request.setAttribute("groupSelect", groupSelect);
        } else if ("changenum".equals(op)) {
            if (submitCheck(request, "changenumsubmit")) {
                dataBaseService.executeUpdate(
                        "UPDATE sns_friend SET num='" + Common.intval(request.getParameter("num"))
                                + "' WHERE uid='" + sGlobal.get("supe_uid") + "' AND fuid='" + uid + "'");
                mainService.friendCache(request, sGlobal, sConfig, (Integer) sGlobal.get("supe_uid"));
                return showMessage(request, response, "do_success", (String) sGlobal.get("refer"), 0);
            }
            List<Map<String, Object>> friends = dataBaseService
                    .executeQuery("SELECT * FROM sns_friend WHERE uid='" + sGlobal.get("supe_uid")
                            + "' AND fuid='" + uid + "'");
            if (friends.isEmpty()) {
                return showMessage(request, response, "specified_user_is_not_your_friend");
            }
            request.setAttribute("friend", friends.get(0));
        } else if ("group".equals(op)) {
            if (submitCheck(request, "groupsubmin")) {
                String[] fUids = request.getParameterValues("fuids");
                if (Common.empty(fUids)) {
                    return showMessage(request, response, "please_correct_choice_groups_friend");
                }
                int groupId = Common.intval(request.getParameter("group"));
                dataBaseService.executeUpdate(
                        "UPDATE sns_friend SET gid='" + groupId + "' WHERE uid='" + sGlobal.get("supe_uid")
                                + "' AND fuid IN (" + Common.sImplode(fUids) + ") AND status='1'");
                mainService.friendCache(request, sGlobal, sConfig, (Integer) sGlobal.get("supe_uid"));
                return showMessage(request, response, "do_success", (String) sGlobal.get("refer"));
            }
            int perPage = 50;
            int page = Common.intval(request.getParameter("page"));
            if (page < 1) {
                page = 1;
            }
            int start = (page - 1) * perPage;
            if (!Common.empty(space.get("friendnum"))) {
                Map<Integer, String> groups = Common.getFriendGroup(request);
                String theURL = "main.action?ac=friend&op=group";
                int group = request.getParameter("group") == null ? -1
                        : Common.intval(request.getParameter("group"));
                String whereSQL = "";
                if (group > -1) {
                    whereSQL = "AND main.gid='" + group + "'";
                    theURL += "&group=" + group;
                }
                int count = dataBaseService.findRows("SELECT COUNT(*) FROM sns_friend main WHERE main.uid='"
                        + space.get("uid") + "' AND main.status='1' " + whereSQL);
                List<Map<String, Object>> list = dataBaseService.executeQuery(
                        "SELECT main.fuid AS uid,main.fusername AS username, main.gid, main.num FROM sns_friend main WHERE main.uid='"
                                + space.get("uid") + "' AND main.status='1' " + whereSQL
                                + " ORDER BY main.dateline DESC LIMIT " + start + "," + perPage);
                for (Map<String, Object> value : list) {
                    value.put("group", groups.get(value.get("gid")));
                }
                request.setAttribute("list", list);
                request.setAttribute("multi", Common.multi(request, count, perPage, page,
                        (Integer) sConfig.get("maxpage"), theURL, null, null));
            }
            Map<Integer, String> groups = Common.getFriendGroup(request);
            request.setAttribute("groups", groups);
            actives.put("group", " class=\"active\"");
        } else if ("request".equals(op)) {
            if (submitCheck(request, "requestsubmin")) {
                return showMessage(request, response, "do_success", (String) sGlobal.get("refer"));
            }
            int maxFriendnum = (Integer) Common.checkPerm(request, response, sGlobal, "maxfriendnum");
            if (maxFriendnum > 0) {
                maxFriendnum = maxFriendnum + (Integer) space.get("addfriend");
            }
            int perPage = 20;
            int page = Common.intval(request.getParameter("page"));
            if (page < 1) {
                page = 1;
            }
            int start = (page - 1) * perPage;
            String[] friend1 = (String[]) space.get("friends");
            Map whereArr = new HashMap();
            whereArr.put("fuid", space.get("uid"));
            whereArr.put("status", 0);
            int count = Common.intval(Common.getCount("sns_friend", whereArr, null));
            if (count > 0) {
                List<Map<String, Object>> list = dataBaseService
                        .executeQuery("SELECT f.dateline,f.note,f.fuid, s.*, sf.friend FROM "
                                + " sns_friend f LEFT JOIN sns_space s ON s.uid=f.uid LEFT JOIN sns_spacefield sf ON sf.uid=f.uid WHERE f.fuid='"
                                + space.get("uid") + "' AND f.status='0' ORDER BY f.dateline DESC LIMIT "
                                + start + "," + perPage);
                for (Map<String, Object> value : list) {
                    String[] cFriend = {};
                    String[] friend2 = Common.empty(value.get("friend")) ? null
                            : value.get("friend").toString().split(",");
                    if (friend1 != null && friend2 != null) {
                        cFriend = getArrayIntersect(friend1, friend2);
                    }
                    value.put("cfriend", Common.implode(cFriend, ","));
                    value.put("cfcount", cFriend.length);
                }
                request.setAttribute("list", list);
            }
            if (count != (Integer) space.get("addfriendnum")) {
                dataBaseService.executeUpdate("UPDATE sns_space SET addfriendnum='" + count + "' WHERE uid='"
                        + space.get("uid") + "'");
            }
            request.setAttribute("multi", Common.multi(request, count, perPage, page,
                    (Integer) sConfig.get("maxpage"), "main.action?ac=friend&op=request", null, null));
            request.setAttribute("maxfriendnum", maxFriendnum);
        } else if ("groupname".equals(op)) {
            Map<Integer, String> groups = Common.getFriendGroup(request);
            int group = Common.intval(request.getParameter("group"));
            if (groups.get(group) == null) {
                return showMessage(request, response, "change_friend_groupname_error");
            }
            if (submitCheck(request, "groupnamesubmit")) {
                Map<String, Object> privacy = (Map<String, Object>) space.get("privacy");
                Map<Integer, String> groupList = null;
                if (privacy != null) {
                    groupList = (Map<Integer, String>) privacy.get("groupname");
                }
                groupList = groupList == null ? new HashMap<Integer, String>() : groupList;
                String groupName = Common.getStr(request.getParameter("groupname"), 20, true, true, false, 0, 0,
                        request, response);
                groupList.put(group, groupName);
                if (privacy != null) {
                    privacy.put("groupname", groupList);
                    space.put("privacy", privacy);
                }
                mainService.privacyUpdate(privacy, (Integer) sGlobal.get("supe_uid"));
                return showMessage(request, response, "do_success", request.getParameter("refer"));
            }
            request.setAttribute("group", group);
            request.setAttribute("groups", groups);
        } else if ("groupignore".equals(op)) {
            Map<Integer, String> groups = Common.getFriendGroup(request);
            int group = Common.intval(request.getParameter("group"));
            if (groups.get(group) == null) {
                return showMessage(request, response, "change_friend_groupname_error");
            }
            if (submitCheck(request, "groupignoresubmit")) {
                Map<String, Object> privacy = (Map<String, Object>) space.get("privacy");
                Map<Integer, Integer> filterGid = null;
                if (privacy != null) {
                    filterGid = (Map<Integer, Integer>) privacy.get("filter_gid");
                }
                filterGid = filterGid == null ? new HashMap<Integer, Integer>() : filterGid;
                if (filterGid.get(group) != null) {
                    filterGid.remove(group);
                } else {
                    filterGid.put(group, group);
                }
                if (privacy != null) {
                    privacy.put("filter_gid", filterGid);
                    space.put("privacy", privacy);
                }
                mainService.privacyUpdate(privacy, (Integer) sGlobal.get("supe_uid"));
                mainService.friendCache(request, sGlobal, sConfig, (Integer) sGlobal.get("supe_uid"));
                return showMessage(request, response, "do_success", request.getParameter("refer"), 0);
            }
            request.setAttribute("group", group);
        } else if ("blacklist".equals(op)) {
            if ("delete".equals(request.getParameter("subop"))) {
                dataBaseService.executeUpdate("DELETE FROM sns_blacklist WHERE uid='" + space.get("uid")
                        + "' AND buid='" + uid + "'");
                return showMessage(request, response, "do_success",
                        "zone.action?do=friend&view=blacklist&start=" + request.getParameter("start"), 0);
            }
            if (submitCheck(request, "blacklistsubmit")) {
                String userName = Common.trim(request.getParameter("username"));
                List<Map<String, Object>> spaceList = dataBaseService
                        .executeQuery("SELECT * FROM sns_space WHERE username='" + userName + "'");
                if (spaceList.isEmpty()) {
                    return showMessage(request, response, "space_does_not_exist");
                }
                Map<String, Object> toSpace = spaceList.get(0);
                if (toSpace.get("uid").equals(space.get("uid"))) {
                    return showMessage(request, response, "unable_to_manage_self");
                }
                if (Common.in_array((String[]) space.get("friends"), toSpace.get("uid"))) {
                    mainService.updateFriend(request, sGlobal, sConfig, (Integer) sGlobal.get("supe_uid"),
                            (String) sGlobal.get("supe_username"), (Integer) toSpace.get("uid"), "", "ignore",
                            0);
                }
                Map insertData = new HashMap();
                insertData.put("uid", space.get("uid"));
                insertData.put("buid", toSpace.get("uid"));
                insertData.put("dateline", sGlobal.get("timestamp"));
                dataBaseService.insertTable("sns_blacklist", insertData, false, true);
                return showMessage(request, response, "do_success",
                        "zone.action?do=friend&view=blacklist&start=" + request.getParameter("start"), 0);
            }
        } else if ("rand".equals(op)) {
            Object[] randUids = null;
            if ((Integer) space.get("friendnum") < 5) {
                List<Map<String, Object>> sessionList = dataBaseService
                        .executeQuery("SELECT uid FROM sns_session LIMIT 0,100");
                List onlineList = new ArrayList(sessionList.size());
                for (Map<String, Object> value : sessionList) {
                    if (!value.get("uid").equals(space.get("uid"))) {
                        onlineList.add(value.get("uid"));
                    }
                }
                randUids = (Object[]) Common
                        .sarrayRand(arrayMerge(onlineList.toArray(), (String[]) space.get("friends")), 1);
            } else {
                randUids = (Object[]) Common.sarrayRand(space.get("friends"), 1);
            }
            return showMessage(request, response, "do_success",
                    "zone.action?uid=" + (randUids == null ? "" : randUids[randUids.length - 1]), 0);
        } else if ("getcfriend".equals(op)) {
            String[] fuids = Common.empty(request.getParameter("fuid")) ? null
                    : request.getParameter("fuid").split(",");
            Map<Integer, Integer> newfUids = new HashMap<Integer, Integer>(fuids == null ? 0 : fuids.length);
            if (fuids != null) {
                for (String value : fuids) {
                    int fuid = Common.intval(value);
                    if (fuid != 0) {
                        newfUids.put(fuid, fuid);
                    }
                }
            }
            if (!newfUids.isEmpty()) {
                List<Map<String, Object>> list = dataBaseService
                        .executeQuery("SELECT uid,username,name,namestatus FROM sns_space WHERE uid IN ("
                                + Common.sImplode(newfUids) + ") LIMIT 0,15");
                request.setAttribute("list", list);
            }
        } else if ("search".equals(op)) {
            Map<Integer, Map<String, Object>> fields = Common.getCacheDate(request, response,
                    "cache/cache_profilefield.jsp", "globalProfilefield");
            if (!Common.empty(request.getParameter("searchsubmit"))
                    || !Common.empty(request.getParameter("searchmode"))) {
                Map<String, String[]> paramMap = request.getParameterMap();
                paramMap.put("searchsubmit", new String[] { 1 + "" });
                paramMap.put("searchmode", new String[] { 1 + "" });
                List<String> whereArr = new ArrayList<String>();
                Map<String, String> fromArr = new HashMap<String, String>();
                String fSQL = "";
                fromArr.put("space", " sns_space s");
                String searchKey = request.getParameter("searchkey");
                if (!Common.empty(Common.stripSearchKey(searchKey))) {
                    whereArr.add("(s.name='" + searchKey + "' OR s.username='" + searchKey + "')");
                } else {
                    for (String value : new String[] { "uid", "username", "name", "videostatus", "avatar" }) {
                        if (!Common.empty(request.getParameter(value))) {
                            whereArr.add("s." + value + "='" + request.getParameter(value) + "'");
                        }
                    }
                }
                String spaceField = null;
                for (String value : new String[] { "sex", "qq", "msn", "birthyear", "birthmonth", "birthday",
                        "blood", "marry", "birthprovince", "birthcity", "resideprovince", "residecity" }) {
                    if (!Common.empty(request.getParameter(value))) {
                        fromArr.put("spacefield", " sns_spacefield sf");
                        spaceField = "sf.uid=s.uid";
                        whereArr.add("sf." + value + "='" + request.getParameter(value) + "'");
                        fSQL += ", sf." + value;
                    }
                }
                int startAge, endAge;
                endAge = startAge = 0;
                if (!Common.empty(request.getParameter("endage"))) {
                    startAge = Integer.valueOf(Common.sgmdate(request, "yyyy", 0))
                            - Common.intval(request.getParameter("endage"));
                }
                if (!Common.empty(request.getParameter("startage"))) {
                    endAge = Integer.valueOf(Common.sgmdate(request, "yyyy", 0))
                            - Common.intval(request.getParameter("startage"));
                }
                if (startAge != 0 || endAge != 0) {
                    fromArr.put("spacefield", " sns_spacefield sf");
                    spaceField = "sf.uid=s.uid";
                }
                if (startAge != 0 && endAge != 0 && endAge > startAge) {
                    whereArr.add("(sf.birthyear>=" + startAge + " AND sf.birthyear<=" + endAge + ")");
                } else if (startAge != 0 && endAge == 0) {
                    whereArr.add("sf.birthyear>=" + startAge);
                } else if (startAge == 0 && endAge != 0) {
                    whereArr.add("sf.birthyear<=" + endAge);
                }
                boolean haveField = false;
                for (Entry<Integer, Map<String, Object>> e : fields.entrySet()) {
                    if (!Common.empty(e.getValue().get("allowsearch"))) {
                        String field = Common.stripSearchKey(request.getParameter("field_" + e.getKey()));
                        if (!Common.empty(field)) {
                            haveField = true;
                            whereArr.add("sf.field_" + e.getKey() + " LIKE '%" + field + "%'");
                        }
                    }
                }
                if (haveField) {
                    fromArr.put("spacefield", " sns_spacefield sf");
                    spaceField = "sf.uid=s.uid";
                }
                String type = request.getParameter("type");
                String spaceInfo = null;
                if ("edu".equals(type) || "work".equals(type)) {
                    for (String value : new String[] { "type", "title", "subtitle", "startyear" }) {
                        if (!Common.empty(request.getParameter(value))) {
                            fromArr.put("spaceinfo", " sns_spaceinfo si");
                            spaceInfo = "si.uid=s.uid";
                            whereArr.add("si." + value + "='" + request.getParameter(value) + "'");
                        }
                    }
                }
                if (!whereArr.isEmpty()) {
                    List<Map<String, Object>> searchList = dataBaseService
                            .executeQuery("SELECT s.* " + fSQL + " FROM " + Common.implode(fromArr, ",")
                                    + " WHERE " + Common.implode(whereArr, " AND ")
                                    + (spaceField == null ? "" : " AND " + spaceField)
                                    + (spaceInfo == null ? "" : " AND " + spaceInfo) + " LIMIT 0,500");
                    Set<Map<String, Object>> list = new LinkedHashSet<Map<String, Object>>(searchList.size());
                    for (Map<String, Object> value : searchList) {
                        value.put("isfriend",
                                (value.get("uid").equals(space.get("uid"))
                                        || (Common.in_array((String[]) space.get("friends"), value.get("uid"))))
                                                ? true
                                                : false);
                        value.put("gColor", Common.getColor(request, response, (Integer) value.get("groupid")));
                        value.put("gIcon", Common.getIcon(request, response, (Integer) value.get("groupid")));
                        list.add(value);
                    }
                    request.setAttribute("list", list);
                }
            } else {
                StringBuffer yearHTML = new StringBuffer();
                int nowy = Integer.valueOf(Common.sgmdate(request, "yyyy", 0));
                for (int i = 0; i < 50; i++) {
                    int they = nowy - i;
                    yearHTML.append("<option value=\"" + they + "\">" + they + "</option>");
                }
                request.setAttribute("yearhtml", yearHTML);
                Map sexArr = new HashMap();
                sexArr.put(space.get("sex").toString(), " checked");
                request.setAttribute("sexarr", sexArr);
                String all = request.getParameter("all");
                StringBuffer birthYearHTML = new StringBuffer();
                for (int i = 0; i < 100; i++) {
                    int they = nowy - i;
                    String selectStr = "";
                    if (Common.empty(all)) {
                        selectStr = they == (Integer) space.get("birthyear") ? " selected" : "";
                    }
                    birthYearHTML
                            .append("<option value=\"" + they + "\"" + selectStr + ">" + they + "</option>");
                }
                request.setAttribute("birthyearhtml", birthYearHTML.toString());
                String birthMonthHTML = "";
                for (int i = 1; i < 13; i++) {
                    String selectStr = "";
                    if (Common.empty(all)) {
                        selectStr = i == (Integer) space.get("birthmonth") ? " selected" : "";
                    }
                    birthMonthHTML += "<option value=\"" + i + "\"" + selectStr + ">" + i + "</option>";
                }
                request.setAttribute("birthmonthhtml", birthMonthHTML.toString());
                StringBuffer birthdayHTML = new StringBuffer();
                for (int i = 1; i < 29; i++) {
                    String selectStr = "";
                    if (Common.empty(all)) {
                        selectStr = i == (Integer) space.get("birthday") ? " selected" : "";
                    }
                    birthdayHTML.append("<option value=\"" + i + "\"" + selectStr + ">" + i + "</option>");
                }
                request.setAttribute("birthdayhtml", birthdayHTML.toString());
                String bloodHTML = "";
                for (String value : new String[] { "A", "B", "O", "AB" }) {
                    String selectStr = "";
                    if (Common.empty(all)) {
                        selectStr = value.equals(space.get("blood")) ? " selected" : "";
                    }
                    bloodHTML += "<option value=\"" + value + "\"" + selectStr + ">" + value + "</option>";
                }
                request.setAttribute("bloodhtml", bloodHTML.toString());
                Map marryArr = new HashMap();
                marryArr.put(space.get("marry").toString(), " selected");
                request.setAttribute("marryarr", marryArr);
                List<Integer> removeKeys = new ArrayList<Integer>(fields.size());
                for (Entry<Integer, Map<String, Object>> e : fields.entrySet()) {
                    Map<String, Object> fValue = e.getValue();
                    if (!Common.empty(fValue.get("allowsearch"))) {
                        if ("text".equals(fValue.get("formtype"))) {
                            fValue.put("html", "<input type=\"text\" name=\"field_" + e.getKey()
                                    + "\" value=\"\" class=\"t_input\">");
                        } else {
                            StringBuffer HTML = new StringBuffer();
                            HTML.append("<select name=\"field_" + e.getKey()
                                    + "\"><option value=\"\">---</option>");
                            String[] optionArr = fValue.get("choice").toString().split("\n");
                            for (String ov : optionArr) {
                                ov = ov.trim();
                                if (!"".equals(ov)) {
                                    HTML.append("<option value=\"" + ov + "\">" + ov + "</option>");
                                }
                            }
                            HTML.append("</select>");
                            fValue.put("html", HTML.toString());
                        }
                    } else {
                        removeKeys.add(e.getKey());
                    }
                }
                for (Integer removeKey : removeKeys) {
                    fields.remove(removeKey);
                }
                request.setAttribute("fields", fields);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        return showMessage(request, response, e.getMessage());
    }
    request.setAttribute("op", op);
    request.setAttribute("uid", uid);
    return include(request, response, sConfig, sGlobal, "cp_friend.jsp");
}

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

public ActionForward cp_friend(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");
    String op = request.getParameter("op");
    int uid = Common.intval(request.getParameter("uid"));
    space.put("key", Common.spaceKey(space, sConfig, 0));
    Map<String, String> actives = new HashMap<String, String>();
    actives.put(op, " class=\"active\"");
    request.setAttribute("actives", actives);
    try {//  w w w  . j  av a 2s .  c  o  m
        if ("add".equals(op)) {
            if (!Common.checkPerm(request, response, "allowfriend")) {
                MessageVO msgVO = Common.ckSpaceLog(request);
                if (msgVO != null) {
                    return showMessage(request, response, msgVO);
                }
                return showMessage(request, response, "no_privilege");
            }
            if (uid == (Integer) sGlobal.get("supe_uid")) {
                return showMessage(request, response, "friend_self_error");
            }
            if (Common.in_array((String[]) space.get("friends"), uid)) {
                return showMessage(request, response, "you_have_friends");
            }
            if (!cpService.checkRealName(request, "friend")) {
                return showMessage(request, response, "no_privilege_realname");
            }
            Map<String, Object> toSpace = Common.getSpace(request, sGlobal, sConfig, uid);
            if (Common.empty(toSpace)) {
                return showMessage(request, response, "space_does_not_exist");
            }
            if (cpService.isBlackList((Integer) toSpace.get("uid"), (Integer) sGlobal.get("supe_uid")) != 0) {
                return showMessage(request, response, "is_blacklist");
            }
            Map<Integer, String> groups = Common.getFriendGroup(request);
            int status = Common.getFriendStatus((Integer) sGlobal.get("supe_uid"), uid);
            if (status == 1) {
                return showMessage(request, response, "you_have_friends");
            } else {
                int maxFriendNum = (Integer) Common.checkPerm(request, response, sGlobal, "maxfriendnum");
                if (maxFriendNum != 0 && (Integer) space.get("friendnum") >= maxFriendNum
                        + (Integer) space.get("addfriend")) {
                    Map globalMagic = Common.getCacheDate(request, response, "/data/cache/cache_magic.jsp",
                            "globalMagic");
                    if (!Common.empty(globalMagic.get("friendnum"))) {
                        return showMessage(request, response, "enough_of_the_number_of_friends_with_magic");
                    } else {
                        return showMessage(request, response, "enough_of_the_number_of_friends");
                    }
                }
                int fStatus = Common.getFriendStatus(uid, (Integer) sGlobal.get("supe_uid"));
                if (fStatus == -1) {
                    if (status == -1) {
                        if (!Common.empty(toSpace.get("videostatus"))) {
                            if (!cpService.checkVideoPhoto(request, response, "friend", toSpace)) {
                                return showMessage(request, response, "no_privilege_videophoto");
                            }
                        }
                        if (submitCheck(request, "addsubmit")) {
                            Map<String, Object> serArr = new HashMap<String, Object>();
                            serArr.put("uid", sGlobal.get("supe_uid"));
                            serArr.put("fuid", uid);
                            serArr.put("fusername", Common.addSlashes((String) toSpace.get("username")));
                            serArr.put("gid", Common.intval(request.getParameter("gid")));
                            serArr.put("note", Common.getStr(request.getParameter("note"), 50, true, true,
                                    false, 0, 0, request, response));
                            serArr.put("dateline", sGlobal.get("timestamp"));
                            dataBaseService.insertTable("friend", serArr, false, false);
                            cpService.sendMail(request, response, uid, "", Common.getMessage(request,
                                    "cp_friend_subject",
                                    new String[] { sNames.get(space.get("uid")),
                                            Common.getSiteUrl(request) + "cp.jsp?ac=friend&amp;op=request" }),
                                    "", "friend_add");
                            dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("space")
                                    + " SET addfriendnum=addfriendnum+1 WHERE uid='" + uid + "'");
                            return showMessage(request, response, "request_has_been_sent");
                        } else {
                            request.setAttribute("op", op);
                            request.setAttribute("tospace", toSpace);
                            request.setAttribute("groups", groups);
                            return include(request, response, sConfig, sGlobal, "cp_friend.jsp");
                        }
                    } else {
                        return showMessage(request, response, "waiting_for_the_other_test");
                    }
                } else {
                    if (submitCheck(request, "add2submit")) {
                        int gid = Common.intval(request.getParameter("gid"));
                        cpService.updateFriend(request, sGlobal, sConfig, (Integer) space.get("uid"),
                                (String) space.get("username"), (Integer) toSpace.get("uid"),
                                (String) toSpace.get("username"), "add", gid);
                        if (Common.ckPrivacy(sGlobal, sConfig, space, "friend", 1)) {
                            Map<String, String> fs = new HashMap<String, String>();
                            fs.put("icon", "friend");
                            fs.put("title_template", Common.getMessage(request, "cp_feed_friend_title"));
                            fs.put("body_template", "");
                            fs.put("body_general", "");
                            Map titleData = new HashMap();
                            titleData.put("touser", "<a href=\"space.jsp?uid=" + toSpace.get("uid") + "\">"
                                    + sNames.get(toSpace.get("uid")) + "</a>");
                            cpService.addFeed(sGlobal, fs.get("icon"), fs.get("title_template"), titleData,
                                    fs.get("body_template"), null, fs.get("body_general"), null, null, "", 0, 0,
                                    0, "", false);
                        }
                        dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("space")
                                + " SET addfriendnum=addfriendnum-1 WHERE uid='" + space.get("uid")
                                + "' AND addfriendnum>0");
                        cpService.addNotification(request, sGlobal, sConfig, uid, "friend",
                                Common.getMessage(request, "cp_note_friend_add"), false);
                        return showMessage(request, response, "friends_add", request.getParameter("refer"), 1,
                                new String[] { sNames.get(toSpace.get("uid")) });
                    } else {
                        op = "add2";
                        request.setAttribute("op", op);
                        request.setAttribute("tospace", toSpace);
                        request.setAttribute("groups", groups);
                        return include(request, response, sConfig, sGlobal, "cp_friend.jsp");
                    }
                }
            }
        } else if ("ignore".equals(op)) {
            if (uid > 0) {
                if (submitCheck(request, "friendsubmit")) {
                    int fStatus = Common.getFriendStatus(uid, (Integer) space.get("uid"));
                    if (fStatus == 1) {
                        cpService.updateFriend(request, sGlobal, sConfig, (Integer) sGlobal.get("supe_uid"),
                                (String) sGlobal.get("supe_username"), uid, "", "ignore", 0);
                    } else if (fStatus == 0) {
                        cpService.ignoreRequest(space, sConfig, uid);
                    }
                    return showMessage(request, response, "do_success", "cp.jsp?ac=friend&op=request", 0);
                }
            } else if (space.get("key").toString().equals(request.getParameter("key"))) {
                List<Map<String, Object>> fUids = dataBaseService
                        .executeQuery("SELECT uid FROM " + JavaCenterHome.getTableName("friend")
                                + " WHERE fuid='" + space.get("uid") + "' AND status='0' LIMIT 0,1");
                if (fUids.size() > 0) {
                    Map<String, Object> value = fUids.get(0);
                    uid = (Integer) value.get("uid");
                    Map whereArr = new HashMap();
                    whereArr.put("uid", uid);
                    String userName = Common.getCount("space", whereArr, "username");
                    cpService.ignoreRequest(space, sConfig, uid);
                    return showMessage(request, response, "friend_ignore_next",
                            "cp.jsp?ac=friend&op=ignore&confirm=1&key=" + space.get("key"), 1, userName);
                } else {
                    return showMessage(request, response, "do_success", "cp.jsp?ac=friend&op=request", 0);
                }
            } else {
                return showMessage(request, response, "specified_user_is_not_your_friend");
            }
        } else if ("addconfirm".equals(op)) {
            if (space.get("key").toString().equals(request.getParameter("key"))) {
                int maxFriendNum = (Integer) Common.checkPerm(request, response, sGlobal, "maxfriendnum");
                if (maxFriendNum != 0 && (Integer) space.get("friendnum") >= maxFriendNum
                        + (Integer) space.get("addfriend")) {
                    Map globalMagic = Common.getCacheDate(request, response, "/data/cache/cache_magic.jsp",
                            "globalMagic");
                    if (!Common.empty(globalMagic.get("friendnum"))) {
                        return showMessage(request, response, "enough_of_the_number_of_friends_with_magic");
                    } else {
                        return showMessage(request, response, "enough_of_the_number_of_friends");
                    }
                }
                List<Map<String, Object>> uids = dataBaseService
                        .executeQuery("SELECT uid FROM " + JavaCenterHome.getTableName("friend")
                                + " WHERE fuid='" + space.get("uid") + "' AND status='0' LIMIT 0,1");
                if (uids.size() > 0) {
                    Map<String, Object> value = uids.get(0);
                    uid = (Integer) value.get("uid");
                    Map whereArr = new HashMap();
                    whereArr.put("uid", uid);
                    String userName = Common.getCount("space", whereArr, "username");
                    cpService.updateFriend(request, sGlobal, sConfig, (Integer) space.get("uid"),
                            (String) space.get("username"), uid, userName, "add", 0);
                    dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("space")
                            + " SET addfriendnum=addfriendnum-1 WHERE uid='" + space.get("uid")
                            + "' AND addfriendnum>0");
                    return showMessage(request, response, "friend_addconfirm_next",
                            "cp.jsp?ac=friend&op=addconfirm&key=" + space.get("key"), 1, userName);
                }
            }
            return showMessage(request, response, "do_success", "cp.jsp?ac=friend&op=request", 0);
        } else if ("syn".equals(op)) {
            return null;
        } else if ("find".equals(op)) {
            int maxNum = 18;
            List noUids = new ArrayList();
            if (space.get("friends") != null) {
                CollectionUtils.addAll(noUids, (String[]) space.get("friends"));
            }
            noUids.add(space.get("uid").toString());
            List<Map<String, Object>> nearList = new ArrayList<Map<String, Object>>(maxNum);
            int i = 0;
            String myIp = Common.getOnlineIP(request, true);
            List<Map<String, Object>> sessionList = dataBaseService.executeQuery("SELECT * FROM "
                    + JavaCenterHome.getTableName("session") + " WHERE ip='" + myIp + "' LIMIT 0,200");
            for (Map<String, Object> value : sessionList) {
                if (!noUids.contains(value.get("uid").toString())) {
                    Common.realname_set(sGlobal, sConfig, sNames, (Integer) value.get("uid"),
                            (String) value.get("username"), "", 0);
                    nearList.add(value);
                    i++;
                    if (i >= maxNum) {
                        break;
                    }
                }
            }
            request.setAttribute("nearList", nearList);
            i = 0;
            if (!Common.empty(space.get("feedfriend"))) {
                Map friendList = new HashMap(maxNum);
                List<Map<String, Object>> friends = dataBaseService
                        .executeQuery("SELECT fuid AS uid, fusername AS username FROM "
                                + JavaCenterHome.getTableName("friend") + " WHERE uid IN ("
                                + space.get("feedfriend") + ") LIMIT 0,200");
                for (Map<String, Object> value : friends) {
                    if (!noUids.contains(value.get("uid").toString()) && !Common.empty(value.get("username"))) {
                        Common.realname_set(sGlobal, sConfig, sNames, (Integer) value.get("uid"),
                                (String) value.get("username"), "", 0);
                        friendList.put(value.get("uid"), value);
                        i++;
                        if (i >= maxNum) {
                            break;
                        }
                    }
                }
                request.setAttribute("friendList", friendList);
            }
            i = 0;
            List<Map<String, Object>> onLineList = new ArrayList<Map<String, Object>>(maxNum);
            List<Map<String, Object>> onLines = dataBaseService
                    .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("session") + " LIMIT 0,200");
            for (Map<String, Object> value : onLines) {
                if (!noUids.contains(value.get("uid").toString())) {
                    Common.realname_set(sGlobal, sConfig, sNames, (Integer) value.get("uid"),
                            (String) value.get("username"), null, 0);
                    onLineList.add(value);
                    i++;
                    if (i >= maxNum) {
                        break;
                    }
                }
            }
            request.setAttribute("onLineList", onLineList);
            Common.realname_get(sGlobal, sConfig, sNames, space);
        } else if ("changegroup".equals(op)) {
            if (submitCheck(request, "changegroupsubmit")) {
                dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("friend") + " SET gid='"
                        + Common.intval(request.getParameter("group")) + "' WHERE uid='"
                        + sGlobal.get("supe_uid") + "' AND fuid='" + uid + "'");
                cpService.friendCache(request, sGlobal, sConfig, (Integer) sGlobal.get("supe_uid"));
                return showMessage(request, response, "do_success", (String) sGlobal.get("refer"));
            }
            List<Map<String, Object>> friends = dataBaseService
                    .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("friend") + " WHERE uid='"
                            + sGlobal.get("supe_uid") + "' AND fuid='" + uid + "'");
            if (friends.isEmpty()) {
                return showMessage(request, response, "specified_user_is_not_your_friend");
            }
            Map<String, Object> friend = friends.get(0);
            Map groupSelect = new HashMap();
            groupSelect.put(friend.get("gid"), " checked");
            Map<Integer, String> groups = Common.getFriendGroup(request);
            request.setAttribute("groups", groups);
            request.setAttribute("groupSelect", groupSelect);
        } else if ("changenum".equals(op)) {
            if (submitCheck(request, "changenumsubmit")) {
                dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("friend") + " SET num='"
                        + Common.intval(request.getParameter("num")) + "' WHERE uid='" + sGlobal.get("supe_uid")
                        + "' AND fuid='" + uid + "'");
                cpService.friendCache(request, sGlobal, sConfig, (Integer) sGlobal.get("supe_uid"));
                return showMessage(request, response, "do_success", (String) sGlobal.get("refer"), 0);
            }
            List<Map<String, Object>> friends = dataBaseService
                    .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("friend") + " WHERE uid='"
                            + sGlobal.get("supe_uid") + "' AND fuid='" + uid + "'");
            if (friends.isEmpty()) {
                return showMessage(request, response, "specified_user_is_not_your_friend");
            }
            request.setAttribute("friend", friends.get(0));
        } else if ("group".equals(op)) {
            if (submitCheck(request, "groupsubmin")) {
                String[] fUids = request.getParameterValues("fuids");
                if (Common.empty(fUids)) {
                    return showMessage(request, response, "please_correct_choice_groups_friend");
                }
                int groupId = Common.intval(request.getParameter("group"));
                dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("friend") + " SET gid='"
                        + groupId + "' WHERE uid='" + sGlobal.get("supe_uid") + "' AND fuid IN ("
                        + Common.sImplode(fUids) + ") AND status='1'");
                cpService.friendCache(request, sGlobal, sConfig, (Integer) sGlobal.get("supe_uid"));
                return showMessage(request, response, "do_success", (String) sGlobal.get("refer"));
            }
            int perPage = 50;
            int page = Common.intval(request.getParameter("page"));
            if (page < 1) {
                page = 1;
            }
            int start = (page - 1) * perPage;
            if (!Common.empty(space.get("friendnum"))) {
                Map<Integer, String> groups = Common.getFriendGroup(request);
                String theURL = "cp.jsp?ac=friend&op=group";
                int group = request.getParameter("group") == null ? -1
                        : Common.intval(request.getParameter("group"));
                String whereSQL = "";
                if (group > -1) {
                    whereSQL = "AND main.gid='" + group + "'";
                    theURL += "&group=" + group;
                }
                int count = dataBaseService.findRows("SELECT COUNT(*) FROM "
                        + JavaCenterHome.getTableName("friend") + " main WHERE main.uid='" + space.get("uid")
                        + "' AND main.status='1' " + whereSQL);
                List<Map<String, Object>> list = dataBaseService.executeQuery(
                        "SELECT main.fuid AS uid,main.fusername AS username, main.gid, main.num FROM "
                                + JavaCenterHome.getTableName("friend") + " main WHERE main.uid='"
                                + space.get("uid") + "' AND main.status='1' " + whereSQL
                                + " ORDER BY main.dateline DESC LIMIT " + start + "," + perPage);
                for (Map<String, Object> value : list) {
                    Common.realname_set(sGlobal, sConfig, sNames, (Integer) value.get("uid"),
                            (String) value.get("username"), "", 0);
                    value.put("group", groups.get(value.get("gid")));
                }
                request.setAttribute("list", list);
                request.setAttribute("multi", Common.multi(request, count, perPage, page,
                        (Integer) sConfig.get("maxpage"), theURL, null, null));
            }
            Map<Integer, String> groups = Common.getFriendGroup(request);
            request.setAttribute("groups", groups);
            actives.put("group", " class=\"active\"");
            Common.realname_get(sGlobal, sConfig, sNames, space);
        } else if ("request".equals(op)) {
            if (submitCheck(request, "requestsubmin")) {
                return showMessage(request, response, "do_success", (String) sGlobal.get("refer"));
            }
            int maxFriendnum = (Integer) Common.checkPerm(request, response, sGlobal, "maxfriendnum");
            if (maxFriendnum > 0) {
                maxFriendnum = maxFriendnum + (Integer) space.get("addfriend");
            }
            int perPage = 20;
            int page = Common.intval(request.getParameter("page"));
            if (page < 1) {
                page = 1;
            }
            int start = (page - 1) * perPage;
            String[] friend1 = (String[]) space.get("friends");
            Map whereArr = new HashMap();
            whereArr.put("fuid", space.get("uid"));
            whereArr.put("status", 0);
            int count = Common.intval(Common.getCount("friend", whereArr, null));
            if (count > 0) {
                List<Map<String, Object>> list = dataBaseService
                        .executeQuery("SELECT f.dateline,f.note,f.fuid, s.*, sf.friend FROM "
                                + JavaCenterHome.getTableName("friend") + " f LEFT JOIN "
                                + JavaCenterHome.getTableName("space") + " s ON s.uid=f.uid LEFT JOIN "
                                + JavaCenterHome.getTableName("spacefield")
                                + " sf ON sf.uid=f.uid WHERE f.fuid='" + space.get("uid")
                                + "' AND f.status='0' ORDER BY f.dateline DESC LIMIT " + start + "," + perPage);
                for (Map<String, Object> value : list) {
                    Common.realname_set(sGlobal, sConfig, sNames, (Integer) value.get("uid"),
                            (String) value.get("username"), "", 0);
                    String[] cFriend = {};
                    String[] friend2 = Common.empty(value.get("friend")) ? null
                            : value.get("friend").toString().split(",");
                    if (friend1 != null && friend2 != null) {
                        cFriend = getArrayIntersect(friend1, friend2);
                    }
                    value.put("cfriend", Common.implode(cFriend, ","));
                    value.put("cfcount", cFriend.length);
                }
                request.setAttribute("list", list);
            }
            if (count != (Integer) space.get("addfriendnum")) {
                dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("space")
                        + " SET addfriendnum='" + count + "' WHERE uid='" + space.get("uid") + "'");
            }
            request.setAttribute("multi", Common.multi(request, count, perPage, page,
                    (Integer) sConfig.get("maxpage"), "cp.jsp?ac=friend&op=request", null, null));
            Common.realname_get(sGlobal, sConfig, sNames, space);
            request.setAttribute("maxfriendnum", maxFriendnum);
        } else if ("groupname".equals(op)) {
            Map<Integer, String> groups = Common.getFriendGroup(request);
            int group = Common.intval(request.getParameter("group"));
            if (groups.get(group) == null) {
                return showMessage(request, response, "change_friend_groupname_error");
            }
            if (submitCheck(request, "groupnamesubmit")) {
                Map<String, Object> privacy = (Map<String, Object>) space.get("privacy");
                Map<Integer, String> groupList = null;
                if (privacy != null) {
                    groupList = (Map<Integer, String>) privacy.get("groupname");
                }
                groupList = groupList == null ? new HashMap<Integer, String>() : groupList;
                String groupName = Common.getStr(request.getParameter("groupname"), 20, true, true, false, 0, 0,
                        request, response);
                groupList.put(group, groupName);
                if (privacy != null) {
                    privacy.put("groupname", groupList);
                    space.put("privacy", privacy);
                }
                cpService.privacyUpdate(privacy, (Integer) sGlobal.get("supe_uid"));
                return showMessage(request, response, "do_success", request.getParameter("refer"));
            }
            request.setAttribute("group", group);
            request.setAttribute("groups", groups);
        } else if ("groupignore".equals(op)) {
            Map<Integer, String> groups = Common.getFriendGroup(request);
            int group = Common.intval(request.getParameter("group"));
            if (groups.get(group) == null) {
                return showMessage(request, response, "change_friend_groupname_error");
            }
            if (submitCheck(request, "groupignoresubmit")) {
                Map<String, Object> privacy = (Map<String, Object>) space.get("privacy");
                Map<Integer, Integer> filterGid = null;
                if (privacy != null) {
                    filterGid = (Map<Integer, Integer>) privacy.get("filter_gid");
                }
                filterGid = filterGid == null ? new HashMap<Integer, Integer>() : filterGid;
                if (filterGid.get(group) != null) {
                    filterGid.remove(group);
                } else {
                    filterGid.put(group, group);
                }
                if (privacy != null) {
                    privacy.put("filter_gid", filterGid);
                    space.put("privacy", privacy);
                }
                cpService.privacyUpdate(privacy, (Integer) sGlobal.get("supe_uid"));
                cpService.friendCache(request, sGlobal, sConfig, (Integer) sGlobal.get("supe_uid"));
                return showMessage(request, response, "do_success", request.getParameter("refer"), 0);
            }
            request.setAttribute("group", group);
        } else if ("blacklist".equals(op)) {
            if ("delete".equals(request.getParameter("subop"))) {
                dataBaseService.executeUpdate("DELETE FROM " + JavaCenterHome.getTableName("blacklist")
                        + " WHERE uid='" + space.get("uid") + "' AND buid='" + uid + "'");
                return showMessage(request, response, "do_success",
                        "space.jsp?do=friend&view=blacklist&start=" + request.getParameter("start"), 0);
            }
            if (submitCheck(request, "blacklistsubmit")) {
                String userName = Common.trim(request.getParameter("username"));
                List<Map<String, Object>> spaceList = dataBaseService.executeQuery("SELECT * FROM "
                        + JavaCenterHome.getTableName("space") + " WHERE username='" + userName + "'");
                if (spaceList.isEmpty()) {
                    return showMessage(request, response, "space_does_not_exist");
                }
                Map<String, Object> toSpace = spaceList.get(0);
                if (toSpace.get("uid").equals(space.get("uid"))) {
                    return showMessage(request, response, "unable_to_manage_self");
                }
                if (Common.in_array((String[]) space.get("friends"), toSpace.get("uid"))) {
                    cpService.updateFriend(request, sGlobal, sConfig, (Integer) sGlobal.get("supe_uid"),
                            (String) sGlobal.get("supe_username"), (Integer) toSpace.get("uid"), "", "ignore",
                            0);
                }
                Map insertData = new HashMap();
                insertData.put("uid", space.get("uid"));
                insertData.put("buid", toSpace.get("uid"));
                insertData.put("dateline", sGlobal.get("timestamp"));
                dataBaseService.insertTable("blacklist", insertData, false, true);
                return showMessage(request, response, "do_success",
                        "space.jsp?do=friend&view=blacklist&start=" + request.getParameter("start"), 0);
            }
        } else if ("rand".equals(op)) {
            Object[] randUids = null;
            if ((Integer) space.get("friendnum") < 5) {
                List<Map<String, Object>> sessionList = dataBaseService.executeQuery(
                        "SELECT uid FROM " + JavaCenterHome.getTableName("session") + " LIMIT 0,100");
                List onlineList = new ArrayList(sessionList.size());
                for (Map<String, Object> value : sessionList) {
                    if (!value.get("uid").equals(space.get("uid"))) {
                        onlineList.add(value.get("uid"));
                    }
                }
                randUids = (Object[]) Common
                        .sarrayRand(arrayMerge(onlineList.toArray(), (String[]) space.get("friends")), 1);
            } else {
                randUids = (Object[]) Common.sarrayRand(space.get("friends"), 1);
            }
            return showMessage(request, response, "do_success",
                    "space.jsp?uid=" + (randUids == null ? "" : randUids[randUids.length - 1]), 0);
        } else if ("getcfriend".equals(op)) {
            String[] fuids = Common.empty(request.getParameter("fuid")) ? null
                    : request.getParameter("fuid").split(",");
            Map<Integer, Integer> newfUids = new HashMap<Integer, Integer>(fuids == null ? 0 : fuids.length);
            if (fuids != null) {
                for (String value : fuids) {
                    int fuid = Common.intval(value);
                    if (fuid != 0) {
                        newfUids.put(fuid, fuid);
                    }
                }
            }
            if (!newfUids.isEmpty()) {
                List<Map<String, Object>> list = dataBaseService.executeQuery(
                        "SELECT uid,username,name,namestatus FROM " + JavaCenterHome.getTableName("space")
                                + " WHERE uid IN (" + Common.sImplode(newfUids) + ") LIMIT 0,15");
                for (Map<String, Object> value : list) {
                    Common.realname_set(sGlobal, sConfig, sNames, (Integer) value.get("uid"),
                            (String) value.get("username"), (String) value.get("name"),
                            (Integer) value.get("namestatus"));
                }
                request.setAttribute("list", list);
                Common.realname_get(sGlobal, sConfig, sNames, space);
            }
        } else if ("search".equals(op)) {
            Map<Integer, Map<String, Object>> fields = Common.getCacheDate(request, response,
                    "/data/cache/cache_profilefield.jsp", "globalProfilefield");
            if (!Common.empty(request.getParameter("searchsubmit"))
                    || !Common.empty(request.getParameter("searchmode"))) {
                Map<String, String[]> paramMap = request.getParameterMap();
                paramMap.put("searchsubmit", new String[] { 1 + "" });
                paramMap.put("searchmode", new String[] { 1 + "" });
                List<String> whereArr = new ArrayList<String>();
                Map<String, String> fromArr = new HashMap<String, String>();
                String fSQL = "";
                fromArr.put("space", JavaCenterHome.getTableName("space") + " s");
                String searchKey = request.getParameter("searchkey");
                if (!Common.empty(Common.stripSearchKey(searchKey))) {
                    whereArr.add("(s.name='" + searchKey + "' OR s.username='" + searchKey + "')");
                } else {
                    for (String value : new String[] { "uid", "username", "name", "videostatus", "avatar" }) {
                        if (!Common.empty(request.getParameter(value))) {
                            whereArr.add("s." + value + "='" + request.getParameter(value) + "'");
                        }
                    }
                }
                String spaceField = null;
                for (String value : new String[] { "sex", "qq", "msn", "birthyear", "birthmonth", "birthday",
                        "blood", "marry", "birthprovince", "birthcity", "resideprovince", "residecity" }) {
                    if (!Common.empty(request.getParameter(value))) {
                        fromArr.put("spacefield", JavaCenterHome.getTableName("spacefield") + " sf");
                        spaceField = "sf.uid=s.uid";
                        whereArr.add("sf." + value + "='" + request.getParameter(value) + "'");
                        fSQL += ", sf." + value;
                    }
                }
                int startAge, endAge;
                endAge = startAge = 0;
                if (!Common.empty(request.getParameter("endage"))) {
                    startAge = Integer.valueOf(Common.sgmdate(request, "yyyy", 0))
                            - Common.intval(request.getParameter("endage"));
                }
                if (!Common.empty(request.getParameter("startage"))) {
                    endAge = Integer.valueOf(Common.sgmdate(request, "yyyy", 0))
                            - Common.intval(request.getParameter("startage"));
                }
                if (startAge != 0 || endAge != 0) {
                    fromArr.put("spacefield", JavaCenterHome.getTableName("spacefield") + " sf");
                    spaceField = "sf.uid=s.uid";
                }
                if (startAge != 0 && endAge != 0 && endAge > startAge) {
                    whereArr.add("(sf.birthyear>=" + startAge + " AND sf.birthyear<=" + endAge + ")");
                } else if (startAge != 0 && endAge == 0) {
                    whereArr.add("sf.birthyear>=" + startAge);
                } else if (startAge == 0 && endAge != 0) {
                    whereArr.add("sf.birthyear<=" + endAge);
                }
                boolean haveField = false;
                for (Entry<Integer, Map<String, Object>> e : fields.entrySet()) {
                    if (!Common.empty(e.getValue().get("allowsearch"))) {
                        String field = Common.stripSearchKey(request.getParameter("field_" + e.getKey()));
                        if (!Common.empty(field)) {
                            haveField = true;
                            whereArr.add("sf.field_" + e.getKey() + " LIKE '%" + field + "%'");
                        }
                    }
                }
                if (haveField) {
                    fromArr.put("spacefield", JavaCenterHome.getTableName("spacefield") + " sf");
                    spaceField = "sf.uid=s.uid";
                }
                String type = request.getParameter("type");
                String spaceInfo = null;
                if ("edu".equals(type) || "work".equals(type)) {
                    for (String value : new String[] { "type", "title", "subtitle", "startyear" }) {
                        if (!Common.empty(request.getParameter(value))) {
                            fromArr.put("spaceinfo", JavaCenterHome.getTableName("spaceinfo") + " si");
                            spaceInfo = "si.uid=s.uid";
                            whereArr.add("si." + value + "='" + request.getParameter(value) + "'");
                        }
                    }
                }
                if (!whereArr.isEmpty()) {
                    List<Map<String, Object>> searchList = dataBaseService
                            .executeQuery("SELECT s.* " + fSQL + " FROM " + Common.implode(fromArr, ",")
                                    + " WHERE " + Common.implode(whereArr, " AND ")
                                    + (spaceField == null ? "" : " AND " + spaceField)
                                    + (spaceInfo == null ? "" : " AND " + spaceInfo) + " LIMIT 0,500");
                    Set<Map<String, Object>> list = new LinkedHashSet<Map<String, Object>>(searchList.size());
                    for (Map<String, Object> value : searchList) {
                        Common.realname_set(sGlobal, sConfig, sNames, (Integer) value.get("uid"),
                                (String) value.get("username"), (String) value.get("name"),
                                (Integer) value.get("namestatus"));
                        value.put("isfriend",
                                (value.get("uid").equals(space.get("uid"))
                                        || (Common.in_array((String[]) space.get("friends"), value.get("uid"))))
                                                ? true
                                                : false);
                        value.put("gColor", Common.getColor(request, response, (Integer) value.get("groupid")));
                        value.put("gIcon", Common.getIcon(request, response, (Integer) value.get("groupid")));
                        list.add(value);
                    }
                    request.setAttribute("list", list);
                }
                Common.realname_get(sGlobal, sConfig, sNames, space);
            } else {
                StringBuffer yearHTML = new StringBuffer();
                int nowy = Integer.valueOf(Common.sgmdate(request, "yyyy", 0));
                for (int i = 0; i < 50; i++) {
                    int they = nowy - i;
                    yearHTML.append("<option value=\"" + they + "\">" + they + "</option>");
                }
                request.setAttribute("yearhtml", yearHTML);
                Map sexArr = new HashMap();
                sexArr.put(space.get("sex").toString(), " checked");
                request.setAttribute("sexarr", sexArr);
                String all = request.getParameter("all");
                StringBuffer birthYearHTML = new StringBuffer();
                for (int i = 0; i < 100; i++) {
                    int they = nowy - i;
                    String selectStr = "";
                    if (Common.empty(all)) {
                        selectStr = they == (Integer) space.get("birthyear") ? " selected" : "";
                    }
                    birthYearHTML
                            .append("<option value=\"" + they + "\"" + selectStr + ">" + they + "</option>");
                }
                request.setAttribute("birthyearhtml", birthYearHTML.toString());
                String birthMonthHTML = "";
                for (int i = 1; i < 13; i++) {
                    String selectStr = "";
                    if (Common.empty(all)) {
                        selectStr = i == (Integer) space.get("birthmonth") ? " selected" : "";
                    }
                    birthMonthHTML += "<option value=\"" + i + "\"" + selectStr + ">" + i + "</option>";
                }
                request.setAttribute("birthmonthhtml", birthMonthHTML.toString());
                StringBuffer birthdayHTML = new StringBuffer();
                for (int i = 1; i < 29; i++) {
                    String selectStr = "";
                    if (Common.empty(all)) {
                        selectStr = i == (Integer) space.get("birthday") ? " selected" : "";
                    }
                    birthdayHTML.append("<option value=\"" + i + "\"" + selectStr + ">" + i + "</option>");
                }
                request.setAttribute("birthdayhtml", birthdayHTML.toString());
                String bloodHTML = "";
                for (String value : new String[] { "A", "B", "O", "AB" }) {
                    String selectStr = "";
                    if (Common.empty(all)) {
                        selectStr = value.equals(space.get("blood")) ? " selected" : "";
                    }
                    bloodHTML += "<option value=\"" + value + "\"" + selectStr + ">" + value + "</option>";
                }
                request.setAttribute("bloodhtml", bloodHTML.toString());
                Map marryArr = new HashMap();
                marryArr.put(space.get("marry").toString(), " selected");
                request.setAttribute("marryarr", marryArr);
                List<Integer> removeKeys = new ArrayList<Integer>(fields.size());
                for (Entry<Integer, Map<String, Object>> e : fields.entrySet()) {
                    Map<String, Object> fValue = e.getValue();
                    if (!Common.empty(fValue.get("allowsearch"))) {
                        if ("text".equals(fValue.get("formtype"))) {
                            fValue.put("html", "<input type=\"text\" name=\"field_" + e.getKey()
                                    + "\" value=\"\" class=\"t_input\">");
                        } else {
                            StringBuffer HTML = new StringBuffer();
                            HTML.append("<select name=\"field_" + e.getKey()
                                    + "\"><option value=\"\">---</option>");
                            String[] optionArr = fValue.get("choice").toString().split("\n");
                            for (String ov : optionArr) {
                                ov = ov.trim();
                                if (!"".equals(ov)) {
                                    HTML.append("<option value=\"" + ov + "\">" + ov + "</option>");
                                }
                            }
                            HTML.append("</select>");
                            fValue.put("html", HTML.toString());
                        }
                    } else {
                        removeKeys.add(e.getKey());
                    }
                }
                for (Integer removeKey : removeKeys) {
                    fields.remove(removeKey);
                }
                request.setAttribute("fields", fields);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        return showMessage(request, response, e.getMessage());
    }
    request.setAttribute("op", op);
    request.setAttribute("uid", uid);
    return include(request, response, sConfig, sGlobal, "cp_friend.jsp");
}