<?php
require('connection.inc.php');
session_name('rubicon_admin');
session_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (!isset($_POST['csrf_token']) || $_POST['csrf_token'] !== $_SESSION['csrf_token']) {
        echo 'invalid_token';
        exit;
    }

    $id = intval($_POST['id']);
    $status = intval($_POST['status']);

    $sql = "UPDATE products SET product_status = $status WHERE product_id = $id";
    if (mysqli_query($conn, $sql)) {
        echo 'success';
    } else {
        echo 'error';
    }
}
?>
