55 public $phpmin = array(7, 0);
60 public $version =
'dolibarr';
73 $langs->loadLangs(array(
"main",
"companies"));
76 $this->
name =
"ODT templates";
77 $this->
description = $langs->trans(
"DocumentModelOdt");
78 $this->scandir =
'RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH';
82 $this->page_largeur = 0;
83 $this->page_hauteur = 0;
84 $this->format = array($this->page_largeur, $this->page_hauteur);
85 $this->marge_gauche = 0;
86 $this->marge_droite = 0;
87 $this->marge_haute = 0;
88 $this->marge_basse = 0;
90 $this->option_logo = 1;
91 $this->option_tva = 0;
92 $this->option_modereg = 0;
93 $this->option_condreg = 0;
94 $this->option_multilang = 1;
95 $this->option_escompte = 0;
96 $this->option_credit_note = 0;
97 $this->option_freetext = 1;
98 $this->option_draft_watermark = 0;
107 if (!$this->emetteur->country_code) {
108 $this->emetteur->country_code = substr($langs->defaultlang, -2);
121 global
$conf, $langs;
124 $langs->loadLangs(array(
"errors",
"companies"));
126 $form =
new Form($this->db);
129 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" enctype="multipart/form-data">';
130 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
131 $texte .=
'<input type="hidden" name="page_y" value="">';
132 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
133 $texte .=
'<input type="hidden" name="param1" value="RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH">';
134 $texte .=
'<table class="nobordernopadding centpercent">';
137 $texte .=
'<tr><td>';
138 $texttitle = $langs->trans(
"ListOfDirectories");
139 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim(
getDolGlobalString(
'RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH'))));
140 $listoffiles = array();
141 foreach ($listofdir as $key => $tmpdir) {
142 $tmpdir = trim($tmpdir);
143 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
145 unset($listofdir[$key]);
148 if (!is_dir($tmpdir)) {
149 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir),
'');
151 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
152 if (count($tmpfiles)) {
153 $listoffiles = array_merge($listoffiles, $tmpfiles);
157 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
158 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
160 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
161 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
164 $nbofiles = count($listoffiles);
166 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
168 $texte .= count($listoffiles);
174 $texte .=
'<div id="div_'.get_class($this).
'" class="hidden">';
175 foreach ($listoffiles as $file) {
176 $texte .=
'- '.$file[
'name'];
184 $texte .=
'<br><br>';
185 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1);
186 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
187 $texte .=
'<textarea class="flat textareafordir" spellcheck="false" cols="60" name="value1">';
188 $texte .=
getDolGlobalString(
'RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH');
189 $texte .=
'</textarea>';
190 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
191 $texte .=
'<input type="submit" class="button button-edit smallpaddingimp reposition" name="modify" value="'.$langs->trans(
"Modify").
'">';
192 $texte .=
'<br></div></div>';
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="RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
203 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
209 $texte .=
'</table>';
227 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
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';
252 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills"));
269 if (!preg_match(
'/specimen/i', $objectref)) {
270 $dir .=
"/".$objectref;
272 $file = $dir.
"/".$objectref.
".odt";
274 if (!file_exists($dir)) {
276 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
281 if (file_exists($dir)) {
283 $newfile = basename($srctemplatepath);
284 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
285 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
286 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
287 $newfiletmp = $objectref.
'_'.$newfiletmp;
290 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
293 if ($format ==
'1') {
294 $format =
'%Y%m%d%H%M%S';
298 $filename = $newfiletmp.
'.'.$newfileformat;
300 $file = $dir.
'/'.$filename;
307 if (!is_writable(
$conf->recruitment->dir_temp)) {
308 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory",
$conf->recruitment->dir_temp);
309 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
315 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
316 if (count($arrayidcontact) > 0) {
318 $result =
$object->fetch_contact($arrayidcontact[0]);
322 $contactobject =
null;
323 if (!empty($usecontact)) {
326 $object->contact->fetch_thirdparty();
327 $socobject =
$object->contact->thirdparty;
328 $contactobject =
$object->contact;
330 $socobject =
$object->thirdparty;
332 $contactobject =
$object->contact;
335 $socobject =
$object->thirdparty;
339 $substitutionarray = array(
340 '__FROM_NAME__' => $this->emetteur->name,
341 '__FROM_EMAIL__' => $this->emetteur->email,
342 '__TOTAL_TTC__' =>
$object->total_ttc,
343 '__TOTAL_HT__' =>
$object->total_ht,
344 '__TOTAL_VAT__' =>
$object->total_tva
348 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$substitutionarray);
349 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
353 $paramfreetext =
'ORDER_FREE_TEXT';
359 require_once ODTPHP_PATH.
'odf.php';
361 $odfHandler =
new Odf(
364 'PATH_TO_TMP' =>
$conf->recruitment->dir_temp,
366 'DELIMITER_LEFT' =>
'{',
367 'DELIMITER_RIGHT' =>
'}'
371 $this->error = $e->getMessage();
384 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
385 }
catch (OdfException $e) {
390 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null,
$object);
392 $array_objet = $this->get_substitutionarray_object(
$object, $outputlangs);
398 $array_thirdparty_contact = array();
399 if ($usecontact && is_object($contactobject)) {
403 $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
407 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
408 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
417 foreach ($tmparray as $key => $value) {
419 if (preg_match(
'/logo$/', $key)) {
421 if (file_exists($value)) {
422 $odfHandler->setImage($key, $value, $ratio);
424 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
428 $odfHandler->setVars($key, $value,
true,
'UTF-8');
430 }
catch (OdfException $e) {
435 $foundtagforlines = 1;
437 $listlines = $odfHandler->setSegment(
'lines');
438 }
catch (OdfExceptionSegmentNotFound $e) {
440 $foundtagforlines = 0;
443 if ($foundtagforlines) {
445 foreach (
$object->lines as $line) {
451 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray,
'line' => $line);
452 $reshook = $hookmanager->executeHooks(
'ODTSubstitutionLine', $parameters, $this, $action);
453 foreach ($tmparray as $key => $val) {
455 $listlines->setVars($key, $val,
true,
'UTF-8');
456 }
catch (SegmentException $e) {
463 $odfHandler->mergeSegment($listlines);
464 }
catch (OdfException $e) {
465 $this->error = $e->getMessage();
472 $tmparray = $outputlangs->get_translations_for_substitutions();
473 foreach ($tmparray as $key => $value) {
475 $odfHandler->setVars($key, $value,
true,
'UTF-8');
476 }
catch (OdfException $e) {
483 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
484 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
489 $odfHandler->exportAsAttachedPDF($file);
491 $this->error = $e->getMessage();
497 $odfHandler->saveToDisk($file);
499 $this->error = $e->getMessage();
505 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
506 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
512 $this->result = array(
'fullpath' => $file);
516 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);