108 lines
5.6 KiB
PHP
108 lines
5.6 KiB
PHP
<?php
|
||
/**
|
||
* Selektor-Schirm: Ausrüstung aus dem Katalog übernehmen.
|
||
*
|
||
* Wird aus views/character_edit.php eingebunden; erwartet $base, $character und
|
||
* $selector (Konfiguration aus item_selector_config()). Derselbe Schirm dient
|
||
* dem Inventar sowie – fest auf eine Art vorgefiltert – der Bewaffnung und der
|
||
* Rüstung.
|
||
*
|
||
* Gefiltert wird serverseitig über GET-Parameter (<key>_kind/<key>_avail/<key>_q),
|
||
* damit der Katalog auch mit hunderten Einträgen ohne JavaScript bedienbar
|
||
* bleibt. Die Auswahl selbst ist ein POST auf $selector['action'].
|
||
*
|
||
* @var string $base
|
||
* @var array $character
|
||
* @var array{key:string,title:string,action:string,anchor:string,kinds:list<string>|null,filters:array<string,mixed>,catalog:list<array<string,mixed>>,count:int,open:bool} $selector
|
||
*/
|
||
$availabilityShort = ['methaven' => 'Methaven', 'garana' => 'Garana', 'selten' => 'selten'];
|
||
$filterUrl = $base . '/edit';
|
||
$selKey = (string) $selector['key'];
|
||
$selKinds = $selector['kinds'];
|
||
$selFilters = $selector['filters'];
|
||
$selCatalog = $selector['catalog'];
|
||
$selCount = (int) $selector['count'];
|
||
$selAnchor = (string) $selector['anchor'];
|
||
?>
|
||
<dialog class="selector" id="<?= e($selKey) ?>-selector" aria-labelledby="<?= e($selKey) ?>-selector-title"<?= $selector['open'] ? ' data-autopen' : '' ?>>
|
||
<div class="selector-head">
|
||
<h2 id="<?= e($selKey) ?>-selector-title"><?= e((string) $selector['title']) ?></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="<?= e($selKey) ?>_q" value="<?= e($selFilters['needle']) ?>" placeholder="Name oder Notiz …" autocomplete="off">
|
||
</label>
|
||
<label class="field">
|
||
<span>Art</span>
|
||
<?php if ($selKinds === null): ?>
|
||
<select name="<?= e($selKey) ?>_kind">
|
||
<option value="">Alle Arten</option>
|
||
<?php foreach (WS_ITEM_CATEGORIES as $category): ?>
|
||
<option value="<?= e($category) ?>"<?= $selFilters['kind'] === $category ? ' selected' : '' ?>><?= e($category) ?></option>
|
||
<?php endforeach; ?>
|
||
</select>
|
||
<?php else: ?>
|
||
<input type="text" value="<?= e(implode(' + ', $selKinds)) ?>" readonly>
|
||
<?php endif; ?>
|
||
</label>
|
||
<label class="field">
|
||
<span>Verfügbarkeit</span>
|
||
<select name="<?= e($selKey) ?>_avail">
|
||
<option value="">Alle (auch Seltenes)</option>
|
||
<?php foreach (WS_ITEM_AVAILABILITY as $key => $label): ?>
|
||
<option value="<?= e($key) ?>"<?= $selFilters['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 . '#' . $selAnchor) ?>">Zurücksetzen</a>
|
||
</div>
|
||
</form>
|
||
|
||
<p class="selector-hint muted">
|
||
<?= count($selCatalog) ?> von <?= $selCount ?> Gegenständen
|
||
<?php if ($selCount > count($selCatalog)): ?>
|
||
– 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(url($selector['action'])) ?>">
|
||
<?= csrf_field() ?>
|
||
<div class="selector-groups">
|
||
<?php $lastKind = ''; ?>
|
||
<?php foreach ($selCatalog as $entry): ?>
|
||
<?php $kind = (string) $entry['kind']; ?>
|
||
<?php if ($kind !== $lastKind && $selKinds === null): ?>
|
||
<?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 ($selCatalog === []): ?>
|
||
<p class="selector-empty">Kein Gegenstand passt zu Suche und Filtern.</p>
|
||
<?php endif; ?>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</dialog>
|