183 lines
4.6 KiB
PHP
183 lines
4.6 KiB
PHP
<?php
|
||
/**
|
||
* MSIN-3756 — Superadm : agir comme promoteur sur un événement (session only).
|
||
* N’écrit pas dans com_eve_promoteur / inscriptions_eve_acces.
|
||
* Droits = fxIsPromoteur (legacy promoteur), pas les kits V2 hors périmètre.
|
||
*/
|
||
|
||
/**
|
||
* Pose le flag session pour un événement et aligne le canal public (com_id) si besoin.
|
||
*
|
||
* @param int $intEveId
|
||
* @return bool
|
||
*/
|
||
function fxActAsPromoteurSet($intEveId)
|
||
{
|
||
$intEveId = intval($intEveId);
|
||
if ($intEveId <= 0 || empty($_SESSION['usa_id'])) {
|
||
return false;
|
||
}
|
||
|
||
$_SESSION['ms1_act_as_promoteur_eve'] = $intEveId;
|
||
|
||
// Les pages compte / site public exigent com_id ; ops n’a souvent que usa_id.
|
||
if (empty($_SESSION['com_id']) && !empty($_SESSION['usa_info']) && is_array($_SESSION['usa_info'])) {
|
||
$_SESSION['com_id'] = intval($_SESSION['usa_id']);
|
||
$_SESSION['com_info'] = $_SESSION['usa_info'];
|
||
if (isset($_SESSION['usa_info']['com_eve_prive'])) {
|
||
$_SESSION['com_info']['eve_prive'] = explode(',', (string)$_SESSION['usa_info']['com_eve_prive']);
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* @return int
|
||
*/
|
||
function fxActAsPromoteurGetEveId()
|
||
{
|
||
if (empty($_SESSION['usa_id'])) {
|
||
return 0;
|
||
}
|
||
|
||
return intval($_SESSION['ms1_act_as_promoteur_eve'] ?? 0);
|
||
}
|
||
|
||
/**
|
||
* @param int $intEveId
|
||
* @return bool
|
||
*/
|
||
function fxActAsPromoteurAllows($intEveId)
|
||
{
|
||
$intEveId = intval($intEveId);
|
||
$intSessionEve = fxActAsPromoteurGetEveId();
|
||
|
||
return ($intEveId > 0 && $intSessionEve === $intEveId);
|
||
}
|
||
|
||
function fxActAsPromoteurClear()
|
||
{
|
||
unset($_SESSION['ms1_act_as_promoteur_eve']);
|
||
}
|
||
|
||
/**
|
||
* URL interface promoteur legacy pour l’événement (même gate que promoteur_eve_id).
|
||
*
|
||
* @param int $intEveId
|
||
* @param string $strLangue
|
||
* @return string
|
||
*/
|
||
function fxActAsPromoteurUrl($intEveId, $strLangue = 'fr')
|
||
{
|
||
global $vDomaine;
|
||
|
||
$intEveId = intval($intEveId);
|
||
$strPage = ($strLangue === 'en') ? 'account' : 'compte';
|
||
|
||
return $vDomaine . '/' . $strPage . '/inc_tableau_promoteur?promoteur_eve_id='
|
||
. urlencode(base64_encode((string)$intEveId));
|
||
}
|
||
|
||
/**
|
||
* URL pour quitter le mode promoteur session.
|
||
*
|
||
* @return string
|
||
*/
|
||
function fxActAsPromoteurQuitUrl()
|
||
{
|
||
global $vDomaine;
|
||
|
||
return $vDomaine . '/superadm/logout_promoteur.php';
|
||
}
|
||
|
||
/**
|
||
* Libellé événement pour la barre (Nom (#id)).
|
||
*
|
||
* @param int $intEveId
|
||
* @return string
|
||
*/
|
||
function fxActAsPromoteurEveLabel($intEveId)
|
||
{
|
||
global $objDatabase, $db;
|
||
|
||
$intEveId = intval($intEveId);
|
||
if ($intEveId <= 0) {
|
||
return '';
|
||
}
|
||
|
||
$objDb = isset($objDatabase) ? $objDatabase : (isset($db) ? $db : null);
|
||
if ($objDb === null) {
|
||
return '#' . $intEveId;
|
||
}
|
||
|
||
$row = $objDb->fxGetRow(
|
||
'SELECT eve_nom_fr, eve_nom_en FROM inscriptions_evenements WHERE eve_id = ' . $intEveId
|
||
);
|
||
if ($row === null) {
|
||
return '#' . $intEveId;
|
||
}
|
||
|
||
$strNom = trim((string)($row['eve_nom_fr'] ?? ''));
|
||
if ($strNom === '') {
|
||
$strNom = trim((string)($row['eve_nom_en'] ?? ''));
|
||
}
|
||
if ($strNom === '') {
|
||
return '#' . $intEveId;
|
||
}
|
||
|
||
if (function_exists('fxUnescape')) {
|
||
$strNom = fxUnescape($strNom);
|
||
}
|
||
|
||
return $strNom . ' (#' . $intEveId . ')';
|
||
}
|
||
|
||
/**
|
||
* HTML inline à injecter dans la bande environnement.
|
||
*
|
||
* @return string
|
||
*/
|
||
function fxActAsPromoteurInlineHtml()
|
||
{
|
||
$intEveId = fxActAsPromoteurGetEveId();
|
||
if ($intEveId <= 0) {
|
||
return '';
|
||
}
|
||
|
||
$strLabel = fxActAsPromoteurEveLabel($intEveId);
|
||
$strQuit = fxActAsPromoteurQuitUrl();
|
||
|
||
return ' <span class="ms1-act-as-promoteur">'
|
||
. '| Mode promoteur : <strong>' . htmlspecialchars($strLabel, ENT_QUOTES, 'UTF-8') . '</strong>'
|
||
. ' <a class="btn btn-sm btn-light py-0 px-2 ml-2" href="' . htmlspecialchars($strQuit, ENT_QUOTES, 'UTF-8') . '">'
|
||
. 'Quitter</a>'
|
||
. '</span>';
|
||
}
|
||
|
||
/**
|
||
* Injecte le marqueur promoteur dans le HTML de la bande env (avant le dernier </div>).
|
||
*
|
||
* @param string $strNoticeHtml
|
||
* @return string
|
||
*/
|
||
function fxActAsPromoteurInjectEnvNotice($strNoticeHtml)
|
||
{
|
||
$strExtra = fxActAsPromoteurInlineHtml();
|
||
if ($strExtra === '') {
|
||
return (string)$strNoticeHtml;
|
||
}
|
||
|
||
$strNoticeHtml = trim((string)$strNoticeHtml);
|
||
if ($strNoticeHtml === '') {
|
||
return '<div class="alert-warning py-2 text-center sticky-top">' . $strExtra . '</div>';
|
||
}
|
||
|
||
$intPos = strrpos($strNoticeHtml, '</div>');
|
||
if ($intPos === false) {
|
||
return $strNoticeHtml . $strExtra;
|
||
}
|
||
|
||
return substr($strNoticeHtml, 0, $intPos) . $strExtra . substr($strNoticeHtml, $intPos);
|
||
}
|