diff --git a/class/actions_digiriskdolibarr.class.php b/class/actions_digiriskdolibarr.class.php index a7eff688b..351a4ab46 100644 --- a/class/actions_digiriskdolibarr.class.php +++ b/class/actions_digiriskdolibarr.class.php @@ -80,6 +80,12 @@ public function constructCategory($parameters, &$object) 'obj_class' => 'Accident', 'obj_table' => 'digiriskdolibarr_accident', ], + 'preventionplan' => [ + 'id' => 436302002, + 'code' => 'preventionplan', + 'obj_class' => 'PreventionPlan', + 'obj_table' => 'digiriskdolibarr_preventionplan', + ], ]; } @@ -511,7 +517,7 @@ public function printCommonFooter($parameters) } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action $offset = $limit * $page; - if ($type == 'accident') { + if ($type == 'accident' || $type == 'preventionplan') { require_once __DIR__ . '/' . $type . '.class.php'; $classname = ucfirst($type); @@ -702,7 +708,7 @@ public function doActions($parameters, $object, $action) $id = GETPOST('id'); $elementId = GETPOST('element_id'); $type = GETPOST('type'); - if ($id > 0 && $elementId > 0 && ($type == 'accident' && $user->rights->digiriskdolibarr->$type->write)) { + if ($id > 0 && $elementId > 0 && (($type == 'accident' || $type == 'preventionplan') && $user->rights->digiriskdolibarr->$type->write)) { require_once __DIR__ . '/' . $type . '.class.php'; $classname = ucfirst($type); diff --git a/class/preventionplan.class.php b/class/preventionplan.class.php index 78a4ba8ed..ed2c29d99 100644 --- a/class/preventionplan.class.php +++ b/class/preventionplan.class.php @@ -236,6 +236,18 @@ public function createFromClone(User $user, int $fromID, array $options): int } } } + + if (!empty($options['categories'])) { + $cat = new Categorie($this->db); + $categories = $cat->containing($fromID, 'preventionplan'); + if (is_array($categories) && !empty($categories)) { + $categoryIds = []; + foreach ($categories as $cat) { + $categoryIds[] = $cat->id; + } + $object->setCategories($categoryIds); + } + } } else { $this->error = $object->error; $this->errors = $object->errors; diff --git a/core/modules/modDigiriskDolibarr.class.php b/core/modules/modDigiriskDolibarr.class.php index 88ca92329..de5eb3204 100644 --- a/core/modules/modDigiriskDolibarr.class.php +++ b/core/modules/modDigiriskDolibarr.class.php @@ -1342,6 +1342,21 @@ public function __construct($db) 'user' => 0, // 0=Menu for internal users, 1=external users, 2=both ]; + $this->menu[$r++] = [ + 'fk_menu' => 'fk_mainmenu=digiriskdolibarr,fk_leftmenu=digiriskpreventionplan', + 'type' => 'left', + 'titre' => '' . $langs->transnoentities('Categories'), + 'mainmenu' => 'digiriskdolibarr', + 'leftmenu' => 'digiriskdolibarr_preventionplantags', + 'url' => '/categories/index.php?type=preventionplan', + 'langs' => 'digiriskdolibarr@digiriskdolibarr', + 'position' => 100 + $r, + 'enabled' => '$conf->digiriskdolibarr->enabled && $conf->categorie->enabled && $user->rights->digiriskdolibarr->preventionplan->read', + 'perms' => '$user->rights->digiriskdolibarr->preventionplan->read', + 'target' => '', + 'user' => 0, + ]; + $this->menu[$r++] = [ 'fk_menu' => 'fk_mainmenu=digiriskdolibarr', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode 'type' => 'left', // This is a Left menu entry diff --git a/langs/fr_FR/digiriskdolibarr.lang b/langs/fr_FR/digiriskdolibarr.lang index 5b76d4793..eeb7df643 100644 --- a/langs/fr_FR/digiriskdolibarr.lang +++ b/langs/fr_FR/digiriskdolibarr.lang @@ -581,6 +581,8 @@ AccidentInvestigationRole = Les rôles de l'enquête accident LesionsOrWorkStop = lésions ou arrêts de travail AccidentsCategoriesArea = Espace des tags/catégories des accidents AddAccidentIntoCategory = Assigner cette catégorie à l'accident +PreventionplansCategoriesArea = Espace des tags/catégories des plans de prévention +AddPreventionplanIntoCategory = Assigner cette catégorie au plan de prévention # AccidentTooltip - Tooltip des accidents VictimActivityTooltip = Précisez l’activité ou la tâche de la victime au moment de l’accident, c’est-à-dire ce que faisait la victime diff --git a/sql/preventionplan/llx_categorie_preventionplan.key.sql b/sql/preventionplan/llx_categorie_preventionplan.key.sql new file mode 100644 index 000000000..19e243532 --- /dev/null +++ b/sql/preventionplan/llx_categorie_preventionplan.key.sql @@ -0,0 +1,20 @@ +-- Copyright (C) 2021-2023 EVARISK +-- +-- 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/. + +ALTER TABLE llx_categorie_preventionplan ADD PRIMARY KEY pk_categorie_preventionplan (fk_categorie, fk_preventionplan); +ALTER TABLE llx_categorie_preventionplan ADD INDEX idx_categorie_preventionplan_fk_categorie (fk_categorie); +ALTER TABLE llx_categorie_preventionplan ADD INDEX idx_categorie_preventionplan_fk_preventionplan (fk_preventionplan); +ALTER TABLE llx_categorie_preventionplan ADD CONSTRAINT fk_categorie_preventionplan_rowid FOREIGN KEY (fk_categorie) REFERENCES llx_categorie (rowid); +ALTER TABLE llx_categorie_preventionplan ADD CONSTRAINT llx_categorie_preventionplan_digiriskdolibarr_preventionplan_rowid FOREIGN KEY (fk_preventionplan) REFERENCES llx_digiriskdolibarr_preventionplan (rowid); diff --git a/sql/preventionplan/llx_categorie_preventionplan.sql b/sql/preventionplan/llx_categorie_preventionplan.sql new file mode 100644 index 000000000..2b971e245 --- /dev/null +++ b/sql/preventionplan/llx_categorie_preventionplan.sql @@ -0,0 +1,20 @@ +-- Copyright (C) 2021-2023 EVARISK +-- +-- 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/. + +CREATE TABLE llx_categorie_preventionplan( + fk_categorie integer NOT NULL, + fk_preventionplan integer NOT NULL, + import_key varchar(14) +) ENGINE=innodb; diff --git a/view/preventionplan/preventionplan_card.php b/view/preventionplan/preventionplan_card.php index 10f96e8b6..881193af9 100644 --- a/view/preventionplan/preventionplan_card.php +++ b/view/preventionplan/preventionplan_card.php @@ -35,6 +35,7 @@ require_once DOL_DOCUMENT_ROOT .'/core/class/html.formprojet.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; // Load Saturne libraries. require_once __DIR__ . '/../../../saturne/class/saturnesignature.class.php'; @@ -232,6 +233,12 @@ if ( ! $error) { $result = $object->create($user, true); if ($result > 0) { + if (isModEnabled('categorie')) { + $categories = GETPOST('categories', 'array'); + if (method_exists($object, 'setCategories')) { + $object->setCategories($categories); + } + } $object->setInProgress($user, true); $digiriskresources->setDigiriskResources($db, $user->id, 'ExtSociety', 'societe', array($extSocietyId), $conf->entity, 'preventionplan', $object->id, 1); $digiriskresources->setDigiriskResources($db, $user->id, 'LabourInspector', 'societe', array($labourInspectorId), $conf->entity, 'preventionplan', $object->id, 1); @@ -341,6 +348,12 @@ if ( ! $error) { $result = $object->update($user, false); if ($result > 0) { + if (isModEnabled('categorie')) { + $categories = GETPOST('categories', 'array'); + if (method_exists($object, 'setCategories')) { + $object->setCategories($categories); + } + } $digiriskresources->setDigiriskResources($db, $user->id, 'ExtSociety', 'societe', array($extSocietyId), $conf->entity, 'preventionplan', $object->id, 0); $digiriskresources->setDigiriskResources($db, $user->id, 'LabourInspector', 'societe', array($labourInspectorId), $conf->entity, 'preventionplan', $object->id, 0); $digiriskresources->setDigiriskResources($db, $user->id, 'LabourInspectorAssigned', 'socpeople', array($labourInspectorContactId), $conf->entity, 'preventionplan', $object->id, 0); @@ -582,6 +595,7 @@ $options['preventionplan_risk'] = GETPOST('clone_preventionplan_risk'); $options['attendants'] = GETPOST('clone_attendants'); $options['schedule'] = GETPOST('clone_schedule'); + $options['categories'] = GETPOST('clone_categories'); if (1 == 0 && ! GETPOST('clone_preventionplan_risk') && ! GETPOST('clone_attendants') && ! GETPOST('clone_schedule')) { setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); @@ -743,6 +757,15 @@ print $form->selectcontacts((GETPOST('labour_inspector') ? GETPOST('labour_inspector') : ($allLinks['LabourInspectorSociety']->id[0] ?: -1)), $labourInspectorContactId, 'labour_inspector_contact', 1, '', '', 1, 'minwidth100imp widthcentpercentminusxx maxwidth400'); print ''; + // Categories + if (!empty($conf->categorie->enabled)) { + print ''.$langs->trans("Categories").''; + $categoryArborescence = $form->select_all_categories('preventionplan', '', 'parent', 64, 0, 1); + print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('categories', $categoryArborescence, GETPOST('categories', 'array'), '', 0, 'minwidth100imp widthcentpercentminusxx maxwidth400'); + print ''; + print ""; + } + // Other attributes include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php'; @@ -902,6 +925,23 @@ print $form->selectcontacts($labourInspectorSociety->id, dol_strlen($contact->email) ? $labourInspectorContact->id : -1, 'labour_inspector_contact', '', 0, '', 1, 'minwidth100imp widthcentpercentminusxx maxwidth400'); print ''; + // Tags-Categories + if ($conf->categorie->enabled) { + print ''.$langs->trans("Categories").''; + $categoryArborescence = $form->select_all_categories('preventionplan', '', 'parent', 64, 0, 1); + $c = new Categorie($db); + $cats = $c->containing($object->id, 'preventionplan'); + $arrayselected = array(); + if (is_array($cats)) { + foreach ($cats as $cat) { + $arrayselected[] = $cat->id; + } + } + print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('categories', $categoryArborescence, $arrayselected, '', 0, 'minwidth100imp widthcentpercentminusxx maxwidth400'); + print ''; + print ""; + } + // Other attributes include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php'; print ''; @@ -939,13 +979,13 @@ if (($action == 'clone' && (empty($conf->use_javascript_ajax) || ! empty($conf->dol_use_jmobile))) // Output when action = clone if jmobile or no js || ( ! empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) { // Always output when not jmobile nor js // Define confirmation messages - $formquestionclone = array( - 'text' => $langs->trans("ConfirmClone"), - array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("NewLabelForClonePreventionPlan"), 'value' => empty($tmpcode) ? $langs->trans("CopyOf") . ' ' . $object->ref : $tmpcode, 'size' => 24), - array('type' => 'checkbox', 'name' => 'clone_preventionplan_risk', 'label' => $langs->trans("ClonePreventionPlanRisk"), 'value' => 1), - array('type' => 'checkbox', 'name' => 'clone_attendants', 'label' => $langs->trans("CloneAttendantsPreventionPlan"), 'value' => 1), - array('type' => 'checkbox', 'name' => 'clone_schedule', 'label' => $langs->trans("CloneSchedulePreventionPlan"), 'value' => 1), - ); + $formquestionclone = ['text' => $langs->trans("ConfirmClone"), + ['type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("NewLabelForClonePreventionPlan"), 'value' => empty($tmpcode) ? $langs->trans("CopyOf") . ' ' . $object->ref : $tmpcode, 'size' => 24], + ['type' => 'checkbox', 'name' => 'clone_preventionplan_risk', 'label' => $langs->trans("ClonePreventionPlanRisk"), 'value' => 1], + ['type' => 'checkbox', 'name' => 'clone_attendants', 'label' => $langs->trans("CloneAttendantsPreventionPlan"), 'value' => 1], + ['type' => 'checkbox', 'name' => 'clone_schedule', 'label' => $langs->trans("CloneSchedulePreventionPlan"), 'value' => 1], + ['type' => 'checkbox', 'name' => 'clone_categories', 'label' => $langs->trans('CloneCategories'), 'value' => 1] + ]; $formconfirm .= $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ToClone'), $langs->trans('ConfirmClonePreventionPlan', $object->ref), 'confirm_clone', $formquestionclone, 'yes', 'actionButtonClone', 350, 600); } @@ -1047,6 +1087,13 @@ print ''; } + // Categories + if ($conf->categorie->enabled) { + print ''.$langs->trans("Categories").''; + print $form->showCategories($object->id, 'preventionplan', 1); + print ""; + } + print ''; print ''; print '
';