From 9481285b847520b94007c522f080c6df03b73df6 Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 10 Jun 2002 09:44:37 +0000 Subject: [PATCH] Fixes related to user timezones. All times are now displayed as expected. --- course/lib.php | 33 +++++++++++++++++++++++++++------ course/log.php | 4 ++-- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/course/lib.php b/course/lib.php index 7b59d9f699..80b3350736 100644 --- a/course/lib.php +++ b/course/lib.php @@ -10,6 +10,8 @@ $FORMATS = array ( function print_log_selector_form($course, $selecteduser=0, $selecteddate="today") { + global $USER, $CFG; + // Get all the possible users $users = array(); if ($students = get_records_sql("SELECT u.* FROM user u, user_students s @@ -30,13 +32,29 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate="today" asort($users); // Get all the possible dates - $tt = usergetdate(time()); - $timemidnight = $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]); - $dates = array("$today" => "Today, ".userdate($today, "j F Y") ); + // Note that we are keeping track of real (GMT) time and user time + // User time is only used in displays - all calcs and passing is GMT + + $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 + + // Put today up the top of the list + $dates = array("$timemidnight" => "Today, ".userdate($timenow, "j F Y") ); + + if (! $course->startdate) { + $course->startdate = $course->timecreated; + } - while ($timemidnight > $course->startdate) { + $numdates = 1; + while ($timemidnight > $course->startdate and $numdates < 365) { $timemidnight = $timemidnight - 86400; - $dates["$timemidnight"] = userdate($timemidnight, "l, j F Y"); + $timenow = $timenow - 86400; + $dates["$timemidnight"] = userdate($timenow, "l, j F Y"); + $numdates++; } if ($selecteddate == "today") { @@ -71,6 +89,8 @@ function make_log_url($module, $url) { function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") { +// It is assumed that $date is the GMT time of midnight for that day, +// and so the next 86400 seconds worth of logs are printed. $selector = "WHERE l.course='$course->id' AND l.user = u.id"; @@ -142,7 +162,8 @@ function print_course($course) { echo ""; echo ""; echo "
"; - echo "

wwwroot/course/view.php?id=$course->id\">$course->fullname

"; + echo "

wwwroot/course/view.php?id=$course->id\">$course->fullname

"; if ($teachers = get_records_sql("SELECT u.* FROM user u, user_teachers t WHERE u.id = t.user AND t.course = '$course->id' ORDER BY t.authority ASC")) { diff --git a/course/log.php b/course/log.php index 793daec786..eba1c37820 100644 --- a/course/log.php +++ b/course/log.php @@ -11,7 +11,7 @@ error("That's an invalid course id"); } - if ( ! isteacher($course->id)) { + if (! isteacher($course->id)) { error("Only teachers can view logs"); } @@ -35,7 +35,7 @@ "id\">$course->shortname -> id\">Logs -> Logs for $userinfo, $dateinfo", ""); - print_heading("Logs for $userinfo, $dateinfo"); + print_heading("Logs for $userinfo, $dateinfo (".usertimezone().")"); print_log_selector_form($course, $user, $date); -- 2.39.5