From 62d31524a1420e160941574e4325ac55a709fd50 Mon Sep 17 00:00:00 2001 From: flavien Date: Mon, 20 May 2019 17:15:51 +0200 Subject: [PATCH] added a way to change voiture in profil --- WEB/profil.php | 170 ----------------- WEB/{ => profil}/profil.css | 0 WEB/profil/profil.php | 323 ++++++++++++++++++++++++++++++++ WEB/ressources/navbarhtml.php | 4 +- WEB/ressources/user.php | 16 +- WEB/tableauBord/tableauBord.php | 134 ------------- 6 files changed, 333 insertions(+), 314 deletions(-) delete mode 100644 WEB/profil.php rename WEB/{ => profil}/profil.css (100%) create mode 100644 WEB/profil/profil.php diff --git a/WEB/profil.php b/WEB/profil.php deleted file mode 100644 index f7a65e1..0000000 --- a/WEB/profil.php +++ /dev/null @@ -1,170 +0,0 @@ -$erreur

"; - } -} - -function getErrorProfil($code) -{ - switch ($code) { - case 1: - return "Ce login est déjà associé à un compte."; - case 2: - return "Les mots de passe ne correspondent pas."; - case 3: - return "Erreur lors de la récupération des informations de profil."; - case 4: - return "Le fichier envoyé doit être une image au format PNG ou JPEG."; - case 5: - return "La taille de l'image ne doit pas dépasser 2 MB."; - case 6: - return "Erreur lors de la modification du compte."; - - } -} - -?> - - - - - - - - - Profil - - - -
-

Profil

-
- -
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
- - -
-
- - diff --git a/WEB/profil.css b/WEB/profil/profil.css similarity index 100% rename from WEB/profil.css rename to WEB/profil/profil.css diff --git a/WEB/profil/profil.php b/WEB/profil/profil.php new file mode 100644 index 0000000..433cbab --- /dev/null +++ b/WEB/profil/profil.php @@ -0,0 +1,323 @@ +$erreur

