#!/usr/bin/perl # NOTE: the above line must be changed to show the path to the # Perl interpreter on your system! Leave the #! as is, but # the path may have to be changed if yours is different. ######################################################################### # Votesie 1.1.1 01/04/2004 # # A simple voting/polling script. Lets visitors to a website vote on # # a question, and view the total results. Admin can configure new polls,# # including the color scheme and look of the Poll and Results pages. # # # # Copyright 1999, Kristina L. Pfaff-Harris, http://tesol.net/scripts/ # # All rights reserved. # # # ######################################################################### ##### License for Votesie 1.1.1 ##### ##### This program may be used free of charge under the following ##### conditions: ##### ##### 1. All instructions and Copyright lines must remain unchanged. ##### ##### 2. All pages generated by the program must contain one of the ##### following pieces of HTML code: ##### ##### Powered by Votesie: ##### ##### http://www.tesol.net/scripts ##### OR: ##### ##### ##### ##### You may not remove the information described above from the script ##### without express written permission from the author. ##### ##### 3. You may not sell or distribute this program. You may charge ##### a reasonable fee for installing it for a client as long as ##### you make it clear that you are not the author, and you are ##### not selling the program to them: only charging for installing ##### it. ##### ##### 4. You agree that this program is offered without warranty of ##### any kind, including warranty of fitness for a particular ##### purpose. You further agree that the author and all sites ##### associated in any way with this program are not liable for ##### any damage or loss incurred as a result of using this program. ##### ##### 5. You may modify the program for your own use but you may not ##### distribute modified copies under any circumstances without ##### express written permission from the author. ##### ##### 6. Use of this program requires agreement to all the terms and ##### conditions of this license. If you do not agree to one or ##### more of these terms, you may not use the program. ##### ########################################################################## # # Using the program: # # This program requires the files "votesie.cgi", and text files # # votesie_votes.txt and votesie_voters.txt for storing the poll results.# # # # In this program (the file you're looking at now), I # # have put **CHANGE** wherever the program needs to be modified. If # # your editor can search for text, you can easily find what to change # # and how to change it. You must follow the instructions for how to # # change things. This is a program, and as such, can get quite fussy # # about very small syntax errors. # # # # Permissions: The votesie.cgi file must be "chmod 755". In # # addition, your "votesie_votes" should be writeable by the web server. # # This usually means making it chmod 766. If you don't know how to do # # this, ask your system administrator. # # # # Where these files go depends on how your web server is set up. # # Sometimes, all cgi files MUST be in the "official" cgi-bin # # directory. Other times, the files can be anywhere as long as # # they end in ".cgi". Again, check with your system administrator # # to see where you need to put this. # # # ######################################################################### # # # I hope this program proves useful to you! Please contact me # # (http://tesol.net/scriptmail.html) for any bugs or feedback. # # # ######################################################################### print "Content-type: text/html\n\n"; %data = &get_data(); ######################################################################### # # # BEGIN SECTION WHERE YOU NEED TO CHANGE THINGS # # # # In this next section, there are various things that you need to # # change in order to get the program to work the way you'd like it to. # # Don't worry: each variable has an explanation of what it does and # # what you'll need to do in order to change it. Be careful of things # # like " and ; and be sure to read the instructions. If you do this, # # then you should be fine! # # # ######################################################################### # First of all, let's determine if we want to enable some debugging # information. This can be very useful when you are first setting up # the program, as it can tell you whether or not the program can find # your "votesie_votes" and whether it can add entries to it. If you're # done installing Votesie, and it seems to be working, **CHANGE** this to: # $debugging = "0"; # Otherwise, you should leave it set to "1", so that you can see any errors # that are happening while you're setting it up. $debugging = "1"; # Next, you need to decide whether you want to try and keep # people from "stuffing the ballot box." This is based on the IP # address of the user that is voting, and so, for many reasons, # is not foolproof. Since many Internet Service Providers use # "dynamically assigned" IP addresses, then two different users # could conceivably hit your site with the same address, in which # case, the second user could not vote. By the same token, the same # user could have a different address the next time they get on # the Internet, and so could vote again. On the other hand, this # will keep a single user from just reloading the votes results # page over and over to add votes to their favorite answer. If # you want the program to NOT count votes from the same IP # address, **CHANGE** $dup_check = "off"; to $dup_check = "on"; # For those of you who know about proxying, the program does # take into account the "HTTP_X_FORWARDED_FOR" header, so that # people behind a firewall will not be unfairly penalized by the # IP check. $dup_check = "on"; # The next few "$javascript_whatever" options are in case you would like # the results of the poll displayed in a little JavaScript popup window. # If you would like the poll results to be displayed in a little popup # window, set $javascript_popup = "yes"; Otherwise, just leave it set # to "no". $javascript_popup = "yes"; # Assuming that you have set $javascript_popup = "yes"; above, and would # like the nice popup window, the next two items let you determine the # width and height of the results window. I think that 400 wide by # 230 high is more or less good for most purposes, but if you would like # it smaller or larger, then change the number 400 and/or 230 to whatever # number you feel is appropriate. # $javascript_popupwidth is the width of the popup window: $javascript_popupwidth = "400"; # $javascript_popupheight is the height of the popup window: $javascript_popupheight = "230"; # Okay, now I have tried to set this up so that if you use the JavaScript # popup window, it will still work if people don't have JavaScript. However, # if your visitors have problems with the JavaScript, then you can still # set $javascript_popup to no, and still have the results open in a new # window. If you set $results_in_new_window = "yes"; then the results # will open in another browser window. If you set it to "no", then the # results will open in the same window as the poll. You probably won't # need to change this. $results_in_new_window = "yes"; # $votesie_votes is the system path to the file that contains the # current poll + votes. This is NOT a URL, and must NOT begin with # "http://". It should begin with "/". **CHANGE** this to the system # path to your votesie_votes file. (The file must be chmod 766) # Sometimes, the setting I have below will work fine for you. (Try it # and see.) Otherwise, it should be something like: # Unix: # $votesie_votes = "/home/users/your/www/directory/votesie_votes.txt"; # Windows: # $votesie_votes = "c:/Inetpub/wwwroot/your_directory/votesie_votes.txt"; # # Note that on some operating systems, what I have below might work if # the "votesie_votes" file in the same directory as this program. # IMPORTANT: If your file does not end with ".txt" then you # will need to make the filename below match what you actually have # on your server, and vice versa. It does not matter what these files # are called, as long as what is on the server EXACTLY matches # what is listed in the script. $votesie_votes = "./votesie_votes.txt"; # $voters should be, like $votesie_votes above, the full path to # the "votesie_voters.txt" file. This file will keep track of users' # IP addresses for each issue in case you care to turn duplicate # checking on. **CHANGE** this to the path to votesie_voters on # your server. NOTE: If your file does not end with ".txt" then you # will need to make the filename below match what you actually have # on your server, and vice versa. It does not matter what these files # are called, as long as what is on the server EXACTLY matches # what is listed in the script. $voters = "./votesie_voters.txt"; # $path_to_poll_files is the system path to the directory where you # want the program to create your poll files. As with $votesie_votes # above, this should begin with "/" (on a Unix-based system) and should # probably begin with "c:" or "d:" or similar on an NT-based system. # It must not end with "/" or "\\". If # you use the same path conventions as with votesie_votes above, you # should be fine. **CHANGE** this to something appropriate for your # site. $path_to_poll_files = "/path/to/your/directory/for/polls"; # $votesie_url is what you would type in a browser to view files # in the directory above (path_to_poll_files). This should begin # with "http://" and should NOT end with a "/" and should NOT end # with ".html". **CHANGE** this to something appropriate for your site. $votesie_url = "http://your_domain.edu/directory/for/polls"; # $cgi_url is the full http URL to the votesie.cgi program # (this program) on your web server. It should begin with # http:// and end with "votesie.cgi". Note: On NT-based systems, # you may have to rename votesie.cgi to votesie.pl. If this is the # case, then the below should end with "votesie.pl" or whatever the # filename of this program is. **CHANGE** this...well, you get the idea. $cgi_url = "http://your_domain.edu/votesie.cgi"; # $admin_password is the password you will use to add new polls, # archive old ones, and otherwise administer the system. # **CHANGE** this to an appropriate password that would not # be easily guessed. For example: # $admin_password = "BX9mlkj7"; # $admin_password = "H0oHa4"; # etc... $admin_password = "password"; # Here, we will define our HTML header. You can monkey about with the # HTML code here so that it looks like that of your page. WARNING: # any " (quotes) or @ ("at" signs) must have a \ (backslash) in front # of them. Please be very careful if you modify the HTML code here -- # just one free " and the script will never run. You can put anything # you like in between the and lines. This is only really used on the admin screens. # You may **CHANGE** this to something that will fit in with the look # of the rest of your site. Please see the FAQ at http://tesol.net/scripts/FAQ # for more detailed information about what to do with $header and so forth. $header = " Votesie v1.1.1

