- add message catalog table & beginning of web interface
[freeside.git] / FS / FS / svc_acct.pm
index 9da5a66..8d22c21 100644 (file)
@@ -192,8 +192,6 @@ FS::svc_Common.  The following fields are currently supported:
 
 =item radius_I<Radius_Attribute> - I<Radius-Attribute>
 
-=item domsvc - service number of svc_domain with which to associate
-
 =back
 
 =head1 METHODS
@@ -216,6 +214,10 @@ otherwise returns false.
 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be 
 defined.  An FS::cust_svc record will be created and inserted.
 
+The additional field I<usergroup> can optionally be defined; if so it should
+contain an arrayref of group names.  See L<FS::radius_usergroup>.  (used in
+sqlradius export only)
+
 If the configuration value (see L<FS::Conf>) shellmachine exists, and the 
 username, uid, and dir fields are defined, the command(s) specified in
 the shellmachine-useradd configuration are added to the job queue (see
@@ -255,8 +257,6 @@ sub insert {
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
-  my $amount = 0;
-
   $error = $self->check;
   return $error if $error;
 
@@ -289,6 +289,20 @@ sub insert {
     return $error;
   }
 
+  if ( $self->usergroup ) {
+    foreach my $groupname ( @{$self->usergroup} ) {
+      my $radius_usergroup = new FS::radius_usergroup ( {
+        svcnum    => $self->svcnum,
+        groupname => $groupname,
+      } );
+      my $error = $radius_usergroup->insert;
+      if ( $error ) {
+        $dbh->rollback if $oldAutoCommit;
+        return $error;
+      }
+    }
+  }
+
   #new-style exports!
   unless ( $noexport_hack ) {
     foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
@@ -561,6 +575,18 @@ sub delete {
     }
   }
 
+  foreach my $radius_usergroup (
+    qsearch('radius_usergroup', { 'svcnum' => $self->svcnum } )
+  ) {
+    my $error = $radius_usergroup->delete;
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
+  }
+
+  my $part_svc = $self->cust_svc->part_svc;
+
   my $error = $self->SUPER::delete;
   if ( $error ) {
     $dbh->rollback if $oldAutoCommit;
@@ -569,7 +595,7 @@ sub delete {
 
   #new-style exports!
   unless ( $noexport_hack ) {
-    foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
+    foreach my $part_export ( $part_svc->part_export ) {
       my $error = $part_export->export_delete($self);
       if ( $error ) {
         $dbh->rollback if $oldAutoCommit;
@@ -700,6 +726,10 @@ sub vpopmail_delete {
 Replaces OLD_RECORD with this one in the database.  If there is an error,
 returns the error, otherwise returns false.
 
+The additional field I<usergroup> can optionally be defined; if so it should
+contain an arrayref of group names.  See L<FS::radius_usergroup>.  (used in
+sqlradius export only)
+
 If the configuration value (see L<FS::Conf>) shellmachine exists, and the 
 dir field has changed, the command(s) specified in the shellmachine-usermod
 configuraiton file are added to the job queue (see L<FS::queue> and
@@ -760,6 +790,40 @@ sub replace {
     return $error if $error;
   }
 
+  $old->usergroup( [ $old->radius_groups ] );
+  if ( $new->usergroup ) {
+    #(sorta) false laziness with FS::part_export::sqlradius::_export_replace
+    my @newgroups = @{$new->usergroup};
+    foreach my $oldgroup ( @{$old->usergroup} ) {
+      if ( grep { $oldgroup eq $_ } @newgroups ) {
+        @newgroups = grep { $oldgroup ne $_ } @newgroups;
+        next;
+      }
+      my $radius_usergroup = qsearchs('radius_usergroup', {
+        svcnum    => $old->svcnum,
+        groupname => $oldgroup,
+      } );
+      my $error = $radius_usergroup->delete;
+      if ( $error ) {
+        $dbh->rollback if $oldAutoCommit;
+        return "error deleting radius_usergroup $oldgroup: $error";
+      }
+    }
+
+    foreach my $newgroup ( @newgroups ) {
+      my $radius_usergroup = new FS::radius_usergroup ( {
+        svcnum    => $new->svcnum,
+        groupname => $newgroup,
+      } );
+      my $error = $radius_usergroup->insert;
+      if ( $error ) {
+        $dbh->rollback if $oldAutoCommit;
+        return "error adding radius_usergroup $newgroup: $error";
+      }
+    }
+
+  }
+
   #new-style exports!
   unless ( $noexport_hack ) {
     foreach my $part_export ( $new->cust_svc->part_svc->part_export ) {
@@ -1008,8 +1072,14 @@ sub check {
   return $x unless ref($x);
   my $part_svc = $x;
 
+  if ( $part_svc->part_svc_column('usergroup')->columnflag eq "F" ) {
+    $self->usergroup(
+      [ split(',', $part_svc->part_svc_column('usergroup')->columnvalue) ] );
+  }
+
   my $error = $self->ut_numbern('svcnum')
               || $self->ut_number('domsvc')
+              || $self->ut_textn('sec_phrase')
   ;
   return $error if $error;
 
@@ -1299,7 +1369,7 @@ sub radius_groups {
 
 =head1 SUBROUTINES
 
-=item radius_usergroup_selector GROUPS_ARRAYREF
+=item radius_usergroup_selector GROUPS_ARRAYREF [ SELECTNAME ]
 
 =cut
 
@@ -1323,6 +1393,7 @@ sub radius_usergroup_selector {
       var optionName = new Option(myvalue,myvalue,false,true);
       var length = object.$selectname.length;
       object.$selectname.options[length] = optionName;
+      object.${selectname}_add.value = "";
     }
     </SCRIPT>
     <SELECT MULTIPLE NAME="$selectname">
@@ -1330,9 +1401,15 @@ END
 
   foreach my $group ( @all_groups ) {
     $html .= '<OPTION';
-    $html .= ' SELECTED' if $sel_groups{$group};
+    if ( $sel_groups{$group} ) {
+      $html .= ' SELECTED';
+      $sel_groups{$group} = 0;
+    }
     $html .= ">$group</OPTION>\n";
   }
+  foreach my $group ( grep { $sel_groups{$_} } keys %sel_groups ) {
+    $html .= "<OPTION SELECTED>$group</OPTION>\n";
+  };
   $html .= '</SELECT>';
 
   $html .= qq!<BR><INPUT TYPE="text" NAME="${selectname}_add">!.