Handle hostnames with upper-case letters
[webmin.git] / postgresql / exec_form.cgi
1 #!/usr/local/bin/perl
2 # exec_form.cgi
3 # Display a form for executing SQL in some database
4
5 require './postgresql-lib.pl';
6 &ReadParse();
7 &can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'});
8 &ui_print_header(undef, $text{'exec_title'}, "", "exec_form");
9
10 # Generate tabs for sections
11 $prog = "exec_form.cgi?db=".&urlize($in{'db'})."&mode=";
12 @tabs = ( [ "exec", $text{'exec_tabexec'}, $prog."exec" ],
13           [ "file", $text{'exec_tabfile'}, $prog."file" ],
14           [ "import", $text{'exec_tabimport'}, $prog."import" ] );
15 print &ui_tabs_start(\@tabs, "mode", $in{'mode'} || "exec", 1);
16
17 # Get recently run commands
18 open(OLD, "$commands_file.$in{'db'}");
19 while(<OLD>) {
20         s/\r|\n//g;
21         push(@old, $_);
22         }
23 close(OLD);
24
25 # Form for executing an SQL command
26 print &ui_tabs_start_tab("mode", "exec");
27 print &text('exec_header', "<tt>$in{'db'}</tt>"),"<p>\n";
28 print &ui_form_start("exec.cgi", "form-data");
29 print &ui_hidden("db", $in{'db'});
30 print &ui_textarea("cmd", undef, 10, 70),"<br>\n";
31 if (@old) {
32         print $text{'exec_old'}," ",
33               &ui_select("old", undef,
34                 [ map { [ $_, &html_escape(length($_) > 80 ?
35                                 substr($_, 0, 80).".." : $_) ] } @old ]),"\n",
36               &ui_button($text{'exec_edit'}, "movecmd", undef,
37                 "onClick='cmd.value = old.options[old.selectedIndex].value'"),
38               " ",&ui_submit($text{'exec_clear'}, "clear"),"<br>\n";
39         }
40 print &ui_form_end([ [ undef, $text{'exec_exec'} ] ]);
41 print &ui_tabs_end_tab();
42
43 # Form for executing commands from a file
44 print &ui_tabs_start_tab("mode", "file");
45 print &text('exec_header2', "<tt>$in{'db'}</tt>"),"<p>\n";
46 print &ui_form_start("exec_file.cgi", "form-data");
47 print &ui_hidden("db", $in{'db'});
48 print &ui_radio_table("mode", 0, [
49         [ 0, $text{'exec_file'}, &ui_textbox("file", undef, 50)." ".
50                                  &file_chooser_button("file", 0, 1) ],
51         [ 1, $text{'exec_upload'}, &ui_upload("upload", 50) ] ]);
52 print &ui_form_end([ [ undef, $text{'exec_exec'} ] ]);
53 print &ui_tabs_end_tab();
54
55 # Form for loading a CSV or tab-separated file
56 print &ui_tabs_start_tab("mode", "import");
57 print &text('exec_header3', "<tt>$in{'db'}</tt>"),"<br>",
58       $text{'exec_header4'},"<p>\n";
59 print &ui_form_start("import.cgi", "form-data");
60 print &ui_hidden("db", $in{'db'});
61 print &ui_table_start(undef, undef, 2);
62
63 # Source for CSV file
64 print &ui_table_row($text{'exec_importmode'},
65         &ui_radio_table("mode", 0, [
66                 [ 0, $text{'exec_file'}, &ui_textbox("file", undef, 50)." ".
67                                          &file_chooser_button("file", 0, 1) ],
68                 [ 1, $text{'exec_upload'}, &ui_upload("upload", 50) ] ]));
69
70 # Table to import into
71 print &ui_table_row($text{'exec_import'},
72         &ui_select("table", undef, [ &list_tables($in{'db'}) ]));
73
74 # Delete existing rows?
75 print &ui_table_row($text{'exec_delete'},
76         &ui_yesno_radio("delete", 0));
77
78 # Ignore dupes?
79 print &ui_table_row($text{'exec_ignore'},
80         &ui_yesno_radio("ignore", 0));
81
82 # CSV format
83 print &ui_table_row($text{'exec_format'},
84         &ui_radio("format", 2, [ [ 0, $text{'csv_format0'} ],
85                                  [ 1, $text{'csv_format1'} ],
86                                  [ 2, $text{'csv_format2'} ] ]));
87
88 print &ui_table_end();
89 print &ui_form_end([ [ undef, $text{'exec_exec'} ] ]);
90
91 print &ui_tabs_end_tab();
92
93 print &ui_tabs_end(1);
94
95 &ui_print_footer("edit_dbase.cgi?db=$in{'db'}", $text{'dbase_return'},
96         "", $text{'index_return'});