<?php
session_start();
include '../config.php';

$email    = $_POST['email'];
$password = $_POST['password'];

$query = "SELECT * FROM pengguna WHERE email='$email' AND peran='admin'";
$result = mysqli_query($conn, $query);

if (mysqli_num_rows($result) == 1) {
    $user = mysqli_fetch_assoc($result);
    if (password_verify($password, $user['password'])) {
        $_SESSION['user_id'] = $user['id'];
        $_SESSION['nama']    = $user['nama'];
        $_SESSION['peran']   = $user['peran'];
        header("Location: ../admin/dashboard.php");
    } else {
        header("Location: ../login/admin_login.php?pesan=gagal");
    }
} else {
    header("Location: ../login/admin_login.php?pesan=gagal");
}
?>
