<?php
include('includes/db.php');

// Check parameters
$classId = isset($_GET['class_id']) ? (int)$_GET['class_id'] : 0;
$sectionId = isset($_GET['section_id']) ? (int)$_GET['section_id'] : 0;
$subjectCode = isset($_GET['subject_code']) ? $conn->real_escape_string($_GET['subject_code']) : '';
$academicYear = isset($_GET['academic_year']) ? $conn->real_escape_string($_GET['academic_year']) : '';
$exportType = isset($_GET['type']) ? $_GET['type'] : '';

// Set headers for Excel file
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="missing_marks_report_' . date('Y-m-d') . '.xls"');

echo '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">';
echo '<head><meta charset="UTF-8"></head><body>';

echo '<h2>Missing Marks Report</h2>';
echo '<p>Generated on: ' . date('Y-m-d H:i:s') . '</p>';

if ($exportType == 'all') {
    // Export all missing marks
    include('ajax/get_all_missing_marks.php');
} elseif ($exportType == 'class') {
    // Export class missing marks
    include('ajax/get_class_missing_marks.php');
} elseif ($subjectCode) {
    // Export subject missing marks
    include('ajax/get_missing_marks_report.php');
} else {
    echo '<p>No export type specified.</p>';
}

echo '</body></html>';