LuminaWebsite/contributions.php
Maaxxs 83e858987c Lumipunkte for activity checks and a daily reward, Lumishop layout polish
- Activity check: configurable Lumipunkte for "Ich bin da", awarded once after the check is
  closed (on the website right away, otherwise on the next dashboard/points/activity page load)
- Daily reward: 5 Lumipunkte on the first page view of the day, one shared award per day
- Lumishop: equal hero buttons, category box as tall as the item list, "Meine Anträge" as tiles,
  spacing between the tabs and the order list in the management view

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

282 lines
15 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.view');
// Automatische Punkte fuer inzwischen archivierte Raids, bevor die Punktestaende angezeigt werden.
raid_process_auto_points();
// Lumipunkte fuer abgeschlossene Aktivitaetschecks (includes/activity_points.php)
require_once __DIR__ . '/includes/activity_points.php';
activity_process_points();
$canManage = user_has_permission('contributions.manage');
$canViewAll = $canManage || user_has_permission('contributions.view_all');
// Der Verlauf ist einstellbar oeffentlich oder nur fuer Leute mit Bearbeitungsrechten.
$historyPublic = contributions_history_public();
$canSeeHistory = $canManage || $historyPublic;
$currentUser = current_user();
$balances = contribution_balances();
$myBalance = contribution_user_balance((int) $currentUser['id']);
// Rang: gleiche Punktzahl = gleicher Platz.
$rank = 0;
$lastPoints = null;
foreach ($balances as $index => $member) {
if ($lastPoints === null || (int) $member['points'] !== $lastPoints) {
$rank = $index + 1;
$lastPoints = (int) $member['points'];
}
$balances[$index]['rank'] = $rank;
}
// Ohne volle Sicht nur die besten Plaetze - bei Gleichstand an der Grenze alle, die sich den
// letzten Platz teilen. Der eigene Platz wird trotzdem angezeigt.
$myEntry = null;
foreach ($balances as $member) {
if ((int) $member['id'] === (int) $currentUser['id']) {
$myEntry = $member;
}
}
// Gezeigt werden immer nur die ersten Plaetze (genau CONTRIBUTION_PUBLIC_RANKS Karten). Mit voller
// Sicht kommen die uebrigen mit auf die Seite, bleiben aber eingeklappt (aufklappen / Suche).
$visibleBalances = $canViewAll ? $balances : array_slice($balances, 0, CONTRIBUTION_PUBLIC_RANKS);
$visibleIds = array_map(static fn (array $m): int => (int) $m['id'], $visibleBalances);
$showMyEntrySeparately = $myEntry !== null && !in_array((int) $myEntry['id'], $visibleIds, true);
$hiddenCount = count($balances) - count($visibleBalances);
// Verlauf, optional nur fuer ein Mitglied (Klick auf eine Karte).
$filterUserId = $canSeeHistory && isset($_GET['user']) ? (int) $_GET['user'] : null;
$filterUser = null;
// Den Verlauf von Mitgliedern ausserhalb der sichtbaren Plaetze nur mit voller Sicht - sonst
// liesse sich die Rangliste ueber den Filter doch vollstaendig abfragen.
if ($filterUserId !== null && !$canViewAll && $filterUserId !== (int) $currentUser['id'] && !in_array($filterUserId, $visibleIds, true)) {
$filterUserId = null;
}
if ($filterUserId !== null) {
foreach ($balances as $member) {
if ((int) $member['id'] === $filterUserId) {
$filterUser = $member;
}
}
if ($filterUser === null) {
$stmt = db()->prepare("SELECT id, username, display_name, avatar_filename FROM users WHERE id = ?");
$stmt->execute([$filterUserId]);
$filterUser = $stmt->fetch() ?: null;
if ($filterUser) {
$filterUser['points'] = contribution_user_balance($filterUserId);
} else {
$filterUserId = null;
}
}
}
$perPage = 20;
$totalAwards = contribution_award_count($filterUserId);
$pageCount = max(1, (int) ceil($totalAwards / $perPage));
$page = min($pageCount, max(1, (int) ($_GET['page'] ?? 1)));
$awards = $canSeeHistory ? contribution_awards($filterUserId, $perPage, ($page - 1) * $perPage) : [];
$displayName = static fn (array $u): string => (string) ($u['display_name'] !== '' ? $u['display_name'] : $u['username']);
$renderCard = static function (array $member, bool $extra = false) use ($currentUser, $canManage, $canSeeHistory, $displayName): void {
?>
<?php
$isMe = (int) $member['id'] === (int) $currentUser['id'];
$rankClass = in_array((int) $member['rank'], [1, 2, 3], true) && (int) $member['points'] > 0 ? ' rank-' . (int) $member['rank'] : '';
?>
<div class="contribution-card<?= $isMe ? ' is-me' : '' ?><?= $rankClass ?>" data-name="<?= e(mb_strtolower($displayName($member))) ?>"<?= $extra ? ' data-extra hidden' : '' ?>>
<?php if ($canSeeHistory): ?>
<a class="contribution-card-link" href="/contributions.php?user=<?= (int) $member['id'] ?>#verlauf" title="Verlauf von <?= e($displayName($member)) ?>">
<?php else: ?>
<div class="contribution-card-link">
<?php endif; ?>
<span class="contribution-rank">#<?= (int) $member['rank'] ?></span>
<?= avatar_html($member, 52) ?>
<span class="contribution-card-name"><?= e($displayName($member)) ?></span>
<span class="contribution-card-points"><?= contribution_coin(18) ?> <?= contribution_format((int) $member['points']) ?></span>
<?= $canSeeHistory ? '</a>' : '</div>' ?>
<?php if ($canManage): ?>
<a class="icon-button contribution-card-add" href="/contributions_award.php?user=<?= (int) $member['id'] ?>"
title="Punkte an <?= e($displayName($member)) ?> vergeben" aria-label="Punkte vergeben">+</a>
<?php endif; ?>
</div>
<?php
};
$pageTitle = 'Lumipunkte';
$containerWide = true;
include __DIR__ . '/includes/header.php';
?>
<div class="panel contribution-hero">
<img class="contribution-hero-coin" src="/assets/images/lumipunkt.svg" alt="" width="72" height="72">
<div class="contribution-hero-text">
<h1>Lumipunkte</h1>
<p class="text-muted">Punkte für Raids, Events und alles, was die Legion voranbringt.</p>
</div>
<div class="contribution-hero-balance" title="Dein Punktestand">
<span class="text-muted">Dein Punktestand</span>
<strong><?= contribution_coin(26) ?> <?= contribution_format($myBalance) ?></strong>
</div>
<?php if ($canManage): ?>
<a class="button" href="/contributions_award.php">Punkte vergeben</a>
<?php endif; ?>
</div>
<div class="panel">
<div class="contribution-head">
<h2>Rangliste <span class="contribution-top-label">Top <?= CONTRIBUTION_PUBLIC_RANKS ?></span></h2>
<input type="search" id="contribution-search" placeholder="Mitglied suchen …" autocomplete="off">
</div>
<?php if (empty($balances)): ?>
<p class="text-muted">Noch keine Mitglieder.</p>
<?php else: ?>
<div class="contribution-grid" id="contribution-ranking" data-limit="<?= CONTRIBUTION_PUBLIC_RANKS ?>">
<?php foreach ($visibleBalances as $index => $member): ?>
<?php $renderCard($member, $index >= CONTRIBUTION_PUBLIC_RANKS); ?>
<?php endforeach; ?>
</div>
<p class="text-muted" id="contribution-no-match" hidden>Kein Mitglied passt zur Suche.</p>
<?php if (count($visibleBalances) > CONTRIBUTION_PUBLIC_RANKS): ?>
<div class="contribution-more">
<button type="button" class="button button-secondary" id="contribution-show-all"
data-more="Alle <?= count($visibleBalances) ?> anzeigen" data-less="Nur die besten <?= CONTRIBUTION_PUBLIC_RANKS ?> anzeigen">
Alle <?= count($visibleBalances) ?> anzeigen
</button>
</div>
<?php endif; ?>
<?php if ($showMyEntrySeparately): ?>
<div class="contribution-own">
<h3>Dein Platz</h3>
<div class="contribution-grid">
<?php $renderCard($myEntry); ?>
</div>
</div>
<?php endif; ?>
<?php if ($hiddenCount > 0): ?>
<p class="text-muted contribution-limit-note">
Angezeigt werden die besten <?= CONTRIBUTION_PUBLIC_RANKS ?> Plätze. Die vollständige Rangliste
(<?= count($balances) ?> Mitglieder) ist der Legionsleitung vorbehalten.
</p>
<?php endif; ?>
<?php endif; ?>
</div>
<?php if ($canSeeHistory): ?>
<div class="panel" id="verlauf">
<div class="contribution-head">
<h2>
Verlauf<?= $filterUser ? ': ' . e($displayName($filterUser)) : '' ?>
<?php if ($filterUser): ?>
<span class="contribution-filter-balance"><?= contribution_coin(20) ?> <?= contribution_format((int) $filterUser['points']) ?></span>
<?php endif; ?>
</h2>
<?php if ($filterUser): ?>
<a href="/contributions.php#verlauf">Alle Vergaben anzeigen</a>
<?php endif; ?>
</div>
<?php if ($canManage): ?>
<form class="settings-toggle" method="post" action="/admin/settings_action.php">
<?= csrf_field() ?>
<input type="hidden" name="setting" value="contributions_history_public">
<label>
<input type="checkbox" name="value" value="1" <?= $historyPublic ? 'checked' : '' ?> onchange="this.form.submit()">
Verlauf für alle sichtbar
<span class="text-muted">- sonst sehen ihn nur Leute, die Punkte vergeben dürfen</span>
</label>
<noscript><button type="submit" class="button-secondary button-small">Speichern</button></noscript>
</form>
<?php endif; ?>
<?php if (empty($awards)): ?>
<p class="text-muted">Noch keine Lumipunkte vergeben.</p>
<?php else: ?>
<div class="contribution-awards">
<?php foreach ($awards as $award): ?>
<?php
$entries = $award['entries'];
$pointValues = array_unique(array_map(static fn (array $entry): int => (int) $entry['points'], $entries));
$uniform = count($pointValues) === 1 ? (int) reset($pointValues) : null;
$mine = null;
if ($filterUserId !== null) {
foreach ($entries as $entry) {
if ((int) $entry['user_id'] === $filterUserId) {
$mine = (int) $entry['points'];
}
}
}
$shownPoints = $mine ?? $uniform;
$isSystem = isset(CONTRIBUTION_SYSTEM_CATEGORIES[(string) $award['category']]);
?>
<article class="contribution-award">
<div class="contribution-award-points<?= $shownPoints !== null && $shownPoints < 0 ? ' negative' : '' ?>">
<?= contribution_coin(22) ?>
<strong><?= $shownPoints !== null ? contribution_format($shownPoints, true) : 'versch.' ?></strong>
<?php if ($mine === null && count($entries) > 1): ?>
<span class="text-muted">je Mitglied</span>
<?php endif; ?>
</div>
<div class="contribution-award-body">
<div class="contribution-award-title">
<span class="badge contribution-badge-<?= e((string) $award['category']) ?>"><?= e(contribution_category_label((string) $award['category'])) ?></span>
<strong><?= e((string) $award['title']) ?></strong>
</div>
<?php if (!empty($award['note'])): ?>
<p class="contribution-award-note"><?= e((string) $award['note']) ?></p>
<?php endif; ?>
<div class="contribution-award-meta text-muted">
<?= e(contribution_format_time($award['awarded_at'])) ?>
· <?= count($entries) ?> <?= count($entries) === 1 ? 'Mitglied' : 'Mitglieder' ?>
<?php if (!empty($award['author'])): ?>· <?= $isSystem ? 'bewilligt' : 'vergeben' ?> von <?= e((string) $award['author']) ?><?php endif; ?>
</div>
<details class="contribution-award-members"<?= count($entries) <= 6 ? ' open' : '' ?>>
<summary>Mitglieder anzeigen</summary>
<div class="contribution-chips">
<?php foreach ($entries as $entry): ?>
<span class="contribution-chip<?= (int) $entry['user_id'] === $filterUserId ? ' highlight' : '' ?>">
<a href="/contributions.php?user=<?= (int) $entry['user_id'] ?>#verlauf"><?= e((string) $entry['name']) ?></a>
<?php if ($uniform === null): ?>
<span class="text-muted"><?= contribution_format((int) $entry['points'], true) ?></span>
<?php endif; ?>
<?php if ($canManage && !$isSystem): ?>
<form class="inline-form" method="post" action="/contributions_action.php"
onsubmit="return confirm(<?= e(json_encode('„' . $entry['name'] . '“ aus dieser Vergabe entfernen? Die Punkte werden abgezogen.', JSON_UNESCAPED_UNICODE)) ?>);">
<?= csrf_field() ?>
<input type="hidden" name="action" value="remove_entry">
<input type="hidden" name="entry_id" value="<?= (int) $entry['id'] ?>">
<button type="submit" class="contribution-chip-remove" title="Aus der Vergabe entfernen" aria-label="Entfernen">×</button>
</form>
<?php endif; ?>
</span>
<?php endforeach; ?>
</div>
</details>
</div>
<?php if ($canManage && !$isSystem): ?>
<form class="contribution-award-delete" method="post" action="/contributions_action.php"
onsubmit="return confirm(<?= e(json_encode('Vergabe „' . $award['title'] . '“ komplett löschen? Allen ' . count($entries) . ' Mitgliedern werden die Punkte wieder abgezogen.', JSON_UNESCAPED_UNICODE)) ?>);">
<?= csrf_field() ?>
<input type="hidden" name="action" value="delete_award">
<input type="hidden" name="award_id" value="<?= (int) $award['id'] ?>">
<button type="submit" class="icon-button icon-button-danger" title="Vergabe löschen" aria-label="Vergabe löschen"><?= icon('trash') ?></button>
</form>
<?php endif; ?>
</article>
<?php endforeach; ?>
</div>
<div class="contribution-pages">
<span class="text-muted">
Vergaben <?= ($page - 1) * $perPage + 1 ?>–<?= min($page * $perPage, $totalAwards) ?>
von <?= number_format($totalAwards, 0, ',', '.') ?>
</span>
<?php render_pagination('/contributions.php?' . ($filterUserId !== null ? 'user=' . $filterUserId . '&' : ''), $page, $pageCount, '#verlauf'); ?>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
<script src="<?= e(asset_url('/assets/js/contributions.js')) ?>"></script>
<?php include __DIR__ . '/includes/footer.php'; ?>