Votesie v1.1.1


"; #<-- This quote and semicolon are necessary! Don't backslash them! # Now define our HTML footer. As before, you may change the html # code, but be careful of " and @ signs. Please leave the copyright # notice and the address of Scripts for Educators so that other # people can find and use this program. **CHANGE** this if you # wish, bearing in mind the caveats from $header above. $footer = " "; #<-- This quote and semicolon are necessary! Don't backslash them! # Okay this is the last thing that needs to be changed. If, for some reason, # someone pulls up "votesie.cgi" all by itself, we'll give them a list of # polls currently on the system. However, we won't have the colors # available since each poll is created with custom colors, so we'll need # to know how to display a poll if it's just by itself. Also, if you don't # want to have to check a color box when creating a poll, it will just create # polls with the colors that you fill in below. These colors need to be # HTML "hex" colors WITHOUT the "#", or strange things will happen. # You might just leave this the way it is, if you don't mind how it looks. # $even_color is the background color for the even-numbered rows in the # list of polls available. (E.g. 2, 4, 6, 8 ...) $even_color = "FFFFFF"; # $odd_color is the background color for the odd-numbered rows in the # list of polls available. (E.g. 1, 3, 5, 7 ...) $odd_color = "EEEEFF"; # $default_header_color is the background color for the Poll question $default_header_color = "0000FF"; # $default_font_color is the color of the text for the Poll question $default_font_color = "FFFFFF"; # $default_poll_area_color is the background color of the main section of # the poll where the options appear. $default_poll_area_color = "FFFFFF"; # $default_poll_font_color is the color of the text in the main poll area. $default_poll_font_color = "000000"; # $default_results_color is the background color of the main results area. $default_results_color = "FFFFFF"; # $default_results_font_color is the color of the text in the main results area. $default_results_font_color = "000000"; # $default_results_bar_color is the color of the bars on the results area $default_results_bar_color = "0000FF"; # $results_bar_style is whether or not you'd like solid or lined bars. Try # it both ways to see which you prefer. To use solid bars, set # $results_bar_style = "solid"; # To use lined bars, set # $results_bar_style = "lined"; $results_bar_style = "solid"; # $default_border_color is the color of the border around the poll $default_border_color = "000000"; ######################################################################### # # # END SECTION WHERE YOU NEED TO CHANGE THINGS # # # # You should not need to change anything beyond this point, unless # # you know quite a bit about Perl and are making specific changes # # to the code. # # # ######################################################################### # Let's do some error checking... # First, this is just so people can't delete stuff on my server with # the demo. :-) if($ENV{'SERVER_NAME'} =~ /tesol.net/i || $ENV{'SERVER_NAME'} =~ /linguistic-funland.com/i || $ENV{'HTTP_HOST'} =~ /linguistic-funland.com/i || $ENV{'HTTP_HOST'} =~ /tesol.net/i){ $header .= "
Note: Deleting is disabled in this demo. You can go through and delete stuff, and it will tell you that it has successfully deleted the files, but it won't actually do it.

