Fixed misfunction of edit mode
[phpmyadmin/ammaryasirr.git] / tbl_zoom_select.php
bloba44b16749958368484dd8680c84d2b59b85eca0b
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'][] = '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);
33 /**
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 .= '&amp;goto=tbl_select.php&amp;back=tbl_select.php';
42 /**
43 * Gets tables informations
45 require_once './libraries/tbl_info.inc.php';
47 /**
48 * Displays top menu links
50 require_once './libraries/tbl_links.inc.php';
52 if (! isset($goto)) {
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);
67 $flag = 1;
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">
74 <?php
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);
80 /**
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')))
85 $flag = 2;
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];
100 <?php
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>
117 <table class="data">
118 <?php echo PMA_tbl_setTableHeader();?>
119 <tbody>
120 <?php
121 $odd_row = true;
123 for($i = 0 ; $i < 4 ; $i++){
125 if($i == 2){
126 echo "<tr><td>";
127 echo __("Additional search criteria");
128 echo "</td><tr>";
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>
135 <?php
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>
139 <?php
141 else{ ?>
142 <option value=<?php echo htmlspecialchars($fields_list[$j]);?> > <?php echo htmlspecialchars($fields_list[$j]);?></option>
143 <?php
145 } ?>
146 </select></th>
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>
150 <td>
151 <?php if(isset($inputs) && $inputs[$i] != __('pma_null')){ ?>
152 <select name="zoomFunc[]">
153 <?php
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)){
158 echo "\n" . ' '
159 . '<option value="' . htmlspecialchars($fc) . '" Selected>'
160 . htmlspecialchars($fc) . '</option>';
162 else {
163 echo "\n" . ' '
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){
171 echo "\n" . ' '
172 . '<option value="' . htmlspecialchars($fc) . '" Selected>'
173 . htmlspecialchars($fc) . '</option>';
175 else {
176 echo "\n" . ' '
177 . '<option value="' . htmlspecialchars($fc) . '">'
178 . htmlspecialchars($fc) . '</option>';
181 } else {
182 foreach ($GLOBALS['cfg']['NumOperators'] as $fc) {
183 if(isset($zoomFunc[$i]) && $zoomFunc[$i] == $fc){
184 echo "\n" . ' '
185 . '<option value="' . htmlspecialchars($fc) . '" Selected>'
186 . htmlspecialchars($fc) . '</option>';
188 else {
189 echo "\n" . ' '
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){
199 echo "\n" . ' '
200 . '<option value="' . htmlspecialchars($fc) . '" Selected>'
201 . htmlspecialchars($fc) . '</option>';
203 else {
204 echo "\n" . ' '
205 . '<option value="' . htmlspecialchars($fc) . '">'
206 . htmlspecialchars($fc) . '</option>';
211 </select>
212 </td>
213 <td>
214 <?php
215 $field = $inputs[$i];
217 $foreignData = PMA_getForeignData($foreigners, $field, false, '', '');
218 if (isset($fields))
219 echo PMA_getForeignFields_Values($foreigners, $foreignData, $field, $tbl_fields_type, $i ,$db, $table, $titles, $GLOBALS['cfg']['ForeignKeyMaxLimit'], $fields);
220 else
221 echo PMA_getForeignFields_Values($foreigners, $foreignData, $field, $tbl_fields_type, $i ,$db, $table, $titles, $GLOBALS['cfg']['ForeignKeyMaxLimit'], '');
224 else{ ?>
226 </td><td></td>
228 <?php } ?>
230 </td>
231 </tr>
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]; ?>" />
240 <?php
241 }//end for
243 </table>
245 <?php
247 * Other inputs like data label and mode go after selection of column criteria
250 <table>
251 <tr><td><label for="label"><?php echo __("Data Label"); ?></label>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</td>
252 <td><select name="dataLabel" id='dataLabel' >
253 <option value = ''> <?php echo __('None'); ?> </option>
254 <?php
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>
258 <?php
260 else{ ?>
261 <option value=<?php echo htmlspecialchars($fields_list[$j]);?> > <?php echo htmlspecialchars($fields_list[$j]);?></option>
262 <?php
264 } ?>
265 </select>
266 </td></tr>
267 </table>
269 </fieldset>
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'); ?>" />
274 </fieldset>
275 </form>
277 <?php
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 *';
291 //Add the table
293 $sql_query .= ' FROM ' . PMA_backquote($table);
294 for($i = 0 ; $i < 4 ; $i++){
295 if($inputs[$i] == __('pma_null'))
296 continue;
297 $tmp = array();
298 // The where clause
299 $charsets = array();
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);
305 if($whereClause)
306 $w[] = $whereClause;
308 } // end for
309 //print_r($w);
310 if ($w) {
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
325 $tmpRow = array();
326 foreach($row as $val)
327 $tmpRow[] = $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];
332 $data[] = $row;
337 <?php
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>
351 <?php
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); ?>
358 </div>
359 <div id="querychart" style="float:right"></div>
360 </div>
361 <?php
362 } ?>
364 <fieldset id='dataDisplay'>
365 <legend><?php echo __('Data point content') ?></legend>
366 <fieldset>
367 <table class="data">
368 <thead>
369 <tr>
370 <th> <?php echo __('Column'); ?> </th>
371 <th> <?php echo __('Null'); ?> </th>
372 <th> <?php echo __('Value'); ?> </th>
373 </tr>
374 </thead>
375 <tbody>
376 <?php
377 $odd_row = true;
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>
387 </tr>
388 <?php
389 } ?>
390 </tbody>
391 </table>
392 </fieldset>
393 <fieldset class="tblFooters">
394 <input type="submit" id="buttonID" name="edit_point" value="<?php echo __('Submit'); ?>" />
395 </fieldset>
396 </fieldset>
398 </fieldset>
399 </div>
400 <input type="hidden" id="queryID" name="sql_query" />
401 </form>
402 </fieldset>
403 <?php
407 <?php
408 require './libraries/footer.inc.php';