94 public function info($langs)
99 $langs->loadLangs(array(
'companies',
'errors'));
101 $form =
new Form($this->db);
104 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" enctype="multipart/form-data">';
105 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
106 $texte .=
'<input type="hidden" name="page_y" value="">';
107 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
108 $texte .=
'<input type="hidden" name="param1" value="TICKET_ADDON_PDF_ODT_PATH">';
110 $texte .=
'<table class="nobordernopadding" width="100%">';
113 $texte .=
'<tr><td>';
114 $texttitle = $langs->trans(
"ListOfDirectories");
115 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim(
getDolGlobalString(
'TICKET_ADDON_PDF_ODT_PATH'))));
116 $listoffiles = array();
117 foreach ($listofdir as $key => $tmpdir) {
118 $tmpdir = trim($tmpdir);
119 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
121 unset($listofdir[$key]);
124 if (!is_dir($tmpdir)) {
125 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir), 0);
127 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
128 if (count($tmpfiles)) {
129 $listoffiles = array_merge($listoffiles, $tmpfiles);
133 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
134 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
136 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
137 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
139 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
140 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
141 $texte .=
'<textarea class="flat" cols="60" name="value1">';
143 $texte .=
'</textarea>';
144 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
145 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dol_escape_htmltag($langs->trans(
"Modify")).
'">';
146 $texte .=
'<br></div></div>';
149 if (count($listofdir)) {
150 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>'.count($listoffiles).
'</b>';
152 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
154 foreach ($listoffiles as $file) {
155 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=tickets/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
156 $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>';
162 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
164 $maxmin = $maxfilesizearray[
'maxmin'];
166 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
168 $texte .=
' <input type="file" name="uploadfile">';
169 $texte .=
'<input type="hidden" value="TICKET_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
170 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
177 $texte .=
'</table>';
195 public function write_file(
$object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
198 global $user, $langs, $conf, $mysoc, $hookmanager;
200 if (empty($srctemplatepath)) {
201 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
206 if (!is_object($hookmanager)) {
207 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
210 $hookmanager->initHooks(array(
'odtgeneration'));
213 if (!is_object($outputlangs)) {
214 $outputlangs = $langs;
216 $sav_charset_output = $outputlangs->charset_output;
217 $outputlangs->charset_output =
'UTF-8';
220 $outputlangs->loadLangs(array(
"main",
"companies",
"bills",
"dict"));
222 if ($conf->ticket->dir_output) {
236 $dir = $conf->ticket->dir_output;
238 if (!preg_match(
'/specimen/i', $objectref)) {
239 $dir .=
"/".$objectref;
241 $file = $dir.
"/".$objectref.
".odt";
243 if (!file_exists($dir)) {
245 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
250 if (file_exists($dir)) {
252 $newfile = basename($srctemplatepath);
253 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
254 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
255 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
257 $newfiletmp = $objectref .
'_' . $newfiletmp;
260 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
263 if ($format ==
'1') {
264 $format =
'%Y%m%d%H%M%S';
268 $filename = $newfiletmp .
'.' . $newfileformat;
270 $file = $dir .
'/' . $filename;
277 if (!is_writable($conf->ticket->dir_temp)) {
278 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->ticket->dir_temp);
279 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
285 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
286 if (count($arrayidcontact) > 0) {
288 $result =
$object->fetch_contact($arrayidcontact[0]);
292 if (!empty($usecontact)) {
294 if (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
295 $object->contact->fetch_thirdparty();
296 $socobject =
$object->contact->thirdparty;
297 $contactobject =
$object->contact;
299 $socobject =
$object->thirdparty;
301 $contactobject =
$object->contact;
304 $socobject =
$object->thirdparty;
308 require_once ODTPHP_PATH.
'odf.php';
310 $odfHandler =
new Odf(
313 'PATH_TO_TMP' => $conf->ticket->dir_temp,
315 'DELIMITER_LEFT' =>
'{',
316 'DELIMITER_RIGHT' =>
'}'
320 $this->error = $e->getMessage();
331 $array_thirdparty_contact = array();
332 if ($usecontact && is_object($contactobject)) {
336 $tmparray = array_merge($array_user, $array_soc, $array_thirdparty, $array_other, $array_thirdparty_contact);
340 $parameters = array(
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
341 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
342 foreach ($tmparray as $key => $value) {
344 if (preg_match(
'/logo$/', $key)) {
345 if (file_exists($value)) {
346 $odfHandler->setImage($key, $value);
348 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
351 $odfHandler->setVars($key, $value,
true,
'UTF-8');
353 }
catch (OdfException $e) {
359 $tmparray = $outputlangs->get_translations_for_substitutions();
360 foreach ($tmparray as $key => $value) {
362 $odfHandler->setVars($key, $value,
true,
'UTF-8');
363 }
catch (OdfException $e) {
369 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>
$object,
'outputlangs'=>$outputlangs);
370 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
375 $odfHandler->exportAsAttachedPDF($file);
377 $this->error = $e->getMessage();
383 $odfHandler->saveToDisk($file);
385 $this->error = $e->getMessage();
391 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
397 $this->result = array(
'fullpath'=>$file);
401 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);