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', '' => '', @{ $config_item->select_hash };
89 % tie %hash, 'Tie::IxHash', '' => '', %{ $config_item->select_hash };
92 % %hash = ( '' => 'WARNING: neither select_enum nor select_hash specified in Conf.pm for configuration option "'. $key. '"' );
96 % foreach my $value ( keys %hash ) {
97 % local($^W)=0; next if $saw{$value}++;
98 % my $label = $hash{$value};
101 <option value="<% $value %>"
103 % if ( $value eq $conf->config($key, $agentnum)
104 % || ( $type eq 'selectmultiple'
105 % && grep { $_ eq $value } $conf->config($key, $agentnum) ) ) {
114 % my $curvalue = $conf->config($key, $agentnum);
115 % if ( $conf->exists($key, $agentnum) && $curvalue && ! $hash{$curvalue} ) {
117 <option value="<% $curvalue %>" SELECTED>
119 % if ( exists( $hash{ $conf->config($key, $agentnum) } ) ) {
121 <% $hash{ $conf->config($key, $agentnum) } %>
132 % } elsif ( $type eq 'select-sub' ) {
134 <select name="<% "$key$n" %>"><option value="">
136 % my %options = &{$config_item->options_sub};
137 % my @options = sort { $a <=> $b } keys %options;
139 % foreach my $value ( @options ) {
140 % local($^W)=0; next if $saw{$value}++;
142 <option value="<% $value %>" <% $value eq $conf->config($key, $agentnum) ? 'SELECTED' : '' %>><% $value %>: <% $options{$value} %>
145 % my $curvalue = $conf->config($key, $agentnum);
146 % if ( $conf->exists($key, $agentnum) && $curvalue && ! $options{$curvalue} ) {
148 <option value="<% $curvalue %>" SELECTED> <% $curvalue %>: <% &{ $config_item->option_sub }( $curvalue ) %>
154 % } elsif ( $type eq 'editlist' ) {
157 function doremove<% "$key$n" %>() {
158 fromObject = document.OneTrueForm.<% "$key$n" %>;
159 for (var i=fromObject.options.length-1;i>-1;i--) {
160 if (fromObject.options[i].selected)
161 deleteOption<% "$key$n" %>(fromObject,i);
164 function deleteOption<% "$key$n" %>(object,index) {
165 object.options[index] = null;
167 function selectall<% "$key$n" %>() {
168 fromObject = document.OneTrueForm.<% "$key$n" %>;
169 for (var i=fromObject.options.length-1;i>-1;i--) {
170 fromObject.options[i].selected = true;
173 function doadd<% "$key$n" %>(object) {
176 % if ( defined($config_item->editlist_parts) ) {
177 % foreach my $pnum ( 0 .. scalar(@{$config_item->editlist_parts})-1 ) {
179 if ( myvalue != "" ) { myvalue = myvalue + " "; }
181 % if ( $config_item->editlist_parts->[$pnum]{type} eq 'select' ) {
183 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.options[object.add<% "$key${n}_$pnum" %>.selectedIndex].value
184 <!-- #RESET SELECT?? maybe not... -->
186 % } elsif ( $config_item->editlist_parts->[$pnum]{type} eq 'immutable' ) {
188 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
192 myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
193 object.add<% "$key${n}_$pnum" %>.value = ""
199 myvalue = object.add<% "$key${n}_1" %>.value
203 var optionName = new Option(myvalue, myvalue);
204 var length = object.<% "$key$n" %>.length;
205 object.<% "$key$n" %>.options[length] = optionName;
208 <select multiple size=5 name="<% "$key$n" %>">
209 <option selected>----------------------------------------------------------------</option>
211 % foreach my $line ( $conf->config($key, $agentnum) ) {
213 <option value="<% $line %>"><% $line %></option>
218 <input type="button" value="remove selected" onClick="doremove<% "$key$n" %>()">
219 <script>SafeAddOnLoad(doremove<% "$key$n" %>);
220 SafeAddOnSubmit(selectall<% "$key$n" %>);
222 <br><% itable() %><tr>
224 % if ( defined $config_item->editlist_parts ) {
226 % foreach my $part ( @{$config_item->editlist_parts} ) {
230 % if ( $part->{type} eq 'text' ) {
232 <input type="text" name="add<% "$key${n}_$pnum" %>">
234 % } elsif ( $part->{type} eq 'immutable' ) {
237 <input type="hidden" name="add<% "$key${n}_$pnum" %>" value="<% $part->{value} %>">
239 % } elsif ( $part->{type} eq 'select' ) {
241 <select name="add<% qq!$key${n}_$pnum! %>">
243 % foreach my $key ( keys %{$part->{select_enum}} ) {
245 <option value="<% $key %>"><% $part->{select_enum}{$key} %></option>
253 <font color="#ff0000">unknown type <% $part->type %> </font>
263 <td><input type="text" name="add<% "$key${n}_0" %>></td>
267 <td><input type="button" value="add" onClick="doadd<% "$key$n" %>(this.form)"></td>
272 <font color="#ff0000">unknown type <% $type %></font>
279 % unless ( $description_printed ) {
280 <td><% $description %></td>
284 <INPUT TYPE="submit" VALUE="<% $title %>">
291 my $conf = new FS::Conf;
292 my @config_items = $conf->config_items;
293 my %confitems = map { $_->key => $_ } @config_items;
299 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
304 if ($cgi->param('agentnum') =~ /(\d+)$/) {
311 $agent = qsearchs('agent', { 'agentnum' => $1 } );
312 die "Agent $agentnum not found!" unless $agent;
314 $title = "$action configuration override for ". $agent->agent;
316 $title = "$action global configuration";
319 $cgi->param('key') =~ /^([-.\w]+)$/ or die "illegal configuration item";
321 my $value = $conf->config($key);
322 my $config_item = $confitems{$key};
324 my $description = $config_item->description;
325 my $config_type = $config_item->type;
326 my @types = ref($config_type) ? @$config_type : ($config_type);