<?php
// Script to add sample online exam data for testing

require_once __DIR__ . '/../config/database.php';

try {
    // Insert a sample online exam
    $stmt = $pdo->prepare("INSERT INTO online_exams (name, class_id, subject_id, exam_date, start_time, end_time, duration, total_marks, pass_marks, created_by, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
    $stmt->execute(['অনলাইন গণিত পরীক্ষা', 9, 3, '2025-10-20', '10:00:00', '11:00:00', 60, 100, 33, 1, 'scheduled']);
    $online_exam_id = $pdo->lastInsertId();
    
    echo "Sample online exam created with ID: " . $online_exam_id . "\n";
    
    // Insert sample questions for online exam
    $questions = [
        [
            'online_exam_id' => $online_exam_id,
            'subject_id' => 3,
            'question_text' => '2 + 2 = ?',
            'question_type' => 'mcq',
            'option_a' => '3',
            'option_b' => '4',
            'option_c' => '5',
            'option_d' => '6',
            'correct_answer' => 'B',
            'marks' => 1
        ],
        [
            'online_exam_id' => $online_exam_id,
            'subject_id' => 3,
            'question_text' => 'What is the area of a circle?',
            'question_type' => 'mcq',
            'option_a' => 'πr²',
            'option_b' => '2πr',
            'option_c' => 'πd',
            'option_d' => '2r',
            'correct_answer' => 'A',
            'marks' => 2
        ],
        [
            'online_exam_id' => $online_exam_id,
            'subject_id' => 3,
            'question_text' => 'Explain Pythagorean theorem',
            'question_type' => 'short',
            'marks' => 5
        ]
    ];
    
    foreach ($questions as $question) {
        if ($question['question_type'] === 'mcq') {
            $stmt = $pdo->prepare("INSERT INTO online_exam_questions (online_exam_id, subject_id, question_text, question_type, option_a, option_b, option_c, option_d, correct_answer, marks) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
            $stmt->execute([
                $question['online_exam_id'],
                $question['subject_id'],
                $question['question_text'],
                $question['question_type'],
                $question['option_a'],
                $question['option_b'],
                $question['option_c'],
                $question['option_d'],
                $question['correct_answer'],
                $question['marks']
            ]);
        } else {
            $stmt = $pdo->prepare("INSERT INTO online_exam_questions (online_exam_id, subject_id, question_text, question_type, marks) VALUES (?, ?, ?, ?, ?)");
            $stmt->execute([
                $question['online_exam_id'],
                $question['subject_id'],
                $question['question_text'],
                $question['question_type'],
                $question['marks']
            ]);
        }
        echo "Online exam question added: " . $question['question_text'] . "\n";
    }
    
    echo "Sample online exam data added successfully!\n";
    
} catch (PDOException $e) {
    echo "Error: " . $e->getMessage() . "\n";
}

?>