|
|
|
<?php
|
|
|
|
//geterror de l'index
|
|
|
|
function getErrorIndex($code)
|
|
|
|
{
|
|
|
|
switch ($code) {
|
|
|
|
case 1:
|
|
|
|
return "Adresse mail ou mot de passe invalide.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 getErrorInscription($code)
|
|
|
|
{
|
|
|
|
switch ($code) {
|
|
|
|
case 1:
|
|
|
|
return "L'adresse mail est invalide.";
|
|
|
|
case 2:
|
|
|
|
return "Cette adresse est déjà associée à un compte.";
|
|
|
|
case 3:
|
|
|
|
return "Ce login est déjà associé à un compte.";
|
|
|
|
case 4:
|
|
|
|
return "Le fichier envoyé doit être une image au format PNG.";
|
|
|
|
case 5:
|
|
|
|
return "La taille de l'image ne doit pas dépasser 2 MB.";
|
|
|
|
case 6:
|
|
|
|
return "Erreur lors de la création du compte.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function authentification($db, $mail, $password)
|
|
|
|
{
|
|
|
|
$result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE mail = $1;", array($mail));
|
|
|
|
if ($result) {
|
|
|
|
$row = pg_fetch_array($result);
|
|
|
|
return (strcmp($row["passwd"], $password)) == 0;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function loginChange($user, $login)
|
|
|
|
{
|
|
|
|
return strcmp($user['login'], $login);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isLoginUniqueModifier($db, $mail, $login)
|
|
|
|
{
|
|
|
|
$result = pg_query_params($db, "SELECT login FROM Utilisateur WHERE login = $1 AND mail != $2;", array($login, $mail));
|
|
|
|
if ($result) {
|
|
|
|
$row = pg_fetch_array($result);
|
|
|
|
return (strcmp($row['login'], $login) != 0);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function modifierLogin($db, $mail, $login)
|
|
|
|
{
|
|
|
|
$result = pg_query_params($db, "UPDATE Utilisateur SET login = $1 WHERE mail = $2;", array($login, $mail));
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function modifierUtilisateur($db, $mail, $prenom, $nom, $password, $phone)
|
|
|
|
{
|
|
|
|
$result = pg_query_params($db, "UPDATE Utilisateur SET prenom = $1, nom = $2, telephone = $3 , passwd = $4 WHERE mail = $5;", array($prenom, $nom, $phone, $password, $mail));
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getUser($db, $mail)
|
|
|
|
{
|
|
|
|
$result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE mail = $1;", array($mail));
|
|
|
|
return pg_fetch_array($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPrenom($db, $mail)
|
|
|
|
{
|
|
|
|
$result = pg_query_params($db, "SELECT prenom from Utilisateur WHERE mail = $1;", array($mail));
|
|
|
|
if ($result) {
|
|
|
|
$row = pg_fetch_array($result);
|
|
|
|
$prenom = $row[0];
|
|
|
|
return $prenom;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getLogin($db, $mail)
|
|
|
|
{
|
|
|
|
$result = pg_query_params($db, "SELECT login from Utilisateur WHERE mail = $1;", array($mail));
|
|
|
|
if ($result) {
|
|
|
|
$row = pg_fetch_array($result);
|
|
|
|
$login = $row[0];
|
|
|
|
return $login;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPathImgProfilTableau($mail)
|
|
|
|
{
|
|
|
|
//Récuperer le fichier contenant $mail dans son nom
|
|
|
|
$list = scandir("../imageProfil");
|
|
|
|
foreach ($list as $entry) {
|
|
|
|
if (strpos($entry, $mail) !== false) {
|
|
|
|
return "../imageProfil/$entry";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "../imageProfil/default.svg";
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPathImgProfil($mail)
|
|
|
|
{
|
|
|
|
//Récuperer le fichier contenant $mail dans son nom
|
|
|
|
$list = scandir("../imageProfil");
|
|
|
|
foreach ($list as $entry) {
|
|
|
|
if (strpos($entry, $mail) !== false) {
|
|
|
|
return "../imageProfil/$entry";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "../imageProfil/default.svg";
|
|
|
|
}
|
|
|
|
|
|
|
|
function supprimerAvatar($mail)
|
|
|
|
{
|
|
|
|
//Supprimer le fichier contenant $mail dans son nom
|
|
|
|
$list = scandir("../imageProfil");
|
|
|
|
foreach ($list as $entry) {
|
|
|
|
if (strpos($entry, $mail) !== false) {
|
|
|
|
unlink("../imageProfil/$entry");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function isMailUnique($db, $mail)
|
|
|
|
{
|
|
|
|
$result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE mail = $1;", array($mail));
|
|
|
|
if ($result) {
|
|
|
|
$row = pg_fetch_array($result);
|
|
|
|
return (strcmp($row['mail'], $mail) != 0);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isLoginUnique($db, $login)
|
|
|
|
{
|
|
|
|
$result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE login = $1;", array($login));
|
|
|
|
if ($result) {
|
|
|
|
$row = pg_fetch_array($result);
|
|
|
|
return (strcmp($row['login'], $login) != 0);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function creerUtilisateur($db, $mail, $password, $prenom, $nom, $login, $phone, $dateN)
|
|
|
|
{
|
|
|
|
$result = pg_query_params($db, "INSERT INTO Utilisateur VALUES ($1, $2, $3, $4, $5, $6, to_date($7, 'YYYY/MM/DD'), false);", array($mail, $password, $prenom, $nom, $login, $phone, $dateN));
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function uploadAvatar($mail, $fic)
|
|
|
|
{
|
|
|
|
$tmp = explode('.', $fic['name']);
|
|
|
|
$extension = end($tmp);
|
|
|
|
$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'))) {
|
|
|
|
return -1;
|
|
|
|
} else if ($fic['size'] > 2 * 1024 * 1024) {
|
|
|
|
return -2;
|
|
|
|
} else {
|
|
|
|
if (!move_uploaded_file($file_tmp, $target_file)) {
|
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function deluser($db, $delmail)
|
|
|
|
{
|
|
|
|
//Remplacer le mail de l'utilisateur à supprimer par l'utilisateur utilisateur_supprime@local
|
|
|
|
$requete = "UPDATE trajet SET mailproposition = $1 WHERE mailproposition = $2;";
|
|
|
|
$result1 = pg_query_params($db, $requete, array('utilisateur_supprime@local', $delmail));
|
|
|
|
$requete = "UPDATE reserver SET mailutilisateur = $1 WHERE mailutilisateur = $2;";
|
|
|
|
$result2 = pg_query_params($db, $requete, array('utilisateur_supprime@local', $delmail));
|
|
|
|
$requete = "DELETE FROM avis WHERE mailemetteur = $1;";
|
|
|
|
$result3 = pg_query_params($db, $requete, array($delmail));
|
|
|
|
$requete = "UPDATE voiture SET mail = $1 WHERE mail = $2;";
|
|
|
|
$result4 = pg_query_params($db, $requete, array('utilisateur_supprime@local', $delmail));
|
|
|
|
//Supprimer l'utilisateur $mail
|
|
|
|
$requete = "DELETE FROM utilisateur WHERE mail = $1;";
|
|
|
|
$result5 = pg_query_params($db, $requete, array($delmail));
|
|
|
|
return $result1 && $result2 && $result3 && $result4 && $result5;
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|