<?php
require_once "config/config.php";
include("Data.class.php");

$Data = new Data($pdo);

if (!isset($_GET["ts"])) {
    echo json_encode(["error" => "missing timestamp"]);
    exit;
}

$ts = intval($_GET["ts"]);

// Tages-Start/Ende berechnen
$dayStart = strtotime("00:00", $ts);
$dayEnd   = strtotime("23:59", $ts);

$sql = $pdo->prepare("
    SELECT id, startzeit, location 
    FROM termine 
    WHERE startzeit BETWEEN :s AND :e
");
$sql->execute([
    ":s" => $dayStart,
    ":e" => $dayEnd
]);

$results = $sql->fetchAll(PDO::FETCH_ASSOC);

echo json_encode($results);
