Fixed: Not selecting a datalabel used to issue a notice(undefined offset)
[phpmyadmin/ammaryasirr.git] / tbl_zoom_select.php
blob2352fc1fb75c5e71b3c837187ea04e9f7824c06b
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';
16 require_once './libraries/relation.lib.php';
17 require_once './libraries/tbl_info.inc.php';
19 $GLOBALS['js_include'][] = 'makegrid.js';
20 $GLOBALS['js_include'][] = 'sql.js';
21 $GLOBALS['js_include'][] = 'functions.js';
22 $GLOBALS['js_include'][] = 'tbl_zoom_plot.js';
23 $GLOBALS['js_include'][] = 'date.js';
24 $GLOBALS['js_include'][] = 'jquery/jquery.mousewheel.js';
25 $GLOBALS['js_include'][] = 'highcharts/highcharts.js';
26 /* Files required for chart exporting */
27 $GLOBALS['js_include'][] = 'highcharts/exporting.js';
28 $GLOBALS['js_include'][] = 'canvg/canvg.js';
29 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
30 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
33 /**
34 * Handle AJAX request for data row on point select
35 * @var post_params Object containing parameters for the POST request
38 if (isset($_REQUEST['get_data_row']) && $_REQUEST['get_data_row'] == true) {
40 $extra_data = array();
41 $row_info_query = 'SELECT * FROM `' . $_REQUEST['db'] . '`.`' . $_REQUEST['table'] . '` WHERE ' . $_REQUEST['where_clause'];
42 $result = PMA_DBI_query( $row_info_query . ";" , null, PMA_DBI_QUERY_STORE);
43 $fields_meta = PMA_DBI_get_fields_meta($result);
44 while ($row = PMA_DBI_fetch_assoc($result))
45 $extra_data['row_info'] = $row;
47 PMA_ajaxResponse(NULL, true, $extra_data);
50 $titles['Browse'] = PMA_tbl_setTitle($GLOBALS['cfg']['PropertiesIconic'], $pmaThemeImage);
51 /**
52 * Not selection yet required -> displays the selection form
55 // Gets some core libraries
56 require_once './libraries/tbl_common.php';
57 //$err_url = 'tbl_select.php' . $err_url;
58 $url_query .= '&amp;goto=tbl_select.php&amp;back=tbl_select.php';
60 /**
61 * Gets tables informations
63 require_once './libraries/tbl_info.inc.php';
65 /**
66 * Displays top menu links
68 require_once './libraries/tbl_links.inc.php';
70 if (! isset($goto)) {
71 $goto = $GLOBALS['cfg']['DefaultTabTable'];
73 // Defines the url to return to in case of error in the next sql statement
74 $err_url = $goto . '?' . PMA_generate_common_url($db, $table);
76 // Gets the list and number of fields
78 list($fields_list, $fields_type, $fields_collation, $fields_null) = PMA_tbl_getFields($table,$db);
79 $fields_cnt = count($fields_list);
81 // retrieve keys into foreign fields, if any
82 // check also foreigners even if relwork is FALSE (to get
83 // foreign keys from innodb)
84 $foreigners = PMA_getForeigners($db, $table);
85 $flag = 1;
86 $tbl_fields_type = $tbl_fields_collation = $tbl_fields_null = array();
87 if(!isset($zoom_submit) && !isset($inputs))
88 $dataLabel = PMA_getDisplayField($db,$table);
93 <div id="sqlqueryresults"></div>
94 <fieldset id="fieldset_subtab">
95 <?php
96 $url_params = array();
97 $url_params['db'] = $db;
98 $url_params['table'] = $table;
99 echo PMA_generate_html_tabs(PMA_tbl_getSubTabs(), $url_params);
102 * Set the field name,type,collation and whether null on select of a coulmn
104 if(isset($inputs) && ($inputs[0] != 'pma_null' || $inputs[1] != 'pma_null'))
106 $flag = 2;
107 for($i = 0 ; $i < 4 ; $i++)
109 if($inputs[$i] != 'pma_null')
111 $key = array_search($inputs[$i],$fields_list);
112 $tbl_fields_type[$i] = $fields_type[$key];
113 $tbl_fields_collation[$i] = $fields_collation[$key];
114 $tbl_fields_null[$i] = $fields_null[$key];
123 <?php
126 * Form for input criteria
130 <form method="post" action="tbl_zoom_select.php" name="insertForm" id="zoom_search_form" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?>>
131 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
132 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
133 <input type="hidden" name="back" value="tbl_zoom_select.php" />
134 <input type="hidden" name="flag" id="id_flag" value=<?php echo $flag; ?> />
139 <fieldset id="inputSection">
141 <legend><?php echo __('Do a "query by example" (wildcard: "%") for two different columns') ?></legend>
142 <table class="data">
143 <?php echo PMA_tbl_setTableHeader();?>
144 <tbody>
145 <?php
146 $odd_row = true;
148 for($i = 0 ; $i < 4 ; $i++){
150 if($i == 2){
151 echo "<tr><td>";
152 echo __("Additional search criteria");
153 echo "</td><tr>";
157 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
158 <th><select name="inputs[]" id=<?php echo 'tableid_' . $i?> >
159 <option value= <?php echo 'pma_null'?>><?php echo __('None'); ?> </option>
160 <?php
161 for ($j = 0 ; $j < $fields_cnt ; $j++){
162 if(isset($inputs[$i]) && $inputs[$i] == htmlspecialchars($fields_list[$j])){?>
163 <option value=<?php echo htmlspecialchars($fields_list[$j]);?> Selected> <?php echo htmlspecialchars($fields_list[$j]);?></option>
164 <?php
166 else{ ?>
167 <option value=<?php echo htmlspecialchars($fields_list[$j]);?> > <?php echo htmlspecialchars($fields_list[$j]);?></option>
168 <?php
170 } ?>
171 </select></th>
172 <td><?php if(isset($tbl_fields_type[$i]))echo $tbl_fields_type[$i]; ?></td>
173 <td><?php if(isset($tbl_fields_collation[$i]))echo $tbl_fields_collation[$i]; ?></td>
175 <td>
176 <?php if(isset($inputs) && $inputs[$i] != 'pma_null'){ ?>
177 <select name="zoomFunc[]">
178 <?php
180 if (strncasecmp($tbl_fields_type[$i], 'enum', 4) == 0) {
181 foreach ($GLOBALS['cfg']['EnumOperators'] as $fc) {
182 if(isset($zoomFunc[$i]) && $zoomFunc[$i] == htmlspecialchars($fc)){
183 echo "\n" . ' '
184 . '<option value="' . htmlspecialchars($fc) . '" Selected>'
185 . htmlspecialchars($fc) . '</option>';
187 else {
188 echo "\n" . ' '
189 . '<option value="' . htmlspecialchars($fc) . '">'
190 . htmlspecialchars($fc) . '</option>';
193 } elseif (preg_match('@char|blob|text|set@i', $tbl_fields_type[$i])) {
194 foreach ($GLOBALS['cfg']['TextOperators'] as $fc) {
195 if(isset($zoomFunc[$i]) && $zoomFunc[$i] == $fc){
196 echo "\n" . ' '
197 . '<option value="' . htmlspecialchars($fc) . '" Selected>'
198 . htmlspecialchars($fc) . '</option>';
200 else {
201 echo "\n" . ' '
202 . '<option value="' . htmlspecialchars($fc) . '">'
203 . htmlspecialchars($fc) . '</option>';
206 } else {
207 foreach ($GLOBALS['cfg']['NumOperators'] as $fc) {
208 if(isset($zoomFunc[$i]) && $zoomFunc[$i] == $fc){
209 echo "\n" . ' '
210 . '<option value="' . htmlspecialchars($fc) . '" Selected>'
211 . htmlspecialchars($fc) . '</option>';
213 else {
214 echo "\n" . ' '
215 . '<option value="' . htmlspecialchars($fc) . '">'
216 . htmlspecialchars($fc) . '</option>';
219 } // end if... else...
221 if ($tbl_fields_null[$i]) {
222 foreach ($GLOBALS['cfg']['NullOperators'] as $fc) {
223 if(isset($zoomFunc[$i]) && $zoomFunc[$i] == $fc){
224 echo "\n" . ' '
225 . '<option value="' . htmlspecialchars($fc) . '" Selected>'
226 . htmlspecialchars($fc) . '</option>';
228 else {
229 echo "\n" . ' '
230 . '<option value="' . htmlspecialchars($fc) . '">'
231 . htmlspecialchars($fc) . '</option>';
236 </select>
237 </td>
238 <td>
239 <?php
240 $field = $inputs[$i];
242 $foreignData = PMA_getForeignData($foreigners, $field, false, '', '');
243 if (isset($fields))
244 echo PMA_getForeignFields_Values($foreigners, $foreignData, $field, $tbl_fields_type, $i ,$db, $table, $titles, $GLOBALS['cfg']['ForeignKeyMaxLimit'], $fields);
245 else
246 echo PMA_getForeignFields_Values($foreigners, $foreignData, $field, $tbl_fields_type, $i ,$db, $table, $titles, $GLOBALS['cfg']['ForeignKeyMaxLimit'], '');
249 else{ ?>
251 </td><td></td>
253 <?php } ?>
255 </td>
256 </tr>
258 <input type="hidden" name="types[<?php echo $i; ?>]" id="types_<?php echo $i; ?>"
259 value="<?php if(isset($tbl_fields_type[$i]))echo $tbl_fields_type[$i]; ?>" />
260 <input type="hidden" name="collations[<?php echo $i; ?>]"
261 value="<?php if(isset($tbl_fields_collation[$i]))echo $tbl_fields_collation[$i]; ?>" />
265 <?php
266 }//end for
268 </table>
270 <?php
272 * Other inputs like data label and mode go after selection of column criteria
275 //Set default datalabel if not selected
276 if(isset($zoom_submit) && $inputs[0] != 'pma_null' && $inputs[1] != 'pma_null') {
277 if ($dataLabel == '')
278 $dataLabel = PMA_getDisplayField($db,$table);
281 <table class="data">
282 <tr><td><label for="label"><?php echo __("Data Label"); ?></label>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</td>
283 <td><select name="dataLabel" id='dataLabel' >
284 <option value = ''> <?php echo __('None'); ?> </option>
285 <?php
286 for ($j = 0 ; $j < $fields_cnt ; $j++){
287 if(isset($dataLabel) && $dataLabel == htmlspecialchars($fields_list[$j])){?>
288 <option value=<?php echo htmlspecialchars($fields_list[$j]);?> Selected> <?php echo htmlspecialchars($fields_list[$j]);?></option>
289 <?php
291 else{ ?>
292 <option value=<?php echo htmlspecialchars($fields_list[$j]);?> > <?php echo htmlspecialchars($fields_list[$j]);?></option>
293 <?php
295 } ?>
296 </select>
297 </td></tr>
298 <tr><td><label for="label"><?php echo __("Maximum rows to plot"); ?></label></td>
299 <td>
300 <?php if(isset($maxPlotLimit)) { ?>
301 <input type="text" name="maxPlotLimit" value="<?php echo $maxPlotLimit; ?>" /></td></tr>
302 <?php
304 else { ?>
305 <input type="text" name="maxPlotLimit" value="<?php echo $GLOBALS['cfg']['maxRowPlotLimit']; ?>" /></td></tr>
306 <?php
307 } ?>
308 </table>
310 </fieldset>
311 <fieldset class="tblFooters">
312 <input type="hidden" name="max_number_of_fields"
313 value="<?php echo $fields_cnt; ?>" />
314 <input type="submit" name="zoom_submit" id="inputFormSubmitId" value="<?php echo __('Go'); ?>" />
315 </fieldset>
316 </form>
318 <?php
321 * Handle the input criteria and gerate the query result
322 * Form for displaying query results
324 if(isset($zoom_submit) && $inputs[0] != 'pma_null' && $inputs[1] != 'pma_null' && $inputs[0] != $inputs[1]) {
327 * Query generation part
329 $w = $data = array();
330 $sql_query = 'SELECT *';
332 //Add the table
334 $sql_query .= ' FROM ' . PMA_backquote($table);
335 for($i = 0 ; $i < 4 ; $i++){
336 if($inputs[$i] == 'pma_null')
337 continue;
338 $tmp = array();
339 // The where clause
340 $charsets = array();
341 $cnt_func = count($zoomFunc[$i]);
342 $func_type = $zoomFunc[$i];
343 list($charsets[$i]) = explode('_', $collations[$i]);
344 $unaryFlag = (isset($GLOBALS['cfg']['UnaryOperators'][$func_type]) && $GLOBALS['cfg']['UnaryOperators'][$func_type] == 1) ? true : false;
345 $whereClause = PMA_tbl_search_getWhereClause($fields[$i],$inputs[$i], $types[$i], $collations[$i], $func_type, $unaryFlag);
346 if($whereClause)
347 $w[] = $whereClause;
349 } // end for
350 if ($w) {
351 $sql_query .= ' WHERE ' . implode(' AND ', $w);
353 $sql_query .= ' LIMIT ' . $maxPlotLimit;
356 * Query execution part
358 $result = PMA_DBI_query( $sql_query . ";" , null, PMA_DBI_QUERY_STORE);
359 $fields_meta = PMA_DBI_get_fields_meta($result);
360 while ($row = PMA_DBI_fetch_assoc($result)) {
361 //Need a row with indexes as 0,1,2 for the PMA_getUniqueCondition hence using a temporary array
362 $tmpRow = array();
363 foreach($row as $val)
364 $tmpRow[] = $val;
365 //Get unique conditon on each row (will be needed for row update)
366 $uniqueCondition = PMA_getUniqueCondition($result, $fields_cnt, $fields_meta, $tmpRow, true);
368 //Append it to row array as where_clause
369 $row['where_clause'] = $uniqueCondition[0];
370 if($dataLabel == $inputs[0] || $dataLabel == $inputs[1])
371 $data[] = array($inputs[0] => $row[$inputs[0]], $inputs[1] => $row[$inputs[1]], 'where_clause' => $uniqueCondition[0]);
372 else if($dataLabel)
373 $data[] = array($inputs[0] => $row[$inputs[0]], $inputs[1] => $row[$inputs[1]], $dataLabel => $row[$dataLabel], 'where_clause' => $uniqueCondition[0]);
374 else
375 $data[] = array($inputs[0] => $row[$inputs[0]], $inputs[1] => $row[$inputs[1]], $dataLabel => '', 'where_clause' => $uniqueCondition[0]);
380 <?php
382 * Form for displaying point data and also the scatter plot
385 <form method="post" action="tbl_zoom_select.php" name="displayResultForm" id="zoom_display_form" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?>>
386 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
387 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
388 <input type="hidden" name="back" value="tbl_zoom_select.php" />
390 <fieldset id="displaySection">
391 <legend><?php echo __('Browse/Edit the points') ?></legend>
392 <center>
393 <?php
394 //JSON encode the data(query result)
395 if(isset($zoom_submit) && !empty($data)){ ?>
396 <div id='resizer' style="width:600px;height:400px">
397 <?php if (isset($data)) ?><center> <a href="#" onClick="displayHelp();"><?php echo __('How to use'); ?></a> </center>
398 <div id="querydata" style="display:none">
399 <?php if(isset($data)) echo json_encode($data); ?>
400 </div>
401 <div id="querychart" style="float:right"></div>
402 </div>
403 <?php
404 } ?>
405 </center>
406 <fieldset id='dataDisplay' style="display:none">
407 <fieldset>
408 <table class="data">
409 <thead>
410 <tr>
411 <th> <?php echo __('Column'); ?> </th>
412 <th> <?php echo __('Null'); ?> </th>
413 <th> <?php echo __('Value'); ?> </th>
414 </tr>
415 </thead>
416 <tbody>
417 <?php
418 $odd_row = true;
419 for ($i = 4; $i < $fields_cnt + 4 ; $i++) {
420 $tbl_fields_type[$i] = $fields_type[$i - 4];
421 $fieldpopup = $fields_list[$i - 4];
422 $foreignData = PMA_getForeignData($foreigners, $fieldpopup, false, '', '');
424 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
425 <th><?php echo htmlspecialchars($fields_list[$i - 4]); ?></th>
426 <th><?php echo '<input type="checkbox" class="checkbox_null" name="fields_null[ ' . $i . ' ]" id="fields_null_id_' . $i . '" />'; ?></th>
427 <th><?php echo PMA_getForeignFields_Values($foreigners, $foreignData, $fieldpopup, $tbl_fields_type, $i, $db, $table, $titles,$GLOBALS['cfg']['ForeignKeyMaxLimit'], '' ); ?> </th>
428 </tr>
429 <?php
430 } ?>
431 </tbody>
432 </table>
433 </fieldset>
434 <fieldset class="tblFooters">
435 <input type="submit" id="submitForm" name="edit_point" value="<?php echo __('Submit'); ?>" />
436 </fieldset>
437 </fieldset>
439 </fieldset>
440 <input type="hidden" id="queryID" name="sql_query" />
441 </form>
442 </fieldset>
443 <?php
447 <?php
448 require './libraries/footer.inc.php';