<?php
// get_specializations.php
require '../db.php';
require '../helpers.php';

header('Content-Type: application/json');

if (isset($_GET['section_id']) && isset($_GET['program_id'])) {
    $section_id = intval($_GET['section_id']);
    $program_id = intval($_GET['program_id']);
    
    // الاستعلام يجلب التخصصات بناءً على section_id و program_id
    $stmt = $mysqli1->prepare("
        SELECT 
            specialization_id as id, 
            specialization_name_ar as name,
            specialization_name_en as name_en,
            degree_awarded_ar,
            degree_awarded_en
        FROM specializations 
        WHERE section_id = ? 
            AND program_id = ? 
            AND deleted_at IS NULL 
        ORDER BY specialization_name_ar
    ");
    
    $stmt->bind_param("ii", $section_id, $program_id);
    $stmt->execute();
    $specializations = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
    
    echo json_encode($specializations);
} else {
    echo json_encode([]);
}
?>