mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
Improved clock output and works when javascript is disabled
This commit is contained in:
parent
259990d2c6
commit
2cb24b647c
@ -134,6 +134,9 @@ if ($lesson->displayleft) {
|
||||
window.onload = function () { show_clock(); };
|
||||
// -->
|
||||
</script>
|
||||
<noscript>
|
||||
<?php print_time_remaining($timer->starttime, $lesson->maxtime); ?>
|
||||
</noscript>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -369,6 +369,43 @@ function lesson_print_submit_link($name, $form, $align = 'center', $class='stand
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a time remaining in the following format: H:MM:SS
|
||||
*
|
||||
* @param int $starttime Time when the lesson started
|
||||
* @param int $maxtime Length of the lesson
|
||||
* @param boolean $return Return output switch
|
||||
* @return mixed boolean/string
|
||||
**/
|
||||
function print_time_remaining($starttime, $maxtime, $return = false) {
|
||||
// Calculate hours, minutes and seconds
|
||||
$timeleft = $starttime + $maxtime * 60 - time();
|
||||
$hours = floor($timeleft/3600);
|
||||
$timeleft = $timeleft - ($hours * 3600);
|
||||
$minutes = floor($timeleft/60);
|
||||
$secs = $timeleft - ($minutes * 60);
|
||||
|
||||
if ($minutes < 10) {
|
||||
$minutes = "0$minutes";
|
||||
}
|
||||
if ($secs < 10) {
|
||||
$secs = "0$secs";
|
||||
}
|
||||
$output = array();
|
||||
$output[] = $hours;
|
||||
$output[] = $minutes;
|
||||
$output[] = $secs;
|
||||
|
||||
$output = implode(':', $output);
|
||||
|
||||
if ($return) {
|
||||
return $output;
|
||||
} else {
|
||||
echo $output;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given some question info and some data about the the answers
|
||||
* this function parses, organises and saves the question
|
||||
|
@ -77,16 +77,12 @@
|
||||
if (secs < 10) {
|
||||
secs = "0"+secs;
|
||||
}
|
||||
|
||||
if (minutes < 10) {
|
||||
minutes = "0"+minutes;
|
||||
}
|
||||
myclock = '';
|
||||
myclock += '<font style="color:'+myfont_color+'; font-family:'+myfont_face+'; font-size:'+myfont_size+'pt;">';
|
||||
if (hours > 0) {
|
||||
myclock += hours+":";
|
||||
if (minutes < 10) {
|
||||
minutes = "0"+minutes;
|
||||
}
|
||||
}
|
||||
myclock += minutes+":"+secs;
|
||||
myclock += hours+":"+minutes+":"+secs;
|
||||
myclock += '</font>';
|
||||
}
|
||||
|
||||
|
@ -545,19 +545,18 @@
|
||||
} else {
|
||||
if ((($timer->starttime + $lesson->maxtime * 60) - time()) > 0) {
|
||||
// code for the clock
|
||||
print_simple_box_start("right", "150px", "#ffffff", 0);
|
||||
echo "<table border=\"0\" valign=\"top\" align=\"center\" class=\"generaltable\" width=\"100%\" cellspacing=\"0\">".
|
||||
"<tr><th valign=\"top\" class=\"generaltableheader\">".get_string("timeremaining", "lesson").
|
||||
"</th></tr><tr><td align=\"center\" class=\"generaltablecell\">";
|
||||
echo '<table align="right" width="150px" class="generaltable generalbox" cellspacing="0" cellpadding="5px" border="0" valign="top">'.
|
||||
"<tr><th valign=\"top\" class=\"header\">".get_string("timeremaining", "lesson").
|
||||
"</th></tr><tr><td align=\"center\" class=\"c0\">";
|
||||
echo "<script language=\"javascript\">\n";
|
||||
echo "var starttime = ". $timer->starttime . ";\n";
|
||||
echo "var servertime = ". time() . ";\n";
|
||||
echo "var testlength = ". $lesson->maxtime * 60 .";\n";
|
||||
echo "document.write('<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"timer.js\"><\/SCRIPT>');\n";
|
||||
echo "document.write('<script type=\"text/javascript\" src=\"$CFG->wwwroot/mod/lesson/timer.js\"><\/script>');\n";
|
||||
echo "window.onload = function () { show_clock(); }\n";
|
||||
echo "</script>\n";
|
||||
echo '<noscript>'.print_time_remaining($timer->starttime, $lesson->maxtime, true)."</noscript>\n";
|
||||
echo "</td></tr></table>";
|
||||
print_simple_box_end();
|
||||
echo "<br /><br /><br />";
|
||||
} else {
|
||||
redirect("view.php?id=$cm->id&action=navigation&pageid=".LESSON_EOL."&outoftime=normal", get_string("outoftime", "lesson"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user