OpenNIT

Quelltext des aktuellen Standes

Fassung 1.1.1

loans.php

6 KB
<?php $this->layout('layouts/portal', [
    'page_title' => 'Leihgeräte',
    'ssp_active' => 'loans',
]);
$du = ($portal_address ?? 'du') !== 'sie';

$statusLabels = [
    'pending'  => $this->te('Angefragt'),
    'reserved' => $this->te('Reserviert'),
    'active'   => $this->te('Ausgeliehen'),
];
$statusPill = [
    'pending'  => 'status-pill--warning',
    'reserved' => 'status-pill--info',
    'active'   => 'status-pill--success',
];

$maxAdvance  = (int)($rules['max_advance_days']  ?? 90);
$maxDuration = (int)($rules['max_duration_days'] ?? 14);
$needsOk     = !empty($rules['require_approval']);
?>
<div class="ssp-hello">
    <h1><?= $this->te('Leihgeräte') ?></h1>
    <p><?= $needsOk
        ? ($du
            ? $this->te('Hier fragst du ein Leihgerät an – die IT gibt die Anfrage frei.')
            : $this->te('Hier fragen Sie ein Leihgerät an – die IT gibt die Anfrage frei.'))
        : ($du
            ? $this->te('Hier reservierst du ein Leihgerät direkt für deinen Wunschzeitraum.')
            : $this->te('Hier reservieren Sie ein Leihgerät direkt für Ihren Wunschzeitraum.')) ?></p>
</div>

<?php if (!empty($my_loans)): ?>
<h2 class="ssp-section-title"><?= $du ? $this->te('Deine Vorgänge') : $this->te('Ihre Vorgänge') ?></h2>
<div class="ssp-list">
    <?php foreach ($my_loans as $l):
        $st = (string)$l['status'];
        $cancelable = in_array($st, ['pending', 'reserved'], true);
    ?>
    <div class="ssp-ticket">
        <span class="ssp-ticket-icon"><i class="fas fa-hand-holding" aria-hidden="true"></i></span>
        <span class="ssp-ticket-main">
            <span class="ssp-ticket-subject"><?= $this->e($l['title']) ?></span>
            <span class="ssp-ticket-meta">
                <?= $l['type'] ? $this->e($l['type']) . ' · ' : '' ?>
                <?= date('d.m.Y', strtotime((string)$l['planned_start'])) ?>
                &ndash; <?= date('d.m.Y', strtotime((string)$l['planned_end'])) ?>
            </span>
        </span>
        <span class="status-pill <?= $statusPill[$st] ?? 'status-pill--neutral' ?>">
            <?= $this->e($statusLabels[$st] ?? $st) ?>
        </span>
        <?php if ($cancelable): ?>
        <form method="POST" action="/portal/leihvorgang/<?= (int)$l['id'] ?>/stornieren" style="margin:0;"
              onsubmit="return confirm('<?= $du ? $this->te('Diesen Vorgang wirklich stornieren?') : $this->te('Diesen Vorgang wirklich stornieren?') ?>');">
            <input type="hidden" name="_csrf" value="<?= $this->csrf() ?>">
            <button type="submit" class="btn btn-sm btn-default">
                <i class="fas fa-times" aria-hidden="true"></i> <?= $this->te('Stornieren') ?>
            </button>
        </form>
        <?php endif; ?>
    </div>
    <?php endforeach; ?>
</div>
<?php endif; ?>

<h2 class="ssp-section-title"><?= $du ? $this->te('Verfügbare Geräte') : $this->te('Verfügbare Geräte') ?></h2>

<form method="GET" action="/portal/leihgeraete" class="ssp-filter">
    <input type="search" name="q" value="<?= $this->e($q ?? '') ?>"
           placeholder="<?= $du ? $this->te('Gerät suchen …') : $this->te('Gerät suchen …') ?>" aria-label="<?= $this->te('Gerät suchen') ?>">
    <?php if (!empty($types)): ?>
    <select name="type" aria-label="<?= $this->te('Geräteart') ?>">
        <option value=""><?= $this->te('Alle Arten') ?></option>
        <?php foreach ($types as $t): ?>
        <option value="<?= $this->e($t) ?>"<?= ($type ?? '') === $t ? ' selected' : '' ?>><?= $this->e($t) ?></option>
        <?php endforeach; ?>
    </select>
    <?php endif; ?>
    <button type="submit" class="btn btn-sm btn-primary"><i class="fas fa-search" aria-hidden="true"></i> <?= $this->te('Suchen') ?></button>
    <?php if (($q ?? '') !== '' || ($type ?? '') !== ''): ?>
    <a href="/portal/leihgeraete" class="btn btn-sm btn-default"><?= $this->te('Zurücksetzen') ?></a>
    <?php endif; ?>
</form>

<?php if (empty($devices)): ?>
<div class="ssp-empty">
    <i class="fas fa-hand-holding" aria-hidden="true"></i>
    <p><?= $this->te('Derzeit stehen keine Leihgeräte zur Verfügung.') ?></p>
</div>
<?php else: ?>
<div class="ssp-list">
    <?php foreach ($devices as $d):
        $meta = array_filter([
            trim((string)($d['type'] ?? '')) !== '' ? $this->e($d['type']) : null,
            !empty($d['serial_number']) ? 'S/N ' . $this->e($d['serial_number']) : null,
        ]);
    ?>
    <a class="ssp-ticket ssp-ticket--link" href="/portal/leihgeraete/<?= (int)$d['id'] ?>">
        <span class="ssp-ticket-icon"><i class="fas fa-hand-holding" aria-hidden="true"></i></span>
        <span class="ssp-ticket-main">
            <span class="ssp-ticket-subject"><?= $this->e($d['title']) ?></span>
            <span class="ssp-ticket-meta"><?= implode(' · ', $meta) ?></span>
        </span>
        <span class="btn btn-sm btn-primary">
            <i class="fas fa-calendar-check" aria-hidden="true"></i>
            <?= $needsOk ? 'Anfragen' : 'Reservieren' ?>
        </span>
    </a>
    <?php endforeach; ?>
</div>
<?php endif; ?>

<p class="ssp-hint">
    <?= $du
        ? 'Buchbar bis zu ' . $maxAdvance . ' Tage im Voraus, maximal ' . $maxDuration . ' Tage am Stück.'
        : 'Buchbar bis zu ' . $maxAdvance . ' Tage im Voraus, maximal ' . $maxDuration . ' Tage am Stück.' ?>
</p>

<style>
.ssp-section-title { font-size:1rem; font-weight:700; margin:1.25rem 0 .5rem; }
.ssp-filter { display:flex; gap:.5rem; flex-wrap:wrap; align-items:center; margin-bottom:.75rem; }
.ssp-filter input[type="search"], .ssp-filter select {
    padding:.45rem .6rem; border:1px solid var(--gray-300); border-radius:.4rem;
    font-size:.9rem; background:var(--color-bg); color:var(--gray-900); min-width:180px;
}
.ssp-ticket--link { text-decoration:none; color:inherit; }
.ssp-hint { font-size:.8rem; color:var(--gray-500); margin-top:1rem; }
</style>