<?php
require_once __DIR__ . '/../../functions/security.php';

$tenant = enrep_tenant_segment($_REQUEST['tenant'] ?? (defined('TENANT_URL') ? TENANT_URL : ''));
if ($tenant !== '' && file_exists('../../../' . $tenant . '/config.php')) {
    require_once('../../../' . $tenant . '/config.php');
}
if (file_exists('/config.php')) {
    require_once('/config.php');
}

require_once __DIR__ . '/log_functions.php';

if (function_exists('enrep_require_admin')) {
    enrep_require_admin();
}

$filters = enrep_log_request_filters();
$rows = enrep_log_fetch($filters, 5000, 0);
$export = trim((string)($_GET['log_export'] ?? 'csv'));

if ($export === 'pdf') {
    enrep_log_export_pdf($rows, $filters);
}

enrep_log_export_csv($rows);
