From: Jérôme Benoit Date: Sat, 20 Jan 2018 16:28:00 +0000 (+0100) Subject: Avoid the booking of full fligths. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=68cee0ac3fe728566e16dc0460416c77022f4b22;p=Project_webapp.git Avoid the booking of full fligths. Signed-off-by: Jérôme Benoit --- diff --git a/includes/formsearch.php b/includes/formsearch.php index 3c6e0ea..cd12ee4 100644 --- a/includes/formsearch.php +++ b/includes/formsearch.php @@ -99,20 +99,19 @@ if (empty($form_arrival_date)) { = ? and VilleD = ? and DateA <= ? and VilleA = ? + $sql_pquery = "select VOLS.NumVol as NumVol, VilleD, DateD, VilleA, DateA, DEFCLASSES.Classe, round(CoutVol*CoeffPrix, 2) as Prix, CapAv + from VOLS join DEFCLASSES on DEFCLASSES.NumVol = VOLS.NumVol + join AVIONS on AVIONS.NumAv = VOLS.NumAv + where DateD >= ? and VilleD = ? and DateA <= ? and VilleA = ? order by DateD, NumVol, Prix"; $connection->prepare_query($sql_pquery); $connection->prepared_query_bind_param("ssss", array($form_departure_date, $form_departure_city, $form_arrival_date, $form_arrival_city)); $connection->run_prepared_query(); $connection->get_pquery_result(); - $rows = $connection->get_result_array(); + $fligths = $connection->get_result_array(); $connection->close_prepared_query(); - //FIXME: Use NumAv to see if a flight is fully booked. - //var_dump($rows); - if (empty($rows)) { + //var_dump($fligths); + if (empty($fligths)) { echo "Aucun vol ne correspond aux critères de recherche.
"; } else { if ($action === "return_flight" && isset($_SESSION['return_flight_nb_place'])) { @@ -132,28 +131,47 @@ if (!$input_failure) { echo " Prix d'une place\n"; echo " Réserver\n"; echo " \n"; - foreach ($rows as $row) { + foreach ($fligths as $fligth) { + $sql_pquery = "select sum(NbPlaces) from RESERVATIONS where NumVol = ?"; + $connection->prepare_query($sql_pquery); + $connection->prepared_query_bind_param("s", array($fligth['NumVol'])); + $connection->run_prepared_query(); + $connection->get_pquery_result(); + $rows = $connection->get_result_array(); + $connection->close_prepared_query(); + $booked_places = $rows[0][0]; + if (is_null($booked_places)) { + $booked_places = 0; + } + if (isset($fligth['CapAv']) && isset($booked_places)) { + $free_places = $fligth['CapAv'] - $booked_places; + } else { + $free_places = "Inconnu"; + } echo " \n"; - echo " " . $row['NumVol'] . "\n"; - echo " " . $row['VilleD'] . "\n"; - echo " " . $row['DateD'] . "\n"; - echo " " . $row['VilleA'] . "\n"; - echo " " . $row['DateA'] . "\n"; - echo " " . $row['Classe'] . "\n"; - echo " " . $row['Prix'] . "€\n"; + echo " " . $fligth['NumVol'] . "\n"; + echo " " . $fligth['VilleD'] . "\n"; + echo " " . $fligth['DateD'] . "\n"; + echo " " . $fligth['VilleA'] . "\n"; + echo " " . $fligth['DateA'] . "\n"; + echo " " . $fligth['Classe'] . "\n"; + echo " " . $fligth['Prix'] . "€\n"; echo " + Places libres : " . $free_places . "
- - - + + + \n"; - if (!($action === "return_flight")) { + if ($action !== "return_flight") { echo " \n"; echo " \n"; } - echo " \n"; + if ($free_places !== 0 || $free_places === "Inconnu") { + echo " \n"; + } echo "
\n"; echo " \n"; diff --git a/includes/reservations.php b/includes/reservations.php index 0416bd5..0d32077 100644 --- a/includes/reservations.php +++ b/includes/reservations.php @@ -17,7 +17,7 @@ $oDateNow = new Datetime($date_now); global $connection; $sql_pquery = "select RESERVATIONS.NumVol as NumVol, VilleD, DateD, VilleA, DateA, RESERVATIONS.Classe, NbPlaces, round(CoutVol*CoeffPrix*NbPlaces, 2) as Prix from RESERVATIONS join VOLS on RESERVATIONS.NumVol = VOLS.NumVol - join DEFCLASSES on DEFCLASSES.NumVol = VOLS.NumVol and RESERVATIONS.Classe = DEFCLASSES.Classe + join DEFCLASSES on DEFCLASSES.NumVol = RESERVATIONS.NumVol and DEFCLASSES.NumVol = VOLS.NumVol and DEFCLASSES.Classe = RESERVATIONS.Classe where NumCl = ? and DateD > ? order by DateD, NumVol, Prix"; $connection->prepare_query($sql_pquery); diff --git a/lib/utils.php b/lib/utils.php index 5ab99b5..f886716 100644 --- a/lib/utils.php +++ b/lib/utils.php @@ -98,7 +98,7 @@ function get_client_id($email) function nb_booked($client_id, $flight_id, $class_name) { global $connection; - $sql_pquery = "select SUM(NbPlaces) from RESERVATIONS where NumCl = ? and NumVol = ? and Classe = ?"; + $sql_pquery = "select sum(NbPlaces) from RESERVATIONS where NumCl = ? and NumVol = ? and Classe = ?"; $connection->prepare_query($sql_pquery); $connection->prepared_query_bind_param("iss", array($client_id, $flight_id, $class_name)); $connection->run_prepared_query();