"; } &check_version; &debug("Make sure to set \$debugging = \"0\" when the program gets up and running so that you will not see these messages any more.
"); &debug("Perl version is $]"); # Actually, what you see as "number 1" in the list of polls # is actually "number 0" as far as the script is concerned. # Therefore, what you THINK is an odd or even number is wrong. # Things are numbered 0, 1, 2, 3 instead of 1, 2, 3, 4, so this # will always be a bit off. However, this is really difficult to # explain sometimes, so we'll just let people tell us what they # want for odd and even colors above, and we'll switch it here # so that it works the way they expect. $even1 = $odd_color; $odd1 = $even_color; $even_color = $even1; $odd_color = $odd1; if($ENV{'SERVER_SOFTWARE'} ne ""){ &debug("Your web server is $ENV{'SERVER_SOFTWARE'}."); } if($^O ne ""){ &debug("Your operating system is $^O"); if($^O =~ /win/i){ &debug("You appear to be running a Windows-based web server. My condolences."); } } &config_error(); # If you remove this link, without replacing it with a similar # HTML comment (as above in the License section) you are in violation # of the license for this program. So don't take it out unless # you're in compliance with the license as noted above. :-) # And honestly, since you didn't have to pay for this, is the link # really too much to ask? :) If so, there are about a bazillion # other free scripts out there: just use one of them instead. # Thanks. :-) $footer = "
Votesie! v1.1.1 is copyright 1999 Kristina Pfaff-Harris and can be found at http://www.tesol.net/scripts/
$footer"; # If no colors were entered, use the default. if($data{'headercolor'} eq ""){$data{'headercolor'} = "#$default_header_color";} if($data{'headerfontcolor'} eq ""){$data{'headerfontcolor'} = "#$default_header_font_color";} if($data{'resultcolor'} eq ""){$data{'resultcolor'} = "#$default_results_color";} if($data{'resultfontcolor'} eq ""){$data{'resultfontcolor'} = "#$default_results_font_color";} if($data{'headercolor'} eq ""){$data{'headercolor'} = "#$default_header_color";} if($data{'headerfontcolor'} eq ""){$data{'headerfontcolor'} = "#$default_font_color";} if($data{'pollcolor'} eq ""){$data{'pollcolor'} = "#$default_poll_area_color";} if($data{'pollfontcolor'} eq ""){$data{'pollfontcolor'} = "#$default_poll_font_color";} if($data{'barcolor'} eq ""){$data{'barcolor'} = "#$default_results_bar_color";} if($data{'bordercolor'} eq ""){$data{'bordercolor'} = "#$default_border_color";} if($results_bar_style eq "solid"){ $results_bar_style = " style=\"background-color: $data{'barcolor'}\""; } else { $results_bar_style = ""; } if($ENV{'QUERY_STRING'} eq "$admin_password"){ $password = $admin_password; $header = "$header
Admin Main Menu
"; $footer = "
Admin Main Menu
$footer"; &admin_login_screen; } elsif($ENV{'QUERY_STRING'} eq "$admin_password" || $data{'password'} eq "$admin_password"){ $password = $admin_password; $header = "$header
Admin Main Menu
"; $footer = "
Admin Main Menu
$footer"; if($data{'NewPoll'}){ &newpoll; } elsif($data{'FA'} eq "Del"){ &delete_poll; } elsif($data{'FA'} eq "DelPollFiles"){ &delete_poll_html_files; } else{ &admin_login_screen; } } elsif($data{'FA'} eq "ShowPoll"){ &show_poll; } else { # The subroutine "write_to_votesie_votes" adds the entry to the votesie_votes. &write_to_votesie_votes unless $data{'Vote'} eq ""; &show_results unless $data{'ShowResults'} ne "Yes"; $poll_links = &show_poll_links(); print "$header

