<?php
###################################################################################################################################################
# Class Description:
# Display the page summary. e.g.
# Records Per Page: 15 <<Previous 1 2 3 4 5 6 7 8 9 10 Next>>
#
# Class Version:
# Version Programmer DateTime Remarks
# --------- -------------- ----------- ---------------------------------
# 0.1.0 MaaN November 20 2004 New Class
# 0.1.2 MaaN November 23 2004 Debug on SetDisplayPages function. add in onChange = \" $this->vFormName.selpg.value = 1
#
# Steps/Example:
# $disprecords = $_POST['disprecords'];
# if (empty($disprecords)) { $disprecords = 15;} #if no specify, then default to 15 records per page
#
# $PgSum = new DisplayPages; #declare the class
# $PgSum->vPageNo=10; #Number of page number to be display <<Previous 1 2 3 4 5 6 7 8 9 10 Next>>. Default to 10
# $PgSum->vDispRecords=$disprecords; #Number of records to be display per page
# $PgSum->vCurrPageNo=$selpg; #Current Selected page number to be display <<Previous 1 2 3 4 5 6 7 8 9 10 Next>>. Default to 10
# $PgSum->TotalRecords($rsql); #run the query and get the records
# if ($PgSum->vTotalRecords>=1) {
# $PgSum->vFormName = "MainBody"; #The name of the working form
# $PgSum->vPageBatchNo=5; #When click on Previous or Next button, how many of pages will be bring forward or backward
# $PgSum->SetDisplayPages(5,5,$disprecords); #display the combo box for set the display records per page
# $PgSum->DisplayHyperlinkPrevious(); #display the Previous button
# $PgSum->DisplayHyperlink($selpg); #Display the hyperlink
# $PgSum->DisplayHyperlinkNext(); #display the next button
# $PgSum->CreateSelPG(); #Create a hidden object to record the selected page number
# } //end of if ($PgSum->vTotalRecords>=1) {
#
#
# Variables Description:
# $vPageNo = Number of page number to be display <<Previous 1 2 3 4 5 6 7 8 9 10 Next>>. Default to 10
# $vCurrPageNo = Current Selected page number to be display <<Previous 1 2 3 4 5 6 7 8 9 10 Next>>. Default to 10
# $vDispRecords = Number of records to be display per page
# $vTotalRecords = Total records return from the query //temporary
# $vPageBatchNo = When click on Previous or Next button, how many of pages will be bring forward or backward
# $vFormName = The name of the working form
#
# Copyright (C) MaaNHousE 2004
##################################################################################################################################################
class DisplayPages {
var $vPageNo;
var $vCurrPageNo;
var $vDispRecords;
var $vPageBatchNo;
var $vTotalRecords;
var $vFormName;
###################################################################################################
#to find out the smallest end limit value, so don't need to select all #
#the records #
# #
###################################################################################################
function LimitSelectedRecords() {
$tmpcountendlimit = $this->vPageNo * $this->vDispRecords;
return($tmpcountendlimit);
}
###################################################################################################
#Use the query to select the data from the database #
#find the total of records as per the query #
# #
###################################################################################################
function TotalRecords($sql) {
$tmpcurrpageno = ($this->vCurrPageNo * $this->vDispRecords) - $this->vDispRecords;
$sql .= " limit ". $tmpcurrpageno .", ". $this->LimitSelectedRecords();
//echo $sql."<br>";
$result = mysql_query($sql) or die (mysql_error());
$this->vTotalRecords = mysql_num_rows($result)+(($this->vCurrPageNo-1)*$this->vDispRecords);
//echo $this->vTotalRecords;
mysql_free_result($result);
}
###################################################################################################
#Actual number of pages to be display on the screen (TotalRecords() already limit the selection #
#It is based on the $vPageNo value set by user #
#vPageNo = Number of page number to be display #
#<<Previous 1 2 3 4 5 6 7 8 9 10 Next>>. #
# #
###################################################################################################
function TotalDisplayPages() {
if ($this->vTotalRecords==0) {
$tmptotdisplaypage = $this->vDispRecords; #zero products zero = zero, so skip;
} else {
$tmptotdisplaypage = ceil($this->vTotalRecords / $this->vDispRecords);
}
return($tmptotdisplaypage);
}
#################################################################################################
#Create the combo box so that user can set the total number of records to be #
#display per page #
# #
#################################################################################################
function SetDisplayPages($vRecordsGap, $vTotalSelection, $vSelectedValue) {
$intNo = 0;
echo "<B>Records Per Page: </B>";
echo "<select size='1' name = 'disprecords' onChange = \" $this->vFormName.selpg.value = 1; $this->vFormName.submit() \">";
for ($x=1; $x<=$vTotalSelection; $x++) {
$intNo = $intNo+$vRecordsGap;
echo "\n<option value = '$intNo' ".GetSelected($vSelectedValue, $intNo).">$intNo</option>";
}
echo "</select>";
}
#################################################################################################
#Calculate start page number #
# #
#################################################################################################
function StartPageNo() {
$tmpstartpageno = $this->vCurrPageNo - $this->vPageBatchNo;
if ($tmpstartpageno<=0) {
$tmpstartpageno=1;
}
return ($tmpstartpageno);
}
#################################################################################################
#Calculate end page number #
# #
#################################################################################################
function EndPageNo() {
$tmpendpageno = $this->StartPageNo() + $this->vPageNo - 1; //minus 1 to make it then
if ($tmpendpageno >= $this->TotalDisplayPages()) {
$tmpendpageno = $this->TotalDisplayPages();
}
return($tmpendpageno);
}
#################################################################################################
#Display the hyperlink #
#e.g. <<Previous 1 2 3 4 5 6 7 8 9 10 Next>> #
# #
#################################################################################################
function DisplayHyperlink($selpage) {
if ($this->EndPageNo() >= 2) {
for ($i=$this->StartPageNo(); $i<=$this->EndPageNo(); $i++) {
if ($i==$this->vCurrPageNo) {
echo "\n <b>$i</b> ";
} else {
echo "\n <a href=\"javascript:$this->vFormName.selpg.value=$i; $this->vFormName.submit();\" >$i</a> ";
}
}
}
}
#################################################################################################
#Display the Previoius button hyperlink #
#e.g. <<Previous 1 2 3 4 5 6 7 8 9 10 Next>> #
# #
#################################################################################################
function DisplayHyperlinkPrevious() {
$prevpageno = $this->StartPageNo()-$this->vPageNo+$this->vPageBatchNo+1; #plus 1 to make sure the last page still display
if ($prevpageno <= 1) { #If the final calculation for the page number is less than 1 then make it 1
$prevpageno = 1;
}
if ($this->vCurrPageNo >= 2 ) { #if the selected page is the the first one then, display the previous button
echo "\n <a href=\"javascript:$this->vFormName.selpg.value=$prevpageno; $this->vFormName.submit();\" ><b>pREvious</b></a> ";
}
}
#################################################################################################
#Display the Back button hyperlink #
#e.g. <<Previous 1 2 3 4 5 6 7 8 9 10 Next>> #
# #
#################################################################################################
function DisplayHyperlinkNext() {
$newendpageno = $this->EndPageNo()+$this->vPageNo-$this->vPageBatchNo;
if ($newendpageno >= $this->TotalDisplayPages()) {
$newendpageno = $this->TotalDisplayPages();
}
if ($this->vCurrPageNo < $this->TotalDisplayPages()) { #if the selected page is not the last then display the next button
echo "\n <a href=\"javascript: $this->vFormName.selpg.value=$newendpageno; $this->vFormName.submit();\" ><b>nExt</b></a> ";
}
}
#################################################################################################
#Create a hidden object to record the selected page number #
#Object name is selpg #
# #
#################################################################################################
function CreateSelPG() {
echo "\n<input type=\"hidden\" name=\"selpg\" value=\"$this->vCurrPageNo\">\n";
}
} //end of class
?>