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

// Fetch schedules with subject_name and class_name
$query = "SELECT s.schedule_id, t.name AS teacher_name, s.day, s.start_time, s.end_time, sub.subject_name, c.class_name
          FROM teacher_schedules s
          INNER JOIN teachers t ON s.teacher_id = t.teacher_id
          INNER JOIN subject sub ON s.subject_id = sub.subject_id
          INNER JOIN classes c ON s.class_id = c.class_id
          ORDER BY s.day, s.start_time";
$result = mysqli_query($conn, $query);

?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>View Schedules</title>
    <link rel="stylesheet" href="#">
    <style type="text/css">
        table {
    width: 80%;
    margin: 20px auto;
    border-collapse: collapse;
    background-color: #fff;
}

table, th, td {
    border: 1px solid #ddd;
}

th, td {
    padding: 10px;
    text-align: left;
}

th {
    background-color: #007bff;
    color: #fff;
}

tr:nth-child(even) {
    background-color: #f2f2f2;
}

    </style>
</head>

<body>
    <div class="container">
        <h2>View Schedules</h2>
        <table>
            <tr>
                <th>Teacher Name</th>
                <th>Day</th>
                <th>Start Time</th>
                <th>End Time</th>
                <th>Subject</th>
                <th>Class to Teach</th>
            </tr>
            <?php while ($row = mysqli_fetch_assoc($result)) : ?>
                <tr>
                    <td><?php echo $row['teacher_name']; ?></td>
                    <td><?php echo $row['day']; ?></td>
                    <td><?php echo $row['start_time']; ?></td>
                    <td><?php echo $row['end_time']; ?></td>
                    <td><?php echo $row['subject_name']; ?></td>
                    <td><?php echo $row['class_name']; ?></td>
                </tr>
            <?php endwhile; ?>
        </table>
    </div>
</body>

</html>

<?php
// Close database connection
mysqli_close($conn);
?>
