From 59f220eb1307fd881ba43e809e0a729432d83d86 Mon Sep 17 00:00:00 2001 From: Martynas Mickevicius Date: Fri, 6 Aug 2010 13:22:04 +0300 Subject: [PATCH] added check for json encoder, cleaned up error handling a bit --- js/pMap.js | 6 +++ libraries/chart.lib.php | 14 ++++--- libraries/chart/pChart/pChart.class | 4 +- libraries/chart/pma_pchart_chart.php | 61 +++++++++++++++------------- tbl_chart.php | 7 ++-- 5 files changed, 52 insertions(+), 40 deletions(-) diff --git a/js/pMap.js b/js/pMap.js index fc3f73849..bfcd4d235 100644 --- a/js/pMap.js +++ b/js/pMap.js @@ -23,6 +23,12 @@ var imageMap = { 'mouseMoved': function(event, cont) { + // return if no imageMap set + // this can happen if server has no json + if (!this.imageMap) { + return; + } + // get mouse coordinated relative to image var mouseX = event.pageX - cont.offsetLeft; var mouseY = event.pageY - cont.offsetTop; diff --git a/libraries/chart.lib.php b/libraries/chart.lib.php index 3939e552e..b8213f2ad 100644 --- a/libraries/chart.lib.php +++ b/libraries/chart.lib.php @@ -1,7 +1,7 @@ toString(); $chartSettings = $chart->getSettings(); - $chartErrors = array_merge($chartErrors, $chart->getErrors()); + $chartErrors = $chart->getErrors(); PMA_handle_chart_err($chartErrors); return $chartCode; @@ -241,6 +240,9 @@ function PMA_handle_chart_err($errors) if (in_array(ERR_NO_GD, $errors)) { PMA_warnMissingExtension('GD', false, 'GD extension is needed for charts.'); } + else if (in_array(ERR_NO_JSON, $errors)) { + PMA_warnMissingExtension('JSON', false, 'JSON encoder is needed for chart tooltips.'); + } } ?> diff --git a/libraries/chart/pChart/pChart.class b/libraries/chart/pChart/pChart.class index eb2bc4693..2b5a07721 100644 --- a/libraries/chart/pChart/pChart.class +++ b/libraries/chart/pChart/pChart.class @@ -3495,7 +3495,7 @@ /* Get the current image map */ function getImageMap() { - return json_encode($this->ImageMap); + return $this->ImageMap; } /* Load and cleanup the image map from disk */ @@ -3544,7 +3544,7 @@ } else { - fwrite($Handle, $this->getImageMap()); + fwrite($Handle, serialize($this->getImageMap())); } fclose ($Handle); } diff --git a/libraries/chart/pma_pchart_chart.php b/libraries/chart/pma_pchart_chart.php index 97af13604..bcca2ac28 100644 --- a/libraries/chart/pma_pchart_chart.php +++ b/libraries/chart/pma_pchart_chart.php @@ -171,37 +171,42 @@ abstract class PMA_pChart_Chart extends PMA_Chart public function toString() { - if (function_exists('gd_info')) { - $this->init(); - $this->prepareDataSet(); - $this->prepareChart(); - - //$this->chart->debugImageMap(); - - if ($this->isContinuous()) { - $this->render(1); - } - else { - $this->render(20); - } - - $returnData = '
'; - foreach ($this->partsEncoded as $part) { - $returnData .= ''; - } - $returnData .= '
'; - $returnData .= ' - - '; - - return $returnData; - } - else { + if (!function_exists('gd_info')) { array_push($this->errors, ERR_NO_GD); return ''; } + + $this->init(); + $this->prepareDataSet(); + $this->prepareChart(); + + //$this->chart->debugImageMap(); + + if ($this->isContinuous()) { + $this->render(1); + } + else { + $this->render(20); + } + + $returnData = '
'; + foreach ($this->partsEncoded as $part) { + $returnData .= ''; + } + $returnData .= '
'; + + if (function_exists('json_encode')) { + $returnData .= ' + + '; + } + else { + array_push($this->errors, ERR_NO_JSON); + } + + return $returnData; } protected function getLabelHeight() diff --git a/tbl_chart.php b/tbl_chart.php index 31118bd8c..4e8f555e2 100644 --- a/tbl_chart.php +++ b/tbl_chart.php @@ -50,11 +50,10 @@ if (PMA_isValid($_REQUEST['chartSettings'], 'array')) { $chartSettings = $_REQUEST['chartSettings']; } -// get the chart and settings and errors after chart generation -$chartErrors = array(); -$chart = PMA_chart_results($data, $chartSettings, $chartErrors); +// get the chart and settings after chart generation +$chart = PMA_chart_results($data, $chartSettings); -if (empty($chartErrors)) { +if (!empty($chart)) { $message = PMA_Message::success(__('Chart generated successfully.')); } else {