Exemple #1
0
 public function write($data)
 {
     if (!($e = $this->_firstUse())) {
         return $e;
     }
     $ok = @pg_lo_write($this->_blob, $data);
     if ($ok === false) {
         return $this->_raiseError('add data to');
     }
     return true;
 }
Exemple #2
0
 function write($data)
 {
     if (!($e = $this->_firstUse())) {
         return $e;
     }
     $ok = pg_lo_write($this->blob, $data);
     if ($ok === false) {
         return $this->_setDbError('add data to');
     }
     return true;
 }
 /**
  * Escreve objeto oid com o arquivo informado
  * @param integer $iOid
  * @param string  $sCaminhoArquivo
  * @return boolean
  */
 public static function escrita($sCaminhoArquivo, $iOid = null)
 {
     global $conn;
     if (!db_utils::inTransaction()) {
         throw new Exception("Sem transação Ativa.");
     }
     $rsLargeObject = pg_lo_open($conn, $iOid, "w");
     $sConteudoArquivo = file_get_contents($sCaminhoArquivo);
     $escrita = pg_lo_write($rsLargeObject, $sConteudoArquivo);
     return $escrita;
 }
Exemple #4
0
 function large_object_create($table, $file)
 {
     trigger_before('large_object_create', $this, $this);
     $return = false;
     if (!file_exists($file)) {
         return $return;
     }
     $filename = basename($file);
     if (!$filename) {
         trigger_error("Error determining base name of large object file {$filename}", E_USER_ERROR);
     }
     $handle = fopen($file, "r");
     if (!$handle) {
         trigger_error("Error opening large object file {$file}", E_USER_ERROR);
     }
     $buffer = fread($handle, filesize($file));
     if (!$buffer) {
         trigger_error("Error reading large object file {$file}", E_USER_ERROR);
     }
     $result = fclose($handle);
     $result = @pg_query($this->conn, "BEGIN");
     if (!$result) {
         trigger_error("error starting l_o_c transaction: " . @pg_last_error($this->conn), E_USER_ERROR);
     }
     $oid = @pg_lo_create($this->conn);
     if (!$oid) {
         trigger_error("error in pg_l_o_c: " . @pg_last_error($this->conn), E_USER_ERROR);
     }
     #$result = pg_query($this->conn,"UPDATE $table SET $field = $oid WHERE $pkfield = '$pkvalue'");
     #if (!$result) { trigger_error("Error updating file OID", E_USER_ERROR ); }
     $handle = @pg_lo_open($this->conn, $oid, "w");
     if (!$handle) {
         trigger_error("error in pg_l_o_o: " . @pg_last_error($this->conn), E_USER_ERROR);
     }
     $result = @pg_lo_write($handle, $buffer);
     if (!$result) {
         trigger_error("error in l_o_w: " . @pg_last_error($this->conn), E_USER_ERROR);
     }
     $result = @pg_lo_close($handle);
     if (!$result) {
         trigger_error("error in l_o_close: " . @pg_last_error($this->conn), E_USER_ERROR);
     }
     $result = @pg_query($this->conn, "COMMIT");
     if (!$result) {
         trigger_error("error committing l_o_c transaction: " . @pg_last_error($this->conn), E_USER_ERROR);
     } else {
         $return = $oid;
     }
     return $return;
 }
 protected function _execute()
 {
     $los =& $this->_driver->los;
     $params = array();
     if ($this->_bound_params) {
         foreach ($this->_bound_params as $k => &$p) {
             $param =& $p[0];
             switch ($p[1]) {
                 case PDO::PARAM_LOB:
                     if (is_resource($param)) {
                         if (isset($los[$param])) {
                             $pos = ftell($param);
                             rewind($param);
                             $lo_stream = $los[(int) $param][1];
                             while (!feof($param)) {
                                 pg_lo_write($lo_stream, fread($param, 8192));
                             }
                             pg_lo_close($lo_stream);
                             fseek($param, $pos);
                             $params[$k] = $los[(int) $param][0];
                         } else {
                             $buffer =& $params[$k];
                             while (!feof($param)) {
                                 $buffer .= fread($param, 8192);
                             }
                         }
                     } else {
                         $params[$k] =& $param;
                     }
                     break;
                 case PDO::PARAM_BOOL:
                     $params[$k] = $param ? 'TRUE' : 'FALSE';
                     break;
                 default:
                     $params[$k] =& $param;
                     break;
             }
         }
     }
     if (!($result = @pg_execute($this->_link, $this->_result_name, $params))) {
         $this->_set_stmt_error(null, PDO::ERRMODE_SILENT, 'execute');
         return false;
     }
     $this->_result = $result;
     return true;
 }
Exemple #6
0
 function stream_write($data)
 {
     return pg_lo_write($this->handle, $data);
 }
