diff --git a/admin/securityconf.php b/admin/securityconf.php
index 3ce0aa8e5..fe88bb8b0 100644
--- a/admin/securityconf.php
+++ b/admin/securityconf.php
@@ -183,278 +183,76 @@
}
if (isModEnabled('societe')) {
- /*
- *** Labour Doctor -- Médecin du travail ***
- */
-
- print '
' . $langs->trans("LabourDoctor") . ' | |
' . "\n";
- print '' . $langs->trans("ActionOnCompany") . ' | ';
-
- $labourdDoctorSociety = $allLinks['LabourDoctorSociety'];
-
- // * Third party concerned - Tiers concerné *
-
- if ($labourdDoctorSociety->ref == 'LabourDoctorSociety') {
- $events = [];
- $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1', 1), 'htmlname' => 'labourdoctor_contactid', 'params' => array('add-customer-contact' => 'disabled'));
- $societe->fetch($labourdDoctorSociety->id[0]);
-
- if ($action == 'create_soc' && $type == $labourdDoctorSociety->ref) {
- $labourdDoctorSociety->id[0] = array_key_first($lastSocietyCreated);
- }
-
- print $form->select_company($labourdDoctorSociety->id[0], 'labourdoctor_socid', '', 'SelectThirdParty', 1, 0, $events, 0, 'minwidth300');
- } else {
- $events = [];
- $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1', 1), 'htmlname' => 'labourdoctor_contactid', 'params' => array('add-customer-contact' => 'disabled'));
-
- //For external user force the company to user company
- if ( ! empty($user->socid)) {
- print $form->select_company($user->socid, 'labourdoctor_socid', '', 0, 1, 0, $events, 0, 'minwidth300');
- } else {
- print $form->select_company('', 'labourdoctor_socid', '', 'SelectThirdParty', 1, 0, $events, 0, 'minwidth300');
- }
- }
- if (!GETPOSTISSET('backtopage')) {
- print ' ref) . '">';
- }
- print ' |
';
-
- // * Related contacts - Contacts associés *
- print '' . $langs->trans("ActionOnContact") . ' | ';
-
- $labourdDoctorContact = $allLinks['LabourDoctorContact'];
- $labourDoctorPreselectedIds = $labourdDoctorContact->id ?: [];
-
- if ($action == 'create_contact' && $contact->fk_soc == $societe->id) {
- $labourDoctorPreselectedIds = array_merge($labourDoctorPreselectedIds, [$lastContactId]);
- }
-
- if ($labourdDoctorContact->id) {
- print $form->selectcontacts(empty($labourdDoctorSociety->id[0]) ? -1 : $labourdDoctorSociety->id[0], $labourDoctorPreselectedIds, 'labourdoctor_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, [], false, 'multiple', 'labourdoctor_contactid');
- } else {
- $labourDoctorPreselectedIds = array_merge($labourDoctorPreselectedIds, GETPOST('labourdoctor_contactid', 'array'));
- if (GETPOST('labourdoctor_contactid', 'array')) {
- $labourDoctorPreselectedIds[GETPOST('labourdoctor_contactid', 'array')] = GETPOST('labourdoctor_contactid', 'array');
+ $securityArray = [
+ 'LabourDoctor' => ['labourdoctor', 'fa-briefcase-medical'],
+ 'LabourInspector' => ['labourinspector', 'fa-search'],
+ 'SAMU' => ['samu', 'fa-hospital-alt'],
+ 'Pompiers' => ['pompiers', 'fa-ambulance'],
+ 'Police' => ['police', 'fa-car'],
+ 'AllEmergencies' => ['touteurgence', 'fa-phone'],
+ 'RightsDefender' => ['defenseur', 'fa-gavel'],
+ 'PoisonControlCenter' => ['antipoison', 'fa-skull-crossbones'],
+ ];
+
+ foreach($securityArray as $title => $infos) {
+ $prefix = $infos[0];
+ $icon = 'fas ' . $infos[1];
+
+ print ' |
' . $langs->trans($title) . ' | |
' . "\n";
+ print '' . $langs->trans("ActionOnCompany") . ' | ';
+
+ // Exceptions for labour doctor and inspector
+ $labourSociety = ($prefix == 'labourdoctor' || $prefix == 'labourinspector' ? $allLinks[$title . 'Society'] : $allLinks[$title]);
+
+ // * Third party concerned - Tiers concerné *
+ $events[] = ['method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1', 1), 'htmlname' => $prefix . '_contactid', 'params' => ['add-customer-contact' => 'disabled']];
+ if ($labourSociety->ref == $title || $labourSociety->ref == $title . 'Society') {
+ $societe->fetch($labourSociety->id[0]);
+
+ if ($action == 'create_soc' && $type == $labourSociety->ref) {
+ $labourSociety->id[0] = array_key_first($lastSocietyCreated);
+ }
+
+ print $form->select_company($labourSociety->id[0], $prefix . '_socid', '', 'SelectThirdParty', 1, 0, $events, 0, 'minwidth300');
+ } else {
+ //For external user force the company to user company
+ if (!empty($user->socid)) {
+ print $form->select_company($user->socid, $prefix . '_socid', '', 0, 1, 0, $events, 0, 'minwidth300');
+ } else {
+ print $form->select_company('', $prefix . '_socid', '', 'SelectThirdParty', 1, 0, $events, 0, 'minwidth300');
+ }
}
- print $form->selectcontacts(empty(GETPOST('labourdoctor_socid', 'int')) ? $labourdDoctorSociety->id[0] : GETPOST('labourdoctor_socid', 'int'), $labourDoctorPreselectedIds, 'labourdoctor_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, [], false, 'multiple', 'labourdoctor_contactid');
- }
- if (!GETPOSTISSET('backtopage')) {
- print ' ';
- }
- print ' |
';
-
- /*
- *** Labour Inspector -- Inspecteur du travail ***
- */
-
- print '' . $langs->trans("LabourInspector") . ' | |
' . "\n";
- print '' . $langs->trans("ActionOnCompany") . ' | ';
-
- $labourdInspectorSociete = $allLinks['LabourInspectorSociety'];
-
- // * Third party concerned - Tiers concerné *
-
- if ($labourdInspectorSociete->ref == 'LabourInspectorSociety') {
- $events = [];
- $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1', 1), 'htmlname' => 'labourinspector_contactid', 'params' => array('add-customer-contact' => 'disabled'));
- $societe->fetch($labourdInspectorSociete->id[0]);
-
- if ($action == 'create_soc' && $type == $labourdInspectorSociete->ref) {
- $labourdInspectorSociete->id[0] = array_key_first($lastSocietyCreated);
+ if (!GETPOSTISSET('backtopage')) {
+ print ' ref) . '">';
}
-
- print $form->select_company($labourdInspectorSociete->id[0], 'labourinspector_socid', '', 0, 1, 0, $events, 0, 'minwidth300');
- } else {
- $events = [];
- $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1', 1), 'htmlname' => 'labourinspector_contactid', 'params' => array('add-customer-contact' => 'disabled'));
- //For external user force the company to user company
- if ( ! empty($user->socid)) {
- print $form->select_company($user->socid, 'labourinspector_socid', '', 0, 1, 0, $events, 0, 'minwidth300');
- } else {
- print $form->select_company('', 'labourinspector_socid', '', 'SelectThirdParty', 1, 0, $events, 0, 'minwidth300');
- }
- }
- if (!GETPOSTISSET('backtopage')) {
- print ' ref) . '">';
- }
- print ' |
';
-
- // * Related contacts - Contacts associés *
-
- print '' . $langs->trans("ActionOnContact") . ' | ';
-
- $labourInspectorContacts = $allLinks['LabourInspectorContact'];
- $labourInspectorPreselectedIds = $labourInspectorContacts->id ?: [];
-
- if ($action == 'create_contact' && $contact->fk_soc == $societe->id) {
- $labourInspectorPreselectedIds = array_merge($labourInspectorPreselectedIds, [$lastContactId]);
- }
-
- if ($labourInspectorContacts->id) {
- print $form->selectcontacts(empty($labourdInspectorSociete->id[0]) ? -1 : $labourdInspectorSociete->id[0], $labourInspectorPreselectedIds, 'labourinspector_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, [], false, 'multiple', 'labourinspector_contactid');
- } else {
- $labourInspectorPreselectedIds = array_merge($labourInspectorPreselectedIds, GETPOST('labourinspector_contactid', 'array'));
- if (GETPOST('labourinspector_contactid', 'array')) {
- $labourInspectorPreselectedIds[GETPOST('labourinspector_contactid', 'array')] = GETPOST('labourinspector_contactid', 'array');
+ print ' |
';
+
+ // * Related contacts - Contacts associés * for labour doctor and inspector
+ if ($prefix == 'labourdoctor' || $prefix == 'labourinspector') {
+ print '' . $langs->trans("ActionOnContact") . ' | ';
+
+ $labourContact = $allLinks[$title . 'Contact'];
+ $labourPreselectedIds = $labourContact->id ?: [];
+
+ if ($action == 'create_contact' && $contact->fk_soc == $societe->id) {
+ $labourPreselectedIds = array_merge($labourPreselectedIds, [$lastContactId]);
+ }
+
+ if ($labourContact->id) {
+ print $form->selectcontacts(empty($labourSociety->id[0]) ? -1 : $labourSociety->id[0], $labourPreselectedIds, $prefix . '_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, [], false, 'multiple', $prefix . '_contactid');
+ } else {
+ $labourPreselectedIds = array_merge($labourPreselectedIds, GETPOST($prefix . '_contactid', 'array'));
+ if (GETPOST($prefix . '_contactid', 'array')) {
+ $labourPreselectedIds[GETPOST($prefix . '_contactid', 'array')] = GETPOST($prefix . '_contactid', 'array');
+ }
+ print $form->selectcontacts(empty(GETPOST($prefix . '_socid', 'int')) ? $labourSociety->id[0] : GETPOST($prefix . '_socid', 'int'), $labourPreselectedIds, $prefix . '_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, [], false, 'multiple', 'labourdoctor_contactid');
+ }
+ if (!GETPOSTISSET('backtopage')) {
+ print ' ';
+ }
+ print ' |
';
}
- print $form->selectcontacts(empty(GETPOST('labourinspector_socid', 'int')) ? $labourdInspectorSociete->id[0] : GETPOST('labourinspector_socid', 'int'), $labourInspectorPreselectedIds, 'labourinspector_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, [], false, 'multiple', 'labourinspector_contactid');
- }
- if (!GETPOSTISSET('backtopage')) {
- print ' ';
}
- print '';
-
- /*
- *** Emergencies -- SAMU ***
- */
-
- print '' . $langs->trans("SAMU") . ' | |
' . "\n";
- print '' . $langs->trans("ActionOnCompany") . ' | ';
-
- $samuResources = $allLinks['SAMU'];
-
- // * Third party concerned - Tiers concerné *
-
- if ($samuResources->ref == 'SAMU') {
- $societe->fetch($samuResources->id[0]);
-
- print $form->select_company($samuResources->id[0], 'samu_socid', '', 'SelectThirdParty', 1, 0, 0, 0, 'minwidth300');
- } else {
- //For external user force the company to user company
- if ( ! empty($user->socid)) {
- print $form->select_company($user->socid, 'samu_socid', '', 1, 1, 0, 0, 0, 'minwidth300');
- } else {
- print $form->select_company('', 'samu_socid', '', 'SelectThirdParty', 1, 0, 0, 0, 'minwidth300');
- }
- }
- if ( ! GETPOSTISSET('backtopage')) print ' ';
- print ' |
';
-
- /*
- *** Fire Brigade -- Pompiers ***
- */
-
- print '' . $langs->trans("FireBrigade") . ' | |
' . "\n";
- print '' . $langs->trans("ActionOnCompany") . ' | ';
-
- $pompiersResources = $allLinks['Pompiers'];
-
- // * Third party concerned - Tiers concerné *
-
- if ($pompiersResources->ref == 'Pompiers') {
- $societe->fetch($pompiersResources->id[0]);
- print $form->select_company($pompiersResources->id[0], 'pompiers_socid', '', 'SelectThirdParty', 1, 0, 0, 0, 'minwidth300');
- } else {
- //For external user force the company to user company
- if ( ! empty($user->socid)) {
- print $form->select_company($user->socid, 'pompiers_socid', '', 1, 1, 0, 0, 0, 'minwidth300');
- } else {
- print $form->select_company('', 'pompiers_socid', '', 'SelectThirdParty', 1, 0, 0, 0, 'minwidth300');
- }
- }
- if ( ! GETPOSTISSET('backtopage')) print ' ';
- print ' |
';
-
- /*
- *** Police -- Police ***
- */
-
- print '' . $langs->trans("Police") . ' | |
' . "\n";
- print '' . $langs->trans("ActionOnCompany") . ' | ';
-
- $policeResources = $allLinks['Police'];
-
- // * Third party concerned - Tiers concerné *
-
- if ($policeResources->ref == 'Police') {
- $societe->fetch($policeResources->id[0]);
- print $form->select_company($policeResources->id[0], 'police_socid', '', 'SelectThirdParty', 1, 0, 0, 0, 'minwidth300');
- } else {
- //For external user force the company to user company
- if ( ! empty($user->socid)) {
- print $form->select_company($user->socid, 'police_socid', '', 1, 1, 0, 0, 0, 'minwidth300');
- } else {
- print $form->select_company('', 'police_socid', '', 'SelectThirdParty', 1, 0, 0, 0, 'minwidth300');
- }
- }
- if ( ! GETPOSTISSET('backtopage')) print ' ';
- print ' |
';
-
- /*
- *** For any emergency -- Pour toute urgence ***
- */
-
- print '' . $langs->trans("AllEmergencies") . ' | |
' . "\n";
- print '' . $langs->trans("ActionOnCompany") . ' | ';
-
- $touteUrgenceResources = $allLinks['AllEmergencies'];
-
- // * Third party concerned - Tiers concerné *
-
- if ($touteUrgenceResources->ref == 'AllEmergencies') {
- $societe->fetch($touteUrgenceResources->id[0]);
- print $form->select_company($touteUrgenceResources->id[0], 'touteurgence_socid', '', 'SelectThirdParty', 1, 0, 0, 0, 'minwidth300');
- } else {
- //For external user force the company to user company
- if ( ! empty($user->socid)) {
- print $form->select_company($user->socid, 'touteurgence_socid', '', 1, 1, 0, 0, 0, 'minwidth300');
- } else {
- print $form->select_company('', 'touteurgence_socid', '', 'SelectThirdParty', 1, 0, 0, 0, 'minwidth300');
- }
- }
- if ( ! GETPOSTISSET('backtopage')) print ' ';
- print ' |
';
-
- /*
- *** Rights defender -- Défenseur des droits ***
- */
-
- print '' . $langs->trans("RightsDefender") . ' | |
' . "\n";
- print '' . $langs->trans("ActionOnCompany") . ' | ';
-
- $defenseurResources = $allLinks['RightsDefender'];
-
- // * Third party concerned - Tiers concerné *
-
- if ($defenseurResources->ref == 'RightsDefender') {
- $societe->fetch($defenseurResources->id[0]);
- print $form->select_company($defenseurResources->id[0], 'defenseur_socid', '', 'SelectThirdParty', 1, 0, 0, 0, 'minwidth300');
- } else {
- //For external user force the company to user company
- if ( ! empty($user->socid)) {
- print $form->select_company($user->socid, 'defenseur_socid', '', 1, 1, 0, 0, 0, 'minwidth300');
- } else {
- print $form->select_company('', 'defenseur_socid', '', 'SelectThirdParty', 1, 0, 0, 0, 'minwidth300');
- }
- }
- if ( ! GETPOSTISSET('backtopage')) print ' ';
- print ' |
';
-
- /*
- *** Poison control center -- Centre antipoison ***
- */
-
- print '' . $langs->trans("PoisonControlCenter") . ' | |
' . "\n";
-
- print '' . $langs->trans("ActionOnCompany") . ' | ';
- $poisonControlCenterResources = $allLinks['PoisonControlCenter'];
-
- // * Third party concerned - Tiers concerné *
-
- if ($poisonControlCenterResources->ref == 'PoisonControlCenter') {
- $societe->fetch($poisonControlCenterResources->id[0]);
- print $form->select_company($poisonControlCenterResources->id[0], 'antipoison_socid', '', 'SelectThirdParty', 1, 0, 0, 0, 'minwidth300');
- } else {
- //For external user force the company to user company
- if ( ! empty($user->socid)) {
- print $form->select_company($user->socid, 'antipoison_socid', '', 1, 1, 0, 0, 0, 'minwidth300');
- } else {
- print $form->select_company('', 'antipoison_socid', '', 'SelectThirdParty', 1, 0, 0, 0, 'minwidth300');
- }
- }
- if ( ! GETPOSTISSET('backtopage')) print ' ';
- print ' |
';
}
/*