diff --git a/README.md b/README.md index 211430e..bf40401 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ und wird später ausgebaut. Fokus dieser Version ist der Mitglieder-/Admin-Berei - Karte: interaktive Zoom-Karte aller Regionen (Verteron, Altgard, Elthen, Morheim, Poeta, Ishalgen, Reshanta) mit Markern und Kategorie-Filtern, dazu Taktiken in Schritten, die direkt auf die Karte gezeichnet werden +- Beitragspunkte: Punkte für Raids, Events und andere Aktivitäten an einzelne oder viele + Mitglieder vergeben, mit Rangliste und Verlauf - Lagerhaus: Bestand der Legion mit Einlagerungen (wer hat was wann überreicht) und Entnahmen (wann, optional an wen), Gegenstandsliste aus dem Aion-2-Wiki mit rund 2.300 Einträgen - Raids-Seite: zeigt anstehende Raid-Termine, Anforderungen, Gruppen und Anmeldungen, @@ -390,6 +392,43 @@ Berechtigung `map.manage` werden nicht mehr benutzt und können bei bestehenden gelöscht werden. Die alten Taktiken werden nicht übernommen: Sie lagen als Anteil eines selbst erstellten Kartenbildes vor, das mit den neuen Kacheln nicht übereinstimmt. +### Beitragspunkte + +Die Seite **Beitragspunkte** (`contributions.php`) vergibt Punkte an Mitglieder, für Raids, +Events oder alles andere, was die Legion voranbringt. Ihr Symbol ist eine goldene Münze in +Herzform (`assets/images/beitragspunkt.svg`). + +- **Rangliste:** alle aktiven Mitglieder mit ihrem Punktestand als Karten, höchster zuerst. + Platz 1 bis 3 sind gold, silber und bronze umrandet, die eigene Karte hervorgehoben. Ein + Klick auf eine Karte zeigt nur die Vergaben dieses Mitglieds. Den eigenen Stand zeigt die + Seite oben und die Seitenleiste unter dem Namen. +- **Punkte vergeben** (`contributions_award.php`): Anlass (Raid, Event, Sonstiges), Grund, + Datum, Punkte pro Mitglied und optional eine Bemerkung. Die Mitglieder wählt man per Häkchen + aus, mit Suche und „Alle/Keine“. Beim Anlass Raid lässt sich ein Raid aus der Raid-API + wählen: Seine Teilnehmer (angemeldet in einer Gruppe) werden dann vorausgewählt, Grund und + Datum vorbelegt. Wer auf der Ersatzbank steht, wird nicht angekreuzt. Wer kein Website-Konto + mit Discord-Verknüpfung hat, wird genannt, kann aber keine Punkte bekommen. +- **Einzelne Mitglieder:** Das + an einer Karte öffnet das Formular mit genau diesem Mitglied. +- **Abzüge:** Negative Punkte ziehen ab, etwa für Korrekturen. +- **Verlauf** aller Vergaben mit Seiten: Punkte, Anlass, Grund, Datum, wer vergeben hat und die + beteiligten Mitglieder. Eine Vergabe lässt sich ganz löschen oder einzelne Mitglieder daraus + entfernen, die Punkte werden dann wieder abgezogen. + +Der Punktestand wird nicht gespeichert, sondern aus den Vergaben berechnet (Tabellen +`contribution_awards` und `contribution_entries`). So kann er nicht vom Verlauf abweichen, und +Punkte lassen sich später auch ausgeben, ohne das System umzubauen. + +Wer nur `contributions.view` hat, sieht in der Rangliste die besten 25 Plätze (bei Gleichstand +an der Grenze alle, die sich Platz 25 teilen) und darunter seinen eigenen Platz. Die +vollständige Rangliste zeigt die Seite mit `contributions.view_all` oder `contributions.manage`. +Die Grenze steht als `CONTRIBUTION_PUBLIC_RANKS` in `includes/contributions.php`. + +Rechte: `contributions.view` (Top 25 und Verlauf ansehen), `contributions.view_all` (vollständige +Rangliste) und `contributions.manage` +(vergeben, abziehen, löschen). Beide legt die Website selbst an und gibt sie der Gruppe +„Administrator“. Anderen Gruppen muss man sie unter Berechtigungsgruppen zuweisen, den +Mitgliedern z.B. nur `contributions.view`. + ### Lagerhaus Die Seite **Lagerhaus** (`warehouse.php`) führt Buch über die Gegenstände der Legion. diff --git a/assets/css/style.css b/assets/css/style.css index 10bc13d..df4a269 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -49,7 +49,7 @@ a:hover { color: var(--gold-hover); text-decoration: underline; } .navbar-brand img { display: block; - height: 40px; + height: 48px; width: auto; } @@ -85,22 +85,23 @@ a:hover { color: var(--gold-hover); text-decoration: underline; } } .sidebar-brand { - padding: 0 0.65rem 1.5rem; + padding: 0 0.65rem 1rem; font-size: 1.15rem; font-weight: bold; } .sidebar-brand a { display: block; } -/* Das Logo ist sehr breit (Seitenverhaeltnis 480:108). Mit fester Hoehe waere es breiter - als die Sidebar und wuerde unten eine waagerechte Scrollleiste erzeugen - deshalb - skaliert es ueber die Breite und behaelt seine Hoehe nur als Obergrenze. */ +/* Das Logo ist quadratisch (Wappen mit Schriftzug). Ueber die volle Sidebar-Breite waere es + fast 240px hoch - deshalb begrenzt und mittig, mit weichem Goldschein. */ .sidebar-brand img { display: block; width: 100%; - max-width: 100%; + max-width: 136px; height: auto; - max-height: 56px; + margin: 0 auto; + border-radius: 12px; + box-shadow: 0 0 0 1px rgba(201, 162, 39, 0.35), 0 6px 22px rgba(201, 162, 39, 0.18); } .sidebar-brand a { color: var(--gold); } @@ -149,7 +150,7 @@ a:hover { color: var(--gold-hover); text-decoration: underline; } .mobile-topbar-brand img { display: block; - height: 32px; + height: 40px; width: auto; } @@ -2223,3 +2224,302 @@ a.page-link:hover { border-color: var(--gold); color: var(--gold); text-decorati align-items: center; gap: 0.5rem; } + +/* --- Beitragspunkte --- */ + +.app-content.bg-contributions { + background-image: linear-gradient(rgba(20, 20, 20, 0.7), rgba(20, 20, 20, 0.86)), url('/assets/images/Landscapes/web/landscape2-bg.jpg'); +} + +.contribution-coin { display: inline-block; vertical-align: -0.2em; flex-shrink: 0; } + +.contribution-hero { + display: flex; + align-items: center; + flex-wrap: wrap; + gap: 1rem 1.5rem; +} + +.contribution-hero-coin { filter: drop-shadow(0 4px 10px rgba(201, 162, 39, 0.35)); } +.contribution-hero-text { flex: 1; min-width: 220px; } +.contribution-hero-text h1 { margin: 0 0 0.25rem; } +.contribution-hero-text p { margin: 0; } + +.contribution-hero-balance { + display: flex; + flex-direction: column; + align-items: flex-end; + font-size: 0.85rem; +} + +.contribution-hero-balance strong { + display: flex; + align-items: center; + gap: 0.4rem; + font-size: 1.8rem; + color: var(--gold); +} + +.contribution-head { + display: flex; + align-items: center; + justify-content: space-between; + flex-wrap: wrap; + gap: 0.75rem 1.5rem; + margin-bottom: 1rem; +} + +.contribution-head h1, .contribution-head h2 { + display: flex; + align-items: center; + gap: 0.6rem; + margin: 0; +} + +.contribution-head input[type="search"] { width: auto; min-width: 240px; } + +.contribution-filter-balance { + display: inline-flex; + align-items: center; + gap: 0.3rem; + padding: 0.15rem 0.6rem; + border-radius: 999px; + background: rgba(201, 162, 39, 0.15); + font-size: 1rem; +} + +/* Rangliste */ +.contribution-grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); + gap: 0.75rem; +} + +.contribution-card { + position: relative; + border: 1px solid var(--border); + border-radius: 10px; + background: rgba(35, 35, 35, 0.72); + transition: border-color 0.15s, transform 0.15s; +} + +.contribution-card:hover { border-color: var(--gold); transform: translateY(-2px); } +.contribution-card[hidden] { display: none; } +.contribution-card.is-me { border-color: rgba(201, 162, 39, 0.6); background: rgba(201, 162, 39, 0.08); } +.contribution-card.rank-1 { box-shadow: 0 0 0 1px #e8c35a inset, 0 0 18px rgba(232, 195, 90, 0.25); } +.contribution-card.rank-2 { box-shadow: 0 0 0 1px #c9ced6 inset; } +.contribution-card.rank-3 { box-shadow: 0 0 0 1px #c98a55 inset; } + +.contribution-card-link { + display: flex; + flex-direction: column; + align-items: center; + gap: 0.4rem; + padding: 1rem 0.6rem 0.8rem; + color: var(--text); + text-align: center; +} + +.contribution-card-link:hover { color: var(--text); text-decoration: none; } + +.contribution-rank { + position: absolute; + top: 0.45rem; + left: 0.55rem; + font-size: 0.75rem; + font-weight: 700; + color: var(--text-muted); +} + +.rank-1 .contribution-rank { color: #e8c35a; } +.rank-2 .contribution-rank { color: #c9ced6; } +.rank-3 .contribution-rank { color: #c98a55; } + +.contribution-card-name { font-weight: 600; font-size: 0.9rem; overflow-wrap: anywhere; } + +.contribution-card-points { + display: inline-flex; + align-items: center; + gap: 0.3rem; + font-weight: 700; + color: var(--gold); +} + +.contribution-card-add { + position: absolute; + top: 0.35rem; + right: 0.35rem; + width: 26px; + height: 26px; + font-size: 1rem; + opacity: 0; + transition: opacity 0.15s; +} + +.contribution-card:hover .contribution-card-add, +.contribution-card-add:focus { opacity: 1; } +a.contribution-card-add:hover { text-decoration: none; } + +@media (hover: none) { + .contribution-card-add { opacity: 1; } +} + +/* Verlauf der Vergaben */ +.contribution-awards { display: flex; flex-direction: column; gap: 0.6rem; } + +.contribution-award { + display: flex; + align-items: flex-start; + gap: 1rem; + padding: 0.8rem 1rem; + border: 1px solid var(--border); + border-radius: 10px; + background: rgba(35, 35, 35, 0.6); +} + +.contribution-award-points { + display: flex; + flex-direction: column; + align-items: center; + min-width: 76px; + gap: 0.15rem; + font-size: 0.75rem; +} + +.contribution-award-points strong { font-size: 1.25rem; color: var(--success); } +.contribution-award-points.negative strong { color: var(--danger); } + +.contribution-award-body { flex: 1; min-width: 0; } + +.contribution-award-title { + display: flex; + align-items: center; + flex-wrap: wrap; + gap: 0.5rem; +} + +.contribution-award-note { margin: 0.3rem 0 0; font-size: 0.9rem; } +.contribution-award-meta { margin-top: 0.3rem; font-size: 0.8rem; } + +.contribution-badge-raid { border-color: #d9534f; color: #ff8a86; } +.contribution-badge-event { border-color: var(--discord); color: #9aa3ff; } +.contribution-badge-other { border-color: var(--border); } + +.contribution-award-members { margin-top: 0.4rem; font-size: 0.85rem; } +.contribution-award-members summary { cursor: pointer; color: var(--text-muted); } +.contribution-award-members[open] summary { margin-bottom: 0.4rem; } + +.contribution-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; } + +.contribution-chip { + display: inline-flex; + align-items: center; + gap: 0.3rem; + padding: 0.15rem 0.3rem 0.15rem 0.6rem; + border: 1px solid var(--border); + border-radius: 999px; + background: var(--bg-panel-alt); +} + +.contribution-chip.highlight { border-color: var(--gold); } +.contribution-chip a { color: var(--text); } + +button.contribution-chip-remove { + padding: 0 0.3rem; + border: none; + background: none; + color: var(--text-muted); + font-size: 1rem; + line-height: 1; + cursor: pointer; +} + +button.contribution-chip-remove:hover { background: none; color: var(--danger); } + +.contribution-award-delete { flex-shrink: 0; } + +.contribution-pages { + display: flex; + align-items: center; + justify-content: space-between; + flex-wrap: wrap; + gap: 0.75rem; + margin-top: 1rem; + font-size: 0.9rem; +} + +/* Formular */ +.contribution-form-grid { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 1rem; +} + +.contribution-form-wide { grid-column: 1 / -1; } +.contribution-form-grid [hidden] { display: none; } + +.contribution-picker-head { + display: flex; + align-items: center; + flex-wrap: wrap; + gap: 0.5rem; +} + +.contribution-picker-head label { margin-right: auto; } +.contribution-picker-head input[type="search"] { width: auto; min-width: 200px; } +.contribution-picker-count { font-weight: 400; color: var(--text-muted); } +.contribution-raid-info { margin: 0.5rem 0 0; } + +.contribution-picker-grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); + gap: 0.4rem; + margin-top: 0.6rem; + max-height: 420px; + overflow-y: auto; + padding: 0.2rem; +} + +.contribution-pick { + display: flex; + align-items: center; + gap: 0.5rem; + padding: 0.4rem 0.6rem; + border: 1px solid var(--border); + border-radius: 8px; + font-weight: 500; + cursor: pointer; +} + +.contribution-pick[hidden] { display: none; } +.contribution-pick input { width: auto; } +.contribution-pick.checked { border-color: var(--gold); background: rgba(201, 162, 39, 0.1); } +.contribution-pick-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.contribution-pick-points { display: inline-flex; align-items: center; gap: 0.2rem; font-size: 0.8rem; color: var(--text-muted); } + +.sidebar-points { + display: inline-flex; + align-items: center; + gap: 0.25rem; + margin-top: 0.15rem; + font-weight: 700; + color: var(--gold); +} + +@media (max-width: 700px) { + .contribution-form-grid { grid-template-columns: 1fr; } + .contribution-hero-balance { align-items: flex-start; } + .contribution-award { flex-wrap: wrap; } +} + +.contribution-top-label { + padding: 0.1rem 0.5rem; + border: 1px solid var(--gold); + border-radius: 999px; + font-size: 0.8rem; + font-weight: 600; +} + +.contribution-own { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px dashed var(--border); } +.contribution-own h3 { margin: 0 0 0.6rem; font-size: 1rem; } +.contribution-limit-note { margin: 1rem 0 0; font-size: 0.85rem; } diff --git a/assets/images/beitragspunkt.svg b/assets/images/beitragspunkt.svg new file mode 100644 index 0000000..729154b --- /dev/null +++ b/assets/images/beitragspunkt.svg @@ -0,0 +1,96 @@ + + Beitragspunkt + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/images/logo-lumina.webp b/assets/images/logo-lumina.webp new file mode 100644 index 0000000..6353803 Binary files /dev/null and b/assets/images/logo-lumina.webp differ diff --git a/assets/images/logo-wordmark.webp b/assets/images/logo-wordmark.webp new file mode 100644 index 0000000..b369629 Binary files /dev/null and b/assets/images/logo-wordmark.webp differ diff --git a/assets/js/contributions.js b/assets/js/contributions.js new file mode 100644 index 0000000..446bebe --- /dev/null +++ b/assets/js/contributions.js @@ -0,0 +1,120 @@ +(function () { + 'use strict'; + + function matches(element, term) { + return term === '' || (element.dataset.name || '').indexOf(term) !== -1; + } + + // ---- Rangliste durchsuchen ---- + var rankingSearch = document.getElementById('contribution-search'); + var ranking = document.getElementById('contribution-ranking'); + if (rankingSearch && ranking) { + var noMatch = document.getElementById('contribution-no-match'); + rankingSearch.addEventListener('input', function () { + var term = rankingSearch.value.trim().toLowerCase(); + var visible = 0; + ranking.querySelectorAll('.contribution-card').forEach(function (card) { + card.hidden = !matches(card, term); + if (!card.hidden) visible++; + }); + if (noMatch) noMatch.hidden = visible > 0; + }); + } + + // ---- Formular "Punkte vergeben" ---- + var form = document.getElementById('contribution-form'); + if (!form) return; + + var picks = Array.prototype.slice.call(form.querySelectorAll('.contribution-pick')); + var boxes = picks.map(function (pick) { return pick.querySelector('input[type="checkbox"]'); }); + var counter = document.getElementById('picker-count'); + var pickerSearch = document.getElementById('picker-search'); + var submit = document.getElementById('contribution-submit'); + var pointsInput = document.getElementById('points'); + + function updateCount() { + var count = boxes.filter(function (box) { return box.checked; }).length; + counter.textContent = count === 0 ? '(keins ausgewählt)' : '(' + count + ' ausgewählt)'; + picks.forEach(function (pick, i) { pick.classList.toggle('checked', boxes[i].checked); }); + + var points = parseInt(pointsInput.value, 10); + var label = 'Punkte vergeben'; + if (count > 0 && points) { + label = points > 0 + ? points + ' Punkte an ' + count + (count === 1 ? ' Mitglied' : ' Mitglieder') + ' vergeben' + : Math.abs(points) + ' Punkte bei ' + count + (count === 1 ? ' Mitglied' : ' Mitgliedern') + ' abziehen'; + } + submit.textContent = label; + } + + boxes.forEach(function (box) { box.addEventListener('change', updateCount); }); + pointsInput.addEventListener('input', updateCount); + + pickerSearch.addEventListener('input', function () { + var term = pickerSearch.value.trim().toLowerCase(); + picks.forEach(function (pick) { pick.hidden = !matches(pick, term); }); + }); + + // "Alle" / "Keine" wirken nur auf die gerade sichtbaren (gefilterten) Mitglieder. + function setVisible(checked) { + picks.forEach(function (pick, i) { + if (!pick.hidden) boxes[i].checked = checked; + }); + updateCount(); + } + document.getElementById('picker-all').addEventListener('click', function () { setVisible(true); }); + document.getElementById('picker-none').addEventListener('click', function () { setVisible(false); }); + + // ---- Anlass und Raid ---- + var category = document.getElementById('category'); + var raidField = document.getElementById('raid-field'); + var raidSelect = document.getElementById('raid_id'); + var raidInfo = document.getElementById('raid-info'); + var titleInput = document.getElementById('title'); + var timeInput = document.getElementById('awarded_at'); + var raidsEl = document.getElementById('contribution-raids'); + var raids = raidsEl ? JSON.parse(raidsEl.textContent) : []; + var autoTitle = ''; + + function toggleRaidField() { + raidField.hidden = category.value !== 'raid'; + if (raidField.hidden && raidInfo) raidInfo.hidden = true; + } + category.addEventListener('change', toggleRaidField); + toggleRaidField(); + + if (raidSelect) { + raidSelect.addEventListener('change', function () { + var raid = raids.filter(function (r) { return String(r.id) === raidSelect.value; })[0]; + if (!raid) { + raidInfo.hidden = true; + return; + } + + // Teilnehmer des Raids auswaehlen, alle anderen abwaehlen. + boxes.forEach(function (box) { + box.checked = raid.participants.indexOf(parseInt(box.value, 10)) !== -1; + }); + + // Grund und Datum nur ueberschreiben, wenn nichts Eigenes eingetragen wurde. + if (titleInput.value === '' || titleInput.value === autoTitle) { + autoTitle = raid.title + (raid.date ? ' (' + raid.date + ')' : ''); + titleInput.value = autoTitle; + } + if (raid.time) timeInput.value = raid.time; + + var info = raid.participants.length + ' Teilnehmer ausgewählt.'; + if (raid.bench.length) { + info += ' ' + raid.bench.length + ' auf der Ersatzbank (nicht ausgewählt).'; + } + if (raid.withoutAccount.length) { + info += ' Ohne Website-Konto, daher keine Punkte möglich: ' + raid.withoutAccount.join(', ') + '.'; + } + raidInfo.textContent = info; + raidInfo.hidden = false; + updateCount(); + }); + } + + updateCount(); +})(); diff --git a/contributions.php b/contributions.php new file mode 100644 index 0000000..d5d3880 --- /dev/null +++ b/contributions.php @@ -0,0 +1,243 @@ + $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; + } +} +$visibleBalances = $canViewAll + ? $balances + : array_values(array_filter($balances, static fn (array $m): bool => (int) $m['rank'] <= 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 = 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 = 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) use ($currentUser, $canManage, $displayName): void { + ?> + 0 ? ' rank-' . (int) $member['rank'] : ''; + ?> +
+ + # + + + + + + + + +
+ +
+ +
+

