413 lines
22 KiB
PHP
413 lines
22 KiB
PHP
<?php
|
||
$current = auth_check() ? user() : null;
|
||
$flashStatus = flash_pull('status');
|
||
$flashError = flash_pull('error');
|
||
$canChangeGuide = $current !== null && $current->isAdmin();
|
||
$galleryLightbox = 'tour-bilder-' . $tour->id;
|
||
|
||
// Räume gruppieren, Reihenfolge wie aus der Abfrage
|
||
$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;
|
||
}
|
||
?>
|
||
|
||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vanillajs-datepicker@1.1.2/dist/css/datepicker-bs4.min.css">
|
||
<script src="https://cdn.jsdelivr.net/npm/vanillajs-datepicker@1.1.2/dist/js/datepicker.min.js"></script>
|
||
<script src="https://cdn.jsdelivr.net/npm/vanillajs-datepicker@1.1.2/dist/js/locales/de.js"></script>
|
||
|
||
<div class="container">
|
||
<div class="row justify-content-center">
|
||
<div class="col-md-8">
|
||
<div class="card mt-4">
|
||
<div class="card-header"><?= e($tour->name) ?></div>
|
||
|
||
<div class="card-body">
|
||
<?php if ($flashStatus !== null): ?>
|
||
<div class="alert alert-success" role="alert"><?= e($flashStatus) ?></div>
|
||
<?php endif; ?>
|
||
|
||
<?php if ($flashError !== null): ?>
|
||
<div class="alert alert-danger" role="alert"><?= e($flashError) ?></div>
|
||
<?php endif; ?>
|
||
|
||
<form style="background-color: #fff;" class="text-dark" method="post"
|
||
action="/tour/<?= e($tour->id) ?>" enctype="multipart/form-data">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="_method" value="PUT">
|
||
<input type="hidden" name="tour_id" value="<?= e($tour->id) ?>">
|
||
|
||
<div class="form-group" style="display:flex;">
|
||
<label class="ml-2 mt-3 col-form-label col-form-label-sm" style="width:180px; text-align:left;font-size:18px;" for="name">Name:</label>
|
||
<input class="mt-3 mr-2 form-control input-sm" type="text" id="name" name="name"
|
||
value="<?= e(old('name') ?? $tour->name) ?>" required>
|
||
</div>
|
||
|
||
<div class="form-group" style="display:flex;">
|
||
<label class="ml-2 mt-3" style="width:180px; text-align:left;font-size:18px;" for="tour_guide_id">Tour Guide:</label>
|
||
|
||
<?php if ($canChangeGuide): ?>
|
||
<select class="mt-3 mr-2 form-control input-sm" id="tour_guide_id" name="tour_guide_id" required>
|
||
<?php foreach ($guides as $guide): ?>
|
||
<option value="<?= e($guide->id) ?>"<?= (int) $guide->id === (int) $tour->tour_guide_id ? ' selected' : '' ?>>
|
||
<?= e($guide->name) ?><?= $guide->role === 'ADMIN' ? ' (Admin)' : ($guide->role === 'TOUR GUIDE' ? ' (Tour Guide)' : '') ?>
|
||
</option>
|
||
<?php endforeach; ?>
|
||
</select>
|
||
<?php else: ?>
|
||
<input class="mt-3 mr-2 form-control input-sm" type="text" value="<?= e($tourGuide ? $tourGuide->name : '') ?>" readonly>
|
||
<input type="hidden" name="tour_guide_id" value="<?= e($tour->tour_guide_id) ?>">
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<div class="form-group" style="display:flex;">
|
||
<label class="ml-2 mt-3" style="width:180px; text-align:left;font-size:18px;" for="start">Start:</label>
|
||
<input class="mt-3 mr-2 form-control input-sm" type="text" id="start" name="start"
|
||
value="<?= e($tour->start) ?>" required>
|
||
</div>
|
||
|
||
<div class="form-group" style="display:flex;">
|
||
<label class="ml-2 mt-4" style="width:180px; text-align:left;font-size:18px;" for="deadline">Anmeldeschluss:</label>
|
||
<input class="mt-3 mr-2 form-control" type="text" id="deadline" style="font-size:16px;"
|
||
name="deadline" value="<?= e(old('deadline') ?? $tour->deadline) ?>" required>
|
||
</div>
|
||
|
||
<div class="form-group" style="display:flex;">
|
||
<label class="ml-2 mt-4" style="width:180px; text-align:left;font-size:18px;" for="max_participants">Max Teilnehmer:</label>
|
||
<input class="mt-3 mr-2 form-control" type="number" min="1" max="99" id="max_participants"
|
||
style="font-size:16px;" name="max_participants"
|
||
value="<?= e(old('max_participants') ?? $tour->max_participants) ?>" required>
|
||
</div>
|
||
|
||
<div class="form-group" style="display:flex;">
|
||
<label class="ml-2 mt-3" style="width:140px; text-align:left;font-size:18px;" for="is_cancelled">Storniert:</label>
|
||
<input class="mt-3 mr-2 form-control" type="checkbox" id="is_cancelled"
|
||
style="font-size:10px;width:20px;" name="is_cancelled"
|
||
<?= $tour->is_cancelled ? 'checked' : '' ?>>
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<textarea class="col-12" name="beschreibung" rows="10" cols="50"><?= e($tour->beschreibung) ?></textarea>
|
||
</div>
|
||
|
||
<a href="/tour/<?= e($tour->id) ?>">
|
||
<div type="submit" class="btn btn-success col-2 mb-2 float-right mr-2">Abbrechen</div>
|
||
</a>
|
||
<button type="submit" class="btn btn-danger col-2 mb-2 float-right mr-2">Speichern</button>
|
||
</form>
|
||
|
||
<section class="tour-media-manager" aria-labelledby="tour-media-title">
|
||
<div class="tour-media-head">
|
||
<div>
|
||
<h4 id="tour-media-title">Tour-Bilder</h4>
|
||
<p class="tour-media-hint">Mehrere Bilder möglich. Das neueste Bild wird zuerst angezeigt.</p>
|
||
</div>
|
||
<span class="tour-media-count"><?= count($tourImages) === 1 ? '1 Bild' : count($tourImages) . ' Bilder' ?></span>
|
||
</div>
|
||
|
||
<?php if ($tourImages === []): ?>
|
||
<div class="tour-media-empty">Noch keine Bilder hinterlegt.</div>
|
||
<?php else: ?>
|
||
<div class="tour-media-grid gallery-grid">
|
||
<?php foreach ($tourImages as $i => $image): ?>
|
||
<figure class="gallery-item" style="--i:<?= $i % 20 ?>">
|
||
<a class="gallery-item-link"
|
||
href="<?= e($image['large']) ?>?v=<?= e($image['version']) ?>"
|
||
data-lightbox="<?= e($galleryLightbox) ?>"
|
||
data-title="<?= e($tour->name) ?> – Bild <?= $i + 1 ?>">
|
||
<img src="<?= e($image['large']) ?>?v=<?= e($image['version']) ?>"
|
||
alt="<?= e($tour->name) ?> – Bild <?= $i + 1 ?>"
|
||
loading="lazy" decoding="async">
|
||
<span class="gallery-overlay" aria-hidden="true">
|
||
<span class="gallery-zoom">
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24"
|
||
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
||
stroke-linejoin="round">
|
||
<circle cx="11" cy="11" r="7"/><path d="m21 21-4.3-4.3"/>
|
||
<path d="M11 8v6"/><path d="M8 11h6"/>
|
||
</svg>
|
||
</span>
|
||
</span>
|
||
</a>
|
||
|
||
<form class="gallery-delete"
|
||
action="/tour/<?= e($tour->id) ?>/images/delete/<?= e($image['name']) ?>"
|
||
method="POST"
|
||
onsubmit="return confirm('Dieses Bild wirklich löschen?');">
|
||
<?= csrf_field() ?>
|
||
<button type="submit" title="Bild löschen" aria-label="Bild löschen">×</button>
|
||
</form>
|
||
</figure>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<form class="tour-media-upload" action="/tour/<?= e($tour->id) ?>/images"
|
||
method="POST" enctype="multipart/form-data">
|
||
<?= csrf_field() ?>
|
||
|
||
<label class="gallery-drop" id="tourImagesDrop" for="tourImagesInput">
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="34" height="34" viewBox="0 0 24 24" fill="none"
|
||
stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
|
||
<path d="m17 8-5-5-5 5"/><path d="M12 3v12"/>
|
||
</svg>
|
||
<span class="gallery-drop-title">Bilder auswählen</span>
|
||
<span class="gallery-drop-hint">oder hierher ziehen</span>
|
||
<input class="gallery-file-input" type="file" id="tourImagesInput" name="bilder[]"
|
||
accept="image/jpeg,image/png,image/gif,image/webp" multiple>
|
||
</label>
|
||
|
||
<div class="gallery-preview" id="tourImagesPreview" aria-live="polite"></div>
|
||
|
||
<div class="gallery-upload-actions">
|
||
<button type="submit" class="btn btn-primary gallery-btn">Bilder hochladen</button>
|
||
</div>
|
||
</form>
|
||
</section>
|
||
|
||
<!-- Modal: Zimmer auswählen -->
|
||
<div id="myModal" class="modal">
|
||
<div class="modal-content">
|
||
<span class="close">×</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>
|
||
<form class="booking_form" action="/tour/<?= e($tour->id) ?>/join4user/<?= e($group['id']) ?>" method="POST" style="display:inline;">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="user_id" value="">
|
||
<button type="submit" style="border:none;background:none;padding:0;cursor:pointer;font-weight:bold;">==> Buchen</button>
|
||
</form>
|
||
</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><b><?= e($group['name']) ?>
|
||
<?php if ($key !== 'ungebucht'): ?>
|
||
<form action="/tour/<?= e($tour->id) ?>/delete_room/<?= e($group['id']) ?>" method="POST" style="display:inline;" class="ts_tooltip">
|
||
<?= csrf_field() ?>
|
||
<button type="submit" class="text-primary" style="border:none;background:none;padding:0;cursor:pointer;">(X)</button>
|
||
<span class="ts_tooltiptext">Raum Löschen</span>
|
||
</form>
|
||
<?php endif; ?>
|
||
</b></div>
|
||
|
||
<?php foreach ($group['users'] as $room): ?>
|
||
<?php if ($room->user_name): ?>
|
||
<div> <?= e($room->user_name) ?>
|
||
<?php if ($key === 'ungebucht'): ?>
|
||
<a href="#" data-user_id="<?= e($room->user_id) ?>" id="myBtn"
|
||
class="float-left ts_tooltip">
|
||
(+)
|
||
<span class="ts_tooltiptext">Zimmer zuweisen</span>
|
||
</a>
|
||
<?php else: ?>
|
||
<form action="/tour/<?= e($tour->id) ?>/join4user/0" method="POST" style="display:inline;" class="float-left ts_tooltip">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="user_id" value="<?= e($room->user_id) ?>">
|
||
<button type="submit" style="border:none;background:none;padding:0;cursor:pointer;">(-)</button>
|
||
<span class="ts_tooltiptext">Zimmer-Zuweisung löschen</span>
|
||
</form>
|
||
<?php endif; ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<div style="height:2px;"></div>
|
||
<?php endforeach; ?>
|
||
|
||
<div class="card-header">
|
||
<p>
|
||
<form action="/tour/<?= e($tour->id) ?>/create_room/1" method="POST" style="display:inline;">
|
||
<?= csrf_field() ?>
|
||
<button type="submit" class="text-primary" style="border:none;background:none;padding:0;cursor:pointer;">+ Einzelzimmer erstellen</button>
|
||
</form>
|
||
</p>
|
||
<p>
|
||
<form action="/tour/<?= e($tour->id) ?>/create_room/2" method="POST" style="display:inline;">
|
||
<?= csrf_field() ?>
|
||
<button type="submit" class="text-primary" style="border:none;background:none;padding:0;cursor:pointer;">+ Doppelzimmer erstellen</button>
|
||
</form>
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
const elem = document.querySelector('input[name="start"]');
|
||
const datepicker_start = new Datepicker(elem, {
|
||
'autohide': true,
|
||
'format': 'dd.mm.yyyy',
|
||
'language': 'de',
|
||
'orientation': 'bottom'
|
||
});
|
||
|
||
const elem2 = document.querySelector('input[name="deadline"]');
|
||
const datepicker_deadline = new Datepicker(elem2, {
|
||
'autohide': true,
|
||
'format': 'dd.mm.yyyy',
|
||
'language': 'de',
|
||
'orientation': 'bottom'
|
||
});
|
||
|
||
var modal = document.getElementById("myModal");
|
||
var btns = document.querySelectorAll("#myBtn");
|
||
for (let i = 0; i < btns.length; ++i) {
|
||
btns[i].onclick = function (e) {
|
||
let user_id = this.dataset.user_id;
|
||
|
||
var forms = document.querySelectorAll(".booking_form");
|
||
for (var j = 0; j < forms.length; j++) {
|
||
forms[j].querySelector('input[name="user_id"]').value = user_id;
|
||
}
|
||
|
||
e.preventDefault();
|
||
modal.style.display = "block";
|
||
}
|
||
}
|
||
|
||
var span = document.getElementsByClassName("close")[0];
|
||
|
||
span.onclick = function (e) {
|
||
e.preventDefault();
|
||
modal.style.display = "none";
|
||
}
|
||
|
||
window.onclick = function (event) {
|
||
if (event.target == modal) {
|
||
modal.style.display = "none";
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<script>
|
||
(function () {
|
||
var drop = document.getElementById('tourImagesDrop');
|
||
var input = document.getElementById('tourImagesInput');
|
||
var preview = document.getElementById('tourImagesPreview');
|
||
|
||
if (!drop || !input || !preview) {
|
||
return;
|
||
}
|
||
|
||
['dragover', 'drop'].forEach(function (eventName) {
|
||
document.addEventListener(eventName, function (event) {
|
||
event.preventDefault();
|
||
});
|
||
});
|
||
|
||
var maxPreview = 12;
|
||
|
||
function renderPreview() {
|
||
preview.innerHTML = '';
|
||
|
||
var files = Array.prototype.slice.call(input.files || []);
|
||
if (files.length === 0) {
|
||
return;
|
||
}
|
||
|
||
var count = document.createElement('p');
|
||
count.className = 'gallery-preview-count';
|
||
count.textContent = files.length === 1 ? '1 Bild ausgewählt' : files.length + ' Bilder ausgewählt';
|
||
preview.appendChild(count);
|
||
|
||
var grid = document.createElement('div');
|
||
grid.className = 'gallery-preview-grid';
|
||
|
||
files.slice(0, maxPreview).forEach(function (file) {
|
||
if (!file.type || file.type.indexOf('image/') !== 0) {
|
||
return;
|
||
}
|
||
|
||
var figure = document.createElement('figure');
|
||
figure.className = 'gallery-preview-item';
|
||
|
||
var img = document.createElement('img');
|
||
img.alt = file.name;
|
||
var url = URL.createObjectURL(file);
|
||
img.src = url;
|
||
img.onload = function () { URL.revokeObjectURL(url); };
|
||
|
||
figure.appendChild(img);
|
||
grid.appendChild(figure);
|
||
});
|
||
|
||
if (files.length > maxPreview) {
|
||
var more = document.createElement('figure');
|
||
more.className = 'gallery-preview-item gallery-preview-more';
|
||
more.textContent = '+' + (files.length - maxPreview);
|
||
grid.appendChild(more);
|
||
}
|
||
|
||
preview.appendChild(grid);
|
||
}
|
||
|
||
input.addEventListener('change', renderPreview);
|
||
|
||
['dragenter', 'dragover'].forEach(function (eventName) {
|
||
drop.addEventListener(eventName, function (event) {
|
||
event.preventDefault();
|
||
event.stopPropagation();
|
||
drop.classList.add('is-dragover');
|
||
});
|
||
});
|
||
|
||
['dragleave', 'drop'].forEach(function (eventName) {
|
||
drop.addEventListener(eventName, function (event) {
|
||
event.preventDefault();
|
||
event.stopPropagation();
|
||
drop.classList.remove('is-dragover');
|
||
});
|
||
});
|
||
|
||
drop.addEventListener('drop', function (event) {
|
||
if (!event.dataTransfer || !event.dataTransfer.files || event.dataTransfer.files.length === 0) {
|
||
return;
|
||
}
|
||
|
||
input.files = event.dataTransfer.files;
|
||
renderPreview();
|
||
});
|
||
})();
|
||
</script>
|