<?php
require_once __DIR__ . '/../includes/functions.php'; requireAdmin(); syncDownloads();
if($_SERVER['REQUEST_METHOD']==='POST' && isset($_POST['delete_id'])){checkCsrf();$id=(int)$_POST['delete_id'];$item=getRelease($id);if($item){$path=safeDownloadPath($item['file_path']);if($path)@unlink($path);if($item['screenshot'])@unlink(SCREENSHOT_ROOT.'/'.basename($item['screenshot']));deleteReleaseRecord($id);}header('Location:index.php');exit;}
$items=getReleases(['sort'=>'newest']);
?>
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Manage Releases — PhantomNET</title><link rel="stylesheet" href="../assets/css/style.css"></head><body><header class="site-header"><div class="shell nav-wrap"><a class="brand" href="../index.php"><span class="brand-mark">P</span><span><strong>PhantomNET</strong><small>Admin</small></span></a><nav><a class="active" href="index.php">Releases</a><a href="upload.php">Upload</a><a href="logout.php">Log out</a></nav></div></header><main class="shell admin-page"><div class="admin-heading"><div><span class="eyebrow">ADMIN</span><h1>Manage releases</h1></div><a class="primary-btn" href="upload.php">+ Upload release</a></div><div class="admin-table-wrap"><table class="admin-table"><thead><tr><th>Release</th><th>Platform</th><th>Downloads</th><th>Featured</th><th></th></tr></thead><tbody><?php foreach($items as $i): ?><tr><td><strong><?= htmlspecialchars($i['title']) ?></strong><small><?= htmlspecialchars($i['filename']) ?></small></td><td><?= htmlspecialchars(strtoupper($i['platform'])) ?></td><td><?= number_format((int)$i['downloads']) ?></td><td><?= $i['featured']?'Yes':'No' ?></td><td class="actions"><a href="edit.php?id=<?= (int)$i['id'] ?>">Edit</a><form method="post" onsubmit="return confirm('Delete this release and its file?')"><input type="hidden" name="csrf" value="<?= htmlspecialchars(csrfToken()) ?>"><input type="hidden" name="delete_id" value="<?= (int)$i['id'] ?>"><button type="submit">Delete</button></form></td></tr><?php endforeach; ?></tbody></table></div></main></body></html>
