1 %if ( scalar(@error) ) {
3 % my $url = popurl(1)."config.cgi";
4 % if ( length($cgi->query_string) > 1920 ) { #stupid IE 2083 URL limit
6 % my $session = int(rand(4294967296)); #XXX
7 % my $pref = new FS::access_user_pref({
8 % 'usernum' => $FS::CurrentUser::CurrentUser->usernum,
9 % 'prefname' => "redirect$session",
10 % 'prefvalue' => $cgi->query_string,
11 % 'expiration' => time + 3600, #1h? 1m?
13 % my $pref_error = $pref->insert;
14 % if ( $pref_error ) {
15 % die "FATAL: couldn't even set redirect cookie: $pref_error".
16 % " attempting to set redirect$session to ". $cgi->query_string."\n";
19 <% $cgi->redirect("$url?redirect=$session") %>
23 <% $cgi->redirect("$url?". $cgi->query_string ) %>
28 <% header('Configuration set') %>
29 <SCRIPT TYPE="text/javascript">
31 % foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) {
32 var configCell = window.top.document.getElementById('<% $agentnum. $i->key. $n %>');
34 window.top.location.reload();
36 //alert('found cell ' + configCell);
37 % if ( $type eq 'textarea'
38 % || $type eq 'editlist'
39 % || $type eq 'selectmultiple' ) {
40 configCell.innerHTML =
41 '<font size="-2"><pre>' + "\n" +
42 <% encode_entities(join("\n",
43 map { length($_) > 88 ? substr($_,0,88).'...' : $_ }
44 $conf->config($i->key, $agentnum)
49 % } elsif ( $type eq 'checkbox' ) {
50 % if ( $conf->exists($i->key, $agentnum) ) {
51 configCell.style.backgroundColor = '#00ff00';
52 configCell.innerHTML = 'YES';
54 configCell.style.backgroundColor = '#ff0000';
55 configCell.innerHTML = 'NO';
57 % } elsif ( $type eq 'select' && $i->select_hash ) {
59 % if ( ref($i->select_hash) eq 'ARRAY' ) {
60 % tie %hash, 'Tie::IxHash', '' => '', @{ $i->select_hash };
62 % tie %hash, 'Tie::IxHash', '' => '', %{ $i->select_hash };
64 configCell.innerHTML = <% $conf->exists($i->key, $agentnum) ? $hash{ $conf->config($i->key, $agentnum) } : '' |js_string %>;
66 % } elsif ( $type eq 'text' || $type eq 'select' ) {
67 configCell.innerHTML = <% $conf->exists($i->key, $agentnum) ? $conf->config($i->key, $agentnum) : '' |js_string %>;
68 % } elsif ( $type =~ /^select-(part_svc|part_pkg|pkg_class|agent)$/ && ! $i->multiple ) {
70 % my $namecol = $namecol{$table};
71 % my $pkey = dbdef->table($table)->primary_key;
72 % my $key = $conf->config($i->key, $agentnum);
73 % my $record = qsearchs($table, { $pkey => $key });
74 % my $value = $record ? "$key: ".$record->$namecol() : $key;
75 configCell.innerHTML = <% $value |js_string %>;
76 % } elsif ( $type eq 'select-sub' && ! $i->multiple ) {
77 configCell.innerHTML =
78 <% $conf->config($i->key, $agentnum) |js_string %> + ': ' +
79 <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) |js_string %>;
81 //alert('unknown type <% $type %>');
82 window.top.location.reload();
93 #false laziness w/config-view.cgi
97 'pkg_class' => 'classname',
103 my $curuser = $FS::CurrentUser::CurrentUser;
104 die "access denied\n" unless $curuser->access_right('Configuration');
106 my $conf = new FS::Conf;
108 if ( $conf->exists('disable_settings_changes') ) {
109 my @changers = split(/\s*,\s*/, $conf->config('disable_settings_changes'));
110 my %changers = map { $_=>1 } @changers;
111 unless ( $changers{$curuser->username} ) {
112 errorpage_popup("Disabled in web demo");
113 die "shouldn't be reached";
117 $FS::Conf::DEBUG = 1;
118 my @config_items = grep { $_->key != ~/^invoice_(html|latex|template)/ }
120 my %confitems = map { $_->key => $_ } $conf->config_items;
122 my $agentnum = $cgi->param('agentnum');
123 my $key = $cgi->param('key');
124 my $i = $confitems{$key};
130 foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) {
132 } elsif ( $type eq 'textarea' ) {
133 if ( $cgi->param($i->key.$n) ne '' ) {
134 my $value = $cgi->param($i->key.$n);
135 $value =~ s/\r\n/\n/g; #browsers?
136 my $error = &{$i->validate}($value, $n) if $i->validate;
137 push @error, $error if $error;
138 $conf->set($i->key, $value, $agentnum);
140 $conf->delete($i->key, $agentnum);
142 } elsif ( $type eq 'binary' || $type eq 'image' ) {
143 if ( defined($cgi->param($i->key.$n)) && $cgi->param($i->key.$n) ) {
144 my $fh = $cgi->upload($i->key.$n);
145 my $error = &{$i->validate}($fh, $n) if $i->validate;
146 push @error, $error if $error;
149 $conf->set_binary($i->key, <$fh>, $agentnum);
152 warn "Condition failed for " . $i->key;
154 } elsif ( $type eq 'checkbox' ) {
155 if ( defined $cgi->param($i->key.$n) ) {
156 push @touch, $i->key;
158 push @delete, $i->key;
161 $type =~ /^(editlist|selectmultiple)$/
162 or ( $type =~ /^select(-(sub|part_svc|part_pkg|pkg_class|agent))?$/
165 if ( scalar(@{[ $cgi->param($i->key.$n) ]}) ) {
166 my $error = &{$i->validate}([ $cgi->param($i->key.$n) ], $n) if $i->validate;
167 push @error, $error if $error;
168 $conf->set($i->key, join("\n", @{[ $cgi->param($i->key.$n) ]} ), $agentnum);
170 $conf->delete($i->key, $agentnum);
172 } elsif ( $type =~ /^(text|select(-(sub|part_svc|part_pkg|pkg_class|agent))?)$/ ) {
173 if ( $cgi->param($i->key.$n) ne '' ) {
174 my $error = &{$i->validate}($cgi->param($i->key.$n), $n) if $i->validate;
175 push @error, $error if $error;
176 $conf->set($i->key, $cgi->param($i->key.$n), $agentnum);
178 $conf->delete($i->key, $agentnum);
184 $conf->touch($_, $agentnum) foreach @touch;
185 $conf->delete($_, $agentnum) foreach @delete;
187 if (scalar(@error)) {
188 $cgi->param('error', join(' ', @error));