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