cvsimport
[hcoop/zz_old/portal.git] / issue.mlt
CommitLineData
184f6cde 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
1fe415e0 15<h3>New issue</h3>
184f6cde 16
add44c00 17<form action="issue" method="post">
184f6cde 18<input type="hidden" name="cat" value="<% catId %>">
19<input type="hidden" name="cmd" value="add">
1fe415e0 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>
184f6cde 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
1fe415e0 31 %><h3>Invalid title</h3><%
184f6cde 32 else
33 val id = Support.addIssue (you, catId, title, $"priv" = "on", Support.NEW);
2eae496b 34 val _ = Support.addPost (you, id, $"body");
35 if not (Support.notifyCreation id) then
1fe415e0 36 %><h3>Error sending e-mail notification</h3><%
2eae496b 37 end;
184f6cde 38 viewingIssue := SOME id
39 end
40
d90ddc1b 41elseif $"cmd" = "list" then
42 showNormal := false %>
1fe415e0 43 <h3>All issues</h3>
d90ddc1b 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
184f6cde 63 showNormal := false;
64 val id = Web.stoi ($"mod");
65 val issue = Support.lookupIssue id;
66 if catId <> #cat issue then
1fe415e0 67 %><h3>Inconsistent cat field</h3><%
184f6cde 68 elseif not admin then
1fe415e0 69 %><h3>You aren't authorized to modify that.</h3><%
184f6cde 70 else %>
1fe415e0 71<h3>Modify issue</h3>
184f6cde 72
add44c00 73<form action="issue" method="post">
184f6cde 74<input type="hidden" name="cat" value="<% catId %>">
75<input type="hidden" name="save" value="<% id %>">
1fe415e0 76<table class="blanks">
77<tr> <td>Category:</td> <td><select name="newCat">
184f6cde 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>
892e3ea1 81<tr> <td>Title:</td> <td><input name="title" value="<% Web.html (#title issue) %>"></td> </tr>
1fe415e0 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">
184f6cde 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>
2eae496b 88<tr> <td><input type="submit" value="Save"></td> </tr>
184f6cde 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";
2eae496b 97 val oldStatus = #status issue;
184f6cde 98 val status = Web.stoi ($"status");
99 val newCat = Support.lookupCategory (Web.stoi ($"newCat"));
100
101 if catId <> #cat issue then
1fe415e0 102 %><h3>Inconsistent cat field</h3><%
184f6cde 103 elseif (iff admin then not (Group.inGroupNum (#grp newCat)) else false) then
1fe415e0 104 %><h3>Authorization failure</h3><%
184f6cde 105 elseif not (Support.validTitle title) then
1fe415e0 106 %><h3>Invalid title</h3><%
184f6cde 107 elseif (iff status < 0 then false else status > 2) then
1fe415e0 108 %><h3>Invalid status</h3><%
184f6cde 109 else
2eae496b 110 val status = (case status of
111 0 => Support.NEW
112 | 1 => Support.PENDING
113 | _ => Support.CLOSED);
114
184f6cde 115 Support.modIssue {issue with cat = #id newCat, title = title,
116 priv = ($"priv" = "on"),
2eae496b 117 status = status};
118 if status <> oldStatus then
119 if not (Support.notifyStatus (you, oldStatus, status, id)) then
1fe415e0 120 %><h3>Error sending e-mail notification</h3><%
2eae496b 121 end
122 end;
184f6cde 123 viewingIssue := SOME id
1fe415e0 124 %><h3>Issue saved</b></h3<%
184f6cde 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
1fe415e0 133 %><h3>Inconsistent cat field</h3><%
184f6cde 134 elseif not admin then
1fe415e0 135 %><h3>Authorization failure</h3><%
184f6cde 136 else
1fe415e0 137 %><h3>Are you sure you want to delete "<% Web.html (#title issue) %>"?</h3>
184f6cde 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
1fe415e0 146 %><h3>Inconsistent cat field</h3><%
184f6cde 147 elseif not admin then
1fe415e0 148 %><h3>Authorization failure</h3><%
184f6cde 149 else
150 Support.deleteIssue id
1fe415e0 151 %><h3>Issue "<% Web.html (#title issue) %>" deleted</h3><%
184f6cde 152 end
153
2eae496b 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
1fe415e0 160 %><h3>Inconsistent cat field</h3><%
2eae496b 161 elseif not (Support.allowedToSee id) then
1fe415e0 162 %><h3>Authorization failure</h3><%
2eae496b 163 else
164 val id = Support.addPost (you, id, $"body");
165 if not (Support.notifyPost id) then
1fe415e0 166 %><h3>Error sending e-mail notification</h3><%
2eae496b 167 end
1fe415e0 168 %><h3>Posted</h3><%
2eae496b 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
1fe415e0 177 %><h3>Inconsistent cat field</h3><%
2eae496b 178 elseif not admin then
1fe415e0 179 %><h3>You aren't authorized to modify that.</h3><%
2eae496b 180 else %>
1fe415e0 181<h3>Modify post</h3>
2eae496b 182
add44c00 183<form action="issue" method="post">
2eae496b 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
1fe415e0 197 %><h3>Inconsistent cat field</h3><%
2eae496b 198 elseif not admin then
1fe415e0 199 %><h3>Authorization failure</h3><%
2eae496b 200 else
201 Support.modPost {post with body = $"body"};
202 viewingIssue := SOME (#iss post)
1fe415e0 203 %><h3>Post saved</b></h3<%
2eae496b 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
1fe415e0 213 %><h3>Inconsistent cat field</h3><%
2eae496b 214 elseif not admin then
1fe415e0 215 %><h3>Authorization failure</h3><%
2eae496b 216 else
1fe415e0 217 %><h3>Are you sure you want to delete this post?</h3>
2eae496b 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
1fe415e0 228 %><h3>Inconsistent cat field</h3><%
2eae496b 229 elseif not admin then
1fe415e0 230 %><h3>Authorization failure</h3><%
2eae496b 231 else
232 Support.deletePost id;
233 viewingIssue := SOME (#iss post)
1fe415e0 234 %><h3>Post deleted</h3><%
2eae496b 235 end
236
184f6cde 237elseif $"id" <> "" then
238 viewingIssue := SOME (Web.stoi ($"id"))
239end;
240
241switch viewingIssue of
242 SOME id =>
243 val issue = Support.lookupIssue id;
2eae496b 244 val canEdit = Support.allowedToEdit id;
245 val canView = Support.allowedToSee id;
184f6cde 246 if catId <> #cat issue then
1fe415e0 247 %><h3>Inconsistent cat field</h3><%
184f6cde 248 elseif not canView then
1fe415e0 249 %><h3>You aren't authorized to view that.</h3><%
184f6cde 250 else
251 val user = Init.lookupUser (#usr issue) %>
252
1fe415e0 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
184f6cde 259 Support.NEW => %>New<%
260 | Support.PENDING => %>Pending<%
261 | Support.CLOSED => %>Closed<%
262 end %></td> </tr>
1365f9a0 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 %>
184f6cde 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>
2eae496b 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
184f6cde 286<% end %>
287
2eae496b 288<br><hr><br>
289
1fe415e0 290<h3>Post to this thread</h3>
2eae496b 291
add44c00 292<form action="issue" method="post">
2eae496b 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
184f6cde 301
302 | NONE =>
303if showNormal then %>
304
d90ddc1b 305<a href="issue?cat=<% catId %>&cmd=new">New issue</a><br>
29826664 306<a href="issue?cat=<% catId %>&cmd=list">List all issues (including closed issues)</a>
184f6cde 307
1fe415e0 308<h3>Open issues</h3>
184f6cde 309
310<table>
311<% val issues = iff admin then Support.listOpenCategoryIssuesAdmin catId
312 else Support.listOpenCategoryIssues (catId, you);
313
d90ddc1b 314foreach (name, issue) in issues do %>
184f6cde 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>
d90ddc1b 318 <td><a href="user?id=<% #usr issue %>"><% name %></a></td>
184f6cde 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[] %>