diff --git a/admin/securityconf.php b/admin/securityconf.php index 2645ec078..fe88bb8b0 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,249 +172,87 @@ '; -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 = 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'); - } 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')); - - //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 ' '; - print ''; - - // * Related contacts - Contacts associés * - print '' . $langs->trans("ActionOnContact") . ''; - - $labourdDoctorContact = $allLinks['LabourDoctorContact']; - $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'); - } 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'); - } - 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 = array(); - $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]); - - print $form->select_company($labourdInspectorSociete->id[0], 'labourinspector_socid', '', 0, 1, 0, $events, 0, 'minwidth300'); - } else { - $events = array(); - $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 ' '; - print ''; - - // * Related contacts - Contacts associés * - - print '' . $langs->trans("ActionOnContact") . ''; - - $labourInspectorContacts = $allLinks['LabourInspectorContact']; - $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'); - } 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'); - } - 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']; +if ($action == 'create_contact') { + $lastContactCreated = saturne_fetch_all_object_type('contact', 'DESC', 'rowid', 1); + $lastContactId = array_key_first($lastContactCreated); + $contact->fetch($lastContactId); +} - // * Third party concerned - Tiers concerné * +if ($action == 'create_soc') { + $lastSocietyCreated = saturne_fetch_all_object_type('societe', 'DESC', 'rowid', 1); +} - 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 ''; +if (isModEnabled('societe')) { + $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'); + } + } + if (!GETPOSTISSET('backtopage')) { + print ' ref) . '">'; + } + 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 ''; + } + } } /*