Translation update done using Pootle.
[phpmyadmin.git] / tbl_zoom_select.php
blob548b03f4f8f09f204afcd0d7cee75894182b876b
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) {
39 $extra_data = array();
40 $row_info_query = 'SELECT * FROM `' . $_REQUEST['db'] . '`.`'
41 . $_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 $url_query .= '&amp;goto=tbl_select.php&amp;back=tbl_select.php';
59 /**
60 * Gets tables informations
62 require_once './libraries/tbl_info.inc.php';
64 /**
65 * Displays top menu links
67 require_once './libraries/tbl_links.inc.php';
69 if (! isset($goto)) {
70 $goto = $GLOBALS['cfg']['DefaultTabTable'];
72 // Defines the url to return to in case of error in the next sql statement
73 $err_url = $goto . '?' . PMA_generate_common_url($db, $table);
75 // Gets the list and number of fields
77 list($fields_list, $fields_type, $fields_collation, $fields_null) = PMA_tbl_getFields($db, $table);
78 $fields_cnt = count($fields_list);
80 // retrieve keys into foreign fields, if any
81 // check also foreigners even if relwork is FALSE (to get
82 // foreign keys from innodb)
83 $foreigners = PMA_getForeigners($db, $table);
84 $flag = 1;
85 $tbl_fields_type = $tbl_fields_collation = $tbl_fields_null = array();
86 if (! isset($zoom_submit) && ! isset($inputs)) {
87 $dataLabel = PMA_getDisplayField($db, $table);
90 <div id="sqlqueryresults"></div>
91 <fieldset id="fieldset_subtab">
92 <?php
93 $url_params = array();
94 $url_params['db'] = $db;
95 $url_params['table'] = $table;
96 echo PMA_generate_html_tabs(PMA_tbl_getSubTabs(), $url_params, '', 'topmenu2');
98 /**
99 * Set the field name,type,collation and whether null on select of a coulmn
101 if (isset($inputs) && ($inputs[0] != 'pma_null' || $inputs[1] != 'pma_null')) {
102 $flag = 2;
103 for ($i = 0 ; $i < 4 ; $i++) {
104 if ($inputs[$i] != 'pma_null') {
105 $key = array_search($inputs[$i], $fields_list);
106 $tbl_fields_type[$i] = $fields_type[$key];
107 $tbl_fields_collation[$i] = $fields_collation[$key];
108 $tbl_fields_null[$i] = $fields_null[$key];
114 * Form for input criteria
118 <form method="post" action="tbl_zoom_select.php" name="insertForm" id="zoom_search_form"
119 <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?>>
120 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
121 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
122 <input type="hidden" name="back" value="tbl_zoom_select.php" />
123 <input type="hidden" name="flag" id="id_flag" value="<?php echo $flag; ?>" />
125 <fieldset id="inputSection">
127 <legend><?php echo __('Do a "query by example" (wildcard: "%") for two different columns') ?></legend>
128 <table class="data">
129 <?php echo PMA_tbl_setTableHeader();?>
130 <tbody>
131 <?php
132 $odd_row = true;
134 for ($i = 0; $i < 4; $i++) {
135 if ($i == 2) {
136 echo "<tr><td>";
137 echo __("Additional search criteria");
138 echo "</td></tr>";
141 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
142 <th><select name="inputs[]" id="<?php echo 'tableid_' . $i; ?>" >
143 <option value="<?php echo 'pma_null'; ?>"><?php echo __('None'); ?></option>
144 <?php
145 for ($j = 0 ; $j < $fields_cnt ; $j++) {
146 if (isset($inputs[$i]) && $inputs[$i] == htmlspecialchars($fields_list[$j])) {?>
147 <option value="<?php echo htmlspecialchars($fields_list[$j]);?>" selected="selected">
148 <?php echo htmlspecialchars($fields_list[$j]);?></option>
149 <?php
150 } else { ?>
151 <option value="<?php echo htmlspecialchars($fields_list[$j]);?>">
152 <?php echo htmlspecialchars($fields_list[$j]);?></option>
153 <?php
155 } ?>
156 </select></th>
157 <td><?php if (isset($tbl_fields_type[$i])) echo $tbl_fields_type[$i]; ?></td>
158 <td><?php if (isset($tbl_fields_collation[$i])) echo $tbl_fields_collation[$i]; ?></td>
159 <td>
160 <?php
161 if (isset($inputs) && $inputs[$i] != 'pma_null') { ?>
162 <select name="zoomFunc[]">
163 <?php
164 if (strncasecmp($tbl_fields_type[$i], 'enum', 4) == 0) {
165 foreach ($GLOBALS['cfg']['EnumOperators'] as $fc) {
166 if (isset($zoomFunc[$i]) && $zoomFunc[$i] == htmlspecialchars($fc)) {
167 echo "\n" . ' '
168 . '<option value="' . htmlspecialchars($fc) . '" selected="selected">'
169 . htmlspecialchars($fc) . '</option>';
170 } else {
171 echo "\n" . ' '
172 . '<option value="' . htmlspecialchars($fc) . '">'
173 . htmlspecialchars($fc) . '</option>';
176 } elseif (preg_match('@char|blob|text|set@i', $tbl_fields_type[$i])) {
177 foreach ($GLOBALS['cfg']['TextOperators'] as $fc) {
178 if (isset($zoomFunc[$i]) && $zoomFunc[$i] == $fc) {
179 echo "\n" . ' '
180 . '<option value="' . htmlspecialchars($fc) . '" selected="selected">'
181 . htmlspecialchars($fc) . '</option>';
182 } else {
183 echo "\n" . ' '
184 . '<option value="' . htmlspecialchars($fc) . '">'
185 . htmlspecialchars($fc) . '</option>';
188 } else {
189 foreach ($GLOBALS['cfg']['NumOperators'] as $fc) {
190 if (isset($zoomFunc[$i]) && $zoomFunc[$i] == $fc) {
191 echo "\n" . ' '
192 . '<option value="' . htmlspecialchars($fc) . '" selected="selected">'
193 . htmlspecialchars($fc) . '</option>';
194 } else {
195 echo "\n" . ' '
196 . '<option value="' . htmlspecialchars($fc) . '">'
197 . htmlspecialchars($fc) . '</option>';
200 } // end if... else...
202 if ($tbl_fields_null[$i]) {
203 foreach ($GLOBALS['cfg']['NullOperators'] as $fc) {
204 if (isset($zoomFunc[$i]) && $zoomFunc[$i] == $fc) {
205 echo "\n" . ' '
206 . '<option value="' . htmlspecialchars($fc) . '" selected="selected">'
207 . htmlspecialchars($fc) . '</option>';
208 } else {
209 echo "\n" . ' '
210 . '<option value="' . htmlspecialchars($fc) . '">'
211 . htmlspecialchars($fc) . '</option>';
216 </select>
217 </td>
218 <td>
219 <?php
220 $field = $inputs[$i];
222 $foreignData = PMA_getForeignData($foreigners, $field, false, '', '');
223 if (isset($fields)) {
224 echo PMA_getForeignFields_Values(
225 $foreigners, $foreignData, $field, $tbl_fields_type, $i, $db,
226 $table, $titles, $GLOBALS['cfg']['ForeignKeyMaxLimit'], $fields
228 } else {
229 echo PMA_getForeignFields_Values(
230 $foreigners, $foreignData, $field, $tbl_fields_type, $i, $db,
231 $table, $titles, $GLOBALS['cfg']['ForeignKeyMaxLimit'], ''
234 } else { ?>
236 </td><td></td>
238 <?php
239 } ?>
241 </tr>
242 <tr><td>
243 <input type="hidden" name="types[<?php echo $i; ?>]" id="types_<?php echo $i; ?>"
244 value="<?php if(isset($tbl_fields_type[$i]))echo $tbl_fields_type[$i]; ?>" />
245 <input type="hidden" name="collations[<?php echo $i; ?>]"
246 value="<?php if(isset($tbl_fields_collation[$i]))echo $tbl_fields_collation[$i]; ?>" />
247 </td></tr>
249 <?php
250 }//end for
252 </tbody>
253 </table>
255 <?php
257 * Other inputs like data label and mode go after selection of column criteria
260 //Set default datalabel if not selected
261 if (isset($zoom_submit) && $inputs[0] != 'pma_null' && $inputs[1] != 'pma_null') {
262 if ($dataLabel == '') {
263 $dataLabel = PMA_getDisplayField($db, $table);
267 <table class="data">
268 <tr><td><label for="dataLabel"><?php echo __("Data Label"); ?></label></td>
269 <td><select name="dataLabel" id='dataLabel' >
270 <option value = ''> <?php echo __('None'); ?> </option>
271 <?php
272 for ($j = 0; $j < $fields_cnt; $j++) {
273 if (isset($dataLabel) && $dataLabel == htmlspecialchars($fields_list[$j])) {
275 <option value="<?php echo htmlspecialchars($fields_list[$j]);?>" selected="selected">
276 <?php echo htmlspecialchars($fields_list[$j]);?></option>
277 <?php
278 } else {
280 <option value="<?php echo htmlspecialchars($fields_list[$j]);?>" >
281 <?php echo htmlspecialchars($fields_list[$j]);?></option>
282 <?php
286 </select>
287 </td></tr>
288 <tr><td><label for="maxRowPlotLimit"><?php echo __("Maximum rows to plot"); ?></label></td>
289 <td>
290 <?php
291 echo '<input type="text" name="maxPlotLimit" id="maxRowPlotLimit" value="';
292 if (! empty($maxPlotLimit)) {
293 echo htmlspecialchars($maxPlotLimit);
294 } else {
295 echo $GLOBALS['cfg']['maxRowPlotLimit'];
297 echo '" /></td></tr>';
299 </table>
301 </fieldset>
302 <fieldset class="tblFooters">
303 <input type="hidden" name="max_number_of_fields"
304 value="<?php echo $fields_cnt; ?>" />
305 <input type="submit" name="zoom_submit" id="inputFormSubmitId" value="<?php echo __('Go'); ?>" />
306 </fieldset>
307 </form>
308 </fieldset>
310 <?php
313 * Handle the input criteria and generate the query result
314 * Form for displaying query results
316 if (isset($zoom_submit) && $inputs[0] != 'pma_null' && $inputs[1] != 'pma_null' && $inputs[0] != $inputs[1]) {
319 * Query generation part
321 $w = $data = array();
322 $sql_query = 'SELECT *';
324 //Add the table
325 $sql_query .= ' FROM ' . PMA_backquote($table);
326 for ($i = 0; $i < 4; $i++) {
327 if ($inputs[$i] == 'pma_null') {
328 continue;
330 $tmp = array();
331 // The where clause
332 $charsets = array();
333 $cnt_func = count($zoomFunc[$i]);
334 $func_type = $zoomFunc[$i];
335 list($charsets[$i]) = explode('_', $collations[$i]);
336 $unaryFlag = (isset($GLOBALS['cfg']['UnaryOperators'][$func_type])
337 && $GLOBALS['cfg']['UnaryOperators'][$func_type] == 1)
338 ? true
339 : false;
340 $whereClause = PMA_tbl_search_getWhereClause(
341 $fields[$i], $inputs[$i], $types[$i],
342 $collations[$i], $func_type, $unaryFlag
344 if ($whereClause) {
345 $w[] = $whereClause;
347 } // end for
348 if ($w) {
349 $sql_query .= ' WHERE ' . implode(' AND ', $w);
351 $sql_query .= ' LIMIT ' . $maxPlotLimit;
354 * Query execution part
356 $result = PMA_DBI_query($sql_query . ";", null, PMA_DBI_QUERY_STORE);
357 $fields_meta = PMA_DBI_get_fields_meta($result);
358 while ($row = PMA_DBI_fetch_assoc($result)) {
359 //Need a row with indexes as 0,1,2 for the PMA_getUniqueCondition hence using a temporary array
360 $tmpRow = array();
361 foreach ($row as $val) {
362 $tmpRow[] = $val;
364 //Get unique conditon on each row (will be needed for row update)
365 $uniqueCondition = PMA_getUniqueCondition($result, $fields_cnt, $fields_meta, $tmpRow, true);
367 //Append it to row array as where_clause
368 $row['where_clause'] = $uniqueCondition[0];
369 if ($dataLabel == $inputs[0] || $dataLabel == $inputs[1]) {
370 $data[] = array(
371 $inputs[0] => $row[$inputs[0]],
372 $inputs[1] => $row[$inputs[1]],
373 'where_clause' => $uniqueCondition[0]
375 } elseif ($dataLabel) {
376 $data[] = array(
377 $inputs[0] => $row[$inputs[0]],
378 $inputs[1] => $row[$inputs[1]],
379 $dataLabel => $row[$dataLabel],
380 'where_clause' => $uniqueCondition[0]
382 } else {
383 $data[] = array(
384 $inputs[0] => $row[$inputs[0]],
385 $inputs[1] => $row[$inputs[1]],
386 $dataLabel => '',
387 'where_clause' => $uniqueCondition[0]
392 * Form for displaying point data and also the scatter plot
395 <form method="post" action="tbl_zoom_select.php" name="displayResultForm" id="zoom_display_form"
396 <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?>>
397 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
398 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
399 <input type="hidden" name="back" value="tbl_zoom_select.php" />
401 <fieldset id="displaySection">
402 <legend><?php echo __('Browse/Edit the points') ?></legend>
403 <center>
404 <?php
405 //JSON encode the data(query result)
406 if (isset($zoom_submit) && ! empty($data)) {
408 <div id='resizer' style="width:600px;height:400px">
409 <center><a href="#" onClick="displayHelp();"><?php echo __('How to use'); ?></a></center>
410 <div id="querydata" style="display:none">
411 <?php
412 echo json_encode($data);
414 </div>
415 <div id="querychart" style="float:right"></div>
416 </div>
417 <?php
420 </center>
421 <fieldset id='dataDisplay' style="display:none">
422 <fieldset>
423 <table class="data">
424 <thead>
425 <tr>
426 <th> <?php echo __('Column'); ?> </th>
427 <th> <?php echo __('Null'); ?> </th>
428 <th> <?php echo __('Value'); ?> </th>
429 </tr>
430 </thead>
431 <tbody>
432 <?php
433 $odd_row = true;
434 for ($i = 4; $i < $fields_cnt + 4; $i++) {
435 $tbl_fields_type[$i] = $fields_type[$i - 4];
436 $fieldpopup = $fields_list[$i - 4];
437 $foreignData = PMA_getForeignData($foreigners, $fieldpopup, false, '', '');
439 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
440 <th><?php echo htmlspecialchars($fields_list[$i - 4]); ?></th>
441 <th><?php echo ($fields_null[$i - 4] == 'YES')
442 ? '<input type="checkbox" class="checkbox_null" name="fields_null[ '
443 . $i . ' ]" id="fields_null_id_' . $i . '" />'
444 : ''; ?>
445 </th>
446 <th> <?php
447 echo PMA_getForeignFields_Values(
448 $foreigners, $foreignData, $fieldpopup, $tbl_fields_type,
449 $i, $db, $table, $titles,
450 $GLOBALS['cfg']['ForeignKeyMaxLimit'], '', false, true
451 ); ?>
452 </th>
453 </tr>
454 <?php
457 </tbody>
458 </table>
459 </fieldset>
460 <fieldset class="tblFooters">
461 <input type="submit" id="submitForm" name="edit_point" value="<?php echo __('Submit'); ?>" />
462 </fieldset>
463 </fieldset>
464 </fieldset>
465 <input type="hidden" id="queryID" name="sql_query" />
466 </form>
467 <?php
469 require './libraries/footer.inc.php';