]> git.mjollnir.org Git - moodle.git/commitdiff
Changes related to timezone display. Datetime display now uses userdate()
authormartin <martin>
Wed, 5 Jun 2002 03:15:30 +0000 (03:15 +0000)
committermartin <martin>
Wed, 5 Jun 2002 03:15:30 +0000 (03:15 +0000)
which itself uses the USER variable timezone to alter the displayed time.

19 files changed:
course/lib.php
course/log.php
course/new.php
files/index.php
lib/db/mysql.sql
lib/moodlelib.php
lib/weblib.php
mod/choice/report.php
mod/journal/lib.php
mod/journal/new.php
mod/journal/report.php
mod/journal/user.php
mod/journal/view.php
mod/survey/download.php
mod/survey/report.php
user/edit.html
user/edit.php
user/index.php
user/lib.php

index 863ec1b9029c623baa166f16d4ab5d82c8df7388..5ac4831853d7cf83a5153751ec45c6108656cd34 100644 (file)
@@ -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 "<TR>";
-        echo "<TD ALIGN=right><FONT SIZE=2>".date("l", $log->time)."</TD>";
-        echo "<TD><FONT SIZE=2>".date("j M Y, h:i A", $log->time)."</TD>";
+        echo "<TD ALIGN=right><FONT SIZE=2>".userdate($log->time, "l")."</TD>";
+        echo "<TD><FONT SIZE=2>".userdate($log->time, "j M Y, h:i A")."</TD>";
         echo "<TD><FONT SIZE=2><B>$log->firstname $log->lastname</B></TD>";
         echo "<TD><FONT SIZE=2>";
         link_to_popup_window( make_log_url($log->module,$log->url), "fromloglive","$log->module $log->action", 400, 600);
index 2153f4d21ac3fccd9067b6ecd278311b849e2d4e..d4ddf59e61fa363b68b7f919f165972b8126ac7e 100644 (file)
@@ -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", 
index d76ecbd6e465f1d7fda88444a90e1354af574b2c..ea9c59f69aa0b946617ad16df8f3a15404b573f8 100644 (file)
@@ -20,7 +20,7 @@
                  "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> -> 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");
index f863f9730c611450087cce02a6295937bea0b401..90c5efd7a376697354f61d5b1a5669baa20c2d74 100644 (file)
@@ -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 "<TR>";
 
@@ -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 "<TR>";
 
index d1fa14ac96fe21843e126cddae29c6a92ceefb51..00cedb57565fcd9acbe76c0f5287488b5b14f8fe 100644 (file)
@@ -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',
index e1131ade58c0807d7d441e53b548b6ebe42ebe5b..b60e3571afc1475ac8503194e49d673d0a255a5e 100644 (file)
@@ -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));
 }
 
 
index 428a5b908febd49352fe08ca6ba865d9801dd3c6..b21dc31e66052d2b9e8766ed754426c56b364d60 100644 (file)
@@ -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 "<SELECT NAME=$name $javascript>\n";
-    echo "   <OPTION VALUE=0>$nothing</OPTION>\n";
+    echo "   <OPTION VALUE=\"$nothingvalue\"\n";
+    if ($nothingvalue == $selected) {
+        echo " SELECTED";
+    }
+    echo ">$nothing</OPTION>\n";
     foreach ($options as $value => $label) {
         echo "   <OPTION VALUE=\"$value\"";
         if ($value == $selected) {
index 9ec4822d35bb0dcc08fa57810da3140b61c1b025..7fb30f218a8844074852226631723acdb6d02bc5 100644 (file)
@@ -65,7 +65,7 @@
         echo "<TD NOWRAP BGCOLOR=\"$THEME->cellheading\">$user->firstname $user->lastname</TD>";
         echo "<TD><P>&nbsp;";
         if ($answer->timemodified) {
-            echo moodledate($answer->timemodified);
+            echo userdate($answer->timemodified);
         } 
         
         echo "</P> </TD>";
index 952b36b9ee6300d06f2ced8ad77ff2e9ad3dc07a..839c98d509e99df73ede323deb0bad7864757540 100644 (file)
@@ -4,8 +4,4 @@ $RATING = array ("3" => "Outstanding",
                  "2" => "Satisfactory",
                  "1" => "Not satisfactory");
 
-function journaldate($date) {
-    return date("l, j F Y, g:i A T", $date);
-}
-
 ?>
index fe0006427069230e96e5a92a6c915a3846cb773f..daf19added1c416f0e5f5ccdd9f8c4929756c3c6 100644 (file)
@@ -16,7 +16,7 @@
                 echo "<P><B>Journal feedback: $journal->name</B></P>";
                 echo "<FONT SIZE=2><UL>";
                 echo "<LI><A HREF=\"/mod/journal/view.php?id=$journal->coursemodule\">Your journal entry</A> has some feedback!";
-                echo ", ".moodledate($entry->timemarked);
+                echo ", ".userdate($entry->timemarked);
                 echo "</UL></FONT>";
             }
 
@@ -29,7 +29,7 @@
                 echo "<FONT SIZE=2><UL>";
                 foreach ($entries as $entry) {
                     echo "<LI>$entry->firstname $entry->lastname edited their journal";
-                    echo ", ".moodledate($entry->modified);
+                    echo ", ".userdate($entry->modified);
                 }
                 echo "</UL></FONT>";
             }
