Translated using Weblate.
[phpmyadmin.git] / tbl_chart.php
blob56fce06287c88042ce8f3d2e89743fbf81f931f1
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * handles creation of the chart
6 * @package PhpMyAdmin
7 */
9 /**
10 * do not import request variable into global scope
11 * @ignore
13 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
14 define('PMA_NO_VARIABLES_IMPORT', true);
17 /**
20 require_once './libraries/common.inc.php';
22 $GLOBALS['js_include'][] = 'tbl_chart.js';
23 $GLOBALS['js_include'][] = 'highcharts/highcharts.js';
24 /* Files required for chart exporting */
25 $GLOBALS['js_include'][] = 'highcharts/exporting.js';
26 /* < IE 9 doesn't support canvas natively */
27 if (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 9) {
28 $GLOBALS['js_include'][] = 'canvg/flashcanvas.js';
30 $GLOBALS['js_include'][] = 'canvg/canvg.js';
32 /**
33 * Runs common work
35 if (strlen($GLOBALS['table'])) {
36 $url_params['goto'] = $cfg['DefaultTabTable'];
37 $url_params['back'] = 'tbl_sql.php';
38 include './libraries/tbl_common.php';
39 include './libraries/tbl_info.inc.php';
40 include './libraries/tbl_links.inc.php';
41 } elseif (strlen($GLOBALS['db'])) {
42 $url_params['goto'] = $cfg['DefaultTabDatabase'];
43 $url_params['back'] = 'sql.php';
44 include './libraries/db_common.inc.php';
45 include './libraries/db_info.inc.php';
46 } else {
47 $url_params['goto'] = $cfg['DefaultTabServer'];
48 $url_params['back'] = 'sql.php';
49 include './libraries/server_common.inc.php';
50 include './libraries/server_links.inc.php';
54 * Execute the query and return the result
56 $data = array();
58 $result = PMA_DBI_try_query($sql_query);
59 while ($row = PMA_DBI_fetch_assoc($result)) {
60 $data[] = $row;
63 // get settings if any posted
64 $chartSettings = array();
65 if (PMA_isValid($_REQUEST['chartSettings'], 'array')) {
66 $chartSettings = $_REQUEST['chartSettings'];
69 $url_params['db'] = $GLOBALS['db'];
70 $url_params['reload'] = 1;
72 /**
73 * Displays the page
75 // pma_token/url_query needed for chart export
77 <script type="text/javascript">
78 pma_token = '<?php echo $_SESSION[' PMA_token ']; ?>';
79 url_query = '<?php echo $url_query;?>';
80 </script>
81 <!-- Display Chart options -->
82 <div id="div_view_options">
83 <form method="post" action="tbl_chart.php">
84 <?php echo PMA_generate_common_hidden_inputs($url_params); ?>
85 <fieldset>
86 <legend><?php echo __('Display chart'); ?></legend>
87 <div style="float:left;">
88 <input type="radio" name="chartType" value="bar" id="radio_bar" />
89 <label for ="radio_bar"><?php echo _pgettext('Chart type', 'Bar'); ?></label>
90 <input type="radio" name="chartType" value="column" id="radio_column" />
91 <label for ="radio_column"><?php echo _pgettext('Chart type', 'Column'); ?></label>
92 <input type="radio" name="chartType" value="line" id="radio_line" checked="checked" />
93 <label for ="radio_line"><?php echo _pgettext('Chart type', 'Line'); ?></label>
94 <input type="radio" name="chartType" value="spline" id="radio_spline" />
95 <label for ="radio_spline"><?php echo _pgettext('Chart type', 'Spline'); ?></label>
96 <input type="radio" name="chartType" value="pie" id="radio_pie" />
97 <label for ="radio_pie"><?php echo _pgettext('Chart type', 'Pie'); ?></label>
98 <span class="barStacked" style="display:none;">
99 <input type="checkbox" name="barStacked" value="1" id="checkbox_barStacked" />
100 <label for ="checkbox_barStacked"><?php echo __('Stacked'); ?></label>
101 </span>
102 <br>
103 <input type="text" name="chartTitle" value="<?php echo __('Chart title'); ?>">
104 <?php
105 $keys = array_keys($data[0]);
106 $yaxis = -1;
107 if (count($keys) > 1) { ?>
108 <br />
109 <label for="select_chartXAxis"><?php echo __('X-Axis:'); ?></label>
110 <select name="chartXAxis" id="select_chartXAxis">
111 <?php
113 foreach ($keys as $idx => $key) {
114 if ($yaxis == -1 && (($idx == count($data[0]) - 1) || preg_match("/(date|time)/i", $key))) {
115 echo '<option value="' . htmlspecialchars($idx) . '" selected>' . htmlspecialchars($key) . '</option>';
116 $yaxis=$idx;
117 } else {
118 echo '<option value="' . htmlspecialchars($idx) . '">' . htmlspecialchars($key) . '</option>';
123 </select><br />
124 <label for="select_chartSeries"><?php echo __('Series:'); ?></label>
125 <select name="chartSeries" id="select_chartSeries">
126 <option value="columns"><?php echo __('The remaining columns'); ?></option>
127 <?php
128 foreach ($keys as $idx => $key) {
129 echo '<option>' . htmlspecialchars($key) . '</option>';
132 </select>
133 <?php
137 </div>
138 <div style="float:left; padding-left:40px;">
139 <label for="xaxis_label"><?php echo __('X-Axis label:'); ?></label>
140 <input style="margin-top:0;" type="text" name="xaxis_label" id="xaxis_label"
141 value="<?php echo ($yaxis == -1) ? __('X Values') : htmlspecialchars($keys[$yaxis]); ?>" /><br />
142 <label for="yaxis_label"><?php echo __('Y-Axis label:'); ?></label>
143 <input type="text" name="yaxis_label" id="yaxis_label" value="<?php echo __('Y Values'); ?>" />
144 </div>
145 <p style="clear:both;">&nbsp;</p>
146 <div id="resizer" style="width:600px; height:400px;">
147 <div id="inner-resizer">
148 <div id="querychart" style="display:none;">
149 <?php
150 $sanitized_data = array();
151 foreach ($data as $data_row_number => $data_row) {
152 $tmp_row = array();
153 foreach ($data_row as $data_column => $data_value) {
154 $tmp_row[htmlspecialchars($data_column)] = htmlspecialchars($data_value);
156 $sanitized_data[] = $tmp_row;
158 echo json_encode($sanitized_data);
159 unset($sanitized_data);
161 </div>
162 </div>
163 </div>
164 </fieldset>
165 </form>
166 </div>
167 <?php
169 * Displays the footer
171 require_once './libraries/footer.inc.php';