Avoid also to modify a full flight.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 20 Jan 2018 17:20:38 +0000 (18:20 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 20 Jan 2018 17:20:38 +0000 (18:20 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
includes/formsearch.php
includes/modify.php

index 5cdca0cc4322af26d8bfe9402bc0d26a009aa11f..dc682dafb80803829b58db91d0d27805ab9853e2 100644 (file)
@@ -108,10 +108,10 @@ if (!$input_failure) {
      $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();
-     $fligths = $connection->get_result_array();
+     $flights = $connection->get_result_array();
      $connection->close_prepared_query();
-     //var_dump($fligths);
-     if (empty($fligths)) {
+     //var_dump($flights);
+     if (empty($flights)) {
          echo "Aucun vol ne correspond aux crite&#768;res de recherche. <br>";
      } else {
          if ($action === "return_flight" && isset($_SESSION['return_flight_nb_place'])) {
@@ -131,10 +131,10 @@ if (!$input_failure) {
          echo "    <th>Prix d'une place</th>\n";
          echo "    <th>Re&#769;server</th>\n";
          echo "  </tr>\n";
-         foreach ($fligths as $fligth) {
+         foreach ($flights as $flight) {
              $sql_pquery = "select sum(NbPlaces) as BookedPlaces from RESERVATIONS where NumVol = ?";
              $connection->prepare_query($sql_pquery);
-             $connection->prepared_query_bind_param("s", array($fligth['NumVol']));
+             $connection->prepared_query_bind_param("s", array($flight['NumVol']));
              $connection->run_prepared_query();
              $connection->get_pquery_result();
              $rows = $connection->get_result_array();
@@ -143,26 +143,26 @@ if (!$input_failure) {
              if (is_null($booked_places)) {
                  $booked_places = 0;
              }
-             if (isset($fligth['CapAv']) && isset($booked_places)) {
-                 $free_places = $fligth['CapAv'] - $booked_places;
+             if (isset($flight['CapAv']) && isset($booked_places)) {
+                 $free_places = $flight['CapAv'] - $booked_places;
              } else {
                  $free_places = "Inconnu";
              }
              echo "  <tr>\n";
-             echo "    <td>" . $fligth['NumVol'] . "</td>\n";
-             echo "    <td>" . $fligth['VilleD'] . "</td>\n";
-             echo "    <td>" . $fligth['DateD'] . "</td>\n";
-             echo "    <td>" . $fligth['VilleA'] . "</td>\n";
-             echo "    <td>" . $fligth['DateA'] . "</td>\n";
-             echo "    <td>" . $fligth['Classe'] . "</td>\n";
-             echo "    <td>" . $fligth['Prix'] . "&euro;</td>\n";
+             echo "    <td>" . $flight['NumVol'] . "</td>\n";
+             echo "    <td>" . $flight['VilleD'] . "</td>\n";
+             echo "    <td>" . $flight['DateD'] . "</td>\n";
+             echo "    <td>" . $flight['VilleA'] . "</td>\n";
+             echo "    <td>" . $flight['DateA'] . "</td>\n";
+             echo "    <td>" . $flight['Classe'] . "</td>\n";
+             echo "    <td>" . $flight['Prix'] . "&euro;</td>\n";
              echo "    <td>
                         Nombre de places libres : " . $free_places . "
                         <form action=\"index.php\" id=\"booking\" method=\"post\">
                           <input type=\"hidden\" name=\"form\" value=\"booking\" />
-                          <input type=\"hidden\" name=\"flight_id\" value=\"" . $fligth['NumVol'] . "\" />
-                          <input type=\"hidden\" name=\"class_name\" value=\"" . $fligth['Classe'] . "\" />
-                          <input type=\"hidden\" name=\"place_price\" value=\"" . $fligth['Prix'] . "\" />
+                          <input type=\"hidden\" name=\"flight_id\" value=\"" . $flight['NumVol'] . "\" />
+                          <input type=\"hidden\" name=\"class_name\" value=\"" . $flight['Classe'] . "\" />
+                          <input type=\"hidden\" name=\"place_price\" value=\"" . $flight['Prix'] . "\" />
                           <label> Place(s) : </label>
                           <input type=\"number\" name=\"nb_place\" min=\"1\" max=\"9\" value=\"" . $nb_places . "\" required/>\n";
              if ($action !== "return_flight") {
index 045d84acfe511c93b11a0cc955c09d917311b9cc..cd37c239ad80c549def4ca098b5ef7aae369f096 100644 (file)
@@ -21,13 +21,39 @@ $connection->run_prepared_query();
 $connection->get_pquery_result();
 $rows = $connection->get_result_array();
 $connection->close_prepared_query();
+$sql_pquery = "select CapAv, sum(NbPlaces) as BookedPlaces
+               from RESERVATIONS, VOLS, AVIONS
+                          where RESERVATIONS.NumVol = VOLS.NumVol and AVIONS.NumAv = VOLS.NumAv and
+               RESERVATIONS.NumVol = ?
+               group by RESERVATIONS.NumVol";
+$connection->prepare_query($sql_pquery);
+$connection->prepared_query_bind_param("s", array($flight_id));
+$connection->run_prepared_query();
+$connection->get_pquery_result();
+$rows_cap = $connection->get_result_array();
+$connection->close_prepared_query();
+//var_dump($rows_cap);
+$booked_places = $rows_cap[0]['BookedPlaces'];
+if (is_null($booked_places)) {
+    $booked_places = 0;
+}
+if (isset($rows_cap[0]['CapAv']) && isset($booked_places)) {
+    $free_places = $rows_cap[0]['CapAv'] - $booked_places;
+} else {
+    $free_places = "Inconnu";
+}
 ?>
+<p> Nombre de places libres : <?php echo $free_places ?> </p>
 <form action="index.php" id="modify" method="post">
   <input type="hidden" name="form" value="modify" />
   <input type="hidden" name="flight_id" value="<?php echo $rows[0]['NumVol'] ?>" />
   <input type="hidden" name="previous_class_name" value="<?php echo $rows[0]['Classe'] ?>" />
-  <label> Nombre de place(s) : </label>
-  <input type="number" name="nb_place" min="1" max="9" value="<?php echo $rows[0]['NbPlaces'] ?>" required/>
+  <?php
+  if ($free_places !== 0 || $free_places === "Inconnu") {
+      echo "  <label> Nombre de place(s) : </label>\n";
+      echo "  <input type=\"number\" name=\"nb_place\" min=\"1\" max=\"9\" value=\"" . $rows[0]['NbPlaces'] . "\" required/>\n";
+  }
+  ?>
   <label> Classe : </label>
   <select size="1" name="class_name" required>
    <optgroup label="Se&#769;lectionner une classe">