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