When a quiz is closing within the next 24 hours, a small countdown

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.  ;-)
This commit is contained in:
moodler 2003-07-28 08:58:47 +00:00
parent 4458c8a887
commit 250e71d967
3 changed files with 75 additions and 2 deletions

View 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";

View File

@ -173,13 +173,20 @@
}
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");

63
mod/quiz/jsclock.php Normal file
View File

@ -0,0 +1,63 @@
<script language="javascript">
<!--
/// This Javascript clock provides a little countdown in the title bar
var timerID = null;
var timerRunning = false;
var secondsleft = <?php echo $secondsleft ?>;
var titleafter = '<?php echo $quiz->name ?>';
var titlebefore = '<?php echo get_string("countdown", "quiz").": " ?>';
var alertmessage = '<?php print_string("countdownfinished", "quiz") ?>';
var alertmessage10 = '<?php print_string("countdowntenminutes", "quiz") ?>';
function stopclock() {
if (timerRunning) {
clearTimeout(timerID);
timerRunning = false;
}
}
function startclock() {
stopclock();
showtime();
}
function showtime() {
secondsleft = secondsleft - 1;
if (secondsleft == 600) {
alert(alertmessage10);
}
if (secondsleft == 0) {
stopclock();
document.title = titleafter;
return alert(alertmessage);
} else {
current = secondsleft;
var hours = Math.floor( current / 3600 );
current = current - (hours*3600);
var minutes = Math.floor( current / 60 );
current = current - (minutes*60);
var seconds = current;
var timeValue = "" + hours;
timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
document.title = titlebefore+timeValue+' '+titleafter;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
}
document.onLoad = startclock();
// -- End of JavaScript code -------------- -->
</script>