31require_once DOL_DOCUMENT_ROOT.
'/recruitment/core/modules/recruitment/modules_recruitmentjobposition.php';
32require_once DOL_DOCUMENT_ROOT.
'/recruitment/class/recruitmentjobposition.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/lib/doc.lib.php';
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 .=
'<span class="opacitylow">'.$langs->trans(
"NumberOfModelFilesFound").
': <b>';
168 $texte .= count($listoffiles);
170 $texte .=
'</b></span>';
174 $texte .=
'<div id="div_'.get_class($this).
'" class="hidden opacitylow">';
175 foreach ($listoffiles as $file) {
176 $texte .=
'- '.$file[
'name'];
184 $texte .=
'<br><br>';
186 $texte .=
'<span class="classlink cursorpointer" onclick="javascript: jQuery(\'.div_odtmodelsof'.get_class($this).
'\').toggle();
">'.img_picto('', 'add').' '.$langs->trans("UploadNewTemplate
").'...</span>';
187 $texte .= '<div class="div_odtmodelsof
'.get_class($this).'" style="display: none; margin-top: 6px;
">';
188 $texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1);
189 $texte .= '<div><div style="display:
inline-block; min-width: 100px; vertical-align: middle;
">';
190 $texte .= '<textarea class="flat textareafordir
" spellcheck="false" cols="60
" name="value1
">';
191 $texte .= getDolGlobalString('RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH');
192 $texte .= '</textarea>';
193 $texte .= '</div><div style="display:
inline-block; vertical-align: middle;
">';
194 $texte .= '<input type="submit
" class="button button-edit smallpaddingimp reposition
" name="modify
" value="'.$langs->trans("Modify").'">';
195 $texte .= '<br></div></div>';
197 // Add input to upload a new template file.
199 $maxfilesizearray = getMaxFileSizeArray();
200 $maxmin = $maxfilesizearray['maxmin'];
202 $texte .= '<input type="hidden
" name="MAX_FILE_SIZE
" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
204 $texte .= ' <input type="file
" name="uploadfile
">';
205 $texte .= '<input type="hidden
" value="RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH
" name="keyforuploaddir
">';
206 $texte .= '<input type="submit
" class="button smallpaddingimp reposition
" value="'.dol_escape_htmltag($langs->trans("Upload")).'" name="upload
">';
213 $texte .= '</table>';
219 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
231 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
234 global $user, $langs, $conf, $mysoc, $hookmanager;
237 if (empty($srctemplatepath)) {
242 // Add odtgeneration hook
243 if (!is_object($hookmanager)) {
244 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
245 $hookmanager = new HookManager($this->db);
247 $hookmanager->initHooks(array('odtgeneration'));
250 if (!is_object($outputlangs)) {
251 $outputlangs = $langs;
253 $sav_charset_output = $outputlangs->charset_output;
254 $outputlangs->charset_output = 'UTF-8';
256 $outputlangs->loadLangs(array("main
", "dict
", "companies
", "bills
"));
258 $dir = getMultidirOutput($object);
261 // If $object is id instead of object
262 if (!is_object($object)) {
264 $object = new RecruitmentJobPosition($this->db);
265 $result = $object->fetch($id);
267 dol_print_error($this->db, $object->error);
272 $objectref = dol_sanitizeFileName((string) $object->ref);
273 if (!preg_match('/specimen/i', $objectref)) {
274 $dir .= "/
".$objectref;
276 $file = $dir."/
".$objectref.".odt
";
278 if (!file_exists($dir)) {
279 if (dol_mkdir($dir) < 0) {
280 $this->error = $langs->transnoentities("ErrorCanNotCreateDir
", $dir);
285 if (file_exists($dir)) {
286 //print "srctemplatepath=
".$srctemplatepath; // Src filename
287 $newfile = basename($srctemplatepath);
288 $newfiletmp = preg_replace('/\.od[ts]/i', '', $newfile);
289 $newfiletmp = preg_replace('/template_/i', '', $newfiletmp);
290 $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp);
291 $newfiletmp = $objectref.'_'.$newfiletmp;
292 //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
293 // Get extension (ods or odt)
294 $newfileformat = substr($newfile, strrpos($newfile, '.') + 1);
295 if (getDolGlobalString('MAIN_DOC_USE_TIMING')) {
296 $format = getDolGlobalString('MAIN_DOC_USE_TIMING');
297 if ($format == '1') {
298 $format = '%Y%m%d%H%M%S';
300 $filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat;
302 $filename = $newfiletmp.'.'.$newfileformat;
304 $file = $dir.'/'.$filename;
305 //print "newdir=
".$dir;
306 //print "newfile=
".$newfile;
307 //print "file=
".$file;
308 //print "conf->societe->dir_temp=
".$conf->societe->dir_temp;
310 dol_mkdir($conf->recruitment->dir_temp);
311 if (!is_writable($conf->recruitment->dir_temp)) {
312 $this->error = $langs->transnoentities("ErrorFailedToWriteInTempDirectory
", $conf->recruitment->dir_temp);
313 dol_syslog('Error in write_file: ' . $this->error, LOG_ERR);
317 // If CUSTOMER contact defined on order, we use it
319 $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
320 if (count($arrayidcontact) > 0) {
322 $result = $object->fetch_contact($arrayidcontact[0]);
326 $contactobject = null;
327 if (!empty($usecontact)) {
328 // We can use the company of contact instead of thirdparty company
329 if ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
330 $object->contact->fetch_thirdparty();
331 $socobject = $object->contact->thirdparty;
332 $contactobject = $object->contact;
334 $socobject = $object->thirdparty;
335 // if we have a CUSTOMER contact and we don't use it as thirdparty recipient we store the contact object for later use
336 $contactobject = $object->contact;
339 $socobject = $object->thirdparty;
343 $substitutionarray = array(
344 '__FROM_NAME__' => $this->emetteur->name,
345 '__FROM_EMAIL__' => $this->emetteur->email,
346 '__TOTAL_TTC__' => $object->total_ttc,
347 '__TOTAL_HT__' => $object->total_ht,
348 '__TOTAL_VAT__' => $object->total_tva
350 complete_substitutions_array($substitutionarray, $langs, $object);
351 // Call the ODTSubstitution hook
352 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$substitutionarray);
353 $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
357 $paramfreetext = 'ORDER_FREE_TEXT';
358 if (getDolGlobalString($paramfreetext)) {
359 $newfreetext = make_substitutions(getDolGlobalString($paramfreetext), $substitutionarray);
362 // Open and load template
363 require_once ODTPHP_PATH.'odf.php';
365 $odfHandler = new Odf(
368 'PATH_TO_TMP' => $conf->recruitment->dir_temp,
369 'ZIP_PROXY' => getDolGlobalString('MAIN_ODF_ZIP_PROXY', 'PclZipProxy'), // PhpZipProxy or PclZipProxy. Got "bad compression method
" error when using PhpZipProxy.
370 'DELIMITER_LEFT' => '{',
371 'DELIMITER_RIGHT' => '}'
374 } catch (Exception $e) {
375 $this->error = $e->getMessage();
376 dol_syslog($e->getMessage(), LOG_INFO);
379 // After construction $odfHandler->contentXml contains content and
380 // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
381 // [!-- BEGIN lines --]*[!-- END lines --]
382 //print html_entity_decode($odfHandler->__toString());
386 // Make substitutions into odt of freetext
388 $odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
389 } catch (OdfException $e) {
390 dol_syslog($e->getMessage(), LOG_INFO);
393 // Define substitution array
394 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
395 $array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs);
396 $array_objet = $this->get_substitutionarray_object($object, $outputlangs);
397 $array_user = $this->get_substitutionarray_user($user, $outputlangs);
398 $array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs);
399 $array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs);
400 $array_other = $this->get_substitutionarray_other($outputlangs);
401 // retrieve contact information for use in object as contact_xxx tags
402 $array_thirdparty_contact = array();
403 if ($usecontact && is_object($contactobject)) {
404 $array_thirdparty_contact = $this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact');
407 $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
408 complete_substitutions_array($tmparray, $outputlangs, $object);
410 // Call the ODTSubstitution hook
411 $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
412 $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
414 // retrieve the constant to apply a ratio for image size or set the ratio to 1
415 if (getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO')) {
416 $ratio = (float) getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO');
421 foreach ($tmparray as $key => $value) {
423 if (preg_match('/logo$/', $key)) {
425 if (file_exists($value)) {
426 $odfHandler->setImage($key, $value, $ratio);
428 $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
432 $odfHandler->setVars($key, $value, true, 'UTF-8');
434 } catch (OdfException $e) {
435 dol_syslog($e->getMessage(), LOG_INFO);
438 // Replace tags of lines
439 $foundtagforlines = 1;
441 $listlines = $odfHandler->setSegment('lines');
442 } catch (OdfExceptionSegmentNotFound $e) {
443 // We may arrive here if tags for lines not present into template
444 $foundtagforlines = 0;
445 dol_syslog($e->getMessage(), LOG_INFO);
447 if ($foundtagforlines) {
449 foreach ($object->lines as $line) {
452 $tmparray = $this->get_substitutionarray_lines($line, $outputlangs, $linenumber);
453 complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines
");
454 // Call the ODTSubstitutionLine hook
455 $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray, 'line' => $line);
456 $reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
457 foreach ($tmparray as $key => $val) {
459 $listlines->setVars($key, $val, true, 'UTF-8');
460 } catch (SegmentException $e) {
461 dol_syslog($e->getMessage(), LOG_INFO);
467 $odfHandler->mergeSegment($listlines);
468 } catch (OdfException $e) {
469 $this->error = $e->getMessage();
470 dol_syslog($this->error, LOG_WARNING);
475 // Replace labels translated
476 $tmparray = $outputlangs->get_translations_for_substitutions();
477 foreach ($tmparray as $key => $value) {
479 $odfHandler->setVars($key, $value, true, 'UTF-8');
480 } catch (OdfException $e) {
481 dol_syslog($e->getMessage(), LOG_INFO);
485 // Call the beforeODTSave hook
487 $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
488 $reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
491 if (getDolGlobalString('MAIN_ODT_AS_PDF')) {
493 $odfHandler->exportAsAttachedPDF($file);
494 } catch (Exception $e) {
495 $this->error = $e->getMessage();
496 dol_syslog($e->getMessage(), LOG_INFO);
501 $odfHandler->saveToDisk($file);
502 } catch (Exception $e) {
503 $this->error = $e->getMessage();
504 dol_syslog($e->getMessage(), LOG_INFO);
509 $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
510 $reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
514 $odfHandler = null; // Destroy object
516 $this->result = array('fullpath' => $file);
520 $this->error = $langs->transnoentities("ErrorCanNotCreateDir
", $dir);
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Parent class for documents models.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build a document on disk using the generic odt module.
Class to build documents using ODF templates generator.
info($langs)
Return description of a module.
__construct($db)
Constructor.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
conf($dolibarr_main_document_root, $realpathconf=null)
Load conf file (file must exists)
$conf db name
Only used if Module[ID]Name translation string is not found.
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button