"; + } +} + +function getErrorProfil($code){ + switch ($code) { + case 1: + return "Ce login est déjà associé à un compte."; + case 2: + return "Les mots de passe ne correspondent pas."; + case 3: + return "Erreur lors de la récupération des informations de profil."; + case 4: + return "Le fichier envoyé doit être une image au format PNG ou JPEG."; + case 5: + return "La taille de l'image ne doit pas dépasser 2 MB."; + case 6: + return "Erreur lors de la modification du compte."; + } +} + +function addVoiture($db, $matricule, $marque, $modele, $nbplaces, $anneefab){ + $requete = "INSERT INTO public.voiture (matricule, marque, modele, nbplaces, anneefab, mail) VALUES ('" . $matricule . "','" . $marque . "','" . $modele . "','" . $nbplaces . "','" . $anneefab . "','" . $_SESSION['mail'] . "');"; + pg_query($db, $requete); +} + +function changeVoiture($db, $matricule, $marque, $modele, $nbplaces, $anneefab){ + $requete = "UPDATE public.voiture SET (matricule, marque, modele, nbplaces, anneefab) = ('" . $matricule . "','" . $marque . "','" . $modele . "','" . $nbplaces . "','" . $anneefab . "') WHERE mail = '" . $_SESSION['mail'] . "';"; + echo "requete =" . $requete; + pg_query($db, $requete); +} + +function showVoiture($db){ + $requete = "SELECT * FROM public.voiture WHERE voiture.mail = '" . $_SESSION['mail'] . "';"; + if ($donnees = pg_query($db, $requete)) { + while ($res = pg_fetch_assoc($donnees)) { + echo "matricule = ".$res['matricule']."
"; + echo "marque = ".$res['marque']."
"; + echo "modele = ".$res['modele']."
"; + echo "nombre de places = ".$res['nbplaces']."
"; + echo "année de fabrication = ".$res['anneefab']."
"; + //return "matricule = ".$res['matricule']."
"."marque = " . $res['marque'] . "
"."modele = " . $res['modele'] . "
"."nombre de places = " . $res['nbplaces'] . "
"."année de fabrication = " . $res['anneefab'] . "
"; + } + } +} + +if (!isset($_SESSION['mail'])) { + header('Location: index.php'); + exit(); +} + +if (isset($_POST['submitadd'])) { + addVoiture($db, $matricule, $marque, $modele, $nbplaces, $anneefab); +} +if (isset($_POST['submitchange'])) { + changeVoiture($db, $matricule, $marque, $modele, $nbplaces, $anneefab); +} + +$user = getUser($db, $mail); + +if (!$user){ + header('Location: profil.php?error=3'); + exit(); +} + +if (isset($_POST['login']) || isset($_FILES['avatar'])){ + if (isset($_FILES['avatar']) and !empty($_FILES['avatar']['name'])) { + $fic = $_FILES['avatar']; + supprimerAvatar($mail); + $res = uploadAvatar($mail, $fic); + switch ($res){ + case -1: + header('Location: profil.php?error=4'); + exit(); + case -2: + header('Location: profil.php?error=5'); + exit(); + case -3: + header('Location: profil.php?error=6'); + exit(); + } + } + if (isset($_POST['login']) && isset($_POST['password']) && isset($_POST['confirmation']) && isset($_POST['prenom']) && isset($_POST['nom']) && isset($_POST['phone'])) { + $login = htmlentities(pg_escape_string($_POST['login'])); + $password = htmlentities(pg_escape_string($_POST['password'])); + $confirmation = htmlentities(pg_escape_string($_POST['confirmation'])); + $prenom = htmlentities(pg_escape_string($_POST['prenom'])); + $nom = htmlentities(pg_escape_string($_POST['nom'])); + $phone = htmlentities(pg_escape_string($_POST['phone'])); + + if (loginChange($user, $login)) { + if (!isLoginUniqueModifier($db, $mail, $login)) { + header('Location: profil.php?error=1'); + exit(); + } else { + if (!modifierLogin($db, $mail, $login)) { + header('Location: profil.php?error=6'); + exit(); + } + } + } + + if (strcmp($password, $confirmation) != 0) { + header('Location: profil.php?error=2'); + exit(); + } + + if (!modifierUtilisateur($db, $mail, $prenom, $nom, $password, $phone)) { + header('Location: profil.php?error=6'); + exit(); + } + } + sleep(0.85); + header('Location: profil.php'); + exit(); +} +?> + + + + + + + + + Profil + + + +
+

Profil de

