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