<?php
include 'includes/conn.php';

if (!isset($_GET['student_id'])) {
    echo json_encode(['success' => false]);
    exit;
}

$student_id = $_GET['student_id'];

$stmt = $pdo->prepare("
    SELECT c.id AS classroom_id, c.name AS class_name 
    FROM classroom_students cs
    JOIN classrooms c ON cs.classroom_id = c.id
    WHERE cs.student_id = ?
    LIMIT 1
");
$stmt->execute([$student_id]);
$class = $stmt->fetch(PDO::FETCH_ASSOC);

if ($class) {
    echo json_encode(['success' => true, 'class_name' => $class['class_name'], 'classroom_id' => $class['classroom_id']]);
} else {
    echo json_encode(['success' => false]);
}
?>
