109 global $conf, $langs;
112 $langs->loadLangs(array(
"errors",
"companies"));
114 $form =
new Form($this->db);
117 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" enctype="multipart/form-data">';
118 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
119 $texte .=
'<input type="hidden" name="page_y" value="">';
120 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
121 $texte .=
'<input type="hidden" name="param1" value="COMMANDE_ADDON_PDF_ODT_PATH">';
122 $texte .=
'<table class="nobordernopadding" width="100%">';
125 $texte .=
'<tr><td>';
126 $texttitle = $langs->trans(
"ListOfDirectories");
127 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim($conf->global->COMMANDE_ADDON_PDF_ODT_PATH)));
128 $listoffiles = array();
129 foreach ($listofdir as $key => $tmpdir) {
130 $tmpdir = trim($tmpdir);
131 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
133 unset($listofdir[$key]);
136 if (!is_dir($tmpdir)) {
137 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir), 0);
139 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
140 if (count($tmpfiles)) {
141 $listoffiles = array_merge($listoffiles, $tmpfiles);
145 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
147 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
148 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
150 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1);
151 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
152 $texte .=
'<textarea class="flat" cols="60" name="value1">';
153 $texte .= $conf->global->COMMANDE_ADDON_PDF_ODT_PATH;
154 $texte .=
'</textarea>';
155 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
156 $texte .=
'<input type="submit" class="button small reposition" name="modify" value="'.dol_escape_htmltag($langs->trans(
"Modify")).
'">';
157 $texte .=
'<br></div></div>';
160 $nbofiles = count($listoffiles);
161 if (!empty($conf->global->COMMANDE_ADDON_PDF_ODT_PATH)) {
162 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
164 $texte .= count($listoffiles);
170 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
172 foreach ($listoffiles as $file) {
173 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=orders/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
174 $texte .=
' <a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?modulepart=doctemplates&keyforuploaddir=COMMANDE_ADDON_PDF_ODT_PATH&action=deletefile&token='.newToken().
'&file='.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'delete').
'</a>';
180 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
182 $maxmin = $maxfilesizearray[
'maxmin'];
184 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
186 $texte .=
' <input type="file" name="uploadfile">';
187 $texte .=
'<input type="hidden" value="COMMANDE_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
188 $texte .=
'<input type="submit" class="button small reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
193 $texte .=
'<td rowspan="2" class="tdtop hideonsmartphone">';
194 $texte .=
'<span class="opacitymedium">';
195 $texte .= $langs->trans(
"ExampleOfDirectoriesForModelGen");
200 $texte .=
'</table>';
218 public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
221 global $user, $langs, $conf, $mysoc, $hookmanager;
223 if (empty($srctemplatepath)) {
224 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
229 if (!is_object($hookmanager)) {
230 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
233 $hookmanager->initHooks(array(
'odtgeneration'));
236 if (!is_object($outputlangs)) {
237 $outputlangs = $langs;
239 $sav_charset_output = $outputlangs->charset_output;
240 $outputlangs->charset_output =
'UTF-8';
243 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills"));
245 if ($conf->commande->dir_output) {
247 if (!is_object($object)) {
250 $result = $object->fetch($id);
257 $object->fetch_thirdparty();
259 $dir = $conf->commande->multidir_output[$object->entity];
261 if (!preg_match(
'/specimen/i', $objectref)) {
262 $dir .=
"/".$objectref;
264 $file = $dir.
"/".$objectref.
".odt";
266 if (!file_exists($dir)) {
268 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
273 if (file_exists($dir)) {
275 $newfile = basename($srctemplatepath);
276 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
277 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
278 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
279 $newfiletmp = $objectref .
'_' . $newfiletmp;
282 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
285 if ($format ==
'1') {
286 $format =
'%Y%m%d%H%M%S';
290 $filename = $newfiletmp .
'.' . $newfileformat;
292 $file = $dir .
'/' . $filename;
299 if (!is_writable($conf->commande->dir_temp)) {
300 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->commande->dir_temp);
301 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
307 $arrayidcontact = $object->getIdContact(
'external',
'CUSTOMER');
308 if (count($arrayidcontact) > 0) {
310 $result = $object->fetch_contact($arrayidcontact[0]);
314 $contactobject =
null;
315 if (!empty($usecontact)) {
317 if ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT))) {
318 $object->contact->fetch_thirdparty();
319 $socobject = $object->contact->thirdparty;
320 $contactobject = $object->contact;
322 $socobject = $object->thirdparty;
324 $contactobject = $object->contact;
327 $socobject = $object->thirdparty;
331 $substitutionarray = array(
332 '__FROM_NAME__' => $this->emetteur->name,
333 '__FROM_EMAIL__' => $this->emetteur->email,
334 '__TOTAL_TTC__' => $object->total_ttc,
335 '__TOTAL_HT__' => $object->total_ht,
336 '__TOTAL_VAT__' => $object->total_tva
340 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$substitutionarray);
341 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
345 $paramfreetext =
'ORDER_FREE_TEXT';
346 if (!empty($conf->global->$paramfreetext)) {
351 require_once ODTPHP_PATH.
'odf.php';
353 $odfHandler =
new Odf(
356 'PATH_TO_TMP' => $conf->commande->dir_temp,
357 'ZIP_PROXY' =>
'PclZipProxy',
358 'DELIMITER_LEFT' =>
'{',
359 'DELIMITER_RIGHT' =>
'}'
363 $this->error = $e->getMessage();
376 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
377 }
catch (OdfException $e) {
390 $array_thirdparty_contact = array();
392 if ($usecontact && is_object($contactobject)) {
396 $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
400 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
401 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
403 foreach ($tmparray as $key => $value) {
405 if (preg_match(
'/logo$/', $key)) {
406 if (file_exists($value)) {
407 $odfHandler->setImage($key, $value);
409 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
413 $odfHandler->setVars($key, $value,
true,
'UTF-8');
415 }
catch (OdfException $e) {
421 $foundtagforlines = 1;
423 $listlines = $odfHandler->setSegment(
'lines');
424 }
catch (OdfException $e) {
426 $foundtagforlines = 0;
429 if ($foundtagforlines) {
431 foreach ($object->lines as $line) {
436 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray,
'line'=>$line);
437 $reshook = $hookmanager->executeHooks(
'ODTSubstitutionLine', $parameters, $this, $action);
438 foreach ($tmparray as $key => $val) {
440 $listlines->setVars($key, $val,
true,
'UTF-8');
441 }
catch (OdfException $e) {
443 }
catch (SegmentException $e) {
449 $odfHandler->mergeSegment($listlines);
451 }
catch (OdfException $e) {
452 $this->error = $e->getMessage();
458 $tmparray = $outputlangs->get_translations_for_substitutions();
459 foreach ($tmparray as $key => $value) {
461 $odfHandler->setVars($key, $value,
true,
'UTF-8');
462 }
catch (OdfException $e) {
468 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
469 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
472 if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
474 $odfHandler->exportAsAttachedPDF($file);
476 $this->error = $e->getMessage();
482 $odfHandler->saveToDisk($file);
484 $this->error = $e->getMessage();
490 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
491 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
497 $this->result = array(
'fullpath'=>$file);
501 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);