Add return flight booking cinematic and personal informations editing.
[Project_webapp.git] / includes / formbooking.php
index 2d47f81da68e34b41cac7afc58a7471444dcab89..be30b874d92cf1d93a33d0e20df5bbb41e8adc9e 100644 (file)
@@ -8,6 +8,7 @@ $form_return_flight = filter_input(INPUT_POST, "return_flight", FILTER_VALIDATE_
 global $is_logged_in;
 if (!$is_logged_in) {
     echo "Please login first. <br>";
+    $_SESSION['login_referer'] = $_SERVER['HTTP_REFERER'];
     redirect("index.php?page=login", 2);
 }
 
@@ -23,7 +24,9 @@ if (!$form_nb_place) {
     $input_failure = true;
 }
 
-if (!$form_return_flight) {
+if (is_null($form_return_flight)) {
+    $form_return_flight = false;
+} elseif (!$form_return_flight) {
     echo "Vol retour invalide. <br>";
     $input_failure = true;
 }
@@ -31,7 +34,7 @@ if (!$form_return_flight) {
 if (!$input_failure && $is_logged_in && !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);
+    $nb_booked = nb_booked($client_id, $form_flight_id, $form_class_name);
     if (!empty($nb_booked)) {
         echo "Vous avez de&#769;ja&#768; re&#769;serve&#769; ce vol, vous allez e&#770;tre redirige&#769; vers la liste de vos re&#769;servations dans 2 secondes. <br>";
         redirect("index.php?page=reservations", 2);
@@ -54,15 +57,16 @@ if (!$input_failure && $is_logged_in && !empty($form_nb_place) && !empty($form_c
     $rows = $connection->get_result_array();
     $connection->close_prepared_query();
     foreach ($rows as $row) {
-        echo "(Simulation de paiement d'une re&#769;servation) <br>";
+        echo "(Simulation de validation et paiement d'une re&#769;servation) <br>";
         echo "Vous avez re&#769;serve&#769; et paye&#769; " . $form_nb_place . " place(s) sur le vol " .$form_flight_id .
              " au de&#769;part de " . $row['VilleD'].  " a&#768; " . $row['DateD'] . " arrivant a&#768; " . $row['VilleA'] . " a&#768; " . $row['DateA'] .
              " pour un montant total de " . $form_place_price * $form_nb_place . "&euro;. <br>";
     }
     if ($form_return_flight) {
-        redirect("index.php?page=search", 3);
-        $_SESSION['current_flight_id'] = $form_flight_id;
-        $_SESSION['return_flight'] = $form_return_flight;
+        $_SESSION['return_flight_departure_city'] = $row['VilleA'];
+        $_SESSION['return_flight_arrival_city'] = $row['VilleD'];
+        $_SESSION['return_flight_departure_date'] = $row['DateA'];
+        redirect("index.php?page=search&action=return_flight", 3);
     } else {
         redirect("index.php?page=reservations", 3);
     }