put functions in files and created a file that check connection

admin
Flavien Haas 6 years ago
parent a92937be62
commit d30839192c

@ -1,67 +1,8 @@
<?php <?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('../connexionBD.php');
require_once('../ressources/trajet.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 //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'])) { 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 //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'); header('Location: depotTrajet.php?error=4');
exit(); exit();
} }
} }
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="fr"> <html lang="fr">
@ -137,9 +76,7 @@ if (isset($_POST['dateDepart']) && isset($_POST['dateArrivee']) && isset($_POST[
<label class="label" for="voiture">Voiture : </label> <label class="label" for="voiture">Voiture : </label>
<select class="form" name="voiture" id="voiture" required> <select class="form" name="voiture" id="voiture" required>
<option selected></option> <option selected></option>
<?php <?php afficherVoitures($db, $mail); ?>
afficherVoitures($db, $mail);
?>
</select> </select>
</div> </div>
<div class="line"> <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"> <input type="text" class="form, villeText" name="villeDepartText" id="villeDepartText">
<select class="form, villeSelect" name="villeDepart" id="villeDepart" required> <select class="form, villeSelect" name="villeDepart" id="villeDepart" required>
<option selected></option> <option selected></option>
<?php <?php afficherVilles($db); ?>
afficherVilles($db);
?>
</select> </select>
</div> </div>
<div id="villeEtapeDiv" class="line"> <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"> <input type="text" class="form, villeText" id="villeEtapeText" name="villeEtapeText">
<select class="form, villeSelect" name="villeEtape" id="villeEtape" required> <select class="form, villeSelect" name="villeEtape" id="villeEtape" required>
<option selected></option> <option selected></option>
<?php <?php afficherVilles($db); ?>
afficherVilles($db);
?>
</select> </select>
</div> </div>
<div id="boutonEtape" class="line"> <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="supprimerEtape" class='button' type='button' value='Supprimer une étape'>
<input id="nbEtapes" name="nbEtapes" type="hidden" value="1" required> <input id="nbEtapes" name="nbEtapes" type="hidden" value="1" required>
</div> </div>
<?php <?php getErrorDepotTrajet($_GET['error']); ?>
printError();
?>
<div class="line"> <div class="line">
<input id="submit" class="button" type="submit" value="Poster le trajet"> <input id="submit" class="button" type="submit" value="Poster le trajet">
</div> </div>

@ -2,13 +2,7 @@
session_start(); session_start();
require_once('../connexionBD.php'); require_once('../connexionBD.php');
require_once ('../ressources/user.php'); require_once ('../ressources/user.php');
require_once ('../ressources/verifconnecte.php');
$mail = $_SESSION['mail'];
if (!isset($_SESSION['mail'])) {
header('Location: index.php');
exit();
}
$user = getUser($db, $mail); $user = getUser($db, $mail);

@ -1,5 +1,4 @@
<?php <?php
//Récupérer la liste complete des villes //Récupérer la liste complete des villes
function getListeVilles($db) { function getListeVilles($db) {
$result = pg_query($db, "SELECT * FROM Ville;"); $result = pg_query($db, "SELECT * FROM Ville;");
@ -37,3 +36,80 @@ function checkVoiture($db, $mail, $matricule){
$row = pg_fetch_array($result); $row = pg_fetch_array($result);
return !strcmp($matricule, $row[0]); 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.";
}
}
?>

@ -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(); session_start();
require_once('../connexionBD.php'); require_once('../connexionBD.php');
require_once ('../ressources/user.php'); require_once ('../ressources/user.php');
require_once ('../ressources/trajet.php');
function getTrajetsProposes($db, $mail){ require_once ('../ressources/verifconnecte.php');
$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'];
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="fr"> <html lang="fr">

Loading…
Cancel
Save