function view_custom_report_print()
 {
     $this->setLayout("html");
     $params = json_decode(str_replace("'", '"', array_var($_POST, 'post')), true);
     $report_id = array_var($_POST, 'id');
     $order_by = array_var($_POST, 'order_by');
     if (!isset($order_by)) {
         $order_by = '';
     }
     tpl_assign('order_by', $order_by);
     $order_by_asc = array_var($_POST, 'order_by_asc');
     if (!isset($order_by_asc)) {
         $order_by_asc = true;
     }
     tpl_assign('order_by_asc', $order_by_asc);
     $report = Reports::getReport($report_id);
     $results = Reports::executeReport($report_id, $params, $order_by, $order_by_asc, 0, 50, true);
     if (isset($results['columns'])) {
         tpl_assign('columns', $results['columns']);
     }
     if (isset($results['rows'])) {
         tpl_assign('rows', $results['rows']);
     }
     tpl_assign('db_columns', $results['db_columns']);
     if (array_var($_POST, 'exportCSV')) {
         $this->generateCSVReport($report, $results);
     } else {
         if (array_var($_POST, 'exportPDF')) {
             $this->generatePDFReport($report, $results);
         } else {
             tpl_assign('types', self::get_report_column_types($report_id));
             tpl_assign('template_name', 'view_custom_report');
             tpl_assign('title', $report->getName());
             tpl_assign('model', $report->getObjectType());
             tpl_assign('description', $report->getDescription());
             $conditions = ReportConditions::getAllReportConditions($report_id);
             tpl_assign('conditions', $conditions);
             tpl_assign('parameters', $params);
             tpl_assign('id', $report_id);
             tpl_assign('to_print', true);
             $this->setTemplate('report_printer');
         }
     }
 }
 function view_custom_report_print()
 {
     $this->setLayout("html");
     set_time_limit(0);
     $params = json_decode(str_replace("'", '"', array_var($_POST, 'post')), true);
     $report_params = json_decode(str_replace("'", '"', array_var($_POST, 'report_params')), true);
     $report_id = array_var($_POST, 'id');
     $order_by = array_var($_POST, 'order_by');
     if (!isset($order_by)) {
         $order_by = '';
     }
     tpl_assign('order_by', $order_by);
     $order_by_asc = array_var($_POST, 'order_by_asc');
     if (!isset($order_by_asc)) {
         $order_by_asc = true;
     }
     tpl_assign('order_by_asc', $order_by_asc);
     $report = Reports::getReport($report_id);
     $limit = array_var($_POST, 'exportCSV') || array_var($_POST, 'exportPDF') ? -1 : 50;
     $results = Reports::executeReport($report_id, $report_params, $order_by, $order_by_asc, 0, $limit, true);
     if (isset($results['columns'])) {
         tpl_assign('columns', $results['columns']);
     }
     if (isset($results['rows'])) {
         tpl_assign('rows', $results['rows']);
     }
     tpl_assign('db_columns', $results['db_columns']);
     if (array_var($_POST, 'exportCSV')) {
         $filename = $this->generateCSVReport($report, $results);
         ajx_current("empty");
         ajx_extra_data(array('filename' => $filename));
     } else {
         if (array_var($_POST, 'exportPDF') && !is_exec_available()) {
             $this->generatePDFReport($report, $results);
         } else {
             tpl_assign('types', self::get_report_column_types($report_id));
             tpl_assign('template_name', 'view_custom_report');
             tpl_assign('title', $report->getObjectName());
             $ot = ObjectTypes::findById($report->getReportObjectTypeId());
             tpl_assign('model', $ot->getHandlerClass());
             tpl_assign('description', $report->getDescription());
             $conditions = ReportConditions::getAllReportConditions($report_id);
             tpl_assign('conditions', $conditions);
             tpl_assign('parameters', $params);
             tpl_assign('id', $report_id);
             tpl_assign('to_print', true);
             if (array_var($_POST, 'exportPDF')) {
                 tpl_assign('pdf_export', true);
                 $html_filename = ROOT . '/tmp/' . gen_id() . 'pdf.html';
                 $pdf_filename = $report->getObjectName() . '.pdf';
                 tpl_assign('html_filename', $html_filename);
                 tpl_assign('pdf_filename', $pdf_filename);
                 tpl_assign('orientation', array_var($_POST, 'pdfPageLayout') == 'L' ? 'Landscape' : 'Portrait');
                 ob_start();
             }
             $this->setTemplate('report_printer');
         }
     }
 }