📄 votepost.java
字号:
package com.laoer.bbscs.web.action;
import com.laoer.bbscs.web.form.*;
import com.laoer.bbscs.web.servlet.*;
import com.laoer.bbscs.bean.*;
import com.laoer.bbscs.sys.*;
import com.laoer.comm.util.*;
import org.apache.struts.action.*;
import org.apache.struts.util.*;
import javax.servlet.http.*;
import java.util.*;
/**
* <p>Title: TianYi BBS</p>
* <p>Description: TianYi BBS System</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: LAOER.COM/TIANYISOFT.NET</p>
* @author laoer
* @version 6.0
*/
public class VotePost
extends BaseAction {
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
ActionErrors errors = new ActionErrors();
VotePostForm form = (VotePostForm) actionForm;
UserCheck uc = this.getUserCheck(httpServletRequest, httpServletResponse,
form.getBid());
if (uc.isGuest()) {
errors.add("error.pleaselogin", new ActionError("error.pleaselogin"));
saveErrors(httpServletRequest, errors);
//return actionMapping.findForward("login");
return SysUtil.getPassLogin(actionMapping);
}
if (uc.getBs() == null) {
errors.add("error.baordsno", new ActionError("error.baordsno"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("error");
}
if (!uc.isCanPost()) {
errors.add("error.forum.cannotpost",
new ActionError("error.forum.cannotpost"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("error");
}
UserInfo ui = getUserCache().getUserInfoFromCache(uc.getId());
if (ui == null) {
errors.add("error.getusererror", new ActionError("error.getusererror"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("error");
}
if (! (uc.isSuperAdmin() || uc.isManager() || uc.isBulletin() ||
ui.getExp() >= SysInfo.getInstance().getVoteexp())) {
errors.add("error.vote.exp",
new ActionError("error.vote.exp",
String.
valueOf(SysInfo.getInstance().getVoteexp())));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("error");
}
httpServletRequest.setAttribute("ui", ui);
httpServletRequest.setAttribute("uc", uc);
if (form.getAction().equals("new")) {
form.setAction("addvote");
form.setDeadLineYear(Util.getYear());
form.setDeadLineMon(Util.getMonth());
httpServletRequest.setAttribute("votePostForm", form);
return actionMapping.findForward("vote");
}
if (form.getAction().equals("addvote")) {
if (uc.getPower() <= 0 && !uc.isCanPostNotNeedExp()) {
errors.add("nopower", new ActionError("error.post.nopower"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("error");
}
String IP = httpServletRequest.getRemoteAddr();
long atime = SysUtil.getLongTime();
String[] details = form.getDetail().split("\n");
if (details.length > this.getSysInfo().getVotenum()) {
errors.add("error.vote.itemnum",
new ActionError("error.vote.itemnum",
String.valueOf(this.getSysInfo().getVotenum())));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("vote");
}
MessageResources messages = getResources(httpServletRequest);
Locale locale = getLocale(httpServletRequest);
Vote vote = new Vote();
vote.setDeadLine(Util.Date2Long(form.getDeadLineYear(),
form.getDeadLineMon(),
form.getDeadLineDay()));
vote.setIsM(form.getIsM());
vote.setTitle("[" + messages.getMessage(locale, "post.vote") + "]" +
form.getTitle());
VoteItem vi;
List vis = new ArrayList();
for (int i = 0; i < details.length; i++) {
vi = new VoteItem();
vi.setItem(details[i]);
vi.setItemValue(0);
vis.add(vi);
}
Result r = this.getVoteService().createVote(vote, vis);
if (!r.isRight()) {
return actionMapping.findForward("error");
}
String detail = (String) r.getObject();
Forum forum = ForumFactory.getInstance(form.getBid());
forum.setAgree(0);
forum.setAmend("");
forum.setArtSize(detail.length());
forum.setAuditing(uc.getBs().getAttrib8());
forum.setBeAgainst(0);
forum.setBoardID(form.getBid());
forum.setBoardName(uc.getBs().getBoardsName());
forum.setCanNotDel( (short) 0);
forum.setCanNotRe( (short) 0);
forum.setCanReadExp(0);
forum.setClick(0);
forum.setDelIP("");
forum.setDelSign( (short) 0);
forum.setDelTime(0);
forum.setDelUserID(0);
forum.setDelUserName("");
forum.setDetail(detail);
forum.setDoEliteName("");
forum.setDoEliteTime(0);
forum.setElite(0);
forum.setEliteID(0);
forum.setEmailInform( (short) 0);
forum.setFace( (short) 0);
forum.setHavePic( (short) 0);
forum.setId1(0);
forum.setId2(0);
forum.setIpAddress(IP);
forum.setIsB( (short) 0);
forum.setIsLock( (short) 0);
forum.setIsNew( (short) 1);
forum.setIsTop( (short) 0);
forum.setIsVote( (short) 1);
forum.setLastPostNickName("---");
forum.setLastPostTitle("---");
forum.setLastPostUserName("---");
forum.setLastTime(atime);
forum.setMsgInform( (short) 0);
forum.setNickName(uc.getNickname());
forum.setPicName("");
forum.setPostTime(atime);
forum.setReNum(0);
forum.setSign("");
forum.setTitle(form.getTitle());
forum.setUserID(uc.getId());
forum.setUserName(uc.getUsername());
forum.setVtime("");
r = getForumService().createForum("new", forum, uc, null);
if (!r.isRight()) {
errors.add("posterror", new ActionError(r.getMsg()));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("error");
}
if (uc.getBs().getAttrib3() == 0) {
ui.setArticleNum(ui.getArticleNum() + 1);
if (!uc.isCanPostNotNeedExp()) {
ui.setPower( (short) (ui.getPower() - 1));
}
ui = this.getUserInfoService().saveUserInfo(ui);
if (ui != null) {
uc.addCookies(ui);
getUserCache().putUserInfoInCache(ui);
}
}
ActionForward f = new ActionForward("/forum" + Constant.FILEPREFIX +
"?bid=" + form.getBid(), true);
return f;
}
return actionMapping.findForward("error");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -