Files
ms1inscription-v5/php/inc_fx_eve_acces.php
2026-06-23 14:19:57 -04:00

1005 lines
35 KiB
PHP

<?php
/**
* Acces evenement v2 — parallele au legacy com_eve_promoteur.
* Ne modifie jamais les champs legacy.
*/
function fxEveAccesIsEnabled()
{
static $blnEnabled = null;
if ($blnEnabled !== null) {
return $blnEnabled;
}
global $objDatabase;
if (!isset($objDatabase)) {
$blnEnabled = false;
return $blnEnabled;
}
$tab = $objDatabase->fxGetResults("SHOW TABLES LIKE 'inscriptions_eve_acces'");
$blnEnabled = ($tab != null && count($tab) > 0);
return $blnEnabled;
}
function fxEveAccesGetRoles($blnActifOnly = true)
{
global $objDatabase;
if (!fxEveAccesIsEnabled()) {
return array();
}
$sql = "SELECT role_id, role_code, role_label_fr, role_label_en, role_description_fr
FROM inscriptions_eve_roles";
if ($blnActifOnly) {
$sql .= " WHERE role_actif = 1";
}
$sql .= " ORDER BY role_tri ASC, role_label_fr ASC";
return $objDatabase->fxGetResults($sql);
}
function fxEveAccesListByComId($intComId)
{
global $objDatabase;
if (!fxEveAccesIsEnabled()) {
return array();
}
$sql = "SELECT ea.ea_id, ea.com_id, ea.eve_id, ea.role_id, ea.ea_statut,
ea.ea_expires_at, ea.ea_expire_days, ea.ea_granted_by, ea.ea_note,
ea.ea_created_at, ea.ea_revoked_at,
r.role_code, r.role_label_fr,
e.eve_nom_fr, e.eve_date_fin
FROM inscriptions_eve_acces ea
INNER JOIN inscriptions_eve_roles r ON r.role_id = ea.role_id
LEFT JOIN inscriptions_evenements e ON e.eve_id = ea.eve_id
WHERE ea.com_id = " . intval($intComId) . "
ORDER BY ea.ea_statut ASC, e.eve_date_fin DESC, ea.ea_created_at DESC";
return $objDatabase->fxGetResults($sql);
}
function fxEveAccesComHasV2($intComId)
{
global $objDatabase;
if (!fxEveAccesIsEnabled()) {
return false;
}
$sql = "SELECT COUNT(*) FROM v_eve_acces_actif WHERE com_id = " . intval($intComId);
$intNb = $objDatabase->fxGetVar($sql);
return ($intNb != null && intval($intNb) > 0);
}
function fxEveAccesComHasV2ForEvent($intComId, $intEveId)
{
global $objDatabase;
if (!fxEveAccesIsEnabled()) {
return false;
}
$sql = "SELECT COUNT(*) FROM v_eve_acces_actif
WHERE com_id = " . intval($intComId) . "
AND eve_id = " . intval($intEveId);
$intNb = $objDatabase->fxGetVar($sql);
return ($intNb != null && intval($intNb) > 0);
}
function fxEveAccesGetEventIds($intComId)
{
global $objDatabase;
if (!fxEveAccesIsEnabled()) {
return array();
}
$sql = "SELECT eve_id FROM v_eve_acces_actif WHERE com_id = " . intval($intComId);
$tab = $objDatabase->fxGetResults($sql);
$arrIds = array();
if ($tab != null) {
foreach ($tab as $row) {
$arrIds[] = (string) intval($row['eve_id']);
}
}
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;
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 = '" . $objDatabase->fxEscape($strPermKey) . "'";
$intNb = $objDatabase->fxGetVar($sql);
return ($intNb != null && intval($intNb) > 0);
}
function fxEveAccesHasAnyPermission($intComId, $intEveId, $arrPermKeys)
{
global $objDatabase;
if (!fxEveAccesIsEnabled() || empty($arrPermKeys)) {
return false;
}
$arrEsc = array();
foreach ($arrPermKeys as $strKey) {
$arrEsc[] = "'" . $objDatabase->fxEscape($strKey) . "'";
}
$sql = "SELECT COUNT(*) FROM v_eve_acces_permissions
WHERE com_id = " . intval($intComId) . "
AND eve_id = " . intval($intEveId) . "
AND perm_key IN (" . implode(',', $arrEsc) . ")";
$intNb = $objDatabase->fxGetVar($sql);
return ($intNb != null && intval($intNb) > 0);
}
function fxEveAccesGetEventIdsWithAnyPermission($intComId, $arrPermKeys)
{
global $objDatabase;
if (!fxEveAccesIsEnabled() || empty($arrPermKeys)) {
return array();
}
$arrEsc = array();
foreach ($arrPermKeys as $strKey) {
$arrEsc[] = "'" . $objDatabase->fxEscape($strKey) . "'";
}
$sql = "SELECT DISTINCT eve_id FROM v_eve_acces_permissions
WHERE com_id = " . intval($intComId) . "
AND perm_key IN (" . implode(',', $arrEsc) . ")
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;
}
/** Outil debug QR — permission v2 tools.qr_test uniquement (pas de bypass super admin). */
function fxEveAccesCanQrTest($intComId)
{
if (!fxEveAccesIsEnabled() || intval($intComId) <= 0) {
return false;
}
global $objDatabase;
$sql = "SELECT COUNT(*) FROM v_eve_acces_permissions
WHERE com_id = " . intval($intComId) . "
AND perm_key = 'tools.qr_test'";
$intNb = $objDatabase->fxGetVar($sql);
return ($intNb != null && intval($intNb) > 0);
}
function fxEveAccesGetCatalogPermissions($strScope = null, $blnActifOnly = true)
{
global $objDatabase;
if (!fxEveAccesIsEnabled()) {
return array();
}
$sql = "SELECT perm_key, perm_group, perm_scope, perm_label_fr, perm_label_en, perm_phase, perm_tri
FROM inscriptions_eve_permissions";
$arrWhere = array();
if ($blnActifOnly) {
$arrWhere[] = 'perm_actif = 1';
}
if ($strScope !== null && $strScope !== '') {
$arrWhere[] = "perm_scope = '" . $objDatabase->fxEscape($strScope) . "'";
}
if (!empty($arrWhere)) {
$sql .= ' WHERE ' . implode(' AND ', $arrWhere);
}
$sql .= ' ORDER BY perm_group ASC, perm_tri ASC, perm_key ASC';
return $objDatabase->fxGetResults($sql);
}
function fxEveAccesListExtraByComId($intComId)
{
global $objDatabase;
if (!fxEveAccesIsEnabled()) {
return array();
}
$sql = "SELECT ae.ae_id, ae.com_id, ae.eve_id, ae.perm_key, ae.ae_statut, ae.ae_created_at,
p.perm_label_fr, p.perm_scope,
e.eve_nom_fr
FROM inscriptions_eve_acces_extra ae
INNER JOIN inscriptions_eve_permissions p ON p.perm_key = ae.perm_key
LEFT JOIN inscriptions_evenements e ON e.eve_id = ae.eve_id
WHERE ae.com_id = " . intval($intComId) . "
ORDER BY ae.ae_statut ASC, e.eve_date_fin DESC, p.perm_group ASC, p.perm_tri ASC";
return $objDatabase->fxGetResults($sql);
}
function fxEveAccesGrantExtra($intComId, $intEveId, $strPermKey, $intGrantedBy, $strNote = '')
{
global $objDatabase;
if (!fxEveAccesIsEnabled()) {
return array('state' => 'error', 'message' => 'Tables v2 non installees');
}
$intComId = intval($intComId);
$intEveId = intval($intEveId);
$strPermKey = trim((string)$strPermKey);
if ($intComId <= 0 || $intEveId <= 0 || $strPermKey === '') {
return array('state' => 'error', 'message' => 'Parametres invalides');
}
$tabPerm = $objDatabase->fxGetRow(
"SELECT perm_key FROM inscriptions_eve_permissions
WHERE perm_key = '" . $objDatabase->fxEscape($strPermKey) . "' AND perm_actif = 1 LIMIT 1"
);
if ($tabPerm == null) {
return array('state' => 'error', 'message' => 'Permission invalide');
}
$strNote = $objDatabase->fxEscape(trim($strNote));
$strGrantedBy = (intval($intGrantedBy) > 0) ? intval($intGrantedBy) : 'NULL';
$sql = "INSERT INTO inscriptions_eve_acces_extra
(com_id, eve_id, perm_key, ae_statut, ae_granted_by, ae_note)
VALUES
($intComId, $intEveId, '" . $objDatabase->fxEscape($strPermKey) . "', 'actif', $strGrantedBy, '$strNote')
ON DUPLICATE KEY UPDATE
ae_statut = 'actif',
ae_granted_by = VALUES(ae_granted_by),
ae_note = VALUES(ae_note),
ae_revoked_at = NULL,
ae_updated_at = NOW()";
$objDatabase->fxQuery($sql);
$intAeId = intval($objDatabase->fxGetVar(
"SELECT ae_id FROM inscriptions_eve_acces_extra
WHERE com_id = $intComId AND eve_id = $intEveId
AND perm_key = '" . $objDatabase->fxEscape($strPermKey) . "' LIMIT 1"
));
fxEveAccesWriteLog(null, $intComId, $intEveId, null, 'extra_grant', 'Grant extra: ' . $strPermKey, $intGrantedBy);
return array('state' => 'success', 'ae_id' => $intAeId);
}
function fxEveAccesRevokeExtra($intAeId, $intRevokedBy)
{
global $objDatabase;
if (!fxEveAccesIsEnabled()) {
return array('state' => 'error', 'message' => 'Tables v2 non installees');
}
$intAeId = intval($intAeId);
$tab = $objDatabase->fxGetRow("SELECT * FROM inscriptions_eve_acces_extra WHERE ae_id = " . $intAeId . " LIMIT 1");
if ($tab == null) {
return array('state' => 'error', 'message' => 'Grant extra introuvable');
}
$sql = "UPDATE inscriptions_eve_acces_extra
SET ae_statut = 'revoke',
ae_revoked_at = NOW(),
ae_updated_at = NOW()
WHERE ae_id = " . $intAeId;
$objDatabase->fxQuery($sql);
fxEveAccesWriteLog(null, $tab['com_id'], $tab['eve_id'], null, 'extra_revoke', 'Revoke extra: ' . $tab['perm_key'], $intRevokedBy);
return array('state' => 'success');
}
function fxEveAccesResolveEveIdFromParId($intParId)
{
global $objDatabase;
$intParId = intval($intParId);
if ($intParId <= 0) {
return 0;
}
$intEveId = intval($objDatabase->fxGetVar(
'SELECT eve_id FROM resultats_participants WHERE par_id = ' . $intParId . ' LIMIT 1'
));
return ($intEveId > 0) ? $intEveId : 0;
}
/**
* Gate AJAX promoteur : legacy promoteur OU permission v2 explicite.
* Si le compte a deja des acces v2 actifs, exige la permission demandee.
*/
function fxEveAccesAssertPromoteurAction($intComId, $intEveId, $strPermKey)
{
$intComId = intval($intComId);
$intEveId = intval($intEveId);
if ($intComId <= 0 || $intEveId <= 0) {
return false;
}
if (!fxEveAccesComHasV2ForEvent($intComId, $intEveId)) {
if (!function_exists('fxIsPromoteur')) {
require_once __DIR__ . '/inc_fonctions.php';
}
return fxIsPromoteur($intComId, $intEveId);
}
return fxEveAccesHasPermission($intComId, $intEveId, $strPermKey);
}
function fxEveAccesGrant($intComId, $intEveId, $intRoleId, $intExpireDays, $intGrantedBy, $strNote = '')
{
global $objDatabase;
if (!fxEveAccesIsEnabled()) {
return array('state' => 'error', 'message' => 'Tables v2 non installees');
}
$intComId = intval($intComId);
$intEveId = intval($intEveId);
$intRoleId = intval($intRoleId);
$intGrantedBy = intval($intGrantedBy);
if ($intComId <= 0 || $intEveId <= 0 || $intRoleId <= 0) {
return array('state' => 'error', 'message' => 'Parametres invalides');
}
$tabRole = $objDatabase->fxGetRow("SELECT role_id FROM inscriptions_eve_roles WHERE role_id = " . $intRoleId . " AND role_actif = 1 LIMIT 1");
if ($tabRole == null) {
return array('state' => 'error', 'message' => 'Role invalide');
}
$tabCom = $objDatabase->fxGetRow("SELECT com_id FROM inscriptions_comptes WHERE com_id = " . $intComId . " LIMIT 1");
if ($tabCom == null) {
return array('state' => 'error', 'message' => 'Compte introuvable');
}
$tabEve = $objDatabase->fxGetRow("SELECT eve_id FROM inscriptions_evenements WHERE eve_id = " . $intEveId . " LIMIT 1");
if ($tabEve == null) {
return array('state' => 'error', 'message' => 'Evenement introuvable');
}
$strExpires = 'NULL';
$intExpireDaysStore = 'NULL';
if ($intExpireDays > 0) {
$strExpires = "'" . $objDatabase->fxEscape(date('Y-m-d H:i:s', strtotime('+' . intval($intExpireDays) . ' days'))) . "'";
$intExpireDaysStore = intval($intExpireDays);
}
$strNote = $objDatabase->fxEscape(trim($strNote));
$strGrantedBy = ($intGrantedBy > 0) ? $intGrantedBy : 'NULL';
$sql = "INSERT INTO inscriptions_eve_acces
(com_id, eve_id, role_id, ea_statut, ea_expires_at, ea_expire_days, ea_granted_by, ea_note)
VALUES
($intComId, $intEveId, $intRoleId, 'actif', $strExpires, $intExpireDaysStore, $strGrantedBy, '$strNote')
ON DUPLICATE KEY UPDATE
ea_statut = 'actif',
ea_expires_at = VALUES(ea_expires_at),
ea_expire_days = VALUES(ea_expire_days),
ea_granted_by = VALUES(ea_granted_by),
ea_note = VALUES(ea_note),
ea_revoked_at = NULL,
ea_revoked_by = NULL,
ea_updated_at = NOW()";
$objDatabase->fxQuery($sql);
$intEaId = intval($objDatabase->fxGetVar(
"SELECT ea_id FROM inscriptions_eve_acces
WHERE com_id = $intComId AND eve_id = $intEveId AND role_id = $intRoleId LIMIT 1"
));
fxEveAccesWriteLog($intEaId, $intComId, $intEveId, $intRoleId, 'create', 'Grant / mise a jour acces v2', $intGrantedBy);
return array('state' => 'success', 'ea_id' => $intEaId);
}
function fxEveAccesRevoke($intEaId, $intRevokedBy)
{
global $objDatabase;
if (!fxEveAccesIsEnabled()) {
return array('state' => 'error', 'message' => 'Tables v2 non installees');
}
$intEaId = intval($intEaId);
$tab = $objDatabase->fxGetRow("SELECT * FROM inscriptions_eve_acces WHERE ea_id = " . $intEaId . " LIMIT 1");
if ($tab == null) {
return array('state' => 'error', 'message' => 'Acces introuvable');
}
$sql = "UPDATE inscriptions_eve_acces
SET ea_statut = 'revoke',
ea_revoked_at = NOW(),
ea_revoked_by = " . intval($intRevokedBy) . ",
ea_updated_at = NOW()
WHERE ea_id = " . $intEaId;
$objDatabase->fxQuery($sql);
fxEveAccesWriteLog($intEaId, $tab['com_id'], $tab['eve_id'], $tab['role_id'], 'revoke', 'Revoke manuel super admin', $intRevokedBy);
return array('state' => 'success');
}
function fxEveAccesRowIsActif($row)
{
if ($row['ea_statut'] !== 'actif') {
return false;
}
if (!empty($row['ea_expires_at']) && strtotime($row['ea_expires_at']) <= time()) {
return false;
}
return true;
}
function fxEveAccesReactivate($intEaId, $intGrantedBy)
{
global $objDatabase;
if (!fxEveAccesIsEnabled()) {
return array('state' => 'error', 'message' => 'Tables v2 non installees');
}
$tab = $objDatabase->fxGetRow("SELECT * FROM inscriptions_eve_acces WHERE ea_id = " . intval($intEaId) . " LIMIT 1");
if ($tab == null) {
return array('state' => 'error', 'message' => 'Acces introuvable');
}
$intExpireDays = intval($tab['ea_expire_days'] ?? 0);
return fxEveAccesGrant(
intval($tab['com_id']),
intval($tab['eve_id']),
intval($tab['role_id']),
$intExpireDays,
intval($intGrantedBy),
'Reactivation super admin'
);
}
function fxEveAccesReactivateExtra($intAeId, $intGrantedBy)
{
global $objDatabase;
if (!fxEveAccesIsEnabled()) {
return array('state' => 'error', 'message' => 'Tables v2 non installees');
}
$tab = $objDatabase->fxGetRow("SELECT * FROM inscriptions_eve_acces_extra WHERE ae_id = " . intval($intAeId) . " LIMIT 1");
if ($tab == null) {
return array('state' => 'error', 'message' => 'Grant extra introuvable');
}
return fxEveAccesGrantExtra(
intval($tab['com_id']),
intval($tab['eve_id']),
$tab['perm_key'],
intval($intGrantedBy),
'Reactivation super admin'
);
}
function fxEveAccesWriteLog($intEaId, $intComId, $intEveId, $intRoleId, $strAction, $strDetail, $intByComId)
{
global $objDatabase;
if (!fxEveAccesIsEnabled()) {
return;
}
$intEaId = ($intEaId > 0) ? intval($intEaId) : 'NULL';
$intRoleId = ($intRoleId > 0) ? intval($intRoleId) : 'NULL';
$intByComId = ($intByComId > 0) ? intval($intByComId) : 'NULL';
$sql = "INSERT INTO inscriptions_eve_acces_log
(ea_id, com_id, eve_id, role_id, log_action, log_detail, log_by_com_id)
VALUES
($intEaId, " . intval($intComId) . ", " . intval($intEveId) . ", $intRoleId,
'" . $objDatabase->fxEscape($strAction) . "',
'" . $objDatabase->fxEscape($strDetail) . "',
$intByComId)";
$objDatabase->fxQuery($sql);
}
function fxEveAccesGetPermissionsForComEvent($intComId, $intEveId)
{
global $objDatabase;
if (!fxEveAccesIsEnabled()) {
return array();
}
$sql = "SELECT perm_key, perm_group, perm_label_fr
FROM v_eve_acces_permissions
WHERE com_id = " . intval($intComId) . "
AND eve_id = " . intval($intEveId) . "
ORDER BY perm_group, perm_key";
return $objDatabase->fxGetResults($sql);
}
function fxEveAccesShowCompteForm($intComId)
{
global $objDatabase;
if (!fxEveAccesIsEnabled()) {
echo '<div class="alert alert-warning">Tables acces v2 non installees. Executer les SQL MSIN-eve-acces-v2-phase1.</div>';
return;
}
$arrAcces = fxEveAccesListByComId($intComId);
$arrRoles = fxEveAccesGetRoles(true);
$strT = urlencode($_GET['t'] ?? '');
$intComId = intval($intComId);
?>
<h1 id="eve-acces-v2">Acces v2 (pilote mobile)</h1>
<p class="text-muted">
Systeme parallele au legacy <code>com_eve_promoteur</code>.
<strong>Revoquer</strong> desactive un kit ou une permission (historique conserve).
Pour reactiver : bouton <strong>Reactiver</strong> dans l'historique, ou re-ajouter le meme kit / la meme permission.
</p>
<div class="card mb-3">
<div class="card-header">Ajouter un acces</div>
<div class="card-body">
<div class="form-row">
<div class="form-group col-md-5">
<label>Evenement</label>
<div id="pick-eve-acces-v2">
<input id="pp-eve-acces-v2" type="text" class="form-control" placeholder="Rechercher un evenement...">
<input type="hidden" id="pp-eve-acces-v2-id" value="">
<div id="pp-results-eve-acces-v2" class="list-group d-none"></div>
</div>
</div>
<div class="form-group col-md-3">
<label>Kit (role)</label>
<select id="pp-eve-acces-v2-role" class="form-control">
<option value="">— Choisir —</option>
<?php
if ($arrRoles != null) {
foreach ($arrRoles as $row) {
echo '<option value="' . intval($row['role_id']) . '">'
. htmlspecialchars($row['role_label_fr']) . ' (' . htmlspecialchars($row['role_code']) . ')</option>';
}
}
?>
</select>
</div>
<div class="form-group col-md-2">
<label>Expiration (jours)</label>
<input type="number" id="pp-eve-acces-v2-days" class="form-control" min="0" placeholder="0 = aucune">
</div>
<div class="form-group col-md-2 d-flex align-items-end">
<button type="button" class="btn btn-success btn-block" id="btn-eve-acces-v2-add">
<i class="fa fa-plus"></i> Ajouter
</button>
</div>
</div>
</div>
</div>
<table class="table table-striped table-sm">
<thead>
<tr>
<th>Evenement</th>
<th>Kit</th>
<th>Statut</th>
<th>Expire</th>
<th>Cree</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$arrPermsByEve = array();
$arrAccesActif = array();
$arrAccesRevoke = array();
if ($arrAcces != null) {
foreach ($arrAcces as $row) {
if (fxEveAccesRowIsActif($row)) {
$arrAccesActif[] = $row;
} elseif ($row['ea_statut'] === 'revoke') {
$arrAccesRevoke[] = $row;
}
}
}
if (count($arrAccesActif) === 0) {
echo '<tr><td colspan="6" class="text-muted">Aucun kit actif. Utilisez le formulaire ci-dessus pour en ajouter un.</td></tr>';
} else {
foreach ($arrAccesActif as $row) {
$strExpire = !empty($row['ea_expires_at']) ? htmlspecialchars($row['ea_expires_at']) : '—';
$intEveKey = intval($row['eve_id']);
if (!isset($arrPermsByEve[$intEveKey])) {
$arrPermsByEve[$intEveKey] = array(
'label' => $row['eve_nom_fr'] ?? ('eve_id ' . $intEveKey),
);
}
?>
<tr>
<td>
<strong><?= htmlspecialchars($row['eve_nom_fr'] ?? ('eve_id ' . $row['eve_id'])) ?></strong>
<small class="text-muted">(#<?= intval($row['eve_id']) ?>)</small>
</td>
<td><?= htmlspecialchars($row['role_label_fr']) ?> <small class="text-muted">(<?= htmlspecialchars($row['role_code']) ?>)</small></td>
<td><span class="badge badge-success">actif</span></td>
<td><?= $strExpire ?></td>
<td><small><?= htmlspecialchars($row['ea_created_at']) ?></small></td>
<td class="text-right">
<a href="index.php?t=<?= $strT ?>&amp;a=mod&amp;id=<?= $intComId ?>&amp;action=revokeveacces&amp;ea_id=<?= intval($row['ea_id']) ?>"
class="btn btn-sm btn-danger"
onclick="return confirm('Revoquer ce kit v2 ?');"
title="Desactiver">
<i class="fa fa-ban"></i>
</a>
</td>
</tr>
<?php
}
}
$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 '<tr class="table-info"><td colspan="6"><small><strong>Droits effectifs — '
. htmlspecialchars($strEveLbl) . ' #' . intval($intEveKey) . ' :</strong> '
. htmlspecialchars(implode(', ', $arrKeys)) . '</small></td></tr>';
}
if (count($arrAccesActif) === 0 && empty($arrEveIdsEffectifs)) {
echo '<tr><td colspan="6" class="text-muted">Aucun droit v2 actif pour ce compte.</td></tr>';
}
?>
</tbody>
</table>
<?php if (count($arrAccesRevoke) > 0) { ?>
<details class="mb-3">
<summary class="text-muted small" style="cursor:pointer;">
Historique kits revoques (<?= count($arrAccesRevoke) ?>)
</summary>
<table class="table table-sm table-borderless mt-2 mb-0">
<tbody>
<?php foreach ($arrAccesRevoke as $row) { ?>
<tr class="text-muted">
<td>
<?= htmlspecialchars($row['eve_nom_fr'] ?? ('eve_id ' . $row['eve_id'])) ?>
<small>(#<?= intval($row['eve_id']) ?>)</small>
</td>
<td><?= htmlspecialchars($row['role_label_fr']) ?> (<?= htmlspecialchars($row['role_code']) ?>)</td>
<td><small>revoke <?= htmlspecialchars($row['ea_revoked_at'] ?? '') ?></small></td>
<td class="text-right">
<a href="index.php?t=<?= $strT ?>&amp;a=mod&amp;id=<?= $intComId ?>&amp;action=reactivateveacces&amp;ea_id=<?= intval($row['ea_id']) ?>"
class="btn btn-sm btn-outline-success">
Reactiver
</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</details>
<?php } ?>
<?php
$arrExtras = fxEveAccesListExtraByComId($intComId);
$arrActionPerms = fxEveAccesGetCatalogPermissions('action');
?>
<h2 class="h5 mt-4">Permissions additionnelles (a l'unite)</h2>
<p class="text-muted small">Complement aux kits — ex. autoriser le statut mobile sans le numero de dossard.</p>
<div class="card mb-3">
<div class="card-header">Ajouter une permission</div>
<div class="card-body">
<div class="form-row">
<div class="form-group col-md-4">
<label>Evenement</label>
<div id="pick-eve-acces-extra">
<input id="pp-eve-acces-extra" type="text" class="form-control" placeholder="Rechercher un evenement...">
<input type="hidden" id="pp-eve-acces-extra-id" value="">
<div id="pp-results-eve-acces-extra" class="list-group d-none"></div>
</div>
</div>
<div class="form-group col-md-5">
<label>Permission</label>
<select id="pp-eve-acces-extra-perm" class="form-control">
<option value="">— Choisir —</option>
<?php
if ($arrActionPerms != null) {
foreach ($arrActionPerms as $row) {
echo '<option value="' . htmlspecialchars($row['perm_key']) . '">'
. htmlspecialchars($row['perm_label_fr'])
. ' (' . htmlspecialchars($row['perm_key']) . ')</option>';
}
}
?>
</select>
</div>
<div class="form-group col-md-3 d-flex align-items-end">
<button type="button" class="btn btn-success btn-block" id="btn-eve-acces-extra-add">
<i class="fa fa-plus"></i> Ajouter
</button>
</div>
</div>
</div>
</div>
<table class="table table-striped table-sm">
<thead>
<tr>
<th>Evenement</th>
<th>Permission</th>
<th>Statut</th>
<th>Cree</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$arrExtrasActif = array();
$arrExtrasRevoke = array();
if ($arrExtras != null) {
foreach ($arrExtras as $row) {
if ($row['ae_statut'] === 'actif') {
$arrExtrasActif[] = $row;
} else {
$arrExtrasRevoke[] = $row;
}
}
}
if (count($arrExtrasActif) === 0) {
echo '<tr><td colspan="5" class="text-muted">Aucune permission additionnelle active.</td></tr>';
} else {
foreach ($arrExtrasActif as $row) {
?>
<tr>
<td>
<strong><?= htmlspecialchars($row['eve_nom_fr'] ?? ('eve_id ' . $row['eve_id'])) ?></strong>
<small class="text-muted">(#<?= intval($row['eve_id']) ?>)</small>
</td>
<td><?= htmlspecialchars($row['perm_label_fr']) ?> <small class="text-muted">(<?= htmlspecialchars($row['perm_key']) ?>)</small></td>
<td><span class="badge badge-success">actif</span></td>
<td><small><?= htmlspecialchars($row['ae_created_at']) ?></small></td>
<td class="text-right">
<a href="index.php?t=<?= $strT ?>&amp;a=mod&amp;id=<?= $intComId ?>&amp;action=revokeveaccesextra&amp;ae_id=<?= intval($row['ae_id']) ?>"
class="btn btn-sm btn-danger"
onclick="return confirm('Revoquer cette permission ?');"
title="Desactiver">
<i class="fa fa-ban"></i>
</a>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<?php if (count($arrExtrasRevoke) > 0) { ?>
<details class="mb-3">
<summary class="text-muted small" style="cursor:pointer;">
Historique permissions revoquees (<?= count($arrExtrasRevoke) ?>)
</summary>
<table class="table table-sm table-borderless mt-2 mb-0">
<tbody>
<?php foreach ($arrExtrasRevoke as $row) { ?>
<tr class="text-muted">
<td>
<?= htmlspecialchars($row['eve_nom_fr'] ?? ('eve_id ' . $row['eve_id'])) ?>
<small>(#<?= intval($row['eve_id']) ?>)</small>
</td>
<td><?= htmlspecialchars($row['perm_label_fr']) ?> (<?= htmlspecialchars($row['perm_key']) ?>)</td>
<td class="text-right">
<a href="index.php?t=<?= $strT ?>&amp;a=mod&amp;id=<?= $intComId ?>&amp;action=reactivateveaccesextra&amp;ae_id=<?= intval($row['ae_id']) ?>"
class="btn btn-sm btn-outline-success">
Reactiver
</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</details>
<?php } ?>
<script>
(function($){
function renderEvePick($box, items){
$box.empty();
if (!items || !items.length){
$box.addClass('d-none');
return;
}
items.forEach(function(it){
var id = it.eve_id || it.eveId || it.id;
var label = it.eve_nom_fr || it.nom || ('#' + id);
$('<a href="#" class="list-group-item list-group-item-action"></a>')
.text(label + ' (#' + id + ')')
.data('item', it)
.appendTo($box);
});
$box.removeClass('d-none');
}
function bindEveSearch(inputSel, resultsSel, hiddenSel){
var timer = null, xhr = null;
$(inputSel).on('input', function(){
var q = $(this).val().trim();
var $box = $(resultsSel);
if (q.length < 2) {
$box.addClass('d-none').empty();
return;
}
clearTimeout(timer);
timer = setTimeout(function(){
if (xhr) xhr.abort();
xhr = $.getJSON('ajax_newpromoteur.php', { action: 'search_evenement', q: q }, function(items){
renderEvePick($box, items);
}).fail(function(){ renderEvePick($box, []); });
}, 200);
});
$(resultsSel).on('click', '.list-group-item', function(e){
e.preventDefault();
var item = $(this).data('item') || {};
var id = item.eve_id || item.eveId || item.id;
var label = item.eve_nom_fr || $(this).text();
$(hiddenSel).val(id);
$(inputSel).val(label);
$(resultsSel).addClass('d-none').empty();
});
}
bindEveSearch('#pp-eve-acces-v2', '#pp-results-eve-acces-v2', '#pp-eve-acces-v2-id');
bindEveSearch('#pp-eve-acces-extra', '#pp-results-eve-acces-extra', '#pp-eve-acces-extra-id');
$('#btn-eve-acces-v2-add').on('click', function(){
var eveId = $('#pp-eve-acces-v2-id').val();
var roleId = $('#pp-eve-acces-v2-role').val();
var days = $('#pp-eve-acces-v2-days').val() || 0;
if (!eveId || !roleId) {
alert('Choisir un evenement et un role.');
return;
}
var p = new URLSearchParams(window.location.search);
var url = 'index.php'
+ '?t=' + encodeURIComponent(p.get('t') || '')
+ '&a=mod'
+ '&id=' + encodeURIComponent(p.get('id') || '0')
+ '&action=addeveacces'
+ '&evenement_id=' + encodeURIComponent(eveId)
+ '&role_id=' + encodeURIComponent(roleId)
+ '&expire_days=' + encodeURIComponent(days);
window.location.href = url;
});
$('#btn-eve-acces-extra-add').on('click', function(){
var eveId = $('#pp-eve-acces-extra-id').val();
var permKey = $('#pp-eve-acces-extra-perm').val();
if (!eveId || !permKey) {
alert('Choisir un evenement et une permission.');
return;
}
var p = new URLSearchParams(window.location.search);
var url = 'index.php'
+ '?t=' + encodeURIComponent(p.get('t') || '')
+ '&a=mod'
+ '&id=' + encodeURIComponent(p.get('id') || '0')
+ '&action=addeveaccesextra'
+ '&evenement_id=' + encodeURIComponent(eveId)
+ '&perm_key=' + encodeURIComponent(permKey);
window.location.href = url;
});
})(jQuery);
</script>
<?php
}