3 // vim: expandtab sw=4 ts=4 sts=4:
7 * Gets some core libraries
9 require('./libraries/grab_globals.lib.php3');
10 require('./libraries/common.lib.php3');
11 require('./libraries/relation.lib.php3'); // foreign keys
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 = '<nobr>';
23 $titles['Browse'] = $iconic_spacer . '<img width="12" height="13" src="images/button_browse.png" alt="' . $strBrowseForeignValues . '" title="' . $strBrowseForeignValues . '" border="0" />';
25 if ($propicon == 'both') {
26 $titles['Browse'] .= ' ' . $strBrowseForeignValues . '</nobr>';
29 $titles['Browse'] = $strBrowseForeignValues;
33 * Defines arrays of functions (should possibly be in config.inc.php3
34 * so it can also be used in tbl_qbe.php3)
36 * LIKE works also on integers and dates so I added it in numfunctions
38 $numfunctions = array('=', '>', '>=', '<', '<=', '!=', 'LIKE');
39 $textfunctions = array('LIKE', '=', '!=');
42 * Not selection yet required -> displays the selection form
44 if (!isset($param) ||
$param[0] == '') {
45 // Gets some core libraries
46 include('./tbl_properties_common.php3');
47 //$err_url = 'tbl_select.php3' . $err_url;
48 $url_query .= '&goto=tbl_select.php3&back=tbl_select.php3';
49 include('./tbl_properties_table_info.php3');
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 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
59 $result = @PMA_mysql_query
($local_query);
61 PMA_mysqlDie('', $local_query, '', $err_url);
64 $fields_cnt = mysql_num_rows($result);
65 while ($row = PMA_mysql_fetch_array($result)) {
66 $fields_list[] = $row['Field'];
68 // reformat mysql query output - staybyte - 9. June 2001
69 $shorttype = substr($type, 0, 3);
70 if ($shorttype == 'set' ||
$shorttype == 'enu') {
71 $type = eregi_replace(',', ', ', $type);
73 $type = eregi_replace('BINARY', '', $type);
74 $type = eregi_replace('ZEROFILL', '', $type);
75 $type = eregi_replace('UNSIGNED', '', $type);
80 $fields_type[] = $type;
82 mysql_free_result($result);
85 // retrieve keys into foreign fields, if any
86 $cfgRelation = PMA_getRelationsParam();
87 // check also foreigners even if relwork is FALSE (to get
88 // foreign keys from innodb)
89 //$foreigners = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE);
90 $foreigners = PMA_getForeigners($db, $table);
92 <form method
="post" action
="tbl_select.php3" name
="insertForm">
93 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
94 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
95 <input type
="hidden" name
="back" value
="tbl_select.php3" />
96  
; 
; 
; 
; 
;
97 <?php
echo $strSelectFields; ?
> 
;:<br
/>
98  
; 
; 
; 
; 
;
99 <select name
="param[]" size
="<?php echo ($fields_cnt < 10) ? $fields_cnt : 10; ?>" multiple
="multiple">
102 // Displays the list of the fields
103 for ($i = 0 ; $i < $fields_cnt; $i++
) {
104 echo ' <option value="' . htmlspecialchars($fields_list[$i]) . '" selected="selected">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n";
110 <div style
="margin-bottom: 10px">
111 <?php
echo $strLimitNumRows . "\n"; ?
>
112 <input type
="text" size
="4" name
="session_max_rows" value
="<?php echo $cfg['MaxRows']; ?>" class="textfield" />
116 <?php
echo $strAddSearchConditions; ?
><br
/>
117 <input type
="text" name
="where" class="textfield" /> 
;
118 <?php
echo PMA_showMySQLDocu('Reference', 'Functions') . "\n"; ?
>
120 <?php
echo '<i>' . $strOr . '</i> ' . $strDoAQuery; ?
><br
/>
121 <table border
="<?php echo $cfg['Border']; ?>">
123 <th
><?php
echo $strField; ?
></th
>
124 <th
><?php
echo $strType; ?
></th
>
125 <th
><?php
echo $strFunction; ?
></th
>
126 <th
><?php
echo $strValue; ?
></th
>
129 for ($i = 0; $i < $fields_cnt; $i++
) {
131 $bgcolor = ($i %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
134 <td bgcolor
="<?php echo $bgcolor; ?>"><?php
echo htmlspecialchars($fields_list[$i]); ?
></td
>
135 <td bgcolor
="<?php echo $bgcolor; ?>"><?php
echo $fields_type[$i]; ?
></td
>
136 <td bgcolor
="<?php echo $bgcolor; ?>">
137 <select name
="func[]">
139 reset($numfunctions);
140 reset($textfunctions);
141 if (eregi('char|blob|text|set|enum', $fields_type[$i])) {
142 while (list($k, $fc) = each($textfunctions)) {
144 . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>';
147 while (list($k, $fc) = each($numfunctions)) {
149 . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>';
151 } // end if... else...
156 <td bgcolor
="<?php echo $bgcolor; ?>">
159 $field = $fields_list[$i];
161 include('./libraries/get_foreign.lib.php3');
164 // we got a bug report: in some cases, even if $disp is true,
165 // there are no rows, so we add a fetch_array
166 if ($foreigners && isset($foreigners[$field]) && isset($disp) && $disp && @PMA_mysql_fetch_array
($disp)) {
167 // f o r e i g n k e y s
168 echo ' <select name="fields[]">' . "\n";
169 // go back to first row
170 mysql_data_seek($disp,0);
171 echo PMA_foreignDropdown($disp, $foreign_field, $foreign_display, $data, 100);
172 echo ' </select>' . "\n";
173 } else if (isset($foreign_link) && $foreign_link == true) {
175 <input type
="text" name
="fields[]" id
="field_<?php echo md5($field); ?>[]" class="textfield" />
176 <script type
="text/javascript" language
="javascript">
177 document
.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes\'); return false" href="browse_foreigners.php3?<?php echo PMA_generate_common_url($db, $table); ?>&field=<?php echo urlencode($field); ?>"><?php echo str_replace("'", "\'
", $titles['Browse']); ?></a>');
180 } else if (substr($fields_type[$i], 0, 3)=='enu'){
182 $enum_value=explode(", ",str_replace("'", "", substr($fields_type[$i], 5, -1)));
183 echo ' <select name
="fields[]">' . "\n";
184 echo ' <option value
=""></option
>' . "\n";
185 for ($j=0; $j<count($enum_value);$j++){
186 echo ' <option value
="' . $enum_value[$j] . '">' . $enum_value[$j] . '</option
>';
188 echo ' </select
>' . "\n";
190 // o t h e r c a s e s
191 echo ' <input type
="text" name
="fields[]" size
="40" class="textfield" />' . "\n";
195 <input type="hidden" name="names[]" value="<?php echo htmlspecialchars($fields_list[$i]); ?>" />
196 <input type="hidden" name="types[]" value="<?php echo $fields_type[$i]; ?>" />
206 <?php echo $strDisplayOrder; ?><br />
207 <select name="orderField" style="vertical-align: middle">
208 <option value="--nil--"></option>
211 for ($i = 0; $i < $fields_cnt; $i++) {
213 echo '<option value
="' . htmlspecialchars($fields_list[$i]) . '">' . htmlspecialchars($fields_list[$i]) . '</option
>' . "\n";
217 <input type="radio" name="order" value="ASC" checked="checked" />
218 <?php echo $strAscending; ?>
219 <input type="radio" name="order" value="DESC" />
220 <?php echo $strDescending; ?><br /><br />
224
225 <input type="hidden" name="max_number_of_fields" value="<?php echo $fields_cnt; ?>" />
226 <input type="submit" name="submit" value="<?php echo $strGo; ?>" />
231 include('./footer
.inc
.php3
');
236 * Selection criteria have been submitted -> do the work
241 $sql_query = 'SELECT
';
243 // if all fields were selected to display, we do a SELECT *
244 // (more efficient and this helps prevent a problem in IE
245 // if one of the rows is edited and we come back to the Select results)
247 if (count($param) == $max_number_of_fields) {
251 $sql_query .= PMA_backquote(urldecode($param[0]));
256 $sql_query .= ',' . PMA_backquote(urldecode($param[$i]));
262 $sql_query .= ' FROM
' . PMA_backquote($table);
265 $sql_query .= ' WHERE
' . $where;
268 $sql_query .= ' WHERE
1';
269 for ($i = 0; $i < count($fields); $i++) {
270 if (!empty($fields) && $fields[$i] != '') {
271 if (eregi('char|blob|text|set|enum|date|time|year
', $types[$i])) {
276 if (strtoupper($fields[$i]) == 'NULL' || strtoupper($fields[$i]) == 'NOT
NULL') {
280 $sql_query .= ' AND ' . PMA_backquote(urldecode($names[$i])) . " $func[$i] $quot$fields[$i]$quot";
285 if ($orderField != '--nil
--') {
286 $sql_query .= ' ORDER BY
' . PMA_backquote(urldecode($orderField)) . ' ' . $order;
289 include('./sql
.php3
');