<?PHP
$erreur = false;
$erreur2 = false;
require_once('core.php');
if(isset($_SESSION['admin']))
{
header("Location: home.php");
exit();
}
if(isset($_GET['staff'])) {
  $pseudo = htmlspecialchars(trim($_GET['staff']));
  $SelectStaff = $bdd->prepare('SELECT * FROM users WHERE username = ?');
  $SelectStaff->execute(array($pseudo));
  $Staff = $SelectStaff->fetch();
  if ($Staff['rank'] <= $S['rank_min']) {
    header('Location: '.$cms['lien']);
    exit();
  }
  if (isset($_POST['mdp'])) {
    $mdp = htmlspecialchars(trim($_POST['mdp']));
    if ($mdp != "") {
      if (sha1($mdp) == $Staff['password']) {
        $_SESSION['admin'] = $Staff['id'];
        header('Location: home.php');
        exit();
      } else {
        $erreur = true;
      }
    } else {
      $erreur = true;
    }
  }
} else {
  header('Location: '.$cms['lien']);
  exit();
}
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title><?PHP echo htmlentities($cms['nom_hotel']); ?> | Connexion</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.7 -->
  <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
  <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

  <!-- 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]-->

  <!-- Google Font -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body class="hold-transition lockscreen">
<?PHP if($erreur == true) { ?> <script>sweetAlert("Oops !", "Impossible de t\'identifier..", "error");</script> <?PHP } ?>
<?PHP if($erreur2 == true) { ?> <script>sweetAlert("Bravo !", "Connexion réussis !", "success");</script> <?PHP } ?>
<!-- Automatic element centering -->
<div class="lockscreen-wrapper">
  <div class="lockscreen-logo">
    <a href="../../index2.html"><b><?PHP echo htmlentities($cms['nom_hotel']); ?></b> Hôtel</a>
  </div>
  <!-- User name -->
  <div class="lockscreen-name"><?PHP echo $pseudo; ?></div>

  <!-- START LOCK SCREEN ITEM -->
  <div class="lockscreen-item">
    <!-- lockscreen image -->
    <div class="lockscreen-image" style="top:-20px;">
      <img style="width: auto;height: auto;" src="https://www.habbo.de/habbo-imaging/avatarimage?figure=<?PHP echo htmlspecialchars(trim($Staff['look'])); ?>&direction=2&head_direction=3&action=wav&size=m&gesture=sml&headonly=1" alt="User Image">
    </div>
    <!-- /.lockscreen-image -->

    <!-- lockscreen credentials (contains the form) -->
    <form class="lockscreen-credentials" method="post">
      <div class="input-group">
        <input type="password" class="form-control" name="mdp" placeholder="mot de passe">

        <div class="input-group-btn">
          <button type="submit" class="btn"><i class="fa fa-arrow-right text-muted"></i></button>
        </div>
      </div>
    </form>
    <!-- /.lockscreen credentials -->

  </div>
  <!-- /.lockscreen-item -->
  <div class="help-block text-center">
    Entrer votre mot de passe pour accéder à l'administration.
  </div>
  <div class="lockscreen-footer text-center">
    <b><a class="text-black">PlusCMS</a></b><br>
    PlusCMS par Dodone.
  </div>
</div>
<!-- /.center -->

<!-- jQuery 3 -->
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
</body>
</html>
