From: martin Date: Wed, 5 Jun 2002 03:15:30 +0000 (+0000) Subject: Changes related to timezone display. Datetime display now uses userdate() X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=873960de8cd652395bd512be8cc45f3273641d0f;p=moodle.git Changes related to timezone display. Datetime display now uses userdate() which itself uses the USER variable timezone to alter the displayed time. --- diff --git a/course/lib.php b/course/lib.php index 863ec1b902..5ac4831853 100644 --- a/course/lib.php +++ b/course/lib.php @@ -8,10 +8,6 @@ $FORMATS = array ( ); -function logdate($date) { - return date("l, j F Y, g:i A", $date); -} - function print_log_selector_form($course, $selecteduser=0, $selecteddate="today") { // Get all the possible users @@ -36,11 +32,11 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate="today" // Get all the possible dates $tt = getdate(time()); $timemidnight = $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]); - $dates = array("$today" => "Today, ".date("j F Y", $today) ); + $dates = array("$today" => "Today, ".userdate($today, "j F Y") ); while ($timemidnight > $course->startdate) { $timemidnight = $timemidnight - 86400; - $dates["$timemidnight"] = date("l, j F Y", $timemidnight); + $dates["$timemidnight"] = userdate($timemidnight, "l, j F Y"); } if ($selecteddate == "today") { @@ -106,8 +102,8 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") { } echo ""; - echo "".date("l", $log->time).""; - echo "".date("j M Y, h:i A", $log->time).""; + echo "".userdate($log->time, "l").""; + echo "".userdate($log->time, "j M Y, h:i A").""; echo "$log->firstname $log->lastname"; echo ""; link_to_popup_window( make_log_url($log->module,$log->url), "fromloglive","$log->module $log->action", 400, 600); diff --git a/course/log.php b/course/log.php index 2153f4d21a..d4ddf59e61 100644 --- a/course/log.php +++ b/course/log.php @@ -28,7 +28,7 @@ $userinfo = "$u->firstname $u->lastname"; } if ($date) { - $dateinfo = date("l, j F Y", $date); + $dateinfo = userdate($date, "l, j F Y"); } print_header("$course->shortname: Logs", "$course->shortname : Logs", diff --git a/course/new.php b/course/new.php index d76ecbd6e4..ea9c59f69a 100644 --- a/course/new.php +++ b/course/new.php @@ -20,7 +20,7 @@ "wwwroot/course/view.php?id=$course->id\">$course->shortname -> What's new"); print_heading("Recent activity since your last login"); - print_heading(logdate($USER->lastlogin)); + print_heading(userdate($USER->lastlogin)); print_simple_box_start("center"); $modules = array ("users"); diff --git a/files/index.php b/files/index.php index f863f9730c..90c5efd7a3 100644 --- a/files/index.php +++ b/files/index.php @@ -535,7 +535,7 @@ function displaydir ($wdir) { $filename = $fullpath."/".$dir; $fileurl = rawurlencode($wdir."/".$dir); $filesafe = rawurlencode($dir); - $filedate = date("d-m-Y H:i:s", filectime($filename)); + $filedate = userdate(filectime($filename), "d-m-Y H:i:s"); echo ""; @@ -561,7 +561,7 @@ function displaydir ($wdir) { $fileurl = "$wdir/$file"; $filesafe = rawurlencode($file); $fileurlsafe = rawurlencode($fileurl); - $filedate = date("d-m-Y H:i:s", filectime($filename)); + $filedate = userdate(filectime($filename), "d-m-Y H:i:s"); echo ""; diff --git a/lib/db/mysql.sql b/lib/db/mysql.sql index d1fa14ac96..00cedb5756 100644 --- a/lib/db/mysql.sql +++ b/lib/db/mysql.sql @@ -23,6 +23,7 @@ CREATE TABLE course ( summary text NOT NULL, format tinyint(4) NOT NULL default '1', teacher varchar(100) NOT NULL default 'Teacher', + student varchar(100) NOT NULL default 'Student', startdate int(10) unsigned NOT NULL default '0', enddate int(10) unsigned NOT NULL default '0', timemodified int(10) unsigned NOT NULL default '0', diff --git a/lib/moodlelib.php b/lib/moodlelib.php index e1131ade58..b60e3571af 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -178,8 +178,22 @@ function print_editing_switch($courseid) { } -function moodledate($date) { - return date("l, j F Y, g:i A T", $date); +function userdate($date, $format="l, j F Y, g:i A") { + global $USER; + + if (abs($USER->timezone) > 12) { + return date("$format T", $date); + } + return gmdate($format, $date + (int)($USER->timezone * 3600)); +} + +function usergetdate($date) { + global $USER; + + if (abs($USER->timezone) > 12) { + return getdate($date); + } + return getdate($date + (int)($USER->timezone * 3600)); } diff --git a/lib/weblib.php b/lib/weblib.php index 428a5b908f..b21dc31e66 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -163,14 +163,18 @@ function close_window_button() { } -function choose_from_menu ($options, $name, $selected="", $nothing="Choose...", $script="") { +function choose_from_menu ($options, $name, $selected="", $nothing="Choose...", $script="", $nothingvalue="0") { // $options["value"]["label"] if ($script) { $javascript = "onChange=\"$script\""; } echo " + +

Timezone: + timezone) > 12) { + $user->timezone = 99; + } + $timenow = time(); + + for ($tz = -23; $tz <= 24; $tz++) { + $zone = (float)$tz/2.0; + $usertime = $timenow + ($tz * 1800); + if ($tz == 0) { + $timezones["$zone"] = gmdate("D, h:i a", $usertime)." (GMT)"; + } else if ($tz < 0) { + $timezones["$zone"] = gmdate("D, h:i a", $usertime)." (GMT$zone)"; + } else { + $timezones["$zone"] = gmdate("D, h:i a", $usertime)." (GMT+$zone)"; + } + } + + choose_from_menu ($timezones, "timezone", $user->timezone, "Use the server's local time", "", "99"); + + ?> + (Your current local time) + diff --git a/user/edit.php b/user/edit.php index 8133d7f3cb..fc48b756a7 100644 --- a/user/edit.php +++ b/user/edit.php @@ -99,8 +99,16 @@ $usernew->timemodified = time(); + + if (update_record("user", $usernew)) { add_to_log($course->id, "user", "update", "view.php?user=$user->id&course=$course->id", ""); + + // Copy data into $USER session variable + $usernew = (array)$usernew; + foreach ($usernew as $variable => $value) { + $USER->$variable = $value; + } redirect("view.php?id=$user->id&course=$course->id", "Changes saved"); } else { error("Could not update the user record ($user->id)"); diff --git a/user/index.php b/user/index.php index 5b56b5d296..b9636f2ae3 100644 --- a/user/index.php +++ b/user/index.php @@ -76,7 +76,7 @@ function print_user($user, $course, $teacherlinks) { echo ""; if ($teacherlinks) { - $tt = getdate(time()); + $tt = usergetdate(time()); $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]); echo "id&user=$user->id\">Contributions
"; echo "id&user=$user->id&date=$today\">Today's logs
"; diff --git a/user/lib.php b/user/lib.php index 41000602a9..b9dce9eb40 100644 --- a/user/lib.php +++ b/user/lib.php @@ -2,10 +2,6 @@ /// FUNCTIONS /////////////////////////////////////////////////////////// -function userdate($date) { - return date("l, j F Y, g:i A T", $date); -} - function ImageCopyBicubic ($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) { if (function_exists("ImageCopyResampled")) { // Assumes gd >= 2.0.1 as well