Rate CDRs immediately, RT#15839
[freeside.git] / FS / FS / Conf.pm
index 3aaa667..473c7be 100644 (file)
@@ -8,6 +8,7 @@ use MIME::Base64;
 use FS::ConfItem;
 use FS::ConfDefaults;
 use FS::Conf_compat17;
+use FS::Locales;
 use FS::payby;
 use FS::conf;
 use FS::Record qw(qsearch qsearchs);
@@ -46,16 +47,25 @@ but this may change in the future.
 
 =over 4
 
-=item new
+=item new [ HASHREF ]
 
 Create a new configuration object.
 
+HASHREF may contain options to set the configuration context.  Currently 
+accepts C<locale>, and C<localeonly> to disable fallback to the null locale.
+
 =cut
 
 sub new {
-  my($proto) = @_;
+  my($proto) = shift;
+  my $opts = shift || {};
   my($class) = ref($proto) || $proto;
-  my($self) = { 'base_dir' => $base_dir };
+  my $self = {
+    'base_dir'    => $base_dir,
+    'locale'      => $opts->{locale},
+    'localeonly'  => $opts->{localeonly}, # for config-view.cgi ONLY
+  };
+  warn "FS::Conf created with no locale fallback.\n" if $self->{localeonly};
   bless ($self, $class);
 }
 
