📄 forumnewsadmin.java
字号:
package com.bcxy.bbs.forum.admin;
/**
* Title:
* Description:
* Copyright:
* Company: www.liyunet.com
*
* @author lishujiang
* @version 1.0
*/
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import com.bcxy.bbs.forum.Forum;
import com.bcxy.bbs.forum.ForumFactory;
import com.bcxy.bbs.forum.SkinUtil;
import com.bcxy.bbs.forum.User;
import com.bcxy.bbs.util.BBSConst;
import com.bcxy.bbs.util.GCookie;
import com.bcxy.bbs.util.ParamUtil;
import com.bcxy.cache.CacheManager;
import com.bcxy.conf.ENV;
import com.bcxy.db.JdbcWrapper;
public class ForumNewsAdmin {
private Logger log = Logger.getLogger(ForumMSGAdmin.class);
int forumID;
String userName, sql;
User theUser;
public ForumNewsAdmin(HttpServletRequest request,
HttpServletResponse response) throws Exception {
userName = GCookie.getCookieValue(request, "UJBBUName", "");
theUser = SkinUtil.checkUser(request, response, 4);
checkAdmin(request, response);
adminNews(request, response);
}
public void checkAdmin(HttpServletRequest request,
HttpServletResponse response) throws Exception {
//
forumID = ParamUtil.getInt(request, "forumID");
if (forumID == 0) {
if (theUser == null || theUser.getUserClass() < 20)
throw new Exception("请指定论坛版面");
} else {
Forum theForum = new Forum(forumID);
if ((theForum == null || theForum.getForumMaster()
.indexOf(userName) < 0)
&& (theUser == null || theUser.getUserClass() < 20))
throw new Exception("您不是该版面斑竹或者系统管理员。");
}
}
public void adminNews(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String action = ParamUtil.getString(request, "action");
if (action == null || "".equals(action)){
return;
}
if (action.equals("new")){
saveNews(request);
}else if (action.equals("update")){
updateNews(request);
}else if (action.equals("del")){
delNews(request);
}else if (action.equals("saveditbm")){
saveForumMaster(request);
}else if (action.equals("savebmset")){
saveForumInfo(request);
}else if (action.equals("savebmcolor")){
saveForumColor(request);
}
}
public void saveNews(HttpServletRequest request) throws Exception {
String title = ParamUtil.getString(request, "title");
if (title == null || "".equals(title.trim()))
throw new Exception("请输入新闻标题。");
String content = ParamUtil.getString(request, "content");
if (content == null || "".equals(content.trim()))
throw new Exception("请输入新闻内容。");
sql = "insert into " + BBSConst.TABLE_BBSNEWS + "(userName,title,content,addtime,boardID) values(?,?,?,now(),"
+ forumID + ")";
JdbcWrapper jw = new JdbcWrapper();
try {
jw.prepareStatement(sql);
jw.setString(1, userName);
jw.setString(2, title);
jw.setString(3, content);
jw.executeUpdate();
} catch (Exception e) {
log.error("添加论坛新闻出错", e);
throw e;
} finally {
jw.close();
}
}
public void updateNews(HttpServletRequest request) throws Exception {
String title = ParamUtil.getString(request, "title");
if (title == null || "".equals(title.trim()))
throw new Exception("请输入新闻标题。");
String content = ParamUtil.getString(request, "content");
if (content == null || "".equals(content.trim()))
throw new Exception("请输入新闻内容。");
int newsID = ParamUtil.getInt(request, "newsID");
sql = "update " + BBSConst.TABLE_BBSNEWS + " set username=?,title=?,content=?,addtime=now(),boardID="
+ forumID + " where ID=" + newsID;
JdbcWrapper jw = new JdbcWrapper();
try {
jw.prepareStatement(sql);
jw.setString(1, userName);
jw.setString(2, title);
jw.setString(3, content);
jw.executeUpdate();
//
CacheManager.getCache(ENV.GATEWAY).remove("news" + (newsID));
} catch (Exception e) {
log.error("更新论坛信息出错", e);
throw e;
} finally {
jw.close();
}
}
public void delNews(HttpServletRequest request) throws Exception {
int newsID = ParamUtil.getInt(request, "newsID");
sql = "delete from " + BBSConst.TABLE_BBSNEWS + " where ID=" + newsID;
JdbcWrapper jw = new JdbcWrapper();
try {
jw.prepareStatement(sql);
jw.executeUpdate();
} catch (Exception e) {
log.error("删除论坛信息出错", e);
throw e;
} finally {
jw.close();
}
}
public void saveForumMaster(HttpServletRequest request) throws Exception {
String boardmaster = ParamUtil.getString(request, "boardmaster", "");
String readme = ParamUtil.getString(request, "readme", "");
sql = "update " + BBSConst.TABLE_BOARD + " set boardmaster=?,readme=? where boardID="
+ forumID;
JdbcWrapper jw = new JdbcWrapper();
String oldBoardMaster = ForumFactory.getForum(forumID).getForumMaster();
try {
jw.setAutoClose(false);
jw.prepareStatement(sql);
jw.setString(1, boardmaster);
jw.setString(2, readme);
jw.executeUpdate();
//
if(!"".equals(oldBoardMaster)){
ForumAdmin.delMaster(oldBoardMaster, jw);
}
if(!"".equals(boardmaster)){
ForumAdmin.addMaster(boardmaster, jw);
}
CacheManager.getCache(ENV.FORUM).remove(String.valueOf(forumID));
} catch (Exception e) {
log.error("保存论坛版主出错", e);
throw e;
} finally {
jw.close();
}
}
public void saveForumInfo(HttpServletRequest request) throws Exception {
String sql = "update " + BBSConst.TABLE_BOARD + " set forumlogo=?,indexIMG=?,strAllowForumCode=?,strAllowHTML=?,strIMGInPosts=?,\n strIcons=?,strflash=? ,boardskin=?\n where boardid="+forumID;
JdbcWrapper jw = new JdbcWrapper();
try {
jw.prepareStatement(sql);
int i = 1;
jw.setString(i++, ParamUtil.getString(request, "Logo", ""));
jw.setString(i++, ParamUtil.getString(request, "indexIMG", ""));
jw.setInt(i++, ParamUtil.getInt(request, "strAllowForumCode",0));
jw.setInt(i++, ParamUtil.getInt(request, "strAllowHTML", 0));
jw.setInt(i++, ParamUtil.getInt(request, "strIMGInPosts", 0));
jw.setInt(i++, ParamUtil.getInt(request, "strIcons", 0));
jw.setInt(i++, ParamUtil.getInt(request, "strflash", 0));
jw.setInt(i++, ParamUtil.getInt(request, "forumSkin", 1));
jw.executeUpdate();
// 消除缓存
CacheManager.getCache(ENV.FORUM).remove(String.valueOf(forumID));
} catch (Exception e) {
log.error("更新论坛信息出错", e);
throw e;
} finally {
jw.close();
}
}
public void saveForumColor(HttpServletRequest request) throws Exception {
String sql = "update " + BBSConst.TABLE_BOARD + " set tableback=?,\n tabletitle=?,tablebody=?,atablebody=?,tableFont=?,tablecontent=?,alertfont=? where boardid="+forumID;
JdbcWrapper jw = new JdbcWrapper();
try {
jw.prepareStatement(sql);
int i = 1;
jw.setString(i++, ParamUtil.getString(request, "Tableback", ""));
jw.setString(i++, ParamUtil.getString(request, "Tabletitle", ""));
jw.setString(i++, ParamUtil.getString(request, "Tablebody", ""));
jw.setString(i++, ParamUtil.getString(request, "aTablebody", ""));
jw.setString(i++, ParamUtil.getString(request, "TableFont", ""));
jw.setString(i++, ParamUtil.getString(request, "TableContent", ""));
jw.setString(i++, ParamUtil.getString(request, "AlertFont", ""));
jw.executeUpdate();
// 消除缓存
CacheManager.getCache(ENV.FORUM).remove(String.valueOf(forumID));
} catch (Exception e) {
log.error("保存论坛信息出错", e);
throw e;
} finally {
jw.close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -