group editing seems to be working... everything except defaults... oh and
authorivan <ivan>
Sat, 23 Mar 2002 16:16:00 +0000 (16:16 +0000)
committerivan <ivan>
Sat, 23 Mar 2002 16:16:00 +0000 (16:16 +0000)
export...

FS/FS/part_export.pm
FS/FS/queue.pm
FS/FS/svc_acct.pm
httemplate/edit/process/svc_acct.cgi
httemplate/edit/svc_acct.cgi

index 3f184be..9aedd9f 100644 (file)
@@ -505,9 +505,11 @@ sub _export_replace {
     }
 
     my @del = grep { !exists $new{$_} } keys %old;
-    my $error = $self->sqlradius_queue( $new->svcnum, 'sqlradius_attrib_delete',
-      $table, $new->username, @del );
-    return $error if $error;
+    if ( @del ) {
+      my $error = $self->sqlradius_queue( $new->svcnum, 'attrib_delete',
+        $table, $new->username, @del );
+      return $error if $error;
+    }
   }
 
   '';
index a6d78e1..7a38a6e 100644 (file)
@@ -222,7 +222,7 @@ sub cust_svc {
   qsearchs('cust_svc', { 'svcnum' => $self->svcnum } );
 }
 
-=item joblisting HASHREF
+=item joblisting HASHREF NOACTIONS
 
 =cut
 
@@ -232,21 +232,24 @@ sub joblisting {
   use Date::Format;
   use FS::CGI;
 
+  my @queue = qsearch( 'queue', $hashref );
+  return '' unless scalar(@queue);
+
   my $html = FS::CGI::table(). <<END;
       <TR>
         <TH COLSPAN=2>Job</TH>
         <TH>Args</TH>
         <TH>Date</TH>
         <TH>Status</TH>
-        <TH>Account</TH>
-      </TR>
 END
+  $html .= '<TH>Account</TH>' unless $hashref->{svcnum};
+  $html .= '</TR>';
 
   my $p = FS::CGI::popurl(2);
   foreach my $queue ( sort { 
     $a->getfield('jobnum') <=> $b->getfield('jobnum')
-  } qsearch( 'queue', $hashref ) ) {
-    my $hashref = $queue->hashref;
+  } @queue ) {
+    my $queue_hashref = $queue->hashref;
     my $jobnum = $queue->jobnum;
     my $args = join(' ', $queue->args);
     my $date = time2str( "%a %b %e %T %Y", $queue->_date );
@@ -258,26 +261,31 @@ END
         qq!&nbsp;<A HREF="$p/misc/queue.cgi?jobnum=$jobnum&action=del">remove</A>&nbsp;)!;
     }
     my $cust_svc = $queue->cust_svc;
-    my $account;
-    if ( $cust_svc ) {
-      my $table = $cust_svc->part_svc->svcdb;
-      my $label = ( $cust_svc->label )[1];
-      $account = qq!<A HREF="../view/$table.cgi?!. $queue->svcnum.
-                 qq!">$label</A>!;
-    } else {
-      $account = '';
-    }
+
     $html .= <<END;
       <TR>
         <TD>$jobnum</TD>
-        <TD>$hashref->{job}</TD>
+        <TD>$queue_hashref->{job}</TD>
         <TD>$args</TD>
         <TD>$date</TD>
         <TD>$status</TD>
-        <TD>$account</TD>
-      </TR>
 END
 
+    unless ( $hashref->{svcnum} ) {
+      my $account;
+      if ( $cust_svc ) {
+        my $table = $cust_svc->part_svc->svcdb;
+        my $label = ( $cust_svc->label )[1];
+        $account = qq!<A HREF="../view/$table.cgi?!. $queue->svcnum.
+                   qq!">$label</A>!;
+      } else {
+        $account = '';
+      }
+      $html .= "<TD>$account</TD>";
+    }
+
+    $html .= '</TR>';
+
 }
 
   $html .= '</TABLE>';
@@ -290,7 +298,7 @@ END
 
 =head1 VERSION
 
-$Id: queue.pm,v 1.7 2002-03-07 14:10:10 ivan Exp $
+$Id: queue.pm,v 1.8 2002-03-23 16:16:00 ivan Exp $
 
 =head1 BUGS
 
