Site hosted by Angelfire.com: Build your free website today!
<<<#!/usr/bin/perl -wT # blogquiz.cgi - a perl script for grading blog quizzes. # For use with the accompanying html file quiz.html. # Documentation and source at http://jemimap.cjb.net/style/blogquiz.html # The source is free for any use. # blogquiz.cgi will grade a multiple-choice quiz form of any number of # questions, with any number of outcomes (the categories). It can grade # either by majority of questions in a particular category, or by # averaging. The default is the former. ######### STEP 0: Can you use the script at all? # # Make sure that you can run perl CGI scripts on your web host. # (Ask somebody, read the FAQ, find the documentation, etc.) # If perl is in a strange place on your server, you'll have to edit # the first line of this script to reflect that. # # Make sure that you can also serve images, if you want people to # link your graphic (rather than download it). # ########## STEP 1: Configure the HTML page, quiz.html. # # First, change the URL for blogquiz.cgi to the URL where you will put # your version of blogquiz.cgi. # # The sample file uses twelve questions of five answers each # for five categories (results). Insert your questions for # "Question 1", etc., and your answers for "Answer 1", etc. # You can add more questions or cut down on the number. # Just be sure that each new question gets a new number in the "name" # field of the input statements. # For each form line (look at the source of quiz.html to see one) # # Answer 2
# # in quiz.html, "name" takes the question number, and "value" the # category number for which this answer counts. # # Traditionally, the answers are in order and there is one answer per # category per question. The script does not require this. # You can add more answers or cut some out, move the answers around, # and have different numbers of answers per question. Just make sure # that the number in "value" refers to the category you want that # answer to count towards. # To pre-check selected answers in quiz.html, use the "checked" # element, thus: # # Answer 2
# # Last, change "Submit Message Here" to what you want on your submit # button. "Submit" is traditional if you're not feeling creative. ######## STEP 2: Customize the results page # # To configure the results, edit this script as directed below. # You should use Notepad or another editor that will not wrap lines when # editing this script. Customize the lines marked for user customization; # these include the URL where you will put quiz.html, the names and # descriptions of the categories for the results page, and the URLs of # the category images. # # The results page is generated automatically. You can edit some of # the html of the results page below, but don't try to edit the # cut-and-paste code section unless you're feeling brave. # ######## STEP 3: Install the script and web page # # To install blogquiz.cgi you need a cgi-capable web server. Put it # in your cgi-bin directory (or any directory if you're not restricted to # a cgi-bin directory). You will probably need to type # # chmod 755 blogquiz.cgi # # at the command line or at the ftp prompt to make the cgi script # executable. (If you're using a graphical ftp program, you may have # to find another way to set permissions so that everyone can read and # execute the program.) # # Note that if you want to serve images, as blog quizzes traditionally # do, you need a server that serves images. Otherwise you'll have to tell # people to download the image and have them edit the URL in the # cut-and-paste for their local image copy, and that would be messy. # ##### Skip down to QUIZ VARIABLES to CUSTOMIZE THE SCRIPT ###### use strict; # don't touch use CGI; my $q = new CGI; my @title; my @image; my @description; my $category; ######### QUIZ VARIABLES # # Change for your quiz, replacing the numbers or quoted text # my $quiz = "Which Category are You?"; # full name of quiz my $quizurl = "http://jemimap.freeshell.org/cgi-bin/quiz.html"; # Absolute URL of your quiz.html my $qs = 12; # Total number of questions my $cs = 5; # Total number of categories (usually the # of answers) ### You can probably leave the next values alone and skip to TITLES my $scoring = 1; # Use 0 for averaging and 1 for majority rules # Settings for average value scoring: my $average = $cs /2; # Don't touch # $average = 0; # Uncomment this line to change the default value # for averaging. The default is the true average, # the other desirable choices are the minimum and # maximum values # Settings for majority (plurality) scoring: my $thresh = 2; # Minimum number of questions to avoid the default. my $default = 1; # The default value is used in conjunction with the # threshhold value. In this case, at least two # questions must be answered in another category # to override the default category of 1. ######## TITLES of categories $title[1] = "You Are Category 1"; $title[2] = "You Are Category 2"; $title[3] = "You Are Category 3"; $title[4] = "You Are Category 4"; $title[5] = "You Are Category 5"; ######## IMAGE URL's (optional - use "" for no image) $image[1] = "http://jemimap.freeshell.org/style/sample1.png"; $image[2] = "http://jemimap.freeshell.org/style/sample2.png"; $image[3] = "http://jemimap.freeshell.org/style/sample3.png"; $image[4] = "http://jemimap.freeshell.org/style/sample4.png"; $image[5] = "http://jemimap.freeshell.org/style/sample5.png"; ######## DESCRIPTIVE TEXT (optional - use "" for no text) $description[1] = "People of category 1 are..."; $description[2] = "People of category 2 are..."; $description[3] = "People of category 3 are..."; $description[4] = "People of category 4 are..."; $description[5] = "People of category 5 are..."; ### The rest is optional. Proceed past this point with caution. ######### RESULTS OUTPUT PAGE - edit HTML *carefully* if desired print < Quiz Results

Your results:


END_OF_RESULTS_HTML ###### Edit the following with caution if desired. $category = &GetQuizResult; # not this print "
"; print "\"$title[$category]\"
"; print "$title[$category]
"; print "$description[$category]

"; print "

Cut and paste the following code into your blog or webpage:
"; ######## CUT AND PASTE CODE ####### # The cut-and-paste code is composed of the following parts. # Keep the variables ($quiz, etc.), and remember to escape the # quotation mark as \" if you want to add more html code. my $image = "

\"$title[$category]\"
"; my $caption = "$title[$category]
"; my $description = "$description[$category]
"; my $link = "Take the $quiz Quiz

"; my $cutandpaste = $image . $caption . $description . $link; ################### You probably don't want to go past this point. print $q->textarea(-name=>'CutAndPasteCode', -default=>$cutandpaste, -columns=>50, -rows=>7); print "
"; ################### Beware. I mean it. Go away now. # subroutine that does the scoring sub GetQuizResult { my @cats; my $cattot = 0; my $cat = $default; my $i; my $k; my $value; if ($scoring == 1) { # scoring by majority for ($i=1; $i <= $qs; $i++) { $k = $q->param( $i ); $cats[$k]++; } for ($i=1; $i <= $cs; $i++) { if ($cats[$i] >= $thresh) { $cat = $i; $thresh = $cats[$i]; } } } else { # scoring by average for ($i=1; $i <= $qs; $i++) { $k = $q->param( $i ); if ($k == "") { # if question was unanswered $cattot = $cattot + $average; # add the average value } else { $cattot = $cattot + $k; # otherwise add the answer } }; $value = $cattot / $qs; $cat = ($value-int($value))>=0.5? int($value)+1 : int($value); } return $cat; } ###EOF >>>