<?php
session_start();
require_once 'includes/database.php';
require_once 'Classes/Timetable.php';

header('Content-Type: application/json');

if(!isset($_SESSION['username']) || !isset($_POST['period_id'])) {
    echo json_encode(['success' => false, 'message' => 'Invalid request']);
    exit();
}

$timetable = new Timetable();
$periodId = $_POST['period_id'];

$sql = "SELECT * FROM timetable_periods WHERE id = :id";
$timetable->query($sql);
$timetable->bind(':id', $periodId);
$period = $timetable->fetchSingle();

if($period) {
    echo json_encode([
        'success' => true,
        'period' => $period
    ]);
} else {
    echo json_encode(['success' => false, 'message' => 'Period not found']);
}
