% val catId = Web.stoi ($"cat");
val cat = Support.lookupCategory catId;
val admin = Group.inGroupNum (#grp cat);
val you = Init.getUserId()
ref viewingIssue = NONE;
@header[("title", ["Support: " ^ Web.html (#name cat)])];
ref showNormal = true;
if $"cmd" = "new" then
showNormal := false %>
New issue
<% elseif $"cmd" = "add" then
val title = $"title";
if not (Support.validTitle title) then
%>
Invalid title
<%
else
val id = Support.addIssue (you, catId, title, $"priv" = "on", Support.NEW);
val _ = Support.addPost (you, id, $"body");
if not (Support.notifyCreation id) then
%>
Error sending e-mail notification
<%
end;
viewingIssue := SOME id
end
elseif $"cmd" = "list" then
showNormal := false %>
All issues
<% foreach (name, issue) in Support.listCategoryIssues catId do
if (iff admin then true else (iff #priv issue then (#usr issue = you) else true)) then %>
<% switch #status issue of
Support.NEW => %>New<%
| Support.PENDING => %>Pending<%
| Support.CLOSED => %>Closed<%
end %>
<% end
end %>
<% elseif $"mod" <> "" then
showNormal := false;
val id = Web.stoi ($"mod");
val issue = Support.lookupIssue id;
if catId <> #cat issue then
%>
Inconsistent cat field
<%
elseif not admin then
%>
You aren't authorized to modify that.
<%
else %>
Modify issue
<% end
elseif $"save" <> "" then
val id = Web.stoi ($"save");
val issue = Support.lookupIssue id;
val title = $"title";
val oldStatus = #status issue;
val status = Web.stoi ($"status");
val newCat = Support.lookupCategory (Web.stoi ($"newCat"));
if catId <> #cat issue then
%>
Inconsistent cat field
<%
elseif (iff admin then not (Group.inGroupNum (#grp newCat)) else false) then
%>
Authorization failure
<%
elseif not (Support.validTitle title) then
%>
Invalid title
<%
elseif (iff status < 0 then false else status > 2) then
%>
Invalid status
<%
else
val status = (case status of
0 => Support.NEW
| 1 => Support.PENDING
| _ => Support.CLOSED);
Support.modIssue {issue with cat = #id newCat, title = title,
priv = ($"priv" = "on"),
status = status};
if status <> oldStatus then
if not (Support.notifyStatus (you, oldStatus, status, id)) then
%>
Error sending e-mail notification
<%
end
end;
viewingIssue := SOME id
%>
Issue saved
"" then
showNormal := false;
val id = Web.stoi ($"del");
val issue = Support.lookupIssue id;
if catId <> #cat issue then
%>
Inconsistent cat field
<%
elseif not admin then
%>
Authorization failure
<%
else
%>
Are you sure you want to delete "<% Web.html (#title issue) %>"?
<%
end
elseif $"cmd" = "post" then
val id = Web.stoi ($"iss");
viewingIssue := SOME id;
val issue = Support.lookupIssue id;
if catId <> #cat issue then
%>
Inconsistent cat field
<%
elseif not (Support.allowedToSee id) then
%>
Authorization failure
<%
else
val id = Support.addPost (you, id, $"body");
if not (Support.notifyPost id) then
%>
Error sending e-mail notification
<%
end
%>
Posted
<%
end
elseif $"modPost" <> "" then
showNormal := false;
val id = Web.stoi ($"modPost");
val post = Support.lookupPost id;
val issue = Support.lookupIssue (#iss post);
if catId <> #cat issue then
%>
Inconsistent cat field
<%
elseif not admin then
%>
You aren't authorized to modify that.
<%
else %>
Modify post
<% end
elseif $"savePost" <> "" then
val id = Web.stoi ($"savePost");
val post = Support.lookupPost id;
val issue = Support.lookupIssue (#iss post);
if catId <> #cat issue then
%>
Inconsistent cat field
<%
elseif not admin then
%>
Authorization failure
<%
else
Support.modPost {post with body = $"body"};
viewingIssue := SOME (#iss post)
%>
Post saved
"" then
showNormal := false;
val id = Web.stoi ($"delPost");
val post = Support.lookupPost id;
val issue = Support.lookupIssue (#iss post);
if catId <> #cat issue then
%>
Inconsistent cat field
<%
elseif not admin then
%>
Authorization failure
<%
else
%>
Are you sure you want to delete this post?
<% Web.htmlNl (#body post) %>
Yes, delete it!<%
end
elseif $"delPost2" <> "" then
val id = Web.stoi ($"delPost2");
val post = Support.lookupPost id;
val issue = Support.lookupIssue (#iss post);
if catId <> #cat issue then
%>
Inconsistent cat field
<%
elseif not admin then
%>
Authorization failure
<%
else
Support.deletePost id;
viewingIssue := SOME (#iss post)
%>
Post deleted
<%
end
elseif $"id" <> "" then
viewingIssue := SOME (Web.stoi ($"id"))
end;
switch viewingIssue of
SOME id =>
val issue = Support.lookupIssue id;
val canEdit = Support.allowedToEdit id;
val canView = Support.allowedToSee id;
if catId <> #cat issue then
%>
Inconsistent cat field
<%
elseif not canView then
%>
You aren't authorized to view that.
<%
else
val user = Init.lookupUser (#usr issue) %>
<% val issues = iff admin then Support.listOpenCategoryIssuesAdmin catId
else Support.listOpenCategoryIssues (catId, you);
foreach (name, issue) in issues do %>