<?php
require_once __DIR__ . '/../includes/functions.php'; requireAdmin(); $id=(int)($_GET['id']??0);$item=getRelease($id);if(!$item){http_response_code(404);exit('Release not found.');}$error='';
if($_SERVER['REQUEST_METHOD']==='POST'){
 try{checkCsrf();$shot=uploadScreenshot($_FILES['screenshot']??[],$item['screenshot']);updateRelease($id,['title'=>trim((string)$_POST['title']),'description'=>trim((string)$_POST['description']),'platform'=>strtolower(trim((string)$_POST['platform'])),'game'=>strtolower(trim((string)$_POST['game'])),'tags'=>trim((string)$_POST['tags']),'screenshot'=>$shot,'featured'=>isset($_POST['featured'])?1:0,'updated_at'=>time()]);header('Location:edit.php?id='.$id.'&saved=1');exit;}catch(Throwable $e){$error=$e->getMessage();}
}
$item=getRelease($id);
?>
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Edit — 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 href="index.php">Releases</a><a href="upload.php">Upload</a></nav></div></header><main class="shell form-page"><span class="eyebrow">EDIT RELEASE #<?= $id ?></span><h1><?= htmlspecialchars($item['title']) ?></h1><?php if(isset($_GET['saved'])): ?><div class="success">Changes saved.</div><?php endif; ?><?php if($error): ?><div class="alert"><?= htmlspecialchars($error) ?></div><?php endif; ?><form class="admin-form" method="post" enctype="multipart/form-data"><input type="hidden" name="csrf" value="<?= htmlspecialchars(csrfToken()) ?>"><div class="form-grid"><label>Title<input name="title" required value="<?= htmlspecialchars($item['title']) ?>"></label><label>Platform<input name="platform" required value="<?= htmlspecialchars($item['platform']) ?>"></label><label>Game<input name="game" value="<?= htmlspecialchars($item['game']) ?>"></label><label>Tags<input name="tags" value="<?= htmlspecialchars($item['tags']) ?>"></label></div><label>Description<textarea name="description" rows="7"><?= htmlspecialchars($item['description']) ?></textarea></label><label>Replace screenshot<input type="file" name="screenshot" accept="image/png,image/jpeg,image/webp"></label><?php if($item['screenshot_url']): ?><img class="admin-preview" src="../<?= htmlspecialchars($item['screenshot_url']) ?>" alt=""><?php endif; ?><label class="check"><input type="checkbox" name="featured" value="1" <?= $item['featured']?'checked':'' ?>> Feature this release</label><button class="primary-btn" type="submit">Save changes</button><a class="ghost-btn" href="../release.php?id=<?= $id ?>">View public page</a></form></main></body></html>
