From 7a302afc5f5bd9454a6e0f7ff8d511c4430eadab Mon Sep 17 00:00:00 2001 From: martin Date: Tue, 2 Jul 2002 07:02:28 +0000 Subject: [PATCH] Slight changes to userdate() function. It now uses gmstrftime() instead of gmdate to format times, thus allowing it to take advantage of locale, if set, to print dates in the appropriate language. Several userdate invocations had to be changed, though, to use the different formatting specs. --- course/index.php | 4 +++- course/lib.php | 10 +++++----- course/log.php | 2 +- files/index.php | 4 ++-- lib/moodlelib.php | 14 ++++++++------ lib/setup.php | 4 ++++ mod/forum/lib.php | 2 +- mod/survey/download.php | 18 +++++++++--------- mod/survey/lib.php | 2 +- mod/survey/report.php | 2 +- 10 files changed, 35 insertions(+), 27 deletions(-) diff --git a/course/index.php b/course/index.php index bb11588780..7c3bd4b7f1 100644 --- a/course/index.php +++ b/course/index.php @@ -3,7 +3,9 @@ require("../config.php"); require("lib.php"); - print_header("Courses", "Courses", "Courses", ""); + $title = get_string("courses"); + + print_header($title, $title, $title, ""); optional_variable($cat, 1); diff --git a/course/lib.php b/course/lib.php index d09ee3cc76..cf659275ae 100644 --- a/course/lib.php +++ b/course/lib.php @@ -64,7 +64,7 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate="today" $timemidnight = $today = usergetmidnight($timenow); // Put today up the top of the list - $dates = array("$timemidnight" => "Today, ".userdate($timenow, "j F Y") ); + $dates = array("$timemidnight" => "Today, ".userdate($timenow, "%e %B %Y") ); if (! $course->startdate) { $course->startdate = $course->timecreated; @@ -74,7 +74,7 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate="today" while ($timemidnight > $course->startdate and $numdates < 365) { $timemidnight = $timemidnight - 86400; $timenow = $timenow - 86400; - $dates["$timemidnight"] = userdate($timenow, "l, j F Y"); + $dates["$timemidnight"] = userdate($timenow, "%A, %e %B %Y"); $numdates++; } @@ -161,8 +161,8 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") { if (! $course->category) { echo "course\">".$courses[$log->course].""; } - echo "".userdate($log->time, "l").""; - echo "".userdate($log->time, "j M Y, h:i A").""; + echo "".userdate($log->time, "%A").""; + echo "".userdate($log->time, "%e %B %Y, %I:%M %p").""; echo "ip\" HREF=\"../user/view.php?id=$log->user&course=$log->course\">$log->firstname $log->lastname"; echo ""; link_to_popup_window( make_log_url($log->module,$log->url), "fromloglive","$log->module $log->action", 400, 600); @@ -201,7 +201,7 @@ function print_course($course) { echo ""; echo ""; echo ""; @@ -561,7 +561,7 @@ function displaydir ($wdir) { $fileurl = "$wdir/$file"; $filesafe = rawurlencode($file); $fileurlsafe = rawurlencode($fileurl); - $filedate = userdate(filectime($filename), "d-m-Y H:i:s"); + $filedate = userdate(filectime($filename), "%e %b %Y, %I:%M %p"); echo ""; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index ba4fdb12f1..d38d5b4820 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -205,10 +205,12 @@ function update_module_icon($moduleid) { function userdate($date, $format="", $timezone=99) { // Returns a formatted string that represents a date in user time +// WARNING: note that the format is for strftime(), not date(). + global $USER; if ($format == "") { - $format = "l, j F Y, g:i A"; + $format = "%A, %e %B %Y, %I:%M %p"; } if ($timezone == 99) { $timezone = (float)$USER->timezone; @@ -216,7 +218,7 @@ function userdate($date, $format="", $timezone=99) { if (abs($timezone) > 12) { return date("$format", $date); } - return gmdate($format, $date + (int)($timezone * 3600)); + return gmstrftime($format, $date + (int)($timezone * 3600)); } function usergetdate($date, $timezone=99) { @@ -1117,7 +1119,7 @@ function get_string($identifier, $module="", $a="", $b="", $c="") { if (!file_exists($langfile)) { // try English instead $langfile = "$langpath/en/strings.php"; if (!file_exists($langfile)) { - return "ERROR: No translation file found"; + return "ERROR: No lang file"; } } @@ -1128,18 +1130,18 @@ function get_string($identifier, $module="", $a="", $b="", $c="") { } else { if ($lang == "en") { - return "ERROR: Translation string '$identifier' is missing!"; + return "ERROR: '$identifier' is missing!"; } else { // Try looking in the english file. $langfile = "$langpath/en/strings.php"; if (!file_exists($langfile)) { - return "ERROR: No translation file found"; + return "ERROR: No lang file"; } if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) { eval($result); return $resultstring; } else { - return "ERROR: Translation string '$identifier' is missing!"; + return "ERROR: '$identifier' is missing!"; } } } diff --git a/lib/setup.php b/lib/setup.php index 6a12ff0473..d72642c952 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -34,6 +34,10 @@ $CFG->header = "$CFG->dirroot/theme/$CFG->theme/header.html"; $CFG->footer = "$CFG->dirroot/theme/$CFG->theme/footer.html"; +// Set language/locale of printed times (must be supported by OS) + + setlocale ("LC_TIME", $CFG->lang); + // Load up theme variables (colours etc) require("$CFG->dirroot/theme/$CFG->theme/config.php"); diff --git a/mod/forum/lib.php b/mod/forum/lib.php index f8237892bf..53631d6b71 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -162,7 +162,7 @@ function print_forum_latest_topics($forum_id=0, $forum_numtopics=5, $forum_style $ownpost = ($topic->userid == $USER->id); switch ($forum_style) { case "minimal": - echo "