+
+ +
+ + + + + + + + + + + + + diff --git a/WEB/ressources/navbarhtml.php b/WEB/ressources/navbarhtml.php index 8aadb30..bd1d009 100644 --- a/WEB/ressources/navbarhtml.php +++ b/WEB/ressources/navbarhtml.php @@ -14,7 +14,7 @@ if (file_exists("./inscription.php")) { Messagerie Avis reçus Avis laissés - Profil + Profil Se déconnecter -
\ No newline at end of file + diff --git a/WEB/ressources/user.php b/WEB/ressources/user.php index 14547e2..15c3c54 100644 --- a/WEB/ressources/user.php +++ b/WEB/ressources/user.php @@ -57,7 +57,7 @@ function getLogin($db, $mail) function getPathImgProfilTableau($mail) { - $list = scandir($_SERVER['DOCUMENT_ROOT'] . "/imageProfil"); + $list = scandir($_SERVER['DOCUMENT_ROOT'] . "../imageProfil"); foreach ($list as $entry) { if (strpos($entry, $mail) !== false) { return "../imageProfil/$entry"; @@ -68,21 +68,21 @@ function getPathImgProfilTableau($mail) function getPathImgProfil($mail) { - $list = scandir($_SERVER['DOCUMENT_ROOT'] . "/imageProfil"); + $list = scandir($_SERVER['DOCUMENT_ROOT'] . "../imageProfil"); foreach ($list as $entry) { if (strpos($entry, $mail) !== false) { - return "./imageProfil/$entry"; + return "/./imageProfil/$entry"; } } - return "./imageProfil/default.svg"; + return "../imageProfil/default.svg"; } function supprimerAvatar($mail) { - $list = scandir($_SERVER['DOCUMENT_ROOT'] . "/imageProfil"); + $list = scandir($_SERVER['DOCUMENT_ROOT'] . "../imageProfil"); foreach ($list as $entry) { if (strpos($entry, $mail) !== false) { - unlink($_SERVER['DOCUMENT_ROOT'] . "/imageProfil/$entry"); + unlink($_SERVER['DOCUMENT_ROOT'] . "../imageProfil/$entry"); } } } @@ -117,7 +117,7 @@ function uploadAvatar($mail, $fic) { $tmp = explode('.', $fic['name']); $extension = end($tmp); - $target_file = "./imageProfil/$mail.$extension"; + $target_file = "../imageProfil/$mail.$extension"; $file_tmp = $fic['tmp_name']; $check = getimagesize($file_tmp); if ($check === false or !in_array($extension, array('png', 'jpg', 'jpeg', 'pjpeg', 'jfif', 'pjp'))) { @@ -130,4 +130,4 @@ function uploadAvatar($mail, $fic) } } return 0; -} \ No newline at end of file +} diff --git a/WEB/tableauBord/tableauBord.php b/WEB/tableauBord/tableauBord.php index 944451a..8c46bf4 100644 --- a/WEB/tableauBord/tableauBord.php +++ b/WEB/tableauBord/tableauBord.php @@ -12,22 +12,6 @@ if (!isset($_SESSION['mail'])) { } $mail = $_SESSION['mail']; -$matricule = isset($_POST['matricule']) ? $_POST['matricule'] : NULL; //recuperation valeur formulaire, isset pour eviter l'erreur "Notice: Undefined index" -$marque = isset($_POST['marque']) ? $_POST['marque'] : NULL; -$modele = isset($_POST['modele']) ? $_POST['modele'] : NULL; -$nbplaces = isset($_POST['nbplaces']) ? $_POST['nbplaces'] : NULL; -$anneefab = isset($_POST['anneefab']) ? $_POST['anneefab'] : NULL; - -if (isset($_POST['submitadd'])) { - addVoiture($db, $matricule, $marque, $modele, $nbplaces, $anneefab); -} -if (isset($_POST['submitchange'])) { - changeVoiture($db, $matricule, $marque, $modele, $nbplaces, $anneefab); -} -if (isset($_POST['submitshow'])) { - showVoiture($db); -} - 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)); @@ -68,34 +52,6 @@ function getAvisNonLus($db, $mail) return $login; } } - -function addVoiture($db, $matricule, $marque, $modele, $nbplaces, $anneefab) -{ - $requete = "INSERT INTO public.voiture (matricule, marque, modele, nbplaces, anneefab, mail) VALUES ('" . $matricule . "','" . $marque . "','" . $modele . "','" . $nbplaces . "','" . $anneefab . "','" . $_SESSION['mail'] . "');"; - pg_query($db, $requete); -} - -function changeVoiture($db, $matricule, $marque, $modele, $nbplaces, $anneefab) -{ - $requete = "UPDATE public.voiture SET (matricule, marque, modele, nbplaces, anneefab) = ('" . $matricule . "','" . $marque . "','" . $modele . "','" . $nbplaces . "','" . $anneefab . "') WHERE mail = '" . $_SESSION['mail'] . "';"; - echo "requete =" . $requete; - pg_query($db, $requete); -} - -function showVoiture($db) -{ - $requete = "SELECT * FROM public.voiture WHERE voiture.mail = '" . $_SESSION['mail'] . "';"; - if ($donnees = pg_query($db, $requete)) { - while ($res = pg_fetch_assoc($donnees)) { - echo "matricule = " . $res['matricule'] . "
"; - echo "marque = " . $res['marque'] . "
"; - echo "modele = " . $res['modele'] . "
"; - echo "nombre de places = " . $res['nbplaces'] . "
"; - echo "année de fabrication = " . $res['anneefab'] . "
"; - } - } -} - ?> @@ -108,13 +64,6 @@ function showVoiture($db) -

Bienvenue

@@ -143,89 +92,6 @@ function showVoiture($db)

Vous avez avis non lus.

-
-
- Ajouter une voiture - Modifier ma voiture - Afficher ma voiture -
-
- - -