1 /*/////////////////////////////////////////////////////////
2 // This code is based off of
3 // "Live Clock Lite" script - Version 1.0
4 // By Mark Plachetta (astroboy@zip.com.au)
6 // The original script displayed a clock.
7 // Mark Nielsen modified it to be a countdown timer
8 // for the lesson module in moodle.
10 // Below is the code that is used to call this page.
11 // echo "<script type=\"text/javascript\">\n";
12 // echo "var starttime = ". $timer->starttime . ";\n";
13 // echo "var servertime = ". time() . ";\n";
14 // echo "var testlength = ". $lesson->timelimit .";\n";
15 // echo "document.write('<script type=\"text/javascript\" src=\"liveclock_lite.js\"><\/script>');\n";
16 // echo "window.onload = function () { show_clock(); }";
17 // echo "</script>\n";
19 //////////////////////////////////////////////////////////*/
23 var timeleft, hours, minutes, secs;
24 var javatimeDate = new Date();
25 var javatime = javatimeDate.getTime();
26 javatime = Math.floor(javatime / 1000);
28 if (typeof(clocksettings) != 'undefined') {
29 if (clocksettings.starttime) {
30 starttime = parseInt(clocksettings.starttime);
32 if (clocksettings.servertime) {
33 servertime = parseInt(clocksettings.servertime);
35 if (clocksettings.testlength) {
36 testlength = parseInt(clocksettings.testlength);
40 difference = javatime - servertime;
41 starttime = starttime + difference;
43 /*function leave() { // feable attempt to run a script when someone leaves a timed test early, failed so far
44 window.onunload = window.open('http://www.google.com','','toolbar=no,menubar=no,location=no,height=500,width=500');
48 function show_clock() {
50 currentDate = new Date();
51 current = currentDate.getTime();
52 current = Math.floor(current / 1000);
55 myclock = document.getElementById("lesson-timer");
56 if (current > starttime + testlength) {
57 mytime += M.util.get_string('timeisup', 'lesson');
60 timeleft = starttime + testlength - current;
62 myclock.className = "timeleft1";
64 hours = Math.floor(timeleft / 3600);
65 timeleft = timeleft - (hours * 3600);
66 minutes = Math.floor(timeleft / 60);
67 secs = timeleft - (minutes * 60);
73 minutes = "0" + minutes;
75 mytime += hours + ":" + minutes + ":" + secs;
78 myclock.innerHTML = mytime;
81 setTimeout("show_clock()", 1000);