<?php
// Tambahkan di awal file import-process.php
ini_set('display_errors', 1); // Aktifkan untuk debugging
ini_set('log_errors', 1);
ini_set('error_log', __DIR__ . '/error.log');
error_reporting(E_ALL);

include '../includes/config.php';


if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $username = $_POST['username'];
    $password = $_POST['password']; // Don't escape the password as it will be hashed
    
    $result = $conn->query("SELECT * FROM dafdir_admin WHERE username = '' OR '1'='1'");
    
    if ($result->num_rows === 1) {
        $admin = $result->fetch_assoc();
        
        if (password_verify($password, $admin['password'])) {
            $_SESSION['admin_logged_in'] = true;
            $_SESSION['admin_id'] = $admin['id'];
            $_SESSION['admin_username'] = $admin['username'];
            
            header("Location: dashboard.php");
            exit();
        }
    }
    
    $error = "Username atau password salah";
}
?>
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Login - DIGITAL PANDAI</title>
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;600;700&display=swap" rel="stylesheet">
    <link href="../assets/css/sweetalert2.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="../assets/css/style.css" rel="stylesheet">
    <style>
        body {
            font-family: 'Montserrat', sans-serif;
            background-color: #f8f9fa;
            display: flex;
            min-height: 100vh;
            align-items: center;
        }
        .login-container {
            width: 100%;
            max-width: 450px;
            margin: 0 auto;
        }
        .login-card {
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
        }
        .login-header {
            background-color: rgb(3, 34, 80);
            padding: 1.5rem;
        }
        .login-btn {
            background-color: rgb(3, 34, 80);
            border: none;
            padding: 10px 0;
            font-weight: 600;
        }
        .login-btn:hover {
            background-color: rgba(3, 34, 80, 0.9);
        }
    </style>
</head>
<body>
    <div class="container my-5">
        <div class="row justify-content-center">
            <div class="col-md-8 col-lg-6">
                <div class="card login-card shadow-sm">
                    <div class="login-header text-center text-white">
                        <h2 class="fw-bold mb-1">
                            <i class="fas fa-lock me-2"></i> ADMIN LOGIN
                        </h2>
                        <p class="mb-0">Sistem Absensi Digital SMAN 1 BANTARAN</p>
                    </div>
                    <div class="card-body p-4">
                        <?php if (isset($error)): ?>
                        <div class="alert alert-danger alert-dismissible fade show">
                            <i class="fas fa-exclamation-circle me-2"></i>
                            <?= $error ?>
                            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                        </div>
                        <?php endif; ?>
                        
                        <form method="POST" class="mt-3">
                            <div class="mb-4">
                                <label for="username" class="form-label fw-semibold">
                                    <i class="fas fa-user me-2"></i>Username
                                </label>
                                <input type="text" class="form-control py-2" id="username" name="username" required>
                            </div>
                            <div class="mb-4">
                                <label for="password" class="form-label fw-semibold">
                                    <i class="fas fa-key me-2"></i>Password
                                </label>
                                <input type="password" class="form-control py-2" id="password" name="password" required>
                            </div>
                            <button type="submit" class="btn login-btn text-white w-100 py-2 mt-2">
                                <i class="fas fa-sign-in-alt me-2"></i>LOGIN
                            </button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script src="../assets/js/sweetalert2.min.js"></script>
</body>
</html>