<?php
// Project/config/config.php

// 1. Session Security
// Start the session globally so you don't have to call it on every page
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// 2. Database Connection Check
// We need the database connection to pull dynamic settings
if (!isset($pdo)) {
    // If database.php hasn't been included yet, we include it
    require_once __DIR__ . '/database.php';
}

// 3. Basic School Information
$school_name = "Cloud Academy School Portal";
$school_address = "123 Education Lane, Lagos";
$school_email = "info@cloudacademy.com";

// 4. Dynamic Academic Settings (Pulled from Database)
try {
    // Fetch the active session
    $session_stmt = $pdo->query("SELECT session_name FROM academic_sessions WHERE is_current = 1 LIMIT 1");
    $db_session = $session_stmt->fetchColumn();
    $current_session = $db_session ?: "2025/2026"; // Fallback if DB is empty

    // Fetch the active term
    $term_stmt = $pdo->query("SELECT term_name FROM academic_terms WHERE is_current = 1 LIMIT 1");
    $db_term = $term_stmt->fetchColumn();
    $current_term = $db_term ?: "First Term"; // Fallback if DB is empty
    
} catch (PDOException $e) {
    // If tables don't exist yet, use hardcoded defaults to prevent site crash
    $current_session = "2025/2026";
    $current_term = "First Term";
}

// 5. Grading Scale Configuration
$grading_scale = [
    'A' => 75,
    'B' => 65,
    'C' => 50,
    'P' => 40,
    'F' => 0
];
?>