jilo-web/app/helpers/pagination.php

82 lines
3.3 KiB
PHP
Raw Permalink Normal View History

2024-09-15 18:42:47 +00:00
<div class="text-center">
<div class="pagination">
<?php
$param = '';
2024-10-03 14:31:39 +00:00
if (isset($_REQUEST['id'])) {
2024-10-04 15:13:55 +00:00
$param .= '&id=' . htmlspecialchars($_REQUEST['id']);
2024-09-15 18:42:47 +00:00
}
2024-10-03 14:31:39 +00:00
if (isset($_REQUEST['name'])) {
2024-10-04 15:13:55 +00:00
$param .= '&name=' . htmlspecialchars($_REQUEST['name']);
2024-09-15 18:42:47 +00:00
}
2024-10-03 14:31:39 +00:00
if (isset($_REQUEST['ip'])) {
2024-10-04 15:13:55 +00:00
$param .= '&ip=' . htmlspecialchars($_REQUEST['ip']);
2024-10-03 14:31:39 +00:00
}
if (isset($_REQUEST['event'])) {
2024-10-04 15:13:55 +00:00
$param .= '&event=' . htmlspecialchars($_REQUEST['event']);
2024-09-15 18:42:47 +00:00
}
2024-10-03 16:33:31 +00:00
if (isset($_REQUEST['from_time'])) {
2024-10-04 15:13:55 +00:00
$param .= '&from_time=' . htmlspecialchars($from_time);
2024-10-03 16:33:31 +00:00
}
if (isset($_REQUEST['until_time'])) {
2024-10-04 15:13:55 +00:00
$param .= '&until_time=' . htmlspecialchars($until_time);
2024-10-03 16:33:31 +00:00
}
2024-10-03 15:47:23 +00:00
$max_visible_pages = 10;
$step_pages = 10;
2024-09-15 18:42:47 +00:00
if ($browse_page > 1) {
2024-10-04 11:18:28 +00:00
echo '<span><a href="' . htmlspecialchars($url) . '&p=1">first</a></span>';
2024-09-15 18:42:47 +00:00
} else {
echo '<span>first</span>';
}
for ($i = 1; $i <= $page_count; $i++) {
2024-10-03 15:47:23 +00:00
// always show the first, last, step pages (10, 20, 30, etc.),
// and the pages close to the current one
if (
$i === 1 || // first page
$i === $page_count || // last page
$i === $browse_page || // current page
$i === $browse_page -1 ||
$i === $browse_page +1 ||
$i === $browse_page -2 ||
$i === $browse_page +2 ||
($i % $step_pages === 0 && $i > $max_visible_pages) // the step pages - 10, 20, etc.
) {
if ($i === $browse_page) {
// current page, no link
if ($browse_page > 1) {
2024-10-04 15:13:55 +00:00
echo '<span><a href="' . htmlspecialchars($app_root) . '?platform=' . htmlspecialchars($platform_id) . '&page=' . htmlspecialchars($page) . $param . '&p=' . (htmlspecialchars($browse_page) -1) . '"><<</a></span>';
2024-10-03 15:47:23 +00:00
} else {
echo '<span><<</span>';
}
2024-10-04 11:18:28 +00:00
echo '[' . htmlspecialchars($i) . ']';
2024-09-15 18:42:47 +00:00
2024-10-03 15:47:23 +00:00
if ($browse_page < $page_count) {
2024-10-04 15:13:55 +00:00
echo '<span><a href="' . htmlspecialchars($app_root) . '?platform=' . htmlspecialchars($platform_id) . '&page=' . htmlspecialchars($page) . $param . '&p=' . (htmlspecialchars($browse_page) +1) . '">>></a></span>';
2024-10-03 15:47:23 +00:00
} else {
echo '<span>>></span>';
}
2024-09-15 18:42:47 +00:00
} else {
2024-10-03 15:47:23 +00:00
// other pages
2024-10-04 15:13:55 +00:00
echo '<span><a href="' . htmlspecialchars($app_root) . '?platform=' . htmlspecialchars($platform_id) . '&page=' . htmlspecialchars($page) . $param . '&p=' . htmlspecialchars($i) . '">[' . htmlspecialchars($i) . ']</a></span>';
2024-09-15 18:42:47 +00:00
}
2024-10-03 15:47:23 +00:00
// show ellipses between distant pages
} elseif (
$i === $browse_page -3 ||
$i === $browse_page +3
) {
echo '<span>...</span>';
2024-09-15 18:42:47 +00:00
}
}
if ($browse_page < $page_count) {
2024-10-04 15:13:55 +00:00
echo '<span><a href="' . htmlspecialchars($app_root) . '?platform=' . htmlspecialchars($platform_id) . '&page=' . htmlspecialchars($page) . $param . '&p=' . (htmlspecialchars($page_count)) . '">last</a></span>';
2024-09-15 18:42:47 +00:00
} else {
echo '<span>last</span>';
}
?>
</div>
</div>