diff --git a/app/Http/Controllers/ChangePasswordController.php b/app/Http/Controllers/ChangePasswordController.php new file mode 100644 index 0000000..cee1153 --- /dev/null +++ b/app/Http/Controllers/ChangePasswordController.php @@ -0,0 +1,40 @@ +middleware('auth'); + } + + public function create() + { + return view('changePassword'); + } + + + public function update(Request $request) + { + $request->validate([ + 'current_password' => new ComparePasswords, + 'password' => 'required|confirmed|min:6|different:current_password', + ], + [ + 'required' => 'Podaj nowe hasło.', + 'confirmed' => 'Nowe hasło się nie zgadza.', + 'min' => ':attribute musi mieć przynajmniej :min znaków.', + 'different' => 'Stare i nowe hasło nie mogą być identyczne.' + ]); + + User::find(auth()->user()->id)->update(['password'=> $request-> password]); + + return redirect()->to('/userprofile')->with('success','Hasło zostało zmienione'); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/DecorationsController.php b/app/Http/Controllers/DecorationsController.php new file mode 100644 index 0000000..fb4ece1 --- /dev/null +++ b/app/Http/Controllers/DecorationsController.php @@ -0,0 +1,72 @@ +user() != null && auth()->user()->fireStationID != null ){ + $awardedDecorations = DB::table('decorationsFirefighters')->where("decorationsFirefighters.firefighterID", '=', $id) + ->whereNull('decorationsFirefighters.deleted_at') + ->leftJoin('decorations', 'decorationsFirefighters.decorationID', '=', 'decorations.id') + ->select('decorationName', 'dateOfAward', 'firefighterID', 'decorations.id AS decorationsId', 'decorationsFirefighters.id AS decorationsFirefightersID') + ->get(); + $alreadyAwarded = $awardedDecorations->pluck('decorationsId')->toArray(); // tablica id wszystkich wyróżnień już posiadanych + $firefighter = User::find($id, ['id', 'name', 'surname']); + $decoration = DB::table('decorations') + ->whereNotIn('id', $alreadyAwarded) //ograniczenie wyboru do wyróżnień jeszcze nie posiadanych + ->pluck('decorationName', 'id'); + + return View::make("decorations") + ->with(compact('firefighter')) + ->with(compact('awardedDecorations')) + ->with(compact('decoration')); + + } else{ + return "Brak dostepu"; + } + } + + public function store() + { + $this->validate(request(),[ + 'decoration' => 'required', + 'dateOfAward' => 'required', + ], + [ + 'required' => ':attribute jest wymagany(e).', + ]); + + $request = request(); + $decoration = decorationsFirefighters::create([ + 'firefighterID' => $request-> firefighterID, + 'decorationID' => $request-> decoration, + 'dateOfAward' => formatDate($request-> dateOfAward), + ]); + + return back(); + } + + public function destroy($id) + { + decorationsFirefighters::where('id',$id)->delete(); + + return back(); + } +} diff --git a/app/Http/Controllers/VehiclesController.php b/app/Http/Controllers/VehiclesController.php index 276a5c8..ae4099b 100644 --- a/app/Http/Controllers/VehiclesController.php +++ b/app/Http/Controllers/VehiclesController.php @@ -90,6 +90,7 @@ class VehiclesController extends Controller 'chassisPoductionYear' => $request-> chassisPoductionYear, 'entryIntoServiceDate' => formatDate($request-> entryIntoServiceDate), 'fireEnginePumpDescription' => $request-> fireEnginePumpDescription, + 'status' => $request-> status ]); return redirect()->to('/pojazdy'); @@ -137,6 +138,7 @@ class VehiclesController extends Controller $vehicle-> chassisPoductionYear = $request-> chassisPoductionYear; $vehicle-> entryIntoServiceDate = formatDate($request-> entryIntoServiceDate); $vehicle-> fireEnginePumpDescription = $request-> fireEnginePumpDescription; + $vehicle-> status = $request-> status; $vehicle->save(); return redirect()->to('/pojazdy');; @@ -147,4 +149,22 @@ class VehiclesController extends Controller vehicle::where('id',$id)->delete(); return redirect()->to('/pojazdy'); } + + public function activate() + { + $request = request(); + $vehicle = vehicle::find( $request-> vehicleID); + $vehicle-> status = 1; + $vehicle->save(); + return redirect()->to('/pojazdy'); + } + + public function deactivate() + { + $request = request(); + $vehicle = vehicle::find( $request-> vehicleID); + $vehicle-> status = 0; + $vehicle->save(); + return redirect()->to('/pojazdy'); + } } diff --git a/app/Http/Controllers/fireStationController.php b/app/Http/Controllers/fireStationController.php index cc5b8d2..817bd6a 100644 --- a/app/Http/Controllers/fireStationController.php +++ b/app/Http/Controllers/fireStationController.php @@ -24,7 +24,7 @@ class fireStationController extends Controller if(auth()->user() != null && auth()->user()->fireStationID != null ) { $id = auth()->user()->fireStationID; - $fireStation = DB::table('firestations')->where("id", $id)->first(); + $fireStation = DB::table('fireStations')->where("id", $id)->first(); $voivodeships = DB::table('wojewodztwa')->pluck("name","id"); return view('fireStationEdit', ["fireStation" => $fireStation], compact('voivodeships')); } diff --git a/app/Http/Controllers/userProfileController.php b/app/Http/Controllers/userProfileController.php index 03209cc..60d87dd 100644 --- a/app/Http/Controllers/userProfileController.php +++ b/app/Http/Controllers/userProfileController.php @@ -69,4 +69,30 @@ class userProfileController extends Controller return redirect()->to('/userprofile');; } + + public function userTrainings(){ + + if(auth()->user() != null && auth()->user()->fireStationID != null ){ + $userTrainings = DB::table('trainingsFirefighters')->where("trainingsFirefighters.firefighterID", '=', auth()->user()->id) + ->leftJoin('trainings', 'trainingsFirefighters.trainingID', '=', 'trainings.id') + ->select('trainingsFirefighters.id','trainings.trainingName','trainingsFirefighters.dateOfComplete', 'trainingsFirefighters.dateOfExpiry') + ->get(); + return view("userTrainings", ["userTrainings" => $userTrainings]); + } + else{ + return redirect()->to('/login');; + } + } + + public function userDecorations(){ + if(auth()->user() != null && auth()->user()->fireStationID != null ){ + $userDecorations = DB::table('decorationsFirefighters')->where("decorationsFirefighters.firefighterID", '=', auth()->user()->id) + ->whereNull('decorationsFirefighters.deleted_at') + ->leftJoin('decorations', 'decorationsFirefighters.decorationID', '=', 'decorations.id') + ->get(); + return view("userDecorations", ["userDecorations" => $userDecorations]); + } else{ + return "Brak dostepu"; + } + } } diff --git a/app/Rules/ComparePasswords.php b/app/Rules/ComparePasswords.php new file mode 100644 index 0000000..b697935 --- /dev/null +++ b/app/Rules/ComparePasswords.php @@ -0,0 +1,41 @@ +user()->password); + } + + /** + * Get the validation error message. + * + * @return string + */ + public function message() + { + return 'Obecne hasło jest niepoprawne.'; + } +} diff --git a/app/decorationsFirefighters.php b/app/decorationsFirefighters.php new file mode 100644 index 0000000..e98da75 --- /dev/null +++ b/app/decorationsFirefighters.php @@ -0,0 +1,15 @@ +integer('status')->default('0'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('vehicles', function (Blueprint $table) { + // + }); + } +} diff --git a/database/migrations/2019_12_31_001536_create_decorations_table.php b/database/migrations/2019_12_31_001536_create_decorations_table.php new file mode 100644 index 0000000..67971a6 --- /dev/null +++ b/database/migrations/2019_12_31_001536_create_decorations_table.php @@ -0,0 +1,42 @@ +integer('id'); + $table->string('decorationName'); + }); + + DB::table('decorations')->insert([ 'id' => '1', 'decorationName' => 'Odznaka "Młodzieżowa Drużyna Pożarnicza" - brązowa' ]); + DB::table('decorations')->insert([ 'id' => '2', 'decorationName' => 'Odznaka "Młodzieżowa Drużyna Pożarnicza" - srebrna' ]); + DB::table('decorations')->insert([ 'id' => '3', 'decorationName' => 'Odznaka "Młodzieżowa Drużyna Pożarnicza" - złota' ]); + DB::table('decorations')->insert([ 'id' => '4', 'decorationName' => 'Odznaka "Za wysługę lat"' ]); + DB::table('decorations')->insert([ 'id' => '5', 'decorationName' => 'Odznaka "Strażak Wzorowy"' ]); + DB::table('decorations')->insert([ 'id' => '6', 'decorationName' => 'Medal "Za Zasługi dla Pożarnictwa" - brązowy' ]); + DB::table('decorations')->insert([ 'id' => '7', 'decorationName' => 'Medal "Za Zasługi dla Pożarnictwa" - srebrny' ]); + DB::table('decorations')->insert([ 'id' => '8', 'decorationName' => 'Medal "Za Zasługi dla Pożarnictwa" - złoty' ]); + DB::table('decorations')->insert([ 'id' => '9', 'decorationName' => 'Medal Honorowy im. Bolesława Chomicza' ]); + DB::table('decorations')->insert([ 'id' => '10', 'decorationName' => 'Złoty Znak Związku Ochotniczych Straży Pożarnych Rzeczypospolitej Polskiej' ]); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('decorations'); + } +} diff --git a/database/migrations/2019_12_31_003036_create_decorationsFirefighters_table.php b/database/migrations/2019_12_31_003036_create_decorationsFirefighters_table.php new file mode 100644 index 0000000..1ea2e5c --- /dev/null +++ b/database/migrations/2019_12_31_003036_create_decorationsFirefighters_table.php @@ -0,0 +1,35 @@ +increments('id'); + $table->integer('firefighterID'); + $table->integer('decorationID'); + $table->date('dateOfAward'); + $table->softDeletes(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('decorationsFirefighters'); + } +} diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index 63ecebe..4315724 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -161,7 +161,9 @@ return [ 'unitName' => 'nazwa jednostki', 'longitude' => 'długość geograficzna', 'latitude' => 'szerokość geograficzna', - 'amount' => 'ilość' + 'amount' => 'ilość', + 'decoration' => 'odznaczenie', + 'dateOfAward' => 'data przyznania' ], diff --git a/resources/views/changePassword.blade.php b/resources/views/changePassword.blade.php new file mode 100644 index 0000000..842de51 --- /dev/null +++ b/resources/views/changePassword.blade.php @@ -0,0 +1,62 @@ +@extends('layout.app') + +@section('left-menu') + @parent + +@stop + +@section('center-area') +@parent +
+
+
+
+
Zmiana hasła
+ +
+
+ @csrf +
+ + +
+ +
+
+ +
+ + +
+ +
+
+ +
+ + +
+ +
+
+ +
+
+ +
+
+ @include('inc.formerrors') +
+
+
+
+
+
+@stop \ No newline at end of file diff --git a/resources/views/decorations.blade.php b/resources/views/decorations.blade.php new file mode 100644 index 0000000..791e107 --- /dev/null +++ b/resources/views/decorations.blade.php @@ -0,0 +1,70 @@ +@extends('layout.app') + +@section('left-menu') + @parent + + @stop +@section('center-area') + @parent + + @if( auth()->check()) + @if( auth()->user()->fireStationID == NULL) + Jednostka nie istnieje + @else + @if(count($awardedDecorations) > 0) +

+ + + + + + + + @foreach($awardedDecorations as $awardedDecoration) + + + + + + + + @endforeach +
{{ $firefighter->name }} {{ $firefighter->surname }} - odznaczenia
OdznaczenieData przyznania
{{ $awardedDecoration->decorationName }}{{ $awardedDecoration->dateOfAward }} + {{ csrf_field() }} + @method('DELETE') + +
+

+ @else + {{ $firefighter->name }} {{ $firefighter->surname }} nie posiada żadnych odznaczeń. + @endif + +
+ {{ csrf_field() }} + +
+ + +
+
+ + +
+
+ +
+ @include('inc.formerrors') +
+ @endif + @else + Brak autoryzacji + @endif + +@stop \ No newline at end of file diff --git a/resources/views/fireFighters.blade.php b/resources/views/fireFighters.blade.php index a1b7975..a638fd6 100644 --- a/resources/views/fireFighters.blade.php +++ b/resources/views/fireFighters.blade.php @@ -4,7 +4,6 @@ @parent