PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/4.6/administrator/includes/pageNavigation.php

http://miacms.googlecode.com/
PHP | 183 lines | 123 code | 8 blank | 52 comment | 25 complexity | 0270d50cd2ae5524ffdb806f5e773d7a MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, LGPL-2.0
  1. <?php
  2. /**
  3. * @package MiaCMS
  4. * @author MiaCMS see README.php
  5. * @copyright see README.php
  6. * See COPYRIGHT.php for copyright notices and details.
  7. * @license GNU/GPL Version 2, see LICENSE.php
  8. * MiaCMS is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; version 2 of the License.
  11. */
  12. /** ensure this file is being included by a parent file */
  13. defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  14. /**
  15. * Page navigation support class
  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. function mosPageNav( $total, $limitstart, $limit ) {
  25. $this->total = intval( $total );
  26. $this->limitstart = max( intval($limitstart), 0 );
  27. $this->limit = max( intval($limit), 1 );
  28. if ($this->limit > $this->total) {
  29. $this->limitstart = 0;
  30. }
  31. if (($this->limit-1)*$this->limitstart > $this->total) {
  32. $this->limitstart -= $this->limitstart % $this->limit;
  33. }
  34. }
  35. /**
  36. * @return string The html for the limit # input box
  37. */
  38. function getLimitBox () {
  39. $limits = array();
  40. for ($i=5; $i <= 30; $i+=5) {
  41. $limits[] = mosHTML::makeOption( "$i" );
  42. }
  43. $limits[] = mosHTML::makeOption( "50" );
  44. // build the html select list
  45. $html = mosHTML::selectList( $limits, 'limit', 'class="inputbox" size="1" onchange="document.adminForm.submit();"',
  46. 'value', 'text', $this->limit );
  47. $html .= "\n<input type=\"hidden\" name=\"limitstart\" value=\"$this->limitstart\" />";
  48. return $html;
  49. }
  50. /**
  51. * Writes the html limit # input box
  52. */
  53. function writeLimitBox () {
  54. echo mosPageNav::getLimitBox();
  55. }
  56. function writePagesCounter() {
  57. echo $this->getPagesCounter();
  58. }
  59. /**
  60. * @return string The html for the pages counter, eg, Results 1-10 of x
  61. */
  62. function getPagesCounter() {
  63. $html = '';
  64. $from_result = $this->limitstart+1;
  65. if ($this->limitstart + $this->limit < $this->total) {
  66. $to_result = $this->limitstart + $this->limit;
  67. } else {
  68. $to_result = $this->total;
  69. }
  70. if ($this->total > 0) {
  71. $html .= sprintf(T_("Results %d to %d of %d"), $from_result, $to_result, $this->total);
  72. } else {
  73. $html .= T_('No records found.');
  74. }
  75. return $html;
  76. }
  77. /**
  78. * Writes the html for the pages counter, eg, Results 1-10 of x
  79. */
  80. function writePagesLinks() {
  81. echo $this->getPagesLinks();
  82. }
  83. /**
  84. * @return string The html links for pages, eg, previous, next, 1 2 3 ... x
  85. */
  86. function getPagesLinks() {
  87. $html = '';
  88. $displayed_pages = 10;
  89. $total_pages = ceil( $this->total / $this->limit );
  90. $this_page = ceil( ($this->limitstart+1) / $this->limit );
  91. $start_loop = (floor(($this_page-1)/$displayed_pages))*$displayed_pages+1;
  92. if ($start_loop + $displayed_pages - 1 < $total_pages) {
  93. $stop_loop = $start_loop + $displayed_pages - 1;
  94. } else {
  95. $stop_loop = $total_pages;
  96. }
  97. if ($this_page > 1) {
  98. $page = ($this_page - 2) * $this->limit;
  99. $html .= "\n<a href=\"#beg\" class=\"pagenav\" title=\"".T_('first page')."\" onclick=\"javascript: document.adminForm.limitstart.value=0; document.adminForm.submit();return false;\">&lt;&lt; ".T_('Start')."</a>";
  100. $html .= "\n<a href=\"#prev\" class=\"pagenav\" title=\"".T_('previous page')."\" onclick=\"javascript: document.adminForm.limitstart.value=$page; document.adminForm.submit();return false;\">&lt; ".T_('Previous')."</a>";
  101. } else {
  102. $html .= "\n<span class=\"pagenav\">&lt;&lt; ".T_('Start')."</span>";
  103. $html .= "\n<span class=\"pagenav\">&lt; ".T_('Previous')."</span>";
  104. }
  105. for ($i=$start_loop; $i <= $stop_loop; $i++) {
  106. $page = ($i - 1) * $this->limit;
  107. if ($i == $this_page) {
  108. $html .= "\n<span class=\"pagenav\"> $i </span>";
  109. } else {
  110. $html .= "\n<a href=\"#$i\" class=\"pagenav\" onclick=\"javascript: document.adminForm.limitstart.value=$page; document.adminForm.submit();return false;\"><strong>$i</strong></a>";
  111. }
  112. }
  113. if ($this_page < $total_pages) {
  114. $page = $this_page * $this->limit;
  115. $end_page = ($total_pages-1) * $this->limit;
  116. $html .= "\n<a href=\"#next\" class=\"pagenav\" title=\"".T_('next page')."\" onclick=\"javascript: document.adminForm.limitstart.value=$page; document.adminForm.submit();return false;\"> ".T_('Next')." &gt;</a>";
  117. $html .= "\n<a href=\"#end\" class=\"pagenav\" title=\"".T_('end page')."\" onclick=\"javascript: document.adminForm.limitstart.value=$end_page; document.adminForm.submit();return false;\"> ".T_('End')." &gt;&gt;</a>";
  118. } else {
  119. $html .= "\n<span class=\"pagenav\">".T_('Next')." &gt;</span>";
  120. $html .= "\n<span class=\"pagenav\">".T_('End')." &gt;&gt;</span>";
  121. }
  122. return $html;
  123. }
  124. function getListFooter() {
  125. $html = '<table class="adminlist"><tr><th colspan="3">';
  126. $html .= $this->getPagesLinks();
  127. $html .= '</th></tr><tr>';
  128. $html .= '<td nowrap="nowrap" width="48%" align="right">'.T_('Display #').'</td>';
  129. $html .= '<td>' .$this->getLimitBox() . '</td>';
  130. $html .= '<td nowrap="nowrap" width="48%" align="left">' . $this->getPagesCounter() . '</td>';
  131. $html .= '</tr></table>';
  132. return $html;
  133. }
  134. /**
  135. * @param int The row index
  136. * @return int
  137. */
  138. function rowNumber( $i ) {
  139. return $i + 1 + $this->limitstart;
  140. }
  141. /**
  142. * @param int The row index
  143. * @param string The task to fire
  144. * @param string The alt text for the icon
  145. * @return string
  146. * Note: The actual click event is handled in miacms_javascript.js
  147. */
  148. function orderUpIcon( $i, $condition=true, $task='orderup' ) {
  149. if (($i > 0 || ($i+$this->limitstart > 0)) && $condition) {
  150. $alt = T_('Move Up');
  151. $orderUpImage = '<img src="images/uparrow.png" id="'.$task.'_cb'.$i.'" width="12" height="12" alt="'.$alt.'" class="link-lookalike hover-pointer list-item-task" />';
  152. return $orderUpImage;
  153. } else {
  154. return '&nbsp;';
  155. }
  156. }
  157. /**
  158. * @param int The row index
  159. * @param int The number of items in the list
  160. * @param string The task to fire
  161. * @param string The alt text for the icon
  162. * @return string
  163. * Note: The actual click event is handled in miacms_javascript.js
  164. */
  165. function orderDownIcon( $i, $n, $condition=true, $task='orderdown' ) {
  166. if (($i < $n-1 || $i+$this->limitstart < $this->total-1) && $condition) {
  167. $alt = T_('Move Down');
  168. $orderDownImage = '<img src="images/downarrow.png" id="'.$task.'_cb'.$i.'" width="12" height="12" alt="'.$alt.'" class="link-lookalike hover-pointer list-item-task" />';
  169. return $orderDownImage;
  170. } else {
  171. return '&nbsp;';
  172. }
  173. }
  174. }
  175. ?>