@@ -107,14 +117,26 @@ sub _usecompat {
 sub _config {
   my($self,$name,$agentnum,$agentonly)=@_;
   my $hashref = { 'name' => $name };
-  $hashref->{agentnum} = $agentnum;
   local $FS::Record::conf = undef;  # XXX evil hack prevents recursion
-  my $cv = FS::Record::qsearchs('conf', $hashref);
-  if (!$agentonly && !$cv && defined($agentnum) && $agentnum) {
-    $hashref->{agentnum} = '';
-    $cv = FS::Record::qsearchs('conf', $hashref);
+  my $cv;
+  my @a = (
+    ($agentnum || ()),
+    ($agentonly && $agentnum ? () : '')
+  );
+  my @l = (
+    ($self->{locale} || ()),
+    ($self->{localeonly} && $self->{locale} ? () : '')
+  );
+  # try with the agentnum first, then fall back to no agentnum if allowed
+  foreach my $a (@a) {
+    $hashref->{agentnum} = $a;
+    foreach my $l (@l) {
+      $hashref->{locale} = $l;
+      $cv = FS::Record::qsearchs('conf', $hashref);
+      return $cv if $cv;
+    }
   }
-  return $cv;
+  return undef;
 }
 
 sub config {
@@ -267,10 +289,14 @@ sub set {
 
   warn "[FS::Conf] SET $name\n" if $DEBUG;
 
-  my $old = FS::Record::qsearchs('conf', {name => $name, agentnum => $agentnum});
-  my $new = new FS::conf { $old ? $old->hash 
-                                : ('name' => $name, 'agentnum' => $agentnum)
-                         };
+  my $hashref = {
+    name => $name,
+    agentnum => $agentnum,
+    locale => $self->{locale}
+  };
+
+  my $old = FS::Record::qsearchs('conf', $hashref);
+  my $new = new FS::conf { $old ? $old->hash : %$hashref };
   $new->value($value);
 
   my $error;
@@ -311,8 +337,8 @@ sub delete {
   return $self->_usecompat('delete', @_) if use_confcompat;
 
   my($name, $agentnum) = @_;
-  if ( my $cv = FS::Record::qsearchs('conf', {name => $name, agentnum => $agentnum}) ) {
-    warn "[FS::Conf] DELETE $name\n";
+  if ( my $cv = FS::Record::qsearchs('conf', {name => $name, agentnum => $agentnum, locale => $self->{locale}}) ) {
+    warn "[FS::Conf] DELETE $name\n" if $DEBUG;
 
     my $oldAutoCommit = $FS::UID::AutoCommit;
     local $FS::UID::AutoCommit = 0;
@@ -395,6 +421,7 @@ sub verify_config_item {
 
   } else {
 
+    no warnings 'uninitialized';
     $error .= "$key fails binary comparison; "
       unless scalar($self->config_binary($key)) eq scalar($compat->config_binary($key));
 
@@ -464,7 +491,7 @@ sub _orbase_items {
                   'key'         => $_,
                   'base_key'    => $proto->key,
                   'section'     => $proto->section,
-                  'description' => 'Alternate ' . $proto->description . '  See the <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:1.7:Documentation:Administration#Invoice_templates">billing documentation</a> for details.',
+                  'description' => 'Alternate ' . $proto->description . '  See the <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:2.1:Documentation:Administration#Invoice_templates">billing documentation</a> for details.',
                   'type'        => $proto->type,
                 };
               } &$listmaker($base);
@@ -549,21 +576,67 @@ worry that config_items is freeside-specific and icky.
   "Solo",
 );
 
-@base_items = qw (
-                   invoice_template
-                   invoice_latex
-                   invoice_latexreturnaddress
-                   invoice_latexfooter
-                   invoice_latexsmallfooter
-                   invoice_latexnotes
-                   invoice_latexcoupon
-                   invoice_html
-                   invoice_htmlreturnaddress
-                   invoice_htmlfooter
-                   invoice_htmlnotes
-                   logo.png
-                   logo.eps
-                 );
+@base_items = qw(
+invoice_template
+invoice_latex
+invoice_latexreturnaddress
+invoice_latexfooter
+invoice_latexsmallfooter
+invoice_latexnotes
+invoice_latexcoupon
+invoice_html
+invoice_htmlreturnaddress
+invoice_htmlfooter
+invoice_htmlnotes
+logo.png
+logo.eps
+);
+
+my %msg_template_options = (
+  'type'        => 'select-sub',
+  'options_sub' => sub { 
+    my @templates = qsearch({
+        'table' => 'msg_template', 
+        'hashref' => { 'disabled' => '' },
+        'extra_sql' => ' AND '. 
+          $FS::CurrentUser::CurrentUser->agentnums_sql(null => 1),
+        });
+    map { $_->msgnum, $_->msgname } @templates;
+  },
+  'option_sub'  => sub { 
+                         my $msg_template = FS::msg_template->by_key(shift);
+                         $msg_template ? $msg_template->msgname : ''
+                       },
+  'per_agent' => 1,
+);
+
+my $_gateway_name = sub {
+  my $g = shift;
+  return '' if !$g;
+  ($g->gateway_username . '@' . $g->gateway_module);
+};
+
+my %payment_gateway_options = (
+  'type'        => 'select-sub',
+  'options_sub' => sub {
+    my @gateways = qsearch({
+        'table' => 'payment_gateway',
+        'hashref' => { 'disabled' => '' },
+      });
+    map { $_->gatewaynum, $_gateway_name->($_) } @gateways;
+  },
+  'option_sub'  => sub {
+    my $gateway = FS::payment_gateway->by_key(shift);
+    $_gateway_name->($gateway);
+  },
+);
+
+#Billing (81 items)
+#Invoicing (50 items)
+#UI (69 items)
+#Self-service (29 items)
+#...
+#Unclassified (77 items)
 
 @config_items = map { new FS::ConfItem $_ } (
 
@@ -575,8 +648,15 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'log_sent_mail',
+    'section'     => 'notification',
+    'description' => 'Enable logging of template-generated email.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'alert_expiration',
-    'section'     => 'billing',
+    'section'     => 'notification',
     'description' => 'Enable alerts about billing method expiration (i.e. expiring credit cards).',
     'type'        => 'checkbox',
     'per_agent'   => 1,
@@ -584,11 +664,18 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'alerter_template',
-    'section'     => 'billing',
-    'description' => 'Template file for billing method expiration alerts (i.e. expiring credit cards).  See the <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:1.7:Documentation:Administration#Credit_cards_and_Electronic_checks">billing documentation</a> for details.',
+    'section'     => 'deprecated',
+    'description' => 'Template file for billing method expiration alerts (i.e. expiring credit cards).',
     'type'        => 'textarea',
     'per_agent'   => 1,
   },
+  
+  {
+    'key'         => 'alerter_msgnum',
+    'section'     => 'notification',
+    'description' => 'Template to use for credit card expiration alerts.',
+    %msg_template_options,
+  },
 
   {
     'key'         => 'apacheip',
@@ -599,11 +686,53 @@ worry that config_items is freeside-specific and icky.
     'description' => 'IP address to assign to new virtual hosts',
     'type'        => 'text',
   },
+  
+  {
+    'key'         => 'credits-auto-apply-disable',
+    'section'     => 'billing',
+    'description' => 'Disable the "Auto-Apply to invoices" UI option for new credits',
+    'type'        => 'checkbox',
+  },
+  
+  {
+    'key'         => 'credit-card-surcharge-percentage',
+    'section'     => 'billing',
+    'description' => 'Add a credit card surcharge to invoices, as a % of the invoice total. WARNING: this is usually prohibited by merchant account / other agreements and/or law, but is currently lawful in AU and UK.',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'discount-show-always',
+    'section'     => 'billing',
+    'description' => 'Generate a line item on an invoice even when a package is discounted 100%',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'discount-show_available',
+    'section'     => 'billing',
+    'description' => 'Show available prepayment discounts on invoices.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'invoice-barcode',
+    'section'     => 'billing',
+    'description' => 'Display a barcode on HTML and PDF invoices',
+    'type'        => 'checkbox',
+  },
+  
+  {
+    'key'         => 'cust_main-select-billday',
+    'section'     => 'billing',
+    'description' => 'When used with a specific billing event, allows the selection of the day of month on which to charge credit card / bank account automatically, on a per-customer basis',
+    'type'        => 'checkbox',
+  },
 
   {
     'key'         => 'encryption',
     'section'     => 'billing',
-    'description' => 'Enable encryption of credit cards.',
+    'description' => 'Enable encryption of credit cards and echeck numbers',
     'type'        => 'checkbox',
   },
 
@@ -611,20 +740,21 @@ worry that config_items is freeside-specific and icky.
     'key'         => 'encryptionmodule',
     'section'     => 'billing',
     'description' => 'Use which module for encryption?',
-    'type'        => 'text',
+    'type'        => 'select',
+    'select_enum' => [ '', 'Crypt::OpenSSL::RSA', ],
   },
 
   {
     'key'         => 'encryptionpublickey',
     'section'     => 'billing',
-    'description' => 'Your RSA Public Key - Required if Encryption is turned on.',
+    'description' => 'Encryption public key',
     'type'        => 'textarea',
   },
 
   {
     'key'         => 'encryptionprivatekey',
     'section'     => 'billing',
-    'description' => 'Your RSA Private Key - Including this will enable the "Bill Now" feature.  However if the system is compromised, a hacker can use this key to decode the stored credit card information.  This is generally not a good idea.',
+    'description' => 'Encryption private key',
     'type'        => 'textarea',
   },
 
@@ -661,7 +791,14 @@ worry that config_items is freeside-specific and icky.
     'type'        => 'text',
     'per_agent'   => 1,
   },
-
+  
+  {
+    'key'         => 'next-bill-ignore-time',
+    'section'     => 'billing',
+    'description' => 'Ignore the time portion of next bill dates when billing, matching anything from 00:00:00 to 23:59:59 on the billing day.',
+    'type'        => 'checkbox',
+  },
+  
   {
     'key'         => 'business-onlinepayment',
     'section'     => 'billing',
@@ -690,7 +827,7 @@ worry that config_items is freeside-specific and icky.
   {
     'key'         => 'business-onlinepayment-description',
     'section'     => 'billing',
-    'description' => 'String passed as the description field to <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a>.  Evaluated as a double-quoted perl string, with the following variables available: <code>$agent</code> (the agent name), and <code>$pkgs</code> (a comma-separated list of packages for which these charges apply)',
+    'description' => 'String passed as the description field to <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a>.  Evaluated as a double-quoted perl string, with the following variables available: <code>$agent</code> (the agent name), and <code>$pkgs</code> (a comma-separated list of packages for which these charges apply - not available in all situations)',
     'type'        => 'text',
   },
 
@@ -709,6 +846,21 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'business-onlinepayment-test_transaction',
+    'section'     => 'billing',
+    'description' => 'Turns on the Business::OnlinePayment test_transaction flag.  Note that not all gateway modules support this flag; if yours does not, transactions will still be sent live.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'business-onlinepayment-currency',
+    'section'     => 'billing',
+    'description' => 'Currency parameter for Business::OnlinePayment transactions.',
+    'type'        => 'select',
+    'select_enum' => [ '', qw( USD AUD CAD DKK EUR GBP ILS JPY NZD ) ],
+  },
+
+  {
     'key'         => 'countrydefault',
     'section'     => 'UI',
     'description' => 'Default two-letter country code (if not supplied, the default is `US\')',
@@ -722,11 +874,23 @@ worry that config_items is freeside-specific and icky.
     'type'        => 'select',
     'select_hash' => [
                        '%m/%d/%Y' => 'MM/DD/YYYY',
+                       '%d/%m/%Y' => 'DD/MM/YYYY',
                       '%Y/%m/%d' => 'YYYY/MM/DD',
                      ],
   },
 
   {
+    'key'         => 'date_format_long',
+    'section'     => 'UI',
+    'description' => 'Verbose format for displaying dates',
+    'type'        => 'select',
+    'select_hash' => [
+                       '%b %o, %Y' => 'Mon DDth, YYYY',
+                       '%e %b %Y'  => 'DD Mon YYYY',
+                     ],
+  },
+
+  {
     'key'         => 'deletecustomers',
     'section'     => 'UI',
     'description' => 'Enable customer deletions.  Be very careful!  Deleting a customer will remove all traces that the customer ever existed!  It should probably only be used when auditing a legacy database.  Normally, you cancel all of a customers\' packages if they cancel service.',
@@ -815,35 +979,35 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'emailinvoiceonly',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Disables postal mail invoices',
     'type'        => 'checkbox',
   },
 
   {
     'key'         => 'disablepostalinvoicedefault',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Disables postal mail invoices as the default option in the UI.  Be careful not to setup customers which are not sent invoices.  See <a href ="#emailinvoiceauto">emailinvoiceauto</a>.',
     'type'        => 'checkbox',
   },
 
   {
     'key'         => 'emailinvoiceauto',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Automatically adds new accounts to the email invoice list',
     'type'        => 'checkbox',
   },
 
   {
     'key'         => 'emailinvoiceautoalways',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Automatically adds new accounts to the email invoice list even when the list contains email addresses',
     'type'        => 'checkbox',
   },
 
   {
     'key'         => 'emailinvoice-apostrophe',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Allows the apostrophe (single quote) character in the email addresses in the email invoice list.',
     'type'        => 'checkbox',
   },
@@ -893,159 +1057,315 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'invoice_subject',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Subject: header on email invoices.  Defaults to "Invoice".  The following substitutions are available: $name, $name_short, $invoice_number, and $invoice_date.',
     'type'        => 'text',
     'per_agent'   => 1,
+    'per_locale'  => 1,
   },
 
   {
     'key'         => 'invoice_usesummary',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Indicates that html and latex invoices should be in summary style and make use of invoice_latexsummary.',
     'type'        => 'checkbox',
   },
 
   {
     'key'         => 'invoice_template',
-    'section'     => 'billing',
-    'description' => 'Text template file for invoices.  Used if no invoice_html template is defined, and also seen by users using non-HTML capable mail clients.  See the <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:1.7:Documentation:Administration#Plaintext_invoice_templates">billing documentation</a> for details.',
+    'section'     => 'invoicing',
+    'description' => 'Text template file for invoices.  Used if no invoice_html template is defined, and also seen by users using non-HTML capable mail clients.  See the <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:2.1:Documentation:Administration#Plaintext_invoice_templates">billing documentation</a> for details.',
     'type'        => 'textarea',
   },
 
   {
     'key'         => 'invoice_html',
-    'section'     => 'billing',
-    'description' => 'Optional HTML template for invoices.  See the <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:1.7:Documentation:Administration#HTML_invoice_templates">billing documentation</a> for details.',
+    'section'     => 'invoicing',
+    'description' => 'Optional HTML template for invoices.  See the <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:2.1:Documentation:Administration#HTML_invoice_templates">billing documentation</a> for details.',
 
     'type'        => 'textarea',
   },
 
   {
     'key'         => 'invoice_htmlnotes',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Notes section for HTML invoices.  Defaults to the same data in invoice_latexnotes if not specified.',
     'type'        => 'textarea',
     'per_agent'   => 1,
+    'per_locale'  => 1,
   },
 
   {
     'key'         => 'invoice_htmlfooter',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Footer for HTML invoices.  Defaults to the same data in invoice_latexfooter if not specified.',
     'type'        => 'textarea',
     'per_agent'   => 1,
+    'per_locale'  => 1,
   },
 
   {
     'key'         => 'invoice_htmlsummary',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Summary initial page for HTML invoices.',
     'type'        => 'textarea',
     'per_agent'   => 1,
+    'per_locale'  => 1,
   },
 
   {
     'key'         => 'invoice_htmlreturnaddress',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Return address for HTML invoices.  Defaults to the same data in invoice_latexreturnaddress if not specified.',
     'type'        => 'textarea',
+    'per_locale'  => 1,
   },
 
   {
     'key'         => 'invoice_latex',
-    'section'     => 'billing',
-    'description' => 'Optional LaTeX template for typeset PostScript invoices.  See the <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:1.7:Documentation:Administration#Typeset_.28LaTeX.29_invoice_templates">billing documentation</a> for details.',
+    'section'     => 'invoicing',
+    'description' => 'Optional LaTeX template for typeset PostScript invoices.  See the <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:2.1:Documentation:Administration#Typeset_.28LaTeX.29_invoice_templates">billing documentation</a> for details.',
     'type'        => 'textarea',
   },
 
   {
+    'key'         => 'invoice_latextopmargin',
+    'section'     => 'invoicing',
+    'description' => 'Optional LaTeX invoice topmargin setting. Include units.',
+    'type'        => 'text',
+    'per_agent'   => 1,
+    'validate'    => sub { shift =~
+                             /^-?\d*\.?\d+(in|mm|cm|pt|em|ex|pc|bp|dd|cc|sp)$/
+                             ? '' : 'Invalid LaTex length';
+                         },
+  },
+
+  {
+    'key'         => 'invoice_latexheadsep',
+    'section'     => 'invoicing',
+    'description' => 'Optional LaTeX invoice headsep setting. Include units.',
+    'type'        => 'text',
+    'per_agent'   => 1,
+    'validate'    => sub { shift =~
+                             /^-?\d*\.?\d+(in|mm|cm|pt|em|ex|pc|bp|dd|cc|sp)$/
+                             ? '' : 'Invalid LaTex length';
+                         },
+  },
+
+  {
+    'key'         => 'invoice_latexaddresssep',
+    'section'     => 'invoicing',
+    'description' => 'Optional LaTeX invoice separation between invoice header
+and customer address. Include units.',
+    'type'        => 'text',
+    'per_agent'   => 1,
+    'validate'    => sub { shift =~
+                             /^-?\d*\.?\d+(in|mm|cm|pt|em|ex|pc|bp|dd|cc|sp)$/
+                             ? '' : 'Invalid LaTex length';
+                         },
+  },
+
+  {
+    'key'         => 'invoice_latextextheight',
+    'section'     => 'invoicing',
+    'description' => 'Optional LaTeX invoice textheight setting. Include units.',
+    'type'        => 'text',
+    'per_agent'   => 1,
+    'validate'    => sub { shift =~
+                             /^-?\d*\.?\d+(in|mm|cm|pt|em|ex|pc|bp|dd|cc|sp)$/
+                             ? '' : 'Invalid LaTex length';
+                         },
+  },
+
+  {
     'key'         => 'invoice_latexnotes',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Notes section for LaTeX typeset PostScript invoices.',
     'type'        => 'textarea',
     'per_agent'   => 1,
+    'per_locale'  => 1,
   },
 
   {
     'key'         => 'invoice_latexfooter',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Footer for LaTeX typeset PostScript invoices.',
     'type'        => 'textarea',
     'per_agent'   => 1,
+    'per_locale'  => 1,
   },
 
   {
     'key'         => 'invoice_latexsummary',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Summary initial page for LaTeX typeset PostScript invoices.',
     'type'        => 'textarea',
     'per_agent'   => 1,
+    'per_locale'  => 1,
   },
 
   {
     'key'         => 'invoice_latexcoupon',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Remittance coupon for LaTeX typeset PostScript invoices.',
     'type'        => 'textarea',
     'per_agent'   => 1,
+    'per_locale'  => 1,
+  },
+
+  {
+    'key'         => 'invoice_latexextracouponspace',
+    'section'     => 'invoicing',
+    'description' => 'Optional LaTeX invoice textheight space to reserve for a tear off coupon. Include units.',
+    'type'        => 'text',
+    'per_agent'   => 1,
+    'validate'    => sub { shift =~
+                             /^-?\d*\.?\d+(in|mm|cm|pt|em|ex|pc|bp|dd|cc|sp)$/
+                             ? '' : 'Invalid LaTex length';
+                         },
+  },
+
+  {
+    'key'         => 'invoice_latexcouponfootsep',
+    'section'     => 'invoicing',
+    'description' => 'Optional LaTeX invoice separation between tear off coupon and footer. Include units.',
+    'type'        => 'text',
+    'per_agent'   => 1,
+    'validate'    => sub { shift =~
+                             /^-?\d*\.?\d+(in|mm|cm|pt|em|ex|pc|bp|dd|cc|sp)$/
+                             ? '' : 'Invalid LaTex length';
+                         },
+  },
+
+  {
+    'key'         => 'invoice_latexcouponamountenclosedsep',
+    'section'     => 'invoicing',
+    'description' => 'Optional LaTeX invoice separation between total due and amount enclosed line. Include units.',
+    'type'        => 'text',
+    'per_agent'   => 1,
+    'validate'    => sub { shift =~
+                             /^-?\d*\.?\d+(in|mm|cm|pt|em|ex|pc|bp|dd|cc|sp)$/
+                             ? '' : 'Invalid LaTex length';
+                         },
+  },
+  {
+    'key'         => 'invoice_latexcoupontoaddresssep',
+    'section'     => 'invoicing',
+    'description' => 'Optional LaTeX invoice separation between invoice data and the to address (usually invoice_latexreturnaddress).  Include units.',
+    'type'        => 'text',
+    'per_agent'   => 1,
+    'validate'    => sub { shift =~
+                             /^-?\d*\.?\d+(in|mm|cm|pt|em|ex|pc|bp|dd|cc|sp)$/
+                             ? '' : 'Invalid LaTex length';
+                         },
   },
 
   {
     'key'         => 'invoice_latexreturnaddress',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Return address for LaTeX typeset PostScript invoices.',
     'type'        => 'textarea',
   },
 
   {
+    'key'         => 'invoice_latexverticalreturnaddress',
+    'section'     => 'invoicing',
+    'description' => 'Place the return address under the company logo rather than beside it.',
+    'type'        => 'checkbox',
+    'per_agent'   => 1,
+  },
+
+  {
+    'key'         => 'invoice_latexcouponaddcompanytoaddress',
+    'section'     => 'invoicing',
+    'description' => 'Add the company name to the To address on the remittance coupon because the return address does not contain it.',
+    'type'        => 'checkbox',
+    'per_agent'   => 1,
+  },
+
+  {
     'key'         => 'invoice_latexsmallfooter',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Optional small footer for multi-page LaTeX typeset PostScript invoices.',
     'type'        => 'textarea',
     'per_agent'   => 1,
+    'per_locale'  => 1,
   },
 
   {
     'key'         => 'invoice_email_pdf',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Send PDF invoice as an attachment to emailed invoices.  By default, includes the plain text invoice as the email body, unless invoice_email_pdf_note is set.',
     'type'        => 'checkbox'
   },
 
   {
     'key'         => 'invoice_email_pdf_note',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'If defined, this text will replace the default plain text invoice as the body of emailed PDF invoices.',
     'type'        => 'textarea'
   },
 
+  {
+    'key'         => 'invoice_print_pdf',
+    'section'     => 'invoicing',
+    'description' => 'For all invoice print operations, store postal invoices for download in PDF format rather than printing them directly.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'invoice_print_pdf-spoolagent',
+    'section'     => 'invoicing',
+    'description' => 'Store postal invoices PDF downloads in per-agent spools.',
+    'type'        => 'checkbox',
+  },
 
   { 
     'key'         => 'invoice_default_terms',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Optional default invoice term, used to calculate a due date printed on invoices.',
     'type'        => 'select',
-    'select_enum' => [ '', 'Payable upon receipt', 'Net 0', 'Net 10', 'Net 15', 'Net 20', 'Net 30', 'Net 45', 'Net 60' ],
+    'select_enum' => [ '', 'Payable upon receipt', 'Net 0', 'Net 3', 'Net 9', 'Net 10', 'Net 15', 'Net 20', 'Net 21', 'Net 30', 'Net 45', 'Net 60', 'Net 90' ],
+  },
+
+  { 
+    'key'         => 'invoice_show_prior_due_date',
+    'section'     => 'invoicing',
+    'description' => 'Show previous invoice due dates when showing prior balances.  Default is to show invoice date.',
+    'type'        => 'checkbox',
+  },
+
+  { 
+    'key'         => 'invoice_include_aging',
+    'section'     => 'invoicing',
+    'description' => 'Show an aging line after the prior balance section.  Only valud when invoice_sections is enabled.',
+    'type'        => 'checkbox',
   },
 
   { 
     'key'         => 'invoice_sections',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Split invoice into sections and label according to package category when enabled.',
     'type'        => 'checkbox',
   },
 
   { 
     'key'         => 'usage_class_as_a_section',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Split usage into sections and label according to usage class name when enabled.  Only valid when invoice_sections is enabled.',
     'type'        => 'checkbox',
   },
 
   { 
+    'key'         => 'phone_usage_class_summary',
+    'section'     => 'invoicing',
+    'description' => 'Summarize usage per DID by usage class and display all CDRs together regardless of usage class. Only valid when svc_phone_sections is enabled.',
+    'type'        => 'checkbox',
+  },
+
+  { 
     'key'         => 'svc_phone_sections',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Create a section for each svc_phone when enabled.  Only valid when invoice_sections is enabled.',
     'type'        => 'checkbox',
   },
@@ -1053,13 +1373,13 @@ worry that config_items is freeside-specific and icky.
   {
     'key'         => 'finance_pkgclass',
     'section'     => 'billing',
-    'description' => 'The package class for finance charges',
+    'description' => 'The default package class for late fee charges, used if the fee event does not specify a package class itself.',
     'type'        => 'select-pkg_class',
   },
 
   { 
     'key'         => 'separate_usage',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Split the rated call usage into a separate line from the recurring charges.',
     'type'        => 'checkbox',
   },
@@ -1072,21 +1392,52 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'payment_receipt',
+    'section'     => 'notification',
+    'description' => 'Send payment receipts.',
+    'type'        => 'checkbox',
+    'per_agent'   => 1,
+  },
+
+  {
+    'key'         => 'payment_receipt_msgnum',
+    'section'     => 'notification',
+    'description' => 'Template to use for payment receipts.',
+    %msg_template_options,
+  },
+  
+  {
+    'key'         => 'payment_receipt_from',
+    'section'     => 'notification',
+    'description' => 'From: address for payment receipts, if not specified in the template.',
+    'type'        => 'text',
+    'per_agent'   => 1,
+  },
+
+  {
     'key'         => 'payment_receipt_email',
-    'section'     => 'billing',
-    'description' => 'Template file for payment receipts.  Payment receipts are sent to the customer email invoice destination(s) when a payment is received.  See the <a href="http://search.cpan.org/dist/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>$date</code> <li><code>$name</code> <li><code>$paynum</code> - Freeside payment number <li><code>$paid</code> - Amount of payment <li><code>$payby</code> - Payment type (Card, Check, Electronic check, etc.) <li><code>$payinfo</code> - Masked credit card number or check number <li><code>$balance</code> - New balance<li><code>$pkg</code> - Package (requires payment_receipt-trigger set to "when payment is applied".)</ul>',
+    'section'     => 'deprecated',
+    'description' => 'Template file for payment receipts.  Payment receipts are sent to the customer email invoice destination(s) when a payment is received.',
     'type'        => [qw( checkbox textarea )],
   },
 
   {
     'key'         => 'payment_receipt-trigger',
-    'section'     => 'billing',
+    'section'     => 'notification',
     'description' => 'When payment receipts are triggered.  Defaults to when payment is made.',
     'type'        => 'select',
     'select_hash' => [
                        'cust_pay'          => 'When payment is made.',
                        'cust_bill_pay_pkg' => 'When payment is applied.',
                      ],
+    'per_agent'   => 1,
+  },
+
+  {
+    'key'         => 'trigger_export_insert_on_payment',
+    'section'     => 'billing',
+    'description' => 'Enable exports on payment application.',
+    'type'        => 'checkbox',
   },
 
   {
@@ -1125,7 +1476,12 @@ worry that config_items is freeside-specific and icky.
     'editlist_parts' => [ { type=>'text' },
                           { type=>'immutable', value=>'IN' },
                           { type=>'select',
-                            select_enum=>{ map { $_=>$_ } qw(A CNAME MX NS TXT)} },
+                            select_enum => {
+                              map { $_=>$_ }
+                                  #@{ FS::domain_record->rectypes }
+                                  qw(A AAAA CNAME MX NS PTR SPF SRV TXT)
+                            },
+                          },
                           { type=> 'text' }, ],
   },
 
@@ -1178,7 +1534,20 @@ worry that config_items is freeside-specific and icky.
     'key'         => 'referraldefault',
     'section'     => 'UI',
     'description' => 'Default referral, specified by refnum',
-    'type'        => 'text',
+    'type'        => 'select-sub',
+    'options_sub' => sub { require FS::Record;
+                           require FS::part_referral;
+                           map { $_->refnum => $_->referral }
+                               FS::Record::qsearch( 'part_referral', 
+                                                   { 'disabled' => '' }
+                                                 );
+                        },
+    'option_sub'  => sub { require FS::Record;
+                           require FS::part_referral;
+                           my $part_referral = FS::Record::qsearchs(
+                            'part_referral', { 'refnum'=>shift } );
+                           $part_referral ? $part_referral->referral : '';
+                        },
   },
 
 #  {