Beitragspunkte

+

Punkte für Raids, Events und alles, was die Legion voranbringt.

+
+
+ Dein Punktestand + +
+ + Punkte vergeben + +
+ +
+
+

RanglisteTop ' . CONTRIBUTION_PUBLIC_RANKS . '' ?>

+ +
+ +

Noch keine Mitglieder.

+ +
+ + + +
+ + +
+

Dein Platz

+
+ +
+
+ + 0): ?> +

+ Angezeigt werden die besten Plätze. Die vollständige Rangliste + ( Mitglieder) ist der Legionsleitung vorbehalten. +

+ + +
+ +
+
+

+ Verlauf + + + +

+ + Alle Vergaben anzeigen + +
+ + +

Noch keine Beitragspunkte vergeben.

+ +
+ + (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; + ?> +
+
+ + + 1): ?> + je Mitglied + +
+
+
+ + +
+ +

+ +
+ + · + · vergeben von +
+
> + Mitglieder anzeigen +
+ + + + + + + +
+ + + + +
+ +
+ +
+
+
+ +
+ + + + +
+ +
+ +
+
+ + Vergaben – + von + + +
+ +
+ + + diff --git a/contributions_action.php b/contributions_action.php new file mode 100644 index 0000000..1ea0a02 --- /dev/null +++ b/contributions_action.php @@ -0,0 +1,119 @@ + (string) ($_POST['category'] ?? ''), + 'raid_id' => (string) ($_POST['raid_id'] ?? ''), + 'title' => (string) ($_POST['title'] ?? ''), + 'awarded_at' => (string) ($_POST['awarded_at'] ?? ''), + 'points' => (string) ($_POST['points'] ?? ''), + 'note' => (string) ($_POST['note'] ?? ''), + 'users' => array_map('intval', (array) ($_POST['users'] ?? [])), + ]; + set_flash('error', $message); + redirect('/contributions_award.php'); +} + +switch ($action) { + // ---- Punkte vergeben ---- + case 'create': + $category = (string) ($_POST['category'] ?? ''); + if (!array_key_exists($category, CONTRIBUTION_CATEGORIES)) { + contribution_fail('Bitte einen Anlass auswählen.'); + } + $title = trim((string) ($_POST['title'] ?? '')); + if ($title === '' || mb_strlen($title) > 150) { + contribution_fail('Bitte einen Grund mit höchstens 150 Zeichen angeben.'); + } + $note = trim((string) ($_POST['note'] ?? '')); + if (mb_strlen($note) > 255) { + contribution_fail('Die Bemerkung darf höchstens 255 Zeichen lang sein.'); + } + $points = filter_var($_POST['points'] ?? '', FILTER_VALIDATE_INT); + if ($points === false || $points === 0 || abs($points) > CONTRIBUTION_MAX_POINTS) { + contribution_fail('Bitte eine Punktzahl zwischen 1 und ' . number_format(CONTRIBUTION_MAX_POINTS, 0, ',', '.') . ' angeben (negativ für einen Abzug).'); + } + $awardedAt = contribution_parse_time((string) ($_POST['awarded_at'] ?? '')); + if ($awardedAt === null) { + contribution_fail('Bitte ein gültiges Datum angeben (nicht in der Zukunft).'); + } + $raidId = $category === 'raid' ? (int) ($_POST['raid_id'] ?? 0) : 0; + + // Nur aktive Konten - doppelte oder unbekannte IDs fallen hier heraus. + $userIds = array_values(array_unique(array_filter(array_map('intval', (array) ($_POST['users'] ?? []))))); + if (!empty($userIds)) { + $placeholders = implode(',', array_fill(0, count($userIds), '?')); + $stmt = $pdo->prepare("SELECT id FROM users WHERE status = 'active' AND id IN ($placeholders)"); + $stmt->execute($userIds); + $userIds = array_map('intval', $stmt->fetchAll(PDO::FETCH_COLUMN)); + } + if (empty($userIds)) { + contribution_fail('Bitte mindestens ein Mitglied auswählen.'); + } + + $pdo->beginTransaction(); + $pdo->prepare( + 'INSERT INTO contribution_awards (category, title, note, raid_id, awarded_at, created_by) VALUES (?, ?, ?, ?, ?, ?)' + )->execute([$category, $title, $note !== '' ? $note : null, $raidId > 0 ? $raidId : null, $awardedAt, (int) current_user()['id']]); + $awardId = (int) $pdo->lastInsertId(); + + $insert = $pdo->prepare('INSERT INTO contribution_entries (award_id, user_id, points) VALUES (?, ?, ?)'); + foreach ($userIds as $userId) { + $insert->execute([$awardId, $userId, $points]); + } + $pdo->commit(); + + $count = count($userIds); + $who = $count === 1 ? '1 Mitglied' : $count . ' Mitglieder'; + set_flash('success', $points > 0 + ? contribution_format($points) . ' Beitragspunkte an ' . $who . ' vergeben.' + : contribution_format(-$points) . ' Beitragspunkte bei ' . $who . ' abgezogen.'); + redirect('/contributions.php'); + + // ---- Ganze Vergabe loeschen ---- + case 'delete_award': + $stmt = $pdo->prepare('DELETE FROM contribution_awards WHERE id = ?'); + $stmt->execute([(int) ($_POST['award_id'] ?? 0)]); + set_flash($stmt->rowCount() > 0 ? 'success' : 'error', $stmt->rowCount() > 0 ? 'Vergabe gelöscht.' : 'Diese Vergabe gibt es nicht mehr.'); + redirect('/contributions.php#verlauf'); + + // ---- Ein Mitglied aus einer Vergabe entfernen ---- + case 'remove_entry': + $entryId = (int) ($_POST['entry_id'] ?? 0); + $stmt = $pdo->prepare('SELECT award_id FROM contribution_entries WHERE id = ?'); + $stmt->execute([$entryId]); + $awardId = (int) $stmt->fetchColumn(); + if ($awardId === 0) { + set_flash('error', 'Diesen Eintrag gibt es nicht mehr.'); + redirect('/contributions.php#verlauf'); + } + + $pdo->beginTransaction(); + $pdo->prepare('DELETE FROM contribution_entries WHERE id = ?')->execute([$entryId]); + // War es das letzte Mitglied, bliebe eine leere Vergabe uebrig - die faellt mit weg. + $left = $pdo->prepare('SELECT COUNT(*) FROM contribution_entries WHERE award_id = ?'); + $left->execute([$awardId]); + if ((int) $left->fetchColumn() === 0) { + $pdo->prepare('DELETE FROM contribution_awards WHERE id = ?')->execute([$awardId]); + } + $pdo->commit(); + + set_flash('success', 'Mitglied aus der Vergabe entfernt.'); + redirect('/contributions.php#verlauf'); + + default: + redirect('/contributions.php'); +} diff --git a/contributions_award.php b/contributions_award.php new file mode 100644 index 0000000..d2d17a5 --- /dev/null +++ b/contributions_award.php @@ -0,0 +1,169 @@ +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'; +?> +
+ + + +
+

Beitragspunkte vergeben

+ Zurück zur Übersicht +
+ +
+
+ + +
+
+ + + +
Wählt die Teilnehmer des Raids automatisch aus.
+ + +

Die Raids konnten nicht geladen werden (). Mitglieder bitte von Hand auswählen.

+ +
+
+ + +
+
+ + +
Negativ für einen Abzug.
+
+
+ + +
+
+ + +
+
+ +
+
+ + + + +
+ +
+ + + + +
+
+ +
+ + Abbrechen +
+
+ + + + diff --git a/includes/contributions.php b/includes/contributions.php new file mode 100644 index 0000000..ae2bc41 --- /dev/null +++ b/includes/contributions.php @@ -0,0 +1,152 @@ + 'Raid', + 'event' => 'Event', + 'other' => 'Sonstiges', +]; + +// So viele Plaetze der Rangliste sieht jeder mit contributions.view - den Rest nur mit +// contributions.view_all (oder contributions.manage). +const CONTRIBUTION_PUBLIC_RANKS = 25; + +// Obergrenze pro Mitglied und Vergabe - schuetzt vor Tippfehlern wie 10000 statt 100. +const CONTRIBUTION_MAX_POINTS = 10000; + +function contribution_category_label(string $key): string +{ + return CONTRIBUTION_CATEGORIES[$key] ?? $key; +} + +/** Das Muenz-Symbol der Beitragspunkte. */ +function contribution_coin(int $size = 20): string +{ + return 'Beitragspunkte'; +} + +/** Punkte mit Tausenderpunkt, Abzuege mit echtem Minuszeichen. */ +function contribution_format(int $points, bool $withSign = false): string +{ + $formatted = number_format(abs($points), 0, ',', '.'); + if ($points < 0) { + return '−' . $formatted; + } + return ($withSign && $points > 0 ? '+' : '') . $formatted; +} + +/** + * Punktestand aller aktiven Mitglieder (auch 0), hoechster zuerst. + * + * @return array> + */ +function contribution_balances(): array +{ + return db()->query( + "SELECT u.id, u.username, u.display_name, u.avatar_filename, + COALESCE(SUM(e.points), 0) AS points, + COUNT(e.id) AS award_count + FROM users u + LEFT JOIN contribution_entries e ON e.user_id = u.id + WHERE u.status = 'active' + GROUP BY u.id + ORDER BY points DESC, COALESCE(NULLIF(u.display_name, ''), u.username)" + )->fetchAll(); +} + +function contribution_user_balance(int $userId): int +{ + $stmt = db()->prepare('SELECT COALESCE(SUM(points), 0) FROM contribution_entries WHERE user_id = ?'); + $stmt->execute([$userId]); + return (int) $stmt->fetchColumn(); +} + +function contribution_award_count(?int $userId): int +{ + if ($userId === null) { + return (int) db()->query('SELECT COUNT(*) FROM contribution_awards')->fetchColumn(); + } + $stmt = db()->prepare('SELECT COUNT(*) FROM contribution_entries WHERE user_id = ?'); + $stmt->execute([$userId]); + return (int) $stmt->fetchColumn(); +} + +/** + * Vergaben mit ihren Empfaengern, neueste zuerst. Mit $userId nur die Vergaben, an denen + * dieses Mitglied beteiligt war. + * + * @return array> + */ +function contribution_awards(?int $userId, int $limit, int $offset): array +{ + $join = $userId !== null ? 'JOIN contribution_entries mine ON mine.award_id = a.id AND mine.user_id = ?' : ''; + $stmt = db()->prepare( + "SELECT a.id, a.category, a.title, a.note, a.raid_id, a.awarded_at, + COALESCE(NULLIF(cu.display_name, ''), cu.username) AS author + FROM contribution_awards a + $join + LEFT JOIN users cu ON cu.id = a.created_by + ORDER BY a.awarded_at DESC, a.id DESC + LIMIT " . (int) $limit . ' OFFSET ' . (int) $offset + ); + $stmt->execute($userId !== null ? [$userId] : []); + + $awards = []; + foreach ($stmt->fetchAll() as $row) { + $row['entries'] = []; + $awards[(int) $row['id']] = $row; + } + if (empty($awards)) { + return []; + } + + $ids = array_keys($awards); + $placeholders = implode(',', array_fill(0, count($ids), '?')); + $entryStmt = db()->prepare( + "SELECT e.id, e.award_id, e.user_id, e.points, + COALESCE(NULLIF(u.display_name, ''), u.username) AS name + FROM contribution_entries e + JOIN users u ON u.id = e.user_id + WHERE e.award_id IN ($placeholders) + ORDER BY name" + ); + $entryStmt->execute($ids); + foreach ($entryStmt->fetchAll() as $entry) { + $awards[(int) $entry['award_id']]['entries'][] = $entry; + } + + return array_values($awards); +} + +/** Jetzt in deutscher Zeit fuer ein datetime-local-Feld. */ +function contribution_now_input(): string +{ + return (new DateTimeImmutable('now', new DateTimeZone('Europe/Berlin')))->format('Y-m-d\TH:i'); +} + +/** Zeitpunkt aus einem datetime-local-Feld, null bei ungueltiger Eingabe oder weit in der Zukunft. */ +function contribution_parse_time(string $value): ?string +{ + $tz = new DateTimeZone('Europe/Berlin'); + $time = DateTimeImmutable::createFromFormat('Y-m-d\TH:i', trim($value), $tz); + if ($time === false || $time > new DateTimeImmutable('+1 day', $tz)) { + return null; + } + return $time->format('Y-m-d H:i:s'); +} + +function contribution_format_time(?string $value): string +{ + $time = $value ? strtotime($value) : false; + return $time ? date('d.m.Y H:i', $time) : '-'; +} diff --git a/includes/functions.php b/includes/functions.php index ea61635..394f45f 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -134,6 +134,7 @@ function icon(string $name): string 'at-sign' => '', 'chevron-down' => '', 'check' => '', + 'heart' => '', 'box' => '', ]; @@ -226,3 +227,61 @@ function class_icon_url(string $className): ?string return '/assets/images/Classes/normalized/' . $map[$key]; } + +/** + * Seitenzahlen fuer eine Blaetter-Leiste: immer die erste und letzte Seite, dazu zwei Seiten + * um die aktuelle herum, Luecken als null (wird als "..." angezeigt). + * + * @return array + */ +function page_numbers(int $current, int $last): array +{ + $pages = []; + $previous = 0; + for ($p = 1; $p <= $last; $p++) { + if ($p === 1 || $p === $last || abs($p - $current) <= 2) { + if ($previous && $p - $previous > 1) { + // Eine einzelne fehlende Seite lieber anzeigen als durch "..." ersetzen. + $pages[] = $p - $previous === 2 ? $p - 1 : null; + } + $pages[] = $p; + $previous = $p; + } + } + return $pages; +} + +/** + * Blaetter-Leiste "Zurueck 1 ... 4 5 [6] 7 8 ... 20 Weiter". $baseUrl endet auf "?" oder "&", + * $anchor (z.B. "#verlauf") wird an jeden Link gehaengt. + */ +function render_pagination(string $baseUrl, int $page, int $pageCount, string $anchor = ''): void +{ + if ($pageCount <= 1) { + return; + } + $link = static fn (int $number): string => e($baseUrl . 'page=' . $number . $anchor); + ?> + + prepare('SELECT COALESCE(SUM(points), 0) FROM contribution_entries WHERE user_id = ?'); + $pointsStmt->execute([(int) $shellUser['id']]); + $sidebarPoints = (int) $pointsStmt->fetchColumn(); + } catch (PDOException $e) { + $sidebarPoints = null; + } +} $canViewMembers = $currentUser && user_has_permission('members.view'); $canViewReports = $currentUser && user_has_permission('reports.view'); $showAdminMenu = $canViewUsers || $canManageRoles || $canViewReports; @@ -27,6 +39,7 @@ $isPremadesActive = $currentScript === 'premades.php'; $isEventsActive = $currentScript === 'events.php'; $isMapActive = $currentScript === 'map.php'; $isWarehouseActive = $currentScript === 'warehouse.php'; +$isContributionsActive = in_array($currentScript, ['contributions.php', 'contributions_award.php'], true); $isMembersActive = $currentScript === 'members.php'; $isReportsActive = $currentScript === 'reports.php'; $isUsersActive = in_array($currentScript, ['users.php', 'user_form.php', 'user_delete.php', 'user_approve.php'], true); @@ -41,6 +54,8 @@ $pageBackgrounds = [ 'events.php' => 'bg-events', 'map.php' => 'bg-map', 'warehouse.php' => 'bg-warehouse', + 'contributions.php' => 'bg-contributions', + 'contributions_award.php' => 'bg-contributions', 'members.php' => 'bg-members', 'users.php' => 'bg-admin', 'user_form.php' => 'bg-admin', @@ -94,11 +109,11 @@ $otherFlashes = array_values(array_filter($allFlashes, fn (array $f): bool => ($ - Lumina Ascendens + Lumina Ascendens