2019-05-18 00:40:45 +02:00
< ? php
2019-05-22 15:33:25 +02:00
//geterror de l'index
2019-05-22 22:52:03 +02:00
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 )
{
2019-05-22 13:56:52 +02:00
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. " ;
}
}
2019-05-22 22:52:03 +02:00
function authentification ( $db , $mail , $password )
{
2019-05-22 13:56:52 +02:00
$result = pg_query_params ( $db , " SELECT * FROM Utilisateur WHERE mail = $ 1; " , array ( $mail ));
2019-05-22 22:52:03 +02:00
if ( $result ) {
2019-05-22 13:56:52 +02:00
$row = pg_fetch_array ( $result );
return ( strcmp ( $row [ " passwd " ], $password )) == 0 ;
}
return false ;
}
2019-05-22 22:52:03 +02:00
function loginChange ( $user , $login )
{
2019-05-18 00:40:45 +02:00
return strcmp ( $user [ 'login' ], $login );
}
2019-05-22 22:52:03 +02:00
function isLoginUniqueModifier ( $db , $mail , $login )
{
2019-05-18 00:40:45 +02:00
$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 ;
}
2019-05-22 22:52:03 +02:00
function modifierLogin ( $db , $mail , $login )
{
2019-05-18 00:40:45 +02:00
$result = pg_query_params ( $db , " UPDATE Utilisateur SET login = $ 1 WHERE mail = $ 2; " , array ( $login , $mail ));
return $result ;
}
2019-05-22 22:52:03 +02:00
function modifierUtilisateur ( $db , $mail , $prenom , $nom , $password , $phone )
{
2019-05-18 00:40:45 +02:00
$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 ;
}
2019-05-22 22:52:03 +02:00
function getUser ( $db , $mail )
{
2019-05-18 00:40:45 +02:00
$result = pg_query_params ( $db , " SELECT * FROM Utilisateur WHERE mail = $ 1; " , array ( $mail ));
return pg_fetch_array ( $result );
}
2019-05-22 22:52:03 +02:00
function getPrenom ( $db , $mail )
{
2019-05-18 00:40:45 +02:00
$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 ;
}
2019-05-22 22:52:03 +02:00
function getLogin ( $db , $mail )
{
2019-05-18 00:40:45 +02:00
$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 ;
}
2019-05-22 22:52:03 +02:00
function getPathImgProfilTableau ( $mail )
{
2019-05-21 16:06:03 +02:00
$list = scandir ( " ../imageProfil " );
2019-05-18 00:40:45 +02:00
foreach ( $list as $entry ) {
if ( strpos ( $entry , $mail ) !== false ) {
return " ../imageProfil/ $entry " ;
}
}
return " ../imageProfil/default.svg " ;
}
2019-05-22 22:52:03 +02:00
function getPathImgProfil ( $mail )
{
2019-05-21 16:06:03 +02:00
$list = scandir ( " ../imageProfil " );
2019-05-18 00:40:45 +02:00
foreach ( $list as $entry ) {
if ( strpos ( $entry , $mail ) !== false ) {
2019-05-21 16:06:03 +02:00
return " ../imageProfil/ $entry " ;
2019-05-18 00:40:45 +02:00
}
}
2019-05-20 17:15:51 +02:00
return " ../imageProfil/default.svg " ;
2019-05-18 00:40:45 +02:00
}
2019-05-22 22:52:03 +02:00
function supprimerAvatar ( $mail )
{
2019-05-21 16:06:03 +02:00
$list = scandir ( " ../imageProfil " );
2019-05-18 00:40:45 +02:00
foreach ( $list as $entry ) {
if ( strpos ( $entry , $mail ) !== false ) {
2019-05-21 16:06:03 +02:00
unlink ( " ../imageProfil/ $entry " );
2019-05-18 00:40:45 +02:00
}
}
}
2019-05-22 22:52:03 +02:00
function isMailUnique ( $db , $mail )
{
2019-05-18 00:40:45 +02:00
$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 ;
}
2019-05-22 22:52:03 +02:00
function isLoginUnique ( $db , $login )
{
2019-05-18 00:40:45 +02:00
$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 ;
}
2019-05-22 22:52:03 +02:00
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 ;
2019-05-18 00:40:45 +02:00
}
2019-05-22 22:52:03 +02:00
function uploadAvatar ( $mail , $fic )
{
2019-05-18 00:40:45 +02:00
$tmp = explode ( '.' , $fic [ 'name' ]);
$extension = end ( $tmp );
2019-05-20 17:15:51 +02:00
$target_file = " ../imageProfil/ $mail . $extension " ;
2019-05-18 00:40:45 +02:00
$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 {
2019-05-22 22:52:03 +02:00
if ( ! move_uploaded_file ( $file_tmp , $target_file )) {
2019-05-18 00:40:45 +02:00
return - 3 ;
}
}
return 0 ;
2019-05-20 17:15:51 +02:00
}
2019-05-22 10:36:02 +02:00
2019-05-22 22:52:03 +02:00
function deluser ( $db , $delmail )
{
/*
$requete = " UPDATE public.utilisateur SET (mail, passwd, prenom, nom, login, telephone, datenaissance, estadmin) = ('utilisateur_supprime@local', '', '', '', 'utilisateur_supprime', '', to_date('1970/01/01','YYYY/MM/DD'), false) WHERE mail = ' " . $delmail . " '; " ;
marche pas
ERROR : duplicate key value violates unique constraint " pk_utilisateur "
DETAIL : Key ( mail ) = ( utilisateur_supprime @ local ) already exists .
*/
2019-05-22 13:56:52 +02:00
2019-05-22 22:52:03 +02:00
/*
a faire = array ( '' => , ); Delete l ' utilisateur du reste de la base
*/
$requete = " UPDATE trajet SET mailproposition = 'utilisateur_supprime@local' WHERE mailproposition = $delmail ; " ;
pg_query ( $db , $requete );
$requete = " UPDATE reserver SET mailutilisateur = 'utilisateur_supprime@local' WHERE mailutilisateur = $delmail ; " ;
pg_query ( $db , $requete );
$requete = " DELETE FROM avis WHERE mailemetteur = $delmail ; " ;
pg_query ( $db , $requete );
$requete = " DELETE FROM voiture WHERE mail = $delmail ; " ;
pg_query ( $db , $requete );
$requete = " DELETE FROM utilisateur WHERE mail = $delmail ; " ;
pg_query ( $db , $requete );
2019-05-22 13:56:52 +02:00
2019-05-22 10:36:02 +02:00
}
2019-05-22 22:52:03 +02:00
2019-05-21 16:06:03 +02:00
?>