//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));
$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.";