function display()
 {
     global $locale;
     //add chart
     if (isset($_REQUEST['id']) && $_REQUEST['id'] != false) {
         $this->bean->is_saved_report = true;
     }
     // fixing bug #47260: Print PDF Reports
     // if chart_type is 'none' we don't need do add any image to pdf
     if ($this->bean->chart_type != 'none') {
         $chartDisplay = new ChartDisplay();
         $xmlFile = $chartDisplay->get_cache_file_name($this->bean);
         $sugarChart = SugarChartFactory::getInstance();
         if ($sugarChart->supports_image_export) {
             $imageFile = $sugarChart->get_image_cache_file_name($xmlFile, "." . $sugarChart->image_export_type);
             // check image size is not '0'
             if (file_exists($imageFile) && getimagesize($imageFile) > 0) {
                 $this->AddPage();
                 list($width, $height) = getimagesize($imageFile);
                 $imageWidthAsUnits = $this->pixelsToUnits($width);
                 $imageHeightAsUnits = $this->pixelsToUnits($height);
                 $dimensions = $this->getPageDimensions();
                 $pageWidth = $dimensions['wk'];
                 $pageHeight = $dimensions['hk'];
                 $marginTop = $dimensions['tm'];
                 $marginBottom = $dimensions['bm'];
                 $marginLeft = $dimensions['lm'];
                 $marginRight = $dimensions['rm'];
                 $freeWidth = 0.9 * ($pageWidth - $marginLeft - $marginRight);
                 $freeHeight = 0.9 * ($pageHeight - $marginTop - $marginBottom);
                 $rate = min($freeHeight / $imageHeightAsUnits, $freeWidth / $imageWidthAsUnits, 2);
                 $imageWidth = floor($rate * $imageWidthAsUnits);
                 $imageHeight = floor($rate * $imageHeightAsUnits);
                 $leftOffset = $this->GetX() + ($pageWidth - $marginLeft - $marginRight - $imageWidth) / 2;
                 $topOffset = $this->GetY();
                 $this->Image($imageFile, $leftOffset, $topOffset, $imageWidth, $imageHeight, "", "", "N", false, 300, "", false, false, 0, true);
                 if ($sugarChart->print_html_legend_pdf) {
                     $legend = $sugarChart->buildHTMLLegend($xmlFile);
                     $this->writeHTML($legend, true, false, false, true, "");
                 }
             }
         }
     }
     //Create new page
     $this->AddPage();
     $this->bean->run_summary_query();
     $item = array();
     $header_row = $this->bean->get_summary_header_row();
     $count = 0;
     if (count($this->bean->report_def['summary_columns']) == 0) {
         $item[$count][''] = '';
         $count++;
     }
     if (count($this->bean->report_def['summary_columns']) > 0) {
         while ($row = $this->bean->get_summary_next_row()) {
             for ($i = 0; $i < sizeof($header_row); $i++) {
                 $label = $header_row[$i];
                 $value = '';
                 if (isset($row['cells'][$i])) {
                     $value = $row['cells'][$i];
                 }
                 $item[$count][$label] = $value;
             }
             $count++;
         }
     }
     $this->writeCellTable($item, $this->options);
     $this->Ln1();
     $this->bean->clear_results();
     if ($this->bean->has_summary_columns()) {
         $this->bean->run_total_query();
     }
     $total_header_row = $this->bean->get_total_header_row();
     $total_row = $this->bean->get_summary_total_row();
     $item = array();
     $count = 0;
     for ($j = 0; $j < sizeof($total_header_row); $j++) {
         $label = $total_header_row[$j];
         $item[$count][$label] = $total_row['cells'][$j];
     }
     $this->writeCellTable($item, $this->options);
 }
