[LON-CAPA-cvs] cvs: loncom /interface londropadd.pm

matthew lon-capa-cvs@mail.lon-capa.org
Tue, 30 Apr 2002 15:24:16 -0000


matthew		Tue Apr 30 11:24:16 2002 EDT

  Modified files:              
    /loncom/interface	londropadd.pm 
  Log:
  Fixed bug which prevented dropping of single students.
  Fixed bug which prevented dropping of students whose section begins with 
  whitespace.
  
  
Index: loncom/interface/londropadd.pm
diff -u loncom/interface/londropadd.pm:1.34 loncom/interface/londropadd.pm:1.35
--- loncom/interface/londropadd.pm:1.34	Tue Apr 30 09:51:00 2002
+++ loncom/interface/londropadd.pm	Tue Apr 30 11:24:16 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to drop and add students in courses 
 #
-# $Id: londropadd.pm,v 1.34 2002/04/30 13:51:00 matthew Exp $
+# $Id: londropadd.pm,v 1.35 2002/04/30 15:24:16 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -84,25 +84,32 @@
     my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
     my ($tmp) = keys(%roles);
     # Bail out if we were unable to get the students roles
-    return if ($tmp =~ /^(con_lost|error|no_such_host)/i);
+    return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
     # Go through the roles looking for enrollment in this course
+    my $result = '';
     foreach my $course (keys(%roles)) {
-        my $value = $roles{$course};
-        if ($course=~/^$courseid(?:\/)*(\w+)*\_st$/) {
+        if ($course=~/^$courseid(?:\/)*(?:\s+)*(\w+)*\_st$/) {
             # We are in this course
             my $section=$1;
             $section='' if ($course eq $courseid.'_st');
-            if (((!$section) && (!$csec)) || ($section ne $csec)) {
+            if ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
                 my (undef,$end,$start)=split(/\_/,$roles{$course});
                 my $now=time;
                 if (!($start && ($now<$start)) || !($end && ($now>$end))) {
                     my $reply=&Apache::lonnet::modifystudent
                         ($udom,$unam,'','','','','','','',
                          $section,time,undef,undef,$desiredhost);
+                    $result .= $reply.':';
                 }
             }
         }
     }
+    if ($result eq '') {
+        $result eq 'Unable to find section for this student';
+    } elsif ($result =~ /^(ok:)+$/) {
+        $result eq 'ok';
+    }
+    return $result;
 }
 
 # ============ build a domain and server selection form
@@ -939,10 +946,21 @@
 sub drop_student_list {
     my $r=shift;
     my $count=0;
-    foreach (@{$ENV{'form.droplist'}}) {
+    my @droplist;
+    if (ref($ENV{'form.droplist'})) {
+        @droplist = @{$ENV{'form.droplist'}};
+    } else {
+        @droplist = ($ENV{'form.droplist'});
+    }
+    foreach (@droplist) {
         my ($uname,$udom)=split(/\:/,$_);
-        &modifystudent($udom,$uname,$ENV{'request.course.id'});
-        $r->print('Dropped '.$uname.' at '.$udom.'<br>');
+        my $result = &modifystudent($udom,$uname,$ENV{'request.course.id'});
+        if ($result eq 'ok') {
+            $r->print('Dropped '.$uname.' at '.$udom.'<br>');
+        } else {
+            $r->print('Error dropping '.$uname.' at '.$udom.': '.$result.
+                      '<br />');
+        }
         $count++;
     }
     $r->print('<p><b>Dropped '.$count.' student(s).</b>');