39 lines
1.7 KiB
PHP
39 lines
1.7 KiB
PHP
<?php
|
|
|
|
//Récupérer la liste complete des villes
|
|
function getListeVilles($db) {
|
|
$result = pg_query($db, "SELECT * FROM Ville;");
|
|
return $result;
|
|
}
|
|
|
|
//Créer un trajet en bd
|
|
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));
|
|
return $result;
|
|
}
|
|
|
|
//Creer les étapes d'un trajet
|
|
function creerEtapes($db, $codeTrajet, $etapes){
|
|
$result = true;
|
|
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));
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
//Vérifier la cohérence des dates
|
|
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 que l'utilisateur est bien associé à cette voiture
|
|
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]);
|
|
} |