Merge branch 'depotTrajet'
This commit is contained in:
commit
af17c6dad9
96
WEB/deposerTrajet/depotTrajet.css
Normal file
96
WEB/deposerTrajet/depotTrajet.css
Normal file
@ -0,0 +1,96 @@
|
||||
*{
|
||||
font-family: "Arial";
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
body{
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
h1{
|
||||
font-size: 2em;
|
||||
text-align: center;
|
||||
margin-bottom: 3em;
|
||||
}
|
||||
|
||||
.villeSelect, .villeText{
|
||||
box-sizing: border-box;
|
||||
margin-bottom: 0.7em;
|
||||
}
|
||||
|
||||
.villeText{
|
||||
width: 20%;
|
||||
}
|
||||
|
||||
.villeSelect{
|
||||
margin-bottom: 0.7em;
|
||||
margin-left: 2%;
|
||||
width: 33%;
|
||||
}
|
||||
|
||||
#supprimerEtape{
|
||||
display: none;
|
||||
}
|
||||
|
||||
#boutonEtape{
|
||||
margin-top: 1.5em;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
#submit{
|
||||
margin-top: 1em;
|
||||
margin-left: 50%;
|
||||
transform: translate(-50%);
|
||||
}
|
||||
|
||||
#formulaire{
|
||||
background-color: white;
|
||||
border-radius: 10px;
|
||||
padding: 4em;
|
||||
width: 40%;
|
||||
}
|
||||
|
||||
.form{
|
||||
box-sizing: border-box;
|
||||
width: 55%;
|
||||
margin-bottom: 0.7em;
|
||||
}
|
||||
|
||||
.button{
|
||||
cursor: pointer;
|
||||
font-weight: bold;
|
||||
padding: 8px;
|
||||
color: white;
|
||||
background-color: rgb(65, 154, 28);
|
||||
border-radius: 5em;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.line{
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
flex-direction: row;
|
||||
justify-content: left;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.error{
|
||||
margin-top: 1em;
|
||||
color: red;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.label{
|
||||
box-sizing: border-box;
|
||||
font-size: 1.1em;
|
||||
width: 45%;
|
||||
min-width: 8em;
|
||||
}
|
55
WEB/deposerTrajet/depotTrajet.js
Normal file
55
WEB/deposerTrajet/depotTrajet.js
Normal file
@ -0,0 +1,55 @@
|
||||
$(document).ready(function () {
|
||||
//copy options
|
||||
let options = $('#villeDepart option').clone();
|
||||
//react on keyup in textbox
|
||||
$('#villeDepartText').keyup(function () {
|
||||
let val = $(this).val().toString().toLowerCase();
|
||||
$('#villeDepart').empty();
|
||||
//take only the options containing your filter text or all if empty
|
||||
options.filter(function (idx, el) {
|
||||
return val === '' || $(el).text().toLowerCase().indexOf(val) >= 0;
|
||||
}).appendTo('#villeDepart');//add it to list
|
||||
});
|
||||
|
||||
//copy options
|
||||
let optionsEtape = $('#villeEtape option').clone();
|
||||
//react on keyup in textbox
|
||||
$('#villeEtapeText').keyup(function () {
|
||||
let val = $(this).val().toString().toLowerCase();
|
||||
$('#villeEtape').empty();
|
||||
//take only the options containing your filter text or all if empty
|
||||
optionsEtape.filter(function (idx, el) {
|
||||
return val === '' || $(el).text().toLowerCase().indexOf(val) >= 0;
|
||||
}).appendTo('#villeEtape');//add it to list
|
||||
});
|
||||
|
||||
$("#ajoutEtape").click(function () {
|
||||
let depart = $("#villeDepart");
|
||||
let etape = $("#villeEtape");
|
||||
let nbEtape = $("#nbEtapes");
|
||||
if(etape.val() != null && etape.val() !== "" && depart.val() != null && depart.val() !== ""){
|
||||
let option = $("#villeEtape option:selected");
|
||||
let numero = (parseInt(nbEtape.val()));
|
||||
$(this).parent().before("<div class='line etape'>" +
|
||||
"<lablel class='label' for='etape" + numero + "'>Etape " + numero + " :</lablel>" +
|
||||
"<input type='text' class='form' value='" + option.text() + "' readonly>" +
|
||||
"<input type='hidden' name='etape" + numero + "' value='" + option.val() + "' readonly></div>");
|
||||
nbEtape.attr('value', parseInt(nbEtape.val())+1);
|
||||
//$("#supprimerEtape").css("display", "initial");
|
||||
$("#supprimerEtape").show();
|
||||
}
|
||||
});
|
||||
|
||||
$("#supprimerEtape").click(function () {
|
||||
let etape = $(".etape:last");
|
||||
let nbEtape = $("#nbEtapes");
|
||||
if (parseInt(nbEtape.val())>0){
|
||||
etape.remove();
|
||||
nbEtape.attr('value', parseInt(nbEtape.val())-1);
|
||||
if (parseInt(nbEtape.val())<=1){
|
||||
//$("#supprimerEtape").css("display", "none");
|
||||
$("#supprimerEtape").hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
180
WEB/deposerTrajet/depotTrajet.php
Normal file
180
WEB/deposerTrajet/depotTrajet.php
Normal file
@ -0,0 +1,180 @@
|
||||
<?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>
|
10598
WEB/ressources/libs/jquery-3.4.1.js
vendored
Normal file
10598
WEB/ressources/libs/jquery-3.4.1.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
7
WEB/ressources/libs/jquery-ui.min.css
vendored
Normal file
7
WEB/ressources/libs/jquery-ui.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
13
WEB/ressources/libs/jquery-ui.min.js
vendored
Normal file
13
WEB/ressources/libs/jquery-ui.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
39
WEB/ressources/trajet.php
Normal file
39
WEB/ressources/trajet.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
//Récupérer la liste complete des villes
|
||||
function getListeVilles($db) {
|
||||
$result = pg_query($db, "SELECT * FROM Ville;");
|
||||
return $result;
|
||||
}
|
||||
|
||||
//Créer un trajet en bd
|
||||
function creerTrajet($db, $mail, $dateDepart, $datArrivee, $matricule){
|
||||
$date = date('Y-m-d H:i:s');
|
||||
$result = pg_query_params($db, "INSERT INTO Trajet (datedepart, datearrivee, dateproposition, estannule, mailproposition, matricule) VALUES ($1, $2, $3, false, $4, $5) RETURNING codeTrajet;", array($dateDepart,$datArrivee, $date, $mail, $matricule));
|
||||
return $result;
|
||||
}
|
||||
|
||||
//Creer les étapes d'un trajet
|
||||
function creerEtapes($db, $codeTrajet, $etapes){
|
||||
$result = true;
|
||||
for ($i=0; $i<count($etapes) && $result; $i++){
|
||||
$arr = explode("%%", $etapes[$i]);
|
||||
$result = pg_query_params($db, "INSERT INTO traverser (codetrajet, nomville, codepostal, numeroetape) VALUES ($1, $2, $3, $4);", array($codeTrajet, $arr[0], $arr[1], $i+1));
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
//Vérifier la cohérence des dates
|
||||
function checkDates($db, $mail, $dateDepart, $dateArrivee) {
|
||||
$valide = $dateDepart < $dateArrivee && $dateDepart > date('Y-m-d H:i:s');
|
||||
$result = pg_query_params($db, "SELECT COUNT(*) From Trajet WHERE mailproposition = $1 AND $2 BETWEEN datedepart AND datearrivee;", array($mail, $dateDepart));
|
||||
$row = pg_fetch_array($result);
|
||||
return $row[0] == 0 && $valide;
|
||||
}
|
||||
|
||||
//Vérifier que l'utilisateur est bien associé à cette voiture
|
||||
function checkVoiture($db, $mail, $matricule){
|
||||
$result = pg_query_params($db, "SELECT matricule From Voiture WHERE mail = $1 AND matricule = $2;", array($mail, $matricule));
|
||||
$row = pg_fetch_array($result);
|
||||
return !strcmp($matricule, $row[0]);
|
||||
}
|
11
WEB/ressources/ville.php
Normal file
11
WEB/ressources/ville.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
require_once ('../connexionBD.php');
|
||||
|
||||
//Envoyer en json les villes correspondantes au champ de saisie pour les villes
|
||||
if (isset($_GET['search'])){
|
||||
$ville = strtolower(htmlentities(pg_escape_string ($_GET['search'])));
|
||||
$result = pg_query_params($db, "SELECT codepostal, nomville FROM ville WHERE lower(nomVille) like lower($1);", array("%$ville%"));
|
||||
$return_arr = pg_fetch_all($result);
|
||||
echo json_encode($return_arr);
|
||||
}
|
Loading…
Reference in New Issue
Block a user