@@ -1230,9 +1599,16 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'report-showpasswords',
+    'section'     => 'UI',
+    'description' => 'This is a terrible idea.  Do not enable it.  STRONGLY NOT RECOMMENDED.  Enables display of passwords on services reports.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'signupurl',
     'section'     => 'UI',
-    'description' => 'if you are using customer-to-customer referrals, and you enter the URL of your <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:1.7:Documentation:Self-Service_Installation">signup server CGI</a>, the customer view screen will display a customized link to the signup server with the appropriate customer as referral',
+    'description' => 'if you are using customer-to-customer referrals, and you enter the URL of your <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:2.1:Documentation:Self-Service_Installation">signup server CGI</a>, the customer view screen will display a customized link to the signup server with the appropriate customer as referral',
     'type'        => 'text',
   },
 
@@ -1244,6 +1620,32 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'smtp-username',
+    'section'     => '',
+    'description' => 'Optional SMTP username for Freeside\'s outgoing mail',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'smtp-password',
+    'section'     => '',
+    'description' => 'Optional SMTP password for Freeside\'s outgoing mail',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'smtp-encryption',
+    'section'     => '',
+    'description' => 'Optional SMTP encryption method.  The STARTTLS methods require smtp-username and smtp-password to be set.',
+    'type'        => 'select',
+    'select_hash' => [ '25'           => 'None (port 25)',
+                       '25-starttls'  => 'STARTTLS (port 25)',
+                       '587-starttls' => 'STARTTLS / submission (port 587)',
+                       '465-tls'      => 'SMTPS (SSL) (port 465)',
+                     ],
+  },
+
+  {
     'key'         => 'soadefaultttl',
     'section'     => 'BIND',
     'description' => 'SOA default TTL for new domains.',
@@ -1384,6 +1786,20 @@ worry that config_items is freeside-specific and icky.
     'type'        => 'checkbox',
   },
 
