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.
This commit is contained in:
martin 2002-07-02 07:02:28 +00:00
parent 1d16c5717b
commit 7a302afc5f
10 changed files with 35 additions and 27 deletions

View File

@ -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);

View File

@ -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 "<TD><FONT SIZE=2><A HREF=\"view.php?id=$log->course\">".$courses[$log->course]."</A></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 ALIGN=right><FONT SIZE=2>".userdate($log->time, "%A")."</TD>";
echo "<TD><FONT SIZE=2>".userdate($log->time, "%e %B %Y, %I:%M %p")."</TD>";
echo "<TD><FONT SIZE=2><A TITLE=\"$log->ip\" HREF=\"../user/view.php?id=$log->user&course=$log->course\"><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);
@ -201,7 +201,7 @@ function print_course($course) {
echo "<TABLE WIDTH=100%>";
echo "<TR VALIGN=top>";
echo "<TD VALIGN=top WIDTH=50%>";
echo "<P><FONT SIZE=3><B><A TITLE=\"Click to enter this course\"
echo "<P><FONT SIZE=3><B><A TITLE=\"".get_string("entercourse")."\"
HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</A></B></FONT></P>";
if ($teachers = get_records_sql("SELECT u.* FROM user u, user_teachers t
WHERE u.id = t.user AND t.course = '$course->id'

View File

@ -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",

View File

@ -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 "<TR>";
@ -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 "<TR>";

View File

@ -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!";
}
}
}

View File

@ -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");

View File

@ -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 "<P><FONT COLOR=#555555>".userdate($topic->modified, "j M H:i")."</FONT>";
echo "<P><FONT COLOR=#555555>".userdate($topic->modified, "%e %B, %H:%M")."</FONT>";
echo "<BR>$topic->subject ";
echo "<A HREF=\"$CFG->wwwroot/mod/discuss/view.php?d=$topic->discuss\">more...</A>";
echo "</P>\n";

View File

@ -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"];

View File

@ -60,7 +60,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>".userdate($a->time, "j M Y, h:i A")."</TD>";
echo "<TD>".userdate($a->time, "%e %B %Y, %I:%M %p")."</TD>";
echo "<TD align=right>$a->numanswers</TD>";
echo "</TR>";
}

View File

@ -194,7 +194,7 @@
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>".userdate($a->time, "j M Y h:i A")."</TD>";
echo "<TD><P>".userdate($a->time, "%e %B %Y, %I:%M %p")."</TD>";
echo "<TD BGCOLOR=\"$THEME->cellcontent\"><P>";
if ($a->answer1) {
echo "$a->answer1 - ".$answers[$a->answer1 - 1];