Annotation of loncom/interface/loncoursegroups.pm, revision 1.47
1.24 www 1: # The LearningOnline Network with CAPA
2: #
1.47 ! raeburn 3: # $Id: loncoursegroups.pm,v 1.46 2006/07/07 20:53:40 albertel 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.45 albertel 106: &group_administration($r,$action,$state,$cdom,$cnum,
1.21 raeburn 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.45 albertel 351: my ($r,$action,$state,$cdom,$cnum,$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,
1.45 albertel 872: $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.45 albertel 965: $enddate,$users,$userdata,$idx,$memchg,$usertools,
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.46 albertel 971: &general_settings_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 972: $functions,$tools,$toolprivs,$fixedprivs,
973: $sectioncount,$stored,$states,$navbuttons,
1.46 albertel 974: $gpterm,$ucgpterm,$crstype);
1.3 raeburn 975: } elsif ($state eq 'pick_members') {
1.46 albertel 976: &choose_members_form($r,$cdom,$cnum,$action,$state,$page,
1.29 raeburn 977: $groupname,$description,$granularity,$quota,
1.5 raeburn 978: $startdate,$enddate,$tools,$fixedprivs,
979: $toolprivs,$functions,$users,$userdata,$idx,
1.46 albertel 980: $stored,$states,$navbuttons,$gpterm,$ucgpterm,
981: $crstype);
1.3 raeburn 982: } elsif ($state eq 'pick_privs') {
1.45 albertel 983: &choose_privs_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 984: $startdate,$enddate,$tools,$functions,
985: $toolprivs,$fixedprivs,$userdata,$usertools,
986: $idx,$states,$stored,$sectioncount,$navbuttons,
1.45 albertel 987: $gpterm,$ucgpterm,$crstype);
1.3 raeburn 988: } elsif ($state eq 'result') {
1.45 albertel 989: &process_request($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 990: $groupname,$description,$specificity,$userdata,
991: $startdate,$enddate,$tools,$functions,
992: $toolprivs,$usertools,$idx,$types,$roles,
993: $sections,$states,$navbuttons,$memchg,
1.45 albertel 994: $sectioncount,$stored,$gpterm,$ucgpterm,$crstype);
1.5 raeburn 995: }
996: } elsif ($action eq 'modify') {
997: my $groupname = $env{'form.groupname'};
998: if ($state eq 'pick_group') {
1.39 albertel 999: &display_groups($r,$cdom,$cnum,$functions,$idx,$view_permission,
1000: $manage_permission,$action,$state,$gpterm,
1001: $ucgpterm,$crstype);
1.5 raeburn 1002: } elsif ($state eq 'pick_task') {
1.29 raeburn 1003: &modify_menu($r,$groupname,$page,$gpterm);
1.5 raeburn 1004: } elsif ($state eq 'change_settings') {
1.46 albertel 1005: &general_settings_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1006: $functions,$tools,$toolprivs,$fixedprivs,
1007: $sectioncount,$stored,$states,$navbuttons,
1.46 albertel 1008: $gpterm,$ucgpterm,$crstype);
1.5 raeburn 1009: } elsif ($state eq 'change_members') {
1010: &change_members_form($r,$cdom,$cnum,$tabcol,$action,$state,$page,
1011: $groupname,$description,$startdate,$enddate,
1012: $tools,$fixedprivs,$functions,$users,
1.29 raeburn 1013: $userdata,$granularity,$quota,$specificity,
1014: $idx,$states,$navbuttons,$rowColor1,$rowColor2,
1015: $gpterm,$ucgpterm);
1.5 raeburn 1016: } elsif ($state eq 'add_members') {
1.46 albertel 1017: &add_members_form($r,$action,$state,$page,$startdate,
1.5 raeburn 1018: $enddate,$groupname,$description,$granularity,
1.29 raeburn 1019: $quota,$sectioncount,$tools,$functions,$stored,
1.46 albertel 1020: $states,$navbuttons,$gpterm,$ucgpterm);
1.5 raeburn 1021: } elsif ($state eq 'pick_members') {
1.46 albertel 1022: &choose_members_form($r,$cdom,$cnum,$action,$state,$page,
1.29 raeburn 1023: $groupname,$description,$granularity,$quota,
1.5 raeburn 1024: $startdate,$enddate,$tools,$fixedprivs,
1025: $toolprivs,$functions,$users,$userdata,$idx,
1.46 albertel 1026: $stored,$states,$navbuttons,$gpterm,$ucgpterm,
1027: $crstype);
1.5 raeburn 1028: } elsif ($state eq 'pick_privs') {
1.46 albertel 1029: &choose_privs_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1030: $startdate,$enddate,$tools,$functions,
1031: $toolprivs,$fixedprivs,$userdata,$usertools,
1032: $idx,$states,$stored,$sectioncount,$navbuttons,
1.46 albertel 1033: $gpterm,$ucgpterm,$crstype);
1.5 raeburn 1034: } elsif ($state eq 'change_privs') {
1.45 albertel 1035: &change_privs_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1036: $startdate,$enddate,$tools,$functions,
1037: $toolprivs,$fixedprivs,$userdata,$usertools,
1038: $memchg,$idx,$states,$stored,$sectioncount,
1.45 albertel 1039: $navbuttons,$gpterm,$ucgpterm);
1.5 raeburn 1040: } elsif ($state eq 'chgresult' || $state eq 'memresult' ||
1041: $state eq 'addresult') {
1.45 albertel 1042: &process_request($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1043: $groupname,$description,$specificity,$userdata,
1044: $startdate,$enddate,$tools,$functions,
1045: $toolprivs,$usertools,$idx,$types,$roles,
1046: $sections,$states,$navbuttons,$memchg,
1.45 albertel 1047: $sectioncount,$stored,$gpterm,$ucgpterm,$crstype);
1.1 raeburn 1048: }
1049: }
1050: }
1051:
1052: sub header {
1.39 albertel 1053: my ($bodytitle,$jscript,$action,$state,$page,$loaditems) = @_;
1.9 albertel 1054: my $start_page=
1.11 albertel 1055: &Apache::loncommon::start_page($bodytitle,
1056: '<script type="text/javascript">'.
1057: $jscript.'</script>',
1.39 albertel 1058: {'add_entries' => $loaditems,});
1.3 raeburn 1059: my $output = <<"END";
1.11 albertel 1060: $start_page
1.9 albertel 1061: <form method="POST" name="$state">
1.3 raeburn 1062:
1063: END
1064: if ($action eq 'create' || $action eq 'modify') {
1065: $output .= <<"END";
1066: <input type="hidden" name="action" value="$action" />
1067: <input type="hidden" name="state" value="" />
1068: <input type="hidden" name="origin" value="$state" />
1.5 raeburn 1069: <input type="hidden" name="page" value="$page" />
1.3 raeburn 1070: END
1071: }
1072: return $output;
1.1 raeburn 1073: }
1074:
1.3 raeburn 1075: sub onload_action {
1076: my ($action,$state) = @_;
1.13 albertel 1077: my %loaditems;
1.3 raeburn 1078: if ((defined($env{'form.origin'})) && ($action eq 'create') &&
1079: ($state eq 'pick_name' || $state eq 'pick_members' ||
1080: $state eq 'pick_privs')) {
1081: unless ($env{'form.origin'} eq '') {
1.13 albertel 1082: $loaditems{'onload'} =
1083: 'javascript:setFormElements(document.'.$state.')';
1.1 raeburn 1084: }
1085: }
1.5 raeburn 1086: if (($action eq 'modify') &&
1087: ($state eq 'change_settings' || $state eq 'change_members' ||
1.7 raeburn 1088: $state eq 'change_privs' || $state eq 'add_members' ||
1089: $state eq 'pick_members')) {
1.13 albertel 1090: $loaditems{'onload'} =
1091: 'javascript:setFormElements(document.'.$state.')';
1.5 raeburn 1092: }
1.13 albertel 1093: return \%loaditems;
1.1 raeburn 1094: }
1095:
1096: sub footer {
1.9 albertel 1097: my $end_page = &Apache::loncommon::end_page();
1.1 raeburn 1098: return(<<ENDFOOT);
1.6 raeburn 1099: <input type="hidden" name="sortby" value="$env{'form.sortby'}" />
1.1 raeburn 1100: </form>
1.9 albertel 1101: $end_page
1.1 raeburn 1102: ENDFOOT
1103: }
1104:
1.3 raeburn 1105: sub build_members_list {
1106: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata) = @_;
1107: my %access = ();
1108: foreach my $role (@{$roles}) {
1109: %{$$users{$role}} = ();
1110: }
1111: foreach my $type (@{$types}) {
1112: $access{$type} = $type;
1113: }
1114: &Apache::loncommon::get_course_users($cdom,$cnum,\%access,$roles,
1.5 raeburn 1115: $sections,$users,$userdata);
1.3 raeburn 1116: return;
1117: }
1118:
1119: sub group_files {
1.29 raeburn 1120: my ($group,$currdir,$numfiles,$numdirs) = @_;
1121: my $dirptr=16384;
1122: my @dir_list=&Apache::portfolio::get_dir_list($currdir,$group);
1123: foreach my $line (@dir_list) {
1124: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
1125: if (($filename !~ /^\.\.?$/) && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/) && ($filename ne 'no_such_dir')) {
1126: if ($dirptr&$testdir) {
1127: $currdir .= '/'.$filename;
1128: $$numdirs ++;
1129: &group_files($numfiles,$numdirs)
1130: } else {
1131: $$numfiles ++;
1132: }
1133: }
1134: }
1.3 raeburn 1135: return;
1136: }
1137:
1138: sub group_members {
1.4 raeburn 1139: my ($cdom,$cnum,$group,$group_info) = @_;
1140: my %memberhash = &Apache::lonnet::get_group_membership($cdom,$cnum,$group);
1141: my $now = time;
1142: my ($tmp)=keys(%memberhash);
1143: if ($tmp=~/^error:/) {
1144: $$group_info{'totalmembers'} = 'Unknown - an error occurred';
1145: return $tmp;
1146: }
1147: my $totalmembers = 0;
1148: my $active = 0;
1149: my $previous = 0;
1150: my $future = 0;
1151: foreach my $member (keys %memberhash) {
1152: $totalmembers ++;
1153: my ($end,$start) = split(/:/,$memberhash{$member});
1.6 raeburn 1154: unless ($start == -1) {
1155: if (($end!=0) && ($end<$now)) {
1156: $previous ++;
1157: } elsif (($start!=0) && ($start>$now)) {
1158: $future ++;
1159: } else {
1160: $active ++;
1161: }
1.4 raeburn 1162: }
1163: }
1164: if ($totalmembers == 0) {
1165: $$group_info{$group}{'totalmembers'} = 'None';
1166: } else {
1.47 ! raeburn 1167: $$group_info{$group}{'totalmembers'} = '<nobr>'.$active.
! 1168: ' - active</nobr><br /><nobr>'.$previous.
! 1169: ' - previous</nobr><br /><nobr>'.$future.
! 1170: ' - future</nobr>';
1.4 raeburn 1171: }
1172: return 'ok';
1.3 raeburn 1173: }
1174:
1175:
1.5 raeburn 1176: sub general_settings_form {
1.46 albertel 1177: my ($r,$cdom,$cnum,$action,$formname,$page,$functions,$tools,
1.5 raeburn 1178: $toolprivs,$fixedprivs,$sectioncount,$stored,$states,$navbuttons,
1.46 albertel 1179: $gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 1180: my ($nexttext,$prevtext);
1.42 albertel 1181: &groupsettings_options($r,$functions,$action,$formname,$stored,1,
1.29 raeburn 1182: $gpterm,$ucgpterm,$crstype);
1.41 albertel 1183: &access_date_settings($r,$action,$formname,$stored,2,$gpterm,$ucgpterm);
1.5 raeburn 1184: if ($action eq 'create') {
1.40 albertel 1185: &membership_options($r,$action,$formname,$sectioncount,3,$gpterm,
1186: $ucgpterm);
1.5 raeburn 1187: $nexttext = $$navbuttons{'gtns'};
1188: } else {
1189: my @available = ();
1190: my @unavailable = ();
1191: &check_tools($functions,$tools,\@available,\@unavailable);
1192: @{$tools} = sort(keys(%{$functions}));
1.46 albertel 1193: &privilege_specificity($r,$action,3,$tools,$stored,$toolprivs,
1194: $fixedprivs,\@available,$formname,
1195: $gpterm,$ucgpterm);
1.44 albertel 1196: &mapping_options($r,$action,$formname,$page,$sectioncount,
1197: $states,$stored,$navbuttons,4,5,
1198: $gpterm,$ucgpterm,$crstype);
1.5 raeburn 1199: $nexttext = $$navbuttons{'mose'};
1200: }
1201: $prevtext = $$navbuttons{'gtpp'};
1202: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
1203: $$states{$action}[$page+1],$nexttext);
1204: return;
1205: }
1206:
1207: sub groupsettings_options {
1.42 albertel 1208: my ($r,$functions,$action,$formname,$stored,$image,$gpterm,
1.29 raeburn 1209: $ucgpterm,$crstype) = @_;
1.1 raeburn 1210: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 1211: 'gdat' => "$ucgpterm open and close dates",
1212: 'sten' => "Set a start date/time and end date/time for the $gpterm",
1213: 'gfun' => "$ucgpterm functionality",
1214: 'gnde' => "$ucgpterm name, description and available functionality",
1.5 raeburn 1215: 'desc' => 'Description',
1216: 'func' => 'Functionality',
1.29 raeburn 1217: 'gnam' => "$ucgpterm Name",
1218: 'doyo' => "Do you want to assign different functionality ".
1219: "to different $gpterm members?",
1.1 raeburn 1220: );
1.37 raeburn 1221: my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,$stored);
1.40 albertel 1222: &topic_bar($r,$image,$lt{'gnde'});
1.5 raeburn 1223: $r->print('
1.42 albertel 1224: <table class="LC_descriptive_input">
1.3 raeburn 1225: <tr>
1.42 albertel 1226: <td class="LC_description">'.$lt{'gnam'}.':</td>
1.5 raeburn 1227: <td colspan="5">
1228: ');
1229: if ($action eq 'create') {
1230: $r->print('<input type="text" name="groupname" size="25" />');
1231: } else {
1232: $r->print('<input type="hidden" name="groupname" value="'.
1233: $env{'form.groupname'}.'" />'.$env{'form.groupname'});
1234: }
1235: $r->print(<<"END");
1.3 raeburn 1236: </td>
1237: <tr>
1238: <tr>
1.42 albertel 1239: <td class="LC_description">$lt{'desc'}:</td>
1.5 raeburn 1240: <td colspan="5"><input type="text" name="description" size="40"
1241: value="" />
1.3 raeburn 1242: </td>
1243: <tr>
1244: <tr>
1.42 albertel 1245: <td class="LC_description">$lt{'func'}:</td>
1.3 raeburn 1246: END
1247: my $numitems = keys(%{$functions});
1248: my $halfnum = int($numitems/2);
1249: my $remnum = $numitems%2;
1250: if ($remnum) {
1251: $halfnum ++;
1252: }
1.5 raeburn 1253: my @allfunctions = sort(keys (%{$functions}));
1.3 raeburn 1254: for (my $i=0; $i<$halfnum; $i++) {
1.7 raeburn 1255: $r->print('<td><label><input type="checkbox" name="tool" value="'.
1.3 raeburn 1256: $allfunctions[$i].'" /> '.
1.7 raeburn 1257: $$functions{$allfunctions[$i]}.'</label></td>
1.3 raeburn 1258: <td> </td><td> </td>');
1259: }
1260: $r->print('<td><input type="button" value="check all" '.
1261: 'onclick="javascript:checkAll(document.'.$formname.'.tool)" />'.
1262: '</td></tr><tr><td> </td>');
1263: for (my $j=$halfnum; $j<@allfunctions; $j++) {
1.7 raeburn 1264: $r->print('<td><label><input type="checkbox" name="tool" value="'.
1.3 raeburn 1265: $allfunctions[$j].'" /> '.
1.7 raeburn 1266: $$functions{$allfunctions[$j]}.'</label></td>
1.3 raeburn 1267: <td> </td><td> </td>');
1268: }
1269: if ($remnum) {
1270: $r->print('<td> </td>');
1271: }
1.5 raeburn 1272: $r->print('
1.3 raeburn 1273: <td>
1.5 raeburn 1274: <input type="button" value="uncheck all"
1275: onclick="javascript:uncheckAll(document.'.$formname.'.tool)" />
1.3 raeburn 1276: </td>
1277: </tr>
1278: <tr>
1.42 albertel 1279: <td class="LC_description">'.&mt('Granularity:').'</td>
1.29 raeburn 1280: <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 1281: if ($action eq 'modify') {
1282: $r->print(' ('.&mt('Currently set to "[_1]"',
1283: $$stored{'granularity'}).')');
1284: }
1285: $r->print('
1286: </td>
1287: </tr>
1.29 raeburn 1288: <tr>
1.42 albertel 1289: <td class="LC_description">'.&mt('Disk quota: ').'</td><td colspan="10">');
1.29 raeburn 1290: if ($action eq 'create') {
1291: $r->print(&mt('If you enable the file repository for the [_1], allocate a disk quota.',$gpterm));
1292: } else {
1293: $r->print(&mt('Quota allocated to file repository:'));
1294: }
1295: $r->print(' <input type="text" name="quota" size="4" />Mb');
1296: if ($action eq 'create') {
1297: $r->print('<br />'.
1298: &mt('A total of [_1] Mb is shared between all [_2]s in the '.
1299: '[_3], and [_4] Mb are currently unallocated.',$crsquota,
1300: $gpterm,lc($crstype),$freespace));
1301: } else {
1302: $r->print(' ('.&mt('The quota is currently [_1] Mb',
1303: $$stored{'quota'}).').');
1304:
1305: $r->print('<br />'.&mt('The quota can be increased to [_1] Mb, '.
1306: 'by adding all unallocated space for [_2]s in the [_3].',
1307: $maxposs,$gpterm,lc($crstype)));
1308: }
1309: $r->print('
1310: </td>
1311: </tr>
1.3 raeburn 1312: </table>
1.5 raeburn 1313: ');
1314: return;
1315: }
1316:
1.37 raeburn 1317: sub get_quota_constraints {
1318: my ($action,$stored) = @_;
1319: my ($crsquota,$freespace,$maxposs);
1320: $crsquota = $env{'course.'.$env{'request.course.id'}.'.internal.coursequota'};
1321: if ($crsquota eq '') {
1322: $crsquota = 20;
1323: }
1324: $freespace = $crsquota - &Apache::longroup::sum_quotas();
1325: if ($action eq 'create') {
1326: $maxposs = $freespace;
1327: } else {
1328: $maxposs = $$stored{'quota'} + $freespace;
1329: }
1330: return ($crsquota,$freespace,$maxposs);
1331: }
1332:
1.5 raeburn 1333: sub membership_options {
1.40 albertel 1334: my ($r,$action,$state,$sectioncount,$image,$gpterm,$ucgpterm) = @_;
1.29 raeburn 1335: my $crstype = &Apache::loncommon::course_type();
1.5 raeburn 1336: my %lt = &Apache::lonlocal::texthash(
1337: 'pipa' => 'Pick parameters to generate membership list',
1.29 raeburn 1338: 'gmem' => "$ucgpterm membership options",
1.5 raeburn 1339: 'picr' => 'Pick the criteria to use to build a list of '.
1.29 raeburn 1340: lc($crstype).' users from which you will select ',
1341: 'meof' => "members of the new $gpterm.",
1342: 'admg' => "additional members of the $gpterm.",
1343: 'ifno' => "If you do not wish to add members when you first ".
1344: "create the $gpterm, do not make any selections.",
1345: '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 1346: 'acty' => 'Access types',
1.29 raeburn 1347: 'coro' => $crstype.' roles',
1348: 'cose' => $crstype.' sections',
1.5 raeburn 1349: );
1350: my %status_types = (
1351: active => &mt('Currently has access'),
1352: previous => &mt('Previously had access'),
1353: future => &mt('Will have future access'),
1354: );
1.15 albertel 1355:
1.34 albertel 1356: #FIXME need to plumb around for the various cr roles defined by the user
1357: my @roles = ('st','cc','in','ta','ep');
1.5 raeburn 1358:
1359: my @sections = keys(%{$sectioncount});
1360:
1.40 albertel 1361: &topic_bar($r,$image,$lt{'pipa'});
1.5 raeburn 1362: $r->print('
1.40 albertel 1363: <b>'.$lt{'gmem'}.'</b><br />'.$lt{'picr'});
1.5 raeburn 1364: if ($action eq 'create') {
1.21 raeburn 1365: $r->print($lt{'meof'}.'<br />'.$lt{'ifno'}.'<br />'.$lt{'asub'});
1.5 raeburn 1366: } else {
1.6 raeburn 1367: $r->print($lt{'admg'});
1.5 raeburn 1368: }
1369: $r->print('
1370: <br />
1371: <br />
1.40 albertel 1372: <table class="LC_status_selector">
1.3 raeburn 1373: <tr>
1.40 albertel 1374: <th>'.$lt{'acty'}.'</th>
1375: <th>'.$lt{'coro'}.'</th>');
1.3 raeburn 1376: if (@sections >0) {
1.5 raeburn 1377: $r->print('
1.40 albertel 1378: <th>'.$lt{'cose'}.'</th>');
1.3 raeburn 1379: }
1.40 albertel 1380: $r->print('</tr><tr><td>');
1.3 raeburn 1381: $r->print(&Apache::lonhtmlcommon::status_select_row(\%status_types));
1.40 albertel 1382: $r->print('</td><td>');
1.3 raeburn 1383: $r->print(&Apache::lonhtmlcommon::role_select_row(\@roles));
1384: if (@sections > 0) {
1.5 raeburn 1385: @sections = sort {$a cmp $b} @sections;
1.31 albertel 1386: unshift(@sections,'none'); # Put 'no sections' next
1.17 raeburn 1387: unshift(@sections,'all'); # Put 'all' at the front of the list
1.40 albertel 1388: $r->print('</td><td>'.
1.5 raeburn 1389: §ions_selection(\@sections,'sectionpick').'</td>');
1.3 raeburn 1390: }
1391: $r->print('
1392: </tr>
1.40 albertel 1393: </table>');
1.5 raeburn 1394: return;
1395: }
1396:
1397: sub sections_selection {
1398: my ($sections,$elementname) = @_;
1399: my $section_sel;
1400: my $numvisible = 4;
1401: if (@{$sections} < 4) {
1402: $numvisible = @{$sections};
1403: }
1404: foreach my $sec (@{$sections}) {
1.17 raeburn 1405: if ($sec eq 'all') {
1.31 albertel 1406: $section_sel .= ' <option value="'.$sec.'" selected="selected">'.&mt('all sections').'</option>'."\n";
1.17 raeburn 1407: } elsif ($sec eq 'none') {
1.31 albertel 1408: $section_sel .= ' <option value="'.$sec.'">'.&mt('no section').'</option>'."\n";
1.5 raeburn 1409: } else {
1.31 albertel 1410: $section_sel .= ' <option value="'.$sec.'">'.$sec."</option>\n";
1.5 raeburn 1411: }
1412: }
1413: my $output = '
1414: <select name="'.$elementname.'" multiple="true" size="'.$numvisible.'">
1415: '.$section_sel.'
1416: </select>';
1417: return $output;
1418: }
1419:
1420: sub access_date_settings {
1.41 albertel 1421: my ($r,$action,$formname,$stored,$image,$gpterm,$ucgpterm) = @_;
1.5 raeburn 1422: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 1423: 'sten' => "Default start and end dates for $gpterm access",
1.5 raeburn 1424: );
1425: my $starttime = time;
1426: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1427: if ($action eq 'modify') {
1428: $starttime = $$stored{'startdate'};
1429: unless ($$stored{'enddate'} == 0) {
1430: $endtime = $$stored{'enddate'};
1431: }
1432: }
1.41 albertel 1433: my ($table) = &date_setting_table($starttime,$endtime,$formname);
1.40 albertel 1434: &topic_bar($r,$image,$lt{'sten'});
1.5 raeburn 1435: $r->print('
1.41 albertel 1436: '.$table.'
1437: ');
1.3 raeburn 1438: return;
1439: }
1440:
1.5 raeburn 1441: sub choose_members_form {
1.46 albertel 1442: my ($r,$cdom,$cnum,$action,$formname,$page,$groupname,$description,
1.29 raeburn 1443: $granularity,$quota,$startdate,$enddate,$tools,$fixedprivs,$toolprivs,
1.5 raeburn 1444: $functions,$users,$userdata,$idx,$stored,$states,$navbuttons,
1.46 albertel 1445: $gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 1446: my @regexps = ('user_','userpriv_','sec_');
1447: my %origmembers;
1.3 raeburn 1448: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.5 raeburn 1449: ['origin','action','state','page','member','specificity','branch',
1.7 raeburn 1450: 'defpriv','autorole','autoadd','autodrop','sortby','togglefunc'],
1.5 raeburn 1451: \@regexps));
1.29 raeburn 1452: my $earlyout = &validate_groupname($groupname,$action,$cdom,$cnum,$gpterm,
1453: $ucgpterm,$crstype);
1.5 raeburn 1454: if ($earlyout) {
1.47 ! raeburn 1455: $r->print($earlyout);
1.5 raeburn 1456: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1457: $$navbuttons{'gtps'});
1.3 raeburn 1458: return;
1.5 raeburn 1459: }
1460: my ($specimg,$memimg);
1461: my @available = ();
1462: my @unavailable = ();
1463: &check_tools($functions,$tools,\@available,\@unavailable);
1464: if ($action eq 'create') {
1.40 albertel 1465: &print_current_settings($r,$action,$functions,$startdate,$enddate,
1466: $groupname,$description,$granularity,$quota,
1467: \@available,\@unavailable,$gpterm,$ucgpterm);
1.5 raeburn 1468: $specimg = 4;
1469: $memimg = 5;
1470: } else {
1471: $specimg = 2;
1472: $memimg = 3;
1473: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
1474: $groupname);
1475: foreach my $key (sort(keys(%membership))) {
1476: if ($key =~ /^\Q$groupname\E:([^:]+):([^:]+)$/) {
1.6 raeburn 1477: my ($end,$start,@userprivs) = split(/:/,$membership{$key});
1478: unless ($start == -1) {
1479: my $uname = $1;
1480: my $udom = $2;
1481: my $user = $uname.':'.$udom;
1482: $origmembers{$user} = 1;
1483: }
1.5 raeburn 1484: }
1485: }
1486: }
1.46 albertel 1487: &privilege_specificity($r,$action,$specimg,$tools,$stored,$toolprivs,
1.29 raeburn 1488: $fixedprivs,\@available,$formname,$gpterm,$ucgpterm);
1.44 albertel 1489: my $newusers = &pick_new_members($r,$action,$formname,\@available,$idx,
1490: $stored,$memimg,$users,$userdata,
1491: $granularity,\%origmembers,$gpterm,
1492: $ucgpterm);
1.5 raeburn 1493: if ($newusers || $action eq 'create') {
1494: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1495: $$navbuttons{'gtps'},$$states{$action}[$page+1],
1496: $$navbuttons{'gtns'});
1497: } else {
1498: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1499: $$navbuttons{'gtps'});
1.3 raeburn 1500: }
1.5 raeburn 1501: return;
1502: }
1503:
1504: sub display_navbuttons {
1505: my ($r,$formname,$prev,$prevtext,$next,$nexttext) = @_;
1.42 albertel 1506: $r->print('<div class="LC_navbuttons">');
1.5 raeburn 1507: if ($prev) {
1508: $r->print('
1509: <input type="button" name="previous" value = "'.$prevtext.'"
1510: onclick="javascript:backPage(document.'.$formname.','."'".$prev."'".')"/>
1511: ');
1512: }
1513: if ($next) {
1514: $r->print('
1515: <input type="button" name="next" value="'.$nexttext.'"
1516: onclick="javascript:nextPage(document.'.$formname.','."'".$next."'".')" />');
1517: }
1.42 albertel 1518: $r->print('</div>');
1.5 raeburn 1519: }
1520:
1521: sub check_tools {
1522: my ($functions,$tools,$available,$unavailable) = @_;
1523: foreach my $item (sort(keys(%{$functions}))) {
1524: if (grep/^$item$/,@{$tools}) {
1525: push(@{$available},$item);
1526: } else {
1527: push(@{$unavailable},$item);
1528: }
1529: }
1530: return;
1531: }
1532:
1533: sub print_current_settings {
1.40 albertel 1534: my ($r,$action,$functions,$startdate,$enddate,$groupname,$description,
1535: $granularity,$quota,$available,$unavailable,$gpterm,$ucgpterm) = @_;
1.5 raeburn 1536:
1537: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 1538: grna => "$ucgpterm Name",
1.5 raeburn 1539: desc => 'Description',
1.29 raeburn 1540: grfn => "$ucgpterm Functions",
1.5 raeburn 1541: gran => 'Granularity',
1.29 raeburn 1542: quot => 'File quota',
1.5 raeburn 1543: dfac => 'Default access dates',
1.29 raeburn 1544: ygrs => "Your $gpterm selections",
1545: tfwa => "The following settings will apply to the $gpterm:",
1546: difn => 'Different functionality<br />for different members:',
1.5 raeburn 1547: stda => 'Start date',
1548: enda => 'End date:',
1549: );
1.3 raeburn 1550: my $showstart = &Apache::lonlocal::locallocaltime($startdate);
1.5 raeburn 1551: my $showend;
1552: if ($enddate == 0) {
1553: $showend = &mt('No end date set');
1554: } else {
1555: $showend = &Apache::lonlocal::locallocaltime($enddate);
1556: }
1557: if ($action eq 'create') {
1558: $r->print('
1.42 albertel 1559: <div><span style="font-size: larger">'.$lt{'ygrs'}.'</span>
1.5 raeburn 1560: <br />'.$lt{'tfwa'}.'
1.40 albertel 1561: </div>');
1.5 raeburn 1562: }
1.40 albertel 1563: $r->print(&Apache::loncommon::start_data_table('LC_course_group_status').
1564: &Apache::loncommon::start_data_table_header_row());
1565: $r->print('
1566: <th>'.$lt{'grna'}.'</th>
1567: <th>'.$lt{'desc'}.'</th>
1568: <th>'.$lt{'grfn'}.'</th>
1569: <th>'.$lt{'gran'}.'</th>
1570: <th>'.$lt{'quot'}.'</th>
1571: <th>'.$lt{'dfac'}.'</th>
1572: ');
1573: $r->print(&Apache::loncommon::end_data_table_header_row().
1574: &Apache::loncommon::start_data_table_row('LC_data_table_dense'));
1.3 raeburn 1575: $r->print('
1.40 albertel 1576: <td valign="top">'.$groupname.'</td>
1577: <td valign="top">'.$description.'</td>
1.3 raeburn 1578: <td>
1579: ');
1.5 raeburn 1580: if (@{$available} > 0) {
1.40 albertel 1581: $r->print('<b>Available:</b>
1.3 raeburn 1582: <table cellpadding="" cellspacing="1"><tr>');
1.5 raeburn 1583: my $rowcell = int(@{$available}/2) + @{$available}%2;
1584: for (my $i=0; $i<@{$available}; $i++) {
1585: if (@{$available} > 3) {
1.3 raeburn 1586: if ($i==$rowcell) {
1587: $r->print('</tr><tr>');
1588: }
1589: }
1.40 albertel 1590: $r->print('<td>'.$$functions{$$available[$i]}.
1591: '</td><td> </td>');
1.3 raeburn 1592: }
1.5 raeburn 1593: if ((@{$available} > 3) && (@{$available}%2)) {
1.3 raeburn 1594: $r->print('<td> </td><td> </td>');
1595: }
1596: $r->print('</tr></table><br />');
1597: }
1.5 raeburn 1598: if (@{$unavailable} > 0) {
1.40 albertel 1599: $r->print('<b>Unavailable:</b>
1.3 raeburn 1600: <table cellpadding="0" cellspacing="1" border="0"><tr>');
1.5 raeburn 1601: my $rowcell = int(@{$unavailable}/2) + @{$unavailable}%2;
1602: for (my $j=0; $j<@{$unavailable}; $j++) {
1603: if (@{$unavailable} > 3) {
1.3 raeburn 1604: if ($j==$rowcell) {
1605: $r->print('</tr><tr>');
1606: }
1607: }
1.40 albertel 1608: $r->print('<td>'.$$functions{$$unavailable[$j]}.
1609: '</td><td> </td>');
1.3 raeburn 1610: }
1.5 raeburn 1611: if ((@{$unavailable} > 3) && (@{$unavailable}%2)) {
1.3 raeburn 1612: $r->print('<td> </td><td> </td>');
1613: }
1614: $r->print('</tr></table>');
1615: }
1616: $r->print(<<"END");
1617: </td>
1.40 albertel 1618: <td valign="top"><b>$lt{'difn'}</b> $granularity</td>
1619: <td valign="top">$quota Mb</td>
1620: <td valign="top"><b>$lt{'stda'}</b> $showstart<br />
1621: <b>$lt{'enda'}</b> $showend
1.3 raeburn 1622: </td>
1623: END
1.40 albertel 1624: $r->print(&Apache::loncommon::end_data_table_row().
1625: &Apache::loncommon::end_data_table());
1.5 raeburn 1626: return;
1627: }
1628:
1629: sub pick_new_members {
1.44 albertel 1630: my ($r,$action,$formname,$available,$idx,$stored,$img,$users,$userdata,
1631: $granularity,$origmembers,$gpterm,$ucgpterm) = @_;
1.5 raeburn 1632: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 1633: 'gpme' => "$ucgpterm membership",
1.5 raeburn 1634: 'addm' => 'Add members',
1635: 'setf' => 'Set functionality',
1636: 'func' => 'Functionality',
1637: 'nome' => 'No members to add at this time.',
1.29 raeburn 1638: 'nnew' => "There are no users to add as new members, as all users".
1639: " matching the specified type(s), role(s), and/or ".
1640: "section(s) are already affiliated with this $gpterm.",
1.5 raeburn 1641: 'yoma' => 'You may need to use the '."'".'modify existing, past or '.
1642: 'future members'."'".' page if you need to re-enable '.
1643: 'or activate access for previous or future members.',
1644: );
1645: my %members;
1646: my $totalusers = 0;
1647: my $newusers = 0;
1.3 raeburn 1648: foreach my $role (keys(%{$users})) {
1649: foreach my $user (keys(%{$$users{$role}})) {
1.5 raeburn 1650: $totalusers ++;
1651: if (ref($origmembers) eq 'HASH') {
1652: if (exists($$origmembers{$user})) {
1653: next;
1654: }
1655: }
1.3 raeburn 1656: unless (defined($members{$user})) {
1657: @{$members{$user}} = @{$$userdata{$user}};
1.5 raeburn 1658: $newusers ++;
1.3 raeburn 1659: }
1660: }
1661: }
1662: if (keys(%members) > 0) {
1.5 raeburn 1663: if (@{$available} > 0 && $granularity eq 'Yes') {
1664: $r->print(&check_uncheck_tools($r,$available));
1665: }
1666: }
1.40 albertel 1667: &topic_bar($r,$img,$lt{'gpme'});
1.5 raeburn 1668: if (keys(%members) > 0) {
1669: $r->print('
1.3 raeburn 1670: <table>
1.5 raeburn 1671: <tr>');
1672: &check_uncheck_buttons($r,$formname,'member',$lt{'addm'});
1673: if (@{$available} > 0 && $granularity eq 'Yes') {
1674: $r->print('<td><nobr>
1675: <fieldset><legend><b>'.$lt{'setf'}.'</b></legend>
1676: <input type="button" value="check all"
1677: onclick="javascript:checkAllTools(document.'.$formname.')" />
1678:
1679: <input type="button" value="uncheck all"
1.3 raeburn 1680: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
1.5 raeburn 1681: </fieldset></nobr></td>');
1.3 raeburn 1682: }
1683: $r->print('</tr></table>
1684: ');
1.43 albertel 1685: $r->print(&Apache::loncommon::start_data_table().
1686: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 1687: $r->print('
1.43 albertel 1688: <th>'.&mt('Add?').'</b></td>
1689: <th><a href="javascript:changeSort('."'fullname'".')">'.&mt('Name').'</a></td>
1690: <th><a href="javascript:changeSort('."'username'".')">'.&mt('Username').'</a></td>
1691: <th><a href="javascript:changeSort('."'domain'".')">'.&mt('Domain').'</a></td>
1692: <th><a href="javascript:changeSort('."'id'".')">'.&mt('ID').'</a></td>
1693: <th><a href="javascript:changeSort('."'section'".')">'.&mt('Section').'</a></td>
1.5 raeburn 1694: ');
1695: if (@{$available} > 0) {
1.43 albertel 1696: $r->print('<th>'.$lt{'func'}.'</th>');
1.3 raeburn 1697: }
1.43 albertel 1698: $r->print(&Apache::loncommon::end_data_table_header_row());
1.5 raeburn 1699: if (@{$available} > 0) {
1700: if ($granularity eq 'Yes') {
1.43 albertel 1701: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense LC_data_table_highlight').'
1.35 raeburn 1702: <td colspan="6"> </td>
1.43 albertel 1703: <td align="center"><nobr><b>'.&mt('All:').'</b> ');
1.5 raeburn 1704: foreach my $tool (@{$available}) {
1.7 raeburn 1705: $r->print('<label><input type="checkbox" name="togglefunc" '.
1706: 'onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
1707: ' value="'.$tool.'">'.'<b>'.$tool.'</b></label> ');
1.5 raeburn 1708: }
1.43 albertel 1709: $r->print('</nobr></td></tr>');
1.5 raeburn 1710: }
1711: }
1.3 raeburn 1712: my %Sortby = ();
1713: foreach my $user (sort(keys(%members))) {
1714: if ($env{'form.sortby'} eq 'fullname') {
1715: push(@{$Sortby{$members{$user}[$$idx{fullname}]}},$user);
1716: } elsif ($env{'form.sortby'} eq 'username') {
1717: push(@{$Sortby{$members{$user}[$$idx{uname}]}},$user);
1718: } elsif ($env{'form.sortby'} eq 'domain') {
1719: push(@{$Sortby{$members{$user}[$$idx{udom}]}},$user);
1720: } elsif ($env{'form.sortby'} eq 'id') {
1721: push(@{$Sortby{$members{$user}[$$idx{id}]}},$user);
1.31 albertel 1722: } elsif ($env{'form.sortby'} eq 'section') {
1723: push(@{$Sortby{$members{$user}[$$idx{section}]}},$user);
1.3 raeburn 1724: } else {
1725: push(@{$Sortby{$members{$user}[$$idx{fullname}]}},$user);
1726: }
1727: }
1728: foreach my $key (sort(keys(%Sortby))) {
1729: foreach my $user (@{$Sortby{$key}}) {
1730: my $id = $members{$user}[$$idx{id}];
1731: my $fullname = $members{$user}[$$idx{fullname}];
1732: my $udom = $members{$user}[$$idx{udom}];
1733: my $uname = $members{$user}[$$idx{uname}];
1.31 albertel 1734: my $section = $members{$user}[$$idx{section}];
1.43 albertel 1735: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense').
1736: '<td align="right"><input type="checkbox" name="member" value="'.$user.'" /></td>'.
1737: '<td>'.$fullname.'</td>'.
1738: '<td>'.$uname.'</td>'.
1739: '<td>'.$udom.'</td>'.
1740: '<td>'.$id.'</td>'.
1741: '<td>'.$section.'</td>');
1.5 raeburn 1742: if (@{$available} > 0) {
1.43 albertel 1743: $r->print('<td align="center"><nobr>'.
1.5 raeburn 1744: ' ');
1745: foreach my $tool (@{$available}) {
1746: if ($granularity eq 'Yes') {
1.3 raeburn 1747: $r->print('<input type="checkbox" name="user_'.
1748: $tool.'" value="'.$user.'" />'.$tool.' ');
1749: } else {
1750: $r->print('<input type="hidden" name="user_'.
1751: $tool.'" value="'.$user.'" />'.$tool.' ');
1752: }
1753: }
1.43 albertel 1754: $r->print('</nobr></td>');
1.3 raeburn 1755: }
1.43 albertel 1756: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.3 raeburn 1757: }
1758: }
1.43 albertel 1759: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 1760: } else {
1761: if ($totalusers > 0) {
1762: $r->print($lt{'nnew'}.'<br /><br />'.$lt{'yoma'});
1763: } else {
1764: $r->print($lt{'nome'});
1765: }
1766: }
1767: return $newusers;
1768: }
1769:
1770: sub privilege_specificity {
1.46 albertel 1771: my ($r,$action,$img,$tools,$stored,$toolprivs,$fixedprivs,$available,
1772: $formname,$gpterm,$ucgpterm) = @_;
1.5 raeburn 1773: my %lt = &Apache::lonlocal::texthash (
1774: 'uprv' => 'User privileges',
1775: 'frty' => 'For each type of functionality you have chosen to include, '.
1776: 'there is a set of standard privileges which apply to all '.
1777: 'of those for whom the functionality is enabled.',
1778: 'thar' => 'There are also additional privileges which can be set for '.
1779: 'some, or all, members. Please choose one of the following:',
1780: 'fort' => 'For the types of functionality you have chosen to include '.
1781: 'there are no additional privileges which can be set for some '.
1782: 'or all members.',
1783: 'eaty' => 'Each of the types of functionality includes standard '.
1784: 'privileges which apply to members with access to that '.
1785: 'functionality, and may also include additional privileges '.
1786: 'which can be set for specific members.',
1.29 raeburn 1787: 'cutg' => "Currently the $gpterm is configured ",
1788: 'sdif' => "so different $gpterm members can receive different privileges.",
1789: 'sall' => "so all $gpterm members will receive the same privileges.",
1790: 'algm' => "All $gpterm members will receive the same privileges.",
1791: 'smgp' => "Some $gpterm members will receive different privileges from ".
1792: "others.",
1793: 'thwi' => "These will be the privileges all $gpterm members receive, ".
1794: "if you selected the first option above.",
1795: 'thes' => "These will be the privileges given to members assigned ".
1796: "in the future, including via automatic $gpterm assignment ".
1797: "for specific sections/roles ",
1798: 'asyo' => "As you have chosen not to include any functionality in the ".
1799: "$gpterm, no default user privileges settings need to be set.",
1.5 raeburn 1800: 'plin' => 'Please indicate which <b>optional</b> privileges members '.
1801: 'will receive by default.',
1802: 'oppr' => 'Optional privileges',
1803: 'defp' => 'The default privileges new members will receive are:',
1804: );
1805: my $totaloptionalprivs = 0;
1806: foreach my $tool (@{$tools}) {
1807: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
1808: if (!exists($$fixedprivs{$tool}{$priv})) {
1809: $totaloptionalprivs ++;
1810: }
1811: }
1812: }
1.40 albertel 1813: &topic_bar($r,$img,$lt{'uprv'});
1.5 raeburn 1814: if ((($action eq 'create') && (@{$available} > 0)) ||
1815: (($action eq 'modify') && ($formname eq 'change_settings'))) {
1816: my %specific = (
1817: 'No' => 'checked="checked"',
1818: 'Yes' => '',
1819: );
1820: if ($action eq 'create') {
1821: $r->print($lt{'frty'}.'<br />');
1822: if ($totaloptionalprivs) {
1823: $r->print($lt{'thar'});
1824: } else {
1825: $r->print($lt{'fort'});
1826: }
1827: } else {
1828: $r->print($lt{'eaty'}.' '.$lt{cutg});
1829: if ($$stored{'specificity'} eq 'Yes') {
1830: $r->print($lt{'sdif'});
1831: $specific{'Yes'} = $specific{'No'};
1832: $specific{'No'} = '';
1833: } else {
1834: $r->print($lt{'sall'});
1835: }
1836: }
1837: if ($totaloptionalprivs) {
1838: $r->print('
1.40 albertel 1839: <br /><br />
1840: <label><nobr><input type="radio" name="specificity" value="No" '.$specific{'No'}.' /> '.$lt{'algm'}.'</nobr></label><br />
1841: <label><nobr><input type="radio" name="specificity" value="Yes" '.$specific{'Yes'}.' /> '.$lt{'smgp'}.'</nobr></label>');
1.5 raeburn 1842: } else {
1843: $r->print('<input type="hidden" name="specificity" value="No" />');
1844: }
1845: if ($totaloptionalprivs) {
1.40 albertel 1846: $r->print($lt{'plin'});
1.5 raeburn 1847: if ($action eq 'create') {
1848: $r->print(' '.$lt{'thwi'});
1849: }
1850: $r->print('<br />'.$lt{'thes'});
1851: if ($action eq 'create') {
1852: $r->print('('.&mt('if enabled on the next page').').');
1853: } else {
1854: $r->print('('.&mt('if enabled below').').');
1855: }
1856: $r->print('<br /><br />
1.40 albertel 1857: <table><tr>');
1.5 raeburn 1858: &check_uncheck_buttons($r,$formname,'defpriv',$lt{'oppr'});
1859: $r->print('
1860: </tr>
1861: </table>
1.3 raeburn 1862: <br />
1863: ');
1.5 raeburn 1864: } else {
1.40 albertel 1865: $r->print($lt{'algm'}.'<br /><br />');
1.3 raeburn 1866: }
1.42 albertel 1867: &default_privileges($r,$action,$tools,$toolprivs,$fixedprivs,
1868: $available);
1.3 raeburn 1869: } else {
1.5 raeburn 1870: if ($action eq 'create') {
1871: $r->print($lt{'asyo'});
1872: } elsif ($action eq 'modify' && $formname eq 'pick_members') {
1873: my @defprivs;
1874: if (ref($$stored{'defpriv'}) eq 'ARRAY') {
1875: @defprivs = @{$$stored{'defpriv'}};
1876: }
1877: $r->print($lt{'eaty'}.' '.$lt{cutg});
1878: if ($$stored{'specificity'} eq 'Yes') {
1879: $r->print($lt{'sdif'});
1880: } else {
1881: $r->print($lt{'sall'});
1882: }
1883: $r->print(' '.$lt{'defp'}.'<br /><br />');
1.45 albertel 1884: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 1885: }
1.3 raeburn 1886: }
1887: return;
1888: }
1889:
1.5 raeburn 1890: sub default_privileges {
1.42 albertel 1891: my ($r,$action,$tools,$toolprivs,$fixedprivs,$available) = @_;
1.5 raeburn 1892: my %lt = &Apache::lonlocal::texthash(
1893: 'addp' => 'Additional privileges',
1894: 'fixp' => 'Fixed privileges',
1895: 'oppr' => 'Optional privileges',
1896: 'func' => 'Function',
1897: );
1.42 albertel 1898: $r->print(&Apache::lonhtmlcommon::start_pick_box('LC_group_priv_box').
1899: &Apache::lonhtmlcommon::row_title($lt{'func'},undef,
1900: 'LC_groups_functionality'));
1901: $r->print(join('</td><td class="LC_groups_functionality">',@{$tools}));
1902: $r->print(&Apache::lonhtmlcommon::row_closure(1));
1903: my $fixed = '';
1904: my $dynamic = '';
1.3 raeburn 1905: foreach my $tool (@{$tools}) {
1.5 raeburn 1906: my $privcount = 0;
1.42 albertel 1907: if ($dynamic ne '') {
1908: $dynamic .= '</td><td class="LC_groups_optional">';
1909: }
1910: $dynamic .= '<table class="LC_group_priv"><tr>';
1.5 raeburn 1911: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
1912: if (exists($$fixedprivs{$tool}{$priv})) {
1.42 albertel 1913: if ($fixed ne '') {
1914: $fixed .= '</td><td class="LC_groups_fixed">';
1915: }
1.5 raeburn 1916: $fixed .= '<input type="hidden" name="defpriv" value="'.$priv.'" />'.$$toolprivs{$tool}{$priv}.' ';
1917: if ($action eq 'modify') {
1.42 albertel 1918: if (grep(/^$tool$/,@{$available})) {
1.5 raeburn 1919: $fixed .= '<small>'.&mt('(on)').'<small> ';
1920: } else {
1921: $fixed .= '<small>'.&mt('(off)').'<small> ';
1.3 raeburn 1922: }
1923: }
1.5 raeburn 1924: } else {
1.42 albertel 1925: $privcount++;
1.5 raeburn 1926: if ($privcount == 3) {
1927: $dynamic .= '</tr>
1.42 albertel 1928: <tr>'."\n";
1.5 raeburn 1929: }
1.7 raeburn 1930: $dynamic .= '<td><label><input type="checkbox" name="defpriv" value="'.$priv.'" />'.$$toolprivs{$tool}{$priv}.'</label></td>'."\n";
1.3 raeburn 1931: }
1932: }
1.42 albertel 1933: if ($privcount == 0) {
1934: $dynamic .= '<td>None</td>'."\n";
1.5 raeburn 1935: }
1936: if ($privcount < 3) {
1.42 albertel 1937: $dynamic .= '</td>
1938: <td> </td>'."\n";
1.5 raeburn 1939: } elsif ($privcount%2) {
1940: $dynamic = '<td> </td>'."\n";
1941: }
1.42 albertel 1942: $dynamic .= '</tr></table>';
1.3 raeburn 1943: }
1.42 albertel 1944: $r->print(&Apache::lonhtmlcommon::row_title($lt{'fixp'},undef,
1945: 'LC_groups_fixed').
1946: $fixed.
1947: &Apache::lonhtmlcommon::row_closure(1));
1948: $r->print(&Apache::lonhtmlcommon::row_title($lt{'oppr'},undef,
1949: 'LC_groups_optional').
1950: $dynamic.
1951: &Apache::lonhtmlcommon::end_pick_box());
1.5 raeburn 1952: $r->print('<br />');
1953: return;
1.42 albertel 1954:
1.5 raeburn 1955: }
1956:
1957: sub display_defprivs {
1.45 albertel 1958: my ($r,$tools,$toolprivs,$defprivs) = @_;
1959: my $function = &Apache::loncommon::get_users_function();
1960: my $tabcol = &Apache::loncommon::designparm($function.'.tabbg');
1961: my $rowColor1 = "#dddddd";
1962: my $rowColor2 = "#eeeeee";
1.5 raeburn 1963: my %lt = &Apache::lonlocal::texthash(
1964: 'priv' => 'Privileges',
1965: 'func' => 'Function',
1966: );
1967: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1968: $r->print('<tr>');
1969: my $numrows = 0;
1970: my %currprivs;
1971: foreach my $tool (@{$tools}) {
1972: @{$currprivs{$tool}} = ();
1973: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
1974: if (ref($defprivs) eq 'ARRAY') {
1.45 albertel 1975: if (grep(/^\Q$priv\E$/,@{$defprivs})) {
1.5 raeburn 1976: push(@{$currprivs{$tool}},$priv);
1977: }
1.3 raeburn 1978: }
1979: }
1.5 raeburn 1980: my $rowcount = int(@{$currprivs{$tool}}/3);
1981: if (@{$currprivs{$tool}}%3 > 0) {
1982: $rowcount ++;
1983: }
1984: if ($rowcount > $numrows) {
1985: $numrows = $rowcount;
1986: }
1987: }
1988: my @rowCols = ($rowColor1,$rowColor2);
1989: foreach my $tool (@{$tools}) {
1990: $r->print('<td align="center" valign="top">
1991: <table cellspacing="0" cellpadding="5">
1992: <tr bgcolor="#cccccc">
1993: <td colspan="3" align="center"><b>'.$tool.'</b></td>
1994: </tr>
1995: ');
1996: my $rownum = 1;
1997: my $privcount = 0;
1998: $r->print('<tr bgcolor="'.$rowColor1.'">');
1999: foreach my $priv (@{$currprivs{$tool}}) {
2000: $privcount ++;
2001: if ($privcount%4 == 0) {
2002: $rownum ++;
2003: my $bgcol = $rownum%2;
2004: $r->print('</tr>
2005: <tr bgcolor="'.$rowCols[$bgcol].'">'."\n");
2006: }
2007: $r->print('<td>'.$$toolprivs{$tool}{$priv}.'</td>'."\n");
2008: }
2009: if ($privcount%3 > 0) {
2010: my $emptycells = 3-($privcount%3);
2011: while($emptycells > 0) {
2012: $r->print('<td> </td>'."\n");
2013: $emptycells --;
2014: }
2015: }
2016: while ($rownum < $numrows) {
2017: $rownum ++;
2018: my $bgcol = $rownum%2;
2019: $r->print('<tr bgcolor="'.$rowCols[$bgcol].'"><td colspan="3"> </td></tr>');
1.3 raeburn 2020: }
1.5 raeburn 2021: $r->print('</table>'."\n".'</td>');
2022: }
2023: $r->print('</tr>'."\n");
2024: $r->print(&Apache::lonhtmlcommon::end_pick_box());
2025: $r->print('<br />');
2026: return;
1.3 raeburn 2027: }
1.5 raeburn 2028:
2029:
2030: sub change_members_form {
2031: my ($r,$cdom,$cnum,$tabcol,$action,$formname,$page,$groupname,$description,
2032: $startdate,$enddate,$tools,$fixedprivs,$functions,$users,$userdata,
1.29 raeburn 2033: $granularity,$quota,$specificity,$idx,$states,$navbuttons,$rowColor1,
2034: $rowColor2,$gpterm,$ucgpterm) = @_;
1.5 raeburn 2035: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 2036: grse => "$ucgpterm settings",
2037: mogm => "Modify $gpterm membership",
1.5 raeburn 2038: );
2039: my @regexps = ('user_','userpriv_');
2040: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2041: ['origin','action','state','page','expire','deletion',
1.7 raeburn 2042: 'reenable','activate','changepriv','sortby',
2043: 'togglefunc'],\@regexps));
1.5 raeburn 2044: my $rowimg = 1;
2045: my @available = ();
2046: my @unavailable = ();
2047: &check_tools($functions,$tools,\@available,\@unavailable);
2048: my $nexttext = $$navbuttons{'gtns'};
2049: my $prevtext = $$navbuttons{'gtpp'};
2050: $r->print('
1.3 raeburn 2051: <br />
1.5 raeburn 2052: ');
1.40 albertel 2053: &topic_bar($r,1,$lt{'grse'});
2054: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2055: $groupname,$description,$granularity,$quota,
2056: \@available,\@unavailable,$gpterm,$ucgpterm);
2057: &topic_bar($r,2,$lt{'mogm'});
1.5 raeburn 2058: ¤t_membership($r,$cdom,$cnum,$formname,$tabcol,$rowColor1,
2059: $rowColor2,$groupname,\@available,\@unavailable,
2060: $fixedprivs,$granularity,$specificity);
2061: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2062: $$states{$action}[$page+1],$nexttext);
2063: return;
2064: }
2065:
2066: sub current_membership {
2067: my ($r,$cdom,$cnum,$formname,$tabcol,$rowColor1,$rowColor2,$groupname,
2068: $available,$unavailable,$fixedprivs,$granularity,$specificity) = @_;
2069: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
2070: $groupname);
2071: my %lt = &Apache::lonlocal::texthash(
1.6 raeburn 2072: 'actn' => 'Action?',
2073: 'name' => 'Name',
2074: 'usnm' => 'Username',
2075: 'doma' => 'Domain',
2076: 'stda' => 'Start Date',
2077: 'enda' => 'End Date',
1.5 raeburn 2078: 'expi' => 'Expire',
2079: 'reen' => 'Re-enable',
2080: 'acti' => 'Activate',
2081: 'dele' => 'Delete',
2082: 'curf' => 'Current Functionality',
2083: 'chpr' => 'Change Privileges'
2084: );
1.36 raeburn 2085: my ($current,$hastools,$addtools,$num_reenable,$num_activate,$num_expire) =
2086: &Apache::longroup::group_memberlist($cdom,$cnum,$groupname,$fixedprivs,
2087: $available);
2088: if (keys(%{$current}) > 0) {
2089: $r->print('
1.5 raeburn 2090: <tr>
2091: <td> </td>
2092: <td colspan="2">
2093: <table>
2094: <tr>');
1.36 raeburn 2095: if ($num_expire) {
2096: &check_uncheck_buttons($r,$formname,'expire',$lt{'expi'});
2097: }
2098: if ($num_reenable) {
2099: &check_uncheck_buttons($r,$formname,'reenable',$lt{'reen'});
2100: }
2101: if ($num_activate) {
2102: &check_uncheck_buttons($r,$formname,'activate',$lt{'acti'});
2103: }
2104: &check_uncheck_buttons($r,$formname,'deletion',$lt{'dele'});
2105: if (@{$available} > 0) {
2106: if ($specificity eq 'Yes') {
2107: &check_uncheck_buttons($r,$formname,'changepriv',$lt{'chpr'});
1.5 raeburn 2108: }
1.36 raeburn 2109: if ($granularity eq 'Yes') {
2110: $r->print(&check_uncheck_tools($r,$available));
2111: $r->print('
1.5 raeburn 2112: <td>
2113: <nobr>
2114: <fieldset><legend><b>'.$lt{'curf'}.'</b></legend>
2115: <input type="button" value="check all"
2116: onclick="javascript:checkAllTools(document.'.$formname.')" />
2117:
2118: <input type="button" value="uncheck all"
2119: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
2120: </fieldset>
2121: </nobr>
2122: </td>
2123: ');
1.3 raeburn 2124: }
1.36 raeburn 2125: }
2126: $r->print(<<"END");
1.5 raeburn 2127: </tr>
2128: </table>
2129: </td>
2130: <td width="100%"> </td>
2131: </tr>
1.3 raeburn 2132: <tr>
2133: <td colspan="4"> </td>
2134: </tr>
2135: <tr>
2136: <td> </td>
2137: <td colspan="3">
1.5 raeburn 2138: END
1.36 raeburn 2139: $r->print(&Apache::lonhtmlcommon::start_pick_box());
2140: $r->print(<<"END");
1.5 raeburn 2141: <table border="0" cellpadding="4" cellspacing="1">
2142: <tr bgcolor="$tabcol" align="center">
1.6 raeburn 2143: <td><b>$lt{'actn'}</b></td>
2144: <td><b><a href="javascript:changeSort('fullname')">$lt{'name'}</a></b></td>
2145: <td><b><a href="javascript:changeSort('username')">$lt{'usnm'}</a></b>
1.5 raeburn 2146: </td>
1.6 raeburn 2147: <td><b><a href="javascript:changeSort('domain')">$lt{'doma'}</a></b></td>
1.5 raeburn 2148: <td><b><a href="javascript:changeSort('id')">ID</a></b></td>
1.6 raeburn 2149: <td><b><a href="javascript:changeSort('start')">$lt{'stda'}</a></b></td>
2150: <td><b><a href="javascript:changeSort('end')">$lt{'enda'}</a></b></td>
1.5 raeburn 2151: END
1.36 raeburn 2152: my $colspan = 0;
2153: if ($hastools) {
2154: $r->print('<td><b>'.$lt{'curf'}.'</b></td>');
2155: $colspan ++;
2156: }
2157: if ($addtools) {
2158: $r->print('<td><b>Additional Functionality</b></td>');
2159: $colspan ++;
2160: }
2161: $r->print('</tr>');
2162: if ($colspan) {
2163: if ($granularity eq 'Yes') {
2164: $r->print('<tr bgcolor="#cccccc">
1.6 raeburn 2165: <td colspan="7"> </td>
2166: <td colspan="'.$colspan.'" align="center"><small><nobr><b>'.&mt('All:').
2167: '</b> ');
1.36 raeburn 2168: foreach my $tool (@{$available}) {
2169: $r->print('<label><input type="checkbox" name="togglefunc"'.
1.7 raeburn 2170: ' onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
2171: ' value="'.$tool.'">'.'<b>'.$tool.'</b></label> ');
1.6 raeburn 2172: }
1.36 raeburn 2173: $r->print('</nobr></small></td></tr>');
1.6 raeburn 2174: }
1.36 raeburn 2175: }
2176: my %Sortby = ();
2177: foreach my $user (sort(keys(%{$current}))) {
2178: if ($env{'form.sortby'} eq 'fullname') {
2179: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2180: } elsif ($env{'form.sortby'} eq 'username') {
2181: push(@{$Sortby{$$current{$user}{uname}}},$user);
2182: } elsif ($env{'form.sortby'} eq 'domain') {
2183: push(@{$Sortby{$$current{$user}{udom}}},$user);
2184: } elsif ($env{'form.sortby'} eq 'id') {
2185: push(@{$Sortby{$$current{$user}{id}}},$user);
2186: } else {
2187: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2188: }
2189: }
2190: my $rowNum = 0;
2191: my $rowColor;
2192: foreach my $key (sort(keys(%Sortby))) {
2193: foreach my $user (@{$Sortby{$key}}) {
2194: if ($rowNum %2 == 1) {
2195: $rowColor = $rowColor1;
1.5 raeburn 2196: } else {
1.36 raeburn 2197: $rowColor = $rowColor2;
1.5 raeburn 2198: }
1.36 raeburn 2199: my $id = $$current{$user}{id};
2200: my $fullname = $$current{$user}{fullname};
2201: my $udom = $$current{$user}{udom};
2202: my $uname = $$current{$user}{uname};
2203: my $start = $$current{$user}{start};
2204: my $end = $$current{$user}{end};
2205: $r->print('<tr bgcolor="'.$rowColor.'">
2206: <td><small>');
2207: if ($$current{$user}{changestate} eq 'reenable') {
2208: $r->print('<nobr><label>'.
1.5 raeburn 2209: '<input type="checkbox" name="reenable" value="'.$user.'" />'.
1.7 raeburn 2210: $lt{'reen'}.'</label></nobr><br />');
1.36 raeburn 2211: } elsif ($$current{$user}{changestate} eq 'expire') {
2212: $r->print('<nobr><label>'.
1.5 raeburn 2213: '<input type="checkbox" name="expire" value="'.$user.'" />'.
1.7 raeburn 2214: $lt{'expi'}.'</label></nobr><br />');
1.36 raeburn 2215: } elsif ($$current{$user}{changestate} eq 'activate') {
2216: $r->print('<nobr><label>'.
1.5 raeburn 2217: '<input type="checkbox" name="activate" value="'.$user.'" />'.
1.7 raeburn 2218: $lt{'acti'}.'</label></nobr><br />');
1.36 raeburn 2219: }
2220: $r->print('<nobr><label>'.
1.6 raeburn 2221: '<input type="checkbox" name="deletion" value="'.$user.'" />'.
1.7 raeburn 2222: $lt{'dele'}.'</label></nobr>');
1.36 raeburn 2223: if ($specificity eq 'Yes') {
2224: $r->print('<br /><nobr><label>'.
1.5 raeburn 2225: '<input type="checkbox" name="changepriv" value="'.$user.'" />'.$lt{'chpr'}.
1.7 raeburn 2226: '</label></nobr>');
1.36 raeburn 2227: }
2228: $r->print('
1.5 raeburn 2229: </td>
2230: <td><small>'.
2231: $fullname.'</small></td><td><small>'.$uname.'</small></td><td><small>'.
2232: $udom.'</small></td><td><small>'.$id.'</small></td><td><small>'.$start.
2233: '</small></td><td><small>'.$end.'</small></td>');
1.36 raeburn 2234: if ($hastools) {
2235: $r->print('<td align="left"><small><nobr>'.
1.6 raeburn 2236: ' ');
1.36 raeburn 2237: foreach my $tool (@{$$current{$user}{currtools}}) {
2238: if ($granularity eq 'Yes') {
2239: $r->print('<label><input type="checkbox" '.
1.7 raeburn 2240: 'checked="checked" '.
2241: 'name="user_'.$tool.'" value="'.
2242: $user.'" />'.$tool.'</label>');
1.36 raeburn 2243: } else {
2244: $r->print('<input type="hidden" '.
1.7 raeburn 2245: 'checked="checked" '.
2246: 'name="user_'.$tool.'" value="'.
2247: $user.'" />'.$tool);
1.36 raeburn 2248: }
2249: $r->print(' ');
1.5 raeburn 2250: }
1.36 raeburn 2251: $r->print('</nobr></small></td>');
2252: }
2253: if ($addtools) {
2254: $r->print('<td align="left"><small>');
2255: if ($granularity eq 'Yes') {
2256: foreach my $tool (@{$$current{$user}{newtools}}) {
2257: $r->print('<nobr><label><input type="checkbox"
1.5 raeburn 2258: name="user_'.$tool.'" value="'.
2259: $user.'" />'.$tool.
1.7 raeburn 2260: '</label></nobr> ');
1.36 raeburn 2261: }
2262: } else {
2263: foreach my $tool (@{$$current{$user}{newtools}}) {
2264: $r->print('<nobr><input type="hidden"
1.5 raeburn 2265: name="user_'. $tool.'" value="'.
2266: $user.'" />'.$tool.
2267: '</nobr> ');
2268: }
2269: }
1.36 raeburn 2270: $r->print('</small></td>');
1.5 raeburn 2271: }
1.36 raeburn 2272: $r->print('</tr>'."\n");
2273: $rowNum ++;
1.5 raeburn 2274: }
1.36 raeburn 2275: }
2276: $r->print(&Apache::lonhtmlcommon::end_pick_box());
2277: $r->print('
1.3 raeburn 2278: </td>
1.5 raeburn 2279: </tr>');
2280: }
2281: return;
2282: }
2283:
2284: sub check_uncheck_buttons {
2285: my ($r,$formname,$field,$title,$colspan) = @_;
2286: $r->print('
2287: <td '.$colspan.'>
2288: <nobr>
2289: <fieldset>
2290: <legend><b>'.$title.'</b></legend>
2291: <input type="button" value="check all"
2292: onclick="javascript:checkAll(document.'.$formname.'.'.$field.')" />
2293:
2294: <input type="button" value="uncheck all"
2295: onclick="javascript:uncheckAll(document.'.$formname.'.'.$field.')" />
2296: </fieldset>
2297: </nobr>
2298: </td>
2299: ');
2300: }
2301:
2302:
2303: sub change_privs_form {
1.45 albertel 2304: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,
2305: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,
2306: $memchg,$idx,$states,$stored,$sectioncount,$navbuttons,$gpterm,
2307: $ucgpterm) = @_;
1.5 raeburn 2308: my @regexps = ('userpriv_');
2309: my $nexttext;
1.6 raeburn 2310: my %lt = &Apache::lonlocal::texthash(
2311: 'tode' => 'To be deleted',
2312: 'toex' => 'To be expired',
1.29 raeburn 2313: 'nome' => "No members to be deleted or expired from the $gpterm.",
1.6 raeburn 2314: );
1.5 raeburn 2315: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2316: ['origin','action','state','page','sortby'],\@regexps));
2317: if ($env{'form.branch'} eq 'adds') {
2318: $nexttext = $$navbuttons{'adme'};
2319: } else {
2320: $nexttext = $$navbuttons{'mose'};
2321: }
1.40 albertel 2322: &topic_bar($r,3,&mt('Members to delete or expire'));
1.6 raeburn 2323: my $exp_or_del = 0;
2324: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2325: if (@{$$memchg{'deletion'}} > 0) {
2326: $r->print('<tr><td> </td><td colspan="3"><b>'.$lt{'tode'}.':</b><br /><ul>');
2327: foreach my $user (@{$$memchg{'deletion'}}) {
2328: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2329: ' ('.$user.')</li>');
2330: }
1.45 albertel 2331: $r->print('</ul>');
1.6 raeburn 2332: $exp_or_del += @{$$memchg{'deletion'}};
2333: }
2334: }
2335: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2336: if (@{$$memchg{'expire'}} > 0) {
2337: $r->print('<tr><td> </td><td colspan="3"><b>'.$lt{'toex'}.':</b><br /><ul>');
2338: foreach my $user (@{$$memchg{'expire'}}) {
2339: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2340: ' ('.$user.')</li>');
2341: }
1.45 albertel 2342: $r->print('</ul>');
1.6 raeburn 2343: $exp_or_del += @{$$memchg{'expire'}};
2344: }
2345: }
2346: if (!$exp_or_del) {
1.45 albertel 2347: $r->print($lt{'nome'}.'<br />');
1.6 raeburn 2348: }
1.5 raeburn 2349:
1.40 albertel 2350: &topic_bar($r,4,&mt('[_1] member privileges',$ucgpterm));
1.6 raeburn 2351:
1.45 albertel 2352: my $numchgs = &member_privileges_form($r,$action,$formname,$tools,
1.6 raeburn 2353: $toolprivs,$fixedprivs,$userdata,
2354: $usertools,$idx,$memchg,$states,
1.45 albertel 2355: $stored,$gpterm);
1.5 raeburn 2356: my $prevtext = $$navbuttons{'gtps'};
1.6 raeburn 2357: if ($numchgs || $exp_or_del) {
2358: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2359: $$states{$action}[$page+1],$nexttext);
2360: } else {
2361: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext);
2362: }
1.5 raeburn 2363: return;
2364: }
2365:
2366: sub add_members_form {
1.46 albertel 2367: my ($r,$action,$formname,$page,$startdate,$enddate,$groupname,
1.29 raeburn 2368: $description,$granularity,$quota,$sectioncount,$tools,$functions,
1.46 albertel 2369: $stored,$states,$navbuttons,$gpterm,$ucgpterm)=@_;
1.40 albertel 2370: $r->print(' <br />');
1.5 raeburn 2371: my @available = ();
2372: my @unavailable = ();
2373: &check_tools($functions,$tools,\@available,\@unavailable);
1.40 albertel 2374: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2375: $groupname,$description,$granularity,$quota,
2376: \@available,\@unavailable,$gpterm,$ucgpterm);
2377: &membership_options($r,$action,$formname,$sectioncount,1,$gpterm,$ucgpterm);
1.5 raeburn 2378: my $nexttext = $$navbuttons{'gtns'};
2379: my $prevtext = $$navbuttons{'gtpp'};
2380: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2381: $$states{$action}[$page+1],$nexttext);
2382: return;
2383: }
2384:
2385: sub choose_privs_form {
1.45 albertel 2386: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,
2387: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,$idx,
2388: $states,$stored,$sectioncount,$navbuttons,$gpterm,$ucgpterm,
2389: $crstype) = @_;
1.5 raeburn 2390:
2391: my @regexps = ('userpriv_');
2392: my $nexttext;
2393:
2394: if ($action eq 'create') {
2395: push(@regexps,'sec_');
2396: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2397: ['origin','action','state','page','sortby','autoadd','autodrop'],
1.5 raeburn 2398: \@regexps));
2399: $nexttext = $$navbuttons{'crgr'};
2400: } else {
2401: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2402: ['origin','action','state','page','sortby'],\@regexps));
1.5 raeburn 2403: $nexttext = $$navbuttons{'adme'};
2404: }
2405:
1.40 albertel 2406: &topic_bar($r,6,&mt('[_1] member privileges',$ucgpterm));
1.5 raeburn 2407:
1.45 albertel 2408: &member_privileges_form($r,$action,$formname,$tools,$toolprivs,
1.5 raeburn 2409: $fixedprivs,$userdata,$usertools,$idx,undef,
1.45 albertel 2410: $states,$stored,$gpterm);
1.5 raeburn 2411:
2412: if ($action eq 'create') {
2413: if (keys(%{$sectioncount}) > 0) {
2414: my $img1 = 7;
2415: my $img2 = 8;
1.44 albertel 2416: &mapping_options($r,$action,$formname,$page,$sectioncount,
1.5 raeburn 2417: $states,$stored,$navbuttons,$img1,$img2,
1.44 albertel 2418: $gpterm,$ucgpterm,$crstype);
1.5 raeburn 2419: }
2420: }
2421: my $prevtext = $$navbuttons{'gtps'};
2422: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2423: $$states{$action}[$page+1],$nexttext);
2424: return;
2425: }
2426:
2427: sub build_boxes {
2428: my ($r,$tools,$usertools,$fixedprivs,$toolprivs,$showtools,
1.6 raeburn 2429: $showboxes,$prefix,$specificity,$excluded) = @_;
1.5 raeburn 2430: my $totalboxes = 0;
2431: if (@{$tools} > 0) {
2432: if ($specificity eq 'Yes') {
2433: foreach my $tool (@{$tools}) {
2434: @{$$showboxes{$tool}} = ();
2435: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 2436: if (ref($excluded) eq 'ARRAY') {
2437: if (grep/^$user$/,@{$excluded}) {
2438: next;
2439: }
1.5 raeburn 2440: }
1.6 raeburn 2441: if ($$usertools{$user}{$tool}) {
2442: unless (grep/^$tool$/,@{$showtools}) {
2443: push(@{$showtools},$tool);
2444: }
2445: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2446: unless (exists($$fixedprivs{$tool}{$priv})) {
2447: unless(grep(/^$priv$/,@{$$showboxes{$tool}})) {
2448: push(@{$$showboxes{$tool}},$priv);
2449: $totalboxes ++;
2450: }
1.5 raeburn 2451: }
2452: }
2453: }
2454: }
2455: }
2456: if ($totalboxes > 0) {
2457: $r->print('
2458: <script type="text/javascript">
2459: function checkAllTools(formname) {
2460: ');
2461: foreach my $tool (sort(keys(%{$showboxes}))) {
2462: foreach my $priv (@{$$showboxes{$tool}}) {
2463: $r->print(' checkAll(formname.'.$prefix.$priv.');'."\n");
2464: }
2465: }
2466: $r->print('
2467: }
2468: function uncheckAllTools(formname) {
2469: ');
2470: foreach my $tool (sort(keys(%{$showboxes}))) {
2471: foreach my $priv (@{$$showboxes{$tool}}) {
2472: $r->print(' uncheckAll(formname'.$prefix.$priv.');'."\n");
2473: }
2474: }
2475: $r->print('
2476: }
2477: </script>
2478: ');
2479: }
2480: }
2481: }
2482: return $totalboxes;
2483: }
2484:
2485: sub member_privileges_form {
1.45 albertel 2486: my ($r,$action,$formname,$tools,$toolprivs,$fixedprivs,$userdata,
2487: $usertools,$idx,$memchg,$states,$stored,$gpterm) = @_;
1.5 raeburn 2488: my %lt = &Apache::lonlocal::texthash(
2489: 'addp' => 'Additional privileges',
2490: 'fixp' => 'Fixed privileges',
2491: 'oppr' => 'Optional privileges',
2492: 'func' => 'Function',
2493: 'forf' => 'For the functionality you have chosen to include '.
2494: 'there are no optional privileges to set besides '.
2495: 'the standard privileges.',
1.29 raeburn 2496: 'algr' => "All $gpterm members will receive the same privileges.",
2497: 'asno' => "As no $gpterm members are being added, ".
2498: "there are no specific user privileges to set.",
2499: 'asng' => "As no $gpterm tools will be made available to users, ".
2500: "there are no specific user privileges to set.",
2501: 'nogm' => "No $gpterm member privileges to display or set, ".
2502: "as you have not indicated that you will be activating,".
2503: " re-enabling, changing privileges, or adding/removing ".
2504: "functionality for any current members ",
1.5 raeburn 2505: 'full' => 'Fullname',
2506: 'user' => 'Username',
2507: 'doma' => 'Domain',
2508: );
2509: my @defprivs;
2510: my $specificity;
2511: if ($action eq 'create') {
2512: if (defined($env{'form.defpriv'})) {
2513: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
2514: }
2515: $specificity = $env{'form.specificity'};
2516: } else {
1.17 raeburn 2517: if (defined($$stored{'defpriv'})) {
2518: @defprivs = @{$$stored{'defpriv'}};
2519: }
1.5 raeburn 2520: $specificity = $$stored{'specificity'};
2521: }
2522: my @showtools;
2523: my %showboxes = ();
2524: my $numtools = 1 + @{$tools};
1.3 raeburn 2525:
1.6 raeburn 2526: my @excluded = ();
2527: my $numchgs = 0;
2528: if ($formname eq 'change_privs') {
2529: my @currmembers = ();
2530: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2531: push(@excluded,@{$$memchg{'deletion'}});
2532: }
2533: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2534: push(@excluded,@{$$memchg{'expire'}});
2535: }
2536: if (@excluded > 0) {
2537: foreach my $user (sort(keys(%{$usertools}))) {
2538: if (grep/^$user$/,@excluded) {
2539: next;
2540: }
2541: push(@currmembers,$user);
2542: }
2543: } else {
2544: @currmembers = sort(keys(%{$usertools}));
2545: }
2546: $numchgs = @currmembers;
2547: if (!$numchgs) {
1.45 albertel 2548: $r->print($lt{'nogm'});
1.6 raeburn 2549: return $numchgs;
2550: }
2551: }
2552:
2553: my $totalboxes = &build_boxes($r,$tools,$usertools,$fixedprivs,
2554: $toolprivs,\@showtools,\%showboxes,
2555: 'userpriv_',$specificity,\@excluded);
1.5 raeburn 2556: if (@{$tools} > 0) {
2557: if ($specificity eq 'Yes') {
2558: if ($totalboxes > 0) {
2559: my $numcells = 2;
2560: my $colspan = $numcells + 1;
2561: my %total;
1.6 raeburn 2562: if (keys(%{$usertools}) > 1) {
2563: $r->print('
1.45 albertel 2564: <table border="0" cellspacing="2" cellpadding="2">
1.5 raeburn 2565: <tr>
2566: ');
1.6 raeburn 2567: foreach my $tool (@{$tools}) {
2568: if (@{$showboxes{$tool}} > 0) {
2569: $r->print('<td valign="top">');
1.45 albertel 2570: $r->print('<table class="thinborder"><tr>'.
2571: '<th colspan="'.$colspan.'">'.
1.6 raeburn 2572: $tool.'</th></tr><tr>');
2573: my $privcount = 0;
2574: foreach my $priv (@{$showboxes{$tool}}) {
2575: $privcount ++;
2576: if (($privcount == @{$showboxes{$tool}}) &&
2577: ($privcount > 1)) {
2578: if ($privcount%$numcells) {
2579: $r->print('<td colspan="'.$colspan.'">');
2580: } else {
2581: $r->print('<td>');
2582: }
1.5 raeburn 2583: } else {
2584: $r->print('<td>');
2585: }
1.6 raeburn 2586: $r->print(qq|
1.5 raeburn 2587: <fieldset><legend><b>$$toolprivs{$tool}{$priv}</b></legend>
2588: <nobr>
2589: <input type="button" value="check all"
2590: onclick="javascript:checkAll(document.$formname.userpriv_$priv)" />
2591:
2592: <input type="button" value="uncheck all"
2593: onclick="javascript:uncheckAll(document.$formname.userpriv_$priv)" />
2594: </nobr></fieldset><br />|);
1.6 raeburn 2595: $r->print('</td>');
2596: if ($privcount < @{$showboxes{$tool}}) {
2597: if (@{$showboxes{$tool}} > 2) {
2598: if ($privcount%$numcells == 0) {
2599: $r->print('</tr><tr>');
2600: }
2601: } else {
2602: $r->print('<tr></tr>');
1.5 raeburn 2603: }
2604: }
2605: }
1.6 raeburn 2606: $r->print('</tr></table></td><td> </td>');
1.5 raeburn 2607: }
2608: }
1.45 albertel 2609: $r->print('</tr></table>');
1.5 raeburn 2610: }
1.45 albertel 2611: $r->print(&Apache::loncommon::start_data_table().
2612: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 2613: $r->print(<<"END");
1.45 albertel 2614: <th>$lt{'full'}</th>
2615: <th>$lt{'user'}</th>
1.5 raeburn 2616: <th>$lt{'doma'}</th>
2617: <th colspan="$numtools">$lt{'addp'}</th>
2618: END
1.45 albertel 2619: $r->print(&Apache::loncommon::end_data_table_header_row());
2620: &member_privs_entries($r,$usertools,$toolprivs,$fixedprivs,
1.6 raeburn 2621: $userdata,$idx,\@showtools,\@defprivs,
2622: \@excluded);
1.45 albertel 2623: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 2624: } else {
1.43 albertel 2625: $r->print($lt{'forf'}.'<br />');
1.45 albertel 2626: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 2627: }
2628: } else {
2629: if (keys(%{$usertools}) > 0) {
1.43 albertel 2630: $r->print($lt{'algr'}.'<br /><br />');
1.45 albertel 2631: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 2632: } else {
1.43 albertel 2633: $r->print($lt{'asno'}.'<br />');
1.5 raeburn 2634: }
2635: }
2636: } else {
1.43 albertel 2637: $r->print($lt{'asng'});
1.5 raeburn 2638: }
1.6 raeburn 2639: return $numchgs;
1.1 raeburn 2640: }
2641:
1.5 raeburn 2642: sub process_request {
1.45 albertel 2643: my ($r,$cdom,$cnum,$action,$state,$page,$groupname,$description,
1.5 raeburn 2644: $specificity,$userdata,$startdate,$enddate,$tools,$functions,$toolprivs,
2645: $usertools,$idx,$types,$roles,$sections,$states,$navbuttons,$memchg,
1.45 albertel 2646: $sectioncount,$stored,$gpterm,$ucgpterm,$crstype) = @_;
1.3 raeburn 2647:
2648: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2649: ['origin','action','state','page','sortby']));
1.5 raeburn 2650:
1.29 raeburn 2651: my $earlyout = &validate_groupname($groupname,$action,$cdom,$cnum,$gpterm,
2652: $ucgpterm,$crstype);
1.5 raeburn 2653: if ($earlyout) {
2654: $r->print('
2655: <table width="100%" cellpadding="0" cellspacing="0" border="0">
2656: <tr>
2657: <td> </td>
2658: <td colspan="3">
2659: '.$earlyout.'</td></tr>');
2660: &display_navbuttons($r,$state,$$states{$action}[$page-1],
2661: $$navbuttons{'gtps'});
2662: $r->print('</table>');
2663: return;
2664: }
2665:
2666: my @defprivs = ();
2667: if ($action eq 'create' || $state eq 'chgresult') {
2668: if (defined($env{'form.defpriv'})) {
2669: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
2670: }
2671: if ($state eq 'chgresult') {
2672: my @okprivs = ();
2673: foreach my $tool (@{$tools}) {
2674: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2675: push(@okprivs,$priv);
2676: }
2677: }
2678: my @temp = ();
2679: foreach my $defpriv (@defprivs) {
2680: if (grep/^$defpriv$/,@okprivs) {
2681: push(@temp,$defpriv);
2682: }
2683: }
2684: @defprivs = @temp;
2685: }
2686: } else {
1.17 raeburn 2687: if (defined($$stored{'defpriv'})) {
2688: @defprivs = @{$$stored{'defpriv'}};
2689: }
1.5 raeburn 2690: }
2691:
2692: my $outcome;
2693: if ($action eq 'create' || $state eq 'chgresult') {
2694: $outcome = &write_group_data($r,$cdom,$cnum,$action,$state,$groupname,
2695: $description,$startdate,$enddate,
2696: $specificity,$functions,$tools,
2697: $sectioncount,$roles,$types,$sections,
1.29 raeburn 2698: \@defprivs,$stored,$gpterm,$ucgpterm,
2699: $crstype);
1.5 raeburn 2700: }
2701: if (($action eq 'create' && $outcome eq 'ok') || (($action eq 'modify') &&
2702: (($state eq 'memresult') || ($state eq 'addresult')))) {
1.6 raeburn 2703: &process_membership($r,$cdom,$cnum,$action,$state,$groupname,$tools,
2704: $enddate,$startdate,$userdata,$idx,$toolprivs,
1.29 raeburn 2705: $usertools,$specificity,\@defprivs,$memchg,$gpterm,
2706: $ucgpterm);
1.5 raeburn 2707: }
2708: return;
2709: }
2710:
2711: sub write_group_data {
2712: my ($r,$cdom,$cnum,$action,$state,$groupname,$description,$startdate,
2713: $enddate,$specificity,$functions,$tools,$sectioncount,$roles,$types,
1.29 raeburn 2714: $sections,$defprivs,$stored,$gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 2715: my $now = time;
2716: my $creation = $now;
2717: my $creator = $env{'user.name'}.':'.$env{'user.domain'};
2718: if ($state eq 'chgresult') {
2719: $creation = $$stored{'creation'};
2720: $creator = $$stored{'creator'};
2721: }
1.24 www 2722: my $esc_description = &escape($description);
1.5 raeburn 2723: my @single_attributes = ('description','functions','startdate','enddate',
2724: 'creation','modified','creator','granularity',
1.29 raeburn 2725: 'specificity','autoadd','autodrop','quota');
1.5 raeburn 2726: my @mult_attributes = ('roles','types','sectionpick','defpriv');
1.15 albertel 2727:
1.37 raeburn 2728: my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,
2729: $stored);
2730: my $quota = $env{'form.quota'};
2731:
2732: $quota =~ s/^\s*([^\s]*)\s*$/$1/;
2733: if ($quota eq '') {
2734: $quota = 0;
2735: }
2736: if ($quota !~ /^\d*\.?\d*$/) {
2737: $quota = 0;
2738: $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));
2739: }
2740: if ($quota > $maxposs) {
2741: $quota = $maxposs;
2742: $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));
2743: }
1.5 raeburn 2744: my %groupinfo = (
2745: description => $esc_description,
2746: startdate => $startdate,
2747: enddate => $enddate,
2748: creation => $creation,
2749: modified => $now,
2750: creator => $creator,
2751: granularity => $env{'form.granularity'},
2752: specificity => $specificity,
2753: autoadd => $env{'form.autoadd'},
2754: autodrop => $env{'form.autodrop'},
1.37 raeburn 2755: quota => $quota,
1.5 raeburn 2756: );
1.37 raeburn 2757:
1.5 raeburn 2758: foreach my $func (keys(%{$functions})) {
2759: my $status;
2760: if (grep(/^$func$/,@{$tools})) {
2761: $status = 'on';
2762: } else {
2763: $status = 'off';
2764: }
2765: $groupinfo{'functions'} .= qq|<name id="$func">$status</name>|;
2766: }
2767:
2768: $groupinfo{'roles'} = $roles;
2769: $groupinfo{'types'} = $types;
2770: $groupinfo{'sectionpick'} = $sections;
2771: $groupinfo{'defpriv'} = $defprivs;
2772:
2773: my %groupsettings = ();
2774: foreach my $item (@single_attributes) {
2775: $groupsettings{$groupname} .= qq|<$item>$groupinfo{$item}</$item>|;
2776: }
2777: foreach my $item (@mult_attributes) {
2778: foreach my $entry (@{$groupinfo{$item}}) {
2779: $groupsettings{$groupname} .= qq|<$item>$entry</$item>|;
2780: }
2781: }
2782: my $autosec;
2783: my @autorole = &Apache::loncommon::get_env_multiple('form.autorole');
1.15 albertel 2784:
1.5 raeburn 2785: foreach my $role (@autorole) {
2786: if (defined($env{'form.sec_'.$role})) {
2787: my @autosections=&Apache::loncommon::get_env_multiple('form.sec_'.
2788: $role);
2789: $autosec .= '<role id="'.$role.'">';
2790: foreach my $sec (@autosections) {
2791: $autosec .= '<section>'.$sec.'</section>';
2792: }
2793: $autosec .= '</role>';
2794: }
2795: }
2796: if ($autosec) {
2797: $groupsettings{$groupname} .= qq|<autosec>$autosec</autosec>|;
2798: }
2799: my $result = &Apache::lonnet::modify_coursegroup($cdom,$cnum,
2800: \%groupsettings);
2801:
2802: if ($result eq 'ok') {
2803: if ($action eq 'create') {
1.32 raeburn 2804: my $result = &add_group_folder($cdom,$cnum,$now,$groupname,$action,
2805: $description,$tools,\%groupinfo,
2806: $gpterm,$ucgpterm,$crstype);
2807: if ($result ne 'ok') {
1.37 raeburn 2808: $r->print(&mt('A problem occurred when creating folders for the new [_1]. [_2].<br />',$gpterm,$result));
1.32 raeburn 2809: }
1.29 raeburn 2810: $r->print(&mt('[_1] [_2] was created.<br />',$ucgpterm,$groupname));
1.5 raeburn 2811: } else {
1.29 raeburn 2812: $r->print(&mt('[_1] [_2] was updated.<br />',$ucgpterm,$groupname));
1.5 raeburn 2813: }
2814: } else {
2815: my %actiontype = (
2816: 'create' => 'creating',
2817: 'modify' => 'modifying',
2818: );
1.29 raeburn 2819: &Apache::lonnet::logthis("Failed to store $gpterm $groupname ".
2820: 'in '.lc($crstype).': '.$cnum.
2821: ' in domain: '.$cdom);
1.37 raeburn 2822: $r->print(&mt('An error occurred when [_1] the [_2]. '.
1.29 raeburn 2823: 'Please try again.',$actiontype{$action},$gpterm));
1.5 raeburn 2824: }
2825: return $result;
2826: }
2827:
2828: sub process_membership {
1.6 raeburn 2829: my ($r,$cdom,$cnum,$action,$state,$groupname,$tools,$enddate,$startdate,
1.29 raeburn 2830: $userdata,$idx,$toolprivs,$usertools,$specificity,$defprivs,$memchg,
2831: $gpterm,$ucgpterm)=@_;
1.5 raeburn 2832: my %usersettings = ();
1.6 raeburn 2833: my %added= ();
2834: my %failed = ();
2835: my $num_ok = 0;
2836: my $num_fail = 0;
1.3 raeburn 2837: my %group_privs = ();
1.20 raeburn 2838: my %curr_privs = ();
1.21 raeburn 2839: my %curr_start = ();
2840: my %curr_end = ();
1.3 raeburn 2841: my %tooltype = ();
1.5 raeburn 2842:
1.3 raeburn 2843: foreach my $tool (@{$tools}) {
2844: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2845: $tooltype{$priv} = $tool;
1.5 raeburn 2846: if ($specificity eq 'Yes') {
1.3 raeburn 2847: my @users =
2848: &Apache::loncommon::get_env_multiple('form.userpriv_'.$priv);
2849: foreach my $user (@users) {
2850: $group_privs{$user} .= $priv.':';
1.8 raeburn 2851: if ($state eq 'memresult') {
2852: unless (exists($$usertools{$user}{$tool})) {
2853: $$usertools{$user}{$tool} = 1;
2854: }
2855: }
1.3 raeburn 2856: }
2857: } else {
1.5 raeburn 2858: if (@{$defprivs} > 0) {
1.26 raeburn 2859: if (grep/^\Q$priv\E$/,@{$defprivs}) {
1.5 raeburn 2860: foreach my $user (sort(keys(%{$usertools}))) {
2861: if ($$usertools{$user}{$tool}) {
2862: $group_privs{$user} .= $priv.':';
2863: }
1.3 raeburn 2864: }
2865: }
2866: }
2867: }
2868: }
2869: }
2870: foreach my $user (keys(%group_privs)) {
2871: $group_privs{$user} =~ s/:$//;
2872: }
1.5 raeburn 2873:
1.6 raeburn 2874: my $now = time;
2875: my @activate = ();
2876: my @expire = ();
2877: my @deletion = ();
2878: my @reenable = ();
1.20 raeburn 2879: my @unchanged = ();
1.6 raeburn 2880: if ($state eq 'memresult') {
2881: if (ref($$memchg{'activate'}) eq 'ARRAY') {
2882: @activate = @{$$memchg{'activate'}};
2883: }
2884: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2885: @expire = @{$$memchg{'expire'}};
2886: }
2887: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2888: @deletion = @{$$memchg{'deletion'}};
2889: }
2890: if (ref($$memchg{'reenable'}) eq 'ARRAY') {
2891: @reenable = @{$$memchg{'reenable'}};
2892: }
1.20 raeburn 2893: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
2894: $groupname);
2895: foreach my $key (sort(keys(%membership))) {
2896: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
1.21 raeburn 2897: ($curr_end{$1},$curr_start{$1},$curr_privs{$1}) =
2898: split(/:/,$membership{$key},3);
1.20 raeburn 2899: }
2900: }
1.6 raeburn 2901: if (@expire + @deletion > 0) {
2902: foreach my $user (@expire) {
1.21 raeburn 2903: my $savestart = $curr_start{$user};
2904: if ($savestart > $now) {
2905: $savestart = $now;
1.6 raeburn 2906: }
1.21 raeburn 2907: $usersettings{$groupname.':'.$user} = $now.':'.$savestart.':'.
2908: $curr_privs{$user};
1.6 raeburn 2909: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.21 raeburn 2910: $user,$now,$savestart,
2911: $curr_privs{$user}) eq 'ok') {
1.6 raeburn 2912: push(@{$added{'expired'}},$user);
2913: $num_ok ++;
2914: } else {
2915: push(@{$failed{'expired'}},$user);
2916: $num_fail ++;
2917: }
2918: }
2919: foreach my $user (@deletion) {
2920: $usersettings{$groupname.':'.$user} = $now.':-1:';
2921: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
2922: $user,$now,'-1','')
2923: eq 'ok') {
2924: push(@{$added{'deleted'}},$user);
2925: $num_ok ++;
2926: } else {
2927: push(@{$failed{'deleted'}},$user);
2928: $num_fail ++;
2929: }
2930: }
2931: }
1.8 raeburn 2932: }
1.6 raeburn 2933:
1.5 raeburn 2934: foreach my $user (sort(keys(%{$usertools}))) {
1.20 raeburn 2935: if ((grep(/^$user$/,@expire)) || (grep(/^$user$/,@deletion))) {
2936: next;
2937: }
1.6 raeburn 2938: my $type;
2939: my $start = $startdate;
2940: my $end = $enddate;
2941: if ($state eq 'memresult') {
2942: if (@activate > 0) {
2943: if (grep/^$user$/,@activate) {
2944: $start = $now;
1.21 raeburn 2945: $end = $enddate;
1.6 raeburn 2946: $type = 'activated';
2947: }
2948: }
2949: if (@reenable > 0) {
2950: if (grep/^$user$/,@reenable) {
1.21 raeburn 2951: $start = $startdate;
2952: $end = $enddate;
1.6 raeburn 2953: $type = 'reenabled';
2954: }
2955: }
1.38 raeburn 2956: if ($type eq '') {
2957: if ($curr_privs{$user} eq $group_privs{$user}) {
2958: push(@unchanged,$user);
2959: next;
2960: }
2961: if (exists($curr_start{$user})) {
2962: $start = $curr_start{$user};
2963: }
2964: if (exists($curr_end{$user})) {
2965: $end = $curr_end{$user};
2966: }
2967: $type = 'modified';
2968: }
1.6 raeburn 2969: } else {
2970: $type = 'added';
2971: }
2972: $usersettings{$groupname.':'.$user} = $end.':'.$start.':'.
1.5 raeburn 2973: $group_privs{$user};
2974: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.6 raeburn 2975: $user,$end,$start,
1.5 raeburn 2976: $group_privs{$user}) eq 'ok') {
1.6 raeburn 2977: push(@{$added{$type}},$user);
2978: $num_ok ++;
1.3 raeburn 2979: } else {
1.6 raeburn 2980: push(@{$failed{$type}},$user);
2981: $num_fail ++;
1.5 raeburn 2982: }
2983: }
2984: my $roster_result = &Apache::lonnet::modify_coursegroup_membership($cdom,
2985: $cnum,\%usersettings);
1.6 raeburn 2986: if ($num_ok) {
2987: foreach my $type (sort(keys(%added))) {
2988: $r->print(&mt('The following users were successfully [_1]',$type));
1.20 raeburn 2989: if (!($type eq 'deleted' || $type eq 'expired')) {
1.6 raeburn 2990: $r->print(&mt(' with the following privileges'));
2991: }
2992: $r->print(':<br />');
2993: foreach my $user (@{$added{$type}}) {
1.8 raeburn 2994: my $privlist = '';
2995: if (!($type eq 'deleted' || $type eq 'expired')) {
2996: $privlist = ': ';
1.6 raeburn 2997: my @privs = split(/:/,$group_privs{$user});
2998: my $curr_tool = '';
2999: foreach my $priv (@privs) {
3000: unless ($curr_tool eq $tooltype{$priv}) {
3001: $curr_tool = $tooltype{$priv};
3002: $privlist .= '<b>'.$curr_tool.'</b>: ';
3003: }
3004: $privlist .= $$toolprivs{$curr_tool}{$priv}.', ';
3005: }
3006: $privlist =~ s/, $//;
3007: }
1.8 raeburn 3008: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.$privlist.'<br />');
1.6 raeburn 3009: }
1.20 raeburn 3010: $r->print('<br />');
1.6 raeburn 3011: }
3012: }
3013: if ($num_fail) {
3014: foreach my $type (sort(keys(%failed))) {
3015: $r->print(&mt('The following users could not be [_1], because an error occurred:<br />',$type));
3016: foreach my $user (@{$failed{$type}}) {
3017: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
3018: }
1.5 raeburn 3019: }
1.20 raeburn 3020: $r->print('<br />');
3021: }
3022: if (@unchanged > 0) {
3023: $r->print(&mt('No change occurred for the following users:<br />'));
3024: foreach my $user (sort(@unchanged)) {
3025: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
3026: }
3027: $r->print('<br />');
1.5 raeburn 3028: }
3029: if ($roster_result eq 'ok') {
1.29 raeburn 3030: $r->print('<br />'.&mt('[_1] membership list updated.',$ucgpterm));
1.30 albertel 3031: $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 3032: } else {
1.29 raeburn 3033: $r->print('<br />'.&mt('An error occurred while updating the [_1] membership list -',$gpterm).$roster_result.'<br />');
1.5 raeburn 3034: }
3035: return;
3036: }
3037:
3038: sub mapping_options {
1.44 albertel 3039: my ($r,$action,$formname,$page,$sectioncount,$states,$stored,
3040: $navbuttons,$img1,$img2,$gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 3041: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 3042: 'auto' => "Settings for automatic $gpterm enrollment",
3043: 'gmma' => "$ucgpterm membership mapping to specific sections/roles",
3044: 'endi' => "Enable/disable automatic $gpterm enrollment for ".
3045: "users in specified roles and sections",
3046: '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.",
3047: '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.",
3048: 'pirs' => "Pick roles and sections for automatic $gpterm enrollment",
1.5 raeburn 3049: 'curr' => 'Currently set to',
3050: 'on' => 'on',
3051: 'off' => 'off',
1.29 raeburn 3052: 'auad' => "Automatically enable $gpterm membership when roles are added?",
3053: 'auex' => "Automatically expire $gpterm membership when roles are removed?",
3054: 'mapr' => "Mapping of roles and sections affected by automatic $gpterm enrollment/disenrollment follows scheme chosen below.",
1.5 raeburn 3055: );
1.44 albertel 3056: &automapping($r,$action,$stored,\%lt,$img1);
3057: &mapping_settings($r,$sectioncount,\%lt,$stored,$img2,$crstype);
1.5 raeburn 3058: return;
3059: }
3060:
3061: sub automapping {
1.44 albertel 3062: my ($r,$action,$stored,$lt,$image) = @_;
1.5 raeburn 3063: my $add = 'off';
3064: my $drop = 'off';
3065: if (exists($$stored{'autoadd'})) {
3066: $add = $$stored{'autoadd'};
3067: }
3068: if (exists($$stored{'autodrop'})) {
3069: $drop = $$stored{'autodrop'};
3070: }
1.40 albertel 3071: &topic_bar($r,$image,$$lt{'endi'});
1.5 raeburn 3072: $r->print('
1.44 albertel 3073: <b>'.$$lt{'gmma'}.':</b><br />'.$$lt{'adds'}.'<br />'.$$lt{'drops'}.'<br /><br />
1.5 raeburn 3074: <nobr>'.$$lt{'auad'}.':
1.18 albertel 3075: <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 3076: if ($action eq 'modify') {
3077: $r->print(' ('.$$lt{'curr'}.' <b>'.$$lt{$add}.'</b>)');
3078: }
3079: $r->print('
1.44 albertel 3080: </nobr><br />
1.5 raeburn 3081: <nobr>'.$$lt{'auex'}.':
1.18 albertel 3082: <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 3083: if ($action eq 'modify') {
3084: $r->print(' ('.$$lt{'curr'}.' <b>'.$$lt{$drop}.'</b>)');
1.3 raeburn 3085: }
1.44 albertel 3086: $r->print('</nobr><br /><br />'.$$lt{'mapr'});
1.5 raeburn 3087: }
1.3 raeburn 3088:
1.5 raeburn 3089: sub mapping_settings {
1.44 albertel 3090: my ($r,$sectioncount,$lt,$stored,$image,$crstype) = @_;
1.5 raeburn 3091: my @sections = keys(%{$sectioncount});
3092: if (@sections > 0) {
3093: @sections = sort {$a cmp $b} @sections;
1.17 raeburn 3094: unshift(@sections,'none'); # Put 'no sections' next
3095: unshift(@sections,'all'); # Put 'all' at the front of the list
1.3 raeburn 3096: }
1.40 albertel 3097: &topic_bar($r,$image,$$lt{'pirs'});
1.5 raeburn 3098: my @roles = &standard_roles();
3099: my %customroles = &my_custom_roles();
1.44 albertel 3100: $r->print(&Apache::loncommon::start_data_table().
3101: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 3102: $r->print('
3103: <th>'.&mt('Active?').'</th>
3104: <th>'.&mt('Role').'</th>');
3105: if (@sections > 0) {
1.44 albertel 3106: $r->print('<th>'.&mt('Sections').'</th>');
1.3 raeburn 3107: }
1.44 albertel 3108: $r->print(&Apache::loncommon::end_data_table_header_row()."\n");
1.5 raeburn 3109: foreach my $role (@roles) {
1.29 raeburn 3110: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.5 raeburn 3111: my $sections_sel;
3112: if (@sections > 0) {
1.17 raeburn 3113: if ($role eq 'cc') {
3114: $sections_sel = '<td align="right">'.
3115: &mt('all sections').'<input type="hidden" '.
3116: 'name="sec_cc" value="all" /></td>';
3117: } else {
3118: $sections_sel='<td align="right">'.
3119: §ions_selection(\@sections,'sec_'.$role).
3120: '</td>';
3121: }
1.5 raeburn 3122: }
1.44 albertel 3123: $r->print(&Apache::loncommon::start_data_table_row().
3124: '<td><input type="checkbox" '.
1.45 albertel 3125: 'name="autorole" value="'.$role.'" /></td><td>'.$plrole.
1.44 albertel 3126: '</td>'.$sections_sel.
3127: &Apache::loncommon::end_data_table_row());
1.5 raeburn 3128: }
3129: foreach my $role (sort(keys(%customroles))) {
3130: my $sections_sel;
3131: if (@sections > 0) {
1.44 albertel 3132: $sections_sel =
3133: '<td>'.§ions_selection(\@sections,'sec_'.$role).'</td>';
1.5 raeburn 3134: }
1.44 albertel 3135: $r->print(&Apache::loncommon::start_data_table_row().
3136: '<td><input type="checkbox" '.
1.45 albertel 3137: 'value="'.$role.'" /></td><td>'.$role.'</td>'.
1.44 albertel 3138: $sections_sel.
3139: &Apache::loncommon::end_data_table_row());
1.5 raeburn 3140: }
1.44 albertel 3141: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 3142: return;
3143: }
1.3 raeburn 3144:
1.5 raeburn 3145: sub standard_roles {
1.17 raeburn 3146: my @roles = ('cc','in','ta','ep','st');
1.5 raeburn 3147: return @roles;
3148: }
3149:
3150: sub my_custom_roles {
3151: my %returnhash=();
3152: my %rolehash=&Apache::lonnet::dump('roles');
3153: foreach (keys %rolehash) {
3154: if ($_=~/^rolesdef\_(\w+)$/) {
3155: $returnhash{$1}=$1;
3156: }
3157: }
3158: return %returnhash;
3159: }
3160:
3161: sub modify_menu {
1.29 raeburn 3162: my ($r,$groupname,$page,$gpterm) = @_;
1.5 raeburn 3163: my @menu =
3164: (
1.29 raeburn 3165: { text => "Modify default $gpterm settings",
1.5 raeburn 3166: help => 'Course_Modify_Group',
3167: state => 'change_settings',
3168: branch => 'settings',
3169: },
1.6 raeburn 3170: { text => 'Modify access, tools and/or privileges for previous, '.
3171: 'future, or current members',
1.5 raeburn 3172: help => 'Course_Modify_Group_Membership',
3173: state => 'change_members',
3174: branch => 'members',
3175: },
1.29 raeburn 3176: { text => "Add member(s) to the $gpterm",
1.5 raeburn 3177: help => 'Course_Group_Add_Members',
3178: state => 'add_members',
3179: branch => 'adds',
3180: },
3181: );
3182: my $menu_html = '';
3183: foreach my $menu_item (@menu) {
3184: $menu_html .=
3185: '<p><font size="+1"><a href="/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state='.$menu_item->{'state'}.'&branch='.$menu_item->{'branch'}.'">';
3186: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
3187: if (exists($menu_item->{'help'})) {
3188: $menu_html.=
3189: &Apache::loncommon::help_open_topic($menu_item->{'help'});
3190: }
3191: $menu_html.='</p>'.$/;
1.3 raeburn 3192: }
1.5 raeburn 3193: $r->print($menu_html);
1.3 raeburn 3194: return;
3195: }
3196:
3197: sub member_privs_entries {
1.45 albertel 3198: my ($r,$usertools,$toolprivs,$fixedprivs,$userdata,$idx,$showtools,
3199: $defprivs,$excluded) = @_;
1.5 raeburn 3200: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 3201: if (defined($excluded)) {
3202: if (ref($excluded) eq 'ARRAY') {
3203: if (grep/^$user$/,@{$excluded}) {
3204: next;
3205: }
3206: }
3207: }
1.5 raeburn 3208: my ($uname,$udom) = split(/:/,$user);
1.45 albertel 3209: $r->print(&Apache::loncommon::start_data_table_row().'
1.5 raeburn 3210: <td>'.$$userdata{$user}[$$idx{fullname}].'</td>
1.3 raeburn 3211: <td>'.$uname.'</td>
3212: <td>'.$udom.'</td>
3213: <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 3214: foreach my $tool (@{$showtools}) {
3215: if (exists($$usertools{$user}{$tool})) {
1.45 albertel 3216: $r->print('<td valign="top"><table><tr><th colspan="2">'.$tool.'</th></tr>');
1.3 raeburn 3217: my $privcount = 0;
3218: my $fixed = '';
3219: my $dynamic = '';
3220: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3221: if (exists($$fixedprivs{$tool}{$priv})) {
1.5 raeburn 3222: $fixed .= '<input type="hidden" name="userpriv_'.$priv.'" value="'.$user.'" />'.$$toolprivs{$tool}{$priv}.' ';
1.3 raeburn 3223: } else {
3224: $privcount ++;
3225: if ($privcount == 3) {
3226: $dynamic .= '</tr><tr>';
3227: }
1.7 raeburn 3228: $dynamic .='<td><nobr><label><input type="checkbox" '.
1.5 raeburn 3229: 'name="userpriv_'.$priv.'" value="'.$user.'"';
3230: if (grep/^\Q$priv\E$/,@{$defprivs}) {
3231: $dynamic .= ' checked="checked" ';
3232: }
3233: $dynamic .= ' />'.$$toolprivs{$tool}{$priv}.
1.7 raeburn 3234: '</label></nobr></td>';
1.3 raeburn 3235: }
3236: }
3237: $r->print('<tr><td colspan="2"><nobr>'.$fixed.'</nobr></td></tr><tr>'.$dynamic.'</tr></table></td>');
3238: } else {
1.45 albertel 3239: $r->print('<td valign="top"><table width="100%"><tr><th colspan="2">'.$tool.'</th></tr><tr><td> </td></tr><tr><td> </td></tr></table></td>');
1.3 raeburn 3240: }
3241: }
1.45 albertel 3242: $r->print(&Apache::loncommon::end_data_table_row());
1.3 raeburn 3243: }
3244: }
3245:
3246: sub get_dates_from_form {
3247: my $startdate;
3248: my $enddate;
3249: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
3250: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
3251: if ( exists ($env{'form.no_end_date'}) ) {
3252: $enddate = 0;
3253: }
3254: return ($startdate,$enddate);
1.5 raeburn 3255: }
3256:
1.3 raeburn 3257: sub date_setting_table {
3258: my ($starttime,$endtime,$formname) = @_;
3259: my $startform = &Apache::lonhtmlcommon::date_setter($formname,
3260: 'startdate',$starttime);
3261: my $endform = &Apache::lonhtmlcommon::date_setter($formname,
3262: 'enddate',$endtime);
1.41 albertel 3263: my $perpetual =
3264: '<nobr><label><input type="checkbox" name="no_end_date" />'.
3265: &mt('None').'</label></nobr>';
1.42 albertel 3266: my $table = "<table class=\"LC_descriptive_input\">\n".
3267: '<tr><td class="LC_description">'.&mt('Start:').'</td>'.
1.3 raeburn 3268: '<td>'.$startform.'</td>'.
1.41 albertel 3269: '<td> </td>'."</tr>\n".
1.42 albertel 3270: '<tr><td class="LC_description">'.&mt('End:').'</td>'.
1.3 raeburn 3271: '<td>'.$endform.'</td>'.
1.41 albertel 3272: '<td>'.$perpetual.'</td>'."</tr>\n".
3273: "</table>\n";
3274: return $table;
1.1 raeburn 3275: }
3276:
1.32 raeburn 3277: sub add_group_folder {
3278: my ($cdom,$cnum,$now,$groupname,$action,$description,$tools,$groupinfo,
3279: $gpterm,$ucgpterm,$crstype) = @_;
3280: if ($cdom eq '' || $cnum eq '') {
3281: return &mt('Error: invalid course domain or number - group folder creation failed');
3282: }
3283: my ($outcome,$allgrpsmap,$grpmap,$boardsmap,$grppage);
3284: my $navmap = Apache::lonnavmaps::navmap->new();
3285: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
1.47 ! raeburn 3286: $allgrpsmap = $crspath.'group_allfolders.sequence';
1.32 raeburn 3287: my $topmap = $navmap->getResourceByUrl($allgrpsmap);
3288: undef($navmap);
3289: if ($action eq 'create') {
1.47 ! raeburn 3290: # check if group_allfolders.sequence exists.
1.32 raeburn 3291: if (!$topmap) {
3292: my $grpstitle = &mt('[_1] [_2]',$crstype,$ucgpterm);
3293: my $topmap_url = '/'.$env{'course.'.$env{'request.course.id'}.'.url'};
3294: $topmap_url =~ s|/+|/|g;
3295: if ($topmap_url =~ m|^/uploaded|) {
1.47 ! raeburn 3296: $outcome = &map_updater($cdom,$cnum,'group_allfolders.sequence',
1.32 raeburn 3297: 'toplevelgroup',$grpstitle,$topmap_url);
3298: if ($outcome ne 'ok') {
3299: return $outcome;
3300: }
3301: } else {
1.47 ! raeburn 3302: $outcome = &mt('Non-standard course - folder for all groups not added.');
1.32 raeburn 3303: return $outcome;
3304: }
3305: }
3306: my $grpfolder = &mt('[_1] Folder -',$ucgpterm,).$description;
3307: $grppage='/adm/'.$cdom.'/'.$cnum.'/'.$groupname.'/grppg';
3308: my $grptitle = &mt('Group homepage').' - '.$description;
3309: my ($seqid,$discussions,$disctitle);
1.47 ! raeburn 3310: my $outcome = &map_updater($cdom,$cnum,'group_folder_'.$groupname.'.sequence',
1.32 raeburn 3311: 'grpseq',$grpfolder,$allgrpsmap,$grppage,
3312: $grptitle);
3313: if ($outcome ne 'ok') {
3314: return $outcome;
3315: }
3316: my $pageout = &create_homepage($cdom,$cnum,$groupname,$groupinfo,
3317: $tools,$gpterm,$ucgpterm,$now);
3318: # Link to folder for bulletin boards
1.47 ! raeburn 3319: $grpmap = $crspath.'group_folder_'.$groupname.'.sequence';
1.32 raeburn 3320: if (grep/^discussion$/,@{$tools}) {
3321: $seqid = $now + 1;
3322: $disctitle = &mt('Discussion Boards');
1.47 ! raeburn 3323: my $outcome = &map_updater($cdom,$cnum,'group_boards_'.$groupname.
1.32 raeburn 3324: '.sequence','bbseq',$disctitle,$grpmap);
3325: if ($outcome ne 'ok') {
3326: return $outcome;
3327: }
1.47 ! raeburn 3328: $boardsmap = $crspath.'group_boards_'.$groupname.'.sequence';
1.32 raeburn 3329: }
3330: } else {
3331: #modify group folder if status of discussions tools is changed
3332: }
3333: my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.33 raeburn 3334: $navmap = Apache::lonnavmaps::navmap->new();
1.32 raeburn 3335: # modify parameters
3336: my $parm_result;
3337: if ($action eq 'create') {
3338: if ($allgrpsmap) {
3339: $parm_result .= &parm_setter($navmap,$cdom,$allgrpsmap,$groupname);
3340: }
3341: if ($grpmap) {
3342: $parm_result .= &parm_setter($navmap,$cdom,$grpmap,$groupname);
3343: }
3344: if ($grppage) {
3345: $parm_result .= &parm_setter($navmap,$cdom,$grppage,$groupname);
3346: }
3347: if ($boardsmap) {
3348: $parm_result .= &parm_setter($navmap,$cdom,$boardsmap,$groupname);
3349: }
3350: }
3351: if ($parm_result) {
3352: return $parm_result;
3353: } else {
3354: return 'ok';
3355: }
3356: }
3357:
3358: sub map_updater {
3359: my ($cdom,$cnum,$newfile,$itemname,$itemtitle,$parentmap,$startsrc,
3360: $starttitle,$endsrc,$endtitle) = @_;
3361: my $outcome;
3362: $env{'form.'.$itemname} = &new_map($startsrc,$starttitle,$endsrc,
3363: $endtitle);
3364: my $newmapurl=&Apache::lonnet::finishuserfileupload($cnum,$cdom,$itemname,
3365: $newfile);
3366: if ($newmapurl !~ m|^/uploaded|) {
1.37 raeburn 3367: $outcome = &mt('Error uploading new folder.')." ($newfile): $newmapurl".'<br />';
1.32 raeburn 3368: return $outcome;
3369: }
3370: my ($errtext,$fatal)=&Apache::lonratedt::mapread($parentmap);
3371: if ($fatal) {
1.37 raeburn 3372: $outcome = &mt('Error reading contents of parent folder')." ($parentmap): $errtext".'<br />';
1.32 raeburn 3373: return $outcome;
3374: } else {
3375: my $newidx=&Apache::lonratedt::getresidx($newmapurl);
3376: $Apache::lonratedt::resources[$newidx] = $itemtitle.':'.$newmapurl.
3377: ':false:normal:res';
3378: $Apache::lonratedt::order[1+$#Apache::lonratedt::order]=$newidx;
3379: my ($outtext,$errtext) = &Apache::lonratedt::storemap($parentmap,1);
3380: if ($errtext) {
1.37 raeburn 3381: $outcome = &mt('Error storing updated parent folder')." ($parentmap): $errtext".'<br />';
1.32 raeburn 3382: return $outcome;
3383: }
3384: }
3385: return 'ok';
3386: }
3387:
3388: sub new_map {
3389: my ($startsrc,$starttitle,$endsrc,$endtitle) = @_;
3390: my $newmapstr = '
3391: <map>
3392: <resource id="1" src="'.$startsrc.'" type="start" title="'.$starttitle.'"></resource>
3393: <link from="1" to="2" index="1"></link>
3394: <resource id="2" src="'.$endsrc.'" type="finish" title="'.$endtitle.'"></resource>
3395: </map>
3396: ';
3397: return $newmapstr;
3398: }
3399:
3400: sub parm_setter {
3401: my ($navmap,$cdom,$url,$groupname) = @_;
1.37 raeburn 3402: my $allresults;
1.32 raeburn 3403: my %hide_settings = (
3404: 'course' => {
3405: 'num' => 13,
3406: 'set' => 'yes',
3407: },
3408: 'group' => {
3409: 'num' => 5,
3410: 'set' => 'no',
3411: 'extra' => $groupname,
3412: },
3413: );
3414: my $res = $navmap->getResourceByUrl($url);
3415: my $symb = $res->symb();
3416: foreach my $level (keys(%hide_settings)) {
1.37 raeburn 3417: my $parmresult = &Apache::lonparmset::storeparm_by_symb($symb,
1.32 raeburn 3418: '0_hiddenresource',
3419: $hide_settings{$level}{'num'},
3420: $hide_settings{$level}{'set'},
3421: 'string_yesno',undef,$cdom,
3422: undef,undef,
3423: $hide_settings{$level}{'extra'});
1.37 raeburn 3424: if ($parmresult) {
3425: $allresults .= $level.': '.$parmresult;
3426: }
1.32 raeburn 3427: }
1.37 raeburn 3428: return $allresults;
1.32 raeburn 3429: }
3430:
1.3 raeburn 3431: sub create_homepage {
1.32 raeburn 3432: my ($cdom,$cnum,$name,$groupinfo,$tools,$gpterm,$ucgpterm,$now) = @_;
1.3 raeburn 3433: my $functionality = join(',',@{$tools});
1.24 www 3434: my $content = &unescape($$groupinfo{description});
1.3 raeburn 3435: $content=~s/\s+$//s;
3436: $content=~s/^\s+//s;
3437: $content=~s/\<br\s*\/*\>$//s;
3438: $content=&Apache::lonfeedback::clear_out_html($content,1);
3439:
3440: my %pageinfo = (
1.29 raeburn 3441: 'aaa_title' => "$ucgpterm: $name",
1.3 raeburn 3442: 'abb_links' => $functionality,
3443: 'bbb_content' => $content,
3444: 'ccc_webreferences' => '',
1.32 raeburn 3445: 'uploaded.lastmodified' => $now,
1.3 raeburn 3446: );
3447: my $putresult = &Apache::lonnet::put('grppage_'.$name,\%pageinfo,$cdom,$cnum);
3448: return $putresult;
1.1 raeburn 3449: }
3450:
1.5 raeburn 3451: sub check_uncheck_tools {
3452: my ($r,$available) = @_;
3453: if (ref($available) eq 'ARRAY') {
3454: $r->print('
3455: <script type="text/javascript">
3456: function checkAllTools(formname) {
3457: ');
3458: foreach my $tool (@{$available}) {
3459: $r->print(' checkAll(formname.user_'.$tool.');'."\n");
3460: }
3461: $r->print(' checkAll(formname.togglefunc);'."\n");
3462: $r->print('
3463: }
3464: function uncheckAllTools(formname) {
3465: ');
3466: foreach my $tool (@{$available}) {
3467: $r->print(' uncheckAll(formname.user_'.$tool.');'."\n");
3468: }
3469: $r->print(' uncheckAll(formname.togglefunc);'."\n");
3470: $r->print('
3471: }
3472: function toggleTools(field,caller) {
3473: if (caller.checked) {
3474: checkAll(field);
3475: } else {
3476: uncheckAll(field);
3477: }
3478: return;
3479: }
3480: </script>
3481: ');
3482: }
3483: return;
3484: }
3485:
3486: sub validate_groupname {
1.29 raeburn 3487: my ($groupname,$action,$cdom,$cnum,$gpterm,$ucgpterm,$crstype) = @_;
1.16 albertel 3488: my %sectioncount = &Apache::loncommon::get_sections($cdom,$cnum);
1.17 raeburn 3489: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.15 albertel 3490:
1.5 raeburn 3491: my %lt = &Apache::lonlocal::texthash (
1.29 raeburn 3492: igna => "Invalid $gpterm name",
3493: tgne => "The $gpterm name entered ",
3494: grna => "$ucgpterm names and section names used in a ".
3495: "$crstype must be unique.",
3496: isno => "is not a valid name.",
3497: gnmo => "$ucgpterm names may only contain letters, ".
3498: "numbers or underscores.",
3499: cnnb => "can not be used as it is the name of ",
3500: inth => " in this $crstype",
3501: thgr => "- does not correspond to the name of an ".
3502: "existing $gpterm",
1.5 raeburn 3503: );
1.15 albertel 3504:
1.42 albertel 3505: my $exitmsg = '<span class="LC_error">'.$lt{'igna'}.'</span><br /><br />'.
3506: $lt{'tgne'}.' "'.$groupname.'" ';
1.5 raeburn 3507: my $dupmsg = $lt{'grna'};
3508: my $earlyout;
3509: if (($groupname eq '') || ($groupname =~ /\W/)) {
3510: $earlyout = $exitmsg.$lt{'isno'}.'<br />'.$lt{'gnmo'};
3511: return $earlyout;
3512: }
1.16 albertel 3513: if (exists($sectioncount{$groupname})) {
3514: return $exitmsg.$lt{'cnnb'}.&mt('a section').$lt{'inth'}.
3515: '<br />'.$lt{'grna'};
1.5 raeburn 3516: }
1.15 albertel 3517: if ($action eq 'create'
3518: && exists($curr_groups{$groupname})) {
3519:
1.29 raeburn 3520: return $exitmsg.$lt{'cnnb'}.&mt('an existing [_1]',$gpterm).
1.15 albertel 3521: $lt{'inth'}.'<br />'.$lt{'grna'};
3522:
1.5 raeburn 3523: } elsif ($action eq 'modify') {
3524: unless(exists($curr_groups{$groupname})) {
1.29 raeburn 3525: $earlyout = &mt('[_1] name:',$ucgpterm).' '.$groupname.$lt{'thgr'}.
3526: $lt{'inth'};
1.5 raeburn 3527: return $earlyout;
3528: }
3529: }
3530: return;
3531: }
3532:
3533: sub topic_bar {
1.40 albertel 3534: my ($r,$imgnum,$title) = @_;
1.5 raeburn 3535: $r->print('
1.40 albertel 3536: <div class="LC_topic_bar">
1.45 albertel 3537: <img alt="'.&mt('Step [_1]',$imgnum).
3538: '"src="/res/adm/pages/bl_step'.$imgnum.'.gif" />
3539: <span>'.$title.'</span>
1.40 albertel 3540: </div>
1.5 raeburn 3541: ');
3542: return;
3543: }
3544:
3545: sub check_changes {
3546: my ($member_changes,$memchg) = @_;
3547: my %exclusions;
3548: @{$exclusions{'changefunc'}} = ('expire');
3549: @{$exclusions{'changepriv'}} = ('expire','changefunc');
3550:
3551: foreach my $change (@{$member_changes}) {
1.6 raeburn 3552: if ($change eq 'deletion') {
1.5 raeburn 3553: next;
3554: }
1.6 raeburn 3555: my @checks = ('deletion');
1.5 raeburn 3556: if (exists($exclusions{$change})) {
3557: push(@checks,@{$exclusions{$change}});
3558: }
3559: my @temp = ();
3560: foreach my $item (@{$$memchg{$change}}) {
3561: my $match = 0;
3562: foreach my $check (@checks) {
1.6 raeburn 3563: if (defined($$memchg{$check})) {
3564: if (ref(@{$$memchg{$check}}) eq 'ARRAY') {
3565: if (@{$$memchg{$check}} > 0) {
3566: if (grep/^$item$/,@{$$memchg{$check}}) {
3567: $match = 1;
3568: last;
3569: }
3570: }
1.5 raeburn 3571: }
3572: }
3573: }
3574: if ($match) {
3575: next;
3576: }
3577: push(@temp,$item);
3578: }
3579: @{$$memchg{$change}} = @temp;
3580: }
3581: }
1.3 raeburn 3582:
1.1 raeburn 3583: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>