diff --git a/app/Http/Controllers/CarteSIAController.php b/app/Http/Controllers/CarteSIAController.php index 61a85e1..9ec4833 100644 --- a/app/Http/Controllers/CarteSIAController.php +++ b/app/Http/Controllers/CarteSIAController.php @@ -13,9 +13,26 @@ public function config_Date() $date = $this->Airac_date($date); return $date; } + + public function checkdate(){ + $date = new DateTime(); + $date = $date->format('Y-m-d'); + if($date <= $this->config_Date()){ + $date = date("m")-1; + if($date < 10){ + $date = "0".$date; + } + $date = $this->Airac_date($date); + }else{ + $date = date("m"); + } + return $date; + + } + public function DateAirac() { - $date = $this->config_Date(); + $date = $this->checkdate(); $date = new DateTime($date); $date = $date->format('d_M_Y'); $date = strtoupper($date); diff --git a/app/Http/Controllers/whazzupController.php b/app/Http/Controllers/whazzupController.php index 668852a..e1ea227 100644 --- a/app/Http/Controllers/whazzupController.php +++ b/app/Http/Controllers/whazzupController.php @@ -121,15 +121,18 @@ public function get_token() } $openid_data = json_decode($openid_result, true); + //dd($openid_data); $idclient = env("ivao_api_client_id"); $secret = env("ivao_api_client_secret"); + $state = rand(100000, 999999); $token_req_data = array( 'grant_type' => 'client_credentials', 'client_id' => $idclient, 'client_secret' => $secret, - 'scope' => 'tracker' + 'scope' => 'tracker', + 'state' => $state ); // use key 'http' even if you send the request to https://... @@ -144,10 +147,10 @@ public function get_token() $token_context = stream_context_create($token_options); $token_result = file_get_contents($openid_data['token_endpoint'], false, $token_context); - if ($token_result === FALSE) { - /* Handle error */ - die('Error while getting token'); - } + // if ($token_result === FALSE) { + // /* Handle error */ + // die('Error while getting token'); + // } $token_res_data = json_decode($token_result, true); $access_token = $token_res_data['access_token']; // Here is the access token diff --git a/resources/views/metar-base.blade.php b/resources/views/metar-base.blade.php index 6d90bc6..9f86555 100644 --- a/resources/views/metar-base.blade.php +++ b/resources/views/metar-base.blade.php @@ -44,6 +44,7 @@ + @endif \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index d35b5d5..ea5e3ee 100644 --- a/routes/web.php +++ b/routes/web.php @@ -44,6 +44,7 @@ use Symfony\Component\HttpKernel\Controller\ErrorController; use App\Http\Controllers\my_fav_plateController; use App\Http\Controllers\airac_info; +use App\Http\Controllers\CarteSIAController; /* |-------------------------------------------------------------------------- @@ -422,20 +423,7 @@ } })->name("pirep.create"); - Route::post("/create", function (Request $request) { - $value = $request->all(); - $pirep = new PirepController(); - $pirep->create_for_website($value); - return redirect()->route("pirep.index"); - })->name("pirep.create"); - Route::get("/upload", function (Request $request) { - if (!Auth::user()) { - return redirect()->route("auth.login"); - } else { - return view("pirep.upload-fpl"); - } - })->name("pirep.upload"); Route::post("/upload", function (Request $request) { $request->validate([ @@ -629,13 +617,45 @@ $airac = new airac_info(); $airport = "LFMT"; $Rwy = "30R"; - $airac2 = $airac->get_approach($airport ); + $airac2 = $airac->get_approach($airport); $airac1 = $airac->get_departure($airport); $ils = $airac->get_ils_information($airport, $Rwy); $airac3 = collect(["departure" => $airac1, "arrival" => $airac2, "ils" => $ils]); return $airac3; - }); + + Route::get("vac", function (Request $request) { + return view("vac.index"); + })->name("vac.index"); + + Route::get("vac/{icao}", function (Request $request) { + $request->merge([ + "icao" => $request->icao + ]); + $icao = strtoupper($request->icao); + $regex_for_icao = "/[A-Za-z]{2}(?:\d{4}|[A-Za-z]{2})/"; + if (!preg_match($regex_for_icao, $icao)) { + return response()->json(["error" => "Icao not valid"], 400); + } + if (strlen($icao) == 4) { + $chart_sia = new CarteSIAController(); + $chart = $chart_sia->chartVFR($icao); + if ($chart == null) { + return response()->json(["error" => "Icao not valid"], 400); + } + $req = http::get($chart); + if ($req->status() != 200) { + return response()->json(["error" => "Icao not valid2"], 400); + } + return response($req->body(), 200)->header('Content-Type', 'application/pdf'); + } + $req = http::get("https://basulm.ffplum.fr/PDF/" . $icao . ".pdf"); + if ($req->status() != 200) { + return response()->json(["error" => "Icao not valid2"], 400); + } + return response($req->body(), 200)->header('Content-Type', 'application/pdf'); + //return $airac; + })->name("vac.icao"); });