diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php
index fd56984fb43..ff3e45f6c54 100644
--- a/mod/quiz/attempt.php
+++ b/mod/quiz/attempt.php
@@ -101,38 +101,50 @@
}
// Check password access
- if ($quiz->password and empty($_POST['q'])) {
- if (empty($_POST['quizpassword'])) {
+ if ($ispreviewing && $forcenew) {
+ unset($SESSION->passwordcheckedquizzes[$quiz->id]);
+ }
+
+ if ($quiz->password and empty($SESSION->passwordcheckedquizzes[$quiz->id])) {
+ $enteredpassword = optional_param('quizpassword', '', PARAM_RAW);
+ if (optional_param('cancelpassword', false)) {
+ // User clicked cancel in the password form.
+ redirect($CFG->wwwroot . '/mod/quiz/view.php?q=' . $quiz->id);
+ } else if (strcmp($quiz->password, $enteredpassword) === 0) {
+ // User entered the correct password.
+ $SESSION->passwordcheckedquizzes[$quiz->id] = true;
+ } else {
+ // User entered the wrong password, or has not entered one yet.
+ $url = $CFG->wwwroot . '/mod/quiz/attempt.php?q=' . $quiz->id;
+
+ if (empty($popup)) {
+ print_header('', '', '', 'quizpassword');
+ }
if (trim(strip_tags($quiz->intro))) {
- print_simple_box(format_text($quiz->intro), "center");
+ $formatoptions->noclean = true;
+ print_box(format_text($quiz->intro, FORMAT_MOODLE, $formatoptions), 'generalbox', 'intro');
}
- echo "
\n";
-
- echo "
', get_string('passworderror', 'quiz'), '
'; + } +?> + + +password, $_POST['quizpassword']) !== 0) { - error(get_string("passworderror", "quiz"), "view.php?id=$cm->id"); - } } } @@ -379,6 +391,7 @@ } if ($finishattempt) { + unset($SESSION->passwordcheckedquizzes[$quiz->id]); redirect('review.php?attempt='.$attempt->id, 0); } diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css index 924f2e7dce8..1f2c3022ebe 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -3399,6 +3399,14 @@ body#mod-forum-search .introcontent { text-align: center; } +.generalbox#passwordbox { /* Should probably match .generalbox#intro above */ + width:70%; + margin-left:auto; + margin-right:auto; +} +#passwordform { + margin: 1em 0; +} #mod-quiz-attempt #page { text-align: center; }