<?php

namespace App\Controllers;

use Core\Controller;
use Core\Database;
use PDO;

class SetUjianController extends Controller
{
    private $db;

    public function __construct()
    {
        $this->db = Database::getConnection();
    }

    public function index()
    {
        if (isset($_GET['edit'])) {
            $id_jenis_s = $_GET['edit'];
    
            // Set semua tidak aktif
            $stmt = $this->db->prepare("UPDATE tb_jenis_soal SET status = 'Tidak Aktif'");
            $stmt->execute();
    
            // Aktifkan yang dipilih
            $update_stmt = $this->db->prepare("UPDATE tb_jenis_soal SET status = 'Aktif' WHERE id_jenis_s = ?");
            $update_stmt->execute([$id_jenis_s]);
    
            // Redirect ke route yang benar
            header("Location: /dashboard/pegawai-set_ujian");
            exit;
        }
    
        // Ambil semua jenis soal
        $query = $this->db->query("SELECT * FROM tb_jenis_soal");
        $jenis_jenis = $query->fetchAll(PDO::FETCH_ASSOC);
    
        require_once __DIR__ . '/../Views/pegawai/setujian.php';
    }

}
