Annotation of loncom/interface/loncoursegroups.pm, revision 1.101
1.24 www 1: # The LearningOnline Network with CAPA
2: #
1.101 ! bisitz 3: # $Id: loncoursegroups.pm,v 1.100 2009/05/11 16:10:33 bisitz 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.3 raeburn 57: "/adm/coursegroups:mdg:0:0:Cannot edit or view course 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.17 raeburn 540: unless ($role eq 'cc') {
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.46 albertel 1089: $states,$navbuttons,$gpterm,$ucgpterm);
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,
1122: \%stored);
1123: } elsif ($state eq 'result') {
1124: &delete_group($r,$cdom,$cnum,$groupname);
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,
1130: \%stored);
1131: } elsif ($state eq 'result') {
1132: &reenable_group($r,$cdom,$cnum,$groupname);
1133: }
1.64 raeburn 1134: }
1135: }
1136:
1137: sub verify_delete {
1138: my ($r,$groupname,$formname,$action,$page,$states,$stored) = @_;
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>'.
1144: '<li>'.&mt('The group ceases to be available either for viewing or for modification of group settings and membership.').'</li>'.
1145: '<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>'.
1146: '</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.'));
1147: my $prevtext = &mt('Go back');
1148: my $nexttext = &mt('Delete group');
1149: my $prev;
1.71 raeburn 1150: if ($env{'form.refpage'} eq 'cusr') {
1.64 raeburn 1151: $prev = 'view';
1152: }
1153: &display_navbuttons($r,$formname,$prev,$prevtext,
1154: $$states{$action}[$page+1],$nexttext);
1155: return;
1156: }
1157:
1158: sub delete_group {
1159: my ($r,$cdom,$cnum,$groupname) = @_;
1160: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
1161: $groupname);
1162: my $now = time;
1163: my $num_users = 0;
1164: my $num_fail = 0;
1165: my $num_ok = 0;
1166: my @deleted;
1167: my @undeleted;
1168: my %usersettings;
1.77 raeburn 1169: my $context = 'deletegroup';
1.64 raeburn 1170: foreach my $key (sort(keys(%membership))) {
1171: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
1172: my $user = $1;
1.65 raeburn 1173: my($end,$start,$userprivs) = split(/:/,$membership{$key},3);
1.64 raeburn 1174: if ($start != -1) {
1175: $num_users ++;
1.65 raeburn 1176: $usersettings{$groupname.':'.$user} = $now.':-1:'.$userprivs;
1.64 raeburn 1177: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,
1178: $groupname,$user,
1.76 raeburn 1179: $now,'-1',$userprivs,
1180: '',$context)
1.64 raeburn 1181: eq 'ok') {
1182: $num_ok ++;
1183: push(@deleted,$user);
1184: } else {
1185: push(@undeleted,$user);
1186: $num_fail ++;
1187: }
1188: }
1189: }
1190: }
1191: if ($num_ok > 0) {
1192: my $roster_result =
1193: &Apache::lonnet::modify_coursegroup_membership($cdom,$cnum,
1194: \%usersettings);
1195: }
1196: if ($num_fail > 0) {
1.79 bisitz 1197: $r->print('<div class="LC_error">'
1198: .&mt('Group deletion failed because deletion of [_1] out of [_2] members failed.'
1199: ,$num_fail,$num_users)
1200: .'</div>');
1.64 raeburn 1201:
1202: } else {
1203: my ($result,$message) =
1.65 raeburn 1204: &Apache::lonnet::toggle_coursegroup_status($cdom,$cnum,
1205: $groupname,'delete');
1.64 raeburn 1206: if ($result eq 'ok') {
1207: my $outcome = &modify_folders($cdom,$cnum,$groupname);
1208: if ($outcome eq '') {
1.79 bisitz 1209: $r->print('<div class="LC_success">'
1210: .&mt('Group successfully deleted.')
1211: .'</div>');
1.64 raeburn 1212: } else {
1.79 bisitz 1213: $r->print('<div class="LC_error">'
1214: .&mt("Although the group was deleted, an error occurred when removing"
1215: ." the group's folder from the 'Course Groups' folder: [_1]",$outcome)
1216: .'</div>');
1.64 raeburn 1217: }
1218: } else {
1.79 bisitz 1219: $r->print('<div class="LC_error">'
1220: .&mt('Group deletion failed.')
1221: .'</div>');
1.64 raeburn 1222: }
1.1 raeburn 1223: }
1.64 raeburn 1224: return;
1225: }
1226:
1.65 raeburn 1227: sub reenable_folder {
1228: my ($cdom,$cnum,$groupname,$description) = @_;
1229: my $outcome;
1230: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
1231: my $allgrpsmap = $crspath.'group_allfolders.sequence';
1.79 bisitz 1232: my $foldertitle = &mt('Course Folder -[_1]',$description);
1.65 raeburn 1233: my $mapurl = $crspath.'group_folder_'.
1234: $groupname.'.sequence';
1235: my ($errtext,$fatal)=&LONCAPA::map::mapread($allgrpsmap);
1236: if ($fatal) {
1.79 bisitz 1237: $outcome='<div class="LC_error">'
1238: .&mt('An error occurred when reading contents of parent folder to group:')
1239: ."<br />($allgrpsmap): $errtext"
1240: .'</div>';
1.65 raeburn 1241: } else {
1242: my $idx=&LONCAPA::map::getresidx($mapurl);
1243: $LONCAPA::map::resources[$idx] = $foldertitle.':'.$mapurl.
1244: ':false:normal:res';
1245: $LONCAPA::map::order[1+$#LONCAPA::map::order]=$idx;
1246: my ($outtext,$errtext) = &LONCAPA::map::storemap($allgrpsmap,1);
1247: if ($errtext) {
1.79 bisitz 1248: $outcome='<div class="LC_error">'
1249: .&mt('An error occurred when saving updated parent folder to group:'
1250: ,"<br />$allgrpsmap - $errtext")
1251: .'</div>';
1.65 raeburn 1252: } else {
1253: my ($furl,$ferr) =
1254: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1255: }
1256: }
1257: return $outcome;
1258: }
1259:
1.64 raeburn 1260: sub modify_folders {
1261: my ($cdom,$cnum,$groupname) = @_;
1.85 raeburn 1262: my ($outcome,$groupmap,$groupmapres,$map,$id,$src);
1.64 raeburn 1263: my $navmap = Apache::lonnavmaps::navmap->new();
1.85 raeburn 1264: if (!defined($navmap)) {
1265: $outcome = '<div class="LC_error">'.
1266: &mt('Error reading course contents.').' '.
1267: &mt('You need to re-initialize the course.').
1268: '</div>';
1269: return $outcome;
1270: }
1271: $groupmap = '/uploaded/'.$cdom.'/'.$cnum.'/'.'group_folder_'.
1.64 raeburn 1272: $groupname.'.sequence';
1.85 raeburn 1273: $groupmapres = $navmap->getResourceByUrl($groupmap);
1.64 raeburn 1274: if ($groupmapres) {
1.65 raeburn 1275: ($map,$id,$src)=&Apache::lonnet::decode_symb($groupmapres->symb());
1276: }
1277: undef($navmap);
1278: if ($map) {
1.64 raeburn 1279: $map = '/'.$map;
1280: my ($errtext,$fatal) = &LONCAPA::map::mapread($map);
1281: if ($fatal) {
1.79 bisitz 1282: $outcome='<div class="LC_error">'
1283: .&mt('An error occurred when reading contents of parent folder to group:')
1284: ."<br />($map): $errtext"
1285: .'</div>';
1.64 raeburn 1286: } else {
1287: my $idx = 0;
1288: my $grpidx;
1289: foreach my $item (@LONCAPA::map::order) {
1290: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$item]);
1291: $url=&LONCAPA::map::qtescape($url);
1292: if ($url eq $groupmap) {
1293: $grpidx = $idx;
1294: last;
1295: } else {
1296: $idx++;
1297: }
1298: }
1299:
1300: if ($grpidx ne '') {
1301: &LONCAPA::map::makezombie($LONCAPA::map::order[$grpidx]);
1302: for (my $i=$grpidx;$i<$#LONCAPA::map::order;$i++) {
1303: $LONCAPA::map::order[$i] = $LONCAPA::map::order[$i+1];
1304: }
1305: $#LONCAPA::map::order--;
1306: my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1);
1.65 raeburn 1307: if ($errtext) {
1.79 bisitz 1308: $outcome='<div class="LC_error">'
1309: .&mt('An error occurred when saving updated parent folder to group:')
1310: ."<br />$map - $errtext"
1311: .'</div>';
1.65 raeburn 1312: } else {
1313: my ($furl,$ferr) =
1314: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1315: }
1316: }
1317: }
1318: }
1319: return $outcome;
1320: }
1321:
1322: sub verify_reenable {
1323: my ($r,$groupname,$formname,$action,$page,$states,$stored) = @_;
1324: $r->print(&Apache::lonhtmlcommon::echo_form_input([]));
1.79 bisitz 1325: $r->print(&mt('You have requested enabling the previously deleted group [_1].'
1326: ,'<i>'.$stored->{'description'}.'</i>').
1.65 raeburn 1327: '<br /><br />'.&mt('When a deleted group is re-enabled the following occurs:').'<ul>'.
1328: '<li>'.&mt('Group settings and membership at the time the group was deleted are reinstated.').'</li>'.
1329: '<li>'.&mt('A group folder is added to the "Course Groups" folder which contains folders for all groups in the course.').'</li></ul>');
1330: my $prevtext = &mt('Go back');
1331: my $nexttext = &mt('Reenable group');
1332: my $prev;
1.71 raeburn 1333: if ($env{'form.refpage'} eq 'cusr') {
1.65 raeburn 1334: $prev = 'view';
1335: }
1336: &display_navbuttons($r,$formname,$prev,$prevtext,
1337: $$states{$action}[$page+1],$nexttext);
1338: return;
1339: }
1340:
1341: sub reenable_group {
1.66 raeburn 1342: my ($r,$cdom,$cnum,$groupname) = @_;
1.65 raeburn 1343: my %groups =
1344: &Apache::longroup::coursegroups($cdom,$cnum,$groupname,
1345: 'deleted_groups');
1.66 raeburn 1346: if (keys(%groups) == 0) {
1.79 bisitz 1347: $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 1348: return;
1349: }
1.65 raeburn 1350: my %groupinfo =
1351: &Apache::longroup::get_group_settings($groups{$groupname});
1352: my $defstart = $groupinfo{'startdate'};
1353: my $defend = $groupinfo{'enddate'};
1354: my $showstart = &Apache::lonlocal::locallocaltime($defstart);
1355: my $showend;
1356: if ($defend == 0) {
1357: $showend = &mt('No end date set');
1358: } else {
1359: $showend = &Apache::lonlocal::locallocaltime($defend);
1360: }
1361: my $description = &unescape($groupinfo{'description'});
1362: my $num_users = 0;
1363: my $num_ok = 0;
1364: my $num_fail = 0;
1.77 raeburn 1365: my $context = 'reenablegroup';
1.65 raeburn 1366: my (%usersettings,@enabled,@unenabled);
1367: my ($result,$message) =
1368: &Apache::lonnet::toggle_coursegroup_status($cdom,$cnum,$groupname,
1369: 'reenable');
1370: if ($result eq 'ok') {
1371: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
1372: $groupname);
1373: foreach my $key (sort(keys(%membership))) {
1374: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
1375: my $user = $1;
1376: my($end,$start,$userprivs) = split(/:/,$membership{$key},3);
1377: if (($start == -1) && ($end == $groupinfo{'modified'})) {
1378: $num_users ++;
1379: $usersettings{$groupname.':'.$user} = $defend.':'.
1380: $defstart.':'.
1381: $userprivs;
1382: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,
1383: $groupname,$user,
1384: $defend,$defstart,
1.76 raeburn 1385: $userprivs,'',
1386: $context) eq 'ok') {
1.65 raeburn 1387: $num_ok ++;
1388: push(@enabled,$user);
1389: } else {
1390: push(@unenabled,$user);
1391: $num_fail ++;
1392: }
1.64 raeburn 1393: }
1394: }
1395: }
1.65 raeburn 1396: if ($num_users > 0) {
1397: if ($num_ok > 0) {
1398: my $roster_result =
1399: &Apache::lonnet::modify_coursegroup_membership($cdom,$cnum,
1400: \%usersettings);
1401: if ($roster_result eq 'ok') {
1.79 bisitz 1402: $r->print('<div class="LC_success">'
1403: .&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)
1404: .'</div>');
1.65 raeburn 1405: }
1406: } else {
1.79 bisitz 1407: $r->print('<div class="LC_error">'
1408: .&mt('A problem occurred when trying to reinstate [_1] of the [_2] members of the pre-existing group.',$num_fail,$num_users)
1409: .'</div>');
1.65 raeburn 1410: }
1411: } else {
1.79 bisitz 1412: $r->print('<div class="LC_info">'
1413: .&mt('There were no group members to reinstate, as none were removed when the group was deleted.')
1414: .'</div>');
1.65 raeburn 1415: }
1416: my $outcome = &reenable_folder($cdom,$cnum,$groupname,$description);
1417: if ($outcome eq '') {
1.79 bisitz 1418: $r->print('<div class="LC_success">'
1419: .&mt('Group successfully re-enabled.')
1420: .'</div>');
1421: } else {
1422: $r->print('<div class="LC_error">'
1423: .&mt("Although the group was re-enabled, an error occurred when adding the group's folder to the 'Course Groups' folder: [_1]",$outcome)
1424: .'</div>');
1.65 raeburn 1425: }
1426: } else {
1.79 bisitz 1427: $r->print('<div class="LC_error">'
1428: .&mt('Re-enabling group failed.')
1429: .'</div>');
1.64 raeburn 1430: }
1.66 raeburn 1431: return;
1.1 raeburn 1432: }
1433:
1434: sub header {
1.39 albertel 1435: my ($bodytitle,$jscript,$action,$state,$page,$loaditems) = @_;
1.9 albertel 1436: my $start_page=
1.11 albertel 1437: &Apache::loncommon::start_page($bodytitle,
1438: '<script type="text/javascript">'.
1439: $jscript.'</script>',
1.39 albertel 1440: {'add_entries' => $loaditems,});
1.3 raeburn 1441: my $output = <<"END";
1.11 albertel 1442: $start_page
1.101 ! bisitz 1443: <form method="post" name="$state">
1.3 raeburn 1444:
1445: END
1446: if ($action eq 'create' || $action eq 'modify') {
1447: $output .= <<"END";
1448: <input type="hidden" name="action" value="$action" />
1449: <input type="hidden" name="state" value="" />
1450: <input type="hidden" name="origin" value="$state" />
1.5 raeburn 1451: <input type="hidden" name="page" value="$page" />
1.3 raeburn 1452: END
1453: }
1454: return $output;
1.1 raeburn 1455: }
1456:
1.3 raeburn 1457: sub onload_action {
1458: my ($action,$state) = @_;
1.13 albertel 1459: my %loaditems;
1.3 raeburn 1460: if ((defined($env{'form.origin'})) && ($action eq 'create') &&
1461: ($state eq 'pick_name' || $state eq 'pick_members' ||
1462: $state eq 'pick_privs')) {
1463: unless ($env{'form.origin'} eq '') {
1.13 albertel 1464: $loaditems{'onload'} =
1465: 'javascript:setFormElements(document.'.$state.')';
1.1 raeburn 1466: }
1467: }
1.5 raeburn 1468: if (($action eq 'modify') &&
1469: ($state eq 'change_settings' || $state eq 'change_members' ||
1.53 raeburn 1470: $state eq 'change_privs' || $state eq 'add_members')) {
1.13 albertel 1471: $loaditems{'onload'} =
1472: 'javascript:setFormElements(document.'.$state.')';
1.5 raeburn 1473: }
1.13 albertel 1474: return \%loaditems;
1.1 raeburn 1475: }
1476:
1477: sub footer {
1.9 albertel 1478: my $end_page = &Apache::loncommon::end_page();
1.1 raeburn 1479: return(<<ENDFOOT);
1.6 raeburn 1480: <input type="hidden" name="sortby" value="$env{'form.sortby'}" />
1.1 raeburn 1481: </form>
1.9 albertel 1482: $end_page
1.1 raeburn 1483: ENDFOOT
1484: }
1485:
1.3 raeburn 1486: sub build_members_list {
1487: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata) = @_;
1488: my %access = ();
1489: foreach my $role (@{$roles}) {
1490: %{$$users{$role}} = ();
1491: }
1492: foreach my $type (@{$types}) {
1493: $access{$type} = $type;
1494: }
1495: &Apache::loncommon::get_course_users($cdom,$cnum,\%access,$roles,
1.5 raeburn 1496: $sections,$users,$userdata);
1.3 raeburn 1497: return;
1498: }
1499:
1500: sub group_files {
1.74 raeburn 1501: my ($group,$portpath,$numfiles,$numdirs) = @_;
1.29 raeburn 1502: my $dirptr=16384;
1.74 raeburn 1503: my @dir_list=&Apache::portfolio::get_dir_list($portpath,undef,$group);
1.29 raeburn 1504: foreach my $line (@dir_list) {
1505: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
1506: if (($filename !~ /^\.\.?$/) && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/) && ($filename ne 'no_such_dir')) {
1507: if ($dirptr&$testdir) {
1.74 raeburn 1508: $portpath .= '/'.$filename;
1.29 raeburn 1509: $$numdirs ++;
1.74 raeburn 1510: &group_files($group,$portpath,$numfiles,$numdirs)
1.29 raeburn 1511: } else {
1512: $$numfiles ++;
1513: }
1514: }
1515: }
1.3 raeburn 1516: return;
1517: }
1518:
1519: sub group_members {
1.4 raeburn 1520: my ($cdom,$cnum,$group,$group_info) = @_;
1521: my %memberhash = &Apache::lonnet::get_group_membership($cdom,$cnum,$group);
1522: my $now = time;
1.60 raeburn 1523: my %lt = &Apache::lonlocal::texthash (
1524: active => 'active',
1525: previous => 'previous',
1526: future => 'future',
1527: );
1528: my %membercounts = (
1529: active => 0,
1530: previous => 0,
1531: future => 0,
1532: );
1.4 raeburn 1533: my $totalmembers = 0;
1534: foreach my $member (keys %memberhash) {
1535: $totalmembers ++;
1536: my ($end,$start) = split(/:/,$memberhash{$member});
1.6 raeburn 1537: unless ($start == -1) {
1538: if (($end!=0) && ($end<$now)) {
1.60 raeburn 1539: $membercounts{previous} ++;
1.6 raeburn 1540: } elsif (($start!=0) && ($start>$now)) {
1.60 raeburn 1541: $membercounts{future} ++;
1.6 raeburn 1542: } else {
1.60 raeburn 1543: $membercounts{active} ++;
1.6 raeburn 1544: }
1.4 raeburn 1545: }
1546: }
1547: if ($totalmembers == 0) {
1548: $$group_info{$group}{'totalmembers'} = 'None';
1549: } else {
1.60 raeburn 1550: foreach my $type ('active','previous','future') {
1551: $$group_info{$group}{'totalmembers'} .=
1552: &open_list_window($group,$type,$membercounts{$type},$lt{$type});
1553: }
1.4 raeburn 1554: }
1555: return 'ok';
1.3 raeburn 1556: }
1557:
1.60 raeburn 1558: sub open_list_window {
1559: my ($group,$status,$count,$text) = @_;
1560: my $entry;
1561: if ($count > 0) {
1.83 bisitz 1562: $entry = '<span class="LC_nobreak"><a href="javascript:openGroupRoster('.
1.60 raeburn 1563: "'$group','$status'".')">'.$text.'</a> - '.$count.
1.83 bisitz 1564: '</span><br />';
1.60 raeburn 1565: } else {
1.83 bisitz 1566: $entry = '<span class="LC_nobreak">'.$text.' - '.$count.'</span><br />';
1.60 raeburn 1567: }
1568: return $entry;
1569: }
1570:
1.3 raeburn 1571:
1.5 raeburn 1572: sub general_settings_form {
1.46 albertel 1573: my ($r,$cdom,$cnum,$action,$formname,$page,$functions,$tools,
1.5 raeburn 1574: $toolprivs,$fixedprivs,$sectioncount,$stored,$states,$navbuttons,
1.46 albertel 1575: $gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 1576: my ($nexttext,$prevtext);
1.42 albertel 1577: &groupsettings_options($r,$functions,$action,$formname,$stored,1,
1.29 raeburn 1578: $gpterm,$ucgpterm,$crstype);
1.41 albertel 1579: &access_date_settings($r,$action,$formname,$stored,2,$gpterm,$ucgpterm);
1.5 raeburn 1580: if ($action eq 'create') {
1.59 raeburn 1581: &membership_options($r,$cdom,$cnum,$action,$formname,$sectioncount,3,
1582: $gpterm,$ucgpterm);
1.5 raeburn 1583: $nexttext = $$navbuttons{'gtns'};
1584: } else {
1585: my @available = ();
1586: my @unavailable = ();
1587: &check_tools($functions,$tools,\@available,\@unavailable);
1588: @{$tools} = sort(keys(%{$functions}));
1.46 albertel 1589: &privilege_specificity($r,$action,3,$tools,$stored,$toolprivs,
1590: $fixedprivs,\@available,$formname,
1.92 schafran 1591: $gpterm,$ucgpterm,$functions);
1.44 albertel 1592: &mapping_options($r,$action,$formname,$page,$sectioncount,
1593: $states,$stored,$navbuttons,4,5,
1.58 raeburn 1594: $gpterm,$ucgpterm,$crstype,$cdom,$cnum);
1.5 raeburn 1595: $nexttext = $$navbuttons{'mose'};
1596: }
1597: $prevtext = $$navbuttons{'gtpp'};
1598: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
1599: $$states{$action}[$page+1],$nexttext);
1600: return;
1601: }
1602:
1603: sub groupsettings_options {
1.42 albertel 1604: my ($r,$functions,$action,$formname,$stored,$image,$gpterm,
1.29 raeburn 1605: $ucgpterm,$crstype) = @_;
1.1 raeburn 1606: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 1607: 'gdat' => "Group access start and end dates",
1608: 'gnde' => "Group name, title and available collaborative tools",
1609: 'desc' => 'Group Title',
1610: 'func' => 'Collaborative Tools',
1611: 'gnam' => 'Group Name',
1612: 'lett' => 'Letters, numbers and underscore only',
1613: 'doyo' => 'Different subsets of the chosen collaborative tools '.
1614: 'for different group members?',
1.97 bisitz 1615: 'gran' => 'Granularity',
1616: 'dquo' => 'Disk quota',
1.1 raeburn 1617: );
1.37 raeburn 1618: my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,$stored);
1.97 bisitz 1619: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$lt{'gnde'}));
1620:
1621: # Group Name
1622: $r->print(&Apache::lonhtmlcommon::start_pick_box()
1623: .&Apache::lonhtmlcommon::row_title($lt{'gnam'})
1624: );
1.5 raeburn 1625: if ($action eq 'create') {
1.97 bisitz 1626: $r->print('<input type="text" name="groupname" size="25" />'
1627: .' <span class="LC_nobreak">('
1628: .$lt{'lett'}.')</span>'
1629: );
1.5 raeburn 1630: } else {
1631: $r->print('<input type="hidden" name="groupname" value="'.
1632: $env{'form.groupname'}.'" />'.$env{'form.groupname'});
1633: }
1.97 bisitz 1634: $r->print(&Apache::lonhtmlcommon::row_closure());
1635:
1636: # Group Title
1637: $r->print(&Apache::lonhtmlcommon::row_title($lt{'desc'})
1638: .'<input type="text" name="description" size="40" value="" />'
1639: .&Apache::lonhtmlcommon::row_closure()
1640: );
1641:
1642: # Collaborative Tools
1.3 raeburn 1643: my $numitems = keys(%{$functions});
1644: my $halfnum = int($numitems/2);
1645: my $remnum = $numitems%2;
1646: if ($remnum) {
1647: $halfnum ++;
1648: }
1.5 raeburn 1649: my @allfunctions = sort(keys (%{$functions}));
1.97 bisitz 1650:
1651: $r->print(&Apache::lonhtmlcommon::row_title($lt{'func'})
1652: .'<div>'
1653: .'<input type="button" value="'.&mt('check all').'"'
1654: .' onclick="javascript:checkAll(document.'.$formname.'.tool)" />'
1655: .' <input type="button" value="'.&mt('uncheck all').'"'
1656: .' onclick="javascript:uncheckAll(document.'.$formname.'.tool)" />'
1657: .'</div>'
1658: .'<table cellpadding="5px"><tr>' # FIXME Get rid of inflexible table (-> float)
1659: );
1660: for (my $i=0; $i<@allfunctions; $i++) {
1661: $r->print('<td><label><span class="LC_nobreak">'
1662: .'<input type="checkbox" name="tool" value="'
1663: .$allfunctions[$i].'" /> '
1664: .&mt($$functions{$allfunctions[$i]})
1665: .'</span></label></td>'
1666: );
1667: if ($i == $halfnum - 1) {
1668: $r->print('</tr><tr>');
1669: }
1.3 raeburn 1670: }
1.97 bisitz 1671: $r->print('</tr></table>'
1672: .&Apache::lonhtmlcommon::row_closure()
1673: );
1674:
1675: # Granularity
1676: $r->print(&Apache::lonhtmlcommon::row_title($lt{'gran'})
1677: .$lt{'doyo'}.'<br />'
1678: .'<label>'
1679: .'<input type="radio" name="granularity" value="Yes" />'.&mt('Yes')
1680: .'</label> <label>'
1681: .'<input type="radio" name="granularity" value="No" checked="checked" />'.&mt('No')
1682: .'</label>'
1683: );
1.5 raeburn 1684: if ($action eq 'modify') {
1.97 bisitz 1685: $r->print(' <span class="LC_nobreak">('
1686: .&mt('Currently set to [_1].'
1687: ,'"'.&mt($$stored{'granularity'}).'"')
1688: .')</span>'
1689: );
1.5 raeburn 1690: }
1.97 bisitz 1691: $r->print(&Apache::lonhtmlcommon::row_closure());
1692:
1693: # Disk Quota
1694: $r->print(&Apache::lonhtmlcommon::row_title($lt{'dquo'}));
1.29 raeburn 1695: if ($action eq 'create') {
1.97 bisitz 1696: $r->print('<span class="LC_info">'
1697: .&mt('If you enable the group portfolio for the '.$gpterm
1698: .', allocate a disk quota.')
1699: .'</span>'
1700: );
1.29 raeburn 1701: } else {
1.96 weissno 1702: $r->print(&mt('Quota allocated to group portfolio:'));
1.29 raeburn 1703: }
1.97 bisitz 1704: $r->print(' '.&mt('[_1] Mb','<input type="text" name="quota" size="4" />'));
1.29 raeburn 1705: if ($action eq 'create') {
1.79 bisitz 1706: $r->print('<br />'
1707: .&mt('A total of [_1] Mb can be divided amongst all '.$gpterm.'s in the '
1708: .lc($crstype).', and [_2] Mb are currently unallocated.'
1709: ,$crsquota,sprintf("%.2f",$freespace))
1710: );
1.29 raeburn 1711: } else {
1712: $r->print(' ('.&mt('The quota is currently [_1] Mb',
1713: $$stored{'quota'}).').');
1714:
1.79 bisitz 1715: $r->print('<br />'
1716: .&mt('The quota can be increased to [_1] Mb, '
1717: .'by adding all unallocated space for '.$gpterm.'s in the '.lc($crstype).'.'
1718: ,sprintf("%.2f",$maxposs)));
1.29 raeburn 1719: }
1.97 bisitz 1720: $r->print(&Apache::lonhtmlcommon::row_closure(1));
1721:
1722: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1723:
1.5 raeburn 1724: return;
1725: }
1726:
1.37 raeburn 1727: sub get_quota_constraints {
1728: my ($action,$stored) = @_;
1729: my ($crsquota,$freespace,$maxposs);
1730: $crsquota = $env{'course.'.$env{'request.course.id'}.'.internal.coursequota'};
1731: if ($crsquota eq '') {
1732: $crsquota = 20;
1733: }
1734: $freespace = $crsquota - &Apache::longroup::sum_quotas();
1735: if ($action eq 'create') {
1736: $maxposs = $freespace;
1737: } else {
1738: $maxposs = $$stored{'quota'} + $freespace;
1739: }
1740: return ($crsquota,$freespace,$maxposs);
1741: }
1742:
1.5 raeburn 1743: sub membership_options {
1.59 raeburn 1744: my ($r,$cdom,$cnum,$action,$state,$sectioncount,$image,$gpterm,$ucgpterm)=@_;
1.29 raeburn 1745: my $crstype = &Apache::loncommon::course_type();
1.5 raeburn 1746: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 1747: 'pipa' => 'Build a list of users for selection of group members',
1748: 'gmem' => "Group membership selection list criteria:",
1.5 raeburn 1749: 'picr' => 'Pick the criteria to use to build a list of '.
1.29 raeburn 1750: lc($crstype).' users from which you will select ',
1.53 raeburn 1751: 'meof' => "members of the new group.",
1752: 'admg' => "additional members of the group.",
1.29 raeburn 1753: 'ifno' => "If you do not wish to add members when you first ".
1.53 raeburn 1754: "create the group, there is no need to pick any criteria.",
1755: 'asub' => "A subsequent step will also allow you to specify automatic adding/dropping of group members triggered by specified user role and section <i>changes</i> in the course.",
1.5 raeburn 1756: 'acty' => 'Access types',
1.29 raeburn 1757: 'coro' => $crstype.' roles',
1758: 'cose' => $crstype.' sections',
1.5 raeburn 1759: );
1760: my %status_types = (
1761: active => &mt('Currently has access'),
1762: previous => &mt('Previously had access'),
1763: future => &mt('Will have future access'),
1764: );
1.15 albertel 1765:
1.59 raeburn 1766: my @roles = ('st','cc','in','ta','ep','cr');
1.5 raeburn 1767:
1768: my @sections = keys(%{$sectioncount});
1769:
1.78 raeburn 1770: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$lt{'pipa'}).'
1.40 albertel 1771: <b>'.$lt{'gmem'}.'</b><br />'.$lt{'picr'});
1.5 raeburn 1772: if ($action eq 'create') {
1.21 raeburn 1773: $r->print($lt{'meof'}.'<br />'.$lt{'ifno'}.'<br />'.$lt{'asub'});
1.5 raeburn 1774: } else {
1.6 raeburn 1775: $r->print($lt{'admg'});
1.5 raeburn 1776: }
1777: $r->print('
1778: <br />
1779: <br />
1.40 albertel 1780: <table class="LC_status_selector">
1.3 raeburn 1781: <tr>
1.40 albertel 1782: <th>'.$lt{'acty'}.'</th>
1.53 raeburn 1783: <th>'.$lt{'coro'}.'</th>
1784: <th>'.$lt{'cose'}.'</th>
1785: </tr><tr><td>');
1.3 raeburn 1786: $r->print(&Apache::lonhtmlcommon::status_select_row(\%status_types));
1.40 albertel 1787: $r->print('</td><td>');
1.59 raeburn 1788: $r->print(&Apache::lonhtmlcommon::role_select_row(\@roles,undef,undef,1,$cdom,$cnum));
1.3 raeburn 1789: if (@sections > 0) {
1.5 raeburn 1790: @sections = sort {$a cmp $b} @sections;
1.31 albertel 1791: unshift(@sections,'none'); # Put 'no sections' next
1.17 raeburn 1792: unshift(@sections,'all'); # Put 'all' at the front of the list
1.53 raeburn 1793: } else {
1794: @sections = ('all','none');
1.3 raeburn 1795: }
1.53 raeburn 1796: $r->print('</td><td>'.
1797: §ions_selection(\@sections,'sectionpick').'</td>
1.3 raeburn 1798: </tr>
1.40 albertel 1799: </table>');
1.5 raeburn 1800: return;
1801: }
1802:
1803: sub sections_selection {
1804: my ($sections,$elementname) = @_;
1805: my $section_sel;
1806: my $numvisible = 4;
1807: if (@{$sections} < 4) {
1808: $numvisible = @{$sections};
1809: }
1810: foreach my $sec (@{$sections}) {
1.17 raeburn 1811: if ($sec eq 'all') {
1.53 raeburn 1812: $section_sel .= ' <option value="'.$sec.'">'.&mt('all sections').'</option>'."\n";
1.17 raeburn 1813: } elsif ($sec eq 'none') {
1.31 albertel 1814: $section_sel .= ' <option value="'.$sec.'">'.&mt('no section').'</option>'."\n";
1.5 raeburn 1815: } else {
1.31 albertel 1816: $section_sel .= ' <option value="'.$sec.'">'.$sec."</option>\n";
1.5 raeburn 1817: }
1818: }
1819: my $output = '
1.89 bisitz 1820: <select name="'.$elementname.'" multiple="multiple" size="'.$numvisible.'">
1.5 raeburn 1821: '.$section_sel.'
1822: </select>';
1823: return $output;
1824: }
1825:
1826: sub access_date_settings {
1.41 albertel 1827: my ($r,$action,$formname,$stored,$image,$gpterm,$ucgpterm) = @_;
1.80 bisitz 1828: my $sten = &mt("Default start and end dates for $gpterm access");
1.5 raeburn 1829: my $starttime = time;
1830: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1831: if ($action eq 'modify') {
1832: $starttime = $$stored{'startdate'};
1833: unless ($$stored{'enddate'} == 0) {
1834: $endtime = $$stored{'enddate'};
1835: }
1836: }
1.41 albertel 1837: my ($table) = &date_setting_table($starttime,$endtime,$formname);
1.80 bisitz 1838: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$sten).'
1.41 albertel 1839: '.$table.'
1840: ');
1.3 raeburn 1841: return;
1842: }
1843:
1.5 raeburn 1844: sub choose_members_form {
1.46 albertel 1845: my ($r,$cdom,$cnum,$action,$formname,$page,$groupname,$description,
1.29 raeburn 1846: $granularity,$quota,$startdate,$enddate,$tools,$fixedprivs,$toolprivs,
1.5 raeburn 1847: $functions,$users,$userdata,$idx,$stored,$states,$navbuttons,
1.46 albertel 1848: $gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 1849: my @regexps = ('user_','userpriv_','sec_');
1850: my %origmembers;
1.3 raeburn 1851: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.5 raeburn 1852: ['origin','action','state','page','member','specificity','branch',
1.7 raeburn 1853: 'defpriv','autorole','autoadd','autodrop','sortby','togglefunc'],
1.5 raeburn 1854: \@regexps));
1.29 raeburn 1855: my $earlyout = &validate_groupname($groupname,$action,$cdom,$cnum,$gpterm,
1856: $ucgpterm,$crstype);
1.5 raeburn 1857: if ($earlyout) {
1.47 raeburn 1858: $r->print($earlyout);
1.5 raeburn 1859: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1860: $$navbuttons{'gtps'});
1.3 raeburn 1861: return;
1.5 raeburn 1862: }
1863: my ($specimg,$memimg);
1864: my @available = ();
1865: my @unavailable = ();
1866: &check_tools($functions,$tools,\@available,\@unavailable);
1867: if ($action eq 'create') {
1.40 albertel 1868: &print_current_settings($r,$action,$functions,$startdate,$enddate,
1869: $groupname,$description,$granularity,$quota,
1870: \@available,\@unavailable,$gpterm,$ucgpterm);
1.5 raeburn 1871: $specimg = 4;
1872: $memimg = 5;
1873: } else {
1874: $specimg = 2;
1875: $memimg = 3;
1876: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
1877: $groupname);
1878: foreach my $key (sort(keys(%membership))) {
1879: if ($key =~ /^\Q$groupname\E:([^:]+):([^:]+)$/) {
1.6 raeburn 1880: my ($end,$start,@userprivs) = split(/:/,$membership{$key});
1881: unless ($start == -1) {
1882: my $uname = $1;
1883: my $udom = $2;
1884: my $user = $uname.':'.$udom;
1885: $origmembers{$user} = 1;
1886: }
1.5 raeburn 1887: }
1888: }
1889: }
1.46 albertel 1890: &privilege_specificity($r,$action,$specimg,$tools,$stored,$toolprivs,
1.29 raeburn 1891: $fixedprivs,\@available,$formname,$gpterm,$ucgpterm);
1.44 albertel 1892: my $newusers = &pick_new_members($r,$action,$formname,\@available,$idx,
1893: $stored,$memimg,$users,$userdata,
1894: $granularity,\%origmembers,$gpterm,
1895: $ucgpterm);
1.5 raeburn 1896: if ($newusers || $action eq 'create') {
1897: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1898: $$navbuttons{'gtps'},$$states{$action}[$page+1],
1899: $$navbuttons{'gtns'});
1900: } else {
1901: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1902: $$navbuttons{'gtps'});
1.3 raeburn 1903: }
1.5 raeburn 1904: return;
1905: }
1906:
1907: sub display_navbuttons {
1908: my ($r,$formname,$prev,$prevtext,$next,$nexttext) = @_;
1.42 albertel 1909: $r->print('<div class="LC_navbuttons">');
1.5 raeburn 1910: if ($prev) {
1911: $r->print('
1912: <input type="button" name="previous" value = "'.$prevtext.'"
1913: onclick="javascript:backPage(document.'.$formname.','."'".$prev."'".')"/>
1914: ');
1.64 raeburn 1915: } elsif ($prevtext) {
1916: $r->print('
1917: <input type="button" name="previous" value = "'.$prevtext.'"
1918: onclick="javascript:history.back()"/>
1919: ');
1.5 raeburn 1920: }
1921: if ($next) {
1922: $r->print('
1923: <input type="button" name="next" value="'.$nexttext.'"
1924: onclick="javascript:nextPage(document.'.$formname.','."'".$next."'".')" />');
1925: }
1.42 albertel 1926: $r->print('</div>');
1.5 raeburn 1927: }
1928:
1929: sub check_tools {
1930: my ($functions,$tools,$available,$unavailable) = @_;
1931: foreach my $item (sort(keys(%{$functions}))) {
1932: if (grep/^$item$/,@{$tools}) {
1933: push(@{$available},$item);
1934: } else {
1935: push(@{$unavailable},$item);
1936: }
1937: }
1938: return;
1939: }
1940:
1941: sub print_current_settings {
1.40 albertel 1942: my ($r,$action,$functions,$startdate,$enddate,$groupname,$description,
1943: $granularity,$quota,$available,$unavailable,$gpterm,$ucgpterm) = @_;
1.5 raeburn 1944:
1945: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 1946: grna => 'Group Name',
1947: desc => 'Group Title',
1948: grfn => "Collaborative Tools",
1.5 raeburn 1949: gran => 'Granularity',
1.29 raeburn 1950: quot => 'File quota',
1.5 raeburn 1951: dfac => 'Default access dates',
1.53 raeburn 1952: ygrs => "Your group selections - ",
1953: tfwa => "The following settings will apply to the group:",
1954: difn => 'Different collaborative tools<br />for different members:',
1.80 bisitz 1955: stda => 'Start date:',
1.5 raeburn 1956: enda => 'End date:',
1957: );
1.3 raeburn 1958: my $showstart = &Apache::lonlocal::locallocaltime($startdate);
1.5 raeburn 1959: my $showend;
1960: if ($enddate == 0) {
1961: $showend = &mt('No end date set');
1962: } else {
1963: $showend = &Apache::lonlocal::locallocaltime($enddate);
1964: }
1965: if ($action eq 'create') {
1966: $r->print('
1.42 albertel 1967: <div><span style="font-size: larger">'.$lt{'ygrs'}.'</span>
1.5 raeburn 1968: <br />'.$lt{'tfwa'}.'
1.40 albertel 1969: </div>');
1.5 raeburn 1970: }
1.40 albertel 1971: $r->print(&Apache::loncommon::start_data_table('LC_course_group_status').
1972: &Apache::loncommon::start_data_table_header_row());
1973: $r->print('
1974: <th>'.$lt{'grna'}.'</th>
1975: <th>'.$lt{'desc'}.'</th>
1976: <th>'.$lt{'grfn'}.'</th>
1977: <th>'.$lt{'gran'}.'</th>
1978: <th>'.$lt{'quot'}.'</th>
1979: <th>'.$lt{'dfac'}.'</th>
1980: ');
1981: $r->print(&Apache::loncommon::end_data_table_header_row().
1982: &Apache::loncommon::start_data_table_row('LC_data_table_dense'));
1.3 raeburn 1983: $r->print('
1.40 albertel 1984: <td valign="top">'.$groupname.'</td>
1985: <td valign="top">'.$description.'</td>
1.3 raeburn 1986: <td>
1987: ');
1.99 bisitz 1988:
1.5 raeburn 1989: if (@{$available} > 0) {
1.99 bisitz 1990: $r->print('<b>'.&mt('Available for assignment to members:').'</b>');
1991: $r->print('<ul>');
1.5 raeburn 1992: for (my $i=0; $i<@{$available}; $i++) {
1.99 bisitz 1993: $r->print('<li>'.&mt($$functions{$$available[$i]}).'</li>');
1.3 raeburn 1994: }
1.99 bisitz 1995: $r->print('</ul>');
1.3 raeburn 1996: }
1.99 bisitz 1997:
1.5 raeburn 1998: if (@{$unavailable} > 0) {
1.99 bisitz 1999: $r->print('<b>'.&mt('Unavailable for assignment:').'</b>');
2000: $r->print('<ul>');
2001: for (my $i=0; $i<@{$unavailable}; $i++) {
2002: $r->print('<li>'.&mt($$functions{$$unavailable[$i]}).'</li>');
1.3 raeburn 2003: }
1.99 bisitz 2004: $r->print('</ul>');
1.3 raeburn 2005: }
1.99 bisitz 2006:
1.79 bisitz 2007: my $quota_text=&mt('[_1] Mb',$quota);
1.80 bisitz 2008: my $granu_text=&mt($granularity);
1.3 raeburn 2009: $r->print(<<"END");
2010: </td>
1.80 bisitz 2011: <td valign="top"><b>$lt{'difn'}</b> $granu_text</td>
1.79 bisitz 2012: <td valign="top">$quota_text</td>
1.40 albertel 2013: <td valign="top"><b>$lt{'stda'}</b> $showstart<br />
2014: <b>$lt{'enda'}</b> $showend
1.3 raeburn 2015: </td>
2016: END
1.40 albertel 2017: $r->print(&Apache::loncommon::end_data_table_row().
2018: &Apache::loncommon::end_data_table());
1.5 raeburn 2019: return;
2020: }
2021:
2022: sub pick_new_members {
1.44 albertel 2023: my ($r,$action,$formname,$available,$idx,$stored,$img,$users,$userdata,
2024: $granularity,$origmembers,$gpterm,$ucgpterm) = @_;
1.5 raeburn 2025: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 2026: 'gpme' => "Group membership",
1.5 raeburn 2027: 'addm' => 'Add members',
1.53 raeburn 2028: 'setf' => 'Assign collaborative tools',
2029: 'func' => 'Tools',
2030: 'nome' => 'No members to add at this time, as there are no users '.
2031: 'matching the specified type(s), role(s) and section(s).',
1.29 raeburn 2032: 'nnew' => "There are no users to add as new members, as all users".
1.53 raeburn 2033: " matching the specified type(s), role(s), and ".
2034: "section(s) are already affiliated with this group.",
1.79 bisitz 2035: 'yoma' => "You may need to use the 'modify existing, past or ".
2036: "future members' page if you need to re-enable ".
2037: "or activate access for previous or future members.",
1.5 raeburn 2038: );
2039: my %members;
2040: my $totalusers = 0;
2041: my $newusers = 0;
1.3 raeburn 2042: foreach my $role (keys(%{$users})) {
2043: foreach my $user (keys(%{$$users{$role}})) {
1.5 raeburn 2044: $totalusers ++;
2045: if (ref($origmembers) eq 'HASH') {
2046: if (exists($$origmembers{$user})) {
2047: next;
2048: }
2049: }
1.3 raeburn 2050: unless (defined($members{$user})) {
2051: @{$members{$user}} = @{$$userdata{$user}};
1.5 raeburn 2052: $newusers ++;
1.3 raeburn 2053: }
2054: }
2055: }
2056: if (keys(%members) > 0) {
1.5 raeburn 2057: if (@{$available} > 0 && $granularity eq 'Yes') {
2058: $r->print(&check_uncheck_tools($r,$available));
2059: }
2060: }
1.78 raeburn 2061: $r->print(&Apache::lonhtmlcommon::topic_bar($img,$lt{'gpme'}));
1.5 raeburn 2062: if (keys(%members) > 0) {
2063: $r->print('
1.3 raeburn 2064: <table>
1.5 raeburn 2065: <tr>');
2066: &check_uncheck_buttons($r,$formname,'member',$lt{'addm'});
2067: if (@{$available} > 0 && $granularity eq 'Yes') {
1.48 albertel 2068: $r->print('<td>
1.5 raeburn 2069: <fieldset><legend><b>'.$lt{'setf'}.'</b></legend>
1.83 bisitz 2070: <span class="LC_nobreak">
1.80 bisitz 2071: <input type="button" value="'.&mt('check all').'"
1.5 raeburn 2072: onclick="javascript:checkAllTools(document.'.$formname.')" />
2073:
1.80 bisitz 2074: <input type="button" value="'.&mt('uncheck all').'"
1.3 raeburn 2075: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
1.83 bisitz 2076: </span>
1.48 albertel 2077: </fieldset></td>');
1.3 raeburn 2078: }
2079: $r->print('</tr></table>
2080: ');
1.43 albertel 2081: $r->print(&Apache::loncommon::start_data_table().
2082: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 2083: $r->print('
1.43 albertel 2084: <th>'.&mt('Add?').'</b></td>
2085: <th><a href="javascript:changeSort('."'fullname'".')">'.&mt('Name').'</a></td>
2086: <th><a href="javascript:changeSort('."'username'".')">'.&mt('Username').'</a></td>
2087: <th><a href="javascript:changeSort('."'domain'".')">'.&mt('Domain').'</a></td>
2088: <th><a href="javascript:changeSort('."'id'".')">'.&mt('ID').'</a></td>
2089: <th><a href="javascript:changeSort('."'section'".')">'.&mt('Section').'</a></td>
1.5 raeburn 2090: ');
2091: if (@{$available} > 0) {
1.43 albertel 2092: $r->print('<th>'.$lt{'func'}.'</th>');
1.3 raeburn 2093: }
1.43 albertel 2094: $r->print(&Apache::loncommon::end_data_table_header_row());
1.5 raeburn 2095: if (@{$available} > 0) {
2096: if ($granularity eq 'Yes') {
1.43 albertel 2097: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense LC_data_table_highlight').'
1.35 raeburn 2098: <td colspan="6"> </td>
1.83 bisitz 2099: <td align="center"><span class="LC_nobreak"><b>'.&mt('All:').'</b> ');
1.5 raeburn 2100: foreach my $tool (@{$available}) {
1.7 raeburn 2101: $r->print('<label><input type="checkbox" name="togglefunc" '.
2102: 'onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
2103: ' value="'.$tool.'">'.'<b>'.$tool.'</b></label> ');
1.5 raeburn 2104: }
1.83 bisitz 2105: $r->print('</span></td></tr>');
1.5 raeburn 2106: }
2107: }
1.3 raeburn 2108: my %Sortby = ();
2109: foreach my $user (sort(keys(%members))) {
2110: if ($env{'form.sortby'} eq 'fullname') {
2111: push(@{$Sortby{$members{$user}[$$idx{fullname}]}},$user);
2112: } elsif ($env{'form.sortby'} eq 'username') {
2113: push(@{$Sortby{$members{$user}[$$idx{uname}]}},$user);
2114: } elsif ($env{'form.sortby'} eq 'domain') {
2115: push(@{$Sortby{$members{$user}[$$idx{udom}]}},$user);
2116: } elsif ($env{'form.sortby'} eq 'id') {
2117: push(@{$Sortby{$members{$user}[$$idx{id}]}},$user);
1.31 albertel 2118: } elsif ($env{'form.sortby'} eq 'section') {
2119: push(@{$Sortby{$members{$user}[$$idx{section}]}},$user);
1.3 raeburn 2120: } else {
2121: push(@{$Sortby{$members{$user}[$$idx{fullname}]}},$user);
2122: }
2123: }
2124: foreach my $key (sort(keys(%Sortby))) {
2125: foreach my $user (@{$Sortby{$key}}) {
2126: my $id = $members{$user}[$$idx{id}];
2127: my $fullname = $members{$user}[$$idx{fullname}];
2128: my $udom = $members{$user}[$$idx{udom}];
2129: my $uname = $members{$user}[$$idx{uname}];
1.31 albertel 2130: my $section = $members{$user}[$$idx{section}];
1.43 albertel 2131: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense').
2132: '<td align="right"><input type="checkbox" name="member" value="'.$user.'" /></td>'.
2133: '<td>'.$fullname.'</td>'.
2134: '<td>'.$uname.'</td>'.
2135: '<td>'.$udom.'</td>'.
2136: '<td>'.$id.'</td>'.
2137: '<td>'.$section.'</td>');
1.5 raeburn 2138: if (@{$available} > 0) {
1.83 bisitz 2139: $r->print('<td align="center"><span class="LC_nobreak">'.
1.5 raeburn 2140: ' ');
2141: foreach my $tool (@{$available}) {
2142: if ($granularity eq 'Yes') {
1.3 raeburn 2143: $r->print('<input type="checkbox" name="user_'.
2144: $tool.'" value="'.$user.'" />'.$tool.' ');
2145: } else {
2146: $r->print('<input type="hidden" name="user_'.
2147: $tool.'" value="'.$user.'" />'.$tool.' ');
2148: }
2149: }
1.83 bisitz 2150: $r->print('</span></td>');
1.3 raeburn 2151: }
1.43 albertel 2152: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.3 raeburn 2153: }
2154: }
1.43 albertel 2155: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 2156: } else {
2157: if ($totalusers > 0) {
2158: $r->print($lt{'nnew'}.'<br /><br />'.$lt{'yoma'});
2159: } else {
2160: $r->print($lt{'nome'});
2161: }
2162: }
2163: return $newusers;
2164: }
2165:
2166: sub privilege_specificity {
1.46 albertel 2167: my ($r,$action,$img,$tools,$stored,$toolprivs,$fixedprivs,$available,
1.92 schafran 2168: $formname,$gpterm,$ucgpterm,$functions) = @_;
1.5 raeburn 2169: my %lt = &Apache::lonlocal::texthash (
1.53 raeburn 2170: 'uprv' => 'User privileges for collaborative tools',
2171: 'frty' => 'For each collaborative tool you have chosen to include, '.
2172: 'there is a set of core privileges which all group members '.
2173: 'assigned use of the tool will receive.',
2174: 'thar' => 'For some tools there are also additional optional '.
2175: 'privileges which can be set.',
2176: 'plch' => 'Choose one of the following:',
2177: 'fort' => 'For the collaborative tools you have chosen to include '.
2178: 'only core privileges are available, '.
2179: 'so there are no optional privileges to assign.',
2180: 'eaty' => 'Each collaborative tool includes core '.
2181: 'privileges assigned to all members with access to the '.
2182: 'tool. Some tools may also feature additional privileges '.
1.5 raeburn 2183: 'which can be set for specific members.',
1.53 raeburn 2184: 'cutg' => 'Currently the group is configured ',
2185: 'sdif' => 'so different members can receive different optional privileges for a particular tool.',
2186: 'sall' => 'so all members will receive the same optional privileges for a particular tool.',
2187: 'algm' => 'All group members will receive the same privileges for any tool assigned to them, including the default set of optional privileges.',
2188: 'smgp' => 'Different group members may receive different privileges from '.
2189: 'others for the tools they have been assigned.',
2190: 'thwi' => 'These will be the privileges all group members receive for a particular assigned tool, '.
2191: 'if you selected the first option above.',
1.29 raeburn 2192: 'thes' => "These will be the privileges given to members assigned ".
1.53 raeburn 2193: "in the future via automatic group assignment ".
2194: "for users who receive specific sections/roles in the course ",
2195: 'asyo' => "As you have chosen not to include any collaborative tools ".
2196: "in the group, no default optional privileges need to be set.",
2197: 'plin' => 'Indicate which <b>optional</b> privileges members '.
2198: 'will receive by default for a specific tool.',
1.5 raeburn 2199: 'oppr' => 'Optional privileges',
2200: 'defp' => 'The default privileges new members will receive are:',
2201: );
2202: my $totaloptionalprivs = 0;
2203: foreach my $tool (@{$tools}) {
2204: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2205: if (!exists($$fixedprivs{$tool}{$priv})) {
2206: $totaloptionalprivs ++;
2207: }
2208: }
2209: }
1.78 raeburn 2210: $r->print(&Apache::lonhtmlcommon::topic_bar($img,$lt{'uprv'}));
1.5 raeburn 2211: if ((($action eq 'create') && (@{$available} > 0)) ||
1.55 raeburn 2212: (($action eq 'modify') && ($formname eq 'change_settings'))) {
1.5 raeburn 2213: my %specific = (
2214: 'No' => 'checked="checked"',
2215: 'Yes' => '',
2216: );
2217: if ($action eq 'create') {
2218: $r->print($lt{'frty'}.'<br />');
2219: if ($totaloptionalprivs) {
1.53 raeburn 2220: $r->print($lt{'thar'}.'<br /><br />'.$lt{'plch'});
1.5 raeburn 2221: } else {
2222: $r->print($lt{'fort'});
2223: }
2224: } else {
2225: $r->print($lt{'eaty'}.' '.$lt{cutg});
2226: if ($$stored{'specificity'} eq 'Yes') {
2227: $r->print($lt{'sdif'});
2228: $specific{'Yes'} = $specific{'No'};
2229: $specific{'No'} = '';
2230: } else {
2231: $r->print($lt{'sall'});
2232: }
2233: }
2234: if ($totaloptionalprivs) {
2235: $r->print('
1.53 raeburn 2236: <br />
1.83 bisitz 2237: <label><span class="LC_nobreak"><input type="radio" name="specificity" value="No" '.$specific{'No'}.' /> '.$lt{'algm'}.'</span></label><br />
2238: <label><span class="LC_nobreak"><input type="radio" name="specificity" value="Yes" '.$specific{'Yes'}.' /> '.$lt{'smgp'}.'</span></label><br /><br />');
1.5 raeburn 2239: } else {
2240: $r->print('<input type="hidden" name="specificity" value="No" />');
2241: }
2242: if ($totaloptionalprivs) {
1.40 albertel 2243: $r->print($lt{'plin'});
1.5 raeburn 2244: if ($action eq 'create') {
1.53 raeburn 2245: $r->print('<br />'.$lt{'thwi'});
1.5 raeburn 2246: }
2247: $r->print('<br />'.$lt{'thes'});
2248: if ($action eq 'create') {
2249: $r->print('('.&mt('if enabled on the next page').').');
2250: } else {
2251: $r->print('('.&mt('if enabled below').').');
2252: }
2253: $r->print('<br /><br />
1.40 albertel 2254: <table><tr>');
1.5 raeburn 2255: &check_uncheck_buttons($r,$formname,'defpriv',$lt{'oppr'});
2256: $r->print('
2257: </tr>
2258: </table>
1.3 raeburn 2259: <br />
2260: ');
1.5 raeburn 2261: } else {
1.40 albertel 2262: $r->print($lt{'algm'}.'<br /><br />');
1.3 raeburn 2263: }
1.42 albertel 2264: &default_privileges($r,$action,$tools,$toolprivs,$fixedprivs,
1.92 schafran 2265: $available,$functions);
1.3 raeburn 2266: } else {
1.5 raeburn 2267: if ($action eq 'create') {
2268: $r->print($lt{'asyo'});
1.55 raeburn 2269: $r->print('<input type="hidden" name="specificity" value="No" />');
1.5 raeburn 2270: } elsif ($action eq 'modify' && $formname eq 'pick_members') {
2271: my @defprivs;
2272: if (ref($$stored{'defpriv'}) eq 'ARRAY') {
2273: @defprivs = @{$$stored{'defpriv'}};
2274: }
2275: $r->print($lt{'eaty'}.' '.$lt{cutg});
2276: if ($$stored{'specificity'} eq 'Yes') {
2277: $r->print($lt{'sdif'});
2278: } else {
2279: $r->print($lt{'sall'});
2280: }
2281: $r->print(' '.$lt{'defp'}.'<br /><br />');
1.45 albertel 2282: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 2283: }
1.3 raeburn 2284: }
2285: return;
2286: }
2287:
1.5 raeburn 2288: sub default_privileges {
1.92 schafran 2289: my ($r,$action,$tools,$toolprivs,$fixedprivs,$available,$functions) = @_;
1.5 raeburn 2290: my %lt = &Apache::lonlocal::texthash(
2291: 'addp' => 'Additional privileges',
2292: 'fixp' => 'Fixed privileges',
2293: 'oppr' => 'Optional privileges',
1.53 raeburn 2294: 'func' => 'Collaborative Tool',
1.5 raeburn 2295: );
1.42 albertel 2296: $r->print(&Apache::lonhtmlcommon::start_pick_box('LC_group_priv_box').
2297: &Apache::lonhtmlcommon::row_title($lt{'func'},undef,
1.90 schafran 2298: 'LC_groups_functionality'));
1.92 schafran 2299: my @tableHeader;
2300: foreach my $key (sort(keys(%{$functions}))){
2301: push (@tableHeader,&mt(${$functions}{$key}));
2302: }
2303: $r->print(join('</td><td class="LC_groups_functionality">', @tableHeader));
1.42 albertel 2304: $r->print(&Apache::lonhtmlcommon::row_closure(1));
2305: my $fixed = '';
2306: my $dynamic = '';
1.3 raeburn 2307: foreach my $tool (@{$tools}) {
1.5 raeburn 2308: my $privcount = 0;
1.42 albertel 2309: if ($dynamic ne '') {
2310: $dynamic .= '</td><td class="LC_groups_optional">';
2311: }
2312: $dynamic .= '<table class="LC_group_priv"><tr>';
1.5 raeburn 2313: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2314: if (exists($$fixedprivs{$tool}{$priv})) {
1.42 albertel 2315: if ($fixed ne '') {
2316: $fixed .= '</td><td class="LC_groups_fixed">';
2317: }
1.79 bisitz 2318: $fixed .= '<input type="hidden" name="defpriv" value="'.$priv.'" />'
1.90 schafran 2319: .'<span class="LC_nobreak">'.&mt($$toolprivs{$tool}{$priv}).' ';
1.5 raeburn 2320: if ($action eq 'modify') {
1.42 albertel 2321: if (grep(/^$tool$/,@{$available})) {
1.5 raeburn 2322: $fixed .= '<small>'.&mt('(on)').'<small> ';
2323: } else {
2324: $fixed .= '<small>'.&mt('(off)').'<small> ';
1.3 raeburn 2325: }
2326: }
1.79 bisitz 2327: $fixed .= '</span>';
1.5 raeburn 2328: } else {
1.42 albertel 2329: $privcount++;
1.5 raeburn 2330: if ($privcount == 3) {
2331: $dynamic .= '</tr>
1.42 albertel 2332: <tr>'."\n";
1.5 raeburn 2333: }
1.90 schafran 2334: $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 2335: }
2336: }
1.42 albertel 2337: if ($privcount == 0) {
1.79 bisitz 2338: $dynamic .= '<td>'.&mt('None').'</td>'."\n";
1.5 raeburn 2339: }
2340: if ($privcount < 3) {
1.53 raeburn 2341: $dynamic .= '<td> </td>'."\n";
1.5 raeburn 2342: } elsif ($privcount%2) {
2343: $dynamic = '<td> </td>'."\n";
2344: }
1.42 albertel 2345: $dynamic .= '</tr></table>';
1.3 raeburn 2346: }
1.42 albertel 2347: $r->print(&Apache::lonhtmlcommon::row_title($lt{'fixp'},undef,
2348: 'LC_groups_fixed').
2349: $fixed.
2350: &Apache::lonhtmlcommon::row_closure(1));
2351: $r->print(&Apache::lonhtmlcommon::row_title($lt{'oppr'},undef,
2352: 'LC_groups_optional').
2353: $dynamic.
2354: &Apache::lonhtmlcommon::end_pick_box());
1.5 raeburn 2355: $r->print('<br />');
2356: return;
1.42 albertel 2357:
1.5 raeburn 2358: }
2359:
2360: sub display_defprivs {
1.45 albertel 2361: my ($r,$tools,$toolprivs,$defprivs) = @_;
2362: my $function = &Apache::loncommon::get_users_function();
2363: my $tabcol = &Apache::loncommon::designparm($function.'.tabbg');
2364: my $rowColor1 = "#dddddd";
2365: my $rowColor2 = "#eeeeee";
1.5 raeburn 2366: my %lt = &Apache::lonlocal::texthash(
2367: 'priv' => 'Privileges',
1.53 raeburn 2368: 'func' => 'Collaborative Tool',
1.5 raeburn 2369: );
2370: $r->print(&Apache::lonhtmlcommon::start_pick_box());
2371: $r->print('<tr>');
2372: my $numrows = 0;
2373: my %currprivs;
2374: foreach my $tool (@{$tools}) {
2375: @{$currprivs{$tool}} = ();
2376: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2377: if (ref($defprivs) eq 'ARRAY') {
1.45 albertel 2378: if (grep(/^\Q$priv\E$/,@{$defprivs})) {
1.5 raeburn 2379: push(@{$currprivs{$tool}},$priv);
2380: }
1.3 raeburn 2381: }
2382: }
1.5 raeburn 2383: my $rowcount = int(@{$currprivs{$tool}}/3);
2384: if (@{$currprivs{$tool}}%3 > 0) {
2385: $rowcount ++;
2386: }
2387: if ($rowcount > $numrows) {
2388: $numrows = $rowcount;
2389: }
2390: }
2391: my @rowCols = ($rowColor1,$rowColor2);
2392: foreach my $tool (@{$tools}) {
2393: $r->print('<td align="center" valign="top">
2394: <table cellspacing="0" cellpadding="5">
2395: <tr bgcolor="#cccccc">
2396: <td colspan="3" align="center"><b>'.$tool.'</b></td>
2397: </tr>
2398: ');
2399: my $rownum = 1;
2400: my $privcount = 0;
2401: $r->print('<tr bgcolor="'.$rowColor1.'">');
2402: foreach my $priv (@{$currprivs{$tool}}) {
2403: $privcount ++;
2404: if ($privcount%4 == 0) {
2405: $rownum ++;
2406: my $bgcol = $rownum%2;
2407: $r->print('</tr>
2408: <tr bgcolor="'.$rowCols[$bgcol].'">'."\n");
2409: }
2410: $r->print('<td>'.$$toolprivs{$tool}{$priv}.'</td>'."\n");
2411: }
2412: if ($privcount%3 > 0) {
2413: my $emptycells = 3-($privcount%3);
2414: while($emptycells > 0) {
2415: $r->print('<td> </td>'."\n");
2416: $emptycells --;
2417: }
2418: }
2419: while ($rownum < $numrows) {
2420: $rownum ++;
2421: my $bgcol = $rownum%2;
2422: $r->print('<tr bgcolor="'.$rowCols[$bgcol].'"><td colspan="3"> </td></tr>');
1.3 raeburn 2423: }
1.5 raeburn 2424: $r->print('</table>'."\n".'</td>');
2425: }
2426: $r->print('</tr>'."\n");
2427: $r->print(&Apache::lonhtmlcommon::end_pick_box());
2428: $r->print('<br />');
2429: return;
1.3 raeburn 2430: }
1.5 raeburn 2431:
2432:
2433: sub change_members_form {
1.48 albertel 2434: my ($r,$cdom,$cnum,$action,$formname,$page,$groupname,$description,
1.5 raeburn 2435: $startdate,$enddate,$tools,$fixedprivs,$functions,$users,$userdata,
1.48 albertel 2436: $granularity,$quota,$specificity,$idx,$states,$navbuttons,$gpterm,
2437: $ucgpterm) = @_;
1.5 raeburn 2438: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 2439: grse => "$ucgpterm settings",
2440: mogm => "Modify $gpterm membership",
1.5 raeburn 2441: );
2442: my @regexps = ('user_','userpriv_');
2443: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2444: ['origin','action','state','page','expire','deletion',
1.7 raeburn 2445: 'reenable','activate','changepriv','sortby',
2446: 'togglefunc'],\@regexps));
1.5 raeburn 2447: my $rowimg = 1;
2448: my @available = ();
2449: my @unavailable = ();
2450: &check_tools($functions,$tools,\@available,\@unavailable);
2451: my $nexttext = $$navbuttons{'gtns'};
2452: my $prevtext = $$navbuttons{'gtpp'};
2453: $r->print('
1.3 raeburn 2454: <br />
1.5 raeburn 2455: ');
1.78 raeburn 2456: $r->print(&Apache::lonhtmlcommon::topic_bar(1,$lt{'grse'}));
1.40 albertel 2457: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2458: $groupname,$description,$granularity,$quota,
2459: \@available,\@unavailable,$gpterm,$ucgpterm);
1.78 raeburn 2460: $r->print(&Apache::lonhtmlcommon::topic_bar(2,$lt{'mogm'}));
1.53 raeburn 2461: my $numcurrent = ¤t_membership($r,$cdom,$cnum,$formname,$groupname,
2462: \@available,\@unavailable,$fixedprivs,
2463: $granularity,$specificity);
2464: if ($numcurrent > 0) {
2465: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2466: $$states{$action}[$page+1],$nexttext);
2467: } else {
2468: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext);
2469: }
1.5 raeburn 2470: return;
2471: }
2472:
2473: sub current_membership {
1.48 albertel 2474: my ($r,$cdom,$cnum,$formname,$groupname,$available,$unavailable,
2475: $fixedprivs,$granularity,$specificity) = @_;
1.5 raeburn 2476: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
2477: $groupname);
2478: my %lt = &Apache::lonlocal::texthash(
1.6 raeburn 2479: 'actn' => 'Action?',
2480: 'name' => 'Name',
2481: 'usnm' => 'Username',
2482: 'doma' => 'Domain',
2483: 'stda' => 'Start Date',
2484: 'enda' => 'End Date',
1.5 raeburn 2485: 'expi' => 'Expire',
2486: 'reen' => 'Re-enable',
2487: 'acti' => 'Activate',
2488: 'dele' => 'Delete',
1.53 raeburn 2489: 'curf' => 'Current Tool Set',
1.5 raeburn 2490: 'chpr' => 'Change Privileges'
2491: );
1.52 raeburn 2492: my ($current,$num_items,$hastools,$addtools) =
1.36 raeburn 2493: &Apache::longroup::group_memberlist($cdom,$cnum,$groupname,$fixedprivs,
2494: $available);
1.53 raeburn 2495: my $numcurrent = scalar(keys(%{$current}));
2496: if ($numcurrent > 0) {
1.36 raeburn 2497: $r->print('
1.5 raeburn 2498: <table>
2499: <tr>');
1.52 raeburn 2500: if ($num_items->{'active'}) {
1.36 raeburn 2501: &check_uncheck_buttons($r,$formname,'expire',$lt{'expi'});
2502: }
1.52 raeburn 2503: if ($num_items->{'previous'}) {
1.36 raeburn 2504: &check_uncheck_buttons($r,$formname,'reenable',$lt{'reen'});
2505: }
1.52 raeburn 2506: if ($num_items->{'future'}) {
1.36 raeburn 2507: &check_uncheck_buttons($r,$formname,'activate',$lt{'acti'});
2508: }
2509: &check_uncheck_buttons($r,$formname,'deletion',$lt{'dele'});
2510: if (@{$available} > 0) {
2511: if ($specificity eq 'Yes') {
2512: &check_uncheck_buttons($r,$formname,'changepriv',$lt{'chpr'});
1.5 raeburn 2513: }
1.36 raeburn 2514: if ($granularity eq 'Yes') {
2515: $r->print(&check_uncheck_tools($r,$available));
2516: $r->print('
1.5 raeburn 2517: <td>
1.83 bisitz 2518: <span class="LC_nobreak">
1.5 raeburn 2519: <fieldset><legend><b>'.$lt{'curf'}.'</b></legend>
1.80 bisitz 2520: <input type="button" value="'.&mt('check all').'"
1.5 raeburn 2521: onclick="javascript:checkAllTools(document.'.$formname.')" />
2522:
1.80 bisitz 2523: <input type="button" value="'.&mt('uncheck all').'"
1.5 raeburn 2524: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
2525: </fieldset>
1.83 bisitz 2526: </span>
1.5 raeburn 2527: </td>
2528: ');
1.3 raeburn 2529: }
1.36 raeburn 2530: }
2531: $r->print(<<"END");
1.5 raeburn 2532: </tr>
2533: </table>
1.48 albertel 2534: <br />
1.5 raeburn 2535: END
1.48 albertel 2536: $r->print(&Apache::loncommon::start_data_table().
2537: &Apache::loncommon::start_data_table_header_row());
1.36 raeburn 2538: $r->print(<<"END");
1.48 albertel 2539: <th>$lt{'actn'}</th>
2540: <th><a href="javascript:changeSort('fullname')">$lt{'name'}</a></th>
2541: <th><a href="javascript:changeSort('username')">$lt{'usnm'}</a></th>
2542: <th><a href="javascript:changeSort('domain')">$lt{'doma'}</a></th>
2543: <th><a href="javascript:changeSort('id')">ID</a></th>
2544: <th><a href="javascript:changeSort('start')">$lt{'stda'}</a></th>
2545: <th><a href="javascript:changeSort('end')">$lt{'enda'}</a></th>
1.5 raeburn 2546: END
1.36 raeburn 2547: my $colspan = 0;
2548: if ($hastools) {
1.48 albertel 2549: $r->print('<th>'.$lt{'curf'}.'</th>');
2550: $colspan++;
1.36 raeburn 2551: }
2552: if ($addtools) {
1.53 raeburn 2553: $r->print('<th>'.&mt('Additional Tools').'</th>');
1.48 albertel 2554: $colspan++;
1.36 raeburn 2555: }
1.48 albertel 2556: $r->print(&Apache::loncommon::end_data_table_header_row());
1.36 raeburn 2557: if ($colspan) {
2558: if ($granularity eq 'Yes') {
1.48 albertel 2559: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense LC_data_table_highlight').'
1.6 raeburn 2560: <td colspan="7"> </td>
1.83 bisitz 2561: <td colspan="'.$colspan.'" align="center"><span class="LC_nobreak"><b>'.&mt('All:').
1.6 raeburn 2562: '</b> ');
1.36 raeburn 2563: foreach my $tool (@{$available}) {
2564: $r->print('<label><input type="checkbox" name="togglefunc"'.
1.7 raeburn 2565: ' onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
1.48 albertel 2566: ' value="'.$tool.'" />'.'<b>'.$tool.'</b></label> ');
1.6 raeburn 2567: }
1.83 bisitz 2568: $r->print('</span></td></tr>');
1.6 raeburn 2569: }
1.36 raeburn 2570: }
2571: my %Sortby = ();
2572: foreach my $user (sort(keys(%{$current}))) {
2573: if ($env{'form.sortby'} eq 'fullname') {
2574: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2575: } elsif ($env{'form.sortby'} eq 'username') {
2576: push(@{$Sortby{$$current{$user}{uname}}},$user);
2577: } elsif ($env{'form.sortby'} eq 'domain') {
2578: push(@{$Sortby{$$current{$user}{udom}}},$user);
2579: } elsif ($env{'form.sortby'} eq 'id') {
2580: push(@{$Sortby{$$current{$user}{id}}},$user);
2581: } else {
2582: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2583: }
2584: }
2585: foreach my $key (sort(keys(%Sortby))) {
2586: foreach my $user (@{$Sortby{$key}}) {
2587: my $id = $$current{$user}{id};
2588: my $fullname = $$current{$user}{fullname};
2589: my $udom = $$current{$user}{udom};
2590: my $uname = $$current{$user}{uname};
2591: my $start = $$current{$user}{start};
2592: my $end = $$current{$user}{end};
1.48 albertel 2593: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense').'
2594: <td>');
1.36 raeburn 2595: if ($$current{$user}{changestate} eq 'reenable') {
1.83 bisitz 2596: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2597: '<input type="checkbox" name="reenable" value="'.$user.'" />'.
1.83 bisitz 2598: $lt{'reen'}.'</label></span><br />');
1.36 raeburn 2599: } elsif ($$current{$user}{changestate} eq 'expire') {
1.83 bisitz 2600: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2601: '<input type="checkbox" name="expire" value="'.$user.'" />'.
1.83 bisitz 2602: $lt{'expi'}.'</label></span><br />');
1.36 raeburn 2603: } elsif ($$current{$user}{changestate} eq 'activate') {
1.83 bisitz 2604: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2605: '<input type="checkbox" name="activate" value="'.$user.'" />'.
1.83 bisitz 2606: $lt{'acti'}.'</label></span><br />');
1.36 raeburn 2607: }
1.83 bisitz 2608: $r->print('<span class="LC_nobreak"><label>'.
1.6 raeburn 2609: '<input type="checkbox" name="deletion" value="'.$user.'" />'.
1.83 bisitz 2610: $lt{'dele'}.'</label></span>');
1.36 raeburn 2611: if ($specificity eq 'Yes') {
1.83 bisitz 2612: $r->print('<br /><span class="LC_nobreak"><label>'.
1.5 raeburn 2613: '<input type="checkbox" name="changepriv" value="'.$user.'" />'.$lt{'chpr'}.
1.83 bisitz 2614: '</label></span>');
1.36 raeburn 2615: }
2616: $r->print('
1.48 albertel 2617: </td>'.
2618: '<td>'.$fullname.'</td>'.
2619: '<td>'.$uname.'</td>'.
2620: '<td>'. $udom.'</td>'.
2621: '<td>'.$id.'</td>'.
2622: '<td>'.$start.'</td>'.
2623: '<td>'.$end.'</td>');
1.36 raeburn 2624: if ($hastools) {
1.83 bisitz 2625: $r->print('<td align="left"><span class="LC_nobreak">'.
1.6 raeburn 2626: ' ');
1.36 raeburn 2627: foreach my $tool (@{$$current{$user}{currtools}}) {
2628: if ($granularity eq 'Yes') {
2629: $r->print('<label><input type="checkbox" '.
1.7 raeburn 2630: 'checked="checked" '.
2631: 'name="user_'.$tool.'" value="'.
2632: $user.'" />'.$tool.'</label>');
1.36 raeburn 2633: } else {
2634: $r->print('<input type="hidden" '.
1.7 raeburn 2635: 'checked="checked" '.
2636: 'name="user_'.$tool.'" value="'.
2637: $user.'" />'.$tool);
1.36 raeburn 2638: }
2639: $r->print(' ');
1.5 raeburn 2640: }
1.83 bisitz 2641: $r->print('</span></td>');
1.36 raeburn 2642: }
2643: if ($addtools) {
1.48 albertel 2644: $r->print('<td align="left">');
1.36 raeburn 2645: if ($granularity eq 'Yes') {
2646: foreach my $tool (@{$$current{$user}{newtools}}) {
1.83 bisitz 2647: $r->print('<span class="LC_nobreak"><label><input type="checkbox"
1.5 raeburn 2648: name="user_'.$tool.'" value="'.
2649: $user.'" />'.$tool.
1.83 bisitz 2650: '</label></span> ');
1.36 raeburn 2651: }
2652: } else {
2653: foreach my $tool (@{$$current{$user}{newtools}}) {
1.83 bisitz 2654: $r->print('<span class="LC_nobreak"><input type="hidden"
1.5 raeburn 2655: name="user_'. $tool.'" value="'.
2656: $user.'" />'.$tool.
1.83 bisitz 2657: '</span> ');
1.5 raeburn 2658: }
2659: }
1.48 albertel 2660: $r->print('</td>');
1.5 raeburn 2661: }
1.48 albertel 2662: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.5 raeburn 2663: }
1.36 raeburn 2664: }
1.48 albertel 2665: $r->print(&Apache::loncommon::end_data_table());
1.53 raeburn 2666: } else {
2667: $r->print(&mt('There are no active, future or previous group members to modify.'));
1.5 raeburn 2668: }
1.53 raeburn 2669: return $numcurrent;
1.5 raeburn 2670: }
2671:
2672: sub check_uncheck_buttons {
2673: my ($r,$formname,$field,$title,$colspan) = @_;
2674: $r->print('
2675: <td '.$colspan.'>
2676: <fieldset>
2677: <legend><b>'.$title.'</b></legend>
1.83 bisitz 2678: <span class="LC_nobreak">
1.80 bisitz 2679: <input type="button" value="'.&mt('check all').'"
1.5 raeburn 2680: onclick="javascript:checkAll(document.'.$formname.'.'.$field.')" />
2681:
1.80 bisitz 2682: <input type="button" value="'.&mt('uncheck all').'"
1.5 raeburn 2683: onclick="javascript:uncheckAll(document.'.$formname.'.'.$field.')" />
1.83 bisitz 2684: </span>
1.5 raeburn 2685: </fieldset>
2686: </td>
2687: ');
2688: }
2689:
2690:
2691: sub change_privs_form {
1.45 albertel 2692: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,
2693: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,
2694: $memchg,$idx,$states,$stored,$sectioncount,$navbuttons,$gpterm,
2695: $ucgpterm) = @_;
1.5 raeburn 2696: my @regexps = ('userpriv_');
2697: my $nexttext;
1.6 raeburn 2698: my %lt = &Apache::lonlocal::texthash(
2699: 'tode' => 'To be deleted',
2700: 'toex' => 'To be expired',
1.29 raeburn 2701: 'nome' => "No members to be deleted or expired from the $gpterm.",
1.6 raeburn 2702: );
1.5 raeburn 2703: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2704: ['origin','action','state','page','sortby'],\@regexps));
2705: if ($env{'form.branch'} eq 'adds') {
2706: $nexttext = $$navbuttons{'adme'};
2707: } else {
2708: $nexttext = $$navbuttons{'mose'};
2709: }
1.78 raeburn 2710: $r->print(&Apache::lonhtmlcommon::topic_bar(3,&mt('Members to delete or expire')));
1.6 raeburn 2711: my $exp_or_del = 0;
2712: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2713: if (@{$$memchg{'deletion'}} > 0) {
1.50 albertel 2714: $r->print('<b>'.$lt{'tode'}.':</b><br /><ul>');
1.6 raeburn 2715: foreach my $user (@{$$memchg{'deletion'}}) {
2716: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2717: ' ('.$user.')</li>');
2718: }
1.45 albertel 2719: $r->print('</ul>');
1.6 raeburn 2720: $exp_or_del += @{$$memchg{'deletion'}};
2721: }
2722: }
2723: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2724: if (@{$$memchg{'expire'}} > 0) {
1.50 albertel 2725: $r->print('<b>'.$lt{'toex'}.':</b><br /><ul>');
1.6 raeburn 2726: foreach my $user (@{$$memchg{'expire'}}) {
2727: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2728: ' ('.$user.')</li>');
2729: }
1.45 albertel 2730: $r->print('</ul>');
1.6 raeburn 2731: $exp_or_del += @{$$memchg{'expire'}};
2732: }
2733: }
2734: if (!$exp_or_del) {
1.45 albertel 2735: $r->print($lt{'nome'}.'<br />');
1.6 raeburn 2736: }
1.5 raeburn 2737:
1.78 raeburn 2738: $r->print(&Apache::lonhtmlcommon::topic_bar(4,&mt('Setting optional privileges for specific group members')));
1.6 raeburn 2739:
1.45 albertel 2740: my $numchgs = &member_privileges_form($r,$action,$formname,$tools,
1.6 raeburn 2741: $toolprivs,$fixedprivs,$userdata,
2742: $usertools,$idx,$memchg,$states,
1.45 albertel 2743: $stored,$gpterm);
1.5 raeburn 2744: my $prevtext = $$navbuttons{'gtps'};
1.6 raeburn 2745: if ($numchgs || $exp_or_del) {
2746: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2747: $$states{$action}[$page+1],$nexttext);
2748: } else {
2749: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext);
2750: }
1.5 raeburn 2751: return;
2752: }
2753:
2754: sub add_members_form {
1.59 raeburn 2755: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,$groupname,
1.29 raeburn 2756: $description,$granularity,$quota,$sectioncount,$tools,$functions,
1.46 albertel 2757: $stored,$states,$navbuttons,$gpterm,$ucgpterm)=@_;
1.40 albertel 2758: $r->print(' <br />');
1.5 raeburn 2759: my @available = ();
2760: my @unavailable = ();
2761: &check_tools($functions,$tools,\@available,\@unavailable);
1.40 albertel 2762: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2763: $groupname,$description,$granularity,$quota,
2764: \@available,\@unavailable,$gpterm,$ucgpterm);
1.59 raeburn 2765: &membership_options($r,$cdom,$cnum,$action,$formname,$sectioncount,1,$gpterm,
2766: $ucgpterm);
1.5 raeburn 2767: my $nexttext = $$navbuttons{'gtns'};
2768: my $prevtext = $$navbuttons{'gtpp'};
2769: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2770: $$states{$action}[$page+1],$nexttext);
2771: return;
2772: }
2773:
2774: sub choose_privs_form {
1.45 albertel 2775: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,
2776: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,$idx,
2777: $states,$stored,$sectioncount,$navbuttons,$gpterm,$ucgpterm,
2778: $crstype) = @_;
1.5 raeburn 2779:
2780: my @regexps = ('userpriv_');
2781: my $nexttext;
2782:
2783: if ($action eq 'create') {
2784: push(@regexps,'sec_');
2785: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2786: ['origin','action','state','page','sortby','autoadd','autodrop'],
1.5 raeburn 2787: \@regexps));
2788: $nexttext = $$navbuttons{'crgr'};
2789: } else {
2790: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2791: ['origin','action','state','page','sortby'],\@regexps));
1.5 raeburn 2792: $nexttext = $$navbuttons{'adme'};
2793: }
2794:
1.78 raeburn 2795: $r->print(&Apache::lonhtmlcommon::topic_bar(6,&mt('Setting optional privileges for specific group members')));
1.5 raeburn 2796:
1.45 albertel 2797: &member_privileges_form($r,$action,$formname,$tools,$toolprivs,
1.5 raeburn 2798: $fixedprivs,$userdata,$usertools,$idx,undef,
1.45 albertel 2799: $states,$stored,$gpterm);
1.5 raeburn 2800:
2801: if ($action eq 'create') {
1.53 raeburn 2802: my $img1 = 7;
2803: my $img2 = 8;
2804: &mapping_options($r,$action,$formname,$page,$sectioncount,
2805: $states,$stored,$navbuttons,$img1,$img2,
1.58 raeburn 2806: $gpterm,$ucgpterm,$crstype,$cdom,$cnum);
1.5 raeburn 2807: }
2808: my $prevtext = $$navbuttons{'gtps'};
2809: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2810: $$states{$action}[$page+1],$nexttext);
2811: return;
2812: }
2813:
2814: sub build_boxes {
2815: my ($r,$tools,$usertools,$fixedprivs,$toolprivs,$showtools,
1.6 raeburn 2816: $showboxes,$prefix,$specificity,$excluded) = @_;
1.5 raeburn 2817: my $totalboxes = 0;
2818: if (@{$tools} > 0) {
2819: if ($specificity eq 'Yes') {
2820: foreach my $tool (@{$tools}) {
2821: @{$$showboxes{$tool}} = ();
2822: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 2823: if (ref($excluded) eq 'ARRAY') {
2824: if (grep/^$user$/,@{$excluded}) {
2825: next;
2826: }
1.5 raeburn 2827: }
1.6 raeburn 2828: if ($$usertools{$user}{$tool}) {
2829: unless (grep/^$tool$/,@{$showtools}) {
2830: push(@{$showtools},$tool);
2831: }
2832: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2833: unless (exists($$fixedprivs{$tool}{$priv})) {
2834: unless(grep(/^$priv$/,@{$$showboxes{$tool}})) {
2835: push(@{$$showboxes{$tool}},$priv);
2836: $totalboxes ++;
2837: }
1.5 raeburn 2838: }
2839: }
2840: }
2841: }
2842: }
2843: if ($totalboxes > 0) {
2844: $r->print('
2845: <script type="text/javascript">
2846: function checkAllTools(formname) {
2847: ');
2848: foreach my $tool (sort(keys(%{$showboxes}))) {
2849: foreach my $priv (@{$$showboxes{$tool}}) {
2850: $r->print(' checkAll(formname.'.$prefix.$priv.');'."\n");
2851: }
2852: }
2853: $r->print('
2854: }
2855: function uncheckAllTools(formname) {
2856: ');
2857: foreach my $tool (sort(keys(%{$showboxes}))) {
2858: foreach my $priv (@{$$showboxes{$tool}}) {
2859: $r->print(' uncheckAll(formname'.$prefix.$priv.');'."\n");
2860: }
2861: }
2862: $r->print('
2863: }
2864: </script>
2865: ');
2866: }
2867: }
2868: }
2869: return $totalboxes;
2870: }
2871:
2872: sub member_privileges_form {
1.45 albertel 2873: my ($r,$action,$formname,$tools,$toolprivs,$fixedprivs,$userdata,
2874: $usertools,$idx,$memchg,$states,$stored,$gpterm) = @_;
1.5 raeburn 2875: my %lt = &Apache::lonlocal::texthash(
2876: 'addp' => 'Additional privileges',
1.53 raeburn 2877: 'fixp' => 'Core privileges',
1.5 raeburn 2878: 'oppr' => 'Optional privileges',
1.53 raeburn 2879: 'func' => 'Tool',
2880: 'forf' => 'For the collaborative tools included for group '.
2881: 'members being added or modified, '.
2882: 'there are no optional privileges to set '.
2883: 'for specific members.',
1.80 bisitz 2884: 'algr' => 'All new group members will receive the same privileges.',
2885: 'ifex' => 'If previously expired members are being re-enabled, or '.
1.54 raeburn 2886: 'if access for future members is being activated now, '.
2887: 'previously set privileges will be preserved.',
1.53 raeburn 2888: 'asno' => 'As no group members are being added, '.
2889: 'there are no specific user privileges to set.',
2890: 'asng' => 'As no group tools will be made available to users, '.
2891: 'there are no specific user privileges to set.',
2892: 'nogm' => 'No group member privileges to display or set, '.
2893: 'as you have not indicated that you will be activating,'.
2894: ' re-enabling, changing privileges, or adding/removing '.
2895: 'tools for any current members.',
1.5 raeburn 2896: 'full' => 'Fullname',
2897: 'user' => 'Username',
2898: 'doma' => 'Domain',
2899: );
2900: my @defprivs;
2901: my $specificity;
2902: if ($action eq 'create') {
2903: if (defined($env{'form.defpriv'})) {
2904: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
2905: }
2906: $specificity = $env{'form.specificity'};
2907: } else {
1.17 raeburn 2908: if (defined($$stored{'defpriv'})) {
2909: @defprivs = @{$$stored{'defpriv'}};
2910: }
1.5 raeburn 2911: $specificity = $$stored{'specificity'};
2912: }
2913: my @showtools;
2914: my %showboxes = ();
2915: my $numtools = 1 + @{$tools};
1.3 raeburn 2916:
1.6 raeburn 2917: my @excluded = ();
2918: my $numchgs = 0;
2919: if ($formname eq 'change_privs') {
2920: my @currmembers = ();
2921: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2922: push(@excluded,@{$$memchg{'deletion'}});
2923: }
2924: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2925: push(@excluded,@{$$memchg{'expire'}});
2926: }
2927: if (@excluded > 0) {
2928: foreach my $user (sort(keys(%{$usertools}))) {
2929: if (grep/^$user$/,@excluded) {
2930: next;
2931: }
2932: push(@currmembers,$user);
2933: }
2934: } else {
2935: @currmembers = sort(keys(%{$usertools}));
2936: }
2937: $numchgs = @currmembers;
2938: if (!$numchgs) {
1.45 albertel 2939: $r->print($lt{'nogm'});
1.6 raeburn 2940: return $numchgs;
2941: }
2942: }
2943:
2944: my $totalboxes = &build_boxes($r,$tools,$usertools,$fixedprivs,
2945: $toolprivs,\@showtools,\%showboxes,
2946: 'userpriv_',$specificity,\@excluded);
1.5 raeburn 2947: if (@{$tools} > 0) {
2948: if ($specificity eq 'Yes') {
2949: if ($totalboxes > 0) {
2950: my $numcells = 2;
2951: my $colspan = $numcells + 1;
2952: my %total;
1.6 raeburn 2953: if (keys(%{$usertools}) > 1) {
2954: $r->print('
1.45 albertel 2955: <table border="0" cellspacing="2" cellpadding="2">
1.5 raeburn 2956: <tr>
2957: ');
1.6 raeburn 2958: foreach my $tool (@{$tools}) {
2959: if (@{$showboxes{$tool}} > 0) {
2960: $r->print('<td valign="top">');
1.100 bisitz 2961: $r->print('<fieldset><legend>'.&mt($tool).'</legend>');
2962: $r->print('<table><tr>');
1.6 raeburn 2963: my $privcount = 0;
2964: foreach my $priv (@{$showboxes{$tool}}) {
2965: $privcount ++;
2966: if (($privcount == @{$showboxes{$tool}}) &&
2967: ($privcount > 1)) {
2968: if ($privcount%$numcells) {
2969: $r->print('<td colspan="'.$colspan.'">');
2970: } else {
2971: $r->print('<td>');
2972: }
1.5 raeburn 2973: } else {
2974: $r->print('<td>');
2975: }
1.80 bisitz 2976: $r->print(
2977: '<fieldset><legend><b>'.&mt($$toolprivs{$tool}{$priv}).'</b></legend>'
2978: .'<span class="LC_nobreak">'
2979: .' <input type="button" value="'.&mt('check all').'"'
2980: .' onclick="javascript:checkAll(document.'.$formname.'.userpriv_'.$priv.')" />'
2981: .' '
2982: .'<input type="button" value="'.&mt('uncheck all').'"'
2983: .' onclick="javascript:uncheckAll(document.'.$formname.'.userpriv_'.$priv.')" />'
2984: .'</span></fieldset><br />'
2985: );
1.6 raeburn 2986: $r->print('</td>');
2987: if ($privcount < @{$showboxes{$tool}}) {
2988: if (@{$showboxes{$tool}} > 2) {
2989: if ($privcount%$numcells == 0) {
2990: $r->print('</tr><tr>');
2991: }
2992: } else {
2993: $r->print('<tr></tr>');
1.5 raeburn 2994: }
2995: }
2996: }
1.100 bisitz 2997: $r->print('</tr></table></fieldset></td><td> </td>');
1.5 raeburn 2998: }
2999: }
1.45 albertel 3000: $r->print('</tr></table>');
1.5 raeburn 3001: }
1.45 albertel 3002: $r->print(&Apache::loncommon::start_data_table().
3003: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 3004: $r->print(<<"END");
1.45 albertel 3005: <th>$lt{'full'}</th>
3006: <th>$lt{'user'}</th>
1.5 raeburn 3007: <th>$lt{'doma'}</th>
3008: <th colspan="$numtools">$lt{'addp'}</th>
3009: END
1.45 albertel 3010: $r->print(&Apache::loncommon::end_data_table_header_row());
3011: &member_privs_entries($r,$usertools,$toolprivs,$fixedprivs,
1.6 raeburn 3012: $userdata,$idx,\@showtools,\@defprivs,
3013: \@excluded);
1.45 albertel 3014: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 3015: } else {
1.43 albertel 3016: $r->print($lt{'forf'}.'<br />');
1.45 albertel 3017: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 3018: }
3019: } else {
3020: if (keys(%{$usertools}) > 0) {
1.54 raeburn 3021: $r->print($lt{'algr'}.'<br />'.$lt{'ifex'}.'<br /><br />');
1.45 albertel 3022: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 3023: } else {
1.43 albertel 3024: $r->print($lt{'asno'}.'<br />');
1.5 raeburn 3025: }
3026: }
3027: } else {
1.43 albertel 3028: $r->print($lt{'asng'});
1.5 raeburn 3029: }
1.6 raeburn 3030: return $numchgs;
1.1 raeburn 3031: }
3032:
1.5 raeburn 3033: sub process_request {
1.45 albertel 3034: my ($r,$cdom,$cnum,$action,$state,$page,$groupname,$description,
1.5 raeburn 3035: $specificity,$userdata,$startdate,$enddate,$tools,$functions,$toolprivs,
3036: $usertools,$idx,$types,$roles,$sections,$states,$navbuttons,$memchg,
1.45 albertel 3037: $sectioncount,$stored,$gpterm,$ucgpterm,$crstype) = @_;
1.3 raeburn 3038:
3039: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 3040: ['origin','action','state','page','sortby']));
1.5 raeburn 3041:
1.29 raeburn 3042: my $earlyout = &validate_groupname($groupname,$action,$cdom,$cnum,$gpterm,
3043: $ucgpterm,$crstype);
1.5 raeburn 3044: if ($earlyout) {
3045: $r->print('
3046: <table width="100%" cellpadding="0" cellspacing="0" border="0">
3047: <tr>
3048: <td> </td>
3049: <td colspan="3">
3050: '.$earlyout.'</td></tr>');
3051: &display_navbuttons($r,$state,$$states{$action}[$page-1],
3052: $$navbuttons{'gtps'});
3053: $r->print('</table>');
3054: return;
3055: }
3056:
3057: my @defprivs = ();
3058: if ($action eq 'create' || $state eq 'chgresult') {
3059: if (defined($env{'form.defpriv'})) {
3060: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
3061: }
3062: if ($state eq 'chgresult') {
3063: my @okprivs = ();
3064: foreach my $tool (@{$tools}) {
3065: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3066: push(@okprivs,$priv);
3067: }
3068: }
3069: my @temp = ();
3070: foreach my $defpriv (@defprivs) {
3071: if (grep/^$defpriv$/,@okprivs) {
3072: push(@temp,$defpriv);
3073: }
3074: }
3075: @defprivs = @temp;
3076: }
3077: } else {
1.17 raeburn 3078: if (defined($$stored{'defpriv'})) {
3079: @defprivs = @{$$stored{'defpriv'}};
3080: }
1.5 raeburn 3081: }
3082:
3083: my $outcome;
3084: if ($action eq 'create' || $state eq 'chgresult') {
3085: $outcome = &write_group_data($r,$cdom,$cnum,$action,$state,$groupname,
3086: $description,$startdate,$enddate,
3087: $specificity,$functions,$tools,
3088: $sectioncount,$roles,$types,$sections,
1.29 raeburn 3089: \@defprivs,$stored,$gpterm,$ucgpterm,
3090: $crstype);
1.5 raeburn 3091: }
3092: if (($action eq 'create' && $outcome eq 'ok') || (($action eq 'modify') &&
3093: (($state eq 'memresult') || ($state eq 'addresult')))) {
1.6 raeburn 3094: &process_membership($r,$cdom,$cnum,$action,$state,$groupname,$tools,
3095: $enddate,$startdate,$userdata,$idx,$toolprivs,
1.29 raeburn 3096: $usertools,$specificity,\@defprivs,$memchg,$gpterm,
3097: $ucgpterm);
1.5 raeburn 3098: }
3099: return;
3100: }
3101:
3102: sub write_group_data {
3103: my ($r,$cdom,$cnum,$action,$state,$groupname,$description,$startdate,
3104: $enddate,$specificity,$functions,$tools,$sectioncount,$roles,$types,
1.29 raeburn 3105: $sections,$defprivs,$stored,$gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 3106: my $now = time;
3107: my $creation = $now;
3108: my $creator = $env{'user.name'}.':'.$env{'user.domain'};
3109: if ($state eq 'chgresult') {
3110: $creation = $$stored{'creation'};
3111: $creator = $$stored{'creator'};
3112: }
1.24 www 3113: my $esc_description = &escape($description);
1.5 raeburn 3114: my @single_attributes = ('description','functions','startdate','enddate',
3115: 'creation','modified','creator','granularity',
1.29 raeburn 3116: 'specificity','autoadd','autodrop','quota');
1.5 raeburn 3117: my @mult_attributes = ('roles','types','sectionpick','defpriv');
1.15 albertel 3118:
1.37 raeburn 3119: my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,
3120: $stored);
3121: my $quota = $env{'form.quota'};
3122:
3123: $quota =~ s/^\s*([^\s]*)\s*$/$1/;
3124: if ($quota eq '') {
3125: $quota = 0;
3126: }
3127: if ($quota !~ /^\d*\.?\d*$/) {
3128: $quota = 0;
1.79 bisitz 3129: $r->print('<div class="LC_warning">'
1.96 weissno 3130: .&mt('The value you entered for the quota for the group portfolio in this '.$gpterm
1.79 bisitz 3131: .' contained invalid characters, so it has been set to 0 Mb. You can change this by'
3132: .' modifying the '.$gpterm.' settings.')
3133: .'</div>');
1.37 raeburn 3134: }
3135: if ($quota > $maxposs) {
3136: $quota = $maxposs;
1.79 bisitz 3137: $r->print('<div class="LC_warning">'
1.96 weissno 3138: .&mt('The value you entered for the quota for the group portfolio in this '.$gpterm
1.79 bisitz 3139: .' exceeded the maximum possible value, so it has been set to [_1] Mb '
3140: .'(the maximum possible value).',sprintf("%.2f",$maxposs))
3141: .'</div>');
1.37 raeburn 3142: }
1.5 raeburn 3143: my %groupinfo = (
3144: description => $esc_description,
3145: startdate => $startdate,
3146: enddate => $enddate,
3147: creation => $creation,
3148: modified => $now,
3149: creator => $creator,
3150: granularity => $env{'form.granularity'},
3151: specificity => $specificity,
3152: autoadd => $env{'form.autoadd'},
3153: autodrop => $env{'form.autodrop'},
1.37 raeburn 3154: quota => $quota,
1.5 raeburn 3155: );
1.37 raeburn 3156:
1.5 raeburn 3157: foreach my $func (keys(%{$functions})) {
3158: my $status;
3159: if (grep(/^$func$/,@{$tools})) {
3160: $status = 'on';
3161: } else {
3162: $status = 'off';
3163: }
3164: $groupinfo{'functions'} .= qq|<name id="$func">$status</name>|;
3165: }
3166:
3167: $groupinfo{'roles'} = $roles;
3168: $groupinfo{'types'} = $types;
3169: $groupinfo{'sectionpick'} = $sections;
3170: $groupinfo{'defpriv'} = $defprivs;
3171:
3172: my %groupsettings = ();
3173: foreach my $item (@single_attributes) {
3174: $groupsettings{$groupname} .= qq|<$item>$groupinfo{$item}</$item>|;
3175: }
3176: foreach my $item (@mult_attributes) {
3177: foreach my $entry (@{$groupinfo{$item}}) {
3178: $groupsettings{$groupname} .= qq|<$item>$entry</$item>|;
3179: }
3180: }
3181: my $autosec;
3182: my @autorole = &Apache::loncommon::get_env_multiple('form.autorole');
1.15 albertel 3183:
1.5 raeburn 3184: foreach my $role (@autorole) {
3185: if (defined($env{'form.sec_'.$role})) {
3186: my @autosections=&Apache::loncommon::get_env_multiple('form.sec_'.
3187: $role);
3188: $autosec .= '<role id="'.$role.'">';
3189: foreach my $sec (@autosections) {
3190: $autosec .= '<section>'.$sec.'</section>';
3191: }
3192: $autosec .= '</role>';
3193: }
3194: }
3195: if ($autosec) {
3196: $groupsettings{$groupname} .= qq|<autosec>$autosec</autosec>|;
3197: }
3198: my $result = &Apache::lonnet::modify_coursegroup($cdom,$cnum,
3199: \%groupsettings);
3200:
3201: if ($result eq 'ok') {
3202: if ($action eq 'create') {
1.32 raeburn 3203: my $result = &add_group_folder($cdom,$cnum,$now,$groupname,$action,
3204: $description,$tools,\%groupinfo,
3205: $gpterm,$ucgpterm,$crstype);
1.79 bisitz 3206: if ($result eq 'ok') {
3207: $r->print('<div class="LC_success">'
3208: .&mt($ucgpterm.' [_1] was created.','<i>'.$groupname.'</i>')
3209: .'</div>');
3210: } else {
3211: $r->print('<div class="LC_error">'
3212: .&mt('A problem occurred when creating folders for the new '.$gpterm.' [_1]:'
3213: ,'<i>'.$groupname.'</i>')
3214: .'<br />'.$result
3215: .'</div>');
1.32 raeburn 3216: }
1.56 raeburn 3217: } elsif ($action eq 'modify') {
3218: my (@oldtools,@newtools);
3219: if (ref($$stored{'tool'}) eq 'ARRAY') {
3220: @oldtools = @{$$stored{'tool'}};
3221: }
3222: if (ref($tools) eq 'ARRAY') {
3223: @newtools = @{$tools};
3224: }
3225: if (!grep(/^discussion$/,@oldtools) &&
3226: grep(/^discussion$/,@newtools)) {
3227: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
3228: my $boardsmap = $crspath.'group_boards_'.$groupname.'.sequence';
3229: my $navmap = Apache::lonnavmaps::navmap->new();
1.85 raeburn 3230: my ($bbmapres,$error);
3231: if (defined($navmap)) {
3232: $bbmapres = $navmap->getResourceByUrl($boardsmap);
3233: undef($navmap);
3234: if (!$bbmapres) {
3235: my $grpmap = $crspath.'group_folder_'.$groupname.'.sequence';
3236: my $disctitle = &mt('Discussion Boards');
3237: my $outcome = &map_updater($cdom,$cnum,'group_boards_'.
3238: $groupname.'.sequence','bbseq',
3239: $disctitle,$grpmap);
3240: my ($furl,$ferr) =
3241: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
3242: # modify parameter
3243: if ($outcome eq 'ok') {
3244: $navmap = Apache::lonnavmaps::navmap->new();
3245: if (defined($navmap)) {
3246: my $parm_result = &parm_setter($navmap,$cdom,$boardsmap,
3247: $groupname);
3248: if ($parm_result) {
3249: $error = &mt('An error occurred while setting parameters '
3250: .'for Discussion Boards folder: '
3251: .'[_1]',$parm_result);
3252: } else {
3253: $r->print('<div class="LC_success">'.
3254: &mt('Discussion Boards Folder created.')
3255: .'</div>');
3256: }
3257: undef($navmap);
3258: } else {
3259: $error = &mt('An error occurred while setting parameters '.
3260: 'for Discussion Boards folder: '.
3261: 'Could not retrieve course information' );
3262: }
1.56 raeburn 3263: } else {
1.85 raeburn 3264: $r->print($outcome);
1.56 raeburn 3265: }
3266: }
1.85 raeburn 3267: } else {
3268: $error = &mt("An error occurred while retrieving the contents of the group's folder.").'<br />'.
3269: &mt('You need to re-initialize the course.');
3270: }
3271: if ($error ne '') {
3272: $r->print('<div class="LC_error">'.$error.'</div>');
1.56 raeburn 3273: }
3274: }
1.79 bisitz 3275: $r->print('<div class="LC_success">'
3276: .&mt($ucgpterm.' [_1] was updated.','<i>'.$groupname.'</i>')
3277: .'</div>');
1.5 raeburn 3278: }
3279: } else {
3280: my %actiontype = (
3281: 'create' => 'creating',
3282: 'modify' => 'modifying',
3283: );
1.29 raeburn 3284: &Apache::lonnet::logthis("Failed to store $gpterm $groupname ".
3285: 'in '.lc($crstype).': '.$cnum.
3286: ' in domain: '.$cdom);
1.79 bisitz 3287: $r->print('<div class="LC_error">'
3288: .&mt('An error occurred when [_1] the '.$gpterm.'. '
3289: .'Please try again.',$actiontype{$action})
3290: .'</div>');
1.5 raeburn 3291: }
3292: return $result;
3293: }
3294:
3295: sub process_membership {
1.6 raeburn 3296: my ($r,$cdom,$cnum,$action,$state,$groupname,$tools,$enddate,$startdate,
1.29 raeburn 3297: $userdata,$idx,$toolprivs,$usertools,$specificity,$defprivs,$memchg,
3298: $gpterm,$ucgpterm)=@_;
1.5 raeburn 3299: my %usersettings = ();
1.6 raeburn 3300: my %added= ();
3301: my %failed = ();
3302: my $num_ok = 0;
3303: my $num_fail = 0;
1.3 raeburn 3304: my %group_privs = ();
1.20 raeburn 3305: my %curr_privs = ();
1.21 raeburn 3306: my %curr_start = ();
3307: my %curr_end = ();
1.3 raeburn 3308: my %tooltype = ();
1.77 raeburn 3309: my $context = 'processgroupmembership';
1.5 raeburn 3310:
1.3 raeburn 3311: foreach my $tool (@{$tools}) {
3312: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3313: $tooltype{$priv} = $tool;
1.5 raeburn 3314: if ($specificity eq 'Yes') {
1.3 raeburn 3315: my @users =
3316: &Apache::loncommon::get_env_multiple('form.userpriv_'.$priv);
3317: foreach my $user (@users) {
3318: $group_privs{$user} .= $priv.':';
1.8 raeburn 3319: if ($state eq 'memresult') {
3320: unless (exists($$usertools{$user}{$tool})) {
3321: $$usertools{$user}{$tool} = 1;
3322: }
3323: }
1.3 raeburn 3324: }
3325: } else {
1.5 raeburn 3326: if (@{$defprivs} > 0) {
1.26 raeburn 3327: if (grep/^\Q$priv\E$/,@{$defprivs}) {
1.5 raeburn 3328: foreach my $user (sort(keys(%{$usertools}))) {
3329: if ($$usertools{$user}{$tool}) {
3330: $group_privs{$user} .= $priv.':';
3331: }
1.3 raeburn 3332: }
3333: }
3334: }
3335: }
3336: }
3337: }
3338: foreach my $user (keys(%group_privs)) {
3339: $group_privs{$user} =~ s/:$//;
3340: }
1.5 raeburn 3341:
1.6 raeburn 3342: my $now = time;
3343: my @activate = ();
3344: my @expire = ();
3345: my @deletion = ();
3346: my @reenable = ();
1.20 raeburn 3347: my @unchanged = ();
1.6 raeburn 3348: if ($state eq 'memresult') {
3349: if (ref($$memchg{'activate'}) eq 'ARRAY') {
3350: @activate = @{$$memchg{'activate'}};
3351: }
3352: if (ref($$memchg{'expire'}) eq 'ARRAY') {
3353: @expire = @{$$memchg{'expire'}};
3354: }
3355: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
3356: @deletion = @{$$memchg{'deletion'}};
3357: }
3358: if (ref($$memchg{'reenable'}) eq 'ARRAY') {
3359: @reenable = @{$$memchg{'reenable'}};
3360: }
1.20 raeburn 3361: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
3362: $groupname);
3363: foreach my $key (sort(keys(%membership))) {
3364: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
1.21 raeburn 3365: ($curr_end{$1},$curr_start{$1},$curr_privs{$1}) =
3366: split(/:/,$membership{$key},3);
1.20 raeburn 3367: }
3368: }
1.6 raeburn 3369: if (@expire + @deletion > 0) {
3370: foreach my $user (@expire) {
1.21 raeburn 3371: my $savestart = $curr_start{$user};
3372: if ($savestart > $now) {
3373: $savestart = $now;
1.6 raeburn 3374: }
1.21 raeburn 3375: $usersettings{$groupname.':'.$user} = $now.':'.$savestart.':'.
3376: $curr_privs{$user};
1.6 raeburn 3377: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.21 raeburn 3378: $user,$now,$savestart,
1.77 raeburn 3379: $curr_privs{$user},'',$context) eq 'ok') {
1.6 raeburn 3380: push(@{$added{'expired'}},$user);
3381: $num_ok ++;
3382: } else {
3383: push(@{$failed{'expired'}},$user);
3384: $num_fail ++;
3385: }
3386: }
3387: foreach my $user (@deletion) {
3388: $usersettings{$groupname.':'.$user} = $now.':-1:';
3389: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.76 raeburn 3390: $user,$now,'-1','','',$context)
1.6 raeburn 3391: eq 'ok') {
3392: push(@{$added{'deleted'}},$user);
3393: $num_ok ++;
3394: } else {
3395: push(@{$failed{'deleted'}},$user);
3396: $num_fail ++;
3397: }
3398: }
3399: }
1.8 raeburn 3400: }
1.6 raeburn 3401:
1.5 raeburn 3402: foreach my $user (sort(keys(%{$usertools}))) {
1.20 raeburn 3403: if ((grep(/^$user$/,@expire)) || (grep(/^$user$/,@deletion))) {
3404: next;
3405: }
1.6 raeburn 3406: my $type;
3407: my $start = $startdate;
3408: my $end = $enddate;
3409: if ($state eq 'memresult') {
3410: if (@activate > 0) {
3411: if (grep/^$user$/,@activate) {
3412: $start = $now;
1.21 raeburn 3413: $end = $enddate;
1.6 raeburn 3414: $type = 'activated';
3415: }
3416: }
3417: if (@reenable > 0) {
3418: if (grep/^$user$/,@reenable) {
1.21 raeburn 3419: $start = $startdate;
3420: $end = $enddate;
1.6 raeburn 3421: $type = 'reenabled';
3422: }
3423: }
1.38 raeburn 3424: if ($type eq '') {
3425: if ($curr_privs{$user} eq $group_privs{$user}) {
3426: push(@unchanged,$user);
3427: next;
3428: }
3429: if (exists($curr_start{$user})) {
3430: $start = $curr_start{$user};
3431: }
3432: if (exists($curr_end{$user})) {
3433: $end = $curr_end{$user};
3434: }
3435: $type = 'modified';
3436: }
1.6 raeburn 3437: } else {
3438: $type = 'added';
3439: }
3440: $usersettings{$groupname.':'.$user} = $end.':'.$start.':'.
1.5 raeburn 3441: $group_privs{$user};
3442: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.6 raeburn 3443: $user,$end,$start,
1.76 raeburn 3444: $group_privs{$user},'',$context) eq 'ok') {
1.6 raeburn 3445: push(@{$added{$type}},$user);
3446: $num_ok ++;
1.3 raeburn 3447: } else {
1.6 raeburn 3448: push(@{$failed{$type}},$user);
3449: $num_fail ++;
1.5 raeburn 3450: }
3451: }
3452: my $roster_result = &Apache::lonnet::modify_coursegroup_membership($cdom,
3453: $cnum,\%usersettings);
1.6 raeburn 3454: if ($num_ok) {
3455: foreach my $type (sort(keys(%added))) {
3456: $r->print(&mt('The following users were successfully [_1]',$type));
1.20 raeburn 3457: if (!($type eq 'deleted' || $type eq 'expired')) {
1.6 raeburn 3458: $r->print(&mt(' with the following privileges'));
3459: }
3460: $r->print(':<br />');
3461: foreach my $user (@{$added{$type}}) {
1.8 raeburn 3462: my $privlist = '';
3463: if (!($type eq 'deleted' || $type eq 'expired')) {
3464: $privlist = ': ';
1.6 raeburn 3465: my @privs = split(/:/,$group_privs{$user});
3466: my $curr_tool = '';
3467: foreach my $priv (@privs) {
3468: unless ($curr_tool eq $tooltype{$priv}) {
3469: $curr_tool = $tooltype{$priv};
3470: $privlist .= '<b>'.$curr_tool.'</b>: ';
3471: }
3472: $privlist .= $$toolprivs{$curr_tool}{$priv}.', ';
3473: }
3474: $privlist =~ s/, $//;
3475: }
1.8 raeburn 3476: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.$privlist.'<br />');
1.6 raeburn 3477: }
1.20 raeburn 3478: $r->print('<br />');
1.6 raeburn 3479: }
3480: }
3481: if ($num_fail) {
3482: foreach my $type (sort(keys(%failed))) {
1.79 bisitz 3483: $r->print('<div class="LC_error">'
3484: .&mt("The following users could not be $type, because an error occurred:")
3485: .'</div>');
1.6 raeburn 3486: foreach my $user (@{$failed{$type}}) {
3487: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
3488: }
1.5 raeburn 3489: }
1.20 raeburn 3490: $r->print('<br />');
3491: }
3492: if (@unchanged > 0) {
1.80 bisitz 3493: $r->print(&mt('No change occurred for the following users:').'<br />');
1.20 raeburn 3494: foreach my $user (sort(@unchanged)) {
3495: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
3496: }
3497: $r->print('<br />');
1.5 raeburn 3498: }
3499: if ($roster_result eq 'ok') {
1.80 bisitz 3500: $r->print('<div class="LC_success">'
3501: .&mt($ucgpterm.' membership list updated.')
3502: .'</div>');
3503: $r->print('<p class="LC_info">'
3504: .&mt('Any currently logged in course users affected by the changes you made'
3505: .' to group membership or privileges for the [_1] group will need to log out'
3506: .' and log back in for their LON-CAPA sessions to reflect these changes.'
3507: ,'<i>'.$groupname.'</i>')
3508: .'</p>'
3509: );
1.5 raeburn 3510: } else {
1.80 bisitz 3511: $r->print('<div class="LC_error">'
3512: .&mt("An error occurred while updating the $gpterm membership list:")
3513: .'<br />'.$roster_result
3514: .'</div>');
1.5 raeburn 3515: }
3516: return;
3517: }
3518:
3519: sub mapping_options {
1.44 albertel 3520: my ($r,$action,$formname,$page,$sectioncount,$states,$stored,
1.58 raeburn 3521: $navbuttons,$img1,$img2,$gpterm,$ucgpterm,$crstype,$cdom,$cnum) = @_;
1.5 raeburn 3522: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 3523: 'auto' => "Settings for automatic $gpterm enrollment",
3524: 'gmma' => "$ucgpterm membership mapping to specific sections/roles",
3525: 'endi' => "Enable/disable automatic $gpterm enrollment for ".
3526: "users in specified roles and sections",
1.53 raeburn 3527: '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 3528: '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.",
3529: 'pirs' => "Pick roles and sections for automatic $gpterm enrollment",
1.5 raeburn 3530: 'on' => 'on',
3531: 'off' => 'off',
1.29 raeburn 3532: 'auad' => "Automatically enable $gpterm membership when roles are added?",
3533: 'auex' => "Automatically expire $gpterm membership when roles are removed?",
3534: 'mapr' => "Mapping of roles and sections affected by automatic $gpterm enrollment/disenrollment follows scheme chosen below.",
1.5 raeburn 3535: );
1.44 albertel 3536: &automapping($r,$action,$stored,\%lt,$img1);
1.58 raeburn 3537: &mapping_settings($r,$sectioncount,\%lt,$stored,$img2,$crstype,$cdom,$cnum,
3538: $action);
1.5 raeburn 3539: return;
3540: }
3541:
3542: sub automapping {
1.44 albertel 3543: my ($r,$action,$stored,$lt,$image) = @_;
1.5 raeburn 3544: my $add = 'off';
3545: my $drop = 'off';
3546: if (exists($$stored{'autoadd'})) {
3547: $add = $$stored{'autoadd'};
3548: }
3549: if (exists($$stored{'autodrop'})) {
3550: $drop = $$stored{'autodrop'};
3551: }
1.78 raeburn 3552: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$$lt{'endi'}).'
1.44 albertel 3553: <b>'.$$lt{'gmma'}.':</b><br />'.$$lt{'adds'}.'<br />'.$$lt{'drops'}.'<br /><br />
1.83 bisitz 3554: <span class="LC_nobreak">'.$$lt{'auad'}.':
1.80 bisitz 3555: <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 3556: if ($action eq 'modify') {
1.82 bisitz 3557: $r->print(' ('.&mt('Currently set to [_1].','<b>'.$$lt{$add}.'</b>').')');
1.5 raeburn 3558: }
3559: $r->print('
1.83 bisitz 3560: </span><br />
3561: <span class="LC_nobreak">'.$$lt{'auex'}.':
1.80 bisitz 3562: <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 3563: if ($action eq 'modify') {
1.82 bisitz 3564: $r->print(' ('.&mt('Currently set to [_1].','<b>'.$$lt{$drop}.'</b>').')');
1.3 raeburn 3565: }
1.83 bisitz 3566: $r->print('</span><br /><br />'.$$lt{'mapr'});
1.5 raeburn 3567: }
1.3 raeburn 3568:
1.5 raeburn 3569: sub mapping_settings {
1.58 raeburn 3570: my ($r,$sectioncount,$lt,$stored,$image,$crstype,$cdom,$cnum,$action) = @_;
1.5 raeburn 3571: my @sections = keys(%{$sectioncount});
3572: if (@sections > 0) {
3573: @sections = sort {$a cmp $b} @sections;
1.17 raeburn 3574: unshift(@sections,'none'); # Put 'no sections' next
3575: unshift(@sections,'all'); # Put 'all' at the front of the list
1.53 raeburn 3576: } else {
3577: @sections = ('all','none');
1.3 raeburn 3578: }
1.78 raeburn 3579: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$$lt{'pirs'}));
1.5 raeburn 3580: my @roles = &standard_roles();
1.59 raeburn 3581: my %customroles = &Apache::lonhtmlcommon::course_custom_roles($cdom,$cnum);
1.44 albertel 3582: $r->print(&Apache::loncommon::start_data_table().
3583: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 3584: $r->print('
3585: <th>'.&mt('Active?').'</th>
3586: <th>'.&mt('Role').'</th>');
3587: if (@sections > 0) {
1.44 albertel 3588: $r->print('<th>'.&mt('Sections').'</th>');
1.3 raeburn 3589: }
1.44 albertel 3590: $r->print(&Apache::loncommon::end_data_table_header_row()."\n");
1.5 raeburn 3591: foreach my $role (@roles) {
1.58 raeburn 3592: my $roletitle=&Apache::lonnet::plaintext($role,$crstype);
3593: $r->print(&print_autorole_item($role,$roletitle,\@sections));
1.5 raeburn 3594: }
1.58 raeburn 3595: my @customs;
1.5 raeburn 3596: foreach my $role (sort(keys(%customroles))) {
1.58 raeburn 3597: my ($roletitle) = ($role =~ m|^cr/[^/]+/[^/]+/(.+)$|);
3598: push (@customs,$role);
3599: $r->print(&print_autorole_item($role,$roletitle,\@sections));
3600: }
3601: if ($action eq 'modify') {
3602: foreach my $role (@{$$stored{'autorole'}}) {
3603: if ((!grep(/^\Q$role\E$/,@customs)) &&
3604: (!grep(/^\Q$role\E$/,@roles))) {
3605: my $roletitle;
3606: if ($role =~ /^cr/) {
3607: ($roletitle) = ($role =~ m|_([^_]+)$|);
3608: } else {
3609: $roletitle = &Apache::lonnet::plaintext($role,$crstype);
3610: }
3611: $r->print(&print_autorole_item($role,$roletitle,\@sections));
3612: }
3613: }
1.5 raeburn 3614: }
1.44 albertel 3615: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 3616: return;
3617: }
1.3 raeburn 3618:
1.58 raeburn 3619: sub print_autorole_item {
3620: my ($role,$roletitle,$sections) = @_;
3621: my $sections_sel;
3622: if (@{$sections} > 0) {
3623: if ($role eq 'cc') {
3624: $sections_sel = '<td align="right">'.
3625: &mt('all sections').'<input type="hidden" '.
3626: 'name="sec_cc" value="all" /></td>';
3627: } else {
3628: $sections_sel='<td align="right">'.
3629: §ions_selection($sections,'sec_'.$role).
3630: '</td>';
3631: }
3632: }
3633: my $output = &Apache::loncommon::start_data_table_row().
3634: '<td><input type="checkbox" '.
3635: 'name="autorole" value="'.$role.'" />'.
3636: '</td><td>'.$roletitle.'</td>'.$sections_sel.
3637: &Apache::loncommon::end_data_table_row();
3638: return $output;
3639: }
3640:
1.5 raeburn 3641: sub standard_roles {
1.17 raeburn 3642: my @roles = ('cc','in','ta','ep','st');
1.5 raeburn 3643: return @roles;
3644: }
3645:
3646: sub modify_menu {
1.29 raeburn 3647: my ($r,$groupname,$page,$gpterm) = @_;
1.5 raeburn 3648: my @menu =
3649: (
1.29 raeburn 3650: { text => "Modify default $gpterm settings",
1.5 raeburn 3651: help => 'Course_Modify_Group',
3652: state => 'change_settings',
3653: branch => 'settings',
3654: },
1.6 raeburn 3655: { text => 'Modify access, tools and/or privileges for previous, '.
3656: 'future, or current members',
1.5 raeburn 3657: help => 'Course_Modify_Group_Membership',
3658: state => 'change_members',
3659: branch => 'members',
3660: },
1.29 raeburn 3661: { text => "Add member(s) to the $gpterm",
1.5 raeburn 3662: help => 'Course_Group_Add_Members',
3663: state => 'add_members',
3664: branch => 'adds',
3665: },
3666: );
3667: my $menu_html = '';
3668: foreach my $menu_item (@menu) {
3669: $menu_html .=
3670: '<p><font size="+1"><a href="/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state='.$menu_item->{'state'}.'&branch='.$menu_item->{'branch'}.'">';
3671: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
3672: if (exists($menu_item->{'help'})) {
3673: $menu_html.=
3674: &Apache::loncommon::help_open_topic($menu_item->{'help'});
3675: }
3676: $menu_html.='</p>'.$/;
1.3 raeburn 3677: }
1.5 raeburn 3678: $r->print($menu_html);
1.3 raeburn 3679: return;
3680: }
3681:
3682: sub member_privs_entries {
1.45 albertel 3683: my ($r,$usertools,$toolprivs,$fixedprivs,$userdata,$idx,$showtools,
3684: $defprivs,$excluded) = @_;
1.5 raeburn 3685: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 3686: if (defined($excluded)) {
3687: if (ref($excluded) eq 'ARRAY') {
3688: if (grep/^$user$/,@{$excluded}) {
3689: next;
3690: }
3691: }
3692: }
1.5 raeburn 3693: my ($uname,$udom) = split(/:/,$user);
1.45 albertel 3694: $r->print(&Apache::loncommon::start_data_table_row().'
1.5 raeburn 3695: <td>'.$$userdata{$user}[$$idx{fullname}].'</td>
1.3 raeburn 3696: <td>'.$uname.'</td>
3697: <td>'.$udom.'</td>
1.53 raeburn 3698: <td valign="top">
3699: <table>
3700: <tr>
3701: <td><b>'.
3702: &mt('Collaborative Tool').'</b></td>
3703: </tr>
3704: <tr>
3705: <td><b>'.&mt('Fixed').'</b></td>
3706: </tr>
3707: <tr>
3708: <td><b>'.&mt('Optional').'</b></td>
3709: </tr>
3710: </table>
3711: </td>');
1.5 raeburn 3712: foreach my $tool (@{$showtools}) {
3713: if (exists($$usertools{$user}{$tool})) {
1.45 albertel 3714: $r->print('<td valign="top"><table><tr><th colspan="2">'.$tool.'</th></tr>');
1.3 raeburn 3715: my $privcount = 0;
3716: my $fixed = '';
3717: my $dynamic = '';
3718: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3719: if (exists($$fixedprivs{$tool}{$priv})) {
1.5 raeburn 3720: $fixed .= '<input type="hidden" name="userpriv_'.$priv.'" value="'.$user.'" />'.$$toolprivs{$tool}{$priv}.' ';
1.3 raeburn 3721: } else {
3722: $privcount ++;
3723: if ($privcount == 3) {
3724: $dynamic .= '</tr><tr>';
3725: }
1.83 bisitz 3726: $dynamic .='<td><span class="LC_nobreak"><label><input type="checkbox" '.
1.5 raeburn 3727: 'name="userpriv_'.$priv.'" value="'.$user.'"';
3728: if (grep/^\Q$priv\E$/,@{$defprivs}) {
3729: $dynamic .= ' checked="checked" ';
3730: }
3731: $dynamic .= ' />'.$$toolprivs{$tool}{$priv}.
1.83 bisitz 3732: '</label></span></td>';
1.3 raeburn 3733: }
3734: }
1.83 bisitz 3735: $r->print('<tr><td colspan="2"><span class="LC_nobreak">'.$fixed.'</span></td></tr><tr>'.$dynamic.'</tr></table></td>');
1.3 raeburn 3736: } else {
1.45 albertel 3737: $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 3738: }
3739: }
1.45 albertel 3740: $r->print(&Apache::loncommon::end_data_table_row());
1.3 raeburn 3741: }
3742: }
3743:
3744: sub get_dates_from_form {
3745: my $startdate;
3746: my $enddate;
3747: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
3748: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
3749: if ( exists ($env{'form.no_end_date'}) ) {
3750: $enddate = 0;
3751: }
3752: return ($startdate,$enddate);
1.5 raeburn 3753: }
3754:
1.3 raeburn 3755: sub date_setting_table {
3756: my ($starttime,$endtime,$formname) = @_;
3757: my $startform = &Apache::lonhtmlcommon::date_setter($formname,
3758: 'startdate',$starttime);
3759: my $endform = &Apache::lonhtmlcommon::date_setter($formname,
3760: 'enddate',$endtime);
1.98 bisitz 3761: my $perpetual = ' <span class="LC_nobreak"><label>'
3762: .'<input type="checkbox" name="no_end_date" />'
3763: .&mt('No end date')
3764: .'</label></span>';
3765: my $table = &Apache::lonhtmlcommon::start_pick_box()
3766: .&Apache::lonhtmlcommon::row_title(&mt('Start Date'))
3767: .$startform
3768: .&Apache::lonhtmlcommon::row_closure()
3769: .&Apache::lonhtmlcommon::row_title(&mt('End Date'))
3770: .$endform
3771: .$perpetual
3772: .&Apache::lonhtmlcommon::row_closure(1)
3773: .&Apache::lonhtmlcommon::end_pick_box();
1.41 albertel 3774: return $table;
1.1 raeburn 3775: }
3776:
1.32 raeburn 3777: sub add_group_folder {
3778: my ($cdom,$cnum,$now,$groupname,$action,$description,$tools,$groupinfo,
3779: $gpterm,$ucgpterm,$crstype) = @_;
3780: if ($cdom eq '' || $cnum eq '') {
1.80 bisitz 3781: return '<span class="LC_error">'
3782: .&mt('Error: invalid course domain or number - group folder creation failed.')
3783: .'</span>';
1.32 raeburn 3784: }
1.67 raeburn 3785: my ($outcome,$allgrpsmap,$grpmap,$boardsmap,$grppage,$warning);
1.32 raeburn 3786: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
1.47 raeburn 3787: $allgrpsmap = $crspath.'group_allfolders.sequence';
1.32 raeburn 3788: if ($action eq 'create') {
1.67 raeburn 3789: if (&get_folder_lock($cdom,$cnum,'group_allfolders',$now) eq 'ok') {
3790: # check if group_allfolders.sequence exists.
1.69 raeburn 3791: my $mapcontents = &Apache::lonnet::getfile($allgrpsmap);
3792: if ($mapcontents eq '-1') { #file does not exist;
1.80 bisitz 3793: my $grpstitle = &mt("$crstype $ucgpterm".'s');
1.67 raeburn 3794: my $topmap_url = '/'.$env{'course.'.$env{'request.course.id'}.'.url'};
3795: $topmap_url =~ s|/+|/|g;
3796: if ($topmap_url =~ m|^/uploaded|) {
3797: $outcome = &map_updater($cdom,$cnum,'group_allfolders.sequence',
3798: 'toplevelgroup',$grpstitle,$topmap_url);
3799: } else {
1.80 bisitz 3800: $outcome = '<span class="LC_warning">'
3801: .&mt('Non-standard course - folder for all groups not added.')
3802: .'</span>';
1.67 raeburn 3803: }
1.32 raeburn 3804: if ($outcome ne 'ok') {
1.67 raeburn 3805: my $delresult = &release_folder_lock($cdom,$cnum,'group_allfolders');
3806: if ($delresult ne 'ok') {
3807: $warning = $delresult;
3808: }
1.84 raeburn 3809: return $outcome.$warning;
1.32 raeburn 3810: }
3811: }
1.67 raeburn 3812: my $delresult = &release_folder_lock($cdom,$cnum,'group_allfolders');
3813: if ($delresult ne 'ok') {
3814: $warning = $delresult ;
3815: }
3816: } else {
1.80 bisitz 3817: $outcome = '<span class="LC_error">'
3818: .&mt('Could not obtain exclusive lock to check status of the folder for all groups. No group folder added.')
1.84 raeburn 3819: .'</span>';
1.67 raeburn 3820: return $outcome;
1.32 raeburn 3821: }
1.75 bisitz 3822: my $grpfolder = &mt($ucgpterm.' Folder - [_1]',$description);
1.49 raeburn 3823: $grppage='/adm/'.$cdom.'/'.$cnum.'/'.$groupname.'/smppg';
1.75 bisitz 3824: my $grptitle = &mt('Group homepage - [_1]',$description);
1.55 raeburn 3825: my ($discussions,$disctitle);
1.47 raeburn 3826: my $outcome = &map_updater($cdom,$cnum,'group_folder_'.$groupname.'.sequence',
1.32 raeburn 3827: 'grpseq',$grpfolder,$allgrpsmap,$grppage,
3828: $grptitle);
3829: if ($outcome ne 'ok') {
1.67 raeburn 3830: return $outcome.$warning;
1.32 raeburn 3831: }
3832: my $pageout = &create_homepage($cdom,$cnum,$groupname,$groupinfo,
3833: $tools,$gpterm,$ucgpterm,$now);
3834: # Link to folder for bulletin boards
1.47 raeburn 3835: $grpmap = $crspath.'group_folder_'.$groupname.'.sequence';
1.32 raeburn 3836: if (grep/^discussion$/,@{$tools}) {
3837: $disctitle = &mt('Discussion Boards');
1.47 raeburn 3838: my $outcome = &map_updater($cdom,$cnum,'group_boards_'.$groupname.
1.32 raeburn 3839: '.sequence','bbseq',$disctitle,$grpmap);
3840: if ($outcome ne 'ok') {
1.67 raeburn 3841: return $outcome.$warning;
1.32 raeburn 3842: }
1.47 raeburn 3843: $boardsmap = $crspath.'group_boards_'.$groupname.'.sequence';
1.32 raeburn 3844: }
3845: } else {
3846: #modify group folder if status of discussions tools is changed
3847: }
3848: my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.67 raeburn 3849: my $navmap = Apache::lonnavmaps::navmap->new();
1.85 raeburn 3850: if (!defined($navmap)) {
3851: return $warning.'<span class="LC_error">'.&mt('Error retrieving course contents').
3852: ' '.&mt('You need to re-initialize the course.').'</span>';
3853: }
1.32 raeburn 3854: # modify parameters
3855: my $parm_result;
3856: if ($action eq 'create') {
3857: if ($grpmap) {
3858: $parm_result .= &parm_setter($navmap,$cdom,$grpmap,$groupname);
3859: }
3860: if ($grppage) {
3861: $parm_result .= &parm_setter($navmap,$cdom,$grppage,$groupname);
3862: }
3863: if ($boardsmap) {
3864: $parm_result .= &parm_setter($navmap,$cdom,$boardsmap,$groupname);
3865: }
3866: }
1.67 raeburn 3867: undef($navmap);
1.32 raeburn 3868: if ($parm_result) {
1.67 raeburn 3869: return $warning.$parm_result;
3870: } else {
3871: return 'ok';
3872: }
3873: }
3874:
3875: sub get_folder_lock {
3876: my ($cdom,$cnum,$folder_name,$now) = @_;
3877: # get lock for folder being edited.
3878: my $lockhash = {
3879: $folder_name."\0".'locked_folder' => $now.':'.$env{'user.name'}.
3880: ':'.$env{'user.domain'},
3881: };
3882: my $tries = 0;
3883: my $gotlock = &Apache::lonnet::newput('coursegroups',$lockhash,$cdom,$cnum);
3884:
3885: while (($gotlock ne 'ok') && $tries <3) {
3886: $tries ++;
1.68 albertel 3887: sleep(1);
1.67 raeburn 3888: $gotlock = &Apache::lonnet::newput('coursegroups',$lockhash,$cdom,$cnum);
3889: }
3890: return $gotlock;
3891: }
3892:
3893: sub release_folder_lock {
3894: my ($cdom,$cnum,$folder_name) = @_;
3895: # remove lock
3896: my @del_lock = ($folder_name."\0".'locked_folder');
3897: my $dellockoutcome=&Apache::lonnet::del('coursegroups',\@del_lock,$cdom,$cnum);
3898: if ($dellockoutcome ne 'ok') {
1.80 bisitz 3899: return ('<div class="LC_error">'
3900: .&mt('Warning: failed to release lock for folder: [_1].','<tt>'.$folder_name.'</tt>')
3901: .'</div>'
3902: );
1.32 raeburn 3903: } else {
3904: return 'ok';
3905: }
3906: }
3907:
3908: sub map_updater {
3909: my ($cdom,$cnum,$newfile,$itemname,$itemtitle,$parentmap,$startsrc,
3910: $starttitle,$endsrc,$endtitle) = @_;
3911: my $outcome;
3912: $env{'form.'.$itemname} = &new_map($startsrc,$starttitle,$endsrc,
3913: $endtitle);
3914: my $newmapurl=&Apache::lonnet::finishuserfileupload($cnum,$cdom,$itemname,
3915: $newfile);
3916: if ($newmapurl !~ m|^/uploaded|) {
1.80 bisitz 3917: $outcome = '<div class="LC_error">'
3918: .&mt('Error uploading new folder.')." ($newfile): $newmapurl"
3919: .'</div>';
1.32 raeburn 3920: return $outcome;
1.67 raeburn 3921: }
1.63 albertel 3922: my ($errtext,$fatal)=&LONCAPA::map::mapread($parentmap);
1.32 raeburn 3923: if ($fatal) {
1.80 bisitz 3924: $outcome = '<div class="LC_error">'
3925: .&mt('Error reading contents of parent folder.')." ($parentmap): $errtext"
3926: .'</div>';
1.32 raeburn 3927: return $outcome;
3928: } else {
1.63 albertel 3929: my $newidx=&LONCAPA::map::getresidx($newmapurl);
3930: $LONCAPA::map::resources[$newidx] = $itemtitle.':'.$newmapurl.
1.32 raeburn 3931: ':false:normal:res';
1.63 albertel 3932: $LONCAPA::map::order[1+$#LONCAPA::map::order]=$newidx;
3933: my ($outtext,$errtext) = &LONCAPA::map::storemap($parentmap,1);
1.67 raeburn 3934: if ($errtext) {
1.80 bisitz 3935: $outcome = '<div class="LC_error">'
3936: .&mt('Error saving updated parent folder.')." ($parentmap): $errtext"
3937: .'</div>';
1.32 raeburn 3938: return $outcome;
3939: }
3940: }
3941: return 'ok';
3942: }
3943:
3944: sub new_map {
3945: my ($startsrc,$starttitle,$endsrc,$endtitle) = @_;
3946: my $newmapstr = '
3947: <map>
3948: <resource id="1" src="'.$startsrc.'" type="start" title="'.$starttitle.'"></resource>
3949: <link from="1" to="2" index="1"></link>
3950: <resource id="2" src="'.$endsrc.'" type="finish" title="'.$endtitle.'"></resource>
3951: </map>
3952: ';
3953: return $newmapstr;
3954: }
3955:
3956: sub parm_setter {
3957: my ($navmap,$cdom,$url,$groupname) = @_;
1.37 raeburn 3958: my $allresults;
1.85 raeburn 3959: if (!defined($navmap)) {
1.86 raeburn 3960: $allresults = '<div class="LC_warning">'.
3961: &mt('Parameters not set for [_1] because the contents of the course could not be retrieved.',$url).' '.
3962: &mt('You need to reinitialize the course.').
3963: '</div>';
1.87 raeburn 3964: return $allresults;
1.85 raeburn 3965: }
1.32 raeburn 3966: my %hide_settings = (
3967: 'course' => {
3968: 'num' => 13,
3969: 'set' => 'yes',
3970: },
3971: 'group' => {
3972: 'num' => 5,
3973: 'set' => 'no',
3974: 'extra' => $groupname,
3975: },
3976: );
3977: my $res = $navmap->getResourceByUrl($url);
1.67 raeburn 3978: if ($res) {
3979: my $symb = $res->symb();
3980: foreach my $level (keys(%hide_settings)) {
3981: my $parmresult =
3982: &Apache::lonparmset::storeparm_by_symb($symb,
1.32 raeburn 3983: '0_hiddenresource',
3984: $hide_settings{$level}{'num'},
3985: $hide_settings{$level}{'set'},
3986: 'string_yesno',undef,$cdom,
3987: undef,undef,
3988: $hide_settings{$level}{'extra'});
1.67 raeburn 3989: if ($parmresult) {
3990: $allresults .= $level.': '.$parmresult;
3991: }
1.37 raeburn 3992: }
1.67 raeburn 3993: } else {
1.80 bisitz 3994: $allresults = '<div class="LC_warning">'
3995: .&mt('Parameters not set for [_1] because the resource was not recognized'
3996: .' as part of the course.','<tt>'.$url.'</tt>')
3997: .'</div>';
1.32 raeburn 3998: }
1.37 raeburn 3999: return $allresults;
1.32 raeburn 4000: }
4001:
1.3 raeburn 4002: sub create_homepage {
1.32 raeburn 4003: my ($cdom,$cnum,$name,$groupinfo,$tools,$gpterm,$ucgpterm,$now) = @_;
1.3 raeburn 4004: my $functionality = join(',',@{$tools});
1.24 www 4005: my $content = &unescape($$groupinfo{description});
1.3 raeburn 4006: $content=~s/\s+$//s;
4007: $content=~s/^\s+//s;
4008: $content=~s/\<br\s*\/*\>$//s;
4009: $content=&Apache::lonfeedback::clear_out_html($content,1);
4010:
4011: my %pageinfo = (
1.29 raeburn 4012: 'aaa_title' => "$ucgpterm: $name",
1.3 raeburn 4013: 'abb_links' => $functionality,
4014: 'bbb_content' => $content,
4015: 'ccc_webreferences' => '',
1.32 raeburn 4016: 'uploaded.lastmodified' => $now,
1.3 raeburn 4017: );
4018: my $putresult = &Apache::lonnet::put('grppage_'.$name,\%pageinfo,$cdom,$cnum);
4019: return $putresult;
1.1 raeburn 4020: }
4021:
1.5 raeburn 4022: sub check_uncheck_tools {
4023: my ($r,$available) = @_;
4024: if (ref($available) eq 'ARRAY') {
4025: $r->print('
4026: <script type="text/javascript">
4027: function checkAllTools(formname) {
4028: ');
4029: foreach my $tool (@{$available}) {
4030: $r->print(' checkAll(formname.user_'.$tool.');'."\n");
4031: }
4032: $r->print(' checkAll(formname.togglefunc);'."\n");
4033: $r->print('
4034: }
4035: function uncheckAllTools(formname) {
4036: ');
4037: foreach my $tool (@{$available}) {
4038: $r->print(' uncheckAll(formname.user_'.$tool.');'."\n");
4039: }
4040: $r->print(' uncheckAll(formname.togglefunc);'."\n");
4041: $r->print('
4042: }
4043: function toggleTools(field,caller) {
4044: if (caller.checked) {
4045: checkAll(field);
4046: } else {
4047: uncheckAll(field);
4048: }
4049: return;
4050: }
4051: </script>
4052: ');
4053: }
4054: return;
4055: }
4056:
4057: sub validate_groupname {
1.29 raeburn 4058: my ($groupname,$action,$cdom,$cnum,$gpterm,$ucgpterm,$crstype) = @_;
1.16 albertel 4059: my %sectioncount = &Apache::loncommon::get_sections($cdom,$cnum);
1.17 raeburn 4060: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.65 raeburn 4061: my %deleted_groups = &Apache::longroup::coursegroups($cdom,$cnum,undef,
4062: 'deleted_groups');
1.64 raeburn 4063: if (my $tmp = &Apache::lonnet::error(%deleted_groups)) {
4064: undef(%deleted_groups);
4065: &Apache::lonnet::logthis('Error retrieving groups: '.$tmp.' in '.$cnum.':'.$cdom);
4066: }
1.5 raeburn 4067: my %lt = &Apache::lonlocal::texthash (
1.29 raeburn 4068: igna => "Invalid $gpterm name",
4069: tgne => "The $gpterm name entered ",
4070: grna => "$ucgpterm names and section names used in a ".
4071: "$crstype must be unique.",
4072: isno => "is not a valid name.",
4073: gnmo => "$ucgpterm names may only contain letters, ".
4074: "numbers or underscores.",
4075: cnnb => "can not be used as it is the name of ",
4076: inth => " in this $crstype",
4077: thgr => "- does not correspond to the name of an ".
4078: "existing $gpterm",
1.5 raeburn 4079: );
1.15 albertel 4080:
1.42 albertel 4081: my $exitmsg = '<span class="LC_error">'.$lt{'igna'}.'</span><br /><br />'.
4082: $lt{'tgne'}.' "'.$groupname.'" ';
1.5 raeburn 4083: my $dupmsg = $lt{'grna'};
4084: my $earlyout;
4085: if (($groupname eq '') || ($groupname =~ /\W/)) {
4086: $earlyout = $exitmsg.$lt{'isno'}.'<br />'.$lt{'gnmo'};
4087: return $earlyout;
4088: }
1.16 albertel 4089: if (exists($sectioncount{$groupname})) {
4090: return $exitmsg.$lt{'cnnb'}.&mt('a section').$lt{'inth'}.
4091: '<br />'.$lt{'grna'};
1.5 raeburn 4092: }
1.64 raeburn 4093: if ($action eq 'create') {
4094: if (exists($curr_groups{$groupname})) {
4095: return $exitmsg.$lt{'cnnb'}.&mt('an existing [_1]',$gpterm).
4096: $lt{'inth'}.'.<br />'.$lt{'grna'};
4097: } elsif (exists($deleted_groups{$groupname})) {
4098: return $exitmsg.$lt{'cnnb'}.&mt('a [_1] which previously existed',$gpterm).
4099: $lt{'inth'}.'.<br />'.$lt{'grna'};
4100: }
1.5 raeburn 4101: } elsif ($action eq 'modify') {
4102: unless(exists($curr_groups{$groupname})) {
1.29 raeburn 4103: $earlyout = &mt('[_1] name:',$ucgpterm).' '.$groupname.$lt{'thgr'}.
4104: $lt{'inth'};
1.5 raeburn 4105: return $earlyout;
4106: }
4107: }
4108: return;
4109: }
4110:
4111: sub check_changes {
4112: my ($member_changes,$memchg) = @_;
4113: my %exclusions;
4114: @{$exclusions{'changefunc'}} = ('expire');
4115: @{$exclusions{'changepriv'}} = ('expire','changefunc');
4116:
4117: foreach my $change (@{$member_changes}) {
1.6 raeburn 4118: if ($change eq 'deletion') {
1.5 raeburn 4119: next;
4120: }
1.6 raeburn 4121: my @checks = ('deletion');
1.5 raeburn 4122: if (exists($exclusions{$change})) {
4123: push(@checks,@{$exclusions{$change}});
4124: }
4125: my @temp = ();
4126: foreach my $item (@{$$memchg{$change}}) {
4127: my $match = 0;
4128: foreach my $check (@checks) {
1.6 raeburn 4129: if (defined($$memchg{$check})) {
4130: if (ref(@{$$memchg{$check}}) eq 'ARRAY') {
4131: if (@{$$memchg{$check}} > 0) {
4132: if (grep/^$item$/,@{$$memchg{$check}}) {
4133: $match = 1;
4134: last;
4135: }
4136: }
1.5 raeburn 4137: }
4138: }
4139: }
4140: if ($match) {
4141: next;
4142: }
4143: push(@temp,$item);
4144: }
4145: @{$$memchg{$change}} = @temp;
4146: }
4147: }
1.3 raeburn 4148:
1.1 raeburn 4149: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>