ForumAdmin.java
上传用户:yuyunping
上传日期:2013-03-21
资源大小:1844k
文件大小:15k
源码类别:

Java书籍

开发平台:

Java

  1. package net.acai.forum.admin;
  2. /**
  3.  * Title:        清清网络
  4.  * Description:
  5.  * Copyright:    Copyright (c) 2002
  6.  * Company:      www.SuperSpace.com
  7.  * @author:       SuperSpace
  8.  * @version 1.0
  9.  */
  10. import net.acai.forum.*;
  11. import net.acai.database.*;
  12. import javax.servlet.http.*;
  13. import java.sql.*;
  14. import net.acai.util.*;
  15. public class ForumAdmin{
  16. public ForumAdmin(){}
  17. //////////////////////////////////save mod/////////////
  18. public void saveMod(HttpServletRequest request) throws Exception{
  19. int forumID;
  20. try{
  21. forumID=ParamUtil.getInt(request,"forumID");
  22. }
  23. catch(Exception e){
  24. throw new Exception("对不起,请您选定您想要修改的论坛ID");
  25. }
  26. int forumSkin;
  27. try{
  28. forumSkin=ParamUtil.getInt(request,"forumSkin");
  29. }
  30. catch(Exception e){
  31. throw new Exception("对不起,请您选定论坛的类别!");
  32. }
  33. Forum theForum=ForumFactory.getForum(forumID);
  34. if(theForum==null)
  35. throw new  Exception("错误的论坛");
  36. if(theForum.getForumSkin()==forumSkin)
  37. return;
  38. String forumUser_1="";
  39. if(forumSkin==5){
  40. String vipuser=ParamUtil.getString(request,"vipuser");
  41. if(vipuser!=null&&!"".equals(vipuser.trim())){
  42. String [] forumUser=vipuser.split("\n|\r");
  43. for(int i=0;i<forumUser.length;i++){
  44. if(!"".equals(forumUser_1)){
  45. if(i!=forumUser.length-1)
  46. forumUser_1+=forumUser[i]+",";
  47. else
  48. forumUser_1+=forumUser[i];
  49. }
  50. }
  51. }
  52. }
  53. DBConnect dbc=new DBConnect("update bbs.board set boardUser=?,boardskin=? where boardID=?");
  54. dbc.setBytes(1,(new String(forumUser_1.getBytes("ISO-8859-1"),"GBK")).getBytes());
  55. dbc.setInt(2,forumSkin);
  56. dbc.setInt(3,forumID);
  57. dbc.executeUpdate();
  58. dbc.close();
  59. }
  60. public static void saveNew(HttpServletRequest request) throws  Exception{
  61. String forumType=ParamUtil.getString(request,"boardtype");
  62. if(forumType==null||"".equals(forumType.trim()))
  63. throw new Exception("请输入论坛名称。");
  64. int classID;
  65. try{
  66. classID=ParamUtil.getInt(request,"class");
  67. }
  68. catch(Exception e){
  69. throw new Exception("请选择论坛分类。");
  70. }
  71. String forumMaster=ParamUtil.getString(request,"boardmaster","");
  72. /*if(forumMaster==null||"".equals(forumMaster.trim()))
  73. throw new Exception("请输入版主姓名。");
  74. */
  75. String readme=ParamUtil.getString(request,"readme");
  76. if(readme==null||"".equals(readme.trim()))
  77. throw new Exception("请输入论坛说明。");
  78. int lockForum;
  79. try{
  80. lockForum=ParamUtil.getInt(request,"lockboard");
  81. }
  82. catch(Exception e){
  83. throw new Exception("请选择论坛开放状态。");
  84. }
  85. DBConnect dbc=new DBConnect();
  86. String sql="insert into bbs.board(boardtype,class,boardmaster,readme,lockboard,tableback,tabletitle,ntablebody,atablebody,tablefont,tablecontent,alertfont,forumlogo,indeximg,nstrallowforumcode,strallowhtml,strimginposts,stricons,strflash,lastpostuser,nlastposttime,lastbbsnum,lasttopicnum)n values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,getdate(),?,?)";
  87. dbc.prepareStatement(sql);
  88. dbc.setBytes(1,(new String(forumType.getBytes("ISO-8859-1"),"GBK")).getBytes());
  89. dbc.setInt(2,classID);
  90. dbc.setBytes(3,(new String(forumMaster.getBytes("ISO-8859-1"),"GBK")).getBytes());
  91. dbc.setBytes(4,(new String(readme.getBytes("ISO-8859-1"),"GBK")).getBytes());
  92. dbc.setInt(5,lockForum);
  93. dbc.setString(6,ParamUtil.getString(request,"Tableback",""));
  94. dbc.setString(7,ParamUtil.getString(request,"Tabletitle",""));
  95. dbc.setString(8,ParamUtil.getString(request,"Tablebody",""));
  96. dbc.setString(9,ParamUtil.getString(request,"aTablebody",""));
  97. dbc.setString(10,ParamUtil.getString(request,"TableFont",""));
  98. dbc.setString(11,ParamUtil.getString(request,"TableContent",""));
  99. dbc.setString(12,ParamUtil.getString(request,"AlertFont",""));
  100. dbc.setString(13,ParamUtil.getString(request,"Logo",""));
  101. dbc.setString(14,ParamUtil.getString(request,"indeIMG",""));
  102. dbc.setString(15,ParamUtil.getString(request,"strAllowForumCode",""));
  103. dbc.setString(16,ParamUtil.getString(request,"strAllowHTML",""));
  104. dbc.setString(17,ParamUtil.getString(request,"strIMGInPosts",""));
  105. dbc.setString(18,ParamUtil.getString(request,"strIcons",""));
  106. dbc.setString(19,ParamUtil.getString(request,"strflash",""));
  107. dbc.setBytes(20,(new String(("未知").getBytes("ISO-8859-1"),"GBK")).getBytes());
  108. dbc.setInt(21,0);
  109. dbc.setInt(22,0);
  110. dbc.executeUpdate();
  111. if(forumMaster!=null&&!("".equals(forumMaster.trim())))
  112. addMaster(forumMaster,dbc);
  113. dbc.close();
  114. }
  115. public static void saveEdit(HttpServletRequest request) throws Exception{
  116. //System.out.println("asdf");
  117. int editID;
  118. try{
  119. editID=ParamUtil.getInt(request,"editid");
  120. }
  121. catch(Exception e){
  122. throw new Exception("请选择编辑论坛的ID。");
  123. }
  124. int newforumID;
  125. try{
  126. newforumID=ParamUtil.getInt(request,"newforumID");
  127. }
  128. catch(Exception e){
  129. throw new Exception("请填写新论坛的ID。");
  130. }
  131. if (newforumID!=editID) {
  132. Forum tempForum=ForumFactory.getForum(newforumID);
  133. if(tempForum!=null)
  134. throw new Exception("您不能指定和别的论坛一样的序号。");
  135. }
  136. String forumType=ParamUtil.getString(request,"boardtype");
  137. if(forumType==null||"".equals(forumType.trim()))
  138. throw new Exception("请输入论坛名称。");
  139. int classID;
  140. try{
  141. classID=ParamUtil.getInt(request,"class");
  142. }
  143. catch(Exception e){
  144. throw new Exception("请选择论坛分类。");
  145. }
  146. String forumMaster=ParamUtil.getString(request,"boardmaster","");
  147. /*if(forumMaster==null||"".equals(forumMaster.trim()))
  148. throw new Exception("请输入版主姓名。");*/
  149. String readme=ParamUtil.getString(request,"readme");
  150. if(readme==null||"".equals(readme.trim()))
  151. throw new Exception("请输入论坛说明。");
  152. int lockForum;
  153. try{
  154. lockForum=ParamUtil.getInt(request,"lockboard");
  155. }
  156. catch(Exception e){
  157. throw new Exception("请选择论坛开放状态。");
  158. }
  159. String sql="update bbs.board set boardtype=?,class=?,boardmaster=?,readme=?,lockboard=?,tableback=?,n tabletitle=?,tablebody=?,atablebody=?,tableFont=?,tablecontent=?,alertfont=?,n forumlogo=?,indexIMG=?,strAllowForumCode=?,strAllowHTML=?,strIMGInPosts=?,n strIcons=?,strflash=? n where bbs.board.boardid=?";
  160. DBConnect dbc=new DBConnect();
  161. dbc.prepareStatement(sql);
  162. dbc.setBytes(1,(new String(forumType.getBytes("ISO-8859-1"),"GBK")).getBytes());
  163. dbc.setInt(2,classID);
  164. dbc.setBytes(3,(new String(forumMaster.getBytes("ISO-8859-1"),"GBK")).getBytes());
  165. dbc.setBytes(4,(new String(readme.getBytes("ISO-8859-1"),"GBK")).getBytes());
  166. dbc.setInt(5,lockForum);
  167. dbc.setString(6,ParamUtil.getString(request,"Tableback",""));
  168. dbc.setString(7,ParamUtil.getString(request,"Tabletitle",""));
  169. dbc.setString(8,ParamUtil.getString(request,"Tablebody",""));
  170. dbc.setString(9,ParamUtil.getString(request,"aTablebody",""));
  171. dbc.setString(10,ParamUtil.getString(request,"TableFont",""));
  172. dbc.setString(11,ParamUtil.getString(request,"TableContent",""));
  173. dbc.setString(12,ParamUtil.getString(request,"AlertFont",""));
  174. dbc.setString(13,ParamUtil.getString(request,"Logo",""));
  175. dbc.setString(14,ParamUtil.getString(request,"indeIMG",""));
  176. dbc.setString(15,ParamUtil.getString(request,"strAllowForumCode",""));
  177. dbc.setString(16,ParamUtil.getString(request,"strAllowHTML",""));
  178. dbc.setString(17,ParamUtil.getString(request,"strIMGInPosts",""));
  179. dbc.setString(18,ParamUtil.getString(request,"strIcons",""));
  180. dbc.setString(19,ParamUtil.getString(request,"strflash",""));
  181. dbc.setInt(20,editID);
  182. dbc.executeUpdate();
  183. sql="update bbs.bbs1 set boardid="+newforumID+" where boardid="+editID;
  184. dbc.executeUpdate(sql);
  185. if(forumMaster!=null&&!("".equals(forumMaster.trim())))
  186. addMaster(forumMaster,dbc);
  187. dbc.close();
  188. }
  189. public static void del(HttpServletRequest request) throws Exception{
  190. int forumID;
  191. try{
  192. forumID=ParamUtil.getInt(request,"boardid");
  193. }
  194. catch(Exception e){
  195. throw new Exception("请您选择您要修改的论坛ID");
  196. }
  197. String sql="delete from bbs.board where boardid="+forumID;
  198. DBConnect dbc=new DBConnect(sql);
  199. dbc.executeUpdate();
  200. sql="delete from bbs.bbs1 where boardid="+forumID;
  201. dbc.executeUpdate(sql);
  202. dbc.close();
  203. }
  204. public static void dell(HttpServletRequest request) throws Exception{
  205. int ID;
  206. try{
  207. ID=ParamUtil.getInt(request,"id");
  208. }
  209. catch(Exception e){
  210. throw new Exception("请您选择您要删除的分类的ID");
  211. }
  212. DBConnect dbc=new DBConnect();
  213. String sql = "delete from bbs.class where id="+ID;
  214. dbc.executeUpdate(sql);
  215. sql = "delete from bbs.board where class="+ID;
  216. dbc.executeUpdate(sql);
  217. sql="select boardid from bbs.board where class="+ID;
  218. ResultSet rs=dbc.executeQuery(sql);
  219. while(rs.next()){
  220. sql="delete from bbs.bbs1 where boardid="+rs.getInt(1);
  221. dbc.executeUpdate(sql);
  222. }
  223. dbc.close();
  224. }
  225. public static void updateOrders(HttpServletRequest request) throws Exception{
  226. int newID;
  227. try{
  228. newID=ParamUtil.getInt(request,"newid");
  229. }
  230. catch(Exception e){
  231. throw new Exception("请您选择您想要更新的类别!");
  232. }
  233. int ID;
  234. try{
  235. ID=ParamUtil.getInt(request,"id");
  236. }
  237. catch(Exception e){
  238. throw new Exception("请您选择您想要更新的类别!");
  239. }
  240. if(newID==ID)
  241. return;
  242. DBConnect dbc=new DBConnect();
  243. String sql="select * from bbs.class where id="+newID;
  244. ResultSet rs=dbc.executeQuery(sql);
  245. if(rs.next())
  246. throw new Exception("您输入的序号和其他分类序号相同,请重新输入。");
  247. sql="update bbs.class set id="+newID+",class=? where id="+ID;
  248. dbc.prepareStatement(sql);
  249. dbc.setBytes(1,(new String(ParamUtil.getString(request,"classname","").getBytes("ISO-8859-1"),"GBK")).getBytes());
  250. dbc.executeUpdate();
  251. sql="update bbs.board set class="+newID+" where class="+ID;
  252. dbc.executeUpdate(sql);
  253. sql="update bbs.board set class="+newID+" where class="+ID;
  254. dbc.executeUpdate(sql);
  255. dbc.close();
  256. }
  257. public static void saveClass(HttpServletRequest request) throws Exception{
  258. String classname=ParamUtil.getString(request,"classname");
  259. if(classname==null)
  260. throw new Exception("请您输入您想添加分类的名字!");
  261. String sql="insert into bbs.class(class) values(?)";
  262. DBConnect dbc=new DBConnect(sql);
  263. dbc.setBytes(1,(new String(classname.getBytes("ISO-8859-1"),"GBK")).getBytes());
  264. dbc.executeUpdate();
  265. dbc.close();
  266. }
  267. public String update() throws Exception{
  268. String sql="select boardid,boardtype from bbs.board";
  269. DBConnect dbc1=new DBConnect(sql);
  270. ResultSet rs=dbc1.executeQuery();
  271. StringBuffer sb=new StringBuffer();
  272. if(!rs.next()){
  273. dbc1.close();
  274. throw new Exception("论坛还没有版面,请先添加版面。");
  275. }
  276. // temprs;
  277. DBConnect dbc=new DBConnect();
  278. String newuser=newuser(dbc);
  279. do{
  280. sql="Select count(announceid) from bbs.bbs1 where boardid="+rs.getInt(1);
  281. ResultSet temprs=dbc.executeQuery(sql);
  282. temprs.next();
  283. String tempString=temprs.getString(1);
  284. int allArticle=(tempString==null)?0:temprs.getInt(1);
  285. temprs=dbc.executeQuery("Select count(announceid) from bbs.bbs1 where boardid="+rs.getInt(1) +" and parentID=0");
  286. temprs.next();
  287. tempString=temprs.getString(1);
  288. int allTopic=(tempString==null)?0:temprs.getInt(1);
  289. ResultSet ers=dbc.executeQuery("select Max(announceid) from bbs.bbs1 where boardid="+rs.getInt(1));
  290. ers.next();
  291. tempString=ers.getString(1);
  292. //int maxID=(tempString==null)?"无":ers.getInt(1);
  293. String userName,dateandtime;
  294. if(tempString==null){
  295. userName="无";
  296. dateandtime=Format.getDateTime();
  297. }
  298. else {
  299. int maxID=ers.getInt(1);
  300. ers=dbc.executeQuery("select username,dateandtime from bbs.bbs1 where announceid="+maxID);
  301. ers.next();
  302. userName=ers.getString(1);
  303. dateandtime=ers.getString(2);
  304. }
  305. sql="update bbs.board set lastpostuser=?,lastposttime='"+dateandtime+"',lastbbsnum="+allArticle+",lasttopicnum="+allTopic+",TodayNum="+todays(rs.getInt(1),dbc)+" where boardid="+rs.getInt(1);
  306. dbc.prepareStatement(sql);
  307. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  308. dbc.executeUpdate();
  309. sb.append("更新论坛数据成功,"+rs.getString(2)+"共有"+allArticle+"篇贴子,"+allTopic+"篇主题,今日有"+todays(rs.getInt(1),dbc)+"篇帖子。<br>");
  310. }
  311. while(rs.next());
  312. sql="update bbs.config set TopicNum="+titlenum(dbc)+",BbsNum="+gettipnum(dbc)+",TodayNum="+alltodays(dbc)+",UserNum="+allusers(dbc)+",lastUser=?";
  313. dbc.prepareStatement(sql);
  314. dbc.setBytes(1,(new String(newuser.getBytes("ISO-8859-1"),"GBK")).getBytes());
  315. dbc.executeUpdate();
  316. dbc.close();
  317. dbc1.close();
  318. ForumPropertiesManager.resetManager();
  319. return sb.toString();
  320. }
  321. public int  todays(int boardid,DBConnect dbc) throws Exception{
  322. ResultSet tmprs=dbc.executeQuery("Select count(announceid) from bbs.bbs1 Where  day(dateandtime)=day(getdate()) and boardid="+boardid);
  323. tmprs.next();
  324. String tempString=tmprs.getString(1);
  325. int temp=(tempString==null)?0:tmprs.getInt(1);
  326. return temp;
  327. }
  328. public int alltodays(DBConnect dbc) throws Exception{
  329.      ResultSet tmprs=dbc.executeQuery("Select count(announceid) from bbs.bbs1 Where  day(dateandtime)=day(getdate())");
  330. tmprs.next();
  331. String tempString=tmprs.getString(1);
  332. int temp=(tempString==null)?0:tmprs.getInt(1);
  333. return temp;
  334. }
  335. public int  allusers(DBConnect dbc) throws Exception{
  336.      ResultSet tmprs=dbc.executeQuery("Select count(userid) from bbs.myuser");
  337.      tmprs.next();
  338. String tempString=tmprs.getString(1);
  339. int temp=(tempString==null)?0:tmprs.getInt(1);
  340. return temp;
  341. }
  342. public  String newuser(DBConnect dbc) throws Exception{
  343. ResultSet tmprs=dbc.executeQuery("Select  username from bbs.myuser order by userid desc");
  344. String newuser;
  345. if(!tmprs.next()){
  346. newuser="没有会员";
  347. }
  348. else{
  349. //tmprs.next();
  350. newuser=tmprs.getString(1);
  351. }
  352. return newuser;
  353. }
  354. public int  gettipnum(DBConnect dbc) throws Exception{
  355.      ResultSet tmprs=dbc.executeQuery("Select Count(announceID) from bbs.bbs1");
  356.      tmprs.next();
  357. String tempString=tmprs.getString(1);
  358. int temp=(tempString==null)?0:tmprs.getInt(1);
  359. return temp;
  360. }
  361. public int titlenum(DBConnect dbc) throws Exception{
  362. ResultSet tmprs=dbc.executeQuery("Select Count(announceID) from bbs.bbs1 where parentID=0");
  363.      tmprs.next();
  364. String tempString=tmprs.getString(1);
  365. int temp=(tempString==null)?0:tmprs.getInt(1);
  366. return temp;
  367. }
  368. //////////////////////////////////////
  369. public static void addMaster(String masters,DBConnect dbc) throws Exception{
  370. String [] arr=masters.split("\|");
  371. //DBConnect dbc=
  372. ResultSet rs;
  373. String sql;
  374. for(int i=0;i<arr.length;i++){
  375. sql="select userID from bbs.myuser where userName=?";
  376. dbc.prepareStatement(sql);
  377. dbc.setBytes(1,(new String(arr[i].getBytes("ISO-8859-1"),"GBK")).getBytes());
  378. rs=dbc.executeQuery();
  379. if(!rs.next()){
  380. dbc.close();
  381. throw new Exception("没有发现此用户"+arr[i]);
  382. }
  383. sql="update bbs.myuser set userclass=19 where username=?";
  384. dbc.prepareStatement(sql);
  385. dbc.setBytes(1,(new String(arr[i].getBytes("ISO-8859-1"),"GBK")).getBytes());
  386. dbc.executeUpdate();
  387. }
  388. }
  389. }