<?php
include('db.php');

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $topic_id = $_POST['topic_id'];
    $allow_retakes = $_POST['allow_retakes'];

    // Update the allow_retakes field in the topics table
    $query = "UPDATE topics SET allow_retakes = :allow_retakes WHERE id = :topic_id";
    $stmt = $pdo->prepare($query);
    $stmt->execute([
        'allow_retakes' => $allow_retakes,
        'topic_id' => $topic_id
    ]);

    // Redirect back to quiz_management.php with success message
    header('Location: quiz_management.php?retakes=updated');
    exit;
}
?>