avisTrajet
remi.biette 6 years ago
parent 78eac17d42
commit 38bd61a394

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

@ -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))) $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> <!DOCTYPE html>

@ -5,7 +5,7 @@ function verifierTrajet($db, $mail, $codetrajet){
if (!$trajet){ if (!$trajet){
return false; 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"); require_once("../connexionBD.php");
@ -19,12 +19,15 @@ $mail = $_SESSION['mail'];
if (isset($_GET['codetrajet'])){ if (isset($_GET['codetrajet'])){
$codetrajet = $_GET['codetrajet']; $codetrajet = $_GET['codetrajet'];
if (verifierTrajet($db, $mail, $codetrajet)){ if (verifierTrajet($db, $mail, $codetrajet) && reserver($db, $mail, $codetrajet)){
reserver($db, $mail, $codetrajet);
}
}
header('Location: ../tableauBord/tableauBord.php'); header('Location: ../tableauBord/tableauBord.php');
exit(); exit();
}
else{
header('Location: ../recherche/recherche.php?error=1');
exit();
}
}

@ -170,7 +170,11 @@ if (isset($_POST['login']) || isset($_FILES['avatar'])){
<label for="avatar">Image du Profil :</label> <label for="avatar">Image du Profil :</label>
<input type="file" id="avatar" class="form" name="avatar" accept="image/png, image/jpeg"> <input type="file" id="avatar" class="form" name="avatar" accept="image/png, image/jpeg">
</div> </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"> <input id="submit" class="button" type="submit" value="Modifier">
</form> </form>
</div> </div>

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

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

@ -7,7 +7,7 @@ function getListeVilles($db)
} }
function reserver($db, $mail, $codetrajet){ 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) function getTrajet($db, $codetrajet)
@ -37,12 +37,18 @@ function creerEtapes($db, $codeTrajet, $etapes)
//Vérifier la cohérence des dates //Vérifier la cohérence des dates
function checkDates($db, $mail, $dateDepart, $dateArrivee) function checkDates($db, $mail, $dateDepart, $dateArrivee)
{ {
$valide = $dateDepart < $dateArrivee && $dateDepart > date('Y-m-d H:i:s'); $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)); $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); $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)
{ {
@ -92,7 +98,7 @@ function getTrajetsProposes($db, $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 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) { if ($result) {
$row = pg_fetch_array($result); $row = pg_fetch_array($result);
return $row[0]; return $row[0];

Loading…
Cancel
Save