2019-05-09 16:35:10 +02:00
|
|
|
<?php
|
|
|
|
|
2019-05-17 06:34:13 +02:00
|
|
|
require_once('connexionBD.php');
|
2019-05-18 00:40:45 +02:00
|
|
|
require_once ('ressources/user.php');
|
2019-05-11 12:44:29 +02:00
|
|
|
|
|
|
|
session_start();
|
2019-05-09 16:35:10 +02:00
|
|
|
|
2019-05-17 06:34:13 +02:00
|
|
|
if (!isset($_SESSION['mail'])) {
|
2019-05-09 16:35:10 +02:00
|
|
|
header('Location: index.php');
|
|
|
|
exit();
|
|
|
|
}
|
2019-05-11 12:44:29 +02:00
|
|
|
|
|
|
|
$mail = $_SESSION['mail'];
|
|
|
|
|
2019-05-18 00:40:45 +02:00
|
|
|
$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'])) {
|
2019-05-11 12:44:29 +02:00
|
|
|
$fic = $_FILES['avatar'];
|
|
|
|
supprimerAvatar($mail);
|
2019-05-18 00:40:45 +02:00
|
|
|
$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();
|
|
|
|
}
|
2019-05-11 12:44:29 +02:00
|
|
|
}
|
2019-05-18 00:40:45 +02:00
|
|
|
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']));
|
2019-05-17 06:34:13 +02:00
|
|
|
$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']));
|
|
|
|
|
2019-05-18 00:40:45 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2019-05-11 12:44:29 +02:00
|
|
|
}
|
|
|
|
|
2019-05-17 06:34:13 +02:00
|
|
|
if (strcmp($password, $confirmation) != 0) {
|
2019-05-11 12:44:29 +02:00
|
|
|
header('Location: profil.php?error=2');
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2019-05-18 00:40:45 +02:00
|
|
|
if (!modifierUtilisateur($db, $mail, $prenom, $nom, $password, $phone)) {
|
2019-05-11 12:44:29 +02:00
|
|
|
header('Location: profil.php?error=6');
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
2019-05-18 00:40:45 +02:00
|
|
|
sleep(0.85);
|
2019-05-11 12:44:29 +02:00
|
|
|
header('Location: profil.php');
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2019-05-17 06:34:13 +02:00
|
|
|
function printError()
|
|
|
|
{
|
|
|
|
if (isset($_GET['error'])) {
|
2019-05-11 12:44:29 +02:00
|
|
|
$erreur = getErrorProfil($_GET['error']);
|
|
|
|
echo "<p class = 'error'>$erreur</p>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-17 06:34:13 +02:00
|
|
|
function getErrorProfil($code)
|
|
|
|
{
|
|
|
|
switch ($code) {
|
2019-05-11 12:44:29 +02:00
|
|
|
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.";
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-09 16:35:10 +02:00
|
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="fr">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
2019-05-11 12:44:29 +02:00
|
|
|
<link rel="stylesheet" href="profil.css">
|
2019-05-17 06:34:13 +02:00
|
|
|
<link rel="stylesheet" href="ressources/navbarhtml.css">
|
2019-05-11 12:44:29 +02:00
|
|
|
<link rel="stylesheet" href="index_inscription.css">
|
2019-05-09 16:35:10 +02:00
|
|
|
<script src="inscription.js"></script>
|
2019-05-11 12:44:29 +02:00
|
|
|
<title>Profil</title>
|
2019-05-09 16:35:10 +02:00
|
|
|
</head>
|
|
|
|
<body>
|
2019-05-17 06:34:13 +02:00
|
|
|
<?php require_once("ressources/navbarhtml.php"); ?>
|
2019-05-09 16:35:10 +02:00
|
|
|
<div id="formulaire">
|
|
|
|
<h1>Profil</h1>
|
2019-05-11 12:44:29 +02:00
|
|
|
<div id="divImgProfil">
|
|
|
|
<img id="imgProfil" src="<?php echo getPathImgProfil($mail); ?>">
|
|
|
|
</div>
|
2019-05-18 00:40:45 +02:00
|
|
|
<form method="post" action="profil.php" enctype="multipart/form-data">
|
2019-05-09 16:35:10 +02:00
|
|
|
<div class="line">
|
2019-05-18 00:40:45 +02:00
|
|
|
<label for="mail">Adresse mail : </label>
|
|
|
|
<input id="mail" class="form" type="email" maxlength="100" readonly value="<?php echo $user['mail']; ?>">
|
2019-05-09 16:35:10 +02:00
|
|
|
</div>
|
|
|
|
<div class="line">
|
2019-05-18 00:40:45 +02:00
|
|
|
<label for="login">Login : </label>
|
|
|
|
<input id="login" class="form" name="login" type="text" maxlength="50"
|
2019-05-17 06:34:13 +02:00
|
|
|
value="<?php echo $user['login']; ?>" required>
|
2019-05-09 16:35:10 +02:00
|
|
|
</div>
|
|
|
|
<div class="line">
|
2019-05-11 12:44:29 +02:00
|
|
|
<label for="password">Mot de passe : </label>
|
2019-05-17 06:34:13 +02:00
|
|
|
<input class="form" id="password" name="password" type="password" maxlength="50"
|
|
|
|
value="<?php echo $user['passwd']; ?>" required>
|
2019-05-11 12:44:29 +02:00
|
|
|
</div>
|
|
|
|
<div class="line">
|
|
|
|
<label for="confirmation">Confirmation : </label>
|
2019-05-17 06:34:13 +02:00
|
|
|
<input class="form" id="confirmation" name="confirmation" type="password" maxlength="16"
|
|
|
|
value="<?php echo $user['passwd']; ?>" required>
|
2019-05-09 16:35:10 +02:00
|
|
|
</div>
|
|
|
|
<div class="line">
|
2019-05-18 00:40:45 +02:00
|
|
|
<label for="prenom">Prénom : </label>
|
|
|
|
<input id="prenom" class="form" name="prenom" type="text" maxlength="50"
|
2019-05-17 06:34:13 +02:00
|
|
|
value="<?php echo $user['prenom']; ?>" required>
|
2019-05-09 16:35:10 +02:00
|
|
|
</div>
|
|
|
|
<div class="line">
|
2019-05-18 00:40:45 +02:00
|
|
|
<label for="nom">Nom : </label>
|
|
|
|
<input id="nom" class="form" name="nom" type="text" maxlength="50" value="<?php echo $user['nom']; ?>"
|
2019-05-17 06:34:13 +02:00
|
|
|
required>
|
2019-05-09 16:35:10 +02:00
|
|
|
</div>
|
|
|
|
<div class="line">
|
2019-05-18 00:40:45 +02:00
|
|
|
<label for="dateN">Date de naissance : </label>
|
|
|
|
<input id="dateN" class="form" readonly="readonly" type="date"
|
2019-05-17 06:34:13 +02:00
|
|
|
value="<?php echo $user['datenaissance']; ?>" required>
|
2019-05-09 16:35:10 +02:00
|
|
|
</div>
|
|
|
|
<div class="line">
|
2019-05-18 00:40:45 +02:00
|
|
|
<label for="phone">Numéro de téléphone : </label>
|
|
|
|
<input id="phone" class="form" name="phone" type="tel" pattern="[0-9]{10}" maxlength="10"
|
2019-05-17 06:34:13 +02:00
|
|
|
value="<?php echo $user['telephone']; ?>" required>
|
2019-05-09 16:35:10 +02:00
|
|
|
</div>
|
|
|
|
<div class="line">
|
|
|
|
<label for="avatar">Image du Profil :</label>
|
2019-05-11 12:44:29 +02:00
|
|
|
<input type="file" id="avatar" class="form" name="avatar" accept="image/png, image/jpeg">
|
2019-05-09 16:35:10 +02:00
|
|
|
</div>
|
|
|
|
<?php
|
2019-05-17 06:34:13 +02:00
|
|
|
printError();
|
2019-05-09 16:35:10 +02:00
|
|
|
?>
|
2019-05-11 12:44:29 +02:00
|
|
|
<input id="submit" class="button" type="submit" value="Modifier">
|
2019-05-09 16:35:10 +02:00
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|