<?php
// includes/config.php

// Database configuration
$host = 'localhost';
$dbname = 'ujian_system';
$username = 'root';
$password = '';

try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    die("Koneksi database gagal: " . $e->getMessage());
}

// **TAMBAHKAN FUNCTION BASE URL DI SINI:**
function getBaseUrl() {
    $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http';
    $host = $_SERVER['HTTP_HOST'];
    
    // Dapatkan base path dari script current
    $scriptPath = dirname($_SERVER['SCRIPT_NAME']);
    
    // Remove subdirectories (admin, penguji) untuk dapat root path
    $basePath = rtrim(str_replace(['/admin', '/penguji'], '', $scriptPath), '/');
    
    // Jika basePath kosong, set ke root
    if ($basePath === '') {
        $basePath = '/';
    }
    
    return $protocol . '://' . $host . $basePath;
}

// Application settings
define('APP_NAME', 'SOCA OSCE System');
define('APP_VERSION', '1.0');
define('UPLOAD_DIR', 'uploads/images/');
?>