motorradig2027/views/tour/show.php
2026-10-09 09:07:18 +02:00

179 lines
8.9 KiB
PHP

<?php
use App\Models\Tour;
$current = auth_check() ? user() : null;
$groups = [];
foreach ($rooms as $room) {
$key = ($room->room_id === null || $room->room_id === '') ? 'ungebucht' : (string) $room->room_id;
if (!isset($groups[$key])) {
$groups[$key] = [
'name' => $room->room_name,
'id' => $room->room_id,
'free_slots' => $room->free_slots,
'users' => [],
];
}
$groups[$key]['users'][] = $room;
}
?>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8 mt-2">
<div class="card mt-4">
<div class="card-header"><h5><?= e($tour->name) ?></h5></div>
<div class="card-body">
<form style="background-color: #fff;" class="text-dark" method="post" action="" enctype="multipart/form-data">
<?= csrf_field() ?>
<div class="" style="display:flex;">
<label class="ml-2" style="width:180px; text-align:left;font-size:18px;" for="name">Name:</label>
<input class="mr-1 form-control" type="text" id="name" name="name"
value="<?= e(old('name') ?? $tour->name) ?>" readonly>
</div>
<div class="mt-1" style="display:flex;">
<label class="ml-2" style="width:180px; text-align:left;font-size:18px;" for="start">Start:</label>
<input class="mr-1 form-control" type="text" id="start" name="start"
value="<?= e(old('start') ?? $tour->start) ?>" readonly>
</div>
<div class="mt-1" style="display:flex;">
<label class="ml-2" style="width:180px; text-align:left;font-size:18px;" for="creator">Ansprechpartner:</label>
<input class="mr-1 form-control" type="text" id="creator" name="creator"
value="<?= e($creator ? $creator->name : '') ?>" readonly>
</div>
<div class="mt-1" style="display:flex;">
<label class="ml-2" style="width:180px; text-align:left;font-size:18px;" for="anmeldeschluss">Anmeldeschluss:</label>
<input class="mr-1 form-control" type="text" id="anmeldeschluss" style="font-size:16px;"
name="deadline" value="<?= e(old('anmeldeschluss') ?? $tour->deadline) ?>" readonly>
</div>
<div class="mt-1" style="display:flex;">
<label class="ml-2" style="width:180px; text-align:left;font-size:18px;" for="max_participants">Max Teilnehmer:</label>
<input class="mr-1 form-control" type="text" id="max_participants"
style="font-size:16px;" name="max_participants"
value="<?= e(old('max_participants') ?? $tour->max_participants) ?>" readonly>
</div>
<?php if ($current && Tour::hasParticipant((int) $tour->id, (int) $current->id)): ?>
<label>Du nimmst teil.</label>
<?php else: ?>
<label>Du nimmst nicht teil.</label>
<?php endif; ?>
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3">
<div class="mt-1" style="display:flex;">
<label class="ml-2" style="width:140px; text-align:left;font-size:18px;" for="is_cancelled">Storniert:</label>
<input class="mr-1 form-control" type="checkbox" id="is_cancelled"
style="font-size:10px;width:20px;" name="is_cancelled"
<?= $tour->is_cancelled ? 'checked' : '' ?> onclick="return false;">
</div>
<div class="mt-1">
<textarea class="col-12" name="beschreibung" rows="10" cols="50" readonly><?= e($tour->beschreibung) ?></textarea>
</div>
<?php if ($current && $current->isAdmin()): ?>
<a href="/tour/<?= e($tour->id) ?>/edit">
<div type="submit" class="btn btn-danger col-3 mb-2 float-left mr-2">Bearbeiten</div>
</a>
<?php endif; ?>
<a href="/tour" type="submit" class="btn btn-success col-3 mb-2 float-right mr-2">Ok</a>
<?php if ($current && !Tour::hasParticipant((int) $tour->id, (int) $current->id) && Tour::hasSpace((int) $tour->id)): ?>
<button id="myBtn" class="btn btn-danger float-left">Teilnehmen</button>
<?php endif; ?>
<?php if ($current && Tour::hasParticipant((int) $tour->id, (int) $current->id)): ?>
<a href="/tour/<?= e($tour->id) ?>/cancelBooking" type="submit"
class="btn btn-danger col-3 mb-2 float-right mr-2">Absagen</a>
<?php endif; ?>
</form>
<!-- Modal: Zimmer auswählen -->
<div id="myModal" class="modal">
<div class="modal-content">
<span class="close">&times;</span>
<h2>Bitte Zimmer auswählen</h2>
<div class="card-body">
<ul>
<?php $first = true; ?>
<?php foreach ($groups as $key => $group): ?>
<?php if ($key !== 'ungebucht' && $group['free_slots'] > 0): ?>
<?php if (!$first): ?><hr/><?php endif; ?>
<p style="list-style-type: none;">[<?= e($group['id']) ?>]
<span><?= e($group['name']) ?></span>
<b><a href="/tour/<?= e($tour->id) ?>/join/<?= e($group['id']) ?>">
==> Buchen</a></b>
</p>
<?php $first = false; ?>
<?php foreach ($group['users'] as $room): ?>
<?php if ($room->user_name): ?>
<li> <?= e($room->user_name) ?></li>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-3 mt-2">
<div class="card mt-4">
<div class="card-header"><h5>Teilnehmer</h5></div>
<div class="card-body">
<?php foreach ($groups as $key => $group): ?>
<div style="border:solid;border-width:1px;">
<div style="text-align:center;"><b><?= e($group['name']) ?>
<?php if ($key !== 'ungebucht'): ?>_<?= e($group['id']) ?><?php endif; ?></b>
</div>
<?php foreach ($group['users'] as $room): ?>
<?php if ($room->user_name): ?>
<div style="list-style:none"> &nbsp; <?= e($room->user_name) ?></div>
<?php endif; ?>
<?php endforeach; ?>
</div>
<div style="height:2px;"></div>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
</div>
<script>
var modal = document.getElementById("myModal");
var btn = document.getElementById("myBtn");
var span = document.getElementsByClassName("close")[0];
if (btn) {
btn.onclick = function (e) {
e.preventDefault();
modal.style.display = "block";
}
}
if (span) {
span.onclick = function (e) {
e.preventDefault();
modal.style.display = "none";
}
}
window.onclick = function (event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>