From a5ee2dbd03cdaf6e2fe3463d76e18fdac096f820 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sun, 14 Nov 2010 20:27:00 +0000 Subject: [PATCH] =?UTF-8?q?task=200000018:=20Gestion=20des=20mod=C3=A8les?= =?UTF-8?q?=20de=20documents?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- html/ajax_misc.php | 5 +- html/js/modele_document.js | 61 +++++++++++++++ include/class_document_modele.php | 70 ++++++++++++++++- include/class_html_input.php | 9 +++ include/document_modele.inc.php | 13 +++- include/modify_mod_document.inc.php | 52 +++++++++++++ include/template/modele_document.php | 110 +++++++++++++++++++++++++++ 7 files changed, 315 insertions(+), 5 deletions(-) create mode 100644 html/js/modele_document.js create mode 100644 include/modify_mod_document.inc.php create mode 100644 include/template/modele_document.php diff --git a/html/ajax_misc.php b/html/ajax_misc.php index 49a3abd24..ec2a4a84a 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -41,7 +41,7 @@ require_once('function_javascript.php'); require_once('ac_common.php'); require_once ('class_user.php'); -$var=array('gDossier'); +$var=array('gDossier','op'); $cont=0; /* check if mandatory parameters are given */ foreach ($var as $v) @@ -426,4 +426,7 @@ echo << EOF; break; +case 'mod_doc': + require_once('modify_mod_document.inc.php'); + break; } diff --git a/html/js/modele_document.js b/html/js/modele_document.js new file mode 100644 index 000000000..ea698120e --- /dev/null +++ b/html/js/modele_document.js @@ -0,0 +1,61 @@ +/*!\brief + * \param p_value jrn.jr_id + */ +function modifyModeleDocument(p_value,dossier) +{ + layer++; + id='det'+layer; +var popup={'id': + 'mod_doc','cssclass':'op_detail' + ,'html': + loading(),'drag': + true}; + querystring='?gDossier='+dossier+'&op=mod_doc&id='+p_value+'&div=mod_doc'; + add_div(popup); + var action=new Ajax.Request( + "ajax_misc.php", + { + method:'get', + parameters:querystring, + onFailure:error_box, + onSuccess:modify_document_success_box + } + ); +} +/** + *@brief receive answer from ajax and just display it into the IBox + * XML must contains at least 2 fields : code is the ID of the IBOX and + * html which is the contain + */ +function modify_document_success_box(req,json) +{ + try + { + var answer=req.responseXML; + var a=answer.getElementsByTagName('ctl'); + var html=answer.getElementsByTagName('code'); + if ( a.length == 0 ) + { + var rec=req.responseText; + alert ('erreur :'+rec); + } + var name_ctl=a[0].firstChild.nodeValue; + var code_html=getNodeText(html[0]); + + code_html=unescape_xml(code_html); + g(name_ctl).innerHTML=code_html; + g(name_ctl).style.height='auto'; + } + catch (e) + { + alert("success_box"+e.message); + } + try + { + code_html.evalScripts(); + } + catch(e) + { + alert("answer_box Impossible executer script de la reponse\n"+e.message); + } +} diff --git a/include/class_document_modele.php b/include/class_document_modele.php index 945cfb5ab..a1dc216a1 100644 --- a/include/class_document_modele.php +++ b/include/class_document_modele.php @@ -86,6 +86,8 @@ class Document_modele $c->name="dm_remove_".$row['md_id']; $r.=$c->input(); $r.=""; + $r.=td(HtmlInput::detail_modele_document($row['md_id'],'Modifier')); + $r.=""; } $r.=""; @@ -100,7 +102,6 @@ class Document_modele 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) @@ -285,5 +286,72 @@ class Document_modele $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 "

Error

"; + $this->cn->rollback(); + exit; + } + } + } + catch (Exception $e) + { + rollback($this->cn); + return ; + } + $this->cn->commit(); + } + } ?> diff --git a/include/class_html_input.php b/include/class_html_input.php index 287268291..d69dd86c7 100755 --- a/include/class_html_input.php +++ b/include/class_html_input.php @@ -249,6 +249,15 @@ class HtmlInput return sprintf('%s', $p_jr_id,dossier::id(),$p_mesg); } + /** + * return a string containing the html code for calling the modifyModeleDocument + */ + static function detail_modele_document($p_id,$p_mesg) + { + return sprintf('%s', + $p_id,dossier::id(),$p_mesg); + } + /** * display a div with the history of the card */ diff --git a/include/document_modele.inc.php b/include/document_modele.inc.php index 87c8aad7c..14b908737 100644 --- a/include/document_modele.inc.php +++ b/include/document_modele.inc.php @@ -24,6 +24,7 @@ require_once("class_document_modele.php"); $sub_action=(isset ($_REQUEST['sa']))?$_REQUEST['sa']:""; +echo js_include('modele_document.js'); echo "
"; // show the form for adding a template @@ -65,11 +66,17 @@ if ( $sub_action=='rm_template') } } - +//---------------------------------------------------------------------- +// Document modify a template +//---------------------------------------------------------------------- +if ( $sub_action == 'mod_template') + { + require_once('class_document_modele.php'); + $doc=new Document_modele($cn,$_POST['id']); + $doc->update($_POST); + } //----------------------------------------------------- // Default action : Show the list //----------------------------------------------------- echo $doc->myList(); -?> -?> ?> \ No newline at end of file diff --git a/include/modify_mod_document.inc.php b/include/modify_mod_document.inc.php new file mode 100644 index 000000000..a8ec3eb7f --- /dev/null +++ b/include/modify_mod_document.inc.php @@ -0,0 +1,52 @@ +load(); +ob_start(); +require('template/modele_document.php'); + +$html=ob_get_contents(); +ob_clean(); +$html=escape_xml($html); +header('Content-type: text/xml; charset=UTF-8'); + +echo << + +mod_doc +$html + +EOF; +exit(); diff --git a/include/template/modele_document.php b/include/template/modele_document.php new file mode 100644 index 000000000..5feae183c --- /dev/null +++ b/include/template/modele_document.php @@ -0,0 +1,110 @@ +
+Fermer +
+

Modèle de document

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Nom du document +value=$doc->md_name; +echo $a->input(); +?> +
+Catégorie de document + +name="md_type"; + + $w->value=$cn->make_array('select dt_id,dt_value from document_type'); + $w->selected=$doc->md_type; + echo $w->input(); +?> + +
+Affectation + +name='md_affect'; + $waffect->value=array( + array('value'=>'ACH','label'=>_('Uniquement journaux achat')), + array('value'=>'VEN','label'=>_('Uniquement journaux vente')), + array('value'=>'GES','label'=>_('Partie gestion')) + ); + $waffect->selected=$doc->md_affect; + echo $waffect->input(); +?> +
+Fichier + +input(); +?> +
+Dernier numéro utilisé pour ce type de document + +exist_sequence("seq_doc_type_".$doc->md_type) ) + { + $ret= $cn->get_array("select last_value,is_called from seq_doc_type_".$doc->md_type) ; + + $last=$ret[0]['last_value']; + /*! + *\note With PSQL sequence , the last_value column is 1 when before AND after the first call, to make the difference between them + * I have to check whether the sequence has been already called or not */ + if ($ret[0]['is_called']=='f' ) $last--; + } +echo $last; +?> +
+Redémarrer la séquence (laisser à 0 pour ne pas changer) + +value=0; +echo $pj->input(); +?> +
+md_id); +echo HtmlInput::submit("mod",'Sauver'); + +?> +
\ No newline at end of file