2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Handles table zoom search tab
6 * display table zoom search form, create SQL queries from form data
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';
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);
52 * Not selection yet required -> displays the selection form
55 // Gets some core libraries
56 require_once './libraries/tbl_common.php';
57 $url_query .= '&goto=tbl_select.php&back=tbl_select.php';
60 * Gets tables informations
62 require_once './libraries/tbl_info.inc.php';
65 * Displays top menu links
67 require_once './libraries/tbl_links.inc.php';
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);
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">
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');
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')) {
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
>
129 <?php
echo PMA_tbl_setTableHeader();?
>
134 for ($i = 0; $i < 4; $i++
) {
137 echo __("Additional search criteria");
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
>
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
>
151 <option value
="<?php echo htmlspecialchars($fields_list[$j]);?>">
152 <?php
echo htmlspecialchars($fields_list[$j]);?
></option
>
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
>
161 if (isset($inputs) && $inputs[$i] != 'pma_null') { ?
>
162 <select name
="zoomFunc[]">
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)) {
168 . '<option value="' . htmlspecialchars($fc) . '" selected="selected">'
169 . htmlspecialchars($fc) . '</option>';
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) {
180 . '<option value="' . htmlspecialchars($fc) . '" selected="selected">'
181 . htmlspecialchars($fc) . '</option>';
184 . '<option value="' . htmlspecialchars($fc) . '">'
185 . htmlspecialchars($fc) . '</option>';
189 foreach ($GLOBALS['cfg']['NumOperators'] as $fc) {
190 if (isset($zoomFunc[$i]) && $zoomFunc[$i] == $fc) {
192 . '<option value="' . htmlspecialchars($fc) . '" selected="selected">'
193 . htmlspecialchars($fc) . '</option>';
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) {
206 . '<option value="' . htmlspecialchars($fc) . '" selected="selected">'
207 . htmlspecialchars($fc) . '</option>';
210 . '<option value="' . htmlspecialchars($fc) . '">'
211 . htmlspecialchars($fc) . '</option>';
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
229 echo PMA_getForeignFields_Values(
230 $foreigners, $foreignData, $field, $tbl_fields_type, $i, $db,
231 $table, $titles, $GLOBALS['cfg']['ForeignKeyMaxLimit'], ''
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]; ?>" />
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);
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
>
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
>
280 <option value
="<?php echo htmlspecialchars($fields_list[$j]);?>" >
281 <?php
echo htmlspecialchars($fields_list[$j]);?
></option
>
288 <tr
><td
><label
for="maxRowPlotLimit"><?php
echo __("Maximum rows to plot"); ?
></label
></td
>
291 echo '<input type="text" name="maxPlotLimit" id="maxRowPlotLimit" value="';
292 if (! empty($maxPlotLimit)) {
293 echo htmlspecialchars($maxPlotLimit);
295 echo $GLOBALS['cfg']['maxRowPlotLimit'];
297 echo '" /></td></tr>';
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'); ?>" />
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 *';
325 $sql_query .= ' FROM ' . PMA_backquote($table);
326 for ($i = 0; $i < 4; $i++
) {
327 if ($inputs[$i] == 'pma_null') {
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)
340 $whereClause = PMA_tbl_search_getWhereClause(
341 $fields[$i], $inputs[$i], $types[$i],
342 $collations[$i], $func_type, $unaryFlag
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
361 foreach ($row as $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]) {
371 $inputs[0] => $row[$inputs[0]],
372 $inputs[1] => $row[$inputs[1]],
373 'where_clause' => $uniqueCondition[0]
375 } elseif ($dataLabel) {
377 $inputs[0] => $row[$inputs[0]],
378 $inputs[1] => $row[$inputs[1]],
379 $dataLabel => $row[$dataLabel],
380 'where_clause' => $uniqueCondition[0]
384 $inputs[0] => $row[$inputs[0]],
385 $inputs[1] => $row[$inputs[1]],
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
>
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">
412 echo json_encode($data);
415 <div id
="querychart" style
="float:right"></div
>
421 <fieldset id
='dataDisplay' style
="display:none">
426 <th
> <?php
echo __('Column'); ?
> </th
>
427 <th
> <?php
echo __('Null'); ?
> </th
>
428 <th
> <?php
echo __('Value'); ?
> </th
>
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 . '" />'
447 echo PMA_getForeignFields_Values(
448 $foreigners, $foreignData, $fieldpopup, $tbl_fields_type,
449 $i, $db, $table, $titles,
450 $GLOBALS['cfg']['ForeignKeyMaxLimit'], '', false, true
460 <fieldset
class="tblFooters">
461 <input type
="submit" id
="submitForm" name
="edit_point" value
="<?php echo __('Submit'); ?>" />
465 <input type
="hidden" id
="queryID" name
="sql_query" />
469 require './libraries/footer.inc.php';