Asked for: the alliances move to their own Discord server with the roles Force Commander, Legion Lead, Legion Officer and Legionär. Decided: everyone with a role there sees the Consilium (our members too), no role per legion (assignment stays on the website), new accounts are approved by our admins, rights per role as planned, a permission for Consilium calendar entries that is assigned later. Server ID 1553882046793777283. - Two Discord servers: settings.consilium_guild_id (seeded, Verwaltung -> Discord-Bot with a check whether the bot is there); a group's role lies on one of them (roles.discord_guild_id, NULL = legion, schema 71). Login and the periodic sync read both memberships (discord_fetch_memberships/discord_apply_memberships) and sync groups per server; name, avatar, joined date and classes come from the legion server, for allies from the Consilium server. - Leaving: whoever leaves a server loses its groups; an account is deactivated only when it is on neither (discord_member_left_guild; bot_api.php takes in_guilds from the bot, the sync checks all servers, older bot versions cannot deactivate Consilium members). Logout text no longer names a server. - Group form lists the roles of both servers, the group list marks Consilium roles; Consilium-Raids channel is chosen from the Consilium server's channels. - Rights per area: consilium.raids / consilium.raids.manage for Consilium raids (create, manage, restore, delete), raids.create / raids.manage only for legion raids (raid_area_can_create, raid_area_can_manage_all, raid_can_manage asks the raid's area). consilium.calendar: only with it Consilium calendar entries (allies without it cannot add entries; legion members with it get "Für wen?" with legion/Consilium). - Consilium member list: everyone with a role on the Consilium server - our legion as its own section, allied legions, without legion - with the Consilium ranks as tags; legion list and profiles leave the Consilium groups out for those who do not see the Consilium. Allies pick their class in the profile. - Consilium admin page: setup checklist for the new structure with the groups of the Consilium server and their rights (setup only for roles.manage). Privacy page, README. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
173 lines
11 KiB
PHP
173 lines
11 KiB
PHP
<?php
|
||
/**
|
||
* Consilium Elyseum verwalten: die verbuendeten Legionen und welche Mitglieder zu welcher gehoeren
|
||
* (includes/consilium.php). Formulare gehen an admin/consilium_action.php.
|
||
*/
|
||
require_once __DIR__ . '/../includes/bootstrap.php';
|
||
require_once __DIR__ . '/../includes/consilium.php';
|
||
require_permission('consilium.manage');
|
||
|
||
$legions = consilium_legions();
|
||
$members = consilium_members(true);
|
||
$consiliumGuild = consilium_guild_id();
|
||
// Die Einrichtung (Server, Gruppen, Rechte) ist Sache unserer Admins - nicht aller mit consilium.manage
|
||
$showSetup = user_has_permission('roles.manage');
|
||
|
||
// Gruppen des Consiliums: die mit einer Rolle des Servers des Consiliums, dazu ihre Consilium-Rechte (und ob sie
|
||
// versehentlich dashboard.view haben - dann zaehlten Verbuendete als Legion)
|
||
$groups = [];
|
||
if ($showSetup) {
|
||
$stmt = db()->prepare(
|
||
"SELECT r.id, COALESCE(NULLIF(r.display_name, ''), r.name) AS label,
|
||
GROUP_CONCAT(CASE WHEN p.`key` LIKE 'consilium.%' OR p.`key` = 'dashboard.view' THEN p.`key` END
|
||
ORDER BY p.`key` SEPARATOR ' ') AS perms
|
||
FROM roles r
|
||
LEFT JOIN role_permissions rp ON rp.role_id = r.id
|
||
LEFT JOIN permissions p ON p.id = rp.permission_id
|
||
WHERE r.discord_guild_id = ?
|
||
GROUP BY r.id
|
||
ORDER BY " . ROLE_TAG_ORDER_SQL
|
||
);
|
||
$stmt->execute([$consiliumGuild]);
|
||
$groups = $stmt->fetchAll();
|
||
}
|
||
$setUp = $consiliumGuild !== '' && ($groups || !$showSetup) && $legions;
|
||
$nameOf = static fn (array $m): string => $m['display_name'] !== '' ? (string) $m['display_name'] : (string) $m['username'];
|
||
|
||
$pageTitle = CONSILIUM_NAME;
|
||
include __DIR__ . '/../includes/header.php';
|
||
?>
|
||
<div class="panel consilium-hero">
|
||
<h1><?= icon('shield-check') ?> <?= e(CONSILIUM_NAME) ?></h1>
|
||
<p class="text-muted">
|
||
Das Bündnis mit anderen Legionen, mit eigenem Discord-Server. Wer dort eine Rolle hat, sieht auf der Website das
|
||
Consilium: die Mitglieder, Consilium-Raids, Consilium-Termine und die Karten-Sitzungen, die ihr freigebt.
|
||
Verbündete sehen nichts von der Legion, und wer von uns nicht auf dem Server ist, nichts vom Consilium.
|
||
</p>
|
||
<?php if ($showSetup): ?>
|
||
<details class="consilium-setup"<?= $setUp ? '' : ' open' ?>>
|
||
<summary>So richtest du das Consilium ein</summary>
|
||
<ol>
|
||
<li>Unter <a href="/admin/bot.php">Discord-Bot</a> den Server des Consiliums eintragen
|
||
(<?= $consiliumGuild !== '' ? 'ist eingetragen: <code>' . e($consiliumGuild) . '</code>' : '<strong>fehlt noch</strong>' ?>) und
|
||
den Bot dort einladen. Dort auch den Kanal „Consilium-Raids“ wählen.</li>
|
||
<li>Unter <a href="/admin/roles.php">Berechtigungsgruppen</a> für jede Rolle des Servers eine Gruppe anlegen und
|
||
mit ihr verknüpfen (Auswahl „Discord-Server des <?= e(CONSILIUM_NAME) ?>“) – mit diesen Rechten und
|
||
<strong>ohne <code>dashboard.view</code></strong>:
|
||
<ul>
|
||
<li>Force Commander: <code>consilium.view</code>, <code>consilium.draw</code>, <code>consilium.manage</code>, <code>consilium.raids.manage</code></li>
|
||
<li>Legion Lead: <code>consilium.view</code>, <code>consilium.draw</code>, <code>consilium.raids.manage</code> (damit auch Raids anlegen)</li>
|
||
<li>Legion Officer: <code>consilium.view</code>, <code>consilium.draw</code>, <code>consilium.raids</code></li>
|
||
<li>Legionär: <code>consilium.view</code></li>
|
||
</ul>
|
||
Consilium-Termine im Kalender eintragen: <code>consilium.calendar</code> – gebt es, wem ihr es zutraut.</li>
|
||
<li>Unten die verbündeten Legionen anlegen und ihre Mitglieder zuordnen. Jedes Mitglied kann seine Legion auch
|
||
selbst unter „Mein Profil“ wählen. Wer von uns auf dem Server ist, steht automatisch unter
|
||
„<?= e(CONSILIUM_HOME_LEGION) ?>“.</li>
|
||
<li>Neue Konten schaltet ihr wie gewohnt in der <a href="/admin/users.php">Benutzerverwaltung</a> frei.</li>
|
||
</ol>
|
||
<p class="consilium-setup-status">
|
||
<strong>Gruppen mit Rolle auf dem Server des Consiliums:</strong>
|
||
<?php if (!$groups): ?>
|
||
<span class="text-muted">noch keine</span>
|
||
<?php endif; ?>
|
||
</p>
|
||
<?php if ($groups): ?>
|
||
<ul class="consilium-group-list">
|
||
<?php foreach ($groups as $group): ?>
|
||
<?php $perms = array_filter(explode(' ', (string) ($group['perms'] ?? ''))); ?>
|
||
<li>
|
||
<?= role_tag_html((string) $group['label']) ?>
|
||
<span class="text-muted"><?= $perms ? e(implode(', ', array_diff($perms, ['dashboard.view']))) : 'keine Consilium-Rechte' ?></span>
|
||
<?php if (in_array('dashboard.view', $perms, true)): ?><span class="badge badge-danger" title="Dann zählen Verbündete als Legion und sehen alles">hat dashboard.view!</span><?php endif; ?>
|
||
</li>
|
||
<?php endforeach; ?>
|
||
</ul>
|
||
<?php endif; ?>
|
||
</details>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<div class="panel">
|
||
<h2>Legionen im Consilium</h2>
|
||
<?php if (!$legions): ?>
|
||
<p class="text-muted">Noch keine verbündete Legion angelegt.</p>
|
||
<?php else: ?>
|
||
<ul class="consilium-legion-list">
|
||
<?php foreach ($legions as $i => $legion): ?>
|
||
<li>
|
||
<form method="post" action="/admin/consilium_action.php" class="consilium-legion-rename">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="action" value="legion_rename">
|
||
<input type="hidden" name="id" value="<?= $legion['id'] ?>">
|
||
<input type="text" name="name" value="<?= e($legion['name']) ?>" maxlength="<?= CONSILIUM_LEGION_NAME_MAX ?>" required aria-label="Name der Legion">
|
||
<button type="submit" class="button-secondary button-small">Umbenennen</button>
|
||
</form>
|
||
<span class="text-muted consilium-legion-count"><?= $legion['member_count'] ?> <?= $legion['member_count'] === 1 ? 'Mitglied' : 'Mitglieder' ?></span>
|
||
<form method="post" action="/admin/consilium_action.php" class="inline-form">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="action" value="legion_move">
|
||
<input type="hidden" name="id" value="<?= $legion['id'] ?>">
|
||
<button type="submit" name="direction" value="up" class="icon-button" title="Nach oben"<?= $i === 0 ? ' disabled' : '' ?>>▲</button>
|
||
<button type="submit" name="direction" value="down" class="icon-button" title="Nach unten"<?= $i === count($legions) - 1 ? ' disabled' : '' ?>>▼</button>
|
||
</form>
|
||
<form method="post" action="/admin/consilium_action.php" class="inline-form"
|
||
data-confirm="Die Legion „<?= e($legion['name']) ?>“ löschen? Ihre Mitglieder bleiben im Consilium, nur ohne Legion." data-confirm-title="Legion löschen" data-confirm-danger data-confirm-ok="Löschen">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="action" value="legion_delete">
|
||
<input type="hidden" name="id" value="<?= $legion['id'] ?>">
|
||
<button type="submit" class="icon-button icon-button-danger" title="Löschen" aria-label="<?= e($legion['name']) ?> löschen"><?= icon('trash') ?></button>
|
||
</form>
|
||
</li>
|
||
<?php endforeach; ?>
|
||
</ul>
|
||
<?php endif; ?>
|
||
<form method="post" action="/admin/consilium_action.php" class="consilium-legion-add">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="action" value="legion_add">
|
||
<input type="text" name="name" maxlength="<?= CONSILIUM_LEGION_NAME_MAX ?>" required placeholder="Name der verbündeten Legion" aria-label="Name der verbündeten Legion">
|
||
<button type="submit">+ Legion hinzufügen</button>
|
||
</form>
|
||
</div>
|
||
|
||
<div class="panel">
|
||
<h2>Mitglieder des Consiliums <span class="chip-count"><?= count($members) ?></span></h2>
|
||
<?php if (!$members): ?>
|
||
<p class="text-muted">Noch niemand. Wer die Discord-Rolle „<?= e(CONSILIUM_NAME) ?>“ hat und sich auf der Website anmeldet, erscheint hier.</p>
|
||
<?php else: ?>
|
||
<div class="table-scroll">
|
||
<table>
|
||
<thead>
|
||
<tr><th>Mitglied</th><th>Discord</th><th>Legion</th><th>Zuletzt aktiv</th></tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php foreach ($members as $member): ?>
|
||
<tr>
|
||
<td>
|
||
<span class="consilium-member-name"><?= avatar_html($member, 28) ?> <?= e($nameOf($member)) ?></span>
|
||
<?php if ($member['status'] === 'pending'): ?><a class="badge badge-pending" href="/admin/users.php">Wartet auf Freischaltung</a><?php endif; ?>
|
||
</td>
|
||
<td class="text-muted"><?= e((string) ($member['discord_username'] ?? '')) ?></td>
|
||
<td>
|
||
<form method="post" action="/admin/consilium_action.php" class="inline-form">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="action" value="member_legion">
|
||
<input type="hidden" name="user_id" value="<?= (int) $member['id'] ?>">
|
||
<select name="legion_id" onchange="this.form.submit()" aria-label="Legion von <?= e($nameOf($member)) ?>">
|
||
<option value="">– keine –</option>
|
||
<?php foreach ($legions as $legion): ?>
|
||
<option value="<?= $legion['id'] ?>"<?= (int) $member['consilium_legion_id'] === $legion['id'] ? ' selected' : '' ?>><?= e($legion['name']) ?></option>
|
||
<?php endforeach; ?>
|
||
</select>
|
||
<noscript><button type="submit" class="button-secondary button-small">Speichern</button></noscript>
|
||
</form>
|
||
</td>
|
||
<td class="text-muted"><?= e(last_active_label($member['last_active'] ?? null)) ?></td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<?php endif; ?>
|
||
</div>
|
||
<?php include __DIR__ . '/../includes/footer.php'; ?>
|