Welcome to the Voting Booth!

The following $number_of_polls polls are available:

$poll_links


Please choose one or go back and try again."; &debug("Debugging information follows: "); foreach $key (keys(%ENV)){ &debug("$key $ENV{$key}"); } print "


$footer"; exit(); } sub write_to_votesie_votes { # First, if dup checking is on, check and see if someone at this # address has voted already.. if($dup_check =~ /on/i){ $stuffer = &check_dup_voters($data{'Question'}); } # Okay, now, we're going to open up our question/answer database # and record the response. # First, open the file and find the question... undef $/; open(FILE, "+<$votesie_votes") || &debug("Could not open (votes database) $votesie_votes for writing $!"); if($^O =~ /win/i){ binmode(FILE); } else { flock(FILE, 2) || &debug("Oops, could not lock $votesie_votes $!"); } $contents = ; @contents = split(/\n/, $contents); seek(FILE, 0, 0); if($stuffer != 1){ # If not, then we want to look through each line to find the question that # is being voted on so we can add the new result. foreach $content (@contents){ $content =~ s/\n//g; if($content =~ /^\Q$data{'Question'}\E/){ ($question,@answers) = split(/\|/, $content); $line_to_print .= "$question|"; foreach $answer (@answers){ ($resp,$numresp) = split(/%%/, $answer); $numresp =~ s/\s//g; $resp =~ s/\s+$//; if($resp =~ /\Q$data{'Vote'}\E/){ $numresp = $numresp + 1; } $line_to_print .= "$resp %% $numresp|" if $resp ne ""; } print FILE "$line_to_print\n"; $line_to_print = ""; } else { print FILE "$content\n"; } } close(FILE); } # end if ... $/ = "\n"; } sub show_results { if($stuffer == 1){ $stuffermsg = "Looks like you may have already voted. Vote not counted."; } open(FILE, "$votesie_votes") || &debug("Ack! I can't read the votesie_votes file! $!"); @contents = ; GETCON: foreach $con (@contents){ if($con =~ /^\Q$data{'Question'}\E/){ $line = $con; last GETCON; } } close(FILE); $line =~ s/\n//; ($question,@answers) = split(/\|/, $line); print "$stuffermsg
"; pop(@answers) if $answers[$#answers] eq ""; foreach $answer (@answers){ ($resp,$numresp) = split(/%%/, $answer); $numresp =~ s/\s//g; $totalvotes = $totalvotes + $numresp; } foreach $answer (@answers){ ($resp,$numresp) = split(/%%/, $answer); $numresp =~ s/\s//g; if($totalvotes > 0){ $percent = int((($numresp / $totalvotes) * 100) + 0.5); } else { $percent = 0; } $totalpercent = $totalpercent + $percent; if($totalpercent > 100){ $howmuchover = $totalpercent - 100; $percent = $percent - $howmuchover; $totalpercent = 100; } if($answer eq $answers[$#answers] && $totalpercent < 100){ $howmuchover = 100 - $totalpercent; $percent = $percent + $howmuchover; $totalpercent = 100; } print ""; } print "
   Results:$question   
$resp "; for($i = 1; $i <= $percent; $i++){ print "|" unless $ENV{'HTTP_USER_AGENT'} =~ /lynx/i; } print " $numresp / $percent %
$totalvotes votes total: $totalpercent %
Powered by Votesie!

