PageRenderTime 27ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/inicio/controller/pagination.php

https://gitlab.com/talueses/SIPVE
PHP | 212 lines | 106 code | 27 blank | 79 comment | 25 complexity | ca475c8dca7f7809e34e8cd0e48078f6 MD5 | raw file
  1. <?php
  2. /*******************************************************************************\
  3. * @copyright
  4. *
  5. * === SIPve ===
  6. * Sistema Integrado de Protección con capacidades de Videovigilancia
  7. * Control de Acceso y Carnetización para el resguardo físico de instalaciones.
  8. *
  9. * Copyright (C) 2012 Fundación Centro Nacional de Innovación Tecnológica, Cenit.
  10. * Dirección de Investigación, Desarrollo e Innovación.
  11. * Gilda Ramos.
  12. * José Medina.
  13. * Héctor Reverón.
  14. * David Concepción.
  15. * Ronald Delgado.
  16. * Jenner Fuentes.
  17. *
  18. * This program is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License as published by
  20. * the Free Software Foundation, either VERSION 3 of the License, or
  21. * (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU General Public License
  29. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. *
  31. * Para mas información visite
  32. * @link http://repositorio.softwarelibre.gob.ve/ - RNA
  33. * @link http://sourceforge.net/projects/sipve/ - SourceForge
  34. * @link https://gitlab.com/talueses/SIPVE - Gitlab Repositorio.
  35. *
  36. \*******************************************************************************/
  37. ?>
  38. <?php
  39. /************************************************************\
  40. *
  41. * PHP Array Pagination Copyright 2007 - Derek Harvey
  42. * www.lotsofcode.com
  43. *
  44. * This file is part of PHP Array Pagination .
  45. *
  46. * PHP Array Pagination is free software; you can redistribute it and/or modify
  47. * it under the terms of the GNU General Public License as published by
  48. * the Free Software Foundation; either version 2 of the License, or
  49. * (at your option) any later version.
  50. *
  51. * PHP Array Pagination is distributed in the hope that it will be useful,
  52. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  53. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  54. * GNU General Public License for more details.
  55. *
  56. * You should have received a copy of the GNU General Public License
  57. * along with PHP Array Pagination ; if not, write to the Free Software
  58. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  59. *
  60. \************************************************************/
  61. class pagination
  62. {
  63. var $page = 1; // Current Page of the pagination
  64. var $perPage = 10; // Items on each page of the pagination, defaulted to 10
  65. function generate($array)
  66. {
  67. if ($_SESSION['PHP_SELF']!=$_SERVER["PHP_SELF"]){
  68. $_SESSION['PHP_SELF'] = $_SERVER["PHP_SELF"];
  69. $_SESSION['perPage'] = $_SESSION['page'] = null;
  70. }
  71. // Assign the items per page variable
  72. if (!empty($_GET['perPage'])){
  73. $this->perPage = $_GET['perPage'];
  74. } elseif (!empty($_SESSION['perPage'])){
  75. $this->perPage = $_SESSION['perPage'];
  76. }
  77. $_SESSION['perPage'] = $this->perPage;
  78. // Assign the page variable
  79. if (!empty($_GET['page'])) {
  80. $this->page = $_GET['page']; // using the get method
  81. } elseif (!empty($_SESSION['page'])) {
  82. $this->page = $_SESSION['page']; // using the session method
  83. } else {
  84. $this->page = 1; // if we don't have a page number then assume we are on the first page
  85. }
  86. $_SESSION['page'] = $this->page;
  87. // Take the length of the array
  88. $this->length = count($array);
  89. // Get the number of pages
  90. $this->pages = ceil($this->length / $this->perPage);
  91. // Calculate the starting point
  92. $this->start = ceil(($this->page - 1) * $this->perPage);
  93. // Reset the starting point if the combo perPage set the start value greater than the length value
  94. if ($this->start>$this->length){
  95. $this->page = 1;
  96. $this->start=0;
  97. }
  98. if ($this->length==0){
  99. return array();
  100. }
  101. // Return the part of the array we have requested
  102. return array_slice($array, $this->start, $this->perPage);
  103. }
  104. function links()
  105. {
  106. // Initiate the links array
  107. $plinks = array();
  108. $links = array();
  109. $slinks = array();
  110. $max = array();
  111. // Concatenate the get variables to add to the page numbering string
  112. if (count($_GET)) {
  113. $queryURL = '';
  114. foreach ($_GET as $key => $value) {
  115. // Query URL for links
  116. if ($key != 'page') {
  117. $queryURL .= '&'.$key.'='.$value;
  118. }
  119. // Query URL for combo perPage
  120. if ($key != 'page' && $key != 'perPage') {
  121. $queryURLMax .= '&'.$key.'='.$value;
  122. }
  123. }
  124. }
  125. // If we have more then one pages
  126. if (($this->pages) > 1)
  127. {
  128. // Assign the 'previous page' link into the array if we are not on the first page
  129. if ($this->page != 1) {
  130. $plinks[] = ' <button type="button" title="Primero" onclick="document.location.href=\'?page=1'.$queryURL.'\'">&laquo;&laquo;</button> ';
  131. $plinks[] = ' <button type="button" title="Anterior" onclick="document.location.href=\'?page='.($this->page - 1).$queryURL.'\'">&laquo;</button> ';
  132. }
  133. // Assign the previous 4 page numbers of the current page to the array $links
  134. for ($i=($this->page-4);$i<=$this->page-1;$i++){
  135. if ($i>0){
  136. //$links[] = ' <a href="?page='.$i.$queryURL.'">'.$i.'</a> '; // add the link to the array
  137. $links[] = '<button type="button" title="'.$i.'" onclick="document.location.href=\'?page='.$i.$queryURL.'\'">'.$i.'</button> ';
  138. }
  139. }
  140. // Assign dots separators previous of the current page number to the array $links
  141. if (($this->page)>1)$links[] = "...";
  142. // Assign the current page to the array $links
  143. $links[] = "&nbsp;<strong>(&nbsp;".($this->page )."&nbsp;)</strong>&nbsp;"; // pagina actual
  144. // Assign dots separators after of the current page number to the array $links
  145. if (($this->page)<($this->pages))$links[] = "...";
  146. // Assign the after 4 page numbers of the current page to the array $links
  147. for ($i=($this->page+1);$i<=(($this->page)+4);$i++){
  148. if ($i<=($this->pages)){
  149. $links[] = '<button type="button" title="'.$i.'" onclick="document.location.href=\'?page='.$i.$queryURL.'\'">'.$i.'</button> ';
  150. }
  151. }
  152. // Assign the 'next page' if we are not on the last page
  153. if ($this->page < $this->pages) {
  154. $slinks[] = '<button type="button" title="Siguiente" onclick="document.location.href=\'?page='.($this->page + 1).$queryURL.'\'">&raquo;</button> ';
  155. $slinks[] = '<button type="button" title="&Uacute;ltimo" onclick="document.location.href=\'?page='.($this->pages).$queryURL.'\'">&raquo;&raquo;</button> ';
  156. }
  157. // Set perPage dinamic value
  158. $max[]= "<b style=\"font-size:10px;\" title=\"Total de Registros\">&nbsp;Registros: ".$this->length."&nbsp;</b>";
  159. $max[]= "<b>";
  160. $max[]= "&hellip;";
  161. $max[]= "<script type=\"text/javascript\" language=\"javascript\"> \n";
  162. $max[]= " function setPerPage(perPage){ \n";
  163. $max[]= " window.location = \"?page=".($this->page).$queryURLMax."&perPage=\"+perPage+\"\"; \n";
  164. $max[]= " } \n";
  165. $max[]= "</script> \n";
  166. $max[]= "[&nbsp;<select name=\"perPage\" id=\"perPage\" title=\"Registros por p&aacute;gina\" onchange=\"javascript:setPerPage(this.value);\">";
  167. for ($i=10;$i<=25;$i+=5){
  168. $selected = "";
  169. if ($this->perPage==$i){
  170. $selected = "selected";
  171. }
  172. $max[]= "<option value=\"".$i."\" ".$selected.">".$i."</option>\n";
  173. }
  174. $max[]= "</select>&nbsp;]";
  175. $max[]= "&hellip;";
  176. $max[]= "</b>";
  177. $max[]= "&nbsp;<b style=\"font-size:10px;\" title=\"Total de P&aacute;ginas\">&nbsp;P&aacute;ginas: ".$this->pages."</b>";
  178. $max[]= "<br />\n";
  179. // Push the array into a string using any some glue
  180. return "<p><div id=\"paginado\" class=\"ui-corner-all\" align=\"center\">".implode(' ', $max).implode(' ', $plinks).implode($this->implodeBy, $links).implode(' ', $slinks)."</div></p>";
  181. }
  182. return;
  183. }
  184. }
  185. ?>