Example usage for java.util Calendar getActualMaximum

List of usage examples for java.util Calendar getActualMaximum

Introduction

In this page you can find the example usage for java.util Calendar getActualMaximum.

Prototype

public int getActualMaximum(int field) 

Source Link

Document

Returns the maximum value that the specified calendar field could have, given the time value of this Calendar.

Usage

From source file:org.alfresco.solr.query.Solr4QueryParser.java

/**
  * @param dateAndResolution//www .  ja  va  2s  .  com
  * @return
 */
private String getDateEnd(Pair<Date, Integer> dateAndResolution) {
    Calendar cal = Calendar.getInstance(I18NUtil.getLocale());
    cal.setTime(dateAndResolution.getFirst());
    switch (dateAndResolution.getSecond()) {
    case Calendar.YEAR:
        cal.set(Calendar.MONTH, cal.getActualMaximum(Calendar.MONTH));
    case Calendar.MONTH:
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
    case Calendar.DAY_OF_MONTH:
        cal.set(Calendar.HOUR_OF_DAY, cal.getActualMaximum(Calendar.HOUR_OF_DAY));
    case Calendar.HOUR_OF_DAY:
        cal.set(Calendar.MINUTE, cal.getActualMaximum(Calendar.MINUTE));
    case Calendar.MINUTE:
        cal.set(Calendar.SECOND, cal.getActualMaximum(Calendar.SECOND));
    case Calendar.SECOND:
        cal.set(Calendar.MILLISECOND, cal.getActualMaximum(Calendar.MILLISECOND));
    case Calendar.MILLISECOND:
    default:
    }
    SimpleDateFormat formatter = CachingDateFormat.getSolrDatetimeFormat();
    formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
    return formatter.format(cal.getTime());
}

From source file:com.aimluck.eip.schedule.util.ScheduleUtils.java

public static boolean matchDay(Calendar cal, String repeat_ptn) { // ??????????
    if (repeat_ptn == null || "".equals(repeat_ptn)) {
        return false;
    }/*from  www .  j a v a  2  s  . co m*/
    if (repeat_ptn.startsWith("M")) {
        int month_day;
        // ?
        if (repeat_ptn.substring(1, 3).equals("XX")) {
            month_day = cal.getActualMaximum(Calendar.DATE);
        } else {
            month_day = Integer.parseInt(repeat_ptn.substring(1, 3));
        }
        int ptn_day = cal.get(Calendar.DAY_OF_MONTH);
        return (month_day == ptn_day);
    }
    if (repeat_ptn.startsWith("Y")) {
        int year_month = Integer.parseInt(repeat_ptn.substring(1, 3));
        int year_day = Integer.parseInt(repeat_ptn.substring(3, 5));
        int ptn_month = cal.get(Calendar.MONTH);
        int ptn_day = cal.get(Calendar.DAY_OF_MONTH);
        return (year_day == ptn_day && (year_month - 1) == ptn_month);
    } else if (repeat_ptn.startsWith("W")) {
        int dow = cal.get(Calendar.DAY_OF_WEEK);
        int dowim = cal.get(Calendar.DAY_OF_WEEK_IN_MONTH);
        if (repeat_ptn.length() == 9 || dowim == Character.getNumericValue(repeat_ptn.charAt(8))) {
            if (dow == Calendar.SUNDAY) {
                return repeat_ptn.matches("W1........?");
            }
            if (dow == Calendar.MONDAY) {
                return repeat_ptn.matches("W.1.......?");
            }
            if (dow == Calendar.TUESDAY) {
                return repeat_ptn.matches("W..1......?");
            }
            if (dow == Calendar.WEDNESDAY) {
                return repeat_ptn.matches("W...1.....?");
            }
            if (dow == Calendar.THURSDAY) {
                return repeat_ptn.matches("W....1....?");
            }
            if (dow == Calendar.FRIDAY) {
                return repeat_ptn.matches("W.....1...?");
            }
            if (dow == Calendar.SATURDAY) {
                return repeat_ptn.matches("W......1..?");
            }
        }
        return false;
    } else {
        return true;
    }
}

From source file:com.smict.person.data.DoctorData.java

