Initial checkin of Webmin
[webmin.git] / module_chooser.cgi
1 #!/usr/local/bin/perl
2 # This CGI generates the HTML for choosing a module or list of modules
3
4 require './web-lib.pl';
5 &init_config();
6 &ReadParse(undef, undef, 2);
7 %access = &get_module_acl();
8
9 if ($in{'multi'}) {
10         # selecting multiple modules
11         if ($in{'frame'} == 0) {
12                 # base frame
13                 &PrintHeader();
14                 print "<script>\n";
15                 @ul = split(/\s+/, $in{'module'});
16                 $len = @ul;
17                 print "sel = new Array($len);\n";
18                 print "selr = new Array($len);\n";
19                 for($i=0; $i<$len; $i++) {
20                         print "sel[$i] = \"$ul[$i]\";\n";
21                         %minfo = &get_module_info($ul[$i]);
22                         if (%minfo) { print "selr[$i] = \"$minfo{'desc'}\";\n"; }
23                         else { print "selr[$i] = \"???\";\n"; }
24                         }
25                 print "</script>\n";
26                 print "<title>$text{'modules_title1'}</title>\n";
27                 print "<frameset cols='50%,50%'>\n";
28                 print "<frame src=\"/module_chooser.cgi?frame=1&multi=1\">\n";
29                 print "<frameset rows='*,50' frameborder=no>\n";
30                 print " <frame src=\"/module_chooser.cgi?frame=2&multi=1\">\n";
31                 print " <frame src=\"/module_chooser.cgi?frame=3&multi=1\" scrolling=no>\n";
32                 print "</frameset>\n";
33                 print "</frameset>\n";
34                 }
35         elsif ($in{'frame'} == 1) {
36                 # list of all modules to choose from
37                 &popup_header();
38                 print "<script>\n";
39                 print "function addmodule(u, r)\n";
40                 print "{\n";
41                 print "top.sel[top.sel.length] = u\n";
42                 print "top.selr[top.selr.length] = r\n";
43                 print "top.frames[1].location = top.frames[1].location\n";
44                 print "return false;\n";
45                 print "}\n";
46                 print "</script>\n";
47                 print "<font size=+1>$text{'modules_all'}</font>\n";
48                 print "<table width=100%>\n";
49                 foreach $m (&get_all_module_infos()) {
50                         if ($in{'module'} eq $m->{'dir'}) { print "<tr $cb>\n"; }
51                         else { print "<tr>\n"; }
52                         print "<td width=20%><a href=\"\" onClick='return addmodule(\"$m->{'dir'}\", \"$m->{'desc'}\")'>$m->{'dir'}</a></td>\n";
53                         print "<td>$m->{'desc'}</td> </tr>\n";
54                         }
55                 print "</table>\n";
56                 &popup_footer();
57                 }
58         elsif ($in{'frame'} == 2) {
59                 # show chosen modules
60                 &popup_header();
61                 print "<font size=+1>$text{'modules_sel'}</font>\n";
62                 print <<'EOF';
63 <table width=100%>
64 <script>
65 function sub(j)
66 {
67 sel2 = new Array(); selr2 = new Array();
68 for(k=0,l=0; k<top.sel.length; k++) {
69         if (k != j) {
70                 sel2[l] = top.sel[k];
71                 selr2[l] = top.selr[k];
72                 l++;
73                 }
74         }
75 top.sel = sel2; top.selr = selr2;
76 top.frames[1].location = top.frames[1].location;
77 return false;
78 }
79 for(i=0; i<top.sel.length; i++) {
80         document.write("<tr>\n");
81         document.write("<td><a href=\"\" onClick='return sub("+i+")'>"+top.sel[i]+"</a></td>\n");
82         document.write("<td>"+top.selr[i]+"</td>\n");
83         }
84 </script>
85 </table>
86 EOF
87                 &popup_footer();
88                 }
89         elsif ($in{'frame'} == 3) {
90                 # output OK and Cancel buttons
91                 &popup_header();
92                 print "<script>\n";
93                 print "function qjoin(l)\n";
94                 print "{\n";
95                 print "rv = \"\";\n";
96                 print "for(i=0; i<l.length; i++) {\n";
97                 print "    if (rv != '') rv += ' ';\n";
98                 print "    if (l[i].indexOf(' ') < 0) rv += l[i];\n";
99                 print "    else rv += '\"'+l[i]+'\"'\n";
100                 print "    }\n";
101                 print "return rv;\n";
102                 print "}\n";
103                 print "</script>\n";
104                 print "<form>\n";
105                 print "<input type=button value=\"$text{'modules_ok'}\" ",
106                       "onClick='top.opener.ifield.value = qjoin(top.sel); ",
107                       "top.close()'>\n";
108                 print "<input type=button value=\"$text{'modules_cancel'}\" ",
109                       "onClick='top.close()'>\n";
110                 print "&nbsp;&nbsp;<input type=button value=\"$text{'modules_clear'}\" onClick='top.sel = new Array(); top.selr = new Array(); top.frames[1].location = top.frames[1].location'>\n";
111                 print "</form>\n";
112                 &popup_footer();
113                 }
114         }
115 else {
116         # selecting just one module .. display a list of all modules to
117         # choose from
118         &popup_header($text{'modules_title2'});
119         print "<script>\n";
120         print "function select(f)\n";
121         print "{\n";
122         print "top.opener.ifield.value = f;\n";
123         print "top.close();\n";
124         print "return false;\n";
125         print "}\n";
126         print "</script>\n";
127         print "<table width=100%>\n";
128         foreach $m (&get_all_module_infos()) {
129                 if ($in{'user'} eq $m->{'dir'}) { print "<tr $cb>\n"; }
130                 else { print "<tr>\n"; }
131                 print "<td width=20%><a href=\"\" onClick='return select(\"$m->{'dir'}\")'>$m->{'dir'}</a></td>\n";
132                 print "<td>$m->{'dir'}</td> </tr>\n";
133                 }
134         print "</table>\n";
135         &popup_footer();
136         }
137
138