Skip to content

Commit

Permalink
Displayed time formats are now stored in lang files
Browse files Browse the repository at this point in the history
(see the new strftime* strings) so they can be customised per language
  • Loading branch information
moodler committed Jan 15, 2003
1 parent 9277dbd commit dcde9f0
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 25 deletions.
3 changes: 3 additions & 0 deletions admin/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
if (!isset($string[$key]) or $string[$key] == "") {
$value = htmlspecialchars($value);
$value = str_replace("$"."a", "\\$"."a", $value);
$value = str_replace("%%","%",$value);
if ($first) {
echo "</PRE><HR><P><B>".get_string("stringsnotset","","$langdir/$file")."</B></P><PRE>";
$first = false;
Expand Down Expand Up @@ -188,6 +189,7 @@
echo "<TD WIDTH=40% BGCOLOR=\"$THEME->cellheading\" VALIGN=TOP>$envalue</TD>";

$value = str_replace("\\","",$string[$key]); // Delete all slashes
$value = str_replace("%%","%",$value);
$value = htmlspecialchars($value);

$cellcolour = $value ? $THEME->cellcontent: $THEME->highlight;
Expand Down Expand Up @@ -261,6 +263,7 @@ function lang_save_file($path, $file, $strings) {
$value = str_replace("\\","",$value); // Delete all slashes
$value = str_replace("$"."a", "\\$"."a", $value); // Add slashes for $a
$value = str_replace("\"", "\\\"", $value); // Add slashes for "
$value = str_replace("%","%%",$value); // Escape % characters
if ($id == "string" and $value != ""){
fwrite($f,"\$string['$stringname'] = \"$value\";\n");
}
Expand Down
14 changes: 10 additions & 4 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate="today"
asort($courses);
}


$strftimedate = get_string("strftimedate");
$strftimedaydate = get_string("strftimedaydate");

asort($users);

// Get all the possible dates
Expand All @@ -59,7 +63,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" => get_string("today").", ".userdate($timenow, "%d %B %Y") );
$dates = array("$timemidnight" => get_string("today").", ".userdate($timenow, $strftimedate) );

if (! $course->startdate) {
$course->startdate = $course->timecreated;
Expand All @@ -69,7 +73,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, "%A, %d %B %Y");
$dates["$timemidnight"] = userdate($timenow, $strftimedaydate);
$numdates++;
}

Expand Down Expand Up @@ -150,6 +154,8 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
$totalcountlogs = "$COURSE_MAX_LOGS_PER_PAGE/$totalcountlogs";
}

$strftimedatetime = get_string("strftimedatetime");

echo "<P ALIGN=CENTER>";
print_string("displayingrecords", "", $totalcountlogs);
echo "</P>";
Expand All @@ -173,7 +179,7 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
echo "<TD NOWRAP><FONT SIZE=2><A HREF=\"view.php?id=$log->course\">".$courses[$log->course]."</A></TD>";
}
echo "<TD NOWRAP ALIGN=right><FONT SIZE=2>".userdate($log->time, "%A")."</TD>";
echo "<TD NOWRAP><FONT SIZE=2>".userdate($log->time, "%d %B %Y, %I:%M %p")."</TD>";
echo "<TD NOWRAP><FONT SIZE=2>".userdate($log->time, $strftimedatetime)."</TD>";
echo "<TD NOWRAP><FONT SIZE=2>";
link_to_popup_window("/lib/ipatlas/plot.php?address=$log->ip&user=$log->userid", "ipatlas","$log->ip", 400, 700);
echo "</TD>";
Expand Down Expand Up @@ -306,7 +312,7 @@ function print_recent_activity($course) {
} else {
echo "<P ALIGN=CENTER><FONT SIZE=1>";
echo get_string("yourlastlogin").":<BR>";
echo userdate($USER->lastlogin, "%A, %d %b %Y, %H:%M");
echo userdate($USER->lastlogin, get_string("strftimerecentfull"));
echo "</FONT></P>";
}

Expand Down
2 changes: 1 addition & 1 deletion course/log.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
$userinfo = "$u->firstname $u->lastname";
}
if ($date) {
$dateinfo = userdate($date, "%A, %d %B %Y");
$dateinfo = userdate($date, get_string("strftimedaydate"));
}

