Annotation of loncom/interface/loncoursegroups.pm, revision 1.89
1.24 www 1: # The LearningOnline Network with CAPA
2: #
1.89 ! bisitz 3: # $Id: loncoursegroups.pm,v 1.88 2008/12/24 07:35:17 raeburn Exp $
1.1 raeburn 4: #
5: # Copyright Michigan State University Board of Trustees
6: #
7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
8: #
9: # LON-CAPA is free software; you can redistribute it and/or modify
10: # it under the terms of the GNU General Public License as published by
11: # the Free Software Foundation; either version 2 of the License, or
12: # (at your option) any later version.
13: #
14: # LON-CAPA is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with LON-CAPA; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27:
28: package Apache::loncoursegroups;
29:
30: use strict;
31: use Apache::lonnet;
1.63 albertel 32: use Apache::loncommon();
33: use Apache::lonhtmlcommon();
1.1 raeburn 34: use Apache::lonlocal;
1.63 albertel 35: use Apache::lonnavmaps();
36: use Apache::longroup();
37: use Apache::portfolio();
1.1 raeburn 38: use Apache::Constants qw(:common :http);
1.63 albertel 39: use LONCAPA::map();
1.24 www 40: use lib '/home/httpd/lib/perl/';
41: use LONCAPA;
1.1 raeburn 42:
43: sub handler {
44: my ($r) = @_;
1.3 raeburn 45:
1.1 raeburn 46: &Apache::loncommon::content_type($r,'text/html');
47: $r->send_http_header;
1.15 albertel 48:
1.1 raeburn 49: if ($r->header_only) {
50: return OK;
51: }
52:
53: # Needs to be in a course
54: if (! ($env{'request.course.fn'})) {
55: # Not in a course
56: $env{'user.error.msg'}=
1.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.87 raeburn 78: email => 'Send Messages',
1.81 schafran 79: discussion => 'Discussion Boards',
1.3 raeburn 80: chat => 'Chat',
1.81 schafran 81: files => 'File Repository',
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.53 raeburn 144: $r->print(&header('Groups',$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) {
788: alert("The file repository quota you entered for this group ("+newquota+" Mb) exceeds the maximum possible ("+maxposs+" Mb). Please enter a smaller number.");
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) {
807: alert("You have indicated that the file repository 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.");
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(
918: gtns => 'Go to next step',
919: gtps => 'Go to previous step',
1.29 raeburn 920: crgr => 'Create '.$gpterm,
1.5 raeburn 921: mose => 'Modify settings',
922: gtpp => 'Go to previous page',
923: adme => 'Add members',
924: );
1.65 raeburn 925: if ((($action eq 'create') || ($action eq 'modify') || ($action eq 'delete') || ($action eq 'reenable')) &&
1.3 raeburn 926: ($manage_permission)) {
927: for (my $i=0; $i<@{$states{$action}}; $i++) {
928: if ($state eq $states{$action}[$i]) {
929: &Apache::lonhtmlcommon::add_breadcrumb(
930: {text=>"$trail{$action}{$state}"});
931: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.61 raeburn 932: ("Groups Manager","Creating_Groups"));
1.48 albertel 933: &display_control($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 934: \%sectioncount,$groupname,$description,$functions,
1.36 raeburn 935: \@tools,$toolprivs,$fixedprivs,$startdate,$enddate,
1.5 raeburn 936: \%users,\%userdata,$idx,\%memchg,\%usertools,
1.45 albertel 937: $view_permission,$manage_permission,
1.29 raeburn 938: \%stored,$granularity,$quota,$specificity,\@types,\@roles,
1.48 albertel 939: \@sections,\%states,\%navbuttons,$gpterm,$ucgpterm,
940: $crstype);
1.3 raeburn 941: last;
942: } else {
1.64 raeburn 943: if (($action eq 'create') || ($action eq 'modify')) {
944: if (($state eq 'result') && ($i > 0)) {
945: &Apache::lonhtmlcommon::add_breadcrumb(
1.3 raeburn 946: {href=>"javascript:backPage(document.$state,'$states{$action}[0]')",
947: text=>"$trail{$action}{$states{$action}[$i]}"});
1.64 raeburn 948: } else {
949: &Apache::lonhtmlcommon::add_breadcrumb(
1.3 raeburn 950: {href=>"javascript:backPage(document.$state,'$states{$action}[$i]')",
951: text=>"$trail{$action}{$states{$action}[$i]}"});
1.64 raeburn 952: }
1.3 raeburn 953: }
1.64 raeburn 954: }
1.3 raeburn 955: }
956: } elsif (($action eq 'view') && ($view_permission)) {
957: &Apache::lonhtmlcommon::add_breadcrumb(
1.29 raeburn 958: {text=>"View $gpterm".'s'});
1.1 raeburn 959: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.53 raeburn 960: ('Groups Manager'));
1.39 albertel 961: &display_groups($r,$cdom,$cnum,$functions,$idx,$view_permission,
962: $manage_permission,$action,$state,$gpterm,$ucgpterm,
963: $crstype);
1.3 raeburn 964: }
965: $r->print(&footer());
966: return;
967: }
968:
1.5 raeburn 969: sub retrieve_settings {
1.65 raeburn 970: my ($cdom,$cnum,$groupname,$action) = @_;
971: my %curr_groups;
972: my $namespace;
973: if ($action eq 'reenable') {
974: $namespace = 'deleted_groups';
975: } else {
976: $namespace = 'coursegroups';
977: }
978: %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$groupname,
979: $namespace);
1.15 albertel 980:
981: return if (!%curr_groups);
982:
983: my %groupinfo =
1.17 raeburn 984: &Apache::longroup::get_group_settings($curr_groups{$groupname});
1.15 albertel 985:
1.5 raeburn 986: my %stored;
1.15 albertel 987:
988: $stored{'description'} =
1.24 www 989: &unescape($groupinfo{'description'});
1.15 albertel 990: $stored{'startdate'} = $groupinfo{'startdate'};
991: $stored{'enddate'} = $groupinfo{'enddate'};
992: if ($stored{'enddate'} == 0) {
993: $stored{'no_end_date'} = 1;
994: }
995: $stored{'granularity'} = $groupinfo{'granularity'};
996: $stored{'specificity'} = $groupinfo{'specificity'};
997: $stored{'creation'} = $groupinfo{'creation'};
998: $stored{'creator'} = $groupinfo{'creator'};
1.29 raeburn 999: $stored{'quota'} = $groupinfo{'quota'};
1.15 albertel 1000:
1001: foreach my $tool (sort(keys(%{$groupinfo{'functions'}}))) {
1002: if ($groupinfo{functions}{$tool} eq 'on') {
1003: push(@{$stored{tool}},$tool);
1004: }
1005: }
1006: foreach my $role (@{$groupinfo{'roles'}}) {
1007: push(@{$stored{roles}},$role);
1008: }
1009: foreach my $type (@{$groupinfo{'types'}}) {
1010: push(@{$stored{types}},$type);
1011: }
1012: foreach my $section (@{$groupinfo{'sectionpick'}}) {
1013: push(@{$stored{sectionpick}},$section);
1014: }
1015: foreach my $defpriv (@{$groupinfo{'defpriv'}}) {
1016: push(@{$stored{defpriv}},$defpriv);
1017: }
1018: $stored{'autoadd'} = $groupinfo{'autoadd'};
1019: $stored{'autodrop'} = $groupinfo{'autodrop'};
1020: if (exists($groupinfo{'autosec'})) {
1021: foreach my $role (sort(keys(%{$groupinfo{'autosec'}}))) {
1.17 raeburn 1022: if (ref($groupinfo{'autosec'}{$role}) eq 'ARRAY') {
1023: foreach my $section (@{$groupinfo{'autosec'}{$role}}) {
1.58 raeburn 1024:
1.17 raeburn 1025: push (@{$stored{'sec_'.$role}},$section);
1026: }
1027: if (@{$groupinfo{'autosec'}{$role}} > 0) {
1028: push(@{$stored{'autorole'}},$role);
1029: }
1030: }
1.15 albertel 1031: }
1.5 raeburn 1032: }
1033: return %stored;
1034: }
1035:
1.3 raeburn 1036: sub display_control {
1.48 albertel 1037: my ($r,$cdom,$cnum,$action,$state,$page,$sectioncount,$groupname,
1.3 raeburn 1038: $description,$functions,$tools,$toolprivs,$fixedprivs,$startdate,
1.45 albertel 1039: $enddate,$users,$userdata,$idx,$memchg,$usertools,
1.29 raeburn 1040: $view_permission,$manage_permission,$stored,$granularity,$quota,
1.48 albertel 1041: $specificity,$types,$roles,$sections,$states,$navbuttons,
1042: $gpterm,$ucgpterm,$crstype) = @_;
1.3 raeburn 1043: if ($action eq 'create') {
1044: if ($state eq 'pick_name') {
1.46 albertel 1045: &general_settings_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1046: $functions,$tools,$toolprivs,$fixedprivs,
1047: $sectioncount,$stored,$states,$navbuttons,
1.46 albertel 1048: $gpterm,$ucgpterm,$crstype);
1.3 raeburn 1049: } elsif ($state eq 'pick_members') {
1.46 albertel 1050: &choose_members_form($r,$cdom,$cnum,$action,$state,$page,
1.29 raeburn 1051: $groupname,$description,$granularity,$quota,
1.5 raeburn 1052: $startdate,$enddate,$tools,$fixedprivs,
1053: $toolprivs,$functions,$users,$userdata,$idx,
1.46 albertel 1054: $stored,$states,$navbuttons,$gpterm,$ucgpterm,
1055: $crstype);
1.3 raeburn 1056: } elsif ($state eq 'pick_privs') {
1.45 albertel 1057: &choose_privs_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1058: $startdate,$enddate,$tools,$functions,
1059: $toolprivs,$fixedprivs,$userdata,$usertools,
1060: $idx,$states,$stored,$sectioncount,$navbuttons,
1.45 albertel 1061: $gpterm,$ucgpterm,$crstype);
1.3 raeburn 1062: } elsif ($state eq 'result') {
1.45 albertel 1063: &process_request($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1064: $groupname,$description,$specificity,$userdata,
1065: $startdate,$enddate,$tools,$functions,
1066: $toolprivs,$usertools,$idx,$types,$roles,
1067: $sections,$states,$navbuttons,$memchg,
1.45 albertel 1068: $sectioncount,$stored,$gpterm,$ucgpterm,$crstype);
1.5 raeburn 1069: }
1070: } elsif ($action eq 'modify') {
1071: my $groupname = $env{'form.groupname'};
1.53 raeburn 1072: if ($state eq 'pick_task') {
1.29 raeburn 1073: &modify_menu($r,$groupname,$page,$gpterm);
1.5 raeburn 1074: } elsif ($state eq 'change_settings') {
1.46 albertel 1075: &general_settings_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1076: $functions,$tools,$toolprivs,$fixedprivs,
1077: $sectioncount,$stored,$states,$navbuttons,
1.46 albertel 1078: $gpterm,$ucgpterm,$crstype);
1.5 raeburn 1079: } elsif ($state eq 'change_members') {
1.48 albertel 1080: &change_members_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1081: $groupname,$description,$startdate,$enddate,
1082: $tools,$fixedprivs,$functions,$users,
1.29 raeburn 1083: $userdata,$granularity,$quota,$specificity,
1.48 albertel 1084: $idx,$states,$navbuttons,$gpterm,$ucgpterm);
1.5 raeburn 1085: } elsif ($state eq 'add_members') {
1.59 raeburn 1086: &add_members_form($r,$cdom,$cnum,$action,$state,$page,$startdate,
1.5 raeburn 1087: $enddate,$groupname,$description,$granularity,
1.29 raeburn 1088: $quota,$sectioncount,$tools,$functions,$stored,
1.46 albertel 1089: $states,$navbuttons,$gpterm,$ucgpterm);
1.5 raeburn 1090: } elsif ($state eq 'pick_members') {
1.46 albertel 1091: &choose_members_form($r,$cdom,$cnum,$action,$state,$page,
1.29 raeburn 1092: $groupname,$description,$granularity,$quota,
1.5 raeburn 1093: $startdate,$enddate,$tools,$fixedprivs,
1094: $toolprivs,$functions,$users,$userdata,$idx,
1.46 albertel 1095: $stored,$states,$navbuttons,$gpterm,$ucgpterm,
1096: $crstype);
1.5 raeburn 1097: } elsif ($state eq 'pick_privs') {
1.46 albertel 1098: &choose_privs_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1099: $startdate,$enddate,$tools,$functions,
1100: $toolprivs,$fixedprivs,$userdata,$usertools,
1101: $idx,$states,$stored,$sectioncount,$navbuttons,
1.46 albertel 1102: $gpterm,$ucgpterm,$crstype);
1.5 raeburn 1103: } elsif ($state eq 'change_privs') {
1.45 albertel 1104: &change_privs_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1105: $startdate,$enddate,$tools,$functions,
1106: $toolprivs,$fixedprivs,$userdata,$usertools,
1107: $memchg,$idx,$states,$stored,$sectioncount,
1.45 albertel 1108: $navbuttons,$gpterm,$ucgpterm);
1.5 raeburn 1109: } elsif ($state eq 'chgresult' || $state eq 'memresult' ||
1110: $state eq 'addresult') {
1.45 albertel 1111: &process_request($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1112: $groupname,$description,$specificity,$userdata,
1113: $startdate,$enddate,$tools,$functions,
1114: $toolprivs,$usertools,$idx,$types,$roles,
1115: $sections,$states,$navbuttons,$memchg,
1.45 albertel 1116: $sectioncount,$stored,$gpterm,$ucgpterm,$crstype);
1.1 raeburn 1117: }
1.64 raeburn 1118: } elsif ($action eq 'delete') {
1.65 raeburn 1119: my %stored = &retrieve_settings($cdom,$cnum,$groupname,$action);
1.64 raeburn 1120: if ($state eq 'verify') {
1121: &verify_delete($r,$groupname,$state,$action,$page,$states,
1122: \%stored);
1123: } elsif ($state eq 'result') {
1124: &delete_group($r,$cdom,$cnum,$groupname);
1125: }
1.65 raeburn 1126: } elsif ($action eq 'reenable') {
1127: my %stored = &retrieve_settings($cdom,$cnum,$groupname,$action);
1128: if ($state eq 'verify') {
1129: &verify_reenable($r,$groupname,$state,$action,$page,$states,
1130: \%stored);
1131: } elsif ($state eq 'result') {
1132: &reenable_group($r,$cdom,$cnum,$groupname);
1133: }
1.64 raeburn 1134: }
1135: }
1136:
1137: sub verify_delete {
1138: my ($r,$groupname,$formname,$action,$page,$states,$stored) = @_;
1139: $r->print(&Apache::lonhtmlcommon::echo_form_input([]));
1.79 bisitz 1140: $r->print(&mt('You have requested deletion of the group [_1].'
1141: ,'<i>'.$stored->{'description'}.'</i>').
1.64 raeburn 1142: '<br /><br />'.&mt('When a group is deleted the following occurs:').'<ul>'.
1143: '<li>'.&mt('All group membership is terminated.').'</li>'.
1144: '<li>'.&mt('The group ceases to be available either for viewing or for modification of group settings and membership.').'</li>'.
1145: '<li>'.&mt('The group folder is removed from the folder containing it - normally this is the "Course Groups" folder which contains folders for all groups in the course.').'</li>'.
1146: '</ul>'.&mt('Although a deleted group is no longer accessible, the group name used for the group will be reserved, and will not be available for assignment to a new group in the same course in the future.'));
1147: my $prevtext = &mt('Go back');
1148: my $nexttext = &mt('Delete group');
1149: my $prev;
1.71 raeburn 1150: if ($env{'form.refpage'} eq 'cusr') {
1.64 raeburn 1151: $prev = 'view';
1152: }
1153: &display_navbuttons($r,$formname,$prev,$prevtext,
1154: $$states{$action}[$page+1],$nexttext);
1155: return;
1156: }
1157:
1158: sub delete_group {
1159: my ($r,$cdom,$cnum,$groupname) = @_;
1160: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
1161: $groupname);
1162: my $now = time;
1163: my $num_users = 0;
1164: my $num_fail = 0;
1165: my $num_ok = 0;
1166: my @deleted;
1167: my @undeleted;
1168: my %usersettings;
1.77 raeburn 1169: my $context = 'deletegroup';
1.64 raeburn 1170: foreach my $key (sort(keys(%membership))) {
1171: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
1172: my $user = $1;
1.65 raeburn 1173: my($end,$start,$userprivs) = split(/:/,$membership{$key},3);
1.64 raeburn 1174: if ($start != -1) {
1175: $num_users ++;
1.65 raeburn 1176: $usersettings{$groupname.':'.$user} = $now.':-1:'.$userprivs;
1.64 raeburn 1177: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,
1178: $groupname,$user,
1.76 raeburn 1179: $now,'-1',$userprivs,
1180: '',$context)
1.64 raeburn 1181: eq 'ok') {
1182: $num_ok ++;
1183: push(@deleted,$user);
1184: } else {
1185: push(@undeleted,$user);
1186: $num_fail ++;
1187: }
1188: }
1189: }
1190: }
1191: if ($num_ok > 0) {
1192: my $roster_result =
1193: &Apache::lonnet::modify_coursegroup_membership($cdom,$cnum,
1194: \%usersettings);
1195: }
1196: if ($num_fail > 0) {
1.79 bisitz 1197: $r->print('<div class="LC_error">'
1198: .&mt('Group deletion failed because deletion of [_1] out of [_2] members failed.'
1199: ,$num_fail,$num_users)
1200: .'</div>');
1.64 raeburn 1201:
1202: } else {
1203: my ($result,$message) =
1.65 raeburn 1204: &Apache::lonnet::toggle_coursegroup_status($cdom,$cnum,
1205: $groupname,'delete');
1.64 raeburn 1206: if ($result eq 'ok') {
1207: my $outcome = &modify_folders($cdom,$cnum,$groupname);
1208: if ($outcome eq '') {
1.79 bisitz 1209: $r->print('<div class="LC_success">'
1210: .&mt('Group successfully deleted.')
1211: .'</div>');
1.64 raeburn 1212: } else {
1.79 bisitz 1213: $r->print('<div class="LC_error">'
1214: .&mt("Although the group was deleted, an error occurred when removing"
1215: ." the group's folder from the 'Course Groups' folder: [_1]",$outcome)
1216: .'</div>');
1.64 raeburn 1217: }
1218: } else {
1.79 bisitz 1219: $r->print('<div class="LC_error">'
1220: .&mt('Group deletion failed.')
1221: .'</div>');
1.64 raeburn 1222: }
1.1 raeburn 1223: }
1.64 raeburn 1224: return;
1225: }
1226:
1.65 raeburn 1227: sub reenable_folder {
1228: my ($cdom,$cnum,$groupname,$description) = @_;
1229: my $outcome;
1230: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
1231: my $allgrpsmap = $crspath.'group_allfolders.sequence';
1.79 bisitz 1232: my $foldertitle = &mt('Course Folder -[_1]',$description);
1.65 raeburn 1233: my $mapurl = $crspath.'group_folder_'.
1234: $groupname.'.sequence';
1235: my ($errtext,$fatal)=&LONCAPA::map::mapread($allgrpsmap);
1236: if ($fatal) {
1.79 bisitz 1237: $outcome='<div class="LC_error">'
1238: .&mt('An error occurred when reading contents of parent folder to group:')
1239: ."<br />($allgrpsmap): $errtext"
1240: .'</div>';
1.65 raeburn 1241: } else {
1242: my $idx=&LONCAPA::map::getresidx($mapurl);
1243: $LONCAPA::map::resources[$idx] = $foldertitle.':'.$mapurl.
1244: ':false:normal:res';
1245: $LONCAPA::map::order[1+$#LONCAPA::map::order]=$idx;
1246: my ($outtext,$errtext) = &LONCAPA::map::storemap($allgrpsmap,1);
1247: if ($errtext) {
1.79 bisitz 1248: $outcome='<div class="LC_error">'
1249: .&mt('An error occurred when saving updated parent folder to group:'
1250: ,"<br />$allgrpsmap - $errtext")
1251: .'</div>';
1.65 raeburn 1252: } else {
1253: my ($furl,$ferr) =
1254: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1255: }
1256: }
1257: return $outcome;
1258: }
1259:
1.64 raeburn 1260: sub modify_folders {
1261: my ($cdom,$cnum,$groupname) = @_;
1.85 raeburn 1262: my ($outcome,$groupmap,$groupmapres,$map,$id,$src);
1.64 raeburn 1263: my $navmap = Apache::lonnavmaps::navmap->new();
1.85 raeburn 1264: if (!defined($navmap)) {
1265: $outcome = '<div class="LC_error">'.
1266: &mt('Error reading course contents.').' '.
1267: &mt('You need to re-initialize the course.').
1268: '</div>';
1269: return $outcome;
1270: }
1271: $groupmap = '/uploaded/'.$cdom.'/'.$cnum.'/'.'group_folder_'.
1.64 raeburn 1272: $groupname.'.sequence';
1.85 raeburn 1273: $groupmapres = $navmap->getResourceByUrl($groupmap);
1.64 raeburn 1274: if ($groupmapres) {
1.65 raeburn 1275: ($map,$id,$src)=&Apache::lonnet::decode_symb($groupmapres->symb());
1276: }
1277: undef($navmap);
1278: if ($map) {
1.64 raeburn 1279: $map = '/'.$map;
1280: my ($errtext,$fatal) = &LONCAPA::map::mapread($map);
1281: if ($fatal) {
1.79 bisitz 1282: $outcome='<div class="LC_error">'
1283: .&mt('An error occurred when reading contents of parent folder to group:')
1284: ."<br />($map): $errtext"
1285: .'</div>';
1.64 raeburn 1286: } else {
1287: my $idx = 0;
1288: my $grpidx;
1289: foreach my $item (@LONCAPA::map::order) {
1290: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$item]);
1291: $url=&LONCAPA::map::qtescape($url);
1292: if ($url eq $groupmap) {
1293: $grpidx = $idx;
1294: last;
1295: } else {
1296: $idx++;
1297: }
1298: }
1299:
1300: if ($grpidx ne '') {
1301: &LONCAPA::map::makezombie($LONCAPA::map::order[$grpidx]);
1302: for (my $i=$grpidx;$i<$#LONCAPA::map::order;$i++) {
1303: $LONCAPA::map::order[$i] = $LONCAPA::map::order[$i+1];
1304: }
1305: $#LONCAPA::map::order--;
1306: my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1);
1.65 raeburn 1307: if ($errtext) {
1.79 bisitz 1308: $outcome='<div class="LC_error">'
1309: .&mt('An error occurred when saving updated parent folder to group:')
1310: ."<br />$map - $errtext"
1311: .'</div>';
1.65 raeburn 1312: } else {
1313: my ($furl,$ferr) =
1314: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1315: }
1316: }
1317: }
1318: }
1319: return $outcome;
1320: }
1321:
1322: sub verify_reenable {
1323: my ($r,$groupname,$formname,$action,$page,$states,$stored) = @_;
1324: $r->print(&Apache::lonhtmlcommon::echo_form_input([]));
1.79 bisitz 1325: $r->print(&mt('You have requested enabling the previously deleted group [_1].'
1326: ,'<i>'.$stored->{'description'}.'</i>').
1.65 raeburn 1327: '<br /><br />'.&mt('When a deleted group is re-enabled the following occurs:').'<ul>'.
1328: '<li>'.&mt('Group settings and membership at the time the group was deleted are reinstated.').'</li>'.
1329: '<li>'.&mt('A group folder is added to the "Course Groups" folder which contains folders for all groups in the course.').'</li></ul>');
1330: my $prevtext = &mt('Go back');
1331: my $nexttext = &mt('Reenable group');
1332: my $prev;
1.71 raeburn 1333: if ($env{'form.refpage'} eq 'cusr') {
1.65 raeburn 1334: $prev = 'view';
1335: }
1336: &display_navbuttons($r,$formname,$prev,$prevtext,
1337: $$states{$action}[$page+1],$nexttext);
1338: return;
1339: }
1340:
1341: sub reenable_group {
1.66 raeburn 1342: my ($r,$cdom,$cnum,$groupname) = @_;
1.65 raeburn 1343: my %groups =
1344: &Apache::longroup::coursegroups($cdom,$cnum,$groupname,
1345: 'deleted_groups');
1.66 raeburn 1346: if (keys(%groups) == 0) {
1.79 bisitz 1347: $r->print(&mt('The group [_1] was not re-enabled, because it is not a deleted group.[_2]Perhaps it has already been re-enabled?','<i>'.$groupname.'</i>'),'<br />');
1.66 raeburn 1348: return;
1349: }
1.65 raeburn 1350: my %groupinfo =
1351: &Apache::longroup::get_group_settings($groups{$groupname});
1352: my $defstart = $groupinfo{'startdate'};
1353: my $defend = $groupinfo{'enddate'};
1354: my $showstart = &Apache::lonlocal::locallocaltime($defstart);
1355: my $showend;
1356: if ($defend == 0) {
1357: $showend = &mt('No end date set');
1358: } else {
1359: $showend = &Apache::lonlocal::locallocaltime($defend);
1360: }
1361: my $description = &unescape($groupinfo{'description'});
1362: my $num_users = 0;
1363: my $num_ok = 0;
1364: my $num_fail = 0;
1.77 raeburn 1365: my $context = 'reenablegroup';
1.65 raeburn 1366: my (%usersettings,@enabled,@unenabled);
1367: my ($result,$message) =
1368: &Apache::lonnet::toggle_coursegroup_status($cdom,$cnum,$groupname,
1369: 'reenable');
1370: if ($result eq 'ok') {
1371: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
1372: $groupname);
1373: foreach my $key (sort(keys(%membership))) {
1374: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
1375: my $user = $1;
1376: my($end,$start,$userprivs) = split(/:/,$membership{$key},3);
1377: if (($start == -1) && ($end == $groupinfo{'modified'})) {
1378: $num_users ++;
1379: $usersettings{$groupname.':'.$user} = $defend.':'.
1380: $defstart.':'.
1381: $userprivs;
1382: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,
1383: $groupname,$user,
1384: $defend,$defstart,
1.76 raeburn 1385: $userprivs,'',
1386: $context) eq 'ok') {
1.65 raeburn 1387: $num_ok ++;
1388: push(@enabled,$user);
1389: } else {
1390: push(@unenabled,$user);
1391: $num_fail ++;
1392: }
1.64 raeburn 1393: }
1394: }
1395: }
1.65 raeburn 1396: if ($num_users > 0) {
1397: if ($num_ok > 0) {
1398: my $roster_result =
1399: &Apache::lonnet::modify_coursegroup_membership($cdom,$cnum,
1400: \%usersettings);
1401: if ($roster_result eq 'ok') {
1.79 bisitz 1402: $r->print('<div class="LC_success">'
1403: .&mt('Membership reinstated for [quant,_1,user], each with start and end dates for group access set to defaults: [_2] and [_3]',$num_ok,$showstart,$showend)
1404: .'</div>');
1.65 raeburn 1405: }
1406: } else {
1.79 bisitz 1407: $r->print('<div class="LC_error">'
1408: .&mt('A problem occurred when trying to reinstate [_1] of the [_2] members of the pre-existing group.',$num_fail,$num_users)
1409: .'</div>');
1.65 raeburn 1410: }
1411: } else {
1.79 bisitz 1412: $r->print('<div class="LC_info">'
1413: .&mt('There were no group members to reinstate, as none were removed when the group was deleted.')
1414: .'</div>');
1.65 raeburn 1415: }
1416: my $outcome = &reenable_folder($cdom,$cnum,$groupname,$description);
1417: if ($outcome eq '') {
1.79 bisitz 1418: $r->print('<div class="LC_success">'
1419: .&mt('Group successfully re-enabled.')
1420: .'</div>');
1421: } else {
1422: $r->print('<div class="LC_error">'
1423: .&mt("Although the group was re-enabled, an error occurred when adding the group's folder to the 'Course Groups' folder: [_1]",$outcome)
1424: .'</div>');
1.65 raeburn 1425: }
1426: } else {
1.79 bisitz 1427: $r->print('<div class="LC_error">'
1428: .&mt('Re-enabling group failed.')
1429: .'</div>');
1.64 raeburn 1430: }
1.66 raeburn 1431: return;
1.1 raeburn 1432: }
1433:
1434: sub header {
1.39 albertel 1435: my ($bodytitle,$jscript,$action,$state,$page,$loaditems) = @_;
1.9 albertel 1436: my $start_page=
1.11 albertel 1437: &Apache::loncommon::start_page($bodytitle,
1438: '<script type="text/javascript">'.
1439: $jscript.'</script>',
1.39 albertel 1440: {'add_entries' => $loaditems,});
1.3 raeburn 1441: my $output = <<"END";
1.11 albertel 1442: $start_page
1.9 albertel 1443: <form method="POST" name="$state">
1.3 raeburn 1444:
1445: END
1446: if ($action eq 'create' || $action eq 'modify') {
1447: $output .= <<"END";
1448: <input type="hidden" name="action" value="$action" />
1449: <input type="hidden" name="state" value="" />
1450: <input type="hidden" name="origin" value="$state" />
1.5 raeburn 1451: <input type="hidden" name="page" value="$page" />
1.3 raeburn 1452: END
1453: }
1454: return $output;
1.1 raeburn 1455: }
1456:
1.3 raeburn 1457: sub onload_action {
1458: my ($action,$state) = @_;
1.13 albertel 1459: my %loaditems;
1.3 raeburn 1460: if ((defined($env{'form.origin'})) && ($action eq 'create') &&
1461: ($state eq 'pick_name' || $state eq 'pick_members' ||
1462: $state eq 'pick_privs')) {
1463: unless ($env{'form.origin'} eq '') {
1.13 albertel 1464: $loaditems{'onload'} =
1465: 'javascript:setFormElements(document.'.$state.')';
1.1 raeburn 1466: }
1467: }
1.5 raeburn 1468: if (($action eq 'modify') &&
1469: ($state eq 'change_settings' || $state eq 'change_members' ||
1.53 raeburn 1470: $state eq 'change_privs' || $state eq 'add_members')) {
1.13 albertel 1471: $loaditems{'onload'} =
1472: 'javascript:setFormElements(document.'.$state.')';
1.5 raeburn 1473: }
1.13 albertel 1474: return \%loaditems;
1.1 raeburn 1475: }
1476:
1477: sub footer {
1.9 albertel 1478: my $end_page = &Apache::loncommon::end_page();
1.1 raeburn 1479: return(<<ENDFOOT);
1.6 raeburn 1480: <input type="hidden" name="sortby" value="$env{'form.sortby'}" />
1.1 raeburn 1481: </form>
1.9 albertel 1482: $end_page
1.1 raeburn 1483: ENDFOOT
1484: }
1485:
1.3 raeburn 1486: sub build_members_list {
1487: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata) = @_;
1488: my %access = ();
1489: foreach my $role (@{$roles}) {
1490: %{$$users{$role}} = ();
1491: }
1492: foreach my $type (@{$types}) {
1493: $access{$type} = $type;
1494: }
1495: &Apache::loncommon::get_course_users($cdom,$cnum,\%access,$roles,
1.5 raeburn 1496: $sections,$users,$userdata);
1.3 raeburn 1497: return;
1498: }
1499:
1500: sub group_files {
1.74 raeburn 1501: my ($group,$portpath,$numfiles,$numdirs) = @_;
1.29 raeburn 1502: my $dirptr=16384;
1.74 raeburn 1503: my @dir_list=&Apache::portfolio::get_dir_list($portpath,undef,$group);
1.29 raeburn 1504: foreach my $line (@dir_list) {
1505: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
1506: if (($filename !~ /^\.\.?$/) && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/) && ($filename ne 'no_such_dir')) {
1507: if ($dirptr&$testdir) {
1.74 raeburn 1508: $portpath .= '/'.$filename;
1.29 raeburn 1509: $$numdirs ++;
1.74 raeburn 1510: &group_files($group,$portpath,$numfiles,$numdirs)
1.29 raeburn 1511: } else {
1512: $$numfiles ++;
1513: }
1514: }
1515: }
1.3 raeburn 1516: return;
1517: }
1518:
1519: sub group_members {
1.4 raeburn 1520: my ($cdom,$cnum,$group,$group_info) = @_;
1521: my %memberhash = &Apache::lonnet::get_group_membership($cdom,$cnum,$group);
1522: my $now = time;
1.60 raeburn 1523: my %lt = &Apache::lonlocal::texthash (
1524: active => 'active',
1525: previous => 'previous',
1526: future => 'future',
1527: );
1528: my %membercounts = (
1529: active => 0,
1530: previous => 0,
1531: future => 0,
1532: );
1.4 raeburn 1533: my $totalmembers = 0;
1534: foreach my $member (keys %memberhash) {
1535: $totalmembers ++;
1536: my ($end,$start) = split(/:/,$memberhash{$member});
1.6 raeburn 1537: unless ($start == -1) {
1538: if (($end!=0) && ($end<$now)) {
1.60 raeburn 1539: $membercounts{previous} ++;
1.6 raeburn 1540: } elsif (($start!=0) && ($start>$now)) {
1.60 raeburn 1541: $membercounts{future} ++;
1.6 raeburn 1542: } else {
1.60 raeburn 1543: $membercounts{active} ++;
1.6 raeburn 1544: }
1.4 raeburn 1545: }
1546: }
1547: if ($totalmembers == 0) {
1548: $$group_info{$group}{'totalmembers'} = 'None';
1549: } else {
1.60 raeburn 1550: foreach my $type ('active','previous','future') {
1551: $$group_info{$group}{'totalmembers'} .=
1552: &open_list_window($group,$type,$membercounts{$type},$lt{$type});
1553: }
1.4 raeburn 1554: }
1555: return 'ok';
1.3 raeburn 1556: }
1557:
1.60 raeburn 1558: sub open_list_window {
1559: my ($group,$status,$count,$text) = @_;
1560: my $entry;
1561: if ($count > 0) {
1.83 bisitz 1562: $entry = '<span class="LC_nobreak"><a href="javascript:openGroupRoster('.
1.60 raeburn 1563: "'$group','$status'".')">'.$text.'</a> - '.$count.
1.83 bisitz 1564: '</span><br />';
1.60 raeburn 1565: } else {
1.83 bisitz 1566: $entry = '<span class="LC_nobreak">'.$text.' - '.$count.'</span><br />';
1.60 raeburn 1567: }
1568: return $entry;
1569: }
1570:
1.3 raeburn 1571:
1.5 raeburn 1572: sub general_settings_form {
1.46 albertel 1573: my ($r,$cdom,$cnum,$action,$formname,$page,$functions,$tools,
1.5 raeburn 1574: $toolprivs,$fixedprivs,$sectioncount,$stored,$states,$navbuttons,
1.46 albertel 1575: $gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 1576: my ($nexttext,$prevtext);
1.42 albertel 1577: &groupsettings_options($r,$functions,$action,$formname,$stored,1,
1.29 raeburn 1578: $gpterm,$ucgpterm,$crstype);
1.41 albertel 1579: &access_date_settings($r,$action,$formname,$stored,2,$gpterm,$ucgpterm);
1.5 raeburn 1580: if ($action eq 'create') {
1.59 raeburn 1581: &membership_options($r,$cdom,$cnum,$action,$formname,$sectioncount,3,
1582: $gpterm,$ucgpterm);
1.5 raeburn 1583: $nexttext = $$navbuttons{'gtns'};
1584: } else {
1585: my @available = ();
1586: my @unavailable = ();
1587: &check_tools($functions,$tools,\@available,\@unavailable);
1588: @{$tools} = sort(keys(%{$functions}));
1.46 albertel 1589: &privilege_specificity($r,$action,3,$tools,$stored,$toolprivs,
1590: $fixedprivs,\@available,$formname,
1591: $gpterm,$ucgpterm);
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.1 raeburn 1615: );
1.37 raeburn 1616: my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,$stored);
1.78 raeburn 1617: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$lt{'gnde'}).'
1.42 albertel 1618: <table class="LC_descriptive_input">
1.3 raeburn 1619: <tr>
1.42 albertel 1620: <td class="LC_description">'.$lt{'gnam'}.':</td>
1.5 raeburn 1621: <td colspan="5">
1622: ');
1623: if ($action eq 'create') {
1.53 raeburn 1624: $r->print('<input type="text" name="groupname" size="25" /> ('.
1625: $lt{'lett'}.')');
1.5 raeburn 1626: } else {
1627: $r->print('<input type="hidden" name="groupname" value="'.
1628: $env{'form.groupname'}.'" />'.$env{'form.groupname'});
1629: }
1630: $r->print(<<"END");
1.3 raeburn 1631: </td>
1632: <tr>
1633: <tr>
1.42 albertel 1634: <td class="LC_description">$lt{'desc'}:</td>
1.5 raeburn 1635: <td colspan="5"><input type="text" name="description" size="40"
1636: value="" />
1.3 raeburn 1637: </td>
1638: <tr>
1639: <tr>
1.42 albertel 1640: <td class="LC_description">$lt{'func'}:</td>
1.3 raeburn 1641: END
1642: my $numitems = keys(%{$functions});
1643: my $halfnum = int($numitems/2);
1644: my $remnum = $numitems%2;
1645: if ($remnum) {
1646: $halfnum ++;
1647: }
1.5 raeburn 1648: my @allfunctions = sort(keys (%{$functions}));
1.3 raeburn 1649: for (my $i=0; $i<$halfnum; $i++) {
1.7 raeburn 1650: $r->print('<td><label><input type="checkbox" name="tool" value="'.
1.3 raeburn 1651: $allfunctions[$i].'" /> '.
1.7 raeburn 1652: $$functions{$allfunctions[$i]}.'</label></td>
1.3 raeburn 1653: <td> </td><td> </td>');
1654: }
1.80 bisitz 1655: $r->print('<td><input type="button" value="'.&mt('check all').'" '.
1.3 raeburn 1656: 'onclick="javascript:checkAll(document.'.$formname.'.tool)" />'.
1657: '</td></tr><tr><td> </td>');
1658: for (my $j=$halfnum; $j<@allfunctions; $j++) {
1.7 raeburn 1659: $r->print('<td><label><input type="checkbox" name="tool" value="'.
1.3 raeburn 1660: $allfunctions[$j].'" /> '.
1.7 raeburn 1661: $$functions{$allfunctions[$j]}.'</label></td>
1.3 raeburn 1662: <td> </td><td> </td>');
1663: }
1664: if ($remnum) {
1665: $r->print('<td> </td>');
1666: }
1.5 raeburn 1667: $r->print('
1.3 raeburn 1668: <td>
1.80 bisitz 1669: <input type="button" value="'.&mt('uncheck all').'"
1.5 raeburn 1670: onclick="javascript:uncheckAll(document.'.$formname.'.tool)" />
1.3 raeburn 1671: </td>
1672: </tr>
1673: <tr>
1.42 albertel 1674: <td class="LC_description">'.&mt('Granularity:').'</td>
1.29 raeburn 1675: <td colspan="10">'.$lt{'doyo'}.' <label><input type="radio" name="granularity" value="Yes" />'.&mt('Yes').'</label> <label><input type="radio" name="granularity" value="No" checked="checked" />'.&mt('No').'</label>');
1.5 raeburn 1676: if ($action eq 'modify') {
1.82 bisitz 1677: $r->print(' ('.&mt('Currently set to [_1].'
1678: ,'"'.&mt($$stored{'granularity'}).'"').')');
1.5 raeburn 1679: }
1680: $r->print('
1681: </td>
1682: </tr>
1.29 raeburn 1683: <tr>
1.42 albertel 1684: <td class="LC_description">'.&mt('Disk quota: ').'</td><td colspan="10">');
1.29 raeburn 1685: if ($action eq 'create') {
1.79 bisitz 1686: $r->print(&mt('If you enable the file repository for the '.$gpterm.', allocate a disk quota.'));
1.29 raeburn 1687: } else {
1688: $r->print(&mt('Quota allocated to file repository:'));
1689: }
1.79 bisitz 1690: $r->print(' '.&mt('[_1] Mb','<input type="text" name="quota" size="4" />'));
1.29 raeburn 1691: if ($action eq 'create') {
1.79 bisitz 1692: $r->print('<br />'
1693: .&mt('A total of [_1] Mb can be divided amongst all '.$gpterm.'s in the '
1694: .lc($crstype).', and [_2] Mb are currently unallocated.'
1695: ,$crsquota,sprintf("%.2f",$freespace))
1696: );
1.29 raeburn 1697: } else {
1698: $r->print(' ('.&mt('The quota is currently [_1] Mb',
1699: $$stored{'quota'}).').');
1700:
1.79 bisitz 1701: $r->print('<br />'
1702: .&mt('The quota can be increased to [_1] Mb, '
1703: .'by adding all unallocated space for '.$gpterm.'s in the '.lc($crstype).'.'
1704: ,sprintf("%.2f",$maxposs)));
1.29 raeburn 1705: }
1706: $r->print('
1707: </td>
1708: </tr>
1.3 raeburn 1709: </table>
1.5 raeburn 1710: ');
1711: return;
1712: }
1713:
1.37 raeburn 1714: sub get_quota_constraints {
1715: my ($action,$stored) = @_;
1716: my ($crsquota,$freespace,$maxposs);
1717: $crsquota = $env{'course.'.$env{'request.course.id'}.'.internal.coursequota'};
1718: if ($crsquota eq '') {
1719: $crsquota = 20;
1720: }
1721: $freespace = $crsquota - &Apache::longroup::sum_quotas();
1722: if ($action eq 'create') {
1723: $maxposs = $freespace;
1724: } else {
1725: $maxposs = $$stored{'quota'} + $freespace;
1726: }
1727: return ($crsquota,$freespace,$maxposs);
1728: }
1729:
1.5 raeburn 1730: sub membership_options {
1.59 raeburn 1731: my ($r,$cdom,$cnum,$action,$state,$sectioncount,$image,$gpterm,$ucgpterm)=@_;
1.29 raeburn 1732: my $crstype = &Apache::loncommon::course_type();
1.5 raeburn 1733: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 1734: 'pipa' => 'Build a list of users for selection of group members',
1735: 'gmem' => "Group membership selection list criteria:",
1.5 raeburn 1736: 'picr' => 'Pick the criteria to use to build a list of '.
1.29 raeburn 1737: lc($crstype).' users from which you will select ',
1.53 raeburn 1738: 'meof' => "members of the new group.",
1739: 'admg' => "additional members of the group.",
1.29 raeburn 1740: 'ifno' => "If you do not wish to add members when you first ".
1.53 raeburn 1741: "create the group, there is no need to pick any criteria.",
1742: '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 1743: 'acty' => 'Access types',
1.29 raeburn 1744: 'coro' => $crstype.' roles',
1745: 'cose' => $crstype.' sections',
1.5 raeburn 1746: );
1747: my %status_types = (
1748: active => &mt('Currently has access'),
1749: previous => &mt('Previously had access'),
1750: future => &mt('Will have future access'),
1751: );
1.15 albertel 1752:
1.59 raeburn 1753: my @roles = ('st','cc','in','ta','ep','cr');
1.5 raeburn 1754:
1755: my @sections = keys(%{$sectioncount});
1756:
1.78 raeburn 1757: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$lt{'pipa'}).'
1.40 albertel 1758: <b>'.$lt{'gmem'}.'</b><br />'.$lt{'picr'});
1.5 raeburn 1759: if ($action eq 'create') {
1.21 raeburn 1760: $r->print($lt{'meof'}.'<br />'.$lt{'ifno'}.'<br />'.$lt{'asub'});
1.5 raeburn 1761: } else {
1.6 raeburn 1762: $r->print($lt{'admg'});
1.5 raeburn 1763: }
1764: $r->print('
1765: <br />
1766: <br />
1.40 albertel 1767: <table class="LC_status_selector">
1.3 raeburn 1768: <tr>
1.40 albertel 1769: <th>'.$lt{'acty'}.'</th>
1.53 raeburn 1770: <th>'.$lt{'coro'}.'</th>
1771: <th>'.$lt{'cose'}.'</th>
1772: </tr><tr><td>');
1.3 raeburn 1773: $r->print(&Apache::lonhtmlcommon::status_select_row(\%status_types));
1.40 albertel 1774: $r->print('</td><td>');
1.59 raeburn 1775: $r->print(&Apache::lonhtmlcommon::role_select_row(\@roles,undef,undef,1,$cdom,$cnum));
1.3 raeburn 1776: if (@sections > 0) {
1.5 raeburn 1777: @sections = sort {$a cmp $b} @sections;
1.31 albertel 1778: unshift(@sections,'none'); # Put 'no sections' next
1.17 raeburn 1779: unshift(@sections,'all'); # Put 'all' at the front of the list
1.53 raeburn 1780: } else {
1781: @sections = ('all','none');
1.3 raeburn 1782: }
1.53 raeburn 1783: $r->print('</td><td>'.
1784: §ions_selection(\@sections,'sectionpick').'</td>
1.3 raeburn 1785: </tr>
1.40 albertel 1786: </table>');
1.5 raeburn 1787: return;
1788: }
1789:
1790: sub sections_selection {
1791: my ($sections,$elementname) = @_;
1792: my $section_sel;
1793: my $numvisible = 4;
1794: if (@{$sections} < 4) {
1795: $numvisible = @{$sections};
1796: }
1797: foreach my $sec (@{$sections}) {
1.17 raeburn 1798: if ($sec eq 'all') {
1.53 raeburn 1799: $section_sel .= ' <option value="'.$sec.'">'.&mt('all sections').'</option>'."\n";
1.17 raeburn 1800: } elsif ($sec eq 'none') {
1.31 albertel 1801: $section_sel .= ' <option value="'.$sec.'">'.&mt('no section').'</option>'."\n";
1.5 raeburn 1802: } else {
1.31 albertel 1803: $section_sel .= ' <option value="'.$sec.'">'.$sec."</option>\n";
1.5 raeburn 1804: }
1805: }
1806: my $output = '
1.89 ! bisitz 1807: <select name="'.$elementname.'" multiple="multiple" size="'.$numvisible.'">
1.5 raeburn 1808: '.$section_sel.'
1809: </select>';
1810: return $output;
1811: }
1812:
1813: sub access_date_settings {
1.41 albertel 1814: my ($r,$action,$formname,$stored,$image,$gpterm,$ucgpterm) = @_;
1.80 bisitz 1815: my $sten = &mt("Default start and end dates for $gpterm access");
1.5 raeburn 1816: my $starttime = time;
1817: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1818: if ($action eq 'modify') {
1819: $starttime = $$stored{'startdate'};
1820: unless ($$stored{'enddate'} == 0) {
1821: $endtime = $$stored{'enddate'};
1822: }
1823: }
1.41 albertel 1824: my ($table) = &date_setting_table($starttime,$endtime,$formname);
1.80 bisitz 1825: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$sten).'
1.41 albertel 1826: '.$table.'
1827: ');
1.3 raeburn 1828: return;
1829: }
1830:
1.5 raeburn 1831: sub choose_members_form {
1.46 albertel 1832: my ($r,$cdom,$cnum,$action,$formname,$page,$groupname,$description,
1.29 raeburn 1833: $granularity,$quota,$startdate,$enddate,$tools,$fixedprivs,$toolprivs,
1.5 raeburn 1834: $functions,$users,$userdata,$idx,$stored,$states,$navbuttons,
1.46 albertel 1835: $gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 1836: my @regexps = ('user_','userpriv_','sec_');
1837: my %origmembers;
1.3 raeburn 1838: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.5 raeburn 1839: ['origin','action','state','page','member','specificity','branch',
1.7 raeburn 1840: 'defpriv','autorole','autoadd','autodrop','sortby','togglefunc'],
1.5 raeburn 1841: \@regexps));
1.29 raeburn 1842: my $earlyout = &validate_groupname($groupname,$action,$cdom,$cnum,$gpterm,
1843: $ucgpterm,$crstype);
1.5 raeburn 1844: if ($earlyout) {
1.47 raeburn 1845: $r->print($earlyout);
1.5 raeburn 1846: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1847: $$navbuttons{'gtps'});
1.3 raeburn 1848: return;
1.5 raeburn 1849: }
1850: my ($specimg,$memimg);
1851: my @available = ();
1852: my @unavailable = ();
1853: &check_tools($functions,$tools,\@available,\@unavailable);
1854: if ($action eq 'create') {
1.40 albertel 1855: &print_current_settings($r,$action,$functions,$startdate,$enddate,
1856: $groupname,$description,$granularity,$quota,
1857: \@available,\@unavailable,$gpterm,$ucgpterm);
1.5 raeburn 1858: $specimg = 4;
1859: $memimg = 5;
1860: } else {
1861: $specimg = 2;
1862: $memimg = 3;
1863: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
1864: $groupname);
1865: foreach my $key (sort(keys(%membership))) {
1866: if ($key =~ /^\Q$groupname\E:([^:]+):([^:]+)$/) {
1.6 raeburn 1867: my ($end,$start,@userprivs) = split(/:/,$membership{$key});
1868: unless ($start == -1) {
1869: my $uname = $1;
1870: my $udom = $2;
1871: my $user = $uname.':'.$udom;
1872: $origmembers{$user} = 1;
1873: }
1.5 raeburn 1874: }
1875: }
1876: }
1.46 albertel 1877: &privilege_specificity($r,$action,$specimg,$tools,$stored,$toolprivs,
1.29 raeburn 1878: $fixedprivs,\@available,$formname,$gpterm,$ucgpterm);
1.44 albertel 1879: my $newusers = &pick_new_members($r,$action,$formname,\@available,$idx,
1880: $stored,$memimg,$users,$userdata,
1881: $granularity,\%origmembers,$gpterm,
1882: $ucgpterm);
1.5 raeburn 1883: if ($newusers || $action eq 'create') {
1884: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1885: $$navbuttons{'gtps'},$$states{$action}[$page+1],
1886: $$navbuttons{'gtns'});
1887: } else {
1888: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1889: $$navbuttons{'gtps'});
1.3 raeburn 1890: }
1.5 raeburn 1891: return;
1892: }
1893:
1894: sub display_navbuttons {
1895: my ($r,$formname,$prev,$prevtext,$next,$nexttext) = @_;
1.42 albertel 1896: $r->print('<div class="LC_navbuttons">');
1.5 raeburn 1897: if ($prev) {
1898: $r->print('
1899: <input type="button" name="previous" value = "'.$prevtext.'"
1900: onclick="javascript:backPage(document.'.$formname.','."'".$prev."'".')"/>
1901: ');
1.64 raeburn 1902: } elsif ($prevtext) {
1903: $r->print('
1904: <input type="button" name="previous" value = "'.$prevtext.'"
1905: onclick="javascript:history.back()"/>
1906: ');
1.5 raeburn 1907: }
1908: if ($next) {
1909: $r->print('
1910: <input type="button" name="next" value="'.$nexttext.'"
1911: onclick="javascript:nextPage(document.'.$formname.','."'".$next."'".')" />');
1912: }
1.42 albertel 1913: $r->print('</div>');
1.5 raeburn 1914: }
1915:
1916: sub check_tools {
1917: my ($functions,$tools,$available,$unavailable) = @_;
1918: foreach my $item (sort(keys(%{$functions}))) {
1919: if (grep/^$item$/,@{$tools}) {
1920: push(@{$available},$item);
1921: } else {
1922: push(@{$unavailable},$item);
1923: }
1924: }
1925: return;
1926: }
1927:
1928: sub print_current_settings {
1.40 albertel 1929: my ($r,$action,$functions,$startdate,$enddate,$groupname,$description,
1930: $granularity,$quota,$available,$unavailable,$gpterm,$ucgpterm) = @_;
1.5 raeburn 1931:
1932: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 1933: grna => 'Group Name',
1934: desc => 'Group Title',
1935: grfn => "Collaborative Tools",
1.5 raeburn 1936: gran => 'Granularity',
1.29 raeburn 1937: quot => 'File quota',
1.5 raeburn 1938: dfac => 'Default access dates',
1.53 raeburn 1939: ygrs => "Your group selections - ",
1940: tfwa => "The following settings will apply to the group:",
1941: difn => 'Different collaborative tools<br />for different members:',
1.80 bisitz 1942: stda => 'Start date:',
1.5 raeburn 1943: enda => 'End date:',
1944: );
1.3 raeburn 1945: my $showstart = &Apache::lonlocal::locallocaltime($startdate);
1.5 raeburn 1946: my $showend;
1947: if ($enddate == 0) {
1948: $showend = &mt('No end date set');
1949: } else {
1950: $showend = &Apache::lonlocal::locallocaltime($enddate);
1951: }
1952: if ($action eq 'create') {
1953: $r->print('
1.42 albertel 1954: <div><span style="font-size: larger">'.$lt{'ygrs'}.'</span>
1.5 raeburn 1955: <br />'.$lt{'tfwa'}.'
1.40 albertel 1956: </div>');
1.5 raeburn 1957: }
1.40 albertel 1958: $r->print(&Apache::loncommon::start_data_table('LC_course_group_status').
1959: &Apache::loncommon::start_data_table_header_row());
1960: $r->print('
1961: <th>'.$lt{'grna'}.'</th>
1962: <th>'.$lt{'desc'}.'</th>
1963: <th>'.$lt{'grfn'}.'</th>
1964: <th>'.$lt{'gran'}.'</th>
1965: <th>'.$lt{'quot'}.'</th>
1966: <th>'.$lt{'dfac'}.'</th>
1967: ');
1968: $r->print(&Apache::loncommon::end_data_table_header_row().
1969: &Apache::loncommon::start_data_table_row('LC_data_table_dense'));
1.3 raeburn 1970: $r->print('
1.40 albertel 1971: <td valign="top">'.$groupname.'</td>
1972: <td valign="top">'.$description.'</td>
1.3 raeburn 1973: <td>
1974: ');
1.5 raeburn 1975: if (@{$available} > 0) {
1.79 bisitz 1976: $r->print('<b>'.&mt('Available for assignment to members:').'</b>'.
1.53 raeburn 1977: '<table class="LC_group_priv"><tr>');
1.5 raeburn 1978: my $rowcell = int(@{$available}/2) + @{$available}%2;
1979: for (my $i=0; $i<@{$available}; $i++) {
1980: if (@{$available} > 3) {
1.3 raeburn 1981: if ($i==$rowcell) {
1982: $r->print('</tr><tr>');
1983: }
1984: }
1.40 albertel 1985: $r->print('<td>'.$$functions{$$available[$i]}.
1986: '</td><td> </td>');
1.3 raeburn 1987: }
1.5 raeburn 1988: if ((@{$available} > 3) && (@{$available}%2)) {
1.3 raeburn 1989: $r->print('<td> </td><td> </td>');
1990: }
1991: $r->print('</tr></table><br />');
1992: }
1.5 raeburn 1993: if (@{$unavailable} > 0) {
1.80 bisitz 1994: $r->print('<b>'.&mt('Unavailable for assignment:').'</b>'.
1.53 raeburn 1995: '<table class="LC_group_priv"><tr>');
1.5 raeburn 1996: my $rowcell = int(@{$unavailable}/2) + @{$unavailable}%2;
1997: for (my $j=0; $j<@{$unavailable}; $j++) {
1998: if (@{$unavailable} > 3) {
1.3 raeburn 1999: if ($j==$rowcell) {
2000: $r->print('</tr><tr>');
2001: }
2002: }
1.40 albertel 2003: $r->print('<td>'.$$functions{$$unavailable[$j]}.
2004: '</td><td> </td>');
1.3 raeburn 2005: }
1.5 raeburn 2006: if ((@{$unavailable} > 3) && (@{$unavailable}%2)) {
1.3 raeburn 2007: $r->print('<td> </td><td> </td>');
2008: }
2009: $r->print('</tr></table>');
2010: }
1.79 bisitz 2011: my $quota_text=&mt('[_1] Mb',$quota);
1.80 bisitz 2012: my $granu_text=&mt($granularity);
1.3 raeburn 2013: $r->print(<<"END");
2014: </td>
1.80 bisitz 2015: <td valign="top"><b>$lt{'difn'}</b> $granu_text</td>
1.79 bisitz 2016: <td valign="top">$quota_text</td>
1.40 albertel 2017: <td valign="top"><b>$lt{'stda'}</b> $showstart<br />
2018: <b>$lt{'enda'}</b> $showend
1.3 raeburn 2019: </td>
2020: END
1.40 albertel 2021: $r->print(&Apache::loncommon::end_data_table_row().
2022: &Apache::loncommon::end_data_table());
1.5 raeburn 2023: return;
2024: }
2025:
2026: sub pick_new_members {
1.44 albertel 2027: my ($r,$action,$formname,$available,$idx,$stored,$img,$users,$userdata,
2028: $granularity,$origmembers,$gpterm,$ucgpterm) = @_;
1.5 raeburn 2029: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 2030: 'gpme' => "Group membership",
1.5 raeburn 2031: 'addm' => 'Add members',
1.53 raeburn 2032: 'setf' => 'Assign collaborative tools',
2033: 'func' => 'Tools',
2034: 'nome' => 'No members to add at this time, as there are no users '.
2035: 'matching the specified type(s), role(s) and section(s).',
1.29 raeburn 2036: 'nnew' => "There are no users to add as new members, as all users".
1.53 raeburn 2037: " matching the specified type(s), role(s), and ".
2038: "section(s) are already affiliated with this group.",
1.79 bisitz 2039: 'yoma' => "You may need to use the 'modify existing, past or ".
2040: "future members' page if you need to re-enable ".
2041: "or activate access for previous or future members.",
1.5 raeburn 2042: );
2043: my %members;
2044: my $totalusers = 0;
2045: my $newusers = 0;
1.3 raeburn 2046: foreach my $role (keys(%{$users})) {
2047: foreach my $user (keys(%{$$users{$role}})) {
1.5 raeburn 2048: $totalusers ++;
2049: if (ref($origmembers) eq 'HASH') {
2050: if (exists($$origmembers{$user})) {
2051: next;
2052: }
2053: }
1.3 raeburn 2054: unless (defined($members{$user})) {
2055: @{$members{$user}} = @{$$userdata{$user}};
1.5 raeburn 2056: $newusers ++;
1.3 raeburn 2057: }
2058: }
2059: }
2060: if (keys(%members) > 0) {
1.5 raeburn 2061: if (@{$available} > 0 && $granularity eq 'Yes') {
2062: $r->print(&check_uncheck_tools($r,$available));
2063: }
2064: }
1.78 raeburn 2065: $r->print(&Apache::lonhtmlcommon::topic_bar($img,$lt{'gpme'}));
1.5 raeburn 2066: if (keys(%members) > 0) {
2067: $r->print('
1.3 raeburn 2068: <table>
1.5 raeburn 2069: <tr>');
2070: &check_uncheck_buttons($r,$formname,'member',$lt{'addm'});
2071: if (@{$available} > 0 && $granularity eq 'Yes') {
1.48 albertel 2072: $r->print('<td>
1.5 raeburn 2073: <fieldset><legend><b>'.$lt{'setf'}.'</b></legend>
1.83 bisitz 2074: <span class="LC_nobreak">
1.80 bisitz 2075: <input type="button" value="'.&mt('check all').'"
1.5 raeburn 2076: onclick="javascript:checkAllTools(document.'.$formname.')" />
2077:
1.80 bisitz 2078: <input type="button" value="'.&mt('uncheck all').'"
1.3 raeburn 2079: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
1.83 bisitz 2080: </span>
1.48 albertel 2081: </fieldset></td>');
1.3 raeburn 2082: }
2083: $r->print('</tr></table>
2084: ');
1.43 albertel 2085: $r->print(&Apache::loncommon::start_data_table().
2086: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 2087: $r->print('
1.43 albertel 2088: <th>'.&mt('Add?').'</b></td>
2089: <th><a href="javascript:changeSort('."'fullname'".')">'.&mt('Name').'</a></td>
2090: <th><a href="javascript:changeSort('."'username'".')">'.&mt('Username').'</a></td>
2091: <th><a href="javascript:changeSort('."'domain'".')">'.&mt('Domain').'</a></td>
2092: <th><a href="javascript:changeSort('."'id'".')">'.&mt('ID').'</a></td>
2093: <th><a href="javascript:changeSort('."'section'".')">'.&mt('Section').'</a></td>
1.5 raeburn 2094: ');
2095: if (@{$available} > 0) {
1.43 albertel 2096: $r->print('<th>'.$lt{'func'}.'</th>');
1.3 raeburn 2097: }
1.43 albertel 2098: $r->print(&Apache::loncommon::end_data_table_header_row());
1.5 raeburn 2099: if (@{$available} > 0) {
2100: if ($granularity eq 'Yes') {
1.43 albertel 2101: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense LC_data_table_highlight').'
1.35 raeburn 2102: <td colspan="6"> </td>
1.83 bisitz 2103: <td align="center"><span class="LC_nobreak"><b>'.&mt('All:').'</b> ');
1.5 raeburn 2104: foreach my $tool (@{$available}) {
1.7 raeburn 2105: $r->print('<label><input type="checkbox" name="togglefunc" '.
2106: 'onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
2107: ' value="'.$tool.'">'.'<b>'.$tool.'</b></label> ');
1.5 raeburn 2108: }
1.83 bisitz 2109: $r->print('</span></td></tr>');
1.5 raeburn 2110: }
2111: }
1.3 raeburn 2112: my %Sortby = ();
2113: foreach my $user (sort(keys(%members))) {
2114: if ($env{'form.sortby'} eq 'fullname') {
2115: push(@{$Sortby{$members{$user}[$$idx{fullname}]}},$user);
2116: } elsif ($env{'form.sortby'} eq 'username') {
2117: push(@{$Sortby{$members{$user}[$$idx{uname}]}},$user);
2118: } elsif ($env{'form.sortby'} eq 'domain') {
2119: push(@{$Sortby{$members{$user}[$$idx{udom}]}},$user);
2120: } elsif ($env{'form.sortby'} eq 'id') {
2121: push(@{$Sortby{$members{$user}[$$idx{id}]}},$user);
1.31 albertel 2122: } elsif ($env{'form.sortby'} eq 'section') {
2123: push(@{$Sortby{$members{$user}[$$idx{section}]}},$user);
1.3 raeburn 2124: } else {
2125: push(@{$Sortby{$members{$user}[$$idx{fullname}]}},$user);
2126: }
2127: }
2128: foreach my $key (sort(keys(%Sortby))) {
2129: foreach my $user (@{$Sortby{$key}}) {
2130: my $id = $members{$user}[$$idx{id}];
2131: my $fullname = $members{$user}[$$idx{fullname}];
2132: my $udom = $members{$user}[$$idx{udom}];
2133: my $uname = $members{$user}[$$idx{uname}];
1.31 albertel 2134: my $section = $members{$user}[$$idx{section}];
1.43 albertel 2135: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense').
2136: '<td align="right"><input type="checkbox" name="member" value="'.$user.'" /></td>'.
2137: '<td>'.$fullname.'</td>'.
2138: '<td>'.$uname.'</td>'.
2139: '<td>'.$udom.'</td>'.
2140: '<td>'.$id.'</td>'.
2141: '<td>'.$section.'</td>');
1.5 raeburn 2142: if (@{$available} > 0) {
1.83 bisitz 2143: $r->print('<td align="center"><span class="LC_nobreak">'.
1.5 raeburn 2144: ' ');
2145: foreach my $tool (@{$available}) {
2146: if ($granularity eq 'Yes') {
1.3 raeburn 2147: $r->print('<input type="checkbox" name="user_'.
2148: $tool.'" value="'.$user.'" />'.$tool.' ');
2149: } else {
2150: $r->print('<input type="hidden" name="user_'.
2151: $tool.'" value="'.$user.'" />'.$tool.' ');
2152: }
2153: }
1.83 bisitz 2154: $r->print('</span></td>');
1.3 raeburn 2155: }
1.43 albertel 2156: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.3 raeburn 2157: }
2158: }
1.43 albertel 2159: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 2160: } else {
2161: if ($totalusers > 0) {
2162: $r->print($lt{'nnew'}.'<br /><br />'.$lt{'yoma'});
2163: } else {
2164: $r->print($lt{'nome'});
2165: }
2166: }
2167: return $newusers;
2168: }
2169:
2170: sub privilege_specificity {
1.46 albertel 2171: my ($r,$action,$img,$tools,$stored,$toolprivs,$fixedprivs,$available,
2172: $formname,$gpterm,$ucgpterm) = @_;
1.5 raeburn 2173: my %lt = &Apache::lonlocal::texthash (
1.53 raeburn 2174: 'uprv' => 'User privileges for collaborative tools',
2175: 'frty' => 'For each collaborative tool you have chosen to include, '.
2176: 'there is a set of core privileges which all group members '.
2177: 'assigned use of the tool will receive.',
2178: 'thar' => 'For some tools there are also additional optional '.
2179: 'privileges which can be set.',
2180: 'plch' => 'Choose one of the following:',
2181: 'fort' => 'For the collaborative tools you have chosen to include '.
2182: 'only core privileges are available, '.
2183: 'so there are no optional privileges to assign.',
2184: 'eaty' => 'Each collaborative tool includes core '.
2185: 'privileges assigned to all members with access to the '.
2186: 'tool. Some tools may also feature additional privileges '.
1.5 raeburn 2187: 'which can be set for specific members.',
1.53 raeburn 2188: 'cutg' => 'Currently the group is configured ',
2189: 'sdif' => 'so different members can receive different optional privileges for a particular tool.',
2190: 'sall' => 'so all members will receive the same optional privileges for a particular tool.',
2191: 'algm' => 'All group members will receive the same privileges for any tool assigned to them, including the default set of optional privileges.',
2192: 'smgp' => 'Different group members may receive different privileges from '.
2193: 'others for the tools they have been assigned.',
2194: 'thwi' => 'These will be the privileges all group members receive for a particular assigned tool, '.
2195: 'if you selected the first option above.',
1.29 raeburn 2196: 'thes' => "These will be the privileges given to members assigned ".
1.53 raeburn 2197: "in the future via automatic group assignment ".
2198: "for users who receive specific sections/roles in the course ",
2199: 'asyo' => "As you have chosen not to include any collaborative tools ".
2200: "in the group, no default optional privileges need to be set.",
2201: 'plin' => 'Indicate which <b>optional</b> privileges members '.
2202: 'will receive by default for a specific tool.',
1.5 raeburn 2203: 'oppr' => 'Optional privileges',
2204: 'defp' => 'The default privileges new members will receive are:',
2205: );
2206: my $totaloptionalprivs = 0;
2207: foreach my $tool (@{$tools}) {
2208: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2209: if (!exists($$fixedprivs{$tool}{$priv})) {
2210: $totaloptionalprivs ++;
2211: }
2212: }
2213: }
1.78 raeburn 2214: $r->print(&Apache::lonhtmlcommon::topic_bar($img,$lt{'uprv'}));
1.5 raeburn 2215: if ((($action eq 'create') && (@{$available} > 0)) ||
1.55 raeburn 2216: (($action eq 'modify') && ($formname eq 'change_settings'))) {
1.5 raeburn 2217: my %specific = (
2218: 'No' => 'checked="checked"',
2219: 'Yes' => '',
2220: );
2221: if ($action eq 'create') {
2222: $r->print($lt{'frty'}.'<br />');
2223: if ($totaloptionalprivs) {
1.53 raeburn 2224: $r->print($lt{'thar'}.'<br /><br />'.$lt{'plch'});
1.5 raeburn 2225: } else {
2226: $r->print($lt{'fort'});
2227: }
2228: } else {
2229: $r->print($lt{'eaty'}.' '.$lt{cutg});
2230: if ($$stored{'specificity'} eq 'Yes') {
2231: $r->print($lt{'sdif'});
2232: $specific{'Yes'} = $specific{'No'};
2233: $specific{'No'} = '';
2234: } else {
2235: $r->print($lt{'sall'});
2236: }
2237: }
2238: if ($totaloptionalprivs) {
2239: $r->print('
1.53 raeburn 2240: <br />
1.83 bisitz 2241: <label><span class="LC_nobreak"><input type="radio" name="specificity" value="No" '.$specific{'No'}.' /> '.$lt{'algm'}.'</span></label><br />
2242: <label><span class="LC_nobreak"><input type="radio" name="specificity" value="Yes" '.$specific{'Yes'}.' /> '.$lt{'smgp'}.'</span></label><br /><br />');
1.5 raeburn 2243: } else {
2244: $r->print('<input type="hidden" name="specificity" value="No" />');
2245: }
2246: if ($totaloptionalprivs) {
1.40 albertel 2247: $r->print($lt{'plin'});
1.5 raeburn 2248: if ($action eq 'create') {
1.53 raeburn 2249: $r->print('<br />'.$lt{'thwi'});
1.5 raeburn 2250: }
2251: $r->print('<br />'.$lt{'thes'});
2252: if ($action eq 'create') {
2253: $r->print('('.&mt('if enabled on the next page').').');
2254: } else {
2255: $r->print('('.&mt('if enabled below').').');
2256: }
2257: $r->print('<br /><br />
1.40 albertel 2258: <table><tr>');
1.5 raeburn 2259: &check_uncheck_buttons($r,$formname,'defpriv',$lt{'oppr'});
2260: $r->print('
2261: </tr>
2262: </table>
1.3 raeburn 2263: <br />
2264: ');
1.5 raeburn 2265: } else {
1.40 albertel 2266: $r->print($lt{'algm'}.'<br /><br />');
1.3 raeburn 2267: }
1.42 albertel 2268: &default_privileges($r,$action,$tools,$toolprivs,$fixedprivs,
2269: $available);
1.3 raeburn 2270: } else {
1.5 raeburn 2271: if ($action eq 'create') {
2272: $r->print($lt{'asyo'});
1.55 raeburn 2273: $r->print('<input type="hidden" name="specificity" value="No" />');
1.5 raeburn 2274: } elsif ($action eq 'modify' && $formname eq 'pick_members') {
2275: my @defprivs;
2276: if (ref($$stored{'defpriv'}) eq 'ARRAY') {
2277: @defprivs = @{$$stored{'defpriv'}};
2278: }
2279: $r->print($lt{'eaty'}.' '.$lt{cutg});
2280: if ($$stored{'specificity'} eq 'Yes') {
2281: $r->print($lt{'sdif'});
2282: } else {
2283: $r->print($lt{'sall'});
2284: }
2285: $r->print(' '.$lt{'defp'}.'<br /><br />');
1.45 albertel 2286: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 2287: }
1.3 raeburn 2288: }
2289: return;
2290: }
2291:
1.5 raeburn 2292: sub default_privileges {
1.42 albertel 2293: my ($r,$action,$tools,$toolprivs,$fixedprivs,$available) = @_;
1.5 raeburn 2294: my %lt = &Apache::lonlocal::texthash(
2295: 'addp' => 'Additional privileges',
2296: 'fixp' => 'Fixed privileges',
2297: 'oppr' => 'Optional privileges',
1.53 raeburn 2298: 'func' => 'Collaborative Tool',
1.5 raeburn 2299: );
1.42 albertel 2300: $r->print(&Apache::lonhtmlcommon::start_pick_box('LC_group_priv_box').
2301: &Apache::lonhtmlcommon::row_title($lt{'func'},undef,
2302: 'LC_groups_functionality'));
2303: $r->print(join('</td><td class="LC_groups_functionality">',@{$tools}));
2304: $r->print(&Apache::lonhtmlcommon::row_closure(1));
2305: my $fixed = '';
2306: my $dynamic = '';
1.3 raeburn 2307: foreach my $tool (@{$tools}) {
1.5 raeburn 2308: my $privcount = 0;
1.42 albertel 2309: if ($dynamic ne '') {
2310: $dynamic .= '</td><td class="LC_groups_optional">';
2311: }
2312: $dynamic .= '<table class="LC_group_priv"><tr>';
1.5 raeburn 2313: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2314: if (exists($$fixedprivs{$tool}{$priv})) {
1.42 albertel 2315: if ($fixed ne '') {
2316: $fixed .= '</td><td class="LC_groups_fixed">';
2317: }
1.79 bisitz 2318: $fixed .= '<input type="hidden" name="defpriv" value="'.$priv.'" />'
2319: .'<span class="LC_nobreak">'.$$toolprivs{$tool}{$priv}.' ';
1.5 raeburn 2320: if ($action eq 'modify') {
1.42 albertel 2321: if (grep(/^$tool$/,@{$available})) {
1.5 raeburn 2322: $fixed .= '<small>'.&mt('(on)').'<small> ';
2323: } else {
2324: $fixed .= '<small>'.&mt('(off)').'<small> ';
1.3 raeburn 2325: }
2326: }
1.79 bisitz 2327: $fixed .= '</span>';
1.5 raeburn 2328: } else {
1.42 albertel 2329: $privcount++;
1.5 raeburn 2330: if ($privcount == 3) {
2331: $dynamic .= '</tr>
1.42 albertel 2332: <tr>'."\n";
1.5 raeburn 2333: }
1.79 bisitz 2334: $dynamic .= '<td><span class="LC_nobreak"><label><input type="checkbox" name="defpriv" value="'.$priv.'" />'.$$toolprivs{$tool}{$priv}.'</label></span></td>'."\n";
1.3 raeburn 2335: }
2336: }
1.42 albertel 2337: if ($privcount == 0) {
1.79 bisitz 2338: $dynamic .= '<td>'.&mt('None').'</td>'."\n";
1.5 raeburn 2339: }
2340: if ($privcount < 3) {
1.53 raeburn 2341: $dynamic .= '<td> </td>'."\n";
1.5 raeburn 2342: } elsif ($privcount%2) {
2343: $dynamic = '<td> </td>'."\n";
2344: }
1.42 albertel 2345: $dynamic .= '</tr></table>';
1.3 raeburn 2346: }
1.42 albertel 2347: $r->print(&Apache::lonhtmlcommon::row_title($lt{'fixp'},undef,
2348: 'LC_groups_fixed').
2349: $fixed.
2350: &Apache::lonhtmlcommon::row_closure(1));
2351: $r->print(&Apache::lonhtmlcommon::row_title($lt{'oppr'},undef,
2352: 'LC_groups_optional').
2353: $dynamic.
2354: &Apache::lonhtmlcommon::end_pick_box());
1.5 raeburn 2355: $r->print('<br />');
2356: return;
1.42 albertel 2357:
1.5 raeburn 2358: }
2359:
2360: sub display_defprivs {
1.45 albertel 2361: my ($r,$tools,$toolprivs,$defprivs) = @_;
2362: my $function = &Apache::loncommon::get_users_function();
2363: my $tabcol = &Apache::loncommon::designparm($function.'.tabbg');
2364: my $rowColor1 = "#dddddd";
2365: my $rowColor2 = "#eeeeee";
1.5 raeburn 2366: my %lt = &Apache::lonlocal::texthash(
2367: 'priv' => 'Privileges',
1.53 raeburn 2368: 'func' => 'Collaborative Tool',
1.5 raeburn 2369: );
2370: $r->print(&Apache::lonhtmlcommon::start_pick_box());
2371: $r->print('<tr>');
2372: my $numrows = 0;
2373: my %currprivs;
2374: foreach my $tool (@{$tools}) {
2375: @{$currprivs{$tool}} = ();
2376: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2377: if (ref($defprivs) eq 'ARRAY') {
1.45 albertel 2378: if (grep(/^\Q$priv\E$/,@{$defprivs})) {
1.5 raeburn 2379: push(@{$currprivs{$tool}},$priv);
2380: }
1.3 raeburn 2381: }
2382: }
1.5 raeburn 2383: my $rowcount = int(@{$currprivs{$tool}}/3);
2384: if (@{$currprivs{$tool}}%3 > 0) {
2385: $rowcount ++;
2386: }
2387: if ($rowcount > $numrows) {
2388: $numrows = $rowcount;
2389: }
2390: }
2391: my @rowCols = ($rowColor1,$rowColor2);
2392: foreach my $tool (@{$tools}) {
2393: $r->print('<td align="center" valign="top">
2394: <table cellspacing="0" cellpadding="5">
2395: <tr bgcolor="#cccccc">
2396: <td colspan="3" align="center"><b>'.$tool.'</b></td>
2397: </tr>
2398: ');
2399: my $rownum = 1;
2400: my $privcount = 0;
2401: $r->print('<tr bgcolor="'.$rowColor1.'">');
2402: foreach my $priv (@{$currprivs{$tool}}) {
2403: $privcount ++;
2404: if ($privcount%4 == 0) {
2405: $rownum ++;
2406: my $bgcol = $rownum%2;
2407: $r->print('</tr>
2408: <tr bgcolor="'.$rowCols[$bgcol].'">'."\n");
2409: }
2410: $r->print('<td>'.$$toolprivs{$tool}{$priv}.'</td>'."\n");
2411: }
2412: if ($privcount%3 > 0) {
2413: my $emptycells = 3-($privcount%3);
2414: while($emptycells > 0) {
2415: $r->print('<td> </td>'."\n");
2416: $emptycells --;
2417: }
2418: }
2419: while ($rownum < $numrows) {
2420: $rownum ++;
2421: my $bgcol = $rownum%2;
2422: $r->print('<tr bgcolor="'.$rowCols[$bgcol].'"><td colspan="3"> </td></tr>');
1.3 raeburn 2423: }
1.5 raeburn 2424: $r->print('</table>'."\n".'</td>');
2425: }
2426: $r->print('</tr>'."\n");
2427: $r->print(&Apache::lonhtmlcommon::end_pick_box());
2428: $r->print('<br />');
2429: return;
1.3 raeburn 2430: }
1.5 raeburn 2431:
2432:
2433: sub change_members_form {
1.48 albertel 2434: my ($r,$cdom,$cnum,$action,$formname,$page,$groupname,$description,
1.5 raeburn 2435: $startdate,$enddate,$tools,$fixedprivs,$functions,$users,$userdata,
1.48 albertel 2436: $granularity,$quota,$specificity,$idx,$states,$navbuttons,$gpterm,
2437: $ucgpterm) = @_;
1.5 raeburn 2438: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 2439: grse => "$ucgpterm settings",
2440: mogm => "Modify $gpterm membership",
1.5 raeburn 2441: );
2442: my @regexps = ('user_','userpriv_');
2443: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2444: ['origin','action','state','page','expire','deletion',
1.7 raeburn 2445: 'reenable','activate','changepriv','sortby',
2446: 'togglefunc'],\@regexps));
1.5 raeburn 2447: my $rowimg = 1;
2448: my @available = ();
2449: my @unavailable = ();
2450: &check_tools($functions,$tools,\@available,\@unavailable);
2451: my $nexttext = $$navbuttons{'gtns'};
2452: my $prevtext = $$navbuttons{'gtpp'};
2453: $r->print('
1.3 raeburn 2454: <br />
1.5 raeburn 2455: ');
1.78 raeburn 2456: $r->print(&Apache::lonhtmlcommon::topic_bar(1,$lt{'grse'}));
1.40 albertel 2457: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2458: $groupname,$description,$granularity,$quota,
2459: \@available,\@unavailable,$gpterm,$ucgpterm);
1.78 raeburn 2460: $r->print(&Apache::lonhtmlcommon::topic_bar(2,$lt{'mogm'}));
1.53 raeburn 2461: my $numcurrent = ¤t_membership($r,$cdom,$cnum,$formname,$groupname,
2462: \@available,\@unavailable,$fixedprivs,
2463: $granularity,$specificity);
2464: if ($numcurrent > 0) {
2465: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2466: $$states{$action}[$page+1],$nexttext);
2467: } else {
2468: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext);
2469: }
1.5 raeburn 2470: return;
2471: }
2472:
2473: sub current_membership {
1.48 albertel 2474: my ($r,$cdom,$cnum,$formname,$groupname,$available,$unavailable,
2475: $fixedprivs,$granularity,$specificity) = @_;
1.5 raeburn 2476: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
2477: $groupname);
2478: my %lt = &Apache::lonlocal::texthash(
1.6 raeburn 2479: 'actn' => 'Action?',
2480: 'name' => 'Name',
2481: 'usnm' => 'Username',
2482: 'doma' => 'Domain',
2483: 'stda' => 'Start Date',
2484: 'enda' => 'End Date',
1.5 raeburn 2485: 'expi' => 'Expire',
2486: 'reen' => 'Re-enable',
2487: 'acti' => 'Activate',
2488: 'dele' => 'Delete',
1.53 raeburn 2489: 'curf' => 'Current Tool Set',
1.5 raeburn 2490: 'chpr' => 'Change Privileges'
2491: );
1.52 raeburn 2492: my ($current,$num_items,$hastools,$addtools) =
1.36 raeburn 2493: &Apache::longroup::group_memberlist($cdom,$cnum,$groupname,$fixedprivs,
2494: $available);
1.53 raeburn 2495: my $numcurrent = scalar(keys(%{$current}));
2496: if ($numcurrent > 0) {
1.36 raeburn 2497: $r->print('
1.5 raeburn 2498: <table>
2499: <tr>');
1.52 raeburn 2500: if ($num_items->{'active'}) {
1.36 raeburn 2501: &check_uncheck_buttons($r,$formname,'expire',$lt{'expi'});
2502: }
1.52 raeburn 2503: if ($num_items->{'previous'}) {
1.36 raeburn 2504: &check_uncheck_buttons($r,$formname,'reenable',$lt{'reen'});
2505: }
1.52 raeburn 2506: if ($num_items->{'future'}) {
1.36 raeburn 2507: &check_uncheck_buttons($r,$formname,'activate',$lt{'acti'});
2508: }
2509: &check_uncheck_buttons($r,$formname,'deletion',$lt{'dele'});
2510: if (@{$available} > 0) {
2511: if ($specificity eq 'Yes') {
2512: &check_uncheck_buttons($r,$formname,'changepriv',$lt{'chpr'});
1.5 raeburn 2513: }
1.36 raeburn 2514: if ($granularity eq 'Yes') {
2515: $r->print(&check_uncheck_tools($r,$available));
2516: $r->print('
1.5 raeburn 2517: <td>
1.83 bisitz 2518: <span class="LC_nobreak">
1.5 raeburn 2519: <fieldset><legend><b>'.$lt{'curf'}.'</b></legend>
1.80 bisitz 2520: <input type="button" value="'.&mt('check all').'"
1.5 raeburn 2521: onclick="javascript:checkAllTools(document.'.$formname.')" />
2522:
1.80 bisitz 2523: <input type="button" value="'.&mt('uncheck all').'"
1.5 raeburn 2524: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
2525: </fieldset>
1.83 bisitz 2526: </span>
1.5 raeburn 2527: </td>
2528: ');
1.3 raeburn 2529: }
1.36 raeburn 2530: }
2531: $r->print(<<"END");
1.5 raeburn 2532: </tr>
2533: </table>
1.48 albertel 2534: <br />
1.5 raeburn 2535: END
1.48 albertel 2536: $r->print(&Apache::loncommon::start_data_table().
2537: &Apache::loncommon::start_data_table_header_row());
1.36 raeburn 2538: $r->print(<<"END");
1.48 albertel 2539: <th>$lt{'actn'}</th>
2540: <th><a href="javascript:changeSort('fullname')">$lt{'name'}</a></th>
2541: <th><a href="javascript:changeSort('username')">$lt{'usnm'}</a></th>
2542: <th><a href="javascript:changeSort('domain')">$lt{'doma'}</a></th>
2543: <th><a href="javascript:changeSort('id')">ID</a></th>
2544: <th><a href="javascript:changeSort('start')">$lt{'stda'}</a></th>
2545: <th><a href="javascript:changeSort('end')">$lt{'enda'}</a></th>
1.5 raeburn 2546: END
1.36 raeburn 2547: my $colspan = 0;
2548: if ($hastools) {
1.48 albertel 2549: $r->print('<th>'.$lt{'curf'}.'</th>');
2550: $colspan++;
1.36 raeburn 2551: }
2552: if ($addtools) {
1.53 raeburn 2553: $r->print('<th>'.&mt('Additional Tools').'</th>');
1.48 albertel 2554: $colspan++;
1.36 raeburn 2555: }
1.48 albertel 2556: $r->print(&Apache::loncommon::end_data_table_header_row());
1.36 raeburn 2557: if ($colspan) {
2558: if ($granularity eq 'Yes') {
1.48 albertel 2559: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense LC_data_table_highlight').'
1.6 raeburn 2560: <td colspan="7"> </td>
1.83 bisitz 2561: <td colspan="'.$colspan.'" align="center"><span class="LC_nobreak"><b>'.&mt('All:').
1.6 raeburn 2562: '</b> ');
1.36 raeburn 2563: foreach my $tool (@{$available}) {
2564: $r->print('<label><input type="checkbox" name="togglefunc"'.
1.7 raeburn 2565: ' onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
1.48 albertel 2566: ' value="'.$tool.'" />'.'<b>'.$tool.'</b></label> ');
1.6 raeburn 2567: }
1.83 bisitz 2568: $r->print('</span></td></tr>');
1.6 raeburn 2569: }
1.36 raeburn 2570: }
2571: my %Sortby = ();
2572: foreach my $user (sort(keys(%{$current}))) {
2573: if ($env{'form.sortby'} eq 'fullname') {
2574: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2575: } elsif ($env{'form.sortby'} eq 'username') {
2576: push(@{$Sortby{$$current{$user}{uname}}},$user);
2577: } elsif ($env{'form.sortby'} eq 'domain') {
2578: push(@{$Sortby{$$current{$user}{udom}}},$user);
2579: } elsif ($env{'form.sortby'} eq 'id') {
2580: push(@{$Sortby{$$current{$user}{id}}},$user);
2581: } else {
2582: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2583: }
2584: }
2585: foreach my $key (sort(keys(%Sortby))) {
2586: foreach my $user (@{$Sortby{$key}}) {
2587: my $id = $$current{$user}{id};
2588: my $fullname = $$current{$user}{fullname};
2589: my $udom = $$current{$user}{udom};
2590: my $uname = $$current{$user}{uname};
2591: my $start = $$current{$user}{start};
2592: my $end = $$current{$user}{end};
1.48 albertel 2593: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense').'
2594: <td>');
1.36 raeburn 2595: if ($$current{$user}{changestate} eq 'reenable') {
1.83 bisitz 2596: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2597: '<input type="checkbox" name="reenable" value="'.$user.'" />'.
1.83 bisitz 2598: $lt{'reen'}.'</label></span><br />');
1.36 raeburn 2599: } elsif ($$current{$user}{changestate} eq 'expire') {
1.83 bisitz 2600: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2601: '<input type="checkbox" name="expire" value="'.$user.'" />'.
1.83 bisitz 2602: $lt{'expi'}.'</label></span><br />');
1.36 raeburn 2603: } elsif ($$current{$user}{changestate} eq 'activate') {
1.83 bisitz 2604: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2605: '<input type="checkbox" name="activate" value="'.$user.'" />'.
1.83 bisitz 2606: $lt{'acti'}.'</label></span><br />');
1.36 raeburn 2607: }
1.83 bisitz 2608: $r->print('<span class="LC_nobreak"><label>'.
1.6 raeburn 2609: '<input type="checkbox" name="deletion" value="'.$user.'" />'.
1.83 bisitz 2610: $lt{'dele'}.'</label></span>');
1.36 raeburn 2611: if ($specificity eq 'Yes') {
1.83 bisitz 2612: $r->print('<br /><span class="LC_nobreak"><label>'.
1.5 raeburn 2613: '<input type="checkbox" name="changepriv" value="'.$user.'" />'.$lt{'chpr'}.
1.83 bisitz 2614: '</label></span>');
1.36 raeburn 2615: }
2616: $r->print('
1.48 albertel 2617: </td>'.
2618: '<td>'.$fullname.'</td>'.
2619: '<td>'.$uname.'</td>'.
2620: '<td>'. $udom.'</td>'.
2621: '<td>'.$id.'</td>'.
2622: '<td>'.$start.'</td>'.
2623: '<td>'.$end.'</td>');
1.36 raeburn 2624: if ($hastools) {
1.83 bisitz 2625: $r->print('<td align="left"><span class="LC_nobreak">'.
1.6 raeburn 2626: ' ');
1.36 raeburn 2627: foreach my $tool (@{$$current{$user}{currtools}}) {
2628: if ($granularity eq 'Yes') {
2629: $r->print('<label><input type="checkbox" '.
1.7 raeburn 2630: 'checked="checked" '.
2631: 'name="user_'.$tool.'" value="'.
2632: $user.'" />'.$tool.'</label>');
1.36 raeburn 2633: } else {
2634: $r->print('<input type="hidden" '.
1.7 raeburn 2635: 'checked="checked" '.
2636: 'name="user_'.$tool.'" value="'.
2637: $user.'" />'.$tool);
1.36 raeburn 2638: }
2639: $r->print(' ');
1.5 raeburn 2640: }
1.83 bisitz 2641: $r->print('</span></td>');
1.36 raeburn 2642: }
2643: if ($addtools) {
1.48 albertel 2644: $r->print('<td align="left">');
1.36 raeburn 2645: if ($granularity eq 'Yes') {
2646: foreach my $tool (@{$$current{$user}{newtools}}) {
1.83 bisitz 2647: $r->print('<span class="LC_nobreak"><label><input type="checkbox"
1.5 raeburn 2648: name="user_'.$tool.'" value="'.
2649: $user.'" />'.$tool.
1.83 bisitz 2650: '</label></span> ');
1.36 raeburn 2651: }
2652: } else {
2653: foreach my $tool (@{$$current{$user}{newtools}}) {
1.83 bisitz 2654: $r->print('<span class="LC_nobreak"><input type="hidden"
1.5 raeburn 2655: name="user_'. $tool.'" value="'.
2656: $user.'" />'.$tool.
1.83 bisitz 2657: '</span> ');
1.5 raeburn 2658: }
2659: }
1.48 albertel 2660: $r->print('</td>');
1.5 raeburn 2661: }
1.48 albertel 2662: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.5 raeburn 2663: }
1.36 raeburn 2664: }
1.48 albertel 2665: $r->print(&Apache::loncommon::end_data_table());
1.53 raeburn 2666: } else {
2667: $r->print(&mt('There are no active, future or previous group members to modify.'));
1.5 raeburn 2668: }
1.53 raeburn 2669: return $numcurrent;
1.5 raeburn 2670: }
2671:
2672: sub check_uncheck_buttons {
2673: my ($r,$formname,$field,$title,$colspan) = @_;
2674: $r->print('
2675: <td '.$colspan.'>
2676: <fieldset>
2677: <legend><b>'.$title.'</b></legend>
1.83 bisitz 2678: <span class="LC_nobreak">
1.80 bisitz 2679: <input type="button" value="'.&mt('check all').'"
1.5 raeburn 2680: onclick="javascript:checkAll(document.'.$formname.'.'.$field.')" />
2681:
1.80 bisitz 2682: <input type="button" value="'.&mt('uncheck all').'"
1.5 raeburn 2683: onclick="javascript:uncheckAll(document.'.$formname.'.'.$field.')" />
1.83 bisitz 2684: </span>
1.5 raeburn 2685: </fieldset>
2686: </td>
2687: ');
2688: }
2689:
2690:
2691: sub change_privs_form {
1.45 albertel 2692: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,
2693: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,
2694: $memchg,$idx,$states,$stored,$sectioncount,$navbuttons,$gpterm,
2695: $ucgpterm) = @_;
1.5 raeburn 2696: my @regexps = ('userpriv_');
2697: my $nexttext;
1.6 raeburn 2698: my %lt = &Apache::lonlocal::texthash(
2699: 'tode' => 'To be deleted',
2700: 'toex' => 'To be expired',
1.29 raeburn 2701: 'nome' => "No members to be deleted or expired from the $gpterm.",
1.6 raeburn 2702: );
1.5 raeburn 2703: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2704: ['origin','action','state','page','sortby'],\@regexps));
2705: if ($env{'form.branch'} eq 'adds') {
2706: $nexttext = $$navbuttons{'adme'};
2707: } else {
2708: $nexttext = $$navbuttons{'mose'};
2709: }
1.78 raeburn 2710: $r->print(&Apache::lonhtmlcommon::topic_bar(3,&mt('Members to delete or expire')));
1.6 raeburn 2711: my $exp_or_del = 0;
2712: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2713: if (@{$$memchg{'deletion'}} > 0) {
1.50 albertel 2714: $r->print('<b>'.$lt{'tode'}.':</b><br /><ul>');
1.6 raeburn 2715: foreach my $user (@{$$memchg{'deletion'}}) {
2716: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2717: ' ('.$user.')</li>');
2718: }
1.45 albertel 2719: $r->print('</ul>');
1.6 raeburn 2720: $exp_or_del += @{$$memchg{'deletion'}};
2721: }
2722: }
2723: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2724: if (@{$$memchg{'expire'}} > 0) {
1.50 albertel 2725: $r->print('<b>'.$lt{'toex'}.':</b><br /><ul>');
1.6 raeburn 2726: foreach my $user (@{$$memchg{'expire'}}) {
2727: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2728: ' ('.$user.')</li>');
2729: }
1.45 albertel 2730: $r->print('</ul>');
1.6 raeburn 2731: $exp_or_del += @{$$memchg{'expire'}};
2732: }
2733: }
2734: if (!$exp_or_del) {
1.45 albertel 2735: $r->print($lt{'nome'}.'<br />');
1.6 raeburn 2736: }
1.5 raeburn 2737:
1.78 raeburn 2738: $r->print(&Apache::lonhtmlcommon::topic_bar(4,&mt('Setting optional privileges for specific group members')));
1.6 raeburn 2739:
1.45 albertel 2740: my $numchgs = &member_privileges_form($r,$action,$formname,$tools,
1.6 raeburn 2741: $toolprivs,$fixedprivs,$userdata,
2742: $usertools,$idx,$memchg,$states,
1.45 albertel 2743: $stored,$gpterm);
1.5 raeburn 2744: my $prevtext = $$navbuttons{'gtps'};
1.6 raeburn 2745: if ($numchgs || $exp_or_del) {
2746: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2747: $$states{$action}[$page+1],$nexttext);
2748: } else {
2749: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext);
2750: }
1.5 raeburn 2751: return;
2752: }
2753:
2754: sub add_members_form {
1.59 raeburn 2755: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,$groupname,
1.29 raeburn 2756: $description,$granularity,$quota,$sectioncount,$tools,$functions,
1.46 albertel 2757: $stored,$states,$navbuttons,$gpterm,$ucgpterm)=@_;
1.40 albertel 2758: $r->print(' <br />');
1.5 raeburn 2759: my @available = ();
2760: my @unavailable = ();
2761: &check_tools($functions,$tools,\@available,\@unavailable);
1.40 albertel 2762: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2763: $groupname,$description,$granularity,$quota,
2764: \@available,\@unavailable,$gpterm,$ucgpterm);
1.59 raeburn 2765: &membership_options($r,$cdom,$cnum,$action,$formname,$sectioncount,1,$gpterm,
2766: $ucgpterm);
1.5 raeburn 2767: my $nexttext = $$navbuttons{'gtns'};
2768: my $prevtext = $$navbuttons{'gtpp'};
2769: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2770: $$states{$action}[$page+1],$nexttext);
2771: return;
2772: }
2773:
2774: sub choose_privs_form {
1.45 albertel 2775: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,
2776: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,$idx,
2777: $states,$stored,$sectioncount,$navbuttons,$gpterm,$ucgpterm,
2778: $crstype) = @_;
1.5 raeburn 2779:
2780: my @regexps = ('userpriv_');
2781: my $nexttext;
2782:
2783: if ($action eq 'create') {
2784: push(@regexps,'sec_');
2785: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2786: ['origin','action','state','page','sortby','autoadd','autodrop'],
1.5 raeburn 2787: \@regexps));
2788: $nexttext = $$navbuttons{'crgr'};
2789: } else {
2790: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2791: ['origin','action','state','page','sortby'],\@regexps));
1.5 raeburn 2792: $nexttext = $$navbuttons{'adme'};
2793: }
2794:
1.78 raeburn 2795: $r->print(&Apache::lonhtmlcommon::topic_bar(6,&mt('Setting optional privileges for specific group members')));
1.5 raeburn 2796:
1.45 albertel 2797: &member_privileges_form($r,$action,$formname,$tools,$toolprivs,
1.5 raeburn 2798: $fixedprivs,$userdata,$usertools,$idx,undef,
1.45 albertel 2799: $states,$stored,$gpterm);
1.5 raeburn 2800:
2801: if ($action eq 'create') {
1.53 raeburn 2802: my $img1 = 7;
2803: my $img2 = 8;
2804: &mapping_options($r,$action,$formname,$page,$sectioncount,
2805: $states,$stored,$navbuttons,$img1,$img2,
1.58 raeburn 2806: $gpterm,$ucgpterm,$crstype,$cdom,$cnum);
1.5 raeburn 2807: }
2808: my $prevtext = $$navbuttons{'gtps'};
2809: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2810: $$states{$action}[$page+1],$nexttext);
2811: return;
2812: }
2813:
2814: sub build_boxes {
2815: my ($r,$tools,$usertools,$fixedprivs,$toolprivs,$showtools,
1.6 raeburn 2816: $showboxes,$prefix,$specificity,$excluded) = @_;
1.5 raeburn 2817: my $totalboxes = 0;
2818: if (@{$tools} > 0) {
2819: if ($specificity eq 'Yes') {
2820: foreach my $tool (@{$tools}) {
2821: @{$$showboxes{$tool}} = ();
2822: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 2823: if (ref($excluded) eq 'ARRAY') {
2824: if (grep/^$user$/,@{$excluded}) {
2825: next;
2826: }
1.5 raeburn 2827: }
1.6 raeburn 2828: if ($$usertools{$user}{$tool}) {
2829: unless (grep/^$tool$/,@{$showtools}) {
2830: push(@{$showtools},$tool);
2831: }
2832: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2833: unless (exists($$fixedprivs{$tool}{$priv})) {
2834: unless(grep(/^$priv$/,@{$$showboxes{$tool}})) {
2835: push(@{$$showboxes{$tool}},$priv);
2836: $totalboxes ++;
2837: }
1.5 raeburn 2838: }
2839: }
2840: }
2841: }
2842: }
2843: if ($totalboxes > 0) {
2844: $r->print('
2845: <script type="text/javascript">
2846: function checkAllTools(formname) {
2847: ');
2848: foreach my $tool (sort(keys(%{$showboxes}))) {
2849: foreach my $priv (@{$$showboxes{$tool}}) {
2850: $r->print(' checkAll(formname.'.$prefix.$priv.');'."\n");
2851: }
2852: }
2853: $r->print('
2854: }
2855: function uncheckAllTools(formname) {
2856: ');
2857: foreach my $tool (sort(keys(%{$showboxes}))) {
2858: foreach my $priv (@{$$showboxes{$tool}}) {
2859: $r->print(' uncheckAll(formname'.$prefix.$priv.');'."\n");
2860: }
2861: }
2862: $r->print('
2863: }
2864: </script>
2865: ');
2866: }
2867: }
2868: }
2869: return $totalboxes;
2870: }
2871:
2872: sub member_privileges_form {
1.45 albertel 2873: my ($r,$action,$formname,$tools,$toolprivs,$fixedprivs,$userdata,
2874: $usertools,$idx,$memchg,$states,$stored,$gpterm) = @_;
1.5 raeburn 2875: my %lt = &Apache::lonlocal::texthash(
2876: 'addp' => 'Additional privileges',
1.53 raeburn 2877: 'fixp' => 'Core privileges',
1.5 raeburn 2878: 'oppr' => 'Optional privileges',
1.53 raeburn 2879: 'func' => 'Tool',
2880: 'forf' => 'For the collaborative tools included for group '.
2881: 'members being added or modified, '.
2882: 'there are no optional privileges to set '.
2883: 'for specific members.',
1.80 bisitz 2884: 'algr' => 'All new group members will receive the same privileges.',
2885: 'ifex' => 'If previously expired members are being re-enabled, or '.
1.54 raeburn 2886: 'if access for future members is being activated now, '.
2887: 'previously set privileges will be preserved.',
1.53 raeburn 2888: 'asno' => 'As no group members are being added, '.
2889: 'there are no specific user privileges to set.',
2890: 'asng' => 'As no group tools will be made available to users, '.
2891: 'there are no specific user privileges to set.',
2892: 'nogm' => 'No group member privileges to display or set, '.
2893: 'as you have not indicated that you will be activating,'.
2894: ' re-enabling, changing privileges, or adding/removing '.
2895: 'tools for any current members.',
1.5 raeburn 2896: 'full' => 'Fullname',
2897: 'user' => 'Username',
2898: 'doma' => 'Domain',
2899: );
2900: my @defprivs;
2901: my $specificity;
2902: if ($action eq 'create') {
2903: if (defined($env{'form.defpriv'})) {
2904: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
2905: }
2906: $specificity = $env{'form.specificity'};
2907: } else {
1.17 raeburn 2908: if (defined($$stored{'defpriv'})) {
2909: @defprivs = @{$$stored{'defpriv'}};
2910: }
1.5 raeburn 2911: $specificity = $$stored{'specificity'};
2912: }
2913: my @showtools;
2914: my %showboxes = ();
2915: my $numtools = 1 + @{$tools};
1.3 raeburn 2916:
1.6 raeburn 2917: my @excluded = ();
2918: my $numchgs = 0;
2919: if ($formname eq 'change_privs') {
2920: my @currmembers = ();
2921: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2922: push(@excluded,@{$$memchg{'deletion'}});
2923: }
2924: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2925: push(@excluded,@{$$memchg{'expire'}});
2926: }
2927: if (@excluded > 0) {
2928: foreach my $user (sort(keys(%{$usertools}))) {
2929: if (grep/^$user$/,@excluded) {
2930: next;
2931: }
2932: push(@currmembers,$user);
2933: }
2934: } else {
2935: @currmembers = sort(keys(%{$usertools}));
2936: }
2937: $numchgs = @currmembers;
2938: if (!$numchgs) {
1.45 albertel 2939: $r->print($lt{'nogm'});
1.6 raeburn 2940: return $numchgs;
2941: }
2942: }
2943:
2944: my $totalboxes = &build_boxes($r,$tools,$usertools,$fixedprivs,
2945: $toolprivs,\@showtools,\%showboxes,
2946: 'userpriv_',$specificity,\@excluded);
1.5 raeburn 2947: if (@{$tools} > 0) {
2948: if ($specificity eq 'Yes') {
2949: if ($totalboxes > 0) {
2950: my $numcells = 2;
2951: my $colspan = $numcells + 1;
2952: my %total;
1.6 raeburn 2953: if (keys(%{$usertools}) > 1) {
2954: $r->print('
1.45 albertel 2955: <table border="0" cellspacing="2" cellpadding="2">
1.5 raeburn 2956: <tr>
2957: ');
1.6 raeburn 2958: foreach my $tool (@{$tools}) {
2959: if (@{$showboxes{$tool}} > 0) {
2960: $r->print('<td valign="top">');
1.45 albertel 2961: $r->print('<table class="thinborder"><tr>'.
2962: '<th colspan="'.$colspan.'">'.
1.80 bisitz 2963: &mt($tool).'</th></tr><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.6 raeburn 2998: $r->print('</tr></table></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">'
3131: .&mt('The value you entered for the quota for the file repository in this '.$gpterm
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">'
3139: .&mt('The value you entered for the quota for the file repository in this '.$gpterm
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.41 albertel 3762: my $perpetual =
1.83 bisitz 3763: '<span class="LC_nobreak"><label><input type="checkbox" name="no_end_date" />'.
3764: &mt('None').'</label></span>';
1.42 albertel 3765: my $table = "<table class=\"LC_descriptive_input\">\n".
3766: '<tr><td class="LC_description">'.&mt('Start:').'</td>'.
1.3 raeburn 3767: '<td>'.$startform.'</td>'.
1.41 albertel 3768: '<td> </td>'."</tr>\n".
1.42 albertel 3769: '<tr><td class="LC_description">'.&mt('End:').'</td>'.
1.3 raeburn 3770: '<td>'.$endform.'</td>'.
1.41 albertel 3771: '<td>'.$perpetual.'</td>'."</tr>\n".
3772: "</table>\n";
3773: return $table;
1.1 raeburn 3774: }
3775:
1.32 raeburn 3776: sub add_group_folder {
3777: my ($cdom,$cnum,$now,$groupname,$action,$description,$tools,$groupinfo,
3778: $gpterm,$ucgpterm,$crstype) = @_;
3779: if ($cdom eq '' || $cnum eq '') {
1.80 bisitz 3780: return '<span class="LC_error">'
3781: .&mt('Error: invalid course domain or number - group folder creation failed.')
3782: .'</span>';
1.32 raeburn 3783: }
1.67 raeburn 3784: my ($outcome,$allgrpsmap,$grpmap,$boardsmap,$grppage,$warning);
1.32 raeburn 3785: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
1.47 raeburn 3786: $allgrpsmap = $crspath.'group_allfolders.sequence';
1.32 raeburn 3787: if ($action eq 'create') {
1.67 raeburn 3788: if (&get_folder_lock($cdom,$cnum,'group_allfolders',$now) eq 'ok') {
3789: # check if group_allfolders.sequence exists.
1.69 raeburn 3790: my $mapcontents = &Apache::lonnet::getfile($allgrpsmap);
3791: if ($mapcontents eq '-1') { #file does not exist;
1.80 bisitz 3792: my $grpstitle = &mt("$crstype $ucgpterm".'s');
1.67 raeburn 3793: my $topmap_url = '/'.$env{'course.'.$env{'request.course.id'}.'.url'};
3794: $topmap_url =~ s|/+|/|g;
3795: if ($topmap_url =~ m|^/uploaded|) {
3796: $outcome = &map_updater($cdom,$cnum,'group_allfolders.sequence',
3797: 'toplevelgroup',$grpstitle,$topmap_url);
3798: } else {
1.80 bisitz 3799: $outcome = '<span class="LC_warning">'
3800: .&mt('Non-standard course - folder for all groups not added.')
3801: .'</span>';
1.67 raeburn 3802: }
1.32 raeburn 3803: if ($outcome ne 'ok') {
1.67 raeburn 3804: my $delresult = &release_folder_lock($cdom,$cnum,'group_allfolders');
3805: if ($delresult ne 'ok') {
3806: $warning = $delresult;
3807: }
1.84 raeburn 3808: return $outcome.$warning;
1.32 raeburn 3809: }
3810: }
1.67 raeburn 3811: my $delresult = &release_folder_lock($cdom,$cnum,'group_allfolders');
3812: if ($delresult ne 'ok') {
3813: $warning = $delresult ;
3814: }
3815: } else {
1.80 bisitz 3816: $outcome = '<span class="LC_error">'
3817: .&mt('Could not obtain exclusive lock to check status of the folder for all groups. No group folder added.')
1.84 raeburn 3818: .'</span>';
1.67 raeburn 3819: return $outcome;
1.32 raeburn 3820: }
1.75 bisitz 3821: my $grpfolder = &mt($ucgpterm.' Folder - [_1]',$description);
1.49 raeburn 3822: $grppage='/adm/'.$cdom.'/'.$cnum.'/'.$groupname.'/smppg';
1.75 bisitz 3823: my $grptitle = &mt('Group homepage - [_1]',$description);
1.55 raeburn 3824: my ($discussions,$disctitle);
1.47 raeburn 3825: my $outcome = &map_updater($cdom,$cnum,'group_folder_'.$groupname.'.sequence',
1.32 raeburn 3826: 'grpseq',$grpfolder,$allgrpsmap,$grppage,
3827: $grptitle);
3828: if ($outcome ne 'ok') {
1.67 raeburn 3829: return $outcome.$warning;
1.32 raeburn 3830: }
3831: my $pageout = &create_homepage($cdom,$cnum,$groupname,$groupinfo,
3832: $tools,$gpterm,$ucgpterm,$now);
3833: # Link to folder for bulletin boards
1.47 raeburn 3834: $grpmap = $crspath.'group_folder_'.$groupname.'.sequence';
1.32 raeburn 3835: if (grep/^discussion$/,@{$tools}) {
3836: $disctitle = &mt('Discussion Boards');
1.47 raeburn 3837: my $outcome = &map_updater($cdom,$cnum,'group_boards_'.$groupname.
1.32 raeburn 3838: '.sequence','bbseq',$disctitle,$grpmap);
3839: if ($outcome ne 'ok') {
1.67 raeburn 3840: return $outcome.$warning;
1.32 raeburn 3841: }
1.47 raeburn 3842: $boardsmap = $crspath.'group_boards_'.$groupname.'.sequence';
1.32 raeburn 3843: }
3844: } else {
3845: #modify group folder if status of discussions tools is changed
3846: }
3847: my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.67 raeburn 3848: my $navmap = Apache::lonnavmaps::navmap->new();
1.85 raeburn 3849: if (!defined($navmap)) {
3850: return $warning.'<span class="LC_error">'.&mt('Error retrieving course contents').
3851: ' '.&mt('You need to re-initialize the course.').'</span>';
3852: }
1.32 raeburn 3853: # modify parameters
3854: my $parm_result;
3855: if ($action eq 'create') {
3856: if ($grpmap) {
3857: $parm_result .= &parm_setter($navmap,$cdom,$grpmap,$groupname);
3858: }
3859: if ($grppage) {
3860: $parm_result .= &parm_setter($navmap,$cdom,$grppage,$groupname);
3861: }
3862: if ($boardsmap) {
3863: $parm_result .= &parm_setter($navmap,$cdom,$boardsmap,$groupname);
3864: }
3865: }
1.67 raeburn 3866: undef($navmap);
1.32 raeburn 3867: if ($parm_result) {
1.67 raeburn 3868: return $warning.$parm_result;
3869: } else {
3870: return 'ok';
3871: }
3872: }
3873:
3874: sub get_folder_lock {
3875: my ($cdom,$cnum,$folder_name,$now) = @_;
3876: # get lock for folder being edited.
3877: my $lockhash = {
3878: $folder_name."\0".'locked_folder' => $now.':'.$env{'user.name'}.
3879: ':'.$env{'user.domain'},
3880: };
3881: my $tries = 0;
3882: my $gotlock = &Apache::lonnet::newput('coursegroups',$lockhash,$cdom,$cnum);
3883:
3884: while (($gotlock ne 'ok') && $tries <3) {
3885: $tries ++;
1.68 albertel 3886: sleep(1);
1.67 raeburn 3887: $gotlock = &Apache::lonnet::newput('coursegroups',$lockhash,$cdom,$cnum);
3888: }
3889: return $gotlock;
3890: }
3891:
3892: sub release_folder_lock {
3893: my ($cdom,$cnum,$folder_name) = @_;
3894: # remove lock
3895: my @del_lock = ($folder_name."\0".'locked_folder');
3896: my $dellockoutcome=&Apache::lonnet::del('coursegroups',\@del_lock,$cdom,$cnum);
3897: if ($dellockoutcome ne 'ok') {
1.80 bisitz 3898: return ('<div class="LC_error">'
3899: .&mt('Warning: failed to release lock for folder: [_1].','<tt>'.$folder_name.'</tt>')
3900: .'</div>'
3901: );
1.32 raeburn 3902: } else {
3903: return 'ok';
3904: }
3905: }
3906:
3907: sub map_updater {
3908: my ($cdom,$cnum,$newfile,$itemname,$itemtitle,$parentmap,$startsrc,
3909: $starttitle,$endsrc,$endtitle) = @_;
3910: my $outcome;
3911: $env{'form.'.$itemname} = &new_map($startsrc,$starttitle,$endsrc,
3912: $endtitle);
3913: my $newmapurl=&Apache::lonnet::finishuserfileupload($cnum,$cdom,$itemname,
3914: $newfile);
3915: if ($newmapurl !~ m|^/uploaded|) {
1.80 bisitz 3916: $outcome = '<div class="LC_error">'
3917: .&mt('Error uploading new folder.')." ($newfile): $newmapurl"
3918: .'</div>';
1.32 raeburn 3919: return $outcome;
1.67 raeburn 3920: }
1.63 albertel 3921: my ($errtext,$fatal)=&LONCAPA::map::mapread($parentmap);
1.32 raeburn 3922: if ($fatal) {
1.80 bisitz 3923: $outcome = '<div class="LC_error">'
3924: .&mt('Error reading contents of parent folder.')." ($parentmap): $errtext"
3925: .'</div>';
1.32 raeburn 3926: return $outcome;
3927: } else {
1.63 albertel 3928: my $newidx=&LONCAPA::map::getresidx($newmapurl);
3929: $LONCAPA::map::resources[$newidx] = $itemtitle.':'.$newmapurl.
1.32 raeburn 3930: ':false:normal:res';
1.63 albertel 3931: $LONCAPA::map::order[1+$#LONCAPA::map::order]=$newidx;
3932: my ($outtext,$errtext) = &LONCAPA::map::storemap($parentmap,1);
1.67 raeburn 3933: if ($errtext) {
1.80 bisitz 3934: $outcome = '<div class="LC_error">'
3935: .&mt('Error saving updated parent folder.')." ($parentmap): $errtext"
3936: .'</div>';
1.32 raeburn 3937: return $outcome;
3938: }
3939: }
3940: return 'ok';
3941: }
3942:
3943: sub new_map {
3944: my ($startsrc,$starttitle,$endsrc,$endtitle) = @_;
3945: my $newmapstr = '
3946: <map>
3947: <resource id="1" src="'.$startsrc.'" type="start" title="'.$starttitle.'"></resource>
3948: <link from="1" to="2" index="1"></link>
3949: <resource id="2" src="'.$endsrc.'" type="finish" title="'.$endtitle.'"></resource>
3950: </map>
3951: ';
3952: return $newmapstr;
3953: }
3954:
3955: sub parm_setter {
3956: my ($navmap,$cdom,$url,$groupname) = @_;
1.37 raeburn 3957: my $allresults;
1.85 raeburn 3958: if (!defined($navmap)) {
1.86 raeburn 3959: $allresults = '<div class="LC_warning">'.
3960: &mt('Parameters not set for [_1] because the contents of the course could not be retrieved.',$url).' '.
3961: &mt('You need to reinitialize the course.').
3962: '</div>';
1.87 raeburn 3963: return $allresults;
1.85 raeburn 3964: }
1.32 raeburn 3965: my %hide_settings = (
3966: 'course' => {
3967: 'num' => 13,
3968: 'set' => 'yes',
3969: },
3970: 'group' => {
3971: 'num' => 5,
3972: 'set' => 'no',
3973: 'extra' => $groupname,
3974: },
3975: );
3976: my $res = $navmap->getResourceByUrl($url);
1.67 raeburn 3977: if ($res) {
3978: my $symb = $res->symb();
3979: foreach my $level (keys(%hide_settings)) {
3980: my $parmresult =
3981: &Apache::lonparmset::storeparm_by_symb($symb,
1.32 raeburn 3982: '0_hiddenresource',
3983: $hide_settings{$level}{'num'},
3984: $hide_settings{$level}{'set'},
3985: 'string_yesno',undef,$cdom,
3986: undef,undef,
3987: $hide_settings{$level}{'extra'});
1.67 raeburn 3988: if ($parmresult) {
3989: $allresults .= $level.': '.$parmresult;
3990: }
1.37 raeburn 3991: }
1.67 raeburn 3992: } else {
1.80 bisitz 3993: $allresults = '<div class="LC_warning">'
3994: .&mt('Parameters not set for [_1] because the resource was not recognized'
3995: .' as part of the course.','<tt>'.$url.'</tt>')
3996: .'</div>';
1.32 raeburn 3997: }
1.37 raeburn 3998: return $allresults;
1.32 raeburn 3999: }
4000:
1.3 raeburn 4001: sub create_homepage {
1.32 raeburn 4002: my ($cdom,$cnum,$name,$groupinfo,$tools,$gpterm,$ucgpterm,$now) = @_;
1.3 raeburn 4003: my $functionality = join(',',@{$tools});
1.24 www 4004: my $content = &unescape($$groupinfo{description});
1.3 raeburn 4005: $content=~s/\s+$//s;
4006: $content=~s/^\s+//s;
4007: $content=~s/\<br\s*\/*\>$//s;
4008: $content=&Apache::lonfeedback::clear_out_html($content,1);
4009:
4010: my %pageinfo = (
1.29 raeburn 4011: 'aaa_title' => "$ucgpterm: $name",
1.3 raeburn 4012: 'abb_links' => $functionality,
4013: 'bbb_content' => $content,
4014: 'ccc_webreferences' => '',
1.32 raeburn 4015: 'uploaded.lastmodified' => $now,
1.3 raeburn 4016: );
4017: my $putresult = &Apache::lonnet::put('grppage_'.$name,\%pageinfo,$cdom,$cnum);
4018: return $putresult;
1.1 raeburn 4019: }
4020:
1.5 raeburn 4021: sub check_uncheck_tools {
4022: my ($r,$available) = @_;
4023: if (ref($available) eq 'ARRAY') {
4024: $r->print('
4025: <script type="text/javascript">
4026: function checkAllTools(formname) {
4027: ');
4028: foreach my $tool (@{$available}) {
4029: $r->print(' checkAll(formname.user_'.$tool.');'."\n");
4030: }
4031: $r->print(' checkAll(formname.togglefunc);'."\n");
4032: $r->print('
4033: }
4034: function uncheckAllTools(formname) {
4035: ');
4036: foreach my $tool (@{$available}) {
4037: $r->print(' uncheckAll(formname.user_'.$tool.');'."\n");
4038: }
4039: $r->print(' uncheckAll(formname.togglefunc);'."\n");
4040: $r->print('
4041: }
4042: function toggleTools(field,caller) {
4043: if (caller.checked) {
4044: checkAll(field);
4045: } else {
4046: uncheckAll(field);
4047: }
4048: return;
4049: }
4050: </script>
4051: ');
4052: }
4053: return;
4054: }
4055:
4056: sub validate_groupname {
1.29 raeburn 4057: my ($groupname,$action,$cdom,$cnum,$gpterm,$ucgpterm,$crstype) = @_;
1.16 albertel 4058: my %sectioncount = &Apache::loncommon::get_sections($cdom,$cnum);
1.17 raeburn 4059: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.65 raeburn 4060: my %deleted_groups = &Apache::longroup::coursegroups($cdom,$cnum,undef,
4061: 'deleted_groups');
1.64 raeburn 4062: if (my $tmp = &Apache::lonnet::error(%deleted_groups)) {
4063: undef(%deleted_groups);
4064: &Apache::lonnet::logthis('Error retrieving groups: '.$tmp.' in '.$cnum.':'.$cdom);
4065: }
1.5 raeburn 4066: my %lt = &Apache::lonlocal::texthash (
1.29 raeburn 4067: igna => "Invalid $gpterm name",
4068: tgne => "The $gpterm name entered ",
4069: grna => "$ucgpterm names and section names used in a ".
4070: "$crstype must be unique.",
4071: isno => "is not a valid name.",
4072: gnmo => "$ucgpterm names may only contain letters, ".
4073: "numbers or underscores.",
4074: cnnb => "can not be used as it is the name of ",
4075: inth => " in this $crstype",
4076: thgr => "- does not correspond to the name of an ".
4077: "existing $gpterm",
1.5 raeburn 4078: );
1.15 albertel 4079:
1.42 albertel 4080: my $exitmsg = '<span class="LC_error">'.$lt{'igna'}.'</span><br /><br />'.
4081: $lt{'tgne'}.' "'.$groupname.'" ';
1.5 raeburn 4082: my $dupmsg = $lt{'grna'};
4083: my $earlyout;
4084: if (($groupname eq '') || ($groupname =~ /\W/)) {
4085: $earlyout = $exitmsg.$lt{'isno'}.'<br />'.$lt{'gnmo'};
4086: return $earlyout;
4087: }
1.16 albertel 4088: if (exists($sectioncount{$groupname})) {
4089: return $exitmsg.$lt{'cnnb'}.&mt('a section').$lt{'inth'}.
4090: '<br />'.$lt{'grna'};
1.5 raeburn 4091: }
1.64 raeburn 4092: if ($action eq 'create') {
4093: if (exists($curr_groups{$groupname})) {
4094: return $exitmsg.$lt{'cnnb'}.&mt('an existing [_1]',$gpterm).
4095: $lt{'inth'}.'.<br />'.$lt{'grna'};
4096: } elsif (exists($deleted_groups{$groupname})) {
4097: return $exitmsg.$lt{'cnnb'}.&mt('a [_1] which previously existed',$gpterm).
4098: $lt{'inth'}.'.<br />'.$lt{'grna'};
4099: }
1.5 raeburn 4100: } elsif ($action eq 'modify') {
4101: unless(exists($curr_groups{$groupname})) {
1.29 raeburn 4102: $earlyout = &mt('[_1] name:',$ucgpterm).' '.$groupname.$lt{'thgr'}.
4103: $lt{'inth'};
1.5 raeburn 4104: return $earlyout;
4105: }
4106: }
4107: return;
4108: }
4109:
4110: sub check_changes {
4111: my ($member_changes,$memchg) = @_;
4112: my %exclusions;
4113: @{$exclusions{'changefunc'}} = ('expire');
4114: @{$exclusions{'changepriv'}} = ('expire','changefunc');
4115:
4116: foreach my $change (@{$member_changes}) {
1.6 raeburn 4117: if ($change eq 'deletion') {
1.5 raeburn 4118: next;
4119: }
1.6 raeburn 4120: my @checks = ('deletion');
1.5 raeburn 4121: if (exists($exclusions{$change})) {
4122: push(@checks,@{$exclusions{$change}});
4123: }
4124: my @temp = ();
4125: foreach my $item (@{$$memchg{$change}}) {
4126: my $match = 0;
4127: foreach my $check (@checks) {
1.6 raeburn 4128: if (defined($$memchg{$check})) {
4129: if (ref(@{$$memchg{$check}}) eq 'ARRAY') {
4130: if (@{$$memchg{$check}} > 0) {
4131: if (grep/^$item$/,@{$$memchg{$check}}) {
4132: $match = 1;
4133: last;
4134: }
4135: }
1.5 raeburn 4136: }
4137: }
4138: }
4139: if ($match) {
4140: next;
4141: }
4142: push(@temp,$item);
4143: }
4144: @{$$memchg{$change}} = @temp;
4145: }
4146: }
1.3 raeburn 4147:
1.1 raeburn 4148: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>