68 lines
1.7 KiB
PHP
68 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* API Endpoint: Get Block Details
|
|
* Returns detailed information about a specific block (for preview)
|
|
*/
|
|
|
|
require_once __DIR__ . '/../vendor/autoload.php';
|
|
require_once __DIR__ . '/../helpers.php';
|
|
|
|
use Dotenv\Dotenv;
|
|
|
|
$dotenv = Dotenv::createImmutable(__DIR__ . '/..');
|
|
$dotenv->load();
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
try {
|
|
$db = getDbConnection();
|
|
|
|
$blockId = $_GET['block_id'] ?? null;
|
|
|
|
if (!$blockId) {
|
|
jsonResponse(['success' => false, 'error' => 'Missing block_id'], 400);
|
|
}
|
|
|
|
// Get block info
|
|
$stmt = $db->prepare("
|
|
SELECT db.*, bt.name as template_name
|
|
FROM daily_blocks db
|
|
LEFT JOIN block_templates bt ON db.template_id = bt.id
|
|
WHERE db.id = ?
|
|
");
|
|
$stmt->execute([$blockId]);
|
|
$block = $stmt->fetch();
|
|
|
|
if (!$block) {
|
|
jsonResponse(['success' => false, 'error' => 'Block not found'], 404);
|
|
}
|
|
|
|
// Get transmissions in this block
|
|
$stmt = $db->prepare("
|
|
SELECT t.*, c.title, c.series_code
|
|
FROM transmissions t
|
|
JOIN infomercials c ON t.infomercial_id = c.id
|
|
WHERE t.start_date = ?
|
|
AND t.channel = ?
|
|
AND t.start_time >= ?
|
|
AND t.start_time < ?
|
|
ORDER BY t.start_time ASC
|
|
");
|
|
$stmt->execute([
|
|
$block['block_date'],
|
|
$block['channel'],
|
|
$block['actual_start_time'],
|
|
$block['actual_end_time'] ?? '23:59:59'
|
|
]);
|
|
$transmissions = $stmt->fetchAll();
|
|
|
|
jsonResponse([
|
|
'success' => true,
|
|
'block' => $block,
|
|
'transmissions' => $transmissions
|
|
]);
|
|
|
|
} catch (Exception $e) {
|
|
jsonResponse(['success' => false, 'error' => $e->getMessage()], 500);
|
|
}
|