PageRenderTime 63ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/kernelActividades/application/libraries/Atajo.php

https://bitbucket.org/punketo28/sistema-de-control-de-actividades-del-poa
PHP | 1331 lines | 1248 code | 31 blank | 52 comment | 273 complexity | c9484fe435c298ece7ce6faf241dd9c1 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0
  1. <?php
  2. if ( ! defined('BASEPATH')) exit('No se vista que no va xD');
  3. /**
  4. En esta clase se encuentran metodos que facilitan la vida para trabajar de forma integrada con el framework
  5. php CodeIgniter y el framework jqGrid.
  6. */
  7. /**
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. <http://www.gnu.org/licenses/>.
  20. *********************************************************************************
  21. Este programa es software libre: usted puede redistribuirlo y / o modificar
  22. * Bajo los términos de la GNU General Public License publicada por
  23. * la Free Software Foundation, bien de la versión 3 de la Licencia, o
  24. * cualquier versión posterior.
  25. *
  26. * Este programa se distribuye con la esperanza de que sea útil,
  27. * pero SIN NINGUNA GARANTÍA, incluso sin la garantía implícita de
  28. * COMERCIALIZACIÓN o IDONEIDAD PARA UN PROPÓSITO PARTICULAR. Consulte la
  29. * Licencia Pública General GNU para más detalles.
  30. <http://www.gnu.org/licenses/>.
  31. *
  32. * @author Manuel Alejandro Marquez Ortiz <punketo28@gmail.com>
  33. * A.K.A. @punketo28
  34. * @date 2011/01/07
  35. */
  36. class Atajo
  37. {
  38. function __construct()
  39. {
  40. $this->CI = & get_instance();
  41. }
  42. /*Metodo copiado de los demos de jqGrid con algunas adaptaciones para validar que un dato introducido por
  43. el usuario sea integer, float o string si asi es requerido por la aplicacion.
  44. */
  45. function datoCompatible($dato, $tipo){
  46. // we need here more advanced checking using the type of the field - i.e. integer, string, float
  47. switch($tipo){
  48. case 'i':
  49. return intval($dato);//intval() Obtiene el valor entero de una variable
  50. break;
  51. case 'f':
  52. return floatval($dato);//floatval() Obtiene el valor flotante de una variable
  53. break;
  54. case 's':
  55. return addslashes($dato); //addslashes() Añade barras invertidas a los caracteres ('),("),(\),(nul) que esten dentro de la cadena.
  56. break;
  57. }
  58. }
  59. //Metodo que me construye el Grid junto con el modulo de busqueda avanzada de jqGrid.
  60. function construyeData($sidx, $sord, $start, $limit, $searchFlag, $searchField, $searchString, $searchOper, $seleccion, $table, $where=null, $apuntadorSearchNM=null, $apuntadorSearchNM1=null, $apuntadorSearchNM2=null, $apuntadorSearchMM=null, $apuntadorSearchMM1=null, $apuntadorSearchMM2=null, $join=null, $distinct=null){
  61. $qopers = array(//Aqui se crea un array cuyos elementos son las opciones del array sopt.
  62. 'ne'=>" != ",
  63. 'lt'=>" < ",
  64. 'le'=>" <= ",
  65. 'gt'=>" > ",
  66. 'ge'=>" >= ",
  67. 'bw'=>" LIKE ",
  68. 'bn'=>" NOT LIKE ",
  69. 'ew'=>" LIKE ",
  70. 'en'=>" NOT LIKE ",
  71. 'cn'=>" LIKE " ,
  72. 'nc'=>" NOT LIKE "
  73. );
  74. $flag = 0;
  75. if ($searchFlag == 'true'){
  76. if($searchString && $searchOper){
  77. if (!is_null($apuntadorSearchNM)){
  78. $countApuntadorNM = count($apuntadorSearchNM);
  79. if($countApuntadorNM > 1){
  80. for($i=0; $i<$countApuntadorNM; $i++){
  81. if ($searchField == $apuntadorSearchNM[$i]['campo']){
  82. $query = $this->CI->db->select($apuntadorSearchNM[$i]['campo11'])->where($apuntadorSearchNM[$i]['campo12'], $searchString)->get($apuntadorSearchNM[$i]['tabla1']);
  83. if($query->num_rows() > 0){
  84. foreach ($query->result() as $fila){
  85. $searchString2 = $fila->$apuntadorSearchNM[$i]['campo11'];
  86. }
  87. }
  88. $this->CI->db->select($apuntadorSearchNM[$i]['campo12']);
  89. $searchField = $apuntadorSearchNM[$i]['campo11'];
  90. $flag = 1;
  91. $searchField2 = $apuntadorSearchNM[$i]['campo12'];
  92. $tabla1 = $apuntadorSearchNM[$i]['tabla1'];
  93. $fkey = $apuntadorSearchNM[$i]['campo'];
  94. }
  95. }
  96. }
  97. else{
  98. if ($searchField == $apuntadorSearchNM[0]['campo']){
  99. $query = $this->CI->db->select($apuntadorSearchNM[0]['campo11'])->where($apuntadorSearchNM[0]['campo12'], $searchString)->get($apuntadorSearchNM[0]['tabla1']);
  100. if($query->num_rows() > 0){
  101. foreach ($query->result() as $fila){
  102. $searchString2 = $fila->$apuntadorSearchNM[0]['campo11'];
  103. }
  104. }
  105. $this->CI->db->select($apuntadorSearchNM[0]['campo12']);
  106. $searchField = $apuntadorSearchNM[0]['campo11'];
  107. $flag = 1;
  108. $searchField2 = $apuntadorSearchNM[0]['campo12'];
  109. $tabla1 = $apuntadorSearchNM[0]['tabla1'];
  110. $fkey = $apuntadorSearchNM[0]['campo'];
  111. }
  112. }
  113. }
  114. /*$apuntadorSearchNM1 = array(
  115. array('campo' => 'municipio', 'campo11' => 'descripcion', 'campo12' => 'id', 'tabla1' => 'municipio', 'campo21' => 'id', 'campo22' => 'id_municipio', 'tabla2' => 'parroquia', 'campo31' => 'id_parroquia')
  116. );
  117. */
  118. if (!is_null($apuntadorSearchNM1)){
  119. $countApuntadorNM1 = count($apuntadorSearchNM1);
  120. if($countApuntadorNM1 > 1){
  121. for($i=0; $i<$countApuntadorNM1; $i++){
  122. if ($searchField == $apuntadorSearchNM1[$i]['campo']){
  123. $query = $this->CI->db->select($apuntadorSearchNM1[$i]['campo11'])->where($apuntadorSearchNM1[$i]['campo12'], $searchString)->get($apuntadorSearchNM1[$i]['tabla1']);
  124. if($query->num_rows() > 0){
  125. foreach ($query->result() as $fila){
  126. $searchString2 = $fila->$apuntadorSearchNM1[$i]['campo11'];
  127. }
  128. }
  129. $this->CI->db->select($apuntadorSearchNM1[$i]['campo12']);
  130. $searchField = $apuntadorSearchNM1[$i]['campo11'];
  131. $flag = 2;
  132. $searchField2 = $apuntadorSearchNM1[$i]['campo12'];
  133. $tabla1 = $apuntadorSearchNM1[$i]['tabla1'];
  134. $campo21 = $apuntadorSearchNM1[$i]['campo21'];
  135. $campo22 = $apuntadorSearchNM1[$i]['campo22'];
  136. $tabla2 = $apuntadorSearchNM1[$i]['tabla2'];
  137. $fkey = $apuntadorSearchNM1[$i]['campo31'];
  138. }
  139. }
  140. }
  141. else{
  142. if ($searchField == $apuntadorSearchNM1[0]['campo']){
  143. $query = $this->CI->db->select($apuntadorSearchNM1[0]['campo11'])->where($apuntadorSearchNM1[0]['campo12'], $searchString)->get($apuntadorSearchNM1[0]['tabla1']);
  144. if($query->num_rows() > 0){
  145. foreach ($query->result() as $fila){
  146. $searchString2 = $fila->$apuntadorSearchNM1[0]['campo11'];
  147. }
  148. }
  149. $this->CI->db->select($apuntadorSearchNM1[0]['campo12']);
  150. $searchField = $apuntadorSearchNM1[0]['campo11'];
  151. $flag = 2;
  152. $searchField2 = $apuntadorSearchNM1[0]['campo12'];
  153. $tabla1 = $apuntadorSearchNM1[0]['tabla1'];
  154. $campo21 = $apuntadorSearchNM1[0]['campo21'];
  155. $campo22 = $apuntadorSearchNM1[0]['campo22'];
  156. $tabla2 = $apuntadorSearchNM1[0]['tabla2'];
  157. $fkey = $apuntadorSearchNM1[0]['campo31'];
  158. }
  159. }
  160. }
  161. /*$apuntadorSearchNM2 = array(
  162. array('campo' => 'eje', 'campo11' => 'descripcion', 'campo12' => 'id', 'tabla1' => 'eje', 'campo21' => 'id', 'campo22' => 'id_eje', 'tabla2' => 'municipio', 'campo31' => 'id', 'campo32' => 'id_municipio', 'tabla3' => 'parroquia', 'campo41' => 'id_parroquia')
  163. );*/
  164. if (!is_null($apuntadorSearchNM2)){
  165. $countApuntadorNM2 = count($apuntadorSearchNM2);
  166. if($countApuntadorNM2 > 1){
  167. for($i=0; $i<$countApuntadorNM2; $i++){
  168. if ($searchField == $apuntadorSearchNM2[$i]['campo']){
  169. $query = $this->CI->db->select($apuntadorSearchNM2[$i]['campo11'])->where($apuntadorSearchNM2[$i]['campo12'], $searchString)->get($apuntadorSearchNM2[$i]['tabla1']);
  170. if($query->num_rows() > 0){
  171. foreach ($query->result() as $fila){
  172. $searchString2 = $fila->$apuntadorSearchNM2[$i]['campo11'];
  173. }
  174. }
  175. $this->CI->db->select($apuntadorSearchNM2[$i]['campo12']);
  176. $searchField = $apuntadorSearchNM2[$i]['campo11'];
  177. $flag = 3;
  178. $searchField2 = $apuntadorSearchNM2[$i]['campo12'];
  179. $tabla1 = $apuntadorSearchNM2[$i]['tabla1'];
  180. $campo21 = $apuntadorSearchNM2[$i]['campo21'];
  181. $campo22 = $apuntadorSearchNM2[$i]['campo22'];
  182. $tabla2 = $apuntadorSearchNM2[$i]['tabla2'];
  183. $campo31 = $apuntadorSearchNM2[$i]['campo31'];
  184. $campo32 = $apuntadorSearchNM2[$i]['campo32'];
  185. $tabla3 = $apuntadorSearchNM2[$i]['tabla3'];
  186. $fkey = $apuntadorSearchNM2[$i]['campo41'];
  187. }
  188. }
  189. }
  190. else{
  191. if ($searchField == $apuntadorSearchNM2[0]['campo']){
  192. $query = $this->CI->db->select($apuntadorSearchNM2[0]['campo11'])->where($apuntadorSearchNM2[0]['campo12'], $searchString)->get($apuntadorSearchNM2[0]['tabla1']);
  193. if($query->num_rows() > 0){
  194. foreach ($query->result() as $fila){
  195. $searchString2 = $fila->$apuntadorSearchNM2[0]['campo11'];
  196. }
  197. }
  198. $this->CI->db->select($apuntadorSearchNM2[0]['campo12']);
  199. $searchField = $apuntadorSearchNM2[0]['campo11'];
  200. $flag = 3;
  201. $searchField2 = $apuntadorSearchNM2[0]['campo12'];
  202. $tabla1 = $apuntadorSearchNM2[0]['tabla1'];
  203. $campo21 = $apuntadorSearchNM2[0]['campo21'];
  204. $campo22 = $apuntadorSearchNM2[0]['campo22'];
  205. $tabla2 = $apuntadorSearchNM2[0]['tabla2'];
  206. $campo31 = $apuntadorSearchNM2[0]['campo31'];
  207. $campo32 = $apuntadorSearchNM2[0]['campo32'];
  208. $tabla3 = $apuntadorSearchNM2[0]['tabla3'];
  209. $fkey = $apuntadorSearchNM2[0]['campo41'];
  210. }
  211. }
  212. }
  213. if (!is_null($apuntadorSearchMM)){
  214. $countApuntadorMM = count($apuntadorSearchMM);
  215. if($countApuntadorMM > 1){
  216. for($i=0; $i<$countApuntadorMM; $i++){
  217. if ($searchField == $apuntadorSearchMM[$i]['campo']){
  218. $query = $this->CI->db->select($apuntadorSearchMM[$i]['campo11'])->where($apuntadorSearchMM[$i]['campo12'], $searchString)->get($apuntadorSearchMM[$i]['tabla1']);
  219. if($query->num_rows() > 0){
  220. foreach ($query->result() as $fila){
  221. $searchString2 = $fila->$apuntadorSearchMM[$i]['campo11'];
  222. }
  223. }
  224. $this->CI->db->select($apuntadorSearchMM[$i]['campo12']);
  225. $searchField = $apuntadorSearchMM[$i]['campo11'];
  226. $flag = 4;
  227. $searchField2 = $apuntadorSearchMM[$i]['campo12'];
  228. $tabla1 = $apuntadorSearchMM[$i]['tabla1'];
  229. $campo21 = $apuntadorSearchMM[$i]['campo21'];
  230. $campo22 = $apuntadorSearchMM[$i]['campo22'];
  231. $tabla2 = $apuntadorSearchMM[$i]['tabla2'];
  232. $campo31 = $apuntadorSearchMM[$i]['campo31'];
  233. }
  234. }
  235. }
  236. else{
  237. if($searchField == $apuntadorSearchMM[0]['campo']){
  238. $query = $this->CI->db->select($apuntadorSearchMM[0]['campo11'])->where($apuntadorSearchMM[0]['campo12'], $searchString)->get($apuntadorSearchMM[0]['tabla1']);
  239. if($query->num_rows() > 0){
  240. foreach ($query->result() as $fila){
  241. $searchString2 = $fila->$apuntadorSearchMM[0]['campo11'];
  242. }
  243. }
  244. $this->CI->db->select($apuntadorSearchMM[0]['campo12']);
  245. $searchField = $apuntadorSearchMM[0]['campo11'];
  246. $flag = 4;
  247. $searchField2 = $apuntadorSearchMM[0]['campo12'];
  248. $tabla1 = $apuntadorSearchMM[0]['tabla1'];
  249. $campo21 = $apuntadorSearchMM[0]['campo21'];
  250. $campo22 = $apuntadorSearchMM[0]['campo22'];
  251. $tabla2 = $apuntadorSearchMM[0]['tabla2'];
  252. $campo31 = $apuntadorSearchMM[0]['campo31'];
  253. }
  254. }
  255. }
  256. if (!is_null($apuntadorSearchMM1)){
  257. $countApuntadorMM1 = count($apuntadorSearchMM1);
  258. if($countApuntadorMM1 > 1){
  259. for($i=0; $i<$countApuntadorMM1; $i++){
  260. if ($searchField == $apuntadorSearchMM1[$i]['campo']){
  261. $query = $this->CI->db->select($apuntadorSearchMM1[$i]['campo11'])->where($apuntadorSearchMM1[$i]['campo12'], $searchString)->get($apuntadorSearchMM1[$i]['tabla1']);
  262. if($query->num_rows() > 0){
  263. foreach ($query->result() as $fila){
  264. $searchString2 = $fila->$apuntadorSearchMM1[$i]['campo11'];
  265. }
  266. }
  267. $this->CI->db->select($apuntadorSearchMM1[$i]['campo12']);
  268. $searchField = $apuntadorSearchMM1[$i]['campo11'];
  269. $flag = 5;
  270. $searchField2 = $apuntadorSearchMM1[$i]['campo12'];
  271. $tabla1 = $apuntadorSearchMM1[$i]['tabla1'];
  272. $campo21 = $apuntadorSearchMM1[$i]['campo21'];
  273. $campo22 = $apuntadorSearchMM1[$i]['campo22'];
  274. $tabla2 = $apuntadorSearchMM1[$i]['tabla2'];
  275. $campo31 = $apuntadorSearchMM1[$i]['campo31'];
  276. $campo32 = $apuntadorSearchMM1[$i]['campo32'];
  277. $tabla3 = $apuntadorSearchMM1[$i]['tabla3'];
  278. $campo41 = $apuntadorSearchMM1[$i]['campo41'];
  279. }
  280. }
  281. }
  282. else{
  283. if ($searchField == $apuntadorSearchMM1[0]['campo']){
  284. $query = $this->CI->db->select($apuntadorSearchMM1[0]['campo11'])->where($apuntadorSearchMM1[0]['campo12'], $searchString)->get($apuntadorSearchMM1[0]['tabla1']);
  285. if($query->num_rows() > 0){
  286. foreach ($query->result() as $fila){
  287. $searchString2 = $fila->$apuntadorSearchMM1[0]['campo11'];
  288. }
  289. }
  290. $this->CI->db->select($apuntadorSearchMM1[0]['campo12']);
  291. $searchField = $apuntadorSearchMM1[0]['campo11'];
  292. $flag = 5;
  293. $searchField2 = $apuntadorSearchMM1[0]['campo12'];
  294. $tabla1 = $apuntadorSearchMM1[0]['tabla1'];
  295. $campo21 = $apuntadorSearchMM1[0]['campo21'];
  296. $campo22 = $apuntadorSearchMM1[0]['campo22'];
  297. $tabla2 = $apuntadorSearchMM1[0]['tabla2'];
  298. $campo31 = $apuntadorSearchMM1[0]['campo31'];
  299. $campo32 = $apuntadorSearchMM1[0]['campo32'];
  300. $tabla3 = $apuntadorSearchMM1[0]['tabla3'];
  301. $campo41 = $apuntadorSearchMM1[0]['campo41'];
  302. }
  303. }
  304. }
  305. if (!is_null($apuntadorSearchMM2)){
  306. $countApuntadorMM2 = count($apuntadorSearchMM2);
  307. if($countApuntadorMM2 > 1){
  308. for($i=0; $i<$countApuntadorMM2; $i++){
  309. if ($searchField == $apuntadorSearchMM2[$i]['campo']){
  310. $query = $this->CI->db->select($apuntadorSearchMM2[$i]['campo11'])->where($apuntadorSearchMM2[$i]['campo12'], $searchString)->get($apuntadorSearchMM2[$i]['tabla1']);
  311. if($query->num_rows() > 0){
  312. foreach ($query->result() as $fila){
  313. $searchString2 = $fila->$apuntadorSearchMM2[$i]['campo11'];
  314. }
  315. }
  316. $this->CI->db->select($apuntadorSearchMM2[$i]['campo12']);
  317. $searchField = $apuntadorSearchMM2[$i]['campo11'];
  318. $flag = 6;
  319. $searchField2 = $apuntadorSearchMM2[$i]['campo12'];
  320. $tabla1 = $apuntadorSearchMM2[$i]['tabla1'];
  321. $campo21 = $apuntadorSearchMM2[$i]['campo21'];
  322. $campo22 = $apuntadorSearchMM2[$i]['campo22'];
  323. $tabla2 = $apuntadorSearchMM2[$i]['tabla2'];
  324. $campo31 = $apuntadorSearchMM2[$i]['campo31'];
  325. $campo32 = $apuntadorSearchMM2[$i]['campo32'];
  326. $tabla3 = $apuntadorSearchMM2[$i]['tabla3'];
  327. $campo41 = $apuntadorSearchMM2[$i]['campo41'];
  328. $campo42 = $apuntadorSearchMM2[$i]['campo42'];
  329. $tabla4 = $apuntadorSearchMM2[$i]['tabla4'];
  330. $campo51 = $apuntadorSearchMM2[$i]['campo51'];
  331. }
  332. }
  333. }
  334. else{
  335. if ($searchField == $apuntadorSearchMM2[0]['campo']){
  336. $query = $this->CI->db->select($apuntadorSearchMM2[0]['campo11'])->where($apuntadorSearchMM2[0]['campo12'], $searchString)->get($apuntadorSearchMM2[0]['tabla1']);
  337. if($query->num_rows() > 0){
  338. foreach ($query->result() as $fila){
  339. $searchString2 = $fila->$apuntadorSearchMM2[0]['campo11'];
  340. }
  341. }
  342. $this->CI->db->select($apuntadorSearchMM2[0]['campo12']);
  343. $searchField = $apuntadorSearchMM2[0]['campo11'];
  344. $flag = 6;
  345. $searchField2 = $apuntadorSearchMM2[0]['campo12'];
  346. $tabla1 = $apuntadorSearchMM2[0]['tabla1'];
  347. $campo21 = $apuntadorSearchMM2[0]['campo21'];
  348. $campo22 = $apuntadorSearchMM2[0]['campo22'];
  349. $tabla2 = $apuntadorSearchMM2[0]['tabla2'];
  350. $campo31 = $apuntadorSearchMM2[0]['campo31'];
  351. $campo32 = $apuntadorSearchMM2[0]['campo32'];
  352. $tabla3 = $apuntadorSearchMM2[0]['tabla3'];
  353. $campo41 = $apuntadorSearchMM2[0]['campo41'];
  354. $campo42 = $apuntadorSearchMM2[0]['campo42'];
  355. $tabla4 = $apuntadorSearchMM2[0]['tabla4'];
  356. $campo51 = $apuntadorSearchMM2[0]['campo51'];
  357. }
  358. }
  359. }
  360. switch ($searchOper){
  361. case "eq":
  362. if($flag != 0)
  363. $searchField = $searchField2;
  364. $this->CI->db->where($searchField, $searchString);
  365. break;
  366. case "ne":
  367. if($flag != 0)
  368. $searchField = $searchField2;
  369. $this->CI->db->where($searchField.$qopers['ne'], $searchString);
  370. break;
  371. case "lt":
  372. if($flag != 0)
  373. $searchString = $searchString2;
  374. $this->CI->db->where($searchField.$qopers['lt'], $searchString);
  375. break;
  376. case "le":
  377. if($flag != 0)
  378. $searchString = $searchString2;
  379. $this->CI->db->where($searchField.$qopers['le'], $searchString);
  380. break;
  381. case "gt":
  382. if($flag != 0)
  383. $searchString = $searchString2;
  384. $this->CI->db->where($searchField.$qopers['gt'], $searchString);
  385. break;
  386. case "ge":
  387. if($flag != 0)
  388. $searchString = $searchString2;
  389. $this->CI->db->where($searchField.$qopers['ge'], $searchString);
  390. break;
  391. case "bw":
  392. if($flag != 0)
  393. $searchString = $searchString2;
  394. $value = strtolower($searchString);
  395. $this->CI->db->where($searchField.$qopers['bw'], $value.'%');
  396. if(!empty($where) && $flag == 0)
  397. $this->CI->db->where($where[0], $where[1]);
  398. $this->CI->db->or_where($searchField.$qopers['bw'], strtoupper($value).'%');
  399. if(!empty($where) && $flag == 0)
  400. $this->CI->db->where($where[0], $where[1]);
  401. $this->CI->db->or_where($searchField.$qopers['bw'], ucfirst($value).'%');
  402. if(!empty($where) && $flag == 0)
  403. $this->CI->db->where($where[0], $where[1]);
  404. $this->CI->db->or_where($searchField.$qopers['bw'], ucwords($value).'%');
  405. if(!empty($where) && $flag == 0)
  406. $this->CI->db->where($where[0], $where[1]);
  407. break;
  408. case "bn":
  409. if($flag != 0)
  410. $searchString = $searchString2;
  411. $this->CI->db->where($searchField.$qopers['bn'], $searchString.'%');
  412. break;
  413. case "in":
  414. if($flag != 0)
  415. $searchField = $searchField2;
  416. $valuesArray = explode(",", $searchString);
  417. foreach ($valuesArray as $key => $valor){
  418. $valores[] = trim($valor);
  419. }
  420. foreach ($valores as $key2 => $valor2){
  421. $minusculas[] = strtolower($valor2);
  422. }
  423. foreach ($valores as $key3 => $valor3){
  424. $mayusculas[] = strtoupper($valor3);
  425. }
  426. foreach ($valores as $key4 => $valor4){
  427. $ucfirst[] = ucfirst($valor4);
  428. }
  429. foreach ($valores as $key5 => $valor5){
  430. $ucwords[] = ucwords($valor5);
  431. }
  432. $this->CI->db->where_in($searchField, $valores);
  433. if(!empty($where) && $flag == 0)
  434. $this->CI->db->where($where[0], $where[1]);
  435. $this->CI->db->or_where_in($searchField, $minusculas);
  436. if(!empty($where) && $flag == 0)
  437. $this->CI->db->where($where[0], $where[1]);
  438. $this->CI->db->or_where_in($searchField, $mayusculas);
  439. if(!empty($where) && $flag == 0)
  440. $this->CI->db->where($where[0], $where[1]);
  441. $this->CI->db->or_where_in($searchField, $ucfirst);
  442. if(!empty($where) && $flag == 0)
  443. $this->CI->db->where($where[0], $where[1]);
  444. $this->CI->db->or_where_in($searchField, $ucwords);
  445. if(!empty($where) && $flag == 0)
  446. $this->CI->db->where($where[0], $where[1]);
  447. break;
  448. case "ni":
  449. if($flag != 0)
  450. $searchField = $searchField2;
  451. $valuesArray = explode(",", $searchString);
  452. foreach ($valuesArray as $key => $valor){
  453. $valores[] = trim($valor);
  454. }
  455. $this->CI->db->where_not_in($searchField, $valores);
  456. if(!empty($where) && $flag == 0)
  457. $this->CI->db->where($where[0], $where[1]);
  458. break;
  459. case "ew":
  460. if($flag != 0)
  461. $searchString = $searchString2;
  462. $value = strtolower($searchString);
  463. $this->CI->db->where($searchField.$qopers['ew'], '%'.$value);
  464. if(!empty($where) && $flag == 0)
  465. $this->CI->db->where($where[0], $where[1]);
  466. $this->CI->db->or_where($searchField.$qopers['ew'], '%'.strtoupper($value));
  467. if(!empty($where) && $flag == 0)
  468. $this->CI->db->where($where[0], $where[1]);
  469. $this->CI->db->or_where($searchField.$qopers['ew'], '%'.ucfirst($value));
  470. if(!empty($where) && $flag == 0)
  471. $this->CI->db->where($where[0], $where[1]);
  472. $this->CI->db->or_where($searchField.$qopers['ew'], '%'.ucwords($value));
  473. if(!empty($where) && $flag == 0)
  474. $this->CI->db->where($where[0], $where[1]);
  475. break;
  476. case "en":
  477. if($flag != 0)
  478. $searchString = $searchString2;
  479. $this->CI->db->where($searchField.$qopers['en'], '%'.$searchString);
  480. break;
  481. case "cn":
  482. if($flag != 0)
  483. $searchString = $searchString2;
  484. $value = strtolower($searchString);
  485. $this->CI->db->where($searchField.$qopers['cn'], '%'.$value);
  486. if(!empty($where) && $flag == 0)
  487. $this->CI->db->where($where[0], $where[1]);
  488. $this->CI->db->or_where($searchField.$qopers['cn'], '%'.strtoupper($value));
  489. if(!empty($where) && $flag == 0)
  490. $this->CI->db->where($where[0], $where[1]);
  491. $this->CI->db->or_where($searchField.$qopers['cn'], '%'.ucfirst($value));
  492. if(!empty($where) && $flag == 0)
  493. $this->CI->db->where($where[0], $where[1]);
  494. $this->CI->db->or_where($searchField.$qopers['cn'], '%'.ucwords($value));
  495. if(!empty($where) && $flag == 0)
  496. $this->CI->db->where($where[0], $where[1]);
  497. $this->CI->db->or_where($searchField.$qopers['cn'], $value.'%');
  498. if(!empty($where) && $flag == 0)
  499. $this->CI->db->where($where[0], $where[1]);
  500. $this->CI->db->or_where($searchField.$qopers['cn'], strtoupper($value).'%');
  501. if(!empty($where) && $flag == 0)
  502. $this->CI->db->where($where[0], $where[1]);
  503. $this->CI->db->or_where($searchField.$qopers['cn'], ucfirst($value).'%');
  504. if(!empty($where) && $flag == 0)
  505. $this->CI->db->where($where[0], $where[1]);
  506. $this->CI->db->or_where($searchField.$qopers['cn'], ucwords($value).'%');
  507. if(!empty($where) && $flag == 0)
  508. $this->CI->db->where($where[0], $where[1]);
  509. $this->CI->db->or_where($searchField.$qopers['cn'], '%'.$value.'%');
  510. if(!empty($where) && $flag == 0)
  511. $this->CI->db->where($where[0], $where[1]);
  512. $this->CI->db->or_where($searchField.$qopers['cn'], '%'.strtoupper($value).'%');
  513. if(!empty($where) && $flag == 0)
  514. $this->CI->db->where($where[0], $where[1]);
  515. $this->CI->db->or_where($searchField.$qopers['cn'], '%'.ucfirst($value).'%');
  516. if(!empty($where) && $flag == 0)
  517. $this->CI->db->where($where[0], $where[1]);
  518. $this->CI->db->or_where($searchField.$qopers['cn'], '%'.ucwords($value).'%');
  519. if(!empty($where) && $flag == 0)
  520. $this->CI->db->where($where[0], $where[1]);
  521. break;
  522. case "nc":
  523. if($flag != 0)
  524. $searchString = $searchString2;
  525. $this->CI->db->where($searchField.$qopers['nc'], '%'.$searchString.'%');
  526. break;
  527. }
  528. }
  529. }
  530. switch($flag){
  531. case 1:
  532. $query = $this->CI->db->get($tabla1);
  533. if($query->num_rows() > 0){
  534. foreach ($query->result() as $fila){
  535. $ids[] = $fila->$searchField2;
  536. }
  537. $this->CI->db->select($seleccion);
  538. $countIds = count($ids);
  539. $idsModificado = array_slice($ids, 1, $countIds-1);
  540. $this->CI->db->where($fkey, $ids[0]);
  541. if(!empty($where))
  542. $this->CI->db->where($where[0], $where[1]);
  543. foreach($idsModificado as $key => $value){
  544. $this->CI->db->or_where($fkey, $value);
  545. if(!empty($where))
  546. $this->CI->db->where($where[0], $where[1]);
  547. }
  548. }
  549. else return array();
  550. break;
  551. case 2:
  552. $query = $this->CI->db->get($tabla1);
  553. if($query->num_rows() > 0){
  554. foreach ($query->result() as $fila){
  555. $ids[] = $fila->$searchField2;
  556. }
  557. $this->CI->db->select($campo21);
  558. $countIds = count($ids);
  559. $idsModificado = array_slice($ids, 1, $countIds-1);
  560. $this->CI->db->where($campo22, $ids[0]);
  561. foreach($idsModificado as $key => $value){
  562. $this->CI->db->or_where($campo22, $value);
  563. }
  564. $query2 = $this->CI->db->get($tabla2);
  565. if($query2->num_rows() > 0){
  566. foreach ($query2->result() as $fila){
  567. $ids2[] = $fila->$campo21;
  568. }
  569. $this->CI->db->select($seleccion);
  570. $countIds2 = count($ids2);
  571. $ids2Modificado = array_slice($ids2, 1, $countIds2-1);
  572. $this->CI->db->where($fkey, $ids2[0]);
  573. if(!empty($where))
  574. $this->CI->db->where($where[0], $where[1]);
  575. foreach($ids2Modificado as $key => $value){
  576. $this->CI->db->or_where($fkey, $value);
  577. if(!empty($where))
  578. $this->CI->db->where($where[0], $where[1]);
  579. }
  580. }
  581. }
  582. else return array();
  583. break;
  584. case 3:
  585. $query = $this->CI->db->get($tabla1);
  586. if($query->num_rows() > 0){
  587. foreach ($query->result() as $fila){
  588. $ids[] = $fila->$searchField2;
  589. }
  590. $this->CI->db->select($campo21);
  591. $countIds = count($ids);
  592. $idsModificado = array_slice($ids, 1, $countIds-1);
  593. $this->CI->db->where($campo22, $ids[0]);
  594. foreach($idsModificado as $key => $value){
  595. $this->CI->db->or_where($campo22, $value);
  596. }
  597. $query2 = $this->CI->db->get($tabla2);
  598. if($query2->num_rows() > 0){
  599. foreach ($query2->result() as $fila){
  600. $ids2[] = $fila->$campo21;
  601. }
  602. $this->CI->db->select($campo31);
  603. $countIds2 = count($ids2);
  604. $ids2Modificado = array_slice($ids2, 1, $countIds2-1);
  605. $this->CI->db->where($campo32, $ids2[0]);
  606. foreach($ids2Modificado as $key => $value){
  607. $this->CI->db->or_where($campo32, $value);
  608. }
  609. $query3 = $this->CI->db->get($tabla3);
  610. if($query3->num_rows() > 0){
  611. foreach ($query3->result() as $fila){
  612. $ids3[] = $fila->$campo31;
  613. }
  614. $this->CI->db->select($seleccion);
  615. $countIds3 = count($ids3);
  616. $ids3Modificado = array_slice($ids3, 1, $countIds3-1);
  617. $this->CI->db->where($fkey, $ids3[0]);
  618. if(!empty($where))
  619. $this->CI->db->where($where[0], $where[1]);
  620. foreach($ids3Modificado as $key => $value){
  621. $this->CI->db->or_where($fkey, $value);
  622. if(!empty($where))
  623. $this->CI->db->where($where[0], $where[1]);
  624. }
  625. }
  626. }
  627. }
  628. else return array();
  629. break;
  630. case 4:
  631. $query = $this->CI->db->get($tabla1);
  632. if($query->num_rows() > 0){
  633. foreach ($query->result() as $fila){
  634. $ids[] = $fila->$searchField2;
  635. }
  636. $this->CI->db->select($campo21);
  637. $countIds = count($ids);
  638. $idsModificado = array_slice($ids, 1, $countIds-1);
  639. $this->CI->db->where($campo22, $ids[0]);
  640. foreach($idsModificado as $key => $value){
  641. $this->CI->db->or_where($campo22, $value);
  642. }
  643. $query2 = $this->CI->db->get($tabla2);
  644. if($query2->num_rows() > 0){
  645. foreach ($query2->result() as $fila){
  646. $ids2[] = $fila->$campo21;
  647. }
  648. $this->CI->db->select($seleccion);
  649. $countIds2 = count($ids2);
  650. $ids2Modificado = array_slice($ids2, 1, $countIds2-1);
  651. $this->CI->db->where($campo31, $ids2[0]);
  652. if(!empty($where))
  653. $this->CI->db->where($where[0], $where[1]);
  654. foreach($ids2Modificado as $key => $value){
  655. $this->CI->db->or_where($campo31, $value);
  656. if(!empty($where))
  657. $this->CI->db->where($where[0], $where[1]);
  658. }
  659. }
  660. else
  661. return array();
  662. }
  663. break;
  664. case 5:
  665. $query = $this->CI->db->get($tabla1);
  666. if($query->num_rows() > 0){
  667. foreach ($query->result() as $fila){
  668. $ids[] = $fila->$searchField2;
  669. }
  670. $this->CI->db->select($campo21);
  671. $countIds = count($ids);
  672. $idsModificado = array_slice($ids, 1, $countIds-1);
  673. $this->CI->db->where($campo22, $ids[0]);
  674. foreach($idsModificado as $key => $value){
  675. $this->CI->db->or_where($campo22, $value);
  676. }
  677. $query2 = $this->CI->db->get($tabla2);
  678. if($query2->num_rows() > 0){
  679. foreach ($query2->result() as $fila){
  680. $ids2[] = $fila->$campo21;
  681. }
  682. $this->CI->db->select($campo31);
  683. $countIds2 = count($ids2);
  684. $ids2Modificado = array_slice($ids2, 1, $countIds2-1);
  685. $this->CI->db->where($campo32, $ids2[0]);
  686. foreach($ids2Modificado as $key => $value){
  687. $this->CI->db->or_where($campo32, $value);
  688. }
  689. $query3 = $this->CI->db->get($tabla3);
  690. if($query3->num_rows() > 0){
  691. foreach ($query3->result() as $fila){
  692. $ids3[] = $fila->$campo31;
  693. }
  694. $this->CI->db->select($seleccion);
  695. $countIds3 = count($ids3);
  696. $ids3Modificado = array_slice($ids3, 1, $countIds3-1);
  697. $this->CI->db->where($campo41, $ids3[0]);
  698. if(!empty($where))
  699. $this->CI->db->where($where[0], $where[1]);
  700. foreach($ids3Modificado as $key => $value){
  701. $this->CI->db->or_where($campo41, $value);
  702. if(!empty($where))
  703. $this->CI->db->where($where[0], $where[1]);
  704. }
  705. }
  706. }
  707. }
  708. else
  709. return array();
  710. break;
  711. case 6:
  712. $query = $this->CI->db->get($tabla1);
  713. if($query->num_rows() > 0){
  714. foreach ($query->result() as $fila){
  715. $ids[] = $fila->$searchField2;
  716. }
  717. $this->CI->db->select($campo21);
  718. $countIds = count($ids);
  719. $idsModificado = array_slice($ids, 1, $countIds-1);
  720. $this->CI->db->where($campo22, $ids[0]);
  721. foreach($idsModificado as $key => $value){
  722. $this->CI->db->or_where($campo22, $value);
  723. }
  724. $query2 = $this->CI->db->get($tabla2);
  725. if($query2->num_rows() > 0){
  726. foreach ($query2->result() as $fila){
  727. $ids2[] = $fila->$campo21;
  728. }
  729. $this->CI->db->select($campo31);
  730. $countIds2 = count($ids2);
  731. $ids2Modificado = array_slice($ids2, 1, $countIds2-1);
  732. $this->CI->db->where($campo32, $ids2[0]);
  733. foreach($ids2Modificado as $key => $value){
  734. $this->CI->db->or_where($campo32, $value);
  735. }
  736. $query3 = $this->CI->db->get($tabla3);
  737. if($query3->num_rows() > 0){
  738. foreach ($query3->result() as $fila){
  739. $ids3[] = $fila->$campo31;
  740. }
  741. $this->CI->db->select($campo41);
  742. $countIds3 = count($ids3);
  743. $ids3Modificado = array_slice($ids3, 1, $countIds3-1);
  744. $this->CI->db->where($campo42, $ids3[0]);
  745. foreach($ids3Modificado as $key => $value){
  746. $this->CI->db->or_where($campo42, $value);
  747. }
  748. $query4 = $this->CI->db->get($tabla4);
  749. if($query4->num_rows() > 0){
  750. foreach ($query4->result() as $fila){
  751. $ids4[] = $fila->$campo41;
  752. }
  753. $this->CI->db->select($seleccion);
  754. $countIds4 = count($ids4);
  755. $ids4Modificado = array_slice($ids4, 1, $countIds4-1);
  756. $this->CI->db->where($campo51, $ids4[0]);
  757. if(!empty($where))
  758. $this->CI->db->where($where[0], $where[1]);
  759. foreach($ids4Modificado as $key => $value){
  760. $this->CI->db->or_where($campo51, $value);
  761. if(!empty($where))
  762. $this->CI->db->where($where[0], $where[1]);
  763. }
  764. }
  765. }
  766. }
  767. }
  768. else
  769. return array();
  770. break;
  771. }
  772. if($flag == 0) $this->CI->db->select($seleccion);
  773. if(!empty($where) && $flag == 0)
  774. $this->CI->db->where($where[0], $where[1]);
  775. if(!is_null($join)){
  776. foreach($join as $key=>$value){
  777. if(count($value)==2)
  778. $this->CI->db->join($join[$key][0],$join[$key][1]);
  779. elseif(count($value)==3)
  780. $this->CI->db->join($join[$key][0],$join[$key][1],$join[$key][2]);
  781. }
  782. }
  783. $this->CI->db->order_by($sidx, $sord);
  784. $this->CI->db->limit($limit, $start);
  785. if(!is_null($distinct)){if($distinct == 1) $this->CI->db->distinct();}
  786. $query = $this->CI->db->get($table);
  787. if($query->num_rows() > 0){
  788. foreach ($query->result() as $fila){
  789. $data[] = $fila;
  790. }
  791. return $data;
  792. }
  793. }
  794. //Metodo que me hace las operaciones CUD (Create, Update, Delete).
  795. function cud($campos, $id, $table, $primaryKey, $oper, $camposMM=null, $camposMM2=null){
  796. foreach ($campos as $key => $value){
  797. if (!empty($value)){
  798. $arrayCampos[$key] = $value;
  799. }
  800. }
  801. if (!isset($oper)){
  802. if(count($primaryKey) == 1)
  803. $this->CI->db->where($primaryKey[0], $id)->update($table, $arrayCampos);
  804. else{
  805. foreach($primaryKey as $key => $value){
  806. $this->CI->db->where($primaryKey[$key], $primaryKey[$value]);
  807. }
  808. $this->CI->db->update($table, $arrayCampos);
  809. }
  810. }
  811. else{
  812. switch($oper){
  813. case 'edit':
  814. $this->CI->db->trans_start();
  815. if(count($primaryKey) == 1)
  816. $this->CI->db->where($primaryKey[0], $id)->update($table, $arrayCampos);
  817. else{
  818. foreach($primaryKey as $key => $value){
  819. $this->CI->db->where($primaryKey[$key], $primaryKey[$value]);
  820. }
  821. $this->CI->db->update($table, $arrayCampos);
  822. }
  823. if(!is_null($camposMM)){
  824. $countCamposMM = count($camposMM);
  825. if($countCamposMM > 1){
  826. for($i=0; $i<$countCamposMM; $i++){
  827. $data = explode(',', $camposMM[$i]['data']);
  828. $this->CI->db->delete($camposMM[$i]['table'], array($camposMM[$i]['campo1'] => $id));
  829. foreach($data as $key => $value){
  830. $dataForUpdate->$camposMM[$i]['campo1'] = $id;
  831. $dataForUpdate->$camposMM[$i]['campo2'] = $value;
  832. $this->CI->db->insert($camposMM[$i]['table'], $dataForUpdate);
  833. unset($dataForUpdate);
  834. }
  835. }
  836. }
  837. else{
  838. $data = explode(',', $camposMM[0]['data']);
  839. $this->CI->db->delete($camposMM[0]['table'], array($camposMM[0]['campo1'] => $id));
  840. foreach($data as $key => $value){
  841. $dataForUpdate->$camposMM[0]['campo1'] = $id;
  842. $dataForUpdate->$camposMM[0]['campo2'] = $value;
  843. $this->CI->db->insert($camposMM[0]['table'], $dataForUpdate);
  844. unset($dataForUpdate);
  845. }
  846. }
  847. }
  848. $this->CI->db->trans_complete();
  849. break;
  850. case 'add':
  851. $this->CI->db->trans_start();
  852. $this->CI->db->insert($table, $arrayCampos);
  853. if(!is_null($camposMM)){
  854. $id = $this->CI->db->insert_id();
  855. $countCamposMM = count($camposMM);
  856. if($countCamposMM > 1){
  857. for($i=0; $i<$countCamposMM; $i++){
  858. $data = explode(',', $camposMM[$i]['data']);
  859. foreach($data as $key => $value){
  860. $dataForInsert->$camposMM[$i]['campo1'] = $id;
  861. $dataForInsert->$camposMM[$i]['campo2'] = $value;
  862. $this->CI->db->insert($camposMM[$i]['table'], $dataForInsert);
  863. unset($dataForInsert);
  864. }
  865. }
  866. }
  867. else{
  868. $data = explode(',', $camposMM[0]['data']);
  869. foreach($data as $key => $value){
  870. $dataForInsert->$camposMM[0]['campo1'] = $id;
  871. $dataForInsert->$camposMM[0]['campo2'] = $value;
  872. $this->CI->db->insert($camposMM[0]['table'], $dataForInsert);
  873. unset($dataForInsert);
  874. }
  875. }
  876. }
  877. if(!is_null($camposMM2)){
  878. $id = $this->CI->db->insert_id();
  879. $countCamposMM2 = count($camposMM2);
  880. if($countCamposMM2 > 1){
  881. for($i=0; $i<$countCamposMM2; $i++){
  882. $dataForInsert->$camposMM2[$i]['campo1'] = $camposMM2[$i]['valor1'];
  883. $dataForInsert->$camposMM2[$i]['campo2'] = $id;
  884. $this->CI->db->insert($camposMM2[$i]['table'], $dataForInsert);
  885. unset($dataForInsert);
  886. }
  887. }
  888. else{
  889. $dataForInsert->$camposMM2[0]['campo1'] = $camposMM2[0]['valor1'];
  890. $dataForInsert->$camposMM2[0]['campo2'] = $id;
  891. $this->CI->db->insert($camposMM2[0]['table'], $dataForInsert);
  892. unset($dataForInsert);
  893. }
  894. }
  895. $this->CI->db->trans_complete();
  896. break;
  897. case 'del':
  898. $count = count($primaryKey);
  899. if($count > 1){
  900. foreach($primaryKey as $key => $value){
  901. $this->CI->db->where($key, $value);
  902. }
  903. $this->CI->db->delete($table);
  904. }
  905. else{
  906. $clauWhere = array($primaryKey[0] => $id);
  907. $this->CI->db->delete($table, $clauWhere);
  908. break;
  909. }
  910. }
  911. }
  912. }
  913. function getNumFilas($table, $where=null, $where2=null){
  914. if(!is_null($where)){
  915. $this->CI->db->where($where[0], $where[1]);
  916. if(!is_null($where2)) $this->CI->db->where($where2[0], $where2[1]);
  917. $this->CI->db->from($table);
  918. return $this->CI->db->count_all_results();
  919. }
  920. else
  921. return $this->CI->db->count_all_results($table);
  922. }
  923. function getRegistrosMM($campo1, $campo2, $idsArreglo, $table, $seleccion, $campo3, $orderBy, $table2){
  924. $countIdsArreglo = count($idsArreglo);
  925. $idsArregloModificado = array_slice($idsArreglo, 1, $countIdsArreglo-1);
  926. $this->CI->db->select($campo1);
  927. $this->CI->db->where($campo2,$idsArreglo[0]);
  928. foreach($idsArregloModificado as $key => $value){
  929. $this->CI->db->or_where($campo2, $value);
  930. }
  931. $this->CI->db->order_by($campo1,'asc');
  932. $query = $this->CI->db->get($table);
  933. if($query->num_rows() > 0){
  934. foreach ($query->result() as $fila) {
  935. $ids[] = $fila->$campo1;
  936. }
  937. $countIds = count($ids);
  938. $idsModificado = array_slice($ids, 1, $countIds-1);
  939. $this->CI->db->select($seleccion);
  940. $this->CI->db->where($campo3, $ids[0]);
  941. foreach($idsModificado as $key => $value){
  942. $this->CI->db->or_where($campo3, $value);
  943. }
  944. $this->CI->db->order_by($orderBy, 'asc');
  945. $query2 = $this->CI->db->get($table2);
  946. if ($query2->num_rows() > 0){
  947. foreach ($query2->result() as $fila) {
  948. $data[] = $fila;
  949. }
  950. return $data;
  951. }
  952. }
  953. else return array();
  954. }
  955. function getRegistrosByIds($ids, $seleccion, $campo1, $orderBy, $table){
  956. $countIds = count($ids);
  957. $idsModificado = array_slice($ids, 1, $countIds-1);
  958. $this->CI->db->select($seleccion);
  959. $this->CI->db->where($campo1, $ids[0]);
  960. foreach($idsModificado as $key => $value){
  961. $this->CI->db->or_where($campo1, $value);
  962. }
  963. $this->CI->db->order_by($orderBy, 'asc');
  964. $query = $this->CI->db->get($table);
  965. if ($query->num_rows() > 0){
  966. foreach ($query->result() as $fila){
  967. $data[] = $fila;
  968. }
  969. return $data;
  970. }
  971. }
  972. function getRegistroById($seleccion, $byCampo, $id, $table, $orderBy=null){
  973. $this->CI->db->select($seleccion);
  974. if(!is_null($byCampo) && !is_null($id))
  975. $this->CI->db->where($byCampo,$id);
  976. if(!is_null($orderBy))
  977. $this->CI->db->order_by($orderBy, 'asc');
  978. $query = $this->CI->db->get($table);
  979. if($query->num_rows() > 0){
  980. foreach ($query->result() as $fila) {
  981. $data[] = $fila;
  982. }
  983. return $data;
  984. }
  985. }
  986. function getAll($seleccion, $table, $orderBy, $where){
  987. $this->CI->db->select($seleccion);
  988. if (!empty($where))
  989. $this->CI->db->where($where[0], $where[1]);
  990. if($orderBy != '')
  991. $this->CI->db->order_by($orderBy,'asc');
  992. $query = $this->CI->db->get($table);
  993. if($query->num_rows() > 0){
  994. foreach ($query->result() as $fila) {
  995. $data[] = $fila;
  996. }
  997. return $data;
  998. }
  999. else return array();
  1000. }
  1001. /*************************Metodo Para cargar select de registros de una relacion un nivel mas arriba de Muchos a Muchos, Ejemplo Obras-Municipios*************************************/
  1002. function cargaSelectSearchMM1($operacion1, $operacion2, $operacion3){
  1003. $ids = array();
  1004. $idsArreglo = array();
  1005. $registros = $this->getAll($operacion1['seleccion'], $operacion1['table'], $operacion1['orderBy'], $operacion1['where']);
  1006. if(count($registros) > 0){
  1007. foreach ($registros as $registro){
  1008. $idsArreglo[] = $registro->$operacion1['seleccion'];
  1009. }
  1010. $registros2 = $this->getRegistrosMM($operacion2['campo1'], $operacion2['campo2'], $idsArreglo, $operacion2['table'], $operacion2['seleccion'], $operacion2['campo3'], $operacion2['orderBy'], $operacion2['table2']);
  1011. foreach ($registros2 as $registro2){
  1012. if (!in_array($registro2->$operacion2['byCampo'], $ids) ){
  1013. $ids[] = $registro2->$operacion2['byCampo'];
  1014. }
  1015. }
  1016. echo '<select>';
  1017. $registros3 = $this->getRegistrosByIds($ids, $operacion3['seleccion'], $operacion3['campo1'], $operacion3['orderBy'], $operacion3['table']);
  1018. $option = explode(',', $operacion3['seleccion']);
  1019. foreach ($registros3 as $registro3){
  1020. echo '<option value="'. $registro3->$option[0] .'">'.$registro3->$option[1].'</option>';
  1021. }
  1022. echo '</select>';
  1023. }
  1024. else echo '<select><option value="">No hay Registros Disponibles</option></select>';
  1025. }
  1026. /*************************Metodo Para cargar select de registros de una relacion un nivel mas arriba de Muchos a Muchos nivel 1, Ejemplo Obras de ejecutores Nivel 4 - Municipios*************************************/
  1027. function cargaSelectSearchMM12($operacion1, $operacion2, $operacion3, $operacion4){
  1028. $ids = array();
  1029. $ids2 = array();
  1030. $idsArreglo = array();
  1031. $registros = $this->getAll($operacion1['seleccion'], $operacion1['table'], $operacion1['orderBy'], $operacion1['where']);
  1032. if(count($registros) > 0){
  1033. foreach ($registros as $registro){
  1034. $idsArreglo[] = $registro->$operacion1['seleccion'];
  1035. }
  1036. $registros2 = $this->getRegistrosMM($operacion2['campo1'], $operacion2['campo2'], $idsArreglo, $operacion2['table'], $operacion2['seleccion'], $operacion2['campo3'], $operacion2['orderBy'], $operacion2['table2']);
  1037. foreach ($registros2 as $registro2){
  1038. if (!in_array($registro2->$operacion2['byCampo'], $ids) ){
  1039. $ids[] = $registro2->$operacion2['byCampo'];
  1040. }
  1041. }
  1042. $registros3 = $this->getRegistrosByIds($ids, $operacion3['seleccion'], $operacion3['campo1'], $operacion3['orderBy'], $operacion3['table']);
  1043. foreach ($registros3 as $registro3){
  1044. if (!in_array($registro3->$operacion3['seleccion'], $ids2) ){
  1045. $ids2[] = $registro3->$operacion3['seleccion'];
  1046. }
  1047. }
  1048. echo '<select>';
  1049. $registros4 = $this->getRegistrosByIds($ids2, $operacion4['seleccion'], $operacion4['campo1'], $operacion4['orderBy'], $operacion4['table']);
  1050. $option = explode(',', $operacion4['seleccion']);
  1051. foreach ($registros4 as $registro4){
  1052. echo '<option value="'. $registro4->$option[0] .'">'.$registro4->$option[1].'</option>';
  1053. }
  1054. echo '</select>';
  1055. }
  1056. else echo '<select><option value="">No hay Registros Disponibles</option></select>';
  1057. }
  1058. /*************************Metodo Para cargar select de registros de una relacion de Muchos a Muchos, Ejemplo Obras-Parroquias*************************************/
  1059. function cargaSelectSearchMM($operacion1, $operacion2, $operacion3){
  1060. $ids = array();
  1061. $arreglo = array();
  1062. $registros = $this->getAll($operacion1['seleccion'], $operacion1['table'], $operacion1['orderBy'], $operacion1['where']);
  1063. if(count($registros) > 0){
  1064. foreach ($registros as $registro) {
  1065. $arreglo[] = $registro->$operacion1['seleccion'];
  1066. }
  1067. $registros2 = $this->getRegistrosMM($operacion2['campo1'], $operacion2['campo2'], $arreglo, $operacion2['table'], $operacion2['seleccion'], $operacion2['campo3'], $operacion2['orderBy'], $operacion2['table2']);
  1068. foreach ($registros2 as $registro2){
  1069. if (!in_array($registro2->$operacion2['byCampo'], $ids) ){
  1070. $ids[] = $registro2->$operacion2['byCampo'];
  1071. }
  1072. }
  1073. echo '<select>';
  1074. $registros3 = $this->getRegistrosByIds($ids, $operacion3['seleccion'], $operacion3['campo1'], $operacion3['orderBy'], $operacion3['table']);
  1075. $option = explode(',', $operacion3['seleccion']);
  1076. foreach ($registros3 as $registro3){
  1077. echo '<option value="'. $registro3->$option[0] .'">'.$registro3->$option[1].'</option>';
  1078. }
  1079. echo '</select>';
  1080. }
  1081. else echo '<select><option value="">No hay Registros Disponibles</option></select>';
  1082. }
  1083. /*************************Metodo Para cargar select de registros de una relacion dos niveles arriba de Muchos a Muchos, Ejemplo Obras-Ejes*************************************/
  1084. function cargaSelectSearchMM2($operacion1, $operacion2, $operacion3, $operacion4){
  1085. $ids = array();
  1086. $ids2 = array();
  1087. $idsArreglo = array();
  1088. $registros = $this->getAll($operacion1['seleccion'], $operacion1['table'], $operacion1['orderBy'], $operacion1['where']);
  1089. if(count($registros) > 0){
  1090. foreach ($registros as $registro) {
  1091. $idsArreglo[] = $registro->$operacion1['seleccion'];
  1092. }
  1093. $registros2 = $this->getRegistrosMM($operacion2['campo1'], $operacion2['campo2'], $idsArreglo, $operacion2['table'], $operacion2['seleccion'], $operacion2['campo3'], $operacion2['orderBy'], $operacion2['table2']);
  1094. foreach ($registros2 as $registro2){
  1095. if (!in_array($registro2->$operacion2['byCampo'], $ids) ){
  1096. $ids[] = $registro2->$operacion2['byCampo'];
  1097. }
  1098. }
  1099. $registros3 = $this->getRegistrosByIds($ids, $operacion3['seleccion'], $operacion3['campo1'], $operacion3['orderBy'], $operacion3['table']);
  1100. foreach ($registros3 as $registro3){
  1101. if (!in_array($registro3->$operacion3['byCampo'], $ids2) ){
  1102. $ids2[] = $registro3->$operacion3['byCampo'];
  1103. }
  1104. }
  1105. echo '<select>';
  1106. $registros4 = $this->getRegistrosByIds($ids2, $operacion4['seleccion'], $operacion4['campo1'], $operacion4['orderBy'], $operacion4['table']);
  1107. $option = explode(',', $operacion4['seleccion']);
  1108. foreach ($registros4 as $registro4){
  1109. echo '<option value="'. $registro4->$option[0] .'">'.$registro4->$option[1].'</option>';
  1110. }
  1111. echo '</select>';
  1112. }
  1113. else echo '<select><option value="">No hay Registros Disponibles</option></select>';
  1114. }
  1115. /*************************Metodo Para cargar select de registros de una relacion un nivel arriba de Muchos a Muchos Nivel 2, Ejemplo Obras de ejecutores nivel 4 - Ejes*************************************/
  1116. function cargaSelectSearchMM22($operacion1, $operacion2, $operacion3, $operacion4, $operacion5){
  1117. $ids = array();
  1118. $ids2 = array();
  1119. $ids3 = array();
  1120. $idsArreglo = array();
  1121. $registros = $this->getAll($operacion1['seleccion'], $operacion1['table'], $operacion1['orderBy'], $operacion1['where']);
  1122. if(count($registros) > 0){
  1123. foreach ($registros as $registro) {
  1124. $idsArreglo[] = $registro->$operacion1['seleccion'];
  1125. }
  1126. $registros2 = $this->getRegistrosMM($operacion2['campo1'], $operacion2['campo2'], $idsArreglo, $operacion2['table'], $operacion2['seleccion'], $operacion2['campo3'], $operacion2['orderBy'], $operacion2['table2']);
  1127. foreach ($registros2 as $registro2){
  1128. if (!in_array($registro2->$operacion2['byCampo'], $ids) ){
  1129. $ids[] = $registro2->$operacion2['byCampo'];
  1130. }
  1131. }
  1132. $registros3 = $this->getRegistrosByIds($ids, $operacion3['seleccion'], $operacion3['campo1'], $operacion3['orderBy'], $operacion3['table']);
  1133. foreach ($registros3 as $registro3){
  1134. if (!in_array($registro3->$operacion3['byCampo'], $ids2) ){
  1135. $ids2[] = $registro3->$operacion3['byCampo'];
  1136. }
  1137. }
  1138. $registros4 = $this->getRegistrosByIds($ids2, $operacion4['seleccion'], $operacion4['campo1'], $operacion4['orderBy'], $operacion4['table']);
  1139. foreach ($registros4 as $registro4){
  1140. if (!in_array($registro4->$operacion4['byCampo'], $ids3) ){
  1141. $ids3[] = $registro4->$operacion4['byCampo'];
  1142. }
  1143. }
  1144. echo '<select>';
  1145. $registros5 = $this->getRegistrosByIds($ids3, $operacion5['seleccion'], $operacion5['campo1'], $operacion5['orderBy'], $operacion5['table']);
  1146. $option = explode(',', $operacion5['seleccion']);
  1147. foreach ($registros5 as $registro5){
  1148. echo '<option value="'. $registro5->$option[0] .'">'.$registro5->$option[1].'</option>';
  1149. }
  1150. echo '</select>';
  1151. }
  1152. else echo '<select><option value="">No hay Registros Disponibles</option></select>';
  1153. }
  1154. function cargaSelectSearchNM($operacion1, $operacion2){
  1155. $ids = array();
  1156. $registros = $this->getAll($operacion1['seleccion'], $operacion1['table'], $operacion1['orderBy'], $operacion1['where']);
  1157. $count = count($registros);
  1158. if($count == 0){
  1159. echo '<select><option value="">No hay registros</option></select>';
  1160. }
  1161. else{
  1162. foreach ($registros as $registro){
  1163. $registros2 = $this->getRegistroById($operacion2['seleccion'], $operacion2['byCampo'], $registro->$operacion1['byCampo'], $operacion2['table']);
  1164. foreach ($registros2 as $registro2){
  1165. if (!in_array($registro2->$operacion2['byCampo'], $ids) ){
  1166. $ids[] = $registro2->$operacion2['byCampo'];
  1167. }
  1168. }
  1169. }
  1170. echo '<select>';
  1171. $registros3 = $this->getRegistrosByIds($ids, $operacion2['seleccion'], $operacion2['byCampo'], $operacion2['orderBy'], $operacion2['table']);
  1172. $option = explode(',', $operacion2['seleccion']);
  1173. foreach ($registros3 as $registro3){
  1174. echo '<option value="'. $registro3->$option[0] .'">'.$registro3->$option[1].'</option>';
  1175. }
  1176. echo '</select>';
  1177. }
  1178. }
  1179. function cargaSelectEdit($arrayForGetAll){
  1180. $registros = $this->getAll($arrayForGetAll['seleccion'], $arrayForGetAll['table'], $arrayForGetAll['orderBy'], $arrayForGetAll['where']);
  1181. $option = explode(',', $arrayForGetAll['seleccion']);
  1182. echo '<select>';
  1183. echo '<option value="">SELECCIONE</option>';
  1184. foreach($registros as $registro){
  1185. echo '<option value="'. $registro->$option[0] .'">'.$registro->$option[1].'</option>';
  1186. }
  1187. echo '</select>';
  1188. }
  1189. function getOptionsSelected($operacion1, $operacion2){
  1190. $ids = $this->getRegistroById($operacion1['seleccion'], $operacion1['byCampo'], $operacion1['id'], $operacion1['table'], $operacion1['orderBy']);
  1191. $registros = $this->getAll($operacion2['seleccion'], $operacion2['table'], $operacion2['orderBy'], $operacion2['where']);
  1192. $option = explode(',',$operacion2['seleccion']);
  1193. foreach ($registros as $registro){
  1194. $cadena = "<option value='".$registro->$option[0]."'";
  1195. foreach ($ids as $id) {
  1196. if($registro->$option[0] == $id->$operacion1['seleccion']){
  1197. $cadena .= " selected ";
  1198. }
  1199. }
  1200. $cadena .= ">".$registro->$option[1]."</option>";
  1201. echo $cadena;
  1202. }
  1203. }
  1204. function getLastId($table){
  1205. $query = $this->CI->db->query('SELECT max(id) as maxi FROM '.$table);
  1206. if ($query->num_rows() > 0){
  1207. foreach ($query->result() as $fila) {
  1208. $max = $fila->maxi;
  1209. }
  1210. return $max;
  1211. }
  1212. }
  1213. function getRows($sql){
  1214. $query = $this->CI->db->query($sql);
  1215. if ($query->num_rows() > 0){
  1216. foreach ($query->result() as $fila) {
  1217. $rows[] = $fila;
  1218. }
  1219. return $rows;
  1220. }else return array();
  1221. }
  1222. function getRow($sql){
  1223. $query = $this->CI->db->query($sql);
  1224. $row=array();
  1225. if ($query->num_rows() > 0)
  1226. $row = $query->row_array();
  1227. return $row;
  1228. }
  1229. function getOptionsForSelect($data, $keyOnValue=false, $optionSelected=false){
  1230. $query=$this->CI->db->query($data['SQL']);
  1231. if($query->num_rows()>0){
  1232. $options = "<option value=''>SELECCIONE</option>";
  1233. foreach($query->result() AS $fila ){
  1234. if($optionSelected != false){
  1235. if($fila->$data['KEY'] == $optionSelected)
  1236. $cierre = " selected>";
  1237. else
  1238. $cierre = " >";
  1239. }
  1240. else
  1241. $cierre = " >";
  1242. if($keyOnValue)
  1243. $options .= "<option value='".$fila->$data['KEY']."' $cierre".$fila->$data['KEY'].' '.$fila->$data['VALUE']."</option>";
  1244. else
  1245. $options .= "<option value='".$fila->$data['KEY']."' $cierre".$fila->$data['VALUE']."</option>";
  1246. }
  1247. }else $options = "<option value=''>NO HAY REGISTROS DISPONIBLES</option>";
  1248. return $options;
  1249. }
  1250. function mayusculas($string){
  1251. return strtr(strtoupper($string), array(
  1252. "à" => "À",
  1253. "è" => "È",
  1254. "ì" => "Ì",
  1255. "ò" => "Ò",
  1256. "ù" => "Ù",
  1257. "á" => "Á",
  1258. "é" => "É",
  1259. "í" => "Í",
  1260. "ó" => "Ó",
  1261. "ú" => "Ú",
  1262. "â" => "Â",
  1263. "ê" => "Ê",
  1264. "î" => "Î",
  1265. "ô" => "Ô",
  1266. "û" => "Û",
  1267. "ç" => "Ç",
  1268. ));
  1269. }
  1270. function login($username, $password){
  1271. $query = $this->CI->db->get_where('usuario', array('login' => $username, 'password' => $password));
  1272. if($query->num_rows()>0){
  1273. $this->CI->session->sess_destroy();
  1274. $this->CI->session->sess_create();
  1275. $query2 = $this->CI->db->get_where('institucion', array('id' => $query->row()->id_institucion));
  1276. $arrayCampos = array('id' => $this->CI->session->userdata('session_id'), 'id_usuario' => $query->row()->id, 'entrada' => date("Y-n-j H:i:s"), 'ip' => $this->CI->session->userdata('ip_address'), 'navegador' => $this->CI->session->userdata('user_agent'));
  1277. $this->CI->db->insert('sesion', $arrayCampos);
  1278. $this->CI->session->set_userdata(array(
  1279. 'ingresado' => true,
  1280. 'login' => $username,
  1281. 'id_usuario' => $query->row()->id,
  1282. 'username' => $query->row()->nombre,
  1283. 'nivel' => $query->row()->nivel,
  1284. 'id-institucion' => $query->row()->id_institucion,
  1285. 'institucion' => $query2->row()->nombre,
  1286. 'siglas' => $query2->row()->siglas
  1287. ));
  1288. return true;
  1289. }
  1290. else
  1291. return false;
  1292. }
  1293. function logout(){
  1294. $this->CI->session->sess_destroy();
  1295. $arrayCampos = array('salida' => date("Y-n-j H:i:s"), 'ultima_actividad' => $this->CI->session->userdata('last_activity'));
  1296. $this->CI->db->where('id', $this->CI->session->userdata('session_id'))->update('sesion', $arrayCampos);
  1297. }
  1298. }
  1299. ?>