jilo-web/app/helpers/pagination.php

97 lines
3.7 KiB
PHP
Raw Normal View History

2024-09-15 18:42:47 +00:00
<?php
2025-11-23 20:47:20 +00:00
/**
* Pagination helper
* @param string $url Base URL for pagination links
* @param int $browse_page Current page number
* @param int $page_count Total number of pages
*/
function renderPagination($url, $browse_page = 1, $page_count = 1) {
2024-09-15 18:42:47 +00:00
$param = '';
2025-11-23 20:47:20 +00:00
// calls
if (isset($_REQUEST['name'])) {
$param .= '&name=' . htmlspecialchars($_REQUEST['name']);
}
if (isset($_REQUEST['invitees'])) {
$param .= '&invitees=' . htmlspecialchars($_REQUEST['invitees']);
}
if (isset($_REQUEST['description'])) {
$param .= '&description=' . htmlspecialchars($_REQUEST['description']);
}
if (isset($_REQUEST['filter'])) {
$param .= '&filter=' . htmlspecialchars($_REQUEST['filter']);
2024-09-15 18:42:47 +00:00
}
2025-11-23 20:47:20 +00:00
// contacts
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
}
2025-11-23 20:47:20 +00:00
if (isset($_REQUEST['phone'])) {
$param .= '&phone=' . htmlspecialchars($_REQUEST['phone']);
2024-10-03 14:31:39 +00:00
}
2025-11-23 20:47:20 +00:00
if (isset($_REQUEST['email'])) {
$param .= '&email=' . htmlspecialchars($_REQUEST['email']);
2024-09-15 18:42:47 +00:00
}
2025-11-23 20:47:20 +00:00
// messages
if (isset($_REQUEST['from'])) {
$param .= '&from=' . htmlspecialchars($_REQUEST['from']);
}
if (isset($_REQUEST['to'])) {
$param .= '&to=' . htmlspecialchars($_REQUEST['to']);
}
if (isset($_REQUEST['subject'])) {
$param .= '&subject=' . htmlspecialchars($_REQUEST['subject']);
}
// notifications
if (isset($_REQUEST['message'])) {
$param .= '&message=' . htmlspecialchars($_REQUEST['message']);
}
// time period
2024-10-03 16:33:31 +00:00
if (isset($_REQUEST['from_time'])) {
2025-11-23 20:47:20 +00:00
$param .= '&from_time=' . htmlspecialchars($_REQUEST['from_time']);
2024-10-03 16:33:31 +00:00
}
if (isset($_REQUEST['until_time'])) {
2025-11-23 20:47:20 +00:00
$param .= '&until_time=' . htmlspecialchars($_REQUEST['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;
2025-11-23 20:47:20 +00:00
echo '<div class="tm-pagination text-center"><div class="pagination">';
2024-09-15 18:42:47 +00:00
if ($browse_page > 1) {
2025-11-23 20:47:20 +00:00
echo '<a class="pagination-link" href="' . htmlspecialchars($url) . '&p=1' . $param . '">first</a>';
echo '<a class="pagination-link" href="' . htmlspecialchars($url) . '&p=' . ($browse_page - 1) . $param . '">&laquo;</a>';
2024-09-15 18:42:47 +00:00
} else {
2025-11-23 20:47:20 +00:00
echo '<span class="pagination-link disabled">first</span>';
echo '<span class="pagination-link disabled">&laquo;</span>';
2024-09-15 18:42:47 +00:00
}
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.),
2025-11-23 20:47:20 +00:00
// and pages around current page
if ($i == 1 || $i == $page_count ||
$i % $step_pages == 0 ||
abs($i - $browse_page) < $max_visible_pages / 2) {
2024-09-15 18:42:47 +00:00
2025-11-23 20:47:20 +00:00
if ($i == $browse_page) {
echo '<span class="pagination-link active">' . $i . '</span>';
2024-09-15 18:42:47 +00:00
} else {
2025-11-23 20:47:20 +00:00
echo '<a class="pagination-link" href="' . htmlspecialchars($url) . '&p=' . $i . $param . '">' . $i . '</a>';
2024-09-15 18:42:47 +00:00
}
2025-11-23 20:47:20 +00:00
} elseif ($i == 2 || $i == $page_count - 1 ||
($i > $browse_page + $max_visible_pages / 2 && $i % $step_pages == 1) ||
($i < $browse_page - $max_visible_pages / 2 && $i % $step_pages == $step_pages - 1)) {
echo '<span class="pagination-link pagination-ellipsis disabled">...</span>';
2024-09-15 18:42:47 +00:00
}
}
if ($browse_page < $page_count) {
2025-11-23 20:47:20 +00:00
echo '<a class="pagination-link" href="' . htmlspecialchars($url) . '&p=' . ($browse_page + 1) . $param . '">&raquo;</a>';
echo '<a class="pagination-link" href="' . htmlspecialchars($url) . '&p=' . $page_count . $param . '">last</a>';
2024-09-15 18:42:47 +00:00
} else {
2025-11-23 20:47:20 +00:00
echo '<span class="pagination-link disabled">&raquo;</span>';
echo '<span class="pagination-link disabled">last</span>';
2024-09-15 18:42:47 +00:00
}
2025-11-23 20:47:20 +00:00
echo '</div></div>';
}