This commit is contained in:
remi.biette 2019-05-23 12:05:13 +02:00
parent 78eac17d42
commit 38bd61a394
7 changed files with 48 additions and 13 deletions

View File

@ -40,6 +40,7 @@ require_once("../ressources/navbarhtml.php");
$date_depart = $row['datedepart'];
$codetrajet = $row['codetrajet'];
$source = getDepart($db, $codetrajet);
$dest = getFin($db, $codetrajet);
echo "<tr><td class='ligne'><hr class='separation'/></td>";
echo "<td class='info'><p>$date_depart - $source vers $dest proposé par : $login</p></td>";

View File

@ -25,7 +25,7 @@ if (isset($_POST['lieu_depart']) && isset($_POST['lieu_arrivee']) && isset($_POS
}
$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));
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 tr.codepostal = v.codepostal AND tr.numeroetape != 1);", array($source, $dest, $date_depart));
?>
<!DOCTYPE html>

View File

@ -5,7 +5,7 @@ function verifierTrajet($db, $mail, $codetrajet){
if (!$trajet){
return false;
}
return checkReservations($db, $mail, $codetrajet) && checkDatesReserve($db, $mail, $trajet['datedepart']) && checkPlacesVoiture($db, $codetrajet) && strcmp($trajet['mailproposition'], $mail) != 0;
return checkReservations($db, $mail, $codetrajet) && checkPlacesVoiture($db, $codetrajet) && strcmp($mail, $trajet['mailproposition'])!=0;
}
require_once("../connexionBD.php");
@ -19,12 +19,15 @@ $mail = $_SESSION['mail'];
if (isset($_GET['codetrajet'])){
$codetrajet = $_GET['codetrajet'];
if (verifierTrajet($db, $mail, $codetrajet)){
reserver($db, $mail, $codetrajet);
if (verifierTrajet($db, $mail, $codetrajet) && reserver($db, $mail, $codetrajet)){
header('Location: ../tableauBord/tableauBord.php');
exit();
}
else{
header('Location: ../recherche/recherche.php?error=1');
exit();
}
}
header('Location: ../tableauBord/tableauBord.php');
exit();

View File

@ -170,7 +170,11 @@ if (isset($_POST['login']) || isset($_FILES['avatar'])){
<label for="avatar">Image du Profil :</label>
<input type="file" id="avatar" class="form" name="avatar" accept="image/png, image/jpeg">
</div>
<?php getErrorProfil($_GET['error']); ?>
<?php
if (isset($_GET['error'])){
echo "<p class='error'>".getErrorProfil($_GET['error'])."</p>";
}
?>
<input id="submit" class="button" type="submit" value="Modifier">
</form>
</div>

View File

@ -1,3 +1,7 @@
*{
font-family: "Arial";
}
.centrage {
text-align: center;
font-size: 20px;
@ -37,4 +41,9 @@ h1 {
text-align: center;
}
.error{
color: red;
text-align: center;
}

View File

@ -1,4 +1,13 @@
<?php
function getError($code)
{
switch ($code) {
case 1:
return "Impossible de réserver ce trajet";
}
}
session_start();
require_once('../ressources/verifconnecte.php');
?>
@ -46,9 +55,12 @@ require_once("../ressources/navbarhtml.php");
</label>
</form>
</div>
<?php
if (isset($_GET['error'])) {
echo "<p class='error'>" . getError($_GET['error']) . "</p>";
}
?>
</div>
</div>
</body>
</html>

View File

@ -7,7 +7,7 @@ function getListeVilles($db)
}
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')));
return pg_query_params($db, "INSERT INTO Reserver VALUES ($1, $2, false, $3);", array($mail, $codetrajet, date('Y-m-d H:i:s')));
}
function getTrajet($db, $codetrajet)
@ -37,12 +37,18 @@ function creerEtapes($db, $codeTrajet, $etapes)
//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));
$valide = $dateDepart <= $dateArrivee && $dateDepart >= date('Y-m-d H:i:s');
$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)
{
@ -92,7 +98,7 @@ function getTrajetsProposes($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 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 estannule = false AND tr.datedepart >= current_timestamp;", array($mail));
if ($result) {
$row = pg_fetch_array($result);
return $row[0];