Plot functionality using Hihcharts
[phpmyadmin/ammaryasirr.git] / tbl_zoom_select.php
blob26052018f6eb6afd3344eded674017a33388a6e4
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Handles table zoom search tab
6 * display table zoom search form, create SQL queries from form data
8 */
10 /**
11 * Gets some core libraries
13 require_once './libraries/common.inc.php';
14 require_once './libraries/mysql_charsets.lib.php';
15 require_once './libraries/tbl_select.lib.php';
17 $GLOBALS['js_include'][] = 'tbl_select.js';
18 $GLOBALS['js_include'][] = 'tbl_zoom_plot.js';
19 $GLOBALS['js_include'][] = 'highcharts/highcharts.js';
20 /* Files required for chart exporting */
21 $GLOBALS['js_include'][] = 'highcharts/exporting.js';
22 $GLOBALS['js_include'][] = 'canvg/canvg.js';
23 $GLOBALS['js_include'][] = 'canvg/rgbcolor.js';
24 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
25 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
27 $titles['Browse'] = PMA_tbl_setTitle($GLOBALS['cfg']['PropertiesIconic'], $pmaThemeImage);
30 /**
31 * Not selection yet required -> displays the selection form
33 if (true) {
34 // Gets some core libraries
35 require_once './libraries/tbl_common.php';
36 //$err_url = 'tbl_select.php' . $err_url;
37 $url_query .= '&amp;goto=tbl_select.php&amp;back=tbl_select.php';
39 /**
40 * Gets tables informations
42 require_once './libraries/tbl_info.inc.php';
44 /**
45 * Displays top menu links
47 require_once './libraries/tbl_links.inc.php';
49 if (! isset($goto)) {
50 $goto = $GLOBALS['cfg']['DefaultTabTable'];
52 // Defines the url to return to in case of error in the next sql statement
53 $err_url = $goto . '?' . PMA_generate_common_url($db, $table);
55 // Gets the list and number of fields
57 list($fields_list, $fields_type, $fields_collation, $fields_null) = PMA_tbl_getFields($table,$db);
58 $fields_cnt = count($fields_list);
60 // retrieve keys into foreign fields, if any
61 // check also foreigners even if relwork is FALSE (to get
62 // foreign keys from innodb)
63 $foreigners = PMA_getForeigners($db, $table);
64 $flag = 1;
65 $tbl_fields_type = $tbl_fields_collation = $tbl_fields_null = array();
68 <fieldset id="fieldset_subtab">
69 <?php
70 $url_params = array();
71 $url_params['db'] = $db;
72 $url_params['table'] = $table;
74 echo PMA_generate_html_tabs(PMA_tbl_getSubTabs(), $url_params);
77 <?php /* Form for Zoom Search input */
79 if(isset($inputs) && ($inputs[0] != __('pma_null') || $inputs[1] != __('pma_null')))
81 $flag = 2;
82 for($i = 0 ; $i < 2 ; $i++)
84 if($inputs[$i] != __('pma_null'))
86 $key = array_search($inputs[$i],$fields_list);
87 $tbl_fields_type[$i] = $fields_type[$key];
88 $tbl_fields_collation[$i] = $fields_collation[$key];
89 $tbl_fields_null[$i] = $fields_null[$key];
97 if(isset($zoom_submit)) {
99 $w = $data = array();
101 $sql_query = 'SELECT *';
103 // Add the colums to be selected
104 //$columns = $inputs;
105 //$columns = PMA_backquote($columns);
106 //$sql_query .= implode(', ', $columns);
109 //Add the table
111 $sql_query .= ' FROM ' . PMA_backquote($table);
112 for($i = 0 ; $i < 2 ; $i++){
114 $tmp = array();
115 // The where clause
116 $charsets = array();
117 $cnt_func = count($zoomFunc[$i]);
118 $func_type = $zoomFunc[$i];
119 list($charsets[$i]) = explode('_', $collations[$i]);
120 $unaryFlag = (isset($GLOBALS['cfg']['UnaryOperators'][$func_type]) && $GLOBALS['cfg']['UnaryOperators'][$func_type] == 1) ? true : false;
121 $whereClause = PMA_tbl_search_getWhereClause($fields[$i],$inputs[$i], $types[$i], $collations[$i], $func_type, $unaryFlag);
122 if($whereClause)
123 $w[] = $whereClause;
125 } // end for
126 //print_r($w);
127 if ($w) {
128 $sql_query .= ' WHERE ' . implode(' AND ', $w);
131 $settings = array('xLabel' => $inputs[0], 'yLabel' => $inputs[1], 'dataLabel' => $dataLabel);
132 $result = PMA_DBI_query( $sql_query . ";" , null, PMA_DBI_QUERY_STORE);
133 while ($row = PMA_DBI_fetch_assoc($result)) {
134 $data[] = $row;
136 $query_data = $data;
137 $scatter_plot = PMA_SVG_scatter_plot($data,$settings);
140 <?php
143 <form method="post" action="tbl_zoom_select.php" name="zoomInputForm" id="zoom_search_form" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?>>
144 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
145 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
146 <input type="hidden" name="back" value="tbl_select.php" />
147 <input type="hidden" name="flag" id="id_flag" value=<?php echo $flag; ?> />
150 <fieldset id="zoom_fieldset_table_qbe">
151 <?php if(isset($zoom_submit) && !empty($scatter_plot)){ ?>
152 <div id='resizer' style="width:600px; height:400px;float:right">
153 <legend><?php echo __('Display Plot'); ?></legend>
154 <div id="querydata" style="display:none;">
155 <?php if(isset($data)) echo json_encode($data); ?>
156 </div>
158 </div>
161 <?php } ?>
162 <legend><?php echo __('Do a "query by example" (wildcard: "%") for two columns') ?></legend>
163 <table class="data">
164 <?php echo PMA_tbl_setTableHeader();?>
165 <tbody>
166 <?php
167 $odd_row = true;
169 for($i = 0 ; $i < 2 ; $i++){
171 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
172 <th><select name="inputs[]" id=<?php echo 'tableid_' . $i?> >
173 <option value= <?php echo __('pma_null')?>><?php echo __('None'); ?> </option>
174 <?php
175 for ($j = 0 ; $j < $fields_cnt ; $j++){
176 if(isset($inputs[$i]) && $inputs[$i] == htmlspecialchars($fields_list[$j])){?>
177 <option value=<?php echo htmlspecialchars($fields_list[$j]);?> Selected> <?php echo htmlspecialchars($fields_list[$j]);?></option>
178 <?php
180 else{ ?>
181 <option value=<?php echo htmlspecialchars($fields_list[$j]);?> > <?php echo htmlspecialchars($fields_list[$j]);?></option>
182 <?php
184 } ?>
185 </select></th>
186 <td><?php if(isset($tbl_fields_type[$i]))echo $tbl_fields_type[$i]; ?></td>
187 <td><?php if(isset($tbl_fields_collation[$i]))echo $tbl_fields_collation[$i]; ?></td>
189 <td>
190 <?php if(isset($inputs) && $inputs[$i] != __('pma_null')){ ?>
191 <select name="zoomFunc[]">
192 <?php
194 if (strncasecmp($tbl_fields_type[$i], 'enum', 4) == 0) {
195 foreach ($GLOBALS['cfg']['EnumOperators'] as $fc) {
196 if(isset($zoomFunc[$i]) && $zoomFunc[$i] == htmlspecialchars($fc)){
197 echo "\n" . ' '
198 . '<option value="' . htmlspecialchars($fc) . '" Selected>'
199 . htmlspecialchars($fc) . '</option>';
201 else {
202 echo "\n" . ' '
203 . '<option value="' . htmlspecialchars($fc) . '">'
204 . htmlspecialchars($fc) . '</option>';
207 } elseif (preg_match('@char|blob|text|set@i', $tbl_fields_type[$i])) {
208 foreach ($GLOBALS['cfg']['TextOperators'] as $fc) {
209 if(isset($zoomFunc[$i]) && $zoomFunc[$i] == $fc){
210 echo "\n" . ' '
211 . '<option value="' . htmlspecialchars($fc) . '" Selected>'
212 . htmlspecialchars($fc) . '</option>';
214 else {
215 echo "\n" . ' '
216 . '<option value="' . htmlspecialchars($fc) . '">'
217 . htmlspecialchars($fc) . '</option>';
220 } else {
221 foreach ($GLOBALS['cfg']['NumOperators'] as $fc) {
222 if(isset($zoomFunc[$i]) && $zoomFunc[$i] == $fc){
223 echo "\n" . ' '
224 . '<option value="' . htmlspecialchars($fc) . '" Selected>'
225 . htmlspecialchars($fc) . '</option>';
227 else {
228 echo "\n" . ' '
229 . '<option value="' . htmlspecialchars($fc) . '">'
230 . htmlspecialchars($fc) . '</option>';
233 } // end if... else...
235 if ($tbl_fields_null[$i]) {
236 foreach ($GLOBALS['cfg']['NullOperators'] as $fc) {
237 if(isset($zoomFunc[$i]) && $zoomFunc[$i] == $fc){
238 echo "\n" . ' '
239 . '<option value="' . htmlspecialchars($fc) . '" Selected>'
240 . htmlspecialchars($fc) . '</option>';
242 else {
243 echo "\n" . ' '
244 . '<option value="' . htmlspecialchars($fc) . '">'
245 . htmlspecialchars($fc) . '</option>';
250 </select>
251 </td>
252 <td>
253 <?php
254 $field = $inputs[$i];
256 $foreignData = PMA_getForeignData($foreigners, $field, false, '', '');
257 if (isset($fields))
258 echo PMA_getForeignFields_Values($foreigners, $foreignData, $field, $tbl_fields_type, $i ,$db, $table, $titles, $GLOBALS['cfg']['ForeignKeyMaxLimit'], $fields);
259 else
260 echo PMA_getForeignFields_Values($foreigners, $foreignData, $field, $tbl_fields_type, $i ,$db, $table, $titles, $GLOBALS['cfg']['ForeignKeyMaxLimit'], '');
263 else{ ?>
265 </td><td></td>
267 <?php } ?>
269 </td>
270 </tr>
272 <input type="hidden" name="types[<?php echo $i; ?>]"
273 value="<?php if(isset($tbl_fields_type[$i]))echo $tbl_fields_type[$i]; ?>" />
274 <input type="hidden" name="collations[<?php echo $i; ?>]"
275 value="<?php if(isset($tbl_fields_collation[$i]))echo $tbl_fields_collation[$i]; ?>" />
279 <?php
282 </table>
284 <table>
285 <tr><td><label for="label"><?php echo __("Data Label"); ?></label>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</td>
286 <td><select name="dataLabel" id='dataLabel' >
287 <option value = ''> <?php echo __('None'); ?> </option>
288 <?php
289 for ($j = 0 ; $j < $fields_cnt ; $j++){
290 if(isset($dataLabel) && $dataLabel == htmlspecialchars($fields_list[$j])){?>
291 <option value=<?php echo htmlspecialchars($fields_list[$j]);?> Selected> <?php echo htmlspecialchars($fields_list[$j]);?></option>
292 <?php
294 else{ ?>
295 <option value=<?php echo htmlspecialchars($fields_list[$j]);?> > <?php echo htmlspecialchars($fields_list[$j]);?></option>
296 <?php
298 } ?>
299 </select>
300 </td></tr>
301 </table>
305 </fieldset>
306 <fieldset class="tblFooters">
307 <input type="hidden" name="max_number_of_fields"
308 value="<?php echo $fields_cnt; ?>" />
309 <input type="submit" name="zoom_submit" value="<?php echo __('Go'); ?>" />
310 </fieldset>
311 </form>
315 <div id="sqlqueryresults"></div>
316 <?php
317 require './libraries/footer.inc.php';
321 </fieldset>
323 <?php