make the config directory configurable
[freeside.git] / FS / FS / Conf.pm
index 72c643f..270b61c 100644 (file)
@@ -1,11 +1,15 @@
 package FS::Conf;
 
-use vars qw($default_dir @config_items $DEBUG );
+use vars qw($default_dir $base_dir @config_items @card_types $DEBUG );
 use IO::File;
 use File::Basename;
 use FS::ConfItem;
 use FS::ConfDefaults;
 
+$base_dir = '%%%FREESIDE_CONF%%%';
+$default_dir = '%%%FREESIDE_CONF%%%';
+
+
 $DEBUG = 0;
 
 =head1 NAME
@@ -52,13 +56,15 @@ $FS::Conf::default_dir has not been set.
 sub new {
   my($proto,$dir) = @_;
   my($class) = ref($proto) || $proto;
-  my($self) = { 'dir' => $dir || $default_dir } ;
+  my($self) = { 'dir'      => $dir || $default_dir,
+                'base_dir' => $base_dir,
+              };
   bless ($self, $class);
 }
 
 =item dir
 
-Returns the directory.
+Returns the conf directory.
 
 =cut
 
@@ -73,6 +79,23 @@ sub dir {
   $1;
 }
 
+=item base_dir
+
+Returns the base directory.  By default this is /usr/local/etc/freeside.
+
+=cut
+
+sub base_dir {
+  my($self) = @_;
+  my $base_dir = $self->{base_dir};
+  -e $base_dir or die "FATAL: $base_dir doesn't exist!";
+  -d $base_dir or die "FATAL: $base_dir isn't a directory!";
+  -r $base_dir or die "FATAL: Can't read $base_dir!";
+  -x $base_dir or die "FATAL: $base_dir not searchable (executable)!";
+  $base_dir =~ /^(.*)$/;
+  $1;
+}
+
 =item config KEY
 
 Returns the configuration value or values (depending on context) for key.
@@ -284,6 +307,20 @@ httemplate/docs/config.html
 
 =cut
 
