<?php
// SHOW ERRORS (for development)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// START SESSION FIRST
session_start();

// DB CONNECTION
require("dbconnect.php");

$msg = "";

// HANDLE FORM SUBMISSION
if (isset($_POST['submit'])) {
    $email = mysqli_real_escape_string($con, $_POST['email']);
    $password = mysqli_real_escape_string($con, $_POST['password']);

    // DEBUG: Show entered values
    // echo "Email: $email <br> Password: $password <br>";

    // QUERY to check email/password
    $sql = "SELECT * FROM memberships WHERE email = '$email' AND password = '$password'";
    $res = mysqli_query($con, $sql);

    if (!$res) {
        die("Query failed: " . mysqli_error($con));
    }

    $count = mysqli_num_rows($res);

    if ($count > 0) {
        $_SESSION['ADMIN_LOGIN'] = 'yes';
        $_SESSION['ADMIN_EMAIL'] = $email;

        // REDIRECT
        header("Location: employee.php");
        exit;
    } else {
        $msg = "Please enter valid login details";
    }
}
?>


<!DOCTYPE html>
<html>
<head>
<title>Admin Login</title>
<meta name="viewport" content="width=device-width, initial-scale=1">

<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">

<style>
body{
    margin:0;
    min-height:100vh;
    display:flex;
    align-items:center;
    justify-content:center;
    background:linear-gradient(135deg,#0f2027,#203a43,#2c5364);
    font-family:Poppins;
}
.card{
    width:380px;
    padding:35px;
    border-radius:18px;
    background:rgba(255,255,255,.1);
    backdrop-filter:blur(15px);
    box-shadow:0 30px 60px rgba(0,0,0,.4);
}
h2{
    text-align:center;
    color:#fff;
    margin-bottom:25px;
}
.input{
    width:100%;
    padding:12px;
    margin-bottom:20px;
    background:transparent;
    border:none;
    border-bottom:2px solid #aaa;
    color:#fff;
    outline:none;
}
.btn{
    width:100%;
    padding:12px;
    border:none;
    border-radius:30px;
    background:linear-gradient(90deg,#00f2fe,#4facfe);
    font-weight:600;
    cursor:pointer;
}
.btn:hover{
    transform:translateY(-2px);
}
.msg{
    margin-top:15px;
    text-align:center;
    color:#ffdada;
}
.footer{
    margin-top:20px;
    text-align:center;
    font-size:12px;
    color:#ccc;
}
</style>
</head>

<body>

<div class="card">
<h2>Admin Employee Login</h2>

<form method="POST">
    <input class="input" type="email" name="email" placeholder="Email" required>
    <input class="input" type="password" name="password" placeholder="Password" required>
    <button class="btn" name="submit">Login</button>
</form>

<?php if($msg!=""){ ?>
<div class="msg"><?php echo $msg; ?></div>
<?php } ?>

<div class="footer">© 2025 RBV</div>
</div>

</body>
</html>
