3 // vim: expandtab sw=4 ts=4 sts=4:
7 * Gets some core libraries
9 require_once('./libraries/grab_globals.lib.php');
10 require_once('./libraries/common.lib.php');
11 require_once('./libraries/relation.lib.php'); // 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.php
34 * so it can also be used in tbl_qbe.php)
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 require('./tbl_properties_common.php');
47 //$err_url = 'tbl_select.php' . $err_url;
48 $url_query .= '&goto=tbl_select.php&back=tbl_select.php';
49 require('./tbl_properties_table_info.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 $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 = str_replace(',', ', ', $type);
73 $type = preg_replace('@BINARY@i', '', $type);
74 $type = preg_replace('@ZEROFILL@i', '', $type);
75 $type = preg_replace('@UNSIGNED@i', '', $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.php" 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.php" />
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 if (preg_match('@char|blob|text|set|enum@i', $fields_type[$i])) {
140 foreach($textfunctions AS $k => $fc) {
142 . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>';
145 foreach($numfunctions AS $k => $fc) {
147 . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>';
149 } // end if... else...
154 <td bgcolor
="<?php echo $bgcolor; ?>">
157 $field = $fields_list[$i];
159 require('./libraries/get_foreign.lib.php');
162 // we got a bug report: in some cases, even if $disp is true,
163 // there are no rows, so we add a fetch_array
164 if ($foreigners && isset($foreigners[$field]) && isset($disp) && $disp && @PMA_mysql_fetch_array
($disp)) {
165 // f o r e i g n k e y s
166 echo ' <select name="fields[]">' . "\n";
167 // go back to first row
168 mysql_data_seek($disp,0);
169 echo PMA_foreignDropdown($disp, $foreign_field, $foreign_display, $data, 100);
170 echo ' </select>' . "\n";
171 } else if (isset($foreign_link) && $foreign_link == true) {
173 <input type
="text" name
="fields[]" id
="field_<?php echo md5($field); ?>[]" class="textfield" />
174 <script type
="text/javascript" language
="javascript">
175 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); ?>"><?php echo str_replace("'", "\'
", $titles['Browse']); ?></a>');
178 } else if (substr($fields_type[$i], 0, 3)=='enu'){
180 $enum_value=explode(', ', str_replace("'", '', substr($fields_type[$i], 5, -1)));
181 echo ' <select name
="fields[]">' . "\n";
182 echo ' <option value
=""></option
>' . "\n";
183 $cnt_enum_value = count($enum_value);
184 for ($j=0; $j<$cnt_enum_value;$j++){
185 echo ' <option value
="' . $enum_value[$j] . '">' . $enum_value[$j] . '</option
>';
187 echo ' </select
>' . "\n";
189 // o t h e r c a s e s
190 echo ' <input type
="text" name
="fields[]" size
="40" class="textfield" />' . "\n";
194 <input type="hidden" name="names[]" value="<?php echo htmlspecialchars($fields_list[$i]); ?>" />
195 <input type="hidden" name="types[]" value="<?php echo $fields_type[$i]; ?>" />
205 <?php echo $strDisplayOrder; ?><br />
206 <select name="orderField" style="vertical-align: middle">
207 <option value="--nil--"></option>
210 for ($i = 0; $i < $fields_cnt; $i++) {
212 echo '<option value
="' . htmlspecialchars($fields_list[$i]) . '">' . htmlspecialchars($fields_list[$i]) . '</option
>' . "\n";
216 <input type="radio" name="order" value="ASC" checked="checked" />
217 <?php echo $strAscending; ?>
218 <input type="radio" name="order" value="DESC" />
219 <?php echo $strDescending; ?><br /><br />
223
224 <input type="hidden" name="max_number_of_fields" value="<?php echo $fields_cnt; ?>" />
225 <input type="submit" name="submit" value="<?php echo $strGo; ?>" />
229 require_once('./footer
.inc
.php
');
234 * Selection criteria have been submitted -> do the work
239 $sql_query = 'SELECT
';
241 // if all fields were selected to display, we do a SELECT *
242 // (more efficient and this helps prevent a problem in IE
243 // if one of the rows is edited and we come back to the Select results)
245 if (count($param) == $max_number_of_fields) {
249 $sql_query .= PMA_backquote(urldecode($param[0]));
254 $sql_query .= ',' . PMA_backquote(urldecode($param[$i]));
260 $sql_query .= ' FROM
' . PMA_backquote($table);
263 $sql_query .= ' WHERE
' . $where;
266 $sql_query .= ' WHERE
1';
267 $cnt_fields = count($fields);
268 for ($i = 0; $i < $cnt_fields; $i++) {
269 if (!empty($fields) && $fields[$i] != '') {
270 if (preg_match('@char|blob|text|set|enum|date|time|year@i
', $types[$i])) {
275 if (strtoupper($fields[$i]) == 'NULL' || strtoupper($fields[$i]) == 'NOT
NULL') {
279 //$sql_query .= ' AND ' . PMA_backquote(urldecode($names[$i])) . " $func[$i] $quot$fields[$i]$quot";
281 $sql_query .= ' AND ' . PMA_backquote(urldecode($names[$i])) . ' ' . $func[$i] . ' ' . $quot . PMA_sqlAddslashes($fields[$i]) . $quot;
287 if ($orderField != '--nil
--') {
288 $sql_query .= ' ORDER BY
' . PMA_backquote(urldecode($orderField)) . ' ' . $order;
291 include('./sql
.php
');