Ajout recherche

This commit is contained in:
remi.biette 2019-05-23 00:25:28 +02:00
parent 4eafe9558d
commit 5d6c29070f
11 changed files with 268 additions and 152 deletions

View File

@ -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;
}

View File

@ -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>

View File

@ -32,7 +32,7 @@ $result = pg_query_params($db, $requete, array($mail));
<div id = "container">
<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>
<br>
</div>

View File

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

View File

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

View File

@ -1,6 +1,7 @@
<?php
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
if (!isset($_SESSION['mail'])) {
@ -9,65 +10,56 @@ if (!isset($_SESSION['mail'])) {
}
$mail = $_SESSION['mail'];
/*
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'];
$dest=$_POST['lieu_arrivee'];
$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;";
$envoi = pg_query($db,$requete);
if ($envoi == FALSE){
echo 'Erreur !';
if (isset($_POST['lieu_depart']) && isset($_POST['lieu_arrivee']) && isset($_POST['date_heure'])) {
$source = $_POST['lieu_depart'];
$dest = $_POST['lieu_arrivee'];
$date_depart = $_POST['date_heure'];
}
$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));
?>
<!DOCTYPE html>
<html lang = "fr">
<html lang="fr">
<head>
<meta charset = "UTF-8">
<link rel = "stylesheet" href = "liste_trajet.css">
<link rel="icon" href="../ressources/favicon.ico" />
<title>Liste des trajets</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="liste_trajet.css">
<link rel="stylesheet" href="../ressources/navbarhtml.css">
<link rel="icon" href="../ressources/favicon.ico"/>
<title>Liste des trajets</title>
</head>
<body>
<div id = "container">
<div id ="entete">
<a href = "../tableauBord/tableauBord.php"><img id = "bouton_retour" src = "../resources/return.png" alt = "Bouton retour"></a>
<h1 class = "float" id = "titre">Liste des trajets</h1>
<br>
<h2>Trajets recherchés : <?php echo $source." --> ".$dest; ?></h2>
</div>
<div id = "liste">
<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
echo "<input type='hidden' name='login' value='$login'/>";
echo "<input type='hidden' name='codeTrajet' value='$codeTrajet'/>";
?>
<input type="submit" value="Reserver">
</form>
</td>
</tr>
</table>
</div>
</div>
<?php
require_once("../ressources/navbarhtml.php");
?>
<div id="container">
<div id="entete">
<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>
<br>
<h2>Trajets recherchés : <?php echo $source . " vers " . $dest; ?></h2>
</div>
<div id="liste">
<table>
<?php
while ($row = pg_fetch_array($result)) {
$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>";
}
}
?>
</table>
</div>
</div>
</body>
</html>

View File

@ -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);
}
}
?>

View File

@ -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;
}

View File

@ -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>

View File

@ -1,43 +1,79 @@
<?php
//Récupérer la liste complete des villes
function getListeVilles($db) {
function getListeVilles($db)
{
$result = pg_query($db, "SELECT * FROM Ville;");
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
function creerTrajet($db, $mail, $dateDepart, $datArrivee, $matricule){
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));
$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){
function creerEtapes($db, $codeTrajet, $etapes)
{
$result = true;
for ($i=0; $i<count($etapes) && $result; $i++){
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));
$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) {
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 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
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));
$row = pg_fetch_array($result);
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));
if ($result) {
$row = pg_fetch_array($result);
@ -46,8 +82,9 @@ function getTrajetsProposes($db, $mail){
return 0;
}
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));
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 estAnnule = false AND datedepart >= current_date;", array($mail));
if ($result) {
$row = pg_fetch_array($result);
return $row[0];
@ -55,7 +92,8 @@ function getTrajetsReserves($db, $mail){
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));
if ($result) {
$row = pg_fetch_array($result);
@ -64,7 +102,8 @@ function getMessagesNonLus($db, $mail){
}
}
function getAvisNonLus($db, $mail){
function getAvisNonLus($db, $mail)
{
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));
if ($result) {
@ -75,59 +114,66 @@ function getAvisNonLus($db, $mail){
}
//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));
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>";
}
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 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 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));
$return = false;
if ($result){
if ($result) {
$return = pg_fetch_array($result)[0];
}
return $return;
}
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));
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));
$return = false;
if ($result){
if ($result) {
$return = pg_fetch_array($result)[0];
}
return $return;
}
function getErrorDepotTrajet($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.";
}
function getErrorDepotTrajet($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.";
}
}
?>
?>

View File

@ -24,7 +24,7 @@ require_once ('../ressources/verifconnecte.php');
</div>
<div id="trajet">
<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 id="recap">
<div class="recapLine">