Annotation of /mambo/branches/4.5.3h/includes/pageNavigation.php
Parent Directory
|
Revision Log
Revision 22 - (view) (download)
| 1 : | root | 1 | <?php |
| 2 : | /** | ||
| 3 : | * @version $Id: pageNavigation.php,v 1.1 2005/07/22 01:57:13 eddieajau Exp $ | ||
| 4 : | * @package Mambo | ||
| 5 : | * @copyright (C) 2000 - 2005 Miro International Pty Ltd | ||
| 6 : | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL | ||
| 7 : | * Mambo is Free Software | ||
| 8 : | */ | ||
| 9 : | |||
| 10 : | /** ensure this file is being included by a parent file */ | ||
| 11 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 12 : | |||
| 13 : | /** | ||
| 14 : | * Page navigation support class | ||
| 15 : | * @package Mambo | ||
| 16 : | */ | ||
| 17 : | class mosPageNav { | ||
| 18 : | /** @var int The record number to start dislpaying from */ | ||
| 19 : | var $limitstart = null; | ||
| 20 : | /** @var int Number of rows to display per page */ | ||
| 21 : | var $limit = null; | ||
| 22 : | /** @var int Total number of rows */ | ||
| 23 : | var $total = null; | ||
| 24 : | |||
| 25 : | function mosPageNav( $total, $limitstart, $limit ) { | ||
| 26 : | $this->total = intval( $total ); | ||
| 27 : | $this->limitstart = max( $limitstart, 0 ); | ||
| 28 : | $this->limit = max( $limit, 0 ); | ||
| 29 : | } | ||
| 30 : | /** | ||
| 31 : | * Returns the html limit # input box | ||
| 32 : | * @param string The basic link to include in the href | ||
| 33 : | * @return string | ||
| 34 : | */ | ||
| 35 : | function getLimitBox ( $link ) { | ||
| 36 : | $limits = array(); | ||
| 37 : | for ($i=5; $i <= 30; $i+=5) { | ||
| 38 : | $limits[] = mosHTML::makeOption( "$i" ); | ||
| 39 : | } | ||
| 40 : | $limits[] = mosHTML::makeOption( "50" ); | ||
| 41 : | |||
| 42 : | // build the html select list | ||
| 43 : | $link = sefRelToAbs($link.'&limit=\' + this.options[selectedIndex].value + \'&limitstart='.$this->limitstart); | ||
| 44 : | return mosHTML::selectList( $limits, 'limit', | ||
| 45 : | 'class="inputbox" size="1" onchange="document.location.href=\''.$link.'\';"', | ||
| 46 : | 'value', 'text', $this->limit ); | ||
| 47 : | } | ||
| 48 : | /** | ||
| 49 : | * Writes the html limit # input box | ||
| 50 : | * @param string The basic link to include in the href | ||
| 51 : | */ | ||
| 52 : | function writeLimitBox ( $link ) { | ||
| 53 : | echo mosPageNav::getLimitBox( $link ); | ||
| 54 : | } | ||
| 55 : | /** | ||
| 56 : | * Writes the html for the pages counter, eg, Results 1-10 of x | ||
| 57 : | */ | ||
| 58 : | function writePagesCounter() { | ||
| 59 : | $txt = ''; | ||
| 60 : | $from_result = $this->limitstart+1; | ||
| 61 : | if ($this->limitstart + $this->limit < $this->total) { | ||
| 62 : | $to_result = $this->limitstart + $this->limit; | ||
| 63 : | } else { | ||
| 64 : | $to_result = $this->total; | ||
| 65 : | } | ||
| 66 : | if ($this->total > 0) { | ||
| 67 : | $txt .= _PN_RESULTS." $from_result - $to_result "._PN_OF." $this->total"; | ||
| 68 : | } | ||
| 69 : | return $txt; | ||
| 70 : | } | ||
| 71 : | |||
| 72 : | /** | ||
| 73 : | * Writes the html for the leafs counter, eg, Page 1 of x | ||
| 74 : | */ | ||
| 75 : | function writeLeafsCounter() { | ||
| 76 : | $txt = ''; | ||
| 77 : | $page = $this->limitstart+1; | ||
| 78 : | if ($this->total > 0) { | ||
| 79 : | $txt .= _PN_PAGE." $page "._PN_OF." $this->total"; | ||
| 80 : | } | ||
| 81 : | return $txt; | ||
| 82 : | } | ||
| 83 : | |||
| 84 : | /** | ||
| 85 : | * Writes the html links for pages, eg, previous, next, 1 2 3 ... x | ||
| 86 : | * @param string The basic link to include in the href | ||
| 87 : | */ | ||
| 88 : | function writePagesLinks( $link ) { | ||
| 89 : | $txt = ''; | ||
| 90 : | |||
| 91 : | $displayed_pages = 10; | ||
| 92 : | $total_pages = ceil( $this->total / $this->limit ); | ||
| 93 : | $this_page = ceil( ($this->limitstart+1) / $this->limit ); | ||
| 94 : | $start_loop = (floor(($this_page-1)/$displayed_pages))*$displayed_pages+1; | ||
| 95 : | if ($start_loop + $displayed_pages - 1 < $total_pages) { | ||
| 96 : | $stop_loop = $start_loop + $displayed_pages - 1; | ||
| 97 : | } else { | ||
| 98 : | $stop_loop = $total_pages; | ||
| 99 : | } | ||
| 100 : | |||
| 101 : | $link .= '&limit='. $this->limit; | ||
| 102 : | |||
| 103 : | if ($this_page > 1) { | ||
| 104 : | $page = ($this_page - 2) * $this->limit; | ||
| 105 : | $txt .= '<a href="'. sefRelToAbs( "$link&limitstart=0" ) .'" class="pagenav" title="first page"><< '. _PN_START .'</a> '; | ||
| 106 : | $txt .= '<a href="'. sefRelToAbs( "$link&limitstart=$page" ) .'" class="pagenav" title="previous page">< '. _PN_PREVIOUS .'</a> '; | ||
| 107 : | } else { | ||
| 108 : | $txt .= '<span class="pagenav"><< '. _PN_START .'</span> '; | ||
| 109 : | $txt .= '<span class="pagenav">< '. _PN_PREVIOUS .'</span> '; | ||
| 110 : | } | ||
| 111 : | |||
| 112 : | for ($i=$start_loop; $i <= $stop_loop; $i++) { | ||
| 113 : | $page = ($i - 1) * $this->limit; | ||
| 114 : | if ($i == $this_page) { | ||
| 115 : | $txt .= '<span class="pagenav">'. $i .'</span> '; | ||
| 116 : | } else { | ||
| 117 : | $txt .= '<a href="'. sefRelToAbs( $link .'&limitstart='. $page ) .'" class="pagenav"><strong>'. $i .'</strong></a> '; | ||
| 118 : | } | ||
| 119 : | } | ||
| 120 : | |||
| 121 : | if ($this_page < $total_pages) { | ||
| 122 : | $page = $this_page * $this->limit; | ||
| 123 : | $end_page = ($total_pages-1) * $this->limit; | ||
| 124 : | $txt .= '<a href="'. sefRelToAbs( $link .'&limitstart='. $page ) .' " class="pagenav" title="next page">'. _PN_NEXT .' ></a> '; | ||
| 125 : | $txt .= '<a href="'. sefRelToAbs( $link .'&limitstart='. $end_page ) .' " class="pagenav" title="end page">'. _PN_END .' >></a>'; | ||
| 126 : | } else { | ||
| 127 : | $txt .= '<span class="pagenav">'. _PN_NEXT .' ></span> '; | ||
| 128 : | $txt .= '<span class="pagenav">'. _PN_END .' >></span>'; | ||
| 129 : | } | ||
| 130 : | return $txt; | ||
| 131 : | } | ||
| 132 : | } | ||
| 133 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

