1 package org.paneris.messageboard.controller;
2
3 import org.paneris.jal.model.RecordSet;
4 import org.paneris.messageboard.model.Board;
5 import org.paneris.user.model.User;
6 import org.paneris.util.SessionUtil;
7 import org.webmacro.Template;
8 import org.webmacro.servlet.HandlerException;
9 import org.webmacro.servlet.PanerisPage;
10 import org.webmacro.servlet.WebContext;
11
12 public class Subscribe extends PanerisPage {
13
14 private static final long serialVersionUID = 1L;
15
16 public Template handle(WebContext context) throws HandlerException {
17 String db = (String) context.getForm("db");
18 String board = (String) context.getForm("board");
19 String subscribe = (String) context.getForm("subscribe");
20 context.put("db",db);
21 String templateName = null;
22
23 if (context.getCGI().getHTTP_REFERER() != null)
24 context.getSession().setAttribute(
25 "SubscribeReturnURL", context.getCGI().getHTTP_REFERER());
26
27 SessionUtil.setReturnURL("SubscribeReturnURL",context);
28 try {
29 templateName = User.checkLoggedIn("controller", this.getClass().getName(), context, " subscribe to a Messageboard.");
30 } catch (Exception e) {
31 throw new HandlerException("Could not get user:" + e.toString());
32 }
33 if (templateName == null) {
34 try {
35 context.put("types", new RecordSet(db,"messageboards_types", "SELECT id, type FROM messageboards_types ORDER BY display_order",new Integer(0)));
36 Board b = new Board(db, new Integer(board));
37 templateName = User.checkLoggedIn("messageboard", b.getFieldValue("name"), context, " subscribe to this Messageboard.");
38 if (templateName == null) {
39 User user = (User) context.getSession().
40 getAttribute(db+"user");
41 if (user == null) {
42 templateName = User.getLoginPage(context, (String) context.getForm("message"));
43 User.setReturnURL(context);
44 } else {
45 context.put("board",b);
46 templateName = (String) context.getForm("wmtemplate");
47 if (templateName == null) templateName = "messageboard/view/Subscribe.wm";
48 if (subscribe.equals("true")) {
49 b.subscribe(user);
50 context.put("subscribe","true");
51 } else {
52 b.unSubscribe(user);
53 }
54 }
55 }
56 } catch (Exception e) {
57 throw new HandlerException("Could not subscribe user: " + e.toString());
58 }
59 }
60
61 try {
62 return (Template) context.getBroker().get("template",templateName);
63 } catch (Exception e) {
64 throw new HandlerException("Could not locate template: " + templateName);
65 }
66 }
67 }