93 public function info($langs)
98 $langs->loadLangs(array(
'companies',
'errors'));
100 $form =
new Form($this->db);
103 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" enctype="multipart/form-data">';
104 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
105 $texte .=
'<input type="hidden" name="page_y" value="">';
106 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
107 $texte .=
'<input type="hidden" name="param1" value="TICKET_ADDON_PDF_ODT_PATH">';
109 $texte .=
'<table class="nobordernopadding" width="100%">';
112 $texte .=
'<tr><td>';
113 $texttitle = $langs->trans(
"ListOfDirectories");
114 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim(
getDolGlobalString(
'TICKET_ADDON_PDF_ODT_PATH'))));
115 $listoffiles = array();
116 foreach ($listofdir as $key => $tmpdir) {
117 $tmpdir = trim($tmpdir);
118 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
120 unset($listofdir[$key]);
123 if (!is_dir($tmpdir)) {
124 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir), 0);
126 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
127 if (count($tmpfiles)) {
128 $listoffiles = array_merge($listoffiles, $tmpfiles);
132 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
133 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
135 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
136 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
138 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
139 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
140 $texte .=
'<textarea class="flat" cols="60" name="value1">';
142 $texte .=
'</textarea>';
143 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
144 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dol_escape_htmltag($langs->trans(
"Modify")).
'">';
145 $texte .=
'<br></div></div>';
148 if (count($listofdir)) {
149 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>'.count($listoffiles).
'</b>';
151 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
153 foreach ($listoffiles as $file) {
154 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=tickets/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
155 $texte .=
' <a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?modulepart=doctemplates&keyforuploaddir=TICKET_ADDON_PDF_ODT_PATH&action=deletefile&token='.newToken().
'&file='.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'delete').
'</a>';
161 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
163 $maxmin = $maxfilesizearray[
'maxmin'];
165 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
167 $texte .=
' <input type="file" name="uploadfile">';
168 $texte .=
'<input type="hidden" value="TICKET_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
169 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
176 $texte .=
'</table>';
194 public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
197 global $user, $langs, $conf, $mysoc, $hookmanager;
199 if (empty($srctemplatepath)) {
200 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
205 if (!is_object($hookmanager)) {
206 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
209 $hookmanager->initHooks(array(
'odtgeneration'));
212 if (!is_object($outputlangs)) {
213 $outputlangs = $langs;
215 $sav_charset_output = $outputlangs->charset_output;
216 $outputlangs->charset_output =
'UTF-8';
219 $outputlangs->loadLangs(array(
"main",
"companies",
"bills",
"dict"));
221 if ($conf->ticket->dir_output) {
223 if (!is_object($object)) {
225 $object =
new User($this->db);
226 $result = $object->fetch($id);
233 $object->fetch_thirdparty();
235 $dir = $conf->ticket->dir_output;
237 if (!preg_match(
'/specimen/i', $objectref)) {
238 $dir .=
"/".$objectref;
240 $file = $dir.
"/".$objectref.
".odt";
242 if (!file_exists($dir)) {
244 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
249 if (file_exists($dir)) {
251 $newfile = basename($srctemplatepath);
252 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
253 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
254 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
256 $newfiletmp = $objectref .
'_' . $newfiletmp;
259 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
262 if ($format ==
'1') {
263 $format =
'%Y%m%d%H%M%S';
267 $filename = $newfiletmp .
'.' . $newfileformat;
269 $file = $dir .
'/' . $filename;
276 if (!is_writable($conf->ticket->dir_temp)) {
277 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->ticket->dir_temp);
278 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
284 $arrayidcontact = $object->getIdContact(
'external',
'CUSTOMER');
285 if (count($arrayidcontact) > 0) {
287 $result = $object->fetch_contact($arrayidcontact[0]);
291 if (!empty($usecontact)) {
293 if ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
294 $object->contact->fetch_thirdparty();
295 $socobject = $object->contact->thirdparty;
296 $contactobject = $object->contact;
298 $socobject = $object->thirdparty;
300 $contactobject = $object->contact;
303 $socobject = $object->thirdparty;
307 require_once ODTPHP_PATH.
'odf.php';
309 $odfHandler =
new Odf(
312 'PATH_TO_TMP' => $conf->ticket->dir_temp,
314 'DELIMITER_LEFT' =>
'{',
315 'DELIMITER_RIGHT' =>
'}'
319 $this->error = $e->getMessage();
330 $array_thirdparty_contact = array();
331 if ($usecontact && is_object($contactobject)) {
335 $tmparray = array_merge($array_user, $array_soc, $array_thirdparty, $array_other, $array_thirdparty_contact);
337 $object->fetch_optionals();
339 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
340 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
341 foreach ($tmparray as $key => $value) {
343 if (preg_match(
'/logo$/', $key)) {
344 if (file_exists($value)) {
345 $odfHandler->setImage($key, $value);
347 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
350 $odfHandler->setVars($key, $value,
true,
'UTF-8');
352 }
catch (OdfException $e) {
358 $tmparray = $outputlangs->get_translations_for_substitutions();
359 foreach ($tmparray as $key => $value) {
361 $odfHandler->setVars($key, $value,
true,
'UTF-8');
362 }
catch (OdfException $e) {
368 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
369 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
374 $odfHandler->exportAsAttachedPDF($file);
376 $this->error = $e->getMessage();
382 $odfHandler->saveToDisk($file);
384 $this->error = $e->getMessage();
390 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
396 $this->result = array(
'fullpath'=>$file);
400 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);