summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FS/FS/Conf.pm77
-rwxr-xr-xhttemplate/browse/agent.cgi22
-rw-r--r--httemplate/config/config-delete.cgi15
-rw-r--r--httemplate/config/config-download.cgi18
-rw-r--r--httemplate/config/config-process.cgi109
-rw-r--r--httemplate/config/config-view.cgi57
-rw-r--r--httemplate/config/config.cgi423
7 files changed, 421 insertions, 300 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 1851c4d08..b8fd27eb2 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -74,9 +74,11 @@ sub base_dir {
$1;
}
-=item config KEY
+=item config KEY [ AGENTNUM ]
Returns the configuration value or values (depending on context) for key.
+The optional agent number selects an agent specific value instead of the
+global default if one is present.
=cut
@@ -89,15 +91,13 @@ sub _usecompat {
}
sub _config {
- my($self,$name,$agent)=@_;
+ my($self,$name,$agentnum)=@_;
my $hashref = { 'name' => $name };
- if (defined($agent) && $agent) {
- $hashref->{agent} = $agent;
- }
+ $hashref->{agentnum} = $agentnum;
local $FS::Record::conf = undef; # XXX evil hack prevents recursion
my $cv = FS::Record::qsearchs('conf', $hashref);
- if (!$cv && exists($hashref->{agent})) {
- delete($hashref->{agent});
+ if (!$cv && defined($agentnum)) {
+ $hashref->{agentnum} = '';
$cv = FS::Record::qsearchs('conf', $hashref);
}
return $cv;
@@ -107,8 +107,8 @@ sub config {
my $self = shift;
return $self->_usecompat('config', @_) if use_confcompat;
- my($name,$agent)=@_;
- my $cv = $self->_config($name, $agent) or return;
+ my($name,$agentnum)=@_;
+ my $cv = $self->_config($name, $agentnum) or return;
if ( wantarray ) {
my $v = $cv->value;
@@ -119,7 +119,7 @@ sub config {
}
}
-=item config_binary KEY
+=item config_binary KEY [ AGENTNUM ]
Returns the exact scalar value for key.
@@ -129,12 +129,12 @@ sub config_binary {
my $self = shift;
return $self->_usecompat('config_binary', @_) if use_confcompat;
- my($name,$agent)=@_;
- my $cv = $self->_config($name, $agent) or return;
+ my($name,$agentnum)=@_;
+ my $cv = $self->_config($name, $agentnum) or return;
decode_base64($cv->value);
}
-=item exists KEY
+=item exists KEY [ AGENTNUM ]
Returns true if the specified key exists, even if the corresponding value
is undefined.
@@ -145,17 +145,18 @@ sub exists {
my $self = shift;
return $self->_usecompat('exists', @_) if use_confcompat;
- my($name,$agent)=@_;
- defined($self->_config($name, $agent));
+ my($name,$agentnum)=@_;
+ defined($self->_config($name, $agentnum));
}
-=item config_orbase KEY SUFFIX
-
-Returns the configuration value or values (depending on context) for
-KEY_SUFFIX, if it exists, otherwise for KEY
-
-=cut
+#=item config_orbase KEY SUFFIX
+#
+#Returns the configuration value or values (depending on context) for
+#KEY_SUFFIX, if it exists, otherwise for KEY
+#
+#=cut
+# outmoded as soon as we shift to agentnum based config values
sub config_orbase {
my $self = shift;
return $self->_usecompat('config_orbase', @_) if use_confcompat;
@@ -168,7 +169,7 @@ sub config_orbase {
}
}
-=item touch KEY
+=item touch KEY [ AGENT ];
Creates the specified configuration key if it does not exist.
@@ -178,13 +179,13 @@ sub touch {
my $self = shift;
return $self->_usecompat('touch', @_) if use_confcompat;
- my($name, $agent) = @_;
- unless ( $self->exists($name, $agent) ) {
- $self->set($name, '', $agent);
+ my($name, $agentnum) = @_;
+ unless ( $self->exists($name, $agentnum) ) {
+ $self->set($name, '', $agentnum);
}
}
-=item set KEY VALUE
+=item set KEY VALUE [ AGENTNUM ];
Sets the specified configuration key to the given value.
@@ -194,15 +195,15 @@ sub set {
my $self = shift;
return $self->_usecompat('set', @_) if use_confcompat;
- my($name, $value, $agent) = @_;
+ my($name, $value, $agentnum) = @_;
$value =~ /^(.*)$/s;
$value = $1;
warn "[FS::Conf] SET $name\n" if $DEBUG;
- my $old = FS::Record::qsearchs('conf', {name => $name, agent => $agent});
+ my $old = FS::Record::qsearchs('conf', {name => $name, agentnum => $agentnum});
my $new = new FS::conf { $old ? $old->hash
- : ('name' => $name, 'agent' => $agent)
+ : ('name' => $name, 'agentnum' => $agentnum)
};
$new->value($value);
@@ -218,7 +219,7 @@ sub set {
}
-=item set_binary KEY VALUE
+=item set_binary KEY VALUE [ AGENTNUM ]
Sets the specified configuration key to an exact scalar value which
can be retrieved with config_binary.
@@ -229,11 +230,11 @@ sub set_binary {
my $self = shift;
return if use_confcompat;
- my($name, $value, $agent)=@_;
- $self->set($name, encode_base64($value), $agent);
+ my($name, $value, $agentnum)=@_;
+ $self->set($name, encode_base64($value), $agentnum);
}
-=item delete KEY
+=item delete KEY [ AGENTNUM ];
Deletes the specified configuration key.
@@ -243,9 +244,9 @@ sub delete {
my $self = shift;
return $self->_usecompat('delete', @_) if use_confcompat;
- my($name, $agent) = @_;
- if ( my $cv = FS::Record::qsearchs('conf', {name => $name, agent => $agent}) ) {
- warn "[FS::Conf] DELETE $file\n";
+ my($name, $agentnum) = @_;
+ if ( my $cv = FS::Record::qsearchs('conf', {name => $name, agentnum => $agentnum}) ) {
+ warn "[FS::Conf] DELETE $name\n";
my $oldAutoCommit = $FS::UID::AutoCommit;
local $FS::UID::AutoCommit = 0;
@@ -1335,6 +1336,7 @@ httemplate/docs/config.html
'section' => '',
'description' => 'Template file for welcome email. Welcome emails are sent to the customer email invoice destination(s) each time a svc_acct record is created. See the <a href="http://search.cpan.org/~mjd/Text-Template/lib/Text/Template.pm">Text::Template</a> documentation for details on the template substitution language. The following variables are available<ul><li><code>$username</code> <li><code>$password</code> <li><code>$first</code> <li><code>$last</code> <li><code>$pkg</code></ul>',
'type' => 'textarea',
+ 'per_agent' => 1,
},
{
@@ -1342,6 +1344,7 @@ httemplate/docs/config.html
'section' => '',
'description' => 'From: address header for welcome email',
'type' => 'text',
+ 'per_agent' => 1,
},
{
@@ -1349,6 +1352,7 @@ httemplate/docs/config.html
'section' => '',
'description' => 'Subject: header for welcome email',
'type' => 'text',
+ 'per_agent' => 1,
},
{
@@ -1357,6 +1361,7 @@ httemplate/docs/config.html
'description' => 'MIME type for welcome email',
'type' => 'select',
'select_enum' => [ 'text/plain', 'text/html' ],
+ 'per_agent' => 1,
},
{
diff --git a/httemplate/browse/agent.cgi b/httemplate/browse/agent.cgi
index 063f259de..83e79a2f3 100755
--- a/httemplate/browse/agent.cgi
+++ b/httemplate/browse/agent.cgi
@@ -38,6 +38,7 @@ full offerings (via their type).<BR><BR>
% }
<TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Payment Gateway Overrides</FONT></TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Configuration Overrides</FONT></TH>
<TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Freq.</FONT></TH>
<TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Prog.</FONT></TH>
</TR>
@@ -344,6 +345,27 @@ Unused
</TABLE>
</TD>
+ <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
+ <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
+% foreach my $override (
+% qsearch('conf', { 'agentnum' => $agent->agentnum } )
+% ) {
+%
+
+ <TR>
+ <TD>
+ <% $override->name %>
+ <FONT SIZE=-1><A HREF="<%$p%>config/config-delete.cgi?<% $override->confnum %>">(delete)</A></FONT>
+ </TD>
+ </TR>
+% }
+
+ <TR>
+ <TD><FONT SIZE=-1><A HREF="<%$p%>config/config-view.cgi?agentnum=<% $agent->agentnum %>">(add override)</A></FONT></TD>
+ </TR>
+ </TABLE>
+ </TD>
+
<!--
<TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $agent->freq %></TD>
<TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $agent->prog %></TD>
diff --git a/httemplate/config/config-delete.cgi b/httemplate/config/config-delete.cgi
new file mode 100644
index 000000000..cdac434fa
--- /dev/null
+++ b/httemplate/config/config-delete.cgi
@@ -0,0 +1,15 @@
+<%init>
+die "access denied\n"
+ unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+
+die "No configuration item specified (bad URL)!" unless $cgi->keywords;
+my ($query) = $cgi->keywords;
+$query =~ /^(\d+)$/;
+my $confnum = $1;
+
+my $conf = qsearchs('conf', {'confnum' => $confnum});
+die "Configuration not found!" unless $conf;
+$conf->delete;
+
+</%init>
+<% $cgi->redirect(popurl(2) . "browse/agent.cgi") %>
diff --git a/httemplate/config/config-download.cgi b/httemplate/config/config-download.cgi
index 95a172a51..6979246db 100644
--- a/httemplate/config/config-download.cgi
+++ b/httemplate/config/config-download.cgi
@@ -5,14 +5,24 @@
%http_header('Content-Type' => 'application/x-unknown' );
%
%die "No configuration variable specified (bad URL)!" # umm
-% unless $cgi->keywords;
-%my($query) = $cgi->keywords;
-%$query =~ /^([\w -\)+-\/@;:?=[\]]+)$/;
+% unless $cgi->param('key');
+%$cgi->param('key') =~ /^([-\w.]+)$/;
%my $name = $1;
%
+%my $agentnum;
+%if ($cgi->param('agentnum') =~ /^(\d+)$/) {
+% $agentnum = $1;
+%}
+%
%http_header('Content-Disposition' => "attachment; filename=$name" );
-% print $conf->config_binary($name);
+% print $conf->config_binary($name, $agentnum);
<%init>
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+
+my $agentnum;
+if ($cgi->param('agentnum') =~ /^(\d+)$/) {
+ $agentnum = $1;
+}
+
</%init>
diff --git a/httemplate/config/config-process.cgi b/httemplate/config/config-process.cgi
index 3e49b4f99..0210d85a7 100644
--- a/httemplate/config/config-process.cgi
+++ b/httemplate/config/config-process.cgi
@@ -2,69 +2,66 @@
die "access denied\n"
unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
-# errant GET/POST protection
-my $Vars = scalar($cgi->Vars);
-my $num_Vars = scalar(keys %$Vars);
-die "only received $num_Vars params; errant or truncated GET/POST?".
- " aborting - not updating config\n"
- unless $num_Vars > 100;
-
my $conf = new FS::Conf;
$FS::Conf::DEBUG = 1;
my @config_items = $conf->config_items;
+my %confitems = map { $_->key => $_ } $conf->config_items;
-foreach my $i ( @config_items ) {
- my @touch = ();
- my @delete = ();
- my $n = 0;
- foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) {
- if ( $type eq '' ) {
- } elsif ( $type eq 'textarea' ) {
- if ( $cgi->param($i->key. $n) ne '' ) {
- my $value = $cgi->param($i->key. $n);
- $value =~ s/\r\n/\n/g; #browsers?
- $conf->set($i->key, $value);
- } else {
- $conf->delete($i->key);
- }
- } elsif ( $type eq 'binary' ) {
- if ( defined($cgi->param($i->key. $n)) && $cgi->param($i->key. $n) ) {
- my $fh = $cgi->upload($i->key. $n);
- if (defined($fh)) {
- local $/;
- $conf->set_binary($i->key, <$fh>);
- }
- }else{
- warn "Condition failed for " . $i->key;
- }
- } elsif ( $type eq 'checkbox' ) {
-# if ( defined($cgi->param($i->key. $n)) && $cgi->param($i->key. $n) ) {
- if ( defined $cgi->param($i->key. $n) ) {
- #$conf->touch($i->key);
- push @touch, $i->key;
- } else {
- #$conf->delete($i->key);
- push @delete, $i->key;
- }
- } elsif ( $type eq 'text' || $type eq 'select' || $type eq 'select-sub' ) {
- if ( $cgi->param($i->key. $n) ne '' ) {
- $conf->set($i->key, $cgi->param($i->key. $n));
- } else {
- $conf->delete($i->key);
- }
- } elsif ( $type eq 'editlist' || $type eq 'selectmultiple' ) {
- if ( scalar(@{[ $cgi->param($i->key. $n) ]}) ) {
- $conf->set($i->key, join("\n", @{[ $cgi->param($i->key. $n) ]} ));
- } else {
- $conf->delete($i->key);
+my $agentnum = $cgi->param('agentnum');
+my $key = $cgi->param('key');
+my $i = $confitems{$key};
+
+my @touch = ();
+my @delete = ();
+my $n = 0;
+foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) {
+ if ( $type eq '' ) {
+ } elsif ( $type eq 'textarea' ) {
+ if ( $cgi->param($i->key.$n) ne '' ) {
+ my $value = $cgi->param($i->key.$n);
+ $value =~ s/\r\n/\n/g; #browsers?
+ $conf->set($i->key, $value, $agentnum);
+ } else {
+ $conf->delete($i->key, $agentnum);
+ }
+ } elsif ( $type eq 'binary' ) {
+ if ( defined($cgi->param($i->key.$n)) && $cgi->param($i->key.$n) ) {
+ my $fh = $cgi->upload($i->key.$n);
+ if (defined($fh)) {
+ local $/;
+ $conf->set_binary($i->key, <$fh>, $agentnum);
}
+ }else{
+ warn "Condition failed for " . $i->key;
+ }
+ } elsif ( $type eq 'checkbox' ) {
+ if ( defined $cgi->param($i->key.$n) ) {
+ push @touch, $i->key;
+ } else {
+ push @delete, $i->key;
+ }
+ } elsif ( $type eq 'text' || $type eq 'select' || $type eq 'select-sub' ) {
+ if ( $cgi->param($i->key.$n) ne '' ) {
+ $conf->set($i->key, $cgi->param($i->key.$n), $agentnum);
} else {
+ $conf->delete($i->key, $agentnum);
+ }
+ } elsif ( $type eq 'editlist' || $type eq 'selectmultiple' ) {
+ if ( scalar(@{[ $cgi->param($i->key.$n) ]}) ) {
+ $conf->set($i->key, join("\n", @{[ $cgi->param($i->key.$n) ]} ), $agentnum);
+ } else {
+ $conf->delete($i->key, $agentnum);
}
- $n++;
}
- # warn @touch;
- $conf->touch($_) foreach @touch;
- $conf->delete($_) foreach @delete;
+ $n++;
}
+# warn @touch;
+$conf->touch($_, $agentnum) foreach @touch;
+$conf->delete($_, $agentnum) foreach @delete;
+
</%init>
-<% $cgi->redirect("config-view.cgi") %>
+<% header('Configuration set') %>
+ <SCRIPT TYPE="text/javascript">
+ window.top.location.reload();
+ </SCRIPT>
+ </BODY></HTML>
diff --git a/httemplate/config/config-view.cgi b/httemplate/config/config-view.cgi
index 7f2a1b293..5f2166320 100644
--- a/httemplate/config/config-view.cgi
+++ b/httemplate/config/config-view.cgi
@@ -1,6 +1,22 @@
-<% include("/elements/header.html",'View Configuration', menubar( 'Main Menu' => $p,
- 'Edit Configuration' => 'config.cgi' ) ) %>
-% my $conf = new FS::Conf; my @config_items = $conf->config_items;
+<% include("/elements/header.html",
+ $title,
+ menubar(
+ 'Main Menu' => $p,
+ 'View all agents' => $p.'browse/agent.cgi',
+ )
+ )
+%>
+
+<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/overlibmws.js"></SCRIPT>
+<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/overlibmws_iframe.js"></SCRIPT>
+<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/overlibmws_draggable.js"></SCRIPT>
+<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/iframecontentmws.js"></SCRIPT>
+
+% if ($FS::UID::use_confcompat) {
+
+ <FONT SIZE="+1" COLOR="#ff0000">CONFIGURATION NOT STORED IN DATABASE -- USING COMPATIBILITY MODE</FONT><BR><BR>
+%}
+%
% foreach my $section ( qw(required billing username password UI session
% shell BIND
% ),
@@ -31,7 +47,7 @@
% foreach my $i (grep $_->section eq $section, @config_items) {
<tr>
- <td><a name="<% $i->key %>">
+ <td><a href="javascript:void(0);" onClick="overlib( OLiframeContent('config.cgi?key=<% $i->key %>;agentnum=<% $agentnum %>', 522, 336, 'config_popup' ), CAPTION, 'Enter configuration value', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;" name="<% $i->key %>">
<b><% $i->key %></b>&nbsp;-&nbsp;<% $i->description %>
</a></td>
<td><table border=0>
@@ -45,8 +61,8 @@
% } elsif ( $type eq 'binary' ) {
<tr>
- <% $conf->exists($i->key)
- ? qq!<a href="config-download.cgi?!. $i->key. qq!">download</a>!
+ <% $conf->exists($i->key, $agentnum)
+ ? qq!<a href="config-download.cgi?key=!. $i->key. ';agentnum='. $agentnum. qq!">download</a>!
: 'empty'
%>
</tr>
@@ -57,27 +73,27 @@
<tr>
<td bgcolor="#ffffff">
<pre>
-<% encode_entities(join("\n", $conf->config($i->key) ) ) %>
+<% encode_entities(join("\n", $conf->config($i->key, $agentnum) ) ) %>
</pre>
</td>
</tr>
% } elsif ( $type eq 'checkbox' ) {
<tr>
- <td bgcolor="#<% $conf->exists($i->key) ? '00ff00">YES' : 'ff0000">NO' %></td>
+ <td bgcolor="#<% $conf->exists($i->key, $agentnum) ? '00ff00">YES' : 'ff0000">NO' %></td>
</tr>
% } elsif ( $type eq 'text' || $type eq 'select' ) {
<tr>
<td bgcolor="#ffffff">
- <% $conf->exists($i->key) ? $conf->config($i->key) : '' %>
+ <% $conf->exists($i->key, $agentnum) ? $conf->config($i->key, $agentnum) : '' %>
</td></tr>
% } elsif ( $type eq 'select-sub' ) {
<tr>
<td bgcolor="#ffffff">
- <% $conf->config($i->key) %>:
- <% &{ $i->option_sub }( $conf->config($i->key) ) %>
+ <% $conf->config($i->key, $agentnum) %>:
+ <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) %>
</td>
</tr>
% } else {
@@ -100,4 +116,23 @@
<%init>
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+
+my ($conf, $title, @config_items, $agentnum);
+
+if ($cgi->param('agentnum') =~ /^(\d+)$/) {
+ $agentnum = $1;
+}
+
+if ($agentnum) {
+ my $agent = qsearchs('agent', { 'agentnum' => $agentnum } );
+ die "Agent $agentnum not found!" unless $agent;
+
+ $title = "Configuration for ". $agent->agent;
+} else {
+ $title = 'Global Configuration';
+}
+
+$conf = new FS::Conf;
+@config_items = grep { $agentnum ? $_->per_agent : 1 } $conf->config_items;
+
</%init>
diff --git a/httemplate/config/config.cgi b/httemplate/config/config.cgi
index df9af47a6..10bbadaf8 100644
--- a/httemplate/config/config.cgi
+++ b/httemplate/config/config.cgi
@@ -1,4 +1,5 @@
-<% include("/elements/header.html",'Edit Configuration', menubar( 'Main Menu' => $p ) ) %>
+<% include("/elements/header-popup.html", $title) %>
+
<SCRIPT>
var gSafeOnload = new Array();
var gSafeOnsubmit = new Array();
@@ -18,250 +19,286 @@ function SafeOnsubmit() {
gSafeOnsubmit[i]();
}
</SCRIPT>
-% my $conf = new FS::Conf; my @config_items = $conf->config_items;
-
-<form name="OneTrueForm" action="config-process.cgi" METHOD="POST" enctype="multipart/form-data" onSubmit="SafeOnsubmit()">
-% foreach my $section ( qw(required billing username password UI session
-% shell BIND
-% ),
-% '', 'deprecated') {
+% if ( $cgi->param('error') ) {
+ <FONT SIZE="+1" COLOR="#ff0000">Error: <% $cgi->param('error') %></FONT>
+ <BR><BR>
+% }
- <A NAME="<% $section || 'unclassified' %>"></A>
- <FONT SIZE="-2">
-% foreach my $nav_section ( qw(required billing username password UI session
-% shell BIND
-% ),
-% '', 'deprecated') {
-% if ( $section eq $nav_section ) {
+<FORM NAME="OneTrueForm" ACTION="config-process.cgi" METHOD="POST" enctype="multipart/form-data" onSubmit="SafeOnsubmit()">
+<INPUT TYPE="hidden" NAME="agentnum" VALUE="<% $agentnum %>">
+<INPUT TYPE="hidden" NAME="key" VALUE="<% $key %>">
- [<A NAME="not<% $nav_section || 'unclassified' %>" style="background-color: #cccccc"><% ucfirst($nav_section || 'unclassified') %></A>]
-% } else {
+Setting <% $key %>
- [<A HREF="#<% $nav_section || 'unclassified' %>"><% ucfirst($nav_section || 'unclassified') %></A>]
-% }
-% }
+<table><tr><td>
- </FONT><BR>
- <% table("#cccccc", 2) %>
- <tr>
- <th colspan="2" bgcolor="#dcdcdc">
- <% ucfirst($section || 'unclassified') %> configuration options
- </th>
- </tr>
-% foreach my $i (grep $_->section eq $section, @config_items) {
-
- <tr>
- <td>
% my $n = 0;
-% foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) {
-% #warn $i->key unless defined($type);
+% foreach my $type ( ref($config_item->type) ? @{$config_item->type} : $config_item->type ) {
+% if ( $type eq '' ) {
+
+ <font color="#ff0000">no type</font>
+
+% } elsif ( $type eq 'binary' ) {
+
+ Filename <input type="file" name="<% "$key$n" %>">
+
+% } elsif ( $type eq 'textarea' ) {
+
+ <textarea name="<% "$key$n" %>" rows=5><% join("\n", $conf->config($key, $agentnum)) %></textarea>
+
+% } elsif ( $type eq 'checkbox' ) {
+
+ <input name="<% "$key$n" %>" type="checkbox" value="1"
+ <% $conf->exists($key, $agentnum) ? 'CHECKED' : '' %> >
+
+% } elsif ( $type eq 'text' ) {
+
+ <input name="<% "$key$n" %>" type="text" value="<% $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : '' %>">
+
+% } elsif ( $type eq 'select' || $type eq 'selectmultiple' ) {
+
+ <select name="<% "$key$n" %>" <% $type eq 'selectmultiple' ? 'MULTIPLE' : '' %>>
+
+%
+% my %hash = ();
+% if ( $config_item->select_enum ) {
+% tie %hash, 'Tie::IxHash',
+% '' => '', map { $_ => $_ } @{ $config_item->select_enum };
+% } elsif ( $config_item->select_hash ) {
+% if ( ref($config_item->select_hash) eq 'ARRAY' ) {
+% tie %hash, 'Tie::IxHash',
+% '' => '', @{ $config_item->select_hash };
+% } else {
+% tie %hash, 'Tie::IxHash',
+% '' => '', %{ $config_item->select_hash };
+% }
+% } else {
+% %hash = ( '' => 'WARNING: neither select_enum nor select_hash specified in Conf.pm for configuration option "'. $key. '"' );
+% }
+%
+% my %saw = ();
+% foreach my $value ( keys %hash ) {
+% local($^W)=0; next if $saw{$value}++;
+% my $label = $hash{$value};
%
-% if ( $type eq '' ) {
+ <option value="<% $value %>"
+
+% if ( $value eq $conf->config($key, $agentnum)
+% || ( $type eq 'selectmultiple'
+% && grep { $_ eq $value } $conf->config($key, $agentnum) ) ) {
+
+ SELECTED
+
+% }
+
+ ><% $label %>
+
+% }
+% my $curvalue = $conf->config($key, $agentnum);
+% if ( $conf->exists($key, $agentnum) && $curvalue && ! $hash{$curvalue} ) {
- <font color="#ff0000">no type</font>
-% } elsif ( $type eq 'binary' ) {
+ <option value="<% $curvalue %>" SELECTED>
+% if ( exists( $hash{ $conf->config($key, $agentnum) } ) ) {
- Filename <input type="file" name="<% $i->key. $n %>">
-% } elsif ( $type eq 'textarea' ) {
+ <% $hash{ $conf->config($key, $agentnum) } %>
+% }else{
- <textarea name="<% $i->key. $n %>" rows=5><% "\n". join("\n", $conf->config($i->key) ) %></textarea>
-% } elsif ( $type eq 'checkbox' ) {
+ <% $curvalue %>
+% }
+% }
- <input name="<% $i->key. $n %>" type="checkbox" value="1"<% $conf->exists($i->key) ? ' CHECKED' : '' %>>
-% } elsif ( $type eq 'text' ) {
+ </select>
+% } elsif ( $type eq 'select-sub' ) {
- <input name="<% $i->key. $n %>" type="<% $type %>" value="<% $conf->exists($i->key) ? $conf->config($i->key) : '' %>">
-% } elsif ( $type eq 'select' || $type eq 'selectmultiple' ) {
+ <select name="<% "$key$n" %>"><option value="">
-
- <select name="<% $i->key. $n %>" <% $type eq 'selectmultiple' ? 'MULTIPLE' : '' %>>
-%
-% my %hash = ();
-% if ( $i->select_enum ) {
-% tie %hash, 'Tie::IxHash',
-% '' => '', map { $_ => $_ } @{ $i->select_enum };
-% } elsif ( $i->select_hash ) {
-% if ( ref($i->select_hash) eq 'ARRAY' ) {
-% tie %hash, 'Tie::IxHash',
-% '' => '', @{ $i->select_hash };
-% } else {
-% tie %hash, 'Tie::IxHash',
-% '' => '', %{ $i->select_hash };
-% }
-% } else {
-% %hash = ( '' => 'WARNING: neither select_enum nor select_hash specified in Conf.pm for configuration option "'. $i->key. '"' );
-% }
+% my %options = &{$config_item->options_sub};
+% my @options = sort { $a <=> $b } keys %options;
+% my %saw;
+% foreach my $value ( @options ) {
+% local($^W)=0; next if $saw{$value}++;
+
+ <option value="<% $value %>" <% $value eq $conf->config($key, $agentnum) ? 'SELECTED' : '' %>><% $value %>: <% $options{$value} %>
+
+% }
+% my $curvalue = $conf->config($key, $agentnum);
+% if ( $conf->exists($key, $agentnum) && $curvalue && ! $options{$curvalue} ) {
+
+ <option value="<% $curvalue %>" SELECTED> <% $curvalue %>: <% &{ $config_item->option_sub }( $curvalue ) %>
+
+% }
+
+ </select>
+
+% } elsif ( $type eq 'editlist' ) {
%
-% my %saw = ();
-% foreach my $value ( keys %hash ) {
-% local($^W)=0; next if $saw{$value}++;
-% my $label = $hash{$value};
-%
+ <script>
+ function doremove<% "$key$n" %>() {
+ fromObject = document.OneTrueForm.<% "$key$n" %>;
+ for (var i=fromObject.options.length-1;i>-1;i--) {
+ if (fromObject.options[i].selected)
+ deleteOption<% "$key$n" %>(fromObject,i);
+ }
+ }
+ function deleteOption<% "$key$n" %>(object,index) {
+ object.options[index] = null;
+ }
+ function selectall<% "$key$n" %>() {
+ fromObject = document.OneTrueForm.<% "$key$n" %>;
+ for (var i=fromObject.options.length-1;i>-1;i--) {
+ fromObject.options[i].selected = true;
+ }
+ }
+ function doadd<% "$key$n" %>(object) {
+ var myvalue = "";
+% if ( defined($config_item->editlist_parts) ) {
+% foreach my $pnum ( 0 .. scalar(@{$config_item->editlist_parts})-1 ) {
- <option value="<% $value %>"<% $value eq $conf->config($i->key) || ( $type eq 'selectmultiple' && grep { $_ eq $value } $conf->config($i->key) ) ? ' SELECTED' : '' %>><% $label %>
-% }
-% my $curvalue = $conf->config($i->key);
-% if ( $conf->exists($i->key) && $curvalue
-% && ! $hash{$curvalue}
-% ) {
-%
-
-
- <option value="<% $conf->config($i->key) %>" SELECTED><% exists( $hash{ $conf->config($i->key) } ) ? $hash{ $conf->config($i->key) } : $conf->config($i->key) %>
-% }
+ if ( myvalue != "" ) { myvalue = myvalue + " "; }
+% if ( $config_item->editlist_parts->[$pnum]{type} eq 'select' ) {
- </select>
-% } elsif ( $type eq 'select-sub' ) {
+ myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.options[object.add<% "$key${n}_$pnum" %>.selectedIndex].value
+ <!-- #RESET SELECT?? maybe not... -->
+% } elsif ( $config_item->editlist_parts->[$pnum]{type} eq 'immutable' ) {
- <select name="<% $i->key. $n %>">
- <option value="">
-% my %options = &{$i->options_sub};
-% my @options = sort { $a <=> $b } keys %options;
-% my %saw;
-% foreach my $value ( @options ) {
-% local($^W)=0; next if $saw{$value}++;
-%
+ myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
- <option value="<% $value %>"<% $value eq $conf->config($i->key) ? ' SELECTED' : '' %>><% $value %>: <% $options{$value} %>
-% }
-% if ( $conf->exists($i->key) && $conf->config($i->key) && ! exists $options{$conf->config($i->key)} ) {
+% } else {
- <option value=<% $conf->config($i->key) %> SELECTED><% $conf->config($i->key) %>: <% &{ $i->option_sub }( $conf->config($i->key) ) %>
-% }
+ myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
+ object.add<% "$key${n}_$pnum" %>.value = ""
- </select>
-% } elsif ( $type eq 'editlist' ) {
-
-
- <script>
- function doremove<% $i->key. $n %>() {
- fromObject = document.OneTrueForm.<% $i->key. $n %>;
- for (var i=fromObject.options.length-1;i>-1;i--) {
- if (fromObject.options[i].selected)
- deleteOption<% $i->key. $n %>(fromObject,i);
- }
- }
- function deleteOption<% $i->key. $n %>(object,index) {
- object.options[index] = null;
- }
- function selectall<% $i->key. $n %>() {
- fromObject = document.OneTrueForm.<% $i->key. $n %>;
- for (var i=fromObject.options.length-1;i>-1;i--) {
- fromObject.options[i].selected = true;
- }
- }
- function doadd<% $i->key. $n %>(object) {
- var myvalue = "";
-% if ( defined($i->editlist_parts) ) {
-% foreach my $pnum ( 0 .. scalar(@{$i->editlist_parts})-1 ) {
-
-
- if ( myvalue != "" ) { myvalue = myvalue + " "; }
-% if ( $i->editlist_parts->[$pnum]{type} eq 'select' ) {
-
- myvalue = myvalue + object.add<% $i->key. $n . "_$pnum" %>.options[object.add<% $i->key. $n . "_$pnum" %>.selectedIndex].value;
- <!-- #RESET SELECT?? maybe not... -->
-% } elsif ( $i->editlist_parts->[$pnum]{type} eq 'immutable' ) {
-
- myvalue = myvalue + object.add<% $i->key. $n . "_$pnum" %>.value;
-% } else {
-
- myvalue = myvalue + object.add<% $i->key. $n . "_$pnum" %>.value;
- object.add<% $i->key. $n. "_$pnum" %>.value = "";
-% }
-% }
-% } else {
+% }
+% }
+% } else {
- myvalue = object.add<% $i->key. $n. "_1" %>.value;
-% }
+ myvalue = object.add<% "$key${n}_1" %>.value
- var optionName = new Option(myvalue, myvalue);
- var length = object.<% $i->key. $n %>.length;
- object.<% $i->key. $n %>.options[length] = optionName;
- }
- </script>
- <select multiple size=5 name="<% $i->key. $n %>">
- <option selected>----------------------------------------------------------------</option>
-% foreach my $line ( $conf->config($i->key) ) {
+% }
- <option value="<% $line %>"><% $line %></option>
-% }
+ var optionName = new Option(myvalue, myvalue);
+ var length = object.<% "$key$n" %>.length;
+ object.<% "$key$n" %>.options[length] = optionName;
+ }
+ </script>
+ <select multiple size=5 name="<% "$key$n" %>">
+ <option selected>----------------------------------------------------------------</option>
- </select><br>
- <input type="button" value="remove selected" onClick="doremove<% $i->key. $n %>()">
- <script>SafeAddOnLoad(doremove<% $i->key. $n %>);
- SafeAddOnSubmit(selectall<% $i->key. $n %>);</script>
- <br>
- <% itable() %><tr>
-% if ( defined $i->editlist_parts ) {
-% my $pnum=0; foreach my $part ( @{$i->editlist_parts} ) {
+% foreach my $line ( $conf->config($key, $agentnum) ) {
- <td>
-% if ( $part->{type} eq 'text' ) {
+ <option value="<% $line %>"><% $line %></option>
- <input type="text" name="add<% $i->key. $n."_$pnum" %>">
-% } elsif ( $part->{type} eq 'immutable' ) {
+% }
- <% $part->{value} %><input type="hidden" name="add<% $i->key. $n. "_$pnum" %>" value="<% $part->{value} %>">
-% } elsif ( $part->{type} eq 'select' ) {
+ </select><br>
+ <input type="button" value="remove selected" onClick="doremove<% "$key$n" %>()">
+ <script>SafeAddOnLoad(doremove<% "$key$n" %>);
+ SafeAddOnSubmit(selectall<% "$key$n" %>);
+ </script>
+ <br><% itable() %><tr>
- <select name="add<% $i->key. $n. "_$pnum" %>">
-% foreach my $key ( keys %{$part->{select_enum}} ) {
+% if ( defined $config_item->editlist_parts ) {
+% my $pnum=0;
+% foreach my $part ( @{$config_item->editlist_parts} ) {
- <option value="<% $key %>"><% $part->{select_enum}{$key} %></option>
-% }
+ <td>
- </select>
-% } else {
+% if ( $part->{type} eq 'text' ) {
- <font color="#ff0000">unknown type <% $part->type %></font>
-% }
+ <input type="text" name="add<% "$key${n}_$pnum" %>">
- </td>
-% $pnum++; }
-% } else {
+% } elsif ( $part->{type} eq 'immutable' ) {
- <td><input type="text" name="add<% $i->key. $n %>_0"></td>
-% }
+ <% $part->{value} %>
+ <input type="hidden" name="add<% "$key${n}_$pnum" %>" value="<% $part->{value} %>">
- <td><input type="button" value="add" onClick="doadd<% $i->key. $n %>(this.form)"></td>
- </tr></table>
-% } else {
+% } elsif ( $part->{type} eq 'select' ) {
+ <select name="add<% qq!$key${n}_$pnum! %>">
- <font color="#ff0000">unknown type <% $type %></font>
-% }
-% $n++; }
+% foreach my $key ( keys %{$part->{select_enum}} ) {
- </td>
- <td><a name="<% $i->key %>">
- <b><% $i->key %></b> - <% $i->description %>
- </a></td>
- </tr>
-% }
+ <option value="<% $key %>"><% $part->{select_enum}{$key} %></option>
- </table><br>
+% }
- You may need to restart Apache and/or freeside-queued for configuration
- changes to take effect.<br>
+ </select>
- <input type="submit" value="Apply changes"><br><br>
-% }
+% } else {
+
+ <font color="#ff0000">unknown type <% $part->type %> </font>
+
+% }
+
+ </td>
+
+% $pnum++;
+% }
+% } else {
+ <td><input type="text" name="add<% "$key${n}_0" %>></td>
-</form>
+% }
+
+ <td><input type="button" value="add" onClick="doadd<% "$key$n" %>(this.form)"></td>
+ </tr></table>
+
+% } else {
+
+ <font color="#ff0000">unknown type $type</font>
+
+% }
+% $n++;
+% }
+
+ </td><td><% $description %></td></tr></table>
+<INPUT TYPE="submit" VALUE="<% $title %>">
+</FORM>
+
+</BODY>
+</HTML>
+<%once>
+my $conf = new FS::Conf;
+my %confitems = map { $_->key => $_ } $conf->config_items;
+</%once>
-</body></html>
<%init>
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+
+my($agentnum, $agent, $title, $action, $key, $value, $config_item,
+ $description, $type);
+
+$action = 'Set';
+
+if ($cgi->param('agentnum') =~ /(\d+)$/) {
+ $agentnum=$1;
+}
+
+if ($agentnum) {
+ $agent = qsearchs('agent', { 'agentnum' => $1 } );
+ die "Agent $agentnum not found!" unless $agent;
+
+ $title = "$action configuration override for ". $agent->agent;
+} else {
+ $title = "$action global configuration";
+}
+
+$cgi->param('key') =~ /^([-.\w]+)$/ or die "illegal configuration item";
+$key=$1;
+$value = $conf->config($key);
+$config_item = $confitems{$key};
+
+$description = $config_item->description;
+$type = $config_item->type;
+
</%init>