From c39d7b122766ac09c79712b2242ad099bc77a8a7 Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Sun, 28 Oct 2012 02:42:04 +0530 Subject: [PATCH] Fix bug #3571970 - Display chart and number of rows to plot --- ChangeLog | 1 + js/tbl_chart.js | 79 ++++++++++++++++++++++++++++++++++++++----------- tbl_chart.php | 63 ++++++++++++++++++++++++++++----------- 3 files changed, 108 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index a2312adc6d..ffc1f797ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,7 @@ phpMyAdmin - ChangeLog - bug #3576322 [search] Invalid select query generated for tables with ENUM fields - bug #3577468 [display] Incorrect imagejpeg Syntax Breaks Image Transformation - bug #3578776 [search] Editing SQL not possible when no records found +- bug #3571970 [interface] Display chart and number of rows to plot 3.5.3.0 (2012-10-08) - bug #3539044 [interface] Browse mode "Show" button gives blank page if no results anymore diff --git a/js/tbl_chart.js b/js/tbl_chart.js index ce7a4c633c..6e395e72c1 100644 --- a/js/tbl_chart.js +++ b/js/tbl_chart.js @@ -4,10 +4,13 @@ var chart_xaxis_idx = -1; var chart_series; var chart_series_index = -1; var temp_chart_title; +var currentChart = null; +var chart_data = null; +var nonJqplotSettings = null; +var currentSettings = null; + $(document).ready(function() { - var currentChart = null; - var chart_data = jQuery.parseJSON($('#querychart').html()); chart_series = 'columns'; chart_xaxis_idx = $('select[name="chartXAxis"]').attr('value'); @@ -24,15 +27,15 @@ $(document).ready(function() { currentChart.replot( {resetAxes: true}) }); - var nonJqplotSettings = { + nonJqplotSettings = { chart: { type: 'line', width: $('#resizer').width() - 20, height: $('#resizer').height() - 20 } - } + }; - var currentSettings = { + currentSettings = { grid: { drawBorder: false, shadow: false, @@ -57,7 +60,7 @@ $(document).ready(function() { placement: 'outsideGrid', location: 'se' } - } + }; $('#querychart').html(''); @@ -118,20 +121,62 @@ $(document).ready(function() { drawChart(); }); - function drawChart() { - nonJqplotSettings.chart.width = $('#resizer').width() - 20; - nonJqplotSettings.chart.height = $('#resizer').height() - 20; +}); - // todo: a better way using .replot() ? - if (currentChart != null) { - currentChart.destroy(); - } - currentChart = PMA_queryChart(chart_data, currentSettings, nonJqplotSettings); +/** + * Ajax Event handler for 'Go' button click + * + */ +$("#tblchartform").live('submit', function(event) { + + if(!checkFormElementInRange(this, 'session_max_rows', PMA_messages['strNotValidRowNumber'], 1) + || !checkFormElementInRange(this, 'pos', PMA_messages['strNotValidRowNumber'], 0-1)) { + return false; } - drawChart(); - $('#querychart').show(); -}); + var $form = $(this); + if (! checkSqlQuery($form[0])) { + return false; + } + + // remove any div containing a previous error message + $('.error').remove(); + + var $msgbox = PMA_ajaxShowMessage(); + + PMA_prepareForAjaxRequest($form); + + $.post($form.attr('action'), $form.serialize() , function(data) { + if (data.success == true) { + $('.success').fadeOut(); + + if (typeof data.chartData != 'undefined') { + chart_data = jQuery.parseJSON(data.chartData); + drawChart(); + $('#querychart').show(); + } + } else { + PMA_ajaxRemoveMessage($msgbox); + PMA_ajaxShowMessage(data.error, false); + chart_data = null; + drawChart(); + } + PMA_ajaxRemoveMessage($msgbox); + }, "json"); // end $.post() + + return false; +}); // end + +function drawChart() { + nonJqplotSettings.chart.width = $('#resizer').width() - 20; + nonJqplotSettings.chart.height = $('#resizer').height() - 20; + + // todo: a better way using .replot() ? + if (currentChart != null) { + currentChart.destroy(); + } + currentChart = PMA_queryChart(chart_data, currentSettings, nonJqplotSettings); +} function in_array(element,array) { diff --git a/tbl_chart.php b/tbl_chart.php index c3c9210d70..af1dd08a73 100644 --- a/tbl_chart.php +++ b/tbl_chart.php @@ -18,6 +18,43 @@ if (! defined('PMA_NO_VARIABLES_IMPORT')) { * */ require_once './libraries/common.inc.php'; +require_once './libraries/common.lib.php'; + +/* + * Execute the query and return the result + */ +if(isset($_REQUEST['ajax_request']) && isset($_REQUEST['pos']) && isset($_REQUEST['session_max_rows'])) { + + if (strlen($GLOBALS['table']) && strlen($GLOBALS['db'])) { + include './libraries/tbl_common.php'; + } + else { + PMA_ajaxResponse(__('Error'), false); + } + + $sql_limit_to_append = ' LIMIT ' . $_REQUEST['pos'] . ', ' . $_REQUEST['session_max_rows'] . " "; + $sql_query .= $sql_limit_to_append; + + $data = array(); + $result = PMA_DBI_try_query($sql_query); + while ($row = PMA_DBI_fetch_assoc($result)) { + $data[] = $row; + } + if(empty($data)) + PMA_ajaxResponse(__('Error'), false); + + $sanitized_data = array(); + foreach ($data as $data_row_number => $data_row) { + $tmp_row = array(); + foreach ($data_row as $data_column => $data_value) { + $tmp_row[htmlspecialchars($data_column)] = htmlspecialchars($data_value); + } + $sanitized_data[] = $tmp_row; + } + $extra_data['chartData'] = json_encode($sanitized_data); + unset($sanitized_data); + PMA_ajaxResponse(null, true, $extra_data); +} $GLOBALS['js_include'][] = 'tbl_chart.js'; $GLOBALS['js_include'][] = 'jqplot/jquery.jqplot.js'; @@ -56,11 +93,7 @@ if (strlen($GLOBALS['table'])) { include './libraries/server_links.inc.php'; } -/* - * Execute the query and return the result - */ $data = array(); - $result = PMA_DBI_try_query($sql_query); while ($row = PMA_DBI_fetch_assoc($result)) { $data[] = $row; @@ -86,7 +119,7 @@ url_query = '';
-
+
@@ -146,23 +179,17 @@ url_query = '';
- +
+ +
+ +
+ +

 

- $data_row) { - $tmp_row = array(); - foreach ($data_row as $data_column => $data_value) { - $tmp_row[htmlspecialchars($data_column)] = htmlspecialchars($data_value); - } - $sanitized_data[] = $tmp_row; -} -echo json_encode($sanitized_data); -unset($sanitized_data); -?>