/** * Sends an HTTP response with the contents of the request file for download * * @param boolean $forceDownload true if force to download the file * @param array $info Array containing the file details. * Currently supported: * - content-type - content type for the file * */ public function outputFile($forceDownload, array $info) { if (empty($info['path'])) { throw new SugarApiException('No file name supplied'); } if (!empty($info['doc_type']) && $info['doc_type'] != "Sugar") { $this->api->setHeader("Location", $info['uri']); return; } $this->api->setHeader("Expires", TimeDate::httpTime(time() + 2592000)); if (!$forceDownload) { if (!empty($info['content-type'])) { $this->api->setHeader("Content-Type", $info['content-type']); } else { $this->api->setHeader("Content-Type", "application/octet-stream"); } } else { $this->api->setHeader("Content-Type", "application/force-download"); $this->api->setHeader("Content-type", "application/octet-stream"); if (empty($info['name'])) { $info['name'] = pathinfo($info['path'], PATHINFO_BASENAME); } $this->api->setHeader("Content-Disposition", "attachment; filename=\"" . $info['name'] . "\""); } $this->api->fileResponse($info['path']); }
/** * Export a Report As PDF * @param SugarBean $report * @return null */ protected function exportPdf(ServiceBase $api, SugarBean $report) { global $beanList, $beanFiles; global $sugar_config, $current_language; require_once 'modules/Reports/templates/templates_pdf.php'; $report_filename = false; if ($report->id != null) { //Translate pdf to correct language $reporter = new Report(html_entity_decode($report->content), '', ''); $reporter->layout_manager->setAttribute("no_sort", 1); $reporter->fromApi = true; //Translate pdf to correct language $mod_strings = return_module_language($current_language, 'Reports'); //Generate actual pdf $report_filename = template_handle_pdf($reporter, false); $api->setHeader("Content-Type", "application/pdf"); $api->setHeader("Content-Disposition", 'attachment; filename="' . basename($report_filename) . '"'); $api->setHeader("Expires", TimeDate::httpTime(time() + 2592000)); $api->fileResponse($report_filename); } }