Location: PHPKode > scripts > Application Framework Classes > application-framework-classes/pagespan.class.php
<?php
/**
 * (c) 2001 Christoph Althammer hide@address.com
 *
 * PageSpan
 *
 *
 *
 */

class Span {

	var $SelfUrl 		= "";
	var $PerPage 		= 3;
	var $LinkClass		= "";
	var $TextClass 		= "";
	var $ActOffset 		= 0;
	var $ParamName		= "";
	
	
	function PageSpanning($Offset=0,$MaxCount=0,$SelfUrl,$PerPage=0,$ParamName="Offset"){
		if ($PerPage>0) $this->PerPage	= $PerPage;
		$this->SelfUrl 		= $SelfUrl.$this->AddUrlParamSeparator($SelfUrl);		
		$this->ActOffset 	= $Offset;
		$this->ParamName	= $ParamName;
		$PageSum			= $this->getPageSum($MaxCount);
		if ($PageSum <= 1) return false;

		$this->writeHeader();
		
		if ($this->ActOffset > 0) {
			$this->writeBack();
			$this->writeSpacer();
			}
		 
		for($i=1;$i<=$PageSum;$i++){
			$this->writePageNumber($i);
			$this->writeSpacer();
			}
		if ((($this->ActOffset / $this->PerPage)+1) < $PageSum ) {
			
			$this->writeForward();
			}			
		$this->writeFooter();

	return true;
	}

	function getPageSum($MaxCount=0){
		$PageSum = (int)($MaxCount / $this->PerPage);
		if ( ($MaxCount % $this->PerPage) > 0 ) $PageSum++;
		return $PageSum;
	}

	function writePageNumber($Num){
		$PageOffset	= ($Num*$this->PerPage) - $this->PerPage;
		$Param		= "".$this->ParamName."=$PageOffset";
		if (	$this->ActOffset != $PageOffset) {
			echo"<a class=\"".$this->LinkClass."\" href=\"$this->SelfUrl".$Param."\" target=\"_self\">$Num</a>";
			} else
			echo"<span class=\"".$this->TextClass."\">$Num</span>";
		return true;
	}
	
	function writeBack(){
		$PageOffset	= $this->ActOffset - $this->PerPage;
		$Param		= "".$this->ParamName."=$PageOffset";
		echo"<a class=\"".$this->LinkClass."\" href=\"$this->SelfUrl".$Param."\" target=\"_self\"><<</a>";
		return true;
	}

	function writeForward(){
		$PageOffset	= $this->ActOffset + $this->PerPage;
		$Param		= "".$this->ParamName."=$PageOffset";
		echo"<a class=\"".$this->LinkClass."\" href=\"$this->SelfUrl".$Param."\" target=\"_self\">>></a>";
		return true;
	}
	

	
	function writeSpacer(){
		echo"&nbsp;&nbsp;&nbsp;";
		return true;
	}

	function Debug($Msg=""){
         
         if ($this->Debug == 1) {
                 $Debugger = new AppDebugger("",get_class($this),$Msg); }
         return true;
		}
	function writeHeader(){
		echo"<div align=\"center\">";
		return true;	
		}
	
	function writeFooter(){
		echo"</div>";
		return true;	
		}
	function AddUrlParamSeparator($Url=""){	
		$Sep	.= (strpos($Url,"?")) != false ? "&" : "?";
		return $Sep;
		}
    

 } // end class
?>
Return current item: Application Framework Classes