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 my $curuser = $FS::CurrentUser::CurrentUser;
75 die "access denied\n" unless $curuser->access_right('Configuration');
77 my $conf = new FS::Conf;
79 if ( $conf->exists('disable_settings_changes') ) {
80 my @changers = split(/\s*,\s*/, $conf->config('disable_settings_changes'));
81 my %changers = map { $_=>1 } @changers;
82 unless ( $changers{$curuser->username} ) {
83 errorpage_popup("Disabled in web demo");
84 die "shouldn't be reached";
89 my @config_items = grep { $_->key != ~/^invoice_(html|latex|template)/ }
91 my %confitems = map { $_->key => $_ } $conf->config_items;
93 my $agentnum = $cgi->param('agentnum');
94 my $key = $cgi->param('key');
95 my $i = $confitems{$key};
100 foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) {
102 } elsif ( $type eq 'textarea' ) {
103 if ( $cgi->param($i->key.$n) ne '' ) {
104 my $value = $cgi->param($i->key.$n);
105 $value =~ s/\r\n/\n/g; #browsers?
106 $conf->set($i->key, $value, $agentnum);
108 $conf->delete($i->key, $agentnum);
110 } elsif ( $type eq 'binary' || $type eq 'image' ) {
111 if ( defined($cgi->param($i->key.$n)) && $cgi->param($i->key.$n) ) {
112 my $fh = $cgi->upload($i->key.$n);
115 $conf->set_binary($i->key, <$fh>, $agentnum);
118 warn "Condition failed for " . $i->key;
120 } elsif ( $type eq 'checkbox' ) {
121 if ( defined $cgi->param($i->key.$n) ) {
122 push @touch, $i->key;
124 push @delete, $i->key;
127 $type =~ /^(editlist|selectmultiple)$/
128 or ( $type =~ /^select(-(sub|part_svc|part_pkg|pkg_class))?$/
131 if ( scalar(@{[ $cgi->param($i->key.$n) ]}) ) {
132 $conf->set($i->key, join("\n", @{[ $cgi->param($i->key.$n) ]} ), $agentnum);
134 $conf->delete($i->key, $agentnum);
136 } elsif ( $type =~ /^(text|select(-(sub|part_svc|part_pkg|pkg_class))?)$/ ) {
137 if ( $cgi->param($i->key.$n) ne '' ) {
138 $conf->set($i->key, $cgi->param($i->key.$n), $agentnum);
140 $conf->delete($i->key, $agentnum);
146 $conf->touch($_, $agentnum) foreach @touch;
147 $conf->delete($_, $agentnum) foreach @delete;