]> git.mjollnir.org Git - moodle.git/commitdiff
I've not tested this at all :-( but it was sent to me by the original
authormoodler <moodler>
Mon, 22 Nov 2004 16:25:29 +0000 (16:25 +0000)
committermoodler <moodler>
Mon, 22 Nov 2004 16:25:29 +0000 (16:25 +0000)
author of this feature as a bug fix.

PLEASE TEST!   (See bug 2179 for example)

mod/quiz/preview.php

index 5f94b4d3d3a22276ef9c0b0536f942d61887d99b..32354025f44d748e3abe367c2328b2cec607267b 100644 (file)
@@ -61,8 +61,6 @@
     print_header();
     print_heading(get_string("previewquestion","quiz"));
 
-    echo "<p align=\"center\"><input type=\"button\" onClick=\"window.close()\" value=\"" . get_string("close", "quiz") . "\" /></p>";
-
     if (empty($question->id)) {
         $question->id = "";
     }
       $answers = array();
       $feedbacks = array();
       $qids = array();
+      $fraction = 0;
 
       foreach ($rawanswers as $key => $value) { // Parse input for question->response
         $postedId = quiz_extract_posted_id($key);
-        if ($id == $postedId) {
-          $question->response[$key] = trim($value);
-          $questionType = $QUIZ_QTYPES[$question->qtype]->name();
-          $rezult = get_exp_answers($id); //answers from the database
-
-          if($rezult) {
-            foreach ($rezult as $qid => $answer) {
-              if($qid == $value || $answer->answer == $value) {
-                $feedbacks[$qid] = "&nbsp;-&nbsp;<span class=\"feedbacktext\">".format_text($answer->feedback, true, false)."</span>";
-                if($answer->fraction > 0)
-                  $answers[$qid] = "<span class=\"highlight\">" . $answer->answer . "</span>";
-                else
-                  $answers[$qid] = $answer->answer;
-              } else {
-                if(!isset($answers[$qid])) {
-                  if($answer->fraction > 0)
-                    $answers[$qid] = "<span class=\"highlight\">" . $answer->answer . "</span>";
-                  else
-                    $answers[$qid] = $answer->answer;
-                  $feedbacks[$qid] = '';
-                }
-              }
-              $qids[] = $qid;
-            }
-          }//end if rezult
-        }//end if pId==id
+        if ($id == $postedId) $question->response[$key] = trim($value);
       }//end for each rowanswers
 
       print_simple_box_start("center", "90%");
+
+      //simulate quiz only for quiestion previews
+      class FakeQuiz {
+        var $correctanswers;
+        var $feedback;
+        var $grade;
+        function FakeQuiz()
+        {
+          $this->correctanswers = 1;
+          $this->feedback = 1;
+          $this->grade = 1;
+        }
+      };
+
+      $question->maxgrade = 1; //this shouldn't be like that
+      $resultdetails = $QUIZ_QTYPES[$question->qtype]->grade_response($question, quiz_qtype_nameprefix($question));
+      $quiz = new FakeQuiz();
+
       $QUIZ_QTYPES[$question->qtype]->print_question
-            (1, 0, $question, true, $resultdetails);
+                                      (1, $quiz, $question, true, $resultdetails);
 
-      $qids = array_unique($qids); //erease duplicates
-      for($i = 0; $i < count($qids); $i++) {
-        global $THEME;
-        echo "<p align=\"left\">" . $answers[$qids[$i]] . format_text($feedbacks[$qids[$i]], true, false)."</p>";
-      }
       print_simple_box_end();
+      echo "<p align=\"center\"><input name=\"backbtn\" type=\"button\" onclick=\"history.back()\" value=\"".get_string("back", "quiz")."\"/>\n";
+      echo "<input type=\"button\" onClick=\"window.close()\" value=\"" . get_string("close", "quiz") . "\"></p>\n";
 
     } else {//show question list
       echo "<form method=\"post\" action=\"preview.php\" $onsubmit>\n";
 
       echo "<br />";
       echo "<center>";
-      echo "<input name=\"submit\" type=\"submit\" value=\"".get_string("checkanswer", "quiz")."\" />\n";
+      echo "<input name=\"submit\" type=\"submit\" value=\"".get_string("checkanswer", "quiz")."\"/>\n";
+      echo "<input type=\"button\" onClick=\"window.close()\" value=\"" . get_string("close", "quiz") . "\">";
       echo "</center>";
       echo "</form>";
     }