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