Exemplo n.º 1
0
 /**
  *  Get the latest report object for the selected reference
  * 
  * @param string $refno Reference number
  * @param string $type Optional type restriction
  */
 public function getLatestReport($refno, $type = null)
 {
     $legacyReport = new Datasource_ReferencingLegacy_ReportHistory();
     return $legacyReport->getLatestReport($refno, $type);
 }
 /**
  * To Download/View the Final/Intereim report.
  *
  * @todo: The legacy URL should be parameterised.
  *
  * @return void
  */
 public function viewReportPdfAction()
 {
     if (!$this->_isReferenceOwnedBy($this->getRequest()->getParam('refno'), $this->_agentSchemeNumber)) {
         throw new Exception("Agent does not own this reference");
     }
     $baseRefUrl = $this->_params->connect->baseUrl->referencing;
     $reportUri = $baseRefUrl . 'cgi-bin/refviewreport.pl?refno=' . $this->getRequest()->getParam('refno') . '&repType=' . $this->getRequest()->getParam('repType');
     $filename = $this->_buildReportAttachementFilename($this->getRequest()->getParam('repType') ?: 'Report', $this->getRequest()->getParam('refno'));
     switch ($this->getRequest()->getParam('contentDisposition')) {
         // View in-line
         default:
         case "view":
             header('Pragma: ');
             // Remove pragma
             header('Cache-Control: ');
             header('Content-Type: application/pdf');
             break;
             // Download
         // Download
         case "attachment":
             header('Pragma: ');
             // Remove pragma
             header('Cache-Control: ');
             // Remove cache control
             header('Content-Description: File Transfer');
             header('Content-Type: application/octet-stream');
             header('Content-Disposition: attachment; filename=' . $filename);
             break;
     }
     // Get the latest report
     $reportDatasource = new Datasource_ReferencingLegacy_ReportHistory();
     $report = $reportDatasource->getLatestReport($this->getRequest()->getParam('refno'));
     $timegenerated = null;
     if ($report && isset($report->generationTime)) {
         $timegenerated = strtotime($report->generationTime);
     }
     // Check report file cache
     if (Application_Cache_Referencing_ReportFileCache::getInstance()->has($filename, $timegenerated)) {
         // Return from cache
         $pdfContent = Application_Cache_Referencing_ReportFileCache::getInstance()->get($filename, $timegenerated);
         $this->getResponse()->appendBody($pdfContent);
     } else {
         // Request report from legacy
         $curl = curl_init();
         curl_setopt($curl, CURLOPT_URL, $reportUri);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
         curl_setopt($curl, CURLOPT_TIMEOUT, 50);
         curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
         $pdfContent = curl_exec($curl);
         if (!$pdfContent) {
             error_log('Critical Error: ' . curl_error($curl));
             exit('Critical Error: Please contact us');
         }
         curl_close($curl);
         // Cache result
         Application_Cache_Referencing_ReportFileCache::getInstance()->set($filename, $pdfContent, $timegenerated);
         $this->getResponse()->appendBody($pdfContent);
     }
     $this->_helper->layout()->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
 }