+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+die "access denied" unless $curuser->access_right('Configuration');
+
+my $page_agent = '';
+my $title;
+my @menubar = ();
+if ($cgi->param('agentnum') =~ /^(\d+)$/) {
+ my $page_agentnum = $1;
+ $page_agent = qsearchs('agent', { 'agentnum' => $page_agentnum } );
+ die "Agent $page_agentnum not found!" unless $page_agent;
+
+ push @menubar, 'View all agents' => $p.'browse/agent.cgi';
+}
+
+my $conf = new FS::Conf;
+my $conf_global = $conf;
+
+my @locales = $conf_global->config('available-locales');
+
+# if this is set, we are in locale mode, so limit the displayed items
+# to those with per_locale.
+my $locale;
+my $locale_desc;
+if ( $cgi->param('locale') =~ /^\w+_\w+$/ ) {
+ $locale = $cgi->param('locale');
+ # and set the context on $conf
+ $conf = new FS::Conf { 'locale' => $locale, 'localeonly' => 1 };
+ my %locale_info = FS::Locales->locale_info($locale);
+ $locale_desc = "$locale_info{name} ($locale_info{country})";
+
+ $title = 'Invoice Configuration'; #for now it is only invoicing
+ $title .= ' for '.$page_agent->agent if $page_agent;
+ $title .= ', '.$locale_desc;
+
+} elsif ($page_agent) {
+ $title = 'Agent Configuration for '. $page_agent->agent;
+ $title .= ", $locale_desc" if $locale;
+} else {
+ $title = 'Global Configuration';
+}
+
+my @config_items = grep { !defined($locale) or $_->per_locale }
+ grep { $page_agent ? $_->per_agent : 1 }
+ grep { $page_agent ? 1 : !$_->agentonly }
+ $conf->config_items;
+
+my @deleteable = qw( invoice_latexreturnaddress invoice_htmlreturnaddress );
+my %deleteable = map { $_ => 1 } @deleteable;
+
+my @sections = (qw(
+ required billing invoicing notification UI API self-service ticketing
+ network_monitoring username password session shell BIND telephony
+ ), '', 'deprecated'
+);
+
+my %section_items = ();
+foreach my $section (@sections) {
+ $section_items{$section} = [ grep $_->section eq $section, @config_items ];
+}
+
+@sections = grep scalar( @{ $section_items{$_} } ), @sections;
+
+my @all_agents = ();
+if ( $cgi->param('showagent') ) {
+ @all_agents = qsearch('agent', { 'disabled' => '' } );
+}
+