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="locale" VALUE="<% $locale %>">
28 <INPUT TYPE="hidden" NAME="key" VALUE="<% $key %>">
30 Setting <b><% $key %></b>
32 % my $description_printed = 0;
33 % if ( grep $_ eq 'textarea', @types ) {
34 % $description_printed = 1;
44 % foreach my $type (@types) {
45 % if ( $type eq '' ) {
47 <font color="#ff0000">no type</font>
49 % } elsif ( $type eq 'image' ) {
52 <% $conf->exists($key, $agentnum)
53 ? 'Current image<br>'.
54 '<img src="config-image.cgi?key='. $key.
55 ';agentnum='. $agentnum.
56 ';locale='. $locale .'"><br>'
61 New image filename <input type="file" name="<% "$key$n" %>">
63 % } elsif ( $type eq 'binary' ) {
66 Filename <input type="file" name="<% "$key$n" %>">
68 % } elsif ( $type eq 'textarea' ) {
71 <textarea name="<% "$key$n" %>" rows=12 cols=78 wrap="off"><% join("\n", $conf->config($key, $agentnum)) |h %></textarea>
73 % } elsif ( $type eq 'checkbox' ) {
75 % if ( $agentnum && $conf->exists($key) && ! $agent_bool ) {
77 <input name="<% "$key$n" %>" type="checkbox" value="1" CHECKED DISABLED>
78 <FONT SIZE="-1"><I>(global setting cannot yet be overridden)</I></FONT>
83 <input name="<% "$key$n" %>" type="checkbox" value="1"
84 <% $conf->config_bool($key, $agentnum) ? 'CHECKED' : '' %> >
87 % } elsif ( $type eq 'text' ) {
90 <input name="<% "$key$n" %>" type="text" value="<% $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : '' |h %>">
92 % } elsif ( $type eq 'select' || $type eq 'selectmultiple' ) {
95 <select name="<% "$key$n" %>" <% $type eq 'selectmultiple' ? 'MULTIPLE' : '' %>>
99 % if ( $config_item->select_enum ) {
100 % tie %hash, 'Tie::IxHash',
101 % '' => '', map { $_ => $_ } @{ $config_item->select_enum };
102 % } elsif ( $config_item->select_hash ) {
103 % if ( ref($config_item->select_hash) eq 'ARRAY' ) {
104 % tie %hash, 'Tie::IxHash', '' => '', @{ $config_item->select_hash };
106 % tie %hash, 'Tie::IxHash', '' => '', %{ $config_item->select_hash };
109 % %hash = ( '' => 'WARNING: neither select_enum nor select_hash specified in Conf.pm for configuration option "'. $key. '"' );
113 % foreach my $value ( keys %hash ) {
114 % local($^W)=0; next if $saw{$value}++;
115 % my $label = $hash{$value};
118 <option value="<% $value %>"
120 % if ( $value eq $conf->config($key, $agentnum)
121 % || ( $type eq 'selectmultiple'
122 % && grep { $_ eq $value } $conf->config($key, $agentnum) ) ) {
131 % my $curvalue = $conf->config($key, $agentnum);
132 % if ( $conf->exists($key, $agentnum) && $curvalue && ! $hash{$curvalue} ) {
134 <option value="<% $curvalue %>" SELECTED>
136 % if ( exists( $hash{ $conf->config($key, $agentnum) } ) ) {
138 <% $hash{ $conf->config($key, $agentnum) } %>
149 % } elsif ( $type eq 'select-sub' ) {
152 <select name="<% "$key$n" %>" <% $config_item->multiple ? 'MULTIPLE' : '' %>>
154 % unless ( $config_item->multiple ) {
158 % my %options = &{$config_item->options_sub};
159 % my @options = keys %options;
160 % my $sortsub = $config_item->sort_sub || sub { $a <=> $b };
161 % @options = sort $sortsub @options;
163 % foreach my $value ( @options ) {
164 % local($^W)=0; next if $saw{$value}++;
166 <option value="<% $value %>"
168 % if ( $value eq $conf->config($key, $agentnum)
169 % || ( $config_item->multiple
170 % && grep { $_ eq $value } $conf->config($key, $agentnum) ) ){
176 ><% $value %>: <% $options{$value} %>
179 % my $curvalue = $conf->config($key, $agentnum);
180 % if ( $conf->exists($key, $agentnum) && $curvalue && ! $options{$curvalue} ) {
182 <option value="<% $curvalue %>" SELECTED> <% $curvalue %>: <% &{ $config_item->option_sub }( $curvalue ) %>
188 % } elsif ( $type eq 'editlist' ) {
191 function doremove<% "$key$n" %>() {
192 fromObject = document.OneTrueForm.<% "$key$n" %>;
193 for (var i=fromObject.options.length-1;i>-1;i--) {
194 if (fromObject.options[i].selected)
195 deleteOption<% "$key$n" %>(fromObject,i);
198 function deleteOption<% "$key$n" %>(object,index) {
199 object.options[index] = null;
201 function selectall<% "$key$n" %>() {
202 fromObject = document.OneTrueForm.<% "$key$n" %>;
203 for (var i=fromObject.options.length-1;i>-1;i--) {
204 fromObject.options[i].selected = true;
207 function doadd<% "$key$n" %>(object) {
210 % if ( defined($config_item->editlist_parts) ) {
211 % foreach my $pnum ( 0 .. scalar(@{$config_item->editlist_parts})-1 ) {
213 if ( myvalue != "" ) { myvalue = myvalue + " "; }
215 % if ( $config_item->editlist_parts->[$pnum]{type} eq 'select' ) {
217 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.options[object.add<% "$key${n}_$pnum" %>.selectedIndex].value
218 <!-- #RESET SELECT?? maybe not... -->
220 % } elsif ( $config_item->editlist_parts->[$pnum]{type} eq 'immutable' ) {
222 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
226 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
227 object.add<% "$key${n}_$pnum" %>.value = ""
233 myvalue = object.add<% "$key${n}_1" %>.value
237 var optionName = new Option(myvalue, myvalue);
238 var length = object.<% "$key$n" %>.length;
239 object.<% "$key$n" %>.options[length] = optionName;
242 <select multiple size=5 name="<% "$key$n" %>">
243 <option selected>----------------------------------------------------------------</option>
245 % foreach my $line ( $conf->config($key, $agentnum) ) {
247 <option value="<% $line %>"><% $line %></option>
252 <input type="button" value="remove selected" onClick="doremove<% "$key$n" %>()">
253 <script>SafeAddOnLoad(doremove<% "$key$n" %>);
254 SafeAddOnSubmit(selectall<% "$key$n" %>);
256 <br><% itable() %><tr>
258 % if ( defined $config_item->editlist_parts ) {
260 % foreach my $part ( @{$config_item->editlist_parts} ) {
264 % if ( $part->{type} eq 'text' ) {
266 <input type="text" name="add<% "$key${n}_$pnum" %>">
268 % } elsif ( $part->{type} eq 'immutable' ) {
271 <input type="hidden" name="add<% "$key${n}_$pnum" %>" value="<% $part->{value} %>">
273 % } elsif ( $part->{type} eq 'select' ) {
275 <select name="add<% qq!$key${n}_$pnum! %>">
277 % foreach my $key ( keys %{$part->{select_enum}} ) {
279 <option value="<% $key %>"><% $part->{select_enum}{$key} %></option>
287 <font color="#ff0000">unknown type <% $part->type %> </font>
297 <td><input type="text" name="add<% "$key${n}_0" %>></td>
301 <td><input type="button" value="add" onClick="doadd<% "$key$n" %>(this.form)"></td>
304 % } elsif ( $element_types{$type} ) {
307 % my %opt = ( 'element_name' => "$key$n",
308 % 'empty_label' => ' ',
310 % if ( $config_item->multiple ) {
311 % $opt{'multiple'} = 1 if $config_item->multiple;
312 % $opt{'curr_value'} = [ $conf->config($key, $agentnum) ];
314 % $opt{'curr_value'} =
315 % $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : '';
318 <% include("/elements/$type.html", %opt ) %>
322 <font color="#ff0000">unknown type <% $type %></font>
329 % unless ( $description_printed ) {
330 <td><% $description %></td>
336 <INPUT TYPE="submit" VALUE="<% $title %>">
344 my %element_types = map { $_ => 1 } qw(
345 select-part_svc select-part_pkg select-pkg_class select-agent
352 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
357 if ($cgi->param('agentnum') =~ /(\d+)$/) {
362 if ( $cgi->param('locale') =~ /^(\w+_\w+)$/) {
366 my $conf = new FS::Conf { 'locale' => $locale, 'localeonly' => 1 };
367 my @config_items = $conf->config_items;
368 my %confitems = map { $_->key => $_ } @config_items;
373 $agent = qsearchs('agent', { 'agentnum' => $1 } );
374 die "Agent $agentnum not found!" unless $agent;
376 $title = "$action configuration override for ". $agent->agent;
378 $title = "$action global configuration";
381 $cgi->param('key') =~ /^([-.\w]+)$/ or die "illegal configuration item";
383 my $value = $conf->config($key);
384 my $config_item = $confitems{$key};
386 my $description = $config_item->description;
387 my $config_type = $config_item->type;
388 my @types = ref($config_type) ? @$config_type : ($config_type);
389 my $agent_bool = $config_item->agent_bool;