<?php
require_once('../config/db.php');

// تحقق من وجود course_id
$course_id = isset($_GET['course_id']) ? intval($_GET['course_id']) : 0;

if ($course_id <= 0) {
    echo json_encode([]);
    exit;
}

// جلب الطلاب المسجلين في هذا الكورس من جدول enrollments
$stmt = $conn->prepare("
    SELECT s.full_name, s.phone, s.email
    FROM enrollments e
    JOIN students s ON s.id = e.student_id
    WHERE e.course_id = ?
");
$stmt->execute([$course_id]);
$students = $stmt->fetchAll(PDO::FETCH_ASSOC);

// إرجاع النتائج بصيغة JSON
header('Content-Type: application/json');
echo json_encode($students);
