30 require_once DOL_DOCUMENT_ROOT.
'/core/modules/project/modules_project.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/modules/project/task/modules_task.php';
32 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/lib/doc.lib.php';
41 require_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';
49 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture-rec.class.php';
52 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
55 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
58 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
61 require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
64 require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
67 require_once DOL_DOCUMENT_ROOT.
'/compta/deplacement/class/deplacement.class.php';
70 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
89 public $version =
'dolibarr';
99 global $conf, $langs, $mysoc;
102 $langs->loadLangs(array(
"main",
"companies"));
105 $this->
name =
"ODT templates";
106 $this->
description = $langs->trans(
"DocumentModelOdt");
107 $this->scandir =
'PROJECT_TASK_ADDON_PDF_ODT_PATH';
111 $this->page_largeur = 0;
112 $this->page_hauteur = 0;
113 $this->format = array($this->page_largeur, $this->page_hauteur);
114 $this->marge_gauche = 0;
115 $this->marge_droite = 0;
116 $this->marge_haute = 0;
117 $this->marge_basse = 0;
119 $this->option_logo = 1;
120 $this->option_tva = 0;
121 $this->option_modereg = 0;
122 $this->option_condreg = 0;
123 $this->option_multilang = 0;
124 $this->option_escompte = 0;
125 $this->option_credit_note = 0;
126 $this->option_freetext = 1;
127 $this->option_draft_watermark = 0;
130 $this->emetteur = $mysoc;
131 if (!$this->emetteur->country_code) {
132 $this->emetteur->country_code = substr($langs->defaultlang, -2);
149 global $conf, $extrafields;
152 $array_key.
'_id'=>$object->id,
153 $array_key.
'_ref'=>$object->ref,
154 $array_key.
'_title'=>$object->title,
155 $array_key.
'_description'=>$object->description,
156 $array_key.
'_date_creation'=>
dol_print_date($object->date_c,
'day'),
157 $array_key.
'_date_modification'=>
dol_print_date($object->date_m,
'day'),
158 $array_key.
'_date_start'=>
dol_print_date($object->date_start,
'day'),
160 $array_key.
'_note_private'=>$object->note_private,
161 $array_key.
'_note_public'=>$object->note_public,
162 $array_key.
'_public'=>$object->public,
163 $array_key.
'_statut'=>$object->getLibStatut()
167 if (is_array($object->array_options) && count($object->array_options)) {
168 $object->fetch_optionals();
188 global $conf, $extrafields;
191 'task_ref'=>$task->ref,
192 'task_fk_project'=>$task->fk_project,
193 'task_projectref'=>$task->projectref,
194 'task_projectlabel'=>$task->projectlabel,
195 'task_label'=>$task->label,
196 'task_description'=>$task->description,
197 'task_fk_parent'=>$task->fk_task_parent,
198 'task_duration'=>$task->duration_effective,
200 'task_planned_workload'=>$task->planned_workload,
201 'task_planned_workload_formated'=>
convertSecondToTime($task->planned_workload,
'allhourmin'),
202 'task_progress'=>$task->progress,
203 'task_public'=>$task->public,
206 'task_note_private'=>$task->note_private,
207 'task_note_public'=>$task->note_public
211 if (is_array($task->array_options) && count($task->array_options)) {
212 $task->fetch_optionals();
234 'projcontacts_id'=>$contact[
'id'],
235 'projcontacts_rowid'=>$contact[
'rowid'],
236 'projcontacts_role'=>$contact[
'libelle'],
237 'projcontacts_lastname'=>$contact[
'lastname'],
238 'projcontacts_firstname'=>$contact[
'firstname'],
239 'projcontacts_fullcivname'=>$contact[
'fullname'],
240 'projcontacts_socname'=>$contact[
'socname'],
241 'projcontacts_email'=>$contact[
'email']
259 'projfile_name'=>$file[
'name'],
261 'projfile_size'=>$file[
'size']
279 'projref_type'=>$refdetail[
'type'],
280 'projref_ref'=>$refdetail[
'ref'],
282 'projref_socname'=>$refdetail[
'socname'],
283 'projref_amountht'=>
price($refdetail[
'amountht'], 0, $outputlangs),
284 'projref_amountttc'=>
price($refdetail[
'amountttc'], 0, $outputlangs),
285 'projref_status'=>$refdetail[
'status']
303 'taskressource_rowid'=>$taskressource[
'rowid'],
304 'taskressource_role'=>$taskressource[
'libelle'],
305 'taskressource_lastname'=>$taskressource[
'lastname'],
306 'taskressource_firstname'=>$taskressource[
'firstname'],
307 'taskressource_fullcivname'=>$taskressource[
'fullname'],
308 'taskressource_socname'=>$taskressource[
'socname'],
309 'taskressource_email'=>$taskressource[
'email']
327 'tasktime_rowid'=>$tasktime[
'rowid'],
328 'tasktime_task_date'=>
dol_print_date($tasktime[
'task_date'],
'day'),
330 'tasktime_note'=>$tasktime[
'note'],
331 'tasktime_fk_user'=>$tasktime[
'fk_user'],
332 'tasktime_user_name'=>$tasktime[
'name'],
333 'tasktime_user_first'=>$tasktime[
'firstname'],
334 'tasktime_fullcivname'=>$tasktime[
'fullcivname']
352 'tasksfile_name'=>$file[
'name'],
354 'tasksfile_size'=>$file[
'size']
367 global $conf, $langs;
370 $langs->loadLangs(array(
"errors",
"companies"));
375 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
376 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
377 $texte .=
'<input type="hidden" name="page_y" value="">';
378 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
379 $texte .=
'<input type="hidden" name="param1" value="PROJECT_TASK_ADDON_PDF_ODT_PATH">';
380 $texte .=
'<table class="nobordernopadding" width="100%">';
383 $texte .=
'<tr><td>';
384 $texttitle = $langs->trans(
"ListOfDirectories");
385 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim($conf->global->PROJECT_TASK_ADDON_PDF_ODT_PATH)));
386 $listoffiles = array();
387 foreach ($listofdir as $key => $tmpdir) {
388 $tmpdir = trim($tmpdir);
389 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
391 unset($listofdir[$key]);
394 if (!is_dir($tmpdir)) {
395 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir), 0);
397 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
398 if (count($tmpfiles)) {
399 $listoffiles = array_merge($listoffiles, $tmpfiles);
403 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
405 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
406 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
408 $texte .=
$form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1);
409 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
410 $texte .=
'<textarea class="flat" cols="60" name="value1">';
411 $texte .= $conf->global->PROJECT_TASK_ADDON_PDF_ODT_PATH;
412 $texte .=
'</textarea>';
413 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
414 $texte .=
'<input type="submit" class="button small reposition" name="modify" value="'.$langs->trans(
"Modify").
'">';
415 $texte .=
'<br></div></div>';
418 $nbofiles = count($listoffiles);
419 if (!empty($conf->global->PROJECT_TASK_ADDON_PDF_ODT_PATH)) {
420 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
428 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
430 foreach ($listoffiles as $file) {
431 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=tasks/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
432 $texte .=
' <a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?modulepart=doctemplates&keyforuploaddir=PROJECT_TASK_ADDON_PDF_ODT_PATH&action=deletefile&token='.
newToken().
'&file='.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'delete').
'</a>';
440 $texte .=
'<td rowspan="2" class="tdtop hideonsmartphone">';
441 $texte .=
'<span class="opacitymedium">';
442 $texte .= $langs->trans(
"ExampleOfDirectoriesForModelGen");
447 $texte .=
'</table>';
462 public function write_file($object, $outputlangs, $srctemplatepath)
465 global $user, $langs, $conf, $mysoc, $hookmanager;
467 if (empty($srctemplatepath)) {
468 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
472 if (!is_object($outputlangs)) {
473 $outputlangs = $langs;
475 $sav_charset_output = $outputlangs->charset_output;
476 $outputlangs->charset_output =
'UTF-8';
479 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
481 if ($conf->project->dir_output) {
483 if (!is_object($object)) {
485 $object =
new Task($this->db);
486 $result = $object->fetch($id);
492 $project =
new Project($this->db);
493 $project->fetch($object->fk_project);
494 $project->fetch_thirdparty();
496 $dir = $conf->project->dir_output.
"/".$project->ref.
"/";
498 if (!preg_match(
'/specimen/i', $objectref)) {
499 $dir .=
"/".$objectref;
501 $file = $dir.
"/".$objectref.
".odt";
503 if (!file_exists($dir)) {
505 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
511 if (file_exists($dir)) {
513 $newfile = basename($srctemplatepath);
514 $newfiletmp = preg_replace(
'/\.(ods|odt)/i',
'', $newfile);
515 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
516 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
517 $newfiletmp = $objectref .
'_' . $newfiletmp;
519 $file = $dir .
'/' . $newfiletmp .
'.odt';
526 if (!is_writable($conf->project->dir_temp)) {
527 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->project->dir_temp);
528 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
532 $socobject = $project->thirdparty;
535 $substitutionarray = array(
536 '__FROM_NAME__' => $this->emetteur->name,
537 '__FROM_EMAIL__' => $this->emetteur->email,
541 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
542 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
545 require_once ODTPHP_PATH.
'odf.php';
547 $odfHandler =
new Odf(
550 'PATH_TO_TMP' => $conf->project->dir_temp,
551 'ZIP_PROXY' =>
'PclZipProxy',
552 'DELIMITER_LEFT' =>
'{',
553 'DELIMITER_RIGHT' =>
'}'
557 $this->error = $e->getMessage();
576 $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other);
579 foreach ($tmparray as $key => $value) {
581 if (preg_match(
'/logo$/', $key)) {
582 if (file_exists($value)) {
583 $odfHandler->setImage($key, $value);
585 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
589 $odfHandler->setVars($key, $value,
true,
'UTF-8');
591 }
catch (OdfException $e) {
600 if (!empty($project->fk_soc)) {
601 $socid = $project->fk_soc;
606 foreach ($tmparray as $key => $val) {
608 $odfHandler->setVars($key, $val,
true,
'UTF-8');
609 }
catch (OdfException $e) {
611 }
catch (SegmentException $e) {
617 $sourcearray = array(
'internal',
'external');
618 $contact_arrray = array();
619 foreach ($sourcearray as $source) {
620 $contact_temp = $object->liste_contact(-1, $source);
621 if ((is_array($contact_temp) && count($contact_temp) > 0)) {
622 $contact_arrray = array_merge($contact_arrray, $contact_temp);
625 if ((is_array($contact_arrray) && count($contact_arrray) > 0)) {
626 $listlinestaskres = $odfHandler->setSegment(
'tasksressources');
628 foreach ($contact_arrray as $contact) {
629 if ($contact[
'source'] ==
'internal') {
630 $objectdetail =
new User($this->db);
631 $objectdetail->fetch($contact[
'id']);
632 $contact[
'socname'] = $mysoc->name;
633 } elseif ($contact[
'source'] ==
'external') {
634 $objectdetail =
new Contact($this->db);
635 $objectdetail->fetch($contact[
'id']);
638 $soc->fetch($contact[
'socid']);
639 $contact[
'socname'] = $soc->name;
641 $contact[
'fullname'] = $objectdetail->getFullName($outputlangs, 1);
645 foreach ($tmparray as $key => $val) {
647 $listlinestaskres->setVars($key, $val,
true,
'UTF-8');
648 }
catch (OdfException $e) {
650 }
catch (SegmentException $e) {
654 $listlinestaskres->merge();
656 $odfHandler->mergeSegment($listlinestaskres);
660 $sql =
"SELECT t.rowid, t.element_date as task_date, t.element_duration as task_duration, t.fk_user, t.note";
661 $sql .=
", u.lastname, u.firstname";
662 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time as t";
663 $sql .=
" , ".MAIN_DB_PREFIX.
"user as u";
664 $sql .=
" WHERE t.fk_element =".((int) $object->id);
665 $sql .=
" AND t.elementtype = 'task'";
666 $sql .=
" AND t.fk_user = u.rowid";
667 $sql .=
" ORDER BY t.element_date DESC";
669 $resql = $this->db->query(
$sql);
671 $num = $this->db->num_rows($resql);
674 $listlinestasktime = $odfHandler->setSegment(
'taskstimes');
676 $row = $this->db->fetch_array($resql);
677 if (!empty($row[
'fk_user'])) {
678 $objectdetail =
new User($this->db);
679 $objectdetail->fetch($row[
'fk_user']);
681 $row[
'fullcivname'] = $objectdetail->getFullName($outputlangs, 1);
683 $row[
'fullcivname'] =
'';
688 foreach ($tmparray as $key => $val) {
690 $listlinestasktime->setVars($key, $val,
true,
'UTF-8');
691 }
catch (OdfException $e) {
693 }
catch (SegmentException $e) {
697 $listlinestasktime->merge();
700 $this->db->free($resql);
702 $odfHandler->mergeSegment($listlinestasktime);
707 $listtasksfiles = $odfHandler->setSegment(
'tasksfiles');
710 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$',
'name', SORT_ASC, 1);
713 foreach ($filearray as $filedetail) {
716 foreach ($tmparray as $key => $val) {
718 $listtasksfiles->setVars($key, $val,
true,
'UTF-8');
719 }
catch (OdfException $e) {
721 }
catch (SegmentException $e) {
725 $listtasksfiles->merge();
729 $odfHandler->mergeSegment($listtasksfiles);
730 }
catch (OdfException $e) {
731 $this->error = $e->getMessage();
740 $listlines = $odfHandler->setSegment(
'projectfiles');
743 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$',
'name', SORT_ASC, 1);
746 foreach ($filearray as $filedetail) {
750 foreach ($tmparray as $key => $val) {
752 $listlines->setVars($key, $val,
true,
'UTF-8');
753 }
catch (OdfException $e) {
755 }
catch (SegmentException $e) {
761 $odfHandler->mergeSegment($listlines);
762 }
catch (OdfException $e) {
763 $this->error = $e->getMessage();
769 $sourcearray = array(
'internal',
'external');
770 $contact_arrray = array();
771 foreach ($sourcearray as $source) {
772 $contact_temp = $project->liste_contact(-1, $source);
773 if ((is_array($contact_temp) && count($contact_temp) > 0)) {
774 $contact_arrray = array_merge($contact_arrray, $contact_temp);
777 if ((is_array($contact_arrray) && count($contact_arrray) > 0)) {
779 $listlines = $odfHandler->setSegment(
'projectcontacts');
781 foreach ($contact_arrray as $contact) {
782 if ($contact[
'source'] ==
'internal') {
783 $objectdetail =
new User($this->db);
784 $objectdetail->fetch($contact[
'id']);
785 $contact[
'socname'] = $mysoc->name;
786 } elseif ($contact[
'source'] ==
'external') {
787 $objectdetail =
new Contact($this->db);
788 $objectdetail->fetch($contact[
'id']);
791 $soc->fetch($contact[
'socid']);
792 $contact[
'socname'] = $soc->name;
794 $contact[
'fullname'] = $objectdetail->getFullName($outputlangs, 1);
798 foreach ($tmparray as $key => $val) {
800 $listlines->setVars($key, $val,
true,
'UTF-8');
801 }
catch (OdfException $e) {
803 }
catch (SegmentException $e) {
809 $odfHandler->mergeSegment($listlines);
810 }
catch (OdfException $e) {
811 $this->error = $e->getMessage();
819 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
820 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
824 if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
826 $odfHandler->exportAsAttachedPDF($file);
828 $this->error = $e->getMessage();
834 $odfHandler->saveToDisk($file);
836 $this->error = $e->getMessage();
841 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
842 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
848 $this->result = array(
'fullpath'=>$file);
852 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);