<% end
elseif $"vote" <> "" then
showNormal := false;
val id = Web.stoi ($"vote");
val poll = Poll.lookupPoll id %>
Poll#:
<% id %>
Title:
<% Web.html (#title poll) %>
Start:
<% Web.html (#starts poll) %>
End:
<% Web.html (#ends poll) %>
Votes/person:
<% #votes poll %>
Description:
<% Web.htmlNl (#descr poll) %>
Choices
<% elseif $"vote2" <> "" then
val id = Web.stoi ($"vote2");
val poll = Poll.lookupPoll id;
editingPoll := SOME id;
val votes = case Web.getMultiParam "v" of
[""] => []
| v => map Web.stoi v;
if length votes > #votes poll then
%>
You can't vote for that many different choices!
<%
elseif not (Poll.noDupes votes) then
%>
You can't vote multiple times for the same choice!
<% end
elseif $"cmd" = "add" then
val title = $"title";
val starts = $"starts";
val ends = $"ends";
val votes = Web.stoi ($"votes");
if title = "" then
%>
Your poll must have a title.
<%
elseif not (Poll.dateGeNow starts) then
%>
That start date is in the past!
<%
elseif not (Poll.dateLe (starts, ends)) then
%>
The end date comes before the start date!
<%
elseif votes <= 0 then
%>
You must specify a positive number of votes per person.
<%
else
val id = Poll.addPoll (Init.getUserId(), title, $"descr", starts, ends, votes);
editingPoll := SOME id;
%>
Poll added!
<%
end
elseif $"mod" <> "" then
showNormal := false;
val poll = Poll.lookupPoll (Web.stoi ($"mod"));
Poll.requireCanModify poll %>
Modify poll
<% elseif $"cmd" = "Save" then
val poll = Poll.lookupPoll (Web.stoi ($"id"));
Poll.requireCanModify poll;
val title = $"title";
val starts = $"starts";
val ends = $"ends";
val votes = Web.stoi ($"votes");
if title = "" then
%>
Your poll must have a title.
<%
elseif not (Poll.dateGeNow starts) then
%>
That start date is in the past!
<%
elseif not (Poll.dateLe (starts, ends)) then
%>
The end date comes before the start date!
<%
elseif votes <= 0 then
%>
You must specify a positive number of votes per person.
<%
else
Poll.modPoll {poll with title = title, descr = $"descr", starts = starts, ends = ends, votes = votes};
editingPoll := SOME (#id poll);
%>
Poll record saved.
<%
end
elseif $"del" <> "" then
Group.requireGroupName "poll";
showNormal := false;
val poll = Poll.lookupPoll (Web.stoi ($"del")) %>
<% elseif $"addChoice" <> "" then
val id = Web.stoi ($"addChoice");
editingPoll := SOME id;
val descr = $"descr";
if descr = "" then
%>
Your poll choice must have a description.
<%
else
val id = Poll.addChoice (id, Web.stor ($"seq"), descr);
%>
Choice added!
<%
end
elseif $"modChoice" <> "" then
showNormal := false;
val id = Web.stoi ($"modChoice");
val cho = Poll.lookupChoice id;
val poll = Poll.lookupPoll (#pol cho);
Poll.requireCanModify poll %>
<% elseif $"saveChoice" <> "" then
val id = Web.stoi ($"saveChoice");
val cho = Poll.lookupChoice id;
val poll = Poll.lookupPoll (#pol cho);
Poll.requireCanModify poll;
editingPoll := SOME (#id poll);
val descr = $"descr";
if descr = "" then
%>
<%
end
elseif $"delChoice" <> "" then
val id = Web.stoi ($"delChoice");
val cho = Poll.lookupChoice id;
val poll = Poll.lookupPoll (#pol cho);
Poll.requireCanModify poll;
showNormal := false %>
Are you sure you want to delete choice "<% Web.html (#descr cho) %>"?
">Yes, delete "<% Web.html (#descr cho) %>"!
<% elseif $"delChoice2" <> "" then
val id = Web.stoi ($"delChoice2");
val cho = Poll.lookupChoice id;
val poll = Poll.lookupPoll (#pol cho);
Poll.requireCanModify poll;
Poll.deleteChoice id;
editingPoll := SOME (#id poll) %>
"<% Web.html (#descr cho) %>" deleted!
<% elseif $"report" <> "" then
showNormal := false;
val id = Web.stoi ($"report");
val poll = Poll.lookupPoll id;
val canModify = Poll.canModify poll %>
Vote Report
Poll#:
<% id %>
Title:
<% Web.html (#title poll) %>
Start:
<% Web.html (#starts poll) %>
End:
<% Web.html (#ends poll) %>
Votes/person:
<% #votes poll %>
Description:
<% Web.htmlNl (#descr poll) %>
Votes
Choice
Voters
<% foreach (_, total, cho) in Poll.listChoicesWithVotes id do %>
<% total %>
<% Web.html (#descr cho) %>
<% ref first = true;
foreach user in Poll.listVoters (#id cho) do
if first then
first := false
else
%>, <%
end
%><% #name user %><%
end
%>
<%
end %>
<% elseif $"id" <> "" then
editingPoll := SOME (Web.stoi ($"id"))
end %>
<% switch editingPoll of
SOME id =>
val poll = Poll.lookupPoll id;
val canModify = Poll.canModify poll %>