| Current Path : /var/www/cesa.co.za/php/templates/bce/ |
| Current File : /var/www/cesa.co.za/php/templates/bce/feedbackformsreportexport.php |
<?php
if (!defined('BCE_FEEDBACK_REPORT_LOGIN')) {
define('BCE_FEEDBACK_REPORT_LOGIN', '/cceadmin/login.php');
}
if (!defined('BCE_FEEDBACK_REPORT_PORTAL_DIR')) {
define('BCE_FEEDBACK_REPORT_PORTAL_DIR', 'cceadmin');
}
session_start();
ob_start();
$bcePortalRoot = $_SERVER['DOCUMENT_ROOT'] . '/' . BCE_FEEDBACK_REPORT_PORTAL_DIR;
include_once $bcePortalRoot . '/ewcfg7.php';
include_once $bcePortalRoot . '/ewmysql7.php';
include_once $bcePortalRoot . '/phpfn7.php';
include_once $bcePortalRoot . '/userfn7.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/php/includes/BceAssignmentFeedbackFormsReportService.php';
if (!isset($_SESSION[EW_SESSION_STATUS]) || $_SESSION[EW_SESSION_STATUS] !== 'login') {
header('Location: ' . BCE_FEEDBACK_REPORT_LOGIN);
exit;
}
header('Cache-Control: private, no-store, no-cache, must-revalidate');
header('Pragma: no-cache');
$formId = isset($_GET['form_id']) ? trim((string) $_GET['form_id']) : '';
if ($formId === '') {
header('HTTP/1.1 400 Bad Request');
header('Content-Type: text/plain; charset=UTF-8');
echo 'Missing form_id.';
exit;
}
$service = new BceAssignmentFeedbackFormsReportService();
$error = '';
$result = $service->exportSpreadsheet($formId, $error);
if (!is_array($result) || !isset($result['body'])) {
header('HTTP/1.1 502 Bad Gateway');
header('Content-Type: text/plain; charset=UTF-8');
echo 'Could not export report. ' . $error;
exit;
}
$safeName = preg_replace('/[^a-zA-Z0-9_.-]+/', '-', $result['filename']);
if ($safeName === '' || substr(strtolower($safeName), -5) !== '.xlsx') {
$safeName = 'form-report.xlsx';
}
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="' . $safeName . '"');
header('Content-Length: ' . strlen($result['body']));
echo $result['body'];
exit;