config goes in database
[freeside.git] / httemplate / config / config-process.cgi
1 <%init>
2 die "access denied\n"
3   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
4
5 # errant GET/POST protection
6 my $Vars = scalar($cgi->Vars);
7 my $num_Vars = scalar(keys %$Vars);
8 die "only received $num_Vars params; errant or truncated GET/POST?".
9     "  aborting - not updating config\n"
10   unless $num_Vars > 100;
11
12 my $conf = new FS::Conf;
13 $FS::Conf::DEBUG = 1;
14 my @config_items = $conf->config_items;
15
16 foreach my $i ( @config_items ) {
17   my @touch = ();
18   my @delete = ();
19   my $n = 0;
20   foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) {
21     if ( $type eq '' ) {
22     } elsif ( $type eq 'textarea' ) {
23       if ( $cgi->param($i->key. $n) ne '' ) {
24         my $value = $cgi->param($i->key. $n);
25         $value =~ s/\r\n/\n/g; #browsers?
26         $conf->set($i->key, $value);
27       } else {
28         $conf->delete($i->key);
29       }
30     } elsif ( $type eq 'binary' ) {
31       if ( defined($cgi->param($i->key. $n)) && $cgi->param($i->key. $n) ) {
32         my $fh = $cgi->upload($i->key. $n);
33         if (defined($fh)) {
34           local $/;
35           $conf->set_binary($i->key, <$fh>);
36         }
37       }else{
38         warn "Condition failed for " . $i->key;
39       }
40     } elsif ( $type eq 'checkbox' ) {
41 #        if ( defined($cgi->param($i->key. $n)) && $cgi->param($i->key. $n) ) {
42       if ( defined $cgi->param($i->key. $n) ) {
43         #$conf->touch($i->key);
44         push @touch, $i->key;
45       } else {
46         #$conf->delete($i->key);
47         push @delete, $i->key;
48       }
49     } elsif ( $type eq 'text' || $type eq 'select' || $type eq 'select-sub' )  {
50       if ( $cgi->param($i->key. $n) ne '' ) {
51         $conf->set($i->key, $cgi->param($i->key. $n));
52       } else {
53         $conf->delete($i->key);
54       }
55     } elsif ( $type eq 'editlist' || $type eq 'selectmultiple' )  {
56       if ( scalar(@{[ $cgi->param($i->key. $n) ]}) ) {
57         $conf->set($i->key, join("\n", @{[ $cgi->param($i->key. $n) ]} ));
58       } else {
59         $conf->delete($i->key);
60       }
61     } else {
62     }
63     $n++;
64   }
65  # warn @touch;
66   $conf->touch($_) foreach @touch;
67   $conf->delete($_) foreach @delete;
68 }
69 </%init>
70 <% $cgi->redirect("config-view.cgi") %>