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