Handle hostnames with upper-case letters
[webmin.git] / mysql / drop_tables.cgi
1 #!/usr/local/bin/perl
2 # Drop multiple tables, views and indexes, after asking for confirmation
3
4 require './mysql-lib.pl';
5 &ReadParse();
6 &can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'});
7 $access{'edonly'} && &error($text{'dbase_ecannot'});
8 @tables = split(/\0/, $in{'d'});
9 @tables || &error($text{'tdrops_enone'});
10
11 if ($in{'confirm'}) {
12         # Drop the tables, views and indexes (tables last)
13         &error_setup($text{'tdrops_err'});
14         foreach $t (@tables) {
15                 if ($t =~ /^\!(.*)$/) {
16                         $str = &index_structure($in{'db'}, $1);
17                         &execute_sql_logged($in{'db'}, "drop index ".&quotestr($1)." on ".quotestr($str->{'table'}));
18                         }
19                 elsif ($t =~ /^\*(.*)$/) {
20                         &execute_sql_logged($in{'db'}, "drop view ".&quotestr($1));
21                         }
22                 else {
23                         push(@rest, $t);
24                         }
25                 }
26         foreach $t (@rest) {
27                 &execute_sql_logged($in{'db'}, "drop table ".&quotestr($t));
28                 }
29         &webmin_log("delete", "tables", scalar(@tables), \%in);
30         &redirect("edit_dbase.cgi?db=$in{'db'}");
31         }
32 else {
33         # Ask the user if he is sure..
34         &ui_print_header(undef, $text{'tdrops_title'}, "");
35         foreach $t (@tables) {
36                 if ($t !~ /^\!/ && $t !~ /^\*/) {
37                         $d = &execute_sql($in{'db'},
38                                 "select count(*) from ".&quotestr($t));
39                         $rows += $d->{'data'}->[0]->[0];
40                         }
41                 }
42
43         $msg = defined($rows) ? 'tdrops_rusure' : 'tdrops_rusure2';
44         print "<center><b>", &text($msg, scalar(@tables),
45                                    "<tt>$in{'db'}</tt>", $rows),"</b><p>\n";
46         print "<form action=drop_tables.cgi>\n";
47         print "<input type=hidden name=db value='$in{'db'}'>\n";
48         print "<input type=submit name=confirm value='$text{'tdrops_ok'}'>\n";
49         foreach $t (@tables) {
50                 print &ui_hidden("d", $t),"\n";
51                 }
52         print "</form></center>\n";
53         &ui_print_footer(
54                 "edit_dbase.cgi?db=$in{'db'}", $text{'dbase_return'},
55                 "", $text{'index_return'});
56         }
57