if $"cmd" = "list" then
showNormal := false %>
-<h2><b>All polls</b></h2>
+<h2>All polls</h2>
<% foreach pol in Poll.listPolls () do %>
<li> <a href="poll?id=<% #id pol %>"><% Web.html (#title pol) %></a>
</li>
<% end
+elseif $"vote" <> "" then
+ showNormal := false;
+ val id = Web.stoi ($"vote");
+ val poll = Poll.lookupPoll id %>
+
+<table class="blanks">
+<tr> <td>Poll#:</td> <td><% id %></td> </tr>
+<tr> <td>Title:</td> <td><% Web.html (#title poll) %></td> </tr>
+<tr> <td>Start:</td> <td><% Web.html (#starts poll) %></td> </tr>
+<tr> <td>End:</td> <td><% Web.html (#ends poll) %></td> </tr>
+<tr> <td>Votes/person:</td> <td><% #votes poll %></td> </tr>
+<tr> <td>Description:</td> <td><% Web.htmlNl (#descr poll) %></td> </tr>
+</table>
+
+<h3>Choices</h3>
+
+<form action="poll" method="post">
+<input type="hidden" name="vote2" value="<% id %>">
+<% val choices = Poll.listChoicesWithMyVotes id;
+if #votes poll = 1 then %>
+<select name="v">
+<option value="">Abstain</option>
+<% else %>
+<select name="v" multiple size="<% length choices %>">
+<% end
+foreach (you, cho) in choices do %>
+ <option value="<% #id cho %>"<% if you then %> selected<% end %>><% Web.html (#descr cho) %></option>
+<% end %></select><br><br>
+<input type="submit" value="Vote">
+</form>
+
+<% 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
+ %><h3>You can't vote for that many different choices!</h3><%
+ elseif not (Poll.noDupes votes) then
+ %><h3>You can't vote multiple times for the same choice!</h3><%
+ else
+ Poll.vote (Init.getUserId (), id, votes)
+ %><h3>Thanks for voting!</h3>
+<% end
+
elseif $"cmd" = "add" then
val title = $"title";
val starts = $"starts";
val ends = $"ends";
val votes = Web.stoi ($"votes");
if title = "" then
- %><h3><b>Your poll must have a title.</b></h3><%
- elseif not (Poll.dateGeNow starts) then
- %><h3><b>That start date is in the past!</b></h3><%
- elseif not (Poll.dateLe (starts, ends)) then
- %><h3><b>The end date comes before the start date!</b></h3><%
+ %><h3>Your poll must have a title.</h3><%
+ elseif not pollAdmin and not (Poll.dateGeNow starts) then
+ %><h3>That start date is in the past!</h3><%
+ elseif not pollAdmin and not (Poll.dateLe (starts, ends)) then
+ %><h3>The end date comes before the start date!</h3><%
elseif votes <= 0 then
- %><h3><b>You must specify a positive number of votes per person.</b></h3><%
+ %><h3>You must specify a positive number of votes per person.</h3><%
else
val id = Poll.addPoll (Init.getUserId(), title, $"descr", starts, ends, votes);
editingPoll := SOME id;
- %><h3><b>Poll added!</b></h3><%
+ %><h3>Poll added!</h3><%
end
elseif $"mod" <> "" then
val poll = Poll.lookupPoll (Web.stoi ($"mod"));
Poll.requireCanModify poll %>
-<h3><b>Modify poll</b></h3>
+<h3>Modify poll</h3>
-<form action="poll">
+<form action="poll" method="post">
<input type="hidden" name="id" value="<% $"mod" %>">
-<table>
-<tr> <td align="right"><b>Title</b>:</td> <td><input name="title" value="<% Web.html (#title poll) %>"></td> </tr>
-<tr> <td align="right"><b>Start date</b>:</td> <td><input name="starts" value="<% Web.html (#starts poll) %>"></td> </tr>
-<tr> <td align="right"><b>End date</b>:</td> <td><input name="ends" value="<% Web.html (#ends poll) %>"></td> </tr>
-<tr> <td align="right"><b>Max votes/person</b>:</td> <td><input name="votes" value="<% #votes poll %>"></td> </tr>
-<tr> <td align="right" valign="top"><b>Description</b>:</td> <td><textarea name="descr" wrap="soft" rows="5" cols="80"><% Web.html (#descr poll) %></textarea></td> </tr>
+<table class="blanks">
+<tr> <td>Title:</td> <td><input name="title" value="<% Web.html (#title poll) %>"></td> </tr>
+<tr> <td>Start date:</td> <td><input name="starts" value="<% Web.html (#starts poll) %>"></td> </tr>
+<tr> <td>End date:</td> <td><input name="ends" value="<% Web.html (#ends poll) %>"></td> </tr>
+<tr> <td>Max votes/person:</td> <td><input name="votes" value="<% #votes poll %>"></td> </tr>
+<tr> <td>Description:</td> <td><textarea name="descr" wrap="soft" rows="5" cols="80"><% Web.html (#descr poll) %></textarea></td> </tr>
<tr> <td><input type="submit" name="cmd" value="Save"></td> </tr>
</table>
</form>
val ends = $"ends";
val votes = Web.stoi ($"votes");
if title = "" then
- %><h3><b>Your poll must have a title.</b></h3><%
- elseif not (Poll.dateGeNow starts) then
- %><h3><b>That start date is in the past!</b></h3><%
- elseif not (Poll.dateLe (starts, ends)) then
- %><h3><b>The end date comes before the start date!</b></h3><%
+ %><h3>Your poll must have a title.</h3><%
+ elseif not pollAdmin and not (Poll.dateGeNow starts) then
+ %><h3>That start date is in the past!</h3><%
+ elseif not pollAdmin and not (Poll.dateLe (starts, ends)) then
+ %><h3>The end date comes before the start date!</h3><%
elseif votes <= 0 then
- %><h3><b>You must specify a positive number of votes per person.</b></h3><%
+ %><h3>You must specify a positive number of votes per person.</h3><%
else
Poll.modPoll {poll with title = title, descr = $"descr", starts = starts, ends = ends, votes = votes};
editingPoll := SOME (#id poll);
- %><h3><b>Poll record saved.</b></h3><%
+ %><h3>Poll record saved.</h3><%
end
elseif $"del" <> "" then
Group.requireGroupName "poll";
showNormal := false;
val poll = Poll.lookupPoll (Web.stoi ($"del")) %>
- <h3><b>Are you sure you want to delete poll <a href="poll?id=<% #id poll %>"><% Web.html (#title poll) %></a>?</b></h3>
+ <h3>Are you sure you want to delete poll <a href="poll?id=<% #id poll %>"><% Web.html (#title poll) %></a>?</h3>
<a href="poll?del2=<% $"del" %>">Yes, delete <% Web.html (#title poll) %>!</a>
<% elseif $"del2" <> "" then
Group.requireGroupName "poll";
val poll = Poll.lookupPoll (Web.stoi ($"del2"));
Poll.deletePoll (Web.stoi ($"del2")) %>
- <h3><b><% Web.html (#title poll) %> deleted!</b></h3>
+ <h3><% Web.html (#title poll) %> deleted!</h3>
<% elseif $"addChoice" <> "" then
val id = Web.stoi ($"addChoice");
editingPoll := SOME id;
val descr = $"descr";
if descr = "" then
- %><h3><b>Your poll choice must have a description.</b></h3><%
+ %><h3>Your poll choice must have a description.</h3><%
else
val id = Poll.addChoice (id, Web.stor ($"seq"), descr);
- %><h3><b>Choice added!</b></h3><%
+ %><h3>Choice added!</h3><%
end
elseif $"modChoice" <> "" then
val poll = Poll.lookupPoll (#pol cho);
Poll.requireCanModify poll %>
-<form action="poll">
+<form action="poll" method="post">
<input type="hidden" name="saveChoice" value="<% id %>">
-<table>
-<tr> <td align="right"><b>Text</b>:</td> <td><input name="descr" value="<% Web.html (#descr cho) %>"></td> </tr>
-<tr> <td align="right"><b>Sequence#</b>:</td> <td><input name="seq" value="<% #seq cho %>"></td> </tr>
+<table class="blanks">
+<tr> <td>Text:</td> <td><input name="descr" value="<% Web.html (#descr cho) %>"></td> </tr>
+<tr> <td>Sequence#:</td> <td><input name="seq" value="<% #seq cho %>"></td> </tr>
<tr> <td><input type="submit" value="Save"></td> </tr>
</table>
</form>
editingPoll := SOME (#id poll);
val descr = $"descr";
if descr = "" then
- %><h3><b>Your poll choice must have a description.</b></h3><%
+ %><h3>Your poll choice must have a description.</h3><%
else
Poll.modChoice {cho with seq = Web.stor ($"seq"), descr = descr};
- %><h3><b>Choice saved!</b></h3><%
+ %><h3>Choice saved!</h3><%
end
elseif $"delChoice" <> "" then
val poll = Poll.lookupPoll (#pol cho);
Poll.requireCanModify poll;
showNormal := false %>
- <h3><b>Are you sure you want to delete choice "<% Web.html (#descr cho) %>"</a>?</b></h3>
+ <h3>Are you sure you want to delete choice "<% Web.html (#descr cho) %>"</a>?</h3>
<a href="poll?delChoice2=<% $"delChoice" %>">Yes, delete "<% Web.html (#descr cho) %>"!</a>
<% elseif $"delChoice2" <> "" then
Poll.requireCanModify poll;
Poll.deleteChoice id;
editingPoll := SOME (#id poll) %>
- <h3><b>"<% Web.html (#descr cho) %>" deleted!</b></h3>
+ <h3>"<% Web.html (#descr cho) %>" deleted!</h3>
+
+<% elseif $"report" <> "" then
+ showNormal := false;
+ val id = Web.stoi ($"report");
+
+ val poll = Poll.lookupPoll id;
+ val canModify = Poll.canModify poll %>
+
+<h3>Vote Report</h3>
+
+<p>Voters:
+<% ref first = true;
+ foreach user in Poll.listPollVoters id do
+ if first then
+ first := false
+ else
+ %>, <%
+ end
+ %><a href="user?id=<% #id user %>"><% #name user %></a><%
+ end %></p>
+
+<table class="blanks">
+<tr> <td>Poll#</b>:</td> <td><% id %></td> </tr>
+<tr> <td>Title</b>:</td> <td><% Web.html (#title poll) %></td> </tr>
+<tr> <td>Start:</td> <td><% Web.html (#starts poll) %></td> </tr>
+<tr> <td>End:</td> <td><% Web.html (#ends poll) %></td> </tr>
+<tr> <td>Votes/person:</td> <td><% #votes poll %></td> </tr>
+<tr> <td>Description:</td> <td><% Web.htmlNl (#descr poll) %></td> </tr>
+</table>
+
+<br><hr><br>
+
+<table>
+<tr> <td><b>Votes</b></td> <td><b>Choice</b></td> <td><b>Voters</b></td> </tr>
+<% foreach (_, total, cho) in Poll.listChoicesWithVotes id do %>
+ <tr> <td><% total %></td> <td><% Web.html (#descr cho) %></td> <td>
+<% ref first = true;
+ foreach user in Poll.listVoters (#id cho) do
+ if first then
+ first := false
+ else
+ %>, <%
+ end
+ %><a href="user?id=<% #id user %>"><% #name user %></a><%
+ end
+ %></td> </tr><%
+end %>
+</table>
<% elseif $"id" <> "" then
editingPoll := SOME (Web.stoi ($"id"))
<% switch editingPoll of
SOME id =>
- val pol = Poll.lookupPoll id;
- val canModify = Poll.canModify pol %>
+ val poll = Poll.lookupPoll id;
+ val canModify = Poll.canModify poll %>
-<table>
+<table class="blanks">
<% if canModify then %><tr> <td></td> <td><a href="poll?mod=<% id %>">Edit poll data</a></td> </tr><% end %>
-<tr> <td align="right"><b>Poll#</b>:</td> <td><% id %></td> </tr>
-<tr> <td align="right"><b>Title</b>:</td> <td><% Web.html (#title pol) %></td> </tr>
-<tr> <td align="right"><b>Start</b>:</td> <td><% Web.html (#starts pol) %></td> </tr>
-<tr> <td align="right"><b>End</b>:</td> <td><% Web.html (#ends pol) %></td> </tr>
-<tr> <td align="right"><b>Votes/person</b>:</td> <td><% #votes pol %></td> </tr>
-<tr> <td align="right" valign="top"><b>Description</b>:</td> <td><% Web.htmlNl (#descr pol) %></td> </tr>
+<tr> <td>Poll#:</td> <td><% id %></td> </tr>
+<tr> <td>Title:</td> <td><% Web.html (#title poll) %></td> </tr>
+<tr> <td>Start:</td> <td><% Web.html (#starts poll) %></td> </tr>
+<tr> <td>End:</td> <td><% Web.html (#ends poll) %></td> </tr>
+<tr> <td>Votes/person:</td> <td><% #votes poll %></td> </tr>
+<tr> <td>Description:</td> <td><% Web.htmlNl (#descr poll) %></td> </tr>
</table>
-<h3><b>Choices</b></h3>
+<h3>Choices<% if Poll.takingVotes poll then %><a href="poll?vote=<% id %>">(Vote!)</a><% end %></h3>
+
+<p><% Poll.countVoters (#id poll) %> people have voted.</p>
+
+<% if Poll.takingVotes poll then %>
+<table>
+<tr> <td><b>You</b></td> <td><b>Total</b></td> </tr>
+<% foreach (you, total, cho) in Poll.listChoicesWithVotes id do %>
+ <tr> <td align="center"><% if you then %>X<% end %></td>
+ <td align="center"><% total %></td>
+ <td><% Web.html (#descr cho) %></td>
+<% if canModify then %>
+<td><i>(<% #seq cho %>)</i>
+<a href="poll?modChoice=<% #id cho %>">[Modify]</a>
+<a href="poll?delChoice=<% #id cho %>">[Delete]</a></td>
+<% end %></tr>
+<% end %>
+</table>
-<% foreach cho in Poll.listChoices id do %>
+<% else
+foreach cho in Poll.listChoices id do %>
<li> <% Web.html (#descr cho) %>
<% if canModify then %>
<i>(<% #seq cho %>)</i>
<a href="poll?modChoice=<% #id cho %>">[Modify]</a>
<a href="poll?delChoice=<% #id cho %>">[Delete]</a>
<% end %></li>
-<% end %>
+<% end
+end %>
+
+<a href="poll?report=<% id %>">Vote Report</a>
<% if canModify then %>
<br><hr><br>
-<h3><b>Add a new choice</b></h3>
+<h3>Add a new choice</h3>
-<form action="poll">
+<form action="poll" method="post">
<input type="hidden" name="addChoice" value="<% id %>">
-<table>
-<tr> <td align="right"><b>Text</b>:</td> <td><input name="descr"></td> </tr>
-<tr> <td align="right"><b>Sequence#</b>:</td> <td><input name="seq" value="<% Poll.nextSeq id %>"></td> </tr>
+<table class="blanks">
+<tr> <td>Text:</td> <td><input name="descr"></td> </tr>
+<tr> <td>Sequence#:</td> <td><input name="seq" value="<% Poll.nextSeq id %>"></td> </tr>
<tr> <td><input type="submit" value="Add"></td> </tr>
</table>
</form>
<a href="poll?cmd=list">Show all polls</a><br>
-<h3><b>Create a poll</b></h3>
+<h3>Create a poll</h3>
-<form action="poll">
+<form action="poll" method="post">
<input type="hidden" name="cmd" value="add">
-<table>
-<tr> <td align="right"><b>Title</b>:</td> <td><input name="title"></td> </tr>
-<tr> <td align="right"><b>Start date</b>:</td> <td><input name="starts"></td> </tr>
-<tr> <td align="right"><b>End date</b>:</td> <td><input name="ends"></td> </tr>
-<tr> <td align="right"><b>Max votes/person</b>:</td> <td><input name="votes"></td> </tr>
-<tr> <td align="right" valign="top"><b>Description</b>:</td> <td><textarea name="descr" wrap="soft" rows="5" cols="80"></textarea></td> </tr>
+<table class="blanks">
+<tr> <td>Title:</td> <td><input name="title"></td> </tr>
+<tr> <td>Start date:</td> <td><input name="starts"></td> </tr>
+<tr> <td>End date:</td> <td><input name="ends"></td> </tr>
+<tr> <td>Max votes/person:</td> <td><input name="votes"></td> </tr>
+<tr> <td>Description:</td> <td><textarea name="descr" wrap="soft" rows="5" cols="80"></textarea></td> </tr>
<tr> <td><input type="submit" value="Create"></td> </tr>
</table>
</form>