From e5347b145edc58aae235edc3014d9d79b5c94a75 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sun, 29 Nov 2015 20:12:12 -0500 Subject: [PATCH 1/8] #329 Update installer for logging table --- install/mods-for-hesk/sql/installSql.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/install/mods-for-hesk/sql/installSql.php b/install/mods-for-hesk/sql/installSql.php index 57162b37..72c33983 100644 --- a/install/mods-for-hesk/sql/installSql.php +++ b/install/mods-for-hesk/sql/installSql.php @@ -693,4 +693,19 @@ function execute252Scripts() hesk_dbConnect(); executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "settings` SET `Value` = '2.5.2' WHERE `Key` = 'modsForHeskVersion'"); +} + +// BEGIN Version 2.6.0 +function execute260Scripts() +{ + global $hesk_settings; + hesk_dbConnect(); + + executeQuery("CREATE TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "logging` ( + `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + `username` VARCHAR(200), + `message` MEDIUMTEXT NOT NULL, + `severity` INT NOT NULL, + `location` MEDIUMTEXT) ENGINE = MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"); + executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "settings` SET `Value` = '2.6.0' WHERE `Key` = 'modsForHeskVersion'"); } \ No newline at end of file From 3c3eb3543287bf14871e98f3dcabd6cb64b70924 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sun, 29 Nov 2015 21:19:50 -0500 Subject: [PATCH 2/8] Getting started on message logs --- admin/view_message_log.php | 72 ++++++++++++++++++++++++ install/mods-for-hesk/sql/installSql.php | 3 +- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 admin/view_message_log.php diff --git a/admin/view_message_log.php b/admin/view_message_log.php new file mode 100644 index 00000000..790677a4 --- /dev/null +++ b/admin/view_message_log.php @@ -0,0 +1,72 @@ + + +
+
+
+
+ Search Logs +
+
+
+
+ +
+ +
+
+
+ +
+ + +
+
+
+ +
+ +
+
+
+ +
+
+
+
+
+
+ Logs +
+
+
+
+ + Date: Sun, 29 Nov 2015 22:05:07 -0500 Subject: [PATCH 3/8] Basic initial load is working --- admin/view_message_log.php | 4 +++ internal-api/admin/message-log/index.php | 24 ++++++++++++++++++ internal-api/dao/message_log_dao.php | 31 ++++++++++++++++++++++++ internal-api/js/view-message-log.js | 21 ++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 internal-api/admin/message-log/index.php create mode 100644 internal-api/dao/message_log_dao.php create mode 100644 internal-api/js/view-message-log.js diff --git a/admin/view_message_log.php b/admin/view_message_log.php index 790677a4..3c1ad83b 100644 --- a/admin/view_message_log.php +++ b/admin/view_message_log.php @@ -13,6 +13,10 @@ hesk_load_database_functions(); hesk_session_start(); hesk_dbConnect(); hesk_isLoggedIn(); + + +define('EXTRA_JS', ''); + /* Print header */ require_once(HESK_PATH . 'inc/headerAdmin.inc.php'); diff --git a/internal-api/admin/message-log/index.php b/internal-api/admin/message-log/index.php new file mode 100644 index 00000000..e5f5bff1 --- /dev/null +++ b/internal-api/admin/message-log/index.php @@ -0,0 +1,24 @@ += '" . hesk_dbEscape($from_date) . " 00:00:00' "; + } + $to_date_format = preg_match("/\d{4}-\d{2}-\d{2}/", $to_date); + if ($to_date != NULL + && $to_date_format === 1) { + $sql .= "AND `timestamp` <= '" . hesk_dbEscape($to_date) . " 23:59:59' "; + } + if ($severity_id != NULL) { + $sql .= "AND `severity` = " . intval($severity_id); + } + + $rs = hesk_dbQuery($sql); + + $results = []; + while ($row = hesk_dbFetchAssoc($rs)) { + $results[] = $row; + } + + return $results; +} \ No newline at end of file diff --git a/internal-api/js/view-message-log.js b/internal-api/js/view-message-log.js new file mode 100644 index 00000000..8c106be6 --- /dev/null +++ b/internal-api/js/view-message-log.js @@ -0,0 +1,21 @@ +$(document).ready(function() { + // We should show the latest 50 logs when the user first views the page. + var endpoint = getHelpdeskUrl(); + endpoint += '/internal-api/admin/message-log/'; + $.ajax({ + url: endpoint, + data: { + location: null, + fromDate: null, + toDate: null, + severityId: null + }, + method: 'POST', + success: function(data) { + console.log(data); + }, + error: function(data) { + console.error(data); + } + }) +}) \ No newline at end of file From 0c841ce60b6b132f91404e382f6164340c0ef5ea Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Mon, 30 Nov 2015 13:04:38 -0500 Subject: [PATCH 4/8] Committing in a bad state...search is half-working --- admin/view_message_log.php | 17 +++++++- internal-api/js/view-message-log.js | 61 ++++++++++++++++++++++++----- 2 files changed, 68 insertions(+), 10 deletions(-) diff --git a/admin/view_message_log.php b/admin/view_message_log.php index 3c1ad83b..961eaf77 100644 --- a/admin/view_message_log.php +++ b/admin/view_message_log.php @@ -58,7 +58,7 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php'); - + @@ -67,6 +67,21 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
Logs
+
+ + + + + + + + + + + + +
DateUserLocationMessage
+
diff --git a/internal-api/js/view-message-log.js b/internal-api/js/view-message-log.js index 8c106be6..a90ad7f7 100644 --- a/internal-api/js/view-message-log.js +++ b/internal-api/js/view-message-log.js @@ -1,21 +1,64 @@ $(document).ready(function() { // We should show the latest 50 logs when the user first views the page. + searchLogs(null, null, null, null); + + $('#search-button').click(function() { + var location = getNullableField($('input[name="location"]').val()); + }); +}); + +function getNullableField(value) { + return value !== "" ? value : null; +} + +function searchLogs(location, fromDate, toDate, severity) { var endpoint = getHelpdeskUrl(); endpoint += '/internal-api/admin/message-log/'; + $.ajax({ url: endpoint, data: { - location: null, - fromDate: null, - toDate: null, - severityId: null + location: location, + fromDate: fromDate, + toDate: toDate, + severityId: severity }, method: 'POST', - success: function(data) { - console.log(data); - }, + success: displayResults, error: function(data) { console.error(data); } - }) -}) \ No newline at end of file + }); +} + +function displayResults(data) { + data = $.parseJSON(data); + var table = $('#results-table > tbody'); + table.empty(); + + if (data.length === 0) { + table.append('No results found'); + } else { + for (var index in data) { + var result = data[index]; + table.append('' + + '' + result.timestamp + '' + + '' + result.username + '' + + '' + result.location + '' + + '' + result.message + ''); + } + } +} + +function getRowColor(result) { + switch (result.severity) { + case "1": + return 'class="info"'; + case "2": + return 'class="warning"'; + case "3": + return 'class="danger"'; + } + + return ''; +} \ No newline at end of file From eda289931fa8e9253cd0e82a6a57626c799b019e Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Thu, 3 Dec 2015 21:06:24 -0500 Subject: [PATCH 5/8] Search is now working --- internal-api/js/view-message-log.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal-api/js/view-message-log.js b/internal-api/js/view-message-log.js index a90ad7f7..c95f484a 100644 --- a/internal-api/js/view-message-log.js +++ b/internal-api/js/view-message-log.js @@ -4,6 +4,14 @@ $(document).ready(function() { $('#search-button').click(function() { var location = getNullableField($('input[name="location"]').val()); + var dateFrom = getNullableField($('input[name="from-date"]').val()); + var dateTo = getNullableField($('input[name="to-date"]').val()); + var severity = $('select[name="severity"]').val(); + if (severity == -1) { + severity = null; + } + + searchLogs(location, dateFrom, dateTo, severity); }); }); From 9d2fd5f4d04efe1199dc17b3cf416b59160079bf Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Tue, 8 Dec 2015 18:25:08 -0500 Subject: [PATCH 6/8] Some more message log stuff. Almost done. --- admin/view_message_log.php | 4 +--- inc/headerAdmin.inc.php | 1 + internal-api/dao/message_log_dao.php | 5 +++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/admin/view_message_log.php b/admin/view_message_log.php index 961eaf77..3106452c 100644 --- a/admin/view_message_log.php +++ b/admin/view_message_log.php @@ -77,9 +77,7 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php'); Message - - - + diff --git a/inc/headerAdmin.inc.php b/inc/headerAdmin.inc.php index 35698c70..54521913 100644 --- a/inc/headerAdmin.inc.php +++ b/inc/headerAdmin.inc.php @@ -90,6 +90,7 @@ $modsForHesk_settings = mfh_getSettings(); + Date: Tue, 8 Dec 2015 22:12:54 -0500 Subject: [PATCH 7/8] Contentify the page --- admin/view_message_log.php | 40 +++++++++++++++++++++----------------- language/en/text.php | 10 ++++++++++ 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/admin/view_message_log.php b/admin/view_message_log.php index 3106452c..afbdbbbd 100644 --- a/admin/view_message_log.php +++ b/admin/view_message_log.php @@ -28,53 +28,57 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
- Search Logs +
- +
- +
- +
- - + +
- +
- +
- Logs +
- - - - + + + + diff --git a/language/en/text.php b/language/en/text.php index 62ac627a..b9c5947f 100644 --- a/language/en/text.php +++ b/language/en/text.php @@ -21,6 +21,16 @@ $hesklang['_COLLATE']='utf8_unicode_ci'; // This is the email break line that will be used in email piping $hesklang['EMAIL_HR']='------ Reply above this line ------'; +// ADDED OR MODIFIED IN Mods for HESK 2.6.0 +$hesklang['search_logs'] = 'Search Logs'; +$hesklang['date_logged'] = 'Date Logged'; +$hesklang['from_date'] = 'From Date'; +$hesklang['to_date'] = 'To Date'; +$hesklang['severity'] = 'Severity'; +$hesklang['debug'] = 'Debug'; +$hesklang['warning_title_case'] = 'Warning'; +$hesklang['logs'] = 'Logs'; + // ADDED OR MODIFIED IN Mods for HESK 2.5.2 $hesklang['manage_statuses'] = 'Manage Statuses'; $hesklang['manage_service_messages'] = 'Manage Service Messages'; From 26e750959af3b07664dfcdd9f51c3ab042a3865a Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Thu, 10 Dec 2015 22:15:32 -0500 Subject: [PATCH 8/8] Some improvments --- admin/view_message_log.php | 11 ++++++++--- build.php | 4 ++++ css/mods-for-hesk.css | 14 ++++++++++++++ inc/common.inc.php | 25 +++++++++++++++++++++++++ inc/header.inc.php | 5 ++--- inc/headerAdmin.inc.php | 4 +--- inc/show_admin_nav.inc.php | 10 ++++++++++ language/en/text.php | 2 ++ 8 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 build.php diff --git a/admin/view_message_log.php b/admin/view_message_log.php index afbdbbbd..66fce341 100644 --- a/admin/view_message_log.php +++ b/admin/view_message_log.php @@ -14,6 +14,7 @@ hesk_session_start(); hesk_dbConnect(); hesk_isLoggedIn(); +hesk_checkPermission('can_view_logs'); define('EXTRA_JS', ''); @@ -45,8 +46,8 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
- - + +
@@ -61,8 +62,12 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
+
+
+ +
+
- diff --git a/build.php b/build.php new file mode 100644 index 00000000..3a51bf2d --- /dev/null +++ b/build.php @@ -0,0 +1,4 @@ +js/platform.js"> - ' . $hesklang['manage_statuses'] . ''; } + if (hesk_checkPermission('can_view_logs', 0)) { + $tools_count++; + $dropdown_items .= '
  • ' . $hesklang['view_message_log'] . '
  • '; + } $dropdown_items .= ''; if ($tools_count > 1) { @@ -224,6 +228,12 @@ if (hesk_check_kb_only(false)) { $active = ' class="active"'; } echo ' ' . $hesklang['tools'] . ''; + } elseif (hesk_checkPermission('can_view_logs', 0)) { + $active = ''; + if (defined('PAGE_TITLE') && PAGE_TITLE == 'ADMIN_TOOLS') { + $active = ' class="active"'; + } + echo ' ' . $hesklang['tools'] . ''; } } if (hesk_checkPermission('can_man_settings', 0)) { diff --git a/language/en/text.php b/language/en/text.php index b9c5947f..4b041e7e 100644 --- a/language/en/text.php +++ b/language/en/text.php @@ -30,6 +30,8 @@ $hesklang['severity'] = 'Severity'; $hesklang['debug'] = 'Debug'; $hesklang['warning_title_case'] = 'Warning'; $hesklang['logs'] = 'Logs'; +$hesklang['view_message_log'] = 'View Message Log'; +$hesklang['can_view_logs'] = 'Can view message logs'; // ADDED OR MODIFIED IN Mods for HESK 2.5.2 $hesklang['manage_statuses'] = 'Manage Statuses';
    DateUserLocationMessage