<?php
session_start();
include 'db_connection.php';

// Check if the teacher is logged in
if (!isset($_SESSION['teacher_id'])) {
    header("Location: teacher_login.php");
    exit;
}

$teacher_id = $_SESSION['teacher_id'];

// Fetch classes handled by the teacher
$sql_classes = "SELECT class_name, class_id FROM classes WHERE teacher_id = ?";
$stmt_classes = $conn->prepare($sql_classes);
$stmt_classes->bind_param("i", $teacher_id);
$stmt_classes->execute();
$result_classes = $stmt_classes->get_result();

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Classes</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <?php include 'header.php'; ?>
    <div class="container">
        <h2>My Classes</h2>
        <ul>
            <?php while ($row = $result_classes->fetch_assoc()): ?>
                <li>
                    <a href="class_details.php?class_id=<?php echo $row['class_id']; ?>"><?php echo $row['class_name']; ?></a>
                </li>
            <?php endwhile; ?>
        </ul>
    </div>
</body>
</html>

<?php
$stmt_classes->close();
$conn->close();
?>
