#!/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";
}
$total++;
# Printing Quiz results.
if ($question == $total) {
# print " Name: $sname Nationality: $snationality
");
# % 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