When a quiz is closing within the next 24 hours, a small countdown
authormoodler <moodler>
Mon, 28 Jul 2003 08:58:47 +0000 (08:58 +0000)
committermoodler <moodler>
Mon, 28 Jul 2003 08:58:47 +0000 (08:58 +0000)
is shown in the titlebar (drawn with javascript).

An alert is shown at ten minutes, and zero minutes.

This doesn't prevent students from doing anything, but it serves
as a reminder and just looks cool.  ;-)

lang/en/quiz.php
mod/quiz/attempt.php
mod/quiz/jsclock.php [new file with mode: 0644]

index be6ed3791c2d85e8e6bf62e564f9100eec2d7231..8c562f5c4fb610a27987c3a2d3ada282e48ab9b3 100644 (file)
@@ -40,6 +40,9 @@ $string['choice'] = "Choice";
 $string['choices'] = "Available choices";
 $string['correctanswer'] = "Correct answer";
 $string['correctanswers'] = "Correct answers";
+$string['countdown'] = "Countdown";
+$string['countdownfinished'] = "The quiz is closing, you should submit your answers now.";
+$string['countdowntenminutes'] = "The quiz will be closing in ten minutes.";
 $string['createmultiple'] = "Create multiple questions";
 $string['createnewquestion'] = "Create new question";
 $string['custom'] = "Custom format";
index 03b80fffcb8e92d84d539f8c655dae5fb5fa1f8e..c16c8818ef96fcbe4fa70174ed5095f62a78248b 100644 (file)
     }
 
     print_heading(get_string("attempt", "quiz", $numattempts));
-
     print_simple_box(text_to_html($quiz->intro), "CENTER");
 
 
+/// Add the javascript timer in the title bar if the closing time appears close
+
+    $secondsleft = $quiz->timeclose - time();
+    if ($secondsleft > 0 and $secondsleft < 24*3600) {  // less than a day remaining
+        include("jsclock.php");
+    }
+
+
 /// Print all the questions
 
-    echo "<BR>";
+    echo "<br />";
 
     if (! quiz_print_quiz_questions($quiz)) {
         print_continue("view.php?id=$cm->id");
diff --git a/mod/quiz/jsclock.php b/mod/quiz/jsclock.php
new file mode 100644 (file)
index 0000000..3929452
--- /dev/null
@@ -0,0 +1,63 @@
+<script language="javascript">\r
+<!--\r
+/// This Javascript clock provides a little countdown in the title bar\r
+\r
+var timerID = null;\r
+var timerRunning = false;\r
+var secondsleft = <?php echo $secondsleft ?>;\r
+var titleafter  = '<?php echo $quiz->name ?>';\r
+var titlebefore = '<?php echo get_string("countdown", "quiz").": " ?>';\r
+var alertmessage  = '<?php print_string("countdownfinished", "quiz") ?>';\r
+var alertmessage10  = '<?php print_string("countdowntenminutes", "quiz") ?>';\r
+\r
+function stopclock() {\r
+    if (timerRunning) {\r
+        clearTimeout(timerID);\r
+        timerRunning = false;\r
+    }\r
+}\r
+\r
+function startclock() {\r
+    stopclock();\r
+    showtime();\r
+}\r
+\r
+function showtime() {\r
+\r
+    secondsleft = secondsleft - 1;\r
+\r
+    if (secondsleft == 600) {\r
+        alert(alertmessage10);\r
+    }\r
+\r
+    if (secondsleft == 0) {\r
+        stopclock();\r
+        document.title = titleafter;\r
+        return alert(alertmessage);\r
+\r
+    } else {\r
+        current = secondsleft;\r
+\r
+        var hours = Math.floor( current / 3600 );\r
+        current = current - (hours*3600);\r
+    \r
+        var minutes =   Math.floor( current / 60 );\r
+        current = current - (minutes*60);\r
+    \r
+        var seconds = current;\r
+    \r
+        var timeValue = "" + hours;\r
+        timeValue  += ((minutes < 10) ? ":0" : ":") + minutes;\r
+        timeValue  += ((seconds < 10) ? ":0" : ":") + seconds;\r
+    \r
+        document.title = titlebefore+timeValue+' '+titleafter;\r
+        timerID = setTimeout("showtime()",1000);\r
+        timerRunning = true;\r
+    }\r
+}\r
+\r
+document.onLoad = startclock();\r
+\r
+\r
+// -- End of JavaScript code -------------- -->\r
+</script>\r