#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); # (c) NueDream Inc. 2000-2001 (www.nuedream.com) ############## GLOBAL VARS AND CONSTS ############ $file = "questions.db"; # This is the name of your questions file. $quizname = "NueQuiz"; # This is what appears in the TITLE. ############ THESE ARE OPTIONAL CHANGES ########### $spacer = '|'; # Leave it unless you already have a database. @list = ('a','b','c','d','e','f'); $result1 = "I think you need to think a little harder before you answer next time."; # Message Displayed when user gets below 50%. $result2 = "You did pretty good. Some of those questions are harder than they look."; # Message Displayed when user gets between 51%-90%. $result3 = "Wow! You did excellent, looks like you know your stuff."; # Message Displayed when user get above 90%. $cheater = "Cheating won't get you anywhere in life."; # Message Displayed when user cheated. $fontface = "verdana, tahoma, arial"; # Font Type. ############## GET COOKIE AND GET INFO ############ $cookie = $ENV{'HTTP_COOKIE'}; (@cookies) = split(/;/, $cookie); $content = $ENV{'QUERY_STRING'}; ($type, $question) = split(/=/, $content); $current = $question-1; $correct = 0; ############## MAIN PROGRAM ############ print "Content-type: text/html\n\n"; print "\n
\n| \n";
print "\n";
open(DATA,$file) or dienice("Couldn't open $file :: $!\n");
#flock(DATA,0); # uncomment this line if using unix based server
seek(DATA,0,0);
@data = ;
close(DATA);
$total = 0;
foreach $line (@data) {
($quiz,$num,$q,$ans,$a,$b,$c,$d,$e,$f,$reason) = split(/\|/,$line);
if ($quiz eq $type) {
$total++;
}
}
$total++;
if ($question == $total) {
print " QUIZ Results: "; print ""; foreach $part (@cookies) { if ($part =~ /$type/) { ($name, $value) = split(/=/,$part); (@answers) = split(/-/,$value); foreach $a (@answers) { ($questionc, $answerc) = split(/_/,$a); foreach $line (@data) { chomp($line); ($quiz,$num,$q,$ans,$a,$b,$c,$d,$e,$f,$reason) = split(/\|/,$line); if ($quiz eq $type && $questionc eq $num) { if(substr($answerc,0,1) eq substr($answerc,1,1)) { print "$questionc. $q CORRECT! "; $correct++; } else { print "$questionc. $q INCORRECT!
"; $percent = ($correct/$current)*100; printf ("$correct / $current = %4.1f", $percent, "% "); print "% "; if ( ($correct/$total) < 0.5) { print "$result1"; } elsif (($correct/$total) < 0.9) { print "$result2"; } elsif (($correct/$total) > 0.9) { print "$result3"; } else { print "$cheater"; } } else { foreach $line (@data) { chomp($line); ($quiz,$num,$q,$ans,$a,$b,$c,$d,$e,$f,$reason) = split(/\|/,$line); if ($quiz eq $type && $question eq $num) { print "\n"; } } } print "\n | \n