<?php
session_start();

if(!isset($_SESSION["etudiant_i"]) OR !isset($_SESSION["eta_i"])){
	header("Location:./");
}

include_once('Library/Basededonnees.php');

$DB_DATABASEG = 'africawebstudent_universite';
$databaseg = new Basededonnees($DB_DATABASEG);
$bddg = $databaseg->getBdd();

$DB_DATABASE = $_SESSION["DB_DATABASE"];
$database = new Basededonnees($DB_DATABASE);
$bdd = $database->getBdd();

$sql2 = "SELECT * FROM `tabetudiant` where matricule= :matri";
$statement2 = $bdd->prepare($sql2);
$statement2->bindParam(':matri', $_SESSION["etudiant_i"], PDO::PARAM_STR);
$statement2->execute();
$row2=$statement2->fetch(PDO::FETCH_ASSOC);
$cheminPhoto 		= $row2['cheminPhoto'];	
$nom 				= $row2['nom'];	
$prenom 			= $row2['prenom'];	
$nationalite 		= $row2['nationalite'];	
$description 		= '';	

$sql1 = "SELECT * FROM `users_student` where matricule= :matri";
$statement1 = $bddg->prepare($sql1);
$statement1->bindParam(':matri', $_SESSION['etudiant_i'], PDO::PARAM_STR);
$statement1->execute();
$row1=$statement1->fetch(PDO::FETCH_ASSOC);
$email1 			= $row1['email'];	
$phone1 			= $row1['phone'];	
$password 			= $row1['password'];
$type_user			= $row1['type_user'];


?>

