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="COMMANDE_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->COMMANDE_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="'.dol_escape_htmltag($langs->trans(
"Modify")).
'">';
152 $texte .=
'<br></div></div>';
155 $nbofiles = count($listoffiles);
157 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
159 $texte .= count($listoffiles);
165 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
167 foreach ($listoffiles as $file) {
168 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=orders/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
169 $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>';
175 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
177 $maxmin = $maxfilesizearray[
'maxmin'];
179 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
181 $texte .=
' <input type="file" name="uploadfile">';
182 $texte .=
'<input type="hidden" value="COMMANDE_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
183 $texte .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
190 $texte .=
'</table>';
208 public function write_file(
$object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
211 global $user, $langs, $conf, $mysoc, $hookmanager;
213 if (empty($srctemplatepath)) {
214 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
219 if (!is_object($hookmanager)) {
220 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
223 $hookmanager->initHooks(array(
'odtgeneration'));
226 if (!is_object($outputlangs)) {
227 $outputlangs = $langs;
229 $sav_charset_output = $outputlangs->charset_output;
230 $outputlangs->charset_output =
'UTF-8';
233 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills"));
235 if ($conf->commande->dir_output) {
249 $dir = $conf->commande->multidir_output[
$object->entity];
251 if (!preg_match(
'/specimen/i', $objectref)) {
252 $dir .=
"/".$objectref;
254 $file = $dir.
"/".$objectref.
".odt";
256 if (!file_exists($dir)) {
258 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
263 if (file_exists($dir)) {
265 $newfile = basename($srctemplatepath);
266 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
267 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
268 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
269 $newfiletmp = $objectref .
'_' . $newfiletmp;
272 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
275 if ($format ==
'1') {
276 $format =
'%Y%m%d%H%M%S';
280 $filename = $newfiletmp .
'.' . $newfileformat;
282 $file = $dir .
'/' . $filename;
289 if (!is_writable($conf->commande->dir_temp)) {
290 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->commande->dir_temp);
291 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
297 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
298 if (count($arrayidcontact) > 0) {
300 $result =
$object->fetch_contact($arrayidcontact[0]);
304 $contactobject =
null;
305 if (!empty($usecontact)) {
307 if (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
308 $object->contact->fetch_thirdparty();
309 $socobject =
$object->contact->thirdparty;
310 $contactobject =
$object->contact;
312 $socobject =
$object->thirdparty;
314 $contactobject =
$object->contact;
317 $socobject =
$object->thirdparty;
321 $substitutionarray = array(
322 '__FROM_NAME__' => $this->emetteur->name,
323 '__FROM_EMAIL__' => $this->emetteur->email,
324 '__TOTAL_TTC__' =>
$object->total_ttc,
325 '__TOTAL_HT__' =>
$object->total_ht,
326 '__TOTAL_VAT__' =>
$object->total_tva
330 $parameters = array(
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$substitutionarray);
331 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
335 $paramfreetext =
'ORDER_FREE_TEXT';
336 if (!empty($conf->global->$paramfreetext)) {
341 require_once ODTPHP_PATH.
'odf.php';
343 $odfHandler =
new Odf(
346 'PATH_TO_TMP' => $conf->commande->dir_temp,
348 'DELIMITER_LEFT' =>
'{',
349 'DELIMITER_RIGHT' =>
'}'
353 $this->error = $e->getMessage();
366 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
367 }
catch (OdfException $e) {
374 $array_objet = $this->get_substitutionarray_object(
$object, $outputlangs);
380 $array_thirdparty_contact = array();
382 if ($usecontact && is_object($contactobject)) {
386 $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
390 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
391 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
393 foreach ($tmparray as $key => $value) {
395 if (preg_match(
'/logo$/', $key)) {
396 if (file_exists($value)) {
397 $odfHandler->setImage($key, $value);
399 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
402 $odfHandler->setVars($key, $value,
true,
'UTF-8');
404 }
catch (OdfException $e) {
409 $foundtagforlines = 1;
411 $listlines = $odfHandler->setSegment(
'lines');
412 }
catch (OdfExceptionSegmentNotFound $e) {
414 $foundtagforlines = 0;
417 if ($foundtagforlines) {
419 foreach (
$object->lines as $line) {
424 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray,
'line'=>$line);
425 $reshook = $hookmanager->executeHooks(
'ODTSubstitutionLine', $parameters, $this, $action);
426 foreach ($tmparray as $key => $val) {
428 $listlines->setVars($key, $val,
true,
'UTF-8');
429 }
catch (SegmentException $e) {
436 $odfHandler->mergeSegment($listlines);
437 }
catch (OdfException $e) {
438 $this->error = $e->getMessage();
445 $tmparray = $outputlangs->get_translations_for_substitutions();
446 foreach ($tmparray as $key => $value) {
448 $odfHandler->setVars($key, $value,
true,
'UTF-8');
449 }
catch (OdfException $e) {
455 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
456 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
461 $odfHandler->exportAsAttachedPDF($file);
463 $this->error = $e->getMessage();
469 $odfHandler->saveToDisk($file);
471 $this->error = $e->getMessage();
477 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
478 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
484 $this->result = array(
'fullpath'=>$file);
488 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);