+  { 
+    'key'         => 'username-slash',
+    'section'     => 'username',
+    'description' => 'Allow the slash character (/) in usernames.  When using, make sure to set "Home directory" to fixed and blank in all svc_acct service definitions.',
+    'type'        => 'checkbox',
+  },
+
+  { 
+    'key'         => 'username-equals',
+    'section'     => 'username',
+    'description' => 'Allow the equal sign character (=) in usernames.',
+    'type'        => 'checkbox',
+  },
+
   {
     'key'         => 'safe-part_bill_event',
     'section'     => 'UI',
@@ -1450,41 +1866,55 @@ worry that config_items is freeside-specific and icky.
   {
     'key'         => 'locale',
     'section'     => 'UI',
-    'description' => 'Message locale',
+    'description' => 'Default locale',
     'type'        => 'select',
-    'select_enum' => [ qw(en_US) ],
+    'options_sub' => sub {
+      map { $_ => FS::Locales->description($_) } FS::Locales->locales;
+    },
+    'option_sub'  => sub {
+      FS::Locales->description(shift)
+    },
   },
 
   {
     'key'         => 'signup_server-payby',
-    'section'     => '',
+    'section'     => 'self-service',
     'description' => 'Acceptable payment types for the signup server',
     'type'        => 'selectmultiple',
     'select_enum' => [ qw(CARD DCRD CHEK DCHK LECB PREPAY BILL COMP) ],
   },
 
   {
-    'key'         => 'signup_server-default_agentnum',
-    'section'     => '',
-    'description' => 'Default agent for the signup server',
-    'type'        => 'select-sub',
-    'options_sub' => sub { require FS::Record;
-                           require FS::agent;
-                          map { $_->agentnum => $_->agent }
-                               FS::Record::qsearch('agent', { disabled=>'' } );
-                        },
-    'option_sub'  => sub { require FS::Record;
-                           require FS::agent;
-                          my $agent = FS::Record::qsearchs(
-                            'agent', { 'agentnum'=>shift }
-                          );
-                           $agent ? $agent->agent : '';
-                        },
+    'key'         => 'selfservice-payment_gateway',
+    'section'     => 'self-service',
+    'description' => 'Force the use of this payment gateway for self-service.',
+    %payment_gateway_options,
+  },
+
+  {
+    'key'         => 'selfservice-save_unchecked',
+    'section'     => 'self-service',
+    'description' => 'In self-service, uncheck "Remember information" checkboxes by default (normally, they are checked by default).',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'default_agentnum',
+    'section'     => 'UI',
+    'description' => 'Default agent for the backoffice',
+    'type'        => 'select-agent',
+  },
+
+  {
+    'key'         => 'signup_server-default_agentnum',
+    'section'     => 'self-service',
+    'description' => 'Default agent for the signup server',
+    'type'        => 'select-agent',
   },
 
   {
     'key'         => 'signup_server-default_refnum',
-    'section'     => '',
+    'section'     => 'self-service',
     'description' => 'Default advertising source for the signup server',
     'type'        => 'select-sub',
     'options_sub' => sub { require FS::Record;
@@ -1504,21 +1934,21 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'signup_server-default_pkgpart',
-    'section'     => '',
+    'section'     => 'self-service',
     'description' => 'Default package for the signup server',
     'type'        => 'select-part_pkg',
   },
 
   {
     'key'         => 'signup_server-default_svcpart',
-    'section'     => '',
+    'section'     => 'self-service',
     'description' => 'Default service definition for the signup server - only necessary for services that trigger special provisioning widgets (such as DID provisioning).',
     'type'        => 'select-part_svc',
   },
 
   {
     'key'         => 'signup_server-mac_addr_svcparts',
-    'section'     => '',
+    'section'     => 'self-service',
     'description' => 'Service definitions which can receive mac addresses (current mapped to username for svc_acct).',
     'type'        => 'select-part_svc',
     'multiple'    => 1,
@@ -1526,25 +1956,33 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'signup_server-nomadix',
-    'section'     => '',
+    'section'     => 'self-service',
     'description' => 'Signup page Nomadix integration',
     'type'        => 'checkbox',
   },
 
   {
     'key'         => 'signup_server-service',
-    'section'     => '',
+    'section'     => 'self-service',
     'description' => 'Service for the signup server - "Account (svc_acct)" is the default setting, or "Phone number (svc_phone)" for ITSP signup',
     'type'        => 'select',
     'select_hash' => [
                        'svc_acct'  => 'Account (svc_acct)',
                        'svc_phone' => 'Phone number (svc_phone)',
+                       'svc_pbx'   => 'PBX (svc_pbx)',
                      ],
   },
+  
+  {
+    'key'         => 'signup_server-prepaid-template-custnum',
+    'section'     => 'self-service',
+    'description' => 'When the signup server is used with prepaid cards and customer info is not required for signup, the contact/address info will be copied from this customer, if specified',
+    'type'        => 'text',
+  },
 
   {
     'key'         => 'selfservice_server-base_url',
-    'section'     => '',
+    'section'     => 'self-service',
     'description' => 'Base URL for the self-service web interface - necessary for some widgets to find their way, including retrieval of non-US state information and phone number provisioning.',
     'type'        => 'text',
   },
@@ -1558,71 +1996,103 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'signup_server-realtime',
-    'section'     => '',
+    'section'     => 'self-service',
     'description' => 'Run billing for signup server signups immediately, and do not provision accounts which subsequently have a balance.',
     'type'        => 'checkbox',
   },
+
   {
     'key'         => 'signup_server-classnum2',
-    'section'     => '',
+    'section'     => 'self-service',
     'description' => 'Package Class for first optional purchase',
     'type'        => 'select-pkg_class',
   },
 
   {
     'key'         => 'signup_server-classnum3',
-    'section'     => '',
+    'section'     => 'self-service',
     'description' => 'Package Class for second optional purchase',
     'type'        => 'select-pkg_class',
   },
 
   {
+    'key'         => 'signup_server-third_party_as_card',
+    'section'     => 'self-service',
+    'description' => 'Allow customer payment type to be set to CARD even when using third-party credit card billing.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'selfservice-xmlrpc',
+    'section'     => 'self-service',
+    'description' => 'Run a standalone self-service XML-RPC server on the backend (on port 8080).',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'backend-realtime',
-    'section'     => '',
+    'section'     => 'billing',
     'description' => 'Run billing for backend signups immediately.',
     'type'        => 'checkbox',
   },
 
   {
+    'key'         => 'decline_msgnum',
+    'section'     => 'notification',
+    'description' => 'Template to use for credit card and electronic check decline messages.',
+    %msg_template_options,
+  },
+
+  {
     'key'         => 'declinetemplate',
-    'section'     => 'billing',
+    'section'     => 'deprecated',
     'description' => 'Template file for credit card and electronic check decline emails.',
     'type'        => 'textarea',
   },
 
   {
     'key'         => 'emaildecline',
-    'section'     => 'billing',
+    'section'     => 'notification',
     'description' => 'Enable emailing of credit card and electronic check decline notices.',
     'type'        => 'checkbox',
+    'per_agent'   => 1,
   },
 
   {
     'key'         => 'emaildecline-exclude',
-    'section'     => 'billing',
+    'section'     => 'notification',
     'description' => 'List of error messages that should not trigger email decline notices, one per line.',
     'type'        => 'textarea',
+    'per_agent'   => 1,
+  },
+
+  {
+    'key'         => 'cancel_msgnum',
+    'section'     => 'notification',
+    'description' => 'Template to use for cancellation emails.',
+    %msg_template_options,
   },
 
   {
     'key'         => 'cancelmessage',
-    'section'     => 'billing',
+    'section'     => 'deprecated',
     'description' => 'Template file for cancellation emails.',
     'type'        => 'textarea',
   },
 
   {
     'key'         => 'cancelsubject',
-    'section'     => 'billing',
+    'section'     => 'deprecated',
     'description' => 'Subject line for cancellation emails.',
     'type'        => 'text',
   },
 
   {
     'key'         => 'emailcancel',
-    'section'     => 'billing',
-    'description' => 'Enable emailing of cancellation notices.  Make sure to fill in the cancelmessage and cancelsubject configuration values as well.',
+    'section'     => 'notification',
+    'description' => 'Enable emailing of cancellation notices.  Make sure to select the template in the cancel_msgnum option.',
     'type'        => 'checkbox',
+    'per_agent'   => 1,
   },
 
   {
@@ -1663,8 +2133,8 @@ worry that config_items is freeside-specific and icky.
   {
     'key'         => 'taxdatadirectdownload',
     'section'     => 'billing',  #well
-    'description' => 'Enable downloading tax data directly from the vendor site',
-    'type'        => 'checkbox',
+    'description' => 'Enable downloading tax data directly from the vendor site. at least three lines: URL, username, and password.j',
+    'type'        => 'textarea',
   },
 
   {
@@ -1675,16 +2145,31 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'welcome_msgnum',
+    'section'     => 'notification',
+    'description' => 'Template to use for welcome messages when a svc_acct record is created.',
+    %msg_template_options,
+  },
+  
+  {
+    'key'         => 'svc_acct_welcome_exclude',
+    'section'     => 'notification',
+    'description' => 'A list of svc_acct services for which no welcome email is to be sent.',
+    'type'        => 'select-part_svc',
+    'multiple'    => 1,
+  },
+
+  {
     'key'         => 'welcome_email',
-    '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/dist/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>',
+    'section'     => 'deprecated',
+    '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.',
     'type'        => 'textarea',
     'per_agent'   => 1,
   },
 
   {
     'key'         => 'welcome_email-from',
-    'section'     => '',
+    'section'     => 'deprecated',
     'description' => 'From: address header for welcome email',
     'type'        => 'text',
     'per_agent'   => 1,
@@ -1692,7 +2177,7 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'welcome_email-subject',
-    'section'     => '',
+    'section'     => 'deprecated',
     'description' => 'Subject: header for welcome email',
     'type'        => 'text',
     'per_agent'   => 1,
@@ -1700,7 +2185,7 @@ worry that config_items is freeside-specific and icky.
   
   {
     'key'         => 'welcome_email-mimetype',
-    'section'     => '',
+    'section'     => 'deprecated',
     'description' => 'MIME type for welcome email',
     'type'        => 'select',
     'select_enum' => [ 'text/plain', 'text/html' ],
@@ -1714,37 +2199,44 @@ worry that config_items is freeside-specific and icky.
     'type'        => 'textarea',
   },
 
+#  {
+#    'key'         => 'warning_msgnum',
+#    'section'     => 'notification',
+#    'description' => 'Template to use for warning messages, sent to the customer email invoice destination(s) when a svc_acct record has its usage drop below a threshold.',
+#    %msg_template_options,
+#  },
+
   {
     'key'         => 'warning_email',
-    'section'     => '',
+    'section'     => 'notification',
     'description' => 'Template file for warning email.  Warning emails are sent to the customer email invoice destination(s) each time a svc_acct record has its usage drop below a threshold or 0.  See the <a href="http://search.cpan.org/dist/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> <li><code>$column</code> <li><code>$amount</code> <li><code>$threshold</code></ul>',
     'type'        => 'textarea',
   },
 
   {
     'key'         => 'warning_email-from',
-    'section'     => '',
+    'section'     => 'notification',
     'description' => 'From: address header for warning email',
     'type'        => 'text',
   },
 
   {
     'key'         => 'warning_email-cc',
-    'section'     => '',
+    'section'     => 'notification',
     'description' => 'Additional recipient(s) (comma separated) for warning email when remaining usage reaches zero.',
     'type'        => 'text',
   },
 
   {
     'key'         => 'warning_email-subject',
-    'section'     => '',
+    'section'     => 'notification',
     'description' => 'Subject: header for warning email',
     'type'        => 'text',
   },
   
   {
     'key'         => 'warning_email-mimetype',
-    'section'     => '',
+    'section'     => 'notification',
     'description' => 'MIME type for warning email',
     'type'        => 'select',
     'select_enum' => [ 'text/plain', 'text/html' ],
@@ -1775,7 +2267,7 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'svc_acct-notes',
-    'section'     => 'UI',
+    'section'     => 'deprecated',
     'description' => 'Extra HTML to be displayed on the Account View screen.',
     'type'        => 'textarea',
   },
@@ -1785,7 +2277,7 @@ worry that config_items is freeside-specific and icky.
     'section'     => '',
     'description' => 'RADIUS attribute for plain-text passwords.',
     'type'        => 'select',
-    'select_enum' => [ 'Password', 'User-Password' ],
+    'select_enum' => [ 'Password', 'User-Password', 'Cleartext-Password' ],
   },
 
   {
@@ -1805,6 +2297,13 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'svc_broadband-radius',
+    'section'     => '',
+    'description' => 'Enable RADIUS groups for broadband services.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'svc_acct-alldomains',
     'section'     => '',
     'description' => 'Allow accounts to select any domain in the database.  Normally accounts can only select from the domain set in the service definition and those purchased by the customer.',
@@ -1812,9 +2311,16 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'dump-localdest',
+    'section'     => '',
+    'description' => 'Destination for local database dumps (full path)',
+    'type'        => 'text',
+  },
+
+  {
     'key'         => 'dump-scpdest',
     'section'     => '',
-    'description' => 'destination for scp database dumps: user@host:/path',
+    'description' => 'Destination for scp database dumps: user@host:/path',
     'type'        => 'text',
   },
 
@@ -1913,7 +2419,7 @@ worry that config_items is freeside-specific and icky.
   {
     'key'         => 'cust_pkg-change_pkgpart-bill_now',
     'section'     => '',
-    'description' => "When changing packages, bill the new package immediately.  Useful for prepaid situations with RADIUS where an Expiration attribute base don the package must be present at all times.",
+    'description' => "When changing packages, bill the new package immediately.  Useful for prepaid situations with RADIUS where an Expiration attribute baseon the package must be present at all times.",
     'type'        => 'checkbox',
   },
 
@@ -1941,26 +2447,138 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'selfservice_server-primary_only',
-    'section'     => '',
+    'section'     => 'self-service',
     'description' => 'Only allow primary accounts to access self-service functionality.',
     'type'        => 'checkbox',
   },
 
   {
     'key'         => 'selfservice_server-phone_login',
-    'section'     => '',
+    'section'     => 'self-service',
     'description' => 'Allow login to self-service with phone number and PIN.',
     'type'        => 'checkbox',
   },
 
   {
     'key'         => 'selfservice_server-single_domain',
-    'section'     => '',
+    'section'     => 'self-service',
     'description' => 'If specified, only use this one domain for self-service access.',
     'type'        => 'text',
   },
 
   {
+    'key'         => 'selfservice_server-login_svcpart',
+    'section'     => 'self-service',
+    'description' => 'If specified, only allow the specified svcparts to login to self-service.',
+    'type'        => 'select-part_svc',
+    'multiple'    => 1,
+  },
+
+  {
+    'key'         => 'selfservice-svc_forward_svcpart',
+    'section'     => 'self-service',
+    'description' => 'Service for self-service forward editing.',
+    'type'        => 'select-part_svc',
+  },
+
+  {
+    'key'         => 'selfservice-password_reset_verification',
+    'section'     => 'self-service',
+    'description' => 'If enabled, specifies the type of verification required for self-service password resets.',
+    'type'        => 'select',
+    'select_hash' => [ '' => 'Password reset disabled',
+                       'paymask,amount,zip' => 'Verify with credit card (or bank account) last 4 digits, payment amount and zip code',
+                     ],
+  },
+
+  {
+    'key'         => 'selfservice-password_reset_msgnum',
+    'section'     => 'self-service',
+    'description' => 'Template to use for password reset emails.',
+    %msg_template_options,
+  },
+
+  {
+    'key'         => 'selfservice-hide_invoices-taxclass',
+    'section'     => 'self-service',
+    'description' => 'Hide invoices with only this package tax class from self-service and supress sending (emailing, printing, faxing) them.  Typically set to something like "Previous balance" and used when importing legacy invoices into legacy_cust_bill.',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'selfservice-recent-did-age',
+    'section'     => 'self-service',
+    'description' => 'If specified, defines "recent", in number of seconds, for "Download recently allocated DIDs" in self-service.',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'selfservice_server-view-wholesale',
+    'section'     => 'self-service',
+    'description' => 'If enabled, use a wholesale package view in the self-service.',
+    'type'        => 'checkbox',
+  },
+  
+  {
+    'key'         => 'selfservice-agent_signup',
+    'section'     => 'self-service',
+    'description' => 'Allow agent signup via self-service.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'selfservice-agent_signup-agent_type',
+    'section'     => 'self-service',
+    'description' => 'Agent type when allowing agent signup via self-service.',
+    'type'        => 'select-sub',
+    'options_sub' => sub { require FS::Record;
+                           require FS::agent_type;
+                          map { $_->typenum => $_->atype }
+                               FS::Record::qsearch('agent_type', {} ); # disabled=>'' } );
+                        },
+    'option_sub'  => sub { require FS::Record;
+                           require FS::agent_type;
+                          my $agent = FS::Record::qsearchs(
+                            'agent_type', { 'typenum'=>shift }
+                          );
+                           $agent_type ? $agent_type->atype : '';
+                        },
+  },
+
+  {
+    'key'         => 'selfservice-agent_login',
+    'section'     => 'self-service',
+    'description' => 'Allow agent login via self-service.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'selfservice-self_suspend_reason',
+    'section'     => 'self-service',
+    'description' => 'Suspend reason when customers suspend their own packages. Set to nothing to disallow self-suspension.',
+    'type'        => 'select-sub',
+    'options_sub' => sub { require FS::Record;
+                           require FS::reason;
+                           my $type = qsearchs('reason_type', 
+                             { class => 'S' }) 
+                              or return ();
+                          map { $_->reasonnum => $_->reason }
+                               FS::Record::qsearch('reason', 
+                                 { reason_type => $type->typenum } 
+                               );
+                        },
+    'option_sub'  => sub { require FS::Record;
+                           require FS::reason;
+                          my $reason = FS::Record::qsearchs(
+                            'reason', { 'reasonnum' => shift }
+                          );
+                           $reason ? $reason->reason : '';
+                        },
+
+    'per_agent'   => 1,
+  },
+
+  {
     'key'         => 'card_refund-days',
     'section'     => 'billing',
     'description' => 'After a payment, the number of days a refund link will be available for that payment.  Defaults to 120.',
@@ -1991,6 +2609,22 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'global_unique-pbx_title',
+    'section'     => '',
+    'description' => 'Global phone number uniqueness control: none (check uniqueness per exports), enabled (check across all services), or disabled (no duplicate checking).',
+    'type'        => 'select',
+    'select_enum' => [ 'enabled', 'disabled' ],
+  },
+
+  {
+    'key'         => 'global_unique-pbx_id',
+    'section'     => '',
+    'description' => 'Global PBX id uniqueness control: none (check uniqueness per exports), enabled (check across all services), or disabled (no duplicate checking).',
+    'type'        => 'select',
+    'select_enum' => [ 'enabled', 'disabled' ],
+  },
+
+  {
     'key'         => 'svc_external-skip_manual',
     'section'     => 'UI',
     'description' => 'When provisioning svc_external services, skip manual entry of id and title fields in the UI.  Usually used in conjunction with an export that populates these fields (i.e. artera_turbo).',
@@ -2007,16 +2641,39 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'ticket_system',
-    'section'     => '',
-    'description' => 'Ticketing system integration.  <b>RT_Internal</b> uses the built-in RT ticketing system (see the <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:1.7:Documentation:RT_Installation">integrated ticketing installation instructions</a>).   <b>RT_External</b> accesses an external RT installation in a separate database (local or remote).',
+    'section'     => 'ticketing',
+    'description' => 'Ticketing system integration.  <b>RT_Internal</b> uses the built-in RT ticketing system (see the <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:2.1:Documentation:RT_Installation">integrated ticketing installation instructions</a>).   <b>RT_External</b> accesses an external RT installation in a separate database (local or remote).',
     'type'        => 'select',
     #'select_enum' => [ '', qw(RT_Internal RT_Libs RT_External) ],
     'select_enum' => [ '', qw(RT_Internal RT_External) ],
   },
 
   {
+    'key'         => 'network_monitoring_system',
+    'section'     => 'network_monitoring',
+    'description' => 'Networking monitoring system (NMS) integration.  <b>Torrus_Internal</b> uses the built-in Torrus ticketing system (see the <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:2.1:Documentation:Torrus_Installation">integrated networking monitoring system installation instructions</a>).',
+    'type'        => 'select',
+    'select_enum' => [ '', qw(Torrus_Internal) ],
+  },
+
+  {
+    'key'         => 'nms-auto_add-svc_ips',
+    'section'     => 'network_monitoring',
+    'description' => 'Automatically add (and remove) IP addresses from these service tables to the network monitoring system.',
+    'type'        => 'selectmultiple',
+    'select_enum' => [ 'svc_acct', 'svc_broadband', 'svc_dsl' ],
+  },
+
+  {
+    'key'         => 'nms-auto_add-community',
+    'section'     => 'network_monitoring',
+    'description' => 'SNMP community string to use when automatically adding IP addresses from these services to the network monitoring system.',
+    'type'        => 'text',
+  },
+
+  {
     'key'         => 'ticket_system-default_queueid',
-    'section'     => '',
+    'section'     => 'ticketing',
     'description' => 'Default queue used when creating new customer tickets.',
     'type'        => 'select-sub',
     'options_sub' => sub {
@@ -2040,38 +2697,99 @@ worry that config_items is freeside-specific and icky.
                            }
                          },
   },
