LuminaWebsite/gear.php
Maaxxs 525bd0d4b5 Gear planner: sets can be shared by link or build code and imported as your own
Asked for: share a build with a link or build code, and an import tool that takes such a code.

- "Teilen" on an own set creates a link (gear.php?build=CODE) and the same code as build code: 10
  characters without 0/O and 1/I/L, shown as K7QX2-M9FRT, stored in gear_sets.share_code (schema
  version 59, unique; also in sql/schema.sql). Whoever opens it sees the set even if it is not on the
  profile, always in its current state; the session remembers the code so tabs, slots and compare
  work, and a renewed or withdrawn code ends that access. "Neuen Code erzeugen" and "Nicht mehr
  teilen" invalidate the old one. The dialog reopens after creating (#teilen) with copy buttons.
- "Build importieren" on "Meine Sets" takes the code (with or without dash, any case) or the whole
  link; viewing someone else's set (shared or on the profile) offers "In meine Sets übernehmen".
  Both copy the set with gear, skills, macros and all planner pages via gear_set_copy() (also used
  by "Kopieren" now); the copy is neither shared nor on the profile. Errors reopen the dialog (#import).
- Members only (gear.view). Opening any page without being logged in now brings you back to it after
  the login (auth_login_return_target) - only for page views in the browser, not for background
  requests like live updates or autosave.
- Privacy policy (shared sets), patch notes and README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 01:44:52 +02:00

809 lines
53 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: eigene Ausruestungssets zusammenstellen, ihre Skills planen und vergleichen.
* /gear.php Uebersicht der eigenen Sets
* /gear.php?set=ID[&slot=KEY] ein Set: Ausruestung (eigene bearbeitbar, fremde nur wenn aufs Profil freigegeben)
* /gear.php?set=ID&tab=skills|stigma Unterseiten Skills und Stigmen des Sets (includes/gear_skills_view.php)
* /gear.php?set=ID&tab=macro[&preset=1-3] die Makros der drei Skill-Presets (includes/gear_macro.php)
* /gear.php?set=ID&tab=arcana|pets|daevanion|pantheon|closet die Seiten nach dem aion2hub-Planer
* (includes/gear_planner_view.php)
* /gear.php?compare[]=ID&… 2-4 Sets nebeneinander
* /gear.php?build=CODE ein per Link/Buildcode geteiltes Set (weiter zu ?set=ID, includes/gear.php)
*/
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/gear.php';
require_once __DIR__ . '/includes/gear_skills_view.php';
require_once __DIR__ . '/includes/gear_planner_view.php';
require_once __DIR__ . '/includes/gear_macro.php';
require_permission('gear.view');
$me = current_user();
$userId = (int) $me['id'];
$canManage = user_has_permission('gear.manage');
$catalogCount = (int) db()->query('SELECT COUNT(*) FROM gear_items')->fetchColumn();
$mySets = gear_sets_for_user($userId);
$mySlots = gear_slots_for_sets(array_column($mySets, 'id'));
$mySkills = gear_set_skills_for_sets($mySets);
// Geteilter Link: Code fuer diese Sitzung merken, dann weiter zum Set (so gehen auch Reiter, Slots und Vergleich)
if (isset($_GET['build'])) {
$code = gear_share_code_input((string) $_GET['build']);
$shared = $code !== null ? gear_set_by_share_code($code) : null;
if (!$shared) {
set_flash('error', 'Diesen Build gibt es nicht (mehr) – vielleicht wird das Set nicht mehr geteilt.');
redirect('/gear.php');
}
gear_share_remember($shared);
redirect('/gear.php?set=' . (int) $shared['id']);
}
// ---- Welche Ansicht? ----
$set = null;
$compare = [];
if (isset($_GET['compare'])) {
foreach (array_slice(array_unique(array_map('intval', (array) $_GET['compare'])), 0, 4) as $compareId) {
$candidate = gear_set($compareId);
if ($candidate && gear_can_view_set($candidate)) {
$compare[] = $candidate;
}
}
if (count($compare) < 2) {
set_flash('error', 'Zum Vergleichen bitte mindestens zwei Sets auswählen.');
redirect('/gear.php');
}
} elseif (isset($_GET['set'])) {
$set = gear_set((int) $_GET['set']);
if (!$set || !gear_can_view_set($set)) {
show_not_found();
}
}
$isOwn = $set && gear_is_own_set($set);
$slots = $set ? (gear_slots_for_sets([(int) $set['id']])[(int) $set['id']] ?? []) : [];
$activeSlot = $set && isset(GEAR_SLOTS[$_GET['slot'] ?? '']) ? (string) $_GET['slot'] : '';
// Unterseite des Sets: Ausruestung (Standard, auch beim Bearbeiten eines Slots), Skills oder Stigmen
$tab = (string) ($_GET['tab'] ?? 'gear');
if (!isset(GEAR_SET_TABS[$tab]) || $activeSlot !== '') {
$tab = 'gear';
}
$activeRow = $activeSlot !== '' ? ($slots[$activeSlot] ?? null) : null;
$activeItem = $activeRow['item'] ?? null;
/** Kurzinfo eines belegten Slots: "+15 · Durchbruch 5 · 3/4 Manasteine" */
$slotTags = static function (?array $row): array {
if (!$row || empty($row['item'])) {
return [];
}
$item = $row['item'];
$tags = [];
if ((int) $item['enchant_max'] > 0) {
$tags[] = '+' . (int) $row['enchant'];
}
if ((int) $row['exceed'] > 0) {
$tags[] = '⬆' . (int) $row['exceed'];
}
if ((int) $item['manastone_slots'] > 0) {
$tags[] = '◆ ' . count($row['manastones']) . '/' . (int) $item['manastone_slots'];
}
return $tags;
};
/** Symbol eines Gegenstands (oder Platzhalter) */
$itemIcon = static function (?array $item, int $size = 40): string {
$url = gear_icon_url($item);
if ($url === null) {
return '<span class="gear-icon gear-icon-empty" style="width:' . $size . 'px;height:' . $size . 'px"></span>';
}
return '<img class="gear-icon ' . e(gear_grade_class($item['grade'] ?? null)) . '" src="' . e($url) . '" alt="" width="' . $size . '" height="' . $size . '" loading="lazy">';
};
$pageTitle = $set ? $set['name'] . ($tab !== 'gear' ? ' · ' . GEAR_SET_TABS[$tab] : '') . ' - Gear-Planer' : 'Gear-Planer';
$containerWide = true;
include __DIR__ . '/includes/header.php';
?>
<div class="panel gear-head">
<div>
<h1>Gear-Planer</h1>
<p class="text-muted">
Stell Ausrüstungssets zusammen, plane Skills, Arcana, Pets, Daevanion-Bretter, Pantheon und Closet
deiner Klasse und vergleiche sie. Grundwerte, Sockel, die Werte bei voller Aufwertung, die Skill-Listen
und die Daten der Planer-Seiten stammen aus dem Spielclient (Global) und werden von der Leitung abgeglichen;
Werte mit <span class="gear-estimated">≈</span> sind für Zwischenstufen hochgerechnet.
</p>
</div>
<div class="gear-head-actions">
<?php if ($set || $compare): ?>
<a class="button button-secondary" href="/gear.php">Meine Sets</a>
<?php endif; ?>
<?php if ($canManage): ?>
<a class="button button-secondary" href="/admin/gear_items.php"><?= icon('list') ?> Gegenstände &amp; Skills verwalten</a>
<?php endif; ?>
</div>
</div>
<?php if ($catalogCount === 0): ?>
<div class="panel gear-empty">
<p><strong>Noch keine Gegenstände im Katalog.</strong></p>
<p class="text-muted">
<?= $canManage
? 'Übernimm zuerst Gegenstände von aion2hub - danach lassen sie sich in die Sets einsetzen.'
: 'Die Leitung muss erst die Gegenstände übernehmen. Sets anlegen kannst du trotzdem schon.' ?>
</p>
<?php if ($canManage): ?><a class="button" href="/admin/gear_items.php">Gegenstände übernehmen</a><?php endif; ?>
</div>
<?php endif; ?>
<?php if ($compare): ?>
<?php
// ---- Vergleich ----
$compareSlots = gear_slots_for_sets(array_column($compare, 'id'));
$compareSkills = gear_set_skills_for_sets($compare);
// Alle Skills, die in mindestens einem Set geplant sind - nach Klasse (wie die Sets), dann wie auf der Klassenseite
$compareSkillRows = [];
foreach ($compare as $c) {
foreach ($compareSkills[(int) $c['id']] ?? [] as $skillId => $planned) {
$compareSkillRows[$skillId] ??= $planned['skill'];
}
}
$classOrder = array_flip(array_unique(array_map(static fn (array $c): string => (string) $c['class_name'], $compare)));
uasort($compareSkillRows, static fn (array $a, array $b): int =>
[$classOrder[$a['class_name']] ?? 99, $a['kind'], (int) $a['sort_order']] <=> [$classOrder[$b['class_name']] ?? 99, $b['kind'], (int) $b['sort_order']]);
$compareTotals = [];
$allKeys = [];
foreach ($compare as $c) {
$compareTotals[(int) $c['id']] = gear_set_totals($compareSlots[(int) $c['id']] ?? []);
foreach ($compareTotals[(int) $c['id']] as $key => $row) {
$allKeys[$key] = $row;
}
}
uksort($allKeys, static function (string $a, string $b) use ($allKeys): int {
$ia = array_search($allKeys[$a]['name'], GEAR_STAT_ORDER, true);
$ib = array_search($allKeys[$b]['name'], GEAR_STAT_ORDER, true);
return [$ia === false ? 99 : $ia, $allKeys[$a]['unit'], $a] <=> [$ib === false ? 99 : $ib, $allKeys[$b]['unit'], $b];
});
$first = (int) $compare[0]['id'];
// Kampfwerte aus Arcana, Pets, Daevanion, Pantheon und Closet (je Set zusammengezaehlt)
$comparePlans = gear_set_plans(array_column($compare, 'id'));
// Skill-Boni aus Daevanion und Arcana je Set: erreichte Stufe = selbst gesteigert + Boni
$compareBonuses = [];
foreach ($compare as $c) {
$compareBonuses[(int) $c['id']] = array_map(static fn (array $bonus): int => (int) array_sum($bonus), gear_plan_skill_bonuses($c, $comparePlans[(int) $c['id']] ?? []));
}
$effectiveIn = static function (array $c, int $skillId, array $skill) use ($compareSkills, $compareBonuses): array {
$level = $compareSkills[(int) $c['id']][$skillId]['level'] ?? 0;
$bonus = $level > 0 ? ($compareBonuses[(int) $c['id']][$skillId] ?? 0) : 0;
return [$level, $bonus, $level > 0 ? gear_skill_effective_level($skill['kind'], min($level, gear_skill_level_max($skill['kind'])), $bonus) : 0];
};
$planTotals = [];
$planKeys = [];
foreach ($compare as $c) {
$sum = [];
foreach (gear_plan_stat_totals($c, $comparePlans[(int) $c['id']] ?? []) as $sectionTotals) {
foreach ($sectionTotals as $stat => $value) {
gear_stats_add($sum, (string) $stat, (float) $value);
}
}
$planTotals[(int) $c['id']] = $sum;
$planKeys += $sum;
}
$planKeys = array_keys(gear_stats_sorted($planKeys));
?>
<div class="panel">
<h2>Vergleich</h2>
<p class="text-muted">Unterschiede beziehen sich immer auf das erste Set (links).</p>
<div class="table-scroll">
<table class="gear-compare">
<thead>
<tr>
<th></th>
<?php foreach ($compare as $c): ?>
<th>
<a href="/gear.php?set=<?= (int) $c['id'] ?>"><?= e($c['name']) ?></a>
<?= class_badge_html($c['class_name'], 18) ?>
<?php if ((int) $c['user_id'] !== $userId): ?><div class="text-muted gear-compare-owner"><?= e($c['owner_name']) ?></div><?php endif; ?>
</th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<tr class="gear-compare-group"><th colspan="<?= count($compare) + 1 ?>">Werte</th></tr>
<?php foreach ($allKeys as $key => $meta): ?>
<?php $base = $compareTotals[$first][$key]['total'] ?? 0.0; ?>
<tr>
<th><?= e($meta['name']) ?></th>
<?php foreach ($compare as $index => $c): ?>
<?php $row = $compareTotals[(int) $c['id']][$key] ?? null; $value = $row['total'] ?? 0.0; $diff = $value - $base; ?>
<td>
<?= $row ? ($row['estimated'] ? '<span class="gear-estimated" title="enthält hochgerechnete Zwischenstufen">≈</span>' : '') . e(gear_format_value($value, $meta['unit'])) : '<span class="text-muted">–</span>' ?>
<?php if ($index > 0 && abs($diff) > 0.001): ?>
<span class="gear-diff <?= $diff > 0 ? 'is-up' : 'is-down' ?>"><?= $diff > 0 ? '+' : '−' ?><?= e(gear_format_value(abs($diff), $meta['unit'])) ?></span>
<?php endif; ?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
<tr class="gear-compare-group"><th colspan="<?= count($compare) + 1 ?>">Ausrüstung</th></tr>
<?php foreach (GEAR_SLOTS as $slotKey => [$slotLabel]): ?>
<tr>
<th><?= e($slotLabel) ?></th>
<?php foreach ($compare as $c): ?>
<?php $row = $compareSlots[(int) $c['id']][$slotKey] ?? null; ?>
<td>
<?php if ($row && $row['item']): ?>
<span class="gear-compare-item">
<?= $itemIcon($row['item'], 24) ?>
<span class="<?= e(gear_grade_class($row['item']['grade'])) ?>"><?= e($row['item']['name']) ?></span>
<span class="text-muted"><?= e(implode(' · ', $slotTags($row))) ?></span>
</span>
<?php else: ?>
<span class="text-muted">–</span>
<?php endif; ?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
<?php if ($planKeys): ?>
<tr class="gear-compare-group"><th colspan="<?= count($compare) + 1 ?>">Werte aus Arcana, Pets, Daevanion, Pantheon &amp; Closet</th></tr>
<?php foreach ($planKeys as $stat): ?>
<?php $base = $planTotals[$first][$stat] ?? 0.0; ?>
<tr>
<th><?= e(gear_stat_label((string) $stat)) ?></th>
<?php foreach ($compare as $index => $c): ?>
<?php $value = $planTotals[(int) $c['id']][$stat] ?? null; $diff = ($value ?? 0.0) - $base; ?>
<td>
<?= $value !== null ? e(gear_stat_value((string) $stat, (float) $value)) : '<span class="text-muted">–</span>' ?>
<?php if ($index > 0 && abs($diff) > 0.001): ?>
<?php $better = in_array($stat, GEAR_STAT_LOWER_BETTER, true) ? $diff < 0 : $diff > 0; ?>
<span class="gear-diff <?= $better ? 'is-up' : 'is-down' ?>"><?= e(gear_stat_value((string) $stat, $diff)) ?></span>
<?php endif; ?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
<?php endif; ?>
<?php if ($compareSkillRows): ?>
<tr class="gear-compare-group"><th colspan="<?= count($compare) + 1 ?>">Skills</th></tr>
<?php foreach ($compareSkillRows as $skillId => $skill): ?>
<?php $baseLevel = $effectiveIn($compare[0], (int) $skillId, $skill)[2]; ?>
<tr>
<th>
<span class="gear-compare-item">
<?php if ($skillIcon = gear_skill_icon_url($skill)): ?><img class="gear-skill-compare-icon" src="<?= e($skillIcon) ?>" alt="" width="22" height="22" loading="lazy"><?php endif; ?>
<?= e(gear_skill_display_name($skill)) ?>
<?php if ($skill['kind'] === 'stigma'): ?><span class="gear-skill-stigma-tag">Stigma</span><?php endif; ?>
</span>
</th>
<?php foreach ($compare as $index => $c): ?>
<?php
// Erreichte Stufe (selbst + Boni aus Daevanion/Arcana), Spezialisierungen nur die, die dabei gehen
[$ownLevel, $bonus, $level] = $effectiveIn($c, (int) $skillId, $skill);
$specNumbers = gear_skill_spec_numbers(gear_skill_specs_clean($compareSkills[(int) $c['id']][$skillId]['specs'] ?? 0, $level));
?>
<td>
<?php if ($level > 0): ?>
<span class="<?= gear_skill_is_bonus($skill['kind'], $level) ? 'gear-skill-bonus-text' : '' ?>"
<?= $bonus > 0 ? 'title="' . e('Stufe ' . $ownLevel . ' selbst, +' . $bonus . ' aus Daevanion/Arcana') . '"' : '' ?>><?= $level ?></span>
<?php if ($specNumbers): ?>
<span class="text-muted" title="<?= e(implode(', ', array_map(static fn (int $no): string => gear_skill_spec_label($skill, $no), $specNumbers))) ?>">
· <?= e(implode(', ', array_map(static fn (int $no): string => GEAR_SKILL_SPEC_NUMERALS[$no], $specNumbers))) ?>
</span>
<?php endif; ?>
<?php else: ?>
<span class="text-muted">–</span>
<?php endif; ?>
<?php if ($index > 0 && $c['class_name'] === $compare[0]['class_name'] && $level !== $baseLevel): ?>
<span class="gear-diff <?= $level > $baseLevel ? 'is-up' : 'is-down' ?>"><?= $level > $baseLevel ? '+' : '−' ?><?= abs($level - $baseLevel) ?></span>
<?php endif; ?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
<?php elseif ($set): ?>
<?php
$totals = gear_set_totals($slots);
$itemLevel = gear_set_item_level($slots);
$plannedSkills = gear_set_skills_for_sets([$set])[(int) $set['id']] ?? [];
$setPlans = gear_set_plans([(int) $set['id']])[(int) $set['id']] ?? [];
?>
<div class="panel gear-set-head">
<div class="gear-set-title">
<h2><?= e($set['name']) ?> <?= class_badge_html($set['class_name'], 26) ?></h2>
<div class="text-muted">
<?php if (!$isOwn): ?>Set von <?= e($set['owner_name']) ?> · <?php endif; ?>
<?= count(array_filter($slots, static fn (array $row): bool => !empty($row['item']))) ?>/<?= count(GEAR_SLOTS) ?> Slots belegt
<?php if ($itemLevel !== null): ?> · Ø Gegenstandsstufe <?= e(number_format($itemLevel, 1, ',', '.')) ?><?php endif; ?>
<?php if ($isOwn && $set['show_on_profile']): ?> · <span class="badge">auf dem Profil sichtbar</span><?php endif; ?>
<?php if ($isOwn && !empty($set['share_code'])): ?> · <span class="badge">per Link geteilt</span><?php endif; ?>
</div>
<?php if (!empty($set['note'])): ?><p><?= e($set['note']) ?></p><?php endif; ?>
</div>
<div class="gear-set-actions">
<?php if (!empty($set['build_url']) && gear_build_host((string) $set['build_url']) !== null): ?>
<a class="button button-secondary" href="<?= e($set['build_url']) ?>" target="_blank" rel="noopener noreferrer nofollow"
title="Build auf <?= e(gear_build_host((string) $set['build_url'])) ?>">Build-Link ↗</a>
<?php endif; ?>
<?php if ($isOwn): ?>
<button type="button" class="button button-secondary" data-modal-open="gear-set-edit"><?= icon('edit') ?> Bearbeiten</button>
<button type="button" class="button button-secondary" data-modal-open="gear-set-share"><?= icon('link') ?> Teilen</button>
<form method="post" action="/gear_action.php">
<?= csrf_field() ?>
<input type="hidden" name="action" value="duplicate">
<input type="hidden" name="set_id" value="<?= (int) $set['id'] ?>">
<button type="submit" class="button button-secondary">Kopieren</button>
</form>
<?php else: ?>
<?php // Fremdes Set (geteilt oder auf dem Profil): als eigenes uebernehmen und dann anpassen ?>
<form method="post" action="/gear_action.php">
<?= csrf_field() ?>
<input type="hidden" name="action" value="import">
<input type="hidden" name="set_id" value="<?= (int) $set['id'] ?>">
<button type="submit" class="button" title="Kopie mit Ausrüstung, Skills, Makros und allen Planer-Seiten in deine Sets – das Original bleibt, wie es ist">In meine Sets übernehmen</button>
</form>
<?php endif; ?>
<?php $compareWith = array_values(array_filter($mySets, static fn (array $s): bool => (int) $s['id'] !== (int) $set['id'])); ?>
<?php if ($compareWith): ?>
<form method="get" action="/gear.php" class="gear-compare-with">
<input type="hidden" name="compare[]" value="<?= (int) $set['id'] ?>">
<select name="compare[]" aria-label="Vergleichen mit" onchange="this.form.submit()">
<option value="">Vergleichen mit …</option>
<?php foreach ($compareWith as $other): ?>
<option value="<?= (int) $other['id'] ?>"><?= e($other['name']) ?></option>
<?php endforeach; ?>
</select>
</form>
<?php endif; ?>
</div>
</div>
<?php
// Reiter: Ausruestung, Arcana, Pets, Skills, Stigmen, Daevanion, Pantheon, Closet - jede eine eigene Seite
$tabCounts = [
'gear' => count(array_filter($slots, static fn (array $row): bool => !empty($row['item']))) . '/' . count(GEAR_SLOTS),
'skills' => (string) count(gear_skills_of_tab($plannedSkills, 'skills')),
'stigma' => count(gear_skills_of_tab($plannedSkills, 'stigma')) . '/' . GEAR_STIGMA_SLOTS,
'macro' => ($macroCount = gear_macro_count(gear_set_macro((int) $set['id']))) > 0 ? (string) $macroCount : '',
];
foreach (array_keys(GEAR_PLAN_SECTIONS) as $section) {
$tabCounts[$section] = gear_plan_tab_count($setPlans, $section);
}
?>
<nav class="gear-tabs" aria-label="Bereiche des Sets">
<?php foreach (GEAR_SET_TABS as $tabKey => $tabLabel): ?>
<a class="gear-tab<?= $tab === $tabKey ? ' is-active' : '' ?>" href="/gear.php?set=<?= (int) $set['id'] ?><?= $tabKey !== 'gear' ? '&amp;tab=' . $tabKey : '' ?>"<?= $tab === $tabKey ? ' aria-current="page"' : '' ?>>
<?= e($tabLabel) ?> <span class="gear-tab-count"><?= e($tabCounts[$tabKey]) ?></span>
</a>
<?php endforeach; ?>
</nav>
<?php if (isset(GEAR_PLAN_SECTIONS[$tab])): ?>
<?php
// Eigene andere Sets, aus denen sich diese Seite uebernehmen laesst
$copySets = [];
if ($isOwn) {
$otherPlans = gear_set_plans(array_column($mySets, 'id'));
foreach ($mySets as $other) {
if ((int) $other['id'] !== (int) $set['id'] && isset($otherPlans[(int) $other['id']][$tab])) {
$copySets[(int) $other['id']] = $other;
}
}
}
gear_render_plan_tab($set, $tab, $setPlans[$tab] ?? [], $isOwn, $canManage, $copySets);
?>
<?php elseif ($tab === 'macro'): ?>
<?php gear_render_macro_tab($set, $isOwn, $canManage, $setPlans, (int) ($_GET['preset'] ?? 0)); ?>
<?php elseif ($tab !== 'gear'): ?>
<?php gear_render_skill_tab($set, $tab, $isOwn, $canManage, $setPlans); ?>
<?php else: ?>
<div class="gear-layout">
<div class="panel gear-slots-panel">
<?php // Ausruestung als Raster wie im Spiel: zwei Slots pro Reihe, Name beim Drueberfahren ?>
<div class="gear-doll">
<?php foreach (GEAR_DOLL_ORDER as $slotKey): ?>
<?php
$slotLabel = GEAR_SLOTS[$slotKey][0];
$row = $slots[$slotKey] ?? null;
$item = $row['item'] ?? null;
// Passt nicht (mehr), z.B. nach einem Klassenwechsel: rot markiert, geloescht wird nichts
$mismatch = $item ? gear_item_mismatch($item, $slotKey, $set['class_name']) : null;
$tip = $slotLabel . ': ' . ($item ? $item['name'] . ($slotTags($row) ? ' (' . implode(' · ', $slotTags($row)) . ')' : '') : 'leer')
. ($mismatch !== null ? ' – ' . $mismatch : '');
?>
<a class="gear-doll-slot<?= $item ? ' is-filled ' . e(gear_grade_class($item['grade'])) : '' ?><?= $mismatch !== null ? ' is-mismatch' : '' ?><?= $slotKey === $activeSlot ? ' is-active' : '' ?>"
href="/gear.php?set=<?= (int) $set['id'] ?>&amp;slot=<?= e($slotKey) ?>#slot" title="<?= e($tip) ?>" aria-label="<?= e($tip) ?>">
<?php if ($item && ($iconUrl = gear_icon_url($item))): ?>
<img src="<?= e($iconUrl) ?>" alt="" loading="lazy">
<?php elseif ($item): ?>
<span class="gear-doll-initial"><?= e(mb_substr($item['name'], 0, 1)) ?></span>
<?php else: ?>
<?= gear_slot_silhouette($slotKey) ?>
<?php endif; ?>
<?php if ($item && (int) $row['exceed'] > 0): ?><span class="gear-doll-exceed">⬆<?= (int) $row['exceed'] ?></span><?php endif; ?>
<?php if ($item && (int) $row['enchant'] > 0): ?><span class="gear-doll-enchant">+<?= (int) $row['enchant'] ?></span><?php endif; ?>
<?php if ($item && (int) $item['manastone_slots'] > 0): ?>
<span class="gear-doll-stones" aria-hidden="true">
<?php for ($i = 0; $i < (int) $item['manastone_slots']; $i++): ?><i class="<?= $i < count($row['manastones']) ? 'is-set' : '' ?>"></i><?php endfor; ?>
</span>
<?php endif; ?>
</a>
<?php endforeach; ?>
</div>
<p class="gear-doll-hint text-muted"><?= $isOwn ? 'Slot anklicken zum Bearbeiten' : 'Slot anklicken für Details' ?></p>
</div>
<div class="gear-side">
<?php if ($activeSlot !== ''): ?>
<div class="panel gear-slot-editor" id="slot">
<h3><?= e(GEAR_SLOTS[$activeSlot][0]) ?></h3>
<?php if ($activeItem): ?>
<?php $activeMismatch = gear_item_mismatch($activeItem, $activeSlot, $set['class_name']); ?>
<div class="gear-item-card">
<?= $itemIcon($activeItem, 48) ?>
<div>
<strong class="<?= e(gear_grade_class($activeItem['grade'])) ?>"><?= e($activeItem['name']) ?></strong>
<?php if ($activeMismatch !== null): ?><span class="badge badge-disabled"><?= e($activeMismatch) ?></span><?php endif; ?>
<div class="text-muted">
<?= e($activeItem['grade']) ?> · Stufe <?= (int) $activeItem['item_level'] ?>
<?= $activeItem['item_type'] !== $activeItem['slot'] ? ' · ' . e(gear_type_label($activeItem['item_type'])) : '' ?>
· <a href="<?= e(GEAR_SOURCE_ITEM_URL . (int) $activeItem['id']) ?>" target="_blank" rel="noopener">aion2hub</a>
</div>
<div class="gear-item-stats"><?= e(gear_stats_text($activeItem['stats'])) ?></div>
</div>
</div>
<?php endif; ?>
<?php if ($isOwn): ?>
<?php $pickerItems = gear_picker_items($activeSlot, $set['class_name'], $activeItem ? (int) $activeItem['id'] : 0); ?>
<form method="post" action="/gear_action.php" class="gear-slot-form" data-autosave>
<?= csrf_field() ?>
<input type="hidden" name="action" value="save_slot">
<input type="hidden" name="set_id" value="<?= (int) $set['id'] ?>">
<input type="hidden" name="slot" value="<?= e($activeSlot) ?>">
<div>
<label for="gear-item-search">Gegenstand</label>
<div class="item-picker" data-picker-items="gear-picker" data-picker-mode="id" data-picker-empty="Nichts gefunden - fehlt ein Gegenstand, sag der Leitung Bescheid.">
<label class="search-field">
<span class="item-picker-icon"><?= icon('search') ?></span>
<input type="text" class="item-picker-input" id="gear-item-search" required placeholder="<?= $pickerItems ? 'Gegenstand suchen …' : 'Noch keine Gegenstände für diesen Slot' ?>">
</label>
<input type="hidden" name="item_id" value="<?= $activeItem ? (int) $activeItem['id'] : '' ?>">
</div>
<script type="application/json" id="gear-picker"><?= json_encode($pickerItems, JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP) ?></script>
<?php if ($activeSlot === 'main_hand'): ?>
<p class="gear-hint text-muted">
<?= isset(GEAR_CLASS_WEAPONS[$set['class_name'] ?? ''])
? 'Nur Waffen für ' . e($set['class_name']) . ' – Klasse ändern unter „Bearbeiten“.'
: 'Tipp: Klasse im Set wählen, dann siehst du nur passende Waffen.' ?>
</p>
<?php endif; ?>
</div>
<?php if ($activeItem): ?>
<div class="gear-form-row">
<?php if ((int) $activeItem['enchant_max'] > 0): ?>
<label>Aufwertung
<select name="enchant">
<?php for ($level = 0; $level <= (int) $activeItem['enchant_max']; $level++): ?>
<option value="<?= $level ?>"<?= (int) $activeRow['enchant'] === $level ? ' selected' : '' ?>>+<?= $level ?></option>
<?php endfor; ?>
</select>
</label>
<?php endif; ?>
<?php if ((int) $activeItem['exceed_max'] > 0): ?>
<label>Durchbruch
<select name="exceed">
<?php for ($level = 0; $level <= (int) $activeItem['exceed_max']; $level++): ?>
<option value="<?= $level ?>"<?= (int) $activeRow['exceed'] === $level ? ' selected' : '' ?>><?= $level ?></option>
<?php endfor; ?>
</select>
</label>
<?php endif; ?>
</div>
<?php if ($activeItem['enchant_stats']): ?>
<p class="gear-hint text-muted">
Bei +<?= (int) $activeItem['enchant_max'] ?>: <?= e(gear_stats_text($activeItem['enchant_stats'])) ?>
<?php if ($activeItem['exceed_stats']): ?><br>Durchbruch <?= (int) $activeItem['exceed_max'] ?>: <?= e(gear_stats_text($activeItem['exceed_stats'])) ?><?php endif; ?>
</p>
<?php endif; ?>
<?php if ((int) $activeItem['soul_imprint_count'] > 0): ?>
<fieldset class="gear-fieldset">
<legend>Seelenprägung <span class="text-muted">(bis zu <?= (int) $activeItem['soul_imprint_count'] ?>, wie im Spiel gewürfelt)</span></legend>
<?php for ($i = 0; $i < (int) $activeItem['soul_imprint_count']; $i++): ?>
<?php $entry = $activeRow['soul_imprint'][$i] ?? null; ?>
<div class="gear-roll-row">
<select name="soul_stat[]" aria-label="Seelenprägung <?= $i + 1 ?>" data-range-select>
<option value="">– keine –</option>
<?php foreach ($activeItem['soul_imprint'] as [$stat, $min, $max, $unit]): ?>
<option value="<?= e($stat) ?>" data-min="<?= e((string) $min) ?>" data-max="<?= e((string) $max) ?>" data-unit="<?= e($unit) ?>"<?= $entry && $entry[0] === $stat ? ' selected' : '' ?>>
<?= e($stat) ?> (<?= e(gear_format_value((float) $min, $unit)) ?>–<?= e(gear_format_value((float) $max, $unit)) ?>)
</option>
<?php endforeach; ?>
</select>
<input type="text" inputmode="decimal" name="soul_value[]" value="<?= $entry ? e(str_replace('.', ',', (string) $entry[1])) : '' ?>" placeholder="Wert" aria-label="Wert Seelenprägung <?= $i + 1 ?>">
</div>
<?php endfor; ?>
</fieldset>
<?php endif; ?>
<?php if ((int) $activeItem['manastone_slots'] > 0): ?>
<?php $manastoneStats = gear_manastone_stats(); ?>
<fieldset class="gear-fieldset">
<legend>Manasteine <span class="text-muted">(<?= (int) $activeItem['manastone_slots'] ?> Sockel)</span></legend>
<?php for ($i = 0; $i < (int) $activeItem['manastone_slots']; $i++): ?>
<?php $entry = $activeRow['manastones'][$i] ?? null; ?>
<div class="gear-roll-row">
<select name="mana_stat[]" aria-label="Manastein <?= $i + 1 ?>">
<option value="">– leer –</option>
<?php foreach ($manastoneStats as $stat): ?>
<option value="<?= e($stat) ?>"<?= $entry && $entry[0] === $stat ? ' selected' : '' ?>><?= e($stat) ?></option>
<?php endforeach; ?>
</select>
<input type="text" inputmode="numeric" name="mana_value[]" value="<?= $entry ? (int) $entry[1] : '' ?>" placeholder="Wert" aria-label="Wert Manastein <?= $i + 1 ?>">
</div>
<?php endfor; ?>
</fieldset>
<?php endif; ?>
<?php if ((int) $activeItem['godstone_slots'] > 0): ?>
<label>Götterstein <span class="text-muted">(nur zur Info, zählt nicht in die Werte)</span>
<input type="text" name="godstone" maxlength="100" value="<?= e((string) ($activeRow['godstone'] ?? '')) ?>" placeholder="z.B. Götterstein: …">
</label>
<?php endif; ?>
<p class="gear-hint text-muted">Wechselst du den Gegenstand, werden Seelenprägung und Manasteine zurückgesetzt.</p>
<?php endif; ?>
<div class="actions gear-slot-actions">
<?php // Mit JavaScript speichert das Formular automatisch (assets/js/gear.js) - der Knopf verschwindet dann ?>
<button type="submit" class="button" data-autosave-fallback>Speichern</button>
<span class="gear-save-status" aria-live="polite"></span>
<a class="button button-secondary" href="/gear.php?set=<?= (int) $set['id'] ?>">Schließen</a>
</div>
</form>
<?php if ($activeItem): ?>
<form method="post" action="/gear_action.php" class="gear-clear-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="clear_slot">
<input type="hidden" name="set_id" value="<?= (int) $set['id'] ?>">
<input type="hidden" name="slot" value="<?= e($activeSlot) ?>">
<button type="submit" class="button button-secondary button-small">Slot leeren</button>
</form>
<?php endif; ?>
<?php elseif ($activeItem): ?>
<dl class="gear-detail-list">
<?php if ((int) $activeItem['enchant_max'] > 0): ?><div><dt>Aufwertung</dt><dd>+<?= (int) $activeRow['enchant'] ?> von +<?= (int) $activeItem['enchant_max'] ?></dd></div><?php endif; ?>
<?php if ((int) $activeItem['exceed_max'] > 0): ?><div><dt>Durchbruch</dt><dd><?= (int) $activeRow['exceed'] ?> von <?= (int) $activeItem['exceed_max'] ?></dd></div><?php endif; ?>
<?php if ($activeRow['soul_imprint']): ?>
<div><dt>Seelenprägung</dt><dd><?= e(implode(', ', array_map(static fn (array $s): string => $s[0] . ' ' . str_replace('.', ',', (string) $s[1]), $activeRow['soul_imprint']))) ?></dd></div>
<?php endif; ?>
<?php if ($activeRow['manastones']): ?>
<div><dt>Manasteine</dt><dd><?= e(implode(', ', array_map(static fn (array $s): string => $s[0] . ' ' . (int) $s[1], $activeRow['manastones']))) ?></dd></div>
<?php endif; ?>
<?php if (!empty($activeRow['godstone'])): ?><div><dt>Götterstein</dt><dd><?= e((string) $activeRow['godstone']) ?></dd></div><?php endif; ?>
</dl>
<?php else: ?>
<p class="text-muted">Dieser Slot ist leer.</p>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="panel gear-totals">
<h3>Werte gesamt</h3>
<?php if (!$totals): ?>
<p class="text-muted">Noch keine Gegenstände eingesetzt.</p>
<?php else: ?>
<?php $usedSources = array_keys(array_filter(GEAR_SOURCES, static fn (string $label, string $source): bool => (bool) array_filter($totals, static fn (array $t): bool => isset($t['by'][$source])), ARRAY_FILTER_USE_BOTH)); ?>
<div class="table-scroll">
<table class="gear-totals-table">
<thead>
<tr>
<th>Wert</th>
<th class="gear-total-col">Gesamt</th>
<?php foreach ($usedSources as $source): ?><th class="gear-source-col"><?= e(GEAR_SOURCES[$source]) ?></th><?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php foreach ($totals as $row): ?>
<tr>
<th><?= e($row['name']) ?></th>
<td class="gear-total-col">
<?php if ($row['estimated']): ?><span class="gear-estimated" title="enthält hochgerechnete Zwischenstufen">≈</span><?php endif; ?>
<?= e(gear_format_value($row['total'], $row['unit'])) ?>
</td>
<?php foreach ($usedSources as $source): ?>
<td class="gear-source-col"><?= isset($row['by'][$source]) ? e(gear_format_value($row['by'][$source], $row['unit'])) : '<span class="text-muted">–</span>' ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<p class="gear-hint text-muted">Einfache Summe aller Gegenstände - Klassen- und Charakterwerte, Set-Boni und Götterstein sind nicht enthalten.</p>
<?php endif; ?>
</div>
</div>
</div>
<?php endif; ?>
<?php if ($isOwn): ?>
<div class="modal-overlay" id="gear-set-edit" hidden>
<div class="modal">
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
<h2>Set bearbeiten</h2>
<form method="post" action="/gear_action.php">
<?= csrf_field() ?>
<input type="hidden" name="action" value="update">
<input type="hidden" name="set_id" value="<?= (int) $set['id'] ?>">
<label>Name <input type="text" name="name" maxlength="80" required value="<?= e($set['name']) ?>"></label>
<label>Klasse
<select name="class_name">
<option value="">– keine –</option>
<?php foreach (AION_CLASSES as $class): ?>
<option value="<?= e($class) ?>"<?= $set['class_name'] === $class ? ' selected' : '' ?>><?= e($class) ?></option>
<?php endforeach; ?>
</select>
</label>
<label>Notiz <input type="text" name="note" maxlength="255" value="<?= e((string) $set['note']) ?>" placeholder="z.B. PvP, Raid, Ziel-Ausrüstung …"></label>
<label>Link zu einem Build <span class="text-muted">(optional)</span>
<input type="url" name="build_url" maxlength="<?= GEAR_BUILD_URL_MAX ?>" value="<?= e((string) ($set['build_url'] ?? '')) ?>" placeholder="https://aion2hub.com/…">
</label>
<p class="field-hint">Skills, Arcana, Pets, Daevanion, Pantheon und Closet planst du direkt hier im Set. Für das, was die Website noch nicht kennt (z. B. Titel oder Flügel), kannst du einen Build auf einer Planer-Seite (<?= e(implode(', ', GEAR_BUILD_HOSTS)) ?>) verlinken – der Link erscheint beim Set und auf deiner Profilseite.</p>
<label class="checkbox-label"><input type="checkbox" name="show_on_profile" value="1"<?= $set['show_on_profile'] ? ' checked' : '' ?>> Auf meiner Profilseite zeigen</label>
<div class="actions">
<button type="submit" class="button">Speichern</button>
</div>
</form>
<form method="post" action="/gear_action.php" data-confirm="Set „<?= e($set['name']) ?>“ wirklich löschen?" data-confirm-title="Set löschen" data-confirm-danger data-confirm-ok="Löschen" class="gear-delete-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="delete">
<input type="hidden" name="set_id" value="<?= (int) $set['id'] ?>">
<button type="submit" class="button button-danger button-small"><?= icon('trash') ?> Set löschen</button>
</form>
</div>
</div>
<?php // Teilen per Link und Buildcode - nach dem Erzeugen geht der Dialog wieder auf (#teilen, assets/js/gear.js) ?>
<div class="modal-overlay" id="gear-set-share" data-hash="teilen" hidden>
<div class="modal">
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
<h2>Set teilen</h2>
<p class="text-muted">
Wer den Link oder den Buildcode hat, sieht dieses Set – auch wenn es nicht auf deinem Profil steht – und kann
es mit einem Klick in seine eigenen Sets übernehmen: mit Ausrüstung, Skills, Makros und allen Planer-Seiten.
Das geht mit einem Konto hier auf der Website. Geteilt wird immer der aktuelle Stand des Sets.
</p>
<?php if (!empty($set['share_code'])): ?>
<div class="gear-share-field">
<label for="gear-share-link">Link</label>
<div class="data-link-copy">
<input type="text" id="gear-share-link" value="<?= e(gear_share_url((string) $set['share_code'])) ?>" readonly>
<button type="button" class="button-secondary" data-copy-target="gear-share-link">Kopieren</button>
</div>
</div>
<div class="gear-share-field">
<label for="gear-share-code">Buildcode <span class="text-muted">(zum Einfügen unter „Meine Sets“ → „Build importieren“)</span></label>
<div class="data-link-copy">
<input type="text" id="gear-share-code" class="gear-share-code" value="<?= e(gear_share_code_label((string) $set['share_code'])) ?>" readonly>
<button type="button" class="button-secondary" data-copy-target="gear-share-code">Kopieren</button>
</div>
</div>
<div class="actions gear-share-actions">
<form method="post" action="/gear_action.php" data-confirm="Neuen Link und Buildcode erzeugen? Die bisherigen gelten dann nicht mehr." data-confirm-title="Neuer Buildcode" data-confirm-ok="Neu erzeugen">
<?= csrf_field() ?>
<input type="hidden" name="action" value="share">
<input type="hidden" name="set_id" value="<?= (int) $set['id'] ?>">
<input type="hidden" name="renew" value="1">
<button type="submit" class="button button-secondary button-small">Neuen Code erzeugen</button>
</form>
<form method="post" action="/gear_action.php" data-confirm="Nicht mehr teilen? Link und Buildcode gelten dann nicht mehr – schon übernommene Kopien bleiben." data-confirm-title="Nicht mehr teilen" data-confirm-ok="Nicht mehr teilen">
<?= csrf_field() ?>
<input type="hidden" name="action" value="unshare">
<input type="hidden" name="set_id" value="<?= (int) $set['id'] ?>">
<button type="submit" class="button button-secondary button-small">Nicht mehr teilen</button>
</form>
</div>
<?php else: ?>
<form method="post" action="/gear_action.php">
<?= csrf_field() ?>
<input type="hidden" name="action" value="share">
<input type="hidden" name="set_id" value="<?= (int) $set['id'] ?>">
<div class="actions">
<button type="submit" class="button"><?= icon('link') ?> Link und Buildcode erzeugen</button>
</div>
</form>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<?php else: ?>
<?php // ---- Uebersicht der eigenen Sets ---- ?>
<div class="panel">
<div class="gear-overview-head">
<h2>Meine Sets</h2>
<form method="post" action="/gear_action.php" class="gear-create-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="create">
<input type="text" name="name" maxlength="80" required placeholder="Name, z.B. Raid-Set" aria-label="Name des neuen Sets">
<select name="class_name" aria-label="Klasse">
<option value=""<?= empty($me['class_name']) ? ' selected' : '' ?>>– keine Klasse –</option>
<?php foreach (AION_CLASSES as $class): ?>
<option value="<?= e($class) ?>"<?= ($me['class_name'] ?? '') === $class ? ' selected' : '' ?>><?= e($class) ?></option>
<?php endforeach; ?>
</select>
<button type="submit" class="button">Neues Set</button>
</form>
<button type="button" class="button button-secondary" data-modal-open="gear-import"><?= icon('link') ?> Build importieren</button>
</div>
<?php if (!$mySets): ?>
<p class="text-muted">Du hast noch kein Set. Leg oben eins an - z.B. deine aktuelle Ausrüstung und ein Ziel-Set zum Vergleichen.</p>
<?php else: ?>
<form method="get" action="/gear.php" id="gear-compare-form">
<div class="gear-set-cards">
<?php foreach ($mySets as $s): ?>
<?php $sSlots = $mySlots[(int) $s['id']] ?? []; $sLevel = gear_set_item_level($sSlots); $sSkills = $mySkills[(int) $s['id']] ?? []; ?>
<article class="gear-set-card">
<label class="gear-set-card-check" title="Zum Vergleich auswählen">
<input type="checkbox" name="compare[]" value="<?= (int) $s['id'] ?>">
</label>
<a class="gear-set-card-link" href="/gear.php?set=<?= (int) $s['id'] ?>">
<span class="gear-set-card-title"><?= e($s['name']) ?> <?= class_badge_html($s['class_name'], 20) ?></span>
<span class="text-muted">
<?= count(array_filter($sSlots, static fn (array $row): bool => !empty($row['item']))) ?>/<?= count(GEAR_SLOTS) ?> Slots
<?php if ($sLevel !== null): ?> · Ø Stufe <?= e(number_format($sLevel, 1, ',', '.')) ?><?php endif; ?>
<?php if ($sSkills): ?> · <?= count($sSkills) ?> Skills<?php endif; ?>
<?php if ($s['show_on_profile']): ?> · auf dem Profil<?php endif; ?>
</span>
<?= gear_doll_mini_html($sSlots) ?>
<?= gear_skills_mini_html($sSkills) ?>
<?php if (!empty($s['note'])): ?><span class="gear-set-card-note"><?= e($s['note']) ?></span><?php endif; ?>
</a>
</article>
<?php endforeach; ?>
</div>
<?php if (count($mySets) > 1): ?>
<div class="actions gear-compare-bar">
<button type="submit" class="button button-secondary" id="gear-compare-button" disabled>Ausgewählte vergleichen</button>
<span class="text-muted">2–4 Sets anhaken</span>
</div>
<?php endif; ?>
</form>
<?php endif; ?>
</div>
<?php // Build importieren: Buildcode oder Link eines geteilten Sets - nach einem Fehler geht der Dialog wieder auf (#import) ?>
<div class="modal-overlay" id="gear-import" data-hash="import" hidden>
<div class="modal">
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
<h2>Build importieren</h2>
<p class="text-muted">
Hat dir jemand einen Buildcode oder Link geschickt? Füg ihn hier ein – das Set kommt als dein eigenes in deine
Sets, mit Ausrüstung, Skills, Makros und allen Planer-Seiten. Das Original bleibt, wie es ist.
</p>
<form method="post" action="/gear_action.php">
<?= csrf_field() ?>
<input type="hidden" name="action" value="import">
<label for="gear-import-code">Buildcode oder Link</label>
<input type="text" id="gear-import-code" class="gear-share-code" name="code" required maxlength="300" autocomplete="off" spellcheck="false" placeholder="z.B. K7QX2-M9FRT">
<div class="actions">
<button type="submit" class="button">Importieren</button>
</div>
</form>
</div>
</div>
<?php endif; ?>
<script src="<?= e(asset_url('/assets/js/item-picker.js')) ?>"></script>
<script src="<?= e(asset_url('/assets/js/copy-button.js')) ?>"></script>
<script src="<?= e(asset_url('/assets/js/gear.js')) ?>"></script>
<?php if ($set && isset(GEAR_PLAN_SECTIONS[$tab])): ?><script src="<?= e(asset_url('/assets/js/gear-plans.js')) ?>"></script><?php endif; ?>
<?php if ($set && $tab === 'macro'): ?><script src="<?= e(asset_url('/assets/js/gear-macro.js')) ?>"></script><?php endif; ?>
<?php include __DIR__ . '/includes/footer.php'; ?>