<?php
	if(isset($_POST['mailp']) AND isset($_POST['phonep'])){
		$matricule=$_POST['matricule'];
		$mail=htmlspecialchars($_POST['mailp']);
		$motpass=htmlspecialchars($_POST['motpass1']);
		$description=htmlspecialchars($_POST['description']);
		$phone=htmlspecialchars($_POST['phonep']);

		if($motpass != '') {
		    $up = 1;
    		date_default_timezone_set('Africa/Porto-Novo');
    		$date = date('Y-m-d H:i:s', time());
			$sql1 = 'UPDATE users_student SET password = :password, updated_at = :update, updatepssword = :up WHERE matricule= :matricule';
			$motpass = password_hash($motpass, PASSWORD_DEFAULT);//crypt($motpass, 'superhashcode');
			$statement1 = $bddg->prepare($sql1);
			$statement1->bindParam(':password', $motpass, PDO::PARAM_STR);
			$statement1->bindParam(':update', $date, PDO::PARAM_STR);
			$statement1->bindParam(':up', $up, PDO::PARAM_STR);
			$statement1->bindParam(':matricule',  $matricule, PDO::PARAM_STR);
			$statement1->execute();
		}
		try{
			$sql2 = 'UPDATE users_student SET email = :mail, phone = :phone WHERE matricule= :matricule';
			$statement2 = $bddg->prepare($sql2);
			$statement2->bindParam(':mail', $mail, PDO::PARAM_STR);
			$statement2->bindParam(':phone',  $phone, PDO::PARAM_STR);
			$statement2->bindParam(':matricule',  $matricule, PDO::PARAM_STR);
			$statement2->execute();
		}catch(PDOException  $e ){
			//exit(notifierErreur($e->getCode( ), $e->getMessage( ), ' Matricule : '.$matricule));
		}
		echo '<meta http-equiv="refresh" content="0">';
	}else{
	}
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" type="image/png" sizes="16x16" href="../plugins/images/favicon.png">
    <title>GestStudent Résultats</title>
    <!-- Bootstrap Core CSS -->
    <link href="bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- animation CSS -->
    <link href="css/animate.css" rel="stylesheet">
    <!-- Menu CSS -->
    <link href="https://progiciel.africawebstudent.org/plugins/bower_components/sidebar-nav/dist/sidebar-nav.min.css" rel="stylesheet">
    <!-- Popup CSS -->
    <link href="https://progiciel.africawebstudent.org/plugins/bower_components/Magnific-Popup-master/dist/magnific-popup.css" rel="stylesheet">
    <!-- Custom CSS -->
    <link href="css/style.css" rel="stylesheet">
    <!-- color CSS -->
    <link href="css/colors/megna-dark.css" id="theme" rel="stylesheet">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
        <style>

            body {
                font-family: "Lucida Sans", Verdana, sans-serif;
                background-size:cover;
                padding-top:0px;
            }

            .white-boxx{background:#fff;padding:25px;margin-bottom:30px;border: 3px solid rgba(255, 0, 0, 0.55);}
            .white-box{background:#fff;padding:25px;margin-bottom:30px;border: 3px solid rgba(0, 0, 255, 1);}
        </style>
</head>

<body class="fix-header">
    <!-- ============================================================== -->
    <!-- Preloader -->
    <!-- ============================================================== -->
    <div class="preloader">
        <svg class="circular" viewBox="25 25 50 50">
            <circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10" />
        </svg>
    </div>
    <!-- ============================================================== -->
    <!-- Wrapper -->
    <!-- ============================================================== -->
    <div id="wrapper">
        <!-- ============================================================== -->
        <!-- Topbar header - style you can find in pages.scss -->
        <!-- ============================================================== -->
        <nav class="navbar navbar-default navbar-static-top m-b-0">
            <div class="navbar-header">
                <div class="top-left-part">
                    <!-- Logo -->
                    <a class="logo" href="accueil.php">
                        <!-- Logo icon image, you can use font-icon also --><b><span class="hidden-xs">
                        <!--This is light logo icon--><img src="https://progiciel.africawebstudent.org/plugins/images/gsr2.png" alt="home" class="light-logo" />
						</span> </b>
					</a>
                </div>
                <!-- /Logo -->
                <!-- Search input and Toggle icon -->
                <ul class="nav navbar-top-links navbar-left">
                    <li><a href="javascript:void(0)" class="open-close waves-effect waves-light visible-xs"><i class="ti-close ti-menu"></i></a></li>
                    <!-- .Task dropdown -->
                
                    <!-- .Megamenu -->

                    <!-- /.Megamenu -->
                </ul>
                <ul class="nav navbar-top-links navbar-right pull-right">
                    <li>
                        <form role="search" class="app-search hidden-sm hidden-xs m-r-10">
                            <input type="text" placeholder="Search..." class="form-control"> <a href=""><i class="fa fa-search"></i></a> </form>
                    </li>
                    <li class="dropdown">
                        <?php
							include('include/affiche_identite.php');
                        ?>
                        <!-- /.dropdown-user -->
                    </li>
                    <!-- /.dropdown -->
                </ul>
            </div>
            <!-- /.navbar-header -->
            <!-- /.navbar-top-links -->
            <!-- /.navbar-static-side -->
        </nav>
        <!-- End Top Navigation -->
        <!-- ============================================================== -->
        <!-- Left Sidebar - style you can find in sidebar.scss  -->
        <!-- ============================================================== -->
        <div class="navbar-default sidebar" role="navigation">
            <div class="sidebar-nav">
                <div class="sidebar-head">
                    <h3><span class="fa-fw open-close"><i class="ti-menu hidden-xs"></i><i class="ti-close visible-xs"></i></span> <span class="hide-menu">Navigation</span></h3> </div>
                <ul class="nav" id="side-menu">
                    <li class="user-pro">
                        <a href="javascript:void(0)" class="waves-effect"><img src="img/profil.png" alt="user-img" class="img-circle"> <span class="hide-menu"><?php echo $infoEtudiant['nom'].'  '.$infoEtudiant['prenom']?> <span class="fa arrow"></span></span>
                        </a>
                    </li>
                    <li> <a href="accueil.php" class="waves-effect active"><i class="mdi mdi-av-timer fa-fw" data-icon="v"></i> <span class="hide-menu"> Accueil <span class="fa arrow"></span> <span class="label label-rouded label-inverse pull-right"></span></span></a>
                    </li>
                </ul>
            </div>
        </div>
        <!-- ============================================================== -->
        <!-- End Left Sidebar -->
        <!-- ============================================================== -->
        <!-- ============================================================== -->
        <!-- Page Content -->
        <!-- ============================================================== -->
        <div id="page-wrapper">
            <div class="container-fluid">
                <div class="row bg-title">
                    <div class="col-lg-3 col-md-4 col-sm-4 col-xs-12">
                        <h4 class="page-title">Profile page</h4> </div>
                    <div class="col-lg-9 col-sm-8 col-md-8 col-xs-12">
                        <button class="right-side-toggle waves-effect waves-light btn-info btn-circle pull-right m-l-20"><i class="ti-settings text-white"></i></button>
                        <a href="javascript: void(0);" target="_blank" class="btn btn-danger pull-right m-l-20 hidden-xs hidden-sm waves-effect waves-light">GestStudent v17.04</a>
                        <ol class="breadcrumb">
                            <li><a href="javascript:void(0)">Dashboard</a></li>
                            <li class="active">Profile page</li>
                        </ol>
                    </div>
                </div
                
                <!-- /.row -->
                <!-- .row -->
                <div class="row">
                    <div class="col-md-4 col-xs-12 hidden">
                        <div class="white-box">
                            <div class="user-bg"> <img width="100%" alt="user" src="../plugins/images/large/img1.jpg">
                                <div class="overlay-box">
                                    <div class="user-content">
                                        <a href="javascript:void(0)"><img src="../plugins/images/users/genu.jpg" class="thumb-lg img-circle" alt="img"></a>
                                        <h4 class="text-white">User Name</h4>
                                        <h5 class="text-white">info@myadmin.com</h5> </div>
                                </div>
                            </div>
                            <div class="user-btm-box">
                                <div class="col-md-4 col-sm-4 text-center">
                                    <p class="text-purple"><i class="ti-facebook"></i></p>
                                    <h1>258</h1> </div>
                                <div class="col-md-4 col-sm-4 text-center">
                                    <p class="text-blue"><i class="ti-twitter"></i></p>
                                    <h1>125</h1> </div>
                                <div class="col-md-4 col-sm-4 text-center">
                                    <p class="text-danger"><i class="ti-dribbble"></i></p>
                                    <h1>556</h1> </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-12">
                        <div class="white-box text-danger">
                            <?php echo $_SESSION['message'];?>
                        </div>
                        <div class="white-box">
                            <ul class="nav nav-tabs tabs customtab">
                                <li class="active tab">
                                    <a href="#home" data-toggle="tab"> <span class="visible-xs"><i class="fa fa-home"></i></span> <span class="hidden-xs">Activités</span> </a>
                                </li>
                                <li class="tab">
                                    <a href="#profile" data-toggle="tab"> <span class="visible-xs"><i class="fa fa-user"></i></span> <span class="hidden-xs">Profile</span> </a>
                                </li>
                                <li class="tab">
                                    <a href="#settings" data-toggle="tab" aria-expanded="false"> <span class="visible-xs"><i class="fa fa-cog"></i></span> <span class="hidden-xs">Settings</span> </a>
                                </li>
                            </ul>
                            <div class="tab-content">
                                <div class="tab-pane active" id="home">
                                    <div class="steamline">
										<?php
											$aff = 'YES';
											$id = $_SESSION['eta_i'];
											$sql0 = "SELECT * FROM `academique` where affiche= :aff and idEtablissement = :idEtablissement";
											$statement0 = $bdd->prepare($sql0);
											$statement0->bindParam(':aff', $aff, PDO::PARAM_STR);
											$statement0->bindParam(':idEtablissement', 	$id, PDO::PARAM_STR);
											$statement0->execute();
											$row0=$statement0->fetch(PDO::FETCH_ASSOC);										
											$acad 		= $row0['annee_acad'].'%';
											$matricule = $_SESSION["etudiant_i"];
	
											//$sql 	 = "SELECT * FROM `historique`  WHERE dateActivite LIKE ? AND matricule =?  AND operation !=? ORDER BY `dateActivite` DESC LIMIT 100";
											$sql 	 = "SELECT * FROM `historique`  WHERE matricule =?  AND operation NOT LIKE ? ORDER BY `dateActivite` DESC LIMIT 100";
										
											//$sql = "SELECT * from geststudent_r where annee_acad= :acad";
											$op = '%'."panneau de contrôle d'administration".'%';
											$statement = $bddg->prepare($sql);
											//$statement->bindParam(1, $acad, PDO::PARAM_STR);
											$statement->bindParam(1, $matricule, PDO::PARAM_STR);
											$statement->bindParam(2, $op, PDO::PARAM_STR);
											$statement->execute();
											$i = 0;
											if($statement->rowCount()) { 
												while($row=$statement->fetch(PDO::FETCH_ASSOC))  {
													/*$sql1 = "SELECT * FROM `users` where matricule= :matri";
													$statement1 = $bdd->prepare($sql1);
													$statement1->bindParam(':matri', $row['matricule'], PDO::PARAM_STR);
													$statement1->execute();
													$row1=$statement1->fetch(PDO::FETCH_ASSOC);
													$email 		= $row1['email'];	
													$phone 		= $row1['phone'];	
													$type_user 	= $row1['type_user'];
													$created_at 	= $row1['created_at'];													
													$idFiliere 	= $row['idFiliere']; */	
													
													$idActivite 		= $row['idActivite'];
													$adresseip 			= $row['adresseip'];
													$dateActivite 		= $row['dateActivite'];
													$operation 			= $row['operation'];//class=\"font-medium text-danger\"
																			
													$i++;
													echo "
													<div class=\"sl-item\">
														<div class=\"sl-left\"> $i </div>
														<div class=\"sl-right\">
															<div class=\"m-l-40\"><a href=\"javascript:void(0)\" class=\"text-info\">$operation : </a> <span class=\"sl-date \"><font color = red>$dateActivite</font></span>
																<p>Adresse ip de l'utilisateur: <a href=\"javascript:void(0)\"> $adresseip</a></p>
															</div>
														</div>
													</div>";	
												}
											}elseif(!$statement->rowCount()) {
											echo '
											<div class="col-md-0">
												<div class="modal-dialog">
													<div class="modal-content">
														<div class="modal-header">
															<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
															<h4 class="modal-title" id="myModalLabel">GestStudent</h4> 
														</div>
														<div class="modal-body text-danger text-center">
															<p>Aucune activité...</p>
														</div>
														
													</div>
													<!-- /.modal-content <div class="modal-footer">
															<a href="form-ajout-validateur.php"><button class="btn btn-info waves-effect"></i>OK</button></a>
														</div>-->
												</div>
											</div>
											';
											}											
										?>																		
                                    </div>
                                </div>
                                <div class="tab-pane" id="profile">
                                    <div class="row">
                                        <div class="col-md-3 col-xs-6 b-r"> <strong>Full Name</strong>
                                            <br>
                                            <p class="text-muted"><?php echo "$nom $prenom"; ?></p>
                                        </div>
                                        <div class="col-md-3 col-xs-6 b-r"> <strong>Mobile</strong>
                                            <br>
                                            <p class="text-muted"><?php echo "$phone1"; ?></p>
                                        </div>
                                        <div class="col-md-3 col-xs-6 b-r"> <strong>Email</strong>
                                            <br>
                                            <p class="text-muted"><?php echo "$email1"; ?></p>
                                        </div>
                                        <div class="col-md-3 col-xs-6"> <strong>Nationalité</strong>
                                            <br>
                                            <p class="text-muted"><?php echo "$nationalite"; ?></p>
                                        </div>
                                    </div>
                                    <hr>
                                    <p class="m-t-30"><?php echo "$description"; ?>.</p>
                                    <hr>
                                </div>
                                <div class="tab-pane" id="settings">
                                    <form id = "profileform" method = "POST" action = "profile.php" class="form-horizontal form-material"  data-toggle="validator">
                                        <div class="form-group">
                                            <label class="col-md-12">Matricule</label>
                                            <div class="col-md-12">
                                                <input readonly id = "matricule" type="text" value = "<?php echo $_SESSION["etudiant_i"]; ?>" class="form-control form-control-line" name="matricule"> </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-12">Full Name</label>
                                            <div class="col-md-12">
                                                <input readonly type="text" value = "<?php echo "$nom $prenom"; ?>" class="form-control form-control-line" name="nom" id="nom"> </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="mail" class="col-md-12">Email</label>
                                            <div class="col-md-12">
                                                <input type="email" value = "<?php echo "$email1"; ?>" class="form-control form-control-line" name="mailp" id="mailp"> </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-12">Password</label>
                                            <div class="col-md-6">
                                                <input type="password" value = "" class="form-control form-control-line"  data-toggle="validator"  data-minlength="10" name = "motpass1" id = "motpass1" placeholder="Password"> 
												<span class="help-block">Minimum of 10 characters</span>
											</div>
                                            <div class="col-md-6">
                                                <input type="password" value = "" class="form-control form-control-line"  data-match="#motpass1"  data-match-error="Whoops, these don't match" name = "motpass2" id = "motpass2"  placeholder="Confirm" > 
												<div class="help-block with-errors"></div>
											</div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-12">Phone No</label>
                                            <div class="col-md-12">
                                                <input type="text" id = "phonep" value = "<?php echo "$phone1"; ?>" class="form-control form-control-line" name = "phonep"> </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-12">Description</label>
                                            <div class="col-md-12">
                                                <textarea id = "description" rows="5" class="form-control form-control-line" name = "description"></textarea>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-sm-12">
                                                <button id = "profileupdate" type = "submit" class="btn btn-success">Update Profile</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /.row -->
                <!-- ============================================================== -->
                <!-- Right sidebar -->
                <!-- ============================================================== -->
                <!-- .right-sidebar -->
                <div class="right-sidebar">
                    <div class="slimscrollright">
                        <div class="rpanel-title"> Service Panel <span><i class="ti-close right-side-toggle"></i></span> </div>
                        <div class="r-panel-body">
                            <ul id="themecolors" class="m-t-20">
                                <li><b>With Light sidebar</b></li>
                                <li><a href="javascript:void(0)" data-theme="default" class="default-theme">1</a></li>
                                <li><a href="javascript:void(0)" data-theme="green" class="green-theme">2</a></li>
                                <li><a href="javascript:void(0)" data-theme="gray" class="yellow-theme">3</a></li>
                                <li><a href="javascript:void(0)" data-theme="blue" class="blue-theme">4</a></li>
                                <li><a href="javascript:void(0)" data-theme="purple" class="purple-theme">5</a></li>
                                <li><a href="javascript:void(0)" data-theme="megna" class="megna-theme">6</a></li>
                                <li><b>With Dark sidebar</b></li>
                                <br/>
                                <li><a href="javascript:void(0)" data-theme="default-dark" class="default-dark-theme">7</a></li>
                                <li><a href="javascript:void(0)" data-theme="green-dark" class="green-dark-theme">8</a></li>
                                <li><a href="javascript:void(0)" data-theme="gray-dark" class="yellow-dark-theme">9</a></li>
                                <li><a href="javascript:void(0)" data-theme="blue-dark" class="blue-dark-theme">10</a></li>
                                <li><a href="javascript:void(0)" data-theme="purple-dark" class="purple-dark-theme">11</a></li>
                                <li><a href="javascript:void(0)" data-theme="megna-dark" class="megna-dark-theme working">12</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <!-- ============================================================== -->
                <!-- End Right sidebar -->
                <!-- ============================================================== -->
            </div>
            <!-- /.container-fluid -->
            <footer class="footer text-center"> 2017 &copy; IITECH </footer>
        </div>
        <!-- /#page-wrapper -->
    </div>
    <!-- /#wrapper -->
    <!-- jQuery -->
    <script src="https://progiciel.africawebstudent.org/plugins/bower_components/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap Core JavaScript -->
    <script src="bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- Menu Plugin JavaScript -->
    <script src="https://progiciel.africawebstudent.org/plugins/bower_components/sidebar-nav/dist/sidebar-nav.min.js"></script>
    <!--slimscroll JavaScript -->
    <script src="js/jquery.slimscroll.js"></script>
    <!--Wave Effects -->
    <script src="js/waves.js"></script>
    <!-- Magnific popup JavaScript -->
    <script src="https://progiciel.africawebstudent.org/plugins/bower_components/Magnific-Popup-master/dist/jquery.magnific-popup.min.js"></script>
    <script src="https://progiciel.africawebstudent.org/plugins/bower_components/Magnific-Popup-master/dist/jquery.magnific-popup-init.js"></script>
    <!-- Custom Theme JavaScript -->
    <script src="js/custom.min.js"></script>
	<script src="js/validator.js"></script>
    <!--Style Switcher -->
    <script src="https://progiciel.africawebstudent.org/plugins/bower_components/styleswitcher/jQuery.style.switcher.js"></script>

	<script>	
		/*window.onload=function(){
			$('#profileupdate').click(function(){
				if($('#mailp').val()=='' || $('#phonep').val()==''){
						alert('Remplissez les options pour continuer');
				}else{
					$.post(
					'profile-update.php',
					{
						matricule:$('#matricule').val(),
						mailp:$('#mailp').val(),
						motpass:$('#motpass1').val(),
						phonep:$('#phonep').val(),
						description:$('#description').val()
					},
					function(data){
						$('#settings .white-box').html(data);
					},
					'html'
					);
				}
			});			
		}*/
	</script>
	
	</body>

</html>
