<?php
require_once '../../config.php';
requireRole('admin');

$conn = connectDB();

if (isset($_POST['new_status'])) {
    $new_status = ($_POST['new_status'] == '1') ? '1' : '0';
    
    $update_sql = "UPDATE settings SET setting_value = ? WHERE setting_name = 'show_results'";
    $stmt = $conn->prepare($update_sql);
    $stmt->bind_param("s", $new_status);
    
    if ($stmt->execute()) {
        echo json_encode(['success' => true]);
    } else {
        echo json_encode(['success' => false, 'error' => $conn->error]);
    }
    
    $stmt->close();
} else {
    echo json_encode(['success' => false, 'error' => 'No status provided']);
}

$conn->close();
?>