From 9c290a66ca41619c3ff4b763a99cee9299ab37a7 Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 19 Jun 2026 13:31:00 -0400 Subject: [PATCH] Update mobile registration access functions and enhance event permission checks This commit modifies the mobile registration access logic to utilize the new `fxEveAccesHasInscrMobileWebAccess` function, improving permission handling for mobile event registrations. Additionally, it updates the `fxInscrMobileGetPromoteurEveIds` and `fxInscrMobileCanAccess` functions to streamline access checks. New functions for retrieving event IDs with mobile access permissions are introduced, enhancing overall access control and user experience. --- inc_footer_scripts.php | 2 +- php/inc_fx_eve_acces.php | 89 +++++++++++++++++++++++++----- php/inc_fx_inscriptions_mobile.php | 4 +- 3 files changed, 78 insertions(+), 17 deletions(-) diff --git a/inc_footer_scripts.php b/inc_footer_scripts.php index f2c03a8..36187fd 100644 --- a/inc_footer_scripts.php +++ b/inc_footer_scripts.php @@ -1225,7 +1225,7 @@ if ($strLangue == 'fr') { $preloader_text.html(''); $preloader.show(); - pendingStatutXhr = $.post('/ajax_promoteur.php', { + pendingStatutXhr = $.post('/ajax_inscr_mobile.php', { a: 'par_statut_course', par_id: intParId, par_statut_course: strCode, diff --git a/php/inc_fx_eve_acces.php b/php/inc_fx_eve_acces.php index 9d0cf86..9157410 100644 --- a/php/inc_fx_eve_acces.php +++ b/php/inc_fx_eve_acces.php @@ -119,6 +119,55 @@ function fxEveAccesGetEventIds($intComId) return $arrIds; } +/** Acces web mobile : vue API/page OU au moins une permission action inscriptions_mobile.* */ +function fxEveAccesHasInscrMobileWebAccess($intComId, $intEveId) +{ + if (fxEveAccesHasAnyPermission(intval($intComId), intval($intEveId), array('registrations.view', 'inscriptions_mobile.view'))) { + return true; + } + + global $objDatabase; + + if (!fxEveAccesIsEnabled()) { + return false; + } + + $sql = "SELECT COUNT(*) FROM v_eve_acces_permissions + WHERE com_id = " . intval($intComId) . " + AND eve_id = " . intval($intEveId) . " + AND perm_key LIKE 'inscriptions_mobile.%'"; + $intNb = $objDatabase->fxGetVar($sql); + + return ($intNb != null && intval($intNb) > 0); +} + +function fxEveAccesGetEventIdsWithInscrMobileAccess($intComId) +{ + global $objDatabase; + + if (!fxEveAccesIsEnabled()) { + return array(); + } + + $sql = "SELECT DISTINCT eve_id FROM v_eve_acces_permissions + WHERE com_id = " . intval($intComId) . " + AND ( + perm_key IN ('registrations.view', 'inscriptions_mobile.view') + OR perm_key LIKE 'inscriptions_mobile.%' + ) + ORDER BY eve_id ASC"; + $tab = $objDatabase->fxGetResults($sql); + $arrIds = array(); + + if ($tab != null) { + foreach ($tab as $row) { + $arrIds[] = intval($row['eve_id']); + } + } + + return $arrIds; +} + function fxEveAccesHasPermission($intComId, $intEveId, $strPermKey) { global $objDatabase; @@ -596,10 +645,8 @@ function fxEveAccesShowCompteForm($intComId) Aucun acces v2 pour ce compte.'; - } else { - $arrPermsByEve = array(); + $arrPermsByEve = array(); + if ($arrAcces != null && count($arrAcces) > 0) { foreach ($arrAcces as $row) { $blnActif = ($row['ea_statut'] === 'actif' && (empty($row['ea_expires_at']) || strtotime($row['ea_expires_at']) > time())); @@ -636,19 +683,33 @@ function fxEveAccesShowCompteForm($intComId) } } } + } - foreach ($arrPermsByEve as $intEveKey => $arrEveMeta) { - $arrPerms = fxEveAccesGetPermissionsForComEvent($intComId, $intEveKey); - if ($arrPerms != null && count($arrPerms) > 0) { - $arrKeys = array(); - foreach ($arrPerms as $p) { - $arrKeys[] = $p['perm_key']; - } - echo 'Droits effectifs — ' - . htmlspecialchars($arrEveMeta['label']) . ' #' . $intEveKey . ' : ' - . htmlspecialchars(implode(', ', $arrKeys)) . ''; + $arrEveIdsEffectifs = fxEveAccesGetEventIdsWithInscrMobileAccess($intComId); + foreach ($arrEveIdsEffectifs as $intEveKey) { + $arrPerms = fxEveAccesGetPermissionsForComEvent($intComId, $intEveKey); + if ($arrPerms == null || count($arrPerms) === 0) { + continue; + } + $arrKeys = array(); + foreach ($arrPerms as $p) { + $arrKeys[] = $p['perm_key']; + } + $strEveLbl = isset($arrPermsByEve[$intEveKey]['label']) + ? $arrPermsByEve[$intEveKey]['label'] + : ('eve_id ' . $intEveKey); + if (!isset($arrPermsByEve[$intEveKey])) { + $tabEveNom = $objDatabase->fxGetVar('SELECT eve_nom_fr FROM inscriptions_evenements WHERE eve_id = ' . intval($intEveKey) . ' LIMIT 1'); + if ($tabEveNom !== null && trim((string)$tabEveNom) !== '') { + $strEveLbl = $tabEveNom; } } + echo 'Droits effectifs — ' + . htmlspecialchars($strEveLbl) . ' #' . intval($intEveKey) . ' : ' + . htmlspecialchars(implode(', ', $arrKeys)) . ''; + } + if (($arrAcces == null || count($arrAcces) === 0) && empty($arrEveIdsEffectifs)) { + echo 'Aucun acces v2 pour ce compte.'; } ?> diff --git a/php/inc_fx_inscriptions_mobile.php b/php/inc_fx_inscriptions_mobile.php index a8e8cac..3974e6a 100644 --- a/php/inc_fx_inscriptions_mobile.php +++ b/php/inc_fx_inscriptions_mobile.php @@ -72,12 +72,12 @@ function fxInscrMobileLoadEveAcces() { */ function fxInscrMobileGetPromoteurEveIds($intComId) { fxInscrMobileLoadEveAcces(); - return fxEveAccesGetEventIdsWithAnyPermission(intval($intComId), fxInscrMobilePermKeysView()); + return fxEveAccesGetEventIdsWithInscrMobileAccess(intval($intComId)); } function fxInscrMobileCanAccess($intComId, $intEveId) { fxInscrMobileLoadEveAcces(); - return fxEveAccesHasAnyPermission(intval($intComId), intval($intEveId), fxInscrMobilePermKeysView()); + return fxEveAccesHasInscrMobileWebAccess(intval($intComId), intval($intEveId)); } function fxInscrMobileCanScan($intComId, $intEveId) {