error_reporting(0); class Page_creator { //Variables that need to be defined from the calling script var $TotalItems;//Total amount of items (eg: the number of a mysql query) //Variables that can be dfined by the calling script var $ItemsPerPage=10;//Amount of items that will be shown per page var $PrevNext=true;//display a Previous/next link var $FirstLast=true;//display a First and lastpagelink var $TrailingPages=2;// The amount of pages that will be shown before and after the current page var $UsePoints=true; //Display points before and after the pagelinks if there are more pages than the ones shown var $Points="..";//string that will be used to represent the points (default is: ..) var $ShowTotalPages=true; //Display the total of all pages (default true) var $ShowTotalPagesString="Pages:"; //Text that will be shown befor the total pages var $ScriptVariable="st";//the parameter that will be used in the url to set the number of the first item in a page var $ScriptFile=""; //url of script (defaults to $PHP_SELF) var $Parameters=""; //array of parameters ( array(parameter => value,parameter => value) ) // Internal variables used generated by the class var $ParamString=""; var $StartItem; var $message; //intenal message function Create_Pagelinks() { $check=$this->check_variables(); if ($check==0) { $PageString=""; //Determin how many pages there are $TotalPages=ceil($this->TotalItems/$this->ItemsPerPage); if ($this->ShowTotalPages) $PageString .="(" . $this->ShowTotalPagesString . " " .$TotalPages .") "; //Determin on wich page we are $CurrentPage=(floor($this->StartItem/$this->ItemsPerPage))+1; if ($CurrentPage>$TotalPages) $CurrentPage=$TotalPages; //if page is not 1 create Prev and first if set to true if ($CurrentPage>1) { if ($this->FirstLast==true) { $PageString .='First '; } if ($this->PrevNext==true) { $PageString .='Prev '; } } //Make Trailing Pages if ($this->UsePoints) { if ($CurrentPage-$this->TrailingPages>1) $PageString .=$this->Points . " "; } $NumberedPages=($this->TrailingPages*2)+1; for ($i=0;$i<$NumberedPages;++$i) { $Pagenumber=$CurrentPage+$i-$this->TrailingPages; if ($Pagenumber<$CurrentPage && $Pagenumber > 0) $PageString .='' . $Pagenumber . ' '; if ($Pagenumber==$CurrentPage) $PageString .="" . $CurrentPage . " "; if ($Pagenumber>$CurrentPage && $Pagenumber <= $TotalPages) $PageString .='' . $Pagenumber . ' '; } if ($this->UsePoints) { if ($CurrentPage+$this->TrailingPages<$TotalPages) $PageString .=$this->Points ." "; } //if page is not last create Next and Last if set to true if ($CurrentPage<$TotalPages) { if ($this->PrevNext==true) { $PageString .='Next '; } if ($this->FirstLast==true) { $PageString .='Last '; } } } else $PageString=$this->message; return $PageString; } function check_variables() { $this->message="";$ok=0; if ((int)($this->TotalItems)<0) $this->TotalItems=0; $this->TotalItems=floor($this->TotalItems); if ($this->TotalItems==0) { //$this->message .= '!!Class PageCreator Error: TotalItems not defined by script (eg: $pg->TotalItems=100)'; $ok=1; } if ((int)($this->ItemsPerPage)<1) $this->ItemsPerPage=1; $this->ItemsPerPage=floor($this->ItemsPerPage); $this->StartItem=$_REQUEST[$this->ScriptVariable]; if (!$this->StartItem) $this->StartItem=0; if ((int)($this->StartItem)<0) $this->StartItem=0; if ((int)($this->StartItem)>$this->TotalItems) $this->StartItem=$this->$TotalItems-$this->ItemsPerPage; $this->StartItem=floor($this->StartItem); if ((int)($this->TrailingPages)<0) $this->TrailingPages=0; $this->TrailingPages=floor($this->TrailingPages); if (!$this->PrevNext && $this->TrailingPages<1) $this->TrailingPages=1; if (!$this->ScriptFile) $this->ScriptFile=$_SERVER["PHP_SELF"]; $this->ParamString=""; foreach ($this->Parameters as $key => $value) { $this->ParamString .="$key=$value&"; } return $ok; } } ?>
![]() | ![]() | ![]() |
|
|
| www.cornettolove.com |
|