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