Ajout recherche

avisTrajet
remi.biette 6 years ago
parent 4eafe9558d
commit 5d6c29070f

@ -1,27 +0,0 @@
.centrage{
text-align : center;
font-size: 20px;
}
.global {
position: absolute; /* postulat de départ */
top: 45%; left: 50%; /* à 50%/50% du parent référent */
transform: translate(-50%, -50%); /* décalage de 50% de sa propre taille */
text-align : center;
}
.fort {
font-weight: bold;
text-align : center;
text-decoration: underline;
font-size : 30px;
}
.bord{
border-radius: 20px;
border-left: 2px solid black;
border-right: 2px solid black;
border-top: 2px solid black;
border-bottom: 2px solid black;
padding : 20px 80px 60px 80px;
}

@ -1,18 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<link rel="stylesheet" href="Recherche.css"/>
</head>
<body>
<div class="global bord">
<p class="fort">Rechercher un trajet</p>
<form method="post" action="Liste.php">
<p><input name="lieu_depart" type="text" placeholder="Lieu de départ" class="centrage"></p>
<p><input name="lieu_arrivée" type="text" placeholder="Lieu d'arrivée" class="centrage"></p>
<p><input name="date_heure" type="text" placeholder="Date et heure de départ" class="centrage"></p>
<p><input name="submit" type="submit" value="Rechercher" class="centrage"></p>
</form>
</div>
</body>
</html>

@ -32,7 +32,7 @@ $result = pg_query_params($db, $requete, array($mail));
<div id = "container"> <div id = "container">
<div id ="entete"> <div id ="entete">
<a href = "https://stri.flavien.ovh/tableauBord/tableauBord.php"><img id = "bouton_retour" src = "../ressources/image/return.png" alt = "Bouton retour"></a> <a href = "../tableauBord/tableauBord.php"><img id = "bouton_retour" src = "../ressources/image/return.png" alt = "Bouton retour"></a>
<h1 id = "titre">Avis Laissés</h1> <h1 id = "titre">Avis Laissés</h1>
<br> <br>
</div> </div>

@ -52,7 +52,6 @@ h1{
} }
#formulaire{ #formulaire{
margin-top: ;
background-color: white; background-color: white;
border-radius: 10px; border-radius: 10px;
padding: 4em; padding: 4em;