public int addDoctorTime(DoctTimeModel timeModel) {
    int rt = 0;/*ww w. j  a v  a2 s  . com*/
    try {
        conn = agent.getConnectMYSql();
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat DateFormat = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat DateS = new SimpleDateFormat("dd");
        Date ConvertDate;
        int dayOfWeek;
        String lastDayOfMonth, loopMonth;
        String AddWorkDaySQL = "INSERT INTO doctor_workday (doctor_id,start_datetime,end_datetime,work_hour,branch_id)"
                + "VALUES ";
        String selectSQL = "INSERT INTO doctor_workday_month "
                + "(doctor_id,branch_id,work_month,time_in_mon,time_out_mon"
                + ",time_in_tue,time_out_tue,time_in_wed,time_out_wed,time_in_thu,time_out_thu"
                + ",time_in_fri,time_out_fri,time_in_sat,time_out_sat,time_in_sun,time_out_sun)" + "VALUES ";
        int chkFirst = 0;
        for (int i = 0; i < timeModel.getWork_month().size(); i++) {
            if (!timeModel.getWork_month().get(i).equals("")) {
                String work_month = timeModel.getWork_month().get(i);
                String[] part = work_month.split("/");
                loopMonth = String.valueOf(Integer.parseInt(part[1]) - 543) + "-" + part[0];
                work_month = String.valueOf(Integer.parseInt(part[1]) - 543) + "-" + part[0] + "-01";
                selectSQL += (i > 0) ? "," : "";
                selectSQL += "(" + timeModel.getDoctorID() + ",'" + timeModel.getBranch_id() + "'" + ",'"
                        + work_month + "'" + ",'" + timeModel.getTime_in_mon().get(i) + ":00'" + ",'"
                        + timeModel.getTime_out_mon().get(i) + ":00'" + ",'" + timeModel.getTime_in_tue().get(i)
                        + ":00'" + ",'" + timeModel.getTime_out_tue().get(i) + ":00'" + ",'"
                        + timeModel.getTime_in_wed().get(i) + ":00'" + ",'" + timeModel.getTime_out_wed().get(i)
                        + ":00'" + ",'" + timeModel.getTime_in_thu().get(i) + ":00'" + ",'"
                        + timeModel.getTime_out_thu().get(i) + ":00'" + ",'" + timeModel.getTime_in_fri().get(i)
                        + ":00'" + ",'" + timeModel.getTime_out_fri().get(i) + ":00'" + ",'"
                        + timeModel.getTime_in_sat().get(i) + ":00'" + ",'" + timeModel.getTime_out_sat().get(i)
                        + ":00'" + ",'" + timeModel.getTime_in_sun().get(i) + ":00'" + ",'"
                        + timeModel.getTime_out_sun().get(i) + ":00'" + ")";

                ConvertDate = DateFormat.parse(work_month);
                calendar.setTime(ConvertDate);
                calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
                lastDayOfMonth = DateS.format(calendar.getTime());

                for (int d = 1; d <= Integer.parseInt(lastDayOfMonth); d++) {
                    ConvertDate = DateFormat.parse(loopMonth + "-" + d);
                    calendar.setTime(ConvertDate);
                    dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);

                    if (!timeModel.getTime_in_sun().get(i).equals("00:00") && dayOfWeek == 1) {
                        AddWorkDaySQL += (chkFirst > 0) ? "," : "";

                        AddWorkDaySQL += "(" + timeModel.getDoctorID() + ",'" + loopMonth + "-" + d + " "
                                + timeModel.getTime_in_sun().get(i) + ":00'," + "'" + loopMonth + "-" + d + " "
                                + timeModel.getTime_out_sun().get(i) + ":00'," + "HOUR(TIMEDIFF('" + loopMonth
                                + "-" + d + " " + timeModel.getTime_out_sun().get(i) + ":00'," + "'" + loopMonth
                                + "-" + d + " " + timeModel.getTime_in_sun().get(i) + ":00'))," + "'"
                                + timeModel.getBranch_id() + "')";
                        chkFirst = 1;
                    }
                    if (!timeModel.getTime_in_mon().get(i).equals("00:00") && dayOfWeek == 2) {
                        AddWorkDaySQL += (chkFirst > 0) ? "," : "";
                        AddWorkDaySQL += "(" + timeModel.getDoctorID() + ",'" + loopMonth + "-" + d + " "
                                + timeModel.getTime_in_mon().get(i) + ":00'," + "'" + loopMonth + "-" + d + " "
                                + timeModel.getTime_out_mon().get(i) + ":00'," + "HOUR(TIMEDIFF('" + loopMonth
                                + "-" + d + " " + timeModel.getTime_out_mon().get(i) + ":00'," + "'" + loopMonth
                                + "-" + d + " " + timeModel.getTime_in_mon().get(i) + ":00'))," + "'"
                                + timeModel.getBranch_id() + "')";
                        chkFirst = 1;
                    }
                    if (!timeModel.getTime_in_tue().get(i).equals("00:00") && dayOfWeek == 3) {
                        AddWorkDaySQL += (chkFirst > 0) ? "," : "";
                        AddWorkDaySQL += "(" + timeModel.getDoctorID() + ",'" + loopMonth + "-" + d + " "
                                + timeModel.getTime_in_tue().get(i) + ":00'," + "'" + loopMonth + "-" + d + " "
                                + timeModel.getTime_out_tue().get(i) + ":00'," + "HOUR(TIMEDIFF('" + loopMonth
                                + "-" + d + " " + timeModel.getTime_out_tue().get(i) + ":00'," + "'" + loopMonth
                                + "-" + d + " " + timeModel.getTime_in_tue().get(i) + ":00'))," + "'"
                                + timeModel.getBranch_id() + "')";
                        chkFirst = 1;
                    }
                    if (!timeModel.getTime_in_wed().get(i).equals("00:00") && dayOfWeek == 4) {
                        AddWorkDaySQL += (chkFirst > 0) ? "," : "";
                        AddWorkDaySQL += "(" + timeModel.getDoctorID() + ",'" + loopMonth + "-" + d + " "
                                + timeModel.getTime_in_wed().get(i) + ":00'," + "'" + loopMonth + "-" + d + " "
                                + timeModel.getTime_out_wed().get(i) + ":00'," + "HOUR(TIMEDIFF('" + loopMonth
                                + "-" + d + " " + timeModel.getTime_out_wed().get(i) + ":00'," + "'" + loopMonth
                                + "-" + d + " " + timeModel.getTime_in_wed().get(i) + ":00'))," + "'"
                                + timeModel.getBranch_id() + "')";
                        chkFirst = 1;
                    }
                    if (!timeModel.getTime_in_thu().get(i).equals("00:00") && dayOfWeek == 5) {
                        AddWorkDaySQL += (chkFirst > 0) ? "," : "";
                        AddWorkDaySQL += "(" + timeModel.getDoctorID() + ",'" + loopMonth + "-" + d + " "
                                + timeModel.getTime_in_thu().get(i) + ":00'," + "'" + loopMonth + "-" + d + " "
                                + timeModel.getTime_out_thu().get(i) + ":00'," + "HOUR(TIMEDIFF('" + loopMonth
                                + "-" + d + " " + timeModel.getTime_out_thu().get(i) + ":00'," + "'" + loopMonth
                                + "-" + d + " " + timeModel.getTime_in_thu().get(i) + ":00'))," + "'"
                                + timeModel.getBranch_id() + "')";
                        chkFirst = 1;
                    }
                    if (!timeModel.getTime_in_fri().get(i).equals("00:00") && dayOfWeek == 6) {
                        AddWorkDaySQL += (chkFirst > 0) ? "," : "";
                        AddWorkDaySQL += "(" + timeModel.getDoctorID() + ",'" + loopMonth + "-" + d + " "
                                + timeModel.getTime_in_fri().get(i) + ":00'," + "'" + loopMonth + "-" + d + " "
                                + timeModel.getTime_out_fri().get(i) + ":00'," + "HOUR(TIMEDIFF('" + loopMonth
                                + "-" + d + " " + timeModel.getTime_out_fri().get(i) + ":00'," + "'" + loopMonth
                                + "-" + d + " " + timeModel.getTime_in_fri().get(i) + ":00'))," + "'"
                                + timeModel.getBranch_id() + "')";
                        chkFirst = 1;
                    }
                    if (!timeModel.getTime_in_sat().get(i).equals("00:00") && dayOfWeek == 7) {
                        AddWorkDaySQL += (chkFirst > 0) ? "," : "";
                        AddWorkDaySQL += "(" + timeModel.getDoctorID() + ",'" + loopMonth + "-" + d + " "
                                + timeModel.getTime_in_sat().get(i) + ":00'," + "'" + loopMonth + "-" + d + " "
                                + timeModel.getTime_out_sat().get(i) + ":00'," + "HOUR(TIMEDIFF('" + loopMonth
                                + "-" + d + " " + timeModel.getTime_out_sat().get(i) + ":00'," + "'" + loopMonth
                                + "-" + d + " " + timeModel.getTime_in_sat().get(i) + ":00'))," + "'"
                                + timeModel.getBranch_id() + "')";
                        chkFirst = 1;
                    }
                }

            }
        }
        //System.out.println(AddWorkDaySQL);

        Stmt = conn.createStatement();
        rt = Stmt.executeUpdate(AddWorkDaySQL);
        Stmt.close();

        pStmt = conn.prepareStatement(selectSQL);
        pStmt.executeUpdate();
        pStmt.close();
        conn.close();
        check_duplicate_Time();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return rt;
}

