55 public $phpmin = array(7, 0);
60 public $version =
'dolibarr';
70 global
$conf, $langs, $mysoc;
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;
100 if ($mysoc ===
null) {
106 $this->emetteur = $mysoc;
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)
230 global $user, $langs,
$conf, $mysoc, $hookmanager;
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"));
254 if (
$conf->recruitment->dir_output) {
266 $dir =
$conf->recruitment->multidir_output[isset(
$object->entity) ?
$object->entity : 1].
'/recruitmentjobposition/';
268 if (!preg_match(
'/specimen/i', $objectref)) {
269 $dir .=
"/".$objectref;
271 $file = $dir.
"/".$objectref.
".odt";
273 if (!file_exists($dir)) {
275 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
280 if (file_exists($dir)) {
282 $newfile = basename($srctemplatepath);
283 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
284 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
285 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
286 $newfiletmp = $objectref.
'_'.$newfiletmp;
289 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
292 if ($format ==
'1') {
293 $format =
'%Y%m%d%H%M%S';
297 $filename = $newfiletmp.
'.'.$newfileformat;
299 $file = $dir.
'/'.$filename;
306 if (!is_writable(
$conf->recruitment->dir_temp)) {
307 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory",
$conf->recruitment->dir_temp);
308 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
314 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
315 if (count($arrayidcontact) > 0) {
317 $result =
$object->fetch_contact($arrayidcontact[0]);
321 $contactobject =
null;
322 if (!empty($usecontact)) {
325 $object->contact->fetch_thirdparty();
326 $socobject =
$object->contact->thirdparty;
327 $contactobject =
$object->contact;
329 $socobject =
$object->thirdparty;
331 $contactobject =
$object->contact;
334 $socobject =
$object->thirdparty;
338 $substitutionarray = array(
339 '__FROM_NAME__' => $this->emetteur->name,
340 '__FROM_EMAIL__' => $this->emetteur->email,
341 '__TOTAL_TTC__' =>
$object->total_ttc,
342 '__TOTAL_HT__' =>
$object->total_ht,
343 '__TOTAL_VAT__' =>
$object->total_tva
347 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$substitutionarray);
348 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
352 $paramfreetext =
'ORDER_FREE_TEXT';
358 require_once ODTPHP_PATH.
'odf.php';
360 $odfHandler =
new Odf(
363 'PATH_TO_TMP' =>
$conf->recruitment->dir_temp,
365 'DELIMITER_LEFT' =>
'{',
366 'DELIMITER_RIGHT' =>
'}'
370 $this->error = $e->getMessage();
383 $odfHandler->setVars(
'free_text', $newfreetext,
true,
'UTF-8');
384 }
catch (OdfException $e) {
389 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null,
$object);
391 $array_objet = $this->get_substitutionarray_object(
$object, $outputlangs);
397 $array_thirdparty_contact = array();
398 if ($usecontact && is_object($contactobject)) {
402 $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
406 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
407 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
416 foreach ($tmparray as $key => $value) {
418 if (preg_match(
'/logo$/', $key)) {
420 if (file_exists($value)) {
421 $odfHandler->setImage($key, $value, $ratio);
423 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
427 $odfHandler->setVars($key, $value,
true,
'UTF-8');
429 }
catch (OdfException $e) {
434 $foundtagforlines = 1;
436 $listlines = $odfHandler->setSegment(
'lines');
437 }
catch (OdfExceptionSegmentNotFound $e) {
439 $foundtagforlines = 0;
442 if ($foundtagforlines) {
444 foreach (
$object->lines as $line) {
450 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray,
'line' => $line);
451 $reshook = $hookmanager->executeHooks(
'ODTSubstitutionLine', $parameters, $this, $action);
452 foreach ($tmparray as $key => $val) {
454 $listlines->setVars($key, $val,
true,
'UTF-8');
455 }
catch (SegmentException $e) {
462 $odfHandler->mergeSegment($listlines);
463 }
catch (OdfException $e) {
464 $this->error = $e->getMessage();
471 $tmparray = $outputlangs->get_translations_for_substitutions();
472 foreach ($tmparray as $key => $value) {
474 $odfHandler->setVars($key, $value,
true,
'UTF-8');
475 }
catch (OdfException $e) {
482 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
483 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
488 $odfHandler->exportAsAttachedPDF($file);
490 $this->error = $e->getMessage();
496 $odfHandler->saveToDisk($file);
498 $this->error = $e->getMessage();
504 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
505 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
511 $this->result = array(
'fullpath' => $file);
515 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);