move header() to include(/elements/header.html) so it can be changed in one place...
[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             <font color="#ff0000">no type</font>
59           <% } elsif ( $type eq 'textarea' ) { %>
60             <textarea name="<%= $i->key. $n %>" rows=5><%= "\n". join("\n", $conf->config($i->key) ) %></textarea>
61           <% } elsif ( $type eq 'checkbox' ) { %>
62             <input name="<%= $i->key. $n %>" type="checkbox" value="1"<%= $conf->exists($i->key) ? ' CHECKED' : '' %>>
63           <% } elsif ( $type eq 'text' )  { %>
64             <input name="<%= $i->key. $n %>" type="<%= $type %>" value="<%= $conf->exists($i->key) ? $conf->config($i->key) : '' %>">
65           <% } elsif ( $type eq 'select' || $type eq 'selectmultiple' )  { %>
66             <select name="<%= $i->key. $n %>" <%= $type eq 'selectmultiple' ? 'MULTIPLE' : '' %>>
67               <% my %saw;
68                  foreach my $value ( "", @{$i->select_enum} ) {
69                     local($^W)=0; next if $saw{$value}++; %>
70                 <option value="<%= $value %>"<%= $value eq $conf->config($i->key) || ( $type eq 'selectmultiple' && grep { $_ eq $value } $conf->config($i->key) ) ? ' SELECTED' : '' %>><%= $value %>
71               <% } %>
72               <% if ( $conf->exists($i->key) && $conf->config($i->key) && ! grep { $conf->config($i->key) eq $_ } @{$i->select_enum}) { %>
73                 <option value=<%= $conf->config($i->key) %> SELECTED><%= $conf->config($i->key) %>
74               <% } %>
75             </select>
76           <% } elsif ( $type eq 'select-sub' ) { %>
77             <select name="<%= $i->key. $n %>">
78               <option value="">
79               <% my %options = &{$i->options_sub};
80                  my @options = sort { $a <=> $b } keys %options;
81                  my %saw;
82                  foreach my $value ( @options ) {
83                     local($^W)=0; next if $saw{$value}++;
84               %>
85                 <option value="<%= $value %>"<%= $value eq $conf->config($i->key) ? ' SELECTED' : '' %>><%= $value %>: <%= $options{$value} %>
86               <% } %>
87               <% if ( $conf->exists($i->key) && $conf->config($i->key) && ! exists $options{$conf->config($i->key)} ) { %>
88                 <option value=<%= $conf->config($i->key) %> SELECTED><%= $conf->config($i->key) %>: <%= &{ $i->option_sub }( $conf->config($i->key) ) %>
89               <% } %>
90             </select>
91           <% } elsif ( $type eq 'editlist' )  { %>
92             <script>
93               function doremove<%= $i->key. $n %>() {
94                 fromObject = document.OneTrueForm.<%= $i->key. $n %>;
95                 for (var i=fromObject.options.length-1;i>-1;i--) {
96                   if (fromObject.options[i].selected)
97                     deleteOption<%= $i->key. $n %>(fromObject,i);
98                 }
99               }
100               function deleteOption<%= $i->key. $n %>(object,index) {
101                 object.options[index] = null;
102               }
103               function selectall<%= $i->key. $n %>() {
104                 fromObject = document.OneTrueForm.<%= $i->key. $n %>;
105                 for (var i=fromObject.options.length-1;i>-1;i--) {
106                   fromObject.options[i].selected = true;
107                 }
108               }
109               function doadd<%= $i->key. $n %>(object) {
110                 var myvalue = "";
111                 <% if ( defined($i->editlist_parts) ) { %>
112
113                   <% foreach my $pnum ( 0 .. scalar(@{$i->editlist_parts})-1 ) { %>
114
115                     if ( myvalue != "" ) { myvalue = myvalue + " "; }
116                     <% if ( $i->editlist_parts->[$pnum]{type} eq 'select' ) { %>
117                       myvalue = myvalue + object.add<%= $i->key. $n . "_$pnum" %>.options[object.add<%= $i->key. $n . "_$pnum" %>.selectedIndex].value;
118                       <!-- #RESET SELECT??  maybe not... -->
119                     <% } elsif ( $i->editlist_parts->[$pnum]{type} eq 'immutable' ) { %>
120                       myvalue = myvalue + object.add<%= $i->key. $n . "_$pnum" %>.value;
121                     <% } else { %>
122                       myvalue = myvalue + object.add<%= $i->key. $n . "_$pnum" %>.value;
123                       object.add<%= $i->key. $n. "_$pnum" %>.value = "";
124                     <% } %>
125
126
127                   <% } %>
128                 <% } else { %>
129                   myvalue = object.add<%= $i->key. $n. "_1" %>.value;
130                 <% } %>
131                 var optionName = new Option(myvalue, myvalue);
132                 var length = object.<%= $i->key. $n %>.length;
133                 object.<%= $i->key. $n %>.options[length] = optionName;
134               }
135             </script>
136             <select multiple size=5 name="<%= $i->key. $n %>">
137             <option selected>----------------------------------------------------------------</option>
138             <% foreach my $line ( $conf->config($i->key) ) { %>
139               <option value="<%= $line %>"><%= $line %></option>
140             <% } %>
141             </select><br>
142             <input type="button" value="remove selected" onClick="doremove<%= $i->key. $n %>()">
143             <script>SafeAddOnLoad(doremove<%= $i->key. $n %>);
144                     SafeAddOnSubmit(selectall<%= $i->key. $n %>);</script>
145             <br>
146             <%= itable() %><tr>
147             <% if ( defined $i->editlist_parts ) { %>
148               <% my $pnum=0; foreach my $part ( @{$i->editlist_parts} ) { %>
149                 <td>
150                 <% if ( $part->{type} eq 'text' ) { %>
151                   <input type="text" name="add<%= $i->key. $n."_$pnum" %>">
152                 <% } elsif ( $part->{type} eq 'immutable' ) { %>
153                   <%= $part->{value} %><input type="hidden" name="add<%= $i->key. $n. "_$pnum" %>" value="<%= $part->{value} %>">
154                 <% } elsif ( $part->{type} eq 'select' ) { %>
155                   <select name="add<%= $i->key. $n. "_$pnum" %>">
156                   <% foreach my $key ( keys %{$part->{select_enum}} ) { %>
157                     <option value="<%= $key %>"><%= $part->{select_enum}{$key} %></option>
158                   <% } %>
159                   </select>
160                 <% } else { %>
161                   <font color="#ff0000">unknown type <%= $part->type %></font>
162                 <% } %>
163                 </td>
164               <% $pnum++; } %>
165             <% } else { %>
166               <td><input type="text" name="add<%= $i->key. $n %>_0"></td>
167             <% } %>
168             <td><input type="button" value="add" onClick="doadd<%= $i->key. $n %>(this.form)"></td>
169             </tr></table>
170           <% } else { %>
171             <font color="#ff0000">unknown type <%= $type %></font>
172           <% } %>
173         <% $n++; } %>
174       </td>
175       <td><a name="<%= $i->key %>">
176         <b><%= $i->key %></b> - <%= $i->description %>
177       </a></td>
178     </tr>
179   <% } %>
180   </table><br>
181
182   You may need to restart Apache and/or freeside-queued for configuration
183   changes to take effect.<br>
184
185   <input type="submit" value="Apply changes"><br><br>
186
187 <% } %>
188
189 </form>
190
191 </body></html>