Exemple #7
0
function DB_lo_write($fp, $data)
{
    if (strcmp(phpversion(), '4.2.0') < 0) {
        return pg_lowrite($fp, $data);
    } else {
        return pg_lo_write($fp, $data);
    }
}
Exemple #8
0
 function Write($data)
 {
     if (!$this->oid || $this->error) {
         echo "{$this->error}<br>\n";
     } else {
         if (version_compare(phpversion(), "4.2.0", "ge") > 0) {
             $this->error = pg_lo_write($this->result, $data);
         } else {
             $this->error = pg_lowrite($this->result, $data);
         }
     }
 }
 function update()
 {
     $ser_id = $_REQUEST["ser_id"];
     $exp_id = $_REQUEST["exp_id"];
     $tra_id = $_REQUEST["tra_id"];
     $cue_id = $_REQUEST["cue_id"];
     // file
     $this->archivo = new tab_archivo();
     $this->archivo->setRequest2Object($_REQUEST);
     $this->archivo->setFil_id($_REQUEST['dov_id']);
     $msm_guardado_archivo = 0;
     if ($_FILES["archivo"]["error"] == 4) {
     } else {
         // Digital file
         $archivo_digital = new tab_archivo_digital();
         $archivo_type = $_FILES["archivo"]["type"];
         $archivo = $_FILES["archivo"]["tmp_name"];
         $archivo_size = $_FILES["archivo"]["size"];
         $archivo_name = $_FILES["archivo"]["name"];
         $nombre = basename($_FILES["archivo"]["name"]);
         $nombreFichero = $_FILES["archivo"]["name"];
         $archivo_name_array = explode(".", $archivo_name);
         $archivo_ext = array_pop($archivo_name_array);
         $archivo_cifrado = md5($archivo_name);
         $sis_tammax = 0;
         // Data Parameters
         $sis_tipcarga = 2;
         $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;
         }
         // Verify size
         if ($archivo_size > $sis_tammax) {
             $errores["archivo"] = "El tamanio del fichero supera el limite permitido ({$maxsize} bytes)!";
             $error = true;
         } else {
             $nombreArchivo = $_FILES['archivo']['name'];
             if ($nombreArchivo == "") {
             } else {
                 if ($sis_tipcarga == 2) {
                     $error = false;
                     $copiarFichero = false;
                     if (is_uploaded_file($_FILES['archivo']['tmp_name'])) {
                         $nombreFichero = $_FILES['archivo']['name'];
                         $copiarFichero = true;
                         $nombreCompleto = $nombreDirectorio . $nombreFichero;
                         if (is_file($nombreCompleto)) {
                             $idUnico = time();
                             $nombreFichero = $idUnico . "-" . $nombreFichero;
                         }
                     } else {
                         if ($_FILES['archivo']['error'] == UPLOAD_ERR_FORM_SIZE) {
                             $maxsize = $_REQUEST['MAX_FILE_SIZE'];
                             $errores["archivo"] = "El tamanio del fichero supera el limite permitido ({$maxsize} bytes)!";
                             $error = true;
                         } else {
                             if ($_FILES['archivo']['name'] == "") {
                                 $nombreFichero = '';
                             } else {
                                 $errores["archivo"] = "No se ha podido subir el fichero!";
                                 $msm_guardado_archivo = 0;
                                 $error = true;
                             }
                         }
                     }
                     if ($error == false) {
                         // Validate
                         $dov_id = $_REQUEST['dov_id'];
                         $rows = $archivo_digital->dbselectByField("dov_id", $dov_id);
                         if (count($rows)) {
                             $sql = "UPDATE tab_archivo_digital\r\n                                    SET fil_nomoriginal='{$nombreFichero}', \r\n                                        fil_nomcifrado='{$archivo_cifrado}', \r\n                                        fil_tipo='{$archivo_type}', \r\n                                        fil_tamano='{$archivo_size}', \r\n                                        fil_extension='{$archivo_ext}', \r\n                                        nombre='{$nombre}', \r\n                                        mime='{$archivo_type}', \r\n                                        size={$archivo_size}, \r\n                                        archivo='{$nombreFichero}', \r\n                                        dov_estado=1\r\n                                    WHERE dov_id = '{$dov_id}' ";
                             $link = $archivo_digital->connect();
                             pg_query($link, "begin");
                             pg_query($link, $sql) or die(pg_last_error($link));
                             pg_query($link, "commit");
                             if ($copiarFichero) {
                                 move_uploaded_file($_FILES['archivo']['tmp_name'], $nombreDirectorio . $nombreFichero);
                             }
                             $msm_guardado_archivo = 1;
                         } else {
                             $sql = "INSERT INTO tab_archivo_digital(dov_id,\r\n                                                            fil_nomoriginal,\r\n                                                            fil_nomcifrado,\r\n                                                            fil_tipo,\r\n                                                            fil_tamano,\r\n                                                            fil_extension,\r\n                                                            nombre,\r\n                                                            mime,\r\n                                                            size,\r\n                                                            archivo,\r\n                                                            dov_estado)\r\n                                                   VALUES ({$dov_id},\r\n                                                           '{$nombreFichero}',\r\n                                                           '{$archivo_cifrado}',\r\n                                                           '{$archivo_type}',\r\n                                                           '{$archivo_size}' ,\r\n                                                           '{$archivo_ext}' ,\r\n                                                           '{$nombre}',\r\n                                                           '{$archivo_type}',\r\n                                                           {$archivo_size},\r\n                                                           '{$nombreFichero}',\r\n                                                           1)";
                             $link = $archivo_digital->connect();
                             pg_query($link, "begin");
                             pg_query($link, $sql) or die(pg_last_error($link));
                             pg_query($link, "commit");
                             if ($copiarFichero) {
                                 move_uploaded_file($_FILES['archivo']['tmp_name'], $nombreDirectorio . $nombreFichero);
                             }
                             $msm_guardado_archivo = 1;
                         }
                     }
                 } else {
                     // Validate
                     $dov_id = $_REQUEST['dov_id'];
                     $rows = $this->series->dbselectByField("dov_id", $dov_id);
                     $row = $rows[0];
                     if (count($row)) {
                         $sql = "UPDATE tab_archivo_digital\r\n                            SET fil_nomoriginal='{$archivo_name}', \r\n                            fil_nomcifrado='{$archivo_cifrado}', \r\n                            fil_tipo='{$archivo_type}', \r\n                            fil_tamano='{$archivo_size}', \r\n                            fil_extension='{$archivo_ext}', \r\n                            nombre='{$nombre}', \r\n                            archivo_oid={$oid}, \r\n                            mime='{$archivo_type}', \r\n                            size={$archivo_size}, \r\n                            archivo='{$nombreFichero}', \r\n                            dov_estado=1\r\n                            WHERE dov_id = {$dov_id} ";
                         $link = $archivo_digital->connect();
                         $fp = fopen($archivo, "rb");
                         $contenido = fread($fp, filesize($archivo));
                         fclose($fp);
                         pg_query($link, "begin");
                         $oid = pg_lo_create($link);
                         pg_query($link, $sql) or die(pg_last_error($link));
                         $blob = pg_lo_open($link, $oid, "w");
                         pg_lo_write($blob, $contenido);
                         pg_lo_close($blob);
                         pg_query($link, "commit");
                         $msm_guardado_archivo = 1;
                         //"Se subio correctamente el archivo"
                     } else {
                         $sql = "INSERT INTO tab_archivo_digital(dov_id,\r\n                                                                fil_nomoriginal,\r\n                                                                fil_nomcifrado,\r\n                                                                fil_tipo,\r\n                                                                fil_tamano,\r\n                                                                fil_extension,\r\n                                                                nombre,\r\n                                                                archivo_oid,\r\n                                                                mime,\r\n                                                                size,\r\n                                                                archivo)\r\n                                                        VALUES ({$dov_id},\r\n                                                                '{$archivo_name}',\r\n                                                                '{$archivo_cifrado}',\r\n                                                                '{$archivo_type}',\r\n                                                                '{$archivo_size}',\r\n                                                                '{$archivo_ext}',\r\n                                                                '{$nombre}',\r\n                                                                {$oid},\r\n                                                                '{$archivo_type}',\r\n                                                                {$archivo_size},\r\n                                                                '{$nombreFichero}')";
                         $link = $archivo_digital->connect();
                         $fp = fopen($archivo, "rb");
                         $contenido = fread($fp, filesize($archivo));
                         fclose($fp);
                         pg_query($link, "begin");
                         $oid = pg_lo_create($link);
                         pg_query($link, $sql) or die(pg_last_error($link));
                         $blob = pg_lo_open($link, $oid, "w");
                         pg_lo_write($blob, $contenido);
                         pg_lo_close($blob);
                         pg_query($link, "commit");
                         $msm_guardado_archivo = 1;
                     }
                 }
             }
         }
     }
     $dov_id = $_REQUEST['dov_id'];
     // Forwarding
     if ($_REQUEST['accion'] == 'guardarsinsalir') {
         $msm_guardado_archivo = 1;
         Header("Location: " . PATH_DOMAIN . "/archivo/view/" . $exp_id . "/" . $dov_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 . "/archivo/viewTree/" . $exp_id . "/" . $msm_guardado_archivo . "/{$cue_id}/");
         } else {
             header("location:" . PATH_DOMAIN . "/archivo/viewTree/" . $exp_id . "/" . $msm_guardado_archivo . "/{$cue_id}/");
         }
     }
 }
