//Verifier qu'un avis n'a pas déja été envoyer avec le compte $mail pour le trajet $codetrajet
//Declaration des fonctions
function checkAvis($db, $mail, $codetrajet)
function checkAvis($db, $mail, $codetrajet)
{
{
$result = pg_query_params($db, "SELECT COUNT(*) FROM avis WHERE mailEmetteur = $1 AND codetrajet = $2;", array($mail, $codetrajet));
$result = pg_query_params($db, "SELECT COUNT(*) FROM avis WHERE mailEmetteur = $1 AND codetrajet = $2;", array($mail, $codetrajet));
@ -8,7 +9,6 @@ function checkAvis($db, $mail, $codetrajet)
return $row[0] == 0;
return $row[0] == 0;
}
}
//Verifier que le trajet à bien été fait par l'utilisateur $mail
function checkCodeTrajetAvis($db, $mail, $codetrajet)
function checkCodeTrajetAvis($db, $mail, $codetrajet)
{
{
$result = pg_query_params($db, "SELECT COUNT(*) FROM trajet tr, reserver re WHERE tr.codetrajet = $1 AND tr.codetrajet = re.codetrajet AND re.mailutilisateur = $2;", array($codetrajet, $mail));
$result = pg_query_params($db, "SELECT COUNT(*) FROM trajet tr, reserver re WHERE tr.codetrajet = $1 AND tr.codetrajet = re.codetrajet AND re.mailutilisateur = $2;", array($codetrajet, $mail));
@ -16,11 +16,14 @@ function checkCodeTrajetAvis($db, $mail, $codetrajet)
return $row[0] >= 1;
return $row[0] >= 1;
}
}
//Importation des fichiers necessaires
session_start();
session_start();
require_once("../connexionBD.php");
require_once("../connexionBD.php");
require_once("../ressources/user.php");
require_once("../ressources/user.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'])) {
header('Location: ../index.php');
header('Location: ../index.php');
exit();
exit();
@ -28,19 +31,19 @@ if (!isset($_SESSION['mail'])) {
$mail = $_SESSION['mail'];
$mail = $_SESSION['mail'];
if (isset($_POST['codetrajet']) && isset($_POST['avislaisse']) && isset($_POST['note'])) {
if (isset($_POST['codetrajet']) && isset($_POST['avislaisse']) && isset($_POST['note'])) {
//Recuperation des variables passer par le formulaire
$avis = $_POST['avislaisse'];
$avis = $_POST['avislaisse'];
$note = $_POST['note'];
$note = $_POST['note'];
$codetrajet = intval($_POST['codetrajet']);
$codetrajet = intval($_POST['codetrajet']);
$date = date('Y-m-d H:i:s');
$date = date('Y-m-d H:i:s');
//Verifier que l'utilisateur a bien participé au trajet et qu'il n'en a pas déjà poster un
if (checkAvis($db, $mail, $codetrajet) && checkCodeTrajetAvis($db, $mail, $codetrajet)) {
if (checkAvis($db, $mail, $codetrajet) && checkCodeTrajetAvis($db, $mail, $codetrajet)) {
$result = pg_query_params($db, "SELECT DISTINCT ut.login as login, tr.* FROM utilisateur ut, trajet tr, reserver re WHERE ut.mail = re.mailutilisateur AND re.codetrajet = tr.codetrajet AND re.mailutilisateur = $1 AND tr.estannule = false ORDER BY datedepart DESC;", array($mail));
$result = pg_query_params($db, "SELECT DISTINCT ut.login as login, tr.* FROM utilisateur ut, trajet tr, reserver re WHERE ut.mail = re.mailutilisateur AND re.codetrajet = tr.codetrajet AND re.mailutilisateur = $1 AND tr.estannule = false;", array($mail));
if (isset($_POST['lieu_depart']) && isset($_POST['lieu_arrivee']) && isset($_POST['date_heure'])) {
$source = $source[0];
$source = $_POST['lieu_depart']; //Recuperation des valeurs passé par le form
$dest = explode('%%', $_POST['villeArrive']);
$dest = $_POST['lieu_arrivee'];
$cpdest = $dest[1];
$date_depart = $_POST['date_heure'];
$dest = $dest[0];
if ($date_depart <date('Y-m-d')){//Verificationdedate
$date_depart = $_POST['date_heure'];
echo "Erreur date</br>";
if ($date_depart <date('Y-m-d')){
echo "<ahref='../tableauBord/tableauBord.php'>Retour vers le tableau de bord</a>";
echo "Erreur date</br>";
exit();
echo "<ahref='../tableauBord/tableauBord.php'>Retour vers le tableau de bord</a>";
}
exit();
}
}
$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) AND codepostal = $4))
//Requete de selection des trajets a affiché
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 LOWER(v.nomville) = LOWER($2) AND v.codepostal = $5 AND tr.codepostal = v.codepostal AND tr.numeroetape != 1);", array($source, $dest, $date_depart, $cpsource, $cpdest));
$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>
<!DOCTYPE html>
@ -44,25 +50,25 @@ INTERSECT (SELECT DISTINCT ut.login, ta.codetrajet, ta.datedepart FROM ville v,
$result = pg_query_params($db, "SELECT COUNT(*) From Trajet WHERE mailproposition = $1 AND estannule = false 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;
}
}
//Récupérer les étapes d'un trajet
function getEtapesTrajet($db, $codetrajet){
$result = pg_query_params($db, "SELECT * FROM Traverser WHERE codetrajet = $1 ;", array($codetrajet));
return $result;
}
//Vérifier le nombre de places restantes
//Vérifier le nombre de places restantes
function checkPlacesVoiture($db, $codetrajet)
function checkPlacesVoiture($db, $codetrajet)
{
{
@ -86,10 +80,9 @@ function checkVoiture($db, $mail, $matricule)
return !strcmp($matricule, $row[0]);
return !strcmp($matricule, $row[0]);
}
}
//Recuperer le nombre de trajets restant proposés par l'utilisateur $mail
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 >= $2;", array($mail, date('Y-m-d H:i:s')));
$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);
return $row[0];
return $row[0];
@ -97,10 +90,9 @@ function getTrajetsProposes($db, $mail)
return 0;
return 0;
}
}
//Recuperer le nombre de trajets restant reservés par l'utilisateur $mail
function getTrajetsReserves($db, $mail)
function getTrajetsReserves($db, $mail)
{
{
$result = pg_query_params($db, "SELECT COUNT(*) FROM trajet tr, reserver re WHERE re.codetrajet = tr.codetrajet AND mailutilisateur = $1 AND tr.estannule = false AND re.estannule = false AND tr.datedepart >= $2;", array($mail, date('Y-m-d H:i:s')));
$result = pg_query_params($db, "SELECT COUNT(*) FROM trajet tr, reserver re WHERE re.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];
@ -158,35 +150,31 @@ function afficherVilles($db)
}
}
}
}
//Récuperer la ville de départ du trajet $codetrajet
function getDepart($db, $codetajet)
function getDepart($db, $codetajet)
{
{
$result = pg_query_params($db, "SELECT * 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) {
$return = pg_fetch_array($result);
$return = pg_fetch_array($result)[0];
}
}
return $return;
return $return;
}
}
//Récuperer la ville d'arrivée du trajet $codetrajet
function getFin($db, $codetajet)
function getFin($db, $codetajet)
{
{
$result = pg_query_params($db, "SELECT * 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) {
$return = pg_fetch_array($result);
$return = pg_fetch_array($result)[0];
}
}
return $return;
return $return;
}
}
//Annuler le trajet $codetrajet
function annulerTrajet($db, $codetrajet){
function annulerTrajet($db, $codetrajet){
$result = pg_query_params($db, "UPDATE Trajet SET estannule = true WHERE codetrajet = $1;", array($codetrajet));
$result = pg_query_params($db, "UPDATE Trajet SET estannule = true WHERE codetrajet = $1;", array($codetrajet));
return $result;
return $result;
}
}
//Annuler la reservation pour le tajet $codetrajet de l'utilisateur $mail
function annulerReservation($db, $mail,$codetrajet){
function annulerReservation($db, $mail,$codetrajet){
$result = pg_query_params($db, "DELETE FROM reserver WHERE codetrajet = $1 AND mailutilisateur = $2;", array($codetrajet, $mail));
$result = pg_query_params($db, "DELETE FROM reserver WHERE codetrajet = $1 AND mailutilisateur = $2;", array($codetrajet, $mail));
return $result;
return $result;
@ -206,13 +194,4 @@ function getErrorDepotTrajet($code)
}
}
}
}
//Verifie l'existance d'un avis pour le trajet $codetrajet émit par l'utilisateur $mail
function avisExiste($db, $mail, $codetrajet){
$result = pg_query_params($db, "SELECT COUNT(*) FROM Avis WHERE mailemetteur = $1 AND codetrajet = $2;", array($mail, $codetrajet));