And fix a couple of bugs.
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
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();
}
-?>
-<h2>Mes informations</h2>
-<h2><a href="<?php echo $configs['root_url']; ?>/index.php?page=reservations">Mes réservations</a></h2>
+$action = filter_input(INPUT_GET, "action", FILTER_SANITIZE_STRING);
+
+global $connection;
+$sql_pquery = "select NomCl, PrenomCl, EmailCl, NumRueCl, NomRueCl, CodePosteCl, VilleCl from CLIENTS where EmailCl = ?";
+$connection->prepare_query($sql_pquery);
+$connection->prepared_query_bind_param("s", array($_SESSION['email']));
+$connection->run_prepared_query();
+$connection->get_pquery_result();
+$rows = $connection->get_result_array();
+$connection->close_prepared_query();
+
+if (empty($action)) {
+ echo "<h2>Mes informations</h2>\n";
+
+ echo "<table id=\"account\">\n";
+ foreach ($rows as $row) {
+ echo " <tr>\n";
+ echo " <td>Nom : </td>\n";
+ echo " <td>" . htmlentities($row['NomCl']) . "</td>\n";
+ echo " </tr>\n";
+
+ echo " <tr>\n";
+ echo " <td>Prénom : </td>\n";
+ echo " <td>" . htmlentities($row['PrenomCl']) . "</td>\n";
+ echo " </tr>\n";
+
+ echo " <tr>\n";
+ echo " <td>Email : </td>\n";
+ echo " <td>" . htmlentities($row['EmailCl']) . "</td>\n";
+ echo " </tr>\n";
+
+ echo " <tr>\n";
+ echo " <td>Adresse : </td>\n";
+ echo " <td></td>\n";
+ echo " </tr>\n";
+
+ echo " <tr>\n";
+ echo " <td>Numéro de rue : </td>\n";
+ echo " <td>" . htmlentities($row['NumRueCl']) . "</td>\n";
+ echo " </tr>\n";
+
+ echo " <tr>\n";
+ echo " <td>Rue : </td>\n";
+ echo " <td>" . htmlentities($row['NomRueCl']) . "</td>\n";
+ echo " </tr>\n";
+
+ echo " <tr>\n";
+ echo " <td>Code postal : </td>\n";
+ echo " <td>" . htmlentities($row['CodePosteCl']) . "</td>\n";
+ echo " </tr>\n";
+
+ echo " <tr>\n";
+ echo " <td>Ville : </td>\n";
+ echo " <td>" . htmlentities($row['VilleCl']) . "</td>\n";
+ echo " </tr>\n";
+ }
+ echo "</table>\n";
+
+ echo "| <a href=\"" . $configs['root_url'] . "/index.php?page=account&action=modifyaccount\">Modifier vos informations</a> | <a href=\"" . $configs['root_url'] . "/index.php?page=account&action=modifypassword\">Modifier votre mot de passe</a> |\n";
+ echo "<h2><a href=\"" . $configs['root_url'] . "/index.php?page=reservations\">Mes réservations</a></h2>\n";
+} elseif ($action === "modifyaccount") {
+ echo "
+ <form action=\"index.php\" id=\"account\" method=\"post\">
+ <input type=\"hidden\" name=\"form\" value=\"account\" />
+ <label> Nom : </label>
+ <input type=\"text\" size=\"25\" name=\"name\" value=\"" . $rows[0]['NomCl'] . "\" required/>
+ <label> Prénom : </label>
+ <input type=\"text\" size=\"25\" name=\"firstname\" value=\"" . $rows[0]['PrenomCl'] . "\" required/>
+ <label> Adresse : <br> Numéro de rue : </label>
+ <input type=\"number\" size=\"5\" name=\"numstreet\" value=\"" . $rows[0]['NumRueCl'] . "\" required/>
+ <label> Rue : </label>
+ <input type=\"text\" size=\"50\" name=\"street\" value=\"" . $rows[0]['NomRueCl'] . "\" required/>
+ <label> Code postal : </label>
+ <input type=\"number\" size=\"5\" name=\"postalcode\" value=\"" . $rows[0]['CodePosteCl'] . "\" required/>
+ <label> Ville : </label>
+ <input type=\"text\" size=\"15\" name=\"city\" value=\"" . $rows[0]['VilleCl'] . "\" required/>
+ <label> Email : </label>
+ <input type=\"email\" size=\"25\" name=\"email\" value=\"" . $rows[0]['EmailCl'] . "\" required/>
+ <input type=\"submit\" value=\"Valider\">
+ </form>
+ <br>\n";
+} elseif ($action === "modifypassword") {
+ echo "Work in progress. <br>\n";
+ redirect("index.php?page=account", 3);
+} else {
+ echo "Unknown account action. <br>\n";
+}
+
+?>
--- /dev/null
+<?php
+$form_name = filter_input(INPUT_POST, "name", FILTER_SANITIZE_STRING);
+$form_firstname = filter_input(INPUT_POST, "firstname", FILTER_SANITIZE_STRING);
+$form_numstreet = filter_input(INPUT_POST, "numstreet", FILTER_VALIDATE_INT);
+$form_street = filter_input(INPUT_POST, "street", FILTER_SANITIZE_STRING);
+$form_postalcode = filter_input(INPUT_POST, "postalcode", FILTER_VALIDATE_INT);
+$form_city = filter_input(INPUT_POST, "city", FILTER_SANITIZE_STRING);
+$form_email = filter_input(INPUT_POST, "email", FILTER_VALIDATE_EMAIL);
+
+$input_failure = false;
+
+if (!$form_numstreet) {
+ echo "The street number is not valid. <br>" ;
+ $input_failure = true;
+}
+if (!$form_postalcode) {
+ echo "The postal code is not valid. <br>";
+ $input_failure = true;
+}
+if (!$form_email) {
+ echo "The email is not valid. <br>";
+ $input_failure = true;
+}
+
+if (!empty($form_name) && !empty($form_firstname) && !empty($form_numstreet) && !empty($form_street) &&
+ !empty($form_postalcode) && !empty($form_city) && !empty($form_email) &&
+ !$input_failure) {
+ global $connection;
+ $client_id = get_client_id($_SESSION['email']);
+ $sql_pquery = "update CLIENTS
+ set NomCl = ?, PrenomCl = ?, EmailCl = ?, NumRueCl = ?, NomRueCl = ?, CodePosteCl = ?, VilleCl = ?
+ where NumCl = ?";
+ $connection->prepare_query($sql_pquery);
+ $connection->prepared_query_bind_param("sssisisi", array($form_name, $form_firstname, $form_email, $form_numstreet, $form_street, $form_postalcode, $form_city, $client_id));
+ $connection->run_prepared_query();
+ $connection->close_prepared_query();
+ echo "You've updated your personal informations, you will be redirected to your account in 3 seconds. <br>";
+ redirect("index.php?page=account", 3);
+
+} else {
+ echo "There's a required non filled field or the input in a field do not match the required pattern. <br>";
+ echo "<a href=\"javascript:history.go(-1)\">Retour</a>";
+}
+?>
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);
}
$input_failure = true;
}
-if (!$form_return_flight) {
+if (is_null($form_return_flight)) {
+ $form_return_flight = false;
+} elseif (!$form_return_flight) {
echo "Vol retour invalide. <br>";
$input_failure = true;
}
if (!$input_failure && $is_logged_in && !empty($form_nb_place) && !empty($form_class_name)) {
global $connection;
$client_id = get_client_id($_SESSION['email']);
- $nb_booked = nb_booked($client_id, $form_flight_id);
+ $nb_booked = nb_booked($client_id, $form_flight_id, $form_class_name);
if (!empty($nb_booked)) {
echo "Vous avez déjà réservé ce vol, vous allez être redirigé vers la liste de vos réservations dans 2 secondes. <br>";
redirect("index.php?page=reservations", 2);
$rows = $connection->get_result_array();
$connection->close_prepared_query();
foreach ($rows as $row) {
- echo "(Simulation de paiement d'une réservation) <br>";
+ echo "(Simulation de validation et paiement d'une réservation) <br>";
echo "Vous avez réservé et payé " . $form_nb_place . " place(s) sur le vol " .$form_flight_id .
" au départ de " . $row['VilleD']. " à " . $row['DateD'] . " arrivant à " . $row['VilleA'] . " à " . $row['DateA'] .
" pour un montant total de " . $form_place_price * $form_nb_place . "€. <br>";
}
if ($form_return_flight) {
- redirect("index.php?page=search", 3);
- $_SESSION['current_flight_id'] = $form_flight_id;
- $_SESSION['return_flight'] = $form_return_flight;
+ $_SESSION['return_flight_departure_city'] = $row['VilleA'];
+ $_SESSION['return_flight_arrival_city'] = $row['VilleD'];
+ $_SESSION['return_flight_departure_date'] = $row['DateA'];
+ redirect("index.php?page=search&action=return_flight", 3);
} else {
redirect("index.php?page=reservations", 3);
}
$form_arrival_city = filter_input(INPUT_POST, "arrival_city", FILTER_SANITIZE_STRING);
$form_arrival_date = filter_input(INPUT_POST, "arrival_date", FILTER_SANITIZE_STRING);
$form_date_now = filter_input(INPUT_POST, "date_now", FILTER_SANITIZE_STRING);
+$action = filter_input(INPUT_POST, "action", FILTER_SANITIZE_STRING);
$oDepartureDate = new DateTime($form_departure_date);
$oArrivalDate = new DateTime($form_arrival_date);
$input_failure = true;
}
-if ($oArrivalDate <= $oDepartureDate) {
+if (!($action === "return_flight") && $oArrivalDate <= $oDepartureDate) {
echo "Arrival date is before departure date. <br>";
$input_failure = true;
}
?>
-<h1> Rechercher un vol </h1>
+<h1> Rechercher un vol <?php if ($action === "return_flight") { echo "retour"; } ?></h1>
<form action="index.php" id="search" method="post">
<input type="hidden" name="form" value="search" />
+ <?php if ($action === "return_flight") echo "<input type=\"hidden\" name=\"action\" value=\"return_flight\" />" ?>
<input type="hidden" name="date_now" value="<?php echo $form_date_now; ?>" />
<label> Départ : Ville -> </label>
<select size="1" name="departure_city" required>
<?php
if (!$input_failure) {
global $connection;
- $sql_pquery = "select VOLS.NumVol as NumVol, VilleD, DateD, VilleA, DateA, Classe, round(CoutVol*CoeffPrix, 2) as Prix from VOLS, DEFCLASSES
+ $sql_pquery = "select VOLS.NumVol as NumVol, VilleD, DateD, VilleA, DateA, Classe, round(CoutVol*CoeffPrix, 2) as Prix, NumAv from VOLS, DEFCLASSES
where DEFCLASSES.NumVol = VOLS.NumVol and
DateD >= ? and VilleD = ? and DateA <= ? and VilleA = ?
order by DateD, NumVol, Prix";
$connection->get_pquery_result();
$rows = $connection->get_result_array();
$connection->close_prepared_query();
+ //FIXME: Use NumAv to see if a flight is fully booked.
//var_dump($rows);
if (empty($rows)) {
echo "Aucun vol ne correspond aux critères de recherche. <br>";
<input type=\"hidden\" name=\"place_price\" value=\"" . $row['Prix'] . "\" />
<label> Place(s) : </label>
<input type=\"number\" name=\"nb_place\" min=\"1\" max=\"9\" value=\"1\" required/>
- <label> Vol retour : </label>
- <input type=\"checkbox\" name=\"return_flight\" checked required/>
- <input type=\"submit\" value=\"Réserver\">
- </form>
- </td>\n";
+ <label> Vol retour : </label>\n";
+ if (!($action === "return_flight")) {
+ echo " <input type=\"checkbox\" name=\"return_flight\" checked/>\n";
+ }
+ echo " <input type=\"submit\" value=\"Réserver\">\n";
+ echo " </form>
+ </td>\n";
echo " </tr>\n";
}
- echo "</table>";
+ echo "</table>\n";
}
}
|
<?php
if ($is_logged_in) {
- echo "<a href=\"" . $configs['root_url'] . "/index.php?page=reservations\">Mes réservations</a> |";
+ echo "<a href=\"" . $configs['root_url'] . "/index.php?page=reservations\">Mes réservations</a> |\n";
}
?>
</div>
<label> Ville :* </label>
<input type="text" size="15" name="city" required/>
<label> Email :* </label>
- <input type="email" size="25 "name="email" required/>
+ <input type="email" size="25" name="email" required/>
<label> Mot de passe :* </label>
<input type="password" minlength="8" size="15" name="password" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*" title="Doit contenir 8 caractères minimum dont une majuscule, une minuscule et un chiffre" required/>
<label> Confirmation du mot de passe :* </label>
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();
</form>
</td>\n";
} else {
- echo "Vol en cours";
+ echo "Vol en cours\n";
}
echo " </tr>\n";
}
- echo "</table>";
+ echo "</table>\n";
}
?>
-<h1> Rechercher un vol </h1>
+<?php
+$action = filter_input(INPUT_GET, "action", FILTER_SANITIZE_STRING);
+?>
+<h1> Rechercher un vol <?php if ($action === "return_flight") { echo "retour"; } ?></h1>
-<?php if (isset($_SESSION['return_flight'])) ?>
+<?php
+
+$return_flight_departure_city = "";
+$return_flight_arrival_city = "";
+$return_flight_departure_date = "";
+$oDepartureDate = new DateTime("now");
+if ($action === "return_flight") {
+ //var_dump($_SESSION);
+ if (isset($_SESSION['return_flight_departure_city'])) $return_flight_departure_city = $_SESSION['return_flight_departure_city'];
+ if (isset($_SESSION['return_flight_arrival_city'])) $return_flight_arrival_city = $_SESSION['return_flight_arrival_city'];
+ if (isset($_SESSION['return_flight_departure_date'])) {
+ $return_flight_departure_date = $_SESSION['return_flight_departure_date'];
+ $oDepartureDate = new DateTime($return_flight_departure_date);
+ }
+}
+
+?>
<form action="index.php" id="search" method="post">
<input type="hidden" name="form" value="search" />
+ <?php if ($action === "return_flight") echo "<input type=\"hidden\" name=\"action\" value=\"return_flight\" />" ?>
<input type="hidden" name="date_now" value="<?php echo date('Y-m-d\TH:i', time() - 600); ?>" />
<label> Départ : Ville -> </label>
<select size="1" name="departure_city" required>
$cities = $connection->get_result_array();
$connection->close_prepared_query();
foreach ($cities as $city) {
- echo "<option value=\"$city[0]\">$city[0]</option>\n";
+ if (strcmp($city[0], $return_flight_departure_city) === 0) {
+ echo "<option value=\"$city[0]\" selected>$city[0]</option>\n";
+ } else {
+ echo "<option value=\"$city[0]\">$city[0]</option>\n";
+ }
}
?>
</optgroup>
</select>
<label> Date -> </label>
- <input type="datetime-local" name="departure_date" value="<?php echo date('Y-m-d\TH:i'); ?>" required/>
+ <input type="datetime-local" name="departure_date" value="<?php echo $oDepartureDate->format('Y-m-d\TH:i'); ?>" required/>
<label> Arrivée : Ville -> </label>
<select size="1" name="arrival_city" required>
<optgroup label="Sélectionner une ville">
$cities = $connection->get_result_array();
$connection->close_prepared_query();
foreach ($cities as $city) {
- echo "<option value=\"$city[0]\">$city[0]</option>\n";
+ if (strcmp($city[0], $return_flight_arrival_city) === 0) {
+ echo "<option value=\"$city[0]\" selected>$city[0]</option>\n";
+ } else {
+ echo "<option value=\"$city[0]\">$city[0]</option>\n";
+ }
}
?>
</optgroup>
<input type="submit" value="Rechercher">
</form>
<br>
+
+<?php
+// Unset all used session variables
+unset($_SESSION['return_flight_departure_city']);
+unset($_SESSION['return_flight_arrival_city']);
+unset($_SESSION['return_flight_departure_date']);
+?>
$form = "";
}
+//var_dump($_SESSION);
+
function get_action_type() {
global $is_page, $is_form;
* @param [type] $flight_id [description]
* @return [type] [description]
*/
-function nb_booked($client_id, $flight_id)
+function nb_booked($client_id, $flight_id, $class_name)
{
global $connection;
- $sql_pquery = "select SUM(NbPlaces) from RESERVATIONS where NumCl = ? and NumVol = ?";
+ $sql_pquery = "select SUM(NbPlaces) from RESERVATIONS where NumCl = ? and NumVol = ? and Classe = ?";
$connection->prepare_query($sql_pquery);
- $connection->prepared_query_bind_param("is", array($client_id, $flight_id));
+ $connection->prepared_query_bind_param("iss", array($client_id, $flight_id, $class_name));
$connection->run_prepared_query();
$connection->get_pquery_result();
$row = $connection->get_result_array();
text-align: right;
}
-label + input {
+label+input {
width: 30%;
/* large margin-right to force the next element to the new-line
and margin-left to create a gutter between the label and input */
margin: 0 30% 0 4%;
}
-label + select {
+label+select {
width: 30%;
/* large margin-right to force the next element to the new-line
and margin-left to create a gutter between the label and select */
/* only the submit button is matched by this selector,
but to be sure you could use an id or class for that button */
-input + input {
+input+input {
float: right;
}
table {
margin: 0px auto;
width: 100%;
+ vertical-align: middle;
+}
+
+table#account {
+ width: 40%;
}
table#home {