<?php
$jsonFile = 'users.json';
$data = json_decode(file_get_contents($jsonFile), true);
$id = $_GET['id'] ?? null;

if ($id !== null && isset($data['users'][$id])) {
    $current_status = $data['users'][$id]['status'];
    $data['users'][$id]['status'] = ($current_status === 'approved') ? 'pending' : 'approved';

    file_put_contents($jsonFile, json_encode($data, JSON_PRETTY_PRINT));
    header("Location: admin.php");
    exit;
} else {
    echo "User not found.";
}
?>
