<?php
require_once(__DIR__ . '/../config.php');

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

if (isset($_GET['course_id']) && is_numeric($_GET['course_id'])) {

    $stmt = $pdo->prepare("SELECT id, module_name FROM modules WHERE course_id = ?");
    $stmt->execute([$_GET['course_id']]);

    echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));
} else {
    echo json_encode([]);
}