Example #2
0
 /**
  * Displays the javascript for the dashlet
  *
  * @return string javascript to use with this dashlet
  */
 function displayScript()
 {
     require_once "modules/Reports/Report.php";
     require_once "include/SugarCharts/ChartDisplay.php";
     $chartReport = BeanFactory::getBean('Reports', $this->report_id, array("encode" => false));
     if (!empty($chartReport)) {
         $this->title = $chartReport->name;
         require_once "modules/Reports/templates/templates_chart.php";
         require_once 'include/SugarCharts/SugarChartFactory.php';
         $sugarChart = SugarChartFactory::getInstance();
         $reporter = new Report($chartReport->content);
         $reporter->is_saved_report = true;
         $reporter->saved_report_id = $chartReport->id;
         // Bug #57213 : Reports with data series removed render charts inconsistently
         if ($reporter && !$reporter->has_summary_columns()) {
             return '';
         }
         $chartDisplay = new ChartDisplay();
         $xmlFile = $chartDisplay->get_cache_file_name($reporter);
         $str = $sugarChart->getDashletScript($this->id, $xmlFile);
         return $str;
     }
 }
 function display()
 {
     global $app_list_strings, $locale;
     //add chart
     if (isset($_REQUEST['id']) && $_REQUEST['id'] != false) {
         $this->bean->is_saved_report = true;
     }
     // fixing bug #47260: Print PDF Reports
     // if chart_type is 'none' we don't need do add any image to pdf
     if ($this->bean->chart_type != 'none') {
         $chartDisplay = new ChartDisplay();
         $xmlFile = $chartDisplay->get_cache_file_name($this->bean);
         $sugarChart = SugarChartFactory::getInstance();
         if ($sugarChart->supports_image_export) {
             $imageFile = $sugarChart->get_image_cache_file_name($xmlFile, "." . $sugarChart->image_export_type);
             // check image size is not '0'
             if (file_exists($imageFile) && getimagesize($imageFile) > 0) {
                 $this->AddPage();
                 list($width, $height) = getimagesize($imageFile);
                 $imageWidthAsUnits = $this->pixelsToUnits($width);
                 $imageHeightAsUnits = $this->pixelsToUnits($height);
                 $dimensions = $this->getPageDimensions();
                 $pageWidth = $dimensions['wk'];
                 $pageHeight = $dimensions['hk'];
                 $marginTop = $dimensions['tm'];
                 $marginBottom = $dimensions['bm'];
                 $marginLeft = $dimensions['lm'];
                 $marginRight = $dimensions['rm'];
                 $freeWidth = 0.9 * ($pageWidth - $marginLeft - $marginRight);
                 $freeHeight = 0.9 * ($pageHeight - $marginTop - $marginBottom);
                 $rate = min($freeHeight / $imageHeightAsUnits, $freeWidth / $imageWidthAsUnits, 2);
                 $imageWidth = floor($rate * $imageWidthAsUnits);
                 $imageHeight = floor($rate * $imageHeightAsUnits);
                 $leftOffset = $this->GetX() + ($freeWidth - $imageWidth) / 2;
                 $topOffset = $this->GetY() + ($freeHeight - $imageHeight) / 2;
                 $this->Image($imageFile, $leftOffset, $topOffset, $imageWidth, $imageHeight, "", "", "N", false, 300, "", false, false, 0, true);
                 if ($sugarChart->print_html_legend_pdf) {
                     $legend = $sugarChart->buildHTMLLegend($xmlFile);
                     $this->writeHTML($legend, true, false, false, true, "");
                 }
             }
         }
     }
     $this->AddPage();
     //disable paging so we get all results in one pass
     $this->bean->enable_paging = false;
     $cols = count($this->bean->report_def['display_columns']);
     $this->bean->run_summary_combo_query();
     $header_row = $this->bean->get_summary_header_row();
     $columns_row = $this->bean->get_header_row();
     // build options for the writeHTMLTable from options for the writeCellTable
     $options = array('header' => array("tr" => array("bgcolor" => $this->options['header']['fill'], "color" => $this->options['header']['textColor']), "td" => array()), 'evencolor' => $this->options['evencolor'], 'oddcolor' => $this->options['oddcolor']);
     while (($row = $this->bean->get_summary_next_row()) != 0) {
         $item = array();
         $count = 0;
         for ($i = 0; $i < $this->bean->current_summary_row_count; $i++) {
             if (($column_row = $this->bean->get_next_row('result', 'display_columns', false, true)) != 0) {
                 for ($j = 0; $j < sizeof($columns_row); $j++) {
                     $label = $columns_row[$j];
                     $item[$count][$label] = $column_row['cells'][$j];
                 }
                 $count++;
             } else {
                 break;
             }
         }
         $this->writeHTMLTable($item, false, $options);
         $this->Ln1();
         $item = array();
         $count = 0;
         for ($j = 0; $j < sizeof($row['cells']); $j++) {
             if ($j > count($header_row) - 1) {
                 $label = $header_row[count($header_row) - 1];
             } else {
                 $label = $header_row[$j];
             }
             if (preg_match('/type.*=.*checkbox/Uis', $row['cells'][$j])) {
                 // parse out checkboxes
                 if (preg_match('/checked/i', $row['cells'][$j])) {
                     $row['cells'][$j] = $app_list_strings['dom_switch_bool']['on'];
                 } else {
                     $row['cells'][$j] = $app_list_strings['dom_switch_bool']['off'];
                 }
             }
             $value = $row['cells'][$j];
             $item[$count][$label] = $value;
         }
         $this->writeHTMLTable($item, false, $options);
         $this->Ln1();
     }
     $this->bean->clear_results();
     if ($this->bean->has_summary_columns()) {
         $this->bean->run_total_query();
         $total_row = $this->bean->get_summary_total_row();
         $item = array();
         $count = 0;
         for ($j = 0; $j < sizeof($header_row); $j++) {
             $label = $header_row[$j];
             $value = $total_row['cells'][$j];
             $item[$count][$label] = $value;
         }
         $this->writeHTMLTable($item, false, $options);
     }
 }
 /**
  * Retrieves a saved report and chart data, given a report ID in the args
  *
  * @param $api ServiceBase The API class of the request
  * @param $args array The arguments array passed in from the API
  * @return array
  */
 public function getSavedReportChartById($api, $args)
 {
     require_once "include/SugarCharts/ChartDisplay.php";
     $chartReport = $this->getSavedReportById($args['reportId']);
     if (isset($args['filter_id']) && $args['filter_id'] !== 'all_records') {
         $chartReport->content = $this->updateFilterDef($chartReport->content, $args['filter_id']);
     }
     if (!empty($chartReport)) {
         if (!$chartReport->ACLAccess('view')) {
             throw new SugarApiExceptionNotAuthorized('No access to view this report');
         }
         $returnData = array();
         $this->title = $chartReport->name;
         require_once "modules/Reports/Report.php";
         $reporter = new Report($chartReport->content);
         $reporter->saved_report_id = $chartReport->id;
         if ($reporter && !$reporter->has_summary_columns()) {
             return '';
         }
         // build report data since it isn't a SugarBean
         $reportData = array();
         $reportData['name'] = $reporter->name;
         $reportData['id'] = $reporter->saved_report_id;
         $reportData['summary_columns'] = $reporter->report_def['summary_columns'];
         $reportData['group_defs'] = $reporter->report_def['group_defs'];
         // add reportData to returnData
         $returnData['reportData'] = $reportData;
         $chartDisplay = new ChartDisplay();
         $chartDisplay->setReporter($reporter);
         $chart = $chartDisplay->getSugarChart();
         $json = json_decode($chart->buildJson($chart->generateXML()));
         $returnData['chartData'] = $json;
         return $returnData;
     }
 }
