<?php
session_start();
include('../connexion.php');
if (isset($_SESSION['celest']))
{
	header ('Location: administration.php');
}
?>
	<?php include('tete.php'); ?>
    <link rel="stylesheet" type="text/css" href="style/style_admin.css" />
</head>
<body id="entree">
	<div class="container">
    	<div class="row">
        	<div class="col-lg-4 col-md-4 col-sm-4"></div>
        	<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
            	<div id="logo"><a href="http://www.2tmultimedia.com"><img src="../img/logo.png" width="250"></a></div>
            	<div id="acces" style="color: #111;">
                    <form role="form" method="post" action="" enctype="multipart/form-data">
                        <div class="row">
                            <div class="col-lg-12">
                                <h4>Login</h4>
                                <input class="form-control" type="text" name="login" value="<?php if(isset($_POST['valider1'])){echo $_POST['login'];}?>">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-12">
                                <h4>Mot de passe</h4><input class="form-control" type="password" name="mdp">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-12" align="center" style="margin-top:15px;">
                                <input type="submit" name="valider1" value="Connexion" class="btn btn-primary">
                            </div>
                        </div>
                    </form>
                    <?php
					if (isset($_POST['valider1']))
					{
						$login=addslashes(($_POST['login']));
						$mdp=addslashes(($_POST['mdp']));
						$date_mise=date('Y-m-d H:i:s');
	
						$sql = 'SELECT *, count(*) as nbr FROM user WHERE lib_user="'.$login.'" AND mdp_user="'.$mdp.'"';
						$reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
						$data =$reponse->fetch();
						$nbr_exist=$data['nbr'];
						
						if (empty($login) or empty($mdp))
						{
							echo '
							<div class="alert alert-danger">
								<strong>Erreur!</strong> Veuillez renseigner tous les champs
							</div>';
						}
						elseif ($nbr_exist!=1)
						{
							echo '
							<div class="alert alert-danger">
								<strong>Erreur!</strong> Login et/ou Mot de passe incorrects
							</div>';
						}
						elseif ($data['bloquer_user']=='oui')
						{
							echo '
							<div class="alert alert-danger">
								<strong>Attention!</strong> Votre compte a été bloqué temporairement. Veuillez nous contactez le webmaster
							</div>';
						}
						else
						{
							$_SESSION['celest'] = $data[0];
							$sql = 'UPDATE user SET connexion_user="'.($data['connexion_user']+1).'", last_user="'.$date_mise.'" WHERE id_user="'.$_SESSION['celest'].'"';
							$reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
							
							$sql2='SELECT * FROM user WHERE id_type_user=1';
							$reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
							$data2=$reponse2->fetch();
							//header('Location: membre.php');
							if($data2['langue_user']=='non')
							{
								?>
								<script type="text/javascript">window.setTimeout("location=('administration.php');",0);</script>
								<?php
							}
							else
							{
								?>
								<script type="text/javascript">window.setTimeout("location=('choix-langue.php');",0);</script>
								<?php
							}
						}
					}
					?>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
