99 public function info($langs)
101 global $conf, $langs;
104 $langs->loadLangs(array(
"errors",
"companies"));
106 $form =
new Form($this->db);
112 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" enctype="multipart/form-data">';
113 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
114 $texte .=
'<input type="hidden" name="page_y" value="">';
115 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
116 $texte .=
'<input type="hidden" name="param1" value="USERGROUP_ADDON_PDF_ODT_PATH">';
118 $texte .=
'<input type="hidden" name="param2" value="USERGROUP_ADDON_PDF_ODT_DEFAULT">';
119 $texte .=
'<input type="hidden" name="param3" value="USERGROUP_ADDON_PDF_ODT_TOBILL">';
120 $texte .=
'<input type="hidden" name="param4" value="USERGROUP_ADDON_PDF_ODT_CLOSED">';
122 $texte .=
'<table class="nobordernopadding" width="100%">';
125 $texte .=
'<tr><td>';
126 $texttitle = $langs->trans(
"ListOfDirectories");
127 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', $odtPath));
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");
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 if (count($listofdir)) {
162 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>'.count($listoffiles).
'</b>';
167 $texte .=
'<table width="50%;">';
169 $texte .=
'<td width="60%;">'.$langs->trans(
"DefaultModelPropalCreate").
'</td>';
170 $texte .=
'<td colspan="">';
171 $texte .= $form->selectarray(
'value2', $list,
getDolGlobalString(
'USERGROUP_ADDON_PDF_ODT_DEFAULT'));
172 $texte .=
"</td></tr>";
175 $texte .=
'<td width="60%;">'.$langs->trans(
"DefaultModelPropalToBill").
'</td>';
176 $texte .=
'<td colspan="">';
177 $texte .= $form->selectarray(
'value3', $list,
getDolGlobalString(
'USERGROUP_ADDON_PDF_ODT_TOBILL'));
178 $texte .=
"</td></tr>";
181 $texte .=
'<td width="60%;">'.$langs->trans(
"DefaultModelPropalClosed").
'</td>';
182 $texte .=
'<td colspan="">';
183 $texte .= $form->selectarray(
'value4', $list,
getDolGlobalString(
'USERGROUP_ADDON_PDF_ODT_CLOSED'));
184 $texte .=
"</td></tr>";
185 $texte .=
'</table>';
187 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
189 foreach ($listoffiles as $file) {
190 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=usergroups/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
191 $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>';
197 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
199 $maxmin = $maxfilesizearray[
'maxmin'];
201 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
203 $texte .=
' <input type="file" name="uploadfile">';
204 $texte .=
'<input type="hidden" value="USERGROUP_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
205 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
212 $texte .=
'</table>';
230 public function write_file(
$object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
233 global $user, $langs, $conf, $mysoc, $hookmanager;
235 if (empty($srctemplatepath)) {
236 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
241 if (!is_object($hookmanager)) {
242 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
245 $hookmanager->initHooks(array(
'odtgeneration'));
248 if (!is_object($outputlangs)) {
249 $outputlangs = $langs;
251 $sav_charset_output = $outputlangs->charset_output;
252 $outputlangs->charset_output =
'UTF-8';
255 $outputlangs->loadLangs(array(
"main",
"companies",
"bills",
"dict"));
257 if ($conf->user->dir_output) {
269 $dir = $conf->user->dir_output.
'/usergroups';
271 if (!preg_match(
'/specimen/i', $objectref)) {
272 $dir .=
"/".$objectref;
274 $file = $dir.
"/".$objectref.
".odt";
276 if (!file_exists($dir)) {
278 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
283 if (file_exists($dir)) {
285 $newfile = basename($srctemplatepath);
286 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
287 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
288 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
290 $newfiletmp = $objectref .
'_' . $newfiletmp;
293 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
296 if ($format ==
'1') {
297 $format =
'%Y%m%d%H%M%S';
301 $filename = $newfiletmp .
'.' . $newfileformat;
303 $file = $dir .
'/' . $filename;
310 if (!is_writable($conf->user->dir_temp)) {
311 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->user->dir_temp);
312 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
318 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
319 if (count($arrayidcontact) > 0) {
321 $result =
$object->fetch_contact($arrayidcontact[0]);
325 if (!empty($usecontact)) {
327 if (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
328 $object->contact->fetch_thirdparty();
329 $socobject =
$object->contact->thirdparty;
330 $contactobject =
$object->contact;
332 $socobject =
$object->thirdparty;
334 $contactobject =
$object->contact;
337 $socobject =
$object->thirdparty;
340 $substitutionarray = array(
341 '__FROM_NAME__' => $this->emetteur->name,
342 '__FROM_EMAIL__' => $this->emetteur->email,
343 '__TOTAL_TTC__' =>
$object->total_ttc,
344 '__TOTAL_HT__' =>
$object->total_ht,
345 '__TOTAL_VAT__' =>
$object->total_tva
349 $parameters = array(
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$substitutionarray);
350 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
354 $paramfreetext =
'user_FREE_TEXT';
355 if (!empty($conf->global->$paramfreetext)) {
360 require_once ODTPHP_PATH.
'odf.php';
362 $odfHandler =
new Odf(
365 'PATH_TO_TMP' => $conf->user->dir_temp,
366 'ZIP_PROXY' =>
'PclZipProxy',
367 'DELIMITER_LEFT' =>
'{',
368 'DELIMITER_RIGHT' =>
'}'
372 $this->error = $e->getMessage();
385 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
386 }
catch (OdfException $e) {
398 $array_thirdparty_contact = array();
399 if ($usecontact && is_object($contactobject)) {
403 $tmparray = array_merge($array_global, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
407 $parameters = array(
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
408 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
409 foreach ($tmparray as $key => $value) {
411 if (preg_match(
'/logo$/', $key)) {
412 if (file_exists($value)) {
413 $odfHandler->setImage($key, $value);
415 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
418 $odfHandler->setVars($key, $value,
true,
'UTF-8');
420 }
catch (OdfException $e) {
425 $foundtagforlines = 1;
427 $listlines = $odfHandler->setSegment(
'lines');
428 }
catch (OdfExceptionSegmentNotFound $e) {
430 $foundtagforlines = 0;
433 if ($foundtagforlines) {
434 foreach (
$object->members as $u) {
436 unset($tmparray[
'object_pass']);
437 unset($tmparray[
'object_pass_indatabase']);
440 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray,
'line'=>$u);
441 $reshook = $hookmanager->executeHooks(
'ODTSubstitutionLine', $parameters, $this, $action);
442 foreach ($tmparray as $key => $val) {
444 if (!is_array($val)) {
445 $listlines->setVars($key, $val,
true,
'UTF-8');
447 }
catch (SegmentException $e) {
454 $odfHandler->mergeSegment($listlines);
455 }
catch (OdfException $e) {
456 $this->error = $e->getMessage();
463 $tmparray = $outputlangs->get_translations_for_substitutions();
464 foreach ($tmparray as $key => $value) {
466 $odfHandler->setVars($key, $value,
true,
'UTF-8');
467 }
catch (OdfException $e) {
473 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs);
474 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
479 $odfHandler->exportAsAttachedPDF($file);
481 $this->error = $e->getMessage();
487 $odfHandler->saveToDisk($file);
489 $this->error = $e->getMessage();
495 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
501 $this->result = array(
'fullpath'=>$file);
505 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);