###################################
# Vote Script 1.2
# Originally written for The Web Page for Brian Wilson
# http://www.cabinessence.com/brian
#
# by Mike Wheeler
# mwheeler@cabinessence.com
#
# This script and others available at 
# http://www.cabinessence.com/cgi
# Copyright 1996, Mike Wheeler, all rights reserved.
#
# Requires server side includes
#
###################################
You may use and modify this script but you must leave the above 
information intact. All rights reserved.

This script is provided to the internet community free of charge.
Though I will gladly accept anything you have to offer for it,
that will provide encouragement for me to develop this script further
and work on new scripts.

The vote script when you get it consists of several files:
    
    vote.pl -- the actual script. It will create the data files on 
               its own if you have it set up properly.
               
    README -- this file which provides more information on setting
               up the script.
              
    purple.jpg (et al) -- these are the image files. They come in a 
               directory named "img." Feel free to use these or make 
               your own.
              
First of all you must put the script in your cgi-bin directory or if
your server allows it anywhere else in your area (if you place it 
elsewhere you will likely need to call it "vote.cgi"). Then you need 
to set the permissions for the script:

     chmod 755 vote.pl
       or
     chmod 755 vote.cgi
       depending on the name.

Then you need to define the variables at the beginning of the script:

   #!/usr/local/bin/perl
      This is on the very first line of the script and must point to where
      Perl is on your server. Another common place for it is #!/usr/bin/perl
      If you don't know where Perl is on your server type "whereis perl" at
      a UNIX prompt.

   $data_dir = "/ccserver/home23/mwheeler/public_html/cgi/vote/data";
      The $data_dir variable is the path to the directory in which you
      want the data files this script makes to be created. Do not put a  
      slash at the end. THIS DIRECTORY MUST BE SET TO chmod 777
      
   $img_url = "http://gladstone.uoregon.edu/~mwheeler/cgi/vote/img";      
      The $img_url variable is the URL to the directory in which you
      want the image files this script uses. Do not put a slash at 
      the end.
   
   $img1 = "blue.jpg";
   $img2 = "magenta.jpg";
   $img3 = "orange.jpg";
   etc....
      The $img1 (2, 3, 4...) variables are the name of the image file
      you want used. $img1 corresponds to the bar for a 1 rating and
      so on through $img10. You can set these all to the same image file
      or to ten different ones.
      
   $mult = 10;
      The $mult variable is the default number that the number of votes 
      cast will be multiplied by to determine the height of the graph 
      in pixels. This will be the first number in the data file when
      it is created. You can edit the first number in each data file by
      hand as needed to make each graph have good proportions.
      
   $script_name = "http://gladstone.uoregon.edu/~mwheeler/cgi/vote/vote.cgi";
      The $script_name variable is the url to the cgi script.
      
   $valid_referer = "www.cabinessence.com";
      The $valid_referer is the domain that pages must reside on for the 
      script to allow voting. If you don't care to limit it to your server 
      you can leave it blank.

   $reprimand = <<EOM;

   <html><head><title>Shame On You!</title></head>
   <body bgcolor=ffffff><center><h1>Shame On You!</h1></center>
   It appears as though you just tried to vote more than once on this 
   particular subject. You ought to be ashamed of yourself. Your first vote 
   will count, but not any of your subsequent votes.<p>

   Go back with your browser to return to the page from where you came.
   </body></html>

   EOM
   1;

      This is the html for a page that is displayed if the same person
      tries to vote on the same thing twice in a row. All the html must be
      after the "EOM;" and before the "EOM". Those lenes MUST remain as 
      they are so do not put anything else on those lines. You do not
      need to put a backslash (\) before quotation marks or @ symbols.

The below variables only need to be set if you plan to use this script's 
ability to average the voting from all the files and compile a table of the 
results.

   $url_file = "url_file.txt";
      The $url_file is used only when the script compiles the averages.
      If this file is there the script will read it and put a link for all
      the pages listed, so the person viewing the averages page can go to
      the various pages that things are being voted on. The format is
      datafile::url
      with one entry per line.

   $min_vote = 1;
      This is the minimum number of votes a file needs before the script
      will include it in the table showing the average score for each.

   $file_dir_url = "http://gladstone.uoregon.edu/~mwheeler/cgi";
      This is the directory to where all the files that are being voted 
      on are kept. This is only used for the part of the script that
      compiles and ranks the average for each in a table. So if you don't 
      plan on using that feature, don't worry about it.

   $average_header = <<EOM;

   <html><head><title>Average Ratings</title></head>
   <body bgcolor=ffffff><center><h1>Average Ratings</h1></center>
   Here is a table of the average ratings you have given for each of my 
   scripts. This table is compiled by my <a href="../vote.shtml">vote</a> 
   script.<p><ul>

   EOM
   1;

      This is the html that goes above the table that the script creates
      of the average score for each file. Same rules apply as for the
      $reprimand variable above.

   $average_footer = <<EOM;

   </ul>
   Return to the main page about my <a href="../vote.shtml">vote</a> script.<p>
   Return to my main <a href="../index.html">scripts</a> page.
   </body></html>

   EOM
   1;

      This is the html that goes above the table that the script creates
      of the average score for each file. Same rules apply as for the
      $reprimand variable above.



Now, to call this script from a file you need to put the following tag:
        
        <!--#exec cmd="/virtual/path/to/script/vote.pl datafile"-->

Change the "vote.pl" part according to whatever you named the script. For me
this tag is <!--#exec vote="/www/htdocs/cgi/vote/vote.cgi chatpro"-->

The "datafile" in the tag is the name of the file in the data directory 
that will be used in this particular case. This is new to version 1.2 and 
allows you to have multiple votes on the same page (with different 
datafile names) and the same vote on multiple pages (with the same 
datafile name).

That's everything you need to do to get this script running on your
server. Make sure you set the permissions properly. Script is chmod 755
and the data directory is chmod 777 if you don't do this right the script
will not work. 

To use the part of the script that compiles the averages for every file and ranks 
them in a table link to the script adding "?average" after the link, so it looks
something like this:

<a href="http://www.cabinessence.com/cgi/vote.cgi?average">

That's all there is to it, enjoy!
