Buchungen anlegen nur für Administratoren

This commit is contained in:
torsten 2026-11-19 10:48:32 +01:00
parent c8ec53ebdd
commit 6a2a9ea342
8 changed files with 67 additions and 32 deletions

View file

@ -6,7 +6,9 @@
/** @var array $groups */
/** @var int $freeCount */
/** @var int $total */
/** @var array $user */
$fieldError = static fn (string $key): string => (string) ($errors[$key] ?? '');
$canCreate = ($user['role'] ?? '') === 'admin';
$bookingUrl = static fn (array $trailer): string => '/bookings/new?trailer=' . (int) $trailer['id']
. '&start=' . rawurlencode($from) . '&end=' . rawurlencode($to);
$groupMeta = [
@ -69,9 +71,11 @@ $groupMeta = [
<h2>Ergebnis</h2>
<p><?= e(fmt_date_range($from, $to)) ?> · <?= (int) $freeCount ?> von <?= (int) $total ?> frei</p>
</div>
<a class="btn small" href="<?= e(url('/bookings/new?start=' . rawurlencode($from) . '&end=' . rawurlencode($to))) ?>">
<svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Neue Buchung
</a>
<?php if ($canCreate): ?>
<a class="btn small" href="<?= e(url('/bookings/new?start=' . rawurlencode($from) . '&end=' . rawurlencode($to))) ?>">
<svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Neue Buchung
</a>
<?php endif; ?>
</div>
<div class="availability-grid">
@ -98,7 +102,9 @@ $groupMeta = [
<?= e($trailer['label']) ?>
</span>
</span>
<a class="btn small primary" href="<?= e(url($bookingUrl($trailer))) ?>">Buchen</a>
<?php if ($canCreate): ?>
<a class="btn small primary" href="<?= e(url($bookingUrl($trailer))) ?>">Buchen</a>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>

View file

@ -171,7 +171,9 @@ $returnTo = '/bookings/' . (int) $booking['id'];
<h2>Aktionen</h2>
<div class="stack-actions">
<a class="btn btn--block" href="<?= e(url($returnTo . '/edit')) ?>"><svg class="ico" aria-hidden="true"><use href="#i-edit"/></svg> Buchung bearbeiten</a>
<a class="btn btn--block" href="<?= e(url('/bookings/new?trailer=' . (int) $booking['trailer_id'] . '&start=' . $booking['end_date'])) ?>"><svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Anschlussbuchung anlegen</a>
<?php if ($isAdmin): ?>
<a class="btn btn--block" href="<?= e(url('/bookings/new?trailer=' . (int) $booking['trailer_id'] . '&start=' . $booking['end_date'])) ?>"><svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Anschlussbuchung anlegen</a>
<?php endif; ?>
<?php if ($canDelete): ?>
<form method="post" action="<?= e(url($returnTo . '/delete')) ?>" data-confirm="Buchung endgültig löschen? Das kann nicht rückgängig gemacht werden.">
<?= csrf_field() ?>

View file

@ -14,6 +14,8 @@
/** @var array $employees */
/** @var int $bookingCount */
/** @var callable $urlFor */
/** @var array $user */
$canCreate = ($user['role'] ?? '') === 'admin';
$cols = count($days);
$laneWidth = 150;
$minWidth = match ($view) {
@ -27,11 +29,13 @@ $minWidth = match ($view) {
<p class="eyebrow">Kalender · <?= $bookingCount ?> Buchung<?= $bookingCount === 1 ? '' : 'en' ?> im Zeitraum</p>
<h1><?= e($calTitle) ?></h1>
</div>
<div class="page-head__actions">
<a class="btn primary" href="<?= e(url('/bookings/new?start=' . $date)) ?>">
<svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Neue Buchung
</a>
</div>
<?php if ($canCreate): ?>
<div class="page-head__actions">
<a class="btn primary" href="<?= e(url('/bookings/new?start=' . $date)) ?>">
<svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Neue Buchung
</a>
</div>
<?php endif; ?>
</div>
<div class="cal-toolbar">
@ -108,16 +112,24 @@ $minWidth = match ($view) {
<strong><?= e($trailer['label']) ?></strong>
<?php if ((int) $trailer['active'] !== 1): ?><small>inaktiv</small><?php endif; ?>
</span>
<a class="cal-label__add" href="<?= e(url('/bookings/new?trailer=' . (int) $trailer['id'] . '&start=' . $date)) ?>" aria-label="Neue Buchung für <?= e($trailer['label']) ?>">+</a>
<?php if ($canCreate): ?>
<a class="cal-label__add" href="<?= e(url('/bookings/new?trailer=' . (int) $trailer['id'] . '&start=' . $date)) ?>" aria-label="Neue Buchung für <?= e($trailer['label']) ?>">+</a>
<?php endif; ?>
</div>
<div class="cal-track" style="--row-h: <?= (int) $row['height'] ?>px; --lanes: <?= (int) $row['lanes'] ?>" data-trailer-id="<?= (int) $trailer['id'] ?>">
<div class="cal-cells">
<?php foreach ($days as $day): ?>
<a class="cal-cell<?= $day['is_today'] ? ' is-today' : '' ?><?= $day['is_weekend'] ? ' is-weekend' : '' ?>"
href="<?= e(url('/bookings/new?trailer=' . (int) $trailer['id'] . '&start=' . $day['iso'] . '&end=' . $day['iso'])) ?>"
data-cell="1"
data-date="<?= e($day['iso']) ?>"
aria-label="Neue Buchung <?= e($trailer['label']) ?> am <?= e(fmt_date($day['iso'])) ?>"></a>
<?php if ($canCreate): ?>
<a class="cal-cell<?= $day['is_today'] ? ' is-today' : '' ?><?= $day['is_weekend'] ? ' is-weekend' : '' ?>"
href="<?= e(url('/bookings/new?trailer=' . (int) $trailer['id'] . '&start=' . $day['iso'] . '&end=' . $day['iso'])) ?>"
data-cell="1"
data-date="<?= e($day['iso']) ?>"
aria-label="Neue Buchung <?= e($trailer['label']) ?> am <?= e(fmt_date($day['iso'])) ?>"></a>
<?php else: ?>
<span class="cal-cell<?= $day['is_today'] ? ' is-today' : '' ?><?= $day['is_weekend'] ? ' is-weekend' : '' ?>"
data-cell="1"
data-date="<?= e($day['iso']) ?>"></span>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php foreach ($row['bars'] as $bar): ?>

View file

@ -7,6 +7,8 @@
/** @var int $openReminderCount */
/** @var int $handoverCount */
/** @var int $employeeScope */
/** @var array $user */
$canCreate = ($user['role'] ?? '') === 'admin';
$rentedTrailers = 0;
$rentedChests = 0;
$freeTrailers = 0;
@ -44,9 +46,11 @@ $isEmployeeView = $employeeScope > 0;
<a class="btn" href="<?= e(url('/availability')) ?>">
<svg class="ico" aria-hidden="true"><use href="#i-search"/></svg> Verfügbarkeit
</a>
<a class="btn primary" href="<?= e(url('/bookings/new')) ?>">
<svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Neue Buchung
</a>
<?php if ($canCreate): ?>
<a class="btn primary" href="<?= e(url('/bookings/new')) ?>">
<svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Neue Buchung
</a>
<?php endif; ?>
</div>
</div>
@ -140,7 +144,9 @@ $isEmployeeView = $employeeScope > 0;
<svg class="ico" aria-hidden="true"><use href="#i-calendar"/></svg>
<h3>Keine Übergaben in den nächsten zwei Wochen</h3>
<p>Neue Buchungen erscheinen hier automatisch mit Übergabe- und Rücknahmetermin.</p>
<a class="btn primary" href="<?= e(url('/bookings/new')) ?>">Buchung anlegen</a>
<?php if ($canCreate): ?>
<a class="btn primary" href="<?= e(url('/bookings/new')) ?>">Buchung anlegen</a>
<?php endif; ?>
</div>
<?php else: ?>
<ul class="event-list">
@ -217,11 +223,13 @@ $isEmployeeView = $employeeScope > 0;
<section class="panel panel--quick">
<h2>Kurz zugreifen</h2>
<a class="quick-link" href="<?= e(url('/bookings/new')) ?>">
<span class="quick-link__icon"><svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg></span>
<span><strong>Neue Buchung</strong><small>Zeitraum und Kunde erfassen</small></span>
<svg class="ico chev" aria-hidden="true"><use href="#i-right"/></svg>
</a>
<?php if ($canCreate): ?>
<a class="quick-link" href="<?= e(url('/bookings/new')) ?>">
<span class="quick-link__icon"><svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg></span>
<span><strong>Neue Buchung</strong><small>Zeitraum und Kunde erfassen</small></span>
<svg class="ico chev" aria-hidden="true"><use href="#i-right"/></svg>
</a>
<?php endif; ?>
<a class="quick-link" href="<?= e(url('/search')) ?>">
<span class="quick-link__icon"><svg class="ico" aria-hidden="true"><use href="#i-search"/></svg></span>
<span><strong>Kunde suchen</strong><small>Buchung nach Name finden</small></span>

View file

@ -80,7 +80,9 @@ foreach ($rows as $row) {
<svg class="ico" aria-hidden="true"><use href="#i-check"/></svg>
<h3>Keine offenen Erinnerungen</h3>
<p>Für den gewählten Zeitraum ist alles erledigt. Neue Erinnerungen entstehen automatisch, sobald eine Buchung angelegt wird.</p>
<a class="btn primary" href="<?= e(url('/bookings/new')) ?>">Neue Buchung anlegen</a>
<?php if ($isAdmin): ?>
<a class="btn primary" href="<?= e(url('/bookings/new')) ?>">Neue Buchung anlegen</a>
<?php endif; ?>
</div>
<?php else: ?>
<p class="list-summary"><?= $openCount ?> offene Erinnerung<?= $openCount === 1 ? '' : 'en' ?><?= $isAdmin ? '' : ' für Sie' ?><?= $employeeFilter > 0 ? ' · ' . e(employees_map()[$employeeFilter]['name'] ?? '') : '' ?></p>