[ Index ] |
|
Code source de Joomla 1.0.13 |
1 <?php 2 /** 3 * @version $Id: pageNavigation.php 5832 2006-11-21 18:59:45Z Saka $ 4 * @package Joomla 5 * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved. 6 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php 7 * Joomla! is free software. This version may have been modified pursuant 8 * to the GNU General Public License, and as distributed it includes or 9 * is derivative of works licensed under the GNU General Public License or 10 * other free or open source software licenses. 11 * See COPYRIGHT.php for copyright notices and details. 12 */ 13 14 // no direct access 15 defined( '_VALID_MOS' ) or die( 'Restricted access' ); 16 17 /** 18 * Page navigation support class 19 * @package Joomla 20 */ 21 class mosPageNav { 22 /** @var int The record number to start dislpaying from */ 23 var $limitstart = null; 24 /** @var int Number of rows to display per page */ 25 var $limit = null; 26 /** @var int Total number of rows */ 27 var $total = null; 28 29 function mosPageNav( $total, $limitstart, $limit ) { 30 $this->total = (int) $total; 31 $this->limitstart = (int) max( $limitstart, 0 ); 32 $this->limit = (int) max( $limit, 1 ); 33 if ($this->limit > $this->total) { 34 $this->limitstart = 0; 35 } 36 if (($this->limit-1)*$this->limitstart > $this->total) { 37 $this->limitstart -= $this->limitstart % $this->limit; 38 } 39 } 40 /** 41 * @return string The html for the limit # input box 42 */ 43 function getLimitBox () { 44 $limits = array(); 45 for ($i=5; $i <= 30; $i+=5) { 46 $limits[] = mosHTML::makeOption( "$i" ); 47 } 48 $limits[] = mosHTML::makeOption( "50" ); 49 50 // build the html select list 51 $html = mosHTML::selectList( $limits, 'limit', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 52 'value', 'text', $this->limit ); 53 $html .= "\n<input type=\"hidden\" name=\"limitstart\" value=\"$this->limitstart\" />"; 54 return $html; 55 } 56 /** 57 * Writes the html limit # input box 58 */ 59 function writeLimitBox () { 60 echo mosPageNav::getLimitBox(); 61 } 62 function writePagesCounter() { 63 echo $this->getPagesCounter(); 64 } 65 /** 66 * @return string The html for the pages counter, eg, Results 1-10 of x 67 */ 68 function getPagesCounter() { 69 $html = ''; 70 $from_result = $this->limitstart+1; 71 if ($this->limitstart + $this->limit < $this->total) { 72 $to_result = $this->limitstart + $this->limit; 73 } else { 74 $to_result = $this->total; 75 } 76 if ($this->total > 0) { 77 $html .= "\nResults " . $from_result . " - " . $to_result . " of " . $this->total; 78 } else { 79 $html .= "\nNo records found."; 80 } 81 return $html; 82 } 83 /** 84 * Writes the html for the pages counter, eg, Results 1-10 of x 85 */ 86 function writePagesLinks() { 87 echo $this->getPagesLinks(); 88 } 89 /** 90 * @return string The html links for pages, eg, previous, next, 1 2 3 ... x 91 */ 92 function getPagesLinks() { 93 $html = ''; 94 $displayed_pages = 10; 95 $total_pages = ceil( $this->total / $this->limit ); 96 $this_page = ceil( ($this->limitstart+1) / $this->limit ); 97 $start_loop = (floor(($this_page-1)/$displayed_pages))*$displayed_pages+1; 98 if ($start_loop + $displayed_pages - 1 < $total_pages) { 99 $stop_loop = $start_loop + $displayed_pages - 1; 100 } else { 101 $stop_loop = $total_pages; 102 } 103 104 if ($this_page > 1) { 105 $page = ($this_page - 2) * $this->limit; 106 $html .= "\n<a href=\"#beg\" class=\"pagenav\" title=\"first page\" onclick=\"javascript: document.adminForm.limitstart.value=0; document.adminForm.submit();return false;\"><< Start</a>"; 107 $html .= "\n<a href=\"#prev\" class=\"pagenav\" title=\"previous page\" onclick=\"javascript: document.adminForm.limitstart.value=$page; document.adminForm.submit();return false;\">< Previous</a>"; 108 } else { 109 $html .= "\n<span class=\"pagenav\"><< Start</span>"; 110 $html .= "\n<span class=\"pagenav\">< Previous</span>"; 111 } 112 113 for ($i=$start_loop; $i <= $stop_loop; $i++) { 114 $page = ($i - 1) * $this->limit; 115 if ($i == $this_page) { 116 $html .= "\n<span class=\"pagenav\"> $i </span>"; 117 } else { 118 $html .= "\n<a href=\"#$i\" class=\"pagenav\" onclick=\"javascript: document.adminForm.limitstart.value=$page; document.adminForm.submit();return false;\"><strong>$i</strong></a>"; 119 } 120 } 121 122 if ($this_page < $total_pages) { 123 $page = $this_page * $this->limit; 124 $end_page = ($total_pages-1) * $this->limit; 125 $html .= "\n<a href=\"#next\" class=\"pagenav\" title=\"next page\" onclick=\"javascript: document.adminForm.limitstart.value=$page; document.adminForm.submit();return false;\"> Next ></a>"; 126 $html .= "\n<a href=\"#end\" class=\"pagenav\" title=\"end page\" onclick=\"javascript: document.adminForm.limitstart.value=$end_page; document.adminForm.submit();return false;\"> End >></a>"; 127 } else { 128 $html .= "\n<span class=\"pagenav\">Next ></span>"; 129 $html .= "\n<span class=\"pagenav\">End >></span>"; 130 } 131 return $html; 132 } 133 134 function getListFooter() { 135 $html = '<table class="adminlist"><tr><th colspan="3">'; 136 $html .= $this->getPagesLinks(); 137 $html .= '</th></tr><tr>'; 138 $html .= '<td nowrap="nowrap" width="48%" align="right">Display #</td>'; 139 $html .= '<td>' .$this->getLimitBox() . '</td>'; 140 $html .= '<td nowrap="nowrap" width="48%" align="left">' . $this->getPagesCounter() . '</td>'; 141 $html .= '</tr></table>'; 142 return $html; 143 } 144 /** 145 * @param int The row index 146 * @return int 147 */ 148 function rowNumber( $i ) { 149 return $i + 1 + $this->limitstart; 150 } 151 /** 152 * @param int The row index 153 * @param string The task to fire 154 * @param string The alt text for the icon 155 * @return string 156 */ 157 function orderUpIcon( $i, $condition=true, $task='orderup', $alt='Move Up' ) { 158 if (($i > 0 || ($i+$this->limitstart > 0)) && $condition) { 159 return '<a href="#reorder" onClick="return listItemTask(\'cb'.$i.'\',\''.$task.'\')" title="'.$alt.'"> 160 <img src="images/uparrow.png" width="12" height="12" border="0" alt="'.$alt.'"> 161 </a>'; 162 } else { 163 return ' '; 164 } 165 } 166 /** 167 * @param int The row index 168 * @param int The number of items in the list 169 * @param string The task to fire 170 * @param string The alt text for the icon 171 * @return string 172 */ 173 function orderDownIcon( $i, $n, $condition=true, $task='orderdown', $alt='Move Down' ) { 174 if (($i < $n-1 || $i+$this->limitstart < $this->total-1) && $condition) { 175 return '<a href="#reorder" onClick="return listItemTask(\'cb'.$i.'\',\''.$task.'\')" title="'.$alt.'"> 176 <img src="images/downarrow.png" width="12" height="12" border="0" alt="'.$alt.'"> 177 </a>'; 178 } else { 179 return ' '; 180 } 181 } 182 183 /** 184 * @param int The row index 185 * @param string The task to fire 186 * @param string The alt text for the icon 187 * @return string 188 */ 189 function orderUpIcon2( $id, $order, $condition=true, $task='orderup', $alt='#' ) { 190 // handling of default value 191 if ($alt = '#') { 192 $alt = 'Move Up'; 193 } 194 195 if ($order == 0) { 196 $img = 'uparrow0.png'; 197 $show = true; 198 } else if ($order < 0) { 199 $img = 'uparrow-1.png'; 200 $show = true; 201 } else { 202 $img = 'uparrow.png'; 203 $show = true; 204 }; 205 if ($show) { 206 $output = '<a href="#ordering" onClick="listItemTask(\'cb'.$id.'\',\'orderup\')" title="'. $alt .'">'; 207 $output .= '<img src="images/' . $img . '" width="12" height="12" border="0" alt="'. $alt .'" title="'. $alt .'" /></a>'; 208 209 return $output; 210 } else { 211 return ' '; 212 } 213 } 214 215 /** 216 * @param int The row index 217 * @param int The number of items in the list 218 * @param string The task to fire 219 * @param string The alt text for the icon 220 * @return string 221 */ 222 function orderDownIcon2( $id, $order, $condition=true, $task='orderdown', $alt='#' ) { 223 // handling of default value 224 if ($alt = '#') { 225 $alt = 'Move Down'; 226 } 227 228 if ($order == 0) { 229 $img = 'downarrow0.png'; 230 $show = true; 231 } else if ($order < 0) { 232 $img = 'downarrow-1.png'; 233 $show = true; 234 } else { 235 $img = 'downarrow.png'; 236 $show = true; 237 }; 238 if ($show) { 239 $output = '<a href="#ordering" onClick="listItemTask(\'cb'.$id.'\',\'orderdown\')" title="'. $alt .'">'; 240 $output .= '<img src="images/' . $img . '" width="12" height="12" border="0" alt="'. $alt .'" title="'. $alt .'" /></a>'; 241 242 return $output; 243 } else { 244 return ' '; 245 } 246 } 247 248 /** 249 * Sets the vars for the page navigation template 250 */ 251 function setTemplateVars( &$tmpl, $name = 'admin-list-footer' ) { 252 $tmpl->addVar( $name, 'PAGE_LINKS', $this->getPagesLinks() ); 253 $tmpl->addVar( $name, 'PAGE_LIST_OPTIONS', $this->getLimitBox() ); 254 $tmpl->addVar( $name, 'PAGE_COUNTER', $this->getPagesCounter() ); 255 } 256 } 257 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 14:43:32 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |