3 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
5 my $conf = new FS::Conf;
7 my @config_items = grep { $_->key != ~/^invoice_(html|latex|template)/ }
9 my %confitems = map { $_->key => $_ } $conf->config_items;
11 my $agentnum = $cgi->param('agentnum');
12 my $key = $cgi->param('key');
13 my $i = $confitems{$key};
18 foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) {
20 } elsif ( $type eq 'textarea' ) {
21 if ( $cgi->param($i->key.$n) ne '' ) {
22 my $value = $cgi->param($i->key.$n);
23 $value =~ s/\r\n/\n/g; #browsers?
24 $conf->set($i->key, $value, $agentnum);
26 $conf->delete($i->key, $agentnum);
28 } elsif ( $type eq 'binary' ) {
29 if ( defined($cgi->param($i->key.$n)) && $cgi->param($i->key.$n) ) {
30 my $fh = $cgi->upload($i->key.$n);
33 $conf->set_binary($i->key, <$fh>, $agentnum);
36 warn "Condition failed for " . $i->key;
38 } elsif ( $type eq 'checkbox' ) {
39 if ( defined $cgi->param($i->key.$n) ) {
42 push @delete, $i->key;
44 } elsif ( $type eq 'text' || $type eq 'select' || $type eq 'select-sub' ) {
45 if ( $cgi->param($i->key.$n) ne '' ) {
46 $conf->set($i->key, $cgi->param($i->key.$n), $agentnum);
48 $conf->delete($i->key, $agentnum);
50 } elsif ( $type eq 'editlist' || $type eq 'selectmultiple' ) {
51 if ( scalar(@{[ $cgi->param($i->key.$n) ]}) ) {
52 $conf->set($i->key, join("\n", @{[ $cgi->param($i->key.$n) ]} ), $agentnum);
54 $conf->delete($i->key, $agentnum);
60 $conf->touch($_, $agentnum) foreach @touch;
61 $conf->delete($_, $agentnum) foreach @delete;
64 <% header('Configuration set') %>
65 <SCRIPT TYPE="text/javascript">
67 % foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) {
68 var configCell = window.top.document.getElementById('<% $i->key. $n %>');
69 //alert('found cell ' + configCell);
70 % if ( $type eq 'textarea'
71 % || $type eq 'editlist'
72 % || $type eq 'selectmultiple' ) {
73 configCell.innerHTML =
74 '<font size="-2"><pre>' + "\n" +
75 <% encode_entities(join("\n",
76 map { length($_) > 88 ? substr($_,0,88).'...' : $_ }
77 $conf->config($i->key, $agentnum)
82 % } elsif ( $type eq 'checkbox' ) {
83 % if ( $conf->exists($i->key, $agentnum) ) {
84 configCell.style.backgroundColor = '#00ff00';
85 configCell.innerHTML = 'YES';
87 configCell.style.backgroundColor = '#ff0000';
88 configCell.innerHTML = 'NO';
90 % } elsif ( $type eq 'text' || $type eq 'select' ) {
91 configCell.innerHTML = <% $conf->exists($i->key, $agentnum) ? $conf->config($i->key, $agentnum) : '' |js_string %>;
92 % } elsif ( $type eq 'select-sub' ) {
93 configCell.innerHTML =
94 <% $conf->config($i->key, $agentnum) |js_string %> + ': ' +
95 <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) |js_string %>;
97 alert('unknown type <% $type %>');
98 window.top.location.reload();