<?php
// Exact PDF download handler using original report card layout
session_start();

// Check authentication (remove comment marks if authentication is needed)
/*
if (!isset($_SESSION['id']) || !isset($_SESSION['loggedin']) || $_SESSION['loggedin'] != 1 || !isset($_SESSION['role']) || $_SESSION['role'] != 1) {
    header("Location: login.php");
    exit();
}
*/

// Get parameters and pass them through
$params = http_build_query($_GET);

// Check if DOMPDF is available
if (file_exists('vendor/autoload.php') || file_exists('dompdf/autoload.inc.php') || file_exists('dompdf/dompdf_config.inc.php')) {
    // Use the exact replica PDF generator
    header("Location: simple_pdf_handler.php?" . $params);
} else {
    // Fallback to browser-based PDF generation
    header("Location: print_version.php?" . $params);
}
?>