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.custom.js';
25 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
27 $titles['Browse'] = PMA_tbl_setTitle($GLOBALS['cfg']['PropertiesIconic'], $pmaThemeImage);
30 * Not selection yet required -> displays the selection form
32 if (! isset($param) ||
$param[0] == '') {
33 // Gets some core libraries
34 require_once './libraries/tbl_common.php';
35 //$err_url = 'tbl_select.php' . $err_url;
36 $url_query .= '&goto=tbl_select.php&back=tbl_select.php';
39 * Gets tables informations
41 require_once './libraries/tbl_info.inc.php';
44 * Displays top menu links
46 require_once './libraries/tbl_links.inc.php';
49 $goto = $GLOBALS['cfg']['DefaultTabTable'];
51 // Defines the url to return to in case of error in the next sql statement
52 $err_url = $goto . '?' . PMA_generate_common_url($db, $table);
54 // Gets the list and number of fields
56 list($fields_list, $fields_type, $fields_collation, $fields_null) = PMA_tbl_getFields($table,$db);
57 $fields_cnt = count($fields_list);
59 // retrieve keys into foreign fields, if any
60 // check also foreigners even if relwork is FALSE (to get
61 // foreign keys from innodb)
62 $foreigners = PMA_getForeigners($db, $table);
65 <fieldset id
="fieldset_subtab">
67 $url_params = array();
68 $url_params['db'] = $db;
69 $url_params['table'] = $table;
71 echo PMA_generate_html_tabs(PMA_tbl_getSubTabs(), $url_params);
75 <form method
="post" action
="tbl_select.php" name
="insertForm" id
="tbl_search_form" <?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
' class="ajax"' : ''); ?
>>
76 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
77 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
78 <input type
="hidden" name
="back" value
="tbl_select.php" />
80 <fieldset id
="fieldset_table_search">
82 <fieldset id
="fieldset_table_qbe">
83 <legend
><?php
echo __('Do a "query by example" (wildcard: "%")') ?
></legend
>
85 <?php
echo PMA_tbl_setTableHeader(); ?
>
90 for ($i = 0; $i < $fields_cnt; $i++
) {
92 <tr
class="noclick <?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
93 <th
><?php
echo htmlspecialchars($fields_list[$i]); ?
></th
>
94 <td
><?php
echo $fields_type[$i]; ?
></td
>
95 <td
><?php
echo $fields_collation[$i]; ?
></td
>
96 <td
><select name
="func[]">
98 if (strncasecmp($fields_type[$i], 'enum', 4) == 0) {
99 foreach ($GLOBALS['cfg']['EnumOperators'] as $fc) {
101 . '<option value="' . htmlspecialchars($fc) . '">'
102 . htmlspecialchars($fc) . '</option>';
104 } elseif (preg_match('@char|blob|text|set@i', $fields_type[$i])) {
105 foreach ($GLOBALS['cfg']['TextOperators'] as $fc) {
107 . '<option value="' . htmlspecialchars($fc) . '">'
108 . htmlspecialchars($fc) . '</option>';
111 foreach ($GLOBALS['cfg']['NumOperators'] as $fc) {
113 . '<option value="' . htmlspecialchars($fc) . '">'
114 . htmlspecialchars($fc) . '</option>';
116 } // end if... else...
117 if ($fields_null[$i]) {
118 foreach ($GLOBALS['cfg']['NullOperators'] as $fc) {
120 . '<option value="' . htmlspecialchars($fc) . '">'
121 . htmlspecialchars($fc) . '</option>';
130 $field = $fields_list[$i];
132 $foreignData = PMA_getForeignData($foreigners, $field, false, '', '');
134 echo PMA_getForeignFields_Values($foreigners, $foreignData, $field, $fields_type, $i, $db, $table, $titles,$GLOBALS['cfg']['ForeignKeyMaxLimit'], '' );
137 <input type
="hidden" name
="names[<?php echo $i; ?>]"
138 value
="<?php echo htmlspecialchars($fields_list[$i]); ?>" />
139 <input type
="hidden" name
="types[<?php echo $i; ?>]"
140 value
="<?php echo $fields_type[$i]; ?>" />
141 <input type
="hidden" name
="collations[<?php echo $i; ?>]"
142 value
="<?php echo $fields_collation[$i]; ?>" />
152 PMA_generate_slider_effect('searchoptions', __('Options'));
154 <fieldset id
="fieldset_select_fields">
155 <legend
><?php
echo __('Select columns (at least one):'); ?
></legend
>
156 <select name
="param[]" size
="<?php echo min($fields_cnt, 10); ?>"
159 // Displays the list of the fields
160 foreach ($fields_list as $each_field) {
162 .'<option value="' . htmlspecialchars($each_field) . '"'
163 .' selected="selected">' . htmlspecialchars($each_field)
168 <input type
="checkbox" name
="distinct" value
="DISTINCT" id
="oDistinct" />
169 <label
for="oDistinct">DISTINCT
</label
>
172 <fieldset id
="fieldset_search_conditions">
173 <legend
><?php
echo '<em>' . __('Or') . '</em> ' . __('Add search conditions (body of the "where" clause):'); ?
></legend
>
174 <?php
echo PMA_showMySQLDocu('SQL-Syntax', 'Functions'); ?
>
176 <input type
="text" name
="where" class="textfield" size
="64" />
179 <fieldset id
="fieldset_limit_rows">
180 <legend
><?php
echo __('Number of rows per page'); ?
></legend
>
181 <input type
="text" size
="4" name
="session_max_rows"
182 value
="<?php echo $GLOBALS['cfg']['MaxRows']; ?>" class="textfield" />
185 <fieldset id
="fieldset_display_order">
186 <legend
><?php
echo __('Display order:'); ?
></legend
>
187 <select name
="orderField">
188 <option value
="--nil--"></option
>
190 foreach ($fields_list as $each_field) {
192 .'<option value="' . htmlspecialchars($each_field) . '">'
193 .htmlspecialchars($each_field) . '</option>' . "\n";
199 'ASC' => __('Ascending'),
200 'DESC' => __('Descending')
202 PMA_display_html_radio('order', $choices, 'ASC', false, true, "formelement");
206 <br style
="clear: both;"/>
209 <fieldset
class="tblFooters">
210 <input type
="hidden" name
="max_number_of_fields"
211 value
="<?php echo $fields_cnt; ?>" />
212 <input type
="submit" name
="submit" value
="<?php echo __('Go'); ?>" />
215 <div id
="sqlqueryresults"></div
>
217 require './libraries/footer.inc.php';
228 * Selection criteria have been submitted -> do the work
234 $sql_query = 'SELECT ' . (isset($distinct) ?
'DISTINCT ' : '');
236 // if all fields were selected to display, we do a SELECT *
237 // (more efficient and this helps prevent a problem in IE
238 // if one of the rows is edited and we come back to the Select results)
240 if (count($param) == $max_number_of_fields) {
243 $param = PMA_backquote($param);
244 $sql_query .= implode(', ', $param);
247 // avoid a loop, for example when $cfg['DefaultTabTable'] is set
248 // to 'tbl_select.php'
251 $sql_query .= ' FROM ' . PMA_backquote($table);
254 if (trim($where) != '') {
255 $sql_query .= ' WHERE ' . $where;
257 $w = $charsets = array();
258 $cnt_func = count($func);
260 while (list($i, $func_type) = each($func)) {
262 list($charsets[$i]) = explode('_', $collations[$i]);
263 $unaryFlag = (isset($GLOBALS['cfg']['UnaryOperators'][$func_type]) && $GLOBALS['cfg']['UnaryOperators'][$func_type] == 1) ?
true : false;
264 $whereClause = PMA_tbl_search_getWhereClause($fields[$i],$names[$i], $types[$i], $collations[$i], $func_type, $unaryFlag);
271 $sql_query .= ' WHERE ' . implode(' AND ', $w);
275 if ($orderField != '--nil--') {
276 $sql_query .= ' ORDER BY ' . PMA_backquote($orderField) . ' ' . $order;