<!-- Realisatsiooni aluseks on võetud:
PHP Object Oriented CRUD Example with Bootstrap
Kasutatud 6.04.2016
https://www.codeofaninja.com/2014/06/php-object-oriented-crud-example-oop.html
-->

<?php

/*
======================
Lehekülgede nummerdus
Aktiivsed oksjonid
======================
*/

echo "<ul class=\"pagination\">";

//  Kood on kommenteeritud täielikult paging_loppenudoksjonid.php failis.
if($page>1){
    echo "<li><a href='{$page_dom}' title='Mine esimesele lehele.'>";
        echo "<<";
    echo "</a></li>";
}
 
if(isset($_GET["kategooria"])){
    $total_rows = $esemeteArvKategoorias;
}else {
    $total_rows = $oksjon->countAll();
}
$total_pages = ceil($total_rows / $records_per_page);

$range = 2;
 
$initial_num = $page - $range;
$condition_limit_num = ($page + $range)  + 1;
 
for ($x=$initial_num; $x<$condition_limit_num; $x++) {
 
    if (($x > 0) && ($x <= $total_pages)) {
 
        if ($x == $page) {
            echo "<li class='active'><a href=\"#\">$x <span class=\"sr-only\">(current)</span></a></li>";
        } 
 
        else {
            if(isset($_GET["kategooria"])){
            echo "<li><a href='{$page_dom}&page=$x'>$x</a></li>";
        }else {
             echo "<li><a href='{$page_dom}?page=$x'>$x</a></li>";
        }
        }
    }
}
 
if($page<$total_pages){
    if(isset($_GET["kategooria"])){
    echo "<li><a href='" .$page_dom . "&page={$total_pages}' title='Last page is {$total_pages}.'>";
}else{
    echo "<li><a href='" .$page_dom . "?page={$total_pages}' title='Last page is {$total_pages}.'>";
}
        echo ">>";
    echo "</a></li>";
}
 
echo "</ul>";
?>