Make your own free website on Tripod.com
#!/usr/bin/perl # * put your path to perl5 above * # ======================================================================== # *Final Four Pool Script* entry.cgi # # FRONTEND - The frontend of this script displays a HTML/JavaScript # document that lets them make their picks. Then the submitted # form is sent here. # # BACKEND - Picks are sent here. Then they are emailed to the person and put into # the appropriate log file on the server. # # script courtesy of http://www.infohiway.com/javascript # ======================================================================== MAIN: { $url = 'http://www.furman.edu/~ggallowa/tourney/standing.cgi'; #full Internet URL to standing.cgi $path1 = "entries.log"; # path of entries.log file $path3 = "teams.log"; # path of teams.log file $path4 = "started.log"; #path to started.log file $mailer = "/usr/lib/sendmail"; #path to your mail program $webmaster = 'webmaster_email@server.com'; #your email address ##### NOT NECESSARY TO CHANGE ANYTHING BELOW THIS POINT ######### $| = 1; #no buffering of output # if tourney has started, don't let them enter if (-s $path4 > 5) { print STDOUT "Content-type: text/html\n\nSorry, but the tournament has " . "already started. It is too late for you enter your picks. Try again next " . "year."; exit; } &getInput; if (scalar keys %input >= 63) { open(FILE, "$path1") or die "can't open $path1 for reading"; @others = ; close(FILE); if (scalar grep(/^$input{fullname}\|/i,@others) > 0) { print STDOUT "Content-type: text/html\n\nSomeone by the same name has " ."already entered his picks. If that person is not you, change your name slightly " ."(add your middle initial or something) and re-submit your picks. Otherwise, " ."please only make one set of picks."; } else { &backend; } } else { open(TEAMS,$path3); @teams = ; $teams = join("",@teams); close(TEAMS); if (length($teams) < 10) { print STDOUT "Content-type: text/html\n\nThe tournament bracket has " . "not yet been input set up for you. Check back soon."; } else { &frontend; } } exit; } sub frontend { print STDOUT "Content-type: text/html\n\n"; print STDOUT < Final Four Pool - Make Your Picks! Scoring: A correctly chosen round one pick will earn you 1 point. Upset picks will earn you a bonus of the seeding differential between the two involved teams. (e.g. If the number 10 seeded team beats the number 7 seeded team in the first round, you will receive 1+(10-7)=4 points). Correct round 2 picks receive 2 points, and so on. The upset seeding differential will no longer be counted when we get to the final four. Here's a scoring summary: Round 1 - 1 point + upset seeding differential Round 2 - 2 points + upset seeding differential Round 3 - 3 points + upset seeding differential Round 4 - 4 points + upset seeding differential Round 5 - 5 points Round 6 - 6 points Please make your picks and click the submit button at the bottom. If you do not see a bracket with pop up boxes below, you need to get Netscape 3 or greater or Internet Explorer 4 or greater in order to enter this pool. Script provided free by Infohiway's Cut and Paste JavaScript (and Perl). EOT } sub backend { $delim = "|"; open(FILE, ">>$path1") or die "can't open $path1 for appending"; if ($input{semis} == 0) { @z = ("s","w","e","m"); } elsif ($input{semis} == 1) { @z = ("s","e","w","m"); } else { @z = ("s","m","w","e"); } print FILE "$input{fullname}$delim$input{email}$delim" . "$input{$z[0].'11'}$delim$input{$z[0].'12'}$delim$input{$z[0].'13'}$delim$input{$z[0].'14'}$delim" #round 1 . "$input{$z[0].'15'}$delim$input{$z[0].'16'}$delim$input{$z[0].'17'}$delim$input{$z[0].'18'}$delim" #round 1 . "$input{$z[1].'11'}$delim$input{$z[1].'12'}$delim$input{$z[1].'13'}$delim$input{$z[1].'14'}$delim" #round 1 . "$input{$z[1].'15'}$delim$input{$z[1].'16'}$delim$input{$z[1].'17'}$delim$input{$z[1].'18'}$delim" #round 1 . "$input{$z[2].'11'}$delim$input{$z[2].'12'}$delim$input{$z[2].'13'}$delim$input{$z[2].'14'}$delim" #round 1 . "$input{$z[2].'15'}$delim$input{$z[2].'16'}$delim$input{$z[2].'17'}$delim$input{$z[2].'18'}$delim" #round 1 . "$input{$z[3].'11'}$delim$input{$z[3].'12'}$delim$input{$z[3].'13'}$delim$input{$z[3].'14'}$delim" #round 1 . "$input{$z[3].'15'}$delim$input{$z[3].'16'}$delim$input{$z[3].'17'}$delim$input{$z[3].'18'}$delim" #round 1 . "$input{$z[0].'21'}$delim$input{$z[0].'22'}$delim$input{$z[0].'23'}$delim$input{$z[0].'24'}$delim" #round 2 . "$input{$z[1].'21'}$delim$input{$z[1].'22'}$delim$input{$z[1].'23'}$delim$input{$z[1].'24'}$delim" #round 2 . "$input{$z[2].'21'}$delim$input{$z[2].'22'}$delim$input{$z[2].'23'}$delim$input{$z[2].'24'}$delim" #round 2 . "$input{$z[3].'21'}$delim$input{$z[3].'22'}$delim$input{$z[3].'23'}$delim$input{$z[3].'24'}$delim" #round 2 . "$input{$z[0].'31'}$delim$input{$z[0].'32'}$delim" #round 3 . "$input{$z[1].'31'}$delim$input{$z[1].'32'}$delim" #round 3 . "$input{$z[2].'31'}$delim$input{$z[2].'32'}$delim" #round 3 . "$input{$z[3].'31'}$delim$input{$z[3].'32'}$delim" #round 3 . "$input{$z[0].'41'}$delim$input{$z[1].'41'}$delim$input{$z[2].'41'}$delim$input{$z[3].'41'}$delim" #round 4 . "$input{f11}$delim$input{f12}$delim$input{f21}\n"; #final four close(FILE); $str = "$input{fullname}, thank you for entering. If you would like" . " to check the standings when the tourney starts, see:\n\n" . "$url\n\nHere are your picks:\n\n\n" . "ROUND 1\n" . "(1 point for correct picks + upset seeding differential*)\n\n" . "$input{$z[0].'11'}\n$input{$z[0].'12'}\n$input{$z[0].'13'}\n$input{$z[0].'14'}\n" #round 1 . "$input{$z[0].'15'}\n$input{$z[0].'16'}\n$input{$z[0].'17'}\n$input{$z[0].'18'}\n" #round 1 . "$input{$z[1].'11'}\n$input{$z[1].'12'}\n$input{$z[1].'13'}\n$input{$z[1].'14'}\n" #round 1 . "$input{$z[1].'15'}\n$input{$z[1].'16'}\n$input{$z[1].'17'}\n$input{$z[1].'18'}\n" #round 1 . "$input{$z[2].'11'}\n$input{$z[2].'12'}\n$input{$z[2].'13'}\n$input{$z[2].'14'}\n" #round 1 . "$input{$z[2].'15'}\n$input{$z[2].'16'}\n$input{$z[2].'17'}\n$input{$z[2].'18'}\n" #round 1 . "$input{$z[3].'11'}\n$input{$z[3].'12'}\n$input{$z[3].'13'}\n$input{$z[3].'14'}\n" #round 1 . "$input{$z[3].'15'}\n$input{$z[3].'16'}\n$input{$z[3].'17'}\n$input{$z[3].'18'}\n\n\n" #round 1 . "ROUND 2\n" . "(2 points for correct picks + upset seeding differential*)\n\n" . "$input{$z[0].'21'}\n$input{$z[0].'22'}\n$input{$z[0].'23'}\n$input{$z[0].'24'}\n" #round 2 . "$input{$z[1].'21'}\n$input{$z[1].'22'}\n$input{$z[1].'23'}\n$input{$z[1].'24'}\n" #round 2 . "$input{$z[2].'21'}\n$input{$z[2].'22'}\n$input{$z[2].'23'}\n$input{$z[2].'24'}\n" #round 2 . "$input{$z[3].'21'}\n$input{$z[3].'22'}\n$input{$z[3].'23'}\n$input{$z[3].'24'}\n\n\n" #round 2 . "ROUND 3 - Sweet Sixteen\n" . "(3 points for correct picks + upset seeding differential*)\n\n" . "$input{$z[0].'31'}\n$input{$z[0].'32'}\n" #round 3 . "$input{$z[1].'31'}\n$input{$z[1].'32'}\n" #round 3 . "$input{$z[2].'31'}\n$input{$z[2].'32'}\n" #round 3 . "$input{$z[3].'31'}\n$input{$z[3].'32'}\n\n\n" #round 3 . "ROUND 4 - Great Eight\n" . "(4 points for correct picks + upset seeding differential*)\n\n" . "$input{$z[0].'41'}\n$input{$z[1].'41'}\n$input{$z[2].'41'}\n$input{$z[3].'41'}\n\n\n" #round 4 . "ROUND 5 - Semi-finals\n" . "(5 points for correct picks)\n\n" . "$input{f11}\n$input{f12}\n\n\n" #semi-finals . "ROUND 5 - Finals\n" . "(6 points for the correct pick)\n\n" . "$input{f21}\n\n\n" #final four . "* The \"upset seeding differential\" only applies for rounds 1-4. If\n" . "the number 10 seeded team beats the number 7 seeded team, there is a\n" . "difference of 3 in their seedings. Since it was an upset victory\n" . "and you picked it correctly, you get 3 bonus points for that game.\n\n\n\n" . "------\nThis pool script provided freely by Infohiway's Cut and Paste JavaScript\n" . "http://www.infohiway.com/javascript"; open(MAIL,"|$mailer -t"); print MAIL "To: $input{email}\n"; #### comment out this following line if you don't want to receive everyone's picks over email print MAIL "CC: $webmaster\n"; print MAIL "From: $webmaster\n"; print MAIL "Reply-To: $webmaster\n"; print MAIL "Subject: $input{fullname}'s NCAA Tourney Picks\n\n"; print MAIL $str; close (MAIL); $str =~ s/\n/ \n/g; print STDOUT "Content-type: text/html\n\n"; print STDOUT "" . "Note: Do not attempt to bookmark this page, because this information will not be here " . "if you return later. This exact same information has just been emailed to you.\n\n\n" . "$str"; } sub getInput { my($allInput, @allPairs, $pair, $label, $value); #parse the variable buffer both get and post if ($ENV{'REQUEST_METHOD'} eq "GET") { $allInput = $ENV{'QUERY_STRING'}; } else { read(STDIN,$allInput,$ENV{'CONTENT_LENGTH'}); } @allPairs = split(/&/,$allInput); while (@allPairs) { $pair = shift @allPairs; ($label, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; if ($input{$label}) { $input{$label} .= "\|$value"; } else { $input{$label} = $value; } } }