<?php
// --- CUSTOM SESSION PATH FIX START (লগইন লুপ এবং /tmp এরর সমাধান) ---
$sessionPath = __DIR__ . '/sessions';
if (!file_exists($sessionPath)) { 
    @mkdir($sessionPath, 0755, true); 
}
if (is_writable($sessionPath)) {
    ini_set('session.save_path', $sessionPath);
}
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}
// --- CUSTOM SESSION PATH FIX END ---

require '../config.php';

if(isset($_POST['login'])) {
    $user = $_POST['username'];
    $pass = $_POST['password'];

    $stmt = $conn->prepare("SELECT * FROM admins WHERE username = ?");
    $stmt->bind_param("s", $user);
    $stmt->execute();
    $result = $stmt->get_result();
    $row = $result->fetch_assoc();

    if($row && password_verify($pass, $row['password'])) {
        $_SESSION['admin_logged_in'] = true;
        header("Location: index.php");
        exit();
    } else {
        $error = "ভুল ইউজারনেম বা পাসওয়ার্ড!";
    }
}
?>
<!-- সিম্পল লগইন ফর্ম এইচটিএমএল -->
<!DOCTYPE html>
<html lang="bn">
<head>
    <meta charset="UTF-8">
    <title>Admin Login</title>
    <link rel="stylesheet" href="../style.css">
</head>
<body>
<div class="container">
    <h2>Admin Login</h2>
    <?php if(isset($error)) echo "<p style='color:red'>$error</p>"; ?>
    <form method="post">
        <input type="text" name="username" placeholder="Username" required>
        <input type="password" name="password" placeholder="Password" required>
        <button type="submit" name="login" class="btn">Login</button>
    </form>
</div>
</body>
</html>