diff --git a/motorradig/app/Http/Controllers/GalleryController.php b/motorradig/app/Http/Controllers/GalleryController.php index 29c3565..992c795 100644 --- a/motorradig/app/Http/Controllers/GalleryController.php +++ b/motorradig/app/Http/Controllers/GalleryController.php @@ -71,13 +71,43 @@ class GalleryController extends Controller ->with("imagelist",$imagelist) ->with("tour_name",$tour_name); } - - /* - tour-1 - 2023-04-24-ref1png.jpg - */ + } - return redirect('/tour/index_old'); + public function show_deleted_images($tour_id) + { + Log::info("GalleryController::show_deleted"); + if(Auth::user()->role!="ADMIN") { + return redirect('/tour/index_old'); + } + + $imagelist_orig = Storage::disk('img_storage')->files("tour-$tour_id-DELETED"); + $imagelist=[]; + foreach($imagelist_orig as $image) { + + $arr = explode("/", $image); + $image = end($arr); + + $before = $image; + if (str_ends_with($image, "_gross.jpg")) { + $image = substr($image, 0, -10); # Remove last 10 characters + $imagenames=[$image, $image]; # filename, displayname + + $imagefilename=$image.".jpg"; + Log::info("Searching displayname for filenamename $imagefilename"); + $row = DB::table('gallery_items')->select('displayname')->where('filename',$imagefilename)->get(); + $displayname = sizeof($row) ? $row[0]->displayname : $imagefilename; + Log::info("=> $displayname"); + + array_push($imagelist, [$image, $displayname] ); + + } + } + + //dd($imagelist); + $tour_name = DB::select("select name from tours where id=".$tour_id)[0]->name; + return view('tour/gallery/show_deleted')->with("tour_id",$tour_id) + ->with("imagelist",$imagelist) + ->with("tour_name",$tour_name); } /** @@ -148,7 +178,8 @@ class GalleryController extends Controller return redirect("/tour/gallery/$tour_id"); } - public function delete_image($tour_id, $image_name) { + public function delete_image($tour_id, $image_name) { + Log::info("GalleryController::delete_image, tour_id=$tour_id, image_name=$image_name"); $image_name = explode(".", $image_name)[0]; $files = [$image_name . ".jpg" , $image_name . "_gross.jpg"]; $sourceDir = storage_path() . "/img_storage/tour-$tour_id"; @@ -165,6 +196,23 @@ class GalleryController extends Controller } + public function restore_image($tour_id, $image_name) { + Log::info("GalleryController::restore_image, tour_id=$tour_id, image_name=$image_name"); + $image_name = explode(".", $image_name)[0]; + $files = [$image_name . ".jpg" , $image_name . "_gross.jpg"]; + $targetDir = storage_path() . "/img_storage/tour-$tour_id"; + $sourceDir = storage_path() . "/img_storage/tour-$tour_id-DELETED"; + + if (!file_exists($targetDir)) { + mkdir($targetDir, 0777, true); + } + + foreach($files as $file) { + rename("$sourceDir/$file", "$targetDir/$file"); + } + return redirect("/tour/gallery/$tour_id/show_deleted"); + } + public function name_image(Request $request, $tour_id, $image_name) { $displayname = $request->new_image_name; Log::info("GalleryController::name_image for tour $tour_id , image_name=$image_name, display_name=$displayname"); diff --git a/motorradig/resources/views/tour/gallery/show.blade.php b/motorradig/resources/views/tour/gallery/show.blade.php index 87a7f0d..4b47f39 100644 --- a/motorradig/resources/views/tour/gallery/show.blade.php +++ b/motorradig/resources/views/tour/gallery/show.blade.php @@ -3,10 +3,8 @@ @section('content')
-

{{$tour_name}}

-
+ +
@@ -90,15 +90,6 @@ } - - - - - - - - -

Hochladen

@@ -107,6 +98,9 @@
+ @if(Auth::user()->role=="ADMIN") + Gelöschte Bilder + @endif
diff --git a/motorradig/resources/views/tour/gallery/show_deleted.blade.php b/motorradig/resources/views/tour/gallery/show_deleted.blade.php new file mode 100644 index 0000000..3e3f6b2 --- /dev/null +++ b/motorradig/resources/views/tour/gallery/show_deleted.blade.php @@ -0,0 +1,85 @@ +@extends('layouts.app') + +@section('content') +
+ +

{{$tour_name}}

+

Gelöschte Bilder

+ +
+ + + + +
+ + + + + + + + Zurück +
+ + +@endsection \ No newline at end of file diff --git a/motorradig/routes/web.php b/motorradig/routes/web.php index 2f797bd..7631f87 100644 --- a/motorradig/routes/web.php +++ b/motorradig/routes/web.php @@ -68,6 +68,8 @@ Route::get('/tour/gallery/{gallery_id}/delete_image/{imageName}', 'GalleryController@delete_image'); Route::put('/tour/gallery/{gallery_id}/name_image/{imageName}', 'GalleryController@name_image'); + Route::get('/tour/gallery/{gallery_id}/show_deleted', 'GalleryController@show_deleted_images'); + Route::get('/tour/gallery/{gallery_id}/restore_image/{imageName}', 'GalleryController@restore_image'); Auth::routes();