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'][] = 'highcharts/highcharts.js';
24 /* Files required for chart exporting */
25 $GLOBALS['js_include'][] = 'highcharts/exporting.js';
26 $GLOBALS['js_include'][] = 'canvg/canvg.js';
27 $GLOBALS['js_include'][] = 'canvg/rgbcolor.js';
28 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
29 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
32 $titles['Browse'] = PMA_tbl_setTitle($GLOBALS['cfg']['PropertiesIconic'], $pmaThemeImage);
34 * Not selection yet required -> displays the selection form
37 // Gets some core libraries
38 require_once './libraries/tbl_common.php';
39 //$err_url = 'tbl_select.php' . $err_url;
40 $url_query .= '&goto=tbl_select.php&back=tbl_select.php';
43 * Gets tables informations
45 require_once './libraries/tbl_info.inc.php';
48 * Displays top menu links
50 require_once './libraries/tbl_links.inc.php';
53 $goto = $GLOBALS['cfg']['DefaultTabTable'];
55 // Defines the url to return to in case of error in the next sql statement
56 $err_url = $goto . '?' . PMA_generate_common_url($db, $table);
58 // Gets the list and number of fields
60 list($fields_list, $fields_type, $fields_collation, $fields_null) = PMA_tbl_getFields($table,$db);
61 $fields_cnt = count($fields_list);
63 // retrieve keys into foreign fields, if any
64 // check also foreigners even if relwork is FALSE (to get
65 // foreign keys from innodb)
66 $foreigners = PMA_getForeigners($db, $table);
68 $tbl_fields_type = $tbl_fields_collation = $tbl_fields_null = array();
69 $maxPlotlLimit = $GLOBALS['cfg']['maxRowPlotLimit'];
72 <div id
="sqlqueryresults"></div
>
73 <fieldset id
="fieldset_subtab">
75 $url_params = array();
76 $url_params['db'] = $db;
77 $url_params['table'] = $table;
78 echo PMA_generate_html_tabs(PMA_tbl_getSubTabs(), $url_params);
81 * Set the field name,type,collation and whether null on select of a coulmn
83 if(isset($inputs) && ($inputs[0] != __('pma_null') ||
$inputs[1] != __('pma_null')))
86 for($i = 0 ; $i < 4 ; $i++
)
88 if($inputs[$i] != __('pma_null'))
90 $key = array_search($inputs[$i],$fields_list);
91 $tbl_fields_type[$i] = $fields_type[$key];
92 $tbl_fields_collation[$i] = $fields_collation[$key];
93 $tbl_fields_null[$i] = $fields_null[$key];
103 * Form for input criteria
107 <form method
="post" action
="tbl_zoom_select.php" name
="zoomInputForm" id
="zoom_search_form" <?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
' class="ajax"' : ''); ?
>>
108 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
109 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
110 <input type
="hidden" name
="back" value
="tbl_zoom_select.php" />
111 <input type
="hidden" name
="flag" id
="id_flag" value
=<?php
echo $flag; ?
> />
114 <fieldset id
="inputSection">
116 <legend
><?php
echo __('Do a "query by example" (wildcard: "%") for two columns') ?
></legend
>
118 <?php
echo PMA_tbl_setTableHeader();?
>
123 for($i = 0 ; $i < 4 ; $i++
){
127 echo __("Additional search criteria");
132 <tr
class="noclick <?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
133 <th
><select name
="inputs[]" id
=<?php
echo 'tableid_' . $i?
> >
134 <option value
= <?php
echo __('pma_null')?
>><?php
echo __('None'); ?
> </option
>
136 for ($j = 0 ; $j < $fields_cnt ; $j++
){
137 if(isset($inputs[$i]) && $inputs[$i] == htmlspecialchars($fields_list[$j])){?
>
138 <option value
=<?php
echo htmlspecialchars($fields_list[$j]);?
> Selected
> <?php
echo htmlspecialchars($fields_list[$j]);?
></option
>
142 <option value
=<?php
echo htmlspecialchars($fields_list[$j]);?
> > <?php
echo htmlspecialchars($fields_list[$j]);?
></option
>
147 <td
><?php
if(isset($tbl_fields_type[$i]))echo $tbl_fields_type[$i]; ?
></td
>
148 <td
><?php
if(isset($tbl_fields_collation[$i]))echo $tbl_fields_collation[$i]; ?
></td
>
151 <?php
if(isset($inputs) && $inputs[$i] != __('pma_null')){ ?
>
152 <select name
="zoomFunc[]">
155 if (strncasecmp($tbl_fields_type[$i], 'enum', 4) == 0) {
156 foreach ($GLOBALS['cfg']['EnumOperators'] as $fc) {
157 if(isset($zoomFunc[$i]) && $zoomFunc[$i] == htmlspecialchars($fc)){
159 . '<option value="' . htmlspecialchars($fc) . '" Selected>'
160 . htmlspecialchars($fc) . '</option>';
164 . '<option value="' . htmlspecialchars($fc) . '">'
165 . htmlspecialchars($fc) . '</option>';
168 } elseif (preg_match('@char|blob|text|set@i', $tbl_fields_type[$i])) {
169 foreach ($GLOBALS['cfg']['TextOperators'] as $fc) {
170 if(isset($zoomFunc[$i]) && $zoomFunc[$i] == $fc){
172 . '<option value="' . htmlspecialchars($fc) . '" Selected>'
173 . htmlspecialchars($fc) . '</option>';
177 . '<option value="' . htmlspecialchars($fc) . '">'
178 . htmlspecialchars($fc) . '</option>';
182 foreach ($GLOBALS['cfg']['NumOperators'] as $fc) {
183 if(isset($zoomFunc[$i]) && $zoomFunc[$i] == $fc){
185 . '<option value="' . htmlspecialchars($fc) . '" Selected>'
186 . htmlspecialchars($fc) . '</option>';
190 . '<option value="' . htmlspecialchars($fc) . '">'
191 . htmlspecialchars($fc) . '</option>';
194 } // end if... else...
196 if ($tbl_fields_null[$i]) {
197 foreach ($GLOBALS['cfg']['NullOperators'] as $fc) {
198 if(isset($zoomFunc[$i]) && $zoomFunc[$i] == $fc){
200 . '<option value="' . htmlspecialchars($fc) . '" Selected>'
201 . htmlspecialchars($fc) . '</option>';
205 . '<option value="' . htmlspecialchars($fc) . '">'
206 . htmlspecialchars($fc) . '</option>';
215 $field = $inputs[$i];
217 $foreignData = PMA_getForeignData($foreigners, $field, false, '', '');
219 echo PMA_getForeignFields_Values($foreigners, $foreignData, $field, $tbl_fields_type, $i ,$db, $table, $titles, $GLOBALS['cfg']['ForeignKeyMaxLimit'], $fields);
221 echo PMA_getForeignFields_Values($foreigners, $foreignData, $field, $tbl_fields_type, $i ,$db, $table, $titles, $GLOBALS['cfg']['ForeignKeyMaxLimit'], '');
233 <input type
="hidden" name
="types[<?php echo $i; ?>]"
234 value
="<?php if(isset($tbl_fields_type[$i]))echo $tbl_fields_type[$i]; ?>" />
235 <input type
="hidden" name
="collations[<?php echo $i; ?>]"
236 value
="<?php if(isset($tbl_fields_collation[$i]))echo $tbl_fields_collation[$i]; ?>" />
247 * Other inputs like data label and mode go after selection of column criteria
251 <tr
><td
><label
for="label"><?php
echo __("Data Label"); ?
></label
> 
 
 
 
 
 
 
 
</td
>
252 <td
><select name
="dataLabel" id
='dataLabel' >
253 <option value
= ''> <?php
echo __('None'); ?
> </option
>
255 for ($j = 0 ; $j < $fields_cnt ; $j++
){
256 if(isset($dataLabel) && $dataLabel == htmlspecialchars($fields_list[$j])){?
>
257 <option value
=<?php
echo htmlspecialchars($fields_list[$j]);?
> Selected
> <?php
echo htmlspecialchars($fields_list[$j]);?
></option
>
261 <option value
=<?php
echo htmlspecialchars($fields_list[$j]);?
> > <?php
echo htmlspecialchars($fields_list[$j]);?
></option
>
270 <fieldset
class="tblFooters">
271 <input type
="hidden" name
="max_number_of_fields"
272 value
="<?php echo $fields_cnt; ?>" />
273 <input type
="submit" name
="zoom_submit" id
="zoomSubmitId" value
="<?php echo __('Go'); ?>" />
280 * Handle the input criteria and gerate the query result
281 * Form for displaying query results
283 if(isset($zoom_submit) && $inputs[0] != __('pma_null') && $inputs[1] != __('pma_null')) {
286 * Query generation part
288 $w = $data = array();
289 $sql_query = 'SELECT *';
293 $sql_query .= ' FROM ' . PMA_backquote($table);
294 for($i = 0 ; $i < 4 ; $i++
){
295 if($inputs[$i] == __('pma_null'))
300 $cnt_func = count($zoomFunc[$i]);
301 $func_type = $zoomFunc[$i];
302 list($charsets[$i]) = explode('_', $collations[$i]);
303 $unaryFlag = (isset($GLOBALS['cfg']['UnaryOperators'][$func_type]) && $GLOBALS['cfg']['UnaryOperators'][$func_type] == 1) ?
true : false;
304 $whereClause = PMA_tbl_search_getWhereClause($fields[$i],$inputs[$i], $types[$i], $collations[$i], $func_type, $unaryFlag);
311 $sql_query .= ' WHERE ' . implode(' AND ', $w);
313 $sql_query .= ' LIMIT ' . $maxPlotlLimit;
314 if ($dataLabel == '') {
315 $dataLabel = PMA_getDisplayField($db,$table);
319 * Query execution part
321 $result = PMA_DBI_query( $sql_query . ";" , null, PMA_DBI_QUERY_STORE
);
322 $fields_meta = PMA_DBI_get_fields_meta($result);
323 while ($row = PMA_DBI_fetch_assoc($result)) {
324 //Need a row with indexes as 0,1,2 for the PMA_getUniqueCondition hence using a temporary array
326 foreach($row as $val)
328 //Get unique conditon on each row (will be needed for row update)
329 $uniqueCondition = PMA_getUniqueCondition($result, $fields_cnt, $fields_meta, $tmpRow, true);
330 //Append it to row array as where_clause
331 $row['where_clause'] = $uniqueCondition[0];
339 * Form for displaying point data and also the scatter plot
342 <form method
="post" action
="tbl_zoom_select.php" name
="displayResultForm" id
="zoom_display_form" <?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
' class="ajax"' : ''); ?
>>
343 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
344 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
345 <input type
="hidden" name
="back" value
="tbl_zoom_select.php" />
347 <div id
="overlay" class="web_dialog_overlay"></div
>
348 <div id
="dialog" class="web_dialog" style
="display:none">
349 <fieldset id
="displaySection">
350 <legend
><?php
echo __('Browse/Edit the points') ?
></legend
>
352 //JSON encode the data(query result)
353 if(isset($zoom_submit) && !empty($data)){ ?
>
354 <div id
='resizer' style
="width:600px;height:400px;float:right">
355 <?php
if (isset($data)) ?
><center
> <a href
="#" onClick
="displayHelp();"><?php
echo __('How to use'); ?
></a
> </center
>
356 <div id
="querydata" style
="display:none">
357 <?php
if(isset($data)) echo json_encode($data); ?
>
359 <div id
="querychart" style
="float:right"></div
>
364 <fieldset id
='dataDisplay'>
365 <legend
><?php
echo __('Data point content') ?
></legend
>
370 <th
> <?php
echo __('Column'); ?
> </th
>
371 <th
> <?php
echo __('Null'); ?
> </th
>
372 <th
> <?php
echo __('Value'); ?
> </th
>
378 for ($i = 4; $i < $fields_cnt +
4 ; $i++
) {
379 $tbl_fields_type[$i] = $fields_type[$i - 4];
380 $fieldpopup = $fields_list[$i - 4];
381 $foreignData = PMA_getForeignData($foreigners, $fieldpopup, false, '', '');
383 <tr
class="noclick <?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
384 <th
><?php
echo htmlspecialchars($fields_list[$i - 4]); ?
></th
>
385 <th
><?php
echo '<input type="checkbox" class="checkbox_null" name="fields_null[ ' . $i . ' ]" id="fields_null_id_' . $i . '" />'; ?
></th
>
386 <th
><?php
echo PMA_getForeignFields_Values($foreigners, $foreignData, $fieldpopup, $tbl_fields_type, $i, $db, $table, $titles,$GLOBALS['cfg']['ForeignKeyMaxLimit'], '' ); ?
> </th
>
393 <fieldset
class="tblFooters">
394 <input type
="submit" id
="buttonID" name
="edit_point" value
="<?php echo __('Submit'); ?>" />
400 <input type
="hidden" id
="queryID" name
="sql_query" />
408 require './libraries/footer.inc.php';