/** * Download the zip file */ function downloadZipFile($exportCode = NULL) { if (!(isset($exportCode) && !empty($exportCode))) { $exportCode = KTUtil::arrayGet($_SESSION['zipcompression'], 'exportcode'); } $aData = KTUtil::arrayGet($_SESSION['zipcompression'], $exportCode); if (!empty($aData)) { $sZipFile = $aData['file']; $sTmpPath = $aData['dir']; } else { $sZipFile = $this->sZipFile; $sTmpPath = $this->sTmpPath; } if (!file_exists($sZipFile)) { return PEAR::raiseError(_kt('The zip file has not been created, if you are downloading a large number of documents or a large document then it may take a few minutes to finish.')); } $mimeType = 'application/zip; charset=utf-8;'; $fileSize = filesize($sZipFile); $fileName = $this->sZipFileName . '.' . $this->extension; KTUtil::download($sZipFile, $mimeType, $fileSize, $fileName); KTUtil::deleteDirectory($sTmpPath); return true; }
function downloadVersion($oDocument, $iVersionId) { //get the document $oContentVersion = KTDocumentContentVersion::get($iVersionId); $oConfig =& KTConfig::getSingleton(); $sPath = sprintf("%s/%s", $oConfig->get('urls/documentRoot'), $this->getPath($oContentVersion)); $sVersion = sprintf("%d.%d", $oContentVersion->getMajorVersionNumber(), $oContentVersion->getMinorVersionNumber()); $mimeType = KTMime::getMimeTypeName($oContentVersion->getMimeTypeID()); $fileSize = $oContentVersion->getFileSize(); $fileName = $sVersion . '-' . $oContentVersion->getFileName(); return KTUtil::download($sPath, $mimeType, $fileSize, $fileName); }
/** * Download the zip file */ function downloadZipFile($exportCode = NULL) { if (!(isset($exportCode) && !empty($exportCode))) { $exportCode = KTUtil::arrayGet($_SESSION['zipcompression'], 'exportcode'); } $aData = KTUtil::arrayGet($_SESSION['zipcompression'], $exportCode); if (!empty($aData)) { $sZipFile = $aData['file']; $sTmpPath = $aData['dir']; } else { $sZipFile = $this->sZipFile; $sTmpPath = $this->sTmpPath; } if (!file_exists($sZipFile)) { return PEAR::raiseError(_kt('The ZIP file can only be downloaded once - if you cancel the download, you will need to reload the page.')); } $mimeType = 'application/zip; charset=utf-8;'; $fileSize = filesize($sZipFile); $fileName = $this->sZipFileName . '.zip'; KTUtil::download($sZipFile, $mimeType, $fileSize, $fileName); KTUtil::deleteDirectory($sTmpPath); return true; }
/** * Method for downloading the document as a pdf. * * @deprecated * @return true on success else false */ function do_pdfdownload_deprecated() { $oDocument = $this->oDocument; $oStorage =& KTStorageManagerUtil::getSingleton(); $oConfig =& KTConfig::getSingleton(); $default = realpath(str_replace('\\', '/', KT_DIR . '/../openoffice/program')); putenv('ooProgramPath=' . $oConfig->get('openoffice/programPath', $default)); $cmdpath = KTUtil::findCommand('externalBinary/python'); // Check if openoffice and python are available if ($cmdpath == false || !file_exists($cmdpath) || empty($cmdpath)) { // Set the error messsage and redirect to view document $this->addErrorMessage(_kt('An error occurred generating the PDF - please contact the system administrator. Python binary not found.')); redirect(generateControllerLink('viewDocument', sprintf('fDocumentId=%d', $oDocument->getId()))); exit(0); } //get the actual path to the document on the server $sPath = sprintf("%s/%s", $oConfig->get('urls/documentRoot'), $oStorage->getPath($oDocument)); if (file_exists($sPath)) { // Get a tmp file $sTempFilename = tempnam('/tmp', 'ktpdf'); // We need to handle Windows differently - as usual ;) if (substr(PHP_OS, 0, 3) == 'WIN') { $cmd = "\"" . $cmdpath . "\" \"" . KT_DIR . "/bin/openoffice/pdfgen.py\" \"" . $sPath . "\" \"" . $sTempFilename . "\""; $cmd = str_replace('/', '\\', $cmd); // TODO: Check for more errors here // SECURTIY: Ensure $sPath and $sTempFilename are safe or they could be used to excecute arbitrary commands! // Excecute the python script. TODO: Check this works with Windows $res = `"{$cmd}" 2>&1`; //print($res); //print($cmd); //exit; } else { // TODO: Check for more errors here // SECURTIY: Ensure $sPath and $sTempFilename are safe or they could be used to excecute arbitrary commands! // Excecute the python script. $cmd = $cmdpath . ' ' . KT_DIR . '/bin/openoffice/pdfgen.py ' . escapeshellcmd($sPath) . ' ' . escapeshellcmd($sTempFilename); $res = shell_exec($cmd . " 2>&1"); //print($res); //print($cmd); //exit; } // Check the tempfile exists and the python script did not return anything (which would indicate an error) if (file_exists($sTempFilename) && $res == '') { $mimetype = 'application/pdf'; $size = filesize($sTempFilename); $name = substr($oDocument->getFileName(), 0, strrpos($oDocument->getFileName(), '.')) . '.pdf'; KTUtil::download($sTempFilename, $mimetype, $size, $name); // Remove the tempfile unlink($sTempFilename); // Create the document transaction $oDocumentTransaction =& new DocumentTransaction($oDocument, 'Document downloaded as PDF', 'ktcore.transactions.download', $aOptions); $oDocumentTransaction->create(); // Just stop here - the content has already been sent. exit(0); } else { // Set the error messsage and redirect to view document $this->addErrorMessage(_kt('An error occurred generating the PDF - please contact the system administrator. ' . $res)); redirect(generateControllerLink('viewDocument', sprintf('fDocumentId=%d', $oDocument->getId()))); exit(0); } } else { // Set the error messsage and redirect to view document $this->addErrorMessage(_kt('An error occurred generating the PDF - please contact the system administrator. The path to the document did not exist.')); redirect(generateControllerLink('viewDocument', sprintf('fDocumentId=%d', $oDocument->getId()))); exit(0); } }