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

raeburn lon-capa-cvs@mail.lon-capa.org
Sun, 02 Jul 2006 12:36:09 -0000


raeburn		Sun Jul  2 08:36:09 2006 EDT

  Modified files:              
    /loncom/interface	loncommon.pm 
  Log:
  &get_course_users() can provide appropriate information when the sections filter includes the reserved section terms 'all' or 'none'.  Call to &check_user_status() now correctly includes $usec information extracted from role key in nohist_userroles.db for non-student roles in a course.  Variable name $secgrp replaced with $sec in &check_user_status as groups are now distinct from sections.
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.411 loncom/interface/loncommon.pm:1.412
--- loncom/interface/loncommon.pm:1.411	Fri Jun 30 00:08:07 2006
+++ loncom/interface/loncommon.pm	Sun Jul  2 08:36:08 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.411 2006/06/30 04:08:07 albertel Exp $
+# $Id: loncommon.pm,v 1.412 2006/07/02 12:36:08 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3898,33 +3898,35 @@
 =cut
 
 sub check_user_status {
-    my ($udom,$uname,$cdom,$crs,$role,$secgrp) = @_;
+    my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
     my @uroles = keys %userinfo;
     my $srchstr;
     my $active_chk = 'none';
+    my $now = time;
     if (@uroles > 0) {
-        if (($role eq 'cc') || ($secgrp eq '') || (!defined($secgrp))) {
+        if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
         } else {
-            $srchstr = '/'.$cdom.'/'.$crs.'/'.$secgrp.'_'.$role;         }
-        if (grep/^$srchstr$/,@uroles) {
+            $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
+        }
+        if (grep/^\Q$srchstr\E$/,@uroles) {
             my $role_end = 0;
             my $role_start = 0;
             $active_chk = 'active';
-            if ($userinfo{$srchstr} =~ m/^($role)_(\d+)/) {
-                $role_end = $2;
-                if ($userinfo{$srchstr} =~ m/^($role)_($role_end)_(\d+)$/) {
-                    $role_start = $3;
+            if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
+                $role_end = $1;
+                if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
+                    $role_start = $1;
                 }
             }
             if ($role_start > 0) {
-                if (time < $role_start) {
+                if ($now < $role_start) {
                     $active_chk = 'future';
                 }
             }
             if ($role_end > 0) {
-                if (time > $role_end) {
+                if ($now > $role_end) {
                     $active_chk = 'previous';
                 }
             }
@@ -4044,11 +4046,23 @@
         my $now = time;
         foreach my $student (keys(%{$classlist})) {
             my $match = 0;
+            my $secmatch = 0;
             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
-		unless(grep(/^\Q$$classlist{$student}[$idx{section}]\E$/,
+                if (grep/^all$/,@{$sections}) {
+                    $secmatch = 1;
+                } elsif ($$classlist{$student}[$idx{section}] eq '') {
+                    if (grep/^none$/,@{$sections}) {
+                        $secmatch = 1;
+                    }
+                } else {  
+		    if (grep(/^\Q$$classlist{$student}[$idx{section}]\E$/,
 			    @{$sections})) {
-		    next;
+		        $secmatch = 1;
+                    }
 		}
+                if (!$secmatch) {
+                    next;
+                }
             } 
             if (defined($$types{'active'})) {
                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
@@ -4068,35 +4082,47 @@
                     $match = 1;
                 }
             }
-            if ($match && defined($userdata)) {
+            if ($match && ref($userdata) eq 'HASH') {
                 $$userdata{$student} = $$classlist{$student};
             }
         }
     }
-    if ((@{$roles} > 0) && (@{$roles} ne "st")) {
+    if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
         my @coursepersonnel = &Apache::lonnet::getkeys('nohist_userroles',$cdom,$cnum);
         foreach my $person (@coursepersonnel) {
             my $match = 0;
-            my ($role,$user) = ($person =~ /^([^:]*):([^:]+:[^:]+)/);
+            my $secmatch = 0;
+            my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
             $user =~ s/:$//;
             if (($role) && (grep(/^\Q$role\E$/,@{$roles}))) {
-                my ($uname,$udom,$usec) = split(/:/,$user);
-                if ($usec ne '' && (ref($sections) eq 'ARRAY') && 
-		    @{$sections} > 0) {
-		    unless(grep(/^\Q$usec\E$/,@{$sections})) {
-			next;
-		    }
+                my ($uname,$udom) = split(/:/,$user);
+                if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
+                    if (grep/^all$/,@{$sections}) {
+                        $secmatch = 1;
+                    } elsif ($usec eq '') {
+                        if (grep/^none$/,@{$sections}) {
+                            $secmatch = 1;
+                        }
+                    } else {
+                        if (grep(/^\Q$usec\E$/,@{$sections})) {
+                            $secmatch = 1;
+                        }
+                    }
+                    if (!$secmatch) {
+                        next;
+                    }
                 }
                 if ($uname ne '' && $udom ne '') {
-                    my $status = &check_user_status($udom,$uname,$cdom,$cnum,$role);
+                    my $status = &check_user_status($udom,$uname,$cdom,$cnum,$role,
+                                                    $usec);
                     foreach my $type (keys(%{$types})) { 
                         if ($status eq $type) {
                             @{$$users{$role}{$user}} = $type;
                             $match = 1;
                         }
                     }
-                    if ($match && defined($userdata) &&
-                        !exists($$userdata{$uname.':'.$udom})) {
+                    if (($match) && (ref($userdata) eq 'HASH') &&
+                        (!exists($$userdata{$uname.':'.$udom}))) {
 			&get_user_info($udom,$uname,\%idx,$userdata);
                     }
                 }