| 1 | <% val catId = Web.stoi ($"cat"); |
| 2 | val cat = Support.lookupCategory catId; |
| 3 | val admin = Group.inGroupNum (#grp cat); |
| 4 | val you = Init.getUserId() |
| 5 | |
| 6 | ref viewingIssue = NONE; |
| 7 | |
| 8 | @header[("title", ["Support: " ^ Web.html (#name cat)])]; |
| 9 | |
| 10 | ref showNormal = true; |
| 11 | |
| 12 | if $"cmd" = "new" then |
| 13 | showNormal := false %> |
| 14 | |
| 15 | <h3>New issue</h3> |
| 16 | |
| 17 | <form action="issue" method="post"> |
| 18 | <input type="hidden" name="cat" value="<% catId %>"> |
| 19 | <input type="hidden" name="cmd" value="add"> |
| 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> |
| 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 |
| 31 | %><h3>Invalid title</h3><% |
| 32 | else |
| 33 | val id = Support.addIssue (you, catId, title, $"priv" = "on", Support.NEW); |
| 34 | val _ = Support.addPost (you, id, $"body"); |
| 35 | if not (Support.notifyCreation id) then |
| 36 | %><h3>Error sending e-mail notification</h3><% |
| 37 | end; |
| 38 | viewingIssue := SOME id |
| 39 | end |
| 40 | |
| 41 | elseif $"cmd" = "list" then |
| 42 | showNormal := false %> |
| 43 | <h3>All issues</h3> |
| 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 |
| 59 | end %> |
| 60 | </table> |
| 61 | |
| 62 | <% elseif $"mod" <> "" then |
| 63 | showNormal := false; |
| 64 | val id = Web.stoi ($"mod"); |
| 65 | val issue = Support.lookupIssue id; |
| 66 | if catId <> #cat issue then |
| 67 | %><h3>Inconsistent cat field</h3><% |
| 68 | elseif not admin then |
| 69 | %><h3>You aren't authorized to modify that.</h3><% |
| 70 | else %> |
| 71 | <h3>Modify issue</h3> |
| 72 | |
| 73 | <form action="issue" method="post"> |
| 74 | <input type="hidden" name="cat" value="<% catId %>"> |
| 75 | <input type="hidden" name="save" value="<% id %>"> |
| 76 | <table class="blanks"> |
| 77 | <tr> <td>Category:</td> <td><select name="newCat"> |
| 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> |
| 81 | <tr> <td>Title:</td> <td><input name="title" value="<% Web.html (#title issue) %>"></td> </tr> |
| 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"> |
| 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> |
| 88 | <tr> <td><input type="submit" value="Save"></td> </tr> |
| 89 | </table> |
| 90 | </form> |
| 91 | <% end |
| 92 | |
| 93 | elseif $"save" <> "" then |
| 94 | val id = Web.stoi ($"save"); |
| 95 | val issue = Support.lookupIssue id; |
| 96 | val title = $"title"; |
| 97 | val oldStatus = #status issue; |
| 98 | val status = Web.stoi ($"status"); |
| 99 | val newCat = Support.lookupCategory (Web.stoi ($"newCat")); |
| 100 | |
| 101 | if catId <> #cat issue then |
| 102 | %><h3>Inconsistent cat field</h3><% |
| 103 | elseif (iff admin then not (Group.inGroupNum (#grp newCat)) else false) then |
| 104 | %><h3>Authorization failure</h3><% |
| 105 | elseif not (Support.validTitle title) then |
| 106 | %><h3>Invalid title</h3><% |
| 107 | elseif (iff status < 0 then false else status > 2) then |
| 108 | %><h3>Invalid status</h3><% |
| 109 | else |
| 110 | val status = (case status of |
| 111 | 0 => Support.NEW |
| 112 | | 1 => Support.PENDING |
| 113 | | _ => Support.CLOSED); |
| 114 | |
| 115 | Support.modIssue {issue with cat = #id newCat, title = title, |
| 116 | priv = ($"priv" = "on"), |
| 117 | status = status}; |
| 118 | if status <> oldStatus then |
| 119 | if not (Support.notifyStatus (you, oldStatus, status, id)) then |
| 120 | %><h3>Error sending e-mail notification</h3><% |
| 121 | end |
| 122 | end; |
| 123 | viewingIssue := SOME id |
| 124 | %><h3>Issue saved</b></h3<% |
| 125 | end |
| 126 | |
| 127 | elseif $"del" <> "" then |
| 128 | showNormal := false; |
| 129 | val id = Web.stoi ($"del"); |
| 130 | val issue = Support.lookupIssue id; |
| 131 | |
| 132 | if catId <> #cat issue then |
| 133 | %><h3>Inconsistent cat field</h3><% |
| 134 | elseif not admin then |
| 135 | %><h3>Authorization failure</h3><% |
| 136 | else |
| 137 | %><h3>Are you sure you want to delete "<% Web.html (#title issue) %>"?</h3> |
| 138 | <a href="issue?cat=<% catId %>&del2=<% id %>">Yes, delete "<% Web.html (#title issue) %>"!</a><% |
| 139 | end |
| 140 | |
| 141 | elseif $"del2" <> "" then |
| 142 | val id = Web.stoi ($"del2"); |
| 143 | val issue = Support.lookupIssue id; |
| 144 | |
| 145 | if catId <> #cat issue then |
| 146 | %><h3>Inconsistent cat field</h3><% |
| 147 | elseif not admin then |
| 148 | %><h3>Authorization failure</h3><% |
| 149 | else |
| 150 | Support.deleteIssue id |
| 151 | %><h3>Issue "<% Web.html (#title issue) %>" deleted</h3><% |
| 152 | end |
| 153 | |
| 154 | elseif $"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 |
| 160 | %><h3>Inconsistent cat field</h3><% |
| 161 | elseif not (Support.allowedToSee id) then |
| 162 | %><h3>Authorization failure</h3><% |
| 163 | else |
| 164 | val id = Support.addPost (you, id, $"body"); |
| 165 | if not (Support.notifyPost id) then |
| 166 | %><h3>Error sending e-mail notification</h3><% |
| 167 | end |
| 168 | %><h3>Posted</h3><% |
| 169 | end |
| 170 | |
| 171 | elseif $"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 |
| 177 | %><h3>Inconsistent cat field</h3><% |
| 178 | elseif not admin then |
| 179 | %><h3>You aren't authorized to modify that.</h3><% |
| 180 | else %> |
| 181 | <h3>Modify post</h3> |
| 182 | |
| 183 | <form action="issue" method="post"> |
| 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 | |
| 191 | elseif $"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 |
| 197 | %><h3>Inconsistent cat field</h3><% |
| 198 | elseif not admin then |
| 199 | %><h3>Authorization failure</h3><% |
| 200 | else |
| 201 | Support.modPost {post with body = $"body"}; |
| 202 | viewingIssue := SOME (#iss post) |
| 203 | %><h3>Post saved</b></h3<% |
| 204 | end |
| 205 | |
| 206 | elseif $"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 |
| 213 | %><h3>Inconsistent cat field</h3><% |
| 214 | elseif not admin then |
| 215 | %><h3>Authorization failure</h3><% |
| 216 | else |
| 217 | %><h3>Are you sure you want to delete this post?</h3> |
| 218 | <blockquote><% Web.htmlNl (#body post) %></blockquote> |
| 219 | <a href="issue?cat=<% catId %>&delPost2=<% id %>">Yes, delete it!</a><% |
| 220 | end |
| 221 | |
| 222 | elseif $"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 |
| 228 | %><h3>Inconsistent cat field</h3><% |
| 229 | elseif not admin then |
| 230 | %><h3>Authorization failure</h3><% |
| 231 | else |
| 232 | Support.deletePost id; |
| 233 | viewingIssue := SOME (#iss post) |
| 234 | %><h3>Post deleted</h3><% |
| 235 | end |
| 236 | |
| 237 | elseif $"id" <> "" then |
| 238 | viewingIssue := SOME (Web.stoi ($"id")) |
| 239 | end; |
| 240 | |
| 241 | switch viewingIssue of |
| 242 | SOME id => |
| 243 | val issue = Support.lookupIssue id; |
| 244 | val canEdit = Support.allowedToEdit id; |
| 245 | val canView = Support.allowedToSee id; |
| 246 | if catId <> #cat issue then |
| 247 | %><h3>Inconsistent cat field</h3><% |
| 248 | elseif not canView then |
| 249 | %><h3>You aren't authorized to view that.</h3><% |
| 250 | else |
| 251 | val user = Init.lookupUser (#usr issue) %> |
| 252 | |
| 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 |
| 259 | Support.NEW => %>New<% |
| 260 | | Support.PENDING => %>Pending<% |
| 261 | | Support.CLOSED => %>Closed<% |
| 262 | end %></td> </tr> |
| 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 %> |
| 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> |
| 274 | <% end; |
| 275 | |
| 276 | foreach (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 | |
| 286 | <% end %> |
| 287 | |
| 288 | <br><hr><br> |
| 289 | |
| 290 | <h3>Post to this thread</h3> |
| 291 | |
| 292 | <form action="issue" method="post"> |
| 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 |
| 301 | |
| 302 | | NONE => |
| 303 | if showNormal then %> |
| 304 | |
| 305 | <a href="issue?cat=<% catId %>&cmd=new">New issue</a><br> |
| 306 | <a href="issue?cat=<% catId %>&cmd=list">List all issues (including closed issues)</a> |
| 307 | |
| 308 | <h3>Open issues</h3> |
| 309 | |
| 310 | <table> |
| 311 | <% val issues = iff admin then Support.listOpenCategoryIssuesAdmin catId |
| 312 | else Support.listOpenCategoryIssues (catId, you); |
| 313 | |
| 314 | foreach (name, issue) in issues do %> |
| 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> |
| 318 | <td><a href="user?id=<% #usr issue %>"><% name %></a></td> |
| 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 |
| 328 | end %> |
| 329 | |
| 330 | <% @footer[] %> |