#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); # (c) NueDream Inc. 2000-2002 (www.nuedream.com) ############## GLOBAL CONSTANTS ############q $file = "questions2.db"; # This is the name of your questions file. $quizname = "Crime Scene Case Quiz"; # This is what appears in the TITLE. $spacer = '|'; # The delimeter used in the database. $result1 = "The suspect may get away if you don't study the evidence more."; # Message Displayed when user gets below 50%. $result2 = "You got most of the evidence. Some of those questions are harder than they look."; # Message Displayed when user gets between 51%-80%. $result3 = "You're a top detective, looks like you know your stuff."; # Message Displayed when user get above 80%. $cheater = "What? Cheating won't get you anywhere in life."; # Message Displayed when user cheated. $fontface = "verdana, tahoma, arial"; # Font Type. $anticheat = 0; # Enables or disables the anti-cheating feature # (1-Enabled, 0-Disabled). ############## PROGRAM START ############ @pairs = split(/&/, $ENV{'QUERY_STRING'} ); foreach $pair (@pairs) { ($name,$value) = split (/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("c", hex($1))/eg; $value =~ s/\n/ /g; $value =~ s/\r//g; $value =~ s/\cM//g; $GET{$name} = $value; } $cookie = $ENV{'HTTP_COOKIE'}; (@cookies) = split(/;/, $cookie); $content = $ENV{'QUERY_STRING'}; ($type, $question) = split(/=/, $content); if($question eq "") { $question = 1; } $current = $question-1; $correct = 0; if($GET{'action'} eq "") { 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);
# Calculating total number of questions.
$total = 0;
foreach $line (@data) {
($quiz,$num,$q,$ans,$a,$b,$c,$d,$e,$f,$reason) = split(/\|/,$line);
if ($quiz eq $type) {
$total++;
}
}
$total++;
# Printing Quiz results.
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 $ans) { $tempa = substr($answerc,0,1); $tempb = substr($answerc,1,1); print "$questionc. $q You Answered: $tempa. CORRECT!
You Answered: $tempa. INCORRECT! Correct Answer: $tempb.
"; $percent = ($correct/$current)*100; printf ("$correct / $current = %4.1f", $percent, "% "); print "% "; if ( ($correct/$total) < 0.5) { print "$result1"; } elsif (($correct/$total) < 0.8) { print "$result2"; } elsif (($correct/$total) <= 1.0) { 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