File:
[LON-CAPA] /
loncom /
interface /
lonuserutils.pm
Revision
1.220:
download - view:
text,
annotated -
select for diffs
Thu Dec 7 04:47:00 2023 UTC (8 months, 1 week ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Prevent name information in classlist.db files being updated with empty
string(s) if file upload by DC i used make bulk change(s) to studentIDs
when csv file lacks column(s) containing name information for users.
1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
4: # $Id: lonuserutils.pm,v 1.220 2023/12/07 04:47:00 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ###############################################################
30:
31: package Apache::lonuserutils;
32:
33: =pod
34:
35: =head1 NAME
36:
37: Apache::lonuserutils.pm
38:
39: =head1 SYNOPSIS
40:
41: Utilities for management of users and custom roles
42:
43: Provides subroutines called by loncreateuser.pm
44:
45: =head1 OVERVIEW
46:
47: =cut
48:
49: use strict;
50: use Apache::lonnet;
51: use Apache::loncommon();
52: use Apache::lonhtmlcommon;
53: use Apache::loncoursequeueadmin;
54: use Apache::lonlocal;
55: use Apache::longroup;
56: use HTML::Entities;
57: use LONCAPA qw(:DEFAULT :match);
58:
59: ###############################################################
60: ###############################################################
61: # Drop student from all sections of a course, except optional $csec
62: sub modifystudent {
63: my ($udom,$unam,$courseid,$csec,$desiredhost,$context)=@_;
64: # if $csec is undefined, drop the student from all the courses matching
65: # this one. If $csec is defined, drop them from all other sections of
66: # this course and add them to section $csec
67: my ($cnum,$cdom) = &get_course_identity($courseid);
68: my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
69: my ($tmp) = keys(%roles);
70: # Bail out if we were unable to get the students roles
71: return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
72: # Go through the roles looking for enrollment in this course
73: my $result = '';
74: foreach my $course (keys(%roles)) {
75: if ($course=~m{^/\Q$cdom\E/\Q$cnum\E(?:\/)*(?:\s+)*(\w+)*\_st$}) {
76: # We are in this course
77: my $section=$1;
78: $section='' if ($course eq "/$cdom/$cnum".'_st');
79: if (defined($csec) && $section eq $csec) {
80: $result .= 'ok:';
81: } elsif ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
82: my (undef,$end,$start)=split(/\_/,$roles{$course});
83: my $now=time;
84: # if this is an active role
85: if (!($start && ($now<$start)) || !($end && ($now>$end))) {
86: my $reply=&Apache::lonnet::modifystudent
87: # dom name id mode pass f m l g
88: ($udom,$unam,'', '', '',undef,undef,undef,undef,
89: $section,time,undef,undef,$desiredhost,'','manual',
90: '',$courseid,'',$context);
91: $result .= $reply.':';
92: }
93: }
94: }
95: }
96: if ($result eq '') {
97: $result = &mt('Unable to find section for this student');
98: } else {
99: $result =~ s/(ok:)+/ok/g;
100: }
101: return $result;
102: }
103:
104: sub modifyuserrole {
105: my ($context,$setting,$changeauth,$cid,$udom,$uname,$uid,$umode,$upass,
106: $first,$middle,$last,$gene,$sec,$forceid,$desiredhome,$email,$role,
107: $end,$start,$checkid,$inststatus,$emptyok) = @_;
108: my ($scope,$userresult,$authresult,$roleresult,$idresult);
109: if ($setting eq 'course' || $context eq 'course') {
110: $scope = '/'.$cid;
111: $scope =~ s/\_/\//g;
112: if (($role ne 'cc') && ($role ne 'co') && ($sec ne '')) {
113: $scope .='/'.$sec;
114: }
115: } elsif ($context eq 'domain') {
116: $scope = '/'.$env{'request.role.domain'}.'/';
117: } elsif ($context eq 'author') {
118: if ($env{'request.role'} =~ m{^ca\.(/$match_domain/$match_username)$}) {
119: $scope = $1;
120: } else {
121: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
122: }
123: }
124: if ($context eq 'domain') {
125: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
126: if ($uhome ne 'no_host') {
127: if (($changeauth eq 'Yes') && (&Apache::lonnet::allowed('mau',$udom))) {
128: if ((($umode =~ /^krb4|krb5|internal$/) && $upass ne '') ||
129: ($umode eq 'localauth')) {
130: $authresult = &Apache::lonnet::modifyuserauth($udom,$uname,$umode,$upass);
131: }
132: }
133: if (($forceid) && (&Apache::lonnet::allowed('mau',$udom)) &&
134: ($env{'form.recurseid'}) && ($checkid)) {
135: my %userupdate = (
136: lastname => $last,
137: middlename => $middle,
138: firstname => $first,
139: generation => $gene,
140: id => $uid,
141: );
142:
143: # When "Update ID in user's course(s)" and "Force change of existing ID"
144: # checkboxes both checked, prevent replacement of name information
145: # in classlist.db file(s) for the user's course(s) with blank(s),
146: # in the case where the uploaded csv file was without column(s) for
147: # the particular field. Fields are: First Name, Middle Names/Initials,
148: # Last Name (or the composite: Last Name, First Names), and Generation.
149:
150: my %emptyallowed;
151: if ((ref($emptyok) eq 'HASH') && (keys(%{$emptyok}) > 0)) {
152: %emptyallowed = %{$emptyok};
153: }
154: foreach my $field (keys(%userupdate)) {
155: if ($userupdate{$field} eq '') {
156: unless ($emptyallowed{$field}) {
157: delete($userupdate{$field});
158: }
159: }
160: }
161: $idresult = &propagate_id_change($uname,$udom,\%userupdate);
162: }
163: }
164: }
165: $userresult =
166: &Apache::lonnet::modifyuser($udom,$uname,$uid,$umode,$upass,$first,
167: $middle,$last,$gene,$forceid,$desiredhome,
168: $email,$inststatus);
169: if ($userresult eq 'ok') {
170: if ($role ne '') {
171: $role =~ s/_/\//g;
172: $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
173: $role,$end,$start,'',
174: '',$context);
175: }
176: }
177: return ($userresult,$authresult,$roleresult,$idresult);
178: }
179:
180: sub role_approval {
181: my ($dom,$context,$process_by,$notifydc) = @_;
182: if (ref($process_by) eq 'HASH') {
183: my %domconfig = &Apache::lonnet::get_dom('configuration',['privacy'],$dom);
184: if (ref($domconfig{'privacy'}) eq 'HASH') {
185: if (ref($notifydc) eq 'ARRAY') {
186: if ($domconfig{'privacy'}{'notify'} ne '') {
187: @{$notifydc} = split(/,/,$domconfig{'privacy'}{'notify'});
188: }
189: }
190: if (ref($domconfig{'privacy'}{'approval'}) eq 'HASH') {
191: my %approvalconf = %{$domconfig{'privacy'}{'approval'}};
192: foreach my $key ('instdom','extdom') {
193: if (ref($approvalconf{$key}) eq 'HASH') {
194: if (keys(%{$approvalconf{$key}})) {
195: $process_by->{$key} = $approvalconf{$key}{$context};
196: }
197: }
198: }
199: }
200: }
201: }
202: return;
203: }
204:
205: sub get_instdoms {
206: my ($udom,$instdoms) = @_;
207: return unless (ref($instdoms) eq 'ARRAY');
208: my @intdoms;
209: my %iphost = &Apache::lonnet::get_iphost();
210: my $primary_id = &Apache::lonnet::domain($udom,'primary');
211: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
212: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
213: foreach my $id (@{$iphost{$primary_ip}}) {
214: my $intdom = &Apache::lonnet::internet_dom($id);
215: unless(grep(/^\Q$intdom\E$/,@intdoms)) {
216: push(@intdoms,$intdom);
217: }
218: }
219: }
220: foreach my $ip (keys(%iphost)) {
221: if (ref($iphost{$ip}) eq 'ARRAY') {
222: foreach my $id (@{$iphost{$ip}}) {
223: my $location = &Apache::lonnet::internet_dom($id);
224: if ($location) {
225: if (grep(/^\Q$location\E$/,@intdoms)) {
226: my $dom = &Apache::lonnet::host_domain($id);
227: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
228: push(@{$instdoms},$dom);
229: }
230: }
231: }
232: }
233: }
234: }
235: return;
236: }
237:
238: sub restricted_dom {
239: my ($context,$key,$udom,$uname,$role,$start,$end,$cdom,$cnum,$csec,$credits,
240: $process_by,$instdoms,$got_role_approvals,$got_instdoms,$reject,$pending,
241: $notifydc,$status,$unauthorized,$currqueued) = @_;
242: return if ($udom eq $cdom);
243: return unless ((ref($process_by) eq 'HASH') && (ref($instdoms) eq 'HASH') &&
244: (ref($got_role_approvals) eq 'HASH') && (ref($got_instdoms) eq 'HASH') &&
245: (ref($reject) eq 'HASH') && (ref($pending) eq 'HASH') &&
246: (ref($notifydc) eq 'HASH') && (ref($status) eq 'HASH') &&
247: (ref($unauthorized) eq 'HASH') && (ref($currqueued) eq 'HASH'));
248: my (%approval,@notify,$gotdata,$skip);
249: if (ref($got_role_approvals->{$context}) eq 'HASH') {
250: if ($got_role_approvals->{$context}{$udom}) {
251: $gotdata = 1;
252: if (ref($process_by->{$context}{$udom}) eq 'HASH') {
253: %approval = %{$process_by->{$context}{$udom}};
254: }
255: }
256: }
257: unless ($gotdata) {
258: &role_approval($udom,$context,\%approval,\@notify);
259: $process_by->{$context} = {
260: $udom => \%approval,
261: };
262: $got_role_approvals->{$context} = {
263: $udom => 1,
264: };
265: $notifydc->{$udom} = \@notify;
266: }
267: if (ref($process_by->{$context}) eq 'HASH') {
268: if (ref($process_by->{$context}{$udom}) eq 'HASH') {
269: my @inst;
270: if ($got_instdoms->{$udom}) {
271: if (ref($instdoms->{$udom}) eq 'ARRAY') {
272: @inst = @{$instdoms->{$udom}};
273: }
274: } else {
275: &get_instdoms(\@inst);
276: $instdoms->{$udom} = \@inst;
277: $got_instdoms->{$udom} = 1;
278: }
279: if (grep(/^\Q$cdom\E$/,@inst)) {
280: if (exists($approval{'instdom'})) {
281: my $rule = $approval{'instdom'};
282: if (($rule eq 'none') || ($rule eq 'user') || ($rule eq 'domain')) {
283: my ($id,$currstatus,$curradj) = &get_othdomreq_status($key,$uname,$udom,$role,$cdom,$cnum,$csec);
284: if (($currstatus ne '') && ($curradj eq $rule)) {
285: $status->{$key}->{$uname.':'.$udom} = $currstatus;
286: }
287: if ($rule eq 'none') {
288: $reject->{$key}->{$uname.':'.$udom} = {
289: cdom => $cdom,
290: cnum => $cnum,
291: csec => $csec,
292: udom => $udom,
293: uname => $uname,
294: role => $role,
295: };
296: $skip = 1;
297: } elsif (($rule eq 'user') || ($rule eq 'domain')) {
298: if ($curradj eq $rule) {
299: unless ($currstatus eq 'approved') {
300: if ($currstatus eq 'rejected') {
301: $unauthorized->{$key}->{$uname.':'.$udom} = {
302: cdom => $cdom,
303: cnum => $cnum,
304: csec => $csec,
305: udom => $udom,
306: uname => $uname,
307: role => $role,
308: };
309: } elsif ($currstatus eq 'pending') {
310: $currqueued->{$key}->{$uname.':'.$udom} = {
311: cdom => $cdom,
312: cnum => $cnum,
313: csec => $csec,
314: udom => $udom,
315: uname => $uname,
316: role => $role,
317: adj => $rule,
318: };
319: }
320: $skip = 1;
321: }
322: } else {
323: $pending->{$key}->{$uname.':'.$udom} = {
324: cdom => $cdom,
325: cnum => $cnum,
326: csec => $csec,
327: udom => $udom,
328: uname => $uname,
329: role => $role,
330: start => $start,
331: end => $end,
332: adj => $rule,
333: };
334: if (($role eq 'st') && ($credits ne '')) {
335: $pending->{$key}->{$uname.':'.$udom}->{'credits'} = $credits;
336: }
337: $skip = 1;
338: }
339: }
340: }
341: }
342: } elsif (exists($approval{'extdom'})) {
343: my $rule = $approval{'extdom'};
344: if (($rule eq 'none') || ($rule eq 'user') || ($rule eq 'domain')) {
345: my ($id,$currstatus,$curradj) = &get_othdomreq_status($key,$uname,$udom,$role,$cdom,$cnum,$csec);
346: if (($currstatus ne '') && ($curradj eq $rule)) {
347: $status->{$key}->{$uname.':'.$udom} = $currstatus;
348: }
349: if ($rule eq 'none') {
350: $reject->{$key}->{$uname.':'.$udom} = {
351: cdom => $cdom,
352: cnum => $cnum,
353: csec => $csec,
354: udom => $udom,
355: uname => $uname,
356: role => $role,
357: };
358: $skip = 1;
359: } elsif (($rule eq 'user') || ($rule eq 'domain')) {
360: if ($curradj eq $rule) {
361: unless ($currstatus eq 'approved') {
362: if ($currstatus eq 'rejected') {
363: $unauthorized->{$key}->{$uname.':'.$udom} = {
364: cdom => $cdom,
365: cnum => $cnum,
366: csec => $csec,
367: udom => $udom,
368: uname => $uname,
369: role => $role,
370: };
371: } elsif ($currstatus eq 'pending') {
372: $currqueued->{$key}->{$uname.':'.$udom} = {
373: cdom => $cdom,
374: cnum => $cnum,
375: csec => $csec,
376: udom => $udom,
377: uname => $uname,
378: role => $role,
379: adj => $rule,
380: };
381: }
382: $skip = 1;
383: }
384: } else {
385: $pending->{$key}->{$uname.':'.$udom} = {
386: cdom => $cdom,
387: cnum => $cnum,
388: csec => $csec,
389: udom => $udom,
390: uname => $uname,
391: role => $role,
392: start => $start,
393: end => $end,
394: adj => $rule,
395: };
396: if (($role eq 'st') && ($credits ne '')) {
397: $pending->{$key}->{$uname.':'.$udom}->{'credits'} = $credits;
398: }
399: $skip = 1;
400: }
401: }
402: }
403: }
404: }
405: }
406: return $skip;
407: }
408:
409: sub get_othdomreq_status {
410: my ($key,$uname,$udom,$role,$cdom,$cnum,$csec) = @_;
411: my $id = $uname.':'.$udom.':'.$role;
412: my ($dbnum,$currstatus,$curradj);
413: if (($role eq 'ca') || ($role eq 'aa')) {
414: $dbnum = $cnum;
415: } elsif ($key eq $cdom.'_'.$role) {
416: $dbnum = &Apache::lonnet::get_domainconfiguser($cdom);
417: } else {
418: $id .= ':'.$csec;
419: $dbnum = $cnum;
420: }
421: my $statusid = 'status&'.$id;
422: my %curr = &Apache::lonnet::get('nohist_othdomqueued',[$id,$statusid],$cdom,$dbnum);
423: if (ref($curr{$id}) eq 'HASH') {
424: $curradj = $curr{$id}{'adj'};
425: }
426: $currstatus = $curr{$statusid};
427: return ($id,$currstatus,$curradj);
428: }
429:
430: sub print_roles_rejected {
431: my ($context,$reject,$unauthorized) = @_;
432: return unless ((ref($reject) eq 'HASH') || (ref($unauthorized) eq 'HASH'));
433: my $output;
434: if (keys(%{$reject}) > 0) {
435: $output = '<p class="LC_warning">'.
436: &mt("The following roles could not be assigned because the user is from another domain, and that domain's policies disallow it").'<ul>';
437: foreach my $key (sort(keys(%{$reject}))) {
438: if (ref($reject->{$key}) eq 'HASH') {
439: foreach my $user (sort(keys(%{$reject->{$key}}))) {
440: if (ref($reject->{$key}->{$user}) eq 'HASH') {
441: my ($crstype,$role,$cdom,$cnum,$csec,$title,$plainrole);
442: $role = $reject->{$key}->{$user}{'role'};
443: $cdom = $reject->{$key}->{$user}{'cdom'};
444: $cnum = $reject->{$key}->{$user}{'cnum'};
445: $csec = $reject->{$key}->{$user}{'csec'};
446: if (($context eq 'domain') && ($cnum ne '')) {
447: if (($role eq 'ca') || ($role eq 'aa')) {
448: $title = &Apache::loncommon::plainname($cnum,$cdom);
449: } else {
450: if (&Apache::lonnet::is_course($cdom,$cnum)) {
451: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
452: $crstype = $coursedata{'type'};
453: $title = $coursedata{'description'};
454: }
455: }
456: } elsif ($context eq 'course') {
457: $crstype = &Apache::loncommon::course_type();
458: }
459: my $plainrole = &Apache::lonnet::plaintext($role,$crstype);
460: $output .= '<li>'.&mt('User: [_1]',$reject->{$key}->{$user}{'uname'}).' | '.
461: &mt('Domain: [_1]',$reject->{$key}->{$user}{'udom'}).' | '.
462: &mt('Role: [_1]',$plainrole);
463: if ($crstype) {
464: if ($csec ne'') {
465: $output .= ' | '.&mt('Section: [_1]',$csec);
466: }
467: } elsif (($context eq 'domain') && (($role eq 'ca') || ($role eq 'aa'))) {
468: $output .= ' | '.&mt('Authoring Space belonging to: [_1]',$title);
469:
470: }
471: if (($context eq 'domain') && ($crstype)) {
472: $output .= ' | '.&mt("$crstype: [_1]",$title);
473: }
474: $output .= '</li>';
475: }
476: }
477: }
478: }
479: $output .= '</ul></p>';
480: }
481: if (keys(%{$unauthorized}) > 0) {
482: $output = '<p class="LC_warning">'.
483: &mt("The following roles could not be assigned because the user is from another domain, and that domain's policies require approval by the user themselves or by a domain coordinator in that domain, and approval has been withheld.").'<ul>';
484: foreach my $key (sort(keys(%{$unauthorized}))) {
485: if (ref($unauthorized->{$key}) eq 'HASH') {
486: foreach my $user (sort(keys(%{$unauthorized->{$key}}))) {
487: if (ref($unauthorized->{$key}->{$user}) eq 'HASH') {
488: my ($crstype,$role,$cdom,$cnum,$csec,$title,$plainrole);
489: $role = $unauthorized->{$key}->{$user}{'role'};
490: $cdom = $unauthorized->{$key}->{$user}{'cdom'};
491: $cnum = $unauthorized->{$key}->{$user}{'cnum'};
492: $csec = $unauthorized->{$key}->{$user}{'csec'};
493: if (($context eq 'domain') && ($cnum ne '')) {
494: if (($role eq 'ca') || ($role eq 'aa')) {
495: $title = &mt('Authoring Space belonging to: [_1]',
496: &Apache::loncommon::plainname($cnum,$cdom));
497: } else {
498: if (&Apache::lonnet::is_course($cdom,$cnum)) {
499: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
500: $crstype = $coursedata{'type'};
501: $title = &mt("$crstype: [_1]",$coursedata{'description'});
502: }
503: }
504: } elsif ($context eq 'course') {
505: $crstype = &Apache::loncommon::course_type();
506: }
507: $plainrole = &Apache::lonnet::plaintext($role,$crstype);
508: $output .= '<li>'.&mt('User: [_1]',$unauthorized->{$key}->{$user}{'uname'}).' | '.
509: &mt('Domain: [_1]',$unauthorized->{$key}->{$user}{'udom'}).' | '.
510: &mt('Role: [_1]',$plainrole);
511: if ($crstype) {
512: if ($csec ne'') {
513: $output .= ' | '.&mt('Section: [_1]',$csec);
514: }
515: }
516: if ($title ne '') {
517: $output .= ' | '.$title;
518: }
519: $output .= '</li>';
520: }
521: }
522: }
523: }
524: $output .= '</ul></p>';
525: }
526: return $output;
527: }
528:
529: sub print_roles_queued {
530: my ($context,$pending,$notifydc,$currqueued) = @_;
531: return unless ((ref($pending) eq 'HASH') && (ref($notifydc) eq 'HASH') &&
532: (ref($currqueued) eq 'HASH'));
533: my $output;
534: if (keys(%{$pending}) > 0) {
535: my $now = time;
536: $output = '<p class="LC_warning">'.
537: &mt("The following role assignments have been queued because the user is from another domain, and that domain's policies require approval by the user themselves or by a domain coordinator in that domain").'<ul>';
538: my (%todom,%touser,%crsqueue,%caqueue,%domqueue);
539: my $requester = $env{'user.name'}.':'.$env{'user.domain'};
540: foreach my $key (sort(keys(%{$pending}))) {
541: if (ref($pending->{$key}) eq 'HASH') {
542: foreach my $user (sort(keys(%{$pending->{$key}}))) {
543: if (ref($pending->{$key}->{$user}) eq 'HASH') {
544: my $role = $pending->{$key}->{$user}{'role'};
545: my $uname = $pending->{$key}->{$user}{'uname'};
546: my $udom = $pending->{$key}->{$user}{'udom'};
547: my $csec = $pending->{$key}->{$user}{'csec'};
548: my $cdom = $pending->{$key}->{$user}{'cdom'};
549: my $cnum = $pending->{$key}->{$user}{'cnum'};
550: my $adj = $pending->{$key}->{$user}{'adj'};
551: my $start = $pending->{$key}->{$user}{'start'};
552: my $end = $pending->{$key}->{$user}{'end'};
553: my $credits = $pending->{$key}->{$user}{'credits'};
554: my $now = time;
555: my ($crstype,$title,$plainrole,$extent,$id,$status);
556: if ($context eq 'course') {
557: $crstype = &Apache::loncommon::course_type();
558: $title = $env{'course.'.$env{'request.course.id'}.'.description'};
559: } elsif ($context eq 'domain') {
560: if (&Apache::lonnet::is_course($cdom,$cnum)) {
561: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
562: $crstype = $coursedata{'type'};
563: $title = $coursedata{'description'};
564: } elsif (($role eq 'ca') || ($role eq 'aa')) {
565: $title = &Apache::loncommon::plainname($cnum,$cdom);
566: }
567: }
568: $plainrole = &Apache::lonnet::plaintext($role,$crstype);
569: $extent = "/$cdom/$cnum";
570: $id = $uname.':'.$udom.':'.$role;
571: if (($context eq 'course') || ($crstype)) {
572: $id .= ':'.$csec;
573: }
574: $output .= '<li>'.&mt('User: [_1]',$uname).' | '.
575: &mt('Domain: [_1]',$udom).' | '.
576: &mt('Role: [_1]',$plainrole);
577: if ($crstype) {
578: if ($csec ne'') {
579: $output .= ' | '.&mt('Section: [_1]',$csec);
580: }
581: } elsif (($context eq 'domain') && (($role eq 'ca') || ($role eq 'aa'))) {
582: $output .= ' | '.&mt('Authoring Space belonging to: [_1]',$title);
583: }
584: if (($context eq 'domain') && ($crstype)) {
585: $output .= ' | '.&mt("$crstype: [_1]",$title);
586: }
587: if (($crstype) && ($csec ne '')) {
588: $extent .= "/$csec";
589: }
590: if ($adj eq 'user') {
591: $output .= '<br />'.&mt('Message sent to user for approval');
592: $touser{$uname.':'.$udom}{'pending:'.$extent.':'.$role} = {
593: timestamp => $now,
594: requester => $requester,
595: start => $start,
596: end => $end,
597: credits => $credits,
598: context => $context,
599: };
600: } elsif ($adj eq 'domain') {
601: $output .= '<br />'.&mt("Message sent to user's domain coordinator for approval");
602: $todom{$udom}{'pending:'.$uname.':'.$extent.':'.$role} = {
603: timestamp => $now,
604: requester => $requester,
605: start => $start,
606: end => $end,
607: credits => $credits,
608: context => $context,
609: };
610: }
611: $output .= '</li>';
612: if (($context eq 'course') || ($crstype)) {
613: $crsqueue{$cdom.'_'.$cnum}{$id} = {
614: timestamp => $now,
615: requester => $requester,
616: adj => $adj,
617: };
618: $crsqueue{$cdom.'_'.$cnum}{'status&'.$id} = 'pending';
619: } elsif (($context eq 'author') ||
620: (($context eq 'domain') && (($role eq 'ca') || ($role eq 'aa')))) {
621: $caqueue{$cnum.':'.$cdom}{$id} = {
622: timestamp => $now,
623: requester => $requester,
624: adj => $adj,
625: };
626: $caqueue{$cnum.':'.$cdom}{'status&'.$id} = 'pending';
627: } elsif ($context eq 'domain') {
628: $domqueue{$id} = {
629: timestamp => $now,
630: requester => $requester,
631: adj => $adj,
632: };
633: $domqueue{'status&'.$id} = 'pending';
634: }
635: }
636: }
637: }
638: }
639: $output .= '</ul></p>';
640: if (keys(%touser)) {
641: foreach my $key (keys(%touser)) {
642: my ($uname,$udom) = split(/:/,$key);
643: if (&Apache::lonnet::put('nohist_queuedrolereqs',$touser{$key},$udom,$uname) eq 'ok') {
644: my $owndomdesc = &Apache::lonnet::domain($udom);
645: &Apache::loncoursequeueadmin::send_selfserve_notification($uname.':'.$udom,
646: '','',$owndomdesc,$now,'othdomroleuser',$requester);
647: }
648: }
649: }
650: if (keys(%todom)) {
651: foreach my $dom (keys(%todom)) {
652: if (ref($todom{$dom}) eq 'HASH') {
653: my $confname = &Apache::lonnet::get_domainconfiguser($dom);
654: if (&Apache::lonnet::put('nohist_queuedrolereqs',$todom{$dom},$dom,$confname) eq 'ok') {
655: if (ref($notifydc->{$dom}) eq 'ARRAY') {
656: if (@{$notifydc->{$dom}} > 0) {
657: my $notifylist = join(',',@{$notifydc->{$dom}});
658: &Apache::loncoursequeueadmin::send_selfserve_notification($notifylist,
659: '','','',$now,'othdomroledc',$requester);
660: }
661: }
662: }
663: }
664: }
665: }
666: if (keys(%crsqueue)) {
667: foreach my $key (keys(%crsqueue)) {
668: my ($cdom,$cnum) = split(/_/,$key);
669: if (ref($crsqueue{$key}) eq 'HASH') {
670: &Apache::lonnet::put('nohist_othdomqueued',$crsqueue{$key},$cdom,$cnum);
671: }
672: }
673: }
674: if (keys(%caqueue)) {
675: foreach my $key (keys(%caqueue)) {
676: my ($auname,$audom) = split(/:/,$key);
677: if (ref($caqueue{$key}) eq 'HASH') {
678: &Apache::lonnet::put('nohist_othdomqueued',$caqueue{$key},$audom,$auname);
679: }
680: }
681: }
682: if (keys(%domqueue)) {
683: my $confname = &Apache::lonnet::get_domainconfiguser($env{'request.role.domain'});
684: &Apache::lonnet::put('nohist_othdomqueued',\%domqueue,$env{'request.role.domain'},$confname);
685: }
686: }
687: if (keys(%{$currqueued}) > 0) {
688: $output = '<p class="LC_warning">'.
689: &mt("The following role assignments were already queued because the user is from another domain, and that domain's policies require approval by the user themselves or by a domain coordinator in that domain").'<ul>';
690: my $requester = $env{'user.name'}.':'.$env{'user.domain'};
691: foreach my $key (sort(keys(%{$currqueued}))) {
692: if (ref($currqueued->{$key}) eq 'HASH') {
693: foreach my $user (sort(keys(%{$currqueued->{$key}}))) {
694: if (ref($currqueued->{$key}->{$user}) eq 'HASH') {
695: my $role = $currqueued->{$key}->{$user}{'role'};
696: my $csec = $currqueued->{$key}->{$user}{'csec'};
697: my $cdom = $currqueued->{$key}->{$user}{'cdom'};
698: my $cnum = $currqueued->{$key}->{$user}{'cnum'};
699: my ($crstype,$title,$plainrole);
700: if ($context eq 'course') {
701: $crstype = &Apache::loncommon::course_type();
702: } elsif (($context eq 'domain') && ($cnum ne '')) {
703: if (($role eq 'ca') || ($role eq 'aa')) {
704: $title = &mt('Authoring Space belonging to: [_1]',
705: &Apache::loncommon::plainname($cnum,$cdom));
706: } elsif (&Apache::lonnet::is_course($cdom,$cnum)) {
707: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
708: $crstype = $coursedata{'type'};
709: $title = &mt("$crstype: [_1]",$coursedata{'description'});
710: }
711: }
712: $plainrole = &Apache::lonnet::plaintext($role,$crstype);
713: $output .= '<li>'.&mt('User: [_1]',$currqueued->{$key}->{$user}{'uname'}).' | '.
714: &mt('Domain: [_1]',$currqueued->{$key}->{$user}{'udom'}).' | '.
715: &mt('Role: [_1]',$plainrole);
716: if ($title ne '') {
717: $output .= ' | '.$title;
718: }
719: if ($crstype) {
720: if ($csec ne '') {
721: $output .= ' | '.&mt('Section: [_1]',$csec);
722: }
723: }
724: $output .= '</li>';
725: }
726: }
727: }
728: }
729: $output .= '</ul></p>';
730: }
731: return $output;
732: }
733:
734: sub propagate_id_change {
735: my ($uname,$udom,$user) = @_;
736: my (@types,@roles);
737: @types = ('active','future');
738: @roles = ('st');
739: my $idresult;
740: my %roleshash = &Apache::lonnet::get_my_roles($uname,
741: $udom,'userroles',\@types,\@roles);
742: my %args = (
743: one_time => 1,
744: );
745: foreach my $item (keys(%roleshash)) {
746: my ($cnum,$cdom,$role) = split(/:/,$item,-1);
747: my ($start,$end) = split(/:/,$roleshash{$item});
748: if (&Apache::lonnet::is_course($cdom,$cnum)) {
749: my $result = &update_classlist($cdom,$cnum,$udom,$uname,$user);
750: my %coursehash =
751: &Apache::lonnet::coursedescription($cdom.'_'.$cnum,\%args);
752: my $cdesc = $coursehash{'description'};
753: if ($cdesc eq '') {
754: $cdesc = $cdom.'_'.$cnum;
755: }
756: if ($result eq 'ok') {
757: $idresult .= &mt('Classlist update for "[_1]" in "[_2]".',$uname.':'.$udom,$cdesc).'<br />'."\n";
758: } else {
759: $idresult .= &mt('Error: "[_1]" during classlist update for "[_2]" in "[_3]".',$result,$uname.':'.$udom,$cdesc).'<br />'."\n";
760: }
761: }
762: }
763: return $idresult;
764: }
765:
766: sub update_classlist {
767: my ($cdom,$cnum,$udom,$uname,$user,$newend) = @_;
768: my ($uid,$classlistentry);
769: my $fullname =
770: &Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
771: $user->{'lastname'},$user->{'generation'},
772: 'lastname');
773: my %classhash = &Apache::lonnet::get('classlist',[$uname.':'.$udom],
774: $cdom,$cnum);
775: my @classinfo = split(/:/,$classhash{$uname.':'.$udom});
776: my $ididx=&Apache::loncoursedata::CL_ID() - 2;
777: my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2;
778: my $endidx = &Apache::loncoursedata::CL_END() - 2;
779: my $startidx = &Apache::loncoursedata::CL_START() - 2;
780: for (my $i=0; $i<@classinfo; $i++) {
781: if ($i == $endidx) {
782: if ($newend ne '') {
783: $classlistentry .= $newend.':';
784: } else {
785: $classlistentry .= $classinfo[$i].':';
786: }
787: } elsif ($i == $startidx) {
788: if ($newend ne '') {
789: if ($classinfo[$i] > $newend) {
790: $classlistentry .= $newend.':';
791: } else {
792: $classlistentry .= $classinfo[$i].':';
793: }
794: } else {
795: $classlistentry .= $classinfo[$i].':';
796: }
797: } elsif ($i == $ididx) {
798: if (defined($user->{'id'})) {
799: $classlistentry .= $user->{'id'}.':';
800: } else {
801: $classlistentry .= $classinfo[$i].':';
802: }
803: } elsif ($i == $nameidx) {
804: if (defined($user->{'lastname'})) {
805: $classlistentry .= $fullname.':';
806: } else {
807: $classlistentry .= $classinfo[$i].':';
808: }
809: } else {
810: $classlistentry .= $classinfo[$i].':';
811: }
812: }
813: $classlistentry =~ s/:$//;
814: my $reply=&Apache::lonnet::cput('classlist',
815: {"$uname:$udom" => $classlistentry},
816: $cdom,$cnum);
817: if (($reply eq 'ok') || ($reply eq 'delayed')) {
818: return 'ok';
819: } else {
820: return 'error: '.$reply;
821: }
822: }
823:
824:
825: ###############################################################
826: ###############################################################
827: # build a role type and role selection form
828: sub domain_roles_select {
829: # Set up the role type and role selection boxes when in
830: # domain context
831: #
832: # Role types
833: my @roletypes = ('domain','author','course','community');
834: my %lt = &role_type_names();
835: my $onchangefirst = "updateCols('showrole')";
836: my $onchangesecond = "updateCols('showrole')";
837: #
838: # build up the menu information to be passed to
839: # &Apache::loncommon::linked_select_forms
840: my %select_menus;
841: if ($env{'form.roletype'} eq '') {
842: $env{'form.roletype'} = 'domain';
843: }
844: foreach my $roletype (@roletypes) {
845: # set up the text for this domain
846: $select_menus{$roletype}->{'text'}= $lt{$roletype};
847: my $crstype;
848: if ($roletype eq 'community') {
849: $crstype = 'Community';
850: }
851: # we want a choice of 'default' as the default in the second menu
852: if ($env{'form.roletype'} ne '') {
853: $select_menus{$roletype}->{'default'} = $env{'form.showrole'};
854: } else {
855: $select_menus{$roletype}->{'default'} = 'Any';
856: }
857: # Now build up the other items in the second menu
858: my @roles;
859: if ($roletype eq 'domain') {
860: @roles = &domain_roles();
861: } elsif ($roletype eq 'author') {
862: @roles = &construction_space_roles();
863: } else {
864: my $custom = 1;
865: @roles = &course_roles('domain',undef,$custom,$roletype);
866: }
867: my $order = ['Any',@roles];
868: $select_menus{$roletype}->{'order'} = $order;
869: foreach my $role (@roles) {
870: if ($role eq 'cr') {
871: $select_menus{$roletype}->{'select2'}->{$role} =
872: &mt('Custom role');
873: } else {
874: $select_menus{$roletype}->{'select2'}->{$role} =
875: &Apache::lonnet::plaintext($role,$crstype);
876: }
877: }
878: $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
879: }
880: my $result = &Apache::loncommon::linked_select_forms
881: ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
882: 'roletype','showrole',\%select_menus,
883: ['domain','author','course','community'],$onchangefirst,
884: $onchangesecond);
885: return $result;
886: }
887:
888: ###############################################################
889: ###############################################################
890: sub hidden_input {
891: my ($name,$value) = @_;
892: return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n";
893: }
894:
895: sub print_upload_manager_header {
896: my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype,
897: $can_assign)=@_;
898: my $javascript;
899: #
900: if (! exists($env{'form.upfile_associate'})) {
901: $env{'form.upfile_associate'} = 'forward';
902: }
903: if ($env{'form.associate'} eq 'Reverse Association') {
904: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
905: $env{'form.upfile_associate'} = 'reverse';
906: } else {
907: $env{'form.upfile_associate'} = 'forward';
908: }
909: }
910: if ($env{'form.upfile_associate'} eq 'reverse') {
911: $javascript=&upload_manager_javascript_reverse_associate($can_assign);
912: } else {
913: $javascript=&upload_manager_javascript_forward_associate($can_assign);
914: }
915: #
916: # Deal with restored settings
917: my $password_choice = '';
918: if (exists($env{'form.ipwd_choice'}) &&
919: $env{'form.ipwd_choice'} ne '') {
920: # If a column was specified for password, assume it is for an
921: # internal password. This is a bug waiting to be filed (could be
922: # local or krb auth instead of internal) but I do not have the
923: # time to mess around with this now.
924: $password_choice = 'int';
925: }
926: #
927: my $groupslist;
928: if ($context eq 'course') {
929: $groupslist = &get_groupslist();
930: }
931: my $javascript_validations =
932: &javascript_validations('upload',$krbdefdom,$password_choice,undef,
933: $env{'request.role.domain'},$context,
934: $groupslist,$crstype);
935: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
936: $r->print(
937: '<h3>'.&mt('Identify fields in uploaded list')."</h3>\n".
938: '<p class="LC_info">'.
939: &mt('Total number of records found in file: [_1]'
940: ,'<b>'.$distotal.'</b>').
941: "</p>\n"
942: );
943: if ($distotal == 0) {
944: $r->print('<p class="LC_warning">'.&mt('None found').'</p>');
945: }
946: $r->print(
947: '<p>'.
948: &mt('Enter as many fields as you can.').'<br />'.
949: &mt('The system will inform you and bring you back to this page,[_1]if the data selected are insufficient to add users.','<br />').
950: "</p>\n"
951: );
952: $r->print(&hidden_input('action','upload').
953: &hidden_input('state','got_file').
954: &hidden_input('associate','').
955: &hidden_input('datatoken',$datatoken).
956: &hidden_input('fileupload',$env{'form.fileupload'}).
957: &hidden_input('upfiletype',$env{'form.upfiletype'}).
958: &hidden_input('upfile_associate',$env{'form.upfile_associate'}));
959: $r->print(
960: '<div class="LC_left_float">'.
961: '<fieldset><legend>'.&mt('Functions').'</legend>'.
962: '<label><input type="checkbox" name="noFirstLine"'.$checked.' />'.
963: &mt('Ignore First Line').'</label>'.
964: ' <input type="button" value="'.&mt('Reverse Association').'" '.
965: 'name="Reverse Association" '.
966: 'onclick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />'.
967: '</fieldset></div><br clear="all" />'
968: );
969: $r->print(
970: '<script type="text/javascript" language="Javascript">'."\n".
971: '// <![CDATA['."\n".
972: $javascript."\n".$javascript_validations."\n".
973: '// ]]>'."\n".
974: '</script>'
975: );
976: }
977:
978: ###############################################################
979: ###############################################################
980: sub javascript_validations {
981: my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain,
982: $context,$groupslist,$crstype)=@_;
983: my %param = (
984: kerb_def_dom => $krbdefdom,
985: curr_authtype => $curr_authtype,
986: );
987: if ($mode eq 'upload') {
988: $param{'formname'} = 'studentform';
989: } elsif ($mode eq 'createcourse') {
990: $param{'formname'} = 'ccrs';
991: } elsif ($mode eq 'modifycourse') {
992: $param{'formname'} = 'cmod';
993: $param{'mode'} = 'modifycourse',
994: $param{'curr_autharg'} = $curr_authfield;
995: }
996:
997: my $showcredits;
998: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
999: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
1000: $showcredits = 1;
1001: }
1002:
1003: my ($setsection_call,$setsections_js);
1004: my $finish = " vf.submit();\n";
1005: if ($mode eq 'upload') {
1006: if (($context eq 'course') || ($context eq 'domain')) {
1007: if ($context eq 'course') {
1008: if ($env{'request.course.sec'} eq '') {
1009: $setsection_call = 'setSections(document.'.$param{'formname'}.",'$crstype'".');';
1010: $setsections_js =
1011: &setsections_javascript($param{'formname'},$groupslist,
1012: $mode,'',$crstype,$showcredits);
1013: } else {
1014: $setsection_call = "'ok'";
1015: }
1016: } elsif ($context eq 'domain') {
1017: $setsection_call = 'setCourse()';
1018: $setsections_js = &dc_setcourse_js($param{'formname'},$mode,
1019: $context,$showcredits,$domain);
1020: }
1021: $finish = " var checkSec = $setsection_call\n".
1022: " if (checkSec == 'ok') {\n".
1023: " vf.submit();\n".
1024: " }\n";
1025: }
1026: }
1027: my $authheader = &Apache::loncommon::authform_header(%param);
1028:
1029: my %alert = &Apache::lonlocal::texthash
1030: (username => 'You need to specify the username field.',
1031: authen => 'You must choose an authentication type.',
1032: krb => 'You need to specify the Kerberos domain.',
1033: ipass => 'You need to specify the initial password.',
1034: name => 'The optional name field was not specified.',
1035: snum => 'The optional student/employee ID field was not specified.',
1036: section => 'The optional section field was not specified.',
1037: email => 'The optional e-mail address field was not specified.',
1038: role => 'The optional role field was not specified.',
1039: domain => 'The optional domain field was not specified.',
1040: continue => 'Continue adding users?',
1041: );
1042: if ($showcredits) {
1043: $alert{'credits'} = &mt('The optional credits field was not specified');
1044: }
1045: if (($mode eq 'upload') && ($context eq 'domain')) {
1046: $alert{'inststatus'} = &mt('The optional affiliation field was not specified');
1047: }
1048: &js_escape(\%alert);
1049: my $function_name = <<"END";
1050: $setsections_js
1051:
1052: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits) {
1053: END
1054: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($domain);
1055: my $auth_checks;
1056: if ($mode eq 'createcourse') {
1057: $auth_checks .= (<<END);
1058: if (vf.autoadds[0].checked == true) {
1059: if (current.radiovalue == null || current.radiovalue == 'nochange') {
1060: alert('$alert{'authen'}');
1061: return;
1062: }
1063: }
1064: END
1065: } else {
1066: $auth_checks .= (<<END);
1067: var foundatype=0;
1068: if (founduname==0) {
1069: alert('$alert{'username'}');
1070: return;
1071: }
1072:
1073: END
1074: if ($authnum > 1) {
1075: $auth_checks .= (<<END);
1076: if (current.radiovalue == null || current.radiovalue == '' || current.radiovalue == 'nochange') {
1077: // They did not check any of the login radiobuttons.
1078: alert('$alert{'authen'}');
1079: return;
1080: }
1081: END
1082: }
1083: }
1084: if ($mode eq 'createcourse') {
1085: $auth_checks .= "
1086: if ( (vf.autoadds[0].checked == true) &&
1087: (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') ) {
1088: ";
1089: } elsif ($mode eq 'modifycourse') {
1090: $auth_checks .= "
1091: if ((current.argfield !== null) && (current.argfield !== undefined) && (current.argfield !== '') && (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '')) {
1092: ";
1093: }
1094: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
1095: $auth_checks .= (<<END);
1096: var alertmsg = '';
1097: switch (current.radiovalue) {
1098: case 'krb':
1099: alertmsg = '$alert{'krb'}';
1100: break;
1101: default:
1102: alertmsg = '';
1103: }
1104: if (alertmsg != '') {
1105: alert(alertmsg);
1106: return;
1107: }
1108: }
1109: /* regexp here to check for non \d \. in credits */
1110: END
1111: } else {
1112: my ($numrules,$intargjs) =
1113: &Apache::loncommon::passwd_validation_js('vf.elements[current.argfield].value',$domain);
1114: $auth_checks .= (<<END);
1115: foundatype=1;
1116: if (current.argfield == null || current.argfield == '') {
1117: // The login radiobutton checked does not have an associated textbox
1118: } else if (vf.elements[current.argfield].value == '') {
1119: var alertmsg = '';
1120: switch (current.radiovalue) {
1121: case 'krb':
1122: alertmsg = '$alert{'krb'}';
1123: break;
1124: case 'int':
1125: alertmsg = '$alert{'ipass'}';
1126: break;
1127: case 'fsys':
1128: alertmsg = '$alert{'ipass'}';
1129: break;
1130: case 'loc':
1131: alertmsg = '';
1132: break;
1133: case 'lti':
1134: default:
1135: alertmsg = '';
1136: }
1137: if (alertmsg != '') {
1138: alert(alertmsg);
1139: return;
1140: }
1141: } else if (current.radiovalue == 'int') {
1142: if ($numrules > 0) {
1143: $intargjs
1144: }
1145: }
1146: END
1147: }
1148: my $section_checks;
1149: my $optional_checks = '';
1150: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
1151: $optional_checks = (<<END);
1152: vf.submit();
1153: }
1154: END
1155: } else {
1156: $section_checks = §ion_check_js();
1157: $optional_checks = (<<END);
1158: var message='';
1159: if (foundname==0) {
1160: message='$alert{'name'}';
1161: }
1162: if (foundid==0) {
1163: if (message!='') {
1164: message+='\\n';
1165: }
1166: message+='$alert{'snum'}';
1167: }
1168: if (foundsec==0) {
1169: if (message!='') {
1170: message+='\\n';
1171: }
1172: message+='$alert{'section'}';
1173: }
1174: if (foundemail==0) {
1175: if (message!='') {
1176: message+='\\n';
1177: }
1178: message+='$alert{'email'}';
1179: }
1180: if (foundrole==0) {
1181: if (message!='') {
1182: message+='\\n';
1183: }
1184: message+='$alert{'role'}';
1185: }
1186: if (founddomain==0) {
1187: if (message!='') {
1188: message+='\\n';
1189: }
1190: message+='$alert{'domain'}';
1191: }
1192: END
1193: if ($showcredits) {
1194: $optional_checks .= <<END;
1195: if (foundcredits==0) {
1196: if (message!='') {
1197: message+='\\n';
1198: }
1199: message+='$alert{'credits'}';
1200: }
1201: END
1202: }
1203: if (($mode eq 'upload') && ($context eq 'domain')) {
1204: $optional_checks .= (<<END);
1205:
1206: if (foundinststatus==0) {
1207: if (message!='') {
1208: message+='\\n';
1209: }
1210: message+='$alert{'inststatus'}';
1211: }
1212: END
1213: }
1214: $optional_checks .= (<<END);
1215:
1216: if (message!='') {
1217: message+= '\\n$alert{'continue'}';
1218: if (confirm(message)) {
1219: vf.state.value='enrolling';
1220: $finish
1221: }
1222: } else {
1223: vf.state.value='enrolling';
1224: $finish
1225: }
1226: }
1227: END
1228: }
1229: my $result = $function_name.$auth_checks.$optional_checks."\n".
1230: $section_checks.$authheader;
1231: return $result;
1232: }
1233:
1234: ###############################################################
1235: ###############################################################
1236: sub upload_manager_javascript_forward_associate {
1237: my ($can_assign) = @_;
1238: my ($auth_update,$numbuttons,$argreset);
1239: if (ref($can_assign) eq 'HASH') {
1240: if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
1241: $argreset .= " vf.krbarg.value='';\n";
1242: $numbuttons ++ ;
1243: }
1244: if ($can_assign->{'int'}) {
1245: $argreset .= " vf.intarg.value='';\n";
1246: $numbuttons ++;
1247: }
1248: if ($can_assign->{'loc'}) {
1249: $argreset .= " vf.locarg.value='';\n";
1250: $numbuttons ++;
1251: }
1252: if (!$can_assign->{'int'}) {
1253: my $warning = &mt('You may not specify an initial password for each user, as this is only available when new users use LON-CAPA internal authentication.')."\n".
1254: &mt('Your current role does not have rights to create users with that authentication type.');
1255: &js_escape(\$warning);
1256: $auth_update = <<"END";
1257: // Currently the initial password field is only supported for internal auth
1258: // (see bug 6368).
1259: if (nw==9) {
1260: eval('vf.f'+tf+'.selectedIndex=0;')
1261: alert('$warning');
1262: }
1263: END
1264: } elsif ($numbuttons > 1) {
1265: $auth_update = <<"END";
1266: // If we set the password, make the password form below correspond to
1267: // the new value.
1268: if (nw==9) {
1269: changed_radio('int',document.studentform);
1270: set_auth_radio_buttons('int',document.studentform);
1271: $argreset
1272: }
1273:
1274: END
1275: }
1276: }
1277:
1278: return(<<ENDPICK);
1279: function verify(vf,sec_caller) {
1280: var founduname=0;
1281: var foundpwd=0;
1282: var foundname=0;
1283: var foundid=0;
1284: var foundsec=0;
1285: var foundemail=0;
1286: var foundrole=0;
1287: var founddomain=0;
1288: var foundinststatus=0;
1289: var foundcredits=0;
1290: var tw;
1291: for (i=0;i<=vf.nfields.value;i++) {
1292: tw=eval('vf.f'+i+'.selectedIndex');
1293: if (tw==1) { founduname=1; }
1294: if ((tw>=2) && (tw<=6)) { foundname=1; }
1295: if (tw==7) { foundid=1; }
1296: if (tw==8) { foundsec=1; }
1297: if (tw==9) { foundpwd=1; }
1298: if (tw==10) { foundemail=1; }
1299: if (tw==11) { foundrole=1; }
1300: if (tw==12) { founddomain=1; }
1301: if (tw==13) { foundinststatus=1; }
1302: if (tw==14) { foundcredits=1; }
1303: }
1304: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits);
1305: }
1306:
1307: //
1308: // vf = this.form
1309: // tf = column number
1310: //
1311: // values of nw
1312: //
1313: // 0 = none
1314: // 1 = username
1315: // 2 = names (lastname, firstnames)
1316: // 3 = fname (firstname)
1317: // 4 = mname (middlename)
1318: // 5 = lname (lastname)
1319: // 6 = gen (generation)
1320: // 7 = id
1321: // 8 = section
1322: // 9 = ipwd (password)
1323: // 10 = email address
1324: // 11 = role
1325: // 12 = domain
1326: // 13 = inststatus
1327: // 14 = foundcredits
1328:
1329: function flip(vf,tf) {
1330: var nw=eval('vf.f'+tf+'.selectedIndex');
1331: var i;
1332: // make sure no other columns are labeled the same as this one
1333: for (i=0;i<=vf.nfields.value;i++) {
1334: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
1335: eval('vf.f'+i+'.selectedIndex=0;')
1336: }
1337: }
1338: // If we set this to 'lastname, firstnames', clear out all the ones
1339: // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
1340: if (nw==2) {
1341: for (i=0;i<=vf.nfields.value;i++) {
1342: if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
1343: (eval('vf.f'+i+'.selectedIndex')<=6)) {
1344: eval('vf.f'+i+'.selectedIndex=0;')
1345: }
1346: }
1347: }
1348: // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
1349: // clear out any that are set to 'lastname, firstnames' (2)
1350: if ((nw>=3) && (nw<=6)) {
1351: for (i=0;i<=vf.nfields.value;i++) {
1352: if (eval('vf.f'+i+'.selectedIndex')==2) {
1353: eval('vf.f'+i+'.selectedIndex=0;')
1354: }
1355: }
1356: }
1357: $auth_update
1358: }
1359:
1360: function clearpwd(vf) {
1361: var i;
1362: for (i=0;i<=vf.nfields.value;i++) {
1363: if (eval('vf.f'+i+'.selectedIndex')==9) {
1364: eval('vf.f'+i+'.selectedIndex=0;')
1365: }
1366: }
1367: }
1368:
1369: ENDPICK
1370: }
1371:
1372: ###############################################################
1373: ###############################################################
1374: sub upload_manager_javascript_reverse_associate {
1375: my ($can_assign) = @_;
1376: my ($auth_update,$numbuttons,$argreset);
1377: if (ref($can_assign) eq 'HASH') {
1378: if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
1379: $argreset .= " vf.krbarg.value='';\n";
1380: $numbuttons ++ ;
1381: }
1382: if ($can_assign->{'int'}) {
1383: $argreset .= " vf.intarg.value='';\n";
1384: $numbuttons ++;
1385: }
1386: if ($can_assign->{'loc'}) {
1387: $argreset .= " vf.locarg.value='';\n";
1388: $numbuttons ++;
1389: }
1390: if (!$can_assign->{'int'}) {
1391: my $warning = &mt('You may not specify an initial password, as this is only available when new users use LON-CAPA internal authentication.\n').
1392: &mt('Your current role does not have rights to create users with that authentication type.');
1393: &js_escape(\$warning);
1394: $auth_update = <<"END";
1395: // Currently the initial password field is only supported for internal auth
1396: // (see bug 6368).
1397: if (tf==8 && nw!=0) {
1398: eval('vf.f'+tf+'.selectedIndex=0;')
1399: alert('$warning');
1400: }
1401: END
1402: } elsif ($numbuttons > 1) {
1403: $auth_update = <<"END";
1404: // initial password specified, pick internal authentication
1405: if (tf==8 && nw!=0) {
1406: changed_radio('int',document.studentform);
1407: set_auth_radio_buttons('int',document.studentform);
1408: $argreset
1409: }
1410:
1411: END
1412: }
1413: }
1414:
1415: return(<<ENDPICK);
1416: function verify(vf,sec_caller) {
1417: var founduname=0;
1418: var foundpwd=0;
1419: var foundname=0;
1420: var foundid=0;
1421: var foundsec=0;
1422: var foundemail=0;
1423: var foundrole=0;
1424: var founddomain=0;
1425: var foundinststatus=0;
1426: var foundcredits=0;
1427: var tw;
1428: for (i=0;i<=vf.nfields.value;i++) {
1429: tw=eval('vf.f'+i+'.selectedIndex');
1430: if (i==0 && tw!=0) { founduname=1; }
1431: if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
1432: if (i==6 && tw!=0) { foundid=1; }
1433: if (i==7 && tw!=0) { foundsec=1; }
1434: if (i==8 && tw!=0) { foundpwd=1; }
1435: if (i==9 && tw!=0) { foundemail=1; }
1436: if (i==10 && tw!=0) { foundrole=1; }
1437: if (i==11 && tw!=0) { founddomain=1; }
1438: if (i==12 && tw!=0) { foundinstatus=1; }
1439: if (i==13 && tw!=0) { foundcredits=1; }
1440: }
1441: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits);
1442: }
1443:
1444: function flip(vf,tf) {
1445: var nw=eval('vf.f'+tf+'.selectedIndex');
1446: var i;
1447: // picked the all one name field, reset the other name ones to blank
1448: if (tf==1 && nw!=0) {
1449: for (i=2;i<=5;i++) {
1450: eval('vf.f'+i+'.selectedIndex=0;')
1451: }
1452: }
1453: //picked one of the piecewise name fields, reset the all in
1454: //one field to blank
1455: if ((tf>=2) && (tf<=5) && (nw!=0)) {
1456: eval('vf.f1.selectedIndex=0;')
1457: }
1458: $auth_update
1459: }
1460:
1461: function clearpwd(vf) {
1462: var i;
1463: if (eval('vf.f8.selectedIndex')!=0) {
1464: eval('vf.f8.selectedIndex=0;')
1465: }
1466: }
1467: ENDPICK
1468: }
1469:
1470: ###############################################################
1471: ###############################################################
1472: sub print_upload_manager_footer {
1473: my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context,$permission,$crstype,
1474: $showcredits) = @_;
1475: my $form = 'document.studentform';
1476: my $formname = 'studentform';
1477: my ($krbdef,$krbdefdom) =
1478: &Apache::loncommon::get_kerberos_defaults($defdom);
1479: my %param = ( formname => $form,
1480: kerb_def_dom => $krbdefdom,
1481: kerb_def_auth => $krbdef
1482: );
1483: if (exists($env{'form.ipwd_choice'}) &&
1484: defined($env{'form.ipwd_choice'}) &&
1485: $env{'form.ipwd_choice'} ne '') {
1486: $param{'curr_authtype'} = 'int';
1487: }
1488: my $krbform = &Apache::loncommon::authform_kerberos(%param);
1489: my $intform = &Apache::loncommon::authform_internal(%param);
1490: my $locform = &Apache::loncommon::authform_local(%param);
1491: my $ltiform = &Apache::loncommon::authform_lti(%param);
1492: my $date_table = &date_setting_table(undef,undef,$context,undef,
1493: $formname,$permission,$crstype);
1494:
1495: my $Str = "\n".'<div class="LC_left_float">';
1496: $Str .= &hidden_input('nfields',$i);
1497: $Str .= &hidden_input('keyfields',$keyfields);
1498:
1499: $Str .= '<h3>'.&mt('Options').'</h3>'
1500: .&Apache::lonhtmlcommon::start_pick_box();
1501:
1502: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Login Type'));
1503: if ($context eq 'domain') {
1504: $Str .= '<p>'
1505: .&mt('Change authentication for existing users in domain "[_1]" to these settings?'
1506: ,$defdom)
1507: .' <span class="LC_nobreak"><label>'
1508: .'<input type="radio" name="changeauth" value="No" checked="checked" />'
1509: .&mt('No').'</label>'
1510: .' <label>'
1511: .'<input type="radio" name="changeauth" value="Yes" />'
1512: .&mt('Yes').'</label>'
1513: .'</span></p>';
1514: } else {
1515: $Str .= '<p class="LC_info">'."\n".
1516: &mt('This will not take effect if the user already exists.').
1517: &Apache::loncommon::help_open_topic('Auth_Options').
1518: "</p>\n";
1519: }
1520: $Str .= &set_login($defdom,$krbform,$intform,$locform,$ltiform);
1521:
1522: my ($home_server_pick,$numlib) =
1523: &Apache::loncommon::home_server_form_item($defdom,'lcserver',
1524: 'default','hide');
1525: if ($numlib > 1) {
1526: $Str .= &Apache::lonhtmlcommon::row_closure()
1527: .&Apache::lonhtmlcommon::row_title(
1528: &mt('LON-CAPA Home Server for New Users'))
1529: .&mt('LON-CAPA domain: [_1] with home server:','"'.$defdom.'"')
1530: .$home_server_pick
1531: .&Apache::lonhtmlcommon::row_closure();
1532: } else {
1533: $Str .= $home_server_pick.
1534: &Apache::lonhtmlcommon::row_closure();
1535: }
1536:
1537: my ($trusted,$untrusted);
1538: if ($context eq 'course') {
1539: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1540: } elsif ($context eq 'author') {
1541: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1542: }
1543: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain'))
1544: .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1,undef,$trusted,$untrusted)
1545: .&Apache::lonhtmlcommon::row_closure();
1546:
1547: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Starting and Ending Dates'))
1548: ."<p>\n".$date_table."</p>\n"
1549: .&Apache::lonhtmlcommon::row_closure();
1550:
1551: if ($context eq 'domain') {
1552: $Str .= &Apache::lonhtmlcommon::row_title(
1553: &mt('Settings for assigning roles'))
1554: .&mt('Pick the action to take on roles for these users:').'<br />'
1555: .'<span class="LC_nobreak"><label>'
1556: .'<input type="radio" name="roleaction" value="norole" checked="checked" />'
1557: .' '.&mt('No role changes').'</label>'
1558: .' <label>'
1559: .'<input type="radio" name="roleaction" value="domain" />'
1560: .' '.&mt('Add a domain role').'</label>'
1561: .' <label>'
1562: .'<input type="radio" name="roleaction" value="course" />'
1563: .' '.&mt('Add a course/community role').'</label>'
1564: .'</span>';
1565: } elsif ($context eq 'author') {
1566: $Str .= &Apache::lonhtmlcommon::row_title(
1567: &mt('Default role'))
1568: .&mt('Choose the role to assign to users without a value specified in the uploaded file.')
1569: } elsif ($context eq 'course') {
1570: if ($showcredits) {
1571: $Str .= &Apache::lonhtmlcommon::row_title(
1572: &mt('Default role, section and credits'))
1573: .&mt('Choose the role and/or section(s) and/or credits to assign to users without values specified in the uploaded file.');
1574: } else {
1575: $Str .= &Apache::lonhtmlcommon::row_title(
1576: &mt('Default role and section'))
1577: .&mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file.');
1578: }
1579: } else {
1580: $Str .= &Apache::lonhtmlcommon::row_title(
1581: &mt('Default role and/or section(s)'))
1582: .&mt('Role and/or section(s) for users without values specified in the uploaded file.');
1583: }
1584: if (($context eq 'domain') || ($context eq 'author')) {
1585: $Str .= '<br />';
1586: my ($options,$cb_script,$coursepick) =
1587: &default_role_selector($context,1,'',$showcredits);
1588: if ($context eq 'domain') {
1589: $Str .= '<p>'
1590: .'<b>'.&mt('Domain Level').'</b><br />'
1591: .$options
1592: .'</p><p>'
1593: .'<b>'.&mt('Course Level').'</b>'
1594: .'</p>'
1595: .$cb_script.$coursepick
1596: .&Apache::lonhtmlcommon::row_closure();
1597: } elsif ($context eq 'author') {
1598: $Str .= $options
1599: .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
1600: }
1601: } else {
1602: my ($cnum,$cdom) = &get_course_identity();
1603: my $rowtitle = &mt('section');
1604: my $defaultcredits;
1605: if ($showcredits) {
1606: $defaultcredits = &get_defaultcredits();
1607: }
1608: my $secbox = §ion_picker($cdom,$cnum,'Any',$rowtitle,$permission,
1609: $context,'upload',$crstype,$showcredits,
1610: $defaultcredits);
1611: $Str .= $secbox
1612: .&Apache::lonhtmlcommon::row_closure();
1613: my %lt;
1614: if ($crstype eq 'Community') {
1615: %lt = &Apache::lonlocal::texthash (
1616: disp => 'Display members with current/future access who are not in the uploaded file',
1617: stus => 'Members selected from this list can be dropped.'
1618: );
1619: } else {
1620: %lt = &Apache::lonlocal::texthash (
1621: disp => 'Display students with current/future access who are not in the uploaded file',
1622: stus => 'Students selected from this list can be dropped.'
1623: );
1624: }
1625: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Full Update'))
1626: .'<label><input type="checkbox" name="fullup" value="yes" />'
1627: .' '.$lt{'disp'}
1628: .'</label><br />'
1629: .$lt{'stus'}
1630: .&Apache::lonhtmlcommon::row_closure();
1631: }
1632: if ($context eq 'course' || $context eq 'domain') {
1633: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID'))
1634: .&forceid_change($context)
1635: .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
1636: }
1637:
1638: $Str .= &Apache::lonhtmlcommon::end_pick_box();
1639: $Str .= '</div>';
1640:
1641: # Footer
1642: $Str .= '<div class="LC_clear_float_footer">'
1643: .'<hr />';
1644: if ($context eq 'course') {
1645: $Str .= '<p class="LC_info">'
1646: .&mt('Note: This operation may be time consuming when adding several users.')
1647: .'</p>';
1648: }
1649: $Str .= '<p><input type="button"'
1650: .' onclick="javascript:verify(this.form,this.form.csec)"'
1651: .' value="'.&mt('Update Users').'" />'
1652: .'</p>'."\n"
1653: .'</div>';
1654: $r->print($Str);
1655: return;
1656: }
1657:
1658: sub get_defaultcredits {
1659: my ($cdom,$cnum) = @_;
1660:
1661: if ($cdom eq '' || $cnum eq '') {
1662: return unless ($env{'request.course.id'});
1663: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1664: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1665: }
1666: return unless(($cdom =~ /^$match_domain$/) && ($cnum =~ /^$match_courseid$/));
1667: my ($defaultcredits,$domdefcredits);
1668: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
1669: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
1670: my $instcode = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
1671: if ($instcode) {
1672: $domdefcredits = $domdefaults{'officialcredits'};
1673: } elsif ($env{'course.'.$cdom.'_'.$cnum.'.internal.textbook'}) {
1674: $domdefcredits = $domdefaults{'textbookcredits'};
1675: } else {
1676: $domdefcredits = $domdefaults{'unofficialcredits'};
1677: }
1678: } else {
1679: return;
1680: }
1681:
1682: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
1683: $defaultcredits = $env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'};
1684: } elsif (exists($env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'})) {
1685: $defaultcredits = $env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'};
1686: } else {
1687: my %crsinfo =
1688: &Apache::lonnet::coursedescription("$cdom/$cnum",{'one_time' => 1});
1689: $defaultcredits = $crsinfo{'internal.defaultcredits'};
1690: }
1691: if ($defaultcredits eq '') {
1692: $defaultcredits = $domdefcredits;
1693: }
1694: return $defaultcredits;
1695: }
1696:
1697: sub forceid_change {
1698: my ($context) = @_;
1699: my $output =
1700: '<label><input type="checkbox" name="forceid" value="yes" />'
1701: .&mt('Force change of existing ID')
1702: .'</label>'.&Apache::loncommon::help_open_topic('ForceIDChange')."\n";
1703: if ($context eq 'domain') {
1704: $output .=
1705: '<br />'
1706: .'<label><input type="checkbox" name="recurseid" value="yes" />'
1707: .&mt("Update ID in user's course(s).").'</label>'."\n";
1708: }
1709: return $output;
1710: }
1711:
1712: ###############################################################
1713: ###############################################################
1714: sub print_upload_manager_form {
1715: my ($r,$context,$permission,$crstype,$showcredits) = @_;
1716: my $firstLine;
1717: my $datatoken;
1718: if (!$env{'form.datatoken'}) {
1719: $datatoken=&Apache::loncommon::upfile_store($r);
1720: } else {
1721: $datatoken=&Apache::loncommon::valid_datatoken($env{'form.datatoken'});
1722: if ($datatoken ne '') {
1723: &Apache::loncommon::load_tmp_file($r,$datatoken);
1724: }
1725: }
1726: if ($datatoken eq '') {
1727: $r->print('<p class="LC_error">'.&mt('Error').': '.
1728: &mt('Invalid datatoken').'</p>');
1729: return 'missingdata';
1730: }
1731: my @records=&Apache::loncommon::upfile_record_sep();
1732: if($env{'form.noFirstLine'}){
1733: $firstLine=shift(@records);
1734: }
1735: my $total=$#records;
1736: my $distotal=$total+1;
1737: my $today=time;
1738: my $halfyear=$today+15552000;
1739: #
1740: # Restore memorized settings
1741: my $col_setting_names = { 'username_choice' => 'scalar', # column settings
1742: 'names_choice' => 'scalar',
1743: 'fname_choice' => 'scalar',
1744: 'mname_choice' => 'scalar',
1745: 'lname_choice' => 'scalar',
1746: 'gen_choice' => 'scalar',
1747: 'id_choice' => 'scalar',
1748: 'sec_choice' => 'scalar',
1749: 'ipwd_choice' => 'scalar',
1750: 'email_choice' => 'scalar',
1751: 'role_choice' => 'scalar',
1752: 'domain_choice' => 'scalar',
1753: 'inststatus_choice' => 'scalar',
1754: };
1755: if ($showcredits) {
1756: $col_setting_names->{'credits_choice'} = 'scalar';
1757: }
1758: if ($context eq 'course') {
1759: &Apache::loncommon::restore_course_settings('enrollment_upload',
1760: $col_setting_names);
1761: } else {
1762: &Apache::loncommon::restore_settings($context,'user_upload',
1763: $col_setting_names);
1764: }
1765: my $defdom = $env{'request.role.domain'};
1766: #
1767: # Determine kerberos parameters as appropriate
1768: my ($krbdef,$krbdefdom) =
1769: &Apache::loncommon::get_kerberos_defaults($defdom);
1770: #
1771: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($defdom);
1772: &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
1773: $permission,$crstype,\%can_assign);
1774: my $i;
1775: my $keyfields;
1776: if ($total>=0) {
1777: my @field=
1778: (['username',&mt('Username'), $env{'form.username_choice'}],
1779: ['names',&mt('Last Name, First Names'),$env{'form.names_choice'}],
1780: ['fname',&mt('First Name'), $env{'form.fname_choice'}],
1781: ['mname',&mt('Middle Names/Initials'),$env{'form.mname_choice'}],
1782: ['lname',&mt('Last Name'), $env{'form.lname_choice'}],
1783: ['gen', &mt('Generation'), $env{'form.gen_choice'}],
1784: ['id', &mt('Student/Employee ID'),$env{'form.id_choice'}],
1785: ['sec', &mt('Section'), $env{'form.sec_choice'}],
1786: ['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
1787: ['email',&mt('E-mail Address'), $env{'form.email_choice'}],
1788: ['role',&mt('Role'), $env{'form.role_choice'}],
1789: ['domain',&mt('Domain'), $env{'form.domain_choice'}],
1790: ['inststatus',&mt('Affiliation'), $env{'form.inststatus_choice'}]);
1791: if ($showcredits) {
1792: push(@field,
1793: ['credits',&mt('Student Credits'), $env{'form.credits_choice'}]);
1794: }
1795: if ($env{'form.upfile_associate'} eq 'reverse') {
1796: &Apache::loncommon::csv_print_samples($r,\@records);
1797: $i=&Apache::loncommon::csv_print_select_table($r,\@records,
1798: \@field);
1799: foreach (@field) {
1800: $keyfields.=$_->[0].',';
1801: }
1802: chop($keyfields);
1803: } else {
1804: unshift(@field,['none','']);
1805: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
1806: \@field);
1807: my %sone=&Apache::loncommon::record_sep($records[0]);
1808: $keyfields=join(',',sort(keys(%sone)));
1809: }
1810: }
1811: &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
1812: $context,$permission,$crstype,$showcredits);
1813: return 'ok';
1814: }
1815:
1816: sub setup_date_selectors {
1817: my ($starttime,$endtime,$mode,$nolink,$formname) = @_;
1818: if ($formname eq '') {
1819: $formname = 'studentform';
1820: }
1821: if (! defined($starttime)) {
1822: $starttime = time;
1823: unless ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1824: if (exists($env{'course.'.$env{'request.course.id'}.
1825: '.default_enrollment_start_date'})) {
1826: $starttime = $env{'course.'.$env{'request.course.id'}.
1827: '.default_enrollment_start_date'};
1828: }
1829: }
1830: }
1831: if (! defined($endtime)) {
1832: $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1833: unless ($mode eq 'createcourse') {
1834: if (exists($env{'course.'.$env{'request.course.id'}.
1835: '.default_enrollment_end_date'})) {
1836: $endtime = $env{'course.'.$env{'request.course.id'}.
1837: '.default_enrollment_end_date'};
1838: }
1839: }
1840: }
1841:
1842: my $startdateform =
1843: &Apache::lonhtmlcommon::date_setter($formname,'startdate',$starttime,
1844: undef,undef,undef,undef,undef,undef,undef,$nolink);
1845:
1846: my $enddateform =
1847: &Apache::lonhtmlcommon::date_setter($formname,'enddate',$endtime,
1848: undef,undef,undef,undef,undef,undef,undef,$nolink);
1849:
1850: if ($mode eq 'create_enrolldates') {
1851: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1852: 'startenroll',
1853: $starttime);
1854: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1855: 'endenroll',
1856: $endtime);
1857: }
1858: if ($mode eq 'create_defaultdates') {
1859: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1860: 'startaccess',
1861: $starttime);
1862: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1863: 'endaccess',
1864: $endtime);
1865: }
1866: return ($startdateform,$enddateform);
1867: }
1868:
1869:
1870: sub get_dates_from_form {
1871: my ($startname,$endname) = @_;
1872: if ($startname eq '') {
1873: $startname = 'startdate';
1874: }
1875: if ($endname eq '') {
1876: $endname = 'enddate';
1877: }
1878: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
1879: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1880: if ($env{'form.no_end_date'}) {
1881: $enddate = 0;
1882: }
1883: return ($startdate,$enddate);
1884: }
1885:
1886: sub date_setting_table {
1887: my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission,$crstype) = @_;
1888: my $nolink;
1889: if ($bulkaction) {
1890: $nolink = 1;
1891: }
1892: my ($startform,$endform) =
1893: &setup_date_selectors($starttime,$endtime,$mode,$nolink,$formname);
1894: my $dateDefault;
1895: if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1896: $dateDefault = ' ';
1897: } elsif ($mode ne 'author' && $mode ne 'domain') {
1898: if (($bulkaction eq 'reenable') ||
1899: ($bulkaction eq 'activate') ||
1900: ($bulkaction eq 'chgdates') ||
1901: ($env{'form.action'} eq 'upload')) {
1902: if ($env{'request.course.sec'} eq '') {
1903: $dateDefault = '<span class="LC_nobreak">'.
1904: '<label><input type="checkbox" name="makedatesdefault" value="1" /> ';
1905: if ($crstype eq 'Community') {
1906: $dateDefault .= &mt("make these dates the default access dates for future community enrollment");
1907: } else {
1908: $dateDefault .= &mt("make these dates the default access dates for future course enrollment");
1909: }
1910: $dateDefault .= '</label></span>';
1911: }
1912: }
1913: }
1914: my $perpetual = '<span class="LC_nobreak"><label><input type="checkbox" name="no_end_date"';
1915: if (defined($endtime) && $endtime == 0) {
1916: $perpetual .= ' checked="checked"';
1917: }
1918: $perpetual.= ' /> '.&mt('no ending date').'</label></span>';
1919: if ($mode eq 'create_enrolldates') {
1920: $perpetual = ' ';
1921: }
1922: my $result = &Apache::lonhtmlcommon::start_pick_box()."\n";
1923: $result .= &Apache::lonhtmlcommon::row_title(&mt('Starting Date'),
1924: 'LC_oddrow_value')."\n".
1925: $startform."\n".
1926: &Apache::lonhtmlcommon::row_closure(1).
1927: &Apache::lonhtmlcommon::row_title(&mt('Ending Date'),
1928: 'LC_oddrow_value')."\n".
1929: $endform.' '.$perpetual.
1930: &Apache::lonhtmlcommon::row_closure(1).
1931: &Apache::lonhtmlcommon::end_pick_box();
1932: if ($dateDefault) {
1933: $result .= $dateDefault.'<br />'."\n";
1934: }
1935: return $result;
1936: }
1937:
1938: sub make_dates_default {
1939: my ($startdate,$enddate,$context,$crstype) = @_;
1940: my $result = '';
1941: if ($context eq 'course') {
1942: my ($cnum,$cdom) = &get_course_identity();
1943: my $put_result = &Apache::lonnet::put('environment',
1944: {'default_enrollment_start_date'=>$startdate,
1945: 'default_enrollment_end_date' =>$enddate},$cdom,$cnum);
1946: if ($put_result eq 'ok') {
1947: if ($crstype eq 'Community') {
1948: $result .= &mt('Set default start and end access dates for community.');
1949: } else {
1950: $result .= &mt('Set default start and end access dates for course.');
1951: }
1952: $result .= '<br />'."\n";
1953: #
1954: # Refresh the course environment
1955: &Apache::lonnet::coursedescription($env{'request.course.id'},
1956: {'freshen_cache' => 1});
1957: } else {
1958: if ($crstype eq 'Community') {
1959: $result .= &mt('Unable to set default access dates for community');
1960: } else {
1961: $result .= &mt('Unable to set default access dates for course');
1962: }
1963: $result .= ':'.$put_result.'<br />';
1964: }
1965: }
1966: return $result;
1967: }
1968:
1969: sub default_role_selector {
1970: my ($context,$checkpriv,$crstype,$showcredits) = @_;
1971: my %customroles;
1972: my ($options,$coursepick,$cb_jscript);
1973: if ($context ne 'author') {
1974: %customroles = &my_custom_roles($crstype);
1975: }
1976:
1977: my %lt=&Apache::lonlocal::texthash(
1978: 'rol' => "Role",
1979: 'grs' => "Section",
1980: 'exs' => "Existing sections",
1981: 'new' => "New section",
1982: 'crd' => "Credits",
1983: );
1984: $options = '<select name="defaultrole">'."\n".
1985: ' <option value="">'.&mt('Please select').'</option>'."\n";
1986: if ($context eq 'course') {
1987: $options .= &default_course_roles($context,$checkpriv,$crstype,%customroles);
1988: } elsif ($context eq 'author') {
1989: my @roles = &construction_space_roles($checkpriv);
1990: foreach my $role (@roles) {
1991: my $plrole=&Apache::lonnet::plaintext($role);
1992: $options .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1993: }
1994: } elsif ($context eq 'domain') {
1995: my @roles = &domain_roles($checkpriv);
1996: foreach my $role (@roles) {
1997: my $plrole=&Apache::lonnet::plaintext($role);
1998: $options .= ' <option value="'.$role.'">'.$plrole.'</option>';
1999: }
2000: my $courseform = &Apache::loncommon::selectcourse_link
2001: ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course/Community');
2002: my ($credit_elem,$creditsinput);
2003: if ($showcredits) {
2004: $credit_elem = 'credits';
2005: $creditsinput = '<td><input type="text" name="credits" value="" /></td>';
2006: }
2007: $cb_jscript =
2008: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform','courserole','Course/Community',$credit_elem);
2009: $coursepick = &Apache::loncommon::start_data_table().
2010: &Apache::loncommon::start_data_table_header_row().
2011: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th>'.
2012: '<th>'.$lt{'grs'}.'</th>'.
2013: '<th>'.$lt{'crd'}.'</th>'.
2014: &Apache::loncommon::end_data_table_header_row().
2015: &Apache::loncommon::start_data_table_row()."\n".
2016: '<td><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'studentform','dccourse','dcdomain','coursedesc','','','','crstype'".')" /></td>'."\n".
2017: '<td><select name="courserole">'."\n".
2018: &default_course_roles($context,$checkpriv,'Course',%customroles)."\n".
2019: '</select></td><td>'.
2020: '<table class="LC_createuser">'.
2021: '<tr class="LC_section_row"><td valign="top">'.
2022: $lt{'exs'}.'<br /><select name="currsec">'.
2023: ' <option value=""><--'.&mt('Pick course first').
2024: '</select></td>'.
2025: '<td> </td>'.
2026: '<td valign="top">'.$lt{'new'}.'<br />'.
2027: '<input type="text" name="newsec" value="" size="5" />'.
2028: '<input type="hidden" name="groups" value="" />'.
2029: '<input type="hidden" name="sections" value="" />'.
2030: '<input type="hidden" name="origdom" value="'.
2031: $env{'request.role.domain'}.'" />'.
2032: '<input type="hidden" name="dccourse" value="" />'.
2033: '<input type="hidden" name="dcdomain" value="" />'.
2034: '<input type="hidden" name="crstype" value="" />'.
2035: '</td></tr></table></td>'.$creditsinput.
2036: &Apache::loncommon::end_data_table_row().
2037: &Apache::loncommon::end_data_table()."\n";
2038: }
2039: $options .= '</select>';
2040: return ($options,$cb_jscript,$coursepick);
2041: }
2042:
2043: sub default_course_roles {
2044: my ($context,$checkpriv,$crstype,%customroles) = @_;
2045: my $output;
2046: my $custom = 1;
2047: my @roles = &course_roles($context,$checkpriv,$custom,lc($crstype));
2048: foreach my $role (@roles) {
2049: if ($role ne 'cr') {
2050: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
2051: $output .= ' <option value="'.$role.'">'.$plrole.'</option>';
2052: }
2053: }
2054: if (keys(%customroles) > 0) {
2055: if (grep(/^cr$/,@roles)) {
2056: foreach my $cust (sort(keys(%customroles))) {
2057: my $custrole='cr_'.$env{'user.domain'}.
2058: '_'.$env{'user.name'}.'_'.$cust;
2059: $output .= ' <option value="'.$custrole.'">'.$cust.'</option>';
2060: }
2061: }
2062: }
2063: return $output;
2064: }
2065:
2066: sub construction_space_roles {
2067: my ($checkpriv) = @_;
2068: my @allroles = &roles_by_context('author');
2069: my @roles;
2070: if ($checkpriv) {
2071: foreach my $role (@allroles) {
2072: if (&Apache::lonnet::allowed('c'.$role,$env{'user.domain'}.'/'.$env{'user.name'})) {
2073: push(@roles,$role);
2074: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2075: my ($audom,$auname) = ($1,$2);
2076: if (($role eq 'ca') || ($role eq 'aa')) {
2077: if ((&Apache::lonnet::allowed('v'.$role,,$audom.'/'.$auname)) &&
2078: ($env{"environment.internal.manager./$audom/$auname"})) {
2079: push(@roles,$role);
2080: }
2081: }
2082: }
2083: }
2084: return @roles;
2085: } else {
2086: return @allroles;
2087: }
2088: }
2089:
2090: sub domain_roles {
2091: my ($checkpriv) = @_;
2092: my @allroles = &roles_by_context('domain');
2093: my @roles;
2094: if ($checkpriv) {
2095: foreach my $role (@allroles) {
2096: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
2097: push(@roles,$role);
2098: }
2099: }
2100: return @roles;
2101: } else {
2102: return @allroles;
2103: }
2104: }
2105:
2106: sub course_roles {
2107: my ($context,$checkpriv,$custom,$roletype) = @_;
2108: my $crstype;
2109: if ($roletype eq 'community') {
2110: $crstype = 'Community' ;
2111: } else {
2112: $crstype = 'Course';
2113: }
2114: my @allroles = &roles_by_context('course',$custom,$crstype);
2115: my @roles;
2116: if ($context eq 'domain') {
2117: @roles = @allroles;
2118: } elsif ($context eq 'course') {
2119: if ($env{'request.course.id'}) {
2120: if ($checkpriv) {
2121: foreach my $role (@allroles) {
2122: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
2123: push(@roles,$role);
2124: } else {
2125: if ((($role ne 'cc') && ($role ne 'co')) && ($env{'request.course.sec'} ne '')) {
2126: if (&Apache::lonnet::allowed('c'.$role,
2127: $env{'request.course.id'}.'/'.
2128: $env{'request.course.sec'})) {
2129: push(@roles,$role);
2130: }
2131: }
2132: }
2133: }
2134: } else {
2135: @roles = @allroles;
2136: }
2137: }
2138: }
2139: return @roles;
2140: }
2141:
2142: sub curr_role_permissions {
2143: my ($context,$setting,$checkpriv,$type) = @_;
2144: my $custom = 1;
2145: my @roles;
2146: if ($context eq 'author') {
2147: @roles = &construction_space_roles($checkpriv);
2148: } elsif ($context eq 'domain') {
2149: if ($setting eq 'course') {
2150: @roles = &course_roles($context,$checkpriv,$custom,$type);
2151: } else {
2152: @roles = &domain_roles($checkpriv);
2153: }
2154: } elsif ($context eq 'course') {
2155: @roles = &course_roles($context,$checkpriv,$custom,$type);
2156: }
2157: return @roles;
2158: }
2159:
2160: # ======================================================= Existing Custom Roles
2161:
2162: sub my_custom_roles {
2163: my ($crstype,$udom,$uname) = @_;
2164: my %returnhash=();
2165: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
2166: my %rolehash=&Apache::lonnet::dump('roles',$udom,$uname);
2167: foreach my $key (keys(%rolehash)) {
2168: if ($key=~/^rolesdef\_(\w+)$/) {
2169: my $role = $1;
2170: if ($crstype eq 'Community') {
2171: next if ($rolehash{$key} =~ /bre\&S/);
2172: }
2173: $returnhash{$role}=$role;
2174: }
2175: }
2176: return %returnhash;
2177: }
2178:
2179: sub print_userlist {
2180: my ($r,$mode,$permission,$context,$formname,$totcodes,$codetitles,
2181: $idlist,$idlist_titles,$showcredits) = @_;
2182: my $format = $env{'form.output'};
2183: if (! exists($env{'form.sortby'})) {
2184: $env{'form.sortby'} = 'username';
2185: }
2186: if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
2187: $env{'form.Status'} = 'Active';
2188: }
2189: my $onchange = "javascript:updateCols('Status');";
2190: my $status_select = &Apache::lonhtmlcommon::StatusOptions
2191: ($env{'form.Status'},undef,undef,$onchange);
2192:
2193: if ($env{'form.showrole'} eq '') {
2194: if ($context eq 'course') {
2195: $env{'form.showrole'} = 'st';
2196: } else {
2197: $env{'form.showrole'} = 'Any';
2198: }
2199: }
2200: if (! defined($env{'form.output'}) ||
2201: $env{'form.output'} !~ /^(csv|excel|html)$/ ) {
2202: $env{'form.output'} = 'html';
2203: }
2204:
2205: my @statuses;
2206: if ($env{'form.Status'} eq 'Any') {
2207: @statuses = ('previous','active','future');
2208: } elsif ($env{'form.Status'} eq 'Expired') {
2209: @statuses = ('previous');
2210: } elsif ($env{'form.Status'} eq 'Active') {
2211: @statuses = ('active');
2212: } elsif ($env{'form.Status'} eq 'Future') {
2213: @statuses = ('future');
2214: }
2215:
2216: # Interface output
2217: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
2218: '<input type="hidden" name="action" value="'.
2219: $env{'form.action'}.'" />');
2220: $r->print('<div>'."\n");
2221: if ($env{'form.action'} ne 'modifystudent') {
2222: my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
2223: 'excel' => "Excel",
2224: 'html' => 'HTML');
2225: my $output_selector = '<select size="1" name="output" onchange="javascript:updateCols('."'output'".');" >';
2226: foreach my $outputformat ('html','csv','excel') {
2227: my $option = '<option value="'.$outputformat.'"';
2228: if ($outputformat eq $env{'form.output'}) {
2229: $option .= ' selected="selected"';
2230: }
2231: $option .='>'.$lt{$outputformat}.'</option>';
2232: $output_selector .= "\n".$option;
2233: }
2234: $output_selector .= '</select>';
2235: $r->print('<span class="LC_nobreak">'
2236: .&mt('Output Format: [_1]',$output_selector)
2237: .'</span>'.(' 'x3));
2238: }
2239: $r->print('<span class="LC_nobreak">'
2240: .&mt('User Status: [_1]',$status_select)
2241: .'</span>'.(' 'x3)."\n");
2242: my $roleselected = '';
2243: if ($env{'form.showrole'} eq 'Any') {
2244: $roleselected = ' selected="selected"';
2245: }
2246: my ($cnum,$cdom);
2247: $r->print(&role_filter($context));
2248: if ($context eq 'course') {
2249: ($cnum,$cdom) = &get_course_identity();
2250: $r->print(§ion_group_filter($cnum,$cdom));
2251: }
2252: $r->print('</div><div class="LC_left_float">'.
2253: &column_checkboxes($context,$mode,$formname,$showcredits).
2254: '</div>');
2255: if ($env{'form.phase'} eq '') {
2256: $r->print('<br clear="all" />'.
2257: &list_submit_button(&mt('Display List of Users'))."\n".
2258: '<input type="hidden" name="phase" value="" /></form>');
2259: return;
2260: }
2261: if (!(($context eq 'domain') &&
2262: (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
2263: $r->print('<br clear="all" />'.
2264: &list_submit_button(&mt('Update Display'))."\n");
2265: }
2266:
2267: my @cols = &infocolumns($context,$mode,$showcredits);
2268: if (!@cols) {
2269: $r->print('<hr style="clear:both;" /><span class="LC_warning">'.
2270: &mt('No user information selected for display.').'</span>'.
2271: '<input type="hidden" name="phase" value="display" /></form>'."\n");
2272: return;
2273: }
2274: my ($indexhash,$keylist) = &make_keylist_array();
2275: my (%userlist,%userinfo,$clearcoursepick,$needauthorquota,$needauthorusage);
2276: if (($context eq 'domain') &&
2277: ($env{'form.roletype'} eq 'course') ||
2278: ($env{'form.roletype'} eq 'community')) {
2279: my ($crstype,$numcodes,$title,$warning);
2280: if ($env{'form.roletype'} eq 'course') {
2281: $crstype = 'Course';
2282: $numcodes = $totcodes;
2283: $title = &mt('Select Courses');
2284: $warning = &mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.');
2285: } elsif ($env{'form.roletype'} eq 'community') {
2286: $crstype = 'Community';
2287: $numcodes = 0;
2288: $title = &mt('Select Communities');
2289: $warning = &mt('Warning: data retrieval for multiple communities can take considerable time, as this operation is not currently optimized.');
2290: }
2291: my @standardnames = &Apache::loncommon::get_standard_codeitems();
2292: my $courseform =
2293: &Apache::lonhtmlcommon::course_selection($formname,$numcodes,
2294: $codetitles,$idlist,$idlist_titles,$crstype,
2295: \@standardnames);
2296: $r->print('<div class="LC_left_float">'.
2297: '<fieldset><legend>'.$title.'</legend>'."\n".
2298: $courseform."\n".
2299: '</fieldset></div><br clear="all" />'.
2300: '<p><input type="hidden" name="origroletype" value="'.$env{'form.roletype'}.'" />'.
2301: &list_submit_button(&mt('Update Display')).
2302: "\n".'</p><span class="LC_warning">'.$warning.'</span>'."\n");
2303: $clearcoursepick = 0;
2304: if (($env{'form.origroletype'} ne '') &&
2305: ($env{'form.origroletype'} ne $env{'form.roletype'})) {
2306: $clearcoursepick = 1;
2307: }
2308: if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
2309: $r->print('<hr />'.&mt('Searching ...').'<br /> <br />');
2310: }
2311: } else {
2312: $r->print('<hr style="clear:both;" /><div id="searching">'.&mt('Searching ...').'</div>');
2313: }
2314: $r->rflush();
2315: if ($context eq 'course') {
2316: if (($env{'form.showrole'} eq 'st') || ($env{'form.showrole'} eq 'Any')) {
2317: my $classlist = &Apache::loncoursedata::get_classlist();
2318: if (ref($classlist) eq 'HASH') {
2319: %userlist = %{$classlist};
2320: }
2321: }
2322: if ($env{'form.showrole'} ne 'st') {
2323: my $showroles;
2324: if ($env{'form.showrole'} ne 'Any') {
2325: $showroles = [$env{'form.showrole'}];
2326: } else {
2327: $showroles = undef;
2328: }
2329: my $withsec = 1;
2330: my $hidepriv = 1;
2331: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
2332: \@statuses,$showroles,undef,$withsec,$hidepriv);
2333: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
2334: \%advrolehash,$permission);
2335: }
2336: } else {
2337: my (%cstr_roles,%dom_roles);
2338: if ($context eq 'author') {
2339: my @possroles = &roles_by_context($context);
2340: my @allowedroles;
2341: # List co-authors and assistant co-authors
2342: my ($auname,$audom);
2343: if ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2344: ($audom,$auname) = ($1,$2);
2345: foreach my $role (@possroles) {
2346: if ((&Apache::lonnet::allowed('v'.$role,"$audom/$auname")) ||
2347: (&Apache::lonnet::allowed('c'.$role,"$audom/$auname"))) {
2348: push(@allowedroles,$role);
2349: }
2350: }
2351: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
2352: if ($1 eq $env{'user.domain'}) {
2353: $auname = $env{'user.name'};
2354: $audom = $env{'user.domain'};
2355: }
2356: @allowedroles = @possroles;
2357: }
2358: if (($auname ne '') && ($audom ne '')) {
2359: %cstr_roles = &Apache::lonnet::get_my_roles($auname,$audom,undef,
2360: \@statuses,\@allowedroles);
2361: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
2362: \%cstr_roles,$permission);
2363: }
2364: } elsif ($context eq 'domain') {
2365: if ($env{'form.roletype'} eq 'domain') {
2366: if (grep(/^authorusage$/,@cols)) {
2367: $needauthorusage = 1;
2368: }
2369: if (grep(/^authorquota$/,@cols)) {
2370: $needauthorquota = 1;
2371: }
2372: %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'});
2373: foreach my $key (keys(%dom_roles)) {
2374: if (ref($dom_roles{$key}) eq 'HASH') {
2375: &gather_userinfo($context,$format,\%userlist,$indexhash,
2376: \%userinfo,$dom_roles{$key},$permission);
2377: }
2378: }
2379: } elsif ($env{'form.roletype'} eq 'author') {
2380: my %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'},['au']);
2381: my %coauthors;
2382: foreach my $key (keys(%dom_roles)) {
2383: if (ref($dom_roles{$key}) eq 'HASH') {
2384: if ($env{'form.showrole'} eq 'au') {
2385: &gather_userinfo($context,$format,\%userlist,$indexhash,
2386: \%userinfo,$dom_roles{$key},$permission);
2387: } else {
2388: my @possroles;
2389: if ($env{'form.showrole'} eq 'Any') {
2390: @possroles = &roles_by_context('author');
2391: } else {
2392: @possroles = ($env{'form.showrole'});
2393: }
2394: foreach my $author (sort(keys(%{$dom_roles{$key}}))) {
2395: my ($role,$authorname,$authordom) = split(/:/,$author,-1);
2396: my $extent = '/'.$authordom.'/'.$authorname;
2397: %{$coauthors{$extent}} =
2398: &Apache::lonnet::get_my_roles($authorname,
2399: $authordom,undef,\@statuses,\@possroles);
2400: }
2401: &gather_userinfo($context,$format,\%userlist,
2402: $indexhash,\%userinfo,\%coauthors,$permission);
2403: }
2404: }
2405: }
2406: } elsif (($env{'form.roletype'} eq 'course') ||
2407: ($env{'form.roletype'} eq 'community')) {
2408: if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
2409: my %courses = &process_coursepick();
2410: my %allusers;
2411: my $hidepriv = 1;
2412: foreach my $cid (keys(%courses)) {
2413: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
2414: next if ($cnum eq '' || $cdom eq '');
2415: my $custom = 1;
2416: my (@roles,@sections,%access,%users,%userdata,
2417: %statushash);
2418: if ($env{'form.showrole'} eq 'Any') {
2419: @roles = &course_roles($context,undef,$custom,
2420: $env{'form.roletype'});
2421: } else {
2422: @roles = ($env{'form.showrole'});
2423: }
2424: foreach my $role (@roles) {
2425: %{$users{$role}} = ();
2426: }
2427: foreach my $type (@statuses) {
2428: $access{$type} = $type;
2429: }
2430: &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash,$hidepriv);
2431: foreach my $user (keys(%userdata)) {
2432: next if (ref($userinfo{$user}) eq 'HASH');
2433: foreach my $item ('fullname','id') {
2434: $userinfo{$user}{$item} = $userdata{$user}[$indexhash->{$item}];
2435: }
2436: }
2437: foreach my $role (keys(%users)) {
2438: foreach my $user (keys(%{$users{$role}})) {
2439: my $uniqid = $user.':'.$role;
2440: $allusers{$uniqid}{$cid} = { desc => $cdesc,
2441: secs => $statushash{$user}{$role},
2442: };
2443: }
2444: }
2445: }
2446: &gather_userinfo($context,$format,\%userlist,$indexhash,
2447: \%userinfo,\%allusers,$permission);
2448: } else {
2449: $r->print('<input type="hidden" name="phase" value="'.
2450: $env{'form.phase'}.'" /></form>');
2451: return;
2452: }
2453: }
2454: }
2455: }
2456: if (keys(%userlist) == 0) {
2457: my $msg = '';
2458: if ($context eq 'author') {
2459: $msg = &mt('There are no co-authors to display.');
2460: } elsif ($context eq 'domain') {
2461: if ($env{'form.roletype'} eq 'domain') {
2462: $msg = &mt('There are no users with domain roles to display.');
2463: } elsif ($env{'form.roletype'} eq 'author') {
2464: $msg = &mt('There are no authors or co-authors to display.');
2465: } elsif ($env{'form.roletype'} eq 'course') {
2466: $msg = &mt('There are no course users to display');
2467: } elsif ($env{'form.roletype'} eq 'community') {
2468: $msg = &mt('There are no community users to display');
2469: }
2470: } elsif ($context eq 'course') {
2471: $r->print(&mt('There are no course users to display.')."\n");
2472: }
2473: $r->print('<p class="LC_info">'.$msg.'</p>'."\n") if $msg;
2474: } else {
2475: # Print out the available choices
2476: my $usercount;
2477: if ($env{'form.action'} eq 'modifystudent') {
2478: ($usercount) = &show_users_list($r,$context,'view',$permission,
2479: $env{'form.Status'},\%userlist,$keylist,'',
2480: $showcredits);
2481: } else {
2482: ($usercount) = &show_users_list($r,$context,$env{'form.output'},
2483: $permission,$env{'form.Status'},\%userlist,
2484: $keylist,'',$showcredits,$needauthorquota,$needauthorusage);
2485: }
2486: if (!$usercount) {
2487: $r->print('<br /><span class="LC_info">'
2488: .&mt('There are no users matching the search criteria.')
2489: .'</span>'
2490: );
2491: }
2492: }
2493: $r->print('<input type="hidden" name="phase" value="'.
2494: $env{'form.phase'}.'" /></form>');
2495: return;
2496: }
2497:
2498: sub role_filter {
2499: my ($context) = @_;
2500: my $output;
2501: my $roleselected = '';
2502: if ($env{'form.showrole'} eq 'Any') {
2503: $roleselected = ' selected="selected"';
2504: }
2505: my ($role_select);
2506: if ($context eq 'domain') {
2507: $role_select = &domain_roles_select();
2508: $output = '<span class="LC_nobreak">'
2509: .&mt('Role Type: [_1]',$role_select)
2510: .'</span>';
2511: } else {
2512: $role_select = '<select name="showrole" onchange="javascript:updateCols('."'showrole'".');">'."\n".
2513: '<option value="Any" '.$roleselected.'>'.
2514: &mt('Any role').'</option>';
2515: my ($roletype,$crstype);
2516: if ($context eq 'course') {
2517: $crstype = &Apache::loncommon::course_type();
2518: if ($crstype eq 'Community') {
2519: $roletype = 'community';
2520: } else {
2521: $roletype = 'course';
2522: }
2523: }
2524: my @poss_roles = &curr_role_permissions($context,'','',$roletype);
2525: foreach my $role (@poss_roles) {
2526: $roleselected = '';
2527: if ($role eq $env{'form.showrole'}) {
2528: $roleselected = ' selected="selected"';
2529: }
2530: my $plrole;
2531: if ($role eq 'cr') {
2532: $plrole = &mt('Custom role');
2533: } else {
2534: $plrole=&Apache::lonnet::plaintext($role,$crstype);
2535: }
2536: $role_select .= '<option value="'.$role.'"'.$roleselected.'>'.$plrole.'</option>';
2537: }
2538: $role_select .= '</select>';
2539: $output = '<span class="LC_nobreak">'
2540: .&mt('Role: [_1]',$role_select)
2541: .'</span>';
2542: }
2543: return $output;
2544: }
2545:
2546: sub section_group_filter {
2547: my ($cnum,$cdom) = @_;
2548: my @filters;
2549: if ($env{'request.course.sec'} eq '') {
2550: @filters = ('sec');
2551: }
2552: push(@filters,'grp');
2553: my %name = (
2554: sec => 'secfilter',
2555: grp => 'grpfilter',
2556: );
2557: my %title = &Apache::lonlocal::texthash (
2558: sec => 'Section(s)',
2559: grp => 'Group(s)',
2560: all => 'all',
2561: none => 'none',
2562: );
2563: my $output;
2564: foreach my $item (@filters) {
2565: my ($markup,@options);
2566: if ($env{'form.'.$name{$item}} eq '') {
2567: $env{'form.'.$name{$item}} = 'all';
2568: }
2569: if ($item eq 'sec') {
2570: if (($env{'form.showrole'} eq 'cc') || ($env{'form.showrole'} eq 'co')) {
2571: $env{'form.'.$name{$item}} = 'none';
2572: }
2573: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
2574: @options = sort(keys(%sections_count));
2575: } elsif ($item eq 'grp') {
2576: my %curr_groups = &Apache::longroup::coursegroups();
2577: @options = sort(keys(%curr_groups));
2578: }
2579: if (@options > 0) {
2580: my $currsel;
2581: $markup = '<select name="'.$name{$item}.'">'."\n";
2582: foreach my $option ('all','none',@options) {
2583: $currsel = '';
2584: if ($env{'form.'.$name{$item}} eq $option) {
2585: $currsel = ' selected="selected"';
2586: }
2587: $markup .= ' <option value="'.$option.'"'.$currsel.'>';
2588: if (($option eq 'all') || ($option eq 'none')) {
2589: $markup .= $title{$option};
2590: } else {
2591: $markup .= $option;
2592: }
2593: $markup .= '</option>'."\n";
2594: }
2595: $markup .= '</select>'."\n";
2596: $output .= (' 'x3).'<span class="LC_nobreak">'
2597: .'<label>'.$title{$item}.': '.$markup.'</label>'
2598: .'</span> ';
2599: }
2600: }
2601: return $output;
2602: }
2603:
2604: sub infocolumns {
2605: my ($context,$mode,$showcredits) = @_;
2606: my @cols;
2607: if (($mode eq 'pickauthor') || ($mode eq 'autoenroll')) {
2608: @cols = &get_cols_array($context,$mode,$showcredits);
2609: } else {
2610: my @posscols = &get_cols_array($context,$mode,$showcredits);
2611: if ($env{'form.phase'} ne '') {
2612: my @checkedcols = &Apache::loncommon::get_env_multiple('form.showcol');
2613: foreach my $col (@checkedcols) {
2614: if (grep(/^$col$/,@posscols)) {
2615: push(@cols,$col);
2616: }
2617: }
2618: } else {
2619: @cols = @posscols;
2620: }
2621: }
2622: return @cols;
2623: }
2624:
2625: sub get_cols_array {
2626: my ($context,$mode,$showcredits) = @_;
2627: my @cols;
2628: if ($mode eq 'pickauthor') {
2629: @cols = ('username','fullname','status','email');
2630: } else {
2631: @cols = ('username','domain','id','fullname');
2632: if ($context eq 'course') {
2633: push(@cols,'section');
2634: }
2635: push(@cols,('start','end','role'));
2636: unless (($mode eq 'autoenroll') && ($env{'form.Status'} ne 'Any')) {
2637: push(@cols,'status');
2638: }
2639: if ($context eq 'course') {
2640: push(@cols,'groups');
2641: }
2642: push(@cols,'email');
2643: if (($context eq 'course') && ($mode ne 'autoenroll')) {
2644: if ($showcredits) {
2645: push(@cols,'credits');
2646: }
2647: push(@cols,'lastlogin','clicker');
2648: }
2649: if (($context eq 'course') && ($mode ne 'autoenroll') &&
2650: ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
2651: push(@cols,'photo');
2652: }
2653: if ($context eq 'domain') {
2654: push(@cols,('authorusage','authorquota','extent'));
2655: }
2656: if ($context eq 'author') {
2657: push(@cols,'manager');
2658: }
2659: }
2660: return @cols;
2661: }
2662:
2663: sub column_checkboxes {
2664: my ($context,$mode,$formname,$showcredits) = @_;
2665: my @cols = &get_cols_array($context,$mode,$showcredits);
2666: my @showncols = &Apache::loncommon::get_env_multiple('form.showcol');
2667: my (%disabledchk,%unchecked);
2668: if ($env{'form.phase'} eq '') {
2669: $disabledchk{'status'} = 1;
2670: if ($context eq 'course') {
2671: $disabledchk{'role'} = 1;
2672: $unchecked{'photo'} = 1;
2673: $unchecked{'clicker'} = 1;
2674: if ($showcredits) {
2675: $unchecked{'credits'} = 1;
2676: }
2677: } elsif ($context eq 'domain') {
2678: $unchecked{'extent'} = 1;
2679: }
2680: $unchecked{'start'} = 1;
2681: $unchecked{'end'} = 1;
2682: } else {
2683: if ($env{'form.Status'} ne 'Any') {
2684: $disabledchk{'status'} = 1;
2685: }
2686: if (($env{'form.showrole'} ne 'Any') && ($env{'form.showrole'} ne 'cr')) {
2687: $disabledchk{'role'} = 1;
2688: }
2689: if ($context eq 'domain') {
2690: if (($env{'form.roletype'} eq 'course') ||
2691: ($env{'form.roletype'} eq 'community')) {
2692: $disabledchk{'status'} = 1;
2693: $disabledchk{'authorusage'} = 1;
2694: $disabledchk{'authorquota'} = 1;
2695: } elsif ($env{'form.roletype'} eq 'domain') {
2696: $disabledchk{'extent'} = 1;
2697: }
2698: } elsif ($context eq 'author') {
2699: if (($env{'form.Status'} eq 'Expired') ||
2700: ($env{'form.showrole'} eq 'aa')) {
2701: $disabledchk{'manager'} = 1;
2702: }
2703: }
2704: }
2705: my $numposs = scalar(@cols);
2706: my $numinrow = 7;
2707: my %lt = &get_column_names($context);
2708: my $output = '<fieldset><legend>'.&mt('Information to show').'</legend>'."\n".'<span class="LC_nobreak">'.
2709: '<input type="button" onclick="javascript:checkAll(document.'.$formname.'.showcol);" value="'.&mt('check all').'" />'.
2710: (' 'x3).
2711: '<input type="button" onclick="javascript:uncheckAll(document.'.$formname.'.showcol);" value="'.&mt('uncheck all').'" />'.
2712: '</span><table>';
2713:
2714: for (my $i=0; $i<$numposs; $i++) {
2715: my $rem = $i%($numinrow);
2716: if ($rem == 0) {
2717: if ($i > 0) {
2718: $output .= '</tr>';
2719: }
2720: $output .= '<tr>';
2721: }
2722: my $checked;
2723: if ($env{'form.phase'} eq '') {
2724: $checked = ' checked="checked"';
2725: if ($unchecked{$cols[$i]}) {
2726: $checked = '';
2727: }
2728: if ($disabledchk{$cols[$i]}) {
2729: $checked = ' disabled="disabled"';
2730: }
2731: } elsif (grep(/^\Q$cols[$i]\E$/,@showncols)) {
2732: $checked = ' checked="checked"';
2733: } elsif ($disabledchk{$cols[$i]}) {
2734: $checked = ' disabled="disabled"';
2735: }
2736: if ($i == $numposs-1) {
2737: my $colsleft = $numinrow-$rem;
2738: if ($colsleft > 1) {
2739: $output .= '<td colspan="'.$colsleft.'">';
2740: } else {
2741: $output .= '<td>';
2742: }
2743: } else {
2744: $output .= '<td>';
2745: }
2746: my $style;
2747: if ($cols[$i] eq 'extent') {
2748: if (($env{'form.roletype'} eq 'domain') || ($env{'form.roletype'} eq '')) {
2749: $style = ' style="display: none;"';
2750: }
2751: } elsif (($cols[$i] eq 'authorusage') || ($cols[$i] eq 'authorquota')) {
2752: if ($env{'form.roletype'} ne 'domain') {
2753: $style = ' style="display: none;"';
2754: }
2755: }
2756: $output .= '<span id="show'.$cols[$i].'"'.$style.'><label>'.
2757: '<input id="showcol'.$cols[$i].'" type="checkbox" name="showcol" value="'.$cols[$i].'"'.$checked.' /><span id="showcoltext'.$cols[$i].'">'.
2758: $lt{$cols[$i]}.'</span>'.
2759: '</label></span></td>';
2760: }
2761: $output .= '</tr></table></fieldset>';
2762: return $output;
2763: }
2764:
2765: sub list_submit_button {
2766: my ($text) = @_;
2767: return '<input type="button" name="updatedisplay" value="'.$text.'" onclick="javascript:display_update()" />';
2768: }
2769:
2770: sub get_column_names {
2771: my ($context) = @_;
2772: my %lt = &Apache::lonlocal::texthash(
2773: 'username' => "username",
2774: 'domain' => "domain",
2775: 'id' => 'ID',
2776: 'fullname' => "name",
2777: 'section' => "section",
2778: 'groups' => "active groups",
2779: 'start' => "start date",
2780: 'end' => "end date",
2781: 'status' => "status",
2782: 'role' => "role",
2783: 'credits' => "credits",
2784: 'type' => "enroll type/action",
2785: 'email' => "e-mail address",
2786: 'photo' => "photo",
2787: 'lastlogin' => "last login",
2788: 'extent' => "extent",
2789: 'authorusage' => "disk usage (%)",
2790: 'authorquota' => "disk quota (MB)",
2791: 'ca' => "check all",
2792: 'ua' => "uncheck all",
2793: 'clicker' => "clicker-ID",
2794: 'manager' => "co-author manager",
2795: );
2796: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
2797: $lt{'extent'} = &mt('course(s): description, section(s), status');
2798: } elsif ($context eq 'domain' && $env{'form.roletype'} eq 'community') {
2799: $lt{'extent'} = &mt('community(s): description, section(s), status');
2800: } elsif (($context eq 'author') ||
2801: ($context eq 'domain' && $env{'form.roletype'} eq 'author')) {
2802: $lt{'extent'} = &mt('author');
2803: }
2804: return %lt;
2805: }
2806:
2807: sub gather_userinfo {
2808: my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_;
2809: my $viewablesec;
2810: if ($context eq 'course') {
2811: $viewablesec = &viewable_section($permission);
2812: }
2813: foreach my $item (keys(%{$rolehash})) {
2814: my %userdata;
2815: if ($context eq 'author') {
2816: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
2817: split(/:/,$item);
2818: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
2819: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2820: $item,$userlist);
2821: } elsif ($context eq 'course') {
2822: ($userdata{'username'},$userdata{'domain'},$userdata{'role'},
2823: $userdata{'section'}) = split(/:/,$item,-1);
2824: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
2825: if (($viewablesec ne '') && ($userdata{'section'} ne '')) {
2826: next if ($viewablesec ne $userdata{'section'});
2827: }
2828: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2829: $item,$userlist);
2830: } elsif ($context eq 'domain') {
2831: if ($env{'form.roletype'} eq 'domain') {
2832: ($userdata{'role'},$userdata{'username'},$userdata{'domain'}) =
2833: split(/:/,$item);
2834: ($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
2835: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2836: $item,$userlist);
2837: } elsif ($env{'form.roletype'} eq 'author') {
2838: if (ref($rolehash->{$item}) eq 'HASH') {
2839: $userdata{'extent'} = $item;
2840: foreach my $key (keys(%{$rolehash->{$item}})) {
2841: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) = split(/:/,$key);
2842: ($userdata{'start'},$userdata{'end'}) =
2843: split(/:/,$rolehash->{$item}{$key});
2844: my $uniqid = $key.':'.$item;
2845: &build_user_record($context,\%userdata,$userinfo,
2846: $indexhash,$uniqid,$userlist);
2847: }
2848: }
2849: } elsif (($env{'form.roletype'} eq 'course') ||
2850: ($env{'form.roletype'} eq 'community')) {
2851: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
2852: split(/:/,$item);
2853: if (ref($rolehash->{$item}) eq 'HASH') {
2854: my $numcids = keys(%{$rolehash->{$item}});
2855: foreach my $cid (sort(keys(%{$rolehash->{$item}}))) {
2856: if (ref($rolehash->{$item}{$cid}) eq 'HASH') {
2857: my $spanstart = '';
2858: my $spanend = '; ';
2859: my $space = ', ';
2860: if ($format eq 'html' || $format eq 'view') {
2861: $spanstart = '<span class="LC_nobreak">';
2862: # FIXME: actions on courses disabled for now
2863: # if ($permission->{'cusr'}) {
2864: # if ($numcids > 1) {
2865: # $spanstart .= '<input type="radio" name="'.$item.'" value="'.$cid.'" /> ';
2866: # } else {
2867: # $spanstart .= '<input type="hidden" name="'.$item.'" value="'.$cid.'" /> ';
2868: # }
2869: # }
2870: $spanend = '</span><br />';
2871: $space = ', ';
2872: }
2873: $userdata{'extent'} .= $spanstart.
2874: $rolehash->{$item}{$cid}{'desc'}.$space;
2875: if (ref($rolehash->{$item}{$cid}{'secs'}) eq 'HASH') {
2876: foreach my $sec (sort(keys(%{$rolehash->{$item}{$cid}{'secs'}}))) {
2877: if (($env{'form.Status'} eq 'Any') ||
2878: ($env{'form.Status'} eq $rolehash->{$item}{$cid}{'secs'}{$sec})) {
2879: $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
2880: $userdata{'status'} = $rolehash->{$item}{$cid}{'secs'}{$sec};
2881: }
2882: }
2883: }
2884: }
2885: }
2886: }
2887: if ($userdata{'status'} ne '') {
2888: &build_user_record($context,\%userdata,$userinfo,
2889: $indexhash,$item,$userlist);
2890: }
2891: }
2892: }
2893: }
2894: return;
2895: }
2896:
2897: sub build_user_record {
2898: my ($context,$userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
2899: next if ($userdata->{'start'} eq '-1' && $userdata->{'end'} eq '-1');
2900: if (!(($context eq 'domain') && (($env{'form.roletype'} eq 'course')
2901: && ($env{'form.roletype'} eq 'community')))) {
2902: &process_date_info($userdata);
2903: }
2904: my $username = $userdata->{'username'};
2905: my $domain = $userdata->{'domain'};
2906: if (ref($userinfo->{$username.':'.$domain}) eq 'HASH') {
2907: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
2908: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
2909: } else {
2910: &aggregate_user_info($domain,$username,$userinfo);
2911: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
2912: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
2913: }
2914: foreach my $key (keys(%{$indexhash})) {
2915: if (defined($userdata->{$key})) {
2916: $userlist->{$record_key}[$indexhash->{$key}] = $userdata->{$key};
2917: }
2918: }
2919: return;
2920: }
2921:
2922: sub courses_selector {
2923: my ($cdom,$formname) = @_;
2924: my %codes = ();
2925: my @codetitles = ();
2926: my %cat_titles = ();
2927: my %cat_order = ();
2928: my %idlist = ();
2929: my %idnums = ();
2930: my %idlist_titles = ();
2931: my $caller = 'global';
2932: my $format_reply;
2933: my $jscript = '';
2934:
2935: my $totcodes = 0;
2936: my $instcats = &Apache::lonnet::get_dom_instcats($cdom);
2937: if (ref($instcats) eq 'HASH') {
2938: if ((ref($instcats->{'codetitles'}) eq 'ARRAY') && (ref($instcats->{'codes'}) eq 'HASH') &&
2939: (ref($instcats->{'cat_titles'}) eq 'HASH') && (ref($instcats->{'cat_order'}) eq 'HASH')) {
2940: %codes = %{$instcats->{'codes'}};
2941: @codetitles = @{$instcats->{'codetitles'}};
2942: %cat_titles = %{$instcats->{'cat_titles'}};
2943: %cat_order = %{$instcats->{'cat_order'}};
2944: $totcodes = scalar(keys(%codes));
2945: my $numtypes = @codetitles;
2946: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
2947: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
2948: my $longtitles_str = join('","',@{$longtitles});
2949: my $allidlist = $idlist{$codetitles[0]};
2950: $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
2951: $jscript .= $scripttext;
2952: $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,\@codetitles);
2953: }
2954: }
2955: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
2956:
2957: my %elements = (
2958: Year => 'selectbox',
2959: coursepick => 'radio',
2960: coursetotal => 'text',
2961: courselist => 'text',
2962: );
2963: $jscript .= &Apache::lonhtmlcommon::set_form_elements(\%elements);
2964: if ($env{'form.coursepick'} eq 'category') {
2965: $jscript .= qq|
2966: function setCourseCat(formname) {
2967: if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
2968: return;
2969: }
2970: courseSet('$codetitles[0]');
2971: for (var j=0; j<formname.Semester.length; j++) {
2972: if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
2973: formname.Semester.options[j].selected = true;
2974: }
2975: }
2976: if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
2977: return;
2978: }
2979: courseSet('$codetitles[1]');
2980: for (var j=0; j<formname.Department.length; j++) {
2981: if (formname.Department.options[j].value == "$env{'form.Department'}") {
2982: formname.Department.options[j].selected = true;
2983: }
2984: }
2985: if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
2986: return;
2987: }
2988: courseSet('$codetitles[2]');
2989: for (var j=0; j<formname.Number.length; j++) {
2990: if (formname.Number.options[j].value == "$env{'form.Number'}") {
2991: formname.Number.options[j].selected = true;
2992: }
2993: }
2994: }
2995: |;
2996: }
2997: return ($cb_jscript,$jscript,$totcodes,\@codetitles,\%idlist,
2998: \%idlist_titles);
2999: }
3000:
3001: sub course_selector_loadcode {
3002: my ($formname) = @_;
3003: my $loadcode;
3004: if ($env{'form.coursepick'} ne '') {
3005: $loadcode = 'javascript:setFormElements(document.'.$formname.')';
3006: if ($env{'form.coursepick'} eq 'category') {
3007: $loadcode .= ';javascript:setCourseCat(document.'.$formname.')';
3008: }
3009: }
3010: return $loadcode;
3011: }
3012:
3013: sub process_coursepick {
3014: my $coursefilter = $env{'form.coursepick'};
3015: my $cdom = $env{'request.role.domain'};
3016: my %courses;
3017: my $crssrch = 'Course';
3018: if ($env{'form.roletype'} eq 'community') {
3019: $crssrch = 'Community';
3020: }
3021: if ($coursefilter eq 'all') {
3022: %courses = &Apache::lonnet::courseiddump($cdom,'.','.','.','.','.',
3023: undef,undef,$crssrch);
3024: } elsif ($coursefilter eq 'category') {
3025: my $instcode = &instcode_from_coursefilter();
3026: %courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.',
3027: undef,undef,$crssrch);
3028: } elsif ($coursefilter eq 'specific') {
3029: if ($env{'form.coursetotal'} > 1) {
3030: my @course_ids = split(/&&/,$env{'form.courselist'});
3031: foreach my $cid (@course_ids) {
3032: $courses{$cid} = '';
3033: }
3034: } else {
3035: $courses{$env{'form.courselist'}} = '';
3036: }
3037: }
3038: return %courses;
3039: }
3040:
3041: sub instcode_from_coursefilter {
3042: my $instcode = '';
3043: my @cats = ('Semester','Year','Department','Number');
3044: foreach my $category (@cats) {
3045: if (defined($env{'form.'.$category})) {
3046: unless ($env{'form.'.$category} eq '-1') {
3047: $instcode .= $env{'form.'.$category};
3048: }
3049: }
3050: }
3051: if ($instcode eq '') {
3052: $instcode = '.';
3053: }
3054: return $instcode;
3055: }
3056:
3057: sub make_keylist_array {
3058: my ($index,$keylist);
3059: $index->{'domain'} = &Apache::loncoursedata::CL_SDOM();
3060: $index->{'username'} = &Apache::loncoursedata::CL_SNAME();
3061: $index->{'end'} = &Apache::loncoursedata::CL_END();
3062: $index->{'start'} = &Apache::loncoursedata::CL_START();
3063: $index->{'id'} = &Apache::loncoursedata::CL_ID();
3064: $index->{'section'} = &Apache::loncoursedata::CL_SECTION();
3065: $index->{'fullname'} = &Apache::loncoursedata::CL_FULLNAME();
3066: $index->{'status'} = &Apache::loncoursedata::CL_STATUS();
3067: $index->{'type'} = &Apache::loncoursedata::CL_TYPE();
3068: $index->{'lockedtype'} = &Apache::loncoursedata::CL_LOCKEDTYPE();
3069: $index->{'groups'} = &Apache::loncoursedata::CL_GROUP();
3070: $index->{'email'} = &Apache::loncoursedata::CL_PERMANENTEMAIL();
3071: $index->{'role'} = &Apache::loncoursedata::CL_ROLE();
3072: $index->{'extent'} = &Apache::loncoursedata::CL_EXTENT();
3073: $index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
3074: $index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();
3075: $index->{'credits'} = &Apache::loncoursedata::CL_CREDITS();
3076: $index->{'instsec'} = &Apache::loncoursedata::CL_INSTSEC();
3077: $index->{'authorquota'} = &Apache::loncoursedata::CL_AUTHORQUOTA();
3078: $index->{'authorusage'} = &Apache::loncoursedata::CL_AUTHORUSAGE();
3079: $index->{'manager'} = &Apache::loncoursedata::CL_CAMANAGER();
3080: foreach my $key (keys(%{$index})) {
3081: $keylist->[$index->{$key}] = $key;
3082: }
3083: return ($index,$keylist);
3084: }
3085:
3086: sub aggregate_user_info {
3087: my ($udom,$uname,$userinfo) = @_;
3088: my %info=&Apache::lonnet::get('environment',
3089: ['firstname','middlename',
3090: 'lastname','generation','id'],
3091: $udom,$uname);
3092: my ($tmp) = keys(%info);
3093: my ($fullname,$id);
3094: if ($tmp =~/^(con_lost|error|no_such_host)/i) {
3095: $fullname = 'not available';
3096: $id = 'not available';
3097: &Apache::lonnet::logthis('unable to retrieve environment '.
3098: 'for '.$uname.':'.$udom);
3099: } else {
3100: $fullname = &Apache::lonnet::format_name(@info{qw/firstname middlename lastname generation/},'lastname');
3101: $id = $info{'id'};
3102: }
3103: $userinfo->{$uname.':'.$udom} = {
3104: fullname => $fullname,
3105: id => $id,
3106: };
3107: return;
3108: }
3109:
3110: sub process_date_info {
3111: my ($userdata) = @_;
3112: my $now = time;
3113: $userdata->{'status'} = 'Active';
3114: if ($userdata->{'start'} > 0) {
3115: if ($now < $userdata->{'start'}) {
3116: $userdata->{'status'} = 'Future';
3117: }
3118: }
3119: if ($userdata->{'end'} > 0) {
3120: if ($now > $userdata->{'end'}) {
3121: $userdata->{'status'} = 'Expired';
3122: }
3123: }
3124: return;
3125: }
3126:
3127: sub show_users_list {
3128: my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname,
3129: $showcredits,$needauthorquota,$needauthorusage)=@_;
3130: if ($formname eq '') {
3131: $formname = 'studentform';
3132: }
3133: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
3134: #
3135: # Variables for excel output
3136: my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
3137: #
3138: # Variables for csv output
3139: my ($CSVfile,$CSVfilename);
3140: #
3141: my $sortby = $env{'form.sortby'};
3142: my @sortable = ('username','domain','id','fullname','start','end','email','role');
3143: if ($context eq 'course') {
3144: push(@sortable,('section','groups','type'));
3145: if ($showcredits) {
3146: push(@sortable,'credits');
3147: }
3148: } else {
3149: push(@sortable,'extent');
3150: if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
3151: (($env{'form.showrole'} eq 'Any') || ($env{'form.showrole'} eq 'au'))) {
3152: push(@sortable,('authorusage','authorquota'));
3153: }
3154: if ($context eq 'author') {
3155: push(@sortable,'manager');
3156: }
3157: }
3158: if ($mode eq 'pickauthor') {
3159: @sortable = ('username','fullname','email','status');
3160: }
3161: my %is_sortable;
3162: map { $is_sortable{$_} = 1; } @sortable;
3163: unless ($is_sortable{$sortby}) {
3164: $sortby = 'username';
3165: }
3166: my $setting = $env{'form.roletype'};
3167: my ($cid,$cdom,$cnum,$classgroups,$crstype,$defaultcredits);
3168: if ($context eq 'course') {
3169: $cid = $env{'request.course.id'};
3170: $crstype = &Apache::loncommon::course_type();
3171: ($cnum,$cdom) = &get_course_identity($cid);
3172: $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
3173: ($classgroups) = &Apache::loncoursedata::get_group_memberships(
3174: $userlist,$keylist,$cdom,$cnum);
3175: if ($mode eq 'autoenroll') {
3176: $env{'form.showrole'} = 'st';
3177: } else {
3178: if ($env{'course.'.$cid.'.internal.showphoto'}) {
3179: $r->print('
3180: <script type="text/javascript">
3181: // <![CDATA[
3182: function photowindow(photolink) {
3183: var title = "Photo_Viewer";
3184: var options = "scrollbars=1,resizable=1,menubar=0";
3185: options += ",width=240,height=240";
3186: stdeditbrowser = open(photolink,title,options,"1");
3187: stdeditbrowser.focus();
3188: }
3189: // ]]>
3190: </script>
3191: ');
3192: }
3193: }
3194: } elsif ($context eq 'domain') {
3195: if ($setting eq 'community') {
3196: $crstype = 'Community';
3197: } elsif ($setting eq 'course') {
3198: $crstype = 'Course';
3199: }
3200: }
3201: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
3202: my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
3203: my $verify_action_js = &bulkaction_javascript($formname);
3204: $r->print(<<END);
3205:
3206: <script type="text/javascript" language="Javascript">
3207: // <![CDATA[
3208:
3209: $verify_action_js
3210:
3211: function username_display_launch(username,domain) {
3212: var target;
3213: if (!document.$formname.usernamelink.length) {
3214: target = document.$formname.usernamelink.value;
3215: } else {
3216: for (var i=0; i<document.$formname.usernamelink.length; i++) {
3217: if (document.$formname.usernamelink[i].checked) {
3218: target = document.$formname.usernamelink[i].value;
3219: }
3220: }
3221: }
3222: if ((target == 'modify') || (target == 'activity')) {
3223: var nextaction = 'singleuser';
3224: if (target == 'activity') {
3225: nextaction = 'accesslogs';
3226: }
3227: if (document.$formname.userwin.checked == true) {
3228: var url = '/adm/createuser?srchterm='+username+'&srchdomain='+domain+'&phase=get_user_info&srchin=dom&srchby=uname&srchtype=exact&popup=1&action='+nextaction;
3229: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3230: modifywin = window.open(url,'',options,1);
3231: modifywin.focus();
3232: return;
3233: } else {
3234: document.$formname.srchterm.value=username;
3235: document.$formname.srchdomain.value=domain;
3236: document.$formname.phase.value='get_user_info';
3237: document.$formname.action.value = nextaction;
3238: document.$formname.submit();
3239: }
3240: }
3241: if (target == 'aboutme') {
3242: if (document.$formname.userwin.checked == true) {
3243: var url = '/adm/'+domain+'/'+username+'/aboutme?popup=1';
3244: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3245: aboutmewin = window.open(url,'',options,1);
3246: aboutmewin.focus();
3247: return;
3248: } else {
3249: document.location.href = '/adm/'+domain+'/'+username+'/aboutme';
3250: }
3251: }
3252: if (target == 'track') {
3253: if (document.$formname.userwin.checked == true) {
3254: var url = '/adm/trackstudent?selected_student='+username+':'+domain+'&only_body=1';
3255: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3256: var trackwin = window.open(url,'',options,1);
3257: trackwin.focus();
3258: return;
3259: } else {
3260: document.location.href = '/adm/trackstudent?selected_student='+username+':'+domain;
3261: }
3262: }
3263: }
3264: // ]]>
3265: </script>
3266: $date_sec_selector
3267: <input type="hidden" name="state" value="$env{'form.state'}" />
3268: END
3269: }
3270: $r->print(<<END);
3271: <input type="hidden" name="sortby" value="$sortby" />
3272: END
3273: my @cols = &infocolumns($context,$mode,$showcredits);
3274: my %coltxt = &get_column_names($context);
3275: my %acttxt = &Apache::lonlocal::texthash(
3276: 'pr' => "Proceed",
3277: 'ac' => "Action to take for selected users",
3278: 'link' => "Behavior of clickable username link for each user",
3279: 'aboutme' => "Display a user's personal information page",
3280: 'owin' => "Open in a new window",
3281: 'modify' => "Modify a user's information",
3282: 'track' => "View a user's recent activity",
3283: 'activity' => "View a user's access log",
3284: );
3285: my %lt = (%coltxt,%acttxt);
3286: my $rolefilter = $env{'form.showrole'};
3287: if ($env{'form.showrole'} eq 'cr') {
3288: $rolefilter = &mt('custom');
3289: } elsif ($env{'form.showrole'} ne 'Any') {
3290: $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'},$crstype);
3291: }
3292: my $results_description;
3293: if ($mode ne 'autoenroll') {
3294: $results_description = &results_header_row($rolefilter,$statusmode,
3295: $context,$permission,$mode,$crstype);
3296: $r->print('<b>'.$results_description.'</b><br clear="all" />');
3297: }
3298: my ($output,$actionselect,%canchange,%canchangesec);
3299: if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
3300: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
3301: if ($permission->{'cusr'}) {
3302: unless (($context eq 'domain') &&
3303: (($setting eq 'course') || ($setting eq 'community'))) {
3304: $actionselect =
3305: &select_actions($context,$setting,$statusmode,$formname);
3306: }
3307: }
3308: $r->print(<<END);
3309: <input type="hidden" name="srchby" value="uname" />
3310: <input type="hidden" name="srchin" value="dom" />
3311: <input type="hidden" name="srchtype" value="exact" />
3312: <input type="hidden" name="srchterm" value="" />
3313: <input type="hidden" name="srchdomain" value="" />
3314: END
3315: if ($actionselect) {
3316: $output .= <<"END";
3317: <div class="LC_left_float"><fieldset><legend>$lt{'ac'}</legend>
3318: $actionselect
3319: <br/><br /><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.$formname.actionlist)" />
3320: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.$formname.actionlist)" /><br /><input type="button" value="$lt{'pr'}" onclick="javascript:verify_action('actionlist')" /></fieldset></div>
3321: END
3322: my @allroles;
3323: if ($env{'form.showrole'} eq 'Any') {
3324: my $custom = 1;
3325: if ($context eq 'domain') {
3326: @allroles = &roles_by_context($setting,$custom,$crstype);
3327: } else {
3328: @allroles = &roles_by_context($context,$custom,$crstype);
3329: }
3330: } else {
3331: @allroles = ($env{'form.showrole'});
3332: }
3333: foreach my $role (@allroles) {
3334: if ($context eq 'domain') {
3335: if ($setting eq 'domain') {
3336: if (&Apache::lonnet::allowed('c'.$role,
3337: $env{'request.role.domain'})) {
3338: $canchange{$role} = 1;
3339: }
3340: } elsif ($setting eq 'author') {
3341: if (&Apache::lonnet::allowed('c'.$role,
3342: $env{'request.role.domain'})) {
3343: $canchange{$role} = 1;
3344: }
3345: }
3346: } elsif ($context eq 'author') {
3347: if (&Apache::lonnet::allowed('c'.$role,
3348: $env{'user.domain'}.'/'.$env{'user.name'})) {
3349: $canchange{$role} = 1;
3350: }
3351: } elsif ($context eq 'course') {
3352: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
3353: $canchange{$role} = 1;
3354: } elsif ($env{'request.course.sec'} ne '') {
3355: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
3356: $canchangesec{$role} = $env{'request.course.sec'};
3357: }
3358: } elsif ((($role eq 'co') && ($crstype eq 'Community')) ||
3359: (($role eq 'cc') && ($crstype eq 'Course'))) {
3360: if (&is_courseowner($env{'request.course.id'},
3361: $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
3362: $canchange{$role} = 1;
3363: }
3364: }
3365: }
3366: }
3367: }
3368: $output .= '<div class="LC_left_float"><fieldset><legend>'.$lt{'link'}.'</legend>'.
3369: '<table><tr>';
3370: my @linkdests = ('aboutme');
3371: if ($permission->{'cusr'}) {
3372: unshift (@linkdests,'modify');
3373: }
3374: if ($context eq 'course') {
3375: if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) ||
3376: &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.
3377: $env{'request.course.sec'})) {
3378: push(@linkdests,'track');
3379: }
3380: } elsif ($context eq 'domain') {
3381: if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
3382: push(@linkdests,'activity');
3383: }
3384: }
3385: $output .= '<td>';
3386: my $usernamelink = $env{'form.usernamelink'};
3387: if ($usernamelink eq '') {
3388: $usernamelink = 'aboutme';
3389: }
3390: foreach my $item (@linkdests) {
3391: my $checkedstr = '';
3392: if ($item eq $usernamelink) {
3393: $checkedstr = ' checked="checked"';
3394: }
3395: $output .= '<span class="LC_nobreak"><label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.' /> '.$lt{$item}.'</label></span><br />';
3396: }
3397: my $checkwin;
3398: if ($env{'form.userwin'}) {
3399: $checkwin = ' checked="checked"';
3400: }
3401: $output .=
3402: '</td><td valign="top" style="border-left: 1px solid;">'
3403: .'<span class="LC_nobreak"><label>'
3404: .'<input type="checkbox" name="userwin" value="1"'.$checkwin.' />'.$lt{'owin'}
3405: .'</label></span></td></tr></table></fieldset></div>';
3406: }
3407: $output .= "\n".'<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
3408: &Apache::loncommon::start_data_table().
3409: &Apache::loncommon::start_data_table_header_row();
3410: if ($mode eq 'autoenroll') {
3411: $output .= "
3412: <th><a href=\"javascript:document.$formname.sortby.value='type';document.$formname.submit();\">$lt{'type'}</a></th>
3413: ";
3414: } else {
3415: $output .= "\n".'<th> </th>'."\n";
3416: if ($actionselect) {
3417: $output .= '<th class="LC_nobreak" valign="top">'.&mt('Select').'</th>'."\n";
3418: }
3419: }
3420: foreach my $item (@cols) {
3421: $output .= '<th class="LC_nobreak" valign="top">';
3422: if ($is_sortable{$item}) {
3423: $output .= "<a href=\"javascript:document.$formname.sortby.value='$item';document.$formname.submit();\" style=\"text-decoration:none;\">$lt{$item}<span class=\"LC_fontsize_small\"> ▼</span></a>";
3424: } else {
3425: $output .= $lt{$item};
3426: }
3427: $output .= "</th>\n";
3428: }
3429: my %role_types = &role_type_names();
3430: $output .= &Apache::loncommon::end_data_table_header_row();
3431: # Done with the HTML header line
3432: } elsif ($mode eq 'csv') {
3433: #
3434: # Open a file
3435: $CSVfilename = '/prtspool/'.
3436: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
3437: time.'_'.rand(1000000000).'.csv';
3438: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
3439: $r->log_error("Couldn't open $CSVfilename for output $!");
3440: $r->print(
3441: '<p class="LC_error">'
3442: .&mt('Problems occurred in writing the CSV file.')
3443: .' '.&mt('This error has been logged.')
3444: .' '.&mt('Please alert your LON-CAPA administrator.')
3445: .'</p>'
3446: );
3447: $CSVfile = undef;
3448: }
3449: #
3450: # Write headers and data to file
3451: print $CSVfile '"'.$results_description.'"'."\n";
3452: print $CSVfile '"'.join('","',map {
3453: &Apache::loncommon::csv_translate($lt{$_})
3454: } (@cols))."\"\n";
3455: } elsif ($mode eq 'excel') {
3456: # Create the excel spreadsheet
3457: ($excel_workbook,$excel_filename,$format) =
3458: &Apache::loncommon::create_workbook($r);
3459: return if (! defined($excel_workbook));
3460: $excel_sheet = $excel_workbook->addworksheet('userlist');
3461: $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
3462: #
3463: my @colnames = map {$lt{$_}} (@cols);
3464:
3465: $excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
3466: }
3467:
3468: # Done with header lines in all formats
3469: my %index;
3470: my $i;
3471: foreach my $idx (@$keylist) {
3472: $index{$idx} = $i++;
3473: }
3474: my $now = time;
3475: my $usercount = 0;
3476: my ($secfilter,$grpfilter);
3477: if ($context eq 'course') {
3478: $secfilter = $env{'form.secfilter'};
3479: $grpfilter = $env{'form.grpfilter'};
3480: if ($secfilter eq '') {
3481: $secfilter = 'all';
3482: }
3483: if ($grpfilter eq '') {
3484: $grpfilter = 'all';
3485: }
3486: }
3487: my %ltstatus = &Apache::lonlocal::texthash(
3488: Active => 'Active',
3489: Future => 'Future',
3490: Expired => 'Expired',
3491: );
3492: my (%crslogins,%camanagers);
3493: if ($context eq 'course') {
3494: # If this is for a single course get last course "log-in".
3495: %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$cnum);
3496: } elsif ($context eq 'author') {
3497: map { $camanagers{$_.':ca'} = 1; } split(/,/,$env{'environment.authormanagers'});
3498: }
3499: # Get groups, role, permanent e-mail so we can sort on them if
3500: # necessary.
3501: foreach my $user (keys(%{$userlist})) {
3502: if ($user eq '' ) {
3503: delete($userlist->{$user});
3504: next;
3505: }
3506: if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) {
3507: delete($userlist->{$user});
3508: next;
3509: }
3510: my ($uname,$udom,$role,$groups,$email);
3511: if (($statusmode ne 'Any') &&
3512: ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
3513: delete($userlist->{$user});
3514: next;
3515: }
3516: if ($context eq 'domain') {
3517: if ($env{'form.roletype'} eq 'domain') {
3518: ($role,$uname,$udom) = split(/:/,$user);
3519: if (($uname eq $env{'request.role.domain'}.'-domainconfig') &&
3520: ($udom eq $env{'request.role.domain'})) {
3521: delete($userlist->{$user});
3522: next;
3523: }
3524: } elsif ($env{'form.roletype'} eq 'author') {
3525: ($uname,$udom,$role) = split(/:/,$user,-1);
3526: } elsif (($env{'form.roletype'} eq 'course') ||
3527: ($env{'form.roletype'} eq 'community')) {
3528: ($uname,$udom,$role) = split(/:/,$user);
3529: }
3530: } else {
3531: ($uname,$udom,$role) = split(/:/,$user,-1);
3532: if (($context eq 'course') && $role eq '') {
3533: $role = 'st';
3534: }
3535: }
3536: $userlist->{$user}->[$index{'role'}] = $role;
3537: if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
3538: delete($userlist->{$user});
3539: next;
3540: }
3541: if ($context eq 'course') {
3542: my @ac_groups;
3543: if (ref($classgroups) eq 'HASH') {
3544: $groups = $classgroups->{$user};
3545: }
3546: if (ref($groups->{'active'}) eq 'HASH') {
3547: @ac_groups = keys(%{$groups->{'active'}});
3548: $userlist->{$user}->[$index{'groups'}] = join(', ',@ac_groups);
3549: }
3550: if ($mode ne 'autoenroll') {
3551: my $section = $userlist->{$user}->[$index{'section'}];
3552: if (($env{'request.course.sec'} ne '') &&
3553: ($section ne $env{'request.course.sec'})) {
3554: if ($role eq 'st') {
3555: delete($userlist->{$user});
3556: next;
3557: }
3558: }
3559: if ($secfilter eq 'none') {
3560: if ($section ne '') {
3561: delete($userlist->{$user});
3562: next;
3563: }
3564: } elsif ($secfilter ne 'all') {
3565: if ($section ne $secfilter) {
3566: delete($userlist->{$user});
3567: next;
3568: }
3569: }
3570: if ($grpfilter eq 'none') {
3571: if (@ac_groups > 0) {
3572: delete($userlist->{$user});
3573: next;
3574: }
3575: } elsif ($grpfilter ne 'all') {
3576: if (!grep(/^\Q$grpfilter\E$/,@ac_groups)) {
3577: delete($userlist->{$user});
3578: next;
3579: }
3580: }
3581: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
3582: if ((grep/^photo$/,@cols) && ($role eq 'st')) {
3583: $userlist->{$user}->[$index{'photo'}] =
3584: &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg');
3585: $userlist->{$user}->[$index{'thumbnail'}] =
3586: &Apache::lonnet::retrievestudentphoto($udom,$uname,
3587: 'gif','thumbnail');
3588: }
3589: }
3590: if (($role eq 'st') && ($defaultcredits)) {
3591: if ($userlist->{$user}->[$index{'credits'}] eq '') {
3592: $userlist->{$user}->[$index{'credits'}] = $defaultcredits;
3593: }
3594: }
3595: }
3596: }
3597: if ($context eq 'author') {
3598: if (($camanagers{$user}) &&
3599: ((!defined($userlist->{$user}->[$index{'end'}])) ||
3600: ($userlist->{$user}->[$index{'end'}] == 0) ||
3601: ($userlist->{$user}->[$index{'end'}] > $now))) {
3602: $userlist->{$user}->[$index{'manager'}] = &mt('Yes');
3603: } else {
3604: $userlist->{$user}->[$index{'manager'}] = &mt('No');
3605: }
3606: }
3607: my %emails = &Apache::loncommon::getemails($uname,$udom);
3608: if ($emails{'permanentemail'} =~ /\S/) {
3609: $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
3610: }
3611: if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
3612: ($role eq 'au')) {
3613: my ($disk_quota,$current_disk_usage,$percent);
3614: if (($needauthorusage) || ($needauthorquota)) {
3615: $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author');
3616: }
3617: if ($needauthorusage) {
3618: $current_disk_usage =
3619: &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname");
3620: if ($disk_quota == 0) {
3621: $percent = 100.0;
3622: } else {
3623: $percent = $current_disk_usage/(10 * $disk_quota);
3624: }
3625: $userlist->{$user}->[$index{'authorusage'}] = sprintf("%.0f",$percent);
3626: }
3627: if ($needauthorquota) {
3628: $userlist->{$user}->[$index{'authorquota'}] = sprintf("%.2f",$disk_quota);
3629: }
3630: }
3631: $usercount ++;
3632: }
3633: my $autocount = 0;
3634: my $manualcount = 0;
3635: my $lockcount = 0;
3636: my $unlockcount = 0;
3637: if ($usercount) {
3638: $r->print($output);
3639: } else {
3640: if ($mode eq 'autoenroll') {
3641: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
3642: } else {
3643: return;
3644: }
3645: }
3646: #
3647: # Sort the users
3648: my $index = $index{$sortby};
3649: my $second = $index{'username'};
3650: my $third = $index{'domain'};
3651: my @sorted_users;
3652: if (($sortby eq 'authorquota') || ($sortby eq 'authorusage')) {
3653: @sorted_users = sort {
3654: $userlist->{$b}->[$index] <=> $userlist->{$a}->[$index] ||
3655: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
3656: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
3657: } (keys(%$userlist));
3658: } else {
3659: @sorted_users = sort {
3660: lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index]) ||
3661: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
3662: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
3663: } (keys(%$userlist));
3664: }
3665: my $rowcount = 0;
3666: my $disabled;
3667: if ($mode eq 'autoenroll') {
3668: unless ($permission->{'cusr'}) {
3669: $disabled = ' disabled="disabled"';
3670: }
3671: }
3672: foreach my $user (@sorted_users) {
3673: my %in;
3674: my $sdata = $userlist->{$user};
3675: $rowcount ++;
3676: foreach my $item (@{$keylist}) {
3677: $in{$item} = $sdata->[$index{$item}];
3678: }
3679: my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
3680: if ($clickers!~/\w/) { $clickers='-'; }
3681: $in{'clicker'} = $clickers;
3682: my $role = $in{'role'};
3683: $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
3684: unless ($mode eq 'excel') {
3685: if (! defined($in{'start'}) || $in{'start'} == 0) {
3686: $in{'start'} = &mt('none');
3687: } else {
3688: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
3689: }
3690: if (! defined($in{'end'}) || $in{'end'} == 0) {
3691: $in{'end'} = &mt('none');
3692: } else {
3693: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
3694: }
3695: }
3696: if ($context eq 'course') {
3697: my $lastlogin = $crslogins{$in{'username'}.':'.$in{'domain'}.':'.$in{'section'}.':'.$role};
3698: if ($lastlogin ne '') {
3699: $in{'lastlogin'} = &Apache::lonlocal::locallocaltime($lastlogin);
3700: }
3701: }
3702: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
3703: $r->print(&Apache::loncommon::start_data_table_row());
3704: my $checkval;
3705: if ($mode eq 'autoenroll') {
3706: my $cellentry;
3707: if ($in{'type'} eq 'auto') {
3708: $cellentry = '<b>'.&mt('auto').'</b> <label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Change').'</label>';
3709: $autocount ++;
3710: } else {
3711: $cellentry = '<table border="0" cellspacing="0"><tr><td rowspan="2"><b>'.&mt('manual').'</b></td><td><span class="LC_nobreak"><label><input type="checkbox" name="chgmanual" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Change').'</label></span></td></tr><tr><td><span class="LC_nobreak">';
3712: $manualcount ++;
3713: if ($in{'lockedtype'}) {
3714: $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Unlock').'</label>';
3715: $unlockcount ++;
3716: } else {
3717: $cellentry .= '<label><input type="checkbox" name="lockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Lock').'</label>';
3718: $lockcount ++;
3719: }
3720: $cellentry .= '</span></td></tr></table>';
3721: }
3722: $r->print("<td>$cellentry</td>\n");
3723: } else {
3724: if ($mode ne 'pickauthor') {
3725: $r->print("<td>$rowcount</td>\n");
3726: }
3727: if ($actionselect) {
3728: my $showcheckbox;
3729: if ($role =~ /^cr\//) {
3730: $showcheckbox = $canchange{'cr'};
3731: } else {
3732: $showcheckbox = $canchange{$role};
3733: }
3734: if (!$showcheckbox) {
3735: if ($context eq 'course') {
3736: if ($canchangesec{$role} ne '') {
3737: if ($canchangesec{$role} eq $in{'section'}) {
3738: $showcheckbox = 1;
3739: }
3740: }
3741: }
3742: }
3743: if ($showcheckbox) {
3744: $checkval = $user;
3745: if ($context eq 'course') {
3746: if (($role eq 'co' || $role eq 'cc') &&
3747: ($user =~ /^\Q$env{'user.name'}:$env{'user.domain'}:$role\E/)) {
3748: $showcheckbox = 0;
3749: } else {
3750: if ($role eq 'st') {
3751: $checkval .= ':st';
3752: }
3753: $checkval .= ':'.$in{'section'};
3754: if ($role eq 'st') {
3755: $checkval .= ':'.$in{'type'}.':'.
3756: $in{'lockedtype'}.':'.
3757: $in{'credits'}.':'.
3758: &escape($in{'instsec'});
3759: }
3760: }
3761: }
3762: if ($showcheckbox) {
3763: $r->print('<td><input type="checkbox" name="'.
3764: 'actionlist" value="'.
3765: &HTML::Entities::encode($checkval,'&<>"').'" />');
3766: foreach my $item ('start','end') {
3767: $r->print('<input type="hidden" name="'.
3768: &HTML::Entities::encode($checkval.'_'.$item,'&<>"').'"'.
3769: ' value="'.$sdata->[$index{$item}].'" />');
3770: }
3771: $r->print('</td>');
3772: } else {
3773: $r->print('<td> </td>');
3774: }
3775: } else {
3776: $r->print('<td> </td>');
3777: }
3778: } elsif ($mode eq 'pickauthor') {
3779: $r->print('<td><input type="button" name="chooseauthor" onclick="javascript:gochoose('."'$in{'username'}'".');" value="'.&mt('Select').'" /></td>');
3780: }
3781: }
3782: foreach my $item (@cols) {
3783: if ($item eq 'username') {
3784: $r->print('<td>'.&print_username_link($mode,\%in).'</td>');
3785: } elsif ($item eq 'status') {
3786: my $showitem = $in{$item};
3787: if (defined($ltstatus{$in{$item}})) {
3788: $showitem = $ltstatus{$in{$item}};
3789: }
3790: $r->print('<td>'.$showitem.'</td>'."\n");
3791: } elsif ($item eq 'photo') {
3792: if (($context eq 'course') && ($mode ne 'autoenroll') &&
3793: ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
3794: if ($role eq 'st') {
3795: $r->print('<td align="right"><a href="javascript:photowindow('."'".$in{'photo'}."'".')"><img src="'.$in{'thumbnail'}.'" border="1" alt="" /></a></td>');
3796: } else {
3797: $r->print('<td> </td>');
3798: }
3799: }
3800: } elsif ($item eq 'clicker') {
3801: if (($context eq 'course') && ($mode ne 'autoenroll')) {
3802: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
3803: my $clickers =
3804: (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
3805: if ($clickers!~/\w/) { $clickers='-'; }
3806: $r->print('<td>'.$clickers.'</td>');
3807: } else {
3808: $r->print('<td> </td>'."\n");
3809: }
3810: }
3811: } elsif (($item eq 'authorquota') || ($item eq 'authorusage')) {
3812: $r->print('<td align="right">'.$in{$item}.'</td>'."\n");
3813: } else {
3814: $r->print('<td>'.$in{$item}.'</td>'."\n");
3815: }
3816: }
3817: $r->print(&Apache::loncommon::end_data_table_row());
3818: } elsif ($mode eq 'csv') {
3819: next if (! defined($CSVfile));
3820: # no need to bother with $linkto
3821: my @line = ();
3822: foreach my $item (@cols) {
3823: push @line,&Apache::loncommon::csv_translate($in{$item});
3824: }
3825: print $CSVfile '"'.join('","',@line)."\"\n";
3826: } elsif ($mode eq 'excel') {
3827: my $col = 0;
3828: foreach my $item (@cols) {
3829: if ($item eq 'start' || $item eq 'end') {
3830: if ((defined($in{$item})) && ($in{$item} != 0)) {
3831: $excel_sheet->write($row,$col++,
3832: &Apache::lonstathelpers::calc_serial($in{$item}),
3833: $format->{'date'});
3834: } else {
3835: $excel_sheet->write($row,$col++,'none');
3836: }
3837: } else {
3838: $excel_sheet->write($row,$col++,$in{$item});
3839: }
3840: }
3841: $row++;
3842: }
3843: }
3844: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
3845: $r->print(&Apache::loncommon::end_data_table().'<br />');
3846: } elsif ($mode eq 'excel') {
3847: $excel_workbook->close();
3848: $r->print('<p>'.&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '<a href="'.$excel_filename.'">','</a>')."</p>\n");
3849: } elsif ($mode eq 'csv') {
3850: close($CSVfile);
3851: $r->print('<p>'.&mt('[_1]Your CSV file[_2] is ready for download.', '<a href="'.$CSVfilename.'">','</a>')."</p>\n");
3852: $r->rflush();
3853: }
3854: if ($mode eq 'autoenroll') {
3855: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
3856: } else {
3857: return ($usercount);
3858: }
3859: }
3860:
3861: sub bulkaction_javascript {
3862: my ($formname,$caller) = @_;
3863: my $docstart = 'document';
3864: if ($caller eq 'popup') {
3865: $docstart = 'opener.document';
3866: }
3867: my %lt = &Apache::lonlocal::texthash(
3868: acwi => 'Access will be set to start immediately',
3869: asyo => 'as you did not select an end date in the pop-up window',
3870: accw => 'Access will be set to continue indefinitely',
3871: asyd => 'as you did not select an end date in the pop-up window',
3872: sewi => "Sections will be switched to 'No section'",
3873: ayes => "as you either selected the 'No section' option",
3874: oryo => 'or you did not select a section in the pop-up window',
3875: arol => 'A role with no section will be added',
3876: swbs => 'Sections will be switched to:',
3877: rwba => 'Roles will be added for section(s):',
3878: );
3879: my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
3880: my $noaction = &mt("You need to select an action to take for the user(s) you have selected");
3881: my $singconfirm = &mt(' for a single user?');
3882: my $multconfirm = &mt(' for multiple users?');
3883: &js_escape(\$alert);
3884: &js_escape(\$noaction);
3885: &js_escape(\$singconfirm);
3886: &js_escape(\$multconfirm);
3887: my $output = <<"ENDJS";
3888: function verify_action (field) {
3889: var numchecked = 0;
3890: var singconf = '$singconfirm';
3891: var multconf = '$multconfirm';
3892: if ($docstart.$formname.elements[field].length > 0) {
3893: for (i=0; i<$docstart.$formname.elements[field].length; i++) {
3894: if ($docstart.$formname.elements[field][i].checked == true) {
3895: numchecked ++;
3896: }
3897: }
3898: } else {
3899: if ($docstart.$formname.elements[field].checked == true) {
3900: numchecked ++;
3901: }
3902: }
3903: if (numchecked == 0) {
3904: alert("$alert");
3905: return;
3906: } else {
3907: var message = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].text;
3908: var choice = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].value;
3909: if (choice == '') {
3910: alert("$noaction");
3911: return;
3912: } else {
3913: if (numchecked == 1) {
3914: message += singconf;
3915: } else {
3916: message += multconf;
3917: }
3918: ENDJS
3919: if ($caller ne 'popup') {
3920: $output .= <<"NEWWIN";
3921: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate' || choice == 'chgsec') {
3922: opendatebrowser(document.$formname,'$formname','go');
3923: return;
3924:
3925: } else {
3926: if (confirm(message)) {
3927: document.$formname.phase.value = 'bulkchange';
3928: document.$formname.submit();
3929: return;
3930: }
3931: }
3932: NEWWIN
3933: } else {
3934: $output .= <<"POPUP";
3935: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
3936: var datemsg = '';
3937: if (($docstart.$formname.startdate_month.value == '') &&
3938: ($docstart.$formname.startdate_day.value == '') &&
3939: ($docstart.$formname.startdate_year.value == '')) {
3940: datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
3941: }
3942: if (($docstart.$formname.enddate_month.value == '') &&
3943: ($docstart.$formname.enddate_day.value == '') &&
3944: ($docstart.$formname.enddate_year.value == '')) {
3945: datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
3946: }
3947: if (datemsg != '') {
3948: message += "\\n"+datemsg;
3949: }
3950: }
3951: if (choice == 'chgsec') {
3952: var rolefilter = $docstart.$formname.showrole.options[$docstart.$formname.showrole.selectedIndex].value;
3953: var retained = $docstart.$formname.retainsec.value;
3954: var secshow = $docstart.$formname.newsecs.value;
3955: if (secshow == '') {
3956: if (rolefilter == 'st' || retained == 0 || retained == "") {
3957: message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
3958: } else {
3959: message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
3960: }
3961: } else {
3962: if (rolefilter == 'st' || retained == 0 || retained == "") {
3963: message += "\\n\\n$lt{'swbs'} "+secshow+".\\n";
3964: } else {
3965: message += "\\n\\n$lt{'rwba'} "+secshow+".\\n";
3966: }
3967: }
3968: }
3969: if (confirm(message)) {
3970: $docstart.$formname.phase.value = 'bulkchange';
3971: $docstart.$formname.submit();
3972: window.close();
3973: }
3974: POPUP
3975: }
3976: $output .= '
3977: }
3978: }
3979: }
3980: ';
3981: return $output;
3982: }
3983:
3984: sub print_username_link {
3985: my ($mode,$in) = @_;
3986: my $output;
3987: if ($mode eq 'autoenroll') {
3988: $output = $in->{'username'};
3989: } else {
3990: $output = '<a href="javascript:username_display_launch('.
3991: "'$in->{'username'}','$in->{'domain'}'".')">'.
3992: $in->{'username'}.'</a>';
3993: }
3994: return $output;
3995: }
3996:
3997: sub role_type_names {
3998: my %lt = &Apache::lonlocal::texthash (
3999: 'domain' => 'Domain Roles',
4000: 'author' => 'Co-Author Roles',
4001: 'course' => 'Course Roles',
4002: 'community' => 'Community Roles',
4003: );
4004: return %lt;
4005: }
4006:
4007: sub select_actions {
4008: my ($context,$setting,$statusmode,$formname) = @_;
4009: my %lt = &Apache::lonlocal::texthash(
4010: revoke => "Revoke user roles",
4011: delete => "Delete user roles",
4012: reenable => "Re-enable expired user roles",
4013: activate => "Make future user roles active now",
4014: chgdates => "Change starting/ending dates",
4015: chgsec => "Change section associated with user roles",
4016: );
4017: # FIXME Add an option to change credits for student roles.
4018: my ($output,$options,%choices);
4019: # FIXME Disable actions for now for roletype=course in domain context
4020: if ($context eq 'domain' && $setting eq 'course') {
4021: return;
4022: }
4023: if ($context eq 'course') {
4024: if ($env{'form.showrole'} ne 'Any') {
4025: my $showactions;
4026: if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},
4027: $env{'request.course.id'})) {
4028: $showactions = 1;
4029: } elsif ($env{'request.course.sec'} ne '') {
4030: if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
4031: $showactions = 1;
4032: }
4033: }
4034: unless ($showactions) {
4035: unless (&is_courseowner($env{'request.course.id'},
4036: $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
4037: return;
4038: }
4039: }
4040: }
4041: }
4042: if ($statusmode eq 'Any') {
4043: $options .= '
4044: <option value="chgdates">'.$lt{'chgdates'}.'</option>';
4045: $choices{'dates'} = 1;
4046: } else {
4047: if ($statusmode eq 'Future') {
4048: $options .= '
4049: <option value="activate">'.$lt{'activate'}.'</option>';
4050: $choices{'dates'} = 1;
4051: } elsif ($statusmode eq 'Expired') {
4052: $options .= '
4053: <option value="reenable">'.$lt{'reenable'}.'</option>';
4054: $choices{'dates'} = 1;
4055: }
4056: if ($statusmode eq 'Active' || $statusmode eq 'Future') {
4057: $options .= '
4058: <option value="chgdates">'.$lt{'chgdates'}.'</option>
4059: <option value="revoke">'.$lt{'revoke'}.'</option>';
4060: $choices{'dates'} = 1;
4061: }
4062: }
4063: if ($context eq 'domain') {
4064: $options .= '
4065: <option value="delete">'.$lt{'delete'}.'</option>';
4066: }
4067: if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
4068: if (($statusmode ne 'Expired') && ($env{'request.course.sec'} eq '')) {
4069: $options .= '
4070: <option value="chgsec">'.$lt{'chgsec'}.'</option>';
4071: $choices{'sections'} = 1;
4072: }
4073: }
4074: if ($options) {
4075: $output = '<select name="bulkaction">'."\n".
4076: '<option value="" selected="selected">'.
4077: &mt('Please select').'</option>'."\n".$options."\n".'</select>';
4078: if ($choices{'dates'}) {
4079: $output .=
4080: '<input type="hidden" name="startdate_month" value="" />'."\n".
4081: '<input type="hidden" name="startdate_day" value="" />'."\n".
4082: '<input type="hidden" name="startdate_year" value="" />'."\n".
4083: '<input type="hidden" name="startdate_hour" value="" />'."\n".
4084: '<input type="hidden" name="startdate_minute" value="" />'."\n".
4085: '<input type="hidden" name="startdate_second" value="" />'."\n".
4086: '<input type="hidden" name="enddate_month" value="" />'."\n".
4087: '<input type="hidden" name="enddate_day" value="" />'."\n".
4088: '<input type="hidden" name="enddate_year" value="" />'."\n".
4089: '<input type="hidden" name="enddate_hour" value="" />'."\n".
4090: '<input type="hidden" name="enddate_minute" value="" />'."\n".
4091: '<input type="hidden" name="enddate_second" value="" />'."\n".
4092: '<input type="hidden" name="no_end_date" value="" />'."\n";
4093: if ($context eq 'course') {
4094: $output .= '<input type="hidden" name="makedatesdefault" value="" />'."\n";
4095: }
4096: }
4097: if ($choices{'sections'}) {
4098: $output .= '<input type="hidden" name="retainsec" value="" />'."\n".
4099: '<input type="hidden" name="newsecs" value="" />'."\n";
4100: }
4101: }
4102: return $output;
4103: }
4104:
4105: sub date_section_javascript {
4106: my ($context,$setting) = @_;
4107: my $title = 'Date_And_Section_Selector';
4108: my %nopopup = &Apache::lonlocal::texthash (
4109: revoke => "Check the boxes for any users for whom roles are to be revoked, and click 'Proceed'",
4110: delete => "Check the boxes for any users for whom roles are to be deleted, and click 'Proceed'",
4111: none => "Choose an action to take for selected users",
4112: );
4113: my $output = <<"ENDONE";
4114: <script type="text/javascript">
4115: // <![CDATA[
4116: function opendatebrowser(callingform,formname,calledby) {
4117: var bulkaction = callingform.bulkaction.options[callingform.bulkaction.selectedIndex].value;
4118: var url = '/adm/createuser?';
4119: var type = '';
4120: var showrole = callingform.showrole.options[callingform.showrole.selectedIndex].value;
4121: ENDONE
4122: if ($context eq 'domain') {
4123: $output .= '
4124: type = callingform.roletype.options[callingform.roletype.selectedIndex].value;
4125: ';
4126: }
4127: my $width= '700';
4128: my $height = '400';
4129: $output .= <<"ENDTWO";
4130: url += 'action=dateselect&callingform=' + formname +
4131: '&roletype='+type+'&showrole='+showrole +'&bulkaction='+bulkaction;
4132: var title = '$title';
4133: var options = 'scrollbars=1,resizable=1,menubar=0';
4134: options += ',width=$width,height=$height';
4135: stdeditbrowser = open(url,title,options,'1');
4136: stdeditbrowser.focus();
4137: }
4138: // ]]>
4139: </script>
4140: ENDTWO
4141: return $output;
4142: }
4143:
4144: sub date_section_selector {
4145: my ($context,$permission,$crstype,$showcredits) = @_;
4146: my $callingform = $env{'form.callingform'};
4147: my $formname = 'dateselect';
4148: my $groupslist = &get_groupslist();
4149: my $sec_js =
4150: &setsections_javascript($formname,$groupslist,undef,undef,$crstype,
4151: $showcredits);
4152: my $output = <<"END";
4153: <script type="text/javascript">
4154: // <![CDATA[
4155:
4156: $sec_js
4157:
4158: function saveselections(formname) {
4159:
4160: END
4161: if ($env{'form.bulkaction'} eq 'chgsec') {
4162: $output .= <<"END";
4163: if (formname.retainsec.length > 1) {
4164: for (var i=0; i<formname.retainsec.length; i++) {
4165: if (formname.retainsec[i].checked == true) {
4166: opener.document.$callingform.retainsec.value = formname.retainsec[i].value;
4167: }
4168: }
4169: } else {
4170: opener.document.$callingform.retainsec.value = formname.retainsec.value;
4171: }
4172: setSections(formname,'$crstype');
4173: if (seccheck == 'ok') {
4174: opener.document.$callingform.newsecs.value = formname.sections.value;
4175: } else {
4176: return;
4177: }
4178: END
4179: } else {
4180: if ($context eq 'course') {
4181: if (($env{'form.bulkaction'} eq 'reenable') ||
4182: ($env{'form.bulkaction'} eq 'activate') ||
4183: ($env{'form.bulkaction'} eq 'chgdates')) {
4184: if ($env{'request.course.sec'} eq '') {
4185: $output .= <<"END";
4186:
4187: if (formname.makedatesdefault.checked == true) {
4188: opener.document.$callingform.makedatesdefault.value = 1;
4189: }
4190: else {
4191: opener.document.$callingform.makedatesdefault.value = 0;
4192: }
4193:
4194: END
4195: }
4196: }
4197: }
4198: $output .= <<"END";
4199: opener.document.$callingform.startdate_month.value = formname.startdate_month.options[formname.startdate_month.selectedIndex].value;
4200: opener.document.$callingform.startdate_day.value = formname.startdate_day.value;
4201: opener.document.$callingform.startdate_year.value = formname.startdate_year.value;
4202: opener.document.$callingform.startdate_hour.value = formname.startdate_hour.options[formname.startdate_hour.selectedIndex].value;
4203: opener.document.$callingform.startdate_minute.value = formname.startdate_minute.value;
4204: opener.document.$callingform.startdate_second.value = formname.startdate_second.value;
4205: opener.document.$callingform.enddate_month.value = formname.enddate_month.options[formname.enddate_month.selectedIndex].value;
4206: opener.document.$callingform.enddate_day.value = formname.enddate_day.value;
4207: opener.document.$callingform.enddate_year.value = formname.enddate_year.value;
4208: opener.document.$callingform.enddate_hour.value = formname.enddate_hour.options[formname.enddate_hour.selectedIndex].value;
4209: opener.document.$callingform.enddate_minute.value = formname.enddate_minute.value;
4210: opener.document.$callingform.enddate_second.value = formname.enddate_second.value;
4211: if (formname.no_end_date.checked) {
4212: opener.document.$callingform.no_end_date.value = '1';
4213: } else {
4214: opener.document.$callingform.no_end_date.value = '0';
4215: }
4216: END
4217: }
4218: my $verify_action_js = &bulkaction_javascript($callingform,'popup');
4219: $output .= <<"ENDJS";
4220: verify_action('actionlist');
4221: }
4222:
4223: $verify_action_js
4224:
4225: // ]]>
4226: </script>
4227: ENDJS
4228: my %lt = &Apache::lonlocal::texthash (
4229: chac => 'Access dates to apply for selected users',
4230: chse => 'Changes in section affiliation to apply to selected users',
4231: fors => 'For student roles, changing the section will result in a section switch as students may only be in one section of a course at a time.',
4232: forn => 'For a course role that is not "student", users may have roles in more than one section at a time.',
4233: reta => "Retain each user's current section affiliations?",
4234: dnap => '(Does not apply to student roles).',
4235: );
4236: my ($date_items,$headertext);
4237: if ($env{'form.bulkaction'} eq 'chgsec') {
4238: $headertext = $lt{'chse'};
4239: } else {
4240: $headertext = $lt{'chac'};
4241: my $starttime;
4242: if (($env{'form.bulkaction'} eq 'activate') ||
4243: ($env{'form.bulkaction'} eq 'reenable')) {
4244: $starttime = time;
4245: }
4246: $date_items = &date_setting_table($starttime,undef,$context,
4247: $env{'form.bulkaction'},$formname,
4248: $permission,$crstype);
4249: }
4250: $output .= '<h3>'.$headertext.'</h3>'.
4251: '<form name="'.$formname.'" method="post" action="">'."\n".
4252: $date_items;
4253: if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
4254: my ($cnum,$cdom) = &get_course_identity();
4255: if ($crstype eq 'Community') {
4256: $lt{'fors'} = &mt('For member roles, changing the section will result in a section switch, as members may only be in one section of a community at a time.');
4257: $lt{'forn'} = &mt('For a community role that is not "member", users may have roles in more than one section at a time.');
4258: $lt{'dnap'} = &mt('(Does not apply to member roles).');
4259: }
4260: my $info;
4261: if ($env{'form.showrole'} eq 'st') {
4262: $output .= '<p>'.$lt{'fors'}.'</p>';
4263: } elsif ($env{'form.showrole'} eq 'Any') {
4264: $output .= '<p>'.$lt{'fors'}.'</p>'.
4265: '<p>'.$lt{'forn'}.' ';
4266: $info = $lt{'reta'};
4267: } else {
4268: $output .= '<p>'.$lt{'forn'}.' ';
4269: $info = $lt{'reta'};
4270: }
4271: if ($info) {
4272: $info .= '<span class="LC_nobreak">'.
4273: '<label><input type="radio" name="retainsec" value="1" '.
4274: 'checked="checked" />'.&mt('Yes').'</label> '.
4275: '<label><input type="radio" name="retainsec" value="0" />'.
4276: &mt('No').'</label></span>';
4277: if ($env{'form.showrole'} eq 'Any') {
4278: $info .= '<br />'.$lt{'dnap'};
4279: }
4280: $info .= '</p>';
4281: } else {
4282: $info = '<input type="hidden" name="retainsec" value="0" />';
4283: }
4284: my $rowtitle = &mt('New section to assign');
4285: my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,
4286: $permission,$context,'chgsec',$crstype);
4287: $output .= $info.$secbox;
4288: }
4289: $output .= '<p>'.
4290: '<input type="button" name="dateselection" value="'.&mt('Save').'" onclick="javascript:saveselections(this.form)" /></p>'."\n".
4291: '</form>';
4292: return $output;
4293: }
4294:
4295: sub section_picker {
4296: my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode,$crstype,
4297: $showcredits,$credits) = @_;
4298: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
4299: my $sections_select .= &course_sections(\%sections_count,$role);
4300: my $secbox = '<div>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
4301: if ($mode eq 'upload') {
4302: my ($options,$cb_script,$coursepick) =
4303: &default_role_selector($context,1,$crstype,$showcredits);
4304: $secbox .= &Apache::lonhtmlcommon::row_title(&mt('role'),'LC_oddrow_value').
4305: $options. &Apache::lonhtmlcommon::row_closure(1)."\n";
4306: }
4307: $secbox .= &Apache::lonhtmlcommon::row_title($rowtitle,'LC_oddrow_value')."\n";
4308: if ($env{'request.course.sec'} eq '') {
4309: $secbox .= '<table class="LC_createuser"><tr class="LC_section_row">'."\n".
4310: '<td align="center">'.&mt('Existing sections')."\n".
4311: '<br />'.$sections_select.'</td><td align="center">'.
4312: &mt('New section').'<br />'."\n".
4313: '<input type="text" name="newsec" size="15" value="" />'."\n".
4314: '<input type="hidden" name="sections" value="" />'."\n".
4315: '</td></tr></table>'."\n";
4316: } else {
4317: $secbox .= '<input type="hidden" name="sections" value="'.
4318: $env{'request.course.sec'}.'" />'.
4319: $env{'request.course.sec'};
4320: }
4321: $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n";
4322: unless ($mode eq 'chgsec') {
4323: if ($showcredits) {
4324: $secbox .=
4325: &Apache::lonhtmlcommon::row_title(&mt('credits (students)'),
4326: 'LC_evenrow_value')."\n".
4327: '<input type="text" name="credits" size="3" value="'.$credits.'" />'."\n".
4328: &Apache::lonhtmlcommon::row_closure(1)."\n";
4329: }
4330: }
4331: $secbox .= &Apache::lonhtmlcommon::end_pick_box().'</div>';
4332: return $secbox;
4333: }
4334:
4335: sub results_header_row {
4336: my ($rolefilter,$statusmode,$context,$permission,$mode,$crstype) = @_;
4337: my ($description,$showfilter);
4338: if ($rolefilter ne 'Any') {
4339: $showfilter = $rolefilter;
4340: }
4341: if ($context eq 'course') {
4342: if ($mode eq 'csv' || $mode eq 'excel') {
4343: if ($crstype eq 'Community') {
4344: $description = &mt('Community - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
4345: } else {
4346: $description = &mt('Course - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
4347: }
4348: }
4349: if ($statusmode eq 'Expired') {
4350: if ($crstype eq 'Community') {
4351: $description .= &mt('Users in community with expired [_1] roles',$showfilter);
4352: } else {
4353: $description .= &mt('Users in course with expired [_1] roles',$showfilter);
4354: }
4355: } elsif ($statusmode eq 'Future') {
4356: if ($crstype eq 'Community') {
4357: $description .= &mt('Users in community with future [_1] roles',$showfilter);
4358: } else {
4359: $description .= &mt('Users in course with future [_1] roles',$showfilter);
4360: }
4361: } elsif ($statusmode eq 'Active') {
4362: if ($crstype eq 'Community') {
4363: $description .= &mt('Users in community with active [_1] roles',$showfilter);
4364: } else {
4365: $description .= &mt('Users in course with active [_1] roles',$showfilter);
4366: }
4367: } else {
4368: if ($rolefilter eq 'Any') {
4369: if ($crstype eq 'Community') {
4370: $description .= &mt('All users in community');
4371: } else {
4372: $description .= &mt('All users in course');
4373: }
4374: } else {
4375: if ($crstype eq 'Community') {
4376: $description .= &mt('All users in community with [_1] roles',$rolefilter);
4377: } else {
4378: $description .= &mt('All users in course with [_1] roles',$rolefilter);
4379: }
4380: }
4381: }
4382: my $constraint;
4383: my $viewablesec = &viewable_section($permission);
4384: if ($viewablesec ne '') {
4385: if ($env{'form.showrole'} eq 'st') {
4386: $constraint = &mt('only users in section "[_1]"',$viewablesec);
4387: } elsif (($env{'form.showrole'} ne 'cc') && ($env{'form.showrole'} ne 'co')) {
4388: $constraint = &mt('only users affiliated with no section or section "[_1]"',$viewablesec);
4389: }
4390: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
4391: if ($env{'form.grpfilter'} eq 'none') {
4392: $constraint .= &mt(' and not in any group');
4393: } else {
4394: $constraint .= &mt(' and members of group: "[_1]"',$env{'form.grpfilter'});
4395: }
4396: }
4397: } else {
4398: if (($env{'form.secfilter'} ne 'all') && ($env{'form.secfilter'} ne '')) {
4399: if ($env{'form.secfilter'} eq 'none') {
4400: $constraint = &mt('only users affiliated with no section');
4401: } else {
4402: $constraint = &mt('only users affiliated with section "[_1]"',$env{'form.secfilter'});
4403: }
4404: }
4405: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
4406: if ($env{'form.grpfilter'} eq 'none') {
4407: if ($constraint eq '') {
4408: $constraint = &mt('only users not in any group');
4409: } else {
4410: $constraint .= &mt(' and also not in any group');
4411: }
4412: } else {
4413: if ($constraint eq '') {
4414: $constraint = &mt('only members of group: "[_1]"',$env{'form.grpfilter'});
4415: } else {
4416: $constraint .= &mt(' and also members of group: "[_1]"'.$env{'form.grpfilter'});
4417: }
4418: }
4419: }
4420: }
4421: if ($constraint ne '') {
4422: $description .= ' ('.$constraint.')';
4423: }
4424: } elsif ($context eq 'author') {
4425: $description =
4426: &mt('Author space for [_1]'
4427: ,'<span class="LC_cusr_emph">'
4428: .&Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'})
4429: .'</span>')
4430: .': ';
4431: if ($statusmode eq 'Expired') {
4432: $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
4433: } elsif ($statusmode eq 'Future') {
4434: $description .= &mt('Co-authors with future [_1] roles',$showfilter);
4435: } elsif ($statusmode eq 'Active') {
4436: $description .= &mt('Co-authors with active [_1] roles',$showfilter);
4437: } else {
4438: if ($rolefilter eq 'Any') {
4439: $description .= &mt('All co-authors');
4440: } else {
4441: $description .= &mt('All co-authors with [_1] roles',$rolefilter);
4442: }
4443: }
4444: } elsif ($context eq 'domain') {
4445: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
4446: $description = &mt('Domain - [_1]:',$domdesc).' ';
4447: if ($env{'form.roletype'} eq 'domain') {
4448: if ($statusmode eq 'Expired') {
4449: $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
4450: } elsif ($statusmode eq 'Future') {
4451: $description .= &mt('Users in domain with future [_1] roles',$showfilter);
4452: } elsif ($statusmode eq 'Active') {
4453: $description .= &mt('Users in domain with active [_1] roles',$showfilter);
4454: } else {
4455: if ($rolefilter eq 'Any') {
4456: $description .= &mt('All users in domain');
4457: } else {
4458: $description .= &mt('All users in domain with [_1] roles',$rolefilter);
4459: }
4460: }
4461: } elsif ($env{'form.roletype'} eq 'author') {
4462: if ($statusmode eq 'Expired') {
4463: $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
4464: } elsif ($statusmode eq 'Future') {
4465: $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
4466: } elsif ($statusmode eq 'Active') {
4467: $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
4468: } else {
4469: if ($rolefilter eq 'Any') {
4470: $description .= &mt('All users with co-author roles in domain',$showfilter);
4471: } else {
4472: $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
4473: }
4474: }
4475: } elsif (($env{'form.roletype'} eq 'course') ||
4476: ($env{'form.roletype'} eq 'community')) {
4477: my $coursefilter = $env{'form.coursepick'};
4478: if ($env{'form.roletype'} eq 'course') {
4479: if ($coursefilter eq 'category') {
4480: my $instcode = &instcode_from_coursefilter();
4481: if ($instcode eq '.') {
4482: $description .= &mt('All courses in domain').' - ';
4483: } else {
4484: $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
4485: }
4486: } elsif ($coursefilter eq 'selected') {
4487: $description .= &mt('Selected courses in domain').' - ';
4488: } elsif ($coursefilter eq 'all') {
4489: $description .= &mt('All courses in domain').' - ';
4490: }
4491: } elsif ($env{'form.roletype'} eq 'community') {
4492: if ($coursefilter eq 'selected') {
4493: $description .= &mt('Selected communities in domain').' - ';
4494: } elsif ($coursefilter eq 'all') {
4495: $description .= &mt('All communities in domain').' - ';
4496: }
4497: }
4498: if ($statusmode eq 'Expired') {
4499: $description .= &mt('users with expired [_1] roles',$showfilter);
4500: } elsif ($statusmode eq 'Future') {
4501: $description .= &mt('users with future [_1] roles',$showfilter);
4502: } elsif ($statusmode eq 'Active') {
4503: $description .= &mt('users with active [_1] roles',$showfilter);
4504: } else {
4505: if ($rolefilter eq 'Any') {
4506: $description .= &mt('all users');
4507: } else {
4508: $description .= &mt('users with [_1] roles',$rolefilter);
4509: }
4510: }
4511: }
4512: }
4513: return $description;
4514: }
4515:
4516: sub viewable_section {
4517: my ($permission) = @_;
4518: my $viewablesec;
4519: if (ref($permission) eq 'HASH') {
4520: if (exists($permission->{'view_section'})) {
4521: $viewablesec = $permission->{'view_section'};
4522: } elsif (exists($permission->{'cusr_section'})) {
4523: $viewablesec = $permission->{'cusr_section'};
4524: }
4525: }
4526: return $viewablesec;
4527: }
4528:
4529:
4530: #################################################
4531: #################################################
4532: sub show_drop_list {
4533: my ($r,$classlist,$nosort,$permission,$crstype) = @_;
4534: my $cid = $env{'request.course.id'};
4535: my ($cnum,$cdom) = &get_course_identity($cid);
4536: if (! exists($env{'form.sortby'})) {
4537: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
4538: ['sortby']);
4539: }
4540: my $sortby = $env{'form.sortby'};
4541: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
4542: $sortby = 'username';
4543: }
4544: my $action = "drop";
4545: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
4546: $r->print(<<END);
4547: <input type="hidden" name="sortby" value="$sortby" />
4548: <input type="hidden" name="action" value="$action" />
4549: <input type="hidden" name="state" value="done" />
4550: <script type="text/javascript" language="Javascript">
4551: // <![CDATA[
4552: $check_uncheck_js
4553: // ]]>
4554: </script>
4555: <input type="hidden" name="phase" value="four" />
4556: END
4557: my ($indexhash,$keylist) = &make_keylist_array();
4558: my $studentcount = 0;
4559: if (ref($classlist) eq 'HASH') {
4560: foreach my $student (keys(%{$classlist})) {
4561: my $sdata = $classlist->{$student};
4562: my $status = $sdata->[$indexhash->{'status'}];
4563: my $section = $sdata->[$indexhash->{'section'}];
4564: if ($status ne 'Active') {
4565: delete($classlist->{$student});
4566: next;
4567: }
4568: if ($env{'request.course.sec'} ne '') {
4569: if ($section ne $env{'request.course.sec'}) {
4570: delete($classlist->{$student});
4571: next;
4572: }
4573: }
4574: $studentcount ++;
4575: }
4576: }
4577: if (!$studentcount) {
4578: my $msg = '';
4579: if ($crstype eq 'Community') {
4580: $msg = &mt('There are no members to drop.');
4581: } else {
4582: $msg = &mt('There are no students to drop.');
4583: }
4584: $r->print('<p class="LC_info">'.$msg.'</p>');
4585: return;
4586: }
4587: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
4588: $classlist,$keylist,$cdom,$cnum);
4589: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
4590: 'dom' => "domain",
4591: 'id' => "ID",
4592: 'sn' => "student name",
4593: 'mn' => "member name",
4594: 'sec' => "section",
4595: 'start' => "start date",
4596: 'end' => "end date",
4597: 'groups' => "active groups",
4598: );
4599: my $nametitle = $lt{'sn'};
4600: if ($crstype eq 'Community') {
4601: $nametitle = $lt{'mn'};
4602: }
4603: if ($nosort) {
4604: $r->print(&Apache::loncommon::start_data_table().
4605: &Apache::loncommon::start_data_table_header_row());
4606: $r->print(<<END);
4607: <th> </th>
4608: <th>$lt{'usrn'}</th>
4609: <th>$lt{'dom'}</th>
4610: <th>$lt{'id'}</th>
4611: <th>$nametitle</th>
4612: <th>$lt{'sec'}</th>
4613: <th>$lt{'start'}</th>
4614: <th>$lt{'end'}</th>
4615: <th>$lt{'groups'}</th>
4616: END
4617: $r->print(&Apache::loncommon::end_data_table_header_row());
4618: } else {
4619: $r->print(&Apache::loncommon::start_data_table().
4620: &Apache::loncommon::start_data_table_header_row());
4621: $r->print(<<END);
4622: <th> </th>
4623: <th>
4624: <a href="/adm/createuser?action=$action&sortby=username">$lt{'usrn'}</a>
4625: </th><th>
4626: <a href="/adm/createuser?action=$action&sortby=domain">$lt{'dom'}</a>
4627: </th><th>
4628: <a href="/adm/createuser?action=$action&sortby=id">$lt{'id'}</a>
4629: </th><th>
4630: <a href="/adm/createuser?action=$action&sortby=fullname">$nametitle</a>
4631: </th><th>
4632: <a href="/adm/createuser?action=$action&sortby=section">$lt{'sec'}</a>
4633: </th><th>
4634: <a href="/adm/createuser?action=$action&sortby=start">$lt{'start'}</a>
4635: </th><th>
4636: <a href="/adm/createuser?action=$action&sortby=end">$lt{'end'}</a>
4637: </th><th>
4638: <a href="/adm/createuser?action=$action&sortby=groups">$lt{'groups'}</a>
4639: </th>
4640: END
4641: $r->print(&Apache::loncommon::end_data_table_header_row());
4642: }
4643: #
4644: # Sort the students
4645: my $index = $indexhash->{$sortby};
4646: my $second = $indexhash->{'username'};
4647: my $third = $indexhash->{'domain'};
4648: my @Sorted_Students = sort {
4649: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
4650: ||
4651: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
4652: ||
4653: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
4654: } (keys(%{$classlist}));
4655: foreach my $student (@Sorted_Students) {
4656: my $error;
4657: my $sdata = $classlist->{$student};
4658: my $username = $sdata->[$indexhash->{'username'}];
4659: my $domain = $sdata->[$indexhash->{'domain'}];
4660: my $section = $sdata->[$indexhash->{'section'}];
4661: my $name = $sdata->[$indexhash->{'fullname'}];
4662: my $id = $sdata->[$indexhash->{'id'}];
4663: my $start = $sdata->[$indexhash->{'start'}];
4664: my $end = $sdata->[$indexhash->{'end'}];
4665: my $groups = $classgroups->{$student};
4666: my $active_groups;
4667: if (ref($groups->{active}) eq 'HASH') {
4668: $active_groups = join(', ',keys(%{$groups->{'active'}}));
4669: }
4670: if (! defined($start) || $start == 0) {
4671: $start = &mt('none');
4672: } else {
4673: $start = &Apache::lonlocal::locallocaltime($start);
4674: }
4675: if (! defined($end) || $end == 0) {
4676: $end = &mt('none');
4677: } else {
4678: $end = &Apache::lonlocal::locallocaltime($end);
4679: }
4680: my $studentkey = $student.':'.$section;
4681: my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$indexhash->{'start'}].'" />';
4682: #
4683: $r->print(&Apache::loncommon::start_data_table_row());
4684: $r->print(<<"END");
4685: <td><input type="checkbox" name="droplist" value="$studentkey" /></td>
4686: <td>$username</td>
4687: <td>$domain</td>
4688: <td>$id</td>
4689: <td>$name</td>
4690: <td>$section</td>
4691: <td>$start $startitem</td>
4692: <td>$end</td>
4693: <td>$active_groups</td>
4694: END
4695: $r->print(&Apache::loncommon::end_data_table_row());
4696: }
4697: $r->print(&Apache::loncommon::end_data_table().'<br />');
4698: %lt=&Apache::lonlocal::texthash(
4699: 'dp' => "Drop Students",
4700: 'dm' => "Drop Members",
4701: 'ca' => "check all",
4702: 'ua' => "uncheck all",
4703: );
4704: my $btn = $lt{'dp'};
4705: if ($crstype eq 'Community') {
4706: $btn = $lt{'dm'};
4707: }
4708: $r->print(<<"END");
4709: <p>
4710: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)" />
4711: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)" />
4712: </p>
4713: <p>
4714: <input type="submit" value="$btn" />
4715: </p>
4716: END
4717: return;
4718: }
4719:
4720: #
4721: # Print out the initial form to get the file containing a list of users
4722: #
4723: sub print_first_users_upload_form {
4724: my ($r,$context) = @_;
4725: my $str;
4726: $str = '<input type="hidden" name="phase" value="two" />';
4727: $str .= '<input type="hidden" name="action" value="upload" />';
4728: $str .= '<input type="hidden" name="state" value="got_file" />';
4729:
4730: $str .= &Apache::grades::checkforfile_js();
4731:
4732: $str .= '<h2>'.&mt('Upload a file containing information about users').'</h2>'."\n";
4733:
4734: # Excel and CSV Help
4735: $str .= '<div class="LC_columnSection">'
4736: .&Apache::loncommon::help_open_topic("Course_Create_Class_List",
4737: &mt("How do I create a users list from a spreadsheet"))
4738: .' '.&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
4739: &mt("How do I create a CSV file from a spreadsheet"))
4740: ."</div>\n";
4741: $str .= &Apache::lonhtmlcommon::start_pick_box()
4742: .&Apache::lonhtmlcommon::row_title(&mt('File'));
4743: if (&Apache::lonlocal::current_language() ne 'en') {
4744: if ($context eq 'course') {
4745: $str .= '<p class="LC_info">'."\n"
4746: .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n"
4747: .'</p>'."\n";
4748: }
4749: }
4750: $str .= &Apache::loncommon::upfile_select_html()
4751: .&Apache::lonhtmlcommon::row_closure()
4752: .&Apache::lonhtmlcommon::row_title(
4753: '<label for="noFirstLine">'
4754: .&mt('Ignore First Line')
4755: .'</label>')
4756: .'<input type="checkbox" name="noFirstLine" id="noFirstLine" />'
4757: .&Apache::lonhtmlcommon::row_closure(1)
4758: .&Apache::lonhtmlcommon::end_pick_box();
4759:
4760: $str .= '<p>'
4761: .'<input type="button" name="fileupload" value="'.&mt('Next').'"'
4762: .' onclick="javascript:checkUpload(this.form);" />'
4763: .'</p>';
4764:
4765: $r->print($str);
4766: return;
4767: }
4768:
4769: # ================================================= Drop/Add from uploaded file
4770: sub upfile_drop_add {
4771: my ($r,$context,$permission,$showcredits) = @_;
4772: my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'});
4773: if ($datatoken ne '') {
4774: &Apache::loncommon::load_tmp_file($r,$datatoken);
4775: }
4776: my @userdata=&Apache::loncommon::upfile_record_sep();
4777: if($env{'form.noFirstLine'}){shift(@userdata);}
4778: my @keyfields = split(/\,/,$env{'form.keyfields'});
4779: my %fields=();
4780: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
4781: if ($env{'form.upfile_associate'} eq 'reverse') {
4782: if ($env{'form.f'.$i} ne 'none') {
4783: $fields{$keyfields[$i]}=$env{'form.f'.$i};
4784: }
4785: } else {
4786: $fields{$env{'form.f'.$i}}=$keyfields[$i];
4787: }
4788: }
4789: #
4790: # Store the field choices away
4791: my @storefields = qw/username names fname mname lname gen id
4792: sec ipwd email role domain inststatus/;
4793: if ($showcredits) {
4794: push (@storefields,'credits');
4795: }
4796: my %fieldstype;
4797: foreach my $field (@storefields) {
4798: $env{'form.'.$field.'_choice'}=$fields{$field};
4799: $fieldstype{$field.'_choice'} = 'scalar';
4800: }
4801: &Apache::loncommon::store_course_settings('enrollment_upload',\%fieldstype);
4802: my ($cid,$crstype,$setting,$crsdom,$crsnum,$oldcrsuserdoms,%emptyok);
4803: if ($context eq 'domain') {
4804: $setting = $env{'form.roleaction'};
4805: if (exists($fields{'names'})) {
4806: map { $emptyok{$_} = 1; } ('lastname','firstname','middlename');
4807: } else {
4808: if (exists($fields{'lname'})) {
4809: $emptyok{'lastname'} = 1;
4810: }
4811: if (exists($fields{'fname'})) {
4812: $emptyok{'firstname'} = 1;
4813: }
4814: if (exists($fields{'mname'})) {
4815: $emptyok{'middlename'} = 1;
4816: }
4817: }
4818: if (exists($fields{'gen'})) {
4819: $emptyok{'generation'} = 1;
4820: }
4821: }
4822: if ($env{'request.course.id'} ne '') {
4823: $cid = $env{'request.course.id'};
4824: $crstype = &Apache::loncommon::course_type();
4825: $crsdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4826: $crsnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4827: } elsif ($setting eq 'course') {
4828: if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
4829: $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
4830: $crstype = &Apache::loncommon::course_type($cid);
4831: $crsdom = $env{'form.dcdomain'};
4832: $crsnum = $env{'form.dccourse'};
4833: if (exists($env{'course.'.$cid.'.internal.userdomains'})) {
4834: $oldcrsuserdoms = 1;
4835: }
4836: my %coursedesc = &Apache::lonnet::coursedescription($cid,{ one_time => 1 });
4837: $env{'course.'.$cid.'.internal.userdomains'} = $coursedesc{'internal.userdomains'};
4838: }
4839: }
4840: my ($startdate,$enddate) = &get_dates_from_form();
4841: if ($env{'form.makedatesdefault'}) {
4842: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
4843: }
4844: # Determine domain and desired host (home server)
4845: my $defdom=$env{'request.role.domain'};
4846: my $domain;
4847: if ($env{'form.defaultdomain'} ne '') {
4848: if (($context eq 'course') || ($setting eq 'course')) {
4849: if ($env{'form.defaultdomain'} eq $crsdom) {
4850: $domain = $env{'form.defaultdomain'};
4851: } else {
4852: if (&Apache::lonnet::will_trust('enroll',$crsdom,$env{'form.defaultdomain'})) {
4853: $domain = $env{'form.defaultdomain'};
4854: } else {
4855: $r->print('<span class="LC_error">'.&mt('Error').': '.
4856: &mt('Enrollment of users not permitted for specified default domain: [_1].',
4857: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
4858: return 'untrusted';
4859: }
4860: }
4861: } elsif ($context eq 'author') {
4862: if ($env{'form.defaultdomain'} eq $defdom) {
4863: $domain = $env{'form.defaultdomain'};
4864: } else {
4865: if ((&Apache::lonnet::will_trust('othcoau',$defdom,$env{'form.defaultdomain'})) &&
4866: (&Apache::lonnet::will_trust('coaurem',$env{'form.defaultdomain'},$defdom))) {
4867: $domain = $env{'form.defaultdomain'};
4868: } else {
4869: $r->print('<span class="LC_error">'.&mt('Error').': '.
4870: &mt('Addition of users not permitted for specified default domain: [_1].',
4871: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
4872: return 'untrusted';
4873: }
4874: }
4875: } elsif (($context eq 'domain') && ($setting eq 'domain')) {
4876: if ($env{'form.defaultdomain'} eq $defdom) {
4877: $domain = $env{'form.defaultdomain'};
4878: } else {
4879: if (&Apache::lonnet::will_trust('domroles',$defdom,$env{'form.defaultdomain'})) {
4880: $domain = $env{'form.defaultdomain'};
4881: } else {
4882: $r->print('<span class="LC_error">'.&mt('Error').': '.
4883: &mt('Addition of users not permitted for specified default domain: [_1].',
4884: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
4885: return 'untrusted';
4886: }
4887: }
4888: }
4889: } else {
4890: $domain = $defdom;
4891: }
4892: my $desiredhost = $env{'form.lcserver'};
4893: if (lc($desiredhost) eq 'default') {
4894: $desiredhost = undef;
4895: } else {
4896: my %home_servers = &Apache::lonnet::get_servers($defdom,'library');
4897: if (! exists($home_servers{$desiredhost})) {
4898: $r->print('<p class="LC_error">'.&mt('Error').': '.
4899: &mt('Invalid home server specified').'</p>');
4900: return 'invalidhome';
4901: }
4902: }
4903: # Determine authentication mechanism
4904: my $changeauth;
4905: if ($context eq 'domain') {
4906: $changeauth = $env{'form.changeauth'};
4907: }
4908: my $amode = '';
4909: my $genpwd = '';
4910: my @genpwdfail;
4911: if ($env{'form.login'} eq 'krb') {
4912: $amode='krb';
4913: $amode.=$env{'form.krbver'};
4914: $genpwd=$env{'form.krbarg'};
4915: } elsif ($env{'form.login'} eq 'int') {
4916: $amode='internal';
4917: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
4918: $genpwd=$env{'form.intarg'};
4919: @genpwdfail =
4920: &Apache::loncommon::check_passwd_rules($domain,$genpwd);
4921: }
4922: } elsif ($env{'form.login'} eq 'loc') {
4923: $amode='localauth';
4924: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
4925: $genpwd=$env{'form.locarg'};
4926: }
4927: } elsif ($env{'form.login'} eq 'lti') {
4928: $amode='lti';
4929: }
4930: if ($amode =~ /^krb/) {
4931: if (! defined($genpwd) || $genpwd eq '') {
4932: $r->print('<span class="Error">'.
4933: &mt('Unable to enroll users').' '.
4934: &mt('No Kerberos domain was specified.').'</span></p>');
4935: $amode = ''; # This causes the loop below to be skipped
4936: }
4937: }
4938: my ($defaultsec,$defaultrole,$defaultcredits,$commoncredits);
4939: if ($context eq 'domain') {
4940: if ($setting eq 'domain') {
4941: $defaultrole = $env{'form.defaultrole'};
4942: } elsif ($setting eq 'course') {
4943: $defaultrole = $env{'form.courserole'};
4944: $defaultsec = $env{'form.sections'};
4945: if ($showcredits) {
4946: $commoncredits = $env{'form.credits'};
4947: if ($crstype ne 'Community') {
4948: my %coursehash=&Apache::lonnet::coursedescription($cid);
4949: $defaultcredits = $coursehash{'internal.defaultcredits'};
4950: }
4951: }
4952: }
4953: } elsif ($context eq 'author') {
4954: $defaultrole = $env{'form.defaultrole'};
4955: } elsif ($context eq 'course') {
4956: $defaultrole = $env{'form.defaultrole'};
4957: $defaultsec = $env{'form.sections'};
4958: if ($showcredits) {
4959: $commoncredits = $env{'form.credits'};
4960: $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
4961: }
4962: }
4963: # Check to see if user information can be changed
4964: my @userinfo = ('firstname','middlename','lastname','generation',
4965: 'permanentemail','id');
4966: my %canmodify;
4967: if (&Apache::lonnet::allowed('mau',$domain)) {
4968: push(@userinfo,'inststatus');
4969: foreach my $field (@userinfo) {
4970: $canmodify{$field} = 1;
4971: }
4972: }
4973: my (%userlist,%modifiable_fields,@poss_roles);
4974: my $secidx = &Apache::loncoursedata::CL_SECTION();
4975: my @courseroles = &roles_by_context('course',1,$crstype);
4976: if (!&Apache::lonnet::allowed('mau',$domain)) {
4977: if ($context eq 'course' || $context eq 'author') {
4978: @poss_roles = &curr_role_permissions($context,'','',$crstype);
4979: my @statuses = ('active','future');
4980: my ($indexhash,$keylist) = &make_keylist_array();
4981: my %info;
4982: foreach my $role (@poss_roles) {
4983: %{$modifiable_fields{$role}} = &can_modify_userinfo($context,$domain,
4984: \@userinfo,[$role]);
4985: }
4986: if ($context eq 'course') {
4987: my ($cnum,$cdom) = &get_course_identity();
4988: my $roster = &Apache::loncoursedata::get_classlist();
4989: if (ref($roster) eq 'HASH') {
4990: %userlist = %{$roster};
4991: }
4992: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
4993: \@statuses,\@poss_roles);
4994: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
4995: \%advrolehash,$permission);
4996: } elsif ($context eq 'author') {
4997: my %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
4998: \@statuses,\@poss_roles);
4999: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
5000: \%cstr_roles,$permission);
5001: }
5002: }
5003: }
5004: if ($datatoken eq '') {
5005: $r->print('<p class="LC_error">'.&mt('Error').': '.
5006: &mt('Invalid datatoken').'</p>');
5007: return 'missingdata';
5008: }
5009: if ( $domain eq &LONCAPA::clean_domain($domain)
5010: && ($amode ne '')) {
5011: #######################################
5012: ## Add/Modify Users ##
5013: #######################################
5014: if ($context eq 'course') {
5015: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
5016: } elsif ($context eq 'author') {
5017: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
5018: } else {
5019: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
5020: }
5021: $r->rflush;
5022: my (%got_role_approvals,%got_instdoms,%process_by,%instdoms,
5023: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
5024:
5025: my %counts = (
5026: user => 0,
5027: auth => 0,
5028: role => 0,
5029: );
5030: my $flushc=0;
5031: my %student=();
5032: my (%curr_groups,@sections,@cleansec,$defaultwarn,$groupwarn);
5033: my %userchg;
5034: if ($context eq 'course' || $setting eq 'course') {
5035: if ($context eq 'course') {
5036: # Get information about course groups
5037: %curr_groups = &Apache::longroup::coursegroups();
5038: } elsif ($setting eq 'course') {
5039: if ($cid) {
5040: %curr_groups =
5041: &Apache::longroup::coursegroups($env{'form.dcdomain'},
5042: $env{'form.dccourse'});
5043: }
5044: }
5045: # determine section number
5046: if ($defaultsec =~ /,/) {
5047: push(@sections,split(/,/,$defaultsec));
5048: } else {
5049: push(@sections,$defaultsec);
5050: }
5051: # remove non alphanumeric values from section
5052: foreach my $item (@sections) {
5053: $item =~ s/\W//g;
5054: if ($item eq "none" || $item eq 'all') {
5055: $defaultwarn = &mt('Default section name [_1] could not be used as it is a reserved word.',$item);
5056: } elsif ($item ne '' && exists($curr_groups{$item})) {
5057: $groupwarn = &mt('Default section name "[_1]" is the name of a course group. Section names and group names must be distinct.',$item);
5058: } elsif ($item ne '') {
5059: push(@cleansec,$item);
5060: }
5061: }
5062: if ($defaultwarn) {
5063: $r->print($defaultwarn.'<br />');
5064: }
5065: if ($groupwarn) {
5066: $r->print($groupwarn.'<br />');
5067: }
5068: }
5069: my (%curr_rules,%got_rules,%alerts,%cancreate);
5070: my %customroles = &my_custom_roles($crstype);
5071: my @permitted_roles =
5072: &roles_on_upload($context,$setting,$crstype,%customroles);
5073: my %longtypes = &Apache::lonlocal::texthash(
5074: official => 'Institutional',
5075: unofficial => 'Non-institutional',
5076: );
5077: my $newuserdom = $env{'request.role.domain'};
5078: map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes);
5079: # Get new users list
5080: my (%existinguser,%userinfo,%disallow,%rulematch,%inst_results,%alerts,%checkuname,
5081: %showpasswdrules,$haspasswdmap);
5082: my $counter = -1;
5083: my (%willtrust,%trustchecked);
5084: foreach my $line (@userdata) {
5085: $counter ++;
5086: my @secs;
5087: my %entries=&Apache::loncommon::record_sep($line);
5088: # Determine user name
5089: $entries{$fields{'username'}} =~ s/^\s+|\s+$//g;
5090: unless (($entries{$fields{'username'}} eq '') ||
5091: (!defined($entries{$fields{'username'}}))) {
5092: my ($fname, $mname, $lname,$gen) = ('','','','');
5093: if (defined($fields{'names'})) {
5094: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
5095: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
5096: } else {
5097: if (defined($fields{'fname'})) {
5098: $fname=$entries{$fields{'fname'}};
5099: }
5100: if (defined($fields{'mname'})) {
5101: $mname=$entries{$fields{'mname'}};
5102: }
5103: if (defined($fields{'lname'})) {
5104: $lname=$entries{$fields{'lname'}};
5105: }
5106: if (defined($fields{'gen'})) {
5107: $gen=$entries{$fields{'gen'}};
5108: }
5109: }
5110:
5111: if ($entries{$fields{'username'}}
5112: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
5113: my $nowhitespace;
5114: if ($entries{$fields{'username'}} =~ /\s/) {
5115: $nowhitespace = ' - '.&mt('usernames may not contain spaces.');
5116: }
5117: $disallow{$counter} =
5118: &mt('Unacceptable username [_1] for user [_2] [_3] [_4] [_5]',
5119: '"<b>'.$entries{$fields{'username'}}.'</b>"',
5120: $fname,$mname,$lname,$gen).$nowhitespace;
5121: next;
5122: } else {
5123: $entries{$fields{'domain'}} =~ s/^\s+|\s+$//g;
5124: if ($entries{$fields{'domain'}}
5125: ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
5126: $disallow{$counter} =
5127: &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
5128: '"<b>'.$entries{$fields{'domain'}}.'</b>"',
5129: $fname,$mname,$lname,$gen);
5130: next;
5131: } elsif ($entries{$fields{'domain'}} ne $domain) {
5132: my $possdom = $entries{$fields{'domain'}};
5133: if ($context eq 'course' || $setting eq 'course') {
5134: unless ($trustchecked{$possdom}) {
5135: $willtrust{$possdom} = &Apache::lonnet::will_trust('enroll',$domain,$possdom);
5136: $trustchecked{$possdom} = 1;
5137: }
5138: } elsif ($context eq 'author') {
5139: unless ($trustchecked{$possdom}) {
5140: $willtrust{$possdom} = &Apache::lonnet::will_trust('othcoau',$domain,$possdom);
5141: }
5142: if ($willtrust{$possdom}) {
5143: $willtrust{$possdom} = &Apache::lonnet::will_trust('coaurem',$possdom,$domain);
5144: }
5145: }
5146: unless ($willtrust{$possdom}) {
5147: $disallow{$counter} =
5148: &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
5149: '"<b>'.$possdom.'</b>"',
5150: $fname,$mname,$lname,$gen);
5151: next;
5152: }
5153: }
5154: my $username = $entries{$fields{'username'}};
5155: my $userdomain = $entries{$fields{'domain'}};
5156: if ($userdomain eq '') {
5157: $userdomain = $domain;
5158: }
5159: if (defined($fields{'sec'})) {
5160: if (defined($entries{$fields{'sec'}})) {
5161: $entries{$fields{'sec'}} =~ s/\W//g;
5162: my $item = $entries{$fields{'sec'}};
5163: if ($item eq "none" || $item eq 'all') {
5164: $disallow{$counter} =
5165: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a reserved word.',
5166: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item);
5167: next;
5168: } elsif (exists($curr_groups{$item})) {
5169: $disallow{$counter} =
5170: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a course group.',
5171: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item).' '.
5172: &mt('Section names and group names must be distinct.');
5173: next;
5174: } else {
5175: push(@secs,$item);
5176: }
5177: }
5178: }
5179: if ($env{'request.course.sec'} ne '') {
5180: @secs = ($env{'request.course.sec'});
5181: if (ref($userlist{$username.':'.$userdomain}) eq 'ARRAY') {
5182: my $currsec = $userlist{$username.':'.$userdomain}[$secidx];
5183: if ($currsec ne $env{'request.course.sec'}) {
5184: $disallow{$counter} =
5185: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]".',
5186: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$secs[0]);
5187: if ($currsec eq '') {
5188: $disallow{$counter} .=
5189: &mt('This user already has an active/future student role in the course, unaffiliated to any section.');
5190:
5191: } else {
5192: $disallow{$counter} .=
5193: &mt('This user already has an active/future role in section "[_1]" of the course.',$currsec);
5194: }
5195: $disallow{$counter} .=
5196: '<br />'.
5197: &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments in other sections.',
5198: $secs[0]);
5199: next;
5200: }
5201: }
5202: } elsif ($context eq 'course' || $setting eq 'course') {
5203: if (@secs == 0) {
5204: @secs = @cleansec;
5205: }
5206: }
5207: # determine id number
5208: my $id='';
5209: if (defined($fields{'id'})) {
5210: if (defined($entries{$fields{'id'}})) {
5211: $id=$entries{$fields{'id'}};
5212: }
5213: $id=~tr/A-Z/a-z/;
5214: }
5215: # determine email address
5216: my $email='';
5217: if (defined($fields{'email'})) {
5218: $entries{$fields{'email'}} =~ s/^\s+|\s+$//g;
5219: if (defined($entries{$fields{'email'}})) {
5220: $email=$entries{$fields{'email'}};
5221: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
5222: }
5223: }
5224: # determine affiliation
5225: my $inststatus='';
5226: if (defined($fields{'inststatus'})) {
5227: if (defined($entries{$fields{'inststatus'}})) {
5228: $inststatus=$entries{$fields{'inststatus'}};
5229: }
5230: }
5231: # determine user password
5232: my $password;
5233: my $passwdfromfile;
5234: if (defined($fields{'ipwd'})) {
5235: if ($entries{$fields{'ipwd'}}) {
5236: $password=$entries{$fields{'ipwd'}};
5237: $passwdfromfile = 1;
5238: if ($env{'form.login'} eq 'int') {
5239: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
5240: if (($uhome eq 'no_host') || ($changeauth)) {
5241: my @brokepwdrules =
5242: &Apache::loncommon::check_passwd_rules($domain,$password);
5243: if (@brokepwdrules) {
5244: $disallow{$counter} = &mt('[_1]: Password included in file for this user did not meet requirements.',
5245: '<b>'.$username.'</b>');
5246: map { $showpasswdrules{$_} = 1; } @brokepwdrules;
5247: next;
5248: }
5249: }
5250: }
5251: }
5252: }
5253: unless ($passwdfromfile) {
5254: if ($env{'form.login'} eq 'int') {
5255: if (@genpwdfail) {
5256: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
5257: if (($uhome eq 'no_host') || ($changeauth)) {
5258: $disallow{$counter} = &mt('[_1]: No specific password in file for this user; default password did not meet requirements',
5259: '<b>'.$username.'</b>');
5260: unless ($haspasswdmap) {
5261: map { $showpasswdrules{$_} = 1; } @genpwdfail;
5262: $haspasswdmap = 1;
5263: }
5264: }
5265: next;
5266: }
5267: }
5268: $password = $genpwd;
5269: }
5270: # determine user role
5271: my $role = '';
5272: if (defined($fields{'role'})) {
5273: if ($entries{$fields{'role'}}) {
5274: $entries{$fields{'role'}} =~ s/(\s+$|^\s+)//g;
5275: if ($entries{$fields{'role'}} ne '') {
5276: if (grep(/^\Q$entries{$fields{'role'}}\E$/,@permitted_roles)) {
5277: $role = $entries{$fields{'role'}};
5278: }
5279: }
5280: if ($role eq '') {
5281: my $rolestr = join(', ',@permitted_roles);
5282: $disallow{$counter} =
5283: &mt('[_1]: You do not have permission to add the requested role [_2] for the user.'
5284: ,'<b>'.$entries{$fields{'username'}}.'</b>'
5285: ,$entries{$fields{'role'}})
5286: .'<br />'
5287: .&mt('Allowable role(s) is/are: [_1].',$rolestr);
5288: next;
5289: }
5290: }
5291: }
5292: if ($role eq '') {
5293: $role = $defaultrole;
5294: }
5295: # Clean up whitespace
5296: foreach (\$id,\$fname,\$mname,\$lname,\$gen,\$inststatus) {
5297: $$_ =~ s/(\s+$|^\s+)//g;
5298: }
5299: my $credits;
5300: if ($showcredits) {
5301: if (($role eq 'st') && ($crstype ne 'Community')) {
5302: $credits = $entries{$fields{'credits'}};
5303: if ($credits ne '') {
5304: $credits =~ s/[^\d\.]//g;
5305: }
5306: if ($credits eq '') {
5307: $credits = $commoncredits;
5308: }
5309: if ($credits eq $defaultcredits) {
5310: undef($credits);
5311: }
5312: }
5313: }
5314: # check against rules
5315: my $checkid = 0;
5316: my $newuser = 0;
5317: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
5318: if ($uhome eq 'no_host') {
5319: if ($userdomain ne $newuserdom) {
5320: if ($context eq 'course') {
5321: $disallow{$counter} =
5322: &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
5323: '<b>'.$username.'</b>',$userdomain);
5324: } elsif ($context eq 'author') {
5325: $disallow{$counter} =
5326: &mt('[_1]: The domain specified ([_2]) is different to that of the author.',
5327: '<b>'.$username.'</b>',$userdomain);
5328: } else {
5329: $disallow{$counter} =
5330: &mt('[_1]: The domain specified ([_2]) is different to that of your current role.',
5331: '<b>'.$username.'</b>',$userdomain);
5332: }
5333: $disallow{$counter} .=
5334: &mt('The user does not already exist, and you may not create a new user in a different domain.');
5335: next;
5336: } else {
5337: unless (($password ne '') || ($env{'form.login'} eq 'loc') || ($env{'form.login'} eq 'lti')) {
5338: $disallow{$counter} =
5339: &mt('[_1]: This is a new user but no default password was provided, and the authentication type requires one.',
5340: '<b>'.$username.'</b>');
5341: next;
5342: }
5343: }
5344: $checkid = 1;
5345: $newuser = 1;
5346: $checkuname{$username.':'.$newuserdom} = { 'newuser' => $newuser, 'id' => $id };
5347: } else {
5348: if ($context eq 'course' || $context eq 'author') {
5349: if ($userdomain eq $domain ) {
5350: if ($role eq '') {
5351: my @checkroles;
5352: foreach my $role (@poss_roles) {
5353: my $endkey;
5354: if ($role ne 'st') {
5355: $endkey = ':'.$role;
5356: }
5357: if (exists($userlist{$username.':'.$userdomain.$endkey})) {
5358: if (!grep(/^\Q$role\E$/,@checkroles)) {
5359: push(@checkroles,$role);
5360: }
5361: }
5362: }
5363: if (@checkroles > 0) {
5364: %canmodify = &can_modify_userinfo($context,$domain,\@userinfo,\@checkroles);
5365: }
5366: } elsif (ref($modifiable_fields{$role}) eq 'HASH') {
5367: %canmodify = %{$modifiable_fields{$role}};
5368: }
5369: }
5370: my @newinfo = (\$fname,\$mname,\$lname,\$gen,\$email,\$id);
5371: for (my $i=0; $i<@newinfo; $i++) {
5372: if (${$newinfo[$i]} ne '') {
5373: if (!$canmodify{$userinfo[$i]}) {
5374: ${$newinfo[$i]} = '';
5375: }
5376: }
5377: }
5378: }
5379: if ($id) {
5380: $existinguser{$userdomain}{$username} = $id;
5381: }
5382: }
5383: $userinfo{$counter} = {
5384: username => $username,
5385: domain => $userdomain,
5386: fname => $fname,
5387: mname => $mname,
5388: lname => $lname,
5389: gen => $gen,
5390: email => $email,
5391: id => $id,
5392: password => $password,
5393: inststatus => $inststatus,
5394: role => $role,
5395: sections => \@secs,
5396: credits => $credits,
5397: newuser => $newuser,
5398: checkid => $checkid,
5399: };
5400: }
5401: }
5402: } # end of foreach (@userdata)
5403: if ($counter > -1) {
5404: my $total = $counter + 1;
5405: my %checkids;
5406: if ((keys(%existinguser)) || (keys(%checkuname))) {
5407: $r->print(&mt('Please be patient -- checking for institutional data ...'));
5408: $r->rflush();
5409: if (keys(%existinguser)) {
5410: foreach my $dom (keys(%existinguser)) {
5411: if (ref($existinguser{$dom}) eq 'HASH') {
5412: my %idhash = &Apache::lonnet::idrget($dom,keys(%{$existinguser{$dom}}));
5413: foreach my $username (keys(%{$existinguser{$dom}})) {
5414: if ($idhash{$username} ne $existinguser{$dom}{$username}) {
5415: $checkids{$username.':'.$dom} = {
5416: 'id' => $existinguser{$dom}{$username},
5417: };
5418: }
5419: }
5420: if (keys(%checkids)) {
5421: &Apache::loncommon::user_rule_check(\%checkids,{ 'id' => 1 },
5422: \%alerts,\%rulematch,
5423: \%inst_results,\%curr_rules,
5424: \%got_rules);
5425: }
5426: }
5427: }
5428: }
5429: if (keys(%checkuname)) {
5430: &Apache::loncommon::user_rule_check(\%checkuname,{ 'username' => 1, 'id' => 1, },
5431: \%alerts,\%rulematch,\%inst_results,
5432: \%curr_rules,\%got_rules);
5433: }
5434: $r->print(' '.&mt('done').'<br /><br />');
5435: $r->rflush();
5436: }
5437: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,$total);
5438: $r->print('<ul>');
5439: for (my $i=0; $i<=$counter; $i++) {
5440: if ($disallow{$i}) {
5441: $r->print('<li>'.$disallow{$i}.'</li>');
5442: } elsif (ref($userinfo{$i}) eq 'HASH') {
5443: my $password = $userinfo{$i}{'password'};
5444: my $newuser = $userinfo{$i}{'newuser'};
5445: my $checkid = $userinfo{$i}{'checkid'};
5446: my $id = $userinfo{$i}{'id'};
5447: my $role = $userinfo{$i}{'role'};
5448: my @secs;
5449: if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
5450: @secs = @{$userinfo{$i}{'sections'}};
5451: }
5452: my $fname = $userinfo{$i}{'fname'};
5453: my $mname = $userinfo{$i}{'mname'};
5454: my $lname = $userinfo{$i}{'lname'};
5455: my $gen = $userinfo{$i}{'gen'};
5456: my $email = $userinfo{$i}{'email'};
5457: my $inststatus = $userinfo{$i}{'inststatus'};
5458: my $credits = $userinfo{$i}{'credits'};
5459: my $username = $userinfo{$i}{'username'};
5460: my $userdomain = $userinfo{$i}{'domain'};
5461: my $user = $username.':'.$userdomain;
5462: if ($newuser) {
5463: if (ref($alerts{'username'}) eq 'HASH') {
5464: if (ref($alerts{'username'}{$userdomain}) eq 'HASH') {
5465: if ($alerts{'username'}{$userdomain}{$username}) {
5466: $r->print('<li>'.
5467: &mt('[_1]: matches the username format at your institution, but is not known to your directory service.','<b>'.$username.'</b>').'<br />'.
5468: &mt('Consequently, the user was not created.').'</li>');
5469: next;
5470: }
5471: }
5472: }
5473: if (ref($inst_results{$user}) eq 'HASH') {
5474: if ($inst_results{$user}{'firstname'} ne '') {
5475: $fname = $inst_results{$user}{'firstname'};
5476: }
5477: if ($inst_results{$user}{'middlename'} ne '') {
5478: $mname = $inst_results{$user}{'middlename'};
5479: }
5480: if ($inst_results{$user}{'lasttname'} ne '') {
5481: $lname = $inst_results{$user}{'lastname'};
5482: }
5483: if ($inst_results{$user}{'permanentemail'} ne '') {
5484: $email = $inst_results{$user}{'permanentemail'};
5485: }
5486: if ($inst_results{$user}{'id'} ne '') {
5487: $id = $inst_results{$user}{'id'};
5488: $checkid = 0;
5489: }
5490: if (ref($inst_results{$user}{'inststatus'}) eq 'ARRAY') {
5491: $inststatus = join(':',@{$inst_results{$user}{'inststatus'}});
5492: }
5493: }
5494: if (($checkid) && ($id ne '')) {
5495: if (ref($alerts{'id'}) eq 'HASH') {
5496: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
5497: if ($alerts{'id'}{$userdomain}{$username}) {
5498: $r->print('<li>'.
5499: &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
5500: '<b>'.$username.'</b>').'<br />'.
5501: &mt('Consequently, the user was not created.').'</li>');
5502: next;
5503: }
5504: }
5505: }
5506: }
5507: my $usertype = 'unofficial';
5508: if (ref($rulematch{$user}) eq 'HASH') {
5509: if ($rulematch{$user}{'username'}) {
5510: $usertype = 'official';
5511: }
5512: }
5513: unless ($cancreate{$usertype}) {
5514: my $showtype = $longtypes{$usertype};
5515: $r->print('<li>'.
5516: &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].','<b>'.$username.'</b>',$showtype).'</li>');
5517: next;
5518: }
5519: } elsif ($id ne '') {
5520: if (exists($checkids{$user})) {
5521: $checkid = 1;
5522: if (ref($alerts{'id'}) eq 'HASH') {
5523: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
5524: if ($alerts{'id'}{$userdomain}{$username}) {
5525: $r->print('<li>'.
5526: &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
5527: '<b>'.$username.'</b>').'<br />'.
5528: &mt('Consequently, the ID was not changed.').'</li>');
5529: $id = '';
5530: }
5531: }
5532: }
5533: }
5534: }
5535: my $multiple = 0;
5536: my ($userresult,$authresult,$roleresult,$idresult);
5537: my (%userres,%authres,%roleres,%idres);
5538: my $singlesec = '';
5539: if ($role eq 'st') {
5540: if (($context eq 'domain') && ($changeauth eq 'Yes') && (!$newuser)) {
5541: if ((&Apache::lonnet::allowed('mau',$userdomain)) &&
5542: (&Apache::lonnet::homeserver($username,$userdomain) ne 'no_host')) {
5543: if ((($amode =~ /^krb4|krb5|internal$/) && $password ne '') ||
5544: ($amode eq 'localauth')) {
5545: $authresult =
5546: &Apache::lonnet::modifyuserauth($userdomain,$username,$amode,$password);
5547: }
5548: }
5549: }
5550: my $sec;
5551: if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
5552: if (@secs > 0) {
5553: $sec = $secs[0];
5554: }
5555: }
5556: if ($userdomain ne $env{'request.role.domain'}) {
5557: my $item = "/$crsdom/$crsnum" ;
5558: if ($sec ne '') {
5559: $item .= "/$sec";
5560: }
5561: $item .= '_st';
5562: next if (&restricted_dom($context,$item,$userdomain,$username,$role,$startdate,
5563: $enddate,$crsdom,$crsnum,$sec,$credits,\%process_by,
5564: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
5565: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
5566: }
5567: &modifystudent($userdomain,$username,$cid,$sec,
5568: $desiredhost,$context);
5569: $roleresult =
5570: &Apache::lonnet::modifystudent
5571: ($userdomain,$username,$id,$amode,$password,
5572: $fname,$mname,$lname,$gen,$sec,$enddate,
5573: $startdate,$env{'form.forceid'},
5574: $desiredhost,$email,'manual','',$cid,
5575: '',$context,$inststatus,$credits);
5576: $userresult = $roleresult;
5577: } else {
5578: my $possrole;
5579: if ($role ne '') {
5580: if ($context eq 'course' || $setting eq 'course') {
5581: if ($customroles{$role}) {
5582: $role = 'cr_'.$env{'user.domain'}.'_'.
5583: $env{'user.name'}.'_'.$role;
5584: }
5585: $possrole = $role;
5586: if ($possrole =~ /^cr_/) {
5587: $possrole =~ s{_}{/}g;
5588: }
5589: if (($role ne 'cc') && ($role ne 'co')) {
5590: if (@secs > 1) {
5591: $multiple = 1;
5592: my $prefix = "/$crsdom/$crsnum";
5593: foreach my $sec (@secs) {
5594: if ($userdomain ne $env{'request.role.domain'}) {
5595: my $item = $prefix;
5596: if ($sec ne '') {
5597: $item .= "/$sec";
5598: }
5599: $item .= '_'.$possrole;
5600: next if (&restricted_dom($context,$item,$userdomain,$username,$possrole,
5601: $startdate,$enddate,$crsdom,$crsnum,$sec,
5602: $credits,\%process_by,\%instdoms,\%got_role_approvals,
5603: \%got_instdoms,\%reject,\%pending,\%notifydc,
5604: \%status,\%unauthorized,\%currqueued));
5605: }
5606: ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
5607: &modifyuserrole($context,$setting,
5608: $changeauth,$cid,$userdomain,$username,
5609: $id,$amode,$password,$fname,
5610: $mname,$lname,$gen,$sec,
5611: $env{'form.forceid'},$desiredhost,
5612: $email,$role,$enddate,
5613: $startdate,$checkid,$inststatus);
5614: }
5615: } elsif (@secs > 0) {
5616: $singlesec = $secs[0];
5617: }
5618: }
5619: } else {
5620: $possrole = $role;
5621: }
5622: }
5623: if (!$multiple) {
5624: if (($userdomain ne $env{'request.role.domain'}) && ($role ne '')) {
5625: my $item = "/$crsdom/$crsnum";
5626: if ($singlesec ne '') {
5627: $item .= "/$singlesec";
5628: }
5629: $item .= '_'.$possrole;
5630: next if (&restricted_dom($context,$item,$userdomain,$username,$possrole,$startdate,$enddate,
5631: $crsdom,$crsnum,$singlesec,$credits,\%process_by,\%instdoms,
5632: \%got_role_approvals,\%got_instdoms,\%reject,\%pending,\%notifydc,
5633: \%status,\%unauthorized,\%currqueued));
5634: }
5635: ($userresult,$authresult,$roleresult,$idresult) =
5636: &modifyuserrole($context,$setting,
5637: $changeauth,$cid,$userdomain,$username,
5638: $id,$amode,$password,$fname,
5639: $mname,$lname,$gen,$singlesec,
5640: $env{'form.forceid'},$desiredhost,
5641: $email,$role,$enddate,$startdate,
5642: $checkid,$inststatus,\%emptyok);
5643: }
5644: }
5645: if ($multiple) {
5646: foreach my $sec (sort(keys(%userres))) {
5647: $flushc =
5648: &user_change_result($r,$userres{$sec},$authres{$sec},
5649: $roleres{$sec},$idres{$sec},\%counts,$flushc,
5650: $username,$userdomain,\%userchg);
5651:
5652: }
5653: } else {
5654: $flushc =
5655: &user_change_result($r,$userresult,$authresult,
5656: $roleresult,$idresult,\%counts,$flushc,
5657: $username,$userdomain,\%userchg);
5658: }
5659: }
5660: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last user');
5661: } # end of loop
5662: $r->print('</ul>');
5663: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
5664: if (($context eq 'domain') && ($setting eq 'course')) {
5665: unless ($oldcrsuserdoms) {
5666: if (exists($env{'course.'.$cid.'.internal.userdomains'})) {
5667: delete($env{'course.'.$cid.'.internal.userdomains'});
5668: }
5669: }
5670: }
5671: }
5672: # Flush the course logs so reverse user roles immediately updated
5673: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
5674: $r->print("</p>\n<p>\n".&mt('Processed [quant,_1,user].',$counts{'user'}).
5675: "</p>\n");
5676: if ($counts{'role'} > 0) {
5677: $r->print("<p>\n".
5678: &mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.
5679: &mt('If a user is currently logged-in to LON-CAPA, any new roles which are active will be available when the user next logs in.').
5680: "</p>\n");
5681: } else {
5682: $r->print('<p>'.&mt('No roles added').'</p>');
5683: }
5684: if ($counts{'auth'} > 0) {
5685: $r->print("<p>\n".
5686: &mt('Authentication changed for [_1] existing users.',
5687: $counts{'auth'})."</p>\n");
5688: }
5689: $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
5690: $r->print(&passwdrule_alerts($domain,\%showpasswdrules));
5691: if ((keys(%reject)) || (keys(%unauthorized))) {
5692: $r->print(&print_roles_rejected($context,\%reject,\%unauthorized));
5693: }
5694: if ((keys(%pending)) || (keys(%currqueued))) {
5695: $r->print(&print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
5696: }
5697: #####################################
5698: # Display list of students to drop #
5699: #####################################
5700: if ($env{'form.fullup'} eq 'yes') {
5701: $r->print('<h3>'.&mt('Students to Drop')."</h3>\n");
5702: # Get current classlist
5703: my $classlist = &Apache::loncoursedata::get_classlist();
5704: if (! defined($classlist)) {
5705: $r->print('<p class="LC_info">'.
5706: &mt('There are no students with current/future access to the course.').
5707: '</p>'."\n");
5708: } elsif (ref($classlist) eq 'HASH') {
5709: # Remove the students we just added from the list of students.
5710: foreach my $line (@userdata) {
5711: my %entries=&Apache::loncommon::record_sep($line);
5712: unless (($entries{$fields{'username'}} eq '') ||
5713: (!defined($entries{$fields{'username'}}))) {
5714: delete($classlist->{$entries{$fields{'username'}}.
5715: ':'.$domain});
5716: }
5717: }
5718: # Print out list of dropped students.
5719: &show_drop_list($r,$classlist,'nosort',$permission);
5720: }
5721: }
5722: } # end of unless
5723: return 'ok';
5724: }
5725:
5726: sub print_namespacing_alerts {
5727: my ($domain,$alerts,$curr_rules) = @_;
5728: my $output;
5729: if (ref($alerts) eq 'HASH') {
5730: if (keys(%{$alerts}) > 0) {
5731: if (ref($alerts->{'username'}) eq 'HASH') {
5732: foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
5733: my $count;
5734: if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
5735: $count = keys(%{$alerts->{'username'}{$dom}});
5736: }
5737: my $domdesc = &Apache::lonnet::domain($domain,'description');
5738: if (ref($curr_rules->{$dom}) eq 'HASH') {
5739: $output .= &Apache::loncommon::instrule_disallow_msg(
5740: 'username',$domdesc,$count,'upload');
5741: }
5742: $output .= &Apache::loncommon::user_rule_formats($dom,
5743: $domdesc,$curr_rules->{$dom}{'username'},
5744: 'username');
5745: }
5746: }
5747: if (ref($alerts->{'id'}) eq 'HASH') {
5748: foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
5749: my $count;
5750: if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
5751: $count = keys(%{$alerts->{'id'}{$dom}});
5752: }
5753: my $domdesc = &Apache::lonnet::domain($domain,'description');
5754: if (ref($curr_rules->{$dom}) eq 'HASH') {
5755: $output .= &Apache::loncommon::instrule_disallow_msg(
5756: 'id',$domdesc,$count,'upload');
5757: }
5758: $output .= &Apache::loncommon::user_rule_formats($dom,
5759: $domdesc,$curr_rules->{$dom}{'id'},'id');
5760: }
5761: }
5762: }
5763: }
5764: }
5765:
5766: sub passwdrule_alerts {
5767: my ($domain,$passwdrules) = @_;
5768: my $warning;
5769: if (ref($passwdrules) eq 'HASH') {
5770: my %showrules = %{$passwdrules};
5771: if (keys(%showrules)) {
5772: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
5773: $warning = '<b>'.&mt('Password requirement(s) unmet for one or more users:').'</b><ul>';
5774: if ($showrules{'min'}) {
5775: my $min = $passwdconf{'min'};
5776: if ($min eq '') {
5777: $min = $Apache::lonnet::passwdmin;
5778: }
5779: $warning .= '<li>'.&mt('minimum [quant,_1,character]',$min).'</li>';
5780: }
5781: if ($showrules{'max'}) {
5782: $warning .= '<li>'.&mt('maximum [quant,_1,character]',$passwdconf{'max'}).'</li>';
5783: }
5784: if ($showrules{'uc'}) {
5785: $warning .= '<li>'.&mt('contain at least one upper case letter').'</li>';
5786: }
5787: if ($showrules{'lc'}) {
5788: $warning .= '<li>'.&mt('contain at least one lower case letter').'</li>';
5789: }
5790: if ($showrules{'num'}) {
5791: $warning .= '<li>'.&mt('contain at least one number').'</li>';
5792: }
5793: if ($showrules{'spec'}) {
5794: $warning .= '<li>'.&mt('contain at least one non-alphanumeric').'</li>';
5795: }
5796: $warning .= '</ul>';
5797: }
5798: }
5799: return $warning;
5800: }
5801:
5802: sub user_change_result {
5803: my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
5804: $username,$userdomain,$userchg) = @_;
5805: my $okresult = 0;
5806: my @status;
5807: if ($userresult ne 'ok') {
5808: if ($userresult =~ /^error:(.+)$/) {
5809: my $error = $1;
5810: push(@status,
5811: &mt('[_1]: Unable to add/modify: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
5812: }
5813: } else {
5814: $counts->{'user'} ++;
5815: $okresult = 1;
5816: }
5817: if ($authresult ne 'ok') {
5818: if ($authresult =~ /^error:(.+)$/) {
5819: my $error = $1;
5820: push(@status,
5821: &mt('[_1]: Unable to modify authentication: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
5822: }
5823: } else {
5824: $counts->{'auth'} ++;
5825: $okresult = 1;
5826: }
5827: if ($roleresult ne 'ok') {
5828: if ($roleresult =~ /^error:(.+)$/) {
5829: my $error = $1;
5830: push(@status,
5831: &mt('[_1]: Unable to add role: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
5832: }
5833: } else {
5834: $counts->{'role'} ++;
5835: $okresult = 1;
5836: }
5837: if ($okresult) {
5838: $flushc++;
5839: $userchg->{$username.':'.$userdomain}=1;
5840: if ($flushc>15) {
5841: $r->rflush;
5842: $flushc=0;
5843: }
5844: }
5845: if ($idresult) {
5846: push(@status,$idresult);
5847: }
5848: if (@status) {
5849: $r->print('<li>'.join('<br />',@status).'</li>');
5850: }
5851: return $flushc;
5852: }
5853:
5854: # ========================================================= Menu Phase Two Drop
5855: sub print_drop_menu {
5856: my ($r,$context,$permission,$crstype) = @_;
5857: my $heading;
5858: if ($crstype eq 'Community') {
5859: $heading = &mt("Drop Members");
5860: } else {
5861: $heading = &mt("Drop Students");
5862: }
5863: $r->print('<h3>'.$heading.'</h3>'."\n".
5864: '<form name="studentform" method="post" action="">'."\n");
5865: my $classlist = &Apache::loncoursedata::get_classlist();
5866: if (! defined($classlist)) {
5867: my $msg = '';
5868: if ($crstype eq 'Community') {
5869: $msg = &mt('There are no members currently enrolled.');
5870: } else {
5871: $msg = &mt('There are no students currently enrolled.');
5872: }
5873: $r->print('<p class="LC_info">'.$msg."</p>\n");
5874: } else {
5875: &show_drop_list($r,$classlist,'nosort',$permission,$crstype);
5876: }
5877: $r->print('</form>');
5878: return;
5879: }
5880:
5881: # ================================================================== Phase four
5882:
5883: sub update_user_list {
5884: my ($r,$context,$setting,$choice,$crstype) = @_;
5885: my $now = time;
5886: my $count=0;
5887: if ($context eq 'course') {
5888: $crstype = &Apache::loncommon::course_type();
5889: }
5890: my (@changelist,%got_role_approvals,%got_instdoms,%process_by,%instdoms,
5891: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
5892: if ($choice eq 'drop') {
5893: @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
5894: } else {
5895: @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
5896: }
5897: my %result_text = ( ok => { 'revoke' => 'Revoked',
5898: 'delete' => 'Deleted',
5899: 'reenable' => 'Re-enabled',
5900: 'activate' => 'Activated',
5901: 'chgdates' => 'Changed Access Dates for',
5902: 'chgsec' => 'Changed section(s) for',
5903: 'drop' => 'Dropped',
5904: },
5905: error => {'revoke' => 'revoking',
5906: 'delete' => 'deleting',
5907: 'reenable' => 're-enabling',
5908: 'activate' => 'activating',
5909: 'chgdates' => 'changing access dates for',
5910: 'chgsec' => 'changing section for',
5911: 'drop' => 'dropping',
5912: },
5913: );
5914: my ($startdate,$enddate);
5915: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
5916: ($startdate,$enddate) = &get_dates_from_form();
5917: }
5918: foreach my $item (@changelist) {
5919: my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,
5920: @sections,$scopestem,$singlesec,$showsecs,$warn_singlesec,
5921: $nothingtodo,$keepnosection,$credits,$instsec,$cdom,$cnum);
5922: if ($choice eq 'drop') {
5923: ($uname,$udom,$sec) = split(/:/,$item,-1);
5924: $role = 'st';
5925: $cid = $env{'request.course.id'};
5926: $scopestem = '/'.$cid;
5927: $scopestem =~s/\_/\//g;
5928: if ($sec eq '') {
5929: $scope = $scopestem;
5930: } else {
5931: $scope = $scopestem.'/'.$sec;
5932: }
5933: } elsif ($context eq 'course') {
5934: ($uname,$udom,$role,$sec,$type,$locktype,$credits,$instsec) =
5935: split(/\:/,$item,8);
5936: $instsec = &unescape($instsec);
5937: $cid = $env{'request.course.id'};
5938: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5939: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5940: $scopestem = '/'.$cid;
5941: $scopestem =~s/\_/\//g;
5942: if ($sec eq '') {
5943: $scope = $scopestem;
5944: } else {
5945: $scope = $scopestem.'/'.$sec;
5946: }
5947: } elsif ($context eq 'author') {
5948: ($uname,$udom,$role) = split(/\:/,$item,-1);
5949: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
5950: $cdom = $env{'user.domain'};
5951: $cnum = $env{'user.name'};
5952: } elsif ($context eq 'domain') {
5953: if ($setting eq 'domain') {
5954: ($role,$uname,$udom) = split(/\:/,$item,-1);
5955: $scope = '/'.$env{'request.role.domain'}.'/';
5956: $cdom = $env{'request.role.domain'};
5957: } elsif ($setting eq 'author') {
5958: ($uname,$udom,$role,$scope) = split(/\:/,$item);
5959: (undef,$cdom,$cnum) = split(/\//,$scope);
5960: } elsif ($setting eq 'course') {
5961: ($uname,$udom,$role,$cid,$sec,$type,$locktype,$credits,$instsec) =
5962: split(/\:/,$item,9);
5963: ($cdom,$cnum) = split('_',$cid);
5964: $instsec = &unescape($instsec);
5965: $scope = '/'.$cid;
5966: $scope =~s/\_/\//g;
5967: if ($sec ne '') {
5968: $scope .= '/'.$sec;
5969: }
5970: }
5971: }
5972: my $plrole = &Apache::lonnet::plaintext($role,$crstype);
5973: my $start = $env{'form.'.$item.'_start'};
5974: my $end = $env{'form.'.$item.'_end'};
5975: if ($choice eq 'drop') {
5976: # drop students
5977: $end = $now;
5978: $type = 'manual';
5979: $result =
5980: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
5981: } elsif ($choice eq 'revoke') {
5982: # revoke or delete user role
5983: $end = $now;
5984: if ($role eq 'st') {
5985: $result =
5986: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
5987: } else {
5988: $result =
5989: &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
5990: '','',$context);
5991: }
5992: } elsif ($choice eq 'delete') {
5993: if ($role eq 'st') {
5994: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
5995: }
5996: $result =
5997: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
5998: $start,1,'',$context);
5999: } else {
6000: #reenable, activate, change access dates or change section
6001: if ($choice ne 'chgsec') {
6002: $start = $startdate;
6003: $end = $enddate;
6004: }
6005: my $id = $scope.'_'.$role;
6006: if ($choice eq 'reenable') {
6007: next if (&restricted_dom($context,$id,$udom,$uname,$role,$now,$end,$cdom,$cnum,
6008: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
6009: \%got_instdoms,\%reject,\%pending,\%notifydc,
6010: \%status,\%unauthorized,\%currqueued));
6011: if ($role eq 'st') {
6012: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
6013: } else {
6014: $result =
6015: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
6016: $now,'','',$context);
6017: }
6018: } elsif ($choice eq 'activate') {
6019: next if (&restricted_dom($context,$id,$udom,$uname,$role,$now,$end,$cdom,$cnum,
6020: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
6021: \%got_instdoms,\%reject,\%pending,\%notifydc,
6022: \%status,\%unauthorized,\%currqueued));
6023: if ($role eq 'st') {
6024: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
6025: } else {
6026: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
6027: $now,'','',$context);
6028: }
6029: } elsif ($choice eq 'chgdates') {
6030: next if (&restricted_dom($context,$id,$udom,$uname,$role,$start,$end,$cdom,$cnum,
6031: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
6032: \%got_instdoms,\%reject,\%pending,\%notifydc,
6033: \%status,\%unauthorized,\%currqueued));
6034: if ($role eq 'st') {
6035: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
6036: } else {
6037: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
6038: $start,'','',$context);
6039: }
6040: } elsif ($choice eq 'chgsec') {
6041: my (@newsecs,$revresult,$nochg,@retained);
6042: if (($role ne 'cc') && ($role ne 'co')) {
6043: my @secs = sort(split(/,/,$env{'form.newsecs'}));
6044: if (@secs) {
6045: my %curr_groups = &Apache::longroup::coursegroups();
6046: foreach my $sec (@secs) {
6047: next if (($sec =~ /\W/) || ($sec eq 'none') ||
6048: (exists($curr_groups{$sec})));
6049: push(@newsecs,$sec);
6050: }
6051: }
6052: }
6053: # remove existing section if not to be retained.
6054: if (!$env{'form.retainsec'} || ($role eq 'st')) {
6055: if ($sec eq '') {
6056: if (@newsecs == 0) {
6057: $result = 'ok';
6058: $nochg = 1;
6059: $nothingtodo = 1;
6060: } else {
6061: $revresult =
6062: &Apache::lonnet::revokerole($udom,$uname,
6063: $scope,$role,
6064: '','',$context);
6065: }
6066: } else {
6067: if (@newsecs > 0) {
6068: if (grep(/^\Q$sec\E$/,@newsecs)) {
6069: push(@retained,$sec);
6070: } else {
6071: $revresult =
6072: &Apache::lonnet::revokerole($udom,$uname,
6073: $scope,$role,
6074: '','',$context);
6075: }
6076: } else {
6077: $revresult =
6078: &Apache::lonnet::revokerole($udom,$uname,
6079: $scope,$role,
6080: '','',$context);
6081: }
6082: }
6083: } else {
6084: if ($sec eq '') {
6085: $nochg = 1;
6086: $keepnosection = 1;
6087: } else {
6088: push(@retained,$sec);
6089: }
6090: }
6091: # add new sections
6092: my (@diffs,@shownew);
6093: if (@retained) {
6094: @diffs = &Apache::loncommon::compare_arrays(\@retained,\@newsecs);
6095: } else {
6096: @diffs = @newsecs;
6097: }
6098: if (@newsecs == 0) {
6099: if ($nochg) {
6100: $result = 'ok';
6101: $nothingtodo = 1;
6102: } else {
6103: if ($role eq 'st') {
6104: $result =
6105: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
6106: } else {
6107: my $newscope = $scopestem;
6108: $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
6109: }
6110: }
6111: $showsecs = &mt('No section');
6112: } elsif (@diffs == 0) {
6113: $result = 'ok';
6114: $nothingtodo = 1;
6115: } else {
6116: foreach my $newsec (@newsecs) {
6117: if (!grep(/^\Q$newsec\E$/,@retained)) {
6118: if ($role eq 'st') {
6119: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
6120: if (@newsecs > 1) {
6121: my $showsingle;
6122: if ($newsec eq '') {
6123: $showsingle = &mt('No section');
6124: } else {
6125: $showsingle = $newsec;
6126: }
6127: if ($crstype eq 'Community') {
6128: $warn_singlesec = &mt('Although more than one section was indicated, a role was only added for the first section - [_1], as each community member may only be in one section at a time.','<i>'.$showsingle.'</i>');
6129: } else {
6130: $warn_singlesec = &mt('Although more than one section was indicated, a role was only added for the first section - [_1], as each student may only be in one section of a course at a time.','<i>'.$showsingle.'</i>');
6131: }
6132: $showsecs = $showsingle;
6133: last;
6134: } else {
6135: if ($newsec eq '') {
6136: $showsecs = &mt('No section');
6137: } else {
6138: $showsecs = $newsec;
6139: }
6140: }
6141: } else {
6142: my $newscope = $scopestem;
6143: if ($newsec ne '') {
6144: $newscope .= '/'.$newsec;
6145: push(@shownew,$newsec);
6146: }
6147: $result = &Apache::lonnet::assignrole($udom,$uname,
6148: $newscope,$role,$end,$start);
6149:
6150: }
6151: }
6152: }
6153: }
6154: unless ($role eq 'st') {
6155: unless ($showsecs) {
6156: my @tolist = sort(@shownew,@retained);
6157: if ($keepnosection) {
6158: push(@tolist,&mt('No section'));
6159: }
6160: $showsecs = join(', ',@tolist);
6161: }
6162: }
6163: }
6164: }
6165: my $extent = $scope;
6166: if ($choice eq 'drop' || $context eq 'course') {
6167: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
6168: if ($cdesc) {
6169: $extent = $cdesc;
6170: }
6171: }
6172: if ($result eq 'ok' || $result eq 'ok:') {
6173: my $dates;
6174: if (($choice eq 'chgsec') || ($choice eq 'chgdates')) {
6175: $dates = &dates_feedback($start,$end,$now);
6176: }
6177: if ($choice eq 'chgsec') {
6178: if ($nothingtodo) {
6179: $r->print(&mt("Section assignment for role of '[_1]' in [_2] for '[_3]' unchanged.",$plrole,$extent,'<i>'.
6180: &Apache::loncommon::plainname($uname,$udom).
6181: '</i>').' ');
6182: if ($sec eq '') {
6183: $r->print(&mt('[_1]No section[_2] - [_3]','<b>','</b>',$dates));
6184: } else {
6185: $r->print(&mt('Section(s): [_1] - [_2]',
6186: '<b>'.$showsecs.'</b>',$dates));
6187: }
6188: $r->print('<br />');
6189: } else {
6190: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' to [_4] - [_5]",$plrole,$extent,
6191: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
6192: '<b>'.$showsecs.'</b>',$dates).'<br />');
6193: $count ++;
6194: }
6195: if ($warn_singlesec) {
6196: $r->print('<div class="LC_warning">'.$warn_singlesec.'</div>');
6197: }
6198: } elsif ($choice eq 'chgdates') {
6199: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' - [_4]",$plrole,$extent,
6200: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
6201: $dates).'<br />');
6202: $count ++;
6203: } else {
6204: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]'.",$plrole,$extent,
6205: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>').
6206: '<br />');
6207: $count ++;
6208: }
6209: } else {
6210: $r->print(
6211: &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for '[_3]': [_4].",
6212: $plrole,$extent,
6213: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
6214: $result).'<br />');
6215: }
6216: }
6217: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
6218: if ($choice eq 'drop') {
6219: $r->print('<input type="hidden" name="action" value="listusers" />'."\n".
6220: '<input type="hidden" name="Status" value="Active" />'."\n".
6221: '<input type="hidden" name="showrole" value="st" />'."\n");
6222: } else {
6223: foreach my $item ('action','sortby','roletype','showrole','Status','secfilter','grpfilter') {
6224: if ($env{'form.'.$item} ne '') {
6225: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.
6226: '" />'."\n");
6227: }
6228: }
6229: }
6230: $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} [quant,_1,user role,user roles,no user roles].",$count).'</b></p>');
6231: if ($count > 0) {
6232: if ($choice eq 'revoke' || $choice eq 'drop') {
6233: $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>');
6234: }
6235: # Flush the course logs so reverse user roles immediately updated
6236: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
6237: }
6238: if ($env{'form.makedatesdefault'}) {
6239: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
6240: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
6241: }
6242: }
6243: if ((keys(%reject)) || (keys(%unauthorized))) {
6244: $r->print(&print_roles_rejected($context,\%reject,\%unauthorized));
6245: }
6246: if ((keys(%pending)) || (keys(%currqueued))) {
6247: $r->print(&print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
6248: }
6249: my $linktext = &mt('Display User Lists');
6250: if ($choice eq 'drop') {
6251: $linktext = &mt('Display current class roster');
6252: }
6253: $r->print(
6254: &Apache::lonhtmlcommon::actionbox(
6255: ['<a href="javascript:document.studentform.submit()">'.$linktext.'</a>'])
6256: .'</form>'."\n");
6257: }
6258:
6259: sub dates_feedback {
6260: my ($start,$end,$now) = @_;
6261: my $dates;
6262: if ($start < $now) {
6263: if ($end == 0) {
6264: $dates = &mt('role(s) active now; no end date');
6265: } elsif ($end > $now) {
6266: $dates = &mt('role(s) active now; ends [_1].',&Apache::lonlocal::locallocaltime($end));
6267: } else {
6268: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
6269: }
6270: } else {
6271: if ($end == 0 || $end > $now) {
6272: $dates = &mt('future role(s); starts: [_1].',&Apache::lonlocal::locallocaltime($start));
6273: } else {
6274: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
6275: }
6276: }
6277: return $dates;
6278: }
6279:
6280: sub classlist_drop {
6281: my ($scope,$uname,$udom,$now) = @_;
6282: my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
6283: if (&Apache::lonnet::is_course($cdom,$cnum)) {
6284: if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
6285: my %user;
6286: my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
6287: return &mt('Drop from classlist: [_1]',
6288: '<b>'.$result.'</b>').'<br />';
6289: }
6290: }
6291: }
6292:
6293: sub active_student_roles {
6294: my ($cnum,$cdom,$uname,$udom) = @_;
6295: my %roles =
6296: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
6297: ['future','active'],['st']);
6298: return exists($roles{"$cnum:$cdom:st"});
6299: }
6300:
6301: sub section_check_js {
6302: my $groupslist= &get_groupslist();
6303: my %js_lt = &Apache::lonlocal::texthash(
6304: mayn => 'may not be used as the name for a section, as it is a reserved word.',
6305: plch => 'Please choose a different section name.',
6306: mnot => 'may not be used as a section name, as it is the name of a course group.',
6307: secn => 'Section names and group names must be distinct. Please choose a different section name.',
6308: );
6309: &js_escape(\%js_lt);
6310: return <<"END";
6311: function validate(caller) {
6312: var groups = new Array($groupslist);
6313: var secname = caller.value;
6314: if ((secname == 'all') || (secname == 'none')) {
6315: alert("'"+secname+"' $js_lt{'mayn'}\\n$js_lt{'plch'}");
6316: return 'error';
6317: }
6318: if (secname != '') {
6319: for (var k=0; k<groups.length; k++) {
6320: if (secname == groups[k]) {
6321: alert("'"+secname+"' $js_lt{'mnot'}\\n$js_lt{'secn'}");
6322: return 'error';
6323: }
6324: }
6325: }
6326: return 'ok';
6327: }
6328: END
6329: }
6330:
6331: sub set_login {
6332: my ($dom,$authformkrb,$authformint,$authformloc,$authformlti) = @_;
6333: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6334: my $response;
6335: my ($authnum,%can_assign) =
6336: &Apache::loncommon::get_assignable_auth($dom);
6337: if ($authnum) {
6338: $response = &Apache::loncommon::start_data_table();
6339: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
6340: $response .= &Apache::loncommon::start_data_table_row().
6341: '<td>'.$authformkrb.'</td>'.
6342: &Apache::loncommon::end_data_table_row()."\n";
6343: }
6344: if ($can_assign{'int'}) {
6345: $response .= &Apache::loncommon::start_data_table_row().
6346: '<td>'.$authformint.'</td>'.
6347: &Apache::loncommon::end_data_table_row()."\n"
6348: }
6349: if ($can_assign{'loc'}) {
6350: $response .= &Apache::loncommon::start_data_table_row().
6351: '<td>'.$authformloc.'</td>'.
6352: &Apache::loncommon::end_data_table_row()."\n";
6353: }
6354: if ($can_assign{'lti'}) {
6355: $response .= &Apache::loncommon::start_data_table_row().
6356: '<td>'.$authformlti.'</td>'.
6357: &Apache::loncommon::end_data_table_row()."\n";
6358: }
6359: $response .= &Apache::loncommon::end_data_table();
6360: }
6361: return $response;
6362: }
6363:
6364: sub course_sections {
6365: my ($sections_count,$role,$current_sec,$disabled) = @_;
6366: my $output = '';
6367: my @sections = (sort {$a <=> $b} keys(%{$sections_count}));
6368: my $numsec = scalar(@sections);
6369: my $is_selected = ' selected="selected"';
6370: if ($numsec <= 1) {
6371: $output = '<select name="currsec_'.$role.'"'.$disabled.'>'."\n".
6372: ' <option value="">'.&mt('Select').'</option>'."\n";
6373: if ($current_sec eq 'none') {
6374: $output .=
6375: ' <option value=""'.$is_selected.'>'.&mt('No section').'</option>'."\n";
6376: } else {
6377: $output .=
6378: ' <option value="">'.&mt('No section').'</option>'."\n";
6379: }
6380: if ($numsec == 1) {
6381: if ($current_sec eq $sections[0]) {
6382: $output .=
6383: ' <option value="'.$sections[0].'"'.$is_selected.'>'.$sections[0].'</option>'."\n";
6384: } else {
6385: $output .=
6386: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
6387: }
6388: }
6389: } else {
6390: $output = '<select name="currsec_'.$role.'" ';
6391: my $multiple = 4;
6392: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
6393: if ($role eq 'st') {
6394: $output .= $disabled.'>'."\n".
6395: ' <option value="">'.&mt('Select').'</option>'."\n";
6396: if ($current_sec eq 'none') {
6397: $output .=
6398: ' <option value=""'.$is_selected.'>'.&mt('No section')."</option>\n";
6399: } else {
6400: $output .=
6401: ' <option value="">'.&mt('No section')."</option>\n";
6402: }
6403: } else {
6404: $output .= 'multiple="multiple" size="'.$multiple.'"'.$disabled.'>'."\n";
6405: }
6406: foreach my $sec (@sections) {
6407: if ($current_sec eq $sec) {
6408: $output .= '<option value="'.$sec.'"'.$is_selected.'>'.$sec."</option>\n";
6409: } else {
6410: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
6411: }
6412: }
6413: }
6414: $output .= '</select>';
6415: return $output;
6416: }
6417:
6418: sub get_groupslist {
6419: my $groupslist;
6420: my %curr_groups = &Apache::longroup::coursegroups();
6421: if (%curr_groups) {
6422: $groupslist = join('","',sort(keys(%curr_groups)));
6423: $groupslist = '"'.$groupslist.'"';
6424: }
6425: return $groupslist;
6426: }
6427:
6428: sub setsections_javascript {
6429: my ($formname,$groupslist,$mode,$checkauth,$crstype,$showcredits) = @_;
6430: my ($checkincluded,$finish,$rolecode,$setsection_js);
6431: if ($mode eq 'upload') {
6432: $checkincluded = 'formname.name == "'.$formname.'"';
6433: $finish = "return 'ok';";
6434: $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
6435: } elsif ($formname eq 'cu') {
6436: if (($crstype eq 'Course') && ($showcredits)) {
6437: $checkincluded = "((role == 'st') && (formname.elements[i-2].checked == true)) || ((role != 'st') && (formname.elements[i-1].checked == true))";
6438: } else {
6439: $checkincluded = 'formname.elements[i-1].checked == true';
6440: }
6441: if ($checkauth) {
6442: $finish = "var authcheck = auth_check();\n".
6443: " if (authcheck == 'ok') {\n".
6444: " formname.submit();\n".
6445: " }\n";
6446: } else {
6447: $finish = 'formname.submit()';
6448: }
6449: $rolecode = "var match = str.split('_');
6450: var role = match[3];\n";
6451: } elsif (($formname eq 'enrollstudent') || ($formname eq 'selfenroll')) {
6452: $checkincluded = 'formname.name == "'.$formname.'"';
6453: if ($checkauth) {
6454: $finish = "var authcheck = auth_check();\n".
6455: " if (authcheck == 'ok') {\n".
6456: " formname.submit();\n".
6457: " }\n";
6458: } else {
6459: $finish = 'formname.submit()';
6460: }
6461: $rolecode = "var match = str.split('_');
6462: var role = match[1];\n";
6463: } else {
6464: $checkincluded = 'formname.name == "'.$formname.'"';
6465: $finish = "seccheck = 'ok';";
6466: $rolecode = "var match = str.split('_');
6467: var role = match[1];\n";
6468: $setsection_js = "var seccheck = 'alert';";
6469: }
6470: my %alerts = &Apache::lonlocal::texthash(
6471: secd => 'Section designations do not apply to Course Coordinator roles.',
6472: sedn => 'Section designations do not apply to Coordinator roles.',
6473: accr => 'A course coordinator role will be added with access to all sections.',
6474: acor => 'A coordinator role will be added with access to all sections',
6475: inea => 'In each course, each user may only have one student role at a time.',
6476: inco => 'In each community, each user may only have one member role at a time.',
6477: youh => 'You had selected',
6478: secs => 'sections.',
6479: plmo => 'Please modify your selections so they include no more than one section.',
6480: mayn => 'may not be used as the name for a section, as it is a reserved word.',
6481: plch => 'Please choose a different section name.',
6482: mnot => 'may not be used as a section name, as it is the name of a course group.',
6483: secn => 'Section names and group names must be distinct. Please choose a different section name.',
6484: nonw => 'Section names may only contain letters or numbers.',
6485: );
6486: &js_escape(\%alerts);
6487: $setsection_js .= <<"ENDSECCODE";
6488:
6489: function setSections(formname,crstype) {
6490: var re1 = /^currsec_/;
6491: var re2 =/\\W/;
6492: var trimleading = /^\\s+/;
6493: var trimtrailing = /\\s+\$/;
6494: var groups = new Array($groupslist);
6495: for (var i=0;i<formname.elements.length;i++) {
6496: var str = formname.elements[i].name;
6497: if (typeof(str) === "undefined") {
6498: continue;
6499: }
6500: var checkcurr = str.match(re1);
6501: if (checkcurr != null) {
6502: var num = i;
6503: $rolecode
6504: if ($checkincluded) {
6505: if (role == 'cc' || role == 'co') {
6506: if (role == 'cc') {
6507: alert("$alerts{'secd'}\\n$alerts{'accr'}");
6508: } else {
6509: alert("$alerts{'sedn'}\\n$alerts{'acor'}");
6510: }
6511: } else {
6512: var sections = '';
6513: var numsec = 0;
6514: var fromexisting = new Array();
6515: for (var j=0; j<formname.elements[num].length; j++) {
6516: if (formname.elements[num].options[j].selected == true ) {
6517: var addsec = formname.elements[num].options[j].value;
6518: if ((addsec != "") && (addsec != null)) {
6519: fromexisting.push(addsec);
6520: if (numsec == 0) {
6521: sections = addsec;
6522: } else {
6523: sections = sections + "," + addsec;
6524: }
6525: numsec ++;
6526: }
6527: }
6528: }
6529: var newsecs = formname.elements[num+1].value;
6530: var validsecs = new Array();
6531: var validsecstr = '';
6532: var badsecs = new Array();
6533: if (newsecs != null && newsecs != "") {
6534: var numsplit;
6535: if (newsecs.indexOf(',') == -1) {
6536: numsplit = new Array(newsecs);
6537: } else {
6538: numsplit = newsecs.split(/,/g);
6539: }
6540: for (var m=0; m<numsplit.length; m++) {
6541: var newsec = numsplit[m];
6542: newsec = newsec.replace(trimleading,'');
6543: newsec = newsec.replace(trimtrailing,'');
6544: if (re2.test(newsec) == true) {
6545: badsecs.push(newsec);
6546: } else {
6547: if (newsec != '') {
6548: var isnew = 1;
6549: if (fromexisting != null) {
6550: for (var n=0; n<fromexisting.length; n++) {
6551: if (newsec == fromexisting[n]) {
6552: isnew = 0;
6553: }
6554: }
6555: }
6556: if (isnew == 1) {
6557: validsecs.push(newsec);
6558: }
6559: }
6560: }
6561: }
6562: if (badsecs.length > 0) {
6563: alert("$alerts{'nonw'}\\n$alerts{'plch'}");
6564: return;
6565: }
6566: numsec = numsec + validsecs.length;
6567: }
6568: if ((role == 'st') && (numsec > 1)) {
6569: if (crstype == 'Community') {
6570: alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
6571: } else {
6572: alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
6573: }
6574: return;
6575: } else {
6576: if (validsecs != null) {
6577: for (var j=0; j<validsecs.length; j++) {
6578: if (validsecstr == '' || validsecstr == null) {
6579: validsecstr = validsecs[j];
6580: } else {
6581: validsecstr += ','+validsecs[j];
6582: }
6583: if ((validsecs[j] == 'all') ||
6584: (validsecs[j] == 'none')) {
6585: alert("'"+validsecs[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
6586: return;
6587: }
6588: for (var k=0; k<groups.length; k++) {
6589: if (validsecs[j] == groups[k]) {
6590: alert("'"+validsecs[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
6591: return;
6592: }
6593: }
6594: }
6595: }
6596: }
6597: if ((validsecstr != '') && (validsecstr != null)) {
6598: if ((sections == '') || (sections == null)) {
6599: sections = validsecstr;
6600: } else {
6601: sections = sections + "," + validsecstr;
6602: }
6603: }
6604: formname.elements[num+2].value = sections;
6605: }
6606: }
6607: }
6608: }
6609: $finish
6610: }
6611: ENDSECCODE
6612: return $setsection_js;
6613: }
6614:
6615: sub can_create_user {
6616: my ($dom,$context,$usertype) = @_;
6617: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6618: my $cancreate = 1;
6619: if (&Apache::lonnet::allowed('mau',$dom)) {
6620: return $cancreate;
6621: } elsif ($context eq 'domain') {
6622: $cancreate = 0;
6623: return $cancreate;
6624: }
6625: if (ref($domconf{'usercreation'}) eq 'HASH') {
6626: if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
6627: if ($context eq 'course' || $context eq 'author' || $context eq 'requestcrs') {
6628: my $creation = $domconf{'usercreation'}{'cancreate'}{$context};
6629: if ($creation eq 'none') {
6630: $cancreate = 0;
6631: } elsif ($creation ne 'any') {
6632: if (defined($usertype)) {
6633: if ($creation ne $usertype) {
6634: $cancreate = 0;
6635: }
6636: }
6637: }
6638: }
6639: }
6640: }
6641: return $cancreate;
6642: }
6643:
6644: sub can_modify_userinfo {
6645: my ($context,$dom,$fields,$userroles) = @_;
6646: my %domconfig =
6647: &Apache::lonnet::get_dom('configuration',['usermodification'],
6648: $dom);
6649: my %canmodify;
6650: if (ref($fields) eq 'ARRAY') {
6651: foreach my $field (@{$fields}) {
6652: $canmodify{$field} = 0;
6653: if (&Apache::lonnet::allowed('mau',$dom)) {
6654: $canmodify{$field} = 1;
6655: } else {
6656: if (ref($domconfig{'usermodification'}) eq 'HASH') {
6657: if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
6658: if (ref($userroles) eq 'ARRAY') {
6659: foreach my $role (@{$userroles}) {
6660: my $testrole;
6661: if ($context eq 'selfcreate') {
6662: $testrole = $role;
6663: } else {
6664: if ($role =~ /^cr\//) {
6665: $testrole = 'cr';
6666: } else {
6667: $testrole = $role;
6668: }
6669: }
6670: if (ref($domconfig{'usermodification'}{$context}{$testrole}) eq 'HASH') {
6671: if ($domconfig{'usermodification'}{$context}{$testrole}{$field}) {
6672: $canmodify{$field} = 1;
6673: last;
6674: }
6675: }
6676: }
6677: } else {
6678: foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
6679: if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
6680: if ($domconfig{'usermodification'}{$context}{$key}{$field}) {
6681: $canmodify{$field} = 1;
6682: last;
6683: }
6684: }
6685: }
6686: }
6687: }
6688: } elsif ($context eq 'course') {
6689: if (ref($userroles) eq 'ARRAY') {
6690: if (grep(/^st$/,@{$userroles})) {
6691: $canmodify{$field} = 1;
6692: }
6693: } else {
6694: $canmodify{$field} = 1;
6695: }
6696: }
6697: }
6698: }
6699: }
6700: return %canmodify;
6701: }
6702:
6703: sub can_change_internalpass {
6704: my ($uname,$udom,$crstype,$permission) = @_;
6705: my $canchange;
6706: if (&Apache::lonnet::allowed('mau',$udom)) {
6707: $canchange = 1;
6708: } elsif ((ref($permission) eq 'HASH') && ($permission->{'mip'}) &&
6709: ($udom eq $env{'request.role.domain'})) {
6710: unless ($env{'course.'.$env{'request.course.id'}.'.internal.nopasswdchg'}) {
6711: my ($cnum,$cdom) = &get_course_identity();
6712: if ((&Apache::lonnet::is_course_owner($cdom,$cnum)) && ($udom eq $env{'user.domain'})) {
6713: my @userstatuses = ('default');
6714: my %userenv = &Apache::lonnet::userenvironment($udom,$uname,'inststatus');
6715: if ($userenv{'inststatus'} ne '') {
6716: @userstatuses = split(/:/,$userenv{'inststatus'});
6717: }
6718: my $noupdate = 1;
6719: my %passwdconf = &Apache::lonnet::get_passwdconf($cdom);
6720: if (ref($passwdconf{'crsownerchg'}) eq 'HASH') {
6721: if (ref($passwdconf{'crsownerchg'}{'for'}) eq 'ARRAY') {
6722: foreach my $status (@userstatuses) {
6723: if (grep(/^\Q$status\E$/,@{$passwdconf{'crsownerchg'}{'for'}})) {
6724: undef($noupdate);
6725: last;
6726: }
6727: }
6728: }
6729: }
6730: if ($noupdate) {
6731: return;
6732: }
6733: my %owned = &Apache::lonnet::courseiddump($cdom,'.',1,'.',
6734: $env{'user.name'}.':'.$env{'user.domain'},
6735: undef,undef,undef,'.');
6736: my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
6737: ['active','future']);
6738: foreach my $key (keys(%roleshash)) {
6739: my ($name,$domain,$role) = split(/:/,$key);
6740: if ($role eq 'st') {
6741: next if (($name eq $cnum) && ($domain eq $cdom));
6742: if ($owned{$domain.'_'.$name}) {
6743: if (ref($owned{$domain.'_'.$name}) eq 'HASH') {
6744: if ($owned{$domain.'_'.$name}{'nopasswdchg'}) {
6745: $noupdate = 1;
6746: last;
6747: }
6748: }
6749: } else {
6750: $noupdate = 1;
6751: last;
6752: }
6753: } else {
6754: $noupdate = 1;
6755: last;
6756: }
6757: }
6758: unless ($noupdate) {
6759: $canchange = 1;
6760: }
6761: }
6762: }
6763: }
6764: return $canchange;
6765: }
6766:
6767: sub check_usertype {
6768: my ($dom,$uname,$rules,$curr_rules,$got_rules) = @_;
6769: my $usertype;
6770: if ((ref($got_rules) eq 'HASH') && (ref($curr_rules) eq 'HASH')) {
6771: if (!$got_rules->{$dom}) {
6772: my %domconfig = &Apache::lonnet::get_dom('configuration',
6773: ['usercreation'],$dom);
6774: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6775: foreach my $item ('username','id') {
6776: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
6777: $curr_rules->{$dom}{$item} =
6778: $domconfig{'usercreation'}{$item.'_rule'};
6779: }
6780: }
6781: }
6782: $got_rules->{$dom} = 1;
6783: }
6784: if (ref($rules) eq 'HASH') {
6785: my @user_rules;
6786: if (ref($curr_rules->{$dom}{'username'}) eq 'ARRAY') {
6787: foreach my $rule (keys(%{$rules})) {
6788: if (grep(/^\Q$rule\E/,@{$curr_rules->{$dom}{'username'}})) {
6789: push(@user_rules,$rule);
6790: }
6791: }
6792: }
6793: if (@user_rules > 0) {
6794: my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
6795: if (keys(%rule_check) > 0) {
6796: $usertype = 'unofficial';
6797: foreach my $item (keys(%rule_check)) {
6798: if ($rule_check{$item}) {
6799: $usertype = 'official';
6800: last;
6801: }
6802: }
6803: }
6804: }
6805: }
6806: }
6807: return $usertype;
6808: }
6809:
6810: sub roles_by_context {
6811: my ($context,$custom,$crstype) = @_;
6812: my @allroles;
6813: if ($context eq 'course') {
6814: @allroles = ('st');
6815: if ($env{'request.role'} =~ m{^dc\./}) {
6816: push(@allroles,'ad');
6817: }
6818: push(@allroles,('ta','ep','in'));
6819: if ($crstype eq 'Community') {
6820: push(@allroles,'co');
6821: } else {
6822: push(@allroles,'cc');
6823: }
6824: if ($custom) {
6825: push(@allroles,'cr');
6826: }
6827: } elsif ($context eq 'author') {
6828: @allroles = ('ca','aa');
6829: } elsif ($context eq 'domain') {
6830: @allroles = ('li','ad','dg','dh','da','sc','au','dc');
6831: }
6832: return @allroles;
6833: }
6834:
6835: sub get_permission {
6836: my ($context,$crstype) = @_;
6837: my %permission;
6838: if ($context eq 'course') {
6839: my $custom = 1;
6840: my @allroles = &roles_by_context($context,$custom,$crstype);
6841: foreach my $role (@allroles) {
6842: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
6843: $permission{'cusr'} = 1;
6844: last;
6845: }
6846: }
6847: if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
6848: $permission{'custom'} = 1;
6849: }
6850: if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
6851: $permission{'view'} = 1;
6852: }
6853: if (!$permission{'view'}) {
6854: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
6855: $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
6856: if ($permission{'view'}) {
6857: $permission{'view_section'} = $env{'request.course.sec'};
6858: }
6859: }
6860: if (!$permission{'cusr'}) {
6861: if ($env{'request.course.sec'} ne '') {
6862: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
6863: $permission{'cusr'} = (&Apache::lonnet::allowed('cst',$scope));
6864: if ($permission{'cusr'}) {
6865: $permission{'cusr_section'} = $env{'request.course.sec'};
6866: }
6867: }
6868: }
6869: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
6870: $permission{'grp_manage'} = 1;
6871: }
6872: if ($permission{'cusr'}) {
6873: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6874: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6875: my %coursehash = (
6876: 'internal.selfenrollmgrdc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrdc'},
6877: 'internal.selfenrollmgrcc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrcc'},
6878: 'internal.coursecode' => $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},
6879: 'internal.textbook' =>$env{'course.'.$env{'request.course.id'}.'.internal.textbook'},
6880: );
6881: my ($managed_by_cc,$managed_by_dc) = &selfenrollment_administration($cdom,$cnum,$crstype,\%coursehash);
6882: if (ref($managed_by_cc) eq 'ARRAY') {
6883: if (@{$managed_by_cc}) {
6884: $permission{'selfenrolladmin'} = 1;
6885: }
6886: }
6887: unless ($permission{'selfenrolladmin'}) {
6888: $permission{'selfenrollview'} = 1;
6889: }
6890: }
6891: if ($env{'request.course.id'}) {
6892: my $user;
6893: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
6894: $user = $env{'user.name'}.':'.$env{'user.domain'};
6895: }
6896: if (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'} eq
6897: $user)) {
6898: $permission{'owner'} = 1;
6899: if (&Apache::lonnet::allowed('mip',$env{'request.course.id'})) {
6900: $permission{'mip'} = 1;
6901: }
6902: } elsif (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.co-owners'} ne '')) {
6903: if (grep(/^\Q$user\E$/,split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.co-owners'}))) {
6904: $permission{'co-owner'} = 1;
6905: }
6906: }
6907: }
6908: } elsif ($context eq 'author') {
6909: my $audom = $env{'request.role.domain'};
6910: my $auname = $env{'user.name'};
6911: if ((&Apache::lonnet::allowed('cca',"$audom/$auname")) ||
6912: (&Apache::lonnet::allowed('caa',"$audom/$auname"))) {
6913: $permission{'author'} = 1;
6914: $permission{'cusr'} = 1;
6915: $permission{'view'} = 1;
6916: }
6917: } elsif ($context eq 'coauthor') {
6918: my ($audom,$auname) = ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$});
6919: if ((&Apache::lonnet::allowed('vca',"$audom/$auname")) ||
6920: (&Apache::lonnet::allowed('vaa',"$audom/$auname"))) {
6921: if ($env{"environment.internal.manager./$audom/$auname"}) {
6922: $permission{'cusr'} = 1;
6923: $permission{'view'} = 1;
6924: }
6925: }
6926: } else {
6927: my @allroles = &roles_by_context($context);
6928: foreach my $role (@allroles) {
6929: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
6930: $permission{'cusr'} = 1;
6931: last;
6932: }
6933: }
6934: if (!$permission{'cusr'}) {
6935: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
6936: $permission{'cusr'} = 1;
6937: }
6938: }
6939: if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
6940: $permission{'custom'} = 1;
6941: }
6942: if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
6943: $permission{'activity'} = 1;
6944: }
6945: if (&Apache::lonnet::allowed('vur',$env{'request.role.domain'})) {
6946: $permission{'view'} = 1;
6947: }
6948: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
6949: $permission{'owner'} = 1;
6950: }
6951: }
6952: my $allowed = 0;
6953: foreach my $key (keys(%permission)) {
6954: next if (($key eq 'owner') || ($key eq 'co-owner') || ($key eq 'author'));
6955: if ($permission{$key}) { $allowed=1; last; }
6956: }
6957: return (\%permission,$allowed);
6958: }
6959:
6960: # ==================================================== Figure out author access
6961:
6962: sub authorpriv {
6963: my ($auname,$audom)=@_;
6964: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
6965: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; } return 1;
6966: }
6967:
6968: sub coauthorpriv {
6969: my ($auname,$audom)=@_;
6970: my $uname = $env{'user.name'};
6971: my $udom = $env{'user.domain'};
6972: if (((&Apache::lonnet::allowed('vca',"$udom/$uname")) ||
6973: (&Apache::lonnet::allowed('vaa',"$udom/$uname"))) &&
6974: ($env{"environment.internal.manager./$audom/$auname"})) {
6975: return 1;
6976: }
6977: return '';
6978: }
6979:
6980: sub roles_on_upload {
6981: my ($context,$setting,$crstype,%customroles) = @_;
6982: my (@possible_roles,@permitted_roles);
6983: @possible_roles = &curr_role_permissions($context,$setting,1,$crstype);
6984: foreach my $role (@possible_roles) {
6985: if ($role eq 'cr') {
6986: push(@permitted_roles,keys(%customroles));
6987: } else {
6988: push(@permitted_roles,$role);
6989: }
6990: }
6991: return @permitted_roles;
6992: }
6993:
6994: sub get_course_identity {
6995: my ($cid) = @_;
6996: my ($cnum,$cdom,$cdesc);
6997: if ($cid eq '') {
6998: $cid = $env{'request.course.id'}
6999: }
7000: if ($cid ne '') {
7001: $cnum = $env{'course.'.$cid.'.num'};
7002: $cdom = $env{'course.'.$cid.'.domain'};
7003: $cdesc = $env{'course.'.$cid.'.description'};
7004: if ($cnum eq '' || $cdom eq '') {
7005: my %coursehash =
7006: &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
7007: $cdom = $coursehash{'domain'};
7008: $cnum = $coursehash{'num'};
7009: $cdesc = $coursehash{'description'};
7010: }
7011: }
7012: return ($cnum,$cdom,$cdesc);
7013: }
7014:
7015: sub dc_setcourse_js {
7016: my ($formname,$mode,$context,$showcredits,$domain) = @_;
7017: my ($dc_setcourse_code,$authen_check);
7018: my $cctext = &Apache::lonnet::plaintext('cc');
7019: my $cotext = &Apache::lonnet::plaintext('co');
7020: my %alerts = §ioncheck_alerts();
7021: my $role = 'role';
7022: if ($mode eq 'upload') {
7023: $role = 'courserole';
7024: } else {
7025: $authen_check = &verify_authen($formname,$context,$domain);
7026: }
7027: $dc_setcourse_code = (<<"SCRIPTTOP");
7028: $authen_check
7029:
7030: function setCourse() {
7031: var course = document.$formname.dccourse.value;
7032: if (course != "") {
7033: if (document.$formname.dcdomain.value != document.$formname.origdom.value) {
7034: alert("$alerts{'curd'}");
7035: return;
7036: }
7037: var userrole = document.$formname.$role.options[document.$formname.$role.selectedIndex].value
7038: var section="";
7039: var numsections = 0;
7040: var newsecs = new Array();
7041: for (var i=0; i<document.$formname.currsec.length; i++) {
7042: if (document.$formname.currsec.options[i].selected == true ) {
7043: if (document.$formname.currsec.options[i].value != "" && document.$formname.currsec.options[i].value != null) {
7044: if (numsections == 0) {
7045: section = document.$formname.currsec.options[i].value
7046: numsections = 1;
7047: }
7048: else {
7049: section = section + "," + document.$formname.currsec.options[i].value
7050: numsections ++;
7051: }
7052: }
7053: }
7054: }
7055: if (document.$formname.newsec.value != "" && document.$formname.newsec.value != null) {
7056: if (numsections == 0) {
7057: section = document.$formname.newsec.value
7058: }
7059: else {
7060: section = section + "," + document.$formname.newsec.value
7061: }
7062: newsecs = document.$formname.newsec.value.split(/,/g);
7063: numsections = numsections + newsecs.length;
7064: }
7065: if ((userrole == 'st') && (numsections > 1)) {
7066: if (document.$formname.crstype.value == 'Community') {
7067: alert("$alerts{'inco'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
7068: } else {
7069: alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
7070: }
7071: return;
7072: }
7073: for (var j=0; j<newsecs.length; j++) {
7074: if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
7075: alert("'"+newsecs[j]+"' $alerts{'mayn'}.\\n$alerts{'plsc'}.");
7076: return;
7077: }
7078: if (document.$formname.groups.value != '') {
7079: var groups = document.$formname.groups.value.split(/,/g);
7080: for (var k=0; k<groups.length; k++) {
7081: if (newsecs[j] == groups[k]) {
7082: if (document.$formname.crstype.value == 'Community') {
7083: alert("'"+newsecs[j]+"' $alerts{'mayc'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
7084: } else {
7085: alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
7086: }
7087: return;
7088: }
7089: }
7090: }
7091: }
7092: if ((userrole == 'cc') && (numsections > 0)) {
7093: alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
7094: section = "";
7095: }
7096: if ((userrole == 'co') && (numsections > 0)) {
7097: alert("$alerts{'secd'} $cotext $alerts{'role'}.\\n$alerts{'accr'}.");
7098: section = "";
7099: }
7100: SCRIPTTOP
7101: if ($mode ne 'upload') {
7102: $dc_setcourse_code .= (<<"SCRIPTMID");
7103: var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
7104: var numcourse = getIndex(document.$formname.dccourse);
7105: if (numcourse == "-1") {
7106: if (document.$formname.type == 'Community') {
7107: alert("$alerts{'thwc'}");
7108: } else {
7109: alert("$alerts{'thwa'}");
7110: }
7111: return;
7112: }
7113: else {
7114: document.$formname.elements[numcourse].name = "act"+coursename;
7115: var numnewsec = getIndex(document.$formname.newsec);
7116: if (numnewsec != "-1") {
7117: document.$formname.elements[numnewsec].name = "sec"+coursename;
7118: document.$formname.elements[numnewsec].value = section;
7119: }
7120: var numstart = getIndex(document.$formname.start);
7121: if (numstart != "-1") {
7122: document.$formname.elements[numstart].name = "start"+coursename;
7123: }
7124: var numend = getIndex(document.$formname.end);
7125: if (numend != "-1") {
7126: document.$formname.elements[numend].name = "end"+coursename
7127: }
7128: SCRIPTMID
7129: if ($showcredits) {
7130: $dc_setcourse_code .= <<ENDCRED;
7131: var numcredits = getIndex(document.$formname.credits);
7132: if (numcredits != "-1") {
7133: document.$formname.elements[numcredits].name = "credits"+coursename;
7134: }
7135: ENDCRED
7136: }
7137: $dc_setcourse_code .= <<ENDSCRIPT;
7138: }
7139: }
7140: var authcheck = auth_check();
7141: if (authcheck == 'ok') {
7142: document.$formname.submit();
7143: }
7144: }
7145: ENDSCRIPT
7146: } else {
7147: $dc_setcourse_code .= "
7148: document.$formname.sections.value = section;
7149: }
7150: return 'ok';
7151: }
7152: ";
7153: }
7154: $dc_setcourse_code .= (<<"ENDSCRIPT");
7155:
7156: function getIndex(caller) {
7157: for (var i=0;i<document.$formname.elements.length;i++) {
7158: if (document.$formname.elements[i] == caller) {
7159: return i;
7160: }
7161: }
7162: return -1;
7163: }
7164: ENDSCRIPT
7165: return $dc_setcourse_code;
7166: }
7167:
7168: sub verify_authen {
7169: my ($formname,$context,$domain) = @_;
7170: my %alerts = &authcheck_alerts();
7171: my $finish = "return 'ok';";
7172: if ($context eq 'author') {
7173: $finish = "document.$formname.submit();";
7174: }
7175: my ($numrules,$intargjs) =
7176: &Apache::loncommon::passwd_validation_js('argpicked',$domain);
7177: my $outcome = <<"ENDSCRIPT";
7178:
7179: function auth_check() {
7180: var logintype;
7181: if (document.$formname.login.length) {
7182: if (document.$formname.login.length > 0) {
7183: var loginpicked = 0;
7184: for (var i=0; i<document.$formname.login.length; i++) {
7185: if (document.$formname.login[i].checked == true) {
7186: loginpicked = 1;
7187: logintype = document.$formname.login[i].value;
7188: }
7189: }
7190: if (loginpicked == 0) {
7191: alert("$alerts{'authen'}");
7192: return;
7193: }
7194: }
7195: } else {
7196: logintype = document.$formname.login.value;
7197: }
7198: if (logintype == 'nochange') {
7199: return 'ok';
7200: }
7201: var argpicked = document.$formname.elements[logintype+'arg'].value;
7202: if ((argpicked == null) || (argpicked == '') || (typeof argpicked == 'undefined')) {
7203: var alertmsg = '';
7204: switch (logintype) {
7205: case 'krb':
7206: alertmsg = '$alerts{'krb'}';
7207: break;
7208: case 'int':
7209: alertmsg = '$alerts{'ipass'}';
7210: break;
7211: case 'fsys':
7212: alertmsg = '$alerts{'ipass'}';
7213: break;
7214: case 'loc':
7215: alertmsg = '';
7216: break;
7217: default:
7218: alertmsg = '';
7219: }
7220: if (alertmsg != '') {
7221: alert(alertmsg);
7222: return;
7223: }
7224: } else if (logintype == 'int') {
7225: var numrules = $numrules;
7226: if (numrules > 0) {
7227: $intargjs
7228: }
7229: }
7230: $finish
7231: }
7232: ENDSCRIPT
7233: }
7234:
7235: sub sectioncheck_alerts {
7236: my %alerts = &Apache::lonlocal::texthash(
7237: curd => 'You must select a course or community in the current domain',
7238: inea => 'In each course, each user may only have one student role at a time',
7239: inco => 'In each community, each user may only have one member role at a time',
7240: youh => 'You had selected',
7241: sect => 'sections',
7242: plsm => 'Please modify your selections so they include no more than one section',
7243: mayn => 'may not be used as the name for a section, as it is a reserved word',
7244: plsc => 'Please choose a different section name',
7245: mayt => 'may not be used as the name for a section, as it is the name of a course group',
7246: mayc => 'may not be used as the name for a section, as it is the name of a community group',
7247: secn => 'Section names and group names must be distinct',
7248: secd => 'Section designations do not apply to ',
7249: role => 'roles',
7250: accr => 'role will be added with access to all sections',
7251: thwa => 'There was a problem with your course selection',
7252: thwc => 'There was a problem with your community selection',
7253: );
7254: &js_escape(\%alerts);
7255: return %alerts;
7256: }
7257:
7258: sub authcheck_alerts {
7259: my %alerts =
7260: &Apache::lonlocal::texthash(
7261: authen => 'You must choose an authentication type.',
7262: krb => 'You need to specify the Kerberos domain.',
7263: ipass => 'You need to specify the initial password.',
7264: );
7265: &js_escape(\%alerts);
7266: return %alerts;
7267: }
7268:
7269: sub is_courseowner {
7270: my ($thiscourse,$courseowner) = @_;
7271: if ($courseowner eq '') {
7272: if ($env{'request.course.id'} eq $thiscourse) {
7273: $courseowner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
7274: }
7275: }
7276: if ($courseowner ne '') {
7277: if ($courseowner eq $env{'user.name'}.':'.$env{'user.domain'}) {
7278: return 1;
7279: }
7280: }
7281: return;
7282: }
7283:
7284: sub get_selfenroll_titles {
7285: my @row = ('types','registered','enroll_dates','access_dates','section',
7286: 'approval','limit');
7287: my %lt = &Apache::lonlocal::texthash (
7288: types => 'Users allowed to self-enroll',
7289: registered => 'Registration status (official courses)' ,
7290: enroll_dates => 'Dates self-enrollment available',
7291: access_dates => 'Access dates for self-enrolling users',
7292: section => "Self-enrolling users' section",
7293: approval => 'Processing of requests',
7294: limit => 'Enrollment limit',
7295: );
7296: return (\@row,\%lt);
7297: }
7298:
7299: sub selfenroll_default_descs {
7300: my %desc = (
7301: types => {
7302: dom => &mt('Course domain'),
7303: all => &mt('Any domain'),
7304: '' => &mt('None'),
7305: },
7306: limit => {
7307: none => &mt('No limit'),
7308: allstudents => &mt('Limit by total students'),
7309: selfenrolled => &mt('Limit by total self-enrolled'),
7310: },
7311: approval => {
7312: '0' => &mt('Processed automatically'),
7313: '1' => &mt('Queued for approval'),
7314: '2' => &mt('Queued, pending validation'),
7315: },
7316: registered => {
7317: 0 => 'No registration required',
7318: 1 => 'Registered students only',
7319: },
7320: );
7321: return %desc;
7322: }
7323:
7324: sub selfenroll_validation_types {
7325: my @items = ('url','fields','button','markup');
7326: my %names = &Apache::lonlocal::texthash (
7327: url => 'Web address of validation server/script',
7328: fields => 'Form fields to send to validator',
7329: button => 'Text for validation button',
7330: markup => 'Validation description (HTML)',
7331: );
7332: my @fields = ('username','domain','uniquecode','course','coursetype','description');
7333: return (\@items,\%names,\@fields);
7334: }
7335:
7336: sub get_extended_type {
7337: my ($cdom,$cnum,$crstype,$current) = @_;
7338: my $type = 'unofficial';
7339: my %settings;
7340: if (ref($current) eq 'HASH') {
7341: %settings = %{$current};
7342: } else {
7343: %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook'],$cdom,$cnum);
7344: }
7345: if ($crstype eq 'Community') {
7346: $type = 'community';
7347: } elsif ($crstype eq 'Placement') {
7348: $type = 'placement';
7349: } elsif ($settings{'internal.coursecode'}) {
7350: $type = 'official';
7351: } elsif ($settings{'internal.textbook'}) {
7352: $type = 'textbook';
7353: }
7354: return $type;
7355: }
7356:
7357: sub selfenrollment_administration {
7358: my ($cdom,$cnum,$crstype,$coursehash) = @_;
7359: my %settings;
7360: if (ref($coursehash) eq 'HASH') {
7361: %settings = %{$coursehash};
7362: } else {
7363: %settings = &Apache::lonnet::get('environment',
7364: ['internal.selfenrollmgrdc','internal.selfenrollmgrcc',
7365: 'internal.coursecode','internal.textbook'],$cdom,$cnum);
7366: }
7367: my ($possconfigs) = &get_selfenroll_titles();
7368: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
7369: my $selfenrolltype = &get_extended_type($cdom,$cnum,$crstype,\%settings);
7370:
7371: my (@in_course,@in_domain);
7372: if ($settings{'internal.selfenrollmgrcc'} ne '') {
7373: @in_course = split(/,/,$settings{'internal.selfenrollmgrcc'});
7374: my @diffs = &Apache::loncommon::compare_arrays($possconfigs,\@in_course);
7375: unless (@diffs) {
7376: return (\@in_course,\@in_domain);
7377: }
7378: }
7379: if ($settings{'internal.selfenrollmgrdc'} ne '') {
7380: @in_domain = split(/,/,$settings{'internal.selfenrollmgrdc'});
7381: my @diffs = &Apache::loncommon::compare_arrays(\@in_domain,$possconfigs);
7382: unless (@diffs) {
7383: return (\@in_course,\@in_domain);
7384: }
7385: }
7386: my @combined = @in_course;
7387: push(@combined,@in_domain);
7388: my @diffs = &Apache::loncommon::compare_arrays(\@combined,$possconfigs);
7389: unless (@diffs) {
7390: return (\@in_course,\@in_domain);
7391: }
7392: if ($domdefaults{$selfenrolltype.'selfenrolladmdc'} eq '') {
7393: push(@in_course,@diffs);
7394: } else {
7395: my @defaultdc = split(/,/,$domdefaults{$selfenrolltype.'selfenrolladmdc'});
7396: foreach my $item (@diffs) {
7397: if (grep(/^\Q$item\E$/,@defaultdc)) {
7398: push(@in_domain,$item);
7399: } else {
7400: push(@in_course,$item);
7401: }
7402: }
7403: }
7404: return (\@in_course,\@in_domain);
7405: }
7406:
7407: sub custom_role_header {
7408: my ($context,$crstype,$templaterolerefs,$prefix) = @_;
7409: my %lt = &Apache::lonlocal::texthash(
7410: sele => 'Select a Template',
7411: );
7412: my ($context_code,$button_code);
7413: if ($context eq 'domain') {
7414: $context_code = &custom_coursetype_switch($crstype,$prefix);
7415: }
7416: if (ref($templaterolerefs) eq 'ARRAY') {
7417: foreach my $role (@{$templaterolerefs}) {
7418: my $display = 'inline';
7419: if (($context eq 'domain') && ($role eq 'co')) {
7420: $display = 'none';
7421: }
7422: $button_code .= &make_button_code($role,$crstype,$display,$prefix).' ';
7423: }
7424: }
7425: return <<"END";
7426: <div class="LC_left_float">
7427: <fieldset>
7428: <legend>$lt{'sele'}</legend>
7429: $button_code
7430: </fieldset></div>
7431: $context_code
7432: <br clear="all" />
7433: END
7434: }
7435:
7436: sub custom_coursetype_switch {
7437: my ($crstype,$prefix) = @_;
7438: my ($checkedcourse,$checkedcommunity);
7439: if ($crstype eq 'Community') {
7440: $checkedcommunity = ' checked="checked"';
7441: } else {
7442: $checkedcourse = ' checked="checked"';
7443: }
7444: my %lt = &Apache::lonlocal::texthash(
7445: cont => 'Context',
7446: cour => 'Course',
7447: comm => 'Community',
7448: );
7449: return <<"END";
7450: <div class="LC_left_float">
7451: <fieldset>
7452: <legend>$lt{'cont'}</legend>
7453: <label>
7454: <input type="radio" name="${prefix}_custrolecrstype" value="Course"$checkedcourse onclick="javascript:customSwitchType('$prefix');" />
7455: $lt{'cour'}
7456: </label>
7457: <label>
7458: <input type="radio" name="${prefix}_custrolecrstype" value="Community"$checkedcommunity onclick="javascript:customSwitchType('$prefix');" />
7459: $lt{'comm'}
7460: </label>
7461: </fieldset>
7462: </div>
7463: END
7464: }
7465:
7466: sub custom_role_table {
7467: my ($crstype,$full,$levels,$levelscurrent,$prefix,$add_class,$id) = @_;
7468: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7469: (ref($levelscurrent) eq 'HASH'));
7470: my %lt=&Apache::lonlocal::texthash (
7471: 'prv' => "Privilege",
7472: 'crl' => "Course Level",
7473: 'dml' => "Domain Level",
7474: 'ssl' => "System Level");
7475: my %cr = (
7476: course => '_c',
7477: domain => '_d',
7478: system => '_s',
7479: );
7480:
7481: my $output=&Apache::loncommon::start_data_table($add_class,$id).
7482: &Apache::loncommon::start_data_table_header_row().
7483: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
7484: '</th><th>'.$lt{'ssl'}.'</th>'.
7485: &Apache::loncommon::end_data_table_header_row();
7486: foreach my $priv (sort(keys(%{$full}))) {
7487: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7488: $output .= &Apache::loncommon::start_data_table_row().
7489: '<td><span id="'.$prefix.$priv.'">'.$privtext.'</span></td>';
7490: foreach my $type ('course','domain','system') {
7491: if (($type eq 'system') && ($priv eq 'bre') && ($crstype eq 'Community')) {
7492: $output .= '<td> </td>';
7493: } else {
7494: $output .= '<td>'.
7495: ($levels->{$type}{$priv}?'<input type="checkbox" id="'.$prefix.$priv.$cr{$type}.'"'.
7496: ' name="'.$prefix.$priv.$cr{$type}.'"'.
7497: ($levelscurrent->{$type}{$priv}?' checked="checked"':'').' />':' ').
7498: '</td>';
7499: }
7500: }
7501: $output .= &Apache::loncommon::end_data_table_row();
7502: }
7503: $output .= &Apache::loncommon::end_data_table();
7504: return $output;
7505: }
7506:
7507: sub custom_role_privs {
7508: my ($privs,$full,$levels,$levelscurrent)= @_;
7509: return unless ((ref($privs) eq 'HASH') && (ref($full) eq 'HASH') &&
7510: (ref($levels) eq 'HASH') && (ref($levelscurrent) eq 'HASH'));
7511: my %cr = (
7512: course => 'cr:c',
7513: domain => 'cr:d',
7514: system => 'cr:s',
7515: );
7516: foreach my $type ('course','domain','system') {
7517: foreach my $item (split(/\:/,$Apache::lonnet::pr{$cr{$type}})) {
7518: my ($priv,$restrict)=split(/\&/,$item);
7519: if (!$restrict) { $restrict='F'; }
7520: $levels->{$type}->{$priv}=$restrict;
7521: if ($privs->{$type}=~/\:$priv/) {
7522: $levelscurrent->{$type}->{$priv}=1;
7523: }
7524: $full->{$priv}=1;
7525: }
7526: }
7527: return;
7528: }
7529:
7530: sub custom_template_roles {
7531: my ($context,$crstype) = @_;
7532: my @template_roles = ("in","ta","ep");
7533: if (($context eq 'domain') || ($context eq 'domprefs')) {
7534: push(@template_roles,"ad");
7535: }
7536: push(@template_roles,"st");
7537: if ($context eq 'domain') {
7538: unshift(@template_roles,('co','cc'));
7539: } else {
7540: if ($crstype eq 'Community') {
7541: unshift(@template_roles,'co');
7542: } else {
7543: unshift(@template_roles,'cc');
7544: }
7545: }
7546: return @template_roles;
7547: }
7548:
7549: sub custom_roledefs_js {
7550: my ($context,$crstype,$formname,$full,$templaterolesref,$jsback) = @_;
7551: my $button_code = "\n";
7552: my $head_script = "\n";
7553: my (%roletitlestr,$rolenamestr);
7554: my %role_titles = (
7555: Course => [],
7556: Community => [],
7557: );
7558: $head_script .= '<script type="text/javascript">'."\n"
7559: .'// <![CDATA['."\n";
7560: if (ref($templaterolesref) eq 'ARRAY') {
7561: if ($context eq 'domain') {
7562: $rolenamestr = join("','",@{$templaterolesref});
7563: }
7564: foreach my $role (@{$templaterolesref}) {
7565: $head_script .= &make_script_template($role,$crstype,$formname);
7566: if ($context eq 'domain') {
7567: foreach my $type ('Course','Community') {
7568: push(@{$role_titles{$type}},&Apache::lonnet::plaintext($role,$type));
7569: }
7570: }
7571: }
7572: }
7573: if ($context eq 'domain') {
7574: foreach my $type ('Course','Community') {
7575: $roletitlestr{$type} = join("','",@{$role_titles{$type}});
7576: }
7577: my %pt = (
7578: Community => {
7579: cst => &mt('Grant/revoke role of Member'),
7580: mdc => &mt('Edit community contents'),
7581: pch => &mt('Post discussion on community resources'),
7582: pfo => &mt('Print for other users and entire community'),
7583: },
7584: Course => {
7585: cst => &mt('Grant/revoke role of Student'),
7586: mdc => &mt('Edit course contents'),
7587: pch => &mt('Post discussion on course resources'),
7588: pfo => &mt('Print for other users and entire course'),
7589: },
7590: );
7591: $head_script .= <<"ENDJS";
7592: function customSwitchType(prefix) {
7593: var privnames = new Array('cst','mdc','pch','pfo');
7594: var privtxtcrs = new Array('$pt{Course}{cst}','$pt{Course}{mdc}','$pt{Course}{pch}','$pt{Course}{pfo}');
7595: var privtxtcom = new Array('$pt{Community}{cst}','$pt{Community}{mdc}','$pt{Community}{pch}','$pt{Community}{pfo}');
7596: var rolenames = new Array('$rolenamestr');
7597: var rolescrs = new Array('$roletitlestr{Course}');
7598: var rolescom = new Array('$roletitlestr{Community}');
7599: var radio = prefix+'_custrolecrstype';
7600: if (document.$formname.elements[radio].length > 1) {
7601: for (var i=0; i<document.$formname.elements[radio].length; i++) {
7602: if (document.$formname.elements[radio][i].checked) {
7603: if ((document.getElementById(prefix+'bre_s')) && (document.getElementById(prefix+'bro_s'))) {
7604: if (document.$formname.elements[radio][i].value == 'Community') {
7605: if (document.getElementById(prefix+'bre_s').checked) {
7606: document.getElementById(prefix+'bro_s').checked = true;
7607: document.getElementById(prefix+'bre_s').checked = false;
7608:
7609: }
7610: document.getElementById(prefix+'bre_s').style.visibility = 'hidden';
7611: } else {
7612: document.getElementById(prefix+'bre_s').style.visibility = 'visible';
7613: if (document.getElementById(prefix+'bro_s').checked) {
7614: document.getElementById(prefix+'bre_s').checked = true;
7615: document.getElementById(prefix+'bro_s').checked = false;
7616: }
7617: }
7618: }
7619: for (var j=0; j<privnames.length; j++) {
7620: if (document.getElementById(prefix+privnames[j])) {
7621: if (document.getElementById(prefix+privnames[j])) {
7622: if (document.$formname.elements[radio][i].value == 'Course') {
7623: document.getElementById(prefix+privnames[j]).innerHTML = privtxtcrs[j];
7624: } else {
7625: document.getElementById(prefix+privnames[j]).innerHTML = privtxtcom[j];
7626: }
7627: }
7628: }
7629: }
7630: for (var j=0; j<rolenames.length; j++) {
7631: if (document.getElementById(prefix+rolenames[j])) {
7632: if (document.getElementById(prefix+rolenames[j])) {
7633: if (document.$formname.elements[radio][i].value == 'Course') {
7634: document.getElementById(prefix+rolenames[j]).value = rolescrs[j];
7635: if (rolenames[j] == 'cc') {
7636: document.getElementById(prefix+rolenames[j]).style.display = 'inline';
7637: }
7638: if (rolenames[j] == 'co') {
7639: document.getElementById(prefix+rolenames[j]).style.display = 'none';
7640: }
7641: } else {
7642: document.getElementById(prefix+rolenames[j]).value = rolescom[j];
7643: if (rolenames[j] == 'cc') {
7644: document.getElementById(prefix+rolenames[j]).style.display = 'none';
7645: }
7646: if (rolenames[j] == 'co') {
7647: document.getElementById(prefix+rolenames[j]).style.display = 'inline';
7648: }
7649: }
7650: }
7651: }
7652: }
7653: }
7654: }
7655: }
7656: return;
7657: }
7658: ENDJS
7659: }
7660: $head_script .= "\n".$jsback."\n"
7661: .'// ]]>'."\n"
7662: .'</script>'."\n";
7663: return $head_script;
7664: }
7665:
7666: # --------------------------------------------------------
7667: sub make_script_template {
7668: my ($role,$crstype,$formname) = @_;
7669: my $return_script = 'function set_'.$role.'(prefix) {'."\n";
7670: my (%full_by_level,%role_priv);
7671: foreach my $level ('c','d','s') {
7672: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
7673: next if (($level eq 's') && ($crstype eq 'Community') && ($item eq 'bre&S'));
7674: my ($priv,$restrict)=split(/\&/,$item);
7675: $full_by_level{$level}{$priv}=1;
7676: }
7677: $role_priv{$level} = {};
7678: my @temp = split(/:/,$Apache::lonnet::pr{$role.':'.$level});
7679: foreach my $priv (@temp) {
7680: my ($priv_item, $dummy) = split(/\&/,$priv);
7681: $role_priv{$level}{$priv_item} = 1;
7682: }
7683: }
7684: my %to_check = (
7685: c => ['c','d','s'],
7686: d => ['d','s'],
7687: s => ['s'],
7688: );
7689: foreach my $level ('c','d','s') {
7690: if (ref($full_by_level{$level}) eq 'HASH') {
7691: foreach my $priv (keys(%{$full_by_level{$level}})) {
7692: my $value = 'false';
7693: if (ref($to_check{$level}) eq 'ARRAY') {
7694: foreach my $lett (@{$to_check{$level}}) {
7695: if (exists($role_priv{$lett}{$priv})) {
7696: $value = 'true';
7697: last;
7698: }
7699: }
7700: $return_script .= "document.$formname.elements[prefix+'".$priv."_".$level."'].checked = $value;\n";
7701: }
7702: }
7703: }
7704: }
7705: $return_script .= '}'."\n";
7706: return ($return_script);
7707: }
7708: # ----------------------------------------------------------
7709: sub make_button_code {
7710: my ($role,$crstype,$display,$prefix) = @_;
7711: my $label = &Apache::lonnet::plaintext($role,$crstype);
7712: my $button_code = '<input type="button" onclick="set_'.$role."('$prefix'".')" '.
7713: 'id="'.$prefix.$role.'" value="'.$label.'" '.
7714: 'style="display:'.$display.'" />';
7715: return ($button_code);
7716: }
7717:
7718: sub custom_role_update {
7719: my ($rolename,$prefix) = @_;
7720: # ------------------------------------------------------- What can be assigned?
7721: my %privs = (
7722: c => '',
7723: d => '',
7724: s => '',
7725: );
7726: foreach my $level (keys(%privs)) {
7727: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
7728: my ($priv,$restrict)=split(/\&/,$item);
7729: if (!$restrict) { $restrict=''; }
7730: if ($env{'form.'.$prefix.$priv.'_'.$level}) {
7731: $privs{$level} .=':'.$item;
7732: }
7733: }
7734: }
7735: return %privs;
7736: }
7737:
7738: sub adhoc_status_types {
7739: my ($cdom,$context,$role,$selectedref,$othertitle,$usertypes,$types,$disabled) = @_;
7740: my $output = &Apache::loncommon::start_data_table();
7741: my $numinrow = 3;
7742: my $rem;
7743: if (ref($types) eq 'ARRAY') {
7744: for (my $i=0; $i<@{$types}; $i++) {
7745: if (defined($usertypes->{$types->[$i]})) {
7746: my $rem = $i%($numinrow);
7747: if ($rem == 0) {
7748: if ($i > 0) {
7749: $output .= &Apache::loncommon::end_data_table_row();
7750: }
7751: $output .= &Apache::loncommon::start_data_table_row();
7752: }
7753: my $check;
7754: if (ref($selectedref) eq 'ARRAY') {
7755: if (grep(/^\Q$types->[$i]\E$/,@{$selectedref})) {
7756: $check = ' checked="checked"';
7757: }
7758: }
7759: $output .= '<td>'.
7760: '<span class="LC_nobreak"><label>'.
7761: '<input type="checkbox" name="'.$context.$role.'_status" '.
7762: 'value="'.$types->[$i].'"'.$check.$disabled.' />'.
7763: $usertypes->{$types->[$i]}.'</label></span></td>';
7764: }
7765: }
7766: $rem = @{$types}%($numinrow);
7767: }
7768: my $colsleft = $numinrow - $rem;
7769: if (($rem == 0) && (@{$types} > 0)) {
7770: $output .= &Apache::loncommon::start_data_table_row();
7771: }
7772: if ($colsleft > 1) {
7773: $output .= '<td colspan="'.$colsleft.'">';
7774: } else {
7775: $output .= '<td>';
7776: }
7777: my $defcheck;
7778: if (ref($selectedref) eq 'ARRAY') {
7779: if (grep(/^default$/,@{$selectedref})) {
7780: $defcheck = ' checked="checked"';
7781: }
7782: }
7783: $output .= '<span class="LC_nobreak"><label>'.
7784: '<input type="checkbox" name="'.$context.$role.'_status"'.
7785: 'value="default"'.$defcheck.$disabled.' />'.
7786: $othertitle.'</label></span></td>'.
7787: &Apache::loncommon::end_data_table_row().
7788: &Apache::loncommon::end_data_table();
7789: return $output;
7790: }
7791:
7792: sub adhoc_staff {
7793: my ($access,$context,$role,$selectedref,$adhocref,$disabled) = @_;
7794: my $output;
7795: if (ref($adhocref) eq 'HASH') {
7796: my %by_fullname;
7797: my $numinrow = 4;
7798: my $rem;
7799: my @personnel = keys(%{$adhocref});
7800: if (@personnel) {
7801: foreach my $person (@personnel) {
7802: my ($uname,$udom) = split(/:/,$person);
7803: my $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
7804: $by_fullname{$fullname} = $person;
7805: }
7806: my @sorted = sort(keys(%by_fullname));
7807: my $count = scalar(@sorted);
7808: $output = &Apache::loncommon::start_data_table();
7809: for (my $i=0; $i<$count; $i++) {
7810: my $rem = $i%($numinrow);
7811: if ($rem == 0) {
7812: if ($i > 0) {
7813: $output .= &Apache::loncommon::end_data_table_row();
7814: }
7815: $output .= &Apache::loncommon::start_data_table_row();
7816: }
7817: my $check;
7818: my $user = $by_fullname{$sorted[$i]};
7819: if (ref($selectedref) eq 'ARRAY') {
7820: if (grep(/^\Q$user\E$/,@{$selectedref})) {
7821: $check = ' checked="checked"';
7822: }
7823: }
7824: if ($i == $count-1) {
7825: my $colsleft = $numinrow - $rem;
7826: if ($colsleft > 1) {
7827: $output .= '<td colspan="'.$colsleft.'">';
7828: } else {
7829: $output .= '<td>';
7830: }
7831: } else {
7832: $output .= '<td>';
7833: }
7834: $output .= '<span class="LC_nobreak"><label>'.
7835: '<input type="checkbox" name="'.$context.$role.'_staff_'.$access.'" '.
7836: 'value="'.$user.'"'.$check.$disabled.' />'.$sorted[$i].
7837: '</label></span></td>';
7838: if ($i == $count-1) {
7839: $output .= &Apache::loncommon::end_data_table_row();
7840: }
7841: }
7842: $output .= &Apache::loncommon::end_data_table();
7843: }
7844: }
7845: return $output;
7846: }
7847:
7848:
7849: 1;
7850:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>