<?php
header("Content-Type: application/json");
require("../includes/config.php");

$data = json_decode(file_get_contents("php://input"), true);

if (!isset($data['id']) || !isset($data['status'])) {
    echo json_encode(["status"=>"error","message"=>"Invalid request"]);
    exit;
}

$id = (int)$data['id'];
$status = (int)$data['status'];

try {
    $stmt = $pdo->prepare(
        "UPDATE subjects SET status = ? WHERE id = ?"
    );
    $stmt->execute([$status, $id]);

    echo json_encode([
        "status"=>"success",
        "message"=>"Status updated"
    ]);
} catch (Exception $e) {
    echo json_encode([
        "status"=>"error",
        "message"=>"Update failed"
    ]);
}
?>