29 require_once DOL_DOCUMENT_ROOT.
'/core/modules/project/modules_project.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/modules/project/task/modules_task.php';
31 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/lib/doc.lib.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
41 if (!empty($conf->propal->enabled)) {
42 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
48 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture-rec.class.php';
50 if (!empty($conf->commande->enabled)) {
51 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
53 if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_invoice->enabled)) {
54 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
56 if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled)) {
57 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
59 if (!empty($conf->contrat->enabled)) {
60 require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
62 if (!empty($conf->ficheinter->enabled)) {
63 require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
65 if (!empty($conf->deplacement->enabled)) {
66 require_once DOL_DOCUMENT_ROOT.
'/compta/deplacement/class/deplacement.class.php';
69 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
88 public $phpmin = array(5, 6);
94 public $version =
'dolibarr';
104 global $conf, $langs, $mysoc;
107 $langs->loadLangs(array(
"main",
"companies"));
110 $this->
name =
"ODT templates";
111 $this->
description = $langs->trans(
"DocumentModelOdt");
112 $this->scandir =
'PROJECT_TASK_ADDON_PDF_ODT_PATH';
116 $this->page_largeur = 0;
117 $this->page_hauteur = 0;
118 $this->format = array($this->page_largeur, $this->page_hauteur);
119 $this->marge_gauche = 0;
120 $this->marge_droite = 0;
121 $this->marge_haute = 0;
122 $this->marge_basse = 0;
124 $this->option_logo = 1;
125 $this->option_tva = 0;
126 $this->option_modereg = 0;
127 $this->option_condreg = 0;
128 $this->option_multilang = 0;
129 $this->option_escompte = 0;
130 $this->option_credit_note = 0;
131 $this->option_freetext = 1;
132 $this->option_draft_watermark = 0;
135 $this->emetteur = $mysoc;
136 if (!$this->emetteur->country_code) {
137 $this->emetteur->country_code = substr($langs->defaultlang, -2);
154 global $conf, $extrafields;
157 $array_key.
'_id'=>$object->id,
158 $array_key.
'_ref'=>$object->ref,
159 $array_key.
'_title'=>$object->title,
160 $array_key.
'_description'=>$object->description,
161 $array_key.
'_date_creation'=>
dol_print_date($object->date_c,
'day'),
162 $array_key.
'_date_modification'=>
dol_print_date($object->date_m,
'day'),
163 $array_key.
'_date_start'=>
dol_print_date($object->date_start,
'day'),
165 $array_key.
'_note_private'=>$object->note_private,
166 $array_key.
'_note_public'=>$object->note_public,
167 $array_key.
'_public'=>$object->public,
168 $array_key.
'_statut'=>$object->getLibStatut()
172 if (is_array($object->array_options) && count($object->array_options)) {
173 $object->fetch_optionals();
193 global $conf, $extrafields;
196 'task_ref'=>$task->ref,
197 'task_fk_project'=>$task->fk_project,
198 'task_projectref'=>$task->projectref,
199 'task_projectlabel'=>$task->projectlabel,
200 'task_label'=>$task->label,
201 'task_description'=>$task->description,
202 'task_fk_parent'=>$task->fk_parent,
203 'task_duration'=>$task->duration_effective,
205 'task_planned_workload'=>$task->planned_workload,
206 'task_planned_workload_formated'=>
convertSecondToTime($task->planned_workload,
'allhourmin'),
207 'task_progress'=>$task->progress,
208 'task_public'=>$task->public,
211 'task_note_private'=>$task->note_private,
212 'task_note_public'=>$task->note_public
216 if (is_array($task->array_options) && count($task->array_options)) {
217 $task->fetch_optionals();
239 'projcontacts_id'=>$contact[
'id'],
240 'projcontacts_rowid'=>$contact[
'rowid'],
241 'projcontacts_role'=>$contact[
'libelle'],
242 'projcontacts_lastname'=>$contact[
'lastname'],
243 'projcontacts_firstname'=>$contact[
'firstname'],
244 'projcontacts_fullcivname'=>$contact[
'fullname'],
245 'projcontacts_socname'=>$contact[
'socname'],
246 'projcontacts_email'=>$contact[
'email']
264 'projfile_name'=>$file[
'name'],
266 'projfile_size'=>$file[
'size']
284 'projref_type'=>$refdetail[
'type'],
285 'projref_ref'=>$refdetail[
'ref'],
287 'projref_socname'=>$refdetail[
'socname'],
288 'projref_amountht'=>
price($refdetail[
'amountht'], 0, $outputlangs),
289 'projref_amountttc'=>
price($refdetail[
'amountttc'], 0, $outputlangs),
290 'projref_status'=>$refdetail[
'status']
308 'taskressource_rowid'=>$taskressource[
'rowid'],
309 'taskressource_role'=>$taskressource[
'libelle'],
310 'taskressource_lastname'=>$taskressource[
'lastname'],
311 'taskressource_firstname'=>$taskressource[
'firstname'],
312 'taskressource_fullcivname'=>$taskressource[
'fullname'],
313 'taskressource_socname'=>$taskressource[
'socname'],
314 'taskressource_email'=>$taskressource[
'email']
332 'tasktime_rowid'=>$tasktime[
'rowid'],
333 'tasktime_task_date'=>
dol_print_date($tasktime[
'task_date'],
'day'),
335 'tasktime_note'=>$tasktime[
'note'],
336 'tasktime_fk_user'=>$tasktime[
'fk_user'],
337 'tasktime_user_name'=>$tasktime[
'name'],
338 'tasktime_user_first'=>$tasktime[
'firstname'],
339 'tasktime_fullcivname'=>$tasktime[
'fullcivname']
357 'tasksfile_name'=>$file[
'name'],
359 'tasksfile_size'=>$file[
'size']
372 global $conf, $langs;
375 $langs->loadLangs(array(
"errors",
"companies"));
380 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
381 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
382 $texte .=
'<input type="hidden" name="page_y" value="">';
383 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
384 $texte .=
'<input type="hidden" name="param1" value="PROJECT_TASK_ADDON_PDF_ODT_PATH">';
385 $texte .=
'<table class="nobordernopadding" width="100%">';
388 $texte .=
'<tr><td>';
389 $texttitle = $langs->trans(
"ListOfDirectories");
390 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim($conf->global->PROJECT_TASK_ADDON_PDF_ODT_PATH)));
391 $listoffiles = array();
392 foreach ($listofdir as $key => $tmpdir) {
393 $tmpdir = trim($tmpdir);
394 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
396 unset($listofdir[$key]);
399 if (!is_dir($tmpdir)) {
400 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir), 0);
402 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
403 if (count($tmpfiles)) {
404 $listoffiles = array_merge($listoffiles, $tmpfiles);
408 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
410 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
411 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
413 $texte .=
$form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1);
414 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
415 $texte .=
'<textarea class="flat" cols="60" name="value1">';
416 $texte .= $conf->global->PROJECT_TASK_ADDON_PDF_ODT_PATH;
417 $texte .=
'</textarea>';
418 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
419 $texte .=
'<input type="submit" class="button small reposition" name="modify" value="'.$langs->trans(
"Modify").
'">';
420 $texte .=
'<br></div></div>';
423 $nbofiles = count($listoffiles);
424 if (!empty($conf->global->PROJECT_TASK_ADDON_PDF_ODT_PATH)) {
425 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
433 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
435 foreach ($listoffiles as $file) {
436 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=tasks/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a><br>';
443 $texte .=
'<td rowspan="2" class="tdtop hideonsmartphone">';
444 $texte .=
'<span class="opacitymedium">';
445 $texte .= $langs->trans(
"ExampleOfDirectoriesForModelGen");
450 $texte .=
'</table>';
465 public function write_file($object, $outputlangs, $srctemplatepath)
468 global $user, $langs, $conf, $mysoc, $hookmanager;
470 if (empty($srctemplatepath)) {
471 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
475 if (!is_object($outputlangs)) {
476 $outputlangs = $langs;
478 $sav_charset_output = $outputlangs->charset_output;
479 $outputlangs->charset_output =
'UTF-8';
482 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
484 if ($conf->project->dir_output) {
486 if (!is_object($object)) {
488 $object =
new Task($this->
db);
489 $result = $object->fetch($id);
496 $project->fetch($object->fk_project);
497 $project->fetch_thirdparty();
499 $dir = $conf->project->dir_output.
"/".$project->ref.
"/";
501 if (!preg_match(
'/specimen/i', $objectref)) {
502 $dir .=
"/".$objectref;
504 $file = $dir.
"/".$objectref.
".odt";
506 if (!file_exists($dir)) {
508 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
514 if (file_exists($dir)) {
516 $newfile = basename($srctemplatepath);
517 $newfiletmp = preg_replace(
'/\.(ods|odt)/i',
'', $newfile);
518 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
519 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
520 $newfiletmp = $objectref.
'_'.$newfiletmp;
522 $file = $dir.
'/'.$newfiletmp.
'.odt';
529 if (!is_writable($conf->project->dir_temp)) {
530 $this->error =
"Failed to write in temp directory ".$conf->project->dir_temp;
531 dol_syslog(
'Error in write_file: '.$this->error, LOG_ERR);
535 $socobject = $project->thirdparty;
538 $substitutionarray = array(
539 '__FROM_NAME__' => $this->emetteur->name,
540 '__FROM_EMAIL__' => $this->emetteur->email,
544 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
545 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
548 require_once ODTPHP_PATH.
'odf.php';
550 $odfHandler =
new odf(
553 'PATH_TO_TMP' => $conf->project->dir_temp,
554 'ZIP_PROXY' =>
'PclZipProxy',
555 'DELIMITER_LEFT' =>
'{',
556 'DELIMITER_RIGHT' =>
'}'
560 $this->error = $e->getMessage();
579 $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other);
582 foreach ($tmparray as $key => $value) {
584 if (preg_match(
'/logo$/', $key)) {
585 if (file_exists($value)) {
586 $odfHandler->setImage($key, $value);
588 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
592 $odfHandler->setVars($key, $value,
true,
'UTF-8');
594 }
catch (OdfException $e) {
603 if (!empty($project->fk_soc)) {
604 $socid = $project->fk_soc;
609 foreach ($tmparray as $key => $val) {
611 $odfHandler->setVars($key, $val,
true,
'UTF-8');
612 }
catch (OdfException $e) {
614 }
catch (SegmentException $e) {
620 $sourcearray = array(
'internal',
'external');
621 $contact_arrray = array();
622 foreach ($sourcearray as $source) {
623 $contact_temp = $object->liste_contact(-1, $source);
624 if ((is_array($contact_temp) && count($contact_temp) > 0)) {
625 $contact_arrray = array_merge($contact_arrray, $contact_temp);
628 if ((is_array($contact_arrray) && count($contact_arrray) > 0)) {
629 $listlinestaskres = $odfHandler->setSegment(
'tasksressources');
631 foreach ($contact_arrray as $contact) {
632 if ($contact[
'source'] ==
'internal') {
633 $objectdetail =
new User($this->
db);
634 $objectdetail->fetch($contact[
'id']);
635 $contact[
'socname'] = $mysoc->name;
636 } elseif ($contact[
'source'] ==
'external') {
638 $objectdetail->fetch($contact[
'id']);
641 $soc->fetch($contact[
'socid']);
642 $contact[
'socname'] = $soc->name;
644 $contact[
'fullname'] = $objectdetail->getFullName($outputlangs, 1);
648 foreach ($tmparray as $key => $val) {
650 $listlinestaskres->setVars($key, $val,
true,
'UTF-8');
651 }
catch (OdfException $e) {
653 }
catch (SegmentException $e) {
657 $listlinestaskres->merge();
659 $odfHandler->mergeSegment($listlinestaskres);
663 $sql =
"SELECT t.rowid, t.task_date, t.task_duration, t.fk_user, t.note";
664 $sql .=
", u.lastname, u.firstname";
665 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as t";
666 $sql .=
" , ".MAIN_DB_PREFIX.
"user as u";
667 $sql .=
" WHERE t.fk_task =".((int) $object->id);
668 $sql .=
" AND t.fk_user = u.rowid";
669 $sql .=
" ORDER BY t.task_date DESC";
676 $listlinestasktime = $odfHandler->setSegment(
'taskstimes');
678 $row = $this->
db->fetch_array(
$resql);
679 if (!empty($row[
'fk_user'])) {
680 $objectdetail =
new User($this->
db);
681 $objectdetail->fetch($row[
'fk_user']);
683 $row[
'fullcivname'] = $objectdetail->getFullName($outputlangs, 1);
685 $row[
'fullcivname'] =
'';
690 foreach ($tmparray as $key => $val) {
692 $listlinestasktime->setVars($key, $val,
true,
'UTF-8');
693 }
catch (OdfException $e) {
695 }
catch (SegmentException $e) {
699 $listlinestasktime->merge();
704 $odfHandler->mergeSegment($listlinestasktime);
709 $listtasksfiles = $odfHandler->setSegment(
'tasksfiles');
712 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$',
'name', SORT_ASC, 1);
715 foreach ($filearray as $filedetail) {
718 foreach ($tmparray as $key => $val) {
720 $listtasksfiles->setVars($key, $val,
true,
'UTF-8');
721 }
catch (OdfException $e) {
723 }
catch (SegmentException $e) {
727 $listtasksfiles->merge();
731 $odfHandler->mergeSegment($listtasksfiles);
732 }
catch (OdfException $e) {
733 $this->error = $e->getMessage();
742 $listlines = $odfHandler->setSegment(
'projectfiles');
745 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$',
'name', SORT_ASC, 1);
748 foreach ($filearray as $filedetail) {
752 foreach ($tmparray as $key => $val) {
754 $listlines->setVars($key, $val,
true,
'UTF-8');
755 }
catch (OdfException $e) {
757 }
catch (SegmentException $e) {
763 $odfHandler->mergeSegment($listlines);
764 }
catch (OdfException $e) {
765 $this->error = $e->getMessage();
771 $sourcearray = array(
'internal',
'external');
772 $contact_arrray = array();
773 foreach ($sourcearray as $source) {
774 $contact_temp = $project->liste_contact(-1, $source);
775 if ((is_array($contact_temp) && count($contact_temp) > 0)) {
776 $contact_arrray = array_merge($contact_arrray, $contact_temp);
779 if ((is_array($contact_arrray) && count($contact_arrray) > 0)) {
781 $listlines = $odfHandler->setSegment(
'projectcontacts');
783 foreach ($contact_arrray as $contact) {
784 if ($contact[
'source'] ==
'internal') {
785 $objectdetail =
new User($this->
db);
786 $objectdetail->fetch($contact[
'id']);
787 $contact[
'socname'] = $mysoc->name;
788 } elseif ($contact[
'source'] ==
'external') {
790 $objectdetail->fetch($contact[
'id']);
793 $soc->fetch($contact[
'socid']);
794 $contact[
'socname'] = $soc->name;
796 $contact[
'fullname'] = $objectdetail->getFullName($outputlangs, 1);
800 foreach ($tmparray as $key => $val) {
802 $listlines->setVars($key, $val,
true,
'UTF-8');
803 }
catch (OdfException $e) {
805 }
catch (SegmentException $e) {
811 $odfHandler->mergeSegment($listlines);
812 }
catch (OdfException $e) {
813 $this->error = $e->getMessage();
821 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
822 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
826 if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
828 $odfHandler->exportAsAttachedPDF($file);
830 $this->error = $e->getMessage();
836 $odfHandler->saveToDisk($file);
838 $this->error = $e->getMessage();
843 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
844 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
846 if (!empty($conf->global->MAIN_UMASK)) {
847 @chmod($file, octdec($conf->global->MAIN_UMASK));
852 $this->result = array(
'fullpath'=>$file);
856 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);