".userdate($topic->modified, "j M H:i").""; + echo "

".userdate($topic->modified, "%e %B, %H:%M").""; echo "
$topic->subject "; echo "wwwroot/mod/discuss/view.php?d=$topic->discuss\">more..."; echo "

\n"; diff --git a/mod/survey/download.php b/mod/survey/download.php index e41057d27e..dd8d6dda60 100644 --- a/mod/survey/download.php +++ b/mod/survey/download.php @@ -142,7 +142,7 @@ $myxls->InsertText($u->lastname); $myxls->InsertText($u->email); $myxls->InsertText($u->idnumber); - $myxls->InsertText( userdate($results["$user"]["time"], "d-M-Y h:i:s A") ); + $myxls->InsertText( userdate($results["$user"]["time"], "%d-%b-%Y %I:%M:%S %p") ); $myxls->InsertText($notes); foreach ($order as $key => $qid) { @@ -187,14 +187,14 @@ if (! $u = get_record_sql("SELECT firstname,lastname,email,idnumber FROM user WHERE id = '$user'")) { error("Error finding student # $user"); } - echo $survey->id." "; - echo $survey->name." "; - echo $user." "; - echo $u->firstname." "; - echo $u->lastname." "; - echo $u->email." "; - echo $u->idnumber." "; - echo userdate($results["$user"]["time"], "d-M-Y h:i:s A")." "; + echo $survey->id."\t"; + echo $survey->name."\t"; + echo $user."\t"; + echo $u->firstname."\t"; + echo $u->lastname."\t"; + echo $u->email."\t"; + echo $u->idnumber."\t"; + echo userdate($results["$user"]["time"], "%d-%b-%Y %I:%M:%S %p")."\t"; foreach ($order as $key => $qid) { $question = $questions["$qid"]; diff --git a/mod/survey/lib.php b/mod/survey/lib.php index ffe96ab5ec..c84473253f 100644 --- a/mod/survey/lib.php +++ b/mod/survey/lib.php @@ -60,7 +60,7 @@ function print_all_responses($survey, $results) { echo ""; echo ""; - echo ""; + echo ""; echo ""; echo ""; } diff --git a/mod/survey/report.php b/mod/survey/report.php index 9a9b252a20..30226e3a1d 100644 --- a/mod/survey/report.php +++ b/mod/survey/report.php @@ -194,7 +194,7 @@ print_user_picture($a->user, $course->id, $a->picture, false); echo ""; echo ""; - echo ""; + echo ""; echo "
"; - 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' diff --git a/course/log.php b/course/log.php index 580d4f6f9a..d89f2c9f93 100644 --- a/course/log.php +++ b/course/log.php @@ -39,7 +39,7 @@ $userinfo = "$u->firstname $u->lastname"; } if ($date) { - $dateinfo = userdate($date, "l, j F Y"); + $dateinfo = userdate($date, "%A, %e %B %Y"); } print_header("$course->shortname: Logs", "$course->fullname", diff --git a/files/index.php b/files/index.php index 90c5efd7a3..09ae0c2d29 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 = userdate(filectime($filename), "d-m-Y H:i:s"); + $filedate = userdate(filectime($filename), "%e %b %Y, %I:%M %p"); echo "
id&id=$survey\">$a->firstname $a->lastname".userdate($a->time, "j M Y, h:i A")."".userdate($a->time, "%e %B %Y, %I:%M %p")."$a->numanswers

user\">$a->firstname $a->lastname

".userdate($a->time, "j M Y h:i A")."

".userdate($a->time, "%e %B %Y, %I:%M %p")."

cellcontent\">

"; if ($a->answer1) { echo "$a->answer1 - ".$answers[$a->answer1 - 1]; -- 2.39.5