<?php
include('../includes/db.php');

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $yearId = (int)$_POST['year_id'];
    
    // Set all years to inactive
    $conn->query("UPDATE academic_years SET status = 'inactive'");
    
    // Set selected year to active
    $query = "UPDATE academic_years SET status = 'active' WHERE year_id = $yearId";
    
    if ($conn->query($query)) {
        echo json_encode(['success' => true, 'message' => 'Academic year set as active']);
    } else {
        echo json_encode(['success' => false, 'message' => 'Error: ' . $conn->error]);
    }
}
?>