|
/********** Global Variables **********/
$OK = TRUE;
$dbhost = "localhost";
$dbuser = "islander";
$dbpwd = "parvenu";
$db = "javascript";
$First = $_REQUEST["First"];
$Last = $_REQUEST["Last"];
$Password = $_REQUEST["Password"];
$url = $_SERVER["SCRIPT_NAME"];
$urlparts = explode("/", $url);
$table = $urlparts[1];
//$file = strtr($parts[count($parts) - 1], "php", "txt");
$file = str_replace("php", "txt", $urlparts[3]);
if (strpos($file, "q") == 0) $test = "Q". substr($file, 4, 1);
else $test = strtoupper(substr($file, 0, 1));
/********** End of Global Variables **********/
/********** Corrects the Test **********/
$Questions = count($Question);
$correct = 0;
$incorrec = "";
$Index = 1;
$wrong = array();
for ($i = 1; $i <= $Questions; $i++) {
if (is_array($_REQUEST["Q". $i])) $answer = join(", ", $_REQUEST["Q". $i]);
else $answer = $_REQUEST["Q". $i];
if ($answer == $Question[$i]){
$correct++;
}
else {
$wrong[$Index++] = $i;
$incorrec .= "Q". $i ." ";
}
}
/********** EOF Corrects the Test **********/
/********** Writes the Results to a Text File **********/
$now = date("D d M");
$DT = "". $now;
$txtStr = " |
| ";
$txtStr .= $First ." ". $Last;
$txtStr .= " | ";
$txtStr .= "";
$txtStr .= $correct;
$txtStr .= " | ";
$txtStr .= "";
if (strlen($incorrec) > 0) $txtStr .= $incorrec;
else $txtStr .= " ";
$txtStr .= " | ";
$txtStr .= "";
$txtStr .= $DT;
$txtStr .= " |
\n";
$txtFile = fopen($file, "a+");
$txtFile.fwrite($txtFile, $txtStr);
$txtFile.fclose($txtFile);
/********** EOF Writes the Results to a Text File **********/
/********** Writes the Results to the DB **********/
$where = "WHERE Last = '". $Last ."' AND Password = '". $Password ."'";
$strSQL = "SELECT * FROM $table ". $where;
$update = "UPDATE $table SET ". $test ." = '". $correct ."' ". $where;
$conn = @mysql_connect($dbhost, $dbuser, $dbpwd) or die(mysql_error());
$db = @mysql_select_db($db, $conn) or die(mysql_error());
$rsStudent = @mysql_query($strSQL, $conn);
if (mysql_num_rows($rsStudent)) {
$field = mysql_fetch_assoc($rsStudent);
if ($field[$test] == NULL) {
mysql_query($update);
echo("Quiz Score has been entered.
");
}
else {
echo("You already have a score for this test.
");
$OK = FALSE;
}
}
else {
echo("Name/Password was not in the Database.
");
$OK = FALSE;
}
mysql_close($conn);
/********** EOF Writes the Results to the DB **********/
if ($OK) { // Write Out the Results only if valid Name/Password
/********** Writes the Results to the Webpage **********/
echo($correct ." Out of ". $Questions ." (". round(($correct / $Questions) * 100) ."%)
");
if ($correct == $Questions) echo("Congratulations on getting a 100%");
else if ($correct == $Questions - 1) {
echo("");
echo("Correct Answer:
");
echo("Q". $wrong[1] ." = ". $Question[$wrong[1]]);
}
else {
echo("
");
echo("Correct Answers:
");
for ($i = 1; $i <= count($wrong); $i++) {
echo("Q". $wrong[$i] ." = ". $Question[$wrong[$i]] ."
");
}
}
/********** End of Writes the Results to the Webpage **********/
/********** References for incorrect answers **********/
if (strpos($incorrec, "1 ")) {
echo('
Question 1: Cl
ock Example');
echo('
Question 1: Annotated Clock
Example');
}
if (strpos($incorrec, "2")) {
echo('
Question 2: Prompt
Reference');
}
if (strpos($incorrec, "8")) {
echo('
Question 8: Comparison Operators');
}
if (strpos($incorrec, "9")) {
echo('
Question 9: Comparison Operators');
}
/********** End of References for incorrect answers **********/
} // End of OK - Writing Out the Results
?>