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) {
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);
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 .= '&goto=tbl_select.php&back=tbl_select.php';
61 * Gets tables informations
63 require_once './libraries/tbl_info.inc.php';
66 * Displays top menu links
68 require_once './libraries/tbl_links.inc.php';
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);
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">
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'))
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];
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
>
143 <?php
echo PMA_tbl_setTableHeader();?
>
148 for($i = 0 ; $i < 4 ; $i++
){
152 echo __("Additional search criteria");
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
>
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
>
167 <option value
=<?php
echo htmlspecialchars($fields_list[$j]);?
> > <?php
echo htmlspecialchars($fields_list[$j]);?
></option
>
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
>
176 <?php
if(isset($inputs) && $inputs[$i] != 'pma_null'){ ?
>
177 <select name
="zoomFunc[]">
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)){
184 . '<option value="' . htmlspecialchars($fc) . '" Selected>'
185 . htmlspecialchars($fc) . '</option>';
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){
197 . '<option value="' . htmlspecialchars($fc) . '" Selected>'
198 . htmlspecialchars($fc) . '</option>';
202 . '<option value="' . htmlspecialchars($fc) . '">'
203 . htmlspecialchars($fc) . '</option>';
207 foreach ($GLOBALS['cfg']['NumOperators'] as $fc) {
208 if(isset($zoomFunc[$i]) && $zoomFunc[$i] == $fc){
210 . '<option value="' . htmlspecialchars($fc) . '" Selected>'
211 . htmlspecialchars($fc) . '</option>';
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){
225 . '<option value="' . htmlspecialchars($fc) . '" Selected>'
226 . htmlspecialchars($fc) . '</option>';
230 . '<option value="' . htmlspecialchars($fc) . '">'
231 . htmlspecialchars($fc) . '</option>';
240 $field = $inputs[$i];
242 $foreignData = PMA_getForeignData($foreigners, $field, false, '', '');
244 echo PMA_getForeignFields_Values($foreigners, $foreignData, $field, $tbl_fields_type, $i ,$db, $table, $titles, $GLOBALS['cfg']['ForeignKeyMaxLimit'], $fields);
246 echo PMA_getForeignFields_Values($foreigners, $foreignData, $field, $tbl_fields_type, $i ,$db, $table, $titles, $GLOBALS['cfg']['ForeignKeyMaxLimit'], '');
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]; ?>" />
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);
282 <tr
><td
><label
for="label"><?php
echo __("Data Label"); ?
></label
> 
 
 
 
 
 
 
 
</td
>
283 <td
><select name
="dataLabel" id
='dataLabel' >
284 <option value
= ''> <?php
echo __('None'); ?
> </option
>
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
>
292 <option value
=<?php
echo htmlspecialchars($fields_list[$j]);?
> > <?php
echo htmlspecialchars($fields_list[$j]);?
></option
>
298 <tr
><td
><label
for="label"><?php
echo __("Maximum rows to plot"); ?
></label
></td
>
300 <?php
if(isset($maxPlotLimit)) { ?
>
301 <input type
="text" name
="maxPlotLimit" value
="<?php echo $maxPlotLimit; ?>" /></td
></tr
>
305 <input type
="text" name
="maxPlotLimit" value
="<?php echo $GLOBALS['cfg']['maxRowPlotLimit']; ?>" /></td
></tr
>
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'); ?>" />
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 *';
334 $sql_query .= ' FROM ' . PMA_backquote($table);
335 for($i = 0 ; $i < 4 ; $i++
){
336 if($inputs[$i] == 'pma_null')
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);
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
363 foreach($row as $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]);
373 $data[] = array($inputs[0] => $row[$inputs[0]], $inputs[1] => $row[$inputs[1]], $dataLabel => $row[$dataLabel], 'where_clause' => $uniqueCondition[0]);
375 $data[] = array($inputs[0] => $row[$inputs[0]], $inputs[1] => $row[$inputs[1]], $dataLabel => '', 'where_clause' => $uniqueCondition[0]);
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
>
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); ?
>
401 <div id
="querychart" style
="float:right"></div
>
406 <fieldset id
='dataDisplay' style
="display:none">
411 <th
> <?php
echo __('Column'); ?
> </th
>
412 <th
> <?php
echo __('Null'); ?
> </th
>
413 <th
> <?php
echo __('Value'); ?
> </th
>
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
>
434 <fieldset
class="tblFooters">
435 <input type
="submit" id
="submitForm" name
="edit_point" value
="<?php echo __('Submit'); ?>" />
440 <input type
="hidden" id
="queryID" name
="sql_query" />
448 require './libraries/footer.inc.php';