<?php
session_start();


include 'include/database.php'; ?>

<?php include 'include/header.php'; ?>


<?php

if (isset($_POST['login'])) {

    $u = $_POST['username'];
    $p = $_POST['password'];

    $ql = "select * from `users`";
    $result = mysqli_query($con, $ql);
    if ($result) {
        $row = mysqli_fetch_array($result);
        $user = $row["username"];
        $pass = $row["password"];
        $act = $row["active"];


        if ($user == $u && $pass == $p && $act == "false") {
            $_SESSION["user"] = $user;
            $_SESSION["password"] = $pass;
            $_SESSION["active"] = $act;

         echo '<script>alert("Login Successful");</script>';
                echo '<script>
                        setTimeout(function() {
                            window.location.href= "index.php";
                        }); 
                      </script>';
           include 'include/reload.php';
        } else {
            echo '<script>alert("Invalid Username Or Password")</script>';
        }
    } 
}

?>

<div class="body-login">
    <div class="login-container">

        <h1 style="color: #005BAA;"> <i class="fa-solid fa-user-tie"></i> Login</h1>
        <form class="login-form" method="post">

            <div>
                <i class="fa-regular fa-user login-icon"></i>
                <input type="text" name="username" placeholder="Username" required>
            </div>

            <div class="password-container">
                <i class="fa-solid fa-lock login-icon"></i>
                <input type="password" name="password" id="password" placeholder="Password" required>

                <i class="fas fa-eye password-icon" id="togglePassword"></i>
            </div>
            <button type="submit" name="login">Login </button>
        </form>
    </div>
</div>

<?php include 'include/footer.php'; ?>