85 public $version =
'dolibarr';
95 global $langs, $mysoc;
98 $langs->loadLangs(array(
"main",
"companies"));
101 $this->
name =
"ODT templates";
102 $this->
description = $langs->trans(
"DocumentModelOdt");
103 $this->scandir =
'PROJECT_TASK_ADDON_PDF_ODT_PATH';
107 $this->page_largeur = 0;
108 $this->page_hauteur = 0;
109 $this->format = array($this->page_largeur, $this->page_hauteur);
110 $this->marge_gauche = 0;
111 $this->marge_droite = 0;
112 $this->marge_haute = 0;
113 $this->marge_basse = 0;
115 $this->option_logo = 1;
116 $this->option_tva = 0;
117 $this->option_modereg = 0;
118 $this->option_condreg = 0;
119 $this->option_multilang = 0;
120 $this->option_escompte = 0;
121 $this->option_credit_note = 0;
122 $this->option_freetext = 1;
123 $this->option_draft_watermark = 0;
125 if ($mysoc ===
null) {
131 $this->emetteur = $mysoc;
132 if (!$this->emetteur->country_code) {
133 $this->emetteur->country_code = substr($langs->defaultlang, -2);
158 $array_key.
'_id' =>
$object->id,
159 $array_key.
'_ref' =>
$object->ref,
160 $array_key.
'_title' =>
$object->title,
161 $array_key.
'_description' =>
$object->description,
166 $array_key.
'_note_private' =>
$object->note_private,
167 $array_key.
'_note_public' =>
$object->note_public,
168 $array_key.
'_public' =>
$object->public,
169 $array_key.
'_statut' =>
$object->getLibStatut()
173 if (is_array(
$object->array_options) && count(
$object->array_options)) {
197 'task_ref' => $task->ref,
198 'task_fk_project' => $task->fk_project,
199 'task_projectref' => $task->projectref,
200 'task_projectlabel' => $task->projectlabel,
201 'task_label' => $task->label,
202 'task_description' => $task->description,
203 'task_fk_parent' => $task->fk_task_parent,
204 'task_duration' => $task->duration_effective,
206 'task_planned_workload' => $task->planned_workload,
207 'task_planned_workload_formated' =>
convertSecondToTime($task->planned_workload,
'allhourmin'),
208 'task_progress' => $task->progress,
209 'task_public' => $task->public,
212 'task_note_private' => (
string) $task->note_private,
213 'task_note_public' => (
string) $task->note_public
217 if (is_array($task->array_options) && count($task->array_options)) {
218 $task->fetch_optionals();
238 'projcontacts_id' => $contact[
'id'],
239 'projcontacts_rowid' => $contact[
'rowid'],
240 'projcontacts_role' => $contact[
'libelle'],
241 'projcontacts_lastname' => $contact[
'lastname'],
242 'projcontacts_firstname' => $contact[
'firstname'],
243 'projcontacts_fullcivname' => $contact[
'fullname'],
244 'projcontacts_socname' => $contact[
'socname'],
245 'projcontacts_email' => $contact[
'email']
261 'projfile_name' => $file[
'name'],
263 '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' => $taskresource[
'rowid'],
304 'taskressource_role' => $taskresource[
'libelle'],
305 'taskressource_lastname' => $taskresource[
'lastname'],
306 'taskressource_firstname' => $taskresource[
'firstname'],
307 'taskressource_fullcivname' => $taskresource[
'fullname'],
308 'taskressource_socname' => $taskresource[
'socname'],
309 'taskressource_email' => $taskresource[
'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[
'lastname'],
333 'tasktime_user_first' => $tasktime[
'firstname'],
334 'tasktime_fullcivname' => $tasktime[
'fullcivname']
350 'tasksfile_name' => $file[
'name'],
352 'tasksfile_size' => $file[
'size']
365 global
$conf, $langs;
368 $langs->loadLangs(array(
"errors",
"companies"));
370 $form =
new Form($this->db);
373 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" enctype="multipart/form-data">';
374 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
375 $texte .=
'<input type="hidden" name="page_y" value="">';
376 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
377 $texte .=
'<input type="hidden" name="param1" value="PROJECT_TASK_ADDON_PDF_ODT_PATH">';
378 $texte .=
'<table class="nobordernopadding centpercent">';
381 $texte .=
'<tr><td>';
382 $texttitle = $langs->trans(
"ListOfDirectories");
383 $listofdir = explode(
',', preg_replace(
'/[\r\n]+/',
',', trim(
$conf->global->PROJECT_TASK_ADDON_PDF_ODT_PATH)));
384 $listoffiles = array();
385 foreach ($listofdir as $key => $tmpdir) {
386 $tmpdir = trim($tmpdir);
387 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
389 unset($listofdir[$key]);
392 if (!is_dir($tmpdir)) {
393 $texttitle .=
img_warning($langs->trans(
"ErrorDirNotFound", $tmpdir),
'');
395 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.(ods|odt)');
396 if (count($tmpfiles)) {
397 $listoffiles = array_merge($listoffiles, $tmpfiles);
401 $texthelp = $langs->trans(
"ListOfDirectoriesForModelGenODT");
402 $texthelp .=
'<br><br><span class="opacitymedium">'.$langs->trans(
"ExampleOfDirectoriesForModelGen").
'</span>';
404 $texthelp .=
'<br>'.$langs->trans(
"FollowingSubstitutionKeysCanBeUsed").
'<br>';
405 $texthelp .= $langs->transnoentitiesnoconv(
"FullListOnOnlineDocumentation");
407 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1, 3, $this->
name);
408 $texte .=
'<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
409 $texte .=
'<textarea class="flat textareafordir" spellcheck="false" cols="60" name="value1">';
411 $texte .=
'</textarea>';
412 $texte .=
'</div><div style="display: inline-block; vertical-align: middle;">';
413 $texte .=
'<input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.dol_escape_htmltag($langs->trans(
"Modify")).
'">';
414 $texte .=
'<br></div></div>';
417 $nbofiles = count($listoffiles);
419 $texte .= $langs->trans(
"NumberOfModelFilesFound").
': <b>';
427 $texte .=
'<div id="div_'.get_class($this).
'" class="hiddenx">';
429 foreach ($listoffiles as $file) {
430 $texte .=
'- '.$file[
'name'].
' <a href="'.DOL_URL_ROOT.
'/document.php?modulepart=doctemplates&file=tasks/'.urlencode(basename($file[
'name'])).
'">'.
img_picto(
'',
'listlight').
'</a>';
431 $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>';
437 $texte .=
'<div>'.$langs->trans(
"UploadNewTemplate");
439 $maxmin = $maxfilesizearray[
'maxmin'];
441 $texte .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
443 $texte .=
' <input type="file" name="uploadfile">';
444 $texte .=
'<input type="hidden" value="PROJECT_TASK_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
445 $texte .=
'<input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans(
"Upload")).
'" name="upload">';
451 $texte .=
'</table>';
469 global $user, $langs,
$conf, $mysoc, $hookmanager;
471 if (empty($srctemplatepath)) {
472 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
477 if (!is_object($hookmanager)) {
478 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
481 $hookmanager->initHooks(array(
'odtgeneration'));
484 if (!is_object($outputlangs)) {
485 $outputlangs = $langs;
487 $sav_charset_output = $outputlangs->charset_output;
488 $outputlangs->charset_output =
'UTF-8';
491 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
493 if (
$conf->project->dir_output) {
504 $project =
new Project($this->db);
505 $project->fetch(
$object->fk_project);
506 $project->fetch_thirdparty();
508 $dir =
$conf->project->dir_output.
"/".$project->ref.
"/";
510 if (!preg_match(
'/specimen/i', $objectref)) {
511 $dir .=
"/".$objectref;
513 $file = $dir.
"/".$objectref.
".odt";
515 if (!file_exists($dir)) {
517 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
523 if (file_exists($dir)) {
525 $newfile = basename($srctemplatepath);
526 $newfiletmp = preg_replace(
'/\.(ods|odt)/i',
'', $newfile);
527 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
528 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
529 $newfiletmp = $objectref .
'_' . $newfiletmp;
531 $file = $dir .
'/' . $newfiletmp .
'.odt';
538 if (!is_writable(
$conf->project->dir_temp)) {
539 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory",
$conf->project->dir_temp);
540 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
544 $socobject = $project->thirdparty;
547 $substitutionarray = array(
548 '__FROM_NAME__' => $this->emetteur->name,
549 '__FROM_EMAIL__' => $this->emetteur->email,
555 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
556 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
559 require_once ODTPHP_PATH.
'odf.php';
561 $odfHandler =
new Odf(
564 'PATH_TO_TMP' =>
$conf->project->dir_temp,
566 'DELIMITER_LEFT' =>
'{',
567 'DELIMITER_RIGHT' =>
'}'
571 $this->error = $e->getMessage();
582 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null,
$object);
590 $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other);
600 foreach ($tmparray as $key => $value) {
602 if (preg_match(
'/logo$/', $key)) {
603 if (file_exists($value)) {
604 $odfHandler->setImage($key, $value, $ratio);
606 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
609 $odfHandler->setVars($key, $value,
true,
'UTF-8');
611 }
catch (OdfException $e) {
622 if (!empty($project->fk_soc)) {
623 $socid = $project->fk_soc;
628 foreach ($tmparray as $key => $val) {
630 $odfHandler->setVars($key, $val,
true,
'UTF-8');
631 }
catch (OdfException $e) {
637 $sourcearray = array(
'internal',
'external');
638 $contact_array = array();
639 foreach ($sourcearray as $source) {
640 $contact_temp =
$object->liste_contact(-1, $source);
641 if ((is_array($contact_temp) && count($contact_temp) > 0)) {
642 $contact_array = array_merge($contact_array, $contact_temp);
646 $foundtagforlines = 1;
648 $listlinestaskres = $odfHandler->setSegment(
'tasksressources');
649 }
catch (OdfExceptionSegmentNotFound $e) {
651 $foundtagforlines = 0;
654 if ($foundtagforlines && (is_array($contact_array) && count($contact_array) > 0)) {
655 foreach ($contact_array as $contact) {
656 if ($contact[
'source'] ==
'internal') {
657 $objectdetail =
new User($this->db);
658 $objectdetail->fetch($contact[
'id']);
659 $contact[
'socname'] = $mysoc->name;
660 } elseif ($contact[
'source'] ==
'external') {
661 $objectdetail =
new Contact($this->db);
662 $objectdetail->fetch($contact[
'id']);
665 $soc->fetch($contact[
'socid']);
666 $contact[
'socname'] = $soc->name;
668 dol_syslog(get_class().
'::'.__METHOD__.
' Unexpected contact source:'.$contact[
'source'], LOG_WARNING);
669 $objectdetail =
null;
671 $contact[
'fullname'] = is_object($objectdetail) ? $objectdetail->getFullName($outputlangs, 1) :
null;
675 foreach ($tmparray as $key => $val) {
677 $listlinestaskres->setVars($key, $val,
true,
'UTF-8');
678 }
catch (SegmentException $e) {
682 $listlinestaskres->merge();
684 $odfHandler->mergeSegment($listlinestaskres);
688 $foundtagforlines = 1;
690 $listlinestasktime = $odfHandler->setSegment(
'taskstimes');
691 }
catch (OdfExceptionSegmentNotFound $e) {
693 $foundtagforlines = 0;
698 $sql =
"SELECT t.rowid, t.element_date as task_date, t.element_duration as task_duration, t.fk_user, t.note";
699 $sql .=
", u.lastname, u.firstname";
700 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time as t";
701 $sql .=
" , ".MAIN_DB_PREFIX.
"user as u";
702 $sql .=
" WHERE t.fk_element =".((int)
$object->id);
703 $sql .=
" AND t.elementtype = 'task'";
704 $sql .=
" AND t.fk_user = u.rowid";
705 $sql .=
" ORDER BY t.element_date DESC";
707 $resql = $this->db->query($sql);
708 if ($foundtagforlines && $resql) {
709 $num = $this->db->num_rows($resql);
714 $row = $this->db->fetch_array($resql);
715 if (!empty($row[
'fk_user'])) {
716 $objectdetail =
new User($this->db);
717 $objectdetail->fetch($row[
'fk_user']);
719 $row[
'fullcivname'] = $objectdetail->getFullName($outputlangs, 1);
721 $row[
'fullcivname'] =
'';
726 foreach ($tmparray as $key => $val) {
728 $listlinestasktime->setVars($key, $val,
true,
'UTF-8');
729 }
catch (SegmentException $e) {
733 $listlinestasktime->merge();
736 $this->db->free($resql);
738 $odfHandler->mergeSegment($listlinestasktime);
744 $foundtagforlines = 1;
746 $listtasksfiles = $odfHandler->setSegment(
'tasksfiles');
747 }
catch (OdfExceptionSegmentNotFound $e) {
749 $foundtagforlines = 0;
752 if ($foundtagforlines) {
754 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$',
'name', SORT_ASC, 1);
756 foreach ($filearray as $filedetail) {
759 foreach ($tmparray as $key => $val) {
761 $listtasksfiles->setVars($key, $val,
true,
'UTF-8');
762 }
catch (SegmentException $e) {
766 $listtasksfiles->merge();
770 $odfHandler->mergeSegment($listtasksfiles);
772 }
catch (OdfException $e) {
773 $this->error = $e->getMessage();
781 $foundtagforlines = 1;
783 $listlines = $odfHandler->setSegment(
'projectfiles');
784 }
catch (OdfExceptionSegmentNotFound $e) {
786 $foundtagforlines = 0;
789 if ($foundtagforlines) {
792 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$',
'name', SORT_ASC, 1);
794 foreach ($filearray as $filedetail) {
798 foreach ($tmparray as $key => $val) {
800 $listlines->setVars($key, $val,
true,
'UTF-8');
801 }
catch (SegmentException $e) {
807 $odfHandler->mergeSegment($listlines);
808 }
catch (OdfException $e) {
809 $this->error = $e->getMessage();
816 $sourcearray = array(
'internal',
'external');
817 $contact_array = array();
818 foreach ($sourcearray as $source) {
819 $contact_temp = $project->liste_contact(-1, $source);
820 if ((is_array($contact_temp) && count($contact_temp) > 0)) {
821 $contact_array = array_merge($contact_array, $contact_temp);
825 $foundtagforlines = 1;
827 $listlines = $odfHandler->setSegment(
'projectcontacts');
828 }
catch (OdfExceptionSegmentNotFound $e) {
830 $foundtagforlines = 0;
833 if ($foundtagforlines && (is_array($contact_array) && count($contact_array) > 0)) {
835 foreach ($contact_array as $contact) {
836 if ($contact[
'source'] ==
'internal') {
837 $objectdetail =
new User($this->db);
838 $objectdetail->fetch($contact[
'id']);
839 $contact[
'socname'] = $mysoc->name;
840 } elseif ($contact[
'source'] ==
'external') {
841 $objectdetail =
new Contact($this->db);
842 $objectdetail->fetch($contact[
'id']);
845 $soc->fetch($contact[
'socid']);
846 $contact[
'socname'] = $soc->name;
848 dol_syslog(get_class().
'::'.__METHOD__.
' Unexpected contact source:'.$contact[
'source'], LOG_ERR);
851 $contact[
'fullname'] = $objectdetail->getFullName($outputlangs, 1);
855 foreach ($tmparray as $key => $val) {
857 $listlines->setVars($key, $val,
true,
'UTF-8');
858 }
catch (SegmentException $e) {
864 $odfHandler->mergeSegment($listlines);
865 }
catch (OdfException $e) {
866 $this->error = $e->getMessage();
874 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
875 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
881 $odfHandler->exportAsAttachedPDF($file);
883 $this->error = $e->getMessage();
889 $odfHandler->saveToDisk($file);
891 $this->error = $e->getMessage();
896 $parameters = array(
'odfHandler' => &$odfHandler,
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs,
'substitutionarray' => &$tmparray);
897 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
903 $this->result = array(
'fullpath' => $file);
907 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);