PageRenderTime 65ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/inicio/controller/buscador.control.php

https://gitlab.com/talueses/SIPVE
PHP | 170 lines | 70 code | 8 blank | 92 comment | 0 complexity | 805646ebcc6b5f13eee15a4cf6e5a69f 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. * Clase Buscador
  41. * @author David Concepcion CENIT-DIDI
  42. * Establece los objetos HTML de trascripcion de datos de busqueda y los datos a buscar
  43. *
  44. * Como usar:
  45. *
  46. * --- Consulta Dinamica ---
  47. *
  48. * En la consulta principal del listado agregar como argumento dinamico del buscador:
  49. *
  50. * // --- Valores del Buscador --- //
  51. * if ($_REQUEST["idcampoBuscador"]){
  52. * $in = null;
  53. * foreach ($_REQUEST["idcampoBuscador"] as $row){
  54. * $in.= "'".$row."',";
  55. * }
  56. * $in = substr($in, 0,(strlen($in)-1));
  57. * $arg = " where idcampo in (".$in.")";
  58. * }
  59. *
  60. * Donde idcampo se refiere al campo clave primaria de la tabla a consultar
  61. * - Se debe concatenar la variable $arg en la consulta como argumento de la misma.
  62. * - Si la consulta ya tiene argumento, sustituir el where por and, y colocar la variagle $arg como ultimo argumento
  63. * - Si la tabla de idcampo refiere un alias, colocarlo a idcampo
  64. *
  65. * --- Objetos HTML ---
  66. *
  67. * Instanciar el metodo getObjBuscador() de la calse Buscador e imprimir el valor de retorno:
  68. *
  69. * echo Buscador::getObjBuscador("idcampo", "campo1,campo2,...", "tabla", "order by campo1,campo2,...");
  70. *
  71. * idcampo: campo clave primaria
  72. * campo1,campo2,...: campos que se desean comparar
  73. * tabla: tabla a consultar
  74. *
  75. *
  76. */
  77. class Buscador {
  78. /**
  79. * Establece los objetos HTML y JS de trascripcion de datos de busqueda
  80. * Los parametros de busqueda son encriptados por BASE-64
  81. * @param string $value valor de codigo ID a bucsar
  82. * @param string $description valores de descripcion a buscar
  83. * @param string $table tabla de BD a consultar
  84. * @param string $arg argumentos sobre la busqueda
  85. * @return string Devuelve objetos HTML y JS para instanciar el motor de busqueda
  86. */
  87. public static function getObjBuscador($value,$description, $table, $arg) {
  88. $table = base64_encode($table);
  89. $arg = base64_encode($arg);
  90. $str = null;
  91. $ntab = Controller::getTabulation(8);//
  92. $str .= "<script type=\"text/javascript\" src=\"../../inicio/js/jquery.fcbkcomplete.js\"></script>\n";
  93. $str .= $ntab."\n";
  94. $str .= $ntab."\n";
  95. $str .= $ntab."<script type=\"text/javascript\">\n";
  96. $str .= $ntab." $(function() {\n";
  97. $str .= $ntab." $('#".Controller::setNameMakeCombo($value)."Buscador').fcbkcomplete({\n";
  98. $str .= $ntab." json_url: '../../inicio/view/buscadorData.php?value=".base64_encode($value)."&description=".base64_encode($description)."&tabla=".$table."&arg=".$arg."',\n";
  99. $str .= $ntab." addontab: true,\n";
  100. $str .= $ntab." maxitems: 10,\n";
  101. $str .= $ntab." input_min_size: 0,\n";
  102. $str .= $ntab." height: 10,\n";
  103. $str .= $ntab." cache: false,\n";
  104. $str .= $ntab." newel: false,\n";
  105. $str .= $ntab." select_all_text: '',\n";
  106. $str .= $ntab." complete_text: '',\n";
  107. $str .= $ntab." width: 'auto',\n";
  108. $str .= $ntab." delay: 0\n";
  109. $str .= $ntab." });\n";
  110. $str .= $ntab." $('#buscadorDiv').hide(0);\n";
  111. $str .= $ntab." $('#buscadorLegend').live({\n";
  112. $str .= $ntab." click:function(){\n";
  113. $str .= $ntab." $('#buscadorDiv').toggle('blind',500);\n";
  114. $str .= $ntab." }\n";
  115. $str .= $ntab." });\n";
  116. $str .= $ntab." });\n";
  117. $str .= $ntab."</script>\n";
  118. $str .= $ntab."\n";
  119. $str .= $ntab."\n";
  120. $str .= $ntab."<form method=\"POST\" >\n";
  121. $str .= $ntab." <fieldset id=\"buscador\">\n";
  122. $str .= $ntab." <legend id=\"buscadorLegend\">Buscador</legend>\n";
  123. $str .= $ntab." <div id=\"buscadorDiv\" align=\"left\">\n";
  124. $str .= $ntab." <input type=\"submit\" id=\"buscadorButton\" value=\"Buscar\" title=\"Presione para buscar o restablecer el listado\" />\n";
  125. $str .= $ntab." <select id=\"".Controller::setNameMakeCombo($value)."Buscador\" name=\"".Controller::setNameMakeCombo($value)."Buscador\">\n";
  126. $str .= $ntab." </select>\n";
  127. $str .= $ntab." <small class=\"comment\">Escriba lo que desee buscar</small>\n";
  128. $str .= $ntab." </div>\n";
  129. $str .= $ntab." </fieldset>\n";
  130. $str .= $ntab."</form>\n";
  131. return $str;
  132. }
  133. /**
  134. * Consulta de datos para motor de busqueda
  135. * Los parametros de la busqueda son desencriptados por BASE-64
  136. * @param string $key valor de codigo ID a bucsar
  137. * @param string $description valores de descripcion a buscar
  138. * @param string $table tabla de BD a consultar
  139. * @param string $arg argumentos sobre la busqueda
  140. * @return json Devuelve datos en formato JSON
  141. */
  142. public static function setDataBuscador($key,$description, $table, $arg){
  143. $key = base64_decode($key);
  144. $description = base64_decode($description);
  145. $table = base64_decode($table);
  146. $arg = base64_decode($arg); $str = array();
  147. $data = Model::getDataBuscador($key, $description, $table, $arg);
  148. $descriptions = explode(",", $description);
  149. foreach ($data as $row){
  150. $value = null;
  151. foreach ($descriptions as $description){
  152. $description = Controller::setNameMakeCombo($description);
  153. $value .= $row->$description." ";
  154. }
  155. $key = Controller::setNameMakeCombo($key);
  156. $str[] = array("key"=>strval($row->$key),"value"=>$value);
  157. }
  158. //echo "<div align='left'><pre>". print_r( $str , true)."</pre></div>";
  159. return json_encode($str);
  160. }
  161. }
  162. ?>