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 %>">
37 % foreach my $type ( ref($config_item->type) ? @{$config_item->type} : $config_item->type ) {
38 % if ( $type eq '' ) {
40 <font color="#ff0000">no type</font>
42 % } elsif ( $type eq 'binary' ) {
44 Filename <input type="file" name="<% "$key$n" %>">
46 % } elsif ( $type eq 'textarea' ) {
48 <textarea name="<% "$key$n" %>" rows=5><% join("\n", $conf->config($key, $agentnum)) %></textarea>
50 % } elsif ( $type eq 'checkbox' ) {
52 <input name="<% "$key$n" %>" type="checkbox" value="1"
53 <% $conf->exists($key, $agentnum) ? 'CHECKED' : '' %> >
55 % } elsif ( $type eq 'text' ) {
57 <input name="<% "$key$n" %>" type="text" value="<% $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : '' %>">
59 % } elsif ( $type eq 'select' || $type eq 'selectmultiple' ) {
61 <select name="<% "$key$n" %>" <% $type eq 'selectmultiple' ? 'MULTIPLE' : '' %>>
65 % if ( $config_item->select_enum ) {
66 % tie %hash, 'Tie::IxHash',
67 % '' => '', map { $_ => $_ } @{ $config_item->select_enum };
68 % } elsif ( $config_item->select_hash ) {
69 % if ( ref($config_item->select_hash) eq 'ARRAY' ) {
70 % tie %hash, 'Tie::IxHash',
71 % '' => '', @{ $config_item->select_hash };
73 % tie %hash, 'Tie::IxHash',
74 % '' => '', %{ $config_item->select_hash };
77 % %hash = ( '' => 'WARNING: neither select_enum nor select_hash specified in Conf.pm for configuration option "'. $key. '"' );
81 % foreach my $value ( keys %hash ) {
82 % local($^W)=0; next if $saw{$value}++;
83 % my $label = $hash{$value};
86 <option value="<% $value %>"
88 % if ( $value eq $conf->config($key, $agentnum)
89 % || ( $type eq 'selectmultiple'
90 % && grep { $_ eq $value } $conf->config($key, $agentnum) ) ) {
99 % my $curvalue = $conf->config($key, $agentnum);
100 % if ( $conf->exists($key, $agentnum) && $curvalue && ! $hash{$curvalue} ) {
102 <option value="<% $curvalue %>" SELECTED>
104 % if ( exists( $hash{ $conf->config($key, $agentnum) } ) ) {
106 <% $hash{ $conf->config($key, $agentnum) } %>
117 % } elsif ( $type eq 'select-sub' ) {
119 <select name="<% "$key$n" %>"><option value="">
121 % my %options = &{$config_item->options_sub};
122 % my @options = sort { $a <=> $b } keys %options;
124 % foreach my $value ( @options ) {
125 % local($^W)=0; next if $saw{$value}++;
127 <option value="<% $value %>" <% $value eq $conf->config($key, $agentnum) ? 'SELECTED' : '' %>><% $value %>: <% $options{$value} %>
130 % my $curvalue = $conf->config($key, $agentnum);
131 % if ( $conf->exists($key, $agentnum) && $curvalue && ! $options{$curvalue} ) {
133 <option value="<% $curvalue %>" SELECTED> <% $curvalue %>: <% &{ $config_item->option_sub }( $curvalue ) %>
139 % } elsif ( $type eq 'editlist' ) {
142 function doremove<% "$key$n" %>() {
143 fromObject = document.OneTrueForm.<% "$key$n" %>;
144 for (var i=fromObject.options.length-1;i>-1;i--) {
145 if (fromObject.options[i].selected)
146 deleteOption<% "$key$n" %>(fromObject,i);
149 function deleteOption<% "$key$n" %>(object,index) {
150 object.options[index] = null;
152 function selectall<% "$key$n" %>() {
153 fromObject = document.OneTrueForm.<% "$key$n" %>;
154 for (var i=fromObject.options.length-1;i>-1;i--) {
155 fromObject.options[i].selected = true;
158 function doadd<% "$key$n" %>(object) {
161 % if ( defined($config_item->editlist_parts) ) {
162 % foreach my $pnum ( 0 .. scalar(@{$config_item->editlist_parts})-1 ) {
164 if ( myvalue != "" ) { myvalue = myvalue + " "; }
166 % if ( $config_item->editlist_parts->[$pnum]{type} eq 'select' ) {
168 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.options[object.add<% "$key${n}_$pnum" %>.selectedIndex].value
169 <!-- #RESET SELECT?? maybe not... -->
171 % } elsif ( $config_item->editlist_parts->[$pnum]{type} eq 'immutable' ) {
173 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
177 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
178 object.add<% "$key${n}_$pnum" %>.value = ""
184 myvalue = object.add<% "$key${n}_1" %>.value
188 var optionName = new Option(myvalue, myvalue);
189 var length = object.<% "$key$n" %>.length;
190 object.<% "$key$n" %>.options[length] = optionName;
193 <select multiple size=5 name="<% "$key$n" %>">
194 <option selected>----------------------------------------------------------------</option>
196 % foreach my $line ( $conf->config($key, $agentnum) ) {
198 <option value="<% $line %>"><% $line %></option>
203 <input type="button" value="remove selected" onClick="doremove<% "$key$n" %>()">
204 <script>SafeAddOnLoad(doremove<% "$key$n" %>);
205 SafeAddOnSubmit(selectall<% "$key$n" %>);
207 <br><% itable() %><tr>
209 % if ( defined $config_item->editlist_parts ) {
211 % foreach my $part ( @{$config_item->editlist_parts} ) {
215 % if ( $part->{type} eq 'text' ) {
217 <input type="text" name="add<% "$key${n}_$pnum" %>">
219 % } elsif ( $part->{type} eq 'immutable' ) {
222 <input type="hidden" name="add<% "$key${n}_$pnum" %>" value="<% $part->{value} %>">
224 % } elsif ( $part->{type} eq 'select' ) {
226 <select name="add<% qq!$key${n}_$pnum! %>">
228 % foreach my $key ( keys %{$part->{select_enum}} ) {
230 <option value="<% $key %>"><% $part->{select_enum}{$key} %></option>
238 <font color="#ff0000">unknown type <% $part->type %> </font>
248 <td><input type="text" name="add<% "$key${n}_0" %>></td>
252 <td><input type="button" value="add" onClick="doadd<% "$key$n" %>(this.form)"></td>
257 <font color="#ff0000">unknown type $type</font>
263 </td><td><% $description %></td></tr></table>
264 <INPUT TYPE="submit" VALUE="<% $title %>">
271 my $conf = new FS::Conf;
272 my @config_items = grep { $_->key != ~/^invoice_(html|latex|template)/ }
274 my %confitems = map { $_->key => $_ } @config_items;
280 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
282 my($agentnum, $agent, $title, $action, $key, $value, $config_item,
283 $description, $type);
287 if ($cgi->param('agentnum') =~ /(\d+)$/) {
292 $agent = qsearchs('agent', { 'agentnum' => $1 } );
293 die "Agent $agentnum not found!" unless $agent;
295 $title = "$action configuration override for ". $agent->agent;
297 $title = "$action global configuration";
300 $cgi->param('key') =~ /^([-.\w]+)$/ or die "illegal configuration item";
302 $value = $conf->config($key);
303 $config_item = $confitems{$key};
305 $description = $config_item->description;
306 $type = $config_item->type;