<?php
session_start();
require_once 'db_connect.php';

if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
    header("Location: admin-login.php");
    exit;
}

if (isset($_GET['id']) && isset($_GET['status'])) {
    $userId = intval($_GET['id']);
    $newStatus = $_GET['status'];

    $allowedStatuses = ['active', 'frozen', 'deleted'];
    if (in_array($newStatus, $allowedStatuses)) {
        $stmt = $conn->prepare("UPDATE users SET status = ?, updated_at = NOW() WHERE id = ?");
        $stmt->bind_param("si", $newStatus, $userId);
        $stmt->execute();
        $stmt->close();
    }
}

header("Location: admin-dashboard.php");
exit;