Back..."; exit(); } sub debug { if($debugging =~ /yes/i || $debugging == 1){ print "DEBUGGING INFO: $_[0]
\n"; } } sub get_data { local($string); # get data if ($ENV{'REQUEST_METHOD'} eq 'GET') { $string = $ENV{'QUERY_STRING'}; } else { read(STDIN, $string, $ENV{'CONTENT_LENGTH'}); } # split data into name=value pairs @data = split(/&/, $string); # split into name=value pairs in associative array foreach (@data) { split(/=/, $_); $_[0] =~ s/\+/ /g; # plus to space $_[0] =~ s/%00//g; # We don' need no steenking nulls :) $_[0] =~ s/%0a/newline/g; $_[0] =~ s/%(..)/pack("c", hex($1))/ge; # hex to alphanumeric if(defined($data{$_[0]})){ $data{$_[0]} .= "\0"; $data{$_[0]} .= "$_[1]"; } else { $data{"$_[0]"} = $_[1]; } } # translate special characters foreach (keys %data) { $data{"$_"} =~ s/\+/ /g; # plus to space $data{"$_"} =~ s/%00//g; # We don' need no steenking nulls :) $data{"$_"} =~ s/%0a/newline/g; $data{"$_"} =~ s/%(..)/pack("c", hex($1))/ge; # hex to alphanumeric } %data; # return associative array of name=value } sub admin_login_screen { my $poll_links = &show_poll_links("admin"); print "$header
Welcome admin!

"; print <

Or, delete a poll from the database below:
$poll_links
$footer EOF # KPH exit(); } sub newpoll { if($data{'NewPoll'} ne "" && $data{'NumResp'} eq ""){ $pollcolorblock = &generate_color_block(pollcolor,$default_poll_area_color); $pollfontcolorblock = &generate_color_block(pollfontcolor,$default_poll_font_color); $headercolorblock = &generate_color_block(headercolor,$default_header_color); $headerfontcolorblock = &generate_color_block(headerfontcolor,$default_font_color); $barcolorblock = &generate_color_block(barcolor,$default_results_bar_color); $bordercolorblock = &generate_color_block(bordercolor,$default_border_color); $resultcolorblock = &generate_color_block(resultcolor,$default_results_color); $resultfontcolorblock = &generate_color_block(resultfontcolor,$default_results_font_color); print <Create a New Poll

$error

What will the question/issue for the poll be?

Now, please tell us the number of possible responses for your poll so we can generate the right form for you to fill in:

Votesie generates its polls in a table format as shown to the right. Please choose from some of the following options so that you can have your table look the way you wish:

Header Color: (    )
$headercolorblock
Header Font Color: (    )
$headerfontcolorblock
Main Poll Area Color: (    )
$pollcolorblock
Font color for Main Poll Area: (    )
$pollfontcolorblock
Background color for Results page: (    ) $resultcolorblock
Font Color for Results page: (    )
$resultfontcolorblock
Color for the bars on the bar graph: (    )
$barcolorblock
Color for the border around the boxes: (    )
$bordercolorblock

 
 
 
Example Poll Window
What is your favorite color?
Red
Blue
Yellow
None

Example Results Window

   Results: What is your favorite color?   
 
