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 % if ( $cgi->param('error') ) {
24 <FONT SIZE="+1" COLOR="#ff0000">Error: <% $cgi->param('error') %></FONT>
28 <FORM NAME="OneTrueForm" ACTION="config-process.cgi" METHOD="POST" enctype="multipart/form-data" onSubmit="SafeOnsubmit()">
29 <INPUT TYPE="hidden" NAME="agentnum" VALUE="<% $agentnum %>">
30 <INPUT TYPE="hidden" NAME="key" VALUE="<% $key %>">
32 Setting <b><% $key %></b>
34 % my $description_printed = 0;
35 % if ( grep $_ eq 'textarea', @types ) {
36 % $description_printed = 1;
45 % foreach my $type (@types) {
46 % if ( $type eq '' ) {
48 <font color="#ff0000">no type</font>
50 % } elsif ( $type eq 'binary' ) {
52 Filename <input type="file" name="<% "$key$n" %>">
54 % } elsif ( $type eq 'textarea' ) {
56 <textarea name="<% "$key$n" %>" rows=18 cols=88 wrap="off"><% join("\n", $conf->config($key, $agentnum)) %></textarea>
58 % } elsif ( $type eq 'checkbox' ) {
60 <input name="<% "$key$n" %>" type="checkbox" value="1"
61 <% $conf->exists($key, $agentnum) ? 'CHECKED' : '' %> >
63 % } elsif ( $type eq 'text' ) {
65 <input name="<% "$key$n" %>" type="text" value="<% $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : '' %>">
67 % } elsif ( $type eq 'select' || $type eq 'selectmultiple' ) {
69 <select name="<% "$key$n" %>" <% $type eq 'selectmultiple' ? 'MULTIPLE' : '' %>>
73 % if ( $config_item->select_enum ) {
74 % tie %hash, 'Tie::IxHash',
75 % '' => '', map { $_ => $_ } @{ $config_item->select_enum };
76 % } elsif ( $config_item->select_hash ) {
77 % if ( ref($config_item->select_hash) eq 'ARRAY' ) {
78 % tie %hash, 'Tie::IxHash',
79 % '' => '', @{ $config_item->select_hash };
81 % tie %hash, 'Tie::IxHash',
82 % '' => '', %{ $config_item->select_hash };
85 % %hash = ( '' => 'WARNING: neither select_enum nor select_hash specified in Conf.pm for configuration option "'. $key. '"' );
89 % foreach my $value ( keys %hash ) {
90 % local($^W)=0; next if $saw{$value}++;
91 % my $label = $hash{$value};
94 <option value="<% $value %>"
96 % if ( $value eq $conf->config($key, $agentnum)
97 % || ( $type eq 'selectmultiple'
98 % && grep { $_ eq $value } $conf->config($key, $agentnum) ) ) {
107 % my $curvalue = $conf->config($key, $agentnum);
108 % if ( $conf->exists($key, $agentnum) && $curvalue && ! $hash{$curvalue} ) {
110 <option value="<% $curvalue %>" SELECTED>
112 % if ( exists( $hash{ $conf->config($key, $agentnum) } ) ) {
114 <% $hash{ $conf->config($key, $agentnum) } %>
125 % } elsif ( $type eq 'select-sub' ) {
127 <select name="<% "$key$n" %>"><option value="">
129 % my %options = &{$config_item->options_sub};
130 % my @options = sort { $a <=> $b } keys %options;
132 % foreach my $value ( @options ) {
133 % local($^W)=0; next if $saw{$value}++;
135 <option value="<% $value %>" <% $value eq $conf->config($key, $agentnum) ? 'SELECTED' : '' %>><% $value %>: <% $options{$value} %>
138 % my $curvalue = $conf->config($key, $agentnum);
139 % if ( $conf->exists($key, $agentnum) && $curvalue && ! $options{$curvalue} ) {
141 <option value="<% $curvalue %>" SELECTED> <% $curvalue %>: <% &{ $config_item->option_sub }( $curvalue ) %>
147 % } elsif ( $type eq 'editlist' ) {
150 function doremove<% "$key$n" %>() {
151 fromObject = document.OneTrueForm.<% "$key$n" %>;
152 for (var i=fromObject.options.length-1;i>-1;i--) {
153 if (fromObject.options[i].selected)
154 deleteOption<% "$key$n" %>(fromObject,i);
157 function deleteOption<% "$key$n" %>(object,index) {
158 object.options[index] = null;
160 function selectall<% "$key$n" %>() {
161 fromObject = document.OneTrueForm.<% "$key$n" %>;
162 for (var i=fromObject.options.length-1;i>-1;i--) {
163 fromObject.options[i].selected = true;
166 function doadd<% "$key$n" %>(object) {
169 % if ( defined($config_item->editlist_parts) ) {
170 % foreach my $pnum ( 0 .. scalar(@{$config_item->editlist_parts})-1 ) {
172 if ( myvalue != "" ) { myvalue = myvalue + " "; }
174 % if ( $config_item->editlist_parts->[$pnum]{type} eq 'select' ) {
176 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.options[object.add<% "$key${n}_$pnum" %>.selectedIndex].value
177 <!-- #RESET SELECT?? maybe not... -->
179 % } elsif ( $config_item->editlist_parts->[$pnum]{type} eq 'immutable' ) {
181 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
185 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
186 object.add<% "$key${n}_$pnum" %>.value = ""
192 myvalue = object.add<% "$key${n}_1" %>.value
196 var optionName = new Option(myvalue, myvalue);
197 var length = object.<% "$key$n" %>.length;
198 object.<% "$key$n" %>.options[length] = optionName;
201 <select multiple size=5 name="<% "$key$n" %>">
202 <option selected>----------------------------------------------------------------</option>
204 % foreach my $line ( $conf->config($key, $agentnum) ) {
206 <option value="<% $line %>"><% $line %></option>
211 <input type="button" value="remove selected" onClick="doremove<% "$key$n" %>()">
212 <script>SafeAddOnLoad(doremove<% "$key$n" %>);
213 SafeAddOnSubmit(selectall<% "$key$n" %>);
215 <br><% itable() %><tr>
217 % if ( defined $config_item->editlist_parts ) {
219 % foreach my $part ( @{$config_item->editlist_parts} ) {
223 % if ( $part->{type} eq 'text' ) {
225 <input type="text" name="add<% "$key${n}_$pnum" %>">
227 % } elsif ( $part->{type} eq 'immutable' ) {
230 <input type="hidden" name="add<% "$key${n}_$pnum" %>" value="<% $part->{value} %>">
232 % } elsif ( $part->{type} eq 'select' ) {
234 <select name="add<% qq!$key${n}_$pnum! %>">
236 % foreach my $key ( keys %{$part->{select_enum}} ) {
238 <option value="<% $key %>"><% $part->{select_enum}{$key} %></option>
246 <font color="#ff0000">unknown type <% $part->type %> </font>
256 <td><input type="text" name="add<% "$key${n}_0" %>></td>
260 <td><input type="button" value="add" onClick="doadd<% "$key$n" %>(this.form)"></td>
265 <font color="#ff0000">unknown type $type</font>
272 % unless ( $description_printed ) {
273 <td><% $description %></td>
277 <INPUT TYPE="submit" VALUE="<% $title %>">
284 my $conf = new FS::Conf;
285 my @config_items = grep { $_->key != ~/^invoice_(html|latex|template)/ }
287 my %confitems = map { $_->key => $_ } @config_items;
293 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
298 if ($cgi->param('agentnum') =~ /(\d+)$/) {
305 $agent = qsearchs('agent', { 'agentnum' => $1 } );
306 die "Agent $agentnum not found!" unless $agent;
308 $title = "$action configuration override for ". $agent->agent;
310 $title = "$action global configuration";
313 $cgi->param('key') =~ /^([-.\w]+)$/ or die "illegal configuration item";
315 my $value = $conf->config($key);
316 my $config_item = $confitems{$key};
318 my $description = $config_item->description;
319 my $config_type = $config_item->type;
320 my @types = ref($config_type) ? @$config_type : ($config_type);