Annotation of loncom/interface/loncoursegroups.pm, revision 1.108
1.24 www 1: # The LearningOnline Network with CAPA
2: #
1.108 ! raeburn 3: # $Id: loncoursegroups.pm,v 1.107 2009/11/25 06:20:20 raeburn Exp $
1.1 raeburn 4: #
5: # Copyright Michigan State University Board of Trustees
6: #
7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
8: #
9: # LON-CAPA is free software; you can redistribute it and/or modify
10: # it under the terms of the GNU General Public License as published by
11: # the Free Software Foundation; either version 2 of the License, or
12: # (at your option) any later version.
13: #
14: # LON-CAPA is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with LON-CAPA; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27:
28: package Apache::loncoursegroups;
29:
30: use strict;
31: use Apache::lonnet;
1.63 albertel 32: use Apache::loncommon();
33: use Apache::lonhtmlcommon();
1.1 raeburn 34: use Apache::lonlocal;
1.63 albertel 35: use Apache::lonnavmaps();
36: use Apache::longroup();
37: use Apache::portfolio();
1.1 raeburn 38: use Apache::Constants qw(:common :http);
1.63 albertel 39: use LONCAPA::map();
1.24 www 40: use lib '/home/httpd/lib/perl/';
41: use LONCAPA;
1.1 raeburn 42:
43: sub handler {
44: my ($r) = @_;
1.3 raeburn 45:
1.1 raeburn 46: &Apache::loncommon::content_type($r,'text/html');
47: $r->send_http_header;
1.15 albertel 48:
1.1 raeburn 49: if ($r->header_only) {
50: return OK;
51: }
52:
53: # Needs to be in a course
54: if (! ($env{'request.course.fn'})) {
55: # Not in a course
56: $env{'user.error.msg'}=
1.104 raeburn 57: "/adm/coursegroups:mdg:0:0:Cannot edit or view course/community groups";
1.1 raeburn 58: return HTTP_NOT_ACCEPTABLE;
59: }
60:
1.3 raeburn 61: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.5 raeburn 62: ['action','refpage','state','groupname','branch']);
1.3 raeburn 63: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
64: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
65:
1.1 raeburn 66: my $view_permission =
1.52 raeburn 67: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.1 raeburn 68: my $manage_permission =
1.52 raeburn 69: &Apache::lonnet::allowed('mdg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.3 raeburn 70: &Apache::lonhtmlcommon::clear_breadcrumbs();
71:
1.29 raeburn 72: my $gpterm = &Apache::loncommon::group_term();
73: my $ucgpterm = $gpterm;
74: $ucgpterm =~ s/^(\w)/uc($1)/e;
75: my $crstype = &Apache::loncommon::course_type();
76:
1.3 raeburn 77: my %functions = (
1.92 schafran 78: email => 'Send Messages',
1.81 schafran 79: discussion => 'Discussion Boards',
1.94 hauer 80: chat => 'Chat Room',
1.96 weissno 81: files => 'Group Portfolio',
1.81 schafran 82: roster => 'Membership Roster',
1.29 raeburn 83: homepage => $ucgpterm.' home page',
1.3 raeburn 84: );
85:
86: my %idx = ();
87: $idx{id} = &Apache::loncoursedata::CL_ID();
88: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
89: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
90: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
1.31 albertel 91: $idx{section} = &Apache::loncoursedata::CL_SECTION();
1.3 raeburn 92:
93: my $action = $env{'form.action'};
1.21 raeburn 94: my $state = $env{'form.state'};
1.65 raeburn 95: if ((!defined($action)) || ($action eq 'view') || ($action eq 'modify') || ($action eq 'delete') || ($action eq 'reenable')) {
1.21 raeburn 96: if (!defined($state)) {
97: $state = 'view';
98: }
99: }
1.64 raeburn 100: if ($action eq 'create' || $action eq 'modify' || $action eq 'view' ||
1.65 raeburn 101: $action eq 'delete' || $action eq 'reenable') {
1.3 raeburn 102: if ($view_permission || $manage_permission) {
1.53 raeburn 103: if ($state eq 'view') {
104: &print_main_menu($r,$cdom,$cnum,\%functions,\%idx,
105: $view_permission,$manage_permission,
106: $action,$state,$gpterm,$ucgpterm,$crstype);
107: } else {
108: &group_administration($r,$action,$state,$cdom,$cnum,
109: \%functions,\%idx,$view_permission,
110: $manage_permission,$gpterm,$ucgpterm,
111: $crstype);
112: }
1.3 raeburn 113: } else {
1.79 bisitz 114: $r->print('<div class="LC_warning">'
115: .&mt('You do not have '.$gpterm.' administration '
116: .'privileges in this '.lc($crstype).'.')
117: .'</div>');
1.3 raeburn 118: }
119: } else {
1.39 albertel 120: &print_main_menu($r,$cdom,$cnum,\%functions,\%idx,$view_permission,
121: $manage_permission,$action,$state,$gpterm,$ucgpterm,
122: $crstype);
1.3 raeburn 123: }
124: return OK;
125: }
126:
127: sub print_main_menu {
1.39 albertel 128: my ($r,$cdom,$cnum,$functions,$idx,$view_permission,$manage_permission,
129: $action,$state,$gpterm,$ucgpterm,$crstype) = @_;
1.21 raeburn 130: my $jscript = qq|
131: function changeSort(caller) {
132: document.$state.sortby.value = caller;
133: document.$state.submit();
1.60 raeburn 134: }
135: function openGroupRoster(group,status) {
136: var url = '/adm/grouproster?';
137: url += 'group='+group+'&status='+status+'&ref=popup';
138: var title = 'Group Membership';
139: var options = 'scrollbars=1,resizable=1,menubar=0';
140: options += ',width=700,height=600';
141: rosterbrowser = open(url,title,options,'1');
142: rosterbrowser.focus();
1.21 raeburn 143: }\n|;
1.95 schafran 144: $r->print(&header('My Space',$jscript,$action,$state));
1.71 raeburn 145: if ($env{'form.refpage'} eq 'cusr') {
1.53 raeburn 146: &Apache::lonhtmlcommon::add_breadcrumb
1.71 raeburn 147: ({href=>"/adm/createuser",
148: text=>"User Management"});
1.53 raeburn 149: }
1.3 raeburn 150: &Apache::lonhtmlcommon::add_breadcrumb
151: ({href=>"/adm/coursegroups",
1.53 raeburn 152: text=>"Groups"});
1.72 raeburn 153: my $helpitem;
154: if ($manage_permission) {
155: $helpitem = 'Creating_Groups';
156: }
157: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Groups',$helpitem));
1.39 albertel 158: &display_groups($r,$cdom,$cnum,$functions,$idx,$view_permission,
159: $manage_permission,$action,$state,$gpterm,$ucgpterm,
160: $crstype);
1.3 raeburn 161: $r->print(&footer());
162: return;
163: }
164:
165: sub display_groups {
1.39 albertel 166: my ($r,$cdom,$cnum,$functions,$idx,$view_permission,
167: $manage_permission,$action,$state,$gpterm,$ucgpterm,$crstype) = @_;
1.3 raeburn 168: my %curr_groups = ();
169: my %grp_info = ();
1.5 raeburn 170: my %actionlinks = (
1.21 raeburn 171: modify => '<a href="/adm/coursegroups?action=modify&refpage='.
1.53 raeburn 172: $env{'form.refpage'}.'&state=pick_task&groupname=',
1.5 raeburn 173: view => '<a href="/adm/'.$cdom.'/'.$cnum.'/',
174: delete => '<a href="/adm/coursegroups?action=delete&refpage='.
1.64 raeburn 175: $env{'form.refpage'}.'&state=verify&groupname=',
1.65 raeburn 176: reenable => '<a href="/adm/coursegroups?action=reenable&refpage='.
177: $env{'form.refpage'}.'&state=verify&groupname=',
1.5 raeburn 178: );
1.6 raeburn 179: my %lt = &Apache::lonlocal::texthash(
1.5 raeburn 180: modify => 'Modify',
1.6 raeburn 181: view => 'View',
1.5 raeburn 182: delete => 'Delete',
1.65 raeburn 183: reenable => 'Re-enable',
1.6 raeburn 184: act => 'Action',
1.53 raeburn 185: gname => 'Group Name',
186: desc => 'Group Title',
1.6 raeburn 187: crea => 'Creator',
188: crtd => 'Created',
189: last => 'Last Modified',
1.53 raeburn 190: func => 'Collaborative Tools',
1.6 raeburn 191: quot => 'Quota (Mb)',
192: memb => 'Members',
193: file => 'Files',
194: dibd => 'Discussion Boards',
1.29 raeburn 195: dius => 'Disk Use (%)',
1.53 raeburn 196: nogr => 'No groups exist.',
197: crng => 'Create a new group',
1.71 raeburn 198: redg => 'Re-enable a deleted group',
1.7 raeburn 199: alth => 'Although your current role has privileges'.
1.62 banghart 200: ' to view any existing groups in this '.
201: lc($crstype).', you do not have privileges '.
1.53 raeburn 202: 'to create new groups.',
1.7 raeburn 203: );
1.3 raeburn 204: if ($view_permission) {
1.5 raeburn 205: if (!defined($action)) {
206: $action = 'view';
207: }
1.71 raeburn 208: my ($status,$reenable_link);
1.65 raeburn 209: if ($action eq 'reenable') {
210: $status = 'deleted_groups';
1.71 raeburn 211: } else {
212: if ($manage_permission) {
213: my %deleted_groups =
214: &Apache::longroup::coursegroups($cdom,$cnum,undef,'deleted_groups');
215: if (keys(%deleted_groups) > 0) {
216: $reenable_link = ' <a href="/adm/coursegroups?action=reenable&refpage='.$env{'form.refpage'}.'">'.$lt{'redg'}.'</a>';
217: }
218: }
1.65 raeburn 219: }
220: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,undef,
221: $status);
1.71 raeburn 222:
1.15 albertel 223: if (%curr_groups) {
1.29 raeburn 224: if ($manage_permission) {
1.71 raeburn 225: if ($action ne 'reenable') {
226: $r->print('<br /><a href="/adm/coursegroups?action=create&refpage='.$env{'form.refpage'}.'">'.$lt{'crng'}.'</a>');
227: }
228: if ($reenable_link) {
229: $r->print($reenable_link);
1.53 raeburn 230: }
1.29 raeburn 231: }
1.7 raeburn 232: $r->print('<br /><br />');
1.39 albertel 233: $r->print(&Apache::loncommon::start_data_table().
234: &Apache::loncommon::start_data_table_header_row());
235:
1.4 raeburn 236: $r->print(<<"END");
1.39 albertel 237: <th>$lt{'act'}</th>
238: <th><a href="javascript:changeSort('groupname')">$lt{'gname'}</a></th>
239: <th><a href="javascript:changeSort('description')">$lt{'desc'}</a></th>
240: <th><a href="javascript:changeSort('creator')">$lt{'crea'}</a></th>
241: <th><a href="javascript:changeSort('creation')">$lt{'crtd'}</a></th>
242: <th><a href="javascript:changeSort('modified')">$lt{'last'}</a></th>
243: <th>$lt{'func'}</b></td>
244: <th><a href="javascript:changeSort('quota')">$lt{'quot'}</a></th>
245: <th><a href="javascript:changeSort('totalmembers')">$lt{'memb'}</a></th>
246: <th><a href="javascript:changeSort('totalfiles')">$lt{'file'}</a></th>
247: <th><a href="javascript:changeSort('boards')">$lt{'dibd'}</a></th>
248: <th><a href="javascript:changeSort('diskuse')">$lt{'dius'}</a></th>
1.3 raeburn 249: END
1.39 albertel 250: $r->print(&Apache::loncommon::end_data_table_header_row());
1.4 raeburn 251: my %Sortby = ();
252: foreach my $group (sort(keys(%curr_groups))) {
253: %{$grp_info{$group}} =
1.17 raeburn 254: &Apache::longroup::get_group_settings(
1.3 raeburn 255: $curr_groups{$group});
1.5 raeburn 256: my $members_result = &group_members($cdom,$cnum,$group,
257: \%grp_info);
1.29 raeburn 258: my $port_path = '/userfiles/groups/'.$group.'/portfolio';
259: my $totaldirs = 0;
260: my $totalfiles = 0;
1.74 raeburn 261: &group_files($group,$port_path,\$totalfiles,\$totaldirs);
1.29 raeburn 262: $grp_info{$group}{'totalfiles'} = $totalfiles;
263: $grp_info{$group}{'totaldirs'} = $totaldirs;
1.74 raeburn 264: my $getpropath = 1;
265: my $diskuse = &Apache::lonnet::diskusage($cdom,$cnum,$port_path, $getpropath);
1.29 raeburn 266: if ($grp_info{$group}{'quota'} > 0) {
267: my $pct_use = 0.1 * $diskuse/$grp_info{$group}{'quota'};
268: $grp_info{$group}{'diskuse'} = sprintf("%.0f",$pct_use);
269: } else {
270: $grp_info{$group}{'diskuse'} = 'N/A';
1.33 raeburn 271: }
272: my ($groupboards,$boardshash)=&Apache::longroup::get_group_bbinfo(
273: $cdom,$cnum,$group);
274: $grp_info{$group}{'boards'} = scalar(@{$groupboards});
1.4 raeburn 275: if ($env{'form.sortby'} eq 'groupname') {
276: push(@{$Sortby{$group}},$group);
277: } elsif ($env{'form.sortby'} eq 'description') {
1.29 raeburn 278: push(@{$Sortby{$grp_info{$group}{'description'}}},$group);
1.4 raeburn 279: } elsif ($env{'form.sortby'} eq 'creator') {
280: push(@{$Sortby{$grp_info{$group}{'creator'}}},$group);
281: } elsif ($env{'form.sortby'} eq 'creation') {
282: push(@{$Sortby{$grp_info{$group}{'creation'}}},$group);
283: } elsif ($env{'form.sortby'} eq 'modified') {
284: push(@{$Sortby{$grp_info{$group}{'modified'}}},$group);
285: } elsif ($env{'form.sortby'} eq 'quota') {
286: push(@{$Sortby{$grp_info{$group}{'quota'}}},$group);
287: } elsif ($env{'form.sortby'} eq 'totalmembers') {
288: push(@{$Sortby{$grp_info{$group}{'totalmembers'}}},
1.3 raeburn 289: $group);
1.4 raeburn 290: } elsif ($env{'form.sortby'} eq 'totalfiles') {
1.5 raeburn 291: push(@{$Sortby{$grp_info{$group}{'totalfiles'}}},$group);
1.4 raeburn 292: } elsif ($env{'form.sortby'} eq 'boards') {
293: push(@{$Sortby{$grp_info{$group}{'boards'}}},$group);
294: } elsif ($env{'form.sortby'} eq 'diskuse') {
295: push(@{$Sortby{$grp_info{$group}{'diskuse'}}},$group);
296: } else {
297: push(@{$Sortby{$group}},$group);
298: }
299: }
300: foreach my $key (sort(keys(%Sortby))) {
301: foreach my $group (@{$Sortby{$key}}) {
302: my $description =
1.39 albertel 303: &unescape($grp_info{$group}{'description'});
1.4 raeburn 304: my $creator = $grp_info{$group}{'creator'};
305: my $creation = $grp_info{$group}{'creation'};
306: my $modified = $grp_info{$group}{'modified'};
307: my $quota = $grp_info{$group}{'quota'};
308: my $totalmembers = $grp_info{$group}{'totalmembers'};
309: my $totalfiles = $grp_info{$group}{'totalfiles'};
1.29 raeburn 310: my $totaldirs = $grp_info{$group}{'totaldirs'};
1.4 raeburn 311: my $boards = $grp_info{$group}{'boards'};
312: my $diskuse = $grp_info{$group}{'diskuse'};
313: my $functionality;
1.5 raeburn 314: foreach my $tool (sort(keys(%{$functions}))) {
1.6 raeburn 315: if ($grp_info{$group}{functions}{$tool} eq 'on') {
1.4 raeburn 316: $functionality .= ' '.$tool;
1.3 raeburn 317: }
318: }
1.4 raeburn 319: if (!$functionality) {
1.6 raeburn 320: $functionality = &mt('None available');
1.4 raeburn 321: }
1.5 raeburn 322: my $link = $actionlinks{$action};
1.65 raeburn 323: if ($action eq 'modify' || $action eq 'delete' ||
324: $action eq 'reenable') {
1.5 raeburn 325: $link .= $group;
326: } else {
1.51 raeburn 327: $link .= $group.'/smppg?ref=grouplist';
1.53 raeburn 328: if (exists($env{'form.refpage'})) {
329: $link .= '&refpage='.$env{'form.refpage'};
330: }
1.5 raeburn 331: }
1.21 raeburn 332: $link .= '">'.$lt{$action}.'</a>';
333: if ($action eq 'view') {
1.71 raeburn 334: if ($manage_permission) {
1.21 raeburn 335: $link .= ' '.$actionlinks{'modify'}.
1.64 raeburn 336: $group.'">'.$lt{'modify'}.'</a>'.
337: ' '.$actionlinks{'delete'}.
338: $group.'">'.$lt{'delete'}.'</a>';
1.21 raeburn 339: }
340: }
1.39 albertel 341: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense').
342: '<td>'.$link.'</td>'.
343: '<td>'.$group.'</td>'.
344: '<td>'.$description.'</td>'.
345: '<td>'.$creator.'</td>'.
346: '<td>'. &Apache::lonnavmaps::timeToHumanString($creation).'</td>'.
347: '<td>'. &Apache::lonnavmaps::timeToHumanString($modified).'</td>'.
348: '<td>'.$functionality.'</td>'.
349: '<td align="right">'.$quota.'</td>'.
350: '<td align="right">'.$totalmembers.'</td>'.
1.79 bisitz 351: '<td align="right">'.
1.88 raeburn 352: '<span class="LC_nobreak">'.&mt('Files: [_1]',$totalfiles).'</span><br />'.
353: '<span class="LC_nobreak">'.&mt('Folders: [_1]',$totaldirs).'</span>'.
1.79 bisitz 354: '</td>'.
1.39 albertel 355: '<td align="right">'.$boards.'</td>'.
356: '<td align="right">'.$diskuse.'</td>'.
357: &Apache::loncommon::end_data_table_row());
1.3 raeburn 358: }
1.4 raeburn 359: }
1.39 albertel 360: $r->print(&Apache::loncommon::end_data_table());
1.21 raeburn 361: $r->print('<input type="hidden" name="refpage" '.
362: 'value="'.$env{'form.refpage'}.'" />');
363: if ($action eq 'view') {
364: if (!defined($state)) {
365: $state = 'view';
366: }
367: $r->print('<input type="hidden" name="state" value="'.
368: $state.'" />');
369: }
1.3 raeburn 370: } else {
1.7 raeburn 371: $r->print($lt{'nogr'});
372: if ($manage_permission) {
1.71 raeburn 373: $r->print('<br /><br /><a href="/adm/coursegroups?action=create&refpage='.$env{'form.refpage'}.'">'.$lt{'crng'}.'</a>');
374: if ($action ne 'reenable') {
375: if ($reenable_link) {
376: $r->print($reenable_link);
377: }
1.53 raeburn 378: }
1.7 raeburn 379: } else {
1.29 raeburn 380: $r->print('<br /><br />'.$lt{'alth'});
1.7 raeburn 381: }
1.3 raeburn 382: }
383: } else {
1.4 raeburn 384: my @coursegroups = split(/:/,$env{'request.course.groups'});
385: if (@coursegroups > 0) {
1.7 raeburn 386: $r->print('<br /><br />');
1.17 raeburn 387: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.15 albertel 388: if (%curr_groups) {
1.4 raeburn 389: foreach my $group (@coursegroups) {
1.17 raeburn 390: my %group_info = &Apache::longroup::get_group_settings(
1.5 raeburn 391: $curr_groups{$group});
1.24 www 392: my $description = &unescape(
1.5 raeburn 393: $group_info{description});
1.52 raeburn 394: $r->print('<font size="+1"><a href="/adm/'.$cdom.'/'.$cnum.'/'.$group.'/smppg?ref=grouplist">'.$group,'</a><font><br /><small>'.$description.'</small><br /><br />');
1.4 raeburn 395: }
396: }
397: } else {
1.79 bisitz 398: $r->print(&mt('You are not currently a member of any active '.$gpterm.'s in this '.lc($crstype).'.'));
1.4 raeburn 399: }
1.3 raeburn 400: }
401: return;
402: }
403:
404: sub group_administration {
1.48 albertel 405: my ($r,$action,$state,$cdom,$cnum,$functions,$idx,$view_permission,
406: $manage_permission,$gpterm,$ucgpterm,$crstype) = @_;
1.3 raeburn 407: my %sectioncount = ();
408: my @tools = ();
409: my @types = ();
410: my @roles = ();
411: my @sections = ();
412: my %users = ();
413: my %userdata = ();
414: my @members = ();
415: my %usertools = ();
1.5 raeburn 416: my %stored = ();
417: my %memchg;
1.6 raeburn 418: my @member_changes = ('deletion','expire','activate','reenable',
1.5 raeburn 419: 'changefunc','changepriv');
1.29 raeburn 420: my ($groupname,$description,$startdate,$enddate,$granularity,$specificity,
1.37 raeburn 421: $quota,$validate_script);
1.5 raeburn 422:
423: if (defined($env{'form.groupname'})) {
424: $groupname = $env{'form.groupname'};
425: }
426:
427: if (($action eq 'create') && ($state eq '')) {
428: $state = 'pick_name';
429: }
430: if (($action eq 'create') ||
431: (($action eq 'modify') && ($state eq 'chgresult'))) {
432: ($startdate,$enddate) = &get_dates_from_form();
433: if (defined($env{'form.description'})) {
434: $description = $env{'form.description'};
435: }
436: if (defined($env{'form.tool'})) {
437: @tools=&Apache::loncommon::get_env_multiple('form.tool');
438: }
439: if (defined($env{'form.granularity'})) {
440: $granularity=$env{'form.granularity'};
441: }
442: if (defined($env{'form.specificity'})) {
443: $specificity=$env{'form.specificity'};
444: }
1.29 raeburn 445: if (defined($env{'form.quota'})) {
446: $quota=$env{'form.quota'};
447: }
1.5 raeburn 448: }
449: if (($action eq 'create') || (($action eq 'modify')
450: && (($state eq 'pick_privs') || ($state eq 'addresult')))) {
451: if (defined($env{'form.member'})) {
452: @members = &Apache::loncommon::get_env_multiple('form.member');
453: foreach my $user (@members) {
454: %{$usertools{$user}} = ();
455: }
456: }
457: }
1.3 raeburn 458:
1.5 raeburn 459: if ($action eq 'modify') {
1.3 raeburn 460: if ($state eq '') {
1.21 raeburn 461: if (defined($env{'form.groupname'})) {
462: $state = 'pick_task';
463: }
1.3 raeburn 464: } else {
1.65 raeburn 465: %stored = &retrieve_settings($cdom,$cnum,$groupname,$action);
1.5 raeburn 466: if (ref($stored{'types'}) eq 'ARRAY') {
467: @types = @{$stored{'types'}};
468: }
469: if (ref($stored{'roles'}) eq 'ARRAY') {
470: @roles = @{$stored{'roles'}};
471: }
472: if (ref($stored{'sectionpick'}) eq 'ARRAY') {
473: @sections = @{$stored{'sectionpick'}};
474: }
475: unless ($state eq 'chgresult') {
476: if (ref($stored{'tool'}) eq 'ARRAY') {
477: @tools = @{$stored{'tool'}};
1.3 raeburn 478: }
1.5 raeburn 479: $startdate = $stored{'startdate'};
480: $enddate = $stored{'enddate'};
481: $description = $stored{'description'};
482: $granularity = $stored{'granularity'};
483: $specificity = $stored{'specificity'};
1.29 raeburn 484: $quota = $stored{'quota'};
1.3 raeburn 485: }
486: }
487: }
488:
1.36 raeburn 489: my $toolprivs = &Apache::longroup::get_tool_privs($gpterm);
1.22 albertel 490:
1.36 raeburn 491: my $fixedprivs = &Apache::longroup::get_fixed_privs();
1.22 albertel 492:
493: my %elements =
494: (
495: create => {
496: pick_name => {
497: startdate_month => 'selectbox',
498: startdate_hour => 'selectbox',
499: enddate_month => 'selectbox',
500: enddate_hour => 'selectbox',
501: startdate_day => 'text',
502: startdate_year => 'text',
503: startdate_minute => 'text',
504: startdate_second => 'text',
505: enddate_day => 'text',
506: enddate_year => 'text',
507: enddate_minute => 'text',
508: enddate_second => 'text',
509: groupname => 'text',
510: description => 'text',
1.29 raeburn 511: quota => 'text',
1.22 albertel 512: tool => 'checkbox',
513: granularity => 'radio',
514: no_end_date => 'checkbox',
515: },
516: pick_members => {
517: member => 'checkbox',
518: defpriv => 'checkbox',
519: },
520: },
521: );
522:
523: $elements{'modify'} = {
524: change_settings => {
525: %{$elements{'create'}{'pick_name'}},
526: specificity => 'radio',
527: defpriv => 'checkbox',
528: autorole => 'checkbox',
529: autoadd => 'radio',
530: autodrop => 'radio',
531: },
532: add_members => {
533: types => 'selectbox',
534: roles => 'selectbox',
535: },
536: };
537:
1.5 raeburn 538: if (ref($stored{'autorole'}) eq 'ARRAY') {
539: foreach my $role (@{$stored{'autorole'}}) {
1.104 raeburn 540: unless (($role eq 'cc') || ($role eq 'co')) {
1.17 raeburn 541: $elements{'modify'}{'change_settings'}{'sec_'.$role} =
542: 'selectbox';
543: }
1.5 raeburn 544: }
545: }
546:
1.3 raeburn 547: if (($action eq 'create') && ($state eq 'pick_name')) {
1.5 raeburn 548: $elements{'create'}{'pick_name'}{'types'} = 'selectbox';
549: $elements{'create'}{'pick_name'}{'roles'} = 'selectbox';
550: }
551: if ((($action eq 'create') &&
552: (($state eq 'pick_name') || ($state eq 'pick_privs'))) ||
553: (($action eq 'modify') && (($state eq 'change_settings') ||
554: ($state eq 'add_members')))) {
1.16 albertel 555: %sectioncount = &Apache::loncommon::get_sections($cdom,$cnum);
1.53 raeburn 556: $elements{'create'}{'pick_name'}{'sectionpick'} = 'selectbox';
557: $elements{'modify'}{'change_mapping'}{'sectionpick'} = 'selectbox';
558: $elements{'modify'}{'add_members'}{'sectionpick'} = 'selectbox';
1.3 raeburn 559: }
1.5 raeburn 560:
1.12 raeburn 561: if (($action eq 'create') ||
562: ($action eq 'modify' && $state eq 'pick_members')) {
1.3 raeburn 563: if (defined($env{'form.types'})) {
564: @types=&Apache::loncommon::get_env_multiple('form.types');
565: }
566: if (defined($env{'form.roles'})) {
567: @roles=&Apache::loncommon::get_env_multiple('form.roles');
568: }
569: if (defined($env{'form.sectionpick'})) {
570: @sections=&Apache::loncommon::get_env_multiple('form.sectionpick');
571: }
1.5 raeburn 572: }
573:
1.6 raeburn 574: if (($state eq 'pick_members') || ($state eq 'pick_privs') || ($state eq 'change_privs')) {
1.78 raeburn 575: &build_members_list($cdom,$cnum,\@types,\@roles,\@sections,\%users,
1.6 raeburn 576: \%userdata);
577: }
578: if ($state eq 'pick_members') {
1.3 raeburn 579: if ((keys(%users) > 0) && (@tools > 0)) {
1.7 raeburn 580: if ($granularity eq 'Yes') {
581: $elements{$action}{'pick_members'}{'togglefunc'} = 'checkbox';
582: }
1.3 raeburn 583: foreach my $tool (@tools) {
1.5 raeburn 584: if ($granularity eq 'Yes') {
585: $elements{$action}{'pick_members'}{'user_'.$tool} = 'checkbox';
1.3 raeburn 586: }
587: }
1.5 raeburn 588: $elements{$action}{'pick_members'}{'specificity'} = 'radio';
1.3 raeburn 589: }
590: }
1.6 raeburn 591: if ($state eq 'change_members') {
592: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
593: $groupname);
594: my $now = time;
595: my $num_expire = 0;
596: my $num_activate = 0;
597: my $num_reenable = 0;
598: my $num_deletion = 0;
599: my $numusers = 0;
600: foreach my $key (sort(keys(%membership))) {
601: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
602: my $user = $1;
603: my($end,$start,@userprivs) = split(/:/,$membership{$key});
604: unless ($start == -1) {
605: $numusers ++;
606: $num_deletion ++;
607: if (($end > 0) && ($end < $now)) {
608: $num_reenable ++;
609: next;
610: } elsif (($start > $now)) {
1.52 raeburn 611: $num_activate ++;
1.6 raeburn 612: next;
613: } else {
614: $num_expire ++;
615: next;
616: }
617: next;
618: }
619: if ($num_reenable && $num_activate && $num_expire) {
620: last;
621: }
622: }
623: }
624: if ($num_deletion) {
625: $elements{$action}{'change_members'}{'deletion'} = 'checkbox';
626: }
627: if ($num_expire) {
628: $elements{$action}{'change_members'}{'expire'} = 'checkbox';
629: }
630: if ($num_activate) {
631: $elements{$action}{'change_members'}{'activate'} = 'checkbox';
632: }
633: if ($num_reenable) {
634: $elements{$action}{'change_members'}{'reenable'} = 'checkbox';
635: }
636: if ($numusers) {
1.7 raeburn 637: if ($granularity eq 'Yes') {
638: $elements{$action}{'change_members'}{'togglefunc'} = 'checkbox';
639: }
1.6 raeburn 640: foreach my $tool (@tools) {
641: if ($granularity eq 'Yes') {
642: $elements{$action}{'change_members'}{'user_'.$tool} = 'checkbox';
643: }
644: }
645: if ($specificity eq 'Yes') {
646: $elements{$action}{'change_members'}{'changepriv'} = 'checkbox';
647: }
648: }
649: }
1.3 raeburn 650:
1.5 raeburn 651: if (($state eq 'pick_privs') || ($state eq 'change_privs') ||
1.21 raeburn 652: (($specificity eq 'No') &&
653: ($state eq 'memresult' || $state eq 'result' || $state eq 'addresult'))) {
1.3 raeburn 654: foreach my $tool (@tools) {
655: my @values = &Apache::loncommon::get_env_multiple('form.user_'.$tool);
656: foreach my $user (@values) {
1.21 raeburn 657: if ($state eq 'pick_privs' || $state eq 'result'
658: || $state eq 'addresult') {
659: if (!grep(/^\Q$user\E$/,@members)) {
660: next;
661: }
662: }
1.3 raeburn 663: unless(exists($usertools{$user}{$tool})) {
664: $usertools{$user}{$tool} = 1;
665: }
666: }
667: }
1.6 raeburn 668: }
669:
670: if (($action eq 'modify') && (($state eq 'change_privs') || ($state eq 'memresult'))) {
671: foreach my $chg (@member_changes) {
672: if (defined($env{'form.'.$chg})) {
673: @{$memchg{$chg}} = &Apache::loncommon::get_env_multiple('form.'.$chg);
674: }
675: }
676:
677: if ($state eq 'change_privs') {
678: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
679: $groupname);
680: my $now = time;
681: foreach my $key (sort(keys(%membership))) {
682: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
683: my $user = $1;
684: my $changefunc = 0;
685: my ($end,$start,@userprivs) = split(/:/,$membership{$key});
686: unless ($start == -1) {
687: if (($end > 0) && ($end < $now)) {
688: unless (grep/^$user$/,$memchg{'reenable'}) {
689: next;
690: }
691: }
692: my @currtools = ();
693: if (@userprivs > 0) {
1.36 raeburn 694: foreach my $tool (sort(keys(%{$fixedprivs}))) {
695: foreach my $priv (keys(%{$$fixedprivs{$tool}})) {
1.6 raeburn 696: if (grep/^$priv$/,@userprivs) {
697: push(@currtools,$tool);
698: last;
699: }
700: }
701: }
1.3 raeburn 702: }
1.6 raeburn 703: foreach my $tool (@currtools) {
704: if (keys(%{$usertools{$user}}) > 0) {
705: if (!$usertools{$user}{$tool}) {
706: push(@{$memchg{'changefunc'}},$user);
707: $changefunc = 1;
708: last;
709: }
710: } else {
711: push(@{$memchg{'changefunc'}},$user);
712: $changefunc = 1;
713: }
714: }
715: if ($changefunc) {
716: next;
717: }
718: if (keys(%{$usertools{$user}}) > 0) {
719: foreach my $tool (keys(%{$usertools{$user}})) {
720: if (!grep/^$tool$/,@currtools) {
721: push(@{$memchg{'changefunc'}},$user);
722: $changefunc = 1;
723: last;
724: }
725: }
726: }
727: }
728: }
729: }
730: &check_changes(\@member_changes,\%memchg);
731: my %temptools;
732: foreach my $change (@member_changes) {
733: if (($change eq 'deletion') || ($change eq 'expire')) {
734: next;
735: }
736: foreach my $user (@{$memchg{$change}}) {
737: unless (exists($usertools{$user})) {
738: %{$usertools{$user}} = ();
739: }
740: %{$temptools{$user}} = %{$usertools{$user}};
741: }
742: }
743: %usertools = %temptools;
744: } elsif ($state eq 'memresult') {
745: foreach my $change (@member_changes) {
746: if ($change eq 'expire' || $change eq 'deletion') {
747: next;
748: }
749: if (ref($memchg{$change}) eq 'ARRAY') {
750: my @users = @{$memchg{$change}};
751: foreach my $user (@users) {
752: unless (exists($usertools{$user})) {
753: %{$usertools{$user}} = ();
754: }
755: }
756: }
757: }
758: }
759: }
760:
761: if ((($state eq 'pick_privs') || ($state eq 'change_privs'))
762: && ($specificity eq 'Yes')) {
763: foreach my $user (sort(keys(%usertools))) {
764: foreach my $tool (keys(%{$usertools{$user}})) {
1.36 raeburn 765: foreach my $priv (keys(%{$$toolprivs{$tool}})) {
766: unless (exists($$fixedprivs{$tool}{$priv})) {
1.6 raeburn 767: $elements{$action}{$state}{'userpriv_'.$priv} = 'checkbox';
1.3 raeburn 768: }
769: }
770: }
771: }
772: }
1.37 raeburn 773:
774: if (($action eq 'create' && $state eq 'pick_name') ||
775: ($action eq 'modify' && $state eq 'change_settings')) {
776: my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,\%stored);
777: my $space_trim = '/^\s*|\s*\$/g,""';
778: my $float_check = '/^([0-9]*\.?[0-9]*)$/';
779: $validate_script = '
1.53 raeburn 780: var newquota = new String(document.'.$state.'.quota.value);
1.37 raeburn 781: newquota.replace('.$space_trim.');
782: if (newquota == "" ) {
783: document.'.$state.'.quota.value = 0;
1.53 raeburn 784: newquota = "0";
1.37 raeburn 785: }
1.53 raeburn 786: var maxposs = '.sprintf("%.2f",$maxposs).';
1.37 raeburn 787: if (newquota > maxposs) {
1.96 weissno 788: alert("The group portfolio quota you entered for this group ("+newquota+" Mb) exceeds the maximum possible ("+maxposs+" Mb). Please enter a smaller number.");
1.37 raeburn 789: return;
790: }
791: var re_quota = '.$float_check.';
792: var check_quota = newquota.match(re_quota);
793: if (check_quota == null) {
794: alert("The quota you entered contains invalid characters, the quota should only include numbers, with or without a decimal point.");
795: return;
796: }
797: if (newquota == 0) {
798: var warn_zero = 0;
799: for (var i=0; i<document.'.$state.'.tool.length; i++) {
800: if (document.'.$state.'.tool[i].value == "files") {
801: if (document.'.$state.'.tool[i].checked) {
802: warn_zero = 1;
803: }
804: }
805: }
806: if (warn_zero == 1) {
1.96 weissno 807: alert("You have indicated that the group portfolio should be enabled, but you have set the respository quota to 0 Mb.\nThis will prevent any upload of files.\nPlease set a value or disable the repository feature.");
1.37 raeburn 808: return;
809: }
810: }
811: ';
812: }
1.5 raeburn 813: my $jscript = &Apache::loncommon::check_uncheck_jscript();
1.3 raeburn 814: $jscript .= qq|
815: function nextPage(formname,nextstate) {
816: formname.state.value= nextstate;
1.37 raeburn 817: $validate_script
1.3 raeburn 818: formname.submit();
819: }
820: function backPage(formname,prevstate) {
821: formname.state.value = prevstate;
822: formname.submit();
823: }
1.6 raeburn 824: function changeSort(caller) {
825: document.$state.state.value = '$state';
826: document.$state.sortby.value = caller;
827: document.$state.submit();
828: }
1.15 albertel 829:
1.3 raeburn 830: |;
831: $jscript .= &Apache::lonhtmlcommon::set_form_elements(
1.5 raeburn 832: \%{$elements{$action}{$state}},\%stored);
833: my $page = 0;
834: my %states = ();
835: my %branchstates = ();
836: @{$states{'create'}} = ('pick_name','pick_members','pick_privs','result');
1.53 raeburn 837: @{$states{'modify'}} = ('pick_task');
1.64 raeburn 838: @{$states{'delete'}} = ('verify','result');
1.65 raeburn 839: @{$states{'reenable'}} = ('verify','result');
1.5 raeburn 840: @{$branchstates{'noprivs'}} = ('result');
841: @{$branchstates{'settings'}} = ('change_settings','chgresult');
842: @{$branchstates{'members'}} = ('change_members','change_privs','memresult');
843: @{$branchstates{'adds'}} = ('add_members','pick_members','pick_privs',
844: 'addresult');
1.21 raeburn 845:
1.5 raeburn 846: if (defined($env{'form.branch'})) {
847: push (@{$states{$action}},@{$branchstates{$env{'form.branch'}}});
848: }
849:
1.65 raeburn 850: if (($action eq 'create') || ($action eq 'modify') || ($action eq 'delete') || ($action eq 'reenable')) {
1.5 raeburn 851: my $done = 0;
852: my $i=0;
853: while ($i<@{$states{$action}} && !$done) {
854: if ($states{$action}[$i] eq $state) {
855: $page = $i;
856: $done = 1;
857: }
858: $i++;
859: }
860: }
1.3 raeburn 861:
862: my $loaditems = &onload_action($action,$state);
1.53 raeburn 863: $r->print(&header("Groups Manager",
1.39 albertel 864: $jscript,$action,$state,$page,$loaditems));
1.1 raeburn 865:
1.71 raeburn 866: if ($env{'form.refpage'} eq 'cusr') {
1.3 raeburn 867: &Apache::lonhtmlcommon::add_breadcrumb
1.71 raeburn 868: ({href=>"/adm/createuser",
869: text=>"User Management",
1.3 raeburn 870: faq=>9,bug=>'Instructor Interface',});
1.64 raeburn 871: if ($action eq 'modify' || $action eq 'delete') {
1.53 raeburn 872: &Apache::lonhtmlcommon::add_breadcrumb
1.71 raeburn 873: ({href=>"/adm/coursegroups?refpage=cusr&action=$action",
1.53 raeburn 874: text=>"Groups",
875: faq=>9,bug=>'Instructor Interface',});
876: }
877: } else {
1.1 raeburn 878: &Apache::lonhtmlcommon::add_breadcrumb
1.53 raeburn 879: ({href=>"/adm/coursegroups",
880: text=>"Groups",
881: faq=>9,bug=>'Instructor Interface',});
1.54 raeburn 882: if ($env{'form.refpage'} eq 'grouplist') {
883: &Apache::lonhtmlcommon::add_breadcrumb
884: ({href=>"/adm/$cdom/$cnum/$env{'form.groupname'}/smppg?ref=grouplist",
885: text=>"Group: $description",});
886: }
1.3 raeburn 887: }
888:
889: my %trail = ();
1.5 raeburn 890: %{$trail{'create'}} = &Apache::lonlocal::texthash (
1.29 raeburn 891: pick_name => $ucgpterm.' Settings',
1.3 raeburn 892: pick_members => 'Select Members',
893: pick_privs => 'Choose Privileges',
894: result => 'Creation Complete',
895: );
1.5 raeburn 896: %{$trail{'modify'}} = &Apache::lonlocal::texthash(
897: pick_task => 'Choose Task',
1.29 raeburn 898: change_settings => "$ucgpterm Settings",
1.5 raeburn 899: change_members => 'Modify/Delete Members',
900: change_privs => 'Change Privileges',
901: change_mapping => 'Membership Mapping',
902: add_members => 'Add Members',
903: pick_members => 'Select Members',
904: pick_privs => 'Choose Privileges',
905: chgresult => 'Setting Changes Complete',
906: memresult => 'Modifications Complete',
907: addresult => 'Additions Complete',
908: );
1.64 raeburn 909: %{$trail{'delete'}} = &Apache::lonlocal::texthash(
910: verify => 'Verify deletion',
911: result => 'Deletion Complete'
912: );
1.65 raeburn 913: %{$trail{'reenable'}} = &Apache::lonlocal::texthash(
914: verify => 'Verify Re-enable',
915: result => 'Re-enabled'
916: );
1.5 raeburn 917: my %navbuttons = &Apache::lonlocal::texthash(
1.91 schafran 918: gtns => 'Next',#'Go to next step',
1.93 schafran 919: gtps => 'Back',#'Go to previous step',
1.29 raeburn 920: crgr => 'Create '.$gpterm,
1.91 schafran 921: mose => 'Save',#'Modify settings',
1.93 schafran 922: gtpp => 'Back',#'Go to previous page',
1.5 raeburn 923: adme => 'Add members',
924: );
1.65 raeburn 925: if ((($action eq 'create') || ($action eq 'modify') || ($action eq 'delete') || ($action eq 'reenable')) &&
1.3 raeburn 926: ($manage_permission)) {
927: for (my $i=0; $i<@{$states{$action}}; $i++) {
928: if ($state eq $states{$action}[$i]) {
929: &Apache::lonhtmlcommon::add_breadcrumb(
930: {text=>"$trail{$action}{$state}"});
931: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.61 raeburn 932: ("Groups Manager","Creating_Groups"));
1.48 albertel 933: &display_control($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 934: \%sectioncount,$groupname,$description,$functions,
1.36 raeburn 935: \@tools,$toolprivs,$fixedprivs,$startdate,$enddate,
1.5 raeburn 936: \%users,\%userdata,$idx,\%memchg,\%usertools,
1.45 albertel 937: $view_permission,$manage_permission,
1.29 raeburn 938: \%stored,$granularity,$quota,$specificity,\@types,\@roles,
1.48 albertel 939: \@sections,\%states,\%navbuttons,$gpterm,$ucgpterm,
940: $crstype);
1.3 raeburn 941: last;
942: } else {
1.64 raeburn 943: if (($action eq 'create') || ($action eq 'modify')) {
944: if (($state eq 'result') && ($i > 0)) {
945: &Apache::lonhtmlcommon::add_breadcrumb(
1.3 raeburn 946: {href=>"javascript:backPage(document.$state,'$states{$action}[0]')",
947: text=>"$trail{$action}{$states{$action}[$i]}"});
1.64 raeburn 948: } else {
949: &Apache::lonhtmlcommon::add_breadcrumb(
1.3 raeburn 950: {href=>"javascript:backPage(document.$state,'$states{$action}[$i]')",
951: text=>"$trail{$action}{$states{$action}[$i]}"});
1.64 raeburn 952: }
1.3 raeburn 953: }
1.64 raeburn 954: }
1.3 raeburn 955: }
956: } elsif (($action eq 'view') && ($view_permission)) {
957: &Apache::lonhtmlcommon::add_breadcrumb(
1.29 raeburn 958: {text=>"View $gpterm".'s'});
1.1 raeburn 959: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.53 raeburn 960: ('Groups Manager'));
1.39 albertel 961: &display_groups($r,$cdom,$cnum,$functions,$idx,$view_permission,
962: $manage_permission,$action,$state,$gpterm,$ucgpterm,
963: $crstype);
1.3 raeburn 964: }
965: $r->print(&footer());
966: return;
967: }
968:
1.5 raeburn 969: sub retrieve_settings {
1.65 raeburn 970: my ($cdom,$cnum,$groupname,$action) = @_;
971: my %curr_groups;
972: my $namespace;
973: if ($action eq 'reenable') {
974: $namespace = 'deleted_groups';
975: } else {
976: $namespace = 'coursegroups';
977: }
978: %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$groupname,
979: $namespace);
1.15 albertel 980:
981: return if (!%curr_groups);
982:
983: my %groupinfo =
1.17 raeburn 984: &Apache::longroup::get_group_settings($curr_groups{$groupname});
1.15 albertel 985:
1.5 raeburn 986: my %stored;
1.15 albertel 987:
988: $stored{'description'} =
1.24 www 989: &unescape($groupinfo{'description'});
1.15 albertel 990: $stored{'startdate'} = $groupinfo{'startdate'};
991: $stored{'enddate'} = $groupinfo{'enddate'};
992: if ($stored{'enddate'} == 0) {
993: $stored{'no_end_date'} = 1;
994: }
995: $stored{'granularity'} = $groupinfo{'granularity'};
996: $stored{'specificity'} = $groupinfo{'specificity'};
997: $stored{'creation'} = $groupinfo{'creation'};
998: $stored{'creator'} = $groupinfo{'creator'};
1.29 raeburn 999: $stored{'quota'} = $groupinfo{'quota'};
1.15 albertel 1000:
1001: foreach my $tool (sort(keys(%{$groupinfo{'functions'}}))) {
1002: if ($groupinfo{functions}{$tool} eq 'on') {
1003: push(@{$stored{tool}},$tool);
1004: }
1005: }
1006: foreach my $role (@{$groupinfo{'roles'}}) {
1007: push(@{$stored{roles}},$role);
1008: }
1009: foreach my $type (@{$groupinfo{'types'}}) {
1010: push(@{$stored{types}},$type);
1011: }
1012: foreach my $section (@{$groupinfo{'sectionpick'}}) {
1013: push(@{$stored{sectionpick}},$section);
1014: }
1015: foreach my $defpriv (@{$groupinfo{'defpriv'}}) {
1016: push(@{$stored{defpriv}},$defpriv);
1017: }
1018: $stored{'autoadd'} = $groupinfo{'autoadd'};
1019: $stored{'autodrop'} = $groupinfo{'autodrop'};
1020: if (exists($groupinfo{'autosec'})) {
1021: foreach my $role (sort(keys(%{$groupinfo{'autosec'}}))) {
1.17 raeburn 1022: if (ref($groupinfo{'autosec'}{$role}) eq 'ARRAY') {
1023: foreach my $section (@{$groupinfo{'autosec'}{$role}}) {
1.58 raeburn 1024:
1.17 raeburn 1025: push (@{$stored{'sec_'.$role}},$section);
1026: }
1027: if (@{$groupinfo{'autosec'}{$role}} > 0) {
1028: push(@{$stored{'autorole'}},$role);
1029: }
1030: }
1.15 albertel 1031: }
1.5 raeburn 1032: }
1033: return %stored;
1034: }
1035:
1.3 raeburn 1036: sub display_control {
1.48 albertel 1037: my ($r,$cdom,$cnum,$action,$state,$page,$sectioncount,$groupname,
1.3 raeburn 1038: $description,$functions,$tools,$toolprivs,$fixedprivs,$startdate,
1.45 albertel 1039: $enddate,$users,$userdata,$idx,$memchg,$usertools,
1.29 raeburn 1040: $view_permission,$manage_permission,$stored,$granularity,$quota,
1.48 albertel 1041: $specificity,$types,$roles,$sections,$states,$navbuttons,
1042: $gpterm,$ucgpterm,$crstype) = @_;
1.3 raeburn 1043: if ($action eq 'create') {
1044: if ($state eq 'pick_name') {
1.46 albertel 1045: &general_settings_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1046: $functions,$tools,$toolprivs,$fixedprivs,
1047: $sectioncount,$stored,$states,$navbuttons,
1.46 albertel 1048: $gpterm,$ucgpterm,$crstype);
1.3 raeburn 1049: } elsif ($state eq 'pick_members') {
1.46 albertel 1050: &choose_members_form($r,$cdom,$cnum,$action,$state,$page,
1.29 raeburn 1051: $groupname,$description,$granularity,$quota,
1.5 raeburn 1052: $startdate,$enddate,$tools,$fixedprivs,
1053: $toolprivs,$functions,$users,$userdata,$idx,
1.46 albertel 1054: $stored,$states,$navbuttons,$gpterm,$ucgpterm,
1055: $crstype);
1.3 raeburn 1056: } elsif ($state eq 'pick_privs') {
1.45 albertel 1057: &choose_privs_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1058: $startdate,$enddate,$tools,$functions,
1059: $toolprivs,$fixedprivs,$userdata,$usertools,
1060: $idx,$states,$stored,$sectioncount,$navbuttons,
1.45 albertel 1061: $gpterm,$ucgpterm,$crstype);
1.3 raeburn 1062: } elsif ($state eq 'result') {
1.45 albertel 1063: &process_request($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1064: $groupname,$description,$specificity,$userdata,
1065: $startdate,$enddate,$tools,$functions,
1066: $toolprivs,$usertools,$idx,$types,$roles,
1067: $sections,$states,$navbuttons,$memchg,
1.45 albertel 1068: $sectioncount,$stored,$gpterm,$ucgpterm,$crstype);
1.5 raeburn 1069: }
1070: } elsif ($action eq 'modify') {
1071: my $groupname = $env{'form.groupname'};
1.53 raeburn 1072: if ($state eq 'pick_task') {
1.29 raeburn 1073: &modify_menu($r,$groupname,$page,$gpterm);
1.5 raeburn 1074: } elsif ($state eq 'change_settings') {
1.46 albertel 1075: &general_settings_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1076: $functions,$tools,$toolprivs,$fixedprivs,
1077: $sectioncount,$stored,$states,$navbuttons,
1.46 albertel 1078: $gpterm,$ucgpterm,$crstype);
1.5 raeburn 1079: } elsif ($state eq 'change_members') {
1.48 albertel 1080: &change_members_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1081: $groupname,$description,$startdate,$enddate,
1082: $tools,$fixedprivs,$functions,$users,
1.29 raeburn 1083: $userdata,$granularity,$quota,$specificity,
1.48 albertel 1084: $idx,$states,$navbuttons,$gpterm,$ucgpterm);
1.5 raeburn 1085: } elsif ($state eq 'add_members') {
1.59 raeburn 1086: &add_members_form($r,$cdom,$cnum,$action,$state,$page,$startdate,
1.5 raeburn 1087: $enddate,$groupname,$description,$granularity,
1.29 raeburn 1088: $quota,$sectioncount,$tools,$functions,$stored,
1.104 raeburn 1089: $states,$navbuttons,$gpterm,$ucgpterm,$crstype);
1.5 raeburn 1090: } elsif ($state eq 'pick_members') {
1.46 albertel 1091: &choose_members_form($r,$cdom,$cnum,$action,$state,$page,
1.29 raeburn 1092: $groupname,$description,$granularity,$quota,
1.5 raeburn 1093: $startdate,$enddate,$tools,$fixedprivs,
1094: $toolprivs,$functions,$users,$userdata,$idx,
1.46 albertel 1095: $stored,$states,$navbuttons,$gpterm,$ucgpterm,
1096: $crstype);
1.5 raeburn 1097: } elsif ($state eq 'pick_privs') {
1.46 albertel 1098: &choose_privs_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1099: $startdate,$enddate,$tools,$functions,
1100: $toolprivs,$fixedprivs,$userdata,$usertools,
1101: $idx,$states,$stored,$sectioncount,$navbuttons,
1.46 albertel 1102: $gpterm,$ucgpterm,$crstype);
1.5 raeburn 1103: } elsif ($state eq 'change_privs') {
1.45 albertel 1104: &change_privs_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1105: $startdate,$enddate,$tools,$functions,
1106: $toolprivs,$fixedprivs,$userdata,$usertools,
1107: $memchg,$idx,$states,$stored,$sectioncount,
1.45 albertel 1108: $navbuttons,$gpterm,$ucgpterm);
1.5 raeburn 1109: } elsif ($state eq 'chgresult' || $state eq 'memresult' ||
1110: $state eq 'addresult') {
1.45 albertel 1111: &process_request($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1112: $groupname,$description,$specificity,$userdata,
1113: $startdate,$enddate,$tools,$functions,
1114: $toolprivs,$usertools,$idx,$types,$roles,
1115: $sections,$states,$navbuttons,$memchg,
1.45 albertel 1116: $sectioncount,$stored,$gpterm,$ucgpterm,$crstype);
1.1 raeburn 1117: }
1.64 raeburn 1118: } elsif ($action eq 'delete') {
1.65 raeburn 1119: my %stored = &retrieve_settings($cdom,$cnum,$groupname,$action);
1.64 raeburn 1120: if ($state eq 'verify') {
1121: &verify_delete($r,$groupname,$state,$action,$page,$states,
1.104 raeburn 1122: \%stored,$crstype);
1.64 raeburn 1123: } elsif ($state eq 'result') {
1.104 raeburn 1124: &delete_group($r,$cdom,$cnum,$groupname,$crstype);
1.64 raeburn 1125: }
1.65 raeburn 1126: } elsif ($action eq 'reenable') {
1127: my %stored = &retrieve_settings($cdom,$cnum,$groupname,$action);
1128: if ($state eq 'verify') {
1129: &verify_reenable($r,$groupname,$state,$action,$page,$states,
1.104 raeburn 1130: \%stored,$crstype);
1.65 raeburn 1131: } elsif ($state eq 'result') {
1.104 raeburn 1132: &reenable_group($r,$cdom,$cnum,$groupname,$crstype);
1.65 raeburn 1133: }
1.64 raeburn 1134: }
1135: }
1136:
1137: sub verify_delete {
1.104 raeburn 1138: my ($r,$groupname,$formname,$action,$page,$states,$stored,$crstype) = @_;
1.64 raeburn 1139: $r->print(&Apache::lonhtmlcommon::echo_form_input([]));
1.79 bisitz 1140: $r->print(&mt('You have requested deletion of the group [_1].'
1141: ,'<i>'.$stored->{'description'}.'</i>').
1.64 raeburn 1142: '<br /><br />'.&mt('When a group is deleted the following occurs:').'<ul>'.
1143: '<li>'.&mt('All group membership is terminated.').'</li>'.
1.104 raeburn 1144: '<li>'.&mt('The group ceases to be available either for viewing or for modification of group settings and membership.').'</li>');
1145: if ($crstype eq 'Community') {
1146: $r->print( '<li>'.&mt("The group folder is removed from the folder containing it - normally this is the 'Community Groups' folder which contains folders for all groups in the community.").'</li>'.
1147: '</ul>'.&mt("Although a deleted group is no longer accessible, the group name used for the group will be reserved, and will not be available for assignment to a new group in the same community in the future."));
1148: } else {
1149: $r->print( '<li>'.&mt("The group folder is removed from the folder containing it - normally this is the 'Course Groups' folder which contains folders for all groups in the course.").'</li>'.
1150: '</ul>'.&mt("Although a deleted group is no longer accessible, the group name used for the group will be reserved, and will not be available for assignment to a new group in the same course in the future."));
1151: }
1.64 raeburn 1152: my $prevtext = &mt('Go back');
1153: my $nexttext = &mt('Delete group');
1154: my $prev;
1.71 raeburn 1155: if ($env{'form.refpage'} eq 'cusr') {
1.64 raeburn 1156: $prev = 'view';
1157: }
1158: &display_navbuttons($r,$formname,$prev,$prevtext,
1159: $$states{$action}[$page+1],$nexttext);
1160: return;
1161: }
1162:
1163: sub delete_group {
1.104 raeburn 1164: my ($r,$cdom,$cnum,$groupname,$crstype) = @_;
1.64 raeburn 1165: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
1166: $groupname);
1167: my $now = time;
1168: my $num_users = 0;
1169: my $num_fail = 0;
1170: my $num_ok = 0;
1171: my @deleted;
1172: my @undeleted;
1173: my %usersettings;
1.77 raeburn 1174: my $context = 'deletegroup';
1.64 raeburn 1175: foreach my $key (sort(keys(%membership))) {
1176: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
1177: my $user = $1;
1.65 raeburn 1178: my($end,$start,$userprivs) = split(/:/,$membership{$key},3);
1.64 raeburn 1179: if ($start != -1) {
1180: $num_users ++;
1.65 raeburn 1181: $usersettings{$groupname.':'.$user} = $now.':-1:'.$userprivs;
1.64 raeburn 1182: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,
1183: $groupname,$user,
1.76 raeburn 1184: $now,'-1',$userprivs,
1185: '',$context)
1.64 raeburn 1186: eq 'ok') {
1187: $num_ok ++;
1188: push(@deleted,$user);
1189: } else {
1190: push(@undeleted,$user);
1191: $num_fail ++;
1192: }
1193: }
1194: }
1195: }
1196: if ($num_ok > 0) {
1197: my $roster_result =
1198: &Apache::lonnet::modify_coursegroup_membership($cdom,$cnum,
1199: \%usersettings);
1200: }
1201: if ($num_fail > 0) {
1.79 bisitz 1202: $r->print('<div class="LC_error">'
1203: .&mt('Group deletion failed because deletion of [_1] out of [_2] members failed.'
1204: ,$num_fail,$num_users)
1205: .'</div>');
1.64 raeburn 1206: } else {
1207: my ($result,$message) =
1.65 raeburn 1208: &Apache::lonnet::toggle_coursegroup_status($cdom,$cnum,
1209: $groupname,'delete');
1.64 raeburn 1210: if ($result eq 'ok') {
1.104 raeburn 1211: my $outcome = &modify_folders($cdom,$cnum,$groupname,$crstype);
1.64 raeburn 1212: if ($outcome eq '') {
1.79 bisitz 1213: $r->print('<div class="LC_success">'
1214: .&mt('Group successfully deleted.')
1215: .'</div>');
1.64 raeburn 1216: } else {
1.104 raeburn 1217: $r->print('<div class="LC_error">');
1.105 bisitz 1218: if ($crstype eq 'Community') {
1.104 raeburn 1219: $r->print(&mt("Although the group was deleted, an error occurred when removing the group's folder from the 'Community Groups' folder: [_1]",$outcome));
1220: } else {
1221: $r->print(&mt("Although the group was deleted, an error occurred when removing the group's folder from the 'Course Groups' folder: [_1]",$outcome));
1222: }
1223: $r->print('</div>');
1.64 raeburn 1224: }
1225: } else {
1.79 bisitz 1226: $r->print('<div class="LC_error">'
1227: .&mt('Group deletion failed.')
1228: .'</div>');
1.64 raeburn 1229: }
1.1 raeburn 1230: }
1.64 raeburn 1231: return;
1232: }
1233:
1.65 raeburn 1234: sub reenable_folder {
1.104 raeburn 1235: my ($cdom,$cnum,$groupname,$description,$crstype) = @_;
1.65 raeburn 1236: my $outcome;
1237: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
1238: my $allgrpsmap = $crspath.'group_allfolders.sequence';
1.104 raeburn 1239: my $foldertitle;
1240: if ($crstype eq 'Community') {
1241: $foldertitle = &mt("Community Folder -[_1]",$description);
1242: } else {
1243: $foldertitle = &mt("Course Folder -[_1]",$description);
1244: }
1.65 raeburn 1245: my $mapurl = $crspath.'group_folder_'.
1246: $groupname.'.sequence';
1247: my ($errtext,$fatal)=&LONCAPA::map::mapread($allgrpsmap);
1248: if ($fatal) {
1.79 bisitz 1249: $outcome='<div class="LC_error">'
1250: .&mt('An error occurred when reading contents of parent folder to group:')
1251: ."<br />($allgrpsmap): $errtext"
1252: .'</div>';
1.65 raeburn 1253: } else {
1254: my $idx=&LONCAPA::map::getresidx($mapurl);
1255: $LONCAPA::map::resources[$idx] = $foldertitle.':'.$mapurl.
1256: ':false:normal:res';
1257: $LONCAPA::map::order[1+$#LONCAPA::map::order]=$idx;
1258: my ($outtext,$errtext) = &LONCAPA::map::storemap($allgrpsmap,1);
1259: if ($errtext) {
1.79 bisitz 1260: $outcome='<div class="LC_error">'
1261: .&mt('An error occurred when saving updated parent folder to group:'
1262: ,"<br />$allgrpsmap - $errtext")
1263: .'</div>';
1.65 raeburn 1264: } else {
1265: my ($furl,$ferr) =
1266: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1267: }
1268: }
1269: return $outcome;
1270: }
1271:
1.64 raeburn 1272: sub modify_folders {
1.104 raeburn 1273: my ($cdom,$cnum,$groupname,$crstype) = @_;
1.85 raeburn 1274: my ($outcome,$groupmap,$groupmapres,$map,$id,$src);
1.64 raeburn 1275: my $navmap = Apache::lonnavmaps::navmap->new();
1.85 raeburn 1276: if (!defined($navmap)) {
1.104 raeburn 1277: $outcome = '<div class="LC_error">';
1278: if ($crstype eq 'Community') {
1279: $outcome .= &mt("Error reading community contents.").' '.
1280: &mt("You need to re-initialize the community.");
1281: } else {
1282: $outcome .= &mt("Error reading course contents.").' '.
1283: &mt("You need to re-initialize the course.");
1284: }
1285: $outcome .= '</div>';
1.85 raeburn 1286: return $outcome;
1287: }
1288: $groupmap = '/uploaded/'.$cdom.'/'.$cnum.'/'.'group_folder_'.
1.64 raeburn 1289: $groupname.'.sequence';
1.85 raeburn 1290: $groupmapres = $navmap->getResourceByUrl($groupmap);
1.64 raeburn 1291: if ($groupmapres) {
1.65 raeburn 1292: ($map,$id,$src)=&Apache::lonnet::decode_symb($groupmapres->symb());
1293: }
1294: undef($navmap);
1295: if ($map) {
1.64 raeburn 1296: $map = '/'.$map;
1297: my ($errtext,$fatal) = &LONCAPA::map::mapread($map);
1298: if ($fatal) {
1.79 bisitz 1299: $outcome='<div class="LC_error">'
1300: .&mt('An error occurred when reading contents of parent folder to group:')
1301: ."<br />($map): $errtext"
1302: .'</div>';
1.64 raeburn 1303: } else {
1304: my $idx = 0;
1305: my $grpidx;
1306: foreach my $item (@LONCAPA::map::order) {
1307: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$item]);
1308: $url=&LONCAPA::map::qtescape($url);
1309: if ($url eq $groupmap) {
1310: $grpidx = $idx;
1311: last;
1312: } else {
1313: $idx++;
1314: }
1315: }
1316:
1317: if ($grpidx ne '') {
1318: &LONCAPA::map::makezombie($LONCAPA::map::order[$grpidx]);
1319: for (my $i=$grpidx;$i<$#LONCAPA::map::order;$i++) {
1320: $LONCAPA::map::order[$i] = $LONCAPA::map::order[$i+1];
1321: }
1322: $#LONCAPA::map::order--;
1323: my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1);
1.65 raeburn 1324: if ($errtext) {
1.79 bisitz 1325: $outcome='<div class="LC_error">'
1326: .&mt('An error occurred when saving updated parent folder to group:')
1327: ."<br />$map - $errtext"
1328: .'</div>';
1.65 raeburn 1329: } else {
1330: my ($furl,$ferr) =
1331: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1332: }
1333: }
1334: }
1335: }
1336: return $outcome;
1337: }
1338:
1339: sub verify_reenable {
1.104 raeburn 1340: my ($r,$groupname,$formname,$action,$page,$states,$stored,$crstype) = @_;
1.65 raeburn 1341: $r->print(&Apache::lonhtmlcommon::echo_form_input([]));
1.79 bisitz 1342: $r->print(&mt('You have requested enabling the previously deleted group [_1].'
1343: ,'<i>'.$stored->{'description'}.'</i>').
1.65 raeburn 1344: '<br /><br />'.&mt('When a deleted group is re-enabled the following occurs:').'<ul>'.
1.104 raeburn 1345: '<li>'.&mt('Group settings and membership at the time the group was deleted are reinstated.').'</li><li>');
1346: if ($crstype eq 'Community') {
1347: $r->print(&mt("A group folder is added to the 'Community Groups' folder which contains folders for all groups in the community."));
1348: } else {
1349: $r->print(&mt("A group folder is added to the 'Course Groups' folder which contains folders for all groups in the course."));
1350: }
1351: $r->print('</li></ul>');
1.65 raeburn 1352: my $prevtext = &mt('Go back');
1353: my $nexttext = &mt('Reenable group');
1354: my $prev;
1.71 raeburn 1355: if ($env{'form.refpage'} eq 'cusr') {
1.65 raeburn 1356: $prev = 'view';
1357: }
1358: &display_navbuttons($r,$formname,$prev,$prevtext,
1359: $$states{$action}[$page+1],$nexttext);
1360: return;
1361: }
1362:
1363: sub reenable_group {
1.104 raeburn 1364: my ($r,$cdom,$cnum,$groupname,$crstype) = @_;
1.65 raeburn 1365: my %groups =
1366: &Apache::longroup::coursegroups($cdom,$cnum,$groupname,
1367: 'deleted_groups');
1.66 raeburn 1368: if (keys(%groups) == 0) {
1.79 bisitz 1369: $r->print(&mt('The group [_1] was not re-enabled, because it is not a deleted group.[_2]Perhaps it has already been re-enabled?','<i>'.$groupname.'</i>'),'<br />');
1.66 raeburn 1370: return;
1371: }
1.65 raeburn 1372: my %groupinfo =
1373: &Apache::longroup::get_group_settings($groups{$groupname});
1374: my $defstart = $groupinfo{'startdate'};
1375: my $defend = $groupinfo{'enddate'};
1376: my $showstart = &Apache::lonlocal::locallocaltime($defstart);
1377: my $showend;
1378: if ($defend == 0) {
1379: $showend = &mt('No end date set');
1380: } else {
1381: $showend = &Apache::lonlocal::locallocaltime($defend);
1382: }
1383: my $description = &unescape($groupinfo{'description'});
1384: my $num_users = 0;
1385: my $num_ok = 0;
1386: my $num_fail = 0;
1.77 raeburn 1387: my $context = 'reenablegroup';
1.65 raeburn 1388: my (%usersettings,@enabled,@unenabled);
1389: my ($result,$message) =
1390: &Apache::lonnet::toggle_coursegroup_status($cdom,$cnum,$groupname,
1391: 'reenable');
1392: if ($result eq 'ok') {
1393: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
1394: $groupname);
1395: foreach my $key (sort(keys(%membership))) {
1396: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
1397: my $user = $1;
1398: my($end,$start,$userprivs) = split(/:/,$membership{$key},3);
1399: if (($start == -1) && ($end == $groupinfo{'modified'})) {
1400: $num_users ++;
1401: $usersettings{$groupname.':'.$user} = $defend.':'.
1402: $defstart.':'.
1403: $userprivs;
1404: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,
1405: $groupname,$user,
1406: $defend,$defstart,
1.76 raeburn 1407: $userprivs,'',
1408: $context) eq 'ok') {
1.65 raeburn 1409: $num_ok ++;
1410: push(@enabled,$user);
1411: } else {
1412: push(@unenabled,$user);
1413: $num_fail ++;
1414: }
1.64 raeburn 1415: }
1416: }
1417: }
1.65 raeburn 1418: if ($num_users > 0) {
1419: if ($num_ok > 0) {
1420: my $roster_result =
1421: &Apache::lonnet::modify_coursegroup_membership($cdom,$cnum,
1422: \%usersettings);
1423: if ($roster_result eq 'ok') {
1.79 bisitz 1424: $r->print('<div class="LC_success">'
1425: .&mt('Membership reinstated for [quant,_1,user], each with start and end dates for group access set to defaults: [_2] and [_3]',$num_ok,$showstart,$showend)
1426: .'</div>');
1.65 raeburn 1427: }
1428: } else {
1.79 bisitz 1429: $r->print('<div class="LC_error">'
1430: .&mt('A problem occurred when trying to reinstate [_1] of the [_2] members of the pre-existing group.',$num_fail,$num_users)
1431: .'</div>');
1.65 raeburn 1432: }
1433: } else {
1.79 bisitz 1434: $r->print('<div class="LC_info">'
1435: .&mt('There were no group members to reinstate, as none were removed when the group was deleted.')
1436: .'</div>');
1.65 raeburn 1437: }
1.104 raeburn 1438: my $outcome = &reenable_folder($cdom,$cnum,$groupname,$description,$crstype);
1.65 raeburn 1439: if ($outcome eq '') {
1.79 bisitz 1440: $r->print('<div class="LC_success">'
1441: .&mt('Group successfully re-enabled.')
1442: .'</div>');
1443: } else {
1.104 raeburn 1444: $r->print('<div class="LC_error">');
1.105 bisitz 1445: if ($crstype eq 'Community') {
1.104 raeburn 1446: $r->print(&mt("Although the group was re-enabled, an error occurred when adding the group's folder to the 'Community Groups' folder: [_1]",$outcome));
1447: } else {
1448: $r->print(&mt("Although the group was re-enabled, an error occurred when adding the group's folder to the 'Course Groups' folder: [_1]",$outcome));
1449: }
1450: $r->print('</div>');
1.65 raeburn 1451: }
1452: } else {
1.79 bisitz 1453: $r->print('<div class="LC_error">'
1454: .&mt('Re-enabling group failed.')
1455: .'</div>');
1.64 raeburn 1456: }
1.66 raeburn 1457: return;
1.1 raeburn 1458: }
1459:
1460: sub header {
1.39 albertel 1461: my ($bodytitle,$jscript,$action,$state,$page,$loaditems) = @_;
1.9 albertel 1462: my $start_page=
1.11 albertel 1463: &Apache::loncommon::start_page($bodytitle,
1464: '<script type="text/javascript">'.
1465: $jscript.'</script>',
1.39 albertel 1466: {'add_entries' => $loaditems,});
1.3 raeburn 1467: my $output = <<"END";
1.11 albertel 1468: $start_page
1.101 bisitz 1469: <form method="post" name="$state">
1.3 raeburn 1470:
1471: END
1472: if ($action eq 'create' || $action eq 'modify') {
1473: $output .= <<"END";
1474: <input type="hidden" name="action" value="$action" />
1475: <input type="hidden" name="state" value="" />
1476: <input type="hidden" name="origin" value="$state" />
1.5 raeburn 1477: <input type="hidden" name="page" value="$page" />
1.3 raeburn 1478: END
1479: }
1480: return $output;
1.1 raeburn 1481: }
1482:
1.3 raeburn 1483: sub onload_action {
1484: my ($action,$state) = @_;
1.13 albertel 1485: my %loaditems;
1.3 raeburn 1486: if ((defined($env{'form.origin'})) && ($action eq 'create') &&
1487: ($state eq 'pick_name' || $state eq 'pick_members' ||
1488: $state eq 'pick_privs')) {
1489: unless ($env{'form.origin'} eq '') {
1.13 albertel 1490: $loaditems{'onload'} =
1491: 'javascript:setFormElements(document.'.$state.')';
1.1 raeburn 1492: }
1493: }
1.5 raeburn 1494: if (($action eq 'modify') &&
1495: ($state eq 'change_settings' || $state eq 'change_members' ||
1.53 raeburn 1496: $state eq 'change_privs' || $state eq 'add_members')) {
1.13 albertel 1497: $loaditems{'onload'} =
1498: 'javascript:setFormElements(document.'.$state.')';
1.5 raeburn 1499: }
1.13 albertel 1500: return \%loaditems;
1.1 raeburn 1501: }
1502:
1503: sub footer {
1.9 albertel 1504: my $end_page = &Apache::loncommon::end_page();
1.1 raeburn 1505: return(<<ENDFOOT);
1.6 raeburn 1506: <input type="hidden" name="sortby" value="$env{'form.sortby'}" />
1.1 raeburn 1507: </form>
1.9 albertel 1508: $end_page
1.1 raeburn 1509: ENDFOOT
1510: }
1511:
1.3 raeburn 1512: sub build_members_list {
1513: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata) = @_;
1514: my %access = ();
1515: foreach my $role (@{$roles}) {
1516: %{$$users{$role}} = ();
1517: }
1518: foreach my $type (@{$types}) {
1519: $access{$type} = $type;
1520: }
1521: &Apache::loncommon::get_course_users($cdom,$cnum,\%access,$roles,
1.5 raeburn 1522: $sections,$users,$userdata);
1.3 raeburn 1523: return;
1524: }
1525:
1526: sub group_files {
1.74 raeburn 1527: my ($group,$portpath,$numfiles,$numdirs) = @_;
1.29 raeburn 1528: my $dirptr=16384;
1.74 raeburn 1529: my @dir_list=&Apache::portfolio::get_dir_list($portpath,undef,$group);
1.29 raeburn 1530: foreach my $line (@dir_list) {
1531: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
1532: if (($filename !~ /^\.\.?$/) && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/) && ($filename ne 'no_such_dir')) {
1533: if ($dirptr&$testdir) {
1.74 raeburn 1534: $portpath .= '/'.$filename;
1.29 raeburn 1535: $$numdirs ++;
1.74 raeburn 1536: &group_files($group,$portpath,$numfiles,$numdirs)
1.29 raeburn 1537: } else {
1538: $$numfiles ++;
1539: }
1540: }
1541: }
1.3 raeburn 1542: return;
1543: }
1544:
1545: sub group_members {
1.4 raeburn 1546: my ($cdom,$cnum,$group,$group_info) = @_;
1547: my %memberhash = &Apache::lonnet::get_group_membership($cdom,$cnum,$group);
1548: my $now = time;
1.60 raeburn 1549: my %lt = &Apache::lonlocal::texthash (
1550: active => 'active',
1551: previous => 'previous',
1552: future => 'future',
1553: );
1554: my %membercounts = (
1555: active => 0,
1556: previous => 0,
1557: future => 0,
1558: );
1.4 raeburn 1559: my $totalmembers = 0;
1560: foreach my $member (keys %memberhash) {
1561: $totalmembers ++;
1562: my ($end,$start) = split(/:/,$memberhash{$member});
1.6 raeburn 1563: unless ($start == -1) {
1564: if (($end!=0) && ($end<$now)) {
1.60 raeburn 1565: $membercounts{previous} ++;
1.6 raeburn 1566: } elsif (($start!=0) && ($start>$now)) {
1.60 raeburn 1567: $membercounts{future} ++;
1.6 raeburn 1568: } else {
1.60 raeburn 1569: $membercounts{active} ++;
1.6 raeburn 1570: }
1.4 raeburn 1571: }
1572: }
1573: if ($totalmembers == 0) {
1574: $$group_info{$group}{'totalmembers'} = 'None';
1575: } else {
1.60 raeburn 1576: foreach my $type ('active','previous','future') {
1577: $$group_info{$group}{'totalmembers'} .=
1578: &open_list_window($group,$type,$membercounts{$type},$lt{$type});
1579: }
1.4 raeburn 1580: }
1581: return 'ok';
1.3 raeburn 1582: }
1583:
1.60 raeburn 1584: sub open_list_window {
1585: my ($group,$status,$count,$text) = @_;
1586: my $entry;
1587: if ($count > 0) {
1.83 bisitz 1588: $entry = '<span class="LC_nobreak"><a href="javascript:openGroupRoster('.
1.60 raeburn 1589: "'$group','$status'".')">'.$text.'</a> - '.$count.
1.83 bisitz 1590: '</span><br />';
1.60 raeburn 1591: } else {
1.83 bisitz 1592: $entry = '<span class="LC_nobreak">'.$text.' - '.$count.'</span><br />';
1.60 raeburn 1593: }
1594: return $entry;
1595: }
1596:
1.3 raeburn 1597:
1.5 raeburn 1598: sub general_settings_form {
1.46 albertel 1599: my ($r,$cdom,$cnum,$action,$formname,$page,$functions,$tools,
1.5 raeburn 1600: $toolprivs,$fixedprivs,$sectioncount,$stored,$states,$navbuttons,
1.46 albertel 1601: $gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 1602: my ($nexttext,$prevtext);
1.42 albertel 1603: &groupsettings_options($r,$functions,$action,$formname,$stored,1,
1.29 raeburn 1604: $gpterm,$ucgpterm,$crstype);
1.41 albertel 1605: &access_date_settings($r,$action,$formname,$stored,2,$gpterm,$ucgpterm);
1.5 raeburn 1606: if ($action eq 'create') {
1.59 raeburn 1607: &membership_options($r,$cdom,$cnum,$action,$formname,$sectioncount,3,
1.104 raeburn 1608: $gpterm,$ucgpterm,$crstype);
1.5 raeburn 1609: $nexttext = $$navbuttons{'gtns'};
1610: } else {
1611: my @available = ();
1612: my @unavailable = ();
1613: &check_tools($functions,$tools,\@available,\@unavailable);
1614: @{$tools} = sort(keys(%{$functions}));
1.46 albertel 1615: &privilege_specificity($r,$action,3,$tools,$stored,$toolprivs,
1616: $fixedprivs,\@available,$formname,
1.104 raeburn 1617: $gpterm,$ucgpterm,$functions,$crstype);
1.44 albertel 1618: &mapping_options($r,$action,$formname,$page,$sectioncount,
1619: $states,$stored,$navbuttons,4,5,
1.58 raeburn 1620: $gpterm,$ucgpterm,$crstype,$cdom,$cnum);
1.5 raeburn 1621: $nexttext = $$navbuttons{'mose'};
1622: }
1623: $prevtext = $$navbuttons{'gtpp'};
1624: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
1625: $$states{$action}[$page+1],$nexttext);
1626: return;
1627: }
1628:
1629: sub groupsettings_options {
1.42 albertel 1630: my ($r,$functions,$action,$formname,$stored,$image,$gpterm,
1.29 raeburn 1631: $ucgpterm,$crstype) = @_;
1.1 raeburn 1632: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 1633: 'gdat' => "Group access start and end dates",
1634: 'gnde' => "Group name, title and available collaborative tools",
1635: 'desc' => 'Group Title',
1636: 'func' => 'Collaborative Tools',
1637: 'gnam' => 'Group Name',
1638: 'lett' => 'Letters, numbers and underscore only',
1639: 'doyo' => 'Different subsets of the chosen collaborative tools '.
1640: 'for different group members?',
1.97 bisitz 1641: 'gran' => 'Granularity',
1642: 'dquo' => 'Disk quota',
1.1 raeburn 1643: );
1.37 raeburn 1644: my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,$stored);
1.97 bisitz 1645: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$lt{'gnde'}));
1646:
1647: # Group Name
1648: $r->print(&Apache::lonhtmlcommon::start_pick_box()
1649: .&Apache::lonhtmlcommon::row_title($lt{'gnam'})
1650: );
1.5 raeburn 1651: if ($action eq 'create') {
1.97 bisitz 1652: $r->print('<input type="text" name="groupname" size="25" />'
1653: .' <span class="LC_nobreak">('
1654: .$lt{'lett'}.')</span>'
1655: );
1.5 raeburn 1656: } else {
1657: $r->print('<input type="hidden" name="groupname" value="'.
1658: $env{'form.groupname'}.'" />'.$env{'form.groupname'});
1659: }
1.97 bisitz 1660: $r->print(&Apache::lonhtmlcommon::row_closure());
1661:
1662: # Group Title
1663: $r->print(&Apache::lonhtmlcommon::row_title($lt{'desc'})
1664: .'<input type="text" name="description" size="40" value="" />'
1665: .&Apache::lonhtmlcommon::row_closure()
1666: );
1667:
1668: # Collaborative Tools
1.3 raeburn 1669: my $numitems = keys(%{$functions});
1670: my $halfnum = int($numitems/2);
1671: my $remnum = $numitems%2;
1672: if ($remnum) {
1673: $halfnum ++;
1674: }
1.5 raeburn 1675: my @allfunctions = sort(keys (%{$functions}));
1.97 bisitz 1676:
1677: $r->print(&Apache::lonhtmlcommon::row_title($lt{'func'})
1678: .'<div>'
1679: .'<input type="button" value="'.&mt('check all').'"'
1680: .' onclick="javascript:checkAll(document.'.$formname.'.tool)" />'
1681: .' <input type="button" value="'.&mt('uncheck all').'"'
1682: .' onclick="javascript:uncheckAll(document.'.$formname.'.tool)" />'
1683: .'</div>'
1684: .'<table cellpadding="5px"><tr>' # FIXME Get rid of inflexible table (-> float)
1685: );
1686: for (my $i=0; $i<@allfunctions; $i++) {
1687: $r->print('<td><label><span class="LC_nobreak">'
1688: .'<input type="checkbox" name="tool" value="'
1689: .$allfunctions[$i].'" /> '
1690: .&mt($$functions{$allfunctions[$i]})
1691: .'</span></label></td>'
1692: );
1693: if ($i == $halfnum - 1) {
1694: $r->print('</tr><tr>');
1695: }
1.3 raeburn 1696: }
1.97 bisitz 1697: $r->print('</tr></table>'
1698: .&Apache::lonhtmlcommon::row_closure()
1699: );
1700:
1701: # Granularity
1702: $r->print(&Apache::lonhtmlcommon::row_title($lt{'gran'})
1703: .$lt{'doyo'}.'<br />'
1704: .'<label>'
1705: .'<input type="radio" name="granularity" value="Yes" />'.&mt('Yes')
1706: .'</label> <label>'
1707: .'<input type="radio" name="granularity" value="No" checked="checked" />'.&mt('No')
1708: .'</label>'
1709: );
1.5 raeburn 1710: if ($action eq 'modify') {
1.97 bisitz 1711: $r->print(' <span class="LC_nobreak">('
1712: .&mt('Currently set to [_1].'
1713: ,'"'.&mt($$stored{'granularity'}).'"')
1714: .')</span>'
1715: );
1.5 raeburn 1716: }
1.97 bisitz 1717: $r->print(&Apache::lonhtmlcommon::row_closure());
1718:
1719: # Disk Quota
1720: $r->print(&Apache::lonhtmlcommon::row_title($lt{'dquo'}));
1.29 raeburn 1721: if ($action eq 'create') {
1.97 bisitz 1722: $r->print('<span class="LC_info">'
1723: .&mt('If you enable the group portfolio for the '.$gpterm
1724: .', allocate a disk quota.')
1725: .'</span>'
1726: );
1.29 raeburn 1727: } else {
1.96 weissno 1728: $r->print(&mt('Quota allocated to group portfolio:'));
1.29 raeburn 1729: }
1.97 bisitz 1730: $r->print(' '.&mt('[_1] Mb','<input type="text" name="quota" size="4" />'));
1.29 raeburn 1731: if ($action eq 'create') {
1.79 bisitz 1732: $r->print('<br />'
1733: .&mt('A total of [_1] Mb can be divided amongst all '.$gpterm.'s in the '
1734: .lc($crstype).', and [_2] Mb are currently unallocated.'
1735: ,$crsquota,sprintf("%.2f",$freespace))
1736: );
1.29 raeburn 1737: } else {
1738: $r->print(' ('.&mt('The quota is currently [_1] Mb',
1739: $$stored{'quota'}).').');
1740:
1.79 bisitz 1741: $r->print('<br />'
1742: .&mt('The quota can be increased to [_1] Mb, '
1743: .'by adding all unallocated space for '.$gpterm.'s in the '.lc($crstype).'.'
1744: ,sprintf("%.2f",$maxposs)));
1.29 raeburn 1745: }
1.97 bisitz 1746: $r->print(&Apache::lonhtmlcommon::row_closure(1));
1747:
1748: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1749:
1.5 raeburn 1750: return;
1751: }
1752:
1.37 raeburn 1753: sub get_quota_constraints {
1754: my ($action,$stored) = @_;
1755: my ($crsquota,$freespace,$maxposs);
1756: $crsquota = $env{'course.'.$env{'request.course.id'}.'.internal.coursequota'};
1757: if ($crsquota eq '') {
1758: $crsquota = 20;
1759: }
1760: $freespace = $crsquota - &Apache::longroup::sum_quotas();
1761: if ($action eq 'create') {
1762: $maxposs = $freespace;
1763: } else {
1764: $maxposs = $$stored{'quota'} + $freespace;
1765: }
1766: return ($crsquota,$freespace,$maxposs);
1767: }
1768:
1.5 raeburn 1769: sub membership_options {
1.104 raeburn 1770: my ($r,$cdom,$cnum,$action,$state,$sectioncount,$image,$gpterm,$ucgpterm,$crstype)=@_;
1.5 raeburn 1771: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 1772: 'pipa' => 'Build a list of users for selection of group members',
1.104 raeburn 1773: 'gmem' => 'Group membership selection list criteria:',
1774: 'picr' => 'Pick the criteria to use to build a list of course users from which you will select members of the new group.',
1775: 'pica' => 'Pick the criteria to use to build a list of course users from which you will select additional members of the group.',
1776: 'ifno' => 'If you do not wish to add members when you first create the group, there is no need to pick any criteria.',
1.5 raeburn 1777: 'acty' => 'Access types',
1.104 raeburn 1778: 'coro' => 'Course roles',
1779: 'cose' => 'Course sections',
1.5 raeburn 1780: );
1.104 raeburn 1781: if ($crstype eq 'Community') {
1782: $lt{'picr'} = &mt('Pick the criteria to use to build a list of community participants from which you will select ');
1783: $lt{'asub'} = &mt('A subsequent step will also allow you to specify automatic adding/dropping of group members triggered by specified user role and section [_1]changes[_2] in the course.','<i>','</i>');
1784: $lt{'coro'} = &mt('Community roles');
1785: $lt{'cose'} = &mt('Community sections');
1786: } else {
1787: $lt{'asub'} = &mt('A subsequent step will also allow you to specify automatic adding/dropping of group members triggered by specified user role and section [_1]changes[_2] in the course.','<i>','</i>');
1788: }
1.5 raeburn 1789: my %status_types = (
1790: active => &mt('Currently has access'),
1791: previous => &mt('Previously had access'),
1792: future => &mt('Will have future access'),
1793: );
1.15 albertel 1794:
1.104 raeburn 1795: my @roles = ('st');
1796: if ($crstype eq 'Community') {
1797: push(@roles,'co');
1798: } else {
1799: push(@roles,'cc');
1800: }
1801: push (@roles,('in','ta','ep','ad','cr'));
1.5 raeburn 1802:
1803: my @sections = keys(%{$sectioncount});
1804:
1.78 raeburn 1805: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$lt{'pipa'}).'
1.104 raeburn 1806: <b>'.$lt{'gmem'}.'</b><br />');
1.5 raeburn 1807: if ($action eq 'create') {
1.104 raeburn 1808: $r->print($lt{'picr'}.'<br />'.$lt{'ifno'}.'<br />'.$lt{'asub'});
1.5 raeburn 1809: } else {
1.104 raeburn 1810: $r->print($lt{'pica'});
1.5 raeburn 1811: }
1812: $r->print('
1813: <br />
1814: <br />
1.40 albertel 1815: <table class="LC_status_selector">
1.3 raeburn 1816: <tr>
1.40 albertel 1817: <th>'.$lt{'acty'}.'</th>
1.53 raeburn 1818: <th>'.$lt{'coro'}.'</th>
1819: <th>'.$lt{'cose'}.'</th>
1820: </tr><tr><td>');
1.3 raeburn 1821: $r->print(&Apache::lonhtmlcommon::status_select_row(\%status_types));
1.40 albertel 1822: $r->print('</td><td>');
1.59 raeburn 1823: $r->print(&Apache::lonhtmlcommon::role_select_row(\@roles,undef,undef,1,$cdom,$cnum));
1.3 raeburn 1824: if (@sections > 0) {
1.5 raeburn 1825: @sections = sort {$a cmp $b} @sections;
1.31 albertel 1826: unshift(@sections,'none'); # Put 'no sections' next
1.17 raeburn 1827: unshift(@sections,'all'); # Put 'all' at the front of the list
1.53 raeburn 1828: } else {
1829: @sections = ('all','none');
1.3 raeburn 1830: }
1.53 raeburn 1831: $r->print('</td><td>'.
1832: §ions_selection(\@sections,'sectionpick').'</td>
1.3 raeburn 1833: </tr>
1.40 albertel 1834: </table>');
1.5 raeburn 1835: return;
1836: }
1837:
1838: sub sections_selection {
1839: my ($sections,$elementname) = @_;
1840: my $section_sel;
1841: my $numvisible = 4;
1842: if (@{$sections} < 4) {
1843: $numvisible = @{$sections};
1844: }
1845: foreach my $sec (@{$sections}) {
1.17 raeburn 1846: if ($sec eq 'all') {
1.53 raeburn 1847: $section_sel .= ' <option value="'.$sec.'">'.&mt('all sections').'</option>'."\n";
1.17 raeburn 1848: } elsif ($sec eq 'none') {
1.31 albertel 1849: $section_sel .= ' <option value="'.$sec.'">'.&mt('no section').'</option>'."\n";
1.5 raeburn 1850: } else {
1.31 albertel 1851: $section_sel .= ' <option value="'.$sec.'">'.$sec."</option>\n";
1.5 raeburn 1852: }
1853: }
1854: my $output = '
1.89 bisitz 1855: <select name="'.$elementname.'" multiple="multiple" size="'.$numvisible.'">
1.5 raeburn 1856: '.$section_sel.'
1857: </select>';
1858: return $output;
1859: }
1860:
1861: sub access_date_settings {
1.41 albertel 1862: my ($r,$action,$formname,$stored,$image,$gpterm,$ucgpterm) = @_;
1.80 bisitz 1863: my $sten = &mt("Default start and end dates for $gpterm access");
1.5 raeburn 1864: my $starttime = time;
1865: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1866: if ($action eq 'modify') {
1867: $starttime = $$stored{'startdate'};
1868: unless ($$stored{'enddate'} == 0) {
1869: $endtime = $$stored{'enddate'};
1870: }
1871: }
1.41 albertel 1872: my ($table) = &date_setting_table($starttime,$endtime,$formname);
1.80 bisitz 1873: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$sten).'
1.41 albertel 1874: '.$table.'
1875: ');
1.3 raeburn 1876: return;
1877: }
1878:
1.5 raeburn 1879: sub choose_members_form {
1.46 albertel 1880: my ($r,$cdom,$cnum,$action,$formname,$page,$groupname,$description,
1.29 raeburn 1881: $granularity,$quota,$startdate,$enddate,$tools,$fixedprivs,$toolprivs,
1.5 raeburn 1882: $functions,$users,$userdata,$idx,$stored,$states,$navbuttons,
1.46 albertel 1883: $gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 1884: my @regexps = ('user_','userpriv_','sec_');
1885: my %origmembers;
1.3 raeburn 1886: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.5 raeburn 1887: ['origin','action','state','page','member','specificity','branch',
1.7 raeburn 1888: 'defpriv','autorole','autoadd','autodrop','sortby','togglefunc'],
1.5 raeburn 1889: \@regexps));
1.29 raeburn 1890: my $earlyout = &validate_groupname($groupname,$action,$cdom,$cnum,$gpterm,
1891: $ucgpterm,$crstype);
1.5 raeburn 1892: if ($earlyout) {
1.47 raeburn 1893: $r->print($earlyout);
1.5 raeburn 1894: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1895: $$navbuttons{'gtps'});
1.3 raeburn 1896: return;
1.5 raeburn 1897: }
1898: my ($specimg,$memimg);
1899: my @available = ();
1900: my @unavailable = ();
1901: &check_tools($functions,$tools,\@available,\@unavailable);
1902: if ($action eq 'create') {
1.40 albertel 1903: &print_current_settings($r,$action,$functions,$startdate,$enddate,
1904: $groupname,$description,$granularity,$quota,
1905: \@available,\@unavailable,$gpterm,$ucgpterm);
1.5 raeburn 1906: $specimg = 4;
1907: $memimg = 5;
1908: } else {
1909: $specimg = 2;
1910: $memimg = 3;
1911: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
1912: $groupname);
1913: foreach my $key (sort(keys(%membership))) {
1914: if ($key =~ /^\Q$groupname\E:([^:]+):([^:]+)$/) {
1.6 raeburn 1915: my ($end,$start,@userprivs) = split(/:/,$membership{$key});
1916: unless ($start == -1) {
1917: my $uname = $1;
1918: my $udom = $2;
1919: my $user = $uname.':'.$udom;
1920: $origmembers{$user} = 1;
1921: }
1.5 raeburn 1922: }
1923: }
1924: }
1.46 albertel 1925: &privilege_specificity($r,$action,$specimg,$tools,$stored,$toolprivs,
1.103 raeburn 1926: $fixedprivs,\@available,$formname,$gpterm,$ucgpterm,
1.104 raeburn 1927: $functions,$crstype);
1.44 albertel 1928: my $newusers = &pick_new_members($r,$action,$formname,\@available,$idx,
1929: $stored,$memimg,$users,$userdata,
1930: $granularity,\%origmembers,$gpterm,
1931: $ucgpterm);
1.5 raeburn 1932: if ($newusers || $action eq 'create') {
1933: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1934: $$navbuttons{'gtps'},$$states{$action}[$page+1],
1935: $$navbuttons{'gtns'});
1936: } else {
1937: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1938: $$navbuttons{'gtps'});
1.3 raeburn 1939: }
1.5 raeburn 1940: return;
1941: }
1942:
1943: sub display_navbuttons {
1944: my ($r,$formname,$prev,$prevtext,$next,$nexttext) = @_;
1.42 albertel 1945: $r->print('<div class="LC_navbuttons">');
1.5 raeburn 1946: if ($prev) {
1947: $r->print('
1948: <input type="button" name="previous" value = "'.$prevtext.'"
1949: onclick="javascript:backPage(document.'.$formname.','."'".$prev."'".')"/>
1950: ');
1.64 raeburn 1951: } elsif ($prevtext) {
1952: $r->print('
1953: <input type="button" name="previous" value = "'.$prevtext.'"
1954: onclick="javascript:history.back()"/>
1955: ');
1.5 raeburn 1956: }
1957: if ($next) {
1958: $r->print('
1959: <input type="button" name="next" value="'.$nexttext.'"
1960: onclick="javascript:nextPage(document.'.$formname.','."'".$next."'".')" />');
1961: }
1.42 albertel 1962: $r->print('</div>');
1.5 raeburn 1963: }
1964:
1965: sub check_tools {
1966: my ($functions,$tools,$available,$unavailable) = @_;
1967: foreach my $item (sort(keys(%{$functions}))) {
1968: if (grep/^$item$/,@{$tools}) {
1969: push(@{$available},$item);
1970: } else {
1971: push(@{$unavailable},$item);
1972: }
1973: }
1974: return;
1975: }
1976:
1977: sub print_current_settings {
1.40 albertel 1978: my ($r,$action,$functions,$startdate,$enddate,$groupname,$description,
1979: $granularity,$quota,$available,$unavailable,$gpterm,$ucgpterm) = @_;
1.5 raeburn 1980:
1981: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 1982: grna => 'Group Name',
1983: desc => 'Group Title',
1984: grfn => "Collaborative Tools",
1.5 raeburn 1985: gran => 'Granularity',
1.29 raeburn 1986: quot => 'File quota',
1.5 raeburn 1987: dfac => 'Default access dates',
1.53 raeburn 1988: ygrs => "Your group selections - ",
1989: tfwa => "The following settings will apply to the group:",
1990: difn => 'Different collaborative tools<br />for different members:',
1.80 bisitz 1991: stda => 'Start date:',
1.5 raeburn 1992: enda => 'End date:',
1993: );
1.3 raeburn 1994: my $showstart = &Apache::lonlocal::locallocaltime($startdate);
1.5 raeburn 1995: my $showend;
1996: if ($enddate == 0) {
1997: $showend = &mt('No end date set');
1998: } else {
1999: $showend = &Apache::lonlocal::locallocaltime($enddate);
2000: }
2001: if ($action eq 'create') {
2002: $r->print('
1.42 albertel 2003: <div><span style="font-size: larger">'.$lt{'ygrs'}.'</span>
1.5 raeburn 2004: <br />'.$lt{'tfwa'}.'
1.40 albertel 2005: </div>');
1.5 raeburn 2006: }
1.40 albertel 2007: $r->print(&Apache::loncommon::start_data_table('LC_course_group_status').
2008: &Apache::loncommon::start_data_table_header_row());
2009: $r->print('
2010: <th>'.$lt{'grna'}.'</th>
2011: <th>'.$lt{'desc'}.'</th>
2012: <th>'.$lt{'grfn'}.'</th>
2013: <th>'.$lt{'gran'}.'</th>
2014: <th>'.$lt{'quot'}.'</th>
2015: <th>'.$lt{'dfac'}.'</th>
2016: ');
2017: $r->print(&Apache::loncommon::end_data_table_header_row().
2018: &Apache::loncommon::start_data_table_row('LC_data_table_dense'));
1.3 raeburn 2019: $r->print('
1.40 albertel 2020: <td valign="top">'.$groupname.'</td>
2021: <td valign="top">'.$description.'</td>
1.3 raeburn 2022: <td>
2023: ');
1.99 bisitz 2024:
1.5 raeburn 2025: if (@{$available} > 0) {
1.99 bisitz 2026: $r->print('<b>'.&mt('Available for assignment to members:').'</b>');
2027: $r->print('<ul>');
1.5 raeburn 2028: for (my $i=0; $i<@{$available}; $i++) {
1.99 bisitz 2029: $r->print('<li>'.&mt($$functions{$$available[$i]}).'</li>');
1.3 raeburn 2030: }
1.99 bisitz 2031: $r->print('</ul>');
1.3 raeburn 2032: }
1.99 bisitz 2033:
1.5 raeburn 2034: if (@{$unavailable} > 0) {
1.99 bisitz 2035: $r->print('<b>'.&mt('Unavailable for assignment:').'</b>');
2036: $r->print('<ul>');
2037: for (my $i=0; $i<@{$unavailable}; $i++) {
2038: $r->print('<li>'.&mt($$functions{$$unavailable[$i]}).'</li>');
1.3 raeburn 2039: }
1.99 bisitz 2040: $r->print('</ul>');
1.3 raeburn 2041: }
1.99 bisitz 2042:
1.79 bisitz 2043: my $quota_text=&mt('[_1] Mb',$quota);
1.80 bisitz 2044: my $granu_text=&mt($granularity);
1.3 raeburn 2045: $r->print(<<"END");
2046: </td>
1.80 bisitz 2047: <td valign="top"><b>$lt{'difn'}</b> $granu_text</td>
1.79 bisitz 2048: <td valign="top">$quota_text</td>
1.40 albertel 2049: <td valign="top"><b>$lt{'stda'}</b> $showstart<br />
2050: <b>$lt{'enda'}</b> $showend
1.3 raeburn 2051: </td>
2052: END
1.40 albertel 2053: $r->print(&Apache::loncommon::end_data_table_row().
2054: &Apache::loncommon::end_data_table());
1.5 raeburn 2055: return;
2056: }
2057:
2058: sub pick_new_members {
1.44 albertel 2059: my ($r,$action,$formname,$available,$idx,$stored,$img,$users,$userdata,
2060: $granularity,$origmembers,$gpterm,$ucgpterm) = @_;
1.5 raeburn 2061: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 2062: 'gpme' => "Group membership",
1.5 raeburn 2063: 'addm' => 'Add members',
1.53 raeburn 2064: 'setf' => 'Assign collaborative tools',
2065: 'func' => 'Tools',
2066: 'nome' => 'No members to add at this time, as there are no users '.
2067: 'matching the specified type(s), role(s) and section(s).',
1.29 raeburn 2068: 'nnew' => "There are no users to add as new members, as all users".
1.53 raeburn 2069: " matching the specified type(s), role(s), and ".
2070: "section(s) are already affiliated with this group.",
1.79 bisitz 2071: 'yoma' => "You may need to use the 'modify existing, past or ".
2072: "future members' page if you need to re-enable ".
2073: "or activate access for previous or future members.",
1.5 raeburn 2074: );
2075: my %members;
2076: my $totalusers = 0;
2077: my $newusers = 0;
1.3 raeburn 2078: foreach my $role (keys(%{$users})) {
2079: foreach my $user (keys(%{$$users{$role}})) {
1.5 raeburn 2080: $totalusers ++;
2081: if (ref($origmembers) eq 'HASH') {
2082: if (exists($$origmembers{$user})) {
2083: next;
2084: }
2085: }
1.3 raeburn 2086: unless (defined($members{$user})) {
2087: @{$members{$user}} = @{$$userdata{$user}};
1.5 raeburn 2088: $newusers ++;
1.3 raeburn 2089: }
2090: }
2091: }
2092: if (keys(%members) > 0) {
1.5 raeburn 2093: if (@{$available} > 0 && $granularity eq 'Yes') {
2094: $r->print(&check_uncheck_tools($r,$available));
2095: }
2096: }
1.78 raeburn 2097: $r->print(&Apache::lonhtmlcommon::topic_bar($img,$lt{'gpme'}));
1.5 raeburn 2098: if (keys(%members) > 0) {
2099: $r->print('
1.3 raeburn 2100: <table>
1.5 raeburn 2101: <tr>');
2102: &check_uncheck_buttons($r,$formname,'member',$lt{'addm'});
2103: if (@{$available} > 0 && $granularity eq 'Yes') {
1.48 albertel 2104: $r->print('<td>
1.102 bisitz 2105: <fieldset><legend>'.$lt{'setf'}.'</legend>
1.83 bisitz 2106: <span class="LC_nobreak">
1.80 bisitz 2107: <input type="button" value="'.&mt('check all').'"
1.5 raeburn 2108: onclick="javascript:checkAllTools(document.'.$formname.')" />
2109:
1.80 bisitz 2110: <input type="button" value="'.&mt('uncheck all').'"
1.3 raeburn 2111: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
1.83 bisitz 2112: </span>
1.48 albertel 2113: </fieldset></td>');
1.3 raeburn 2114: }
2115: $r->print('</tr></table>
2116: ');
1.43 albertel 2117: $r->print(&Apache::loncommon::start_data_table().
2118: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 2119: $r->print('
1.43 albertel 2120: <th>'.&mt('Add?').'</b></td>
2121: <th><a href="javascript:changeSort('."'fullname'".')">'.&mt('Name').'</a></td>
2122: <th><a href="javascript:changeSort('."'username'".')">'.&mt('Username').'</a></td>
2123: <th><a href="javascript:changeSort('."'domain'".')">'.&mt('Domain').'</a></td>
2124: <th><a href="javascript:changeSort('."'id'".')">'.&mt('ID').'</a></td>
2125: <th><a href="javascript:changeSort('."'section'".')">'.&mt('Section').'</a></td>
1.5 raeburn 2126: ');
2127: if (@{$available} > 0) {
1.43 albertel 2128: $r->print('<th>'.$lt{'func'}.'</th>');
1.3 raeburn 2129: }
1.43 albertel 2130: $r->print(&Apache::loncommon::end_data_table_header_row());
1.5 raeburn 2131: if (@{$available} > 0) {
2132: if ($granularity eq 'Yes') {
1.43 albertel 2133: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense LC_data_table_highlight').'
1.35 raeburn 2134: <td colspan="6"> </td>
1.83 bisitz 2135: <td align="center"><span class="LC_nobreak"><b>'.&mt('All:').'</b> ');
1.5 raeburn 2136: foreach my $tool (@{$available}) {
1.7 raeburn 2137: $r->print('<label><input type="checkbox" name="togglefunc" '.
2138: 'onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
2139: ' value="'.$tool.'">'.'<b>'.$tool.'</b></label> ');
1.5 raeburn 2140: }
1.83 bisitz 2141: $r->print('</span></td></tr>');
1.5 raeburn 2142: }
2143: }
1.3 raeburn 2144: my %Sortby = ();
2145: foreach my $user (sort(keys(%members))) {
2146: if ($env{'form.sortby'} eq 'fullname') {
2147: push(@{$Sortby{$members{$user}[$$idx{fullname}]}},$user);
2148: } elsif ($env{'form.sortby'} eq 'username') {
2149: push(@{$Sortby{$members{$user}[$$idx{uname}]}},$user);
2150: } elsif ($env{'form.sortby'} eq 'domain') {
2151: push(@{$Sortby{$members{$user}[$$idx{udom}]}},$user);
2152: } elsif ($env{'form.sortby'} eq 'id') {
2153: push(@{$Sortby{$members{$user}[$$idx{id}]}},$user);
1.31 albertel 2154: } elsif ($env{'form.sortby'} eq 'section') {
2155: push(@{$Sortby{$members{$user}[$$idx{section}]}},$user);
1.3 raeburn 2156: } else {
2157: push(@{$Sortby{$members{$user}[$$idx{fullname}]}},$user);
2158: }
2159: }
2160: foreach my $key (sort(keys(%Sortby))) {
2161: foreach my $user (@{$Sortby{$key}}) {
2162: my $id = $members{$user}[$$idx{id}];
2163: my $fullname = $members{$user}[$$idx{fullname}];
2164: my $udom = $members{$user}[$$idx{udom}];
2165: my $uname = $members{$user}[$$idx{uname}];
1.31 albertel 2166: my $section = $members{$user}[$$idx{section}];
1.43 albertel 2167: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense').
2168: '<td align="right"><input type="checkbox" name="member" value="'.$user.'" /></td>'.
2169: '<td>'.$fullname.'</td>'.
2170: '<td>'.$uname.'</td>'.
2171: '<td>'.$udom.'</td>'.
2172: '<td>'.$id.'</td>'.
2173: '<td>'.$section.'</td>');
1.5 raeburn 2174: if (@{$available} > 0) {
1.83 bisitz 2175: $r->print('<td align="center"><span class="LC_nobreak">'.
1.5 raeburn 2176: ' ');
2177: foreach my $tool (@{$available}) {
2178: if ($granularity eq 'Yes') {
1.3 raeburn 2179: $r->print('<input type="checkbox" name="user_'.
2180: $tool.'" value="'.$user.'" />'.$tool.' ');
2181: } else {
2182: $r->print('<input type="hidden" name="user_'.
2183: $tool.'" value="'.$user.'" />'.$tool.' ');
2184: }
2185: }
1.83 bisitz 2186: $r->print('</span></td>');
1.3 raeburn 2187: }
1.43 albertel 2188: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.3 raeburn 2189: }
2190: }
1.43 albertel 2191: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 2192: } else {
2193: if ($totalusers > 0) {
2194: $r->print($lt{'nnew'}.'<br /><br />'.$lt{'yoma'});
2195: } else {
2196: $r->print($lt{'nome'});
2197: }
2198: }
2199: return $newusers;
2200: }
2201:
2202: sub privilege_specificity {
1.46 albertel 2203: my ($r,$action,$img,$tools,$stored,$toolprivs,$fixedprivs,$available,
1.104 raeburn 2204: $formname,$gpterm,$ucgpterm,$functions,$crstype) = @_;
1.5 raeburn 2205: my %lt = &Apache::lonlocal::texthash (
1.53 raeburn 2206: 'uprv' => 'User privileges for collaborative tools',
2207: 'frty' => 'For each collaborative tool you have chosen to include, '.
2208: 'there is a set of core privileges which all group members '.
2209: 'assigned use of the tool will receive.',
2210: 'thar' => 'For some tools there are also additional optional '.
2211: 'privileges which can be set.',
2212: 'plch' => 'Choose one of the following:',
2213: 'fort' => 'For the collaborative tools you have chosen to include '.
2214: 'only core privileges are available, '.
2215: 'so there are no optional privileges to assign.',
2216: 'eaty' => 'Each collaborative tool includes core '.
2217: 'privileges assigned to all members with access to the '.
2218: 'tool. Some tools may also feature additional privileges '.
1.5 raeburn 2219: 'which can be set for specific members.',
1.53 raeburn 2220: 'cutg' => 'Currently the group is configured ',
2221: 'sdif' => 'so different members can receive different optional privileges for a particular tool.',
2222: 'sall' => 'so all members will receive the same optional privileges for a particular tool.',
2223: 'algm' => 'All group members will receive the same privileges for any tool assigned to them, including the default set of optional privileges.',
2224: 'smgp' => 'Different group members may receive different privileges from '.
2225: 'others for the tools they have been assigned.',
2226: 'thwi' => 'These will be the privileges all group members receive for a particular assigned tool, '.
2227: 'if you selected the first option above.',
1.29 raeburn 2228: 'thes' => "These will be the privileges given to members assigned ".
1.53 raeburn 2229: "in the future via automatic group assignment ".
2230: "for users who receive specific sections/roles in the course ",
2231: 'asyo' => "As you have chosen not to include any collaborative tools ".
2232: "in the group, no default optional privileges need to be set.",
2233: 'plin' => 'Indicate which <b>optional</b> privileges members '.
2234: 'will receive by default for a specific tool.',
1.5 raeburn 2235: 'oppr' => 'Optional privileges',
2236: 'defp' => 'The default privileges new members will receive are:',
2237: );
1.104 raeburn 2238: if ($crstype eq 'Community') {
2239: $lt{'thes'} = &mt('These will be the privileges given to members assigned in the future via automatic group assignment for users who receive specific sections/roles in the community ');
2240: }
1.5 raeburn 2241: my $totaloptionalprivs = 0;
2242: foreach my $tool (@{$tools}) {
2243: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2244: if (!exists($$fixedprivs{$tool}{$priv})) {
2245: $totaloptionalprivs ++;
2246: }
2247: }
2248: }
1.78 raeburn 2249: $r->print(&Apache::lonhtmlcommon::topic_bar($img,$lt{'uprv'}));
1.5 raeburn 2250: if ((($action eq 'create') && (@{$available} > 0)) ||
1.55 raeburn 2251: (($action eq 'modify') && ($formname eq 'change_settings'))) {
1.5 raeburn 2252: my %specific = (
2253: 'No' => 'checked="checked"',
2254: 'Yes' => '',
2255: );
2256: if ($action eq 'create') {
2257: $r->print($lt{'frty'}.'<br />');
2258: if ($totaloptionalprivs) {
1.53 raeburn 2259: $r->print($lt{'thar'}.'<br /><br />'.$lt{'plch'});
1.5 raeburn 2260: } else {
2261: $r->print($lt{'fort'});
2262: }
2263: } else {
2264: $r->print($lt{'eaty'}.' '.$lt{cutg});
2265: if ($$stored{'specificity'} eq 'Yes') {
2266: $r->print($lt{'sdif'});
2267: $specific{'Yes'} = $specific{'No'};
2268: $specific{'No'} = '';
2269: } else {
2270: $r->print($lt{'sall'});
2271: }
2272: }
2273: if ($totaloptionalprivs) {
2274: $r->print('
1.53 raeburn 2275: <br />
1.83 bisitz 2276: <label><span class="LC_nobreak"><input type="radio" name="specificity" value="No" '.$specific{'No'}.' /> '.$lt{'algm'}.'</span></label><br />
2277: <label><span class="LC_nobreak"><input type="radio" name="specificity" value="Yes" '.$specific{'Yes'}.' /> '.$lt{'smgp'}.'</span></label><br /><br />');
1.5 raeburn 2278: } else {
2279: $r->print('<input type="hidden" name="specificity" value="No" />');
2280: }
2281: if ($totaloptionalprivs) {
1.40 albertel 2282: $r->print($lt{'plin'});
1.5 raeburn 2283: if ($action eq 'create') {
1.53 raeburn 2284: $r->print('<br />'.$lt{'thwi'});
1.5 raeburn 2285: }
2286: $r->print('<br />'.$lt{'thes'});
2287: if ($action eq 'create') {
2288: $r->print('('.&mt('if enabled on the next page').').');
2289: } else {
2290: $r->print('('.&mt('if enabled below').').');
2291: }
2292: $r->print('<br /><br />
1.40 albertel 2293: <table><tr>');
1.5 raeburn 2294: &check_uncheck_buttons($r,$formname,'defpriv',$lt{'oppr'});
2295: $r->print('
2296: </tr>
2297: </table>
1.3 raeburn 2298: <br />
2299: ');
1.5 raeburn 2300: } else {
1.40 albertel 2301: $r->print($lt{'algm'}.'<br /><br />');
1.3 raeburn 2302: }
1.42 albertel 2303: &default_privileges($r,$action,$tools,$toolprivs,$fixedprivs,
1.92 schafran 2304: $available,$functions);
1.3 raeburn 2305: } else {
1.5 raeburn 2306: if ($action eq 'create') {
2307: $r->print($lt{'asyo'});
1.55 raeburn 2308: $r->print('<input type="hidden" name="specificity" value="No" />');
1.5 raeburn 2309: } elsif ($action eq 'modify' && $formname eq 'pick_members') {
2310: my @defprivs;
2311: if (ref($$stored{'defpriv'}) eq 'ARRAY') {
2312: @defprivs = @{$$stored{'defpriv'}};
2313: }
2314: $r->print($lt{'eaty'}.' '.$lt{cutg});
2315: if ($$stored{'specificity'} eq 'Yes') {
2316: $r->print($lt{'sdif'});
2317: } else {
2318: $r->print($lt{'sall'});
2319: }
2320: $r->print(' '.$lt{'defp'}.'<br /><br />');
1.45 albertel 2321: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 2322: }
1.3 raeburn 2323: }
2324: return;
2325: }
2326:
1.5 raeburn 2327: sub default_privileges {
1.92 schafran 2328: my ($r,$action,$tools,$toolprivs,$fixedprivs,$available,$functions) = @_;
1.5 raeburn 2329: my %lt = &Apache::lonlocal::texthash(
2330: 'addp' => 'Additional privileges',
2331: 'fixp' => 'Fixed privileges',
2332: 'oppr' => 'Optional privileges',
1.53 raeburn 2333: 'func' => 'Collaborative Tool',
1.5 raeburn 2334: );
1.42 albertel 2335: $r->print(&Apache::lonhtmlcommon::start_pick_box('LC_group_priv_box').
2336: &Apache::lonhtmlcommon::row_title($lt{'func'},undef,
1.90 schafran 2337: 'LC_groups_functionality'));
1.92 schafran 2338: my @tableHeader;
1.107 raeburn 2339: if ((ref($functions) eq 'HASH') && (ref($tools) eq 'ARRAY')) {
2340: @tableHeader = map { $functions->{$_}; } @{$tools};
2341: }
1.92 schafran 2342: $r->print(join('</td><td class="LC_groups_functionality">', @tableHeader));
1.42 albertel 2343: $r->print(&Apache::lonhtmlcommon::row_closure(1));
2344: my $fixed = '';
2345: my $dynamic = '';
1.3 raeburn 2346: foreach my $tool (@{$tools}) {
1.5 raeburn 2347: my $privcount = 0;
1.42 albertel 2348: if ($dynamic ne '') {
2349: $dynamic .= '</td><td class="LC_groups_optional">';
2350: }
2351: $dynamic .= '<table class="LC_group_priv"><tr>';
1.5 raeburn 2352: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2353: if (exists($$fixedprivs{$tool}{$priv})) {
1.42 albertel 2354: if ($fixed ne '') {
2355: $fixed .= '</td><td class="LC_groups_fixed">';
2356: }
1.79 bisitz 2357: $fixed .= '<input type="hidden" name="defpriv" value="'.$priv.'" />'
1.90 schafran 2358: .'<span class="LC_nobreak">'.&mt($$toolprivs{$tool}{$priv}).' ';
1.5 raeburn 2359: if ($action eq 'modify') {
1.42 albertel 2360: if (grep(/^$tool$/,@{$available})) {
1.5 raeburn 2361: $fixed .= '<small>'.&mt('(on)').'<small> ';
2362: } else {
2363: $fixed .= '<small>'.&mt('(off)').'<small> ';
1.3 raeburn 2364: }
2365: }
1.79 bisitz 2366: $fixed .= '</span>';
1.5 raeburn 2367: } else {
1.42 albertel 2368: $privcount++;
1.5 raeburn 2369: if ($privcount == 3) {
2370: $dynamic .= '</tr>
1.42 albertel 2371: <tr>'."\n";
1.5 raeburn 2372: }
1.90 schafran 2373: $dynamic .= '<td><span class="LC_nobreak"><label><input type="checkbox" name="defpriv" value="'.$priv.'" />'.&mt($$toolprivs{$tool}{$priv}).'</label></span></td>'."\n";
1.3 raeburn 2374: }
2375: }
1.42 albertel 2376: if ($privcount == 0) {
1.79 bisitz 2377: $dynamic .= '<td>'.&mt('None').'</td>'."\n";
1.5 raeburn 2378: }
2379: if ($privcount < 3) {
1.53 raeburn 2380: $dynamic .= '<td> </td>'."\n";
1.5 raeburn 2381: } elsif ($privcount%2) {
2382: $dynamic = '<td> </td>'."\n";
2383: }
1.42 albertel 2384: $dynamic .= '</tr></table>';
1.3 raeburn 2385: }
1.42 albertel 2386: $r->print(&Apache::lonhtmlcommon::row_title($lt{'fixp'},undef,
2387: 'LC_groups_fixed').
2388: $fixed.
2389: &Apache::lonhtmlcommon::row_closure(1));
2390: $r->print(&Apache::lonhtmlcommon::row_title($lt{'oppr'},undef,
2391: 'LC_groups_optional').
2392: $dynamic.
2393: &Apache::lonhtmlcommon::end_pick_box());
1.5 raeburn 2394: $r->print('<br />');
2395: return;
1.42 albertel 2396:
1.5 raeburn 2397: }
2398:
2399: sub display_defprivs {
1.45 albertel 2400: my ($r,$tools,$toolprivs,$defprivs) = @_;
2401: my $function = &Apache::loncommon::get_users_function();
2402: my $tabcol = &Apache::loncommon::designparm($function.'.tabbg');
2403: my $rowColor1 = "#dddddd";
2404: my $rowColor2 = "#eeeeee";
1.5 raeburn 2405: my %lt = &Apache::lonlocal::texthash(
2406: 'priv' => 'Privileges',
1.53 raeburn 2407: 'func' => 'Collaborative Tool',
1.5 raeburn 2408: );
2409: $r->print(&Apache::lonhtmlcommon::start_pick_box());
2410: $r->print('<tr>');
2411: my $numrows = 0;
2412: my %currprivs;
2413: foreach my $tool (@{$tools}) {
2414: @{$currprivs{$tool}} = ();
2415: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2416: if (ref($defprivs) eq 'ARRAY') {
1.45 albertel 2417: if (grep(/^\Q$priv\E$/,@{$defprivs})) {
1.5 raeburn 2418: push(@{$currprivs{$tool}},$priv);
2419: }
1.3 raeburn 2420: }
2421: }
1.5 raeburn 2422: my $rowcount = int(@{$currprivs{$tool}}/3);
2423: if (@{$currprivs{$tool}}%3 > 0) {
2424: $rowcount ++;
2425: }
2426: if ($rowcount > $numrows) {
2427: $numrows = $rowcount;
2428: }
2429: }
2430: my @rowCols = ($rowColor1,$rowColor2);
2431: foreach my $tool (@{$tools}) {
2432: $r->print('<td align="center" valign="top">
2433: <table cellspacing="0" cellpadding="5">
2434: <tr bgcolor="#cccccc">
2435: <td colspan="3" align="center"><b>'.$tool.'</b></td>
2436: </tr>
2437: ');
2438: my $rownum = 1;
2439: my $privcount = 0;
2440: $r->print('<tr bgcolor="'.$rowColor1.'">');
2441: foreach my $priv (@{$currprivs{$tool}}) {
2442: $privcount ++;
2443: if ($privcount%4 == 0) {
2444: $rownum ++;
2445: my $bgcol = $rownum%2;
2446: $r->print('</tr>
2447: <tr bgcolor="'.$rowCols[$bgcol].'">'."\n");
2448: }
2449: $r->print('<td>'.$$toolprivs{$tool}{$priv}.'</td>'."\n");
2450: }
2451: if ($privcount%3 > 0) {
2452: my $emptycells = 3-($privcount%3);
2453: while($emptycells > 0) {
2454: $r->print('<td> </td>'."\n");
2455: $emptycells --;
2456: }
2457: }
2458: while ($rownum < $numrows) {
2459: $rownum ++;
2460: my $bgcol = $rownum%2;
2461: $r->print('<tr bgcolor="'.$rowCols[$bgcol].'"><td colspan="3"> </td></tr>');
1.3 raeburn 2462: }
1.5 raeburn 2463: $r->print('</table>'."\n".'</td>');
2464: }
2465: $r->print('</tr>'."\n");
2466: $r->print(&Apache::lonhtmlcommon::end_pick_box());
2467: $r->print('<br />');
2468: return;
1.3 raeburn 2469: }
1.5 raeburn 2470:
2471:
2472: sub change_members_form {
1.48 albertel 2473: my ($r,$cdom,$cnum,$action,$formname,$page,$groupname,$description,
1.5 raeburn 2474: $startdate,$enddate,$tools,$fixedprivs,$functions,$users,$userdata,
1.48 albertel 2475: $granularity,$quota,$specificity,$idx,$states,$navbuttons,$gpterm,
2476: $ucgpterm) = @_;
1.5 raeburn 2477: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 2478: grse => "$ucgpterm settings",
2479: mogm => "Modify $gpterm membership",
1.5 raeburn 2480: );
2481: my @regexps = ('user_','userpriv_');
2482: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2483: ['origin','action','state','page','expire','deletion',
1.7 raeburn 2484: 'reenable','activate','changepriv','sortby',
2485: 'togglefunc'],\@regexps));
1.5 raeburn 2486: my $rowimg = 1;
2487: my @available = ();
2488: my @unavailable = ();
2489: &check_tools($functions,$tools,\@available,\@unavailable);
2490: my $nexttext = $$navbuttons{'gtns'};
2491: my $prevtext = $$navbuttons{'gtpp'};
2492: $r->print('
1.3 raeburn 2493: <br />
1.5 raeburn 2494: ');
1.78 raeburn 2495: $r->print(&Apache::lonhtmlcommon::topic_bar(1,$lt{'grse'}));
1.40 albertel 2496: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2497: $groupname,$description,$granularity,$quota,
2498: \@available,\@unavailable,$gpterm,$ucgpterm);
1.78 raeburn 2499: $r->print(&Apache::lonhtmlcommon::topic_bar(2,$lt{'mogm'}));
1.53 raeburn 2500: my $numcurrent = ¤t_membership($r,$cdom,$cnum,$formname,$groupname,
2501: \@available,\@unavailable,$fixedprivs,
2502: $granularity,$specificity);
2503: if ($numcurrent > 0) {
2504: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2505: $$states{$action}[$page+1],$nexttext);
2506: } else {
2507: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext);
2508: }
1.5 raeburn 2509: return;
2510: }
2511:
2512: sub current_membership {
1.48 albertel 2513: my ($r,$cdom,$cnum,$formname,$groupname,$available,$unavailable,
2514: $fixedprivs,$granularity,$specificity) = @_;
1.5 raeburn 2515: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
2516: $groupname);
2517: my %lt = &Apache::lonlocal::texthash(
1.6 raeburn 2518: 'actn' => 'Action?',
2519: 'name' => 'Name',
2520: 'usnm' => 'Username',
2521: 'doma' => 'Domain',
2522: 'stda' => 'Start Date',
2523: 'enda' => 'End Date',
1.5 raeburn 2524: 'expi' => 'Expire',
2525: 'reen' => 'Re-enable',
2526: 'acti' => 'Activate',
2527: 'dele' => 'Delete',
1.53 raeburn 2528: 'curf' => 'Current Tool Set',
1.5 raeburn 2529: 'chpr' => 'Change Privileges'
2530: );
1.52 raeburn 2531: my ($current,$num_items,$hastools,$addtools) =
1.36 raeburn 2532: &Apache::longroup::group_memberlist($cdom,$cnum,$groupname,$fixedprivs,
2533: $available);
1.53 raeburn 2534: my $numcurrent = scalar(keys(%{$current}));
2535: if ($numcurrent > 0) {
1.36 raeburn 2536: $r->print('
1.5 raeburn 2537: <table>
2538: <tr>');
1.52 raeburn 2539: if ($num_items->{'active'}) {
1.36 raeburn 2540: &check_uncheck_buttons($r,$formname,'expire',$lt{'expi'});
2541: }
1.52 raeburn 2542: if ($num_items->{'previous'}) {
1.36 raeburn 2543: &check_uncheck_buttons($r,$formname,'reenable',$lt{'reen'});
2544: }
1.52 raeburn 2545: if ($num_items->{'future'}) {
1.36 raeburn 2546: &check_uncheck_buttons($r,$formname,'activate',$lt{'acti'});
2547: }
2548: &check_uncheck_buttons($r,$formname,'deletion',$lt{'dele'});
2549: if (@{$available} > 0) {
2550: if ($specificity eq 'Yes') {
2551: &check_uncheck_buttons($r,$formname,'changepriv',$lt{'chpr'});
1.5 raeburn 2552: }
1.36 raeburn 2553: if ($granularity eq 'Yes') {
2554: $r->print(&check_uncheck_tools($r,$available));
2555: $r->print('
1.5 raeburn 2556: <td>
1.83 bisitz 2557: <span class="LC_nobreak">
1.102 bisitz 2558: <fieldset><legend>'.$lt{'curf'}.'</legend>
1.80 bisitz 2559: <input type="button" value="'.&mt('check all').'"
1.5 raeburn 2560: onclick="javascript:checkAllTools(document.'.$formname.')" />
2561:
1.80 bisitz 2562: <input type="button" value="'.&mt('uncheck all').'"
1.5 raeburn 2563: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
2564: </fieldset>
1.83 bisitz 2565: </span>
1.5 raeburn 2566: </td>
2567: ');
1.3 raeburn 2568: }
1.36 raeburn 2569: }
2570: $r->print(<<"END");
1.5 raeburn 2571: </tr>
2572: </table>
1.48 albertel 2573: <br />
1.5 raeburn 2574: END
1.48 albertel 2575: $r->print(&Apache::loncommon::start_data_table().
2576: &Apache::loncommon::start_data_table_header_row());
1.36 raeburn 2577: $r->print(<<"END");
1.48 albertel 2578: <th>$lt{'actn'}</th>
2579: <th><a href="javascript:changeSort('fullname')">$lt{'name'}</a></th>
2580: <th><a href="javascript:changeSort('username')">$lt{'usnm'}</a></th>
2581: <th><a href="javascript:changeSort('domain')">$lt{'doma'}</a></th>
2582: <th><a href="javascript:changeSort('id')">ID</a></th>
2583: <th><a href="javascript:changeSort('start')">$lt{'stda'}</a></th>
2584: <th><a href="javascript:changeSort('end')">$lt{'enda'}</a></th>
1.5 raeburn 2585: END
1.36 raeburn 2586: my $colspan = 0;
2587: if ($hastools) {
1.48 albertel 2588: $r->print('<th>'.$lt{'curf'}.'</th>');
2589: $colspan++;
1.36 raeburn 2590: }
2591: if ($addtools) {
1.53 raeburn 2592: $r->print('<th>'.&mt('Additional Tools').'</th>');
1.48 albertel 2593: $colspan++;
1.36 raeburn 2594: }
1.48 albertel 2595: $r->print(&Apache::loncommon::end_data_table_header_row());
1.36 raeburn 2596: if ($colspan) {
2597: if ($granularity eq 'Yes') {
1.48 albertel 2598: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense LC_data_table_highlight').'
1.6 raeburn 2599: <td colspan="7"> </td>
1.83 bisitz 2600: <td colspan="'.$colspan.'" align="center"><span class="LC_nobreak"><b>'.&mt('All:').
1.6 raeburn 2601: '</b> ');
1.36 raeburn 2602: foreach my $tool (@{$available}) {
2603: $r->print('<label><input type="checkbox" name="togglefunc"'.
1.7 raeburn 2604: ' onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
1.48 albertel 2605: ' value="'.$tool.'" />'.'<b>'.$tool.'</b></label> ');
1.6 raeburn 2606: }
1.83 bisitz 2607: $r->print('</span></td></tr>');
1.6 raeburn 2608: }
1.36 raeburn 2609: }
2610: my %Sortby = ();
2611: foreach my $user (sort(keys(%{$current}))) {
2612: if ($env{'form.sortby'} eq 'fullname') {
2613: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2614: } elsif ($env{'form.sortby'} eq 'username') {
2615: push(@{$Sortby{$$current{$user}{uname}}},$user);
2616: } elsif ($env{'form.sortby'} eq 'domain') {
2617: push(@{$Sortby{$$current{$user}{udom}}},$user);
2618: } elsif ($env{'form.sortby'} eq 'id') {
2619: push(@{$Sortby{$$current{$user}{id}}},$user);
2620: } else {
2621: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2622: }
2623: }
2624: foreach my $key (sort(keys(%Sortby))) {
2625: foreach my $user (@{$Sortby{$key}}) {
2626: my $id = $$current{$user}{id};
2627: my $fullname = $$current{$user}{fullname};
2628: my $udom = $$current{$user}{udom};
2629: my $uname = $$current{$user}{uname};
2630: my $start = $$current{$user}{start};
2631: my $end = $$current{$user}{end};
1.48 albertel 2632: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense').'
2633: <td>');
1.36 raeburn 2634: if ($$current{$user}{changestate} eq 'reenable') {
1.83 bisitz 2635: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2636: '<input type="checkbox" name="reenable" value="'.$user.'" />'.
1.83 bisitz 2637: $lt{'reen'}.'</label></span><br />');
1.36 raeburn 2638: } elsif ($$current{$user}{changestate} eq 'expire') {
1.83 bisitz 2639: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2640: '<input type="checkbox" name="expire" value="'.$user.'" />'.
1.83 bisitz 2641: $lt{'expi'}.'</label></span><br />');
1.36 raeburn 2642: } elsif ($$current{$user}{changestate} eq 'activate') {
1.83 bisitz 2643: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2644: '<input type="checkbox" name="activate" value="'.$user.'" />'.
1.83 bisitz 2645: $lt{'acti'}.'</label></span><br />');
1.36 raeburn 2646: }
1.83 bisitz 2647: $r->print('<span class="LC_nobreak"><label>'.
1.6 raeburn 2648: '<input type="checkbox" name="deletion" value="'.$user.'" />'.
1.83 bisitz 2649: $lt{'dele'}.'</label></span>');
1.36 raeburn 2650: if ($specificity eq 'Yes') {
1.83 bisitz 2651: $r->print('<br /><span class="LC_nobreak"><label>'.
1.5 raeburn 2652: '<input type="checkbox" name="changepriv" value="'.$user.'" />'.$lt{'chpr'}.
1.83 bisitz 2653: '</label></span>');
1.36 raeburn 2654: }
2655: $r->print('
1.48 albertel 2656: </td>'.
2657: '<td>'.$fullname.'</td>'.
2658: '<td>'.$uname.'</td>'.
2659: '<td>'. $udom.'</td>'.
2660: '<td>'.$id.'</td>'.
2661: '<td>'.$start.'</td>'.
2662: '<td>'.$end.'</td>');
1.36 raeburn 2663: if ($hastools) {
1.83 bisitz 2664: $r->print('<td align="left"><span class="LC_nobreak">'.
1.6 raeburn 2665: ' ');
1.36 raeburn 2666: foreach my $tool (@{$$current{$user}{currtools}}) {
2667: if ($granularity eq 'Yes') {
2668: $r->print('<label><input type="checkbox" '.
1.7 raeburn 2669: 'checked="checked" '.
2670: 'name="user_'.$tool.'" value="'.
2671: $user.'" />'.$tool.'</label>');
1.36 raeburn 2672: } else {
2673: $r->print('<input type="hidden" '.
1.7 raeburn 2674: 'checked="checked" '.
2675: 'name="user_'.$tool.'" value="'.
2676: $user.'" />'.$tool);
1.36 raeburn 2677: }
2678: $r->print(' ');
1.5 raeburn 2679: }
1.83 bisitz 2680: $r->print('</span></td>');
1.36 raeburn 2681: }
2682: if ($addtools) {
1.48 albertel 2683: $r->print('<td align="left">');
1.36 raeburn 2684: if ($granularity eq 'Yes') {
2685: foreach my $tool (@{$$current{$user}{newtools}}) {
1.83 bisitz 2686: $r->print('<span class="LC_nobreak"><label><input type="checkbox"
1.5 raeburn 2687: name="user_'.$tool.'" value="'.
2688: $user.'" />'.$tool.
1.83 bisitz 2689: '</label></span> ');
1.36 raeburn 2690: }
2691: } else {
2692: foreach my $tool (@{$$current{$user}{newtools}}) {
1.83 bisitz 2693: $r->print('<span class="LC_nobreak"><input type="hidden"
1.5 raeburn 2694: name="user_'. $tool.'" value="'.
2695: $user.'" />'.$tool.
1.83 bisitz 2696: '</span> ');
1.5 raeburn 2697: }
2698: }
1.48 albertel 2699: $r->print('</td>');
1.5 raeburn 2700: }
1.48 albertel 2701: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.5 raeburn 2702: }
1.36 raeburn 2703: }
1.48 albertel 2704: $r->print(&Apache::loncommon::end_data_table());
1.53 raeburn 2705: } else {
2706: $r->print(&mt('There are no active, future or previous group members to modify.'));
1.5 raeburn 2707: }
1.53 raeburn 2708: return $numcurrent;
1.5 raeburn 2709: }
2710:
2711: sub check_uncheck_buttons {
2712: my ($r,$formname,$field,$title,$colspan) = @_;
2713: $r->print('
2714: <td '.$colspan.'>
2715: <fieldset>
1.102 bisitz 2716: <legend>'.$title.'</legend>
1.83 bisitz 2717: <span class="LC_nobreak">
1.80 bisitz 2718: <input type="button" value="'.&mt('check all').'"
1.5 raeburn 2719: onclick="javascript:checkAll(document.'.$formname.'.'.$field.')" />
2720:
1.80 bisitz 2721: <input type="button" value="'.&mt('uncheck all').'"
1.5 raeburn 2722: onclick="javascript:uncheckAll(document.'.$formname.'.'.$field.')" />
1.83 bisitz 2723: </span>
1.5 raeburn 2724: </fieldset>
2725: </td>
2726: ');
2727: }
2728:
2729:
2730: sub change_privs_form {
1.45 albertel 2731: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,
2732: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,
2733: $memchg,$idx,$states,$stored,$sectioncount,$navbuttons,$gpterm,
2734: $ucgpterm) = @_;
1.5 raeburn 2735: my @regexps = ('userpriv_');
2736: my $nexttext;
1.6 raeburn 2737: my %lt = &Apache::lonlocal::texthash(
2738: 'tode' => 'To be deleted',
2739: 'toex' => 'To be expired',
1.29 raeburn 2740: 'nome' => "No members to be deleted or expired from the $gpterm.",
1.6 raeburn 2741: );
1.5 raeburn 2742: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2743: ['origin','action','state','page','sortby'],\@regexps));
2744: if ($env{'form.branch'} eq 'adds') {
2745: $nexttext = $$navbuttons{'adme'};
2746: } else {
2747: $nexttext = $$navbuttons{'mose'};
2748: }
1.78 raeburn 2749: $r->print(&Apache::lonhtmlcommon::topic_bar(3,&mt('Members to delete or expire')));
1.6 raeburn 2750: my $exp_or_del = 0;
2751: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2752: if (@{$$memchg{'deletion'}} > 0) {
1.50 albertel 2753: $r->print('<b>'.$lt{'tode'}.':</b><br /><ul>');
1.6 raeburn 2754: foreach my $user (@{$$memchg{'deletion'}}) {
2755: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2756: ' ('.$user.')</li>');
2757: }
1.45 albertel 2758: $r->print('</ul>');
1.6 raeburn 2759: $exp_or_del += @{$$memchg{'deletion'}};
2760: }
2761: }
2762: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2763: if (@{$$memchg{'expire'}} > 0) {
1.50 albertel 2764: $r->print('<b>'.$lt{'toex'}.':</b><br /><ul>');
1.6 raeburn 2765: foreach my $user (@{$$memchg{'expire'}}) {
2766: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2767: ' ('.$user.')</li>');
2768: }
1.45 albertel 2769: $r->print('</ul>');
1.6 raeburn 2770: $exp_or_del += @{$$memchg{'expire'}};
2771: }
2772: }
2773: if (!$exp_or_del) {
1.45 albertel 2774: $r->print($lt{'nome'}.'<br />');
1.6 raeburn 2775: }
1.5 raeburn 2776:
1.78 raeburn 2777: $r->print(&Apache::lonhtmlcommon::topic_bar(4,&mt('Setting optional privileges for specific group members')));
1.6 raeburn 2778:
1.45 albertel 2779: my $numchgs = &member_privileges_form($r,$action,$formname,$tools,
1.6 raeburn 2780: $toolprivs,$fixedprivs,$userdata,
2781: $usertools,$idx,$memchg,$states,
1.45 albertel 2782: $stored,$gpterm);
1.5 raeburn 2783: my $prevtext = $$navbuttons{'gtps'};
1.6 raeburn 2784: if ($numchgs || $exp_or_del) {
2785: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2786: $$states{$action}[$page+1],$nexttext);
2787: } else {
2788: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext);
2789: }
1.5 raeburn 2790: return;
2791: }
2792:
2793: sub add_members_form {
1.59 raeburn 2794: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,$groupname,
1.29 raeburn 2795: $description,$granularity,$quota,$sectioncount,$tools,$functions,
1.104 raeburn 2796: $stored,$states,$navbuttons,$gpterm,$ucgpterm,$crstype)=@_;
1.40 albertel 2797: $r->print(' <br />');
1.5 raeburn 2798: my @available = ();
2799: my @unavailable = ();
2800: &check_tools($functions,$tools,\@available,\@unavailable);
1.40 albertel 2801: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2802: $groupname,$description,$granularity,$quota,
2803: \@available,\@unavailable,$gpterm,$ucgpterm);
1.59 raeburn 2804: &membership_options($r,$cdom,$cnum,$action,$formname,$sectioncount,1,$gpterm,
1.104 raeburn 2805: $ucgpterm,$crstype);
1.5 raeburn 2806: my $nexttext = $$navbuttons{'gtns'};
2807: my $prevtext = $$navbuttons{'gtpp'};
2808: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2809: $$states{$action}[$page+1],$nexttext);
2810: return;
2811: }
2812:
2813: sub choose_privs_form {
1.45 albertel 2814: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,
2815: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,$idx,
2816: $states,$stored,$sectioncount,$navbuttons,$gpterm,$ucgpterm,
2817: $crstype) = @_;
1.5 raeburn 2818:
2819: my @regexps = ('userpriv_');
2820: my $nexttext;
2821:
2822: if ($action eq 'create') {
2823: push(@regexps,'sec_');
2824: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2825: ['origin','action','state','page','sortby','autoadd','autodrop'],
1.5 raeburn 2826: \@regexps));
2827: $nexttext = $$navbuttons{'crgr'};
2828: } else {
2829: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2830: ['origin','action','state','page','sortby'],\@regexps));
1.5 raeburn 2831: $nexttext = $$navbuttons{'adme'};
2832: }
2833:
1.78 raeburn 2834: $r->print(&Apache::lonhtmlcommon::topic_bar(6,&mt('Setting optional privileges for specific group members')));
1.5 raeburn 2835:
1.45 albertel 2836: &member_privileges_form($r,$action,$formname,$tools,$toolprivs,
1.5 raeburn 2837: $fixedprivs,$userdata,$usertools,$idx,undef,
1.45 albertel 2838: $states,$stored,$gpterm);
1.5 raeburn 2839:
2840: if ($action eq 'create') {
1.53 raeburn 2841: my $img1 = 7;
2842: my $img2 = 8;
2843: &mapping_options($r,$action,$formname,$page,$sectioncount,
2844: $states,$stored,$navbuttons,$img1,$img2,
1.58 raeburn 2845: $gpterm,$ucgpterm,$crstype,$cdom,$cnum);
1.5 raeburn 2846: }
2847: my $prevtext = $$navbuttons{'gtps'};
2848: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2849: $$states{$action}[$page+1],$nexttext);
2850: return;
2851: }
2852:
2853: sub build_boxes {
2854: my ($r,$tools,$usertools,$fixedprivs,$toolprivs,$showtools,
1.6 raeburn 2855: $showboxes,$prefix,$specificity,$excluded) = @_;
1.5 raeburn 2856: my $totalboxes = 0;
2857: if (@{$tools} > 0) {
2858: if ($specificity eq 'Yes') {
2859: foreach my $tool (@{$tools}) {
2860: @{$$showboxes{$tool}} = ();
2861: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 2862: if (ref($excluded) eq 'ARRAY') {
2863: if (grep/^$user$/,@{$excluded}) {
2864: next;
2865: }
1.5 raeburn 2866: }
1.6 raeburn 2867: if ($$usertools{$user}{$tool}) {
2868: unless (grep/^$tool$/,@{$showtools}) {
2869: push(@{$showtools},$tool);
2870: }
2871: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2872: unless (exists($$fixedprivs{$tool}{$priv})) {
2873: unless(grep(/^$priv$/,@{$$showboxes{$tool}})) {
2874: push(@{$$showboxes{$tool}},$priv);
2875: $totalboxes ++;
2876: }
1.5 raeburn 2877: }
2878: }
2879: }
2880: }
2881: }
2882: if ($totalboxes > 0) {
2883: $r->print('
2884: <script type="text/javascript">
2885: function checkAllTools(formname) {
2886: ');
2887: foreach my $tool (sort(keys(%{$showboxes}))) {
2888: foreach my $priv (@{$$showboxes{$tool}}) {
2889: $r->print(' checkAll(formname.'.$prefix.$priv.');'."\n");
2890: }
2891: }
2892: $r->print('
2893: }
2894: function uncheckAllTools(formname) {
2895: ');
2896: foreach my $tool (sort(keys(%{$showboxes}))) {
2897: foreach my $priv (@{$$showboxes{$tool}}) {
2898: $r->print(' uncheckAll(formname'.$prefix.$priv.');'."\n");
2899: }
2900: }
2901: $r->print('
2902: }
2903: </script>
2904: ');
2905: }
2906: }
2907: }
2908: return $totalboxes;
2909: }
2910:
2911: sub member_privileges_form {
1.45 albertel 2912: my ($r,$action,$formname,$tools,$toolprivs,$fixedprivs,$userdata,
2913: $usertools,$idx,$memchg,$states,$stored,$gpterm) = @_;
1.5 raeburn 2914: my %lt = &Apache::lonlocal::texthash(
2915: 'addp' => 'Additional privileges',
1.53 raeburn 2916: 'fixp' => 'Core privileges',
1.5 raeburn 2917: 'oppr' => 'Optional privileges',
1.53 raeburn 2918: 'func' => 'Tool',
2919: 'forf' => 'For the collaborative tools included for group '.
2920: 'members being added or modified, '.
2921: 'there are no optional privileges to set '.
2922: 'for specific members.',
1.80 bisitz 2923: 'algr' => 'All new group members will receive the same privileges.',
2924: 'ifex' => 'If previously expired members are being re-enabled, or '.
1.54 raeburn 2925: 'if access for future members is being activated now, '.
2926: 'previously set privileges will be preserved.',
1.53 raeburn 2927: 'asno' => 'As no group members are being added, '.
2928: 'there are no specific user privileges to set.',
2929: 'asng' => 'As no group tools will be made available to users, '.
2930: 'there are no specific user privileges to set.',
2931: 'nogm' => 'No group member privileges to display or set, '.
2932: 'as you have not indicated that you will be activating,'.
2933: ' re-enabling, changing privileges, or adding/removing '.
2934: 'tools for any current members.',
1.5 raeburn 2935: 'full' => 'Fullname',
2936: 'user' => 'Username',
2937: 'doma' => 'Domain',
2938: );
2939: my @defprivs;
2940: my $specificity;
2941: if ($action eq 'create') {
2942: if (defined($env{'form.defpriv'})) {
2943: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
2944: }
2945: $specificity = $env{'form.specificity'};
2946: } else {
1.17 raeburn 2947: if (defined($$stored{'defpriv'})) {
2948: @defprivs = @{$$stored{'defpriv'}};
2949: }
1.5 raeburn 2950: $specificity = $$stored{'specificity'};
2951: }
2952: my @showtools;
2953: my %showboxes = ();
2954: my $numtools = 1 + @{$tools};
1.3 raeburn 2955:
1.6 raeburn 2956: my @excluded = ();
2957: my $numchgs = 0;
2958: if ($formname eq 'change_privs') {
2959: my @currmembers = ();
2960: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2961: push(@excluded,@{$$memchg{'deletion'}});
2962: }
2963: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2964: push(@excluded,@{$$memchg{'expire'}});
2965: }
2966: if (@excluded > 0) {
2967: foreach my $user (sort(keys(%{$usertools}))) {
2968: if (grep/^$user$/,@excluded) {
2969: next;
2970: }
2971: push(@currmembers,$user);
2972: }
2973: } else {
2974: @currmembers = sort(keys(%{$usertools}));
2975: }
2976: $numchgs = @currmembers;
2977: if (!$numchgs) {
1.45 albertel 2978: $r->print($lt{'nogm'});
1.6 raeburn 2979: return $numchgs;
2980: }
2981: }
2982:
2983: my $totalboxes = &build_boxes($r,$tools,$usertools,$fixedprivs,
2984: $toolprivs,\@showtools,\%showboxes,
2985: 'userpriv_',$specificity,\@excluded);
1.5 raeburn 2986: if (@{$tools} > 0) {
2987: if ($specificity eq 'Yes') {
2988: if ($totalboxes > 0) {
2989: my $numcells = 2;
2990: my $colspan = $numcells + 1;
2991: my %total;
1.6 raeburn 2992: if (keys(%{$usertools}) > 1) {
2993: $r->print('
1.45 albertel 2994: <table border="0" cellspacing="2" cellpadding="2">
1.5 raeburn 2995: <tr>
2996: ');
1.6 raeburn 2997: foreach my $tool (@{$tools}) {
2998: if (@{$showboxes{$tool}} > 0) {
2999: $r->print('<td valign="top">');
1.100 bisitz 3000: $r->print('<fieldset><legend>'.&mt($tool).'</legend>');
3001: $r->print('<table><tr>');
1.6 raeburn 3002: my $privcount = 0;
3003: foreach my $priv (@{$showboxes{$tool}}) {
3004: $privcount ++;
3005: if (($privcount == @{$showboxes{$tool}}) &&
3006: ($privcount > 1)) {
3007: if ($privcount%$numcells) {
3008: $r->print('<td colspan="'.$colspan.'">');
3009: } else {
3010: $r->print('<td>');
3011: }
1.5 raeburn 3012: } else {
3013: $r->print('<td>');
3014: }
1.80 bisitz 3015: $r->print(
1.102 bisitz 3016: '<fieldset><legend>'.&mt($$toolprivs{$tool}{$priv}).'</legend>'
1.80 bisitz 3017: .'<span class="LC_nobreak">'
3018: .' <input type="button" value="'.&mt('check all').'"'
3019: .' onclick="javascript:checkAll(document.'.$formname.'.userpriv_'.$priv.')" />'
3020: .' '
3021: .'<input type="button" value="'.&mt('uncheck all').'"'
3022: .' onclick="javascript:uncheckAll(document.'.$formname.'.userpriv_'.$priv.')" />'
3023: .'</span></fieldset><br />'
3024: );
1.6 raeburn 3025: $r->print('</td>');
3026: if ($privcount < @{$showboxes{$tool}}) {
3027: if (@{$showboxes{$tool}} > 2) {
3028: if ($privcount%$numcells == 0) {
3029: $r->print('</tr><tr>');
3030: }
3031: } else {
3032: $r->print('<tr></tr>');
1.5 raeburn 3033: }
3034: }
3035: }
1.100 bisitz 3036: $r->print('</tr></table></fieldset></td><td> </td>');
1.5 raeburn 3037: }
3038: }
1.45 albertel 3039: $r->print('</tr></table>');
1.5 raeburn 3040: }
1.45 albertel 3041: $r->print(&Apache::loncommon::start_data_table().
3042: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 3043: $r->print(<<"END");
1.45 albertel 3044: <th>$lt{'full'}</th>
3045: <th>$lt{'user'}</th>
1.5 raeburn 3046: <th>$lt{'doma'}</th>
3047: <th colspan="$numtools">$lt{'addp'}</th>
3048: END
1.45 albertel 3049: $r->print(&Apache::loncommon::end_data_table_header_row());
3050: &member_privs_entries($r,$usertools,$toolprivs,$fixedprivs,
1.6 raeburn 3051: $userdata,$idx,\@showtools,\@defprivs,
3052: \@excluded);
1.45 albertel 3053: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 3054: } else {
1.43 albertel 3055: $r->print($lt{'forf'}.'<br />');
1.45 albertel 3056: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 3057: }
3058: } else {
3059: if (keys(%{$usertools}) > 0) {
1.54 raeburn 3060: $r->print($lt{'algr'}.'<br />'.$lt{'ifex'}.'<br /><br />');
1.45 albertel 3061: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 3062: } else {
1.43 albertel 3063: $r->print($lt{'asno'}.'<br />');
1.5 raeburn 3064: }
3065: }
3066: } else {
1.43 albertel 3067: $r->print($lt{'asng'});
1.5 raeburn 3068: }
1.6 raeburn 3069: return $numchgs;
1.1 raeburn 3070: }
3071:
1.5 raeburn 3072: sub process_request {
1.45 albertel 3073: my ($r,$cdom,$cnum,$action,$state,$page,$groupname,$description,
1.5 raeburn 3074: $specificity,$userdata,$startdate,$enddate,$tools,$functions,$toolprivs,
3075: $usertools,$idx,$types,$roles,$sections,$states,$navbuttons,$memchg,
1.45 albertel 3076: $sectioncount,$stored,$gpterm,$ucgpterm,$crstype) = @_;
1.3 raeburn 3077:
3078: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 3079: ['origin','action','state','page','sortby']));
1.5 raeburn 3080:
1.29 raeburn 3081: my $earlyout = &validate_groupname($groupname,$action,$cdom,$cnum,$gpterm,
3082: $ucgpterm,$crstype);
1.5 raeburn 3083: if ($earlyout) {
3084: $r->print('
3085: <table width="100%" cellpadding="0" cellspacing="0" border="0">
3086: <tr>
3087: <td> </td>
3088: <td colspan="3">
3089: '.$earlyout.'</td></tr>');
3090: &display_navbuttons($r,$state,$$states{$action}[$page-1],
3091: $$navbuttons{'gtps'});
3092: $r->print('</table>');
3093: return;
3094: }
3095:
3096: my @defprivs = ();
3097: if ($action eq 'create' || $state eq 'chgresult') {
3098: if (defined($env{'form.defpriv'})) {
3099: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
3100: }
3101: if ($state eq 'chgresult') {
3102: my @okprivs = ();
3103: foreach my $tool (@{$tools}) {
3104: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3105: push(@okprivs,$priv);
3106: }
3107: }
3108: my @temp = ();
3109: foreach my $defpriv (@defprivs) {
3110: if (grep/^$defpriv$/,@okprivs) {
3111: push(@temp,$defpriv);
3112: }
3113: }
3114: @defprivs = @temp;
3115: }
3116: } else {
1.17 raeburn 3117: if (defined($$stored{'defpriv'})) {
3118: @defprivs = @{$$stored{'defpriv'}};
3119: }
1.5 raeburn 3120: }
3121:
3122: my $outcome;
3123: if ($action eq 'create' || $state eq 'chgresult') {
3124: $outcome = &write_group_data($r,$cdom,$cnum,$action,$state,$groupname,
3125: $description,$startdate,$enddate,
3126: $specificity,$functions,$tools,
3127: $sectioncount,$roles,$types,$sections,
1.29 raeburn 3128: \@defprivs,$stored,$gpterm,$ucgpterm,
3129: $crstype);
1.5 raeburn 3130: }
3131: if (($action eq 'create' && $outcome eq 'ok') || (($action eq 'modify') &&
3132: (($state eq 'memresult') || ($state eq 'addresult')))) {
1.6 raeburn 3133: &process_membership($r,$cdom,$cnum,$action,$state,$groupname,$tools,
3134: $enddate,$startdate,$userdata,$idx,$toolprivs,
1.29 raeburn 3135: $usertools,$specificity,\@defprivs,$memchg,$gpterm,
1.104 raeburn 3136: $ucgpterm,$crstype);
1.5 raeburn 3137: }
3138: return;
3139: }
3140:
3141: sub write_group_data {
3142: my ($r,$cdom,$cnum,$action,$state,$groupname,$description,$startdate,
3143: $enddate,$specificity,$functions,$tools,$sectioncount,$roles,$types,
1.29 raeburn 3144: $sections,$defprivs,$stored,$gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 3145: my $now = time;
3146: my $creation = $now;
3147: my $creator = $env{'user.name'}.':'.$env{'user.domain'};
3148: if ($state eq 'chgresult') {
3149: $creation = $$stored{'creation'};
3150: $creator = $$stored{'creator'};
3151: }
1.24 www 3152: my $esc_description = &escape($description);
1.5 raeburn 3153: my @single_attributes = ('description','functions','startdate','enddate',
3154: 'creation','modified','creator','granularity',
1.29 raeburn 3155: 'specificity','autoadd','autodrop','quota');
1.5 raeburn 3156: my @mult_attributes = ('roles','types','sectionpick','defpriv');
1.15 albertel 3157:
1.37 raeburn 3158: my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,
3159: $stored);
3160: my $quota = $env{'form.quota'};
3161:
3162: $quota =~ s/^\s*([^\s]*)\s*$/$1/;
3163: if ($quota eq '') {
3164: $quota = 0;
3165: }
3166: if ($quota !~ /^\d*\.?\d*$/) {
3167: $quota = 0;
1.79 bisitz 3168: $r->print('<div class="LC_warning">'
1.96 weissno 3169: .&mt('The value you entered for the quota for the group portfolio in this '.$gpterm
1.79 bisitz 3170: .' contained invalid characters, so it has been set to 0 Mb. You can change this by'
3171: .' modifying the '.$gpterm.' settings.')
3172: .'</div>');
1.37 raeburn 3173: }
3174: if ($quota > $maxposs) {
3175: $quota = $maxposs;
1.79 bisitz 3176: $r->print('<div class="LC_warning">'
1.96 weissno 3177: .&mt('The value you entered for the quota for the group portfolio in this '.$gpterm
1.79 bisitz 3178: .' exceeded the maximum possible value, so it has been set to [_1] Mb '
3179: .'(the maximum possible value).',sprintf("%.2f",$maxposs))
3180: .'</div>');
1.37 raeburn 3181: }
1.5 raeburn 3182: my %groupinfo = (
3183: description => $esc_description,
3184: startdate => $startdate,
3185: enddate => $enddate,
3186: creation => $creation,
3187: modified => $now,
3188: creator => $creator,
3189: granularity => $env{'form.granularity'},
3190: specificity => $specificity,
3191: autoadd => $env{'form.autoadd'},
3192: autodrop => $env{'form.autodrop'},
1.37 raeburn 3193: quota => $quota,
1.5 raeburn 3194: );
1.37 raeburn 3195:
1.5 raeburn 3196: foreach my $func (keys(%{$functions})) {
3197: my $status;
3198: if (grep(/^$func$/,@{$tools})) {
3199: $status = 'on';
3200: } else {
3201: $status = 'off';
3202: }
3203: $groupinfo{'functions'} .= qq|<name id="$func">$status</name>|;
3204: }
3205:
3206: $groupinfo{'roles'} = $roles;
3207: $groupinfo{'types'} = $types;
3208: $groupinfo{'sectionpick'} = $sections;
3209: $groupinfo{'defpriv'} = $defprivs;
3210:
3211: my %groupsettings = ();
3212: foreach my $item (@single_attributes) {
3213: $groupsettings{$groupname} .= qq|<$item>$groupinfo{$item}</$item>|;
3214: }
3215: foreach my $item (@mult_attributes) {
3216: foreach my $entry (@{$groupinfo{$item}}) {
3217: $groupsettings{$groupname} .= qq|<$item>$entry</$item>|;
3218: }
3219: }
3220: my $autosec;
3221: my @autorole = &Apache::loncommon::get_env_multiple('form.autorole');
1.15 albertel 3222:
1.5 raeburn 3223: foreach my $role (@autorole) {
3224: if (defined($env{'form.sec_'.$role})) {
3225: my @autosections=&Apache::loncommon::get_env_multiple('form.sec_'.
3226: $role);
3227: $autosec .= '<role id="'.$role.'">';
3228: foreach my $sec (@autosections) {
3229: $autosec .= '<section>'.$sec.'</section>';
3230: }
3231: $autosec .= '</role>';
3232: }
3233: }
3234: if ($autosec) {
3235: $groupsettings{$groupname} .= qq|<autosec>$autosec</autosec>|;
3236: }
3237: my $result = &Apache::lonnet::modify_coursegroup($cdom,$cnum,
3238: \%groupsettings);
3239:
3240: if ($result eq 'ok') {
3241: if ($action eq 'create') {
1.32 raeburn 3242: my $result = &add_group_folder($cdom,$cnum,$now,$groupname,$action,
3243: $description,$tools,\%groupinfo,
3244: $gpterm,$ucgpterm,$crstype);
1.79 bisitz 3245: if ($result eq 'ok') {
3246: $r->print('<div class="LC_success">'
3247: .&mt($ucgpterm.' [_1] was created.','<i>'.$groupname.'</i>')
3248: .'</div>');
3249: } else {
3250: $r->print('<div class="LC_error">'
3251: .&mt('A problem occurred when creating folders for the new '.$gpterm.' [_1]:'
3252: ,'<i>'.$groupname.'</i>')
3253: .'<br />'.$result
3254: .'</div>');
1.32 raeburn 3255: }
1.56 raeburn 3256: } elsif ($action eq 'modify') {
3257: my (@oldtools,@newtools);
3258: if (ref($$stored{'tool'}) eq 'ARRAY') {
3259: @oldtools = @{$$stored{'tool'}};
3260: }
3261: if (ref($tools) eq 'ARRAY') {
3262: @newtools = @{$tools};
3263: }
3264: if (!grep(/^discussion$/,@oldtools) &&
3265: grep(/^discussion$/,@newtools)) {
3266: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
3267: my $boardsmap = $crspath.'group_boards_'.$groupname.'.sequence';
3268: my $navmap = Apache::lonnavmaps::navmap->new();
1.85 raeburn 3269: my ($bbmapres,$error);
3270: if (defined($navmap)) {
3271: $bbmapres = $navmap->getResourceByUrl($boardsmap);
3272: undef($navmap);
3273: if (!$bbmapres) {
3274: my $grpmap = $crspath.'group_folder_'.$groupname.'.sequence';
3275: my $disctitle = &mt('Discussion Boards');
3276: my $outcome = &map_updater($cdom,$cnum,'group_boards_'.
3277: $groupname.'.sequence','bbseq',
3278: $disctitle,$grpmap);
3279: my ($furl,$ferr) =
3280: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
3281: # modify parameter
3282: if ($outcome eq 'ok') {
3283: $navmap = Apache::lonnavmaps::navmap->new();
3284: if (defined($navmap)) {
3285: my $parm_result = &parm_setter($navmap,$cdom,$boardsmap,
3286: $groupname);
3287: if ($parm_result) {
3288: $error = &mt('An error occurred while setting parameters '
3289: .'for Discussion Boards folder: '
3290: .'[_1]',$parm_result);
3291: } else {
3292: $r->print('<div class="LC_success">'.
3293: &mt('Discussion Boards Folder created.')
3294: .'</div>');
3295: }
3296: undef($navmap);
3297: } else {
1.104 raeburn 3298: if ($crstype eq 'Community') {
3299: $error = &mt("An error occurred while setting parameters '.
1.85 raeburn 3300: 'for Discussion Boards folder: '.
1.104 raeburn 3301: 'Could not retrieve community information");
3302: } else {
3303: $error = &mt("An error occurred while setting parameters '.
3304: 'for Discussion Boards folder: '.
3305: 'Could not retrieve course information");
3306: }
1.85 raeburn 3307: }
1.56 raeburn 3308: } else {
1.85 raeburn 3309: $r->print($outcome);
1.56 raeburn 3310: }
3311: }
1.85 raeburn 3312: } else {
1.104 raeburn 3313: $error = &mt("An error occurred while retrieving the contents of the group's folder.").'<br />';
3314: if ($crstype eq 'Community') {
3315: $error .= &mt("You need to re-initialize the community.");
3316:
3317: } else {
3318: $error .= &mt("You need to re-initialize the course.");
3319: }
1.85 raeburn 3320: }
3321: if ($error ne '') {
3322: $r->print('<div class="LC_error">'.$error.'</div>');
1.56 raeburn 3323: }
3324: }
1.79 bisitz 3325: $r->print('<div class="LC_success">'
3326: .&mt($ucgpterm.' [_1] was updated.','<i>'.$groupname.'</i>')
3327: .'</div>');
1.5 raeburn 3328: }
3329: } else {
3330: my %actiontype = (
3331: 'create' => 'creating',
3332: 'modify' => 'modifying',
3333: );
1.29 raeburn 3334: &Apache::lonnet::logthis("Failed to store $gpterm $groupname ".
3335: 'in '.lc($crstype).': '.$cnum.
3336: ' in domain: '.$cdom);
1.79 bisitz 3337: $r->print('<div class="LC_error">'
3338: .&mt('An error occurred when [_1] the '.$gpterm.'. '
3339: .'Please try again.',$actiontype{$action})
3340: .'</div>');
1.5 raeburn 3341: }
3342: return $result;
3343: }
3344:
3345: sub process_membership {
1.6 raeburn 3346: my ($r,$cdom,$cnum,$action,$state,$groupname,$tools,$enddate,$startdate,
1.29 raeburn 3347: $userdata,$idx,$toolprivs,$usertools,$specificity,$defprivs,$memchg,
1.104 raeburn 3348: $gpterm,$ucgpterm,$crstype)=@_;
1.5 raeburn 3349: my %usersettings = ();
1.6 raeburn 3350: my %added= ();
3351: my %failed = ();
3352: my $num_ok = 0;
3353: my $num_fail = 0;
1.3 raeburn 3354: my %group_privs = ();
1.20 raeburn 3355: my %curr_privs = ();
1.21 raeburn 3356: my %curr_start = ();
3357: my %curr_end = ();
1.3 raeburn 3358: my %tooltype = ();
1.77 raeburn 3359: my $context = 'processgroupmembership';
1.5 raeburn 3360:
1.3 raeburn 3361: foreach my $tool (@{$tools}) {
3362: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3363: $tooltype{$priv} = $tool;
1.5 raeburn 3364: if ($specificity eq 'Yes') {
1.3 raeburn 3365: my @users =
3366: &Apache::loncommon::get_env_multiple('form.userpriv_'.$priv);
3367: foreach my $user (@users) {
3368: $group_privs{$user} .= $priv.':';
1.8 raeburn 3369: if ($state eq 'memresult') {
3370: unless (exists($$usertools{$user}{$tool})) {
3371: $$usertools{$user}{$tool} = 1;
3372: }
3373: }
1.3 raeburn 3374: }
3375: } else {
1.5 raeburn 3376: if (@{$defprivs} > 0) {
1.26 raeburn 3377: if (grep/^\Q$priv\E$/,@{$defprivs}) {
1.5 raeburn 3378: foreach my $user (sort(keys(%{$usertools}))) {
3379: if ($$usertools{$user}{$tool}) {
3380: $group_privs{$user} .= $priv.':';
3381: }
1.3 raeburn 3382: }
3383: }
3384: }
3385: }
3386: }
3387: }
3388: foreach my $user (keys(%group_privs)) {
3389: $group_privs{$user} =~ s/:$//;
3390: }
1.5 raeburn 3391:
1.6 raeburn 3392: my $now = time;
3393: my @activate = ();
3394: my @expire = ();
3395: my @deletion = ();
3396: my @reenable = ();
1.20 raeburn 3397: my @unchanged = ();
1.6 raeburn 3398: if ($state eq 'memresult') {
3399: if (ref($$memchg{'activate'}) eq 'ARRAY') {
3400: @activate = @{$$memchg{'activate'}};
3401: }
3402: if (ref($$memchg{'expire'}) eq 'ARRAY') {
3403: @expire = @{$$memchg{'expire'}};
3404: }
3405: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
3406: @deletion = @{$$memchg{'deletion'}};
3407: }
3408: if (ref($$memchg{'reenable'}) eq 'ARRAY') {
3409: @reenable = @{$$memchg{'reenable'}};
3410: }
1.20 raeburn 3411: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
3412: $groupname);
3413: foreach my $key (sort(keys(%membership))) {
3414: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
1.21 raeburn 3415: ($curr_end{$1},$curr_start{$1},$curr_privs{$1}) =
3416: split(/:/,$membership{$key},3);
1.20 raeburn 3417: }
3418: }
1.6 raeburn 3419: if (@expire + @deletion > 0) {
3420: foreach my $user (@expire) {
1.21 raeburn 3421: my $savestart = $curr_start{$user};
3422: if ($savestart > $now) {
3423: $savestart = $now;
1.6 raeburn 3424: }
1.21 raeburn 3425: $usersettings{$groupname.':'.$user} = $now.':'.$savestart.':'.
3426: $curr_privs{$user};
1.6 raeburn 3427: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.21 raeburn 3428: $user,$now,$savestart,
1.77 raeburn 3429: $curr_privs{$user},'',$context) eq 'ok') {
1.6 raeburn 3430: push(@{$added{'expired'}},$user);
3431: $num_ok ++;
3432: } else {
3433: push(@{$failed{'expired'}},$user);
3434: $num_fail ++;
3435: }
3436: }
3437: foreach my $user (@deletion) {
3438: $usersettings{$groupname.':'.$user} = $now.':-1:';
3439: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.76 raeburn 3440: $user,$now,'-1','','',$context)
1.6 raeburn 3441: eq 'ok') {
3442: push(@{$added{'deleted'}},$user);
3443: $num_ok ++;
3444: } else {
3445: push(@{$failed{'deleted'}},$user);
3446: $num_fail ++;
3447: }
3448: }
3449: }
1.8 raeburn 3450: }
1.6 raeburn 3451:
1.5 raeburn 3452: foreach my $user (sort(keys(%{$usertools}))) {
1.20 raeburn 3453: if ((grep(/^$user$/,@expire)) || (grep(/^$user$/,@deletion))) {
3454: next;
3455: }
1.6 raeburn 3456: my $type;
3457: my $start = $startdate;
3458: my $end = $enddate;
3459: if ($state eq 'memresult') {
3460: if (@activate > 0) {
3461: if (grep/^$user$/,@activate) {
3462: $start = $now;
1.21 raeburn 3463: $end = $enddate;
1.6 raeburn 3464: $type = 'activated';
3465: }
3466: }
3467: if (@reenable > 0) {
3468: if (grep/^$user$/,@reenable) {
1.21 raeburn 3469: $start = $startdate;
3470: $end = $enddate;
1.6 raeburn 3471: $type = 'reenabled';
3472: }
3473: }
1.38 raeburn 3474: if ($type eq '') {
3475: if ($curr_privs{$user} eq $group_privs{$user}) {
3476: push(@unchanged,$user);
3477: next;
3478: }
3479: if (exists($curr_start{$user})) {
3480: $start = $curr_start{$user};
3481: }
3482: if (exists($curr_end{$user})) {
3483: $end = $curr_end{$user};
3484: }
3485: $type = 'modified';
3486: }
1.6 raeburn 3487: } else {
3488: $type = 'added';
3489: }
3490: $usersettings{$groupname.':'.$user} = $end.':'.$start.':'.
1.5 raeburn 3491: $group_privs{$user};
3492: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.6 raeburn 3493: $user,$end,$start,
1.76 raeburn 3494: $group_privs{$user},'',$context) eq 'ok') {
1.6 raeburn 3495: push(@{$added{$type}},$user);
3496: $num_ok ++;
1.3 raeburn 3497: } else {
1.6 raeburn 3498: push(@{$failed{$type}},$user);
3499: $num_fail ++;
1.5 raeburn 3500: }
3501: }
3502: my $roster_result = &Apache::lonnet::modify_coursegroup_membership($cdom,
3503: $cnum,\%usersettings);
1.6 raeburn 3504: if ($num_ok) {
3505: foreach my $type (sort(keys(%added))) {
3506: $r->print(&mt('The following users were successfully [_1]',$type));
1.20 raeburn 3507: if (!($type eq 'deleted' || $type eq 'expired')) {
1.6 raeburn 3508: $r->print(&mt(' with the following privileges'));
3509: }
3510: $r->print(':<br />');
3511: foreach my $user (@{$added{$type}}) {
1.8 raeburn 3512: my $privlist = '';
3513: if (!($type eq 'deleted' || $type eq 'expired')) {
3514: $privlist = ': ';
1.6 raeburn 3515: my @privs = split(/:/,$group_privs{$user});
3516: my $curr_tool = '';
3517: foreach my $priv (@privs) {
3518: unless ($curr_tool eq $tooltype{$priv}) {
3519: $curr_tool = $tooltype{$priv};
3520: $privlist .= '<b>'.$curr_tool.'</b>: ';
3521: }
3522: $privlist .= $$toolprivs{$curr_tool}{$priv}.', ';
3523: }
3524: $privlist =~ s/, $//;
3525: }
1.8 raeburn 3526: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.$privlist.'<br />');
1.6 raeburn 3527: }
1.20 raeburn 3528: $r->print('<br />');
1.6 raeburn 3529: }
3530: }
3531: if ($num_fail) {
3532: foreach my $type (sort(keys(%failed))) {
1.79 bisitz 3533: $r->print('<div class="LC_error">'
3534: .&mt("The following users could not be $type, because an error occurred:")
3535: .'</div>');
1.6 raeburn 3536: foreach my $user (@{$failed{$type}}) {
3537: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
3538: }
1.5 raeburn 3539: }
1.20 raeburn 3540: $r->print('<br />');
3541: }
3542: if (@unchanged > 0) {
1.80 bisitz 3543: $r->print(&mt('No change occurred for the following users:').'<br />');
1.20 raeburn 3544: foreach my $user (sort(@unchanged)) {
3545: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
3546: }
3547: $r->print('<br />');
1.5 raeburn 3548: }
3549: if ($roster_result eq 'ok') {
1.80 bisitz 3550: $r->print('<div class="LC_success">'
3551: .&mt($ucgpterm.' membership list updated.')
3552: .'</div>');
1.104 raeburn 3553: $r->print('<p class="LC_info">');
3554: if ($crstype eq 'Community') {
3555: $r->print(&mt("Any currently logged in community users affected by the changes you made"
1.80 bisitz 3556: .' to group membership or privileges for the [_1] group will need to log out'
3557: .' and log back in for their LON-CAPA sessions to reflect these changes.'
1.104 raeburn 3558: ,'<i>'.$groupname.'</i>'));
3559:
3560: } else {
3561: $r->print(&mt("Any currently logged in course users affected by the changes you made"
3562: .' to group membership or privileges for the [_1] group will need to log out'
3563: .' and log back in for their LON-CAPA sessions to reflect these changes.'
3564: ,'<i>'.$groupname.'</i>'));
3565: }
3566: $r->print('</p>');
1.5 raeburn 3567: } else {
1.80 bisitz 3568: $r->print('<div class="LC_error">'
3569: .&mt("An error occurred while updating the $gpterm membership list:")
3570: .'<br />'.$roster_result
3571: .'</div>');
1.5 raeburn 3572: }
3573: return;
3574: }
3575:
3576: sub mapping_options {
1.44 albertel 3577: my ($r,$action,$formname,$page,$sectioncount,$states,$stored,
1.58 raeburn 3578: $navbuttons,$img1,$img2,$gpterm,$ucgpterm,$crstype,$cdom,$cnum) = @_;
1.5 raeburn 3579: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 3580: 'auto' => "Settings for automatic $gpterm enrollment",
3581: 'gmma' => "$ucgpterm membership mapping to specific sections/roles",
3582: 'endi' => "Enable/disable automatic $gpterm enrollment for ".
3583: "users in specified roles and sections",
1.53 raeburn 3584: 'adds' => "If automatic $gpterm enrollment is enabled, when a user is newly assigned a ".lc($crstype)."-wide or section-specific role, he/she will automatically be added as a member of the $gpterm, with start and end access dates defined by the default dates set for the $gpterm, unless he/she is already a $gpterm member, with access dates that permit either current or future $gpterm access.",
1.29 raeburn 3585: 'drops' => "If automatic $gpterm disenrollment is enabled, when a user's role is expired, access to the $gpterm will be terminated unless the user continues to have other ".lc($crstype)."-wide or section-specific active or future roles which receive automatic membership in the $gpterm.",
3586: 'pirs' => "Pick roles and sections for automatic $gpterm enrollment",
1.5 raeburn 3587: 'on' => 'on',
3588: 'off' => 'off',
1.29 raeburn 3589: 'auad' => "Automatically enable $gpterm membership when roles are added?",
3590: 'auex' => "Automatically expire $gpterm membership when roles are removed?",
3591: 'mapr' => "Mapping of roles and sections affected by automatic $gpterm enrollment/disenrollment follows scheme chosen below.",
1.5 raeburn 3592: );
1.44 albertel 3593: &automapping($r,$action,$stored,\%lt,$img1);
1.58 raeburn 3594: &mapping_settings($r,$sectioncount,\%lt,$stored,$img2,$crstype,$cdom,$cnum,
3595: $action);
1.5 raeburn 3596: return;
3597: }
3598:
3599: sub automapping {
1.44 albertel 3600: my ($r,$action,$stored,$lt,$image) = @_;
1.5 raeburn 3601: my $add = 'off';
3602: my $drop = 'off';
3603: if (exists($$stored{'autoadd'})) {
3604: $add = $$stored{'autoadd'};
3605: }
3606: if (exists($$stored{'autodrop'})) {
3607: $drop = $$stored{'autodrop'};
3608: }
1.78 raeburn 3609: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$$lt{'endi'}).'
1.44 albertel 3610: <b>'.$$lt{'gmma'}.':</b><br />'.$$lt{'adds'}.'<br />'.$$lt{'drops'}.'<br /><br />
1.83 bisitz 3611: <span class="LC_nobreak">'.$$lt{'auad'}.':
1.80 bisitz 3612: <label><input type="radio" name="autoadd" value="on" />'.&mt('on').' </label><label><input type="radio" name="autoadd" value="off" checked="checked" />'.&mt('off').'</label>');
1.5 raeburn 3613: if ($action eq 'modify') {
1.82 bisitz 3614: $r->print(' ('.&mt('Currently set to [_1].','<b>'.$$lt{$add}.'</b>').')');
1.5 raeburn 3615: }
3616: $r->print('
1.83 bisitz 3617: </span><br />
3618: <span class="LC_nobreak">'.$$lt{'auex'}.':
1.80 bisitz 3619: <label><input type="radio" name="autodrop" value="on" />'.&mt('on').' </label><label><input type="radio" name="autodrop" value="off" checked="checked" />'.&mt('off').'</label>');
1.5 raeburn 3620: if ($action eq 'modify') {
1.82 bisitz 3621: $r->print(' ('.&mt('Currently set to [_1].','<b>'.$$lt{$drop}.'</b>').')');
1.3 raeburn 3622: }
1.83 bisitz 3623: $r->print('</span><br /><br />'.$$lt{'mapr'});
1.5 raeburn 3624: }
1.3 raeburn 3625:
1.5 raeburn 3626: sub mapping_settings {
1.58 raeburn 3627: my ($r,$sectioncount,$lt,$stored,$image,$crstype,$cdom,$cnum,$action) = @_;
1.5 raeburn 3628: my @sections = keys(%{$sectioncount});
3629: if (@sections > 0) {
3630: @sections = sort {$a cmp $b} @sections;
1.17 raeburn 3631: unshift(@sections,'none'); # Put 'no sections' next
3632: unshift(@sections,'all'); # Put 'all' at the front of the list
1.53 raeburn 3633: } else {
3634: @sections = ('all','none');
1.3 raeburn 3635: }
1.78 raeburn 3636: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$$lt{'pirs'}));
1.104 raeburn 3637: my @roles = &standard_roles($crstype);
1.59 raeburn 3638: my %customroles = &Apache::lonhtmlcommon::course_custom_roles($cdom,$cnum);
1.44 albertel 3639: $r->print(&Apache::loncommon::start_data_table().
3640: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 3641: $r->print('
3642: <th>'.&mt('Active?').'</th>
3643: <th>'.&mt('Role').'</th>');
3644: if (@sections > 0) {
1.44 albertel 3645: $r->print('<th>'.&mt('Sections').'</th>');
1.3 raeburn 3646: }
1.44 albertel 3647: $r->print(&Apache::loncommon::end_data_table_header_row()."\n");
1.5 raeburn 3648: foreach my $role (@roles) {
1.58 raeburn 3649: my $roletitle=&Apache::lonnet::plaintext($role,$crstype);
3650: $r->print(&print_autorole_item($role,$roletitle,\@sections));
1.5 raeburn 3651: }
1.58 raeburn 3652: my @customs;
1.5 raeburn 3653: foreach my $role (sort(keys(%customroles))) {
1.58 raeburn 3654: my ($roletitle) = ($role =~ m|^cr/[^/]+/[^/]+/(.+)$|);
3655: push (@customs,$role);
3656: $r->print(&print_autorole_item($role,$roletitle,\@sections));
3657: }
3658: if ($action eq 'modify') {
3659: foreach my $role (@{$$stored{'autorole'}}) {
3660: if ((!grep(/^\Q$role\E$/,@customs)) &&
3661: (!grep(/^\Q$role\E$/,@roles))) {
3662: my $roletitle;
3663: if ($role =~ /^cr/) {
3664: ($roletitle) = ($role =~ m|_([^_]+)$|);
3665: } else {
3666: $roletitle = &Apache::lonnet::plaintext($role,$crstype);
3667: }
3668: $r->print(&print_autorole_item($role,$roletitle,\@sections));
3669: }
3670: }
1.5 raeburn 3671: }
1.44 albertel 3672: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 3673: return;
3674: }
1.3 raeburn 3675:
1.58 raeburn 3676: sub print_autorole_item {
3677: my ($role,$roletitle,$sections) = @_;
3678: my $sections_sel;
3679: if (@{$sections} > 0) {
1.104 raeburn 3680: if (($role eq 'cc') || ($role eq 'co')) {
1.58 raeburn 3681: $sections_sel = '<td align="right">'.
3682: &mt('all sections').'<input type="hidden" '.
1.104 raeburn 3683: 'name="sec_'.$role.'" value="all" /></td>';
1.58 raeburn 3684: } else {
3685: $sections_sel='<td align="right">'.
3686: §ions_selection($sections,'sec_'.$role).
3687: '</td>';
3688: }
3689: }
3690: my $output = &Apache::loncommon::start_data_table_row().
3691: '<td><input type="checkbox" '.
3692: 'name="autorole" value="'.$role.'" />'.
3693: '</td><td>'.$roletitle.'</td>'.$sections_sel.
3694: &Apache::loncommon::end_data_table_row();
3695: return $output;
3696: }
3697:
1.5 raeburn 3698: sub standard_roles {
1.104 raeburn 3699: my ($crstype) = @_;
3700: my @roles = qw(in ta ep ad st);
3701: if ($crstype eq 'Community') {
3702: unshift(@roles,'co');
3703: } else {
3704: unshift(@roles,'cc');
3705: }
1.5 raeburn 3706: return @roles;
3707: }
3708:
3709: sub modify_menu {
1.29 raeburn 3710: my ($r,$groupname,$page,$gpterm) = @_;
1.5 raeburn 3711: my @menu =
1.106 wenzelju 3712: ( { categorytitle =>'Group Actions',
3713: items => [
3714:
3715: { linktext => "Modify default $gpterm settings",
3716: url => '/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state=change_settings&branch=settings',
3717: icon => 'grp_settings.png',
3718: alttext => "Modify default $gpterm settings",
3719: permission => '1',
3720: help => 'Course_Modify_Group',
1.5 raeburn 3721: },
1.106 wenzelju 3722: { linktext => 'Modify access, tools and privileges for members',
3723: url => '/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state=change_members&branch=members',
3724: icon => 'grp_tools.png',
3725: alttext => 'Modify access, tools and privileges for members',
3726: permission => '1',
1.5 raeburn 3727: help => 'Course_Modify_Group_Membership',
3728: },
1.106 wenzelju 3729: { linktext => "Add member(s) to the $gpterm",
3730: url => '/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state=add_members&branch=adds',
3731: icon => 'grp_add.png',
3732: alttext => "Add member(s) to the $gpterm",
3733: permission => '1',
1.5 raeburn 3734: help => 'Course_Group_Add_Members',
1.106 wenzelju 3735: }]}
3736: );
3737: $r->print(&Apache::lonhtmlcommon::generate_menu(@menu));
1.3 raeburn 3738: return;
3739: }
3740:
3741: sub member_privs_entries {
1.45 albertel 3742: my ($r,$usertools,$toolprivs,$fixedprivs,$userdata,$idx,$showtools,
3743: $defprivs,$excluded) = @_;
1.5 raeburn 3744: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 3745: if (defined($excluded)) {
3746: if (ref($excluded) eq 'ARRAY') {
3747: if (grep/^$user$/,@{$excluded}) {
3748: next;
3749: }
3750: }
3751: }
1.5 raeburn 3752: my ($uname,$udom) = split(/:/,$user);
1.45 albertel 3753: $r->print(&Apache::loncommon::start_data_table_row().'
1.5 raeburn 3754: <td>'.$$userdata{$user}[$$idx{fullname}].'</td>
1.3 raeburn 3755: <td>'.$uname.'</td>
3756: <td>'.$udom.'</td>
1.53 raeburn 3757: <td valign="top">
3758: <table>
3759: <tr>
3760: <td><b>'.
3761: &mt('Collaborative Tool').'</b></td>
3762: </tr>
3763: <tr>
3764: <td><b>'.&mt('Fixed').'</b></td>
3765: </tr>
3766: <tr>
3767: <td><b>'.&mt('Optional').'</b></td>
3768: </tr>
3769: </table>
3770: </td>');
1.5 raeburn 3771: foreach my $tool (@{$showtools}) {
3772: if (exists($$usertools{$user}{$tool})) {
1.45 albertel 3773: $r->print('<td valign="top"><table><tr><th colspan="2">'.$tool.'</th></tr>');
1.3 raeburn 3774: my $privcount = 0;
3775: my $fixed = '';
3776: my $dynamic = '';
3777: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3778: if (exists($$fixedprivs{$tool}{$priv})) {
1.5 raeburn 3779: $fixed .= '<input type="hidden" name="userpriv_'.$priv.'" value="'.$user.'" />'.$$toolprivs{$tool}{$priv}.' ';
1.3 raeburn 3780: } else {
3781: $privcount ++;
3782: if ($privcount == 3) {
3783: $dynamic .= '</tr><tr>';
3784: }
1.83 bisitz 3785: $dynamic .='<td><span class="LC_nobreak"><label><input type="checkbox" '.
1.5 raeburn 3786: 'name="userpriv_'.$priv.'" value="'.$user.'"';
3787: if (grep/^\Q$priv\E$/,@{$defprivs}) {
3788: $dynamic .= ' checked="checked" ';
3789: }
3790: $dynamic .= ' />'.$$toolprivs{$tool}{$priv}.
1.83 bisitz 3791: '</label></span></td>';
1.3 raeburn 3792: }
3793: }
1.83 bisitz 3794: $r->print('<tr><td colspan="2"><span class="LC_nobreak">'.$fixed.'</span></td></tr><tr>'.$dynamic.'</tr></table></td>');
1.3 raeburn 3795: } else {
1.45 albertel 3796: $r->print('<td valign="top"><table width="100%"><tr><th colspan="2">'.$tool.'</th></tr><tr><td> </td></tr><tr><td> </td></tr></table></td>');
1.3 raeburn 3797: }
3798: }
1.45 albertel 3799: $r->print(&Apache::loncommon::end_data_table_row());
1.3 raeburn 3800: }
3801: }
3802:
3803: sub get_dates_from_form {
3804: my $startdate;
3805: my $enddate;
3806: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
3807: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
3808: if ( exists ($env{'form.no_end_date'}) ) {
3809: $enddate = 0;
3810: }
3811: return ($startdate,$enddate);
1.5 raeburn 3812: }
3813:
1.3 raeburn 3814: sub date_setting_table {
3815: my ($starttime,$endtime,$formname) = @_;
3816: my $startform = &Apache::lonhtmlcommon::date_setter($formname,
3817: 'startdate',$starttime);
3818: my $endform = &Apache::lonhtmlcommon::date_setter($formname,
3819: 'enddate',$endtime);
1.98 bisitz 3820: my $perpetual = ' <span class="LC_nobreak"><label>'
3821: .'<input type="checkbox" name="no_end_date" />'
3822: .&mt('No end date')
3823: .'</label></span>';
3824: my $table = &Apache::lonhtmlcommon::start_pick_box()
3825: .&Apache::lonhtmlcommon::row_title(&mt('Start Date'))
3826: .$startform
3827: .&Apache::lonhtmlcommon::row_closure()
3828: .&Apache::lonhtmlcommon::row_title(&mt('End Date'))
3829: .$endform
3830: .$perpetual
3831: .&Apache::lonhtmlcommon::row_closure(1)
3832: .&Apache::lonhtmlcommon::end_pick_box();
1.41 albertel 3833: return $table;
1.1 raeburn 3834: }
3835:
1.32 raeburn 3836: sub add_group_folder {
3837: my ($cdom,$cnum,$now,$groupname,$action,$description,$tools,$groupinfo,
3838: $gpterm,$ucgpterm,$crstype) = @_;
3839: if ($cdom eq '' || $cnum eq '') {
1.104 raeburn 3840: my $error = '<span class="LC_error">';
3841: if ($crstype eq 'Community') {
3842: $error .= &mt("Error: invalid community domain or number - group folder creation failed.");
3843: } else {
3844: $error .= &mt("Error: invalid course domain or number - group folder creation failed.");
3845: }
3846: $error .= '</span>';
3847: return $error;
1.32 raeburn 3848: }
1.67 raeburn 3849: my ($outcome,$allgrpsmap,$grpmap,$boardsmap,$grppage,$warning);
1.32 raeburn 3850: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
1.47 raeburn 3851: $allgrpsmap = $crspath.'group_allfolders.sequence';
1.32 raeburn 3852: if ($action eq 'create') {
1.67 raeburn 3853: if (&get_folder_lock($cdom,$cnum,'group_allfolders',$now) eq 'ok') {
3854: # check if group_allfolders.sequence exists.
1.69 raeburn 3855: my $mapcontents = &Apache::lonnet::getfile($allgrpsmap);
3856: if ($mapcontents eq '-1') { #file does not exist;
1.80 bisitz 3857: my $grpstitle = &mt("$crstype $ucgpterm".'s');
1.67 raeburn 3858: my $topmap_url = '/'.$env{'course.'.$env{'request.course.id'}.'.url'};
3859: $topmap_url =~ s|/+|/|g;
3860: if ($topmap_url =~ m|^/uploaded|) {
3861: $outcome = &map_updater($cdom,$cnum,'group_allfolders.sequence',
3862: 'toplevelgroup',$grpstitle,$topmap_url);
3863: } else {
1.80 bisitz 3864: $outcome = '<span class="LC_warning">'
3865: .&mt('Non-standard course - folder for all groups not added.')
3866: .'</span>';
1.67 raeburn 3867: }
1.32 raeburn 3868: if ($outcome ne 'ok') {
1.67 raeburn 3869: my $delresult = &release_folder_lock($cdom,$cnum,'group_allfolders');
3870: if ($delresult ne 'ok') {
3871: $warning = $delresult;
3872: }
1.84 raeburn 3873: return $outcome.$warning;
1.32 raeburn 3874: }
3875: }
1.67 raeburn 3876: my $delresult = &release_folder_lock($cdom,$cnum,'group_allfolders');
3877: if ($delresult ne 'ok') {
3878: $warning = $delresult ;
3879: }
3880: } else {
1.80 bisitz 3881: $outcome = '<span class="LC_error">'
3882: .&mt('Could not obtain exclusive lock to check status of the folder for all groups. No group folder added.')
1.84 raeburn 3883: .'</span>';
1.67 raeburn 3884: return $outcome;
1.32 raeburn 3885: }
1.75 bisitz 3886: my $grpfolder = &mt($ucgpterm.' Folder - [_1]',$description);
1.49 raeburn 3887: $grppage='/adm/'.$cdom.'/'.$cnum.'/'.$groupname.'/smppg';
1.75 bisitz 3888: my $grptitle = &mt('Group homepage - [_1]',$description);
1.55 raeburn 3889: my ($discussions,$disctitle);
1.47 raeburn 3890: my $outcome = &map_updater($cdom,$cnum,'group_folder_'.$groupname.'.sequence',
1.32 raeburn 3891: 'grpseq',$grpfolder,$allgrpsmap,$grppage,
3892: $grptitle);
3893: if ($outcome ne 'ok') {
1.67 raeburn 3894: return $outcome.$warning;
1.32 raeburn 3895: }
3896: my $pageout = &create_homepage($cdom,$cnum,$groupname,$groupinfo,
3897: $tools,$gpterm,$ucgpterm,$now);
3898: # Link to folder for bulletin boards
1.47 raeburn 3899: $grpmap = $crspath.'group_folder_'.$groupname.'.sequence';
1.32 raeburn 3900: if (grep/^discussion$/,@{$tools}) {
3901: $disctitle = &mt('Discussion Boards');
1.47 raeburn 3902: my $outcome = &map_updater($cdom,$cnum,'group_boards_'.$groupname.
1.32 raeburn 3903: '.sequence','bbseq',$disctitle,$grpmap);
3904: if ($outcome ne 'ok') {
1.67 raeburn 3905: return $outcome.$warning;
1.32 raeburn 3906: }
1.47 raeburn 3907: $boardsmap = $crspath.'group_boards_'.$groupname.'.sequence';
1.32 raeburn 3908: }
3909: } else {
3910: #modify group folder if status of discussions tools is changed
3911: }
3912: my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.67 raeburn 3913: my $navmap = Apache::lonnavmaps::navmap->new();
1.85 raeburn 3914: if (!defined($navmap)) {
1.104 raeburn 3915: $warning .= '<span class="LC_error">';
3916: if ($crstype eq 'Community') {
3917: $warning .= &mt("Error retrieving community contents").
3918: ' '.&mt("You need to re-initialize the community.");
3919: } else {
3920: $warning .= &mt("Error retrieving course contents").
3921: ' '.&mt("You need to re-initialize the course.");
3922: }
3923: $warning .= '</span>';
3924: return $warning;
1.85 raeburn 3925: }
1.32 raeburn 3926: # modify parameters
3927: my $parm_result;
3928: if ($action eq 'create') {
3929: if ($grpmap) {
3930: $parm_result .= &parm_setter($navmap,$cdom,$grpmap,$groupname);
3931: }
3932: if ($grppage) {
3933: $parm_result .= &parm_setter($navmap,$cdom,$grppage,$groupname);
3934: }
3935: if ($boardsmap) {
3936: $parm_result .= &parm_setter($navmap,$cdom,$boardsmap,$groupname);
3937: }
3938: }
1.67 raeburn 3939: undef($navmap);
1.32 raeburn 3940: if ($parm_result) {
1.67 raeburn 3941: return $warning.$parm_result;
3942: } else {
3943: return 'ok';
3944: }
3945: }
3946:
3947: sub get_folder_lock {
3948: my ($cdom,$cnum,$folder_name,$now) = @_;
3949: # get lock for folder being edited.
3950: my $lockhash = {
3951: $folder_name."\0".'locked_folder' => $now.':'.$env{'user.name'}.
3952: ':'.$env{'user.domain'},
3953: };
3954: my $tries = 0;
3955: my $gotlock = &Apache::lonnet::newput('coursegroups',$lockhash,$cdom,$cnum);
3956:
3957: while (($gotlock ne 'ok') && $tries <3) {
3958: $tries ++;
1.68 albertel 3959: sleep(1);
1.67 raeburn 3960: $gotlock = &Apache::lonnet::newput('coursegroups',$lockhash,$cdom,$cnum);
3961: }
3962: return $gotlock;
3963: }
3964:
3965: sub release_folder_lock {
3966: my ($cdom,$cnum,$folder_name) = @_;
3967: # remove lock
3968: my @del_lock = ($folder_name."\0".'locked_folder');
3969: my $dellockoutcome=&Apache::lonnet::del('coursegroups',\@del_lock,$cdom,$cnum);
3970: if ($dellockoutcome ne 'ok') {
1.80 bisitz 3971: return ('<div class="LC_error">'
3972: .&mt('Warning: failed to release lock for folder: [_1].','<tt>'.$folder_name.'</tt>')
3973: .'</div>'
3974: );
1.32 raeburn 3975: } else {
3976: return 'ok';
3977: }
3978: }
3979:
3980: sub map_updater {
3981: my ($cdom,$cnum,$newfile,$itemname,$itemtitle,$parentmap,$startsrc,
3982: $starttitle,$endsrc,$endtitle) = @_;
3983: my $outcome;
3984: $env{'form.'.$itemname} = &new_map($startsrc,$starttitle,$endsrc,
3985: $endtitle);
3986: my $newmapurl=&Apache::lonnet::finishuserfileupload($cnum,$cdom,$itemname,
3987: $newfile);
3988: if ($newmapurl !~ m|^/uploaded|) {
1.80 bisitz 3989: $outcome = '<div class="LC_error">'
3990: .&mt('Error uploading new folder.')." ($newfile): $newmapurl"
3991: .'</div>';
1.32 raeburn 3992: return $outcome;
1.67 raeburn 3993: }
1.63 albertel 3994: my ($errtext,$fatal)=&LONCAPA::map::mapread($parentmap);
1.32 raeburn 3995: if ($fatal) {
1.80 bisitz 3996: $outcome = '<div class="LC_error">'
3997: .&mt('Error reading contents of parent folder.')." ($parentmap): $errtext"
3998: .'</div>';
1.32 raeburn 3999: return $outcome;
4000: } else {
1.63 albertel 4001: my $newidx=&LONCAPA::map::getresidx($newmapurl);
4002: $LONCAPA::map::resources[$newidx] = $itemtitle.':'.$newmapurl.
1.32 raeburn 4003: ':false:normal:res';
1.63 albertel 4004: $LONCAPA::map::order[1+$#LONCAPA::map::order]=$newidx;
4005: my ($outtext,$errtext) = &LONCAPA::map::storemap($parentmap,1);
1.67 raeburn 4006: if ($errtext) {
1.80 bisitz 4007: $outcome = '<div class="LC_error">'
4008: .&mt('Error saving updated parent folder.')." ($parentmap): $errtext"
4009: .'</div>';
1.32 raeburn 4010: return $outcome;
4011: }
4012: }
4013: return 'ok';
4014: }
4015:
4016: sub new_map {
4017: my ($startsrc,$starttitle,$endsrc,$endtitle) = @_;
4018: my $newmapstr = '
4019: <map>
4020: <resource id="1" src="'.$startsrc.'" type="start" title="'.$starttitle.'"></resource>
4021: <link from="1" to="2" index="1"></link>
4022: <resource id="2" src="'.$endsrc.'" type="finish" title="'.$endtitle.'"></resource>
4023: </map>
4024: ';
4025: return $newmapstr;
4026: }
4027:
4028: sub parm_setter {
1.104 raeburn 4029: my ($navmap,$cdom,$url,$groupname,$crstype) = @_;
1.85 raeburn 4030: if (!defined($navmap)) {
1.104 raeburn 4031: my $allresults;
4032: if ($crstype eq 'Community') {
4033: $allresults = &mt("Parameters not set for [_1] because the contents of the community could not be retrieved.",$url).' '.
4034: &mt("You need to reinitialize the community.");
4035: } else {
4036: $allresults = &mt("Parameters not set for [_1] because the contents of the course could not be retrieved.",$url).' '.
4037: &mt("You need to reinitialize the course.");
4038:
4039: }
4040: return '<div class="LC_warning">'.$allresults.'</div>';
1.85 raeburn 4041: }
1.32 raeburn 4042: my %hide_settings = (
4043: 'course' => {
4044: 'num' => 13,
4045: 'set' => 'yes',
4046: },
4047: 'group' => {
4048: 'num' => 5,
4049: 'set' => 'no',
4050: 'extra' => $groupname,
4051: },
4052: );
4053: my $res = $navmap->getResourceByUrl($url);
1.104 raeburn 4054: my $allresults;
1.67 raeburn 4055: if ($res) {
4056: my $symb = $res->symb();
4057: foreach my $level (keys(%hide_settings)) {
4058: my $parmresult =
4059: &Apache::lonparmset::storeparm_by_symb($symb,
1.32 raeburn 4060: '0_hiddenresource',
4061: $hide_settings{$level}{'num'},
4062: $hide_settings{$level}{'set'},
4063: 'string_yesno',undef,$cdom,
4064: undef,undef,
4065: $hide_settings{$level}{'extra'});
1.67 raeburn 4066: if ($parmresult) {
4067: $allresults .= $level.': '.$parmresult;
4068: }
1.37 raeburn 4069: }
1.67 raeburn 4070: } else {
1.104 raeburn 4071: $allresults = '<div class="LC_warning">';
4072: if ($crstype eq 'Community') {
4073: $allresults .= &mt("Parameters not set for [_1] because the resource was not recognized as part of the community.",'<tt>'.$url.'</tt>');
4074: } else {
4075: $allresults .= &mt('Parameters not set for [_1] because the resource was not recognized as part of the course.','<tt>'.$url.'</tt>');
4076: }
4077: $allresults .= '</div>';
1.32 raeburn 4078: }
1.37 raeburn 4079: return $allresults;
1.32 raeburn 4080: }
4081:
1.3 raeburn 4082: sub create_homepage {
1.32 raeburn 4083: my ($cdom,$cnum,$name,$groupinfo,$tools,$gpterm,$ucgpterm,$now) = @_;
1.3 raeburn 4084: my $functionality = join(',',@{$tools});
1.24 www 4085: my $content = &unescape($$groupinfo{description});
1.3 raeburn 4086: $content=~s/\s+$//s;
4087: $content=~s/^\s+//s;
4088: $content=~s/\<br\s*\/*\>$//s;
4089: $content=&Apache::lonfeedback::clear_out_html($content,1);
4090:
4091: my %pageinfo = (
1.29 raeburn 4092: 'aaa_title' => "$ucgpterm: $name",
1.3 raeburn 4093: 'abb_links' => $functionality,
4094: 'bbb_content' => $content,
4095: 'ccc_webreferences' => '',
1.32 raeburn 4096: 'uploaded.lastmodified' => $now,
1.3 raeburn 4097: );
4098: my $putresult = &Apache::lonnet::put('grppage_'.$name,\%pageinfo,$cdom,$cnum);
4099: return $putresult;
1.1 raeburn 4100: }
4101:
1.5 raeburn 4102: sub check_uncheck_tools {
4103: my ($r,$available) = @_;
4104: if (ref($available) eq 'ARRAY') {
4105: $r->print('
4106: <script type="text/javascript">
4107: function checkAllTools(formname) {
4108: ');
4109: foreach my $tool (@{$available}) {
4110: $r->print(' checkAll(formname.user_'.$tool.');'."\n");
4111: }
4112: $r->print(' checkAll(formname.togglefunc);'."\n");
4113: $r->print('
4114: }
4115: function uncheckAllTools(formname) {
4116: ');
4117: foreach my $tool (@{$available}) {
4118: $r->print(' uncheckAll(formname.user_'.$tool.');'."\n");
4119: }
4120: $r->print(' uncheckAll(formname.togglefunc);'."\n");
4121: $r->print('
4122: }
4123: function toggleTools(field,caller) {
4124: if (caller.checked) {
4125: checkAll(field);
4126: } else {
4127: uncheckAll(field);
4128: }
4129: return;
4130: }
4131: </script>
4132: ');
4133: }
4134: return;
4135: }
4136:
4137: sub validate_groupname {
1.29 raeburn 4138: my ($groupname,$action,$cdom,$cnum,$gpterm,$ucgpterm,$crstype) = @_;
1.16 albertel 4139: my %sectioncount = &Apache::loncommon::get_sections($cdom,$cnum);
1.17 raeburn 4140: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.65 raeburn 4141: my %deleted_groups = &Apache::longroup::coursegroups($cdom,$cnum,undef,
4142: 'deleted_groups');
1.64 raeburn 4143: if (my $tmp = &Apache::lonnet::error(%deleted_groups)) {
4144: undef(%deleted_groups);
4145: &Apache::lonnet::logthis('Error retrieving groups: '.$tmp.' in '.$cnum.':'.$cdom);
4146: }
1.5 raeburn 4147: my %lt = &Apache::lonlocal::texthash (
1.29 raeburn 4148: igna => "Invalid $gpterm name",
4149: tgne => "The $gpterm name entered ",
4150: grna => "$ucgpterm names and section names used in a ".
4151: "$crstype must be unique.",
4152: isno => "is not a valid name.",
4153: gnmo => "$ucgpterm names may only contain letters, ".
4154: "numbers or underscores.",
4155: cnnb => "can not be used as it is the name of ",
4156: inth => " in this $crstype",
4157: thgr => "- does not correspond to the name of an ".
4158: "existing $gpterm",
1.5 raeburn 4159: );
1.15 albertel 4160:
1.42 albertel 4161: my $exitmsg = '<span class="LC_error">'.$lt{'igna'}.'</span><br /><br />'.
4162: $lt{'tgne'}.' "'.$groupname.'" ';
1.5 raeburn 4163: my $dupmsg = $lt{'grna'};
4164: my $earlyout;
4165: if (($groupname eq '') || ($groupname =~ /\W/)) {
4166: $earlyout = $exitmsg.$lt{'isno'}.'<br />'.$lt{'gnmo'};
4167: return $earlyout;
4168: }
1.16 albertel 4169: if (exists($sectioncount{$groupname})) {
4170: return $exitmsg.$lt{'cnnb'}.&mt('a section').$lt{'inth'}.
4171: '<br />'.$lt{'grna'};
1.5 raeburn 4172: }
1.64 raeburn 4173: if ($action eq 'create') {
4174: if (exists($curr_groups{$groupname})) {
4175: return $exitmsg.$lt{'cnnb'}.&mt('an existing [_1]',$gpterm).
4176: $lt{'inth'}.'.<br />'.$lt{'grna'};
4177: } elsif (exists($deleted_groups{$groupname})) {
4178: return $exitmsg.$lt{'cnnb'}.&mt('a [_1] which previously existed',$gpterm).
4179: $lt{'inth'}.'.<br />'.$lt{'grna'};
4180: }
1.5 raeburn 4181: } elsif ($action eq 'modify') {
4182: unless(exists($curr_groups{$groupname})) {
1.29 raeburn 4183: $earlyout = &mt('[_1] name:',$ucgpterm).' '.$groupname.$lt{'thgr'}.
4184: $lt{'inth'};
1.5 raeburn 4185: return $earlyout;
4186: }
4187: }
4188: return;
4189: }
4190:
4191: sub check_changes {
4192: my ($member_changes,$memchg) = @_;
4193: my %exclusions;
4194: @{$exclusions{'changefunc'}} = ('expire');
4195: @{$exclusions{'changepriv'}} = ('expire','changefunc');
4196:
4197: foreach my $change (@{$member_changes}) {
1.6 raeburn 4198: if ($change eq 'deletion') {
1.5 raeburn 4199: next;
4200: }
1.6 raeburn 4201: my @checks = ('deletion');
1.5 raeburn 4202: if (exists($exclusions{$change})) {
4203: push(@checks,@{$exclusions{$change}});
4204: }
4205: my @temp = ();
4206: foreach my $item (@{$$memchg{$change}}) {
4207: my $match = 0;
4208: foreach my $check (@checks) {
1.6 raeburn 4209: if (defined($$memchg{$check})) {
4210: if (ref(@{$$memchg{$check}}) eq 'ARRAY') {
4211: if (@{$$memchg{$check}} > 0) {
4212: if (grep/^$item$/,@{$$memchg{$check}}) {
4213: $match = 1;
4214: last;
4215: }
4216: }
1.5 raeburn 4217: }
4218: }
4219: }
4220: if ($match) {
4221: next;
4222: }
4223: push(@temp,$item);
4224: }
4225: @{$$memchg{$change}} = @temp;
4226: }
4227: }
1.3 raeburn 4228:
1.1 raeburn 4229: 1;
1.106 wenzelju 4230:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>