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;
43 % foreach my $type (@types) {
44 % if ( $type eq '' ) {
46 <font color="#ff0000">no type</font>
48 % } elsif ( $type eq 'image' ) {
50 <% $conf->exists($key, $agentnum)
51 ? 'Current image<br>'.
52 '<img src="config-image.cgi?key='. $key.
53 ';agentnum='. $agentnum.
54 ';locale='. $locale .'"><br>'
59 New image filename <input type="file" name="<% "$key$n" %>">
61 % } elsif ( $type eq 'binary' ) {
63 Filename <input type="file" name="<% "$key$n" %>">
65 % } elsif ( $type eq 'textarea' ) {
67 <textarea name="<% "$key$n" %>" rows=12 cols=78 wrap="off"><% join("\n", $conf->config($key, $agentnum)) |h %></textarea>
69 % } elsif ( $type eq 'checkbox' ) {
71 <input name="<% "$key$n" %>" type="checkbox" value="1"
72 <% $conf->exists($key, $agentnum) ? 'CHECKED' : '' %> >
74 % } elsif ( $type eq 'text' ) {
76 <input name="<% "$key$n" %>" type="text" value="<% $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : '' |h %>">
78 % } elsif ( $type eq 'select' || $type eq 'selectmultiple' ) {
80 <select name="<% "$key$n" %>" <% $type eq 'selectmultiple' ? 'MULTIPLE' : '' %>>
84 % if ( $config_item->select_enum ) {
85 % tie %hash, 'Tie::IxHash',
86 % '' => '', map { $_ => $_ } @{ $config_item->select_enum };
87 % } elsif ( $config_item->select_hash ) {
88 % if ( ref($config_item->select_hash) eq 'ARRAY' ) {
89 % tie %hash, 'Tie::IxHash', '' => '', @{ $config_item->select_hash };
91 % tie %hash, 'Tie::IxHash', '' => '', %{ $config_item->select_hash };
94 % %hash = ( '' => 'WARNING: neither select_enum nor select_hash specified in Conf.pm for configuration option "'. $key. '"' );
98 % foreach my $value ( keys %hash ) {
99 % local($^W)=0; next if $saw{$value}++;
100 % my $label = $hash{$value};
103 <option value="<% $value %>"
105 % if ( $value eq $conf->config($key, $agentnum)
106 % || ( $type eq 'selectmultiple'
107 % && grep { $_ eq $value } $conf->config($key, $agentnum) ) ) {
116 % my $curvalue = $conf->config($key, $agentnum);
117 % if ( $conf->exists($key, $agentnum) && $curvalue && ! $hash{$curvalue} ) {
119 <option value="<% $curvalue %>" SELECTED>
121 % if ( exists( $hash{ $conf->config($key, $agentnum) } ) ) {
123 <% $hash{ $conf->config($key, $agentnum) } %>
134 % } elsif ( $type eq 'select-sub' ) {
136 <select name="<% "$key$n" %>" <% $config_item->multiple ? 'MULTIPLE' : '' %>>
138 % unless ( $config_item->multiple ) {
142 % my %options = &{$config_item->options_sub};
143 % my @options = sort { $a <=> $b } keys %options;
145 % foreach my $value ( @options ) {
146 % local($^W)=0; next if $saw{$value}++;
148 <option value="<% $value %>"
150 % if ( $value eq $conf->config($key, $agentnum)
151 % || ( $config_item->multiple
152 % && grep { $_ eq $value } $conf->config($key, $agentnum) ) ){
158 ><% $value %>: <% $options{$value} %>
161 % my $curvalue = $conf->config($key, $agentnum);
162 % if ( $conf->exists($key, $agentnum) && $curvalue && ! $options{$curvalue} ) {
164 <option value="<% $curvalue %>" SELECTED> <% $curvalue %>: <% &{ $config_item->option_sub }( $curvalue ) %>
170 % } elsif ( $type eq 'editlist' ) {
173 function doremove<% "$key$n" %>() {
174 fromObject = document.OneTrueForm.<% "$key$n" %>;
175 for (var i=fromObject.options.length-1;i>-1;i--) {
176 if (fromObject.options[i].selected)
177 deleteOption<% "$key$n" %>(fromObject,i);
180 function deleteOption<% "$key$n" %>(object,index) {
181 object.options[index] = null;
183 function selectall<% "$key$n" %>() {
184 fromObject = document.OneTrueForm.<% "$key$n" %>;
185 for (var i=fromObject.options.length-1;i>-1;i--) {
186 fromObject.options[i].selected = true;
189 function doadd<% "$key$n" %>(object) {
192 % if ( defined($config_item->editlist_parts) ) {
193 % foreach my $pnum ( 0 .. scalar(@{$config_item->editlist_parts})-1 ) {
195 if ( myvalue != "" ) { myvalue = myvalue + " "; }
197 % if ( $config_item->editlist_parts->[$pnum]{type} eq 'select' ) {
199 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.options[object.add<% "$key${n}_$pnum" %>.selectedIndex].value
200 <!-- #RESET SELECT?? maybe not... -->
202 % } elsif ( $config_item->editlist_parts->[$pnum]{type} eq 'immutable' ) {
204 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
208 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
209 object.add<% "$key${n}_$pnum" %>.value = ""
215 myvalue = object.add<% "$key${n}_1" %>.value
219 var optionName = new Option(myvalue, myvalue);
220 var length = object.<% "$key$n" %>.length;
221 object.<% "$key$n" %>.options[length] = optionName;
224 <select multiple size=5 name="<% "$key$n" %>">
225 <option selected>----------------------------------------------------------------</option>
227 % foreach my $line ( $conf->config($key, $agentnum) ) {
229 <option value="<% $line %>"><% $line %></option>
234 <input type="button" value="remove selected" onClick="doremove<% "$key$n" %>()">
235 <script>SafeAddOnLoad(doremove<% "$key$n" %>);
236 SafeAddOnSubmit(selectall<% "$key$n" %>);
238 <br><% itable() %><tr>
240 % if ( defined $config_item->editlist_parts ) {
242 % foreach my $part ( @{$config_item->editlist_parts} ) {
246 % if ( $part->{type} eq 'text' ) {
248 <input type="text" name="add<% "$key${n}_$pnum" %>">
250 % } elsif ( $part->{type} eq 'immutable' ) {
253 <input type="hidden" name="add<% "$key${n}_$pnum" %>" value="<% $part->{value} %>">
255 % } elsif ( $part->{type} eq 'select' ) {
257 <select name="add<% qq!$key${n}_$pnum! %>">
259 % foreach my $key ( keys %{$part->{select_enum}} ) {
261 <option value="<% $key %>"><% $part->{select_enum}{$key} %></option>
269 <font color="#ff0000">unknown type <% $part->type %> </font>
279 <td><input type="text" name="add<% "$key${n}_0" %>></td>
283 <td><input type="button" value="add" onClick="doadd<% "$key$n" %>(this.form)"></td>
286 % } elsif ( $element_types{$type} ) {
288 % my %opt = ( 'element_name' => "$key$n",
289 % 'empty_label' => ' ',
290 % 'showdisabled' => 1,
292 % if ( $config_item->multiple ) {
293 % $opt{'multiple'} = 1 if $config_item->multiple;
294 % $opt{'curr_value'} = [ $conf->config($key, $agentnum) ];
296 % $opt{'curr_value'} =
297 % $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : '';
300 <% include("/elements/$type.html", %opt ) %>
304 <font color="#ff0000">unknown type <% $type %></font>
311 % unless ( $description_printed ) {
312 <td><% $description %></td>
316 <INPUT TYPE="submit" VALUE="<% $title %>">
323 my %element_types = map { $_ => 1 } qw(
324 select-part_svc select-part_pkg select-pkg_class select-agent
331 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
336 if ($cgi->param('agentnum') =~ /(\d+)$/) {
341 if ( $cgi->param('locale') =~ /^(\w+_\w+)$/) {
345 my $conf = new FS::Conf { 'locale' => $locale, 'localeonly' => 1 };
346 my @config_items = $conf->config_items;
347 my %confitems = map { $_->key => $_ } @config_items;
352 $agent = qsearchs('agent', { 'agentnum' => $1 } );
353 die "Agent $agentnum not found!" unless $agent;
355 $title = "$action configuration override for ". $agent->agent;
357 $title = "$action global configuration";
360 $cgi->param('key') =~ /^([-.\w]+)$/ or die "illegal configuration item";
362 my $value = $conf->config($key);
363 my $config_item = $confitems{$key};
365 my $description = $config_item->description;
366 my $config_type = $config_item->type;
367 my @types = ref($config_type) ? @$config_type : ($config_type);