#!/usr/bin/perl -w push(@INC,"/www/cgi-bin"); require 5.003; require "cgi-lib.pl"; #-------------------------- What This Does ---------------------------- # The new ingredients here are: # 1. Make a list of the people who vote. # 2. Reject a voter whose name is a already on this list. # # New sections: AlreadyVoted and RecordWhoVoted #---------------------------- Configure ---------------------------- $vote = "http://www.math.upenn.edu/~kazdan/210/vote/vote4.html"; #Election Form $data_dir = "/www/cgi-bin/210/vote"; # Directory where data is kept $voted = "$data_dir/voted"; # those who already voted #---------------------------- Main Program ---------------------------- &ReadParse; print &PrintHeader; &Preliminaries; # If something is missing, print an error message and return to form. if (($in{lastname} eq "") || ($in{firstname} eq "") || ($in{"pres"} eq "")) { &missing; } else { # Their ballot is complete. OK unless voted already. &AlreadyVoted; if ( $alreadyvoted ne "yes") { &RecordWhoVoted; # Add name to voted list &Thanks; # Thanks &ClosePage; } } # end Main Program #--------------------------------------------------------------- sub Preliminaries { # Next is a useful "Return to the Form" button. $header = '
Return to Voting Forms Page
'; } # end Preliminaries #--------------------------------------------------------------- sub missing { # The only trick here is how to switch to a new URL after giving # 3 seconds to read the error message. The Election 2000 error $header  
To vote, you must include your First and Last names as well as your Vote.

In a few seconds your Election Ballot will be returned. error } # end missing #--------------------------------------------------------------- sub AlreadyVoted { # Did they already vote? We check. # Open the file listing those who already voted; die & warn if can't open. open(VOTED, "$voted") || die "Can't open $voted\n"; # Look through the list line by line to locate this voter. $alreadyvoted = "no"; while () {# This reads VOTED one line at a time until the end. if ($_ eq "$in{lastname},$in{firstname}\n") { # if this person is found print "Our lists show you have already voted. Only one vote per person is allowed.\n"; $alreadyvoted = "yes"; last # Stop searching if the person is found. close(VOTED); } } } # end AlreadyVoted #--------------------------------------------------------------- sub RecordWhoVoted { `echo "$in{lastname},$in{firstname}" >> $voted`; } # end RecordWhoVoted #--------------------------------------------------------------- sub Thanks { print <Election 2000 $header  

To:   $in{firstname} $in{lastname}

Thank you for voting. (One more vote for "$in{pres}"). ok } # end Thanks #--------------------------------------------------------------- sub ClosePage { # This closes the HTML page. print < end } # end ClosePage #---------------------------------------------------------------