diff --git a/app/Http/Controllers/Admin/PirepController.php b/app/Http/Controllers/Admin/PirepController.php
index 578b951c..d4e49a90 100644
--- a/app/Http/Controllers/Admin/PirepController.php
+++ b/app/Http/Controllers/Admin/PirepController.php
@@ -141,11 +141,12 @@ class PirepController extends BaseController
*/
public function store(CreatePirepRequest $request)
{
- $input = $request->all();
- $pirep = $this->pirepRepo->create($input);
+ $attrs = $request->all();
+ $pirep = $this->pirepRepo->create($attrs);
- $pirep->flight_time = ((int) Utils::hoursToMinutes($request['hours']))
- + ((int) $request['minutes']);
+ $hours = (int) $attrs['hours'];
+ $minutes = (int) $attrs['minutes'];
+ $pirep->flight_time = Utils::hoursToMinutes($hours) + $minutes;
Flash::success('Pirep saved successfully.');
return redirect(route('admin.pireps.index'));
@@ -187,8 +188,15 @@ class PirepController extends BaseController
$pirep->hours = $hms['h'];
$pirep->minutes = $hms['m'];
+ # Can we modify?
+ $read_only = false;
+ if($pirep->state !== PirepState::PENDING) {
+ $read_only = false;
+ }
+
return view('admin.pireps.edit', [
'pirep' => $pirep,
+ 'read_only' => $read_only,
'aircraft' => $this->aircraftList(),
'airports' => $this->airportRepo->selectBoxList(),
'airlines' => $this->airlineRepo->selectBoxList(),
@@ -205,16 +213,21 @@ class PirepController extends BaseController
{
$pirep = $this->pirepRepo->findWithoutFail($id);
- $pirep->flight_time = ((int) Utils::hoursToMinutes($request['hours']))
- + ((int) $request['minutes']);
-
if (empty($pirep)) {
Flash::error('Pirep not found');
return redirect(route('admin.pireps.index'));
}
- $attrs = $request->all();
$orig_route = $pirep->route;
+ $orig_flight_time = $pirep->flight_time;
+
+ $attrs = $request->all();
+
+ # Fix the time
+ $hours = (int) $attrs['hours'];
+ $minutes = (int) $attrs['minutes'];
+ $attrs['flight_time'] = Utils::hoursToMinutes($hours) + $minutes;
+
$pirep = $this->pirepRepo->update($attrs, $id);
// A route change in the PIREP, so update the saved points in the ACARS table
@@ -257,12 +270,12 @@ class PirepController extends BaseController
$pirep = $this->pirepRepo->findWithoutFail($request->id);
if($request->isMethod('post')) {
- $new_status = (int) $request->new_status;
+ $new_status = (int) $request->post('new_status');
$pirep = $this->pirepSvc->changeState($pirep, $new_status);
}
$pirep->refresh();
- return view('admin.pireps.actions', ['pirep' => $pirep]);
+ return view('admin.pireps.actions', ['pirep' => $pirep, 'on_edit_page' => false]);
}
/**
diff --git a/app/Models/Pirep.php b/app/Models/Pirep.php
index 2348ec7d..4ae6a410 100644
--- a/app/Models/Pirep.php
+++ b/app/Models/Pirep.php
@@ -99,6 +99,16 @@ class Pirep extends BaseModel
return $flight_id;
}
+ /**
+ * Do some cleanup on the route
+ * @param $route
+ */
+ public function setRouteAttribute($route)
+ {
+ $route = strtoupper(trim($route));
+ $this->attributes['route'] = $route;
+ }
+
/**
* Check if this PIREP is allowed to be updated
* @return bool
diff --git a/resources/views/admin/app.blade.php b/resources/views/admin/app.blade.php
index f41516a2..326f0f9b 100644
--- a/resources/views/admin/app.blade.php
+++ b/resources/views/admin/app.blade.php
@@ -21,6 +21,12 @@
@endsection