<?php
require_once "../config/config.php";
require_once "../classes/Database.php";

$db = Database::getInstance();

$id    = intval($_POST['id']);
$field = $_POST['field'];
$value = intval($_POST['value']);

$allowed = [
    "is_active",
    "login_blocked",
    "can_search",
    "wallet_frozen",
    "credit_limit"
];

if (!in_array($field, $allowed)) {
    echo "INVALID FIELD";
    exit;
}

$sql = "UPDATE users SET $field = :value WHERE id = :id";
$ok = $db->query($sql, [":value"=>$value, ":id"=>$id]);

echo $ok ? "OK" : "ERROR";
