You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
180 lines
6.5 KiB
PHTML
180 lines
6.5 KiB
PHTML
6 years ago
|
<?php
|
||
|
|
||
|
//Récupérer la liste des voitures concernant un utilisateur
|
||
|
function getListeVoitures($db, $mail){
|
||
|
$result = pg_query_params($db, "SELECT * FROM Voiture WHERE mail = $1;", array($mail));
|
||
|
return $result;
|
||
|
}
|
||
|
|
||
|
//Afficher les voitures dans un select
|
||
|
function afficherVoitures($db, $mail){
|
||
|
|
||
|
$voitures = getListeVoitures($db, $mail);
|
||
|
while ($row = pg_fetch_array($voitures)) {
|
||
|
$modele = $row['modele'];
|
||
|
$matricule = $row['matricule'];
|
||
|
echo "<option value='$matricule'>$modele</option>";
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
//Afficher les voitures dans un select
|
||
|
function afficherVilles($db)
|
||
|
{
|
||
|
$villes = getListeVilles($db);
|
||
|
while ($row = pg_fetch_array($villes)) {
|
||
|
$nom = $row['nomville'];
|
||
|
$cp = $row['codepostal'];
|
||
|
echo "<option value='$nom%%$cp'>$nom ($cp)</option>";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function printError()
|
||
|
{
|
||
|
if (isset($_GET['error'])) {
|
||
|
$erreur = getError($_GET['error']);
|
||
|
echo "<p class = 'error'>$erreur</p>";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function getError($code)
|
||
|
{
|
||
|
switch ($code) {
|
||
|
case 1:
|
||
|
return "Erreur lors de la vérification des étapes.";
|
||
|
case 2:
|
||
|
return "Erreur lors de la vérification des dates.";
|
||
|
case 3:
|
||
|
return "Ce compte n'est pas associé à la voiture sélectionnée.";
|
||
|
case 4:
|
||
|
return "Erreur lors de l'enregistrement du trajet.";
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
require_once('../connexionBD.php');
|
||
|
require_once('../ressources/trajet.php');
|
||
|
|
||
|
session_start();
|
||
|
//Utilisateur connecté
|
||
|
if (!isset($_SESSION['mail'])) {
|
||
|
header('Location: ../index.php');
|
||
|
exit();
|
||
|
}
|
||
|
$mail = $_SESSION['mail'];
|
||
|
//Tester que tous les champs ont été renseignés
|
||
|
if (isset($_POST['dateDepart']) && isset($_POST['dateArrivee']) && isset($_POST['voiture']) && isset($_POST['villeDepart']) && isset($_POST['nbEtapes']) && isset($_POST['etape1'])) {
|
||
|
//Récupérer tous les $_POST en variables
|
||
|
$nbEtapes = htmlspecialchars(pg_escape_string($_POST['nbEtapes']));
|
||
|
$dateDepart = htmlspecialchars(pg_escape_string($_POST['dateDepart']));
|
||
|
$dateArrivee = htmlspecialchars(pg_escape_string($_POST['dateArrivee']));
|
||
|
$voiture = htmlspecialchars(pg_escape_string($_POST['voiture']));
|
||
|
$villeDepart = htmlspecialchars(pg_escape_string($_POST['villeDepart']));
|
||
|
$arrEtapes = array();
|
||
|
$i=1;
|
||
|
//Ajouter les étapes à un tableau
|
||
|
array_push($arrEtapes, htmlspecialchars(pg_escape_string($_POST['villeDepart'])));
|
||
|
while (isset($_POST['etape'.$i])){
|
||
|
array_push($arrEtapes, htmlspecialchars(pg_escape_string($_POST['etape'.$i])));
|
||
|
$i++;
|
||
|
}
|
||
|
//Vérifie le nombre d'étapes entré par l'utilisateur
|
||
|
if (count($arrEtapes) == 0 || intval($nbEtapes)<1 || intval($nbEtapes) != count($arrEtapes)){
|
||
|
header('Location: depotTrajet.php?error=1');
|
||
|
exit();
|
||
|
}
|
||
|
//Vérifie que les dates entrées par l'utilisateur ne se chevauchent pas et sont correctes
|
||
|
if (!checkDates($db, $mail, $dateDepart, $dateArrivee)){
|
||
|
header('Location: depotTrajet.php?error=2');
|
||
|
exit();
|
||
|
}
|
||
|
//Vérifie la voiture de l'utilisateur est correcte
|
||
|
if (!checkVoiture($db, $mail, $voiture)){
|
||
|
header('Location: depotTrajet.php?error=3');
|
||
|
exit();
|
||
|
}
|
||
|
//Creer le trajet en bd
|
||
|
$result = creerTrajet($db, $mail, $dateDepart, $dateArrivee, $voiture);
|
||
|
if ($result){
|
||
|
$codeTrajet = pg_fetch_array($result)[0];
|
||
|
//Creer les etapes en bd
|
||
|
$result = creerEtapes($db, $codeTrajet, $arrEtapes);
|
||
|
}
|
||
|
if (!$result){
|
||
|
header('Location: depotTrajet.php?error=4');
|
||
|
exit();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
?>
|
||
|
<!DOCTYPE html>
|
||
|
<html lang="fr">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<link rel="stylesheet" href="../ressources/libs/jquery-ui.min.css">
|
||
|
<link rel="stylesheet" href="../ressources/navbarhtml.css">
|
||
|
<link rel="stylesheet" href="depotTrajet.css">
|
||
|
<title>Déposer un trajet</title>
|
||
|
</head>
|
||
|
<body>
|
||
|
<script type="application/javascript" src="../ressources/libs/jquery-3.4.1.js"></script>
|
||
|
<script type="application/javascript" src="../ressources/libs/jquery-ui.min.js"></script>
|
||
|
<script type="application/javascript" src="../ressources/libs/chosen.jquery.min.js"></script>
|
||
|
<?php require_once ("../ressources/navbarhtml.php"); ?>
|
||
|
<div id="formulaire">
|
||
|
<h1>Déposer un trajet</h1>
|
||
|
<form method="post" enctype="multipart/form-data" action="depotTrajet.php">
|
||
|
<div class="line">
|
||
|
<label class="label" for="dateDepart">Date départ : </label>
|
||
|
<input type="datetime-local" class="form" name="dateDepart" id="dateDepart" required>
|
||
|
</div>
|
||
|
<div class="line">
|
||
|
<label class="label" for="dateArrivee">Date arrivée : </label>
|
||
|
<input type="datetime-local" class="form" name="dateArrivee" id="dateArrivee" required>
|
||
|
</div>
|
||
|
<div class="line">
|
||
|
<label class="label" for="voiture">Voiture : </label>
|
||
|
<select class="form" name="voiture" id="voiture" required>
|
||
|
<option selected></option>
|
||
|
<?php
|
||
|
afficherVoitures($db, $mail);
|
||
|
?>
|
||
|
</select>
|
||
|
</div>
|
||
|
<div class="line">
|
||
|
<label class="label" for="villeDepart">Ville de départ : </label>
|
||
|
<input type="text" class="form, villeText" name="villeDepartText" id="villeDepartText">
|
||
|
<select class="form, villeSelect" name="villeDepart" id="villeDepart" required>
|
||
|
<option selected></option>
|
||
|
<?php
|
||
|
afficherVilles($db);
|
||
|
?>
|
||
|
</select>
|
||
|
</div>
|
||
|
<div id="villeEtapeDiv" class="line">
|
||
|
<label class="label" for="villeEtape">Etape : </label>
|
||
|
<input type="text" class="form, villeText" id="villeEtapeText" name="villeEtapeText">
|
||
|
<select class="form, villeSelect" name="villeEtape" id="villeEtape" required>
|
||
|
<option selected></option>
|
||
|
<?php
|
||
|
afficherVilles($db);
|
||
|
?>
|
||
|
</select>
|
||
|
</div>
|
||
|
<div id="boutonEtape" class="line">
|
||
|
<input class="button" id="ajoutEtape" type="button" value="Ajouter une étape">
|
||
|
<input id="supprimerEtape" class='button' type='button' value='Supprimer une étape'>
|
||
|
<input id="nbEtapes" name="nbEtapes" type="hidden" value="1" required>
|
||
|
</div>
|
||
|
<?php
|
||
|
printError();
|
||
|
?>
|
||
|
<div class="line">
|
||
|
<input id="submit" class="button" type="submit" value="Poster le trajet">
|
||
|
</div>
|
||
|
</form>
|
||
|
<script src="depotTrajet.js"></script>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|