+#Business::CreditCard
+@card_types = (
+  "VISA card",
+  "MasterCard",
+  "Discover card",
+  "American Express card",
+  "Diner's Club/Carte Blanche",
+  "enRoute",
+  "JCB",
+  "BankCard",
+  "Switch",
+  "Solo",
+);
+
 @config_items = map { new FS::ConfItem $_ } (
 
   {
@@ -1000,6 +1037,13 @@ httemplate/docs/config.html
   },
 
   {
+    'key'         => 'unsuspend-always_adjust_next_bill_date',
+    'section'     => 'billing',
+    'description' => 'Global override that causes unsuspensions to always adjust the next bill date under any circumstances.  This is now controlled on a per-package bases - probably best not to use this option unless you are a legacy installation that requires this behaviour.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'usernamemin',
     'section'     => 'username',
     'description' => 'Minimum username length (default 2)',
@@ -1188,15 +1232,63 @@ httemplate/docs/config.html
   {
     'key'         => 'signup_server-default_agentnum',
     'section'     => '',
-    'description' => 'Default agentnum for the signup server',
-    'type'        => 'text',
+    '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'         => 'signup_server-default_refnum',
     'section'     => '',
-    'description' => 'Default advertising source number for the signup server',
-    'type'        => 'text',
+    'description' => 'Default advertising source for the signup server',
+    '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 : '';
+                        },
+  },
+
+  {
+    'key'         => 'signup_server-default_pkgpart',
+    'section'     => '',
+    'description' => 'Default pakcage for the signup server',
+    'type'        => 'select-sub',
+    'options_sub' => sub { require FS::Record;
+                           require FS::part_pkg;
+                           map { $_->pkgpart => $_->pkg.' - '.$_->comment }
+                               FS::Record::qsearch( 'part_pkg',
+                                                   { 'disabled' => ''}
+                                                 );
+                        },
+    'option_sub'  => sub { require FS::Record;
+                           require FS::part_pkg;
+                           my $part_pkg = FS::Record::qsearchs(
+                            'part_pkg', { 'pkgpart'=>shift }
+                          );
+                           $part_pkg
+                            ? $part_pkg->pkg.' - '.$part_pkg->comment
+                            : '';
+                        },
   },
 
   {
@@ -1213,24 +1305,41 @@ httemplate/docs/config.html
     'type'        => 'checkbox',
   },
   {
-      key         => 'signup_server-classnum2',
-      section     => '',
-      description => 'Package Class for first optional purchase',
-      type        => 'select-sub',
-      options_sub => sub { my @o = map { $_->{classnum} => $_->{classname} }  map { $_->hashref } FS::Record::qsearch('pkg_class',{});
-                          } ,
-      option_sub => sub { return map { $_->hashref->{classname}}  FS::Record::qsearchs('pkg_class', { classnum => shift } );  }, 
-
-  },
-
-  {
-      key         => 'signup_server-classnum3',
-      section     => '',
-      description => 'Package Class for second optional purchase',
-      type        => 'select-sub',
-      options_sub => sub { my @o = map { $_->{classnum} => $_->{classname} }  map { $_->hashref } FS::Record::qsearch('pkg_class',{});
-                          } ,
-      option_sub => sub { return map { $_->hashref->{classname}}  FS::Record::qsearchs('pkg_class', { classnum => shift } );  }, 
+    'key'         => 'signup_server-classnum2',
+    'section'     => '',
+    'description' => 'Package Class for first optional purchase',
+    'type'        => 'select-sub',
+    'options_sub' => sub { require FS::Record;
+                           require FS::pkg_class;
+                           map { $_->classnum => $_->classname }
+                               FS::Record::qsearch('pkg_class', {} );
+                        },
+    'option_sub'  => sub { require FS::Record;
+                           require FS::pkg_class;
+                           my $pkg_class = FS::Record::qsearchs(
+                            'pkg_class', { 'classnum'=>shift }
+                          );
+                           $pkg_class ? $pkg_class->classname : '';
+                        },
+  },
+
+  {
+    'key'         => 'signup_server-classnum3',
+    'section'     => '',
+    'description' => 'Package Class for second optional purchase',
+    'type'        => 'select-sub',
+    'options_sub' => sub { require FS::Record;
+                           require FS::pkg_class;
+                           map { $_->classnum => $_->classname }
+                               FS::Record::qsearch('pkg_class', {} );
+                        },
+    'option_sub'  => sub { require FS::Record;
+                           require FS::pkg_class;
+                           my $pkg_class = FS::Record::qsearchs(
+                            'pkg_class', { 'classnum'=>shift }
+                          );
+                           $pkg_class ? $pkg_class->classname : '';
+                        },
   },
 
   {
@@ -1333,6 +1442,42 @@ httemplate/docs/config.html
   },
 
   {
+    'key'         => 'warning_email',
+    'section'     => '',
+    '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/~mjd/Text-Template/lib/Text/Template.pm">Text::Template</a> documentation for details on the template substitution language.  The following variables are available<ul><li><code>$username</code> <li><code>$password</code> <li><code>$first</code> <li><code>$last</code> <li><code>$pkg</code> <li><code>$column</code> <li><code>$amount</code> <li><code>$threshold</code></ul>',
+    'type'        => 'textarea',
+  },
+
+  {
+    'key'         => 'warning_email-from',
+    'section'     => '',
+    'description' => 'From: address header for warning email',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'warning_email-cc',
+    'section'     => '',
+    'description' => 'Additional recipient(s) (comma separated) for warning email when remaining usage reaches zero.',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'warning_email-subject',
+    'section'     => '',
+    'description' => 'Subject: header for warning email',
+    'type'        => 'text',
+  },
+  
+  {
+    'key'         => 'warning_email-mimetype',
+    'section'     => '',
+    'description' => 'MIME type for warning email',
+    'type'        => 'select',
+    'select_enum' => [ 'text/plain', 'text/html' ],
+  },
+
+  {
     'key'         => 'payby',
     'section'     => 'billing',
     'description' => 'Available payment types.',
@@ -1404,15 +1549,7 @@ httemplate/docs/config.html
     'section'     => 'billing',
     'description' => 'Save CVV2 information after the initial transaction for the selected credit card types.  Enabling this option may be in violation of your merchant agreement(s), so please check them carefully before enabling this option for any credit card types.',
     'type'        => 'selectmultiple',
-    'select_enum' => [ "VISA card",
-                       "MasterCard",
-                       "Discover card",
-                       "American Express card",
-                       "Diner's Club/Carte Blanche",
-                       "enRoute",
-                       "JCB",
-                       "BankCard",
-                     ],
+    'select_enum' => \@card_types,
   },
 
   {
@@ -1637,18 +1774,25 @@ httemplate/docs/config.html
   {
     'key'         => 'svc_acct-usage_suspend',
     'section'     => 'billing',
-    'description' => 'Suspends the package an account belongs to when svc_acct.seconds is decremented to 0 or below (accounts with an empty seconds value are ignored).  Typically used in conjunction with prepaid packages and freeside-sqlradius-radacctd.',
+    'description' => 'Suspends the package an account belongs to when svc_acct.seconds or a bytecount is decremented to 0 or below (accounts with an empty seconds and up|down|totalbytes value are ignored).  Typically used in conjunction with prepaid packages and freeside-sqlradius-radacctd.',
     'type'        => 'checkbox',
   },
 
   {
     'key'         => 'svc_acct-usage_unsuspend',
     'section'     => 'billing',
-    'description' => 'Unuspends the package an account belongs to when svc_acct.seconds is incremented from 0 or below to a positive value (accounts with an empty seconds value are ignored).  Typically used in conjunction with prepaid packages and freeside-sqlradius-radacctd.',
+    'description' => 'Unuspends the package an account belongs to when svc_acct.seconds or a bytecount is incremented from 0 or below to a positive value (accounts with an empty seconds and up|down|totalbytes value are ignored).  Typically used in conjunction with prepaid packages and freeside-sqlradius-radacctd.',
     'type'        => 'checkbox',
   },
 
   {
+    'key'         => 'svc_acct-usage_threshold',
+    'section'     => 'billing',
+    'description' => 'The threshold (expressed as percentage) of acct.seconds or acct.up|down|totalbytes at which a warning message is sent to a service holder.  Typically used in conjunction with prepaid packages and freeside-sqlradius-radacctd.  Defaults to 80.',
+    'type'        => 'text',
+  },
+
+  {
     'key'         => 'cust-fields',
     'section'     => 'UI',
     'description' => 'Which customer fields to display on reports by default',
@@ -1744,7 +1888,8 @@ httemplate/docs/config.html
     'section'     => 'billing',
     'description' => 'Default format for batches.',
     'type'        => 'select',
-    'select_enum' => [ 'csv-td_canada_trust-merchant_pc_batch', 'BoM', 'PAP' ]
+    'select_enum' => [ 'csv-td_canada_trust-merchant_pc_batch',
+                       'csv-chase_canada-E-xactBatch', 'BoM', 'PAP' ]
   },
 
   {
@@ -1752,7 +1897,8 @@ httemplate/docs/config.html
     'section'     => 'billing',
     'description' => 'Fixed (unchangeable) format for credit card batches.',
     'type'        => 'select',
-    'select_enum' => [ 'csv-td_canada_trust-merchant_pc_batch', 'BoM', 'PAP' ]
+    'select_enum' => [ 'csv-td_canada_trust-merchant_pc_batch', 'BoM', 'PAP' ,
+                       'csv-chase_canada-E-xactBatch', 'BoM', 'PAP' ]
   },
 
   {
@@ -1834,6 +1980,21 @@ httemplate/docs/config.html
     '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.',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'card-types',
+    'section'     => 'billing',
+    'description' => 'Select one or more card types to enable only those card types.  If no card types are selected, all card types are available.',
+    'type'        => 'selectmultiple',
+    'select_enum' => \@card_types,
+  },
+
 );
 
 1;