001: package forum;
002:
003: import javax.servlet.*;
004: import javax.servlet.http.*;
005: import java.sql.*;
006: import java.sql.Connection;
007: import java.sql.Statement;
008: import java.sql.ResultSet;
009:
010: public class Utilities {
011:
012: public static String getTopics(String forum_id) {
013:
014: String topics = null;
015: try {
016: DBConnectie db = new DBConnectie(Variable.getDb(), Variable
017: .getDbLogin(), Variable.getDbPassword());
018: db.connect();
019:
020: ResultSet rs = db
021: .selectQuery("SELECT count(*) topics FROM forum_message "
022: + "WHERE forum_id =\""
023: + forum_id
024: + "\" "
025: + "AND reply_id=\"0\"");
026:
027: while (rs.next()) {
028: topics = rs.getString("topics");
029: }
030: db.close();
031: } catch (Exception e) {
032: }
033:
034: return topics;
035: }
036:
037: public static String getforumReplies(String forum_id) {
038:
039: String replies = null;
040: try {
041: DBConnectie db = new DBConnectie(Variable.getDb(), Variable
042: .getDbLogin(), Variable.getDbPassword());
043: db.connect();
044:
045: ResultSet rs = db.selectQuery("SELECT count(*)-"
046: + getTopics(forum_id)
047: + " replies FROM forum_message "
048: + "WHERE forum_id =\"" + forum_id + "\"");
049:
050: while (rs.next()) {
051: replies = rs.getString("replies");
052: }
053: db.close();
054: } catch (Exception e) {
055: }
056:
057: return replies;
058: }
059:
060: public static String getReplies(String forum_id, String thread_id) {
061:
062: String replies = null;
063: try {
064: DBConnectie db = new DBConnectie(Variable.getDb(), Variable
065: .getDbLogin(), Variable.getDbPassword());
066: db.connect();
067:
068: ResultSet rs = db
069: .selectQuery("SELECT count(*)-1 replies FROM forum_message "
070: + "WHERE forum_id=\""
071: + forum_id
072: + "\" AND thread_id =\"" + thread_id + "\"");
073:
074: while (rs.next()) {
075: replies = rs.getString("replies");
076: }
077: db.close();
078: } catch (Exception e) {
079: }
080:
081: return replies;
082: }
083:
084: public static String getMorePages(String replies, String forum_id,
085: String thread_id, boolean pages) {
086:
087: String morePages = "";
088: if (!((Integer.parseInt(replies) + 1) < (Integer
089: .parseInt(Variable.getMessagePerPage()) + 1))) {
090:
091: if (pages) {
092: morePages += " ( ";
093: }
094:
095: for (int i = 0; i < (Integer.parseInt(replies) + 1); i += (Integer
096: .parseInt(Variable.getMessagePerPage()))) {
097: morePages += "<a href=message.jsp?forum_id="
098: + forum_id
099: + "&thread_id="
100: + thread_id
101: + "&start="
102: + i
103: + " class=\"pathBarLink\">"
104: + ((i / (Integer.parseInt(Variable
105: .getMessagePerPage()))) + 1) + "</a> ";
106: }
107: if (pages) {
108: morePages += " )</span>";
109: }
110: }
111: return morePages;
112: }
113:
114: public static String getforumTile(String forum_id) {
115:
116: String forumTitle = null;
117: try {
118: DBConnectie db = new DBConnectie(Variable.getDb(), Variable
119: .getDbLogin(), Variable.getDbPassword());
120: db.connect();
121:
122: ResultSet rs = db
123: .selectQuery("SELECT title FROM forum_forums "
124: + "WHERE forum_id=\"" + forum_id + "\"");
125:
126: while (rs.next()) {
127: forumTitle = rs.getString("title");
128: }
129: db.close();
130: } catch (Exception e) {
131: }
132:
133: return forumTitle;
134: }
135:
136: public static String getThreadTile(String forum_id, String thread_id) {
137:
138: String threadTitle = null;
139: try {
140: DBConnectie db = new DBConnectie(Variable.getDb(), Variable
141: .getDbLogin(), Variable.getDbPassword());
142: db.connect();
143:
144: ResultSet rs = db
145: .selectQuery("SELECT title FROM forum_threads "
146: + "WHERE forum_id=\"" + forum_id + "\" "
147: + "AND thread_id=\"" + thread_id + "\"");
148:
149: while (rs.next()) {
150: threadTitle = rs.getString("title");
151: }
152: db.close();
153: } catch (Exception e) {
154: }
155:
156: return threadTitle;
157: }
158:
159: public static String getforumInfo(String forum_id) {
160:
161: String forumInfo = null;
162: try {
163: DBConnectie db = new DBConnectie(Variable.getDb(), Variable
164: .getDbLogin(), Variable.getDbPassword());
165: db.connect();
166:
167: ResultSet rs = db
168: .selectQuery("SELECT forum_info FROM forum_forums "
169: + "WHERE forum_id=\"" + forum_id + "\"");
170:
171: while (rs.next()) {
172: forumInfo = rs.getString("forum_info");
173: }
174: db.close();
175: } catch (Exception e) {
176: }
177:
178: if (forumInfo.equals(null)) {
179: forumInfo = "";
180: }
181:
182: return forumInfo;
183: }
184:
185: public static String lastPostInfo(String forum_id) {
186:
187: String lastPostInfo = null;
188: String thread_id = null;
189: String title = null;
190: String date_time = null;
191: String user = null;
192:
193: try {
194: DBConnectie db = new DBConnectie(Variable.getDb(), Variable
195: .getDbLogin(), Variable.getDbPassword());
196: db.connect();
197:
198: ResultSet rs = db
199: .selectQuery("SELECT MAX(date_time) date_time FROM forum_message "
200: + "WHERE forum_id=\"" + forum_id + "\"");
201:
202: while (rs.next()) {
203: date_time = rs.getString("date_time");
204: }
205:
206: ResultSet rs2 = db
207: .selectQuery("SELECT thread_id,user FROM forum_message "
208: + "WHERE forum_id=\""
209: + forum_id
210: + "\" "
211: + "AND date_time=\"" + date_time + "\"");
212:
213: while (rs2.next()) {
214: thread_id = rs2.getString("thread_id");
215: user = rs2.getString("user");
216: }
217:
218: ResultSet rs3 = db
219: .selectQuery("SELECT * FROM forum_threads "
220: + "WHERE thread_id=\"" + thread_id + "\" "
221: + "AND forum_id=\"" + forum_id + "\"");
222:
223: while (rs3.next()) {
224: title = rs3.getString("title");
225: }
226:
227: if (date_time == null) {
228: date_time = "No info";
229: }
230: if (user == null) {
231: user = "No info";
232: }
233: if (title == null) {
234: title = "No info";
235: }
236:
237: lastPostInfo = date_time + "<br>In: " + title + "<br>By: "
238: + user;
239:
240: db.close();
241: } catch (Exception e) {
242: }
243:
244: return lastPostInfo;
245: }
246:
247: public static String lastActionInfo(String forum_id,
248: String thread_id) {
249:
250: String lastPostInfo = null;
251: String date_time = null;
252: String user = null;
253:
254: try {
255: DBConnectie db = new DBConnectie(Variable.getDb(), Variable
256: .getDbLogin(), Variable.getDbPassword());
257: db.connect();
258:
259: ResultSet rs = db
260: .selectQuery("SELECT MAX(date_time) date_time FROM forum_message "
261: + "WHERE forum_id=\""
262: + forum_id
263: + "\" "
264: + "AND thread_id=\"" + thread_id + "\"");
265:
266: while (rs.next()) {
267: date_time = rs.getString("date_time");
268: }
269:
270: ResultSet rs2 = db
271: .selectQuery("SELECT user FROM forum_message "
272: + "WHERE forum_id=\"" + forum_id + "\" "
273: + "AND thread_id=\"" + thread_id + "\" "
274: + "AND date_time=\"" + date_time + "\"");
275:
276: while (rs2.next()) {
277: user = rs2.getString("user");
278: }
279:
280: if (date_time == null) {
281: date_time = "No info";
282: }
283: if (user == null) {
284: user = "No info";
285: }
286:
287: lastPostInfo = date_time + "<br>Last post by: " + user;
288:
289: db.close();
290: } catch (Exception e) {
291: }
292:
293: return lastPostInfo;
294: }
295:
296: public static void addView(String forum_id, String thread_id) {
297:
298: try {
299: DBConnectie db = new DBConnectie(Variable.getDb(), Variable
300: .getDbLogin(), Variable.getDbPassword());
301: db.connect();
302:
303: db.query("UPDATE forum_threads SET views = views + 1 "
304: + "WHERE forum_id =\"" + forum_id + "\" "
305: + "AND thread_id=\"" + thread_id + "\"");
306:
307: db.close();
308: } catch (Exception e) {
309: }
310: }
311:
312: public static String getViews(String forum_id, String thread_id) {
313:
314: String views = null;
315: try {
316: DBConnectie db = new DBConnectie(Variable.getDb(), Variable
317: .getDbLogin(), Variable.getDbPassword());
318: db.connect();
319:
320: ResultSet rs = db
321: .selectQuery("SELECT views FROM forum_threads "
322: + "WHERE forum_id=\"" + forum_id + "\" "
323: + "AND thread_id=\"" + thread_id + "\"");
324:
325: while (rs.next()) {
326: views = rs.getString("views");
327: }
328: db.close();
329: } catch (Exception e) {
330: }
331:
332: return views;
333: }
334:
335: public static int getMessageLength(String forum_id,
336: String thread_id, String reply_id) {
337: int messageLength = 0;
338: try {
339: DBConnectie db = new DBConnectie(Variable.getDb(), Variable
340: .getDbLogin(), Variable.getDbPassword());
341: db.connect();
342:
343: ResultSet rs = db
344: .selectQuery("SELECT message FROM forum_message "
345: + "WHERE forum_id=\"" + forum_id + "\" "
346: + "AND thread_id=\"" + thread_id + "\" "
347: + "AND reply_id=\"" + reply_id + "\"");
348:
349: while (rs.next()) {
350: messageLength = rs.getString("message").length();
351: }
352: db.close();
353: } catch (Exception e) {
354: }
355:
356: return messageLength;
357:
358: }
359: }
|