2019-05-20 17:15:51 +02:00
< ? php
session_start ();
require_once ( '../connexionBD.php' );
require_once ( '../ressources/user.php' );
2019-05-25 19:59:36 +02:00
require_once ( '../ressources/verifconnecte.php' );
2019-05-22 10:36:02 +02:00
require_once ( '../ressources/voiture.php' );
2019-05-20 17:15:51 +02:00
$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 ;
2019-05-25 19:59:36 +02:00
if ( isset ( $_POST [ 'submitadd' ])) { //si formulaire pressé appele la methode
2019-05-22 22:52:03 +02:00
$result = pg_query_params ( $db , " SELECT COUNT(*), matricule FROM voiture WHERE mail = $ 1 GROUP BY matricule; " , array ( $mail ));
$row = pg_fetch_array ( $result );
if ( $row [ 0 ] == 0 ){
addVoiture ( $db , $matricule , $marque , $modele , $nbplaces , $anneefab );
}
2019-05-20 17:15:51 +02:00
}
if ( isset ( $_POST [ 'submitchange' ])) {
changeVoiture ( $db , $matricule , $marque , $modele , $nbplaces , $anneefab );
}
$user = getUser ( $db , $mail );
if ( ! $user ){
header ( 'Location: profil.php?error=3' );
exit ();
}
2019-05-25 19:59:36 +02:00
if ( isset ( $_POST [ 'login' ]) || isset ( $_FILES [ 'avatar' ])){ //si connecte ou si avatar de defini
if ( isset ( $_FILES [ 'avatar' ]) and ! empty ( $_FILES [ 'avatar' ][ 'name' ])) { //si avatar et pas de fichier au nom de l'utilisateur
$fic = $_FILES [ 'avatar' ]; //avatar envoyé par l'utilisateur
supprimerAvatar ( $mail ); //supprime l'avatar courant de l'utilisateur
$res = uploadAvatar ( $mail , $fic ); //enregistre l'avatar avec le mail de l'utilisateur
switch ( $res ){ //controle d'erreur de la fonction uploadAvatar
2019-05-20 17:15:51 +02:00
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-25 19:59:36 +02:00
if ( isset ( $_POST [ 'login' ]) && isset ( $_POST [ 'password' ]) && isset ( $_POST [ 'confirmation' ]) && isset ( $_POST [ 'prenom' ]) && isset ( $_POST [ 'nom' ]) && isset ( $_POST [ 'phone' ])) { //controle du remplissage du formulaire
$login = htmlentities ( pg_escape_string ( $_POST [ 'login' ])); //recupere la variable du formulaire
2019-05-20 17:15:51 +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' ]));
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 ();
}
?>
<! DOCTYPE html >
< html lang = " fr " >
< head >
< meta charset = " UTF-8 " >
< link rel = " stylesheet " href = " profil.css " >
< link rel = " stylesheet " href = " ../ressources/navbarhtml.css " >
2019-05-22 10:36:02 +02:00
< script src = " ../inscription/inscription.js " ></ script >
2019-05-20 17:15:51 +02:00
< title > Profil </ title >
</ head >
< body >
< ? php require_once ( " ../ressources/navbarhtml.php " ); ?>
< div id = " formulaire " >
< h1 > Profil de < ? php echo $user [ 'prenom' ]; ?> </h1>
< div id = " divImgProfil " >
< img id = " imgProfil " src = " <?php echo getPathImgProfil( $mail ); ?> " >
</ div >
< script type = " text/javascript " >
function visibilite ( thingId ){
var targetElement ;
var elements ;
targetElement = document . getElementById ( thingId ) ;
elements = document . getElementsByClassName ( " Element " )
for ( var i = 0 ; i < elements . length ; i ++ ){
if ( ! targetElement . isSameNode ( elements [ i ])){
elements [ i ] . style . display = " none " ;
}
}
if ( targetElement . style . display == " none " ){
targetElement . style . display = " " ;
}
else {
targetElement . style . display = " none " ;
}
}
</ script >
< ul class = " profil-nav " >
< li class = " FT " >< a href = " " onclick = " javascript:visibilite('profilgeneral'); return false; " > Profil général </ a ></ li >
< li class = " FT " >< a href = " " onclick = " javascript:visibilite('profilvoiture'); return false; " > Profil voiture </ a ></ li >
</ ul >
< div id = " profilgeneral " class = " Element " style = " display:none; " >
< form method = " post " action = " profil.php " enctype = " multipart/form-data " >
< div class = " line " >
< label for = " mail " > Adresse mail : </ label >
< input id = " mail " class = " form " type = " email " maxlength = " 100 " readonly value = " <?php echo $user['mail'] ; ?> " >
</ div >
< div class = " line " >
< label for = " login " > Login : </ label >
< input id = " login " class = " form " name = " login " type = " text " maxlength = " 50 "
value = " <?php echo $user['login'] ; ?> " required >
</ div >
< div class = " line " >
< label for = " password " > Mot de passe : </ label >
< input class = " form " id = " password " name = " password " type = " password " maxlength = " 50 "
value = " <?php echo $user['passwd'] ; ?> " required >
</ div >
< div class = " line " >
< label for = " confirmation " > Confirmation : </ label >
< input class = " form " id = " confirmation " name = " confirmation " type = " password " maxlength = " 16 "
value = " <?php echo $user['passwd'] ; ?> " required >
</ div >
< div class = " line " >
< label for = " prenom " > Prénom : </ label >
< input id = " prenom " class = " form " name = " prenom " type = " text " maxlength = " 50 "
value = " <?php echo $user['prenom'] ; ?> " required >
</ div >
< div class = " line " >
< label for = " nom " > Nom : </ label >
< input id = " nom " class = " form " name = " nom " type = " text " maxlength = " 50 " value = " <?php echo $user['nom'] ; ?> "
required >
</ div >
< div class = " line " >
< label for = " dateN " > Date de naissance : </ label >
< input id = " dateN " class = " form " readonly = " readonly " type = " date "
value = " <?php echo $user['datenaissance'] ; ?> " required >
</ div >
< div class = " line " >
< 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 "
value = " <?php echo $user['telephone'] ; ?> " required >
</ div >
< div class = " line " >
< label for = " avatar " > Image du Profil :</ label >
< input type = " file " id = " avatar " class = " form " name = " avatar " accept = " image/png, image/jpeg " >
</ div >
2019-05-22 15:33:25 +02:00
< ? php getErrorProfil ( $_GET [ 'error' ]); ?>
2019-05-20 17:15:51 +02:00
< input id = " submit " class = " button " type = " submit " value = " Modifier " >
</ form >
</ div >
< div id = " profilvoiture " class = " Element " style = " display:none; " >
< script type = " text/javascript " >
function ShowTab ( E ) {
document . getElementById ( " addVoiture " ) . style . display = ( E == 1 ) ? 'block' : 'none' ;
document . getElementById ( " changeVoiture " ) . style . display = ( E == 2 ) ? 'block' : 'none' ;
document . getElementById ( " showVoiture " ) . style . display = ( E == 3 ) ? 'block' : 'none' ;
}
</ script >
< form id = " choixFormeTestVoiture " >
< div >
< input type = " radio " name = " TabCheck " onclick = " ShowTab(1) " /> Ajouter une voiture
< input type = " radio " name = " TabCheck " onclick = " ShowTab(2) " /> Modifier ma voiture
< input type = " radio " name = " TabCheck " onclick = " ShowTab(3) " /> Afficher ma voiture
</ div >
</ form >
< div id = " addVoiture " style = " display: none; " >
< h1 > Ajouter une voiture </ h1 >
< fieldset >
< form action = " profil.php " method = " post " >
< table >
< tr >
< td >< p > matricule :</ p ></ td >
< td >< input type = " text " name = " matricule " /></ td >
</ tr >
< tr >
< td >< p > marque :</ p ></ td >
< td >< input type = " text " name = " marque " /></ td >
</ tr >
< tr >
< td >< p > modele :</ p ></ td >
< td >< input type = " text " name = " modele " /></ td >
</ tr >
< tr >
< td >< p > nombre de places :</ p ></ td >
< td >< input type = " number " maxlength = " 1 " name = " nbplaces " /></ td >
</ tr >
< tr >
< td >< p > année de fabrication :</ p ></ td >
< td >< input type = " number " nmaxlength = " 4 " name = " anneefab " /></ td >
</ tr >
< tr >
< td >< p >< input type = " submit " name = " submitadd " value = " ajouter une voiture " ></ td >
</ tr >
</ table >
</ form >
</ fieldset >
</ div >
< div id = " changeVoiture " style = " display: none; " >
< h1 > Modifier une voiture </ h1 >
< fieldset >
< form action = " profil.php " method = " post " >
< table >
< tr >
< td >< p > matricule :</ p ></ td >
< td >< input type = " text " name = " matricule " /></ td >
</ tr >
< tr >
< td >< p > marque :</ p ></ td >
< td >< input type = " text " name = " marque " /></ td >
</ tr >
< tr >
< td >< p > modele :</ p ></ td >
< td >< input type = " text " name = " modele " /></ td >
</ tr >
< tr >
< td >< p > nombre de places :</ p ></ td >
< td >< input type = " number " maxlength = " 1 " name = " nbplaces " /></ td >
</ tr >
< tr >
< td >< p > année de fabrication :</ p ></ td >
< td >< input type = " number " nmaxlength = " 4 " name = " anneefab " /></ td >
</ tr >
< tr >
< td >< p >< input type = " submit " name = " submitchange " value = " modifier une voiture " ></ td >
</ tr >
</ table >
</ form >
</ fieldset >
</ div >
< div id = " showVoiture " style = " display: none; " >
< h1 > Afficher ma voiture </ h1 >
< fieldset >
< form action = " profil.php " method = " post " >
< table >
< tr >
< td >< p >< input type = " submit " name = " submitshow " value = " afficher ma voiture " ></ p ></ td >
2019-05-22 10:36:02 +02:00
</ tr >
< tr >
< td >< ? php if ( isset ( $_POST [ 'submitshow' ])) { showVoiture ( $db ); } ?> </td>
2019-05-20 17:15:51 +02:00
</ tr >
</ table >
</ form >
</ fieldset >
</ div >
</ div >
</ body >
</ html >