<?php $pageTitle='Poll — Almost Heaven Radio'; include __DIR__ . '/../header.php'; include __DIR__ . '/../menu.php'; $pollFile=__DIR__.'/../data/poll.json'; $votesFile=__DIR__.'/../data/poll_votes.json'; $poll=file_exists($pollFile)?json_decode((string)file_get_contents($pollFile),true):[]; if(!is_array($poll)) $poll=[]; $poll=array_merge(['question'=>'','options'=>[]],$poll); $votes=file_exists($votesFile)?json_decode((string)file_get_contents($votesFile),true):[]; if(!is_array($votes)) $votes=[]; $message = isset($_GET['voted']) ? 'Thanks for voting!' : ''; $total=array_sum(array_map('intval',$votes)); ?>
<main class="content-area"><div class="content-wrapper page-shell"><section class="content-card"><h1>📊 Station Poll</h1><?php if($message): ?><div class="comment-item"><?= htmlspecialchars($message) ?></div><?php endif; ?><?php if(empty($poll['question']) || empty($poll['options'])): ?><p>No poll is live right now.</p><?php else: ?><p><strong><?= htmlspecialchars($poll['question']) ?></strong></p><form method="post" action="submit_vote.php" class="d-grid" style="gap:12px;margin-top:14px;"><input type="hidden" name="return_to" value="<?= htmlspecialchars($_SERVER['REQUEST_URI'] ?? '/poll/index.php') ?>"><?php foreach((array)$poll['options'] as $opt): ?><label class="comment-item" style="display:flex;justify-content:space-between;align-items:center;gap:14px;"><span><input type="radio" name="option" value="<?= htmlspecialchars((string)$opt) ?>" required> <span style="margin-left:10px;"><?= htmlspecialchars((string)$opt) ?></span></span><strong><?= (int)($votes[$opt] ?? 0) ?></strong></label><?php endforeach; ?><div><button class="play-button" type="submit">Vote</button></div></form><p class="text-muted" style="margin-top:12px;">Total votes: <?= (int)$total ?></p><?php endif; ?></section></div></main>
<?php include __DIR__ . '/../footer.php'; ?>
