<?php
ob_start();
require_once '../config.php';

// 检查登录
if (!isAdmin()) {
    header('Content-Type: application/json');
    echo json_encode(['error' => true, 'message' => '请先登录']);
    exit;
}

$id = intval($_GET['id'] ?? 0);
if ($id <= 0) {
    header('Content-Type: application/json');
    echo json_encode(['error' => true, 'message' => '参数错误']);
    exit;
}

$item = $db->fetchOne("SELECT * FROM announcements WHERE id = $id");

header('Content-Type: application/json');
if ($item) {
    echo json_encode($item);
} else {
    echo json_encode(['error' => true, 'message' => '公告不存在']);
}
exit;