@ -7,7 +7,7 @@ Page PHP : liste.php
body { body {
color:black; color:black;
background-color:white; background-color:white;
background-image:url(../resources/background.jpg); background-image:url("../ressources/image/background.jpg");
background-repeat:no-repeat; background-repeat:no-repeat;
background-size:104%; background-size:104%;
margin: 0; margin: 0;
@ -39,13 +39,14 @@ h2{
.separation{ .separation{
margin-top : 5%; margin-top : 5%;
margin-left : 20%; margin-left : 20%;
height: 200px; min-height: 2em;
width : 5px; width : 5px;
background: black; background: black;
} }
#ligne{ td{
padding-left:10%; padding-left: 1.5em;
padding-right: 1.5em;
width: 33%; width: 33%;
} }

@ -1,6 +1,7 @@
<?php <?php
session_start(); session_start();
require_once("../connexionBD.php"); require_once("../connexionBD.php");
require_once("../ressources/trajet.php");
//Si on est pas connecté redirection vers la page de connexion //Si on est pas connecté redirection vers la page de connexion
if (!isset($_SESSION['mail'])) { if (!isset($_SESSION['mail'])) {
@ -9,63 +10,54 @@ if (!isset($_SESSION['mail'])) {
} }
$mail = $_SESSION['mail']; $mail = $_SESSION['mail'];
/* if (isset($_POST['lieu_depart']) && isset($_POST['lieu_arrivee']) && isset($_POST['date_heure'])) {
Crée par PALAFFRE Raphael
Fonction: Lister les trajets recherché
Page CSS : liste.css
Donnée en entrée : lieu_depart, lieu_arrivee et date_heure <- recherche.php
Donnée en sortie : $login et $codeTrajet -> contact.php
*/
$source = $_POST['lieu_depart']; $source = $_POST['lieu_depart'];
$dest = $_POST['lieu_arrivee']; $dest = $_POST['lieu_arrivee'];
$date_depart = $_POST['date_heure']; $date_depart = $_POST['date_heure'];
}
$requete="SELECT codeTrajet, dateDepart, dateArrivee, mailProposition FROM Trajet WHERE Trajet.dateDepart=$date_depart AND (SELECT codeTrajet FROM Traverser WHERE nomVille=$source AND nomVille=$dest)=Trajet.codeTrajet;"; $result = pg_query_params($db, "(SELECT DISTINCT ut.login, ta.codetrajet, ta.datedepart FROM ville v, traverser tr, utilisateur ut, trajet ta WHERE DATE(ta.datedepart) = DATE($3) AND ta.estannule = false AND ta.codetrajet = tr.codetrajet AND ta.mailproposition = ut.mail AND tr.nomVille = v.nomVille AND tr.codepostal = v.codepostal AND tr.numeroetape = (SELECT MIN(numeroetape) FROM traverser WHERE LOWER(nomVille) = LOWER($1)))
INTERSECT (SELECT DISTINCT ut.login, ta.codetrajet, ta.datedepart FROM ville v, traverser tr, utilisateur ut, trajet ta WHERE DATE(ta.datedepart) = DATE($3) AND ta.estannule = false AND ta.codetrajet = tr.codetrajet AND ta.mailproposition = ut.mail AND tr.nomVille = v.nomVille AND tr.codepostal = v.codepostal AND tr.numeroetape = (SELECT MAX(numeroetape) FROM traverser WHERE LOWER(nomVille) = LOWER($2)));", array($source, $dest, $date_depart));
$envoi = pg_query($db,$requete);
if ($envoi == FALSE){
echo 'Erreur !';
}
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="fr"> <html lang="fr">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<link rel="stylesheet" href="liste_trajet.css"> <link rel="stylesheet" href="liste_trajet.css">
<link rel="stylesheet" href="../ressources/navbarhtml.css">
<link rel="icon" href="../ressources/favicon.ico"/> <link rel="icon" href="../ressources/favicon.ico"/>
<title>Liste des trajets</title> <title>Liste des trajets</title>
</head> </head>
<body> <body>
<?php
require_once("../ressources/navbarhtml.php");
?>
<div id="container"> <div id="container">
<div id="entete"> <div id="entete">
<a href = "../tableauBord/tableauBord.php"><img id = "bouton_retour" src = "../resources/return.png" alt = "Bouton retour"></a> <a href="../tableauBord/tableauBord.php"><img id="bouton_retour" src="../ressources/image/return.png"
alt="Bouton retour"></a>
<h1 class="float" id="titre">Liste des trajets</h1> <h1 class="float" id="titre">Liste des trajets</h1>
<br> <br>
<h2>Trajets recherchés : <?php echo $source." --> ".$dest; ?></h2> <h2>Trajets recherchés : <?php echo $source . " vers " . $dest; ?></h2>
</div> </div>
<div id="liste"> <div id="liste">
<table> <table>
<tr>
<td id="ligne">
<hr class="separation" />
</td>
<td id="info">
<?php echo "$date_depart - $source --> $dest : $login";
//sourcedest recupéré avec le code du trajet, afficher plusieurs avec un while
?>
</td>
<td id="reserver">
<form action="contact.php" method="POST">
<?php <?php
echo "<input type='hidden' name='login' value='$login'/>"; while ($row = pg_fetch_array($result)) {
echo "<input type='hidden' name='codeTrajet' value='$codeTrajet'/>"; $codetrajet = $row['codetrajet'];
$login = $row['login'];
$source = getDepart($db, $codetrajet);
$dest = getFin($db, $codetrajet);
$date_depart = $row['datedepart'];
if (checkPlacesVoiture($db, $codetrajet)){
echo "<tr><td class='ligne'><hr class='separation'/></td><td class='info'>";
echo "<p>$date_depart - $source vers $dest proposé par : $login</p></td>";
echo "<td><a href='reserver.php?codetrajet=$codetrajet'>Réserver</a></td>";
echo "</tr>";
}
}
?> ?>
<input type="submit" value="Reserver">
</form>
</td>
</tr>
</table> </table>
</div> </div>
</div> </div>

@ -0,0 +1,29 @@
<?php
function verifierTrajet($db, $mail, $codetrajet){
$trajet = getTrajet($db, $codetrajet);
if (!$trajet){
return false;
}
return checkDatesReserve($db, $mail, $trajet['datedepart']) && checkPlacesVoiture($db, $codetrajet) && strcmp($trajet['mailproposition'], $mail) != 0;
}
require_once("../connexionBD.php");
require_once("../ressources/trajet.php");
if (!isset($_SESSION['mail'])) {
header('Location: ../index.php');
exit();
}
$mail = $_SESSION['mail'];
if (isset($_GET['codetrajet'])){
$codetrajet = $_GET['codetrajet'];
if (verifierTrajet($db, $mail, $codetrajet)){
reserver($db, $mail, $codetrajet);
}
}
?>

@ -0,0 +1,40 @@
.centrage {
text-align: center;
font-size: 20px;
}
.global {
text-align: center;
}
br {
line-height: 50px;
}
body {
color: black;
background-color: white;
background-image: url("../ressources/image/background.jpg");
background-repeat: no-repeat;
background-size: 104%;
margin: 0;
}
#container {
margin: 5% 15% 2% 15%;
background-color: white;
border: 2px solid black;
}
h1 {
text-align: center;
font-size: 250%;
}
#form {
text-align: center;
}