Red |||||||||||||||| 730 / 16%
Blue |||||||||||||||||||||||||||||| 1369 / 30%
Yellow |||||||||||||||||||||||||||||||||||||||| 1825 / 40%
None |||||||||||||| 638 / 14%
4,562 votes total
Powered by Votesie!
$footer EOF exit(); } elsif($data{'NumResp'} ne "" && $data{'GenerateForm'} ne ""){ &dup_poll_create_check; print "$header
Create a New Poll: Step 2

Here is what your poll and results windows will look like with the color scheme you've chosen. If you don't like the looks of it, just hit the \"back\" button on your browser and select different colors. Your poll will not be created until you finish with this screen.

\"$data{'PollQuestion'}\"

(Please enter the possible responses in the spaces below.)

"; for ($i = 1; $i <= $data{'NumResp'}; $i++){ print "
\n"; } print "

Example Poll Window
$data{'PollQuestion'}
Answer 1
Answer 2
Answer 3
None
Example Results Window
   Results: $data{'PollQuestion'}   
 
Answer 1 |||||||||||||||| 730 / 16%
Answer 2 |||||||||||||||||||||||||||||| 1369 / 30%
Answer 3 |||||||||||||||||||||||||||||||||||||||| 1825 / 40%
Answer 4 |||||||||||||| 638 / 14%
4,562 votes total
Powered by Votesie!
$footer"; exit(); } elsif($data{'PollQuestion'} ne "" && $data{'Resp1'} ne ""){ &dup_poll_create_check(); # Use a database # |Question|answerx %% numresp|answery %% numresp etc... open(FILE, ">>$votesie_votes") || &debug("Can't open $votesie_votes! The system said: $!"); if($^O !~ /win/i){ binmode(FILE); } else { flock(FILE,2) || &debug("Can't lock the votesie_votes file. $!"); } seek(FILE, 0, 2); print FILE "$data{'PollQuestion'}|"; for($i = 1; $i <= $data{'NumResp'}; $i++){ $name = "Resp" . $i; print FILE "$data{$name} %% 0|" unless $data{$name} eq ""; } print FILE "\n"; close(FILE); open(FILE, ">>$voters") || &debug("Can't open $voters! The system said: $!"); if($^O !~ /win/i){ binmode(FILE); } else { flock(FILE,2) || &debug("Can't lock the votesie_votes file. $!"); } seek(FILE, 0, 2); print FILE "$data{'PollQuestion'}\n"; close(FILE); open(FILE, ">$path_to_poll_files/poll$$.html") || &debug("Can't open poll! $!"); if($^O !~ /win/i){ binmode(FILE); } else { flock(FILE,2) || &debug("Can't lock the votesie_votes file. $!"); } # Okay, all this stuff here is if you chose the options for # $javascript_popup. Basically, this prints out some Javascript for # the colors and so forth that you chose for the poll, and makes it so # that it will pop up the results in a new window. I'm sure this probably # could be done better, but hey: I do Perl, not JavaScript. :-) if($javascript_popup eq "yes"){ print FILE < function votesie_popup () { var vurl_string = '$cgi_url?Question='; vurl_string += escape(document.Votesie.Question.value); vurl_string += '&ShowResults=Yes&Vote='; for (var i = 0; i < document.Votesie.Vote.length; i++){ if(document.Votesie.Vote[i].checked){ vurl_string += escape(document.Votesie.Vote[i].value); } } vurl_string += '&headercolor='; vurl_string += escape(document.Votesie.headercolor.value); vurl_string += '&headerfontcolor='; vurl_string += escape(document.Votesie.headerfontcolor.value); vurl_string += '&pollcolor='; vurl_string += escape(document.Votesie.pollcolor.value); vurl_string += '&pollfontcolor='; vurl_string += escape(document.Votesie.pollfontcolor.value); vurl_string += '&resultcolor='; vurl_string += escape(document.Votesie.resultcolor.value); vurl_string += '&resultfontcolor='; vurl_string += escape(document.Votesie.resultfontcolor.value); vurl_string += '&barcolor='; vurl_string += escape(document.Votesie.barcolor.value); vurl_string += '&bordercolor='; vurl_string += escape(document.Votesie.bordercolor.value); window.open(vurl_string,'Votesie','width=$javascript_popupwidth,height=$javascript_popupheight,left=0,top=0,toolbar=no,scrollbars=no,resizable=yes,status=no,directories=no,menubar=no,location=no'); return false; } EOF $formtag = "

"; $formbutton = ""; } else { if($results_in_new_window eq "yes"){ $target = " target=\"_blank\""; } $formtag = ""; $formbutton = ""; } print FILE "$javascript$formtag
"; for($i = 1; $i <= $data{'NumResp'}; $i++){ $name = "Resp" . $i; print FILE " " unless $data{$name} eq ""; } print FILE "\n\t\t
$data{'PollQuestion'}
$data{$name}
$formbutton
"; close(FILE); print "$header
Poll Created!

NOTE: The below is the message Votesie gives you when you've set up a poll on YOUR site. Please don't use this to create a poll and just link to it on my server, as all test polls are periodically deleted. Thanks!
Your poll has been created and can be found at: $votesie_url/poll$$.html. You may copy and paste it into another web page, or just link to it where it lies. It will look like this: \n\n\n"; open(FILE, "$path_to_poll_files/poll$$.html"); while(){ print; $_ =~ s//>/sg; $htmlstring .= $_; } close(FILE); print "\n\n\n
You may also copy and paste the following HTML code into your page:

<!-- Poll starts here -->\n$htmlstring\n<!-- Poll ends here -->

$footer"; exit(); } } sub archivepoll { print "$header
Feature Unavailable

Sorry, but this feature is currently unavailable. $footer"; exit(); } sub viewarchive { print "$header

Feature Unavailable

