From 26ece44b3aed384720305921b962e774a0b6e182 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Mon, 13 Oct 2014 20:32:20 +0200 Subject: [PATCH] web-ballot.pl: Add feature Inspect vote --- web-ballot.pl | 57 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/web-ballot.pl b/web-ballot.pl index f23ea5b..3610674 100755 --- a/web-ballot.pl +++ b/web-ballot.pl @@ -6,6 +6,8 @@ use v5.10; use CGI; +my $votefile = '/home/pasky/votes.txt'; + our @names; open my $fh, "names.txt" or die "$!"; while (<$fh>) { @@ -33,6 +35,8 @@ print <

brmelect Web Ballot

@@ -43,14 +47,12 @@ print <Keep your token secret until the vote is closed!
Udržujte svůj token v tajnosti, dokud není hlasování uzavřeno!

-

Enter preference numbers -for individual candidates. You may skip some candidates (which you absolutely -do not wish to elect), but you must select at least one candidate. You must start -numbering your candidates with number 1, all candidates must have a unique -number and you must not skip any number.

+

Sort individual candidates by preference.
+If you do not wish to elect some candidates at all, do not assign any preference to them.
+Do not leave any gaps in the preferences.

-

2011/5 VII.8: Úč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ý. -

+ @@ -61,7 +63,38 @@ number and you must not skip any number.

EOT -if ($q->param('go')) { +if ($q->param('inspect')) { + my $token = $q->param('token'); + unless (grep { $_ eq $token } @tokens) { + print qq#

ERROR: Unknown token specified. Please go back and try again.

#; + 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#

No vote for this (valid) token has been cast.

#; + exit; + } else { + my @vote = @{$votes{$token}}; + shift @vote; + print "\n"; + for my $i (0..$#names) { + print "\n"; + } + print "
".$names[$i]."".$vote[$i]."
\n"; + } + exit; +} + + +if ($q->param('submit')) { my $token = $q->param('token'); unless (grep { $_ eq $token } @tokens) { print qq#

ERROR: Unknown token specified. Please go back and try again.

#; @@ -110,7 +143,7 @@ if ($q->param('go')) { print STDERR "$votestr\n"; - open $fh, '>>/home/pasky/votes.txt' or die "$!"; + open $fh, '>>' . $votefile or die "$!"; print $fh "$votestr\n"; close $fh; @@ -123,7 +156,9 @@ if ($q->param('go')) { print <
-

Token:

+

Token: +()

+

    EOT @@ -136,7 +171,7 @@ print <
-

+