Fixlets to today coding session.
[Project_webapp.git] / includes / reservations.php
index f560b9a1dd776ce60f4d14cf8aa4f947704062be..15beeacb5777c9442114277e9bd3a21b885ce332 100644 (file)
@@ -10,8 +10,9 @@ 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
@@ -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,15 +52,19 @@ 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=\"submit\" name=\"modify\" value=\"Modifier\">
+                          <input type=\"submit\" name=\"cancel\" value=\"Annuler\">
+                        </form>
+                      </td>\n";
+        } else {
+            echo "Vol en cours";
+        }
         echo "  </tr>\n";
     }
     echo "</table>";