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 'binary' ) {
49 Filename <input type="file" name="<% "$key$n" %>">
51 % } elsif ( $type eq 'textarea' ) {
53 <textarea name="<% "$key$n" %>" rows=12 cols=78 wrap="off"><% join("\n", $conf->config($key, $agentnum)) %></textarea>
55 % } elsif ( $type eq 'checkbox' ) {
57 <input name="<% "$key$n" %>" type="checkbox" value="1"
58 <% $conf->exists($key, $agentnum) ? 'CHECKED' : '' %> >
60 % } elsif ( $type eq 'text' ) {
62 <input name="<% "$key$n" %>" type="text" value="<% $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : '' |h %>">
64 % } elsif ( $type eq 'select' || $type eq 'selectmultiple' ) {
66 <select name="<% "$key$n" %>" <% $type eq 'selectmultiple' ? 'MULTIPLE' : '' %>>
70 % if ( $config_item->select_enum ) {
71 % tie %hash, 'Tie::IxHash',
72 % '' => '', map { $_ => $_ } @{ $config_item->select_enum };
73 % } elsif ( $config_item->select_hash ) {
74 % if ( ref($config_item->select_hash) eq 'ARRAY' ) {
75 % tie %hash, 'Tie::IxHash',
76 % '' => '', @{ $config_item->select_hash };
78 % tie %hash, 'Tie::IxHash',
79 % '' => '', %{ $config_item->select_hash };
82 % %hash = ( '' => 'WARNING: neither select_enum nor select_hash specified in Conf.pm for configuration option "'. $key. '"' );
86 % foreach my $value ( keys %hash ) {
87 % local($^W)=0; next if $saw{$value}++;
88 % my $label = $hash{$value};
91 <option value="<% $value %>"
93 % if ( $value eq $conf->config($key, $agentnum)
94 % || ( $type eq 'selectmultiple'
95 % && grep { $_ eq $value } $conf->config($key, $agentnum) ) ) {
104 % my $curvalue = $conf->config($key, $agentnum);
105 % if ( $conf->exists($key, $agentnum) && $curvalue && ! $hash{$curvalue} ) {
107 <option value="<% $curvalue %>" SELECTED>
109 % if ( exists( $hash{ $conf->config($key, $agentnum) } ) ) {
111 <% $hash{ $conf->config($key, $agentnum) } %>
122 % } elsif ( $type eq 'select-sub' ) {
124 <select name="<% "$key$n" %>"><option value="">
126 % my %options = &{$config_item->options_sub};
127 % my @options = sort { $a <=> $b } keys %options;
129 % foreach my $value ( @options ) {
130 % local($^W)=0; next if $saw{$value}++;
132 <option value="<% $value %>" <% $value eq $conf->config($key, $agentnum) ? 'SELECTED' : '' %>><% $value %>: <% $options{$value} %>
135 % my $curvalue = $conf->config($key, $agentnum);
136 % if ( $conf->exists($key, $agentnum) && $curvalue && ! $options{$curvalue} ) {
138 <option value="<% $curvalue %>" SELECTED> <% $curvalue %>: <% &{ $config_item->option_sub }( $curvalue ) %>
144 % } elsif ( $type eq 'editlist' ) {
147 function doremove<% "$key$n" %>() {
148 fromObject = document.OneTrueForm.<% "$key$n" %>;
149 for (var i=fromObject.options.length-1;i>-1;i--) {
150 if (fromObject.options[i].selected)
151 deleteOption<% "$key$n" %>(fromObject,i);
154 function deleteOption<% "$key$n" %>(object,index) {
155 object.options[index] = null;
157 function selectall<% "$key$n" %>() {
158 fromObject = document.OneTrueForm.<% "$key$n" %>;
159 for (var i=fromObject.options.length-1;i>-1;i--) {
160 fromObject.options[i].selected = true;
163 function doadd<% "$key$n" %>(object) {
166 % if ( defined($config_item->editlist_parts) ) {
167 % foreach my $pnum ( 0 .. scalar(@{$config_item->editlist_parts})-1 ) {
169 if ( myvalue != "" ) { myvalue = myvalue + " "; }
171 % if ( $config_item->editlist_parts->[$pnum]{type} eq 'select' ) {
173 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.options[object.add<% "$key${n}_$pnum" %>.selectedIndex].value
174 <!-- #RESET SELECT?? maybe not... -->
176 % } elsif ( $config_item->editlist_parts->[$pnum]{type} eq 'immutable' ) {
178 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
182 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
183 object.add<% "$key${n}_$pnum" %>.value = ""
189 myvalue = object.add<% "$key${n}_1" %>.value
193 var optionName = new Option(myvalue, myvalue);
194 var length = object.<% "$key$n" %>.length;
195 object.<% "$key$n" %>.options[length] = optionName;
198 <select multiple size=5 name="<% "$key$n" %>">
199 <option selected>----------------------------------------------------------------</option>
201 % foreach my $line ( $conf->config($key, $agentnum) ) {
203 <option value="<% $line %>"><% $line %></option>
208 <input type="button" value="remove selected" onClick="doremove<% "$key$n" %>()">
209 <script>SafeAddOnLoad(doremove<% "$key$n" %>);
210 SafeAddOnSubmit(selectall<% "$key$n" %>);
212 <br><% itable() %><tr>
214 % if ( defined $config_item->editlist_parts ) {
216 % foreach my $part ( @{$config_item->editlist_parts} ) {
220 % if ( $part->{type} eq 'text' ) {
222 <input type="text" name="add<% "$key${n}_$pnum" %>">
224 % } elsif ( $part->{type} eq 'immutable' ) {
227 <input type="hidden" name="add<% "$key${n}_$pnum" %>" value="<% $part->{value} %>">
229 % } elsif ( $part->{type} eq 'select' ) {
231 <select name="add<% qq!$key${n}_$pnum! %>">
233 % foreach my $key ( keys %{$part->{select_enum}} ) {
235 <option value="<% $key %>"><% $part->{select_enum}{$key} %></option>
243 <font color="#ff0000">unknown type <% $part->type %> </font>
253 <td><input type="text" name="add<% "$key${n}_0" %>></td>
257 <td><input type="button" value="add" onClick="doadd<% "$key$n" %>(this.form)"></td>
262 <font color="#ff0000">unknown type $type</font>
269 % unless ( $description_printed ) {
270 <td><% $description %></td>
274 <INPUT TYPE="submit" VALUE="<% $title %>">
281 my $conf = new FS::Conf;
282 my @config_items = grep { $_->key != ~/^invoice_(html|latex|template)/ }
284 my %confitems = map { $_->key => $_ } @config_items;
290 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
295 if ($cgi->param('agentnum') =~ /(\d+)$/) {
302 $agent = qsearchs('agent', { 'agentnum' => $1 } );
303 die "Agent $agentnum not found!" unless $agent;
305 $title = "$action configuration override for ". $agent->agent;
307 $title = "$action global configuration";
310 $cgi->param('key') =~ /^([-.\w]+)$/ or die "illegal configuration item";
312 my $value = $conf->config($key);
313 my $config_item = $confitems{$key};
315 my $description = $config_item->description;
316 my $config_type = $config_item->type;
317 my @types = ref($config_type) ? @$config_type : ($config_type);