]> git.mjollnir.org Git - moodle.git/commitdiff
Two new features for quizzes! (Thanks Shane)
authormoodler <moodler>
Thu, 8 Jul 2004 07:50:49 +0000 (07:50 +0000)
committermoodler <moodler>
Thu, 8 Jul 2004 07:50:49 +0000 (07:50 +0000)
 1)  Quizzes can be restricted by subnet

 2)  Quizzes can require a password to be entered before attempts

mod/quiz/attempt.php
mod/quiz/lib.php
mod/quiz/mod.html
mod/quiz/view.php

index 0df9ae7cece66b714250d277804281e050ab40d8..c82b7efafe99d35cb04f934bfb530db3fb0cb95a 100644 (file)
         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 "<form name=\"passwordform\" method=\"post\" action=\"attempt.php?q=$quiz->id\">\n";
+            print_simple_box_start("center");
+            
+            echo "<div align=\"center\">\n";
+            print_string("requirepasswordmessage", "quiz");
+            echo "<br /><br />\n";
+            echo " <input name=\"quizpassword\" type=\"password\" value=\"\">";
+            echo " <input name=\"submit\" type=\"submit\" value=\"".get_string("ok")."\">\n";
+            echo "</div>\n";
+
+            print_simple_box_end();
+            echo "</form>\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;
index 6e39eb1064f8f47df33b2e375333de6634eaa594..8e7ed1bf69a9113a9afb2d50e0280a2c0dc5c9e9 100644 (file)
@@ -3078,4 +3078,5 @@ function get_exp_answers( $question_num ) {
         }
     return $answers;
 }
+
 ?>
index 2d6a9fe6d7d8b28534dfeb0869d9f44248912e90..0f1f890a3f99a2cb2c6dcbe5411b2376019edfa8 100644 (file)
     if (!isset($form->questions)) {
         $form->questions = "";
     }
+    if (!isset($form->password)) {
+        $form->password = "";
+    }
+    if (!isset($form->subnet)) {
+        $form->subnet = "";
+    }
 ?>
 
 
      ?>
     </td>
 </tr>
+<tr valign=top>
+    <td align=right><p><b><?php print_string("requirepassword", "quiz") ?>:</b></p></td>
+    <td>
+        <input type="text" name="password" size=40 value="<?php p($form->password) ?>">
+        <?php helpbutton("requirepassword", get_string("requirepassword", "quiz"), "quiz"); ?>
+    </td>
+</tr>
+<tr valign=top>
+    <td align=right><p><b><?php print_string("requiresubnet", "quiz") ?>:</b></p></td>
+    <td>
+        <input type="text" name="subnet" size=40 value="<?php p($form->subnet) ?>">
+        <?php helpbutton("requiresubnet", get_string("requiresubnet", "quiz"), "quiz"); ?>
+    </td>
+</tr>
+    
 </table>
 <input type="hidden" name=questions     value="<?php p($form->questions) ?>">
 <!-- these hidden variables are always the same -->
index 9e5d3cb50e0b2481b90458a7c2f7e35c3899a2f7..da2337969e5b697225f5d7d4ba26ef706cb32736 100644 (file)
                 $strconfirmstartattempt = addslashes(get_string("confirmstartattempt","quiz"));
                 echo "<br />";
                 echo "<div align=\"center\">";
-                // 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 "</div>\n";
-                // END EDIT
                 echo "</p>";
             }
         } else {