Adds proper pagination. Paginates logs page.
parent
9fd2af6538
commit
e85292b58f
|
@ -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();
|
||||
|
|
|
@ -56,10 +56,11 @@
|
|||
</table>
|
||||
</div>
|
||||
<?php
|
||||
if ($widget['pagination'] && $item_count > $items_per_page) {
|
||||
include '../app/helpers/pagination.php';
|
||||
if ($widget['pagination'] === true) {
|
||||
include '../app/templates/pagination.php';
|
||||
}
|
||||
} else { ?>
|
||||
?>
|
||||
<?php } else { ?>
|
||||
<div class="alert alert-info m-3">
|
||||
<i class="fas fa-info-circle me-2"></i>No log entries found for the specified criteria.
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
/**
|
||||
* Reusable pagination view/template component
|
||||
* Required variables:
|
||||
* $currentPage - Current page number
|
||||
* $totalPages - Total number of pages
|
||||
*/
|
||||
|
||||
// Ensure required variables are set
|
||||
if (!isset($currentPage) || !isset($totalPages)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Number of page links to show before and after current page
|
||||
$range = 2;
|
||||
?>
|
||||
|
||||
<?php if ($totalPages > 1): ?>
|
||||
<nav aria-label="Page navigation" class="mt-4">
|
||||
<ul class="pagination justify-content-center d-flex flex-row gap-1">
|
||||
|
||||
<!-- First page -->
|
||||
<?php if ($currentPage > 1): ?>
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="<?= htmlspecialchars($app_root . '?page=' . $page . $params) ?>">First</a>
|
||||
</li>
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="<?= htmlspecialchars($app_root . '?page=' . $page . ($currentPage > 1 ? '&page_num=' . ($currentPage - 1) : '') . $params) ?>">«</a>
|
||||
</li>
|
||||
<?php else: ?>
|
||||
<li class="page-item disabled">
|
||||
<span class="page-link">First</span>
|
||||
</li>
|
||||
<li class="page-item disabled">
|
||||
<span class="page-link">«</span>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Page numbers -->
|
||||
<?php
|
||||
for ($i = 1; $i <= $totalPages; $i++) {
|
||||
// Show first, last, current page, 2 pages before and after current, and step pages (10, 20, etc.)
|
||||
if ($i === 1 ||
|
||||
$i === $totalPages ||
|
||||
$i === $currentPage ||
|
||||
$i === $currentPage - 1 ||
|
||||
$i === $currentPage + 1 ||
|
||||
$i === $currentPage - 2 ||
|
||||
$i === $currentPage + 2 ||
|
||||
($i % 10 === 0 && $i > 10)
|
||||
) { ?>
|
||||
<li class="page-item <?= $i === (int)$currentPage ? 'active' : '' ?>">
|
||||
<a class="page-link" href="<?= htmlspecialchars($app_root . '?page=' . $page . ($i > 1 ? '&page_num=' . $i : '') . $params) ?>">
|
||||
<?= $i ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
} elseif ($i === $currentPage - 3 || $i === $currentPage + 3) {
|
||||
?>
|
||||
<li class="page-item disabled">
|
||||
<span class="page-link">...</span>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
} ?>
|
||||
|
||||
<!-- Last page -->
|
||||
<?php if ($currentPage < $totalPages): ?>
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="<?= htmlspecialchars($app_root . '?page=' . $page . '&page_num=' . ($currentPage + 1) . $params) ?>">»</a>
|
||||
</li>
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="<?= htmlspecialchars($app_root . '?page=' . $page . '&page_num=' . $totalPages . $params) ?>">Last</a>
|
||||
</li>
|
||||
<?php else: ?>
|
||||
<li class="page-item disabled">
|
||||
<span class="page-link">»</span>
|
||||
</li>
|
||||
<li class="page-item disabled">
|
||||
<span class="page-link">Last</span>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</nav>
|
||||
<?php endif; ?>
|
Loading…
Reference in New Issue