function reportResults(&$reporter, &$args)
{
    ob_start();
    echo '<div id="report_results">';
    $do_chart = false;
    if ($reporter->report_type == 'summary' && !empty($reporter->report_def['summary_columns'])) {
        if ($reporter->show_columns && !empty($reporter->report_def['display_columns']) && !empty($reporter->report_def['group_defs'])) {
            template_summary_combo_view($reporter, $args);
            $do_chart = true;
        } else {
            if ($reporter->show_columns && !empty($reporter->report_def['display_columns']) && empty($reporter->report_def['group_defs'])) {
                template_detail_and_total_list_view($reporter, $args);
            } else {
                if (!empty($reporter->report_def['group_defs'])) {
                    template_summary_list_view($reporter, $args);
                    $do_chart = true;
                } else {
                    template_total_view($reporter, $args);
                }
            }
        }
        // else
    } else {
        if (!empty($reporter->report_def['display_columns'])) {
            template_list_view($reporter, $args);
        }
    }
    // else if
    $searchArray = array("'", "\r\n", "\n");
    $replaceArray = array("\\'", "", "");
    $filterStringForUI = str_replace($searchArray, $replaceArray, $reporter->createFilterStringForUI());
    echo "<script>var filterString='" . htmlspecialchars($filterStringForUI) . "';</script>";
    if ($reporter->report_def['chart_type'] == 'none') {
        $do_chart = false;
    }
    echo '</div>';
    $contents = ob_get_contents();
    ob_end_clean();
    if ($do_chart) {
        global $mod_strings;
        $reportChartButtonTitle = $mod_strings['LBL_REPORT_HIDE_CHART'];
        $reportChartDivStyle = "";
        if (isset($args['reportCache'])) {
            $reportCache = $args['reportCache'];
            if (!empty($reportCache->report_options_array)) {
                if (array_key_exists("showChart", $reportCache->report_options_array) && !$reportCache->report_options_array['showChart']) {
                    $reportChartButtonTitle = $mod_strings['LBL_REPORT_SHOW_CHART'];
                    $reportChartDivStyle = "display:none";
                }
            }
            // if
        }
        // if
        echo "<input class=\"button\" name=\"showHideChartButton\" id=\"showHideChartButton\" title=\"{$reportChartButtonTitle}\"\n\ttype=\"button\" value=\"{$reportChartButtonTitle}\" onclick=\"showHideChart();\"><br/><br/>";
        echo "<script>function showHideChart() {\n\tvar idObject = document.getElementById('record');\n\tvar id = '';\n\tif (idObject != null) {\n\t\tid = idObject.value;\n\t} // if\n\tvar chartId = document.getElementById(id + '_div');\n\tvar showHideChartButton = document.getElementById('showHideChartButton');\n\tif (chartId.style.display == \"none\") {\n\t\tsaveReportOptionsState('showChart', '1');\n\t\tchartId.style.display = \"\";\n\t\tshowHideChartButton.title = \"{$mod_strings['LBL_REPORT_HIDE_CHART']}\";\n\t\tshowHideChartButton.value = \"{$mod_strings['LBL_REPORT_HIDE_CHART']}\";\n\t\tloadCustomChartForReports();\n\t} else {\n\t\tchartId.style.display = 'none';\n\t\tsaveReportOptionsState('showChart', '0');\n\t\tshowHideChartButton.title = \"{$mod_strings['LBL_REPORT_SHOW_CHART']}\";\n\t\tshowHideChartButton.value = \"{$mod_strings['LBL_REPORT_SHOW_CHART']}\";\n\t} // else\n} </script>";
        if (isset($reporter->saved_report->id)) {
            $report_id = $reporter->saved_report->id;
        } elseif (!empty($_REQUEST['record'])) {
            $report_id = $_REQUEST['record'];
        } else {
            $report_id = 'unsavedReport';
        }
        echo "<div class='reportChartContainer' id='{$report_id}_div' style='{$reportChartDivStyle}'>";
        require_once "include/SugarCharts/ChartDisplay.php";
        $chartDisplay = new ChartDisplay();
        $chartDisplay->setReporter($reporter);
        echo "<div align='center'>" . $chartDisplay->legacyDisplay(null, false) . "</div>";
        echo "</div>";
    }
    // if
    print $contents;
}