Join script should rule out retired usernames
[bpt/portal.git] / issue.mlt
CommitLineData
1cb3df3f
AC
1<% val catId = Web.stoi ($"cat");
2val cat = Support.lookupCategory catId;
3val admin = Group.inGroupNum (#grp cat);
4val you = Init.getUserId()
5
6ref viewingIssue = NONE;
7
8@header[("title", ["Support: " ^ Web.html (#name cat)])];
9
10ref showNormal = true;
11
12if $"cmd" = "new" then
13 showNormal := false %>
14
b6dd1aaf 15<h3>New issue</h3>
1cb3df3f 16
a4ccdb5e 17<form action="issue" method="post">
1cb3df3f
AC
18<input type="hidden" name="cat" value="<% catId %>">
19<input type="hidden" name="cmd" value="add">
b6dd1aaf
AC
20<table class="blanks">
21<tr> <td>Title:</td> <td><input name="title"></td> </tr>
22<tr> <td><input type="checkbox" name="priv"></td> <td>Only make this issue accessible to the admins for this support category.</td> </tr>
23<tr> <td>Description:</td> <td><textarea name="body" rows="10" cols="80" wrap="soft"></textarea></td> </tr>
1cb3df3f
AC
24<tr> <td><input type="submit" value="Add"></td> </tr>
25</table>
26</form>
27
28<% elseif $"cmd" = "add" then
29 val title = $"title";
30 if not (Support.validTitle title) then
b6dd1aaf 31 %><h3>Invalid title</h3><%
1cb3df3f
AC
32 else
33 val id = Support.addIssue (you, catId, title, $"priv" = "on", Support.NEW);
edeb626e
AC
34 val _ = Support.addPost (you, id, $"body");
35 if not (Support.notifyCreation id) then
b6dd1aaf 36 %><h3>Error sending e-mail notification</h3><%
edeb626e 37 end;
1cb3df3f
AC
38 viewingIssue := SOME id
39 end
40
5d851d7c
AC
41elseif $"cmd" = "list" then
42 showNormal := false %>
b6dd1aaf 43 <h3>All issues</h3>
5d851d7c
AC
44
45<table>
46<% foreach (name, issue) in Support.listCategoryIssues catId do
47 if (iff admin then true else (iff #priv issue then (#usr issue = you) else true)) then %>
48 <tr> <td><a href="issue?cat=<% catId %>&id=<% #id issue %>"><% Web.html (#title issue) %></a>
49<% if #priv issue then %><i>(private)</i><% end %>
50 </td>
51 <td><a href="user?id=<% #usr issue %>"><% name %></a></td>
52 <td><% #stamp issue %></td>
53 <td><% switch #status issue of
54 Support.NEW => %>New<%
55 | Support.PENDING => %>Pending<%
56 | Support.CLOSED => %>Closed<%
57 end %></td> </tr>
58<% end
59end %>
60</table>
61
62<% elseif $"mod" <> "" then
1cb3df3f
AC
63 showNormal := false;
64 val id = Web.stoi ($"mod");
65 val issue = Support.lookupIssue id;
66 if catId <> #cat issue then
b6dd1aaf 67 %><h3>Inconsistent cat field</h3><%
1cb3df3f 68 elseif not admin then
b6dd1aaf 69 %><h3>You aren't authorized to modify that.</h3><%
1cb3df3f 70 else %>
b6dd1aaf 71<h3>Modify issue</h3>
1cb3df3f 72
a4ccdb5e 73<form action="issue" method="post">
1cb3df3f
AC
74<input type="hidden" name="cat" value="<% catId %>">
75<input type="hidden" name="save" value="<% id %>">
b6dd1aaf
AC
76<table class="blanks">
77<tr> <td>Category:</td> <td><select name="newCat">
1cb3df3f
AC
78<% foreach cat in Support.listCategories () do %>
79 <option value="<% #id cat %>"<% if #id cat = catId then %> selected<% end %>><% Web.html (#name cat) %></option>
80<% end %></select></td> </tr>
aaa50197 81<tr> <td>Title:</td> <td><input name="title" value="<% Web.html (#title issue) %>"></td> </tr>
b6dd1aaf
AC
82<tr> <td><input type="checkbox" name="priv"<% if #priv issue then %> checked<% end %>></td> <td>Only make this issue accessible to the admins for this support category.</td> </tr>
83<tr> <td>Status:</td> <td><select name="status">
1cb3df3f
AC
84 <option value="0"<% if #status issue = Support.NEW then %> selected<% end %>>New</option>
85 <option value="1"<% if #status issue = Support.PENDING then %> selected<% end %>>Pending</option>
86 <option value="2"<% if #status issue = Support.CLOSED then %> selected<% end %>>Closed</option>
87</select></td> </tr>
edeb626e 88<tr> <td><input type="submit" value="Save"></td> </tr>
1cb3df3f
AC
89</table>
90</form>
91<% end
92
93elseif $"save" <> "" then
94 val id = Web.stoi ($"save");
95 val issue = Support.lookupIssue id;
96 val title = $"title";
edeb626e 97 val oldStatus = #status issue;
1cb3df3f
AC
98 val status = Web.stoi ($"status");
99 val newCat = Support.lookupCategory (Web.stoi ($"newCat"));
100
101 if catId <> #cat issue then
b6dd1aaf 102 %><h3>Inconsistent cat field</h3><%
1cb3df3f 103 elseif (iff admin then not (Group.inGroupNum (#grp newCat)) else false) then
b6dd1aaf 104 %><h3>Authorization failure</h3><%
1cb3df3f 105 elseif not (Support.validTitle title) then
b6dd1aaf 106 %><h3>Invalid title</h3><%
1cb3df3f 107 elseif (iff status < 0 then false else status > 2) then
b6dd1aaf 108 %><h3>Invalid status</h3><%
1cb3df3f 109 else
edeb626e
AC
110 val status = (case status of
111 0 => Support.NEW
112 | 1 => Support.PENDING
113 | _ => Support.CLOSED);
114
1cb3df3f
AC
115 Support.modIssue {issue with cat = #id newCat, title = title,
116 priv = ($"priv" = "on"),
edeb626e
AC
117 status = status};
118 if status <> oldStatus then
119 if not (Support.notifyStatus (you, oldStatus, status, id)) then
b6dd1aaf 120 %><h3>Error sending e-mail notification</h3><%
edeb626e
AC
121 end
122 end;
1cb3df3f 123 viewingIssue := SOME id
b6dd1aaf 124 %><h3>Issue saved</b></h3<%
1cb3df3f
AC
125 end
126
127elseif $"del" <> "" then
128 showNormal := false;
129 val id = Web.stoi ($"del");
130 val issue = Support.lookupIssue id;
131
132 if catId <> #cat issue then
b6dd1aaf 133 %><h3>Inconsistent cat field</h3><%
1cb3df3f 134 elseif not admin then
b6dd1aaf 135 %><h3>Authorization failure</h3><%
1cb3df3f 136 else
b6dd1aaf 137 %><h3>Are you sure you want to delete "<% Web.html (#title issue) %>"?</h3>
1cb3df3f
AC
138 <a href="issue?cat=<% catId %>&del2=<% id %>">Yes, delete "<% Web.html (#title issue) %>"!</a><%
139 end
140
141elseif $"del2" <> "" then
142 val id = Web.stoi ($"del2");
143 val issue = Support.lookupIssue id;
144
145 if catId <> #cat issue then
b6dd1aaf 146 %><h3>Inconsistent cat field</h3><%
1cb3df3f 147 elseif not admin then
b6dd1aaf 148 %><h3>Authorization failure</h3><%
1cb3df3f
AC
149 else
150 Support.deleteIssue id
b6dd1aaf 151 %><h3>Issue "<% Web.html (#title issue) %>" deleted</h3><%
1cb3df3f
AC
152 end
153
edeb626e
AC
154elseif $"cmd" = "post" then
155 val id = Web.stoi ($"iss");
156 viewingIssue := SOME id;
157 val issue = Support.lookupIssue id;
158
159 if catId <> #cat issue then
b6dd1aaf 160 %><h3>Inconsistent cat field</h3><%
edeb626e 161 elseif not (Support.allowedToSee id) then
b6dd1aaf 162 %><h3>Authorization failure</h3><%
edeb626e
AC
163 else
164 val id = Support.addPost (you, id, $"body");
165 if not (Support.notifyPost id) then
b6dd1aaf 166 %><h3>Error sending e-mail notification</h3><%
edeb626e 167 end
b6dd1aaf 168 %><h3>Posted</h3><%
edeb626e
AC
169 end
170
171elseif $"modPost" <> "" then
172 showNormal := false;
173 val id = Web.stoi ($"modPost");
174 val post = Support.lookupPost id;
175 val issue = Support.lookupIssue (#iss post);
176 if catId <> #cat issue then
b6dd1aaf 177 %><h3>Inconsistent cat field</h3><%
edeb626e 178 elseif not admin then
b6dd1aaf 179 %><h3>You aren't authorized to modify that.</h3><%
edeb626e 180 else %>
b6dd1aaf 181<h3>Modify post</h3>
edeb626e 182
a4ccdb5e 183<form action="issue" method="post">
edeb626e
AC
184<input type="hidden" name="cat" value="<% catId %>">
185<input type="hidden" name="savePost" value="<% id %>">
186<textarea name="body" rows="10" cols="80" wrap="soft"><% Web.htmlNl (#body post) %></textarea>
187<input type="submit" value="Save">
188</form>
189<% end
190
191elseif $"savePost" <> "" then
192 val id = Web.stoi ($"savePost");
193 val post = Support.lookupPost id;
194 val issue = Support.lookupIssue (#iss post);
195
196 if catId <> #cat issue then
b6dd1aaf 197 %><h3>Inconsistent cat field</h3><%
edeb626e 198 elseif not admin then
b6dd1aaf 199 %><h3>Authorization failure</h3><%
edeb626e
AC
200 else
201 Support.modPost {post with body = $"body"};
202 viewingIssue := SOME (#iss post)
b6dd1aaf 203 %><h3>Post saved</b></h3<%
edeb626e
AC
204 end
205
206elseif $"delPost" <> "" then
207 showNormal := false;
208 val id = Web.stoi ($"delPost");
209 val post = Support.lookupPost id;
210 val issue = Support.lookupIssue (#iss post);
211
212 if catId <> #cat issue then
b6dd1aaf 213 %><h3>Inconsistent cat field</h3><%
edeb626e 214 elseif not admin then
b6dd1aaf 215 %><h3>Authorization failure</h3><%
edeb626e 216 else
b6dd1aaf 217 %><h3>Are you sure you want to delete this post?</h3>
edeb626e
AC
218 <blockquote><% Web.htmlNl (#body post) %></blockquote>
219 <a href="issue?cat=<% catId %>&delPost2=<% id %>">Yes, delete it!</a><%
220 end
221
222elseif $"delPost2" <> "" then
223 val id = Web.stoi ($"delPost2");
224 val post = Support.lookupPost id;
225 val issue = Support.lookupIssue (#iss post);
226
227 if catId <> #cat issue then
b6dd1aaf 228 %><h3>Inconsistent cat field</h3><%
edeb626e 229 elseif not admin then
b6dd1aaf 230 %><h3>Authorization failure</h3><%
edeb626e
AC
231 else
232 Support.deletePost id;
233 viewingIssue := SOME (#iss post)
b6dd1aaf 234 %><h3>Post deleted</h3><%
edeb626e
AC
235 end
236
1cb3df3f
AC
237elseif $"id" <> "" then
238 viewingIssue := SOME (Web.stoi ($"id"))
239end;
240
241switch viewingIssue of
242 SOME id =>
243 val issue = Support.lookupIssue id;
edeb626e
AC
244 val canEdit = Support.allowedToEdit id;
245 val canView = Support.allowedToSee id;
1cb3df3f 246 if catId <> #cat issue then
b6dd1aaf 247 %><h3>Inconsistent cat field</h3><%
1cb3df3f 248 elseif not canView then
b6dd1aaf 249 %><h3>You aren't authorized to view that.</h3><%
1cb3df3f
AC
250 else
251 val user = Init.lookupUser (#usr issue) %>
252
b6dd1aaf
AC
253<table class="blanks">
254<tr> <td>Title:</td> <td><% Web.html (#title issue) %></td> </tr>
255<tr> <td>Created by:</td> <td><a href="user?id=<% #usr issue %>"><% #name user %></a></td> </tr>
256<tr> <td>At:</td> <td><% #stamp issue %></td> </tr>
257<tr> <td>Private:</td> <td><% if #priv issue then %>yes<% else %>no<% end %></td> </tr>
258<tr> <td>Status:</td> <td><% switch #status issue of
1cb3df3f
AC
259 Support.NEW => %>New<%
260 | Support.PENDING => %>Pending<%
261 | Support.CLOSED => %>Closed<%
262 end %></td> </tr>
4d46d3eb
AC
263<% switch #pstamp issue of
264 SOME stamp => %><tr> <td>Changed to pending:</td> <td><% stamp %></td> </tr><%
265 end;
266 switch #cstamp issue of
267 SOME stamp => %><tr> <td>Closed:</td> <td><% stamp %></td> </tr><%
268 end %>
1cb3df3f
AC
269</table>
270
271<% if admin then %>
272<a href="issue?cat=<% catId %>&mod=<% id %>">Modify this issue</a><br>
273<a href="issue?cat=<% catId %>&del=<% id %>">Delete this issue</a><br>
edeb626e
AC
274<% end;
275
276foreach (name, post) in Support.listPosts id do %>
277<br><hr><br>
278<a href="user?id=<% #usr post %>"><% name %></a> at <% #stamp post %>:
279<% if admin then %>
280<a href="issue?cat=<% catId %>&modPost=<% #id post %>">[Modify]</a>
281<a href="issue?cat=<% catId %>&delPost=<% #id post %>">[Delete]</a>
282<% end %>
283
284<p><% Web.htmlNl (#body post) %></p>
285
1cb3df3f
AC
286<% end %>
287
edeb626e
AC
288<br><hr><br>
289
b6dd1aaf 290<h3>Post to this thread</h3>
edeb626e 291
a4ccdb5e 292<form action="issue" method="post">
edeb626e
AC
293<input type="hidden" name="cat" value="<% catId %>">
294<input type="hidden" name="iss" value="<% id %>">
295<input type="hidden" name="cmd" value="post">
296<textarea name="body" rows="10" cols="80"></textarea><br>
297<input type="submit" value="Post">
298</form>
299
300<% end
1cb3df3f
AC
301
302 | NONE =>
303if showNormal then %>
304
5d851d7c 305<a href="issue?cat=<% catId %>&cmd=new">New issue</a><br>
af6f6078 306<a href="issue?cat=<% catId %>&cmd=list">List all issues (including closed issues)</a>
1cb3df3f 307
b6dd1aaf 308<h3>Open issues</h3>
1cb3df3f
AC
309
310<table>
311<% val issues = iff admin then Support.listOpenCategoryIssuesAdmin catId
312 else Support.listOpenCategoryIssues (catId, you);
313
5d851d7c 314foreach (name, issue) in issues do %>
1cb3df3f
AC
315 <tr> <td><a href="issue?cat=<% catId %>&id=<% #id issue %>"><% Web.html (#title issue) %></a>
316<% if #priv issue then %><i>(private)</i><% end %>
317 </td>
5d851d7c 318 <td><a href="user?id=<% #usr issue %>"><% name %></a></td>
1cb3df3f
AC
319 <td><% #stamp issue %></td>
320 <td><% switch #status issue of
321 Support.NEW => %>New<%
322 | Support.PENDING => %>Pending<%
323 | Support.CLOSED => %>Closed<%
324 end %></td> </tr>
325<% end %>
326
327<% end
328end %>
329
330<% @footer[] %>