3 // vim: expandtab sw=4 ts=4 sts=4:
7 * Gets some core libraries
9 require_once('./libraries/common.lib.php');
10 require_once('./libraries/relation.lib.php'); // foreign keys
11 require_once('./libraries/mysql_charsets.lib.php');
13 if ( $GLOBALS['cfg']['PropertiesIconic'] == true ) {
15 '<img class="icon" width="16" height="16" src="' . $pmaThemeImage
16 .'b_browse.png" alt="' . $strBrowseForeignValues . '" title="'
17 .$strBrowseForeignValues . '" />';
19 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
20 $titles['Browse'] .= $strBrowseForeignValues;
23 $titles['Browse'] = $strBrowseForeignValues;
27 * Not selection yet required -> displays the selection form
29 if (!isset($param) ||
$param[0] == '') {
30 // Gets some core libraries
31 require_once('./libraries/tbl_properties_common.php');
32 //$err_url = 'tbl_select.php' . $err_url;
33 $url_query .= '&goto=tbl_select.php&back=tbl_select.php';
36 * Gets tables informations
38 require_once('./libraries/tbl_properties_table_info.inc.php');
41 * Displays top menu links
43 require_once('./libraries/tbl_properties_links.inc.php');
46 $goto = $GLOBALS['cfg']['DefaultTabTable'];
48 // Defines the url to return to in case of error in the next sql statement
49 $err_url = $goto . '?' . PMA_generate_common_url($db, $table);
51 // Gets the list and number of fields
52 $result = PMA_DBI_query('SHOW' . (PMA_MYSQL_INT_VERSION
>= 40100 ?
' FULL' : '') . ' FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE
);
53 $fields_cnt = PMA_DBI_num_rows($result);
54 // rabue: we'd better ensure, that all arrays are empty.
55 $fields_list = $fields_null = $fields_type = $fields_collation = array();
56 while ($row = PMA_DBI_fetch_assoc($result)) {
57 $fields_list[] = $row['Field'];
59 // reformat mysql query output - staybyte - 9. June 2001
60 if (strncasecmp($type, 'set', 3) == 0
61 ||
strncasecmp($type, 'enum', 4) == 0) {
62 $type = str_replace(',', ', ', $type);
65 // strip the "BINARY" attribute, except if we find "BINARY(" because
66 // this would be a BINARY or VARBINARY field type
67 if (!preg_match('@BINARY[\(]@i', $type)) {
68 $type = preg_replace('@BINARY@i', '', $type);
70 $type = preg_replace('@ZEROFILL@i', '', $type);
71 $type = preg_replace('@UNSIGNED@i', '', $type);
73 $type = strtolower($type);
78 $fields_null[] = $row['Null'];
79 $fields_type[] = $type;
80 $fields_collation[] = PMA_MYSQL_INT_VERSION
>= 40100 && !empty($row['Collation']) && $row['Collation'] != 'NULL'
84 PMA_DBI_free_result($result);
85 unset($result, $type);
88 // retrieve keys into foreign fields, if any
89 $cfgRelation = PMA_getRelationsParam();
90 // check also foreigners even if relwork is FALSE (to get
91 // foreign keys from innodb)
92 //$foreigners = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE);
93 $foreigners = PMA_getForeigners($db, $table);
95 <script type
="text/javascript" language
="javascript">
97 function PMA_tbl_select_operator(f
, index
, multiple
) {
98 switch (f
.elements
["func[" + index +
"]"].options
[f
.elements
["func[" + index +
"]"].selectedIndex
].value
) {
100 reset( $GLOBALS['cfg']['UnaryOperators'] );
101 while (list($operator) = each($GLOBALS['cfg']['UnaryOperators'])) {
102 echo ' case "' . $operator . "\":\r\n";
111 f
.elements
["fields[" + index +
"]" +
((multiple
) ?
"[]": "")].disabled
= bDisabled
;
115 <form method
="post" action
="tbl_select.php" name
="insertForm">
116 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
117 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
118 <input type
="hidden" name
="back" value
="tbl_select.php" />
120 <fieldset id
="fieldset_table_search">
122 <fieldset id
="fieldset_select_fields">
123 <legend
><?php
echo $strSelectFields; ?
></legend
>
124 <select name
="param[]" size
="<?php echo min($fields_cnt, 10); ?>"
127 // Displays the list of the fields
128 foreach ( $fields_list as $each_field ) {
130 .'<option value="' . htmlspecialchars( $each_field ) . '"'
131 .' selected="selected">' . htmlspecialchars( $each_field )
136 <input type
="checkbox" name
="distinct" value
="DISTINCT" id
="oDistinct" />
137 <label
for="oDistinct">DISTINCT
</label
>
140 <fieldset id
="fieldset_limit_rows">
141 <legend
><?php
echo $strLimitNumRows; ?
></legend
>
142 <input type
="text" size
="4" name
="session_max_rows"
143 value
="<?php echo $GLOBALS['cfg']['MaxRows']; ?>" class="textfield" />
146 <fieldset id
="fieldset_display_order">
147 <legend
><?php
echo $strDisplayOrder; ?
></legend
>
148 <select name
="orderField" style
="vertical-align: middle">
149 <option value
="--nil--"></option
>
151 foreach ( $fields_list as $each_field ) {
153 .'<option value="' . htmlspecialchars( $each_field ) . '">'
154 .htmlspecialchars( $each_field ) . '</option>' . "\n";
159 <div
class="formelement">
160 <input type
="radio" name
="order" value
="ASC" checked
="checked" id
="sortASC" />
161 <label
for="sortASC"><?php
echo $strAscending; ?
></label
>
164 <div
class="formelement">
165 <input type
="radio" name
="order" value
="DESC" id
="sortDESC" />
166 <label
for="sortDESC"><?php
echo $strDescending; ?
></label
>
170 <br
class="clearfloat" />
171 <?php
echo $strAddSearchConditions; ?
>
172 <?php
echo PMA_showMySQLDocu('SQL-Syntax', 'Functions'); ?
>
174 <input type
="text" name
="where" class="textfield" size
="64" />
177 <fieldset
class="tblFooters">
178 <input type
="submit" name
="submit" value
="<?php echo $strGo; ?>" />
181 <fieldset id
="fieldset_table_qbe">
182 <legend
><?php
echo '<em>' . $strOr . '</em> ' . $strDoAQuery; ?
></legend
>
185 <tr
><th
><?php
echo $strField; ?
></th
>
186 <th
><?php
echo $strType; ?
></th
>
187 <?php
echo PMA_MYSQL_INT_VERSION
>= 40100 ?
'<th>' . $strCollation . '</th>' . "\n" : ''; ?
>
188 <th
><?php
echo $strOperator; ?
></th
>
189 <th
><?php
echo $strValue; ?
></th
>
195 for ($i = 0; $i < $fields_cnt; $i++
) {
197 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
198 <th
><?php
echo htmlspecialchars($fields_list[$i]); ?
></th
>
199 <td
><?php
echo $fields_type[$i]; ?
></td
>
200 <?php
echo PMA_MYSQL_INT_VERSION
>= 40100 ?
'<td>'
201 . $fields_collation[$i] . '</td>' . "\n" : ''; ?
>
202 <td
><select name
="func[]">
204 if (strncasecmp($fields_type[$i], 'enum', 4) == 0) {
205 foreach ($GLOBALS['cfg']['EnumOperators'] as $fc) {
207 . '<option value="' . htmlspecialchars($fc) . '">'
208 . htmlspecialchars($fc) . '</option>';
210 } elseif (preg_match('@char|blob|text|set@i', $fields_type[$i])) {
211 foreach ($GLOBALS['cfg']['TextOperators'] as $fc) {
213 . '<option value="' . htmlspecialchars($fc) . '">'
214 . htmlspecialchars($fc) . '</option>';
217 foreach ($GLOBALS['cfg']['NumOperators'] as $fc) {
219 . '<option value="' . htmlspecialchars($fc) . '">'
220 . htmlspecialchars($fc) . '</option>';
222 } // end if... else...
223 if ($fields_null[$i]) {
224 foreach ($GLOBALS['cfg']['NullOperators'] as $fc) {
226 . '<option value="' . htmlspecialchars($fc) . '">'
227 . htmlspecialchars($fc) . '</option>';
237 $field = $fields_list[$i];
239 // do not use require_once here
240 require('./libraries/get_foreign.lib.php');
242 // we got a bug report: in some cases, even if $disp is true,
243 // there are no rows, so we add a fetch_array
245 if ($foreigners && isset($foreigners[$field]) && isset($disp_row) && is_array($disp_row)) {
246 // f o r e i g n k e y s
247 echo ' <select name="fields[' . $i . ']">' . "\n";
248 // go back to first row
250 // here, the 4th parameter is empty because there is no current
251 // value of data for the dropdown (the search page initial values
252 // are displayed empty)
253 echo PMA_foreignDropdown($disp_row, $foreign_field, $foreign_display,
254 '', $GLOBALS['cfg']['ForeignKeyMaxLimit']);
255 echo ' </select>' . "\n";
256 } elseif (isset($foreign_link) && $foreign_link == true) {
258 <input type
="text" name
="fields[<?php echo $i; ?>]"
259 id
="field_<?php echo md5($field); ?>[<?php echo $i; ?>]"
261 <script type
="text/javascript" language
="javascript">
262 document
.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes\'); return false" href="browse_foreigners.php?<?php echo PMA_generate_common_url($db, $table); ?>&field=<?php echo urlencode($field); ?>&fieldkey=<?php echo $i; ?>"><?php echo str_replace("'", "\'
", $titles['Browse']); ?></a>');
265 } elseif (strncasecmp($fields_type[$i], 'enum', 4) == 0) {
267 $enum_value=explode(', ', str_replace("'", '', substr($fields_type[$i], 5, -1)));
268 $cnt_enum_value = count($enum_value);
269 echo ' <select name
="fields[' . $i . '][]"'
270 .' multiple
="multiple" size
="' . min(3, $cnt_enum_value) . '">' . "\n";
271 for ($j = 0; $j < $cnt_enum_value; $j++) {
272 echo ' <option value
="' . $enum_value[$j] . '">'
273 . $enum_value[$j] . '</option
>';
275 echo ' </select
>' . "\n";
277 // o t h e r c a s e s
278 echo ' <input type
="text" name
="fields[' . $i . ']"'
279 .' size
="40" class="textfield" />' . "\n";
283 <input type="hidden" name="names[<?php echo $i; ?>]"
284 value="<?php echo htmlspecialchars($fields_list[$i]); ?>" />
285 <input type="hidden" name="types[<?php echo $i; ?>]"
286 value="<?php echo $fields_type[$i]; ?>" />
287 <input type="hidden" name="collations[<?php echo $i; ?>]"
288 value="<?php echo $fields_collation[$i]; ?>" />
297 <fieldset class="tblFooters">
298 <input type="hidden" name="max_number_of_fields"
299 value="<?php echo $fields_cnt; ?>" />
300 <input type="submit" name="submit" value="<?php echo $strGo; ?>" />
304 require_once('./libraries
/footer
.inc
.php
');
309 * Selection criteria have been submitted -> do the work
314 $sql_query = 'SELECT
' . (isset($distinct) ? 'DISTINCT
' : '');
316 // if all fields were selected to display, we do a SELECT *
317 // (more efficient and this helps prevent a problem in IE
318 // if one of the rows is edited and we come back to the Select results)
320 if (count($param) == $max_number_of_fields) {
323 $param = PMA_backquote( $param );
324 $sql_query .= implode( ', ', $param );
328 $sql_query .= ' FROM
' . PMA_backquote($table);
331 if (trim($where) != '') {
332 $sql_query .= ' WHERE
' . $where;
334 $w = $charsets = array();
335 $cnt_func = count($func);
337 while (list($i, $func_type) = each($func)) {
338 if (PMA_MYSQL_INT_VERSION >= 40100) {
339 list($charsets[$i]) = explode('_
', $collations[$i]);
341 if (@$GLOBALS['cfg
']['UnaryOperators
'][$func_type] == 1) {
343 $w[] = PMA_backquote(urldecode($names[$i])) . ' ' . $func_type;
345 } elseif (strncasecmp($types[$i], 'enum
', 4) == 0) {
346 if (!empty($fields[$i])) {
347 if (!is_array($fields[$i])) {
348 $fields[$i] = explode(',', $fields[$i]);
350 $enum_selected_count = count($fields[$i]);
351 if ($func_type == '=' && $enum_selected_count > 1) {
352 $func_type = $func[$i] = 'IN
';
356 } elseif ($func_type == '!=' && $enum_selected_count > 1) {
357 $func_type = $func[$i] = 'NOT IN
';
365 $enum_where = '\'
' . PMA_sqlAddslashes($fields[$i][0]) . '\'
';
366 if (PMA_MYSQL_INT_VERSION >= 40100 && $charsets[$i] != $charset_connection) {
367 $enum_where = 'CONVERT(_utf8
' . $enum_where . ' USING
' . $charsets[$i] . ') COLLATE
' . $collations[$i];
369 for ($e = 1; $e < $enum_selected_count; $e++) {
371 $tmp_literal = '\'
' . PMA_sqlAddslashes($fields[$i][$e]) . '\'
';
372 if (PMA_MYSQL_INT_VERSION >= 40100 && $charsets[$i] != $charset_connection) {
373 $tmp_literal = 'CONVERT(_utf8
' . $tmp_literal . ' USING
' . $charsets[$i] . ') COLLATE
' . $collations[$i];
375 $enum_where .= $tmp_literal;
379 $w[] = PMA_backquote(urldecode($names[$i])) . ' ' . $func_type . ' ' . $parens_open . $enum_where . $parens_close;
382 } elseif ($fields[$i] != '') {
383 if (preg_match('@char|binary|blob|text|set|date|time|year@i
', $types[$i])) {
389 // Make query independant from the selected connection charset.
390 // But if the field's type is VARBINARY
, it has no charset
391 // and $charsets[$i] is empty, so we cannot generate a CONVERT
393 if (PMA_MYSQL_INT_VERSION
>= 40101 && !empty($charsets[$i]) && $charsets[$i] != $charset_connection && preg_match('@char|binary|blob|text|set@i', $types[$i])) {
394 $prefix = 'CONVERT(_utf8 ';
395 $suffix = ' USING ' . $charsets[$i] . ') COLLATE ' . $collations[$i];
397 $prefix = $suffix = '';
401 if ($func_type == 'LIKE %...%') {
403 $fields[$i] = '%' . $fields[$i] . '%';
405 $w[] = PMA_backquote(urldecode($names[$i])) . ' ' . $func_type . ' ' . $prefix . $quot . PMA_sqlAddslashes($fields[$i]) . $quot . $suffix;
411 $sql_query .= ' WHERE ' . implode(' AND ', $w);
415 if ($orderField != '--nil--') {
416 $sql_query .= ' ORDER BY ' . PMA_backquote(urldecode($orderField)) . ' ' . $order;
418 include('./sql.php');