]> git.mjollnir.org Git - moodle.git/commitdiff
More or less working now
authormoodler <moodler>
Sun, 6 Oct 2002 03:23:34 +0000 (03:23 +0000)
committermoodler <moodler>
Sun, 6 Oct 2002 03:23:34 +0000 (03:23 +0000)
mod/quiz/view.php

index 5e941c4fc1a97db7383138eaece5ba2e6e34324e..2fff1da035813d67cd0d06f5d364241b13fff53c 100644 (file)
@@ -22,7 +22,7 @@
         }
 
     } else {
-        if (! $quiz = get_record("quiz", "id", $a)) {
+        if (! $quiz = get_record("quiz", "id", $q)) {
             error("Course module is incorrect");
         }
         if (! $course = get_record("course", "id", $quiz->course)) {
 
     add_to_log($course->id, "quiz", "view", "view.php?id=$cm->id", "$quiz->id");
 
+    if ($course->format == "weeks" and $quiz->days) {
+        $timenow = time();
+        $timestart = $course->startdate + (($cw->section - 1) * 608400);
+        $timefinish = $timestart + (3600 * 24 * $quiz->days);
+        $available = ($timestart < $timenow and $timenow < $timefinish);
+    } else {
+        $available = true;
+    }
+
 // Print the page header
 
     if ($course->category) {
 
 // Print the main part of the page
 
-   echo "YOUR CODE GOES HERE";
+    print_heading($quiz->name);
+
+    print_simple_box($quiz->intro, "CENTER");
+
+    if (isset($timestart) and isset($timefinish)) {
+        if ($available) {
+            echo "<P ALIGN=CENTER>The quiz is available: ";
+        } else {
+            echo "<P ALIGN=CENTER>The quiz is not available: ";
+        }
+        echo userdate($timestart)." - ".userdate($timefinish)." </P>";
+    }
+
+    if ($attempts = quiz_get_user_attempts($quiz->id, $USER->id)) {
+        $numattempts = count($attempts);
+    } else {
+        $numattempts = 0;
+    }
+
+    echo "<P ALIGN=CENTER>You have attempted this quiz $numattempts times, out of $quiz->attempts allowed attempts.</P>";
+    if ($numattempts) { 
+        $table->data = array("Attempt", "Time", "Grade");
+        foreach ($attempts as $attempt) {
+            $table->data = array($attempt->attempt, userdate($attempt->timemodified), $attempt->grade);
+        }
+        print_table($table);
+    }
+
+    $mygrade = quiz_get_grade($quiz->id, $USER->id);
+
+    if ($numattempts < $quiz->attempts) { 
+        $options["id"] = $quiz->id;
+        if ($numattempts) {
+            print_heading("Your best grade so far is $mygrade / $quiz->grade.");
+        }
+        echo "<DIV align=CENTER>";
+        print_single_button("attempt.php", $options, $label="Attempt quiz now");
+        echo "</P>";
+    } else {
+        print_heading("You have no attempts left.  Your final grade is $mygrade / $quiz->grade.");
+    }
 
 
 // Finish the page