Location: PHPKode > projects > @1 File Store > libs/multipage.php
<?
class multipage
{
 var $totalrec;
 var $reconpage;
 var $pagename;
 var $curpage;
 var $constparam;
 var $pageinch;
 var $link;
 //êîíñòðóêòîð
 //$name - èìÿ ïàðàìåòðà äëÿ ïåðåäà÷è íîìåðà ñòðàíèöû
 function multipage($name)
 {
 	$this->pagename=$name;
 	if(isset($_GET[$name]) && strlen($_GET[$name]))
 	{
 		$this->curpage=intval(trim($_GET[$name]));
 	}else
         {
         	$this->curpage=1;
         }
        $this->reconpage=10;
        $this->totalrec=0;
        $this->link=array();
        $this->constparam=$this->generatequery($_GET, $name);
 }
 //óñòàíàâëèâàåò îáùèå ÷èñëî çàïèñåé
 //$count - ÷èñëî çàïèñåé
 function setrec($count)
 {
 	$this->totalrec=$count;
 }
 function getrec()
 {
 	return $this->totalrec;
 }
 //óñòàíàâëèâàåò ðàçìåð ñòðàíèöû
 //$count - ÷èñëî çàïèñåé íà ñòðàíèöå
 function setpagesize($count)
 {
 	$this->reconpage=$count;
 }
 function getpagesize()
 {
        return $this->reconpage;
 }
 //óñòíàíàâëèâàåò ÷èñëî ñòðàíèö, êîòîðûå íàäî âûâîäèòü
 //$count - ÷èñëî ñòðàíèö
 function setchapter($count)
 {
 	$this->pageinch=$count;
 }
 function getchapter()
 {
 	return $this->pageinch;
 }
 //óñòàíàâëèâàåò òåêñò ññûëîê íà ñëåäóþùóþ/ïðåäûäóùóþ ñòðàíèöó
 function pagelink($prev, $next)
 {
 	$this->link["prevpage"]=$prev;
 	$this->link["nextpage"]=$next;
 }
 //óñòàíàâëèâàåò òåêñò ññûëîê íà ïåðâóþ/ïîñëåäíþþ ñòðàíèöó
 function endlink($prev, $next)
 {
 	$this->link["startpage"]=$prev;
 	$this->link["endpage"]=$next;
 }
 //óñòàíàâëèâàåò òåêñò ññûëîê íà ñëåäóþùèé/ïðåäûäóùèé ïàðàãðàô
 function chaplink($prev, $next)
 {
 	$this->link["prevchap"]=$prev;
 	$this->link["nextchap"]=$next;
 }
 //ãåíåðèðóåò ñòðîêó ñ ïàðàìåòðàìè
 //$getarr - ìàññèâ ïàðàìåòðîâ ïåðåäàííûõ íà ñòðàíèöó
 //$name - èìÿ ïàðàìåòðà äëÿ îáîçíà÷åíèÿ íîìåðà ñòðàíèöû
 function generatequery($getarr, $name)
 {
 	$result="";
 	if(isset($getarr) && is_array($getarr) && count($getarr)>0)
 	{
 	 	while(list($param, $value)=each($getarr))
 	 	{
 	 		if($param==$name)
 	 			continue;
 	 		$result.=$param."=".urlencode($value)."&";
 	 	}
 	}
 	return $result;
 }
 //ôîðìèðîâàíèå ññûëêè
 //$num - íîìåð ñòðàíèöû íà êîòîðóþ ññûëêà
 
