2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * handles creation of the chart
10 * do not import request variable into global scope
13 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
14 define('PMA_NO_VARIABLES_IMPORT', true);
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';
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';
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
58 $result = PMA_DBI_try_query($sql_query);
59 while ($row = PMA_DBI_fetch_assoc($result)) {
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;
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;?>';
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); ?
>
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
>
103 <input type
="text" name
="chartTitle" value
="<?php echo __('Chart title'); ?>">
105 $keys = array_keys($data[0]);
107 if (count($keys) > 1) { ?
>
109 <label
for="select_chartXAxis"><?php
echo __('X-Axis:'); ?
></label
>
110 <select name
="chartXAxis" id
="select_chartXAxis">
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>';
118 echo '<option value="' . htmlspecialchars($idx) . '">' . htmlspecialchars($key) . '</option>';
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
>
128 foreach ($keys as $idx => $key) {
129 echo '<option>' . htmlspecialchars($key) . '</option>';
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'); ?>" />
145 <p style
="clear:both;"> 
;</p
>
146 <div id
="resizer" style
="width:600px; height:400px;">
147 <div id
="inner-resizer">
148 <div id
="querychart" style
="display:none;">
150 $sanitized_data = array();
151 foreach ($data as $data_row_number => $data_row) {
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);
169 * Displays the footer
171 require_once './libraries/footer.inc.php';