예제 #1
0
 function buscar2($busquedaArray)
 {
     $valor = "";
     $id_listar = "";
     if (isset($_SESSION['id_lista'])) {
         $id_listar = $_SESSION['id_lista'];
     }
     $page = $busquedaArray['page'];
     $rp = $busquedaArray['rp'];
     $sortname = $busquedaArray['sortname'];
     $sortorder = $busquedaArray['sortorder'];
     //
     //        $fon_id = $busquedaArray['fon_id'];
     // Search
     $archivo = new archivo();
     $tarchivo = new tab_archivo();
     $tarchivo->setRequest2Object($_REQUEST);
     $page = $_REQUEST['page'];
     $rp = $_REQUEST['rp'];
     $sortname = $_REQUEST['sortname'];
     $sortorder = $_REQUEST['sortorder'];
     if (!$sortname) {
         $sortname = 'fil_id';
     }
     if (!$sortorder) {
         $sortorder = 'desc';
     }
     $sort = "ORDER BY {$sortname} {$sortorder}";
     if (!$page) {
         $page = 1;
     }
     if (!$rp) {
         $rp = 15;
     }
     $start = ($page - 1) * $rp;
     $limit = "LIMIT {$rp} OFFSET {$start} ";
     $query = $_REQUEST['query'];
     $qtype = $_REQUEST['qtype'];
     $where = "";
     if ($query) {
         if ($qtype == 'fil_id') {
             $where = " WHERE {$qtype} = '{$query}' ";
         } else {
             $where = " WHERE {$qtype} LIKE '%{$query}%' ";
         }
         $sql = "SELECT *\r\n                    FROM tab_rol\r\n                    {$where} AND\r\n                    rol_estado = 1 {$sort} {$limit} ";
     } else {
         $sql = "SELECT *\r\n                    FROM tab_rol\r\n                    WHERE rol_estado = 1 {$sort} {$limit} ";
     }
     $usu_id = $_SESSION['USU_ID'];
     $select = "SELECT\r\n                tab_archivo.fil_id,\r\n                (SELECT fon_codigo from tab_fondo WHERE fon_id=f.fon_par) AS fon_codigo,\r\n                tab_unidad.uni_descripcion,\r\n                tab_series.ser_categoria,\r\n                tab_expisadg.exp_titulo,\r\n                f.fon_cod,\r\n                tab_unidad.uni_cod,\r\n                tab_tipocorr.tco_codigo,\r\n                tab_series.ser_codigo,\r\n                tab_expediente.exp_id,\r\n                tab_expediente.exp_codigo,\r\n                tab_cuerpos.cue_codigo,\r\n                tab_archivo.fil_codigo,\r\n                tab_cuerpos.cue_descripcion,\r\n                tab_archivo.fil_titulo,\r\n                tab_archivo.fil_subtitulo,\r\n                tab_archivo.fil_proc,\r\n                tab_archivo.fil_firma,\r\n                tab_archivo.fil_cargo,\r\n                tab_archivo.fil_nrofoj,\r\n                tab_archivo.fil_tomovol,\r\n                tab_archivo.fil_nroejem,\r\n                tab_archivo.fil_nrocaj,\r\n                tab_archivo.fil_sala,\r\n                tab_archivo.fil_estante,\r\n                tab_archivo.fil_cuerpo,\r\n                tab_archivo.fil_balda,\r\n                tab_archivo.fil_tipoarch,\r\n                tab_archivo.fil_mrb,\r\n                tab_archivo.fil_ori,\r\n                tab_archivo.fil_cop,\r\n                tab_archivo.fil_fot,\r\n                (CASE tab_exparchivo.exa_condicion\r\n                                    WHEN '1' THEN 'DISPONIBLE'\r\n                                    WHEN '2' THEN 'PRESTADO' END) AS disponibilidad,\r\n                (SELECT fil_nomoriginal FROM tab_archivo_digital WHERE tab_archivo_digital.fil_id=tab_archivo.fil_id AND tab_archivo_digital.fil_estado = '1' ) AS fil_nomoriginal,\r\n                (SELECT fil_extension FROM tab_archivo_digital WHERE tab_archivo_digital.fil_id=tab_archivo.fil_id AND tab_archivo_digital.fil_estado = '1' ) AS fil_extension,\r\n                (SELECT fil_tamano/1048576 FROM tab_archivo_digital WHERE tab_archivo_digital.fil_id=tab_archivo.fil_id AND tab_archivo_digital.fil_estado = '1' ) AS fil_tamano,\r\n                (SELECT fil_nur FROM tab_doccorr WHERE tab_doccorr.fil_id=tab_archivo.fil_id AND tab_doccorr.dco_estado = '1' ) AS fil_nur,\r\n                (SELECT fil_asunto FROM tab_doccorr WHERE tab_doccorr.fil_id=tab_archivo.fil_id AND tab_doccorr.dco_estado = '1' ) AS fil_asunto,\r\n                tab_archivo.fil_obs";
     $from = "FROM\r\n                tab_fondo as f\r\n                INNER JOIN tab_unidad ON f.fon_id = tab_unidad.fon_id\r\n                INNER JOIN tab_series ON tab_unidad.uni_id = tab_series.uni_id\r\n                INNER JOIN tab_tipocorr ON tab_tipocorr.tco_id = tab_series.tco_id\r\n                INNER JOIN tab_expediente ON tab_series.ser_id = tab_expediente.ser_id\r\n                INNER JOIN tab_exparchivo ON tab_expediente.exp_id = tab_exparchivo.exp_id\r\n                INNER JOIN tab_archivo ON tab_archivo.fil_id = tab_exparchivo.fil_id\r\n                INNER JOIN tab_expisadg ON tab_expediente.exp_id = tab_expisadg.exp_id\r\n                INNER JOIN tab_expusuario ON tab_expediente.exp_id = tab_expusuario.exp_id\r\n                INNER JOIN tab_cuerpos ON tab_cuerpos.cue_id = tab_exparchivo.cue_id\r\n                INNER JOIN tab_tramitecuerpos ON tab_cuerpos.cue_id = tab_tramitecuerpos.cue_id\r\n                INNER JOIN tab_tramite ON tab_tramite.tra_id = tab_tramitecuerpos.tra_id\r\n                WHERE\r\n                f.fon_estado = 1 AND\r\n                tab_unidad.uni_estado = 1 AND\r\n                tab_tipocorr.tco_estado = 1 AND\r\n                tab_series.ser_estado = 1 AND\r\n                tab_expediente.exp_estado = 1 AND\r\n                tab_archivo.fil_estado = 1 AND\r\n                tab_exparchivo.exa_estado = 1 AND\r\n                tab_expusuario.eus_estado = 1 AND\r\n                tab_expusuario.usu_id='{$usu_id}'";
     $where = "";
     //        if (strlen($fon_id)> 0 && $fon_id!='null') {
     //            $where .= " AND tab_fondo.fon_id='$fon_id' ";
     //        }
     // Search addwords
     if ($id_listar != "") {
         $explode = explode(",", $id_listar);
         $cantidad = count($explode);
         for ($i = 0; $i < $cantidad; $i++) {
             $valor .= "tab_archivo.fil_id=" . $explode[$i];
             if ($i < $cantidad - 1) {
                 $valor .= " or ";
             }
         }
         $where .= " AND {$valor} ";
     }
     $sql = "{$select} {$from} {$where} {$sort} {$limit}";
     $result = $tarchivo->dbSelectBySQL($sql);
     //print $sql;
     $sql_c = "SELECT COUNT(tab_archivo.fil_id) {$from} {$where} ";
     $total = $tarchivo->countBySQL($sql_c);
     $exp = new expediente();
     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
     header("Cache-Control: no-cache, must-revalidate");
     header("Pragma: no-cache");
     header("Content-type: text/x-json");
     $json = "";
     $json .= "{\n";
     $json .= "page: {$page},\n";
     $json .= "total: {$total},\n";
     $json .= "rows: [";
     $rc = false;
     $i = 0;
     $j = 1;
     foreach ($result as $un) {
         if ($rc) {
             $json .= ",";
         }
         $json .= "\n{";
         $json .= "id:'" . $un->fil_id . "',";
         //$json .= "cell:['" . $un->fil_id . "'";
         $json .= "cell:[";
         $json .= "'<input id=\"chkid_" . $un->fil_id . "\" restric=\"" . $un->fil_confidencialidad . "\" class=\"fil_chk" . $j . "\" type=\"checkbox\" value=\"" . $un->fil_id . "\" checked=\"checked\" />'";
         if ($un->fil_confidencialidad == 3) {
             $json .= ",'<img src=\"" . PATH_DOMAIN . "/web/lib/32/b_view.png\" file=\"{$un->fil_id}\" valueId=\"" . $un->fil_id . "\" restric=\"" . $un->fil_confidencialidad . "\" class=\"viewFileP icon\" />'";
         } else {
             //$json .= ",'<img src=\"" . PATH_DOMAIN . "/web/lib/32/b_view.png\" file=\"$un->fil_id\" valueId=\"" . $un->fil_id . "\" restric=\"" . $un->fil_confidencialidad . "\" class=\"viewFile icon\" />'";
             $json .= ",'<img src=\"" . PATH_DOMAIN . "/web/lib/32/document-{$un->fil_extension}.png\" file=\"{$un->fil_id}\" valueId=\"" . $un->fil_id . "\" restric=\"" . $un->fil_confidencialidad . "\" class=\"viewFile icon\" />'";
             ///web/lib/32/document-". $una->fil_extension .".png'
         }
         if ($un->fil_confidencialidad == 3) {
             $json .= ",'<img src=\"" . PATH_DOMAIN . "/web/lib/32/b_view.png\" file=\"{$un->fil_id}\" valueId=\"" . $un->fil_id . "\" restric=\"" . $un->fil_confidencialidad . "\" class=\"viewP icon\" />'";
         } else {
             //$json .= ",'<img src=\"" . PATH_DOMAIN . "/web/lib/32/b_view.png\" file=\"$un->fil_id\" valueId=\"" . $un->fil_id . "\" restric=\"" . $un->fil_confidencialidad . "\" class=\"viewFile icon\" />'";
             $json .= ",'<img src=\"" . PATH_DOMAIN . "/web/lib/32/b_view.png\" file=\"{$un->fil_id}\" valueId=\"" . $un->fil_id . "\" restric=\"" . $un->fil_confidencialidad . "\" class=\"view icon\" />'";
             ///web/lib/32/document-". $una->fil_extension .".png'
         }
         $json .= ",'" . $un->fil_id . "'";
         $json .= ",'" . addslashes($un->fon_codigo) . "'";
         $json .= ",'" . addslashes(utf8_decode($un->uni_descripcion)) . "'";
         $json .= ",'" . addslashes(utf8_decode($un->ser_categoria)) . "'";
         $json .= ",'" . addslashes(utf8_decode($un->exp_titulo)) . "'";
         $json .= ",'" . addslashes(utf8_decode($un->cue_descripcion)) . "'";
         $json .= ",'" . addslashes($un->fon_cod . DELIMITER . $un->uni_cod . DELIMITER . $un->tco_codigo . DELIMITER . $un->ser_codigo . DELIMITER . $un->exp_codigo . DELIMITER . $un->cue_codigo . DELIMITER . $un->fil_codigo) . "'";
         $json .= ",'" . addslashes(utf8_decode($un->fil_titulo)) . "'";
         $json .= ",'" . addslashes(utf8_decode($un->fil_proc)) . "'";
         $json .= ",'" . addslashes(utf8_decode($un->fil_firma)) . "'";
         $json .= ",'" . addslashes(utf8_decode($un->fil_cargo)) . "'";
         $json .= ",'" . addslashes($un->fil_nrofoj) . "'";
         $json .= ",'" . addslashes($un->fil_nrocaj) . "'";
         $json .= ",'" . addslashes($un->fil_sala) . "'";
         $json .= ",'" . addslashes($un->fil_estante) . "'";
         $json .= ",'" . addslashes($un->fil_cuerpo) . "'";
         $json .= ",'" . addslashes($un->fil_balda) . "'";
         $json .= ",'" . addslashes($un->fil_tipoarch) . "'";
         $json .= ",'" . addslashes($un->fil_mrb) . "'";
         $json .= ",'" . addslashes($un->fil_ori) . "'";
         $json .= ",'" . addslashes($un->fil_cop) . "'";
         $json .= ",'" . addslashes($un->fil_fot) . "'";
         $json .= ",'" . addslashes($un->fil_nur) . "'";
         $json .= ",'" . addslashes(utf8_decode($un->fil_asunto)) . "'";
         $json .= ",'" . addslashes($un->disponibilidad) . "'";
         $json .= ",'" . addslashes(utf8_decode($un->fil_nomoriginal)) . "'";
         $json .= ",'" . addslashes($un->fil_tamano) . "'";
         $json .= ",'" . addslashes(utf8_decode($un->fil_obs)) . "'";
         $json .= "]}";
         $rc = true;
         $i++;
         $j++;
     }
     $json .= "]\n";
     $json .= "}";
     echo $json;
 }
 function search()
 {
     // Search
     $usuario = new usuario();
     $tarchivo = new tab_archivo();
     $tarchivo->setRequest2Object($_REQUEST);
     // Hasta aqui
     $valor = "";
     $id_listar = "";
     if (isset($_SESSION['id_lista'])) {
         $id_listar = $_SESSION['id_lista'];
     }
     if (isset($_REQUEST["palabra"])) {
         $palabra = html_entity_decode(trim(strtoupper($_REQUEST["palabra"])), ENT_QUOTES);
     }
     if (isset($_REQUEST["uni_id"])) {
         $uni_id = html_entity_decode(trim($_REQUEST["uni_id"]), ENT_QUOTES);
     }
     if (isset($_REQUEST["ser_id"])) {
         $ser_id = html_entity_decode(trim($_REQUEST["ser_id"]), ENT_QUOTES);
     }
     if (isset($_REQUEST["tra_id"])) {
         $tra_id = html_entity_decode(trim($_REQUEST["tra_id"]), ENT_QUOTES);
     }
     if (isset($_REQUEST["cue_id"])) {
         $cue_id = html_entity_decode(trim($_REQUEST["cue_id"]), ENT_QUOTES);
     }
     if (isset($_REQUEST["exp_titulo"])) {
         $exp_titulo = html_entity_decode(trim(strtoupper($_REQUEST["exp_titulo"])), ENT_QUOTES);
     }
     if (isset($_REQUEST["fil_titulo"])) {
         $fil_titulo = html_entity_decode(trim(strtoupper($_REQUEST["fil_titulo"])), ENT_QUOTES);
     }
     if (isset($_REQUEST["fil_subtitulo"])) {
         $fil_subtitulo = html_entity_decode(strtoupper(trim($_REQUEST["fil_subtitulo"])), ENT_QUOTES);
     }
     if (isset($_REQUEST["fil_proc"])) {
         $fil_proc = html_entity_decode(trim(strtoupper($_REQUEST["fil_proc"])), ENT_QUOTES);
     }
     if (isset($_REQUEST["fil_firma"])) {
         $fil_firma = html_entity_decode(trim(strtoupper($_REQUEST["fil_firma"])), ENT_QUOTES);
     }
     if (isset($_REQUEST["fil_cargo"])) {
         $fil_cargo = html_entity_decode(trim(strtoupper($_REQUEST["fil_cargo"])), ENT_QUOTES);
     }
     if (isset($_REQUEST["fil_tipoarch"])) {
         // MODIFICAR ESTE PARAMETRO POR EL MOMENTO ESTA RECIBIENDO VACIO
         //$result['fil_tipoarch'] = html_entity_decode(trim(strtoupper($_REQUEST["fil_tipoarch"])), ENT_QUOTES);
         $fil_tipoarch = html_entity_decode(trim(strtoupper("")), ENT_QUOTES);
     }
     if (isset($_REQUEST["pac_nombre"])) {
         $pac_nombre = html_entity_decode(trim(strtoupper($_REQUEST["pac_nombre"])), ENT_QUOTES);
     }
     $page = $_REQUEST['page'];
     $rp = $_REQUEST['rp'];
     $sortname = $_REQUEST['sortname'];
     $sortorder = $_REQUEST['sortorder'];
     if (!$sortname) {
         $sortname = " tab_series.ser_orden, \r\n                tab_expediente.exp_codigo::int,\r\n                tab_archivo.fil_nro::int  ";
     } else {
         $sortname = $sortname;
     }
     if (!$sortorder) {
         $sortorder = 'desc';
     }
     $sort = "ORDER BY {$sortname} {$sortorder}";
     if (!$page) {
         $page = 1;
     }
     if (!$rp) {
         $rp = 20;
     }
     $start = ($page - 1) * $rp;
     $limit = "LIMIT {$rp} OFFSET {$start} ";
     $query = $_REQUEST['query'];
     $qtype = $_REQUEST['qtype'];
     $where = "";
     if ($query) {
         if ($qtype) {
         }
     }
     $whereUsuario = "";
     //        $usu_id = $_SESSION['USU_ID'];
     //        if ($_SESSION['ROL_COD'] != 'AA') {
     //            $whereUsuario = " AND tab_expusuario.usu_id=" . $_SESSION['USU_ID'] . "";
     //        }
     // Search docs
     $select = "SELECT   \r\n                tab_expediente.exp_id,\r\n                tab_archivo.fil_id,\r\n                f.fon_codigo,\r\n                f.fon_cod,\r\n                tab_unidad.uni_cod,\r\n                tab_tipocorr.tco_codigo,\r\n                tab_series.ser_codigo,\r\n                tab_expediente.exp_codigo,\r\n                tab_archivo.fil_nro,\r\n                tab_unidad.uni_descripcion,\r\n                tab_series.ser_categoria,\r\n                tab_expisadg.exp_titulo,                                \r\n                tab_cuerpos.cue_descripcion,\r\n                tab_archivo.fil_confidencialidad,\r\n                tab_archivo.fil_titulo,\r\n                tab_archivo.fil_subtitulo,\r\n                tab_archivo.fil_proc,\r\n                tab_archivo.fil_firma,\r\n                tab_archivo.fil_cargo,\r\n                tab_archivo.fil_nrofoj,\r\n                tab_archivo.fil_tomovol,\r\n                tab_archivo.fil_nroejem,\r\n                tab_archivo.fil_nrocaj,\r\n                tab_archivo.fil_sala,\r\n                tab_archivo.fil_estante,\r\n                tab_archivo.fil_cuerpo,\r\n                tab_archivo.fil_balda,\r\n                tab_archivo.fil_tipoarch,\r\n                tab_archivo.fil_mrb,\r\n                tab_archivo.fil_ori,\r\n                tab_archivo.fil_cop,\r\n                tab_archivo.fil_fot,    \r\n                (SELECT fil_extension FROM tab_archivo_digital WHERE tab_archivo_digital.fil_id=tab_archivo.fil_id AND tab_archivo_digital.fil_estado = '1' ) AS fil_extension,\r\n                (SELECT fil_nur FROM tab_doccorr WHERE tab_doccorr.fil_id=tab_archivo.fil_id AND tab_doccorr.dco_estado = '1' ) AS fil_nur,                \r\n                (SELECT fil_asunto FROM tab_doccorr WHERE tab_doccorr.fil_id=tab_archivo.fil_id AND tab_doccorr.dco_estado = '1' ) AS fil_asunto,                \r\n                tab_archivo.fil_obs,\r\n                tab_expusuario.usu_id";
     $from = "FROM\r\n                tab_fondo as f\r\n                INNER JOIN tab_unidad ON f.fon_id = tab_unidad.fon_id\r\n                INNER JOIN tab_series ON tab_unidad.uni_id = tab_series.uni_id\r\n                INNER JOIN tab_tipocorr ON tab_tipocorr.tco_id = tab_series.tco_id\r\n                INNER JOIN tab_expediente ON tab_series.ser_id = tab_expediente.ser_id\r\n                INNER JOIN tab_expisadg ON tab_expediente.exp_id = tab_expisadg.exp_id\r\n                INNER JOIN tab_expusuario ON tab_expediente.exp_id = tab_expusuario.exp_id\r\n                LEFT JOIN tab_exparchivo ON tab_expediente.exp_id = tab_exparchivo.exp_id\r\n                INNER JOIN tab_archivo ON tab_archivo.fil_id = tab_exparchivo.fil_id                                \r\n                INNER JOIN tab_cuerpos ON tab_cuerpos.cue_id = tab_exparchivo.cue_id\r\n                INNER JOIN tab_tramitecuerpos ON tab_cuerpos.cue_id = tab_tramitecuerpos.cue_id\r\n                INNER JOIN tab_tramite ON tab_tramite.tra_id = tab_tramitecuerpos.tra_id\r\n                WHERE\r\n                f.fon_estado = 1 AND\r\n                tab_unidad.uni_estado = 1 AND\r\n                tab_tipocorr.tco_estado = 1 AND\r\n                tab_series.ser_estado = 1 AND\r\n                tab_expediente.exp_estado = 1 AND\r\n                tab_archivo.fil_estado = 1 AND\r\n                tab_exparchivo.exa_estado = 1 AND\r\n                tab_expusuario.eus_estado = 1\r\n                {$whereUsuario} ";
     // (SELECT fil_extension FROM tab_archivo_digital WHERE tab_archivo_digital.fil_id=tab_archivo.fil_id AND tab_archivo_digital.fil_estado = '1' ) AS fil_extension,
     $where = "";
     if ($id_listar != "") {
         $explode = explode(",", $id_listar);
         $cantidad = count($explode);
         for ($i = 0; $i < $cantidad; $i++) {
             $valor .= "tab_archivo.fil_id<>" . $explode[$i];
             if ($i < $cantidad - 1) {
                 $valor .= " and ";
             }
         }
         $where .= " AND {$valor} ";
     }
     // Search all fields
     if (strlen($palabra)) {
         $where .= " AND (tab_expisadg.exp_titulo like '%{$palabra}%' ";
         $where .= " OR f.fon_descripcion like '%{$palabra}%' ";
         $where .= " OR tab_unidad.uni_descripcion like '%{$palabra}%' ";
         $where .= " OR tab_series.ser_categoria like '%{$palabra}%' ";
         $where .= " OR tab_archivo.fil_titulo like '%{$palabra}%' ";
         $where .= " OR tab_archivo.fil_subtitulo like '%{$palabra}%' ";
         $where .= " OR tab_archivo.fil_proc like '%{$palabra}%' ";
         $where .= " OR tab_archivo.fil_firma like '%{$palabra}%' ";
         $where .= " OR tab_archivo.fil_cargo like '%{$palabra}%' ";
         $where .= " OR tab_archivo.fil_tipoarch like '%{$palabra}%' ";
         $palclave = new palclave();
         $ids = $palclave->listaPCSearchFile($palabra);
         if ($ids == "") {
         } else {
             $where .= " OR tab_archivo.fil_id IN ({$ids}) ";
         }
         $where .= " ) ";
     }
     if (strlen($uni_id) > 0 && $uni_id != 'null') {
         $where .= " AND tab_unidad.uni_id='{$uni_id}' ";
     }
     if (strlen($ser_id) > 0 && $ser_id != 'null') {
         $where .= " AND tab_series.ser_id='{$ser_id}' ";
     }
     if (strlen($tra_id) > 0 && $tra_id != 'null') {
         $where .= " AND tab_tramite.tra_id='{$tra_id}' ";
     }
     if (strlen($cue_id) > 0 && $cue_id != 'null') {
         $where .= " AND tab_cuerpos.cue_id='{$cue_id}' ";
     }
     if (strlen($exp_titulo)) {
         $where .= " AND tab_expisadg.exp_titulo like '%{$exp_titulo}%' ";
     }
     if (strlen($fil_titulo)) {
         $where .= " AND tab_archivo.fil_titulo like '%{$fil_titulo}%' ";
     }
     if (strlen($fil_subtitulo)) {
         $where .= " AND tab_archivo.fil_subtitulo like '%{$fil_subtitulo}%' ";
     }
     if (strlen($fil_proc)) {
         $where .= " AND tab_archivo.fil_proc like '%{$fil_proc}%' ";
     }
     if (strlen($fil_firma)) {
         $where .= " AND tab_archivo.fil_firma like '%{$fil_firma}%' ";
     }
     if (strlen($fil_cargo)) {
         $where .= " AND tab_archivo.fil_cargo like '%{$fil_cargo}%' ";
     }
     if (strlen($fil_tipoarch)) {
         $where .= " AND tab_archivo.fil_tipoarch like '%{$fil_tipoarch}%' ";
     }
     // Search addwords
     if (strlen($pac_nombre)) {
         $palclave = new palclave();
         $ids = $palclave->listaPCSearchFile($pac_nombre);
         if ($ids == "") {
         } else {
             $where .= " AND tab_archivo.fil_id IN ({$ids}) ";
         }
     }
     // MODIFICADO
     //$sort = "ORDER BY tab_expediente.exp_id, tab_cuerpos.cue_id, tab_archivo.fil_nro ";
     //$sort = "ORDER BY tab_series.ser_orden, tab_expediente.exp_codigo::int, tab_archivo.fil_nro::int ";
     $sql = "{$select} {$from} {$where} {$sort} {$limit}";
     $result = $tarchivo->dbSelectBySQL($sql);
     //print $sql;
     $sql_c = "SELECT COUNT(tab_archivo.fil_id) {$from} {$where} ";
     $total = $tarchivo->countBySQL($sql_c);
     $exp = new expediente();
     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
     header("Cache-Control: no-cache, must-revalidate");
     header("Pragma: no-cache");
     header("Content-type: text/x-json");
     $json = "";
     $json .= "{\n";
     $json .= "page: {$page},\n";
     $json .= "total: {$total},\n";
     $json .= "rows: [";
     $rc = false;
     $exp_titulo = "";
     foreach ($result as $un) {
         if ($un->exp_titulo != $exp_titulo) {
             // Expediente
             if ($rc) {
                 $json .= ",";
             }
             $json .= "\n{";
             $json .= "id:'" . $un->exp_id . "',";
             $json .= "cell:['" . '<font color=#238E23>E' . $un->exp_id . "</font>'";
             $json .= ",'<img src=\"" . PATH_DOMAIN . "/web/lib/32/document-{$un->fil_extension}.png\" file=\"{$un->fil_id}\" valueId=\"" . 'E' . $un->fil_id . "\" restric=\"" . $un->fil_confidencialidad . "\" class=\"viewFile icon\" />'";
             //$json .= ",'<img src=\"" . PATH_DOMAIN . "/web/lib/32/document-.png\" file=\"$un->fil_id\" valueId=\"" . 'E' . $un->fil_id . "\" restric=\"" . $un->fil_confidencialidad . "\" class=\"viewFile icon\" />'";
             $json .= ",'<img src=\"" . PATH_DOMAIN . "/web/lib/32/b_view.png\" file=\" {$un->exp_id}\" valueId=\"" . 'E' . $un->exp_id . "\" restric=\"" . $un->fil_confidencialidad . "\" class=\"view icon\" />'";
             $json .= ",'<font color=#238E23>" . addslashes($un->fon_cod . DELIMITER . $un->uni_cod . DELIMITER . $un->tco_codigo . DELIMITER . $un->ser_codigo . DELIMITER . $un->exp_codigo) . "</font>'";
             //$json .= ",'" . addslashes($un->fon_cod . DELIMITER . $un->uni_cod . DELIMITER . $un->tco_codigo . DELIMITER . $un->ser_codigo . DELIMITER . $un->exp_codigo) . "'";
             $json .= ",'" . addslashes($usuario->getRol($un->usu_id)) . "'";
             $json .= ",'" . addslashes($un->fon_codigo) . "'";
             $json .= ",'" . addslashes(utf8_decode($un->uni_descripcion)) . "'";
             $json .= ",'" . addslashes(utf8_decode($un->ser_categoria)) . "'";
             $json .= ",'" . addslashes(utf8_decode($un->exp_titulo)) . "'";
             //$json .= ",'" . addslashes(utf8_decode($un->cue_descripcion)) . "'";
             //$json .= ",'" . addslashes(/*utf8_decode($un->fil_titulo)*/) . "'";
             $json .= ",'" . addslashes("") . "'";
             $json .= ",'" . addslashes("") . "'";
             $json .= ",'" . addslashes("") . "'";
             $json .= ",'" . addslashes("") . "'";
             $json .= ",'" . addslashes("") . "'";
             $json .= ",'" . addslashes("") . "'";
             $json .= ",'" . addslashes("") . "'";
             $json .= ",'" . addslashes("") . "'";
             $json .= ",'" . addslashes("") . "'";
             $json .= ",'" . addslashes("") . "'";
             $json .= ",'" . addslashes("") . "'";
             $json .= ",'" . addslashes("") . "'";
             $json .= ",'" . addslashes("") . "'";
             $json .= ",'" . addslashes("") . "'";
             $json .= ",'" . addslashes("") . "'";
             $json .= ",'" . addslashes("") . "'";
             $json .= ",'" . addslashes("") . "'";
             // SIACO
             $json .= ",'" . addslashes("") . "'";
             $json .= ",'" . addslashes("") . "'";
             $json .= "]}";
             $rc = true;
             // Documento
             if ($rc) {
                 $json .= ",";
             }
             $json .= "\n{";
             $json .= "id:'" . $un->fil_id . "',";
             $json .= "cell:['" . $un->fil_id . "'";
             $json .= ",'<img src=\"" . PATH_DOMAIN . "/web/lib/32/document-{$un->fil_extension}.png\" file=\"{$un->fil_id}\" valueId=\"" . $un->fil_id . "\" restric=\"" . $un->fil_confidencialidad . "\" class=\"viewFile icon\" />'";
             //$json .= ",'<img src=\"" . PATH_DOMAIN . "/web/lib/32/document-.png\" file=\"$un->fil_id\" valueId=\"" . $un->fil_id . "\" restric=\"" . $un->fil_confidencialidad . "\" class=\"viewFile icon\" />'";
             $json .= ",'<img src=\"" . PATH_DOMAIN . "/web/lib/32/b_view.png\" file=\"{$un->fil_id}\" valueId=\"" . $un->fil_id . "\" restric=\"" . $un->fil_confidencialidad . "\" class=\"view icon\" />'";
             $json .= ",'" . addslashes($un->fon_cod . DELIMITER . $un->uni_cod . DELIMITER . $un->tco_codigo . DELIMITER . $un->ser_codigo . DELIMITER . $un->exp_codigo . DELIMITER . $un->fil_nro) . "'";
             $json .= ",'" . addslashes($usuario->getRol($un->usu_id)) . "'";
             $json .= ",'" . addslashes($un->fon_codigo) . "'";
             $json .= ",'" . addslashes(utf8_decode($un->uni_descripcion)) . "'";
             $json .= ",'" . addslashes(utf8_decode($un->ser_categoria)) . "'";
             //$json .= ",'" . addslashes(utf8_decode($un->exp_titulo)) . "'";
             //$json .= ",'" . addslashes(utf8_decode($un->cue_descripcion)) . "'";
             if ($un->fil_subtitulo) {
                 $json .= ",'" . addslashes(utf8_decode($un->fil_titulo . " - " . $un->fil_subtitulo)) . "'";
             } else {
                 $json .= ",'" . addslashes(utf8_decode($un->fil_titulo)) . "'";
             }
             $json .= ",'" . addslashes($un->fil_tomovol) . "'";
             $json .= ",'" . addslashes(utf8_decode($un->fil_proc)) . "'";
             $json .= ",'" . addslashes(utf8_decode($un->fil_firma)) . "'";
             $json .= ",'" . addslashes(utf8_decode($un->fil_cargo)) . "'";
             $json .= ",'" . addslashes($un->fil_nrofoj) . "'";
             $json .= ",'" . addslashes($un->fil_nrocaj) . "'";
             $json .= ",'" . addslashes($un->fil_sala) . "'";
             $json .= ",'" . addslashes($un->fil_estante) . "'";
             $json .= ",'" . addslashes($un->fil_cuerpo) . "'";
             $json .= ",'" . addslashes($un->fil_balda) . "'";
             $json .= ",'" . addslashes($un->fil_tipoarch) . "'";
             $json .= ",'" . addslashes($un->fil_mrb) . "'";
             $json .= ",'" . addslashes($un->fil_ori) . "'";
             $json .= ",'" . addslashes($un->fil_cop) . "'";
             $json .= ",'" . addslashes($un->fil_fot) . "'";
             //palabras clave
             $palclave = new palclave();
             $fil_palclave = $palclave->listaPCFile($un->fil_id);
             $json .= ",'" . addslashes($fil_palclave) . "'";
             $json .= ",'" . addslashes(utf8_decode($un->fil_obs)) . "'";
             // SIACO
             $json .= ",'" . addslashes($un->fil_nur) . "'";
             $json .= ",'" . addslashes(utf8_decode($un->fil_asunto)) . "'";
             $json .= "]}";
             $rc = true;
             $exp_titulo = $un->exp_titulo;
         } else {
             // Documento
             if ($rc) {
                 $json .= ",";
             }
             $json .= "\n{";
             $json .= "id:'" . $un->fil_id . "',";
             $json .= "cell:['" . $un->fil_id . "'";
             $json .= ",'<img src=\"" . PATH_DOMAIN . "/web/lib/32/document-{$un->fil_extension}.png\" file=\"{$un->fil_id}\" valueId=\"" . $un->fil_id . "\" restric=\"" . $un->fil_confidencialidad . "\" class=\"viewFile icon\" />'";
             //$json .= ",'<img src=\"" . PATH_DOMAIN . "/web/lib/32/document-.png\" file=\"$un->fil_id\" valueId=\"" . $un->fil_id . "\" restric=\"" . $un->fil_confidencialidad . "\" class=\"viewFile icon\" />'";
             $json .= ",'<img src=\"" . PATH_DOMAIN . "/web/lib/32/b_view.png\" file=\"{$un->fil_id}\" valueId=\"" . $un->fil_id . "\" restric=\"" . $un->fil_confidencialidad . "\" class=\"view icon\" />'";
             $json .= ",'" . addslashes($un->fon_cod . DELIMITER . $un->uni_cod . DELIMITER . $un->tco_codigo . DELIMITER . $un->ser_codigo . DELIMITER . $un->exp_codigo . DELIMITER . $un->fil_nro) . "'";
             $json .= ",'" . addslashes($usuario->getRol($un->usu_id)) . "'";
             $json .= ",'" . addslashes($un->fon_codigo) . "'";
             $json .= ",'" . addslashes(utf8_decode($un->uni_descripcion)) . "'";
             $json .= ",'" . addslashes(utf8_decode($un->ser_categoria)) . "'";
             //$json .= ",'" . addslashes(utf8_decode($un->exp_titulo)) . "'";
             //$json .= ",'" . addslashes(utf8_decode($un->cue_descripcion)) . "'";
             if ($un->fil_subtitulo) {
                 $json .= ",'" . addslashes(utf8_decode($un->fil_titulo . " - " . $un->fil_subtitulo)) . "'";
             } else {
                 $json .= ",'" . addslashes(utf8_decode($un->fil_titulo)) . "'";
             }
             $json .= ",'" . addslashes($un->fil_tomovol) . "'";
             $json .= ",'" . addslashes(utf8_decode($un->fil_proc)) . "'";
             $json .= ",'" . addslashes(utf8_decode($un->fil_firma)) . "'";
             $json .= ",'" . addslashes(utf8_decode($un->fil_cargo)) . "'";
             $json .= ",'" . addslashes($un->fil_nrofoj) . "'";
             $json .= ",'" . addslashes($un->fil_nrocaj) . "'";
             $json .= ",'" . addslashes($un->fil_sala) . "'";
             $json .= ",'" . addslashes($un->fil_estante) . "'";
             $json .= ",'" . addslashes($un->fil_cuerpo) . "'";
             $json .= ",'" . addslashes($un->fil_balda) . "'";
             $json .= ",'" . addslashes($un->fil_tipoarch) . "'";
             $json .= ",'" . addslashes($un->fil_mrb) . "'";
             $json .= ",'" . addslashes($un->fil_ori) . "'";
             $json .= ",'" . addslashes($un->fil_cop) . "'";
             $json .= ",'" . addslashes($un->fil_fot) . "'";
             //palabras clave
             $palclave = new palclave();
             $fil_palclave = $palclave->listaPCFile($un->fil_id);
             $json .= ",'" . addslashes($fil_palclave) . "'";
             $json .= ",'" . addslashes(utf8_decode($un->fil_obs)) . "'";
             // SIACO
             $json .= ",'" . addslashes($un->fil_nur) . "'";
             $json .= ",'" . addslashes(utf8_decode($un->fil_asunto)) . "'";
             $json .= "]}";
             $rc = true;
             $exp_titulo = $un->exp_titulo;
         }
     }
     $json .= "]\n";
     $json .= "}";
     echo $json;
 }
 function loadDoc()
 {
     // Search
     $usuario = new usuario();
     $tarchivo = new tab_archivo();
     $tarchivo->setRequest2Object($_REQUEST);
     // Hasta aqui
     $valor = "";
     $id_listar = "";
     if (isset($_SESSION['id_lista'])) {
         $id_listar = $_SESSION['id_lista'];
     }
     $page = $_REQUEST['page'];
     $rp = $_REQUEST['rp'];
     $sortname = $_REQUEST['sortname'];
     $sortorder = $_REQUEST['sortorder'];
     if (!$sortname) {
         $sortname = " f.fon_cod,\r\n                        tab_unidad.uni_cod,\r\n                        tab_series.ser_orden,\r\n                        tab_series.ser_codigo,\r\n                        tab_expediente.exp_codigo::int,\r\n                        tab_archivo.fil_nro::int  ";
     } else {
         $sortname = $sortname;
     }
     if (!$sortorder) {
         $sortorder = 'desc';
     }
     $sort = "ORDER BY {$sortname} {$sortorder}";
     if (!$page) {
         $page = 1;
     }
     if (!$rp) {
         $rp = 20;
     }
     $start = ($page - 1) * $rp;
     $limit = "LIMIT {$rp} OFFSET {$start} ";
     $query = $_REQUEST['query'];
     $qtype = $_REQUEST['qtype'];
     $where = "";
     if ($query) {
         if ($qtype) {
         }
     }
     $whereUsuario = "";
     $usu_id = $_SESSION['USU_ID'];
     if ($_SESSION['ROL_COD'] != 'AA') {
         $whereUsuario = " AND tab_expusuario.usu_id=" . $_SESSION['USU_ID'] . "";
     }
     // Search docs
     $select = "SELECT\r\n                tab_expediente.exp_id,\r\n                tab_archivo.fil_id,\r\n                f.fon_codigo,\r\n                f.fon_cod,\r\n                tab_unidad.uni_cod,\r\n                tab_tipocorr.tco_codigo,\r\n                tab_series.ser_codigo,\r\n                tab_expediente.exp_codigo,\r\n                tab_archivo.fil_nro,\r\n                tab_unidad.uni_descripcion,\r\n                tab_series.ser_categoria,\r\n                tab_expisadg.exp_titulo,\r\n                tab_cuerpos.cue_descripcion,\r\n                tab_archivo.fil_confidencialidad,\r\n                tab_archivo.fil_titulo,\r\n                tab_archivo.fil_subtitulo,\r\n                tab_archivo.fil_proc,\r\n                tab_archivo.fil_firma,\r\n                tab_archivo.fil_cargo,\r\n                tab_archivo.fil_nrofoj,\r\n                tab_archivo.fil_tomovol,\r\n                tab_archivo.fil_nroejem,\r\n                tab_archivo.fil_nrocaj,\r\n                tab_archivo.fil_sala,\r\n                tab_archivo.fil_estante,\r\n                tab_archivo.fil_cuerpo,\r\n                tab_archivo.fil_balda,\r\n                tab_archivo.fil_tipoarch,\r\n                tab_archivo.fil_mrb,\r\n                tab_archivo.fil_ori,\r\n                tab_archivo.fil_cop,\r\n                tab_archivo.fil_fot,\r\n                (SELECT fil_nur FROM tab_doccorr WHERE tab_doccorr.fil_id=tab_archivo.fil_id AND tab_doccorr.dco_estado = '1' ) AS fil_nur,\r\n                (SELECT fil_asunto FROM tab_doccorr WHERE tab_doccorr.fil_id=tab_archivo.fil_id AND tab_doccorr.dco_estado = '1' ) AS fil_asunto,\r\n                tab_archivo.fil_obs,\r\n                tab_expusuario.usu_id";
     $from = "FROM\r\n                tab_fondo as f\r\n                INNER JOIN tab_unidad ON f.fon_id = tab_unidad.fon_id\r\n                INNER JOIN tab_series ON tab_unidad.uni_id = tab_series.uni_id\r\n                INNER JOIN tab_tipocorr ON tab_tipocorr.tco_id = tab_series.tco_id\r\n                INNER JOIN tab_expediente ON tab_series.ser_id = tab_expediente.ser_id\r\n                INNER JOIN tab_expisadg ON tab_expediente.exp_id = tab_expisadg.exp_id\r\n                INNER JOIN tab_expusuario ON tab_expediente.exp_id = tab_expusuario.exp_id\r\n                LEFT JOIN tab_exparchivo ON tab_expediente.exp_id = tab_exparchivo.exp_id\r\n                INNER JOIN tab_archivo ON tab_archivo.fil_id = tab_exparchivo.fil_id\r\n                INNER JOIN tab_cuerpos ON tab_cuerpos.cue_id = tab_exparchivo.cue_id\r\n                INNER JOIN tab_tramitecuerpos ON tab_cuerpos.cue_id = tab_tramitecuerpos.cue_id\r\n                INNER JOIN tab_tramite ON tab_tramite.tra_id = tab_tramitecuerpos.tra_id\r\n                WHERE\r\n                f.fon_estado = 1 AND\r\n                tab_unidad.uni_estado = 1 AND\r\n                tab_tipocorr.tco_estado = 1 AND\r\n                tab_series.ser_estado = 1 AND\r\n                tab_expediente.exp_estado = 1 AND\r\n                tab_archivo.fil_estado = 1 AND\r\n                tab_exparchivo.exa_estado = 1 AND\r\n                tab_expusuario.eus_estado = 1\r\n                {$whereUsuario} ";
     $where = "";
     // Search addwords
     if ($id_listar != "") {
         $explode = explode(",", $id_listar);
         $cantidad = count($explode);
         if ($cantidad > 0) {
             $valor .= "tab_archivo.fil_id=0 OR ";
             for ($i = 0; $i < $cantidad; $i++) {
                 $valor .= "tab_archivo.fil_id=" . $explode[$i];
                 if ($i < $cantidad - 1) {
                     $valor .= " or ";
                 }
             }
         }
         $where .= " AND {$valor} ";
     }
     // MODIFICADO
     //$sort = "ORDER BY tab_expediente.exp_id, tab_cuerpos.cue_id, tab_archivo.fil_nro ";
     //$sort = "ORDER BY tab_series.ser_orden, tab_expediente.exp_codigo::int, tab_archivo.fil_nro::int ";
     $sql = "{$select} {$from} {$where} {$sort} {$limit}";
     $result = $tarchivo->dbSelectBySQL($sql);
     //print $sql;
     $sql_c = "SELECT COUNT(tab_archivo.fil_id) {$from} {$where} ";
     $total = $tarchivo->countBySQL($sql_c);
     $exp = new expediente();
     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
     header("Cache-Control: no-cache, must-revalidate");
     header("Pragma: no-cache");
     header("Content-type: text/x-json");
     $json = "";
     $json .= "{\n";
     $json .= "page: {$page},\n";
     $json .= "total: {$total},\n";
     $json .= "rows: [";
     $rc = false;
     $i = 0;
     $j = 1;
     $exp_titulo = "";
     foreach ($result as $un) {
         // Documento
         if ($rc) {
             $json .= ",";
         }
         $json .= "\n{";
         $json .= "id:'" . $un->fil_id . "',";
         $json .= "cell:[";
         $json .= "'<input id=\"chkid_" . $un->fil_id . "\" restric=\"" . $un->fil_confidencialidad . "\" class=\"fil_chk" . $j . "\" type=\"checkbox\" value=\"" . $un->fil_id . "\" checked=\"checked\" />'";
         //            $json .= ",'<img src=\"" . PATH_DOMAIN . "/web/lib/32/document-$un->fil_extension.png\" file=\"$un->fil_id\" valueId=\"" . $un->fil_id . "\" restric=\"" . $un->fil_confidencialidad . "\" class=\"viewFile icon\"  />'";
         $json .= ",'<img src=\"" . PATH_DOMAIN . "/web/lib/32/document-.png\" file=\"{$un->fil_id}\" valueId=\"" . $un->fil_id . "\" restric=\"" . $un->fil_confidencialidad . "\" class=\"viewFile icon\"  />'";
         $json .= ",'<img src=\"" . PATH_DOMAIN . "/web/lib/32/b_view.png\" file=\"{$un->fil_id}\" valueId=\"" . $un->fil_id . "\" restric=\"" . $un->fil_confidencialidad . "\" class=\"view icon\" />'";
         $json .= ",'" . $un->fil_id . "'";
         $json .= ",'" . addslashes($un->fon_cod . DELIMITER . $un->uni_cod . DELIMITER . $un->tco_codigo . DELIMITER . $un->ser_codigo . DELIMITER . $un->exp_codigo . DELIMITER . $un->fil_nro) . "'";
         $json .= ",'" . addslashes($usuario->getRol($un->usu_id)) . "'";
         $json .= ",'" . addslashes($un->fon_codigo) . "'";
         $json .= ",'" . addslashes(utf8_decode($un->uni_descripcion)) . "'";
         $json .= ",'" . addslashes(utf8_decode($un->ser_categoria)) . "'";
         $json .= ",'" . addslashes(utf8_decode($un->exp_titulo)) . "'";
         //$json .= ",'" . addslashes(utf8_decode($un->cue_descripcion)) . "'";
         if ($un->fil_subtitulo) {
             $json .= ",'" . addslashes(utf8_decode($un->fil_titulo . " - " . $un->fil_subtitulo)) . "'";
         } else {
             $json .= ",'" . addslashes(utf8_decode($un->fil_titulo)) . "'";
         }
         $json .= ",'" . addslashes($un->fil_tomovol) . "'";
         $json .= ",'" . addslashes(utf8_decode($un->fil_proc)) . "'";
         $json .= ",'" . addslashes(utf8_decode($un->fil_firma)) . "'";
         $json .= ",'" . addslashes(utf8_decode($un->fil_cargo)) . "'";
         $json .= ",'" . addslashes($un->fil_nrofoj) . "'";
         $json .= ",'" . addslashes($un->fil_nrocaj) . "'";
         $json .= ",'" . addslashes($un->fil_sala) . "'";
         $json .= ",'" . addslashes($un->fil_estante) . "'";
         $json .= ",'" . addslashes($un->fil_cuerpo) . "'";
         $json .= ",'" . addslashes($un->fil_balda) . "'";
         $json .= ",'" . addslashes($un->fil_tipoarch) . "'";
         $json .= ",'" . addslashes($un->fil_mrb) . "'";
         $json .= ",'" . addslashes($un->fil_ori) . "'";
         $json .= ",'" . addslashes($un->fil_cop) . "'";
         $json .= ",'" . addslashes($un->fil_fot) . "'";
         //palabras clave
         $palclave = new palclave();
         $fil_palclave = $palclave->listaPCFile($un->fil_id);
         $json .= ",'" . addslashes($fil_palclave) . "'";
         $json .= ",'" . addslashes(utf8_decode($un->fil_obs)) . "'";
         // SIACO
         $json .= ",'" . addslashes($un->fil_nur) . "'";
         $json .= ",'" . addslashes(utf8_decode($un->fil_asunto)) . "'";
         $json .= "]}";
         $rc = true;
         $i++;
         $j++;
     }
     $json .= "]\n";
     $json .= "}";
     echo $json;
 }