]> git.mjollnir.org Git - moodle.git/commitdiff
Christian's code to support time delays
authormoodler <moodler>
Tue, 21 Mar 2006 09:24:47 +0000 (09:24 +0000)
committermoodler <moodler>
Tue, 21 Mar 2006 09:24:47 +0000 (09:24 +0000)
mod/quiz/lib.php
mod/quiz/mod.html
mod/quiz/view.php

index 84990dd98cb4d4621faee2a7234a58422abea720..70a944707043f1dbcbe9103aaa61cf0ee1756b27 100644 (file)
@@ -174,7 +174,6 @@ function quiz_update_instance($quiz) {
     $quiz->timelimit = round($quiz->timelimit);
 
     $quiz->id = $quiz->instance;
-
     if (!update_record("quiz", $quiz)) {
         return false;  // some error occurred
     }
index 16f996b4c853077ea823339ea355d5f2e10cfc9d..868004e9eebad6b9d53be3ba3cefeb824c17c135 100644 (file)
     //enforced time delay between quiz attempts add-on
     //delay1: time delay between first and second attempt
     //delay2: time delay between second and additional quiz attempt
-    if(!isset($form->delay1)) {
-        $form->delay1 = 0;
+    //enforced delay attempt between quiz
+    if (!isset($form->delay1)) {
+         $form->delay1 = $CFG->quiz_delay1;
     }
-    if(!isset($form->delay2)) {
-        $form->delay2 = 0;
+    if (!isset($form->delay2)) {
+         $form->delay2 = $CFG->quiz_delay2;
     }
 
     $fix = 0; // This will later be set to 1 if some of the variables have been fixed by the admin.
         <td align="right"><b><?php print_string("delay1", "quiz") ?>:</b></td>
         <td align="left">
         <?php
-        choose_from_menu($timedelayoptions, "delay1", "$form->delay1", "");
-        helpbutton("timedelay1", get_string("delay1","quiz"), "quiz");
-    ?>
+             choose_from_menu($timedelayoptions, "delay1", "$form->delay1", "");
+             helpbutton("timedelay1", get_string("delay1","quiz"), "quiz");
+        ?>
         </td>
         </tr>
 <?php } else $fix=1 ?>
         <td align="right"><b><?php print_string("delay2", "quiz") ?>:</b></td>
         <td align="left">
         <?php
-        choose_from_menu($timedelayoptions, "delay2", "$form->delay2", "");
-        helpbutton("timedelay2", get_string("delay2","quiz"), "quiz");
-    ?>
+             choose_from_menu($timedelayoptions, "delay2", "$form->delay2", "");
+             helpbutton("timedelay2", get_string("delay2","quiz"), "quiz");
+        ?>
         </td>
         </tr>
 <?php } else $fix=1 ?>
         <td align="right"><b><?php print_string("delay1", "quiz") ?>:</b></td>
         <td align="left">
         <?php
-             choose_from_menu($timedelayoptions, "timedelay", "$form->delay1", "");
+             choose_from_menu($timedelayoptions, "delay1", "$form->delay1", "");
              helpbutton("timedelay1", get_string("delay1","quiz"), "quiz");
         ?>
         </td>
          <td align="right"><b><?php print_string("delay2", "quiz") ?>:</b></td>
          <td align="left">
          <?php
-             choose_from_menu($timedelayoptions, "timedelay", "$form->delay2", "");
+             choose_from_menu($timedelayoptions, "delay2", "$form->delay2", "");
              helpbutton("timedelay2", get_string("delay2","quiz"), "quiz");
          ?>
          </td>
index 60d0e15362fa10b24b38648c9038f304d87c1cac..37681f194511717c8040e3de4c3ab73d3f14005f 100644 (file)
@@ -10,7 +10,7 @@
     $id          = optional_param('id', 0, PARAM_INT); // Course Module ID, or
     $q           = optional_param('q',  0, PARAM_INT);  // quiz ID
     $edit        = optional_param('edit', '');
-
+    
     if ($id) {
         if (! $cm = get_record("course_modules", "id", $id)) {
             error("There is no coursemodule with id $id");
     $strtimetaken     = get_string("timetaken", "quiz");
     $strtimecompleted = get_string("timecompleted", "quiz");
     $strgrade         = get_string("grade");
-    $strmarks          = get_string('marks', 'quiz');
+    $strmarks         = get_string('marks', 'quiz');
     $strbestgrade     = $QUIZ_GRADE_METHOD[$quiz->grademethod];
 
     $windowoptions = "left=0, top=0, channelmode=yes, fullscreen=yes, scrollbars=yes, resizeable=no, directories=no, toolbar=no, titlebar=no, location=no, status=no, menubar=no";
 
                 echo "<br />";
                 echo "</p>";
-                echo "<div align=\"center\">";
-
-                include("view_js.php");
-
-                echo "</div>\n";
+                if ($quiz->delay1 or $quiz->delay2) {
+                     //quiz enforced time delay
+                     $lastattempt_obj = get_record_select('quiz_attempts', "quiz = $quiz->id AND attempt = $numattempts AND userid = $USER->id", 'timefinish');
+                     if ($lastattempt_obj) {
+                         $lastattempt = $lastattempt_obj->timefinish;
+                     }
+                     echo "<div align=\"center\">";
+                     if($numattempts == 1 && $quiz->delay1) {
+                         if ($timenow - $quiz->delay1 > $lastattempt) {
+                              include("view_js.php");
+                         }
+                         else {
+                             $notify_msg = get_string('temporaryblocked', 'quiz') . '<b>'. userdate($lastattempt + $quiz->delay1). '<b>';
+                             print_simple_box($notify_msg, "center");
+                         }
+                     }
+                     else if($numattempts > 1 && $quiz->delay2) {
+                         if ($timenow - $quiz->delay2 > $lastattempt) {
+                              include("view_js.php");
+                         }
+                         else {
+                              $notify_msg = get_string('temporaryblocked', 'quiz') . '<b>'. userdate($lastattempt + $quiz->delay2). '<b>';
+                              print_simple_box($notify_msg, "center");
+                         }
+                     }
+                     else {
+                         include("view_js.php");
+                     }
+                     echo "</div>\n";
+                }
+                else {
+                     echo "<div align=\"center\">"; 
+                     include("view_js.php");
+                     echo "</div>\n";
+                }     
             }
         } else {
             print_heading(get_string("nomoreattempts", "quiz"));