2019-09-25 18:39:01 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\User;
|
|
|
|
use App\fireStation;
|
|
|
|
use App\Rules\Pesel;
|
2019-10-02 15:26:30 +02:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2020-01-29 21:01:06 +01:00
|
|
|
use Illuminate\Support\Facades\Input;
|
|
|
|
use Mail;
|
2019-09-25 18:39:01 +02:00
|
|
|
|
|
|
|
class fireFightersController extends Controller
|
|
|
|
{
|
|
|
|
public function create(){
|
2019-10-02 15:26:30 +02:00
|
|
|
|
2020-01-31 23:38:24 +01:00
|
|
|
if(auth()->user() != null && auth()->user()->accessLevel() >= 20) //prezes,naczelnik,sekretarz
|
|
|
|
{
|
2019-10-05 22:29:46 +02:00
|
|
|
// $users = user::where("fireStationID", auth()->user()->fireStationID)->get();
|
2019-10-06 08:16:10 +02:00
|
|
|
// $users = DB::table('users')->where("fireStationID", '=', auth()->user()->fireStationID)->get();
|
|
|
|
$users = DB::table('users')->where("fireStationID", '=', auth()->user()->fireStationID)
|
2019-11-23 15:01:59 +01:00
|
|
|
->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')
|
2020-02-01 01:18:26 +01:00
|
|
|
->paginate(10);
|
2019-10-02 15:26:30 +02:00
|
|
|
return view("fireFighters", ["users" => $users]);
|
2020-02-01 01:18:26 +01:00
|
|
|
} else {
|
2020-01-31 23:38:24 +01:00
|
|
|
return redirect()->to('/userprofile');
|
2019-10-02 15:26:30 +02:00
|
|
|
}
|
|
|
|
|
2019-09-25 18:39:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function addForm(){
|
2020-01-31 23:38:24 +01:00
|
|
|
if(auth()->user() != null && auth()->user()->accessLevel() == 50 ){ //prezes,naczelnik
|
2019-09-25 18:39:01 +02:00
|
|
|
$fireStation = fireStation::find(auth()->user()->fireStationID);
|
2020-01-31 23:38:24 +01:00
|
|
|
if($fireStation-> creatorID == auth()->user()->id){ //if do usunięcia w pzyszłości
|
2019-10-06 00:56:23 +02:00
|
|
|
$ranks = DB::table('ranks')->pluck("rank","id");
|
|
|
|
$unitFunctions = DB::table('unitFunctions')->pluck("unitFunction","id");
|
|
|
|
return view('fireFightersAdd',compact('ranks'), compact('unitFunctions'));
|
2020-01-31 23:38:24 +01:00
|
|
|
} else return fireFightersController::create(); // ???
|
|
|
|
} else return redirect()->to('/strazacy');
|
2019-09-25 18:39:01 +02:00
|
|
|
}
|
|
|
|
|
2019-10-05 22:29:46 +02:00
|
|
|
public function editForm($id){
|
2020-01-31 23:38:24 +01:00
|
|
|
if(auth()->user() != null && auth()->user()->accessLevel() == 50 ){ //prezes,naczelnik
|
2019-10-05 22:29:46 +02:00
|
|
|
$userFireStation = auth()->user()->fireStationID;
|
|
|
|
$fireFighterFireStation = DB::table('users')->where("id", $id)->value('fireStationID');
|
2019-10-06 02:15:16 +02:00
|
|
|
$fireStationCreatorId = DB::table('fireStations')->where("id", $userFireStation)->value('creatorID');
|
|
|
|
|
|
|
|
$fireFighter = DB::table('users')->where("id", $id)->first();
|
2020-01-31 23:38:24 +01:00
|
|
|
if($userFireStation == $fireFighterFireStation && auth()->user()->id == $fireStationCreatorId) { // if do usunięcia w pzyszłości
|
2019-10-06 02:15:16 +02:00
|
|
|
return view('fireFightersEdit', ["fireFighter" => $fireFighter]);
|
2019-10-05 22:29:46 +02:00
|
|
|
} else{
|
|
|
|
return "Brak dostepu";
|
|
|
|
}
|
|
|
|
}else{
|
2020-01-31 23:38:24 +01:00
|
|
|
return redirect()->to('/strazacy');
|
2019-10-05 22:29:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 18:39:01 +02:00
|
|
|
public function store(){
|
|
|
|
$this->validate(request(), [
|
|
|
|
|
2020-01-31 03:13:13 +01:00
|
|
|
'name' =>'required|min:2|max:45|regex:/^[\p{L}\040\x27-]+$/',
|
|
|
|
'surname' =>'required|min:2|max:45|regex:/^[\p{L}\040\x27-]+$/',
|
2019-09-25 18:39:01 +02:00
|
|
|
'PESEL' => new Pesel,
|
|
|
|
'phoneNumber' => 'required|digits:9',
|
|
|
|
'email' => 'required|email|unique:users',
|
2019-10-06 00:56:23 +02:00
|
|
|
'rank' => 'required',
|
|
|
|
'unitFunction' => 'required',
|
2019-09-25 18:39:01 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'required' => ':attribute jest wymagany(e).',
|
|
|
|
'min' => ':attribute musi mieć przynajmniej :min znaki.',
|
|
|
|
'max' => ':attribute musi mieć nie więcej niż :max znaków.',
|
2020-01-31 03:13:13 +01:00
|
|
|
'regex' => ':attribute może zawierać tylko litery, spacje, myślniki i apostrofy',
|
2019-09-25 18:39:01 +02:00
|
|
|
'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();
|
2020-01-29 21:01:06 +01:00
|
|
|
$confirmation_code = str_random(30);
|
|
|
|
$password = str_random(10);
|
|
|
|
|
2019-09-25 18:39:01 +02:00
|
|
|
$user = User::create([
|
2020-01-29 21:01:06 +01:00
|
|
|
'password' => $password,
|
2019-09-25 18:39:01 +02:00
|
|
|
'email' => $request-> email,
|
|
|
|
'name' => $request-> name,
|
|
|
|
'surname' => $request-> surname,
|
|
|
|
'PESEL' => $request-> PESEL,
|
|
|
|
'phoneNumber' => $request-> phoneNumber,
|
2019-10-06 00:56:23 +02:00
|
|
|
'functionID' => $request-> unitFunction,
|
|
|
|
'degreeID' => $request-> rank,
|
2019-09-25 18:39:01 +02:00
|
|
|
'number' => 'ABC123',
|
|
|
|
'fireStationID' => auth()->user()->fireStationID,
|
|
|
|
'creatorID' => auth()->user()-> id,
|
2020-01-29 21:01:06 +01:00
|
|
|
'changingID' => auth()->user()-> id,
|
|
|
|
'confirmation_code' => $confirmation_code,
|
2019-09-25 18:39:01 +02:00
|
|
|
]);
|
|
|
|
|
2020-01-29 21:01:06 +01:00
|
|
|
Mail::send('emails.newUserVerification', compact('password', 'confirmation_code'), function($message) {
|
|
|
|
$message->to(Input::get('email'), Input::get('name'))->subject('Witamy w serwisie eOSP');
|
|
|
|
});
|
|
|
|
|
2019-10-05 23:04:47 +02:00
|
|
|
return fireFightersController::create();
|
2019-09-25 18:39:01 +02:00
|
|
|
}
|
2019-10-02 15:26:30 +02:00
|
|
|
|
2019-10-06 02:15:16 +02:00
|
|
|
public function update(){
|
|
|
|
$this->validate(request(), [
|
2020-01-31 03:13:13 +01:00
|
|
|
'name' =>'required|min:2|max:45|regex:/^[\p{L}\040\x27-]+$/',
|
|
|
|
'surname' =>'required|min:2|max:45|regex:/^[\p{L}\040\x27-]+$/',
|
2019-10-06 02:15:16 +02:00
|
|
|
'PESEL' => new Pesel,
|
|
|
|
'phoneNumber' => 'required|digits:9',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'required' => ':attribute jest wymagany(e).',
|
|
|
|
'min' => ':attribute musi mieć przynajmniej :min znaki.',
|
|
|
|
'max' => ':attribute musi mieć nie więcej niż :max znaków.',
|
2020-01-31 03:13:13 +01:00
|
|
|
'regex' => ':attribute może zawierać tylko litery, spacje, myślniki i apostrofy',
|
2019-10-06 02:15:16 +02:00
|
|
|
'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->save();
|
|
|
|
|
|
|
|
return fireFightersController::create();
|
|
|
|
}
|
2019-10-02 15:26:30 +02:00
|
|
|
|
2020-02-01 01:18:26 +01:00
|
|
|
|
2020-02-01 01:03:57 +01:00
|
|
|
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->createSingleFireFighterPDF($request->userID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-31 19:07:55 +01:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2019-09-25 18:39:01 +02:00
|
|
|
}
|
|
|
|
|