PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_virtuemart/classes/pageNavigation.class.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 233 lines | 164 code | 11 blank | 58 comment | 50 complexity | ba59d1a98d89dc9c585bf2d0c44580f2 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
  3. /**
  4. *
  5. * @version $Id: pageNavigation.class.php 1472 2008-07-14 19:36:23Z soeren_nb $
  6. * @package VirtueMart
  7. * @subpackage classes
  8. * @copyright Copyright (C) 2004-2008 soeren - All rights reserved.
  9. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  10. * VirtueMart is free software. This version may have been modified pursuant
  11. * to the GNU General Public License, and as distributed it includes or
  12. * is derivative of works licensed under the GNU General Public License or
  13. * other free or open source software licenses.
  14. * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
  15. *
  16. * http://virtuemart.net
  17. */
  18. /**
  19. * Page navigation support class
  20. * @package VirtueMart
  21. */
  22. class vmPageNav {
  23. /** @var int The record number to start dislpaying from */
  24. var $limitstart = null;
  25. /** @var int Number of rows to display per page */
  26. var $limit = null;
  27. /** @var int Total number of rows */
  28. var $total = null;
  29. function vmPageNav( $total, $limitstart, $limit ) {
  30. $this->total = intval( $total );
  31. $this->limitstart = max( $limitstart, 0 );
  32. $this->limit = 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. * Writes the html limit # input box
  42. * Modified by shumisha to handle SEF URLs 2008-06-28
  43. */
  44. function writeLimitBox ( $link = '') {
  45. echo $this->getLimitBox( $link);
  46. }
  47. /**
  48. * Modified by shumisha to handle SEF URLs 2008-06-28
  49. * @return string The html for the limit # input box
  50. */
  51. function getLimitBox ( $link = '') {
  52. $limits = array();
  53. if (!empty($link) && strpos( 'limitstart=', $link) === false) { // insert limitstart in url if missing // shumisha
  54. $link .= '&limitstart='.$this->limitstart;
  55. }
  56. for ($i=5; $i <= 30; $i+=5) {
  57. if (empty( $link)) {
  58. $limits[$i] = $i;
  59. } else {
  60. $limits[vmRoute($link.'&limit='.$i)] = $i;
  61. }
  62. }
  63. if (empty( $link)) {
  64. $limits[50] = 50;
  65. } else {
  66. $limits[vmRoute($link.'&limit=50')] = 50;
  67. }
  68. // build the html select list
  69. if (empty( $link)) {
  70. $html = ps_html::selectList( 'limit', $this->limit, $limits, 1, '', 'onchange="this.form.submit();"' );
  71. } else {
  72. $current = vmRoute($link.'&limit='.$this->limit);
  73. $html = ps_html::selectList( 'limit', $current, $limits, 1, '', 'onchange="location.href=this.value"' );
  74. }
  75. $html .= "\n<input type=\"hidden\" name=\"limitstart\" value=\"$this->limitstart\" />";
  76. return $html;
  77. }
  78. function writePagesCounter() {
  79. echo $this->getPagesCounter();
  80. }
  81. /**
  82. * @return string The html for the pages counter, eg, Results 1-10 of x
  83. */
  84. function getPagesCounter() {
  85. $html = '';
  86. $from_result = $this->limitstart+1;
  87. if ($this->limitstart + $this->limit < $this->total) {
  88. $to_result = $this->limitstart + $this->limit;
  89. } else {
  90. $to_result = $this->total;
  91. }
  92. if ($this->total > 0) {
  93. $html .= $GLOBALS['VM_LANG']->_('PN_RESULTS')." $from_result - $to_result ".$GLOBALS['VM_LANG']->_('PN_OF')." $this->total";
  94. } else {
  95. //$html .= "\nNo records found.";
  96. }
  97. return $html;
  98. }
  99. /**
  100. * Writes the html for the pages counter, eg, Results 1-10 of x
  101. */
  102. function writePagesLinks($link='') {
  103. echo $this->getPagesLinks($link);
  104. }
  105. /**
  106. * @return string The html links for pages, eg, previous, next, 1 2 3 ... x
  107. */
  108. function getPagesLinks($link='') {
  109. global $VM_LANG;
  110. $displayed_pages = 10;
  111. $total_pages = ceil( $this->total / $this->limit );
  112. $this_page = ceil( ($this->limitstart+1) / $this->limit );
  113. $start_loop = (floor(($this_page-1)/$displayed_pages))*$displayed_pages+1;
  114. if ($start_loop + $displayed_pages - 1 < $total_pages) {
  115. $stop_loop = $start_loop + $displayed_pages - 1;
  116. } else {
  117. $stop_loop = $total_pages;
  118. }
  119. $html = '<ul class="pagination">';
  120. if ($this_page > 1) {
  121. $page = ($this_page - 2) * $this->limit;
  122. if( $link != '') {
  123. $html .= "\n<li><a href=\"".vmRoute($link.'&limitstart=0')."\" class=\"pagenav\" title=\"".$VM_LANG->_('PN_START')."\">&laquo;&laquo; ".$VM_LANG->_('PN_START')."</a></li>";
  124. $html .= "\n<li><a href=\"".vmRoute($link.'&limitstart='.$page)."\" class=\"pagenav\" title=\"".$VM_LANG->_('PN_PREVIOUS')."\">&laquo; ".$VM_LANG->_('PN_PREVIOUS')."</a></li>";
  125. } else {
  126. $html .= "\n<li><a href=\"#beg\" class=\"pagenav\" title=\"".$VM_LANG->_('PN_START')."\" onclick=\"javascript: document.adminForm.limitstart.value=0; document.adminForm.submit();return false;\">&laquo;&laquo; ".$VM_LANG->_('PN_START')."</a></li>";
  127. $html .= "\n<li><a href=\"#prev\" class=\"pagenav\" title=\"".$VM_LANG->_('PN_PREVIOUS')."\" onclick=\"javascript: document.adminForm.limitstart.value=$page; document.adminForm.submit();return false;\">&laquo; ".$VM_LANG->_('PN_PREVIOUS')."</a></li>";
  128. }
  129. } else {
  130. $html .= "\n<li><span class=\"pagenav\">&laquo;&laquo; ".$VM_LANG->_('PN_START')."</span></li>";
  131. $html .= "\n<li><span class=\"pagenav\">&laquo; ".$VM_LANG->_('PN_PREVIOUS')."</span></li>";
  132. }
  133. for ($i=$start_loop; $i <= $stop_loop; $i++) {
  134. $page = ($i - 1) * $this->limit;
  135. if ($i == $this_page) {
  136. $html .= "\n<li><span class=\"pagenav\"> $i </span></li>";
  137. } else {
  138. if( $link != '') {
  139. $html .= "\n<li><a href=\"".vmRoute($link.'&limitstart='.$page)."\" class=\"pagenav\"><strong>$i</strong></a></li>";
  140. } else {
  141. $html .= "\n<li><a href=\"#$i\" class=\"pagenav\" onclick=\"javascript: document.adminForm.limitstart.value=$page; document.adminForm.submit();return false;\"><strong>$i</strong></a></li>";
  142. }
  143. }
  144. }
  145. if ($this_page < $total_pages) {
  146. $page = $this_page * $this->limit;
  147. $end_page = ($total_pages-1) * $this->limit;
  148. if( $link != '') {
  149. $html .= "\n<li><a href=\"".vmRoute($link.'&limitstart='.$page)."\" class=\"pagenav\" title=\"".$VM_LANG->_('PN_NEXT')."\"> ".$VM_LANG->_('PN_NEXT')." &raquo;</a></li>";
  150. $html .= "\n<li><a href=\"".vmRoute($link.'&limitstart='.$end_page)."\" class=\"pagenav\" title=\"".$VM_LANG->_('PN_END')."\"> ".$VM_LANG->_('PN_END')." &raquo;&raquo;</a></li>";
  151. } else {
  152. $html .= "\n<li><a href=\"#next\" class=\"pagenav\" title=\"".$VM_LANG->_('PN_NEXT')."\" onclick=\"javascript: document.adminForm.limitstart.value=$page; document.adminForm.submit();return false;\"> ".$VM_LANG->_('PN_NEXT')." &raquo;</a></li>";
  153. $html .= "\n<li><a href=\"#end\" class=\"pagenav\" title=\"".$VM_LANG->_('PN_END')."\" onclick=\"javascript: document.adminForm.limitstart.value=$end_page; document.adminForm.submit();return false;\"> ".$VM_LANG->_('PN_END')." &raquo;&raquo;</a></li>";
  154. }
  155. } else {
  156. $html .= "\n<li><span class=\"pagenav\">".$VM_LANG->_('PN_NEXT')." &raquo;</span></li>";
  157. $html .= "\n<li><span class=\"pagenav\">".$VM_LANG->_('PN_END')." &raquo;&raquo;</span></li>";
  158. }
  159. $html .= "\n</ul>";
  160. return $html;
  161. }
  162. function getListFooter() {
  163. $html = '<table class="adminlist">';
  164. if( $this->total > $this->limit || $this->limitstart > 0) {
  165. $html .= '<tr><th colspan="3">';
  166. $html .= $this->getPagesLinks();
  167. $html .= '</th></tr>';
  168. }
  169. $html .= '<tr><td nowrap="true" width="48%" align="right">'.$GLOBALS['VM_LANG']->_('PN_DISPLAY_NR').'</td>';
  170. $html .= '<td>' .$this->getLimitBox() . '</td>';
  171. $html .= '<td nowrap="true" width="48%" align="left">' . $this->getPagesCounter() . '</td>';
  172. $html .= '</tr></table>';
  173. return $html;
  174. }
  175. /**
  176. * @param int The row index
  177. * @return int
  178. */
  179. function rowNumber( $i ) {
  180. return $i + 1 + $this->limitstart;
  181. }
  182. /**
  183. * @param int The row index
  184. * @param string The task to fire
  185. * @param string The alt text for the icon
  186. * @return string
  187. */
  188. function orderUpIcon( $i, $condition=true, $task='orderup', $alt='', $page, $func ) {
  189. global $mosConfig_live_site, $VM_LANG;
  190. if( $alt == '') {
  191. $alt = $VM_LANG->_('CMN_ORDER_UP');
  192. }
  193. if (($i > 0 || ($i+$this->limitstart > 0)) && $condition) {
  194. return '<a href="#reorder" onclick="return vm_listItemTask(\'cb'.$i.'\',\''.$task.'\', \'adminForm\', \''.$page.'\', \''.$func.'\')" title="'.$alt.'">
  195. <img src="'.$mosConfig_live_site.'/administrator/images/uparrow.png" width="12" height="12" border="0" alt="'.$alt.'" />
  196. </a>';
  197. } else {
  198. return '&nbsp;';
  199. }
  200. }
  201. /**
  202. * @param int The row index
  203. * @param int The number of items in the list
  204. * @param string The task to fire
  205. * @param string The alt text for the icon
  206. * @return string
  207. */
  208. function orderDownIcon( $i, $n, $condition=true, $task='orderdown', $alt='', $page, $func ) {
  209. global $mosConfig_live_site, $VM_LANG;
  210. if( $alt == '') {
  211. $alt = $VM_LANG->_('CMN_ORDER_DOWN');
  212. }
  213. if (($i < $n-1 || $i+$this->limitstart < $this->total-1) && $condition) {
  214. return '<a href="#reorder" onclick="return vm_listItemTask(\'cb'.$i.'\',\''.$task.'\', \'adminForm\', \''.$page.'\', \''.$func.'\')" title="'.$alt.'">
  215. <img src="'.$mosConfig_live_site.'/administrator/images/downarrow.png" width="12" height="12" border="0" alt="'.$alt.'" />
  216. </a>';
  217. } else {
  218. return '&nbsp;';
  219. }
  220. }
  221. }
  222. ?>