01: package forum;
02:
03: import java.io.*;
04: import javax.servlet.*;
05: import javax.servlet.http.*;
06: import java.util.*;
07:
08: public class ChangeMessage extends HttpServlet {
09:
10: DBConnectie db = new DBConnectie(Variable.getDb(), Variable
11: .getDbLogin(), Variable.getDbPassword());
12:
13: public void doPost(HttpServletRequest request,
14: HttpServletResponse response) throws ServletException,
15: IOException {
16:
17: PrintWriter out = response.getWriter();
18:
19: try {
20:
21: HttpSession session = request.getSession(true);
22: String sessionUsername = (String) session
23: .getAttribute("username");
24: String sessionType = (String) session.getAttribute("type");
25:
26: String forum_id = request.getParameter("forum_id");
27: String start = request.getParameter("start");
28: String reqThread_id = request.getParameter("thread_id");
29: String reqReply_id = request.getParameter("reply_id");
30: String message = request.getParameter("message");
31: message = Filter.filterAll(message);
32:
33: int changeDifference = (((100 * message.length()) / Utilities
34: .getMessageLength(forum_id, reqThread_id,
35: reqReply_id)));
36:
37: java.util.Date date_time = new java.util.Date();
38:
39: message += "<!-- begin --!><BR><BR><I>Edited by "
40: + sessionUsername + " - " + date_time + " ("
41: + changeDifference + "%)</I><!-- end --!>";
42:
43: db.connect();
44:
45: if (sessionType.equals("Admin")) {
46: db.query("UPDATE forum_message " + "SET message =\""
47: + message + "\"" + "WHERE forum_id=\""
48: + forum_id + "\" AND thread_id =\""
49: + reqThread_id + "\" AND reply_id=\""
50: + reqReply_id + "\"");
51: } else {
52: db.query("UPDATE forum_message " + "SET message =\""
53: + message + "\"" + "WHERE forum_id=\""
54: + forum_id + "\" AND thread_id =\""
55: + reqThread_id + "\" AND reply_id=\""
56: + reqReply_id + "\" AND user=\""
57: + sessionUsername + "\"");
58: }
59:
60: response.sendRedirect(Variable.getForumPath()
61: + "index.jsp?page=message&forum_id=" + forum_id
62: + "&thread_id=" + reqThread_id + "&start=" + start);
63:
64: db.close();
65: } catch (Exception e) {
66: out.println(e);
67: }
68: }
69: }
|