diff --git a/mod/lesson/action/continue.html b/mod/lesson/action/continue.html index 83cdb2655f3..50b1d221fa1 100644 --- a/mod/lesson/action/continue.html +++ b/mod/lesson/action/continue.html @@ -134,6 +134,9 @@ if ($lesson->displayleft) { window.onload = function () { show_clock(); }; // --> + diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 38285954540..9d542ce1182 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -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 diff --git a/mod/lesson/timer.js b/mod/lesson/timer.js index 1cbff841cea..39f5ab51662 100644 --- a/mod/lesson/timer.js +++ b/mod/lesson/timer.js @@ -77,16 +77,12 @@ if (secs < 10) { secs = "0"+secs; } - + if (minutes < 10) { + minutes = "0"+minutes; + } myclock = ''; myclock += ''; - if (hours > 0) { - myclock += hours+":"; - if (minutes < 10) { - minutes = "0"+minutes; - } - } - myclock += minutes+":"+secs; + myclock += hours+":"+minutes+":"+secs; myclock += ''; } diff --git a/mod/lesson/view.php b/mod/lesson/view.php index e89a5325965..f6025eef81c 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -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 "
".get_string("timeremaining", "lesson"). - " | ||
---|---|---|
";
+ echo '
"; } else { redirect("view.php?id=$cm->id&action=navigation&pageid=".LESSON_EOL."&outoftime=normal", get_string("outoftime", "lesson")); |