LuminaWebsite/contributions_award.php
Maaxxs 5f25e20900 Kina in the warehouse, Lumipunkte, new logo, versioned assets
Warehouse: Kina (the game currency) can be paid in and out, shown in its own
box with the in-game coin icon (Icon_Currency_Coin_GoldNonbinding from the
game client via aion2.app, since the wiki has none). It is a catalog item in
the new "Währung" category, kept out of the item cards and totals, and
allows up to a trillion per entry; warehouse_movements.quantity becomes
BIGINT for that. A leftover "Kinah" entry is merged into "Kina".

Beitragspunkte are renamed to Lumipunkte in every visible text, the coin is
now lumipunkt.svg, and the schema sync also updates the descriptions of
existing core permissions so the new name reaches the role editor.

The sidebar, login page and mobile top bar show the new Lumina Ascendens
logo, cropped and with its dark background made transparent.

Scripts and the stylesheet are included with a ?v=<mtime> query
(asset_url()), so browsers pick up new versions after an upload instead of
running stale JavaScript - the cause of raid points not being saved.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 10:25:28 +02:00

194 lines
9.4 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
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'
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'; ?>