/********** PHP QUIZ *********************** This script is a freeware. You can use it and modify it freely, as long as you leave the copyright (c) 2000, PHP Vault. For more info, write to: cyberlp@bibelec.com Copyright 2000, PhpVault, Kidou/Cyberlp ********************************************/ /* Path to your quiz directory (NO TRAILING SLASH) **************************************************/ $path= "/usr/local/etc/httpd/htdocs/campinternet/quiz/phpquiz"; /*************************** DON'T CHANGE ANYTHING BELOW ****************************/ $voir=basename($PHP_SELF); $voir_exp=explode(".",$voir); $voir_num=substr($voir_exp[0], 10); $config=file("$path/quizz$voir_num/quizz_config$voir_num.dat"); $config[8]=substr($config[8],0,3); $config[9]=substr($config[9],0,3); $config[10]=substr($config[10],0,3); $max_q_page=$config[12]; $config_gen=file("$path/quizz_config_gen.dat"); print ("
");
if ($Validate != "Validate") {
$fp = fopen("$path/quizz$voir_num/quizz_data$voir_num.dat","r");
$nbq = fgets($fp,10000);
if ($page=="") { $page=1; }
if ( ($Validate=="Previous") && ($page>1) ) { $page-=$max_q_page; }
if ( ($Validate=="Next") && (($page+$max_q_page-1)<$nbq) ) { $page+=$max_q_page; }
print ("
"); exit; } $complet=1; for ($question=1; $question <=$nbq; $question++) { $temp = "q".$question; if ($$temp == "") { $complet=0; }; } if ($complet == 0) { $error="Please try to answer all the questions!"; error($error); } /* Answers analysis *****************/ $score=0; $score_tot=0; $mailBody_Reponses=""; $fp = fopen("$path/quizz$voir_num/quizz_data$voir_num.dat","r"); $nbq = fgets($fp,10000); for ($question=1; $question <=$nbq; $question++) { $data = fgetcsv($fp,10000,";"); $num = count($data); $reponse = "q".$question; $reponse = $$reponse; $mailBody_Reponses .= "Question: $data[0] : $reponse. The right answer is: $data[1]\n"; if ($config[8] == "Yes") { print "\n\n
Question: $question : ";
echo stripslashes($data[0]);
print "\n
You have answered: $reponse";
}
if (strcasecmp($reponse, $data[1]) != 0) {
if ($config[8] == "Yes") {
print "\n
The right answer was ";
echo stripslashes($data[1]);
echo stripslashes($data[3]);
}
$score_tot +=$data[2];
} else {
if ($config[8] == "Yes") {
print "\n
Congratulations, it is the right answer!";
echo stripslashes($data[3]);
}
$score += $data[2];
$score_tot +=$data[2];
}
}
if ($config[8] == "Yes") {
print "\n\n
Your score: $score/$score_tot
"; } fclose($fp); /* Scores update ******************/ $date = Date("d/m/Y"); $reponses = fopen ("$path/quizz$voir_num/quizz_reponses$voir_num.dat","a"); fputs($reponses, "$score;$Name;$Email;$date\n"); fclose($reponses); if ($config[8] == "Oui") { $classement = file ("$path/quizz$voir_num/quizz_reponses$voir_num.dat"); function cmp ($a, $b) { $c=explode(';',$a); $d=explode(';',$b); return ($c[0] > $d[0]) ? -1 : 1; } usort ($classement, cmp); $np=count($classement); if ($config[7] > 0) { print "\n\n
Ranking - Top $config[7]
";
if ($np < $config[7]) { $config[7]=$np; }
for ($i=0; $i<$config[7]; $i++) {
$temp=explode(';',$classement[$i]);
if ($temp[2] == $Email) {
$temp[1]="$temp[1]";
}
print "\n
";
}
print "\n
© 2000, PHP Vault