--- loncom/lonnet/perl/lonnet.pm 2006/04/26 15:47:38 1.732 +++ loncom/lonnet/perl/lonnet.pm 2006/05/01 06:17:32 1.733 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.732 2006/04/26 15:47:38 albertel Exp $ +# $Id: lonnet.pm,v 1.733 2006/05/01 06:17:32 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -4016,31 +4016,51 @@ sub get_group_membership { sub get_users_groups { my ($udom,$uname,$courseid) = @_; + my @usersgroups; my $cachetime=1800; $courseid=~s/\_/\//g; $courseid=~s/^(\w)/\/$1/; my $hashid="$udom:$uname:$courseid"; - my ($result,$cached)=&is_cached_new('getgroups',$hashid); - if (defined($cached)) { return $result; } - - my %roleshash = &dump('roles',$udom,$uname,$courseid); - my ($tmp) = keys(%roleshash); - if ($tmp=~/^error:/) { - &logthis('Error retrieving roles: '.$tmp.' for '.$uname.':'.$udom); - return ''; - } else { - my $grouplist; - foreach my $key (keys %roleshash) { - if ($key =~ /^\Q$courseid\E\/(\w+)\_gr$/) { - unless ($roleshash{$key} =~ /_\d+_\-1$/) { # deleted membership - $grouplist .= $1.':'; + my ($grouplist,$cached)=&is_cached_new('getgroups',$hashid); + if (defined($cached)) { + @usersgroups = split/:/,$grouplist; + } else { + $grouplist = ''; + my %roleshash = &dump('roles',$udom,$uname,$courseid); + my ($tmp) = keys(%roleshash); + if ($tmp=~/^error:/) { + &logthis('Error retrieving roles: '.$tmp.' for '.$uname.':'.$udom); + } else { + my $access_end = $env{'course.'.$courseid. + '.default_enrollment_end_date'}; + my $now = time; + foreach my $key (keys %roleshash) { + if ($key =~ /^\Q$courseid\E\/(\w+)\_gr$/) { + my $group = $1; + if ($roleshash{$key} =~ /_(\d+)_(\d+)$/) { + my $start = $2; + my $end = $1; + if ($start == -1) { next; } # deleted from group + if (($start!=0) && ($start>$now)) { next; } + if (($end!=0) && ($end<$now)) { + if ($access_end && $access_end < $now) { + if ($access_end - $end < 86400) { + push(@usersgroups,$group); + } + } + next; + } + push(@usersgroups,$group); + } } } + @usersgroups = &sort_course_groups($courseid,@usersgroups); + $grouplist = join(':',@usersgroups); + &do_cache_new('getgroups',$hashid,$grouplist,$cachetime); } - $grouplist =~ s/:$//; - return &do_cache_new('getgroups',$hashid,$grouplist,$cachetime); } + return @usersgroups; } sub devalidate_getgroups_cache { @@ -5159,17 +5179,15 @@ sub EXT { if (($env{'user.name'} eq $uname) && ($env{'user.domain'} eq $udom)) { $section=$env{'request.course.sec'}; - @groups=&sort_course_groups($env{'request.course.groups'},$courseid); + @groups = split(/:/,$env{'request.course.groups'}); + @groups=&sort_course_groups($courseid,@groups); } else { if (! defined($usection)) { $section=&getsection($udom,$uname,$courseid); } else { $section = $usection; } - my $grouplist = &get_users_groups($udom,$uname,$courseid); - if ($grouplist) { - @groups=&sort_course_groups($grouplist,$courseid); - } + @groups = &get_users_groups($udom,$uname,$courseid); } my $seclevel=$courseid.'.['.$section.'].'.$spacequalifierrest; @@ -5293,8 +5311,8 @@ sub check_group_parms { } sub sort_course_groups { # Sort groups based on defined rankings. Default is sort(). - my ($grouplist,$courseid) = @_; - my @groups = sort(split(/:/,$grouplist)); + my ($courseid,@groups) = @_; + @groups = sort(@groups); return @groups; }