File:  [LON-CAPA] / loncom / interface / longroup.pm
Revision 1.16: download - view: text, annotated - select for diffs
Thu May 1 16:26:29 2008 UTC (16 years ago) by raeburn
Branches: MAIN
CVS tags: version_2_7_X, version_2_7_1, version_2_7_0, version_2_6_99_1, version_2_6_99_0, HEAD
&group_changes() can take extra arguments - selfenroll and context, to be stored in record for membership changes in nohist_groupslog.db

    1: # The LearningOnline Network with CAPA
    2: # accessor routines used to provide information about course groups 
    3: #
    4: # Copyright Michigan State University Board of Trustees
    5: #
    6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    7: #
    8: # LON-CAPA is free software; you can redistribute it and/or modify
    9: # it under the terms of the GNU General Public License as published by
   10: # the Free Software Foundation; either version 2 of the License, or
   11: # (at your option) any later version.
   12: #
   13: # LON-CAPA is distributed in the hope that it will be useful,
   14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16: # GNU General Public License for more details.
   17: #
   18: # You should have received a copy of the GNU General Public License
   19: # along with LON-CAPA; if not, write to the Free Software
   20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21: #
   22: # /home/httpd/html/adm/gpl.txt
   23: #
   24: # http://www.lon-capa.org/
   25: #
   26: 
   27: package Apache::longroup;
   28: 
   29: use strict;
   30: use Apache::lonnet;
   31: 
   32: ###############################################
   33: =pod
   34: 
   35: =item coursegroups
   36: 
   37: Retrieve information about groups in a course,
   38: 
   39: Input:
   40: 1. Optional course domain
   41: 2. Optional course number
   42: 3. Optional group name
   43: 4. Optional namespace
   44: 
   45: Course domain and number will be taken from user's
   46: environment if not supplied. Optional group name will 
   47: be passed to lonnet function as a regexp to
   48: use in the call to the dump function.  Optional namespace
   49: will determine whether information is retrieved about current 
   50: groups (default) or deleted groups (namespace = deleted_groups). 
   51: 
   52: Output
   53: Returns hash of groups in a course (subject to the
   54: optional group name filter). In the hash, the keys are
   55: group names, and their corresponding values
   56: are scalars containing group information in XML. This
   57: can be sent to &get_group_settings() to be parsed.
   58: 
   59: Side effects:
   60: None.
   61: 
   62: =cut
   63: 
   64: ###############################################
   65: 
   66: sub coursegroups {
   67:     my ($cdom,$cnum,$group,$namespace) = @_;
   68:     if (!defined($cdom) || !defined($cnum)) {
   69:         my $cid =  $env{'request.course.id'};
   70: 
   71:         return if (!defined($cid));
   72: 
   73:         $cdom = $env{'course.'.$cid.'.domain'};
   74:         $cnum = $env{'course.'.$cid.'.num'};
   75:     }
   76:     if (!defined($namespace)) {
   77:         $namespace = 'coursegroups';
   78:     } 
   79:     my %groups =  &Apache::lonnet::get_coursegroups($cdom,$cnum,$group,
   80:                                                     $namespace);
   81:     if (my $tmp = &Apache::lonnet::error(%groups)) {
   82: 	undef(%groups);
   83:         &Apache::lonnet::logthis('Error retrieving groups: '.$tmp.' in '.$cnum.':'.$cdom.' - '.$namespace);
   84:     }
   85:     if (defined($groups{'group_allfolders'."\0".'locked_folder'})) {
   86:         delete($groups{'group_allfolders'."\0".'locked_folder'}); 
   87:     }
   88:     return %groups;
   89: }
   90: 
   91: ###############################################
   92: 
   93: =pod 
   94: 
   95: =item get_group_settings
   96: 
   97: Uses TokeParser to extract group information from the
   98: XML used to describe course groups.
   99: 
  100: Input:
  101: Scalar containing XML  - as retrieved from &coursegroups().
  102: 
  103: Output:
  104: Hash containing group information as key=values for (a), and
  105: hash of hashes for (b)
  106: 
  107: Keys (in two categories):
  108: (a) groupname, creator, creation, modified, startdate, enddate, quota.
  109: Corresponding values are name of the group, creator of the group
  110: (username:domain), UNIX time for date group was created, and
  111: settings were last modified, file quota, and default start and end 
  112: access times for group members.
  113: 
  114: (b) functions returned in hash of hashes.
  115: Outer hash key is functions.
  116: Inner hash keys are chat,discussion,email,files,homepage,roster.
  117: Corresponding values are either on or off, depending on
  118: whether this type of functionality is available for the group.
  119: 
  120: =cut
  121: 
  122: ###############################################
  123: 
  124: sub get_group_settings {
  125:     my ($groupinfo)=@_;
  126:     my $parser=HTML::TokeParser->new(\$groupinfo);
  127:     my $token;
  128:     my $tool = '';
  129:     my $role = '';
  130:     my %content=();
  131:     while ($token=$parser->get_token) {
  132:         if ($token->[0] eq 'S')  {
  133:             my $entry=$token->[1];
  134:             if ($entry eq 'functions' || $entry eq 'autosec') {
  135:                 %{$content{$entry}} = ();
  136:                 $tool = $entry;
  137:             } elsif ($entry eq 'role') {
  138:                 if ($tool eq 'autosec') {
  139:                     $role = $token->[2]{id};
  140:                     @{$content{$tool}{$role}} = ();
  141:                 }
  142:             } else {
  143:                 my $value=$parser->get_text('/'.$entry);
  144:                 if ($entry eq 'name') {
  145:                     if ($tool eq 'functions') {
  146:                         my $function = $token->[2]{id};
  147:                         $content{$tool}{$function} = $value;
  148:                     }
  149:                 } elsif ($entry eq 'groupname') {
  150:                     $content{$entry}=&unescape($value);
  151:                 } elsif (($entry eq 'roles') || ($entry eq 'types') ||
  152:                          ($entry eq 'sectionpick') || ($entry eq 'defpriv')) {
  153:                     push(@{$content{$entry}},$value);
  154:                 } elsif ($entry eq 'section') {
  155:                     if ($tool eq 'autosec'  && $role ne '') {
  156:                         push(@{$content{$tool}{$role}},$value);
  157:                     }
  158:                 } else {
  159:                     $content{$entry}=$value;
  160:                 }
  161:             }
  162:         } elsif ($token->[0] eq 'E') {
  163:             if ($token->[1] eq 'functions' || $token->[1] eq 'autosec') {
  164:                 $tool = '';
  165:             } elsif ($token->[1] eq 'role') {
  166:                 $role = '';
  167:             }
  168:         }
  169:     }
  170:     return %content;
  171: }
  172: 
  173: ###############################################
  174: 
  175: sub check_group_access {
  176:     my ($group) = @_;
  177:     my $access = 1;
  178:     my $now = time;
  179:     my ($start,$end) = split(/\./,$env{'user.role.gr/'.$env{'request.course,id'}.'/'.$group});
  180:     if (($end!=0) && ($end<$now)) { $access = 0; }
  181:     if (($start!=0) && ($start>$now)) { $access=0; }
  182:     return $access;
  183: }
  184: 
  185: ###############################################
  186: 
  187: =pod
  188: 
  189: =item group_changes
  190: 
  191: Add or drop group memberships in a course as a result of
  192: changes in a user's roles/sections. Called by
  193: &Apache::lonnet:assignrole()     
  194: 
  195: Input:
  196: 1. User's domain
  197: 2. User's username
  198: 3. Url of role
  199: 4. Role
  200: 5. End date of role
  201: 6. Start date of role
  202: 7. Selfenroll
  203: 8. Context
  204: 
  205: Checks to see if role for which assignment is being made is in a course.
  206: If so, gathers information about auto-group population settings for
  207: groups in the course.
  208: 
  209: If role is being expired, will also expire any group memberships that
  210: are specified for auto-group population for the specific role and
  211: section (including section 'none' and 'all' sections), unless a
  212: different role/section also included in auto-group population
  213: for the course is included amongst the user's unexpired roles
  214: and would trigger membership in teh same group(s) 
  215: 
  216: If role is being added, will add any group memberships specified
  217: for auto-group population, unless use is already a group member.
  218: Uses default group privileges and default start and end group access
  219: times.
  220: 
  221: Flag for selfenroll (value of 1), and context (auto, updatenow, 
  222: automated, course, domain etc.) can be used to log the reason for
  223: the role change.     
  224: 
  225: Output
  226: None
  227: 
  228: Side effects:
  229: May result in calls to Apache::lonnet::modify_group_roles()
  230: and Apache::lonnet::modify_coursegroup_membership() to add
  231: or expire group membership(s) for a user. 
  232: 
  233: =cut
  234: 
  235: sub group_changes {
  236:     my ($udom,$uname,$url,$role,$origend,$origstart,$selfenroll,$context) = @_;
  237:     my $now = time;
  238:     my $chgtype;
  239:     if ($origend > 0 && $origend <= $now) {
  240:         $chgtype = 'drop';
  241:     } else {
  242:         $chgtype = 'add';
  243:     }
  244:     my ($cid,$cdom,$cnum,$sec);
  245:     if ($url =~ m-^(/[^/]+/[^/]+)/([^/]+)$-) {
  246:         $cid = $1;
  247:         $sec = $2;
  248:     } else {
  249:         $cid = $url;
  250:     }
  251:     my $courseid = $cid;
  252:     $courseid =~ s|^/||;
  253:     $courseid =~ s|/|_|;
  254:     my %crshash=&Apache::lonnet::coursedescription($cid);
  255:     $cdom = $crshash{'domain'};
  256:     $cnum = $crshash{'num'};
  257:     if (defined($cdom) && defined($cnum)) {
  258:         my %settings;
  259:         my @changegroups = ();
  260:         my %dropgroup = ();
  261:         my %dropstart = ();
  262:         my %addgroup = ();
  263:         my %curr_groups = &coursegroups($cdom,$cnum);
  264:         if (%curr_groups) {
  265:             foreach my $group (keys(%curr_groups)) {
  266:                 %{$settings{$group}}=&get_group_settings($curr_groups{$group});
  267:                 if ($chgtype eq 'add') {
  268:                     if (!($settings{$group}{autoadd} eq 'on')) {
  269:                         next;
  270:                     }
  271:                 } else {
  272:                     if (!($settings{$group}{autodrop} eq 'on')) {
  273:                         next;
  274:                     }
  275:                 }
  276:                 my @autosec = ();
  277:                 if (ref($settings{$group}{'autosec'}{$role}) eq 'ARRAY') {
  278:                     @autosec = @{$settings{$group}{'autosec'}{$role}};
  279:                 }
  280:                 if ($sec eq '') {
  281:                     $sec = 'none';
  282:                 }
  283:                 if ((grep(/^$sec$/,@autosec)) || (grep(/^all$/,@autosec))) {
  284:                     push(@changegroups,$group);
  285:                 }
  286:             }
  287:         }
  288:        if (@changegroups > 0) {
  289:             my %currpriv;
  290:             my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname,$cid);
  291: 	    if (my $tmp = &Apache::lonnet::error(%roleshash)) {
  292:                 &Apache::lonnet::logthis('Error retrieving roles: '.$tmp.
  293:                                          ' for '.$uname.':'.$udom);
  294:             } else {
  295:                 my $group_privs = '';
  296:                 foreach my $group (@changegroups) {
  297:                     if ($chgtype eq 'add') {
  298:                         if (ref($settings{$group}{'defpriv'}) eq 'ARRAY') {
  299:                             $group_privs =
  300:                                   join(':',@{$settings{$group}{'defpriv'}});
  301:                         }
  302:                     }
  303:                     my $key = $cid.'/'.$group.'_gr';
  304:                     if (defined($roleshash{$key})) {
  305:                         if ($roleshash{$key}=~ /^gr\/([^_]*)_(\d+)_([\-\d]+)$/) {
  306:                             my $grpstart = $3;
  307:                             my $grpend = $2;
  308:                             $currpriv{$group} = $1;
  309:                             if ($chgtype eq 'drop') {
  310:                                 if ($grpstart == -1) { next; } # deleted
  311:                                 if ($grpend == 0 || $grpend > $now) {
  312:                                     if (!defined($dropgroup{$group})) {
  313:                                         $dropstart{$group} = $grpstart;
  314:                                         if ($grpstart > $now) {
  315:                                             $dropstart{$group} = $now;
  316:                                         }
  317:                                         $dropgroup{$group} = $now.':'.
  318:                                                             $dropstart{$group}.
  319:                                                          ':'.$currpriv{$group};
  320:                                     }
  321:                                 }
  322:                             } elsif ($chgtype eq 'add') {
  323:                                 if (($grpstart == -1) || ($grpend > 0 &&
  324:                                      ($grpend < $settings{$group}{'enddate'} ||
  325:                                       $settings{$group}{'enddate'} == 0)) ||
  326:                                      ($grpstart > $settings{$group}{'startdate'})) {
  327:                                     if (!defined($addgroup{$group})) {
  328:                                         $addgroup{$group} =
  329:                                             $settings{$group}{'enddate'}.':'.
  330:                                             $settings{$group}{'startdate'}.':'.
  331:                                             $group_privs;
  332:                                     }
  333:                                 }
  334:                             }
  335:                         }
  336:                     } elsif ($chgtype eq 'add') {
  337:                         $addgroup{$group} = $settings{$group}{'enddate'}.':'.
  338:                                             $settings{$group}{'startdate'}.':'.
  339:                                             $group_privs;
  340:                     }
  341:                 }
  342:                 if ($chgtype eq 'add') {
  343:                     foreach my $add (keys(%addgroup)) {
  344:                         if (&Apache::lonnet::modify_group_roles($cdom,$cnum,
  345:                                                   $add,$uname.':'.$udom,
  346:                                                   $settings{$add}{'enddate'},
  347:                                                   $settings{$add}{'startdate'},
  348:                                                   $group_privs,$selfenroll,$context) eq 'ok') {
  349:                             my %usersettings;
  350:                             $usersettings{$add.':'.$uname.':'.$udom} =
  351:                                                                $addgroup{$add};
  352:                             my $roster_result =
  353:                                &Apache::lonnet::modify_coursegroup_membership(
  354:                                                    $cdom,$cnum,\%usersettings);
  355:                         }
  356:                     }
  357:                 } elsif ($chgtype eq 'drop') {
  358:                     foreach my $drop (keys(%dropgroup)) {
  359:                         my $nodrop = 0;
  360:                         if ($settings{$drop}{'autoadd'} eq 'on') {
  361:                             foreach my $urole (keys(%{$settings{$drop}{'autosec'}})) {
  362:                                 if ($nodrop) {
  363:                                     last;
  364:                                 } else {
  365:                                     my @autosec = ();
  366:                                     if (ref($settings{$drop}{'autosec'}{$urole}) eq 'ARRAY') {
  367:                                         @autosec = @{$settings{$drop}{'autosec'}{$urole}};
  368:                                     }
  369:                                     foreach my $usec (@autosec) {
  370:                                         if ($usec eq 'all') {
  371:                                             foreach my $ukey (keys(%roleshash)) {
  372:                                                 if ($ukey =~ /^\Q$cid\E(\/?\w*)_($urole)$/) {
  373:                                                     if ($sec ne $1) {
  374:                                                         if ($roleshash{$ukey} =~ /_?(\d*)_?([\-\d]*)$/) {
  375:                                                             my $roleend = $1;
  376:                                                             if ((!$roleend) ||
  377:                                                                 ($roleend > $now)) {
  378:                                                                 $nodrop = 1;
  379:                                                                 last;
  380:                                                             }
  381:                                                         }
  382:                                                     }
  383:                                                 }
  384:                                             }
  385:                                         } else {
  386:                                             my $ukey = $cid.'/'.$usec.'_'.$urole;
  387:                                             if ($usec eq 'none') {
  388:                                                 if ($sec eq '') {
  389:                                                     next;
  390:                                                 }
  391:                                             } else {
  392:                                                 if ($usec eq $sec) {
  393:                                                     next;
  394:                                                 }
  395:                                             }
  396:                                             if (exists($roleshash{$ukey})) {
  397:                                                 if ($roleshash{$ukey} =~
  398:                                                        /_?(\d*)_?([\-\d]*)$/) {
  399:                                                     my $roleend = $1;
  400:                                                     if ((!$roleend) ||
  401:                                                         ($roleend > $now)) {
  402:                                                         $nodrop = 1;
  403:                                                         last;
  404:                                                     }
  405:                                                 }
  406:                                             }
  407:                                         }
  408:                                     }
  409:                                 }
  410:                             }
  411:                         }
  412:                         if (!$nodrop) {
  413:                             if (&Apache::lonnet::modify_group_roles($cdom,
  414:                                                          $cnum,$drop,
  415:                                                          $uname.':'.$udom,$now,
  416:                                                          $dropstart{$drop},
  417:                                                          $currpriv{$drop},
  418:                                                          $selfenroll,$context) 
  419:                                                                      eq 'ok') {
  420:                                 my %usersettings;
  421:                                 $usersettings{$drop.':'.$uname.':'.$udom} =
  422:                                                              $dropgroup{$drop};
  423:                                 my $roster_result =
  424:                                 &Apache::lonnet::modify_coursegroup_membership(
  425:                                                    $cdom,$cnum,\%usersettings);
  426:                             }
  427:                         }
  428:                     }
  429:                 }
  430:             }
  431:         }
  432:     }
  433:     return;
  434: }
  435: 
  436: ###############################################
  437: 
  438: sub get_fixed_privs {
  439:     my $fixedprivs = {
  440:                       email      => {sgm => 1},
  441:                       discussion => {vgb => 1},
  442:                       chat       => {pgc => 1},
  443:                       files      => {rgf => 1},
  444:                       roster     => {vgm => 1},
  445:                       homepage   => {vgh => 1},
  446:                      };
  447:     return $fixedprivs;
  448: }
  449: 
  450: ###############################################
  451: 
  452: sub get_tool_privs {
  453:     my ($gpterm) = @_;
  454:     my $toolprivs = {
  455:         email      => {
  456:             sgm => 'Send '.$gpterm.' mail',
  457:             sgb => 'Broadcast mail',
  458:         },
  459:         discussion => {
  460:             cgb => 'Create boards',
  461:             pgd => 'Post',
  462:             egp => 'Edit own posts',
  463:             dgp => 'Hide/Delete any post',
  464:             vgb => 'View boards',
  465:         },
  466:         chat       => {
  467:             pgc => 'Chat',
  468:         },
  469:         files      => {
  470:             rgf => 'Retrieve',
  471:             ugf => 'Upload',
  472:             mgf => 'Modify',
  473:             dgf => 'Delete',
  474:             agf => 'Control Access',
  475:         },
  476:         roster     => {
  477:             vgm => 'Basic Display',
  478:             vmd => 'Detailed Display',
  479:         },
  480:         homepage   => {
  481:             vgh => 'View page',
  482:             mgh => 'Modify page',
  483:         },
  484:     };
  485:     return $toolprivs;
  486: }
  487: 
  488: ###############################################
  489: 
  490: 
  491: sub group_memberlist {
  492:     my ($cdom,$cnum,$groupname,$fixedprivs,$available) = @_;
  493:     my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
  494:                                                            $groupname);
  495:     my %current = ();
  496:     my $hastools = 0;
  497:     my $addtools = 0;
  498:     my %member_nums = (
  499:                         'previous' => 0,
  500:                         'future' => 0,
  501:                         'active' => 0,
  502:                       );
  503:     my $now = time;
  504:     if (keys(%membership) > 0) {
  505:         my %allnames = ();
  506:         foreach my $key (sort(keys(%membership))) {
  507:             if ($key =~ /^\Q$groupname\E:([^:]+):([^:]+)$/) {
  508:                 my $uname = $1;
  509:                 my $udom = $2;
  510:                 my $user = $uname.':'.$udom;
  511:                 my($end,$start,@userprivs) = split(/:/,$membership{$key});
  512:                 unless ($start == -1) {
  513:                     $allnames{$udom}{$uname} = 1;
  514:                     $current{$user} = {
  515:                         uname     => $uname,
  516:                         udom      => $udom,
  517:                         start     => &Apache::lonlocal::locallocaltime($start),
  518:                         currtools => [],
  519:                         newtools  => [],
  520:                         privs     => \@userprivs,
  521:                     };
  522: 
  523:                     if ($end == 0) {
  524:                         $current{$user}{end} =  'No end date';
  525:                     } else {
  526:                         $current{$user}{end} =
  527:                                      &Apache::lonlocal::locallocaltime($end);
  528:                     }
  529:                     my $now = time;
  530:                     if (($end > 0) && ($end < $now)) {
  531:                         $current{$user}{changestate} = 'reenable';
  532:                         $current{$user}{'status'} = 'previous';
  533:                         $member_nums{'previous'} ++;
  534:                     } elsif (($start > $now)) {
  535:                         $current{$user}{changestate} = 'activate';
  536:                         $current{$user}{'status'} = 'future';
  537:                         $member_nums{'future'} ++;
  538:                     } else {
  539:                         $current{$user}{changestate} = 'expire';
  540:                         $current{$user}{'status'} = 'active';
  541:                         $member_nums{'active'} ++;
  542:                     }
  543:                     if ((@userprivs > 0) && (ref($fixedprivs) eq 'HASH')) {
  544:                         foreach my $tool (sort(keys(%{$fixedprivs}))) {
  545:                             foreach my $priv (keys(%{$$fixedprivs{$tool}})) {
  546:                                 if (grep/^$priv$/,@userprivs) {
  547:                                     push(@{$current{$user}{currtools}},$tool);
  548:                                     last;
  549:                                 }
  550:                             }
  551:                         }
  552:                         $hastools = 1;
  553:                     }
  554:                     if ((ref($available) eq 'ARRAY') && (@{$available} > 0)) {
  555:                         if (@{$current{$user}{currtools}} > 0) {
  556:                             if ("@{$available}" ne "@{$current{$user}{currtools}}") {
  557:                                 foreach my $tool (@{$available}) {
  558:                                     unless (grep/^$tool$/,@{$current{$user}{currtools}}) {
  559:                                         push(@{$current{$user}{newtools}},$tool);                                    }
  560:                                 }
  561:                             }
  562:                         } else {
  563:                             @{$current{$user}{newtools}} = @{$available};
  564: 
  565:                         }
  566:                         if (@{$current{$user}{newtools}} > 0) {
  567:                             $addtools = 1;
  568:                         }
  569:                     }
  570:                 }
  571:             }
  572:         }
  573:         if (keys(%current) > 0) {
  574:             my %idhash;
  575:             foreach my $udom (keys(%allnames)) {
  576:                 %{$idhash{$udom}} = &Apache::lonnet::idrget($udom,
  577:                                                 keys(%{$allnames{$udom}}));
  578:                 foreach my $uname (keys(%{$idhash{$udom}})) {
  579:                     $current{$uname.':'.$udom}{'id'} = $idhash{$udom}{$uname};
  580:                 }
  581:                 foreach my $uname (keys(%{$allnames{$udom}})) {
  582:                     $current{$uname.':'.$udom}{'fullname'} =
  583:                                 &Apache::loncommon::plainname($uname,$udom,
  584:                                                                   'lastname');
  585:                 }
  586:             }
  587:         }
  588:     }
  589:     return (\%current,\%member_nums,$hastools,$addtools);
  590: }
  591: 
  592: ###############################################
  593: 
  594: sub sum_quotas {
  595:     my ($courseid) = @_;
  596:     my $totalquotas = 0;
  597:     my ($cdom,$cnum);
  598:     if (!defined($courseid)) {
  599:         if (defined($env{'request.course.id'})) {
  600:             $courseid = $env{'request.course.id'};
  601:             $cdom = $env{'course.'.$courseid.'.domain'};
  602:             $cnum = $env{'course.'.$courseid.'.num'};
  603:         } else {
  604:             return '';
  605:         }
  606:     } else {
  607:         ($cdom,$cnum) = split(/_/,$courseid);
  608:     }
  609:     if ($cdom && $cnum) {
  610:         my %curr_groups = &coursegroups($cdom,$cnum);
  611:         if (%curr_groups) {
  612:             foreach my $group (keys(%curr_groups)) {
  613:                 my %settings=&get_group_settings($curr_groups{$group});
  614:                 my $quota = $settings{'quota'};
  615:                 if ($quota eq '') {
  616:                     $quota = 0;
  617:                 }
  618:                 $totalquotas += $quota; 
  619:             }
  620:         } else {
  621:             return 0;
  622:         }
  623:     } else {
  624:         return '';
  625:     }
  626:     return $totalquotas;
  627: }
  628: 
  629: ###############################################
  630: 
  631: sub get_bbfolder_url {
  632:     my ($cdom,$cnum,$group) = @_;
  633:     my %curr_groups = &coursegroups($cdom,$cnum,$group);
  634:     my $grpbbmap;
  635:     if (%curr_groups) {
  636:         my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
  637:         $grpbbmap = $crspath.'group_boards_'.$group.'.sequence';
  638:     }
  639:     return $grpbbmap;
  640: }
  641: 
  642: ###############################################
  643: 
  644: sub get_group_bbinfo {
  645:     my ($cdom,$cnum,$group,$boardurl) = @_;
  646:     my $navmap = Apache::lonnavmaps::navmap->new();
  647:     my @groupboards;
  648:     my %boardshash;
  649:     my $grpbbmap = &get_bbfolder_url($cdom,$cnum,$group);
  650:     if ($grpbbmap) {
  651:         my $bbfolderres = $navmap->getResourceByUrl($grpbbmap);
  652:         if ($bbfolderres) {
  653:             my @boards = $navmap->retrieveResources($bbfolderres,undef,0,0);
  654:             foreach my $res (@boards) {
  655:                 my $url = $res->src();
  656:                 if ($url =~ m|^(/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard)|) {
  657:                     if ($boardurl) {
  658:                         if ($boardurl =~ /^\Q$1\E/) {
  659:                             push(@groupboards,$res->symb());
  660:                             $boardshash{$res->symb()} = {
  661:                                                         title => $res->title(),
  662:                                                         url   => $res->src(),
  663:                                                         };
  664:                             last;
  665:                         }
  666:                     } else {
  667:                         push(@groupboards,$res->symb());
  668:                         $boardshash{$res->symb()} = {
  669:                                                       title => $res->title(),
  670:                                                       url   => $res->src(),
  671:                                                     };
  672:                     }
  673:                 }
  674:             }
  675:         }
  676:     }
  677:     undef($navmap);
  678:     return (\@groupboards,\%boardshash);
  679: }
  680: 
  681: ###############################################
  682: 
  683: 1;
  684: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>