Refine the fligth search:
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 17 Jan 2018 15:09:31 +0000 (16:09 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 17 Jan 2018 15:09:31 +0000 (16:09 +0100)
- Make a select for the cities;
- Keep selected values between each call.

Permit to cancel a reservation.

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
includes/account.php
includes/formbooking.php
includes/formreservations.php [new file with mode: 0644]
includes/formsearch.php
includes/reservations.php
includes/search.php
styles/airpolytech.css

index c7099dbaa319fd5f7b70b9b96817783e679660c3..073d5adfc0f73ae1aced29bb7ff7837590149130 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 global $is_logged_in;
 if (!$is_logged_in) {
-    echo "Please login first.";
+    echo "Please login first. <br>";
     redirect("index.php?page=login", 2);
     include('footer.html');
     exit();
index dd4189e969bc39b4f7f8bdfdfecb69261d24dd60..3d55c5013e1936880f83dd2fa65e5791e0540260 100644 (file)
@@ -7,7 +7,7 @@ $form_return_flight = filter_input(INPUT_POST, "return_flight", FILTER_VALIDATE_
 
 global $is_logged_in;
 if (!$is_logged_in) {
-    echo "Please login first.";
+    echo "Please login first. <br>";
     redirect("index.php?page=login", 2);
 }
 
diff --git a/includes/formreservations.php b/includes/formreservations.php
new file mode 100644 (file)
index 0000000..479489b
--- /dev/null
@@ -0,0 +1,25 @@
+<?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)) {
+    //FIXME: Add a confirmation step
+    $client_id = get_client_id($_SESSION['email']);
+    global $connection;
+    $sql_pquery = "delete from RESERVATIONS
+                   where NumCl = ? and NumVol = ? and Classe = ?";
+    $connection->prepare_query($sql_pquery);
+    $connection->prepared_query_bind_param("iss", array($client_id, $form_flight_id, $form_class_name));
+    $connection->run_prepared_query();
+    $connection->close_prepared_query();
+    echo "Votre re&#769;servation a e&#769;te&#769; annule&#769;e. <br>";
+    redirect("index.php?page=reservations", 3);
+} else {
+    echo "Make an error message. <br>";
+}
+
+?>
index 951bef1e546da3e6f311a6a8c32638fcdb818ea0..7796f0691ae75452042e1ee02ae7906e228a46bf 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 $form_departure_city = filter_input(INPUT_POST, "departure_city", FILTER_SANITIZE_STRING);
 $form_departure_date = filter_input(INPUT_POST, "departure_date", FILTER_SANITIZE_STRING);
 $form_arrival_city = filter_input(INPUT_POST, "arrival_city", FILTER_SANITIZE_STRING);
@@ -31,6 +30,13 @@ if ($oArrivalDate <= $oDepartureDate) {
     $input_failure = true;
 }
 
+if (empty($form_arrival_date)) {
+    // Limit to a 6 months interval from the departure date.
+    $oArrivalDate = $oDepartureDate;
+    $oArrivalDate->add(new DateInterval("P6M"));
+    $form_arrival_date = $oArrivalDate->format('Y-m-d\TH:i');
+}
+
 ?>
 
 <h1> Rechercher un vol </h1>
@@ -39,13 +45,51 @@ if ($oArrivalDate <= $oDepartureDate) {
  <input type="hidden" name="form" value="search" />
  <input type="hidden" name="date_now" value="<?php echo $form_date_now; ?>" />
  <label> De&#769;part : Ville -> </label>
- <input type="text" size="15" name="departure_city" value="<?php echo $form_departure_city; ?>" required/>
+ <select size="1" name="departure_city" required>
+  <optgroup label="Se&#769;lectionner une ville">
+ <?php
+ $sql_pquery = "select distinct VilleD from VOLS";
+ global $connection;
+ $connection->prepare_query($sql_pquery);
+ $connection->run_prepared_query();
+ $connection->get_pquery_result();
+ $cities = $connection->get_result_array();
+ $connection->close_prepared_query();
+ foreach ($cities as $city) {
+     if (strcmp($city[0], $form_departure_city) === 0) {
+         echo "<option value=\"$city[0]\" selected>$city[0]</option>\n";
+     } else {
+         echo "<option value=\"$city[0]\">$city[0]</option>\n";
+     }
+ }
+ ?>
+  </optgroup>
+ </select>
  <label> Date -> </label>
  <input type="datetime-local" name="departure_date" value="<?php echo $form_departure_date; ?>" required/>
  <label> Arrive&#769;e : Ville -> </label>
- <input type="text" size="15" name="arrival_city" value="<?php echo $form_arrival_city; ?>" required/>
+ <select size="1" name="arrival_city" required>
+  <optgroup label="Se&#769;lectionner une ville">
+ <?php
+ $sql_pquery = "select distinct VilleA from VOLS";
+ global $connection;
+ $connection->prepare_query($sql_pquery);
+ $connection->run_prepared_query();
+ $connection->get_pquery_result();
+ $cities = $connection->get_result_array();
+ $connection->close_prepared_query();
+ foreach ($cities as $city) {
+     if (strcmp($city[0], $form_arrival_city) === 0) {
+         echo "<option value=\"$city[0]\" selected>$city[0]</option>\n";
+     } else {
+         echo "<option value=\"$city[0]\">$city[0]</option>\n";
+     }
+ }
+ ?>
+  </optgroup>
+ </select>
  <label> Date -> </label>
- <input type="datetime-local" name="arrival_date" value="<?php echo $form_arrival_date; ?>" required/>
+ <input type="datetime-local" name="arrival_date" <?php if (isset($form_arrival_date)) echo "value=\"$form_arrival_date\"";?> />
  <input type="submit" value="Valider">
 </form>
 <br>
@@ -97,7 +141,7 @@ if (!$input_failure) {
                           <input type=\"number\" name=\"nb_place\" min=\"1\" max=\"9\" value=\"1\" required/>
                           <label> Vol retour : </label>
                           <input type=\"checkbox\" name=\"return_flight\" checked required/>
-                          <input type=\"submit\" value=\"Reserver\">
+                          <input type=\"submit\" value=\"Re&#769;server\">
                         </form>
                       </td>\n";
             echo "  </tr>\n";
index e986fb6647a31dd56326f23bc016718178bb4f0c..f560b9a1dd776ce60f4d14cf8aa4f947704062be 100644 (file)
@@ -1,10 +1,66 @@
 <?php
 global $is_logged_in;
 if (!$is_logged_in) {
-    echo "Please login first.";
+    echo "Please login first. <br>";
     redirect("index.php?page=login", 2);
     include('footer.html');
     exit();
 }
 ?>
 <h1>Mes re&#769;servations</h1>
+<?php
+$client_id = get_client_id($_SESSION['email']);
+//Add teen minutes to permit to show reservations after the end of the flight
+$date_now = date('Y-m-d\TH:i', time() + 600);
+global $connection;
+$sql_pquery = "select RESERVATIONS.NumVol as NumVol, VilleD, DateD, VilleA, DateA, RESERVATIONS.Classe, NbPlaces, round(CoutVol*CoeffPrix*NbPlaces, 2) as Prix
+               from RESERVATIONS join VOLS on RESERVATIONS.NumVol = VOLS.NumVol
+               join DEFCLASSES on DEFCLASSES.NumVol = VOLS.NumVol and RESERVATIONS.Classe = DEFCLASSES.Classe
+                          where NumCl = ? and DateD > ?
+               order by DateD, NumVol, Prix";
+$connection->prepare_query($sql_pquery);
+$connection->prepared_query_bind_param("is", array($client_id, $date_now));
+$connection->run_prepared_query();
+$connection->get_pquery_result();
+$rows = $connection->get_result_array();
+$connection->close_prepared_query();
+//var_dump($rows);
+if (empty($rows)) {
+    echo "Aucune(s) re&#769;servation(s) en cours pour le moment. <br>";
+} else {
+    echo "<table id=\"reservations\">\n";
+    echo "  <tr>\n";
+    echo "    <th>Nume&#769;ro de vol</th>\n";
+    echo "    <th>Ville de de&#769;part</th>\n";
+    echo "    <th>Date de de&#769;part</th>\n";
+    echo "    <th>Ville d'arrive&#769;e</th>\n";
+    echo "    <th>Date d'arrive&#769;e</th>\n";
+    echo "    <th>Classe</th>\n";
+    echo "    <th>Nombre de place(s)</th>\n";
+    echo "    <th>Prix</th>\n";
+    echo "    <th>Actions</th>\n";
+    echo "  </tr>\n";
+    foreach ($rows as $row) {
+        echo "  <tr>\n";
+        echo "    <td>" . $row['NumVol'] . "</td>\n";
+        echo "    <td>" . $row['VilleD'] . "</td>\n";
+        echo "    <td>" . $row['DateD'] . "</td>\n";
+        echo "    <td>" . $row['VilleA'] . "</td>\n";
+        echo "    <td>" . $row['DateA'] . "</td>\n";
+        echo "    <td>" . $row['Classe'] . "</td>\n";
+        echo "    <td>" . $row['NbPlaces'] . "</td>\n";
+        echo "    <td>" . $row['Prix'] . "&euro;</td>\n";
+        echo "    <td>
+                    <form action=\"index.php\" id=\"reservations\" method=\"post\">
+                      <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=\"submit\" name=\"cancel\" value=\"Annuler\">
+                    </form>
+                  </td>\n";
+        echo "  </tr>\n";
+    }
+    echo "</table>";
+}
+?>
index 03a956079e021cac06febe8b22112186155dba38..3365090f26c9cef10a04b08fe0331af73b554863 100644 (file)
@@ -4,15 +4,45 @@
 
 <form action="index.php" id="search" method="post">
  <input type="hidden" name="form" value="search" />
- <input type="hidden" name="date_now" value="<?php echo date('Y-m-d\TH:i'); ?>" />
+ <input type="hidden" name="date_now" value="<?php echo date('Y-m-d\TH:i', time() - 600); ?>" />
  <label> De&#769;part : Ville -> </label>
- <input type="text" size="15" name="departure_city" required/>
+ <select size="1" name="departure_city" required>
+  <optgroup label="Se&#769;lectionner une ville">
+ <?php
+ $sql_pquery = "select distinct VilleD from VOLS";
+ global $connection;
+ $connection->prepare_query($sql_pquery);
+ $connection->run_prepared_query();
+ $connection->get_pquery_result();
+ $cities = $connection->get_result_array();
+ $connection->close_prepared_query();
+ foreach ($cities as $city) {
+     echo "<option value=\"$city[0]\">$city[0]</option>\n";
+ }
+ ?>
+  </optgroup>
+ </select>
  <label> Date -> </label>
  <input type="datetime-local" name="departure_date" value="<?php echo date('Y-m-d\TH:i'); ?>" required/>
  <label> Arrive&#769;e : Ville -> </label>
- <input type="text" size="15" name="arrival_city" required/>
+ <select size="1" name="arrival_city" required>
+  <optgroup label="Se&#769;lectionner une ville">
+ <?php
+ $sql_pquery = "select distinct VilleA from VOLS";
+ global $connection;
+ $connection->prepare_query($sql_pquery);
+ $connection->run_prepared_query();
+ $connection->get_pquery_result();
+ $cities = $connection->get_result_array();
+ $connection->close_prepared_query();
+ foreach ($cities as $city) {
+     echo "<option value=\"$city[0]\">$city[0]</option>\n";
+ }
+ ?>
+  </optgroup>
+ </select>
  <label> Date -> </label>
- <input type="datetime-local" name="arrival_date" value="<?php echo date('Y-m-d\TH:i', time() + 86400); ?>" required/>
+ <input type="datetime-local" name="arrival_date" />
  <input type="submit" value="Valider">
 </form>
 <br>
index a5e5ebc4062f4462d0daa2cc95f71d01f10df0f7..fbbb3cc13ade1d05ffb0a82234d366c697870eb0 100644 (file)
@@ -45,7 +45,11 @@ form#booking {
     width: 250px;
 }
 
-label, input {
+form#reservations {
+    width: 130px;
+}
+
+label, input, select {
     /* in order to define widths */
     display: inline-block;
 }
@@ -63,6 +67,13 @@ label + input {
     margin: 0 30% 0 4%;
 }
 
+label + select {
+    width: 30%;
+    /* large margin-right to force the next element to the new-line
+       and margin-left to create a gutter between the label and select */
+    margin: 0 30% 0 4%;
+}
+
 /* only the submit button is matched by this selector,
    but to be sure you could use an id or class for that button */
 input + input {
@@ -91,6 +102,18 @@ table#search tr:nth-child(odd) {
     background-color: #474343;
 }
 
+table#reservations {
+    border: none;
+}
+
+table#reservations tr:nth-child(even) {
+    background-color: #675b5b;
+}
+
+table#reservations tr:nth-child(odd) {
+    background-color: #474343;
+}
+
 #header {
     font-size: 4em;
     text-align: center;