diff --git a/doc/readme.txt b/doc/readme.txt index ad15d5e..290c4ac 100644 --- a/doc/readme.txt +++ b/doc/readme.txt @@ -2,3 +2,8 @@ laravel new motorradig cd motorradig composer require laravel/ui --dev + + + + +mysql -ud0304938 -phubbabubba -h motorrad-ig.de d0304938 diff --git a/motorradig/.env.production b/motorradig/.env.production index 4f69e6d..60ff134 100644 --- a/motorradig/.env.production +++ b/motorradig/.env.production @@ -3,7 +3,7 @@ APP_ENV=local APP_KEY=base64:7Md2wHHNq04ldtpdsz4B2LDAMEOB+4fSfxMJGfDU2zY= APP_DEBUG=true APP_URL=http://test.motorrad-ig.de -LOG_CHANNEL=stack +LOG_CHANNEL=daily DB_CONNECTION=mysql DB_HOST=127.0.0.1 diff --git a/motorradig/app/Http/Controllers/Auth/RegisterController.php b/motorradig/app/Http/Controllers/Auth/RegisterController.php index c6a6de6..e2611b8 100644 --- a/motorradig/app/Http/Controllers/Auth/RegisterController.php +++ b/motorradig/app/Http/Controllers/Auth/RegisterController.php @@ -52,6 +52,7 @@ class RegisterController extends Controller return Validator::make($data, [ 'name' => ['required', 'string', 'max:255'], 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], + 'mobile' => ['required', 'string', 'max:255'], 'password' => ['required', 'string', 'min:8', 'confirmed'], ]); } @@ -67,6 +68,7 @@ class RegisterController extends Controller return User::create([ 'name' => $data['name'], 'email' => $data['email'], + 'mobile' => $data['mobile'], 'password' => Hash::make($data['password']), ]); } diff --git a/motorradig/app/Http/Controllers/PageController.php b/motorradig/app/Http/Controllers/PageController.php index bc0d4e7..dcb2882 100644 --- a/motorradig/app/Http/Controllers/PageController.php +++ b/motorradig/app/Http/Controllers/PageController.php @@ -1,103 +1,111 @@ first(); + $content = $page->content; + + $content = rtrim(ltrim($content, '"'), '"'); + + $user = Auth::user(); + if ($user) { + Log::info("Home page display for user " . $user->name . "[" . $user->id . "]"); + } + + return view('home')->with('content', $content); + } + + public function page_activities() + { + $page = Page::where('name', 'activities')->first(); + $content = $page->content; + return view('activities')->with('content', $content); + } + } - - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() - { - // - } - - /** - * Store a newly created resource in storage. - * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response - */ - public function store(Request $request) - { - // - } - - /** - * Display the specified resource. - * - * @param \App\Page $page - * @return \Illuminate\Http\Response - */ - public function show(Page $page) - { - // - } - - /** - * Show the form for editing the specified resource. - * - * @param \App\Page $page - * @return \Illuminate\Http\Response - */ - public function edit(Page $page) - { - // - } - - /** - * Update the specified resource in storage. - * - * @param \Illuminate\Http\Request $request - * @param \App\Page $page - * @return \Illuminate\Http\Response - */ - public function update(Request $request, Page $page) - { - // - } - - /** - * Remove the specified resource from storage. - * - * @param \App\Page $page - * @return \Illuminate\Http\Response - */ - public function destroy(Page $page) - { - // - } - - - public function page_home() { - $page=Page::where('name','home')->first(); - $content=$page->content; - - $content = rtrim(ltrim($content,'"'),'"'); - - - return view('home')->with('content',$content); - } - - public function page_activities() { - $page=Page::where('name','activities')->first(); - $content=$page->content; - return view('activities')->with('content',$content); - } - -} diff --git a/motorradig/app/Http/Controllers/TourController.php b/motorradig/app/Http/Controllers/TourController.php index fda1106..7df151d 100644 --- a/motorradig/app/Http/Controllers/TourController.php +++ b/motorradig/app/Http/Controllers/TourController.php @@ -1,158 +1,159 @@ ',Carbon::now())->orderBy('start')->get(); - $participantCount=array(); - foreach($tours as $key => $tour) { - $result = DB::select('select count(*) as cnt from bookings where tour_id=?', [$tour->id]); - $participantCount[$tour->id] = $result[0]->cnt; - $tours[$key]->start=Tour::toGermanDate($tour->start); - $tours[$key]->deadline=Tour::toGermanDate($tour->deadline); - } - return view('tour.index')->with('tours',$tours)->with('participantCount',$participantCount); - } - - public function index_old() - { - error_log("Tour:index_old"); - $tours=Tour::where('start','<',Carbon::now())->orderBy('start')->get(); - $participantCount=array(); - foreach($tours as $key => $tour) { - $result = DB::select('select count(*) as cnt from bookings where tour_id=?', [$tour->id]); - $participantCount[$tour->id] = $result[0]->cnt; - $tours[$key]->start=Tour::toGermanDate($tour->start); - $tours[$key]->deadline=Tour::toGermanDate($tour->deadline); - } - return view('tour.index_old')->with('tours',$tours)->with('participantCount',$participantCount); - } - - -/* - - - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() - { - error_log("Tour:create"); - $tour = new Tour; - $tour->name="neue Tour"; - $tour->beschreibung="Tour Beschreibung"; - $tour->user_id=Auth::user()->id; - return view('tour.create')->with('tour',$tour); - } - - /** - * Store a newly created resource in storage. - * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response - */ - public function store(Request $request) - { - error_log("Tour:store"); - - $request->validate( - [ - 'name'=>'required|min:3', - 'beschreibung'=>'required', - 'start'=>'required', - 'deadline'=>'required', - 'user_id'=>'required', - 'bild'=>'mimes:jpg,jpeg,bmp,png,gif' - ] - ); - - $tour=new Tour; - $tour->name=$request->input('name'); - $tour->user_id=$request->input('user_id'); - $tour->beschreibung=$request->input('beschreibung'); - $tour->start=Tour::toDBDate($request->input('start')); - $tour->deadline=Tour::toDBDate($request->input('deadline')); - $tour->max_participants=$request->input('max_participants'); - $tour->is_cancelled=$request->input('is_cancelled',false); - $tour->save(); - - error_log("Stored deadline:".$tour->deadline); - - return redirect('/tour'); - } - - /** - * Display the specified resource. - * - * @param \App\Tour $tour - * @return \Illuminate\Http\Response - */ - public function show(Tour $tour) - { - $creator = User::find($tour->user_id); - $bookings = Booking::where('tour_id',$tour->id)->get(); - $users = array(); - foreach($bookings as $booking) { - $user=User::find($booking->user_id); - array_push($users, $user); + /** + * Display a listing of the resource. + * + * @return \Illuminate\Http\Response + */ + public function index() + { + error_log("Tour:index"); + $tours = Tour::where('start', '>', Carbon::now())->orderBy('start')->get(); + $participantCount = array(); + foreach ($tours as $key => $tour) { + $result = DB::select('select count(*) as cnt from bookings where tour_id=?', [$tour->id]); + $participantCount[$tour->id] = $result[0]->cnt; + $tours[$key]->start = Tour::toGermanDate($tour->start); + $tours[$key]->deadline = Tour::toGermanDate($tour->deadline); + } + return view('tour.index')->with('tours', $tours)->with('participantCount', $participantCount); } - // Vergangene Tour anzeigen - if($tour->start < Carbon::now()) { + public function index_old() + { + error_log("Tour:index_old"); + $tours = Tour::where('start', '<', Carbon::now())->orderBy('start')->get(); + $participantCount = array(); + foreach ($tours as $key => $tour) { + $result = DB::select('select count(*) as cnt from bookings where tour_id=?', [$tour->id]); + $participantCount[$tour->id] = $result[0]->cnt; + $tours[$key]->start = Tour::toGermanDate($tour->start); + $tours[$key]->deadline = Tour::toGermanDate($tour->deadline); + } + return view('tour.index_old')->with('tours', $tours)->with('participantCount', $participantCount); + } + + + /* + + + /** + * Show the form for creating a new resource. + * + * @return \Illuminate\Http\Response + */ + public function create() + { + error_log("Tour:create"); + $tour = new Tour; + $tour->name = "neue Tour"; + $tour->beschreibung = "Tour Beschreibung"; + $tour->user_id = Auth::user()->id; + return view('tour.create')->with('tour', $tour); + } + + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function store(Request $request) + { + error_log("Tour:store"); + + $request->validate( + [ + 'name' => 'required|min:3', + 'beschreibung' => 'required', + 'start' => 'required', + 'deadline' => 'required', + 'user_id' => 'required', + 'bild' => 'mimes:jpg,jpeg,bmp,png,gif' + ] + ); + + $tour = new Tour; + $tour->name = $request->input('name'); + $tour->user_id = $request->input('user_id'); + $tour->beschreibung = $request->input('beschreibung'); + $tour->start = Tour::toDBDate($request->input('start')); + $tour->deadline = Tour::toDBDate($request->input('deadline')); + $tour->max_participants = $request->input('max_participants'); + $tour->is_cancelled = $request->input('is_cancelled', false); + $tour->save(); + + error_log("Stored deadline:" . $tour->deadline); + + return redirect('/tour'); + } + + /** + * Display the specified resource. + * + * @param \App\Tour $tour + * @return \Illuminate\Http\Response + */ + public function show(Tour $tour) + { + $creator = User::find($tour->user_id); + $bookings = Booking::where('tour_id', $tour->id)->get(); + $users = array(); + foreach ($bookings as $booking) { + $user = User::find($booking->user_id); + array_push($users, $user); + } + + // Vergangene Tour anzeigen + if ($tour->start < Carbon::now()) { + $tour->start = Tour::toGermanDate($tour->start); + $tour->deadline = Tour::toGermanDate($tour->deadline); + return view('tour.show_old') + ->with('tour', $tour) + ->with('users', $users) + ->with('creator', $creator); + } + + // Zukünftige Tour anzeigen + $rooms = $this->fetch_rooms($tour->id); + $tour->start = Tour::toGermanDate($tour->start); $tour->deadline = Tour::toGermanDate($tour->deadline); - return view('tour.show_old') + return view('tour.show') ->with('tour', $tour) ->with('users', $users) - ->with('creator', $creator); + ->with('creator', $creator) + ->with('rooms', $rooms); } - // Zukünftige Tour anzeigen - $rooms=$this->fetch_rooms($tour->id); + /** + * Show the form for editing the specified resource. + * + * @param \App\Tour $tour + * @return \Illuminate\Http\Response + */ - $tour->start = Tour::toGermanDate($tour->start); - $tour->deadline = Tour::toGermanDate($tour->deadline); - return view('tour.show') - ->with('tour', $tour) - ->with('users', $users) - ->with('creator', $creator) - ->with('rooms', $rooms); - } - - /** - * Show the form for editing the specified resource. - * - * @param \App\Tour $tour - * @return \Illuminate\Http\Response - */ - - private function fetch_rooms($tour_id) { - // - all existing rooms with booked users (if any) - // - all users without room - $sql=" + private function fetch_rooms($tour_id) + { + // - all existing rooms with booked users (if any) + // - all users without room + $sql = " SELECT qry.tour_id, qry.room_id, @@ -162,7 +163,7 @@ class TourController extends Controller qry.free_slots, COALESCE(qry.room_name,'Ungebucht') as room_name, - COALESCE(qry.room_name,'ZZZZZZZZZ') as room_sort_order + COALESCE(qry.room_id,'ZZZZZZZZZ') as room_sort_order FROM ( SELECT @@ -173,15 +174,16 @@ class TourController extends Controller b.user_id, (SELECT tr.capacity - count(*) from bookings where tour_id=tr.tour_id and room_id=tr.id) as free_slots FROM - tour_rooms tr - LEFT JOIN bookings as b - ON b.tour_id = tr.tour_id AND b.room_id = tr.id + tour_rooms tr LEFT JOIN bookings as b + ON b.tour_id = tr.tour_id AND b.room_id = tr.id WHERE - tr.tour_id= ".$tour_id." + tr.tour_id= " . $tour_id . " + ) qry LEFT JOIN users as u ON qry.user_id = u.id + UNION -- unbooked tour users @@ -200,154 +202,183 @@ class TourController extends Controller LEFT JOIN tour_rooms as tr ON b.room_id = tr.id WHERE - b.tour_id= ".$tour_id." + b.tour_id= " . $tour_id . " AND b.user_id = u.id AND capacity is null - ORDER BY room_name, user_name + ORDER BY room_sort_order, user_name ; "; - $rooms=DB::select($sql); + $rooms = DB::select($sql); - Log::info("TourController.fetch_rooms, returning rooms result:"); - Log::info($rooms); + //Log::info("TourController.fetch_rooms, returning rooms result:"); + //Log::info($rooms); - return($rooms); - } - - public function edit(Tour $tour) - { - error_log("Tour:edit"); - if ($tour->startwith('tour', $tour); + return ($rooms); } - $tour->start = Tour::toGermanDate($tour->start); - $tour->deadline = Tour::toGermanDate($tour->deadline); - - $rooms = $this->fetch_rooms($tour->id); - - return view('tour.edit') - ->with('tour', $tour) - ->with('rooms', $rooms); - } - - /** - * Update the specified resource in storage. - * - * @param \Illuminate\Http\Request $request - * @param \App\Tour $tour - * @return \Illuminate\Http\Response - */ - public function update(Request $request, Tour $tour) - { - - error_log("Tour:update"); - $tour=Tour::find($request->input('tour_id')); - - $request->validate( - [ - 'tour_id' => 'required', - 'name'=>'required|min:3', - 'user_id'=>'required', - 'bild'=>'mimes:jpg,jpeg,bmp,png,gif' - ] - ); - - if ($request->bild){ - $bild = Image::make($request->bild); - $breite = $bild->width(); - $hoehe = $bild->height(); - if ($breite>$hoehe) { - Image::make($request->bild) - ->widen(1200) - ->save(public_path().'/img/tour/'.$tour->id.'_gross.jpg'); - Image::make($request->bild) - ->widen(64) - ->save(public_path().'/img/tour/'.$tour->id.'.jpg'); - }else { - Image::make($request->bild) - ->heighten(900) - ->save(public_path().'/img/tour/'.$tour->id.'_gross.jpg'); - Image::make($request->bild) - ->widen(96) - ->save(public_path().'/img/tour/'.$tour->id.'.jpg'); + public function edit(Tour $tour) + { + 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); + + $rooms = $this->fetch_rooms($tour->id); + + + return view('tour.edit') + ->with('tour', $tour) + ->with('rooms', $rooms); } - $tour->name=$request->input('name'); - if ($request->beschreibung) $tour->beschreibung=$request->input('beschreibung'); - if ($request->start) $tour->start=Tour::toDBDate($request->input('start')); - if ($request->deadline) $tour->deadline=Tour::toDBDate($request->input('deadline')); - if ($request->max_participants) $tour->max_participants=$request->input('max_participants'); - $tour->is_cancelled= ($request->has('is_cancelled')); - if ($request->bericht) $tour->bericht=$request->bericht; - $tour->save(); + /** + * Update the specified resource in storage. + * + * @param \Illuminate\Http\Request $request + * @param \App\Tour $tour + * @return \Illuminate\Http\Response + */ + public function update(Request $request, Tour $tour) + { + + error_log("Tour:update"); + $tour = Tour::find($request->input('tour_id')); + + $request->validate( + [ + 'tour_id' => 'required', + 'name' => 'required|min:3', + 'user_id' => 'required', + 'bild' => 'mimes:jpg,jpeg,bmp,png,gif' + ] + ); + + if ($request->bild) { + $bild = Image::make($request->bild); + $breite = $bild->width(); + $hoehe = $bild->height(); + if ($breite > $hoehe) { + Image::make($request->bild) + ->widen(1200) + ->save(public_path() . '/img/tour/' . $tour->id . '_gross.jpg'); + Image::make($request->bild) + ->widen(64) + ->save(public_path() . '/img/tour/' . $tour->id . '.jpg'); + } else { + Image::make($request->bild) + ->heighten(900) + ->save(public_path() . '/img/tour/' . $tour->id . '_gross.jpg'); + Image::make($request->bild) + ->widen(96) + ->save(public_path() . '/img/tour/' . $tour->id . '.jpg'); + } + } + + $tour->name = $request->input('name'); + if ($request->beschreibung) $tour->beschreibung = $request->input('beschreibung'); + if ($request->start) $tour->start = Tour::toDBDate($request->input('start')); + if ($request->deadline) $tour->deadline = Tour::toDBDate($request->input('deadline')); + if ($request->max_participants) $tour->max_participants = $request->input('max_participants'); + $tour->is_cancelled = ($request->has('is_cancelled')); + if ($request->bericht) $tour->bericht = $request->bericht; + $tour->save(); - error_log("Is cancelled:". $tour->is_cancelled); + error_log("Is cancelled:" . $tour->is_cancelled); - return redirect('/tour'); + return redirect('/tour'); - } - -/* - public function create_room($tour_id, $capacity) { - DB::delete("INSERT INTO booking_rooms") - } -*/ - - public function upload_gallery(Request $request, Tour $tour){ - dd($request); - } - - - /** - * Remove the specified resource from storage. - * - * @param \App\Tour $tour - * @return \Illuminate\Http\Response - */ - public function destroy(Tour $tour) - { - // - } - - public function join_room($tour_id,$room_id) { - Log::info("TourController::join_room"); - $user=Auth::user(); - Tour::join_room($tour_id,$user->id, $room_id); - return redirect('/tour/'.$tour_id); - } - - public function cancelBooking($tour_id) { - $user=Auth::user(); - Booking::where('tour_id', $tour_id)->where('user_id', $user->id)->delete(); - return redirect('/tour'); - } - - public function cancelBookingAdmin($tour_id, $user_id) { - $user=Auth::user(); - if (Auth::user()->role == "ADMIN") { - Booking::where('tour_id', $tour_id)->where('user_id', $user_id)->delete(); } - return redirect('/tour/'.$tour_id); - } - public function create_room($tour_id,$capacity) { - Log::info("create_room Controller started"); - $user=Auth::user(); - Tour::create_room($tour_id,$capacity); - return redirect('tour/'.$tour_id.'/edit'); - } - public function delete_room($tour_id,$room_id) { - Log::info("create_room Controller started"); - $user=Auth::user(); + /* + public function create_room($tour_id, $capacity) { + DB::delete("INSERT INTO booking_rooms") + } + */ - Booking::where('tour_id', $tour_id)->where('room_id', $room_id)->delete(); - DB::delete("DELETE FROM tour_rooms WHERE tour_id = ? AND id = ?",[$tour_id, $room_id]); - return redirect('tour/'.$tour_id.'/edit'); + public function upload_gallery(Request $request, Tour $tour) + { + dd($request); + } + + + /** + * Remove the specified resource from storage. + * + * @param \App\Tour $tour + * @return \Illuminate\Http\Response + */ + public function destroy(Tour $tour) + { + // + } + + public function join_room($tour_id, $room_id) + { + Log::info("TourController::join_room"); + $user_id = Auth::user()->id; + Tour::join_room($tour_id, $user_id, $room_id); + return redirect('/tour/' . $tour_id); + } + + public function join_room4user($tour_id, $room_id, $user_id) + { + Log::info("TourController::join_room"); + Tour::join_room($tour_id, $user_id, $room_id); + + $tour = Tour::find($tour_id); + $tour->start = Tour::toGermanDate($tour->start); + $tour->deadline = Tour::toGermanDate($tour->deadline); + + $rooms = $this->fetch_rooms($tour->id); + + return view('tour.edit') + ->with('tour', $tour) + ->with('rooms', $rooms); + + return redirect('/tour/' . $tour_id); + } + + public function cancelBooking($tour_id) + { + $user = Auth::user(); + Booking::where('tour_id', $tour_id)->where('user_id', $user->id)->delete(); + return redirect('/tour'); + } + + public function cancelBookingAdmin($tour_id, $user_id) + { + $user = Auth::user(); + if (Auth::user()->role == "ADMIN") { + Booking::where('tour_id', $tour_id)->where('user_id', $user_id)->delete(); + } + return redirect('/tour/' . $tour_id); + } + + public function create_room($tour_id, $capacity) + { + Log::info("create_room Controller started"); + $user = Auth::user(); + Tour::create_room($tour_id, $capacity); + return redirect('tour/' . $tour_id . '/edit'); + } + + public function delete_room($tour_id, $room_id) + { + Log::info("create_room Controller started"); + $user = Auth::user(); + + DB::update("UPDATE bookings SET room_id=0 WHERE room_id=" . $room_id); + DB::delete("DELETE FROM tour_rooms WHERE tour_id = ? AND id = ?", [$tour_id, $room_id]); + return redirect('tour/' . $tour_id . '/edit'); + } } -} diff --git a/motorradig/app/Http/Controllers/UserController.php b/motorradig/app/Http/Controllers/UserController.php index 138a77f..ffc6f70 100644 --- a/motorradig/app/Http/Controllers/UserController.php +++ b/motorradig/app/Http/Controllers/UserController.php @@ -1,144 +1,164 @@ with('users',$users); - } - - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() - { - // - } - - /** - * Store a newly created resource in storage. - * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response - * / - public function store(Request $request) - { - - } - - /** - * Display the specified resource. - * - * @param \App\User $user - * @return \Illuminate\Http\Response - */ - public function show($id) - { - //Log("show user id=".$id); - error_log("(show)=>".$id); - - $user=User::find($id); - - - return view('users.show')->with('user',$user); - - } - - /** - * Show the form for editing the specified resource. - * - * @param \App\User $user - * @return \Illuminate\Http\Response - */ - public function edit($id) - { - error_log("Edit:".$id); - $user=User::find($id); - - error_log($user); - return view('users.edit')->with('user',$user); - } - - /** - * Update the specified resource in storage. - * - * @param \Illuminate\Http\Request $request - * @param \App\User $user - * @return \Illuminate\Http\Response - */ - public function update(Request $request, User $user) - { - $user=User::find($request->input('id')); - - $request->validate( - [ - 'name'=>'required|min:3', - 'email'=>'required|email', - 'role'=>'required', - 'mobile'=>'required', - 'bild'=>'mimes:jpg,jpeg,bmp,png,gif' - ] - ); - - if ($request->bild){ - $bild = Image::make($request->bild); - $breite = $bild->width(); - $hoehe = $bild->height(); - if ($breite>$hoehe) { - Image::make($request->bild) - ->widen(1200) - ->save(storage_path().'/img_storage/user/'.$user->id.'_gross.jpg'); - Image::make($request->bild) - ->widen(64) - ->save(storage_path().'/img_storage/user/'.$user->id.'.jpg'); - }else { - Image::make($request->bild) - ->heighten(900) - ->save(storage_path().'/img_storage/user/'.$user->id.'_gross.jpg'); - Image::make($request->bild) - ->widen(96) - ->save(storage_path().'/img_storage/user/'.$user->id.'.jpg'); - } + /** + * Display a listing of the resource. + * + * @return \Illuminate\Http\Response + */ + public function index() + { + $users = User::all(); + return view('users.index')->with('users', $users); } - $user->name=$request->input('name'); - $user->email=$request->input('email'); - $user->role=$request->input('role'); - $user->mobile=$request->input('mobile'); - $user->save(); + /** + * Show the form for creating a new resource. + * + * @return \Illuminate\Http\Response + */ + public function create() + { + // + } - error_log("User role: ".$user->role); + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\Request $request + * @param \App\User $user + * @return \Illuminate\Http\Response + * / + * public function store(Request $request) + * { + * + * } + * + * /** + * Display the specified resource. + * + * @return \Illuminate\Http\Response + */ + public function show($id) + { + //Log("show user id=".$id); + error_log("(show)=>" . $id); + + $user = User::find($id); + + + return view('users.show')->with('user', $user); + + } + + /** + * Show the form for editing the specified resource. + * + * @param \App\User $user + * @return \Illuminate\Http\Response + */ + public function edit($id) + { + + error_log("Edit:" . $id); + $user = User::find($id); + + if (Auth::user()->role != 'ADMIN' && $user->id != Auth::user()->id) { + return redirect('/users'); + } + + + error_log($user); + return view('users.edit')->with('user', $user); + } + + /** + * Update the specified resource in storage. + * + * @param \Illuminate\Http\Request $request + * @param \App\User $user + * @return \Illuminate\Http\Response + */ + public function update(Request $request, User $user) + { + $user = User::find($request->input('id')); + + $request->validate( + [ + 'name' => 'required|min:3', + 'email' => 'required|email', + 'role' => 'required', + 'mobile' => 'required', + 'bild' => 'mimes:jpg,jpeg,bmp,png,gif' + ] + ); + + if ($request->bild) { + $bild = Image::make($request->bild); + $breite = $bild->width(); + $hoehe = $bild->height(); + if ($breite > $hoehe) { + Image::make($request->bild) + ->widen(1200) + ->save(storage_path() . '/img_storage/user/' . $user->id . '_gross.jpg'); + Image::make($request->bild) + ->widen(64) + ->save(storage_path() . '/img_storage/user/' . $user->id . '.jpg'); + } else { + Image::make($request->bild) + ->heighten(900) + ->save(storage_path() . '/img_storage/user/' . $user->id . '_gross.jpg'); + Image::make($request->bild) + ->widen(96) + ->save(storage_path() . '/img_storage/user/' . $user->id . '.jpg'); + } + } + + $user->name = $request->input('name'); + $user->email = $request->input('email'); + $user->role = $request->input('role'); + $user->mobile = $request->input('mobile'); + $user->save(); + + error_log("User role: " . $user->role); + + return redirect('/member/'); + + } + + /** + * Remove the specified resource from storage. + * + * @param \App\User $user + * @return \Illuminate\Http\Response + */ + public function destroy($user_id) + { + $user = User::find($user_id); + Log::info("UserController::destroy for user_id " . $user->id); + + Log::info("Preparing to destroy user [" . $user->id . "]" . $user->name); + Log::info("#DESTROY_USER [users]" . $user); + + $tours = DB::select("SELECT id FROM tours WHERE user_id=" . $user_id); + Log::info('#DESTROY_USER [affected tour ids]', $tours); + $bookings = DB::select("SELECT id FROM bookings WHERE user_id=" . $user_id); + Log::info("#DESTROY_USER [affected booking ids]", $bookings); + + DB::delete('DELETE FROM users WHERE id=' . $user->id); + + return redirect('/member/'); + } - return redirect('/member/'); } - - /** - * Remove the specified resource from storage. - * - * @param \App\User $user - * @return \Illuminate\Http\Response - */ - public function destroy(User $user) - { - // - } - - - -} diff --git a/motorradig/app/Tour.php b/motorradig/app/Tour.php index 24b2c26..f29823b 100644 --- a/motorradig/app/Tour.php +++ b/motorradig/app/Tour.php @@ -1,88 +1,107 @@ get(); - return $bookings; - } - - public static function has_participant($tour_id, $user_id) { - $booking=Booking::where('tour_id', $tour_id)->where('user_id',$user_id)->first(); - - if($booking) return true; - - return false; - } - - // new join with room parameter - public static function join_room($tour_id, $user_id, $room_id) { - Log::info("Tour::join_room, tour_id=".$tour_id.", user_id=".$user_id.", room_id=".$room_id); - $booking = Booking::firstOrCreate( - ['tour_id' => $tour_id, 'user_id' => $user_id], // Retrieve if existing - ['tour_id' => $tour_id, 'user_id' => $user_id, 'room_id' => $room_id, - 'created_at' => Carbon::now(), 'updated_at' => Carbon::now() ] // or create new - ); - $booking->room_id=$room_id; - $booking->save(); - //Log::info($booking); - } - - public static function cancel($tour_id, $user_id) { - Booking::where('tour_id',$tour_id)->where('user_id',$user_id)->delete(); - } - - public static function is_over($tour_id) { - $tour = Tour::find($tour_id); - if ($tour->start < Carbon::now()) return true; - return false; - } - - public static function create_room($tour_id,$capacity) { - $tour = Tour::find($tour_id); - $name="Einzelzimmer"; - if ($capacity!=1) { $name="Doppelzimmer";} - $sql="INSERT INTO tour_rooms (name,tour_id,capacity,created_at,updated_at) VALUES ('".$name."',".$tour_id.",".$capacity.",now(),now());"; - DB::insert($sql); - } - - public static function toGermanDate($engDate) + class Tour extends Model { - error_log("to german Date:"); - error_log($engDate); - $values = explode("-", $engDate); - $year = $values[0]; - $month = $values[1]; - $day = $values[2]; + protected $fillable = [ + 'id', 'name', 'beschreibung', 'user_id', 'start', 'deadline', 'is_cancelled', 'status', 'bericht', 'max_participants' + ]; - return $day.".".$month.".".$year; + public static function getBookings($tour_id) + { + error_log("getBookings for tour_id: " . $tour_id); + $bookings = Booking::where('tour_id', $tour_id)->get(); + return $bookings; + } + + public static function has_participant($tour_id, $user_id) + { + $booking = Booking::where('tour_id', $tour_id)->where('user_id', $user_id)->first(); + if ($booking) return true; + return false; + } + + public static function has_space($tour_id) + { + //$tour = Tour::where("id", $tour_id)->get(); + //Log::info($tour[0]); + $tour = Tour::find($tour_id); + //Log::info($tour); + + $bookings = Booking::where('tour_id', $tour_id)->get(); + if (count($bookings) >= $tour->max_participants) return false; + + return true; + } + + // new join with room parameter + public static function join_room($tour_id, $user_id, $room_id) + { + Log::info("Tour::join_room, tour_id=" . $tour_id . ", user_id=" . $user_id . ", room_id=" . $room_id); + $booking = Booking::firstOrCreate( + ['tour_id' => $tour_id, 'user_id' => $user_id], // Retrieve if existing + ['tour_id' => $tour_id, 'user_id' => $user_id, 'room_id' => $room_id, + 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()] // or create new + ); + $booking->room_id = $room_id; + $booking->save(); + //Log::info($booking); + } + + public static function cancel($tour_id, $user_id) + { + Booking::where('tour_id', $tour_id)->where('user_id', $user_id)->delete(); + } + + public static function is_over($tour_id) + { + $tour = Tour::find($tour_id); + if ($tour->start < Carbon::now()) return true; + return false; + } + + public static function create_room($tour_id, $capacity) + { + $tour = Tour::find($tour_id); + $name = "Einzelzimmer"; + if ($capacity != 1) { + $name = "Doppelzimmer"; + } + $sql = "INSERT INTO tour_rooms (name,tour_id,capacity,created_at,updated_at) VALUES ('" . $name . "'," . $tour_id . "," . $capacity . ",now(),now());"; + DB::insert($sql); + } + + public static function toGermanDate($engDate) + { + error_log("to german Date:"); + error_log($engDate); + $values = explode("-", $engDate); + $year = $values[0]; + $month = $values[1]; + $day = $values[2]; + + return $day . "." . $month . "." . $year; + } + + public static function toDBDate($deDate) + { + if (!$deDate) return ""; + + $values = explode(" ", $deDate); + + $year = explode(".", $values[0])[2]; + $month = explode(".", $values[0])[1]; + $day = explode(".", $values[0])[0]; + + $dbDate = $year . "-" . $month . "-" . $day; + //Log::info("deDate=".$deDate." converted to:".$dbDate); + + return $dbDate; + } } - - public static function toDBDate($deDate) - { - if (!$deDate) return ""; - - $values = explode(" ", $deDate); - - $year = explode(".",$values[0])[2]; - $month = explode(".",$values[0])[1]; - $day = explode(".", $values[0])[0]; - - $dbDate=$year . "-" . $month . "-" . $day; - //Log::info("deDate=".$deDate." converted to:".$dbDate); - - return $dbDate; - } -} diff --git a/motorradig/app/User.php b/motorradig/app/User.php index 148f121..64ebd96 100644 --- a/motorradig/app/User.php +++ b/motorradig/app/User.php @@ -1,47 +1,48 @@ 'datetime', - ]; + /** + * The attributes that should be cast to native types. + * + * @var array + */ + protected $casts = [ + 'email_verified_at' => 'datetime', + ]; - public static function has_tour($tour_id, $user_id) { - $tour=Tour::find($tour_id); - $user=User::first($user_id); - $booking=Booking::where('tour_id', $tour_id)->where('user_id', $user_id); - if ($booking) return true; - return false; + public static function has_tour($tour_id, $user_id) + { +// $tour=Tour::find($tour_id); +// $user=User::first($user_id); + $booking = Booking::where('tour_id', $tour_id)->where('user_id', $user_id); + if ($booking) return true; + return false; + } } -} diff --git a/motorradig/resources/views/auth/register.blade.php b/motorradig/resources/views/auth/register.blade.php index 057ed07..9b3f1c0 100644 --- a/motorradig/resources/views/auth/register.blade.php +++ b/motorradig/resources/views/auth/register.blade.php @@ -39,6 +39,21 @@ +
+ + +
+ + + @error('email') + + {{ $message }} + + @enderror +
+
+ +
diff --git a/motorradig/resources/views/tour/edit.blade.php b/motorradig/resources/views/tour/edit.blade.php index 1d5c344..8631993 100644 --- a/motorradig/resources/views/tour/edit.blade.php +++ b/motorradig/resources/views/tour/edit.blade.php @@ -13,8 +13,8 @@
- -
+ @csrf @@ -24,134 +24,284 @@
- - + +
- - + +
- - + +
- - + +
- + @if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg'))) - - + + @else - + @endif - +
- - is_cancelled) - checked + + is_cancelled) + checked @endif >
-
-
Abbrechen
+ +
Abbrechen
+
-
-
- -
-
-
Teilnehmer
+ -
-

