<?php
session_start();
require_once "../SystemController/DbConnection.php";


$db_handle = new Dbconnection();

$msg = "";
if(isset($_POST['email'])){

$token = bin2hex(random_bytes(50));

$email = $db_handle->sanitize($_POST['email']);
$password = $db_handle->sanitize($_POST['password']);


$admin = $db_handle->runBaseQuery("SELECT * FROM admins WHERE email = '$email' ");

if($admin){

if(password_verify($password, $admin[0]['password'])){
  
  
  
    $_SESSION['admin_id'] = $admin[0]['id'];
    $_SESSION['role'] = $admin[0]['role'];
    header("location: dashboard.php?page=dashboard");
    
        
        
  }else{
    $msg = "<div class='alert alert-danger mx-auto'>
            
    <strong><i class='fa fa-info-circle'></i> Passwords do not match, please check and try again </strong>
  </div>";
  }
  
}
}
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="csrf-token" content="ocjB56H6vKcQjnq7sifD2mLVYgNhCe19CBr3prCe" />
    <meta name="viewport" content="width=device-width,initial-scale=1">
    
    <meta property="og:image" content="website-image.jpg" />
   
    <title>Ovoh Initiative | Welcome Admin</title>
    <link rel="icon" href="../assets/img/favicon.png" type="image/x-icon">
        <link rel="icon" href="../assets/img/favicon.ico" sizes="any">
        <link rel="icon" href="../assets/img/favicon.svg" type="image/svg+xml">
        <link rel="apple-touch-icon" href="../assets/img/favicon.png">
    <link rel="stylesheet" href="../assets/css/bootstrap.min.css">
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="../assets/css/fontawesome/all.min.css">
    <!-- FontAwesome CSS -->
    
    <!-- FontAwesome CSS -->
    <link rel="stylesheet" href="../style.css"><!-- Custom CSS -->
     <link rel="stylesheet" href="../responsive.css">
    <!-- Responsive CSS -->
    <!-- IF VERSION 2  -->
        <style>
      :root {
          /* Color */
          --bs-primary: #000000;
          --bs-secondary: #c0a146;
      }
  </style>
</head>
<body>
    
    <main>
            <section>
        <div class="row align-items-center g-0 w-100 h-100vh position-relative">
            <div class="col-md-5 d-md-block d-none">
                <div class="login-left-content">
                    <a href="">
                        <img src="../assets/img/logo.png" class="logo-img" alt="">
                    </a>
                </div>
            </div>
            <div class="col-md-7 overflow-hidden bg-white">
                <div class="login-right-content login-forgot-padding row">
                    <div class="pb-0 px-0">
                        <div class="text-primary d-flex align-items-center justify-content-between">
                            <div>
                                <h2 class="fw-bold text-color title-text mb-2" style="color:#BA0C2F">WELCOME ADMIN!</h2>
                                <p class="text-color">Get back to managing your business.</p>
                            </div>
                            <!-- FOR SMALL DEVICE TOP CATEGORIES -->
                                                    </div>
                        <form class="mt-3" method="POST" action="">
                            <?php echo $msg; ?>
                            <input type="hidden" name="_token" value="ocjB56H6vKcQjnq7sifD2mLVYgNhCe19CBr3prCe">                            <div class="form-group">
                                <label for="email" class="form-label">Email<span
                                        class="text-danger"> * </span></label>
                                <input type="email" class="form-control" name="email"
                                    placeholder="Email" id="email" required>

                            </div>
                            <div class="form-group">
                                <label for="password" class="form-label">Password<span
                                        class="text-danger"> * </span></label>
                                <div class="form-control d-flex align-items-center gap-3">
                                    <input type="password" class="form-control border-0 p-0" name="password"
                                        placeholder="Password" id="password" required>
                                    <span>
                                        <a href="#"><i class="fa-light fa-eye-slash" id="eye"></i></a>
                                    </span>
                                </div>

                            </div>
                            <div class="d-flex">
                               <!-- <div class="form-group mb-2 col-6 d-flex align-items-center">
                                    <input class="form-check-input mt-0" type="checkbox" value="" name="check_terms"
                                        id="check_terms" checked>
                                    <label class="form-check-label cursor-pointer mx-1" for="check_terms">
                                        <span class="fs-7 text-color">
                                            Remember Me
                                        </span>
                                    </label>
                                </div>
                                <div
                                    class="text-end  mb-2 col-6">
                                    <a href="forgot_password" class="fs-7 fw-600">
                                        Forgot Password ?
                                    </a>
                                </div>-->
                            </div>
                            <button class="btn btn-danger w-100 mt-2 mb-3 padding"
                                type="submit">Login</button>

                                                            
                                                    </form>
                                            </div>
                </div>
            </div>
        </div>
    </section>
        </main>
    <script src="https://ushoppen.com/storage/app/public/admin-assets/js/jquery/jquery.min.js"></script><!-- jQuery JS -->
    <script src="https://ushoppen.com/storage/app/public/admin-assets/js/bootstrap/bootstrap.bundle.min.js"></script><!-- Bootstrap JS -->
    <script src="https://ushoppen.com/storage/app/public/admin-assets/js/toastr/toastr.min.js"></script><!-- Toastr JS -->
    <script>
        toastr.options = {
          "closeButton": true,
          "positionClass": "toast-top-right",
         
        }
                        $(window).on("load", function() {
          "use strict";
          $('#preloader').fadeOut('slow')
        });
        function myFunction() {
          "use strict";
          toastr.error("This operation was not performed due to demo mode");
          return false;
        }

        $('#name').on('blur', function() {
          "use strict";
          $('#slug').val($('#name').val().split(" ").join("-").toLowerCase());
        });
    </script>
            <script>
        function AdminFill(email, password) {
            $('#email').val(email);
            $('#password').val(password);
        }
        // password eye hide
        $(function() {
            $('#eye').click(function() {
                if ($(this).hasClass('fa-eye-slash')) {
                    $(this).removeClass('fa-eye-slash');
                    $(this).addClass('fa-eye');
                    $('#password').attr('type', 'text');
                } else {
                    $(this).removeClass('fa-eye');
                    $(this).addClass('fa-eye-slash');
                    $('#password').attr('type', 'password');
                }
            });
        });
    </script>
</body>
</html>