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.
117 lines
5.0 KiB
PHP
117 lines
5.0 KiB
PHP
<?php
|
|
session_start();
|
|
require_once('../connexionBD.php');
|
|
require_once('../ressources/trajet.php');
|
|
require_once ('../ressources/verifconnecte.php');
|
|
|
|
//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
|
|
if (isset($_GET['error'])){
|
|
getErrorDepotTrajet($_GET['error']);
|
|
}
|
|
?>
|
|
<div class="line">
|
|
<input id="submit" class="button" type="submit" value="Poster le trajet">
|
|
</div>
|
|
</form>
|
|
<script src="depotTrajet.js"></script>
|
|
</div>
|
|
</body>
|
|
</html>
|