2024-09-16 14:09:37 +00:00
|
|
|
<?php
|
|
|
|
|
2024-11-27 14:26:55 +00:00
|
|
|
/**
|
2024-11-29 16:08:56 +00:00
|
|
|
* Logs listings
|
2024-11-27 14:26:55 +00:00
|
|
|
*
|
|
|
|
* This page ("logs") retrieves and displays logs for a specified user within a time range.
|
|
|
|
* It supports pagination and filtering, and generates a widget to display the logs.
|
|
|
|
*/
|
2024-09-16 14:09:37 +00:00
|
|
|
|
2025-01-13 08:45:31 +00:00
|
|
|
// Get any new messages
|
|
|
|
include '../app/includes/messages.php';
|
|
|
|
include '../app/includes/messages-show.php';
|
|
|
|
|
2025-01-07 19:31:07 +00:00
|
|
|
// Check for rights; user or system
|
2025-01-18 11:17:32 +00:00
|
|
|
$has_system_access = ($userObject->hasRight($user_id, 'superuser') ||
|
|
|
|
$userObject->hasRight($user_id, 'view app logs'));
|
|
|
|
|
2025-01-18 15:24:30 +00:00
|
|
|
// Get current page for pagination
|
|
|
|
$currentPage = $_REQUEST['page_num'] ?? 1;
|
|
|
|
$currentPage = (int)$currentPage;
|
|
|
|
|
2025-01-18 11:17:32 +00:00
|
|
|
// Get selected tab
|
|
|
|
$selected_tab = $_REQUEST['tab'] ?? 'user';
|
|
|
|
if ($selected_tab === 'system' && !$has_system_access) {
|
|
|
|
$selected_tab = 'user';
|
2025-01-07 19:31:07 +00:00
|
|
|
}
|
|
|
|
|
2025-01-18 11:17:32 +00:00
|
|
|
// Set scope based on selected tab
|
|
|
|
$scope = ($selected_tab === 'system') ? 'system' : 'user';
|
|
|
|
|
2024-09-16 14:09:37 +00:00
|
|
|
// specify time range
|
|
|
|
include '../app/helpers/time_range.php';
|
|
|
|
|
2025-01-18 11:17:32 +00:00
|
|
|
// Prepare search filters
|
|
|
|
$filters = [];
|
|
|
|
if (isset($_REQUEST['from_time']) && !empty($_REQUEST['from_time'])) {
|
|
|
|
$filters['from_time'] = $_REQUEST['from_time'];
|
|
|
|
}
|
|
|
|
if (isset($_REQUEST['until_time']) && !empty($_REQUEST['until_time'])) {
|
|
|
|
$filters['until_time'] = $_REQUEST['until_time'];
|
|
|
|
}
|
|
|
|
if (isset($_REQUEST['message']) && !empty($_REQUEST['message'])) {
|
|
|
|
$filters['message'] = $_REQUEST['message'];
|
|
|
|
}
|
|
|
|
if ($scope === 'system' && isset($_REQUEST['id']) && !empty($_REQUEST['id'])) {
|
|
|
|
$filters['id'] = $_REQUEST['id'];
|
|
|
|
}
|
|
|
|
|
2024-09-16 16:08:03 +00:00
|
|
|
// pagination variables
|
|
|
|
$items_per_page = 15;
|
2025-01-18 15:24:30 +00:00
|
|
|
$offset = ($currentPage - 1) * $items_per_page;
|
|
|
|
|
|
|
|
// Build params for pagination
|
|
|
|
$params = '';
|
2025-01-18 15:41:03 +00:00
|
|
|
if (!empty($_REQUEST['from_time'])) {
|
|
|
|
$params .= '&from_time=' . urlencode($_REQUEST['from_time']);
|
|
|
|
}
|
|
|
|
if (!empty($_REQUEST['until_time'])) {
|
|
|
|
$params .= '&until_time=' . urlencode($_REQUEST['until_time']);
|
2025-01-18 15:24:30 +00:00
|
|
|
}
|
2025-01-18 15:41:03 +00:00
|
|
|
if (!empty($_REQUEST['message'])) {
|
|
|
|
$params .= '&message=' . urlencode($_REQUEST['message']);
|
2025-01-18 15:24:30 +00:00
|
|
|
}
|
2025-01-18 15:41:03 +00:00
|
|
|
if (!empty($_REQUEST['id'])) {
|
|
|
|
$params .= '&id=' . urlencode($_REQUEST['id']);
|
2025-01-18 15:24:30 +00:00
|
|
|
}
|
|
|
|
if (isset($_REQUEST['tab'])) {
|
|
|
|
$params .= '&tab=' . urlencode($_REQUEST['tab']);
|
|
|
|
}
|
2024-09-16 16:08:03 +00:00
|
|
|
|
2024-09-16 14:09:37 +00:00
|
|
|
// prepare the result
|
2025-01-18 15:41:03 +00:00
|
|
|
$search = $logObject->readLog($user_id, $scope, $offset, $items_per_page, $filters);
|
|
|
|
$search_all = $logObject->readLog($user_id, $scope, '', '', $filters);
|
2024-09-16 14:09:37 +00:00
|
|
|
|
|
|
|
if (!empty($search)) {
|
2024-09-16 16:08:03 +00:00
|
|
|
// we get total items and number of pages
|
|
|
|
$item_count = count($search_all);
|
2025-01-18 15:24:30 +00:00
|
|
|
$totalPages = ceil($item_count / $items_per_page);
|
2024-09-16 16:08:03 +00:00
|
|
|
|
2024-09-16 14:09:37 +00:00
|
|
|
$logs = array();
|
|
|
|
$logs['records'] = array();
|
|
|
|
|
|
|
|
foreach ($search as $item) {
|
2024-09-16 16:08:03 +00:00
|
|
|
// when we show only user's logs, omit user_id column
|
|
|
|
if ($scope === 'user') {
|
|
|
|
$log_record = array(
|
|
|
|
// assign title to the field in the array record
|
2025-01-18 11:17:32 +00:00
|
|
|
'time' => $item['time'],
|
|
|
|
'log message' => $item['message']
|
2024-09-16 16:08:03 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$log_record = array(
|
|
|
|
// assign title to the field in the array record
|
2025-01-18 11:17:32 +00:00
|
|
|
'userID' => $item['user_id'],
|
|
|
|
'username' => $item['username'],
|
|
|
|
'time' => $item['time'],
|
|
|
|
'log message' => $item['message']
|
2024-09-16 16:08:03 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-09-16 14:09:37 +00:00
|
|
|
// populate the result array
|
|
|
|
array_push($logs['records'], $log_record);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// prepare the widget
|
|
|
|
$widget['full'] = false;
|
|
|
|
$widget['name'] = 'Logs';
|
|
|
|
$username = $userObject->getUserDetails($user_id)[0]['username'];
|
2025-01-18 11:17:32 +00:00
|
|
|
$widget['title'] = "Log events";
|
2024-09-16 14:09:37 +00:00
|
|
|
$widget['filter'] = true;
|
2025-01-18 11:17:32 +00:00
|
|
|
$widget['scope'] = $scope;
|
|
|
|
$widget['has_system_access'] = $has_system_access;
|
2025-01-18 15:41:03 +00:00
|
|
|
|
2024-09-16 16:08:03 +00:00
|
|
|
if (!empty($logs['records'])) {
|
2024-09-16 14:09:37 +00:00
|
|
|
$widget['full'] = true;
|
|
|
|
$widget['table_records'] = $logs['records'];
|
|
|
|
}
|
|
|
|
$widget['pagination'] = true;
|
|
|
|
|
|
|
|
// display the widget
|
|
|
|
include '../app/templates/logs-list.php';
|
|
|
|
|
|
|
|
?>
|