LuminaWebsite/admin/consilium.php
Maaxxs 5aaf44eaec Consilium Elyseum: allied legions get their own view - own raids, calendar entries, member tab and shared live map sessions
Asked for: alliances ("Consilium Elyseum") with their own view, a member-list tab with the allied legions and their
members, an own raid area, a calendar that shows them only alliance entries, and live map sessions the legion can
share with them - watching only, or drawing only with an extra permission. There is one Discord role "Consilium
Elyseum" for all allies, so which legion each ally belongs to is stored on the website.

- Permissions consilium.view / consilium.draw / consilium.manage. An account with consilium.view but without
  dashboard.view is a guest of the Consilium (consilium_only(), sql_is_consilium_only()) and sees only the alliance
  area; raids, calendar and map stay restricted even with extra rights like raids.view or map.view.
- includes/consilium.php; consilium.php is the allies' start page instead of the dashboard (next raids and entries,
  legions, running shared map sessions); admin/consilium.php: setup hints, allied legions, member assignment.
  users.consilium_legion_id, table consilium_legions (schema 69); allies pick their legion under Mein Profil.
- Members: new tab "Consilium Elyseum" (legions with their members), the only tab allies see. Legion-only lists
  (dues, Lumipunkte, member pickers, raid and activity points) leave allies out.
- Raids: two areas, legion and Consilium, told apart by the Discord channel ("Consilium-Raids" under Verwaltung ->
  Discord-Bot, settings.consilium_raid_channel; the bot API returns channel_id). Allies only see and sign up for
  Consilium raids, which give no Lumipunkte; raids created in the Consilium area are posted to its channel.
- Calendar: audience "Consilium Elyseum". Allies see only those entries and the Consilium raids (also in their iCal
  subscription), their own entries are always Consilium entries; the public calendar shows no Consilium raids; the
  legion sees them marked with 🤝.
- Map: whoever may edit a public tactic shares its running live session with the Consilium (consilium_share, logged).
  The share lives in the bot's live relay and only for that session: it ends with "Freigabe beenden" or 60 s after
  the last legion member left; making the tactic private or deleting it ends it as well. Allies see only running
  shared sessions under Karte (and on their start page), join and watch; with consilium.draw they add strokes,
  areas, points and text - no figures, nothing moved, erased or undone, no tactics, steps, copies or history.
  Enforced in tactics_api.php (guest branch: shared tactics only, only live_token and shape_create) and in the relay
  (guest tickets, event whitelist, guests are disconnected when the share ends). Needs the bot update (api.py,
  database/db.py, live_tactics.py).
- Navigation, privacy page, patch note, README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 01:36:49 +02:00

145 lines
8.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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);
// Gruppen des Consiliums: consilium.view ohne dashboard.view (Gruppen mit beidem gehoeren zur Legion, z.B. Administrator)
$groups = db()->query(
"SELECT r.id, COALESCE(NULLIF(r.display_name, ''), r.name) AS label, r.discord_role_id
FROM roles r
JOIN role_permissions rp ON rp.role_id = r.id
JOIN permissions p ON p.id = rp.permission_id
WHERE p.`key` = 'consilium.view'
AND NOT EXISTS (SELECT 1 FROM role_permissions rp2 JOIN permissions p2 ON p2.id = rp2.permission_id
WHERE rp2.role_id = r.id AND p2.`key` = 'dashboard.view')
ORDER BY label"
)->fetchAll();
$setUp = $groups && $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. Ihre Mitglieder melden sich über Discord an, haben dort die Rolle
„<?= e(CONSILIUM_NAME) ?>“ und sehen auf der Website nur ihre eigene Ansicht: die Mitglieder des Consiliums,
Consilium-Raids, Consilium-Termine und die Karten-Sitzungen, die ihr für sie freigebt - nichts von der Legion.
</p>
<details class="consilium-setup"<?= $setUp ? '' : ' open' ?>>
<summary>So richtest du das Consilium ein</summary>
<ol>
<li>Unter <a href="/admin/roles.php">Berechtigungsgruppen</a> eine Gruppe anlegen (z.&nbsp;B. „<?= e(CONSILIUM_NAME) ?>“)
und mit der Discord-Rolle „<?= e(CONSILIUM_NAME) ?>“ verknüpfen.</li>
<li>Der Gruppe das Recht <code>consilium.view</code> geben - und dazu <code>consilium.draw</code>, wenn sie in
freigegebenen Karten-Sitzungen mitzeichnen darf. <strong>Kein <code>dashboard.view</code></strong>, sonst zählt
sie als Legion und sieht alles.</li>
<li>Unten die verbündeten Legionen anlegen und ihre Mitglieder zuordnen. Jedes Mitglied kann seine Legion auch
selbst unter „Mein Profil“ wählen.</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 des Consiliums</strong> <span class="text-muted">(<code>consilium.view</code> ohne <code>dashboard.view</code>):</span>
<?php if (!$groups): ?>
<span class="text-muted">noch keine</span>
<?php else: ?>
<?php foreach ($groups as $group): ?>
<?= role_tag_html((string) $group['label']) ?>
<?php if ($group['discord_role_id'] === null): ?><span class="text-muted">(ohne Discord-Rolle)</span><?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
</p>
</details>
</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'; ?>