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

/clases/browser_kernel.php

#
PHP | 293 lines | 253 code | 28 blank | 12 comment | 90 complexity | 03b445c75859dfc380d5ed268a2a1762 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="528px"><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. //print_r($row_rs_def);
  61. $keys = array_keys($row_rs_def[$entidad_def]);
  62. $i = 0;
  63. foreach ($keys as $key) {
  64. if (strstr($row_rs_def[$entidad_def][$key], 'primaria1_')) {
  65. $this->campo_llave = $this->codigo_tabla($tabla);
  66. $llave = 1;
  67. }
  68. if (strstr($row_rs_def[$entidad_def][$key], 'grid1')) {
  69. $llave_grid = explode('_', $key);
  70. $this->fila_de_datos_grid_def[] = $llave_grid[0];
  71. }
  72. 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')) {
  73. if ($tabla == 'empleado' && (strstr($row_rs_def[$entidad_def][$key], 'municipio') || strstr($row_rs_def[$entidad_def][$key], 'sexo'))) {
  74. echo ''; // no info.
  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 (strrchr($row_rs_def[$entidad_def][$key],'foranea')) {
  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. } while ($row_Rsfora1 = mysql_fetch_assoc($Rsfora1));
  114. $rows = mysql_num_rows($Rsfora1);
  115. if ($rows > 0) {
  116. mysql_data_seek($Rsfora1, 0);
  117. $row_Rsfora1 = mysql_fetch_assoc($Rsfora1);
  118. mysql_free_result($Rsfora1);
  119. }
  120. $this->buscador_str .= '</select></td></tr>';
  121. }
  122. } else {
  123. if ($flag == 0) {
  124. if (isset($_GET[$campo_rotulo])) {
  125. $campo_valor_buscado = $_GET[$campo_rotulo];
  126. } else {
  127. $campo_valor_buscado = '';
  128. }
  129. $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>';
  130. }
  131. if (isset($_GET[$campo_rotulo])) {
  132. $hidden_ordenar_str .= '<input type="hidden" name="' . $campo_rotulo . '" value="' . $_GET[$campo_rotulo] . '">';
  133. }
  134. if ($flag == 1) {
  135. if (isset($_GET['ordenar_por'])) {
  136. if ($_GET['ordenar_por'] == $rotulo_arr[0]) {
  137. $select_ordenar_option = ' selected ';
  138. } else {
  139. $select_ordenar_option = ' ';
  140. }
  141. }
  142. $this->ordenar_str .= '<option ' . $select_ordenar_option . ' value="' . $rotulo_arr[0] . '">' . $row_rs_rot[$entidad_rot][$campo_rotulo] . '</option>';
  143. }
  144. }
  145. if ($llave == 1) {
  146. if (isset($_GET[$campo_rotulo]) && $_GET[$campo_rotulo] != '') {
  147. $where_str .= " AND UPPER(" . $rotulo_arr[0] . ") LIKE '" . strtoupper($_GET[$campo_rotulo]) . "'";
  148. }
  149. } else {
  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. }
  155. }
  156. }
  157. $i++;
  158. }
  159. if ($flag == 1) {
  160. if (isset($_GET['s']) && $_GET['s'] != '') {
  161. $s = $_GET['s'];
  162. } else {
  163. $s = '';
  164. }
  165. if (isset($_GET['estado']) && $_GET['estado'] != '') {
  166. $gestados = $_GET['estado'];
  167. } else {
  168. $gestados = '';
  169. }
  170. $this->ordenar_str .= '</select>' . $hidden_ordenar_str . '
  171. <input name="tabla" type="hidden" value="' . $_GET["tabla"] . '">
  172. <input name="titulo_sufix" type="hidden" value="' . $_GET["titulo_sufix"] . '">
  173. <input name="estado" type="hidden" value="' . $gestados . '">
  174. <input name="nombre_seccion" type="hidden" value="' . $_GET["nombre_seccion"] . '">
  175. <input name="s" type="hidden" id="s" value="' . $s . '">
  176. <input name="ned" type="hidden" id="ned" value="' . $ned . '">
  177. <input name="id_op" type="hidden" id="id_op" value="' . $id_op . '">
  178. <input name="flag" type="hidden" id="flag" value="' . $flag . '">
  179. <input name="ordenar_descendente" type="hidden" id="ordenar_descendente" value="' . $ord_desc_val . '">
  180. <td class="tr1" align="right"><input name="Submit2" type="submit" class="input_submit" value=" Orden ' . $rotulo_boton_ordenar . ' "></td></tr>';
  181. }
  182. $this->currentPage = $_SERVER["PHP_SELF"];
  183. $this->maxRows_rs = 10;
  184. $this->pageNum_rs = 0;
  185. if (isset($_GET['pageNum_rs'])) {
  186. $this->pageNum_rs = $_GET['pageNum_rs'];
  187. }
  188. $this->startRow_rs = $this->pageNum_rs * $this->maxRows_rs;
  189. mysql_select_db(DB_NAME, CONEXION);
  190. if (isset($_GET['ordenar_por']) && $_GET['ordenar_por'] != '') {
  191. //dummy
  192. } else {
  193. $order_by = ' ORDER BY ' . $this->campo_llave . ' DESC ';
  194. }
  195. $where_str .= $whereEstado;
  196. $query_rs = 'SELECT ' . substr($rotulo_campos, 0, strlen($rotulo_campos) - 2) . ' FROM `' . $tabla . '` ' . $where_str . $order_by;
  197. //echo $query_rs ;
  198. if ($flag == 1) {
  199. $query_limit_rs = sprintf('%s LIMIT %d, %d', $query_rs, $this->startRow_rs, $this->maxRows_rs);
  200. // echo $query_limit_rs;
  201. $this->rs = mysql_query($query_limit_rs, CONEXION) or trigger_error(mysql_error(), E_USER_ERROR);
  202. $this->numfields = mysql_num_fields($this->rs);
  203. if (isset($_GET['totalRows_rs'])) {
  204. $this->totalRows_rs = $_GET['totalRows_rs'];
  205. } else {
  206. $all_rs = mysql_query($query_rs) or trigger_error(mysql_error(), E_USER_ERROR);
  207. $this->totalRows_rs = mysql_num_rows($all_rs);
  208. }
  209. $this->totalPages_rs = ceil($this->totalRows_rs / $this->maxRows_rs) - 1;
  210. $this->queryString_rs = '';
  211. if (!empty($_SERVER['QUERY_STRING'])) {
  212. $params = explode('&', $_SERVER['QUERY_STRING']);
  213. $newParams = array();
  214. foreach ($params as $param) {
  215. if (stristr($param, 'pageNum_rs') == false &&
  216. stristr($param, 'totalRows_rs') == false) {
  217. array_push($newParams, $param);
  218. }
  219. }
  220. if (count($newParams) != 0) {
  221. $this->queryString_rs = '&' . htmlentities(implode('&', $newParams), ENT_COMPAT, 'UTF-8');
  222. }
  223. }
  224. $this->queryString_rs = sprintf('&totalRows_rs=%d%s', $this->totalRows_rs, $this->queryString_rs);
  225. }
  226. if ($flag == 1) {
  227. $this->ordenar_str .= '</table></form>';
  228. }
  229. if ($flag == 0) {
  230. if (isset($_GET['s'])) {
  231. $s = $_GET['s'];
  232. } else {
  233. $s = '';
  234. }
  235. $this->buscador_str .='<tr align="center">
  236. <td colspan="2" class="tr3"><input name="tabla" type="hidden" value="' . $_GET["tabla"] . '">
  237. <input name="titulo_sufix" type="hidden" value="' . $_GET["titulo_sufix"] . '">
  238. <input name="nombre_seccion" type="hidden" value="' . $_GET["nombre_seccion"] . '">
  239. <input name="s" type="hidden" id="s" value="' . $s . '">
  240. <input name="flag" type="hidden" id="flag" value="1">
  241. <input name="id_op" type="hidden" id="flag" value="' . $id_op . '">
  242. <input name="ned" type="hidden" id="ned3" value="' . $ned . '">
  243. <input name="Reset" type="reset" class="input_submit" value=" Cancelar ">
  244. <input name="Submit" type="submit" class="input_submit" value=" Buscar "></td></tr></table></form>';
  245. }
  246. }
  247. public function __destruct() {
  248. // destruye esta clase
  249. unset($this->buscador_str);
  250. unset($this->ordenar_str);
  251. unset($this->rs);
  252. unset($this->row_rs);
  253. unset($this->numfields);
  254. unset($this->campo_llave);
  255. unset($this->startRow_rs);
  256. unset($this->totalRows_rs);
  257. unset($this->currentPage);
  258. unset($this->queryString_rs);
  259. unset($this->totalPages_rs);
  260. unset($this->maxRows_rs);
  261. unset($this->pageNum_rs);
  262. unset($this->fila_de_datos_grid_def);
  263. }
  264. }
  265. ?>