Translated using Weblate (Catalan)
[phpmyadmin.git] / tbl_chart.php
blob283aaceba8d8420c3001d6368ce7518c8b0a1226
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * handles creation of the chart
6 * @package PhpMyAdmin
7 */
9 require_once 'libraries/common.inc.php';
10 require_once 'libraries/tbl_chart.lib.php';
13 * Execute the query and return the result
15 if (isset($_REQUEST['ajax_request'])
16 && isset($_REQUEST['pos'])
17 && isset($_REQUEST['session_max_rows'])
18 ) {
19 $response = PMA_Response::getInstance();
21 $tableLength = /*overload*/mb_strlen($GLOBALS['table']);
22 $dbLength = /*overload*/mb_strlen($GLOBALS['db']);
23 if ($tableLength && $dbLength) {
24 include './libraries/tbl_common.inc.php';
27 $sql_with_limit = 'SELECT * FROM( ' . $sql_query . ' ) AS `temp_res` LIMIT '
28 . $_REQUEST['pos'] . ', ' . $_REQUEST['session_max_rows'];
29 $data = array();
30 $result = $GLOBALS['dbi']->tryQuery($sql_with_limit);
31 while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
32 $data[] = $row;
35 if (empty($data)) {
36 $response->isSuccess(false);
37 $response->addJSON('message', __('No data to display'));
38 exit;
40 $sanitized_data = array();
42 foreach ($data as $data_row_number => $data_row) {
43 $tmp_row = array();
44 foreach ($data_row as $data_column => $data_value) {
45 $tmp_row[htmlspecialchars($data_column)] = htmlspecialchars($data_value);
47 $sanitized_data[] = $tmp_row;
49 $response->isSuccess(true);
50 $response->addJSON('message', null);
51 $response->addJSON('chartData', json_encode($sanitized_data));
52 unset($sanitized_data);
53 exit;
56 $response = PMA_Response::getInstance();
57 // Throw error if no sql query is set
58 if (! isset($sql_query) || $sql_query == '') {
59 $response->isSuccess(false);
60 $response->addHTML(
61 PMA_Message::error(__('No SQL query was set to fetch data.'))
63 exit;
65 $header = $response->getHeader();
66 $scripts = $header->getScripts();
67 $scripts->addFile('chart.js');
68 $scripts->addFile('tbl_chart.js');
69 $scripts->addFile('jqplot/jquery.jqplot.js');
70 $scripts->addFile('jqplot/plugins/jqplot.barRenderer.js');
71 $scripts->addFile('jqplot/plugins/jqplot.canvasAxisLabelRenderer.js');
72 $scripts->addFile('jqplot/plugins/jqplot.canvasTextRenderer.js');
73 $scripts->addFile('jqplot/plugins/jqplot.categoryAxisRenderer.js');
74 $scripts->addFile('jqplot/plugins/jqplot.dateAxisRenderer.js');
75 $scripts->addFile('jqplot/plugins/jqplot.pointLabels.js');
76 $scripts->addFile('jqplot/plugins/jqplot.pieRenderer.js');
77 $scripts->addFile('jqplot/plugins/jqplot.highlighter.js');
79 /**
80 * Runs common work
82 if (/*overload*/mb_strlen($GLOBALS['table'])) {
83 $url_params['goto'] = $cfg['DefaultTabTable'];
84 $url_params['back'] = 'tbl_sql.php';
85 include 'libraries/tbl_common.inc.php';
86 include 'libraries/tbl_info.inc.php';
87 } elseif (/*overload*/mb_strlen($GLOBALS['db'])) {
88 $url_params['goto'] = $cfg['DefaultTabDatabase'];
89 $url_params['back'] = 'sql.php';
90 include 'libraries/db_common.inc.php';
91 include 'libraries/db_info.inc.php';
92 } else {
93 $url_params['goto'] = $cfg['DefaultTabServer'];
94 $url_params['back'] = 'sql.php';
95 include 'libraries/server_common.inc.php';
98 $data = array();
100 $result = $GLOBALS['dbi']->tryQuery($sql_query);
101 $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
102 while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
103 $data[] = $row;
106 $keys = array_keys($data[0]);
108 $numeric_types = array('int', 'real');
109 $numeric_column_count = 0;
110 foreach ($keys as $idx => $key) {
111 if (in_array($fields_meta[$idx]->type, $numeric_types)) {
112 $numeric_column_count++;
115 if ($numeric_column_count == 0) {
116 $response->isSuccess(false);
117 $response->addJSON(
118 'message',
119 __('No numeric columns present in the table to plot.')
121 exit;
124 // get settings if any posted
125 $chartSettings = array();
126 if (PMA_isValid($_REQUEST['chartSettings'], 'array')) {
127 $chartSettings = $_REQUEST['chartSettings'];
130 $url_params['db'] = $GLOBALS['db'];
131 $url_params['reload'] = 1;
134 * Displays the page
136 $htmlString = PMA_getHtmlForTableChartDisplay(
137 $url_query, $url_params, $keys, $fields_meta, $numeric_types,
138 $numeric_column_count, $sql_query
141 $response->addHTML($htmlString);