81 lines
2.8 KiB
PHP
Executable File
81 lines
2.8 KiB
PHP
Executable File
<?php
|
|
require __DIR__ . '/../includes/auth.php';
|
|
require __DIR__ . '/../includes/admin_layout.php';
|
|
require __DIR__ . '/../includes/broadcasts.php';
|
|
|
|
$admin = requireAdmin();
|
|
$db = getDB();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
verifyCsrf();
|
|
$action = $_POST['action'] ?? '';
|
|
|
|
if ($action === 'set_show') {
|
|
$stmt = $db->prepare('SELECT id, name FROM shows WHERE id = ?');
|
|
$stmt->execute([(int)($_POST['show_id'] ?? 0)]);
|
|
$show = $stmt->fetch();
|
|
if (!$show) {
|
|
flash('Please choose a show.', 'error');
|
|
} elseif (setBroadcastShow($db, (int)$show['id']) === 'live') {
|
|
flash("The live broadcast is now {$show['name']}.");
|
|
} else {
|
|
flash("{$show['name']} is queued. It will go live as soon as the stream starts.");
|
|
}
|
|
} elseif ($action === 'clear_queue') {
|
|
clearQueuedShow($db);
|
|
flash('The queued show has been cleared.');
|
|
}
|
|
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
$live = liveBroadcast($db);
|
|
$current = currentShow($db);
|
|
$shows = $db->query('SELECT id, name FROM shows ORDER BY name')->fetchAll();
|
|
|
|
adminHeader('Dashboard', $admin);
|
|
?>
|
|
<h3>Broadcast status</h3>
|
|
<p>
|
|
<?php if ($live): ?>
|
|
<strong>Live now</strong><?= $current ? ': ' . e($current['name']) : ' (no show set)' ?>, since <?= e($live['started_at']) ?> UTC.
|
|
<?php elseif ($current): ?>
|
|
Offline. <strong><?= e($current['name']) ?></strong> is queued for the next broadcast.
|
|
<?php else: ?>
|
|
Offline. No show is queued.
|
|
<?php endif; ?>
|
|
</p>
|
|
|
|
<h3><?= $live ? 'Change the live show' : 'Queue the next show' ?></h3>
|
|
<p><?= $live
|
|
? 'Switch which show the live page and recently played list belong to.'
|
|
: 'Choose the show before you start streaming. The broadcast goes live on the site automatically when the stream comes online.' ?></p>
|
|
<form method="post" action="index.php">
|
|
<?= csrfField() ?>
|
|
<input type="hidden" name="action" value="set_show" />
|
|
<div class="row gtr-uniform gtr-50">
|
|
<div class="col-8 col-12-small">
|
|
<select name="show_id" aria-label="Show" required>
|
|
<option value="">Choose a show…</option>
|
|
<?php foreach ($shows as $show): ?>
|
|
<option value="<?= (int)$show['id'] ?>"<?= $current && $current['id'] == $show['id'] ? ' selected' : '' ?>><?= e($show['name']) ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="col-4 col-12-small">
|
|
<input type="submit" class="primary fit" value="<?= $live ? 'Switch show' : 'Queue show' ?>" />
|
|
</div>
|
|
</div>
|
|
</form>
|
|
|
|
<?php if (!$live && $current): ?>
|
|
<form method="post" action="index.php">
|
|
<?= csrfField() ?>
|
|
<input type="hidden" name="action" value="clear_queue" />
|
|
<input type="submit" class="small" value="Clear queued show" />
|
|
</form>
|
|
<?php endif; ?>
|
|
<?php
|
|
adminFooter();
|