PageRenderTime 51ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/browser_kernel.php

#
PHP | 297 lines | 258 code | 28 blank | 11 comment | 85 complexity | ae2af3d362696a7d2352e0c5a117bca6 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. class browser_kernel extends utiles {
  3. /* Extrae de la base de datos la informacion principal
  4. * de los catalogos y la deja lista para el ordenamiento, la busqueda y el paginado
  5. */
  6. public $buscador_str;
  7. public $ordenar_str;
  8. public $rs;
  9. public $row_rs;
  10. public $numfields;
  11. public $campo_llave;
  12. public $startRow_rs;
  13. public $totalRows_rs;
  14. public $currentPage;
  15. public $queryString_rs;
  16. public $totalPages_rs;
  17. public $maxRows_rs;
  18. public $pageNum_rs;
  19. public $fila_de_datos_grid_def = array();
  20. public function __construct() {
  21. global $tabla;
  22. global $ned;
  23. global $where_str;
  24. global $rotulo_boton_ordenar;
  25. global $ord_desc_val;
  26. global $flag;
  27. global $id_op;
  28. global $form_action;
  29. global $nombre_seccion;
  30. global $whereEstado;
  31. $rotulo_campos = '';
  32. $rotulo_mensaje = '';
  33. $hidden_ordenar_str = '';
  34. $select_ordenar_option = '';
  35. $campo_valor_buscado = '';
  36. $this->buscador_str = '';
  37. if ($flag == 0) {
  38. $this->buscador_str = '<form name="form_buscador" method="get" action="'.$form_action.'" onKeyUp="highlight(event)" onClick="highlight(event)">
  39. <table width="98%" align="center" class="tabla"><tr><td colspan="2" class="tr2">BUSCAR '.$nombre_seccion.'</td></tr>';
  40. }
  41. if ($flag == 1) {
  42. $this->ordenar_str = '<form action="'.$form_action.'" method="get" name="form_ordenar" id="form_ordenar">
  43. <table width="98%" align="center" class="tabla">';
  44. }
  45. $entidad_def = $tabla. '_definicion';
  46. // $metadata_def = new metadatos_array();
  47. $row_rs_def = $this->recorrer_entidad($entidad_def);
  48. $numfields_def = count($row_rs_def[$entidad_def]);
  49. if ($flag == 1) {
  50. $this->ordenar_str .= '<tr><td class="tr1" width="534px"><select class= "select_list_largo" name="ordenar_por">';
  51. $order_by = '';
  52. if (isset($_GET['ordenar_por']) && $_GET['ordenar_por'] != '') {
  53. $order_by = ' ORDER BY ' . $_GET['ordenar_por'] ;
  54. if (isset($_GET['ordenar_descendente']) && $_GET['ordenar_descendente'] == '1') {
  55. $order_by .= ' DESC ';
  56. }
  57. }
  58. }
  59. // echo $entidad_def;
  60. $keys = array_keys($row_rs_def[$entidad_def]);
  61. $i=0;
  62. foreach($keys as $key) {
  63. if (strstr($row_rs_def[$entidad_def][$key],'primaria1_')) {
  64. $this->campo_llave = $this->codigo_tabla($tabla);
  65. $llave = 1;
  66. }
  67. if (strstr($row_rs_def[$entidad_def][$key],'grid1')) {
  68. $llave_grid = explode('_',$key);
  69. $this->fila_de_datos_grid_def[] = $llave_grid[0];
  70. }
  71. if (strstr($row_rs_def[$entidad_def][$key],'_ppal') || strstr($row_rs_def[$entidad_def][$key],'_auto') || strstr($row_rs_def[$entidad_def][$key],'foranea')) {
  72. if ($tabla == 'empleado' && (strstr($row_rs_def[$entidad_def][$key],'municipio') || strstr($row_rs_def[$entidad_def][$key],'sexo'))) {
  73. echo ''; // no info.
  74. }
  75. else {
  76. $rotulo_arr = explode('_',$key);
  77. $campo_rotulo = $rotulo_arr[0].'_rotulo';
  78. $rotulo_campos .= $rotulo_arr[0].', ';
  79. $rotulo_nombre = $rotulo_arr[0];
  80. $entidad_rot = $tabla. '_definicion';
  81. // $metadata_rot = new metadatos_array();
  82. if (count($this->recorrer_entidad($entidad_rot)) > 0) {
  83. $row_rs_rot = $this->recorrer_entidad($entidad_rot);
  84. $rotulo_mensaje .= $row_rs_rot[$entidad_rot][$campo_rotulo].'/';
  85. // $metadata_srch = new metadatos_array();
  86. $row_rs_srch = $this->recorrer_entidad($entidad_rot);
  87. if ($row_rs_def[$entidad_def][$key] == 'foranea1') {
  88. $llave = 1;
  89. if ($flag == 0) {
  90. $this->buscador_str .= '<tr><td class="tr1">'.$row_rs_rot[$entidad_rot][$campo_rotulo].'</td> <td class="tr1"><select class= "select_list_largo" name="'.$campo_rotulo.'">';
  91. }
  92. if (isset($_GET[$campo_rotulo])) {
  93. $hidden_ordenar_str .= '<input type="hidden" name="'.$campo_rotulo.'" value="'.$_GET[$campo_rotulo].'">';
  94. }
  95. if ($flag == 1) {
  96. $this->ordenar_str .= '<option '.$select_ordenar_option.' value="'. $rotulo_arr[0].'">'.$row_rs_rot[$entidad_rot][$campo_rotulo] .'</option>';
  97. }
  98. $query_Rsfora1 = 'SELECT * FROM '.$this->replace_general($this->nombre_tabla_foranea($rotulo_arr[0]));
  99. if ($flag == 0) {
  100. $Rsfora1 = mysql_query($query_Rsfora1, CONEXION) or trigger_error(mysql_error(),E_USER_ERROR);
  101. $row_Rsfora1 = mysql_fetch_assoc($Rsfora1);
  102. $totalRows_Rsfora1 = mysql_num_rows($Rsfora1);
  103. $this->buscador_str .= '<option value=""></option>';
  104. do {
  105. $op_cod = $row_Rsfora1['id'.$this->replace_general($this->nombre_tabla_foranea($rotulo_arr[0]))];
  106. $this->buscador_str .= '<option ';
  107. if (isset($_GET[$campo_rotulo]) && $_GET[$campo_rotulo] != '' ) {
  108. if ($op_cod == $_GET[$campo_rotulo] ) {
  109. $this->buscador_str .= ' SELECTED ' ;
  110. }
  111. }
  112. $this->buscador_str .= ' value="'.$op_cod.'">'.$row_Rsfora1[$this->replace_general($this->nombre_tabla_foranea($rotulo_arr[0]))].'</option>';
  113. }
  114. while ($row_Rsfora1 = mysql_fetch_assoc($Rsfora1));
  115. $rows = mysql_num_rows($Rsfora1);
  116. if($rows > 0) {
  117. mysql_data_seek($Rsfora1, 0);
  118. $row_Rsfora1 = mysql_fetch_assoc($Rsfora1);
  119. mysql_free_result($Rsfora1);
  120. }
  121. $this->buscador_str .= '</select></td></tr>';
  122. }
  123. }
  124. else {
  125. if ($flag == 0) {
  126. if (isset($_GET[$campo_rotulo])) {
  127. $campo_valor_buscado = $_GET[$campo_rotulo];
  128. }
  129. else {
  130. $campo_valor_buscado = '';
  131. }
  132. $this->buscador_str .= '<tr><td class="tr1">'.$row_rs_rot[$entidad_rot][$campo_rotulo].'</td><td class="tr1"><input class="input_text" type="text" name="'.$campo_rotulo.'" value="'.$campo_valor_buscado.'"></td></tr>';
  133. }
  134. if (isset($_GET[$campo_rotulo])) {
  135. $hidden_ordenar_str .= '<input type="hidden" name="'.$campo_rotulo.'" value="'.$_GET[$campo_rotulo].'">';
  136. }
  137. if ($flag == 1) {
  138. if (isset($_GET['ordenar_por'])) {
  139. if ($_GET['ordenar_por'] == $rotulo_arr[0]) {
  140. $select_ordenar_option = ' selected ';
  141. }
  142. else {
  143. $select_ordenar_option = ' ';
  144. }
  145. }
  146. $this->ordenar_str .= '<option '.$select_ordenar_option.' value="'. $rotulo_arr[0].'">'.$row_rs_rot[$entidad_rot][$campo_rotulo] .'</option>';
  147. }
  148. }
  149. if ($llave == 1) {
  150. if (isset($_GET[$campo_rotulo]) && $_GET[$campo_rotulo] != '' ) {
  151. $where_str .= " AND UPPER(" .$rotulo_arr[0]. ") LIKE '". strtoupper($_GET[$campo_rotulo]) ."'";
  152. }
  153. }
  154. else {
  155. if (isset($_GET[$campo_rotulo]) && $_GET[$campo_rotulo] != '' ) {
  156. $where_str .= " AND UPPER(" . $rotulo_arr[0]. ") LIKE '%". strtoupper($_GET[$campo_rotulo]) ."%'";
  157. }
  158. }
  159. }
  160. }
  161. }
  162. $i++;
  163. }
  164. if ($flag == 1) {
  165. if(isset($_GET['s'])) {
  166. $s = $_GET['s'];
  167. }
  168. else {
  169. $s = '';
  170. }
  171. $this->ordenar_str .= '</select>'.$hidden_ordenar_str.'
  172. <input name="tabla" type="hidden" value="'. $_GET["tabla"].'">
  173. <input name="titulo_sufix" type="hidden" value="'. $_GET["titulo_sufix"].'">
  174. <input name="estado" type="hidden" value="'. $_GET["estado"].'">
  175. <input name="nombre_seccion" type="hidden" value="'. $_GET["nombre_seccion"].'">
  176. <input name="s" type="hidden" id="s" value="'.$s.'">
  177. <input name="ned" type="hidden" id="ned" value="'.$ned.'">
  178. <input name="id_op" type="hidden" id="id_op" value="'.$id_op.'">
  179. <input name="flag" type="hidden" id="flag" value="'.$flag.'">
  180. <input name="ordenar_descendente" type="hidden" id="ordenar_descendente" value="'.$ord_desc_val.'">
  181. <td class="tr1" align="right"><input name="Submit2" type="submit" class="input_submit" value=" Orden '.$rotulo_boton_ordenar.' "></td></tr>';
  182. }
  183. $this->currentPage = $_SERVER["PHP_SELF"];
  184. $this->maxRows_rs = 8;
  185. $this->pageNum_rs = 0;
  186. if (isset($_GET['pageNum_rs'])) {
  187. $this->pageNum_rs = $_GET['pageNum_rs'];
  188. }
  189. $this->startRow_rs = $this->pageNum_rs * $this->maxRows_rs;
  190. mysql_select_db(DB_NAME, CONEXION);
  191. if (isset($_GET['ordenar_por']) && $_GET['ordenar_por'] != '') {
  192. //dummy
  193. }
  194. else {
  195. $order_by = ' ORDER BY '. $this->campo_llave . ' DESC ';
  196. }
  197. $where_str .= $whereEstado ;
  198. $query_rs = 'SELECT ' . substr($rotulo_campos,0,strlen($rotulo_campos)-2) . ' FROM `'. $tabla. '` '. $where_str . $order_by;
  199. //echo $query_rs ;
  200. if ($flag == 1) {
  201. $query_limit_rs = sprintf('%s LIMIT %d, %d', $query_rs, $this->startRow_rs, $this->maxRows_rs);
  202. // echo $query_limit_rs;
  203. $this->rs= mysql_query($query_limit_rs, CONEXION) or trigger_error(mysql_error(),E_USER_ERROR);
  204. $this->numfields = mysql_num_fields($this->rs);
  205. if (isset($_GET['totalRows_rs'])) {
  206. $this->totalRows_rs = $_GET['totalRows_rs'];
  207. }
  208. else {
  209. $all_rs = mysql_query($query_rs) or trigger_error(mysql_error(),E_USER_ERROR);
  210. $this->totalRows_rs = mysql_num_rows($all_rs);
  211. }
  212. $this->totalPages_rs = ceil($this->totalRows_rs/$this->maxRows_rs)-1;
  213. $this->queryString_rs = '';
  214. if (!empty($_SERVER['QUERY_STRING'])) {
  215. $params = explode('&', $_SERVER['QUERY_STRING']);
  216. $newParams = array();
  217. foreach ($params as $param) {
  218. if (stristr($param, 'pageNum_rs') == false &&
  219. stristr($param, 'totalRows_rs') == false) {
  220. array_push($newParams, $param);
  221. }
  222. }
  223. if (count($newParams) != 0) {
  224. $this->queryString_rs = '&' . htmlentities(implode('&', $newParams),ENT_COMPAT,'UTF-8');
  225. }
  226. }
  227. $this->queryString_rs = sprintf('&totalRows_rs=%d%s', $this->totalRows_rs, $this->queryString_rs);
  228. }
  229. if ($flag == 1) {
  230. $this->ordenar_str .= '</table></form>';
  231. }
  232. if ($flag == 0) {
  233. if(isset($_GET['s'])) {
  234. $s = $_GET['s'];
  235. }
  236. else {
  237. $s = '';
  238. }
  239. $this->buscador_str .='<tr align="center">
  240. <td colspan="2" class="tr3"><input name="tabla" type="hidden" value="'. $_GET["tabla"].'">
  241. <input name="titulo_sufix" type="hidden" value="'. $_GET["titulo_sufix"].'">
  242. <input name="nombre_seccion" type="hidden" value="'. $_GET["nombre_seccion"].'">
  243. <input name="s" type="hidden" id="s" value="'.$s.'">
  244. <input name="flag" type="hidden" id="flag" value="1">
  245. <input name="id_op" type="hidden" id="flag" value="'.$id_op.'">
  246. <input name="ned" type="hidden" id="ned3" value="'.$ned.'">
  247. <input name="Reset" type="reset" class="input_submit" value=" Cancelar ">
  248. <input name="Submit" type="submit" class="input_submit" value=" Buscar "></td></tr></table></form>';
  249. }
  250. }
  251. public function __destruct() {
  252. // destruye esta clase
  253. unset($this->buscador_str);
  254. unset($this->ordenar_str);
  255. unset($this->rs);
  256. unset($this->row_rs);
  257. unset($this->numfields);
  258. unset($this->campo_llave);
  259. unset($this->startRow_rs);
  260. unset($this->totalRows_rs);
  261. unset($this->currentPage);
  262. unset($this->queryString_rs);
  263. unset($this->totalPages_rs);
  264. unset($this->maxRows_rs);
  265. unset($this->pageNum_rs);
  266. unset($this->fila_de_datos_grid_def);
  267. }
  268. }
  269. ?>