<?php
#Навигация на страницах
#CatCMS
#ver.3 by Akdmeh
#Version 3 for CatCMS
final class navigation
{
private $string_parametrs;
private $string;
private $all;
private $array;
private $now;
private $to;
private $style;
public function __construct($all, $now, $array=array(), $style=1, $to=NULL)
{
$this->all=$all;
$this->now=$now;
$this->array=$array;
if($to==NULL) $this->to=$_SERVER['PHP_SELF'];
else $this->to=$to;
$this->style=$style;
$this->array_to_string();
$this->strings();
}
public function array_to_string()
{
foreach ($this->array as $key => $value)
{
$this->string_parametrs.=$key.'='.$value.'&';
}
}
public function strings()
{
if($this->style==1)
{
for($i=1; $i<=$this->all; $i++)
{
if($i==$this->now) $this->string.=$i;
else $this->string.='<a href="'.$this->to.'?'.$this->string_parametrs.'page='.$i.'">'.$i.'</a>';
if($i!=$this->all) $this->string.=' | ';
if($i==$this->all) $this->string.='<br />';
}
}
elseif($this->style==2)
{
if ($this->now > 1) $this->string.='<a href="'.$this->to.'?'.$this->string_parametrs.'page='.($this->now-1).'"><Назад</a>|';
if($this->now< $this->all) $this->string.='<a href="'.$this->to.'?'.$this->string_parametrs.'page='.($this->now+1).'">Далее></a>';
if ($this->now > 1 || $this->now< $this->all)$this->string.='<br />';
$this->string.='Текущая страница: '.$this->now.' из '.$this->all.'<br/>';
$this->string.='<form action="'.$this->to.'"><p>Перейти к:<br /><input type="text" name="page" value="'.$this->now.'" maxlength="3" size="2" />';
foreach ($this->array as $key => $value)
{
$this->string.='<input type="hidden" name="'.$key.'" value="'.$value.'" />';
}
$this->string.='<input type="submit" value=">>" /></p></form>';
}
elseif($this->style==3)
{
if($this->all<=5)
{
for($i=1; $i<=$this->all; $i++)
{
if($i==$this->now) $this->string.=$i;
else $this->string.='<a href="'.$this->to.'?'.$this->string_parametrs.'page='.$i.'">'.$i.'</a>';
if($i!=$this->all) $this->string.=' ';
if($i==$this->all) $this->string.='<br />';
}
}
if($this->all>=6)
{
$one=1;
$end=$this->all;
$now=$this->now;
$pred=$now-1;
$next=$now+1;
if($one==$now) $this->string.='<span style="font-weight: bold;">1</span> ';
if($one!==$now) $this->string.='<a href="'.$this->to.'?'.$this->string_parametrs.'page=1">1</a>';
if($pred-1>1) $this->string.=' ... ';
if($pred>1) $this->string.=' <a href="'.$this->to.'?'.$this->string_parametrs.'page='.$pred.'">'.$pred.'</a> ';
if($now>1 && $now<$end) $this->string.=' '.$now.' ';
if($next<$end) $this->string.=' <a href="'.$this->to.'?'.$this->string_parametrs.'page='.$next.'">'.$next.'</a> ';
if($next+1<$end) $this->string.=' ... ';
if($now==$end) $this->string.=' <span style="font-weight: bold;">'.$end.'</span>';
else $this->string.=' <a href="'.$this->to.'?'.$this->string_parametrs.'page='.$end.'">'.$end.'</a> ';
$this->string.='<br />';
}
}
elseif($this->style==4)
{
if ($this->now > 1) $this->string.='<a href="'.$this->to.'?'.$this->string_parametrs.'page='.($this->now-1).'"><Назад</a>|';
if($this->now< $this->all) $this->string.='<a href="'.$this->to.'?'.$this->string_parametrs.'page='.($this->now+1).'">Далее></a>';
$this->string.='<br />';
$this->string.='Текущая страница: '.$this->now.' из '.$this->all.'<br/>';
}
}
public function __toString()
{
return $this->string;
}
} ?>