Path : /home/vishqocm/pcib.in/student/
File Upload :
Current File : /home/vishqocm//pcib.in/student/exam-results.php

<?php
$pageTitle = "Exam Results";
include_once('includes/header.php');

// Get student ID
$student_id = $_SESSION['user_id'];

// Check if specific exam ID is provided
$exam_id = isset($_GET['id']) ? intval($_GET['id']) : 0;

// If exam ID is provided, show detailed result
if ($exam_id > 0) {
    // Get exam details and student's result
    $query = "
        SELECT se.*, es.title as exam_title, es.description, es.passing_percentage,
               es.exam_date, es.duration_minutes,
               c.title as course_title, c.image as course_image,
               CONCAT(i.first_name, ' ', i.last_name) as instructor_name
        FROM student_exams se
        JOIN exam_schedules es ON se.exam_id = es.id
        JOIN courses c ON es.course_id = c.id
        LEFT JOIN users i ON c.instructor_id = i.id
        LEFT JOIN enrollments e ON e.course_id = c.id AND e.user_id = se.user_id
        WHERE se.user_id = ? AND se.exam_id = ?
        ORDER BY se.attempt_date DESC
        LIMIT 1
    ";
    
    $stmt = $conn->prepare($query);
    $stmt->bind_param("ii", $student_id, $exam_id);
    $stmt->execute();
    $result = $stmt->get_result();
    
    if ($result->num_rows > 0) {
        $exam_result = $result->fetch_assoc();
        
        // Get exam questions and student's answers
        $questions_query = "
            SELECT eq.*, eq.question_text, eq.mark, eq.question_type,
                   sea.selected_option, sea.answer_text,
                   CASE 
                       WHEN eq.question_type = 'mcq' AND sea.selected_option = eq.correct_option THEN 'correct'
                       WHEN eq.question_type = 'descriptive' AND sea.marks_awarded IS NOT NULL THEN 
                           CASE WHEN sea.marks_awarded = eq.mark THEN 'correct'
                                WHEN sea.marks_awarded = 0 THEN 'incorrect'
                                ELSE 'partial' END
                       WHEN sea.selected_option IS NOT NULL OR sea.answer_text IS NOT NULL THEN 'incorrect'
                       ELSE 'unanswered' 
                   END as status,
                   sea.marks_awarded
            FROM exam_questions eq
            LEFT JOIN student_exam_answers sea ON sea.question_id = eq.id AND sea.student_exam_id = ?
            WHERE eq.exam_id = ?
            ORDER BY eq.question_order ASC
        ";
        
        $q_stmt = $conn->prepare($questions_query);
        $q_stmt->bind_param("ii", $exam_result['id'], $exam_id);
        $q_stmt->execute();
        $questions = $q_stmt->get_result();
        
        // Calculate statistics
        $total_questions = $questions->num_rows;
        $answered = 0;
        $correct = 0;
        $incorrect = 0;
        $partial = 0;
        
        $temp_questions = [];
        while ($q = $questions->fetch_assoc()) {
            $temp_questions[] = $q;
            
            if ($q['status'] != 'unanswered') {
                $answered++;
                
                if ($q['status'] == 'correct') {
                    $correct++;
                } else if ($q['status'] == 'incorrect') {
                    $incorrect++;
                } else if ($q['status'] == 'partial') {
                    $partial++;
                }
            }
        }
        $questions_data = $temp_questions;
        
        // Get certificate info if exam is passed
        $certificate_query = "
            SELECT ec.*
            FROM exam_certificates ec
            JOIN student_exams se ON ec.student_exam_id = se.id
            WHERE se.user_id = ? AND se.exam_id = ? AND se.status = 'passed'
        ";
        
        $cert_stmt = $conn->prepare($certificate_query);
        $cert_stmt->bind_param("ii", $student_id, $exam_id);
        $cert_stmt->execute();
        $cert_result = $cert_stmt->get_result();
        $certificate = $cert_result->num_rows > 0 ? $cert_result->fetch_assoc() : null;
        
        if ($exam_result['status'] == 'failed') {
            // Check if 7 days have passed since the attempt
            $attempt_date = new DateTime($exam_result['attempt_date']);
            $current_date = new DateTime();
            $days_passed = $current_date->diff($attempt_date)->days;
            $can_reattempt = ($days_passed >= 7);
            
            // Check if student has already paid for a re-attempt
            $payment_query = "
                SELECT * FROM payments 
                WHERE user_id = ? AND exam_id = ? AND payment_type = 'reattempt_fee' 
                AND status = 'completed' AND created_at > ?
            ";
            
            $payment_stmt = $conn->prepare($payment_query);
            $one_week_ago = date('Y-m-d H:i:s', strtotime('-7 days'));
            $payment_stmt->bind_param("iis", $student_id, $exam_id, $one_week_ago);
            $payment_stmt->execute();
            $payment_result = $payment_stmt->get_result();
            $has_paid = $payment_result->num_rows > 0;
        }
    } else {
        $_SESSION['error_message'] = "Exam result not found or you haven't taken this exam yet.";
        header("Location: scheduled-exams.php");
        exit();
    }
} else {
    // Get all exam results for the student
    $query = "
        SELECT se.*, es.title as exam_title, es.passing_percentage,
               es.exam_date, c.title as course_title,
               c.image as course_image, c.id as course_id
        FROM student_exams se
        JOIN exam_schedules es ON se.exam_id = es.id
        JOIN courses c ON es.course_id = c.id
        WHERE se.user_id = ?
        ORDER BY se.attempt_date DESC
    ";
    
    $stmt = $conn->prepare($query);
    $stmt->bind_param("i", $student_id);
    $stmt->execute();
    $results = $stmt->get_result();
}
?>

