1
0
forked from s421507/eOSP2

Edycja strazakow

This commit is contained in:
czup 2019-10-06 02:15:16 +02:00
parent e00f575f94
commit a66e11509a
6 changed files with 63 additions and 16 deletions

View File

@ -16,7 +16,6 @@ class fireFightersController extends Controller
if(auth()->user() != null && auth()->user()->fireStationID != null ){ if(auth()->user() != null && auth()->user()->fireStationID != null ){
// $users = user::where("fireStationID", auth()->user()->fireStationID)->get(); // $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)->get();
echo "<script type='text/javascript'>alert('test');</script>";
return view("fireFighters", ["users" => $users]); return view("fireFighters", ["users" => $users]);
} else{ } else{
return view('fireFighters'); return view('fireFighters');
@ -37,8 +36,11 @@ class fireFightersController extends Controller
if(auth()->user() != null && auth()->user()->fireStationID != null ){ if(auth()->user() != null && auth()->user()->fireStationID != null ){
$userFireStation = auth()->user()->fireStationID; $userFireStation = auth()->user()->fireStationID;
$fireFighterFireStation = DB::table('users')->where("id", $id)->value('fireStationID'); $fireFighterFireStation = DB::table('users')->where("id", $id)->value('fireStationID');
if($userFireStation == $fireFighterFireStation) { $fireStationCreatorId = DB::table('fireStations')->where("id", $userFireStation)->value('creatorID');
return view('fireFightersEdit');
$fireFighter = DB::table('users')->where("id", $id)->first();
if($userFireStation == $fireFighterFireStation && auth()->user()->id == $fireStationCreatorId) {
return view('fireFightersEdit', ["fireFighter" => $fireFighter]);
} else{ } else{
return "Brak dostepu"; return "Brak dostepu";
} }
@ -88,6 +90,35 @@ class fireFightersController extends Controller
return fireFightersController::create(); return fireFightersController::create();
} }
public function update(){
$this->validate(request(), [
'name' => 'required|alpha|min:3|max:45',
'surname' => 'required|alpha|min:3|max:45',
'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.',
'alpha' => ':attribute może zawierać tylko litery.',
'alpha_num' => ':attribute może zawierać tylko litery i cyfry.',
'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();
}
} }

View File

@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration class CreateUsersTable extends Migration
{ {
/** /**
* Run the migrations. * Run the migrations.

View File

@ -49,6 +49,12 @@
document.getElementById("userDegree"+id).style.backgroundColor = "#e6e6e6"; document.getElementById("userDegree"+id).style.backgroundColor = "#e6e6e6";
} }
</script> </script>
<script type="text/javascript">
function test(id){
document.getElementById("editForm"+id).style.display="block";
}
</script>
</head> </head>
@ -81,9 +87,17 @@
<td id="userFunction{{ $user->id }}">Zast. Naczelnika</td> <td id="userFunction{{ $user->id }}">Zast. Naczelnika</td>
<td id="userDegree{{ $user->id }}">Dowódca</td> <td id="userDegree{{ $user->id }}">Dowódca</td>
<td id="userStatus{{ $user->id }}">@if( $user->statusID == 0) Czynny @else Wyłączony @endif</td> <td id="userStatus{{ $user->id }}">@if( $user->statusID == 0) Czynny @else Wyłączony @endif</td>
{{-- <td><a href="{{ URL::asset('strazacy/edit/'.$user->id) }}">Edytuj<input type="button" onclick="add({{$user->id}})" value="Edytuj"> </a></td>--}} <td><a href="{{ URL::asset('strazacy/edit/'.$user->id) }}"><input type="button" onclick="" value="Edytuj"> </a></td>
<td><button class="editbtn" onclick="editUser({{$user->id}})">Edytuj</button></td>
</tr> </tr>
{{-- <tr>--}}
{{-- <form id="editForm{{$user->id}}" method="POST" action="/strazacy">--}}
{{-- {{ csrf_field() }}--}}
{{-- <div class="form-group">--}}
{{-- <label for="name">Imię:</label>--}}
{{-- <input type="text" class="form-control" id="name" name="name" value="{{ old('name') }} ">--}}
{{-- </div>--}}
{{-- </form>--}}
{{-- </tr>--}}
@endforeach @endforeach
</table>" </table>"

View File

@ -3,11 +3,11 @@
@section('left-menu') @section('left-menu')
@parent @parent
<ul> <ul>
<a href="/strazacy/add"><li>Dodaj<img src="img/left_menu_icon/add.png"></li></a> <a href="/strazacy/add"><li>Dodaj<img src="../img/left_menu_icon/add.png"></li></a>
<li>Edytuj<img src="img/left_menu_icon/edit.png"></li> <li>Edytuj<img src="../img/left_menu_icon/edit.png"></li>
<li>Wyklucz<img src="img/left_menu_icon/delete.png"></li> <li>Wyklucz<img src="../img/left_menu_icon/delete.png"></li>
<li>Zawieś<img src="img/left_menu_icon/suspended.png"></li> <li>Zawieś<img src="../img/left_menu_icon/suspended.png"></li>
<li>Więcej<img src="img/left_menu_icon/more.png"></li> <li>Więcej<img src="../img/left_menu_icon/more.png"></li>
</ul> </ul>
@stop @stop

View File

@ -15,24 +15,26 @@
@parent @parent
<form method="POST" action="/strazacy/edit"> <form method="POST" action="/strazacy/edit">
{{ csrf_field() }} {{ csrf_field() }}
<input type="hidden" class="form-control" name="userID" value="{{$fireFighter->id}}">
<div class="form-group"> <div class="form-group">
<label for="name">Imię:</label> <label for="name">Imię:</label>
<input type="text" class="form-control" id="name" name="name" value="{{ old('name') }} "> <input type="text" class="form-control" id="name" name="name" value="{{ $fireFighter->name}}">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="name">Nazwisko:</label> <label for="name">Nazwisko:</label>
<input type="text" class="form-control" id="surname" name="surname" value="{{ old('surname') }}"> <input type="text" class="form-control" id="surname" name="surname" value="{{ $fireFighter->surname }}">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="name">Pesel:</label> <label for="name">Pesel:</label>
<input type="text" class="form-control" id="PESEL" name="PESEL" value="{{ old('PESEL') }}"> <input type="text" class="form-control" id="PESEL" name="PESEL" value="{{ $fireFighter->PESEL }}">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="name">Numer telefonu:</label> <label for="name">Numer telefonu:</label>
<input type="text" class="form-control" id="phoneNumber" name="phoneNumber" value="{{ old('phoneNumber') }}"> <input type="text" class="form-control" id="phoneNumber" name="phoneNumber" value="{{ $fireFighter->phoneNumber }}">
</div> </div>

View File

@ -48,7 +48,7 @@ Route::get('/strazacy', 'fireFightersController@create');
Route::get('/strazacy/add', 'fireFightersController@addForm'); Route::get('/strazacy/add', 'fireFightersController@addForm');
Route::post('/strazacy', 'fireFightersController@store'); Route::post('/strazacy', 'fireFightersController@store');
Route::get('/strazacy/edit/{id}', 'fireFightersController@editForm'); Route::get('/strazacy/edit/{id}', 'fireFightersController@editForm');
//Route::post('/strazacy/edit', ''); Route::post('/strazacy/edit', 'fireFightersController@update');
Route::get('/jednostka', 'fireStationController@create'); Route::get('/jednostka', 'fireStationController@create');
Route::post('/jednostka', 'fireStationController@store'); Route::post('/jednostka', 'fireStationController@store');