105 $langs->loadLangs(array(
'companies',
'errors'));
107 $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="TICKET_ADDON_PDF_ODT_PATH">';
116 $texte .=
'<table class="nobordernopadding" width="100%">';
119 $texte .=
'<tr><td>';
120 $texttitle = $langs->trans(
"ListOfDirectories");
121 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim(
getDolGlobalString(
'TICKET_ADDON_PDF_ODT_PATH'))));
122 $listoffiles = array();
123 foreach ($listofdir as $key => $tmpdir) {
124 $tmpdir = trim($tmpdir);
125 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
127 unset($listofdir[$key]);
130 if (!is_dir($tmpdir)) {
131 $texttitle .= img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir),
'');
133 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
134 if (count($tmpfiles)) {
135 $listoffiles = array_merge($listoffiles, $tmpfiles);
139 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
140 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
142 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
143 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
145 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
146 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
147 $texte .=
'<textarea class="flat textareafordir" spellcheck="false" cols="60" name="value1">';
149 $texte .=
'</textarea>';
150 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
151 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dol_escape_htmltag($langs->trans(
"Modify")).
'">';
152 $texte .=
'<br></div></div>';
155 if (count($listofdir)) {
156 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>'.count($listoffiles).
'</b>';
158 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
160 foreach ($listoffiles as $file) {
161 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=tickets/'.urlencode(basename($file[
'name'])).
'">'.img_picto(
'',
'listlight').
'</a>';
162 $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>';
168 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
170 $maxmin = $maxfilesizearray[
'maxmin'];
172 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
174 $texte .=
' <input type="file" name="uploadfile">';
175 $texte .=
'<input type="hidden" value="TICKET_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
176 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
183 $texte .=
'</table>';
201 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
206 if (empty($srctemplatepath)) {
207 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
212 if (!is_object($hookmanager)) {
213 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
216 $hookmanager->initHooks(array(
'odtgeneration'));
219 if (!is_object($outputlangs)) {
220 $outputlangs = $langs;
222 $sav_charset_output = $outputlangs->charset_output;
223 $outputlangs->charset_output =
'UTF-8';
226 $outputlangs->loadLangs(array(
"main",
"companies",
"bills",
"dict"));
228 if (
$conf->ticket->dir_output) {
235 dol_print_error($this->db,
$object->error);
242 $dir =
$conf->ticket->dir_output;
244 if (!preg_match(
'/specimen/i', $objectref)) {
245 $dir .=
"/".$objectref;
247 $file = $dir.
"/".$objectref.
".odt";
249 if (!file_exists($dir)) {
251 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
256 if (file_exists($dir)) {
258 $newfile = basename($srctemplatepath);
259 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
260 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
261 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
263 $newfiletmp = $objectref .
'_' . $newfiletmp;
266 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
269 if ($format ==
'1') {
270 $format =
'%Y%m%d%H%M%S';
274 $filename = $newfiletmp .
'.' . $newfileformat;
276 $file = $dir .
'/' . $filename;
283 if (!is_writable(
$conf->ticket->dir_temp)) {
284 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory",
$conf->ticket->dir_temp);
285 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
291 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
292 if (count($arrayidcontact) > 0) {
294 $result =
$object->fetch_contact($arrayidcontact[0]);
297 $contactobject =
null;
299 if (!empty($usecontact)) {
302 $object->contact->fetch_thirdparty();
303 $socobject =
$object->contact->thirdparty;
304 $contactobject =
$object->contact;
306 $socobject =
$object->thirdparty;
308 $contactobject =
$object->contact;
311 $socobject =
$object->thirdparty;
315 require_once ODTPHP_PATH.
'odf.php';
317 $odfHandler =
new Odf(
320 'PATH_TO_TMP' =>
$conf->ticket->dir_temp,
322 'DELIMITER_LEFT' =>
'{',
323 'DELIMITER_RIGHT' =>
'}'
327 $this->error = $e->getMessage();
338 $array_thirdparty_contact = array();
339 if ($usecontact && is_object($contactobject)) {
343 $tmparray = array_merge($array_user, $array_soc, $array_thirdparty, $array_other, $array_thirdparty_contact);
347 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
348 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
357 foreach ($tmparray as $key => $value) {
359 if (preg_match(
'/logo$/', $key)) {
360 if (file_exists($value)) {
361 $odfHandler->setImage($key, $value, $ratio);
363 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
366 $odfHandler->setVars($key, $value,
true,
'UTF-8');
368 }
catch (OdfException $e) {
374 $tmparray = $outputlangs->get_translations_for_substitutions();
375 foreach ($tmparray as $key => $value) {
377 $odfHandler->setVars($key, $value,
true,
'UTF-8');
378 }
catch (OdfException $e) {
384 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
385 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
390 $odfHandler->exportAsAttachedPDF($file);
392 $this->error = $e->getMessage();
398 $odfHandler->saveToDisk($file);
400 $this->error = $e->getMessage();
406 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
412 $this->result = array(
'fullpath' => $file);
416 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);