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 ($cfg['PropertiesIconic'] == true) {
14 // We need to copy the value or else the == 'both' check will always return true
15 $propicon = (string)$cfg['PropertiesIconic'];
17 if ($propicon == 'both') {
18 $iconic_spacer = '<div class="nowrap">';
23 $titles['Browse'] = $iconic_spacer . '<img width="16" height="16" src="' . $pmaThemeImage . 'b_browse.png" alt="' . $strBrowseForeignValues . '" title="' . $strBrowseForeignValues . '" border="0" />';
25 if ($propicon == 'both') {
26 $titles['Browse'] .= ' ' . $strBrowseForeignValues . '</div>';
29 $titles['Browse'] = $strBrowseForeignValues;
33 * Not selection yet required -> displays the selection form
35 if (!isset($param) ||
$param[0] == '') {
36 // Gets some core libraries
37 require_once('./tbl_properties_common.php');
38 //$err_url = 'tbl_select.php' . $err_url;
39 $url_query .= '&goto=tbl_select.php&back=tbl_select.php';
42 * Gets tables informations
44 require_once('./tbl_properties_table_info.php');
47 * Displays top menu links
49 require_once('./tbl_properties_links.php');
52 $goto = $cfg['DefaultTabTable'];
54 // Defines the url to return to in case of error in the next sql statement
55 $err_url = $goto . '?' . PMA_generate_common_url($db, $table);
57 // Gets the list and number of fields
58 $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
);
59 $fields_cnt = PMA_DBI_num_rows($result);
60 // rabue: we'd better ensure, that all arrays are empty.
61 $fields_list = $fields_null = $fields_type = $fields_collation = array();
62 while ($row = PMA_DBI_fetch_assoc($result)) {
63 $fields_list[] = $row['Field'];
65 // reformat mysql query output - staybyte - 9. June 2001
66 if (strncasecmp($type, 'set', 3) == 0
67 ||
strncasecmp($type, 'enum', 4) == 0) {
68 $type = str_replace(',', ', ', $type);
71 // strip the "BINARY" attribute, except if we find "BINARY(" because
72 // this would be a BINARY or VARBINARY field type
73 if (!preg_match('@BINARY[\(]@i', $type)) {
74 $type = preg_replace('@BINARY@i', '', $type);
76 $type = preg_replace('@ZEROFILL@i', '', $type);
77 $type = preg_replace('@UNSIGNED@i', '', $type);
79 $type = strtolower($type);
84 $fields_null[] = $row['Null'];
85 $fields_type[] = $type;
86 $fields_collation[] = PMA_MYSQL_INT_VERSION
>= 40100 && !empty($row['Collation']) && $row['Collation'] != 'NULL'
90 PMA_DBI_free_result($result);
91 unset($result, $type);
94 // retrieve keys into foreign fields, if any
95 $cfgRelation = PMA_getRelationsParam();
96 // check also foreigners even if relwork is FALSE (to get
97 // foreign keys from innodb)
98 //$foreigners = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE);
99 $foreigners = PMA_getForeigners($db, $table);
101 <script language
="JavaScript" type
="text/javascript">
103 function PMA_tbl_select_operator(f
, index
, multiple
) {
104 switch (f
.elements
["func[" + index +
"]"].options
[f
.elements
["func[" + index +
"]"].selectedIndex
].value
) {
106 reset($GLOBALS['cfg']['UnaryOperators']);
107 while (list($operator) = each($GLOBALS['cfg']['UnaryOperators'])) {
108 echo ' case "' . $operator . "\":\r\n";
117 f
.elements
["fields[" + index +
"]" +
((multiple
) ?
"[]": "")].disabled
= bDisabled
;
121 <form method
="post" action
="tbl_select.php" name
="insertForm">
122 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
123 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
124 <input type
="hidden" name
="back" value
="tbl_select.php" />
125 <table border
="0" cellpadding
="0" cellspacing
="0">
128 <table border
="0" cellpadding
="3" cellspacing
="0">
130 <th align
="left" colspan
="2">
131 <?php
echo $strSelectFields; ?
>
135 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
136 <select name
="param[]" size
="<?php echo min($fields_cnt, 10); ?>" multiple
="multiple" align
="left">
139 // Displays the list of the fields
140 for ($i = 0 ; $i < $fields_cnt; $i++
) {
142 . '<option value="' . htmlspecialchars($fields_list[$i]) . '" selected="selected">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n";
147 <td valign
="bottom" bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
148 <input type
="checkbox" name
="distinct" value
="DISTINCT" id
="oDistinct" /><label
for="oDistinct">DISTINCT
</label
>
153 <td nowrap
="nowrap" width
="50"> 
;</td
>
155 <table border
="0" cellpadding
="3" cellspacing
="0">
158 <?php
echo $strLimitNumRows . "\n"; ?
>:
162 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
163 <input type
="text" size
="4" name
="session_max_rows" value
="<?php echo $cfg['MaxRows']; ?>" class="textfield" />
171 <?php
echo $strDisplayOrder; ?
>
175 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
176 <select name
="orderField" style
="vertical-align: middle">
177 <option value
="--nil--"></option
>
180 for ($i = 0; $i < $fields_cnt; $i++
) {
182 echo '<option value="' . htmlspecialchars($fields_list[$i]) . '">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n";
186 <input type
="radio" name
="order" value
="ASC" checked
="checked" id
="sortASC" /><label
for="sortASC"><?php
echo $strAscending; ?
></label
><br
/>
187 <input type
="radio" name
="order" value
="DESC" id
="sortDESC" /><label
for="sortDESC"><?php
echo $strDescending; ?
></label
>
194 <table border
="0" cellpadding
="3" cellspacing
="0">
196 <td colspan
="2"> 
;</td
>
199 <th align
="left" class="tblHeaders" colspan
="2">
200 <?php
echo $strAddSearchConditions; ?
>
201 <?php
echo PMA_showMySQLDocu('SQL-Syntax', 'Functions') . "\n"; ?
>
206 <input type
="text" name
="where" class="textfield" size
="64" />
209 <input type
="submit" name
="submit" value
="<?php echo $strGo; ?>" />
213 <td colspan
="2"> 
;</td
>
216 <th align
="left" class="tblHeaders" colspan
="2">
217 <?php
echo '<i>' . $strOr . '</i> ' . $strDoAQuery; ?
>
222 <table border
="<?php echo $cfg['Border']; ?>" cellpadding
="2" cellspacing
="1">
224 <th
><?php
echo $strField; ?
></th
>
225 <th
><?php
echo $strType; ?
></th
>
226 <?php
echo PMA_MYSQL_INT_VERSION
>= 40100 ?
'<th>' . $strCollation . '</th>' . "\n" : ''; ?
>
227 <th
><?php
echo $strOperator; ?
></th
>
228 <th
><?php
echo $strValue; ?
></th
>
231 for ($i = 0; $i < $fields_cnt; $i++
) {
233 $bgcolor = ($i %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
236 <td bgcolor
="<?php echo $bgcolor; ?>"><b
><?php
echo htmlspecialchars($fields_list[$i]); ?
></b
></td
>
237 <td bgcolor
="<?php echo $bgcolor; ?>"><?php
echo $fields_type[$i]; ?
></td
>
238 <?php
echo PMA_MYSQL_INT_VERSION
>= 40100 ?
'<td bgcolor="' . $bgcolor . '">' . $fields_collation[$i] . '</td>' . "\n" : ''; ?
>
239 <td bgcolor
="<?php echo $bgcolor; ?>">
240 <select name
="func[]">
242 if (strncasecmp($fields_type[$i], 'enum', 4) == 0) {
243 foreach ($GLOBALS['cfg']['EnumOperators'] as $k => $fc) {
245 . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>';
247 } elseif (preg_match('@char|blob|text|set@i', $fields_type[$i])) {
248 foreach ($GLOBALS['cfg']['TextOperators'] as $k => $fc) {
250 . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>';
253 foreach ($GLOBALS['cfg']['NumOperators'] as $k => $fc) {
255 . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>';
257 } // end if... else...
258 if ($fields_null[$i]) {
259 foreach ($GLOBALS['cfg']['NullOperators'] as $k => $fc) {
261 . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>';
268 <td bgcolor
="<?php echo $bgcolor; ?>">
271 $field = $fields_list[$i];
273 // do not use require_once here
274 require('./libraries/get_foreign.lib.php');
277 // we got a bug report: in some cases, even if $disp is true,
278 // there are no rows, so we add a fetch_array
280 if ($foreigners && isset($foreigners[$field]) && isset($disp_row) && is_array($disp_row)) {
281 // f o r e i g n k e y s
282 echo ' <select name="fields[' . $i . ']">' . "\n";
283 // go back to first row
285 // here, the 4th parameter is empty because there is no current
286 // value of data for the dropdown (the search page initial values
287 // are displayed empty)
288 echo PMA_foreignDropdown($disp_row, $foreign_field, $foreign_display, '', $cfg['ForeignKeyMaxLimit']);
289 echo ' </select>' . "\n";
290 } else if (isset($foreign_link) && $foreign_link == true) {
292 <input type
="text" name
="fields[<?php echo $i; ?>]" id
="field_<?php echo md5($field); ?>[<?php echo $i; ?>]" class="textfield" />
293 <script type
="text/javascript" language
="javascript">
294 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>');
297 } else if (strncasecmp($fields_type[$i], 'enum', 4) == 0) {
299 $enum_value=explode(', ', str_replace("'", '', substr($fields_type[$i], 5, -1)));
300 $cnt_enum_value = count($enum_value);
301 echo ' <select name
="fields[' . $i . '][]" multiple
="multiple" size
="' . min(3, $cnt_enum_value) . '">' . "\n";
302 for ($j = 0; $j < $cnt_enum_value; $j++) {
303 echo ' <option value
="' . $enum_value[$j] . '">' . $enum_value[$j] . '</option
>';
305 echo ' </select
>' . "\n";
307 // o t h e r c a s e s
308 echo ' <input type
="text" name
="fields[' . $i . ']" size
="40" class="textfield" />' . "\n";
312 <input type="hidden" name="names[<?php echo $i; ?>]" value="<?php echo htmlspecialchars($fields_list[$i]); ?>" />
313 <input type="hidden" name="types[<?php echo $i; ?>]" value="<?php echo $fields_type[$i]; ?>" />
314 <input type="hidden" name="collations[<?php echo $i; ?>]" value="<?php echo $fields_collation[$i]; ?>" />
325 <td nowrap="nowrap" colspan="2" align="right">
326 <input type="hidden" name="max_number_of_fields" value="<?php echo $fields_cnt; ?>" />
327 <input type="submit" name="submit" value="<?php echo $strGo; ?>" />
333 require_once('./footer
.inc
.php
');
338 * Selection criteria have been submitted -> do the work
343 $sql_query = 'SELECT
' . (isset($distinct) ? 'DISTINCT
' : '');
345 // if all fields were selected to display, we do a SELECT *
346 // (more efficient and this helps prevent a problem in IE
347 // if one of the rows is edited and we come back to the Select results)
349 if (count($param) == $max_number_of_fields) {
353 $sql_query .= PMA_backquote(urldecode($param[0]));
355 for ($i = 1; $i < $c; $i++) {
356 $sql_query .= ',' . PMA_backquote(urldecode($param[$i]));
360 $sql_query .= ' FROM
' . PMA_backquote($table);
363 if (trim($where) != '') {
364 $sql_query .= ' WHERE
' . $where;
366 $w = $charsets = array();
367 $cnt_func = count($func);
369 while (list($i, $func_type) = each($func)) {
370 if (PMA_MYSQL_INT_VERSION >= 40100) {
371 list($charsets[$i]) = explode('_
', $collations[$i]);
373 if (@$GLOBALS['cfg
']['UnaryOperators
'][$func_type] == 1) {
375 $w[] = PMA_backquote(urldecode($names[$i])) . ' ' . $func_type;
377 } elseif (strncasecmp($types[$i], 'enum
', 4) == 0) {
378 if (!empty($fields[$i])) {
379 if (!is_array($fields[$i])) {
380 $fields[$i] = explode(',', $fields[$i]);
382 $enum_selected_count = count($fields[$i]);
383 if ($func_type == '=' && $enum_selected_count > 1) {
384 $func_type = $func[$i] = 'IN
';
388 } elseif ($func_type == '!=' && $enum_selected_count > 1) {
389 $func_type = $func[$i] = 'NOT IN
';
397 $enum_where = '\'
' . PMA_sqlAddslashes($fields[$i][0]) . '\'
';
398 if (PMA_MYSQL_INT_VERSION >= 40100 && $charsets[$i] != $charset_connection) {
399 $enum_where = 'CONVERT(_utf8
' . $enum_where . ' USING
' . $charsets[$i] . ') COLLATE
' . $collations[$i];
401 for ($e = 1; $e < $enum_selected_count; $e++) {
403 $tmp_literal = '\'
' . PMA_sqlAddslashes($fields[$i][$e]) . '\'
';
404 if (PMA_MYSQL_INT_VERSION >= 40100 && $charsets[$i] != $charset_connection) {
405 $tmp_literal = 'CONVERT(_utf8
' . $tmp_literal . ' USING
' . $charsets[$i] . ') COLLATE
' . $collations[$i];
407 $enum_where .= $tmp_literal;
411 $w[] = PMA_backquote(urldecode($names[$i])) . ' ' . $func_type . ' ' . $parens_open . $enum_where . $parens_close;
414 } elseif ($fields[$i] != '') {
415 if (preg_match('@char|binary|blob|text|set|date|time|year@i
', $types[$i])) {
421 // Make query independant from the selected connection charset.
422 // But if the field's type is VARBINARY
, it has no charset
423 // and $charsets[$i] is empty, so we cannot generate a CONVERT
425 if (PMA_MYSQL_INT_VERSION
>= 40101 && !empty($charsets[$i]) && $charsets[$i] != $charset_connection && preg_match('@char|binary|blob|text|set@i', $types[$i])) {
426 $prefix = 'CONVERT(_utf8 ';
427 $suffix = ' USING ' . $charsets[$i] . ') COLLATE ' . $collations[$i];
429 $prefix = $suffix = '';
433 if ($func_type == 'LIKE %...%') {
435 $fields[$i] = '%' . $fields[$i] . '%';
437 $w[] = PMA_backquote(urldecode($names[$i])) . ' ' . $func_type . ' ' . $prefix . $quot . PMA_sqlAddslashes($fields[$i]) . $quot . $suffix;
443 $sql_query .= ' WHERE ' . implode(' AND ', $w);
447 if ($orderField != '--nil--') {
448 $sql_query .= ' ORDER BY ' . PMA_backquote(urldecode($orderField)) . ' ' . $order;
450 include('./sql.php');