Overhaul raid signup/management to match the Discord bot's full feature set
Signup is now a single "Anmelden" button that opens a class-icon
picker + optional group choice. A new raid_wish_is_sensible() mirrors
the bot's exact role-cap algorithm (Tank/Heal 1, DPS 3 per 5-player
group, ROLE_MAPPING copied from teamplaner.py) to decide server-side
whether the requested group is honored or the request falls back to
the bot's own auto-assignment - with a message telling the member to
ping the raid lead if they wanted something specific. Verified the
cap logic with 7 synthetic cases (own-signup exclusion, full group,
role caps, bench always allowed) before wiring it up.
Admins get a per-raid edit-mode toggle (pencil icon) that reveals:
inline raid editing (title/date/requirements/gearscore/groups/slots/
group locks) via PATCH, a premade-invite mini-form via the new
premades endpoint, and native HTML5 drag-and-drop to move a signup
between groups/bench via PATCH .../signup/{user_id}.
New pieces: includes/raids_api.php gained move_signup(), update_raid(),
invite_premade(), fetch_premades(), fetch_raid_by_id() and the wish-
sensibility check; four new JSON action endpoints (raid_signup_action,
raid_move_action, raid_edit_action, raid_premade_invite_action) reusing
the session CSRF token via a new verify_csrf_token()/read_json_body()/
json_response() trio in functions.php; assets/js/raids.js drives the
modal, edit-mode, and drag-and-drop with plain fetch() (no framework).
Read-heavy parts (page render, class icons, signup-wish logic) verified
against real data/live API. Edit, move and premade-invite are NOT
tested against the live API yet since they'd mutate the real raid or
send real Discord DMs to guild members - flagging this for a
supervised live check before considering it fully verified.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
ba8c1bccac
commit
fea0cc3a91
10 changed files with 876 additions and 56 deletions
|
|
@ -577,3 +577,143 @@ input:focus, select:focus, textarea:focus {
|
||||||
|
|
||||||
.sidebar-user { display: none; }
|
.sidebar-user { display: none; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --- Raid-Verwaltung: Icon-Buttons, Editor-Modus, Modal, Drag & Drop --- */
|
||||||
|
|
||||||
|
.icon-button {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
padding: 0;
|
||||||
|
background: var(--bg-panel-alt);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 6px;
|
||||||
|
color: var(--text-muted);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-button:hover { color: var(--gold); border-color: var(--gold); }
|
||||||
|
|
||||||
|
.raid-card.editing .raid-edit-toggle { color: var(--gold); border-color: var(--gold); }
|
||||||
|
|
||||||
|
.raid-edit-panel {
|
||||||
|
display: none;
|
||||||
|
margin-top: 1rem;
|
||||||
|
padding: 1rem;
|
||||||
|
background: var(--bg-panel-alt);
|
||||||
|
border: 1px dashed var(--border);
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.raid-card.editing .raid-edit-panel { display: block; }
|
||||||
|
|
||||||
|
.raid-edit-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
||||||
|
gap: 0.75rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.raid-edit-form .actions { align-items: center; }
|
||||||
|
|
||||||
|
.raid-premade-form {
|
||||||
|
margin-top: 1rem;
|
||||||
|
padding-top: 1rem;
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.raid-premade-row {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.5rem;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.raid-premade-row select { width: auto; }
|
||||||
|
|
||||||
|
.raid-empty-hint { margin: 0; }
|
||||||
|
|
||||||
|
/* Drag & Drop nur optisch aktiv, wenn die Karte im Editor-Modus ist */
|
||||||
|
.raid-card.editing .raid-signup-item { cursor: grab; }
|
||||||
|
.raid-signup-item.dragging { opacity: 0.4; }
|
||||||
|
|
||||||
|
.raid-drop-zone { transition: background 0.15s ease, border-color 0.15s ease; }
|
||||||
|
.raid-card.editing .raid-drop-zone.drag-over {
|
||||||
|
background: rgba(201, 162, 39, 0.15);
|
||||||
|
border-color: var(--gold);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --- Anmelde-Popup --- */
|
||||||
|
|
||||||
|
.modal-overlay {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
background: rgba(0, 0, 0, 0.65);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 1000;
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
max-width: 480px;
|
||||||
|
max-height: 90vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
background: var(--bg-panel);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 2rem;
|
||||||
|
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal .modal-close {
|
||||||
|
position: absolute;
|
||||||
|
top: 1rem;
|
||||||
|
right: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.class-picker {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
|
||||||
|
gap: 0.6rem;
|
||||||
|
margin: 1.25rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.class-picker-option {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.4rem;
|
||||||
|
padding: 0.75rem 0.5rem;
|
||||||
|
background: var(--bg-panel-alt);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 8px;
|
||||||
|
color: var(--text);
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.class-picker-option img { width: 32px; height: 32px; }
|
||||||
|
|
||||||
|
.class-picker-option:hover { border-color: var(--gold); }
|
||||||
|
|
||||||
|
.class-picker-option.selected {
|
||||||
|
border-color: var(--gold);
|
||||||
|
background: rgba(201, 162, 39, 0.15);
|
||||||
|
color: var(--gold);
|
||||||
|
}
|
||||||
|
|
||||||
|
.raid-modal-feedback {
|
||||||
|
min-height: 1.2rem;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.raid-modal-feedback.success { color: var(--success); }
|
||||||
|
.raid-modal-feedback.error { color: var(--danger); }
|
||||||
|
|
|
||||||
235
assets/js/raids.js
Normal file
235
assets/js/raids.js
Normal file
|
|
@ -0,0 +1,235 @@
|
||||||
|
(function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var csrfToken = (document.querySelector('meta[name="csrf-token"]') || {}).content || '';
|
||||||
|
|
||||||
|
function postJson(url, data) {
|
||||||
|
data.csrf_token = csrfToken;
|
||||||
|
return fetch(url, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(data)
|
||||||
|
}).then(function (response) {
|
||||||
|
return response.json();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Anmelde-Popup ----
|
||||||
|
var modal = document.getElementById('raid-signup-modal');
|
||||||
|
var groupSelect = document.getElementById('raid-signup-group');
|
||||||
|
var feedbackEl = document.getElementById('raid-signup-feedback');
|
||||||
|
var confirmBtn = document.getElementById('raid-signup-confirm');
|
||||||
|
var currentRaidId = null;
|
||||||
|
var selectedClass = null;
|
||||||
|
|
||||||
|
function openSignupModal(card) {
|
||||||
|
if (!modal) return;
|
||||||
|
currentRaidId = card.getAttribute('data-raid-id');
|
||||||
|
selectedClass = card.getAttribute('data-my-class') || null;
|
||||||
|
|
||||||
|
var groups = [];
|
||||||
|
try {
|
||||||
|
groups = JSON.parse(card.getAttribute('data-groups') || '[]');
|
||||||
|
} catch (e) {
|
||||||
|
groups = [];
|
||||||
|
}
|
||||||
|
var myGroup = card.getAttribute('data-my-group') || '';
|
||||||
|
|
||||||
|
groupSelect.innerHTML = '<option value="">Automatisch zuteilen</option>';
|
||||||
|
groups.forEach(function (name, index) {
|
||||||
|
var opt = document.createElement('option');
|
||||||
|
opt.value = String(index + 1);
|
||||||
|
opt.textContent = name;
|
||||||
|
if (String(index + 1) === myGroup) opt.selected = true;
|
||||||
|
groupSelect.appendChild(opt);
|
||||||
|
});
|
||||||
|
var benchOpt = document.createElement('option');
|
||||||
|
benchOpt.value = '0';
|
||||||
|
benchOpt.textContent = 'Ersatzbank';
|
||||||
|
if (myGroup === '0') benchOpt.selected = true;
|
||||||
|
groupSelect.appendChild(benchOpt);
|
||||||
|
|
||||||
|
modal.querySelectorAll('.class-picker-option').forEach(function (btn) {
|
||||||
|
btn.classList.toggle('selected', btn.getAttribute('data-class') === selectedClass);
|
||||||
|
});
|
||||||
|
|
||||||
|
feedbackEl.textContent = '';
|
||||||
|
feedbackEl.className = 'raid-modal-feedback';
|
||||||
|
modal.hidden = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeSignupModal() {
|
||||||
|
if (modal) modal.hidden = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.querySelectorAll('.raid-open-signup').forEach(function (btn) {
|
||||||
|
btn.addEventListener('click', function () {
|
||||||
|
var card = btn.closest('.raid-card');
|
||||||
|
if (card) openSignupModal(card);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (modal) {
|
||||||
|
modal.querySelector('.modal-close').addEventListener('click', closeSignupModal);
|
||||||
|
modal.addEventListener('click', function (e) {
|
||||||
|
if (e.target === modal) closeSignupModal();
|
||||||
|
});
|
||||||
|
|
||||||
|
modal.querySelectorAll('.class-picker-option').forEach(function (btn) {
|
||||||
|
btn.addEventListener('click', function () {
|
||||||
|
selectedClass = btn.getAttribute('data-class');
|
||||||
|
modal.querySelectorAll('.class-picker-option').forEach(function (b) {
|
||||||
|
b.classList.toggle('selected', b === btn);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
confirmBtn.addEventListener('click', function () {
|
||||||
|
if (!selectedClass) {
|
||||||
|
feedbackEl.textContent = 'Bitte zuerst eine Klasse auswählen.';
|
||||||
|
feedbackEl.className = 'raid-modal-feedback error';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
confirmBtn.disabled = true;
|
||||||
|
feedbackEl.textContent = 'Wird gesendet …';
|
||||||
|
feedbackEl.className = 'raid-modal-feedback';
|
||||||
|
|
||||||
|
postJson('/raid_signup_action.php', {
|
||||||
|
raid_id: currentRaidId,
|
||||||
|
class: selectedClass,
|
||||||
|
group: groupSelect.value === '' ? null : parseInt(groupSelect.value, 10)
|
||||||
|
}).then(function (result) {
|
||||||
|
feedbackEl.textContent = result.message || '';
|
||||||
|
feedbackEl.className = 'raid-modal-feedback ' + (result.status === 'success' ? 'success' : 'error');
|
||||||
|
if (result.status === 'success') {
|
||||||
|
setTimeout(function () { window.location.reload(); }, 1400);
|
||||||
|
} else {
|
||||||
|
confirmBtn.disabled = false;
|
||||||
|
}
|
||||||
|
}).catch(function () {
|
||||||
|
feedbackEl.textContent = 'Verbindung fehlgeschlagen. Bitte erneut versuchen.';
|
||||||
|
feedbackEl.className = 'raid-modal-feedback error';
|
||||||
|
confirmBtn.disabled = false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Editor-Modus ----
|
||||||
|
document.querySelectorAll('.raid-edit-toggle').forEach(function (btn) {
|
||||||
|
btn.addEventListener('click', function () {
|
||||||
|
var card = btn.closest('.raid-card');
|
||||||
|
if (card) card.classList.toggle('editing');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ---- Raid bearbeiten (Formular) ----
|
||||||
|
document.querySelectorAll('.raid-edit-form').forEach(function (form) {
|
||||||
|
form.addEventListener('submit', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var feedback = form.querySelector('.raid-edit-feedback');
|
||||||
|
var lockedGroups = Array.prototype.slice.call(form.querySelectorAll('input[name="locked_groups[]"]:checked'))
|
||||||
|
.map(function (cb) { return parseInt(cb.value, 10); });
|
||||||
|
|
||||||
|
feedback.textContent = 'Wird gespeichert …';
|
||||||
|
postJson('/raid_edit_action.php', {
|
||||||
|
raid_id: form.getAttribute('data-raid-id'),
|
||||||
|
title: form.title.value,
|
||||||
|
date_raw: form.date_raw.value,
|
||||||
|
requirements: form.requirements.value,
|
||||||
|
gearscore: form.gearscore.value,
|
||||||
|
group_names: form.group_names.value,
|
||||||
|
max_slots: form.max_slots.value,
|
||||||
|
locked_groups: lockedGroups
|
||||||
|
}).then(function (result) {
|
||||||
|
feedback.textContent = result.message || '';
|
||||||
|
if (result.status === 'success') {
|
||||||
|
setTimeout(function () { window.location.reload(); }, 900);
|
||||||
|
}
|
||||||
|
}).catch(function () {
|
||||||
|
feedback.textContent = 'Verbindung fehlgeschlagen.';
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ---- Premade einladen ----
|
||||||
|
document.querySelectorAll('.raid-premade-form').forEach(function (form) {
|
||||||
|
form.addEventListener('submit', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var feedback = form.querySelector('.raid-premade-feedback');
|
||||||
|
feedback.textContent = 'Wird eingeladen …';
|
||||||
|
|
||||||
|
postJson('/raid_premade_invite_action.php', {
|
||||||
|
raid_id: form.getAttribute('data-raid-id'),
|
||||||
|
premade_id: form.premade_id.value,
|
||||||
|
group: form.group.value
|
||||||
|
}).then(function (result) {
|
||||||
|
feedback.textContent = result.message || '';
|
||||||
|
if (result.status === 'success') {
|
||||||
|
setTimeout(function () { window.location.reload(); }, 1200);
|
||||||
|
}
|
||||||
|
}).catch(function () {
|
||||||
|
feedback.textContent = 'Verbindung fehlgeschlagen.';
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ---- Drag & Drop (nur im Editor-Modus) ----
|
||||||
|
document.querySelectorAll('.raid-signup-item').forEach(function (item) {
|
||||||
|
item.addEventListener('dragstart', function (e) {
|
||||||
|
var card = item.closest('.raid-card');
|
||||||
|
if (!card || !card.classList.contains('editing')) {
|
||||||
|
e.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
e.dataTransfer.setData('text/plain', JSON.stringify({
|
||||||
|
raidId: card.getAttribute('data-raid-id'),
|
||||||
|
userId: item.getAttribute('data-user-id')
|
||||||
|
}));
|
||||||
|
item.classList.add('dragging');
|
||||||
|
});
|
||||||
|
item.addEventListener('dragend', function () {
|
||||||
|
item.classList.remove('dragging');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelectorAll('.raid-drop-zone').forEach(function (zone) {
|
||||||
|
zone.addEventListener('dragover', function (e) {
|
||||||
|
var card = zone.closest('.raid-card');
|
||||||
|
if (!card || !card.classList.contains('editing')) return;
|
||||||
|
e.preventDefault();
|
||||||
|
zone.classList.add('drag-over');
|
||||||
|
});
|
||||||
|
zone.addEventListener('dragleave', function () {
|
||||||
|
zone.classList.remove('drag-over');
|
||||||
|
});
|
||||||
|
zone.addEventListener('drop', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
zone.classList.remove('drag-over');
|
||||||
|
var card = zone.closest('.raid-card');
|
||||||
|
if (!card || !card.classList.contains('editing')) return;
|
||||||
|
|
||||||
|
var raw = e.dataTransfer.getData('text/plain');
|
||||||
|
if (!raw) return;
|
||||||
|
var payload;
|
||||||
|
try {
|
||||||
|
payload = JSON.parse(raw);
|
||||||
|
} catch (err) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
postJson('/raid_move_action.php', {
|
||||||
|
raid_id: payload.raidId,
|
||||||
|
user_id: payload.userId,
|
||||||
|
group: zone.getAttribute('data-group')
|
||||||
|
}).then(function (result) {
|
||||||
|
if (result.status === 'success') {
|
||||||
|
window.location.reload();
|
||||||
|
} else {
|
||||||
|
alert(result.message || 'Verschieben fehlgeschlagen.');
|
||||||
|
}
|
||||||
|
}).catch(function () {
|
||||||
|
alert('Verbindung fehlgeschlagen.');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
|
@ -27,13 +27,52 @@ function csrf_field(): string
|
||||||
|
|
||||||
function verify_csrf(): void
|
function verify_csrf(): void
|
||||||
{
|
{
|
||||||
$token = $_POST['csrf_token'] ?? '';
|
verify_csrf_token($_POST['csrf_token'] ?? '');
|
||||||
if (!is_string($token) || !hash_equals($_SESSION['csrf_token'] ?? '', $token)) {
|
}
|
||||||
|
|
||||||
|
// Fuer JSON-Endpunkte (fetch()), die kein normales $_POST haben.
|
||||||
|
function verify_csrf_token($token): void
|
||||||
|
{
|
||||||
|
if (!is_string($token) || $token === '' || !hash_equals($_SESSION['csrf_token'] ?? '', $token)) {
|
||||||
http_response_code(400);
|
http_response_code(400);
|
||||||
exit('Ungültige Anfrage (CSRF-Token fehlt oder ist abgelaufen). Bitte Seite neu laden und erneut versuchen.');
|
exit('Ungültige Anfrage (CSRF-Token fehlt oder ist abgelaufen). Bitte Seite neu laden und erneut versuchen.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liest einen JSON-Request-Body (fuer fetch()-Endpunkte). Bricht mit 400 ab,
|
||||||
|
* wenn der Body kein gueltiges JSON-Objekt ist.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
function read_json_body(): array
|
||||||
|
{
|
||||||
|
$raw = file_get_contents('php://input');
|
||||||
|
$data = json_decode((string) $raw, true);
|
||||||
|
if (!is_array($data)) {
|
||||||
|
http_response_code(400);
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'Ungültiger Request-Body.']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Beendet einen JSON-Endpunkt mit einer Erfolgs- oder Fehlerantwort.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $extra Zusaetzliche Felder fuer die JSON-Antwort.
|
||||||
|
*/
|
||||||
|
function json_response(bool $success, string $message = '', array $extra = []): void
|
||||||
|
{
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo json_encode(array_merge([
|
||||||
|
'status' => $success ? 'success' : 'error',
|
||||||
|
'message' => $message,
|
||||||
|
], $extra), JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
function set_flash(string $type, string $message): void
|
function set_flash(string $type, string $message): void
|
||||||
{
|
{
|
||||||
$_SESSION['flash'][] = ['type' => $type, 'message' => $message];
|
$_SESSION['flash'][] = ['type' => $type, 'message' => $message];
|
||||||
|
|
@ -73,6 +112,9 @@ function icon(string $name): string
|
||||||
'profile' => '<circle cx="12" cy="8" r="4"/><path d="M4.5 20c0-4 3.5-6.5 7.5-6.5s7.5 2.5 7.5 6.5"/>',
|
'profile' => '<circle cx="12" cy="8" r="4"/><path d="M4.5 20c0-4 3.5-6.5 7.5-6.5s7.5 2.5 7.5 6.5"/>',
|
||||||
'link' => '<path d="M9 17H7a5 5 0 0 1 0-10h2"/><path d="M15 7h2a5 5 0 0 1 0 10h-2"/><line x1="8" y1="12" x2="16" y2="12"/>',
|
'link' => '<path d="M9 17H7a5 5 0 0 1 0-10h2"/><path d="M15 7h2a5 5 0 0 1 0 10h-2"/><line x1="8" y1="12" x2="16" y2="12"/>',
|
||||||
'list' => '<line x1="9" y1="6" x2="20" y2="6"/><line x1="9" y1="12" x2="20" y2="12"/><line x1="9" y1="18" x2="20" y2="18"/><circle cx="4.5" cy="6" r="1"/><circle cx="4.5" cy="12" r="1"/><circle cx="4.5" cy="18" r="1"/>',
|
'list' => '<line x1="9" y1="6" x2="20" y2="6"/><line x1="9" y1="12" x2="20" y2="12"/><line x1="9" y1="18" x2="20" y2="18"/><circle cx="4.5" cy="6" r="1"/><circle cx="4.5" cy="12" r="1"/><circle cx="4.5" cy="18" r="1"/>',
|
||||||
|
'edit' => '<path d="M12 20h9"/><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z"/>',
|
||||||
|
'x' => '<line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/>',
|
||||||
|
'move' => '<polyline points="5 9 2 12 5 15"/><polyline points="9 5 12 2 15 5"/><polyline points="15 19 12 22 9 19"/><polyline points="19 9 22 12 19 15"/><line x1="2" y1="12" x2="22" y2="12"/><line x1="12" y1="2" x2="12" y2="22"/>',
|
||||||
];
|
];
|
||||||
|
|
||||||
$path = $paths[$name] ?? '';
|
$path = $paths[$name] ?? '';
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ $pageBackgroundClass = $pageBackgrounds[$currentScript] ?? '';
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<meta name="csrf-token" content="<?= e(csrf_token()) ?>">
|
||||||
<title><?= e(($pageTitle ?? '') !== '' ? $pageTitle . ' - Aion2 Gilde' : 'Aion2 Gilde') ?></title>
|
<title><?= e(($pageTitle ?? '') !== '' ? $pageTitle . ' - Aion2 Gilde' : 'Aion2 Gilde') ?></title>
|
||||||
<link rel="stylesheet" href="/assets/css/style.css">
|
<link rel="stylesheet" href="/assets/css/style.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
|
||||||
|
|
@ -122,15 +122,22 @@ function restore_raid(int $raidId): void
|
||||||
raids_api_request('POST', '/' . $raidId . '/restore');
|
raids_api_request('POST', '/' . $raidId . '/restore');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @throws RuntimeException */
|
/**
|
||||||
function raid_signup(int $raidId, int $discordId, string $discordName, string $className, int $group): void
|
* @param int|null $group Feste Zielgruppe (0 = Ersatzbank) oder null, damit der Bot
|
||||||
|
* automatisch nach Rollen-Caps zuteilt.
|
||||||
|
* @return array<string, mixed> Die von der API zugewiesene Anmeldung (u.a. tatsaechliche "group").
|
||||||
|
* @throws RuntimeException
|
||||||
|
*/
|
||||||
|
function raid_signup(int $raidId, int $discordId, string $discordName, string $className, ?int $group): array
|
||||||
{
|
{
|
||||||
raids_api_request('POST', '/' . $raidId . '/signup', [], [
|
$data = raids_api_request('POST', '/' . $raidId . '/signup', [], [
|
||||||
'user_id' => $discordId,
|
'user_id' => $discordId,
|
||||||
'name' => $discordName,
|
'name' => $discordName,
|
||||||
'class' => $className,
|
'class' => $className,
|
||||||
'group' => $group,
|
'group' => $group,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
return $data['signup'] ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @throws RuntimeException */
|
/** @throws RuntimeException */
|
||||||
|
|
@ -138,3 +145,138 @@ function raid_unsignup(int $raidId, int $discordId): void
|
||||||
{
|
{
|
||||||
raids_api_request('DELETE', '/' . $raidId . '/signup/' . $discordId);
|
raids_api_request('DELETE', '/' . $raidId . '/signup/' . $discordId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @throws RuntimeException */
|
||||||
|
function move_signup(int $raidId, int $discordId, int $group): void
|
||||||
|
{
|
||||||
|
raids_api_request('PATCH', '/' . $raidId . '/signup/' . $discordId, [], ['group' => $group]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $fields Nur die zu aendernden Felder, z.B.
|
||||||
|
* ['title' => ..., 'date_raw' => ..., 'requirements' => ..., 'gearscore' => ...,
|
||||||
|
* 'group_names' => ..., 'max_slots' => ..., 'locked_groups' => [1, 3]]
|
||||||
|
* @throws RuntimeException
|
||||||
|
*/
|
||||||
|
function update_raid(int $raidId, array $fields): void
|
||||||
|
{
|
||||||
|
raids_api_request('PATCH', '/' . $raidId, [], $fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @throws RuntimeException */
|
||||||
|
function invite_premade(int $raidId, int $premadeId, int $group): int
|
||||||
|
{
|
||||||
|
$data = raids_api_request('POST', '/' . $raidId . '/premades/' . $premadeId . '/invite', [], ['group' => $group]);
|
||||||
|
|
||||||
|
return (int) ($data['invited_count'] ?? 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, array<string, mixed>>
|
||||||
|
* @throws RuntimeException
|
||||||
|
*/
|
||||||
|
function fetch_premades(): array
|
||||||
|
{
|
||||||
|
$configPath = __DIR__ . '/../config.php';
|
||||||
|
if (!file_exists($configPath)) {
|
||||||
|
throw new RuntimeException('Konfigurationsdatei fehlt.');
|
||||||
|
}
|
||||||
|
$config = require $configPath;
|
||||||
|
$apiUrl = $config['raids_api']['url'] ?? '';
|
||||||
|
$apiKey = $config['raids_api']['key'] ?? '';
|
||||||
|
if ($apiUrl === '' || $apiKey === '') {
|
||||||
|
throw new RuntimeException('Raid-API ist nicht konfiguriert.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// /api/premades liegt eine Ebene ueber /api/raids.
|
||||||
|
$base = preg_replace('#/raids$#', '', rtrim($apiUrl, '/'));
|
||||||
|
|
||||||
|
$ch = curl_init($base . '/premades');
|
||||||
|
curl_setopt_array($ch, [
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_HTTPHEADER => ['X-API-Key: ' . $apiKey],
|
||||||
|
CURLOPT_TIMEOUT => 10,
|
||||||
|
CURLOPT_SSL_VERIFYPEER => true,
|
||||||
|
]);
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
if ($response === false || $httpCode !== 200) {
|
||||||
|
throw new RuntimeException('Premades konnten nicht geladen werden.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = json_decode($response, true);
|
||||||
|
if (!is_array($data) || ($data['status'] ?? '') !== 'success' || !is_array($data['premades'] ?? null)) {
|
||||||
|
throw new RuntimeException('Unerwartetes Antwortformat der Premades-API.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data['premades'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sucht einen einzelnen Raid (inkl. aktueller Signups) anhand seiner ID.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>|null
|
||||||
|
* @throws RuntimeException
|
||||||
|
*/
|
||||||
|
function fetch_raid_by_id(int $raidId): ?array
|
||||||
|
{
|
||||||
|
foreach (fetch_raids('all') as $raid) {
|
||||||
|
if ((int) ($raid['raid_id'] ?? 0) === $raidId) {
|
||||||
|
return $raid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rollen-Zuordnung 1:1 aus ROLE_MAPPING in teamplaner.py uebernommen.
|
||||||
|
const RAID_ROLE_MAPPING = [
|
||||||
|
'Templer' => 'Tank',
|
||||||
|
'Kleriker' => 'Heal',
|
||||||
|
'Kantor' => 'Heal',
|
||||||
|
'Gladiator' => 'DPS',
|
||||||
|
'Assassine' => 'DPS',
|
||||||
|
'Jäger' => 'DPS',
|
||||||
|
'Magier' => 'DPS',
|
||||||
|
'Beschwörer' => 'DPS',
|
||||||
|
];
|
||||||
|
const RAID_GROUP_SIZE = 5;
|
||||||
|
const RAID_ROLE_CAPS = ['Tank' => 1, 'Heal' => 1, 'DPS' => 3];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prueft, ob eine gewuenschte Gruppe fuer eine Klasse nach den gleichen Rollen-Caps
|
||||||
|
* Sinn ergeben wuerde wie der Smart-Sort-Algorithmus des Bots (Tank/Heal je max. 1,
|
||||||
|
* DPS max. 3 pro 5er-Gruppe). Die Ersatzbank (Gruppe 0) ist immer erlaubt.
|
||||||
|
*
|
||||||
|
* @param array<int, array<string, mixed>> $signups Aktuelle Anmeldungen des Raids.
|
||||||
|
*/
|
||||||
|
function raid_wish_is_sensible(array $signups, int $discordId, string $className, int $desiredGroup): bool
|
||||||
|
{
|
||||||
|
if ($desiredGroup <= 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$role = RAID_ROLE_MAPPING[$className] ?? 'DPS';
|
||||||
|
$counts = ['Tank' => 0, 'Heal' => 0, 'DPS' => 0];
|
||||||
|
$total = 0;
|
||||||
|
|
||||||
|
foreach ($signups as $signup) {
|
||||||
|
if ((int) ($signup['user_id'] ?? 0) === $discordId) {
|
||||||
|
continue; // eigene bestehende Anmeldung nicht mitzaehlen
|
||||||
|
}
|
||||||
|
if ((int) ($signup['group'] ?? 0) !== $desiredGroup) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$memberRole = RAID_ROLE_MAPPING[$signup['class'] ?? ''] ?? 'DPS';
|
||||||
|
$counts[$memberRole]++;
|
||||||
|
$total++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($total >= RAID_GROUP_SIZE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $counts[$role] < RAID_ROLE_CAPS[$role];
|
||||||
|
}
|
||||||
|
|
|
||||||
36
raid_edit_action.php
Normal file
36
raid_edit_action.php
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/includes/bootstrap.php';
|
||||||
|
require_once __DIR__ . '/includes/raids_api.php';
|
||||||
|
require_permission('raids.manage');
|
||||||
|
|
||||||
|
$input = read_json_body();
|
||||||
|
verify_csrf_token($input['csrf_token'] ?? '');
|
||||||
|
|
||||||
|
$raidId = (int) ($input['raid_id'] ?? 0);
|
||||||
|
if ($raidId <= 0) {
|
||||||
|
json_response(false, 'Ungültige Anfrage.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$fields = [];
|
||||||
|
foreach (['title', 'date_raw', 'requirements', 'gearscore', 'group_names'] as $key) {
|
||||||
|
if (isset($input[$key]) && trim((string) $input[$key]) !== '') {
|
||||||
|
$fields[$key] = trim((string) $input[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isset($input['max_slots']) && is_numeric($input['max_slots'])) {
|
||||||
|
$fields['max_slots'] = (int) $input['max_slots'];
|
||||||
|
}
|
||||||
|
if (isset($input['locked_groups']) && is_array($input['locked_groups'])) {
|
||||||
|
$fields['locked_groups'] = array_values(array_map('intval', $input['locked_groups']));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($fields)) {
|
||||||
|
json_response(false, 'Keine Änderungen übermittelt.');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
update_raid($raidId, $fields);
|
||||||
|
json_response(true, 'Raid wurde aktualisiert.');
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
json_response(false, 'Speichern fehlgeschlagen: ' . $e->getMessage());
|
||||||
|
}
|
||||||
22
raid_move_action.php
Normal file
22
raid_move_action.php
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/includes/bootstrap.php';
|
||||||
|
require_once __DIR__ . '/includes/raids_api.php';
|
||||||
|
require_permission('raids.manage');
|
||||||
|
|
||||||
|
$input = read_json_body();
|
||||||
|
verify_csrf_token($input['csrf_token'] ?? '');
|
||||||
|
|
||||||
|
$raidId = (int) ($input['raid_id'] ?? 0);
|
||||||
|
$discordId = (int) ($input['user_id'] ?? 0);
|
||||||
|
$group = $input['group'] ?? null;
|
||||||
|
|
||||||
|
if ($raidId <= 0 || $discordId <= 0 || !is_numeric($group) || (int) $group < 0) {
|
||||||
|
json_response(false, 'Ungültige Anfrage.');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
move_signup($raidId, $discordId, (int) $group);
|
||||||
|
json_response(true, 'Spieler wurde verschoben.');
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
json_response(false, 'Verschieben fehlgeschlagen: ' . $e->getMessage());
|
||||||
|
}
|
||||||
22
raid_premade_invite_action.php
Normal file
22
raid_premade_invite_action.php
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/includes/bootstrap.php';
|
||||||
|
require_once __DIR__ . '/includes/raids_api.php';
|
||||||
|
require_permission('raids.manage');
|
||||||
|
|
||||||
|
$input = read_json_body();
|
||||||
|
verify_csrf_token($input['csrf_token'] ?? '');
|
||||||
|
|
||||||
|
$raidId = (int) ($input['raid_id'] ?? 0);
|
||||||
|
$premadeId = (int) ($input['premade_id'] ?? 0);
|
||||||
|
$group = (int) ($input['group'] ?? 0);
|
||||||
|
|
||||||
|
if ($raidId <= 0 || $premadeId <= 0 || $group <= 0) {
|
||||||
|
json_response(false, 'Bitte Premade und Zielgruppe auswählen.');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$count = invite_premade($raidId, $premadeId, $group);
|
||||||
|
json_response(true, $count . ' Mitglied(er) wurden per DM eingeladen, die Gruppe ist jetzt gesperrt.');
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
json_response(false, 'Einladen fehlgeschlagen: ' . $e->getMessage());
|
||||||
|
}
|
||||||
73
raid_signup_action.php
Normal file
73
raid_signup_action.php
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/includes/bootstrap.php';
|
||||||
|
require_once __DIR__ . '/includes/raids_api.php';
|
||||||
|
require_permission('raids.view');
|
||||||
|
|
||||||
|
$input = read_json_body();
|
||||||
|
verify_csrf_token($input['csrf_token'] ?? '');
|
||||||
|
|
||||||
|
$user = current_user();
|
||||||
|
if (empty($user['discord_id'])) {
|
||||||
|
json_response(false, 'Bitte verknüpfe zuerst deinen Discord-Account in "Mein Profil".');
|
||||||
|
}
|
||||||
|
|
||||||
|
$raidId = (int) ($input['raid_id'] ?? 0);
|
||||||
|
$class = trim((string) ($input['class'] ?? ''));
|
||||||
|
$groupRaw = $input['group'] ?? null; // null/"auto" = automatische Zuteilung, sonst gewuenschte Gruppe (0 = Bank)
|
||||||
|
|
||||||
|
if ($raidId <= 0 || $class === '') {
|
||||||
|
json_response(false, 'Bitte eine Klasse auswählen.');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$raid = fetch_raid_by_id($raidId);
|
||||||
|
if (!$raid) {
|
||||||
|
json_response(false, 'Raid wurde nicht gefunden.');
|
||||||
|
}
|
||||||
|
if (!empty($raid['archived'])) {
|
||||||
|
json_response(false, 'Dieser Raid ist archiviert. Anmeldungen sind geschlossen.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$maxGroups = count(array_filter(array_map('trim', explode(',', (string) ($raid['groups'] ?? '')))));
|
||||||
|
$signups = is_array($raid['signups'] ?? null) ? $raid['signups'] : [];
|
||||||
|
$discordId = (int) $user['discord_id'];
|
||||||
|
|
||||||
|
$wantsAuto = $groupRaw === null || $groupRaw === '' || $groupRaw === 'auto';
|
||||||
|
$matchedWish = true;
|
||||||
|
$requestGroup = null;
|
||||||
|
|
||||||
|
if (!$wantsAuto) {
|
||||||
|
$desiredGroup = (int) $groupRaw;
|
||||||
|
if ($desiredGroup < 0 || $desiredGroup > $maxGroups) {
|
||||||
|
json_response(false, 'Ungültige Gruppe ausgewählt.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (raid_wish_is_sensible($signups, $discordId, $class, $desiredGroup)) {
|
||||||
|
$requestGroup = $desiredGroup;
|
||||||
|
} else {
|
||||||
|
$requestGroup = null; // Bot automatisch zuteilen lassen
|
||||||
|
$matchedWish = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$assigned = raid_signup($raidId, $discordId, (string) $user['discord_username'], $class, $requestGroup);
|
||||||
|
$assignedGroup = (int) ($assigned['group'] ?? 0);
|
||||||
|
|
||||||
|
$groupNames = array_values(array_filter(array_map('trim', explode(',', (string) ($raid['groups'] ?? '')))));
|
||||||
|
$assignedGroupLabel = $assignedGroup === 0 ? 'Ersatzbank' : ($groupNames[$assignedGroup - 1] ?? ('Gruppe ' . $assignedGroup));
|
||||||
|
|
||||||
|
if ($matchedWish) {
|
||||||
|
json_response(true, 'Du bist angemeldet: ' . $class . ' in ' . $assignedGroupLabel . '.', [
|
||||||
|
'group' => $assignedGroup,
|
||||||
|
'matched_wish' => true,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
json_response(true, 'Deine Wunschgruppe war schon voll besetzt für diese Rolle, daher wurdest du automatisch zugeteilt: '
|
||||||
|
. $assignedGroupLabel . '. Melde dich gerne beim Raid-Lead, falls du eine Anpassung möchtest.', [
|
||||||
|
'group' => $assignedGroup,
|
||||||
|
'matched_wish' => false,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
json_response(false, 'Anmeldung fehlgeschlagen: ' . $e->getMessage());
|
||||||
|
}
|
||||||
191
raids.php
191
raids.php
|
|
@ -3,18 +3,21 @@ require_once __DIR__ . '/includes/bootstrap.php';
|
||||||
require_once __DIR__ . '/includes/raids_api.php';
|
require_once __DIR__ . '/includes/raids_api.php';
|
||||||
require_permission('raids.view');
|
require_permission('raids.view');
|
||||||
|
|
||||||
function render_signup_list(array $members): void
|
function render_signup_list(array $members, bool $draggable): void
|
||||||
{
|
{
|
||||||
?>
|
?>
|
||||||
<ul>
|
<ul class="raid-signup-list">
|
||||||
<?php foreach ($members as $member): ?>
|
<?php foreach ($members as $member): ?>
|
||||||
<?php
|
<?php
|
||||||
$memberName = (string) ($member['name'] ?? '?');
|
$memberName = (string) ($member['name'] ?? '?');
|
||||||
$memberClass = (string) ($member['class'] ?? '');
|
$memberClass = (string) ($member['class'] ?? '');
|
||||||
|
$memberUserId = (string) ($member['user_id'] ?? '');
|
||||||
$isPending = $memberClass === 'Ausstehend';
|
$isPending = $memberClass === 'Ausstehend';
|
||||||
$classIconUrl = $isPending ? null : class_icon_url($memberClass);
|
$classIconUrl = $isPending ? null : class_icon_url($memberClass);
|
||||||
?>
|
?>
|
||||||
<li<?= $isPending ? ' class="raid-signup-pending"' : '' ?>>
|
<li class="raid-signup-item<?= $isPending ? ' raid-signup-pending' : '' ?>"
|
||||||
|
<?= $draggable ? 'draggable="true"' : '' ?>
|
||||||
|
data-user-id="<?= e($memberUserId) ?>" data-name="<?= e($memberName) ?>" data-class="<?= e($memberClass) ?>">
|
||||||
<?php if ($isPending): ?>
|
<?php if ($isPending): ?>
|
||||||
<span class="class-icon-placeholder" title="Einladung ausstehend">⏳</span>
|
<span class="class-icon-placeholder" title="Einladung ausstehend">⏳</span>
|
||||||
<?php elseif ($classIconUrl): ?>
|
<?php elseif ($classIconUrl): ?>
|
||||||
|
|
@ -50,6 +53,15 @@ try {
|
||||||
$apiError = $e->getMessage();
|
$apiError = $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$premades = [];
|
||||||
|
if ($canManageRaids) {
|
||||||
|
try {
|
||||||
|
$premades = fetch_premades();
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
$premades = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$statusLabels = [
|
$statusLabels = [
|
||||||
'active' => 'Aktiv',
|
'active' => 'Aktiv',
|
||||||
'archived' => 'Archiviert',
|
'archived' => 'Archiviert',
|
||||||
|
|
@ -85,8 +97,10 @@ include __DIR__ . '/includes/header.php';
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<?php foreach ($raids as $raid): ?>
|
<?php foreach ($raids as $raid): ?>
|
||||||
<?php
|
<?php
|
||||||
|
$raidId = (int) ($raid['raid_id'] ?? 0);
|
||||||
$title = (string) ($raid['title'] ?? 'Raid');
|
$title = (string) ($raid['title'] ?? 'Raid');
|
||||||
$dateLabel = (string) ($raid['date'] ?? '');
|
$dateRaw = (string) ($raid['date'] ?? '');
|
||||||
|
$dateLabel = $dateRaw;
|
||||||
if (!empty($raid['timestamp'])) {
|
if (!empty($raid['timestamp'])) {
|
||||||
$dateLabel = date('d.m.Y H:i', (int) $raid['timestamp']) . ' Uhr';
|
$dateLabel = date('d.m.Y H:i', (int) $raid['timestamp']) . ' Uhr';
|
||||||
}
|
}
|
||||||
|
|
@ -96,8 +110,10 @@ include __DIR__ . '/includes/header.php';
|
||||||
$signups = is_array($raid['signups'] ?? null) ? $raid['signups'] : [];
|
$signups = is_array($raid['signups'] ?? null) ? $raid['signups'] : [];
|
||||||
$isArchived = !empty($raid['archived']) || !empty($raid['archived_at']);
|
$isArchived = !empty($raid['archived']) || !empty($raid['archived_at']);
|
||||||
$archivedAt = $raid['archived_at'] ?? null;
|
$archivedAt = $raid['archived_at'] ?? null;
|
||||||
|
$lockedGroups = is_array($raid['locked_groups'] ?? null) ? array_map('intval', $raid['locked_groups']) : [];
|
||||||
|
|
||||||
$groupNames = array_values(array_filter(array_map('trim', explode(',', (string) ($raid['groups'] ?? '')))));
|
$groupNames = array_values(array_filter(array_map('trim', explode(',', (string) ($raid['groups'] ?? '')))));
|
||||||
|
$canEditThis = $canManageRaids && !$isArchived;
|
||||||
|
|
||||||
// Gruppennummern folgen der Logik des Bots: >=1 echte Gruppe, 0 Ersatzbank, -1 abgemeldet.
|
// Gruppennummern folgen der Logik des Bots: >=1 echte Gruppe, 0 Ersatzbank, -1 abgemeldet.
|
||||||
$signupsByGroup = [];
|
$signupsByGroup = [];
|
||||||
|
|
@ -127,8 +143,15 @@ include __DIR__ . '/includes/header.php';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$mySignupGroupNumber = $mySignup ? (int) ($mySignup['group'] ?? 0) : null;
|
||||||
|
$mySignupGroupLabel = $mySignupGroupNumber === 0 ? 'Ersatzbank' : ($mySignupGroupNumber ? ($groupNames[$mySignupGroupNumber - 1] ?? ('#' . $mySignupGroupNumber)) : null);
|
||||||
?>
|
?>
|
||||||
<div class="panel<?= $isArchived ? ' panel-archived' : '' ?>">
|
<div class="panel raid-card<?= $isArchived ? ' panel-archived' : '' ?>"
|
||||||
|
data-raid-id="<?= $raidId ?>"
|
||||||
|
data-groups='<?= e(json_encode($groupNames, JSON_UNESCAPED_UNICODE)) ?>'
|
||||||
|
data-my-class="<?= e((string) ($mySignup['class'] ?? '')) ?>"
|
||||||
|
data-my-group="<?= $mySignupGroupNumber ?? '' ?>">
|
||||||
<div class="raid-header">
|
<div class="raid-header">
|
||||||
<h2><?= e($title) ?></h2>
|
<h2><?= e($title) ?></h2>
|
||||||
<div class="badge-group">
|
<div class="badge-group">
|
||||||
|
|
@ -136,18 +159,23 @@ include __DIR__ . '/includes/header.php';
|
||||||
<span class="badge badge-disabled">Archiviert<?= $archivedAt ? ' (' . e((string) $archivedAt) . ')' : '' ?></span>
|
<span class="badge badge-disabled">Archiviert<?= $archivedAt ? ' (' . e((string) $archivedAt) . ')' : '' ?></span>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<span class="badge"><?= $activeCount ?> / <?= $maxSlots ?> angemeldet</span>
|
<span class="badge"><?= $activeCount ?> / <?= $maxSlots ?> angemeldet</span>
|
||||||
|
<?php if ($canEditThis): ?>
|
||||||
|
<button type="button" class="icon-button raid-edit-toggle" title="Bearbeiten">
|
||||||
|
<?= icon('edit') ?>
|
||||||
|
</button>
|
||||||
|
<?php endif; ?>
|
||||||
<?php if ($canManageRaids): ?>
|
<?php if ($canManageRaids): ?>
|
||||||
<?php if ($isArchived): ?>
|
<?php if ($isArchived): ?>
|
||||||
<form method="post" action="/raid_restore.php" class="inline-form">
|
<form method="post" action="/raid_restore.php" class="inline-form">
|
||||||
<?= csrf_field() ?>
|
<?= csrf_field() ?>
|
||||||
<input type="hidden" name="raid_id" value="<?= (int) ($raid['raid_id'] ?? 0) ?>">
|
<input type="hidden" name="raid_id" value="<?= $raidId ?>">
|
||||||
<input type="hidden" name="status" value="<?= e($status) ?>">
|
<input type="hidden" name="status" value="<?= e($status) ?>">
|
||||||
<button type="submit" class="text-button">Wiederherstellen</button>
|
<button type="submit" class="text-button">Wiederherstellen</button>
|
||||||
</form>
|
</form>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<form method="post" action="/raid_archive.php" class="inline-form" onsubmit="return confirm('Diesen Raid wirklich archivieren?');">
|
<form method="post" action="/raid_archive.php" class="inline-form" onsubmit="return confirm('Diesen Raid wirklich archivieren?');">
|
||||||
<?= csrf_field() ?>
|
<?= csrf_field() ?>
|
||||||
<input type="hidden" name="raid_id" value="<?= (int) ($raid['raid_id'] ?? 0) ?>">
|
<input type="hidden" name="raid_id" value="<?= $raidId ?>">
|
||||||
<input type="hidden" name="status" value="<?= e($status) ?>">
|
<input type="hidden" name="status" value="<?= e($status) ?>">
|
||||||
<button type="submit" class="text-button">Archivieren</button>
|
<button type="submit" class="text-button">Archivieren</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
@ -163,26 +191,96 @@ include __DIR__ . '/includes/header.php';
|
||||||
<p><strong>Gearscore:</strong> <?= e($gearscore) ?></p>
|
<p><strong>Gearscore:</strong> <?= e($gearscore) ?></p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($canEditThis): ?>
|
||||||
|
<div class="raid-edit-panel">
|
||||||
|
<form class="raid-edit-form" data-raid-id="<?= $raidId ?>">
|
||||||
|
<div class="raid-edit-grid">
|
||||||
|
<div>
|
||||||
|
<label>Titel</label>
|
||||||
|
<input type="text" name="title" value="<?= e($title) ?>">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label>Datum & Uhrzeit</label>
|
||||||
|
<input type="text" name="date_raw" value="<?= e($dateRaw) ?>" placeholder="TT.MM.JJJJ HH:MM">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label>Max. Spieler</label>
|
||||||
|
<input type="text" name="max_slots" value="<?= (int) $maxSlots ?>">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label>Gearscore</label>
|
||||||
|
<input type="text" name="gearscore" value="<?= e($gearscore) ?>">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label>Anforderungen</label>
|
||||||
|
<input type="text" name="requirements" value="<?= e($requirements) ?>">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label>Gruppennamen (kommagetrennt)</label>
|
||||||
|
<input type="text" name="group_names" value="<?= e(implode(', ', $groupNames)) ?>">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label>Gruppen sperren</label>
|
||||||
|
<div class="checkbox-grid">
|
||||||
|
<?php foreach ($groupNames as $index => $groupName): ?>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="locked_groups[]" value="<?= $index + 1 ?>" <?= in_array($index + 1, $lockedGroups, true) ? 'checked' : '' ?>>
|
||||||
|
<?= e($groupName) ?>
|
||||||
|
</label>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="actions">
|
||||||
|
<button type="submit">Speichern</button>
|
||||||
|
<span class="raid-edit-feedback text-muted"></span>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php if (!empty($premades)): ?>
|
||||||
|
<form class="raid-premade-form" data-raid-id="<?= $raidId ?>">
|
||||||
|
<label>Premade einladen</label>
|
||||||
|
<div class="raid-premade-row">
|
||||||
|
<select name="premade_id">
|
||||||
|
<?php foreach ($premades as $premade): ?>
|
||||||
|
<option value="<?= (int) ($premade['id'] ?? 0) ?>"><?= e((string) ($premade['name'] ?? '')) ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
<select name="group">
|
||||||
|
<?php foreach ($groupNames as $index => $groupName): ?>
|
||||||
|
<option value="<?= $index + 1 ?>"><?= e($groupName) ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
<button type="submit" class="button-secondary">Einladen</button>
|
||||||
|
</div>
|
||||||
|
<span class="raid-premade-feedback text-muted"></span>
|
||||||
|
</form>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if (!empty($groupNames)): ?>
|
<?php if (!empty($groupNames)): ?>
|
||||||
<div class="raid-groups">
|
<div class="raid-groups">
|
||||||
<?php foreach ($groupNames as $index => $groupName): ?>
|
<?php foreach ($groupNames as $index => $groupName): ?>
|
||||||
<?php $members = $signupsByGroup[$index + 1] ?? []; ?>
|
<?php $members = $signupsByGroup[$index + 1] ?? []; ?>
|
||||||
<div class="raid-group">
|
<div class="raid-group raid-drop-zone" data-group="<?= $index + 1 ?>">
|
||||||
<h3><?= e($groupName) ?> (<?= count($members) ?>)</h3>
|
<h3><?= e($groupName) ?> (<?= count($members) ?>)<?= in_array($index + 1, $lockedGroups, true) ? ' ' . icon('lock') : '' ?></h3>
|
||||||
<?php if (empty($members)): ?>
|
<?php if (empty($members)): ?>
|
||||||
<p class="text-muted">Keine Anmeldungen</p>
|
<p class="text-muted raid-empty-hint">Keine Anmeldungen</p>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<?php render_signup_list($members); ?>
|
<?php render_signup_list($members, $canEditThis); ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php if (!empty($benchSignups)): ?>
|
<div class="raid-group raid-group-bench raid-drop-zone" data-group="0">
|
||||||
<div class="raid-group raid-group-bench">
|
|
||||||
<h3>Ersatzbank (<?= count($benchSignups) ?>)</h3>
|
<h3>Ersatzbank (<?= count($benchSignups) ?>)</h3>
|
||||||
<?php render_signup_list($benchSignups); ?>
|
<?php if (empty($benchSignups)): ?>
|
||||||
</div>
|
<p class="text-muted raid-empty-hint">Keine Anmeldungen</p>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php render_signup_list($benchSignups, $canEditThis); ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php if (!empty($declinedSignups)): ?>
|
<?php if (!empty($declinedSignups)): ?>
|
||||||
<p class="text-muted raid-declined">
|
<p class="text-muted raid-declined">
|
||||||
|
|
@ -190,52 +288,61 @@ include __DIR__ . '/includes/header.php';
|
||||||
</p>
|
</p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php
|
|
||||||
$mySignupGroupNumber = $mySignup ? (int) ($mySignup['group'] ?? 0) : null;
|
|
||||||
$mySignupGroupLabel = $mySignupGroupNumber === 0 ? 'Ersatzbank' : ($mySignupGroupNumber ? ($groupNames[$mySignupGroupNumber - 1] ?? ('#' . $mySignupGroupNumber)) : null);
|
|
||||||
?>
|
|
||||||
<?php if ($isArchived): ?>
|
<?php if ($isArchived): ?>
|
||||||
<p class="text-muted raid-signup-note">Dieser Raid ist archiviert – Anmeldungen sind geschlossen.</p>
|
<p class="text-muted raid-signup-note">Dieser Raid ist archiviert – Anmeldungen sind geschlossen.</p>
|
||||||
<?php elseif (!$currentDiscordId): ?>
|
<?php elseif (!$currentDiscordId): ?>
|
||||||
<p class="text-muted raid-signup-note">Verknüpfe deinen <a href="/profile.php">Discord-Account</a>, um dich anzumelden.</p>
|
<p class="text-muted raid-signup-note">Verknüpfe deinen <a href="/profile.php">Discord-Account</a>, um dich anzumelden.</p>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<?php if ($mySignup): ?>
|
|
||||||
<div class="raid-signup-note">
|
<div class="raid-signup-note">
|
||||||
|
<?php if ($mySignup): ?>
|
||||||
<p>
|
<p>
|
||||||
Du bist angemeldet als <strong><?= e((string) ($mySignup['class'] ?? '')) ?></strong>
|
Du bist angemeldet als <strong><?= e((string) ($mySignup['class'] ?? '')) ?></strong>
|
||||||
in <strong><?= e($mySignupGroupLabel) ?></strong>.
|
in <strong><?= e($mySignupGroupLabel) ?></strong>.
|
||||||
</p>
|
</p>
|
||||||
|
<div class="actions">
|
||||||
|
<button type="button" class="button button-secondary raid-open-signup">Ändern</button>
|
||||||
<form method="post" action="/raid_unsignup.php" class="inline-form">
|
<form method="post" action="/raid_unsignup.php" class="inline-form">
|
||||||
<?= csrf_field() ?>
|
<?= csrf_field() ?>
|
||||||
<input type="hidden" name="raid_id" value="<?= (int) ($raid['raid_id'] ?? 0) ?>">
|
<input type="hidden" name="raid_id" value="<?= $raidId ?>">
|
||||||
<input type="hidden" name="status" value="<?= e($status) ?>">
|
<input type="hidden" name="status" value="<?= e($status) ?>">
|
||||||
<button type="submit" class="button button-secondary">Abmelden</button>
|
<button type="submit" class="button-secondary">Abmelden</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
<?php else: ?>
|
||||||
|
<button type="button" class="button raid-open-signup">Anmelden</button>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php if (!empty($groupNames)): ?>
|
</div>
|
||||||
<form method="post" action="/raid_signup.php" class="raid-signup-form">
|
|
||||||
<?= csrf_field() ?>
|
|
||||||
<input type="hidden" name="raid_id" value="<?= (int) ($raid['raid_id'] ?? 0) ?>">
|
|
||||||
<input type="hidden" name="status" value="<?= e($status) ?>">
|
|
||||||
<select name="class" required>
|
|
||||||
<option value="">Klasse wählen…</option>
|
|
||||||
<?php foreach ($classOptions as $classOption): ?>
|
|
||||||
<option value="<?= e($classOption) ?>" <?= ($mySignup && ($mySignup['class'] ?? '') === $classOption) ? 'selected' : '' ?>><?= e($classOption) ?></option>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</select>
|
|
||||||
<select name="group" required>
|
|
||||||
<?php foreach ($groupNames as $index => $groupName): ?>
|
|
||||||
<option value="<?= $index + 1 ?>" <?= $mySignupGroupNumber === $index + 1 ? 'selected' : '' ?>><?= e($groupName) ?></option>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
<option value="0" <?= $mySignupGroupNumber === 0 ? 'selected' : '' ?>>Ersatzbank</option>
|
|
||||||
</select>
|
|
||||||
<button type="submit"><?= $mySignup ? 'Aktualisieren' : 'Anmelden' ?></button>
|
|
||||||
</form>
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<!-- Gemeinsames Anmelde-Popup fuer alle Raids auf dieser Seite -->
|
||||||
|
<div id="raid-signup-modal" class="modal-overlay" hidden>
|
||||||
|
<div class="modal">
|
||||||
|
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
|
||||||
|
<h2>Zum Raid anmelden</h2>
|
||||||
|
<p class="text-muted">Wähle deine Klasse. Die Gruppe ist optional – ohne Auswahl teilt der Bot dich automatisch sinnvoll ein.</p>
|
||||||
|
<div class="class-picker">
|
||||||
|
<?php foreach ($classOptions as $classOption): ?>
|
||||||
|
<button type="button" class="class-picker-option" data-class="<?= e($classOption) ?>">
|
||||||
|
<img src="<?= e(class_icon_url($classOption)) ?>" alt="">
|
||||||
|
<span><?= e($classOption) ?></span>
|
||||||
|
</button>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="raid-signup-group">Wunschgruppe (optional)</label>
|
||||||
|
<select id="raid-signup-group">
|
||||||
|
<option value="">Automatisch zuteilen</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div id="raid-signup-feedback" class="raid-modal-feedback"></div>
|
||||||
|
<div class="actions">
|
||||||
|
<button type="button" id="raid-signup-confirm">Anmelden</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="/assets/js/raids.js"></script>
|
||||||
<?php include __DIR__ . '/includes/footer.php'; ?>
|
<?php include __DIR__ . '/includes/footer.php'; ?>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue