LuminaWebsite/admin/gear_items_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

124 lines
5.6 KiB
PHP

<?php
/**
* Gear-Planer, Katalog: Gegenstaende von aion2hub uebernehmen und abgleichen.
* Antwortet als JSON (Aufrufe aus assets/js/gear-admin.js), nur "delete" leitet zurueck.
*/
require_once __DIR__ . '/../includes/bootstrap.php';
require_once __DIR__ . '/../includes/gear.php';
require_permission('gear.manage');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
redirect('/admin/gear_items.php');
}
verify_csrf();
$userId = (int) current_user()['id'];
$action = (string) ($_POST['action'] ?? '');
/** JSON-Antwort und Ende. */
$respond = static function (array $data, int $status = 200): void {
http_response_code($status);
header('Content-Type: application/json; charset=UTF-8');
echo json_encode($data, JSON_UNESCAPED_UNICODE);
exit;
};
/**
* Hoechstens ein Abruf pro Sekunde (pro Sitzung) - aion2hub soll von uns nicht mehr merken als
* von jemandem, der sich durch die Seiten klickt.
*/
$politePause = static function (): void {
$last = (float) ($_SESSION['gear_source_last_fetch'] ?? 0);
$wait = 1.0 - (microtime(true) - $last);
if ($wait > 0) {
usleep((int) ($wait * 1000000));
}
$_SESSION['gear_source_last_fetch'] = microtime(true);
};
try {
switch ($action) {
case 'list':
// Listen-Seite von aion2hub (z.B. database?cat=Armor&grade=Unique&page=2) -> enthaltene IDs
$url = trim((string) ($_POST['url'] ?? ''));
$single = gear_source_parse_id($url);
if ($single !== null) {
$respond(['ok' => true, 'ids' => [$single]]);
}
if (!preg_match('#^https://(www\.)?aion2hub\.com/database(\?|$)#i', $url)) {
$respond(['ok' => false, 'error' => 'Bitte eine Gegenstands-ID, einen Gegenstands-Link oder eine Listen-Seite von aion2hub.com/database eintragen.'], 400);
}
$politePause();
$ids = gear_source_list_ids(gear_source_fetch($url));
if (!$ids) {
$respond(['ok' => false, 'error' => 'Auf dieser Seite wurden keine Gegenstände gefunden.'], 404);
}
$known = db()->query('SELECT id FROM gear_items')->fetchAll(PDO::FETCH_COLUMN);
$respond(['ok' => true, 'ids' => $ids, 'known' => array_map('intval', array_values(array_intersect($known, $ids)))]);
case 'import':
case 'check':
$id = (int) ($_POST['id'] ?? 0);
if ($id <= 0) {
$respond(['ok' => false, 'error' => 'Ungültige ID.'], 400);
}
$politePause();
$parsed = gear_item_fetch($id);
$old = gear_item($id);
$diffs = gear_item_diff($old, $parsed);
// Abgleich ohne Uebernehmen: nur zeigen, was anders waere
$apply = $action === 'import' || !empty($_POST['apply']);
if ($apply) {
$result = gear_item_store($parsed, $userId);
} elseif ($old !== null) {
// Trotzdem als "geprueft" vermerken, wenn sich nichts geaendert hat
if (!$diffs) {
db()->prepare('UPDATE gear_items SET checked_at = NOW(), checked_by = ?, source_version = ? WHERE id = ?')
->execute([$userId, mb_substr($parsed['source_version'], 0, 120), $id]);
}
}
if (empty($_POST['batch']) && $apply) {
admin_log($old === null ? '🗡️ Gear-Planer: Gegenstand übernommen' : '🗡️ Gear-Planer: Gegenstand abgeglichen', [
'Gegenstand' => $parsed['name'] . ' (#' . $id . ')',
'Änderungen' => $old === null ? 'neu' : ($diffs ? implode(', ', array_column($diffs, 0)) : 'keine'),
], 'info', 'gear');
}
$respond([
'ok' => true,
'id' => $id,
'name' => $parsed['name'],
'new' => $old === null,
'applied' => $apply,
'diffs' => $old === null ? [] : $diffs,
]);
case 'batch_done':
// Eine Zusammenfassung pro Durchlauf statt eines Eintrags je Gegenstand
$summary = array_filter([
'Art' => (string) ($_POST['kind'] ?? '') === 'check' ? 'Abgleich' : 'Übernahme',
'Neu' => (int) ($_POST['new'] ?? 0) ?: null,
'Geändert' => (int) ($_POST['changed'] ?? 0) ?: null,
'Unverändert' => (int) ($_POST['same'] ?? 0) ?: null,
'Fehler' => (int) ($_POST['failed'] ?? 0) ?: null,
'Quelle' => mb_substr((string) ($_POST['source'] ?? ''), 0, 200) ?: null,
], static fn ($value): bool => $value !== null);
admin_log('🗡️ Gear-Planer: Gegenstände von aion2hub', $summary, 'info', 'gear');
$respond(['ok' => true]);
case 'delete':
$item = gear_item((int) ($_POST['id'] ?? 0));
if ($item) {
db()->prepare('DELETE FROM gear_items WHERE id = ?')->execute([$item['id']]);
if (!empty($item['icon']) && strpos((string) $item['icon'], '/') === false) {
@unlink(GEAR_ICON_DIR . $item['icon']);
}
admin_log('🗡️ Gear-Planer: Gegenstand gelöscht', ['Gegenstand' => $item['name'] . ' (#' . $item['id'] . ')'], 'danger', 'gear');
set_flash('success', '„' . $item['name'] . '“ gelöscht - in Sets ist der Slot jetzt leer.');
}
redirect('/admin/gear_items.php');
}
} catch (RuntimeException $e) {
$respond(['ok' => false, 'error' => $e->getMessage()], 422);
}
$respond(['ok' => false, 'error' => 'Unbekannte Aktion.'], 400);