Ejemplo n.º 1
0
 /**
  * Shows the requested report's HTML output.
  * 
  * @param CommandContext $context
  * @throws InvalidArgumentExection
  */
 public function execute(CommandContext $context)
 {
     if (!Current_User::allow('hms', 'reports')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do no have permission to run reports.');
     }
     $reportId = $context->get('reportId');
     if (!isset($reportId) || is_null($reportId)) {
         throw new InvalidArgumentExection('Missing report id.');
     }
     // Instantiate the report controller with the requested report id
     PHPWS_Core::initModClass('hms', 'ReportFactory.php');
     $report = ReportFactory::getReportById($reportId);
     Layout::addPageTitle($report->getFriendlyName());
     $detailCmd = CommandFactory::getCommand('ShowReportDetail');
     $detailCmd->setReportClass($report->getClass());
     $content = '<div> ' . $detailCmd->getLink('&laquo; back') . ' </div>';
     $content .= file_get_contents($report->getHtmlOutputFilename());
     if ($content === FALSE) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Could not open report file.');
         PHPWS_Error::log('Could not open report file ' . $report->getCsvOutputFilename(), 'hms');
         $reportCmd = CommandFactory::getCommand('ShowReportDetail');
         $reportCmd->setReportClass($report->getClass());
         $reportCmd->redirect();
     }
     $context->setContent($content);
 }
Ejemplo n.º 2
0
 public function execute(CommandContext $context)
 {
     // Check for report ID
     $reportId = $context->get('reportId');
     if (!isset($reportId) || is_null($reportId)) {
         throw new InvalidArgumentException('Missing report id.');
     }
     PHPWS_Core::initModClass('hms', 'ReportFactory.php');
     // Load the report to get its class
     try {
         $report = ReportFactory::getReportById($reportId);
     } catch (InvalidArgumentException $e) {
         NQ::simple('hms', hms\NotificationView::SUCCESS, 'Report canceled.');
         $context->goBack();
     }
     $db = new PHPWS_DB('hms_report');
     $db->addWhere('id', $reportId);
     $result = $db->delete();
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->toString());
     }
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'Report canceled.');
     $cmd = CommandFactory::getCommand('ShowReportDetail');
     $cmd->setReportClass($report->getClass());
     $cmd->redirect();
 }
Ejemplo n.º 3
0
 /**
  * Exec
  *
  * @param CommandContext $context
  * @throws InvalidArgumentExection
  */
 public function execute(CommandContext $context)
 {
     if (!Current_User::allow('hms', 'reports')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do no have permission to run reports.');
     }
     $reportId = $context->get('reportId');
     if (!isset($reportId) || is_null($reportId)) {
         throw new InvalidArgumentExection('Missing report id.');
     }
     // Instantiate the report controller with the requested report id
     PHPWS_Core::initModClass('hms', 'ReportFactory.php');
     $report = ReportFactory::getReportById($reportId);
     // Check to make sure the file exists
     if (!file_exists($report->getCsvOutputFilename())) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Could not open report file.');
         PHPWS_Error::log('Could not open report file ' . $report->getCsvOutputFilename(), 'hms');
         $reportCmd = CommandFactory::getCommand('ShowReportDetail');
         $reportCmd->setReportClass($report->getClass());
         $reportCmd->redirect();
     }
     $pdf = file_get_contents($report->getCsvOutputFilename());
     // Hoepfully force the browser to open a 'save as' dialogue
     header('Content-Type: text/csv');
     header('Cache-Control: public, must-revalidate, max-age=0');
     // HTTP/1.1
     header('Pragma: public');
     header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
     // Date in the past
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
     header('Content-Length: ' . strlen($pdf));
     header('Content-Disposition: attachment; filename="' . basename($report->getCsvOutputFilename()) . '";');
     echo $pdf;
     exit;
 }