<?php
session_start();
include '../admin/dbconn.php'; // This should include your database connection code

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $email = $_POST['email'];
    $password = $_POST['password'];

    // Query to check user credentials
    $stmt = $conn->prepare('SELECT * FROM users WHERE email = ? AND password = ?');
    $stmt->bind_param('ss', $email, $password);
    $stmt->execute();
    $result = $stmt->get_result();

    if ($result->num_rows > 0) {
        $user = $result->fetch_assoc();
        // Store user data in session
        $_SESSION['user'] = $user;
        
        if ($user['status'] === 'active') {
            header('Location: ../admin');
        } elseif ($user['status'] === 'inactive') {
            header('Location: index.php?error=account_disabled');
        } else {
            // Redirect to a default or error page if role is not recognized
            header('Location: index.php?error=invalid_role');
        }
    } else {
        // Redirect back to login page with error message
        header('Location: index.php?error=invalid_credentials');
    }
}
?>