Forum.java
上传用户:toby834
上传日期:2013-10-21
资源大小:2613k
文件大小:35k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package net.acai.forum;
  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.database.*;
  11. import java.sql.*;
  12. import net.acai.filter.*;
  13. import net.acai.util.*;
  14. import net.acai.forum.*;
  15. import net.acai.util.Format;
  16. import java.util.Vector;
  17. import javax.servlet.http.*;
  18. //import net.acai.forum.util.*;
  19. import java.util.regex.*;
  20. public class Forum{
  21. int forumID,forumClass,lockForum,forumSkin,lastBbsNum;
  22. int lastTopicNum,strAllowForumCode,strAllowHTML,strIMGInPosts;
  23. int strIcons,strFlash,lastRootID,todayNum;
  24. int voteID;
  25. String forumType,readMe,forumMaster;
  26. String tableBack,tableTitle,tableBody,aTableBody,tableFont,tableContent;
  27. String alertFont,lastPostUser,lastPostTime,forumLogo,indexIMG,lastTopic,forumUser;
  28. Vector forumOLUsers;
  29. int forumTopicNum;
  30. int forumOLGuestUsersNum=0,forumOLMemberUsersNum=0,forumsOLUsersNum=0;
  31. int forumMSGsNum=0;
  32. ForumTopic forumMSGTopic;
  33. public Forum(){
  34. }
  35. public Forum(HttpServletRequest request,HttpServletResponse response,int forumID) throws ForumNotFoundException{
  36. init(forumID);
  37. SkinUtil.checkUserStats(request,response,this.forumType);
  38. this.getOnline();
  39. }
  40. public Forum(int forumID) throws ForumNotFoundException{
  41. init(forumID);
  42. this.getOnline();
  43. }
  44. public void init(int forumID) throws ForumNotFoundException{
  45. try{
  46. DBConnect dbc=new DBConnect("select * from bbs.board where boardid=?");
  47. dbc.setInt(1,forumID);
  48. ResultSet rs=dbc.executeQuery();
  49. rs.next();
  50. this.forumID=rs.getInt(1);
  51. forumType=rs.getString(2);
  52. forumClass=rs.getInt(3);
  53. readMe=rs.getString(4);
  54. forumMaster=rs.getString(5);
  55. lockForum=rs.getInt(6);
  56. forumSkin=rs.getInt(7);
  57. tableBack=rs.getString(8);
  58. tableTitle=rs.getString(9);
  59. tableBody=rs.getString(10);
  60. aTableBody=rs.getString(11);
  61. tableFont=rs.getString(12);
  62. tableContent=rs.getString(13);
  63. alertFont=rs.getString(14);
  64. lastPostUser=rs.getString(15);
  65. lastPostTime=rs.getString(16);
  66. lastBbsNum=rs.getInt(17);
  67. lastTopicNum=rs.getInt(18);
  68. strAllowForumCode=rs.getInt(19);
  69. strAllowHTML=rs.getInt(20);
  70. strIMGInPosts=rs.getInt(21);
  71. strIcons=rs.getInt(22);
  72. strFlash=rs.getInt(23);
  73. forumLogo=rs.getString(24);
  74. indexIMG=rs.getString(25);
  75. lastRootID=rs.getInt(26);
  76. lastTopic=rs.getString(27);
  77. todayNum=rs.getInt(28);
  78. forumUser=rs.getString(29);
  79. dbc.clearParameters();
  80. dbc.close();
  81. }
  82. catch(Exception e){
  83. e.printStackTrace();
  84. throw new ForumNotFoundException();
  85. }
  86. }
  87. public Vector getOnline() throws ForumNotFoundException{
  88. try{
  89. DBConnect dbc=new DBConnect();
  90. dbc.prepareStatement("select * from bbs.online order by id");
  91. ResultSet rs=dbc.executeQuery();
  92. forumsOLUsersNum=rs.getRow();
  93. forumOLUsers=new Vector();
  94. dbc.prepareStatement("select * from bbs.online where stats like ? order by id");
  95. String tempForumType="%"+forumType+"%";
  96. dbc.setBytes(1,(new String(tempForumType.getBytes("ISO-8859-1"),"GBK")).getBytes());
  97. rs=dbc.executeQuery();
  98. while(rs.next()){//&&this.forumType.equals(rs.getString(4).trim())){
  99. OLUser tempOLUser=new OLUser();
  100. tempOLUser.setUserID(rs.getInt(1));
  101. if("guest".equals(rs.getString(2)))
  102. forumOLGuestUsersNum++;
  103. else
  104. forumOLMemberUsersNum++;
  105. tempOLUser.setUserName(rs.getString(2));
  106. tempOLUser.setUserClass(rs.getString(3));
  107. tempOLUser.setStats(rs.getString(4));
  108. tempOLUser.setUserIP(rs.getString(5));
  109. tempOLUser.setStartTime(rs.getString(6));
  110. tempOLUser.setLastTimeBK(rs.getString(7));
  111. tempOLUser.setLastTime(rs.getString(8));
  112. tempOLUser.setBrowser(rs.getString(9));
  113. tempOLUser.setActForIP(rs.getString(10));
  114. tempOLUser.setComeFrom(rs.getString(11));
  115. tempOLUser.setActCome(rs.getString(12));
  116. forumOLUsers.add(tempOLUser);
  117. }
  118. dbc.close();
  119. return forumOLUsers;
  120. }
  121. catch(Exception e){
  122. e.printStackTrace();
  123. throw new ForumNotFoundException();
  124. }
  125. }
  126. public Vector getForumTopics  (int forumID,int start ,int Page) throws ForumTopicNotFoundException{
  127. try
  128. {
  129. //DBConnect dbc=new DBConnect(2,0);
  130. DBConnect dbc=new DBConnect();
  131. ResultSet rs=dbc.executeQuery("select count(announceid) from bbs.bbs1 where boardID="+forumID+" and parentID=0  and  locktopic!=2");
  132. rs.next();
  133. forumTopicNum=rs.getInt(1);
  134. String sql="select count(Announceid) from bbs.bbs1 where istop=1 and layer=1 and boardid="+forumID;
  135. rs=dbc.executeQuery(sql);
  136. rs.next();
  137. int topNum=rs.getInt(1);
  138. rs.close();
  139. int maxAnnouncePerPage=Integer.parseInt(ForumPropertiesManager.getString("MaxAnnouncePerPage"));
  140. /*if(Page>1)
  141. sql="select * from bbs1 where boardID="+forumID+" and parentID=0n and times < (select all (times) from bbs1 where boardID="+forumID+" and istop=0 and parentID=0 order by times desc limit 0,"+((Page-1)*maxAnnouncePerPage-topNum)+")  andn  locktopic!=2 ORDER BY istop desc,times desc,announceid desc limitn 0,"+maxAnnouncePerPage;
  142. else*/
  143. sql="select * from bbs.bbs1 where boardID="+forumID+" and parentID=0  and  locktopic!=2n ORDER BY istop desc,times desc,announceid descn";
  144. dbc.prepareStatement(sql);
  145. rs=dbc.executeQuery();
  146. int num1 = ((Page-1)*maxAnnouncePerPage) ;
  147. int num2 = (((Page-1)*maxAnnouncePerPage)+maxAnnouncePerPage) ;
  148. int i = 0 ;
  149. int n = 0 ;
  150. Vector forumTopics=new Vector();
  151. while(rs.next()){
  152. i++;
  153. if(i<num1)continue;
  154. n++;
  155. if(n>num2)break;
  156. ForumTopic theTopic=new ForumTopic(rs.getInt(12));
  157. theTopic.setAnnounceID(rs.getInt(1));
  158. theTopic.setParentID(rs.getInt(2));
  159. theTopic.setChildNum(rs.getInt(3));
  160. theTopic.setForumID(rs.getInt(4));
  161. theTopic.setUserName(rs.getString(5));
  162. theTopic.setUserEmail(rs.getString(6));
  163. theTopic.setTopic(rs.getString(7));
  164. theTopic.setBody(rs.getString(8));
  165. theTopic.setDateAndTime(rs.getString(9));
  166. theTopic.setHits(rs.getInt(10));
  167. theTopic.setLength(rs.getInt(11));
  168. theTopic.setRootID(rs.getInt(12));
  169. theTopic.setLayer(rs.getInt(13));
  170. theTopic.setOrders(rs.getInt(14));
  171. theTopic.setIsBest(rs.getInt(15));
  172. theTopic.setUserIP(rs.getString(16));
  173. theTopic.setExpression(rs.getString(17));
  174. theTopic.setTimes(rs.getInt(18));
  175. theTopic.setLockTopic(rs.getInt(19));
  176. theTopic.setSignFlag(rs.getInt(20));
  177. theTopic.setEmailFlag(rs.getInt(21));
  178. theTopic.setIsTop(rs.getInt(22));
  179. theTopic.setIsVote(rs.getInt(23));
  180. forumTopics.add(theTopic);
  181. }
  182. dbc.close();
  183. return forumTopics;
  184. }
  185. catch ( ForumTopicNotFoundException  oe )
  186. {
  187. oe.printStackTrace();
  188. return null;
  189. }
  190. catch ( SQLException s3 )
  191. {
  192. s3.printStackTrace();
  193. return null;
  194. }
  195. catch(Exception e)
  196. {
  197. e.printStackTrace();
  198. throw new ForumTopicNotFoundException();
  199. }
  200. }
  201. public Vector getForumBestTopics  (int forumID,int start ,int perPage) throws ForumTopicNotFoundException{
  202. try{
  203. //DBConnect dbc=new DBConnect(2,0);
  204. DBConnect dbc=new DBConnect();
  205. dbc.prepareStatement("select * from bbs.bbs1 where boardID=? and isBest=1 and locktopic!=2  ORDER BY bbs1.times desc,bbs1.announceid desc");
  206. dbc.setInt(1,forumID);
  207. ResultSet rs=dbc.executeQuery();
  208. if(rs.last())
  209. forumTopicNum=rs.getRow();
  210. rs.absolute(start);
  211. int i=0;
  212. Vector forumTopics=new Vector();
  213. do
  214. {
  215. ForumTopic theTopic=new ForumTopic(rs.getInt(12));
  216. theTopic.setAnnounceID(rs.getInt(1));
  217. theTopic.setParentID(rs.getInt(2));
  218. theTopic.setChildNum(rs.getInt(3));
  219. theTopic.setForumID(rs.getInt(4));
  220. theTopic.setUserName(rs.getString(5));
  221. theTopic.setUserEmail(rs.getString(6));
  222. theTopic.setTopic(rs.getString(7));
  223. theTopic.setBody(rs.getString(8));
  224. theTopic.setDateAndTime(rs.getString(9));
  225. theTopic.setHits(rs.getInt(10));
  226. theTopic.setLength(rs.getInt(11));
  227. theTopic.setRootID(rs.getInt(12));
  228. theTopic.setLayer(rs.getInt(13));
  229. theTopic.setOrders(rs.getInt(14));
  230. theTopic.setIsBest(rs.getInt(15));
  231. theTopic.setUserIP(rs.getString(16));
  232. theTopic.setExpression(rs.getString(17));
  233. theTopic.setTimes(rs.getInt(18));
  234. theTopic.setLockTopic(rs.getInt(19));
  235. theTopic.setSignFlag(rs.getInt(20));
  236. theTopic.setEmailFlag(rs.getInt(21));
  237. theTopic.setIsTop(rs.getInt(22));
  238. theTopic.setIsVote(rs.getInt(23));
  239. forumTopics.add(theTopic);
  240. i++;
  241. if(i==perPage)
  242. break;
  243. }
  244. while(rs.next());
  245. dbc.close();
  246. return forumTopics;
  247. }
  248. catch(Exception e)
  249. {
  250. e.printStackTrace();
  251. throw new ForumTopicNotFoundException();
  252. }
  253. }
  254. public static Vector getFollowTopics (int forumID,int rootID){
  255. Vector followTopics=new Vector();
  256. try{
  257. String sql="select announceID,layer,bbs.bbs1.boardID,rootID,topic,body,userName,child,hits from bbs.bbs1,bbs.board where bbs.bbs1.boardid="+forumID+" and bbs.bbs1.rootid="+rootID+" and bbs.bbs1.announceid<>"+rootID+" and bbs.bbs1.boardid=bbs.board.boardid and  bbs.bbs1.locktopic!=2 order by bbs.bbs1.rootid desc,bbs.bbs1.orders";
  258. //DBConnect dbc=new DBConnect(2,0);
  259. DBConnect dbc=new DBConnect();
  260. ResultSet rs=dbc.executeQuery(sql);
  261. while(rs.next()){
  262. ForumTopic theMSG=new ForumTopic();
  263. theMSG.setAnnounceID(rs.getInt("announceID"));
  264. theMSG.setLayer(rs.getInt("layer"));
  265. theMSG.setForumID(rs.getInt("boardID"));
  266. theMSG.setRootID(rs.getInt("rootID"));
  267. theMSG.setAnnounceID(rs.getInt("announceID"));
  268. /*
  269. if(rs.getString("topic")==null||rs.getString("topic").trim().equals("")){
  270. String m=rs.getString("body");
  271. if(rs.getString("body").length()>22)
  272. theMSG.setTopic(m.substring(0,22).replaceAll("\n|\r"," ").replaceAll(">", "&gt;").replaceAll("<", "&lt;"));
  273. else{
  274. theMSG.setTopic(m.replaceAll("\r|\n"," ").replaceAll(">", "&gt;").replaceAll("<", "&lt;"));
  275. }
  276. }
  277. else*/
  278. theMSG.setTopic(rs.getString("topic"));
  279. theMSG.setBody(rs.getString("body"));
  280. theMSG.setUserName(rs.getString("userName"));
  281. theMSG.setChildNum(rs.getInt("child"));
  282. theMSG.setHits(rs.getInt("hits"));
  283. followTopics.add(theMSG);
  284. }
  285. dbc.close();
  286. }
  287. catch(Exception e){
  288. e.printStackTrace();
  289. }
  290. return followTopics;
  291. }
  292. public ForumMSG getForumMSGTopic(){
  293. return this.forumMSGTopic;
  294. }
  295. public Vector getForumMSGs  (int forumID,int rootID,int announceID,int start ,int perPage) throws ForumMSGNotFoundException{
  296. try{
  297. DBConnect dbc=new DBConnect();
  298. ResultSet rs=dbc.executeQuery("select topic,istop,isbest,username,hits,times from bbs.bbs1 where announceID="+rootID);
  299. rs.next();
  300. forumMSGTopic=new ForumTopic();
  301. forumMSGTopic.setTopic(rs.getString(1));
  302. forumMSGTopic.setIsTop(rs.getInt(2));
  303. forumMSGTopic.setIsBest(rs.getInt(3));
  304. forumMSGTopic.setUserName(rs.getString(4));
  305. forumMSGTopic.setHits(rs.getInt(5));
  306. forumMSGTopic.setTimes(rs.getInt(6));
  307. forumMSGTopic.setAnnounceID(rootID);
  308. rs.close();
  309. String sql="Select B.AnnounceID,B.boardID,B.UserName,B.Topic,B.dateandtime,B.body,"+
  310. "B.Expression,B.ip,B.rootid,B.signflag,B.isbest,B.isvote,"+
  311. "U.username,U.useremail,U.homepage,U.oicq,U.sign,U.userclass,"+
  312. "U.title,U.width,U.height,U.article,U.face,U.addDate,"+
  313. "U.userWealth,U.userEP,U.userCP,B.hits,B.isTop,B.lockTopic"+
  314. " from bbs.bbs1 B inner join bbs.myuser U on U.username=B.username "+
  315. "where B.boardid="+forumID+" and B.rootid="+rootID+" and B.lockTopic!=2 order by announceid";
  316. rs=dbc.executeQuery(sql);
  317. //if(rs.last()) forumMSGsNum=rs.getRow();
  318. forumMSGsNum = 0 ;
  319. while(rs.next())
  320. {
  321. forumMSGsNum  ++ ;
  322. }
  323. rs=dbc.executeQuery(sql);
  324. int t = 1 ;
  325. if(t<start)
  326. {
  327. while(rs.next())
  328. {
  329. if(t==start)break;
  330. t++;
  331. }
  332. }
  333. //rs.absolute(start);
  334. int i=0;
  335. Vector forumMSGs=new Vector();
  336. while(rs.next())
  337. {
  338. ForumMSG theMSG=new ForumMSG();
  339. theMSG.setAnnounceID(rs.getInt(1));
  340. theMSG.setForumID(rs.getInt(2));
  341. theMSG.setUserName(rs.getString(3));
  342. theMSG.setTopic(rs.getString(4));
  343. theMSG.setDateAndTime(rs.getString(5));
  344. theMSG.setBody(rs.getString(6));
  345. theMSG.setExpression(rs.getString(7));
  346. theMSG.setUserIP(rs.getString(8));
  347. theMSG.setRootID(rs.getInt(9));
  348. theMSG.setSignFlag(rs.getInt(10));
  349. theMSG.setIsBest(rs.getInt(11));
  350. theMSG.setIsVote(rs.getInt(12));
  351. theMSG.setIsTop(rs.getInt(29));
  352. theMSG.setLockTopic(rs.getInt(30));
  353. theMSG.setHits(rs.getInt(28)+1);
  354. User msgUser=new User();
  355. msgUser.setUserName(rs.getString(13));
  356. msgUser.setUserEmail(rs.getString(14));
  357. msgUser.setHomePage(rs.getString(15));
  358. msgUser.setOicq(rs.getString(16));
  359. msgUser.setSign(rs.getString(17));
  360. msgUser.setUserClass(rs.getInt(18));
  361. msgUser.setTitle(rs.getString(19));
  362. msgUser.setWidth(rs.getInt(20));
  363. msgUser.setHeight(rs.getInt(21));
  364. msgUser.setArticle(rs.getInt(22));
  365. msgUser.setFace(rs.getString(23));
  366. msgUser.setAddDate(rs.getString(24));
  367. msgUser.setUserWealth(rs.getInt(25));
  368. msgUser.setUserEP(rs.getInt(26));
  369. msgUser.setUserCP(rs.getInt(27));
  370. theMSG.setUser(msgUser);
  371. forumMSGs.add(theMSG);
  372. i++;
  373. if(i==perPage)
  374. break;
  375. }
  376. sql="update bbs.bbs1 set hits=hits+1 where announceID="+announceID;
  377. dbc.executeUpdate(sql);
  378. dbc.close();
  379. return forumMSGs;
  380. }
  381. catch(SQLException se)
  382. {
  383. se.printStackTrace();
  384. throw new ForumMSGNotFoundException();
  385. }
  386. catch(Exception e)
  387. {
  388. e.printStackTrace();
  389. throw new ForumMSGNotFoundException();
  390. }
  391. }
  392. public static Vector getForumTextMSGs  (HttpServletRequest request) throws ForumMSGNotFoundException{
  393. try{
  394. int forumID,rootID;
  395. try{
  396. forumID=ParamUtil.getInt(request,"forumID");
  397. rootID=ParamUtil.getInt(request,"rootID");
  398. }
  399. catch(Exception e){
  400. throw new Exception("对不起,没有发现帖子!");
  401. }
  402. //DBConnect dbc=new DBConnect(2,0);
  403. DBConnect dbc=new DBConnect();
  404. String sql="Select UserName,Topic,dateandtime,body from bbs.bbs1 where boardid="+forumID+" and rootid="+rootID+" order by announceid";
  405. ResultSet rs=dbc.executeQuery(sql);
  406. /*if(!rs.next())
  407. throw new Exception("对不起没有发现帖子!");*/
  408. Vector forumMSGs=new Vector();
  409. while(rs.next())
  410. {
  411. ForumMSG theMSG=new ForumMSG();
  412. //theMSG.setAnnounceID(rs.getInt(1));
  413. //theMSG.setForumID(rs.getInt(2));
  414. theMSG.setUserName(rs.getString(1));
  415. theMSG.setTopic(rs.getString(2));
  416. theMSG.setDateAndTime(rs.getString(3));
  417. theMSG.setBody(rs.getString(4));
  418. /*theMSG.setExpression(rs.getString(7));
  419. theMSG.setUserIP(rs.getString(8));
  420. theMSG.setRootID(rs.getInt(9));
  421. theMSG.setSignFlag(rs.getInt(10));
  422. theMSG.setIsBest(rs.getInt(11));
  423. theMSG.setIsVote(rs.getInt(12));
  424. theMSG.setIsTop(rs.getInt(29));
  425. theMSG.setLockTopic(rs.getInt(30));
  426. theMSG.setHits(rs.getInt(28)+1);
  427. User msgUser=new User();
  428. msgUser.setUserName(rs.getString(13));
  429. msgUser.setUserEmail(rs.getString(14));
  430. msgUser.setHomePage(rs.getString(15));
  431. msgUser.setOicq(rs.getString(16));
  432. msgUser.setSign(rs.getString(17));
  433. msgUser.setUserClass(rs.getInt(18));
  434. msgUser.setTitle(rs.getString(19));
  435. msgUser.setWidth(rs.getInt(20));
  436. msgUser.setHeight(rs.getInt(21));
  437. msgUser.setArticle(rs.getInt(22));
  438. msgUser.setFace(rs.getString(23));
  439. msgUser.setAddDate(rs.getString(24));
  440. msgUser.setUserWealth(rs.getInt(25));
  441. msgUser.setUserEP(rs.getInt(26));
  442. msgUser.setUserCP(rs.getInt(27));
  443. theMSG.setUser(msgUser);*/
  444. forumMSGs.add(theMSG);
  445. }
  446. dbc.close();
  447. return forumMSGs;
  448. }
  449. catch(Exception e)
  450. {
  451. e.printStackTrace();
  452. throw new ForumMSGNotFoundException(e.getMessage());
  453. }
  454. }
  455. public int getForumMSGsNum(){
  456. return this.forumMSGsNum;
  457. }
  458. public int getForumTopicNum(){
  459. return forumTopicNum;
  460. }
  461. public int getForumID(){
  462. return forumID;
  463. }
  464. public String getForumType(){
  465. return forumType;
  466. }
  467. public int getForumClass(){
  468. return forumClass;
  469. }
  470. public String getReadMe(){
  471. return readMe;
  472. }
  473. public String getForumMaster(){
  474. return forumMaster;
  475. }
  476. public int getLockForum(){
  477. return lockForum;
  478. }
  479. public int getForumSkin(){
  480. return forumSkin;
  481. }
  482. public String getTableBack(){
  483. return tableBack;
  484. }
  485. public String getTableTitle(){
  486. return tableTitle;
  487. }
  488. public String getTableBody(){
  489. return tableBody;
  490. }
  491. public String getATableBody(){
  492. return aTableBody;
  493. }
  494. public String getTableFont(){
  495. return tableFont;
  496. }
  497. public String getTableContent(){
  498. return tableContent;
  499. }
  500. public String getAlertFont(){
  501. return alertFont;
  502. }
  503. public String getLastPostUser(){
  504. return lastPostUser;
  505. }
  506. public String getLastPostTime(){
  507. return lastPostTime;
  508. }
  509. public int getLastBbsNum(){
  510. return lastBbsNum;
  511. }
  512. public int getLastTopicNum(){
  513. return lastTopicNum;
  514. }
  515. public boolean getStrAllowForumCode(){
  516. if(strAllowForumCode==1)
  517. return true;
  518. else
  519. return false;
  520. }
  521. public boolean getStrAllowHTML(){
  522. if(strAllowHTML==1)
  523. return true;
  524. else
  525. return false;
  526. }
  527. public boolean getStrIMGInPosts(){
  528. if(strIMGInPosts==1)
  529. return true;
  530. else
  531. return false;
  532. }
  533. public boolean getStrIcons(){
  534. if(strIcons==1)
  535. return true;
  536. else
  537. return false;
  538. }
  539. public boolean getStrFlash(){
  540. if(strFlash==1)
  541. return true;
  542. else
  543. return false;
  544. }
  545. public String getForumLogo(){
  546. return forumLogo;
  547. }
  548. public String getIndexIMG(){
  549. return indexIMG;
  550. }
  551. public int getLastRootID(){
  552. return lastRootID;
  553. }
  554. public String getLastTopic(){
  555. return StringUtils.escapeHTMLTags(this.lastTopic);
  556. }
  557. public int getTodayNum(){
  558. return todayNum;
  559. }
  560. public String getForumUser(){
  561. return forumUser;
  562. }
  563. public Vector getForumOLUsers(){
  564. return forumOLUsers;
  565. }
  566. public int getForumOLGuestUsersNum(){
  567. return this.forumOLGuestUsersNum;
  568. }
  569. public int getForumOLMemberUsersNum(){
  570. return this.forumOLMemberUsersNum;
  571. }
  572. public int getForumsOLUsersNum(){
  573. return this.forumsOLUsersNum;
  574. }
  575. public String getForumIMG(String lastlogin){
  576. String strIMG="";
  577. switch(this.getForumSkin())
  578. {
  579. case 1:
  580. if(Format.compareTo(lastlogin,this.lastPostTime))
  581. strIMG="<img src=pic/foldernew.gif width=13 height=16 alt=常规论坛,有新帖子>";
  582. else
  583. strIMG="<img src=pic/ifolder.gif width=13 height=16 alt=常规论坛,无新帖子>";
  584. break;
  585. case 2:
  586. if(Format.compareTo(lastlogin,this.lastPostTime))
  587. strIMG="<img src=pic/folderallnew.gif width=13 height=16 alt=开放论坛,有新帖子>";
  588. else
  589. strIMG="<img src=pic/folderall.gif width=13 height=16 alt=开放论坛,无新帖子>";
  590. break;
  591. case 3:
  592. if(Format.compareTo(lastlogin,this.lastPostTime))
  593. strIMG="<img src=pic/follownew.gif width=13 height=16 alt=评论论坛,有新帖子>";
  594. else
  595. strIMG="<img src=pic/follow.gif width=13 height=16 alt=评论论坛,无新帖子>";
  596. break;
  597. case 4:
  598. if(Format.compareTo(lastlogin,this.lastPostTime))
  599. strIMG="<img src=pic/jinghua.gif width=13 height=16 alt=精华区,有新帖子>";
  600. else
  601. strIMG="<img src=pic/jinghua.gif width=13 height=16 alt=精华区,无新帖子>";
  602. break;
  603. case 5:
  604. if(Format.compareTo(lastlogin,this.lastPostTime))
  605. strIMG="<img src=pic/lock_l.gif width=13 height=16 alt=认证论坛,有新帖子>";
  606. else
  607. strIMG="<img src=pic/lock_b.gif width=13 height=16 alt=认证论坛,无新帖子>";
  608. break;
  609. case 6:
  610. if(Format.compareTo(lastlogin,this.lastPostTime))
  611. strIMG="<img src=pic/foldernew.gif width=13 height=16 alt=正规论坛,有新帖子>";
  612. else
  613. strIMG="<img src=pic/ifolder.gif width=13 height=16 alt=正规论坛,无新帖子>";
  614. break;
  615. default:
  616. }
  617. return strIMG;
  618. }
  619. public String authorSaveMSG(HttpServletRequest request,HttpServletResponse response) throws Exception{
  620. String userName=ParamUtil.getString(request,"userName","");
  621. String userPassword=ParamUtil.getString(request,"userPassword","");
  622. String sql="";
  623. String char_changed = "[align=right][此贴子已经被作者于"+Format.getDateTime()+"编辑过][/align]";
  624.          try{
  625.          User tempUser=new User(userName,userPassword,4);
  626. DBConnect dbc=new DBConnect();
  627. ResultSet rs;
  628.          int forumID=ParamUtil.getInt(request,"forumID");
  629. int announceID=ParamUtil.getInt(request,"announceID");
  630. int rootID=ParamUtil.getInt(request,"rootID");
  631. dbc.prepareStatement("select * from bbs.bbs1 where announceID=? and rootID=? and userName=?");
  632. dbc.setInt(1,announceID);
  633. dbc.setInt(2,rootID);
  634. dbc.setBytes(3,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  635. rs=dbc.executeQuery();
  636. if(!rs.next())
  637. throw new Exception("<li>对不起,您没有权利编辑此帖子!</li>");
  638.          String subject=ParamUtil.getString(request,"subject","");
  639.          String content=ParamUtil.getString(request,"content","")+"nnnn"+char_changed;
  640.          String expression=ParamUtil.getString(request,"expression","");
  641.          int signFlag=ParamUtil.getInt(request,"signFlag",1);
  642.          int emailFlag=ParamUtil.getInt(request,"emailFlag",0);
  643.          if(subject.equals("")) throw new Exception("没有主体文字");
  644. sql="update bbs.bbs1 set Topic=?,Body=?,DateAndTime=getdate(),length=?,ip=?,expression=?,signflag=?,emailflag=? where announceID=?";
  645. dbc.prepareStatement(sql);
  646. dbc.setBytes(1,(new String(subject.getBytes("ISO-8859-1"),"GBK")).getBytes());
  647. dbc.setBytes(2,(new String(content.getBytes("ISO-8859-1"),"GBK")).getBytes());
  648. dbc.setInt(3,content.length());
  649. dbc.setString(4,request.getRemoteAddr());
  650. dbc.setString(5,expression);
  651. dbc.setInt(6,signFlag);
  652. dbc.setInt(7,emailFlag);
  653. dbc.setInt(8,announceID);
  654. dbc.executeUpdate();
  655. dbc.close();
  656. return "dispbbs.jsp?forumID="+forumID+"&rootID="+rootID+"&announceID="+announceID+"#"+announceID;
  657.    }
  658.    catch(UserNotFoundException e){
  659.    throw new Exception("没有发现用户");
  660.    }
  661.    catch(Exception e){
  662.    e.printStackTrace();
  663.    throw new Exception("<Br>"+"<li>"+e.getMessage());
  664. }
  665. }
  666. public String masterSaveMSG(HttpServletRequest request,HttpServletResponse response) throws Exception{
  667. String userName=GCookie.getCookieValue(request,"UJBBUName","");
  668. //String userPassword=ParamUtil.getString(request,"userPassword","");
  669. String sql="";
  670. String char_changed = "[align=right][此贴子已经被"+userName+"于"+Format.getDateTime()+"编辑过][/align]";
  671.          try{
  672.          User tempUser=SkinUtil.checkUser(request,response,4);
  673. DBConnect dbc=new DBConnect();
  674. ResultSet rs;
  675.          int forumID=ParamUtil.getInt(request,"forumID");
  676. int announceID=ParamUtil.getInt(request,"announceID");
  677. int rootID=ParamUtil.getInt(request,"rootID");
  678.          String subject=ParamUtil.getString(request,"subject","");
  679.          String content=ParamUtil.getString(request,"content","")+"nnnn"+char_changed;
  680.          String expression=ParamUtil.getString(request,"expression","");
  681.          int signFlag=ParamUtil.getInt(request,"signFlag",1);
  682.          int emailFlag=ParamUtil.getInt(request,"emailFlag",0);
  683.          if(subject.equals("")) throw new Exception("没有主体文字");
  684. sql="update bbs.bbs1 set Topic=?,Body=?,DateAndTime=getdate(),length=?,ip=?,expression=?,signflag=?,emailflag=? where announceID=?";
  685. dbc.prepareStatement(sql);
  686. dbc.setBytes(1,(new String(subject.getBytes("ISO-8859-1"),"GBK")).getBytes());
  687. dbc.setBytes(2,(new String(content.getBytes("ISO-8859-1"),"GBK")).getBytes());
  688. dbc.setInt(3,content.length());
  689. dbc.setString(4,request.getRemoteAddr());
  690. dbc.setString(5,expression);
  691. dbc.setInt(6,signFlag);
  692. dbc.setInt(7,emailFlag);
  693. dbc.setInt(8,announceID);
  694. dbc.executeUpdate();
  695. dbc.close();
  696. return "dispbbs.jsp?forumID="+forumID+"&rootID="+rootID+"&announceID="+announceID+"#"+announceID;
  697.    }
  698.    catch(UserNotFoundException e){
  699.    throw new Exception("没有发现用户");
  700.    }
  701.    catch(Exception e){
  702.    e.printStackTrace();
  703.    throw new Exception("<Br>"+"<li>"+e.getMessage());
  704. }
  705. }
  706. public String addTopic(HttpServletRequest request,HttpServletResponse response) throws Exception{
  707. String userName=ParamUtil.getString(request,"userName","");
  708. String userPassword=ParamUtil.getString(request,"userPassword","");
  709. String sql="";
  710.          try{
  711.          //SkinUtil.userLogin(request,response,2);
  712.          User tempUser=new User(userName,userPassword,2);
  713. DBConnect dbc=new DBConnect();
  714.          int forumID=ParamUtil.getInt(request,"forumID",1);
  715.          String subject=ParamUtil.getString(request,"subject","");
  716.          String content=ParamUtil.getString(request,"content","");
  717.          String expression=ParamUtil.getString(request,"expression","");
  718. int isVote=ParamUtil.getInt(request,"isVote",0);
  719.          int signFlag=ParamUtil.getInt(request,"signFlag",1);
  720.          int emailFlag=ParamUtil.getInt(request,"emailFlag",0);
  721.          if(subject.equals("")) throw new Exception("没有主体文字");
  722. sql="insert into bbs.bbs1(Boardid,ParentID,Child,username,topic,body,DateAndTime,hits,length,rootid,layer,orders,ip,Expression,locktopic,signflag,emailflag,istop,isbest,isvote,times) values "+
  723. "("+
  724. forumID+",0,0,?,?,?,'"+
  725. Format.getDateTime()+"',0,"+
  726. content.length()+",0,1,0,'"+request.getRemoteAddr()+"','"+
  727. expression+".gif',0,"+signFlag+","+emailFlag+",0,0,"+isVote+",0)";
  728. dbc.prepareStatement(sql);
  729. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  730. dbc.setBytes(2,(new String(subject.getBytes("ISO-8859-1"),"GBK")).getBytes());
  731. dbc.setBytes(3,(new String(content.getBytes("ISO-8859-1"),"GBK")).getBytes());
  732. dbc.executeUpdate();
  733. ResultSet rs=dbc.executeQuery("select announceid from bbs.bbs1 order by announceid desc");
  734.          rs.next();
  735.          int announceID=rs.getInt(1);
  736. voteID=announceID;
  737. sql="update bbs.bbs1 set rootid="+announceID+",times="+announceID+" where announceid="+announceID;
  738. dbc.executeUpdate(sql);
  739. String shortTopic="";
  740. if ("".equals(subject))
  741. if(content.length()>21)
  742. shortTopic=content.substring(0,20);
  743. else
  744. shortTopic=content;
  745. else
  746. if(subject.length()>21)
  747. shortTopic=subject.substring(0,20);
  748. else
  749. shortTopic=subject;
  750. ResultSet tmprs=dbc.executeQuery("Select count(announceid) from bbs.bbs1 Where day(dateandtime)-day(getdate())=0 and boardid="+forumID);
  751.      tmprs.next();
  752.      int forumToday=tmprs.getInt(1);
  753.      tmprs=null;
  754. sql="update bbs.board set lastpostuser=?,lastposttime='"+Format.getDateTime()+"',lastbbsnum=lastbbsnum+1,lasttopicnum=lasttopicnum+1,todaynum="+forumToday+",lastrootid="+announceID+",lasttopic=? where  boardid="+forumID;
  755. dbc.clearParameters();
  756. dbc.prepareStatement(sql);
  757. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  758. dbc.setBytes(2,(new String(shortTopic.getBytes("ISO-8859-1"),"GBK")).getBytes());
  759. dbc.executeUpdate();
  760. tmprs=dbc.executeQuery("Select count(announceid) from bbs.bbs1 Where day(dateandtime)-day(getdate())=0");
  761.      tmprs.next();
  762.      int allTodays=tmprs.getInt(1);
  763. dbc.executeUpdate("update bbs.config set topicnum=topicnum+1,bbsnum=bbsnum+1,todayNum="+allTodays);
  764. dbc.close();
  765. ForumPropertiesManager.resetManager();
  766. return "dispbbs.jsp?forumID="+forumID+"&rootID="+announceID+"&announceID="+announceID;
  767.    }
  768.    catch(UserNotFoundException e){
  769.    throw new Exception("没有发现用户");
  770.    }
  771.    catch(Exception e){
  772.    e.printStackTrace();
  773.    throw new Exception("<Br>"+"<li>数据库操作失败,请以后再试");
  774. }
  775. }
  776. public String addMSG(HttpServletRequest request,HttpServletResponse response)throws UserNotFoundException ,Exception{
  777. //try{
  778. String userName=ParamUtil.getString(request,"userName","");
  779. String userPassword=ParamUtil.getString(request,"userPassword","");
  780. //SkinUtil.userLogin(request,response,3);
  781. User tempUser=new User(userName,userPassword,3);
  782.          DBConnect dbc=new DBConnect();
  783.          int forumID=this.forumID;
  784.          String subject=ParamUtil.getString(request,"subject","");
  785.          String content=ParamUtil.getString(request,"content","");
  786.          String expression=ParamUtil.getString(request,"expression","face7.gif");
  787. String sql="";
  788. int rootID=ParamUtil.getInt(request,"rootID");
  789. ResultSet rs;
  790. dbc.prepareStatement("select locktopic from bbs.bbs1 where announceid="+rootID);
  791. rs=dbc.executeQuery();
  792. if(!rs.next()){
  793. dbc.close();
  794. throw new Exception("<li>对不起,没有发现此主题!</li>");
  795. }
  796. else{
  797. //rs.next();
  798. if(rs.getInt(1)==1||rs.getInt(1)==2){
  799. dbc.close();
  800. throw new Exception("对不起,此帖子已经锁定,您不能回复!");
  801. }
  802. }
  803. int iLayer,iOrders;
  804.          int signFlag=ParamUtil.getInt(request,"signFlag",1);
  805.          int emailFlag=ParamUtil.getInt(request,"emailFlag",0);
  806. int parentID=ParamUtil.getInt(request,"parentID",rootID);
  807. sql="select layer,orders from bbs.bbs1 where announceid="+parentID;
  808. rs=dbc.executeQuery(sql);
  809. if(rs.next()){
  810. if(rs.getString(1)!=null)
  811. iLayer=0;
  812. else
  813. iLayer=rs.getInt(1);
  814. if(rs.getString(2)!=null)
  815. iOrders=0;
  816. else
  817. iOrders=rs.getInt(2);
  818. }
  819. else{
  820. iLayer=0;
  821. iOrders=0;
  822. }
  823. rs.close();
  824. if (rootID!=0){
  825. iLayer=iLayer+1;
  826. dbc.executeUpdate("update bbs.bbs1 set orders=orders+1 where rootid="+rootID+" and orders>"+iOrders);
  827. iOrders=iOrders+1;
  828.       }
  829.          sql="insert into bbs.bbs1(Boardid,ParentID,Child,username,topic,body,DateAndTime,hits,length,rootid,layer,orders,ip,Expression,locktopic,signflag,emailflag,istop,isbest,isvote,times) values "+
  830. "("+
  831. forumID+","+parentID+",0,"+
  832. "?,?,?,'"+
  833. Format.getDateTime()+"',0,"+
  834. content.length()+","+rootID+","+iLayer+","+iOrders+",'"+request.getRemoteAddr()+"','"+
  835. expression+"',0,"+signFlag+","+emailFlag+",0,0,0,0)";
  836. dbc.prepareStatement(sql);
  837. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  838. dbc.setBytes(2,(new String(subject.getBytes("ISO-8859-1"),"GBK")).getBytes());
  839. dbc.setBytes(3,(new String(content.getBytes("ISO-8859-1"),"GBK")).getBytes());
  840. dbc.executeUpdate();
  841. rs=dbc.executeQuery("select announceid from bbs.bbs1 order by announceid desc");
  842.          rs.next();
  843.          int announceID=rs.getInt(1);
  844. sql="update bbs.bbs1 set child=child+1,times="+announceID+" where rootID="+rootID;
  845.            dbc.executeUpdate(sql);
  846.            String shortTopic="";
  847.            if ("".equals(subject))
  848. if(content.length()>21)
  849. shortTopic=content.substring(0,20);
  850. else
  851. shortTopic=content;
  852. else
  853. if(subject.length()>21)
  854. shortTopic=subject.substring(0,20);
  855. else
  856. shortTopic=subject;
  857. ResultSet tmprs=dbc.executeQuery("Select count(announceid) from bbs.bbs1 Where day(dateandtime)-day(getdate())=0 and boardid="+forumID);
  858.      tmprs.next();
  859.      int forumToday=tmprs.getInt(1);
  860.      tmprs=null;
  861. sql="update bbs.board set lastpostuser=?,lastposttime='"+Format.getDateTime()+"',lastbbsnum=lastbbsnum+1,todaynum="+forumToday+",lastrootid="+rootID+",lasttopic=? where  boardid="+forumID;
  862. dbc.clearParameters();
  863. dbc.prepareStatement(sql);
  864. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  865. dbc.setBytes(2,(new String(shortTopic.getBytes("ISO-8859-1"),"GBK")).getBytes());
  866. dbc.executeUpdate();
  867. tmprs=dbc.executeQuery("Select count(announceid) from bbs.bbs1 Where day(dateandtime)-day(getdate())=0");
  868.      tmprs.next();
  869.      int allTodays=tmprs.getInt(1);
  870. dbc.executeUpdate("update bbs.config set bbsnum=bbsnum+1,todayNum="+allTodays);
  871. dbc.close();
  872. ForumPropertiesManager.resetManager();
  873. return "dispbbs.jsp?forumID="+forumID+"&rootID="+rootID+"&announceID="+announceID+"#"+announceID;
  874. }
  875. public String addVote(HttpServletRequest request,HttpServletResponse response) throws Exception{
  876. try{
  877. String vote=ParamUtil.getString(request,"vote");
  878. String userName=ParamUtil.getString(request,"userName","");
  879. if(vote==null) throw new Exception("<li>请您输入选举内容</li>");
  880. String voteNum="";
  881. String reg="(r|n)";
  882. String [] tempString=vote.split(reg);
  883. for(int i=0;i<tempString.length;i++)
  884. if(!tempString[i].trim().equals(""))
  885. if(i==tempString.length-1)
  886. voteNum+="0";
  887. else
  888. voteNum+="0|";
  889. int voteType=ParamUtil.getInt(request,"voteType",0);
  890. String url=this.addTopic(request,response);
  891. DBConnect dbc=new DBConnect("insert into bbs.vote(announceID,vote,voteNum,voteType,voteUser) values(?,?,?,?,?)");
  892. dbc.setInt(1,voteID);
  893. dbc.setBytes(2,(new String(vote.getBytes("ISO-8859-1"),"GBK")).getBytes());
  894. dbc.setString(3,voteNum);
  895. dbc.setInt(4,voteType);
  896. dbc.setBytes(5,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  897. dbc.executeUpdate();
  898. dbc.close();
  899. return url;
  900. }
  901. catch(Exception e){
  902. e.printStackTrace();
  903. throw new Exception(e.getMessage());
  904. }
  905. }
  906. public ForumVote getForumVote(int announceID) throws Exception{
  907. DBConnect dbc=new DBConnect("select * from bbs.vote where announceID=?");
  908. dbc.setInt(1,announceID);
  909. ResultSet rs=dbc.executeQuery();
  910. if(rs.next()){
  911. ForumVote forumVote=new ForumVote();
  912. forumVote.setVoteID(rs.getInt(1));
  913. forumVote.setAnnounceID(rs.getInt(2));
  914. forumVote.setVote(rs.getString(3));
  915. forumVote.setVoteNum(rs.getString(4));
  916. forumVote.setVoteUser(rs.getString(5));
  917. forumVote.setVoteType(rs.getInt(6));
  918. return forumVote;
  919. }
  920. else
  921. throw new Exception("<li>错误,对不起,没有发现投票!</li>");
  922. }
  923. public String addVoteNum(HttpServletRequest request,HttpServletResponse response) throws Exception {
  924. String userName=GCookie.getCookieValue(request,"UJBBUName","");
  925. String userPassword=GCookie.getCookieValue(request,"UJBBUPSW","");
  926. User tempUser=new User(userName,userPassword,1);
  927. int announceID=ParamUtil.getInt(request,"announceID");
  928. int forumID=ParamUtil.getInt(request,"forumID");
  929. ForumVote theVote=this.getForumVote(announceID);
  930. String voteNum="";
  931. int [] voteNumS=theVote.getVoteNumS();
  932. if(theVote.getUserSign(userName))
  933. throw new Exception("<li>对不起,您已经投票了!</li>");
  934. else{
  935. if(theVote.getVoteType()==0){
  936. int postID=ParamUtil.getInt(request,"postVote");
  937. voteNumS[postID]++;
  938. }
  939. else{
  940. for(int i=0;i<voteNumS.length;i++){
  941. if(ParamUtil.getString(request,"postVote_"+(i))!=null)
  942. voteNumS[i]++;
  943. }
  944. }
  945. for(int i=0;i<voteNumS.length;i++)
  946. if(i==voteNumS.length-1)
  947. voteNum+=Integer.toString(voteNumS[i]);
  948. else
  949. voteNum+=Integer.toString(voteNumS[i])+"|";
  950. }
  951. DBConnect dbc=new DBConnect("select * from bbs.vote where announceID="+announceID);
  952. ResultSet rs=dbc.executeQuery();
  953. rs.next();
  954. String voteUser=rs.getString(5);
  955. voteUser+="|"+userName;
  956. dbc.prepareStatement("update bbs.vote set voteNum='"+voteNum+"',voteUser=? where announceID="+announceID);
  957. dbc.setBytes(1,(new String(voteUser.getBytes("ISO-8859-1"),"GBK")).getBytes());
  958. dbc.executeUpdate();
  959. return "dispbbs.jsp?forumID="+forumID+"&rootID="+announceID+"&announceID="+announceID;
  960. }
  961. }