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