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';
43 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
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';
50 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
53 require_once DOL_DOCUMENT_ROOT.
'/supplier_proposal/class/supplier_proposal.class.php';
56 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
59 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
62 require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
65 require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
68 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
71 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
74 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereportline.class.php';
77 require_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
80 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
83 require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
86 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
98 public $version =
'dolibarr';
111 $langs->loadLangs(array(
"companies",
"main"));
114 $this->
name =
"ODT templates";
115 $this->
description = $langs->trans(
"DocumentModelOdt");
116 $this->update_main_doc_field = 1;
117 $this->scandir =
'PROJECT_ADDON_PDF_ODT_PATH';
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;
129 $this->option_logo = 1;
130 $this->option_tva = 0;
131 $this->option_modereg = 0;
132 $this->option_condreg = 0;
133 $this->option_multilang = 1;
134 $this->option_escompte = 0;
135 $this->option_credit_note = 0;
136 $this->option_freetext = 1;
137 $this->option_draft_watermark = 0;
146 if (!$this->emetteur->country_code) {
147 $this->emetteur->country_code = substr($langs->defaultlang, -2);
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,
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()
183 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
185 $extrafields->fetch_name_optionals_label(
$object->table_element,
true);
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,
214 'task_planned_workload' => $task->planned_workload,
216 'task_progress' => $task->progress,
217 'task_public' => $task->public,
220 'task_note_private' => $task->note_private,
221 'task_note_public' => $task->note_public
224 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
226 $extrafields->fetch_name_optionals_label($task->table_element,
true);
227 $task->fetch_optionals();
245 $pc =
'projcontacts_';
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']
259 if ($contact[
'source'] ==
'external') {
260 $ret[$pc.
'isInternal'] =
'';
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;
269 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
271 $extrafields->fetch_name_optionals_label($ct->table_element,
true);
272 $extrafields_num = $ct->fetch_optionals();
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;
278 } elseif ($contact[
'source'] ==
'internal') {
279 $ret[$pc.
'isInternal'] =
'1';
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;
303 'projfile_name' => (
string) $file[
'name'],
305 'projfile_size' => (
int) $file[
'size']
321 'projref_type' => (
string) $refdetail[
'type'],
322 'projref_ref' => (
string) $refdetail[
'ref'],
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']
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']
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'],
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']
394 'tasksfile_name' => (
string) $file[
'name'],
396 'tasksfile_size' => (
int) $file[
'size']
409 global
$conf, $langs;
412 $langs->loadLangs(array(
"companies",
"errors"));
414 $form =
new Form($this->db);
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">';
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);
433 unset($listofdir[$key]);
436 if (!is_dir($tmpdir)) {
437 $texttitle .= img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir),
'');
439 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
440 if (count($tmpfiles)) {
441 $listoffiles = array_merge($listoffiles, $tmpfiles);
445 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
446 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
448 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
449 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
452 $nbofiles = count($listoffiles);
454 $texte .=
'<span class="opacitylow">'.$langs->trans(
"NumberOfModelFilesFound").
': <b>';
458 $texte .=
'</b></span><br>';
462 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx opacitylow">';
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 .=
' <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>';
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>';
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'];
490 $texte .= '<input type="hidden
" name="MAX_FILE_SIZE
" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
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
">';
500 $texte .= '</table>';
506 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
518 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
521 global $user, $langs, $conf, $mysoc, $hookmanager;
523 if (empty($srctemplatepath)) {
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);
533 $hookmanager->initHooks(array('odtgeneration'));
536 if (!is_object($outputlangs)) {
537 $outputlangs = $langs;
539 $sav_charset_output = $outputlangs->charset_output;
540 $outputlangs->charset_output = 'UTF-8';
542 // Load translation files required by the page
543 $outputlangs->loadLangs(array("main
", "dict
", "companies
", "projects
"));
545 if ($conf->project->dir_output) {
546 // If $object is id instead of object
547 if (!is_object($object)) {
549 $object = new Project($this->db);
550 $result = $object->fetch($id);
552 dol_print_error($this->db, $object->error);
557 $object->fetch_thirdparty();
559 $dir = $conf->project->dir_output;
560 $objectref = dol_sanitizeFileName($object->ref);
561 if (!preg_match('/specimen/i', $objectref)) {
562 $dir .= "/
".$objectref;
564 $file = $dir."/
".$objectref.".odt
";
566 if (!file_exists($dir)) {
567 if (dol_mkdir($dir) < 0) {
568 $this->error = $langs->transnoentities("ErrorCanNotCreateDir
", $dir);
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';
588 $filename = $newfiletmp . '-' . dol_print_date(dol_now(), $format) . '.' . $newfileformat;
590 $filename = $newfiletmp . '.' . $newfileformat;
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;
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);
605 // If PROJECTLEADER contact defined on project, we use it
607 $arrayidcontact = $object->getIdContact('external', 'PROJECTLEADER');
608 if (count($arrayidcontact) > 0) {
610 $result = $object->fetch_contact($arrayidcontact[0]);
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;
620 $socobject = $object->thirdparty;
623 $substitutionarray = array(
624 '__FROM_NAME__' => $this->emetteur->name,
625 '__FROM_EMAIL__' => $this->emetteur->email,
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
632 // Open and load template
633 require_once ODTPHP_PATH.'odf.php';
635 $odfHandler = new Odf(
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' => '}'
644 } catch (Exception $e) {
645 $this->error = $e->getMessage();
646 dol_syslog($e->getMessage(), LOG_INFO);
649 // After construction $odfHandler->contentXml contains content and
650 // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
651 // [!-- BEGIN lines --]*[!-- END lines --]
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');
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);
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
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');
681 foreach ($tmparray as $key => $value) {
683 if (preg_match('/logo$/', $key)) { // Image
684 if (file_exists($value)) {
685 $odfHandler->setImage($key, $value, $ratio);
687 $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
690 $odfHandler->setVars($key, $value, true, 'UTF-8');
692 } catch (OdfException $e) {
693 dol_syslog($e->getMessage(), LOG_INFO);
697 // Replace tags of lines for tasks
698 $foundtagfortasks = 1;
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);
706 if ($foundtagfortasks && isset($listlines)) {
707 $taskstatic = new Task($this->db);
711 if (!empty($object->socid)) {
712 $socid = $object->socid;
715 $tasksarray = $taskstatic->getTasksArray(null, null, $object->id, $socid, 0);
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) {
723 $listlines->setVars($key, $val, true, 'UTF-8');
724 } catch (SegmentException $e) {
725 dol_syslog($e->getMessage(), LOG_INFO);
729 $taskobj = new Task($this->db);
730 $taskobj->fetch($task->id);
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);
741 if ((is_array($contact_arrray) && count($contact_arrray) > 0)) {
742 $foundtagfortasksressources = 1;
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);
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']);
760 $soc = new Societe($this->db);
761 $soc->fetch($contact['socid']);
762 $contact['socname'] = $soc->name;
764 dol_syslog(get_class().'::'.__METHOD__.' Unexpected contact source:'.$contact['source'], LOG_ERR);
767 $contact['fullname'] = $objectdetail->getFullName($outputlangs, 1);
769 $tmparray = $this->get_substitutionarray_tasksressource($contact, $outputlangs);
771 foreach ($tmparray as $key => $val) {
773 $listlinestaskres->setVars($key, $val, true, 'UTF-8');
774 } catch (SegmentException $e) {
775 dol_syslog($e->getMessage(), LOG_INFO);
778 $listlinestaskres->merge();
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
";
793 $resql = $this->db->query($sql);
795 $num = $this->db->num_rows($resql);
799 $foundtagfortaskstimes = 1;
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);
807 if ($foundtagfortaskstimes && isset($listlinestasktime)) {
810 $row['task_date'] = 0;
811 $row['task_duration'] = 0;
812 //$row['$tasktime'] = '';
816 $row['firstname'] = '';
817 $row['fullcivname'] = '';
818 $row['amountht'] = 0;
819 $row['amountttc'] = 0;
821 $tmparray = $this->get_substitutionarray_taskstime($row, $outputlangs);
822 foreach ($tmparray as $key => $val) {
824 $listlinestasktime->setVars($key, $val, true, 'UTF-8');
825 } catch (SegmentException $e) {
826 dol_syslog($e->getMessage(), LOG_INFO);
829 $listlinestasktime->merge();
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);
838 $row['fullcivname'] = '';
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');
846 $row['amountht'] = 0;
847 $row['amountttc'] = 0;
851 $tmparray = $this->get_substitutionarray_taskstime($row, $outputlangs); // @phpstan-ignore argument.type
853 foreach ($tmparray as $key => $val) {
855 $listlinestasktime->setVars($key, $val, true, 'UTF-8');
856 } catch (SegmentException $e) {
857 dol_syslog($e->getMessage(), LOG_INFO);
860 $listlinestasktime->merge();
864 $this->db->free($resql);
868 // Replace tags of project files
869 $foundtagfortasksfiles = 1;
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);
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);
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) {
887 $listtasksfiles->setVars($key, $val, true, 'UTF-8');
888 } catch (SegmentException $e) {
889 dol_syslog($e->getMessage(), LOG_INFO);
892 $listtasksfiles->merge();
898 $odfHandler->mergeSegment($listlines);
899 } catch (OdfException $e) {
900 $this->error = $e->getMessage();
901 dol_syslog($this->error, LOG_WARNING);
906 // Replace tags of project files
907 $foundtagforprojectfiles = 1;
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);
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);
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);
923 foreach ($tmparray as $key => $val) {
925 $listlines->setVars($key, $val, true, 'UTF-8');
926 } catch (SegmentException $e) {
927 dol_syslog($e->getMessage(), LOG_INFO);
933 $odfHandler->mergeSegment($listlines);
934 } catch (OdfException $e) {
935 $this->error = $e->getMessage();
936 dol_syslog($this->error, LOG_WARNING);
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);
950 if ((is_array($contact_arrray) && count($contact_arrray) > 0)) {
951 $foundtagforprojectcontacts = 1;
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);
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']);
970 $soc = new Societe($this->db);
971 $soc->fetch($contact['socid']);
972 $contact['socname'] = $soc->name;
974 dol_syslog('Unexpected contact source:'.$contact['source'].'.'. getCallerInfoString(), LOG_ERR);
977 $contact['fullname'] = $objectdetail->getFullName($outputlangs, 1);
979 $tmparray = $this->get_substitutionarray_project_contacts($contact, $outputlangs);
980 foreach ($tmparray as $key => $val) {
982 $listlines->setVars($key, $val, true, 'UTF-8');
983 } catch (SegmentException $e) {
984 dol_syslog($e->getMessage(), LOG_INFO);
990 $odfHandler->mergeSegment($listlines);
991 } catch (OdfException $e) {
992 $this->error = $e->getMessage();
993 dol_syslog($this->error, LOG_WARNING);
1001 $listofreferent = array(
1003 'title' => "ListProposalsAssociatedProject
",
1004 'class' => 'Propal',
1005 'table' => 'propal',
1006 'test' => isModEnabled('propal') && $user->hasRight('propal', 'lire')
1009 'title' => "ListOrdersAssociatedProject
",
1010 'class' => 'Commande',
1011 'table' => 'commande',
1012 'test' => isModEnabled('order') && $user->hasRight('commande', 'lire')
1015 'title' => "ListInvoicesAssociatedProject
",
1016 'class' => 'Facture',
1017 'table' => 'facture',
1018 'test' => isModEnabled('invoice') && $user->hasRight('facture', 'lire')
1020 'invoice_predefined' => array(
1021 'title' => "ListPredefinedInvoicesAssociatedProject
",
1022 'class' => 'FactureRec',
1023 'table' => 'facture_rec',
1024 'test' => isModEnabled('invoice') && $user->hasRight('facture', 'lire')
1026 'proposal_supplier' => array(
1027 'title' => "ListSupplierProposalsAssociatedProject
",
1028 'class' => 'SupplierProposal',
1029 'table' => 'supplier_proposal',
1030 'test' => isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire')
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'))
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'))
1044 'contract' => array(
1045 'title' => "ListContractAssociatedProject
",
1046 'class' => 'Contrat',
1047 'table' => 'contrat',
1048 'test' => isModEnabled('contract') && $user->hasRight('contrat', 'lire')
1050 'intervention' => array(
1051 'title' => "ListFichinterAssociatedProject
",
1052 'class' => 'Fichinter',
1053 'table' => 'fichinter',
1054 'disableamount' => 1,
1055 'test' => isModEnabled('intervention') && $user->hasRight('ficheinter', 'lire')
1057 'shipping' => array(
1058 'title' => "ListShippingAssociatedProject
",
1059 'class' => 'Expedition',
1060 'table' => 'expedition',
1061 'disableamount' => 1,
1062 'test' => isModEnabled('shipping') && $user->hasRight('expedition', 'lire')
1064 'expensereport' => array(
1065 'title' => "ListExpenseReportsAssociatedProject
",
1066 'class' => 'ExpenseReportLine',
1067 'table' => 'expensereport_det',
1068 'test' => isModEnabled('expensereport') && $user->hasRight('expensereport', 'lire')
1070 'donation' => array(
1071 'title' => "ListDonationsAssociatedProject
",
1074 'test' => isModEnabled('don') && $user->hasRight('don', 'lire')
1077 'title' => "ListLoanAssociatedProject
",
1080 'test' => isModEnabled('loan') && $user->hasRight('loan', 'read')
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')
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'))
1096 'title' => "ListActionsAssociatedProject
",
1097 'class' => 'ActionComm',
1098 'table' => 'actioncomm',
1099 'disableamount' => 1,
1100 'test' => isModEnabled('agenda') && $user->hasRight('agenda', 'allactions', 'lire')
1104 // Insert list of objects into the project
1105 $foundtagforprojectrefs = 1;
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);
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'];
1120 $elementarray = $object->get_element_list($keyref, $tablename);
1121 if (count($elementarray) > 0 && is_array($elementarray)) {
1124 $num = count($elementarray);
1125 for ($i = 0; $i < $num; $i++) {
1126 $ref_array = array();
1127 $ref_array['type'] = (string) $langs->trans($classname);
1129 $element = new $classname($this->db);
1130 $element->fetch((int) $elementarray[$i]);
1131 $element->fetch_thirdparty();
1134 $ref_array['ref'] = (string) $element->ref;
1137 $dateref = $element->date;
1138 if (empty($dateref)) {
1139 $dateref = $element->datep;
1141 if (empty($dateref)) {
1142 $dateref = $element->date_contrat;
1144 $ref_array['date'] = (string) $dateref;
1147 if (is_object($element->thirdparty)) {
1148 $ref_array['socname'] = $element->thirdparty->name;
1150 $ref_array['socname'] = '';
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;
1159 $ref_array['amountht'] = 0;
1160 $ref_array['amountttc'] = 0;
1163 $ref_array['amountht'] = '';
1164 $ref_array['amountttc'] = '';
1167 $ref_array['status'] = method_exists($element, 'getLibStatut') ? $element->getLibStatut(0) : '';
1169 $tmparray = $this->get_substitutionarray_project_reference($ref_array, $outputlangs);
1171 foreach ($tmparray as $key => $val) {
1173 $listlines->setVars($key, $val, true, 'UTF-8');
1174 } catch (SegmentException $e) {
1175 dol_syslog($e->getMessage(), LOG_INFO);
1178 $listlines->merge();
1183 $odfHandler->mergeSegment($listlines);
1184 } catch (OdfException $e) {
1185 $this->error = $e->getMessage();
1186 dol_syslog($this->error, LOG_WARNING);
1192 // Replace labels translated
1193 $tmparray = $outputlangs->get_translations_for_substitutions();
1194 foreach ($tmparray as $key => $value) {
1196 $odfHandler->setVars($key, $value, true, 'UTF-8');
1197 } catch (OdfException $e) {
1198 dol_syslog($e->getMessage(), LOG_INFO);
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
1208 if (getDolGlobalString('MAIN_ODT_AS_PDF')) {
1210 $odfHandler->exportAsAttachedPDF($file);
1211 } catch (Exception $e) {
1212 $this->error = $e->getMessage();
1217 $odfHandler->saveToDisk($file);
1218 } catch (Exception $e) {
1219 $this->error = $e->getMessage();
1220 dol_syslog($e->getMessage(), LOG_INFO);
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
1229 $odfHandler = null; // Destroy object
1231 $this->result = array('fullpath' => $file);
1233 return 1; // Success
1235 $this->error = $langs->transnoentities("ErrorCanNotCreateDir
", $dir);
if(! $sortfield) if(! $sortorder) $object
$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:
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...
Parent class for projects models.
Class to manage projects.
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.
__construct($db)
Constructor.
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.
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
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.
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)
$conf db user
Active Directory does not allow anonymous connections.
$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