cn=$p_cn; $this->md_id=$p_id; } /*! ************************************************** * \brief : show all the stored document_modele. * return a string containing all the data * separate by TD & TR tag * \return table in HTML Code */ function myList() { $s=dossier::get(); $sql="select md_id,md_name,md_affect,dt_value from document_modele join document_type on(dt_id=md_type) order by md_name"; $Res=$this->cn->exec_sql($sql); $all=Database::fetch_all($Res); $r=''; if ( Database::num_row($Res) != 0 ) { $r.='
"; return $r; } /*! * \brief : Save a document_modele in the database, * if the document_modele doesn't exist yet it will be * first created (-> insert into document_modele) * in that case the name and the type must be set * set before calling Save, the name will be modified * with sql_string * */ function Save() { // if name is empty return immediately if ( trim(strlen($this->md_name))==0) return; try { // Start transaction $this->cn->start(); // Save data into the table document_modele // if $this->md_id == -1 it means it is a new document model // so first we have to insert it // the name and the type must be set before calling save if ( $this->md_id == -1) { // insert into the table document_modele $this->md_id=$this->cn->get_next_seq('document_modele_md_id_seq'); $sql="insert into document_modele(md_id,md_name,md_type,md_affect) values ($1,$2,$3,$4)"; $Ret=$this->cn->exec_sql($sql,array($this->md_id,$this->md_name,$this->md_type,$this->md_affect)); // create the sequence for this modele of document $this->md_sequence="document_".$this->cn->get_next_seq("document_seq"); // if start is not equal to 0 and he's a number than the user // request a number change if ( $this->start != 0 && isNumber($this->start) == 1 ) { $sql="alter sequence seq_doc_type_".$this->md_type." restart ".$this->start; $this->cn->exec_sql($sql); } } // Save the file $new_name=tempnam($_ENV['TMP'],'document_'); if ( strlen ($_FILES['doc']['tmp_name']) != 0 ) { if (move_uploaded_file($_FILES['doc']['tmp_name'], $new_name)) { // echo "Image saved"; $oid= $this->cn->lo_import($new_name); if ( $oid == false ) { echo_error('class_document_modele.php',__LINE__,"cannot upload document"); $this->cn->rollback(); return; } // Remove old document $ret=$this->cn->exec_sql("select md_lob from document_modele where md_id=".$this->md_id); if (Database::num_row($ret) != 0) { $r=Database::fetch_array($ret,0); $old_oid=$r['md_lob']; if (strlen($old_oid) != 0) $this->cn->lo_unlink($old_oid); } // Load new document $this->cn->exec_sql("update document_modele set md_lob=".$oid.", md_mimetype='".$_FILES['doc']['type']."' ,md_filename='".$_FILES['doc']['name']."' where md_id=".$this->md_id); $this->cn->commit(); } else { echo "'; $r.='Veuillez introduire les modèles servant à générer vos documents'; $r.='
'; $r.='"; return $r; } /*!\brief load the value of a document_modele,the ag_id variable must be set */ function load() { $array=$this->cn->get_array("SELECT md_id, md_name, md_lob, md_type, md_filename, md_mimetype,md_affect". " FROM document_modele where md_id=$1",array($this->md_id)); if ( count($array) == 0 ) return null; foreach ( array('md_name', 'md_lob','md_type', 'md_filename', 'md_mimetype','md_affect') as $idx) { $this->$idx=$array[0][$idx]; } } /*! * \brief : update a document_modele in the database, */ function update($p_array) { $this->load(); // if name is empty return immediately if ( trim(strlen($p_array['md_name']))==0) return; try { // Start transaction $this->cn->start(); $sql="update document_modele set md_name=$1,md_type=$2,md_affect=$3 where md_id=$4"; $this->cn->exec_sql($sql,array( $p_array['md_name'], $p_array['md_type'], $p_array['md_affect'], $this->md_id )); if ( $p_array['seq'] != 0 ) $this->cn->alter_seq('seq_doc_type_'.$p_array['md_type'],$p_array['seq']); // Save the file $new_name=tempnam($_ENV['TMP'],'document_'); if ( strlen ($_FILES['doc']['tmp_name']) != 0 ) { if (move_uploaded_file($_FILES['doc']['tmp_name'], $new_name)) { // echo "Image saved"; $oid= $this->cn->lo_import($new_name); if ( $oid == false ) { echo_error('class_document_modele.php',__LINE__,"cannot upload document"); $this->cn->rollback(); return; } // Remove old document $ret=$this->cn->exec_sql("select md_lob from document_modele where md_id=".$this->md_id); if (Database::num_row($ret) != 0) { $r=Database::fetch_array($ret,0); $old_oid=$r['md_lob']; if (strlen($old_oid) != 0) $this->cn->lo_unlink($old_oid); } // Load new document $this->cn->exec_sql("update document_modele set md_lob=".$oid.", md_mimetype='".$_FILES['doc']['type']."' ,md_filename='".$_FILES['doc']['name']."' where md_id=".$this->md_id); $this->cn->commit(); } else { echo "