adding paginations

This commit is contained in:
Flatlogic Bot 2026-03-20 05:45:17 +00:00
parent 6b6d23d100
commit 6f7b57b235
3 changed files with 59 additions and 2 deletions

View File

@ -3289,7 +3289,13 @@ switch ($page) {
header("Location: index.php?page=outlets"); header("Location: index.php?page=outlets");
exit; exit;
} }
$data['outlets'] = db()->query("SELECT * FROM outlets ORDER BY id ASC")->fetchAll(); $countStmt = db()->query("SELECT COUNT(*) FROM outlets");
$total_records = (int)$countStmt->fetchColumn();
$data['total_pages'] = ceil($total_records / $limit);
$data['current_page'] = $page_num;
$stmt = db()->prepare("SELECT * FROM outlets ORDER BY id ASC LIMIT $limit OFFSET $offset");
$stmt->execute();
$data['outlets'] = $stmt->fetchAll();
break; break;
case 'copy_outlet_data': require 'pages/copy_outlet_data_logic.php'; break; case 'copy_outlet_data': require 'pages/copy_outlet_data_logic.php'; break;
case 'settings': case 'settings':
@ -6604,6 +6610,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
</tbody> </tbody>
</table> </table>
</div> </div>
<?= renderPagination($data['current_page'] ?? 1, $data['total_pages'] ?? 1) ?>
</div> </div>
@ -6728,6 +6735,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
</tbody> </tbody>
</table> </table>
</div> </div>
<?= renderPagination($data['current_page'] ?? 1, $data['total_pages'] ?? 1) ?>
</div> </div>

View File

@ -10,6 +10,44 @@ ini_set('display_errors', 1);
require_once __DIR__ . '/config.php'; require_once __DIR__ . '/config.php';
function renderPagination($currentPage, $totalPages) {
if ($totalPages <= 1) return '';
$url = 'manage.php?page=';
$html = '<nav aria-label="Page navigation" class="mt-4"><ul class="pagination justify-content-center">';
// Previous
$disabled = ($currentPage <= 1) ? 'disabled' : '';
$html .= '<li class="page-item ' . $disabled . '"><a class="page-link" href="' . $url . ($currentPage - 1) . '"><i class="bi bi-chevron-left"></i></a></li>';
// Pages
$start = max(1, $currentPage - 2);
$end = min($totalPages, $currentPage + 2);
if ($start > 1) {
$html .= '<li class="page-item"><a class="page-link" href="' . $url . '1">1</a></li>';
if ($start > 2) $html .= '<li class="page-item disabled"><span class="page-link">...</span></li>';
}
for ($i = $start; $i <= $end; $i++) {
$active = ($i == $currentPage) ? 'active' : '';
$html .= '<li class="page-item ' . $active . '"><a class="page-link" href="' . $url . $i . '">' . $i . '</a></li>';
}
if ($end < $totalPages) {
if ($end < $totalPages - 1) $html .= '<li class="page-item disabled"><span class="page-link">...</span></li>';
$html .= '<li class="page-item"><a class="page-link" href="' . $url . $totalPages . '">' . $totalPages . '</a></li>';
}
// Next
$disabled = ($currentPage >= $totalPages) ? 'disabled' : '';
$html .= '<li class="page-item ' . $disabled . '"><a class="page-link" href="' . $url . ($currentPage + 1) . '"><i class="bi bi-chevron-right"></i></a></li>';
$html .= '</ul></nav>';
return $html;
}
// SIMPLE PASSWORD PROTECTION // SIMPLE PASSWORD PROTECTION
$admin_password = "Meezan@2026"; $admin_password = "Meezan@2026";
@ -148,7 +186,16 @@ if (isset($_SESSION['flash_message'])) {
// Fetch Licenses // Fetch Licenses
try { try {
$licenses = $pdo->query("SELECT * FROM licenses ORDER BY created_at DESC")->fetchAll(); // Pagination
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
if ($page < 1) $page = 1;
$limit = 20;
$offset = ($page - 1) * $limit;
$total = $pdo->query("SELECT COUNT(*) FROM licenses")->fetchColumn();
$totalPages = ceil($total / $limit);
$licenses = $pdo->query("SELECT * FROM licenses ORDER BY created_at DESC LIMIT $limit OFFSET $offset")->fetchAll();
} catch (Exception $e) { } catch (Exception $e) {
$licenses = []; $licenses = [];
$error = "Failed to fetch licenses: " . $e->getMessage(); $error = "Failed to fetch licenses: " . $e->getMessage();
@ -321,6 +368,7 @@ try {
</tbody> </tbody>
</table> </table>
</div> </div>
<?= renderPagination($page ?? 1, $totalPages ?? 1) ?>
</div> </div>
</div> </div>

View File

@ -46,6 +46,7 @@
</tbody> </tbody>
</table> </table>
</div> </div>
<?= renderPagination($data['current_page'] ?? 1, $data['total_pages'] ?? 1) ?>
</div> </div>
</div> </div>