103 global
$conf, $langs;
105 $langs->load(
"companies");
106 $langs->load(
"errors");
108 $form =
new Form($this->db);
111 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
112 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
113 $texte .=
'<input type="hidden" name="page_y" value="">';
114 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
115 $texte .=
'<input type="hidden" name="param1" value="RECEPTION_ADDON_PDF_ODT_PATH">';
116 $texte .=
'<table class="nobordernopadding centpercent">';
119 $texte .=
'<tr><td>';
120 $texttitle = $langs->trans(
"ListOfDirectories");
121 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim(
$conf->global->RECEPTION_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" 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="'.$langs->trans(
"Modify").
'">';
152 $texte .=
'<br></div></div>';
155 $nbofiles = count($listoffiles);
157 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
159 $texte .= count($listoffiles);
164 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
166 foreach ($listoffiles as $file) {
167 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=receptions/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
168 $texte .=
' <a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?modulepart=doctemplates&keyforuploaddir=RECEPTION_ADDON_PDF_ODT_PATH&action=deletefile&token='.
newToken().
'&file='.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'delete').
'</a>';
174 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
176 $maxmin = $maxfilesizearray[
'maxmin'];
178 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
180 $texte .=
' <input type="file" name="uploadfile">';
181 $texte .=
'<input type="hidden" value="RECEPTION_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
182 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
189 $texte .=
'</table>';
207 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
210 global $user, $langs,
$conf, $mysoc, $hookmanager;
212 if (empty($srctemplatepath)) {
213 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
218 if (!is_object($hookmanager)) {
219 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
222 $hookmanager->initHooks(array(
'odtgeneration'));
225 if (!is_object($outputlangs)) {
226 $outputlangs = $langs;
228 $sav_charset_output = $outputlangs->charset_output;
229 $outputlangs->charset_output =
'UTF-8';
231 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills"));
233 if (
$conf->reception->dir_output) {
247 $dir = !empty(
$conf->reception->multidir_output[
$object->entity]) ?
$conf->reception->multidir_output[
$object->entity] :
$conf->reception->dir_output;
249 if (!preg_match(
'/specimen/i', $objectref)) {
250 $dir .=
"/".$objectref;
252 $file = $dir.
"/".$objectref.
".odt";
254 if (!file_exists($dir)) {
256 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
261 if (file_exists($dir)) {
263 $newfile = basename($srctemplatepath);
264 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
265 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
266 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
267 $newfiletmp = $objectref .
'_' . $newfiletmp;
270 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
273 if ($format ==
'1') {
274 $format =
'%Y%m%d%H%M%S';
278 $filename = $newfiletmp .
'.' . $newfileformat;
280 $file = $dir .
'/' . $filename;
287 if (!is_writable(
$conf->reception->dir_temp)) {
288 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory",
$conf->reception->dir_temp);
289 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
295 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
296 if (count($arrayidcontact) > 0) {
298 $result =
$object->fetch_contact($arrayidcontact[0]);
302 $contactobject =
null;
303 if (!empty($usecontact)) {
306 $object->contact->fetch_thirdparty();
307 $socobject =
$object->contact->thirdparty;
308 $contactobject =
$object->contact;
310 $socobject =
$object->thirdparty;
312 $contactobject =
$object->contact;
315 $socobject =
$object->thirdparty;
319 $substitutionarray = array(
320 '__FROM_NAME__' => $this->emetteur->name,
321 '__FROM_EMAIL__' => $this->emetteur->email,
322 '__TOTAL_TTC__' =>
$object->total_ttc,
323 '__TOTAL_HT__' =>
$object->total_ht,
324 '__TOTAL_VAT__' =>
$object->total_tva
329 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$substitutionarray);
330 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
334 $paramfreetext =
'RECEPTION_FREE_TEXT';
340 require_once ODTPHP_PATH.
'odf.php';
342 $odfHandler =
new Odf(
345 'PATH_TO_TMP' =>
$conf->reception->dir_temp,
347 'DELIMITER_LEFT' =>
'{',
348 'DELIMITER_RIGHT' =>
'}'
352 $this->error = $e->getMessage();
363 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
364 }
catch (OdfException $e) {
371 $array_objet = $this->get_substitutionarray_object(
$object, $outputlangs);
377 $array_thirdparty_contact = array();
378 if ($usecontact && is_object($contactobject)) {
382 $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
386 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
387 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
388 foreach ($tmparray as $key => $value) {
390 if (preg_match(
'/logo$/', $key)) {
391 if (file_exists($value)) {
392 $odfHandler->setImage($key, $value);
394 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
397 $odfHandler->setVars($key, $value,
true,
'UTF-8');
399 }
catch (OdfException $e) {
404 $foundtagforlines = 1;
406 $listlines = $odfHandler->setSegment(
'lines');
407 }
catch (OdfExceptionSegmentNotFound $e) {
409 $foundtagforlines = 0;
412 if ($foundtagforlines) {
414 foreach (
$object->lines as $line) {
419 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray,
'line' => $line);
420 $reshook = $hookmanager->executeHooks(
'ODTSubstitutionLine', $parameters, $this, $action);
421 foreach ($tmparray as $key => $val) {
423 $listlines->setVars($key, $val,
true,
'UTF-8');
424 }
catch (SegmentException $e) {
431 $odfHandler->mergeSegment($listlines);
432 }
catch (OdfException $e) {
433 $this->error = $e->getMessage();
440 $tmparray = $outputlangs->get_translations_for_substitutions();
441 foreach ($tmparray as $key => $value) {
443 $odfHandler->setVars($key, $value,
true,
'UTF-8');
444 }
catch (OdfException $e) {
450 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
451 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
456 $odfHandler->exportAsAttachedPDF($file);
458 $this->error = $e->getMessage();
464 $odfHandler->saveToDisk($file);
466 $this->error = $e->getMessage();
471 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
472 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
478 $this->result = array(
'fullpath' => $file);
482 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);