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