index 765b8e97399ca63eca4aeead18fae145f7f7ffa5..3412afc1a8b74420881bb8a7e11d69fa36f6c9af 100644 (file)
         echo "</TD>";
         echo "<TD NOWRAP WIDTH=100% BGCOLOR=\"$THEME->cellheading\">$student->firstname $student->lastname";
         if ($entry) {
-            echo "&nbsp;&nbsp;<FONT SIZE=1>Last edited: ".journaldate($entry->modified)."</FONT>";
+            echo "&nbsp;&nbsp;<FONT SIZE=1>Last edited: ".userdate($entry->modified)."</FONT>";
         }
         echo "</TR>";
 
             echo "<TD BGCOLOR=\"$THEME->cellheading\">Teacher Feedback:";
             choose_from_menu($RATING, "r$entry->id", $entry->rating, "Rate...");
             if ($entry->timemarked) {
-                echo "&nbsp;&nbsp;<FONT SIZE=1>".journaldate($entry->timemarked)."</FONT>";
+                echo "&nbsp;&nbsp;<FONT SIZE=1>".userdate($entry->timemarked)."</FONT>";
             }
             echo "<BR><TEXTAREA NAME=\"c$entry->id\" ROWS=4 COLS=60 WRAP=virtual>";
             p($entry->comment);
