30 require_once DOL_DOCUMENT_ROOT.
'/core/modules/expedition/modules_expedition.php';
31 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/doc.lib.php';
47 public $version =
'dolibarr';
57 global $conf, $langs, $mysoc;
60 $langs->loadLangs(array(
"main",
"companies"));
63 $this->
name =
"ODT templates";
64 $this->
description = $langs->trans(
"DocumentModelOdt");
65 $this->scandir =
'EXPEDITION_ADDON_PDF_ODT_PATH';
69 $this->page_largeur = 0;
70 $this->page_hauteur = 0;
71 $this->format = array($this->page_largeur, $this->page_hauteur);
72 $this->marge_gauche = 0;
73 $this->marge_droite = 0;
74 $this->marge_haute = 0;
75 $this->marge_basse = 0;
77 $this->option_logo = 1;
78 $this->option_tva = 0;
79 $this->option_modereg = 0;
80 $this->option_condreg = 0;
81 $this->option_multilang = 1;
82 $this->option_escompte = 0;
83 $this->option_credit_note = 0;
84 $this->option_freetext = 1;
85 $this->option_draft_watermark = 0;
88 $this->emetteur = $mysoc;
89 if (!$this->emetteur->country_code) {
90 $this->emetteur->country_code = substr($langs->defaultlang, -2);
103 global $conf, $langs;
106 $langs->loadLangs(array(
"errors",
"companies"));
108 $form =
new Form($this->db);
111 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" enctype="multipart/form-data">';
112 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
113 $texte .=
'<input type="hidden" name="page_y" value="">';
114 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
115 $texte .=
'<input type="hidden" name="param1" value="EXPEDITION_ADDON_PDF_ODT_PATH">';
116 $texte .=
'<table class="nobordernopadding" width="100%">';
119 $texte .=
'<tr><td>';
120 $texttitle = $langs->trans(
"ListOfDirectories");
121 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim($conf->global->EXPEDITION_ADDON_PDF_ODT_PATH)));
122 $listoffiles = array();
123 foreach ($listofdir as $key => $tmpdir) {
124 $tmpdir = trim($tmpdir);
125 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
127 unset($listofdir[$key]);
130 if (!is_dir($tmpdir)) {
131 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir), 0);
133 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
134 if (count($tmpfiles)) {
135 $listoffiles = array_merge($listoffiles, $tmpfiles);
139 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
140 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
142 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
143 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
145 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
146 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
147 $texte .=
'<textarea class="flat" cols="60" name="value1">';
149 $texte .=
'</textarea>';
150 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
151 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.$langs->trans(
"Modify").
'">';
152 $texte .=
'<br></div></div>';
155 $nbofiles = count($listoffiles);
157 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
159 $texte .= count($listoffiles);
164 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
166 foreach ($listoffiles as $file) {
167 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=shipments/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
168 $texte .=
' <a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?modulepart=doctemplates&keyforuploaddir=EXPEDITION_ADDON_PDF_ODT_PATH&action=deletefile&token='.
newToken().
'&file='.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'delete').
'</a>';
174 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
176 $maxmin = $maxfilesizearray[
'maxmin'];
178 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
180 $texte .=
' <input type="file" name="uploadfile">';
181 $texte .=
'<input type="hidden" value="EXPEDITION_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
182 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
188 $texte .=
'</table>';
206 public function write_file(
$object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
209 global $user, $langs, $conf, $mysoc, $hookmanager;
211 if (empty($srctemplatepath)) {
212 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
217 if (!is_object($hookmanager)) {
218 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
221 $hookmanager->initHooks(array(
'odtgeneration'));
224 if (!is_object($outputlangs)) {
225 $outputlangs = $langs;
227 $sav_charset_output = $outputlangs->charset_output;
228 $outputlangs->charset_output =
'UTF-8';
231 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills"));
233 if ($conf->expedition->dir_output.
"/sending") {
247 $dir = $conf->expedition->dir_output.
"/sending";
249 if (!preg_match(
'/specimen/i', $objectref)) {
250 $dir .=
"/".$objectref;
252 $file = $dir.
"/".$objectref.
".odt";
254 if (!file_exists($dir)) {
256 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
261 if (file_exists($dir)) {
263 $newfile = basename($srctemplatepath);
264 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
265 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
266 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
267 $newfiletmp = $objectref .
'_' . $newfiletmp;
270 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
273 if ($format ==
'1') {
274 $format =
'%Y%m%d%H%M%S';
278 $filename = $newfiletmp .
'.' . $newfileformat;
280 $file = $dir .
'/' . $filename;
287 if (!is_writable($conf->expedition->dir_temp)) {
288 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->expedition->dir_temp);
289 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
295 $arrayidcontact =
$object->getIdContact(
'external',
'SHIPPING');
296 if (count($arrayidcontact) > 0) {
298 $result =
$object->fetch_contact($arrayidcontact[0]);
302 $contactobject =
null;
303 if (!empty($usecontact)) {
305 if (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
306 $object->contact->fetch_thirdparty();
307 $socobject =
$object->contact->thirdparty;
308 $contactobject =
$object->contact;
310 $socobject =
$object->thirdparty;
312 $contactobject =
$object->contact;
315 $socobject =
$object->thirdparty;
319 $substitutionarray = array(
320 '__FROM_NAME__' => $this->emetteur->name,
321 '__FROM_EMAIL__' => $this->emetteur->email,
322 '__TOTAL_TTC__' =>
$object->total_ttc,
323 '__TOTAL_HT__' =>
$object->total_ht,
324 '__TOTAL_VAT__' =>
$object->total_tva
328 $parameters = array(
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$substitutionarray);
329 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
333 $paramfreetext =
'EXPEDITION_FREE_TEXT';
334 if (!empty($conf->global->$paramfreetext)) {
339 require_once ODTPHP_PATH.
'odf.php';
341 $odfHandler =
new Odf(
344 'PATH_TO_TMP' => $conf->expedition->dir_temp,
345 'ZIP_PROXY' =>
'PclZipProxy',
346 'DELIMITER_LEFT' =>
'{',
347 'DELIMITER_RIGHT' =>
'}'
351 $this->error = $e->getMessage();
364 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
365 }
catch (OdfException $e) {
372 foreach ($tmparray as $key => $value) {
374 if (preg_match(
'/logo$/', $key)) {
376 if (file_exists($value)) {
377 $odfHandler->setImage($key, $value);
379 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
382 $odfHandler->setVars($key, $value,
true,
'UTF-8');
384 }
catch (OdfException $e) {
391 foreach ($tmparray as $key => $value) {
393 if (preg_match(
'/logo$/', $key)) {
395 if (file_exists($value)) {
396 $odfHandler->setImage($key, $value);
398 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
401 $odfHandler->setVars($key, $value,
true,
'UTF-8');
403 }
catch (OdfException $e) {
408 if ($socobject->element ==
'contact') {
413 foreach ($tmparray as $key => $value) {
415 if (preg_match(
'/logo$/', $key)) {
416 if (file_exists($value)) {
417 $odfHandler->setImage($key, $value);
419 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
422 $odfHandler->setVars($key, $value,
true,
'UTF-8');
424 }
catch (OdfException $e) {
429 if ($usecontact && is_object($contactobject)) {
431 foreach ($tmparray as $key => $value) {
433 if (preg_match(
'/logo$/', $key)) {
434 if (file_exists($value)) {
435 $odfHandler->setImage($key, $value);
437 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
440 $odfHandler->setVars($key, $value,
true,
'UTF-8');
442 }
catch (OdfException $e) {
454 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
455 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
456 foreach ($tmparray as $key => $value) {
458 if (preg_match(
'/logo$/', $key)) {
459 if (file_exists($value)) {
460 $odfHandler->setImage($key, $value);
462 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
465 $odfHandler->setVars($key, $value,
true,
'UTF-8');
467 }
catch (OdfException $e) {
473 $foundtagforlines = 1;
475 $listlines = $odfHandler->setSegment(
'lines');
476 }
catch (OdfExceptionSegmentNotFound $e) {
478 $foundtagforlines = 0;
480 }
catch (OdfException $e) {
481 $foundtagforlines = 0;
484 if ($foundtagforlines) {
485 foreach (
$object->lines as $line) {
489 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray,
'line'=>$line);
490 $reshook = $hookmanager->executeHooks(
'ODTSubstitutionLine', $parameters, $this, $action);
491 foreach ($tmparray as $key => $val) {
493 $listlines->setVars($key, $val,
true,
'UTF-8');
494 }
catch (OdfException $e) {
496 }
catch (SegmentException $e) {
502 $odfHandler->mergeSegment($listlines);
504 }
catch (OdfException $e) {
505 $this->error = $e->getMessage();
511 $tmparray = $outputlangs->get_translations_for_substitutions();
512 foreach ($tmparray as $key => $value) {
514 $odfHandler->setVars($key, $value,
true,
'UTF-8');
515 }
catch (OdfException $e) {
521 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
522 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
527 $odfHandler->exportAsAttachedPDF($file);
529 $this->error = $e->getMessage();
535 $odfHandler->saveToDisk($file);
537 $this->error = $e->getMessage();
542 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
543 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
549 $this->result = array(
'fullpath'=>$file);
553 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
get_substitutionarray_shipment($object, $outputlangs, $array_key='object')
Define array with couple substitution key => substitution value Note that vars into substitutions arr...
get_substitutionarray_mysoc($mysoc, $outputlangs)
Define array with couple substitution key => substitution value.
get_substitutionarray_contact($object, $outputlangs, $array_key='object')
Define array with couple substitution key => substitution value.
get_substitutionarray_other($outputlangs)
Define array with couple substitution key => substitution value.
get_substitutionarray_lines($line, $outputlangs, $linenumber=0)
Define array with couple substitution key => substitution value Note that vars into substitutions arr...
get_substitutionarray_thirdparty($object, $outputlangs, $array_key='company')
Define array with couple substitution key => substitution value For example {company_name},...
get_substitutionarray_user($user, $outputlangs)
Define array with couple substitution key => substitution value.
Class to manage shipments.
Parent class of sending receipts models.
Class to build documents using ODF templates generator.
info($langs)
Return description of a module.
__construct($db)
Constructor.
write_file($object, $outputlangs, $srctemplatepath, $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build a document on disk using the generic odt module.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$conf db name
Only used if Module[ID]Name translation string is not found.
getMaxFileSizeArray()
Return the max allowed for file upload.