Login   Register  
PHP Classes
elePHPant
Icontem

File: test1.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Stanislav Okhvat  >  PageNavigator  >  test1.php  >  Download  
File: test1.php
Role: ???
Content type: text/plain
Description: Testing script which demonstrates the behavior of all subclasses of PageNavigator
Class: PageNavigator
Author: By
Last change:
Date: 2002-03-25 03:36
Size: 5,976 bytes
 

Contents

Class file image Download
<?php

error_reporting (E_ALL);

include ("./Debugger.php");

define ("PAGENAV_PERPAGE",15);
define ("PAGENAV_TOTALRECS",355);
define ("PAGENAV_MINPAGES",6);
define ("PAGENAV_MAXPAGES",10);
define ("PAGENAV_CURRPAGEOFFSET",-1); // defines the number of pages to display
									// right of the current page in 
									// an AutoScroll-ed page navigator.
									// Default is -1 - center
define ("PAGENAV_PERSET",10);

/**
* Includes all classes above and including the given class name (by using a mapping array that defines class-filenames mappings)
*
* @param    string    name of the lowest class which, with its parent classes, needs to be included
* @param    string    path to the classes
* @return   void
* @access   public
*/
function includeAllClasses($class_name, $inc_path='./')
{
	$files = array('PageNavigator'=>'pagenav',
					'PageNavigator_AutoScroll'=>'autoscroll',
					'PageNavigator_ManualScroll'=>'manualscroll',
					'PageNavigator_AutoScroll_CustomRanges'=>'autoscrollrange',
					'PageNavigator_AutoScroll_Example'=>'autoscrollsimple',
					'PageNavigator_AutoScroll_FormButtons'=>'autoscrollform');

	// now do a loop and include every class
	$classes = explode('_', $class_name);
	for ($i=0; $i < sizeof($classes); $i++)
	{
		$class_file = (empty($class_file) ? $classes[$i] : $class_file.'_'.$classes[$i]);

		include_once($inc_path.$files[$class_file].'.php');
	}
} // end func 

/**
* Shows sample data in a table
*
* @param    integer   record to start with
* @param    integer   record to finish with
* @access   public
*/
function RenderSampleData($startrecord, $endrecord)
{
	$output = '';

	$output = "<table border=0 cellpadding=2 cellspacing=1 width=\"90%\">\n";
	// create the array
	for ($i = $startrecord; $i <= $endrecord; $i++)
	{
		$color = ($i % 2 == 1 ? "#C8C8C8" : "#FFFFFF");
		$output .= "<tr valign=\"top\"><td bgcolor=\"$color\">Record $i</td></tr>\n";
	}
	$output .= "</table>\n";

	return $output;

} // end func RenderSampleData


/**
* Loads a page navigator of a particular style and returns formatted output
*
* @param    string    type of page navigator, such as 'AutoScroll', 'ManualScroll', etc
* @param    string    style: 'from', 'page'
* @return   string    formatted page navigator
* @access   public
*/
function GetPageNavigator($type, $style='')
{
	// type of navigator to load
	$navigator_type = 'PageNavigator_'.(empty($type) ? 'AutoScroll' : $type);
	
	includeAllClasses($navigator_type, '');

	global $start, $page;

	// save copy of $page var for later re-use
	$page2 = $page;

	switch($style)
	{
		case "from":
			//$start = (empty($start) || $start == 0) ? 1 : $start;
			//$page = PageNavigator::toPage($start, PAGENAV_PERPAGE);
			if ($type != 'AutoScroll_FormButtons') $args = array('from'=>'start');
			else $args = array('page'=>'page');

			break;
		case "page":
		default:
			//if (empty($page) || $page <= 0) $page = $page2 = 1;
			$args = array('page'=>'page');
			break;
	}

	// if ($type == 'AutoScroll_FormButtons') $page = ($page2 == 0 ? 1 : $page2);

	$debug = new Debugger;
	$debug->TimerStart();

	switch(strpos($navigator_type,'ManualScroll'))
	{
		case 0:
			// AutoScroll, initialize with 7 arguments
			$pagenav = new $navigator_type($page, PAGENAV_PERPAGE, PAGENAV_TOTALRECS, PAGENAV_MINPAGES, PAGENAV_MAXPAGES, PAGENAV_CURRPAGEOFFSET, $args);
			break;
		default:
			// Manual scroll, only 5 arguments
			$pagenav = new $navigator_type($page, PAGENAV_PERPAGE, PAGENAV_TOTALRECS, PAGENAV_PERSET, $args);
			break;
	} // end switch

	$pagenav->autoLoadFromQuery();

	if ($pagenav->getTotalPages() > 1)
	{
		$pagenav->getRange($pagenav->getCurrentPage(), $firstrec, $lastrec);
		
		$formatted_range = sprintf( 'Records %s to %s from %s total', $firstrec, $lastrec, $pagenav->getRecordCount() );
		$formatted_range .= "<br><br>\n";

		$pagenav_html = $pagenav->render();
		
		$debug->TimerStop();
		$debug->TimerPrint();
		print "<br>\n";

		return $formatted_range.$pagenav_html.'<br>'.RenderSampleData($firstrec, $lastrec).'<br>'.$pagenav_html;
	}
	else
	{
		return false;
	}

} // end func GetPageNavigator

print '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>PageNavigator tests</TITLE>
<STYLE>
a.ln
{
	font-family : Verdana;
	font-size : 11px;
	font-weight : bold;
	text-decoration:none;
	color : #FFFFCC;
}

a.ln2
{
	font-family : Verdana;
	font-size : 10px;
	font-weight : bold;
	text-decoration:none;
	color : #FFCC33;
}
.buttons
{
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	color: #FFFFCC;
	background-color: #6699CC
}
</STYLE>
</HEAD>
<BODY>';

print '<h4><font color="green">PageNavigator tests</font></h4>';

print "<ul><li>Page mode &nbsp;&nbsp;&nbsp; <a href=\"$PHP_SELF?style=page&type=AutoScroll\">AutoScroll</a> | <a href=\"$PHP_SELF?style=page&type=ManualScroll\">ManualScroll</a> | <a href=\"$PHP_SELF?style=page&type=AutoScroll_Example\">AutoScroll custom style</a> | <a href=\"$PHP_SELF?style=page&type=AutoScroll_FormButtons\">AutoScroll with form buttons</a> | <a href=\"$PHP_SELF?style=page&type=AutoScroll_CustomRanges\">AutoScroll with from-to labels</a></li>\n\n";

print "<li>From-To mode &nbsp;&nbsp;&nbsp; <a href=\"$PHP_SELF?style=from&type=AutoScroll\">AutoScroll</a> | <a href=\"$PHP_SELF?style=from&type=ManualScroll\">ManualScroll</a> | <a href=\"$PHP_SELF?style=from&type=AutoScroll_Example\">AutoScroll custom style</a> | <a href=\"$PHP_SELF?style=from&type=AutoScroll_FormButtons\">AutoScroll with form buttons</a> | <a href=\"$PHP_SELF?style=page&type=AutoScroll_CustomRanges\">AutoScroll with from-to labels</a></li>\n";
print "</ul>\n";

if (!isset($type)) $type = '';
if (!isset($style)) $style = '';

print GetPageNavigator($type, $style);

print "</td></tr></table>\n</BODY></HTML>";
?>