LuminaWebsite/gear_action.php
Maaxxs 5dabbccbd7 Gear planner, dashboard polish, images on bug reports
Gear planner:
- Personal gear sets (18 slots) with enchant, exceed, soul imprint and manastones,
  stat totals by source and side-by-side comparison of 2-4 sets
- Sets can be shown on the own profile page (read-only for other members)
- Admin catalog: import items from aion2hub.com (Global client), compare stored
  values with the source one by one or all at once, at most one request per second
- New permissions gear.view (all with dashboard access) and gear.manage

Dashboard:
- Role badges ordered like the member list (roster_order)
- Stronger hover effect on "Rangliste & Verlauf" / "Zum Lumishop", no more blue
  hover on secondary buttons
- "Anstehende Raids" box links to the raids page, next raids link to the raid
  and to the calendar day
- Raid attendance only knows present/absent (old "excused" entries count as unset)

Bug reports:
- Up to 5 images per report, pasting copied images with Ctrl+V (also for the gallery)
- Images are only served to the reporter and bugs.manage via bug_image.php

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

212 lines
9.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Gear-Planer: Sets anlegen, bearbeiten, kopieren, loeschen und Slots belegen. Jedes Mitglied
* bearbeitet nur seine eigenen Sets.
*/
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/gear.php';
require_permission('gear.view');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
redirect('/gear.php');
}
verify_csrf();
$me = current_user();
$userId = (int) $me['id'];
$pdo = db();
$action = (string) ($_POST['action'] ?? '');
/** Eigenes Set laden oder mit Meldung zurueck. */
$ownSet = static function () use ($userId): array {
$set = gear_set((int) ($_POST['set_id'] ?? 0));
if (!$set || (int) $set['user_id'] !== $userId) {
set_flash('error', 'Dieses Set gibt es nicht (mehr).');
redirect('/gear.php');
}
return $set;
};
$cleanName = static fn (string $value): string => mb_substr(trim(preg_replace('/\s+/u', ' ', $value) ?? ''), 0, 80);
$cleanClass = static fn (string $value): ?string => in_array($value, AION_CLASSES, true) ? $value : null;
$touch = static function (int $setId) use ($pdo): void {
$pdo->prepare('UPDATE gear_sets SET updated_at = NOW() WHERE id = ?')->execute([$setId]);
};
switch ($action) {
case 'create':
$name = $cleanName((string) ($_POST['name'] ?? ''));
if ($name === '') {
set_flash('error', 'Bitte gib dem Set einen Namen.');
redirect('/gear.php');
}
$count = $pdo->prepare('SELECT COUNT(*) FROM gear_sets WHERE user_id = ?');
$count->execute([$userId]);
if ((int) $count->fetchColumn() >= GEAR_MAX_SETS) {
set_flash('error', 'Du hast schon ' . GEAR_MAX_SETS . ' Sets - lösche erst ein altes.');
redirect('/gear.php');
}
$pdo->prepare(
'INSERT INTO gear_sets (user_id, name, class_name, sort_order, updated_at)
SELECT ?, ?, ?, COALESCE(MAX(sort_order), 0) + 10, NOW() FROM gear_sets WHERE user_id = ?'
)->execute([$userId, $name, $cleanClass((string) ($_POST['class_name'] ?? '')) ?? ($me['class_name'] ?: null), $userId]);
redirect('/gear.php?set=' . (int) $pdo->lastInsertId());
case 'update':
$set = $ownSet();
$name = $cleanName((string) ($_POST['name'] ?? ''));
if ($name === '') {
set_flash('error', 'Der Name darf nicht leer sein.');
redirect('/gear.php?set=' . (int) $set['id']);
}
$note = mb_substr(trim((string) ($_POST['note'] ?? '')), 0, 255);
$pdo->prepare('UPDATE gear_sets SET name = ?, class_name = ?, note = ?, show_on_profile = ?, updated_at = NOW() WHERE id = ?')
->execute([$name, $cleanClass((string) ($_POST['class_name'] ?? '')), $note !== '' ? $note : null, isset($_POST['show_on_profile']) ? 1 : 0, $set['id']]);
set_flash('success', 'Set gespeichert.');
redirect('/gear.php?set=' . (int) $set['id']);
case 'duplicate':
$set = $ownSet();
$count = $pdo->prepare('SELECT COUNT(*) FROM gear_sets WHERE user_id = ?');
$count->execute([$userId]);
if ((int) $count->fetchColumn() >= GEAR_MAX_SETS) {
set_flash('error', 'Du hast schon ' . GEAR_MAX_SETS . ' Sets - lösche erst ein altes.');
redirect('/gear.php?set=' . (int) $set['id']);
}
$pdo->beginTransaction();
$pdo->prepare(
'INSERT INTO gear_sets (user_id, name, class_name, note, show_on_profile, sort_order, updated_at)
SELECT user_id, ?, class_name, note, 0, sort_order + 1, NOW() FROM gear_sets WHERE id = ?'
)->execute([mb_substr($set['name'] . ' (Kopie)', 0, 80), $set['id']]);
$newId = (int) $pdo->lastInsertId();
$pdo->prepare(
'INSERT INTO gear_set_slots (set_id, slot, item_id, enchant, exceed, soul_imprint, manastones, godstone)
SELECT ?, slot, item_id, enchant, exceed, soul_imprint, manastones, godstone FROM gear_set_slots WHERE set_id = ?'
)->execute([$newId, $set['id']]);
$pdo->commit();
set_flash('success', 'Set kopiert - jetzt kannst du Varianten ausprobieren.');
redirect('/gear.php?set=' . $newId);
case 'delete':
$set = $ownSet();
$pdo->prepare('DELETE FROM gear_sets WHERE id = ?')->execute([$set['id']]);
set_flash('success', 'Set „' . $set['name'] . '“ gelöscht.');
redirect('/gear.php');
case 'clear_slot':
$set = $ownSet();
$slot = (string) ($_POST['slot'] ?? '');
$pdo->prepare('DELETE FROM gear_set_slots WHERE set_id = ? AND slot = ?')->execute([$set['id'], $slot]);
$touch((int) $set['id']);
redirect('/gear.php?set=' . (int) $set['id']);
case 'save_slot':
$set = $ownSet();
$slot = (string) ($_POST['slot'] ?? '');
$back = '/gear.php?set=' . (int) $set['id'] . '&slot=' . rawurlencode($slot);
if (!isset(GEAR_SLOTS[$slot])) {
set_flash('error', 'Unbekannter Slot.');
redirect('/gear.php?set=' . (int) $set['id']);
}
$item = gear_item((int) ($_POST['item_id'] ?? 0));
if (!$item) {
set_flash('error', 'Bitte einen Gegenstand aus der Liste wählen.');
redirect($back);
}
if (!gear_item_fits_slot($item, $slot)) {
set_flash('error', '„' . $item['name'] . '“ passt nicht in den Slot ' . GEAR_SLOTS[$slot][0] . '.');
redirect($back);
}
// Bei einem anderen Gegenstand passen Seelenpraegung und Manasteine nicht mehr - neu anfangen
$current = $pdo->prepare('SELECT item_id FROM gear_set_slots WHERE set_id = ? AND slot = ?');
$current->execute([$set['id'], $slot]);
$sameItem = (int) $current->fetchColumn() === (int) $item['id'];
$enchant = max(0, min((int) $item['enchant_max'], (int) ($_POST['enchant'] ?? 0)));
$exceed = max(0, min((int) $item['exceed_max'], (int) ($_POST['exceed'] ?? 0)));
$errors = [];
$soul = [];
if ($sameItem) {
$ranges = [];
foreach ($item['soul_imprint'] as $entry) {
$ranges[$entry[0]] = $entry;
}
$stats = (array) ($_POST['soul_stat'] ?? []);
$values = (array) ($_POST['soul_value'] ?? []);
foreach ($stats as $i => $stat) {
$stat = (string) $stat;
$raw = str_replace(',', '.', trim((string) ($values[$i] ?? '')));
if ($stat === '' || $raw === '') {
continue;
}
if (!isset($ranges[$stat])) {
$errors[] = 'Seelenprägung „' . $stat . '“ gibt es bei diesem Gegenstand nicht.';
continue;
}
if (isset(array_column($soul, 1, 0)[$stat])) {
$errors[] = 'Seelenprägung „' . $stat . '“ ist doppelt eingetragen.';
continue;
}
$value = (float) $raw;
[, $min, $max, $unit] = $ranges[$stat];
if (!is_numeric($raw) || $value < $min || $value > $max) {
$errors[] = $stat . ': ' . gear_format_value($value, $unit) . ' liegt nicht in der möglichen Spanne '
. gear_format_value((float) $min, $unit) . '–' . gear_format_value((float) $max, $unit) . '.';
continue;
}
$soul[] = [$stat, $value];
}
if (count($soul) > (int) $item['soul_imprint_count']) {
$errors[] = 'Höchstens ' . (int) $item['soul_imprint_count'] . ' Seelenprägungen.';
$soul = array_slice($soul, 0, (int) $item['soul_imprint_count']);
}
}
$manastones = [];
if ($sameItem) {
$allowed = array_flip(gear_manastone_stats());
$stats = (array) ($_POST['mana_stat'] ?? []);
$values = (array) ($_POST['mana_value'] ?? []);
foreach ($stats as $i => $stat) {
$stat = (string) $stat;
$raw = trim((string) ($values[$i] ?? ''));
if ($stat === '' || $raw === '') {
continue;
}
if (!isset($allowed[$stat]) || !ctype_digit($raw) || (int) $raw < 1 || (int) $raw > 9999) {
$errors[] = 'Manastein ' . ($i + 1) . ': bitte einen Wert aus der Liste und eine ganze Zahl eintragen.';
continue;
}
$manastones[] = [$stat, (int) $raw];
}
$manastones = array_slice($manastones, 0, (int) $item['manastone_slots']);
}
$godstone = (int) $item['godstone_slots'] > 0 ? mb_substr(trim((string) ($_POST['godstone'] ?? '')), 0, 100) : '';
$pdo->prepare(
'INSERT INTO gear_set_slots (set_id, slot, item_id, enchant, exceed, soul_imprint, manastones, godstone)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
ON DUPLICATE KEY UPDATE item_id = VALUES(item_id), enchant = VALUES(enchant), exceed = VALUES(exceed),
soul_imprint = VALUES(soul_imprint), manastones = VALUES(manastones), godstone = VALUES(godstone)'
)->execute([
$set['id'], $slot, $item['id'], $enchant, $exceed,
json_encode($soul, JSON_UNESCAPED_UNICODE), json_encode($manastones, JSON_UNESCAPED_UNICODE), $godstone !== '' ? $godstone : null,
]);
$touch((int) $set['id']);
if ($errors) {
set_flash('error', 'Gespeichert, aber nicht alles übernommen: ' . implode(' ', $errors));
redirect($back);
}
if (!$sameItem && ((int) $item['soul_imprint_count'] > 0 || (int) $item['manastone_slots'] > 0)) {
set_flash('success', '„' . $item['name'] . '“ eingesetzt - trag jetzt Seelenprägung und Manasteine ein.');
redirect($back);
}
set_flash('success', GEAR_SLOTS[$slot][0] . ' gespeichert.');
redirect('/gear.php?set=' . (int) $set['id']);
}
set_flash('error', 'Unbekannte Aktion.');
redirect('/gear.php');