telvero_whatson_talpa/api/get_next_start_time.php
2026-02-19 15:58:15 +01:00

45 lines
1.1 KiB
PHP

<?php
/**
* API Endpoint: Get Next Start Time
* Calculates the next available start time based on existing transmissions
*/
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../helpers.php';
require_once __DIR__ . '/../auth/auth_functions.php';
use Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable(__DIR__ . '/..');
$dotenv->load();
header('Content-Type: application/json');
if (!isLoggedIn()) {
http_response_code(401);
echo json_encode(['success' => false, 'error' => 'Niet geautoriseerd.']);
exit;
}
try {
$db = getDbConnection();
$date = $_GET['date'] ?? date('Y-m-d');
$channel = $_GET['channel'] ?? 'SBS9';
$requestedTime = $_GET['requested_time'] ?? null;
// Get next start time using helper function
$nextStartTime = calculateNextStartTime($db, $date, $channel, $requestedTime);
jsonResponse([
'next_start_time' => $nextStartTime,
'date' => $date,
'channel' => $channel
]);
} catch (Exception $e) {
jsonResponse([
'error' => $e->getMessage()
], 500);
}