EternalWinter/pagination.php

70 lines
1.3 KiB
PHP
Executable file

<?php
require 'common.php';
if (isset($_GET["page"])) {
$page = intval($_GET["page"]);
} else {
$page = 1;
}
if (isset($_GET["cat"])) {
$cat = $_GET["cat"];
} else {
$cat = null;
}
function getEntries() {
global $cat;
global $page;
renderPage($page, $cat);
}
function params($pageARG=null) {
global $cat;
global $page;
$params = "?page=" . $pageARG;
if ($cat) {
$params = $params . "&cat=" . $cat;
}
return $params;
}
function backButton($params) {
echo("<th><a href='" . $params . "'><button>Back</button></a></th>");
}
function nextButton($params) {
echo("<th><a href='" . $params . "'><button>Next</button></a></th>");
}
function totalPages($limit) {
global $cat;
return ceil(getRowCount($cat)/$limit);
}
function pageLinks() {
global $page;
global $cat;
for ($i=0; $i < totalPages(15); $i++) {
if ($page == $i+1) {
echo("<td class='selectedpage'>");
} else {
echo("<td>");
}
echo("<a href='" . params($i+1) . "'>" . $i + 1 . "</a></td>");
}
}
function pageButtons() {
global $cat;
global $page;
if (1 < $page) {
backButton(params($page-1));
}
pageLinks();
if ($page < totalPages(15)) {
nextButton(params($page+1));
}
}
?>