[Postfixadmin-devel] Improvement: Use localized dates in log view
Brought to you by:
christian_boltz,
gingerdog
|
From: Ullrich v. B. <uz...@mu...> - 2016-12-21 20:39:05
|
The following is for postfixadmin v3.0.
In the log file view, dates aren't localized. This is most visible when using
postgres because in this case, dates are converted in viewlog.php using some
US date format:
$row['timestamp']=gmstrftime('%c %Z',$row['timestamp']);
This gives a date string like "Mon Dec 19 13:41:45 2016 GMT" as can be seen in
the screenshot from a german postfixadmin installation:
http://www.musoftware.de/Screenshot_2016-12-21_20-54-23.png
When using MySQL, the standard format returned by the database is used. It
looks like "2016-12-19 13:41:45", which is more "natural" but still not as
defined in the language files.
The following patch fixes this and makes the log view use the date formats
defined in the language files:
------------------------------------------------------------------------------
--- viewlog.php.orig 2016-12-20 22:30:33.296023861 +0100
+++ viewlog.php 2016-12-21 21:13:47.094649703 +0100
@@ -57,18 +57,21 @@
if ($error != 1)
{
$table_log = table_by_key('log');
- $query = "SELECT timestamp,username,domain,action,data FROM $table_log WHERE domain='$fDomain' ORDER BY timestamp DESC LIMIT 10";
if (db_pgsql()) {
- $query = "SELECT extract(epoch from timestamp) as timestamp,username,domain,action,data FROM $table_log WHERE domain='$fDomain' ORDER BY timestamp DESC LIMIT 10";
+ $dateformat = escape_string(Config::Lang('dateformat_pgsql'));
+ $query = "SELECT to_char (timestamp, '" . $dateformat . "') as timestamp,username,domain,action,data FROM $table_log WHERE domain='$fDomain' ORDER BY timestamp DESC LIMIT 10";
+ } elseif (db_sqlite()) {
+ $dateformat = escape_string(Config::Lang('dateformat_mysql'));
+ $query = "SELECT strftime (timestamp, '" . $dateformat . "') as timestamp,username,domain,action,data FROM $table_log WHERE domain='$fDomain' ORDER BY timestamp DESC LIMIT 10";
+ } else {
+ $dateformat = escape_string(Config::Lang('dateformat_mysql'));
+ $query = "SELECT date_format (timestamp, '" . $dateformat . "') as timestamp,username,domain,action,data FROM $table_log WHERE domain='$fDomain' ORDER BY timestamp DESC LIMIT 10";
}
$result=db_query($query);
if ($result['rows'] > 0)
{
while ($row = db_array ($result['result']))
{
- if (db_pgsql()) {
- $row['timestamp']=gmstrftime('%c %Z',$row['timestamp']);
- }
$tLog[] = $row;
}
}
------------------------------------------------------------------------------
The code for mysql and postgresql is tested. For the sqlite version, the code
from PFAHandler.php was used. I was not able to test it, but I assume it
should be ok, provided that the code in PFAHandler.php is ok.
Please note that the existing date formats in the language files have no hours
and minutes, so after this change, dates displayed have no time attached. I
would suggest to change that. For the german language file, the current format
$PALANG['dateformat_pgsql'] = 'dd.mm.YYYY';
$PALANG['dateformat_mysql'] = '%d.%m.%Y';
can be replaced by
$PALANG['dateformat_pgsql'] = 'DD.MM.YYYY HH24:MI';
$PALANG['dateformat_mysql'] = '%d.%m.%Y %H:%i';
to add hours and minutes. Similar for the other language files.
After this change, there's one place left, where the local date format is
ignored. I will have a look at that in the next days.
Regards
Uz
--
Ullrich von Bassewitz uz...@mu...
Encrypted email preferred PGP Key-Id: 29D93B10
|