97 public function info($langs)
102 $langs->loadLangs(array(
'companies',
'errors'));
104 $form =
new Form($this->db);
110 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" enctype="multipart/form-data">';
111 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
112 $texte .=
'<input type="hidden" name="page_y" value="">';
113 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
114 $texte .=
'<input type="hidden" name="param1" value="USER_ADDON_PDF_ODT_PATH">';
116 $texte .=
'<input type="hidden" name="param2" value="USER_ADDON_PDF_ODT_DEFAULT">';
117 $texte .=
'<input type="hidden" name="param3" value="USER_ADDON_PDF_ODT_TOBILL">';
118 $texte .=
'<input type="hidden" name="param4" value="USER_ADDON_PDF_ODT_CLOSED">';
120 $texte .=
'<table class="nobordernopadding" width="100%">';
123 $texte .=
'<tr><td>';
124 $texttitle = $langs->trans(
"ListOfDirectories");
125 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', $odtPath));
126 $listoffiles = array();
127 foreach ($listofdir as $key => $tmpdir) {
128 $tmpdir = trim($tmpdir);
129 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
131 unset($listofdir[$key]);
134 if (!is_dir($tmpdir)) {
135 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir), 0);
137 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
138 if (count($tmpfiles)) {
139 $listoffiles = array_merge($listoffiles, $tmpfiles);
143 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
144 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
146 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
147 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
149 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
150 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
151 $texte .=
'<textarea class="flat" cols="60" name="value1">';
153 $texte .=
'</textarea>';
154 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
155 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dol_escape_htmltag($langs->trans(
"Modify")).
'">';
156 $texte .=
'<br></div></div>';
159 if (count($listofdir)) {
160 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>'.count($listoffiles).
'</b>';
165 $texte .=
'<table width="50%;">';
167 $texte .=
'<td width="60%;">'.$langs->trans(
"DefaultModelPropalCreate").
'</td>';
168 $texte .=
'<td colspan="">';
169 $texte .= $form->selectarray(
'value2', $list,
getDolGlobalString(
'USER_ADDON_PDF_ODT_DEFAULT'));
170 $texte .=
"</td></tr>";
173 $texte .=
'<td width="60%;">'.$langs->trans(
"DefaultModelPropalToBill").
'</td>';
174 $texte .=
'<td colspan="">';
175 $texte .= $form->selectarray(
'value3', $list,
getDolGlobalString(
'USER_ADDON_PDF_ODT_TOBILL'));
176 $texte .=
"</td></tr>";
179 $texte .=
'<td width="60%;">'.$langs->trans(
"DefaultModelPropalClosed").
'</td>';
180 $texte .=
'<td colspan="">';
181 $texte .= $form->selectarray(
'value4', $list,
getDolGlobalString(
'USER_ADDON_PDF_ODT_CLOSED'));
182 $texte .=
"</td></tr>";
183 $texte .=
'</table>';
185 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
187 foreach ($listoffiles as $file) {
188 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=users/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
189 $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>';
195 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
197 $maxmin = $maxfilesizearray[
'maxmin'];
199 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
201 $texte .=
' <input type="file" name="uploadfile">';
202 $texte .=
'<input type="hidden" value="USER_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
203 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
210 $texte .=
'</table>';
228 public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
231 global $user, $langs, $conf, $mysoc, $hookmanager;
233 if (empty($srctemplatepath)) {
234 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
239 if (!is_object($hookmanager)) {
240 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
243 $hookmanager->initHooks(array(
'odtgeneration'));
246 if (!is_object($outputlangs)) {
247 $outputlangs = $langs;
249 $sav_charset_output = $outputlangs->charset_output;
250 $outputlangs->charset_output =
'UTF-8';
253 $outputlangs->loadLangs(array(
"main",
"companies",
"bills",
"dict"));
255 if ($conf->user->dir_output) {
257 if (!is_object($object)) {
259 $object =
new User($this->db);
260 $result = $object->fetch($id);
267 $object->fetch_thirdparty();
269 $dir = $conf->user->dir_output;
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)) {
326 if ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
327 $socobject = $object->contact;
329 $socobject = $object->thirdparty;
331 $contactobject = $object->contact;
334 $socobject = $object->thirdparty;
338 require_once ODTPHP_PATH.
'odf.php';
340 $odfHandler =
new Odf(
343 'PATH_TO_TMP' => $conf->user->dir_temp,
345 'DELIMITER_LEFT' =>
'{',
346 'DELIMITER_RIGHT' =>
'}'
350 $this->error = $e->getMessage();
361 $array_thirdparty_contact = array();
362 if ($usecontact && is_object($contactobject)) {
366 $tmparray = array_merge($array_user, $array_soc, $array_thirdparty, $array_other, $array_thirdparty_contact);
368 $object->fetch_optionals();
370 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
371 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
372 foreach ($tmparray as $key => $value) {
374 if (preg_match(
'/logo$/', $key)) {
375 if (file_exists($value)) {
376 $odfHandler->setImage($key, $value);
378 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
381 $odfHandler->setVars($key, $value,
true,
'UTF-8');
383 }
catch (OdfException $e) {
389 $tmparray = $outputlangs->get_translations_for_substitutions();
390 foreach ($tmparray as $key => $value) {
392 $odfHandler->setVars($key, $value,
true,
'UTF-8');
393 }
catch (OdfException $e) {
399 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
400 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
405 $odfHandler->exportAsAttachedPDF($file);
407 $this->error = $e->getMessage();
413 $odfHandler->saveToDisk($file);
415 $this->error = $e->getMessage();
421 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
427 $this->result = array(
'fullpath'=>$file);
431 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);