1 <% header('Configuration set') %>
2 <SCRIPT TYPE="text/javascript">
4 % foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) {
5 var configCell = window.top.document.getElementById('<% $agentnum. $i->key. $n %>');
7 window.top.location.reload();
9 //alert('found cell ' + configCell);
10 % if ( $type eq 'textarea'
11 % || $type eq 'editlist'
12 % || $type eq 'selectmultiple' ) {
13 configCell.innerHTML =
14 '<font size="-2"><pre>' + "\n" +
15 <% encode_entities(join("\n",
16 map { length($_) > 88 ? substr($_,0,88).'...' : $_ }
17 $conf->config($i->key, $agentnum)
22 % } elsif ( $type eq 'checkbox' ) {
23 % if ( $conf->exists($i->key, $agentnum) ) {
24 configCell.style.backgroundColor = '#00ff00';
25 configCell.innerHTML = 'YES';
27 configCell.style.backgroundColor = '#ff0000';
28 configCell.innerHTML = 'NO';
30 % } elsif ( $type eq 'select' && $i->select_hash ) {
32 % if ( ref($i->select_hash) eq 'ARRAY' ) {
33 % tie %hash, 'Tie::IxHash', '' => '', @{ $i->select_hash };
35 % tie %hash, 'Tie::IxHash', '' => '', %{ $i->select_hash };
37 configCell.innerHTML = <% $conf->exists($i->key, $agentnum) ? $hash{ $conf->config($i->key, $agentnum) } : '' |js_string %>;
39 % } elsif ( $type eq 'text' || $type eq 'select' ) {
40 configCell.innerHTML = <% $conf->exists($i->key, $agentnum) ? $conf->config($i->key, $agentnum) : '' |js_string %>;
41 % } elsif ( $type =~ /^select-(part_svc|part_pkg|pkg_class)$/ && ! $i->multiple ) {
43 % my $namecol = $namecol{$table};
44 % my $pkey = dbdef->table($table)->primary_key;
45 % my $key = $conf->config($i->key, $agentnum);
46 % my $record = qsearchs($table, { $pkey => $key });
47 % my $value = $record ? "$key: ".$record->$namecol() : $key;
48 configCell.innerHTML = <% $value |js_string %>;
49 % } elsif ( $type eq 'select-sub' ) {
50 configCell.innerHTML =
51 <% $conf->config($i->key, $agentnum) |js_string %> + ': ' +
52 <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) |js_string %>;
54 //alert('unknown type <% $type %>');
55 window.top.location.reload();
65 #false laziness w/config-view.cgi
69 'pkg_class' => 'classname',
74 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
76 my $conf = new FS::Conf;
78 my @config_items = grep { $_->key != ~/^invoice_(html|latex|template)/ }
80 my %confitems = map { $_->key => $_ } $conf->config_items;
82 my $agentnum = $cgi->param('agentnum');
83 my $key = $cgi->param('key');
84 my $i = $confitems{$key};
89 foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) {
91 } elsif ( $type eq 'textarea' ) {
92 if ( $cgi->param($i->key.$n) ne '' ) {
93 my $value = $cgi->param($i->key.$n);
94 $value =~ s/\r\n/\n/g; #browsers?
95 $conf->set($i->key, $value, $agentnum);
97 $conf->delete($i->key, $agentnum);
99 } elsif ( $type eq 'binary' || $type eq 'image' ) {
100 if ( defined($cgi->param($i->key.$n)) && $cgi->param($i->key.$n) ) {
101 my $fh = $cgi->upload($i->key.$n);
104 $conf->set_binary($i->key, <$fh>, $agentnum);
107 warn "Condition failed for " . $i->key;
109 } elsif ( $type eq 'checkbox' ) {
110 if ( defined $cgi->param($i->key.$n) ) {
111 push @touch, $i->key;
113 push @delete, $i->key;
116 $type =~ /^(editlist|selectmultiple)$/
117 or ( $type =~ /^select(-(sub|part_svc|part_pkg|pkg_class))?$/
120 if ( scalar(@{[ $cgi->param($i->key.$n) ]}) ) {
121 $conf->set($i->key, join("\n", @{[ $cgi->param($i->key.$n) ]} ), $agentnum);
123 $conf->delete($i->key, $agentnum);
125 } elsif ( $type =~ /^(text|select(-(sub|part_svc|part_pkg|pkg_class))?)$/ ) {
126 if ( $cgi->param($i->key.$n) ne '' ) {
127 $conf->set($i->key, $cgi->param($i->key.$n), $agentnum);
129 $conf->delete($i->key, $agentnum);
135 $conf->touch($_, $agentnum) foreach @touch;
136 $conf->delete($_, $agentnum) foreach @delete;