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"><?php
echo _pgettext('Chart type', 'Bar'); ?
>
89 <input type
="radio" name
="chartType" value
="column"><?php
echo _pgettext('Chart type', 'Column'); ?
>
90 <input type
="radio" name
="chartType" value
="line" checked
><?php
echo _pgettext('Chart type', 'Line'); ?
>
91 <input type
="radio" name
="chartType" value
="spline"><?php
echo _pgettext('Chart type', 'Spline'); ?
>
92 <input type
="radio" name
="chartType" value
="pie"><?php
echo _pgettext('Chart type', 'Pie'); ?
>
93 <span
class="barStacked" style
="display:none;">
94 <input type
="checkbox" name
="barStacked" value
="1"><?php
echo __('Stacked'); ?
>
97 <input type
="text" name
="chartTitle" value
="<?php echo __('Chart title'); ?>">
99 $keys = array_keys($data[0]);
101 if (count($keys) > 1) {
103 echo __('X-Axis:'); ?
> <select name
="chartXAxis">
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>';
111 echo '<option value="' . htmlspecialchars($idx) . '">' . htmlspecialchars($key) . '</option>';
117 <?php
echo __('Series:'); ?
>
118 <select name
="chartSeries">
119 <option value
="columns"><?php
echo __('The remaining columns'); ?
></option
>
121 foreach ($keys as $idx => $key) {
122 echo '<option>' . htmlspecialchars($key) . '</option>';
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'); ?>">
136 <p style
="clear:both;"> 
;</p
>
137 <div id
="resizer" style
="width:600px; height:400px;">
138 <div id
="inner-resizer">
139 <div id
="querychart" style
="display:none;">
141 $sanitized_data = array();
142 foreach ($data as $data_row_number => $data_row) {
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);
160 * Displays the footer
162 require_once './libraries/footer.inc.php';