cd12ee4a5b988b8aff76f592022ed64c1f77cd3e
2 $form_departure_city = filter_input(INPUT_POST
, "departure_city", FILTER_SANITIZE_STRING
);
3 $form_departure_date = filter_input(INPUT_POST
, "departure_date", FILTER_SANITIZE_STRING
);
4 $form_arrival_city = filter_input(INPUT_POST
, "arrival_city", FILTER_SANITIZE_STRING
);
5 $form_arrival_date = filter_input(INPUT_POST
, "arrival_date", FILTER_SANITIZE_STRING
);
6 $form_date_now = filter_input(INPUT_POST
, "date_now", FILTER_SANITIZE_STRING
);
7 $action = filter_input(INPUT_POST
, "action", FILTER_SANITIZE_STRING
);
9 $oDepartureDate = new DateTime($form_departure_date);
10 $oArrivalDate = new DateTime($form_arrival_date);
11 $oDateNow = new Datetime($form_date_now);
17 $input_failure = false;
19 if ($form_departure_city === $form_arrival_city) {
20 echo "Departure and arrival city are the same. <br>";
21 $input_failure = true;
24 if ($oDepartureDate < $oDateNow) {
25 echo "The departure date is before the current date. <br>";
26 $input_failure = true;
29 if (!($action === "return_flight") && $oArrivalDate <= $oDepartureDate) {
30 echo "Arrival date is before departure date. <br>";
31 $input_failure = true;
34 if (empty($form_arrival_date)) {
35 // Limit to a 6 months interval from the departure date.
36 $oArrivalDate = $oDepartureDate;
37 $oArrivalDate->add(new DateInterval("P6M"));
38 $form_arrival_date = $oArrivalDate->format('Y-m-d\TH:i');
43 <h1
> Rechercher un vol
<?php
if ($action === "return_flight") { echo "retour"; } ?
> </h1
>
45 <form action
="index.php" id
="search" method
="post">
46 <input type
="hidden" name
="form" value
="search" />
47 <?php
if ($action === "return_flight") { echo "<input type=\"hidden\" name=\"action\" value=\"return_flight\" />"; } ?
>
48 <input type
="hidden" name
="date_now" value
="<?php echo $form_date_now; ?>" />
49 <label
> De
́part : Ville -> </label>
50 <select size
="1" name
="departure_city" required
>
51 <optgroup label
="Sélectionner une ville">
53 $sql_pquery = "select distinct VilleD from VOLS order by VilleD";
55 $connection->prepare_query($sql_pquery);
56 $connection->run_prepared_query();
57 $connection->get_pquery_result();
58 $cities = $connection->get_result_array();
59 $connection->close_prepared_query();
60 foreach ($cities as $city) {
61 if (strcmp($city[0], $form_departure_city) === 0) {
62 echo "<option value=\"$city[0]\" selected>$city[0]</option>\n";
64 echo "<option value=\"$city[0]\">$city[0]</option>\n";
70 <label
> Date
-> </label
>
71 <input type
="datetime-local" name
="departure_date" value
="<?php echo $form_departure_date; ?>" required
/>
72 <label
> Arrive
́e : Ville -> </label>
73 <select size
="1" name
="arrival_city" required
>
74 <optgroup label
="Sélectionner une ville">
76 $sql_pquery = "select distinct VilleA from VOLS order by VilleA";
78 $connection->prepare_query($sql_pquery);
79 $connection->run_prepared_query();
80 $connection->get_pquery_result();
81 $cities = $connection->get_result_array();
82 $connection->close_prepared_query();
83 foreach ($cities as $city) {
84 if (strcmp($city[0], $form_arrival_city) === 0) {
85 echo "<option value=\"$city[0]\" selected>$city[0]</option>\n";
87 echo "<option value=\"$city[0]\">$city[0]</option>\n";
93 <label
> Date
-> </label
>
94 <input type
="datetime-local" name
="arrival_date" <?php
if (isset($form_arrival_date)) { echo "value=\"$form_arrival_date\""; } ?
> />
95 <input type
="submit" value
="Rechercher">
100 if (!$input_failure) {
102 $sql_pquery = "select VOLS.NumVol as NumVol, VilleD, DateD, VilleA, DateA, DEFCLASSES.Classe, round(CoutVol*CoeffPrix, 2) as Prix, CapAv
103 from VOLS join DEFCLASSES on DEFCLASSES.NumVol = VOLS.NumVol
104 join AVIONS on AVIONS.NumAv = VOLS.NumAv
105 where DateD >= ? and VilleD = ? and DateA <= ? and VilleA = ?
106 order by DateD, NumVol, Prix";
107 $connection->prepare_query($sql_pquery);
108 $connection->prepared_query_bind_param("ssss", array($form_departure_date, $form_departure_city, $form_arrival_date, $form_arrival_city));
109 $connection->run_prepared_query();
110 $connection->get_pquery_result();
111 $fligths = $connection->get_result_array();
112 $connection->close_prepared_query();
113 //var_dump($fligths);
114 if (empty($fligths)) {
115 echo "Aucun vol ne correspond aux critères de recherche. <br>";
117 if ($action === "return_flight" && isset($_SESSION['return_flight_nb_place'])) {
118 $nb_places = $_SESSION['return_flight_nb_place'];
119 unset($_SESSION['return_flight_nb_place']);
123 echo "<table id=\"search\">\n";
125 echo " <th>Numéro de vol</th>\n";
126 echo " <th>Ville de départ</th>\n";
127 echo " <th>Date de départ</th>\n";
128 echo " <th>Ville d'arrivée</th>\n";
129 echo " <th>Date d'arrivée</th>\n";
130 echo " <th>Classe</th>\n";
131 echo " <th>Prix d'une place</th>\n";
132 echo " <th>Réserver</th>\n";
134 foreach ($fligths as $fligth) {
135 $sql_pquery = "select sum(NbPlaces) from RESERVATIONS where NumVol = ?";
136 $connection->prepare_query($sql_pquery);
137 $connection->prepared_query_bind_param("s", array($fligth['NumVol']));
138 $connection->run_prepared_query();
139 $connection->get_pquery_result();
140 $rows = $connection->get_result_array();
141 $connection->close_prepared_query();
142 $booked_places = $rows[0][0];
143 if (is_null($booked_places)) {
146 if (isset($fligth['CapAv']) && isset($booked_places)) {
147 $free_places = $fligth['CapAv'] - $booked_places;
149 $free_places = "Inconnu";
152 echo " <td>" . $fligth['NumVol'] . "</td>\n";
153 echo " <td>" . $fligth['VilleD'] . "</td>\n";
154 echo " <td>" . $fligth['DateD'] . "</td>\n";
155 echo " <td>" . $fligth['VilleA'] . "</td>\n";
156 echo " <td>" . $fligth['DateA'] . "</td>\n";
157 echo " <td>" . $fligth['Classe'] . "</td>\n";
158 echo " <td>" . $fligth['Prix'] . "€</td>\n";
160 Places libres : " . $free_places . "
161 <form action=\"index.php\" id=\"booking\" method=\"post\">
162 <input type=\"hidden\" name=\"form\" value=\"booking\" />
163 <input type=\"hidden\" name=\"flight_id\" value=\"" . $fligth['NumVol'] . "\" />
164 <input type=\"hidden\" name=\"class_name\" value=\"" . $fligth['Classe'] . "\" />
165 <input type=\"hidden\" name=\"place_price\" value=\"" . $fligth['Prix'] . "\" />
166 <label> Place(s) : </label>
167 <input type=\"number\" name=\"nb_place\" min=\"1\" max=\"9\" value=\"" . $nb_places . "\" required/>\n";
168 if ($action !== "return_flight") {
169 echo " <label> Vol retour : </label>\n";
170 echo " <input type=\"checkbox\" name=\"return_flight\" checked/>\n";
172 if ($free_places !== 0 ||
$free_places === "Inconnu") {
173 echo " <input type=\"submit\" value=\"Réserver\">\n";