Просмотр файла admin/navigation.php

Размер файла: 1.38Kb
<?php
class navigation
{
public $num = 10;
public $url = false;

function __construct()
{
if(isset($_GET['p'])) $this->p = (int)$_GET['p']; else $this->p = 1;
if(empty($this->p) || $this->p < 1) $this->p = 1;
}

public function limit()
{
global $all;

$this->all = $all;

$this->maxpage = ceil($this->all/$this->num);
if($this->p > $this->maxpage) $this->p = 1;

$nmin = ($this->p * $this->num) - $this->num;
$nmax = ($this->num * $this->p) - 1;

return 'LIMIT '.$nmin.', '.$this->num;
}

public function view()
{
if($this->all > $this->num)
{
echo '<div class="menu">Страницы: ';

if($this->maxpage > 3 && $this->p > 2) echo '<a href="'.($this->url ? $this->url.'&amp;' : '?').'p=1">1</a>...';

$beg = $this->p-1;
$end = $this->p+1;

if($end > $this->maxpage + 1)
{
$end = $this->maxpage;
$beg = $beg - 2;
}
elseif($end > $this->maxpage)
{
$end = $this->maxpage;
$beg = $beg - 1;
}

for($m = $beg; $m <= $end; $m++)
{
if($m <= 0)
{
$end++;
}
else
{
if($m == $this->p)
{
echo '<span class="navcurrent">'.$m.'</span>';
}
else
{
echo '<a href="'.($this->url ? $this->url.'&amp;' : '?').'p='.$m.'">'.$m.'</a>';
}

if($m != $end)
{
echo ' ';
}
}
if($end > $this->maxpage) $end = $this->maxpage;
}

if($this->maxpage > 3 && $this->p <= ($this->maxpage - 2)) echo ' ... <a href="'.($this->url ? $this->url.'&amp;' : '?').'p='.$this->maxpage.'">'.$this->maxpage.'</a>';

echo '</div>';
}
}
}
?>