Sorry, but this feature is currently unavailable. $footer"; exit(); } sub generate_color_block { local($name,$default) = @_; $colorblock = "
                 
                 
"; $colorblock; } sub check_dup_voters { local($o_poll,$poll,$host,$addr,$squid,@voters,@addrs); $poll = $_[0]; # get remote host # get remote addr $host = $ENV{'REMOTE_HOST'}; $addr = $ENV{'REMOTE_ADDR'}; # Get squid "real" header if present $squid = $ENV{'HTTP_X_FORWARDED_FOR'}; open(VFILE, "$voters") || &debug("Cannot open $voters to check IP address."); @voters = ; close(VFILE); # Geeeeeez, this is ugly. That's what you get for bug fixing bit by bit # until it works rather than fixing the code for real. :) CHECKADDR: foreach $ventry (@voters){ if($ventry =~ /^\Q$poll\E/){ ($o_poll,@addrs) = split(/\|/, $ventry); if($poll eq $o_poll){ foreach $addrs (@addrs){ $addrs =~ s/\n//g; if($addrs eq "$addr:$squid"){ $dup = 1; last CHECKADDR; } } } } } if($dup != 1){ open(VFILE, "+<$voters") || &debug("Could not open $voters for writing $!"); if($^O =~ /win/i){ binmode(VFILE); } else{ flock(VFILE,2); } @lines = ; seek(VFILE,0,0); &debug("Writing to voters"); foreach $line (@lines){ $test = $line; $test =~ s/\|.*//g; $test =~ s/\n+//g; if($test eq $poll && $line !~ /\|$ENV{'REMOTE_ADDR'}:$ENV{'HTTP_X_FORWARDED_FOR'}/){ $line .= "|$ENV{'REMOTE_ADDR'}:$ENV{'HTTP_X_FORWARDED_FOR'}"; $line =~ s/\n//g; print VFILE "$line\n"; &debug("Added address for $ENV{'REMOTE_ADDR'}:$ENV{'HTTP_X_FORWARDED_FOR'}"); } else{ print VFILE "$line"; } } close(VFILE); } $dup; } sub check_version { # Get the version of Perl and make sure it's version 5. if($] !~ /^5/){ print "Content-type: text/html\n\n"; print "Sorry, you need Perl 5 or greater to run this script. You are running $] . Please ask your local technical support people to upgrade."; exit(); } } sub show_poll { $poll = uri_unescape($data{'Poll'}); open(V, "<$votesie_votes") || &debug("could not open $votesie_votes: $!"); ($question,@opts) = split(/\|/, (grep(/\Q$poll\E\|/, ))[0]); print "
"; foreach $opt (@opts){ chomp($opt); if($opt eq ""){ next; } ($realopt, $votes) = split(/%%/, $opt); $realopt =~ s/\s+$//sg; $realopt =~ s/^\s+//sg; print ""; } print qq[ ]; print "
$question
$realopt

"; exit(); } sub show_poll_links { my $poll_links; my ($is_admin) = $_[0]; $poll_links = ""; open(V, "<$votesie_votes"); $i = 0; while(){ ($poll,@stuff) = split(/\|/, $_); if($poll eq "" || $poll =~ /^\s+$/){ next; } if($i / 2 eq int($i / 2)){ $bgc = $even_color; } else { $bgc = $odd_color; } if($is_admin){ $poll_links .= "\n"; } else { $poll_links .= "\n"; } $i++; } close(V); if($poll_links eq ""){ $poll_links .= ""; } $poll_links .= "
$poll
$poll
No polls available.
\n"; $number_of_polls = $i; $poll_links; } sub delete_poll { $poll = $data{'Poll'}; if($data{'Confirm'} ne "Yes"){ print "$header Are you sure you want to delete this poll?
$poll
"; open(F, "<$votesie_votes") || &debug("Could not open $votesie_votes for reading: $!"); while(){ if($_ =~ /^\Q$poll\E\|/s){ ($q,@answers) = split(/\|/, $_); foreach $answer (@answers){ ($ans,$votes) = split(/%%/, $answer); print "\n"; } last; } } close(F); print "
$ans

$footer"; } else { open(F, "+<$votesie_votes"); if($^O =~ /win/i){ binmode(F); } else { flock(F, 2); } while(){ if(($_ !~ /^\Q$poll\E\|/s && $_ !~ /^\s+$/) || $ENV{'SERVER_NAME'} =~ /tesol.net/i || $ENV{'SERVER_NAME'} =~ /linguistic-funland.com/i || $ENV{'HTTP_HOST'} =~ /linguistic-funland.com/i || $ENV{'HTTP_HOST'} =~ /tesol.net/i){ $newfile .= $_; } } truncate(F, length($newfile)); seek(F, 0,0); print F $newfile; close(F); $msg = "
Poll \"$poll\" deleted.
"; &admin_login_screen(); exit(); } } sub config_error { eval("use URI::Escape;"); if ($@){ $err .= "Sorry, but this program requires Perl version 5 (Your version of Perl is $]) with the URI::Escape module and your system does not appear to have the URI::Escape module installed. Please ask the technical support people or administrators of your website to install the URI::Escape module, or you will not be able to use this program.

