<?php
# Configure pagination navigation for the control panel and the website.
# get $n & 'max', both must be strings containing digits only.
$n = isset($cwd) ? get_account($_SESSION['userID'])['results_'.$cwd] : (string)$files_to_load;
$_GET['max'] = !isset($_GET['max']) || !ctype_digit($_GET['max']) ? $n : $_GET['max'];
# Pagination navigation types:
# 1 : standard
# 2 : pages numeric
# 3 : standard with any number allowed as a 'max' GET value.(default)
# Load the nav type
$paginopt = simplexml_object('extras.xml','l',null);
if (is_array($paginopt))
$menutype = 3;
else
$menutype = isset($cwd) ? $paginopt->pagination->type : $paginopt->websitepagination->type;
# Do not allow a bad value for $n
$err = isset($cwd) ? '<i>:: Unwanted value for results per page. Must be a number greater than 0.</i>' : '';
if (!ctype_digit($n) || $n == 0)
exit ($err);
# Allow all max values for menu type 3
$maxall = $menutype == 3 ? true : is_int($_GET['max']/$n);
# Last max value
$finallink = ceil($catnum/$n)*$n;
if ($_GET['max'] > 0 && $maxall) {
if (abs($_GET['max']) > $catnum)
$_GET['max'] = $finallink;
$ofp = $_GET['max'];
}
else
$ofp = $n;
# next and previous page values
$nextlink = $ofp + $n;
$prevlink = $ofp - $n;
# results on a single page
$first = $ofp - $n < 0 ? 0 : $ofp - $n;
$last = $ofp;
###
# Type 2 pagination nav
# Print the sequence of the pages as links, instead of the "next - previous" menu.
# Total number of pages
$tnp = $finallink/$n;
# Menu size
$nol = 2;
# current page
$cpg = $ofp/$n;
if ($cpg == 0)
$cpg = 1;
# The distance to page 1
$fnl = $cpg-$nol <= 0 ? 1 : $cpg-$nol;
# Nav items
$firstpage = $lastpage = $nextpg = $prevpg = '';
$hlp = '…';
if ($cpg-$nol == 2)
$hlp = '';
/*
#calculate the number of results in the last page
$marg = $catnum / $n;
$marg = floatval($marg) - intval($marg);
$nlp = $n / (1/$marg);
*/
?>