@ -0,0 +1,54 @@
<?php
session_start();
require_once('../ressources/verifconnecte.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<link rel="stylesheet" href="recherche.css"/>
<link rel="stylesheet" href="../ressources/navbarhtml.css"/>
<title>Rechercher trajet</title>
</head>
<body>
<?php
require_once("../ressources/navbarhtml.php");
?>
<div id="container">
<div id="entete">
<h1>Rechercher trajet</h1><br/>
</div>
<div class="global bord">
<form method="post" action="../liste_trajets/liste_trajet.php">
<label>
<input name="lieu_depart" type="text" placeholder="Lieu de départ" class="centrage" required>
<br/>
<br/>
</label>
<label>
<input name="lieu_arrivee" type="text" placeholder="Lieu d'arrivée" class="centrage" required>
<br/>
<br/>
</label>
<label>
<input name="date_heure" type="date" placeholder="Date et heure de départ" class="centrage"
required>
<br/>
</label>
<br/>
<label>
<input id="submit" name="submit" type="submit" value="Rechercher" class="centrage">
</label>
</form>
</div>
</div>
</div>
</body>
</html>

@ -1,19 +1,31 @@
<?php <?php
//Récupérer la liste complete des villes //Récupérer la liste complete des villes
function getListeVilles($db) { function getListeVilles($db)
{
$result = pg_query($db, "SELECT * FROM Ville;"); $result = pg_query($db, "SELECT * FROM Ville;");
return $result; return $result;
} }
function reserver($db, $mail, $codetrajet){
return pg_query_params($db, "INSERT INTO Reserver VALUES ($1, $2, $3);", array($mail, $codetrajet, date('Y-m-d H:i:s')));
}
function getTrajet($db, $codetrajet)
{
return pg_query_params($db, "SELECT * FROM Trajet WHERE codetrajet = $1;", array($codetrajet));
}
//Créer un trajet en bd //Créer un trajet en bd
function creerTrajet($db, $mail, $dateDepart, $datArrivee, $matricule){ function creerTrajet($db, $mail, $dateDepart, $datArrivee, $matricule)
{
$date = date('Y-m-d H:i:s'); $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)); $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; return $result;
} }
//Creer les étapes d'un trajet //Creer les étapes d'un trajet
function creerEtapes($db, $codeTrajet, $etapes){ function creerEtapes($db, $codeTrajet, $etapes)
{
$result = true; $result = true;
for ($i = 0; $i < count($etapes) && $result; $i++) { for ($i = 0; $i < count($etapes) && $result; $i++) {
$arr = explode("%%", $etapes[$i]); $arr = explode("%%", $etapes[$i]);
@ -23,21 +35,45 @@ function creerEtapes($db, $codeTrajet, $etapes){
} }
//Vérifier la cohérence des dates //Vérifier la cohérence des dates
function checkDates($db, $mail, $dateDepart, $dateArrivee) { function checkDates($db, $mail, $dateDepart, $dateArrivee)
{
$valide = $dateDepart < $dateArrivee && $dateDepart > date('Y-m-d H:i:s'); $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)); $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); $row = pg_fetch_array($result);
return $row[0] == 0 && $valide; return $row[0] == 0 && $valide;
} }
//Vérifier le nombre de places restantes
function checkPlacesVoiture($db, $codetrajet)
{
$result = pg_query_params($db, "SELECT nbplaces FROM Voiture vo, Trajet ta WHERE vo.mail = ta.mailproposition AND ta.codeTrajet = $1 LIMIT 1;", array($codetrajet));
$result2 = pg_query_params($db, "SELECT COUNT(*) FROM Reserver re, Trajet ta WHERE re.codetrajet.mail = ta.codetrajet AND ta.codetrajet = $1;", array($codetrajet));
if(!$result || !$result2){
return false;
}
$nbplaces = pg_fetch_array($result);
$nbreservations = pg_fetch_array($result);
return $nbplaces-1>$nbreservations;
}
//Vérifier la cohérence des dates
function checkDatesReserve($db, $mail, $dateDepart)
{
$result = pg_query_params($db, "SELECT COUNT(*) From Trajet ta, reserve re WHERE re.mailutilisateur = $1 AND re.codetrajet = ta.codetrajet AND $2 BETWEEN datedepart AND datearrivee;", array($mail, $dateDepart));
$row = pg_fetch_array($result);
return $row[0] == 0;
}
//Vérifier que l'utilisateur est bien associé à cette voiture //Vérifier que l'utilisateur est bien associé à cette voiture
function checkVoiture($db, $mail, $matricule){ function checkVoiture($db, $mail, $matricule)
{
$result = pg_query_params($db, "SELECT matricule From Voiture WHERE mail = $1 AND matricule = $2;", array($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); $row = pg_fetch_array($result);
return !strcmp($matricule, $row[0]); return !strcmp($matricule, $row[0]);
} }
function getTrajetsProposes($db, $mail){ function getTrajetsProposes($db, $mail)
{
$result = pg_query_params($db, "SELECT COUNT(*) from Trajet WHERE mailProposition = $1 AND estAnnule = false AND datedepart >= current_date;", array($mail)); $result = pg_query_params($db, "SELECT COUNT(*) from Trajet WHERE mailProposition = $1 AND estAnnule = false AND datedepart >= current_date;", array($mail));
if ($result) { if ($result) {
$row = pg_fetch_array($result); $row = pg_fetch_array($result);
@ -46,8 +82,9 @@ function getTrajetsProposes($db, $mail){
return 0; return 0;
} }
function getTrajetsReserves($db, $mail){ function getTrajetsReserves($db, $mail)
$result = pg_query_params($db, "SELECT COUNT(*) FROM trajet tr, reserver r WHERE r.codetrajet = tr.codetrajet AND mailutilisateur = $1 AND etatres != 'Annulée' AND estAnnule = false AND datedepart >= current_date;", array($mail)); {
$result = pg_query_params($db, "SELECT COUNT(*) FROM trajet tr, reserver r WHERE r.codetrajet = tr.codetrajet AND mailutilisateur = $1 AND estAnnule = false AND datedepart >= current_date;", array($mail));
if ($result) { if ($result) {
$row = pg_fetch_array($result); $row = pg_fetch_array($result);
return $row[0]; return $row[0];
@ -55,7 +92,8 @@ function getTrajetsReserves($db, $mail){
return 0; return 0;
} }
function getMessagesNonLus($db, $mail){ function getMessagesNonLus($db, $mail)
{
$result = pg_query_params($db, "SELECT COUNT(*) from Message WHERE mailRecepteur = $1 AND estLu = FALSE;", array($mail)); $result = pg_query_params($db, "SELECT COUNT(*) from Message WHERE mailRecepteur = $1 AND estLu = FALSE;", array($mail));
if ($result) { if ($result) {
$row = pg_fetch_array($result); $row = pg_fetch_array($result);
@ -64,7 +102,8 @@ function getMessagesNonLus($db, $mail){
} }
} }
function getAvisNonLus($db, $mail){ function getAvisNonLus($db, $mail)
{
global $db; global $db;
$result = pg_query_params($db, "SELECT COUNT(tr.mailProposition) FROM Trajet tr, Avis av WHERE tr.codeTrajet = av.codeTrajet AND av.estLu = false AND tr.mailProposition = $1;", array($mail)); $result = pg_query_params($db, "SELECT COUNT(tr.mailProposition) FROM Trajet tr, Avis av WHERE tr.codeTrajet = av.codeTrajet AND av.estLu = false AND tr.mailProposition = $1;", array($mail));
if ($result) { if ($result) {
@ -75,13 +114,15 @@ function getAvisNonLus($db, $mail){
} }
//Récupérer la liste des voitures concernant un utilisateur //Récupérer la liste des voitures concernant un utilisateur
function getListeVoitures($db, $mail){ function getListeVoitures($db, $mail)
{
$result = pg_query_params($db, "SELECT * FROM Voiture WHERE mail = $1;", array($mail)); $result = pg_query_params($db, "SELECT * FROM Voiture WHERE mail = $1;", array($mail));
return $result; return $result;
} }
//Afficher les voitures dans un select //Afficher les voitures dans un select
function afficherVoitures($db, $mail){ function afficherVoitures($db, $mail)
{
$voitures = getListeVoitures($db, $mail); $voitures = getListeVoitures($db, $mail);
while ($row = pg_fetch_array($voitures)) { while ($row = pg_fetch_array($voitures)) {
$modele = $row['modele']; $modele = $row['modele'];
@ -91,7 +132,8 @@ function afficherVoitures($db, $mail){
} }
//Afficher les voitures dans un select //Afficher les voitures dans un select
function afficherVilles($db){ function afficherVilles($db)
{
$villes = getListeVilles($db); $villes = getListeVilles($db);
while ($row = pg_fetch_array($villes)) { while ($row = pg_fetch_array($villes)) {
$nom = $row['nomville']; $nom = $row['nomville'];
@ -100,7 +142,8 @@ function afficherVilles($db){
} }
} }
function getDepart($db, $codetajet){ function getDepart($db, $codetajet)
{
$result = pg_query_params($db, "SELECT v.nomVille FROM ville v, traverser tr WHERE tr.nomVille = v.nomVille AND tr.codepostal = v.codepostal AND tr.codetrajet = $1 AND tr.numeroetape = (SELECT MIN(numeroetape) FROM traverser WHERE codetrajet = $1);", array($codetajet)); $result = pg_query_params($db, "SELECT v.nomVille FROM ville v, traverser tr WHERE tr.nomVille = v.nomVille AND tr.codepostal = v.codepostal AND tr.codetrajet = $1 AND tr.numeroetape = (SELECT MIN(numeroetape) FROM traverser WHERE codetrajet = $1);", array($codetajet));
$return = false; $return = false;
if ($result) { if ($result) {
@ -109,7 +152,8 @@ function getDepart($db, $codetajet){
return $return; return $return;
} }
function getFin($db, $codetajet){ function getFin($db, $codetajet)
{
$result = pg_query_params($db, "SELECT v.nomVille FROM ville v, traverser tr WHERE tr.nomVille = v.nomVille AND tr.codepostal = v.codepostal AND tr.codetrajet = $1 AND tr.numeroetape = (SELECT MAX(numeroetape) FROM traverser WHERE codetrajet = $1);", array($codetajet)); $result = pg_query_params($db, "SELECT v.nomVille FROM ville v, traverser tr WHERE tr.nomVille = v.nomVille AND tr.codepostal = v.codepostal AND tr.codetrajet = $1 AND tr.numeroetape = (SELECT MAX(numeroetape) FROM traverser WHERE codetrajet = $1);", array($codetajet));
$return = false; $return = false;
if ($result) { if ($result) {
@ -118,7 +162,8 @@ function getFin($db, $codetajet){
return $return; return $return;
} }
function getErrorDepotTrajet($code){ function getErrorDepotTrajet($code)
{
switch ($code) { switch ($code) {
case 1: case 1:
return "Erreur lors de la vérification des étapes."; return "Erreur lors de la vérification des étapes.";
@ -130,4 +175,5 @@ function getErrorDepotTrajet($code){
return "Erreur lors de l'enregistrement du trajet."; return "Erreur lors de l'enregistrement du trajet.";
} }
} }
?> ?>

@ -24,7 +24,7 @@ require_once ('../ressources/verifconnecte.php');
</div> </div>
<div id="trajet"> <div id="trajet">
<a class="btnTrajet" href="../deposerTrajet/depotTrajet.php">Déposer un trajet</a> <a class="btnTrajet" href="../deposerTrajet/depotTrajet.php">Déposer un trajet</a>
<a id="btnTrajet2" class="btnTrajet" href="../ah.php">Rechercher un trajet</a> <a id="btnTrajet2" class="btnTrajet" href="../recherche/recherche.php">Rechercher un trajet</a>
</div> </div>
<div id="recap"> <div id="recap">
<div class="recapLine"> <div class="recapLine">

Loading…
Cancel
Save