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>
194 lines
9.5 KiB
PHP
194 lines
9.5 KiB
PHP
<?php
|
||
require_once __DIR__ . '/includes/bootstrap.php';
|
||
require_once __DIR__ . '/includes/contributions.php';
|
||
require_once __DIR__ . '/includes/raid_attendance.php';
|
||
require_permission('contributions.manage');
|
||
|
||
$members = db()->query(
|
||
"SELECT u.id, u.username, u.display_name, u.avatar_filename, u.discord_id,
|
||
COALESCE(SUM(e.points), 0) AS points
|
||
FROM users u
|
||
LEFT JOIN contribution_entries e ON e.user_id = u.id
|
||
WHERE u.status = 'active' AND " . sql_is_legion_member('u') . "
|
||
GROUP BY u.id
|
||
ORDER BY COALESCE(NULLIF(u.display_name, ''), u.username)"
|
||
)->fetchAll();
|
||
|
||
$userIdByDiscord = [];
|
||
foreach ($members as $member) {
|
||
if (!empty($member['discord_id'])) {
|
||
$userIdByDiscord[(string) $member['discord_id']] = (int) $member['id'];
|
||
}
|
||
}
|
||
|
||
// Raids fuer den Anlass "Raid": die Teilnehmer (Anmeldungen in einer Gruppe) werden im
|
||
// Formular vorausgewaehlt - soweit sie ein Website-Konto mit Discord-Verknuepfung haben.
|
||
$raids = [];
|
||
$raidsError = null;
|
||
try {
|
||
$apiRaids = fetch_raids('all');
|
||
raid_process_auto_points($apiRaids);
|
||
usort($apiRaids, static fn (array $a, array $b): int => (int) ($b['timestamp'] ?? 0) <=> (int) ($a['timestamp'] ?? 0));
|
||
foreach (array_slice($apiRaids, 0, 40) as $raid) {
|
||
$participants = [];
|
||
$bench = [];
|
||
$withoutAccount = [];
|
||
foreach ((array) ($raid['signups'] ?? []) as $signup) {
|
||
$group = (int) ($signup['group'] ?? 0);
|
||
if ($group < 0 || ($signup['class'] ?? '') === 'Ausstehend') {
|
||
continue; // abgemeldet bzw. noch nicht bestaetigt
|
||
}
|
||
$userId = $userIdByDiscord[(string) ($signup['user_id'] ?? '')] ?? null;
|
||
if ($userId === null) {
|
||
$withoutAccount[] = (string) ($signup['name'] ?? '?');
|
||
} elseif ($group >= 1) {
|
||
$participants[] = $userId;
|
||
} else {
|
||
$bench[] = $userId;
|
||
}
|
||
}
|
||
// Anwesenheitsliste: Anwesende bekommen Punkte, Abwesenden kann man abziehen.
|
||
$present = [];
|
||
$absent = [];
|
||
$raidIdValue = (int) ($raid['raid_id'] ?? 0);
|
||
$attendance = raid_attendance_get($raidIdValue);
|
||
foreach ($attendance as $discordId => $entry) {
|
||
$userId = $userIdByDiscord[$discordId] ?? null;
|
||
if ($userId !== null && $entry['status'] === 'present') {
|
||
$present[] = $userId;
|
||
} elseif ($userId !== null && $entry['status'] === 'absent') {
|
||
$absent[] = $userId;
|
||
}
|
||
}
|
||
|
||
$timestamp = (int) ($raid['timestamp'] ?? 0);
|
||
$raids[] = [
|
||
// Als Text: Discord-IDs sind 19-stellig und in JavaScript als Zahl nicht exakt.
|
||
'id' => (string) $raidIdValue,
|
||
'attendance' => !empty($attendance),
|
||
'present' => $present,
|
||
'absent' => $absent,
|
||
'title' => (string) ($raid['title'] ?? 'Raid'),
|
||
'date' => $timestamp ? date('d.m.Y H:i', $timestamp) : (string) ($raid['date'] ?? ''),
|
||
'time' => $timestamp ? date('Y-m-d\TH:i', $timestamp) : '',
|
||
'participants' => $participants,
|
||
'bench' => $bench,
|
||
'withoutAccount' => $withoutAccount,
|
||
];
|
||
}
|
||
} catch (Throwable $e) {
|
||
$raidsError = $e->getMessage();
|
||
}
|
||
|
||
// Vorbelegung: nach einem Fehler die bisherigen Eingaben, sonst ggf. ein einzelnes Mitglied.
|
||
$old = $_SESSION['contribution_form'] ?? null;
|
||
unset($_SESSION['contribution_form']);
|
||
$preselectUser = isset($_GET['user']) ? (int) $_GET['user'] : 0;
|
||
$form = $old ?? [
|
||
'category' => $preselectUser ? 'other' : 'raid',
|
||
'raid_id' => '',
|
||
'title' => '',
|
||
'awarded_at' => contribution_now_input(),
|
||
'points' => '',
|
||
'note' => '',
|
||
'users' => $preselectUser ? [$preselectUser] : [],
|
||
];
|
||
$selected = array_map('intval', (array) ($form['users'] ?? []));
|
||
|
||
$pageTitle = 'Lumipunkte vergeben';
|
||
$containerWide = true;
|
||
include __DIR__ . '/includes/header.php';
|
||
?>
|
||
<form class="panel contribution-form" method="post" action="/contributions_action.php" id="contribution-form">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="action" value="create">
|
||
|
||
<div class="contribution-head">
|
||
<h1><?= contribution_coin(32) ?> Lumipunkte vergeben</h1>
|
||
<a href="/contributions.php">Zurück zur Übersicht</a>
|
||
</div>
|
||
|
||
<div class="contribution-form-grid">
|
||
<div>
|
||
<label for="category">Anlass</label>
|
||
<select id="category" name="category">
|
||
<?php foreach (CONTRIBUTION_CATEGORIES as $key => $label): ?>
|
||
<option value="<?= e($key) ?>" <?= ($form['category'] ?? '') === $key ? 'selected' : '' ?>><?= e($label) ?></option>
|
||
<?php endforeach; ?>
|
||
</select>
|
||
</div>
|
||
<div id="raid-field">
|
||
<label for="raid_id">Raid <span class="text-muted">(optional)</span></label>
|
||
<?php if ($raidsError === null): ?>
|
||
<select id="raid_id" name="raid_id">
|
||
<option value="">– keinen Raid auswählen –</option>
|
||
<?php foreach ($raids as $raid): ?>
|
||
<option value="<?= e($raid['id']) ?>" <?= (string) ($form['raid_id'] ?? '') === $raid['id'] ? 'selected' : '' ?>>
|
||
<?= e($raid['title']) ?><?= $raid['date'] !== '' ? ' – ' . e($raid['date']) : '' ?>
|
||
</option>
|
||
<?php endforeach; ?>
|
||
</select>
|
||
<div class="field-hint" id="raid-hint">Wählt die Teilnehmer des Raids automatisch aus.</div>
|
||
<?php else: ?>
|
||
<input type="hidden" name="raid_id" value="">
|
||
<p class="field-hint">Die Raids konnten nicht geladen werden (<?= e($raidsError) ?>). Mitglieder bitte von Hand auswählen.</p>
|
||
<?php endif; ?>
|
||
</div>
|
||
<div class="contribution-form-wide">
|
||
<label for="title">Grund</label>
|
||
<input type="text" id="title" name="title" maxlength="150" required
|
||
value="<?= e((string) ($form['title'] ?? '')) ?>" placeholder="z.B. Festungskampf Verteron, Hilfe beim Handwerk …">
|
||
</div>
|
||
<div>
|
||
<label for="points">Punkte pro Mitglied</label>
|
||
<input type="number" id="points" name="points" required step="1"
|
||
min="-<?= CONTRIBUTION_MAX_POINTS ?>" max="<?= CONTRIBUTION_MAX_POINTS ?>"
|
||
value="<?= e((string) ($form['points'] ?? '')) ?>" placeholder="z.B. 10">
|
||
<div class="field-hint">Negativ für einen Abzug.</div>
|
||
</div>
|
||
<div>
|
||
<label for="awarded_at">Datum</label>
|
||
<input type="datetime-local" id="awarded_at" name="awarded_at" required value="<?= e((string) ($form['awarded_at'] ?? contribution_now_input())) ?>">
|
||
</div>
|
||
<div class="contribution-form-wide">
|
||
<label for="note">Bemerkung <span class="text-muted">(optional)</span></label>
|
||
<input type="text" id="note" name="note" maxlength="255" value="<?= e((string) ($form['note'] ?? '')) ?>">
|
||
</div>
|
||
</div>
|
||
|
||
<div class="contribution-picker">
|
||
<div class="contribution-picker-head">
|
||
<label>Mitglieder <span class="contribution-picker-count" id="picker-count"></span></label>
|
||
<input type="search" id="picker-search" placeholder="Mitglied suchen …" autocomplete="off">
|
||
<button type="button" class="button-secondary button-small" id="picker-all">Alle</button>
|
||
<button type="button" class="button-secondary button-small" id="picker-none">Keine</button>
|
||
</div>
|
||
<div class="contribution-raid-mode" id="raid-mode" hidden>
|
||
<span class="text-muted">Laut Anwesenheitsliste:</span>
|
||
<button type="button" class="button-secondary button-small" data-raid-mode="present">Anwesende auswählen (Punkte)</button>
|
||
<button type="button" class="button-secondary button-small" data-raid-mode="absent">Abwesende auswählen (Abzug)</button>
|
||
<button type="button" class="button-secondary button-small" data-raid-mode="participants">Alle Teilnehmer laut Anmeldung</button>
|
||
</div>
|
||
<p class="field-hint contribution-raid-info" id="raid-info" hidden></p>
|
||
<div class="contribution-picker-grid">
|
||
<?php foreach ($members as $member): ?>
|
||
<?php $name = (string) ($member['display_name'] !== '' ? $member['display_name'] : $member['username']); ?>
|
||
<label class="contribution-pick" data-name="<?= e(mb_strtolower($name)) ?>">
|
||
<input type="checkbox" name="users[]" value="<?= (int) $member['id'] ?>" <?= in_array((int) $member['id'], $selected, true) ? 'checked' : '' ?>>
|
||
<?= avatar_html($member, 32) ?>
|
||
<span class="contribution-pick-name"><?= e($name) ?></span>
|
||
<span class="contribution-pick-points"><?= contribution_coin(14) ?> <?= contribution_format((int) $member['points']) ?></span>
|
||
</label>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="actions">
|
||
<button type="submit" id="contribution-submit">Punkte vergeben</button>
|
||
<a class="button button-secondary" href="/contributions.php">Abbrechen</a>
|
||
</div>
|
||
</form>
|
||
|
||
<script id="contribution-raids" type="application/json"><?= json_encode($raids, JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT) ?></script>
|
||
<script src="<?= e(asset_url('/assets/js/contributions.js')) ?>"></script>
|
||
<?php include __DIR__ . '/includes/footer.php'; ?>
|