reincorporate the changes from http://www.sisd.com/cgi-bin/viewcvs.cgi/freeside/httem...
[freeside.git] / FS / FS / svc_acct.pm
index 7cbe63f..0a7d6be 100644 (file)
@@ -8,7 +8,8 @@ use vars qw( @ISA $DEBUG $me $conf $skip_fuzzyfiles
              $username_noperiod $username_nounderscore $username_nodash
              $username_uppercase $username_percent
              $password_noampersand $password_noexclamation
-             $welcome_template $welcome_from $welcome_subject $welcome_mimetype
+             $welcome_template $welcome_from
+             $welcome_subject $welcome_subject_template $welcome_mimetype
              $warning_template $warning_from $warning_subject $warning_mimetype
              $warning_cc
              $smtpmachine
@@ -71,6 +72,10 @@ $FS::UID::callback{'FS::svc_acct'} = sub {
     ) or warn "can't create welcome email template: $Text::Template::ERROR";
     $welcome_from = $conf->config('welcome_email-from'); # || 'your-isp-is-dum'
     $welcome_subject = $conf->config('welcome_email-subject') || 'Welcome';
+    $welcome_subject_template = new Text::Template (
+      TYPE   => 'STRING',
+      SOURCE => $welcome_subject,
+    ) or warn "can't create welcome email subject template: $Text::Template::ERROR";
     $welcome_mimetype = $conf->config('welcome_email-mimetype') || 'text/plain';
   } else {
     $welcome_template = '';
@@ -232,17 +237,20 @@ sub table_info {
                          select_table => 'svc_acct_pop',
                          select_key   => 'popnum',
                          select_label => 'city',
+                         disable_select => 1,
                        },
         'username'  => {
                          label => 'Username',
                          type => 'text',
                          disable_default => 1,
                          disable_fixed => 1,
+                         disable_select => 1,
                        },
         'quota'     => { 
                          label => 'Quota',
                          type => 'text',
                          disable_inventory => 1,
+                         disable_select => 1,
                        },
         '_password' => 'Password',
         'gid'       => {
@@ -257,25 +265,29 @@ sub table_info {
                          type     =>'select',
                          select_list => [ $conf->config('shells') ],
                          disable_inventory => 1,
+                         disable_select => 1,
                        },
         'finger'    => 'Real name (GECOS)',
         'domsvc'    => {
                          label     => 'Domain',
-                         def_label => 'svcnum from svc_domain',
+                         #def_label => 'svcnum from svc_domain',
                          type      => 'select',
                          select_table => 'svc_domain',
                          select_key   => 'svcnum',
                          select_label => 'domain',
                          disable_inventory => 1,
+
                        },
         'usergroup' => {
                          label => 'RADIUS groups',
                          type  => 'radius_usergroup_selector',
                          disable_inventory => 1,
+                         disable_select => 1,
                        },
         'seconds'   => { label => 'Seconds',
                          type  => 'text',
                          disable_inventory => 1,
+                         disable_select => 1,
                        },
     },
   };
@@ -453,7 +465,10 @@ sub insert {
   if ( $cust_pkg ) {
     my $cust_main = $cust_pkg->cust_main;
 
-    if ( $conf->exists('emailinvoiceauto') ) {
+    if (   $conf->exists('emailinvoiceautoalways')
+        || $conf->exists('emailinvoiceauto')
+        && ! $cust_main->invoicing_list_emailonly
+       ) {
       my @invoicing_list = $cust_main->invoicing_list;
       push @invoicing_list, $self->email;
       $cust_main->invoicing_list(\@invoicing_list);
@@ -464,6 +479,15 @@ sub insert {
     if ( $welcome_template && $cust_pkg ) {
       my $to = join(', ', grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list );
       if ( $to ) {
+
+        my %hash = (
+                     'custnum'  => $self->custnum,
+                     'username' => $self->username,
+                     'password' => $self->_password,
+                     'first'    => $cust_main->first,
+                     'last'     => $cust_main->getfield('last'),
+                     'pkg'      => $cust_pkg->part_pkg->pkg,
+                   );
         my $wqueue = new FS::queue {
           'svcnum' => $self->svcnum,
           'job'    => 'FS::svc_acct::send_email'
@@ -471,16 +495,9 @@ sub insert {
         my $error = $wqueue->insert(
           'to'       => $to,
           'from'     => $welcome_from,
-          'subject'  => $welcome_subject,
+          'subject'  => $welcome_subject_template->fill_in( HASH => \%hash, ),
           'mimetype' => $welcome_mimetype,
-          'body'     => $welcome_template->fill_in( HASH => {
-                          'custnum'  => $self->custnum,
-                          'username' => $self->username,
-                          'password' => $self->_password,
-                          'first'    => $cust_main->first,
-                          'last'     => $cust_main->getfield('last'),
-                          'pkg'      => $cust_pkg->part_pkg->pkg,
-                        } ),
+          'body'     => $welcome_template->fill_in( HASH => \%hash, ),
         );
         if ( $error ) {
           $dbh->rollback if $oldAutoCommit;
@@ -1515,6 +1532,28 @@ sub _op_usage {
 
   my $action = $op2action{$op};
 
+  if ( &{$op2condition{$op}}($self, $column, $amount) ) {
+    foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
+      if ($part_export->option('overlimit_groups')) {
+        my ($new,$old);
+        my $other = new FS::svc_acct $self->hashref;
+        my $groups = &{ $self->_fieldhandlers->{'usergroup'} }
+                       ($self, $part_export->option('overlimit_groups'));
+        $other->usergroup( $groups );
+        if ($action eq 'suspend'){
+          $new = $other; $old = $self;
+        }else{
+          $new = $self; $old = $other;
+        }
+        my $error = $part_export->export_replace($new, $old);
+        if ( $error ) {
+          $dbh->rollback if $oldAutoCommit;
+          return "Error replacing radius groups in export, ${op}: $error";
+        }
+      }
+    }
+  }
+
   if ( $conf->exists("svc_acct-usage_$action")
        && &{$op2condition{$op}}($self, $column, $amount)    ) {
     #my $error = $self->$action();
@@ -1571,6 +1610,7 @@ sub set_usage {
   local $SIG{TSTP} = 'IGNORE';
   local $SIG{PIPE} = 'IGNORE';
 
+  local $FS::svc_Common::noexport_hack = 1;
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;