Exemple #10
0
 function stream_write($data)
 {
     return pg_lo_write($this->loh, $data);
 }
 /**
  *
  */
 function lo_write($handle, $buffer)
 {
     return pg_lo_write($handle, $buffer);
 }
Exemple #12
0
 } elseif( substr($req,0,11) == 'blob_create' ) {
   list($oid) = sscanf( $req, 'blob_create %u' );
   pg_free_result( pg_query( $commit ? 'COMMIT' : 'ROLLBACK' ) );
   pg_free_result( pg_query( 'BEGIN' ) );
   $oid = pg_lo_create() or pgerr('lo_create failed');
   pg_free_result( pg_query( 'COMMIT' ) );
   pg_free_result( pg_query( 'BEGIN' ) );
   dump($oid);
 } elseif( substr($req,0,11) == 'blob_delete' ) {
   list($oid) = sscanf( $req, 'blob_delete %u' );
   $oid = pg_lo_unlink($oid) or pgerr('lo_unlink failed');
 } elseif( substr($req,0,10) == 'blob_write' ) {
   list($oid) = sscanf( $req, 'blob_write %s ' );
   $bin = substr($req,12+strlen($oid));
   $obj = pg_lo_open($oid,'w') or pgerr( 'lo_open failed' );
   $res = pg_lo_write($obj,$bin) or pgerr( 'lo_write failed' );
   pg_lo_close($obj);
   dump($res);
 } elseif( substr($req,0,9) == 'blob_read' ) {
   list($oid) = sscanf( $req, 'blob_read %u' );
   $obj = pg_lo_open($oid,'r') or pgerr( 'lo_open failed' );
   pg_lo_seek($obj,0,PGSQL_SEEK_END);
   $len = pg_lo_tell($obj);
   pg_lo_seek($obj,0,PGSQL_SEEK_SET);
   $res = pg_lo_read($obj,$len) or pgerr( 'lo_read failed' );
   pg_lo_close($obj);
   dump($res);
 } else {
   $result = pg_query($req) or pgerr("error at request: $req");
   if( pg_result_status($result) == PGSQL_COMMAND_OK ) {
     dump( 0 );
 function update()
 {
     $ser_id = $_REQUEST["ser_id"];
     $exp_id = $_REQUEST["exp_id"];
     $tra_id = $_REQUEST["tra_id"];
     $cue_id = $_REQUEST["cue_id"];
     // file
     $this->archivo = new tab_archivo();
     $this->archivo->setRequest2Object($_REQUEST);
     $this->archivo->setFil_id($_REQUEST['fil_id']);
     if ($_REQUEST['exp_corr'] == 'AUTO') {
         $this->archivo->setFil_codigo(strtoupper($_REQUEST['fil_codigo']));
         $this->archivo->setFil_nro(strtoupper($_REQUEST['fil_nro']));
     } else {
         $this->archivo->setFil_codigo(strtoupper($_REQUEST['fil_codigo']));
         $this->archivo->setFil_nro(strtoupper($_REQUEST['fil_nro']));
     }
     if ($_REQUEST['fil_titulo2']) {
         $this->archivo->setFil_titulo(strtoupper($_REQUEST['fil_titulo'] . " Nro. " . $_REQUEST['fil_titulo2']));
     } else {
         $this->archivo->setFil_titulo(strtoupper($_REQUEST['fil_titulo']));
     }
     $this->archivo->setFil_subtitulo(strtoupper($_REQUEST['fil_subtitulo']));
     //$this->archivo->setFil_fecha($_REQUEST['fil_fecha']);
     $this->archivo->setFil_mes($_REQUEST['fil_mes']);
     $this->archivo->setFil_anio($_REQUEST['fil_anio']);
     $this->archivo->setFil_mesf($_REQUEST['fil_mesf']);
     $this->archivo->setFil_aniof($_REQUEST['fil_aniof']);
     $this->archivo->setIdi_id($_REQUEST['idi_id']);
     $this->archivo->setFil_proc(strtoupper($_REQUEST['fil_proc']));
     $this->archivo->setFil_firma(strtoupper($_REQUEST['fil_firma']));
     $this->archivo->setFil_cargo(strtoupper($_REQUEST['fil_cargo']));
     $this->archivo->setFil_alccon(addslashes(htmlentities(strtoupper($_REQUEST['fil_alccon']))));
     $this->archivo->setSof_id($_REQUEST['sof_id']);
     $this->archivo->setFil_nrofoj(strtoupper($_REQUEST['fil_nrofoj']));
     $this->archivo->setFil_tomovol(strtoupper($_REQUEST['fil_tomovol']));
     $this->archivo->setFil_nroejem(strtoupper($_REQUEST['fil_nroejem']));
     $this->archivo->setFil_nrocaj(strtoupper($_REQUEST['fil_nrocaj']));
     $this->archivo->setFil_nropaq(strtoupper($_REQUEST['fil_nropaq']));
     $this->archivo->setFil_sala(strtoupper($_REQUEST['fil_sala']));
     $this->archivo->setFil_estante(strtoupper($_REQUEST['fil_estante']));
     $this->archivo->setFil_cuerpo(strtoupper($_REQUEST['fil_cuerpo']));
     $this->archivo->setFil_balda(strtoupper($_REQUEST['fil_balda']));
     $this->archivo->setFil_tipoarch($_REQUEST['fil_tipoarch']);
     if ($_REQUEST['fil_mrb']) {
         $this->archivo->setFil_mrb($_REQUEST['fil_mrb']);
     }
     $this->archivo->setFil_cantpaq(strtoupper(trim($_REQUEST['fil_cantpaq'])));
     $this->archivo->setFil_cantcaj(strtoupper(trim($_REQUEST['fil_cantcaj'])));
     if ($_REQUEST['fil_ori']) {
         $this->archivo->setFil_ori($_REQUEST['fil_ori']);
     } else {
         $this->archivo->setFil_ori(0);
     }
     if ($_REQUEST['fil_cop']) {
         $this->archivo->setFil_cop($_REQUEST['fil_cop']);
     } else {
         $this->archivo->setFil_cop(0);
     }
     if ($_REQUEST['fil_fot']) {
         $this->archivo->setFil_fot($_REQUEST['fil_fot']);
     } else {
         $this->archivo->setFil_fot(0);
     }
     $this->archivo->setFil_confidencialidad($_REQUEST['fil_confidencialidad']);
     $this->archivo->setFil_obs(strtoupper($_REQUEST['fil_obs']));
     $this->archivo->setFil_estado('1');
     $this->archivo->update3();
     $this->archivo->update();
     // Tab_doccorr
     if ($_REQUEST['fil_nur']) {
         $this->doccorr = new Tab_doccorr();
         $rows = $this->doccorr->dbselectByField("fil_id", $_REQUEST['fil_id']);
         $row = $rows[0];
         if (count($row)) {
             // Update data
             $this->doccorr->setDco_id($row->dco_id);
             $this->doccorr->setFil_id($_REQUEST['fil_id']);
             $this->doccorr->setFil_nur($_REQUEST['fil_nur']);
             if ($_REQUEST['fil_nur_s']) {
                 $this->doccorr->setFil_nur(strtoupper($_REQUEST['fil_nur_s']));
             }
             if ($_REQUEST['fil_cite']) {
                 $this->doccorr->setFil_cite(strtoupper($_REQUEST['fil_cite']));
             }
             if ($_REQUEST['fil_asunto']) {
                 $this->doccorr->setFil_asunto(strtoupper($_REQUEST['fil_asunto']));
             }
             if ($_REQUEST['fil_sintesis']) {
                 $this->doccorr->setFil_sintesis(strtoupper($_REQUEST['fil_sintesis']));
             }
             $this->doccorr->setDco_estado(1);
             $dco_id = $this->doccorr->update();
             // New
             if ($_REQUEST['tiponur'] == 'ORI' || $_REQUEST['tiponur'] == '') {
                 // Registra en el SIACO tabla archivados
                 $this->archivados = new tab_archivados();
                 $this->archivados->setRequest2Object($_REQUEST);
                 $rows2 = $this->archivados->dbselectByField("codigo", $_REQUEST['fil_nur']);
                 if (count($rows2)) {
                     $row2 = $rows2[0];
                     $this->archivados->setId_archivado($row2->id_archivado);
                     $this->archivados->setCodigo($_REQUEST['fil_nur']);
                     $this->archivados->setFecha(date("Y-m-d"));
                     $this->archivados->setPersona($_SESSION['USU_LOGIN']);
                     $this->archivados->setLugar($_REQUEST['exp_id'] . '-' . $_REQUEST['exp_nombre']);
                     $this->archivados->setObservaciones("SAD");
                     $this->archivados->setCopia("NO");
                     $this->archivados->update();
                     // Update seguimiento
                     $this->seguimientos = new Tab_seguimientos();
                     $sql = "SELECT seguimientos.id_seguimiento\r\n                                FROM seguimientos\r\n                                WHERE codigo = '" . $_REQUEST['fil_nur'] . "'\r\n                                ORDER BY id_seguimiento DESC ";
                     $rows = $this->seguimientos->dbSelectBySQL($sql);
                     $row = $rows[0];
                     $this->seguimientos->setId_seguimiento($row->id_seguimiento);
                     $this->seguimientos->setEstado(100);
                     $this->seguimientos->update();
                 } else {
                     $this->archivados->setId_archivado('');
                     $this->archivados->setCodigo($_REQUEST['fil_nur']);
                     $this->archivados->setFecha(date("Y-m-d"));
                     $this->archivados->setPersona($_SESSION['USU_LOGIN']);
                     $this->archivados->setLugar($_REQUEST['exp_id'] . '-' . $_REQUEST['exp_nombre']);
                     $this->archivados->setObservaciones("SAD");
                     $this->archivados->setCopia("NO");
                     $this->archivados->insert();
                     // Update seguimiento
                     $this->seguimientos = new Tab_seguimientos();
                     $sql = "SELECT seguimientos.id_seguimiento\r\n                                FROM seguimientos\r\n                                WHERE codigo = '" . $_REQUEST['fil_nur'] . "'\r\n                                ORDER BY id_seguimiento DESC ";
                     $rows = $this->seguimientos->dbSelectBySQL($sql);
                     $row = $rows[0];
                     $this->seguimientos->setId_seguimiento($row->id_seguimiento);
                     $this->seguimientos->setEstado(100);
                     $this->seguimientos->update();
                 }
             } else {
                 // Registra en el SIACO tabla archivados_digitales
                 $this->archivados_digitales = new tab_archivados_digitales();
                 $this->archivados_digitales->setRequest2Object($_REQUEST);
                 $rows2 = $this->archivados_digitales->dbselectByField("codigo", $_REQUEST['fil_nur']);
                 if (count($row2)) {
                     $row2 = $rows2[0];
                     $this->archivados_digitales->setId_archivado($row2->id_archivado);
                     $this->archivados_digitales->setCodigo($_REQUEST['fil_nur']);
                     $this->archivados_digitales->setFecha(date("Y-m-d"));
                     $this->archivados_digitales->setPersona($_SESSION['USU_LOGIN']);
                     $this->archivados->setLugar($_REQUEST['exp_id'] . '-' . $_REQUEST['exp_nombre']);
                     $this->archivados_digitales->setObservaciones("SAD");
                     $this->archivados_digitales->setCopia("SI");
                     $this->archivados_digitales->update();
                     // Update seguimiento
                     $this->seguimientos = new Tab_seguimientos();
                     $sql = "SELECT seguimientos.id_seguimiento\r\n                                FROM seguimientos\r\n                                WHERE codigo = '" . $_REQUEST['fil_nur'] . "'\r\n                                ORDER BY id_seguimiento DESC ";
                     $rows = $this->seguimientos->dbSelectBySQL($sql);
                     $row = $rows[0];
                     $this->seguimientos->setId_seguimiento($row->id_seguimiento);
                     $this->seguimientos->setEstado(51);
                     $this->seguimientos->update();
                 } else {
                     $this->archivados_digitales->setId_archivado("0");
                     $this->archivados_digitales->setCodigo($_REQUEST['fil_nur']);
                     $this->archivados_digitales->setFecha(date("Y-m-d"));
                     $this->archivados_digitales->setPersona($_SESSION['USU_LOGIN']);
                     $this->archivados->setLugar($_REQUEST['exp_id'] . '-' . $_REQUEST['exp_nombre']);
                     $this->archivados_digitales->setObservaciones("SAD");
                     $this->archivados_digitales->setCopia("SI");
                     $this->archivados_digitales->insert();
                     // Update seguimiento
                     $this->seguimientos = new Tab_seguimientos();
                     $sql = "SELECT seguimientos.id_seguimiento\r\n                                FROM seguimientos\r\n                                WHERE codigo = '" . $_REQUEST['fil_nur'] . "'\r\n                                ORDER BY id_seguimiento DESC ";
                     $rows = $this->seguimientos->dbSelectBySQL($sql);
                     $row = $rows[0];
                     $this->seguimientos->setId_seguimiento($row->id_seguimiento);
                     $this->seguimientos->setEstado(51);
                     $this->seguimientos->update();
                 }
             }
         } else {
             // Insert data
             $this->doccorr->setDco_id('');
             $this->doccorr->setFil_id($_REQUEST['fil_id']);
             $this->doccorr->setFil_nur($_REQUEST['fil_nur']);
             if ($_REQUEST['fil_nur_s']) {
                 $this->doccorr->setFil_nur(strtoupper($_REQUEST['fil_nur_s']));
             }
             if ($_REQUEST['fil_cite']) {
                 $this->doccorr->setFil_cite(strtoupper($_REQUEST['fil_cite']));
             }
             if ($_REQUEST['fil_asunto']) {
                 $this->doccorr->setFil_asunto(strtoupper($_REQUEST['fil_asunto']));
             }
             if ($_REQUEST['fil_sintesis']) {
                 $this->doccorr->setFil_sintesis(strtoupper($_REQUEST['fil_sintesis']));
             }
             $this->doccorr->setDco_estado(1);
             $dco_id = $this->doccorr->insert();
             if ($_REQUEST['tiponur'] == 'ORI' || $_REQUEST['tiponur'] == '') {
                 // Registra en el SIACO tabla archivados
                 $this->archivados = new tab_archivados();
                 $this->archivados->setRequest2Object($_REQUEST);
                 $this->archivados->setId_archivado("0");
                 $this->archivados->setCodigo($_REQUEST['fil_nur']);
                 $this->archivados->setFecha(date("Y-m-d"));
                 $this->archivados->setPersona($_SESSION['USU_LOGIN']);
                 $this->archivados->setLugar($_REQUEST['exp_id'] . '-' . $_REQUEST['exp_nombre']);
                 $this->archivados->setObservaciones("SAD");
                 $this->archivados->setCopia("NO");
                 $this->archivados->insert();
                 // Update seguimiento
                 $this->seguimientos = new Tab_seguimientos();
                 $sql = "SELECT seguimientos.id_seguimiento\r\n                            FROM seguimientos\r\n                            WHERE codigo = '" . $_REQUEST['fil_nur'] . "'\r\n                            ORDER BY id_seguimiento DESC ";
                 $rows = $this->seguimientos->dbSelectBySQL($sql);
                 $row = $rows[0];
                 $this->seguimientos->setId_seguimiento($row->id_seguimiento);
                 $this->seguimientos->setEstado(100);
                 $this->seguimientos->update();
             } else {
                 // Registra en el SIACO tabla archivados_digitales
                 $this->archivados_digitales = new tab_archivados_digitales();
                 $this->archivados_digitales->setRequest2Object($_REQUEST);
                 $this->archivados_digitales->setId_archivado("0");
                 $this->archivados_digitales->setCodigo($_REQUEST['fil_nur']);
                 $this->archivados_digitales->setFecha(date("Y-m-d"));
                 $this->archivados_digitales->setPersona($_SESSION['USU_LOGIN']);
                 $this->archivados->setLugar($_REQUEST['exp_id'] . '-' . $_REQUEST['exp_nombre']);
                 $this->archivados_digitales->setObservaciones("SAD");
                 $this->archivados_digitales->setCopia("SI");
                 $this->archivados_digitales->insert();
                 // Update seguimiento
                 $this->seguimientos = new Tab_seguimientos();
                 $sql = "SELECT seguimientos.id_seguimiento\r\n                            FROM seguimientos\r\n                            WHERE codigo = '" . $_REQUEST['fil_nur'] . "'\r\n                            ORDER BY id_seguimiento DESC ";
                 $rows = $this->seguimientos->dbSelectBySQL($sql);
                 $row = $rows[0];
                 $this->seguimientos->setId_seguimiento($row->id_seguimiento);
                 $this->seguimientos->setEstado(51);
                 $this->seguimientos->update();
             }
         }
     }
     $this->palclave = new tab_palclave();
     $this->palclave->deleteByField("fil_id", $_REQUEST['fil_id']);
     if (!empty($_REQUEST['fil_descripcion'])) {
         $pac_nombre = trim($_REQUEST['fil_descripcion']);
         $array = explode(SEPARATOR_SEARCH, $pac_nombre);
         for ($j = 0; $j < count($array); $j++) {
             if ($array[$j] != '') {
                 $this->palclave->setFil_id($_REQUEST['fil_id']);
                 $this->palclave->setPac_nombre(strtoupper(trim($array[$j])));
                 $this->palclave->setPac_formulario('Documento');
                 $this->palclave->setPac_estado(1);
                 $this->palclave->insert();
             }
         }
     }
     $msm_guardado_archivo = 0;
     if ($_FILES["archivo"]["error"] == 4) {
     } else {
         // Digital file
         $archivo_digital = new tab_archivo_digital();
         $archivo_type = $_FILES["archivo"]["type"];
         $archivo = $_FILES["archivo"]["tmp_name"];
         $archivo_size = $_FILES["archivo"]["size"];
         $archivo_name = $_FILES["archivo"]["name"];
         $nombre = basename($_FILES["archivo"]["name"]);
         $nombreFichero = $_FILES["archivo"]["name"];
         $archivo_name_array = explode(".", $archivo_name);
         $archivo_ext = array_pop($archivo_name_array);
         $archivo_cifrado = md5($archivo_name);
         $sis_tammax = 0;
         // Data Parameters
         $sis_tipcarga = 2;
         $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;
         }
         // Verify size
         if ($archivo_size > $sis_tammax) {
             $errores["archivo"] = "El tamanio del fichero supera el limite permitido ({$maxsize} bytes)!";
             $error = true;
         } else {
             $nombreArchivo = $_FILES['archivo']['name'];
             if ($nombreArchivo == "") {
             } else {
                 if ($sis_tipcarga == 2) {
                     $error = false;
                     $copiarFichero = false;
                     if (is_uploaded_file($_FILES['archivo']['tmp_name'])) {
                         $nombreFichero = $_FILES['archivo']['name'];
                         $copiarFichero = true;
                         $nombreCompleto = $nombreDirectorio . $nombreFichero;
                         if (is_file($nombreCompleto)) {
                             $idUnico = time();
                             $nombreFichero = $idUnico . "-" . $nombreFichero;
                         }
                     } else {
                         if ($_FILES['archivo']['error'] == UPLOAD_ERR_FORM_SIZE) {
                             $maxsize = $_REQUEST['MAX_FILE_SIZE'];
                             $errores["archivo"] = "El tamanio del fichero supera el limite permitido ({$maxsize} bytes)!";
                             $error = true;
                         } else {
                             if ($_FILES['archivo']['name'] == "") {
                                 $nombreFichero = '';
                             } else {
                                 $errores["archivo"] = "No se ha podido subir el fichero!";
                                 $msm_guardado_archivo = 0;
                                 $error = true;
                             }
                         }
                     }
                     if ($error == false) {
                         // Validate
                         $fil_id = $_REQUEST['fil_id'];
                         $rows = $archivo_digital->dbselectByField("fil_id", $fil_id);
                         if (count($rows)) {
                             $sql = "UPDATE tab_archivo_digital\r\n                                    SET fil_nomoriginal='{$nombreFichero}', \r\n                                        fil_nomcifrado='{$archivo_cifrado}', \r\n                                        fil_tipo='{$archivo_type}', \r\n                                        fil_tamano='{$archivo_size}', \r\n                                        fil_extension='{$archivo_ext}', \r\n                                        nombre='{$nombre}', \r\n                                        mime='{$archivo_type}', \r\n                                        size={$archivo_size}, \r\n                                        archivo='{$nombreFichero}', \r\n                                        fil_estado=1\r\n                                    WHERE fil_id = '{$fil_id}' ";
                             $link = $archivo_digital->connect();
                             pg_query($link, "begin");
                             pg_query($link, $sql) or die(pg_last_error($link));
                             pg_query($link, "commit");
                             if ($copiarFichero) {
                                 move_uploaded_file($_FILES['archivo']['tmp_name'], $nombreDirectorio . $nombreFichero);
                             }
                             $msm_guardado_archivo = 1;
                         } else {
                             $sql = "INSERT INTO tab_archivo_digital(fil_id,\r\n                                                            fil_nomoriginal,\r\n                                                            fil_nomcifrado,\r\n                                                            fil_tipo,\r\n                                                            fil_tamano,\r\n                                                            fil_extension,\r\n                                                            nombre,\r\n                                                            mime,\r\n                                                            size,\r\n                                                            archivo,\r\n                                                            fil_estado)\r\n                                                   VALUES ({$fil_id},\r\n                                                           '{$nombreFichero}',\r\n                                                           '{$archivo_cifrado}',\r\n                                                           '{$archivo_type}',\r\n                                                           '{$archivo_size}' ,\r\n                                                           '{$archivo_ext}' ,\r\n                                                           '{$nombre}',\r\n                                                           '{$archivo_type}',\r\n                                                           {$archivo_size},\r\n                                                           '{$nombreFichero}',\r\n                                                           1)";
                             $link = $archivo_digital->connect();
                             pg_query($link, "begin");
                             pg_query($link, $sql) or die(pg_last_error($link));
                             pg_query($link, "commit");
                             if ($copiarFichero) {
                                 move_uploaded_file($_FILES['archivo']['tmp_name'], $nombreDirectorio . $nombreFichero);
                             }
                             $msm_guardado_archivo = 1;
                         }
                     }
                 } else {
                     // Validate
                     $fil_id = $_REQUEST['fil_id'];
                     $rows = $this->series->dbselectByField("fil_id", $fil_id);
                     $row = $rows[0];
                     if (count($row)) {
                         $sql = "UPDATE tab_archivo_digital\r\n                            SET fil_nomoriginal='{$archivo_name}', \r\n                            fil_nomcifrado='{$archivo_cifrado}', \r\n                            fil_tipo='{$archivo_type}', \r\n                            fil_tamano='{$archivo_size}', \r\n                            fil_extension='{$archivo_ext}', \r\n                            nombre='{$nombre}', \r\n                            archivo_oid={$oid}, \r\n                            mime='{$archivo_type}', \r\n                            size={$archivo_size}, \r\n                            archivo='{$nombreFichero}', \r\n                            fil_estado=1\r\n                            WHERE fil_id = {$fil_id} ";
                         $link = $archivo_digital->connect();
                         $fp = fopen($archivo, "rb");
                         $contenido = fread($fp, filesize($archivo));
                         fclose($fp);
                         pg_query($link, "begin");
                         $oid = pg_lo_create($link);
                         pg_query($link, $sql) or die(pg_last_error($link));
                         $blob = pg_lo_open($link, $oid, "w");
                         pg_lo_write($blob, $contenido);
                         pg_lo_close($blob);
                         pg_query($link, "commit");
                         $msm_guardado_archivo = 1;
                         //"Se subio correctamente el archivo"
                     } else {
                         $sql = "INSERT INTO tab_archivo_digital(fil_id,\r\n                                                                fil_nomoriginal,\r\n                                                                fil_nomcifrado,\r\n                                                                fil_tipo,\r\n                                                                fil_tamano,\r\n                                                                fil_extension,\r\n                                                                nombre,\r\n                                                                archivo_oid,\r\n                                                                mime,\r\n                                                                size,\r\n                                                                archivo)\r\n                                                        VALUES ({$fil_id},\r\n                                                                '{$archivo_name}',\r\n                                                                '{$archivo_cifrado}',\r\n                                                                '{$archivo_type}',\r\n                                                                '{$archivo_size}',\r\n                                                                '{$archivo_ext}',\r\n                                                                '{$nombre}',\r\n                                                                {$oid},\r\n                                                                '{$archivo_type}',\r\n                                                                {$archivo_size},\r\n                                                                '{$nombreFichero}')";
                         $link = $archivo_digital->connect();
                         $fp = fopen($archivo, "rb");
                         $contenido = fread($fp, filesize($archivo));
                         fclose($fp);
                         pg_query($link, "begin");
                         $oid = pg_lo_create($link);
                         pg_query($link, $sql) or die(pg_last_error($link));
                         $blob = pg_lo_open($link, $oid, "w");
                         pg_lo_write($blob, $contenido);
                         pg_lo_close($blob);
                         pg_query($link, "commit");
                         $msm_guardado_archivo = 1;
                     }
                 }
             }
         }
     }
     $fil_id = $_REQUEST['fil_id'];
     // Forwarding
     if ($_REQUEST['accion'] == 'guardarsinsalir') {
         $msm_guardado_archivo = 1;
         Header("Location: " . PATH_DOMAIN . "/archivo/view/" . $exp_id . "/" . $fil_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 . "/archivo/viewTree/" . $exp_id . "/" . $msm_guardado_archivo . "/{$cue_id}/");
         } else {
             header("location:" . PATH_DOMAIN . "/archivo/viewTree/" . $exp_id . "/" . $msm_guardado_archivo . "/{$cue_id}/");
         }
     }
     //        // Forwarding
     //        if ($_REQUEST ['accion'] == 'cargarnuevo') {
     //            header("location:" . PATH_DOMAIN . "/archivo/viewTree/" . $exp_id . "/" . $msm_guardado_archivo . "/$cue_id/");
     //            //$this->add2();
     //        } else {
     //            header("location:" . PATH_DOMAIN . "/archivo/viewTree/" . $exp_id . "/" . $msm_guardado_archivo . "/$cue_id/");
     //        }
 }