- - @if ($room_id="") @endif - @foreach($rooms as $room) - @if ($room_id != $room->room_id) - @if(strlen($room_id)) -


- @endif -

[{{$room->room_id}}] {{$room->room_name}} - @if($room->room_id>0) - - (X) Raum Löschen - - @endif -

+ + + +
+
+
+
Teilnehmer
+ +
+ + + @if ($room_id="") @endif + @foreach($rooms as $room) + + @if ($room_id != $room->room_id) + @if($room_id!="") + @if($room->room_name=="Ungebucht") +
+ @else +
+ @endif + @endif + +
+
{{$room->room_name}} + @if( $room->room_name != "Ungebucht" ) + + + (X) Raum Löschen + + @endif +
+ + + @if ($room_id=$room->room_id) @endif + @endif + + @if(strlen($room->user_name)) +
  {{ $room->user_name}} + @if( $room->room_name == "Ungebucht" ) + + (+) + Zimmer zuweisen + + @else + + (-) + Zimmer-Zuweisung löschen + + @endif + +
+ @endif + + + @endforeach + +
+ + +
+ + + + + @endsection diff --git a/motorradig/resources/views/tour/show.blade.php b/motorradig/resources/views/tour/show.blade.php index b1d23be..de2211e 100644 --- a/motorradig/resources/views/tour/show.blade.php +++ b/motorradig/resources/views/tour/show.blade.php @@ -2,13 +2,7 @@ @section('content') - -
- - - -
@@ -18,33 +12,41 @@
-
+ @csrf
- +
- +
- +
- +
- - + +
@if(App\Tour::has_participant($tour->id, Auth::user()->id)) @@ -55,17 +57,20 @@ @if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg'))) - - - + + + @else - + @endif
- - Storniert: + is_cancelled) checked @endif @@ -79,29 +84,31 @@
-
Bearbeiten
+ @if(Auth::user()->role=="ADMIN") + +
Bearbeiten +
+
+ @endif Ok - @if(!App\Tour::has_participant($tour->id, Auth::user()->id)) + @if(!App\Tour::has_participant($tour->id, Auth::user()->id) && App\Tour::has_space($tour->id)) - @else - Absagen + @endif + @if(App\Tour::has_participant($tour->id, Auth::user()->id)) + Absagen @endif
- - - - - - +
@@ -150,39 +159,49 @@
-
    - - @if ($room_id="") @endif - @foreach($rooms as $room) - @if ($room_id != $room->room_id) - @if(strlen($room_id)) -

    -------------------------

    - @endif -

    [{{$room->room_id}}] {{$room->room_name}}

    - - @if ($room_id=$room->room_id) @endif - @endif + + @if ($room_id="") @endif + @foreach($rooms as $room) - @if(strlen($room->user_name)) -
  • {{ $room->user_name}} - @if(Auth::user()->role=="ADMIN") - (X) - Stornieren - - @endif -
  • - @endif - - @endforeach -
