From e85292b58fc0c0267e43a2d947318e1d85ac67a8 Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Sat, 18 Jan 2025 17:24:30 +0200 Subject: [PATCH] Adds proper pagination. Paginates logs page. --- app/pages/logs.php | 32 +++++++++++--- app/templates/logs-list.php | 9 ++-- app/templates/pagination.php | 85 ++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 10 deletions(-) create mode 100644 app/templates/pagination.php diff --git a/app/pages/logs.php b/app/pages/logs.php index e00f4c0..3f95176 100644 --- a/app/pages/logs.php +++ b/app/pages/logs.php @@ -15,6 +15,10 @@ include '../app/includes/messages-show.php'; $has_system_access = ($userObject->hasRight($user_id, 'superuser') || $userObject->hasRight($user_id, 'view app logs')); +// Get current page for pagination +$currentPage = $_REQUEST['page_num'] ?? 1; +$currentPage = (int)$currentPage; + // Get selected tab $selected_tab = $_REQUEST['tab'] ?? 'user'; if ($selected_tab === 'system' && !$has_system_access) { @@ -44,18 +48,34 @@ if ($scope === 'system' && isset($_REQUEST['id']) && !empty($_REQUEST['id'])) { // pagination variables $items_per_page = 15; -$browse_page = $_REQUEST['p'] ?? 1; -$browse_page = (int)$browse_page; -$offset = ($browse_page -1) * $items_per_page; +$offset = ($currentPage - 1) * $items_per_page; + +// Get filter from request or default to empty +$filter = $_REQUEST['filter'] ?? ''; + +// Build params for pagination +$params = ''; +if (!empty($filter)) { + $params .= '&filter=' . urlencode($filter); +} +if (isset($_REQUEST['from'])) { + $params .= '&from=' . urlencode($_REQUEST['from']); +} +if (isset($_REQUEST['until'])) { + $params .= '&until=' . urlencode($_REQUEST['until']); +} +if (isset($_REQUEST['tab'])) { + $params .= '&tab=' . urlencode($_REQUEST['tab']); +} // prepare the result -$search = $logObject->readLog($user_id, $scope, $offset, $items_per_page, $filters); -$search_all = $logObject->readLog($user_id, $scope, 0, '', $filters); +$search = $logObject->readLog($user_id, $scope, $offset, $items_per_page, $filter); +$search_all = $logObject->readLog($user_id, $scope, '', '', $filter); if (!empty($search)) { // we get total items and number of pages $item_count = count($search_all); - $page_count = ceil($item_count / $items_per_page); + $totalPages = ceil($item_count / $items_per_page); $logs = array(); $logs['records'] = array(); diff --git a/app/templates/logs-list.php b/app/templates/logs-list.php index 53f1443..6ffa5fc 100644 --- a/app/templates/logs-list.php +++ b/app/templates/logs-list.php @@ -56,10 +56,11 @@ $items_per_page) { - include '../app/helpers/pagination.php'; - } - } else { ?> +if ($widget['pagination'] === true) { + include '../app/templates/pagination.php'; +} +?> +
No log entries found for the specified criteria.
diff --git a/app/templates/pagination.php b/app/templates/pagination.php new file mode 100644 index 0000000..cd5a419 --- /dev/null +++ b/app/templates/pagination.php @@ -0,0 +1,85 @@ + + + 1): ?> + +