+  {
+    'key'         => 'ticket_system-force_default_queueid',
+    'section'     => 'ticketing',
+    'description' => 'Disallow queue selection when creating new tickets from customer view.',
+    'type'        => 'checkbox',
+  },
+  {
+    'key'         => 'ticket_system-selfservice_queueid',
+    'section'     => 'ticketing',
+    'description' => 'Queue used when creating new customer tickets from self-service.  Defautls to ticket_system-default_queueid if not specified.',
+    #false laziness w/above
+    'type'        => 'select-sub',
+    'options_sub' => sub {
+                           my $conf = new FS::Conf;
+                           if ( $conf->config('ticket_system') ) {
+                             eval "use FS::TicketSystem;";
+                             die $@ if $@;
+                             FS::TicketSystem->queues();
+                           } else {
+                             ();
+                           }
+                         },
+    'option_sub'  => sub { 
+                           my $conf = new FS::Conf;
+                           if ( $conf->config('ticket_system') ) {
+                             eval "use FS::TicketSystem;";
+                             die $@ if $@;
+                             FS::TicketSystem->queue(shift);
+                           } else {
+                             '';
+                           }
+                         },
+  },
+
+  {
+    'key'         => 'ticket_system-requestor',
+    'section'     => 'ticketing',
+    'description' => 'Email address to use as the requestor for new tickets.  If blank, the customer\'s invoicing address(es) will be used.',
+    'type'        => 'text',
+  },
 
   {
     'key'         => 'ticket_system-priority_reverse',
-    'section'     => '',
+    'section'     => 'ticketing',
     'description' => 'Enable this to consider lower numbered priorities more important.  A bad habit we picked up somewhere.  You probably want to avoid it and use the default.',
     'type'        => 'checkbox',
   },
 
   {
     'key'         => 'ticket_system-custom_priority_field',
-    'section'     => '',
+    'section'     => 'ticketing',
     'description' => 'Custom field from the ticketing system to use as a custom priority classification.',
     'type'        => 'text',
   },
 
   {
     'key'         => 'ticket_system-custom_priority_field-values',
-    'section'     => '',
+    'section'     => 'ticketing',
     'description' => 'Values for the custom field from the ticketing system to break down and sort customer ticket lists.',
     'type'        => 'textarea',
   },
 
   {
     'key'         => 'ticket_system-custom_priority_field_queue',
-    'section'     => '',
+    'section'     => 'ticketing',
     'description' => 'Ticketing system queue in which the custom field specified in ticket_system-custom_priority_field is located.',
     'type'        => 'text',
   },
 
   {
+    'key'         => 'ticket_system-selfservice_priority_field',
+    'section'     => 'ticketing',
+    'description' => 'Custom field from the ticket system to use as a customer-managed priority field.',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'ticket_system-selfservice_edit_subject',
+    'section'     => 'ticketing',
+    'description' => 'Allow customers to edit ticket subjects through selfservice.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'ticket_system-escalation',
+    'section'     => 'ticketing',
+    'description' => 'Enable priority escalation of tickets as part of daily batch processing.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'ticket_system-rt_external_datasrc',
-    'section'     => '',
+    'section'     => 'ticketing',
     'description' => 'With external RT integration, the DBI data source for the external RT installation, for example, <code>DBI:Pg:user=rt_user;password=rt_word;host=rt.example.com;dbname=rt</code>',
     'type'        => 'text',
 
@@ -2079,7 +2797,7 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'ticket_system-rt_external_url',
-    'section'     => '',
+    'section'     => 'ticketing',
     'description' => 'With external RT integration, the URL for the external RT installation, for example, <code>https://rt.example.com/rt</code>',
     'type'        => 'text',
   },
@@ -2101,6 +2819,14 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'company_phonenum',
+    'section'     => 'notification',
+    'description' => 'Your company phone number',
+    'type'        => 'text',
+    'per_agent'   => 1,
+  },
+
+  {
     'key'         => 'echeck-void',
     'section'     => 'deprecated',
     'description' => '<B>DEPRECATED</B>, now controlled by ACLs.  Used to enable local-only voiding of echeck payments in addition to refunds against the payment gateway',
@@ -2124,7 +2850,7 @@ worry that config_items is freeside-specific and icky.
   {
     'key'         => 'address1-search',
     'section'     => 'UI',
-    'description' => 'Enable the ability to search the address1 field from customer search.',
+    'description' => 'Enable the ability to search the address1 field from the quick customer search.  Not recommended in most cases as it tends to bring up too many search results - use explicit address searching from the advanced customer search instead.',
     'type'        => 'checkbox',
   },
 
@@ -2156,7 +2882,7 @@ worry that config_items is freeside-specific and icky.
   },
 
   { 'key'         => 'selfservice_server-cache_module',
-    'section'     => '',
+    'section'     => 'self-service',
     'description' => 'Module used to store self-service session information.  All modules handle any number of self-service servers.  Cache::SharedMemoryCache is appropriate for a single database / single Freeside server.  Cache::FileCache is useful for multiple databases on a single server, or when IPC::ShareLite is not available (i.e. FreeBSD).', #  _Database stores session information in the database and is appropriate for multiple Freeside servers, but may be slower.',
     'type'        => 'select',
     'select_enum' => [ 'Cache::SharedMemoryCache', 'Cache::FileCache', ], # '_Database' ],
@@ -2171,7 +2897,7 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'cust_bill-ftpformat',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Enable FTP of raw invoice data - format.',
     'type'        => 'select',
     'select_enum' => [ '', 'default', 'billco', ],
@@ -2179,35 +2905,35 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'cust_bill-ftpserver',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Enable FTP of raw invoice data - server.',
     'type'        => 'text',
   },
 
   {
     'key'         => 'cust_bill-ftpusername',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Enable FTP of raw invoice data - server.',
     'type'        => 'text',
   },
 
   {
     'key'         => 'cust_bill-ftppassword',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Enable FTP of raw invoice data - server.',
     'type'        => 'text',
   },
 
   {
     'key'         => 'cust_bill-ftpdir',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Enable FTP of raw invoice data - server.',
     'type'        => 'text',
   },
 
   {
     'key'         => 'cust_bill-spoolformat',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Enable spooling of raw invoice data - format.',
     'type'        => 'select',
     'select_enum' => [ '', 'default', 'billco', ],
@@ -2215,7 +2941,7 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'cust_bill-spoolagent',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Enable per-agent spooling of raw invoice data.',
     'type'        => 'checkbox',
   },
@@ -2242,17 +2968,38 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
-    'key'         => 'cust-fields',
-    'section'     => 'UI',
-    'description' => 'Which customer fields to display on reports by default',
-    'type'        => 'select',
-    'select_hash' => [ FS::ConfDefaults->cust_fields_avail() ],
-  },
-
-  {
-    'key'         => 'cust_pkg-display_times',
-    'section'     => 'UI',
-    'description' => 'Display full timestamps (not just dates) for customer packages.  Useful if you are doing real-time things like hourly prepaid.',
+    'key'         => 'overlimit_groups',
+    'section'     => '',
+    'description' => 'RADIUS group(s) to assign to svc_acct which has exceeded its bandwidth or time limit.',
+    'type'        => 'select-sub',
+    'per_agent'   => 1,
+    'multiple'    => 1,
+    'options_sub' => sub { require FS::Record;
+                           require FS::radius_group;
+                          map { $_->groupnum => $_->long_description }
+                               FS::Record::qsearch('radius_group', {} );
+                        },
+    'option_sub'  => sub { require FS::Record;
+                           require FS::radius_group;
+                          my $radius_group = FS::Record::qsearchs(
+                            'radius_group', { 'groupnum' => shift }
+                          );
+               $radius_group ? $radius_group->long_description : '';
+                        },
+  },
+
+  {
+    'key'         => 'cust-fields',
+    'section'     => 'UI',
+    'description' => 'Which customer fields to display on reports by default',
+    'type'        => 'select',
+    'select_hash' => [ FS::ConfDefaults->cust_fields_avail() ],
+  },
+
+  {
+    'key'         => 'cust_pkg-display_times',
+    'section'     => 'UI',
+    'description' => 'Display full timestamps (not just dates) for customer packages.  Useful if you are doing real-time things like hourly prepaid.',
     'type'        => 'checkbox',
   },
 
@@ -2264,6 +3011,27 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'cust_pkg-group_by_location',
+    'section'     => 'UI',
+    'description' => "Group packages by location.",
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'cust_pkg-show_fcc_voice_grade_equivalent',
+    'section'     => 'UI',
+    'description' => "Show a field on package definitions for assigning a DS0 equivalency number suitable for use on FCC form 477.",
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'cust_pkg-large_pkg_size',
+    'section'     => 'UI',
+    'description' => "In customer view, summarize packages with more than this many services.  Set to zero to never summarize packages.",
+    'type'        => 'text',
+  },
+
+  {
     'key'         => 'svc_acct-edit_uid',
     'section'     => 'shell',
     'description' => 'Allow UID editing.',
@@ -2278,6 +3046,13 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'svc_acct-no_edit_username',
+    'section'     => 'shell',
+    'description' => 'Disallow username editing.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'zone-underscore',
     'section'     => 'BIND',
     'description' => 'Allow underscores in zone names.  As underscores are illegal characters in zone names, this option is not recommended.',
@@ -2292,34 +3067,55 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'voip-cust_accountcode_cdr',
+    'section'     => 'telephony',
+    'description' => 'Enable the per-customer option for CDR breakdown by accountcode.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'voip-cust_cdr_spools',
-    'section'     => '',
+    'section'     => 'telephony',
     'description' => 'Enable the per-customer option for individual CDR spools.',
     'type'        => 'checkbox',
   },
 
   {
     'key'         => 'voip-cust_cdr_squelch',
-    'section'     => '',
+    'section'     => 'telephony',
     'description' => 'Enable the per-customer option for not printing CDR on invoices.',
     'type'        => 'checkbox',
   },
 
   {
     'key'         => 'voip-cdr_email',
-    'section'     => '',
-    'description' => 'Include the call details on emailed invoices even if the customer is configured for not printing them on the invoices.',
+    'section'     => 'telephony',
+    'description' => 'Include the call details on emailed invoices (and HTML invoices viewed in the backend), even if the customer is configured for not printing them on the invoices.',
     'type'        => 'checkbox',
   },
 
   {
     'key'         => 'voip-cust_email_csv_cdr',
-    'section'     => '',
+    'section'     => 'telephony',
     'description' => 'Enable the per-customer option for including CDR information as a CSV attachment on emailed invoices.',
     'type'        => 'checkbox',
   },
 
   {
+    'key'         => 'cgp_rule-domain_templates',
+    'section'     => '',
+    'description' => 'Communigate Pro rule templates for domains, one per line, "svcnum Name"',
+    'type'        => 'textarea',
+  },
+
+  {
+    'key'         => 'svc_forward-no_srcsvc',
+    'section'     => '',
+    'description' => "Don't allow forwards from existing accounts, only arbitrary addresses.  Useful when exporting to systems such as Communigate Pro which treat forwards in this fashion.",
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'svc_forward-arbitrary_dst',
     'section'     => '',
     'description' => "Allow forwards to point to arbitrary strings that don't necessarily look like email addresses.  Only used when using forwards for weird, non-email things.",
@@ -2336,34 +3132,34 @@ worry that config_items is freeside-specific and icky.
   {
     'key'         => 'tax-pkg_address',
     'section'     => 'billing',
-    'description' => 'By default, tax calculations are done based on the billing address.  Enable this switch to calculate tax based on the package address instead (when present).  Note that this option is currently incompatible with vendor data taxation enabled by enable_taxproducts.',
+    'description' => 'By default, tax calculations are done based on the billing address.  Enable this switch to calculate tax based on the package address instead (when present).',
     'type'        => 'checkbox',
   },
 
   {
     'key'         => 'invoice-ship_address',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Include the shipping address on invoices.',
     'type'        => 'checkbox',
   },
 
   {
     'key'         => 'invoice-unitprice',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Enable unit pricing on invoices.',
     'type'        => 'checkbox',
   },
 
   {
     'key'         => 'invoice-smallernotes',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Display the notes section in a smaller font on invoices.',
     'type'        => 'checkbox',
   },
 
   {
     'key'         => 'invoice-smallerfooter',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Display footers in a smaller font on invoices.',
     'type'        => 'checkbox',
   },
@@ -2373,6 +3169,7 @@ worry that config_items is freeside-specific and icky.
     'section'     => 'billing',
     'description' => 'This allows selection of a package to insert on invoices for customers with postal invoices selected.',
     'type'        => 'select-part_pkg',
+    'per_agent'   => 1,
   },
 
   {
@@ -2433,7 +3230,8 @@ worry that config_items is freeside-specific and icky.
     'description' => 'Fixed (unchangeable) format for electronic check batches.',
     'type'        => 'select',
     'select_enum' => [ 'csv-td_canada_trust-merchant_pc_batch', 'BoM', 'PAP',
-                       'paymentech', 'ach-spiritone', 'RBC'
+                       'paymentech', 'ach-spiritone', 'RBC', 'td_eft1464',
+                       'eft_canada'
                      ]
   },
 
@@ -2480,6 +3278,35 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'batchconfig-td_eft1464',
+    'section'     => 'billing',
+    'description' => 'Configuration for TD Bank EFT1464 batching, seven lines: 1. Originator ID, 2. Datacenter Code, 3. Short name, 4. Long name, 5. Returned payment branch number, 6. Returned payment account, 7. Transaction code.',
+    'type'        => 'textarea',
+  },
+
+  {
+    'key'         => 'batch-manual_approval',
+    'section'     => 'billing',
+    'description' => 'Allow manual batch closure, which will approve all payments that do not yet have a status.  This is not advised, but is needed for payment processors that provide a report of rejected rather than approved payments.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'batchconfig-eft_canada',
+    'section'     => 'billing',
+    'description' => 'Configuration for EFT Canada batching, four lines: 1. SFTP username, 2. SFTP password, 3. Transaction code, 4. Number of days to delay process date.',
+    'type'        => 'textarea',
+    'per_agent'   => 1,
+  },
+
+  {
+    'key'         => 'batch-spoolagent',
+    'section'     => 'billing',
+    'description' => 'Store payment batches per-agent.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'payment_history-years',
     'section'     => 'UI',
     'description' => 'Number of years of payment history to show by default.  Currently defaults to 2.',
@@ -2558,6 +3385,13 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'cust_main-edit_calling_list_exempt',
+    'section'     => 'UI',
+    'description' => 'Display the "calling_list_exempt" checkbox on customer edit.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'support-key',
     'section'     => '',
     'description' => 'A support key enables access to commercial services delivered over the network, such as the payroll module, access to the internal ticket system, priority support and optional backups.',
@@ -2607,8 +3441,15 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'impending_recur_msgnum',
+    'section'     => 'notification',
+    'description' => 'Template to use for alerts about first-time recurring billing.',
+    %msg_template_options,
+  },
+
+  {
     'key'         => 'impending_recur_template',
-    'section'     => 'billing',
+    'section'     => 'deprecated',
     'description' => 'Template file for alerts about looming first time recurrant billing.  See the <a href="http://search.cpan.org/dist/Text-Template/lib/Text/Template.pm">Text::Template</a> documentation for details on the template substitition language.  Also see packages with a <a href="../browse/part_pkg.cgi">flat price plan</a>  The following variables are available<ul><li><code>$packages</code> allowing <code>$packages->[0]</code> thru <code>$packages->[n]</code> <li><code>$package</code> the first package, same as <code>$packages->[0]</code> <li><code>$recurdates</code> allowing <code>$recurdates->[0]</code> thru <code>$recurdates->[n]</code> <li><code>$recurdate</code> the first recurdate, same as <code>$recurdate->[0]</code> <li><code>$first</code> <li><code>$last</code></ul>',
 # <li><code>$payby</code> <li><code>$expdate</code> most likely only confuse
     'type'        => 'textarea',
@@ -2616,31 +3457,33 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'logo.png',
-    'section'     => 'billing',  #? 
+    'section'     => 'UI',  #'invoicing' ?
     'description' => 'Company logo for HTML invoices and the backoffice interface, in PNG format.  Suggested size somewhere near 92x62.',
     'type'        => 'image',
     'per_agent'   => 1, #XXX just view/logo.cgi, which is for the global
                         #old-style editor anyway...?
+    'per_locale'  => 1,
   },
 
   {
     'key'         => 'logo.eps',
-    'section'     => 'billing',  #? 
+    'section'     => 'invoicing',
     'description' => 'Company logo for printed and PDF invoices, in EPS format.',
     'type'        => 'image',
     'per_agent'   => 1, #XXX as above, kinda
+    'per_locale'  => 1,
   },
 
   {
     'key'         => 'selfservice-ignore_quantity',
-    'section'     => '',
+    'section'     => 'self-service',
     'description' => 'Ignores service quantity restrictions in self-service context.  Strongly not recommended - just set your quantities correctly in the first place.',
     'type'        => 'checkbox',
   },
 
   {
     'key'         => 'selfservice-session_timeout',
-    'section'     => '',
+    'section'     => 'self-service',
     'description' => 'Self-service session timeout.  Defaults to 1 hour.',
     'type'        => 'select',
     'select_enum' => [ '1 hour', '2 hours', '4 hours', '8 hours', '1 day', '1 week', ],
@@ -2757,7 +3600,7 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'signup_credit_type',
-    'section'     => 'billing',
+    'section'     => 'billing', #self-service?
     'description' => 'The group to use for new, automatically generated credit reasons resulting from signup and self-service declines.',
     'type'        => 'select-sub',
     'options_sub' => sub { require FS::Record;
@@ -2775,13 +3618,34 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'prepayment_discounts-credit_type',
+    'section'     => 'billing',
+    'description' => 'Enables the offering of prepayment discounts and establishes the credit reason type.',
+    'type'        => 'select-sub',
+    'options_sub' => sub { require FS::Record;
+                           require FS::reason_type;
+                           map { $_->typenum => $_->type }
+                               FS::Record::qsearch('reason_type', { class=>'R' } );
+                         },
+    'option_sub'  => sub { require FS::Record;
+                           require FS::reason_type;
+                           my $reason_type = FS::Record::qsearchs(
+                             'reason_type', { 'typenum' => shift }
+                           );
+                           $reason_type ? $reason_type->type : '';
+                         },
+
+  },
+
+  {
     'key'         => 'cust_main-agent_custid-format',
     'section'     => '',
     'description' => 'Enables searching of various formatted values in cust_main.agent_custid',
     'type'        => 'select',
     'select_hash' => [
-                       ''      => 'Numeric only',
-                       'ww?d+' => 'Numeric with one or two letter prefix',
+                       ''       => 'Numeric only',
+                       '\d{7}'  => 'Numeric only, exactly 7 digits',
+                       'ww?d+'  => 'Numeric with one or two letter prefix',
                      ],
   },
 
@@ -2804,19 +3668,40 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'disable_previous_balance',
-    'section'     => 'billing',
-    'description' => 'Disable inclusion of previous balancem payment, and credit lines on invoices',
+    'section'     => 'invoicing',
+    'description' => 'Disable inclusion of previous balance, payment, and credit lines on invoices',
     'type'        => 'checkbox',
   },
 
   {
+    'key'         => 'previous_balance-exclude_from_total',
+    'section'     => 'invoicing',
+    'description' => 'Do not include previous balance in the \'Total\' line.  Only meaningful when invoice_sections is false.  Optionally provide text to override the Total New Charges description',
+    'type'        => [ qw(checkbox text) ],
+  },
+
+  {
     'key'         => 'previous_balance-summary_only',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Only show a single line summarizing the total previous balance rather than one line per invoice.',
     'type'        => 'checkbox',
   },
 
   {
+    'key'         => 'previous_balance-show_credit',
+    'section'     => 'invoicing',
+    'description' => 'Show the customer\'s credit balance on invoices when applicable.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'balance_due_below_line',
+    'section'     => 'invoicing',
+    'description' => 'Place the balance due message below a line.  Only meaningful when when invoice_sections is false.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'usps_webtools-userid',
     'section'     => 'UI',
     'description' => 'Production UserID for USPS web tools.   Enables USPS address standardization.  See the <a href="http://www.usps.com/webtools/">USPS website</a>, register and agree not to use the tools for batch purposes.',
@@ -2849,7 +3734,7 @@ worry that config_items is freeside-specific and icky.
     'section'     => 'UI',
     'description' => 'The year to use in census tract lookups',
     'type'        => 'select',
-    'select_enum' => [ qw( 2009 2008 2007 2006 ) ],
+    'select_enum' => [ qw( 2010 2009 2008 ) ],
   },
 
   {
@@ -2867,6 +3752,21 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'geocode_module',
+    'section'     => '',
+    'description' => 'Module to geocode (retrieve a latitude and longitude for) addresses',
+    'type'        => 'select',
+    'select_enum' => [ 'Geo::Coder::Googlev3' ],
+  },
+
+  {
+    'key'         => 'geocode-require_nw_coordinates',
+    'section'     => 'UI',
+    'description' => 'Require latitude and longitude in the North Western quadrant, e.g. for North American co-ordinates, etc.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'disable_acl_changes',
     'section'     => '',
     'description' => 'Disable all ACL changes, for demos.',
@@ -2874,6 +3774,13 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'disable_settings_changes',
+    'section'     => '',
+    'description' => 'Disable all settings changes, for demos, except for the usernames given in the comma-separated list.',
+    'type'        => [qw( checkbox text )],
+  },
+
+  {
     'key'         => 'cust_main-edit_agent_custid',
     'section'     => 'UI',
     'description' => 'Enable editing of the agent_custid field.',
@@ -2888,6 +3795,13 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'cust_main-title-display_custnum',
+    'section'     => 'UI',
+    'description' => 'Add the display_custom (agent_custid or custnum) to the title on customer view pages.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'cust_bill-default_agent_invid',
     'section'     => 'UI',
     'description' => 'Display the agent_invid field when available instead of the invnum field.',
@@ -2905,6 +3819,14 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'cust_main-custnum-display_prefix',
+    'section'     => 'UI',
+    'description' => 'Prefix the customer number with this number for display purposes (and zero fill to 8 digits).',
+    'type'        => 'text',
+    #and then probably agent-virt this to merge these instances
+  },
+
+  {
     'key'         => 'cust_main-default_areacode',
     'section'     => 'UI',
     'description' => 'Default area code for customers.',
@@ -2912,6 +3834,13 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'order_pkg-no_start_date',
+    'section'     => 'UI',
+    'description' => 'Don\'t set a default start date for new packages.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'mcp_svcpart',
     'section'     => '',
     'description' => 'Master Control Program svcpart.  Leave this blank.',
@@ -2920,14 +3849,14 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'cust_bill-max_same_services',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Maximum number of the same service to list individually on invoices before condensing to a single line listing the number of services.  Defaults to 5.',
     'type'        => 'text',
   },
 
   {
     'key'         => 'cust_bill-consolidate_services',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Consolidate service display into fewer lines on invoices rather than one per service.',
     'type'        => 'checkbox',
   },
@@ -2948,7 +3877,7 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'selfservice-head',
-    'section'     => '',
+    'section'     => 'self-service',
     'description' => 'HTML for the HEAD section of the self-service interface, typically used for LINK stylesheet tags',
     'type'        => 'textarea', #htmlarea?
     'per_agent'   => 1,
@@ -2957,7 +3886,7 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'selfservice-body_header',
-    'section'     => '',
+    'section'     => 'self-service',
     'description' => 'HTML header for the self-service interface',
     'type'        => 'textarea', #htmlarea?
     'per_agent'   => 1,
@@ -2965,8 +3894,8 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'selfservice-body_footer',
-    'section'     => '',
-    'description' => 'HTML header for the self-service interface',
+    'section'     => 'self-service',
+    'description' => 'HTML footer for the self-service interface',
     'type'        => 'textarea', #htmlarea?
     'per_agent'   => 1,
   },
@@ -2974,7 +3903,7 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'selfservice-body_bgcolor',
-    'section'     => '',
+    'section'     => 'self-service',
     'description' => 'HTML background color for the self-service interface, for example, #FFFFFF',
     'type'        => 'text',
     'per_agent'   => 1,
