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