typo
[phpmyadmin/crack.git] / tbl_select.php3
blob616d535da569d26cb52cc93033687589d38cf5f0
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
14 /**
15 * Defines arrays of functions (should possibly be in config.inc.php3
16 * so it can also be used in tbl_qbe.php3)
18 $numfunctions = array('=', '>', '>=', '<', '<=', '!=');
19 $textfunctions = array('LIKE', '=', '!=');
22 /**
23 * Not selection yet required -> displays the selection form
25 if (!isset($param) || $param[0] == '') {
26 // Gets some core libraries
27 include('./tbl_properties_common.php3');
28 $err_url = 'tbl_select.php3' . $err_url;
29 $url_query .= '&amp;goto=tbl_select.php3&amp;back=tbl_select.php3';
30 include('./tbl_properties_table_info.php3');
32 // Defines the url to return to in case of error in the next sql statement
33 $err_url = $goto
34 . '?lang=' . $lang
35 . '&amp;convcharset=' . $convcharset
36 . '&amp;server=' . $server
37 . '&amp;db=' . urlencode($db)
38 . '&amp;table=' . urlencode($table);
40 // Gets the list and number of fields
41 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
42 $result = @PMA_mysql_query($local_query);
43 if (!$result) {
44 PMA_mysqlDie('', $local_query, '', $err_url);
46 else {
47 $fields_cnt = mysql_num_rows($result);
48 while ($row = PMA_mysql_fetch_array($result)) {
49 $fields_list[] = $row['Field'];
50 $type = $row['Type'];
51 // reformat mysql query output - staybyte - 9. June 2001
52 $shorttype = substr($type, 0, 3);
53 if ($shorttype == 'set' || $shorttype == 'enu') {
54 $type = eregi_replace(',', ', ', $type);
55 // Removes automatic MySQL escape format
56 $type = str_replace('\'\'', '\\\'', $type);
58 $type = eregi_replace('BINARY', '', $type);
59 $type = eregi_replace('ZEROFILL', '', $type);
60 $type = eregi_replace('UNSIGNED', '', $type);
61 if (empty($type)) {
62 $type = '&nbsp;';
64 $fields_type[] = $type;
65 } // end while
66 mysql_free_result($result);
68 // <markus@noga.de>
69 // retrieve keys into foreign fields, if any
70 $cfgRelation = PMA_getRelationsParam();
71 $foreigners = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE);
73 <form method="post" action="tbl_select.php3">
74 <input type="hidden" name="server" value="<?php echo $server; ?>" />
75 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
76 <input type="hidden" name="convcharset" value="<?php echo $convcharset; ?>" />
77 <input type="hidden" name="db" value="<?php echo $db; ?>" />
78 <input type="hidden" name="table" value="<?php echo $table; ?>" />
79 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
80 <input type="hidden" name="back" value="tbl_select.php3" />
81 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
82 <?php echo $strSelectFields; ?>&nbsp;:<br />
83 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
84 <select name="param[]" size="<?php echo ($fields_cnt < 10) ? $fields_cnt : 10; ?>" multiple="multiple">
85 <?php
86 echo "\n";
87 // Displays the list of the fields
88 for ($i = 0 ; $i < $fields_cnt; $i++) {
89 echo ' <option value="' . urlencode($fields_list[$i]) . '" selected="selected">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n";
92 </select><br />
93 <ul>
94 <li>
95 <div style="margin-bottom: 10px">
96 <?php echo $strLimitNumRows . "\n"; ?>
97 <input type="text" size="4" name="session_max_rows" value="<?php echo $cfg['MaxRows']; ?>" class="textfield" />
98 </div>
99 </li>
100 <li>
101 <?php echo $strAddSearchConditions; ?><br />
102 <input type="text" name="where" class="textfield" />&nbsp;
103 <?php echo PMA_showMySQLDocu('Reference', 'Functions') . "\n"; ?>
104 <br /><br />
105 <?php echo '<i>' . $strOr . '</i> ' . $strDoAQuery; ?><br />
106 <table border="<?php echo $cfg['Border']; ?>">
107 <tr>
108 <th><?php echo $strField; ?></th>
109 <th><?php echo $strType; ?></th>
110 <th><?php echo $strFunction; ?></th>
111 <th><?php echo $strValue; ?></th>
112 </tr>
113 <?php
114 for ($i = 0; $i < $fields_cnt; $i++) {
115 echo "\n";
116 $bgcolor = ($i % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
118 <tr>
119 <td bgcolor="<?php echo $bgcolor; ?>"><?php echo htmlspecialchars($fields_list[$i]); ?></td>
120 <td bgcolor="<?php echo $bgcolor; ?>"><?php echo $fields_type[$i]; ?></td>
121 <td bgcolor="<?php echo $bgcolor; ?>">
122 <select name="func[]">
123 <?php
124 reset($numfunctions);
125 reset($textfunctions);
126 if (eregi('char|blob|text|set|enum', $fields_type[$i])) {
127 while (list($k, $fc) = each($textfunctions)) {
128 echo "\n" . ' '
129 . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>';
130 } // end while
131 } else {
132 while (list($k, $fc) = each($numfunctions)) {
133 echo "\n" . ' '
134 . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>';
135 } // end while
136 } // end if... else...
137 echo "\n";
139 </select>
140 </td>
141 <td bgcolor="<?php echo $bgcolor; ?>">
142 <?php
143 // <markus@noga.de>
144 $field = $fields_list[$i];
146 include('./libraries/get_foreign.lib.php3');
148 echo "\n";
149 if ($foreigners && isset($foreigners[$field]) && isset($disp) && $disp) {
150 echo ' <select name="fields[]">' . "\n";
151 echo ' <option value=""></option>' . "\n";
152 while ($relrow = @PMA_mysql_fetch_array($disp)) {
153 $key = $relrow[$foreign_field];
154 $value = (($foreign_display != FALSE) ? '-' . htmlspecialchars($relrow[$foreign_display]) : '');
155 echo ' <option value="' . urlencode($key) . '">'
156 . htmlspecialchars($key) . $value . '</option>' . "\n";
157 } // end while
158 echo ' </select>' . "\n";
159 } else {
160 echo ' <input type="text" name="fields[]" size="40" class="textfield" />' . "\n";
163 <input type="hidden" name="names[]" value="<?php echo urlencode($fields_list[$i]); ?>" />
164 <input type="hidden" name="types[]" value="<?php echo $fields_type[$i]; ?>" />
165 </td>
166 </tr>
167 <?php
168 } // end for
169 echo "\n";
171 </table><br />
172 </li>
173 <li>
174 <?php echo $strDisplayOrder; ?><br />
175 <select name="orderField" style="vertical-align: middle">
176 <option value="--nil--"></option>
177 <?php
178 echo "\n";
179 for ($i = 0; $i < $fields_cnt; $i++) {
180 echo ' ';
181 echo '<option value="' . urlencode($fields_list[$i]) . '">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n";
182 } // end for
184 </select>
185 <input type="radio" name="order" value="ASC" checked="checked" />
186 <?php echo $strAscending; ?>&nbsp;
187 <input type="radio" name="order" value="DESC" />
188 <?php echo $strDescending; ?><br /><br />
189 </li>
190 </ul>
192 &nbsp;&nbsp;&nbsp;&nbsp;
193 <input type="submit" name="submit" value="<?php echo $strGo; ?>" />
194 </form>
195 <?php
196 } // end if
197 echo "\n";
198 include('./footer.inc.php3');
203 * Selection criteria have been submitted -> do the work
205 else {
206 // Builds the query
207 $sql_query = 'SELECT ' . PMA_backquote(urldecode($param[0]));
208 $i = 0;
209 $c = count($param);
210 while ($i < $c) {
211 if ($i > 0) {
212 $sql_query .= ',' . PMA_backquote(urldecode($param[$i]));
214 $i++;
216 $sql_query .= ' FROM ' . PMA_backquote($table);
217 // The where clause
218 if ($where != '') {
219 $sql_query .= ' WHERE ' . ((get_magic_quotes_gpc()) ? stripslashes($where) : $where);
221 else {
222 $sql_query .= ' WHERE 1';
223 for ($i = 0; $i < count($fields); $i++) {
224 if (!empty($fields) && $fields[$i] != '') {
225 if (eregi('char|blob|text|set|enum|date|time|year', $types[$i])) {
226 $quot = '\'';
227 } else {
228 $quot = '';
230 if (strtoupper($fields[$i]) == 'NULL' || strtoupper($fields[$i]) == 'NOT NULL') {
231 $quot = '';
232 $func[$i] = 'IS';
234 $sql_query .= ' AND ' . PMA_backquote(urldecode($names[$i])) . " $func[$i] $quot$fields[$i]$quot";
235 } // end if
236 } // end for
237 } // end if
239 if ($orderField != '--nil--') {
240 $sql_query .= ' ORDER BY ' . PMA_backquote(urldecode($orderField)) . ' ' . $order;
241 } // end if
243 // The query will be stripslashed in sql.php3 if "magic_quotes_gpc" is on
244 if (get_magic_quotes_gpc()) {
245 $sql_query = addslashes($sql_query);
247 include('./sql.php3');