Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3942 [PreventionPlan] add: associated fire permits documents #3966

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
56 changes: 56 additions & 0 deletions class/actions_digiriskdolibarr.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<div class="div-table-responsive-no-min">';
print '<table class="noborder allwidth" data-block="showLinkedObject" data-element="' . $object->element . '" data-elementid="' . $object->id . '" >';

print '<tr class="liste_titre">';
print '<td>' . $langs->trans("Type") . '</td>';
print '<td>' . $langs->trans("Ref") . '</td>';
print '<td>' . $langs->trans("Label") . '</td>';
print '<td class="center">' . $langs->trans("DateStart") . '</td>';
print '<td class="center">' . $langs->trans("DateEnd") . '</td>';
print '<td class="right">' . $langs->trans("Status") . '</td>';
print '</tr>';

$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 '<tr><td class="impair" colspan="7"><span class="opacitymedium">' . $langs->trans("None") . '</span></td></tr>';
}

print '</table>';
print '</div>';

return 1;
}

return 0; // or return 1 to replace standard code
}
}
2 changes: 2 additions & 0 deletions core/tpl/firepermit/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
//Silence is golden
36 changes: 36 additions & 0 deletions core/tpl/firepermit/linkedobjectblock.tpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/* Copyright (C) 2024 EVARISK <[email protected]>
*
* 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 <https://www.gnu.org/licenses/>.
*/

$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';
} ?>
<tr class="<?php echo $trclass; ?>" >
<td class="linkedcol-element tdoverflowmax100"><?php echo $langs->trans("FirePermit"); ?>
<td class="linkedcol-name tdoverflowmax150"><?php echo $objectlink->getNomUrl(1); ?></td>
<td class="linkedcol-label"><?php echo $objectlink->label; ?></td>
<td class="linkedcol-date center"><?php echo dol_print_date($objectlink->date_start, 'day'); ?></td>
<td class="linkedcol-date center"><?php echo dol_print_date($objectlink->date_end, 'day'); ?></td>
<td class="linkedcol-statut right"><?php echo $objectlink->getLibStatut(3); ?></td>
</tr>
<?php
}
1 change: 1 addition & 0 deletions langs/fr_FR/digiriskdolibarr.lang
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ ErrorThirdPartyHasAtLeastOneChildOfTypePreventionPlan = Le tiers est lié à au
ErrorContactHasAtLeastOneChildOfTypePreventionPlan = Le contact est lié à au moins un enfant de type Plan de Prévention :
ConfirmDeletePreventionPlan = Êtes-vous sûr de vouloir supprimer ce plan de prévention ?
PreventionPlanRole = Les rôles du plan de prévention
RelatedFirePermit = Permis de feu liés

# Email - Mail
PreventionPlanLabel = Récapitulatif du plan de prévention
Expand Down
36 changes: 35 additions & 1 deletion view/preventionplan/preventionplan_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@
require_once __DIR__ . '/../../class/digiriskelement.class.php';
require_once __DIR__ . '/../../class/digiriskresources.class.php';
require_once __DIR__ . '/../../class/preventionplan.class.php';
require_once __DIR__ . '/../../class/firepermit.class.php';
require_once __DIR__ . '/../../class/riskanalysis/risk.class.php';
require_once __DIR__ . '/../../class/digiriskdolibarrdocuments/preventionplandocument.class.php';
require_once __DIR__ . '/../../class/digiriskdolibarrdocuments/firepermitdocument.class.php';
require_once __DIR__ . '/../../lib/digiriskdolibarr_function.lib.php';
require_once __DIR__ . '/../../lib/digiriskdolibarr_preventionplan.lib.php';

Expand Down Expand Up @@ -1446,6 +1448,7 @@ class="attachment-thumbail size-thumbnail photo photowithmargin" alt="">
print '</table>';
print '</div>';
}

// Document Generation -- Génération des documents
if ($permissiontoadd) {
print '<div class=""><div class="preventionplanDocument fichehalfleft">';
Expand Down Expand Up @@ -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 '</div><div class="fichehalfright">';
} else {
print '</div><div class="">';
Expand Down