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

if (!isset($_SESSION['teacher_id'])) {
    header("Location: teacher_login.php");
    exit();
}

$teacher_id = $_SESSION['teacher_id'];

$sql = "SELECT class_id, class_name FROM classes WHERE teacher_id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $teacher_id);
$stmt->execute();
$classes = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
$stmt->close();
?>

<!DOCTYPE html>
<html>
<head>
<title>Add Attendance</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">

<style>
.sidebar{width:240px;height:100vh;position:fixed;background:#1e2a38;padding-top:20px}
.sidebar a{display:block;color:#fff;padding:12px;text-decoration:none}
.main{margin-left:240px;padding:20px}
</style>
</head>

<body>

<div class="sidebar">
    <a href="teacher_dashboard.php">Dashboard</a>
    <a href="attendance.php">Attendance</a>
    <a href="feedback_grading.php">Feedback</a>
    <a href="logout.php">Logout</a>
</div>

<div class="main">

<h3>Select Class & Date</h3>

<form method="POST" action="mark_attendance.php">

<select name="class_id" class="form-select mb-3" required>
<option value="">Select Class</option>
<?php foreach ($classes as $c): ?>
<option value="<?= $c['class_id'] ?>"><?= $c['class_name'] ?></option>
<?php endforeach; ?>
</select>

<input type="date" name="date" class="form-control mb-3" required>

<button class="btn btn-primary">Proceed</button>

</form>

</div>

</body>
</html>