#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); # (c) NueDream Inc. 2000-2002 (www.nuedream.com) ############## GLOBAL CONSTANTS ############ $file = "/sites/v3i/sntcollege/snt.db"; # This is the name of your questions file. $quizname = "NueQuiz"; # This is what appears in the TITLE. $spacer = '|'; # The delimeter used in the database. $result1 = "Sorry, But you need to pass the Pre-Intermediate test to be a SNT student"; # 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%-80%. $result3 = "Wow! You did excellent, looks like you know your stuff."; # Message Displayed when user get above 80%. $cheater = "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 ############ #you did well, you got corrects. You can the ... test now. @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; } if($sname eq "") { $sname = ""; } if($snationality eq "") { $snationality = ""; } $level = ""; $nextlevel = ""; if ($type eq "pre") { $level = "Pre-Intermediate"; $nextlevel = "Intermediate"; $nexturl = "quiz.cgi?inter"; } if ($type eq "inter") { $level = "Intermediate"; $nextlevel = "Upper-Intermediate"; $nexturl = "quiz.cgi?upper"; } if ($type eq "upper") { $level = "Upper-Intermediate"; $nextlevel = "Well done"; $nexturl = "en_home.htm"; } $current = $question-1; $correct = 0; $min = 0; if($GET{'action'} eq "") { print "Content-type: text/html\n\n"; print "\n"; print "\n"; print < < snt >

TEST YOUR ENGLISH

EOF ; 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++; } } # print "

 

\n"; # print "

Test your English - $level Level

\n"; ######### print "
Test your English - $level Level


"; # print "
"; # print "
Name: $sname Nationality: $snationality

"; if ($question == 1) { # print "For a student to study at SNT he/she must answer at least 30 questions correctly.... GOOD LUCK! "; print "
\n"; print " Name:\n"; print "\n"; print " Nationality:\n"; print "\n"; print "\n"; } $total++; # Printing Quiz results. if ($question == $total) { # print "
Name: $sname Nationality: $snationality

"; print "
Your incorrect answers are:

"; #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) { $tempa = substr($answerc,0,1); $tempb = substr($answerc,1,1); if ( $tempa eq "a") { $disp = $a; } if ( $tempa eq "b") { $disp = $b; } if ( $tempa eq "c") { $disp = $c; } if ( $tempa eq "d") { $disp = $d; } if(substr($answerc,0,1) eq $ans) { ### print "
$questionc. $q
You Answered: $tempa. CORRECT!
    The correct answer is $reason
"; ### print "

$questionc. $q
You Answered: $tempa. $disp - CORRECT!"; $correct++; } else { ### print "$questionc. $q
You Answered: $tempa. $disp - INCORRECT!
Correct Answer: $tempb.
    The correct answer is $reason
"; print "

$questionc. $q
You Answered: $tempa. $disp - INCORRECT!
Correct Answer: $tempb. $reason "; } } } } } } print "
"; print "



"; $percent = ($correct/$current)*100; # printf ("Final Result: $correct correct of $current questions

"); printf ("Correct Answers: $correct

"); # % is out # 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"; # } # while (($chave, $valor) = each(%ENV)) # { # print "
$chave é igual a $valor\n"; # } if ( $correct < $min) { if ($type eq "pre") { print "I am sorry but you haven’t passed your written test.... "; print "
Unfortunately we do not offer classes for Elementary levels.... "; } if ($type eq "inter") { print "Sorry, but you need to pass the Intermediate test to take next one "; # print "\n \n"; } if ($type eq "upper") { print "Sorry, but you you are not a Upper-Intermediate student!!! "; } print "\n

\n"; } else { # if ($type eq "pre") -o ($type eq "inter"){ # print "You did well, you got $correct corrects. You can the $nextlevel test now. "; # print "\n \n"; # } # if ($type eq "upper") { print "You did well, you got $correct corrects. You are a Upper-Intermediate student "; print "\n

\n"; } else { # print "Well done!! You have passed your written English test!!! Now you need to take your oral test!!! "; # print "
Hope to see you in England soon!!! Bye for now!!!"; print "\n

\n"; print "    \n"; # print "\n \n"; # print "    \n"; print "\n \n"; } } print "
 
\n"; } 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) { $righttotal= $total-1; print "
\n"; # print "

 

\n"; # print "

Test your English - $level Level

\n"; # print "
Test your English - $level Level


"; # print "
"; print "\n"; print "\n"; # print "
Question $question of $righttotal
\n"; # print "
 
\n"; print "\n"; print "\n"; print "
Question $question of $righttotal
$q
 
\n"; print "\n"; if ($a ne "") { print "\n"; } if ($b ne "") { print "\n"; } if ($c ne "") { print "\n"; } if ($d ne "") { print "\n"; } if ($e ne "") { print "\n"; } if ($f ne "") { print "\n"; } print "
  A. $a
  B. $b
  C. $c
  D. $d
  E. $e
  F. $f
\n"; print "

\n"; print "
"; print "
\n"; print "\n
\n"; } } } print <

 

EOFF ; #print "\n\n\n\n\n\n"; } elsif ($GET{'action'} eq "check") { $content = $ENV{'QUERY_STRING'}; ($temp, $temp2, $temp3) = split(/&/, $content); ($question, $answer) = split(/=/, $temp); ($type, $question) = split(/=/, $temp2); ($temp4, $act) = split(/=/,$temp3); $start = $question+1; $url = "quiz.cgi?$type=$start"; $tempv = ""; (@cookies) = split(/;/, $ENV{'HTTP_COOKIE'}); foreach $crum (@cookies) { ($name, $value) = split(/=/, $crum); if($name =~ /$type/) { $tempv = $value; last; } } if($temp3 eq "") { $url = "quiz.cgi?pre=$answer"; # print "Location: $url\n\n"; print "Content-type: text/html\n\n"; print "\n"; print "\n"; print < < snt >

TEST YOUR ENGLISH
\n\n

EOF ; # print "
\n"; # print " \n"; # print " \n"; # print " \n"; # print "
 \n"; print "\n"; ###### print "
Test your English - $level Level


"; print "
 "; print "
 "; # print "

Please answer this question before moving to the next one !!!

\n"; print "
Please answer this question before moving to the next one !!!"; print "
 "; print "
 "; print "
 "; print "
 "; print "
 "; print "
"; print "

\n \n"; print "
 "; # print "
\n
\n
\n\n"; print <

 

EOF ; } 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); 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) { if($tempv ne "") { if ($tempv =~ /$question/) { if($anticheat == 1) { print "Content-type: text/html\n\n"; print "

$cheater

If you did not try to cheat, try again. This time do not double click the next button.
Click once and wait until the next question is fully displayed before clicking again.
"; } else { print "Location: $url\n\n"; } } else { $tempcookie = "$tempv" . "-" . $question . "_" . $answer . $ans; print "Set-cookie: $type=$tempcookie\n"; print "Location: $url\n\n"; } } else { $tempcookie = $question . "_" . $answer . $ans; print "Set-cookie: $type=$tempcookie\n"; print "Location: $url\n\n"; } } } } ############# DYING SUBROUTINE ############ sub dienice { my($msg) = @_; print ("


FATAL ERROR



\n"); print ($msg); exit; }