/kernelActividades/application/libraries/Atajo.php
PHP | 1331 lines | 1248 code | 31 blank | 52 comment | 273 complexity | c9484fe435c298ece7ce6faf241dd9c1 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0
- <?php
- if ( ! defined('BASEPATH')) exit('No se vista que no va xD');
- /**
- En esta clase se encuentran metodos que facilitan la vida para trabajar de forma integrada con el framework
- php CodeIgniter y el framework jqGrid.
- */
- /**
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- <http://www.gnu.org/licenses/>.
- *********************************************************************************
- Este programa es software libre: usted puede redistribuirlo y / o modificar
- * Bajo los términos de la GNU General Public License publicada por
- * la Free Software Foundation, bien de la versión 3 de la Licencia, o
- * cualquier versión posterior.
- *
- * Este programa se distribuye con la esperanza de que sea útil,
- * pero SIN NINGUNA GARANTÍA, incluso sin la garantía implícita de
- * COMERCIALIZACIÓN o IDONEIDAD PARA UN PROPÓSITO PARTICULAR. Consulte la
- * Licencia Pública General GNU para más detalles.
- <http://www.gnu.org/licenses/>.
- *
- * @author Manuel Alejandro Marquez Ortiz <punketo28@gmail.com>
- * A.K.A. @punketo28
- * @date 2011/01/07
- */
- class Atajo
- {
- function __construct()
- {
- $this->CI = & get_instance();
- }
-
- /*Metodo copiado de los demos de jqGrid con algunas adaptaciones para validar que un dato introducido por
- el usuario sea integer, float o string si asi es requerido por la aplicacion.
- */
- function datoCompatible($dato, $tipo){
- // we need here more advanced checking using the type of the field - i.e. integer, string, float
- switch($tipo){
- case 'i':
- return intval($dato);//intval() Obtiene el valor entero de una variable
- break;
- case 'f':
- return floatval($dato);//floatval() Obtiene el valor flotante de una variable
- break;
- case 's':
- return addslashes($dato); //addslashes() Añade barras invertidas a los caracteres ('),("),(\),(nul) que esten dentro de la cadena.
- break;
- }
- }
- //Metodo que me construye el Grid junto con el modulo de busqueda avanzada de jqGrid.
- 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){
- $qopers = array(//Aqui se crea un array cuyos elementos son las opciones del array sopt.
- 'ne'=>" != ",
- 'lt'=>" < ",
- 'le'=>" <= ",
- 'gt'=>" > ",
- 'ge'=>" >= ",
- 'bw'=>" LIKE ",
- 'bn'=>" NOT LIKE ",
- 'ew'=>" LIKE ",
- 'en'=>" NOT LIKE ",
- 'cn'=>" LIKE " ,
- 'nc'=>" NOT LIKE "
- );
- $flag = 0;
- if ($searchFlag == 'true'){
- if($searchString && $searchOper){
- if (!is_null($apuntadorSearchNM)){
- $countApuntadorNM = count($apuntadorSearchNM);
- if($countApuntadorNM > 1){
- for($i=0; $i<$countApuntadorNM; $i++){
- if ($searchField == $apuntadorSearchNM[$i]['campo']){
- $query = $this->CI->db->select($apuntadorSearchNM[$i]['campo11'])->where($apuntadorSearchNM[$i]['campo12'], $searchString)->get($apuntadorSearchNM[$i]['tabla1']);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila){
- $searchString2 = $fila->$apuntadorSearchNM[$i]['campo11'];
- }
- }
- $this->CI->db->select($apuntadorSearchNM[$i]['campo12']);
- $searchField = $apuntadorSearchNM[$i]['campo11'];
- $flag = 1;
- $searchField2 = $apuntadorSearchNM[$i]['campo12'];
- $tabla1 = $apuntadorSearchNM[$i]['tabla1'];
- $fkey = $apuntadorSearchNM[$i]['campo'];
- }
- }
- }
- else{
- if ($searchField == $apuntadorSearchNM[0]['campo']){
- $query = $this->CI->db->select($apuntadorSearchNM[0]['campo11'])->where($apuntadorSearchNM[0]['campo12'], $searchString)->get($apuntadorSearchNM[0]['tabla1']);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila){
- $searchString2 = $fila->$apuntadorSearchNM[0]['campo11'];
- }
- }
- $this->CI->db->select($apuntadorSearchNM[0]['campo12']);
- $searchField = $apuntadorSearchNM[0]['campo11'];
- $flag = 1;
- $searchField2 = $apuntadorSearchNM[0]['campo12'];
- $tabla1 = $apuntadorSearchNM[0]['tabla1'];
- $fkey = $apuntadorSearchNM[0]['campo'];
- }
- }
- }
- /*$apuntadorSearchNM1 = array(
- array('campo' => 'municipio', 'campo11' => 'descripcion', 'campo12' => 'id', 'tabla1' => 'municipio', 'campo21' => 'id', 'campo22' => 'id_municipio', 'tabla2' => 'parroquia', 'campo31' => 'id_parroquia')
- );
- */
- if (!is_null($apuntadorSearchNM1)){
- $countApuntadorNM1 = count($apuntadorSearchNM1);
- if($countApuntadorNM1 > 1){
- for($i=0; $i<$countApuntadorNM1; $i++){
- if ($searchField == $apuntadorSearchNM1[$i]['campo']){
- $query = $this->CI->db->select($apuntadorSearchNM1[$i]['campo11'])->where($apuntadorSearchNM1[$i]['campo12'], $searchString)->get($apuntadorSearchNM1[$i]['tabla1']);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila){
- $searchString2 = $fila->$apuntadorSearchNM1[$i]['campo11'];
- }
- }
- $this->CI->db->select($apuntadorSearchNM1[$i]['campo12']);
- $searchField = $apuntadorSearchNM1[$i]['campo11'];
- $flag = 2;
- $searchField2 = $apuntadorSearchNM1[$i]['campo12'];
- $tabla1 = $apuntadorSearchNM1[$i]['tabla1'];
- $campo21 = $apuntadorSearchNM1[$i]['campo21'];
- $campo22 = $apuntadorSearchNM1[$i]['campo22'];
- $tabla2 = $apuntadorSearchNM1[$i]['tabla2'];
- $fkey = $apuntadorSearchNM1[$i]['campo31'];
- }
- }
- }
- else{
- if ($searchField == $apuntadorSearchNM1[0]['campo']){
- $query = $this->CI->db->select($apuntadorSearchNM1[0]['campo11'])->where($apuntadorSearchNM1[0]['campo12'], $searchString)->get($apuntadorSearchNM1[0]['tabla1']);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila){
- $searchString2 = $fila->$apuntadorSearchNM1[0]['campo11'];
- }
- }
- $this->CI->db->select($apuntadorSearchNM1[0]['campo12']);
- $searchField = $apuntadorSearchNM1[0]['campo11'];
- $flag = 2;
- $searchField2 = $apuntadorSearchNM1[0]['campo12'];
- $tabla1 = $apuntadorSearchNM1[0]['tabla1'];
- $campo21 = $apuntadorSearchNM1[0]['campo21'];
- $campo22 = $apuntadorSearchNM1[0]['campo22'];
- $tabla2 = $apuntadorSearchNM1[0]['tabla2'];
- $fkey = $apuntadorSearchNM1[0]['campo31'];
- }
- }
- }
-
- /*$apuntadorSearchNM2 = array(
- 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')
- );*/
- if (!is_null($apuntadorSearchNM2)){
- $countApuntadorNM2 = count($apuntadorSearchNM2);
- if($countApuntadorNM2 > 1){
- for($i=0; $i<$countApuntadorNM2; $i++){
- if ($searchField == $apuntadorSearchNM2[$i]['campo']){
- $query = $this->CI->db->select($apuntadorSearchNM2[$i]['campo11'])->where($apuntadorSearchNM2[$i]['campo12'], $searchString)->get($apuntadorSearchNM2[$i]['tabla1']);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila){
- $searchString2 = $fila->$apuntadorSearchNM2[$i]['campo11'];
- }
- }
- $this->CI->db->select($apuntadorSearchNM2[$i]['campo12']);
- $searchField = $apuntadorSearchNM2[$i]['campo11'];
- $flag = 3;
- $searchField2 = $apuntadorSearchNM2[$i]['campo12'];
- $tabla1 = $apuntadorSearchNM2[$i]['tabla1'];
- $campo21 = $apuntadorSearchNM2[$i]['campo21'];
- $campo22 = $apuntadorSearchNM2[$i]['campo22'];
- $tabla2 = $apuntadorSearchNM2[$i]['tabla2'];
- $campo31 = $apuntadorSearchNM2[$i]['campo31'];
- $campo32 = $apuntadorSearchNM2[$i]['campo32'];
- $tabla3 = $apuntadorSearchNM2[$i]['tabla3'];
- $fkey = $apuntadorSearchNM2[$i]['campo41'];
- }
- }
- }
- else{
- if ($searchField == $apuntadorSearchNM2[0]['campo']){
- $query = $this->CI->db->select($apuntadorSearchNM2[0]['campo11'])->where($apuntadorSearchNM2[0]['campo12'], $searchString)->get($apuntadorSearchNM2[0]['tabla1']);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila){
- $searchString2 = $fila->$apuntadorSearchNM2[0]['campo11'];
- }
- }
- $this->CI->db->select($apuntadorSearchNM2[0]['campo12']);
- $searchField = $apuntadorSearchNM2[0]['campo11'];
- $flag = 3;
- $searchField2 = $apuntadorSearchNM2[0]['campo12'];
- $tabla1 = $apuntadorSearchNM2[0]['tabla1'];
- $campo21 = $apuntadorSearchNM2[0]['campo21'];
- $campo22 = $apuntadorSearchNM2[0]['campo22'];
- $tabla2 = $apuntadorSearchNM2[0]['tabla2'];
- $campo31 = $apuntadorSearchNM2[0]['campo31'];
- $campo32 = $apuntadorSearchNM2[0]['campo32'];
- $tabla3 = $apuntadorSearchNM2[0]['tabla3'];
- $fkey = $apuntadorSearchNM2[0]['campo41'];
- }
- }
- }
-
- if (!is_null($apuntadorSearchMM)){
- $countApuntadorMM = count($apuntadorSearchMM);
- if($countApuntadorMM > 1){
- for($i=0; $i<$countApuntadorMM; $i++){
- if ($searchField == $apuntadorSearchMM[$i]['campo']){
- $query = $this->CI->db->select($apuntadorSearchMM[$i]['campo11'])->where($apuntadorSearchMM[$i]['campo12'], $searchString)->get($apuntadorSearchMM[$i]['tabla1']);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila){
- $searchString2 = $fila->$apuntadorSearchMM[$i]['campo11'];
- }
- }
- $this->CI->db->select($apuntadorSearchMM[$i]['campo12']);
- $searchField = $apuntadorSearchMM[$i]['campo11'];
- $flag = 4;
- $searchField2 = $apuntadorSearchMM[$i]['campo12'];
- $tabla1 = $apuntadorSearchMM[$i]['tabla1'];
- $campo21 = $apuntadorSearchMM[$i]['campo21'];
- $campo22 = $apuntadorSearchMM[$i]['campo22'];
- $tabla2 = $apuntadorSearchMM[$i]['tabla2'];
- $campo31 = $apuntadorSearchMM[$i]['campo31'];
- }
- }
- }
- else{
- if($searchField == $apuntadorSearchMM[0]['campo']){
- $query = $this->CI->db->select($apuntadorSearchMM[0]['campo11'])->where($apuntadorSearchMM[0]['campo12'], $searchString)->get($apuntadorSearchMM[0]['tabla1']);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila){
- $searchString2 = $fila->$apuntadorSearchMM[0]['campo11'];
- }
- }
- $this->CI->db->select($apuntadorSearchMM[0]['campo12']);
- $searchField = $apuntadorSearchMM[0]['campo11'];
- $flag = 4;
- $searchField2 = $apuntadorSearchMM[0]['campo12'];
- $tabla1 = $apuntadorSearchMM[0]['tabla1'];
- $campo21 = $apuntadorSearchMM[0]['campo21'];
- $campo22 = $apuntadorSearchMM[0]['campo22'];
- $tabla2 = $apuntadorSearchMM[0]['tabla2'];
- $campo31 = $apuntadorSearchMM[0]['campo31'];
- }
- }
- }
-
- if (!is_null($apuntadorSearchMM1)){
- $countApuntadorMM1 = count($apuntadorSearchMM1);
- if($countApuntadorMM1 > 1){
- for($i=0; $i<$countApuntadorMM1; $i++){
- if ($searchField == $apuntadorSearchMM1[$i]['campo']){
- $query = $this->CI->db->select($apuntadorSearchMM1[$i]['campo11'])->where($apuntadorSearchMM1[$i]['campo12'], $searchString)->get($apuntadorSearchMM1[$i]['tabla1']);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila){
- $searchString2 = $fila->$apuntadorSearchMM1[$i]['campo11'];
- }
- }
- $this->CI->db->select($apuntadorSearchMM1[$i]['campo12']);
- $searchField = $apuntadorSearchMM1[$i]['campo11'];
- $flag = 5;
- $searchField2 = $apuntadorSearchMM1[$i]['campo12'];
- $tabla1 = $apuntadorSearchMM1[$i]['tabla1'];
- $campo21 = $apuntadorSearchMM1[$i]['campo21'];
- $campo22 = $apuntadorSearchMM1[$i]['campo22'];
- $tabla2 = $apuntadorSearchMM1[$i]['tabla2'];
- $campo31 = $apuntadorSearchMM1[$i]['campo31'];
- $campo32 = $apuntadorSearchMM1[$i]['campo32'];
- $tabla3 = $apuntadorSearchMM1[$i]['tabla3'];
- $campo41 = $apuntadorSearchMM1[$i]['campo41'];
- }
- }
- }
- else{
- if ($searchField == $apuntadorSearchMM1[0]['campo']){
- $query = $this->CI->db->select($apuntadorSearchMM1[0]['campo11'])->where($apuntadorSearchMM1[0]['campo12'], $searchString)->get($apuntadorSearchMM1[0]['tabla1']);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila){
- $searchString2 = $fila->$apuntadorSearchMM1[0]['campo11'];
- }
- }
- $this->CI->db->select($apuntadorSearchMM1[0]['campo12']);
- $searchField = $apuntadorSearchMM1[0]['campo11'];
- $flag = 5;
- $searchField2 = $apuntadorSearchMM1[0]['campo12'];
- $tabla1 = $apuntadorSearchMM1[0]['tabla1'];
- $campo21 = $apuntadorSearchMM1[0]['campo21'];
- $campo22 = $apuntadorSearchMM1[0]['campo22'];
- $tabla2 = $apuntadorSearchMM1[0]['tabla2'];
- $campo31 = $apuntadorSearchMM1[0]['campo31'];
- $campo32 = $apuntadorSearchMM1[0]['campo32'];
- $tabla3 = $apuntadorSearchMM1[0]['tabla3'];
- $campo41 = $apuntadorSearchMM1[0]['campo41'];
- }
- }
- }
- if (!is_null($apuntadorSearchMM2)){
- $countApuntadorMM2 = count($apuntadorSearchMM2);
- if($countApuntadorMM2 > 1){
- for($i=0; $i<$countApuntadorMM2; $i++){
- if ($searchField == $apuntadorSearchMM2[$i]['campo']){
- $query = $this->CI->db->select($apuntadorSearchMM2[$i]['campo11'])->where($apuntadorSearchMM2[$i]['campo12'], $searchString)->get($apuntadorSearchMM2[$i]['tabla1']);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila){
- $searchString2 = $fila->$apuntadorSearchMM2[$i]['campo11'];
- }
- }
- $this->CI->db->select($apuntadorSearchMM2[$i]['campo12']);
- $searchField = $apuntadorSearchMM2[$i]['campo11'];
- $flag = 6;
- $searchField2 = $apuntadorSearchMM2[$i]['campo12'];
- $tabla1 = $apuntadorSearchMM2[$i]['tabla1'];
- $campo21 = $apuntadorSearchMM2[$i]['campo21'];
- $campo22 = $apuntadorSearchMM2[$i]['campo22'];
- $tabla2 = $apuntadorSearchMM2[$i]['tabla2'];
- $campo31 = $apuntadorSearchMM2[$i]['campo31'];
- $campo32 = $apuntadorSearchMM2[$i]['campo32'];
- $tabla3 = $apuntadorSearchMM2[$i]['tabla3'];
- $campo41 = $apuntadorSearchMM2[$i]['campo41'];
- $campo42 = $apuntadorSearchMM2[$i]['campo42'];
- $tabla4 = $apuntadorSearchMM2[$i]['tabla4'];
- $campo51 = $apuntadorSearchMM2[$i]['campo51'];
- }
- }
- }
- else{
- if ($searchField == $apuntadorSearchMM2[0]['campo']){
- $query = $this->CI->db->select($apuntadorSearchMM2[0]['campo11'])->where($apuntadorSearchMM2[0]['campo12'], $searchString)->get($apuntadorSearchMM2[0]['tabla1']);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila){
- $searchString2 = $fila->$apuntadorSearchMM2[0]['campo11'];
- }
- }
- $this->CI->db->select($apuntadorSearchMM2[0]['campo12']);
- $searchField = $apuntadorSearchMM2[0]['campo11'];
- $flag = 6;
- $searchField2 = $apuntadorSearchMM2[0]['campo12'];
- $tabla1 = $apuntadorSearchMM2[0]['tabla1'];
- $campo21 = $apuntadorSearchMM2[0]['campo21'];
- $campo22 = $apuntadorSearchMM2[0]['campo22'];
- $tabla2 = $apuntadorSearchMM2[0]['tabla2'];
- $campo31 = $apuntadorSearchMM2[0]['campo31'];
- $campo32 = $apuntadorSearchMM2[0]['campo32'];
- $tabla3 = $apuntadorSearchMM2[0]['tabla3'];
- $campo41 = $apuntadorSearchMM2[0]['campo41'];
- $campo42 = $apuntadorSearchMM2[0]['campo42'];
- $tabla4 = $apuntadorSearchMM2[0]['tabla4'];
- $campo51 = $apuntadorSearchMM2[0]['campo51'];
- }
- }
- }
-
- switch ($searchOper){
- case "eq":
- if($flag != 0)
- $searchField = $searchField2;
- $this->CI->db->where($searchField, $searchString);
- break;
- case "ne":
- if($flag != 0)
- $searchField = $searchField2;
- $this->CI->db->where($searchField.$qopers['ne'], $searchString);
- break;
- case "lt":
- if($flag != 0)
- $searchString = $searchString2;
- $this->CI->db->where($searchField.$qopers['lt'], $searchString);
- break;
- case "le":
- if($flag != 0)
- $searchString = $searchString2;
- $this->CI->db->where($searchField.$qopers['le'], $searchString);
- break;
- case "gt":
- if($flag != 0)
- $searchString = $searchString2;
- $this->CI->db->where($searchField.$qopers['gt'], $searchString);
- break;
- case "ge":
- if($flag != 0)
- $searchString = $searchString2;
- $this->CI->db->where($searchField.$qopers['ge'], $searchString);
- break;
- case "bw":
- if($flag != 0)
- $searchString = $searchString2;
- $value = strtolower($searchString);
- $this->CI->db->where($searchField.$qopers['bw'], $value.'%');
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where($searchField.$qopers['bw'], strtoupper($value).'%');
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where($searchField.$qopers['bw'], ucfirst($value).'%');
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where($searchField.$qopers['bw'], ucwords($value).'%');
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- break;
- case "bn":
- if($flag != 0)
- $searchString = $searchString2;
- $this->CI->db->where($searchField.$qopers['bn'], $searchString.'%');
- break;
- case "in":
- if($flag != 0)
- $searchField = $searchField2;
- $valuesArray = explode(",", $searchString);
- foreach ($valuesArray as $key => $valor){
- $valores[] = trim($valor);
- }
- foreach ($valores as $key2 => $valor2){
- $minusculas[] = strtolower($valor2);
- }
- foreach ($valores as $key3 => $valor3){
- $mayusculas[] = strtoupper($valor3);
- }
- foreach ($valores as $key4 => $valor4){
- $ucfirst[] = ucfirst($valor4);
- }
- foreach ($valores as $key5 => $valor5){
- $ucwords[] = ucwords($valor5);
- }
- $this->CI->db->where_in($searchField, $valores);
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where_in($searchField, $minusculas);
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where_in($searchField, $mayusculas);
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where_in($searchField, $ucfirst);
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where_in($searchField, $ucwords);
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- break;
- case "ni":
- if($flag != 0)
- $searchField = $searchField2;
- $valuesArray = explode(",", $searchString);
- foreach ($valuesArray as $key => $valor){
- $valores[] = trim($valor);
- }
- $this->CI->db->where_not_in($searchField, $valores);
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- break;
- case "ew":
- if($flag != 0)
- $searchString = $searchString2;
- $value = strtolower($searchString);
- $this->CI->db->where($searchField.$qopers['ew'], '%'.$value);
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where($searchField.$qopers['ew'], '%'.strtoupper($value));
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where($searchField.$qopers['ew'], '%'.ucfirst($value));
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where($searchField.$qopers['ew'], '%'.ucwords($value));
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- break;
- case "en":
- if($flag != 0)
- $searchString = $searchString2;
- $this->CI->db->where($searchField.$qopers['en'], '%'.$searchString);
- break;
- case "cn":
- if($flag != 0)
- $searchString = $searchString2;
- $value = strtolower($searchString);
- $this->CI->db->where($searchField.$qopers['cn'], '%'.$value);
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where($searchField.$qopers['cn'], '%'.strtoupper($value));
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where($searchField.$qopers['cn'], '%'.ucfirst($value));
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where($searchField.$qopers['cn'], '%'.ucwords($value));
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where($searchField.$qopers['cn'], $value.'%');
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where($searchField.$qopers['cn'], strtoupper($value).'%');
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where($searchField.$qopers['cn'], ucfirst($value).'%');
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where($searchField.$qopers['cn'], ucwords($value).'%');
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where($searchField.$qopers['cn'], '%'.$value.'%');
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where($searchField.$qopers['cn'], '%'.strtoupper($value).'%');
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where($searchField.$qopers['cn'], '%'.ucfirst($value).'%');
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- $this->CI->db->or_where($searchField.$qopers['cn'], '%'.ucwords($value).'%');
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- break;
- case "nc":
- if($flag != 0)
- $searchString = $searchString2;
- $this->CI->db->where($searchField.$qopers['nc'], '%'.$searchString.'%');
- break;
- }
- }
- }
- switch($flag){
- case 1:
- $query = $this->CI->db->get($tabla1);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila){
- $ids[] = $fila->$searchField2;
- }
- $this->CI->db->select($seleccion);
- $countIds = count($ids);
- $idsModificado = array_slice($ids, 1, $countIds-1);
- $this->CI->db->where($fkey, $ids[0]);
- if(!empty($where))
- $this->CI->db->where($where[0], $where[1]);
- foreach($idsModificado as $key => $value){
- $this->CI->db->or_where($fkey, $value);
- if(!empty($where))
- $this->CI->db->where($where[0], $where[1]);
- }
- }
- else return array();
- break;
-
- case 2:
- $query = $this->CI->db->get($tabla1);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila){
- $ids[] = $fila->$searchField2;
- }
- $this->CI->db->select($campo21);
- $countIds = count($ids);
- $idsModificado = array_slice($ids, 1, $countIds-1);
- $this->CI->db->where($campo22, $ids[0]);
- foreach($idsModificado as $key => $value){
- $this->CI->db->or_where($campo22, $value);
- }
- $query2 = $this->CI->db->get($tabla2);
- if($query2->num_rows() > 0){
- foreach ($query2->result() as $fila){
- $ids2[] = $fila->$campo21;
- }
- $this->CI->db->select($seleccion);
- $countIds2 = count($ids2);
- $ids2Modificado = array_slice($ids2, 1, $countIds2-1);
- $this->CI->db->where($fkey, $ids2[0]);
- if(!empty($where))
- $this->CI->db->where($where[0], $where[1]);
- foreach($ids2Modificado as $key => $value){
- $this->CI->db->or_where($fkey, $value);
- if(!empty($where))
- $this->CI->db->where($where[0], $where[1]);
- }
- }
- }
- else return array();
- break;
-
- case 3:
- $query = $this->CI->db->get($tabla1);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila){
- $ids[] = $fila->$searchField2;
- }
- $this->CI->db->select($campo21);
- $countIds = count($ids);
- $idsModificado = array_slice($ids, 1, $countIds-1);
- $this->CI->db->where($campo22, $ids[0]);
- foreach($idsModificado as $key => $value){
- $this->CI->db->or_where($campo22, $value);
- }
- $query2 = $this->CI->db->get($tabla2);
- if($query2->num_rows() > 0){
- foreach ($query2->result() as $fila){
- $ids2[] = $fila->$campo21;
- }
- $this->CI->db->select($campo31);
- $countIds2 = count($ids2);
- $ids2Modificado = array_slice($ids2, 1, $countIds2-1);
- $this->CI->db->where($campo32, $ids2[0]);
- foreach($ids2Modificado as $key => $value){
- $this->CI->db->or_where($campo32, $value);
- }
- $query3 = $this->CI->db->get($tabla3);
- if($query3->num_rows() > 0){
- foreach ($query3->result() as $fila){
- $ids3[] = $fila->$campo31;
- }
- $this->CI->db->select($seleccion);
- $countIds3 = count($ids3);
- $ids3Modificado = array_slice($ids3, 1, $countIds3-1);
- $this->CI->db->where($fkey, $ids3[0]);
- if(!empty($where))
- $this->CI->db->where($where[0], $where[1]);
- foreach($ids3Modificado as $key => $value){
- $this->CI->db->or_where($fkey, $value);
- if(!empty($where))
- $this->CI->db->where($where[0], $where[1]);
- }
- }
- }
- }
- else return array();
- break;
-
- case 4:
- $query = $this->CI->db->get($tabla1);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila){
- $ids[] = $fila->$searchField2;
- }
- $this->CI->db->select($campo21);
- $countIds = count($ids);
- $idsModificado = array_slice($ids, 1, $countIds-1);
- $this->CI->db->where($campo22, $ids[0]);
- foreach($idsModificado as $key => $value){
- $this->CI->db->or_where($campo22, $value);
- }
- $query2 = $this->CI->db->get($tabla2);
- if($query2->num_rows() > 0){
- foreach ($query2->result() as $fila){
- $ids2[] = $fila->$campo21;
- }
- $this->CI->db->select($seleccion);
- $countIds2 = count($ids2);
- $ids2Modificado = array_slice($ids2, 1, $countIds2-1);
- $this->CI->db->where($campo31, $ids2[0]);
- if(!empty($where))
- $this->CI->db->where($where[0], $where[1]);
- foreach($ids2Modificado as $key => $value){
- $this->CI->db->or_where($campo31, $value);
- if(!empty($where))
- $this->CI->db->where($where[0], $where[1]);
- }
- }
- else
- return array();
- }
- break;
-
- case 5:
- $query = $this->CI->db->get($tabla1);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila){
- $ids[] = $fila->$searchField2;
- }
- $this->CI->db->select($campo21);
- $countIds = count($ids);
- $idsModificado = array_slice($ids, 1, $countIds-1);
- $this->CI->db->where($campo22, $ids[0]);
- foreach($idsModificado as $key => $value){
- $this->CI->db->or_where($campo22, $value);
- }
- $query2 = $this->CI->db->get($tabla2);
- if($query2->num_rows() > 0){
- foreach ($query2->result() as $fila){
- $ids2[] = $fila->$campo21;
- }
- $this->CI->db->select($campo31);
- $countIds2 = count($ids2);
- $ids2Modificado = array_slice($ids2, 1, $countIds2-1);
- $this->CI->db->where($campo32, $ids2[0]);
- foreach($ids2Modificado as $key => $value){
- $this->CI->db->or_where($campo32, $value);
- }
- $query3 = $this->CI->db->get($tabla3);
- if($query3->num_rows() > 0){
- foreach ($query3->result() as $fila){
- $ids3[] = $fila->$campo31;
- }
- $this->CI->db->select($seleccion);
- $countIds3 = count($ids3);
- $ids3Modificado = array_slice($ids3, 1, $countIds3-1);
- $this->CI->db->where($campo41, $ids3[0]);
- if(!empty($where))
- $this->CI->db->where($where[0], $where[1]);
- foreach($ids3Modificado as $key => $value){
- $this->CI->db->or_where($campo41, $value);
- if(!empty($where))
- $this->CI->db->where($where[0], $where[1]);
- }
- }
- }
- }
- else
- return array();
- break;
-
- case 6:
- $query = $this->CI->db->get($tabla1);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila){
- $ids[] = $fila->$searchField2;
- }
- $this->CI->db->select($campo21);
- $countIds = count($ids);
- $idsModificado = array_slice($ids, 1, $countIds-1);
- $this->CI->db->where($campo22, $ids[0]);
- foreach($idsModificado as $key => $value){
- $this->CI->db->or_where($campo22, $value);
- }
- $query2 = $this->CI->db->get($tabla2);
- if($query2->num_rows() > 0){
- foreach ($query2->result() as $fila){
- $ids2[] = $fila->$campo21;
- }
- $this->CI->db->select($campo31);
- $countIds2 = count($ids2);
- $ids2Modificado = array_slice($ids2, 1, $countIds2-1);
- $this->CI->db->where($campo32, $ids2[0]);
- foreach($ids2Modificado as $key => $value){
- $this->CI->db->or_where($campo32, $value);
- }
- $query3 = $this->CI->db->get($tabla3);
- if($query3->num_rows() > 0){
- foreach ($query3->result() as $fila){
- $ids3[] = $fila->$campo31;
- }
- $this->CI->db->select($campo41);
- $countIds3 = count($ids3);
- $ids3Modificado = array_slice($ids3, 1, $countIds3-1);
- $this->CI->db->where($campo42, $ids3[0]);
- foreach($ids3Modificado as $key => $value){
- $this->CI->db->or_where($campo42, $value);
- }
- $query4 = $this->CI->db->get($tabla4);
- if($query4->num_rows() > 0){
- foreach ($query4->result() as $fila){
- $ids4[] = $fila->$campo41;
- }
- $this->CI->db->select($seleccion);
- $countIds4 = count($ids4);
- $ids4Modificado = array_slice($ids4, 1, $countIds4-1);
- $this->CI->db->where($campo51, $ids4[0]);
- if(!empty($where))
- $this->CI->db->where($where[0], $where[1]);
- foreach($ids4Modificado as $key => $value){
- $this->CI->db->or_where($campo51, $value);
- if(!empty($where))
- $this->CI->db->where($where[0], $where[1]);
- }
- }
- }
- }
- }
- else
- return array();
- break;
- }
- if($flag == 0) $this->CI->db->select($seleccion);
- if(!empty($where) && $flag == 0)
- $this->CI->db->where($where[0], $where[1]);
- if(!is_null($join)){
- foreach($join as $key=>$value){
- if(count($value)==2)
- $this->CI->db->join($join[$key][0],$join[$key][1]);
- elseif(count($value)==3)
- $this->CI->db->join($join[$key][0],$join[$key][1],$join[$key][2]);
- }
- }
- $this->CI->db->order_by($sidx, $sord);
- $this->CI->db->limit($limit, $start);
- if(!is_null($distinct)){if($distinct == 1) $this->CI->db->distinct();}
- $query = $this->CI->db->get($table);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila){
- $data[] = $fila;
- }
- return $data;
- }
- }
-
- //Metodo que me hace las operaciones CUD (Create, Update, Delete).
- function cud($campos, $id, $table, $primaryKey, $oper, $camposMM=null, $camposMM2=null){
- foreach ($campos as $key => $value){
- if (!empty($value)){
- $arrayCampos[$key] = $value;
- }
- }
- if (!isset($oper)){
- if(count($primaryKey) == 1)
- $this->CI->db->where($primaryKey[0], $id)->update($table, $arrayCampos);
- else{
- foreach($primaryKey as $key => $value){
- $this->CI->db->where($primaryKey[$key], $primaryKey[$value]);
- }
- $this->CI->db->update($table, $arrayCampos);
- }
- }
- else{
- switch($oper){
- case 'edit':
- $this->CI->db->trans_start();
- if(count($primaryKey) == 1)
- $this->CI->db->where($primaryKey[0], $id)->update($table, $arrayCampos);
- else{
- foreach($primaryKey as $key => $value){
- $this->CI->db->where($primaryKey[$key], $primaryKey[$value]);
- }
- $this->CI->db->update($table, $arrayCampos);
- }
- if(!is_null($camposMM)){
- $countCamposMM = count($camposMM);
- if($countCamposMM > 1){
- for($i=0; $i<$countCamposMM; $i++){
- $data = explode(',', $camposMM[$i]['data']);
- $this->CI->db->delete($camposMM[$i]['table'], array($camposMM[$i]['campo1'] => $id));
- foreach($data as $key => $value){
- $dataForUpdate->$camposMM[$i]['campo1'] = $id;
- $dataForUpdate->$camposMM[$i]['campo2'] = $value;
- $this->CI->db->insert($camposMM[$i]['table'], $dataForUpdate);
- unset($dataForUpdate);
- }
- }
- }
- else{
- $data = explode(',', $camposMM[0]['data']);
- $this->CI->db->delete($camposMM[0]['table'], array($camposMM[0]['campo1'] => $id));
- foreach($data as $key => $value){
- $dataForUpdate->$camposMM[0]['campo1'] = $id;
- $dataForUpdate->$camposMM[0]['campo2'] = $value;
- $this->CI->db->insert($camposMM[0]['table'], $dataForUpdate);
- unset($dataForUpdate);
- }
- }
- }
- $this->CI->db->trans_complete();
- break;
- case 'add':
- $this->CI->db->trans_start();
- $this->CI->db->insert($table, $arrayCampos);
- if(!is_null($camposMM)){
- $id = $this->CI->db->insert_id();
- $countCamposMM = count($camposMM);
- if($countCamposMM > 1){
- for($i=0; $i<$countCamposMM; $i++){
- $data = explode(',', $camposMM[$i]['data']);
- foreach($data as $key => $value){
- $dataForInsert->$camposMM[$i]['campo1'] = $id;
- $dataForInsert->$camposMM[$i]['campo2'] = $value;
- $this->CI->db->insert($camposMM[$i]['table'], $dataForInsert);
- unset($dataForInsert);
- }
- }
- }
- else{
- $data = explode(',', $camposMM[0]['data']);
- foreach($data as $key => $value){
- $dataForInsert->$camposMM[0]['campo1'] = $id;
- $dataForInsert->$camposMM[0]['campo2'] = $value;
- $this->CI->db->insert($camposMM[0]['table'], $dataForInsert);
- unset($dataForInsert);
- }
- }
- }
- if(!is_null($camposMM2)){
- $id = $this->CI->db->insert_id();
- $countCamposMM2 = count($camposMM2);
- if($countCamposMM2 > 1){
- for($i=0; $i<$countCamposMM2; $i++){
- $dataForInsert->$camposMM2[$i]['campo1'] = $camposMM2[$i]['valor1'];
- $dataForInsert->$camposMM2[$i]['campo2'] = $id;
- $this->CI->db->insert($camposMM2[$i]['table'], $dataForInsert);
- unset($dataForInsert);
- }
- }
- else{
- $dataForInsert->$camposMM2[0]['campo1'] = $camposMM2[0]['valor1'];
- $dataForInsert->$camposMM2[0]['campo2'] = $id;
- $this->CI->db->insert($camposMM2[0]['table'], $dataForInsert);
- unset($dataForInsert);
- }
- }
- $this->CI->db->trans_complete();
- break;
- case 'del':
- $count = count($primaryKey);
- if($count > 1){
- foreach($primaryKey as $key => $value){
- $this->CI->db->where($key, $value);
- }
- $this->CI->db->delete($table);
- }
- else{
- $clauWhere = array($primaryKey[0] => $id);
- $this->CI->db->delete($table, $clauWhere);
- break;
- }
- }
- }
- }
-
- function getNumFilas($table, $where=null, $where2=null){
- if(!is_null($where)){
- $this->CI->db->where($where[0], $where[1]);
- if(!is_null($where2)) $this->CI->db->where($where2[0], $where2[1]);
- $this->CI->db->from($table);
- return $this->CI->db->count_all_results();
- }
- else
- return $this->CI->db->count_all_results($table);
- }
-
- function getRegistrosMM($campo1, $campo2, $idsArreglo, $table, $seleccion, $campo3, $orderBy, $table2){
- $countIdsArreglo = count($idsArreglo);
- $idsArregloModificado = array_slice($idsArreglo, 1, $countIdsArreglo-1);
- $this->CI->db->select($campo1);
- $this->CI->db->where($campo2,$idsArreglo[0]);
- foreach($idsArregloModificado as $key => $value){
- $this->CI->db->or_where($campo2, $value);
- }
- $this->CI->db->order_by($campo1,'asc');
- $query = $this->CI->db->get($table);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila) {
- $ids[] = $fila->$campo1;
- }
- $countIds = count($ids);
- $idsModificado = array_slice($ids, 1, $countIds-1);
- $this->CI->db->select($seleccion);
- $this->CI->db->where($campo3, $ids[0]);
- foreach($idsModificado as $key => $value){
- $this->CI->db->or_where($campo3, $value);
- }
- $this->CI->db->order_by($orderBy, 'asc');
- $query2 = $this->CI->db->get($table2);
- if ($query2->num_rows() > 0){
- foreach ($query2->result() as $fila) {
- $data[] = $fila;
- }
- return $data;
- }
- }
- else return array();
- }
-
- function getRegistrosByIds($ids, $seleccion, $campo1, $orderBy, $table){
- $countIds = count($ids);
- $idsModificado = array_slice($ids, 1, $countIds-1);
- $this->CI->db->select($seleccion);
- $this->CI->db->where($campo1, $ids[0]);
- foreach($idsModificado as $key => $value){
- $this->CI->db->or_where($campo1, $value);
- }
- $this->CI->db->order_by($orderBy, 'asc');
- $query = $this->CI->db->get($table);
- if ($query->num_rows() > 0){
- foreach ($query->result() as $fila){
- $data[] = $fila;
- }
- return $data;
- }
- }
-
- function getRegistroById($seleccion, $byCampo, $id, $table, $orderBy=null){
- $this->CI->db->select($seleccion);
- if(!is_null($byCampo) && !is_null($id))
- $this->CI->db->where($byCampo,$id);
- if(!is_null($orderBy))
- $this->CI->db->order_by($orderBy, 'asc');
- $query = $this->CI->db->get($table);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila) {
- $data[] = $fila;
- }
- return $data;
- }
- }
-
- function getAll($seleccion, $table, $orderBy, $where){
- $this->CI->db->select($seleccion);
- if (!empty($where))
- $this->CI->db->where($where[0], $where[1]);
- if($orderBy != '')
- $this->CI->db->order_by($orderBy,'asc');
- $query = $this->CI->db->get($table);
- if($query->num_rows() > 0){
- foreach ($query->result() as $fila) {
- $data[] = $fila;
- }
- return $data;
- }
- else return array();
- }
-
- /*************************Metodo Para cargar select de registros de una relacion un nivel mas arriba de Muchos a Muchos, Ejemplo Obras-Municipios*************************************/
- function cargaSelectSearchMM1($operacion1, $operacion2, $operacion3){
- $ids = array();
- $idsArreglo = array();
- $registros = $this->getAll($operacion1['seleccion'], $operacion1['table'], $operacion1['orderBy'], $operacion1['where']);
- if(count($registros) > 0){
- foreach ($registros as $registro){
- $idsArreglo[] = $registro->$operacion1['seleccion'];
- }
- $registros2 = $this->getRegistrosMM($operacion2['campo1'], $operacion2['campo2'], $idsArreglo, $operacion2['table'], $operacion2['seleccion'], $operacion2['campo3'], $operacion2['orderBy'], $operacion2['table2']);
- foreach ($registros2 as $registro2){
- if (!in_array($registro2->$operacion2['byCampo'], $ids) ){
- $ids[] = $registro2->$operacion2['byCampo'];
- }
- }
- echo '<select>';
- $registros3 = $this->getRegistrosByIds($ids, $operacion3['seleccion'], $operacion3['campo1'], $operacion3['orderBy'], $operacion3['table']);
- $option = explode(',', $operacion3['seleccion']);
- foreach ($registros3 as $registro3){
- echo '<option value="'. $registro3->$option[0] .'">'.$registro3->$option[1].'</option>';
- }
- echo '</select>';
- }
- else echo '<select><option value="">No hay Registros Disponibles</option></select>';
- }
-
- /*************************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*************************************/
- function cargaSelectSearchMM12($operacion1, $operacion2, $operacion3, $operacion4){
- $ids = array();
- $ids2 = array();
- $idsArreglo = array();
- $registros = $this->getAll($operacion1['seleccion'], $operacion1['table'], $operacion1['orderBy'], $operacion1['where']);
- if(count($registros) > 0){
- foreach ($registros as $registro){
- $idsArreglo[] = $registro->$operacion1['seleccion'];
- }
- $registros2 = $this->getRegistrosMM($operacion2['campo1'], $operacion2['campo2'], $idsArreglo, $operacion2['table'], $operacion2['seleccion'], $operacion2['campo3'], $operacion2['orderBy'], $operacion2['table2']);
- foreach ($registros2 as $registro2){
- if (!in_array($registro2->$operacion2['byCampo'], $ids) ){
- $ids[] = $registro2->$operacion2['byCampo'];
- }
- }
- $registros3 = $this->getRegistrosByIds($ids, $operacion3['seleccion'], $operacion3['campo1'], $operacion3['orderBy'], $operacion3['table']);
- foreach ($registros3 as $registro3){
- if (!in_array($registro3->$operacion3['seleccion'], $ids2) ){
- $ids2[] = $registro3->$operacion3['seleccion'];
- }
- }
- echo '<select>';
- $registros4 = $this->getRegistrosByIds($ids2, $operacion4['seleccion'], $operacion4['campo1'], $operacion4['orderBy'], $operacion4['table']);
- $option = explode(',', $operacion4['seleccion']);
- foreach ($registros4 as $registro4){
- echo '<option value="'. $registro4->$option[0] .'">'.$registro4->$option[1].'</option>';
- }
- echo '</select>';
- }
- else echo '<select><option value="">No hay Registros Disponibles</option></select>';
- }
- /*************************Metodo Para cargar select de registros de una relacion de Muchos a Muchos, Ejemplo Obras-Parroquias*************************************/
- function cargaSelectSearchMM($operacion1, $operacion2, $operacion3){
- $ids = array();
- $arreglo = array();
- $registros = $this->getAll($operacion1['seleccion'], $operacion1['table'], $operacion1['orderBy'], $operacion1['where']);
- if(count($registros) > 0){
- foreach ($registros as $registro) {
- $arreglo[] = $registro->$operacion1['seleccion'];
- }
- $registros2 = $this->getRegistrosMM($operacion2['campo1'], $operacion2['campo2'], $arreglo, $operacion2['table'], $operacion2['seleccion'], $operacion2['campo3'], $operacion2['orderBy'], $operacion2['table2']);
- foreach ($registros2 as $registro2){
- if (!in_array($registro2->$operacion2['byCampo'], $ids) ){
- $ids[] = $registro2->$operacion2['byCampo'];
- }
- }
- echo '<select>';
- $registros3 = $this->getRegistrosByIds($ids, $operacion3['seleccion'], $operacion3['campo1'], $operacion3['orderBy'], $operacion3['table']);
- $option = explode(',', $operacion3['seleccion']);
- foreach ($registros3 as $registro3){
- echo '<option value="'. $registro3->$option[0] .'">'.$registro3->$option[1].'</option>';
- }
- echo '</select>';
- }
- else echo '<select><option value="">No hay Registros Disponibles</option></select>';
- }
-
- /*************************Metodo Para cargar select de registros de una relacion dos niveles arriba de Muchos a Muchos, Ejemplo Obras-Ejes*************************************/
- function cargaSelectSearchMM2($operacion1, $operacion2, $operacion3, $operacion4){
- $ids = array();
- $ids2 = array();
- $idsArreglo = array();
- $registros = $this->getAll($operacion1['seleccion'], $operacion1['table'], $operacion1['orderBy'], $operacion1['where']);
- if(count($registros) > 0){
- foreach ($registros as $registro) {
- $idsArreglo[] = $registro->$operacion1['seleccion'];
- }
- $registros2 = $this->getRegistrosMM($operacion2['campo1'], $operacion2['campo2'], $idsArreglo, $operacion2['table'], $operacion2['seleccion'], $operacion2['campo3'], $operacion2['orderBy'], $operacion2['table2']);
- foreach ($registros2 as $registro2){
- if (!in_array($registro2->$operacion2['byCampo'], $ids) ){
- $ids[] = $registro2->$operacion2['byCampo'];
- }
- }
- $registros3 = $this->getRegistrosByIds($ids, $operacion3['seleccion'], $operacion3['campo1'], $operacion3['orderBy'], $operacion3['table']);
- foreach ($registros3 as $registro3){
- if (!in_array($registro3->$operacion3['byCampo'], $ids2) ){
- $ids2[] = $registro3->$operacion3['byCampo'];
- }
- }
- echo '<select>';
- $registros4 = $this->getRegistrosByIds($ids2, $operacion4['seleccion'], $operacion4['campo1'], $operacion4['orderBy'], $operacion4['table']);
- $option = explode(',', $operacion4['seleccion']);
- foreach ($registros4 as $registro4){
- echo '<option value="'. $registro4->$option[0] .'">'.$registro4->$option[1].'</option>';
- }
- echo '</select>';
- }
- else echo '<select><option value="">No hay Registros Disponibles</option></select>';
- }
-
- /*************************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*************************************/
- function cargaSelectSearchMM22($operacion1, $operacion2, $operacion3, $operacion4, $operacion5){
- $ids = array();
- $ids2 = array();
- $ids3 = array();
- $idsArreglo = array();
- $registros = $this->getAll($operacion1['seleccion'], $operacion1['table'], $operacion1['orderBy'], $operacion1['where']);
- if(count($registros) > 0){
- foreach ($registros as $registro) {
- $idsArreglo[] = $registro->$operacion1['seleccion'];
- }
- $registros2 = $this->getRegistrosMM($operacion2['campo1'], $operacion2['campo2'], $idsArreglo, $operacion2['table'], $operacion2['seleccion'], $operacion2['campo3'], $operacion2['orderBy'], $operacion2['table2']);
- foreach ($registros2 as $registro2){
- if (!in_array($registro2->$operacion2['byCampo'], $ids) ){
- $ids[] = $registro2->$operacion2['byCampo'];
- }
- }
- $registros3 = $this->getRegistrosByIds($ids, $operacion3['seleccion'], $operacion3['campo1'], $operacion3['orderBy'], $operacion3['table']);
- foreach ($registros3 as $registro3){
- if (!in_array($registro3->$operacion3['byCampo'], $ids2) ){
- $ids2[] = $registro3->$operacion3['byCampo'];
- }
- }
- $registros4 = $this->getRegistrosByIds($ids2, $operacion4['seleccion'], $operacion4['campo1'], $operacion4['orderBy'], $operacion4['table']);
- foreach ($registros4 as $registro4){
- if (!in_array($registro4->$operacion4['byCampo'], $ids3) ){
- $ids3[] = $registro4->$operacion4['byCampo'];
- }
- }
- echo '<select>';
- $registros5 = $this->getRegistrosByIds($ids3, $operacion5['seleccion'], $operacion5['campo1'], $operacion5['orderBy'], $operacion5['table']);
- $option = explode(',', $operacion5['seleccion']);
- foreach ($registros5 as $registro5){
- echo '<option value="'. $registro5->$option[0] .'">'.$registro5->$option[1].'</option>';
- }
- echo '</select>';
- }
- else echo '<select><option value="">No hay Registros Disponibles</option></select>';
- }
-
- function cargaSelectSearchNM($operacion1, $operacion2){
- $ids = array();
- $registros = $this->getAll($operacion1['seleccion'], $operacion1['table'], $operacion1['orderBy'], $operacion1['where']);
- $count = count($registros);
- if($count == 0){
- echo '<select><option value="">No hay registros</option></select>';
- }
- else{
- foreach ($registros as $registro){
- $registros2 = $this->getRegistroById($operacion2['seleccion'], $operacion2['byCampo'], $registro->$operacion1['byCampo'], $operacion2['table']);
- foreach ($registros2 as $registro2){
- if (!in_array($registro2->$operacion2['byCampo'], $ids) ){
- $ids[] = $registro2->$operacion2['byCampo'];
- }
- }
- }
- echo '<select>';
- $registros3 = $this->getRegistrosByIds($ids, $operacion2['seleccion'], $operacion2['byCampo'], $operacion2['orderBy'], $operacion2['table']);
- $option = explode(',', $operacion2['seleccion']);
- foreach ($registros3 as $registro3){
- echo '<option value="'. $registro3->$option[0] .'">'.$registro3->$option[1].'</option>';
- }
- echo '</select>';
- }
- }
-
- function cargaSelectEdit($arrayForGetAll){
- $registros = $this->getAll($arrayForGetAll['seleccion'], $arrayForGetAll['table'], $arrayForGetAll['orderBy'], $arrayForGetAll['where']);
- $option = explode(',', $arrayForGetAll['seleccion']);
- echo '<select>';
- echo '<option value="">SELECCIONE</option>';
- foreach($registros as $registro){
- echo '<option value="'. $registro->$option[0] .'">'.$registro->$option[1].'</option>';
- }
- echo '</select>';
- }
-
- function getOptionsSelected($operacion1, $operacion2){
- $ids = $this->getRegistroById($operacion1['seleccion'], $operacion1['byCampo'], $operacion1['id'], $operacion1['table'], $operacion1['orderBy']);
- $registros = $this->getAll($operacion2['seleccion'], $operacion2['table'], $operacion2['orderBy'], $operacion2['where']);
- $option = explode(',',$operacion2['seleccion']);
- foreach ($registros as $registro){
- $cadena = "<option value='".$registro->$option[0]."'";
- foreach ($ids as $id) {
- if($registro->$option[0] == $id->$operacion1['seleccion']){
- $cadena .= " selected ";
- }
- }
- $cadena .= ">".$registro->$option[1]."</option>";
- echo $cadena;
- }
- }
-
- function getLastId($table){
- $query = $this->CI->db->query('SELECT max(id) as maxi FROM '.$table);
- if ($query->num_rows() > 0){
- foreach ($query->result() as $fila) {
- $max = $fila->maxi;
- }
- return $max;
- }
- }
-
- function getRows($sql){
- $query = $this->CI->db->query($sql);
- if ($query->num_rows() > 0){
- foreach ($query->result() as $fila) {
- $rows[] = $fila;
- }
- return $rows;
- }else return array();
- }
-
- function getRow($sql){
- $query = $this->CI->db->query($sql);
- $row=array();
- if ($query->num_rows() > 0)
- $row = $query->row_array();
- return $row;
- }
-
- function getOptionsForSelect($data, $keyOnValue=false, $optionSelected=false){
- $query=$this->CI->db->query($data['SQL']);
- if($query->num_rows()>0){
- $options = "<option value=''>SELECCIONE</option>";
- foreach($query->result() AS $fila ){
- if($optionSelected != false){
- if($fila->$data['KEY'] == $optionSelected)
- $cierre = " selected>";
- else
- $cierre = " >";
- }
- else
- $cierre = " >";
- if($keyOnValue)
- $options .= "<option value='".$fila->$data['KEY']."' $cierre".$fila->$data['KEY'].' '.$fila->$data['VALUE']."</option>";
- else
- $options .= "<option value='".$fila->$data['KEY']."' $cierre".$fila->$data['VALUE']."</option>";
- }
- }else $options = "<option value=''>NO HAY REGISTROS DISPONIBLES</option>";
- return $options;
- }
-
- function mayusculas($string){
- return strtr(strtoupper($string), array(
- "à" => "À",
- "è" => "È",
- "ì" => "Ì",
- "ò" => "Ò",
- "ù" => "Ù",
- "á" => "Á",
- "é" => "É",
- "í" => "Í",
- "ó" => "Ó",
- "ú" => "Ú",
- "â" => "Â",
- "ê" => "Ê",
- "î" => "Î",
- "ô" => "Ô",
- "û" => "Û",
- "ç" => "Ç",
- ));
- }
- function login($username, $password){
- $query = $this->CI->db->get_where('usuario', array('login' => $username, 'password' => $password));
- if($query->num_rows()>0){
- $this->CI->session->sess_destroy();
- $this->CI->session->sess_create();
- $query2 = $this->CI->db->get_where('institucion', array('id' => $query->row()->id_institucion));
- $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'));
- $this->CI->db->insert('sesion', $arrayCampos);
- $this->CI->session->set_userdata(array(
- 'ingresado' => true,
- 'login' => $username,
- 'id_usuario' => $query->row()->id,
- 'username' => $query->row()->nombre,
- 'nivel' => $query->row()->nivel,
- 'id-institucion' => $query->row()->id_institucion,
- 'institucion' => $query2->row()->nombre,
- 'siglas' => $query2->row()->siglas
- ));
- return true;
- }
- else
- return false;
- }
- function logout(){
- $this->CI->session->sess_destroy();
- $arrayCampos = array('salida' => date("Y-n-j H:i:s"), 'ultima_actividad' => $this->CI->session->userdata('last_activity'));
- $this->CI->db->where('id', $this->CI->session->userdata('session_id'))->update('sesion', $arrayCampos);
- }
- }
- ?>