📄 forumnewsadmin.java
字号:
package com.bcxy.bbs.forum.admin;
/**
* Title:
* Description:
* Copyright:
* Company: www.liyunet.com
*
* @author lishujiang
* @version 1.0
*/
import java.sql.ResultSet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.bcxy.bbs.database.DBConnect;
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.GCookie;
import com.bcxy.bbs.util.ParamUtil;
import com.bcxy.cache.CacheManager;
import com.bcxy.conf.ENV;
public class ForumNewsAdmin {
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 bbsnews(userName,title,content,addtime,boardID) values(?,?,?,now(),"
+ forumID + ")";
DBConnect dbc = null;
try {
dbc = new DBConnect();
dbc.prepareStatement(sql);
dbc.setString(1, userName);
dbc.setString(2, title);
dbc.setString(3, content);
dbc.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
dbc.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 bbsnews set username=?,title=?,content=?,addtime=now(),boardID="
+ forumID + " where ID=" + newsID;
DBConnect dbc = null;
try {
dbc = new DBConnect();
dbc.prepareStatement(sql);
dbc.setString(1, userName);
dbc.setString(2, title);
dbc.setString(3, content);
dbc.executeUpdate();
//
CacheManager.getCache(ENV.GATEWAY).remove("news" + (newsID));
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
dbc.close();
}
}
public void delNews(HttpServletRequest request) throws Exception {
int newsID = ParamUtil.getInt(request, "newsID");
sql = "delete from bbsnews where ID=" + newsID;
DBConnect dbc = null;
try {
dbc = new DBConnect();
dbc.prepareStatement(sql);
dbc.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
dbc.close();
}
}
public void saveForumMaster(HttpServletRequest request) throws Exception {
String boardmaster = ParamUtil.getString(request, "boardmaster", "");
String readme = ParamUtil.getString(request, "readme", "");
sql = "update board set boardmaster=?,readme=? where boardID="
+ forumID;
DBConnect dbc = null;
String oldBoardMaster = ForumFactory.getForum(forumID).getForumMaster();
try {
dbc = new DBConnect();
dbc.prepareStatement(sql);
dbc.setString(1, boardmaster);
dbc.setString(2, readme);
dbc.executeUpdate();
//
if(!"".equals(oldBoardMaster)){
ForumAdmin.delMaster(oldBoardMaster, dbc);
}
if(!"".equals(boardmaster)){
ForumAdmin.addMaster(boardmaster, dbc);
}
CacheManager.getCache(ENV.FORUM).remove(String.valueOf(forumID));
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
dbc.close();
}
}
public void saveForumInfo(HttpServletRequest request) throws Exception {
String sql = "update board set forumlogo=?,indexIMG=?,strAllowForumCode=?,strAllowHTML=?,strIMGInPosts=?,\n strIcons=?,strflash=? ,boardskin=?\n where boardid="+forumID;
DBConnect dbc = null;
try {
dbc = new DBConnect();
dbc.prepareStatement(sql);
int i = 1;
dbc.setString(i++, ParamUtil.getString(request, "Logo", ""));
dbc.setString(i++, ParamUtil.getString(request, "indexIMG", ""));
dbc.setInt(i++, ParamUtil.getInt(request, "strAllowForumCode",0));
dbc.setInt(i++, ParamUtil.getInt(request, "strAllowHTML", 0));
dbc.setInt(i++, ParamUtil.getInt(request, "strIMGInPosts", 0));
dbc.setInt(i++, ParamUtil.getInt(request, "strIcons", 0));
dbc.setInt(i++, ParamUtil.getInt(request, "strflash", 0));
dbc.setInt(i++, ParamUtil.getInt(request, "forumSkin", 1));
dbc.executeUpdate();
// 消除缓存
CacheManager.getCache(ENV.FORUM).remove(String.valueOf(forumID));
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
dbc.close();
}
}
public void saveForumColor(HttpServletRequest request) throws Exception {
String sql = "update board set tableback=?,\n tabletitle=?,tablebody=?,atablebody=?,tableFont=?,tablecontent=?,alertfont=? where boardid="+forumID;
DBConnect dbc = null;
try {
dbc = new DBConnect();
dbc.prepareStatement(sql);
int i = 1;
dbc.setString(i++, ParamUtil.getString(request, "Tableback", ""));
dbc.setString(i++, ParamUtil.getString(request, "Tabletitle", ""));
dbc.setString(i++, ParamUtil.getString(request, "Tablebody", ""));
dbc.setString(i++, ParamUtil.getString(request, "aTablebody", ""));
dbc.setString(i++, ParamUtil.getString(request, "TableFont", ""));
dbc.setString(i++, ParamUtil.getString(request, "TableContent", ""));
dbc.setString(i++, ParamUtil.getString(request, "AlertFont", ""));
dbc.executeUpdate();
// 消除缓存
CacheManager.getCache(ENV.FORUM).remove(String.valueOf(forumID));
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
dbc.close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -