Translation update done using Pootle.
[phpmyadmin.git] / tbl_select.php
blobabda39949aac5cc3cd494ca0aa9c4fee170ee6ce
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Handles table search tab
6 * display table search form, create SQL query from form data
7 * and include sql.php to execute it
9 * @todo display search form again if no results from previous search
10 * @package phpMyAdmin
13 /**
14 * Gets some core libraries
16 require_once './libraries/common.inc.php';
17 require_once './libraries/mysql_charsets.lib.php';
18 require_once './libraries/tbl_select.lib.php';
20 $GLOBALS['js_include'][] = 'makegrid.js';
21 $GLOBALS['js_include'][] = 'sql.js';
22 $GLOBALS['js_include'][] = 'tbl_select.js';
23 $GLOBALS['js_include'][] = 'tbl_change.js';
24 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
25 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
27 // required for GIS editor loaded via AJAX
28 $GLOBALS['js_include'][] = 'gis_data_editor.js';
29 $GLOBALS['js_include'][] = 'jquery/jquery.sprintf.js';
30 $GLOBALS['js_include'][] = 'jquery/jquery.svg.js';
31 $GLOBALS['js_include'][] = 'jquery/jquery.mousewheel.js';
32 $GLOBALS['js_include'][] = 'jquery/jquery.event.drag-2.0.min.js';
33 $GLOBALS['js_include'][] = 'tbl_gis_visualization.js';
34 $GLOBALS['js_include'][] = 'openlayers/OpenLayers.js';
35 $GLOBALS['js_include'][] = 'OpenStreetMap.js';
37 $titles['Browse'] = PMA_tbl_setTitle($GLOBALS['cfg']['PropertiesIconic'], $pmaThemeImage);
39 $geom_types = PMA_getGISDatatypes();
40 /**
41 * Not selection yet required -> displays the selection form
43 if (! isset($param) || $param[0] == '') {
44 // Gets some core libraries
45 require_once './libraries/tbl_common.php';
46 //$err_url = 'tbl_select.php' . $err_url;
47 $url_query .= '&amp;goto=tbl_select.php&amp;back=tbl_select.php';
49 /**
50 * Gets tables informations
52 require_once './libraries/tbl_info.inc.php';
54 /**
55 * Displays top menu links
57 require_once './libraries/tbl_links.inc.php';
59 if (! isset($goto)) {
60 $goto = $GLOBALS['cfg']['DefaultTabTable'];
62 // Defines the url to return to in case of error in the next sql statement
63 $err_url = $goto . '?' . PMA_generate_common_url($db, $table);
65 // Gets the list and number of fields
66 list($fields_list, $fields_type, $fields_collation, $fields_null, $geom_column_present) = PMA_tbl_getFields($db, $table);
67 $fields_cnt = count($fields_list);
69 // retrieve keys into foreign fields, if any
70 // check also foreigners even if relwork is FALSE (to get
71 // foreign keys from innodb)
72 $foreigners = PMA_getForeigners($db, $table);
75 <fieldset id="fieldset_subtab">
76 <?php
77 $url_params = array();
78 $url_params['db'] = $db;
79 $url_params['table'] = $table;
81 echo PMA_generate_html_tabs(PMA_tbl_getSubTabs(), $url_params);
85 <form method="post" action="tbl_select.php" name="insertForm" id="tbl_search_form" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?>>
86 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
87 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
88 <input type="hidden" name="back" value="tbl_select.php" />
90 <fieldset id="fieldset_table_search">
92 <fieldset id="fieldset_table_qbe">
93 <legend><?php echo __('Do a "query by example" (wildcard: "%")') ?></legend>
94 <table class="data">
95 <?php echo PMA_tbl_setTableHeader($geom_column_present); ?>
96 <tbody>
97 <?php
98 $odd_row = true;
100 for ($i = 0; $i < $fields_cnt; $i++) {
102 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
103 <?php
104 // if 'Function' column is present
105 if ($geom_column_present) {
106 echo('<td>');
107 // if a geometry column
108 if (in_array($fields_type[$i], $geom_types)) {
109 echo('<select class="geom_func" name="geom_func['. $i .']">');
110 // get the relevant list of functions
111 $funcs = PMA_getGISFunctions($fields_type[$i], true, true);
112 foreach ($funcs as $func_name => $func) {
113 $name = isset($func['display']) ? $func['display'] : $func_name;
114 echo('<option value="' . htmlspecialchars($name) . '">'
115 . htmlspecialchars($name) . '</option>');
117 echo('</select>');
118 } else {
119 echo('&nbsp;');
121 echo('</td>');
124 <th><?php echo htmlspecialchars($fields_list[$i]); ?></th>
125 <td><?php echo $fields_type[$i]; ?></td>
126 <td><?php echo $fields_collation[$i]; ?></td>
127 <td><select name="func[]">
128 <?php
129 if (strncasecmp($fields_type[$i], 'enum', 4) == 0) {
130 foreach ($GLOBALS['cfg']['EnumOperators'] as $fc) {
131 echo "\n" . ' '
132 . '<option value="' . htmlspecialchars($fc) . '">'
133 . htmlspecialchars($fc) . '</option>';
135 } elseif (preg_match('@char|blob|text|set@i', $fields_type[$i])) {
136 foreach ($GLOBALS['cfg']['TextOperators'] as $fc) {
137 echo "\n" . ' '
138 . '<option value="' . htmlspecialchars($fc) . '">'
139 . htmlspecialchars($fc) . '</option>';
141 } else {
142 foreach ($GLOBALS['cfg']['NumOperators'] as $fc) {
143 echo "\n" . ' '
144 . '<option value="' . htmlspecialchars($fc) . '">'
145 . htmlspecialchars($fc) . '</option>';
147 } // end if... else...
148 if ($fields_null[$i]) {
149 foreach ($GLOBALS['cfg']['NullOperators'] as $fc) {
150 echo "\n" . ' '
151 . '<option value="' . htmlspecialchars($fc) . '">'
152 . htmlspecialchars($fc) . '</option>';
157 </select>
158 </td>
159 <td>
160 <?php
161 $field = $fields_list[$i];
163 $foreignData = PMA_getForeignData($foreigners, $field, false, '', '');
165 echo PMA_getForeignFields_Values($foreigners, $foreignData, $field, $fields_type, $i, $db, $table, $titles,$GLOBALS['cfg']['ForeignKeyMaxLimit'], '', true);
168 <input type="hidden" name="names[<?php echo $i; ?>]"
169 value="<?php echo htmlspecialchars($fields_list[$i]); ?>" />
170 <input type="hidden" name="types[<?php echo $i; ?>]"
171 value="<?php echo $fields_type[$i]; ?>" />
172 <input type="hidden" name="collations[<?php echo $i; ?>]"
173 value="<?php echo $fields_collation[$i]; ?>" />
174 </td>
175 </tr>
176 <?php
177 } // end for
179 </tbody>
180 </table>
181 <div id="gis_editor"></div><div id="popup_background"></div>
182 </fieldset>
183 <?php
184 PMA_generate_slider_effect('searchoptions', __('Options'));
186 <fieldset id="fieldset_select_fields">
187 <legend><?php echo __('Select columns (at least one):'); ?></legend>
188 <select name="param[]" size="<?php echo min($fields_cnt, 10); ?>"
189 multiple="multiple">
190 <?php
191 // Displays the list of the fields
192 foreach ($fields_list as $each_field) {
193 echo ' '
194 .'<option value="' . htmlspecialchars($each_field) . '"'
195 .' selected="selected">' . htmlspecialchars($each_field)
196 .'</option>' . "\n";
199 </select>
200 <input type="checkbox" name="distinct" value="DISTINCT" id="oDistinct" />
201 <label for="oDistinct">DISTINCT</label>
202 </fieldset>
204 <fieldset id="fieldset_search_conditions">
205 <legend><?php echo '<em>' . __('Or') . '</em> ' . __('Add search conditions (body of the "where" clause):'); ?></legend>
206 <?php echo PMA_showMySQLDocu('SQL-Syntax', 'Functions'); ?>
208 <input type="text" name="where" class="textfield" size="64" />
209 </fieldset>
211 <fieldset id="fieldset_limit_rows">
212 <legend><?php echo __('Number of rows per page'); ?></legend>
213 <input type="text" size="4" name="session_max_rows"
214 value="<?php echo $GLOBALS['cfg']['MaxRows']; ?>" class="textfield" />
215 </fieldset>
217 <fieldset id="fieldset_display_order">
218 <legend><?php echo __('Display order:'); ?></legend>
219 <select name="orderField">
220 <option value="--nil--"></option>
221 <?php
222 foreach ($fields_list as $each_field) {
223 echo ' '
224 .'<option value="' . htmlspecialchars($each_field) . '">'
225 .htmlspecialchars($each_field) . '</option>' . "\n";
226 } // end for
228 </select>
229 <?php
230 $choices = array(
231 'ASC' => __('Ascending'),
232 'DESC' => __('Descending')
234 PMA_display_html_radio('order', $choices, 'ASC', false, true, "formelement");
235 unset($choices);
237 </fieldset>
238 <br style="clear: both;"/>
239 </div>
240 </fieldset>
241 <fieldset class="tblFooters">
242 <input type="hidden" name="max_number_of_fields"
243 value="<?php echo $fields_cnt; ?>" />
244 <input type="submit" name="submit" value="<?php echo __('Go'); ?>" />
245 </fieldset>
246 </form>
247 <div id="sqlqueryresults"></div>
248 <?php
249 require './libraries/footer.inc.php';
252 </fieldset>
254 <?php
260 * Selection criteria have been submitted -> do the work
262 else {
263 // Builds the query
265 $sql_query = 'SELECT ' . (isset($distinct) ? 'DISTINCT ' : '');
267 // if all fields were selected to display, we do a SELECT *
268 // (more efficient and this helps prevent a problem in IE
269 // if one of the rows is edited and we come back to the Select results)
271 if (count($param) == $max_number_of_fields) {
272 $sql_query .= '* ';
273 } else {
274 $param = PMA_backquote($param);
275 $sql_query .= implode(', ', $param);
276 } // end if
278 // avoid a loop, for example when $cfg['DefaultTabTable'] is set
279 // to 'tbl_select.php'
280 unset($param);
282 $sql_query .= ' FROM ' . PMA_backquote($table);
284 // The where clause
285 if (trim($where) != '') {
286 $sql_query .= ' WHERE ' . $where;
287 } else {
288 $w = $charsets = array();
289 $cnt_func = count($func);
290 reset($func);
291 while (list($i, $func_type) = each($func)) {
293 list($charsets[$i]) = explode('_', $collations[$i]);
294 $unaryFlag = (isset($GLOBALS['cfg']['UnaryOperators'][$func_type]) && $GLOBALS['cfg']['UnaryOperators'][$func_type] == 1) ? true : false;
296 $tmp_geom_func = isset($geom_func[$i]) ? $geom_func[$i] : null;
297 $whereClause = PMA_tbl_search_getWhereClause($fields[$i],$names[$i], $types[$i], $collations[$i], $func_type, $unaryFlag, $tmp_geom_func);
299 if($whereClause)
300 $w[] = $whereClause;
301 } // end for
302 if ($w) {
303 $sql_query .= ' WHERE ' . implode(' AND ', $w);
305 } // end if
307 if ($orderField != '--nil--') {
308 $sql_query .= ' ORDER BY ' . PMA_backquote($orderField) . ' ' . $order;
309 } // end if
310 require './sql.php';