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),
'');
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");
146 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
148 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
149 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
151 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
152 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
153 $texte .=
'<textarea class="flat" cols="60" name="value1">';
155 $texte .=
'</textarea>';
156 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
157 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dol_escape_htmltag($langs->trans(
"Modify")).
'">';
158 $texte .=
'<br></div></div>';
161 $nbofiles = count($listoffiles);
163 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
165 $texte .= count($listoffiles);
171 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
173 foreach ($listoffiles as $file) {
174 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=orders/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
175 $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>';
181 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
183 $maxmin = $maxfilesizearray[
'maxmin'];
185 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
187 $texte .=
' <input type="file" name="uploadfile">';
188 $texte .=
'<input type="hidden" value="COMMANDE_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
189 $texte .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
196 $texte .=
'</table>';
214 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
217 global $user, $langs, $conf, $mysoc, $hookmanager;
219 if (empty($srctemplatepath)) {
220 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
225 if (!is_object($hookmanager)) {
226 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
229 $hookmanager->initHooks(array(
'odtgeneration'));
232 if (!is_object($outputlangs)) {
233 $outputlangs = $langs;
235 $sav_charset_output = $outputlangs->charset_output;
236 $outputlangs->charset_output =
'UTF-8';
239 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills"));
241 if ($conf->commande->dir_output) {
255 $dir = $conf->commande->multidir_output[
$object->entity];
257 if (!preg_match(
'/specimen/i', $objectref)) {
258 $dir .=
"/".$objectref;
260 $file = $dir.
"/".$objectref.
".odt";
262 if (!file_exists($dir)) {
264 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
269 if (file_exists($dir)) {
271 $newfile = basename($srctemplatepath);
272 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
273 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
274 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
275 $newfiletmp = $objectref .
'_' . $newfiletmp;
278 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
281 if ($format ==
'1') {
282 $format =
'%Y%m%d%H%M%S';
286 $filename = $newfiletmp .
'.' . $newfileformat;
288 $file = $dir .
'/' . $filename;
295 if (!is_writable($conf->commande->dir_temp)) {
296 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->commande->dir_temp);
297 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
303 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
304 if (count($arrayidcontact) > 0) {
306 $result =
$object->fetch_contact($arrayidcontact[0]);
310 $contactobject =
null;
311 if (!empty($usecontact)) {
313 if (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
314 $object->contact->fetch_thirdparty();
315 $socobject =
$object->contact->thirdparty;
316 $contactobject =
$object->contact;
318 $socobject =
$object->thirdparty;
320 $contactobject =
$object->contact;
323 $socobject =
$object->thirdparty;
327 $substitutionarray = array(
328 '__FROM_NAME__' => $this->emetteur->name,
329 '__FROM_EMAIL__' => $this->emetteur->email,
330 '__TOTAL_TTC__' =>
$object->total_ttc,
331 '__TOTAL_HT__' =>
$object->total_ht,
332 '__TOTAL_VAT__' =>
$object->total_tva
336 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$substitutionarray);
337 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
341 $paramfreetext =
'ORDER_FREE_TEXT';
347 require_once ODTPHP_PATH.
'odf.php';
349 $odfHandler =
new Odf(
352 'PATH_TO_TMP' => $conf->commande->dir_temp,
354 'DELIMITER_LEFT' =>
'{',
355 'DELIMITER_RIGHT' =>
'}'
359 $this->error = $e->getMessage();
372 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
373 }
catch (OdfException $e) {
380 $array_objet = $this->get_substitutionarray_object(
$object, $outputlangs);
386 $array_thirdparty_contact = array();
388 if ($usecontact && is_object($contactobject)) {
392 $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
396 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
397 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
399 foreach ($tmparray as $key => $value) {
401 if (preg_match(
'/logo$/', $key)) {
402 if (file_exists($value)) {
403 $odfHandler->setImage($key, $value);
405 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
408 $odfHandler->setVars($key, $value,
true,
'UTF-8');
410 }
catch (OdfException $e) {
415 $foundtagforlines = 1;
417 $listlines = $odfHandler->setSegment(
'lines');
418 }
catch (OdfExceptionSegmentNotFound $e) {
420 $foundtagforlines = 0;
423 if ($foundtagforlines) {
425 foreach (
$object->lines as $line) {
430 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray,
'line' => $line);
431 $reshook = $hookmanager->executeHooks(
'ODTSubstitutionLine', $parameters, $this, $action);
432 foreach ($tmparray as $key => $val) {
434 $listlines->setVars($key, $val,
true,
'UTF-8');
435 }
catch (SegmentException $e) {
442 $odfHandler->mergeSegment($listlines);
443 }
catch (OdfException $e) {
444 $this->error = $e->getMessage();
451 $tmparray = $outputlangs->get_translations_for_substitutions();
452 foreach ($tmparray as $key => $value) {
454 $odfHandler->setVars($key, $value,
true,
'UTF-8');
455 }
catch (OdfException $e) {
461 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
462 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
467 $odfHandler->exportAsAttachedPDF($file);
469 $this->error = $e->getMessage();
475 $odfHandler->saveToDisk($file);
477 $this->error = $e->getMessage();
483 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
484 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
490 $this->result = array(
'fullpath' => $file);
494 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);