1 <% include("/elements/header-popup.html", $title) %>
4 var gSafeOnload = new Array();
5 var gSafeOnsubmit = new Array();
6 window.onload = SafeOnload;
7 function SafeAddOnLoad(f) {
8 gSafeOnload[gSafeOnload.length] = f;
10 function SafeOnload() {
11 for (var i=0;i<gSafeOnload.length;i++)
14 function SafeAddOnSubmit(f) {
15 gSafeOnsubmit[gSafeOnsubmit.length] = f;
17 function SafeOnsubmit() {
18 for (var i=0;i<gSafeOnsubmit.length;i++)
23 <% include('/elements/error.html') %>
25 <FORM NAME="OneTrueForm" ACTION="config-process.cgi" METHOD="POST" enctype="multipart/form-data" onSubmit="SafeOnsubmit()">
26 <INPUT TYPE="hidden" NAME="agentnum" VALUE="<% $agentnum %>">
27 <INPUT TYPE="hidden" NAME="key" VALUE="<% $key %>">
29 Setting <b><% $key %></b>
31 % my $description_printed = 0;
32 % if ( grep $_ eq 'textarea', @types ) {
33 % $description_printed = 1;
42 % foreach my $type (@types) {
43 % if ( $type eq '' ) {
45 <font color="#ff0000">no type</font>
47 % } elsif ( $type eq 'image' ) {
49 <% $conf->exists($key, $agentnum)
50 ? 'Current image<br>'.
51 '<img src="config-image.cgi?key='. $key.
52 ';agentnum='. $agentnum. '"><br>'
57 New image filename <input type="file" name="<% "$key$n" %>">
59 % } elsif ( $type eq 'binary' ) {
61 Filename <input type="file" name="<% "$key$n" %>">
63 % } elsif ( $type eq 'textarea' ) {
65 <textarea name="<% "$key$n" %>" rows=12 cols=78 wrap="off"><% join("\n", $conf->config($key, $agentnum)) |h %></textarea>
67 % } elsif ( $type eq 'checkbox' ) {
69 <input name="<% "$key$n" %>" type="checkbox" value="1"
70 <% $conf->exists($key, $agentnum) ? 'CHECKED' : '' %> >
72 % } elsif ( $type eq 'text' ) {
74 <input name="<% "$key$n" %>" type="text" value="<% $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : '' |h %>">
76 % } elsif ( $type eq 'select' || $type eq 'selectmultiple' ) {
78 <select name="<% "$key$n" %>" <% $type eq 'selectmultiple' ? 'MULTIPLE' : '' %>>
82 % if ( $config_item->select_enum ) {
83 % tie %hash, 'Tie::IxHash',
84 % '' => '', map { $_ => $_ } @{ $config_item->select_enum };
85 % } elsif ( $config_item->select_hash ) {
86 % if ( ref($config_item->select_hash) eq 'ARRAY' ) {
87 % tie %hash, 'Tie::IxHash', '' => '', @{ $config_item->select_hash };
89 % tie %hash, 'Tie::IxHash', '' => '', %{ $config_item->select_hash };
92 % %hash = ( '' => 'WARNING: neither select_enum nor select_hash specified in Conf.pm for configuration option "'. $key. '"' );
96 % foreach my $value ( keys %hash ) {
97 % local($^W)=0; next if $saw{$value}++;
98 % my $label = $hash{$value};
101 <option value="<% $value %>"
103 % if ( $value eq $conf->config($key, $agentnum)
104 % || ( $type eq 'selectmultiple'
105 % && grep { $_ eq $value } $conf->config($key, $agentnum) ) ) {
114 % my $curvalue = $conf->config($key, $agentnum);
115 % if ( $conf->exists($key, $agentnum) && $curvalue && ! $hash{$curvalue} ) {
117 <option value="<% $curvalue %>" SELECTED>
119 % if ( exists( $hash{ $conf->config($key, $agentnum) } ) ) {
121 <% $hash{ $conf->config($key, $agentnum) } %>
132 % } elsif ( $type eq 'select-sub' ) {
134 <select name="<% "$key$n" %>" <% $config_item->multiple ? 'MULTIPLE' : '' %>>
136 % unless ( $config_item->multiple ) {
140 % my %options = &{$config_item->options_sub};
141 % my @options = sort { $a <=> $b } keys %options;
143 % foreach my $value ( @options ) {
144 % local($^W)=0; next if $saw{$value}++;
146 <option value="<% $value %>"
148 % if ( $value eq $conf->config($key, $agentnum)
149 % || ( $config_item->multiple
150 % && grep { $_ eq $value } $conf->config($key, $agentnum) ) ){
156 ><% $value %>: <% $options{$value} %>
159 % my $curvalue = $conf->config($key, $agentnum);
160 % if ( $conf->exists($key, $agentnum) && $curvalue && ! $options{$curvalue} ) {
162 <option value="<% $curvalue %>" SELECTED> <% $curvalue %>: <% &{ $config_item->option_sub }( $curvalue ) %>
168 % } elsif ( $type eq 'editlist' ) {
171 function doremove<% "$key$n" %>() {
172 fromObject = document.OneTrueForm.<% "$key$n" %>;
173 for (var i=fromObject.options.length-1;i>-1;i--) {
174 if (fromObject.options[i].selected)
175 deleteOption<% "$key$n" %>(fromObject,i);
178 function deleteOption<% "$key$n" %>(object,index) {
179 object.options[index] = null;
181 function selectall<% "$key$n" %>() {
182 fromObject = document.OneTrueForm.<% "$key$n" %>;
183 for (var i=fromObject.options.length-1;i>-1;i--) {
184 fromObject.options[i].selected = true;
187 function doadd<% "$key$n" %>(object) {
190 % if ( defined($config_item->editlist_parts) ) {
191 % foreach my $pnum ( 0 .. scalar(@{$config_item->editlist_parts})-1 ) {
193 if ( myvalue != "" ) { myvalue = myvalue + " "; }
195 % if ( $config_item->editlist_parts->[$pnum]{type} eq 'select' ) {
197 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.options[object.add<% "$key${n}_$pnum" %>.selectedIndex].value
198 <!-- #RESET SELECT?? maybe not... -->
200 % } elsif ( $config_item->editlist_parts->[$pnum]{type} eq 'immutable' ) {
202 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
206 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
207 object.add<% "$key${n}_$pnum" %>.value = ""
213 myvalue = object.add<% "$key${n}_1" %>.value
217 var optionName = new Option(myvalue, myvalue);
218 var length = object.<% "$key$n" %>.length;
219 object.<% "$key$n" %>.options[length] = optionName;
222 <select multiple size=5 name="<% "$key$n" %>">
223 <option selected>----------------------------------------------------------------</option>
225 % foreach my $line ( $conf->config($key, $agentnum) ) {
227 <option value="<% $line %>"><% $line %></option>
232 <input type="button" value="remove selected" onClick="doremove<% "$key$n" %>()">
233 <script>SafeAddOnLoad(doremove<% "$key$n" %>);
234 SafeAddOnSubmit(selectall<% "$key$n" %>);
236 <br><% itable() %><tr>
238 % if ( defined $config_item->editlist_parts ) {
240 % foreach my $part ( @{$config_item->editlist_parts} ) {
244 % if ( $part->{type} eq 'text' ) {
246 <input type="text" name="add<% "$key${n}_$pnum" %>">
248 % } elsif ( $part->{type} eq 'immutable' ) {
251 <input type="hidden" name="add<% "$key${n}_$pnum" %>" value="<% $part->{value} %>">
253 % } elsif ( $part->{type} eq 'select' ) {
255 <select name="add<% qq!$key${n}_$pnum! %>">
257 % foreach my $key ( keys %{$part->{select_enum}} ) {
259 <option value="<% $key %>"><% $part->{select_enum}{$key} %></option>
267 <font color="#ff0000">unknown type <% $part->type %> </font>
277 <td><input type="text" name="add<% "$key${n}_0" %>></td>
281 <td><input type="button" value="add" onClick="doadd<% "$key$n" %>(this.form)"></td>
284 % } elsif ( $element_types{$type} ) {
286 % my %opt = ( 'element_name' => "$key$n",
287 % 'empty_label' => ' ',
288 % 'showdisabled' => 1,
290 % if ( $config_item->multiple ) {
291 % $opt{'multiple'} = 1 if $config_item->multiple;
292 % $opt{'curr_value'} = [ $conf->config($key, $agentnum) ];
294 % $opt{'curr_value'} =
295 % $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : '';
298 <% include("/elements/$type.html", %opt ) %>
302 <font color="#ff0000">unknown type <% $type %></font>
309 % unless ( $description_printed ) {
310 <td><% $description %></td>
314 <INPUT TYPE="submit" VALUE="<% $title %>">
321 my $conf = new FS::Conf;
322 my @config_items = $conf->config_items;
323 my %confitems = map { $_->key => $_ } @config_items;
325 my %element_types = map { $_ => 1 } qw(
326 select-part_svc select-part_pkg select-pkg_class
333 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
338 if ($cgi->param('agentnum') =~ /(\d+)$/) {
345 $agent = qsearchs('agent', { 'agentnum' => $1 } );
346 die "Agent $agentnum not found!" unless $agent;
348 $title = "$action configuration override for ". $agent->agent;
350 $title = "$action global configuration";
353 $cgi->param('key') =~ /^([-.\w]+)$/ or die "illegal configuration item";
355 my $value = $conf->config($key);
356 my $config_item = $confitems{$key};
358 my $description = $config_item->description;
359 my $config_type = $config_item->type;
360 my @types = ref($config_type) ? @$config_type : ($config_type);