package com.yxq.action;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.util.LabelValueBean;
import com.yxq.actionform.AbleForm;
import com.yxq.actionform.BoardForm;
import com.yxq.actionform.ClassForm;
import com.yxq.actionform.UserForm;
import com.yxq.dao.OpDB;
import com.yxq.tools.Change;
public class AdminAction extends DispatchAction {
/** 置顶帖子 */
public ActionForward setTopBbs(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){
HttpSession session=request.getSession();
session.setAttribute("mainPage","/pages/show/bbs/openRootShow.jsp");
String forwardPath="error";
String bbsId=request.getParameter("bbsId");
if(bbsId!=null&&!bbsId.equals("")){
Date date=new Date();
String today=Change.dateTimeChange(date);
String sql="update tb_bbs set bbs_isTop='1', bbs_toTopTime=? where bbs_id=?";
Object[] params={today,bbsId};
ActionMessages messages=new ActionMessages();
OpDB myOp=new OpDB();
int i=myOp.OpUpdate(sql, params);
if(i<=0){
System.out.println("置顶帖子出错!");
forwardPath="error";
messages.add("userOpR",new ActionMessage("luntan.bbs.top.E"));
}
else{
System.out.println("置顶帖子成功!");
forwardPath="success";
messages.add("userOpR",new ActionMessage("luntan.bbs.top.S"));
}
saveErrors(request,messages);
}
return mapping.findForward(forwardPath);
}
/** 设为精华帖子 */
public ActionForward setGoodBbs(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){
String forwardPath="error";
String bbsId=request.getParameter("bbsId");
if(bbsId!=null&&!bbsId.equals("")){
Date date=new Date();
String today=Change.dateTimeChange(date);
String sql="update tb_bbs set bbs_isGood='1', bbs_toTopTime=? where bbs_id=?";
Object[] params={today,bbsId};
ActionMessages messages=new ActionMessages();
OpDB myOp=new OpDB();
int i=myOp.OpUpdate(sql, params);
if(i<=0){
System.out.println("设为精华帖子失败!");
forwardPath="error";
messages.add("userOpR",new ActionMessage("luntan.bbs.good.E"));
}
else{
System.out.println("设为精华帖子成功!");
forwardPath="success";
messages.add("userOpR",new ActionMessage("luntan.bbs.good.S"));
}
saveErrors(request,messages);
}
return mapping.findForward(forwardPath);
}
/** 删除回复帖 */
public ActionForward deleteAnswerBbs(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){
String forwardPath="error";
String delbbsId=request.getParameter("delbbsAnswerId");
if(delbbsId!=null&&!delbbsId.equals("")){
String sql="delete from tb_bbsAnswer where bbsAnswer_id=?";
Object[] params={delbbsId};
ActionMessages messages=new ActionMessages();
OpDB myOp=new OpDB();
int i=myOp.OpUpdate(sql, params);
if(i<=0){
System.out.println("删除回复帖失败!");
forwardPath="error";
messages.add("userOpR",new ActionMessage("luntan.bbs.deleteAnswerR.E"));
}
else{
System.out.println("删除回复帖成功!");
forwardPath="success";
messages.add("userOpR",new ActionMessage("luntan.bbs.deleteAnswerR.S"));
}
saveErrors(request,messages);
}
return mapping.findForward(forwardPath);
}
/** 后台-列表查看论坛类别 */
public ActionForward getClassList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){
HttpSession session=request.getSession();
session.setAttribute("backMainPage","../class/classListShow.jsp");
OpDB myOp=new OpDB();
List classList=myOp.OpClassListShow();
session.setAttribute("backClassList",classList);
return mapping.findForward("success");
}
/** 后台-修改论坛类别 */
public ActionForward modifyClass(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){
HttpSession session=request.getSession();
session.setAttribute("backMainPage","../class/classModify.jsp");
String forwardPath="";
String classId=request.getParameter("classId");
if(classId==null)
classId="";
OpDB myOp=new OpDB();
ClassForm classForm=(ClassForm)form;
String validate=request.getParameter("validate");
if(validate==null||validate.equals("")||!validate.equals("yes")){
forwardPath="showModifyJSP";
String sql="select * from tb_class where class_id=?";
Object[] params={classId};
ClassForm classSingle=myOp.OpClassSingleShow(sql, params);
classForm.setClassId(classSingle.getClassId());
classForm.setClassName(classSingle.getClassName());
classForm.setClassIntro(classSingle.getClassIntro());
}
else{
ActionMessages messages=new ActionMessages();
classId = classForm.getClassId();
String className=Change.HTMLChange(classForm.getClassName());
String classIntro=Change.HTMLChange(classForm.getClassIntro());
String sql="update tb_class set class_name=?,class_intro=? where class_id=?";
Object[] paramsMo={className,classIntro,classId};
int i=myOp.OpUpdate(sql, paramsMo);
if(i<=0){
System.out.println("更新论坛类别失败!");
forwardPath="error";
messages.add("adminOpR",new ActionMessage("luntan.admin.modify.class.E"));
}
else{
System.out.println("更新论坛类别成功!");
session.setAttribute("backMainPage","../class/classListShow.jsp");
forwardPath="success";
messages.add("adminOpR",new ActionMessage("luntan.admin.modify.class.S"));
}
saveErrors(request,messages);
}
return mapping.findForward(forwardPath);
}
/** 后台-添加论坛类别 */
public ActionForward addClass(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){
HttpSession session=request.getSession();
session.setAttribute("backMainPage","../class/classAdd.jsp");
String validate=request.getParameter("validate");
if(validate==null||validate.equals("")||!validate.equals("yes")){
return mapping.findForward("result");
}
else{
ActionMessages messages=new ActionMessages();
ClassForm classForm=(ClassForm)form;
String className=Change.HTMLChange(classForm.getClassName());
String classIntro=Change.HTMLChange(classForm.getClassIntro());
String sql="";
Object[] params=null;
OpDB myOp=new OpDB();
sql="select * from tb_class where class_name=?";
params=new Object[1];
params[0]=className;
if(myOp.OpClassSingleShow(sql, params)!=null){
System.out.println("添加论坛类别-名称:"+className+" 的论坛已经存在!");
messages.add("adminOpR",new ActionMessage("luntan.admin.add.class.exist",className));
}
else{
sql="insert into tb_class values(?,?)";
params=new Object[2];
params[0]=className;
params[1]=classIntro;
int i=myOp.OpUpdate(sql, params);
if(i<=0){
System.out.println("添加论坛类别失败!");
messages.add("adminOpR",new ActionMessage("l