Documentation: Add votename to UVmenu.
[usenet/usevote.git] / uvvote.pl
old mode 100644 (file)
new mode 100755 (executable)
index a86ef43..8e8fb68
--- a/uvvote.pl
+++ b/uvvote.pl
@@ -1,8 +1,8 @@
 #!/usr/bin/perl -w
 
 ###############################################################################
 #!/usr/bin/perl -w
 
 ###############################################################################
-# UseVoteGer 4.09 Wahldurchfuehrung
-# (c) 2001-2005 Marc Langer <uv@marclanger.de>
+# UseVoteGer 4.11 Wahldurchfuehrung
+# (c) 2001-2012 Marc Langer <uv@marclanger.de>
 # 
 # This script package is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Public License as published by the
 # 
 # This script package is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Public License as published by the
@@ -123,7 +123,7 @@ if ($clean) {
   my $ext = time;
 
   opendir (TMP, $config{tmpdir});
   my $ext = time;
 
   opendir (TMP, $config{tmpdir});
-  my @tmpfiles = readdir (DIR);
+  my @tmpfiles = readdir (TMP);
   closedir (TMP);
   opendir (FERTIG, $config{archivedir});
   my @fertigfiles = readdir (FERTIG);
   closedir (TMP);
   opendir (FERTIG, $config{archivedir});
   my @fertigfiles = readdir (FERTIG);
@@ -135,16 +135,6 @@ if ($clean) {
   my $thisresult = "ergebnis-" . $ext;
   my $thisvotes = "stimmen-" . $ext;
   
   my $thisresult = "ergebnis-" . $ext;
   my $thisvotes = "stimmen-" . $ext;
   
-  # POP3 not activated: rename votes file
-  unless ($config{pop3}) {
-    print UVmessage::get("VOTE_RENAMING_MAILBOX"), "\n";
-    rename ($config{votefile}, "$config{tmpdir}/$thisvotes")
-       or die UVmessage::get("ERR_RENAME_MAILFILE") . "$!\n\n";
-  
-    #  wait, so that current mail deliveries can finalize
-    sleep 2;
-  }
-
   # open results file
   open (RESULT, ">>$config{tmpdir}/$thisresult")
      or die UVmessage::get("VOTE_WRITE_RESULTS", (FILE=>$thisresult)) . "\n\n";
   # open results file
   open (RESULT, ">>$config{tmpdir}/$thisresult")
      or die UVmessage::get("VOTE_WRITE_RESULTS", (FILE=>$thisresult)) . "\n\n";
@@ -158,7 +148,7 @@ if ($clean) {
 
   # no mails: exit here
   unless ($count) {
 
   # no mails: exit here
   unless ($count) {
-    print UVmessage::get("VOTE_NO_VOTES") . "\n\n";
+    print UVmessage::get("VOTE_NO_VOTEMAILS") . "\n\n";
     exit 0;
   }
 
     exit 0;
   }
 
@@ -224,6 +214,7 @@ sub process_vote {
   my $onevote = 0;             # 0=no votes, 1=everything OK, 2=vote cancelled
   my $voteerror = "";          # error message in case of invalid vote
   my $ballot_id = "";          # ballot id (German: Wahlscheinkennung)
   my $onevote = 0;             # 0=no votes, 1=everything OK, 2=vote cancelled
   my $voteerror = "";          # error message in case of invalid vote
   my $ballot_id = "";          # ballot id (German: Wahlscheinkennung)
+  my $voting = "";             # voting (should be votename)
 
   # found address?
   if ($voter_addr) {
 
   # found address?
   if ($voter_addr) {
@@ -239,6 +230,15 @@ sub process_vote {
     push (@errors, 'InvalidAddress');
   }
 
     push (@errors, 'InvalidAddress');
   }
 
+  # correct voting?
+  if ($$body =~ /\Q$config{ballotintro}\E\s+(.+?)\s*\n([>:|]*?[\t ]+(\S+.+)\s*$)?/m) {
+    $voting = $1;
+    $voting .= " $3" if (defined($3) and $3 !~ /\Q$config{nametext}\E/);
+    push (@errors, 'WrongVoting') if ($config{votename} !~ /^\s*\Q$voting\E\s*$/);
+  } else {
+    push (@errors, 'NoVoting');
+  }
+
   # personalized ballots?
   if ($config{personal}) {
     if ($$body =~ /$config{ballotidtext}\s+([a-z0-9]+)/) {
   # personalized ballots?
   if ($config{personal}) {
     if ($$body =~ /$config{ballotidtext}\s+([a-z0-9]+)/) {
@@ -273,7 +273,7 @@ sub process_vote {
     # this matches on a single appearance:
     if ($$body =~ /#$votenum\W*?\[(.+)\]/) {
       # one or more vote strings were found
     # this matches on a single appearance:
     if ($$body =~ /#$votenum\W*?\[(.+)\]/) {
       # one or more vote strings were found
-      $onevote = 1;
+      $onevote ||= 1; # set $onevote to 1 if it was 0
       my $votestring = $1;
       if ($votestring =~ /^\W*$config{ja_stimme}\W*$/i) {
         $vote = "J";
       my $votestring = $1;
       if ($votestring =~ /^\W*$config{ja_stimme}\W*$/i) {
         $vote = "J";
@@ -319,7 +319,7 @@ sub process_vote {
     # Should read like this: #a [ STIMME ] Text
     # (Text is configurable in usevote.cfg)
     unless ($$body =~ /$bdsg_regexp/s &&
     # Should read like this: #a [ STIMME ] Text
     # (Text is configurable in usevote.cfg)
     unless ($$body =~ /$bdsg_regexp/s &&
-            $$body =~ /#a\W*?\[\W*?$config{ja_stimme}\W*?\]\W*?$bdsg2_regexp/is) {
+            $$body =~ /#a\W*?\[\W*?$config{bdsg_confirm}\W*?\]\W*?$bdsg2_regexp/is) {
 
       push (@errors, 'InvalidBDSG');
     }
 
       push (@errors, 'InvalidBDSG');
     }
@@ -343,7 +343,7 @@ sub process_vote {
   # Errors encountered?
   if (@errors) {
     my $res = UVmenu::menu(\@votes, \@header, $body, \$voter_addr, \$voter_name,
   # Errors encountered?
   if (@errors) {
     my $res = UVmenu::menu(\@votes, \@header, $body, \$voter_addr, \$voter_name,
-                           \$ballot_id, \@set, \@errors);
+                           \$ballot_id, \$voting, \@set, \@errors);
     return 0 if ($res eq 'i');      # "Ignore": Ignore vote, don't save
 
     my $tpl;
     return 0 if ($res eq 'i');      # "Ignore": Ignore vote, don't save
 
     my $tpl;
@@ -402,6 +402,12 @@ sub process_vote {
       my $msg = $template->processTemplate($config{tpl_bdsg_error});
       UVsendmail::mail($voter_addr, "Fehler", $msg, $msgid) if ($config{voteack});
       return 0;
       my $msg = $template->processTemplate($config{tpl_bdsg_error});
       UVsendmail::mail($voter_addr, "Fehler", $msg, $msgid) if ($config{voteack});
       return 0;
+    } elsif ($error{NoVoting} or $error{WrongVoting}) {
+      $voteerror = UVmessage::get("VOTE_WRONG_VOTING");
+      my $template = UVtemplate->new();
+      $template->setKey('body'  => $$body);
+      my $msg = $template->processTemplate($config{tpl_wrong_voting});
+      UVsendmail::mail($voter_addr, "Fehler", $msg, $msgid) if ($config{voteack});
     } elsif ($error{NoVote}) {
       $voteerror = UVmessage::get("VOTE_NO_VOTES");
       my $template = UVtemplate->new();
     } elsif ($error{NoVote}) {
       $voteerror = UVmessage::get("VOTE_NO_VOTES");
       my $template = UVtemplate->new();
This page took 0.012564 seconds and 4 git commands to generate.