Add show management and going-live controls to admin
- admin/shows.php: list shows - admin/show_edit.php: add, edit and delete shows, with validated background image uploads saved under generated names - admin/index.php: queue the next show, switch the live show, or clear the queue - includes/broadcasts.php: setBroadcastShow() and clearQueuedShow(), shared by the dashboard and cli/set_show.php - includes/admin_layout.php: flash messages and Shows nav link Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
babb71660c
commit
6e61fc6bda
7 files changed
+297
-12
No files matched your search
+59
-6
@@ -6,22 +6,75 @@ 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);
|
||||
$show = currentShow($db);
|
||||
$current = currentShow($db);
|
||||
$shows = $db->query('SELECT id, name FROM shows ORDER BY name')->fetchAll();
|
||||
|
||||
adminHeader('Dashboard', $admin);
|
||||
?>
|
||||
<p>Logged in as <strong><?= e($admin['username']) ?></strong>.</p>
|
||||
|
||||
<h3>Broadcast status</h3>
|
||||
<p>
|
||||
<?php if ($live): ?>
|
||||
Live now<?= $show ? ': <strong>' . e($show['name']) . '</strong>' : ' (no show set)' ?>, since <?= e($live['started_at']) ?> UTC.
|
||||
<?php elseif ($show): ?>
|
||||
Offline. <strong><?= e($show['name']) ?></strong> is queued for the next broadcast.
|
||||
<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();
|
||||
Reference in new issue
Block a user