drink-it-cold/views/admin_trailers.php

160 lines
9.1 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
/** @var array $rows */
/** @var array $errors */
/** @var array $createErrors */
/** @var array $createValues */
$fieldError = static fn (int $id): string => (string) ($errors['trailer_' . $id] ?? '');
$createError = static fn (string $key): string => (string) ($createErrors[$key] ?? '');
?>
<div class="page-head page-head--compact">
<div>
<p class="eyebrow">Verwaltung</p>
<h1>Kühlanhänger</h1>
<p class="page-head__lede">Anhänger anlegen und pflegen. Jeder Anhänger hat seine eigene Farbe im Kalender; weitere Anhänger erscheinen automatisch als zusätzliche Zeile.</p>
</div>
</div>
<?php require __DIR__ . '/_admin_nav.php'; ?>
<?php if ($errors): ?>
<div class="alert alert--error" role="alert">
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
<div><strong>Bitte die markierten Anhänger prüfen.</strong>
<?php foreach ($errors as $message): ?><p><?= e($message) ?></p><?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<details class="card create-trailer"<?= $createErrors ? ' open' : '' ?>>
<summary class="create-trailer__summary">
<span class="create-trailer__title">
<svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg>
Anhänger anlegen
</span>
<span class="create-trailer__hint">Nur bei Bedarf – z. B. für einen zusätzlichen Mietanhänger.</span>
<svg class="ico create-trailer__chevron" aria-hidden="true"><use href="#i-right"/></svg>
</summary>
<div class="create-trailer__body">
<p class="muted small">Neue Anhänger stehen sofort im Kalender und in der Buchungsmaske zur Auswahl. Die Sortierung bestimmt die Reihenfolge der Zeilen.</p>
<?php if ($createErrors): ?>
<div class="alert alert--error" role="alert" style="margin-top: 14px">
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
<div><strong>Bitte die markierten Felder prüfen.</strong>
<?php foreach ($createErrors as $message): ?><p><?= e($message) ?></p><?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<form method="post" action="<?= e(url('/admin/trailers')) ?>" class="form-grid" data-color-row>
<?= csrf_field() ?>
<input type="hidden" name="action" value="create">
<label class="field<?= $createError('label') !== '' ? ' has-error' : '' ?>">
<span>Bezeichnung</span>
<input type="text" name="label" value="<?= e($createValues['label']) ?>" maxlength="40" required placeholder="z. B. Nr. 9">
<?php if ($createError('label')): ?><em class="field-error"><?= e($createError('label')) ?></em><?php endif; ?>
</label>
<label class="field<?= $createError('color_name') !== '' ? ' has-error' : '' ?>">
<span>Farbname</span>
<input type="text" name="color_name" value="<?= e($createValues['color_name']) ?>" maxlength="40" required placeholder="z. B. Türkis">
<?php if ($createError('color_name')): ?><em class="field-error"><?= e($createError('color_name')) ?></em><?php endif; ?>
</label>
<div class="field<?= $createError('color_hex') !== '' ? ' has-error' : '' ?>">
<span>Farbe</span>
<span class="trailer-admin__color">
<input type="color" value="<?= e($createValues['color_hex']) ?>" data-color-sync aria-label="Farbe für den neuen Anhänger">
<input type="text" name="color_hex" value="<?= e($createValues['color_hex']) ?>" maxlength="7" pattern="#[0-9a-fA-F]{6}" class="color-hex" data-color-text aria-label="Farbe als Hex-Wert">
</span>
<span class="trailer-admin__preview" data-color-preview style="--trailer: <?= e($createValues['color_hex']) ?>; --trailer-text: <?= e(contrast_color($createValues['color_hex'])) ?>">
<span class="trailer-dot" style="--trailer: <?= e($createValues['color_hex']) ?>"></span>
<span data-color-preview-label><?= e($createValues['label'] ?: 'Neuer Anhänger') ?></span>
</span>
<?php if ($createError('color_hex')): ?><em class="field-error"><?= e($createError('color_hex')) ?></em><?php endif; ?>
</div>
<label class="field">
<span>Sortierung</span>
<input type="number" name="sort_order" value="<?= (int) $createValues['sort_order'] ?>" step="10">
</label>
<div class="field">
<span>Status</span>
<label class="check check--boxed">
<input type="hidden" name="active" value="0">
<input type="checkbox" name="active" value="1"<?= (int) $createValues['active'] === 1 ? ' checked' : '' ?>>
<span>Anhänger ist aktiv</span>
</label>
</div>
<div class="field field--wide">
<button class="btn primary" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Anhänger anlegen</button>
</div>
</form>
</div>
</details>
<form method="post" action="<?= e(url('/admin/trailers')) ?>" class="panel" style="margin-top: 16px">
<?= csrf_field() ?>
<input type="hidden" name="action" value="update">
<div class="panel__head">
<div>
<h2>Anhänger &amp; Farben</h2>
<p>Inaktive Anhänger erscheinen nicht in der Buchungsmaske; historische Buchungen bleiben erhalten.</p>
</div>
<button class="btn primary" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> Speichern</button>
</div>
<div class="trailer-admin">
<div class="trailer-admin__head" aria-hidden="true">
<span>Farbe</span>
<span>Bezeichnung</span>
<span>Farbname</span>
<span>Sortierung</span>
<span>Aktiv</span>
<span>Vorschau</span>
<span>Aktion</span>
</div>
<?php foreach ($rows as $row): ?>
<?php $id = (int) $row['id']; ?>
<div class="trailer-admin__row<?= $fieldError($id) !== '' ? ' has-error' : '' ?>" data-color-row>
<span class="trailer-admin__color">
<input type="color" value="<?= e($row['color_hex']) ?>" data-color-sync aria-label="Farbe für <?= e($row['label']) ?>">
<input type="text" name="color_hex[<?= $id ?>]" value="<?= e($row['color_hex']) ?>" maxlength="7" pattern="#[0-9a-fA-F]{6}" class="color-hex" data-color-text aria-label="Farbe als Hex-Wert">
</span>
<input type="text" name="label[<?= $id ?>]" value="<?= e($row['label']) ?>" maxlength="40" required aria-label="Bezeichnung">
<input type="text" name="color_name[<?= $id ?>]" value="<?= e($row['color_name']) ?>" maxlength="40" required aria-label="Farbname">
<input type="number" name="sort_order[<?= $id ?>]" value="<?= (int) $row['sort_order'] ?>" step="10" aria-label="Sortierung">
<label class="check trailer-admin__active">
<input type="hidden" name="active[<?= $id ?>]" value="0">
<input type="checkbox" name="active[<?= $id ?>]" value="1"<?= (int) $row['active'] === 1 ? ' checked' : '' ?>>
<span class="sr-only"><?= e($row['label']) ?> ist aktiv</span>
</label>
<span class="trailer-admin__preview" data-color-preview style="--trailer: <?= e($row['color_hex']) ?>; --trailer-text: <?= e(contrast_color($row['color_hex'])) ?>">
<span class="trailer-dot" style="--trailer: <?= e($row['color_hex']) ?>"></span>
<?= e($row['label']) ?>
</span>
<?php if ((int) $row['booking_count'] === 0): ?>
<button class="link-button small" type="submit" form="delete-trailer-<?= $id ?>"><svg class="ico" aria-hidden="true"><use href="#i-trash"/></svg> Löschen</button>
<?php else: ?>
<span class="muted small" title="<?= (int) $row['booking_count'] ?> Buchung(en) verweisen auf diesen Anhänger"><?= (int) $row['booking_count'] ?> Buchung<?= (int) $row['booking_count'] === 1 ? '' : 'en' ?></span>
<?php endif; ?>
<?php if ($fieldError($id)): ?><em class="field-error"><?= e($fieldError($id)) ?></em><?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<p class="muted small">Hinweis: Die Farbe wird bei allen Buchungen dieses Anhängers sofort übernommen. Der Buchungstext selbst bleibt unverändert.</p>
</form>
<?php foreach ($rows as $row): ?>
<?php if ((int) $row['booking_count'] === 0): ?>
<form id="delete-trailer-<?= (int) $row['id'] ?>" method="post" action="<?= e(url('/admin/trailers')) ?>" data-confirm="Anhänger <?= e($row['label']) ?> endgültig löschen?">
<?= csrf_field() ?>
<input type="hidden" name="action" value="delete">
<input type="hidden" name="id" value="<?= (int) $row['id'] ?>">
</form>
<?php endif; ?>
<?php endforeach; ?>