107 global
$conf, $langs;
110 $langs->loadLangs(array(
"errors",
"companies"));
112 $form =
new Form($this->db);
118 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" enctype="multipart/form-data">';
119 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
120 $texte .=
'<input type="hidden" name="page_y" value="">';
121 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
122 $texte .=
'<input type="hidden" name="param1" value="USERGROUP_ADDON_PDF_ODT_PATH">';
124 $texte .=
'<input type="hidden" name="param2" value="USERGROUP_ADDON_PDF_ODT_DEFAULT">';
125 $texte .=
'<input type="hidden" name="param3" value="USERGROUP_ADDON_PDF_ODT_TOBILL">';
126 $texte .=
'<input type="hidden" name="param4" value="USERGROUP_ADDON_PDF_ODT_CLOSED">';
128 $texte .=
'<table class="nobordernopadding" width="100%">';
131 $texte .=
'<tr><td>';
132 $texttitle = $langs->trans(
"ListOfDirectories");
133 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', $odtPath));
134 $listoffiles = array();
135 foreach ($listofdir as $key => $tmpdir) {
136 $tmpdir = trim($tmpdir);
137 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
139 unset($listofdir[$key]);
142 if (!is_dir($tmpdir)) {
143 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir),
'');
145 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
146 if (count($tmpfiles)) {
147 $listoffiles = array_merge($listoffiles, $tmpfiles);
151 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
152 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
154 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
155 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
158 if (count($listofdir)) {
159 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>'.count($listoffiles).
'</b>';
164 $texte .=
'<table width="50%;">';
166 $texte .=
'<td width="60%;">'.$langs->trans(
"DefaultModelPropalCreate").
'</td>';
167 $texte .=
'<td colspan="">';
168 $texte .= $form->selectarray(
'value2', $list,
getDolGlobalString(
'USERGROUP_ADDON_PDF_ODT_DEFAULT'));
169 $texte .=
"</td></tr>";
172 $texte .=
'<td width="60%;">'.$langs->trans(
"DefaultModelPropalToBill").
'</td>';
173 $texte .=
'<td colspan="">';
174 $texte .= $form->selectarray(
'value3', $list,
getDolGlobalString(
'USERGROUP_ADDON_PDF_ODT_TOBILL'));
175 $texte .=
"</td></tr>";
178 $texte .=
'<td width="60%;">'.$langs->trans(
"DefaultModelPropalClosed").
'</td>';
179 $texte .=
'<td colspan="">';
180 $texte .= $form->selectarray(
'value4', $list,
getDolGlobalString(
'USERGROUP_ADDON_PDF_ODT_CLOSED'));
181 $texte .=
"</td></tr>";
182 $texte .=
'</table>';
184 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
186 foreach ($listoffiles as $file) {
187 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=usergroups/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
188 $texte .=
' <a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?modulepart=doctemplates&keyforuploaddir=USERGROUP_ADDON_PDF_ODT_PATH&action=deletefile&token='.
newToken().
'&file='.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'delete').
'</a>';
195 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
196 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
197 $texte .=
'<textarea class="flat textareafordir" spellcheck="false" cols="60" name="value1">';
199 $texte .=
'</textarea>';
200 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
201 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dol_escape_htmltag($langs->trans(
"Modify")).
'">';
202 $texte .=
'<br></div></div>';
205 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
207 $maxmin = $maxfilesizearray[
'maxmin'];
209 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
211 $texte .=
' <input type="file" name="uploadfile">';
212 $texte .=
'<input type="hidden" value="USERGROUP_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
213 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
220 $texte .=
'</table>';
238 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
241 global $user, $langs,
$conf, $mysoc, $hookmanager;
243 if (empty($srctemplatepath)) {
244 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
249 if (!is_object($hookmanager)) {
250 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
253 $hookmanager->initHooks(array(
'odtgeneration'));
256 if (!is_object($outputlangs)) {
257 $outputlangs = $langs;
259 $sav_charset_output = $outputlangs->charset_output;
260 $outputlangs->charset_output =
'UTF-8';
263 $outputlangs->loadLangs(array(
"main",
"companies",
"bills",
"dict"));
265 if (
$conf->user->dir_output) {
277 $dir =
$conf->user->dir_output.
'/usergroups';
279 if (!preg_match(
'/specimen/i', $objectref)) {
280 $dir .=
"/".$objectref;
282 $file = $dir.
"/".$objectref.
".odt";
284 if (!file_exists($dir)) {
286 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
291 if (file_exists($dir)) {
293 $newfile = basename($srctemplatepath);
294 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
295 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
296 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
298 $newfiletmp = $objectref .
'_' . $newfiletmp;
301 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
304 if ($format ==
'1') {
305 $format =
'%Y%m%d%H%M%S';
309 $filename = $newfiletmp .
'.' . $newfileformat;
311 $file = $dir .
'/' . $filename;
318 if (!is_writable(
$conf->user->dir_temp)) {
319 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory",
$conf->user->dir_temp);
320 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
326 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
327 if (count($arrayidcontact) > 0) {
329 $result =
$object->fetch_contact($arrayidcontact[0]);
333 if (!empty($usecontact)) {
336 $object->contact->fetch_thirdparty();
337 $socobject =
$object->contact->thirdparty;
338 $contactobject =
$object->contact;
340 $socobject =
$object->thirdparty;
342 $contactobject =
$object->contact;
345 $socobject =
$object->thirdparty;
348 $substitutionarray = array(
349 '__FROM_NAME__' => $this->emetteur->name,
350 '__FROM_EMAIL__' => $this->emetteur->email,
351 '__TOTAL_TTC__' =>
$object->total_ttc,
352 '__TOTAL_HT__' =>
$object->total_ht,
353 '__TOTAL_VAT__' =>
$object->total_tva
357 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$substitutionarray);
358 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
362 $paramfreetext =
'user_FREE_TEXT';
368 require_once ODTPHP_PATH.
'odf.php';
370 $odfHandler =
new Odf(
373 'PATH_TO_TMP' =>
$conf->user->dir_temp,
375 'DELIMITER_LEFT' =>
'{',
376 'DELIMITER_RIGHT' =>
'}'
380 $this->error = $e->getMessage();
393 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
394 }
catch (OdfException $e) {
406 $array_thirdparty_contact = array();
407 if ($usecontact && is_object($contactobject)) {
411 $tmparray = array_merge($array_global, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
415 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
416 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
425 foreach ($tmparray as $key => $value) {
427 if (preg_match(
'/logo$/', $key)) {
428 if (file_exists($value)) {
429 $odfHandler->setImage($key, $value, $ratio);
431 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
434 $odfHandler->setVars($key, $value,
true,
'UTF-8');
436 }
catch (OdfException $e) {
441 $foundtagforlines = 1;
443 $listlines = $odfHandler->setSegment(
'lines');
444 }
catch (OdfExceptionSegmentNotFound $e) {
446 $foundtagforlines = 0;
449 if ($foundtagforlines) {
450 foreach (
$object->members as $u) {
452 unset($tmparray[
'object_pass']);
453 unset($tmparray[
'object_pass_indatabase']);
456 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray,
'line' => $u);
457 $reshook = $hookmanager->executeHooks(
'ODTSubstitutionLine', $parameters, $this, $action);
458 foreach ($tmparray as $key => $val) {
460 if (!is_array($val)) {
461 $listlines->setVars($key, $val,
true,
'UTF-8');
463 }
catch (SegmentException $e) {
470 $odfHandler->mergeSegment($listlines);
471 }
catch (OdfException $e) {
472 $this->error = $e->getMessage();
479 $tmparray = $outputlangs->get_translations_for_substitutions();
480 foreach ($tmparray as $key => $value) {
482 $odfHandler->setVars($key, $value,
true,
'UTF-8');
483 }
catch (OdfException $e) {
489 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
490 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
495 $odfHandler->exportAsAttachedPDF($file);
497 $this->error = $e->getMessage();
503 $odfHandler->saveToDisk($file);
505 $this->error = $e->getMessage();
511 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
517 $this->result = array(
'fullpath' => $file);
521 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);