]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-12540 - Quiz sometimes outputs content before <head> when previewing - breaks...
authortjhunt <tjhunt>
Tue, 11 Dec 2007 15:04:31 +0000 (15:04 +0000)
committertjhunt <tjhunt>
Tue, 11 Dec 2007 15:04:31 +0000 (15:04 +0000)
mod/quiz/attempt.php

index 3070e21640862088a75fb605ba0e4fc2d80f4f31..aa7c8f1f0f074b3fc1abee41304c525fba79d92a 100644 (file)
@@ -79,6 +79,9 @@
     $strquizzes = get_string("modulenameplural", "quiz");
     $popup = $quiz->popup && !$ispreviewing; // Controls whether this is shown in a javascript-protected window.
 
+/// We intentionally do not check open and close times here. Instead we do it lower down.
+/// This is to deal with what happens when someone submits close to the exact moment when the quiz closes.
+
 /// Check number of attempts
     $numberofpreviousattempts = count_records_select('quiz_attempts', "quiz = '{$quiz->id}' AND " .
         "userid = '{$USER->id}' AND timefinish > 0 AND preview != 1");
     }
 
 /// Check subnet access
-    if ($quiz->subnet and !address_in_subnet(getremoteaddr(), $quiz->subnet)) {
-        if ($ispreviewing) {
-            notify(get_string('subnetnotice', 'quiz'));
-        } else {
-            error(get_string("subneterror", "quiz"), "view.php?id=$cm->id");
-        }
+    if (!$ispreviewing && $quiz->subnet && !address_in_subnet(getremoteaddr(), $quiz->subnet)) {
+        error(get_string("subneterror", "quiz"), "view.php?id=$cm->id");
     }
 
 /// Check password access
         quiz_send_notification_emails($course, $quiz, $attempt, $context, $cm);
     }
 
-/// Check access to quiz page
-
-    // check the quiz times
-    if ($timestamp < $quiz->timeopen || ($quiz->timeclose and $timestamp > $quiz->timeclose)) {
-        if ($ispreviewing) {
-            notify(get_string('notavailabletostudents', 'quiz'));
-        } else {
-            notice(get_string('notavailable', 'quiz'), "view.php?id={$cm->id}");
-        }
-    }
-
     if ($finishattempt) {
         if (!empty($SESSION->passwordcheckedquizzes[$quiz->id])) {
             unset($SESSION->passwordcheckedquizzes[$quiz->id]);
         redirect($CFG->wwwroot . '/mod/quiz/review.php?attempt='.$attempt->id, 0);
     }
 
+// Now is the right time to check the open and close times.
+    if (!$ispreviewing && ($timestamp < $quiz->timeopen || ($quiz->timeclose && $timestamp > $quiz->timeclose))) {
+        error(get_string('notavailable', 'quiz'), "view.php?id={$cm->id}");
+    }
+
 /// Print the quiz page ////////////////////////////////////////////////////////
 
     // Print the page header
         $buttonoptions['q'] = $quiz->id;
         $buttonoptions['forcenew'] = true;
         print_single_button($CFG->wwwroot.'/mod/quiz/attempt.php', $buttonoptions, get_string('startagain', 'quiz'));
+    /// Notices about restrictions that would affect students.
         if ($quiz->popup) {
             notify(get_string('popupnotice', 'quiz'));
         }
+        if ($timestamp < $quiz->timeopen || ($quiz->timeclose && $timestamp > $quiz->timeclose)) {
+            notify(get_string('notavailabletostudents', 'quiz'));
+        }
+        if ($quiz->subnet && !address_in_subnet(getremoteaddr(), $quiz->subnet)) {
+            notify(get_string('subnetnotice', 'quiz'));
+        }
     } else {
         if ($quiz->attempts != 1) {
             print_heading(format_string($quiz->name).' - '.$strattemptnum);