<?php
/**
 * 获取单个公告信息 API
 */
require_once dirname(__DIR__) . '/config.php';

header('Content-Type: application/json');

// 检查登录
if (!isLoggedIn()) {
    echo json_encode(['error' => true, 'message' => '请先登录']);
    exit;
}

$user = currentUser();
if ($user['role'] !== 'admin') {
    echo json_encode(['error' => true, 'message' => '无权限访问']);
    exit;
}

$id = intval($_GET['id'] ?? 0);
if ($id <= 0) {
    echo json_encode(['error' => true, 'message' => '参数错误']);
    exit;
}

$item = $db->fetchOne("SELECT * FROM announcements WHERE id = $id");
if ($item) {
    echo json_encode($item);
} else {
    echo json_encode(['error' => true, 'message' => '公告不存在']);
}