package cn.jsprun.struts.foreg.actions;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.util.MessageResources;
import cn.jsprun.domain.Attachments;
import cn.jsprun.domain.Forumfields;
import cn.jsprun.domain.Forums;
import cn.jsprun.domain.Members;
import cn.jsprun.domain.Polloptions;
import cn.jsprun.domain.Polls;
import cn.jsprun.domain.Posts;
import cn.jsprun.domain.Threads;
import cn.jsprun.struts.action.BaseAction;
import cn.jsprun.utils.Cache;
import cn.jsprun.utils.Common;
import cn.jsprun.utils.CookieUtil;
import cn.jsprun.utils.FileUploadUtil;
import cn.jsprun.utils.FormDataCheck;
import cn.jsprun.utils.ForumInit;
import cn.jsprun.utils.ImageUtil;
import cn.jsprun.utils.JspRunConfig;
import cn.jsprun.utils.Jspruncode;
import cn.jsprun.utils.Log;
import cn.jsprun.utils.Md5Token;
public class PostManageAction extends BaseAction {
public final static String FILEPATHTIME = JspRunConfig.realPath+"forumdata/temp";
public final static int memeoryBlock = 1572864;
@SuppressWarnings("unchecked")
public ActionForward toNewthread(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {
short fid = (short)Common.toDigit(request.getParameter("fid"));
Forums forum = forumService.findById(fid);
if (forum == null) {
request.setAttribute("errorInfo", getMessage(request, "forum_nonexistence"));
return mapping.findForward("showMessage");
}
request.setAttribute("styleid", forum.getStyleid() > 0 ? forum.getStyleid() : null);
Forumfields forumfield = forumfieldService.findById(fid);
if((forum.getSimple()&1)>0||forumfield.getRedirect().length()>0){
request.setAttribute("resultInfo", getMessage(request, "forum_disablepost"));
return mapping.findForward("showMessage");
}
HttpSession session = request.getSession();
short groupid=(Short)session.getAttribute("jsprun_groupid");
Members member = (Members) session.getAttribute("user");
int jsprun_uid = (Integer) session.getAttribute("jsprun_uid");
Map<String, String> usergroups = (Map<String, String>) request.getAttribute("usergroups");
int allowpost =Integer.valueOf(usergroups.get("allowpost"));
String postperm = forumfield.getPostperm();
List<Map<String,String>> accesslist = dataBaseService.executeQuery("select allowpost,allowpostattach from jrun_access where uid='"+jsprun_uid+"' and fid='"+fid+"'");
Map<String,String> access = accesslist.size()>0?accesslist.get(0):null;
if (member == null&& !((postperm.equals("") && allowpost > 0) || (!postperm.equals("") && Common.forumperm(postperm, groupid, member!=null?member.getExtgroupids():"")))) {
request.setAttribute("show_message", getMessage(request, "group_nopermission", usergroups.get("grouptitle")));
return mapping.findForward("nopermission");
}else if(access==null||Common.empty(access.get("allowpost"))){
if (postperm.equals("") && allowpost == 0) {
request.setAttribute("show_message", getMessage(request, "group_nopermission", usergroups.get("grouptitle")));
return mapping.findForward("nopermission");
} else if (!postperm.equals("") && !Common.forumperm(postperm, groupid, member!=null?member.getExtgroupids():"")) {
request.setAttribute("errorInfo", getMessage(request, "post_forum_newthread_nopermission"));
return mapping.findForward("showMessage");
}
}
if ("yes".equals(request.getParameter("isblog"))&& (Integer.valueOf(usergroups.get("allowuseblog")) == 0 || forum.getAllowshare() == 0)) {
request.setAttribute("errorInfo", getMessage(request, "post_newthread_blog_invalid"));
return mapping.findForward("showMessage");
}
if("yes".equals(request.getParameter("isblog"))){
request.setAttribute("blogcheck", "checked");
request.setAttribute("isblog", "yes");
}
int timestamp = (Integer)(request.getAttribute("timestamp"));
int special = Common.range(Common.intval(request.getParameter("special")), 6, 0);
Map<String, String> settings = ForumInit.settings;
String status = this.common(request, response, settings, usergroups, forumfield, forum,special,access,null);
if(status != null ){
return mapping.findForward(status);
}
byte only = forum.getAllowspecialonly();
boolean allowpostpoll = (Boolean)request.getAttribute("allowpostpoll");
boolean allowposttrade = (Boolean)request.getAttribute("allowposttrade");
boolean allowpostreward = (Boolean)request.getAttribute("allowpostreward");
boolean allowpostactivity = (Boolean)request.getAttribute("allowpostactivity");
boolean allowpostdebate = (Boolean)request.getAttribute("allowpostdebate");
boolean allowpostvideo = (Boolean)request.getAttribute("allowpostvideo");
if(special>0){
if(!((special==1&&allowpostpoll)||(special==2&&allowposttrade)||(special==3&&allowpostreward)||(special==4&&allowpostactivity)||(special==5&&allowpostdebate)||(special==6&&allowpostvideo))){
request.setAttribute("show_message", getMessage(request, "group_nopermission", usergroups.get("grouptitle")));
return mapping.findForward("nopermission");
}
}
if(only==1&&special==0){
if(allowpostpoll){
special = 1;
}else if(allowposttrade){
special = 2;
}else if(allowpostreward){
special = 3;
}else if(allowpostactivity){
special = 4;
}else if(allowpostdebate){
special = 5;
}else if(allowpostvideo){
special = 6;
}else{
request.setAttribute("errorInfo", getMessage(request, "undefined_action_return"));
return mapping.findForward("showMessage");
}
request.setAttribute("special", special);
}
String timeoffset=(String)session.getAttribute("timeoffset");
usergroups=null;
String target =null;
if (special == 2) {
SimpleDateFormat format = Common.getSimpleDateFormat("yyyy-MM-dd", timeoffset);
Map<String, String> trade = new HashMap<String, String>();
Calendar calendar = Common.getCalendar(timeoffset);
calendar.add(Calendar.MONTH, 1);
String expiration_month = format.format(calendar.getTimeInMillis());
calendar.add(Calendar.MONTH, -1);
calendar.add(Calendar.DATE, 7);
request.setAttribute("expiration_7days", format.format(calendar.getTimeInMillis()));
calendar.add(Calendar.DATE, 7);
request.setAttribute("expiration_14days", format.format(calendar.getTimeInMillis()));
request.setAttribute("expiration_month", expiration_month);
calendar.add(Calendar.DATE, -14);
calendar.add(Calendar.MONTH, 3);
request.setAttribute("expiration_3months", format.format(calendar.getTimeInMillis()));
calendar.add(Calendar.MONTH, 3);
request.setAttribute("expiration_halfyear", format.format(calendar.getTimeInMillis()));
calendar.add(Calendar.MONTH, -6);
calendar.add(Calendar.YEAR, 1);
request.setAttribute("expiration_year", format.format(calendar.getTimeInMillis()));
trade.put("amount", "1");
trade.put("transport", "2");
trade.put("expiration", expiration_month);
request.setAttribute("trade", trade);
trade=null;
String tradetypes=settings.get("tradetypes");
if(tradetypes!=null&&tradetype