2019-04-18 18:37:23 +02:00
< ? php
2019-05-10 10:23:27 +02:00
require_once ( '../connexionBD.php' );
session_start ();
//Si on est pas connecté redirection vers la page de connexion
2019-05-17 06:24:11 +02:00
if ( ! isset ( $_SESSION [ 'mail' ])) {
2019-05-10 10:23:27 +02:00
header ( 'Location: ../index.php' );
exit ();
}
$mail = $_SESSION [ 'mail' ];
2019-05-09 16:48:26 +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-17 06:24:11 +02:00
if ( isset ( $_POST [ 'submitadd' ])) {
addVoiture ( $db , $matricule , $marque , $modele , $nbplaces , $anneefab );
2019-05-09 16:48:26 +02:00
}
2019-05-17 06:24:11 +02:00
if ( isset ( $_POST [ 'submitchange' ])) {
changeVoiture ( $db , $matricule , $marque , $modele , $nbplaces , $anneefab );
2019-05-09 16:48:26 +02:00
}
2019-05-17 06:24:11 +02:00
if ( isset ( $_POST [ 'submitshow' ])) {
showVoiture ( $db );
2019-05-09 16:48:26 +02:00
}
2019-05-17 06:24:11 +02:00
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 null ;
2019-05-09 16:48:26 +02:00
}
2019-05-17 06:24:11 +02:00
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 null ;
2019-05-09 16:48:26 +02:00
}
2019-05-17 06:24:11 +02:00
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 ));
if ( $result ) {
$row = pg_fetch_array ( $result );
return $row [ 0 ];
}
return 0 ;
2019-05-09 16:48:26 +02:00
}
2019-05-17 06:24:11 +02:00
function getTrajetsReserves ( $db , $mail )
{
$result = pg_query_params ( $db , " SELECT COUNT(*) FROM trajet tr, reserver r WHERE r.codetrajet = tr.codetrajet AND mailutilisateur = $ 1 AND etatres != 'Annulée' AND estAnnule = false AND datedepart >= current_date; " , array ( $mail ));
if ( $result ) {
$row = pg_fetch_array ( $result );
return $row [ 0 ];
}
return 0 ;
2019-05-09 16:48:26 +02:00
}
2019-05-17 06:24:11 +02:00
function getMessagesNonLus ( $db , $mail )
{
$result = pg_query_params ( $db , " SELECT COUNT(*) from Message WHERE mailRecepteur = $ 1 AND estLu = FALSE; " , array ( $mail ));
if ( $result ) {
$row = pg_fetch_array ( $result );
$login = $row [ 0 ];
return $login ;
}
2019-05-09 16:48:26 +02:00
}
2019-05-17 06:24:11 +02:00
function getAvisNonLus ( $db , $mail )
{
global $db ;
$result = pg_query_params ( $db , " SELECT COUNT(tr.mailProposition) FROM Trajet tr, Avis av WHERE tr.codeTrajet = av.codeTrajet AND av.estLu = false AND tr.mailProposition = $ 1; " , array ( $mail ));
if ( $result ) {
$row = pg_fetch_array ( $result );
$login = $row [ 0 ];
return $login ;
}
2019-05-09 16:48:26 +02:00
}
2019-05-17 06:24:11 +02:00
function getPathImgProfil ( $mail )
{
if ( file_exists ( " ../imageProfil/ $mail .png " )) {
return " ../imageProfil/ $mail .png " ;
}
return " ../imageProfil/default.svg " ;
2019-05-09 16:48:26 +02:00
}
2019-05-17 06:24:11 +02:00
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 );
2019-05-09 16:48:26 +02:00
}
2019-05-17 06:24:11 +02:00
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 );
2019-05-09 16:48:26 +02:00
}
2019-05-17 06:24:11 +02:00
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' ] . " <br> " ;
echo " marque = " . $res [ 'marque' ] . " <br> " ;
echo " modele = " . $res [ 'modele' ] . " <br> " ;
echo " nombre de places = " . $res [ 'nbplaces' ] . " <br> " ;
echo " année de fabrication = " . $res [ 'anneefab' ] . " <br> " ;
}
2019-04-28 14:53:08 +02:00
}
2019-05-09 16:48:26 +02:00
}
2019-05-17 06:24:11 +02:00
2019-04-18 18:37:23 +02:00
?>
2019-05-16 11:23:12 +02:00
<! DOCTYPE html >
< html lang = " fr " >
< head >
2019-05-17 06:24:11 +02:00
< meta charset = " UTF-8 " >
< link rel = " stylesheet " href = " tableauBord.css " >
< link rel = " stylesheet " href = " ../ressources/navbarhtml.css " >
< link rel = " icon " type = " image/png " href = " " />
< title > Tableau de bord </ title >
2019-05-16 11:23:12 +02:00
</ head >
< body >
2019-05-17 06:24:11 +02:00
< ? php require ( '../ressources/navbarhtml.php' ); ?>
< 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' ;
2019-05-09 16:48:26 +02:00
}
2019-05-17 06:24:11 +02:00
</ script >
< div id = " content " >
2019-04-28 14:53:08 +02:00
< div id = " tableauBord " >
2019-05-17 06:24:11 +02:00
< h1 > Bienvenue < ? php echo getLogin ( $db , $mail ); ?> </h1>
< div id = " divImgProfil " >
< img id = " imgProfil " src = " <?php echo getPathImgProfil( $mail ); ?> " >
</ div >
< div id = " trajet " >
< a class = " btnTrajet " href = " ../ah.php " > Déposer un trajet </ a >
< a id = " btnTrajet2 " class = " btnTrajet " href = " ../ah.php " > Rechercher un trajet </ a >
2019-04-28 14:53:08 +02:00
</ div >
2019-05-17 06:24:11 +02:00
< div id = " recap " >
< div class = " recapLine " >
< img class = " recapIcon " src = " ../car.png " >
< p > Vous avez < ? php echo getTrajetsProposes ( $db , $mail ); ?> trajets proposés à effectuer.</p>
</ div >
< div class = " recapLine " >
< img class = " recapIcon " src = " ../car.png " >
< p > Vous avez < ? php echo getTrajetsReserves ( $db , $mail ); ?> trajets réservés à effectuer.</p>
</ div >
< div class = " recapLine " >
< img class = " recapIcon " src = " ../mail.svg " >
< p > Vous avez < ? php echo getMessagesNonLus ( $db , $mail ); ?> messages non lus.</p>
</ div >
< div class = " recapLine " >
< img class = " recapIcon " src = " ../star.png " >
< p > Vous avez < ? php echo getAvisNonLus ( $db , $mail ); ?> avis non lus.</p>
</ div >
2019-04-28 14:53:08 +02:00
</ div >
2019-05-17 06:24:11 +02:00
< 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 = " tableauBord.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 >
2019-04-28 14:53:08 +02:00
</ div >
2019-05-17 06:24:11 +02:00
< div id = " changeVoiture " style = " display: none; " >
< h1 > Modifier une voiture </ h1 >
< fieldset >
< form action = " tableauBord.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 >
2019-05-07 01:03:54 +02:00
</ div >
2019-05-17 06:24:11 +02:00
< div id = " showVoiture " style = " display: none; " >
< h1 > Afficher ma voiture </ h1 >
< fieldset >
< form action = " tableauBord.php " method = " post " >
< table >
< tr >
< td >< p >< input type = " submit " name = " submitshow " value = " afficher ma voiture " ></ td >
</ tr >
</ table >
</ form >
</ fieldset >
2019-05-07 01:03:54 +02:00
</ div >
2019-04-18 18:37:23 +02:00
</ div >
2019-05-17 06:24:11 +02:00
</ div >
2019-04-18 18:37:23 +02:00
</ body >
2019-05-07 01:03:54 +02:00
</ html >