From: moodler Date: Thu, 8 Jul 2004 07:50:49 +0000 (+0000) Subject: Two new features for quizzes! (Thanks Shane) X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=8c467676c2d3ad2f5b92994154366a33801cab0b;p=moodle.git Two new features for quizzes! (Thanks Shane) 1) Quizzes can be restricted by subnet 2) Quizzes can require a password to be entered before attempts --- diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index 0df9ae7cec..c82b7efafe 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -74,6 +74,40 @@ error("Sorry, you've had $quiz->attempts attempts already.", "view.php?id=$cm->id"); } +/// Check subnet access + if ($quiz->subnet and !address_in_subnet($_SERVER['REMOTE_ADDR'], $quiz->subnet)) { + error(get_string("subneterror", "quiz"), "view.php?id=$cm->id"); + } + +/// Check password access + if ($quiz->password) { + if (empty($_POST['quizpassword'])) { + + echo "
id\">\n"; + print_simple_box_start("center"); + + echo "
\n"; + print_string("requirepasswordmessage", "quiz"); + echo "

\n"; + echo " "; + echo " \n"; + echo "
\n"; + + print_simple_box_end(); + echo "
\n"; + + print_footer(); + exit; + + } else { + if (strcmp($quiz->password, $_POST['quizpassword']) !== 0) { + error(get_string("passworderror", "quiz"), "view.php?id=$cm->id"); + } + unset($_POST); /// needed so as not to confuse later code dealing with submitted answers + } + } + + /// BEGIN EDIT Get time limit if any. $timelimit = $quiz->timelimit * 60; diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 6e39eb1064..8e7ed1bf69 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -3078,4 +3078,5 @@ function get_exp_answers( $question_num ) { } return $answers; } + ?> diff --git a/mod/quiz/mod.html b/mod/quiz/mod.html index 2d6a9fe6d7..0f1f890a3f 100644 --- a/mod/quiz/mod.html +++ b/mod/quiz/mod.html @@ -46,6 +46,12 @@ if (!isset($form->questions)) { $form->questions = ""; } + if (!isset($form->password)) { + $form->password = ""; + } + if (!isset($form->subnet)) { + $form->subnet = ""; + } ?> @@ -237,6 +243,21 @@ ?> + +

:

+ + + + + + +

:

+ + + + + + diff --git a/mod/quiz/view.php b/mod/quiz/view.php index 9e5d3cb50e..da2337969e 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -164,14 +164,12 @@ $strconfirmstartattempt = addslashes(get_string("confirmstartattempt","quiz")); echo "
"; echo "
"; - // BEGIN EDIT - if($quiz->timelimit) { + if ($quiz->timelimit) { include("view_js.php"); } else { - print_single_button("attempt.php", $options, get_string("attemptquiznow","quiz")); + print_single_button("attempt.php", $options, get_string("attemptquiznow","quiz")); } echo "
\n"; - // END EDIT echo "

"; } } else {