<?php
 if ($R['downloadReport']) { $reportDir=$MODULE_REL_PATH.$CFG['paths']['generatedReports'].$idReportGenerating."/"; $reportFile=$reportOutput['report']['reportName']; $reportDownloadFile=$reportDir.$reportOutput['report']['fileName']; if (is_file($reportDownloadFile)) { $userTrailItem->updateActionOld('reportGenerating_reportDownload'); if ($R['format']=='zip') { $zipFileName=\Engine\File::getName($reportDownloadFile).'.zip'; $zipFileNameWithPath=\Engine\File::getPath($reportDownloadFile).$zipFileName; $zip=new ZipArchive(); if (!$zip->open($zipFileNameWithPath, ZIPARCHIVE::CREATE)) { writeLog('There is a problem with `ZipArchive::open` PHP lib.', 'events', 8); $showMessage['error']=$_LANG['reportsGeneration']['viewReport']['zipFileBad']; $OK=false; } if ($OK and !$zip->addFile($reportDownloadFile, \Engine\File::getNameFull($reportFile))) { writeLog('There is a problem with `ZipArchive::addFile` PHP lib.', 'events', 8); $showMessage['error']=$_LANG['reportsGeneration']['viewReport']['zipFileBad']; $OK=false; } $zip->close(); $reportDownloadFile=$zipFileNameWithPath; $reportFile=\Engine\File::getName($reportFile).'.zip'; } if ($OK) { $reportSize=filesize($reportDownloadFile); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header("Content-Disposition: attachment; filename=\"".$reportFile."\";"); if ($reportSize) { header("Content-Length: ".$reportSize); } readfile($reportDownloadFile); if ($R['format']=='zip') { if (file_exists($reportDownloadFile)) { unlink($reportDownloadFile); } } exit; } } else { $showMessage['error'] = $_LANG['reportsGeneration']['viewReport']['noFileOnServer']; writeLog("Report file is missing from the server. (id: ".$idReportGenerating, 'events', 9); $OK=0; } } if ($R['viewReport']) { $reportDir=$MODULE_REL_PATH.$CFG['paths']['generatedReports'].$idReportGenerating."/"; $reportFile=$reportOutput['report']['fileName']; $reportDownloadFile=$reportDir.$reportFile; if (is_file($reportDownloadFile)) { $userTrailItem->updateActionOld('reportGenerating_reportView'); readfile($reportDownloadFile); exit; } else { $showMessage['error'] = $_LANG['reportsGeneration']['viewReport']['noFileOnServer']; writeLog("Report file is missing from the server. file: ".$reportDownloadFile, 'events', 9); $OK=0; } } ?>