Translated using Weblate (Slovenian)
[phpmyadmin.git] / tbl_chart.php
blobf6cd4c0644fe083087c4819955e76bc4740ead63
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/Template.class.php';
11 use PMA\Template;
14 * Execute the query and return the result
16 if (isset($_REQUEST['ajax_request'])
17 && isset($_REQUEST['pos'])
18 && isset($_REQUEST['session_max_rows'])
19 ) {
20 $response = PMA_Response::getInstance();
22 $tableLength = /*overload*/mb_strlen($GLOBALS['table']);
23 $dbLength = /*overload*/mb_strlen($GLOBALS['db']);
24 if ($tableLength && $dbLength) {
25 include './libraries/tbl_common.inc.php';
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');
80 /**
81 * Runs common work
83 if (/*overload*/mb_strlen($GLOBALS['table'])) {
84 $url_params['goto'] = PMA_Util::getScriptNameForOption(
85 $GLOBALS['cfg']['DefaultTabTable'], 'table'
87 $url_params['back'] = 'tbl_sql.php';
88 include 'libraries/tbl_common.inc.php';
89 include 'libraries/tbl_info.inc.php';
90 } elseif (/*overload*/mb_strlen($GLOBALS['db'])) {
91 $url_params['goto'] = PMA_Util::getScriptNameForOption(
92 $GLOBALS['cfg']['DefaultTabDatabase'], 'database'
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'] = PMA_Util::getScriptNameForOption(
99 $GLOBALS['cfg']['DefaultTabServer'], 'server'
101 $url_params['back'] = 'sql.php';
102 include 'libraries/server_common.inc.php';
105 $data = array();
107 $result = $GLOBALS['dbi']->tryQuery($sql_query);
108 $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
109 while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
110 $data[] = $row;
113 $keys = array_keys($data[0]);
115 $numeric_types = array('int', 'real');
116 $numeric_column_count = 0;
117 foreach ($keys as $idx => $key) {
118 if (in_array($fields_meta[$idx]->type, $numeric_types)) {
119 $numeric_column_count++;
122 if ($numeric_column_count == 0) {
123 $response->isSuccess(false);
124 $response->addJSON(
125 'message',
126 __('No numeric columns present in the table to plot.')
128 exit;
131 // get settings if any posted
132 $chartSettings = array();
133 if (PMA_isValid($_REQUEST['chartSettings'], 'array')) {
134 $chartSettings = $_REQUEST['chartSettings'];
137 $url_params['db'] = $GLOBALS['db'];
138 $url_params['reload'] = 1;
141 * Displays the page
143 $response->addHTML(
144 Template::get('tbl_chart')
145 ->render(
146 array(
147 'url_query' => $url_query,
148 'url_params' => $url_params,
149 'keys' => $keys,
150 'fields_meta' => $fields_meta,
151 'numeric_types' => $numeric_types,
152 'numeric_column_count' => $numeric_column_count,
153 'sql_query' => $sql_query