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_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_info.inc.php');
41 * Displays top menu links
43 require_once('./libraries/tbl_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
>
196 <script type
="text/javascript" language
="javascript" src
="./js/tbl_change.js"></script
>
198 for ($i = 0; $i < $fields_cnt; $i++
) {
200 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
201 <th
><?php
echo htmlspecialchars($fields_list[$i]); ?
></th
>
202 <td
><?php
echo $fields_type[$i]; ?
></td
>
203 <?php
echo PMA_MYSQL_INT_VERSION
>= 40100 ?
'<td>'
204 . $fields_collation[$i] . '</td>' . "\n" : ''; ?
>
205 <td
><select name
="func[]">
207 if (strncasecmp($fields_type[$i], 'enum', 4) == 0) {
208 foreach ($GLOBALS['cfg']['EnumOperators'] as $fc) {
210 . '<option value="' . htmlspecialchars($fc) . '">'
211 . htmlspecialchars($fc) . '</option>';
213 } elseif (preg_match('@char|blob|text|set@i', $fields_type[$i])) {
214 foreach ($GLOBALS['cfg']['TextOperators'] as $fc) {
216 . '<option value="' . htmlspecialchars($fc) . '">'
217 . htmlspecialchars($fc) . '</option>';
220 foreach ($GLOBALS['cfg']['NumOperators'] as $fc) {
222 . '<option value="' . htmlspecialchars($fc) . '">'
223 . htmlspecialchars($fc) . '</option>';
225 } // end if... else...
226 if ($fields_null[$i]) {
227 foreach ($GLOBALS['cfg']['NullOperators'] as $fc) {
229 . '<option value="' . htmlspecialchars($fc) . '">'
230 . htmlspecialchars($fc) . '</option>';
240 $field = $fields_list[$i];
242 // do not use require_once here
243 require('./libraries/get_foreign.lib.php');
245 // we got a bug report: in some cases, even if $disp is true,
246 // there are no rows, so we add a fetch_array
248 if ($foreigners && isset($foreigners[$field]) && isset($disp_row) && is_array($disp_row)) {
249 // f o r e i g n k e y s
250 echo ' <select name="fields[' . $i . ']">' . "\n";
251 // go back to first row
253 // here, the 4th parameter is empty because there is no current
254 // value of data for the dropdown (the search page initial values
255 // are displayed empty)
256 echo PMA_foreignDropdown($disp_row, $foreign_field, $foreign_display,
257 '', $GLOBALS['cfg']['ForeignKeyMaxLimit']);
258 echo ' </select>' . "\n";
259 } elseif (isset($foreign_link) && $foreign_link == true) {
261 <input type
="text" name
="fields[<?php echo $i; ?>]"
262 id
="field_<?php echo md5($field); ?>[<?php echo $i; ?>]"
264 <script type
="text/javascript" language
="javascript">
265 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>');
268 } elseif (strncasecmp($fields_type[$i], 'enum', 4) == 0) {
270 $enum_value=explode(', ', str_replace("'", '', substr($fields_type[$i], 5, -1)));
271 $cnt_enum_value = count($enum_value);
272 echo ' <select name
="fields[' . $i . '][]"'
273 .' multiple
="multiple" size
="' . min(3, $cnt_enum_value) . '">' . "\n";
274 for ($j = 0; $j < $cnt_enum_value; $j++) {
275 echo ' <option value
="' . $enum_value[$j] . '">'
276 . $enum_value[$j] . '</option
>';
278 echo ' </select
>' . "\n";
280 // o t h e r c a s e s
281 echo ' <input type
="text" name
="fields[' . $i . ']"'
282 .' size
="40" class="textfield" id
="field_' . $i . '" />' . "\n";
284 $type = $fields_type[$i];
285 if ($type == 'date
' || $type == 'datetime
' || substr($type, 0, 9) == 'timestamp
') {
287 <script type="text/javascript" language="javascript">
289 document.write('<a title
="<?php echo $strCalendar;?>" href
="javascript:openCalendar(\'<?php echo PMA_generate_common_url();?>\', \'insertForm\', \'field_<?php echo ($i); ?>\', \'<?php echo (PMA_MYSQL_INT_VERSION >= 40100 && substr($type, 0, 9) == 'timestamp') ? 'datetime' : substr($type, 0, 9); ?>\')"><img
class="calendar" src
="<?php echo $pmaThemeImage; ?>b_calendar.png" alt
="<?php echo $strCalendar; ?>"/></a
>');
295 <input type="hidden" name="names[<?php echo $i; ?>]"
296 value="<?php echo htmlspecialchars($fields_list[$i]); ?>" />
297 <input type="hidden" name="types[<?php echo $i; ?>]"
298 value="<?php echo $fields_type[$i]; ?>" />
299 <input type="hidden" name="collations[<?php echo $i; ?>]"
300 value="<?php echo $fields_collation[$i]; ?>" />
309 <fieldset class="tblFooters">
310 <input type="hidden" name="max_number_of_fields"
311 value="<?php echo $fields_cnt; ?>" />
312 <input type="submit" name="submit" value="<?php echo $strGo; ?>" />
316 require_once('./libraries
/footer
.inc
.php
');
321 * Selection criteria have been submitted -> do the work
326 $sql_query = 'SELECT
' . (isset($distinct) ? 'DISTINCT
' : '');
328 // if all fields were selected to display, we do a SELECT *
329 // (more efficient and this helps prevent a problem in IE
330 // if one of the rows is edited and we come back to the Select results)
332 if (count($param) == $max_number_of_fields) {
335 $param = PMA_backquote( $param );
336 $sql_query .= implode( ', ', $param );
340 $sql_query .= ' FROM
' . PMA_backquote($table);
343 if (trim($where) != '') {
344 $sql_query .= ' WHERE
' . $where;
346 $w = $charsets = array();
347 $cnt_func = count($func);
349 while (list($i, $func_type) = each($func)) {
350 if (PMA_MYSQL_INT_VERSION >= 40100) {
351 list($charsets[$i]) = explode('_
', $collations[$i]);
353 if (@$GLOBALS['cfg
']['UnaryOperators
'][$func_type] == 1) {
355 $w[] = PMA_backquote(urldecode($names[$i])) . ' ' . $func_type;
357 } elseif (strncasecmp($types[$i], 'enum
', 4) == 0) {
358 if (!empty($fields[$i])) {
359 if (!is_array($fields[$i])) {
360 $fields[$i] = explode(',', $fields[$i]);
362 $enum_selected_count = count($fields[$i]);
363 if ($func_type == '=' && $enum_selected_count > 1) {
364 $func_type = $func[$i] = 'IN
';
368 } elseif ($func_type == '!=' && $enum_selected_count > 1) {
369 $func_type = $func[$i] = 'NOT IN
';
377 $enum_where = '\'
' . PMA_sqlAddslashes($fields[$i][0]) . '\'
';
378 if (PMA_MYSQL_INT_VERSION >= 40100 && $charsets[$i] != $charset_connection) {
379 $enum_where = 'CONVERT(_utf8
' . $enum_where . ' USING
' . $charsets[$i] . ') COLLATE
' . $collations[$i];
381 for ($e = 1; $e < $enum_selected_count; $e++) {
383 $tmp_literal = '\'
' . PMA_sqlAddslashes($fields[$i][$e]) . '\'
';
384 if (PMA_MYSQL_INT_VERSION >= 40100 && $charsets[$i] != $charset_connection) {
385 $tmp_literal = 'CONVERT(_utf8
' . $tmp_literal . ' USING
' . $charsets[$i] . ') COLLATE
' . $collations[$i];
387 $enum_where .= $tmp_literal;
391 $w[] = PMA_backquote(urldecode($names[$i])) . ' ' . $func_type . ' ' . $parens_open . $enum_where . $parens_close;
394 } elseif ($fields[$i] != '') {
395 // For these types we quote the value. Even if it's another
type (like
INT),
396 // for a LIKE we always quote the value. MySQL converts strings to numbers
397 // and numbers to strings as necessary during the comparison
398 if (preg_match('@char|binary|blob|text|set|date|time|year@i', $types[$i]) ||
strpos(' ' . $func_type, 'LIKE')) {
404 // Make query independant from the selected connection charset.
405 // But if the field's type is VARBINARY, it has no charset
406 // and $charsets[$i] is empty, so we cannot generate a CONVERT
408 if (PMA_MYSQL_INT_VERSION
>= 40101 && !empty($charsets[$i]) && $charsets[$i] != $charset_connection && preg_match('@char|binary|blob|text|set@i', $types[$i])) {
409 $prefix = 'CONVERT(_utf8 ';
410 $suffix = ' USING ' . $charsets[$i] . ') COLLATE ' . $collations[$i];
412 $prefix = $suffix = '';
416 if ($func_type == 'LIKE %...%') {
418 $fields[$i] = '%' . $fields[$i] . '%';
420 $w[] = PMA_backquote(urldecode($names[$i])) . ' ' . $func_type . ' ' . $prefix . $quot . PMA_sqlAddslashes($fields[$i]) . $quot . $suffix;
426 $sql_query .= ' WHERE ' . implode(' AND ', $w);
430 if ($orderField != '--nil--') {
431 $sql_query .= ' ORDER BY ' . PMA_backquote(urldecode($orderField)) . ' ' . $order;
433 include('./sql.php');