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',
88 % '' => '', @{ $config_item->select_hash };
90 % tie %hash, 'Tie::IxHash',
91 % '' => '', %{ $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" %>"><option value="">
138 % my %options = &{$config_item->options_sub};
139 % my @options = sort { $a <=> $b } keys %options;
141 % foreach my $value ( @options ) {
142 % local($^W)=0; next if $saw{$value}++;
144 <option value="<% $value %>" <% $value eq $conf->config($key, $agentnum) ? 'SELECTED' : '' %>><% $value %>: <% $options{$value} %>
147 % my $curvalue = $conf->config($key, $agentnum);
148 % if ( $conf->exists($key, $agentnum) && $curvalue && ! $options{$curvalue} ) {
150 <option value="<% $curvalue %>" SELECTED> <% $curvalue %>: <% &{ $config_item->option_sub }( $curvalue ) %>
156 % } elsif ( $type eq 'editlist' ) {
159 function doremove<% "$key$n" %>() {
160 fromObject = document.OneTrueForm.<% "$key$n" %>;
161 for (var i=fromObject.options.length-1;i>-1;i--) {
162 if (fromObject.options[i].selected)
163 deleteOption<% "$key$n" %>(fromObject,i);
166 function deleteOption<% "$key$n" %>(object,index) {
167 object.options[index] = null;
169 function selectall<% "$key$n" %>() {
170 fromObject = document.OneTrueForm.<% "$key$n" %>;
171 for (var i=fromObject.options.length-1;i>-1;i--) {
172 fromObject.options[i].selected = true;
175 function doadd<% "$key$n" %>(object) {
178 % if ( defined($config_item->editlist_parts) ) {
179 % foreach my $pnum ( 0 .. scalar(@{$config_item->editlist_parts})-1 ) {
181 if ( myvalue != "" ) { myvalue = myvalue + " "; }
183 % if ( $config_item->editlist_parts->[$pnum]{type} eq 'select' ) {
185 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.options[object.add<% "$key${n}_$pnum" %>.selectedIndex].value
186 <!-- #RESET SELECT?? maybe not... -->
188 % } elsif ( $config_item->editlist_parts->[$pnum]{type} eq 'immutable' ) {
190 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
194 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
195 object.add<% "$key${n}_$pnum" %>.value = ""
201 myvalue = object.add<% "$key${n}_1" %>.value
205 var optionName = new Option(myvalue, myvalue);
206 var length = object.<% "$key$n" %>.length;
207 object.<% "$key$n" %>.options[length] = optionName;
210 <select multiple size=5 name="<% "$key$n" %>">
211 <option selected>----------------------------------------------------------------</option>
213 % foreach my $line ( $conf->config($key, $agentnum) ) {
215 <option value="<% $line %>"><% $line %></option>
220 <input type="button" value="remove selected" onClick="doremove<% "$key$n" %>()">
221 <script>SafeAddOnLoad(doremove<% "$key$n" %>);
222 SafeAddOnSubmit(selectall<% "$key$n" %>);
224 <br><% itable() %><tr>
226 % if ( defined $config_item->editlist_parts ) {
228 % foreach my $part ( @{$config_item->editlist_parts} ) {
232 % if ( $part->{type} eq 'text' ) {
234 <input type="text" name="add<% "$key${n}_$pnum" %>">
236 % } elsif ( $part->{type} eq 'immutable' ) {
239 <input type="hidden" name="add<% "$key${n}_$pnum" %>" value="<% $part->{value} %>">
241 % } elsif ( $part->{type} eq 'select' ) {
243 <select name="add<% qq!$key${n}_$pnum! %>">
245 % foreach my $key ( keys %{$part->{select_enum}} ) {
247 <option value="<% $key %>"><% $part->{select_enum}{$key} %></option>
255 <font color="#ff0000">unknown type <% $part->type %> </font>
265 <td><input type="text" name="add<% "$key${n}_0" %>></td>
269 <td><input type="button" value="add" onClick="doadd<% "$key$n" %>(this.form)"></td>
274 <font color="#ff0000">unknown type <% $type %></font>
281 % unless ( $description_printed ) {
282 <td><% $description %></td>
286 <INPUT TYPE="submit" VALUE="<% $title %>">
293 my $conf = new FS::Conf;
294 my @config_items = grep { $_->key != ~/^invoice_(html|latex|template)/ }
296 my %confitems = map { $_->key => $_ } @config_items;
302 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
307 if ($cgi->param('agentnum') =~ /(\d+)$/) {
314 $agent = qsearchs('agent', { 'agentnum' => $1 } );
315 die "Agent $agentnum not found!" unless $agent;
317 $title = "$action configuration override for ". $agent->agent;
319 $title = "$action global configuration";
322 $cgi->param('key') =~ /^([-.\w]+)$/ or die "illegal configuration item";
324 my $value = $conf->config($key);
325 my $config_item = $confitems{$key};
327 my $description = $config_item->description;
328 my $config_type = $config_item->type;
329 my @types = ref($config_type) ? @$config_type : ($config_type);