<?php
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../includes/functions.php';

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

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

// 检查权限
$user = currentUser();
if ($user['role'] !== 'admin' && $user['role'] !== 'employee') {
    echo json_encode(['success' => false, 'message' => '权限不足']);
    exit;
}

// 获取参数
$id = intval($_POST['id'] ?? 0);
$status = intval($_POST['status'] ?? 0);

if ($id <= 0) {
    echo json_encode(['success' => false, 'message' => '用户ID无效']);
    exit;
}

// 更新用户状态（只允许修改普通用户）
$db->query("UPDATE users SET status = $status WHERE id = $id AND role = 'user'");

echo json_encode(['success' => true, 'message' => '状态更新成功']);
exit;