<?php
require_once __DIR__ . '/../includes/redirect_helper.php';
session_start();

// Only master/admin can delete DJs
$role = $_SESSION['role'] ?? 'guest';
if (!in_array($role, ['master','admin'])) {
  header('Location: /login/index.php');
  exit;
}

$file = __DIR__ . '/../data/djs.txt';

if (isset($_GET['delete'])) {
  $deleteId = (int)$_GET['delete'];

  if (file_exists($file)) {
    $entries = explode("---\n", file_get_contents($file));

    if (isset($entries[$deleteId])) {
      unset($entries[$deleteId]);
      $newContent = implode("---\n", $entries);
      file_put_contents($file, $newContent);
    }
  }
}

// Redirect back to manage DJs
ah_redirect_back('/admin/djs.php', ['saved' => 1]);
