Add the reservation modification feature.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 19 Jan 2018 21:57:10 +0000 (22:57 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 19 Jan 2018 21:57:10 +0000 (22:57 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
includes/booking.php [deleted file]
includes/config-example.php
includes/formmodify.php [new file with mode: 0644]
includes/formreservations.php
includes/modify.php [new file with mode: 0644]
includes/reservations.php
js/airpolytech.js

diff --git a/includes/booking.php b/includes/booking.php
deleted file mode 100644 (file)
index e69de29..0000000
index a7edf02773269a5787f4c8ff898017f609e414ee..ed4bf1559e86235580403b2a10569e16094f848d 100644 (file)
@@ -14,7 +14,8 @@
          'reservations',
          'booking',
          'search',
-         'account'
+         'account',
+         'modify'
      )
  );
 
diff --git a/includes/formmodify.php b/includes/formmodify.php
new file mode 100644 (file)
index 0000000..20e53f6
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+$form_flight_id = filter_input(INPUT_POST, "flight_id", FILTER_SANITIZE_STRING);
+$form_nb_place = filter_input(INPUT_POST, "nb_place", FILTER_VALIDATE_INT);
+$form_class_name = filter_input(INPUT_POST, "class_name", FILTER_SANITIZE_STRING);
+
+global $connection;
+$client_id = get_client_id($_SESSION['email']);
+$sql_pquery = "update RESERVATIONS
+                   set NbPlaces = ?, Classe = ?
+                   where NumCl = ? and NumVol = ?";
+$connection->prepare_query($sql_pquery);
+$connection->prepared_query_bind_param("isis", array($form_nb_place, $form_class_name, $client_id, $form_flight_id));
+$connection->run_prepared_query();
+$connection->close_prepared_query();
+echo "Modifications enregistre&#769;es. <br>";
+redirect("index.php?page=reservations", 3);
+?>
index 4bca04c5c07935ce74b9184a27ce6d25d4aaf10b..06989006b122921a4d7b44cda15b3897780ac1fd 100644 (file)
@@ -1,12 +1,9 @@
 <?php
 $form_flight_id = filter_input(INPUT_POST, "flight_id", FILTER_SANITIZE_STRING);
 $form_class_name = filter_input(INPUT_POST, "class_name", FILTER_SANITIZE_STRING);
-$form_modify = filter_input(INPUT_POST, "modify", FILTER_SANITIZE_STRING);
 $form_cancel = filter_input(INPUT_POST, "cancel", FILTER_SANITIZE_STRING);
 
-if (isset($form_modify) && isset($form_flight_id) && isset($form_class_name)) {
-    echo $form_modify;
-} elseif (isset($form_cancel) && isset($form_flight_id) && isset($form_class_name)) {
+if (isset($form_cancel) && isset($form_flight_id) && isset($form_class_name)) {
     $client_id = get_client_id($_SESSION['email']);
     global $connection;
     $sql_pquery = "delete from RESERVATIONS
diff --git a/includes/modify.php b/includes/modify.php
new file mode 100644 (file)
index 0000000..aeb9741
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+$flight_id = filter_input(INPUT_GET, "flight_id", FILTER_SANITIZE_STRING);
+$class_name = filter_input(INPUT_GET, "class_name", FILTER_SANITIZE_STRING);
+$client_id = get_client_id($_SESSION['email']);
+echo "<h1> Modification de la re&#769;servation sur le vol $flight_id</h2>\n";
+global $connection;
+$sql_pquery = "select NumCl, NumVol, Classe, 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();
+$connection->get_pquery_result();
+$rows = $connection->get_result_array();
+$connection->close_prepared_query();
+?>
+<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'] ?>" />
+  <label> Nombre de place(s) : </label>
+  <input type="number" name="nb_place" min="1" max="9" value="<?php echo $rows[0]['NbPlaces'] ?>" required/>
+  <label> Classe : </label>
+  <select size="1" name="class_name" required>
+   <optgroup label="Se&#769;lectionner une classe">
+  <?php
+  $sql_pquery = "select distinct Classe from DEFCLASSES where NumVol = ?";
+  global $connection;
+  $connection->prepare_query($sql_pquery);
+  $connection->prepared_query_bind_param("s", array($flight_id));
+  $connection->run_prepared_query();
+  $connection->get_pquery_result();
+  $classes = $connection->get_result_array();
+  $connection->close_prepared_query();
+  foreach ($classes as $class) {
+      if (strcmp($class[0], $rows[0]['Classe']) === 0) {
+          echo "<option value=\"$class[0]\" selected>$class[0]</option>\n";
+      } else {
+          echo "<option value=\"$class[0]\">$class[0]</option>\n";
+      }
+  }
+  ?>
+   </optgroup>
+  </select>
+  <input type="submit" value="Valider">
+</form>
index 43148671acd1a16ce90e0ccf6032a8b4cc734599..0416bd5af660a159d5777a2029ebf2723021282a 100644 (file)
@@ -58,7 +58,7 @@ if (empty($rows)) {
                           <input type=\"hidden\" name=\"form\" value=\"reservations\" />
                           <input type=\"hidden\" name=\"flight_id\" value=\"" . $row['NumVol'] . "\" />
                           <input type=\"hidden\" name=\"class_name\" value=\"" . $row['Classe'] . "\" />
-                          <input type=\"submit\" name=\"modify\" value=\"Modifier\">
+                          <input type=\"button\" name=\"modify\" value=\"Modifier\" onClick=\"location.href='index.php?page=modify&flight_id=" . $row['NumVol'] . "&class_name=" . $row['Classe'] . "';\">
                           <input type=\"button\" name=\"cancel\" value=\"Annuler\" onClick=\"ConfirmCancelFlight()\">
                         </form>
                       </td>\n";
index 0f5a17a3c24710db6bd75922578455309423ef0a..8e628871c2f9006035162e95bd10bcd39ce460e5 100644 (file)
@@ -1,6 +1,6 @@
 function ConfirmCancelFlight() {
     var oFormObject = document.forms['reservations'];
-    if (confirm("Voulez-vous vraiment annuler votre re&#769;servation sur le vol " + oFormObject.elements['flight_id'].value + " ?")) {
+    if (confirm("Voulez-vous vraiment annuler votre réservation sur le vol " + oFormObject.elements['flight_id'].value + " ?")) {
         var input = document.createElement("input");
         input.setAttribute("type", "hidden");
         input.setAttribute("name", "cancel");