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)
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]);
332 $contactobject =
null;
334 if (!empty($usecontact)) {
337 $object->contact->fetch_thirdparty();
338 $socobject =
$object->contact->thirdparty;
339 $contactobject =
$object->contact;
341 $socobject =
$object->thirdparty;
343 $contactobject =
$object->contact;
346 $socobject =
$object->thirdparty;
349 $substitutionarray = array(
350 '__FROM_NAME__' => $this->emetteur->name,
351 '__FROM_EMAIL__' => $this->emetteur->email,
352 '__TOTAL_TTC__' =>
$object->total_ttc,
353 '__TOTAL_HT__' =>
$object->total_ht,
354 '__TOTAL_VAT__' =>
$object->total_tva
358 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$substitutionarray);
359 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
363 $paramfreetext =
'user_FREE_TEXT';
369 require_once ODTPHP_PATH.
'odf.php';
371 $odfHandler =
new Odf(
374 'PATH_TO_TMP' =>
$conf->user->dir_temp,
376 'DELIMITER_LEFT' =>
'{',
377 'DELIMITER_RIGHT' =>
'}'
381 $this->error = $e->getMessage();
394 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
395 }
catch (OdfException $e) {
407 $array_thirdparty_contact = array();
408 if ($usecontact && is_object($contactobject)) {
412 $tmparray = array_merge($array_global, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
416 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
417 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
426 foreach ($tmparray as $key => $value) {
428 if (preg_match(
'/logo$/', $key)) {
429 if (file_exists($value)) {
430 $odfHandler->setImage($key, $value, $ratio);
432 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
435 $odfHandler->setVars($key, $value,
true,
'UTF-8');
437 }
catch (OdfException $e) {
442 $foundtagforlines = 1;
444 $listlines = $odfHandler->setSegment(
'lines');
445 }
catch (OdfExceptionSegmentNotFound $e) {
447 $foundtagforlines = 0;
450 if ($foundtagforlines) {
451 foreach (
$object->members as $u) {
453 unset($tmparray[
'object_pass']);
454 unset($tmparray[
'object_pass_indatabase']);
457 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray,
'line' => $u);
458 $reshook = $hookmanager->executeHooks(
'ODTSubstitutionLine', $parameters, $this, $action);
459 foreach ($tmparray as $key => $val) {
461 if (!is_array($val)) {
462 $listlines->setVars($key, $val,
true,
'UTF-8');
464 }
catch (SegmentException $e) {
471 $odfHandler->mergeSegment($listlines);
472 }
catch (OdfException $e) {
473 $this->error = $e->getMessage();
480 $tmparray = $outputlangs->get_translations_for_substitutions();
481 foreach ($tmparray as $key => $value) {
483 $odfHandler->setVars($key, $value,
true,
'UTF-8');
484 }
catch (OdfException $e) {
490 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
491 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
496 $odfHandler->exportAsAttachedPDF($file);
498 $this->error = $e->getMessage();
504 $odfHandler->saveToDisk($file);
506 $this->error = $e->getMessage();
512 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
518 $this->result = array(
'fullpath' => $file);
522 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);