@@ -2982,123 +3911,339 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'selfservice-box_bgcolor',
-    'section'     => '',
-    'description' => 'HTML color for self-service interface input boxes, for example, #C0C0C0"',
+    'section'     => 'self-service',
+    'description' => 'HTML color for self-service interface input boxes, for example, #C0C0C0',
     'type'        => 'text',
     'per_agent'   => 1,
   },
 
   {
-    'key'         => 'selfservice-bulk_format',
-    'section'     => '',
-    'description' => 'Parameter arrangement for selfservice bulk features',
-    'type'        => 'select',
-    'select_enum' => [ '', 'izoom-soap', 'izoom-ftp' ],
+    'key'         => 'selfservice-text_color',
+    'section'     => 'self-service',
+    'description' => 'HTML text color for the self-service interface, for example, #000000',
+    'type'        => 'text',
     'per_agent'   => 1,
   },
 
   {
-    'key'         => 'selfservice-bulk_ftp_dir',
-    'section'     => '',
-    'description' => 'Enable bulk ftp provisioning in this folder',
+    'key'         => 'selfservice-link_color',
+    'section'     => 'self-service',
+    'description' => 'HTML link color for the self-service interface, for example, #0000FF',
     'type'        => 'text',
     'per_agent'   => 1,
   },
 
   {
-    'key'         => 'signup-no_company',
-    'section'     => '',
-    'description' => "Don't display a field for company name on signup.",
-    'type'        => 'checkbox',
+    'key'         => 'selfservice-vlink_color',
+    'section'     => 'self-service',
+    'description' => 'HTML visited link color for the self-service interface, for example, #FF00FF',
+    'type'        => 'text',
+    'per_agent'   => 1,
   },
 
   {
-    'key'         => 'signup-recommend_email',
-    'section'     => '',
-    'description' => 'Encourage the entry of an invoicing email address on signup.',
-    'type'        => 'checkbox',
+    'key'         => 'selfservice-hlink_color',
+    'section'     => 'self-service',
+    'description' => 'HTML hover link color for the self-service interface, for example, #808080',
+    'type'        => 'text',
+    'per_agent'   => 1,
   },
 
   {
-    'key'         => 'signup-recommend_daytime',
-    'section'     => '',
-    'description' => 'Encourage the entry of a daytime phone number  invoicing email address on signup.',
-    'type'        => 'checkbox',
+    'key'         => 'selfservice-alink_color',
+    'section'     => 'self-service',
+    'description' => 'HTML active (clicked) link color for the self-service interface, for example, #808080',
+    'type'        => 'text',
+    'per_agent'   => 1,
   },
 
   {
-    'key'         => 'svc_phone-radius-default_password',
-    'section'     => '',
-    'description' => 'Default password when exporting svc_phone records to RADIUS',
+    'key'         => 'selfservice-font',
+    'section'     => 'self-service',
+    'description' => 'HTML font CSS for the self-service interface, for example, 0.9em/1.5em Arial, Helvetica, Geneva, sans-serif',
     'type'        => 'text',
+    'per_agent'   => 1,
   },
 
   {
-    'key'         => 'svc_phone-allow_alpha_phonenum',
-    'section'     => '',
-    'description' => 'Allow letters in phone numbers.',
-    'type'        => 'checkbox',
+    'key'         => 'selfservice-title_color',
+    'section'     => 'self-service',
+    'description' => 'HTML color for the self-service title, for example, #000000',
+    'type'        => 'text',
+    'per_agent'   => 1,
   },
 
   {
-    'key'         => 'default_phone_countrycode',
-    'section'     => '',
-    'description' => 'Default countrcode',
+    'key'         => 'selfservice-title_align',
+    'section'     => 'self-service',
+    'description' => 'HTML alignment for the self-service title, for example, center',
+    'type'        => 'text',
+    'per_agent'   => 1,
+  },
+  {
+    'key'         => 'selfservice-title_size',
+    'section'     => 'self-service',
+    'description' => 'HTML font size for the self-service title, for example, 3',
     'type'        => 'text',
+    'per_agent'   => 1,
   },
 
   {
-    'key'         => 'cdr-charged_party-accountcode',
-    'section'     => '',
-    'description' => 'Set the charged_party field of CDRs to the accountcode.',
-    'type'        => 'checkbox',
+    'key'         => 'selfservice-title_left_image',
+    'section'     => 'self-service',
+    'description' => 'Image used for the top of the menu in the self-service interface, in PNG format.',
+    'type'        => 'image',
+    'per_agent'   => 1,
   },
 
   {
-    'key'         => 'cdr-charged_party-accountcode-trim_leading_0s',
-    'section'     => '',
-    'description' => 'When setting the charged_party field of CDRs to the accountcode, trim any leading zeros.',
-    'type'        => 'checkbox',
+    'key'         => 'selfservice-title_right_image',
+    'section'     => 'self-service',
+    'description' => 'Image used for the top of the menu in the self-service interface, in PNG format.',
+    'type'        => 'image',
+    'per_agent'   => 1,
   },
 
-#  {
-#    'key'         => 'cdr-charged_party-truncate_prefix',
-#    'section'     => '',
-#    'description' => 'If the charged_party field has this prefix, truncate it to the length in cdr-charged_party-truncate_length.',
-#    'type'        => 'text',
-#  },
-#
-#  {
-#    'key'         => 'cdr-charged_party-truncate_length',
-#    'section'     => '',
-#    'description' => 'If the charged_party field has the prefix in cdr-charged_party-truncate_prefix, truncate it to this length.',
-#    'type'        => 'text',
-#  },
+  {
+    'key'         => 'selfservice-menu_skipblanks',
+    'section'     => 'self-service',
+    'description' => 'Skip blank (spacer) entries in the self-service menu',
+    'type'        => 'checkbox',
+    'per_agent'   => 1,
+  },
 
   {
-    'key'         => 'cdr-charged_party_rewrite',
-    'section'     => '',
-    'description' => 'Do charged party rewriting in the freeside-cdrrewrited daemon; useful if CDRs are being dropped off directly in the database and require special charged_party processing such as cdr-charged_party-accountcode or cdr-charged_party-truncate*.',
+    'key'         => 'selfservice-menu_skipheadings',
+    'section'     => 'self-service',
+    'description' => 'Skip the unclickable heading entries in the self-service menu',
     'type'        => 'checkbox',
+    'per_agent'   => 1,
   },
 
   {
-    'key'         => 'cdr-taqua-da_rewrite',
-    'section'     => '',
-    'description' => 'For the Taqua CDR format, a comma-separated list of directory assistance 800 numbers.  Any CDRs with these numbers as "BilledNumber" will be rewritten to the "CallingPartyNumber" (and CallType "12") on import.',
+    'key'         => 'selfservice-menu_bgcolor',
+    'section'     => 'self-service',
+    'description' => 'HTML color for the self-service menu, for example, #C0C0C0',
     'type'        => 'text',
+    'per_agent'   => 1,
   },
 
   {
-    'key'         => 'cust_pkg-show_autosuspend',
-    'section'     => 'UI',
-    'description' => 'Show package auto-suspend dates.  Use with caution for now; can slow down customer view for large insallations.',
+    'key'         => 'selfservice-menu_fontsize',
+    'section'     => 'self-service',
+    'description' => 'HTML font size for the self-service menu, for example, -1',
+    'type'        => 'text',
+    'per_agent'   => 1,
+  },
+  {
+    'key'         => 'selfservice-menu_nounderline',
+    'section'     => 'self-service',
+    'description' => 'Styles menu links in the self-service without underlining.',
     'type'        => 'checkbox',
+    'per_agent'   => 1,
   },
 
+
   {
-    'key'         => 'cdr-asterisk_forward_rewrite',
+    'key'         => 'selfservice-menu_top_image',
+    'section'     => 'self-service',
+    'description' => 'Image used for the top of the menu in the self-service interface, in PNG format.',
+    'type'        => 'image',
+    'per_agent'   => 1,
+  },
+
+  {
+    'key'         => 'selfservice-menu_body_image',
+    'section'     => 'self-service',
+    'description' => 'Repeating image used for the body of the menu in the self-service interface, in PNG format.',
+    'type'        => 'image',
+    'per_agent'   => 1,
+  },
+
+  {
+    'key'         => 'selfservice-menu_bottom_image',
+    'section'     => 'self-service',
+    'description' => 'Image used for the bottom of the menu in the self-service interface, in PNG format.',
+    'type'        => 'image',
+    'per_agent'   => 1,
+  },
+  
+  {
+    'key'         => 'selfservice-view_usage_nodomain',
+    'section'     => 'self-service',
+    'description' => 'Show usernames without their domains in "View my usage" in the self-service interface.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'selfservice-bulk_format',
+    'section'     => 'deprecated',
+    'description' => 'Parameter arrangement for selfservice bulk features',
+    'type'        => 'select',
+    'select_enum' => [ '', 'izoom-soap', 'izoom-ftp' ],
+    'per_agent'   => 1,
+  },
+
+  {
+    'key'         => 'selfservice-bulk_ftp_dir',
+    'section'     => 'deprecated',
+    'description' => 'Enable bulk ftp provisioning in this folder',
+    'type'        => 'text',
+    'per_agent'   => 1,
+  },
+
+  {
+    'key'         => 'signup-no_company',
+    'section'     => 'self-service',
+    'description' => "Don't display a field for company name on signup.",
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'signup-recommend_email',
+    'section'     => 'self-service',
+    'description' => 'Encourage the entry of an invoicing email address on signup.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'signup-recommend_daytime',
+    'section'     => 'self-service',
+    'description' => 'Encourage the entry of a daytime phone number on signup.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'signup-duplicate_cc-warn_hours',
+    'section'     => 'self-service',
+    'description' => 'Issue a warning if the same credit card is used for multiple signups within this many hours.',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'svc_phone-radius-default_password',
+    'section'     => 'telephony',
+    'description' => 'Default password when exporting svc_phone records to RADIUS',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'svc_phone-allow_alpha_phonenum',
+    'section'     => 'telephony',
+    'description' => 'Allow letters in phone numbers.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'svc_phone-domain',
+    'section'     => 'telephony',
+    'description' => 'Track an optional domain association with each phone service.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'svc_phone-phone_name-max_length',
+    'section'     => 'telephony',
+    'description' => 'Maximum length of the phone service "Name" field (svc_phone.phone_name).  Sometimes useful to limit this (to 15?) when exporting as Caller ID data.',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'svc_phone-random_pin',
+    'section'     => 'telephony',
+    'description' => 'Number of random digits to generate in the "PIN" field, if empty.',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'svc_phone-lnp',
+    'section'     => 'telephony',
+    'description' => 'Enables Number Portability features for svc_phone',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'default_phone_countrycode',
     'section'     => '',
+    'description' => 'Default countrcode',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'cdr-charged_party-field',
+    'section'     => 'telephony',
+    'description' => 'Set the charged_party field of CDRs to this field.',
+    'type'        => 'select-sub',
+    'options_sub' => sub { my $fields = FS::cdr->table_info->{'fields'};
+                           map { $_ => $fields->{$_}||$_ }
+                           grep { $_ !~ /^(acctid|charged_party)$/ }
+                           FS::Schema::dbdef->table('cdr')->columns;
+                         },
+    'option_sub'  => sub { my $f = shift;
+                           FS::cdr->table_info->{'fields'}{$f} || $f;
+                         },
+  },
+
+  #probably deprecate in favor of cdr-charged_party-field above
+  {
+    'key'         => 'cdr-charged_party-accountcode',
+    'section'     => 'telephony',
+    'description' => 'Set the charged_party field of CDRs to the accountcode.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'cdr-charged_party-accountcode-trim_leading_0s',
+    'section'     => 'telephony',
+    'description' => 'When setting the charged_party field of CDRs to the accountcode, trim any leading zeros.',
+    'type'        => 'checkbox',
+  },
+
+#  {
+#    'key'         => 'cdr-charged_party-truncate_prefix',
+#    'section'     => '',
+#    'description' => 'If the charged_party field has this prefix, truncate it to the length in cdr-charged_party-truncate_length.',
+#    'type'        => 'text',
+#  },
+#
+#  {
+#    'key'         => 'cdr-charged_party-truncate_length',
+#    'section'     => '',
+#    'description' => 'If the charged_party field has the prefix in cdr-charged_party-truncate_prefix, truncate it to this length.',
+#    'type'        => 'text',
+#  },
+
+  {
+    'key'         => 'cdr-charged_party_rewrite',
+    'section'     => 'telephony',
+    'description' => 'Do charged party rewriting in the freeside-cdrrewrited daemon; useful if CDRs are being dropped off directly in the database and require special charged_party processing such as cdr-charged_party-accountcode or cdr-charged_party-truncate*.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'cdr-taqua-da_rewrite',
+    'section'     => 'telephony',
+    'description' => 'For the Taqua CDR format, a comma-separated list of directory assistance 800 numbers.  Any CDRs with these numbers as "BilledNumber" will be rewritten to the "CallingPartyNumber" (and CallType "12") on import.',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'cdr-taqua-accountcode_rewrite',
+    'section'     => 'telephony',
+    'description' => 'For the Taqua CDR format, pull accountcodes from secondary CDRs with matching sessionNumber.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'cust_pkg-show_autosuspend',
+    'section'     => 'UI',
+    'description' => 'Show package auto-suspend dates.  Use with caution for now; can slow down customer view for large insallations.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'cdr-asterisk_forward_rewrite',
+    'section'     => 'telephony',
     'description' => 'Enable special processing for CDRs representing forwarded calls: For CDRs that have a dcontext that starts with "Local/" but does not match dst, set charged_party to dst, parse a new dst from dstchannel, and set amaflags to "2" ("BILL"/"BILLING").',
     'type'        => 'checkbox',
   },
