user() != null && auth()->user()->accessLevel() >= 20) //prezes,naczelnik,sekretarz { // $users = user::where("fireStationID", auth()->user()->fireStationID)->get(); // $users = DB::table('users')->where("fireStationID", '=', auth()->user()->fireStationID)->get(); $users = DB::table('users')->where("fireStationID", '=', auth()->user()->fireStationID) ->leftJoin('ranks', 'users.degreeID', '=', 'ranks.id') ->leftJoin('unitFunctions', 'users.functionID', '=', 'unitFunctions.id') ->select('users.id','users.name', 'users.surname', 'users.PESEL', 'users.email', 'users.statusID', 'ranks.rank', 'unitFunctions.unitFunction') ->paginate(10); return view("fireFighters", ["users" => $users]); } else { return redirect()->to('/userprofile'); } } public function addForm(){ if(auth()->user() != null && auth()->user()->accessLevel() == 50 ){ //prezes,naczelnik $fireStation = fireStation::find(auth()->user()->fireStationID); $ranks = DB::table('ranks')->pluck("rank","id"); $unitFunctions = DB::table('unitFunctions')->pluck("unitFunction","id"); return view('fireFightersAdd',compact('ranks'), compact('unitFunctions')); } else return redirect()->to('/strazacy'); } public function editForm($id){ if(auth()->user() != null && auth()->user()->accessLevel() == 50 ){ //prezes,naczelnik $userFireStation = auth()->user()->fireStationID; $fireFighterFireStation = DB::table('users')->where("id", $id)->value('fireStationID'); $fireFighter = DB::table('users')->where("id", $id)->first(); return view('fireFightersEdit', ["fireFighter" => $fireFighter]); } else { return redirect()->to('/strazacy'); } } public function store(){ $this->validate(request(), [ 'name' =>'required|min:2|max:45|regex:/^[A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ\040\x27-]+$/', 'surname' =>'required|min:2|max:45|regex:/^[A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ\040\x27-]+$/', 'PESEL' => new Pesel, 'phoneNumber' => 'required|digits:9', 'email' => 'required|email|unique:users', 'rank' => 'required', 'unitFunction' => 'required', ], [ 'required' => ':attribute jest wymagany(e).', 'min' => ':attribute musi mieć przynajmniej :min znaki.', 'max' => ':attribute musi mieć nie więcej niż :max znaków.', 'regex' => ':attribute może zawierać tylko litery, spacje, myślniki i apostrofy', 'digits' => ':attribute musi składać się z :digits cyfr.', 'unique' =>':attribute jest już zajęty.', 'confirmed' =>':attribute się nie zgadza.', 'email' => 'Niepoprawny adres e-mail.' ]); $request = request(); $confirmation_code = str_random(30); $password = str_random(10); $user = User::create([ 'password' => $password, 'email' => $request-> email, 'name' => $request-> name, 'surname' => $request-> surname, 'PESEL' => $request-> PESEL, 'phoneNumber' => $request-> phoneNumber, 'functionID' => $request-> unitFunction, 'degreeID' => $request-> rank, 'number' => 'ABC123', 'fireStationID' => auth()->user()->fireStationID, 'creatorID' => auth()->user()-> id, 'changingID' => auth()->user()-> id, 'confirmation_code' => $confirmation_code, ]); Mail::send('emails.newUserVerification', compact('password', 'confirmation_code'), function($message) { $message->to(Input::get('email'), Input::get('name'))->subject('Witamy w serwisie eOSP'); }); return fireFightersController::create(); } public function update(){ $this->validate(request(), [ 'name' =>'required|min:2|max:45|regex:/^[A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ\040\x27-]+$/', 'surname' =>'required|min:2|max:45|regex:/^[A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ\040\x27-]+$/', 'PESEL' => new Pesel, 'phoneNumber' => 'required|digits:9', 'secondName' => 'max:45', 'fathersName' => 'max:45', 'mothersName' => 'max:45', 'homePhoneNumber' => 'max:20', 'address' => 'max:45', 'apartment'=> 'max:45', 'placeOfBirth'=> 'max:45', 'IDSeries'=> 'max:3', 'IDNumber'=> 'max:6', 'identityCardNumber'=> 'max:20', 'driversLicense'=> 'max:20', 'education'=> 'max:45', 'profession'=> 'max:45', ], [ 'required' => ':attribute jest wymagany(e).', 'min' => ':attribute musi mieć przynajmniej :min znaki.', 'max' => ':attribute musi mieć nie więcej niż :max znaków.', 'regex' => ':attribute może zawierać tylko litery, spacje, myślniki i apostrofy', 'digits' => ':attribute musi składać się z :digits cyfr.', 'unique' =>':attribute jest już zajęty.', 'confirmed' =>':attribute się nie zgadza.', 'email' => 'Niepoprawny adres e-mail.' ]); $request = request(); $fireFighter = User::find( $request->userID); $fireFighter-> name = $request->name; $fireFighter-> surname = $request->surname; $fireFighter-> PESEL = $request->PESEL; $fireFighter-> phoneNumber = $request->phoneNumber; $fireFighter-> changingID = auth()->user()-> id; $fireFighter-> secondName = $request->secondName; $fireFighter-> fathersName = $request->fathersName; $fireFighter-> mothersName = $request->mothersName; $fireFighter-> homePhoneNumber = $request->homePhoneNumber; $fireFighter-> address = $request->address; $fireFighter-> apartment = $request->apartment; $fireFighter-> placeOfBirth = $request->placeOfBirth; $fireFighter-> joiningOSPDate = $request->joiningOSPDate; $fireFighter-> IDSeries = $request->IDSeries; $fireFighter-> IDNumber = $request->IDNumber; $fireFighter-> IDValidUntil = $request->IDValidUntil; $fireFighter-> identityCardNumber = $request->identityCardNumber; $fireFighter-> driversLicense= $request->driversLicense; $fireFighter-> education = $request->education; $fireFighter-> profession = $request->profession; $fireFighter->save(); return fireFightersController::create(); } public function createSingleFireFighterPDF(){ if (auth()->user() != null && auth()->user()->fireStationID != null) { $request = request(); $test = new documentCreators(); $test->createSingleFireFighterPDF($request->userID); } } public function CreateAllFireFightersPDF(){ if (auth()->user() != null && auth()->user()->fireStationID != null) { $request = request(); $test = new documentCreators(); $test->CreateAllFireFightersPDF($request->fireStationID); } } public function activate() { $request = request(); $user = User::find( $request-> userID); $user-> statusID = 0; $user->save(); return redirect()->to('/strazacy'); } public function deactivate() { $request = request(); $user = User::find( $request-> userID); $user-> statusID = 1; $user->save(); return redirect()->to('/strazacy'); } }