diff --git a/motorradig/app/Http/Controllers/ImageController.php b/motorradig/app/Http/Controllers/ImageController.php index 6db57a1..4950c6a 100644 --- a/motorradig/app/Http/Controllers/ImageController.php +++ b/motorradig/app/Http/Controllers/ImageController.php @@ -19,7 +19,7 @@ class ImageController extends Controller } } - Log::debug("User $user->name is not authorized to access image $imageName in category $category"); + Log::debug("Unauthorized image access"); return response()->file(public_path()."/img/placeholder/icon_unknown.png"); } } diff --git a/motorradig/app/Http/Controllers/TourController.php b/motorradig/app/Http/Controllers/TourController.php index ad93c90..9715c49 100644 --- a/motorradig/app/Http/Controllers/TourController.php +++ b/motorradig/app/Http/Controllers/TourController.php @@ -13,6 +13,7 @@ use Intervention\Image\Facades\Image; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; + use Illuminate\Support\Str; class TourController extends Controller { @@ -77,6 +78,7 @@ public function store(Request $request) { + Log::info("TourController.store"); $request->validate( [ 'name' => 'required|min:3', @@ -88,6 +90,12 @@ ] ); + Log::info("Storage Test"); + Log::info(Storage::allDirectories()); + dd($request); + //error_log("Test§§§"); + //Log::info($request); + $tour = new Tour; $tour->name = $request->input('name'); $tour->user_id = $request->input('user_id'); @@ -98,7 +106,7 @@ $tour->is_cancelled = $request->input('is_cancelled', false); $tour->save(); - error_log("Stored deadline:" . $tour->deadline); + Log::info("Stored deadline:" . $tour->deadline); return redirect('/tour'); } @@ -229,14 +237,14 @@ if (Auth::user()->role != 'ADMIN') { return redirect('/tour'); } - error_log("Tour:edit"); - if ($tour->start < Carbon::now()) { - return view('tour.edit_old')->with('tour', $tour); - } $tour->start = Tour::toGermanDate($tour->start); $tour->deadline = Tour::toGermanDate($tour->deadline); + if ($tour->start < Carbon::now()) { + return view('tour.edit_old')->with('tour', $tour); + } + $rooms = $this->fetch_rooms($tour->id); @@ -255,7 +263,7 @@ public function update(Request $request, Tour $tour) { - error_log("Tour:update"); + Log::info("Tour:update"); $tour = Tour::find($request->input('tour_id')); $request->validate( @@ -268,6 +276,9 @@ ); if ($request->bild) { + $this->storeImage($request->bild, "tour_".$tour->id, $request->name); + /* + Log::info("Processing image"); $bild = Image::make($request->bild); $breite = $bild->width(); $hoehe = $bild->height(); @@ -286,6 +297,9 @@ ->widen(96) ->save(public_path() . '/img/tour/' . $tour->id . '.jpg'); } + Log::info("Image saved as ". public_path() . '/img/tour/' . $tour->id . '_gross.jpg'); + Log::info("Image saved as ". public_path() . '/img/tour/' . $tour->id . '.jpg'); + */ } $tour->name = $request->input('name'); @@ -386,4 +400,53 @@ DB::delete("DELETE FROM tour_rooms WHERE tour_id = ? AND id = ?", [$tour_id, $room_id]); return redirect('tour/' . $tour_id . '/edit'); } + + + + private function getImage($category, $imageName) { + Log::debug("File request for category: ".$category.", File: ".$imageName); + $user=Auth::user(); + if ($user) { + + if ($user->role == "ADMIN" || $user->role == "MEMBER") { + Log::info("User has proper role: ".$user->role.", serving content"); + return response()->file(storage_path() . "/img_storage/".$category."/" . $imageName); + } + } + + Log::debug("User $user->name is not authorized to access image $imageName in category $category"); + return response()->file(public_path()."/img/placeholder/icon_unknown.png"); } + + private function storeImage($bild, $category, $name) { + $cat=Str::slug($category); + $name=Str::slug($name); + + $dirPath = storage_path() . "/img_storage/$cat"; + if (!file_exists($dirPath)) { + mkdir($dirPath, 0777, true); + } + + $bild = Image::make($bild); + $breite = $bild->width(); + $hoehe = $bild->height(); + if ($breite > $hoehe) { + Image::make($bild) + ->widen(1200) + ->save("$dirPath/$name"."_gross.jpg"); + Image::make($bild) + ->widen(64) + ->save("$dirPath/$name".".jpg"); + } else { + Image::make($bild) + ->heighten(900) + ->save("$dirPath/$name"."_gross.jpg");; + Image::make($bild) + ->widen(96) + ->save("$dirPath/$name".".jpg"); + } + Log::info("Image saved as $dirPath/$name" . '_gross.jpg'); + Log::info("Image saved as $dirPath/$name" . '.jpg'); + } + +} \ No newline at end of file diff --git a/motorradig/public/img/tour/1.jpg b/motorradig/public/img/tour/1.jpg new file mode 100644 index 0000000..49477a1 Binary files /dev/null and b/motorradig/public/img/tour/1.jpg differ diff --git a/motorradig/public/img/tour/1_gross.jpg b/motorradig/public/img/tour/1_gross.jpg new file mode 100644 index 0000000..5b300d8 Binary files /dev/null and b/motorradig/public/img/tour/1_gross.jpg differ diff --git a/motorradig/public/img/tour/8.jpg b/motorradig/public/img/tour/8.jpg new file mode 100644 index 0000000..49477a1 Binary files /dev/null and b/motorradig/public/img/tour/8.jpg differ diff --git a/motorradig/public/img/tour/8_gross.jpg b/motorradig/public/img/tour/8_gross.jpg new file mode 100644 index 0000000..5b300d8 Binary files /dev/null and b/motorradig/public/img/tour/8_gross.jpg differ diff --git a/motorradig/resources/views/tour/gallery/show.blade.php b/motorradig/resources/views/tour/gallery/show.blade.php index 235fc1a..272951e 100644 --- a/motorradig/resources/views/tour/gallery/show.blade.php +++ b/motorradig/resources/views/tour/gallery/show.blade.php @@ -4,11 +4,21 @@