alpinux-portail/web/admin/members.php
Alpinux 4921a0691c Admin : gestion groupes, services par groupes, badge admin
- admin/groups.php : liste/création/suppression des groupes Keycloak
  avec comptage des membres et services associés par groupe
- admin/services.php : remplace requires_adherent par sélection multi-groupes
- inc/services.php : modèle groups[], migration auto depuis requires_adherent,
  helper service_accessible() pour l'accès contextuel
- inc/keycloak.php : kc_list_groups, kc_create_group, kc_delete_group, kc_group_members
- profile.php : badge Admin visible dans la tuile Mon compte
- index.php : utilise service_accessible() avec les groupes de l'utilisateur

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 00:59:25 +02:00

111 lines
3.8 KiB
PHP

<?php
require_once __DIR__ . '/../inc/config.php';
require_once __DIR__ . '/../inc/auth.php';
require_once __DIR__ . '/../inc/keycloak.php';
session_start_safe();
require_admin();
$users = [];
$kc_error = null;
try {
$users = kc_list_users();
} catch (Exception $e) {
$kc_error = $e->getMessage();
}
// Sépare adhérents et inscrits en attente
$adherents = array_filter($users, fn($u) => in_array(ADHERENT_GROUP, $u['groupNames'], true));
$pending = array_filter($users, fn($u) => !in_array(ADHERENT_GROUP, $u['groupNames'], true));
$title = 'Gestion des membres';
require __DIR__ . '/../views/layout.php';
?>
<div class="admin-page">
<div class="page-header">
<h1>Gestion des membres</h1>
<div class="admin-nav">
<a href="/admin/members.php" class="active">Membres</a>
<a href="/admin/groups.php">Groupes</a>
<a href="/admin/services.php">Services</a>
</div>
</div>
<?php if ($kc_error): ?>
<div class="alert alert-error">Erreur Keycloak : <?= htmlspecialchars($kc_error) ?></div>
<?php endif; ?>
<!-- Inscrits en attente de validation -->
<section class="card">
<h2>En attente de validation (<?= count($pending) ?>)</h2>
<?php if (!$pending): ?>
<p class="text-muted">Aucun inscrit en attente.</p>
<?php else: ?>
<table class="members-table">
<thead>
<tr>
<th>Nom</th><th>Identifiant</th><th>Email</th><th>Groupes</th><th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($pending as $u): ?>
<tr>
<td><?= htmlspecialchars(trim(($u['firstName'] ?? '') . ' ' . ($u['lastName'] ?? ''))) ?></td>
<td><?= htmlspecialchars($u['username'] ?? '') ?></td>
<td><?= htmlspecialchars($u['email'] ?? '') ?></td>
<td><?= htmlspecialchars(implode(', ', $u['groupNames']) ?: '—') ?></td>
<td>
<form method="post" action="/admin/validate.php" style="display:inline">
<input type="hidden" name="user_id" value="<?= htmlspecialchars($u['id']) ?>">
<button type="submit" class="btn-primary btn-sm"
onclick="return confirm('Valider l\'adhésion de <?= htmlspecialchars(addslashes($u['username'] ?? '')) ?> ?')">
Valider adhésion
</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</section>
<!-- Adhérents actifs -->
<section class="card">
<h2>Adhérents (<?= count($adherents) ?>)</h2>
<?php if (!$adherents): ?>
<p class="text-muted">Aucun adhérent.</p>
<?php else: ?>
<table class="members-table">
<thead>
<tr>
<th>Nom</th><th>Identifiant</th><th>Email</th><th>Groupes</th><th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($adherents as $u): ?>
<tr>
<td><?= htmlspecialchars(trim(($u['firstName'] ?? '') . ' ' . ($u['lastName'] ?? ''))) ?></td>
<td><?= htmlspecialchars($u['username'] ?? '') ?></td>
<td><?= htmlspecialchars($u['email'] ?? '') ?></td>
<td><?= htmlspecialchars(implode(', ', $u['groupNames'])) ?></td>
<td>
<form method="post" action="/admin/revoke.php" style="display:inline">
<input type="hidden" name="user_id" value="<?= htmlspecialchars($u['id']) ?>">
<button type="submit" class="btn-danger btn-sm"
onclick="return confirm('Révoquer l\'adhésion de <?= htmlspecialchars(addslashes($u['username'] ?? '')) ?> ?')">
Révoquer
</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</section>
</div>
<?php require __DIR__ . '/../views/layout_end.php'; ?>