104 global $conf, $langs;
107 $langs->loadLangs(array(
'companies',
'errors'));
109 $form =
new Form($this->db);
115 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" enctype="multipart/form-data">';
116 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
117 $texte .=
'<input type="hidden" name="page_y" value="">';
118 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
119 $texte .=
'<input type="hidden" name="param1" value="USER_ADDON_PDF_ODT_PATH">';
121 $texte .=
'<input type="hidden" name="param2" value="USER_ADDON_PDF_ODT_DEFAULT">';
122 $texte .=
'<input type="hidden" name="param3" value="USER_ADDON_PDF_ODT_TOBILL">';
123 $texte .=
'<input type="hidden" name="param4" value="USER_ADDON_PDF_ODT_CLOSED">';
125 $texte .=
'<table class="nobordernopadding" width="100%">';
128 $texte .=
'<tr><td>';
129 $texttitle = $langs->trans(
"ListOfDirectories");
130 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', $odtPath));
131 $listoffiles = array();
132 foreach ($listofdir as $key => $tmpdir) {
133 $tmpdir = trim($tmpdir);
134 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
136 unset($listofdir[$key]);
139 if (!is_dir($tmpdir)) {
140 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir), 0);
142 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
143 if (count($tmpfiles)) {
144 $listoffiles = array_merge($listoffiles, $tmpfiles);
148 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
150 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
151 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
153 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1);
154 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
155 $texte .=
'<textarea class="flat" cols="60" name="value1">';
157 $texte .=
'</textarea>';
158 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
159 $texte .=
'<input type="submit" class="button small reposition" name="modify" value="'.$langs->trans(
"Modify").
'">';
160 $texte .=
'<br></div></div>';
163 if (count($listofdir)) {
164 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>'.count($listoffiles).
'</b>';
169 $texte .=
'<table width="50%;">';
171 $texte .=
'<td width="60%;">'.$langs->trans(
"DefaultModelPropalCreate").
'</td>';
172 $texte .=
'<td colspan="">';
173 $texte .= $form->selectarray(
'value2', $list,
getDolGlobalString(
'USER_ADDON_PDF_ODT_DEFAULT'));
174 $texte .=
"</td></tr>";
177 $texte .=
'<td width="60%;">'.$langs->trans(
"DefaultModelPropalToBill").
'</td>';
178 $texte .=
'<td colspan="">';
179 $texte .= $form->selectarray(
'value3', $list,
getDolGlobalString(
'USER_ADDON_PDF_ODT_TOBILL'));
180 $texte .=
"</td></tr>";
183 $texte .=
'<td width="60%;">'.$langs->trans(
"DefaultModelPropalClosed").
'</td>';
184 $texte .=
'<td colspan="">';
185 $texte .= $form->selectarray(
'value4', $list,
getDolGlobalString(
'USER_ADDON_PDF_ODT_CLOSED'));
186 $texte .=
"</td></tr>";
187 $texte .=
'</table>';
189 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
191 foreach ($listoffiles as $file) {
192 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=users/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
193 $texte .=
' <a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?modulepart=doctemplates&keyforuploaddir=USER_ADDON_PDF_ODT_PATH&action=deletefile&token='.newToken().
'&file='.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'delete').
'</a>';
199 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
201 $maxmin = $maxfilesizearray[
'maxmin'];
203 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
205 $texte .=
' <input type="file" name="uploadfile">';
206 $texte .=
'<input type="hidden" value="USER_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
207 $texte .=
'<input type="submit" class="button small reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
212 $texte .=
'<td rowspan="2" class="tdtop hideonsmartphone">';
213 $texte .=
'<span class="opacitymedium">';
214 $texte .= $langs->trans(
"ExampleOfDirectoriesForModelGen");
219 $texte .=
'</table>';
237 public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
240 global $user, $langs, $conf, $mysoc, $hookmanager;
242 if (empty($srctemplatepath)) {
243 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
248 if (!is_object($hookmanager)) {
249 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
252 $hookmanager->initHooks(array(
'odtgeneration'));
255 if (!is_object($outputlangs)) {
256 $outputlangs = $langs;
258 $sav_charset_output = $outputlangs->charset_output;
259 $outputlangs->charset_output =
'UTF-8';
262 $outputlangs->loadLangs(array(
"main",
"companies",
"bills",
"dict"));
264 if ($conf->user->dir_output) {
266 if (!is_object($object)) {
268 $object =
new User($this->db);
269 $result = $object->fetch($id);
276 $object->fetch_thirdparty();
278 $dir = $conf->user->dir_output;
280 if (!preg_match(
'/specimen/i', $objectref)) {
281 $dir .=
"/".$objectref;
283 $file = $dir.
"/".$objectref.
".odt";
285 if (!file_exists($dir)) {
287 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
292 if (file_exists($dir)) {
294 $newfile = basename($srctemplatepath);
295 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
296 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
297 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
299 $newfiletmp = $objectref .
'_' . $newfiletmp;
302 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
305 if ($format ==
'1') {
306 $format =
'%Y%m%d%H%M%S';
310 $filename = $newfiletmp .
'.' . $newfileformat;
312 $file = $dir .
'/' . $filename;
319 if (!is_writable($conf->user->dir_temp)) {
320 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->user->dir_temp);
321 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
327 $arrayidcontact = $object->getIdContact(
'external',
'CUSTOMER');
328 if (count($arrayidcontact) > 0) {
330 $result = $object->fetch_contact($arrayidcontact[0]);
334 if (!empty($usecontact)) {
335 if ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT))) {
336 $socobject = $object->contact;
338 $socobject = $object->thirdparty;
340 $contactobject = $object->contact;
343 $socobject = $object->thirdparty;
347 require_once ODTPHP_PATH.
'odf.php';
349 $odfHandler =
new Odf(
352 'PATH_TO_TMP' => $conf->user->dir_temp,
353 'ZIP_PROXY' =>
'PclZipProxy',
354 'DELIMITER_LEFT' =>
'{',
355 'DELIMITER_RIGHT' =>
'}'
359 $this->error = $e->getMessage();
370 $array_thirdparty_contact = array();
371 if ($usecontact && is_object($contactobject)) {
375 $tmparray = array_merge($array_user, $array_soc, $array_thirdparty, $array_other, $array_thirdparty_contact);
377 $object->fetch_optionals();
379 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
380 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
381 foreach ($tmparray as $key => $value) {
383 if (preg_match(
'/logo$/', $key)) {
384 if (file_exists($value)) {
385 $odfHandler->setImage($key, $value);
387 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
391 $odfHandler->setVars($key, $value,
true,
'UTF-8');
393 }
catch (OdfException $e) {
399 $tmparray = $outputlangs->get_translations_for_substitutions();
400 foreach ($tmparray as $key => $value) {
402 $odfHandler->setVars($key, $value,
true,
'UTF-8');
403 }
catch (OdfException $e) {
409 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
410 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
413 if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
415 $odfHandler->exportAsAttachedPDF($file);
417 $this->error = $e->getMessage();
423 $odfHandler->saveToDisk($file);
425 $this->error = $e->getMessage();
431 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
437 $this->result = array(
'fullpath'=>$file);
441 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);