2004-09-15 20:32:24 +00:00
|
|
|
/*/////////////////////////////////////////////////////////
|
|
|
|
// This code is based off of
|
|
|
|
// "Live Clock Lite" script - Version 1.0
|
|
|
|
// By Mark Plachetta (astroboy@zip.com.au)
|
|
|
|
//
|
|
|
|
// The original script displayed a clock.
|
|
|
|
// Mark Nielsen modified it to be a countdown timer
|
|
|
|
// for the lesson module in moodle.
|
|
|
|
//
|
2005-03-05 00:09:39 +00:00
|
|
|
// Below is the code that is used to call this page.
|
2007-01-03 19:33:44 +00:00
|
|
|
// echo "<script type=\"text/javascript\">\n";
|
2005-03-05 00:09:39 +00:00
|
|
|
// echo "var starttime = ". $timer->starttime . ";\n";
|
|
|
|
// echo "var servertime = ". time() . ";\n";
|
|
|
|
// echo "var testlength = ". $lesson->maxtime * 60 .";\n";
|
2007-01-03 19:33:44 +00:00
|
|
|
// echo "document.write('<script type=\"text/javascript\" src=\"liveclock_lite.js\"><\/script>');\n";
|
2005-03-05 00:09:39 +00:00
|
|
|
// echo "window.onload = function () { show_clock(); }";
|
|
|
|
// echo "</script>\n";
|
2004-09-15 20:32:24 +00:00
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////*/
|
|
|
|
|
2005-03-05 00:09:39 +00:00
|
|
|
var myfont_face = "Arial";
|
|
|
|
var myfont_size = "12";
|
|
|
|
var myfont_color = "#000000";
|
|
|
|
var myback_color = "#FFFFFF";
|
|
|
|
var mywidth = 80;
|
|
|
|
var my12_hour = 1;
|
|
|
|
var stopclock = 0;
|
2005-03-11 23:15:18 +00:00
|
|
|
var myclock = '';
|
2005-05-16 22:41:19 +00:00
|
|
|
var timeleft, hours, minutes, secs;
|
2005-03-05 00:09:39 +00:00
|
|
|
var javatimeDate = new Date();
|
|
|
|
var javatime = javatimeDate.getTime();
|
|
|
|
javatime = Math.floor(javatime/1000);
|
|
|
|
|
|
|
|
difference = javatime - servertime;
|
|
|
|
starttime = starttime + difference;
|
2004-09-15 20:32:24 +00:00
|
|
|
|
2005-03-11 23:15:18 +00:00
|
|
|
var dn = "";
|
2005-05-16 22:41:19 +00:00
|
|
|
var old = "";
|
2004-09-15 20:32:24 +00:00
|
|
|
|
2005-03-11 23:15:18 +00:00
|
|
|
if (document.all||document.getElementById) {
|
2005-05-16 22:41:19 +00:00
|
|
|
document.write('<span id="LiveClockIE" style="width:'+mywidth+'px;"></span>');
|
|
|
|
} else if (document.layers) {
|
|
|
|
document.write('<ilayer id="ClockPosNS"><layer width="'+mywidth+'" id="LiveClockNS"></layer></ilayer>');
|
|
|
|
} else {
|
|
|
|
old = "true"; show_clock();
|
|
|
|
}
|
2005-03-05 00:09:39 +00:00
|
|
|
|
|
|
|
/*function leave() { // feable attempt to run a script when someone leaves a timed test early, failed so far
|
|
|
|
window.onunload = window.open('http://www.google.com','','toolbar=no,menubar=no,location=no,height=500,width=500');
|
|
|
|
}
|
|
|
|
leave();*/
|
|
|
|
|
|
|
|
function show_clock() {
|
2004-09-15 20:32:24 +00:00
|
|
|
|
2005-03-05 00:09:39 +00:00
|
|
|
//show clock in NS 4
|
|
|
|
if (document.layers)
|
2004-09-15 20:32:24 +00:00
|
|
|
document.ClockPosNS.visibility="show"
|
2005-03-05 00:09:39 +00:00
|
|
|
if (old == "die") { return; }
|
2004-09-15 20:32:24 +00:00
|
|
|
|
2005-03-05 00:09:39 +00:00
|
|
|
currentDate = new Date();
|
|
|
|
current = currentDate.getTime();
|
|
|
|
current = Math.floor(current/1000);
|
|
|
|
|
|
|
|
if (current > starttime + testlength) {
|
|
|
|
myclock = '';
|
|
|
|
myclock += '<font style="color:'+myfont_color+'; font-family:'+myfont_face+'; font-size:'+myfont_size+'pt;">';
|
|
|
|
myclock += "Time is up";
|
|
|
|
myclock += '</font>';
|
|
|
|
stopclock = 1;
|
|
|
|
} else {
|
|
|
|
timeleft = starttime + testlength - current;
|
2005-05-16 22:41:19 +00:00
|
|
|
hours = Math.floor(timeleft/3600);
|
|
|
|
timeleft = timeleft - (hours * 3600);
|
|
|
|
minutes = Math.floor(timeleft/60);
|
|
|
|
secs = timeleft - (minutes * 60);
|
2005-03-05 00:09:39 +00:00
|
|
|
|
|
|
|
if (secs < 10) {
|
|
|
|
secs = "0"+secs;
|
|
|
|
}
|
2006-09-09 22:20:51 +00:00
|
|
|
if (minutes < 10) {
|
|
|
|
minutes = "0"+minutes;
|
|
|
|
}
|
2005-03-05 00:09:39 +00:00
|
|
|
myclock = '';
|
|
|
|
myclock += '<font style="color:'+myfont_color+'; font-family:'+myfont_face+'; font-size:'+myfont_size+'pt;">';
|
2006-09-09 22:20:51 +00:00
|
|
|
myclock += hours+":"+minutes+":"+secs;
|
2005-03-05 00:09:39 +00:00
|
|
|
myclock += '</font>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old == "true") {
|
|
|
|
document.write(myclock);
|
|
|
|
old = "die"; return;
|
|
|
|
}
|
2004-09-15 20:32:24 +00:00
|
|
|
|
2005-03-05 00:09:39 +00:00
|
|
|
if (document.layers) {
|
|
|
|
clockpos = document.ClockPosNS;
|
|
|
|
liveclock = clockpos.document.LiveClockNS;
|
|
|
|
liveclock.document.write(myclock);
|
|
|
|
liveclock.document.close();
|
|
|
|
} else if (document.all) {
|
|
|
|
LiveClockIE.innerHTML = myclock;
|
|
|
|
} else if (document.getElementById) {
|
|
|
|
document.getElementById("LiveClockIE").innerHTML = myclock;
|
|
|
|
}
|
2004-09-15 20:32:24 +00:00
|
|
|
|
2005-03-05 00:09:39 +00:00
|
|
|
if (stopclock == 0) {
|
|
|
|
setTimeout("show_clock()",1000);
|
|
|
|
}
|
2004-09-15 20:32:24 +00:00
|
|
|
}
|
|
|
|
|