<?php
require_once('../../includes/config.php');
header('Content-Type: application/json');

try {
    // Fetch all academic years, ordering by the most recent first
    $sql = "SELECT id, year_name, is_current 
            FROM academic_years 
            ORDER BY year_name DESC";
            
    $stmt = $pdo->query($sql);
    $years = $stmt->fetchAll(PDO::FETCH_ASSOC);

    echo json_encode($years);

} catch (PDOException $e) {
    http_response_code(500);
    echo json_encode([
        "status" => "error", 
        "message" => "Could not fetch academic years: " . $e->getMessage()
    ]);
}
?>
