<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
header("Content-Type: application/json");
require("../../includes/config.php");

$enrollment_id = $_POST['id'] ?? null;
$new_status = $_POST['status'] ?? null;

// 2. Execute the update
$stmt = $pdo->prepare("UPDATE enrollments SET promotion_status = ? WHERE id = ?");
$stmt->execute([$new_status, $enrollment_id]);

// 3. CHECK IF IT ACTUALLY WORKED
if ($stmt->rowCount() > 0) {
    echo json_encode(['success' => true]);
} else {
    // If we are here, the SQL ran but nothing changed in the DB
    echo json_encode([
        'success' => false, 
        'message' => 'No changes made. Either the ID is wrong or the status was already ' . $new_status
    ]);
}
?>