<?php
/**
 * Admin Init
 * Initialize admin session and check authentication
 */

// Start session
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// Load configuration
require_once __DIR__ . '/../../config/database.php';
require_once __DIR__ . '/../../config/constants.php';

// Load classes
require_once __DIR__ . '/../../includes/Database.php';
require_once __DIR__ . '/../../includes/Auth.php';

// Initialize auth
$auth = new Auth();

// Check if admin is logged in (except for login page)
$currentPage = basename($_SERVER['PHP_SELF']);
if ($currentPage !== 'login.php' && !$auth->isAdmin()) {
    header('Location: /admin/login');
    exit;
}

// Get admin user if logged in
$adminUser = null;
if ($auth->isAdmin()) {
    $adminUser = $auth->getUser();
}
?>

