function update()
 {
     $this->expediente = new tab_expediente();
     $this->expediente->setRequest2Object($_REQUEST);
     $rows2 = $this->expediente->dbselectByField("exp_id", $_REQUEST['exp_id']);
     $row2 = $rows2[0];
     $exp_id = $row2->exp_id;
     //        $this->expediente->setExp_id($_REQUEST['exp_id']);
     $this->expediente->setExp_id($row2->exp_id);
     $this->expediente->setSer_id($_REQUEST['ser_id']);
     if ($_REQUEST['ser_corr'] == 'AUTO') {
         $this->expediente->setExp_codigo($_REQUEST['exp_codigo']);
     } else {
         $this->expediente->setExp_codigo($_REQUEST['exp_codigo']);
     }
     $this->expediente->setExp_lugar(strtoupper($_REQUEST['exp_lugar']));
     $this->expediente->setSof_id($_REQUEST['sof_id']);
     $this->expediente->setExp_nrofoj(strtoupper($_REQUEST['exp_nrofoj']));
     $this->expediente->setExp_tomovol(strtoupper($_REQUEST['exp_tomovol']));
     $this->expediente->setExp_nroejem(strtoupper($_REQUEST['exp_nroejem']));
     $this->expediente->setExp_nrocaj(strtoupper($_REQUEST['exp_nrocaj']));
     $this->expediente->setExp_sala(strtoupper($_REQUEST['exp_sala']));
     $this->expediente->setExp_estante(strtoupper($_REQUEST['exp_estante']));
     $this->expediente->setExp_cuerpo(strtoupper($_REQUEST['exp_cuerpo']));
     $this->expediente->setExp_balda(strtoupper($_REQUEST['exp_balda']));
     if ($_REQUEST['exp_ori']) {
         $this->expediente->setExp_ori($_REQUEST['exp_ori']);
     } else {
         $this->expediente->setExp_ori(0);
     }
     if ($_REQUEST['exp_cop']) {
         $this->expediente->setExp_cop($_REQUEST['exp_cop']);
     } else {
         $this->expediente->setExp_cop(0);
     }
     if ($_REQUEST['exp_fot']) {
         $this->expediente->setExp_fot($_REQUEST['exp_fot']);
     } else {
         $this->expediente->setExp_fot(0);
     }
     $this->expediente->setExp_obs($_REQUEST['exp_obs']);
     $this->expediente->setExp_corr($_REQUEST['exp_corr']);
     $this->expediente->setExp_estado(1);
     $this->expediente->setExp_mexcel(0);
     $this->expediente->update2();
     // isadg
     $this->tab_expisadg = new tab_expisadg();
     $rows = $this->tab_expisadg->dbselectByField("exp_id", $_REQUEST['exp_id']);
     $row = $rows[0];
     $this->tab_expisadg->setEig_id($row->eig_id);
     $this->tab_expisadg->setExp_id($_REQUEST['exp_id']);
     $this->tab_expisadg->setExp_titulo(strtoupper(trim($_REQUEST['exp_titulo'])));
     if ($_REQUEST['exp_anioi'] == "") {
         $anioi = " ";
     } else {
         $anioi = $_REQUEST['exp_anioi'];
     }
     if ($_REQUEST['exp_aniof'] == "") {
         $aniof = " ";
     } else {
         $aniof = $_REQUEST['exp_aniof'];
     }
     if ($_REQUEST['exp_mesi'] == "") {
         $mesi = " ";
     } else {
         $mesi = $_REQUEST['exp_mesi'];
     }
     if ($_REQUEST['exp_mesf'] == "") {
         $mesf = " ";
     } else {
         $mesf = $_REQUEST['exp_mesf'];
     }
     $this->tab_expisadg->setExp_fecha_exi($_REQUEST['exp_fecha_exi']);
     $this->tab_expisadg->setExp_mesi($mesi);
     $this->tab_expisadg->setExp_anioi($anioi);
     $this->tab_expisadg->setExp_fecha_exf($_REQUEST['exp_fecha_exf']);
     $this->tab_expisadg->setExp_mesf($mesf);
     $this->tab_expisadg->setExp_aniof($aniof);
     $this->tab_expisadg->setExp_volsop(strtoupper(trim($_REQUEST['exp_volsop'])));
     $this->tab_expisadg->setExp_nomprod(strtoupper(trim($_REQUEST['exp_nomprod'])));
     $this->tab_expisadg->setExp_hisins(strtoupper(trim($_REQUEST['exp_hisins'])));
     $this->tab_expisadg->setExp_hisarc(strtoupper(trim($_REQUEST['exp_hisarc'])));
     $this->tab_expisadg->setExp_foring(strtoupper(trim($_REQUEST['exp_foring'])));
     $this->tab_expisadg->setExp_alccon(strtoupper(trim($_REQUEST['exp_alccon'])));
     $this->tab_expisadg->setExp_vaseel(strtoupper(trim($_REQUEST['exp_vaseel'])));
     $this->tab_expisadg->setExp_nueing(strtoupper(trim($_REQUEST['exp_nueing'])));
     $this->tab_expisadg->setExp_org(strtoupper(trim($_REQUEST['exp_org'])));
     $this->tab_expisadg->setExp_conacc(strtoupper(trim($_REQUEST['exp_conacc'])));
     $this->tab_expisadg->setExp_conrep(strtoupper(trim($_REQUEST['exp_conrep'])));
     $this->tab_expisadg->setIdi_id($_REQUEST['idi_id']);
     $this->tab_expisadg->setExp_carfis(strtoupper(trim($_REQUEST['exp_carfis'])));
     $this->tab_expisadg->setExp_insdes(strtoupper(trim($_REQUEST['exp_insdes'])));
     $this->tab_expisadg->setExp_exloor(strtoupper(trim($_REQUEST['exp_exloor'])));
     $this->tab_expisadg->setExp_exloco(strtoupper(trim($_REQUEST['exp_exloco'])));
     $this->tab_expisadg->setExp_underel(strtoupper(trim($_REQUEST['exp_underel'])));
     $this->tab_expisadg->setExp_notpub(strtoupper(trim($_REQUEST['exp_notpub'])));
     $this->tab_expisadg->setExp_notas(strtoupper(trim($_REQUEST['exp_notas'])));
     $this->tab_expisadg->setExp_notarc(strtoupper(trim($_REQUEST['exp_notarc'])));
     $this->tab_expisadg->setExp_regnor(strtoupper(trim($_REQUEST['exp_regnor'])));
     $this->tab_expisadg->setExp_estado(1);
     $this->tab_expisadg->update();
     // Update dynamic data
     $expcampo = new expcampo();
     $rows3 = $expcampo->obtenerCampos($_REQUEST['ser_id']);
     if (count($rows3) > 0) {
         foreach ($rows3 as $val) {
             if ($val->ecp_tipdat == 'Lista') {
                 $ecp_id = $val->ecp_id;
                 $ecp_valor = $_REQUEST[$ecp_id];
                 $expcampovalor = new expcampovalor();
                 $ecv_id = $expcampovalor->obtenerIdCampoValorporExpediente($ecp_id, $exp_id);
                 if ($ecv_id == 0) {
                     $this->expcampovalor = new tab_expcampovalor();
                     $this->expcampovalor->setExp_id($exp_id);
                     $this->expcampovalor->setEcp_id($ecp_id);
                     $this->expcampovalor->setEcl_id($ecp_valor);
                     $this->expcampovalor->setEcv_valor($ecp_valor);
                     $this->expcampovalor->setEcv_estado(1);
                     $this->expcampovalor->insert();
                 } else {
                     $this->expcampovalor = new tab_expcampovalor();
                     $this->expcampovalor->setEcv_id($ecv_id);
                     $this->expcampovalor->setExp_id($exp_id);
                     $this->expcampovalor->setEcp_id($ecp_id);
                     $this->expcampovalor->setEcl_id($ecp_valor);
                     $this->expcampovalor->setEcv_valor($ecp_valor);
                     $this->expcampovalor->setEcv_estado(1);
                     $this->expcampovalor->update();
                 }
             } else {
                 $ecp_id = (string) $val->ecp_id;
                 $ecp_valor = $_REQUEST[$ecp_id];
                 $expcampovalor = new expcampovalor();
                 $ecv_id = $expcampovalor->obtenerIdCampoValorporExpediente($ecp_id, $exp_id);
                 if ($ecv_id == 0) {
                     $this->expcampovalor = new tab_expcampovalor();
                     $this->expcampovalor->setExp_id($exp_id);
                     $this->expcampovalor->setEcp_id($ecp_id);
                     $this->expcampovalor->setEcv_valor($ecp_valor);
                     $this->expcampovalor->setEcv_estado(1);
                     $this->expcampovalor->insert();
                 } else {
                     $this->expcampovalor = new tab_expcampovalor();
                     $this->expcampovalor->setEcv_id($ecv_id);
                     $this->expcampovalor->setExp_id($exp_id);
                     $this->expcampovalor->setEcp_id($ecp_id);
                     $this->expcampovalor->setEcv_valor($ecp_valor);
                     $this->expcampovalor->setEcv_estado(1);
                     $this->expcampovalor->update();
                 }
             }
         }
     }
     $expusuario = new tab_expusuario();
     $row4 = $expusuario->dbselectByField("exp_id", $_REQUEST['exp_id']);
     if (count($row4) == 0) {
         $this->expusuario = new Tab_expusuario();
         $this->expusuario->eus_id = '';
         $this->expusuario->exp_id = $_REQUEST['exp_id'];
         $this->expusuario->usu_id = $_SESSION['USU_ID'];
         $this->expusuario->eus_fecha_crea = date("Y-m-d");
         $this->expusuario->eus_estado = '1';
         $this->expusuario->insert();
     }
     // Keywords
     $this->palclave = new tab_palclave();
     $this->palclave->deleteByField("exp_id", $exp_id);
     if (!empty($_REQUEST['exp_descripcion'])) {
         $pac_nombre = trim($_REQUEST['exp_descripcion']);
         $array = explode(SEPARATOR_SEARCH, $pac_nombre);
         for ($j = 0; $j < count($array); $j++) {
             if ($array[$j] != '') {
                 $this->palclave->setExp_id($exp_id);
                 $this->palclave->setPac_nombre(strtoupper(trim($array[$j])));
                 $this->palclave->setPac_formulario('Expediente');
                 $this->palclave->setPac_estado(1);
                 $this->palclave->insert();
             }
         }
     }
     if ($_REQUEST['accion'] == 'guardarsinsalir') {
         $msm_guardado_archivo = 1;
         Header("Location: " . PATH_DOMAIN . "/expediente/view/" . $_REQUEST['exp_id'] . "/" . $msm_guardado_archivo . "/");
     } else {
         if ($_REQUEST['accion'] == 'guardarnuevo') {
             $_SESSION['SER_ID'] = $_REQUEST['ser_id'];
             $this->add();
         } else {
             if ($_REQUEST['accion'] == 'guardar') {
                 Header("Location: " . PATH_DOMAIN . "/expediente/index/");
             } else {
                 Header("Location: " . PATH_DOMAIN . "/expediente/index/");
             }
         }
     }
 }