// Last Modified: 12/18/2005 // // You may freely use, modify, and distribute this script. // //////////////////////////////////////////////////////////// // // SET VARIABLES // // name of XML file which contains your quiz data $xmlFile = "quiz.xml"; // name of header file $headerFile = "header.inc"; // name of footer file $footerFile = "footer.inc"; // // GET QUIZ DATA // // get XML data $data = implode("", file($xmlFile)); $data = mb_convert_encoding($data, "UTF-8", 'Windows-1251'); // create XML parser $parser = xml_parser_create(); // set parser options xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); // parse XML data into arrays xml_parse_into_struct($parser, $data, $values, $tags); // free parser xml_parser_free($parser); // // STRUCTURE XML DATA INTO ARRAY // // set counter variable for to-be-created questions array $questionNo = 0; // cycle through parsed XML data to look for text and answer tags foreach ($values as $key=>$val) { $xvalue = mb_convert_encoding (trim ( $val[value] ), "Windows-1251", 'UTF-8'); // save value to "questions" array if this is a TEXT tag if ($val[tag] == "TEXT") { $questions[$questionNo]['text'] = $xvalue; } // save value to "questions" array if this is a CHOICES tag if ($val[tag] == "CHOICES") { $questions[$questionNo]['choices'] = $xvalue; } // save value to "questions" array if this is an ANSWER tag if ($val[tag] == "ANSWER") { $questions[$questionNo]['answer'] = $xvalue ; // increment question counter variable $questionNo++; } } // // IMPORT POST VARIABLES // import_request_variables("p", "post_"); // // INCLUDE HEADER FILE // include($headerFile); // // PRINT FIRST QUESTION // echo ( '
'); if (!isset($post_answers)) { echo "" . $questions[0]['text'] . "\n"; echo "
\n"; // split choices into "choices" array $choices = explode(", ", $questions[0]['choices']); echo "

"; // print text field if there are no choices if (count($choices) == 1) { echo "\n"; } // print radio fields if there are multiple choices else { // print a radio button for each choice for ($i = 0; $i < count($choices); $i++) { echo "   " . $choices[$i] . "

\n"; } } echo "

\n"; echo "
\n"; } // // PRINT NEXT QUESTION // elseif (count($questions) > count($post_answers)) { // get number of next question $nextQuestion = count($post_answers); // print question echo "" . $questions[$nextQuestion]['text'] . "\n"; echo "
\n"; // print answers to previous questions as hidden form fields for ($i = 0; $i < count($post_answers); $i++) { echo "\n"; } // split choices into "choices" array $choices = explode(", ", $questions[$nextQuestion]['choices']); echo "

"; // print text field if there are no choices if (count($choices) == 1) { echo "\n"; } // print radio fields if there are multiple choices else { // print a radio button for each choice for ($i = 0; $i < count($choices); $i++) { echo "   " . $choices[$i] . "

\n"; } } // print appropriate button label if (count($questions) == count($post_answers) + 1) { echo "

\n"; } else { echo "

\n"; } echo "
\n"; } // // CALCULATE AND PRINT SCORE // else { // get number of questions $noQuestions = count($questions); // get number of correct answers for ($i = 0; $i < $noQuestions; $i++) { // increment "noCorrectAnswers" variable if user has correct answer if (strtoupper( trim ( $questions[$i]['answer'] ) ) == strtoupper ( trim ( $post_answers[$i] ) ) ) { $noCorrectAnswers++; } } // calculate score $score = ($noCorrectAnswers / $noQuestions) * 100; // round score to nearest whole precentage point $score = round($score); // print score echo "

Correct answers: $score%

\n"; if ($score <= 10) { $title = '���-���? Ƹ����� ���?'; $text = '���������� �� ���� �������, � ��� ����. � - ����������� ������.'; } if ($score > 10) { $title = '��, ��������, ��� ��������� ��� ��������� ���������, ��� ��� ��������� �������� ����-����!'; $text = '� ��������� ��� �������, ��� �������� ������ �����! ������, � ��������� ��� ������ ������?'; } if ($score > 35) { $title = '� ����� ��� � ����!'; $text = '��, ��� �����������, � ����� ��� � �� ����� ���� ����. ������ ����������, ��� ���� ������ ������������ ���� �� ����� ����-����!'; } if (($score > 70 ) && ($noCorrectAnswers < $noQuestions)) { $title = '� ����-����! �������!'; $text = '� ������ �� ����, ��������� � �����������. � �������, ��� �� ��� ��������, ��� ������ ���� ���������, � ��� ���, � ��� �����!'; } if ($noCorrectAnswers == $noQuestions) { $title = '� - ������������ ���! � - ����!'; $text = 'Ƹ����� ����� - ��� �����. � ���������� � ������ ������ ��� ������� ��� ���� � ����. ��� ������ ��� � �����������. � 100% ����!'; } $x = ''; $x .= ''; $x .= ''; $x .= ''; $x .= ''; $x .= ''; $x .= ''; $x .= ''; $x .= ''; $x .= ''; $x .= ''; $x .= '
'; $x .= ''; $x .= $title; $x .= ''; $x .= '
'; $x .= $text; $x .= '
'; $x .= ''; $x .= '����� �� ���� ����?'; $x .= ''; $x .= '
'; echo ( $x ); echo ( '


�� ������ ���������� ���������� ����� �� ����� ��������


HTML Code:
' ); echo ( '' ); $fw=fopen("statistics.txt","a"); fputs($fw,"IP: [" . $_SERVER['REMOTE_ADDR'] . "]: $score\n"); fclose($fw); } echo ( '
'); // // INCLUDE FOOTER FILE // include($footerFile); ?>