]> git.mjollnir.org Git - moodle.git/commitdiff
New usergetmidnight function and use in finding today's logs
authormartin <martin>
Mon, 10 Jun 2002 14:01:30 +0000 (14:01 +0000)
committermartin <martin>
Mon, 10 Jun 2002 14:01:30 +0000 (14:01 +0000)
course/lib.php
lib/moodlelib.php
user/index.php

index f84bb095501b78ab6a1e9afb54ecd3127d9a8c06..2cd94ca2887da5e32c6d79d668bf5f5127554dae 100644 (file)
@@ -38,9 +38,7 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate="today"
     $timenow = time(); // GMT
 
     // What day is it now for the user, and when is midnight that day (in GMT).
-    $date = usergetdate($timenow);
-    $timemidnight = gmmktime (0, 0, 0, $date["mon"], $date["mday"], $date["year"]);
-    $timemidnight = usertime($timemidnight); // Time of midnight of this user's day, in GMT
+    $timemidnight = usergetmidnight($timenow);
 
     // Put today up the top of the list
     $dates = array("$timemidnight" => "Today, ".userdate($timenow, "j F Y") );
index 8f8b41ae961af341f30ca5fec6a4bdbe1c207cb3..5c63b760a2425a261c83b34449388b85d7df42ef 100644 (file)
@@ -246,6 +246,22 @@ function usertime($date, $timezone=99) {
     return $date - (int)($timezone * 3600);
 }
 
+function usergetmidnight($date, $timezone=99) {
+// Given a time, return the GMT timestamp of the most recent midnight
+// for the current user.
+
+    global $USER;
+
+    if ($timezone == 99) {
+        $timezone = (float)$USER->timezone;
+    }
+
+    $userdate = usergetdate($date, $timezone);
+    $timemidnight = gmmktime (0, 0, 0, $userdate["mon"], $userdate["mday"], $userdate["year"]);
+    return usertime($timemidnight, $timezone); // Time of midnight of this user's day, in GMT
+
+}
+
 function usertimezone($timezone=99) {
 // returns a string that prints the user's timezone
     global $USER;
index 67b8b76f0c6dbb3a7866ee48e56cb6c5bc59b6b6..9f2bb46cfb2a9a234e3b0a4347bbcd7c45df55d3 100644 (file)
@@ -75,10 +75,9 @@ function print_user($user, $course, $teacherlinks) {
 
     echo "<FONT SIZE=1>";
     if ($teacherlinks) {
-        $tt = usergetdate(time());
-        $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
+        $timemidnight = usergetmidnight(time());
         echo "<A HREF=\"../course/user.php?id=$course->id&user=$user->id\">Contributions</A><BR>";
-        echo "<A HREF=\"../course/log.php?id=$course->id&user=$user->id&date=$today\">Today's logs</A><BR>";
+        echo "<A HREF=\"../course/log.php?id=$course->id&user=$user->id&date=$timemidnight\">Today's logs</A><BR>";
         echo "<A HREF=\"../course/log.php?id=$course->id&user=$user->id\">All logs</A><BR>";
         if (isstudent($course->id, $user->id)) {
             echo "<A HREF=\"../course/loginas.php?id=$course->id&user=$user->id\">Login as</A><BR>";