Exemple #14
0
<?php

include 'config.inc';
$db = pg_connect($conn_str);
echo "create/write/close LO\n";
pg_exec($db, "begin");
$oid = pg_lo_create($db);
if (!$oid) {
    echo "pg_lo_create() error\n";
}
$handle = pg_lo_open($db, $oid, "w");
if (!$handle) {
    echo "pg_lo_open() error\n";
}
pg_lo_write($handle, "large object data\n");
pg_lo_close($handle);
pg_exec($db, "commit");
echo "open/read/tell/seek/close LO\n";
pg_exec($db, "begin");
$handle = pg_lo_open($db, $oid, "w");
pg_lo_read($handle, 100);
pg_lo_tell($handle);
pg_lo_seek($handle, 2);
pg_lo_close($handle);
pg_exec($db, "commit");
echo "open/read_all/close LO\n";
pg_exec($db, "begin");
$handle = pg_lo_open($db, $oid, "w");
pg_lo_read_all($handle);
if (pg_last_error()) {
    echo "pg_lo_read_all() error\n" . pg_last_error();
 public function makePgLO(&$data = null)
 {
     $pg = $this->connectionFactory->get('RW');
     $pgResource = $pg->resource->get();
     if (!isset($data)) {
         $data = file_get_contents($this->makeAndFillFile());
     }
     pg_query($pgResource, "BEGIN");
     $oid = pg_lo_create($pgResource);
     $handle = pg_lo_open($pgResource, $oid, 'w');
     pg_lo_write($handle, $data);
     pg_query($pgResource, "COMMIT");
     return new Oid($oid, $pg);
 }
 function UpdateBlobFile($table, $column, $path, $where, $blobtype = 'BLOB')
 {
     pg_exec($this->_connectionID, "begin");
     $fd = fopen($path, 'r');
     $contents = fread($fd, filesize($path));
     fclose($fd);
     $oid = pg_lo_create($this->_connectionID);
     $handle = pg_lo_open($this->_connectionID, $oid, 'w');
     pg_lo_write($handle, $contents);
     pg_lo_close($handle);
     // $oid = pg_lo_import ($path);
     pg_exec($this->_connectionID, "commit");
     $rs = ADOConnection::UpdateBlob($table, $column, $oid, $where, $blobtype);
     $rez = !empty($rs);
     return $rez;
 }
        $clcertidaoweb->cerhtml = "x";
        $clcertidaoweb->cerweb = 'true';
        $clcertidaoweb->incluir();
        $erro_msg = $clcertidaoweb->erro_msg;
        if ($clcertidaoweb->erro_status == 0) {
            $sqlerro = true;
            db_msgbox("Erro ao gerar certidao. ERRO: " . $erro_msg);
            exit;
        }
        /**
         * Grava arquivo da certidao também na tabela certidao
         */
        $clcertidao->p50_arquivo = $oidgrava;
        $clcertidao->alterar($clcertidao->p50_sequencial);
        $objeto = pg_lo_open($conn, $oidgrava, "w");
        if ($objeto != false) {
            $erro = pg_lo_write($objeto, $dados);
            pg_lo_close($objeto);
        } else {
            $sqlerro = true;
        }
    }
    db_fim_transacao($sqlerro);
}
if (file_exists($arqpdf)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/pdf');
    header('Content-Disposition: attachment; filename=' . $arqpdf);
    header('Content-Length: ' . filesize($arqpdf));
    readfile($arqpdf);
}