From 591d93d69987c44c75b1fa8da5823ebca8897eae Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 13 Jul 2026 10:11:19 -0400 Subject: [PATCH] Implement event access invitation and revocation handling in compte.php, ensuring proper processing before HTML output to prevent blank pages. Update inc_tableau_eve_acces.php to reflect new error handling and success messaging. Enhance fxEveAccesPromoteurInvite function to handle mail sending failures gracefully. This aligns with MSIN-4401 requirements for improved event management functionality. --- compte.php | 44 ++++++++++++++++++++++++++++++ inc_tableau_eve_acces.php | 40 +++++++++------------------ php/inc_fx_eve_acces_promoteur.php | 12 ++++++-- 3 files changed, 66 insertions(+), 30 deletions(-) diff --git a/compte.php b/compte.php index 8dadf5f..b87cf88 100644 --- a/compte.php +++ b/compte.php @@ -378,6 +378,50 @@ $strMetaKeywords = fxRemoveHtml(fxUnescape($recPage['pag_keywords_' . $strLangue $blnBoutonRetour = true; $blnHideCompteTitle = false; +// MSIN-4401 — POST invite/revoke AVANT le HTML (sinon header Location → page blanche). +if ($strCode === 'compte_inc_tableau_eve_acces' + && ($_SERVER['REQUEST_METHOD'] ?? '') === 'POST' + && isset($_GET['promoteur_eve_id'])) { + require_once('php/inc_fx_eve_acces_promoteur.php'); + $intEveIdPost = intval(base64_decode(urldecode($_GET['promoteur_eve_id']))); + $intActorPost = intval($_SESSION['com_id'] ?? 0); + if (!empty($_SESSION['usa_id'])) { + $intActorPost = intval($_SESSION['usa_id']); + } + $strLanguePost = ($strLangue === 'en') ? 'en' : 'fr'; + $strBasePathPost = ($strLanguePost === 'en') ? '/account' : '/compte'; + $strSelfUrlPost = $vDomaine . $strBasePathPost . '/inc_tableau_eve_acces?promoteur_eve_id=' + . urlencode(base64_encode($intEveIdPost)) . '&lng=' . $strLanguePost; + + if ($intEveIdPost > 0 && fxEveAccesCanTeamInvite($intActorPost, $intEveIdPost)) { + $strEveAccesAction = (string)($_POST['eve_acces_action'] ?? ''); + if ($strEveAccesAction === 'invite') { + $arrEveAccesResult = fxEveAccesPromoteurInvite($intEveIdPost, $intActorPost, $_POST, $strLanguePost); + if (($arrEveAccesResult['state'] ?? '') === 'success') { + header('Location: ' . $strSelfUrlPost . '&ok=' . urlencode($arrEveAccesResult['message'])); + exit; + } + header('Location: ' . $strSelfUrlPost . '&err=' . urlencode( + $arrEveAccesResult['message'] ?? fxEveAccesPromoteurT('eve_acces_promoteur_err_generic', $strLanguePost) + )); + exit; + } + if ($strEveAccesAction === 'revoke') { + $arrEveAccesResult = fxEveAccesPromoteurRevoke(intval($_POST['ea_id'] ?? 0), $intActorPost, $intEveIdPost); + if (($arrEveAccesResult['state'] ?? '') === 'success') { + header('Location: ' . $strSelfUrlPost . '&ok=' . urlencode( + fxEveAccesPromoteurT('eve_acces_promoteur_ok_revoked', $strLanguePost) + )); + exit; + } + header('Location: ' . $strSelfUrlPost . '&err=' . urlencode( + fxEveAccesPromoteurT('eve_acces_promoteur_err_revoke', $strLanguePost) + )); + exit; + } + } +} + require_once("inc_header.php"); ?> diff --git a/inc_tableau_eve_acces.php b/inc_tableau_eve_acces.php index a8b8bf6..b997b10 100644 --- a/inc_tableau_eve_acces.php +++ b/inc_tableau_eve_acces.php @@ -2,6 +2,7 @@ /** * MSIN-4401 — Gestion des accès V2 (promoteur, par événement). + * Les POST invite/revoke sont traités dans compte.php AVANT inc_header (évite page blanche). */ include_once('php/inc_fx_promoteur.php'); @@ -31,39 +32,24 @@ if (!empty($_SESSION['usa_id'])) { if ($intEveId <= 0 || (empty($_SESSION['com_id']) && empty($_SESSION['usa_id'])) || !fxEveAccesCanTeamInvite($intActor, $intEveId)) { - header('Location: ' . $strRedirect); - exit; + // Headers déjà envoyés (include après layout) : message + lien, pas de header Location. + echo '
'; + echo fxEveAccesPromoteurEsc( + $strLangue === 'en' ? 'Access denied.' : 'Accès refusé.' + ); + echo ' '; + echo fxEveAccesPromoteurEsc($strLangue === 'en' ? 'Back' : 'Retour'); + echo '
'; + return; } $strFlash = ''; $strError = ''; -$strSelfUrl = $vDomaine . $strBasePath . '/inc_tableau_eve_acces?promoteur_eve_id=' - . urlencode(base64_encode($intEveId)) . '&lng=' . $strLangue; - -if ($_SERVER['REQUEST_METHOD'] === 'POST') { - $strAction = (string)($_POST['eve_acces_action'] ?? ''); - - if ($strAction === 'invite') { - $arrResult = fxEveAccesPromoteurInvite($intEveId, $intActor, $_POST, $strLangue); - if (($arrResult['state'] ?? '') === 'success') { - header('Location: ' . $strSelfUrl . '&ok=' . urlencode($arrResult['message'])); - exit; - } - $strError = $arrResult['message'] ?? fxEveAccesPromoteurT('eve_acces_promoteur_err_generic', $strLangue); - } elseif ($strAction === 'revoke') { - $arrResult = fxEveAccesPromoteurRevoke(intval($_POST['ea_id'] ?? 0), $intActor, $intEveId); - if (($arrResult['state'] ?? '') === 'success') { - header('Location: ' . $strSelfUrl . '&ok=' . urlencode( - fxEveAccesPromoteurT('eve_acces_promoteur_ok_revoked', $strLangue) - )); - exit; - } - $strError = fxEveAccesPromoteurT('eve_acces_promoteur_err_revoke', $strLangue); - } -} - if (!empty($_GET['ok'])) { $strFlash = (string)$_GET['ok']; } +if (!empty($_GET['err'])) { + $strError = (string)$_GET['err']; +} fxEveAccesPromoteurRenderPage($intEveId, $strLangue, $strFlash, $strError); diff --git a/php/inc_fx_eve_acces_promoteur.php b/php/inc_fx_eve_acces_promoteur.php index 720ffb4..4013bc5 100644 --- a/php/inc_fx_eve_acces_promoteur.php +++ b/php/inc_fx_eve_acces_promoteur.php @@ -338,7 +338,8 @@ function fxEveAccesPromoteurInvite($intEveId, $intGrantedBy, $arrPost, $strLangu $arrRole = $objDatabase->fxGetRow( 'SELECT role_id, role_code, role_label_fr, role_label_en FROM inscriptions_eve_roles WHERE role_id = ' . $intRoleId . ' LIMIT 1' ); - if ($arrEve === null || $arrRole === null) { + // fxGetRow peut retourner false (pas null) selon l'environnement. + if (empty($arrEve) || empty($arrRole)) { return array('state' => 'error', 'message' => fxEveAccesPromoteurT('eve_acces_promoteur_err_generic', $strLangue)); } @@ -354,7 +355,7 @@ function fxEveAccesPromoteurInvite($intEveId, $intGrantedBy, $arrPost, $strLangu $strResetToken = ''; $arrCompte = null; - if ($rowExisting !== null) { + if (!empty($rowExisting) && is_array($rowExisting)) { if (intval($rowExisting['com_actif']) !== 1) { return array('state' => 'error', 'message' => fxEveAccesPromoteurT('eve_acces_promoteur_err_inactive', $strLangue)); } @@ -414,7 +415,12 @@ function fxEveAccesPromoteurInvite($intEveId, $intGrantedBy, $arrPost, $strLangu ); } - fxEveAccesPromoteurSendInviteMail($arrCompte, $arrEve, $arrRole, $strLangue, $blnCreated, $strResetToken); + // L'accès est déjà enregistré : un échec mail ne doit pas faire planter la page. + try { + fxEveAccesPromoteurSendInviteMail($arrCompte, $arrEve, $arrRole, $strLangue, $blnCreated, $strResetToken); + } catch (Throwable $e) { + // ignore + } return array( 'state' => 'success',