index ffd95151b597dcf9ac3fe88422e0a2779dddc695..366d87d9363fe8f332bf290fceecb2445c115333 100644 (file)
@@ -45,7 +45,7 @@
             echo "<TD BGCOLOR=\"$THEME->cellcontent\">";
             echo "<P><A HREF=\"$CFG->wwwroot/mod/journal/view.php?id=$journal->coursemodule\">$journal->name</A></P>";
             if ($entry->modified) {
-                echo "<P><FONT SIZE=1>Last edited: ".moodledate($entry->modified)."</FONT></P>";
+                echo "<P><FONT SIZE=1>Last edited: ".userdate($entry->modified)."</FONT></P>";
             }
             echo text_to_html($entry->text);
             if ($entry->teacher) {
@@ -54,7 +54,7 @@
                 print_user_picture($entry->teacher, $course->id, $teachers[$entry->teacher]->picture);
                 echo "<TD BGCOLOR=\"$THEME->cellheading\">".$RATING[$entry->rating];
                 if ($entry->timemarked) {
-                    echo "&nbsp;&nbsp;<FONT SIZE=1>".moodledate($entry->timemarked)."</FONT>";
+                    echo "&nbsp;&nbsp;<FONT SIZE=1>".userdate($entry->timemarked)."</FONT>";
                 }
                 echo "<BR><FONT COLOR=#000055>";
                 echo text_to_html($entry->comment);
index cc92c971f9c2b325762f19c5f5634e904a716fef..ad58950778321855f3923259afafb0c1ace9fa9d 100644 (file)
         if ($timenow < $timefinish) {
             if ($entry->modified) {
                 echo "<P><FONT SIZE=-2><B>Last edited:</B> ";
-                echo journaldate($entry->modified)."</FONT></P>";
+                echo userdate($entry->modified)."</FONT></P>";
             }
             if ($journal->days) {
                 echo "<P><FONT SIZE=-2><B>Editing period ends:</B> ";
-                echo journaldate($timefinish)."</FONT></P>";
+                echo userdate($timefinish)."</FONT></P>";
             }
         } else {
             echo "<P><FONT SIZE=-2><B>Editing period has ended:</B> ";
-            echo journaldate($timefinish)."</P>";
+            echo userdate($timefinish)."</P>";
         }
 
         if ($entry->comment || $entry->rating) {
 
     } else {
         echo "<P><B>This journal won't be open until: ";
-        echo journaldate($timestart)."</B></P>";
+        echo userdate($timestart)."</B></P>";
     }
 
     print_footer($course);
@@ -122,7 +122,7 @@ function print_feedback($course, $entry) {
     print_user_picture($teacher->id, $course->id, $teacher->picture);
     echo "</TD>";
     echo "<TD NOWRAP WIDTH=100% BGCOLOR=\"$THEME->cellheading\">$teacher->firstname $teacher->lastname";
-    echo "&nbsp;&nbsp;<FONT SIZE=2><I>".journaldate($entry->timemarked)."</I>";
+    echo "&nbsp;&nbsp;<FONT SIZE=2><I>".userdate($entry->timemarked)."</I>";
     echo "</TR>";
 
     echo "\n<TR><TD WIDTH=100% BGCOLOR=\"$THEME->cellcontent\">";
index 31ba883454eea5046c5155dce61127449923a32d..e41057d27eefb8a93c75736a33cdf2e4d4db1d5b 100644 (file)
             $myxls->InsertText($u->lastname);
             $myxls->InsertText($u->email);
             $myxls->InsertText($u->idnumber);
-            $myxls->InsertText( date("d-M-Y h:i:s A", $results["$user"]["time"]) );
+            $myxls->InsertText( userdate($results["$user"]["time"], "d-M-Y h:i:s A") );
             $myxls->InsertText($notes);
     
             foreach ($order as $key => $qid) {
         echo $u->lastname."    ";
         echo $u->email."    ";
         echo $u->idnumber."    ";
-        echo date("d-M-Y h:i:s A", $results["$user"]["time"])."    ";
+        echo userdate($results["$user"]["time"], "d-M-Y h:i:s A")."    ";
 
         foreach ($order as $key => $qid) {
             $question = $questions["$qid"];
index 9397f27004a1f03de7f5b65589f4d5b4401ba93f..13d4e96d2d60c5c30f62e41205db408ee6cde162 100644 (file)
             print_user_picture($a->user, $course->id, $a->picture, false);
             echo "</TD>";
             echo "<TD><P><A HREF=\"report.php?id=$id&action=student&student=$a->user\">$a->firstname $a->lastname</A></TD>";
-            echo "<TD><P>".date("j M Y h:i A",$a->time)."</TD>";
+            echo "<TD><P>".userdate($a->time, "j M Y h:i A")."</TD>";
             echo "<TD BGCOLOR=\"$THEME->cellcontent\"><P>";
             if ($a->answer1) {
                 echo "$a->answer1 - ".$answers[$a->answer1 - 1];
@@ -330,7 +330,7 @@ function print_all_responses($survey, $results) {
                  
         echo "<TR>";
         echo "<TD><A HREF=\"report.php?action=student&student=$a->id&id=$survey\">$a->firstname $a->lastname</A></TD>";
-        echo "<TD>".date("j M Y, h:i A",$a->time)."</TD>";
+        echo "<TD>".userdate($a->time, "j M Y, h:i A")."</TD>";
         echo "<TD align=right>$a->numanswers</TD>";
         echo "</TR>";
     }
index 38d1ac73e3d6561da4719eed3694dd04a71c2442..982e3023181b22bc79761bbe77c137bdc1adf214 100644 (file)
        <td><TEXTAREA NAME=description COLS=50 ROWS=10 WRAP=virtual><?=$user->description ?></TEXTAREA>
        </td>
 </tr>
+<tr valign=top>
+       <td><P>Timezone:</td>
+       <td><?
+       if (abs($user->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)</td>
+</tr>
 <tr>
        <td></td>
        <td><input type="submit" value="Update my profile"></td>
index 8133d7f3cba7427b97d3bc2a878dbceecf4a318b..fc48b756a73f9ddc86a00f2dd4baaecd50591333 100644 (file)
     
             $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)");
index 5b56b5d2965ebbd0a7bd5189624fe4cf8a954b31..b9636f2ae37443ba624b3c52ce86d3de3a151eaa 100644 (file)
@@ -76,7 +76,7 @@ function print_user($user, $course, $teacherlinks) {
 
     echo "<FONT SIZE=1>";
     if ($teacherlinks) {
-        $tt = getdate(time());
+        $tt = usergetdate(time());
         $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
         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>";
index 41000602a97189e3d8a7f3d04cf6d4e5b000951c..b9dce9eb40d9f21725b54d323e9e58d4ecb2f246 100644 (file)
@@ -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