From source file:org.exoplatform.addon.pulse.service.ws.RestActivitiesStatistic.java

private ChartData buildPlfDownloadData(String maxColumn, String filter, Date fromDate) {
    int totalDataCoulumn = 5;
    try {/*from  w ww . ja  va  2 s. c  om*/
        totalDataCoulumn = Integer.parseInt(maxColumn);
    } catch (Exception e) {
        //do nothing
    }
    if (filter.equalsIgnoreCase(FILTER_BY_DAY)) {
        List<String> listTitle = new ArrayList<String>();
        List<Long> plfDownloadsData = new ArrayList<Long>();

        for (int i = 0; i < totalDataCoulumn; i++) {
            Calendar calendar = Calendar.getInstance();
            calendar.clear();
            calendar.setTime(fromDate);
            calendar.add(Calendar.DATE, i);
            Date toDate = calendar.getTime();
            String toDateStr = partString(toDate, "yyyy-MM-dd");

            listTitle.add(partString(toDate, "dd-MM-yyyy"));
            String url = "http://sourceforge.net/projects/exo/files/stats/json?start_date=" + toDateStr
                    + "&end_date=" + toDateStr;
            try {
                String returnValue = httpGet(url);
                plfDownloadsData.add(getTotalPlfDownloadDataFromJson(returnValue, toDate));
            } catch (Exception e) {
                LOG.error(e.getMessage());
                plfDownloadsData.add(0l);
            }

        }
        ChartData chartData = new ChartData();
        chartData.setListTitle(listTitle);
        chartData.setPlfDownloadsData(plfDownloadsData);
        return chartData;
    }

    if (filter.equalsIgnoreCase(FILTER_BY_WEEK)) {
        List<String> listTitle = new ArrayList<String>();
        List<Long> plfDownloadsData = new ArrayList<Long>();

        String fromDateStr = partString(fromDate, "yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.setTime(fromDate);
        int fromWeek = calendar.get(Calendar.WEEK_OF_YEAR);
        int fromMonth = calendar.get(Calendar.MONTH);
        if (fromMonth == Calendar.DECEMBER && fromWeek == 1)
            fromWeek = 53;
        int fromYear = calendar.get(Calendar.YEAR);
        calendar.clear();
        calendar.set(Calendar.WEEK_OF_YEAR, fromWeek);
        calendar.set(Calendar.YEAR, fromYear);
        Date beginWeekDate = calendar.getTime();
        calendar.clear();
        calendar.setTime(beginWeekDate);
        calendar.add(Calendar.DATE, 6);
        Date endWeekDate = calendar.getTime();
        calendar.clear();
        String toDateStr = partString(endWeekDate, "yyyy-MM-dd");
        for (int i = 0; i < totalDataCoulumn; i++) {
            calendar.setTime(endWeekDate);
            listTitle.add("W" + calendar.get(Calendar.WEEK_OF_YEAR) + "-" + calendar.get(Calendar.YEAR));
            String url = "http://sourceforge.net/projects/exo/files/stats/json?start_date=" + fromDateStr
                    + "&end_date=" + toDateStr;
            try {
                String returnValue = httpGet(url);
                plfDownloadsData.add(
                        getTotalPlfDownloadDataFromJson(returnValue, parseDate(fromDateStr, "yyyy-MM-dd")));
            } catch (Exception e) {
                LOG.error(e.getMessage());
                plfDownloadsData.add(0l);
            }

            calendar.clear();

            fromDate = endWeekDate;
            calendar.setTime(fromDate);
            calendar.add(Calendar.DATE, 1);
            fromDate = calendar.getTime();
            fromDateStr = partString(fromDate, "yyyy-MM-dd");

            calendar.add(Calendar.DATE, 6);
            endWeekDate = calendar.getTime();
            toDateStr = partString(endWeekDate, "yyyy-MM-dd");
            calendar.clear();
        }
        ChartData chartData = new ChartData();
        chartData.setListTitle(listTitle);
        chartData.setPlfDownloadsData(plfDownloadsData);
        return chartData;
    }

    if (filter.equalsIgnoreCase(FILTER_BY_MONTH)) {
        List<String> listTitle = new ArrayList<String>();
        List<Long> plfDownloadsData = new ArrayList<Long>();

        String fromDateStr = partString(fromDate, "yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.setTime(fromDate);

        int fromMonth = calendar.get(Calendar.MONTH);
        int fromYear = calendar.get(Calendar.YEAR);
        //calendar.add(Calendar.MONTH, totalDataCoulumn);
        //int toYear = calendar.get(Calendar.YEAR);
        calendar.clear();
        calendar.set(Calendar.MONTH, fromMonth);
        calendar.set(Calendar.YEAR, fromYear);
        Date beginMonthDate = calendar.getTime();
        calendar.clear();
        calendar.setTime(beginMonthDate);
        int dayOfMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        calendar.add(Calendar.DATE, dayOfMonth - 1);
        Date endMonthDate = calendar.getTime();
        calendar.clear();
        String toDateStr = partString(endMonthDate, "yyyy-MM-dd");
        for (int i = 0; i < totalDataCoulumn; i++) {
            calendar.setTime(endMonthDate);
            listTitle.add(partString(calendar.getTime(), "MMM") + "-" + calendar.get(Calendar.YEAR));
            String url = "http://sourceforge.net/projects/exo/files/stats/json?start_date=" + fromDateStr
                    + "&end_date=" + toDateStr;
            try {
                String returnValue = httpGet(url);
                plfDownloadsData.add(
                        getTotalPlfDownloadDataFromJson(returnValue, parseDate(fromDateStr, "yyyy-MM-dd")));
            } catch (Exception e) {
                plfDownloadsData.add(0l);
            }

            calendar.clear();

            fromDate = endMonthDate;
            calendar.setTime(fromDate);
            calendar.add(Calendar.DATE, 1);
            fromDate = calendar.getTime();
            fromDateStr = partString(fromDate, "yyyy-MM-dd");

            dayOfMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
            calendar.add(Calendar.DATE, dayOfMonth - 1);
            endMonthDate = calendar.getTime();
            toDateStr = partString(endMonthDate, "yyyy-MM-dd");
            calendar.clear();
        }
        ChartData chartData = new ChartData();
        chartData.setListTitle(listTitle);
        chartData.setPlfDownloadsData(plfDownloadsData);
        return chartData;
    }

    return null;
}

From source file:com.s3d.webapps.util.time.DateUtils.java

/**
 * <p>Internal calculation method.</p>
 * //  w w w.ja v a2  s .  com
 * @param val  the calendar
 * @param field  the field constant
 * @param modType  type to truncate, round or ceiling
 * @throws ArithmeticException if the year is over 280 million
 */
private static void modify(Calendar val, int field, int modType) {
    if (val.get(Calendar.YEAR) > 280000000) {
        throw new ArithmeticException("Calendar value too large for accurate calculations");
    }

    if (field == Calendar.MILLISECOND) {
        return;
    }

    // ----------------- Fix for LANG-59 ---------------------- START ---------------
    // see http://issues.apache.org/jira/browse/LANG-59
    //
    // Manually truncate milliseconds, seconds and minutes, rather than using
    // Calendar methods.

    Date date = val.getTime();
    long time = date.getTime();
    boolean done = false;

    // truncate milliseconds
    int millisecs = val.get(Calendar.MILLISECOND);
    if (MODIFY_TRUNCATE == modType || millisecs < 500) {
        time = time - millisecs;
    }
    if (field == Calendar.SECOND) {
        done = true;
    }

    // truncate seconds
    int seconds = val.get(Calendar.SECOND);
    if (!done && (MODIFY_TRUNCATE == modType || seconds < 30)) {
        time = time - (seconds * 1000L);
    }
    if (field == Calendar.MINUTE) {
        done = true;
    }

    // truncate minutes
    int minutes = val.get(Calendar.MINUTE);
    if (!done && (MODIFY_TRUNCATE == modType || minutes < 30)) {
        time = time - (minutes * 60000L);
    }

    // reset time
    if (date.getTime() != time) {
        date.setTime(time);
        val.setTime(date);
    }
    // ----------------- Fix for LANG-59 ----------------------- END ----------------

    boolean roundUp = false;
    for (int i = 0; i < fields.length; i++) {
        for (int j = 0; j < fields[i].length; j++) {
            if (fields[i][j] == field) {
                //This is our field... we stop looping
                if (modType == MODIFY_CEILING || (modType == MODIFY_ROUND && roundUp)) {
                    if (field == DateUtils.SEMI_MONTH) {
                        //This is a special case that's hard to generalize
                        //If the date is 1, we round up to 16, otherwise
                        //  we subtract 15 days and add 1 month
                        if (val.get(Calendar.DATE) == 1) {
                            val.add(Calendar.DATE, 15);
                        } else {
                            val.add(Calendar.DATE, -15);
                            val.add(Calendar.MONTH, 1);
                        }
                        // ----------------- Fix for LANG-440 ---------------------- START ---------------
                    } else if (field == Calendar.AM_PM) {
                        // This is a special case
                        // If the time is 0, we round up to 12, otherwise
                        //  we subtract 12 hours and add 1 day
                        if (val.get(Calendar.HOUR_OF_DAY) == 0) {
                            val.add(Calendar.HOUR_OF_DAY, 12);
                        } else {
                            val.add(Calendar.HOUR_OF_DAY, -12);
                            val.add(Calendar.DATE, 1);
                        }
                        // ----------------- Fix for LANG-440 ---------------------- END ---------------
                    } else {
                        //We need at add one to this field since the
                        //  last number causes us to round up
                        val.add(fields[i][0], 1);
                    }
                }
                return;
            }
        }
        //We have various fields that are not easy roundings
        int offset = 0;
        boolean offsetSet = false;
        //These are special types of fields that require different rounding rules
        switch (field) {
        case DateUtils.SEMI_MONTH:
            if (fields[i][0] == Calendar.DATE) {
                //If we're going to drop the DATE field's value,
                //  we want to do this our own way.
                //We need to subtrace 1 since the date has a minimum of 1
                offset = val.get(Calendar.DATE) - 1;
                //If we're above 15 days adjustment, that means we're in the
                //  bottom half of the month and should stay accordingly.
                if (offset >= 15) {
                    offset -= 15;
                }
                //Record whether we're in the top or bottom half of that range
                roundUp = offset > 7;
                offsetSet = true;
            }
            break;
        case Calendar.AM_PM:
            if (fields[i][0] == Calendar.HOUR_OF_DAY) {
                //If we're going to drop the HOUR field's value,
                //  we want to do this our own way.
                offset = val.get(Calendar.HOUR_OF_DAY);
                if (offset >= 12) {
                    offset -= 12;
                }
                roundUp = offset >= 6;
                offsetSet = true;
            }
            break;
        }
        if (!offsetSet) {
            int min = val.getActualMinimum(fields[i][0]);
            int max = val.getActualMaximum(fields[i][0]);
            //Calculate the offset from the minimum allowed value
            offset = val.get(fields[i][0]) - min;
            //Set roundUp if this is more than half way between the minimum and maximum
            roundUp = offset > ((max - min) / 2);
        }
        //We need to remove this field
        if (offset != 0) {
            val.set(fields[i][0], val.get(fields[i][0]) - offset);
        }
    }
    throw new IllegalArgumentException("The field " + field + " is not supported");

}

From source file:com.xunlei.util.DateUtils.java

/**
 * <p>//  w w  w. j  a  v a 2 s  . com
 * Internal calculation method.
 * </p>
 * 
 * @param val the calendar
 * @param field the field constant
 * @param modType type to truncate, round or ceiling
 * @throws ArithmeticException if the year is over 280 million
 */
static void modify(Calendar val, int field, int modType) {
    if (val.get(Calendar.YEAR) > 280000000) {
        throw new ArithmeticException("Calendar value too large for accurate calculations");
    }

    if (field == Calendar.MILLISECOND) {
        return;
    }

    // ----------------- Fix for LANG-59 ---------------------- START ---------------
    // see http://issues.apache.org/jira/browse/LANG-59
    //
    // Manually truncate milliseconds, seconds and minutes, rather than using
    // Calendar methods.

    Date date = val.getTime();
    long time = date.getTime();
    boolean done = false;

    // truncate milliseconds
    int millisecs = val.get(Calendar.MILLISECOND);
    if (MODIFY_TRUNCATE == modType || millisecs < 500) {
        time = time - millisecs;
    }
    if (field == Calendar.SECOND) {
        done = true;
    }

    // truncate seconds
    int seconds = val.get(Calendar.SECOND);
    if (!done && (MODIFY_TRUNCATE == modType || seconds < 30)) {
        time = time - (seconds * 1000L);
    }
    if (field == Calendar.MINUTE) {
        done = true;
    }

    // truncate minutes
    int minutes = val.get(Calendar.MINUTE);
    if (!done && (MODIFY_TRUNCATE == modType || minutes < 30)) {
        time = time - (minutes * 60000L);
    }

    // reset time
    if (date.getTime() != time) {
        date.setTime(time);
        val.setTime(date);
    }
    // ----------------- Fix for LANG-59 ----------------------- END ----------------

    boolean roundUp = false;
    for (int i = 0; i < fields.length; i++) {
        for (int j = 0; j < fields[i].length; j++) {
            if (fields[i][j] == field) {
                // This is our field... we stop looping
                if (modType == MODIFY_CEILING || (modType == MODIFY_ROUND && roundUp)) {
                    if (field == DateUtils.SEMI_MONTH) {
                        // This is a special case that's hard to generalize
                        // If the date is 1, we round up to 16, otherwise
                        // we subtract 15 days and add 1 month
                        if (val.get(Calendar.DATE) == 1) {
                            val.add(Calendar.DATE, 15);
                        } else {
                            val.add(Calendar.DATE, -15);
                            val.add(Calendar.MONTH, 1);
                        }
                        // ----------------- Fix for LANG-440 ---------------------- START ---------------
                    } else if (field == Calendar.AM_PM) {
                        // This is a special case
                        // If the time is 0, we round up to 12, otherwise
                        // we subtract 12 hours and add 1 day
                        if (val.get(Calendar.HOUR_OF_DAY) == 0) {
                            val.add(Calendar.HOUR_OF_DAY, 12);
                        } else {
                            val.add(Calendar.HOUR_OF_DAY, -12);
                            val.add(Calendar.DATE, 1);
                        }
                        // ----------------- Fix for LANG-440 ---------------------- END ---------------
                    } else {
                        // We need at add one to this field since the
                        // last number causes us to round up
                        val.add(fields[i][0], 1);
                    }
                }
                return;
            }
        }
        // We have various fields that are not easy roundings
        int offset = 0;
        boolean offsetSet = false;
        // These are special types of fields that require different rounding rules
        switch (field) {
        case DateUtils.SEMI_MONTH:
            if (fields[i][0] == Calendar.DATE) {
                // If we're going to drop the DATE field's value,
                // we want to do this our own way.
                // We need to subtrace 1 since the date has a minimum of 1
                offset = val.get(Calendar.DATE) - 1;
                // If we're above 15 days adjustment, that means we're in the
                // bottom half of the month and should stay accordingly.
                if (offset >= 15) {
                    offset -= 15;
                }
                // Record whether we're in the top or bottom half of that range
                roundUp = offset > 7;
                offsetSet = true;
            }
            break;
        case Calendar.AM_PM:
            if (fields[i][0] == Calendar.HOUR_OF_DAY) {
                // If we're going to drop the HOUR field's value,
                // we want to do this our own way.
                offset = val.get(Calendar.HOUR_OF_DAY);
                if (offset >= 12) {
                    offset -= 12;
                }
                roundUp = offset >= 6;
                offsetSet = true;
            }
            break;
        }
        if (!offsetSet) {
            int min = val.getActualMinimum(fields[i][0]);
            int max = val.getActualMaximum(fields[i][0]);
            // Calculate the offset from the minimum allowed value
            offset = val.get(fields[i][0]) - min;
            // Set roundUp if this is more than half way between the minimum and maximum
            roundUp = offset > ((max - min) / 2);
        }
        // We need to remove this field
        if (offset != 0) {
            val.set(fields[i][0], val.get(fields[i][0]) - offset);
        }
    }
    throw new IllegalArgumentException("The field " + field + " is not supported");

}

From source file:com.aimluck.eip.schedule.util.ScheduleUtils.java

/**
 * ?????????????//from  ww w . ja  va  2s  . c  o m
 *
 * @param date
 * @param ptn
 * @param startDate
 * @param limitDate
 * @return
 */
public static boolean isView(ALDateTimeField date, String ptn, Date startDate, Date limitDate) {
    int count = 0;
    boolean result = false;
    Calendar cal = Calendar.getInstance();
    cal.setTime(date.getValue());
    // 
    if (ptn.charAt(0) == 'D') {
        result = true;
        count = 1;
        // , 
    } else if (ptn.charAt(0) == 'W') {

        int dow = cal.get(Calendar.DAY_OF_WEEK);
        // ??
        int dowim = cal.get(Calendar.DAY_OF_WEEK_IN_MONTH);
        if (ptn.charAt(8) == 'N' || ptn.charAt(8) == 'L' || dowim == Character.getNumericValue(ptn.charAt(8))) {
            switch (dow) {
            // 
            case Calendar.SUNDAY:
                result = ptn.charAt(1) != '0';
                break;
            // 
            case Calendar.MONDAY:
                result = ptn.charAt(2) != '0';
                break;
            // ?
            case Calendar.TUESDAY:
                result = ptn.charAt(3) != '0';
                break;
            // 
            case Calendar.WEDNESDAY:
                result = ptn.charAt(4) != '0';
                break;
            // 
            case Calendar.THURSDAY:
                result = ptn.charAt(5) != '0';
                break;
            // 
            case Calendar.FRIDAY:
                result = ptn.charAt(6) != '0';
                break;
            // 
            case Calendar.SATURDAY:
                result = ptn.charAt(7) != '0';
                break;
            default:
                result = false;
                break;
            }
            if (ptn.length() == 9) {
                count = 8;
            } else {
                count = 9;
            }
        }
        // 
    } else if (ptn.charAt(0) == 'M') {
        int mday;
        if (ptn.substring(1, 3).equals("XX")) {
            mday = cal.getActualMaximum(Calendar.DATE);
        } else {
            mday = Integer.parseInt(ptn.substring(1, 3));
        }
        result = Integer.parseInt(date.getDay()) == mday;
        count = 3;
    } else if (ptn.charAt(0) == 'Y') {
        int ymonth = Integer.parseInt(ptn.substring(1, 3));
        int yday = Integer.parseInt(ptn.substring(3, 5));
        int month = Integer.parseInt(date.getMonth());
        int day = Integer.parseInt(date.getDay());
        if (ymonth == month && yday == day) {
            result = true;
            count = 5;
        } else {
            result = false;
        }
    } else {
        return true;
    }

    if (result) {
        if (ptn.charAt(count) == 'L') {
            // ????
            if (equalsToDate(startDate, date.getValue(), false)
                    || equalsToDate(limitDate, date.getValue(), false)) {
                // ???
                result = true;
            } else {
                // ????????????
                result = result && startDate.before(cal.getTime()) && limitDate.after(cal.getTime());
            }
        }
    }

    return result;
}

From source file:util.DnCalendar.java

/**
 * Get an HTML formatted calendar widget based on the date and 
 * the url and a list of String dates which have blog activity.
 * The widget will have today's day highlighted if present in
 * the month specified in the cdate parameter, and the current
 * day in the cdate parameter will also be highlighted with a
 * different color.// ww  w  .  j  a v  a2  s .  c  o  m
 *
 * @param cdate The date is in the format YYYY-MM-DD.
 * @param url The url will be used as a prefix in each link.
 * @param dates A list of String dates in format YYYY-MM-DD.
 */
public String getWidget(String cdate, String url, HashSet dates, String member) {

    if (cdate == null)
        return null;

    String year, monthNumStr, day;
    year = monthNumStr = day = null;
    if (cdate.length() >= 7) {
        year = MyUtils.getYear(cdate);
        monthNumStr = MyUtils.getMonthNum(cdate);
    }
    if (cdate.length() == 10) {
        day = MyUtils.getDay(cdate);
    }

    //logger.info("year = " + year + " month = " + monthNumStr + " day = " + day + " cdate= " + cdate);
    //logger.info("url = " + url);
    //logger.info("dates = " + dates.toString());

    Calendar cal = Calendar.getInstance();
    int yrNum = new Integer(year).intValue();
    int monthNum = new Integer(monthNumStr).intValue();
    //System.out.println("yrNum = " + yrNum);
    //System.out.println("monthNum = " + monthNum);
    cal.set(yrNum, monthNum - 1, 1);
    //System.out.println(cal.getTime().toString());

    StringBuffer sb = new StringBuffer();

    // table top
    sb.append("<TABLE BORDER=\"1\" CELLSPACING=\"1\">\n");

    // today's date
    sb.append("<TR>\n");
    sb.append("<TD WIDTH=\"100\">\n");

    sb.append("<TABLE BORDER=\"0\" CELLSPACING=\"1\" WIDTH=\"100\">\n");
    //sb.append("<TR ALIGN=\"CENTER\">\n");
    sb.append("<TR>\n");

    //previous month link
    int prevMonthNum = monthNum - 1;
    int prevYrNum = yrNum;
    if (monthNum == 1) {
        prevMonthNum = 12;
        prevYrNum = yrNum - 1;
    }
    String ndate = null;
    String prevMonthStr = MyUtils.getMonthString(prevMonthNum);
    if (prevMonthNum < 10) {
        ndate = prevYrNum + "-0" + prevMonthNum;
    } else {
        ndate = prevYrNum + "-" + prevMonthNum;
    }
    //logger.info("prev month = " + prevMonthStr + " ndate = " + ndate);
    sb.append("<TD ALIGN=\"CENTER\">\n");
    sb.append("<font color=\"");
    sb.append(GlobalConst.calLabelColor);
    sb.append("\" size=\"");
    sb.append(GlobalConst.calFontSize);
    sb.append("\"><B>\n");

    // url begin
    sb.append("<a href=\"");
    sb.append(GlobalConst.PblogMonthlyUrl);
    sb.append("?date=");
    sb.append(ndate);
    sb.append("&member=");
    sb.append(member);
    sb.append("\">");
    sb.append("<font color=\"");
    sb.append(GlobalConst.calUrlColor);
    sb.append("\">");
    sb.append(prevMonthStr).append(" ").append(year);
    sb.append("</font>");
    sb.append("</a>");
    // url end
    sb.append("</B></font>\n</TD>\n");
    sb.append("<TD>\n&nbsp;</TD>\n<TD>\n&nbsp;</TD>\n");

    // current month
    sb.append("<TD ALIGN=\"RIGHT\">\n");
    sb.append("<font color=\"");
    sb.append(GlobalConst.calLabelColor);
    sb.append("\" size=\"");
    sb.append(GlobalConst.calFontSize);
    sb.append("\"><B>\n");
    String monthStr = MyUtils.getMonthString(monthNum);
    //logger.info("current month = " + monthStr);
    sb.append(monthStr).append(" ").append(year);
    sb.append("</B></font>\n");
    sb.append("</TD>\n");

    // fill the gaps
    sb.append("<TD>&nbsp;</TD>\n<TD>&nbsp;</TD>\n");

    // next month 
    int nextMonthNum = monthNum + 1;
    int nextYrNum = yrNum;
    if (monthNum == 12) {
        nextMonthNum = 1;
        nextYrNum = yrNum + 1;
    }
    String nextMonthStr = MyUtils.getMonthString(nextMonthNum);
    if (nextMonthNum < 10) {
        ndate = nextYrNum + "-0" + nextMonthNum;
    } else {
        ndate = nextYrNum + "-" + nextMonthNum;
    }
    //logger.info("next month = " + nextMonthStr + " ndate = " + ndate);

    //sb.append("<font color=\"");
    //sb.append(GlobalConst.calLabelColor);
    //sb.append("\"><font size=\"");
    //sb.append(GlobalConst.calFontSize);
    //sb.append("\"></font><u><B>\n");

    // url begin
    sb.append("<TD ALIGN=\"CENTER\">\n");
    sb.append("<a href=\"");
    sb.append(GlobalConst.PblogMonthlyUrl);
    sb.append("?date=");
    sb.append(ndate);
    sb.append("&member=");
    sb.append(member);
    sb.append("\">");
    sb.append("<font color=\"");
    sb.append(GlobalConst.calUrlColor);
    sb.append("\"><font size=\"");
    sb.append(GlobalConst.calFontSize);
    sb.append("\"></font><B>\n");
    sb.append(nextMonthStr).append(" ").append(year);
    sb.append("</B></font>\n");
    sb.append("</a>");
    // url end

    //sb.append("</u></B></font>\n");
    sb.append("</TD>\n");

    sb.append("</TR>\n");
    sb.append("</TABLE>\n");

    sb.append("</TD>\n");
    sb.append("</TR>\n");

    // week days, month days
    sb.append("<TR>\n");
    sb.append("<TD WIDTH=\"100\">\n");

    StringBuffer colorBegin = new StringBuffer("<TD><font color=\"");
    colorBegin.append(GlobalConst.calLabelColor);
    colorBegin.append("\">");

    StringBuffer colorEnd = new StringBuffer("</font></TD>\n");

    sb.append("<TABLE BORDER=\"1\" CELLSPACING=\"1\">\n");
    sb.append("<TR>\n");

    sb.append(colorBegin.toString());
    sb.append("S");
    sb.append(colorEnd.toString());

    sb.append(colorBegin.toString());
    sb.append("M");
    sb.append(colorEnd.toString());

    sb.append(colorBegin.toString());
    sb.append("T");
    sb.append(colorEnd.toString());

    sb.append(colorBegin.toString());
    sb.append("W");
    sb.append(colorEnd.toString());

    sb.append(colorBegin.toString());
    sb.append("T");
    sb.append(colorEnd.toString());

    sb.append(colorBegin.toString());
    sb.append("F");
    sb.append(colorEnd.toString());

    sb.append(colorBegin.toString());
    sb.append("S");
    sb.append(colorEnd.toString());
    /*
           sb.append("<TD><font color=\"ffffff\">S</font></TD>\n");
           sb.append("<TD><font color=\"ffffff\">M</font></TD>\n");
           sb.append("<TD><font color=\"ffffff\">T</font></TD>\n");
           sb.append("<TD><font color=\"ffffff\">W</font></TD>\n");
           sb.append("<TD><font color=\"ffffff\">T</font></TD>\n");
           sb.append("<TD><font color=\"ffffff\">F</font></TD>\n");
           sb.append("<TD><font color=\"ffffff\">S</font></TD>\n");
    */

    sb.append("</TR>\n");
    int dayMax = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
    int dayOfWeek = 0;
    for (int i = 1; i <= dayMax; i++) {
        cal.set(Calendar.DAY_OF_MONTH, i);
        ndate = yrNum + "-" + monthNumStr + "-" + i;

        // 01 to 09
        if (i < 10) {
            ndate = yrNum + "-" + monthNumStr + "-0" + i;
        }

        //logger.info("ndate = " + ndate);

        boolean islink = false;
        if (dates != null) {
            islink = dates.contains(ndate);
        }
        //logger.info("islink = " + ndate);
        dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);

        if ((dayOfWeek == 1) || (i == 1)) {
            sb.append("<TR>\n");
            for (int j = 1; j < dayOfWeek; j++) {
                sb.append("<TD>\n");
                sb.append("&nbsp;");
                sb.append("</TD>\n");
            }
        }
        sb.append("<TD>\n");
        if (islink) {
            //logger.info("islink exists " + url);
            sb.append("<a href=\"");
            sb.append(url);
            sb.append("&date=");
            sb.append(ndate);
            sb.append("\">");
            sb.append("<font color=\"");
            sb.append(GlobalConst.calUrlColor);
            sb.append("\">");
        } else {
            sb.append("<font color=\"");
            sb.append(GlobalConst.calLabelColor);
            sb.append("\">");
        }

        sb.append(i);
        sb.append("</font>");
        if (islink)
            sb.append("</a>");
        sb.append("</TD>\n");
        if (dayOfWeek == 7) {
            sb.append("</TR>\n");
        }
    }

    if (dayOfWeek != 7) {
        sb.append("</TR>\n");
    }
    sb.append("</TABLE>\n");
    sb.append("</TD>\n");
    sb.append("</TR>\n");

    /*
           sb.append("</TD>\n");
           sb.append("</TR>\n");
    */

    // table bottom
    sb.append("</TABLE>\n");
    return sb.toString();
}

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

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