no table creation in information_schema
[phpmyadmin/crack.git] / mult_submits.inc.php
blob5d4ec3594fff9896a0a95f49814880fd9aee8622
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
6 /**
7 * Prepares the work and runs some other scripts if required
8 */
9 if (!empty($submit_mult)
10 && ($submit_mult != $strWithChecked)
11 && ( !empty($selected_db)
12 || !empty($selected_tbl)
13 || !empty($selected_fld)
14 || !empty($rows_to_delete)
15 )) {
17 if (!empty($selected_db)) {
18 $selected = $selected_db;
19 $what = 'drop_db';
20 } else if (!empty($selected_tbl)) {
21 if ($submit_mult == $strPrintView) {
22 require('./tbl_printview.php');
23 } else {
24 $selected = $selected_tbl;
25 switch ($submit_mult) {
26 case 'drop_db':
27 $what = 'drop_db';
28 break;
29 case $strDrop:
30 $what = 'drop_tbl';
31 break;
32 case $strEmpty:
33 $what = 'empty_tbl';
34 break;
35 case $strCheckTable:
36 unset($submit_mult);
37 $query_type = 'check_tbl';
38 $mult_btn = $strYes;
39 break;
40 case $strOptimizeTable:
41 unset($submit_mult);
42 $query_type = 'optimize_tbl';
43 $mult_btn = $strYes;
44 break;
45 case $strRepairTable:
46 unset($submit_mult);
47 $query_type = 'repair_tbl';
48 $mult_btn = $strYes;
49 break;
50 case $strAnalyzeTable:
51 unset($submit_mult);
52 $query_type = 'analyze_tbl';
53 $mult_btn = $strYes;
54 break;
55 } // end switch
57 } else if (!empty($selected_fld)) {
58 $selected = $selected_fld;
59 switch ($submit_mult) {
60 case $strDrop:
61 $what = 'drop_fld';
62 break;
63 case $strPrimary:
64 // Gets table primary key
65 PMA_DBI_select_db($db);
66 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
67 $primary = '';
68 while ($row = PMA_DBI_fetch_assoc($result)) {
69 // Backups the list of primary keys
70 if ($row['Key_name'] == 'PRIMARY') {
71 $primary .= $row['Column_name'] . ', ';
73 } // end while
74 PMA_DBI_free_result($result);
75 if (empty($primary)) {
76 // no primary key, so we can safely create new
77 unset($submit_mult);
78 $query_type = 'primary_fld';
79 $mult_btn = $strYes;
80 } else {
81 // primary key exists, so lets as user
82 $what = 'primary_fld';
84 break;
85 case $strIndex:
86 unset($submit_mult);
87 $query_type = 'index_fld';
88 $mult_btn = $strYes;
89 break;
90 case $strUnique:
91 unset($submit_mult);
92 $query_type = 'unique_fld';
93 $mult_btn = $strYes;
94 break;
95 case $strIdxFulltext:
96 unset($submit_mult);
97 $query_type = 'fulltext_fld';
98 $mult_btn = $strYes;
99 break;
100 case $strChange:
101 require('./tbl_alter.php');
102 break;
104 } else {
105 $what = 'row_delete';
106 $selected = $rows_to_delete;
108 } // end if
112 * Displays the confirmation form if required
114 if (!empty($submit_mult) && !empty($what)) {
115 $js_to_run = 'functions.js';
116 unset($message);
117 if (!empty($table)) {
118 require('./tbl_properties_common.php');
119 $url_query .= '&amp;goto=tbl_properties.php&amp;back=tbl_properties.php';
120 require('./tbl_properties_table_info.php');
122 elseif (!empty($db)) {
123 require('./db_details_common.php');
124 require('./db_details_db_info.php');
126 // Builds the query
127 $full_query = '';
128 if ($what == 'drop_tbl') {
129 $full_query_views = '';
131 $selected_cnt = count($selected);
132 $i = 0;
133 foreach ($selected AS $idx => $sval) {
134 switch ($what) {
135 case 'row_delete':
136 $full_query .= htmlspecialchars(urldecode($sval))
137 . ';<br />';
138 break;
139 case 'drop_db':
140 $full_query .= 'DROP DATABASE '
141 . PMA_backquote(htmlspecialchars(urldecode($sval)))
142 . ';<br />';
143 break;
145 case 'drop_tbl':
146 $current = urldecode($sval);
147 if (!empty($views) && in_array($current, $views)) {
148 $full_query_views .= (empty($full_query_views) ? 'DROP VIEW ' : ', ')
149 . PMA_backquote(htmlspecialchars($current));
150 } else {
151 $full_query .= (empty($full_query) ? 'DROP TABLE ' : ', ')
152 . PMA_backquote(htmlspecialchars($current));
154 break;
156 case 'empty_tbl':
157 if (PMA_MYSQL_INT_VERSION >= 40000) {
158 $full_query .= 'TRUNCATE ';
159 } else {
160 $full_query .= 'DELETE FROM ';
162 $full_query .= PMA_backquote(htmlspecialchars(urldecode($sval)))
163 . ';<br />';
164 break;
166 case 'primary_fld':
167 if ($full_query == '') {
168 $full_query .= 'ALTER TABLE '
169 . PMA_backquote(htmlspecialchars($table))
170 . '<br />&nbsp;&nbsp;DROP PRIMARY KEY,'
171 . '<br />&nbsp;&nbsp; ADD PRIMARY KEY('
172 . '<br />&nbsp;&nbsp;&nbsp;&nbsp; '
173 . PMA_backquote(htmlspecialchars(urldecode($sval)))
174 . ',';
175 } else {
176 $full_query .= '<br />&nbsp;&nbsp;&nbsp;&nbsp; '
177 . PMA_backquote(htmlspecialchars(urldecode($sval)))
178 . ',';
180 if ($i == $selected_cnt-1) {
181 $full_query = preg_replace('@,$@', ');<br />', $full_query);
183 break;
185 case 'drop_fld':
186 if ($full_query == '') {
187 $full_query .= 'ALTER TABLE '
188 . PMA_backquote(htmlspecialchars($table))
189 . '<br />&nbsp;&nbsp;DROP '
190 . PMA_backquote(htmlspecialchars(urldecode($sval)))
191 . ',';
192 } else {
193 $full_query .= '<br />&nbsp;&nbsp;DROP '
194 . PMA_backquote(htmlspecialchars(urldecode($sval)))
195 . ',';
197 if ($i == $selected_cnt-1) {
198 $full_query = preg_replace('@,$@', ';<br />', $full_query);
200 break;
201 } // end switch
202 $i++;
204 if ($what == 'drop_tbl') {
205 if (!empty($full_query)) {
206 $full_query .= ';<br />' . "\n";
208 if (!empty($full_query_views)) {
209 $full_query .= $full_query_views . ';<br />' . "\n";
211 unset($full_query_views);
214 // Displays the form
216 <!-- Do it really ? -->
217 <table border="0" cellpadding="3" cellspacing="0">
218 <tr>
219 <th class="tblHeadError" align="left">
220 <?php
221 echo ($GLOBALS['cfg']['ErrorIconic'] ? '<img src="' . $GLOBALS['pmaThemeImage'] . 's_really.png" border="0" hspace="2" width="11" height="11" valign="middle" />' : '');
222 echo $strDoYouReally . ':&nbsp;' . "\n";
224 </th>
225 </tr>
226 <tr>
227 <td bgcolor="<?php echo $GLOBALS['cfg']['BgcolorOne']; ?>">
228 <?php
229 echo '<tt>' . $full_query . '</tt>&nbsp;?<br/>' . "\n";
231 </td>
232 </tr>
233 <tr>
234 <td align="right" nowrap="nowrap">
235 <form action="<?php echo $action; ?>" method="post">
236 <?php
237 echo "\n";
238 if (strpos(' ' . $action, 'db_details') == 1) {
239 echo PMA_generate_common_hidden_inputs($db);
240 } else if (strpos(' ' . $action, 'tbl_properties') == 1
241 || $what == 'row_delete') {
242 echo PMA_generate_common_hidden_inputs($db,$table);
243 } else {
244 echo PMA_generate_common_hidden_inputs();
246 foreach ($selected AS $idx => $sval) {
247 echo ' <input type="hidden" name="selected[]" value="' . htmlspecialchars($sval) . '" />' . "\n";
249 if ($what == 'drop_tbl' && !empty($views)) {
250 foreach ($views as $current) {
251 echo ' <input type="hidden" name="views[]" value="' . htmlspecialchars($current) . '" />' . "\n";
255 <input type="hidden" name="query_type" value="<?php echo $what; ?>" />
256 <?php
257 if ($what == 'row_delete') {
258 echo '<input type="hidden" name="original_sql_query" value="' . htmlspecialchars($original_sql_query) . '" />' . "\n";
259 echo '<input type="hidden" name="original_pos" value="' . $original_pos . '" />' . "\n";
260 echo '<input type="hidden" name="original_url_query" value="' . htmlspecialchars($original_url_query) . '" />' . "\n";
261 echo '<input type="hidden" name="disp_direction" value="' . $disp_direction . '" />' . "\n";
262 echo '<input type="hidden" name="repeat_cells" value="' . $repeat_cells . '" />' . "\n";
263 echo '<input type="hidden" name="dontlimitchars" value="' . $dontlimitchars . '" />' . "\n";
264 echo '<input type="hidden" name="pos" value="' . $pos . '" />' . "\n";
265 echo '<input type="hidden" name="session_max_rows" value="' . $session_max_rows . '" />' . "\n";
268 <input type="submit" name="mult_btn" value="<?php echo $strYes; ?>" id="buttonYes" />
269 <input type="submit" name="mult_btn" value="<?php echo $strNo; ?>" id="buttonNo" />
270 </form>
271 </td>
272 </tr>
273 </table>
274 <?php
275 echo"\n";
277 require_once('./footer.inc.php');
278 } // end if
282 * Executes the query
284 else if ($mult_btn == $strYes) {
286 if ($query_type == 'drop_db' || $query_type == 'drop_tbl' || $query_type == 'drop_fld') {
287 require_once('./libraries/relation_cleanup.lib.php');
290 $sql_query = '';
291 if ($query_type == 'drop_tbl') {
292 $sql_query_views = '';
294 $selected_cnt = count($selected);
295 $run_parts = FALSE; // whether to run query after each pass
296 $use_sql = FALSE; // whether to include sql.php at the end (to display results)
298 if ($query_type == 'primary_fld') {
299 // Gets table primary key
300 PMA_DBI_select_db($db);
301 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
302 $primary = '';
303 while ($row = PMA_DBI_fetch_assoc($result)) {
304 // Backups the list of primary keys
305 if ($row['Key_name'] == 'PRIMARY') {
306 $primary .= $row['Column_name'] . ', ';
308 } // end while
309 PMA_DBI_free_result($result);
312 for ($i = 0; $i < $selected_cnt; $i++) {
313 switch ($query_type) {
314 case 'row_delete':
315 $a_query = urldecode($selected[$i]);
316 $run_parts = TRUE;
317 break;
319 case 'drop_db':
320 PMA_relationsCleanupDatabase($selected[$i]);
321 $a_query = 'DROP DATABASE '
322 . PMA_backquote(urldecode($selected[$i]));
323 $reload = 1;
324 $run_parts = TRUE;
325 break;
327 case 'drop_tbl':
328 PMA_relationsCleanupTable($db, $selected[$i]);
329 $current = urldecode($selected[$i]);
330 if (!empty($views) && in_array($current, $views)) {
331 $sql_query_views .= (empty($sql_query_views) ? 'DROP VIEW ' : ', ')
332 . PMA_backquote($current);
333 } else {
334 $sql_query .= (empty($sql_query) ? 'DROP TABLE ' : ', ')
335 . PMA_backquote($current);
337 $reload = 1;
338 break;
340 case 'check_tbl':
341 $sql_query .= (empty($sql_query) ? 'CHECK TABLE ' : ', ')
342 . PMA_backquote(urldecode($selected[$i]));
343 $use_sql = TRUE;
344 break;
346 case 'optimize_tbl':
347 $sql_query .= (empty($sql_query) ? 'OPTIMIZE TABLE ' : ', ')
348 . PMA_backquote(urldecode($selected[$i]));
349 $use_sql = TRUE;
350 break;
352 case 'analyze_tbl':
353 $sql_query .= (empty($sql_query) ? 'ANALYZE TABLE ' : ', ')
354 . PMA_backquote(urldecode($selected[$i]));
355 $use_sql = TRUE;
356 break;
358 case 'repair_tbl':
359 $sql_query .= (empty($sql_query) ? 'REPAIR TABLE ' : ', ')
360 . PMA_backquote(urldecode($selected[$i]));
361 $use_sql = TRUE;
362 break;
364 case 'empty_tbl':
365 if (PMA_MYSQL_INT_VERSION >= 40000) {
366 $a_query = 'TRUNCATE ';
367 } else {
368 $a_query = 'DELETE FROM ';
370 $a_query .= PMA_backquote(htmlspecialchars(urldecode($selected[$i])));
371 $run_parts = TRUE;
372 break;
374 case 'drop_fld':
375 PMA_relationsCleanupColumn($db, $table, $selected[$i]);
376 $sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) : ',')
377 . ' DROP ' . PMA_backquote(urldecode($selected[$i]))
378 . (($i == $selected_cnt-1) ? ';' : '');
379 break;
381 case 'primary_fld':
382 $sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) . ( empty($primary) ? '' : ' DROP PRIMARY KEY,') . ' ADD PRIMARY KEY( ' : ', ')
383 . PMA_backquote(urldecode($selected[$i]))
384 . (($i == $selected_cnt-1) ? ');' : '');
385 break;
387 case 'index_fld':
388 $sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) . ' ADD INDEX( ' : ', ')
389 . PMA_backquote(urldecode($selected[$i]))
390 . (($i == $selected_cnt-1) ? ');' : '');
391 break;
393 case 'unique_fld':
394 $sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) . ' ADD UNIQUE( ' : ', ')
395 . PMA_backquote(urldecode($selected[$i]))
396 . (($i == $selected_cnt-1) ? ');' : '');
397 break;
399 case 'fulltext_fld':
400 $sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) . ' ADD FULLTEXT( ' : ', ')
401 . PMA_backquote(urldecode($selected[$i]))
402 . (($i == $selected_cnt-1) ? ');' : '');
403 break;
404 } // end switch
406 // All "DROP TABLE","DROP FIELD", "OPTIMIZE TABLE" and "REPAIR TABLE"
407 // statements will be run at once below
408 if ($run_parts) {
409 $sql_query .= $a_query . ';' . "\n";
410 if ($query_type != 'drop_db') {
411 PMA_DBI_select_db($db);
413 $result = @PMA_DBI_query($a_query) or PMA_mysqlDie('', $a_query, FALSE, $err_url);
414 } // end if
415 } // end for
417 if ($query_type == 'drop_tbl') {
418 if (!empty($sql_query)) {
419 $sql_query .= ';';
420 } else if (!empty($sql_query_views)) {
421 $sql_query = $sql_query_views . ';';
422 unset($sql_query_views);
426 if ($use_sql) {
427 require('./sql.php');
428 } elseif (!$run_parts) {
429 PMA_DBI_select_db($db);
430 $result = PMA_DBI_query($sql_query);
431 if (!empty($sql_query_views)) {
432 $sql_query .= ' ' . $sql_query_views . ';';
433 PMA_DBI_query($sql_query_views);
434 unset($sql_query_views);