web-ballot.pl: Add feature Inspect vote

This commit is contained in:
Petr Baudis 2014-10-13 20:32:20 +02:00
parent 9fd23805c5
commit 26ece44b3a

View file

@ -6,6 +6,8 @@ use v5.10;
use CGI; use CGI;
my $votefile = '/home/pasky/votes.txt';
our @names; our @names;
open my $fh, "names.txt" or die "$!"; open my $fh, "names.txt" or die "$!";
while (<$fh>) { while (<$fh>) {
@ -33,6 +35,8 @@ print <<EOT;
#ballot { margin-left: auto; margin-right: auto; border: 1pt solid; width: 20em; padding: 1ex 1em; } #ballot { margin-left: auto; margin-right: auto; border: 1pt solid; width: 20em; padding: 1ex 1em; }
.error { text-width: bold; color: red } .error { text-width: bold; color: red }
#blurb { margin: 8ex 2em; } #blurb { margin: 8ex 2em; }
table { margin-left: auto; margin-right: auto; border: 1pt solid; border-collapse: collapse; }
td { border: 1pt solid; padding: 0.5ex 0.5em; }
</style> </style>
</head> </head>
<body><h1 align="center">brmelect Web Ballot</h1> <body><h1 align="center">brmelect Web Ballot</h1>
@ -43,14 +47,12 @@ print <<EOT;
<b style="color: darkred">Keep your token secret until the vote is closed!<br /> <b style="color: darkred">Keep your token secret until the vote is closed!<br />
Udržujte svůj token v tajnosti, dokud není hlasování uzavřeno!</b></p> Udržujte svůj token v tajnosti, dokud není hlasování uzavřeno!</b></p>
<p>Enter preference numbers <p align="center">Sort individual candidates by preference.<br />
for individual candidates. You may skip some candidates (which you absolutely If you do not wish to elect some candidates at all, do not assign any preference to them.<br />
do not wish to elect), but you must select at least one candidate. You must start Do not leave any gaps in the preferences.</p>
numbering your candidates with number 1, all candidates must have a unique
number and you must not skip any number.</p>
<p><a href="https://brmlab.cz/members/vnitrni-predpisy/sbrm/2011/5">2011/5 VII.8</a>: <em>Účastníci Valné hromady označí na volebních lístcích pořadí kandidátů připsáním čísla z nepřerušené řady přirozených čísel začínající jedničkou ke jménu kandidáta. Hlasovací lístek, který neobsahuje žádného označeného kandidáta nebo obsahuje alespoň dvě stejná čísla připsaná k různým kandidátům nebo takový, na kterém nejsou použita čísla z nepřerušené řady přirozených čísel, nebo žádný kandidát není označen číslem jedna, je neplatný. <!--<p><a href="https://brmlab.cz/members/vnitrni-predpisy/sbrm/2011/5">2011/5 VII.8</a>: <em>Účastníci Valné hromady označí na volebních lístcích pořadí kandidátů připsáním čísla z nepřerušené řady přirozených čísel začínající jedničkou ke jménu kandidáta. Hlasovací lístek, který neobsahuje žádného označeného kandidáta nebo obsahuje alespoň dvě stejná čísla připsaná k různým kandidátům nebo takový, na kterém nejsou použita čísla z nepřerušené řady přirozených čísel, nebo žádný kandidát není označen číslem jedna, je neplatný.
</em></p> </em></p>-->
<!-- <p>If you wish to cast an invalid vote, check the invalid ballot checkbox.</p> --> <!-- <p>If you wish to cast an invalid vote, check the invalid ballot checkbox.</p> -->
@ -61,7 +63,38 @@ number and you must not skip any number.</p>
EOT EOT
if ($q->param('go')) { if ($q->param('inspect')) {
my $token = $q->param('token');
unless (grep { $_ eq $token } @tokens) {
print qq#<p class="error">ERROR: Unknown token specified. Please go back and try again.</p>#;
exit;
}
my %votes;
open my $fh, $votefile or die "$!";
while (<$fh>) {
chomp;
my @b = split/,/;
$votes{$b[0]} = [@b];
}
close $fh;
if (not $votes{$token}) {
print qq#<p>No vote for this (valid) token has been cast.</p>#;
exit;
} else {
my @vote = @{$votes{$token}};
shift @vote;
print "<table>\n";
for my $i (0..$#names) {
print "<tr><td>".$names[$i]."</td><td>".$vote[$i]."</td></tr>\n";
}
print "</table>\n";
}
exit;
}
if ($q->param('submit')) {
my $token = $q->param('token'); my $token = $q->param('token');
unless (grep { $_ eq $token } @tokens) { unless (grep { $_ eq $token } @tokens) {
print qq#<p class="error">ERROR: Unknown token specified. Please go back and try again.</p>#; print qq#<p class="error">ERROR: Unknown token specified. Please go back and try again.</p>#;
@ -110,7 +143,7 @@ if ($q->param('go')) {
print STDERR "$votestr\n"; print STDERR "$votestr\n";
open $fh, '>>/home/pasky/votes.txt' or die "$!"; open $fh, '>>' . $votefile or die "$!";
print $fh "$votestr\n"; print $fh "$votestr\n";
close $fh; close $fh;
@ -123,7 +156,9 @@ if ($q->param('go')) {
print <<EOT; print <<EOT;
<form method="post"> <form method="post">
<div id="ballot"> <div id="ballot">
<p align="center"><b>Token:</b> <input type="password" name="token" size="5" maxlength="5" /></p> <p align="center"><b>Token:</b> <input type="password" name="token" size="5" maxlength="5" />
(<input type="submit" name="inspect" value="Inspect Vote" />)</p>
</p>
<ul> <ul>
EOT EOT
@ -136,7 +171,7 @@ print <<EOT;
</ul> </ul>
<!-- <p align="center"><input type="checkbox" name="invalid" value="1" /> Produce <em>invalid</em> ballot</p> --> <!-- <p align="center"><input type="checkbox" name="invalid" value="1" /> Produce <em>invalid</em> ballot</p> -->
</div> </div>
<p align="center"><input type="submit" name="go" value="Submit Vote" /></p> <p align="center"><input type="submit" name="submit" value="Submit Vote" /></p>
</form> </form>
</body></html> </body></html>