+ @if ($room_id != $room->room_id) + @if($room_id!="") + @if($room->room_name=="Ungebucht")
- +
+ @else
+
+ @endif + @endif + +
+
{{$room->room_name}} + @if( $room->room_name != "Ungebucht" ) + _{{$room->room_id}}
+ @endif + + + @if ($room_id=$room->room_id) @endif + @endif + + @if(strlen($room->user_name)) +
  {{ $room->user_name}} + +
+ @endif + + @endforeach +
+
+
- + + + + @@ -205,19 +224,19 @@ var span = document.getElementsByClassName("close")[0]; // When the user clicks on the button, open the modal - btn.onclick = function(e) { + btn.onclick = function (e) { e.preventDefault(); modal.style.display = "block"; } // When the user clicks on (x), close the modal - span.onclick = function(e) { + span.onclick = function (e) { e.preventDefault(); modal.style.display = "none"; } // When the user clicks anywhere outside of the modal, close it - window.onclick = function(event) { + window.onclick = function (event) { if (event.target == modal) { modal.style.display = "none"; } diff --git a/motorradig/resources/views/users/edit.blade.php b/motorradig/resources/views/users/edit.blade.php index 8c96bc0..cf8d455 100644 --- a/motorradig/resources/views/users/edit.blade.php +++ b/motorradig/resources/views/users/edit.blade.php @@ -4,63 +4,82 @@

{{$user->name}}

-
+ @csrf @method('PUT')
- +
- - + +
- - + +
- + @if(file_exists (storage_path().'/img_storage/user/'.$user->id.'.jpg')) - - + + @else - + @endif - +
@if(Auth::user()->role=="ADMIN")
- + - + + +
@else
- +

{{$user->role}}

@endif + Zurück + @if(Auth::user()->role=="ADMIN" || Auth::user()->id==$user->id) + Löschen @endif - Zurück
@@ -69,12 +88,10 @@