Translation update done using Pootle.
[phpmyadmin.git] / tbl_chart.php
blob43de35144b959990b3f58ed2811bbb24d8c161d8
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 require './libraries/tbl_common.php';
39 require './libraries/tbl_info.inc.php';
40 require './libraries/tbl_links.inc.php';
41 } elseif (strlen($GLOBALS['db'])) {
42 $url_params['goto'] = $cfg['DefaultTabDatabase'];
43 $url_params['back'] = 'sql.php';
44 require './libraries/db_common.inc.php';
45 require './libraries/db_info.inc.php';
46 } else {
47 $url_params['goto'] = $cfg['DefaultTabServer'];
48 $url_params['back'] = 'sql.php';
49 require './libraries/server_common.inc.php';
50 require './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"><?php echo __('Bar'); ?>
89 <input type="radio" name="chartType" value="column"><?php echo __('Column'); ?>
90 <input type="radio" name="chartType" value="line" checked><?php echo __('Line'); ?>
91 <input type="radio" name="chartType" value="spline"><?php echo __('Spline'); ?>
92 <input type="radio" name="chartType" value="pie"><?php echo __('Pie'); ?>
93 <span class="barStacked" style="display:none;">
94 <input type="checkbox" name="barStacked" value="1"><?php echo __('Stacked'); ?>
95 </span>
96 <br>
97 <input type="text" name="chartTitle" value="<?php echo __('Chart title'); ?>">
98 <?php
99 $keys = array_keys($data[0]);
100 $yaxis = -1;
101 if (count($keys) > 1) {
102 echo '<br>';
103 echo __('X-Axis:'); ?> <select name="chartXAxis">
104 <?php
106 foreach ($keys as $idx => $key) {
107 if ($yaxis == -1 && (($idx == count($data[0]) - 1) || preg_match("/(date|time)/i", $key))) {
108 echo '<option value="' . htmlspecialchars($idx) . '" selected>' . htmlspecialchars($key) . '</option>';
109 $yaxis=$idx;
110 } else {
111 echo '<option value="' . htmlspecialchars($idx) . '">' . htmlspecialchars($key) . '</option>';
116 </select><br />
117 <?php echo __('Series:'); ?>
118 <select name="chartSeries">
119 <option value="columns"><?php echo __('The remaining columns'); ?></option>
120 <?php
121 foreach ($keys as $idx => $key) {
122 echo '<option>' . htmlspecialchars($key) . '</option>';
125 </select>
126 <?php
130 </div>
131 <div style="float:left; padding-left:40px;">
132 <?php echo __('X-Axis label:'); ?> <input style="margin-top:0;" type="text" name="xaxis_label"
133 value="<?php echo ($yaxis == -1) ? __('X Values') : htmlspecialchars($keys[$yaxis]); ?>"><br />
134 <?php echo __('Y-Axis label:'); ?> <input type="text" name="yaxis_label" value="<?php echo __('Y Values'); ?>">
135 </div>
136 <p style="clear:both;">&nbsp;</p>
137 <div id="resizer" style="width:600px; height:400px;">
138 <div id="inner-resizer">
139 <div id="querychart" style="display:none;">
140 <?php
141 $sanitized_data = array();
142 foreach ($data as $data_row_number => $data_row) {
143 $tmp_row = array();
144 foreach ($data_row as $data_column => $data_value) {
145 $tmp_row[htmlspecialchars($data_column)] = htmlspecialchars($data_value);
147 $sanitized_data[] = $tmp_row;
149 echo json_encode($sanitized_data);
150 unset($sanitized_data);
152 </div>
153 </div>
154 </div>
155 </fieldset>
156 </form>
157 </div>
158 <?php
160 * Displays the footer
162 require_once './libraries/footer.inc.php';