Translated using Weblate (Indonesian)
[phpmyadmin.git] / tbl_chart.php
blobe06114f30c9dc0e55ec2817fe7f30772107adacf
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';
12 * Execute the query and return the result
14 if (isset($_REQUEST['ajax_request'])
15 && isset($_REQUEST['pos'])
16 && isset($_REQUEST['session_max_rows'])
17 ) {
18 $response = PMA_Response::getInstance();
20 if (strlen($GLOBALS['table']) && strlen($GLOBALS['db'])) {
21 include './libraries/tbl_common.inc.php';
22 } else {
23 $response->isSuccess(false);
24 $response->addJSON('message', __('Error'));
25 exit;
28 $sql_with_limit = 'SELECT * FROM( ' . $sql_query . ' ) AS `temp_res` LIMIT '
29 . $_REQUEST['pos'] . ', ' . $_REQUEST['session_max_rows'];
30 $data = array();
31 $result = $GLOBALS['dbi']->tryQuery($sql_with_limit);
32 while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
33 $data[] = $row;
36 if (empty($data)) {
37 $response->isSuccess(false);
38 $response->addJSON('message', __('No data to display'));
39 exit;
41 $sanitized_data = array();
43 foreach ($data as $data_row_number => $data_row) {
44 $tmp_row = array();
45 foreach ($data_row as $data_column => $data_value) {
46 $tmp_row[htmlspecialchars($data_column)] = htmlspecialchars($data_value);
48 $sanitized_data[] = $tmp_row;
50 $response->isSuccess(true);
51 $response->addJSON('message', null);
52 $response->addJSON('chartData', json_encode($sanitized_data));
53 unset($sanitized_data);
54 exit;
57 $response = PMA_Response::getInstance();
58 // Throw error if no sql query is set
59 if (! isset($sql_query) || $sql_query == '') {
60 $response->isSuccess(false);
61 $response->addHTML(
62 PMA_Message::error(__('No SQL query was set to fetch data.'))
64 exit;
66 $header = $response->getHeader();
67 $scripts = $header->getScripts();
68 $scripts->addFile('chart.js');
69 $scripts->addFile('tbl_chart.js');
70 $scripts->addFile('jqplot/jquery.jqplot.js');
71 $scripts->addFile('jqplot/plugins/jqplot.barRenderer.js');
72 $scripts->addFile('jqplot/plugins/jqplot.canvasAxisLabelRenderer.js');
73 $scripts->addFile('jqplot/plugins/jqplot.canvasTextRenderer.js');
74 $scripts->addFile('jqplot/plugins/jqplot.categoryAxisRenderer.js');
75 $scripts->addFile('jqplot/plugins/jqplot.dateAxisRenderer.js');
76 $scripts->addFile('jqplot/plugins/jqplot.pointLabels.js');
77 $scripts->addFile('jqplot/plugins/jqplot.pieRenderer.js');
78 $scripts->addFile('jqplot/plugins/jqplot.highlighter.js');
79 /* < IE 9 doesn't support canvas natively */
80 if (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 9) {
81 $scripts->addFile('canvg/flashcanvas.js');
84 /**
85 * Runs common work
87 if (strlen($GLOBALS['table'])) {
88 $url_params['goto'] = $cfg['DefaultTabTable'];
89 $url_params['back'] = 'tbl_sql.php';
90 include 'libraries/tbl_common.inc.php';
91 include 'libraries/tbl_info.inc.php';
92 } elseif (strlen($GLOBALS['db'])) {
93 $url_params['goto'] = $cfg['DefaultTabDatabase'];
94 $url_params['back'] = 'sql.php';
95 include 'libraries/db_common.inc.php';
96 include 'libraries/db_info.inc.php';
97 } else {
98 $url_params['goto'] = $cfg['DefaultTabServer'];
99 $url_params['back'] = 'sql.php';
100 include 'libraries/server_common.inc.php';
103 $data = array();
105 $result = $GLOBALS['dbi']->tryQuery($sql_query);
106 $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
107 while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
108 $data[] = $row;
111 $keys = array_keys($data[0]);
113 $numeric_types = array('int', 'real');
114 $numeric_column_count = 0;
115 foreach ($keys as $idx => $key) {
116 if (in_array($fields_meta[$idx]->type, $numeric_types)) {
117 $numeric_column_count++;
120 if ($numeric_column_count == 0) {
121 $response->isSuccess(false);
122 $response->addJSON(
123 'message',
124 __('No numeric columns present in the table to plot.')
126 exit;
129 // get settings if any posted
130 $chartSettings = array();
131 if (PMA_isValid($_REQUEST['chartSettings'], 'array')) {
132 $chartSettings = $_REQUEST['chartSettings'];
135 $url_params['db'] = $GLOBALS['db'];
136 $url_params['reload'] = 1;
139 * Displays the page
141 $htmlString = PMA_getHtmlForTableChartDisplay(
142 $url_query, $url_params, $keys, $fields_meta, $numeric_types,
143 $numeric_column_count, $sql_query
146 $response->addHTML($htmlString);