
<?php
// Get student information
 $studentId = $_SESSION['user_id'];
 $stmt = $pdo->prepare("SELECT * FROM students WHERE id = ?");
 $stmt->execute([$studentId]);
 $student = $stmt->fetch(PDO::FETCH_ASSOC);

// Check if student can access admission letter
if ($student['application_status'] !== 'Approved' || $student['acceptance_fee_status'] !== 'Paid') {
    header('Location: ?page=student_dashboard');
    exit;
}
?>

<div class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h4 class="mb-0">Admission Letter</h4>
                <button class="btn btn-secondary no-print" onclick="window.print()">
                    <i class="bi bi-printer"></i> Print
                </button>
            </div>
            <div class="card-body">
                <div class="text-center mb-4">
                    <img src="https://via.placeholder.com/150x150/000000/FFFFFF/000000?url=https://picsum.photos/seed/ijmb-logo/150/150" alt="ABU Logo" style="max-width: 100px;">
                    <h3>AHMADU BELLO UNIVERSITY, ZARIA</h3>
                    <p>In affiliation with Federal College of Education (Technical) Asaba</p>
                    <h4>INTERIM JOINT MATRICULATION BOARD EXAMINATION</h4>
                    <p>ADMISSION LETTER</p>
                </div>
                
                <div class="row">
                    <div class="col-md-12">
                        <table class="table table-bordered">
                            <tr>
                                <th width="30%">Name</th>
                                <td><?php echo $student['first_name'] . ' ' . $student['surname']; ?></td>
                            </tr>
                            <tr>
                                <th width="30%">Registration Number</th>
                                <td><?php echo $student['registration_no']; ?></td>
                            </tr>
                            <tr>
                                <th width="30%">Course</th>
                                <td>IJMB Programme</td>
                            </tr>
                            <tr>
                                <th width="30%">Academic Session</th>
                                <td>
                                    <?php
                                    $stmt = $pdo->prepare("SELECT setting_value FROM system_settings WHERE setting_key = 'academic_session'");
                                    $stmt->execute();
                                    echo $stmt->fetchColumn();
                                    ?>
                                </td>
                            </tr>
                            <tr>
                                <th width="30%">Admission Status</th>
                                <td><span class="badge bg-success">ADMITTED</span></td>
                            </tr>
                        </table>
                    </div>
                </div>
                
                <div class="mt-5">
                    <h5>This is to certify that</h5>
                    <p><strong><?php echo $student['first_name'] . ' ' . $student['surname']; ?></strong> has been offered provisional admission into the Interim Joint Matriculation Board (IJMB) programme for the <?php
                        $stmt = $pdo->prepare("SELECT setting_value FROM system_settings WHERE setting_key = 'academic_session'");
                        $stmt->execute();
                        echo $stmt->fetchColumn();
                    ?> academic session.</p>
                    
                    <p>This admission is subject to the candidate fulfilling all admission requirements including payment of the acceptance fee.</p>
                    
                    <div class="mt-4">
                        <p><strong>Date:</strong> <?php echo date('d F Y'); ?></p>
                        <p><strong>Signature:</strong></p>
                        <div class="mt-2">
                            <img src="https://via.placeholder.com/200x100/000000/FFFFFF/000000?url=https://picsum.photos/seed/signature/200/100" alt="Signature" style="max-height: 80px;">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
