Raids: attendance list, automatic points on archive, reminder callback
Each raid gets an attendance list for raids.manage (present, absent, excused) with quick actions, members added by hand and a "checked" mark with who and when. The contribution form can now select a raid's present members for points or its absent members for a deduction. Raids can carry points for present members and a deduction for absent ones (raid_settings). When a raid is archived - on the website or via the button in Discord, detected on the next raid or contribution page view - the site awards them once: by attendance if a list exists, otherwise to everyone in a group without deduction, and not at all if points were already given for that raid. Settings, attendance and awards follow a raid_id change when the API re-posts a deleted message. bot_api.php lets the bot ask which signed-up members have raids.manage when a raid starts (shared key in config.php bot_callback.key); the bot then sends them a DM with a link to the list. The bot side lives in the separate bot repository (cogs/attendance.py). Also fixes contribution_awards.raid_id being too small for Discord IDs (it is widened automatically) and raid IDs losing precision in the contribution form's JavaScript, which kept the raid preselection from ever matching. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
dd7ad2a25b
commit
fe1561f4f7
17 changed files with 1059 additions and 31 deletions
66
README.md
66
README.md
|
|
@ -30,6 +30,8 @@ und wird später ausgebaut. Fokus dieser Version ist der Mitglieder-/Admin-Berei
|
||||||
Mitglieder vergeben, mit Rangliste und Verlauf
|
Mitglieder vergeben, mit Rangliste und Verlauf
|
||||||
- Lagerhaus: Bestand der Legion mit Einlagerungen (wer hat was wann überreicht) und Entnahmen
|
- 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
|
(wann, optional an wen), Gegenstandsliste aus dem Aion-2-Wiki mit rund 2.300 Einträgen
|
||||||
|
- Anwesenheitsliste pro Raid (anwesend, abwesend, entschuldigt), automatische Beitragspunkte
|
||||||
|
beim Archivieren und eine Discord-PN an die Raidleitung, sobald ein Raid beginnt
|
||||||
- Raids-Seite: zeigt anstehende Raid-Termine, Anforderungen, Gruppen und Anmeldungen,
|
- Raids-Seite: zeigt anstehende Raid-Termine, Anforderungen, Gruppen und Anmeldungen,
|
||||||
bezogen von einer externen API (`config.php: raids_api`), Filter Aktiv/Archiviert/Alle
|
bezogen von einer externen API (`config.php: raids_api`), Filter Aktiv/Archiviert/Alle
|
||||||
- "Mein Profil"-Seite: Anzeigename ändern, Passwort ändern, Discord-Verknüpfung verwalten
|
- "Mein Profil"-Seite: Anzeigename ändern, Passwort ändern, Discord-Verknüpfung verwalten
|
||||||
|
|
@ -392,6 +394,70 @@ 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
|
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.
|
selbst erstellten Kartenbildes vor, das mit den neuen Kacheln nicht übereinstimmt.
|
||||||
|
|
||||||
|
### Anwesenheit bei Raids
|
||||||
|
|
||||||
|
Auf der Raid-Seite hat jeder Raid für Mitglieder mit `raids.manage` den Knopf **Anwesenheit**
|
||||||
|
(`raid_attendance.php`). Dort steht jede Anmeldung mit Gruppe und Klasse und bekommt einen der
|
||||||
|
Zustände **Anwesend**, **Abwesend** oder **Entschuldigt**. Knöpfe setzen alle in den Gruppen auf
|
||||||
|
anwesend, die Ersatzbank auf abwesend oder Abgemeldete auf entschuldigt. Wer dabei war, ohne
|
||||||
|
angemeldet zu sein, lässt sich als Mitglied nachtragen. **Speichern & als kontrolliert
|
||||||
|
markieren** hält fest, wer die Liste wann geprüft hat. Die Raid-Karte zeigt danach „kontrolliert“,
|
||||||
|
vorher nach Raidbeginn „noch nicht kontrolliert“. Wer kein Website-Konto mit Discord-Verknüpfung
|
||||||
|
hat, steht mit in der Liste, kann aber keine Beitragspunkte bekommen.
|
||||||
|
|
||||||
|
Gespeichert wird in `raid_attendance` (je Raid und Discord-ID) und `raid_settings`. Die Raids
|
||||||
|
selbst liegen weiter beim Bot, zugeordnet ist alles über die `raid_id` (= Discord-Nachrichten-ID).
|
||||||
|
Postet die Raid-API eine gelöschte Nachricht neu und ändert sich dadurch die ID, ziehen
|
||||||
|
Einstellungen, Anwesenheit und Vergaben beim Bearbeiten mit um.
|
||||||
|
|
||||||
|
**Punkte nach Anwesenheit:** Im Formular „Punkte vergeben“ wählt man beim Anlass Raid einen Raid.
|
||||||
|
Mit Anwesenheitsliste sind die Anwesenden vorausgewählt. Ein Knopf wechselt auf die Abwesenden,
|
||||||
|
dann wird die Punktzahl negativ, also ein Abzug. Ohne Liste sind wie bisher alle in einer Gruppe
|
||||||
|
Angemeldeten vorausgewählt.
|
||||||
|
|
||||||
|
**Automatische Punkte beim Archivieren:** Beim Anlegen und Bearbeiten eines Raids gibt es die
|
||||||
|
Felder **Punkte für Anwesende** und **Abzug für Abwesende** (0 = keine Automatik). Wird der Raid
|
||||||
|
archiviert, vergibt die Website diese Punkte selbst:
|
||||||
|
|
||||||
|
- Anwesenheitsliste geführt: die Anwesenden bekommen die Punkte, den Abwesenden wird der Abzug
|
||||||
|
abgezogen, Entschuldigte bleiben unberührt.
|
||||||
|
- Keine Liste: alle, die in einer Gruppe angemeldet waren, bekommen die Punkte, einen Abzug gibt
|
||||||
|
es dann nicht.
|
||||||
|
- Wurden für den Raid vorher schon Punkte vergeben (von Hand), entfällt die Automatik.
|
||||||
|
|
||||||
|
Das gilt auch, wenn der Raid im Discord über den Knopf archiviert wurde. Davon erfährt die
|
||||||
|
Website nicht direkt, deshalb prüft sie beim Aufruf der Raid- und Punkteseiten, ob ein Raid mit
|
||||||
|
offener Automatik inzwischen archiviert ist. Jeder Raid wird nur einmal verarbeitet, das Ergebnis
|
||||||
|
steht an der Raid-Karte und in der Anwesenheitsliste.
|
||||||
|
|
||||||
|
#### Discord-PN zum Raidbeginn
|
||||||
|
|
||||||
|
Sobald die Uhrzeit eines Raids erreicht ist, bekommen alle Angemeldeten mit `raids.manage` eine
|
||||||
|
Discord-PN mit einem Knopf zur Anwesenheitsliste. War die Liste schon vorher als kontrolliert
|
||||||
|
markiert, entfällt die Nachricht. Das erledigt der Bot (Datei `cogs/attendance.py` im Bot-Repo
|
||||||
|
Aion2_RaidPlaner): Er prüft jede Minute, ob ein Raid begonnen hat, höchstens drei Stunden
|
||||||
|
rückwirkend, damit nach einer Pause keine Flut alter Erinnerungen kommt. Dann fragt er die
|
||||||
|
Website über `bot_api.php`, wer die Nachricht bekommen soll. Für jeden Raid geht die
|
||||||
|
Erinnerung einmal raus. Ist die Website nicht erreichbar, versucht er es später erneut.
|
||||||
|
|
||||||
|
Einrichtung:
|
||||||
|
|
||||||
|
1. In `config.php` der Website einen langen, zufälligen Schlüssel eintragen:
|
||||||
|
```php
|
||||||
|
'bot_callback' => [
|
||||||
|
'key' => 'mindestens-16-zeichen-zufaellig',
|
||||||
|
],
|
||||||
|
```
|
||||||
|
2. In der `.env` des Bots:
|
||||||
|
```
|
||||||
|
WEBSITE_URL=https://lumina.maaxxs-coding.de
|
||||||
|
WEBSITE_BOT_KEY=<derselbe Schlüssel>
|
||||||
|
```
|
||||||
|
3. `cogs/attendance.py` in den Bot kopieren und den Bot neu starten. Die zusätzliche Spalte
|
||||||
|
`attendance_notified` in `raids` legt die Datei beim Start selbst an.
|
||||||
|
|
||||||
|
Fehlt einer der Werte, bleibt die Erinnerung aus, alles andere funktioniert trotzdem.
|
||||||
|
|
||||||
### Beitragspunkte
|
### Beitragspunkte
|
||||||
|
|
||||||
Die Seite **Beitragspunkte** (`contributions.php`) vergibt Punkte an Mitglieder, für Raids,
|
Die Seite **Beitragspunkte** (`contributions.php`) vergibt Punkte an Mitglieder, für Raids,
|
||||||
|
|
|
||||||
|
|
@ -2522,3 +2522,116 @@ button.contribution-chip-remove:hover { background: none; color: var(--danger);
|
||||||
.contribution-own { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px dashed var(--border); }
|
.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-own h3 { margin: 0 0 0.6rem; font-size: 1rem; }
|
||||||
.contribution-limit-note { margin: 1rem 0 0; font-size: 0.85rem; }
|
.contribution-limit-note { margin: 1rem 0 0; font-size: 0.85rem; }
|
||||||
|
|
||||||
|
/* --- Raids: Anwesenheit und automatische Beitragspunkte --- */
|
||||||
|
|
||||||
|
.raid-points-fields {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
gap: 0.75rem;
|
||||||
|
margin-top: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.raid-points-fields label { display: flex; align-items: center; gap: 0.35rem; }
|
||||||
|
.raid-points-fields .field-hint { grid-column: 1 / -1; margin: 0; }
|
||||||
|
|
||||||
|
.raid-attendance-line {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.5rem;
|
||||||
|
margin: 0.25rem 0 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.button-small:hover { text-decoration: none; }
|
||||||
|
.raid-auto-points { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.85rem; }
|
||||||
|
|
||||||
|
.attendance-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.5rem 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.attendance-head h1 { margin-bottom: 0.2rem; }
|
||||||
|
.attendance-head p { margin-top: 0; }
|
||||||
|
|
||||||
|
.attendance-status {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.5rem 1rem;
|
||||||
|
padding: 0.75rem 1rem;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: var(--bg-panel-alt);
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.attendance-auto { display: inline-flex; align-items: center; gap: 0.35rem; }
|
||||||
|
|
||||||
|
.attendance-bulk {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.4rem;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.attendance-list { display: flex; flex-direction: column; gap: 0.35rem; }
|
||||||
|
|
||||||
|
.attendance-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.5rem 1rem;
|
||||||
|
padding: 0.55rem 0.8rem;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: rgba(35, 35, 35, 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
.attendance-person { display: flex; align-items: center; flex-wrap: wrap; gap: 0.3rem 0.6rem; }
|
||||||
|
.attendance-person .text-muted { font-size: 0.85rem; }
|
||||||
|
|
||||||
|
.attendance-choice { display: flex; gap: 0.3rem; }
|
||||||
|
|
||||||
|
.attendance-option {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0.3rem 0.7rem;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 999px;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
font-weight: 500;
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.attendance-option input { position: absolute; opacity: 0; pointer-events: none; }
|
||||||
|
.attendance-option:hover { border-color: var(--text-muted); }
|
||||||
|
.attendance-present:has(input:checked) { border-color: var(--success); background: rgba(76, 175, 80, 0.2); color: #8fdc92; }
|
||||||
|
.attendance-absent:has(input:checked) { border-color: var(--danger); background: rgba(217, 83, 79, 0.2); color: #ff9b97; }
|
||||||
|
.attendance-excused:has(input:checked) { border-color: var(--gold); background: rgba(201, 162, 39, 0.18); color: var(--gold); }
|
||||||
|
.attendance-none:has(input:checked) { border-color: var(--text-muted); background: var(--bg-panel-alt); }
|
||||||
|
.attendance-option:has(input:focus-visible) { outline: 2px solid var(--gold); outline-offset: 2px; }
|
||||||
|
|
||||||
|
.attendance-add { display: flex; flex-direction: column; gap: 0.3rem; max-width: 420px; }
|
||||||
|
|
||||||
|
@media (max-width: 600px) {
|
||||||
|
.raid-points-fields { grid-template-columns: 1fr; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.contribution-raid-mode {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.4rem;
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contribution-raid-mode[hidden] { display: none; }
|
||||||
|
.contribution-raid-mode .button-small.active { border-color: var(--gold); color: var(--gold); }
|
||||||
|
|
|
||||||
|
|
@ -83,36 +83,72 @@
|
||||||
category.addEventListener('change', toggleRaidField);
|
category.addEventListener('change', toggleRaidField);
|
||||||
toggleRaidField();
|
toggleRaidField();
|
||||||
|
|
||||||
|
var raidMode = document.getElementById('raid-mode');
|
||||||
|
var currentRaid = null;
|
||||||
|
|
||||||
|
function selectUsers(ids) {
|
||||||
|
boxes.forEach(function (box) {
|
||||||
|
box.checked = ids.indexOf(parseInt(box.value, 10)) !== -1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// mode: present = Anwesende mit Punkten, absent = Abwesende mit Abzug,
|
||||||
|
// participants = alle in einer Gruppe Angemeldeten (ohne Anwesenheitsliste).
|
||||||
|
function applyRaid(raid, mode) {
|
||||||
|
var ids = mode === 'present' ? raid.present : (mode === 'absent' ? raid.absent : raid.participants);
|
||||||
|
selectUsers(ids);
|
||||||
|
|
||||||
|
// Grund nur ueberschreiben, wenn nichts Eigenes eingetragen wurde.
|
||||||
|
if (titleInput.value === '' || titleInput.value === autoTitle) {
|
||||||
|
autoTitle = (mode === 'absent' ? 'Abwesend: ' : '') + raid.title + (raid.date ? ' (' + raid.date + ')' : '');
|
||||||
|
titleInput.value = autoTitle;
|
||||||
|
}
|
||||||
|
if (raid.time) timeInput.value = raid.time;
|
||||||
|
|
||||||
|
// Abwesenden werden Punkte abgezogen, allen anderen gutgeschrieben.
|
||||||
|
var points = parseInt(pointsInput.value, 10);
|
||||||
|
if (points && ((mode === 'absent' && points > 0) || (mode !== 'absent' && points < 0))) {
|
||||||
|
pointsInput.value = -points;
|
||||||
|
}
|
||||||
|
|
||||||
|
var info;
|
||||||
|
if (mode === 'present') {
|
||||||
|
info = ids.length + ' Anwesende ausgewählt (laut Anwesenheitsliste).';
|
||||||
|
} else if (mode === 'absent') {
|
||||||
|
info = ids.length + ' Abwesende ausgewählt - die Punkte werden abgezogen.';
|
||||||
|
} else {
|
||||||
|
info = ids.length + ' Teilnehmer ausgewählt (laut Anmeldung).';
|
||||||
|
if (raid.bench.length) info += ' ' + raid.bench.length + ' auf der Ersatzbank (nicht ausgewählt).';
|
||||||
|
}
|
||||||
|
if (!raid.attendance) {
|
||||||
|
info += ' Für diesen Raid wurde noch keine Anwesenheitsliste geführt.';
|
||||||
|
}
|
||||||
|
if (raid.withoutAccount.length) {
|
||||||
|
info += ' Ohne Website-Konto, daher keine Punkte möglich: ' + raid.withoutAccount.join(', ') + '.';
|
||||||
|
}
|
||||||
|
raidInfo.textContent = info;
|
||||||
|
raidInfo.hidden = false;
|
||||||
|
raidMode.querySelectorAll('[data-raid-mode]').forEach(function (button) {
|
||||||
|
button.classList.toggle('active', button.getAttribute('data-raid-mode') === mode);
|
||||||
|
});
|
||||||
|
updateCount();
|
||||||
|
}
|
||||||
|
|
||||||
if (raidSelect) {
|
if (raidSelect) {
|
||||||
raidSelect.addEventListener('change', function () {
|
raidSelect.addEventListener('change', function () {
|
||||||
var raid = raids.filter(function (r) { return String(r.id) === raidSelect.value; })[0];
|
currentRaid = raids.filter(function (r) { return r.id === raidSelect.value; })[0] || null;
|
||||||
if (!raid) {
|
raidMode.hidden = !(currentRaid && currentRaid.attendance);
|
||||||
|
if (!currentRaid) {
|
||||||
raidInfo.hidden = true;
|
raidInfo.hidden = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
applyRaid(currentRaid, currentRaid.attendance ? 'present' : 'participants');
|
||||||
|
});
|
||||||
|
|
||||||
// Teilnehmer des Raids auswaehlen, alle anderen abwaehlen.
|
raidMode.querySelectorAll('[data-raid-mode]').forEach(function (button) {
|
||||||
boxes.forEach(function (box) {
|
button.addEventListener('click', function () {
|
||||||
box.checked = raid.participants.indexOf(parseInt(box.value, 10)) !== -1;
|
if (currentRaid) applyRaid(currentRaid, button.getAttribute('data-raid-mode'));
|
||||||
});
|
});
|
||||||
|
|
||||||
// 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();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,9 @@
|
||||||
gearscore: form.gearscore.value,
|
gearscore: form.gearscore.value,
|
||||||
group_names: groupNames.join(', '),
|
group_names: groupNames.join(', '),
|
||||||
max_slots: form.max_slots.value,
|
max_slots: form.max_slots.value,
|
||||||
locked_groups: lockedGroups
|
locked_groups: lockedGroups,
|
||||||
|
points_present: form.points_present ? form.points_present.value : 0,
|
||||||
|
points_absent: form.points_absent ? form.points_absent.value : 0
|
||||||
}).then(function (result) {
|
}).then(function (result) {
|
||||||
feedback.textContent = result.message || '';
|
feedback.textContent = result.message || '';
|
||||||
if (result.status === 'success') {
|
if (result.status === 'success') {
|
||||||
|
|
@ -276,7 +278,9 @@
|
||||||
requirements: raidCreateForm.requirements.value,
|
requirements: raidCreateForm.requirements.value,
|
||||||
gearscore: raidCreateForm.gearscore.value,
|
gearscore: raidCreateForm.gearscore.value,
|
||||||
group_names: groupNames.join(', '),
|
group_names: groupNames.join(', '),
|
||||||
max_slots: raidCreateForm.max_slots.value
|
max_slots: raidCreateForm.max_slots.value,
|
||||||
|
points_present: raidCreateForm.points_present.value,
|
||||||
|
points_absent: raidCreateForm.points_absent.value
|
||||||
}).then(function (result) {
|
}).then(function (result) {
|
||||||
feedback.textContent = result.message || '';
|
feedback.textContent = result.message || '';
|
||||||
if (result.status === 'success') {
|
if (result.status === 'success') {
|
||||||
|
|
|
||||||
72
bot_api.php
Normal file
72
bot_api.php
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Rueckkanal fuer den Discord-Bot (cogs/attendance.py im Bot).
|
||||||
|
*
|
||||||
|
* Wenn die Uhrzeit eines Raids erreicht ist, fragt der Bot hier nach, wer von den Angemeldeten
|
||||||
|
* eine Erinnerung zur Anwesenheitsliste bekommen soll: alle mit einem aktiven Website-Konto und
|
||||||
|
* der Berechtigung raids.manage. Die Discord-PN schickt der Bot selbst.
|
||||||
|
*
|
||||||
|
* GET /bot_api.php?action=attendance_recipients&raid_id=...&discord_ids=1,2,3
|
||||||
|
* Header: X-Bot-Key: <config.php bot_callback.key>
|
||||||
|
*/
|
||||||
|
require_once __DIR__ . '/includes/bootstrap.php';
|
||||||
|
require_once __DIR__ . '/includes/raid_attendance.php';
|
||||||
|
|
||||||
|
header('Content-Type: application/json; charset=UTF-8');
|
||||||
|
|
||||||
|
function bot_api_reply(int $status, array $data): void
|
||||||
|
{
|
||||||
|
http_response_code($status);
|
||||||
|
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$expectedKey = bot_callback_key();
|
||||||
|
if ($expectedKey === null) {
|
||||||
|
bot_api_reply(503, ['status' => 'error', 'message' => 'bot_callback.key ist in config.php nicht eingetragen.']);
|
||||||
|
}
|
||||||
|
$givenKey = (string) ($_SERVER['HTTP_X_BOT_KEY'] ?? '');
|
||||||
|
if (!hash_equals($expectedKey, $givenKey)) {
|
||||||
|
bot_api_reply(403, ['status' => 'error', 'message' => 'Ungültiger Schlüssel.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$action = (string) ($_GET['action'] ?? '');
|
||||||
|
if ($action !== 'attendance_recipients') {
|
||||||
|
bot_api_reply(400, ['status' => 'error', 'message' => 'Unbekannte Aktion.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$raidId = (string) ($_GET['raid_id'] ?? '');
|
||||||
|
if (!ctype_digit($raidId)) {
|
||||||
|
bot_api_reply(400, ['status' => 'error', 'message' => 'raid_id fehlt.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$discordIds = array_values(array_filter(
|
||||||
|
array_map('trim', explode(',', (string) ($_GET['discord_ids'] ?? ''))),
|
||||||
|
static fn (string $id): bool => $id !== '' && ctype_digit($id)
|
||||||
|
));
|
||||||
|
|
||||||
|
$recipients = [];
|
||||||
|
if (!empty($discordIds)) {
|
||||||
|
$placeholders = implode(',', array_fill(0, count($discordIds), '?'));
|
||||||
|
$stmt = db()->prepare(
|
||||||
|
"SELECT DISTINCT u.discord_id FROM users u
|
||||||
|
JOIN user_roles ur ON ur.user_id = u.id
|
||||||
|
JOIN role_permissions rp ON rp.role_id = ur.role_id
|
||||||
|
JOIN permissions p ON p.id = rp.permission_id
|
||||||
|
WHERE u.status = 'active' AND p.`key` = 'raids.manage' AND u.discord_id IN ($placeholders)"
|
||||||
|
);
|
||||||
|
$stmt->execute($discordIds);
|
||||||
|
$recipients = array_map('strval', $stmt->fetchAll(PDO::FETCH_COLUMN));
|
||||||
|
}
|
||||||
|
|
||||||
|
$settings = raid_settings_get((int) $raidId);
|
||||||
|
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
|
||||||
|
$host = (string) ($_SERVER['HTTP_HOST'] ?? '');
|
||||||
|
|
||||||
|
bot_api_reply(200, [
|
||||||
|
'status' => 'success',
|
||||||
|
'recipients' => $recipients,
|
||||||
|
// Schon kontrolliert (z.B. vor Raidbeginn)? Dann braucht es keine Erinnerung mehr.
|
||||||
|
'checked' => $settings['attendance_checked_at'] !== null,
|
||||||
|
'url' => $scheme . '://' . $host . '/raid_attendance.php?raid=' . $raidId,
|
||||||
|
]);
|
||||||
|
|
@ -21,6 +21,11 @@ return [
|
||||||
// dieses Servers. Ohne raid_channel-Konfiguration im Bot schlaegt das Erstellen fehl.
|
// dieses Servers. Ohne raid_channel-Konfiguration im Bot schlaegt das Erstellen fehl.
|
||||||
'guild_id' => 'deine-discord-server-id',
|
'guild_id' => 'deine-discord-server-id',
|
||||||
],
|
],
|
||||||
|
// Gemeinsamer Schluessel fuer den Rueckkanal vom Bot (bot_api.php): im Bot als
|
||||||
|
// WEBSITE_BOT_KEY in der .env eintragen. Mindestens 16 Zeichen, z.B. zufaellig erzeugt.
|
||||||
|
'bot_callback' => [
|
||||||
|
'key' => 'langer-zufaelliger-schluessel',
|
||||||
|
],
|
||||||
'discord' => [
|
'discord' => [
|
||||||
'client_id' => 'deine-discord-client-id',
|
'client_id' => 'deine-discord-client-id',
|
||||||
'client_secret' => 'dein-discord-client-secret',
|
'client_secret' => 'dein-discord-client-secret',
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/includes/bootstrap.php';
|
require_once __DIR__ . '/includes/bootstrap.php';
|
||||||
require_once __DIR__ . '/includes/contributions.php';
|
require_once __DIR__ . '/includes/contributions.php';
|
||||||
|
require_once __DIR__ . '/includes/raid_attendance.php';
|
||||||
require_permission('contributions.view');
|
require_permission('contributions.view');
|
||||||
|
|
||||||
|
// Automatische Punkte fuer inzwischen archivierte Raids, bevor die Punktestaende angezeigt werden.
|
||||||
|
raid_process_auto_points();
|
||||||
|
|
||||||
$canManage = user_has_permission('contributions.manage');
|
$canManage = user_has_permission('contributions.manage');
|
||||||
$canViewAll = $canManage || user_has_permission('contributions.view_all');
|
$canViewAll = $canManage || user_has_permission('contributions.view_all');
|
||||||
// Der Verlauf ist einstellbar oeffentlich oder nur fuer Leute mit Bearbeitungsrechten.
|
// Der Verlauf ist einstellbar oeffentlich oder nur fuer Leute mit Bearbeitungsrechten.
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/includes/bootstrap.php';
|
require_once __DIR__ . '/includes/bootstrap.php';
|
||||||
require_once __DIR__ . '/includes/contributions.php';
|
require_once __DIR__ . '/includes/contributions.php';
|
||||||
require_once __DIR__ . '/includes/raids_api.php';
|
require_once __DIR__ . '/includes/raid_attendance.php';
|
||||||
require_permission('contributions.manage');
|
require_permission('contributions.manage');
|
||||||
|
|
||||||
$members = db()->query(
|
$members = db()->query(
|
||||||
|
|
@ -27,6 +27,7 @@ $raids = [];
|
||||||
$raidsError = null;
|
$raidsError = null;
|
||||||
try {
|
try {
|
||||||
$apiRaids = fetch_raids('all');
|
$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));
|
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) {
|
foreach (array_slice($apiRaids, 0, 40) as $raid) {
|
||||||
$participants = [];
|
$participants = [];
|
||||||
|
|
@ -46,9 +47,27 @@ try {
|
||||||
$bench[] = $userId;
|
$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);
|
$timestamp = (int) ($raid['timestamp'] ?? 0);
|
||||||
$raids[] = [
|
$raids[] = [
|
||||||
'id' => (int) ($raid['raid_id'] ?? 0),
|
// 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'),
|
'title' => (string) ($raid['title'] ?? 'Raid'),
|
||||||
'date' => $timestamp ? date('d.m.Y H:i', $timestamp) : (string) ($raid['date'] ?? ''),
|
'date' => $timestamp ? date('d.m.Y H:i', $timestamp) : (string) ($raid['date'] ?? ''),
|
||||||
'time' => $timestamp ? date('Y-m-d\TH:i', $timestamp) : '',
|
'time' => $timestamp ? date('Y-m-d\TH:i', $timestamp) : '',
|
||||||
|
|
@ -104,7 +123,7 @@ include __DIR__ . '/includes/header.php';
|
||||||
<select id="raid_id" name="raid_id">
|
<select id="raid_id" name="raid_id">
|
||||||
<option value="">– keinen Raid auswählen –</option>
|
<option value="">– keinen Raid auswählen –</option>
|
||||||
<?php foreach ($raids as $raid): ?>
|
<?php foreach ($raids as $raid): ?>
|
||||||
<option value="<?= (int) $raid['id'] ?>" <?= (string) ($form['raid_id'] ?? '') === (string) $raid['id'] ? 'selected' : '' ?>>
|
<option value="<?= e($raid['id']) ?>" <?= (string) ($form['raid_id'] ?? '') === $raid['id'] ? 'selected' : '' ?>>
|
||||||
<?= e($raid['title']) ?><?= $raid['date'] !== '' ? ' – ' . e($raid['date']) : '' ?>
|
<?= e($raid['title']) ?><?= $raid['date'] !== '' ? ' – ' . e($raid['date']) : '' ?>
|
||||||
</option>
|
</option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
@ -144,6 +163,12 @@ include __DIR__ . '/includes/header.php';
|
||||||
<button type="button" class="button-secondary button-small" id="picker-all">Alle</button>
|
<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>
|
<button type="button" class="button-secondary button-small" id="picker-none">Keine</button>
|
||||||
</div>
|
</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>
|
<p class="field-hint contribution-raid-info" id="raid-info" hidden></p>
|
||||||
<div class="contribution-picker-grid">
|
<div class="contribution-picker-grid">
|
||||||
<?php foreach ($members as $member): ?>
|
<?php foreach ($members as $member): ?>
|
||||||
|
|
|
||||||
290
includes/raid_attendance.php
Normal file
290
includes/raid_attendance.php
Normal file
|
|
@ -0,0 +1,290 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require_once __DIR__ . '/raids_api.php';
|
||||||
|
require_once __DIR__ . '/contributions.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anwesenheit bei Raids und automatische Beitragspunkte beim Archivieren.
|
||||||
|
*
|
||||||
|
* Die Raids selbst liegen beim Bot (Raid-API). Hier auf der Website liegen nur Zusaetze, die
|
||||||
|
* ueber die raid_id (= Discord-Nachrichten-ID) zugeordnet sind: die Punkte-Einstellungen
|
||||||
|
* (raid_settings) und die Anwesenheitsliste (raid_attendance, je Discord-ID).
|
||||||
|
*/
|
||||||
|
|
||||||
|
const RAID_ATTENDANCE_STATUSES = [
|
||||||
|
'present' => 'Anwesend',
|
||||||
|
'absent' => 'Abwesend',
|
||||||
|
'excused' => 'Entschuldigt',
|
||||||
|
];
|
||||||
|
|
||||||
|
/** @return array{points_present: int, points_absent: int, auto_processed_at: ?string, auto_result: ?string, attendance_checked_at: ?string, checked_by: ?string} */
|
||||||
|
function raid_settings_get(int $raidId): array
|
||||||
|
{
|
||||||
|
$stmt = db()->prepare(
|
||||||
|
"SELECT s.points_present, s.points_absent, s.auto_processed_at, s.auto_result, s.attendance_checked_at,
|
||||||
|
COALESCE(NULLIF(u.display_name, ''), u.username) AS checked_by
|
||||||
|
FROM raid_settings s LEFT JOIN users u ON u.id = s.attendance_checked_by
|
||||||
|
WHERE s.raid_id = ?"
|
||||||
|
);
|
||||||
|
$stmt->execute([$raidId]);
|
||||||
|
$row = $stmt->fetch();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'points_present' => (int) ($row['points_present'] ?? 0),
|
||||||
|
'points_absent' => (int) ($row['points_absent'] ?? 0),
|
||||||
|
'auto_processed_at' => $row['auto_processed_at'] ?? null,
|
||||||
|
'auto_result' => $row['auto_result'] ?? null,
|
||||||
|
'attendance_checked_at' => $row['attendance_checked_at'] ?? null,
|
||||||
|
'checked_by' => $row['checked_by'] ?? null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alle Einstellungen auf einmal (fuer die Raid-Uebersicht).
|
||||||
|
*
|
||||||
|
* @return array<string, array<string, mixed>> raid_id => Einstellungen
|
||||||
|
*/
|
||||||
|
function raid_settings_all(): array
|
||||||
|
{
|
||||||
|
$settings = [];
|
||||||
|
foreach (db()->query('SELECT * FROM raid_settings')->fetchAll() as $row) {
|
||||||
|
$settings[(string) $row['raid_id']] = $row;
|
||||||
|
}
|
||||||
|
return $settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
function raid_settings_save_points(int $raidId, int $present, int $absent): void
|
||||||
|
{
|
||||||
|
db()->prepare(
|
||||||
|
'INSERT INTO raid_settings (raid_id, points_present, points_absent) VALUES (?, ?, ?)
|
||||||
|
ON DUPLICATE KEY UPDATE points_present = VALUES(points_present), points_absent = VALUES(points_absent)'
|
||||||
|
)->execute([$raidId, $present, $absent]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Raid-API postet die Discord-Nachricht neu, wenn sie geloescht wurde - dann aendert sich
|
||||||
|
* die raid_id. Einstellungen, Anwesenheit und Vergaben ziehen mit um.
|
||||||
|
*/
|
||||||
|
function raid_rename_id(int $oldId, int $newId): void
|
||||||
|
{
|
||||||
|
if ($oldId === $newId || $newId <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$pdo = db();
|
||||||
|
$pdo->prepare('UPDATE raid_settings SET raid_id = ? WHERE raid_id = ?')->execute([$newId, $oldId]);
|
||||||
|
$pdo->prepare('UPDATE raid_attendance SET raid_id = ? WHERE raid_id = ?')->execute([$newId, $oldId]);
|
||||||
|
$pdo->prepare('UPDATE contribution_awards SET raid_id = ? WHERE raid_id = ?')->execute([$newId, $oldId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anwesenheitsliste eines Raids.
|
||||||
|
*
|
||||||
|
* @return array<string, array{status: string, name: string}> Discord-ID => Eintrag
|
||||||
|
*/
|
||||||
|
function raid_attendance_get(int $raidId): array
|
||||||
|
{
|
||||||
|
$stmt = db()->prepare('SELECT discord_id, name, status FROM raid_attendance WHERE raid_id = ?');
|
||||||
|
$stmt->execute([$raidId]);
|
||||||
|
$list = [];
|
||||||
|
foreach ($stmt->fetchAll() as $row) {
|
||||||
|
$list[(string) $row['discord_id']] = ['status' => (string) $row['status'], 'name' => (string) $row['name']];
|
||||||
|
}
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anmeldungen eines Raids, aufgeteilt: in einer Gruppe, auf der Ersatzbank, abgemeldet.
|
||||||
|
* Ausstehende Premade-Einladungen zaehlen nicht als Anmeldung.
|
||||||
|
*
|
||||||
|
* @return array{groups: array<int, array>, bench: array<int, array>, declined: array<int, array>}
|
||||||
|
*/
|
||||||
|
function raid_signups_split(array $raid): array
|
||||||
|
{
|
||||||
|
$split = ['groups' => [], 'bench' => [], 'declined' => []];
|
||||||
|
foreach ((array) ($raid['signups'] ?? []) as $signup) {
|
||||||
|
$group = (int) ($signup['group'] ?? 0);
|
||||||
|
if ($group < 0) {
|
||||||
|
$split['declined'][] = $signup;
|
||||||
|
} elseif (($signup['class'] ?? '') === 'Ausstehend') {
|
||||||
|
continue;
|
||||||
|
} elseif ($group === 0) {
|
||||||
|
$split['bench'][] = $signup;
|
||||||
|
} else {
|
||||||
|
$split['groups'][] = $signup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $split;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aktive Website-Konten je Discord-ID.
|
||||||
|
*
|
||||||
|
* @return array<string, int> Discord-ID => user_id
|
||||||
|
*/
|
||||||
|
function raid_user_ids_by_discord(): array
|
||||||
|
{
|
||||||
|
$map = [];
|
||||||
|
$rows = db()->query("SELECT id, discord_id FROM users WHERE status = 'active' AND discord_id IS NOT NULL")->fetchAll();
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$map[(string) $row['discord_id']] = (int) $row['id'];
|
||||||
|
}
|
||||||
|
return $map;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Wurden fuer diesen Raid schon Beitragspunkte vergeben (von Hand oder automatisch)? */
|
||||||
|
function raid_has_awards(int $raidId): bool
|
||||||
|
{
|
||||||
|
$stmt = db()->prepare('SELECT 1 FROM contribution_awards WHERE raid_id = ? LIMIT 1');
|
||||||
|
$stmt->execute([$raidId]);
|
||||||
|
return (bool) $stmt->fetchColumn();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatische Beitragspunkte fuer archivierte Raids.
|
||||||
|
*
|
||||||
|
* Laeuft bei jedem Aufruf der Raid- und Punkteseiten und direkt nach dem Archivieren - so
|
||||||
|
* werden auch Raids erfasst, die im Discord ueber den Knopf archiviert wurden (die Website
|
||||||
|
* erfaehrt davon sonst nichts). Kosten: eine Abfrage, solange nichts offen ist.
|
||||||
|
*
|
||||||
|
* - Schon Punkte fuer den Raid vergeben? Dann entfaellt die Automatik.
|
||||||
|
* - Anwesenheitsliste gefuehrt: Anwesende bekommen die Punkte, Abwesende den Abzug.
|
||||||
|
* - Keine Liste: alle, die in einer Gruppe angemeldet waren, bekommen die Punkte (kein Abzug).
|
||||||
|
*
|
||||||
|
* @param array<int, array<string, mixed>>|null $raids Bereits geladene Raids (spart eine API-Abfrage)
|
||||||
|
* @return array<int, string> Meldungen je verarbeitetem Raid
|
||||||
|
*/
|
||||||
|
function raid_process_auto_points(?array $raids = null): array
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$pending = db()->query(
|
||||||
|
'SELECT raid_id, points_present, points_absent FROM raid_settings
|
||||||
|
WHERE auto_processed_at IS NULL AND (points_present > 0 OR points_absent > 0)'
|
||||||
|
)->fetchAll();
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
if (empty($pending)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nur archivierte Raids zaehlen. Sind die mitgegebenen Raids nicht alle dabei, frisch laden.
|
||||||
|
$raidsById = [];
|
||||||
|
foreach ((array) $raids as $raid) {
|
||||||
|
$raidsById[(string) ($raid['raid_id'] ?? '')] = $raid;
|
||||||
|
}
|
||||||
|
$missing = array_filter($pending, static fn (array $p): bool => !isset($raidsById[(string) $p['raid_id']]));
|
||||||
|
if (!empty($missing)) {
|
||||||
|
try {
|
||||||
|
foreach (fetch_raids('all') as $raid) {
|
||||||
|
$raidsById[(string) ($raid['raid_id'] ?? '')] = $raid;
|
||||||
|
}
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
return []; // Raid-API nicht erreichbar - beim naechsten Aufruf erneut
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$messages = [];
|
||||||
|
$userIds = null;
|
||||||
|
foreach ($pending as $setting) {
|
||||||
|
$raidId = (int) $setting['raid_id'];
|
||||||
|
$raid = $raidsById[(string) $raidId] ?? null;
|
||||||
|
if ($raid === null || (empty($raid['archived']) && empty($raid['archived_at']))) {
|
||||||
|
continue; // noch aktiv (oder geloescht) - nichts zu tun
|
||||||
|
}
|
||||||
|
|
||||||
|
$messages[] = raid_run_auto_points($raidId, $raid, (int) $setting['points_present'], (int) $setting['points_absent'], $userIds);
|
||||||
|
}
|
||||||
|
return $messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Vergibt die automatischen Punkte fuer einen archivierten Raid und merkt sich das Ergebnis. */
|
||||||
|
function raid_run_auto_points(int $raidId, array $raid, int $pointsPresent, int $pointsAbsent, ?array &$userIds): string
|
||||||
|
{
|
||||||
|
$pdo = db();
|
||||||
|
$title = (string) ($raid['title'] ?? 'Raid');
|
||||||
|
$timestamp = (int) ($raid['timestamp'] ?? 0);
|
||||||
|
$awardedAt = $timestamp > 0 ? date('Y-m-d H:i:s', $timestamp) : date('Y-m-d H:i:s');
|
||||||
|
|
||||||
|
// Gegen doppelte Vergabe bei gleichzeitigen Seitenaufrufen: Zeile sperren und erneut pruefen.
|
||||||
|
$pdo->beginTransaction();
|
||||||
|
$lock = $pdo->prepare('SELECT auto_processed_at FROM raid_settings WHERE raid_id = ? FOR UPDATE');
|
||||||
|
$lock->execute([$raidId]);
|
||||||
|
if ($lock->fetchColumn() !== null) {
|
||||||
|
$pdo->commit();
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$finish = static function (string $result) use ($pdo, $raidId): string {
|
||||||
|
$pdo->prepare('UPDATE raid_settings SET auto_processed_at = NOW(), auto_result = ? WHERE raid_id = ?')
|
||||||
|
->execute([mb_substr($result, 0, 255), $raidId]);
|
||||||
|
$pdo->commit();
|
||||||
|
return $result;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (raid_has_awards($raidId)) {
|
||||||
|
return $finish('Übersprungen: Für „' . $title . '“ wurden schon vorher Punkte vergeben.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$userIds ??= raid_user_ids_by_discord();
|
||||||
|
$attendance = raid_attendance_get($raidId);
|
||||||
|
$present = [];
|
||||||
|
$absent = [];
|
||||||
|
if (!empty($attendance)) {
|
||||||
|
foreach ($attendance as $discordId => $entry) {
|
||||||
|
$userId = $userIds[$discordId] ?? null;
|
||||||
|
if ($userId === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($entry['status'] === 'present') {
|
||||||
|
$present[] = $userId;
|
||||||
|
} elseif ($entry['status'] === 'absent') {
|
||||||
|
$absent[] = $userId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
foreach (raid_signups_split($raid)['groups'] as $signup) {
|
||||||
|
$userId = $userIds[(string) ($signup['user_id'] ?? '')] ?? null;
|
||||||
|
if ($userId !== null) {
|
||||||
|
$present[] = $userId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$present = array_values(array_unique($present));
|
||||||
|
$absent = array_values(array_unique($absent));
|
||||||
|
|
||||||
|
$insertAward = $pdo->prepare(
|
||||||
|
"INSERT INTO contribution_awards (category, title, note, raid_id, awarded_at, created_by) VALUES ('raid', ?, ?, ?, ?, NULL)"
|
||||||
|
);
|
||||||
|
$insertEntry = $pdo->prepare('INSERT INTO contribution_entries (award_id, user_id, points) VALUES (?, ?, ?)');
|
||||||
|
$parts = [];
|
||||||
|
|
||||||
|
if ($pointsPresent > 0 && !empty($present)) {
|
||||||
|
$insertAward->execute([mb_substr($title, 0, 150), 'Automatisch beim Archivieren' . (empty($attendance) ? ' (ohne Anwesenheitsliste: alle Teilnehmer)' : ''), $raidId, $awardedAt]);
|
||||||
|
$awardId = (int) $pdo->lastInsertId();
|
||||||
|
foreach ($present as $userId) {
|
||||||
|
$insertEntry->execute([$awardId, $userId, $pointsPresent]);
|
||||||
|
}
|
||||||
|
$parts[] = count($present) . '× +' . $pointsPresent;
|
||||||
|
}
|
||||||
|
if ($pointsAbsent > 0 && !empty($absent)) {
|
||||||
|
$insertAward->execute([mb_substr('Abwesend: ' . $title, 0, 150), 'Automatisch beim Archivieren', $raidId, $awardedAt]);
|
||||||
|
$awardId = (int) $pdo->lastInsertId();
|
||||||
|
foreach ($absent as $userId) {
|
||||||
|
$insertEntry->execute([$awardId, $userId, -$pointsAbsent]);
|
||||||
|
}
|
||||||
|
$parts[] = count($absent) . '× −' . $pointsAbsent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $finish(empty($parts)
|
||||||
|
? 'Keine automatischen Punkte für „' . $title . '“: niemand mit Website-Konto zu berücksichtigen.'
|
||||||
|
: 'Automatische Beitragspunkte für „' . $title . '“ vergeben: ' . implode(', ', $parts) . '.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ist fuer den Bot-Rueckkanal ein gemeinsamer Schluessel eingetragen? (config.php: bot_callback.key) */
|
||||||
|
function bot_callback_key(): ?string
|
||||||
|
{
|
||||||
|
$config = require __DIR__ . '/../config.php';
|
||||||
|
$key = (string) ($config['bot_callback']['key'] ?? '');
|
||||||
|
return strlen($key) >= 16 ? $key : null;
|
||||||
|
}
|
||||||
|
|
@ -11,7 +11,7 @@ declare(strict_types=1);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Hochzaehlen, sobald unten eine Aenderung dazukommt - dann pruefen alle Sitzungen neu.
|
// Hochzaehlen, sobald unten eine Aenderung dazukommt - dann pruefen alle Sitzungen neu.
|
||||||
const SCHEMA_VERSION = 5;
|
const SCHEMA_VERSION = 6;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tabellen, die nachtraeglich dazugekommen sind: Tabelle => CREATE-Befehl (wie in sql/schema.sql).
|
* Tabellen, die nachtraeglich dazugekommen sind: Tabelle => CREATE-Befehl (wie in sql/schema.sql).
|
||||||
|
|
@ -65,7 +65,7 @@ CREATE TABLE IF NOT EXISTS contribution_awards (
|
||||||
title VARCHAR(150) NOT NULL,
|
title VARCHAR(150) NOT NULL,
|
||||||
note VARCHAR(255) NULL,
|
note VARCHAR(255) NULL,
|
||||||
-- Raid aus der Raid-API, wenn die Punkte fuer einen Raid vergeben wurden
|
-- Raid aus der Raid-API, wenn die Punkte fuer einen Raid vergeben wurden
|
||||||
raid_id INT UNSIGNED NULL,
|
raid_id BIGINT UNSIGNED NULL,
|
||||||
awarded_at DATETIME NOT NULL,
|
awarded_at DATETIME NOT NULL,
|
||||||
created_by INT UNSIGNED NULL,
|
created_by INT UNSIGNED NULL,
|
||||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
|
@ -85,6 +85,35 @@ CREATE TABLE IF NOT EXISTS contribution_entries (
|
||||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||||
INDEX idx_contribution_entries_user (user_id)
|
INDEX idx_contribution_entries_user (user_id)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
||||||
|
SQL,
|
||||||
|
'raid_settings' => <<<'SQL'
|
||||||
|
CREATE TABLE IF NOT EXISTS raid_settings (
|
||||||
|
-- Discord-Nachrichten-ID des Raids (wie in der Raid-API), 19-stellig
|
||||||
|
raid_id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
|
||||||
|
-- Automatische Beitragspunkte beim Archivieren: fuer Anwesende bzw. Abzug fuer Abwesende
|
||||||
|
points_present INT NOT NULL DEFAULT 0,
|
||||||
|
points_absent INT NOT NULL DEFAULT 0,
|
||||||
|
-- Wann die Automatik gelaufen ist (oder uebersprungen wurde, weil schon Punkte vergeben waren)
|
||||||
|
auto_processed_at DATETIME NULL,
|
||||||
|
auto_result VARCHAR(255) NULL,
|
||||||
|
-- Anwesenheitsliste als kontrolliert bestaetigt
|
||||||
|
attendance_checked_at DATETIME NULL,
|
||||||
|
attendance_checked_by INT UNSIGNED NULL,
|
||||||
|
FOREIGN KEY (attendance_checked_by) REFERENCES users(id) ON DELETE SET NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
||||||
|
SQL,
|
||||||
|
'raid_attendance' => <<<'SQL'
|
||||||
|
CREATE TABLE IF NOT EXISTS raid_attendance (
|
||||||
|
raid_id BIGINT UNSIGNED NOT NULL,
|
||||||
|
-- Discord-ID wie in den Raid-Anmeldungen; zugeordnet zu Website-Konten ueber users.discord_id
|
||||||
|
discord_id BIGINT UNSIGNED NOT NULL,
|
||||||
|
name VARCHAR(100) NOT NULL DEFAULT '',
|
||||||
|
status ENUM('present', 'absent', 'excused') NOT NULL,
|
||||||
|
updated_by INT UNSIGNED NULL,
|
||||||
|
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (raid_id, discord_id),
|
||||||
|
FOREIGN KEY (updated_by) REFERENCES users(id) ON DELETE SET NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
||||||
SQL,
|
SQL,
|
||||||
'settings' => <<<'SQL'
|
'settings' => <<<'SQL'
|
||||||
CREATE TABLE IF NOT EXISTS settings (
|
CREATE TABLE IF NOT EXISTS settings (
|
||||||
|
|
@ -166,6 +195,26 @@ function ensure_schema(): void
|
||||||
$statements[] = "ALTER TABLE users MODIFY status ENUM('active', 'disabled', 'pending') NOT NULL DEFAULT 'active'";
|
$statements[] = "ALTER TABLE users MODIFY status ENUM('active', 'disabled', 'pending') NOT NULL DEFAULT 'active'";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Spalten, deren Typ nachtraeglich korrigiert wurde: [Tabelle, Spalte, erwarteter Typ-Anfang, Befehl].
|
||||||
|
// raid_id sind Discord-Nachrichten-IDs (19-stellig) - ein INT war dafuer zu klein.
|
||||||
|
$typeFixes = [
|
||||||
|
['contribution_awards', 'raid_id', 'bigint', 'ALTER TABLE contribution_awards MODIFY raid_id BIGINT UNSIGNED NULL'],
|
||||||
|
];
|
||||||
|
foreach ($typeFixes as [$table, $column, $expected, $sql]) {
|
||||||
|
if (!in_array($table, $tables, true)) {
|
||||||
|
continue; // Tabelle wird oben frisch (schon richtig) angelegt
|
||||||
|
}
|
||||||
|
$typeStmt = $pdo->prepare(
|
||||||
|
'SELECT LOWER(column_type) FROM information_schema.columns
|
||||||
|
WHERE table_schema = DATABASE() AND table_name = ? AND column_name = ?'
|
||||||
|
);
|
||||||
|
$typeStmt->execute([$table, $column]);
|
||||||
|
$type = (string) $typeStmt->fetchColumn();
|
||||||
|
if ($type !== '' && strpos($type, $expected) !== 0) {
|
||||||
|
$statements[] = $sql;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
foreach ($statements as $sql) {
|
foreach ($statements as $sql) {
|
||||||
$pdo->exec($sql);
|
$pdo->exec($sql);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/includes/bootstrap.php';
|
require_once __DIR__ . '/includes/bootstrap.php';
|
||||||
require_once __DIR__ . '/includes/raids_api.php';
|
require_once __DIR__ . '/includes/raids_api.php';
|
||||||
|
require_once __DIR__ . '/includes/raid_attendance.php';
|
||||||
require_permission('raids.manage');
|
require_permission('raids.manage');
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||||
|
|
@ -22,6 +23,11 @@ if ($raidId <= 0) {
|
||||||
try {
|
try {
|
||||||
archive_raid($raidId);
|
archive_raid($raidId);
|
||||||
set_flash('success', 'Raid wurde archiviert.');
|
set_flash('success', 'Raid wurde archiviert.');
|
||||||
|
foreach (raid_process_auto_points() as $autoMessage) {
|
||||||
|
if ($autoMessage !== '') {
|
||||||
|
set_flash('info', $autoMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
set_flash('error', 'Archivieren fehlgeschlagen: ' . $e->getMessage());
|
set_flash('error', 'Archivieren fehlgeschlagen: ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
186
raid_attendance.php
Normal file
186
raid_attendance.php
Normal file
|
|
@ -0,0 +1,186 @@
|
||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/includes/bootstrap.php';
|
||||||
|
require_once __DIR__ . '/includes/raid_attendance.php';
|
||||||
|
require_permission('raids.manage');
|
||||||
|
|
||||||
|
$raidId = (int) ($_GET['raid'] ?? 0);
|
||||||
|
$raid = null;
|
||||||
|
$apiError = null;
|
||||||
|
try {
|
||||||
|
$raid = $raidId > 0 ? fetch_raid_by_id($raidId) : null;
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
$apiError = $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$raid && !$apiError) {
|
||||||
|
set_flash('error', 'Dieser Raid wurde nicht gefunden.');
|
||||||
|
redirect('/raids.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
$settings = raid_settings_get($raidId);
|
||||||
|
$attendance = raid_attendance_get($raidId);
|
||||||
|
$userIds = raid_user_ids_by_discord();
|
||||||
|
|
||||||
|
// Zeilen der Liste: alle Anmeldungen plus bereits erfasste Personen, die (inzwischen) nicht
|
||||||
|
// mehr angemeldet sind oder von Hand hinzugefuegt wurden.
|
||||||
|
$rows = [];
|
||||||
|
if ($raid) {
|
||||||
|
$split = raid_signups_split($raid);
|
||||||
|
$groupNames = array_values(array_filter(array_map('trim', explode(',', (string) ($raid['groups'] ?? '')))));
|
||||||
|
foreach (['groups' => null, 'bench' => 'Ersatzbank', 'declined' => 'Abgemeldet'] as $key => $label) {
|
||||||
|
foreach ($split[$key] as $signup) {
|
||||||
|
$discordId = (string) ($signup['user_id'] ?? '');
|
||||||
|
if ($discordId === '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$group = (int) ($signup['group'] ?? 0);
|
||||||
|
$rows[$discordId] = [
|
||||||
|
'discord_id' => $discordId,
|
||||||
|
'name' => (string) ($signup['name'] ?? '?'),
|
||||||
|
'class' => (string) ($signup['class'] ?? ''),
|
||||||
|
'where' => $label ?? ($groupNames[$group - 1] ?? 'Gruppe ' . $group),
|
||||||
|
'section' => $key,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($attendance as $discordId => $entry) {
|
||||||
|
if (!isset($rows[$discordId])) {
|
||||||
|
$rows[$discordId] = [
|
||||||
|
'discord_id' => $discordId,
|
||||||
|
'name' => $entry['name'] !== '' ? $entry['name'] : $discordId,
|
||||||
|
'class' => '',
|
||||||
|
'where' => 'Nachgetragen',
|
||||||
|
'section' => 'extra',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zum Nachtragen: Website-Konten mit Discord-Verknuepfung, die noch nicht in der Liste stehen.
|
||||||
|
$addable = db()->query(
|
||||||
|
"SELECT discord_id, COALESCE(NULLIF(display_name, ''), username) AS name FROM users
|
||||||
|
WHERE status = 'active' AND discord_id IS NOT NULL ORDER BY name"
|
||||||
|
)->fetchAll();
|
||||||
|
$addable = array_values(array_filter($addable, static fn (array $u): bool => !isset($rows[(string) $u['discord_id']])));
|
||||||
|
|
||||||
|
$title = $raid ? (string) ($raid['title'] ?? 'Raid') : 'Raid';
|
||||||
|
$timestamp = $raid ? (int) ($raid['timestamp'] ?? 0) : 0;
|
||||||
|
$isArchived = $raid && (!empty($raid['archived']) || !empty($raid['archived_at']));
|
||||||
|
|
||||||
|
$pageTitle = 'Anwesenheit';
|
||||||
|
include __DIR__ . '/includes/header.php';
|
||||||
|
?>
|
||||||
|
<div class="panel">
|
||||||
|
<div class="attendance-head">
|
||||||
|
<div>
|
||||||
|
<h1>Anwesenheit: <?= e($title) ?></h1>
|
||||||
|
<p class="text-muted">
|
||||||
|
<?= $timestamp ? e(date('d.m.Y H:i', $timestamp)) . ' Uhr' : '' ?>
|
||||||
|
<?= $isArchived ? ' · archiviert' : '' ?>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<a href="/raids.php">Zurück zu den Raids</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if ($apiError): ?>
|
||||||
|
<div class="flash flash-error">Die Raid-Daten konnten nicht geladen werden: <?= e($apiError) ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<div class="attendance-status">
|
||||||
|
<?php if ($settings['attendance_checked_at']): ?>
|
||||||
|
<span class="badge badge-active">Kontrolliert</span>
|
||||||
|
am <?= e(date('d.m.Y H:i', strtotime((string) $settings['attendance_checked_at']))) ?>
|
||||||
|
<?= $settings['checked_by'] ? 'von ' . e((string) $settings['checked_by']) : '' ?>
|
||||||
|
<?php else: ?>
|
||||||
|
<span class="badge badge-pending">Noch nicht kontrolliert</span>
|
||||||
|
<?php endif; ?>
|
||||||
|
<span class="text-muted attendance-auto">
|
||||||
|
<?= contribution_coin(16) ?>
|
||||||
|
<?php if ($settings['points_present'] > 0 || $settings['points_absent'] > 0): ?>
|
||||||
|
Beim Archivieren: +<?= (int) $settings['points_present'] ?> für Anwesende<?= $settings['points_absent'] > 0 ? ', −' . (int) $settings['points_absent'] . ' für Abwesende' : '' ?>.
|
||||||
|
<?php if ($settings['auto_result']): ?><br><?= e((string) $settings['auto_result']) ?><?php endif; ?>
|
||||||
|
<?php else: ?>
|
||||||
|
Keine automatischen Beitragspunkte für diesen Raid eingestellt.
|
||||||
|
<?php endif; ?>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form method="post" action="/raid_attendance_action.php" id="attendance-form">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<input type="hidden" name="raid_id" value="<?= $raidId ?>">
|
||||||
|
|
||||||
|
<div class="attendance-bulk">
|
||||||
|
<span class="text-muted">Schnell setzen:</span>
|
||||||
|
<button type="button" class="button-secondary button-small" data-bulk="groups:present">Alle in Gruppen anwesend</button>
|
||||||
|
<button type="button" class="button-secondary button-small" data-bulk="bench:absent">Ersatzbank abwesend</button>
|
||||||
|
<button type="button" class="button-secondary button-small" data-bulk="declined:excused">Abgemeldete entschuldigt</button>
|
||||||
|
<button type="button" class="button-secondary button-small" data-bulk="all:">Alles zurücksetzen</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if (empty($rows)): ?>
|
||||||
|
<p class="text-muted">Für diesen Raid gibt es keine Anmeldungen.</p>
|
||||||
|
<?php else: ?>
|
||||||
|
<div class="attendance-list">
|
||||||
|
<?php foreach ($rows as $row): ?>
|
||||||
|
<?php
|
||||||
|
$current = $attendance[$row['discord_id']]['status'] ?? '';
|
||||||
|
$hasAccount = isset($userIds[$row['discord_id']]);
|
||||||
|
?>
|
||||||
|
<div class="attendance-row" data-section="<?= e($row['section']) ?>">
|
||||||
|
<input type="hidden" name="names[<?= e($row['discord_id']) ?>]" value="<?= e($row['name']) ?>">
|
||||||
|
<div class="attendance-person">
|
||||||
|
<strong><?= e($row['name']) ?></strong>
|
||||||
|
<span class="text-muted"><?= e($row['where']) ?><?= $row['class'] !== '' && $row['class'] !== 'Abgemeldet' ? ' · ' . e($row['class']) : '' ?></span>
|
||||||
|
<?php if (!$hasAccount): ?>
|
||||||
|
<span class="badge" title="Ohne Website-Konto mit Discord-Verknüpfung gibt es keine Beitragspunkte">kein Website-Konto</span>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<div class="attendance-choice" role="radiogroup" aria-label="Anwesenheit von <?= e($row['name']) ?>">
|
||||||
|
<?php foreach (RAID_ATTENDANCE_STATUSES as $value => $label): ?>
|
||||||
|
<label class="attendance-option attendance-<?= e($value) ?>">
|
||||||
|
<input type="radio" name="status[<?= e($row['discord_id']) ?>]" value="<?= e($value) ?>" <?= $current === $value ? 'checked' : '' ?>>
|
||||||
|
<?= e($label) ?>
|
||||||
|
</label>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<label class="attendance-option attendance-none" title="Noch nicht erfasst">
|
||||||
|
<input type="radio" name="status[<?= e($row['discord_id']) ?>]" value="" <?= $current === '' ? 'checked' : '' ?>>
|
||||||
|
–
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if (!empty($addable)): ?>
|
||||||
|
<div class="attendance-add">
|
||||||
|
<label for="attendance-add">Nicht angemeldet, aber dabei gewesen?</label>
|
||||||
|
<select id="attendance-add" name="add_discord_id">
|
||||||
|
<option value="">– Mitglied nachtragen (als anwesend) –</option>
|
||||||
|
<?php foreach ($addable as $user): ?>
|
||||||
|
<option value="<?= e((string) $user['discord_id']) ?>"><?= e((string) $user['name']) ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<div class="actions">
|
||||||
|
<button type="submit" name="mark_checked" value="1">Speichern & als kontrolliert markieren</button>
|
||||||
|
<button type="submit" class="button-secondary">Nur speichern</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.querySelectorAll('[data-bulk]').forEach(function (button) {
|
||||||
|
button.addEventListener('click', function () {
|
||||||
|
var parts = button.getAttribute('data-bulk').split(':');
|
||||||
|
document.querySelectorAll('.attendance-row').forEach(function (row) {
|
||||||
|
if (parts[0] !== 'all' && row.getAttribute('data-section') !== parts[0]) return;
|
||||||
|
var radio = row.querySelector('input[type="radio"][value="' + parts[1] + '"]');
|
||||||
|
if (radio) radio.checked = true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<?php include __DIR__ . '/includes/footer.php'; ?>
|
||||||
67
raid_attendance_action.php
Normal file
67
raid_attendance_action.php
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/includes/bootstrap.php';
|
||||||
|
require_once __DIR__ . '/includes/raid_attendance.php';
|
||||||
|
require_permission('raids.manage');
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||||
|
redirect('/raids.php');
|
||||||
|
}
|
||||||
|
verify_csrf();
|
||||||
|
|
||||||
|
$raidId = (int) ($_POST['raid_id'] ?? 0);
|
||||||
|
if ($raidId <= 0) {
|
||||||
|
redirect('/raids.php');
|
||||||
|
}
|
||||||
|
$userId = (int) current_user()['id'];
|
||||||
|
$statuses = (array) ($_POST['status'] ?? []);
|
||||||
|
$names = (array) ($_POST['names'] ?? []);
|
||||||
|
|
||||||
|
// Nachgetragenes Mitglied kommt als anwesend dazu.
|
||||||
|
$addDiscordId = trim((string) ($_POST['add_discord_id'] ?? ''));
|
||||||
|
if ($addDiscordId !== '' && ctype_digit($addDiscordId)) {
|
||||||
|
$stmt = db()->prepare("SELECT COALESCE(NULLIF(display_name, ''), username) FROM users WHERE discord_id = ?");
|
||||||
|
$stmt->execute([$addDiscordId]);
|
||||||
|
$name = $stmt->fetchColumn();
|
||||||
|
if ($name !== false) {
|
||||||
|
$statuses[$addDiscordId] = 'present';
|
||||||
|
$names[$addDiscordId] = (string) $name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$pdo = db();
|
||||||
|
$pdo->beginTransaction();
|
||||||
|
$upsert = $pdo->prepare(
|
||||||
|
'INSERT INTO raid_attendance (raid_id, discord_id, name, status, updated_by, updated_at) VALUES (?, ?, ?, ?, ?, NOW())
|
||||||
|
ON DUPLICATE KEY UPDATE name = VALUES(name), status = VALUES(status), updated_by = VALUES(updated_by), updated_at = NOW()'
|
||||||
|
);
|
||||||
|
$delete = $pdo->prepare('DELETE FROM raid_attendance WHERE raid_id = ? AND discord_id = ?');
|
||||||
|
$counts = array_fill_keys(array_keys(RAID_ATTENDANCE_STATUSES), 0);
|
||||||
|
|
||||||
|
foreach ($statuses as $discordId => $status) {
|
||||||
|
$discordId = (string) $discordId;
|
||||||
|
if (!ctype_digit($discordId)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$status = (string) $status;
|
||||||
|
if (isset(RAID_ATTENDANCE_STATUSES[$status])) {
|
||||||
|
$upsert->execute([$raidId, $discordId, mb_substr((string) ($names[$discordId] ?? ''), 0, 100), $status, $userId]);
|
||||||
|
$counts[$status]++;
|
||||||
|
} else {
|
||||||
|
$delete->execute([$raidId, $discordId]); // "–" = nicht erfasst
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($_POST['mark_checked'])) {
|
||||||
|
$pdo->prepare(
|
||||||
|
'INSERT INTO raid_settings (raid_id, attendance_checked_at, attendance_checked_by) VALUES (?, NOW(), ?)
|
||||||
|
ON DUPLICATE KEY UPDATE attendance_checked_at = NOW(), attendance_checked_by = VALUES(attendance_checked_by)'
|
||||||
|
)->execute([$raidId, $userId]);
|
||||||
|
}
|
||||||
|
$pdo->commit();
|
||||||
|
|
||||||
|
set_flash('success', sprintf(
|
||||||
|
'Anwesenheit gespeichert: %d anwesend, %d abwesend, %d entschuldigt%s.',
|
||||||
|
$counts['present'], $counts['absent'], $counts['excused'],
|
||||||
|
!empty($_POST['mark_checked']) ? ' - als kontrolliert markiert' : ''
|
||||||
|
));
|
||||||
|
redirect('/raid_attendance.php?raid=' . $raidId);
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/includes/bootstrap.php';
|
require_once __DIR__ . '/includes/bootstrap.php';
|
||||||
require_once __DIR__ . '/includes/raids_api.php';
|
require_once __DIR__ . '/includes/raids_api.php';
|
||||||
|
require_once __DIR__ . '/includes/raid_attendance.php';
|
||||||
require_permission('raids.manage');
|
require_permission('raids.manage');
|
||||||
|
|
||||||
$input = read_json_body();
|
$input = read_json_body();
|
||||||
|
|
@ -12,6 +13,8 @@ $requirements = trim((string) ($input['requirements'] ?? ''));
|
||||||
$groupNames = trim((string) ($input['group_names'] ?? ''));
|
$groupNames = trim((string) ($input['group_names'] ?? ''));
|
||||||
$gearscore = trim((string) ($input['gearscore'] ?? ''));
|
$gearscore = trim((string) ($input['gearscore'] ?? ''));
|
||||||
$maxSlots = isset($input['max_slots']) && is_numeric($input['max_slots']) ? (int) $input['max_slots'] : 12;
|
$maxSlots = isset($input['max_slots']) && is_numeric($input['max_slots']) ? (int) $input['max_slots'] : 12;
|
||||||
|
$pointsPresent = max(0, min(CONTRIBUTION_MAX_POINTS, (int) ($input['points_present'] ?? 0)));
|
||||||
|
$pointsAbsent = max(0, min(CONTRIBUTION_MAX_POINTS, (int) ($input['points_absent'] ?? 0)));
|
||||||
|
|
||||||
if ($title === '' || $dateRaw === '' || $requirements === '' || $groupNames === '') {
|
if ($title === '' || $dateRaw === '' || $requirements === '' || $groupNames === '') {
|
||||||
json_response(false, 'Bitte Titel, Datum, Anforderungen und mindestens eine Gruppe angeben.');
|
json_response(false, 'Bitte Titel, Datum, Anforderungen und mindestens eine Gruppe angeben.');
|
||||||
|
|
@ -26,6 +29,11 @@ try {
|
||||||
'gearscore' => $gearscore,
|
'gearscore' => $gearscore,
|
||||||
'max_slots' => $maxSlots,
|
'max_slots' => $maxSlots,
|
||||||
]);
|
]);
|
||||||
|
$newRaidId = (int) ($result['raid_id'] ?? 0);
|
||||||
|
// Beitragspunkte beim Archivieren kennt die Raid-API nicht - die merkt sich die Website.
|
||||||
|
if ($newRaidId > 0 && ($pointsPresent > 0 || $pointsAbsent > 0)) {
|
||||||
|
raid_settings_save_points($newRaidId, $pointsPresent, $pointsAbsent);
|
||||||
|
}
|
||||||
json_response(true, 'Raid wurde erstellt.', ['raid_id' => $result['raid_id'] ?? null]);
|
json_response(true, 'Raid wurde erstellt.', ['raid_id' => $result['raid_id'] ?? null]);
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
json_response(false, 'Erstellen fehlgeschlagen: ' . $e->getMessage());
|
json_response(false, 'Erstellen fehlgeschlagen: ' . $e->getMessage());
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/includes/bootstrap.php';
|
require_once __DIR__ . '/includes/bootstrap.php';
|
||||||
require_once __DIR__ . '/includes/raids_api.php';
|
require_once __DIR__ . '/includes/raids_api.php';
|
||||||
|
require_once __DIR__ . '/includes/raid_attendance.php';
|
||||||
require_permission('raids.manage');
|
require_permission('raids.manage');
|
||||||
|
|
||||||
$input = read_json_body();
|
$input = read_json_body();
|
||||||
|
|
@ -32,6 +33,16 @@ try {
|
||||||
$result = update_raid($raidId, $fields);
|
$result = update_raid($raidId, $fields);
|
||||||
$newRaidId = (int) ($result['raid_id'] ?? $raidId);
|
$newRaidId = (int) ($result['raid_id'] ?? $raidId);
|
||||||
|
|
||||||
|
// Einstellungen, Anwesenheit und Vergaben haengen an der raid_id - ggf. mit umziehen.
|
||||||
|
raid_rename_id($raidId, $newRaidId);
|
||||||
|
if (isset($input['points_present']) || isset($input['points_absent'])) {
|
||||||
|
raid_settings_save_points(
|
||||||
|
$newRaidId,
|
||||||
|
max(0, min(CONTRIBUTION_MAX_POINTS, (int) ($input['points_present'] ?? 0))),
|
||||||
|
max(0, min(CONTRIBUTION_MAX_POINTS, (int) ($input['points_absent'] ?? 0)))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Die API postet die Discord-Nachricht automatisch neu, falls sie zwischenzeitlich
|
// Die API postet die Discord-Nachricht automatisch neu, falls sie zwischenzeitlich
|
||||||
// manuell geloescht wurde - die raid_id (= Discord-Message-ID) aendert sich dann.
|
// manuell geloescht wurde - die raid_id (= Discord-Message-ID) aendert sich dann.
|
||||||
if ($newRaidId !== $raidId) {
|
if ($newRaidId !== $raidId) {
|
||||||
|
|
|
||||||
55
raids.php
55
raids.php
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/includes/bootstrap.php';
|
require_once __DIR__ . '/includes/bootstrap.php';
|
||||||
require_once __DIR__ . '/includes/raids_api.php';
|
require_once __DIR__ . '/includes/raids_api.php';
|
||||||
|
require_once __DIR__ . '/includes/raid_attendance.php';
|
||||||
require_permission('raids.view');
|
require_permission('raids.view');
|
||||||
|
|
||||||
function render_signup_list(array $members, bool $draggable): void
|
function render_signup_list(array $members, bool $draggable): void
|
||||||
|
|
@ -53,6 +54,18 @@ try {
|
||||||
$apiError = $e->getMessage();
|
$apiError = $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Automatische Beitragspunkte fuer inzwischen archivierte Raids (auch im Discord archivierte).
|
||||||
|
foreach (raid_process_auto_points($apiError ? null : $raids) as $autoMessage) {
|
||||||
|
if ($autoMessage !== '' && $canManageRaids) {
|
||||||
|
set_flash('info', $autoMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$raidSettings = raid_settings_all();
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$raidSettings = [];
|
||||||
|
}
|
||||||
|
|
||||||
$premades = [];
|
$premades = [];
|
||||||
if ($canManageRaids) {
|
if ($canManageRaids) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -117,6 +130,17 @@ include __DIR__ . '/includes/header.php';
|
||||||
<label>Anforderungen</label>
|
<label>Anforderungen</label>
|
||||||
<textarea name="requirements" rows="3" placeholder="Setup / Rollenvorgabe" required></textarea>
|
<textarea name="requirements" rows="3" placeholder="Setup / Rollenvorgabe" required></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="raid-points-fields">
|
||||||
|
<div>
|
||||||
|
<label><?= contribution_coin(16) ?> Punkte für Anwesende beim Archivieren</label>
|
||||||
|
<input type="number" name="points_present" min="0" max="<?= CONTRIBUTION_MAX_POINTS ?>" value="0">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label>Abzug für Abwesende</label>
|
||||||
|
<input type="number" name="points_absent" min="0" max="<?= CONTRIBUTION_MAX_POINTS ?>" value="0">
|
||||||
|
</div>
|
||||||
|
<p class="field-hint">Wird beim Archivieren automatisch vergeben - außer es wurden vorher schon Punkte für den Raid verteilt. Ohne Anwesenheitsliste bekommen alle in den Gruppen die Punkte, einen Abzug gibt es dann nicht. 0 = keine Automatik.</p>
|
||||||
|
</div>
|
||||||
<div class="group-editor" data-locks="0">
|
<div class="group-editor" data-locks="0">
|
||||||
<label>Gruppen</label>
|
<label>Gruppen</label>
|
||||||
<div class="group-editor-rows">
|
<div class="group-editor-rows">
|
||||||
|
|
@ -195,6 +219,11 @@ include __DIR__ . '/includes/header.php';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$raidSetting = $raidSettings[(string) $raidId] ?? null;
|
||||||
|
$autoPresent = (int) ($raidSetting['points_present'] ?? 0);
|
||||||
|
$autoAbsent = (int) ($raidSetting['points_absent'] ?? 0);
|
||||||
|
$raidStarted = !empty($raid['timestamp']) && (int) $raid['timestamp'] <= time();
|
||||||
|
|
||||||
$mySignupGroupNumber = $mySignup ? (int) ($mySignup['group'] ?? 0) : null;
|
$mySignupGroupNumber = $mySignup ? (int) ($mySignup['group'] ?? 0) : null;
|
||||||
$mySignupGroupLabel = $mySignupGroupNumber === 0 ? 'Ersatzbank' : ($mySignupGroupNumber ? ($groupNames[$mySignupGroupNumber - 1] ?? ('#' . $mySignupGroupNumber)) : null);
|
$mySignupGroupLabel = $mySignupGroupNumber === 0 ? 'Ersatzbank' : ($mySignupGroupNumber ? ($groupNames[$mySignupGroupNumber - 1] ?? ('#' . $mySignupGroupNumber)) : null);
|
||||||
?>
|
?>
|
||||||
|
|
@ -242,6 +271,22 @@ include __DIR__ . '/includes/header.php';
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p class="text-muted"><?= e($dateLabel) ?></p>
|
<p class="text-muted"><?= e($dateLabel) ?></p>
|
||||||
|
<?php if ($canManageRaids): ?>
|
||||||
|
<div class="raid-attendance-line">
|
||||||
|
<a class="button button-secondary button-small" href="/raid_attendance.php?raid=<?= $raidId ?>">Anwesenheit</a>
|
||||||
|
<?php if (!empty($raidSetting['attendance_checked_at'])): ?>
|
||||||
|
<span class="badge badge-active">kontrolliert</span>
|
||||||
|
<?php elseif ($raidStarted): ?>
|
||||||
|
<span class="badge badge-pending">noch nicht kontrolliert</span>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ($autoPresent > 0 || $autoAbsent > 0): ?>
|
||||||
|
<span class="text-muted raid-auto-points" title="Automatische Beitragspunkte beim Archivieren">
|
||||||
|
<?= contribution_coin(15) ?> +<?= $autoPresent ?><?= $autoAbsent > 0 ? ' / −' . $autoAbsent : '' ?>
|
||||||
|
<?= !empty($raidSetting['auto_processed_at']) ? '· ' . e((string) $raidSetting['auto_result']) : 'beim Archivieren' ?>
|
||||||
|
</span>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
<?php if ($requirements !== ''): ?>
|
<?php if ($requirements !== ''): ?>
|
||||||
<p class="raid-meta-line"><?= icon('list') ?> <strong>Anforderungen:</strong> <?= e($requirements) ?></p>
|
<p class="raid-meta-line"><?= icon('list') ?> <strong>Anforderungen:</strong> <?= e($requirements) ?></p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
@ -274,6 +319,16 @@ include __DIR__ . '/includes/header.php';
|
||||||
<label>Anforderungen</label>
|
<label>Anforderungen</label>
|
||||||
<textarea name="requirements" rows="3"><?= e($requirements) ?></textarea>
|
<textarea name="requirements" rows="3"><?= e($requirements) ?></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="raid-points-fields">
|
||||||
|
<div>
|
||||||
|
<label><?= contribution_coin(16) ?> Punkte für Anwesende beim Archivieren</label>
|
||||||
|
<input type="number" name="points_present" min="0" max="<?= CONTRIBUTION_MAX_POINTS ?>" value="<?= (int) ($raidSetting['points_present'] ?? 0) ?>">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label>Abzug für Abwesende</label>
|
||||||
|
<input type="number" name="points_absent" min="0" max="<?= CONTRIBUTION_MAX_POINTS ?>" value="<?= (int) ($raidSetting['points_absent'] ?? 0) ?>">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="group-editor">
|
<div class="group-editor">
|
||||||
<label>Gruppen</label>
|
<label>Gruppen</label>
|
||||||
<div class="group-editor-rows">
|
<div class="group-editor-rows">
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,37 @@ CREATE TABLE IF NOT EXISTS user_roles (
|
||||||
FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE CASCADE
|
FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE CASCADE
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- --------------------------------------------------------------------------
|
||||||
|
-- Raids: Einstellungen und Anwesenheit (die Raids selbst liegen beim Bot)
|
||||||
|
-- --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS raid_settings (
|
||||||
|
-- Discord-Nachrichten-ID des Raids (wie in der Raid-API), 19-stellig
|
||||||
|
raid_id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
|
||||||
|
-- Automatische Beitragspunkte beim Archivieren: fuer Anwesende bzw. Abzug fuer Abwesende
|
||||||
|
points_present INT NOT NULL DEFAULT 0,
|
||||||
|
points_absent INT NOT NULL DEFAULT 0,
|
||||||
|
-- Wann die Automatik gelaufen ist (oder uebersprungen wurde, weil schon Punkte vergeben waren)
|
||||||
|
auto_processed_at DATETIME NULL,
|
||||||
|
auto_result VARCHAR(255) NULL,
|
||||||
|
-- Anwesenheitsliste als kontrolliert bestaetigt
|
||||||
|
attendance_checked_at DATETIME NULL,
|
||||||
|
attendance_checked_by INT UNSIGNED NULL,
|
||||||
|
FOREIGN KEY (attendance_checked_by) REFERENCES users(id) ON DELETE SET NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS raid_attendance (
|
||||||
|
raid_id BIGINT UNSIGNED NOT NULL,
|
||||||
|
-- Discord-ID wie in den Raid-Anmeldungen; zugeordnet zu Website-Konten ueber users.discord_id
|
||||||
|
discord_id BIGINT UNSIGNED NOT NULL,
|
||||||
|
name VARCHAR(100) NOT NULL DEFAULT '',
|
||||||
|
status ENUM('present', 'absent', 'excused') NOT NULL,
|
||||||
|
updated_by INT UNSIGNED NULL,
|
||||||
|
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (raid_id, discord_id),
|
||||||
|
FOREIGN KEY (updated_by) REFERENCES users(id) ON DELETE SET NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||||
|
|
||||||
-- --------------------------------------------------------------------------
|
-- --------------------------------------------------------------------------
|
||||||
-- Beitragspunkte
|
-- Beitragspunkte
|
||||||
-- --------------------------------------------------------------------------
|
-- --------------------------------------------------------------------------
|
||||||
|
|
@ -87,7 +118,7 @@ CREATE TABLE IF NOT EXISTS contribution_awards (
|
||||||
title VARCHAR(150) NOT NULL,
|
title VARCHAR(150) NOT NULL,
|
||||||
note VARCHAR(255) NULL,
|
note VARCHAR(255) NULL,
|
||||||
-- Raid aus der Raid-API, wenn die Punkte fuer einen Raid vergeben wurden
|
-- Raid aus der Raid-API, wenn die Punkte fuer einen Raid vergeben wurden
|
||||||
raid_id INT UNSIGNED NULL,
|
raid_id BIGINT UNSIGNED NULL,
|
||||||
awarded_at DATETIME NOT NULL,
|
awarded_at DATETIME NOT NULL,
|
||||||
created_by INT UNSIGNED NULL,
|
created_by INT UNSIGNED NULL,
|
||||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue