PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/includes/pageNavigation.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 257 lines | 172 code | 15 blank | 70 comment | 41 complexity | e55d92be2a0a965cc3abfb2c0e6dfe29 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @version $Id: pageNavigation.php 5830 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. // no direct access
  14. defined( '_VALID_MOS' ) or die( 'Restricted access' );
  15. /**
  16. * Page navigation support class
  17. * @package Joomla
  18. */
  19. class mosPageNav {
  20. /** @var int The record number to start dislpaying from */
  21. var $limitstart = null;
  22. /** @var int Number of rows to display per page */
  23. var $limit = null;
  24. /** @var int Total number of rows */
  25. var $total = null;
  26. function mosPageNav( $total, $limitstart, $limit ) {
  27. $this->total = (int) $total;
  28. $this->limitstart = (int) max( $limitstart, 0 );
  29. $this->limit = (int) max( $limit, 1 );
  30. if ($this->limit > $this->total) {
  31. $this->limitstart = 0;
  32. }
  33. if (($this->limit-1)*$this->limitstart > $this->total) {
  34. $this->limitstart -= $this->limitstart % $this->limit;
  35. }
  36. }
  37. /**
  38. * @return string The html for the limit # input box
  39. */
  40. function getLimitBox () {
  41. $limits = array();
  42. for ($i=5; $i <= 30; $i+=5) {
  43. $limits[] = mosHTML::makeOption( "$i" );
  44. }
  45. $limits[] = mosHTML::makeOption( "50" );
  46. // build the html select list
  47. $html = mosHTML::selectList( $limits, 'limit', 'class="inputbox" size="1" onchange="document.adminForm.submit();"',
  48. 'value', 'text', $this->limit );
  49. $html .= "\n<input type=\"hidden\" name=\"limitstart\" value=\"$this->limitstart\" />";
  50. return $html;
  51. }
  52. /**
  53. * Writes the html limit # input box
  54. */
  55. function writeLimitBox () {
  56. echo mosPageNav::getLimitBox();
  57. }
  58. function writePagesCounter() {
  59. echo $this->getPagesCounter();
  60. }
  61. /**
  62. * @return string The html for the pages counter, eg, Results 1-10 of x
  63. */
  64. function getPagesCounter() {
  65. $html = '';
  66. $from_result = $this->limitstart+1;
  67. if ($this->limitstart + $this->limit < $this->total) {
  68. $to_result = $this->limitstart + $this->limit;
  69. } else {
  70. $to_result = $this->total;
  71. }
  72. if ($this->total > 0) {
  73. $html .= "\nResults " . $from_result . " - " . $to_result . " of " . $this->total;
  74. } else {
  75. $html .= "\nNo records found.";
  76. }
  77. return $html;
  78. }
  79. /**
  80. * Writes the html for the pages counter, eg, Results 1-10 of x
  81. */
  82. function writePagesLinks() {
  83. echo $this->getPagesLinks();
  84. }
  85. /**
  86. * @return string The html links for pages, eg, previous, next, 1 2 3 ... x
  87. */
  88. function getPagesLinks() {
  89. $html = '';
  90. $displayed_pages = 10;
  91. $total_pages = ceil( $this->total / $this->limit );
  92. $this_page = ceil( ($this->limitstart+1) / $this->limit );
  93. $start_loop = (floor(($this_page-1)/$displayed_pages))*$displayed_pages+1;
  94. if ($start_loop + $displayed_pages - 1 < $total_pages) {
  95. $stop_loop = $start_loop + $displayed_pages - 1;
  96. } else {
  97. $stop_loop = $total_pages;
  98. }
  99. if ($this_page > 1) {
  100. $page = ($this_page - 2) * $this->limit;
  101. $html .= "\n<a href=\"#beg\" class=\"pagenav\" title=\"first page\" onclick=\"javascript: document.adminForm.limitstart.value=0; document.adminForm.submit();return false;\">&lt;&lt;&nbsp;Start</a>";
  102. $html .= "\n<a href=\"#prev\" class=\"pagenav\" title=\"previous page\" onclick=\"javascript: document.adminForm.limitstart.value=$page; document.adminForm.submit();return false;\">&lt;&nbsp;Previous</a>";
  103. } else {
  104. $html .= "\n<span class=\"pagenav\">&lt;&lt;&nbsp;Start</span>";
  105. $html .= "\n<span class=\"pagenav\">&lt;&nbsp;Previous</span>";
  106. }
  107. for ($i=$start_loop; $i <= $stop_loop; $i++) {
  108. $page = ($i - 1) * $this->limit;
  109. if ($i == $this_page) {
  110. $html .= "\n<span class=\"pagenav\"> $i </span>";
  111. } else {
  112. $html .= "\n<a href=\"#$i\" class=\"pagenav\" onclick=\"javascript: document.adminForm.limitstart.value=$page; document.adminForm.submit();return false;\"><strong>$i</strong></a>";
  113. }
  114. }
  115. if ($this_page < $total_pages) {
  116. $page = $this_page * $this->limit;
  117. $end_page = ($total_pages-1) * $this->limit;
  118. $html .= "\n<a href=\"#next\" class=\"pagenav\" title=\"next page\" onclick=\"javascript: document.adminForm.limitstart.value=$page; document.adminForm.submit();return false;\"> Next&nbsp;&gt;</a>";
  119. $html .= "\n<a href=\"#end\" class=\"pagenav\" title=\"end page\" onclick=\"javascript: document.adminForm.limitstart.value=$end_page; document.adminForm.submit();return false;\"> End&nbsp;&gt;&gt;</a>";
  120. } else {
  121. $html .= "\n<span class=\"pagenav\">Next&nbsp;&gt;</span>";
  122. $html .= "\n<span class=\"pagenav\">End&nbsp;&gt;&gt;</span>";
  123. }
  124. return $html;
  125. }
  126. function getListFooter() {
  127. $html = '<table class="adminlist"><tr><th colspan="3">';
  128. $html .= $this->getPagesLinks();
  129. $html .= '</th></tr><tr>';
  130. $html .= '<td nowrap="nowrap" width="48%" align="right">Display #</td>';
  131. $html .= '<td>' .$this->getLimitBox() . '</td>';
  132. $html .= '<td nowrap="nowrap" width="48%" align="left">' . $this->getPagesCounter() . '</td>';
  133. $html .= '</tr></table>';
  134. return $html;
  135. }
  136. /**
  137. * @param int The row index
  138. * @return int
  139. */
  140. function rowNumber( $i ) {
  141. return $i + 1 + $this->limitstart;
  142. }
  143. /**
  144. * @param int The row index
  145. * @param string The task to fire
  146. * @param string The alt text for the icon
  147. * @return string
  148. */
  149. function orderUpIcon( $i, $condition=true, $task='orderup', $alt='Move Up' ) {
  150. if (($i > 0 || ($i+$this->limitstart > 0)) && $condition) {
  151. return '<a href="#reorder" onClick="return listItemTask(\'cb'.$i.'\',\''.$task.'\')" title="'.$alt.'">
  152. <img src="images/uparrow.png" width="12" height="12" border="0" alt="'.$alt.'">
  153. </a>';
  154. } else {
  155. return '&nbsp;';
  156. }
  157. }
  158. /**
  159. * @param int The row index
  160. * @param int The number of items in the list
  161. * @param string The task to fire
  162. * @param string The alt text for the icon
  163. * @return string
  164. */
  165. function orderDownIcon( $i, $n, $condition=true, $task='orderdown', $alt='Move Down' ) {
  166. if (($i < $n-1 || $i+$this->limitstart < $this->total-1) && $condition) {
  167. return '<a href="#reorder" onClick="return listItemTask(\'cb'.$i.'\',\''.$task.'\')" title="'.$alt.'">
  168. <img src="images/downarrow.png" width="12" height="12" border="0" alt="'.$alt.'">
  169. </a>';
  170. } else {
  171. return '&nbsp;';
  172. }
  173. }
  174. /**
  175. * @param int The row index
  176. * @param string The task to fire
  177. * @param string The alt text for the icon
  178. * @return string
  179. */
  180. function orderUpIcon2( $id, $order, $condition=true, $task='orderup', $alt='#' ) {
  181. // handling of default value
  182. if ($alt = '#') {
  183. $alt = 'Move Up';
  184. }
  185. if ($order == 0) {
  186. $img = 'uparrow0.png';
  187. $show = true;
  188. } else if ($order < 0) {
  189. $img = 'uparrow-1.png';
  190. $show = true;
  191. } else {
  192. $img = 'uparrow.png';
  193. $show = true;
  194. };
  195. if ($show) {
  196. $output = '<a href="#ordering" onClick="listItemTask(\'cb'.$id.'\',\'orderup\')" title="'. $alt .'">';
  197. $output .= '<img src="images/' . $img . '" width="12" height="12" border="0" alt="'. $alt .'" title="'. $alt .'" /></a>';
  198. return $output;
  199. } else {
  200. return '&nbsp;';
  201. }
  202. }
  203. /**
  204. * @param int The row index
  205. * @param int The number of items in the list
  206. * @param string The task to fire
  207. * @param string The alt text for the icon
  208. * @return string
  209. */
  210. function orderDownIcon2( $id, $order, $condition=true, $task='orderdown', $alt='#' ) {
  211. // handling of default value
  212. if ($alt = '#') {
  213. $alt = 'Move Down';
  214. }
  215. if ($order == 0) {
  216. $img = 'downarrow0.png';
  217. $show = true;
  218. } else if ($order < 0) {
  219. $img = 'downarrow-1.png';
  220. $show = true;
  221. } else {
  222. $img = 'downarrow.png';
  223. $show = true;
  224. };
  225. if ($show) {
  226. $output = '<a href="#ordering" onClick="listItemTask(\'cb'.$id.'\',\'orderdown\')" title="'. $alt .'">';
  227. $output .= '<img src="images/' . $img . '" width="12" height="12" border="0" alt="'. $alt .'" title="'. $alt .'" /></a>';
  228. return $output;
  229. } else {
  230. return '&nbsp;';
  231. }
  232. }
  233. /**
  234. * Sets the vars for the page navigation template
  235. */
  236. function setTemplateVars( &$tmpl, $name = 'admin-list-footer' ) {
  237. $tmpl->addVar( $name, 'PAGE_LINKS', $this->getPagesLinks() );
  238. $tmpl->addVar( $name, 'PAGE_LIST_OPTIONS', $this->getLimitBox() );
  239. $tmpl->addVar( $name, 'PAGE_COUNTER', $this->getPagesCounter() );
  240. }
  241. }
  242. ?>