Annotation of loncom/interface/loncoursegroups.pm, revision 1.101.4.2
1.24 www 1: # The LearningOnline Network with CAPA
2: #
1.101.4.2! raeburn 3: # $Id: loncoursegroups.pm,v 1.101.4.1 2010/01/25 22:19:55 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.101.4.2! 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.101.4.2! 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.101.4.2! 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.101.4.2! raeburn 1122: \%stored,$crstype);
1.64 raeburn 1123: } elsif ($state eq 'result') {
1.101.4.2! 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.101.4.2! raeburn 1130: \%stored,$crstype);
1.65 raeburn 1131: } elsif ($state eq 'result') {
1132: &reenable_group($r,$cdom,$cnum,$groupname);
1133: }
1.64 raeburn 1134: }
1135: }
1136:
1137: sub verify_delete {
1.101.4.2! 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.101.4.2! 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.101.4.2! 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.101.4.2! 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.101.4.2! raeburn 1217: $r->print('<div class="LC_error">');
! 1218: if ($crstype eq 'Community') {
! 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.101.4.2! 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.101.4.2! 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.101.4.2! 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.101.4.2! 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.101.4.2! 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.101.4.2! 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.101.4.2! 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.101.4.2! 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.101.4.2! raeburn 1444: $r->print('<div class="LC_error">');
! 1445: if ($crstype eq 'Community') {
! 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,
1608: $gpterm,$ucgpterm);
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.101.4.2! 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.101.4.2! 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.101.4.2! 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.101.4.2! raeburn 1778: 'coro' => 'Course roles',
! 1779: 'cose' => 'Course sections',
1.5 raeburn 1780: );
1.101.4.2! 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: }
! 1789:
1.5 raeburn 1790: my %status_types = (
1791: active => &mt('Currently has access'),
1792: previous => &mt('Previously had access'),
1793: future => &mt('Will have future access'),
1794: );
1.15 albertel 1795:
1.101.4.2! raeburn 1796: my @roles = ('st');
! 1797: if ($crstype eq 'Community') {
! 1798: push(@roles,'co');
! 1799: } else {
! 1800: push(@roles,'cc');
! 1801: }
! 1802: push (@roles,('in','ta','ep','ad','cr'));
1.5 raeburn 1803:
1804: my @sections = keys(%{$sectioncount});
1805:
1.78 raeburn 1806: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$lt{'pipa'}).'
1.101.4.2! raeburn 1807: <b>'.$lt{'gmem'}.'</b><br />');
! 1808:
1.5 raeburn 1809: if ($action eq 'create') {
1.101.4.2! raeburn 1810: $r->print($lt{'picr'}.'<br />'.$lt{'ifno'}.'<br />'.$lt{'asub'});
1.5 raeburn 1811: } else {
1.101.4.2! raeburn 1812: $r->print($lt{'pica'});
1.5 raeburn 1813: }
1814: $r->print('
1815: <br />
1816: <br />
1.40 albertel 1817: <table class="LC_status_selector">
1.3 raeburn 1818: <tr>
1.40 albertel 1819: <th>'.$lt{'acty'}.'</th>
1.53 raeburn 1820: <th>'.$lt{'coro'}.'</th>
1821: <th>'.$lt{'cose'}.'</th>
1822: </tr><tr><td>');
1.3 raeburn 1823: $r->print(&Apache::lonhtmlcommon::status_select_row(\%status_types));
1.40 albertel 1824: $r->print('</td><td>');
1.59 raeburn 1825: $r->print(&Apache::lonhtmlcommon::role_select_row(\@roles,undef,undef,1,$cdom,$cnum));
1.3 raeburn 1826: if (@sections > 0) {
1.5 raeburn 1827: @sections = sort {$a cmp $b} @sections;
1.31 albertel 1828: unshift(@sections,'none'); # Put 'no sections' next
1.17 raeburn 1829: unshift(@sections,'all'); # Put 'all' at the front of the list
1.53 raeburn 1830: } else {
1831: @sections = ('all','none');
1.3 raeburn 1832: }
1.53 raeburn 1833: $r->print('</td><td>'.
1834: §ions_selection(\@sections,'sectionpick').'</td>
1.3 raeburn 1835: </tr>
1.40 albertel 1836: </table>');
1.5 raeburn 1837: return;
1838: }
1839:
1840: sub sections_selection {
1841: my ($sections,$elementname) = @_;
1842: my $section_sel;
1843: my $numvisible = 4;
1844: if (@{$sections} < 4) {
1845: $numvisible = @{$sections};
1846: }
1847: foreach my $sec (@{$sections}) {
1.17 raeburn 1848: if ($sec eq 'all') {
1.53 raeburn 1849: $section_sel .= ' <option value="'.$sec.'">'.&mt('all sections').'</option>'."\n";
1.17 raeburn 1850: } elsif ($sec eq 'none') {
1.31 albertel 1851: $section_sel .= ' <option value="'.$sec.'">'.&mt('no section').'</option>'."\n";
1.5 raeburn 1852: } else {
1.31 albertel 1853: $section_sel .= ' <option value="'.$sec.'">'.$sec."</option>\n";
1.5 raeburn 1854: }
1855: }
1856: my $output = '
1.89 bisitz 1857: <select name="'.$elementname.'" multiple="multiple" size="'.$numvisible.'">
1.5 raeburn 1858: '.$section_sel.'
1859: </select>';
1860: return $output;
1861: }
1862:
1863: sub access_date_settings {
1.41 albertel 1864: my ($r,$action,$formname,$stored,$image,$gpterm,$ucgpterm) = @_;
1.80 bisitz 1865: my $sten = &mt("Default start and end dates for $gpterm access");
1.5 raeburn 1866: my $starttime = time;
1867: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1868: if ($action eq 'modify') {
1869: $starttime = $$stored{'startdate'};
1870: unless ($$stored{'enddate'} == 0) {
1871: $endtime = $$stored{'enddate'};
1872: }
1873: }
1.41 albertel 1874: my ($table) = &date_setting_table($starttime,$endtime,$formname);
1.80 bisitz 1875: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$sten).'
1.41 albertel 1876: '.$table.'
1877: ');
1.3 raeburn 1878: return;
1879: }
1880:
1.5 raeburn 1881: sub choose_members_form {
1.46 albertel 1882: my ($r,$cdom,$cnum,$action,$formname,$page,$groupname,$description,
1.29 raeburn 1883: $granularity,$quota,$startdate,$enddate,$tools,$fixedprivs,$toolprivs,
1.5 raeburn 1884: $functions,$users,$userdata,$idx,$stored,$states,$navbuttons,
1.46 albertel 1885: $gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 1886: my @regexps = ('user_','userpriv_','sec_');
1887: my %origmembers;
1.3 raeburn 1888: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.5 raeburn 1889: ['origin','action','state','page','member','specificity','branch',
1.7 raeburn 1890: 'defpriv','autorole','autoadd','autodrop','sortby','togglefunc'],
1.5 raeburn 1891: \@regexps));
1.29 raeburn 1892: my $earlyout = &validate_groupname($groupname,$action,$cdom,$cnum,$gpterm,
1893: $ucgpterm,$crstype);
1.5 raeburn 1894: if ($earlyout) {
1.47 raeburn 1895: $r->print($earlyout);
1.5 raeburn 1896: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1897: $$navbuttons{'gtps'});
1.3 raeburn 1898: return;
1.5 raeburn 1899: }
1900: my ($specimg,$memimg);
1901: my @available = ();
1902: my @unavailable = ();
1903: &check_tools($functions,$tools,\@available,\@unavailable);
1904: if ($action eq 'create') {
1.40 albertel 1905: &print_current_settings($r,$action,$functions,$startdate,$enddate,
1906: $groupname,$description,$granularity,$quota,
1907: \@available,\@unavailable,$gpterm,$ucgpterm);
1.5 raeburn 1908: $specimg = 4;
1909: $memimg = 5;
1910: } else {
1911: $specimg = 2;
1912: $memimg = 3;
1913: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
1914: $groupname);
1915: foreach my $key (sort(keys(%membership))) {
1916: if ($key =~ /^\Q$groupname\E:([^:]+):([^:]+)$/) {
1.6 raeburn 1917: my ($end,$start,@userprivs) = split(/:/,$membership{$key});
1918: unless ($start == -1) {
1919: my $uname = $1;
1920: my $udom = $2;
1921: my $user = $uname.':'.$udom;
1922: $origmembers{$user} = 1;
1923: }
1.5 raeburn 1924: }
1925: }
1926: }
1.46 albertel 1927: &privilege_specificity($r,$action,$specimg,$tools,$stored,$toolprivs,
1.101.4.1 raeburn 1928: $fixedprivs,\@available,$formname,$gpterm,$ucgpterm,
1.101.4.2! raeburn 1929: $functions,$crstype);
1.44 albertel 1930: my $newusers = &pick_new_members($r,$action,$formname,\@available,$idx,
1931: $stored,$memimg,$users,$userdata,
1932: $granularity,\%origmembers,$gpterm,
1933: $ucgpterm);
1.5 raeburn 1934: if ($newusers || $action eq 'create') {
1935: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1936: $$navbuttons{'gtps'},$$states{$action}[$page+1],
1937: $$navbuttons{'gtns'});
1938: } else {
1939: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1940: $$navbuttons{'gtps'});
1.3 raeburn 1941: }
1.5 raeburn 1942: return;
1943: }
1944:
1945: sub display_navbuttons {
1946: my ($r,$formname,$prev,$prevtext,$next,$nexttext) = @_;
1.42 albertel 1947: $r->print('<div class="LC_navbuttons">');
1.5 raeburn 1948: if ($prev) {
1949: $r->print('
1950: <input type="button" name="previous" value = "'.$prevtext.'"
1951: onclick="javascript:backPage(document.'.$formname.','."'".$prev."'".')"/>
1952: ');
1.64 raeburn 1953: } elsif ($prevtext) {
1954: $r->print('
1955: <input type="button" name="previous" value = "'.$prevtext.'"
1956: onclick="javascript:history.back()"/>
1957: ');
1.5 raeburn 1958: }
1959: if ($next) {
1960: $r->print('
1961: <input type="button" name="next" value="'.$nexttext.'"
1962: onclick="javascript:nextPage(document.'.$formname.','."'".$next."'".')" />');
1963: }
1.42 albertel 1964: $r->print('</div>');
1.5 raeburn 1965: }
1966:
1967: sub check_tools {
1968: my ($functions,$tools,$available,$unavailable) = @_;
1969: foreach my $item (sort(keys(%{$functions}))) {
1970: if (grep/^$item$/,@{$tools}) {
1971: push(@{$available},$item);
1972: } else {
1973: push(@{$unavailable},$item);
1974: }
1975: }
1976: return;
1977: }
1978:
1979: sub print_current_settings {
1.40 albertel 1980: my ($r,$action,$functions,$startdate,$enddate,$groupname,$description,
1981: $granularity,$quota,$available,$unavailable,$gpterm,$ucgpterm) = @_;
1.5 raeburn 1982:
1983: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 1984: grna => 'Group Name',
1985: desc => 'Group Title',
1986: grfn => "Collaborative Tools",
1.5 raeburn 1987: gran => 'Granularity',
1.29 raeburn 1988: quot => 'File quota',
1.5 raeburn 1989: dfac => 'Default access dates',
1.53 raeburn 1990: ygrs => "Your group selections - ",
1991: tfwa => "The following settings will apply to the group:",
1992: difn => 'Different collaborative tools<br />for different members:',
1.80 bisitz 1993: stda => 'Start date:',
1.5 raeburn 1994: enda => 'End date:',
1995: );
1.3 raeburn 1996: my $showstart = &Apache::lonlocal::locallocaltime($startdate);
1.5 raeburn 1997: my $showend;
1998: if ($enddate == 0) {
1999: $showend = &mt('No end date set');
2000: } else {
2001: $showend = &Apache::lonlocal::locallocaltime($enddate);
2002: }
2003: if ($action eq 'create') {
2004: $r->print('
1.42 albertel 2005: <div><span style="font-size: larger">'.$lt{'ygrs'}.'</span>
1.5 raeburn 2006: <br />'.$lt{'tfwa'}.'
1.40 albertel 2007: </div>');
1.5 raeburn 2008: }
1.40 albertel 2009: $r->print(&Apache::loncommon::start_data_table('LC_course_group_status').
2010: &Apache::loncommon::start_data_table_header_row());
2011: $r->print('
2012: <th>'.$lt{'grna'}.'</th>
2013: <th>'.$lt{'desc'}.'</th>
2014: <th>'.$lt{'grfn'}.'</th>
2015: <th>'.$lt{'gran'}.'</th>
2016: <th>'.$lt{'quot'}.'</th>
2017: <th>'.$lt{'dfac'}.'</th>
2018: ');
2019: $r->print(&Apache::loncommon::end_data_table_header_row().
2020: &Apache::loncommon::start_data_table_row('LC_data_table_dense'));
1.3 raeburn 2021: $r->print('
1.40 albertel 2022: <td valign="top">'.$groupname.'</td>
2023: <td valign="top">'.$description.'</td>
1.3 raeburn 2024: <td>
2025: ');
1.99 bisitz 2026:
1.5 raeburn 2027: if (@{$available} > 0) {
1.99 bisitz 2028: $r->print('<b>'.&mt('Available for assignment to members:').'</b>');
2029: $r->print('<ul>');
1.5 raeburn 2030: for (my $i=0; $i<@{$available}; $i++) {
1.99 bisitz 2031: $r->print('<li>'.&mt($$functions{$$available[$i]}).'</li>');
1.3 raeburn 2032: }
1.99 bisitz 2033: $r->print('</ul>');
1.3 raeburn 2034: }
1.99 bisitz 2035:
1.5 raeburn 2036: if (@{$unavailable} > 0) {
1.99 bisitz 2037: $r->print('<b>'.&mt('Unavailable for assignment:').'</b>');
2038: $r->print('<ul>');
2039: for (my $i=0; $i<@{$unavailable}; $i++) {
2040: $r->print('<li>'.&mt($$functions{$$unavailable[$i]}).'</li>');
1.3 raeburn 2041: }
1.99 bisitz 2042: $r->print('</ul>');
1.3 raeburn 2043: }
1.99 bisitz 2044:
1.79 bisitz 2045: my $quota_text=&mt('[_1] Mb',$quota);
1.80 bisitz 2046: my $granu_text=&mt($granularity);
1.3 raeburn 2047: $r->print(<<"END");
2048: </td>
1.80 bisitz 2049: <td valign="top"><b>$lt{'difn'}</b> $granu_text</td>
1.79 bisitz 2050: <td valign="top">$quota_text</td>
1.40 albertel 2051: <td valign="top"><b>$lt{'stda'}</b> $showstart<br />
2052: <b>$lt{'enda'}</b> $showend
1.3 raeburn 2053: </td>
2054: END
1.40 albertel 2055: $r->print(&Apache::loncommon::end_data_table_row().
2056: &Apache::loncommon::end_data_table());
1.5 raeburn 2057: return;
2058: }
2059:
2060: sub pick_new_members {
1.44 albertel 2061: my ($r,$action,$formname,$available,$idx,$stored,$img,$users,$userdata,
2062: $granularity,$origmembers,$gpterm,$ucgpterm) = @_;
1.5 raeburn 2063: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 2064: 'gpme' => "Group membership",
1.5 raeburn 2065: 'addm' => 'Add members',
1.53 raeburn 2066: 'setf' => 'Assign collaborative tools',
2067: 'func' => 'Tools',
2068: 'nome' => 'No members to add at this time, as there are no users '.
2069: 'matching the specified type(s), role(s) and section(s).',
1.29 raeburn 2070: 'nnew' => "There are no users to add as new members, as all users".
1.53 raeburn 2071: " matching the specified type(s), role(s), and ".
2072: "section(s) are already affiliated with this group.",
1.79 bisitz 2073: 'yoma' => "You may need to use the 'modify existing, past or ".
2074: "future members' page if you need to re-enable ".
2075: "or activate access for previous or future members.",
1.5 raeburn 2076: );
2077: my %members;
2078: my $totalusers = 0;
2079: my $newusers = 0;
1.3 raeburn 2080: foreach my $role (keys(%{$users})) {
2081: foreach my $user (keys(%{$$users{$role}})) {
1.5 raeburn 2082: $totalusers ++;
2083: if (ref($origmembers) eq 'HASH') {
2084: if (exists($$origmembers{$user})) {
2085: next;
2086: }
2087: }
1.3 raeburn 2088: unless (defined($members{$user})) {
2089: @{$members{$user}} = @{$$userdata{$user}};
1.5 raeburn 2090: $newusers ++;
1.3 raeburn 2091: }
2092: }
2093: }
2094: if (keys(%members) > 0) {
1.5 raeburn 2095: if (@{$available} > 0 && $granularity eq 'Yes') {
2096: $r->print(&check_uncheck_tools($r,$available));
2097: }
2098: }
1.78 raeburn 2099: $r->print(&Apache::lonhtmlcommon::topic_bar($img,$lt{'gpme'}));
1.5 raeburn 2100: if (keys(%members) > 0) {
2101: $r->print('
1.3 raeburn 2102: <table>
1.5 raeburn 2103: <tr>');
2104: &check_uncheck_buttons($r,$formname,'member',$lt{'addm'});
2105: if (@{$available} > 0 && $granularity eq 'Yes') {
1.48 albertel 2106: $r->print('<td>
1.5 raeburn 2107: <fieldset><legend><b>'.$lt{'setf'}.'</b></legend>
1.83 bisitz 2108: <span class="LC_nobreak">
1.80 bisitz 2109: <input type="button" value="'.&mt('check all').'"
1.5 raeburn 2110: onclick="javascript:checkAllTools(document.'.$formname.')" />
2111:
1.80 bisitz 2112: <input type="button" value="'.&mt('uncheck all').'"
1.3 raeburn 2113: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
1.83 bisitz 2114: </span>
1.48 albertel 2115: </fieldset></td>');
1.3 raeburn 2116: }
2117: $r->print('</tr></table>
2118: ');
1.43 albertel 2119: $r->print(&Apache::loncommon::start_data_table().
2120: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 2121: $r->print('
1.43 albertel 2122: <th>'.&mt('Add?').'</b></td>
2123: <th><a href="javascript:changeSort('."'fullname'".')">'.&mt('Name').'</a></td>
2124: <th><a href="javascript:changeSort('."'username'".')">'.&mt('Username').'</a></td>
2125: <th><a href="javascript:changeSort('."'domain'".')">'.&mt('Domain').'</a></td>
2126: <th><a href="javascript:changeSort('."'id'".')">'.&mt('ID').'</a></td>
2127: <th><a href="javascript:changeSort('."'section'".')">'.&mt('Section').'</a></td>
1.5 raeburn 2128: ');
2129: if (@{$available} > 0) {
1.43 albertel 2130: $r->print('<th>'.$lt{'func'}.'</th>');
1.3 raeburn 2131: }
1.43 albertel 2132: $r->print(&Apache::loncommon::end_data_table_header_row());
1.5 raeburn 2133: if (@{$available} > 0) {
2134: if ($granularity eq 'Yes') {
1.43 albertel 2135: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense LC_data_table_highlight').'
1.35 raeburn 2136: <td colspan="6"> </td>
1.83 bisitz 2137: <td align="center"><span class="LC_nobreak"><b>'.&mt('All:').'</b> ');
1.5 raeburn 2138: foreach my $tool (@{$available}) {
1.7 raeburn 2139: $r->print('<label><input type="checkbox" name="togglefunc" '.
2140: 'onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
2141: ' value="'.$tool.'">'.'<b>'.$tool.'</b></label> ');
1.5 raeburn 2142: }
1.83 bisitz 2143: $r->print('</span></td></tr>');
1.5 raeburn 2144: }
2145: }
1.3 raeburn 2146: my %Sortby = ();
2147: foreach my $user (sort(keys(%members))) {
2148: if ($env{'form.sortby'} eq 'fullname') {
2149: push(@{$Sortby{$members{$user}[$$idx{fullname}]}},$user);
2150: } elsif ($env{'form.sortby'} eq 'username') {
2151: push(@{$Sortby{$members{$user}[$$idx{uname}]}},$user);
2152: } elsif ($env{'form.sortby'} eq 'domain') {
2153: push(@{$Sortby{$members{$user}[$$idx{udom}]}},$user);
2154: } elsif ($env{'form.sortby'} eq 'id') {
2155: push(@{$Sortby{$members{$user}[$$idx{id}]}},$user);
1.31 albertel 2156: } elsif ($env{'form.sortby'} eq 'section') {
2157: push(@{$Sortby{$members{$user}[$$idx{section}]}},$user);
1.3 raeburn 2158: } else {
2159: push(@{$Sortby{$members{$user}[$$idx{fullname}]}},$user);
2160: }
2161: }
2162: foreach my $key (sort(keys(%Sortby))) {
2163: foreach my $user (@{$Sortby{$key}}) {
2164: my $id = $members{$user}[$$idx{id}];
2165: my $fullname = $members{$user}[$$idx{fullname}];
2166: my $udom = $members{$user}[$$idx{udom}];
2167: my $uname = $members{$user}[$$idx{uname}];
1.31 albertel 2168: my $section = $members{$user}[$$idx{section}];
1.43 albertel 2169: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense').
2170: '<td align="right"><input type="checkbox" name="member" value="'.$user.'" /></td>'.
2171: '<td>'.$fullname.'</td>'.
2172: '<td>'.$uname.'</td>'.
2173: '<td>'.$udom.'</td>'.
2174: '<td>'.$id.'</td>'.
2175: '<td>'.$section.'</td>');
1.5 raeburn 2176: if (@{$available} > 0) {
1.83 bisitz 2177: $r->print('<td align="center"><span class="LC_nobreak">'.
1.5 raeburn 2178: ' ');
2179: foreach my $tool (@{$available}) {
2180: if ($granularity eq 'Yes') {
1.3 raeburn 2181: $r->print('<input type="checkbox" name="user_'.
2182: $tool.'" value="'.$user.'" />'.$tool.' ');
2183: } else {
2184: $r->print('<input type="hidden" name="user_'.
2185: $tool.'" value="'.$user.'" />'.$tool.' ');
2186: }
2187: }
1.83 bisitz 2188: $r->print('</span></td>');
1.3 raeburn 2189: }
1.43 albertel 2190: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.3 raeburn 2191: }
2192: }
1.43 albertel 2193: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 2194: } else {
2195: if ($totalusers > 0) {
2196: $r->print($lt{'nnew'}.'<br /><br />'.$lt{'yoma'});
2197: } else {
2198: $r->print($lt{'nome'});
2199: }
2200: }
2201: return $newusers;
2202: }
2203:
2204: sub privilege_specificity {
1.46 albertel 2205: my ($r,$action,$img,$tools,$stored,$toolprivs,$fixedprivs,$available,
1.101.4.2! raeburn 2206: $formname,$gpterm,$ucgpterm,$functions,$crstype) = @_;
1.5 raeburn 2207: my %lt = &Apache::lonlocal::texthash (
1.53 raeburn 2208: 'uprv' => 'User privileges for collaborative tools',
2209: 'frty' => 'For each collaborative tool you have chosen to include, '.
2210: 'there is a set of core privileges which all group members '.
2211: 'assigned use of the tool will receive.',
2212: 'thar' => 'For some tools there are also additional optional '.
2213: 'privileges which can be set.',
2214: 'plch' => 'Choose one of the following:',
2215: 'fort' => 'For the collaborative tools you have chosen to include '.
2216: 'only core privileges are available, '.
2217: 'so there are no optional privileges to assign.',
2218: 'eaty' => 'Each collaborative tool includes core '.
2219: 'privileges assigned to all members with access to the '.
2220: 'tool. Some tools may also feature additional privileges '.
1.5 raeburn 2221: 'which can be set for specific members.',
1.53 raeburn 2222: 'cutg' => 'Currently the group is configured ',
2223: 'sdif' => 'so different members can receive different optional privileges for a particular tool.',
2224: 'sall' => 'so all members will receive the same optional privileges for a particular tool.',
2225: 'algm' => 'All group members will receive the same privileges for any tool assigned to them, including the default set of optional privileges.',
2226: 'smgp' => 'Different group members may receive different privileges from '.
2227: 'others for the tools they have been assigned.',
2228: 'thwi' => 'These will be the privileges all group members receive for a particular assigned tool, '.
2229: 'if you selected the first option above.',
1.29 raeburn 2230: 'thes' => "These will be the privileges given to members assigned ".
1.53 raeburn 2231: "in the future via automatic group assignment ".
2232: "for users who receive specific sections/roles in the course ",
2233: 'asyo' => "As you have chosen not to include any collaborative tools ".
2234: "in the group, no default optional privileges need to be set.",
2235: 'plin' => 'Indicate which <b>optional</b> privileges members '.
2236: 'will receive by default for a specific tool.',
1.5 raeburn 2237: 'oppr' => 'Optional privileges',
2238: 'defp' => 'The default privileges new members will receive are:',
2239: );
1.101.4.2! raeburn 2240: if ($crstype eq 'Community') {
! 2241: $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 ');
! 2242: }
1.5 raeburn 2243: my $totaloptionalprivs = 0;
2244: foreach my $tool (@{$tools}) {
2245: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2246: if (!exists($$fixedprivs{$tool}{$priv})) {
2247: $totaloptionalprivs ++;
2248: }
2249: }
2250: }
1.78 raeburn 2251: $r->print(&Apache::lonhtmlcommon::topic_bar($img,$lt{'uprv'}));
1.5 raeburn 2252: if ((($action eq 'create') && (@{$available} > 0)) ||
1.55 raeburn 2253: (($action eq 'modify') && ($formname eq 'change_settings'))) {
1.5 raeburn 2254: my %specific = (
2255: 'No' => 'checked="checked"',
2256: 'Yes' => '',
2257: );
2258: if ($action eq 'create') {
2259: $r->print($lt{'frty'}.'<br />');
2260: if ($totaloptionalprivs) {
1.53 raeburn 2261: $r->print($lt{'thar'}.'<br /><br />'.$lt{'plch'});
1.5 raeburn 2262: } else {
2263: $r->print($lt{'fort'});
2264: }
2265: } else {
2266: $r->print($lt{'eaty'}.' '.$lt{cutg});
2267: if ($$stored{'specificity'} eq 'Yes') {
2268: $r->print($lt{'sdif'});
2269: $specific{'Yes'} = $specific{'No'};
2270: $specific{'No'} = '';
2271: } else {
2272: $r->print($lt{'sall'});
2273: }
2274: }
2275: if ($totaloptionalprivs) {
2276: $r->print('
1.53 raeburn 2277: <br />
1.83 bisitz 2278: <label><span class="LC_nobreak"><input type="radio" name="specificity" value="No" '.$specific{'No'}.' /> '.$lt{'algm'}.'</span></label><br />
2279: <label><span class="LC_nobreak"><input type="radio" name="specificity" value="Yes" '.$specific{'Yes'}.' /> '.$lt{'smgp'}.'</span></label><br /><br />');
1.5 raeburn 2280: } else {
2281: $r->print('<input type="hidden" name="specificity" value="No" />');
2282: }
2283: if ($totaloptionalprivs) {
1.40 albertel 2284: $r->print($lt{'plin'});
1.5 raeburn 2285: if ($action eq 'create') {
1.53 raeburn 2286: $r->print('<br />'.$lt{'thwi'});
1.5 raeburn 2287: }
2288: $r->print('<br />'.$lt{'thes'});
2289: if ($action eq 'create') {
2290: $r->print('('.&mt('if enabled on the next page').').');
2291: } else {
2292: $r->print('('.&mt('if enabled below').').');
2293: }
2294: $r->print('<br /><br />
1.40 albertel 2295: <table><tr>');
1.5 raeburn 2296: &check_uncheck_buttons($r,$formname,'defpriv',$lt{'oppr'});
2297: $r->print('
2298: </tr>
2299: </table>
1.3 raeburn 2300: <br />
2301: ');
1.5 raeburn 2302: } else {
1.40 albertel 2303: $r->print($lt{'algm'}.'<br /><br />');
1.3 raeburn 2304: }
1.42 albertel 2305: &default_privileges($r,$action,$tools,$toolprivs,$fixedprivs,
1.92 schafran 2306: $available,$functions);
1.3 raeburn 2307: } else {
1.5 raeburn 2308: if ($action eq 'create') {
2309: $r->print($lt{'asyo'});
1.55 raeburn 2310: $r->print('<input type="hidden" name="specificity" value="No" />');
1.5 raeburn 2311: } elsif ($action eq 'modify' && $formname eq 'pick_members') {
2312: my @defprivs;
2313: if (ref($$stored{'defpriv'}) eq 'ARRAY') {
2314: @defprivs = @{$$stored{'defpriv'}};
2315: }
2316: $r->print($lt{'eaty'}.' '.$lt{cutg});
2317: if ($$stored{'specificity'} eq 'Yes') {
2318: $r->print($lt{'sdif'});
2319: } else {
2320: $r->print($lt{'sall'});
2321: }
2322: $r->print(' '.$lt{'defp'}.'<br /><br />');
1.45 albertel 2323: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 2324: }
1.3 raeburn 2325: }
2326: return;
2327: }
2328:
1.5 raeburn 2329: sub default_privileges {
1.92 schafran 2330: my ($r,$action,$tools,$toolprivs,$fixedprivs,$available,$functions) = @_;
1.5 raeburn 2331: my %lt = &Apache::lonlocal::texthash(
2332: 'addp' => 'Additional privileges',
2333: 'fixp' => 'Fixed privileges',
2334: 'oppr' => 'Optional privileges',
1.53 raeburn 2335: 'func' => 'Collaborative Tool',
1.5 raeburn 2336: );
1.42 albertel 2337: $r->print(&Apache::lonhtmlcommon::start_pick_box('LC_group_priv_box').
2338: &Apache::lonhtmlcommon::row_title($lt{'func'},undef,
1.90 schafran 2339: 'LC_groups_functionality'));
1.92 schafran 2340: my @tableHeader;
1.101.4.1 raeburn 2341: if ((ref($functions) eq 'HASH') && (ref($tools) eq 'ARRAY')) {
2342: @tableHeader = map { $functions->{$_}; } @{$tools};
2343: }
1.92 schafran 2344: $r->print(join('</td><td class="LC_groups_functionality">', @tableHeader));
1.42 albertel 2345: $r->print(&Apache::lonhtmlcommon::row_closure(1));
2346: my $fixed = '';
2347: my $dynamic = '';
1.3 raeburn 2348: foreach my $tool (@{$tools}) {
1.5 raeburn 2349: my $privcount = 0;
1.42 albertel 2350: if ($dynamic ne '') {
2351: $dynamic .= '</td><td class="LC_groups_optional">';
2352: }
2353: $dynamic .= '<table class="LC_group_priv"><tr>';
1.5 raeburn 2354: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2355: if (exists($$fixedprivs{$tool}{$priv})) {
1.42 albertel 2356: if ($fixed ne '') {
2357: $fixed .= '</td><td class="LC_groups_fixed">';
2358: }
1.79 bisitz 2359: $fixed .= '<input type="hidden" name="defpriv" value="'.$priv.'" />'
1.90 schafran 2360: .'<span class="LC_nobreak">'.&mt($$toolprivs{$tool}{$priv}).' ';
1.5 raeburn 2361: if ($action eq 'modify') {
1.42 albertel 2362: if (grep(/^$tool$/,@{$available})) {
1.5 raeburn 2363: $fixed .= '<small>'.&mt('(on)').'<small> ';
2364: } else {
2365: $fixed .= '<small>'.&mt('(off)').'<small> ';
1.3 raeburn 2366: }
2367: }
1.79 bisitz 2368: $fixed .= '</span>';
1.5 raeburn 2369: } else {
1.42 albertel 2370: $privcount++;
1.5 raeburn 2371: if ($privcount == 3) {
2372: $dynamic .= '</tr>
1.42 albertel 2373: <tr>'."\n";
1.5 raeburn 2374: }
1.90 schafran 2375: $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 2376: }
2377: }
1.42 albertel 2378: if ($privcount == 0) {
1.79 bisitz 2379: $dynamic .= '<td>'.&mt('None').'</td>'."\n";
1.5 raeburn 2380: }
2381: if ($privcount < 3) {
1.53 raeburn 2382: $dynamic .= '<td> </td>'."\n";
1.5 raeburn 2383: } elsif ($privcount%2) {
2384: $dynamic = '<td> </td>'."\n";
2385: }
1.42 albertel 2386: $dynamic .= '</tr></table>';
1.3 raeburn 2387: }
1.42 albertel 2388: $r->print(&Apache::lonhtmlcommon::row_title($lt{'fixp'},undef,
2389: 'LC_groups_fixed').
2390: $fixed.
2391: &Apache::lonhtmlcommon::row_closure(1));
2392: $r->print(&Apache::lonhtmlcommon::row_title($lt{'oppr'},undef,
2393: 'LC_groups_optional').
2394: $dynamic.
2395: &Apache::lonhtmlcommon::end_pick_box());
1.5 raeburn 2396: $r->print('<br />');
2397: return;
1.42 albertel 2398:
1.5 raeburn 2399: }
2400:
2401: sub display_defprivs {
1.45 albertel 2402: my ($r,$tools,$toolprivs,$defprivs) = @_;
2403: my $function = &Apache::loncommon::get_users_function();
2404: my $tabcol = &Apache::loncommon::designparm($function.'.tabbg');
2405: my $rowColor1 = "#dddddd";
2406: my $rowColor2 = "#eeeeee";
1.5 raeburn 2407: my %lt = &Apache::lonlocal::texthash(
2408: 'priv' => 'Privileges',
1.53 raeburn 2409: 'func' => 'Collaborative Tool',
1.5 raeburn 2410: );
2411: $r->print(&Apache::lonhtmlcommon::start_pick_box());
2412: $r->print('<tr>');
2413: my $numrows = 0;
2414: my %currprivs;
2415: foreach my $tool (@{$tools}) {
2416: @{$currprivs{$tool}} = ();
2417: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2418: if (ref($defprivs) eq 'ARRAY') {
1.45 albertel 2419: if (grep(/^\Q$priv\E$/,@{$defprivs})) {
1.5 raeburn 2420: push(@{$currprivs{$tool}},$priv);
2421: }
1.3 raeburn 2422: }
2423: }
1.5 raeburn 2424: my $rowcount = int(@{$currprivs{$tool}}/3);
2425: if (@{$currprivs{$tool}}%3 > 0) {
2426: $rowcount ++;
2427: }
2428: if ($rowcount > $numrows) {
2429: $numrows = $rowcount;
2430: }
2431: }
2432: my @rowCols = ($rowColor1,$rowColor2);
2433: foreach my $tool (@{$tools}) {
2434: $r->print('<td align="center" valign="top">
2435: <table cellspacing="0" cellpadding="5">
2436: <tr bgcolor="#cccccc">
2437: <td colspan="3" align="center"><b>'.$tool.'</b></td>
2438: </tr>
2439: ');
2440: my $rownum = 1;
2441: my $privcount = 0;
2442: $r->print('<tr bgcolor="'.$rowColor1.'">');
2443: foreach my $priv (@{$currprivs{$tool}}) {
2444: $privcount ++;
2445: if ($privcount%4 == 0) {
2446: $rownum ++;
2447: my $bgcol = $rownum%2;
2448: $r->print('</tr>
2449: <tr bgcolor="'.$rowCols[$bgcol].'">'."\n");
2450: }
2451: $r->print('<td>'.$$toolprivs{$tool}{$priv}.'</td>'."\n");
2452: }
2453: if ($privcount%3 > 0) {
2454: my $emptycells = 3-($privcount%3);
2455: while($emptycells > 0) {
2456: $r->print('<td> </td>'."\n");
2457: $emptycells --;
2458: }
2459: }
2460: while ($rownum < $numrows) {
2461: $rownum ++;
2462: my $bgcol = $rownum%2;
2463: $r->print('<tr bgcolor="'.$rowCols[$bgcol].'"><td colspan="3"> </td></tr>');
1.3 raeburn 2464: }
1.5 raeburn 2465: $r->print('</table>'."\n".'</td>');
2466: }
2467: $r->print('</tr>'."\n");
2468: $r->print(&Apache::lonhtmlcommon::end_pick_box());
2469: $r->print('<br />');
2470: return;
1.3 raeburn 2471: }
1.5 raeburn 2472:
2473:
2474: sub change_members_form {
1.48 albertel 2475: my ($r,$cdom,$cnum,$action,$formname,$page,$groupname,$description,
1.5 raeburn 2476: $startdate,$enddate,$tools,$fixedprivs,$functions,$users,$userdata,
1.48 albertel 2477: $granularity,$quota,$specificity,$idx,$states,$navbuttons,$gpterm,
2478: $ucgpterm) = @_;
1.5 raeburn 2479: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 2480: grse => "$ucgpterm settings",
2481: mogm => "Modify $gpterm membership",
1.5 raeburn 2482: );
2483: my @regexps = ('user_','userpriv_');
2484: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2485: ['origin','action','state','page','expire','deletion',
1.7 raeburn 2486: 'reenable','activate','changepriv','sortby',
2487: 'togglefunc'],\@regexps));
1.5 raeburn 2488: my $rowimg = 1;
2489: my @available = ();
2490: my @unavailable = ();
2491: &check_tools($functions,$tools,\@available,\@unavailable);
2492: my $nexttext = $$navbuttons{'gtns'};
2493: my $prevtext = $$navbuttons{'gtpp'};
2494: $r->print('
1.3 raeburn 2495: <br />
1.5 raeburn 2496: ');
1.78 raeburn 2497: $r->print(&Apache::lonhtmlcommon::topic_bar(1,$lt{'grse'}));
1.40 albertel 2498: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2499: $groupname,$description,$granularity,$quota,
2500: \@available,\@unavailable,$gpterm,$ucgpterm);
1.78 raeburn 2501: $r->print(&Apache::lonhtmlcommon::topic_bar(2,$lt{'mogm'}));
1.53 raeburn 2502: my $numcurrent = ¤t_membership($r,$cdom,$cnum,$formname,$groupname,
2503: \@available,\@unavailable,$fixedprivs,
2504: $granularity,$specificity);
2505: if ($numcurrent > 0) {
2506: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2507: $$states{$action}[$page+1],$nexttext);
2508: } else {
2509: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext);
2510: }
1.5 raeburn 2511: return;
2512: }
2513:
2514: sub current_membership {
1.48 albertel 2515: my ($r,$cdom,$cnum,$formname,$groupname,$available,$unavailable,
2516: $fixedprivs,$granularity,$specificity) = @_;
1.5 raeburn 2517: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
2518: $groupname);
2519: my %lt = &Apache::lonlocal::texthash(
1.6 raeburn 2520: 'actn' => 'Action?',
2521: 'name' => 'Name',
2522: 'usnm' => 'Username',
2523: 'doma' => 'Domain',
2524: 'stda' => 'Start Date',
2525: 'enda' => 'End Date',
1.5 raeburn 2526: 'expi' => 'Expire',
2527: 'reen' => 'Re-enable',
2528: 'acti' => 'Activate',
2529: 'dele' => 'Delete',
1.53 raeburn 2530: 'curf' => 'Current Tool Set',
1.5 raeburn 2531: 'chpr' => 'Change Privileges'
2532: );
1.52 raeburn 2533: my ($current,$num_items,$hastools,$addtools) =
1.36 raeburn 2534: &Apache::longroup::group_memberlist($cdom,$cnum,$groupname,$fixedprivs,
2535: $available);
1.53 raeburn 2536: my $numcurrent = scalar(keys(%{$current}));
2537: if ($numcurrent > 0) {
1.36 raeburn 2538: $r->print('
1.5 raeburn 2539: <table>
2540: <tr>');
1.52 raeburn 2541: if ($num_items->{'active'}) {
1.36 raeburn 2542: &check_uncheck_buttons($r,$formname,'expire',$lt{'expi'});
2543: }
1.52 raeburn 2544: if ($num_items->{'previous'}) {
1.36 raeburn 2545: &check_uncheck_buttons($r,$formname,'reenable',$lt{'reen'});
2546: }
1.52 raeburn 2547: if ($num_items->{'future'}) {
1.36 raeburn 2548: &check_uncheck_buttons($r,$formname,'activate',$lt{'acti'});
2549: }
2550: &check_uncheck_buttons($r,$formname,'deletion',$lt{'dele'});
2551: if (@{$available} > 0) {
2552: if ($specificity eq 'Yes') {
2553: &check_uncheck_buttons($r,$formname,'changepriv',$lt{'chpr'});
1.5 raeburn 2554: }
1.36 raeburn 2555: if ($granularity eq 'Yes') {
2556: $r->print(&check_uncheck_tools($r,$available));
2557: $r->print('
1.5 raeburn 2558: <td>
1.83 bisitz 2559: <span class="LC_nobreak">
1.5 raeburn 2560: <fieldset><legend><b>'.$lt{'curf'}.'</b></legend>
1.80 bisitz 2561: <input type="button" value="'.&mt('check all').'"
1.5 raeburn 2562: onclick="javascript:checkAllTools(document.'.$formname.')" />
2563:
1.80 bisitz 2564: <input type="button" value="'.&mt('uncheck all').'"
1.5 raeburn 2565: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
2566: </fieldset>
1.83 bisitz 2567: </span>
1.5 raeburn 2568: </td>
2569: ');
1.3 raeburn 2570: }
1.36 raeburn 2571: }
2572: $r->print(<<"END");
1.5 raeburn 2573: </tr>
2574: </table>
1.48 albertel 2575: <br />
1.5 raeburn 2576: END
1.48 albertel 2577: $r->print(&Apache::loncommon::start_data_table().
2578: &Apache::loncommon::start_data_table_header_row());
1.36 raeburn 2579: $r->print(<<"END");
1.48 albertel 2580: <th>$lt{'actn'}</th>
2581: <th><a href="javascript:changeSort('fullname')">$lt{'name'}</a></th>
2582: <th><a href="javascript:changeSort('username')">$lt{'usnm'}</a></th>
2583: <th><a href="javascript:changeSort('domain')">$lt{'doma'}</a></th>
2584: <th><a href="javascript:changeSort('id')">ID</a></th>
2585: <th><a href="javascript:changeSort('start')">$lt{'stda'}</a></th>
2586: <th><a href="javascript:changeSort('end')">$lt{'enda'}</a></th>
1.5 raeburn 2587: END
1.36 raeburn 2588: my $colspan = 0;
2589: if ($hastools) {
1.48 albertel 2590: $r->print('<th>'.$lt{'curf'}.'</th>');
2591: $colspan++;
1.36 raeburn 2592: }
2593: if ($addtools) {
1.53 raeburn 2594: $r->print('<th>'.&mt('Additional Tools').'</th>');
1.48 albertel 2595: $colspan++;
1.36 raeburn 2596: }
1.48 albertel 2597: $r->print(&Apache::loncommon::end_data_table_header_row());
1.36 raeburn 2598: if ($colspan) {
2599: if ($granularity eq 'Yes') {
1.48 albertel 2600: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense LC_data_table_highlight').'
1.6 raeburn 2601: <td colspan="7"> </td>
1.83 bisitz 2602: <td colspan="'.$colspan.'" align="center"><span class="LC_nobreak"><b>'.&mt('All:').
1.6 raeburn 2603: '</b> ');
1.36 raeburn 2604: foreach my $tool (@{$available}) {
2605: $r->print('<label><input type="checkbox" name="togglefunc"'.
1.7 raeburn 2606: ' onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
1.48 albertel 2607: ' value="'.$tool.'" />'.'<b>'.$tool.'</b></label> ');
1.6 raeburn 2608: }
1.83 bisitz 2609: $r->print('</span></td></tr>');
1.6 raeburn 2610: }
1.36 raeburn 2611: }
2612: my %Sortby = ();
2613: foreach my $user (sort(keys(%{$current}))) {
2614: if ($env{'form.sortby'} eq 'fullname') {
2615: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2616: } elsif ($env{'form.sortby'} eq 'username') {
2617: push(@{$Sortby{$$current{$user}{uname}}},$user);
2618: } elsif ($env{'form.sortby'} eq 'domain') {
2619: push(@{$Sortby{$$current{$user}{udom}}},$user);
2620: } elsif ($env{'form.sortby'} eq 'id') {
2621: push(@{$Sortby{$$current{$user}{id}}},$user);
2622: } else {
2623: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2624: }
2625: }
2626: foreach my $key (sort(keys(%Sortby))) {
2627: foreach my $user (@{$Sortby{$key}}) {
2628: my $id = $$current{$user}{id};
2629: my $fullname = $$current{$user}{fullname};
2630: my $udom = $$current{$user}{udom};
2631: my $uname = $$current{$user}{uname};
2632: my $start = $$current{$user}{start};
2633: my $end = $$current{$user}{end};
1.48 albertel 2634: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense').'
2635: <td>');
1.36 raeburn 2636: if ($$current{$user}{changestate} eq 'reenable') {
1.83 bisitz 2637: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2638: '<input type="checkbox" name="reenable" value="'.$user.'" />'.
1.83 bisitz 2639: $lt{'reen'}.'</label></span><br />');
1.36 raeburn 2640: } elsif ($$current{$user}{changestate} eq 'expire') {
1.83 bisitz 2641: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2642: '<input type="checkbox" name="expire" value="'.$user.'" />'.
1.83 bisitz 2643: $lt{'expi'}.'</label></span><br />');
1.36 raeburn 2644: } elsif ($$current{$user}{changestate} eq 'activate') {
1.83 bisitz 2645: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2646: '<input type="checkbox" name="activate" value="'.$user.'" />'.
1.83 bisitz 2647: $lt{'acti'}.'</label></span><br />');
1.36 raeburn 2648: }
1.83 bisitz 2649: $r->print('<span class="LC_nobreak"><label>'.
1.6 raeburn 2650: '<input type="checkbox" name="deletion" value="'.$user.'" />'.
1.83 bisitz 2651: $lt{'dele'}.'</label></span>');
1.36 raeburn 2652: if ($specificity eq 'Yes') {
1.83 bisitz 2653: $r->print('<br /><span class="LC_nobreak"><label>'.
1.5 raeburn 2654: '<input type="checkbox" name="changepriv" value="'.$user.'" />'.$lt{'chpr'}.
1.83 bisitz 2655: '</label></span>');
1.36 raeburn 2656: }
2657: $r->print('
1.48 albertel 2658: </td>'.
2659: '<td>'.$fullname.'</td>'.
2660: '<td>'.$uname.'</td>'.
2661: '<td>'. $udom.'</td>'.
2662: '<td>'.$id.'</td>'.
2663: '<td>'.$start.'</td>'.
2664: '<td>'.$end.'</td>');
1.36 raeburn 2665: if ($hastools) {
1.83 bisitz 2666: $r->print('<td align="left"><span class="LC_nobreak">'.
1.6 raeburn 2667: ' ');
1.36 raeburn 2668: foreach my $tool (@{$$current{$user}{currtools}}) {
2669: if ($granularity eq 'Yes') {
2670: $r->print('<label><input type="checkbox" '.
1.7 raeburn 2671: 'checked="checked" '.
2672: 'name="user_'.$tool.'" value="'.
2673: $user.'" />'.$tool.'</label>');
1.36 raeburn 2674: } else {
2675: $r->print('<input type="hidden" '.
1.7 raeburn 2676: 'checked="checked" '.
2677: 'name="user_'.$tool.'" value="'.
2678: $user.'" />'.$tool);
1.36 raeburn 2679: }
2680: $r->print(' ');
1.5 raeburn 2681: }
1.83 bisitz 2682: $r->print('</span></td>');
1.36 raeburn 2683: }
2684: if ($addtools) {
1.48 albertel 2685: $r->print('<td align="left">');
1.36 raeburn 2686: if ($granularity eq 'Yes') {
2687: foreach my $tool (@{$$current{$user}{newtools}}) {
1.83 bisitz 2688: $r->print('<span class="LC_nobreak"><label><input type="checkbox"
1.5 raeburn 2689: name="user_'.$tool.'" value="'.
2690: $user.'" />'.$tool.
1.83 bisitz 2691: '</label></span> ');
1.36 raeburn 2692: }
2693: } else {
2694: foreach my $tool (@{$$current{$user}{newtools}}) {
1.83 bisitz 2695: $r->print('<span class="LC_nobreak"><input type="hidden"
1.5 raeburn 2696: name="user_'. $tool.'" value="'.
2697: $user.'" />'.$tool.
1.83 bisitz 2698: '</span> ');
1.5 raeburn 2699: }
2700: }
1.48 albertel 2701: $r->print('</td>');
1.5 raeburn 2702: }
1.48 albertel 2703: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.5 raeburn 2704: }
1.36 raeburn 2705: }
1.48 albertel 2706: $r->print(&Apache::loncommon::end_data_table());
1.53 raeburn 2707: } else {
2708: $r->print(&mt('There are no active, future or previous group members to modify.'));
1.5 raeburn 2709: }
1.53 raeburn 2710: return $numcurrent;
1.5 raeburn 2711: }
2712:
2713: sub check_uncheck_buttons {
2714: my ($r,$formname,$field,$title,$colspan) = @_;
2715: $r->print('
2716: <td '.$colspan.'>
2717: <fieldset>
2718: <legend><b>'.$title.'</b></legend>
1.83 bisitz 2719: <span class="LC_nobreak">
1.80 bisitz 2720: <input type="button" value="'.&mt('check all').'"
1.5 raeburn 2721: onclick="javascript:checkAll(document.'.$formname.'.'.$field.')" />
2722:
1.80 bisitz 2723: <input type="button" value="'.&mt('uncheck all').'"
1.5 raeburn 2724: onclick="javascript:uncheckAll(document.'.$formname.'.'.$field.')" />
1.83 bisitz 2725: </span>
1.5 raeburn 2726: </fieldset>
2727: </td>
2728: ');
2729: }
2730:
2731:
2732: sub change_privs_form {
1.45 albertel 2733: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,
2734: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,
2735: $memchg,$idx,$states,$stored,$sectioncount,$navbuttons,$gpterm,
2736: $ucgpterm) = @_;
1.5 raeburn 2737: my @regexps = ('userpriv_');
2738: my $nexttext;
1.6 raeburn 2739: my %lt = &Apache::lonlocal::texthash(
2740: 'tode' => 'To be deleted',
2741: 'toex' => 'To be expired',
1.29 raeburn 2742: 'nome' => "No members to be deleted or expired from the $gpterm.",
1.6 raeburn 2743: );
1.5 raeburn 2744: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2745: ['origin','action','state','page','sortby'],\@regexps));
2746: if ($env{'form.branch'} eq 'adds') {
2747: $nexttext = $$navbuttons{'adme'};
2748: } else {
2749: $nexttext = $$navbuttons{'mose'};
2750: }
1.78 raeburn 2751: $r->print(&Apache::lonhtmlcommon::topic_bar(3,&mt('Members to delete or expire')));
1.6 raeburn 2752: my $exp_or_del = 0;
2753: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2754: if (@{$$memchg{'deletion'}} > 0) {
1.50 albertel 2755: $r->print('<b>'.$lt{'tode'}.':</b><br /><ul>');
1.6 raeburn 2756: foreach my $user (@{$$memchg{'deletion'}}) {
2757: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2758: ' ('.$user.')</li>');
2759: }
1.45 albertel 2760: $r->print('</ul>');
1.6 raeburn 2761: $exp_or_del += @{$$memchg{'deletion'}};
2762: }
2763: }
2764: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2765: if (@{$$memchg{'expire'}} > 0) {
1.50 albertel 2766: $r->print('<b>'.$lt{'toex'}.':</b><br /><ul>');
1.6 raeburn 2767: foreach my $user (@{$$memchg{'expire'}}) {
2768: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2769: ' ('.$user.')</li>');
2770: }
1.45 albertel 2771: $r->print('</ul>');
1.6 raeburn 2772: $exp_or_del += @{$$memchg{'expire'}};
2773: }
2774: }
2775: if (!$exp_or_del) {
1.45 albertel 2776: $r->print($lt{'nome'}.'<br />');
1.6 raeburn 2777: }
1.5 raeburn 2778:
1.78 raeburn 2779: $r->print(&Apache::lonhtmlcommon::topic_bar(4,&mt('Setting optional privileges for specific group members')));
1.6 raeburn 2780:
1.45 albertel 2781: my $numchgs = &member_privileges_form($r,$action,$formname,$tools,
1.6 raeburn 2782: $toolprivs,$fixedprivs,$userdata,
2783: $usertools,$idx,$memchg,$states,
1.45 albertel 2784: $stored,$gpterm);
1.5 raeburn 2785: my $prevtext = $$navbuttons{'gtps'};
1.6 raeburn 2786: if ($numchgs || $exp_or_del) {
2787: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2788: $$states{$action}[$page+1],$nexttext);
2789: } else {
2790: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext);
2791: }
1.5 raeburn 2792: return;
2793: }
2794:
2795: sub add_members_form {
1.59 raeburn 2796: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,$groupname,
1.29 raeburn 2797: $description,$granularity,$quota,$sectioncount,$tools,$functions,
1.101.4.2! raeburn 2798: $stored,$states,$navbuttons,$gpterm,$ucgpterm,$crstype)=@_;
1.40 albertel 2799: $r->print(' <br />');
1.5 raeburn 2800: my @available = ();
2801: my @unavailable = ();
2802: &check_tools($functions,$tools,\@available,\@unavailable);
1.40 albertel 2803: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2804: $groupname,$description,$granularity,$quota,
2805: \@available,\@unavailable,$gpterm,$ucgpterm);
1.59 raeburn 2806: &membership_options($r,$cdom,$cnum,$action,$formname,$sectioncount,1,$gpterm,
1.101.4.2! raeburn 2807: $ucgpterm,$crstype);
1.5 raeburn 2808: my $nexttext = $$navbuttons{'gtns'};
2809: my $prevtext = $$navbuttons{'gtpp'};
2810: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2811: $$states{$action}[$page+1],$nexttext);
2812: return;
2813: }
2814:
2815: sub choose_privs_form {
1.45 albertel 2816: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,
2817: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,$idx,
2818: $states,$stored,$sectioncount,$navbuttons,$gpterm,$ucgpterm,
2819: $crstype) = @_;
1.5 raeburn 2820:
2821: my @regexps = ('userpriv_');
2822: my $nexttext;
2823:
2824: if ($action eq 'create') {
2825: push(@regexps,'sec_');
2826: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2827: ['origin','action','state','page','sortby','autoadd','autodrop'],
1.5 raeburn 2828: \@regexps));
2829: $nexttext = $$navbuttons{'crgr'};
2830: } else {
2831: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2832: ['origin','action','state','page','sortby'],\@regexps));
1.5 raeburn 2833: $nexttext = $$navbuttons{'adme'};
2834: }
2835:
1.78 raeburn 2836: $r->print(&Apache::lonhtmlcommon::topic_bar(6,&mt('Setting optional privileges for specific group members')));
1.5 raeburn 2837:
1.45 albertel 2838: &member_privileges_form($r,$action,$formname,$tools,$toolprivs,
1.5 raeburn 2839: $fixedprivs,$userdata,$usertools,$idx,undef,
1.45 albertel 2840: $states,$stored,$gpterm);
1.5 raeburn 2841:
2842: if ($action eq 'create') {
1.53 raeburn 2843: my $img1 = 7;
2844: my $img2 = 8;
2845: &mapping_options($r,$action,$formname,$page,$sectioncount,
2846: $states,$stored,$navbuttons,$img1,$img2,
1.58 raeburn 2847: $gpterm,$ucgpterm,$crstype,$cdom,$cnum);
1.5 raeburn 2848: }
2849: my $prevtext = $$navbuttons{'gtps'};
2850: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2851: $$states{$action}[$page+1],$nexttext);
2852: return;
2853: }
2854:
2855: sub build_boxes {
2856: my ($r,$tools,$usertools,$fixedprivs,$toolprivs,$showtools,
1.6 raeburn 2857: $showboxes,$prefix,$specificity,$excluded) = @_;
1.5 raeburn 2858: my $totalboxes = 0;
2859: if (@{$tools} > 0) {
2860: if ($specificity eq 'Yes') {
2861: foreach my $tool (@{$tools}) {
2862: @{$$showboxes{$tool}} = ();
2863: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 2864: if (ref($excluded) eq 'ARRAY') {
2865: if (grep/^$user$/,@{$excluded}) {
2866: next;
2867: }
1.5 raeburn 2868: }
1.6 raeburn 2869: if ($$usertools{$user}{$tool}) {
2870: unless (grep/^$tool$/,@{$showtools}) {
2871: push(@{$showtools},$tool);
2872: }
2873: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2874: unless (exists($$fixedprivs{$tool}{$priv})) {
2875: unless(grep(/^$priv$/,@{$$showboxes{$tool}})) {
2876: push(@{$$showboxes{$tool}},$priv);
2877: $totalboxes ++;
2878: }
1.5 raeburn 2879: }
2880: }
2881: }
2882: }
2883: }
2884: if ($totalboxes > 0) {
2885: $r->print('
2886: <script type="text/javascript">
2887: function checkAllTools(formname) {
2888: ');
2889: foreach my $tool (sort(keys(%{$showboxes}))) {
2890: foreach my $priv (@{$$showboxes{$tool}}) {
2891: $r->print(' checkAll(formname.'.$prefix.$priv.');'."\n");
2892: }
2893: }
2894: $r->print('
2895: }
2896: function uncheckAllTools(formname) {
2897: ');
2898: foreach my $tool (sort(keys(%{$showboxes}))) {
2899: foreach my $priv (@{$$showboxes{$tool}}) {
2900: $r->print(' uncheckAll(formname'.$prefix.$priv.');'."\n");
2901: }
2902: }
2903: $r->print('
2904: }
2905: </script>
2906: ');
2907: }
2908: }
2909: }
2910: return $totalboxes;
2911: }
2912:
2913: sub member_privileges_form {
1.45 albertel 2914: my ($r,$action,$formname,$tools,$toolprivs,$fixedprivs,$userdata,
2915: $usertools,$idx,$memchg,$states,$stored,$gpterm) = @_;
1.5 raeburn 2916: my %lt = &Apache::lonlocal::texthash(
2917: 'addp' => 'Additional privileges',
1.53 raeburn 2918: 'fixp' => 'Core privileges',
1.5 raeburn 2919: 'oppr' => 'Optional privileges',
1.53 raeburn 2920: 'func' => 'Tool',
2921: 'forf' => 'For the collaborative tools included for group '.
2922: 'members being added or modified, '.
2923: 'there are no optional privileges to set '.
2924: 'for specific members.',
1.80 bisitz 2925: 'algr' => 'All new group members will receive the same privileges.',
2926: 'ifex' => 'If previously expired members are being re-enabled, or '.
1.54 raeburn 2927: 'if access for future members is being activated now, '.
2928: 'previously set privileges will be preserved.',
1.53 raeburn 2929: 'asno' => 'As no group members are being added, '.
2930: 'there are no specific user privileges to set.',
2931: 'asng' => 'As no group tools will be made available to users, '.
2932: 'there are no specific user privileges to set.',
2933: 'nogm' => 'No group member privileges to display or set, '.
2934: 'as you have not indicated that you will be activating,'.
2935: ' re-enabling, changing privileges, or adding/removing '.
2936: 'tools for any current members.',
1.5 raeburn 2937: 'full' => 'Fullname',
2938: 'user' => 'Username',
2939: 'doma' => 'Domain',
2940: );
2941: my @defprivs;
2942: my $specificity;
2943: if ($action eq 'create') {
2944: if (defined($env{'form.defpriv'})) {
2945: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
2946: }
2947: $specificity = $env{'form.specificity'};
2948: } else {
1.17 raeburn 2949: if (defined($$stored{'defpriv'})) {
2950: @defprivs = @{$$stored{'defpriv'}};
2951: }
1.5 raeburn 2952: $specificity = $$stored{'specificity'};
2953: }
2954: my @showtools;
2955: my %showboxes = ();
2956: my $numtools = 1 + @{$tools};
1.3 raeburn 2957:
1.6 raeburn 2958: my @excluded = ();
2959: my $numchgs = 0;
2960: if ($formname eq 'change_privs') {
2961: my @currmembers = ();
2962: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2963: push(@excluded,@{$$memchg{'deletion'}});
2964: }
2965: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2966: push(@excluded,@{$$memchg{'expire'}});
2967: }
2968: if (@excluded > 0) {
2969: foreach my $user (sort(keys(%{$usertools}))) {
2970: if (grep/^$user$/,@excluded) {
2971: next;
2972: }
2973: push(@currmembers,$user);
2974: }
2975: } else {
2976: @currmembers = sort(keys(%{$usertools}));
2977: }
2978: $numchgs = @currmembers;
2979: if (!$numchgs) {
1.45 albertel 2980: $r->print($lt{'nogm'});
1.6 raeburn 2981: return $numchgs;
2982: }
2983: }
2984:
2985: my $totalboxes = &build_boxes($r,$tools,$usertools,$fixedprivs,
2986: $toolprivs,\@showtools,\%showboxes,
2987: 'userpriv_',$specificity,\@excluded);
1.5 raeburn 2988: if (@{$tools} > 0) {
2989: if ($specificity eq 'Yes') {
2990: if ($totalboxes > 0) {
2991: my $numcells = 2;
2992: my $colspan = $numcells + 1;
2993: my %total;
1.6 raeburn 2994: if (keys(%{$usertools}) > 1) {
2995: $r->print('
1.45 albertel 2996: <table border="0" cellspacing="2" cellpadding="2">
1.5 raeburn 2997: <tr>
2998: ');
1.6 raeburn 2999: foreach my $tool (@{$tools}) {
3000: if (@{$showboxes{$tool}} > 0) {
3001: $r->print('<td valign="top">');
1.100 bisitz 3002: $r->print('<fieldset><legend>'.&mt($tool).'</legend>');
3003: $r->print('<table><tr>');
1.6 raeburn 3004: my $privcount = 0;
3005: foreach my $priv (@{$showboxes{$tool}}) {
3006: $privcount ++;
3007: if (($privcount == @{$showboxes{$tool}}) &&
3008: ($privcount > 1)) {
3009: if ($privcount%$numcells) {
3010: $r->print('<td colspan="'.$colspan.'">');
3011: } else {
3012: $r->print('<td>');
3013: }
1.5 raeburn 3014: } else {
3015: $r->print('<td>');
3016: }
1.80 bisitz 3017: $r->print(
3018: '<fieldset><legend><b>'.&mt($$toolprivs{$tool}{$priv}).'</b></legend>'
3019: .'<span class="LC_nobreak">'
3020: .' <input type="button" value="'.&mt('check all').'"'
3021: .' onclick="javascript:checkAll(document.'.$formname.'.userpriv_'.$priv.')" />'
3022: .' '
3023: .'<input type="button" value="'.&mt('uncheck all').'"'
3024: .' onclick="javascript:uncheckAll(document.'.$formname.'.userpriv_'.$priv.')" />'
3025: .'</span></fieldset><br />'
3026: );
1.6 raeburn 3027: $r->print('</td>');
3028: if ($privcount < @{$showboxes{$tool}}) {
3029: if (@{$showboxes{$tool}} > 2) {
3030: if ($privcount%$numcells == 0) {
3031: $r->print('</tr><tr>');
3032: }
3033: } else {
3034: $r->print('<tr></tr>');
1.5 raeburn 3035: }
3036: }
3037: }
1.100 bisitz 3038: $r->print('</tr></table></fieldset></td><td> </td>');
1.5 raeburn 3039: }
3040: }
1.45 albertel 3041: $r->print('</tr></table>');
1.5 raeburn 3042: }
1.45 albertel 3043: $r->print(&Apache::loncommon::start_data_table().
3044: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 3045: $r->print(<<"END");
1.45 albertel 3046: <th>$lt{'full'}</th>
3047: <th>$lt{'user'}</th>
1.5 raeburn 3048: <th>$lt{'doma'}</th>
3049: <th colspan="$numtools">$lt{'addp'}</th>
3050: END
1.45 albertel 3051: $r->print(&Apache::loncommon::end_data_table_header_row());
3052: &member_privs_entries($r,$usertools,$toolprivs,$fixedprivs,
1.6 raeburn 3053: $userdata,$idx,\@showtools,\@defprivs,
3054: \@excluded);
1.45 albertel 3055: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 3056: } else {
1.43 albertel 3057: $r->print($lt{'forf'}.'<br />');
1.45 albertel 3058: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 3059: }
3060: } else {
3061: if (keys(%{$usertools}) > 0) {
1.54 raeburn 3062: $r->print($lt{'algr'}.'<br />'.$lt{'ifex'}.'<br /><br />');
1.45 albertel 3063: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 3064: } else {
1.43 albertel 3065: $r->print($lt{'asno'}.'<br />');
1.5 raeburn 3066: }
3067: }
3068: } else {
1.43 albertel 3069: $r->print($lt{'asng'});
1.5 raeburn 3070: }
1.6 raeburn 3071: return $numchgs;
1.1 raeburn 3072: }
3073:
1.5 raeburn 3074: sub process_request {
1.45 albertel 3075: my ($r,$cdom,$cnum,$action,$state,$page,$groupname,$description,
1.5 raeburn 3076: $specificity,$userdata,$startdate,$enddate,$tools,$functions,$toolprivs,
3077: $usertools,$idx,$types,$roles,$sections,$states,$navbuttons,$memchg,
1.45 albertel 3078: $sectioncount,$stored,$gpterm,$ucgpterm,$crstype) = @_;
1.3 raeburn 3079:
3080: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 3081: ['origin','action','state','page','sortby']));
1.5 raeburn 3082:
1.29 raeburn 3083: my $earlyout = &validate_groupname($groupname,$action,$cdom,$cnum,$gpterm,
3084: $ucgpterm,$crstype);
1.5 raeburn 3085: if ($earlyout) {
3086: $r->print('
3087: <table width="100%" cellpadding="0" cellspacing="0" border="0">
3088: <tr>
3089: <td> </td>
3090: <td colspan="3">
3091: '.$earlyout.'</td></tr>');
3092: &display_navbuttons($r,$state,$$states{$action}[$page-1],
3093: $$navbuttons{'gtps'});
3094: $r->print('</table>');
3095: return;
3096: }
3097:
3098: my @defprivs = ();
3099: if ($action eq 'create' || $state eq 'chgresult') {
3100: if (defined($env{'form.defpriv'})) {
3101: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
3102: }
3103: if ($state eq 'chgresult') {
3104: my @okprivs = ();
3105: foreach my $tool (@{$tools}) {
3106: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3107: push(@okprivs,$priv);
3108: }
3109: }
3110: my @temp = ();
3111: foreach my $defpriv (@defprivs) {
3112: if (grep/^$defpriv$/,@okprivs) {
3113: push(@temp,$defpriv);
3114: }
3115: }
3116: @defprivs = @temp;
3117: }
3118: } else {
1.17 raeburn 3119: if (defined($$stored{'defpriv'})) {
3120: @defprivs = @{$$stored{'defpriv'}};
3121: }
1.5 raeburn 3122: }
3123:
3124: my $outcome;
3125: if ($action eq 'create' || $state eq 'chgresult') {
3126: $outcome = &write_group_data($r,$cdom,$cnum,$action,$state,$groupname,
3127: $description,$startdate,$enddate,
3128: $specificity,$functions,$tools,
3129: $sectioncount,$roles,$types,$sections,
1.29 raeburn 3130: \@defprivs,$stored,$gpterm,$ucgpterm,
3131: $crstype);
1.5 raeburn 3132: }
3133: if (($action eq 'create' && $outcome eq 'ok') || (($action eq 'modify') &&
3134: (($state eq 'memresult') || ($state eq 'addresult')))) {
1.6 raeburn 3135: &process_membership($r,$cdom,$cnum,$action,$state,$groupname,$tools,
3136: $enddate,$startdate,$userdata,$idx,$toolprivs,
1.29 raeburn 3137: $usertools,$specificity,\@defprivs,$memchg,$gpterm,
1.101.4.2! raeburn 3138: $ucgpterm,$crstype);
1.5 raeburn 3139: }
3140: return;
3141: }
3142:
3143: sub write_group_data {
3144: my ($r,$cdom,$cnum,$action,$state,$groupname,$description,$startdate,
3145: $enddate,$specificity,$functions,$tools,$sectioncount,$roles,$types,
1.29 raeburn 3146: $sections,$defprivs,$stored,$gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 3147: my $now = time;
3148: my $creation = $now;
3149: my $creator = $env{'user.name'}.':'.$env{'user.domain'};
3150: if ($state eq 'chgresult') {
3151: $creation = $$stored{'creation'};
3152: $creator = $$stored{'creator'};
3153: }
1.24 www 3154: my $esc_description = &escape($description);
1.5 raeburn 3155: my @single_attributes = ('description','functions','startdate','enddate',
3156: 'creation','modified','creator','granularity',
1.29 raeburn 3157: 'specificity','autoadd','autodrop','quota');
1.5 raeburn 3158: my @mult_attributes = ('roles','types','sectionpick','defpriv');
1.15 albertel 3159:
1.37 raeburn 3160: my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,
3161: $stored);
3162: my $quota = $env{'form.quota'};
3163:
3164: $quota =~ s/^\s*([^\s]*)\s*$/$1/;
3165: if ($quota eq '') {
3166: $quota = 0;
3167: }
3168: if ($quota !~ /^\d*\.?\d*$/) {
3169: $quota = 0;
1.79 bisitz 3170: $r->print('<div class="LC_warning">'
1.96 weissno 3171: .&mt('The value you entered for the quota for the group portfolio in this '.$gpterm
1.79 bisitz 3172: .' contained invalid characters, so it has been set to 0 Mb. You can change this by'
3173: .' modifying the '.$gpterm.' settings.')
3174: .'</div>');
1.37 raeburn 3175: }
3176: if ($quota > $maxposs) {
3177: $quota = $maxposs;
1.79 bisitz 3178: $r->print('<div class="LC_warning">'
1.96 weissno 3179: .&mt('The value you entered for the quota for the group portfolio in this '.$gpterm
1.79 bisitz 3180: .' exceeded the maximum possible value, so it has been set to [_1] Mb '
3181: .'(the maximum possible value).',sprintf("%.2f",$maxposs))
3182: .'</div>');
1.37 raeburn 3183: }
1.5 raeburn 3184: my %groupinfo = (
3185: description => $esc_description,
3186: startdate => $startdate,
3187: enddate => $enddate,
3188: creation => $creation,
3189: modified => $now,
3190: creator => $creator,
3191: granularity => $env{'form.granularity'},
3192: specificity => $specificity,
3193: autoadd => $env{'form.autoadd'},
3194: autodrop => $env{'form.autodrop'},
1.37 raeburn 3195: quota => $quota,
1.5 raeburn 3196: );
1.37 raeburn 3197:
1.5 raeburn 3198: foreach my $func (keys(%{$functions})) {
3199: my $status;
3200: if (grep(/^$func$/,@{$tools})) {
3201: $status = 'on';
3202: } else {
3203: $status = 'off';
3204: }
3205: $groupinfo{'functions'} .= qq|<name id="$func">$status</name>|;
3206: }
3207:
3208: $groupinfo{'roles'} = $roles;
3209: $groupinfo{'types'} = $types;
3210: $groupinfo{'sectionpick'} = $sections;
3211: $groupinfo{'defpriv'} = $defprivs;
3212:
3213: my %groupsettings = ();
3214: foreach my $item (@single_attributes) {
3215: $groupsettings{$groupname} .= qq|<$item>$groupinfo{$item}</$item>|;
3216: }
3217: foreach my $item (@mult_attributes) {
3218: foreach my $entry (@{$groupinfo{$item}}) {
3219: $groupsettings{$groupname} .= qq|<$item>$entry</$item>|;
3220: }
3221: }
3222: my $autosec;
3223: my @autorole = &Apache::loncommon::get_env_multiple('form.autorole');
1.15 albertel 3224:
1.5 raeburn 3225: foreach my $role (@autorole) {
3226: if (defined($env{'form.sec_'.$role})) {
3227: my @autosections=&Apache::loncommon::get_env_multiple('form.sec_'.
3228: $role);
3229: $autosec .= '<role id="'.$role.'">';
3230: foreach my $sec (@autosections) {
3231: $autosec .= '<section>'.$sec.'</section>';
3232: }
3233: $autosec .= '</role>';
3234: }
3235: }
3236: if ($autosec) {
3237: $groupsettings{$groupname} .= qq|<autosec>$autosec</autosec>|;
3238: }
3239: my $result = &Apache::lonnet::modify_coursegroup($cdom,$cnum,
3240: \%groupsettings);
3241:
3242: if ($result eq 'ok') {
3243: if ($action eq 'create') {
1.32 raeburn 3244: my $result = &add_group_folder($cdom,$cnum,$now,$groupname,$action,
3245: $description,$tools,\%groupinfo,
3246: $gpterm,$ucgpterm,$crstype);
1.79 bisitz 3247: if ($result eq 'ok') {
3248: $r->print('<div class="LC_success">'
3249: .&mt($ucgpterm.' [_1] was created.','<i>'.$groupname.'</i>')
3250: .'</div>');
3251: } else {
3252: $r->print('<div class="LC_error">'
3253: .&mt('A problem occurred when creating folders for the new '.$gpterm.' [_1]:'
3254: ,'<i>'.$groupname.'</i>')
3255: .'<br />'.$result
3256: .'</div>');
1.32 raeburn 3257: }
1.56 raeburn 3258: } elsif ($action eq 'modify') {
3259: my (@oldtools,@newtools);
3260: if (ref($$stored{'tool'}) eq 'ARRAY') {
3261: @oldtools = @{$$stored{'tool'}};
3262: }
3263: if (ref($tools) eq 'ARRAY') {
3264: @newtools = @{$tools};
3265: }
3266: if (!grep(/^discussion$/,@oldtools) &&
3267: grep(/^discussion$/,@newtools)) {
3268: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
3269: my $boardsmap = $crspath.'group_boards_'.$groupname.'.sequence';
3270: my $navmap = Apache::lonnavmaps::navmap->new();
1.85 raeburn 3271: my ($bbmapres,$error);
3272: if (defined($navmap)) {
3273: $bbmapres = $navmap->getResourceByUrl($boardsmap);
3274: undef($navmap);
3275: if (!$bbmapres) {
3276: my $grpmap = $crspath.'group_folder_'.$groupname.'.sequence';
3277: my $disctitle = &mt('Discussion Boards');
3278: my $outcome = &map_updater($cdom,$cnum,'group_boards_'.
3279: $groupname.'.sequence','bbseq',
3280: $disctitle,$grpmap);
3281: my ($furl,$ferr) =
3282: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
3283: # modify parameter
3284: if ($outcome eq 'ok') {
3285: $navmap = Apache::lonnavmaps::navmap->new();
3286: if (defined($navmap)) {
3287: my $parm_result = &parm_setter($navmap,$cdom,$boardsmap,
3288: $groupname);
3289: if ($parm_result) {
3290: $error = &mt('An error occurred while setting parameters '
3291: .'for Discussion Boards folder: '
3292: .'[_1]',$parm_result);
3293: } else {
3294: $r->print('<div class="LC_success">'.
3295: &mt('Discussion Boards Folder created.')
3296: .'</div>');
3297: }
3298: undef($navmap);
3299: } else {
1.101.4.2! raeburn 3300: if ($crstype eq 'Community') {
! 3301: $error = &mt("An error occurred while setting parameters '.
! 3302: 'for Discussion Boards folder: '.
! 3303: 'Could not retrieve community information");
! 3304: } else {
! 3305: $error = &mt("An error occurred while setting parameters '.
1.85 raeburn 3306: 'for Discussion Boards folder: '.
1.101.4.2! raeburn 3307: 'Could not retrieve course information");
! 3308: }
1.85 raeburn 3309: }
1.56 raeburn 3310: } else {
1.85 raeburn 3311: $r->print($outcome);
1.56 raeburn 3312: }
3313: }
1.85 raeburn 3314: } else {
1.101.4.2! raeburn 3315: $error = &mt("An error occurred while retrieving the contents of the group's folder.").'<br />';
! 3316: if ($crstype eq 'Community') {
! 3317: $error .= &mt("You need to re-initialize the community.");
! 3318:
! 3319: } else {
! 3320: $error .= &mt("You need to re-initialize the course.");
! 3321: }
1.85 raeburn 3322: }
3323: if ($error ne '') {
3324: $r->print('<div class="LC_error">'.$error.'</div>');
1.56 raeburn 3325: }
3326: }
1.79 bisitz 3327: $r->print('<div class="LC_success">'
3328: .&mt($ucgpterm.' [_1] was updated.','<i>'.$groupname.'</i>')
3329: .'</div>');
1.5 raeburn 3330: }
3331: } else {
3332: my %actiontype = (
3333: 'create' => 'creating',
3334: 'modify' => 'modifying',
3335: );
1.29 raeburn 3336: &Apache::lonnet::logthis("Failed to store $gpterm $groupname ".
3337: 'in '.lc($crstype).': '.$cnum.
3338: ' in domain: '.$cdom);
1.79 bisitz 3339: $r->print('<div class="LC_error">'
3340: .&mt('An error occurred when [_1] the '.$gpterm.'. '
3341: .'Please try again.',$actiontype{$action})
3342: .'</div>');
1.5 raeburn 3343: }
3344: return $result;
3345: }
3346:
3347: sub process_membership {
1.6 raeburn 3348: my ($r,$cdom,$cnum,$action,$state,$groupname,$tools,$enddate,$startdate,
1.29 raeburn 3349: $userdata,$idx,$toolprivs,$usertools,$specificity,$defprivs,$memchg,
1.101.4.2! raeburn 3350: $gpterm,$ucgpterm,$crstype)=@_;
1.5 raeburn 3351: my %usersettings = ();
1.6 raeburn 3352: my %added= ();
3353: my %failed = ();
3354: my $num_ok = 0;
3355: my $num_fail = 0;
1.3 raeburn 3356: my %group_privs = ();
1.20 raeburn 3357: my %curr_privs = ();
1.21 raeburn 3358: my %curr_start = ();
3359: my %curr_end = ();
1.3 raeburn 3360: my %tooltype = ();
1.77 raeburn 3361: my $context = 'processgroupmembership';
1.5 raeburn 3362:
1.3 raeburn 3363: foreach my $tool (@{$tools}) {
3364: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3365: $tooltype{$priv} = $tool;
1.5 raeburn 3366: if ($specificity eq 'Yes') {
1.3 raeburn 3367: my @users =
3368: &Apache::loncommon::get_env_multiple('form.userpriv_'.$priv);
3369: foreach my $user (@users) {
3370: $group_privs{$user} .= $priv.':';
1.8 raeburn 3371: if ($state eq 'memresult') {
3372: unless (exists($$usertools{$user}{$tool})) {
3373: $$usertools{$user}{$tool} = 1;
3374: }
3375: }
1.3 raeburn 3376: }
3377: } else {
1.5 raeburn 3378: if (@{$defprivs} > 0) {
1.26 raeburn 3379: if (grep/^\Q$priv\E$/,@{$defprivs}) {
1.5 raeburn 3380: foreach my $user (sort(keys(%{$usertools}))) {
3381: if ($$usertools{$user}{$tool}) {
3382: $group_privs{$user} .= $priv.':';
3383: }
1.3 raeburn 3384: }
3385: }
3386: }
3387: }
3388: }
3389: }
3390: foreach my $user (keys(%group_privs)) {
3391: $group_privs{$user} =~ s/:$//;
3392: }
1.5 raeburn 3393:
1.6 raeburn 3394: my $now = time;
3395: my @activate = ();
3396: my @expire = ();
3397: my @deletion = ();
3398: my @reenable = ();
1.20 raeburn 3399: my @unchanged = ();
1.6 raeburn 3400: if ($state eq 'memresult') {
3401: if (ref($$memchg{'activate'}) eq 'ARRAY') {
3402: @activate = @{$$memchg{'activate'}};
3403: }
3404: if (ref($$memchg{'expire'}) eq 'ARRAY') {
3405: @expire = @{$$memchg{'expire'}};
3406: }
3407: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
3408: @deletion = @{$$memchg{'deletion'}};
3409: }
3410: if (ref($$memchg{'reenable'}) eq 'ARRAY') {
3411: @reenable = @{$$memchg{'reenable'}};
3412: }
1.20 raeburn 3413: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
3414: $groupname);
3415: foreach my $key (sort(keys(%membership))) {
3416: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
1.21 raeburn 3417: ($curr_end{$1},$curr_start{$1},$curr_privs{$1}) =
3418: split(/:/,$membership{$key},3);
1.20 raeburn 3419: }
3420: }
1.6 raeburn 3421: if (@expire + @deletion > 0) {
3422: foreach my $user (@expire) {
1.21 raeburn 3423: my $savestart = $curr_start{$user};
3424: if ($savestart > $now) {
3425: $savestart = $now;
1.6 raeburn 3426: }
1.21 raeburn 3427: $usersettings{$groupname.':'.$user} = $now.':'.$savestart.':'.
3428: $curr_privs{$user};
1.6 raeburn 3429: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.21 raeburn 3430: $user,$now,$savestart,
1.77 raeburn 3431: $curr_privs{$user},'',$context) eq 'ok') {
1.6 raeburn 3432: push(@{$added{'expired'}},$user);
3433: $num_ok ++;
3434: } else {
3435: push(@{$failed{'expired'}},$user);
3436: $num_fail ++;
3437: }
3438: }
3439: foreach my $user (@deletion) {
3440: $usersettings{$groupname.':'.$user} = $now.':-1:';
3441: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.76 raeburn 3442: $user,$now,'-1','','',$context)
1.6 raeburn 3443: eq 'ok') {
3444: push(@{$added{'deleted'}},$user);
3445: $num_ok ++;
3446: } else {
3447: push(@{$failed{'deleted'}},$user);
3448: $num_fail ++;
3449: }
3450: }
3451: }
1.8 raeburn 3452: }
1.6 raeburn 3453:
1.5 raeburn 3454: foreach my $user (sort(keys(%{$usertools}))) {
1.20 raeburn 3455: if ((grep(/^$user$/,@expire)) || (grep(/^$user$/,@deletion))) {
3456: next;
3457: }
1.6 raeburn 3458: my $type;
3459: my $start = $startdate;
3460: my $end = $enddate;
3461: if ($state eq 'memresult') {
3462: if (@activate > 0) {
3463: if (grep/^$user$/,@activate) {
3464: $start = $now;
1.21 raeburn 3465: $end = $enddate;
1.6 raeburn 3466: $type = 'activated';
3467: }
3468: }
3469: if (@reenable > 0) {
3470: if (grep/^$user$/,@reenable) {
1.21 raeburn 3471: $start = $startdate;
3472: $end = $enddate;
1.6 raeburn 3473: $type = 'reenabled';
3474: }
3475: }
1.38 raeburn 3476: if ($type eq '') {
3477: if ($curr_privs{$user} eq $group_privs{$user}) {
3478: push(@unchanged,$user);
3479: next;
3480: }
3481: if (exists($curr_start{$user})) {
3482: $start = $curr_start{$user};
3483: }
3484: if (exists($curr_end{$user})) {
3485: $end = $curr_end{$user};
3486: }
3487: $type = 'modified';
3488: }
1.6 raeburn 3489: } else {
3490: $type = 'added';
3491: }
3492: $usersettings{$groupname.':'.$user} = $end.':'.$start.':'.
1.5 raeburn 3493: $group_privs{$user};
3494: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.6 raeburn 3495: $user,$end,$start,
1.76 raeburn 3496: $group_privs{$user},'',$context) eq 'ok') {
1.6 raeburn 3497: push(@{$added{$type}},$user);
3498: $num_ok ++;
1.3 raeburn 3499: } else {
1.6 raeburn 3500: push(@{$failed{$type}},$user);
3501: $num_fail ++;
1.5 raeburn 3502: }
3503: }
3504: my $roster_result = &Apache::lonnet::modify_coursegroup_membership($cdom,
3505: $cnum,\%usersettings);
1.6 raeburn 3506: if ($num_ok) {
3507: foreach my $type (sort(keys(%added))) {
3508: $r->print(&mt('The following users were successfully [_1]',$type));
1.20 raeburn 3509: if (!($type eq 'deleted' || $type eq 'expired')) {
1.6 raeburn 3510: $r->print(&mt(' with the following privileges'));
3511: }
3512: $r->print(':<br />');
3513: foreach my $user (@{$added{$type}}) {
1.8 raeburn 3514: my $privlist = '';
3515: if (!($type eq 'deleted' || $type eq 'expired')) {
3516: $privlist = ': ';
1.6 raeburn 3517: my @privs = split(/:/,$group_privs{$user});
3518: my $curr_tool = '';
3519: foreach my $priv (@privs) {
3520: unless ($curr_tool eq $tooltype{$priv}) {
3521: $curr_tool = $tooltype{$priv};
3522: $privlist .= '<b>'.$curr_tool.'</b>: ';
3523: }
3524: $privlist .= $$toolprivs{$curr_tool}{$priv}.', ';
3525: }
3526: $privlist =~ s/, $//;
3527: }
1.8 raeburn 3528: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.$privlist.'<br />');
1.6 raeburn 3529: }
1.20 raeburn 3530: $r->print('<br />');
1.6 raeburn 3531: }
3532: }
3533: if ($num_fail) {
3534: foreach my $type (sort(keys(%failed))) {
1.79 bisitz 3535: $r->print('<div class="LC_error">'
3536: .&mt("The following users could not be $type, because an error occurred:")
3537: .'</div>');
1.6 raeburn 3538: foreach my $user (@{$failed{$type}}) {
3539: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
3540: }
1.5 raeburn 3541: }
1.20 raeburn 3542: $r->print('<br />');
3543: }
3544: if (@unchanged > 0) {
1.80 bisitz 3545: $r->print(&mt('No change occurred for the following users:').'<br />');
1.20 raeburn 3546: foreach my $user (sort(@unchanged)) {
3547: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
3548: }
3549: $r->print('<br />');
1.5 raeburn 3550: }
3551: if ($roster_result eq 'ok') {
1.80 bisitz 3552: $r->print('<div class="LC_success">'
3553: .&mt($ucgpterm.' membership list updated.')
3554: .'</div>');
1.101.4.2! raeburn 3555: $r->print('<p class="LC_info">');
! 3556: if ($crstype eq 'Community') {
! 3557: $r->print(&mt("Any currently logged in community users affected by the changes you made"
! 3558: .' to group membership or privileges for the [_1] group will need to log out'
! 3559: .' and log back in for their LON-CAPA sessions to reflect these changes.'
! 3560: ,'<i>'.$groupname.'</i>'));
! 3561:
! 3562: } else {
! 3563: $r->print(&mt("Any currently logged in course users affected by the changes you made"
1.80 bisitz 3564: .' to group membership or privileges for the [_1] group will need to log out'
3565: .' and log back in for their LON-CAPA sessions to reflect these changes.'
1.101.4.2! raeburn 3566: ,'<i>'.$groupname.'</i>'));
! 3567: }
! 3568: $r->print('</p>');
1.5 raeburn 3569: } else {
1.80 bisitz 3570: $r->print('<div class="LC_error">'
3571: .&mt("An error occurred while updating the $gpterm membership list:")
3572: .'<br />'.$roster_result
3573: .'</div>');
1.5 raeburn 3574: }
3575: return;
3576: }
3577:
3578: sub mapping_options {
1.44 albertel 3579: my ($r,$action,$formname,$page,$sectioncount,$states,$stored,
1.58 raeburn 3580: $navbuttons,$img1,$img2,$gpterm,$ucgpterm,$crstype,$cdom,$cnum) = @_;
1.5 raeburn 3581: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 3582: 'auto' => "Settings for automatic $gpterm enrollment",
3583: 'gmma' => "$ucgpterm membership mapping to specific sections/roles",
3584: 'endi' => "Enable/disable automatic $gpterm enrollment for ".
3585: "users in specified roles and sections",
1.53 raeburn 3586: '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 3587: '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.",
3588: 'pirs' => "Pick roles and sections for automatic $gpterm enrollment",
1.5 raeburn 3589: 'on' => 'on',
3590: 'off' => 'off',
1.29 raeburn 3591: 'auad' => "Automatically enable $gpterm membership when roles are added?",
3592: 'auex' => "Automatically expire $gpterm membership when roles are removed?",
3593: 'mapr' => "Mapping of roles and sections affected by automatic $gpterm enrollment/disenrollment follows scheme chosen below.",
1.5 raeburn 3594: );
1.44 albertel 3595: &automapping($r,$action,$stored,\%lt,$img1);
1.58 raeburn 3596: &mapping_settings($r,$sectioncount,\%lt,$stored,$img2,$crstype,$cdom,$cnum,
3597: $action);
1.5 raeburn 3598: return;
3599: }
3600:
3601: sub automapping {
1.44 albertel 3602: my ($r,$action,$stored,$lt,$image) = @_;
1.5 raeburn 3603: my $add = 'off';
3604: my $drop = 'off';
3605: if (exists($$stored{'autoadd'})) {
3606: $add = $$stored{'autoadd'};
3607: }
3608: if (exists($$stored{'autodrop'})) {
3609: $drop = $$stored{'autodrop'};
3610: }
1.78 raeburn 3611: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$$lt{'endi'}).'
1.44 albertel 3612: <b>'.$$lt{'gmma'}.':</b><br />'.$$lt{'adds'}.'<br />'.$$lt{'drops'}.'<br /><br />
1.83 bisitz 3613: <span class="LC_nobreak">'.$$lt{'auad'}.':
1.80 bisitz 3614: <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 3615: if ($action eq 'modify') {
1.82 bisitz 3616: $r->print(' ('.&mt('Currently set to [_1].','<b>'.$$lt{$add}.'</b>').')');
1.5 raeburn 3617: }
3618: $r->print('
1.83 bisitz 3619: </span><br />
3620: <span class="LC_nobreak">'.$$lt{'auex'}.':
1.80 bisitz 3621: <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 3622: if ($action eq 'modify') {
1.82 bisitz 3623: $r->print(' ('.&mt('Currently set to [_1].','<b>'.$$lt{$drop}.'</b>').')');
1.3 raeburn 3624: }
1.83 bisitz 3625: $r->print('</span><br /><br />'.$$lt{'mapr'});
1.5 raeburn 3626: }
1.3 raeburn 3627:
1.5 raeburn 3628: sub mapping_settings {
1.58 raeburn 3629: my ($r,$sectioncount,$lt,$stored,$image,$crstype,$cdom,$cnum,$action) = @_;
1.5 raeburn 3630: my @sections = keys(%{$sectioncount});
3631: if (@sections > 0) {
3632: @sections = sort {$a cmp $b} @sections;
1.17 raeburn 3633: unshift(@sections,'none'); # Put 'no sections' next
3634: unshift(@sections,'all'); # Put 'all' at the front of the list
1.53 raeburn 3635: } else {
3636: @sections = ('all','none');
1.3 raeburn 3637: }
1.78 raeburn 3638: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$$lt{'pirs'}));
1.101.4.2! raeburn 3639: my @roles = &standard_roles($crstype);
1.59 raeburn 3640: my %customroles = &Apache::lonhtmlcommon::course_custom_roles($cdom,$cnum);
1.44 albertel 3641: $r->print(&Apache::loncommon::start_data_table().
3642: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 3643: $r->print('
3644: <th>'.&mt('Active?').'</th>
3645: <th>'.&mt('Role').'</th>');
3646: if (@sections > 0) {
1.44 albertel 3647: $r->print('<th>'.&mt('Sections').'</th>');
1.3 raeburn 3648: }
1.44 albertel 3649: $r->print(&Apache::loncommon::end_data_table_header_row()."\n");
1.5 raeburn 3650: foreach my $role (@roles) {
1.58 raeburn 3651: my $roletitle=&Apache::lonnet::plaintext($role,$crstype);
3652: $r->print(&print_autorole_item($role,$roletitle,\@sections));
1.5 raeburn 3653: }
1.58 raeburn 3654: my @customs;
1.5 raeburn 3655: foreach my $role (sort(keys(%customroles))) {
1.58 raeburn 3656: my ($roletitle) = ($role =~ m|^cr/[^/]+/[^/]+/(.+)$|);
3657: push (@customs,$role);
3658: $r->print(&print_autorole_item($role,$roletitle,\@sections));
3659: }
3660: if ($action eq 'modify') {
3661: foreach my $role (@{$$stored{'autorole'}}) {
3662: if ((!grep(/^\Q$role\E$/,@customs)) &&
3663: (!grep(/^\Q$role\E$/,@roles))) {
3664: my $roletitle;
3665: if ($role =~ /^cr/) {
3666: ($roletitle) = ($role =~ m|_([^_]+)$|);
3667: } else {
3668: $roletitle = &Apache::lonnet::plaintext($role,$crstype);
3669: }
3670: $r->print(&print_autorole_item($role,$roletitle,\@sections));
3671: }
3672: }
1.5 raeburn 3673: }
1.44 albertel 3674: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 3675: return;
3676: }
1.3 raeburn 3677:
1.58 raeburn 3678: sub print_autorole_item {
3679: my ($role,$roletitle,$sections) = @_;
3680: my $sections_sel;
3681: if (@{$sections} > 0) {
1.101.4.2! raeburn 3682: if (($role eq 'cc') || ($role eq 'co')) {
1.58 raeburn 3683: $sections_sel = '<td align="right">'.
3684: &mt('all sections').'<input type="hidden" '.
1.101.4.2! raeburn 3685: 'name="sec_'.$role.'" value="all" /></td>';
1.58 raeburn 3686: } else {
3687: $sections_sel='<td align="right">'.
3688: §ions_selection($sections,'sec_'.$role).
3689: '</td>';
3690: }
3691: }
3692: my $output = &Apache::loncommon::start_data_table_row().
3693: '<td><input type="checkbox" '.
3694: 'name="autorole" value="'.$role.'" />'.
3695: '</td><td>'.$roletitle.'</td>'.$sections_sel.
3696: &Apache::loncommon::end_data_table_row();
3697: return $output;
3698: }
3699:
1.5 raeburn 3700: sub standard_roles {
1.101.4.2! raeburn 3701: my ($crstype) = @_;
! 3702: my @roles = qw(in ta ep ad st);
! 3703: if ($crstype eq 'Community') {
! 3704: unshift(@roles,'co');
! 3705: } else {
! 3706: unshift(@roles,'cc');
! 3707: }
1.5 raeburn 3708: return @roles;
3709: }
3710:
3711: sub modify_menu {
1.29 raeburn 3712: my ($r,$groupname,$page,$gpterm) = @_;
1.5 raeburn 3713: my @menu =
3714: (
1.29 raeburn 3715: { text => "Modify default $gpterm settings",
1.5 raeburn 3716: help => 'Course_Modify_Group',
3717: state => 'change_settings',
3718: branch => 'settings',
3719: },
1.6 raeburn 3720: { text => 'Modify access, tools and/or privileges for previous, '.
3721: 'future, or current members',
1.5 raeburn 3722: help => 'Course_Modify_Group_Membership',
3723: state => 'change_members',
3724: branch => 'members',
3725: },
1.29 raeburn 3726: { text => "Add member(s) to the $gpterm",
1.5 raeburn 3727: help => 'Course_Group_Add_Members',
3728: state => 'add_members',
3729: branch => 'adds',
3730: },
3731: );
3732: my $menu_html = '';
3733: foreach my $menu_item (@menu) {
3734: $menu_html .=
3735: '<p><font size="+1"><a href="/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state='.$menu_item->{'state'}.'&branch='.$menu_item->{'branch'}.'">';
3736: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
3737: if (exists($menu_item->{'help'})) {
3738: $menu_html.=
3739: &Apache::loncommon::help_open_topic($menu_item->{'help'});
3740: }
3741: $menu_html.='</p>'.$/;
1.3 raeburn 3742: }
1.5 raeburn 3743: $r->print($menu_html);
1.3 raeburn 3744: return;
3745: }
3746:
3747: sub member_privs_entries {
1.45 albertel 3748: my ($r,$usertools,$toolprivs,$fixedprivs,$userdata,$idx,$showtools,
3749: $defprivs,$excluded) = @_;
1.5 raeburn 3750: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 3751: if (defined($excluded)) {
3752: if (ref($excluded) eq 'ARRAY') {
3753: if (grep/^$user$/,@{$excluded}) {
3754: next;
3755: }
3756: }
3757: }
1.5 raeburn 3758: my ($uname,$udom) = split(/:/,$user);
1.45 albertel 3759: $r->print(&Apache::loncommon::start_data_table_row().'
1.5 raeburn 3760: <td>'.$$userdata{$user}[$$idx{fullname}].'</td>
1.3 raeburn 3761: <td>'.$uname.'</td>
3762: <td>'.$udom.'</td>
1.53 raeburn 3763: <td valign="top">
3764: <table>
3765: <tr>
3766: <td><b>'.
3767: &mt('Collaborative Tool').'</b></td>
3768: </tr>
3769: <tr>
3770: <td><b>'.&mt('Fixed').'</b></td>
3771: </tr>
3772: <tr>
3773: <td><b>'.&mt('Optional').'</b></td>
3774: </tr>
3775: </table>
3776: </td>');
1.5 raeburn 3777: foreach my $tool (@{$showtools}) {
3778: if (exists($$usertools{$user}{$tool})) {
1.45 albertel 3779: $r->print('<td valign="top"><table><tr><th colspan="2">'.$tool.'</th></tr>');
1.3 raeburn 3780: my $privcount = 0;
3781: my $fixed = '';
3782: my $dynamic = '';
3783: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3784: if (exists($$fixedprivs{$tool}{$priv})) {
1.5 raeburn 3785: $fixed .= '<input type="hidden" name="userpriv_'.$priv.'" value="'.$user.'" />'.$$toolprivs{$tool}{$priv}.' ';
1.3 raeburn 3786: } else {
3787: $privcount ++;
3788: if ($privcount == 3) {
3789: $dynamic .= '</tr><tr>';
3790: }
1.83 bisitz 3791: $dynamic .='<td><span class="LC_nobreak"><label><input type="checkbox" '.
1.5 raeburn 3792: 'name="userpriv_'.$priv.'" value="'.$user.'"';
3793: if (grep/^\Q$priv\E$/,@{$defprivs}) {
3794: $dynamic .= ' checked="checked" ';
3795: }
3796: $dynamic .= ' />'.$$toolprivs{$tool}{$priv}.
1.83 bisitz 3797: '</label></span></td>';
1.3 raeburn 3798: }
3799: }
1.83 bisitz 3800: $r->print('<tr><td colspan="2"><span class="LC_nobreak">'.$fixed.'</span></td></tr><tr>'.$dynamic.'</tr></table></td>');
1.3 raeburn 3801: } else {
1.45 albertel 3802: $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 3803: }
3804: }
1.45 albertel 3805: $r->print(&Apache::loncommon::end_data_table_row());
1.3 raeburn 3806: }
3807: }
3808:
3809: sub get_dates_from_form {
3810: my $startdate;
3811: my $enddate;
3812: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
3813: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
3814: if ( exists ($env{'form.no_end_date'}) ) {
3815: $enddate = 0;
3816: }
3817: return ($startdate,$enddate);
1.5 raeburn 3818: }
3819:
1.3 raeburn 3820: sub date_setting_table {
3821: my ($starttime,$endtime,$formname) = @_;
3822: my $startform = &Apache::lonhtmlcommon::date_setter($formname,
3823: 'startdate',$starttime);
3824: my $endform = &Apache::lonhtmlcommon::date_setter($formname,
3825: 'enddate',$endtime);
1.98 bisitz 3826: my $perpetual = ' <span class="LC_nobreak"><label>'
3827: .'<input type="checkbox" name="no_end_date" />'
3828: .&mt('No end date')
3829: .'</label></span>';
3830: my $table = &Apache::lonhtmlcommon::start_pick_box()
3831: .&Apache::lonhtmlcommon::row_title(&mt('Start Date'))
3832: .$startform
3833: .&Apache::lonhtmlcommon::row_closure()
3834: .&Apache::lonhtmlcommon::row_title(&mt('End Date'))
3835: .$endform
3836: .$perpetual
3837: .&Apache::lonhtmlcommon::row_closure(1)
3838: .&Apache::lonhtmlcommon::end_pick_box();
1.41 albertel 3839: return $table;
1.1 raeburn 3840: }
3841:
1.32 raeburn 3842: sub add_group_folder {
3843: my ($cdom,$cnum,$now,$groupname,$action,$description,$tools,$groupinfo,
3844: $gpterm,$ucgpterm,$crstype) = @_;
3845: if ($cdom eq '' || $cnum eq '') {
1.101.4.2! raeburn 3846: my $error = '<span class="LC_error">';
! 3847: if ($crstype eq 'Community') {
! 3848: $error .= &mt("Error: invalid community domain or number - group folder creation failed.");
! 3849: } else {
! 3850: $error .= &mt("Error: invalid course domain or number - group folder creation failed.");
! 3851: }
! 3852: $error .= '</span>';
! 3853: return $error;
1.32 raeburn 3854: }
1.67 raeburn 3855: my ($outcome,$allgrpsmap,$grpmap,$boardsmap,$grppage,$warning);
1.32 raeburn 3856: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
1.47 raeburn 3857: $allgrpsmap = $crspath.'group_allfolders.sequence';
1.32 raeburn 3858: if ($action eq 'create') {
1.67 raeburn 3859: if (&get_folder_lock($cdom,$cnum,'group_allfolders',$now) eq 'ok') {
3860: # check if group_allfolders.sequence exists.
1.69 raeburn 3861: my $mapcontents = &Apache::lonnet::getfile($allgrpsmap);
3862: if ($mapcontents eq '-1') { #file does not exist;
1.80 bisitz 3863: my $grpstitle = &mt("$crstype $ucgpterm".'s');
1.67 raeburn 3864: my $topmap_url = '/'.$env{'course.'.$env{'request.course.id'}.'.url'};
3865: $topmap_url =~ s|/+|/|g;
3866: if ($topmap_url =~ m|^/uploaded|) {
3867: $outcome = &map_updater($cdom,$cnum,'group_allfolders.sequence',
3868: 'toplevelgroup',$grpstitle,$topmap_url);
3869: } else {
1.80 bisitz 3870: $outcome = '<span class="LC_warning">'
3871: .&mt('Non-standard course - folder for all groups not added.')
3872: .'</span>';
1.67 raeburn 3873: }
1.32 raeburn 3874: if ($outcome ne 'ok') {
1.67 raeburn 3875: my $delresult = &release_folder_lock($cdom,$cnum,'group_allfolders');
3876: if ($delresult ne 'ok') {
3877: $warning = $delresult;
3878: }
1.84 raeburn 3879: return $outcome.$warning;
1.32 raeburn 3880: }
3881: }
1.67 raeburn 3882: my $delresult = &release_folder_lock($cdom,$cnum,'group_allfolders');
3883: if ($delresult ne 'ok') {
3884: $warning = $delresult ;
3885: }
3886: } else {
1.80 bisitz 3887: $outcome = '<span class="LC_error">'
3888: .&mt('Could not obtain exclusive lock to check status of the folder for all groups. No group folder added.')
1.84 raeburn 3889: .'</span>';
1.67 raeburn 3890: return $outcome;
1.32 raeburn 3891: }
1.75 bisitz 3892: my $grpfolder = &mt($ucgpterm.' Folder - [_1]',$description);
1.49 raeburn 3893: $grppage='/adm/'.$cdom.'/'.$cnum.'/'.$groupname.'/smppg';
1.75 bisitz 3894: my $grptitle = &mt('Group homepage - [_1]',$description);
1.55 raeburn 3895: my ($discussions,$disctitle);
1.47 raeburn 3896: my $outcome = &map_updater($cdom,$cnum,'group_folder_'.$groupname.'.sequence',
1.32 raeburn 3897: 'grpseq',$grpfolder,$allgrpsmap,$grppage,
3898: $grptitle);
3899: if ($outcome ne 'ok') {
1.67 raeburn 3900: return $outcome.$warning;
1.32 raeburn 3901: }
3902: my $pageout = &create_homepage($cdom,$cnum,$groupname,$groupinfo,
3903: $tools,$gpterm,$ucgpterm,$now);
3904: # Link to folder for bulletin boards
1.47 raeburn 3905: $grpmap = $crspath.'group_folder_'.$groupname.'.sequence';
1.32 raeburn 3906: if (grep/^discussion$/,@{$tools}) {
3907: $disctitle = &mt('Discussion Boards');
1.47 raeburn 3908: my $outcome = &map_updater($cdom,$cnum,'group_boards_'.$groupname.
1.32 raeburn 3909: '.sequence','bbseq',$disctitle,$grpmap);
3910: if ($outcome ne 'ok') {
1.67 raeburn 3911: return $outcome.$warning;
1.32 raeburn 3912: }
1.47 raeburn 3913: $boardsmap = $crspath.'group_boards_'.$groupname.'.sequence';
1.32 raeburn 3914: }
3915: } else {
3916: #modify group folder if status of discussions tools is changed
3917: }
3918: my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.67 raeburn 3919: my $navmap = Apache::lonnavmaps::navmap->new();
1.85 raeburn 3920: if (!defined($navmap)) {
1.101.4.2! raeburn 3921: $warning .= '<span class="LC_error">';
! 3922: if ($crstype eq 'Community') {
! 3923: $warning .= &mt("Error retrieving community contents").
! 3924: ' '.&mt("You need to re-initialize the community.");
! 3925: } else {
! 3926: $warning .= &mt("Error retrieving course contents").
! 3927: ' '.&mt("You need to re-initialize the course.");
! 3928: }
! 3929: $warning .= '</span>';
! 3930: return $warning;
1.85 raeburn 3931: }
1.32 raeburn 3932: # modify parameters
3933: my $parm_result;
3934: if ($action eq 'create') {
3935: if ($grpmap) {
3936: $parm_result .= &parm_setter($navmap,$cdom,$grpmap,$groupname);
3937: }
3938: if ($grppage) {
3939: $parm_result .= &parm_setter($navmap,$cdom,$grppage,$groupname);
3940: }
3941: if ($boardsmap) {
3942: $parm_result .= &parm_setter($navmap,$cdom,$boardsmap,$groupname);
3943: }
3944: }
1.67 raeburn 3945: undef($navmap);
1.32 raeburn 3946: if ($parm_result) {
1.67 raeburn 3947: return $warning.$parm_result;
3948: } else {
3949: return 'ok';
3950: }
3951: }
3952:
3953: sub get_folder_lock {
3954: my ($cdom,$cnum,$folder_name,$now) = @_;
3955: # get lock for folder being edited.
3956: my $lockhash = {
3957: $folder_name."\0".'locked_folder' => $now.':'.$env{'user.name'}.
3958: ':'.$env{'user.domain'},
3959: };
3960: my $tries = 0;
3961: my $gotlock = &Apache::lonnet::newput('coursegroups',$lockhash,$cdom,$cnum);
3962:
3963: while (($gotlock ne 'ok') && $tries <3) {
3964: $tries ++;
1.68 albertel 3965: sleep(1);
1.67 raeburn 3966: $gotlock = &Apache::lonnet::newput('coursegroups',$lockhash,$cdom,$cnum);
3967: }
3968: return $gotlock;
3969: }
3970:
3971: sub release_folder_lock {
3972: my ($cdom,$cnum,$folder_name) = @_;
3973: # remove lock
3974: my @del_lock = ($folder_name."\0".'locked_folder');
3975: my $dellockoutcome=&Apache::lonnet::del('coursegroups',\@del_lock,$cdom,$cnum);
3976: if ($dellockoutcome ne 'ok') {
1.80 bisitz 3977: return ('<div class="LC_error">'
3978: .&mt('Warning: failed to release lock for folder: [_1].','<tt>'.$folder_name.'</tt>')
3979: .'</div>'
3980: );
1.32 raeburn 3981: } else {
3982: return 'ok';
3983: }
3984: }
3985:
3986: sub map_updater {
3987: my ($cdom,$cnum,$newfile,$itemname,$itemtitle,$parentmap,$startsrc,
3988: $starttitle,$endsrc,$endtitle) = @_;
3989: my $outcome;
3990: $env{'form.'.$itemname} = &new_map($startsrc,$starttitle,$endsrc,
3991: $endtitle);
3992: my $newmapurl=&Apache::lonnet::finishuserfileupload($cnum,$cdom,$itemname,
3993: $newfile);
3994: if ($newmapurl !~ m|^/uploaded|) {
1.80 bisitz 3995: $outcome = '<div class="LC_error">'
3996: .&mt('Error uploading new folder.')." ($newfile): $newmapurl"
3997: .'</div>';
1.32 raeburn 3998: return $outcome;
1.67 raeburn 3999: }
1.63 albertel 4000: my ($errtext,$fatal)=&LONCAPA::map::mapread($parentmap);
1.32 raeburn 4001: if ($fatal) {
1.80 bisitz 4002: $outcome = '<div class="LC_error">'
4003: .&mt('Error reading contents of parent folder.')." ($parentmap): $errtext"
4004: .'</div>';
1.32 raeburn 4005: return $outcome;
4006: } else {
1.63 albertel 4007: my $newidx=&LONCAPA::map::getresidx($newmapurl);
4008: $LONCAPA::map::resources[$newidx] = $itemtitle.':'.$newmapurl.
1.32 raeburn 4009: ':false:normal:res';
1.63 albertel 4010: $LONCAPA::map::order[1+$#LONCAPA::map::order]=$newidx;
4011: my ($outtext,$errtext) = &LONCAPA::map::storemap($parentmap,1);
1.67 raeburn 4012: if ($errtext) {
1.80 bisitz 4013: $outcome = '<div class="LC_error">'
4014: .&mt('Error saving updated parent folder.')." ($parentmap): $errtext"
4015: .'</div>';
1.32 raeburn 4016: return $outcome;
4017: }
4018: }
4019: return 'ok';
4020: }
4021:
4022: sub new_map {
4023: my ($startsrc,$starttitle,$endsrc,$endtitle) = @_;
4024: my $newmapstr = '
4025: <map>
4026: <resource id="1" src="'.$startsrc.'" type="start" title="'.$starttitle.'"></resource>
4027: <link from="1" to="2" index="1"></link>
4028: <resource id="2" src="'.$endsrc.'" type="finish" title="'.$endtitle.'"></resource>
4029: </map>
4030: ';
4031: return $newmapstr;
4032: }
4033:
4034: sub parm_setter {
1.101.4.2! raeburn 4035: my ($navmap,$cdom,$url,$groupname,$crstype) = @_;
1.85 raeburn 4036: if (!defined($navmap)) {
1.101.4.2! raeburn 4037: my $allresults;
! 4038: if ($crstype eq 'Community') {
! 4039: $allresults = &mt("Parameters not set for [_1] because the contents of the community could not be retrieved.",$url).' '.
! 4040: &mt("You need to reinitialize the community.");
! 4041: } else {
! 4042: $allresults = &mt("Parameters not set for [_1] because the contents of the course could not be retrieved.",$url).' '.
! 4043: &mt("You need to reinitialize the course.");
! 4044:
! 4045: }
! 4046: return '<div class="LC_warning">'.$allresults.'</div>';
1.85 raeburn 4047: }
1.32 raeburn 4048: my %hide_settings = (
4049: 'course' => {
4050: 'num' => 13,
4051: 'set' => 'yes',
4052: },
4053: 'group' => {
4054: 'num' => 5,
4055: 'set' => 'no',
4056: 'extra' => $groupname,
4057: },
4058: );
4059: my $res = $navmap->getResourceByUrl($url);
1.101.4.2! raeburn 4060: my $allresults;
1.67 raeburn 4061: if ($res) {
4062: my $symb = $res->symb();
4063: foreach my $level (keys(%hide_settings)) {
4064: my $parmresult =
4065: &Apache::lonparmset::storeparm_by_symb($symb,
1.32 raeburn 4066: '0_hiddenresource',
4067: $hide_settings{$level}{'num'},
4068: $hide_settings{$level}{'set'},
4069: 'string_yesno',undef,$cdom,
4070: undef,undef,
4071: $hide_settings{$level}{'extra'});
1.67 raeburn 4072: if ($parmresult) {
4073: $allresults .= $level.': '.$parmresult;
4074: }
1.37 raeburn 4075: }
1.67 raeburn 4076: } else {
1.101.4.2! raeburn 4077: $allresults = '<div class="LC_warning">';
! 4078: if ($crstype eq 'Community') {
! 4079: $allresults .= &mt("Parameters not set for [_1] because the resource was not recognized as part of the community.",'<tt>'.$url.'</tt>');
! 4080: } else {
! 4081: $allresults .= &mt('Parameters not set for [_1] because the resource was not recognized as part of the course.','<tt>'.$url.'</tt>');
! 4082: }
! 4083: $allresults .= '</div>';
1.32 raeburn 4084: }
1.37 raeburn 4085: return $allresults;
1.32 raeburn 4086: }
4087:
1.3 raeburn 4088: sub create_homepage {
1.32 raeburn 4089: my ($cdom,$cnum,$name,$groupinfo,$tools,$gpterm,$ucgpterm,$now) = @_;
1.3 raeburn 4090: my $functionality = join(',',@{$tools});
1.24 www 4091: my $content = &unescape($$groupinfo{description});
1.3 raeburn 4092: $content=~s/\s+$//s;
4093: $content=~s/^\s+//s;
4094: $content=~s/\<br\s*\/*\>$//s;
4095: $content=&Apache::lonfeedback::clear_out_html($content,1);
4096:
4097: my %pageinfo = (
1.29 raeburn 4098: 'aaa_title' => "$ucgpterm: $name",
1.3 raeburn 4099: 'abb_links' => $functionality,
4100: 'bbb_content' => $content,
4101: 'ccc_webreferences' => '',
1.32 raeburn 4102: 'uploaded.lastmodified' => $now,
1.3 raeburn 4103: );
4104: my $putresult = &Apache::lonnet::put('grppage_'.$name,\%pageinfo,$cdom,$cnum);
4105: return $putresult;
1.1 raeburn 4106: }
4107:
1.5 raeburn 4108: sub check_uncheck_tools {
4109: my ($r,$available) = @_;
4110: if (ref($available) eq 'ARRAY') {
4111: $r->print('
4112: <script type="text/javascript">
4113: function checkAllTools(formname) {
4114: ');
4115: foreach my $tool (@{$available}) {
4116: $r->print(' checkAll(formname.user_'.$tool.');'."\n");
4117: }
4118: $r->print(' checkAll(formname.togglefunc);'."\n");
4119: $r->print('
4120: }
4121: function uncheckAllTools(formname) {
4122: ');
4123: foreach my $tool (@{$available}) {
4124: $r->print(' uncheckAll(formname.user_'.$tool.');'."\n");
4125: }
4126: $r->print(' uncheckAll(formname.togglefunc);'."\n");
4127: $r->print('
4128: }
4129: function toggleTools(field,caller) {
4130: if (caller.checked) {
4131: checkAll(field);
4132: } else {
4133: uncheckAll(field);
4134: }
4135: return;
4136: }
4137: </script>
4138: ');
4139: }
4140: return;
4141: }
4142:
4143: sub validate_groupname {
1.29 raeburn 4144: my ($groupname,$action,$cdom,$cnum,$gpterm,$ucgpterm,$crstype) = @_;
1.16 albertel 4145: my %sectioncount = &Apache::loncommon::get_sections($cdom,$cnum);
1.17 raeburn 4146: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.65 raeburn 4147: my %deleted_groups = &Apache::longroup::coursegroups($cdom,$cnum,undef,
4148: 'deleted_groups');
1.64 raeburn 4149: if (my $tmp = &Apache::lonnet::error(%deleted_groups)) {
4150: undef(%deleted_groups);
4151: &Apache::lonnet::logthis('Error retrieving groups: '.$tmp.' in '.$cnum.':'.$cdom);
4152: }
1.5 raeburn 4153: my %lt = &Apache::lonlocal::texthash (
1.29 raeburn 4154: igna => "Invalid $gpterm name",
4155: tgne => "The $gpterm name entered ",
4156: grna => "$ucgpterm names and section names used in a ".
4157: "$crstype must be unique.",
4158: isno => "is not a valid name.",
4159: gnmo => "$ucgpterm names may only contain letters, ".
4160: "numbers or underscores.",
4161: cnnb => "can not be used as it is the name of ",
4162: inth => " in this $crstype",
4163: thgr => "- does not correspond to the name of an ".
4164: "existing $gpterm",
1.5 raeburn 4165: );
1.15 albertel 4166:
1.42 albertel 4167: my $exitmsg = '<span class="LC_error">'.$lt{'igna'}.'</span><br /><br />'.
4168: $lt{'tgne'}.' "'.$groupname.'" ';
1.5 raeburn 4169: my $dupmsg = $lt{'grna'};
4170: my $earlyout;
4171: if (($groupname eq '') || ($groupname =~ /\W/)) {
4172: $earlyout = $exitmsg.$lt{'isno'}.'<br />'.$lt{'gnmo'};
4173: return $earlyout;
4174: }
1.16 albertel 4175: if (exists($sectioncount{$groupname})) {
4176: return $exitmsg.$lt{'cnnb'}.&mt('a section').$lt{'inth'}.
4177: '<br />'.$lt{'grna'};
1.5 raeburn 4178: }
1.64 raeburn 4179: if ($action eq 'create') {
4180: if (exists($curr_groups{$groupname})) {
4181: return $exitmsg.$lt{'cnnb'}.&mt('an existing [_1]',$gpterm).
4182: $lt{'inth'}.'.<br />'.$lt{'grna'};
4183: } elsif (exists($deleted_groups{$groupname})) {
4184: return $exitmsg.$lt{'cnnb'}.&mt('a [_1] which previously existed',$gpterm).
4185: $lt{'inth'}.'.<br />'.$lt{'grna'};
4186: }
1.5 raeburn 4187: } elsif ($action eq 'modify') {
4188: unless(exists($curr_groups{$groupname})) {
1.29 raeburn 4189: $earlyout = &mt('[_1] name:',$ucgpterm).' '.$groupname.$lt{'thgr'}.
4190: $lt{'inth'};
1.5 raeburn 4191: return $earlyout;
4192: }
4193: }
4194: return;
4195: }
4196:
4197: sub check_changes {
4198: my ($member_changes,$memchg) = @_;
4199: my %exclusions;
4200: @{$exclusions{'changefunc'}} = ('expire');
4201: @{$exclusions{'changepriv'}} = ('expire','changefunc');
4202:
4203: foreach my $change (@{$member_changes}) {
1.6 raeburn 4204: if ($change eq 'deletion') {
1.5 raeburn 4205: next;
4206: }
1.6 raeburn 4207: my @checks = ('deletion');
1.5 raeburn 4208: if (exists($exclusions{$change})) {
4209: push(@checks,@{$exclusions{$change}});
4210: }
4211: my @temp = ();
4212: foreach my $item (@{$$memchg{$change}}) {
4213: my $match = 0;
4214: foreach my $check (@checks) {
1.6 raeburn 4215: if (defined($$memchg{$check})) {
4216: if (ref(@{$$memchg{$check}}) eq 'ARRAY') {
4217: if (@{$$memchg{$check}} > 0) {
4218: if (grep/^$item$/,@{$$memchg{$check}}) {
4219: $match = 1;
4220: last;
4221: }
4222: }
1.5 raeburn 4223: }
4224: }
4225: }
4226: if ($match) {
4227: next;
4228: }
4229: push(@temp,$item);
4230: }
4231: @{$$memchg{$change}} = @temp;
4232: }
4233: }
1.3 raeburn 4234:
1.1 raeburn 4235: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>