<?php
include 'db_connection.php';

$teacher_id = isset($_GET['teacher_id']) ? (int)$_GET['teacher_id'] : null;

if (!$teacher_id) {
    echo json_encode(['success' => false, 'message' => 'Teacher ID is required.']);
    exit();
}

try {
    $stmt = $pdo->prepare("SELECT id, name FROM tests WHERE teacher_id = :teacher_id");
    $stmt->bindParam(':teacher_id', $teacher_id, PDO::PARAM_INT);
    $stmt->execute();
    $tests = $stmt->fetchAll(PDO::FETCH_ASSOC);

    echo json_encode(['success' => true, 'tests' => $tests]);
} catch (PDOException $e) {
    echo json_encode(['success' => false, 'message' => 'Database error: ' . $e->getMessage()]);
}
?>
