forked from phpmyadmin/phpmyadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtbl_chart.php
207 lines (189 loc) · 7.96 KB
/
tbl_chart.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* handles creation of the chart
*
* @package PhpMyAdmin
*/
/**
*
*/
require_once 'libraries/common.inc.php';
/*
* Execute the query and return the result
*/
if(isset($_REQUEST['ajax_request']) && isset($_REQUEST['pos']) && isset($_REQUEST['session_max_rows'])) {
$response = PMA_Response::getInstance();
if (strlen($GLOBALS['table']) && strlen($GLOBALS['db'])) {
include './libraries/tbl_common.inc.php';
}
else {
$response->isSuccess(false);
$response->addJSON('message', __('Error'));
exit;
}
$sql_limit_to_append = ' LIMIT ' . $_REQUEST['pos'] . ', ' . $_REQUEST['session_max_rows'] . " ";
$sql_query .= $sql_limit_to_append;
$data = array();
$result = PMA_DBI_try_query($sql_query);
while ($row = PMA_DBI_fetch_assoc($result)) {
$data[] = $row;
}
if(empty($data)) {
$response->isSuccess(false);
$response->addJSON('message', __('No data to display'));
exit;
}
$sanitized_data = array();
foreach ($data as $data_row_number => $data_row) {
$tmp_row = array();
foreach ($data_row as $data_column => $data_value) {
$tmp_row[htmlspecialchars($data_column)] = htmlspecialchars($data_value);
}
$sanitized_data[] = $tmp_row;
}
$response->isSuccess(true);
$response->addJSON('message', null);
$response->addJSON('chartData', json_encode($sanitized_data));
unset($sanitized_data);
exit;
}
$response = PMA_Response::getInstance();
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('tbl_chart.js');
$scripts->addFile('jqplot/jquery.jqplot.js');
$scripts->addFile('jqplot/plugins/jqplot.barRenderer.js');
$scripts->addFile('jqplot/plugins/jqplot.canvasAxisLabelRenderer.js');
$scripts->addFile('jqplot/plugins/jqplot.canvasTextRenderer.js');
$scripts->addFile('jqplot/plugins/jqplot.categoryAxisRenderer.js');
$scripts->addFile('jqplot/plugins/jqplot.pointLabels.js');
$scripts->addFile('jqplot/plugins/jqplot.pieRenderer.js');
/* < IE 9 doesn't support canvas natively */
if (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 9) {
$scripts->addFile('canvg/flashcanvas.js');
}
/**
* Runs common work
*/
if (strlen($GLOBALS['table'])) {
$url_params['goto'] = $cfg['DefaultTabTable'];
$url_params['back'] = 'tbl_sql.php';
include 'libraries/tbl_common.inc.php';
include 'libraries/tbl_info.inc.php';
} elseif (strlen($GLOBALS['db'])) {
$url_params['goto'] = $cfg['DefaultTabDatabase'];
$url_params['back'] = 'sql.php';
include 'libraries/db_common.inc.php';
include 'libraries/db_info.inc.php';
} else {
$url_params['goto'] = $cfg['DefaultTabServer'];
$url_params['back'] = 'sql.php';
include 'libraries/server_common.inc.php';
}
$data = array();
$result = PMA_DBI_try_query($sql_query);
$fields_meta = PMA_DBI_get_fields_meta($result);
while ($row = PMA_DBI_fetch_assoc($result)) {
$data[] = $row;
}
// get settings if any posted
$chartSettings = array();
if (PMA_isValid($_REQUEST['chartSettings'], 'array')) {
$chartSettings = $_REQUEST['chartSettings'];
}
$url_params['db'] = $GLOBALS['db'];
$url_params['reload'] = 1;
/**
* Displays the page
*/
// pma_token/url_query needed for chart export
?>
<script type="text/javascript">
pma_token = '<?php echo $_SESSION[' PMA_token ']; ?>';
url_query = '<?php echo $url_query;?>';
</script>
<!-- Display Chart options -->
<div id="div_view_options">
<form method="post" id="tblchartform" action="tbl_chart.php" class="ajax">
<?php echo PMA_generate_common_hidden_inputs($url_params); ?>
<fieldset>
<legend><?php echo __('Display chart'); ?></legend>
<div style="float:left; width:370px;">
<input type="radio" name="chartType" value="bar" id="radio_bar" />
<label for ="radio_bar"><?php echo _pgettext('Chart type', 'Bar'); ?></label>
<input type="radio" name="chartType" value="column" id="radio_column" />
<label for ="radio_column"><?php echo _pgettext('Chart type', 'Column'); ?></label>
<input type="radio" name="chartType" value="line" id="radio_line" checked="checked" />
<label for ="radio_line"><?php echo _pgettext('Chart type', 'Line'); ?></label>
<input type="radio" name="chartType" value="spline" id="radio_spline" />
<label for ="radio_spline"><?php echo _pgettext('Chart type', 'Spline'); ?></label>
<span class="span_pie" style="display:none;">
<input type="radio" name="chartType" value="pie" id="radio_pie" />
<label for ="radio_pie"><?php echo _pgettext('Chart type', 'Pie'); ?></label>
</span>
<span class="barStacked" style="display:none;">
<input type="checkbox" name="barStacked" value="1" id="checkbox_barStacked" />
<label for ="checkbox_barStacked"><?php echo __('Stacked'); ?></label>
</span>
<br>
<input type="text" name="chartTitle" value="<?php echo __('Chart title'); ?>">
</div>
<?php
$keys = array_keys($data[0]);
$yaxis = -1;
if (count($keys) > 1) { ?>
<div style="float:left; padding-left:40px;">
<label for="select_chartXAxis"><?php echo __('X-Axis:'); ?></label>
<select name="chartXAxis" id="select_chartXAxis">
<?php
foreach ($keys as $idx => $key) {
if ($yaxis == -1 && (($idx == count($data[0]) - 1) || preg_match("/(date|time)/i", $key))) {
echo '<option value="' . htmlspecialchars($idx) . '" selected="selected">' . htmlspecialchars($key) . '</option>';
$yaxis = $idx;
} else {
echo '<option value="' . htmlspecialchars($idx) . '">' . htmlspecialchars($key) . '</option>';
}
}
?>
</select><br />
<label for="select_chartSeries"><?php echo __('Series:'); ?></label>
<select name="chartSeries" id="select_chartSeries" multiple="multiple">
<?php
$numeric_types = array('int', 'real', 'year', 'bit');
foreach ($keys as $idx => $key) {
if (in_array($fields_meta[$idx]->type, $numeric_types)) {
if ($idx == $yaxis) {
echo '<option value"' . htmlspecialchars($key) . '">' . htmlspecialchars($key) . '</option>';
} else {
echo '<option value"' . htmlspecialchars($key) . '" selected="selected">' . htmlspecialchars($key) . '</option>';
}
}
}
?>
</select>
</div>
<?php
}
?>
<div style="float:left; padding-left:40px;">
<label for="xaxis_label"><?php echo __('X-Axis label:'); ?></label>
<input style="margin-top:0;" type="text" name="xaxis_label" id="xaxis_label"
value="<?php echo ($yaxis == -1) ? __('X Values') : htmlspecialchars($keys[$yaxis]); ?>" /><br />
<label for="yaxis_label"><?php echo __('Y-Axis label:'); ?></label>
<input type="text" name="yaxis_label" id="yaxis_label" value="<?php echo __('Y Values'); ?>" /><br />
<label for="pos"><?php echo __('Start row') . ': ' . "\n"; ?></label>
<input type="text" name="pos" size="3" value="<?php echo $_SESSION['tmp_user_values']['pos']; ?>" /><br />
<label for="session_max_rows"><?php echo __('Number of rows') . ': ' . "\n"; ?></label>
<input type="text" name="session_max_rows" size="3" value="<?php echo (($_SESSION['tmp_user_values']['max_rows'] != 'all') ? $_SESSION['tmp_user_values']['max_rows'] : $GLOBALS['cfg']['MaxRows']); ?>" /><br />
<input type="submit" name="submit" class="Go" value="<?php echo __('Go'); ?>" />
<input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
</div>
<p style="clear:both;"> </p>
<div id="resizer" style="width:600px; height:400px;">
<div id="querychart">
</div>
</div>
</fieldset>
</form>
</div>