AlaK4X
Linux lhjmq-records 5.15.0-118-generic #128-Ubuntu SMP Fri Jul 5 09:28:59 UTC 2024 x86_64



Your IP : 3.148.144.139


Current Path : /var/www/lhjmq-records.qc.ca/public_html/administration/includes/
Upload File :
Current File : /var/www/lhjmq-records.qc.ca/public_html/administration/includes/drawPageNumbers.php

<?php
/*********************************************************************
Author:				Mathieu Dumoulin
Date:					8 avril 2003
Info:					This class is in charge of drawing page number arrays
							for the user to select.
Version:			2.0.0
*********************************************************************/
if(!defined("CLS_PAGEDRAW")) {	
	define("CLS_PAGEDRAW","");
	
	class pagearray{
		
		var $url = "";
		var $currentpage = 0;
		var $res = 0;
		var $max = 0;
		var $pack = 0;
		var $page_sep = " - ";
		var $sel_open = "<STRONG>(";
		var $sel_close = ")</STRONG>";
		var $pack_open = "[ ";
		var $pack_close = " ]";
		
	
		/*constructor*/
		function pagearray($url, $currentpage, $res, $max, $pack, $page_sep, $sel_open, $sel_close, $pack_open, $pack_close){
			//Save the data
			$this->url = $url;
			$this->currentpage = $currentpage;
			$this->res = $res;
			$this->max = $max;
			$this->pack = $pack;
			$this->page_sep = $page_sep;
			$this->sel_open = $sel_open;
			$this->sel_close = $sel_close;
			$this->pack_open = $pack_open;
			$this->pack_close = $pack_close;
		}
		
		/*Quick call*/
		function drawpages(){
			//Call the complex_drawpages
			return $this->cdrawpages($this->url, $this->currentpage, $this->res, $this->max, $this->pack, $this->page_sep, $this->sel_open, $this->sel_close, $this->pack_open, $this->pack_close);
		}
		
		/*Draws a page array*/
		function cdrawpages($url, $currentpage, $res, $max, $pack, $page_sep, $sel_open, $sel_close, $pack_open, $pack_close){
			//Formatting
			$default_page_sep = $page_sep;
			$default_pack_open = $pack_open;
			$default_pack_close = $pack_close;
			
			//Return 1 if no other page
			if($res <= $max){
				return $default_pack_open . " 1 " . $default_pack_close;
			}
			
			//Get the max page and the package this page is in
			$nbpages = ceil($res / $max);
			$maxPagePack = ceil($nbpages / $pack);
			
			//Get the package of pages this page is in
			$selPagePack = ceil($currentpage / $pack);
			
			/*APPREND BY MDUMOULIN TO CORRECT DRAWING PHASE*/
			//Loop each page until all pages looped
			for($curPagePack=1; $curPagePack<=$maxPagePack; $curPagePack++){
				//Compare this page package to the current page one
				if($selPagePack == $curPagePack){
					//Draw each page seperatly, get the first page num and the last page num
					$packFirstPage = (($curPagePack * $pack) - ($pack - 1));
					$packLastPage = ($curPagePack * $pack);
					//Check that the last page doesn't over flow
					if($packLastPage > $nbpages){
						$packLastPage = $nbpages;
					}
					$pages .= $pack_open;
					for($i=$packFirstPage;$i<=$packLastPage;$i++){
						//Is it the current page
						if($i == $currentpage){
							//Draw as selected page
							$pages .= $pipeSep . str_replace('%%pagetag%%', '<B>'.$i.'</B>', str_replace('%%pageid%%', $i, $url));
							$pipeSep = $default_page_sep;
						}else{
							//Draw normal page
							$pages .= $pipeSep . str_replace('%%pagetag%%', $i, str_replace('%%pageid%%', $i, $url));
							$pipeSep = $default_page_sep;
						}
					}
					$pipeSep = '';
					$pages .= $pack_close;
				}else{
					//Draw a block of pages, get the first page num
					$packFirstPage = (($curPagePack * $pack) - ($pack - 1));
					$packLastPage = ($curPagePack * $pack);
					//Check that the last page doesn't over flow
					if($packLastPage > $nbpages){
						$packLastPage = $nbpages;
					}
					//Draw the block of pages
					$pages .= $pack_open . str_replace('%%pagetag%%', $packFirstPage . '-' . $packLastPage, str_replace('%%pageid%%', $packFirstPage, $url)) . $pack_close;
				}
			}
			return $pages;
		}
	}
}
?>