<?php
//ajax/get_exams_by_class.php


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

if(isset($_GET['class_id']) && !empty($_GET['class_id'])) {
    $class_id = intval($_GET['class_id']);
    
    // Get exams assigned to this class
    $query = "SELECT id, exam_type, exm_year, exm_year_ad 
              FROM examination_type 
              WHERE FIND_IN_SET(?, assigned_class) > 0 
              OR assigned_class = 'all'
              ORDER BY exm_year DESC, exam_type ASC";
    
    $stmt = $conn->prepare($query);
    $stmt->bind_param("s", $class_id);
    $stmt->execute();
    $result = $stmt->get_result();
    
    $exams = array();
    while($row = $result->fetch_assoc()) {
        $exams[] = $row;
    }
    
    echo json_encode($exams);
    $stmt->close();
} else {
    echo json_encode(array());
}
?>