Fix the flight reservation with a return cinematic.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 20 Jan 2018 13:49:58 +0000 (14:49 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 20 Jan 2018 13:49:58 +0000 (14:49 +0100)
And also fix the reservation modification code.

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
includes/formbooking.php
includes/formmodify.php
includes/formsearch.php

index be30b874d92cf1d93a33d0e20df5bbb41e8adc9e..8699109e66e57feba93b0e93bbe337427fcebbfc 100644 (file)
@@ -66,6 +66,7 @@ if (!$input_failure && $is_logged_in && !empty($form_nb_place) && !empty($form_c
         $_SESSION['return_flight_departure_city'] = $row['VilleA'];
         $_SESSION['return_flight_arrival_city'] = $row['VilleD'];
         $_SESSION['return_flight_departure_date'] = $row['DateA'];
+        $_SESSION['return_flight_nb_place'] = $form_nb_place;
         redirect("index.php?page=search&action=return_flight", 3);
     } else {
         redirect("index.php?page=reservations", 3);
index 6b6490612b85681dedc8cbc15bd7ca3fa4389a88..a09debeb035b46008d279e7df50a2262a87a5dd9 100644 (file)
@@ -18,14 +18,24 @@ if (!$form_nb_place) {
     $input_failure = true;
 }
 
-if (!$input_failure && $is_logged_in && !empty($form_nb_place) && !empty($form_class_name)) {
+if (!$input_failure && $is_logged_in && !empty($form_nb_place) && !empty($form_class_name) && !empty($form_previous_class_name)) {
     global $connection;
     $client_id = get_client_id($_SESSION['email']);
-    $sql_pquery = "update RESERVATIONS
-                   set NbPlaces = ?, Classe = ?
-                   where NumCl = ? and NumVol = ? and Classe = ?";
+    if (strcmp($form_class_name, $form_previous_class_name) === 0) {
+        $sql_pquery = "update RESERVATIONS
+                       set NbPlaces = ?
+                       where NumCl = ? and NumVol = ? and Classe = ?";
+    } else {
+        $sql_pquery = "update RESERVATIONS
+                       set NbPlaces = ?, Classe = ?
+                       where NumCl = ? and NumVol = ? and Classe = ?";
+    }
     $connection->prepare_query($sql_pquery);
-    $connection->prepared_query_bind_param("isiss", array($form_nb_place, $form_class_name, $client_id, $form_flight_id, $form_previous_class_name));
+    if (strcmp($form_class_name, $form_previous_class_name) === 0) {
+        $connection->prepared_query_bind_param("iiss", array($form_nb_place, $client_id, $form_flight_id, $form_previous_class_name));
+    } else {
+        $connection->prepared_query_bind_param("isiss", array($form_nb_place, $form_class_name, $client_id, $form_flight_id, $form_previous_class_name));
+    }
     $connection->run_prepared_query();
     $connection->close_prepared_query();
     echo "Modifications enregistre&#769;es. <br>";
index 6bd0fa1850372714c2224ecda11385873441e8fd..3c6e0ea3f1ce224ff39421be44b1025a88c4ddad 100644 (file)
@@ -99,7 +99,8 @@ if (empty($form_arrival_date)) {
 <?php
 if (!$input_failure) {
      global $connection;
-     $sql_pquery = "select VOLS.NumVol as NumVol, VilleD, DateD, VilleA, DateA, Classe, round(CoutVol*CoeffPrix, 2) as Prix, NumAv from VOLS, DEFCLASSES
+     $sql_pquery = "select VOLS.NumVol as NumVol, VilleD, DateD, VilleA, DateA, Classe, round(CoutVol*CoeffPrix, 2) as Prix, NumAv
+                    from VOLS, DEFCLASSES
                     where DEFCLASSES.NumVol = VOLS.NumVol and
                     DateD >= ? and VilleD = ? and DateA <= ? and VilleA = ?
                     order by DateD, NumVol, Prix";
@@ -114,6 +115,12 @@ if (!$input_failure) {
      if (empty($rows)) {
          echo "Aucun vol ne correspond aux crite&#768;res de recherche. <br>";
      } else {
+         if ($action === "return_flight" && isset($_SESSION['return_flight_nb_place'])) {
+             $nb_places = $_SESSION['return_flight_nb_place'];
+             unset($_SESSION['return_flight_nb_place']);
+         } else {
+             $nb_places = 1;
+         }
          echo "<table id=\"search\">\n";
          echo "  <tr>\n";
          echo "    <th>Nume&#769;ro de vol</th>\n";
@@ -141,9 +148,9 @@ if (!$input_failure) {
                           <input type=\"hidden\" name=\"class_name\" value=\"" . $row['Classe'] . "\" />
                           <input type=\"hidden\" name=\"place_price\" value=\"" . $row['Prix'] . "\" />
                           <label> Place(s) : </label>
-                          <input type=\"number\" name=\"nb_place\" min=\"1\" max=\"9\" value=\"1\" required/>
-                          <label> Vol retour : </label>\n";
+                          <input type=\"number\" name=\"nb_place\" min=\"1\" max=\"9\" value=\"" . $nb_places . "\" required/>\n";
              if (!($action === "return_flight")) {
+                 echo "       <label> Vol retour : </label>\n";
                  echo "       <input type=\"checkbox\" name=\"return_flight\" checked/>\n";
              }
              echo "       <input type=\"submit\" value=\"Re&#769;server\">\n";