dolibarr 25.0.0-alpha
doc_generic_project_odt.modules.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
4 * Copyright (C) 2013 Florian Henry <florian.henry@ope-concept.pro>
5 * Copyright (C) 2016-2023 Charlene Benke <charlene@patas-monkey.com>
6 * Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
8 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 * or see https://www.gnu.org/
23 */
24
31require_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
32require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
33require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
34require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
35require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
36require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/doc.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
42if (isModEnabled("propal")) {
43 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
44}
45if (isModEnabled('invoice')) {
46 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
47 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
48}
49if (isModEnabled('order')) {
50 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
51}
52if (isModEnabled("supplier_proposal")) {
53 require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
54}
55if ((isModEnabled("fournisseur") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || isModEnabled("supplier_invoice")) {
56 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
57}
58if ((isModEnabled("fournisseur") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || isModEnabled("supplier_order")) {
59 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
60}
61if (isModEnabled('contract')) {
62 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
63}
64if (isModEnabled('intervention')) {
65 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
66}
67if (isModEnabled('agenda')) {
68 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
69}
70if (isModEnabled('shipping')) {
71 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
72}
73if (isModEnabled('expensereport')) {
74 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereportline.class.php';
75}
76if (isModEnabled('don')) {
77 require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
78}
79if (isModEnabled('loan')) {
80 require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
81}
82if (isModEnabled('tax')) {
83 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
84}
85if (isModEnabled('stock')) {
86 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
87}
88
93{
98 public $version = 'dolibarr';
99
100
106 public function __construct($db)
107 {
108 global $langs, $mysoc;
109
110 // Load traductions files required by page
111 $langs->loadLangs(array("companies", "main"));
112
113 $this->db = $db;
114 $this->name = "ODT templates";
115 $this->description = $langs->trans("DocumentModelOdt");
116 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
117 $this->scandir = 'PROJECT_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan
118
119 // Page size for A4 format
120 $this->type = 'odt';
121 $this->page_largeur = 0;
122 $this->page_hauteur = 0;
123 $this->format = array($this->page_largeur, $this->page_hauteur);
124 $this->marge_gauche = 0;
125 $this->marge_droite = 0;
126 $this->marge_haute = 0;
127 $this->marge_basse = 0;
128
129 $this->option_logo = 1; // Display logo
130 $this->option_tva = 0; // Manage the vat option COMMANDE_TVAOPTION
131 $this->option_modereg = 0; // Display payment mode
132 $this->option_condreg = 0; // Display payment terms
133 $this->option_multilang = 1; // Available in several languages
134 $this->option_escompte = 0; // Displays if there has been a discount
135 $this->option_credit_note = 0; // Support credit notes
136 $this->option_freetext = 1; // Support add of a personalised text
137 $this->option_draft_watermark = 0; // Support add of a watermark on drafts
138
139 if ($mysoc === null) {
140 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
141 return;
142 }
143
144 // Get source company
145 $this->emetteur = $mysoc;
146 if (!$this->emetteur->country_code) {
147 $this->emetteur->country_code = substr($langs->defaultlang, -2); // Par default, si n'etait pas defini
148 }
149 }
150
151 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
160 public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object')
161 {
162 // phpcs:enable
163 if (!$object instanceof Project) {
164 dol_syslog("Expected Project object, got ".gettype($object), LOG_ERR);
165 return array();
166 }
167
168 $resarray = array(
169 $array_key.'_id' => (int) $object->id,
170 $array_key.'_ref' => (string) $object->ref,
171 $array_key.'_title' => (string) $object->title,
172 $array_key.'_description' => (string) $object->description,
173 $array_key.'_date_creation' => dol_print_date($object->date_c, 'day'),
174 $array_key.'_date_modification' => dol_print_date($object->date_m, 'day'),
175 $array_key.'_date_start' => dol_print_date($object->date_start, 'day'),
176 $array_key.'_date_end' => dol_print_date($object->date_end, 'day'),
177 $array_key.'_note_private' => (string) $object->note_private,
178 $array_key.'_note_public' => (string) $object->note_public,
179 $array_key.'_public' => (string) $object->public,
180 $array_key.'_statut' => $object->getLibStatut()
181 );
182
183 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
184 $extrafields = new ExtraFields($this->db);
185 $extrafields->fetch_name_optionals_label($object->table_element, true);
186 $object->fetch_optionals();
187
188 $resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs);
189
190 return $resarray;
191 }
192
193 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
201 public function get_substitutionarray_tasks(Task $task, $outputlangs)
202 {
203 // phpcs:enable
204 $resarray = array(
205 'task_ref' => $task->ref,
206 'task_fk_project' => $task->fk_project,
207 'task_projectref' => $task->projectref,
208 'task_projectlabel' => $task->projectlabel,
209 'task_label' => $task->label,
210 'task_description' => $task->description,
211 'task_fk_parent' => $task->fk_task_parent,
212 'task_duration' => $task->duration_effective,
213 'task_duration_hour' => convertSecondToTime($task->duration_effective, 'all'),
214 'task_planned_workload' => $task->planned_workload,
215 'task_planned_workload_hour' => convertSecondToTime($task->planned_workload, 'all'),
216 'task_progress' => $task->progress,
217 'task_public' => $task->public,
218 'task_date_start' => dol_print_date($task->date_start, 'day'),
219 'task_date_end' => dol_print_date($task->date_end, 'day'),
220 'task_note_private' => $task->note_private,
221 'task_note_public' => $task->note_public
222 );
223
224 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
225 $extrafields = new ExtraFields($this->db);
226 $extrafields->fetch_name_optionals_label($task->table_element, true);
227 $task->fetch_optionals();
228
229 $resarray = $this->fill_substitutionarray_with_extrafields($task, $resarray, $extrafields, 'task', $outputlangs);
230
231 return $resarray;
232 }
233
234 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
242 public function get_substitutionarray_project_contacts($contact, $outputlangs)
243 {
244 // phpcs:enable
245 $pc = 'projcontacts_'; // prefix to avoid typos
246
247 $ret = array(
248 $pc.'id' => $contact['id'],
249 $pc.'rowid' => $contact['rowid'],
250 $pc.'role' => $contact['libelle'],
251 $pc.'lastname' => $contact['lastname'],
252 $pc.'firstname' => $contact['firstname'],
253 $pc.'civility' => $contact['civility'],
254 $pc.'fullcivname' => $contact['fullname'],
255 $pc.'socname' => $contact['socname'],
256 $pc.'email' => $contact['email']
257 );
258
259 if ($contact['source'] == 'external') {
260 $ret[$pc.'isInternal'] = ''; // not internal
261
262 $ct = new Contact($this->db);
263 $ct->fetch($contact['id']);
264 $ret[$pc.'phone_pro'] = $ct->phone_pro;
265 $ret[$pc.'phone_perso'] = $ct->phone_perso;
266 $ret[$pc.'phone_mobile'] = $ct->phone_mobile;
267
268 // fetch external user extrafields
269 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
270 $extrafields = new ExtraFields($this->db);
271 $extrafields->fetch_name_optionals_label($ct->table_element, true);
272 $extrafields_num = $ct->fetch_optionals();
273 //dol_syslog(get_class($this)."::get_substitutionarray_project_contacts: ===== Number of Extrafields found: ".$extrafields_num, LOG_DEBUG);
274 foreach ($ct->array_options as $efkey => $efval) {
275 dol_syslog(get_class($this)."::get_substitutionarray_project_contacts: +++++ Extrafield ".$efkey." => ".$efval, LOG_DEBUG);
276 $ret[$pc.$efkey] = $efval; // add nothing else because it already comes as 'options_XX'
277 }
278 } elseif ($contact['source'] == 'internal') {
279 $ret[$pc.'isInternal'] = '1'; // this is an internal user
280
281 $ct = new User($this->db);
282 $ct->fetch($contact['id']);
283 $ret[$pc.'phone_pro'] = $ct->office_phone;
284 $ret[$pc.'phone_perso'] = '';
285 $ret[$pc.'phone_mobile'] = $ct->user_mobile;
286 // do internal users have extrafields ?
287 }
288 return $ret;
289 }
290
291 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
299 public function get_substitutionarray_project_file($file, $outputlangs)
300 {
301 // phpcs:enable
302 return array(
303 'projfile_name' => (string) $file['name'],
304 'projfile_date' => dol_print_date($file['date'], 'day'),
305 'projfile_size' => (int) $file['size']
306 );
307 }
308
309 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
317 public function get_substitutionarray_project_reference($refdetail, $outputlangs)
318 {
319 // phpcs:enable
320 return array(
321 'projref_type' => (string) $refdetail['type'],
322 'projref_ref' => (string) $refdetail['ref'],
323 'projref_date' => dol_print_date($refdetail['date'], 'day'),
324 'projref_socname' => (string) $refdetail['socname'],
325 'projref_amountht' => price($refdetail['amountht'], 0, $outputlangs),
326 'projref_amountttc' => price($refdetail['amountttc'], 0, $outputlangs),
327 'projref_status' => (int) $refdetail['status']
328 );
329 }
330
331 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
339 public function get_substitutionarray_tasksressource($taskresource, $outputlangs)
340 {
341 // phpcs:enable
342
343 //dol_syslog(get_class($this).'::get_substitutionarray_tasksressource taskressource='.var_export($taskressource,true),LOG_DEBUG);
344 return array(
345 'taskressource_rowid' => (int) $taskresource['rowid'],
346 'taskressource_role' => (string) $taskresource['libelle'],
347 'taskressource_lastname' => (string) $taskresource['lastname'],
348 'taskressource_firstname' => (string) $taskresource['firstname'],
349 'taskressource_fullcivname' => (string) $taskresource['fullname'],
350 'taskressource_socname' => (string) $taskresource['socname'],
351 'taskressource_email' => (string) $taskresource['email']
352 );
353 }
354
355 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
363 public function get_substitutionarray_taskstime($tasktime, $outputlangs)
364 {
365 // phpcs:enable
366 return array(
367 'tasktime_rowid' => (int) $tasktime['rowid'],
368 'tasktime_task_date' => dol_print_date($tasktime['task_date'], 'day'),
369 'tasktime_task_duration_sec' => (int) $tasktime['task_duration'],
370 'tasktime_task_duration' => convertSecondToTime($tasktime['task_duration'], 'all'),
371 'tasktime_note' => (string) $tasktime['note'],
372 'tasktime_fk_user' => (int) $tasktime['fk_user'],
373 'tasktime_user_name' => (string) $tasktime['name'],
374 'tasktime_user_first' => (string) $tasktime['firstname'],
375 'tasktime_fullcivname' => (string) $tasktime['fullcivname'],
376 'tasktime_amountht' => (float) $tasktime['amountht'],
377 'tasktime_amountttc' => (float) $tasktime['amountttc'],
378 'tasktime_thm' => (float) $tasktime['thm']
379 );
380 }
381
382 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
390 public function get_substitutionarray_task_file($file, $outputlangs)
391 {
392 // phpcs:enable
393 return array(
394 'tasksfile_name' => (string) $file['name'],
395 'tasksfile_date' => dol_print_date($file['date'], 'day'),
396 'tasksfile_size' => (int) $file['size']
397 );
398 }
399
400
407 public function info($langs)
408 {
409 global $conf, $langs;
410
411 // Load translation files required by the page
412 $langs->loadLangs(array("companies", "errors"));
413
414 $form = new Form($this->db);
415
416 $texte = $this->description.".<br>\n";
417 $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" enctype="multipart/form-data">';
418 $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
419 $texte .= '<input type="hidden" name="page_y" value="">';
420 $texte .= '<input type="hidden" name="action" value="setModuleOptions">';
421 $texte .= '<input type="hidden" name="param1" value="PROJECT_ADDON_PDF_ODT_PATH">';
422 $texte .= '<table class="nobordernopadding centpercent">';
423
424 // List of directories area
425 $texte .= '<tr><td>';
426 $texttitle = $langs->trans("ListOfDirectories");
427 $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim(getDolGlobalString('PROJECT_ADDON_PDF_ODT_PATH'))));
428 $listoffiles = array();
429 foreach ($listofdir as $key => $tmpdir) {
430 $tmpdir = trim($tmpdir);
431 $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
432 if (!$tmpdir) {
433 unset($listofdir[$key]);
434 continue;
435 }
436 if (!is_dir($tmpdir)) {
437 $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), '');
438 } else {
439 $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)');
440 if (count($tmpfiles)) {
441 $listoffiles = array_merge($listoffiles, $tmpfiles);
442 }
443 }
444 }
445 $texthelp = $langs->trans("ListOfDirectoriesForModelGenODT");
446 $texthelp .= '<br><br><span class="opacitymedium">'.$langs->trans("ExampleOfDirectoriesForModelGen").'</span>';
447 // Add list of substitution keys
448 $texthelp .= '<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
449 $texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it
450
451 // Scan directories
452 $nbofiles = count($listoffiles);
453 if (getDolGlobalString('PROJECT_ADDON_PDF_ODT_PATH')) {
454 $texte .= '<span class="opacitylow">'.$langs->trans("NumberOfModelFilesFound").': <b>';
455 //$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':'';
456 $texte .= $nbofiles;
457 //$texte.=$nbofiles?'</a>':'';
458 $texte .= '</b></span><br>';
459 }
460
461 if ($nbofiles) {
462 $texte .= '<div id="div_'.get_class($this).'" class="hiddenx opacitylow">';
463 // Show list of found files
464 foreach ($listoffiles as $file) {
465 $texte .= '- '.$file['name'].' <a href="'.DOL_URL_ROOT.'/document.php?modulepart=doctemplates&file=projects/'.urlencode(basename($file['name'])).'">'.img_picto('', 'listlight').'</a>';
466 $texte .= ' &nbsp; <a class="reposition" href="'.$_SERVER["PHP_SELF"].'?modulepart=doctemplates&keyforuploaddir=PROJECT_ADDON_PDF_ODT_PATH&action=deletefile&token='.newToken().'&file='.urlencode(basename($file['name'])).'">'.img_picto('', 'delete').'</a>';
467 $texte .= '<br>';
468 }
469 $texte .= '</div>';
470 }
471 $texte .= '<br>';
472 // Link to show/hide the area to manage directories of ODT models and template files
473 $texte .= '<span class="classlink cursorpointer" onclick="javascript: jQuery(\'.div_odtmodelsof'.get_class($this).'\').toggle();">'.img_picto('', 'add').' '.$langs->trans("UploadNewTemplate").'...</span>';
474 $texte .= '<div class="div_odtmodelsof'.get_class($this).'" style="display: none; margin-top: 6px;">';
475 $texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1, 3, $this->name);
476 $texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
477 $texte .= '<textarea class="flat textareafordir" spellcheck="false" cols="60" name="value1">';
478 $texte .= getDolGlobalString('PROJECT_ADDON_PDF_ODT_PATH');
479 $texte .= '</textarea>';
480 $texte .= '</div><div style="display: inline-block; vertical-align: middle;">';
481 $texte .= '<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dol_escape_htmltag($langs->trans("Modify")).'">';
482 $texte .= '<br></div></div>';
483 $texte .= '</div>';
484
485 // Add input to upload a new template file.
486 $texte .= '<div class="div_odtmodelsof'.get_class($this).'" style="display: none;">';
487 $maxfilesizearray = getMaxFileSizeArray();
488 $maxmin = $maxfilesizearray['maxmin'];
489 if ($maxmin > 0) {
490 $texte .= '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
491 }
492 $texte .= ' <input type="file" name="uploadfile">';
493 $texte .= '<input type="hidden" value="PROJECT_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
494 $texte .= '<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans("Upload")).'" name="upload">';
495 $texte .= '</div>';
496 $texte .= '</td>';
497
498 $texte .= '</tr>';
499
500 $texte .= '</table>';
501 $texte .= '</form>';
502
503 return $texte;
504 }
505
506 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
518 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
519 {
520 // phpcs:enable
521 global $user, $langs, $conf, $mysoc, $hookmanager;
522
523 if (empty($srctemplatepath)) {
524 dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
525 return -1;
526 }
527
528 // Add odtgeneration hook
529 if (!is_object($hookmanager)) {
530 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
531 $hookmanager = new HookManager($this->db);
532 }
533 $hookmanager->initHooks(array('odtgeneration'));
534 global $action;
535
536 if (!is_object($outputlangs)) {
537 $outputlangs = $langs;
538 }
539 $sav_charset_output = $outputlangs->charset_output;
540 $outputlangs->charset_output = 'UTF-8';
541
542 // Load translation files required by the page
543 $outputlangs->loadLangs(array("main", "dict", "companies", "projects"));
544
545 if ($conf->project->dir_output) {
546 // If $object is id instead of object
547 if (!is_object($object)) {
548 $id = $object;
549 $object = new Project($this->db);
550 $result = $object->fetch($id);
551 if ($result < 0) {
552 dol_print_error($this->db, $object->error);
553 return -1;
554 }
555 }
556
557 $object->fetch_thirdparty();
558
559 $dir = $conf->project->dir_output;
560 $objectref = dol_sanitizeFileName($object->ref);
561 if (!preg_match('/specimen/i', $objectref)) {
562 $dir .= "/".$objectref;
563 }
564 $file = $dir."/".$objectref.".odt";
565
566 if (!file_exists($dir)) {
567 if (dol_mkdir($dir) < 0) {
568 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
569 return -1;
570 }
571 }
572
573 if (file_exists($dir)) {
574 //print "srctemplatepath=".$srctemplatepath; // Src filename
575 $newfile = basename($srctemplatepath);
576 $newfiletmp = preg_replace('/\.od[ts]/i', '', $newfile);
577 $newfiletmp = preg_replace('/template_/i', '', $newfiletmp);
578 $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp);
579 $newfiletmp = $objectref . '_' . $newfiletmp;
580 //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
581 // Get extension (ods or odt)
582 $newfileformat = substr($newfile, strrpos($newfile, '.') + 1);
583 if (getDolGlobalString('MAIN_DOC_USE_TIMING')) {
584 $format = getDolGlobalString('MAIN_DOC_USE_TIMING');
585 if ($format == '1') {
586 $format = '%Y%m%d%H%M%S';
587 }
588 $filename = $newfiletmp . '-' . dol_print_date(dol_now(), $format) . '.' . $newfileformat;
589 } else {
590 $filename = $newfiletmp . '.' . $newfileformat;
591 }
592 $file = $dir . '/' . $filename;
593 //print "newdir=".$dir;
594 //print "newfile=".$newfile;
595 //print "file=".$file;
596 //print "conf->societe->dir_temp=".$conf->societe->dir_temp;
597
598 dol_mkdir($conf->project->dir_temp);
599 if (!is_writable($conf->project->dir_temp)) {
600 $this->error = $langs->transnoentities("ErrorFailedToWriteInTempDirectory", $conf->project->dir_temp);
601 dol_syslog('Error in write_file: ' . $this->error, LOG_ERR);
602 return -1;
603 }
604
605 // If PROJECTLEADER contact defined on project, we use it
606 $usecontact = false;
607 $arrayidcontact = $object->getIdContact('external', 'PROJECTLEADER');
608 if (count($arrayidcontact) > 0) {
609 $usecontact = true;
610 $result = $object->fetch_contact($arrayidcontact[0]);
611 }
612
613 // Recipient name
614 $contactobject = null;
615 if (!empty($usecontact)) {
616 // if we have a PROJECTLEADER contact and we don't use it as recipient we store the contact object for later use
617 $contactobject = $object->contact;
618 }
619
620 $socobject = $object->thirdparty;
621
622 // Make substitution
623 $substitutionarray = array(
624 '__FROM_NAME__' => $this->emetteur->name,
625 '__FROM_EMAIL__' => $this->emetteur->email,
626 );
627 complete_substitutions_array($substitutionarray, $langs, $object);
628 // Call the ODTSubstitution hook
629 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$substitutionarray);
630 $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
631
632 // Open and load template
633 require_once ODTPHP_PATH.'odf.php';
634 try {
635 $odfHandler = new Odf(
636 $srctemplatepath,
637 array(
638 'PATH_TO_TMP' => $conf->project->dir_temp,
639 'ZIP_PROXY' => getDolGlobalString('MAIN_ODF_ZIP_PROXY', 'PclZipProxy'), // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
640 'DELIMITER_LEFT' => '{',
641 'DELIMITER_RIGHT' => '}'
642 )
643 );
644 } catch (Exception $e) {
645 $this->error = $e->getMessage();
646 dol_syslog($e->getMessage(), LOG_INFO);
647 return -1;
648 }
649 // After construction $odfHandler->contentXml contains content and
650 // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
651 // [!-- BEGIN lines --]*[!-- END lines --]
652
653 // Define substitution array
654 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
655 $array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs);
656 $array_objet = $this->get_substitutionarray_object($object, $outputlangs);
657 $array_user = $this->get_substitutionarray_user($user, $outputlangs);
658 $array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs);
659 $array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs);
660 $array_other = $this->get_substitutionarray_other($outputlangs);
661 // retrieve contact information for use in object as contact_xxx tags
662 $array_project_contact = array();
663 if ($usecontact && is_object($contactobject)) {
664 $array_project_contact = $this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact');
665 }
666
667 $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_project_contact);
668 complete_substitutions_array($tmparray, $outputlangs, $object);
669
670 // Call the ODTSubstitution hook
671 $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
672 $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
673
674 // retrieve the constant to apply a ratio for image size or set the ratio to 1
675 if (getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO')) {
676 $ratio = (float) getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO');
677 } else {
678 $ratio = 1;
679 }
680
681 foreach ($tmparray as $key => $value) {
682 try {
683 if (preg_match('/logo$/', $key)) { // Image
684 if (file_exists($value)) {
685 $odfHandler->setImage($key, $value, $ratio);
686 } else {
687 $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
688 }
689 } else { // Text
690 $odfHandler->setVars($key, $value, true, 'UTF-8');
691 }
692 } catch (OdfException $e) {
693 dol_syslog($e->getMessage(), LOG_INFO);
694 }
695 }
696
697 // Replace tags of lines for tasks
698 $foundtagfortasks = 1;
699 try {
700 $listlines = $odfHandler->setSegment('tasks');
701 } catch (OdfExceptionSegmentNotFound $e) {
702 // We may arrive here if tags for tasks not present into template
703 $foundtagfortasks = 0;
704 dol_syslog($e->getMessage(), LOG_INFO);
705 }
706 if ($foundtagfortasks && isset($listlines)) {
707 $taskstatic = new Task($this->db);
708
709 // Security check
710 $socid = 0;
711 if (!empty($object->socid)) {
712 $socid = $object->socid;
713 }
714
715 $tasksarray = $taskstatic->getTasksArray(null, null, $object->id, $socid, 0);
716
717
718 foreach ($tasksarray as $task) {
719 $tmparray = $this->get_substitutionarray_tasks($task, $outputlangs);
720 //complete_substitutions_array($tmparray, $outputlangs, $object, $task, "completesubstitutionarray_lines");
721 foreach ($tmparray as $key => $val) {
722 try {
723 $listlines->setVars($key, $val, true, 'UTF-8');
724 } catch (SegmentException $e) {
725 dol_syslog($e->getMessage(), LOG_INFO);
726 }
727 }
728
729 $taskobj = new Task($this->db);
730 $taskobj->fetch($task->id);
731
732 // Replace tags of lines for contacts task
733 $sourcearray = array('internal', 'external');
734 $contact_arrray = array();
735 foreach ($sourcearray as $source) {
736 $contact_temp = $taskobj->liste_contact(-1, $source);
737 if ((is_array($contact_temp) && count($contact_temp) > 0)) {
738 $contact_arrray = array_merge($contact_arrray, $contact_temp);
739 }
740 }
741 if ((is_array($contact_arrray) && count($contact_arrray) > 0)) {
742 $foundtagfortasksressources = 1;
743 try {
744 $listlinestaskres = $listlines->__get('tasksressources');
745 } catch (SegmentException $e) {
746 // We may arrive here if tags for tasksressources not present into template
747 $foundtagfortasksressources = 0;
748 dol_syslog($e->getMessage(), LOG_INFO);
749 }
750 if ($foundtagfortasksressources && isset($listlinestaskres)) {
751 foreach ($contact_arrray as $contact) {
752 if ($contact['source'] == 'internal') {
753 $objectdetail = new User($this->db);
754 $objectdetail->fetch($contact['id']);
755 $contact['socname'] = $mysoc->name;
756 } elseif ($contact['source'] == 'external') {
757 $objectdetail = new Contact($this->db);
758 $objectdetail->fetch($contact['id']);
759
760 $soc = new Societe($this->db);
761 $soc->fetch($contact['socid']);
762 $contact['socname'] = $soc->name;
763 } else {
764 dol_syslog(get_class().'::'.__METHOD__.' Unexpected contact source:'.$contact['source'], LOG_ERR);
765 continue;
766 }
767 $contact['fullname'] = $objectdetail->getFullName($outputlangs, 1);
768
769 $tmparray = $this->get_substitutionarray_tasksressource($contact, $outputlangs);
770
771 foreach ($tmparray as $key => $val) {
772 try {
773 $listlinestaskres->setVars($key, $val, true, 'UTF-8');
774 } catch (SegmentException $e) {
775 dol_syslog($e->getMessage(), LOG_INFO);
776 }
777 }
778 $listlinestaskres->merge();
779 }
780 }
781 }
782
783 //Time resources
784 $sql = "SELECT t.rowid, t.element_date as task_date, t.element_duration as task_duration, t.fk_user, t.note";
785 $sql .= ", u.lastname, u.firstname, t.thm";
786 $sql .= " FROM ".MAIN_DB_PREFIX."element_time as t";
787 $sql .= " , ".MAIN_DB_PREFIX."user as u";
788 $sql .= " WHERE t.fk_element =".((int) $task->id);
789 $sql .= " AND t.elementtype = 'task'";
790 $sql .= " AND t.fk_user = u.rowid";
791 $sql .= " ORDER BY t.element_date DESC";
792
793 $resql = $this->db->query($sql);
794 if ($resql) {
795 $num = $this->db->num_rows($resql);
796 $i = 0;
797 $tasks = array();
798 $row = array();
799 $foundtagfortaskstimes = 1;
800 try {
801 $listlinestasktime = $listlines->__get('taskstimes');
802 } catch (SegmentException $e) {
803 // We may arrive here if tags for taskstimes not present into template
804 $foundtagfortaskstimes = 0;
805 dol_syslog($e->getMessage(), LOG_INFO);
806 }
807 if ($foundtagfortaskstimes && isset($listlinestasktime)) {
808 if (empty($num)) {
809 $row['rowid'] = 0;
810 $row['task_date'] = 0;
811 $row['task_duration'] = 0;
812 //$row['$tasktime'] = '';
813 $row['note'] = '';
814 $row['fk_user'] = 0;
815 $row['name'] = '';
816 $row['firstname'] = '';
817 $row['fullcivname'] = '';
818 $row['amountht'] = 0;
819 $row['amountttc'] = 0;
820 $row['thm'] = 0;
821 $tmparray = $this->get_substitutionarray_taskstime($row, $outputlangs);
822 foreach ($tmparray as $key => $val) {
823 try {
824 $listlinestasktime->setVars($key, $val, true, 'UTF-8');
825 } catch (SegmentException $e) {
826 dol_syslog($e->getMessage(), LOG_INFO);
827 }
828 }
829 $listlinestasktime->merge();
830 }
831 while ($i < $num) {
832 $row = $this->db->fetch_array($resql);
833 if (!empty($row['fk_user'])) {
834 $objectdetail = new User($this->db);
835 $objectdetail->fetch($row['fk_user']);
836 $row['fullcivname'] = $objectdetail->getFullName($outputlangs, 1);
837 } else {
838 $row['fullcivname'] = '';
839 }
840
841 if (!empty($row['thm'])) {
842 $row['amountht'] = ($row['task_duration'] / 3600) * $row['thm'];
843 $defaultvat = get_default_tva($mysoc, $mysoc);
844 $row['amountttc'] = price2num($row['amountht'] * (1 + ($defaultvat / 100)), 'MT');
845 } else {
846 $row['amountht'] = 0;
847 $row['amountttc'] = 0;
848 $row['thm'] = 0;
849 }
850
851 $tmparray = $this->get_substitutionarray_taskstime($row, $outputlangs); // @phpstan-ignore argument.type
852
853 foreach ($tmparray as $key => $val) {
854 try {
855 $listlinestasktime->setVars($key, $val, true, 'UTF-8');
856 } catch (SegmentException $e) {
857 dol_syslog($e->getMessage(), LOG_INFO);
858 }
859 }
860 $listlinestasktime->merge();
861 $i++;
862 }
863 }
864 $this->db->free($resql);
865 }
866
867
868 // Replace tags of project files
869 $foundtagfortasksfiles = 1;
870 try {
871 $listtasksfiles = $listlines->__get('tasksfiles');
872 } catch (SegmentException $e) {
873 // We may arrive here if tags for tasksfiles not present into template
874 $foundtagfortasksfiles = 0;
875 dol_syslog($e->getMessage(), LOG_INFO);
876 }
877 if ($foundtagfortasksfiles && isset($listtasksfiles)) {
878 $upload_dir = $conf->project->dir_output.'/'.dol_sanitizeFileName($object->ref).'/'.dol_sanitizeFileName($task->ref);
879 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', 'name', SORT_ASC, 1);
880
881
882 foreach ($filearray as $filedetail) {
883 $tmparray = $this->get_substitutionarray_task_file($filedetail, $outputlangs);
884 //dol_syslog(get_class($this).'::main $tmparray'.var_export($tmparray,true));
885 foreach ($tmparray as $key => $val) {
886 try {
887 $listtasksfiles->setVars($key, $val, true, 'UTF-8');
888 } catch (SegmentException $e) {
889 dol_syslog($e->getMessage(), LOG_INFO);
890 }
891 }
892 $listtasksfiles->merge();
893 }
894 }
895 $listlines->merge();
896 }
897 try {
898 $odfHandler->mergeSegment($listlines);
899 } catch (OdfException $e) {
900 $this->error = $e->getMessage();
901 dol_syslog($this->error, LOG_WARNING);
902 return -1;
903 }
904 }
905
906 // Replace tags of project files
907 $foundtagforprojectfiles = 1;
908 try {
909 $listlines = $odfHandler->setSegment('projectfiles');
910 } catch (OdfExceptionSegmentNotFound $e) {
911 // We may arrive here if tags for projectfiles not present into template
912 $foundtagforprojectfiles = 0;
913 dol_syslog($e->getMessage(), LOG_INFO);
914 }
915 if ($foundtagforprojectfiles && isset($listlines)) {
916 $upload_dir = $conf->project->dir_output.'/'.dol_sanitizeFileName($object->ref);
917 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', 'name', SORT_ASC, 1);
918
919 foreach ($filearray as $filedetail) {
920 //dol_syslog(get_class($this).'::main $filedetail'.var_export($filedetail,true));
921 $tmparray = $this->get_substitutionarray_project_file($filedetail, $outputlangs);
922
923 foreach ($tmparray as $key => $val) {
924 try {
925 $listlines->setVars($key, $val, true, 'UTF-8');
926 } catch (SegmentException $e) {
927 dol_syslog($e->getMessage(), LOG_INFO);
928 }
929 }
930 $listlines->merge();
931 }
932 try {
933 $odfHandler->mergeSegment($listlines);
934 } catch (OdfException $e) {
935 $this->error = $e->getMessage();
936 dol_syslog($this->error, LOG_WARNING);
937 return -1;
938 }
939 }
940
941 // Replace tags of lines for contacts
942 $sourcearray = array('internal', 'external');
943 $contact_arrray = array();
944 foreach ($sourcearray as $source) {
945 $contact_temp = $object->liste_contact(-1, $source);
946 if ((is_array($contact_temp) && count($contact_temp) > 0)) {
947 $contact_arrray = array_merge($contact_arrray, $contact_temp);
948 }
949 }
950 if ((is_array($contact_arrray) && count($contact_arrray) > 0)) {
951 $foundtagforprojectcontacts = 1;
952 try {
953 $listlines = $odfHandler->setSegment('projectcontacts');
954 } catch (OdfExceptionSegmentNotFound $e) {
955 // We may arrive here if tags for projectcontacts not present into template
956 $foundtagforprojectcontacts = 0;
957 dol_syslog($e->getMessage(), LOG_INFO);
958 }
959 if ($foundtagforprojectcontacts && isset($listlines)) {
960 foreach ($contact_arrray as $contact) {
961 $objectdetail = null;
962 if ($contact['source'] == 'internal') {
963 $objectdetail = new User($this->db);
964 $objectdetail->fetch($contact['id']);
965 $contact['socname'] = $mysoc->name;
966 } elseif ($contact['source'] == 'external') {
967 $objectdetail = new Contact($this->db);
968 $objectdetail->fetch($contact['id']);
969
970 $soc = new Societe($this->db);
971 $soc->fetch($contact['socid']);
972 $contact['socname'] = $soc->name;
973 } else {
974 dol_syslog('Unexpected contact source:'.$contact['source'].'.'. getCallerInfoString(), LOG_ERR);
975 continue;
976 }
977 $contact['fullname'] = $objectdetail->getFullName($outputlangs, 1);
978
979 $tmparray = $this->get_substitutionarray_project_contacts($contact, $outputlangs);
980 foreach ($tmparray as $key => $val) {
981 try {
982 $listlines->setVars($key, $val, true, 'UTF-8');
983 } catch (SegmentException $e) {
984 dol_syslog($e->getMessage(), LOG_INFO);
985 }
986 }
987 $listlines->merge();
988 }
989 try {
990 $odfHandler->mergeSegment($listlines);
991 } catch (OdfException $e) {
992 $this->error = $e->getMessage();
993 dol_syslog($this->error, LOG_WARNING);
994 return -1;
995 }
996 }
997 }
998
999 //List of referent
1000
1001 $listofreferent = array(
1002 'propal' => array(
1003 'title' => "ListProposalsAssociatedProject",
1004 'class' => 'Propal',
1005 'table' => 'propal',
1006 'test' => isModEnabled('propal') && $user->hasRight('propal', 'lire')
1007 ),
1008 'order' => array(
1009 'title' => "ListOrdersAssociatedProject",
1010 'class' => 'Commande',
1011 'table' => 'commande',
1012 'test' => isModEnabled('order') && $user->hasRight('commande', 'lire')
1013 ),
1014 'invoice' => array(
1015 'title' => "ListInvoicesAssociatedProject",
1016 'class' => 'Facture',
1017 'table' => 'facture',
1018 'test' => isModEnabled('invoice') && $user->hasRight('facture', 'lire')
1019 ),
1020 'invoice_predefined' => array(
1021 'title' => "ListPredefinedInvoicesAssociatedProject",
1022 'class' => 'FactureRec',
1023 'table' => 'facture_rec',
1024 'test' => isModEnabled('invoice') && $user->hasRight('facture', 'lire')
1025 ),
1026 'proposal_supplier' => array(
1027 'title' => "ListSupplierProposalsAssociatedProject",
1028 'class' => 'SupplierProposal',
1029 'table' => 'supplier_proposal',
1030 'test' => isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire')
1031 ),
1032 'order_supplier' => array(
1033 'title' => "ListSupplierOrdersAssociatedProject",
1034 'table' => 'commande_fournisseur',
1035 'class' => 'CommandeFournisseur',
1036 'test' => (isModEnabled("fournisseur") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight('fournisseur', 'commande', 'lire')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire'))
1037 ),
1038 'invoice_supplier' => array(
1039 'title' => "ListSupplierInvoicesAssociatedProject",
1040 'table' => 'facture_fourn',
1041 'class' => 'FactureFournisseur',
1042 'test' => (isModEnabled("fournisseur") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight('fournisseur', 'facture', 'lire')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))
1043 ),
1044 'contract' => array(
1045 'title' => "ListContractAssociatedProject",
1046 'class' => 'Contrat',
1047 'table' => 'contrat',
1048 'test' => isModEnabled('contract') && $user->hasRight('contrat', 'lire')
1049 ),
1050 'intervention' => array(
1051 'title' => "ListFichinterAssociatedProject",
1052 'class' => 'Fichinter',
1053 'table' => 'fichinter',
1054 'disableamount' => 1,
1055 'test' => isModEnabled('intervention') && $user->hasRight('ficheinter', 'lire')
1056 ),
1057 'shipping' => array(
1058 'title' => "ListShippingAssociatedProject",
1059 'class' => 'Expedition',
1060 'table' => 'expedition',
1061 'disableamount' => 1,
1062 'test' => isModEnabled('shipping') && $user->hasRight('expedition', 'lire')
1063 ),
1064 'expensereport' => array(
1065 'title' => "ListExpenseReportsAssociatedProject",
1066 'class' => 'ExpenseReportLine',
1067 'table' => 'expensereport_det',
1068 'test' => isModEnabled('expensereport') && $user->hasRight('expensereport', 'lire')
1069 ),
1070 'donation' => array(
1071 'title' => "ListDonationsAssociatedProject",
1072 'class' => 'Don',
1073 'table' => 'don',
1074 'test' => isModEnabled('don') && $user->hasRight('don', 'lire')
1075 ),
1076 'loan' => array(
1077 'title' => "ListLoanAssociatedProject",
1078 'class' => 'Loan',
1079 'table' => 'loan',
1080 'test' => isModEnabled('loan') && $user->hasRight('loan', 'read')
1081 ),
1082 'chargesociales' => array(
1083 'title' => "ListSocialContributionAssociatedProject",
1084 'class' => 'ChargeSociales',
1085 'table' => 'chargesociales',
1086 'urlnew' => DOL_URL_ROOT.'/compta/sociales/card.php?action=create&projectid='.$object->id,
1087 'test' => isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')
1088 ),
1089 'stock_mouvement' => array(
1090 'title' => "ListMouvementStockProject",
1091 'class' => 'MouvementStock',
1092 'table' => 'stock_mouvement',
1093 'test' => (isModEnabled('stock') && $user->hasRight('stock', 'mouvement', 'lire') && getDolGlobalString('STOCK_MOVEMENT_INTO_PROJECT_OVERVIEW'))
1094 ),
1095 'agenda' => array(
1096 'title' => "ListActionsAssociatedProject",
1097 'class' => 'ActionComm',
1098 'table' => 'actioncomm',
1099 'disableamount' => 1,
1100 'test' => isModEnabled('agenda') && $user->hasRight('agenda', 'allactions', 'lire')
1101 ),
1102 );
1103
1104 // Insert list of objects into the project
1105 $foundtagforprojectrefs = 1;
1106 try {
1107 $listlines = $odfHandler->setSegment('projectrefs');
1108 } catch (OdfExceptionSegmentNotFound $e) {
1109 // We may arrive here if tags for projectrefs not present into template
1110 $foundtagforprojectrefs = 0;
1111 dol_syslog($e->getMessage(), LOG_INFO);
1112 }
1113 if ($foundtagforprojectrefs && isset($listlines)) {
1114 foreach ($listofreferent as $keyref => $valueref) {
1115 $title = $valueref['title'];
1116 $tablename = $valueref['table'];
1117 $classname = $valueref['class'];
1118 $qualified = $valueref['test'];
1119 if ($qualified) {
1120 $elementarray = $object->get_element_list($keyref, $tablename);
1121 if (count($elementarray) > 0 && is_array($elementarray)) {
1122 $total_ht = 0;
1123 $total_ttc = 0;
1124 $num = count($elementarray);
1125 for ($i = 0; $i < $num; $i++) {
1126 $ref_array = array();
1127 $ref_array['type'] = (string) $langs->trans($classname);
1128
1129 $element = new $classname($this->db);
1130 $element->fetch((int) $elementarray[$i]);
1131 $element->fetch_thirdparty();
1132
1133 //Ref object
1134 $ref_array['ref'] = (string) $element->ref;
1135
1136 //Date object
1137 $dateref = $element->date;
1138 if (empty($dateref)) {
1139 $dateref = $element->datep;
1140 }
1141 if (empty($dateref)) {
1142 $dateref = $element->date_contrat;
1143 }
1144 $ref_array['date'] = (string) $dateref;
1145
1146 //Soc object
1147 if (is_object($element->thirdparty)) {
1148 $ref_array['socname'] = $element->thirdparty->name;
1149 } else {
1150 $ref_array['socname'] = '';
1151 }
1152
1153 //Amount object
1154 if (empty($valueref['disableamount'])) {
1155 if (!empty($element->total_ht)) {
1156 $ref_array['amountht'] = (float) $element->total_ht;
1157 $ref_array['amountttc'] = (float) $element->total_ttc;
1158 } else {
1159 $ref_array['amountht'] = 0;
1160 $ref_array['amountttc'] = 0;
1161 }
1162 } else {
1163 $ref_array['amountht'] = '';
1164 $ref_array['amountttc'] = '';
1165 }
1166
1167 $ref_array['status'] = method_exists($element, 'getLibStatut') ? $element->getLibStatut(0) : '';
1168
1169 $tmparray = $this->get_substitutionarray_project_reference($ref_array, $outputlangs);
1170
1171 foreach ($tmparray as $key => $val) {
1172 try {
1173 $listlines->setVars($key, $val, true, 'UTF-8');
1174 } catch (SegmentException $e) {
1175 dol_syslog($e->getMessage(), LOG_INFO);
1176 }
1177 }
1178 $listlines->merge();
1179 }
1180 }
1181 }
1182 try {
1183 $odfHandler->mergeSegment($listlines);
1184 } catch (OdfException $e) {
1185 $this->error = $e->getMessage();
1186 dol_syslog($this->error, LOG_WARNING);
1187 return -1;
1188 }
1189 }
1190 }
1191
1192 // Replace labels translated
1193 $tmparray = $outputlangs->get_translations_for_substitutions();
1194 foreach ($tmparray as $key => $value) {
1195 try {
1196 $odfHandler->setVars($key, $value, true, 'UTF-8');
1197 } catch (OdfException $e) {
1198 dol_syslog($e->getMessage(), LOG_INFO);
1199 }
1200 }
1201
1202 // Call the beforeODTSave hook
1203 $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
1204 $reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1205
1206
1207 // Write new file
1208 if (getDolGlobalString('MAIN_ODT_AS_PDF')) {
1209 try {
1210 $odfHandler->exportAsAttachedPDF($file);
1211 } catch (Exception $e) {
1212 $this->error = $e->getMessage();
1213 return -1;
1214 }
1215 } else {
1216 try {
1217 $odfHandler->saveToDisk($file);
1218 } catch (Exception $e) {
1219 $this->error = $e->getMessage();
1220 dol_syslog($e->getMessage(), LOG_INFO);
1221 return -1;
1222 }
1223 }
1224 $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
1225 $reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1226
1227 dolChmod($file);
1228
1229 $odfHandler = null; // Destroy object
1230
1231 $this->result = array('fullpath' => $file);
1232
1233 return 1; // Success
1234 } else {
1235 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
1236 return -1;
1237 }
1238 }
1239
1240 return -1;
1241 }
1242}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:281
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
fill_substitutionarray_with_extrafields($object, $array_to_fill, $extrafields, $array_key, $outputlangs)
Fill array with couple extrafield key => extrafield value Note that vars into substitutions array are...
Class to manage contact/addresses.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
Parent class for projects models.
Class to manage projects.
Class to manage tasks.
Class to manage Dolibarr users.
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.
get_substitutionarray_tasks(Task $task, $outputlangs)
Define array with couple substitution key => substitution value.
get_substitutionarray_task_file($file, $outputlangs)
Define array with couple substitution key => substitution value.
get_substitutionarray_project_file($file, $outputlangs)
Define array with couple substitution key => substitution value.
get_substitutionarray_tasksressource($taskresource, $outputlangs)
Define array with couple substitution key => substitution value.
get_substitutionarray_taskstime($tasktime, $outputlangs)
Define array with couple substitution key => substitution value.
get_substitutionarray_project_contacts($contact, $outputlangs)
Define array with couple substitution key => substitution value.
get_substitutionarray_object($object, $outputlangs, $array_key='object')
Define array with couple substitution key => substitution value.
get_substitutionarray_project_reference($refdetail, $outputlangs)
Define array with couple substitution key => substitution value.
info($langs)
Return description of a module.
global $mysoc
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
Definition date.lib.php:263
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.
Definition files.lib.php:66
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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)
Definition inc.php:431
$conf db user
Active Directory does not allow anonymous connections.
Definition repair.php:166
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:165
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button