update
[phpmyadmin/crack.git] / tbl_select.php3
blobfbf095f8973f4c270dfe12774b3284031787a02c
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 if (!isset($goto)) {
33 $goto = $cfg['DefaultTabTable'];
35 // Defines the url to return to in case of error in the next sql statement
36 $err_url = $goto . '?' . PMA_generate_common_url($db, $table);
38 // Gets the list and number of fields
39 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
40 $result = @PMA_mysql_query($local_query);
41 if (!$result) {
42 PMA_mysqlDie('', $local_query, '', $err_url);
44 else {
45 $fields_cnt = mysql_num_rows($result);
46 while ($row = PMA_mysql_fetch_array($result)) {
47 $fields_list[] = $row['Field'];
48 $type = $row['Type'];
49 // reformat mysql query output - staybyte - 9. June 2001
50 $shorttype = substr($type, 0, 3);
51 if ($shorttype == 'set' || $shorttype == 'enu') {
52 $type = eregi_replace(',', ', ', $type);
53 // Removes automatic MySQL escape format
54 $type = str_replace('\'\'', '\\\'', $type);
55 } else {
56 $type = eregi_replace('BINARY', '', $type);
57 $type = eregi_replace('ZEROFILL', '', $type);
58 $type = eregi_replace('UNSIGNED', '', $type);
60 if (empty($type)) {
61 $type = '&nbsp;';
63 $fields_type[] = $type;
64 } // end while
65 mysql_free_result($result);
67 // <markus@noga.de>
68 // retrieve keys into foreign fields, if any
69 $cfgRelation = PMA_getRelationsParam();
70 $foreigners = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE);
72 <form method="post" action="tbl_select.php3">
73 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
74 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
75 <input type="hidden" name="back" value="tbl_select.php3" />
76 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
77 <?php echo $strSelectFields; ?>&nbsp;:<br />
78 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
79 <select name="param[]" size="<?php echo ($fields_cnt < 10) ? $fields_cnt : 10; ?>" multiple="multiple">
80 <?php
81 echo "\n";
82 // Displays the list of the fields
83 for ($i = 0 ; $i < $fields_cnt; $i++) {
84 echo ' <option value="' . htmlspecialchars($fields_list[$i]) . '" selected="selected">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n";
87 </select><br />
88 <ul>
89 <li>
90 <div style="margin-bottom: 10px">
91 <?php echo $strLimitNumRows . "\n"; ?>
92 <input type="text" size="4" name="session_max_rows" value="<?php echo $cfg['MaxRows']; ?>" class="textfield" />
93 </div>
94 </li>
95 <li>
96 <?php echo $strAddSearchConditions; ?><br />
97 <input type="text" name="where" class="textfield" />&nbsp;
98 <?php echo PMA_showMySQLDocu('Reference', 'Functions') . "\n"; ?>
99 <br /><br />
100 <?php echo '<i>' . $strOr . '</i> ' . $strDoAQuery; ?><br />
101 <table border="<?php echo $cfg['Border']; ?>">
102 <tr>
103 <th><?php echo $strField; ?></th>
104 <th><?php echo $strType; ?></th>
105 <th><?php echo $strFunction; ?></th>
106 <th><?php echo $strValue; ?></th>
107 </tr>
108 <?php
109 for ($i = 0; $i < $fields_cnt; $i++) {
110 echo "\n";
111 $bgcolor = ($i % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
113 <tr>
114 <td bgcolor="<?php echo $bgcolor; ?>"><?php echo htmlspecialchars($fields_list[$i]); ?></td>
115 <td bgcolor="<?php echo $bgcolor; ?>"><?php echo $fields_type[$i]; ?></td>
116 <td bgcolor="<?php echo $bgcolor; ?>">
117 <select name="func[]">
118 <?php
119 reset($numfunctions);
120 reset($textfunctions);
121 if (eregi('char|blob|text|set|enum', $fields_type[$i])) {
122 while (list($k, $fc) = each($textfunctions)) {
123 echo "\n" . ' '
124 . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>';
125 } // end while
126 } else {
127 while (list($k, $fc) = each($numfunctions)) {
128 echo "\n" . ' '
129 . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>';
130 } // end while
131 } // end if... else...
132 echo "\n";
134 </select>
135 </td>
136 <td bgcolor="<?php echo $bgcolor; ?>">
137 <?php
138 // <markus@noga.de>
139 $field = $fields_list[$i];
141 include('./libraries/get_foreign.lib.php3');
143 echo "\n";
144 // we got a bug report: in some cases, even if $disp is true,
145 // there are no rows, so we add a fetch_array
146 if ($foreigners && isset($foreigners[$field]) && isset($disp) && $disp && @PMA_mysql_fetch_array($disp)) {
147 // f o r e i g n k e y s
148 echo ' <select name="fields[]">' . "\n";
149 echo ' <option value=""></option>' . "\n";
150 // go back to first row
151 mysql_data_seek($disp,0);
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="' . htmlspecialchars($key) . '">'
156 . htmlspecialchars($key) . $value . '</option>' . "\n";
157 } // end while
158 echo ' </select>' . "\n";
159 } else if (substr($fields_type[$i], 0, 3)=='enu'){
160 // e n u m s
161 $enum_value=explode(", ",str_replace("'", "", substr($fields_type[$i], 5, -1)));
162 echo ' <select name="fields[]">' . "\n";
163 echo ' <option value=""></option>' . "\n";
164 for ($j=0; $j<count($enum_value);$j++){
165 echo ' <option value="' . $enum_value[$j] . '">' . $enum_value[$j] . '</option>';
166 } // end for
167 echo ' </select>' . "\n";
168 } else {
169 // o t h e r c a s e s
170 echo ' <input type="text" name="fields[]" size="40" class="textfield" />' . "\n";
174 <input type="hidden" name="names[]" value="<?php echo htmlspecialchars($fields_list[$i]); ?>" />
175 <input type="hidden" name="types[]" value="<?php echo $fields_type[$i]; ?>" />
176 </td>
177 </tr>
178 <?php
179 } // end for
180 echo "\n";
182 </table><br />
183 </li>
184 <li>
185 <?php echo $strDisplayOrder; ?><br />
186 <select name="orderField" style="vertical-align: middle">
187 <option value="--nil--"></option>
188 <?php
189 echo "\n";
190 for ($i = 0; $i < $fields_cnt; $i++) {
191 echo ' ';
192 echo '<option value="' . htmlspecialchars($fields_list[$i]) . '">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n";
193 } // end for
195 </select>
196 <input type="radio" name="order" value="ASC" checked="checked" />
197 <?php echo $strAscending; ?>&nbsp;
198 <input type="radio" name="order" value="DESC" />
199 <?php echo $strDescending; ?><br /><br />
200 </li>
201 </ul>
203 &nbsp;&nbsp;&nbsp;&nbsp;
204 <input type="submit" name="submit" value="<?php echo $strGo; ?>" />
205 </form>
206 <?php
207 } // end if
208 echo "\n";
209 include('./footer.inc.php3');
214 * Selection criteria have been submitted -> do the work
216 else {
217 // Builds the query
218 $sql_query = 'SELECT ' . PMA_backquote(urldecode($param[0]));
219 $i = 0;
220 $c = count($param);
221 while ($i < $c) {
222 if ($i > 0) {
223 $sql_query .= ',' . PMA_backquote(urldecode($param[$i]));
225 $i++;
227 $sql_query .= ' FROM ' . PMA_backquote($table);
228 // The where clause
229 if ($where != '') {
230 $sql_query .= ' WHERE ' . $where;
232 else {
233 $sql_query .= ' WHERE 1';
234 for ($i = 0; $i < count($fields); $i++) {
235 if (!empty($fields) && $fields[$i] != '') {
236 if (eregi('char|blob|text|set|enum|date|time|year', $types[$i])) {
237 $quot = '\'';
238 } else {
239 $quot = '';
241 if (strtoupper($fields[$i]) == 'NULL' || strtoupper($fields[$i]) == 'NOT NULL') {
242 $quot = '';
243 $func[$i] = 'IS';
245 $sql_query .= ' AND ' . PMA_backquote(urldecode($names[$i])) . " $func[$i] $quot$fields[$i]$quot";
246 } // end if
247 } // end for
248 } // end if
250 if ($orderField != '--nil--') {
251 $sql_query .= ' ORDER BY ' . PMA_backquote(urldecode($orderField)) . ' ' . $order;
252 } // end if
254 include('./sql.php3');