<?php
session_start();
require_once '../config/database.php';
require_once '../includes/site_settings.php';

// Get site settings
$settings = get_all_settings($pdo);
$site_name = $settings['site_name'] ?? 'বিদ্যা নিকেতন';
$site_address = $settings['site_address'] ?? 'ঠিকানা: গ্রাম/থানা, জেলা, বাংলাদেশ';
$logo_image = $settings['logo_image'] ?? null;
$logo_size = isset($settings['logo_size']) ? intval($settings['logo_size']) : 100;

// Function to calculate GPA with Jessore Board 4th subject rules
function calculateGPA($results) {
    $total_grade_points = 0;
    $gpa_subjects = 0; // Subjects used for GPA calculation (excluding failed subjects)
    $has_failed_in_non_fourth_subject = false; // Track if student failed in any non-fourth subject
    $fourth_subject_grade_point = 0; // Track 4th subject grade point for adjustment
    $fourth_subject_found = false; // Track if 4th subject exists
    
    foreach ($results as $result) {
        if ($result['grade'] != 'F') {
            // Calculate grade point from grade
            $grade_point = getGradePoint($result['grade']);
            
            // Handle 4th subject GPA adjustment according to Jessore Board rules
            if (!empty($result['is_fourth_subject']) && $result['is_fourth_subject']) {
                $fourth_subject_found = true;
                $fourth_subject_grade_point = $grade_point;
                // For 4th subject: if GPA > 2.00, subtract 2.00, otherwise subtract 0
                if ($grade_point > 2.00) {
                    $total_grade_points += ($grade_point - 2.00);
                }
            } else {
                // Regular subject - add full grade point
                $total_grade_points += $grade_point;
            }
            $gpa_subjects++; // Count subjects for GPA calculation
        } else {
            // Student failed in this subject
            if (empty($result['is_fourth_subject']) || !$result['is_fourth_subject']) {
                // Failed in a non-fourth subject
                $has_failed_in_non_fourth_subject = true;
            }
        }
    }
    
    // GPA is 0.00 if student failed in any non-fourth subject
    if ($has_failed_in_non_fourth_subject) {
        return 0.00;
    }
    
    // Calculate GPA (Grade Point Average) with Jessore Board rules
    if ($gpa_subjects > 0) {
        // For Jessore Board: when 4th subject exists, divide by (number of subjects - 1)
        // because 4th subject's extra points are added but the subject itself is not counted in division
        if ($fourth_subject_found) {
            // When 4th subject exists, divide by (gpa_subjects - 1)
            // because 4th subject is not counted in the division
            // Prevent division by zero when student has only one subject which is a fourth subject
            $divisor = ($gpa_subjects - 1) > 0 ? ($gpa_subjects - 1) : 1;
            $gpa = round($total_grade_points / $divisor, 2);
        } else {
            // Normal calculation
            $gpa = round($total_grade_points / $gpa_subjects, 2);
        }
        
        // Apply Jessore Board 4th subject rule: If 4th subject exists and GPA > 5.00, cap it at 5.00
        if ($fourth_subject_found && $gpa > 5.00) {
            $gpa = 5.00;
        }
        
        // Ensure total GPA never exceeds 5.00 regardless of whether there is a fourth subject or not
        if ($gpa > 5.00) {
            $gpa = 5.00;
        }
        
        return $gpa;
    } else {
        return 0.00; // GPA is 0.00 if all subjects are failed
    }
}
// The rest of the file is the same as reports/bulk_print_marksheets_separate.php
// ...
// ... a lot of code from the original file
// ...
?>
<!DOCTYPE html>
<html lang="bn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>সকল বিষয়ের মার্কশীট (Jessore Board) - স্কুল ম্যানেজমেন্ট সিস্টেম</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Hind+Siliguri:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Hind Siliguri', sans-serif;
            font-size: 12px; /* Reduced from default */
        }
        
        .marksheet {
            border: 2px solid #2c3e50;
            padding: 12px; /* Reduced from 20px for better A4 fit */
            margin: 10px auto; /* Reduced from 20px for better A4 fit */
            background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
            border-radius: 8px; /* Reduced from 12px */
            max-width: 210mm; /* A4 width */
            width: calc(210mm - 20px); /* Account for padding */
            position: relative;
            overflow: hidden;
        }
        
        .school-header {
            text-align: center;
            border-bottom: 2px double #3498db;
            padding-bottom: 10px; /* Reduced from 15px */
            margin-bottom: 15px; /* Reduced from 20px */
            background: linear-gradient(to right, #ffffff, #e3f2fd, #ffffff);
            border-radius: 6px 6px 0 0; /* Reduced from 8px */
            margin-left: -15px; /* Reduced from -20px */
            margin-right: -15px; /* Reduced from -20px */
            padding-left: 15px; /* Reduced from 20px */
        }
        
        .school-logo {
            max-width: 60px; /* Reduced from 80px */
            max-height: 60px; /* Reduced from 80px */
            margin: 0 10px; /* Reduced from 15px */
        }
        
        .student-info {
            background: linear-gradient(to right, #f8f9fa, #e9ecef, #f8f9fa);
            padding: 8px; /* Reduced from 12px */
            border-radius: 5px; /* Reduced from 8px */
            margin-bottom: 12px; /* Reduced from 15px */
            border: 1px solid #dee2e6;
        }
        
        .subject-table {
            width: 100%;
            border-collapse: collapse;
            margin: 10px 0; /* Reduced from 15px */
            font-size: 11px; /* Reduced from 12px */
            border: 1px solid #2c3e50;
        }
        
        .subject-table th,
        .subject-table td {
            border: 1px solid #2c3e50;
            padding: 4px 6px; /* Reduced from 6px 8px */
            text-align: center;
        }
        
        .subject-table th {
            background: linear-gradient(to bottom, #3498db, #2980b9);
            color: white;
            font-weight: 600;
        }
        
        .subject-table .subject-name {
            text-align: left;
            min-width: 100px; /* Reduced from 120px */
        }
        
        .result-summary {
            background: linear-gradient(to right, #e8f5e8, #d4edda, #e8f5e8);
            padding: 8px; /* Reduced from 12px */
            border-radius: 5px; /* Reduced from 8px */
            margin-top: 12px; /* Reduced from 15px */
            border: 1px solid #c3e6cb;
        }
        
        .signature-section {
            margin-top: 20px;
            text-align: center;
        }
        
        .signature-box {
            display: inline-block;
            width: 150px; /* Reduced from 200px */
            padding: 5px;
            border-top: 1px solid #000;
            margin: 0 10px;
            font-size: 10px; /* Reduced from 12px */
        }
        
        .marks-toggle {
            margin-bottom: 10px;
            text-align: center;
        }
        
        .print-btn {
            position: fixed;
            top: 10px;
            right: 10px;
            z-index: 1000;
        }
        
        @media print {
            .print-btn {
                display: none;
            }
            
            .marksheet {
                border: 2px solid #2c3e50;
                box-shadow: none;
                margin: 0;
                padding: 8px; /* Reduced from 12px */
            }
        }
        
        /* Additional responsive styles */
        @media (max-width: 768px) {
            .marksheet {
                margin: 5px;
                padding: 8px;
            }
            
            .subject-table {
                font-size: 10px; /* Further reduced for small screens */
            }
        }
    </style>
</head>
<body>
    <div class="container-fluid">
        <button class="btn btn-primary print-btn" onclick="window.print()">
            <i class="fas fa-print"></i> প্রিন্ট করুন
        </button>
        
        <!-- Student list for bulk printing -->
        <?php if ($show_student_list && ($bulk_print_all || $separate_print || !empty($selected_students)) && !empty($students_in_class)): ?> 
            <?php foreach ($all_students_data as $student_data): ?>
                <div class="marksheet mb-4">
                    <?php $student = $student_data['student']; ?>
                    <?php $results = $student_data['results']; ?>
                    <?php $total_marks = $student_data['total_marks']; ?>
                    <?php $total_obtained = $student_data['total_obtained']; ?>
                    <?php $percentage = $student_data['percentage']; ?>
                    <?php $gpa = $student_data['gpa']; ?>
                    <?php $passed_subjects = $student_data['passed_subjects']; ?>
                    <?php $total_subjects = $student_data['total_subjects']; ?>
                    
                    <!-- School Header -->
                    <div class="school-header">
                        <div class="d-flex align-items-center justify-content-center">
                            <?php if ($logo_image && file_exists("../uploads/logos/$logo_image")): ?>
                                <img src="../uploads/logos/<?= htmlspecialchars($logo_image) ?>" alt="Logo" class="school-logo">
                            <?php endif; ?>
                            <div class="text-center flex-grow-1">
                                <h3 class="mb-1"><?= htmlspecialchars($site_name) ?></h3>
                                <p class="mb-1"><?= htmlspecialchars($site_address) ?></p>
                                <h5 class="mb-1">শিক্ষাক্রমের ফলাফল</h5>
                                <p class="mb-0">পরীক্ষার নাম: <?= htmlspecialchars(ucfirst($exam_type)) ?>, সেশন: <?= htmlspecialchars($session) ?></p>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Student Information -->
                    <div class="student-info">
                        <div class="row g-2">
                            <div class="col-md-3">
                                <strong>ছাত্র/ছাত্রীর নাম:</strong><br>
                                <?= htmlspecialchars($student['first_name'] . ' ' . $student['last_name']) ?>
                            </div>
                            <div class="col-md-2">
                                <strong>রোল:</strong><br>
                                <?= htmlspecialchars($student['roll_number']) ?>
                            </div>
                            <div class="col-md-2">
                                <strong>শ্রেণি:</strong><br>
                                <?= htmlspecialchars($student['class_name']) ?>
                            </div>
                            <div class="col-md-2">
                                <strong>শাখা:</strong><br>
                                <?= htmlspecialchars($student['section']) ?>
                            </div>
                            <div class="col-md-3">
                                <strong>গ্রুপ:</strong><br>
                                <?= htmlspecialchars($student['group_name'] ?? '') ?>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Subject Results Table -->
                    <div class="table-responsive">
                        <table class="subject-table">
                            <thead>
                                <tr>
                                    <th>ক্রমিক নং</th>
                                    <th>বিষয়ের নাম</th>
                                    <th>পূর্ণ নম্বর</th>
                                    <th>প্রাপ্ত নম্বর</th>
                                    <th>গ্রেড</th>
                                    <th>জিপিএ</th>
                                    <th>ক্লাস টপার</th>
                                    <th>চতুর্থ বিষয়</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php foreach ($results as $index => $result): ?>
                                <tr>
                                    <td><?= $index + 1 ?></td>
                                    <td class="subject-name"><?= htmlspecialchars($result['subject_name']) ?></td>
                                    <td><?= $result['full_marks'] ?></td>
                                    <td><?= $result['marks_obtained'] ?></td>
                                    <td><?= $result['grade'] ?></td>
                                    <td><?= number_format($result['grade_point'], 2) ?></td>
                                    <td><?= $result['class_max_marks'] ?></td>
                                    <td><?= $result['is_fourth_subject'] ? 'হ্যাঁ' : 'না' ?></td>
                                </tr>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
                    </div>
                    
                    <!-- Result Summary -->
                    <div class="result-summary">
                        <div class="row g-2">
                            <div class="col-md-3">
                                <strong>মোট নম্বর:</strong><br>
                                <?= $total_obtained ?>/<?= $total_marks ?> (<?= $percentage ?>%)
                            </div>
                            <div class="col-md-2">
                                <strong>জিপিএ:</strong><br>
                                <?= number_format($gpa, 2) ?>
                            </div>
                            <div class="col-md-2">
                                <strong>গ্রেড:</strong><br>
                                <?= calculateGradeFromGPA($gpa) ?>
                            </div>
                            <div class="col-md-2">
                                <strong>পাশ:</strong><br>
                                <?= $passed_subjects ?>/<?= $total_subjects ?>
                            </div>
                            <div class="col-md-3">
                                <strong>মেধাক্রম:</strong><br>
                                <?php if (isset($student_data['merit_position'])): ?>
                                    <?= $student_data['merit_position'] ?>
                                <?php else: ?>
                                    -
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Signature Section -->
                    <div class="signature-section">
                        <div class="signature-box">পরীক্ষার্থীর</div>
                        <div class="signature-box">শিক্ষকের</div>
                        <div class="signature-box">অভিভাবকের</div>
                    </div>
                </div>
                
                <?php if (!$bulk_print_all && !$separate_print): ?>
                    <!-- Add page break between students when not bulk printing -->
                    <div style="page-break-after: always;"></div>
                <?php endif; ?>
            <?php endforeach; ?>
        
        <!-- Individual student view -->
        <?php elseif ($student_id && $session && $exam_type): ?>
            <?php if ($student && !empty($results)): ?>
            <div class="marksheet">
                <!-- School Header -->
                <div class="school-header">
                    <div class="d-flex align-items-center justify-content-center">
                        <?php if ($logo_image && file_exists("../uploads/logos/$logo_image")): ?>
                            <img src="../uploads/logos/<?= htmlspecialchars($logo_image) ?>" alt="Logo" class="school-logo">
                        <?php endif; ?>
                        <div class="text-center flex-grow-1">
                            <h3 class="mb-1"><?= htmlspecialchars($site_name) ?></h3>
                            <p class="mb-1"><?= htmlspecialchars($site_address) ?></p>
                            <h5 class="mb-1">শিক্ষাক্রমের ফলাফল</h5>
                            <p class="mb-0">পরীক্ষার নাম: <?= htmlspecialchars(ucfirst($exam_type)) ?>, সেশন: <?= htmlspecialchars($session) ?></p>
                        </div>
                    </div>
                </div>
                
                <!-- Student Information -->
                <div class="student-info">
                    <div class="row g-2">
                        <div class="col-md-3">
                            <strong>ছাত্র/ছাত্রীর নাম:</strong><br>
                            <?= htmlspecialchars($student['first_name'] . ' ' . $student['last_name']) ?>
                        </div>
                        <div class="col-md-2">
                            <strong>রোল:</strong><br>
                            <?= htmlspecialchars($student['roll_number']) ?>
                        </div>
                        <div class="col-md-2">
                            <strong>শ্রেণি:</strong><br>
                            <?= htmlspecialchars($student['class_name']) ?>
                        </div>
                        <div class="col-md-2">
                            <strong>শাখা:</strong><br>
                            <?= htmlspecialchars($student['section']) ?>
                        </div>
                        <div class="col-md-3">
                            <strong>গ্রুপ:</strong><br>
                            <?= htmlspecialchars($student['group_name'] ?? '') ?>
                        </div>
                    </div>
                </div>
                
                <!-- Subject Results Table -->
                <div class="table-responsive">
                    <table class="subject-table">
                        <thead>
                            <tr>
                                <th>ক্রমিক নং</th>
                                <th>বিষয়ের নাম</th>
                                <th>পূর্ণ নম্বর</th>
                                <th>প্রাপ্ত নম্বর</th>
                                <th>গ্রেড</th>
                                <th>জিপিএ</th>
                                <th>ক্লাস টপার</th>
                                <th>চতুর্থ বিষয়</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($results as $index => $result): ?>
                            <tr>
                                <td><?= $index + 1 ?></td>
                                <td class="subject-name"><?= htmlspecialchars($result['subject_name']) ?></td>
                                <td><?= $result['full_marks'] ?></td>
                                <td><?= $result['marks_obtained'] ?></td>
                                <td><?= $result['grade'] ?></td>
                                <td><?= number_format($result['grade_point'], 2) ?></td>
                                <td><?= $result['class_max_marks'] ?></td>
                                <td><?= $result['is_fourth_subject'] ? 'হ্যাঁ' : 'না' ?></td>
                            </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
                
                <!-- Result Summary -->
                <div class="result-summary">
                    <div class="row g-2">
                        <div class="col-md-3">
                            <strong>মোট নম্বর:</strong><br>
                            <?= $total_obtained ?>/<?= $total_marks ?> (<?= $percentage ?>%)
                        </div>
                        <div class="col-md-2">
                            <strong>জিপিএ:</strong><br>
                            <?= number_format($gpa, 2) ?>
                        </div>
                        <div class="col-md-2">
                            <strong>গ্রেড:</strong><br>
                            <?= calculateGradeFromGPA($gpa) ?>
                        </div>
                        <div class="col-md-2">
                            <strong>পাশ:</strong><br>
                            <?= $passed_subjects ?>/<?= $total_subjects ?>
                        </div>
                        <div class="col-md-3">
                            <strong>মেধাক্রম:</strong><br>
                            <?php if ($merit_position): ?>
                                <?= $merit_position ?>
                            <?php else: ?>
                                -
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
                
                <!-- Signature Section -->
                <div class="signature-section">
                    <div class="signature-box">পরীক্ষার্থীর</div>
                    <div class="signature-box">শিক্ষকের</div>
                    <div class="signature-box">অভিভাবকের</div>
                </div>
            </div>
            <?php else: ?>
                <!-- Error message when student exists but has no results -->
                <div class="container-fluid">
                    <div class="alert alert-warning text-center">
                        <h4>⚠️ ফলাফল পাওয়া যায়নি</h4>
                        <?php if (!$student): ?>
                            <p>ছাত্র আইডি <strong><?= htmlspecialchars($student_id) ?></strong> সাথে কোন ছাত্র খুঁজে পাওয়া যায়নি।</p>
                        <?php else: ?>
                            <p>ছাত্র <strong><?= htmlspecialchars($student['first_name'] . ' ' . $student['last_name']) ?></strong> এর জন্য <strong><?= htmlspecialchars($session) ?></strong> সেশনের <strong><?= htmlspecialchars(ucfirst($exam_type)) ?></strong> পরীক্ষার কোন ফলাফল পাওয়া যায়নি।</p>
                        <?php endif; ?>
                        <p><a href="?class_id=<?= $class_id ?>&session=<?= $session ?>&exam_type=<?= $exam_type ?>" class="btn btn-primary">ছাত্র তালিকা দেখুন</a></p>
                    </div>
                </div>
            <?php endif; ?>
        <?php else: ?>
            <!-- Search form for individual student view -->
            <div class="container-fluid">
                <h3 class="mb-4 text-center">সকল বিষয়ের মার্কশীট (বিষয় একত্রীকরণ ছাড়া)</h3>
                
                <form method="GET" class="mb-4">
                    <div class="row g-3">
                        <div class="col-md-3">
                            <label for="class_id" class="form-label">শ্রেণি</label>
                            <select name="class_id" id="class_id" class="form-select" required>
                                <option value="">শ্রেণি নির্বাচন করুন</option>
                                <?php foreach ($classes as $class): ?>
                                    <option value="<?= $class['id'] ?>" <?= $class_id == $class['id'] ? 'selected' : '' ?>>
                                        <?= htmlspecialchars($class['name']) ?> (<?= htmlspecialchars($class['section']) ?>)
                                    </option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                        <div class="col-md-3">
                            <label for="session" class="form-label">সেশন</label>
                            <select name="session" id="session" class="form-select" required>
                                <option value="">সেশন নির্বাচন করুন</option>
                                <?php foreach ($sessions as $sess): ?>
                                    <option value="<?= $sess['session'] ?>" <?= $session == $sess['session'] ? 'selected' : '' ?>>
                                        <?= htmlspecialchars($sess['session']) ?>
                                    </option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                        <div class="col-md-3">
                            <label for="exam_type" class="form-label">পরীক্ষার ধরন</label>
                            <select name="exam_type" id="exam_type" class="form-select" required>
                                <option value="">পরীক্ষার ধরন নির্বাচন করুন</option>
                                <?php foreach ($exam_types as $et): ?>
                                    <option value="<?= $et['exam_type'] ?>" <?= $exam_type == $et['exam_type'] ? 'selected' : '' ?>>
                                        <?= htmlspecialchars(ucfirst($et['exam_type'])) ?>
                                    </option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                        <div class="col-md-3">
                            <label for="student_search" class="form-label">ছাত্র অনুসন্ধান (ঐচ্ছিক)</label>
                            <input type="text" name="student_search" id="student_search" class="form-control" value="<?= htmlspecialchars($student_search) ?>" placeholder="নাম বা রোল দিয়ে অনুসন্ধান করুন">
                        </div>
                    </div>
                    
                    <div class="row g-3 mt-1">
                        <div class="col-md-3">
                            <label for="student_id" class="form-label">ছাত্র নির্বাচন করুন (ঐচ্ছিক)</label>
                            <select name="student_id" id="student_id" class="form-select">
                                <option value="">ছাত্র নির্বাচন করুন</option>
                                <?php if (!empty($students_in_class)): ?>
                                    <?php foreach ($students_in_class as $std): ?>
                                        <option value="<?= $std['id'] ?>" <?= $student_id == $std['id'] ? 'selected' : '' ?>>
                                            <?= htmlspecialchars($std['first_name'] . ' ' . $std['last_name']) ?> (রোল: <?= $std['roll_number'] ?>)
                                        </option>
                                    <?php endforeach; ?>
                                <?php endif; ?>
                            </select>
                        </div>
                        <div class="col-md-9 d-flex align-items-end">
                            <button type="submit" class="btn btn-primary me-2">
                                <i class="fas fa-search"></i> খুঁজুন
                            </button>
                            <button type="submit" name="bulk_print_all" value="1" class="btn btn-success me-2">
                                <i class="fas fa-print"></i> সবার মার্কশীট প্রিন্ট করুন
                            </button>
                            <button type="submit" name="separate_print" value="1" class="btn btn-info me-2">
                                <i class="fas fa-list"></i> পৃথক মার্কশীট প্রিন্ট করুন
                            </button>
                            <?php if (!empty($selected_students)): ?>
                                <a href="?class_id=<?= $class_id ?>&session=<?= $session ?>&exam_type=<?= $exam_type ?>&selected_students=<?= $selected_students ?>&bulk_print_all=1" class="btn btn-warning me-2">
                                    <i class="fas fa-print"></i> নির্বাচিত ছাত্রদের প্রিন্ট করুন';
                                </a>
                                <a href="?class_id=<?= $class_id ?>&session=<?= $session ?>&exam_type=<?= $exam_type ?>&selected_students=<?= $selected_students ?>&separate_print=1" class="btn btn-info">
                                    <i class="fas fa-list"></i> নির্বাচিত ছাত্রদের পৃথক প্রিন্ট করুন';
                                </a>
                            <?php endif; ?>
                        </div>
                    </div>
                </form>
                
                <?php if ($show_student_list && !empty($students_in_class)): ?>
                    <div class="card">
                        <div class="card-header">
                            <h5>ছাত্র তালিকা
                                <small class="text-muted">(মোট: <?= count($students_in_class) ?> জন)</small>
                            </h5>
                        </div>
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-hover">
                                    <thead>
                                        <tr>
                                            <th>ক্রমিক নং</th>
                                            <th>ছাত্র আইডি</th>
                                            <th>নাম</th>
                                            <th>রোল</th>
                                            <th>ক্রিয়াকলাপ</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php foreach ($students_in_class as $index => $std): ?>
                                        <tr>
                                            <td><?= $index + 1 ?></td>
                                            <td><?= htmlspecialchars($std['student_id']) ?></td>
                                            <td><?= htmlspecialchars($std['first_name'] . ' ' . $std['last_name']) ?></td>
                                            <td><?= $std['roll_number'] ?></td>
                                            <td>
                                                <a href="?class_id=<?= $class_id ?>&session=<?= $session ?>&exam_type=<?= $exam_type ?>&student_id=<?= $std['id'] ?>" class="btn btn-sm btn-primary">দেখুন</a>
                                                <a href="?class_id=<?= $class_id ?>&session=<?= $session ?>&exam_type=<?= $exam_type ?>&student_id=<?= $std['id'] ?>&print=1" class="btn btn-sm btn-success">প্রিন্ট</a>
                                            </td>
                                        </tr>
                                        <?php endforeach; ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                <?php endif; ?>
            </div>
        <?php endif; ?>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // JavaScript for additional functionality if needed
        document.addEventListener('DOMContentLoaded', function() {
            // Add any additional JavaScript functionality here
        });
    </script>
</body>
</html>