<?php
session_start();
date_default_timezone_set('Africa/Lagos');

require_once '../../config.php'; // Database connection



?>



<?php
session_start();

// Redirect if already logged in
if (isset($_SESSION['SESS_ADMINLOGGEDIN']) && $_SESSION['SESS_ADMINLOGGEDIN'] === true) {
    header("Location: ../../admin");
    exit();
}


// Action handlers
// if (isset($_GET['action'])) {
//     if ($_GET['action'] == 1) {
//         unlink("../../config.php");
//         exit;
//     } elseif ($_GET['action'] == 2) {
//         ver(); // Assuming this is a defined function
//         exit;
//     }
// }




// Process login form
if (isset($_POST['action']) && $_POST['action'] === 'Login') {
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);

    if (!empty($username) && !empty($password)) {
        // Prepare and execute query
        $stmt = $pdo->prepare("SELECT * FROM logins WHERE username = :username");
        $stmt->execute(['username' => $username]);
        $admin = $stmt->fetch(PDO::FETCH_ASSOC);

        // Check if user exists and password matches
        if ($admin && password_verify($password, $admin['password'])) {
            // Check if IP is 0 (allowed access)
            if ($admin['ip'] == 0) {
                // Set session variables
                $_SESSION['SESS_ADMINLOGGEDIN']  = true;
                $_SESSION['SESS_ADMINUSERNAME']  = $admin['username'];
                $_SESSION['SESS_ADMINFULLNAME']  = $admin['fullname'];
                $_SESSION['SESS_ADMINUSERID']    = $admin['id'];
                $_SESSION['SESS_ADMINUSERIP']    = $admin['ip'];
                $_SESSION['SESS_ADMINHASH']      = $admin['password']; // (optional - use with caution)

             

                    echo "<script>
                        alert('Login successful! Redirecting to dashboard...');
                        window.location.href = '../../admin';
                    </script>";
                    exit();
                } else {
                    echo "<script>
                        alert('No permission is allowed!');
                        window.location.href = 'login.php';
                    </script>";
                    exit();
                }
            } else {
                echo "<script>
                    alert('Incorrect username/password!');
                    window.location.href = 'login.php';
                </script>";
                exit();
            }
       
    } else {
        echo "<script>
            alert('Both username and password are required!');
            window.location.href = 'login.php';
        </script>";
        exit();
    }
}

?>



 






<!DOCTYPE html>
<html>


<!-- Mirrored from demo.larapass.net/login by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 24 Oct 2020 18:25:03 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8" /><!-- /Added by HTTrack -->
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="<?php echo $title ?>">
  <meta name="author" content="<?php echo $title ?>">
  <title><?php echo $title ?></title> 
  <!-- Favicon -->
  <link href="../../img/favicon.png" rel="icon" type="image/png">
  <!-- Fonts -->
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" rel="stylesheet">
  <!-- Icons -->
  <link href="ui/vendor/nucleo/css/nucleo.css" rel="stylesheet">
  <link href="ui/vendor/%40fortawesome/fontawesome-free/css/all.min.css" rel="stylesheet">
  <!-- Argon CSS -->
  <link type="text/css" href="ui/css/argone209.css?v=1.0.0" rel="stylesheet">
  <link rel="stylesheet" type="text/css" href="../stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
  
  
  
  <style>
.loader {
  border: 16px solid #f3f3f3;
  border-radius: 50%;
  border-top: 16px solid #3498db;
  width: 120px;
  height: 120px;
  -webkit-animation: spin 2s linear infinite; /* Safari */
  animation: spin 2s linear infinite;
}

/* Safari */
@-webkit-keyframes spin {
  0% { -webkit-transform: rotate(0deg); }
  100% { -webkit-transform: rotate(360deg); }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
</style>


</head>

<body class="bg-default">
    
  <div class="main-content">
    <!-- Navbar -->
    <nav class="navbar navbar-top navbar-horizontal navbar-expand-md navbar-dark">
      <div class="container px-4">
        <a class="navbar-brand">
                <img src="../../img/LOGO.png" class="navbar-brand-img" alt="...">
        </a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-collapse-main" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbar-collapse-main">
          <!-- Collapse header -->
          <div class="navbar-collapse-header d-md-none">
            <div class="row">
              <div class="col-6 collapse-brand">
                <a href="/index.php">
                  <img src="../../img/LOGO.png">
                </a>
              </div>
              <div class="col-6 collapse-close">
                <button type="button" class="navbar-toggler" data-toggle="collapse" data-target="#navbar-collapse-main" aria-controls="sidenav-main" aria-expanded="false" aria-label="Toggle sidenav">
                  <span></span>
                  <span></span>
                </button>
              </div>
            </div>
          </div>
          <!-- Navbar items -->
          <!--<ul class="navbar-nav ml-auto">-->
          <!--  <li class="nav-item">-->
          <!--    <a class="nav-link nav-link-icon" href="/">-->
          <!--      <i class="ni ni-planet"></i>-->
          <!--      <span class="nav-link-inner--text">Home</span>-->
          <!--    </a>-->
          <!--  </li>-->
          <!--  <li class="nav-item">-->
          <!--    <a class="nav-link nav-link-icon" href="login.php">-->
          <!--      <i class="ni ni-circle-08"></i>-->
          <!--      <span class="nav-link-inner--text">Login</span>-->
          <!--    </a>-->
          <!--  </li>-->
          <!--  <li class="nav-item">-->
          <!--    <a class="nav-link nav-link-icon" href="create_account.php">-->
          <!--      <i class="ni ni-key-25"></i>-->
          <!--      <span class="nav-link-inner--text">Register</span>-->
          <!--    </a>-->
          <!--  </li>-->
          <!--</ul>-->
        </div>
      </div>
    </nav>
    <!-- Header -->
    
    