<?php
require __DIR__ . '/../../app/bootstrap.php';
require __DIR__ . '/../../app/database.php';
require_login();

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    http_response_code(405);
    exit('Method Not Allowed');
}
require_csrf();
$adId = isset($_POST['id']) ? (int)$_POST['id'] : 0;
if ($adId <= 0) {
    redirect('/admin/ad/list.php?delete_status=error');
}

try {
    if (!delete_article_ad($adId)) {
        redirect('/admin/ad/list.php?delete_status=error');
    }
    log_admin_action('ad_delete', '删除广告 ID:' . $adId);
    redirect('/admin/ad/list.php?delete_status=success');
} catch (Exception $e) {
    redirect('/admin/ad/list.php?delete_status=error');
}
