Commit | Line | Data |
---|---|---|
c49f7219 | 1 | <?php |
8d17cae3 JB |
2 | global $is_logged_in; |
3 | if (!$is_logged_in) { | |
4 | echo "Please login first. <br>"; | |
5 | $_SESSION['login_referer'] = $_SERVER['HTTP_REFERER']; | |
6 | redirect("index.php?page=login", 2); | |
7 | include('footer.html'); | |
8 | exit(); | |
9 | } | |
c49f7219 JB |
10 | $flight_id = filter_input(INPUT_GET, "flight_id", FILTER_SANITIZE_STRING); |
11 | $class_name = filter_input(INPUT_GET, "class_name", FILTER_SANITIZE_STRING); | |
12 | $client_id = get_client_id($_SESSION['email']); | |
8d17cae3 | 13 | echo "<h1> Modification de la réservation sur le vol $flight_id </h2>\n"; |
c49f7219 JB |
14 | global $connection; |
15 | $sql_pquery = "select NumCl, NumVol, Classe, NbPlaces | |
16 | from RESERVATIONS | |
17 | where NumCl = ? and NumVol = ? and Classe = ?"; | |
18 | $connection->prepare_query($sql_pquery); | |
19 | $connection->prepared_query_bind_param("iss", array($client_id, $flight_id, $class_name)); | |
20 | $connection->run_prepared_query(); | |
21 | $connection->get_pquery_result(); | |
22 | $rows = $connection->get_result_array(); | |
23 | $connection->close_prepared_query(); | |
e14003dc JB |
24 | $sql_pquery = "select CapAv, sum(NbPlaces) as BookedPlaces |
25 | from RESERVATIONS, VOLS, AVIONS | |
26 | where RESERVATIONS.NumVol = VOLS.NumVol and AVIONS.NumAv = VOLS.NumAv and | |
27 | RESERVATIONS.NumVol = ? | |
28 | group by RESERVATIONS.NumVol"; | |
29 | $connection->prepare_query($sql_pquery); | |
30 | $connection->prepared_query_bind_param("s", array($flight_id)); | |
31 | $connection->run_prepared_query(); | |
32 | $connection->get_pquery_result(); | |
33 | $rows_cap = $connection->get_result_array(); | |
34 | $connection->close_prepared_query(); | |
35 | //var_dump($rows_cap); | |
36 | $booked_places = $rows_cap[0]['BookedPlaces']; | |
37 | if (is_null($booked_places)) { | |
38 | $booked_places = 0; | |
39 | } | |
40 | if (isset($rows_cap[0]['CapAv']) && isset($booked_places)) { | |
41 | $free_places = $rows_cap[0]['CapAv'] - $booked_places; | |
42 | } else { | |
43 | $free_places = "Inconnu"; | |
44 | } | |
c49f7219 | 45 | ?> |
e14003dc | 46 | <p> Nombre de places libres : <?php echo $free_places ?> </p> |
c49f7219 JB |
47 | <form action="index.php" id="modify" method="post"> |
48 | <input type="hidden" name="form" value="modify" /> | |
49 | <input type="hidden" name="flight_id" value="<?php echo $rows[0]['NumVol'] ?>" /> | |
f38123a5 | 50 | <input type="hidden" name="previous_class_name" value="<?php echo $rows[0]['Classe'] ?>" /> |
e14003dc JB |
51 | <?php |
52 | if ($free_places !== 0 || $free_places === "Inconnu") { | |
53 | echo " <label> Nombre de place(s) : </label>\n"; | |
54 | echo " <input type=\"number\" name=\"nb_place\" min=\"1\" max=\"9\" value=\"" . $rows[0]['NbPlaces'] . "\" required/>\n"; | |
55 | } | |
56 | ?> | |
c49f7219 JB |
57 | <label> Classe : </label> |
58 | <select size="1" name="class_name" required> | |
59 | <optgroup label="Sélectionner une classe"> | |
60 | <?php | |
f38123a5 | 61 | $sql_pquery = "select distinct Classe from DEFCLASSES where NumVol = ? order by Classe"; |
c49f7219 JB |
62 | global $connection; |
63 | $connection->prepare_query($sql_pquery); | |
64 | $connection->prepared_query_bind_param("s", array($flight_id)); | |
65 | $connection->run_prepared_query(); | |
66 | $connection->get_pquery_result(); | |
67 | $classes = $connection->get_result_array(); | |
68 | $connection->close_prepared_query(); | |
69 | foreach ($classes as $class) { | |
70 | if (strcmp($class[0], $rows[0]['Classe']) === 0) { | |
71 | echo "<option value=\"$class[0]\" selected>$class[0]</option>\n"; | |
72 | } else { | |
73 | echo "<option value=\"$class[0]\">$class[0]</option>\n"; | |
74 | } | |
75 | } | |
76 | ?> | |
77 | </optgroup> | |
78 | </select> | |
79 | <input type="submit" value="Valider"> | |
80 | </form> |