diff --git a/class/actions_digiriskdolibarr.class.php b/class/actions_digiriskdolibarr.class.php index 2861266b8..80b569b02 100644 --- a/class/actions_digiriskdolibarr.class.php +++ b/class/actions_digiriskdolibarr.class.php @@ -1126,4 +1126,60 @@ public function addMoreActionsButtons($parameters, &$object, &$action) } } + + /** + * Overloading the showLinkedObjectBlock function : replacing the parent's function with the one below + * + * @param array $parameters Hook metadata (context, etc...) + * @param object $object The object to process + * @return int 0 < on error, 0 on success, 1 to replace standard code + * @throws Exception + */ + public function showLinkedObjectBlock($parameters, &$object) { + global $conf, $langs; + + if (strpos($parameters['context'], 'preventionplancard') !== false) { + $firePermits = saturne_fetch_all_object_type('FirePermit', '', '', 0, 0, ['customsql' => 'fk_preventionplan = ' . $object->id]); + $morehtmlright = $parameters['morehtmlright']; + + print load_fiche_titre($langs->trans('RelatedFirePermit'), $morehtmlright, '', 0, 0, 'showlinkedobjectblock'); + + print '
'; + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $nboftypesoutput = 0; + $tplpath = 'firepermit'; + $tplname = 'linkedobjectblock'; + $linkedObjectBlock = $firePermits; + + $dirtpls = array_merge($conf->modules_parts['tpl'], ['digiriskdolibarr' => '/digiriskdolibarr/core/tpl/' . $tplpath . '/']); + foreach ($dirtpls as $reldir) { + $res = @include dol_buildpath($reldir . $tplname . '.tpl.php'); + if ($res) { + $nboftypesoutput++; + break; + } + } + + if (!$nboftypesoutput) { + print ''; + } + + print '
' . $langs->trans("Type") . '' . $langs->trans("Ref") . '' . $langs->trans("Label") . '' . $langs->trans("DateStart") . '' . $langs->trans("DateEnd") . '' . $langs->trans("Status") . '
' . $langs->trans("None") . '
'; + print '
'; + + return 1; + } + + return 0; // or return 1 to replace standard code + } } diff --git a/core/tpl/firepermit/index.php b/core/tpl/firepermit/index.php new file mode 100644 index 000000000..cd6990e24 --- /dev/null +++ b/core/tpl/firepermit/index.php @@ -0,0 +1,2 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'datec', 'desc', 0, 0, 1); +$ilink = 0; +foreach ($linkedObjectBlock as $key => $objectlink) { + $ilink++; + + $trclass = 'oddeven'; + if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) { + $trclass .= ' liste_sub_total'; + } ?> + + trans("FirePermit"); ?> + getNomUrl(1); ?> + label; ?> + date_start, 'day'); ?> + date_end, 'day'); ?> + getLibStatut(3); ?> + + print ''; print ''; } + // Document Generation -- Génération des documents if ($permissiontoadd) { print '
'; @@ -1475,7 +1478,38 @@ class="attachment-thumbail size-thumbnail photo photowithmargin" alt=""> print saturne_show_documents($modulepart, $dirFiles, $filedir, $urlsource, $genallowed, 0, $defaultmodel, 1, 0, 0, 0, 0, $title, 0, 0, empty($soc->default_lang) ? '' : $soc->default_lang, $object, 0, 'remove_file', (($object->status > $object::STATUS_VALIDATED) ? 1 : 0), $langs->trans('ObjectMustBeLockedToGenerate', ucfirst($langs->transnoentities('The' . ucfirst($object->element))))); } - if ($permissiontoadd) { + $firepermits = saturne_fetch_all_object_type('FirePermit', '', '', 0, 0, ['customsql' => 'fk_preventionplan = ' . $id]); + + if (!empty($firepermits) && is_array($firepermits)) { + $firepermitdocument = new FirePermitDocument($db); + foreach ($firepermits as $firepermit) { + $objRef = dol_sanitizeFileName($firepermit->ref); + $dirFiles = $firepermitdocument->element . '/' . $objRef; + + $filedir = $upload_dir . '/' . $dirFiles; + $dirFilesArray[] = $dirFiles; + $filedirArray[] = $filedir; + + $modulepart = 'digiriskdolibarr:FirePermitDocument'; + $title = $langs->trans('FirePermitDocument'); + + $filelist = array_merge($filelist, dol_dir_list($filedir, 'files')); + if (!empty($filelist) && is_array($filelist)) { + foreach ($filelist as $file) { + if (preg_match('/sign/', $file['name'])) { + $filesigned = 1; + } + } + } + } + $urlsource = $_SERVER["PHP_SELF"] . '?id=' . $object->id; + + print saturne_show_documents($modulepart, $dirFilesArray, $filedirArray, $urlsource, 0, 0, '', 1, 0, 0, 0, 0, $title, 0, 0); + } + + $form->showLinkedObjectBlock($object, '', null, $langs->trans('RelatedFirePermit')); + + if ($permissiontoadd) { print '
'; } else { print '
';