Tour Guide, mehrere Tour-Bilder und Guide-Verwaltungsrechte
This commit is contained in:
parent
322d232012
commit
b52155c5f0
12 changed files with 784 additions and 154 deletions
|
|
@ -84,7 +84,7 @@ Die Datenbank wurde um ungenutzte bzw. redundante Bestandteile bereinigt
|
|||
| Spalte `users.email_verified_at` | immer NULL, keine Verifizierung |
|
||||
| Spalte `users.remember_token` | Session-Auth ohne „Angemeldet bleiben" |
|
||||
| Spalte `tours.status` | redundant zu `tours.is_cancelled` |
|
||||
| `tours.user_id` VARCHAR → INT | speicherte nur IDs |
|
||||
| `tours.user_id` → `tours.tour_guide_id` | eindeutiger Feldname für den Tour Guide |
|
||||
|
||||
Die Galerie ist rein dateisystembasiert; das Umbenennen von Bildern
|
||||
(`displayname`) entfällt.
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ declare(strict_types=1);
|
|||
* - Tabellen: migrations, failed_jobs, galleries, gallery_items, password_resets
|
||||
* - Spalte users.email_verified_at, users.remember_token
|
||||
* - Spalte tours.status (redundant zu tours.is_cancelled)
|
||||
* - Typ von tours.user_id: VARCHAR -> INT
|
||||
* - tours.user_id: VARCHAR -> INT und Umbenennung in tours.tour_guide_id
|
||||
*/
|
||||
|
||||
require dirname(__DIR__) . '/src/bootstrap.php';
|
||||
|
|
@ -104,23 +104,28 @@ foreach ([
|
|||
}
|
||||
}
|
||||
|
||||
// tours.user_id von VARCHAR auf INT ändern
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT DATA_TYPE FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'tours' AND COLUMN_NAME = 'user_id'"
|
||||
);
|
||||
$stmt->execute();
|
||||
$type = $stmt->fetchColumn();
|
||||
// tours.user_id in tours.tour_guide_id umbenennen (und ggf. VARCHAR -> INT)
|
||||
if (columnExists($pdo, 'tours', 'user_id')) {
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT DATA_TYPE FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'tours' AND COLUMN_NAME = 'user_id'"
|
||||
);
|
||||
$stmt->execute();
|
||||
$type = $stmt->fetchColumn();
|
||||
|
||||
if ($type === 'varchar') {
|
||||
// Sicherstellen, dass keine nicht-numerischen Werte verbleiben
|
||||
$pdo->exec("UPDATE `tours` SET user_id = '0' WHERE user_id NOT REGEXP '^[0-9]+$'");
|
||||
$pdo->exec('ALTER TABLE `tours` MODIFY `user_id` INT NOT NULL');
|
||||
$out("tours.user_id nach INT geändert");
|
||||
} elseif ($type === 'int') {
|
||||
$out('tours.user_id ist bereits INT');
|
||||
if ($type === 'varchar') {
|
||||
// Sicherstellen, dass keine nicht-numerischen Werte verbleiben
|
||||
$pdo->exec("UPDATE `tours` SET user_id = '0' WHERE user_id NOT REGEXP '^[0-9]+$'");
|
||||
$pdo->exec('ALTER TABLE `tours` MODIFY `user_id` INT NOT NULL');
|
||||
$out('tours.user_id nach INT geändert');
|
||||
}
|
||||
|
||||
$pdo->exec('ALTER TABLE `tours` CHANGE `user_id` `tour_guide_id` INT NOT NULL');
|
||||
$out('tours.user_id in tours.tour_guide_id umbenannt');
|
||||
} elseif (columnExists($pdo, 'tours', 'tour_guide_id')) {
|
||||
$out('tours.tour_guide_id existiert bereits');
|
||||
} else {
|
||||
$out("tours.user_id hat Typ '$type' (nicht geändert)");
|
||||
$out('tours.tour_guide_id nicht gefunden');
|
||||
}
|
||||
|
||||
echo "Fertig.\n";
|
||||
|
|
|
|||
|
|
@ -782,3 +782,66 @@ p {
|
|||
transition: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* Tour-Bilder: mehrere Bilder pro Tour */
|
||||
.tour-media-grid {
|
||||
--gallery-accent: #4ea1ff;
|
||||
--gallery-radius: 14px;
|
||||
margin-top: .5rem;
|
||||
}
|
||||
|
||||
.tour-media-manager {
|
||||
margin-top: 2rem;
|
||||
padding-top: 1.5rem;
|
||||
border-top: 1px solid #e2e8f0;
|
||||
}
|
||||
|
||||
.tour-media-head {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.tour-media-head h4 {
|
||||
margin: 0;
|
||||
color: #111827;
|
||||
font-size: 1.15rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.tour-media-hint {
|
||||
margin: .25rem 0 0;
|
||||
color: #6b7280;
|
||||
font-size: .85rem;
|
||||
}
|
||||
|
||||
.tour-media-count {
|
||||
flex-shrink: 0;
|
||||
padding: .2rem .6rem;
|
||||
color: #1d4ed8;
|
||||
font-size: .78rem;
|
||||
font-weight: 700;
|
||||
background: #eff6ff;
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.tour-media-empty {
|
||||
padding: 1.4rem;
|
||||
color: #6b7280;
|
||||
text-align: center;
|
||||
background: #f8fafc;
|
||||
border: 1px dashed #cbd5e1;
|
||||
border-radius: 14px;
|
||||
}
|
||||
|
||||
.tour-media-upload {
|
||||
margin-top: 1.25rem;
|
||||
}
|
||||
|
||||
@media (max-width: 575.98px) {
|
||||
.tour-media-head {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ class TourController
|
|||
$tour = new Tour();
|
||||
$tour->name = 'neue Tour';
|
||||
$tour->beschreibung = 'Tour Beschreibung';
|
||||
$tour->user_id = Auth::id();
|
||||
$tour->tour_guide_id = Auth::id();
|
||||
|
||||
view('tour.create', ['tour' => $tour]);
|
||||
}
|
||||
|
|
@ -95,13 +95,13 @@ class TourController
|
|||
'beschreibung' => 'required',
|
||||
'start' => 'required',
|
||||
'deadline' => 'required',
|
||||
'user_id' => 'required',
|
||||
'tour_guide_id' => 'required',
|
||||
'bild' => 'mimes:jpg,jpeg,bmp,png,gif',
|
||||
]);
|
||||
|
||||
$tour = Tour::create([
|
||||
'name' => (string) input('name'),
|
||||
'user_id' => (int) input('user_id'),
|
||||
'tour_guide_id' => (int) input('tour_guide_id'),
|
||||
'beschreibung' => (string) input('beschreibung'),
|
||||
'start' => db_date(input('start')),
|
||||
'deadline' => db_date(input('deadline')),
|
||||
|
|
@ -138,8 +138,9 @@ class TourController
|
|||
redirect('/tour');
|
||||
}
|
||||
|
||||
$creator = User::find((int) $tour->user_id);
|
||||
$canManage = $this->canManageBookings($tour);
|
||||
$guide = User::find((int) $tour->tour_guide_id);
|
||||
$canManage = $this->canManageTour($tour);
|
||||
$tourImages = $this->tourImages((int) $tour->id);
|
||||
|
||||
$users = [];
|
||||
foreach (Booking::forTour((int) $tour->id) as $booking) {
|
||||
|
|
@ -155,10 +156,11 @@ class TourController
|
|||
$tour->deadline = german_date($tour->deadline);
|
||||
|
||||
view('tour.show_old', [
|
||||
'tour' => $tour,
|
||||
'users' => $users,
|
||||
'creator' => $creator,
|
||||
'canManage' => $canManage,
|
||||
'tour' => $tour,
|
||||
'users' => $users,
|
||||
'guide' => $guide,
|
||||
'tourImages' => $tourImages,
|
||||
'canManage' => $canManage,
|
||||
]);
|
||||
|
||||
return;
|
||||
|
|
@ -170,35 +172,38 @@ class TourController
|
|||
$tour->deadline = german_date($tour->deadline);
|
||||
|
||||
view('tour.show', [
|
||||
'tour' => $tour,
|
||||
'users' => $users,
|
||||
'creator' => $creator,
|
||||
'rooms' => $rooms,
|
||||
'canManage' => $canManage,
|
||||
'tour' => $tour,
|
||||
'users' => $users,
|
||||
'guide' => $guide,
|
||||
'tourImages' => $tourImages,
|
||||
'rooms' => $rooms,
|
||||
'canManage' => $canManage,
|
||||
]);
|
||||
}
|
||||
|
||||
public function edit(string $id): void
|
||||
{
|
||||
$current = Auth::user();
|
||||
|
||||
if (!$current->isAdmin()) {
|
||||
redirect('/tour');
|
||||
}
|
||||
|
||||
$tour = Tour::find((int) $id);
|
||||
|
||||
if ($tour === null) {
|
||||
if ($tour === null || !$this->canManageTour($tour)) {
|
||||
redirect('/tour');
|
||||
}
|
||||
|
||||
$guides = User::selectableGuides();
|
||||
$current = Auth::user();
|
||||
$guides = $current->isAdmin() ? User::selectableGuides() : [];
|
||||
$tourGuide = User::find((int) $tour->tour_guide_id);
|
||||
$tourImages = $this->tourImages((int) $tour->id);
|
||||
|
||||
if ($tour->start < today()) {
|
||||
$tour->start = german_date($tour->start);
|
||||
$tour->deadline = german_date($tour->deadline);
|
||||
|
||||
view('tour.edit_old', ['tour' => $tour, 'guides' => $guides]);
|
||||
view('tour.edit_old', [
|
||||
'tour' => $tour,
|
||||
'guides' => $guides,
|
||||
'tourGuide' => $tourGuide,
|
||||
'tourImages' => $tourImages,
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -208,7 +213,13 @@ class TourController
|
|||
$tour->start = german_date($tour->start);
|
||||
$tour->deadline = german_date($tour->deadline);
|
||||
|
||||
view('tour.edit', ['tour' => $tour, 'rooms' => $rooms, 'guides' => $guides]);
|
||||
view('tour.edit', [
|
||||
'tour' => $tour,
|
||||
'rooms' => $rooms,
|
||||
'guides' => $guides,
|
||||
'tourGuide' => $tourGuide,
|
||||
'tourImages' => $tourImages,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(string $id): void
|
||||
|
|
@ -220,43 +231,29 @@ class TourController
|
|||
redirect('/tour');
|
||||
}
|
||||
|
||||
if (!Auth::user()->isAdmin()) {
|
||||
if (!$this->canManageTour($tour)) {
|
||||
redirect('/tour');
|
||||
}
|
||||
|
||||
// Bild wird in Image::store() inhaltlich geprüft (Format/Größe);
|
||||
// die dortige Fehlermeldung wird als Flash-Meldung angezeigt.
|
||||
$current = Auth::user();
|
||||
|
||||
validate([
|
||||
'tour_id' => 'required',
|
||||
'name' => 'required|min:3',
|
||||
'user_id' => 'required',
|
||||
]);
|
||||
|
||||
$guide = User::find((int) input('user_id'));
|
||||
// Nur Admins dürfen den Tour Guide ändern.
|
||||
if ($current->isAdmin()) {
|
||||
$guide = User::find((int) input('tour_guide_id'));
|
||||
|
||||
if ($guide === null || $guide->role === 'GUEST') {
|
||||
flash_set('error', 'Der gewählte Ansprechpartner ist ungültig.');
|
||||
redirect('/tour/' . $tourId . '/edit');
|
||||
}
|
||||
|
||||
$imageError = null;
|
||||
|
||||
if (!empty($_FILES['bild']['name'])) {
|
||||
try {
|
||||
// Tour-Titelbilder liegen wie bisher unter public/img/tour/<id>.jpg
|
||||
Image::storePublic($_FILES['bild'], 'img/tour', (string) $tourId);
|
||||
} catch (\Throwable $e) {
|
||||
if (!$e instanceof \RuntimeException) {
|
||||
error_log('Tourbild-Upload: ' . $e);
|
||||
}
|
||||
|
||||
$imageError = $e instanceof \RuntimeException
|
||||
? $e->getMessage()
|
||||
: 'Das Bild konnte nicht verarbeitet werden.';
|
||||
if ($guide === null || $guide->role === 'GUEST') {
|
||||
flash_set('error', 'Der gewählte Tour Guide ist ungültig.');
|
||||
redirect('/tour/' . $tourId . '/edit');
|
||||
}
|
||||
|
||||
$tour->tour_guide_id = (int) $guide->id;
|
||||
}
|
||||
|
||||
$tour->user_id = (int) $guide->id;
|
||||
$tour->name = (string) input('name');
|
||||
if (input('beschreibung') !== null) {
|
||||
$tour->beschreibung = (string) input('beschreibung');
|
||||
|
|
@ -282,12 +279,7 @@ class TourController
|
|||
$tour->updated_at = now();
|
||||
$tour->save();
|
||||
|
||||
if ($imageError !== null) {
|
||||
flash_set('error', $imageError);
|
||||
redirect('/tour/' . $tourId . '/edit');
|
||||
}
|
||||
|
||||
redirect('/tour');
|
||||
redirect('/tour/' . $tourId . '/edit');
|
||||
}
|
||||
|
||||
public function destroy(string $id): void
|
||||
|
|
@ -300,6 +292,179 @@ class TourController
|
|||
redirect('/tour');
|
||||
}
|
||||
|
||||
/** Lädt mehrere Tour-Bilder hoch (Admin oder Tour Guide). */
|
||||
public function storeImages(string $tour_id): void
|
||||
{
|
||||
$tour = Tour::find((int) $tour_id);
|
||||
|
||||
if (!$this->canManageTour($tour)) {
|
||||
redirect('/tour');
|
||||
}
|
||||
|
||||
$files = $_FILES['bilder'] ?? null;
|
||||
|
||||
if (!is_array($files) || !isset($files['name'])) {
|
||||
flash_set('error', 'Bitte mindestens ein Bild auswählen.');
|
||||
redirect('/tour/' . $tour_id . '/edit');
|
||||
}
|
||||
|
||||
$names = (array) $files['name'];
|
||||
$tmpNames = (array) ($files['tmp_name'] ?? []);
|
||||
$errors = (array) ($files['error'] ?? []);
|
||||
$sizes = (array) ($files['size'] ?? []);
|
||||
|
||||
$stored = 0;
|
||||
$problems = [];
|
||||
|
||||
foreach (array_keys($names) as $i) {
|
||||
$upload = [
|
||||
'name' => (string) ($names[$i] ?? ''),
|
||||
'tmp_name' => (string) ($tmpNames[$i] ?? ''),
|
||||
'error' => (int) ($errors[$i] ?? UPLOAD_ERR_NO_FILE),
|
||||
'size' => (int) ($sizes[$i] ?? 0),
|
||||
];
|
||||
|
||||
if ($upload['error'] === UPLOAD_ERR_NO_FILE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$imageName = $this->uniqueTourImageName((int) $tour->id, $upload['name']);
|
||||
Image::storePublic($upload, 'img/tour/' . $tour->id, $imageName);
|
||||
$stored++;
|
||||
} catch (\Throwable $e) {
|
||||
if (!$e instanceof \RuntimeException) {
|
||||
error_log('Tourbild-Upload: ' . $e);
|
||||
$problems[] = 'Ein Bild konnte nicht verarbeitet werden.';
|
||||
} else {
|
||||
$problems[] = $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($stored > 0) {
|
||||
flash_set('status', $stored === 1 ? 'Bild wurde hinzugefügt.' : $stored . ' Bilder wurden hinzugefügt.');
|
||||
}
|
||||
|
||||
if ($problems !== []) {
|
||||
flash_set('error', implode(' ', array_unique($problems)));
|
||||
} elseif ($stored === 0) {
|
||||
flash_set('error', 'Bitte mindestens ein Bild auswählen.');
|
||||
}
|
||||
|
||||
redirect('/tour/' . $tour_id . '/edit');
|
||||
}
|
||||
|
||||
/** Löscht ein Tour-Bild (Admin oder Tour Guide). */
|
||||
public function deleteImage(string $tour_id, string $imageName): void
|
||||
{
|
||||
$tour = Tour::find((int) $tour_id);
|
||||
|
||||
if (!$this->canManageTour($tour)) {
|
||||
redirect('/tour');
|
||||
}
|
||||
|
||||
$name = basename((string) $imageName);
|
||||
$name = preg_replace('/(?:_gross)?\.(?:jpe?g)$/i', '', $name) ?? $name;
|
||||
|
||||
$deleted = false;
|
||||
|
||||
if ($name === (string) $tour->id) {
|
||||
// Altes Einzelbild (public/img/tour/<id>.jpg)
|
||||
foreach (['.jpg', '_gross.jpg'] as $suffix) {
|
||||
$path = public_path('img/tour/' . $name . $suffix);
|
||||
if (is_file($path) && @unlink($path)) {
|
||||
$deleted = true;
|
||||
}
|
||||
}
|
||||
} elseif (preg_match('/^[a-z0-9][a-z0-9-]*$/', $name) === 1) {
|
||||
// Neues Bild im Ordner public/img/tour/<id>/
|
||||
foreach (['.jpg', '_gross.jpg'] as $suffix) {
|
||||
$path = public_path('img/tour/' . $tour->id . '/' . $name . $suffix);
|
||||
if (is_file($path) && @unlink($path)) {
|
||||
$deleted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
flash_set($deleted ? 'status' : 'error', $deleted
|
||||
? 'Bild wurde gelöscht.'
|
||||
: 'Das Bild konnte nicht gelöscht werden.');
|
||||
|
||||
redirect('/tour/' . $tour_id . '/edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert alle Tour-Bilder (altes Einzelbild und neuer Bilderordner),
|
||||
* neueste zuerst.
|
||||
*/
|
||||
private function tourImages(int $tourId): array
|
||||
{
|
||||
$images = [];
|
||||
|
||||
$legacy = public_path('img/tour/' . $tourId . '.jpg');
|
||||
if (is_file($legacy)) {
|
||||
$images[] = [
|
||||
'name' => (string) $tourId,
|
||||
'thumb' => '/img/tour/' . $tourId . '.jpg',
|
||||
'large' => '/img/tour/' . $tourId . '_gross.jpg',
|
||||
'version' => @filemtime($legacy) ?: 0,
|
||||
'mtime' => @filemtime($legacy) ?: 0,
|
||||
];
|
||||
}
|
||||
|
||||
$dir = public_path('img/tour/' . $tourId);
|
||||
if (is_dir($dir)) {
|
||||
foreach (glob($dir . '/*.jpg') ?: [] as $file) {
|
||||
$filename = basename($file);
|
||||
|
||||
if (str_ends_with($filename, '_gross.jpg')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = substr($filename, 0, -4);
|
||||
$gross = $dir . '/' . $name . '_gross.jpg';
|
||||
|
||||
$images[] = [
|
||||
'name' => $name,
|
||||
'thumb' => '/img/tour/' . $tourId . '/' . $filename,
|
||||
'large' => is_file($gross)
|
||||
? '/img/tour/' . $tourId . '/' . $name . '_gross.jpg'
|
||||
: '/img/tour/' . $tourId . '/' . $filename,
|
||||
'version' => @filemtime($file) ?: 0,
|
||||
'mtime' => @filemtime($file) ?: 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
usort($images, fn(array $a, array $b) => $b['mtime'] <=> $a['mtime']);
|
||||
|
||||
return $images;
|
||||
}
|
||||
|
||||
/** Erzeugt einen Dateinamen, der im Tour-Ordner noch nicht existiert. */
|
||||
private function uniqueTourImageName(int $tourId, string $originalName): string
|
||||
{
|
||||
$dir = public_path('img/tour/' . $tourId);
|
||||
$base = Image::slug(pathinfo($originalName, PATHINFO_FILENAME));
|
||||
|
||||
// Reine Zahlen wären mit dem alten Einzelbild (<id>.jpg) verwechselbar.
|
||||
if (ctype_digit($base)) {
|
||||
$base = 'bild-' . $base;
|
||||
}
|
||||
|
||||
$base = substr($base, 0, 60);
|
||||
$name = $base;
|
||||
$i = 2;
|
||||
|
||||
while (is_file($dir . '/' . $name . '.jpg') || is_file($dir . '/' . $name . '_gross.jpg')) {
|
||||
$name = $base . '-' . $i;
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
public function joinRoom(string $tour_id, string $room_id): void
|
||||
{
|
||||
$tour = Tour::find((int) $tour_id);
|
||||
|
|
@ -313,7 +478,7 @@ class TourController
|
|||
|
||||
// Normale Nutzer dürfen sich nur selbst in einen echten, freien Raum
|
||||
// eintragen. room_id 0 (austragen) und Raumwechsel bleiben Admins
|
||||
// bzw. dem Tour-Ansprechpartner vorbehalten.
|
||||
// bzw. dem Tour Guide vorbehalten.
|
||||
if (Booking::forUser((int) $tour->id, (int) $user->id) !== null
|
||||
|| !TourRoom::isBookable((int) $tour->id, $roomId)
|
||||
|| !Tour::hasSpace((int) $tour->id)) {
|
||||
|
|
@ -326,10 +491,16 @@ class TourController
|
|||
|
||||
public function joinRoom4user(string $tour_id, string $room_id): void
|
||||
{
|
||||
$tour = Tour::find((int) $tour_id);
|
||||
|
||||
if (!$this->canManageTour($tour)) {
|
||||
redirect('/tour');
|
||||
}
|
||||
|
||||
$userId = (int) input('user_id', 0);
|
||||
|
||||
if ($userId > 0) {
|
||||
Booking::joinRoom((int) $tour_id, $userId, (int) $room_id);
|
||||
Booking::joinRoom((int) $tour->id, $userId, (int) $room_id);
|
||||
}
|
||||
|
||||
redirect('/tour/' . $tour_id . '/edit');
|
||||
|
|
@ -337,7 +508,7 @@ class TourController
|
|||
|
||||
public function cancelBooking(string $tour_id): void
|
||||
{
|
||||
if (!$this->canManageBookings(Tour::find((int) $tour_id))) {
|
||||
if (!$this->canManageTour(Tour::find((int) $tour_id))) {
|
||||
redirect('/tour');
|
||||
}
|
||||
|
||||
|
|
@ -347,7 +518,7 @@ class TourController
|
|||
|
||||
public function cancelBookingAdmin(string $tour_id, string $user_id): void
|
||||
{
|
||||
if (!$this->canManageBookings(Tour::find((int) $tour_id))) {
|
||||
if (!$this->canManageTour(Tour::find((int) $tour_id))) {
|
||||
redirect('/tour/' . $tour_id);
|
||||
}
|
||||
|
||||
|
|
@ -357,24 +528,36 @@ class TourController
|
|||
|
||||
public function createRoom(string $tour_id, string $capacity): void
|
||||
{
|
||||
Tour::createRoom((int) $tour_id, (int) $capacity);
|
||||
$tour = Tour::find((int) $tour_id);
|
||||
|
||||
if (!$this->canManageTour($tour)) {
|
||||
redirect('/tour');
|
||||
}
|
||||
|
||||
Tour::createRoom((int) $tour->id, (int) $capacity);
|
||||
redirect('/tour/' . $tour_id . '/edit');
|
||||
}
|
||||
|
||||
public function deleteRoom(string $tour_id, string $room_id): void
|
||||
{
|
||||
$tour = Tour::find((int) $tour_id);
|
||||
|
||||
if (!$this->canManageTour($tour)) {
|
||||
redirect('/tour');
|
||||
}
|
||||
|
||||
db()->execute('UPDATE `bookings` SET room_id = NULL WHERE room_id = ?', [(int) $room_id]);
|
||||
db()->execute('DELETE FROM `tour_rooms` WHERE tour_id = ? AND id = ?', [(int) $tour_id, (int) $room_id]);
|
||||
db()->execute('DELETE FROM `tour_rooms` WHERE tour_id = ? AND id = ?', [(int) $tour->id, (int) $room_id]);
|
||||
|
||||
redirect('/tour/' . $tour_id . '/edit');
|
||||
}
|
||||
|
||||
private function canManageBookings(?Tour $tour): bool
|
||||
private function canManageTour(?Tour $tour): bool
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
return $user !== null
|
||||
&& $tour !== null
|
||||
&& ($user->isAdmin() || (int) $user->id === (int) $tour->user_id);
|
||||
&& ($user->isAdmin() || (int) $user->id === (int) $tour->tour_guide_id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class User extends Model
|
|||
return $row === null ? null : static::fromRow($row);
|
||||
}
|
||||
|
||||
/** Admins und Mitglieder, die als Tour-Ansprechpartner wählbar sind. */
|
||||
/** Admins und Mitglieder, die als Tour Guide wählbar sind. */
|
||||
public static function selectableGuides(): array
|
||||
{
|
||||
$rows = db()->fetchAll(
|
||||
|
|
|
|||
|
|
@ -57,11 +57,13 @@ $router->delete('/tour/{id}', [TourController::class, 'destroy'], true);
|
|||
$router->post('/tour/upload_gallery/{tour_id}', [TourController::class, 'uploadGallery']);
|
||||
|
||||
$router->post('/tour/{tour_id}/join/{room_id}', [TourController::class, 'joinRoom'], true);
|
||||
$router->post('/tour/{tour_id}/join4user/{room_id}', [TourController::class, 'joinRoom4user'], 'ADMIN');
|
||||
$router->post('/tour/{tour_id}/join4user/{room_id}', [TourController::class, 'joinRoom4user'], true);
|
||||
$router->post('/tour/{tour_id}/cancelBooking', [TourController::class, 'cancelBooking'], true);
|
||||
$router->post('/tour/{tour_id}/cancelBookingAdmin/{user_id}', [TourController::class, 'cancelBookingAdmin'], true);
|
||||
$router->post('/tour/{tour_id}/create_room/{capacity}', [TourController::class, 'createRoom'], 'ADMIN');
|
||||
$router->post('/tour/{tour_id}/delete_room/{room_id}', [TourController::class, 'deleteRoom'], 'ADMIN');
|
||||
$router->post('/tour/{tour_id}/create_room/{capacity}', [TourController::class, 'createRoom'], true);
|
||||
$router->post('/tour/{tour_id}/delete_room/{room_id}', [TourController::class, 'deleteRoom'], true);
|
||||
$router->post('/tour/{tour_id}/images', [TourController::class, 'storeImages'], true);
|
||||
$router->post('/tour/{tour_id}/images/delete/{imageName}', [TourController::class, 'deleteImage'], true);
|
||||
|
||||
// Bilder (Zugriff wird im Controller geprüft)
|
||||
$router->get('/img_storage/{category}/{imageName}', [ImageController::class, 'getImage']);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
<form style="background-color: #fff;" class="text-dark" method="post" action="/tour/store" enctype="multipart/form-data">
|
||||
<?= csrf_field() ?>
|
||||
|
||||
<input type="hidden" name="user_id" value="<?= e(user()->id) ?>">
|
||||
<input type="hidden" name="tour_guide_id" value="<?= e(user()->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>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
<?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 = [];
|
||||
|
|
@ -28,6 +32,10 @@
|
|||
<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; ?>
|
||||
|
|
@ -45,14 +53,20 @@
|
|||
</div>
|
||||
|
||||
<div class="form-group" style="display:flex;">
|
||||
<label class="ml-2 mt-3" style="width:180px; text-align:left;font-size:18px;" for="user_id">Ansprechpartner:</label>
|
||||
<select class="mt-3 mr-2 form-control input-sm" id="user_id" name="user_id" required>
|
||||
<?php foreach ($guides as $guide): ?>
|
||||
<option value="<?= e($guide->id) ?>"<?= (int) $guide->id === (int) $tour->user_id ? ' selected' : '' ?>>
|
||||
<?= e($guide->name) ?><?= $guide->role === 'ADMIN' ? ' (Admin)' : '' ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<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;">
|
||||
|
|
@ -74,23 +88,6 @@
|
|||
value="<?= e(old('max_participants') ?? $tour->max_participants) ?>" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="display:flex;">
|
||||
<label class="ml-2 mt-4" style="width:150px; text-align:left;" for="bild"><h4>Bild:</h4></label>
|
||||
|
||||
<?php $tourThumb = public_path('img/tour/' . (int) $tour->id . '.jpg'); ?>
|
||||
<?php if (is_file($tourThumb)): ?>
|
||||
<a href="/img/tour/<?= e($tour->id) ?>_gross.jpg?v=<?= @filemtime(public_path('img/tour/' . (int) $tour->id . '_gross.jpg')) ?>"
|
||||
data-lightbox="<?= e($tour->id) ?>_gross.jpg" data-title="<?= e($tour->name) ?>">
|
||||
<img src="/img/tour/<?= e($tour->id) ?>.jpg?v=<?= @filemtime($tourThumb) ?>" class="mt-3 ml-3">
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3">
|
||||
<?php endif; ?>
|
||||
|
||||
<input type="file" class="mt-3 mr-2 form-control" id="bild" style="font-size:20px;"
|
||||
name="bild" value="">
|
||||
</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"
|
||||
|
|
@ -108,6 +105,76 @@
|
|||
<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['thumb']) ?>?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">
|
||||
|
|
@ -251,3 +318,94 @@
|
|||
}
|
||||
}
|
||||
</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>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,11 @@
|
|||
<?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">
|
||||
|
|
@ -5,7 +13,15 @@
|
|||
<div class="card-header"><?= e($tour->name) ?></div>
|
||||
|
||||
<div class="card-body">
|
||||
<form style="background-color: #fff;" class="text-dark" method="post" action="/tour/<?= e($tour->id) ?>" enctype="multipart/form-data">
|
||||
<?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) ?>">
|
||||
|
|
@ -16,14 +32,20 @@
|
|||
</div>
|
||||
|
||||
<div class="form-group" style="display:flex;">
|
||||
<label class="ml-2 mt-3" style="width:180px; text-align:left;font-size:18px;" for="user_id">Ansprechpartner:</label>
|
||||
<select class="mt-3 mr-2 form-control input-sm" id="user_id" name="user_id" required>
|
||||
<?php foreach ($guides as $guide): ?>
|
||||
<option value="<?= e($guide->id) ?>"<?= (int) $guide->id === (int) $tour->user_id ? ' selected' : '' ?>>
|
||||
<?= e($guide->name) ?><?= $guide->role === 'ADMIN' ? ' (Admin)' : '' ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<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;">
|
||||
|
|
@ -31,22 +53,6 @@
|
|||
<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" style="display:flex;">
|
||||
<label class="ml-2 mt-4" style="width:150px; text-align:left;" for="bild"><h4>Bild:</h4></label>
|
||||
|
||||
<?php $tourThumb = public_path('img/tour/' . (int) $tour->id . '.jpg'); ?>
|
||||
<?php if (is_file($tourThumb)): ?>
|
||||
<a href="/img/tour/<?= e($tour->id) ?>_gross.jpg?v=<?= @filemtime(public_path('img/tour/' . (int) $tour->id . '_gross.jpg')) ?>"
|
||||
data-lightbox="<?= e($tour->id) ?>_gross.jpg" data-title="<?= e($tour->name) ?>">
|
||||
<img src="/img/tour/<?= e($tour->id) ?>.jpg?v=<?= @filemtime($tourThumb) ?>" class="mt-3 ml-3">
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3">
|
||||
<?php endif; ?>
|
||||
|
||||
<input type="file" class="mt-3 mr-2 form-control" id="bild" style="font-size:20px;" name="bild" value="">
|
||||
</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>
|
||||
|
|
@ -55,8 +61,169 @@
|
|||
<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['thumb']) ?>?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>
|
||||
|
|
|
|||
|
|
@ -41,9 +41,9 @@
|
|||
</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>
|
||||
<label class="ml-2" style="width:180px; text-align:left;font-size:18px;" for="tour_guide">Tour Guide:</label>
|
||||
<input class="mr-1 form-control" type="text" id="tour_guide" name="tour_guide"
|
||||
value="<?= e($guide ? $guide->name : '') ?>" readonly>
|
||||
</div>
|
||||
|
||||
<div class="mt-1" style="display:flex;">
|
||||
|
|
@ -65,12 +65,31 @@
|
|||
<label>Du nimmst nicht teil.</label>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php $tourThumb = public_path('img/tour/' . (int) $tour->id . '.jpg'); ?>
|
||||
<?php if (is_file($tourThumb)): ?>
|
||||
<a href="/img/tour/<?= e($tour->id) ?>_gross.jpg?v=<?= @filemtime(public_path('img/tour/' . (int) $tour->id . '_gross.jpg')) ?>"
|
||||
data-lightbox="<?= e($tour->id) ?>_gross.jpg" data-title="<?= e($tour->name) ?>">
|
||||
<img src="/img/tour/<?= e($tour->id) ?>.jpg?v=<?= @filemtime($tourThumb) ?>" class="mt-3 ml-3">
|
||||
</a>
|
||||
<?php if ($tourImages !== []): ?>
|
||||
<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="tour-bilder-<?= e($tour->id) ?>"
|
||||
data-title="<?= e($tour->name) ?> – Bild <?= $i + 1 ?>">
|
||||
<img src="<?= e($image['thumb']) ?>?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>
|
||||
</figure>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3">
|
||||
<?php endif; ?>
|
||||
|
|
@ -86,7 +105,7 @@
|
|||
<textarea class="col-12" name="beschreibung" rows="10" cols="50" readonly><?= e($tour->beschreibung) ?></textarea>
|
||||
</div>
|
||||
|
||||
<?php if ($current && $current->isAdmin()): ?>
|
||||
<?php if ($current && $canManage): ?>
|
||||
<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>
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@
|
|||
</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>
|
||||
<label class="ml-2" style="width:180px; text-align:left;font-size:18px;" for="tour_guide">Tour Guide:</label>
|
||||
<input class="mr-1 form-control" type="text" id="tour_guide" name="tour_guide" value="<?= e($guide ? $guide->name : '') ?>" readonly>
|
||||
</div>
|
||||
|
||||
<div class="mt-1" style="display:flex;">
|
||||
|
|
@ -40,12 +40,31 @@
|
|||
<label>Du nimmst nicht teil.</label>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php $tourThumb = public_path('img/tour/' . (int) $tour->id . '.jpg'); ?>
|
||||
<?php if (is_file($tourThumb)): ?>
|
||||
<a href="/img/tour/<?= e($tour->id) ?>_gross.jpg?v=<?= @filemtime(public_path('img/tour/' . (int) $tour->id . '_gross.jpg')) ?>"
|
||||
data-lightbox="<?= e($tour->id) ?>_gross.jpg" data-title="<?= e($tour->name) ?>">
|
||||
<img src="/img/tour/<?= e($tour->id) ?>.jpg?v=<?= @filemtime($tourThumb) ?>" class="mt-3 ml-3">
|
||||
</a>
|
||||
<?php if ($tourImages !== []): ?>
|
||||
<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="tour-bilder-<?= e($tour->id) ?>"
|
||||
data-title="<?= e($tour->name) ?> – Bild <?= $i + 1 ?>">
|
||||
<img src="<?= e($image['thumb']) ?>?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>
|
||||
</figure>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3">
|
||||
<?php endif; ?>
|
||||
|
|
@ -60,7 +79,9 @@
|
|||
<textarea class="col-12" name="bericht" rows="10" cols="50" readonly><?= e($tour->bericht) ?></textarea>
|
||||
</div>
|
||||
|
||||
<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 if ($current && $canManage): ?>
|
||||
<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>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -71,6 +71,18 @@ MIGRATIONS = [
|
|||
`updated_at` timestamp NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci''',
|
||||
|
||||
# tours.user_id -> tours.tour_guide_id umbenennen (idempotent)
|
||||
'''SET @has_user := (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'tours' AND COLUMN_NAME = 'user_id');
|
||||
SET @has_guide := (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'tours' AND COLUMN_NAME = 'tour_guide_id');
|
||||
SET @sql := IF(@has_user > 0 AND @has_guide = 0,
|
||||
'ALTER TABLE `tours` CHANGE `user_id` `tour_guide_id` INT NOT NULL',
|
||||
'DO 0');
|
||||
PREPARE mig_stmt FROM @sql;
|
||||
EXECUTE mig_stmt;
|
||||
DEALLOCATE PREPARE mig_stmt''',
|
||||
]
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue