<?php
session_start();
if (!isset($_SESSION['admin'])) {
    header("Location: index.php");
    exit;
}

if (isset($_GET['id'])) {
    $file = '../data/trading_tips.json';
    $tips = file_exists($file) ? json_decode(file_get_contents($file), true) : [];

    $id = (int) $_GET['id'];
    if (isset($tips[$id])) {
        array_splice($tips, $id, 1); // Remove the message at index
        file_put_contents($file, json_encode($tips, JSON_PRETTY_PRINT));
    }
}

header("Location: dashboard.php");
exit;
