Members can be awarded contribution points for raids, events and other activities, shown with a golden heart-shaped coin. An award has an occasion, reason, date and points per member; members are picked with search and select all/none, and choosing a raid preselects its participants (signed up in a group and linked to a website account), fills in reason and date and names participants without an account. The + on a member's card awards to that member alone, negative points deduct, and awards can be deleted whole or per member. Balances are always computed from the awards. The ranking shows members as cards with gold/silver/bronze for the top three and the viewer's own balance in the header and sidebar. With only contributions.view it lists the best 25 places plus the viewer's own place; contributions.view_all or contributions.manage show everyone. The history of awards is paginated, using pagination now shared with the warehouse. The sidebar shows the new logo, and the login page and mobile top bar a wordmark cut from it with soft edges. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
169 lines
8 KiB
PHP
169 lines
8 KiB
PHP
<?php
|
||
require_once __DIR__ . '/includes/bootstrap.php';
|
||
require_once __DIR__ . '/includes/contributions.php';
|
||
require_once __DIR__ . '/includes/raids_api.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');
|
||
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;
|
||
}
|
||
}
|
||
$timestamp = (int) ($raid['timestamp'] ?? 0);
|
||
$raids[] = [
|
||
'id' => (int) ($raid['raid_id'] ?? 0),
|
||
'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 = 'Beitragspunkte 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) ?> Beitragspunkte 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="<?= (int) $raid['id'] ?>" <?= (string) ($form['raid_id'] ?? '') === (string) $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>
|
||
<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="/assets/js/contributions.js"></script>
|
||
<?php include __DIR__ . '/includes/footer.php'; ?>
|