InnoDB in Relation view
[phpmyadmin/crack.git] / tbl_select.php3
blob8ce9129eb1128e44a794af7cd64de3c80236d9a0
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
6 /**
7 * Gets some core libraries
8 */
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>';
19 } else {
20 $iconic_spacer = '';
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'] .= '&nbsp;' . $strBrowseForeignValues . '</nobr>';
28 } else {
29 $titles['Browse'] = $strBrowseForeignValues;
32 /**
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', '=', '!=');
41 /**
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 .= '&amp;goto=tbl_select.php3&amp;back=tbl_select.php3';
49 include('./tbl_properties_table_info.php3');
51 if (!isset($goto)) {
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);
60 if (!$result) {
61 PMA_mysqlDie('', $local_query, '', $err_url);
63 else {
64 $fields_cnt = mysql_num_rows($result);
65 while ($row = PMA_mysql_fetch_array($result)) {
66 $fields_list[] = $row['Field'];
67 $type = $row['Type'];
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);
72 } else {
73 $type = eregi_replace('BINARY', '', $type);
74 $type = eregi_replace('ZEROFILL', '', $type);
75 $type = eregi_replace('UNSIGNED', '', $type);
77 if (empty($type)) {
78 $type = '&nbsp;';
80 $fields_type[] = $type;
81 } // end while
82 mysql_free_result($result);
84 // <markus@noga.de>
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 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
97 <?php echo $strSelectFields; ?>&nbsp;:<br />
98 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
99 <select name="param[]" size="<?php echo ($fields_cnt < 10) ? $fields_cnt : 10; ?>" multiple="multiple">
100 <?php
101 echo "\n";
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";
107 </select><br />
108 <ul>
109 <li>
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" />
113 </div>
114 </li>
115 <li>
116 <?php echo $strAddSearchConditions; ?><br />
117 <input type="text" name="where" class="textfield" />&nbsp;
118 <?php echo PMA_showMySQLDocu('Reference', 'Functions') . "\n"; ?>
119 <br /><br />
120 <?php echo '<i>' . $strOr . '</i> ' . $strDoAQuery; ?><br />
121 <table border="<?php echo $cfg['Border']; ?>">
122 <tr>
123 <th><?php echo $strField; ?></th>
124 <th><?php echo $strType; ?></th>
125 <th><?php echo $strFunction; ?></th>
126 <th><?php echo $strValue; ?></th>
127 </tr>
128 <?php
129 for ($i = 0; $i < $fields_cnt; $i++) {
130 echo "\n";
131 $bgcolor = ($i % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
133 <tr>
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[]">
138 <?php
139 reset($numfunctions);
140 reset($textfunctions);
141 if (eregi('char|blob|text|set|enum', $fields_type[$i])) {
142 while (list($k, $fc) = each($textfunctions)) {
143 echo "\n" . ' '
144 . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>';
145 } // end while
146 } else {
147 while (list($k, $fc) = each($numfunctions)) {
148 echo "\n" . ' '
149 . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>';
150 } // end while
151 } // end if... else...
152 echo "\n";
154 </select>
155 </td>
156 <td bgcolor="<?php echo $bgcolor; ?>">
157 <?php
158 // <markus@noga.de>
159 $field = $fields_list[$i];
161 include('./libraries/get_foreign.lib.php3');
163 echo "\n";
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); ?>&amp;field=<?php echo urlencode($field); ?>"><?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
178 </script>
179 <?php
180 } else if (substr($fields_type[$i], 0, 3)=='enu'){
181 // e n u m s
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>';
187 } // end for
188 echo ' </select>' . "\n";
189 } else {
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]; ?>" />
197 </td>
198 </tr>
199 <?php
200 } // end for
201 echo "\n";
203 </table><br />
204 </li>
205 <li>
206 <?php echo $strDisplayOrder; ?><br />
207 <select name="orderField" style="vertical-align: middle">
208 <option value="--nil--"></option>
209 <?php
210 echo "\n";
211 for ($i = 0; $i < $fields_cnt; $i++) {
212 echo ' ';
213 echo '<option value="' . htmlspecialchars($fields_list[$i]) . '">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n";
214 } // end for
216 </select>
217 <input type="radio" name="order" value="ASC" checked="checked" />
218 <?php echo $strAscending; ?>&nbsp;
219 <input type="radio" name="order" value="DESC" />
220 <?php echo $strDescending; ?><br /><br />
221 </li>
222 </ul>
224 &nbsp;&nbsp;&nbsp;&nbsp;
225 <input type="hidden" name="max_number_of_fields" value="<?php echo $fields_cnt; ?>" />
226 <input type="submit" name="submit" value="<?php echo $strGo; ?>" />
227 </form>
228 <?php
229 } // end if
230 echo "\n";
231 include('./footer.inc.php3');
236 * Selection criteria have been submitted -> do the work
238 else {
239 // Builds the query
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) {
248 $sql_query .= '* ';
249 } else {
251 $sql_query .= PMA_backquote(urldecode($param[0]));
252 $i = 0;
253 $c = count($param);
254 while ($i < $c) {
255 if ($i > 0) {
256 $sql_query .= ',' . PMA_backquote(urldecode($param[$i]));
258 $i++;
260 } // end if
262 $sql_query .= ' FROM ' . PMA_backquote($table);
263 // The where clause
264 if ($where != '') {
265 $sql_query .= ' WHERE ' . $where;
267 else {
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])) {
272 $quot = '\'';
273 } else {
274 $quot = '';
276 if (strtoupper($fields[$i]) == 'NULL' || strtoupper($fields[$i]) == 'NOT NULL') {
277 $quot = '';
278 $func[$i] = 'IS';
280 $sql_query .= ' AND ' . PMA_backquote(urldecode($names[$i])) . " $func[$i] $quot$fields[$i]$quot";
281 } // end if
282 } // end for
283 } // end if
285 if ($orderField != '--nil--') {
286 $sql_query .= ' ORDER BY ' . PMA_backquote(urldecode($orderField)) . ' ' . $order;
287 } // end if
289 include('./sql.php3');