<?php
require_once __DIR__ . '/../includes/redirect_helper.php';
$name = htmlspecialchars($_POST['name']);
$song = htmlspecialchars($_POST['song']);
$message = htmlspecialchars($_POST['message']);
$timestamp = date("Y-m-d H:i:s");

$new = [
  "name" => $name,
  "song" => $song,
  "message" => $message,
  "timestamp" => $timestamp,
  "approved" => false,   // ✅ default to not approved
  "reply" => ""          // ✅ placeholder for admin reply
];

// Always point to the same file used by index.php
$file = __DIR__ . '/../data/requests.json';

$requests = file_exists($file) ? json_decode(file_get_contents($file), true) : [];
array_unshift($requests, $new);

file_put_contents($file, json_encode($requests, JSON_PRETTY_PRINT));

ah_redirect_back('/requests/index.php', ['sent' => 1]);
