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