Avoid the booking of full fligths.
[Project_webapp.git] / includes / reservations.php
CommitLineData
a96fefe1
JB
1<?php
2global $is_logged_in;
3if (!$is_logged_in) {
a2f7a729 4 echo "Please login first. <br>";
22f1dc64 5 $_SESSION['login_referer'] = $_SERVER['HTTP_REFERER'];
a96fefe1 6 redirect("index.php?page=login", 2);
01135b89 7 include('footer.html');
f78b3417 8 exit();
a96fefe1
JB
9}
10?>
5b8676e8 11<h1>Mes re&#769;servations</h1>
a2f7a729
JB
12<?php
13$client_id = get_client_id($_SESSION['email']);
0a87f453 14// Add teen minutes to permit to show reservations after the end of the flight
a2f7a729 15$date_now = date('Y-m-d\TH:i', time() + 600);
0a87f453 16$oDateNow = new Datetime($date_now);
a2f7a729
JB
17global $connection;
18$sql_pquery = "select RESERVATIONS.NumVol as NumVol, VilleD, DateD, VilleA, DateA, RESERVATIONS.Classe, NbPlaces, round(CoutVol*CoeffPrix*NbPlaces, 2) as Prix
19 from RESERVATIONS join VOLS on RESERVATIONS.NumVol = VOLS.NumVol
68cee0ac 20 join DEFCLASSES on DEFCLASSES.NumVol = RESERVATIONS.NumVol and DEFCLASSES.NumVol = VOLS.NumVol and DEFCLASSES.Classe = RESERVATIONS.Classe
a2f7a729
JB
21 where NumCl = ? and DateD > ?
22 order by DateD, NumVol, Prix";
23$connection->prepare_query($sql_pquery);
24$connection->prepared_query_bind_param("is", array($client_id, $date_now));
25$connection->run_prepared_query();
26$connection->get_pquery_result();
27$rows = $connection->get_result_array();
28$connection->close_prepared_query();
a2f7a729
JB
29if (empty($rows)) {
30 echo "Aucune(s) re&#769;servation(s) en cours pour le moment. <br>";
31} else {
32 echo "<table id=\"reservations\">\n";
33 echo " <tr>\n";
34 echo " <th>Nume&#769;ro de vol</th>\n";
35 echo " <th>Ville de de&#769;part</th>\n";
36 echo " <th>Date de de&#769;part</th>\n";
37 echo " <th>Ville d'arrive&#769;e</th>\n";
38 echo " <th>Date d'arrive&#769;e</th>\n";
39 echo " <th>Classe</th>\n";
40 echo " <th>Nombre de place(s)</th>\n";
41 echo " <th>Prix</th>\n";
42 echo " <th>Actions</th>\n";
43 echo " </tr>\n";
44 foreach ($rows as $row) {
0a87f453 45 $oDepartureDate = new DateTime($row['DateD']);
a2f7a729
JB
46 echo " <tr>\n";
47 echo " <td>" . $row['NumVol'] . "</td>\n";
48 echo " <td>" . $row['VilleD'] . "</td>\n";
49 echo " <td>" . $row['DateD'] . "</td>\n";
50 echo " <td>" . $row['VilleA'] . "</td>\n";
51 echo " <td>" . $row['DateA'] . "</td>\n";
52 echo " <td>" . $row['Classe'] . "</td>\n";
53 echo " <td>" . $row['NbPlaces'] . "</td>\n";
54 echo " <td>" . $row['Prix'] . "&euro;</td>\n";
0a87f453
JB
55 if ($oDepartureDate > $oDateNow) {
56 echo " <td>
57 <form action=\"index.php\" id=\"reservations\" method=\"post\">
58 <input type=\"hidden\" name=\"form\" value=\"reservations\" />
59 <input type=\"hidden\" name=\"flight_id\" value=\"" . $row['NumVol'] . "\" />
60 <input type=\"hidden\" name=\"class_name\" value=\"" . $row['Classe'] . "\" />
c49f7219 61 <input type=\"button\" name=\"modify\" value=\"Modifier\" onClick=\"location.href='index.php?page=modify&flight_id=" . $row['NumVol'] . "&class_name=" . $row['Classe'] . "';\">
77c2d82c 62 <input type=\"button\" name=\"cancel\" value=\"Annuler\" onClick=\"ConfirmCancelFlight()\">
0a87f453
JB
63 </form>
64 </td>\n";
65 } else {
22f1dc64 66 echo "Vol en cours\n";
0a87f453 67 }
a2f7a729
JB
68 echo " </tr>\n";
69 }
22f1dc64 70 echo "</table>\n";
a2f7a729
JB
71}
72?>