cn=$p_cn; $this->md_id=$p_id; $this->start=0; } /*! ************************************************** * \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() { $dosid=dossier::id(); $sql="select md_id,md_name,md_affect,dt_value,md_filename 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.='

'; $r.=dossier::hidden(); $r.=\HtmlInput::filter_table("document_template_tb",'0,1,2,3',1); $r.=''; $r.=" "; $r.=th(_('Nom')); $r.=th(_('Catégorie')); $r.=th(_('Affect.')); $r.=th(_('Fichier')); $r.=th(_('Effacer')); $r.=""; $idx=0; foreach ( $all as $row) { $even=($idx%2==0)?'class="odd"':'class="even"'; $idx++; $r.=""; $r.=""; $r.=""; $r.=td(h($row['md_affect'])); $r.=""; $r.=""; $r.=td(\Icon_Action::modify(uniqid(),sprintf("modifyModeleDocument('%s','%s')",$row['md_id'],$dosid) )); $r.=""; } $r.="
"; $r.=h($row['md_name']); $r.=""; $r.=$row['dt_value']; $r.=""; $href=http_build_query(array('gDossier'=>$dosid,'md_id'=>$row['md_id'],'act'=>'RAW:document_template')); $r.=''.h($row['md_filename']).''; $r.=""; $c=new ICheckBox(); $c->name="dm_remove_".$row['md_id']; $r.=$c->input(); $r.="
"; // need hidden parameter for subaction $a=new IHidden(); $a->name="sa"; $a->value="rm_template"; $r.=$a->input(); $r.=HtmlInput::submit("rm_template",_("Effacer la sélection")); } else { echo h2(_("Aucun document")); echo _("Il n'y a aucun document, cliquez sur Ajouter pour en ajouter un"); } $b=new IButton('show'); $b->label="Ajout d'un document"; $b->javascript="$('add_modele').style.display='block';new Draggable('add_modele',{starteffect:function(){ new Effect.Highlight(obj.id,{scroll:window,queue:'end'});}});"; $r.=$b->input(); $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 ($this->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/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 "

"._("Erreur opération annulée")."

"; $this->cn->rollback(); throw new Exception("DM191 : error loading template".__FILE__.__LINE__); } } } catch (Exception $e) { record_log($e); $this->cn->rollback(); return ; } } function move_uploaded_file($temporary_name, $target_path) { return move_uploaded_file ($temporary_name, $target_path); } /*! * \brief Remove a template * \return nothing */ function Delete() { $this->cn->start(); // first we unlink the document $sql="select md_lob from document_modele where md_id=$1"; $res=$this->cn->exec_sql($sql,[$this->md_id]); $r=Database::fetch_array($res,0); // if a lob is found if ( !empty ($r['md_lob']) &&$this->cn->exist_blob($r['md_lob']) ) { // we remove it first $this->cn->lo_unlink($r['md_lob']); } // now we can delete the row $sql="delete from document_modele where md_id =$1"; $res=$this->cn->exec_sql($sql,[$this->md_id]); $this->cn->commit(); } /** * @brief show the form for loading a template * @param p_action for the field action = destination url * * * @return string containing the forms */ function form() { $r='

'; $r.='Veuillez introduire les modèles servant à générer vos documents'; $r.='

'; $r.='
'; $r.=\HtmlInput::hidden("MAX_FILE_SIZE", MAX_FILE_SIZE); $r.=dossier::hidden(); // we need to add the sub action as hidden $h=new IHidden(); $h->name="sa"; $h->value="add_document"; $r.=$h->input(); $r.=''; $t=new IText(); $t->name="md_name"; $r.=""; $r.=""; $r.=""; $w=new ISelect(); $w->name="md_type"; $w->value=$this->cn->make_array('select dt_id,dt_value from document_type order by dt_value'); $r.=""; $r.=''; $r.=td(_('Affectation')); $waffect=new ISelect(); $waffect->name='md_affect'; $waffect->value=$this->cn->make_array("select dc_code,dc_comment from public.document_component order by dc_code"); $r.=td($waffect->input()); $r.=''; $f=new IFile(); $f->name="doc"; $f->setAlertOnSize(true); $r.=""; $start=new IText(); $start->name="start_seq"; $start->size=9; $start->value="0"; $r.=""; $r.=''; $r.=""; $r.='
Nom ".$t->input()."
Catégorie de document ".$w->input()."
fichier ".$f->input()."
Numerotation commence a ".$start->input()."Si vous laissez à 0, la numérotation ne changera pas, la prochaine facture sera n+1, n étant le n° que vous avez donné
'; $r.='