commit
8ec86ffb9c
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
define('IN_SCRIPT', 1);
|
||||
define('HESK_PATH', '../');
|
||||
define('PAGE_TITLE', 'ADMIN_TOOLS');
|
||||
|
||||
/* Get all the required files and functions */
|
||||
require(HESK_PATH . 'hesk_settings.inc.php');
|
||||
require(HESK_PATH . 'inc/common.inc.php');
|
||||
require(HESK_PATH . 'inc/admin_functions.inc.php');
|
||||
hesk_load_database_functions();
|
||||
|
||||
hesk_session_start();
|
||||
hesk_dbConnect();
|
||||
hesk_isLoggedIn();
|
||||
|
||||
hesk_checkPermission('can_view_logs');
|
||||
|
||||
define('EXTRA_JS', '<script src="'.HESK_PATH.'internal-api/js/view-message-log.js"></script>');
|
||||
|
||||
/* Print header */
|
||||
require_once(HESK_PATH . 'inc/headerAdmin.inc.php');
|
||||
|
||||
/* Print main manage users page */
|
||||
require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
|
||||
?>
|
||||
|
||||
<div class="row pad-20">
|
||||
<div class="col-sm-4">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<?php echo $hesklang['search_logs']; ?>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="form-horizontal">
|
||||
<div class="form-group">
|
||||
<label for="location" class="control-label col-sm-4">
|
||||
<?php echo $hesklang['custom_place']; ?>
|
||||
</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" name="location" class="form-control" placeholder="<?php echo hesk_htmlspecialchars($hesklang['custom_place']); ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="date" class="control-label col-sm-4">
|
||||
<?php echo $hesklang['date_logged']; ?>
|
||||
</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" name="from-date" class="datepicker form-control white-readonly no-bottom-round-corners no-bottom-border" placeholder="<?php echo hesk_htmlspecialchars($hesklang['from_date']); ?>" readonly>
|
||||
<input type="text" name="to-date" class="datepicker form-control white-readonly no-top-round-corners" placeholder="<?php echo hesk_htmlspecialchars($hesklang['to_date']); ?>" readonly>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="severity" class="control-label col-sm-4"><?php echo $hesklang['severity']; ?></label>
|
||||
<div class="col-sm-8">
|
||||
<select name="severity" class="form-control">
|
||||
<option value="-1" selected><?php echo $hesklang['all']; ?></option>
|
||||
<option value="0"><?php echo $hesklang['debug']; ?></option>
|
||||
<option value="1"><?php echo $hesklang['info']; ?></option>
|
||||
<option value="2"><?php echo $hesklang['warning_title_case']; ?></option>
|
||||
<option value="3"><?php echo $hesklang['sm_error']; ?></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-8 col-sm-offset-4">
|
||||
<button class="btn btn-default" id="search-button"><?php echo $hesklang['search']; ?></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-8">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<?php echo $hesklang['logs']; ?>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<table class="table table-striped" id="results-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php echo $hesklang['date']; ?></th>
|
||||
<th><?php echo $hesklang['user']; ?></th>
|
||||
<th><?php echo $hesklang['custom_place']; ?></th>
|
||||
<th><?php echo $hesklang['message']; ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
require_once(HESK_PATH . 'inc/footer.inc.php');
|
||||
exit();
|
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
// Define the current build
|
||||
define('MODS_FOR_HESK_BUILD', 23);
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
define('IN_SCRIPT', 1);
|
||||
define('HESK_PATH', '../../../');
|
||||
define('INTERNAL_API_PATH', '../../');
|
||||
require_once(HESK_PATH . 'hesk_settings.inc.php');
|
||||
require_once(HESK_PATH . 'inc/common.inc.php');
|
||||
require_once(INTERNAL_API_PATH . 'core/output.php');
|
||||
require_once(INTERNAL_API_PATH . 'dao/message_log_dao.php');
|
||||
|
||||
hesk_load_internal_api_database_functions();
|
||||
hesk_dbConnect();
|
||||
|
||||
// Routing
|
||||
$request_method = $_SERVER['REQUEST_METHOD'];
|
||||
if ($request_method == 'POST') {
|
||||
$location = $_POST['location'];
|
||||
$from_date = $_POST['fromDate'];
|
||||
$to_date = $_POST['toDate'];
|
||||
$severity_id = $_POST['severityId'];
|
||||
|
||||
$results = search_log($hesk_settings, $location, $from_date, $to_date, $severity_id);
|
||||
print json_encode($results);
|
||||
return http_response_code(200);
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
function search_log($hesk_settings, $location, $from_date, $to_date, $severity_id) {
|
||||
if (!function_exists('hesk_date')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "logging` WHERE 1=1 ";
|
||||
|
||||
if ($location != NULL) {
|
||||
$sql .= "AND `location` LIKE '%" . hesk_dbEscape(hesk_dbLike($location)) . "%' ";
|
||||
}
|
||||
$from_date_format = preg_match("/\d{4}-\d{2}-\d{2}/", $from_date);
|
||||
if ($from_date != NULL
|
||||
&& $from_date_format === 1) {
|
||||
$sql .= "AND `timestamp` >= '" . 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)) {
|
||||
$row['timestamp'] = hesk_date($row['timestamp'], true);
|
||||
$results[] = $row;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
$(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());
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
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: location,
|
||||
fromDate: fromDate,
|
||||
toDate: toDate,
|
||||
severityId: severity
|
||||
},
|
||||
method: 'POST',
|
||||
success: displayResults,
|
||||
error: function(data) {
|
||||
console.error(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function displayResults(data) {
|
||||
data = $.parseJSON(data);
|
||||
var table = $('#results-table > tbody');
|
||||
table.empty();
|
||||
|
||||
if (data.length === 0) {
|
||||
table.append('<tr><td colspan="4">No results found</td></tr>');
|
||||
} else {
|
||||
for (var index in data) {
|
||||
var result = data[index];
|
||||
table.append('<tr ' + getRowColor(result) + '>' +
|
||||
'<td>' + result.timestamp + '</td>' +
|
||||
'<td>' + result.username + '</td>' +
|
||||
'<td>' + result.location + '</td>' +
|
||||
'<td>' + result.message + '</td>');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getRowColor(result) {
|
||||
switch (result.severity) {
|
||||
case "1":
|
||||
return 'class="info"';
|
||||
case "2":
|
||||
return 'class="warning"';
|
||||
case "3":
|
||||
return 'class="danger"';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
Loading…
Reference in New Issue