<?php
require_once __DIR__ . '/lib/core.php';
dc_security_headers();

$type = isset($_GET['type']) ? $_GET['type'] : '';
$id = isset($_GET['id']) ? trim($_GET['id']) : '';
$key = isset($_GET['key']) ? trim($_GET['key']) : '';
$door = dc_find_public_door($id, $key);

if (!$door || !in_array($type, array('html', 'certificate', 'pdf'), true)) {
    http_response_code(404);
    exit('Certificate not found.');
}

if ($type === 'pdf') {
    dc_send_certificate_pdf_export($door);
}

dc_send_certificate_html($door, !empty($_GET['download']));
