<?php
// Include your MySQLi connection script
include 'db_connection.php';

// Example query to retrieve homework assignments for the current month
$currentMonth = date('m');
$sql = "SELECT h.homework_id, h.title, h.due_date
        FROM homework h
        WHERE MONTH(h.due_date) = $currentMonth";

$result = $conn->query($sql);

$events = [];
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $events[] = [
            'title' => $row['title'],
            'start' => $row['due_date'],
            'end' => $row['due_date'],
            'url' => 'link-to-details-page.php?homework_id=' . $row['homework_id']
        ];
    }
} else {
    echo "No homework assignments found for the current month.";
}

$conn->close();
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Calendar View - Homework Assignments</title>
    <link href='fullcalendar/core/main.css' rel='stylesheet' />
    <link href='fullcalendar/daygrid/main.css' rel='stylesheet' />
    <script src='fullcalendar/core/main.js'></script>
    <script src='fullcalendar/daygrid/main.js'></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            var calendarEl = document.getElementById('calendar');

            var calendar = new FullCalendar.Calendar(calendarEl, {
                plugins: ['dayGrid'],
                events: <?php echo json_encode($events); ?>
            });

            calendar.render();
        });
    </script>
</head>
<body>
    <div id='calendar'></div>
</body>
</html>
