diff --git a/include/class/database.class.php b/include/class/database.class.php index 38a8e0daf..6ecc504b3 100644 --- a/include/class/database.class.php +++ b/include/class/database.class.php @@ -82,7 +82,7 @@ class Database extends DatabaseCore . "]"; } /*** - * \brief Save a "piece justificative" , the name must be pj + * \brief Save a "piece justificative" , the name must be a receipt * * \param $seq jr_grpt_id * \return $oid of the lob file if success @@ -91,12 +91,16 @@ class Database extends DatabaseCore */ function save_receipt($seq) { + /** + * pj is the $_FILES key + */ $oid = $this->upload('pj'); if ($oid == false) { return false; } // Remove old document - $ret = $this->exec_sql("select jr_pj from jrn where jr_grpt_id=$seq"); + $ret = $this->exec_sql("select jr_pj from jrn where jr_grpt_id=$1" + ,[$seq]); if (pg_num_rows($ret) != 0) { $r = pg_fetch_array($ret, 0); $old_oid = $r['jr_pj']; @@ -107,6 +111,12 @@ class Database extends DatabaseCore $this->exec_sql("update jrn set jr_pj=$1 , jr_pj_name=$2, jr_pj_type=$3 where jr_grpt_id=$4", array($oid, $_FILES['pj']['name'], $_FILES['pj']['type'], $seq)); + if ( $_FILES['pj']['type'] == 'text/xml' + || $_FILES['pj']['type'] == 'application/xml' + ) + { + + } return $oid; } diff --git a/include/lib/database_core.class.php b/include/lib/database_core.class.php index 901f3b644..12f328d95 100644 --- a/include/lib/database_core.class.php +++ b/include/lib/database_core.class.php @@ -718,7 +718,7 @@ class DatabaseCore } /*** - * \brief Save a document into the database , it just puts the file in the database + * \brief Save one or several documents into the database , it just puts the file in the database * and returns the corresponding OID , the mimetype , size ... of the document * must be set in the calling function. * @@ -730,15 +730,25 @@ class DatabaseCore function upload($p_name) { + + //var $a : 0 we're in a transaction, 1 we are not in a transaction + $a=0; + if ( $this->status() !== PGSQL_TRANSACTION_INTRANS ) { + $a=1; + $this->start(); + } + /* there is no file to upload */ if ($_FILES[$p_name]["error"] == UPLOAD_ERR_NO_FILE) { + \record_log("DC759: error upload file".var_export($_FILES, true)); + if ( $a==1) { $this->rollback(); } return false; } $new_name = tempnam($_ENV['TMP'], $p_name); if ($_FILES[$p_name]["error"] > 0) { - print_r($_FILES); - echo_error(__FILE__ . ":" . __LINE__ . "Error: " . $_FILES[$p_name]["error"]); + \record_log("DC740: error upload file".var_export($_FILES, true)); + if ( $a==1) { $this->rollback(); } return false; } if (strlen($_FILES[$p_name]['tmp_name']) != 0) { @@ -746,17 +756,20 @@ class DatabaseCore // echo "Image saved"; $oid = pg_lo_import($this->db, $new_name); if ($oid == false) { - echo_error(__FILE__, __LINE__, "cannot upload document"); + \record_log("DC747: error upload file".var_export($_FILES, true). "SQL MESSAGE". pg_last_error($this->db)); $this->rollback(); return false; } return $oid; } else { - echo "

Error

"; + \record_log("DC754: move_uploaded fails".var_export($_FILES, true)); $this->rollback(); return false; } } + + \record_log("DC576: Files error names empty".var_export($_FILES, true)); + if ( $a==1) { $this->commit(); } return false; } /** diff --git a/scenario/LIB/databasecore.test.php b/scenario/LIB/databasecore.test.php index b1c853736..ad87b9b0a 100644 --- a/scenario/LIB/databasecore.test.php +++ b/scenario/LIB/databasecore.test.php @@ -34,13 +34,34 @@ $cn=Dossier::connect(); echo h2(" Status IDLE"); echo $cn->status(); -echo h2(" Status in begin "); +echo h2(" Status start "); //echo PGSQL_TRANSACTION_INTRANS; echo $cn->start(); echo $cn->status (); echo "
"; $cn->get_value("select count(*) from jrnx"); +echo "
"; echo $cn->status (); - echo PGSQL_TRANSACTION_INTRANS; + +echo "
"; echo h2(" Status after rollback "); echo $cn->commit(); +echo "
"; echo $cn->status (); +echo h1("Upload"); +echo h2("One file"); +if ( isset($_POST['submit_one'])) { + var_dump($_FILES); + // $cn->start(); + if ( $cn->upload("validate_one") != false){ + echo "success : loaded ".var_export($_FILES['validate_one'],true); + } + // $cn->commit(); +}else{ + echo <<
+ + +
+FORM; + +}