diff --git a/doc/Developing/Style-Guidelines.md b/doc/Developing/Style-Guidelines.md index cef63a7ee8..d6acb1265f 100644 --- a/doc/Developing/Style-Guidelines.md +++ b/doc/Developing/Style-Guidelines.md @@ -37,4 +37,26 @@ do this but provides so much flexibility along with stopping the need for retrie place. As an example pull request, see [PR 706](https://github.com/librenms/librenms/pull/706/files) to get an idea of what -it's like to convert an existing pure html table to Bootgrid. \ No newline at end of file +it's like to convert an existing pure html table to Bootgrid. + +### Datetime format + +When displaying datetimes, please ensure you use the format YYYY-MM-DD mm:hh:ss where possible, you shouldn't change the +order of this as it will be confusing to users. Cutting it short to just display YYYY-MM-DD mm:hh is fine :). + +To keep things consistent we have the following variables which should be used rather than to format dates yourself. +This has the added benefit that users can customise the format: + +```php +# Date format for PHP date()s +$config['dateformat']['long'] = "r"; # RFC2822 style +$config['dateformat']['compact'] = "Y-m-d H:i:s"; +$config['dateformat']['byminute'] = "Y-m-d H:i"; +$config['dateformat']['time'] = "H:i:s"; + +# Date format for MySQL DATE_FORMAT +$config['dateformat']['mysql']['compact'] = "%Y-%m-%d %H:%i:%s"; +$config['dateformat']['mysql']['date'] = "%Y-%m-%d"; +$config['dateformat']['mysql']['time'] = "%H:%i:%s"; +``` + diff --git a/html/includes/modal/alert_schedule.inc.php b/html/includes/modal/alert_schedule.inc.php index 6afb748fb7..7c6b7b628e 100644 --- a/html/includes/modal/alert_schedule.inc.php +++ b/html/includes/modal/alert_schedule.inc.php @@ -48,13 +48,13 @@ if(is_admin() !== false) {
- +
- +
@@ -208,7 +208,7 @@ $('#map-stub').typeahead({ $(function () { $("#start").datetimepicker({ - minDate: '' + minDate: '' }); $("#end").datetimepicker(); $("#start").on("dp.change", function (e) { diff --git a/html/includes/reports/alert-log.pdf.inc.php b/html/includes/reports/alert-log.pdf.inc.php index b44023620b..5ee0e91ea1 100644 --- a/html/includes/reports/alert-log.pdf.inc.php +++ b/html/includes/reports/alert-log.pdf.inc.php @@ -32,7 +32,7 @@ $pdf->AddPage('L'); $numresults = 250; } - $full_query = "SELECT D.device_id,name,state,time_logged,DATE_FORMAT(time_logged, '%D %b %Y %T') as humandate $query LIMIT $start,$numresults"; + $full_query = "SELECT D.device_id,name,state,time_logged,DATE_FORMAT(time_logged, '".$config['dateformat']['mysql']['compact']."') as humandate $query LIMIT $start,$numresults"; foreach (dbFetchRows($full_query, $param) as $alert_entry) { $hostname = gethostbyid(mres($alert_entry['device_id'])); diff --git a/html/includes/table/alert-schedule.inc.php b/html/includes/table/alert-schedule.inc.php index ba6f9884cc..635e67be92 100644 --- a/html/includes/table/alert-schedule.inc.php +++ b/html/includes/table/alert-schedule.inc.php @@ -46,7 +46,7 @@ if ($rowCount != -1) { $sql .= " LIMIT $limit_low,$limit_high"; } -$sql = "SELECT `S`.`schedule_id`, DATE_FORMAT(`S`.`start`, '%D %b %Y %T') AS `start`, DATE_FORMAT(`S`.`end`, '%D %b %Y %T') AS `end`, `S`.`title` $sql"; +$sql = "SELECT `S`.`schedule_id`, DATE_FORMAT(`S`.`start`, '".$config['dateformat']['mysql']['compact']."') AS `start`, DATE_FORMAT(`S`.`end`, '".$config['dateformat']['mysql']['compact']."') AS `end`, `S`.`title` $sql"; foreach (dbFetchRows($sql,$param) as $schedule) { $status = 0; diff --git a/html/includes/table/alertlog.inc.php b/html/includes/table/alertlog.inc.php index 860d6066fe..0c8e515e62 100644 --- a/html/includes/table/alertlog.inc.php +++ b/html/includes/table/alertlog.inc.php @@ -39,7 +39,7 @@ if ($rowCount != -1) { $sql .= " LIMIT $limit_low,$limit_high"; } -$sql = "SELECT D.device_id,name AS alert,state,time_logged,DATE_FORMAT(time_logged, '%D %b %Y %T') as humandate,details $sql"; +$sql = "SELECT D.device_id,name AS alert,state,time_logged,DATE_FORMAT(time_logged, '".$config['dateformat']['mysql']['compact']."') as humandate,details $sql"; $rulei = 0; foreach (dbFetchRows($sql,$param) as $alertlog) { diff --git a/html/includes/table/eventlog.inc.php b/html/includes/table/eventlog.inc.php index c2bd64e4f1..d5e5e7d60e 100644 --- a/html/includes/table/eventlog.inc.php +++ b/html/includes/table/eventlog.inc.php @@ -46,7 +46,7 @@ if ($rowCount != -1) { $sql .= " LIMIT $limit_low,$limit_high"; } -$sql = "SELECT `E`.*,DATE_FORMAT(datetime, '%D %b %Y %T') as humandate $sql"; +$sql = "SELECT `E`.*,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate $sql"; foreach (dbFetchRows($sql,$param) as $eventlog) { $dev = device_by_id_cache($eventlog['host']); diff --git a/html/includes/table/syslog.inc.php b/html/includes/table/syslog.inc.php index ca041fe2ad..81df05d289 100644 --- a/html/includes/table/syslog.inc.php +++ b/html/includes/table/syslog.inc.php @@ -60,7 +60,7 @@ if ($rowCount != -1) { $sql .= " LIMIT $limit_low,$limit_high"; } -$sql = "SELECT S.*, DATE_FORMAT(timestamp, '%Y-%m-%d %T') AS date $sql"; +$sql = "SELECT S.*, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date $sql"; foreach (dbFetchRows($sql,$param) as $syslog) { $dev = device_by_id_cache($syslog['device_id']); diff --git a/html/pages/authlog.inc.php b/html/pages/authlog.inc.php index 606345526e..64b4080ad2 100644 --- a/html/pages/authlog.inc.php +++ b/html/pages/authlog.inc.php @@ -4,7 +4,7 @@ if ($_SESSION['userlevel'] >= '10') { echo(""); - foreach (dbFetchRows("SELECT *,DATE_FORMAT(datetime, '%D %b %Y %T') as humandate FROM `authlog` ORDER BY `datetime` DESC LIMIT 0,250") as $entry) + foreach (dbFetchRows("SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `authlog` ORDER BY `datetime` DESC LIMIT 0,250") as $entry) { if ($bg == $list_colour_a) { $bg = $list_colour_b; } else { $bg=$list_colour_a; } diff --git a/html/pages/bill.inc.php b/html/pages/bill.inc.php index c6c0029e65..13b640057b 100644 --- a/html/pages/bill.inc.php +++ b/html/pages/bill.inc.php @@ -50,8 +50,8 @@ if (bill_permitted($bill_id)) $bill_color = "#0000cc"; } - $fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '%M %D %Y')"); - $totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '%M %D %Y')"); + $fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '".$config['dateformat']['mysql']['date']."')"); + $totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '".$config['dateformat']['mysql']['date']."')"); $unixfrom = dbFetchCell("SELECT UNIX_TIMESTAMP('$datefrom')"); $unixto = dbFetchCell("SELECT UNIX_TIMESTAMP('$dateto')"); diff --git a/html/pages/bill/transfer.inc.php b/html/pages/bill/transfer.inc.php index fd317393d2..194db3446e 100644 --- a/html/pages/bill/transfer.inc.php +++ b/html/pages/bill/transfer.inc.php @@ -25,8 +25,8 @@ $in_data = $bill_data['total_data_in']; $out_data = $bill_data['total_data_out']; - $fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '%M %D %Y')"); - $totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '%M %D %Y')"); + $fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '".$config['dateformat']['mysql']['date']."')"); + $totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '".$config['dateformat']['mysql']['date']."')"); $unixfrom = dbFetchCell("SELECT UNIX_TIMESTAMP('$datefrom')"); $unixto = dbFetchCell("SELECT UNIX_TIMESTAMP('$dateto')"); $unix_prev_from = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastfrom')"); diff --git a/html/pages/device/logs/eventlog.inc.php b/html/pages/device/logs/eventlog.inc.php index 57753f048c..aec8bdd98c 100644 --- a/html/pages/device/logs/eventlog.inc.php +++ b/html/pages/device/logs/eventlog.inc.php @@ -31,7 +31,7 @@ if( !empty($_POST['string']) ) { $sql .= " AND message LIKE '%".mres($_POST['string'])."%'"; } -$entries = dbFetchRows("SELECT *,DATE_FORMAT(datetime, '%D %b %Y %T') as humandate FROM `eventlog` WHERE `host` = ? $sql ORDER BY `datetime` DESC LIMIT 0,250", array($device['device_id'])); +$entries = dbFetchRows("SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` WHERE `host` = ? $sql ORDER BY `datetime` DESC LIMIT 0,250", array($device['device_id'])); echo('
diff --git a/html/pages/device/logs/syslog.inc.php b/html/pages/device/logs/syslog.inc.php index 6ff642123d..7aae3b8e0c 100644 --- a/html/pages/device/logs/syslog.inc.php +++ b/html/pages/device/logs/syslog.inc.php @@ -40,7 +40,7 @@ if ($_POST['program']) $param[] = $_POST['program']; } -$sql = "SELECT *, DATE_FORMAT(timestamp, '%Y-%m-%d %T') AS date from syslog WHERE device_id = ? $where"; +$sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog WHERE device_id = ? $where"; $sql .= " ORDER BY timestamp DESC LIMIT 1000"; echo('
diff --git a/html/pages/device/overview/eventlog.inc.php b/html/pages/device/overview/eventlog.inc.php index 1fb306c679..ff235aa4a8 100644 --- a/html/pages/device/overview/eventlog.inc.php +++ b/html/pages/device/overview/eventlog.inc.php @@ -10,7 +10,7 @@ echo(" Recent Events"); echo('
'); -$eventlog = dbFetchRows("SELECT *,DATE_FORMAT(datetime, '%d/%b/%y %T') as humandate FROM `eventlog` WHERE `host` = ? ORDER BY `datetime` DESC LIMIT 0,10", array($device['device_id'])); +$eventlog = dbFetchRows("SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` WHERE `host` = ? ORDER BY `datetime` DESC LIMIT 0,10", array($device['device_id'])); foreach ($eventlog as $entry) { include("includes/print-event-short.inc.php"); diff --git a/html/pages/device/overview/syslog.inc.php b/html/pages/device/overview/syslog.inc.php index b473078a55..1d26fbb2a7 100644 --- a/html/pages/device/overview/syslog.inc.php +++ b/html/pages/device/overview/syslog.inc.php @@ -2,7 +2,7 @@ if ($config['enable_syslog']) { - $syslog = dbFetchRows("SELECT *, DATE_FORMAT(timestamp, '%Y-%m-%d %T') AS date from syslog WHERE device_id = ? ORDER BY timestamp DESC LIMIT 20", array($device['device_id'])); + $syslog = dbFetchRows("SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog WHERE device_id = ? ORDER BY timestamp DESC LIMIT 20", array($device['device_id'])); if (count($syslog)) { echo('
'); diff --git a/html/pages/device/port/events.inc.php b/html/pages/device/port/events.inc.php index 3cdd09c7b3..6de49ef262 100644 --- a/html/pages/device/port/events.inc.php +++ b/html/pages/device/port/events.inc.php @@ -1,6 +1,6 @@ '); foreach ($entries as $entry) diff --git a/html/pages/device/showconfig.inc.php b/html/pages/device/showconfig.inc.php index 5ce3e608cc..ca96e6559c 100644 --- a/html/pages/device/showconfig.inc.php +++ b/html/pages/device/showconfig.inc.php @@ -48,7 +48,7 @@ if ($_SESSION['userlevel'] >= "7") if ($vars['rev'] == $svnlog["rev"]) { echo(''); } - $linktext = "r" . $svnlog["rev"] . " " . date("d M H:i", strtotime($svnlog["date"])) . ""; + $linktext = "r" . $svnlog["rev"] . " " . date($config['dateformat']['byminute'], strtotime($svnlog["date"])) . ""; echo(generate_link($linktext, array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig', 'rev' => $svnlog["rev"]))); if ($vars['rev'] == $svnlog["rev"]) { diff --git a/html/pages/front/default.php b/html/pages/front/default.php index 9e689b0065..7b17f08a45 100644 --- a/html/pages/front/default.php +++ b/html/pages/front/default.php @@ -165,7 +165,7 @@ echo(' if ($config['enable_syslog']) { - $sql = "SELECT *, DATE_FORMAT(timestamp, '%D %b %T') AS date from syslog ORDER BY timestamp DESC LIMIT 20"; + $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY timestamp DESC LIMIT 20"; $query = mysql_query($sql); echo('
@@ -198,10 +198,10 @@ if ($config['enable_syslog']) if ($_SESSION['userlevel'] >= '10') { - $query = "SELECT *,DATE_FORMAT(datetime, '%D %b %T') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15"; + $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15"; $alertquery = "SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id ORDER BY `time_logged` DESC LIMIT 0,15"; } else { - $query = "SELECT *,DATE_FORMAT(datetime, '%D %b %T') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = P.device_id AND P.user_id = " . $_SESSION['user_id'] . " ORDER BY `datetime` DESC LIMIT 0,15"; + $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = P.device_id AND P.user_id = " . $_SESSION['user_id'] . " ORDER BY `datetime` DESC LIMIT 0,15"; $alertquery = "SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id RIGHT JOIN devices_perms ON alert_log.device_id = devices_perms.device_id AND devices_perms.user_id = " . $_SESSION['user_id'] . " ORDER BY `time_logged` DESC LIMIT 0,15"; } diff --git a/html/pages/front/demo.php b/html/pages/front/demo.php index f9651a58e7..1000fbca24 100644 --- a/html/pages/front/demo.php +++ b/html/pages/front/demo.php @@ -161,7 +161,7 @@ echo("

Recent Syslog Messages

"); -$sql = "SELECT *, DATE_FORMAT(timestamp, '%D %b %T') AS date from `syslog` ORDER BY seq DESC LIMIT 20"; +$sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from `syslog` ORDER BY seq DESC LIMIT 20"; echo("
"); foreach (dbFetchRows($sql) as $entry) { diff --git a/html/pages/front/example2.php b/html/pages/front/example2.php index 1950e9eeed..717ee75184 100644 --- a/html/pages/front/example2.php +++ b/html/pages/front/example2.php @@ -96,7 +96,7 @@ echo(" "); -$sql = "SELECT *, DATE_FORMAT(timestamp, '%D %b %T') AS date from syslog ORDER BY timestamp DESC LIMIT 20"; +$sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY timestamp DESC LIMIT 20"; echo("
"); foreach (dbFetchRows($sql) as $entry) { diff --git a/html/pages/front/globe.php b/html/pages/front/globe.php index 94b31e2dfa..75a5917c70 100644 --- a/html/pages/front/globe.php +++ b/html/pages/front/globe.php @@ -123,7 +123,7 @@ echo ' //From default.php - This code is not part of above license. if ($config['enable_syslog']) { -$sql = "SELECT *, DATE_FORMAT(timestamp, '%D %b %T') AS date from syslog ORDER BY seq DESC LIMIT 20"; +$sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY seq DESC LIMIT 20"; $query = mysql_query($sql); echo('
@@ -155,9 +155,9 @@ echo('
if ($_SESSION['userlevel'] == '10') { - $query = "SELECT *,DATE_FORMAT(datetime, '%D %b %T') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15"; + $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15"; } else { - $query = "SELECT *,DATE_FORMAT(datetime, '%D %b %T') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = + $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = P.device_id AND P.user_id = " . $_SESSION['user_id'] . " ORDER BY `datetime` DESC LIMIT 0,15"; } diff --git a/html/pages/front/jt.php b/html/pages/front/jt.php index bead12a521..2256cf0856 100644 --- a/html/pages/front/jt.php +++ b/html/pages/front/jt.php @@ -104,7 +104,7 @@ echo(" "); -$sql = "SELECT *, DATE_FORMAT(timestamp, '%D %b %T') AS date from syslog,devices WHERE syslog.device_id = devices.device_id ORDER BY seq DESC LIMIT 20"; +$sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog,devices WHERE syslog.device_id = devices.device_id ORDER BY seq DESC LIMIT 20"; echo("
"); foreach (dbFetchRows($sql) as $entry) { diff --git a/html/pages/front/traffic.php b/html/pages/front/traffic.php index da614b1fbc..5f9a8acced 100644 --- a/html/pages/front/traffic.php +++ b/html/pages/front/traffic.php @@ -98,7 +98,7 @@ echo(" "); -$sql = "SELECT *, DATE_FORMAT(timestamp, '%D %b %T') AS date from syslog,devices WHERE syslog.device_id = devices.device_id ORDER BY seq DESC LIMIT 20"; +$sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog,devices WHERE syslog.device_id = devices.device_id ORDER BY seq DESC LIMIT 20"; echo("
"); foreach (dbFetchRows($sql) as $entry) { diff --git a/html/pages/graphs.inc.php b/html/pages/graphs.inc.php index 2996766c7e..89c47aeecb 100644 --- a/html/pages/graphs.inc.php +++ b/html/pages/graphs.inc.php @@ -146,11 +146,11 @@ if (!$auth) echo('
- +
- +
diff --git a/html/pages/syslog.inc.php b/html/pages/syslog.inc.php index 0786a8f9e2..0c8eb1a60f 100644 --- a/html/pages/syslog.inc.php +++ b/html/pages/syslog.inc.php @@ -100,7 +100,7 @@ $(function () { if( $("#dtpickerto").val() != "" ) { $("#dtpickerfrom").data("DateTimePicker").maxDate($("#dtpickerto").val()); } else { - $("#dtpickerto").data("DateTimePicker").maxDate(''); + $("#dtpickerto").data("DateTimePicker").maxDate(''); } }); diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 9a8105e090..739cc11273 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -583,8 +583,14 @@ $config['perf_times_purge'] = 30; # Number in days # Date format for PHP date()s $config['dateformat']['long'] = "r"; # RFC2822 style $config['dateformat']['compact'] = "Y-m-d H:i:s"; +$config['dateformat']['byminute'] = "Y-m-d H:i"; $config['dateformat']['time'] = "H:i:s"; +# Date format for MySQL DATE_FORMAT +$config['dateformat']['mysql']['compact'] = "%Y-%m-%d %H:%i:%s"; +$config['dateformat']['mysql']['date'] = "%Y-%m-%d"; +$config['dateformat']['mysql']['time'] = "%H:%i:%s"; + $config['enable_clear_discovery'] = 1;// Set this to 0 if you want to disable the web option to rediscover devices $config['enable_port_relationship'] = TRUE;// Set this to false to not display neighbour relationships for ports diff --git a/scripts/console-ui.php b/scripts/console-ui.php index 566b94dd4a..2ab7b7368f 100755 --- a/scripts/console-ui.php +++ b/scripts/console-ui.php @@ -52,7 +52,7 @@ while($end == 0) { $sql = "WHERE host='".$options['d']."'"; } - $query = "SELECT *,DATE_FORMAT(datetime, '%D %b %Y %T') as humandate FROM `eventlog` AS E $sql ORDER BY `datetime` DESC LIMIT 20"; + $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` AS E $sql ORDER BY `datetime` DESC LIMIT 20"; foreach (dbFetchRows($query, $param) as $entry) { $tbl->addRow(array($entry['datetime'],gethostbyid($entry['host']),$entry['message'],$entry['type'],$entry['reference'])); @@ -67,7 +67,7 @@ while($end == 0) { $sql = "WHERE device_id='".$options['d']."'"; } - $query = "SELECT *, DATE_FORMAT(timestamp, '%Y-%m-%d %T') AS date from syslog AS S $sql_query ORDER BY `timestamp` DESC LIMIT 20"; + $query = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog AS S $sql_query ORDER BY `timestamp` DESC LIMIT 20"; foreach (dbFetchRows($query, $param) as $entry) { $tbl->addRow(array($entry['timestamp'],gethostbyid($entry['device_id']),$entry['program'],$entry['msg'],$entry['level'],$entry['facility']));