229 lines
12 KiB
PHP
229 lines
12 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;
|
||
?>
|
||
|
||
<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) ?>">
|
||
<?= 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)' : '' ?>
|
||
</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(old('start') ?? $tour->start) ?>" required>
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label class="ml-2 mt-3" style="width:140px; text-align:left;font-size:18px;" for="bericht">Bericht:</label>
|
||
<textarea class="col-12" name="bericht" rows="10" cols="50"><?= e($tour->bericht) ?></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>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<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>
|