From f7a3f17d211ba82bf472d933f1cfdb93590658bf Mon Sep 17 00:00:00 2001 From: evarisk-micka Date: Thu, 14 Mar 2024 12:05:13 +0100 Subject: [PATCH 1/4] #730 [Admin] add: bouton plus for contact in security conf --- admin/securityconf.php | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/admin/securityconf.php b/admin/securityconf.php index 2645ec078..519cb3109 100644 --- a/admin/securityconf.php +++ b/admin/securityconf.php @@ -200,7 +200,9 @@ print $form->select_company('', 'labourdoctor_socid', '', 'SelectThirdParty', 1, 0, $events, 0, 'minwidth300'); } } - if ( ! GETPOSTISSET('backtopage')) print ' '; + if (!GETPOSTISSET('backtopage')) { + print ' '; + } print ''; // * Related contacts - Contacts associés * @@ -210,13 +212,18 @@ $labourDoctorPreselectedIds = $labourdDoctorContact->id; if ($labourdDoctorContact->id) { - print $form->selectcontacts(empty($labourdDoctorSociety->id[0]) ? -1 : $labourdDoctorSociety->id[0], $labourdDoctorContact->id, 'labourdoctor_contactid[]', 0, '', '', 0, 'quatrevingtpercent', false, 0, array(), false, 'multiple', 'labourdoctor_contactid'); + print $form->selectcontacts(empty($labourdDoctorSociety->id[0]) ? -1 : $labourdDoctorSociety->id[0], $labourdDoctorContact->id, 'labourdoctor_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourdoctor_contactid'); } else { - $labourDoctorPreselectedIds = GETPOST('labourdoctor_contactid', 'array'); - if (GETPOST('labourdoctor_contactid', 'array')) $labourDoctorPreselectedIds[GETPOST('labourdoctor_contactid', 'array')] = GETPOST('labourdoctor_contactid', 'array'); - print $form->selectcontacts(empty(GETPOST('labourdoctor_socid', 'int')) ? -1 : GETPOST('labourdoctor_socid', 'int'), $labourDoctorPreselectedIds, 'labourdoctor_contactid[]', 0, '', '', 0, 'quatrevingtpercent', false, 0, array(), false, 'multiple', 'labourdoctor_contactid'); + $labourDoctorPreselectedIds = GETPOST('labourdoctor_contactid', 'array'); + if (GETPOST('labourdoctor_contactid', 'array')) { + $labourDoctorPreselectedIds[GETPOST('labourdoctor_contactid', 'array')] = GETPOST('labourdoctor_contactid', 'array'); + } + print $form->selectcontacts(empty(GETPOST('labourdoctor_socid', 'int')) ? -1 : GETPOST('labourdoctor_socid', 'int'), $labourDoctorPreselectedIds, 'labourdoctor_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourdoctor_contactid'); } - print ''; + if (!GETPOSTISSET('backtopage')) { + print ' '; + } + print ''; /* *** Labour Inspector -- Inspecteur du travail *** @@ -245,7 +252,9 @@ print $form->select_company('', 'labourinspector_socid', '', 'SelectThirdParty', 1, 0, $events, 0, 'minwidth300'); } } - if ( ! GETPOSTISSET('backtopage')) print ' '; + if (!GETPOSTISSET('backtopage')) { + print ' '; + } print ''; // * Related contacts - Contacts associés * @@ -256,12 +265,17 @@ $labourInspectorPreselectedIds = $labourInspectorContacts->id; if ($labourInspectorContacts->id) { - print $form->selectcontacts(empty($labourdInspectorSociete->id[0]) ? -1 : $labourdInspectorSociete->id[0], $labourInspectorContacts->id, 'labourinspector_contactid[]', 0, '', '', 0, 'quatrevingtpercent', false, 0, array(), false, 'multiple', 'labourinspector_contactid'); + print $form->selectcontacts(empty($labourdInspectorSociete->id[0]) ? -1 : $labourdInspectorSociete->id[0], $labourInspectorContacts->id, 'labourinspector_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourinspector_contactid'); } else { $labourInspectorPreselectedIds = GETPOST('labourinspector_contactid', 'array'); - if (GETPOST('labourinspector_contactid', 'array')) $labourInspectorPreselectedIds[GETPOST('labourinspector_contactid', 'array')] = GETPOST('labourinspector_contactid', 'array'); - print $form->selectcontacts(empty(GETPOST('labourinspector_socid', 'int')) ? -1 : GETPOST('labourinspector_socid', 'int'), $labourInspectorPreselectedIds, 'labourinspector_contactid[]', 0, '', '', 0, 'quatrevingtpercent', false, 0, array(), false, 'multiple', 'labourinspector_contactid'); + if (GETPOST('labourinspector_contactid', 'array')) { + $labourInspectorPreselectedIds[GETPOST('labourinspector_contactid', 'array')] = GETPOST('labourinspector_contactid', 'array'); + } + print $form->selectcontacts(empty(GETPOST('labourinspector_socid', 'int')) ? -1 : GETPOST('labourinspector_socid', 'int'), $labourInspectorPreselectedIds, 'labourinspector_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourinspector_contactid'); } + if (!GETPOSTISSET('backtopage')) { + print ' '; + } print ''; /* From de6ed81909abcebb7f71c62f0bb9c9cdb070fb3c Mon Sep 17 00:00:00 2001 From: evarisk-micka Date: Wed, 3 Apr 2024 14:53:02 +0200 Subject: [PATCH 2/4] #730 [Admin] fix: handle linkback after backtopage --- admin/securityconf.php | 60 +++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/admin/securityconf.php b/admin/securityconf.php index 519cb3109..1f9436a09 100644 --- a/admin/securityconf.php +++ b/admin/securityconf.php @@ -181,14 +181,24 @@ $labourdDoctorSociety = $allLinks['LabourDoctorSociety']; - // * Third party concerned - Tiers concerné * + // * Third party concerned - Tiers concerné * if ($labourdDoctorSociety->ref == 'LabourDoctorSociety') { $events = array(); $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]); - print $form->select_company($labourdDoctorSociety->id[0], 'labourdoctor_socid', '', 'SelectThirdParty', 1, 0, $events, 0, 'minwidth300'); + if ($action == 'createdoctorcontact') { + $lastDoctorContact = $societe->contact_array(); + $lastDoctorContactId = array_key_last($lastDoctorContact); + } + + if ($action == 'createdoctorsoc') { + $lastSocieteCreated = saturne_fetch_all_object_type('societe', 'DESC', 'rowid', 1); + $labourdDoctorSociety->id[0] = array_key_first($lastSocieteCreated); + } + + print $form->select_company($labourdDoctorSociety->id[0], 'labourdoctor_socid', '', 'SelectThirdParty', 1, 0, $events, 0, 'minwidth300'); } else { $events = array(); $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1', 1), 'htmlname' => 'labourdoctor_contactid', 'params' => array('add-customer-contact' => 'disabled')); @@ -201,27 +211,31 @@ } } if (!GETPOSTISSET('backtopage')) { - print ' '; + print ' '; } print ''; // * Related contacts - Contacts associés * print '' . $langs->trans("ActionOnContact") . ''; - $labourdDoctorContact = $allLinks['LabourDoctorContact']; - $labourDoctorPreselectedIds = $labourdDoctorContact->id; + $labourdDoctorContact = $allLinks['LabourDoctorContact']; + $labourDoctorPreselectedIds = $labourdDoctorContact->id ?: []; + + if (!empty($labourdDoctorSociety)) { + $labourDoctorPreselectedIds = array_merge($labourDoctorPreselectedIds, [$lastDoctorContactId]); + } - if ($labourdDoctorContact->id) { - print $form->selectcontacts(empty($labourdDoctorSociety->id[0]) ? -1 : $labourdDoctorSociety->id[0], $labourdDoctorContact->id, 'labourdoctor_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourdoctor_contactid'); + if ($labourdDoctorContact->id) { + print $form->selectcontacts(empty($labourdDoctorSociety->id[0]) ? -1 : $labourdDoctorSociety->id[0], $labourDoctorPreselectedIds, 'labourdoctor_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourdoctor_contactid'); } else { - $labourDoctorPreselectedIds = GETPOST('labourdoctor_contactid', 'array'); + $labourDoctorPreselectedIds = array_merge($labourDoctorPreselectedIds, GETPOST('labourdoctor_contactid', 'array')); if (GETPOST('labourdoctor_contactid', 'array')) { $labourDoctorPreselectedIds[GETPOST('labourdoctor_contactid', 'array')] = GETPOST('labourdoctor_contactid', 'array'); } - print $form->selectcontacts(empty(GETPOST('labourdoctor_socid', 'int')) ? -1 : GETPOST('labourdoctor_socid', 'int'), $labourDoctorPreselectedIds, 'labourdoctor_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourdoctor_contactid'); + print $form->selectcontacts(empty(GETPOST('labourdoctor_socid', 'int')) ? $labourdDoctorSociety->id[0] : GETPOST('labourdoctor_socid', 'int'), $labourDoctorPreselectedIds, 'labourdoctor_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourdoctor_contactid'); } if (!GETPOSTISSET('backtopage')) { - print ' '; + print ' '; } print ''; @@ -241,6 +255,16 @@ $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 == 'createinspectorcontact') { + $lastInspectorContact = $societe->contact_array(); + $lastInspectorContactId = array_key_last($lastInspectorContact); + } + + if ($action == 'createinspectorsoc') { + $lastSocieteCreated = saturne_fetch_all_object_type('societe', 'DESC', 'rowid', 1); + $labourdInspectorSociete->id[0] = array_key_first($lastSocieteCreated); + } + print $form->select_company($labourdInspectorSociete->id[0], 'labourinspector_socid', '', 0, 1, 0, $events, 0, 'minwidth300'); } else { $events = array(); @@ -253,7 +277,7 @@ } } if (!GETPOSTISSET('backtopage')) { - print ' '; + print ' '; } print ''; @@ -262,19 +286,23 @@ print '' . $langs->trans("ActionOnContact") . ''; $labourInspectorContacts = $allLinks['LabourInspectorContact']; - $labourInspectorPreselectedIds = $labourInspectorContacts->id; + $labourInspectorPreselectedIds = $labourInspectorContacts->id ?: []; + + if (!empty($labourdInspectorSociete)) { + $labourInspectorPreselectedIds = array_merge($labourInspectorPreselectedIds, [$lastInspectorContactId]); + } if ($labourInspectorContacts->id) { - print $form->selectcontacts(empty($labourdInspectorSociete->id[0]) ? -1 : $labourdInspectorSociete->id[0], $labourInspectorContacts->id, 'labourinspector_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourinspector_contactid'); + print $form->selectcontacts(empty($labourdInspectorSociete->id[0]) ? -1 : $labourdInspectorSociete->id[0], $labourInspectorPreselectedIds, 'labourinspector_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourinspector_contactid'); } else { - $labourInspectorPreselectedIds = GETPOST('labourinspector_contactid', 'array'); + $labourInspectorPreselectedIds = array_merge($labourInspectorPreselectedIds, GETPOST('labourinspector_contactid', 'array')); if (GETPOST('labourinspector_contactid', 'array')) { $labourInspectorPreselectedIds[GETPOST('labourinspector_contactid', 'array')] = GETPOST('labourinspector_contactid', 'array'); } - print $form->selectcontacts(empty(GETPOST('labourinspector_socid', 'int')) ? -1 : GETPOST('labourinspector_socid', 'int'), $labourInspectorPreselectedIds, 'labourinspector_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourinspector_contactid'); + print $form->selectcontacts(empty(GETPOST('labourinspector_socid', 'int')) ? $labourdInspectorSociete->id[0] : GETPOST('labourinspector_socid', 'int'), $labourInspectorPreselectedIds, 'labourinspector_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourinspector_contactid'); } if (!GETPOSTISSET('backtopage')) { - print ' '; + print ' '; } print ''; From 5170e0d1ca5660c7d0ffd4e519b9c2dec2ace24d Mon Sep 17 00:00:00 2001 From: evarisk-micka Date: Thu, 4 Apr 2024 09:56:35 +0200 Subject: [PATCH 3/4] #730 [Admin] fix: use only two actions and getpost type --- admin/securityconf.php | 69 +++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/admin/securityconf.php b/admin/securityconf.php index 1f9436a09..3ce0aa8e5 100644 --- a/admin/securityconf.php +++ b/admin/securityconf.php @@ -50,6 +50,7 @@ // Parameters $action = GETPOST('action', 'aZ09'); +$type = GETPOST('type'); $error = 0; // Initialize technical objects @@ -70,7 +71,7 @@ * Actions */ -$parameters = array(); +$parameters = []; $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); @@ -78,8 +79,8 @@ $labourDoctorId[0] = GETPOST('labourdoctor_socid', 'int') > 0 ? GETPOST('labourdoctor_socid', 'int') : 0 ; $labourInspectorId[0] = GETPOST('labourinspector_socid', 'int') > 0 ? GETPOST('labourinspector_socid', 'int') : 0; - $labourDoctorSocpeopleAssigned = ! empty(GETPOST('labourdoctor_contactid', 'array')) ? GETPOST('labourdoctor_contactid', 'array') : (GETPOST('labourdoctor_contactid', 'int') > 0 ? array(GETPOST('labourdoctor_contactid', 'int')) : array()); - $labourInspectorSocpeopleAssigned = ! empty(GETPOST('labourinspector_contactid', 'array')) ? GETPOST('labourinspector_contactid', 'array') : (GETPOST('labourinspector_contactid', 'int') > 0 ? array(GETPOST('labourinspector_contactid', 'int')) : array()); + $labourDoctorSocpeopleAssigned = !empty(GETPOST('labourdoctor_contactid', 'array')) ? GETPOST('labourdoctor_contactid', 'array') : (GETPOST('labourdoctor_contactid', 'int') > 0 ? array(GETPOST('labourdoctor_contactid', 'int')) : []); + $labourInspectorSocpeopleAssigned = !empty(GETPOST('labourinspector_contactid', 'array')) ? GETPOST('labourinspector_contactid', 'array') : (GETPOST('labourinspector_contactid', 'int') > 0 ? array(GETPOST('labourinspector_contactid', 'int')) : []); $resources->setDigiriskResources($db, $user->id, 'LabourDoctorSociety', 'societe', $labourDoctorId, $conf->entity); $resources->setDigiriskResources($db, $user->id, 'LabourInspectorSociety', 'societe', $labourInspectorId, $conf->entity); @@ -171,6 +172,16 @@ '; +if ($action == 'create_contact') { + $lastContactCreated = saturne_fetch_all_object_type('contact', 'DESC', 'rowid', 1); + $lastContactId = array_key_first($lastContactCreated); + $contact->fetch($lastContactId); +} + +if ($action == 'create_soc') { + $lastSocietyCreated = saturne_fetch_all_object_type('societe', 'DESC', 'rowid', 1); +} + if (isModEnabled('societe')) { /* *** Labour Doctor -- Médecin du travail *** @@ -184,23 +195,17 @@ // * Third party concerned - Tiers concerné * if ($labourdDoctorSociety->ref == 'LabourDoctorSociety') { - $events = array(); + $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 == 'createdoctorcontact') { - $lastDoctorContact = $societe->contact_array(); - $lastDoctorContactId = array_key_last($lastDoctorContact); - } - - if ($action == 'createdoctorsoc') { - $lastSocieteCreated = saturne_fetch_all_object_type('societe', 'DESC', 'rowid', 1); - $labourdDoctorSociety->id[0] = array_key_first($lastSocieteCreated); + 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 = array(); + $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 @@ -211,7 +216,7 @@ } } if (!GETPOSTISSET('backtopage')) { - print ' '; + print ' ref) . '">'; } print ''; @@ -221,21 +226,21 @@ $labourdDoctorContact = $allLinks['LabourDoctorContact']; $labourDoctorPreselectedIds = $labourdDoctorContact->id ?: []; - if (!empty($labourdDoctorSociety)) { - $labourDoctorPreselectedIds = array_merge($labourDoctorPreselectedIds, [$lastDoctorContactId]); + 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, array(), false, 'multiple', 'labourdoctor_contactid'); + 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'); } - print $form->selectcontacts(empty(GETPOST('labourdoctor_socid', 'int')) ? $labourdDoctorSociety->id[0] : GETPOST('labourdoctor_socid', 'int'), $labourDoctorPreselectedIds, 'labourdoctor_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourdoctor_contactid'); + 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 ' '; } print ''; @@ -251,23 +256,17 @@ // * Third party concerned - Tiers concerné * if ($labourdInspectorSociete->ref == 'LabourInspectorSociety') { - $events = array(); + $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 == 'createinspectorcontact') { - $lastInspectorContact = $societe->contact_array(); - $lastInspectorContactId = array_key_last($lastInspectorContact); - } - - if ($action == 'createinspectorsoc') { - $lastSocieteCreated = saturne_fetch_all_object_type('societe', 'DESC', 'rowid', 1); - $labourdInspectorSociete->id[0] = array_key_first($lastSocieteCreated); + if ($action == 'create_soc' && $type == $labourdInspectorSociete->ref) { + $labourdInspectorSociete->id[0] = array_key_first($lastSocietyCreated); } print $form->select_company($labourdInspectorSociete->id[0], 'labourinspector_socid', '', 0, 1, 0, $events, 0, 'minwidth300'); } else { - $events = array(); + $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)) { @@ -277,7 +276,7 @@ } } if (!GETPOSTISSET('backtopage')) { - print ' '; + print ' ref) . '">'; } print ''; @@ -288,21 +287,21 @@ $labourInspectorContacts = $allLinks['LabourInspectorContact']; $labourInspectorPreselectedIds = $labourInspectorContacts->id ?: []; - if (!empty($labourdInspectorSociete)) { - $labourInspectorPreselectedIds = array_merge($labourInspectorPreselectedIds, [$lastInspectorContactId]); + 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, array(), false, 'multiple', 'labourinspector_contactid'); + 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 $form->selectcontacts(empty(GETPOST('labourinspector_socid', 'int')) ? $labourdInspectorSociete->id[0] : GETPOST('labourinspector_socid', 'int'), $labourInspectorPreselectedIds, 'labourinspector_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourinspector_contactid'); + 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 ' '; } print ''; From 0ef43b2584c0b1c1e8287dc7faeff8ae6fa4f357 Mon Sep 17 00:00:00 2001 From: evarisk-micka Date: Thu, 4 Apr 2024 15:42:00 +0200 Subject: [PATCH 4/4] #730 [Admin] fix: clean code and make it shorter --- admin/securityconf.php | 334 ++++++++--------------------------------- 1 file changed, 66 insertions(+), 268 deletions(-) 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 ''; } /*