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/jquery-ui-1.8.16.custom.js';
25 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
26 $GLOBALS['js_include'][] = 'gis_data_editor.js';
28 $titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values'));
30 $geom_types = PMA_getGISDatatypes();
39 'max_number_of_fields',
49 foreach ($post_params as $one_post_param) {
50 if (isset($_POST[$one_post_param])) {
51 $GLOBALS[$one_post_param] = $_POST[$one_post_param];
57 * Not selection yet required -> displays the selection form
59 if (! isset($param) ||
$param[0] == '') {
60 // Gets some core libraries
61 include_once './libraries/tbl_common.php';
62 //$err_url = 'tbl_select.php' . $err_url;
63 $url_query .= '&goto=tbl_select.php&back=tbl_select.php';
66 * Gets tables informations
68 include_once './libraries/tbl_info.inc.php';
71 * Displays top menu links
73 include_once './libraries/tbl_links.inc.php';
76 $goto = $GLOBALS['cfg']['DefaultTabTable'];
78 // Defines the url to return to in case of error in the next sql statement
79 $err_url = $goto . '?' . PMA_generate_common_url($db, $table);
81 // Gets the list and number of fields
82 list($fields_list, $fields_type, $fields_collation, $fields_null, $geom_column_present) = PMA_tbl_getFields($db, $table);
83 $fields_cnt = count($fields_list);
85 // retrieve keys into foreign fields, if any
86 // check also foreigners even if relwork is FALSE (to get
87 // foreign keys from innodb)
88 $foreigners = PMA_getForeigners($db, $table);
91 <fieldset id
="fieldset_subtab">
93 $url_params = array();
94 $url_params['db'] = $db;
95 $url_params['table'] = $table;
97 echo PMA_generate_html_tabs(PMA_tbl_getSubTabs(), $url_params, '', 'topmenu2');
101 <form method
="post" action
="tbl_select.php" name
="insertForm" id
="tbl_search_form" <?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
' class="ajax"' : ''); ?
>>
102 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
103 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
104 <input type
="hidden" name
="back" value
="tbl_select.php" />
106 <fieldset id
="fieldset_table_search">
108 <fieldset id
="fieldset_table_qbe">
109 <legend
><?php
echo __('Do a "query by example" (wildcard: "%")') ?
></legend
>
111 <?php
echo PMA_tbl_setTableHeader($geom_column_present); ?
>
116 for ($i = 0; $i < $fields_cnt; $i++
) {
118 <tr
class="noclick <?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
120 // if 'Function' column is present
121 if ($geom_column_present) {
123 // if a geometry column
124 if (in_array($fields_type[$i], $geom_types)) {
125 echo('<select class="geom_func" name="geom_func['. $i .']">');
126 // get the relevant list of functions
127 $funcs = PMA_getGISFunctions($fields_type[$i], true, true);
128 foreach ($funcs as $func_name => $func) {
129 $name = isset($func['display']) ?
$func['display'] : $func_name;
130 echo('<option value="' . htmlspecialchars($name) . '">'
131 . htmlspecialchars($name) . '</option>');
140 <th
><?php
echo htmlspecialchars($fields_list[$i]); ?
></th
>
141 <td
><?php
echo htmlspecialchars($fields_type[$i]); ?
></td
>
142 <td
><?php
echo $fields_collation[$i]; ?
></td
>
143 <td
><select name
="func[]">
145 if (strncasecmp($fields_type[$i], 'enum', 4) == 0) {
146 foreach ($GLOBALS['cfg']['EnumOperators'] as $fc) {
148 . '<option value="' . htmlspecialchars($fc) . '">'
149 . htmlspecialchars($fc) . '</option>';
151 } elseif (preg_match('@char|blob|text|set@i', $fields_type[$i])) {
152 foreach ($GLOBALS['cfg']['TextOperators'] as $fc) {
154 . '<option value="' . htmlspecialchars($fc) . '">'
155 . htmlspecialchars($fc) . '</option>';
158 foreach ($GLOBALS['cfg']['NumOperators'] as $fc) {
160 . '<option value="' . htmlspecialchars($fc) . '">'
161 . htmlspecialchars($fc) . '</option>';
163 } // end if... else...
164 if ($fields_null[$i]) {
165 foreach ($GLOBALS['cfg']['NullOperators'] as $fc) {
167 . '<option value="' . htmlspecialchars($fc) . '">'
168 . htmlspecialchars($fc) . '</option>';
177 $field = $fields_list[$i];
179 $foreignData = PMA_getForeignData($foreigners, $field, false, '', '');
181 echo PMA_getForeignFields_Values($foreigners, $foreignData, $field, $fields_type, $i, $db, $table, $titles, $GLOBALS['cfg']['ForeignKeyMaxLimit'], '', true);
184 <input type
="hidden" name
="names[<?php echo $i; ?>]"
185 value
="<?php echo htmlspecialchars($fields_list[$i]); ?>" />
186 <input type
="hidden" name
="types[<?php echo $i; ?>]"
187 value
="<?php echo $fields_type[$i]; ?>" />
188 <input type
="hidden" name
="collations[<?php echo $i; ?>]"
189 value
="<?php echo $fields_collation[$i]; ?>" />
197 <div id
="gis_editor"></div
><div id
="popup_background"></div
>
200 PMA_generate_slider_effect('searchoptions', __('Options'));
202 <fieldset id
="fieldset_select_fields">
203 <legend
><?php
echo __('Select columns (at least one):'); ?
></legend
>
204 <select name
="param[]" size
="<?php echo min($fields_cnt, 10); ?>"
207 // Displays the list of the fields
208 foreach ($fields_list as $each_field) {
210 .'<option value="' . htmlspecialchars($each_field) . '"'
211 .' selected="selected">' . htmlspecialchars($each_field)
216 <input type
="checkbox" name
="distinct" value
="DISTINCT" id
="oDistinct" />
217 <label
for="oDistinct">DISTINCT
</label
>
220 <fieldset id
="fieldset_search_conditions">
221 <legend
><?php
echo '<em>' . __('Or') . '</em> ' . __('Add search conditions (body of the "where" clause):'); ?
></legend
>
222 <?php
echo PMA_showMySQLDocu('SQL-Syntax', 'Functions'); ?
>
224 <input type
="text" name
="where" class="textfield" size
="64" />
227 <fieldset id
="fieldset_limit_rows">
228 <legend
><?php
echo __('Number of rows per page'); ?
></legend
>
229 <input type
="text" size
="4" name
="session_max_rows"
230 value
="<?php echo $GLOBALS['cfg']['MaxRows']; ?>" class="textfield" />
233 <fieldset id
="fieldset_display_order">
234 <legend
><?php
echo __('Display order:'); ?
></legend
>
235 <select name
="orderField">
236 <option value
="--nil--"></option
>
238 foreach ($fields_list as $each_field) {
240 .'<option value="' . htmlspecialchars($each_field) . '">'
241 .htmlspecialchars($each_field) . '</option>' . "\n";
247 'ASC' => __('Ascending'),
248 'DESC' => __('Descending')
250 PMA_display_html_radio('order', $choices, 'ASC', false, true, "formelement");
254 <br style
="clear: both;"/>
257 <fieldset
class="tblFooters">
258 <input type
="hidden" name
="max_number_of_fields"
259 value
="<?php echo $fields_cnt; ?>" />
260 <input type
="submit" name
="submit" value
="<?php echo __('Go'); ?>" />
263 <div id
="sqlqueryresults"></div
>
265 include './libraries/footer.inc.php';
273 * Selection criteria have been submitted -> do the work
278 $sql_query = 'SELECT ' . (isset($distinct) ?
'DISTINCT ' : '');
280 // if all fields were selected to display, we do a SELECT *
281 // (more efficient and this helps prevent a problem in IE
282 // if one of the rows is edited and we come back to the Select results)
284 if (count($param) == $max_number_of_fields) {
287 $param = PMA_backquote($param);
288 $sql_query .= implode(', ', $param);
291 // avoid a loop, for example when $cfg['DefaultTabTable'] is set
292 // to 'tbl_select.php'
295 $sql_query .= ' FROM ' . PMA_backquote($table);
298 if (trim($where) != '') {
299 $sql_query .= ' WHERE ' . $where;
301 $w = $charsets = array();
302 $cnt_func = count($func);
304 while (list($i, $func_type) = each($func)) {
306 list($charsets[$i]) = explode('_', $collations[$i]);
307 $unaryFlag = (isset($GLOBALS['cfg']['UnaryOperators'][$func_type]) && $GLOBALS['cfg']['UnaryOperators'][$func_type] == 1) ?
true : false;
309 $tmp_geom_func = isset($geom_func[$i]) ?
$geom_func[$i] : null;
310 $whereClause = PMA_tbl_search_getWhereClause($fields[$i], $names[$i], $types[$i], $collations[$i], $func_type, $unaryFlag, $tmp_geom_func);
316 $sql_query .= ' WHERE ' . implode(' AND ', $w);
320 if ($orderField != '--nil--') {
321 $sql_query .= ' ORDER BY ' . PMA_backquote($orderField) . ' ' . $order;