<?php
session_start();
require_once '../includes/config.php';
require_once '../includes/functions.php';

// Cek apakah user sudah login dan memiliki akses admin
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] != 'admin') {
    header('Location: ../login.php');
    exit;
}

if (isset($_GET['id']) && !empty($_GET['id'])) {
    try {
        $stmt = $pdo->prepare("DELETE FROM bank_soal_teori WHERE id = ?");
        $stmt->execute([$_GET['id']]);
        
        $_SESSION['success'] = 'Soal berhasil dihapus!';
    } catch (PDOException $e) {
        $_SESSION['error'] = 'Gagal menghapus soal: ' . $e->getMessage();
    }
}

header('Location: list_soal_teori.php');
exit;
?>