put functions in files and created a file that check connection
This commit is contained in:
parent
a92937be62
commit
d30839192c
@ -1,67 +1,8 @@
|
||||
<?php
|
||||
|
||||
//Récupérer la liste des voitures concernant un utilisateur
|
||||
function getListeVoitures($db, $mail){
|
||||
$result = pg_query_params($db, "SELECT * FROM Voiture WHERE mail = $1;", array($mail));
|
||||
return $result;
|
||||
}
|
||||
|
||||
//Afficher les voitures dans un select
|
||||
function afficherVoitures($db, $mail){
|
||||
|
||||
$voitures = getListeVoitures($db, $mail);
|
||||
while ($row = pg_fetch_array($voitures)) {
|
||||
$modele = $row['modele'];
|
||||
$matricule = $row['matricule'];
|
||||
echo "<option value='$matricule'>$modele</option>";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Afficher les voitures dans un select
|
||||
function afficherVilles($db)
|
||||
{
|
||||
$villes = getListeVilles($db);
|
||||
while ($row = pg_fetch_array($villes)) {
|
||||
$nom = $row['nomville'];
|
||||
$cp = $row['codepostal'];
|
||||
echo "<option value='$nom%%$cp'>$nom ($cp)</option>";
|
||||
}
|
||||
}
|
||||
|
||||
function printError()
|
||||
{
|
||||
if (isset($_GET['error'])) {
|
||||
$erreur = getError($_GET['error']);
|
||||
echo "<p class = 'error'>$erreur</p>";
|
||||
}
|
||||
}
|
||||
|
||||
function getError($code)
|
||||
{
|
||||
switch ($code) {
|
||||
case 1:
|
||||
return "Erreur lors de la vérification des étapes.";
|
||||
case 2:
|
||||
return "Erreur lors de la vérification des dates.";
|
||||
case 3:
|
||||
return "Ce compte n'est pas associé à la voiture sélectionnée.";
|
||||
case 4:
|
||||
return "Erreur lors de l'enregistrement du trajet.";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
require_once('../connexionBD.php');
|
||||
require_once('../ressources/trajet.php');
|
||||
require_once ('../ressources/verifconnecte.php');
|
||||
|
||||
session_start();
|
||||
//Utilisateur connecté
|
||||
if (!isset($_SESSION['mail'])) {
|
||||
header('Location: ../index.php');
|
||||
exit();
|
||||
}
|
||||
$mail = $_SESSION['mail'];
|
||||
//Tester que tous les champs ont été renseignés
|
||||
if (isset($_POST['dateDepart']) && isset($_POST['dateArrivee']) && isset($_POST['voiture']) && isset($_POST['villeDepart']) && isset($_POST['nbEtapes']) && isset($_POST['etape1'])) {
|
||||
//Récupérer tous les $_POST en variables
|
||||
@ -104,9 +45,7 @@ if (isset($_POST['dateDepart']) && isset($_POST['dateArrivee']) && isset($_POST[
|
||||
header('Location: depotTrajet.php?error=4');
|
||||
exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
@ -137,9 +76,7 @@ if (isset($_POST['dateDepart']) && isset($_POST['dateArrivee']) && isset($_POST[
|
||||
<label class="label" for="voiture">Voiture : </label>
|
||||
<select class="form" name="voiture" id="voiture" required>
|
||||
<option selected></option>
|
||||
<?php
|
||||
afficherVoitures($db, $mail);
|
||||
?>
|
||||
<?php afficherVoitures($db, $mail); ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="line">
|
||||
@ -147,9 +84,7 @@ if (isset($_POST['dateDepart']) && isset($_POST['dateArrivee']) && isset($_POST[
|
||||
<input type="text" class="form, villeText" name="villeDepartText" id="villeDepartText">
|
||||
<select class="form, villeSelect" name="villeDepart" id="villeDepart" required>
|
||||
<option selected></option>
|
||||
<?php
|
||||
afficherVilles($db);
|
||||
?>
|
||||
<?php afficherVilles($db); ?>
|
||||
</select>
|
||||
</div>
|
||||
<div id="villeEtapeDiv" class="line">
|
||||
@ -157,9 +92,7 @@ if (isset($_POST['dateDepart']) && isset($_POST['dateArrivee']) && isset($_POST[
|
||||
<input type="text" class="form, villeText" id="villeEtapeText" name="villeEtapeText">
|
||||
<select class="form, villeSelect" name="villeEtape" id="villeEtape" required>
|
||||
<option selected></option>
|
||||
<?php
|
||||
afficherVilles($db);
|
||||
?>
|
||||
<?php afficherVilles($db); ?>
|
||||
</select>
|
||||
</div>
|
||||
<div id="boutonEtape" class="line">
|
||||
@ -167,9 +100,7 @@ if (isset($_POST['dateDepart']) && isset($_POST['dateArrivee']) && isset($_POST[
|
||||
<input id="supprimerEtape" class='button' type='button' value='Supprimer une étape'>
|
||||
<input id="nbEtapes" name="nbEtapes" type="hidden" value="1" required>
|
||||
</div>
|
||||
<?php
|
||||
printError();
|
||||
?>
|
||||
<?php getErrorDepotTrajet($_GET['error']); ?>
|
||||
<div class="line">
|
||||
<input id="submit" class="button" type="submit" value="Poster le trajet">
|
||||
</div>
|
||||
@ -177,4 +108,4 @@ if (isset($_POST['dateDepart']) && isset($_POST['dateArrivee']) && isset($_POST[
|
||||
<script src="depotTrajet.js"></script>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
@ -2,13 +2,7 @@
|
||||
session_start();
|
||||
require_once('../connexionBD.php');
|
||||
require_once ('../ressources/user.php');
|
||||
|
||||
$mail = $_SESSION['mail'];
|
||||
|
||||
if (!isset($_SESSION['mail'])) {
|
||||
header('Location: index.php');
|
||||
exit();
|
||||
}
|
||||
require_once ('../ressources/verifconnecte.php');
|
||||
|
||||
$user = getUser($db, $mail);
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
//Récupérer la liste complete des villes
|
||||
function getListeVilles($db) {
|
||||
$result = pg_query($db, "SELECT * FROM Ville;");
|
||||
@ -36,4 +35,81 @@ 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]);
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
if ($result) {
|
||||
$row = pg_fetch_array($result);
|
||||
return $row[0];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function getTrajetsReserves($db, $mail){
|
||||
$result = pg_query_params($db, "SELECT COUNT(*) FROM trajet tr, reserver r WHERE r.codetrajet = tr.codetrajet AND mailutilisateur = $1 AND etatres != 'Annulée' AND estAnnule = false AND datedepart >= current_date;", array($mail));
|
||||
if ($result) {
|
||||
$row = pg_fetch_array($result);
|
||||
return $row[0];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function getMessagesNonLus($db, $mail){
|
||||
$result = pg_query_params($db, "SELECT COUNT(*) from Message WHERE mailRecepteur = $1 AND estLu = FALSE;", array($mail));
|
||||
if ($result) {
|
||||
$row = pg_fetch_array($result);
|
||||
$login = $row[0];
|
||||
return $login;
|
||||
}
|
||||
}
|
||||
|
||||
function getAvisNonLus($db, $mail){
|
||||
global $db;
|
||||
$result = pg_query_params($db, "SELECT COUNT(tr.mailProposition) FROM Trajet tr, Avis av WHERE tr.codeTrajet = av.codeTrajet AND av.estLu = false AND tr.mailProposition = $1;", array($mail));
|
||||
if ($result) {
|
||||
$row = pg_fetch_array($result);
|
||||
$login = $row[0];
|
||||
return $login;
|
||||
}
|
||||
}
|
||||
|
||||
//Récupérer la liste des voitures concernant un utilisateur
|
||||
function getListeVoitures($db, $mail){
|
||||
$result = pg_query_params($db, "SELECT * FROM Voiture WHERE mail = $1;", array($mail));
|
||||
return $result;
|
||||
}
|
||||
|
||||
//Afficher les voitures dans un select
|
||||
function afficherVoitures($db, $mail){
|
||||
$voitures = getListeVoitures($db, $mail);
|
||||
while ($row = pg_fetch_array($voitures)) {
|
||||
$modele = $row['modele'];
|
||||
$matricule = $row['matricule'];
|
||||
echo "<option value='$matricule'>$modele</option>";
|
||||
}
|
||||
}
|
||||
|
||||
//Afficher les voitures dans un select
|
||||
function afficherVilles($db){
|
||||
$villes = getListeVilles($db);
|
||||
while ($row = pg_fetch_array($villes)) {
|
||||
$nom = $row['nomville'];
|
||||
$cp = $row['codepostal'];
|
||||
echo "<option value='$nom%%$cp'>$nom ($cp)</option>";
|
||||
}
|
||||
}
|
||||
|
||||
function getErrorDepotTrajet($code){
|
||||
switch ($code) {
|
||||
case 1:
|
||||
return "Erreur lors de la vérification des étapes.";
|
||||
case 2:
|
||||
return "Erreur lors de la vérification des dates.";
|
||||
case 3:
|
||||
return "Ce compte n'est pas associé à la voiture sélectionnée.";
|
||||
case 4:
|
||||
return "Erreur lors de l'enregistrement du trajet.";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
8
WEB/ressources/verifconnecte.php
Normal file
8
WEB/ressources/verifconnecte.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
//Si on est pas connecté redirection vers la page de connexion
|
||||
if (!isset($_SESSION['mail'])) {
|
||||
header('Location: ../index.php');
|
||||
exit();
|
||||
}
|
||||
$mail = $_SESSION['mail'];
|
||||
?>
|
@ -2,50 +2,8 @@
|
||||
session_start();
|
||||
require_once('../connexionBD.php');
|
||||
require_once ('../ressources/user.php');
|
||||
|
||||
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));
|
||||
if ($result) {
|
||||
$row = pg_fetch_array($result);
|
||||
return $row[0];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function getTrajetsReserves($db, $mail){
|
||||
$result = pg_query_params($db, "SELECT COUNT(*) FROM trajet tr, reserver r WHERE r.codetrajet = tr.codetrajet AND mailutilisateur = $1 AND etatres != 'Annulée' AND estAnnule = false AND datedepart >= current_date;", array($mail));
|
||||
if ($result) {
|
||||
$row = pg_fetch_array($result);
|
||||
return $row[0];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function getMessagesNonLus($db, $mail){
|
||||
$result = pg_query_params($db, "SELECT COUNT(*) from Message WHERE mailRecepteur = $1 AND estLu = FALSE;", array($mail));
|
||||
if ($result) {
|
||||
$row = pg_fetch_array($result);
|
||||
$login = $row[0];
|
||||
return $login;
|
||||
}
|
||||
}
|
||||
|
||||
function getAvisNonLus($db, $mail){
|
||||
global $db;
|
||||
$result = pg_query_params($db, "SELECT COUNT(tr.mailProposition) FROM Trajet tr, Avis av WHERE tr.codeTrajet = av.codeTrajet AND av.estLu = false AND tr.mailProposition = $1;", array($mail));
|
||||
if ($result) {
|
||||
$row = pg_fetch_array($result);
|
||||
$login = $row[0];
|
||||
return $login;
|
||||
}
|
||||
}
|
||||
|
||||
//Si on est pas connecté redirection vers la page de connexion
|
||||
if (!isset($_SESSION['mail'])) {
|
||||
header('Location: ../index.php');
|
||||
exit();
|
||||
}
|
||||
$mail = $_SESSION['mail'];
|
||||
require_once ('../ressources/trajet.php');
|
||||
require_once ('../ressources/verifconnecte.php');
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
|
Loading…
Reference in New Issue
Block a user