Beispiel #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);
 }
 /**
  * Retrieve a referencing report
  */
 public function viewReferencingReportAction()
 {
     $request = $this->getRequest();
     $response = $this->getResponse();
     $refNo = $request->getParam('refno');
     $download = $request->getParam('download');
     $reporttype = '';
     $reportkey = $request->getParam('report');
     // Validate the refNo parameter
     preg_match('/([0-9]*\\.[0-9]*)/', $refNo, $refNo);
     if (count($refNo) == 2) {
         $refNo = $refNo[1];
     } else {
         // Fails validation, return error
         $this->render('view-document-not-found');
         return;
     }
     // Validate direct landlord is the correct owner of the reference
     // Get the customer session
     $customerSession = $this->auth->getStorage()->read();
     // Get list of external reference numbers
     $referenceManager = new Manager_Referencing_Reference();
     $referenceIds = $referenceManager->getAllReferenceIds($customerSession->id);
     if (!in_array($refNo, $referenceIds)) {
         // This reference does not belong to the customer
         $this->render('view-document-not-found');
         return;
     }
     // Get Latest report
     $legacyRefManager = new Manager_ReferencingLegacy_Munt();
     $report = $legacyRefManager->getLatestReport($refNo);
     // Check the $reportkey parameter against the key provided by the report object returned.
     // If they dont match, display a notice page that the report is out of date.
     if ($reportkey != '' && $report->validationKey != $reportkey) {
         $this->view->download = $download == 'true' ? 'true' : 'false';
         $this->view->report = $report;
         $this->render('reference-report-outofdate');
         return;
     }
     // Set the report type of that of the report object
     $reporttype = $report->reportType;
     $params = Zend_Registry::get('params');
     $baseRefUrl = $params->baseUrl->referencing;
     $reportUri = $baseRefUrl . 'cgi-bin/refviewreport.pl?refno=' . $refNo . '&repType=' . $reporttype;
     //error_log('debug: ' . $reportUri);
     $filename = $this->_buildReportAttachementFilename('Report', $refNo);
     // Get the latest report
     $reportDatasource = new Datasource_ReferencingLegacy_ReportHistory();
     $timegenerated = $reportDatasource->getTimeReportGenerated($refNo, $reporttype);
     // 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);
         curl_close($curl);
         if (!$pdfContent) {
             $this->render('view-document-not-found');
             return;
         }
         // Cache result
         Application_Cache_Referencing_ReportFileCache::getInstance()->set($filename, $pdfContent, $timegenerated);
         $this->getResponse()->appendBody($pdfContent);
     }
     // Create filename
     // AJD - Why is this being done again? Also - it doesn't follow the new filename schema. Address must not be used.
     /*$referenceManager = new Manager_Referencing_Reference();
       $reference = $referenceManager->getReference($refNo);
       $filename = ucfirst(strtolower($reporttype)) . ', ' . $reference->propertyLease->address->addressLine1 . ', ' . $reference->propertyLease->address->addressLine2 . '.pdf';
       $filename = preg_replace('/&|\\//', '', $filename);*/
     // Apply appropriate headers
     //        $response->setHeader('Pragma', '');
     //        $response->setHeader('Cache-Control', '');
     if ($download == 'true') {
         // Downloading
         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);
         //           $response->setHeader('Content-Description', 'File Transfer');
         //           $response->setHeader('Content-Type', 'application/octet-stream');
         //           $response->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
     } else {
         header('Pragma: ');
         // Remove pragma
         header('Cache-Control: ');
         header('Content-Type: application/pdf');
         // Viewing
         //            $response->setHeader('Content-Type', 'text/plain');
     }
     $this->_helper->layout()->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
 }
 /**
  * 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);
 }