<?php $pageTitle='Requests — Almost Heaven Radio'; include __DIR__ . '/header.php'; include __DIR__ . '/menu.php'; $sent=isset($_GET['sent'])&&$_GET['sent']==='1'; $requestsFile=__DIR__.'/data/requests.txt'; $statusFile=__DIR__.'/data/request_status.json'; $statusMap=file_exists($statusFile)?json_decode((string)file_get_contents($statusFile),true):[]; if(!is_array($statusMap)) $statusMap=[]; function req_parse($file){ if(!file_exists($file) || filesize($file)===0) return []; $raw=trim((string)file_get_contents($file)); if($raw==='') return []; $out=[]; if(strpos($raw,'---')!==false){ foreach(preg_split('/
---\s*
/',$raw) as $block){ $block=trim($block); if($block==='') continue; $item=['_raw'=>$block]; foreach(preg_split('/\R/',$block) as $line){ if(preg_match('/^([^:]+):\s*(.*)$/',$line,$m)) $item[strtolower(trim($m[1]))]=trim($m[2]); } $out[]=$item; } } return array_reverse($out);} $items=req_parse($requestsFile); ?>
<main class="content-area"><div class="content-wrapper page-shell"><section class="content-card"><h1>🎶 Song Requests</h1><p>Send a request to the station and see approved requests below.</p><?php if($sent): ?><div class="comment-item">Request sent successfully.</div><?php endif; ?><form method="post" action="/send_request.php" class="d-grid" style="gap:14px;margin-top:18px;"><div class="row g-3"><div class="col-md-6"><input type="text" name="name" placeholder="Your name" required></div><div class="col-md-6"><input type="email" name="email" placeholder="Your email" required></div></div><div class="row g-3"><div class="col-md-6"><input type="text" name="song" placeholder="Song title" required></div><div class="col-md-6"><input type="text" name="artist" placeholder="Artist" required></div></div><textarea name="dedication" rows="5" placeholder="Dedication or note"></textarea><div><button class="play-button" type="submit">Send Request</button></div></form></section><section class="content-card"><h2>Approved Requests</h2><div class="table-like-list"><?php $shown=0; foreach($items as $item): $raw=(string)($item['_raw'] ?? ''); $approved=(string)($item['approved'] ?? '0'); $id=(string)($item['id'] ?? md5($raw)); $state=$statusMap[$id]['status'] ?? null; $publicShow=($state==='approved' || strtolower($approved)==='1'); if(!$publicShow) continue; $shown++; ?><li><strong><?= htmlspecialchars(($item['song'] ?? 'Song')) ?> — <?= htmlspecialchars(($item['artist'] ?? 'Artist')) ?></strong><br><span>Requested by <?= htmlspecialchars(($item['name'] ?? 'Listener')) ?></span><?php if(!empty($item['dedication'])): ?><br><span><?= htmlspecialchars($item['dedication']) ?></span><?php endif; ?></li><?php endforeach; if(!$shown): ?><li>No approved requests are live yet.</li><?php endif; ?></div></section></div></main>
<?php include __DIR__ . '/footer.php'; ?>