Skip to content

Commit

Permalink
FIX substitution in ODT of thirdparties documents
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Oct 21, 2017
1 parent f7556e7 commit cad44ee
Showing 1 changed file with 13 additions and 55 deletions.
68 changes: 13 additions & 55 deletions htdocs/core/modules/societe/doc/doc_generic_odt.modules.php
Expand Up @@ -150,7 +150,7 @@ function info($langs)
}
$texte.='<div id="div_'.get_class($this).'">';
}

$texte.= '</td>';

$texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">';
Expand Down Expand Up @@ -272,53 +272,6 @@ function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidede
}
//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();

Expand All @@ -333,7 +286,7 @@ function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidede
if ($num)
{
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';

$i=0;
$contactstatic = new Contact($this->db);

Expand Down Expand Up @@ -380,13 +333,18 @@ function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidede
}
}

// 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)
Expand Down Expand Up @@ -438,13 +396,13 @@ function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidede
$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();
Expand All @@ -453,7 +411,7 @@ function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidede
}
$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));

Expand Down

0 comments on commit cad44ee

Please sign in to comment.