Add password change feature.
[Project_webapp.git] / includes / search.php
index 03a956079e021cac06febe8b22112186155dba38..e2503d96536f5e1988e5a485cf3b77d09ef5595d 100644 (file)
@@ -1,18 +1,82 @@
-<h1> Rechercher un vol </h1>
+<?php
+$action = filter_input(INPUT_GET, "action", FILTER_SANITIZE_STRING);
+?>
+<h1> Rechercher un vol <?php if ($action === "return_flight") { echo "retour"; } ?></h1>
 
-<?php if (isset($_SESSION['return_flight'])) ?>
+<?php
+
+$return_flight_departure_city = "";
+$return_flight_arrival_city = "";
+$return_flight_departure_date = "";
+$oDepartureDate = new DateTime("now");
+if ($action === "return_flight") {
+    if (isset($_SESSION['return_flight_departure_city'])) $return_flight_departure_city = $_SESSION['return_flight_departure_city'];
+    if (isset($_SESSION['return_flight_arrival_city'])) $return_flight_arrival_city = $_SESSION['return_flight_arrival_city'];
+    if (isset($_SESSION['return_flight_departure_date'])) {
+        $return_flight_departure_date = $_SESSION['return_flight_departure_date'];
+        $oDepartureDate = new DateTime($return_flight_departure_date);
+    }
+}
+
+?>
 
 <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'); ?>" />
+ <?php if ($action === "return_flight") echo "<input type=\"hidden\" name=\"action\" value=\"return_flight\" />" ?>
+ <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) {
+     if (strcmp($city[0], $return_flight_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 date('Y-m-d\TH:i'); ?>" required/>
+ <input type="datetime-local" name="departure_date" value="<?php echo $oDepartureDate->format('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) {
+     if (strcmp($city[0], $return_flight_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 date('Y-m-d\TH:i', time() + 86400); ?>" required/>
- <input type="submit" value="Valider">
+ <input type="datetime-local" name="arrival_date" />
+ <input type="submit" value="Rechercher">
 </form>
 <br>
+
+<?php
+// Unset all used session variables
+unset($_SESSION['return_flight_departure_city']);
+unset($_SESSION['return_flight_arrival_city']);
+unset($_SESSION['return_flight_departure_date']);
+?>