//Verifier qu'un avis n'a pas déja été envoyer avec le compte $mail pour le trajet $codetrajet
function checkAvis($db, $mail, $codetrajet)
{
$result = pg_query_params($db, "SELECT COUNT(*) FROM avis WHERE mailEmetteur = $1 AND codetrajet = $2;", array($mail, $codetrajet));
@ -7,6 +8,7 @@ function checkAvis($db, $mail, $codetrajet)
return $row[0] == 0;
}
//Verifier que le trajet à bien été fait par l'utilisateur $mail
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));
@ -30,6 +32,7 @@ if (isset($_POST['codetrajet']) && isset($_POST['avislaisse']) && isset($_POST['
$note = $_POST['note'];
$codetrajet = intval($_POST['codetrajet']);
$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)) {
$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));
$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));
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'];
if ($date_depart <date('Y-m-d')){
$source = explode('%%', $_POST['villeDepart']);
$cpsource = $source[1];
$source = $source[0];
$dest = explode('%%', $_POST['villeArrive']);
$cpdest = $dest[1];
$dest = $dest[0];
$date_depart = $_POST['date_heure'];
if ($date_depart <date('Y-m-d')){
echo "Erreur date</br>";
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)))
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 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))
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 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 estannule = false AND $2 BETWEEN datedepart AND datearrivee;", array($mail, $dateDepart));
$row = pg_fetch_array($result);
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
function checkPlacesVoiture($db, $codetrajet)
{
@ -80,9 +86,10 @@ function checkVoiture($db, $mail, $matricule)
return !strcmp($matricule, $row[0]);
}
//Recuperer le nombre de trajets restant proposés par l'utilisateur $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 >= $2;", array($mail, date('Y-m-d H:i:s')));
if ($result) {
$row = pg_fetch_array($result);
return $row[0];
@ -90,9 +97,10 @@ function getTrajetsProposes($db, $mail)
return 0;
}
//Recuperer le nombre de trajets restant reservés par l'utilisateur $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 estAnnule = false AND datedepart >= current_date;", array($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')));
if ($result) {
$row = pg_fetch_array($result);
return $row[0];
@ -150,31 +158,35 @@ function afficherVilles($db)
}
}
//Récuperer la ville de départ du trajet $codetrajet
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 * 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) {
$return = pg_fetch_array($result)[0];
$return = pg_fetch_array($result);
}
return $return;
}
//Récuperer la ville d'arrivée du trajet $codetrajet
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 * 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) {
$return = pg_fetch_array($result)[0];
$return = pg_fetch_array($result);
}
return $return;
}
//Annuler le trajet $codetrajet
function annulerTrajet($db, $codetrajet){
$result = pg_query_params($db, "UPDATE Trajet SET estannule = true WHERE codetrajet = $1;", array($codetrajet));
return $result;
}
//Annuler la reservation pour le tajet $codetrajet de l'utilisateur $mail
function annulerReservation($db, $mail,$codetrajet){
$result = pg_query_params($db, "DELETE FROM reserver WHERE codetrajet = $1 AND mailutilisateur = $2;", array($codetrajet, $mail));
return $result;
@ -194,4 +206,13 @@ 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));