<?php
require_once __DIR__ . '/../config/database.php';

requireLogin();
requireAnyRole(['admin', 'super_admin']);

$db = Database::getInstance();

$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
if ($id <= 0) {
    die('Invalid certificate ID.');
}

$cert = $db->get(
    "SELECT cert.*, c.title AS course_title, u.first_name, u.last_name
     FROM certificates cert
     JOIN courses c ON cert.course_id = c.id
     JOIN users u ON cert.student_id = u.id
     WHERE cert.id = ?",
    [$id]
);

if (!$cert) {
    die('Certificate not found.');
}

header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="certificate_' . $id . '.pdf"');
echo 'PDF generation not implemented yet.';
exit;
