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