--- loncom/interface/longroup.pm 2006/06/30 18:27:19 1.7 +++ loncom/interface/longroup.pm 2006/12/20 22:37:04 1.15 @@ -40,14 +40,17 @@ Input: 1. Optional course domain 2. Optional course number 3. Optional group name +4. Optional namespace Course domain and number will be taken from user's environment if not supplied. Optional group name will -be passed to lonnet::get_coursegroups() as a regexp to -use in the call to the dump function. +be passed to lonnet function as a regexp to +use in the call to the dump function. Optional namespace +will determine whether information is retrieved about current +groups (default) or deleted groups (namespace = deleted_groups). Output -Returns hash of groups in the course (subject to the +Returns hash of groups in a course (subject to the optional group name filter). In the hash, the keys are group names, and their corresponding values are scalars containing group information in XML. This @@ -55,12 +58,13 @@ can be sent to &get_group_settings() to Side effects: None. + =cut ############################################### sub coursegroups { - my ($cdom,$cnum,$group) = @_; + my ($cdom,$cnum,$group,$namespace) = @_; if (!defined($cdom) || !defined($cnum)) { my $cid = $env{'request.course.id'}; @@ -69,16 +73,25 @@ sub coursegroups { $cdom = $env{'course.'.$cid.'.domain'}; $cnum = $env{'course.'.$cid.'.num'}; } - my %curr_groups = &Apache::lonnet::get_coursegroups($cdom,$cnum,$group); - if (my $tmp = &Apache::lonnet::error(%curr_groups)) { - undef(%curr_groups); - &Apache::lonnet::logthis('Error retrieving groups: '.$tmp.' in '.$cnum.':'.$cdom); + if (!defined($namespace)) { + $namespace = 'coursegroups'; + } + my %groups = &Apache::lonnet::get_coursegroups($cdom,$cnum,$group, + $namespace); + if (my $tmp = &Apache::lonnet::error(%groups)) { + undef(%groups); + &Apache::lonnet::logthis('Error retrieving groups: '.$tmp.' in '.$cnum.':'.$cdom.' - '.$namespace); + } + if (defined($groups{'group_allfolders'."\0".'locked_folder'})) { + delete($groups{'group_allfolders'."\0".'locked_folder'}); } - return %curr_groups; + return %groups; } ############################################### +=pod + =item get_group_settings Uses TokeParser to extract group information from the @@ -415,6 +428,162 @@ sub group_changes { ############################################### +sub get_fixed_privs { + my $fixedprivs = { + email => {sgm => 1}, + discussion => {vgb => 1}, + chat => {pgc => 1}, + files => {rgf => 1}, + roster => {vgm => 1}, + homepage => {vgh => 1}, + }; + return $fixedprivs; +} + +############################################### + +sub get_tool_privs { + my ($gpterm) = @_; + my $toolprivs = { + email => { + sgm => 'Send '.$gpterm.' mail', + sgb => 'Broadcast mail', + }, + discussion => { + cgb => 'Create boards', + pgd => 'Post', + egp => 'Edit own posts', + dgp => 'Hide/Delete any post', + vgb => 'View boards', + }, + chat => { + pgc => 'Chat', + }, + files => { + rgf => 'Retrieve', + ugf => 'Upload', + mgf => 'Modify', + dgf => 'Delete', + agf => 'Control Access', + }, + roster => { + vgm => 'Basic Display', + vmd => 'Detailed Display', + }, + homepage => { + vgh => 'View page', + mgh => 'Modify page', + }, + }; + return $toolprivs; +} + +############################################### + + +sub group_memberlist { + my ($cdom,$cnum,$groupname,$fixedprivs,$available) = @_; + my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum, + $groupname); + my %current = (); + my $hastools = 0; + my $addtools = 0; + my %member_nums = ( + 'previous' => 0, + 'future' => 0, + 'active' => 0, + ); + my $now = time; + if (keys(%membership) > 0) { + my %allnames = (); + foreach my $key (sort(keys(%membership))) { + if ($key =~ /^\Q$groupname\E:([^:]+):([^:]+)$/) { + my $uname = $1; + my $udom = $2; + my $user = $uname.':'.$udom; + my($end,$start,@userprivs) = split(/:/,$membership{$key}); + unless ($start == -1) { + $allnames{$udom}{$uname} = 1; + $current{$user} = { + uname => $uname, + udom => $udom, + start => &Apache::lonlocal::locallocaltime($start), + currtools => [], + newtools => [], + privs => \@userprivs, + }; + + if ($end == 0) { + $current{$user}{end} = 'No end date'; + } else { + $current{$user}{end} = + &Apache::lonlocal::locallocaltime($end); + } + my $now = time; + if (($end > 0) && ($end < $now)) { + $current{$user}{changestate} = 'reenable'; + $current{$user}{'status'} = 'previous'; + $member_nums{'previous'} ++; + } elsif (($start > $now)) { + $current{$user}{changestate} = 'activate'; + $current{$user}{'status'} = 'future'; + $member_nums{'future'} ++; + } else { + $current{$user}{changestate} = 'expire'; + $current{$user}{'status'} = 'active'; + $member_nums{'active'} ++; + } + if ((@userprivs > 0) && (ref($fixedprivs) eq 'HASH')) { + foreach my $tool (sort(keys(%{$fixedprivs}))) { + foreach my $priv (keys(%{$$fixedprivs{$tool}})) { + if (grep/^$priv$/,@userprivs) { + push(@{$current{$user}{currtools}},$tool); + last; + } + } + } + $hastools = 1; + } + if ((ref($available) eq 'ARRAY') && (@{$available} > 0)) { + if (@{$current{$user}{currtools}} > 0) { + if ("@{$available}" ne "@{$current{$user}{currtools}}") { + foreach my $tool (@{$available}) { + unless (grep/^$tool$/,@{$current{$user}{currtools}}) { + push(@{$current{$user}{newtools}},$tool); } + } + } + } else { + @{$current{$user}{newtools}} = @{$available}; + + } + if (@{$current{$user}{newtools}} > 0) { + $addtools = 1; + } + } + } + } + } + if (keys(%current) > 0) { + my %idhash; + foreach my $udom (keys(%allnames)) { + %{$idhash{$udom}} = &Apache::lonnet::idrget($udom, + keys(%{$allnames{$udom}})); + foreach my $uname (keys(%{$idhash{$udom}})) { + $current{$uname.':'.$udom}{'id'} = $idhash{$udom}{$uname}; + } + foreach my $uname (keys(%{$allnames{$udom}})) { + $current{$uname.':'.$udom}{'fullname'} = + &Apache::loncommon::plainname($uname,$udom, + 'lastname'); + } + } + } + } + return (\%current,\%member_nums,$hastools,$addtools); +} + +############################################### + sub sum_quotas { my ($courseid) = @_; my $totalquotas = 0; @@ -457,11 +626,8 @@ sub get_bbfolder_url { my %curr_groups = &coursegroups($cdom,$cnum,$group); my $grpbbmap; if (%curr_groups) { - my %group_info = &get_group_settings($curr_groups{$group}); - my $creation = $group_info{'creation'}; - my $bbfolder = $creation + 1; my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/'; - $grpbbmap = $crspath.'default_'.$bbfolder.'.sequence'; + $grpbbmap = $crspath.'group_boards_'.$group.'.sequence'; } return $grpbbmap; } @@ -469,7 +635,7 @@ sub get_bbfolder_url { ############################################### sub get_group_bbinfo { - my ($cdom,$cnum,$group) = @_; + my ($cdom,$cnum,$group,$boardurl) = @_; my $navmap = Apache::lonnavmaps::navmap->new(); my @groupboards; my %boardshash; @@ -480,12 +646,23 @@ sub get_group_bbinfo { my @boards = $navmap->retrieveResources($bbfolderres,undef,0,0); foreach my $res (@boards) { my $url = $res->src(); - if ($url =~ m|^/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard|) { - push(@groupboards,$res->symb()); - $boardshash{$res->symb()} = { - title => $res->title(), - url => $res->src(), - }; + if ($url =~ m|^(/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard)|) { + if ($boardurl) { + if ($boardurl =~ /^\Q$1\E/) { + push(@groupboards,$res->symb()); + $boardshash{$res->symb()} = { + title => $res->title(), + url => $res->src(), + }; + last; + } + } else { + push(@groupboards,$res->symb()); + $boardshash{$res->symb()} = { + title => $res->title(), + url => $res->src(), + }; + } } } }