Annotation of loncom/interface/longroup.pm, revision 1.32
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # accessor routines used to provide information about course groups
3: #
1.32 ! raeburn 4: # $Id: longroup.pm,v 1.31 2016/03/11 22:11:22 musolffc Exp $
1.21 bisitz 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.4 albertel 28:
1.1 raeburn 29: package Apache::longroup;
1.4 albertel 30:
1.1 raeburn 31: use strict;
32: use Apache::lonnet;
1.19 schafran 33: use Apache::lonlocal;
1.23 raeburn 34: use LONCAPA;
1.1 raeburn 35:
36: ###############################################
37: =pod
38:
39: =item coursegroups
40:
41: Retrieve information about groups in a course,
42:
43: Input:
44: 1. Optional course domain
45: 2. Optional course number
46: 3. Optional group name
1.13 raeburn 47: 4. Optional namespace
1.1 raeburn 48:
49: Course domain and number will be taken from user's
50: environment if not supplied. Optional group name will
1.13 raeburn 51: be passed to lonnet function as a regexp to
52: use in the call to the dump function. Optional namespace
53: will determine whether information is retrieved about current
54: groups (default) or deleted groups (namespace = deleted_groups).
1.4 albertel 55:
1.1 raeburn 56: Output
1.13 raeburn 57: Returns hash of groups in a course (subject to the
1.1 raeburn 58: optional group name filter). In the hash, the keys are
59: group names, and their corresponding values
60: are scalars containing group information in XML. This
61: can be sent to &get_group_settings() to be parsed.
62:
63: Side effects:
64: None.
1.15 albertel 65:
1.1 raeburn 66: =cut
67:
68: ###############################################
69:
70: sub coursegroups {
1.13 raeburn 71: my ($cdom,$cnum,$group,$namespace) = @_;
1.1 raeburn 72: if (!defined($cdom) || !defined($cnum)) {
73: my $cid = $env{'request.course.id'};
74:
75: return if (!defined($cid));
76:
77: $cdom = $env{'course.'.$cid.'.domain'};
78: $cnum = $env{'course.'.$cid.'.num'};
79: }
1.13 raeburn 80: if (!defined($namespace)) {
81: $namespace = 'coursegroups';
82: }
83: my %groups = &Apache::lonnet::get_coursegroups($cdom,$cnum,$group,
84: $namespace);
85: if (my $tmp = &Apache::lonnet::error(%groups)) {
86: undef(%groups);
87: &Apache::lonnet::logthis('Error retrieving groups: '.$tmp.' in '.$cnum.':'.$cdom.' - '.$namespace);
1.1 raeburn 88: }
1.14 raeburn 89: if (defined($groups{'group_allfolders'."\0".'locked_folder'})) {
90: delete($groups{'group_allfolders'."\0".'locked_folder'});
91: }
1.13 raeburn 92: return %groups;
1.1 raeburn 93: }
94:
95: ###############################################
96:
1.15 albertel 97: =pod
98:
1.1 raeburn 99: =item get_group_settings
1.4 albertel 100:
1.1 raeburn 101: Uses TokeParser to extract group information from the
102: XML used to describe course groups.
1.4 albertel 103:
1.1 raeburn 104: Input:
105: Scalar containing XML - as retrieved from &coursegroups().
1.4 albertel 106:
1.1 raeburn 107: Output:
108: Hash containing group information as key=values for (a), and
109: hash of hashes for (b)
1.4 albertel 110:
1.1 raeburn 111: Keys (in two categories):
1.6 raeburn 112: (a) groupname, creator, creation, modified, startdate, enddate, quota.
1.1 raeburn 113: Corresponding values are name of the group, creator of the group
114: (username:domain), UNIX time for date group was created, and
1.6 raeburn 115: settings were last modified, file quota, and default start and end
116: access times for group members.
1.4 albertel 117:
1.1 raeburn 118: (b) functions returned in hash of hashes.
119: Outer hash key is functions.
120: Inner hash keys are chat,discussion,email,files,homepage,roster.
121: Corresponding values are either on or off, depending on
122: whether this type of functionality is available for the group.
1.4 albertel 123:
1.1 raeburn 124: =cut
125:
126: ###############################################
127:
128: sub get_group_settings {
129: my ($groupinfo)=@_;
130: my $parser=HTML::TokeParser->new(\$groupinfo);
131: my $token;
132: my $tool = '';
133: my $role = '';
134: my %content=();
135: while ($token=$parser->get_token) {
136: if ($token->[0] eq 'S') {
137: my $entry=$token->[1];
138: if ($entry eq 'functions' || $entry eq 'autosec') {
139: %{$content{$entry}} = ();
140: $tool = $entry;
141: } elsif ($entry eq 'role') {
142: if ($tool eq 'autosec') {
143: $role = $token->[2]{id};
144: @{$content{$tool}{$role}} = ();
145: }
146: } else {
147: my $value=$parser->get_text('/'.$entry);
148: if ($entry eq 'name') {
149: if ($tool eq 'functions') {
150: my $function = $token->[2]{id};
151: $content{$tool}{$function} = $value;
152: }
153: } elsif ($entry eq 'groupname') {
154: $content{$entry}=&unescape($value);
155: } elsif (($entry eq 'roles') || ($entry eq 'types') ||
156: ($entry eq 'sectionpick') || ($entry eq 'defpriv')) {
157: push(@{$content{$entry}},$value);
158: } elsif ($entry eq 'section') {
159: if ($tool eq 'autosec' && $role ne '') {
160: push(@{$content{$tool}{$role}},$value);
161: }
162: } else {
163: $content{$entry}=$value;
164: }
165: }
166: } elsif ($token->[0] eq 'E') {
167: if ($token->[1] eq 'functions' || $token->[1] eq 'autosec') {
168: $tool = '';
169: } elsif ($token->[1] eq 'role') {
170: $role = '';
171: }
172: }
173: }
174: return %content;
175: }
176:
177: ###############################################
178:
179: sub check_group_access {
180: my ($group) = @_;
181: my $access = 1;
182: my $now = time;
183: my ($start,$end) = split(/\./,$env{'user.role.gr/'.$env{'request.course,id'}.'/'.$group});
184: if (($end!=0) && ($end<$now)) { $access = 0; }
185: if (($start!=0) && ($start>$now)) { $access=0; }
186: return $access;
187: }
188:
189: ###############################################
190:
191: =pod
1.4 albertel 192:
1.1 raeburn 193: =item group_changes
194:
195: Add or drop group memberships in a course as a result of
196: changes in a user's roles/sections. Called by
197: &Apache::lonnet:assignrole()
1.4 albertel 198:
1.1 raeburn 199: Input:
200: 1. User's domain
201: 2. User's username
202: 3. Url of role
203: 4. Role
204: 5. End date of role
205: 6. Start date of role
1.16 raeburn 206: 7. Selfenroll
207: 8. Context
1.1 raeburn 208:
209: Checks to see if role for which assignment is being made is in a course.
210: If so, gathers information about auto-group population settings for
211: groups in the course.
212:
213: If role is being expired, will also expire any group memberships that
214: are specified for auto-group population for the specific role and
215: section (including section 'none' and 'all' sections), unless a
216: different role/section also included in auto-group population
217: for the course is included amongst the user's unexpired roles
218: and would trigger membership in teh same group(s)
219:
220: If role is being added, will add any group memberships specified
1.29 raeburn 221: for auto-group population, unless user is already a group member.
1.1 raeburn 222: Uses default group privileges and default start and end group access
1.16 raeburn 223: times.
224:
225: Flag for selfenroll (value of 1), and context (auto, updatenow,
226: automated, course, domain etc.) can be used to log the reason for
227: the role change.
1.1 raeburn 228:
229: Output
230: None
231:
232: Side effects:
233: May result in calls to Apache::lonnet::modify_group_roles()
234: and Apache::lonnet::modify_coursegroup_membership() to add
235: or expire group membership(s) for a user.
236:
237: =cut
238:
239: sub group_changes {
1.32 ! raeburn 240: my ($udom,$uname,$url,$role,$origend,$origstart,$selfenroll,$context,
! 241: $othdomby,$requester) = @_;
1.1 raeburn 242: my $now = time;
243: my $chgtype;
244: if ($origend > 0 && $origend <= $now) {
245: $chgtype = 'drop';
246: } else {
247: $chgtype = 'add';
248: }
249: my ($cid,$cdom,$cnum,$sec);
250: if ($url =~ m-^(/[^/]+/[^/]+)/([^/]+)$-) {
251: $cid = $1;
252: $sec = $2;
253: } else {
254: $cid = $url;
255: }
256: my %crshash=&Apache::lonnet::coursedescription($cid);
257: $cdom = $crshash{'domain'};
258: $cnum = $crshash{'num'};
259: if (defined($cdom) && defined($cnum)) {
260: my %settings;
261: my @changegroups = ();
262: my %dropgroup = ();
263: my %dropstart = ();
264: my %addgroup = ();
265: my %curr_groups = &coursegroups($cdom,$cnum);
266: if (%curr_groups) {
267: foreach my $group (keys(%curr_groups)) {
268: %{$settings{$group}}=&get_group_settings($curr_groups{$group});
269: if ($chgtype eq 'add') {
270: if (!($settings{$group}{autoadd} eq 'on')) {
271: next;
272: }
273: } else {
274: if (!($settings{$group}{autodrop} eq 'on')) {
275: next;
276: }
277: }
278: my @autosec = ();
279: if (ref($settings{$group}{'autosec'}{$role}) eq 'ARRAY') {
280: @autosec = @{$settings{$group}{'autosec'}{$role}};
281: }
282: if ($sec eq '') {
283: $sec = 'none';
284: }
285: if ((grep(/^$sec$/,@autosec)) || (grep(/^all$/,@autosec))) {
286: push(@changegroups,$group);
287: }
288: }
289: }
290: if (@changegroups > 0) {
291: my %currpriv;
1.28 raeburn 292: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname,$cid);
1.29 raeburn 293: if (keys(%roleshash) > 0) {
1.1 raeburn 294: my $group_privs = '';
295: foreach my $group (@changegroups) {
296: if ($chgtype eq 'add') {
297: if (ref($settings{$group}{'defpriv'}) eq 'ARRAY') {
298: $group_privs =
299: join(':',@{$settings{$group}{'defpriv'}});
300: }
301: }
302: my $key = $cid.'/'.$group.'_gr';
303: if (defined($roleshash{$key})) {
304: if ($roleshash{$key}=~ /^gr\/([^_]*)_(\d+)_([\-\d]+)$/) {
305: my $grpstart = $3;
306: my $grpend = $2;
307: $currpriv{$group} = $1;
308: if ($chgtype eq 'drop') {
309: if ($grpstart == -1) { next; } # deleted
310: if ($grpend == 0 || $grpend > $now) {
1.2 albertel 311: if (!defined($dropgroup{$group})) {
1.1 raeburn 312: $dropstart{$group} = $grpstart;
313: if ($grpstart > $now) {
314: $dropstart{$group} = $now;
315: }
316: $dropgroup{$group} = $now.':'.
317: $dropstart{$group}.
318: ':'.$currpriv{$group};
319: }
320: }
321: } elsif ($chgtype eq 'add') {
322: if (($grpstart == -1) || ($grpend > 0 &&
323: ($grpend < $settings{$group}{'enddate'} ||
324: $settings{$group}{'enddate'} == 0)) ||
325: ($grpstart > $settings{$group}{'startdate'})) {
1.2 albertel 326: if (!defined($addgroup{$group})) {
1.1 raeburn 327: $addgroup{$group} =
328: $settings{$group}{'enddate'}.':'.
329: $settings{$group}{'startdate'}.':'.
330: $group_privs;
331: }
332: }
333: }
334: }
335: } elsif ($chgtype eq 'add') {
336: $addgroup{$group} = $settings{$group}{'enddate'}.':'.
337: $settings{$group}{'startdate'}.':'.
338: $group_privs;
339: }
340: }
341: if ($chgtype eq 'add') {
342: foreach my $add (keys(%addgroup)) {
343: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,
344: $add,$uname.':'.$udom,
345: $settings{$add}{'enddate'},
346: $settings{$add}{'startdate'},
1.32 ! raeburn 347: $group_privs,$selfenroll,$context,
! 348: $othdomby,$requester) eq 'ok') {
1.1 raeburn 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)$/) {
1.2 albertel 373: if ($sec ne $1) {
1.1 raeburn 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},
1.16 raeburn 417: $currpriv{$drop},
1.32 ! raeburn 418: $selfenroll,$context,
! 419: $othdomby,$requester)
1.1 raeburn 420: eq 'ok') {
421: my %usersettings;
422: $usersettings{$drop.':'.$uname.':'.$udom} =
423: $dropgroup{$drop};
424: my $roster_result =
425: &Apache::lonnet::modify_coursegroup_membership(
426: $cdom,$cnum,\%usersettings);
427: }
428: }
429: }
430: }
431: }
432: }
433: }
434: return;
435: }
436:
437: ###############################################
438:
1.8 raeburn 439: sub get_fixed_privs {
440: my $fixedprivs = {
1.20 schafran 441: email => {sgm => 1},
1.19 schafran 442: discussion => {vgb => 1},
443: chat => {pgc => 1},
444: files => {rgf => 1},
445: roster => {vgm => 1},
446: homepage => {vgh => 1},
1.8 raeburn 447: };
448: return $fixedprivs;
449: }
450:
451: ###############################################
452:
453: sub get_tool_privs {
454: my ($gpterm) = @_;
455: my $toolprivs = {
1.20 schafran 456: email => {
1.18 schafran 457: sgm => 'Send '.$gpterm.' message',
458: sgb => 'Broadcast message',
1.8 raeburn 459: },
460: discussion => {
461: cgb => 'Create boards',
462: pgd => 'Post',
1.10 raeburn 463: egp => 'Edit own posts',
464: dgp => 'Hide/Delete any post',
1.8 raeburn 465: vgb => 'View boards',
466: },
467: chat => {
1.22 hauer 468: pgc => 'Chat Room',
1.8 raeburn 469: },
470: files => {
471: rgf => 'Retrieve',
472: ugf => 'Upload',
473: mgf => 'Modify',
474: dgf => 'Delete',
475: agf => 'Control Access',
476: },
477: roster => {
1.10 raeburn 478: vgm => 'Basic Display',
479: vmd => 'Detailed Display',
1.8 raeburn 480: },
481: homepage => {
482: vgh => 'View page',
483: mgh => 'Modify page',
484: },
485: };
486: return $toolprivs;
487: }
488:
489: ###############################################
490:
491:
492: sub group_memberlist {
493: my ($cdom,$cnum,$groupname,$fixedprivs,$available) = @_;
494: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
495: $groupname);
496: my %current = ();
497: my $hastools = 0;
498: my $addtools = 0;
1.9 raeburn 499: my %member_nums = (
500: 'previous' => 0,
501: 'future' => 0,
502: 'active' => 0,
503: );
1.8 raeburn 504: my $now = time;
505: if (keys(%membership) > 0) {
506: my %allnames = ();
507: foreach my $key (sort(keys(%membership))) {
508: if ($key =~ /^\Q$groupname\E:([^:]+):([^:]+)$/) {
509: my $uname = $1;
510: my $udom = $2;
511: my $user = $uname.':'.$udom;
512: my($end,$start,@userprivs) = split(/:/,$membership{$key});
513: unless ($start == -1) {
514: $allnames{$udom}{$uname} = 1;
515: $current{$user} = {
516: uname => $uname,
517: udom => $udom,
518: start => &Apache::lonlocal::locallocaltime($start),
519: currtools => [],
520: newtools => [],
521: privs => \@userprivs,
522: };
523:
524: if ($end == 0) {
525: $current{$user}{end} = 'No end date';
526: } else {
527: $current{$user}{end} =
528: &Apache::lonlocal::locallocaltime($end);
529: }
530: my $now = time;
531: if (($end > 0) && ($end < $now)) {
532: $current{$user}{changestate} = 'reenable';
533: $current{$user}{'status'} = 'previous';
1.9 raeburn 534: $member_nums{'previous'} ++;
1.8 raeburn 535: } elsif (($start > $now)) {
536: $current{$user}{changestate} = 'activate';
537: $current{$user}{'status'} = 'future';
1.9 raeburn 538: $member_nums{'future'} ++;
1.8 raeburn 539: } else {
540: $current{$user}{changestate} = 'expire';
541: $current{$user}{'status'} = 'active';
1.9 raeburn 542: $member_nums{'active'} ++;
1.8 raeburn 543: }
1.10 raeburn 544: if ((@userprivs > 0) && (ref($fixedprivs) eq 'HASH')) {
1.8 raeburn 545: foreach my $tool (sort(keys(%{$fixedprivs}))) {
546: foreach my $priv (keys(%{$$fixedprivs{$tool}})) {
547: if (grep/^$priv$/,@userprivs) {
548: push(@{$current{$user}{currtools}},$tool);
549: last;
550: }
551: }
552: }
553: $hastools = 1;
554: }
1.10 raeburn 555: if ((ref($available) eq 'ARRAY') && (@{$available} > 0)) {
1.8 raeburn 556: if (@{$current{$user}{currtools}} > 0) {
557: if ("@{$available}" ne "@{$current{$user}{currtools}}") {
558: foreach my $tool (@{$available}) {
559: unless (grep/^$tool$/,@{$current{$user}{currtools}}) {
560: push(@{$current{$user}{newtools}},$tool); }
561: }
562: }
563: } else {
564: @{$current{$user}{newtools}} = @{$available};
565:
566: }
567: if (@{$current{$user}{newtools}} > 0) {
568: $addtools = 1;
569: }
570: }
571: }
572: }
573: }
574: if (keys(%current) > 0) {
575: my %idhash;
576: foreach my $udom (keys(%allnames)) {
577: %{$idhash{$udom}} = &Apache::lonnet::idrget($udom,
578: keys(%{$allnames{$udom}}));
579: foreach my $uname (keys(%{$idhash{$udom}})) {
580: $current{$uname.':'.$udom}{'id'} = $idhash{$udom}{$uname};
581: }
582: foreach my $uname (keys(%{$allnames{$udom}})) {
583: $current{$uname.':'.$udom}{'fullname'} =
584: &Apache::loncommon::plainname($uname,$udom,
585: 'lastname');
586: }
587: }
588: }
589: }
1.10 raeburn 590: return (\%current,\%member_nums,$hastools,$addtools);
1.8 raeburn 591: }
592:
593: ###############################################
594:
1.6 raeburn 595: sub sum_quotas {
596: my ($courseid) = @_;
597: my $totalquotas = 0;
598: my ($cdom,$cnum);
599: if (!defined($courseid)) {
600: if (defined($env{'request.course.id'})) {
601: $courseid = $env{'request.course.id'};
602: $cdom = $env{'course.'.$courseid.'.domain'};
603: $cnum = $env{'course.'.$courseid.'.num'};
604: } else {
605: return '';
606: }
607: } else {
608: ($cdom,$cnum) = split(/_/,$courseid);
609: }
610: if ($cdom && $cnum) {
611: my %curr_groups = &coursegroups($cdom,$cnum);
612: if (%curr_groups) {
613: foreach my $group (keys(%curr_groups)) {
614: my %settings=&get_group_settings($curr_groups{$group});
615: my $quota = $settings{'quota'};
616: if ($quota eq '') {
617: $quota = 0;
618: }
619: $totalquotas += $quota;
620: }
621: } else {
622: return 0;
623: }
624: } else {
625: return '';
626: }
627: return $totalquotas;
628: }
629:
630: ###############################################
631:
1.7 raeburn 632: sub get_bbfolder_url {
633: my ($cdom,$cnum,$group) = @_;
634: my %curr_groups = &coursegroups($cdom,$cnum,$group);
635: my $grpbbmap;
636: if (%curr_groups) {
637: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
1.9 raeburn 638: $grpbbmap = $crspath.'group_boards_'.$group.'.sequence';
1.7 raeburn 639: }
640: return $grpbbmap;
641: }
642:
643: ###############################################
644:
645: sub get_group_bbinfo {
1.10 raeburn 646: my ($cdom,$cnum,$group,$boardurl) = @_;
1.17 raeburn 647: my @groupboards = ();
648: my %boardshash = ();
1.7 raeburn 649: my $navmap = Apache::lonnavmaps::navmap->new();
1.17 raeburn 650: if (defined($navmap)) {
651: my $grpbbmap = &get_bbfolder_url($cdom,$cnum,$group);
652: if ($grpbbmap) {
653: my $bbfolderres = $navmap->getResourceByUrl($grpbbmap);
654: if ($bbfolderres) {
655: my @boards = $navmap->retrieveResources($bbfolderres,undef,0,0);
656: foreach my $res (@boards) {
657: my $url = $res->src();
658: if ($url =~ m|^(/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard)|) {
659: if ($boardurl) {
660: if ($boardurl =~ /^\Q$1\E/) {
661: push(@groupboards,$res->symb());
662: $boardshash{$res->symb()} = {
663: title => $res->title(),
664: url => $res->src(),
665: };
666: last;
667: }
668: } else {
1.10 raeburn 669: push(@groupboards,$res->symb());
670: $boardshash{$res->symb()} = {
1.17 raeburn 671: title => $res->title(),
672: url => $res->src(),
1.10 raeburn 673: };
674: }
675: }
1.7 raeburn 676: }
677: }
678: }
1.17 raeburn 679: undef($navmap);
680: } else {
681: &Apache::lonnet::logthis('Retrieval of group boards failed - could not create navmap object for group: '.$group.' in course: '.$cdom.':'.$cnum);
1.7 raeburn 682: }
683: return (\@groupboards,\%boardshash);
684: }
685:
686: ###############################################
687:
1.24 raeburn 688: sub get_group_link {
1.30 raeburn 689: my ($cdom,$cnum,$group,$navmap,$view_permission,$refarg) = @_;
1.24 raeburn 690: if (ref($navmap)) {
1.30 raeburn 691: my $map = "uploaded/$cdom/$cnum/group_folder_"."$group.sequence";
692: my $mapres = $navmap->getResourceByUrl("/$map");
693: my $hidden;
694: if (ref($mapres)) {
1.31 musolffc 695: if ((!$view_permission) && ($mapres->randomout())) {
1.30 raeburn 696: $hidden = 1;
697: }
698: }
699: my $url = "adm/$cdom/$cnum/$group/smppg";
700: my $idx = '1';
701: my $symb = $map.'___'.$idx.'___'.$url;
1.24 raeburn 702: my $res = $navmap->getBySymb($symb);
1.30 raeburn 703: $url = "/$url";
704: $map = "/$map";
1.25 raeburn 705: my $link;
706: if (ref($res)) {
1.30 raeburn 707: if ((!$view_permission) && ($res->randomout())) {
708: $hidden = 1;
709: } else {
710: $hidden = 0;
711: if ($refarg) {
712: $link = $url.'?'.$refarg;
713: } else {
714: $link = $res->link();
715: $link .= (($link=~/\?/)?'&':'?').'symb='.$res->shown_symb();
716: }
717: }
718: } elsif (&Apache::lonnet::is_on_map($url)) {
719: unless ($hidden) {
720: $link = $url;
721: if ($refarg) {
722: $link = $url.'?'.$refarg;
723: }
724: }
725: }
726: if (wantarray) {
727: return ($link,$hidden);
1.25 raeburn 728: } else {
1.30 raeburn 729: return $link;
1.25 raeburn 730: }
1.24 raeburn 731: }
732: return;
733: }
734:
735: ###############################################
736:
1.30 raeburn 737: sub display_group_links {
738: my ($r,$target,$group,$context,$refarg,$numtoolsref,$hidehdr,%groupinfo) = @_;
739: my @available = ();
740: my %menu = ();
741: %{$menu{'email'}} = (
742: text => 'Group Message',
743: href => '/adm/email?compose=group&group='.$group.
744: $refarg,
745: );
746: %{$menu{'discussion'}} = (
747: text => 'Discussion Boards',
748: href => '/adm/groupboards?group='.$group.$refarg,
749: );
750: %{$menu{'chat'}} = (
751: text => 'Group Chat Room',
752: href => "javascript:group_chat('$group')",
753: );
754: %{$menu{'files'}} = (
755: text => 'Group Portfolio',
756: href => '/adm/coursegrp_portfolio?group='.$group.
757: $refarg,
758: );
759: %{$menu{'roster'}} = (
760: text => 'Membership Roster',
761: href => '/adm/grouproster?group='.$group.$refarg,
762: );
763: foreach my $tool (sort(keys(%menu))) {
764: if ($groupinfo{functions}{$tool} eq 'on') {
765: push(@available,$tool);
766: }
767: }
768: my $output = '';
769: if (ref($numtoolsref) eq 'SCALAR') {
770: $$numtoolsref = scalar(@available);
771: }
772: if (@available > 0) {
773: if ($target eq 'tex') {
774: $output = '<table cellspacing="4" cellpadding="4">';
775: } else {
776: $output = &Apache::loncommon::start_data_table();
777: }
778: foreach my $tool (@available) {
779: if ($target eq 'tex') {
780: $output .= '<tr><td>'.&mt($menu{$tool}{text}).'</td></tr>';
781: } else {
782: $output .= &Apache::loncommon::start_data_table_row()
783: .'<td><a href="'.$menu{$tool}{href}.'">'
784: .&mt($menu{$tool}{text}).'</a></td>'
785: .&Apache::loncommon::end_data_table_row();
786: }
787: }
788: if ($target eq 'tex') {
789: $output .= '</table>';
790: } else {
791: $output .= &Apache::loncommon::end_data_table();
792: }
793: if ($target eq 'tex') {
794: $output = &Apache::lonxml::xmlparse($r,'tex',&mt('Available functions').'<br /><br />'.$output);
795: } else {
796: unless ($hidehdr) {
797: $output = '<h3>'.&mt('Available Group Tools').'</h3>'.$output;
798: }
799: }
800: } else {
801: if ($context eq 'edit') {
802: $output = &mt('No group functionality.');
803: } else {
804: $output = &mt('No group functionality (e.g., e-mail, discussion, chat room or file upload) is currently available to you in this group: [_1].',
805: '<b>'.&unescape($groupinfo{'description'}).'</b>');
806: }
807: if ($target eq 'tex') {
808: $output = &Apache::lonxml::xmlparse($r,'tex',$output);
809: }
810: }
811: return $output;
812: }
813:
1.1 raeburn 814: 1;
815:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>