From: Jérôme Benoit Date: Tue, 16 Jan 2018 15:44:21 +0000 (+0100) Subject: Add the flight search and booking features. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=33eb6f2ab954597a257e9eb8f793a9bc52dd9524;p=Project_webapp.git Add the flight search and booking features. Signed-off-by: Jérôme Benoit --- diff --git a/includes/account.php b/includes/account.php index 74fbddb..dc25449 100644 --- a/includes/account.php +++ b/includes/account.php @@ -5,3 +5,6 @@ if (!$is_logged_in) { redirect("index.php?page=login", 2); } ?> + +

Mes informations

+

Mes réversations

diff --git a/includes/config-example.php b/includes/config-example.php index d7ad853..a7edf02 100644 --- a/includes/config-example.php +++ b/includes/config-example.php @@ -11,6 +11,7 @@ 'login', 'logout', 'register', + 'reservations', 'booking', 'search', 'account' diff --git a/includes/formbooking.php b/includes/formbooking.php new file mode 100644 index 0000000..373e18b --- /dev/null +++ b/includes/formbooking.php @@ -0,0 +1,68 @@ +"; + $input_failure = true; +} + +if (!$form_nb_place) { + echo "Nombre de place(s) invalide.
"; + $input_failure = true; +} + +if (!$form_return_flight) { + echo "Vol retour invalide.
"; + $input_failure = true; +} + +if (!$input_failure && !empty($form_nb_place) && !empty($form_class_name)) { + global $connection; + $client_id = get_client_id($_SESSION['email']); + $nb_booked = nb_booked($client_id, $form_flight_id); + if (!empty($nb_booked)) { + echo "Vous avez déjà réservé ce vol, vous allez être redirigé vers la liste de vos réservations dans 2 secondes.
"; + redirect("index.php?page=reservations", 2); + } + $sql_pquery = "insert into RESERVATIONS (NumCl, NumVol, Classe, NbPlaces) + values (?, ?, ?, ?)"; + $connection->prepare_query($sql_pquery); + $connection->prepared_query_bind_param("issi", array($client_id, $form_flight_id, $form_class_name, $form_nb_place)); + $connection->run_prepared_query(); + $connection->close_prepared_query(); + $sql_pquery = "select VilleD, DateD, VilleA, DateA from VOLS, DEFCLASSES + where DEFCLASSES.NumVol = VOLS.NumVol and + VOLS.NumVol = ? and Classe = ?"; + $connection->prepare_query($sql_pquery); + $connection->prepared_query_bind_param("ss", array($form_flight_id, $form_class_name)); + $connection->run_prepared_query(); + $connection->get_pquery_result(); + $rows = $connection->get_result_array(); + $connection->close_prepared_query(); + foreach ($rows as $row) { + echo "Vous avez réservé et payé " . $form_nb_place . " place(s) sur le vol " .$form_flight_id . + " au départ de " . $row['VilleD']. " à " . $row['DateD'] . " arrivant à " . $row['VilleA'] . " à " . $row['DateA'] . + " pour un montant de " . $form_place_price * $form_nb_place . "€.
"; + } + if ($form_return_flight) { + redirect("index.php?page=search", 3); + $_SESSION['current_flight_id'] = $form_flight_id; + $_SESSION['return_flight'] = $form_return_flight; + } else { + redirect("index.php?page=reservations", 3); + } +} + +?> diff --git a/includes/formlogin.php b/includes/formlogin.php index 73cdff0..ed17f80 100644 --- a/includes/formlogin.php +++ b/includes/formlogin.php @@ -15,7 +15,7 @@ if (!$form_email) { echo "You're successfully authenticated.
"; redirect("index.php", 3); } else { - echo "Your password is incorrect for the account email" . $form_email . ".
"; + echo "Your password is incorrect for the account email " . $form_email . ".
"; echo "Retour"; } } else { diff --git a/includes/formsearch.php b/includes/formsearch.php new file mode 100644 index 0000000..951bef1 --- /dev/null +++ b/includes/formsearch.php @@ -0,0 +1,109 @@ +"; + $input_failure = true; +} + +if ($oDepartureDate < $oDateNow) { + echo "The departure date is before the current date.
"; + $input_failure = true; +} + +if ($oArrivalDate <= $oDepartureDate) { + echo "Arrival date is before departure date.
"; + $input_failure = true; +} + +?> + +

Rechercher un vol

+ + +
+ += ? 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(); + $connection->close_prepared_query(); + //var_dump($rows); + if (empty($rows)) { + echo "Aucun vol ne correspond aux critères de recherche.
"; + } else { + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + foreach ($rows as $row) { + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + } + echo "
Numéro de volVille de départDate de départVille d'arrivéeDate d'arrivéeClassePrix d'une placeRéserver
" . $row['NumVol'] . "" . $row['VilleD'] . "" . $row['DateD'] . "" . $row['VilleA'] . "" . $row['DateA'] . "" . $row['Classe'] . "" . $row['Prix'] . "€ +
+ + + + + + + + + +
+
"; + } +} + +?> diff --git a/includes/header.php b/includes/header.php index 2e32552..4dae576 100644 --- a/includes/header.php +++ b/includes/header.php @@ -33,10 +33,15 @@ $is_logged_in = chk_logged_in(); - - + diff --git a/includes/booking.php b/includes/reservations.php similarity index 80% rename from includes/booking.php rename to includes/reservations.php index 74fbddb..b2d8f4f 100644 --- a/includes/booking.php +++ b/includes/reservations.php @@ -5,3 +5,4 @@ if (!$is_logged_in) { redirect("index.php?page=login", 2); } ?> +

Mes réservations

diff --git a/includes/search.php b/includes/search.php index 366c962..aab5733 100644 --- a/includes/search.php +++ b/includes/search.php @@ -1,7 +1,10 @@

Rechercher un vol

+ + diff --git a/lib/db.php b/lib/db.php index c7c2d48..cd9b082 100644 --- a/lib/db.php +++ b/lib/db.php @@ -80,6 +80,7 @@ class CustomDB /** * [prepared_query_bind_param description] + * @param [type] $types [description] * @param [type] $params [description] * @return [type] [description] */ @@ -116,9 +117,18 @@ class CustomDB public function get_result_array() { - $rt_val = $this->current_result->fetch_array(); - if (!$rt_val) { + $row = $this->current_result->fetch_array(); + if (is_null($row)) { + $rt_val = []; + } elseif (!isset($row)) { echo "Fail to build SQL query result array : (" . $this->current_stmt->errno . ") " . $this->current_stmt->error . " - " . $this->current_pquery . "
"; + $rt_val = false; + } else { + $rows[] = $row; + while ($row = $this->current_result->fetch_array()) { + $rows[] = $row; + } + $rt_val = $rows; } return $rt_val; } @@ -136,4 +146,5 @@ class CustomDB return $rt_val; } } + ?> diff --git a/lib/utils.php b/lib/utils.php index 8fdb0aa..47c8bda 100644 --- a/lib/utils.php +++ b/lib/utils.php @@ -28,7 +28,7 @@ function chk_account($email) $connection->get_pquery_result(); $row = $connection->get_result_array(); $connection->close_prepared_query(); - if (!empty($row[0])) { + if (!empty($row[0][0])) { return true; } else { return false; @@ -45,13 +45,39 @@ function chk_password($email, $password) $connection->get_pquery_result(); $row = $connection->get_result_array(); $connection->close_prepared_query(); - if (password_verify($password, $row[0])) { + if (password_verify($password, $row[0][0])) { return true; } else { return false; } } +function get_client_id($email) +{ + global $connection; + $sql_pquery = "select NumCl from CLIENTS where EmailCl = ?"; + $connection->prepare_query($sql_pquery); + $connection->prepared_query_bind_param("s", array($email)); + $connection->run_prepared_query(); + $connection->get_pquery_result(); + $row = $connection->get_result_array(); + $connection->close_prepared_query(); + return $row[0][0]; +} + +function nb_booked($client_id, $flight_id) +{ + global $connection; + $sql_pquery = "select SUM(NbPlaces) from RESERVATIONS where NumCl = ? and NumVol = ?"; + $connection->prepare_query($sql_pquery); + $connection->prepared_query_bind_param("is", array($client_id, $flight_id)); + $connection->run_prepared_query(); + $connection->get_pquery_result(); + $row = $connection->get_result_array(); + $connection->close_prepared_query(); + return $row[0][0]; +} + function chk_logged_in() { if (isset($_SESSION['email']) && isset($_SESSION['IP_address'])) { diff --git a/styles/airpolytech.css b/styles/airpolytech.css index e5a93bf..a05683e 100644 --- a/styles/airpolytech.css +++ b/styles/airpolytech.css @@ -41,6 +41,10 @@ form#register { width: 720px; } +form#booking { + width: 250px; +} + label, input { /* in order to define widths */ display: inline-block; @@ -75,12 +79,16 @@ table#home { line-height: 1em; } -table#result tr:nth-child(even) { - background-color: #eee; +table#search { + border: none; +} + +table#search tr:nth-child(even) { + background-color: #675b5b; } -table#result tr:nth-child(odd) { - background-color: #fff; +table#search tr:nth-child(odd) { + background-color: #474343; } #header {