99 lines
5 KiB
PHP
99 lines
5 KiB
PHP
<?php
|
||
/**
|
||
* Selektor-Schirm: Ausrüstung aus dem Katalog ins Inventar übernehmen.
|
||
*
|
||
* Wird aus views/character_edit.php eingebunden; erwartet $base, $character,
|
||
* $itemCatalog, $itemCatalogCount, $itemFilters und $itemSelectorOpen.
|
||
*
|
||
* Gefiltert wird serverseitig über GET-Parameter (item_kind/item_avail/item_q),
|
||
* damit der Katalog auch mit hunderten Einträgen ohne JavaScript bedienbar
|
||
* bleibt. Die Auswahl selbst ist ein POST auf /characters/{id}/items/from-catalog.
|
||
*
|
||
* @var string $base
|
||
* @var array $character
|
||
* @var list<array<string,mixed>> $itemCatalog
|
||
* @var int $itemCatalogCount
|
||
* @var array{kind:string,availability:string,needle:string} $itemFilters
|
||
* @var bool $itemSelectorOpen
|
||
*/
|
||
$availabilityShort = ['methaven' => 'Methaven', 'garana' => 'Garana', 'selten' => 'selten'];
|
||
$filterUrl = $base . '/edit';
|
||
?>
|
||
<dialog class="selector" id="item-selector" aria-labelledby="item-selector-title"<?= $itemSelectorOpen ? ' data-autopen' : '' ?>>
|
||
<div class="selector-head">
|
||
<h2 id="item-selector-title">Ausrüstung aus dem Katalog</h2>
|
||
<button class="btn btn-small" type="button" data-dialog-close>Schließen</button>
|
||
</div>
|
||
<div class="selector-body">
|
||
<form method="get" action="<?= e($filterUrl) ?>" class="selector-filters">
|
||
<label class="field">
|
||
<span>Suche</span>
|
||
<input type="search" name="item_q" value="<?= e($itemFilters['needle']) ?>" placeholder="Name oder Notiz …" autocomplete="off">
|
||
</label>
|
||
<label class="field">
|
||
<span>Art</span>
|
||
<select name="item_kind">
|
||
<option value="">Alle Arten</option>
|
||
<?php foreach (WS_ITEM_CATEGORIES as $category): ?>
|
||
<option value="<?= e($category) ?>"<?= $itemFilters['kind'] === $category ? ' selected' : '' ?>><?= e($category) ?></option>
|
||
<?php endforeach; ?>
|
||
</select>
|
||
</label>
|
||
<label class="field">
|
||
<span>Verfügbarkeit</span>
|
||
<select name="item_avail">
|
||
<option value="">Alle (auch Seltenes)</option>
|
||
<?php foreach (WS_ITEM_AVAILABILITY as $key => $label): ?>
|
||
<option value="<?= e($key) ?>"<?= $itemFilters['availability'] === $key ? ' selected' : '' ?>><?= e($label) ?></option>
|
||
<?php endforeach; ?>
|
||
</select>
|
||
</label>
|
||
<div class="selector-filter-actions">
|
||
<button class="btn btn-small" type="submit">Filtern</button>
|
||
<a class="btn btn-small" href="<?= e($filterUrl . '#inventar') ?>">Zurücksetzen</a>
|
||
</div>
|
||
</form>
|
||
|
||
<p class="selector-hint muted">
|
||
<?= count($itemCatalog) ?> von <?= (int) $itemCatalogCount ?> Gegenständen
|
||
<?php if ((int) $itemCatalogCount > count($itemCatalog)): ?>
|
||
– Suche oder Filter eingrenzen, um mehr zu sehen.
|
||
<?php endif; ?>
|
||
</p>
|
||
<p class="selector-hint muted">
|
||
Verfügbarkeit ist gestaffelt: Garana schließt Methaven ein, „Alle“ zeigt auch das,
|
||
was in keiner der beiden Ortschaften zu kaufen ist. Gewicht in OSE-Münzeinheiten
|
||
(10 Münzen ≈ 1 Pfund).
|
||
</p>
|
||
|
||
<form method="post" action="<?= e($base . '/items/from-catalog') ?>">
|
||
<?= csrf_field() ?>
|
||
<div class="selector-groups">
|
||
<?php $lastKind = ''; ?>
|
||
<?php foreach ($itemCatalog as $entry): ?>
|
||
<?php $kind = (string) $entry['kind']; ?>
|
||
<?php if ($kind !== $lastKind): ?>
|
||
<?php $lastKind = $kind; ?>
|
||
<p class="selector-group"><?= e($kind) ?></p>
|
||
<?php endif; ?>
|
||
<button class="selector-item selector-item-wide" type="submit" name="catalog_id" value="<?= (int) $entry['id'] ?>">
|
||
<span class="selector-item-main"><?= e((string) $entry['name']) ?></span>
|
||
<span class="meta">
|
||
<?= e(item_cost_label($entry['cost'])) ?>
|
||
<?php if (item_weight_label($entry['weight']) !== ''): ?>
|
||
· <?= e(item_weight_label($entry['weight'])) ?>
|
||
<?php endif; ?>
|
||
· <?= e($availabilityShort[(string) $entry['availability']] ?? (string) $entry['availability']) ?>
|
||
<?php if ((string) $entry['note'] !== ''): ?>
|
||
· <em><?= e((string) $entry['note']) ?></em>
|
||
<?php endif; ?>
|
||
</span>
|
||
</button>
|
||
<?php endforeach; ?>
|
||
<?php if ($itemCatalog === []): ?>
|
||
<p class="selector-empty">Kein Gegenstand passt zu Suche und Filtern.</p>
|
||
<?php endif; ?>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</dialog>
|