"; } unless(-d "$path_to_poll_files"){ $err = "\$path_to_poll_files ($path_to_poll_files) does not exist, or your server does not understand how to find it. Please double check your configuration in the script, and make sure that it is correct, and is the FULL system path to a directory.
\n"; } else { unless(-w $path_to_poll_files){ $err .= "\$path_to_poll_files ($path_to_poll_files) is not writeable, meaning that I cannot create files in that directory. Try doing 'chmod 777 $path_to_poll_files' or, if you are under Windows, get your web hosting provider to make it so that your CGI programs can create files in that directory. Note that sometimes you cannot have directories chmodded 777 if they're inside your cgi-bin.
\n"; } } unless(-f $votesie_votes){ $err .= "\$votesie_votes ($votesie_votes) does not appear to exist, or is not a regular file. Please make sure that a file of this name exists on your server, or we will not be able to store information for your polls.
\n"; } unless(-w $votesie_votes){ $err .= "\$votesie_votes ($votesie_votes) does not appear to exist, or is not writeable. This means that we can't store information in it. You might try 'chmod 766 $votesie_votes' or, if you are running on a Windows server, get your web hosting provider to make it so that your CGI programs can write to this file. You may also have set up the path to this file incorrectly in the script. In this case, please fix it and try again.
\n"; } unless(-f $voters){ $err .= "\$voters ($voters) does not appear to exist, or is not a regular file. Please make sure that a file of this name exists on your server, or we will not be able to store information about who has voted in the polls in order to prevent ballot box stuffing.
\n"; } unless(-w $voters){ $err .= "\$voters ($voters) does not appear to exist, or is not writeable. This means that we can't store information in it. You might try 'chmod 766 $votesie_voters' or, if you are running on a Windows server, get your web hosting provider to make it so that your CGI programs can write to this file. You may also have set up the path to this file incorrectly in the script. In this case, please fix it and try again.
\n"; } if($err){ print "$header
FATAL ERROR!

The following configuration errors have been found. You'll need to correct these before the program can work:

$err

The following information may help you find the correct paths:

"; print "Path Translated: $ENV{'PATH_TRANSLATED'}
" if $ENV{'PATH_TRANSLATED'}; print "Script Filename: $ENV{'SCRIPT_FILENAME'}
" if $ENV{'SCRIPT_FILENAME'}; print "Document Root: $ENV{'DOCUMENT_ROOT'}
" if $ENV{'DOCUMENT_ROOT'}; print "Server Software: $ENV{'SERVER_SOFTWARE'}
" if $ENV{'SERVER_SOFTWARE'}; print "Operating System: $^O
" if $^O; print "Perl Version: $]
" if $]; print "Script Name: $ENV{'SCRIPT_FILENAME'}
" if $ENV{'SCRIPT_FILENAME'}; print "

If you're not sure what all this means, please feel free to copy and paste all this information into an email to the author at http://tesol.net/scripts/scriptmail.html and let me know what was happening when you got this message. Also, you might check the FAQ which has information about system paths, chmod, and that sort of stuff. :-)
$footer"; exit(); } } sub delete_poll_html_files { if($data{'Confirm'} ne "Blah"){ $html = "$header
Deleting Poll HTML files!

Please select the poll files you wish to delete. If you're not sure what the poll is about, click on the filename to view it. THERE IS NO CONFIRMATION BEYOND THIS POINT! Be sure you've checked the files you want to check!
"; opendir(DIR, $path_to_poll_files) || print "Could not: $!
"; @files = readdir(DIR); closedir(DIR); foreach $file (@files){ if($file !~ /^poll\d+\.html$/){ next; } else { $html .= "\n"; $foundfiles = 1; } } if($foundfiles == 1){ $html .= "
$file
$footer"; } else { $msg = "
No Poll HTML files found
"; &admin_login_screen; exit(); } print $html; exit(); } @files_to_delete = split(/\0/, $data{'Poll'}); foreach $file (@files_to_delete){ if(-f "$path_to_poll_files/$file" && $file =~ /^poll\d+\.html$/){ if($ENV{'SERVER_NAME'} !~ /tesol.net/i && $ENV{'SERVER_NAME'} !~ /linguistic-funland.com/i && $ENV{'HTTP_HOST'} !~ /linguistic-funland.com/i && $ENV{'HTTP_HOST'} !~ /tesol.net/i){ unlink("$path_to_poll_files/$file"); } } } $msg = "
Files successfully deleted
"; &admin_login_screen; exit(); } sub dup_poll_create_check { open(V, "<$votesie_votes") || &debug("Could not open $votesie_votes for reading: $!"); while(){ ($pollq,@stuff) = split(/\|/, $_); if($pollq eq $data{'PollQuestion'}){ $error = "
 ERROR: \"$data{'PollQuestion'}\" already exists. Please delete the existing poll before creating a new one. 

"; $data{'NewPoll'} = "Yes"; $data{'NumResp'} = ""; &newpoll; close(V); exit(); } } close(V); }