drink-it-cold/views/admin_employees.php
2026-11-13 01:33:10 +01:00

110 lines
5.8 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|null $editing */
/** @var int $editId */
/** @var array $values */
/** @var array $errors */
$fieldError = static fn (string $key): string => (string) ($errors[$key] ?? '');
?>
<div class="page-head page-head--compact">
<div>
<p class="eyebrow">Verwaltung</p>
<h1>Mitarbeiter</h1>
<p class="page-head__lede">Jede Buchung bekommt einen zuständigen Mitarbeiter. Erinnerungen gehen an diese Zuordnung.</p>
</div>
</div>
<?php require __DIR__ . '/_admin_nav.php'; ?>
<div class="admin-split">
<section class="card">
<div class="card__head">
<h2><?= $editing ? 'Mitarbeiter bearbeiten' : 'Mitarbeiter anlegen' ?></h2>
<p><?= $editing ? 'Name, Reihenfolge und Status anpassen.' : 'Neue Mitarbeiter stehen sofort in der Buchungsmaske zur Auswahl.' ?></p>
</div>
<?php if ($errors): ?>
<div class="alert alert--error" role="alert">
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
<div><strong>Bitte prüfen.</strong>
<?php if ($fieldError('name')): ?><p><?= e($fieldError('name')) ?></p><?php endif; ?>
<?php if ($fieldError('active')): ?><p><?= e($fieldError('active')) ?></p><?php endif; ?>
</div>
</div>
<?php endif; ?>
<form method="post" action="<?= e(url('/admin/employees' . ($editing ? '?edit=' . (int) $editing['id'] : ''))) ?>" class="stack">
<?= csrf_field() ?>
<input type="hidden" name="action" value="<?= $editing ? 'update' : 'create' ?>">
<?php if ($editing): ?><input type="hidden" name="id" value="<?= (int) $editing['id'] ?>"><?php endif; ?>
<label class="field<?= $fieldError('name') !== '' ? ' has-error' : '' ?>">
<span>Name (wie im Kalender)</span>
<input type="text" name="name" value="<?= e($values['name']) ?>" maxlength="100" required placeholder="z. B. M. Krücken">
<?php if ($fieldError('name')): ?><em class="field-error"><?= e($fieldError('name')) ?></em><?php endif; ?>
</label>
<label class="field">
<span>Sortierung</span>
<input type="number" name="sort_order" value="<?= (int) $values['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) $values['active'] === 1 ? ' checked' : '' ?>>
<span>Mitarbeiter ist aktiv</span>
</label>
</div>
<div class="form-actions">
<button class="btn primary" type="submit"><?= $editing ? 'Speichern' : 'Mitarbeiter anlegen' ?></button>
<?php if ($editing): ?><a class="btn" href="<?= e(url('/admin/employees')) ?>">Abbrechen</a><?php endif; ?>
</div>
</form>
</section>
<section class="panel">
<div class="panel__head">
<div>
<h2>Team</h2>
<p>Buchungen bleiben auch bei Namensänderungen erhalten.</p>
</div>
</div>
<div class="table-wrap">
<table class="data-table">
<thead>
<tr>
<th>Name</th>
<th>Benutzerkonto</th>
<th>Kommende Buchungen</th>
<th>Status</th>
<th class="ta-right">Aktion</th>
</tr>
</thead>
<tbody>
<?php foreach ($rows as $row): ?>
<tr>
<td><strong><?= e($row['name']) ?></strong></td>
<td><?= e($row['first_name'] ? $row['first_name'] . ' ' . $row['last_name'] : '–') ?></td>
<td><?= (int) $row['future_bookings'] ?></td>
<td><span class="pill <?= (int) $row['active'] === 1 ? 'pill--green' : 'pill--grey' ?>"><?= (int) $row['active'] === 1 ? 'aktiv' : 'inaktiv' ?></span></td>
<td class="ta-right">
<div class="table-actions">
<a class="btn small" href="<?= e(url('/admin/employees?edit=' . (int) $row['id'])) ?>">Bearbeiten</a>
<?php if ((int) $row['booking_count'] === 0): ?>
<form method="post" action="<?= e(url('/admin/employees')) ?>" data-confirm="Mitarbeiter <?= e($row['name']) ?> endgültig löschen?">
<?= csrf_field() ?>
<input type="hidden" name="action" value="delete">
<input type="hidden" name="id" value="<?= (int) $row['id'] ?>">
<button class="link-button small" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-trash"/></svg> Löschen</button>
</form>
<?php else: ?>
<span class="muted small" title="<?= (int) $row['booking_count'] ?> Buchung(en) verweisen auf diesen Mitarbeiter"><?= (int) $row['booking_count'] ?> Buchung<?= (int) $row['booking_count'] === 1 ? '' : 'en' ?></span>
<?php endif; ?>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</section>
</div>