if ($course->category) {
Expand Down
6 changes: 4 additions & 2 deletions course/weeks.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
$weekofseconds = 604800;
$course->enddate = $course->startdate + ($weekofseconds * $course->numsections);

$strftimedateshort = " ".get_string("strftimedateshort");

while ($weekdate < $course->enddate) {

$nextweekdate = $weekdate + ($weekofseconds);
Expand All @@ -127,8 +129,8 @@

$thisweek = (($weekdate <= $timenow) && ($timenow < $nextweekdate));

$weekday = userdate($weekdate, " %d %B");
$endweekday = userdate($weekdate+518400, " %d %B");
$weekday = userdate($weekdate, $strftimedateshort);
$endweekday = userdate($weekdate+518400, $strftimedateshort);

if ($thisweek) {
$colorsides = "bgcolor=\"$THEME->cellheading2\" class=\"weeklyoutlinesidehighlight\"";
Expand Down
2 changes: 1 addition & 1 deletion file.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
header("Content-type: $mimetype");
readfile("$pathname");
} else {
error("Sorry, but the file you are looking for was not found", "course/view.php?id=$courseid");
error("Sorry, but the file you are looking for was not found ($pathname)", "course/view.php?id=$courseid");
}

exit;
Expand Down
8 changes: 8 additions & 0 deletions lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,14 @@
$string['startdate'] = "Course start date";
$string['startsignup'] = "Start now by creating a new account!";
$string['status'] = "Status";
$string['strftimedate'] = "%%d %%B %%Y";
$string['strftimedateshort'] = "%%d %%B";
$string['strftimedatetime'] = "%%d %%B %%Y, %%I:%%M %%p";
$string['strftimedaydate'] = "%%A, %%d %%B %%Y";
$string['strftimedaydatetime'] = "%%A, %%d %%B %%Y, %%I:%%M %%p";
$string['strftimerecent'] = "%%d %%b, %%H:%%M";
$string['strftimerecentfull'] = "%%a, %%d %%b %%Y, %%I:%%M %%p";
$string['strftimetime'] = "%%I:%%M %%p";
$string['stringsnotset'] = "The following strings are not defined in \$a";
$string['studentnotallowed'] = "Sorry, but you can not enter this course as '\$a'";
$string['success'] = "Success";
Expand Down
10 changes: 4 additions & 6 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,12 @@ function userdate($date, $format="", $timezone=99) {
global $USER;

if ($format == "") {
$format = "%A, %d %B %Y, %I:%M %p";
$formatnoday = "%A, DD %B %Y, %I:%M %p";
$fixday = true;
} else {
$formatnoday = str_replace("%d", "DD", $format);
$fixday = ($formatnoday != $format);
$format = get_string("strftimedaydatetime");
}

$formatnoday = str_replace("%d", "DD", $format);
$fixday = ($formatnoday != $format);

if ($timezone == 99) {
if (isset($USER->timezone)) {
$timezone = (float)$USER->timezone;
Expand Down
3 changes: 2 additions & 1 deletion mod/assignment/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,11 @@ function assignment_print_recent_activity(&$logs, $isteacher=false) {
}

if ($assignments) {
$strftimerecent = get_string("strftimerecent");
$content = true;
print_headline(get_string("newsubmissions", "assignment").":");
foreach ($assignments as $assignment) {
$date = userdate($assignment->time, "%d %b, %H:%M");
$date = userdate($assignment->time, $strftimerecent);
echo "<P><FONT SIZE=1>$date - $assignment->firstname $assignment->lastname<BR>";
echo "\"<A HREF=\"$CFG->wwwroot/mod/assignment/$assignment->url\">";
echo "$assignment->name";
Expand Down
6 changes: 5 additions & 1 deletion mod/choice/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@
$useranswer[$key] = array();
}
foreach ($users as $user) {
$answer = $answers[$user->id];
if (!empty($answers[$user->id])) {
$answer = $answers[$user->id];
} else {
$answer->answer = 0;
}
$useranswer[(int)$answer->answer][] = $user;
}
foreach ($choice->answer as $key => $answer) {
Expand Down
13 changes: 10 additions & 3 deletions mod/forum/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ function forum_print_recent_activity(&$logs, $isteacher=false) {
$heading = false;
$content = false;

$strftimerecent = get_string("strftimerecent");

foreach ($logs as $log) {
if ($log->module == "forum") {

Expand All @@ -321,7 +323,7 @@ function forum_print_recent_activity(&$logs, $isteacher=false) {
$heading = true;
$content = true;
}
$date = userdate($post->modified, "%d %b, %H:%M");
$date = userdate($post->modified, $strftimerecent);
echo "<P><FONT SIZE=1 $teacherpost>$date - $post->firstname $post->lastname<BR>";
echo "\"<A HREF=\"$CFG->wwwroot/mod/forum/$log->url\">";
if ($log->action == "add") {
Expand Down Expand Up @@ -1468,6 +1470,11 @@ function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5, $f

$discussioncount = 0;

if ($forum_style == "minimal") {
$strftimerecent = get_string("strftimerecent");
$strmore = get_string("more", "forum");
}

foreach ($discussions as $discussion) {
$discussioncount++;

Expand All @@ -1488,10 +1495,10 @@ function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5, $f
}
switch ($forum_style) {
case "minimal":
echo "<P><FONT COLOR=#555555>".userdate($discussion->modified, "%d %b, %H:%M")." - $discussion->firstname</FONT>";
echo "<P><FONT COLOR=#555555>".userdate($discussion->modified, $strftimerecent)." - $discussion->firstname</FONT>";
echo "<BR>$discussion->subject ";
echo "<A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$discussion->discussion\">";
echo get_string("more", "forum")."...</A>";
echo $strmore."...</A>";
echo "</P>\n";
break;
case "header":
Expand Down
3 changes: 2 additions & 1 deletion mod/journal/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ function journal_print_recent_activity(&$logs, $isteacher=false) {

if ($journals) {
$content = true;
$strftimerecent = get_string("strftimerecent");
print_headline(get_string("newjournalentries", "journal").":");
foreach ($journals as $journal) {
$date = userdate($journal->time, "%d %b, %H:%M");
$date = userdate($journal->time, $strftimerecent);
echo "<P><FONT SIZE=1>$date - $journal->firstname $journal->lastname<BR>";
echo "\"<A HREF=\"$CFG->wwwroot/mod/journal/$journal->url\">";
echo "$journal->name";
Expand Down
4 changes: 2 additions & 2 deletions mod/resource/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
break;

case WEBPAGE:
if ($frameset) {
if (!empty($frameset)) {
print_header("$course->shortname: $resource->name", "$course->fullname",
"$navigation <A TARGET=_top HREF=\"$resource->reference\" TITLE=\"$resource->reference\">$resource->name</A>",
"", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm));
Expand All @@ -69,7 +69,7 @@
break;

case UPLOADEDFILE:
if ($frameset) {
if (!empty($frameset)) {
print_header("$course->shortname: $resource->name", "$course->fullname", "$navigation $resource->name",
"", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm));
echo "<CENTER><FONT SIZE=-1>".text_to_html($resource->summary, true, false)."</FONT></CENTER>";
Expand Down
7 changes: 5 additions & 2 deletions mod/survey/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ function survey_print_recent_activity(&$logs, $isteacher=false) {

if ($surveys) {
$content = true;
$strftimerecent = get_string("strftimerecent");
print_headline(get_string("newsurveyresponses", "survey").":");
foreach ($surveys as $survey) {
$date = userdate($survey->time, "%d %b, %H:%M");
$date = userdate($survey->time, $strftimerecent);
echo "<P><FONT SIZE=1>$date - $survey->firstname $survey->lastname<BR>";
echo "\"<A HREF=\"$CFG->wwwroot/mod/survey/$survey->url\">";
echo "$survey->name";
Expand Down Expand Up @@ -213,14 +214,16 @@ function survey_count_responses($survey) {
function survey_print_all_responses($survey, $results) {
global $THEME;

$dateformat = get_string("strftimedatetime");

echo "<TABLE CELLPADDING=5 CELLSPACING=2 ALIGN=CENTER>";
echo "<TR><TD>Name<TD>Time<TD>Answered</TR>";

foreach ($results as $a) {

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, "%d %B %Y, %I:%M %p")."</TD>";
echo "<TD>".userdate($a->time, $dateformat)."</TD>";
echo "<TD align=right>$a->numanswers</TD>";
echo "</TR>";
}
Expand Down
3 changes: 2 additions & 1 deletion mod/survey/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
$strtime = get_string("time", "survey");
$stractual = get_string("actual", "survey");
$strpreferred = get_string("preferred", "survey");
$strdateformat = get_string("strftimedatetime");

echo "<TABLE ALIGN=center CELLPADDING=0 CELLSPACING=10><TR><TD>&nbsp;<TH align=left>$strname<TH align=left>$strtime<TH align=left>$stractual<TH align=left>$strpreferred</TR>";

Expand All @@ -226,7 +227,7 @@
print_user_picture($a->userid, $course->id, $a->picture, false);
echo "</TD>";
echo "<TD><P><A HREF=\"report.php?id=$id&action=student&student=$a->userid\">$a->firstname $a->lastname</A></TD>";
echo "<TD><P>".userdate($a->time, "%d %B %Y, %I:%M %p")."</TD>";
echo "<TD><P>".userdate($a->time, $strdateformat)."</TD>";
echo "<TD BGCOLOR=\"$THEME->cellcontent\"><P>";
if ($a->answer1) {
echo "$a->answer1 - ".$answers[$a->answer1 - 1];
Expand Down

0 comments on commit dcde9f0

Please sign in to comment.