index 9da5a66..bb6b995 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
@@ -289,6 +291,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 +577,16 @@ 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 $error = $self->SUPER::delete;
   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 ) {
+
+    foreach my $groupname ( @{$old->usergroup} ) {
+      if ( grep { $groupname eq $_ } @{$new->usergroup} ) {
+        $new->usergroup( [ grep { $groupname ne $_ } @{$new->usergroup} ] );
+        next;
+      }
+      my $radius_usergroup = qsearch('radius_usergroup', {
+        svcnum    => $old->svcnum,
+        groupname => $groupname,
+      } );
+      my $error = $radius_usergroup->delete;
+      if ( $error ) {
+        $dbh->rollback if $oldAutoCommit;
+        return "error deleting radius_usergroup $groupname: $error";
+      }
+    }
+
+    foreach my $groupname ( @{$new->usergroup} ) {
+      my $radius_usergroup = new FS::radius_usergroup ( {
+        svcnum    => $new->svcnum,
+        groupname => $groupname,
+      } );
+      my $error = $radius_usergroup->insert;
+      if ( $error ) {
+        $dbh->rollback if $oldAutoCommit;
+        return "error adding radius_usergroup $groupname: $error";
+      }
+    }
+
+  }
+
   #new-style exports!
   unless ( $noexport_hack ) {
     foreach my $part_export ( $new->cust_svc->part_svc->part_export ) {
@@ -1299,7 +1363,7 @@ sub radius_groups {
 
 =head1 SUBROUTINES
 
-=item radius_usergroup_selector GROUPS_ARRAYREF
+=item radius_usergroup_selector GROUPS_ARRAYREF [ SELECTNAME ]
 
 =cut
 
@@ -1323,6 +1387,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 +1395,12 @@ END
 
   foreach my $group ( @all_groups ) {
     $html .= '<OPTION';
-    $html .= ' SELECTED' if $sel_groups{$group};
+    $html .= ' SELECTED' if $sel_groups{$group}--;
     $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">!.
index 5e8a16f..950a860 100755 (executable)
@@ -20,12 +20,15 @@ if ( $cgi->param('_password') eq '*HIDDEN*' ) {
   $cgi->param('_password',$old->getfield('_password'));
 }
 
+#unmunge usergroup
+$cgi->param('usergroup', [ $cgi->param('radius_usergroup') ] );
+
 my $new = new FS::svc_acct ( {
   map {
     $_, scalar($cgi->param($_));
   #} qw(svcnum pkgnum svcpart username _password popnum uid gid finger dir
   #  shell quota slipip)
-  } ( fields('svc_acct'), qw( pkgnum svcpart ) )
+  } ( fields('svc_acct'), qw( pkgnum svcpart usergroup ) )
 } );
 
 my $error;
index 6846b5c..8a80d4c 100755 (executable)
@@ -4,7 +4,7 @@
 my $conf = new FS::Conf;
 my @shells = $conf->config('shells');
 
-my($svcnum, $pkgnum, $svcpart, $part_svc, $svc_acct);
+my($svcnum, $pkgnum, $svcpart, $part_svc, $svc_acct, @groups);
 if ( $cgi->param('error') ) {
   $svc_acct = new FS::svc_acct ( {
     map { $_, scalar($cgi->param($_)) } fields('svc_acct')
@@ -14,6 +14,7 @@ if ( $cgi->param('error') ) {
   $svcpart = $cgi->param('svcpart');
   $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
   die "No part_svc entry!" unless $part_svc;
+  @groups = $cgi->param('radius_usergroup');
 } else {
   my($query) = $cgi->keywords;
   if ( $query =~ /^(\d+)$/ ) { #editing
@@ -30,6 +31,8 @@ if ( $cgi->param('error') ) {
     $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
     die "No part_svc entry!" unless $part_svc;
 
+    @groups = $svc_acct->radius_groups;
+
   } else { #adding
 
     $svc_acct = new FS::svc_acct({}); 
@@ -63,6 +66,8 @@ if ( $cgi->param('error') ) {
                          );
     }
 
+    #SET DEFAULT GROUP(S) FROM PART_SVC!!!!
+
   }
 }
 my $action = $svcnum ? 'Edit' : 'Add';
@@ -100,7 +105,7 @@ print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
 print 'Service # '. ( $svcnum ? "<B>$svcnum</B>" : " (NEW)" ). '<BR>'.
       'Service: <B>'. $part_svc->svc. '</B><BR><BR>'.
       <<END;
-    <FORM ACTION="${p1}process/svc_acct.cgi" METHOD=POST>
+    <FORM NAME="OneTrueForm" ACTION="${p1}process/svc_acct.cgi" METHOD=POST>
       <INPUT TYPE="hidden" NAME="svcnum" VALUE="$svcnum">
       <INPUT TYPE="hidden" NAME="pkgnum" VALUE="$pkgnum">
       <INPUT TYPE="hidden" NAME="svcpart" VALUE="$svcpart">
@@ -240,7 +245,7 @@ foreach my $r ( grep { /^r(adius|[cr])_/ } fields('svc_acct') ) {
 }
 
 print '<TR><TD ALIGN="right">RADIUS groups</TD><TD>'.
-      &FS::svc_acct::radius_usergroup_selector( [ $svc_acct->radius_groups ] ).
+      &FS::svc_acct::radius_usergroup_selector( \@groups ).
       '</TD></TR>';
 
 #submit