//##################################################################//
//#
//# SERVICE - NETWORK, INC
//# Virtual Webhosting & Design Services .
//# ===========================
//#
//# http://www.service-network.com or http://www.service-network.Net
//#
//# Developed 2002 by Root (root@service-network.com)
//#
//# ICQ # 33377799
//#
//#
//# Saudi Arabia
//#
//#
//##################################################################//
require("config.php");
if (! mysql_connect($host, $username, $password)) {
print "MySQL Error: " . mysql_error();
exit;
}
mysql_select_db($database);
$result = mysql_query(
"SELECT anticheat, require_info, show_record, show_answer, show_copyright, " .
"use_table, randomize_ans, allow_empty_ans, " .
"admin_password, admin_email, email_admin, email_taker, header, footer, ".
"url_site, url_tick, url_cross, font_face, font_color, table_border_color, ".
"table_color_1, table_color_2, level_name_1, level_name_2, level_name_3, ".
"no_options, no_recent, no_top FROM quirex_config");
if ($result) {
list($anticheat, $require_info, $show_record, $show_answer, $show_copyright, $use_table, $randomize_ans, $allow_empty_ans, $admin_password, $admin_email, $email_admin, $email_taker, $header, $footer, $url_site, $url_tick, $url_cross, $font_face, $font_color, $table_border_color, $table_color_1, $table_color_2, $level_name_1, $level_name_2, $level_name_3, $no_options, $no_recent, $no_top) = mysql_fetch_row($result);
}
else {
print "MySQL Error: " . mysql_error();
exit;
}
$script = getenv("SCRIPT_NAME");
if (file_exists("language.php")) {
include("language.php");
}
else {
$language[quiz] = "Quiz";
$language[total_takers] = "Total Takers";
$language[record_holder] = "Record Holders";
$language[na] = "N/A";
$language[num_of_questions] = "Number of Questions";
$language[name] = "Name";
$language[email] = "E-mail";
$language[both_required] = "both reqired";
$language[hide_email] = "Check here if you want to hide your email address";
$language[take_quiz] = "Take the quiz now!";
$language[tf_true] = "True";
$language[tf_false] = "False";
$language[answer] = "Answer";
$language[submit] = "Done!";
$language[continue_quiz] = "Continue the Quiz...";
$language[info_required_msg] = "Both your name and email are required to take the quiz.";
$language[anticheat_msg] = "You are not allowed to re-take the same quiz within 1 hour.";
$language[empty_ans_msg] = "You have unanswered questions.";
$language[your_answer] = "Your Answer";
$language[correct_answer] = "Correct Answer";
$language[explanation] = "Explanation";
$language[result] = "You've got [no_correct] correct out of [no_total] questions, which gives you a score of [percentage].";
$language[take_again] = "Take the Quiz Again!";
$language[back] = "Back to Home";
$language[no_total] = "Ques Attemped";
$language[no_correct] = "Ques Correct";
$language[score] = "Score";
$language[time_taken] = "Time Taken";
$language[time_of_trial] = "Time";
}
srand ((float) microtime() * 1000000);
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
print $header;
if ($action == 'quiz' && $quiz != '') {
if (isset($first_ques)) {
continue_quiz();
}
else {
start_quiz();
}
}
elseif ($action == 'done' && $quiz != '') {
check_answer();
}
elseif ($quiz) {
if (eregi("^recent", $show)) $show = "recent";
if (eregi("^top", $show)) $show = "top";
if (($show == 'recent' || $show == 'top') && $show_record) {
show_record($show);
}
else {
start_quiz(0);
}
}
else {
show_quiz();
}
print $footer;
function show_quiz($msg = '') {
global $script, $anticheat, $require_info, $show_record, $show_answer, $show_copyright, $use_table, $randomize_ans, $allow_empty_ans, $admin_password, $admin_email, $email_admin, $email_taker, $header, $footer, $url_site, $url_tick, $url_cross, $font_face, $font_color, $table_border_color, $table_color_1, $table_color_2, $level_name_1, $level_name_2, $level_name_3, $no_options, $no_recent, $no_top;
global $action, $quiz, $number, $name, $email, $hide;
global $language;
print "
\n";
}
function start_quiz($check_info = 1) {
global $script, $anticheat, $require_info, $show_record, $show_answer, $show_copyright, $use_table, $randomize_ans, $allow_empty_ans, $admin_password, $admin_email, $email_admin, $email_taker, $header, $footer, $url_site, $url_tick, $url_cross, $font_face, $font_color, $table_border_color, $table_color_1, $table_color_2, $level_name_1, $level_name_2, $level_name_3, $no_options, $no_recent, $no_top;
global $action, $quiz, $number, $name, $email, $hide;
global $language;
if ($check_info && $require_info && ($name == '' || ! ereg(".+@.+\..+", $email))) {
show_quiz($language[both_required_long]);
}
else {
list($all_ques) = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM quirex_ques WHERE quiz_id = '$quiz'"));
if ($all_ques == 0) {
print "No questions";
print $footer;
exit;
}
if(is_numeric($number)) {
$ques_show = min($number, $all_ques);
}
elseif (strtolower($number) == 'all') {
$ques_show = $all_ques;
}
else {
$ques_show = min(10, $all_ques);
}
print "\n";
print "\n";
}
}
function continue_quiz() {
global $script, $anticheat, $require_info, $show_record, $show_answer, $show_copyright, $use_table, $randomize_ans, $allow_empty_ans, $admin_password, $admin_email, $email_admin, $email_taker, $header, $footer, $url_site, $url_tick, $url_cross, $font_face, $font_color, $table_border_color, $table_color_1, $table_color_2, $level_name_1, $level_name_2, $level_name_3, $no_options, $no_recent, $no_top;
global $action, $quiz, $number, $name, $email, $hide, $first_ques, $q0;
global $language;
list($all_ques) = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM quirex_ques WHERE quiz_id = '$quiz'"));
if(is_numeric($number)) {
$ques_show = min($number, $all_ques);
}
elseif (strtolower($number) == 'all') {
$ques_show = $all_ques;
}
else {
$ques_show = min(10, $all_ques);
}
print "\n";
print "\n";
}
function check_answer() {
global $script, $anticheat, $require_info, $show_record, $show_answer, $show_copyright, $use_table, $randomize_ans, $allow_empty_ans, $admin_password, $admin_email, $email_admin, $email_taker, $header, $footer, $url_site, $url_tick, $url_cross, $font_face, $font_color, $table_border_color, $table_color_1, $table_color_2, $level_name_1, $level_name_2, $level_name_3, $no_options, $no_recent, $no_top;
global $action, $array, $quiz, $number, $name, $email, $hide, $begin;
global $language;
for ($i=0;$i<$number;$i++)
global ${"q$i"};
$taker_ip = getenv("REMOTE_ADDR");
if ($anticheat != 0) {
$seconds = $anticheat * 3600;
$result = mysql_query("SELECT * FROM quirex_record WHERE ip = '$taker_ip' AND quiz_id = '$quiz' AND (UNIX_TIMESTAMP() - time_finish) < $seconds");
}
if (!$allow_empty_ans) {
$empty_ans = 0;
for ($i=0;$i<$number;$i++)
if (!isset(${"q$i"}))
$empty_ans = 1;
}
if ($anticheat != 0 && mysql_num_rows($result) != 0) {
print "$language[anticheat_msg]";
}
elseif (!$allow_empty_ans && $empty_ans) {
print "$language[empty_ans_msg]";
}
elseif ($require_info && ($name == '' || ! ereg(".+@.+\..+", $email))) {
print "$language[info_required_msg]";
}
else {
print "\n";
$id = split(",", $array);
$no_correct = 0;
list($quiz_name) = mysql_fetch_row(mysql_query("SELECT quiz_name FROM quirex_list WHERE quiz_id = '$quiz'"));
if ($use_table) {
print "\n";
print "\n";
print "$quiz_name | \n";
}
else {
print "$quiz_name
\n";
}
for ($i=0;$i<$number;$i++) {
list($ques_id, $ques_type, $question, $choice, $answer, $ans_img, $explanation) = mysql_fetch_row(mysql_query("SELECT ques_id, ques_type, question, choice, answer, ans_img, explanation FROM quirex_ques WHERE ques_id = '$id[$i]'"));
$is_correct = 0;
if ($ques_type == 'mc') {
if (${"q$i"} == $answer)
$is_correct = 1;
}
elseif ($ques_type == 'ma' && isset(${"q$i"})) {
$multi_ans = split("\|\|", $answer);
$flag = 1;
for ($j=0;$j";
if ($is_correct)
print " | ";
else
print " ";
print "";
print "".($i+1).". $question ";
if ($ques_type == 'mc' && isset(${"q$i"}))
$your_ans = eregi_replace("\[img=([^]]+)\]", " ", ${"q$i"});
elseif ($ques_type == 'ma' && isset(${"q$i"}))
$your_ans = eregi_replace("\[img=([^]]+)\]", " ", join(", ", ${"q$i"}));
elseif ($ques_type == 'sa' && ${"q$i"} != '')
$your_ans = trim(${"q$i"});
elseif ($ques_type == 'tf' && isset(${"q$i"})) {
if (${"q$i"} == 't') $your_ans = $language[tf_true];
if (${"q$i"} == 'f') $your_ans = $language[tf_false];
}
elseif ($ques_type == 'nu' && ${"q$i"} != '') {
$your_ans = ${"q$i"};
}
else {
$your_ans = $language[na];
}
print "$language[your_answer]: $your_ans ";
if ($show_answer) {
if ($ques_type == 'sa') {
$ans = join(", ", split("\|\|", $answer));
}
elseif ($ques_type == 'ma') {
$ans = join(", ", split("\|\|", $answer));
$ans = eregi_replace("\[img=([^]]+)\]", " ", $ans);
}
elseif ($ques_type == 'tf') {
if ($answer == 't') $ans = $language[tf_true];
if ($answer == 'f') $ans = $language[tf_false];
}
elseif ($ques_type == 'mc')
$ans = eregi_replace("\[img=([^]]+)\]", " ", $answer);
else
$ans = $answer;
print "$language[correct_answer]: $ans ";
if ($ans_img)
print " ";
if ($explanation)
print "$language[explanation]: $explanation ";
}
print " | \n";
}
else {
if ($is_correct)
print " ";
else
print " ";
print "".($i+1).". $question ";
if ($ques_type == 'mc' && isset(${"q$i"}))
$your_ans = eregi_replace("\[img=([^]]+)\]", " ", ${"q$i"});
elseif ($ques_type == 'ma' && isset(${"q$i"}))
$your_ans = eregi_replace("\[img=([^]]+)\]", " ", join(", ", ${"q$i"}));
elseif ($ques_type == 'sa' && ${"q$i"} != '')
$your_ans = trim(${"q$i"});
elseif ($ques_type == 'tf' && isset(${"q$i"})) {
if (${"q$i"} == 't') $your_ans = $language[tf_true];
if (${"q$i"} == 'f') $your_ans = $language[tf_false];
}
elseif ($ques_type == 'nu' && ${"q$i"} != '') {
$your_ans = ${"q$i"};
}
else {
$your_ans = $language[na];
}
print "$language[your_answer]: $your_ans ";
if ($show_answer) {
if ($ques_type == 'sa') {
$ans = join(", ", split("\|\|", $answer));
}
elseif ($ques_type == 'ma') {
$ans = join(", ", split("\|\|", $answer));
$ans = eregi_replace("\[img=([^]]+)\]", " ", $ans);
}
elseif ($ques_type == 'tf') {
if ($answer == 't') $ans = $language[tf_true];
if ($answer == 'f') $ans = $language[tf_false];
}
elseif ($ques_type == 'mc')
$ans = eregi_replace("\[img=([^]]+)\]", " ", $answer);
else
$ans = $answer;
print "$language[correct_answer]: $ans ";
if ($ans_img)
print " ";
if ($explanation)
print "$language[explanation]: $explanation ";
}
print " \n";
}
}
$percentage = round($no_correct/$number*10000) / 100;
$language[result] = eregi_replace("\[no_correct\]", "$no_correct", $language[result]);
$language[result] = eregi_replace("\[no_total\]", "$number", $language[result]);
$language[result] = eregi_replace("\[percentage\]", "$percentage", $language[result]);
if ($use_table) print "\n";
print "$language[result]\n";
if ($use_table) print " | \n";
if (!$anticheat) {
if ($use_table) print "\n";
print " \n";
print " \n";
print "\n";
if ($use_table) print " | \n";
}
if ($use_table) {
if ($show_copyright)
print "Developed by SERVICE - NETWORK, INC | \n";
print " \n";
print " |
\n";
}
print "$language[back]
";
if ($hide == '1') $show_info = 0;
if ($hide == '') $show_info = 1;
mysql_query("INSERT INTO quirex_record SET quiz_id = '$quiz', taker_name = '$name', taker_email = '$email', show_record = '$show_info', no_total = '$number', no_correct = '$no_correct', time_begin = '$begin', time_finish = UNIX_TIMESTAMP(), ip = '$taker_ip'");
$seconds = $anticheat * 3600;
mysql_query("UPDATE quirex_record SET ip = '' WHERE (UNIX_TIMESTAMP() - time_finish) > $seconds");
print "\n";
if ($email_admin) {
$mail_header = "From: \"SERVICE - NETWORK, INC\" <$admin_email>\n";
$mail_subject= "Someone has taken your Quiz";
$mail_body = "$name has taken the quiz \"$quiz_name\" \n";
$mail_body .= "at ".strftime("%Y-%m-%d %H:%M:%S").".\n";
$mail_body .= "The following is a report of his/her answers.\n";
$mail_body .= "\n";
for ($i=0;$i<$number;$i++) {
list($ques_type, $question, $answer) = mysql_fetch_row(mysql_query("SELECT ques_type, question, answer FROM quirex_ques WHERE ques_id = '$id[$i]'"));
$mail_body .= ($i+1).". $question\n";
if ($ques_type == 'mc') {
$mail_body .= "Taker's Answer: ".${"q$i"}."\n";
$mail_body .= "Correct Answer: $answer\n";
}
elseif ($ques_type == 'ma') {
$mail_body .= "Taker's Answer: ".join(", ", ${"q$i"})."\n";
$mail_body .= "Correct Answer: ".join(", ", split("\|\|", $answer))."\n";
}
elseif ($ques_type == 'sa') {
$mail_body .= "Taker's Answer: ".${"q$i"}."\n";
$mail_body .= "Correct Answer: ".join(", ", split("\|\|", $answer))."\n";
}
elseif ($ques_type == 'nu') {
$mail_body .= "Taker's Answer: ".${"q$i"}."\n";
$mail_body .= "Correct Answer: $answer\n";
}
elseif ($ques_type == 'tf') {
$tf[t] = "True";
$tf[f] = "False";
$mail_body .= "Taker's Answer: ".$tf[${"q$i"}]."\n";
$mail_body .= "Correct Answer: ".$tf[$answer]."\n";
}
$mail_body .= "\n";
}
mail($admin_email, $mail_subject, $mail_body, $mail_header);
}
if ($email_admin) {
$mail_header = "From: $admin_email\n";
$mail_subject= "Your Quiz Report";
$mail_body = "$name,\n";
$mail_body = "Thank you for taking the quiz \"$quiz_name\".\n";
$mail_body .= "The following is your quiz report.\n";
$mail_body .= "\n";
for ($i=0;$i<$number;$i++) {
list($ques_type, $question, $answer) = mysql_fetch_row(mysql_query("SELECT ques_type, question, answer FROM quirex_ques WHERE ques_id = '$id[$i]'"));
$mail_body .= ($i+1).". $question\n";
if ($ques_type == 'mc') {
$mail_body .= "Your Answer: ".${"q$i"}."\n";
if ($show_answer)
$mail_body .= "Correct Answer: $answer\n";
}
elseif ($ques_type == 'ma') {
$mail_body .= "Your Answer: ".join(", ", ${"q$i"})."\n";
if ($show_answer)
$mail_body .= "Correct Answer: ".join(", ", split("\|\|", $answer))."\n";
}
elseif ($ques_type == 'sa') {
$mail_body .= "Your Answer: ".${"q$i"}."\n";
if ($show_answer)
$mail_body .= "Correct Answer: ".join(", ", split("\|\|", $answer))."\n";
}
elseif ($ques_type == 'nu') {
$mail_body .= "Your Answer: ".${"q$i"}."\n";
if ($show_answer)
$mail_body .= "Correct Answer: $answer\n";
}
elseif ($ques_type == 'tf') {
$tf[t] = "True";
$tf[f] = "False";
$mail_body .= "Your Answer: ".$tf[${"q$i"}]."\n";
if ($show_answer)
$mail_body .= "Correct Answer: ".$tf[$answer]."\n";
}
$mail_body .= "\n";
}
mail($email, $mail_subject, $mail_body, $mail_header);
}
}
}
function show_record($show) {
global $script, $anticheat, $require_info, $show_record, $show_answer, $show_copyright, $use_table, $randomize_ans, $allow_empty_ans, $admin_password, $admin_email, $email_admin, $email_taker, $header, $footer, $url_site, $url_tick, $url_cross, $font_face, $font_color, $table_border_color, $table_color_1, $table_color_2, $level_name_1, $level_name_2, $level_name_3, $no_options, $no_recent, $no_top;
global $quiz, $language;
if ($show == "recent") {
$result = mysql_query("SELECT taker_name, taker_email, show_record, no_total, no_correct, (time_finish-time_begin) AS time_taken, FROM_UNIXTIME(time_finish) FROM quirex_record WHERE quiz_id = '$quiz' ORDER BY time_finish DESC LIMIT $no_recent");
$str = "آخر $no_recent متسابق";
}
elseif ($show == "top") {
$result = mysql_query("SELECT taker_name, taker_email, show_record, no_total, no_correct, (time_finish-time_begin) AS time_taken, FROM_UNIXTIME(time_finish) FROM quirex_record WHERE quiz_id = '$quiz' ORDER BY (no_correct/no_total) DESC, no_total DESC, time_taken ASC, time_finish DESC LIMIT $no_top");
$str = "أفضل $no_top متسابق";
}
list($quiz_name) = mysql_fetch_row(mysql_query("SELECT quiz_name FROM quirex_list WHERE quiz_id = '$quiz'"));
print "\n";
print "\n";
print "$quiz_name: $str | \n";
print "\n";
print " $language[name] | \n";
print " $language[no_total] | \n";
print " $language[no_correct] | \n";
print " $language[score] | \n";
print " $language[time_taken] | \n";
print " $language[time_of_trial] | \n";
print " \n";
for($i=0;$i\n";
if ($show_record) $taker_name = "$taker_name";
print " $taker_name | \n";
print " $no_total | \n";
print " $no_correct | \n";
print " $percentage | \n";
print " $time_taken | \n";
print " $time | \n";
print "\n";
}
print " \n";
print " |
\n";
}
?>