]> git.mjollnir.org Git - moodle.git/commitdiff
Improved clock output and works when javascript is disabled
authormark-nielsen <mark-nielsen>
Sat, 9 Sep 2006 22:20:51 +0000 (22:20 +0000)
committermark-nielsen <mark-nielsen>
Sat, 9 Sep 2006 22:20:51 +0000 (22:20 +0000)
mod/lesson/action/continue.html
mod/lesson/locallib.php
mod/lesson/timer.js
mod/lesson/view.php

index 83cdb2655f38c3cf1805af3d3a8be6264c4a6528..50b1d221fa1246f0a89f35d70753029ec5f6be40 100644 (file)
@@ -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>
index 382859545405da50360d7a83eae3e3b2336b51c4..9d542ce1182b994108e048d5558e3c1dc2dd36d9 100644 (file)
@@ -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
index 1cbff841cea9b864776d4709bb47cfbd9687bcda..39f5ab516623f2a5c3339fe25345a524fb01c3f5 100644 (file)
             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>';
         }
         
index e89a532596515c79884743e09aecdae2a01ec076..f6025eef81c453978ef6e37fd6dbc18e0174c18f 100644 (file)
                 } 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&amp;action=navigation&amp;pageid=".LESSON_EOL."&amp;outoftime=normal", get_string("outoftime", "lesson"));