<?php
  include 'connection.php';
  error_reporting(0);
  session_start();
  $validcode=$_SESSION['CODE'];
  $msg="";
  if (isset($_POST['loginbtn'])) {
    $username = $_POST['username'];
    $password = $_POST['password'];
    $captcha = $_POST['captcha'];
    if ($captcha==$validcode) {
      $query = "SELECT * FROM officers WHERE email='$username' && password='$password'";
      $result = mysqli_query($con,$query);
      if (mysqli_num_rows($result) == 1) {
        //set cookies
        if (isset($_POST['remember'])) {
          setcookie('username',$username, time()+60*60*24*30);
          setcookie('password',$password, time()+60*60*24*30);
        }
        else{
          setcookie('username',$username,30);
          setcookie('password',$password,30);
        }

        //set session
        header('location:index.php');
        $_SESSION['user']=$username;
      }
      else{
        $msg="Your Login Name or Password is invalid";
      }
    }
    else{
      $msg="Invalid captcha";
    }
    
  }

  // active remmeber button
  $username_cookie='';
  $password_cookie='';
  $set_remember='';
  if (isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
    $username_cookie=$_COOKIE['username'];
    $password_cookie=$_COOKIE['password'];
    $set_remember="checked='checked'";
  }
?>
<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>जिला लोक शिकायत केंद्र</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <link href="https://fonts.googleapis.com/css2?family=Material+Icons" rel="stylesheet">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.theme.default.min.css"/>
  <link rel="stylesheet" type="text/css" href="css/style.css">
<style type="text/css">
body{
  background: #2D8248;
}
  .login-box{
    background: #fff;
    box-shadow: 0 0 25px #eee;
    padding: 40px 20px;
    margin: 25px 10px;
  }
  .login-box h3{
    font-weight: bold;
    margin-bottom: 15px;
  }
  .login-box form input,
  .login-box form select{
    width: 100%;
    height: 40px;
    margin-bottom: 15px;
    border: none;
    outline: none;
    background: transparent;
    background: #eee;
    padding-left: 15px;
  }
  .login-box form input[type="checkbox"]{
    width: 5px;
    height: 15px;
    border: 1px solid #000;
  }
  .login-box form img{
    margin-bottom: 10px;
  }
  .login-box form input[type="submit"]{
    background: #2D8248;
    color: #fff;
  }
</style>
<body>
  
<!--=====Contact area===-->
<section>
  <div class="container col-lg-6 m-auto">
    <div class="login-box">
      <h3>ADMIN LOGIN</h3>
      <form method="post">
        <input type="email" name="username" placeholder="Enter Email" value="<?php echo $username_cookie; ?>" required="">
        <input type="password" name="password" placeholder="Enter Password" value="<?php echo $password_cookie; ?>" required="">
        <input type="text" name="captcha" placeholder="Enter Valid Captcha" required="">
        <img src="captcha.php"><br>
        <input type="checkbox" class="form-check-input" id="exampleCheck1" name="remember" <?php echo $set_remember; ?>>
        <label class="form-check-label">Remember me</label>
        <input type="submit" name="loginbtn" value="Login">
        <span class="text-danger"><a href="#">forget password?</a></span>
      </form>
      <div><span style="color: red;"><?php echo $msg; ?></span></div>
    </div>
  </div>
</section>

<!--=====End Contact area===-->

    <!-- Optional JavaScript; choose one of the two! -->

    <!-- Option 1: Bootstrap Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>

    <!-- Option 2: Separate Popper and Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js" ></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js"></script>

    <script type="text/javascript" src="js/script.js"></script>
    <script type="text/javascript">
      
    </script>
  </body>
</html>

</head>
</html>
