Simbrief Edit & Download Latest OFP (#1228)
* SimBrief OFP Edit Changes aim to have ability of editing generated SimBrief Flight Plans and re-downloading. * Move url to config * Blade update and $uri change * Update simbrief_form.blade.php Used `$flight->id` along with `$user->ident` to have a more unique static id value. No details given for that fields uniqueness requirements, this will be ok I think though. Also we are passing user's simbrief userid with api to find the flight plan, both combined, no chance to get another users plan and/or any other plan of same user. * Update SimBriefController.php Move `static_id` to controller * Update simbrief_form.blade.php Read `static_id` from controller * StyleFix * Update phpvms.php * Update SimBriefService.php Co-authored-by: Nabeel S <nabeelio@users.noreply.github.com>
This commit is contained in:
@@ -70,6 +70,9 @@ class SimBriefController
|
|||||||
return redirect(route('frontend.flights.index'));
|
return redirect(route('frontend.flights.index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate SimBrief Static ID
|
||||||
|
$static_id = $user->ident.'_'.$flight->id;
|
||||||
|
|
||||||
// No aircraft selected, show selection form
|
// No aircraft selected, show selection form
|
||||||
if (!$aircraft_id) {
|
if (!$aircraft_id) {
|
||||||
// If no subfleets defined for flight get them from user
|
// If no subfleets defined for flight get them from user
|
||||||
@@ -237,6 +240,7 @@ class SimBriefController
|
|||||||
'tpayload' => $tpayload,
|
'tpayload' => $tpayload,
|
||||||
'tcargoload' => $tcargoload,
|
'tcargoload' => $tcargoload,
|
||||||
'loaddist' => implode(' ', $loaddist),
|
'loaddist' => implode(' ', $loaddist),
|
||||||
|
'static_id' => $static_id,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,6 +371,31 @@ class SimBriefController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the latest generated OFP. Pass in two additional items, the Simbrief userid and static_id
|
||||||
|
* This will get the latest edited/regenerated of from Simbrief and update our records
|
||||||
|
* We do not need to send the fares again, so used an empty array
|
||||||
|
*/
|
||||||
|
public function update_ofp(Request $request)
|
||||||
|
{
|
||||||
|
/** @var User $user */
|
||||||
|
$user = Auth::user();
|
||||||
|
$ofp_id = $request->input('ofp_id');
|
||||||
|
$flight_id = $request->input('flight_id');
|
||||||
|
$aircraft_id = $request->input('aircraft_id');
|
||||||
|
$sb_userid = $request->input('sb_userid');
|
||||||
|
$sb_static_id = $request->input('sb_static_id');
|
||||||
|
$fares = [];
|
||||||
|
|
||||||
|
$simbrief = $this->simBriefSvc->downloadOfp($user->id, $ofp_id, $flight_id, $aircraft_id, $fares, $sb_userid, $sb_static_id);
|
||||||
|
if ($simbrief === null) {
|
||||||
|
$error = new AssetNotFound(new Exception('Simbrief OFP not found'));
|
||||||
|
return $error->getResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect(route('frontend.simbrief.briefing', [$ofp_id]));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the API code
|
* Generate the API code
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ class RouteServiceProvider extends ServiceProvider
|
|||||||
Route::get('simbrief/generate', 'SimBriefController@generate')->name('simbrief.generate');
|
Route::get('simbrief/generate', 'SimBriefController@generate')->name('simbrief.generate');
|
||||||
Route::post('simbrief/apicode', 'SimBriefController@api_code')->name('simbrief.api_code');
|
Route::post('simbrief/apicode', 'SimBriefController@api_code')->name('simbrief.api_code');
|
||||||
Route::get('simbrief/check_ofp', 'SimBriefController@check_ofp')->name('simbrief.check_ofp');
|
Route::get('simbrief/check_ofp', 'SimBriefController@check_ofp')->name('simbrief.check_ofp');
|
||||||
|
Route::get('simbrief/update_ofp', 'SimBriefController@update_ofp')->name('simbrief.update_ofp');
|
||||||
Route::get('simbrief/{id}', 'SimBriefController@briefing')->name('simbrief.briefing');
|
Route::get('simbrief/{id}', 'SimBriefController@briefing')->name('simbrief.briefing');
|
||||||
Route::get('simbrief/{id}/prefile', 'SimBriefController@prefile')->name('simbrief.prefile');
|
Route::get('simbrief/{id}/prefile', 'SimBriefController@prefile')->name('simbrief.prefile');
|
||||||
Route::get('simbrief/{id}/cancel', 'SimBriefController@cancel')->name('simbrief.cancel');
|
Route::get('simbrief/{id}/cancel', 'SimBriefController@cancel')->name('simbrief.cancel');
|
||||||
|
|||||||
@@ -26,11 +26,13 @@ class SimBriefService extends Service
|
|||||||
* Check to see if the OFP exists server-side. If it does, download it and
|
* Check to see if the OFP exists server-side. If it does, download it and
|
||||||
* cache it immediately
|
* cache it immediately
|
||||||
*
|
*
|
||||||
* @param string $user_id User who generated this
|
* @param string $user_id User who generated this
|
||||||
* @param string $ofp_id The SimBrief OFP ID
|
* @param string $ofp_id The SimBrief OFP ID
|
||||||
* @param string $flight_id The flight ID
|
* @param string $flight_id The flight ID
|
||||||
* @param string $ac_id The aircraft ID
|
* @param string $ac_id The aircraft ID
|
||||||
* @param array $fares Full list of fares for the flightß
|
* @param array $fares Full list of fares for the flight
|
||||||
|
* @param string $sb_userid User's Simbrief ID (Used for Update)
|
||||||
|
* @param string $sb_static_id Static ID for the generated OFP (Used for Update)
|
||||||
*
|
*
|
||||||
* @return SimBrief|null
|
* @return SimBrief|null
|
||||||
*/
|
*/
|
||||||
@@ -39,10 +41,18 @@ class SimBriefService extends Service
|
|||||||
string $ofp_id,
|
string $ofp_id,
|
||||||
string $flight_id,
|
string $flight_id,
|
||||||
string $ac_id,
|
string $ac_id,
|
||||||
array $fares = []
|
array $fares = [],
|
||||||
|
string $sb_user_id = null,
|
||||||
|
string $sb_static_id = null
|
||||||
) {
|
) {
|
||||||
$uri = str_replace('{id}', $ofp_id, config('phpvms.simbrief_url'));
|
$uri = str_replace('{id}', $ofp_id, config('phpvms.simbrief_url'));
|
||||||
|
|
||||||
|
if ($sb_user_id && $sb_static_id) {
|
||||||
|
// $uri = str_replace('{sb_user_id}', $sb_user_id, config('phpvms.simbrief_update_url'));
|
||||||
|
// $uri = str_replace('{sb_static_id}', $sb_static_id, $uri);
|
||||||
|
$uri = 'https://www.simbrief.com/api/xml.fetcher.php?userid='.$sb_user_id.'&static_id='.$sb_static_id;
|
||||||
|
}
|
||||||
|
|
||||||
$opts = [
|
$opts = [
|
||||||
'connect_timeout' => 2, // wait two seconds by default
|
'connect_timeout' => 2, // wait two seconds by default
|
||||||
'allow_redirects' => false,
|
'allow_redirects' => false,
|
||||||
|
|||||||
@@ -52,6 +52,11 @@ return [
|
|||||||
*/
|
*/
|
||||||
'simbrief_url' => 'https://www.simbrief.com/ofp/flightplans/xml/{id}.xml',
|
'simbrief_url' => 'https://www.simbrief.com/ofp/flightplans/xml/{id}.xml',
|
||||||
|
|
||||||
|
/*
|
||||||
|
* URL for fetching an updated Simbrief flight plan via API
|
||||||
|
*/
|
||||||
|
'simbrief_update_url' => 'https://www.simbrief.com/api/xml.fetcher.php?userid={sb_user_id}&static_id={sb_static_id}',
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Your vaCentral API key
|
* Your vaCentral API key
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -7,14 +7,22 @@
|
|||||||
<h2>{{ $simbrief->xml->general->icao_airline }}{{ $simbrief->xml->general->flight_number }}
|
<h2>{{ $simbrief->xml->general->icao_airline }}{{ $simbrief->xml->general->flight_number }}
|
||||||
: {{ $simbrief->xml->origin->icao_code }} to {{ $simbrief->xml->destination->icao_code }}</h2>
|
: {{ $simbrief->xml->origin->icao_code }} to {{ $simbrief->xml->destination->icao_code }}</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-3">
|
<div class="col-sm-2">
|
||||||
@if (empty($simbrief->pirep_id))
|
@if (empty($simbrief->pirep_id))
|
||||||
<a class="btn btn-outline-info pull-right btn-lg"
|
<a class="btn btn-outline-info pull-right btn-lg"
|
||||||
style="margin-top: -10px; margin-bottom: 5px"
|
style="margin-top: -10px; margin-bottom: 5px"
|
||||||
href="{{ url(route('frontend.simbrief.prefile', [$simbrief->id])) }}">Prefile PIREP</a>
|
href="{{ url(route('frontend.simbrief.prefile', [$simbrief->id])) }}">Prefile PIREP</a>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-3">
|
<div class="col-sm-2">
|
||||||
|
@if (!empty($simbrief->xml->params->static_id) && Auth::id() == $simbrief->user_id)
|
||||||
|
<a class="btn btn-secondary pull-right btn-lg"
|
||||||
|
style="margin-top: -10px; margin-bottom: 5px"
|
||||||
|
href="#"
|
||||||
|
data-toggle="modal" data-target="#OFP_Edit">Edit OFP</a>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-2">
|
||||||
<a class="btn btn-primary pull-right btn-lg"
|
<a class="btn btn-primary pull-right btn-lg"
|
||||||
style="margin-top: -10px; margin-bottom: 5px"
|
style="margin-top: -10px; margin-bottom: 5px"
|
||||||
href="{{ url(route('frontend.simbrief.generate_new', [$simbrief->id])) }}">Generate New OFP</a>
|
href="{{ url(route('frontend.simbrief.generate_new', [$simbrief->id])) }}">Generate New OFP</a>
|
||||||
@@ -284,6 +292,31 @@
|
|||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{-- SimBrief Edit Modal --}}
|
||||||
|
@if(!empty($simbrief->xml->params->static_id))
|
||||||
|
<div class="modal fade" id="OFP_Edit" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog" style="max-width: 1020px;">
|
||||||
|
<div class="modal-content p-0" style="border-radius: 5px;">
|
||||||
|
<div class="modal-header p-1">
|
||||||
|
<h5 class="modal-title m-1 p-0">SimBrief</h5>
|
||||||
|
<span class="close"><i class="fas fa-times-circle" data-dismiss="modal" aria-label="Close" aria-hidden="true"></i></span>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body p-0">
|
||||||
|
<iframe src="https://www.simbrief.com/system/dispatch.php?editflight=last&static_id={{ $simbrief->xml->params->static_id }}" style="width: 100%; height: 80vh;" frameBorder="0" title="SimBrief"></iframe>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer text-right p-1">
|
||||||
|
<a
|
||||||
|
class="btn btn-success btn-sm m-1 p-1"
|
||||||
|
href="{{ route('frontend.simbrief.update_ofp') }}?ofp_id={{ $simbrief->id }}&flight_id={{ $simbrief->flight_id }}&aircraft_id={{ $simbrief->aircraft_id }}&sb_userid={{ $simbrief->xml->params->user_id }}&sb_static_id={{ $simbrief->xml->params->static_id }}">
|
||||||
|
Download Updated OFP & Close
|
||||||
|
</a>
|
||||||
|
<button type="button" class="btn btn-danger btn-sm m-1 p-1" data-dismiss="modal">Close</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@section('scripts')
|
@section('scripts')
|
||||||
|
|||||||
@@ -160,6 +160,7 @@
|
|||||||
<input type="hidden" name="omit_stars" value="0">
|
<input type="hidden" name="omit_stars" value="0">
|
||||||
<input type="hidden" name="cruise" value="CI">
|
<input type="hidden" name="cruise" value="CI">
|
||||||
<input type="hidden" name="civalue" value="AUTO">
|
<input type="hidden" name="civalue" value="AUTO">
|
||||||
|
<input type="hidden" name="static_id" value="{{ $static_id }}">
|
||||||
{{-- For more info about form fields and their details check SimBrief Forum / API Support --}}
|
{{-- For more info about form fields and their details check SimBrief Forum / API Support --}}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
|
|||||||
Reference in New Issue
Block a user