 function generatehref($num)
 {
 	$res="<a href=".$_SERVER["PHP_SELF"]."?";
 	if(isset($this->constparam) && strlen($this->constparam)>0)
 	{
 		$res.=$this->constparam;
 	}
 	$res.=$this->pagename."=".$num.">";
 	return $res;
  }
 //âûâîä íàâèãàöèè
 function printrow()
 {
 	
 	$totalpage=intval(ceil($this->totalrec/$this->reconpage));
 	if($totalpage==0)$totalpage=1;
 	if(isset($this->pageinch) && $this->pageinch>0)
 	{
 		$tempor=intval(floor($this->curpage/$this->pageinch));
 		$startpage=$tempor*$this->pageinch;
 		if($this->curpage%$this->pageinch!=0)
 		{
 			$startpage++;
 		}
 		if($this->curpage>1 && $this->curpage%$this->pageinch==0)
 		{
 			$startpage-=($this->pageinch-1);
		}
 		$endpage=$startpage+$this->pageinch-1;
 		if($endpage>$totalpage)
 			$endpage=$totalpage;
 	}else
 	 {
 	 	$startpage=1;
	 	$endpage=$totalpage;
	 }
 	$referense="";
 	//íàâèãàöèîííûå êíîïêè
 	if($this->curpage!=1 && isset($this->link["startpage"]) && strlen($this->link["startpage"])>0)
 	{
 		$referense.=$this->generatehref(1).$this->link["startpage"]."</a>&nbsp;";
 	}
 	if($this->curpage>$this->pageinch && isset($this->link["prevchap"]) && strlen($this->link["prevchap"])>0)
 	{
 		$referense.=$this->generatehref($this->curpage-$this->pageinch).$this->link["prevchap"]."</a>&nbsp; ";
 	}
 	if($this->curpage>1 && isset($this->link["prevpage"]) && strlen($this->link["prevpage"])>0)
 	{
 		$referense.=$this->generatehref($this->curpage-1).$this->link["prevpage"]."</a>&nbsp; ";
 	}
 	//ïî íîìåðàì
 	for($i=$startpage; $i<=$endpage; $i++)
 	{
 		$referense.="&nbsp;";
 		if($i==$this->curpage)
 		{
 			$referense.=strval($i);
 		}else
 		 {
 		 	$referense.=$this->generatehref($i).$i."</a>";
 		 }
 		$referense.="&nbsp ";
 	}
 	//íàâèãàöèîííûå êíîïêè
 	if($this->curpage<$totalpage && isset($this->link["nextpage"]) && strlen($this->link["nextpage"])>0)
 	{
 		$referense.=$this->generatehref($this->curpage+1).$this->link["nextpage"]."</a>&nbsp; ";
 	}
 	if($this->curpage<($totalpage-$this->pageinch) && isset($this->link["nextchap"]) && strlen($this->link["nextchap"])>0)
 	{
 		$referense.=$this->generatehref($this->curpage+$this->pageinch).$this->link["nextchap"]."</a>&nbsp; ";
 	}
 	if($this->curpage!=$totalpage && isset($this->link["endpage"]) && strlen($this->link["startpage"])>0)
 	{
 		$referense.=$this->generatehref($totalpage).$this->link["endpage"]."</a>&nbsp;";
 	}
 	return $referense;
 }
 
 function getlink($num)
 {
  $link=$_SERVER["PHP_SELF"]."?";
  if(isset($this->constparam) && strlen($this->constparam)>0)
  {
   $link.=$this->constparam;
  }
  $link.=$this->pagename."=".$num;
  return $link;
 }
 
 function smarty()
 {
  $res=array("page"=>$this->curpage, "pages"=>array());
  
  $totalpage=intval(ceil($this->totalrec/$this->reconpage));
  if($totalpage==0)$totalpage=1;
  $startpage=1;
  $endpage=$totalpage;
  for($i=$startpage; $i<=$endpage; $i++)
  {
   $res["pages"][$i]=$this->getlink($i);
  }
  return $res;
 }
 //Ôîðìèðóåò äèðåêòèóâå LIMIT äëÿ SQL çàïðîñà
 function limit()
 {
 	$result=" LIMIT ";
 	$result.=intval(($this->curpage-1)*$this->reconpage).",";
 	$result.=$this->reconpage;
 	return $result;
 }
}
?>
Return current item: @1 File Store