<?php
include '../../includes/conn.php';
include '../../includes/functions.php';
requireRole('teacher');

if (!isset($_GET['question_id'])) {
    die("Question ID not provided.");
}

$question_id = $_GET['question_id'];

// Get exam ID before deleting (for redirect)
$stmt = $pdo->prepare("SELECT exam_id FROM cbt_questions WHERE id = ?");
$stmt->execute([$question_id]);
$question = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$question) {
    die("Question not found.");
}

$exam_id = $question['exam_id'];

// Delete the question
$delete_stmt = $pdo->prepare("DELETE FROM cbt_questions WHERE id = ?");
$delete_stmt->execute([$question_id]);

header("Location: add_questions.php?exam_id=" . $exam_id . "&deleted=1");
exit;
?>
