putting the C in ACL
[freeside.git] / httemplate / config / config.cgi
1 <% include("/elements/header.html",'Edit Configuration', menubar( 'Main Menu' => $p ) ) %>
2 <SCRIPT>
3 var gSafeOnload = new Array();
4 var gSafeOnsubmit = new Array();
5 window.onload = SafeOnload;
6 function SafeAddOnLoad(f) {
7   gSafeOnload[gSafeOnload.length] = f;
8 }
9 function SafeOnload() {
10   for (var i=0;i<gSafeOnload.length;i++)
11     gSafeOnload[i]();
12 }
13 function SafeAddOnSubmit(f) {
14   gSafeOnsubmit[gSafeOnsubmit.length] = f;
15 }
16 function SafeOnsubmit() {
17   for (var i=0;i<gSafeOnsubmit.length;i++)
18     gSafeOnsubmit[i]();
19 }
20 </SCRIPT>
21 % my $conf = new FS::Conf; my @config_items = $conf->config_items; 
22
23
24 <form name="OneTrueForm" action="config-process.cgi" METHOD="POST" onSubmit="SafeOnsubmit()">
25 % foreach my $section ( qw(required billing username password UI session
26 %                            shell BIND
27 %                           ),
28 %                         '', 'deprecated') { 
29
30   <A NAME="<% $section || 'unclassified' %>"></A>
31   <FONT SIZE="-2">
32 % foreach my $nav_section ( qw(required billing username password UI session
33 %                                  shell BIND
34 %                                 ),
35 %                               '', 'deprecated') { 
36 % if ( $section eq $nav_section ) { 
37
38       [<A NAME="not<% $nav_section || 'unclassified' %>" style="background-color: #cccccc"><% ucfirst($nav_section || 'unclassified') %></A>]
39 % } else { 
40
41       [<A HREF="#<% $nav_section || 'unclassified' %>"><% ucfirst($nav_section || 'unclassified') %></A>]
42 % } 
43 % } 
44
45   </FONT><BR>
46   <% table("#cccccc", 2) %>
47   <tr>
48     <th colspan="2" bgcolor="#dcdcdc">
49       <% ucfirst($section || 'unclassified') %> configuration options
50     </th>
51   </tr>
52 % foreach my $i (grep $_->section eq $section, @config_items) { 
53
54     <tr>
55       <td>
56 % my $n = 0;
57 %           foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) {
58 %             #warn $i->key unless defined($type);
59 %        
60 % if ( $type eq '' ) { 
61
62
63                <font color="#ff0000">no type</font>
64 % } elsif ( $type eq 'textarea' ) { 
65
66
67                <textarea name="<% $i->key. $n %>" rows=5><% "\n". join("\n", $conf->config($i->key) ) %></textarea>
68 % } elsif ( $type eq 'checkbox' ) { 
69
70
71                <input name="<% $i->key. $n %>" type="checkbox" value="1"<% $conf->exists($i->key) ? ' CHECKED' : '' %>>
72 % } elsif ( $type eq 'text' )  { 
73
74
75                <input name="<% $i->key. $n %>" type="<% $type %>" value="<% $conf->exists($i->key) ? $conf->config($i->key) : '' %>">
76 % } elsif ( $type eq 'select' || $type eq 'selectmultiple' )  { 
77
78           
79                <select name="<% $i->key. $n %>" <% $type eq 'selectmultiple' ? 'MULTIPLE' : '' %>>
80
81 %                  my %hash = ();
82 %                  if ( $i->select_enum ) {
83 %                    tie %hash, 'Tie::IxHash',
84 %                      '' => '', map { $_ => $_ } @{ $i->select_enum };
85 %                  } elsif ( $i->select_hash ) {
86 %                    if ( ref($i->select_hash) eq 'ARRAY' ) {
87 %                      tie %hash, 'Tie::IxHash',
88 %                        '' => '', @{ $i->select_hash };
89 %                    } else {
90 %                      tie %hash, 'Tie::IxHash',
91 %                        '' => '', %{ $i->select_hash };
92 %                    }
93 %                  } else {
94 %                    %hash = ( '' => 'WARNING: neither select_enum nor select_hash specified in Conf.pm for configuration option "'. $i->key. '"' );
95 %                  }
96 %
97 %                  my %saw = ();
98 %                  foreach my $value ( keys %hash ) {
99 %                    local($^W)=0; next if $saw{$value}++;
100 %                    my $label = $hash{$value};
101 %               
102
103
104                     <option value="<% $value %>"<% $value eq $conf->config($i->key) || ( $type eq 'selectmultiple' && grep { $_ eq $value } $conf->config($i->key) ) ? ' SELECTED' : '' %>><% $label %>
105 % } 
106 % my $curvalue = $conf->config($i->key);
107 %                 if ( $conf->exists($i->key) && $curvalue
108 %                      && ! $hash{$curvalue}
109 %                    ) {
110 %              
111
112               
113                    <option value="<% $conf->config($i->key) %>" SELECTED><% exists( $hash{ $conf->config($i->key) } ) ? $hash{ $conf->config($i->key) } : $conf->config($i->key) %>
114 % } 
115
116
117             </select>
118 % } elsif ( $type eq 'select-sub' ) { 
119
120
121             <select name="<% $i->key. $n %>">
122               <option value="">
123 % my %options = &{$i->options_sub};
124 %                 my @options = sort { $a <=> $b } keys %options;
125 %                 my %saw;
126 %                 foreach my $value ( @options ) {
127 %                    local($^W)=0; next if $saw{$value}++;
128 %              
129
130                 <option value="<% $value %>"<% $value eq $conf->config($i->key) ? ' SELECTED' : '' %>><% $value %>: <% $options{$value} %>
131 % } 
132 % if ( $conf->exists($i->key) && $conf->config($i->key) && ! exists $options{$conf->config($i->key)} ) { 
133
134                 <option value=<% $conf->config($i->key) %> SELECTED><% $conf->config($i->key) %>: <% &{ $i->option_sub }( $conf->config($i->key) ) %>
135 % } 
136
137             </select>
138 % } elsif ( $type eq 'editlist' ) { 
139
140
141             <script>
142               function doremove<% $i->key. $n %>() {
143                 fromObject = document.OneTrueForm.<% $i->key. $n %>;
144                 for (var i=fromObject.options.length-1;i>-1;i--) {
145                   if (fromObject.options[i].selected)
146                     deleteOption<% $i->key. $n %>(fromObject,i);
147                 }
148               }
149               function deleteOption<% $i->key. $n %>(object,index) {
150                 object.options[index] = null;
151               }
152               function selectall<% $i->key. $n %>() {
153                 fromObject = document.OneTrueForm.<% $i->key. $n %>;
154                 for (var i=fromObject.options.length-1;i>-1;i--) {
155                   fromObject.options[i].selected = true;
156                 }
157               }
158               function doadd<% $i->key. $n %>(object) {
159                 var myvalue = "";
160 % if ( defined($i->editlist_parts) ) { 
161 % foreach my $pnum ( 0 .. scalar(@{$i->editlist_parts})-1 ) { 
162
163
164                     if ( myvalue != "" ) { myvalue = myvalue + " "; }
165 % if ( $i->editlist_parts->[$pnum]{type} eq 'select' ) { 
166
167                       myvalue = myvalue + object.add<% $i->key. $n . "_$pnum" %>.options[object.add<% $i->key. $n . "_$pnum" %>.selectedIndex].value;
168                       <!-- #RESET SELECT??  maybe not... -->
169 % } elsif ( $i->editlist_parts->[$pnum]{type} eq 'immutable' ) { 
170
171                       myvalue = myvalue + object.add<% $i->key. $n . "_$pnum" %>.value;
172 % } else { 
173
174                       myvalue = myvalue + object.add<% $i->key. $n . "_$pnum" %>.value;
175                       object.add<% $i->key. $n. "_$pnum" %>.value = "";
176 % } 
177 % } 
178 % } else { 
179
180                   myvalue = object.add<% $i->key. $n. "_1" %>.value;
181 % } 
182
183                 var optionName = new Option(myvalue, myvalue);
184                 var length = object.<% $i->key. $n %>.length;
185                 object.<% $i->key. $n %>.options[length] = optionName;
186               }
187             </script>
188             <select multiple size=5 name="<% $i->key. $n %>">
189             <option selected>----------------------------------------------------------------</option>
190 % foreach my $line ( $conf->config($i->key) ) { 
191
192               <option value="<% $line %>"><% $line %></option>
193 % } 
194
195             </select><br>
196             <input type="button" value="remove selected" onClick="doremove<% $i->key. $n %>()">
197             <script>SafeAddOnLoad(doremove<% $i->key. $n %>);
198                     SafeAddOnSubmit(selectall<% $i->key. $n %>);</script>
199             <br>
200             <% itable() %><tr>
201 % if ( defined $i->editlist_parts ) { 
202 % my $pnum=0; foreach my $part ( @{$i->editlist_parts} ) { 
203
204                 <td>
205 % if ( $part->{type} eq 'text' ) { 
206
207                   <input type="text" name="add<% $i->key. $n."_$pnum" %>">
208 % } elsif ( $part->{type} eq 'immutable' ) { 
209
210                   <% $part->{value} %><input type="hidden" name="add<% $i->key. $n. "_$pnum" %>" value="<% $part->{value} %>">
211 % } elsif ( $part->{type} eq 'select' ) { 
212
213                   <select name="add<% $i->key. $n. "_$pnum" %>">
214 % foreach my $key ( keys %{$part->{select_enum}} ) { 
215
216                     <option value="<% $key %>"><% $part->{select_enum}{$key} %></option>
217 % } 
218
219                   </select>
220 % } else { 
221
222                   <font color="#ff0000">unknown type <% $part->type %></font>
223 % } 
224
225                 </td>
226 % $pnum++; } 
227 % } else { 
228
229               <td><input type="text" name="add<% $i->key. $n %>_0"></td>
230 % } 
231
232             <td><input type="button" value="add" onClick="doadd<% $i->key. $n %>(this.form)"></td>
233             </tr></table>
234 % } else { 
235
236
237             <font color="#ff0000">unknown type <% $type %></font>
238 % } 
239 % $n++; } 
240
241       </td>
242       <td><a name="<% $i->key %>">
243         <b><% $i->key %></b> - <% $i->description %>
244       </a></td>
245     </tr>
246 % } 
247
248   </table><br>
249
250   You may need to restart Apache and/or freeside-queued for configuration
251   changes to take effect.<br>
252
253   <input type="submit" value="Apply changes"><br><br>
254 % } 
255
256
257 </form>
258
259 </body></html>
260 <%init>
261 die "access denied"
262   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
263 </%init>