From cad44ee68afe1b2b24a1b3020cb0eb2ff475970e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 22 Oct 2017 01:25:59 +0200 Subject: [PATCH] FIX substitution in ODT of thirdparties documents --- .../societe/doc/doc_generic_odt.modules.php | 68 ++++--------------- 1 file changed, 13 insertions(+), 55 deletions(-) diff --git a/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php b/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php index edee43b274c..13595108140 100644 --- a/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php +++ b/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php @@ -150,7 +150,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc } $texte.='
'; } - + $texte.= ''; $texte.= ''; @@ -272,53 +272,6 @@ class doc_generic_odt extends ModeleThirdPartyDoc } //print $odfHandler->__toString()."\n"; - // Make substitutions into odt of user info - $tmparray=$this->get_substitutionarray_user($user,$outputlangs); - //var_dump($tmparray); exit; - foreach($tmparray as $key=>$value) - { - try { - if (preg_match('/logo$/',$key)) // Image - { - //var_dump($value);exit; - if (file_exists($value)) $odfHandler->setImage($key, $value); - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); - } - else // Text - { - //print $key.' '.$value;exit; - $odfHandler->setVars($key, $value, true, 'UTF-8'); - } - } - catch(OdfException $e) - { - // setVars failed, probably because key not found - } - } - // Make substitutions into odt of mysoc info - $tmparray=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); - //var_dump($tmparray); exit; - foreach($tmparray as $key=>$value) - { - try { - if (preg_match('/logo$/',$key)) // Image - { - //var_dump($value);exit; - if (file_exists($value)) $odfHandler->setImage($key, $value); - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); - } - else // Text - { - $odfHandler->setVars($key, $value, true, 'UTF-8'); - } - } - catch(OdfException $e) - { - // setVars failed, probably because key not found - } - } - - // Replace tags of lines for contacts $contact_arrray=array(); @@ -333,7 +286,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc if ($num) { require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; - + $i=0; $contactstatic = new Contact($this->db); @@ -380,13 +333,18 @@ class doc_generic_odt extends ModeleThirdPartyDoc } } - // Make substitutions into odt of thirdparty + external modules - $tmparray=$this->get_substitutionarray_thirdparty($object,$outputlangs); + // Make substitutions into odt + $array_user=$this->get_substitutionarray_user($user,$outputlangs); + $array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); + $array_thirdparty=$this->get_substitutionarray_thirdparty($object,$outputlangs); + $array_other=$this->get_substitutionarray_other($outputlangs); + + $tmparray = array_merge($array_user,$array_soc,$array_thirdparty,$array_other); complete_substitutions_array($tmparray, $outputlangs, $object); // Call the ODTSubstitution hook $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks // Replace variables into document foreach($tmparray as $key=>$value) @@ -438,13 +396,13 @@ class doc_generic_odt extends ModeleThirdPartyDoc $odfHandler->creator = $user->getFullName($outputlangs); $odfHandler->title = $object->builddoc_filename; $odfHandler->subject = $object->builddoc_filename; - + if (! empty($conf->global->ODT_ADD_DOLIBARR_ID)) { $odfHandler->userdefined['dol_id'] = $object->id; $odfHandler->userdefined['dol_element'] = $object->element; } - + $odfHandler->saveToDisk($file); }catch (Exception $e){ $this->error=$e->getMessage(); @@ -453,7 +411,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc } $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - + if (! empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK));