From d8d94977199691d1ddceee2320f3b14f9a0f7dd5 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Tue, 11 Dec 2007 15:04:31 +0000 Subject: [PATCH] MDL-12540 - Quiz sometimes outputs content before when previewing - breaks HTML strict. Merged from MOODLE_19_STABLE. --- mod/quiz/attempt.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index 3070e21640..aa7c8f1f0f 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -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"); @@ -87,12 +90,8 @@ } /// 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 @@ -374,17 +373,6 @@ 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]); @@ -392,6 +380,11 @@ 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 @@ -422,9 +415,16 @@ $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); -- 2.39.5