<div class="container py-4">
    <?php if (isset($_SESSION['success_message'])): ?>
    <div class="alert alert-success alert-dismissible fade show" role="alert">
        <i class="fas fa-check-circle me-2"></i> <?php echo $_SESSION['success_message']; ?>
        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
    </div>
    <?php unset($_SESSION['success_message']); endif; ?>
    
    <?php if (isset($_SESSION['error_message'])): ?>
    <div class="alert alert-danger alert-dismissible fade show" role="alert">
        <i class="fas fa-exclamation-circle me-2"></i> <?php echo $_SESSION['error_message']; ?>
        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
    </div>
    <?php unset($_SESSION['error_message']); endif; ?>

    <?php if ($exam_id > 0 && isset($exam_result)): ?>
        <!-- Detailed Exam Result View -->
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h2>Exam Result: <?php echo htmlspecialchars($exam_result['exam_title']); ?></h2>
            <a href="exam-results.php" class="btn btn-outline-primary">
                <i class="fas fa-arrow-left me-2"></i>Back to All Results
            </a>
        </div>
        
        <!-- Result Summary Card -->
        <div class="card mb-4">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0"><i class="fas fa-chart-pie me-2"></i>Result Summary</h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6">
                        <div class="d-flex align-items-center mb-3">
                            <?php if (!empty($exam_result['course_image'])): ?>
                                <img src="../<?php echo htmlspecialchars($exam_result['course_image']); ?>" alt="Course Image" class="me-3 rounded" style="width: 80px; height: 80px; object-fit: cover;">
                            <?php else: ?>
                                <div class="me-3 rounded bg-light d-flex align-items-center justify-content-center" style="width: 80px; height: 80px;">
                                    <i class="fas fa-book fa-2x text-primary"></i>
                                </div>
                            <?php endif; ?>
                            <div>
                                <h5 class="mb-1"><?php echo htmlspecialchars($exam_result['course_title']); ?></h5>
                                <p class="mb-1 text-muted">Instructor: <?php echo htmlspecialchars($exam_result['instructor_name']); ?></p>
                                <p class="mb-0 text-muted">
                                    <i class="far fa-calendar-alt me-1"></i> 
                                    <?php echo date('d M Y', strtotime($exam_result['exam_date'])); ?>
                                </p>
                            </div>
                        </div>
                        
                        <div class="mb-3">
                            <p class="mb-1"><strong>Attempt Date:</strong> <?php echo date('d M Y h:i A', strtotime($exam_result['attempt_date'])); ?></p>
                            <p class="mb-1"><strong>Time Taken:</strong> <?php echo $exam_result['time_taken']; ?> minutes</p>
                            <p class="mb-1"><strong>Passing Percentage:</strong> <?php echo $exam_result['passing_percentage']; ?>%</p>
                        </div>
                        
                        <div class="alert <?php echo $exam_result['status'] == 'passed' ? 'alert-success' : 'alert-danger'; ?>">
                            <div class="d-flex align-items-center">
                                <div class="me-3">
                                    <?php if ($exam_result['status'] == 'passed'): ?>
                                        <i class="fas fa-check-circle fa-3x"></i>
                                    <?php else: ?>
                                        <i class="fas fa-times-circle fa-3x"></i>
                                    <?php endif; ?>
                                </div>
                                <div>
                                    <h5 class="alert-heading mb-1">
                                        <?php echo $exam_result['status'] == 'passed' ? 'Congratulations!' : 'Better Luck Next Time!'; ?>
                                    </h5>
                                    <p class="mb-0">
                                        <?php if ($exam_result['status'] == 'passed'): ?>
                                            You have successfully passed this exam with a score of <?php echo $exam_result['percentage']; ?>%.
                                        <?php else: ?>
                                            You did not pass this exam. Your score was <?php echo $exam_result['percentage']; ?>%, but you needed <?php echo $exam_result['passing_percentage']; ?>% to pass.
                                        <?php endif; ?>
                                    </p>
                                </div>
                            </div>
                        </div>
                        
                        <?php if ($certificate): ?>
                        <div class="mt-3">
                            <a href="../verify-certificate.php?cert=<?php echo urlencode($certificate['certificate_number']); ?>" class="btn btn-success" target="_blank">
                                <i class="fas fa-certificate me-2"></i> View Certificate
                            </a>
                        </div>
                        <?php endif; ?>
                    </div>
                    <div class="col-md-6">
                        <div class="card h-100">
                            <div class="card-body">
                                <h5 class="card-title">Score Breakdown</h5>
                                <div class="d-flex justify-content-center align-items-center mb-4" style="height: 200px;">
                                    <div class="position-relative" style="width: 180px; height: 180px;">
                                        <div class="position-absolute top-50 start-50 translate-middle text-center">
                                            <h3 class="mb-0"><?php echo $exam_result['percentage']; ?>%</h3>
                                            <p class="mb-0 small text-muted">Total Score</p>
                                        </div>
                                        <canvas id="scoreChart" width="180" height="180"></canvas>
                                    </div>
                                </div>
                                
                                <div class="row text-center">
                                    <div class="col-4">
                                        <div class="p-3 rounded bg-success bg-opacity-10 mb-2">
                                            <h3 class="mb-0 text-success"><?php echo $correct; ?></h3>
                                        </div>
                                        <p class="small mb-0">Correct</p>
                                    </div>
                                    <div class="col-4">
                                        <div class="p-3 rounded bg-danger bg-opacity-10 mb-2">
                                            <h3 class="mb-0 text-danger"><?php echo $incorrect; ?></h3>
                                        </div>
                                        <p class="small mb-0">Incorrect</p>
                                    </div>
                                    <div class="col-4">
                                        <div class="p-3 rounded bg-warning bg-opacity-10 mb-2">
                                            <h3 class="mb-0 text-warning"><?php echo $total_questions - $answered; ?></h3>
                                        </div>
                                        <p class="small mb-0">Unanswered</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- Questions and Answers -->
        <div class="card mb-4">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0"><i class="fas fa-list-ol me-2"></i>Questions and Answers</h5>
            </div>
            <div class="card-body">
                <div class="accordion" id="accordionQuestions">
                    <?php foreach ($questions_data as $index => $question): ?>
                        <div class="accordion-item mb-3">
                            <h2 class="accordion-header" id="heading<?php echo $index; ?>">
                                <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapse<?php echo $index; ?>" aria-expanded="false" aria-controls="collapse<?php echo $index; ?>">
                                    <div class="d-flex align-items-center w-100">
                                        <div class="me-3">
                                            <?php if ($question['status'] == 'correct'): ?>
                                                <span class="badge bg-success rounded-circle"><i class="fas fa-check"></i></span>
                                            <?php elseif ($question['status'] == 'incorrect'): ?>
                                                <span class="badge bg-danger rounded-circle"><i class="fas fa-times"></i></span>
                                            <?php elseif ($question['status'] == 'partial'): ?>
                                                <span class="badge bg-warning rounded-circle"><i class="fas fa-adjust"></i></span>
                                            <?php else: ?>
                                                <span class="badge bg-secondary rounded-circle"><i class="fas fa-minus"></i></span>
                                            <?php endif; ?>
                                        </div>
                                        <div class="flex-grow-1">
                                            <div>Question <?php echo $index + 1; ?>: <?php echo htmlspecialchars($question['question_text']); ?></div>
                                            <div class="small text-muted">
                                                <?php echo ucfirst($question['question_type']); ?> | 
                                                Marks: <?php echo isset($question['marks_awarded']) ? $question['marks_awarded'] : 0; ?>/<?php echo $question['mark']; ?>
                                            </div>
                                        </div>
                                    </div>
                                </button>
                            </h2>
                            <div id="collapse<?php echo $index; ?>" class="accordion-collapse collapse" aria-labelledby="heading<?php echo $index; ?>" data-bs-parent="#accordionQuestions">
                                <div class="accordion-body">
                                    <?php if ($question['question_type'] == 'mcq'): ?>
                                        <div class="mb-3">
                                            <p><strong>Options:</strong></p>
                                            <div class="ms-3">
                                                <?php for ($i = 1; $i <= 4; $i++): ?>
                                                    <?php 
                                                        $option_class = '';
                                                        if ($i == $question['correct_option']) {
                                                            $option_class = 'text-success fw-bold';
                                                        }
                                                        if ($i == $question['selected_option'] && $i != $question['correct_option']) {
                                                            $option_class = 'text-danger fw-bold';
                                                        }
                                                    ?>
                                                    <div class="mb-2 <?php echo $option_class; ?>">
                                                        <div class="d-flex">
                                                            <div class="me-2"><?php echo chr(64 + $i); ?>.</div>
                                                            <div><?php echo htmlspecialchars($question['option' . $i]); ?></div>
                                                        </div>
                                                    </div>
                                                <?php endfor; ?>
                                            </div>
                                        </div>
                                        
                                        <div class="row">
                                            <div class="col-md-6">
                                                <p><strong>Your Answer:</strong> 
                                                    <?php 
                                                        if ($question['selected_option']) {
                                                            echo chr(64 + $question['selected_option']) . '. ' . htmlspecialchars($question['option' . $question['selected_option']]);
                                                        } else {
                                                            echo 'Not answered';
                                                        }
                                                    ?>
                                                </p>
                                            </div>
                                            <div class="col-md-6">
                                                <p><strong>Correct Answer:</strong> 
                                                    <?php echo chr(64 + $question['correct_option']) . '. ' . htmlspecialchars($question['option' . $question['correct_option']]); ?>
                                                </p>
                                            </div>
                                        </div>
                                    <?php else: ?>
                                        <div class="mb-3">
                                            <p><strong>Your Answer:</strong></p>
                                            <div class="border p-3 rounded bg-light">
                                                <?php echo nl2br(htmlspecialchars($question['answer_text'] ?? 'Not answered')); ?>
                                            </div>
                                        </div>
                                        
                                        <?php if (isset($question['marks_awarded'])): ?>
                                        <div class="mb-3">
                                            <p><strong>Marks Awarded:</strong> <?php echo $question['marks_awarded']; ?> out of <?php echo $question['mark']; ?></p>
                                        </div>
                                        <?php endif; ?>
                                        
                                        <?php if (!empty($question['correct_answer'])): ?>
                                        <div class="mb-3">
                                            <p><strong>Model Answer:</strong></p>
                                            <div class="border p-3 rounded bg-light">
                                                <?php echo nl2br(htmlspecialchars($question['correct_answer'])); ?>
                                            </div>
                                        </div>
                                        <?php endif; ?>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
        
        <!-- Feedback and Improvement -->
        <div class="card">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0"><i class="fas fa-comment me-2"></i>Feedback and Improvement</h5>
            </div>
            <div class="card-body">
                <?php if ($exam_result['status'] == 'passed'): ?>
                    <div class="alert alert-success">
                        <h5><i class="fas fa-thumbs-up me-2"></i>Great job!</h5>
                        <p>You've successfully passed this exam. This demonstrates a good understanding of the course material.</p>
                    </div>
                    
                    <div class="mt-3">
                        <h5>Next Steps:</h5>
                        <ul>
                            <li>Download your certificate and add it to your profile</li>
                            <li>Explore advanced courses in this topic</li>
                            <li>Share your achievement with peers and on your professional profiles</li>
                        </ul>
                    </div>
                <?php else: ?>
                    <div class="alert alert-warning">
                        <h5><i class="fas fa-lightbulb me-2"></i>Areas for Improvement</h5>
                        <p>Don't worry about not passing this time. Here are some suggestions to help you improve:</p>
                    </div>
                    
                    <div class="mt-3">
                        <h5>Recommendations:</h5>
                        <ul>
                            <li>Review the topics where you struggled the most</li>
                            <li>Go through course materials again, focusing on areas with incorrect answers</li>
                            <li>Practice with additional exercises and sample questions</li>
                            <li>Consider reaching out to your instructor for additional guidance</li>
                        </ul>
                    </div>
                    
                    <div class="mt-4">
                        <a href="scheduled-exams.php" class="btn btn-primary">
                            <i class="fas fa-redo me-2"></i>Check if you can retake the exam
                        </a>
                    </div>
                <?php endif; ?>
            </div>
        </div>
        
        <!-- Chart.js for Score Chart -->
        <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
        <script>
            document.addEventListener('DOMContentLoaded', function() {
                // Score Pie Chart
                var ctx = document.getElementById('scoreChart').getContext('2d');
                var scoreChart = new Chart(ctx, {
                    type: 'doughnut',
                    data: {
                        labels: ['Correct', 'Incorrect', 'Unanswered'],
                        datasets: [{
                            data: [<?php echo $correct; ?>, <?php echo $incorrect; ?>, <?php echo $total_questions - $answered; ?>],
                            backgroundColor: [
                                'rgba(40, 167, 69, 0.8)',
                                'rgba(220, 53, 69, 0.8)',
                                'rgba(108, 117, 125, 0.8)'
                            ],
                            borderColor: [
                                'rgba(40, 167, 69, 1)',
                                'rgba(220, 53, 69, 1)',
                                'rgba(108, 117, 125, 1)'
                            ],
                            borderWidth: 1
                        }]
                    },
                    options: {
                        responsive: true,
                        maintainAspectRatio: false,
                        cutout: '75%',
                        plugins: {
                            legend: {
                                display: false
                            }
                        }
                    }
                });
            });
        </script>
        
        <?php if ($exam_id > 0 && isset($exam_result) && $exam_result['status'] == 'failed'): ?>
            <div class="card mt-4">
                <div class="card-header bg-warning">
                    <h5 class="mb-0 text-dark"><i class="fas fa-redo me-2"></i>Re-attempt Exam</h5>
                </div>
                <div class="card-body">
                    <?php if (!$can_reattempt): ?>
                        <div class="alert alert-info">
                            <i class="fas fa-info-circle me-2"></i> You can re-attempt this exam after 7 days from your last attempt. 
                            <?php 
                            $days_remaining = 7 - $days_passed;
                            echo "Please wait " . ($days_remaining == 1 ? "1 more day" : "$days_remaining more days") . " to re-attempt.";
                            ?>
                        </div>
                    <?php elseif ($has_paid): ?>
                        <div class="alert alert-success">
                            <i class="fas fa-check-circle me-2"></i> You have already paid the re-attempt fee. You can now re-attempt the exam.
                        </div>
                        <a href="take_exam.php?id=<?php echo $exam_id; ?>&reattempt=1" class="btn btn-primary">
                            <i class="fas fa-edit me-2"></i> Re-attempt Exam Now
                        </a>
                    <?php else: ?>
                        <div class="alert alert-light">
                            <p><i class="fas fa-info-circle me-2"></i> You can now re-attempt this exam with a payment of ₹50.</p>
                            <p>Re-attempting the exam gives you another chance to pass and earn your certificate.</p>
                        </div>
                        <form action="exam_payment.php" method="post">
                            <input type="hidden" name="exam_id" value="<?php echo $exam_id; ?>">
                            <input type="hidden" name="payment_type" value="reattempt_fee">
                            <input type="hidden" name="amount" value="50">
                            <button type="submit" class="btn btn-warning">
                                <i class="fas fa-credit-card me-2"></i> Pay ₹50 to Re-attempt
                            </button>
                        </form>
                    <?php endif; ?>
                </div>
            </div>
        <?php endif; ?>
    <?php else: ?>
        <!-- All Exam Results List View -->
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h2><?php echo $pageTitle; ?></h2>
            <a href="scheduled-exams.php" class="btn btn-outline-primary">
                <i class="fas fa-calendar-alt me-2"></i>View Upcoming Exams
            </a>
        </div>
        
        <?php if ($results->num_rows > 0): ?>
            <div class="row">
                <?php while ($result = $results->fetch_assoc()): ?>
                    <div class="col-md-6 col-lg-4 mb-4">
                        <div class="card h-100">
                            <div class="card-header d-flex justify-content-between align-items-center">
                                <h5 class="mb-0"><?php echo htmlspecialchars($result['exam_title']); ?></h5>
                                <span class="badge <?php echo $result['status'] == 'passed' ? 'bg-success' : 'bg-danger'; ?>">
                                    <?php echo ucfirst($result['status']); ?>
                                </span>
                            </div>
                            <div class="card-body">
                                <div class="d-flex align-items-center mb-3">
                                    <?php if (!empty($result['course_image'])): ?>
                                        <img src="../<?php echo htmlspecialchars($result['course_image']); ?>" alt="Course Image" class="me-3 rounded" style="width: 60px; height: 60px; object-fit: cover;">
                                    <?php else: ?>
                                        <div class="me-3 rounded bg-light d-flex align-items-center justify-content-center" style="width: 60px; height: 60px;">
                                            <i class="fas fa-book fa-2x text-primary"></i>
                                        </div>
                                    <?php endif; ?>
                                    <div>
                                        <h6 class="mb-1"><?php echo htmlspecialchars($result['course_title']); ?></h6>
                                        <p class="small text-muted mb-0">
                                            <i class="far fa-calendar-alt me-1"></i> 
                                            <?php echo date('d M Y', strtotime($result['attempt_date'])); ?>
                                        </p>
                                    </div>
                                </div>
                                
                                <div class="mb-3">
                                    <div class="progress" style="height: 10px;">
                                        <div class="progress-bar <?php echo $result['status'] == 'passed' ? 'bg-success' : 'bg-danger'; ?>" 
                                             role="progressbar" 
                                             style="width: <?php echo $result['percentage']; ?>%;" 
                                             aria-valuenow="<?php echo $result['percentage']; ?>" 
                                             aria-valuemin="0" 
                                             aria-valuemax="100">
                                        </div>
                                    </div>
                                    <div class="d-flex justify-content-between mt-1">
                                        <small>Score: <?php echo $result['percentage']; ?>%</small>
                                        <small>Passing: <?php echo $result['passing_percentage']; ?>%</small>
                                    </div>
                                </div>
                                
                                <div class="mb-3">
                                    <p class="small mb-1"><strong>Time Taken:</strong> <?php echo $result['time_taken']; ?> minutes</p>
                                    <p class="small mb-1"><strong>Total Questions:</strong> <?php echo $result['total_questions']; ?></p>
                                    <p class="small mb-0"><strong>Correct Answers:</strong> <?php echo $result['correct_answers']; ?></p>
                                </div>
                                
                                <div class="text-center mt-3">
                                    <a href="exam-results.php?id=<?php echo $result['exam_id']; ?>" class="btn btn-primary">
                                        <i class="fas fa-eye me-1"></i> View Details
                                    </a>
                                </div>
                            </div>
                            <div class="card-footer bg-white border-top-0 text-center">
                                <?php if ($result['status'] == 'passed'): ?>
                                    <a href="certificates.php" class="btn btn-outline-success btn-sm">
                                        <i class="fas fa-certificate me-1"></i> View Certificate
                                    </a>
                                <?php else: ?>
                                    <a href="scheduled-exams.php" class="btn btn-outline-secondary btn-sm">
                                        <i class="fas fa-sync me-1"></i> Check Retake Options
                                    </a>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                <?php endwhile; ?>
            </div>
        <?php else: ?>
            <div class="alert alert-info">
                <div class="d-flex">
                    <div class="me-3">
                        <i class="fas fa-info-circle fa-2x"></i>
                    </div>
                    <div>
                        <h5>No Exam Results Yet</h5>
                        <p class="mb-0">You haven't taken any exams yet. Check the upcoming exams schedule to see available exams.</p>
                        <a href="scheduled-exams.php" class="btn btn-primary mt-3">View Scheduled Exams</a>
                    </div>
                </div>
            </div>
        <?php endif; ?>
    <?php endif; ?>
</div>

<?php include_once('includes/footer.php'); ?>