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';
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';
51 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
53 if ((
isModEnabled(
"fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) ||
isModEnabled(
"supplier_invoice")) {
54 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
56 if ((
isModEnabled(
"fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) ||
isModEnabled(
"supplier_order")) {
57 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
60 require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
63 require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
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(7, 0);
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>';
437 $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>';
445 $texte .=
'<td rowspan="2" class="tdtop hideonsmartphone">';
446 $texte .=
'<span class="opacitymedium">';
447 $texte .= $langs->trans(
"ExampleOfDirectoriesForModelGen");
452 $texte .=
'</table>';
467 public function write_file($object, $outputlangs, $srctemplatepath)
470 global $user, $langs, $conf, $mysoc, $hookmanager;
472 if (empty($srctemplatepath)) {
473 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
477 if (!is_object($outputlangs)) {
478 $outputlangs = $langs;
480 $sav_charset_output = $outputlangs->charset_output;
481 $outputlangs->charset_output =
'UTF-8';
484 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
486 if ($conf->project->dir_output) {
488 if (!is_object($object)) {
490 $object =
new Task($this->
db);
491 $result = $object->fetch($id);
498 $project->fetch($object->fk_project);
499 $project->fetch_thirdparty();
501 $dir = $conf->project->dir_output.
"/".$project->ref.
"/";
503 if (!preg_match(
'/specimen/i', $objectref)) {
504 $dir .=
"/".$objectref;
506 $file = $dir.
"/".$objectref.
".odt";
508 if (!file_exists($dir)) {
510 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
516 if (file_exists($dir)) {
518 $newfile = basename($srctemplatepath);
519 $newfiletmp = preg_replace(
'/\.(ods|odt)/i',
'', $newfile);
520 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
521 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
522 $newfiletmp = $objectref .
'_' . $newfiletmp;
524 $file = $dir .
'/' . $newfiletmp .
'.odt';
531 if (!is_writable($conf->project->dir_temp)) {
532 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->project->dir_temp);
533 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
537 $socobject = $project->thirdparty;
540 $substitutionarray = array(
541 '__FROM_NAME__' => $this->emetteur->name,
542 '__FROM_EMAIL__' => $this->emetteur->email,
546 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
547 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
550 require_once ODTPHP_PATH.
'odf.php';
552 $odfHandler =
new odf(
555 'PATH_TO_TMP' => $conf->project->dir_temp,
556 'ZIP_PROXY' =>
'PclZipProxy',
557 'DELIMITER_LEFT' =>
'{',
558 'DELIMITER_RIGHT' =>
'}'
562 $this->error = $e->getMessage();
581 $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other);
584 foreach ($tmparray as $key => $value) {
586 if (preg_match(
'/logo$/', $key)) {
587 if (file_exists($value)) {
588 $odfHandler->setImage($key, $value);
590 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
594 $odfHandler->setVars($key, $value,
true,
'UTF-8');
596 }
catch (OdfException $e) {
605 if (!empty($project->fk_soc)) {
606 $socid = $project->fk_soc;
611 foreach ($tmparray as $key => $val) {
613 $odfHandler->setVars($key, $val,
true,
'UTF-8');
614 }
catch (OdfException $e) {
616 }
catch (SegmentException $e) {
622 $sourcearray = array(
'internal',
'external');
623 $contact_arrray = array();
624 foreach ($sourcearray as $source) {
625 $contact_temp = $object->liste_contact(-1, $source);
626 if ((is_array($contact_temp) && count($contact_temp) > 0)) {
627 $contact_arrray = array_merge($contact_arrray, $contact_temp);
630 if ((is_array($contact_arrray) && count($contact_arrray) > 0)) {
631 $listlinestaskres = $odfHandler->setSegment(
'tasksressources');
633 foreach ($contact_arrray as $contact) {
634 if ($contact[
'source'] ==
'internal') {
635 $objectdetail =
new User($this->
db);
636 $objectdetail->fetch($contact[
'id']);
637 $contact[
'socname'] = $mysoc->name;
638 } elseif ($contact[
'source'] ==
'external') {
640 $objectdetail->fetch($contact[
'id']);
643 $soc->fetch($contact[
'socid']);
644 $contact[
'socname'] = $soc->name;
646 $contact[
'fullname'] = $objectdetail->getFullName($outputlangs, 1);
650 foreach ($tmparray as $key => $val) {
652 $listlinestaskres->setVars($key, $val,
true,
'UTF-8');
653 }
catch (OdfException $e) {
655 }
catch (SegmentException $e) {
659 $listlinestaskres->merge();
661 $odfHandler->mergeSegment($listlinestaskres);
665 $sql =
"SELECT t.rowid, t.task_date, t.task_duration, t.fk_user, t.note";
666 $sql .=
", u.lastname, u.firstname";
667 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as t";
668 $sql .=
" , ".MAIN_DB_PREFIX.
"user as u";
669 $sql .=
" WHERE t.fk_task =".((int) $object->id);
670 $sql .=
" AND t.fk_user = u.rowid";
671 $sql .=
" ORDER BY t.task_date DESC";
673 $resql = $this->
db->query(
$sql);
675 $num = $this->
db->num_rows($resql);
678 $listlinestasktime = $odfHandler->setSegment(
'taskstimes');
680 $row = $this->
db->fetch_array($resql);
681 if (!empty($row[
'fk_user'])) {
682 $objectdetail =
new User($this->
db);
683 $objectdetail->fetch($row[
'fk_user']);
685 $row[
'fullcivname'] = $objectdetail->getFullName($outputlangs, 1);
687 $row[
'fullcivname'] =
'';
692 foreach ($tmparray as $key => $val) {
694 $listlinestasktime->setVars($key, $val,
true,
'UTF-8');
695 }
catch (OdfException $e) {
697 }
catch (SegmentException $e) {
701 $listlinestasktime->merge();
704 $this->
db->free($resql);
706 $odfHandler->mergeSegment($listlinestasktime);
711 $listtasksfiles = $odfHandler->setSegment(
'tasksfiles');
714 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$',
'name', SORT_ASC, 1);
717 foreach ($filearray as $filedetail) {
720 foreach ($tmparray as $key => $val) {
722 $listtasksfiles->setVars($key, $val,
true,
'UTF-8');
723 }
catch (OdfException $e) {
725 }
catch (SegmentException $e) {
729 $listtasksfiles->merge();
733 $odfHandler->mergeSegment($listtasksfiles);
734 }
catch (OdfException $e) {
735 $this->error = $e->getMessage();
744 $listlines = $odfHandler->setSegment(
'projectfiles');
747 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$',
'name', SORT_ASC, 1);
750 foreach ($filearray as $filedetail) {
754 foreach ($tmparray as $key => $val) {
756 $listlines->setVars($key, $val,
true,
'UTF-8');
757 }
catch (OdfException $e) {
759 }
catch (SegmentException $e) {
765 $odfHandler->mergeSegment($listlines);
766 }
catch (OdfException $e) {
767 $this->error = $e->getMessage();
773 $sourcearray = array(
'internal',
'external');
774 $contact_arrray = array();
775 foreach ($sourcearray as $source) {
776 $contact_temp = $project->liste_contact(-1, $source);
777 if ((is_array($contact_temp) && count($contact_temp) > 0)) {
778 $contact_arrray = array_merge($contact_arrray, $contact_temp);
781 if ((is_array($contact_arrray) && count($contact_arrray) > 0)) {
783 $listlines = $odfHandler->setSegment(
'projectcontacts');
785 foreach ($contact_arrray as $contact) {
786 if ($contact[
'source'] ==
'internal') {
787 $objectdetail =
new User($this->
db);
788 $objectdetail->fetch($contact[
'id']);
789 $contact[
'socname'] = $mysoc->name;
790 } elseif ($contact[
'source'] ==
'external') {
792 $objectdetail->fetch($contact[
'id']);
795 $soc->fetch($contact[
'socid']);
796 $contact[
'socname'] = $soc->name;
798 $contact[
'fullname'] = $objectdetail->getFullName($outputlangs, 1);
802 foreach ($tmparray as $key => $val) {
804 $listlines->setVars($key, $val,
true,
'UTF-8');
805 }
catch (OdfException $e) {
807 }
catch (SegmentException $e) {
813 $odfHandler->mergeSegment($listlines);
814 }
catch (OdfException $e) {
815 $this->error = $e->getMessage();
823 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
824 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
828 if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
830 $odfHandler->exportAsAttachedPDF($file);
832 $this->error = $e->getMessage();
838 $odfHandler->saveToDisk($file);
840 $this->error = $e->getMessage();
845 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs,
'substitutionarray'=>&$tmparray);
846 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
852 $this->result = array(
'fullpath'=>$file);
856 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);