function download()
 {
     /*         * *************************************************** */
     /* TYPE SAVE  */
     /*         * *************************************************** */
     $sis_tipcarga = 1;
     //
     $pasaje_viatico = new tab_pasaje_viatico();
     //
     // A BD
     if ($sis_tipcarga == 2) {
         $error = "";
         /*
                       if (isset ( $_COOKIE [session_name ()] )) {
                       if (session_is_registered ( 'USU_ID' )) { */
         if (isset($_POST['dov_id_open'])) {
             $dov_id = $_POST['dov_id_open'];
         } else {
             $dov_id = VAR3;
         }
         if ($dov_id != '') {
             $documento_viaje = new tab_documento_viaje();
             $rowe = $documento_viaje->dbSelectBySQL("SELECT * FROM tab_documento_viaje WHERE dov_id =  '" . $dov_id . "'");
             if (count($rowe) == 1) {
                 $sql = "SELECT\r\n                            tab_documento_viaje.dov_id,\r\n                            tab_documento_viaje.fil_nomoriginal,\r\n                            tab_documento_viaje.fil_nomcifrado,\r\n                            tab_documento_viaje.fil_tamano,\r\n                            tab_documento_viaje.fil_extension,\r\n                            tab_documento_viaje.fil_tipo,\r\n                            coalesce(tab_documento_viajebin.fil_contenido,'-1') as fil_contenido\r\n                            FROM\r\n                            tab_documento_viaje\r\n                            Inner Join tab_documento_viajebin ON tab_documento_viaje.dov_id = tab_documento_viajebin.dov_id WHERE tab_documento_viajebin.dov_id =  '" . $dov_id . "'";
                 $r_files = $documento_viaje->dbSelectBySQLArchive($sql);
                 //
                 $link = $pasaje_viatico->connect();
                 $sql = "select dov_id, nombre, mime, size, coalesce(archivo_oid,'-1') as archivo_oid, coalesce(archivo_bytea,'-1') as archivo_bytea from tab_documento_viaje where dov_id={$dov_id}";
                 $result = pg_query($link, $sql);
                 if (!$result || pg_num_rows($result) < 1) {
                     header("Location: index.php");
                     exit;
                 }
                 $row = pg_fetch_array($result, 0);
                 pg_free_result($result);
                 if ($row['archivo_bytea'] == -1 && $row['archivo_oid'] == -1) {
                     die('No existe el archivo para mostrar o bajar');
                 }
                 pg_query($link, "begin");
                 $file = pg_lo_open($link, $row['archivo_oid'], "r");
                 header("Cache-control: private");
                 header("Content-type: {$row['mime']}");
                 //if($f==1) header("Content-Disposition: attachment; filename=\"$row[nombre]\"");
                 header("Content-length: {$row['size']}");
                 header("Expires: " . gmdate("D, d M Y H:i:s", mktime(date("H") + 2, date("i"), date("s"), date("m"), date("d"), date("Y"))) . " GMT");
                 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
                 header("Cache-Control: no-cache, must-revalidate");
                 header("Pragma: no-cache");
                 pg_lo_read_all($file);
                 pg_lo_close($file);
                 pg_query($link, "commit");
                 pg_close($link);
             } else {
                 $error = "No existe el archivo.";
             }
         } else {
             $error = 'No existe el archivo.';
         }
     } else {
         // A SERVER
         $error = "";
         if (isset($_POST['dov_id_open'])) {
             $dov_id = $_POST['dov_id_open'];
         } else {
             $dov_id = VAR3;
         }
         if ($dov_id != '') {
             //
             $link = $pasaje_viatico->connect();
             $sql = "SELECT dov_id, \r\n                               pav_id, \r\n                               dov_nombre, \r\n                               dov_mime, \r\n                               dov_size, \r\n                               coalesce(dov_archivo_oid,'-1') as archivo_oid, \r\n                               coalesce(dov_archivo_bytea,'-1') as archivo_bytea \r\n                               FROM tab_documento_viaje \r\n                               WHERE dov_id = {$dov_id} ";
             $result = pg_query($link, $sql);
             if (!$result || pg_num_rows($result) < 1) {
                 header("Location: index.php");
                 exit;
             }
             $row = pg_fetch_array($result, 0);
             // Data Parameters
             $nombreDirectorio = "";
             $tsistema = new tab_sistema();
             $sql = "SELECT *\r\n                        FROM tab_sistema";
             $rows2 = $tsistema->dbselectBySQL($sql);
             if (count($rows2) >= 1) {
                 $sis_tipcarga = $rows2[0]->sis_tipcarga;
                 $sis_tammax = $rows2[0]->sis_tammax;
                 $nombreDirectorio = $rows2[0]->sis_ruta;
             }
             $archivopdf = $nombreDirectorio . $row[2];
             $len = filesize($archivopdf);
             //$archivopdf = PATH_DOMAIN ."/". $nombreDirectorio . $row[1];
             //$len = filesize($archivopdf);
             header("Cache-control: private");
             //header("Content-type: $row[mime]");
             header("Content-type: {$row['3']}");
             //header("Content-Disposition: attachment; filename='".$archivopdf."'");
             header("Content-length: {$len}");
             header("Expires: " . gmdate("D, d M Y H:i:s", mktime(date("H") + 2, date("i"), date("s"), date("m"), date("d"), date("Y"))) . " GMT");
             header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
             header("Cache-Control: no-cache, must-revalidate");
             header("Pragma: no-cache");
             readfile($archivopdf);
             pg_free_result($result);
             pg_close($link);
         }
     }
     if ($error != '') {
         echo $error;
     }
 }