2024-09-16 14:09:37 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
//
|
|
|
|
// logs listings
|
|
|
|
//
|
|
|
|
|
|
|
|
// specify time range
|
|
|
|
include '../app/helpers/time_range.php';
|
|
|
|
|
2024-09-16 16:08:03 +00:00
|
|
|
// pagination variables
|
|
|
|
$items_per_page = 15;
|
|
|
|
$browse_page = $_REQUEST['p'] ?? 1;
|
|
|
|
$browse_page = (int)$browse_page;
|
|
|
|
$offset = ($browse_page -1) * $items_per_page;
|
|
|
|
|
|
|
|
// user or system
|
|
|
|
$scope = 'user';
|
|
|
|
|
2024-09-16 14:09:37 +00:00
|
|
|
// prepare the result
|
2024-09-16 16:08:03 +00:00
|
|
|
$search = $logObject->readLog($user_id, $scope, $offset, $items_per_page);
|
|
|
|
$search_all = $logObject->readLog($user_id, $scope);
|
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);
|
|
|
|
$page_count = ceil($item_count / $items_per_page);
|
|
|
|
|
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
|
|
|
|
'time' => $item['time'],
|
|
|
|
'log message' => $item['message']
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$log_record = array(
|
|
|
|
// assign title to the field in the array record
|
|
|
|
'userID' => $item['user_id'],
|
|
|
|
'time' => $item['time'],
|
|
|
|
'log message' => $item['message']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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['collapsible'] = false;
|
|
|
|
$widget['name'] = 'Logs';
|
|
|
|
$username = $userObject->getUserDetails($user_id)[0]['username'];
|
|
|
|
$widget['title'] = "Log events for user \"$username\"";
|
|
|
|
$widget['filter'] = true;
|
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_headers'] = array_keys($logs['records'][0]);
|
|
|
|
$widget['table_records'] = $logs['records'];
|
|
|
|
}
|
|
|
|
$widget['pagination'] = true;
|
|
|
|
|
|
|
|
// display the widget
|
|
|
|
include '../app/templates/logs-list.php';
|
|
|
|
|
|
|
|
?>
|