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.

This commit is contained in:
2026-07-13 10:11:19 -04:00
parent 5cd00a1ff1
commit 591d93d699
3 changed files with 66 additions and 30 deletions

View File

@ -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");
?>

View File

@ -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 '<div class="alert alert-warning">';
echo fxEveAccesPromoteurEsc(
$strLangue === 'en' ? 'Access denied.' : 'Accès refusé.'
);
echo ' <a href="' . htmlspecialchars($strRedirect, ENT_QUOTES, 'UTF-8') . '">';
echo fxEveAccesPromoteurEsc($strLangue === 'en' ? 'Back' : 'Retour');
echo '</a></div>';
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);

View File

@ -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',