1#!/usr/local/bin/perl
2# table_form.cgi
3# Display a form for creating a table
4
5require './mysql-lib.pl';
6&ReadParse();
7&can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'});
8
9# Redirect to other pages depending on button
10if ($in{'addview'}) {
11	&redirect("edit_view.cgi?new=1&db=".&urlize($in{'db'}));
12	return;
13	}
14elsif ($in{'dropdb'}) {
15	&redirect("drop_dbase.cgi?db=".&urlize($in{'db'}));
16	return;
17	}
18elsif ($in{'backupdb'}) {
19	&redirect("backup_form.cgi?db=".&urlize($in{'db'}));
20	return;
21	}
22elsif ($in{'exec'}) {
23	&redirect("exec_form.cgi?db=".&urlize($in{'db'}));
24	return;
25	}
26
27$access{'edonly'} && &error($text{'dbase_ecannot'});
28$desc = "<tt>$in{'db'}</tt>";
29&ui_print_header($desc, $text{'table_title2'}, "", "table_form");
30
31print &ui_form_start("create_table.cgi", "post");
32print &ui_hidden("db", $in{'db'}),"\n";
33print &ui_table_start($text{'table_header2'}, undef, 2);
34
35print &ui_table_row($text{'table_name'},
36		    &ui_textbox("name", undef, 30));
37
38@dbs = grep { &can_edit_db($_) } &list_databases();
39if (@dbs > $max_dbs) {
40	# Enter source table name manually
41	print &ui_table_row($text{'table_copy2'},
42		&ui_select("copydb", $in{'db'}, \@dbs).
43		" $text{'table_copy2t'} ".
44		&ui_textbox("copytable", undef, 20));
45	}
46else {
47	# Show all tables in all DBs
48	foreach $d (@dbs) {
49		foreach $t (&list_tables($d, 1)) {
50			push(@tables, [ "$d.$t" ]);
51			}
52		}
53	print &ui_table_row($text{'table_copy'},
54			    &ui_select("copy", undef,
55				       [ [ "", $text{'table_copynone'} ],
56					 @tables ]));
57	}
58
59print &ui_table_row($text{'table_type'},
60		    &ui_select("type", "",
61		      [ [ "", $text{'default'} ], [ "isam" ], [ "myisam" ],
62			[ "heap" ], [ "merge" ], [ "innodb" ], [ "ndbcluster" ]
63		      ]));
64
65print &ui_table_row(undef, &show_table_form($in{"fields"} || 4), 2);
66
67print &ui_table_end();
68print &ui_form_end([ [ "create", $text{'create'} ] ]);
69
70&ui_print_footer("edit_dbase.cgi?db=$in{'db'}", $text{'dbase_return'},
71		 &get_databases_return_link($in{'db'}), $text{'index_return'});
72
73