2 /* vim: set expandtab sw=4 ts=4 sts=4: */
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
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/timepicker.js';
25 $GLOBALS['js_include'][] = 'gis_data_editor.js';
27 $titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values'));
29 $geom_types = PMA_getGISDatatypes();
38 'max_number_of_fields',
48 foreach ($post_params as $one_post_param) {
49 if (isset($_POST[$one_post_param])) {
50 $GLOBALS[$one_post_param] = $_POST[$one_post_param];
56 * Not selection yet required -> displays the selection form
58 if (! isset($param) ||
$param[0] == '') {
59 // Gets some core libraries
60 include_once 'libraries/tbl_common.php';
61 //$err_url = 'tbl_select.php' . $err_url;
62 $url_query .= '&goto=tbl_select.php&back=tbl_select.php';
65 * Gets tables informations
67 include_once 'libraries/tbl_info.inc.php';
70 * Displays top menu links
72 include_once 'libraries/tbl_links.inc.php';
75 $goto = $GLOBALS['cfg']['DefaultTabTable'];
77 // Defines the url to return to in case of error in the next sql statement
78 $err_url = $goto . '?' . PMA_generate_common_url($db, $table);
80 // Gets the list and number of fields
81 list($fields_list, $fields_type, $fields_collation, $fields_null, $geom_column_present) = PMA_tbl_getFields($db, $table);
82 $fields_cnt = count($fields_list);
84 // retrieve keys into foreign fields, if any
85 // check also foreigners even if relwork is FALSE (to get
86 // foreign keys from innodb)
87 $foreigners = PMA_getForeigners($db, $table);
90 <fieldset id
="fieldset_subtab">
92 $url_params = array();
93 $url_params['db'] = $db;
94 $url_params['table'] = $table;
96 echo PMA_generate_html_tabs(PMA_tbl_getSubTabs(), $url_params, '', 'topmenu2');
100 <form method
="post" action
="tbl_select.php" name
="insertForm" id
="tbl_search_form" <?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
' class="ajax"' : ''); ?
>>
101 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
102 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
103 <input type
="hidden" name
="back" value
="tbl_select.php" />
105 <fieldset id
="fieldset_table_search">
107 <fieldset id
="fieldset_table_qbe">
108 <legend
><?php
echo __('Do a "query by example" (wildcard: "%")') ?
></legend
>
110 <?php
echo PMA_tbl_setTableHeader($geom_column_present); ?
>
115 for ($i = 0; $i < $fields_cnt; $i++
) {
117 <tr
class="noclick <?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
119 // if 'Function' column is present
120 if ($geom_column_present) {
122 // if a geometry column
123 if (in_array($fields_type[$i], $geom_types)) {
124 echo('<select class="geom_func" name="geom_func['. $i .']">');
125 // get the relevant list of functions
126 $funcs = PMA_getGISFunctions($fields_type[$i], true, true);
127 foreach ($funcs as $func_name => $func) {
128 $name = isset($func['display']) ?
$func['display'] : $func_name;
129 echo('<option value="' . htmlspecialchars($name) . '">'
130 . htmlspecialchars($name) . '</option>');
139 <th
><?php
echo htmlspecialchars($fields_list[$i]); ?
></th
>
140 <td
><?php
echo htmlspecialchars($fields_type[$i]); ?
></td
>
141 <td
><?php
echo $fields_collation[$i]; ?
></td
>
142 <td
><select name
="func[]">
144 if (strncasecmp($fields_type[$i], 'enum', 4) == 0) {
145 foreach ($GLOBALS['cfg']['EnumOperators'] as $fc) {
147 . '<option value="' . htmlspecialchars($fc) . '">'
148 . htmlspecialchars($fc) . '</option>';
150 } elseif (preg_match('@char|blob|text|set@i', $fields_type[$i])) {
151 foreach ($GLOBALS['cfg']['TextOperators'] as $fc) {
153 . '<option value="' . htmlspecialchars($fc) . '">'
154 . htmlspecialchars($fc) . '</option>';
157 foreach ($GLOBALS['cfg']['NumOperators'] as $fc) {
159 . '<option value="' . htmlspecialchars($fc) . '">'
160 . htmlspecialchars($fc) . '</option>';
162 } // end if... else...
163 if ($fields_null[$i]) {
164 foreach ($GLOBALS['cfg']['NullOperators'] as $fc) {
166 . '<option value="' . htmlspecialchars($fc) . '">'
167 . htmlspecialchars($fc) . '</option>';
176 $field = $fields_list[$i];
178 $foreignData = PMA_getForeignData($foreigners, $field, false, '', '');
180 echo PMA_getForeignFields_Values($foreigners, $foreignData, $field, $fields_type, $i, $db, $table, $titles, $GLOBALS['cfg']['ForeignKeyMaxLimit'], '', true);
183 <input type
="hidden" name
="names[<?php echo $i; ?>]"
184 value
="<?php echo htmlspecialchars($fields_list[$i]); ?>" />
185 <input type
="hidden" name
="types[<?php echo $i; ?>]"
186 value
="<?php echo $fields_type[$i]; ?>" />
187 <input type
="hidden" name
="collations[<?php echo $i; ?>]"
188 value
="<?php echo $fields_collation[$i]; ?>" />
196 <div id
="gis_editor"></div
><div id
="popup_background"></div
>
199 PMA_generate_slider_effect('searchoptions', __('Options'));
201 <fieldset id
="fieldset_select_fields">
202 <legend
><?php
echo __('Select columns (at least one):'); ?
></legend
>
203 <select name
="param[]" size
="<?php echo min($fields_cnt, 10); ?>"
206 // Displays the list of the fields
207 foreach ($fields_list as $each_field) {
209 .'<option value="' . htmlspecialchars($each_field) . '"'
210 .' selected="selected">' . htmlspecialchars($each_field)
215 <input type
="checkbox" name
="distinct" value
="DISTINCT" id
="oDistinct" />
216 <label
for="oDistinct">DISTINCT
</label
>
219 <fieldset id
="fieldset_search_conditions">
220 <legend
><?php
echo '<em>' . __('Or') . '</em> ' . __('Add search conditions (body of the "where" clause):'); ?
></legend
>
221 <?php
echo PMA_showMySQLDocu('SQL-Syntax', 'Functions'); ?
>
223 <input type
="text" name
="where" class="textfield" size
="64" />
226 <fieldset id
="fieldset_limit_rows">
227 <legend
><?php
echo __('Number of rows per page'); ?
></legend
>
228 <input type
="text" size
="4" name
="session_max_rows"
229 value
="<?php echo $GLOBALS['cfg']['MaxRows']; ?>" class="textfield" />
232 <fieldset id
="fieldset_display_order">
233 <legend
><?php
echo __('Display order:'); ?
></legend
>
234 <select name
="orderField">
235 <option value
="--nil--"></option
>
237 foreach ($fields_list as $each_field) {
239 .'<option value="' . htmlspecialchars($each_field) . '">'
240 .htmlspecialchars($each_field) . '</option>' . "\n";
246 'ASC' => __('Ascending'),
247 'DESC' => __('Descending')
249 PMA_display_html_radio('order', $choices, 'ASC', false, true, "formelement");
253 <br style
="clear: both;"/>
256 <fieldset
class="tblFooters">
257 <input type
="hidden" name
="max_number_of_fields"
258 value
="<?php echo $fields_cnt; ?>" />
259 <input type
="submit" name
="submit" value
="<?php echo __('Go'); ?>" />
262 <div id
="sqlqueryresults"></div
>
265 include 'libraries/footer.inc.php';
268 * Selection criteria have been submitted -> do the work
273 $sql_query = 'SELECT ' . (isset($distinct) ?
'DISTINCT ' : '');
275 // if all fields were selected to display, we do a SELECT *
276 // (more efficient and this helps prevent a problem in IE
277 // if one of the rows is edited and we come back to the Select results)
279 if (count($param) == $max_number_of_fields) {
282 $param = PMA_backquote($param);
283 $sql_query .= implode(', ', $param);
286 // avoid a loop, for example when $cfg['DefaultTabTable'] is set
287 // to 'tbl_select.php'
290 $sql_query .= ' FROM ' . PMA_backquote($table);
293 if (trim($where) != '') {
294 $sql_query .= ' WHERE ' . $where;
296 $w = $charsets = array();
297 $cnt_func = count($func);
299 while (list($i, $func_type) = each($func)) {
301 list($charsets[$i]) = explode('_', $collations[$i]);
302 $unaryFlag = (isset($GLOBALS['cfg']['UnaryOperators'][$func_type]) && $GLOBALS['cfg']['UnaryOperators'][$func_type] == 1) ?
true : false;
304 $tmp_geom_func = isset($geom_func[$i]) ?
$geom_func[$i] : null;
305 $whereClause = PMA_tbl_search_getWhereClause($fields[$i], $names[$i], $types[$i], $collations[$i], $func_type, $unaryFlag, $tmp_geom_func);
311 $sql_query .= ' WHERE ' . implode(' AND ', $w);
315 if ($orderField != '--nil--') {
316 $sql_query .= ' ORDER BY ' . PMA_backquote($orderField) . ' ' . $order;