<?php
chdir('../');

	require_once("public/connection.php");
	require_once("public/functions.php");

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $class = $_POST['class'] ?? '';
    $staff_id = $_POST['staff_id'] ?? 0;

    $subjects = [];

    if (!empty($class) && is_numeric($staff_id)) {
        $stmt = $connection->prepare("SELECT DISTINCT subject FROM subject_teacher WHERE staff_id = ? AND class = ?");
        $stmt->bind_param("is", $staff_id, $class);
        $stmt->execute();
        $res = $stmt->get_result();

        while ($row = $res->fetch_assoc()) {
            $subjects[] = $row['subject'];
        }

        $stmt->close();
    }

    header('Content-Type: application/json');
    echo json_encode($subjects);
}

?>
