Join script should rule out retired usernames
[bpt/portal.git] / roll.mlt
1 <% @header [("title", ["Roll call!"])];
2
3 val you = Init.getUserId ();
4
5 ref viewingCall = NONE;
6 ref showNormal = true;
7
8 if $"cmd" = "respond" then
9 showNormal := false;
10
11 val rol = Web.stoi ($"rol");
12 val code = $"code";
13 val rc = Roll.lookupEntry (rol, you);
14
15 if code = #code rc then
16 Roll.respond (rol, you);
17 %><h3>Your response has been saved. Thank you!</h3><%
18 else
19 %><h3>Incorrect code!</h3><%
20 end
21 elseif $"cmd" = "add" then
22 Group.requireGroupNum 0;
23 val title = $"title";
24 val msg = $"msg";
25 if title = "" then
26 %><h3>Your roll call must have a title.</h3><%
27 else
28 val id = Roll.addRollCall (title, msg);
29 viewingCall := SOME id;
30 %><h3>Roll call added!</h3><%
31 end
32
33 elseif $"mod" <> "" then
34 Group.requireGroupNum 0;
35 showNormal := false;
36 val rc = Roll.lookupRollCall (Web.stoi ($"mod")) %>
37 <h3>Modify roll call</h3>
38
39 <form action="roll" method="post">
40 <input type="hidden" name="id" value="<% $"mod" %>">
41 <table class="blanks">
42 <tr> <td>Title:</td> <td><input name="title" value="<% Web.html (#title rc) %>"></td> </tr>
43 <tr> <td>Message:</td> <td><textarea name="msg" wrap="soft" rows="5" cols="80"><% Web.html (#msg rc) %></textarea></td> </tr>
44 <tr> <td><input type="submit" name="cmd" value="Save"></td> </tr>
45 </table>
46 </form>
47
48 <% elseif $"cmd" = "Save" then
49 Group.requireGroupNum 0;
50 val rc = Roll.lookupRollCall (Web.stoi ($"id"));
51
52 val title = $"title";
53 val msg = $"msg";
54 if title = "" then
55 %><h3>Your rol call must have a title.</h3><%
56 else
57 Roll.modRollCall {rc with title = title, msg = msg};
58 viewingCall := SOME (#id rc);
59 %><h3>Roll call saved.</h3><%
60 end
61
62 elseif $"del" <> "" then
63 Group.requireGroupNum 0;
64 showNormal := false;
65 val rc = Roll.lookupRollCall (Web.stoi ($"del")) %>
66 <h3>Are you sure you want to delete roll call "<a href="roll?view=<% #id rc %>"><% Web.html (#title rc) %></a>"?</h3>
67 <a href="roll?del2=<% $"del" %>">Yes, delete <% Web.html (#title rc) %>!</a>
68
69 <% elseif $"del2" <> "" then
70 Group.requireGroupNum 0;
71 val rc = Roll.lookupRollCall (Web.stoi ($"del2"));
72 Roll.deleteRollCall (Web.stoi ($"del2")) %>
73 <h3><% Web.html (#title rc) %> deleted!</h3>
74
75 <% elseif $"cmd" = "mailall" then
76 Group.requireGroupNum 0;
77 showNormal := false;
78 ref first = true %>
79
80 <a href="mailto:<% foreach uname in Roll.activeUsernames () do
81 if first then
82 first := false
83 else
84 %>,<%
85 end
86 uname; Init.emailSuffix
87 end %>">Mail everyone!</a>
88
89 <% elseif $"view" <> "" then
90 Group.requireGroupNum 0;
91 val id = Web.stoi ($"view");
92 viewingCall := SOME id
93 end;
94
95 if showNormal then
96 Group.requireGroupNum 0;
97
98 switch viewingCall of
99 NONE => %>
100 <h3>Existing roll calls</h3>
101
102 <% foreach rc in Roll.listRollCalls () do %>
103 <li> <a href="roll?view=<% #id rc %>"><% Web.html (#title rc) %></a> (<% #started rc %>)</li>
104 <% end %>
105
106 <h3>New roll call</h3>
107
108 <form action="roll" method="post">
109 <input type="hidden" name="cmd" value="add">
110 <table class="blanks">
111 <tr> <td>Title:</td> <td><input name="title"></td> </tr>
112 <tr> <td>Message:</td> <td><textarea name="msg" wrap="soft" rows="5" cols="80"></textarea></td> </tr>
113 <tr> <td><input type="submit" value="Create"></td> </tr>
114 </table>
115 </form>
116
117 <a href="roll?cmd=mailall">Mail everyone! (provides mailto: link)</a>
118
119 <% | SOME id =>
120 val rc = Roll.lookupRollCall id %>
121 <h3>Roll call "<% Web.html (#title rc) %>"</h3>
122 <table border="0" class="blanks">
123 <tr> <td>Started:</td> <td><% #started rc %></td> </tr>
124 <tr> <td>Message:</td> <td><% Web.htmlNl (#msg rc) %></td> </tr>
125 </table>
126 [ <a href="roll?mod=<% id %>">Modify</a> | <a href="roll?del=<% id %>">Delete</a> ]<br>
127
128 <% val (didnt, did) = Roll.listEntries id %>
129
130 <h2>Didn't respond yet:</h2>
131 <% foreach (usr, ent) in didnt do %>
132 <li> <a href="user?id=<% #id usr %>"><% Web.html (#name usr) %></a></li>
133 <% end %>
134
135 <h2>Responded:</h2>
136 <% foreach (usr, ent) in did do %>
137 <li> <a href="user?id=<% #id usr %>"><% Web.html (#name usr) %></a> (<%
138 switch #responded ent of SOME st => st end %>)</li>
139 <% end %>
140
141 <% end
142 end %>
143
144 <% @footer[] %>