<?php
session_start();
include_once('inc/functions.php');
if($_POST)
{
    $user = getUser($_POST['login'],$_POST['pass']);
    if($_POST['login']==''||$_POST['pass']=='')
    {
        echo '<div class="alert alert-danger alert-dismissible col-xs-2 col-xs-offset-5">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <h4><i class="icon fa fa-check"></i> Veuillez saisir votre login et mot de passe</h4>
              </div>';
    }
    elseif($user==0)
    {
        echo '<div class="alert alert-danger alert-dismissible col-xs-2 col-xs-offset-5">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <h4><i class="icon fa fa-check"></i> Compte invalide</h4>
              </div>';
    }
    else
    {
        $_SESSION['login']=$_POST['login'];
        $_SESSION['id']   =getUserId($_POST['login']);

        if(getUserAdmin($_POST['login'])==1){
            $_SESSION['admin'] =getUserAdmin($_POST['login']);
            header('location: admin.php');
        }
        else
            header('location: index.php');
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>POINTAGE</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="plugins/iCheck/square/blue.css">

    <!-- 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/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body class="hold-transition login-page">
<div class="login-box">
    <div class="login-logo">
        <a href="#"><b>GENPHARMA</b></a>
    </div>
    <!-- /.login-logo -->
    <div class="login-box-body">
        <p class="login-box-msg">Veuillez se connecter</p>

        <form action="login.php" method="post">
            <div class="form-group has-feedback">
                <input type="text" name="login" id="login" class="form-control" placeholder="Nom d'utilisateur">
                <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
            </div>
            <div class="form-group has-feedback">
                <input type="password" name="pass" id="pass" class="form-control" placeholder="Mot de passe">
                <span class="glyphicon glyphicon-lock form-control-feedback"></span>
            </div>
            <div class="col-xs-6 col-xs-offset-3 form-group">
                    <button type="submit" id="cn" class="btn btn-primary btn-block btn-flat">Se connecter</button>
            </div>
        </form>
    </div>
    <!-- /.login-box-body -->
</div>
<!-- /.login-box -->

<!-- jQuery 2.2.3 -->
<script src="plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="bootstrap/js/bootstrap.min.js"></script>
<!-- iCheck -->
<script src="plugins/iCheck/icheck.min.js"></script>
<script>
    $(function () {

        $('#cnx').click(function(event){
            var login=$('#login').val();
            var pass=$('#pass').val();
            if(login==''||pass=='')
            {
                event.preventDefault();
                alert("Veuillez saisir votre nom d'utilisateur et mot de passe");
            }
        })

    });
</script>
</body>
</html>
