config goes in database
[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" enctype="multipart/form-data" 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 'binary' ) { 
65
66
67                Filename <input type="file" name="<% $i->key. $n %>">
68 % } elsif ( $type eq 'textarea' ) { 
69
70
71                <textarea name="<% $i->key. $n %>" rows=5><% "\n". join("\n", $conf->config($i->key) ) %></textarea>
72 % } elsif ( $type eq 'checkbox' ) { 
73
74
75                <input name="<% $i->key. $n %>" type="checkbox" value="1"<% $conf->exists($i->key) ? ' CHECKED' : '' %>>
76 % } elsif ( $type eq 'text' )  { 
77
78
79                <input name="<% $i->key. $n %>" type="<% $type %>" value="<% $conf->exists($i->key) ? $conf->config($i->key) : '' %>">
80 % } elsif ( $type eq 'select' || $type eq 'selectmultiple' )  { 
81
82           
83                <select name="<% $i->key. $n %>" <% $type eq 'selectmultiple' ? 'MULTIPLE' : '' %>>
84
85 %                  my %hash = ();
86 %                  if ( $i->select_enum ) {
87 %                    tie %hash, 'Tie::IxHash',
88 %                      '' => '', map { $_ => $_ } @{ $i->select_enum };
89 %                  } elsif ( $i->select_hash ) {
90 %                    if ( ref($i->select_hash) eq 'ARRAY' ) {
91 %                      tie %hash, 'Tie::IxHash',
92 %                        '' => '', @{ $i->select_hash };
93 %                    } else {
94 %                      tie %hash, 'Tie::IxHash',
95 %                        '' => '', %{ $i->select_hash };
96 %                    }
97 %                  } else {
98 %                    %hash = ( '' => 'WARNING: neither select_enum nor select_hash specified in Conf.pm for configuration option "'. $i->key. '"' );
99 %                  }
100 %
101 %                  my %saw = ();
102 %                  foreach my $value ( keys %hash ) {
103 %                    local($^W)=0; next if $saw{$value}++;
104 %                    my $label = $hash{$value};
105 %               
106
107
108                     <option value="<% $value %>"<% $value eq $conf->config($i->key) || ( $type eq 'selectmultiple' && grep { $_ eq $value } $conf->config($i->key) ) ? ' SELECTED' : '' %>><% $label %>
109 % } 
110 % my $curvalue = $conf->config($i->key);
111 %                 if ( $conf->exists($i->key) && $curvalue
112 %                      && ! $hash{$curvalue}
113 %                    ) {
114 %              
115
116               
117                    <option value="<% $conf->config($i->key) %>" SELECTED><% exists( $hash{ $conf->config($i->key) } ) ? $hash{ $conf->config($i->key) } : $conf->config($i->key) %>
118 % } 
119
120
121             </select>
122 % } elsif ( $type eq 'select-sub' ) { 
123
124
125             <select name="<% $i->key. $n %>">
126               <option value="">
127 % my %options = &{$i->options_sub};
128 %                 my @options = sort { $a <=> $b } keys %options;
129 %                 my %saw;
130 %                 foreach my $value ( @options ) {
131 %                    local($^W)=0; next if $saw{$value}++;
132 %              
133
134                 <option value="<% $value %>"<% $value eq $conf->config($i->key) ? ' SELECTED' : '' %>><% $value %>: <% $options{$value} %>
135 % } 
136 % if ( $conf->exists($i->key) && $conf->config($i->key) && ! exists $options{$conf->config($i->key)} ) { 
137
138                 <option value=<% $conf->config($i->key) %> SELECTED><% $conf->config($i->key) %>: <% &{ $i->option_sub }( $conf->config($i->key) ) %>
139 % } 
140
141             </select>
142 % } elsif ( $type eq 'editlist' ) { 
143
144
145             <script>
146               function doremove<% $i->key. $n %>() {
147                 fromObject = document.OneTrueForm.<% $i->key. $n %>;
148                 for (var i=fromObject.options.length-1;i>-1;i--) {
149                   if (fromObject.options[i].selected)
150                     deleteOption<% $i->key. $n %>(fromObject,i);
151                 }
152               }
153               function deleteOption<% $i->key. $n %>(object,index) {
154                 object.options[index] = null;
155               }
156               function selectall<% $i->key. $n %>() {
157                 fromObject = document.OneTrueForm.<% $i->key. $n %>;
158                 for (var i=fromObject.options.length-1;i>-1;i--) {
159                   fromObject.options[i].selected = true;
160                 }
161               }
162               function doadd<% $i->key. $n %>(object) {
163                 var myvalue = "";
164 % if ( defined($i->editlist_parts) ) { 
165 % foreach my $pnum ( 0 .. scalar(@{$i->editlist_parts})-1 ) { 
166
167
168                     if ( myvalue != "" ) { myvalue = myvalue + " "; }
169 % if ( $i->editlist_parts->[$pnum]{type} eq 'select' ) { 
170
171                       myvalue = myvalue + object.add<% $i->key. $n . "_$pnum" %>.options[object.add<% $i->key. $n . "_$pnum" %>.selectedIndex].value;
172                       <!-- #RESET SELECT??  maybe not... -->
173 % } elsif ( $i->editlist_parts->[$pnum]{type} eq 'immutable' ) { 
174
175                       myvalue = myvalue + object.add<% $i->key. $n . "_$pnum" %>.value;
176 % } else { 
177
178                       myvalue = myvalue + object.add<% $i->key. $n . "_$pnum" %>.value;
179                       object.add<% $i->key. $n. "_$pnum" %>.value = "";
180 % } 
181 % } 
182 % } else { 
183
184                   myvalue = object.add<% $i->key. $n. "_1" %>.value;
185 % } 
186
187                 var optionName = new Option(myvalue, myvalue);
188                 var length = object.<% $i->key. $n %>.length;
189                 object.<% $i->key. $n %>.options[length] = optionName;
190               }
191             </script>
192             <select multiple size=5 name="<% $i->key. $n %>">
193             <option selected>----------------------------------------------------------------</option>
194 % foreach my $line ( $conf->config($i->key) ) { 
195
196               <option value="<% $line %>"><% $line %></option>
197 % } 
198
199             </select><br>
200             <input type="button" value="remove selected" onClick="doremove<% $i->key. $n %>()">
201             <script>SafeAddOnLoad(doremove<% $i->key. $n %>);
202                     SafeAddOnSubmit(selectall<% $i->key. $n %>);</script>
203             <br>
204             <% itable() %><tr>
205 % if ( defined $i->editlist_parts ) { 
206 % my $pnum=0; foreach my $part ( @{$i->editlist_parts} ) { 
207
208                 <td>
209 % if ( $part->{type} eq 'text' ) { 
210
211                   <input type="text" name="add<% $i->key. $n."_$pnum" %>">
212 % } elsif ( $part->{type} eq 'immutable' ) { 
213
214                   <% $part->{value} %><input type="hidden" name="add<% $i->key. $n. "_$pnum" %>" value="<% $part->{value} %>">
215 % } elsif ( $part->{type} eq 'select' ) { 
216
217                   <select name="add<% $i->key. $n. "_$pnum" %>">
218 % foreach my $key ( keys %{$part->{select_enum}} ) { 
219
220                     <option value="<% $key %>"><% $part->{select_enum}{$key} %></option>
221 % } 
222
223                   </select>
224 % } else { 
225
226                   <font color="#ff0000">unknown type <% $part->type %></font>
227 % } 
228
229                 </td>
230 % $pnum++; } 
231 % } else { 
232
233               <td><input type="text" name="add<% $i->key. $n %>_0"></td>
234 % } 
235
236             <td><input type="button" value="add" onClick="doadd<% $i->key. $n %>(this.form)"></td>
237             </tr></table>
238 % } else { 
239
240
241             <font color="#ff0000">unknown type <% $type %></font>
242 % } 
243 % $n++; } 
244
245       </td>
246       <td><a name="<% $i->key %>">
247         <b><% $i->key %></b> - <% $i->description %>
248       </a></td>
249     </tr>
250 % } 
251
252   </table><br>
253
254   You may need to restart Apache and/or freeside-queued for configuration
255   changes to take effect.<br>
256
257   <input type="submit" value="Apply changes"><br><br>
258 % } 
259
260
261 </form>
262
263 </body></html>
264 <%init>
265 die "access denied"
266   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
267 </%init>