@@ -3132,6 +4277,14 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'mc-outbound_packages',
+    'section'     => '',
+    'description' => "Don't use this.",
+    'type'        => 'select-part_pkg',
+    'multiple'    => 1,
+  },
+
+  {
     'key'         => 'disable-cust-pkg_class',
     'section'     => 'UI',
     'description' => 'Disable the two-step dropdown for selecting package class and package, and return to the classic single dropdown.',
@@ -3146,6 +4299,13 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'queued-sleep_time',
+    'section'     => '',
+    'description' => 'Time to sleep between attempts to find new jobs to process in the queue.  Defaults to 10.  Installations doing real-time CDR processing for prepaid may want to set it lower.',
+    'type'        => 'text',
+  },
+
+  {
     'key'         => 'cancelled_cust-noevents',
     'section'     => 'billing',
     'description' => "Don't run events for cancelled customers",
@@ -3154,7 +4314,7 @@ worry that config_items is freeside-specific and icky.
 
   {
     'key'         => 'agent-invoice_template',
-    'section'     => 'billing',
+    'section'     => 'invoicing',
     'description' => 'Enable display/edit of old-style per-agent invoice template selection',
     'type'        => 'checkbox',
   },
@@ -3166,6 +4326,31 @@ worry that config_items is freeside-specific and icky.
     'type'        => 'text',
   },
 
+  {
+    'key'         => 'svc_broadband-manage_link_text',
+    'section'     => 'UI',
+    'description' => 'Label for "Manage Device" link',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'svc_broadband-manage_link_loc',
+    'section'     => 'UI',
+    'description' => 'Location for "Manage Device" link',
+    'type'        => 'select',
+    'select_hash' => [
+      'bottom' => 'Near Unprovision link',
+      'right'  => 'With export-related links',
+    ],
+  },
+
+  {
+    'key'         => 'svc_broadband-manage_link-new_window',
+    'section'     => 'UI',
+    'description' => 'Open the "Manage Device" link in a new window',
+    'type'        => 'checkbox',
+  },
+
   #more fine-grained, service def-level control could be useful eventually?
   {
     'key'         => 'svc_broadband-allow_null_ip_addr',
@@ -3283,6 +4468,322 @@ worry that config_items is freeside-specific and icky.
     'type'        => 'checkbox',
   },
 
+  {
+    'key'         => 'svc_domain-edit_domain',
+    'section'     => '',
+    'description' => 'Enable domain renaming',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'enable_legacy_prepaid_income',
+    'section'     => '',
+    'description' => "Enable legacy prepaid income reporting.  Only useful when you have imported pre-Freeside packages with longer-than-monthly duration, and need to do prepaid income reporting on them before they've been invoiced the first time.",
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'cust_main-exports',
+    'section'     => '',
+    'description' => 'Export(s) to call on cust_main insert, modification and deletion.',
+    'type'        => 'select-sub',
+    'multiple'    => 1,
+    'options_sub' => sub {
+      require FS::Record;
+      require FS::part_export;
+      my @part_export =
+        map { qsearch( 'part_export', {exporttype => $_ } ) }
+          keys %{FS::part_export::export_info('cust_main')};
+      map { $_->exportnum => $_->exporttype.' to '.$_->machine } @part_export;
+    },
+    'option_sub'  => sub {
+      require FS::Record;
+      require FS::part_export;
+      my $part_export = FS::Record::qsearchs(
+        'part_export', { 'exportnum' => shift }
+      );
+      $part_export
+        ? $part_export->exporttype.' to '.$part_export->machine
+        : '';
+    },
+  },
+
+  {
+    'key'         => 'cust_tag-location',
+    'section'     => 'UI',
+    'description' => 'Location where customer tags are displayed.',
+    'type'        => 'select',
+    'select_enum' => [ 'misc_info', 'top' ],
+  },
+
+  {
+    'key'         => 'maestro-status_test',
+    'section'     => 'UI',
+    'description' => 'Display a link to the maestro status test page on the customer view page',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'cust_main-custom_link',
+    'section'     => 'UI',
+    'description' => 'URL to use as source for the "Custom" tab in the View Customer page.  The customer number will be appended, or you can insert "$custnum" to have it inserted elsewhere.  "$agentnum" will be replaced with the agent number, and "$usernum" will be replaced with the employee number.',
+    'type'        => 'textarea',
+  },
+
+  {
+    'key'         => 'cust_main-custom_title',
+    'section'     => 'UI',
+    'description' => 'Title for the "Custom" tab in the View Customer page.',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'part_pkg-default_suspend_bill',
+    'section'     => 'billing',
+    'description' => 'Default the "Continue recurring billing while suspended" flag to on for new package definitions.',
+    'type'        => 'checkbox',
+  },
+  
+  {
+    'key'         => 'qual-alt_address_format',
+    'section'     => 'UI',
+    'description' => 'Enable the alternate address format (location type, number, and kind) for qualifications.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'prospect_main-alt_address_format',
+    'section'     => 'UI',
+    'description' => 'Enable the alternate address format (location type, number, and kind) for prospects.  Recommended if qual-alt_address_format is set and the main use of propects is for qualifications.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'prospect_main-location_required',
+    'section'     => 'UI',
+    'description' => 'Require an address for prospects.  Recommended if the main use of propects is for qualifications.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'note-classes',
+    'section'     => 'UI',
+    'description' => 'Use customer note classes',
+    'type'        => 'select',
+    'select_hash' => [
+                       0 => 'Disabled',
+                      1 => 'Enabled',
+                      2 => 'Enabled, with tabs',
+                    ],
+  },
+
+  {
+    'key'         => 'svc_acct-cf_privatekey-message',
+    'section'     => '',
+    'description' => 'For internal use: HTML displayed when cf_privatekey field is set.',
+    'type'        => 'textarea',
+  },
+
+  {
+    'key'         => 'menu-prepend_links',
+    'section'     => 'UI',
+    'description' => 'Links to prepend to the main menu, one per line, with format "URL Link Label (optional ALT popup)".',
+    'type'        => 'textarea',
+  },
+
+  {
+    'key'         => 'cust_main-external_links',
+    'section'     => 'UI',
+    'description' => 'External links available in customer view, one per line, with format "URL Link Label (optional ALT popup)".  The URL will have custnum appended.',
+    'type'        => 'textarea',
+  },
+  
+  {
+    'key'         => 'svc_phone-did-summary',
+    'section'     => 'invoicing',
+    'description' => 'Enable DID activity summary on invoices, showing # DIDs activated/deactivated/ported-in/ported-out and total minutes usage, covering period since last invoice.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'svc_acct-usage_seconds',
+    'section'     => 'invoicing',
+    'description' => 'Enable calculation of RADIUS usage time for invoices.  You must modify your template to display this information.',
+    'type'        => 'checkbox',
+  },
+  
+  {
+    'key'         => 'opensips_gwlist',
+    'section'     => 'telephony',
+    'description' => 'For svc_phone OpenSIPS dr_rules export, gwlist column value, per-agent',
+    'type'        => 'text',
+    'per_agent'   => 1,
+    'agentonly'   => 1,
+  },
+
+  {
+    'key'         => 'opensips_description',
+    'section'     => 'telephony',
+    'description' => 'For svc_phone OpenSIPS dr_rules export, description column value, per-agent',
+    'type'        => 'text',
+    'per_agent'   => 1,
+    'agentonly'   => 1,
+  },
+  
+  {
+    'key'         => 'opensips_route',
+    'section'     => 'telephony',
+    'description' => 'For svc_phone OpenSIPS dr_rules export, routeid column value, per-agent',
+    'type'        => 'text',
+    'per_agent'   => 1,
+    'agentonly'   => 1,
+  },
+
+  {
+    'key'         => 'cust_bill-no_recipients-error',
+    'section'     => 'invoicing',
+    'description' => 'For customers with no invoice recipients, throw a job queue error rather than the default behavior of emailing the invoice to the invoice_from address.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'cust_bill-latex_lineitem_maxlength',
+    'section'     => 'invoicing',
+    'description' => 'Truncate long line items to this number of characters on typeset invoices, to avoid losing things off the right margin.  Defaults to 50.  ',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'cust_main-status_module',
+    'section'     => 'UI',
+    'description' => 'Which module to use for customer status display.  The "Classic" module (the default) considers accounts with cancelled recurring packages but un-cancelled one-time charges Inactive.  The "Recurring" module considers those customers Cancelled.  Similarly for customers with suspended recurring packages but one-time charges.', #other differences?
+    'type'        => 'select',
+    'select_enum' => [ 'Classic', 'Recurring' ],
+  },
+
+  { 
+    'key'         => 'username-pound',
+    'section'     => 'username',
+    'description' => 'Allow the pound character (#) in usernames.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'ie-compatibility_mode',
+    'section'     => 'UI',
+    'description' => "Compatibility mode META tag for Internet Explorer, used on the customer view page.  Not necessary in normal operation unless custom content (notes, cust_main-custom_link) is included on customer view that is incompatibile with newer IE verisons.",
+    'type'        => 'select',
+    'select_enum' => [ '', '7', 'EmulateIE7', '8', 'EmulateIE8' ],
+  },
+
+  {
+    'key'         => 'disable_payauto_default',
+    'section'     => 'UI',
+    'description' => 'Disable the "Charge future payments to this (card|check) automatically" checkbox from defaulting to checked.',
+    'type'        => 'checkbox',
+  },
+  
+  {
+    'key'         => 'payment-history-report',
+    'section'     => 'UI',
+    'description' => 'Show a link to the raw database payment history report in the Reports menu.  DO NOT ENABLE THIS for modern installations.',
+    'type'        => 'checkbox',
+  },
+  
+  {
+    'key'         => 'svc_broadband-require-nw-coordinates',
+    'section'     => 'deprecated',
+    'description' => 'Deprecated; see geocode-require_nw_coordinates instead',
+    'type'        => 'checkbox',
+  },
+  
+  {
+    'key'         => 'cust-email-high-visibility',
+    'section'     => 'UI',
+    'description' => 'Move the invoicing e-mail address field to the top of the billing address section and highlight it.',
+    'type'        => 'checkbox',
+  },
+  
+  {
+    'key'         => 'cust_main-require-bank-branch',
+    'section'     => 'UI',
+    'description' => 'An alternate DCHK/CHEK format; require entry of bank branch number.',
+    'type'        => 'checkbox',
+  },
+  
+  {
+    'key'         => 'cust-edit-alt-field-order',
+    'section'     => 'UI',
+    'description' => 'An alternate ordering of fields for the New Customer and Edit Customer screens.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'cust_bill-enable_promised_date',
+    'section'     => 'UI',
+    'description' => 'Enable display/editing of the "promised payment date" field on invoices.',
+    'type'        => 'checkbox',
+  },
+  
+  {
+    'key'         => 'available-locales',
+    'section'     => '',
+    'description' => 'Limit available locales (employee preferences, per-customer locale selection, etc.) to a particular set.',
+    'type'        => 'select-sub',
+    'multiple'    => 1,
+    'options_sub' => sub { 
+      map { $_ => FS::Locales->description($_) }
+      grep { $_ ne 'en_US' } 
+      FS::Locales->locales;
+    },
+    'option_sub'  => sub { FS::Locales->description(shift) },
+  },
+  
+  {
+    'key'         => 'translate-auto-insert',
+    'section'     => '',
+    'description' => 'Auto-insert untranslated strings for selected non-en_US locales with their default/en_US values.  Do not turn this on unless translating the interface into a new language.',
+    'type'        => 'select',
+    'multiple'    => 1,
+    'select_enum' => [ grep { $_ ne 'en_US' } FS::Locales::locales ],
+  },
+
+  {
+    'key'         => 'svc_acct-tower_sector',
+    'section'     => '',
+    'description' => 'Track tower and sector for svc_acct (account) services.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'cdr-prerate',
+    'section'     => 'telephony',
+    'description' => 'Experimental feature to rate CDRs immediately, rather than waiting until invoice generation time.  Can reduce invoice generation time when processing lots of CDRs.  Currently works with "VoIP/telco CDR rating (standard)" price plans using "Phone numbers (svc_phone.phonenum)" CDR service matching, without any included minutes.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'cdr-prerate-cdrtypenums',
+    'section'     => 'telephony',
+    'description' => 'When using cdr-prerate to rate CDRs immediately, limit processing to these CDR types.',
+    'type'        => 'select-sub',
+    'multiple'    => 1,
+    'options_sub' => sub { require FS::Record;
+                           require FS::cdr_type;
+                           map { $_->cdrtypenum => $_->cdrtypename }
+                               FS::Record::qsearch( 'cdr_type', 
+                                                   {} #{ 'disabled' => '' }
+                                                 );
+                        },
+    'option_sub'  => sub { require FS::Record;
+                           require FS::cdr_type;
+                           my $cdr_type = FS::Record::qsearchs(
+                            'cdr_type', { 'cdrtypenum'=>shift } );
+                           $cdr_type ? $cdr_type->cdrtypename : '';
+                        },
+  },
+  
+  
   { key => "apacheroot", section => "deprecated", description => "<b>DEPRECATED</b>", type => "text" },
   { key => "apachemachine", section => "deprecated", description => "<b>DEPRECATED</b>", type => "text" },
   { key => "apachemachines", section => "deprecated", description => "<b>DEPRECATED</b>", type => "text" },