Avoid the booking of full fligths.
[Project_webapp.git] / includes / reservations.php
index f560b9a1dd776ce60f4d14cf8aa4f947704062be..0d32077720b46e5c5271580c0ad8461c44a3833b 100644 (file)
@@ -2,6 +2,7 @@
 global $is_logged_in;
 if (!$is_logged_in) {
     echo "Please login first. <br>";
+    $_SESSION['login_referer'] = $_SERVER['HTTP_REFERER'];
     redirect("index.php?page=login", 2);
     include('footer.html');
     exit();
@@ -10,12 +11,13 @@ if (!$is_logged_in) {
 <h1>Mes re&#769;servations</h1>
 <?php
 $client_id = get_client_id($_SESSION['email']);
-//Add teen minutes to permit to show reservations after the end of the flight
+// Add teen minutes to permit to show reservations after the end of the flight
 $date_now = date('Y-m-d\TH:i', time() + 600);
+$oDateNow = new Datetime($date_now);
 global $connection;
 $sql_pquery = "select RESERVATIONS.NumVol as NumVol, VilleD, DateD, VilleA, DateA, RESERVATIONS.Classe, NbPlaces, round(CoutVol*CoeffPrix*NbPlaces, 2) as Prix
                from RESERVATIONS join VOLS on RESERVATIONS.NumVol = VOLS.NumVol
-               join DEFCLASSES on DEFCLASSES.NumVol = VOLS.NumVol and RESERVATIONS.Classe = DEFCLASSES.Classe
+               join DEFCLASSES on DEFCLASSES.NumVol = RESERVATIONS.NumVol and DEFCLASSES.NumVol = VOLS.NumVol and DEFCLASSES.Classe = RESERVATIONS.Classe
                           where NumCl = ? and DateD > ?
                order by DateD, NumVol, Prix";
 $connection->prepare_query($sql_pquery);
@@ -24,7 +26,6 @@ $connection->run_prepared_query();
 $connection->get_pquery_result();
 $rows = $connection->get_result_array();
 $connection->close_prepared_query();
-//var_dump($rows);
 if (empty($rows)) {
     echo "Aucune(s) re&#769;servation(s) en cours pour le moment. <br>";
 } else {
@@ -41,6 +42,7 @@ if (empty($rows)) {
     echo "    <th>Actions</th>\n";
     echo "  </tr>\n";
     foreach ($rows as $row) {
+        $oDepartureDate = new DateTime($row['DateD']);
         echo "  <tr>\n";
         echo "    <td>" . $row['NumVol'] . "</td>\n";
         echo "    <td>" . $row['VilleD'] . "</td>\n";
@@ -50,17 +52,21 @@ if (empty($rows)) {
         echo "    <td>" . $row['Classe'] . "</td>\n";
         echo "    <td>" . $row['NbPlaces'] . "</td>\n";
         echo "    <td>" . $row['Prix'] . "&euro;</td>\n";
-        echo "    <td>
-                    <form action=\"index.php\" id=\"reservations\" method=\"post\">
-                      <input type=\"hidden\" name=\"form\" value=\"reservations\" />
-                      <input type=\"hidden\" name=\"flight_id\" value=\"" . $row['NumVol'] . "\" />
-                      <input type=\"hidden\" name=\"class_name\" value=\"" . $row['Classe'] . "\" />
-                      <input type=\"submit\" name=\"modify\" value=\"Modifier\">
-                      <input type=\"submit\" name=\"cancel\" value=\"Annuler\">
-                    </form>
-                  </td>\n";
+        if ($oDepartureDate > $oDateNow) {
+            echo "    <td>
+                        <form action=\"index.php\" id=\"reservations\" method=\"post\">
+                          <input type=\"hidden\" name=\"form\" value=\"reservations\" />
+                          <input type=\"hidden\" name=\"flight_id\" value=\"" . $row['NumVol'] . "\" />
+                          <input type=\"hidden\" name=\"class_name\" value=\"" . $row['Classe'] . "\" />
+                          <input type=\"button\" name=\"modify\" value=\"Modifier\" onClick=\"location.href='index.php?page=modify&flight_id=" . $row['NumVol'] . "&class_name=" . $row['Classe'] . "';\">
+                          <input type=\"button\" name=\"cancel\" value=\"Annuler\" onClick=\"ConfirmCancelFlight()\">
+                        </form>
+                      </td>\n";
+        } else {
+            echo "Vol en cours\n";
+        }
         echo "  </tr>\n";
     }
-    echo "</table>";
+    echo "</table>\n";
 }
 ?>