File:
[LON-CAPA] /
loncom /
interface /
lonuserutils.pm
Revision
1.216:
download - view:
text,
annotated -
select for diffs
Tue Aug 1 15:56:32 2023 UTC (12 months, 2 weeks ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- "User Self-Enrollment" link/icon always shown in Administration box in
People > Users for course personnel with privilege to assign student roles,
even if course configuration (set by DC) makes all self-enrollment options
configurable by a DC and not a CC (settings will be readonly by CC).
1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
4: # $Id: lonuserutils.pm,v 1.216 2023/08/01 15:56:32 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) = @_;
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: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
119: }
120: if ($context eq 'domain') {
121: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
122: if ($uhome ne 'no_host') {
123: if (($changeauth eq 'Yes') && (&Apache::lonnet::allowed('mau',$udom))) {
124: if ((($umode =~ /^krb4|krb5|internal$/) && $upass ne '') ||
125: ($umode eq 'localauth')) {
126: $authresult = &Apache::lonnet::modifyuserauth($udom,$uname,$umode,$upass);
127: }
128: }
129: if (($forceid) && (&Apache::lonnet::allowed('mau',$udom)) &&
130: ($env{'form.recurseid'}) && ($checkid)) {
131: my %userupdate = (
132: lastname => $last,
133: middlename => $middle,
134: firstname => $first,
135: generation => $gene,
136: id => $uid,
137: );
138: $idresult = &propagate_id_change($uname,$udom,\%userupdate);
139: }
140: }
141: }
142: $userresult =
143: &Apache::lonnet::modifyuser($udom,$uname,$uid,$umode,$upass,$first,
144: $middle,$last,$gene,$forceid,$desiredhome,
145: $email,$inststatus);
146: if ($userresult eq 'ok') {
147: if ($role ne '') {
148: $role =~ s/_/\//g;
149: $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
150: $role,$end,$start,'',
151: '',$context);
152: }
153: }
154: return ($userresult,$authresult,$roleresult,$idresult);
155: }
156:
157: sub role_approval {
158: my ($dom,$context,$process_by,$notifydc) = @_;
159: if (ref($process_by) eq 'HASH') {
160: my %domconfig = &Apache::lonnet::get_dom('configuration',['privacy'],$dom);
161: if (ref($domconfig{'privacy'}) eq 'HASH') {
162: if (ref($notifydc) eq 'ARRAY') {
163: if ($domconfig{'privacy'}{'notify'} ne '') {
164: @{$notifydc} = split(/,/,$domconfig{'privacy'}{'notify'});
165: }
166: }
167: if (ref($domconfig{'privacy'}{'approval'}) eq 'HASH') {
168: my %approvalconf = %{$domconfig{'privacy'}{'approval'}};
169: foreach my $key ('instdom','extdom') {
170: if (ref($approvalconf{$key}) eq 'HASH') {
171: if (keys(%{$approvalconf{$key}})) {
172: $process_by->{$key} = $approvalconf{$key}{$context};
173: }
174: }
175: }
176: }
177: }
178: }
179: return;
180: }
181:
182: sub get_instdoms {
183: my ($udom,$instdoms) = @_;
184: return unless (ref($instdoms) eq 'ARRAY');
185: my @intdoms;
186: my %iphost = &Apache::lonnet::get_iphost();
187: my $primary_id = &Apache::lonnet::domain($udom,'primary');
188: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
189: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
190: foreach my $id (@{$iphost{$primary_ip}}) {
191: my $intdom = &Apache::lonnet::internet_dom($id);
192: unless(grep(/^\Q$intdom\E$/,@intdoms)) {
193: push(@intdoms,$intdom);
194: }
195: }
196: }
197: foreach my $ip (keys(%iphost)) {
198: if (ref($iphost{$ip}) eq 'ARRAY') {
199: foreach my $id (@{$iphost{$ip}}) {
200: my $location = &Apache::lonnet::internet_dom($id);
201: if ($location) {
202: if (grep(/^\Q$location\E$/,@intdoms)) {
203: my $dom = &Apache::lonnet::host_domain($id);
204: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
205: push(@{$instdoms},$dom);
206: }
207: }
208: }
209: }
210: }
211: }
212: return;
213: }
214:
215: sub restricted_dom {
216: my ($context,$key,$udom,$uname,$role,$start,$end,$cdom,$cnum,$csec,$credits,
217: $process_by,$instdoms,$got_role_approvals,$got_instdoms,$reject,$pending,
218: $notifydc,$status,$unauthorized,$currqueued) = @_;
219: return if ($udom eq $cdom);
220: return unless ((ref($process_by) eq 'HASH') && (ref($instdoms) eq 'HASH') &&
221: (ref($got_role_approvals) eq 'HASH') && (ref($got_instdoms) eq 'HASH') &&
222: (ref($reject) eq 'HASH') && (ref($pending) eq 'HASH') &&
223: (ref($notifydc) eq 'HASH') && (ref($status) eq 'HASH') &&
224: (ref($unauthorized) eq 'HASH') && (ref($currqueued) eq 'HASH'));
225: my (%approval,@notify,$gotdata,$skip);
226: if (ref($got_role_approvals->{$context}) eq 'HASH') {
227: if ($got_role_approvals->{$context}{$udom}) {
228: $gotdata = 1;
229: if (ref($process_by->{$context}{$udom}) eq 'HASH') {
230: %approval = %{$process_by->{$context}{$udom}};
231: }
232: }
233: }
234: unless ($gotdata) {
235: &role_approval($udom,$context,\%approval,\@notify);
236: $process_by->{$context} = {
237: $udom => \%approval,
238: };
239: $got_role_approvals->{$context} = {
240: $udom => 1,
241: };
242: $notifydc->{$udom} = \@notify;
243: }
244: if (ref($process_by->{$context}) eq 'HASH') {
245: if (ref($process_by->{$context}{$udom}) eq 'HASH') {
246: my @inst;
247: if ($got_instdoms->{$udom}) {
248: if (ref($instdoms->{$udom}) eq 'ARRAY') {
249: @inst = @{$instdoms->{$udom}};
250: }
251: } else {
252: &get_instdoms(\@inst);
253: $instdoms->{$udom} = \@inst;
254: $got_instdoms->{$udom} = 1;
255: }
256: if (grep(/^\Q$cdom\E$/,@inst)) {
257: if (exists($approval{'instdom'})) {
258: my $rule = $approval{'instdom'};
259: if (($rule eq 'none') || ($rule eq 'user') || ($rule eq 'domain')) {
260: my ($id,$currstatus,$curradj) = &get_othdomreq_status($key,$uname,$udom,$role,$cdom,$cnum,$csec);
261: if (($currstatus ne '') && ($curradj eq $rule)) {
262: $status->{$key}->{$uname.':'.$udom} = $currstatus;
263: }
264: if ($rule eq 'none') {
265: $reject->{$key}->{$uname.':'.$udom} = {
266: cdom => $cdom,
267: cnum => $cnum,
268: csec => $csec,
269: udom => $udom,
270: uname => $uname,
271: role => $role,
272: };
273: $skip = 1;
274: } elsif (($rule eq 'user') || ($rule eq 'domain')) {
275: if ($curradj eq $rule) {
276: unless ($currstatus eq 'approved') {
277: if ($currstatus eq 'rejected') {
278: $unauthorized->{$key}->{$uname.':'.$udom} = {
279: cdom => $cdom,
280: cnum => $cnum,
281: csec => $csec,
282: udom => $udom,
283: uname => $uname,
284: role => $role,
285: };
286: } elsif ($currstatus eq 'pending') {
287: $currqueued->{$key}->{$uname.':'.$udom} = {
288: cdom => $cdom,
289: cnum => $cnum,
290: csec => $csec,
291: udom => $udom,
292: uname => $uname,
293: role => $role,
294: adj => $rule,
295: };
296: }
297: $skip = 1;
298: }
299: } else {
300: $pending->{$key}->{$uname.':'.$udom} = {
301: cdom => $cdom,
302: cnum => $cnum,
303: csec => $csec,
304: udom => $udom,
305: uname => $uname,
306: role => $role,
307: start => $start,
308: end => $end,
309: adj => $rule,
310: };
311: if (($role eq 'st') && ($credits ne '')) {
312: $pending->{$key}->{$uname.':'.$udom}->{'credits'} = $credits;
313: }
314: $skip = 1;
315: }
316: }
317: }
318: }
319: } elsif (exists($approval{'extdom'})) {
320: my $rule = $approval{'extdom'};
321: if (($rule eq 'none') || ($rule eq 'user') || ($rule eq 'domain')) {
322: my ($id,$currstatus,$curradj) = &get_othdomreq_status($key,$uname,$udom,$role,$cdom,$cnum,$csec);
323: if (($currstatus ne '') && ($curradj eq $rule)) {
324: $status->{$key}->{$uname.':'.$udom} = $currstatus;
325: }
326: if ($rule eq 'none') {
327: $reject->{$key}->{$uname.':'.$udom} = {
328: cdom => $cdom,
329: cnum => $cnum,
330: csec => $csec,
331: udom => $udom,
332: uname => $uname,
333: role => $role,
334: };
335: $skip = 1;
336: } elsif (($rule eq 'user') || ($rule eq 'domain')) {
337: if ($curradj eq $rule) {
338: unless ($currstatus eq 'approved') {
339: if ($currstatus eq 'rejected') {
340: $unauthorized->{$key}->{$uname.':'.$udom} = {
341: cdom => $cdom,
342: cnum => $cnum,
343: csec => $csec,
344: udom => $udom,
345: uname => $uname,
346: role => $role,
347: };
348: } elsif ($currstatus eq 'pending') {
349: $currqueued->{$key}->{$uname.':'.$udom} = {
350: cdom => $cdom,
351: cnum => $cnum,
352: csec => $csec,
353: udom => $udom,
354: uname => $uname,
355: role => $role,
356: adj => $rule,
357: };
358: }
359: $skip = 1;
360: }
361: } else {
362: $pending->{$key}->{$uname.':'.$udom} = {
363: cdom => $cdom,
364: cnum => $cnum,
365: csec => $csec,
366: udom => $udom,
367: uname => $uname,
368: role => $role,
369: start => $start,
370: end => $end,
371: adj => $rule,
372: };
373: if (($role eq 'st') && ($credits ne '')) {
374: $pending->{$key}->{$uname.':'.$udom}->{'credits'} = $credits;
375: }
376: $skip = 1;
377: }
378: }
379: }
380: }
381: }
382: }
383: return $skip;
384: }
385:
386: sub get_othdomreq_status {
387: my ($key,$uname,$udom,$role,$cdom,$cnum,$csec) = @_;
388: my $id = $uname.':'.$udom.':'.$role;
389: my ($dbnum,$currstatus,$curradj);
390: if (($role eq 'ca') || ($role eq 'aa')) {
391: $dbnum = $cnum;
392: } elsif ($key eq $cdom.'_'.$role) {
393: $dbnum = &Apache::lonnet::get_domainconfiguser($cdom);
394: } else {
395: $id .= ':'.$csec;
396: $dbnum = $cnum;
397: }
398: my $statusid = 'status&'.$id;
399: my %curr = &Apache::lonnet::get('nohist_othdomqueued',[$id,$statusid],$cdom,$dbnum);
400: if (ref($curr{$id}) eq 'HASH') {
401: $curradj = $curr{$id}{'adj'};
402: }
403: $currstatus = $curr{$statusid};
404: return ($id,$currstatus,$curradj);
405: }
406:
407: sub print_roles_rejected {
408: my ($context,$reject,$unauthorized) = @_;
409: return unless ((ref($reject) eq 'HASH') || (ref($unauthorized) eq 'HASH'));
410: my $output;
411: if (keys(%{$reject}) > 0) {
412: $output = '<p class="LC_warning">'.
413: &mt("The following roles could not be assigned because the user is from another domain, and that domain's policies disallow it").'<ul>';
414: foreach my $key (sort(keys(%{$reject}))) {
415: if (ref($reject->{$key}) eq 'HASH') {
416: foreach my $user (sort(keys(%{$reject->{$key}}))) {
417: if (ref($reject->{$key}->{$user}) eq 'HASH') {
418: my ($crstype,$role,$cdom,$cnum,$csec,$title,$plainrole);
419: $role = $reject->{$key}->{$user}{'role'};
420: $cdom = $reject->{$key}->{$user}{'cdom'};
421: $cnum = $reject->{$key}->{$user}{'cnum'};
422: $csec = $reject->{$key}->{$user}{'csec'};
423: if (($context eq 'domain') && ($cnum ne '')) {
424: if (($role eq 'ca') || ($role eq 'aa')) {
425: $title = &Apache::loncommon::plainname($cnum,$cdom);
426: } else {
427: if (&Apache::lonnet::is_course($cdom,$cnum)) {
428: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
429: $crstype = $coursedata{'type'};
430: $title = $coursedata{'description'};
431: }
432: }
433: } elsif ($context eq 'course') {
434: $crstype = &Apache::loncommon::course_type();
435: }
436: my $plainrole = &Apache::lonnet::plaintext($role,$crstype);
437: $output .= '<li>'.&mt('User: [_1]',$reject->{$key}->{$user}{'uname'}).' | '.
438: &mt('Domain: [_1]',$reject->{$key}->{$user}{'udom'}).' | '.
439: &mt('Role: [_1]',$plainrole);
440: if ($crstype) {
441: if ($csec ne'') {
442: $output .= ' | '.&mt('Section: [_1]',$csec);
443: }
444: } elsif (($context eq 'domain') && (($role eq 'ca') || ($role eq 'aa'))) {
445: $output .= ' | '.&mt('Authoring Space belonging to: [_1]',$title);
446:
447: }
448: if (($context eq 'domain') && ($crstype)) {
449: $output .= ' | '.&mt("$crstype: [_1]",$title);
450: }
451: $output .= '</li>';
452: }
453: }
454: }
455: }
456: $output .= '</ul></p>';
457: }
458: if (keys(%{$unauthorized}) > 0) {
459: $output = '<p class="LC_warning">'.
460: &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>';
461: foreach my $key (sort(keys(%{$unauthorized}))) {
462: if (ref($unauthorized->{$key}) eq 'HASH') {
463: foreach my $user (sort(keys(%{$unauthorized->{$key}}))) {
464: if (ref($unauthorized->{$key}->{$user}) eq 'HASH') {
465: my ($crstype,$role,$cdom,$cnum,$csec,$title,$plainrole);
466: $role = $unauthorized->{$key}->{$user}{'role'};
467: $cdom = $unauthorized->{$key}->{$user}{'cdom'};
468: $cnum = $unauthorized->{$key}->{$user}{'cnum'};
469: $csec = $unauthorized->{$key}->{$user}{'csec'};
470: if (($context eq 'domain') && ($cnum ne '')) {
471: if (($role eq 'ca') || ($role eq 'aa')) {
472: $title = &mt('Authoring Space belonging to: [_1]',
473: &Apache::loncommon::plainname($cnum,$cdom));
474: } else {
475: if (&Apache::lonnet::is_course($cdom,$cnum)) {
476: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
477: $crstype = $coursedata{'type'};
478: $title = &mt("$crstype: [_1]",$coursedata{'description'});
479: }
480: }
481: } elsif ($context eq 'course') {
482: $crstype = &Apache::loncommon::course_type();
483: }
484: $plainrole = &Apache::lonnet::plaintext($role,$crstype);
485: $output .= '<li>'.&mt('User: [_1]',$unauthorized->{$key}->{$user}{'uname'}).' | '.
486: &mt('Domain: [_1]',$unauthorized->{$key}->{$user}{'udom'}).' | '.
487: &mt('Role: [_1]',$plainrole);
488: if ($crstype) {
489: if ($csec ne'') {
490: $output .= ' | '.&mt('Section: [_1]',$csec);
491: }
492: }
493: if ($title ne '') {
494: $output .= ' | '.$title;
495: }
496: $output .= '</li>';
497: }
498: }
499: }
500: }
501: $output .= '</ul></p>';
502: }
503: return $output;
504: }
505:
506: sub print_roles_queued {
507: my ($context,$pending,$notifydc,$currqueued) = @_;
508: return unless ((ref($pending) eq 'HASH') && (ref($notifydc) eq 'HASH') &&
509: (ref($currqueued) eq 'HASH'));
510: my $output;
511: if (keys(%{$pending}) > 0) {
512: my $now = time;
513: $output = '<p class="LC_warning">'.
514: &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>';
515: my (%todom,%touser,%crsqueue,%caqueue,%domqueue);
516: my $requester = $env{'user.name'}.':'.$env{'user.domain'};
517: foreach my $key (sort(keys(%{$pending}))) {
518: if (ref($pending->{$key}) eq 'HASH') {
519: foreach my $user (sort(keys(%{$pending->{$key}}))) {
520: if (ref($pending->{$key}->{$user}) eq 'HASH') {
521: my $role = $pending->{$key}->{$user}{'role'};
522: my $uname = $pending->{$key}->{$user}{'uname'};
523: my $udom = $pending->{$key}->{$user}{'udom'};
524: my $csec = $pending->{$key}->{$user}{'csec'};
525: my $cdom = $pending->{$key}->{$user}{'cdom'};
526: my $cnum = $pending->{$key}->{$user}{'cnum'};
527: my $adj = $pending->{$key}->{$user}{'adj'};
528: my $start = $pending->{$key}->{$user}{'start'};
529: my $end = $pending->{$key}->{$user}{'end'};
530: my $credits = $pending->{$key}->{$user}{'credits'};
531: my $now = time;
532: my ($crstype,$title,$plainrole,$extent,$id,$status);
533: if ($context eq 'course') {
534: $crstype = &Apache::loncommon::course_type();
535: $title = $env{'course.'.$env{'request.course.id'}.'.description'};
536: } elsif ($context eq 'domain') {
537: if (&Apache::lonnet::is_course($cdom,$cnum)) {
538: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
539: $crstype = $coursedata{'type'};
540: $title = $coursedata{'description'};
541: } elsif (($role eq 'ca') || ($role eq 'aa')) {
542: $title = &Apache::loncommon::plainname($cnum,$cdom);
543: }
544: }
545: $plainrole = &Apache::lonnet::plaintext($role,$crstype);
546: $extent = "/$cdom/$cnum";
547: $id = $uname.':'.$udom.':'.$role;
548: if (($context eq 'course') || ($crstype)) {
549: $id .= ':'.$csec;
550: }
551: $output .= '<li>'.&mt('User: [_1]',$uname).' | '.
552: &mt('Domain: [_1]',$udom).' | '.
553: &mt('Role: [_1]',$plainrole);
554: if ($crstype) {
555: if ($csec ne'') {
556: $output .= ' | '.&mt('Section: [_1]',$csec);
557: }
558: } elsif (($context eq 'domain') && (($role eq 'ca') || ($role eq 'aa'))) {
559: $output .= ' | '.&mt('Authoring Space belonging to: [_1]',$title);
560: }
561: if (($context eq 'domain') && ($crstype)) {
562: $output .= ' | '.&mt("$crstype: [_1]",$title);
563: }
564: if (($crstype) && ($csec ne '')) {
565: $extent .= "/$csec";
566: }
567: if ($adj eq 'user') {
568: $output .= '<br />'.&mt('Message sent to user for approval');
569: $touser{$uname.':'.$udom}{'pending:'.$extent.':'.$role} = {
570: timestamp => $now,
571: requester => $requester,
572: start => $start,
573: end => $end,
574: credits => $credits,
575: context => $context,
576: };
577: } elsif ($adj eq 'domain') {
578: $output .= '<br />'.&mt("Message sent to user's domain coordinator for approval");
579: $todom{$udom}{'pending:'.$uname.':'.$extent.':'.$role} = {
580: timestamp => $now,
581: requester => $requester,
582: start => $start,
583: end => $end,
584: credits => $credits,
585: context => $context,
586: };
587: }
588: $output .= '</li>';
589: if (($context eq 'course') || ($crstype)) {
590: $crsqueue{$cdom.'_'.$cnum}{$id} = {
591: timestamp => $now,
592: requester => $requester,
593: adj => $adj,
594: };
595: $crsqueue{$cdom.'_'.$cnum}{'status&'.$id} = 'pending';
596: } elsif (($context eq 'author') ||
597: (($context eq 'domain') && (($role eq 'ca') || ($role eq 'aa')))) {
598: $caqueue{$cnum.':'.$cdom}{$id} = {
599: timestamp => $now,
600: requester => $requester,
601: adj => $adj,
602: };
603: $caqueue{$cnum.':'.$cdom}{'status&'.$id} = 'pending';
604: } elsif ($context eq 'domain') {
605: $domqueue{$id} = {
606: timestamp => $now,
607: requester => $requester,
608: adj => $adj,
609: };
610: $domqueue{'status&'.$id} = 'pending';
611: }
612: }
613: }
614: }
615: }
616: $output .= '</ul></p>';
617: if (keys(%touser)) {
618: foreach my $key (keys(%touser)) {
619: my ($uname,$udom) = split(/:/,$key);
620: if (&Apache::lonnet::put('nohist_queuedrolereqs',$touser{$key},$udom,$uname) eq 'ok') {
621: my $owndomdesc = &Apache::lonnet::domain($udom);
622: &Apache::loncoursequeueadmin::send_selfserve_notification($uname.':'.$udom,
623: '','',$owndomdesc,$now,'othdomroleuser',$requester);
624: }
625: }
626: }
627: if (keys(%todom)) {
628: foreach my $dom (keys(%todom)) {
629: if (ref($todom{$dom}) eq 'HASH') {
630: my $confname = &Apache::lonnet::get_domainconfiguser($dom);
631: if (&Apache::lonnet::put('nohist_queuedrolereqs',$todom{$dom},$dom,$confname) eq 'ok') {
632: if (ref($notifydc->{$dom}) eq 'ARRAY') {
633: if (@{$notifydc->{$dom}} > 0) {
634: my $notifylist = join(',',@{$notifydc->{$dom}});
635: &Apache::loncoursequeueadmin::send_selfserve_notification($notifylist,
636: '','','',$now,'othdomroledc',$requester);
637: }
638: }
639: }
640: }
641: }
642: }
643: if (keys(%crsqueue)) {
644: foreach my $key (keys(%crsqueue)) {
645: my ($cdom,$cnum) = split(/_/,$key);
646: if (ref($crsqueue{$key}) eq 'HASH') {
647: &Apache::lonnet::put('nohist_othdomqueued',$crsqueue{$key},$cdom,$cnum);
648: }
649: }
650: }
651: if (keys(%caqueue)) {
652: foreach my $key (keys(%caqueue)) {
653: my ($auname,$audom) = split(/:/,$key);
654: if (ref($caqueue{$key}) eq 'HASH') {
655: &Apache::lonnet::put('nohist_othdomqueued',$caqueue{$key},$audom,$auname);
656: }
657: }
658: }
659: if (keys(%domqueue)) {
660: my $confname = &Apache::lonnet::get_domainconfiguser($env{'request.role.domain'});
661: &Apache::lonnet::put('nohist_othdomqueued',\%domqueue,$env{'request.role.domain'},$confname);
662: }
663: }
664: if (keys(%{$currqueued}) > 0) {
665: $output = '<p class="LC_warning">'.
666: &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>';
667: my $requester = $env{'user.name'}.':'.$env{'user.domain'};
668: foreach my $key (sort(keys(%{$currqueued}))) {
669: if (ref($currqueued->{$key}) eq 'HASH') {
670: foreach my $user (sort(keys(%{$currqueued->{$key}}))) {
671: if (ref($currqueued->{$key}->{$user}) eq 'HASH') {
672: my $role = $currqueued->{$key}->{$user}{'role'};
673: my $csec = $currqueued->{$key}->{$user}{'csec'};
674: my $cdom = $currqueued->{$key}->{$user}{'cdom'};
675: my $cnum = $currqueued->{$key}->{$user}{'cnum'};
676: my ($crstype,$title,$plainrole);
677: if ($context eq 'course') {
678: $crstype = &Apache::loncommon::course_type();
679: } elsif (($context eq 'domain') && ($cnum ne '')) {
680: if (($role eq 'ca') || ($role eq 'aa')) {
681: $title = &mt('Authoring Space belonging to: [_1]',
682: &Apache::loncommon::plainname($cnum,$cdom));
683: } elsif (&Apache::lonnet::is_course($cdom,$cnum)) {
684: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
685: $crstype = $coursedata{'type'};
686: $title = &mt("$crstype: [_1]",$coursedata{'description'});
687: }
688: }
689: $plainrole = &Apache::lonnet::plaintext($role,$crstype);
690: $output .= '<li>'.&mt('User: [_1]',$currqueued->{$key}->{$user}{'uname'}).' | '.
691: &mt('Domain: [_1]',$currqueued->{$key}->{$user}{'udom'}).' | '.
692: &mt('Role: [_1]',$plainrole);
693: if ($title ne '') {
694: $output .= ' | '.$title;
695: }
696: if ($crstype) {
697: if ($csec ne '') {
698: $output .= ' | '.&mt('Section: [_1]',$csec);
699: }
700: }
701: $output .= '</li>';
702: }
703: }
704: }
705: }
706: $output .= '</ul></p>';
707: }
708: return $output;
709: }
710:
711: sub propagate_id_change {
712: my ($uname,$udom,$user) = @_;
713: my (@types,@roles);
714: @types = ('active','future');
715: @roles = ('st');
716: my $idresult;
717: my %roleshash = &Apache::lonnet::get_my_roles($uname,
718: $udom,'userroles',\@types,\@roles);
719: my %args = (
720: one_time => 1,
721: );
722: foreach my $item (keys(%roleshash)) {
723: my ($cnum,$cdom,$role) = split(/:/,$item,-1);
724: my ($start,$end) = split(/:/,$roleshash{$item});
725: if (&Apache::lonnet::is_course($cdom,$cnum)) {
726: my $result = &update_classlist($cdom,$cnum,$udom,$uname,$user);
727: my %coursehash =
728: &Apache::lonnet::coursedescription($cdom.'_'.$cnum,\%args);
729: my $cdesc = $coursehash{'description'};
730: if ($cdesc eq '') {
731: $cdesc = $cdom.'_'.$cnum;
732: }
733: if ($result eq 'ok') {
734: $idresult .= &mt('Classlist update for "[_1]" in "[_2]".',$uname.':'.$udom,$cdesc).'<br />'."\n";
735: } else {
736: $idresult .= &mt('Error: "[_1]" during classlist update for "[_2]" in "[_3]".',$result,$uname.':'.$udom,$cdesc).'<br />'."\n";
737: }
738: }
739: }
740: return $idresult;
741: }
742:
743: sub update_classlist {
744: my ($cdom,$cnum,$udom,$uname,$user,$newend) = @_;
745: my ($uid,$classlistentry);
746: my $fullname =
747: &Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
748: $user->{'lastname'},$user->{'generation'},
749: 'lastname');
750: my %classhash = &Apache::lonnet::get('classlist',[$uname.':'.$udom],
751: $cdom,$cnum);
752: my @classinfo = split(/:/,$classhash{$uname.':'.$udom});
753: my $ididx=&Apache::loncoursedata::CL_ID() - 2;
754: my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2;
755: my $endidx = &Apache::loncoursedata::CL_END() - 2;
756: my $startidx = &Apache::loncoursedata::CL_START() - 2;
757: for (my $i=0; $i<@classinfo; $i++) {
758: if ($i == $endidx) {
759: if ($newend ne '') {
760: $classlistentry .= $newend.':';
761: } else {
762: $classlistentry .= $classinfo[$i].':';
763: }
764: } elsif ($i == $startidx) {
765: if ($newend ne '') {
766: if ($classinfo[$i] > $newend) {
767: $classlistentry .= $newend.':';
768: } else {
769: $classlistentry .= $classinfo[$i].':';
770: }
771: } else {
772: $classlistentry .= $classinfo[$i].':';
773: }
774: } elsif ($i == $ididx) {
775: if (defined($user->{'id'})) {
776: $classlistentry .= $user->{'id'}.':';
777: } else {
778: $classlistentry .= $classinfo[$i].':';
779: }
780: } elsif ($i == $nameidx) {
781: if (defined($user->{'lastname'})) {
782: $classlistentry .= $fullname.':';
783: } else {
784: $classlistentry .= $classinfo[$i].':';
785: }
786: } else {
787: $classlistentry .= $classinfo[$i].':';
788: }
789: }
790: $classlistentry =~ s/:$//;
791: my $reply=&Apache::lonnet::cput('classlist',
792: {"$uname:$udom" => $classlistentry},
793: $cdom,$cnum);
794: if (($reply eq 'ok') || ($reply eq 'delayed')) {
795: return 'ok';
796: } else {
797: return 'error: '.$reply;
798: }
799: }
800:
801:
802: ###############################################################
803: ###############################################################
804: # build a role type and role selection form
805: sub domain_roles_select {
806: # Set up the role type and role selection boxes when in
807: # domain context
808: #
809: # Role types
810: my @roletypes = ('domain','author','course','community');
811: my %lt = &role_type_names();
812: my $onchangefirst = "updateCols('showrole')";
813: my $onchangesecond = "updateCols('showrole')";
814: #
815: # build up the menu information to be passed to
816: # &Apache::loncommon::linked_select_forms
817: my %select_menus;
818: if ($env{'form.roletype'} eq '') {
819: $env{'form.roletype'} = 'domain';
820: }
821: foreach my $roletype (@roletypes) {
822: # set up the text for this domain
823: $select_menus{$roletype}->{'text'}= $lt{$roletype};
824: my $crstype;
825: if ($roletype eq 'community') {
826: $crstype = 'Community';
827: }
828: # we want a choice of 'default' as the default in the second menu
829: if ($env{'form.roletype'} ne '') {
830: $select_menus{$roletype}->{'default'} = $env{'form.showrole'};
831: } else {
832: $select_menus{$roletype}->{'default'} = 'Any';
833: }
834: # Now build up the other items in the second menu
835: my @roles;
836: if ($roletype eq 'domain') {
837: @roles = &domain_roles();
838: } elsif ($roletype eq 'author') {
839: @roles = &construction_space_roles();
840: } else {
841: my $custom = 1;
842: @roles = &course_roles('domain',undef,$custom,$roletype);
843: }
844: my $order = ['Any',@roles];
845: $select_menus{$roletype}->{'order'} = $order;
846: foreach my $role (@roles) {
847: if ($role eq 'cr') {
848: $select_menus{$roletype}->{'select2'}->{$role} =
849: &mt('Custom role');
850: } else {
851: $select_menus{$roletype}->{'select2'}->{$role} =
852: &Apache::lonnet::plaintext($role,$crstype);
853: }
854: }
855: $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
856: }
857: my $result = &Apache::loncommon::linked_select_forms
858: ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
859: 'roletype','showrole',\%select_menus,
860: ['domain','author','course','community'],$onchangefirst,
861: $onchangesecond);
862: return $result;
863: }
864:
865: ###############################################################
866: ###############################################################
867: sub hidden_input {
868: my ($name,$value) = @_;
869: return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n";
870: }
871:
872: sub print_upload_manager_header {
873: my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype,
874: $can_assign)=@_;
875: my $javascript;
876: #
877: if (! exists($env{'form.upfile_associate'})) {
878: $env{'form.upfile_associate'} = 'forward';
879: }
880: if ($env{'form.associate'} eq 'Reverse Association') {
881: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
882: $env{'form.upfile_associate'} = 'reverse';
883: } else {
884: $env{'form.upfile_associate'} = 'forward';
885: }
886: }
887: if ($env{'form.upfile_associate'} eq 'reverse') {
888: $javascript=&upload_manager_javascript_reverse_associate($can_assign);
889: } else {
890: $javascript=&upload_manager_javascript_forward_associate($can_assign);
891: }
892: #
893: # Deal with restored settings
894: my $password_choice = '';
895: if (exists($env{'form.ipwd_choice'}) &&
896: $env{'form.ipwd_choice'} ne '') {
897: # If a column was specified for password, assume it is for an
898: # internal password. This is a bug waiting to be filed (could be
899: # local or krb auth instead of internal) but I do not have the
900: # time to mess around with this now.
901: $password_choice = 'int';
902: }
903: #
904: my $groupslist;
905: if ($context eq 'course') {
906: $groupslist = &get_groupslist();
907: }
908: my $javascript_validations =
909: &javascript_validations('upload',$krbdefdom,$password_choice,undef,
910: $env{'request.role.domain'},$context,
911: $groupslist,$crstype);
912: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
913: $r->print(
914: '<h3>'.&mt('Identify fields in uploaded list')."</h3>\n".
915: '<p class="LC_info">'.
916: &mt('Total number of records found in file: [_1]'
917: ,'<b>'.$distotal.'</b>').
918: "</p>\n"
919: );
920: if ($distotal == 0) {
921: $r->print('<p class="LC_warning">'.&mt('None found').'</p>');
922: }
923: $r->print(
924: '<p>'.
925: &mt('Enter as many fields as you can.').'<br />'.
926: &mt('The system will inform you and bring you back to this page,[_1]if the data selected are insufficient to add users.','<br />').
927: "</p>\n"
928: );
929: $r->print(&hidden_input('action','upload').
930: &hidden_input('state','got_file').
931: &hidden_input('associate','').
932: &hidden_input('datatoken',$datatoken).
933: &hidden_input('fileupload',$env{'form.fileupload'}).
934: &hidden_input('upfiletype',$env{'form.upfiletype'}).
935: &hidden_input('upfile_associate',$env{'form.upfile_associate'}));
936: $r->print(
937: '<div class="LC_left_float">'.
938: '<fieldset><legend>'.&mt('Functions').'</legend>'.
939: '<label><input type="checkbox" name="noFirstLine"'.$checked.' />'.
940: &mt('Ignore First Line').'</label>'.
941: ' <input type="button" value="'.&mt('Reverse Association').'" '.
942: 'name="Reverse Association" '.
943: 'onclick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />'.
944: '</fieldset></div><br clear="all" />'
945: );
946: $r->print(
947: '<script type="text/javascript" language="Javascript">'."\n".
948: '// <![CDATA['."\n".
949: $javascript."\n".$javascript_validations."\n".
950: '// ]]>'."\n".
951: '</script>'
952: );
953: }
954:
955: ###############################################################
956: ###############################################################
957: sub javascript_validations {
958: my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain,
959: $context,$groupslist,$crstype)=@_;
960: my %param = (
961: kerb_def_dom => $krbdefdom,
962: curr_authtype => $curr_authtype,
963: );
964: if ($mode eq 'upload') {
965: $param{'formname'} = 'studentform';
966: } elsif ($mode eq 'createcourse') {
967: $param{'formname'} = 'ccrs';
968: } elsif ($mode eq 'modifycourse') {
969: $param{'formname'} = 'cmod';
970: $param{'mode'} = 'modifycourse',
971: $param{'curr_autharg'} = $curr_authfield;
972: }
973:
974: my $showcredits;
975: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
976: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
977: $showcredits = 1;
978: }
979:
980: my ($setsection_call,$setsections_js);
981: my $finish = " vf.submit();\n";
982: if ($mode eq 'upload') {
983: if (($context eq 'course') || ($context eq 'domain')) {
984: if ($context eq 'course') {
985: if ($env{'request.course.sec'} eq '') {
986: $setsection_call = 'setSections(document.'.$param{'formname'}.",'$crstype'".');';
987: $setsections_js =
988: &setsections_javascript($param{'formname'},$groupslist,
989: $mode,'',$crstype,$showcredits);
990: } else {
991: $setsection_call = "'ok'";
992: }
993: } elsif ($context eq 'domain') {
994: $setsection_call = 'setCourse()';
995: $setsections_js = &dc_setcourse_js($param{'formname'},$mode,
996: $context,$showcredits,$domain);
997: }
998: $finish = " var checkSec = $setsection_call\n".
999: " if (checkSec == 'ok') {\n".
1000: " vf.submit();\n".
1001: " }\n";
1002: }
1003: }
1004: my $authheader = &Apache::loncommon::authform_header(%param);
1005:
1006: my %alert = &Apache::lonlocal::texthash
1007: (username => 'You need to specify the username field.',
1008: authen => 'You must choose an authentication type.',
1009: krb => 'You need to specify the Kerberos domain.',
1010: ipass => 'You need to specify the initial password.',
1011: name => 'The optional name field was not specified.',
1012: snum => 'The optional student/employee ID field was not specified.',
1013: section => 'The optional section field was not specified.',
1014: email => 'The optional e-mail address field was not specified.',
1015: role => 'The optional role field was not specified.',
1016: domain => 'The optional domain field was not specified.',
1017: continue => 'Continue adding users?',
1018: );
1019: if ($showcredits) {
1020: $alert{'credits'} = &mt('The optional credits field was not specified');
1021: }
1022: if (($mode eq 'upload') && ($context eq 'domain')) {
1023: $alert{'inststatus'} = &mt('The optional affiliation field was not specified');
1024: }
1025: &js_escape(\%alert);
1026: my $function_name = <<"END";
1027: $setsections_js
1028:
1029: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits) {
1030: END
1031: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($domain);
1032: my $auth_checks;
1033: if ($mode eq 'createcourse') {
1034: $auth_checks .= (<<END);
1035: if (vf.autoadds[0].checked == true) {
1036: if (current.radiovalue == null || current.radiovalue == 'nochange') {
1037: alert('$alert{'authen'}');
1038: return;
1039: }
1040: }
1041: END
1042: } else {
1043: $auth_checks .= (<<END);
1044: var foundatype=0;
1045: if (founduname==0) {
1046: alert('$alert{'username'}');
1047: return;
1048: }
1049:
1050: END
1051: if ($authnum > 1) {
1052: $auth_checks .= (<<END);
1053: if (current.radiovalue == null || current.radiovalue == '' || current.radiovalue == 'nochange') {
1054: // They did not check any of the login radiobuttons.
1055: alert('$alert{'authen'}');
1056: return;
1057: }
1058: END
1059: }
1060: }
1061: if ($mode eq 'createcourse') {
1062: $auth_checks .= "
1063: if ( (vf.autoadds[0].checked == true) &&
1064: (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') ) {
1065: ";
1066: } elsif ($mode eq 'modifycourse') {
1067: $auth_checks .= "
1068: if ((current.argfield !== null) && (current.argfield !== undefined) && (current.argfield !== '') && (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '')) {
1069: ";
1070: }
1071: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
1072: $auth_checks .= (<<END);
1073: var alertmsg = '';
1074: switch (current.radiovalue) {
1075: case 'krb':
1076: alertmsg = '$alert{'krb'}';
1077: break;
1078: default:
1079: alertmsg = '';
1080: }
1081: if (alertmsg != '') {
1082: alert(alertmsg);
1083: return;
1084: }
1085: }
1086: /* regexp here to check for non \d \. in credits */
1087: END
1088: } else {
1089: my ($numrules,$intargjs) =
1090: &Apache::loncommon::passwd_validation_js('vf.elements[current.argfield].value',$domain);
1091: $auth_checks .= (<<END);
1092: foundatype=1;
1093: if (current.argfield == null || current.argfield == '') {
1094: // The login radiobutton checked does not have an associated textbox
1095: } else if (vf.elements[current.argfield].value == '') {
1096: var alertmsg = '';
1097: switch (current.radiovalue) {
1098: case 'krb':
1099: alertmsg = '$alert{'krb'}';
1100: break;
1101: case 'int':
1102: alertmsg = '$alert{'ipass'}';
1103: break;
1104: case 'fsys':
1105: alertmsg = '$alert{'ipass'}';
1106: break;
1107: case 'loc':
1108: alertmsg = '';
1109: break;
1110: case 'lti':
1111: default:
1112: alertmsg = '';
1113: }
1114: if (alertmsg != '') {
1115: alert(alertmsg);
1116: return;
1117: }
1118: } else if (current.radiovalue == 'int') {
1119: if ($numrules > 0) {
1120: $intargjs
1121: }
1122: }
1123: END
1124: }
1125: my $section_checks;
1126: my $optional_checks = '';
1127: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
1128: $optional_checks = (<<END);
1129: vf.submit();
1130: }
1131: END
1132: } else {
1133: $section_checks = §ion_check_js();
1134: $optional_checks = (<<END);
1135: var message='';
1136: if (foundname==0) {
1137: message='$alert{'name'}';
1138: }
1139: if (foundid==0) {
1140: if (message!='') {
1141: message+='\\n';
1142: }
1143: message+='$alert{'snum'}';
1144: }
1145: if (foundsec==0) {
1146: if (message!='') {
1147: message+='\\n';
1148: }
1149: message+='$alert{'section'}';
1150: }
1151: if (foundemail==0) {
1152: if (message!='') {
1153: message+='\\n';
1154: }
1155: message+='$alert{'email'}';
1156: }
1157: if (foundrole==0) {
1158: if (message!='') {
1159: message+='\\n';
1160: }
1161: message+='$alert{'role'}';
1162: }
1163: if (founddomain==0) {
1164: if (message!='') {
1165: message+='\\n';
1166: }
1167: message+='$alert{'domain'}';
1168: }
1169: END
1170: if ($showcredits) {
1171: $optional_checks .= <<END;
1172: if (foundcredits==0) {
1173: if (message!='') {
1174: message+='\\n';
1175: }
1176: message+='$alert{'credits'}';
1177: }
1178: END
1179: }
1180: if (($mode eq 'upload') && ($context eq 'domain')) {
1181: $optional_checks .= (<<END);
1182:
1183: if (foundinststatus==0) {
1184: if (message!='') {
1185: message+='\\n';
1186: }
1187: message+='$alert{'inststatus'}';
1188: }
1189: END
1190: }
1191: $optional_checks .= (<<END);
1192:
1193: if (message!='') {
1194: message+= '\\n$alert{'continue'}';
1195: if (confirm(message)) {
1196: vf.state.value='enrolling';
1197: $finish
1198: }
1199: } else {
1200: vf.state.value='enrolling';
1201: $finish
1202: }
1203: }
1204: END
1205: }
1206: my $result = $function_name.$auth_checks.$optional_checks."\n".
1207: $section_checks.$authheader;
1208: return $result;
1209: }
1210:
1211: ###############################################################
1212: ###############################################################
1213: sub upload_manager_javascript_forward_associate {
1214: my ($can_assign) = @_;
1215: my ($auth_update,$numbuttons,$argreset);
1216: if (ref($can_assign) eq 'HASH') {
1217: if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
1218: $argreset .= " vf.krbarg.value='';\n";
1219: $numbuttons ++ ;
1220: }
1221: if ($can_assign->{'int'}) {
1222: $argreset .= " vf.intarg.value='';\n";
1223: $numbuttons ++;
1224: }
1225: if ($can_assign->{'loc'}) {
1226: $argreset .= " vf.locarg.value='';\n";
1227: $numbuttons ++;
1228: }
1229: if (!$can_assign->{'int'}) {
1230: 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".
1231: &mt('Your current role does not have rights to create users with that authentication type.');
1232: &js_escape(\$warning);
1233: $auth_update = <<"END";
1234: // Currently the initial password field is only supported for internal auth
1235: // (see bug 6368).
1236: if (nw==9) {
1237: eval('vf.f'+tf+'.selectedIndex=0;')
1238: alert('$warning');
1239: }
1240: END
1241: } elsif ($numbuttons > 1) {
1242: $auth_update = <<"END";
1243: // If we set the password, make the password form below correspond to
1244: // the new value.
1245: if (nw==9) {
1246: changed_radio('int',document.studentform);
1247: set_auth_radio_buttons('int',document.studentform);
1248: $argreset
1249: }
1250:
1251: END
1252: }
1253: }
1254:
1255: return(<<ENDPICK);
1256: function verify(vf,sec_caller) {
1257: var founduname=0;
1258: var foundpwd=0;
1259: var foundname=0;
1260: var foundid=0;
1261: var foundsec=0;
1262: var foundemail=0;
1263: var foundrole=0;
1264: var founddomain=0;
1265: var foundinststatus=0;
1266: var foundcredits=0;
1267: var tw;
1268: for (i=0;i<=vf.nfields.value;i++) {
1269: tw=eval('vf.f'+i+'.selectedIndex');
1270: if (tw==1) { founduname=1; }
1271: if ((tw>=2) && (tw<=6)) { foundname=1; }
1272: if (tw==7) { foundid=1; }
1273: if (tw==8) { foundsec=1; }
1274: if (tw==9) { foundpwd=1; }
1275: if (tw==10) { foundemail=1; }
1276: if (tw==11) { foundrole=1; }
1277: if (tw==12) { founddomain=1; }
1278: if (tw==13) { foundinststatus=1; }
1279: if (tw==14) { foundcredits=1; }
1280: }
1281: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits);
1282: }
1283:
1284: //
1285: // vf = this.form
1286: // tf = column number
1287: //
1288: // values of nw
1289: //
1290: // 0 = none
1291: // 1 = username
1292: // 2 = names (lastname, firstnames)
1293: // 3 = fname (firstname)
1294: // 4 = mname (middlename)
1295: // 5 = lname (lastname)
1296: // 6 = gen (generation)
1297: // 7 = id
1298: // 8 = section
1299: // 9 = ipwd (password)
1300: // 10 = email address
1301: // 11 = role
1302: // 12 = domain
1303: // 13 = inststatus
1304: // 14 = foundcredits
1305:
1306: function flip(vf,tf) {
1307: var nw=eval('vf.f'+tf+'.selectedIndex');
1308: var i;
1309: // make sure no other columns are labeled the same as this one
1310: for (i=0;i<=vf.nfields.value;i++) {
1311: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
1312: eval('vf.f'+i+'.selectedIndex=0;')
1313: }
1314: }
1315: // If we set this to 'lastname, firstnames', clear out all the ones
1316: // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
1317: if (nw==2) {
1318: for (i=0;i<=vf.nfields.value;i++) {
1319: if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
1320: (eval('vf.f'+i+'.selectedIndex')<=6)) {
1321: eval('vf.f'+i+'.selectedIndex=0;')
1322: }
1323: }
1324: }
1325: // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
1326: // clear out any that are set to 'lastname, firstnames' (2)
1327: if ((nw>=3) && (nw<=6)) {
1328: for (i=0;i<=vf.nfields.value;i++) {
1329: if (eval('vf.f'+i+'.selectedIndex')==2) {
1330: eval('vf.f'+i+'.selectedIndex=0;')
1331: }
1332: }
1333: }
1334: $auth_update
1335: }
1336:
1337: function clearpwd(vf) {
1338: var i;
1339: for (i=0;i<=vf.nfields.value;i++) {
1340: if (eval('vf.f'+i+'.selectedIndex')==9) {
1341: eval('vf.f'+i+'.selectedIndex=0;')
1342: }
1343: }
1344: }
1345:
1346: ENDPICK
1347: }
1348:
1349: ###############################################################
1350: ###############################################################
1351: sub upload_manager_javascript_reverse_associate {
1352: my ($can_assign) = @_;
1353: my ($auth_update,$numbuttons,$argreset);
1354: if (ref($can_assign) eq 'HASH') {
1355: if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
1356: $argreset .= " vf.krbarg.value='';\n";
1357: $numbuttons ++ ;
1358: }
1359: if ($can_assign->{'int'}) {
1360: $argreset .= " vf.intarg.value='';\n";
1361: $numbuttons ++;
1362: }
1363: if ($can_assign->{'loc'}) {
1364: $argreset .= " vf.locarg.value='';\n";
1365: $numbuttons ++;
1366: }
1367: if (!$can_assign->{'int'}) {
1368: my $warning = &mt('You may not specify an initial password, as this is only available when new users use LON-CAPA internal authentication.\n').
1369: &mt('Your current role does not have rights to create users with that authentication type.');
1370: &js_escape(\$warning);
1371: $auth_update = <<"END";
1372: // Currently the initial password field is only supported for internal auth
1373: // (see bug 6368).
1374: if (tf==8 && nw!=0) {
1375: eval('vf.f'+tf+'.selectedIndex=0;')
1376: alert('$warning');
1377: }
1378: END
1379: } elsif ($numbuttons > 1) {
1380: $auth_update = <<"END";
1381: // initial password specified, pick internal authentication
1382: if (tf==8 && nw!=0) {
1383: changed_radio('int',document.studentform);
1384: set_auth_radio_buttons('int',document.studentform);
1385: $argreset
1386: }
1387:
1388: END
1389: }
1390: }
1391:
1392: return(<<ENDPICK);
1393: function verify(vf,sec_caller) {
1394: var founduname=0;
1395: var foundpwd=0;
1396: var foundname=0;
1397: var foundid=0;
1398: var foundsec=0;
1399: var foundemail=0;
1400: var foundrole=0;
1401: var founddomain=0;
1402: var foundinststatus=0;
1403: var foundcredits=0;
1404: var tw;
1405: for (i=0;i<=vf.nfields.value;i++) {
1406: tw=eval('vf.f'+i+'.selectedIndex');
1407: if (i==0 && tw!=0) { founduname=1; }
1408: if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
1409: if (i==6 && tw!=0) { foundid=1; }
1410: if (i==7 && tw!=0) { foundsec=1; }
1411: if (i==8 && tw!=0) { foundpwd=1; }
1412: if (i==9 && tw!=0) { foundemail=1; }
1413: if (i==10 && tw!=0) { foundrole=1; }
1414: if (i==11 && tw!=0) { founddomain=1; }
1415: if (i==12 && tw!=0) { foundinstatus=1; }
1416: if (i==13 && tw!=0) { foundcredits=1; }
1417: }
1418: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits);
1419: }
1420:
1421: function flip(vf,tf) {
1422: var nw=eval('vf.f'+tf+'.selectedIndex');
1423: var i;
1424: // picked the all one name field, reset the other name ones to blank
1425: if (tf==1 && nw!=0) {
1426: for (i=2;i<=5;i++) {
1427: eval('vf.f'+i+'.selectedIndex=0;')
1428: }
1429: }
1430: //picked one of the piecewise name fields, reset the all in
1431: //one field to blank
1432: if ((tf>=2) && (tf<=5) && (nw!=0)) {
1433: eval('vf.f1.selectedIndex=0;')
1434: }
1435: $auth_update
1436: }
1437:
1438: function clearpwd(vf) {
1439: var i;
1440: if (eval('vf.f8.selectedIndex')!=0) {
1441: eval('vf.f8.selectedIndex=0;')
1442: }
1443: }
1444: ENDPICK
1445: }
1446:
1447: ###############################################################
1448: ###############################################################
1449: sub print_upload_manager_footer {
1450: my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context,$permission,$crstype,
1451: $showcredits) = @_;
1452: my $form = 'document.studentform';
1453: my $formname = 'studentform';
1454: my ($krbdef,$krbdefdom) =
1455: &Apache::loncommon::get_kerberos_defaults($defdom);
1456: my %param = ( formname => $form,
1457: kerb_def_dom => $krbdefdom,
1458: kerb_def_auth => $krbdef
1459: );
1460: if (exists($env{'form.ipwd_choice'}) &&
1461: defined($env{'form.ipwd_choice'}) &&
1462: $env{'form.ipwd_choice'} ne '') {
1463: $param{'curr_authtype'} = 'int';
1464: }
1465: my $krbform = &Apache::loncommon::authform_kerberos(%param);
1466: my $intform = &Apache::loncommon::authform_internal(%param);
1467: my $locform = &Apache::loncommon::authform_local(%param);
1468: my $ltiform = &Apache::loncommon::authform_lti(%param);
1469: my $date_table = &date_setting_table(undef,undef,$context,undef,
1470: $formname,$permission,$crstype);
1471:
1472: my $Str = "\n".'<div class="LC_left_float">';
1473: $Str .= &hidden_input('nfields',$i);
1474: $Str .= &hidden_input('keyfields',$keyfields);
1475:
1476: $Str .= '<h3>'.&mt('Options').'</h3>'
1477: .&Apache::lonhtmlcommon::start_pick_box();
1478:
1479: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Login Type'));
1480: if ($context eq 'domain') {
1481: $Str .= '<p>'
1482: .&mt('Change authentication for existing users in domain "[_1]" to these settings?'
1483: ,$defdom)
1484: .' <span class="LC_nobreak"><label>'
1485: .'<input type="radio" name="changeauth" value="No" checked="checked" />'
1486: .&mt('No').'</label>'
1487: .' <label>'
1488: .'<input type="radio" name="changeauth" value="Yes" />'
1489: .&mt('Yes').'</label>'
1490: .'</span></p>';
1491: } else {
1492: $Str .= '<p class="LC_info">'."\n".
1493: &mt('This will not take effect if the user already exists.').
1494: &Apache::loncommon::help_open_topic('Auth_Options').
1495: "</p>\n";
1496: }
1497: $Str .= &set_login($defdom,$krbform,$intform,$locform,$ltiform);
1498:
1499: my ($home_server_pick,$numlib) =
1500: &Apache::loncommon::home_server_form_item($defdom,'lcserver',
1501: 'default','hide');
1502: if ($numlib > 1) {
1503: $Str .= &Apache::lonhtmlcommon::row_closure()
1504: .&Apache::lonhtmlcommon::row_title(
1505: &mt('LON-CAPA Home Server for New Users'))
1506: .&mt('LON-CAPA domain: [_1] with home server:','"'.$defdom.'"')
1507: .$home_server_pick
1508: .&Apache::lonhtmlcommon::row_closure();
1509: } else {
1510: $Str .= $home_server_pick.
1511: &Apache::lonhtmlcommon::row_closure();
1512: }
1513:
1514: my ($trusted,$untrusted);
1515: if ($context eq 'course') {
1516: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1517: } elsif ($context eq 'author') {
1518: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1519: }
1520: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain'))
1521: .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1,undef,$trusted,$untrusted)
1522: .&Apache::lonhtmlcommon::row_closure();
1523:
1524: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Starting and Ending Dates'))
1525: ."<p>\n".$date_table."</p>\n"
1526: .&Apache::lonhtmlcommon::row_closure();
1527:
1528: if ($context eq 'domain') {
1529: $Str .= &Apache::lonhtmlcommon::row_title(
1530: &mt('Settings for assigning roles'))
1531: .&mt('Pick the action to take on roles for these users:').'<br />'
1532: .'<span class="LC_nobreak"><label>'
1533: .'<input type="radio" name="roleaction" value="norole" checked="checked" />'
1534: .' '.&mt('No role changes').'</label>'
1535: .' <label>'
1536: .'<input type="radio" name="roleaction" value="domain" />'
1537: .' '.&mt('Add a domain role').'</label>'
1538: .' <label>'
1539: .'<input type="radio" name="roleaction" value="course" />'
1540: .' '.&mt('Add a course/community role').'</label>'
1541: .'</span>';
1542: } elsif ($context eq 'author') {
1543: $Str .= &Apache::lonhtmlcommon::row_title(
1544: &mt('Default role'))
1545: .&mt('Choose the role to assign to users without a value specified in the uploaded file.')
1546: } elsif ($context eq 'course') {
1547: if ($showcredits) {
1548: $Str .= &Apache::lonhtmlcommon::row_title(
1549: &mt('Default role, section and credits'))
1550: .&mt('Choose the role and/or section(s) and/or credits to assign to users without values specified in the uploaded file.');
1551: } else {
1552: $Str .= &Apache::lonhtmlcommon::row_title(
1553: &mt('Default role and section'))
1554: .&mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file.');
1555: }
1556: } else {
1557: $Str .= &Apache::lonhtmlcommon::row_title(
1558: &mt('Default role and/or section(s)'))
1559: .&mt('Role and/or section(s) for users without values specified in the uploaded file.');
1560: }
1561: if (($context eq 'domain') || ($context eq 'author')) {
1562: $Str .= '<br />';
1563: my ($options,$cb_script,$coursepick) =
1564: &default_role_selector($context,1,'',$showcredits);
1565: if ($context eq 'domain') {
1566: $Str .= '<p>'
1567: .'<b>'.&mt('Domain Level').'</b><br />'
1568: .$options
1569: .'</p><p>'
1570: .'<b>'.&mt('Course Level').'</b>'
1571: .'</p>'
1572: .$cb_script.$coursepick
1573: .&Apache::lonhtmlcommon::row_closure();
1574: } elsif ($context eq 'author') {
1575: $Str .= $options
1576: .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
1577: }
1578: } else {
1579: my ($cnum,$cdom) = &get_course_identity();
1580: my $rowtitle = &mt('section');
1581: my $defaultcredits;
1582: if ($showcredits) {
1583: $defaultcredits = &get_defaultcredits();
1584: }
1585: my $secbox = §ion_picker($cdom,$cnum,'Any',$rowtitle,$permission,
1586: $context,'upload',$crstype,$showcredits,
1587: $defaultcredits);
1588: $Str .= $secbox
1589: .&Apache::lonhtmlcommon::row_closure();
1590: my %lt;
1591: if ($crstype eq 'Community') {
1592: %lt = &Apache::lonlocal::texthash (
1593: disp => 'Display members with current/future access who are not in the uploaded file',
1594: stus => 'Members selected from this list can be dropped.'
1595: );
1596: } else {
1597: %lt = &Apache::lonlocal::texthash (
1598: disp => 'Display students with current/future access who are not in the uploaded file',
1599: stus => 'Students selected from this list can be dropped.'
1600: );
1601: }
1602: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Full Update'))
1603: .'<label><input type="checkbox" name="fullup" value="yes" />'
1604: .' '.$lt{'disp'}
1605: .'</label><br />'
1606: .$lt{'stus'}
1607: .&Apache::lonhtmlcommon::row_closure();
1608: }
1609: if ($context eq 'course' || $context eq 'domain') {
1610: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID'))
1611: .&forceid_change($context)
1612: .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
1613: }
1614:
1615: $Str .= &Apache::lonhtmlcommon::end_pick_box();
1616: $Str .= '</div>';
1617:
1618: # Footer
1619: $Str .= '<div class="LC_clear_float_footer">'
1620: .'<hr />';
1621: if ($context eq 'course') {
1622: $Str .= '<p class="LC_info">'
1623: .&mt('Note: This operation may be time consuming when adding several users.')
1624: .'</p>';
1625: }
1626: $Str .= '<p><input type="button"'
1627: .' onclick="javascript:verify(this.form,this.form.csec)"'
1628: .' value="'.&mt('Update Users').'" />'
1629: .'</p>'."\n"
1630: .'</div>';
1631: $r->print($Str);
1632: return;
1633: }
1634:
1635: sub get_defaultcredits {
1636: my ($cdom,$cnum) = @_;
1637:
1638: if ($cdom eq '' || $cnum eq '') {
1639: return unless ($env{'request.course.id'});
1640: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1641: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1642: }
1643: return unless(($cdom =~ /^$match_domain$/) && ($cnum =~ /^$match_courseid$/));
1644: my ($defaultcredits,$domdefcredits);
1645: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
1646: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
1647: my $instcode = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
1648: if ($instcode) {
1649: $domdefcredits = $domdefaults{'officialcredits'};
1650: } elsif ($env{'course.'.$cdom.'_'.$cnum.'.internal.textbook'}) {
1651: $domdefcredits = $domdefaults{'textbookcredits'};
1652: } else {
1653: $domdefcredits = $domdefaults{'unofficialcredits'};
1654: }
1655: } else {
1656: return;
1657: }
1658:
1659: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
1660: $defaultcredits = $env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'};
1661: } elsif (exists($env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'})) {
1662: $defaultcredits = $env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'};
1663: } else {
1664: my %crsinfo =
1665: &Apache::lonnet::coursedescription("$cdom/$cnum",{'one_time' => 1});
1666: $defaultcredits = $crsinfo{'internal.defaultcredits'};
1667: }
1668: if ($defaultcredits eq '') {
1669: $defaultcredits = $domdefcredits;
1670: }
1671: return $defaultcredits;
1672: }
1673:
1674: sub forceid_change {
1675: my ($context) = @_;
1676: my $output =
1677: '<label><input type="checkbox" name="forceid" value="yes" />'
1678: .&mt('Force change of existing ID')
1679: .'</label>'.&Apache::loncommon::help_open_topic('ForceIDChange')."\n";
1680: if ($context eq 'domain') {
1681: $output .=
1682: '<br />'
1683: .'<label><input type="checkbox" name="recurseid" value="yes" />'
1684: .&mt("Update ID in user's course(s).").'</label>'."\n";
1685: }
1686: return $output;
1687: }
1688:
1689: ###############################################################
1690: ###############################################################
1691: sub print_upload_manager_form {
1692: my ($r,$context,$permission,$crstype,$showcredits) = @_;
1693: my $firstLine;
1694: my $datatoken;
1695: if (!$env{'form.datatoken'}) {
1696: $datatoken=&Apache::loncommon::upfile_store($r);
1697: } else {
1698: $datatoken=&Apache::loncommon::valid_datatoken($env{'form.datatoken'});
1699: if ($datatoken ne '') {
1700: &Apache::loncommon::load_tmp_file($r,$datatoken);
1701: }
1702: }
1703: if ($datatoken eq '') {
1704: $r->print('<p class="LC_error">'.&mt('Error').': '.
1705: &mt('Invalid datatoken').'</p>');
1706: return 'missingdata';
1707: }
1708: my @records=&Apache::loncommon::upfile_record_sep();
1709: if($env{'form.noFirstLine'}){
1710: $firstLine=shift(@records);
1711: }
1712: my $total=$#records;
1713: my $distotal=$total+1;
1714: my $today=time;
1715: my $halfyear=$today+15552000;
1716: #
1717: # Restore memorized settings
1718: my $col_setting_names = { 'username_choice' => 'scalar', # column settings
1719: 'names_choice' => 'scalar',
1720: 'fname_choice' => 'scalar',
1721: 'mname_choice' => 'scalar',
1722: 'lname_choice' => 'scalar',
1723: 'gen_choice' => 'scalar',
1724: 'id_choice' => 'scalar',
1725: 'sec_choice' => 'scalar',
1726: 'ipwd_choice' => 'scalar',
1727: 'email_choice' => 'scalar',
1728: 'role_choice' => 'scalar',
1729: 'domain_choice' => 'scalar',
1730: 'inststatus_choice' => 'scalar',
1731: };
1732: if ($showcredits) {
1733: $col_setting_names->{'credits_choice'} = 'scalar';
1734: }
1735: if ($context eq 'course') {
1736: &Apache::loncommon::restore_course_settings('enrollment_upload',
1737: $col_setting_names);
1738: } else {
1739: &Apache::loncommon::restore_settings($context,'user_upload',
1740: $col_setting_names);
1741: }
1742: my $defdom = $env{'request.role.domain'};
1743: #
1744: # Determine kerberos parameters as appropriate
1745: my ($krbdef,$krbdefdom) =
1746: &Apache::loncommon::get_kerberos_defaults($defdom);
1747: #
1748: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($defdom);
1749: &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
1750: $permission,$crstype,\%can_assign);
1751: my $i;
1752: my $keyfields;
1753: if ($total>=0) {
1754: my @field=
1755: (['username',&mt('Username'), $env{'form.username_choice'}],
1756: ['names',&mt('Last Name, First Names'),$env{'form.names_choice'}],
1757: ['fname',&mt('First Name'), $env{'form.fname_choice'}],
1758: ['mname',&mt('Middle Names/Initials'),$env{'form.mname_choice'}],
1759: ['lname',&mt('Last Name'), $env{'form.lname_choice'}],
1760: ['gen', &mt('Generation'), $env{'form.gen_choice'}],
1761: ['id', &mt('Student/Employee ID'),$env{'form.id_choice'}],
1762: ['sec', &mt('Section'), $env{'form.sec_choice'}],
1763: ['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
1764: ['email',&mt('E-mail Address'), $env{'form.email_choice'}],
1765: ['role',&mt('Role'), $env{'form.role_choice'}],
1766: ['domain',&mt('Domain'), $env{'form.domain_choice'}],
1767: ['inststatus',&mt('Affiliation'), $env{'form.inststatus_choice'}]);
1768: if ($showcredits) {
1769: push(@field,
1770: ['credits',&mt('Student Credits'), $env{'form.credits_choice'}]);
1771: }
1772: if ($env{'form.upfile_associate'} eq 'reverse') {
1773: &Apache::loncommon::csv_print_samples($r,\@records);
1774: $i=&Apache::loncommon::csv_print_select_table($r,\@records,
1775: \@field);
1776: foreach (@field) {
1777: $keyfields.=$_->[0].',';
1778: }
1779: chop($keyfields);
1780: } else {
1781: unshift(@field,['none','']);
1782: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
1783: \@field);
1784: my %sone=&Apache::loncommon::record_sep($records[0]);
1785: $keyfields=join(',',sort(keys(%sone)));
1786: }
1787: }
1788: &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
1789: $context,$permission,$crstype,$showcredits);
1790: return 'ok';
1791: }
1792:
1793: sub setup_date_selectors {
1794: my ($starttime,$endtime,$mode,$nolink,$formname) = @_;
1795: if ($formname eq '') {
1796: $formname = 'studentform';
1797: }
1798: if (! defined($starttime)) {
1799: $starttime = time;
1800: unless ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1801: if (exists($env{'course.'.$env{'request.course.id'}.
1802: '.default_enrollment_start_date'})) {
1803: $starttime = $env{'course.'.$env{'request.course.id'}.
1804: '.default_enrollment_start_date'};
1805: }
1806: }
1807: }
1808: if (! defined($endtime)) {
1809: $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1810: unless ($mode eq 'createcourse') {
1811: if (exists($env{'course.'.$env{'request.course.id'}.
1812: '.default_enrollment_end_date'})) {
1813: $endtime = $env{'course.'.$env{'request.course.id'}.
1814: '.default_enrollment_end_date'};
1815: }
1816: }
1817: }
1818:
1819: my $startdateform =
1820: &Apache::lonhtmlcommon::date_setter($formname,'startdate',$starttime,
1821: undef,undef,undef,undef,undef,undef,undef,$nolink);
1822:
1823: my $enddateform =
1824: &Apache::lonhtmlcommon::date_setter($formname,'enddate',$endtime,
1825: undef,undef,undef,undef,undef,undef,undef,$nolink);
1826:
1827: if ($mode eq 'create_enrolldates') {
1828: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1829: 'startenroll',
1830: $starttime);
1831: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1832: 'endenroll',
1833: $endtime);
1834: }
1835: if ($mode eq 'create_defaultdates') {
1836: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1837: 'startaccess',
1838: $starttime);
1839: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1840: 'endaccess',
1841: $endtime);
1842: }
1843: return ($startdateform,$enddateform);
1844: }
1845:
1846:
1847: sub get_dates_from_form {
1848: my ($startname,$endname) = @_;
1849: if ($startname eq '') {
1850: $startname = 'startdate';
1851: }
1852: if ($endname eq '') {
1853: $endname = 'enddate';
1854: }
1855: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
1856: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1857: if ($env{'form.no_end_date'}) {
1858: $enddate = 0;
1859: }
1860: return ($startdate,$enddate);
1861: }
1862:
1863: sub date_setting_table {
1864: my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission,$crstype) = @_;
1865: my $nolink;
1866: if ($bulkaction) {
1867: $nolink = 1;
1868: }
1869: my ($startform,$endform) =
1870: &setup_date_selectors($starttime,$endtime,$mode,$nolink,$formname);
1871: my $dateDefault;
1872: if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1873: $dateDefault = ' ';
1874: } elsif ($mode ne 'author' && $mode ne 'domain') {
1875: if (($bulkaction eq 'reenable') ||
1876: ($bulkaction eq 'activate') ||
1877: ($bulkaction eq 'chgdates') ||
1878: ($env{'form.action'} eq 'upload')) {
1879: if ($env{'request.course.sec'} eq '') {
1880: $dateDefault = '<span class="LC_nobreak">'.
1881: '<label><input type="checkbox" name="makedatesdefault" value="1" /> ';
1882: if ($crstype eq 'Community') {
1883: $dateDefault .= &mt("make these dates the default access dates for future community enrollment");
1884: } else {
1885: $dateDefault .= &mt("make these dates the default access dates for future course enrollment");
1886: }
1887: $dateDefault .= '</label></span>';
1888: }
1889: }
1890: }
1891: my $perpetual = '<span class="LC_nobreak"><label><input type="checkbox" name="no_end_date"';
1892: if (defined($endtime) && $endtime == 0) {
1893: $perpetual .= ' checked="checked"';
1894: }
1895: $perpetual.= ' /> '.&mt('no ending date').'</label></span>';
1896: if ($mode eq 'create_enrolldates') {
1897: $perpetual = ' ';
1898: }
1899: my $result = &Apache::lonhtmlcommon::start_pick_box()."\n";
1900: $result .= &Apache::lonhtmlcommon::row_title(&mt('Starting Date'),
1901: 'LC_oddrow_value')."\n".
1902: $startform."\n".
1903: &Apache::lonhtmlcommon::row_closure(1).
1904: &Apache::lonhtmlcommon::row_title(&mt('Ending Date'),
1905: 'LC_oddrow_value')."\n".
1906: $endform.' '.$perpetual.
1907: &Apache::lonhtmlcommon::row_closure(1).
1908: &Apache::lonhtmlcommon::end_pick_box();
1909: if ($dateDefault) {
1910: $result .= $dateDefault.'<br />'."\n";
1911: }
1912: return $result;
1913: }
1914:
1915: sub make_dates_default {
1916: my ($startdate,$enddate,$context,$crstype) = @_;
1917: my $result = '';
1918: if ($context eq 'course') {
1919: my ($cnum,$cdom) = &get_course_identity();
1920: my $put_result = &Apache::lonnet::put('environment',
1921: {'default_enrollment_start_date'=>$startdate,
1922: 'default_enrollment_end_date' =>$enddate},$cdom,$cnum);
1923: if ($put_result eq 'ok') {
1924: if ($crstype eq 'Community') {
1925: $result .= &mt('Set default start and end access dates for community.');
1926: } else {
1927: $result .= &mt('Set default start and end access dates for course.');
1928: }
1929: $result .= '<br />'."\n";
1930: #
1931: # Refresh the course environment
1932: &Apache::lonnet::coursedescription($env{'request.course.id'},
1933: {'freshen_cache' => 1});
1934: } else {
1935: if ($crstype eq 'Community') {
1936: $result .= &mt('Unable to set default access dates for community');
1937: } else {
1938: $result .= &mt('Unable to set default access dates for course');
1939: }
1940: $result .= ':'.$put_result.'<br />';
1941: }
1942: }
1943: return $result;
1944: }
1945:
1946: sub default_role_selector {
1947: my ($context,$checkpriv,$crstype,$showcredits) = @_;
1948: my %customroles;
1949: my ($options,$coursepick,$cb_jscript);
1950: if ($context ne 'author') {
1951: %customroles = &my_custom_roles($crstype);
1952: }
1953:
1954: my %lt=&Apache::lonlocal::texthash(
1955: 'rol' => "Role",
1956: 'grs' => "Section",
1957: 'exs' => "Existing sections",
1958: 'new' => "New section",
1959: 'crd' => "Credits",
1960: );
1961: $options = '<select name="defaultrole">'."\n".
1962: ' <option value="">'.&mt('Please select').'</option>'."\n";
1963: if ($context eq 'course') {
1964: $options .= &default_course_roles($context,$checkpriv,$crstype,%customroles);
1965: } elsif ($context eq 'author') {
1966: my @roles = &construction_space_roles($checkpriv);
1967: foreach my $role (@roles) {
1968: my $plrole=&Apache::lonnet::plaintext($role);
1969: $options .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1970: }
1971: } elsif ($context eq 'domain') {
1972: my @roles = &domain_roles($checkpriv);
1973: foreach my $role (@roles) {
1974: my $plrole=&Apache::lonnet::plaintext($role);
1975: $options .= ' <option value="'.$role.'">'.$plrole.'</option>';
1976: }
1977: my $courseform = &Apache::loncommon::selectcourse_link
1978: ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course/Community');
1979: my ($credit_elem,$creditsinput);
1980: if ($showcredits) {
1981: $credit_elem = 'credits';
1982: $creditsinput = '<td><input type="text" name="credits" value="" /></td>';
1983: }
1984: $cb_jscript =
1985: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform','courserole','Course/Community',$credit_elem);
1986: $coursepick = &Apache::loncommon::start_data_table().
1987: &Apache::loncommon::start_data_table_header_row().
1988: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th>'.
1989: '<th>'.$lt{'grs'}.'</th>'.
1990: '<th>'.$lt{'crd'}.'</th>'.
1991: &Apache::loncommon::end_data_table_header_row().
1992: &Apache::loncommon::start_data_table_row()."\n".
1993: '<td><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'studentform','dccourse','dcdomain','coursedesc','','','','crstype'".')" /></td>'."\n".
1994: '<td><select name="courserole">'."\n".
1995: &default_course_roles($context,$checkpriv,'Course',%customroles)."\n".
1996: '</select></td><td>'.
1997: '<table class="LC_createuser">'.
1998: '<tr class="LC_section_row"><td valign="top">'.
1999: $lt{'exs'}.'<br /><select name="currsec">'.
2000: ' <option value=""><--'.&mt('Pick course first').
2001: '</select></td>'.
2002: '<td> </td>'.
2003: '<td valign="top">'.$lt{'new'}.'<br />'.
2004: '<input type="text" name="newsec" value="" size="5" />'.
2005: '<input type="hidden" name="groups" value="" />'.
2006: '<input type="hidden" name="sections" value="" />'.
2007: '<input type="hidden" name="origdom" value="'.
2008: $env{'request.role.domain'}.'" />'.
2009: '<input type="hidden" name="dccourse" value="" />'.
2010: '<input type="hidden" name="dcdomain" value="" />'.
2011: '<input type="hidden" name="crstype" value="" />'.
2012: '</td></tr></table></td>'.$creditsinput.
2013: &Apache::loncommon::end_data_table_row().
2014: &Apache::loncommon::end_data_table()."\n";
2015: }
2016: $options .= '</select>';
2017: return ($options,$cb_jscript,$coursepick);
2018: }
2019:
2020: sub default_course_roles {
2021: my ($context,$checkpriv,$crstype,%customroles) = @_;
2022: my $output;
2023: my $custom = 1;
2024: my @roles = &course_roles($context,$checkpriv,$custom,lc($crstype));
2025: foreach my $role (@roles) {
2026: if ($role ne 'cr') {
2027: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
2028: $output .= ' <option value="'.$role.'">'.$plrole.'</option>';
2029: }
2030: }
2031: if (keys(%customroles) > 0) {
2032: if (grep(/^cr$/,@roles)) {
2033: foreach my $cust (sort(keys(%customroles))) {
2034: my $custrole='cr_'.$env{'user.domain'}.
2035: '_'.$env{'user.name'}.'_'.$cust;
2036: $output .= ' <option value="'.$custrole.'">'.$cust.'</option>';
2037: }
2038: }
2039: }
2040: return $output;
2041: }
2042:
2043: sub construction_space_roles {
2044: my ($checkpriv) = @_;
2045: my @allroles = &roles_by_context('author');
2046: my @roles;
2047: if ($checkpriv) {
2048: foreach my $role (@allroles) {
2049: if (&Apache::lonnet::allowed('c'.$role,$env{'user.domain'}.'/'.$env{'user.name'})) {
2050: push(@roles,$role);
2051: }
2052: }
2053: return @roles;
2054: } else {
2055: return @allroles;
2056: }
2057: }
2058:
2059: sub domain_roles {
2060: my ($checkpriv) = @_;
2061: my @allroles = &roles_by_context('domain');
2062: my @roles;
2063: if ($checkpriv) {
2064: foreach my $role (@allroles) {
2065: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
2066: push(@roles,$role);
2067: }
2068: }
2069: return @roles;
2070: } else {
2071: return @allroles;
2072: }
2073: }
2074:
2075: sub course_roles {
2076: my ($context,$checkpriv,$custom,$roletype) = @_;
2077: my $crstype;
2078: if ($roletype eq 'community') {
2079: $crstype = 'Community' ;
2080: } else {
2081: $crstype = 'Course';
2082: }
2083: my @allroles = &roles_by_context('course',$custom,$crstype);
2084: my @roles;
2085: if ($context eq 'domain') {
2086: @roles = @allroles;
2087: } elsif ($context eq 'course') {
2088: if ($env{'request.course.id'}) {
2089: if ($checkpriv) {
2090: foreach my $role (@allroles) {
2091: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
2092: push(@roles,$role);
2093: } else {
2094: if ((($role ne 'cc') && ($role ne 'co')) && ($env{'request.course.sec'} ne '')) {
2095: if (&Apache::lonnet::allowed('c'.$role,
2096: $env{'request.course.id'}.'/'.
2097: $env{'request.course.sec'})) {
2098: push(@roles,$role);
2099: }
2100: }
2101: }
2102: }
2103: } else {
2104: @roles = @allroles;
2105: }
2106: }
2107: }
2108: return @roles;
2109: }
2110:
2111: sub curr_role_permissions {
2112: my ($context,$setting,$checkpriv,$type) = @_;
2113: my $custom = 1;
2114: my @roles;
2115: if ($context eq 'author') {
2116: @roles = &construction_space_roles($checkpriv);
2117: } elsif ($context eq 'domain') {
2118: if ($setting eq 'course') {
2119: @roles = &course_roles($context,$checkpriv,$custom,$type);
2120: } else {
2121: @roles = &domain_roles($checkpriv);
2122: }
2123: } elsif ($context eq 'course') {
2124: @roles = &course_roles($context,$checkpriv,$custom,$type);
2125: }
2126: return @roles;
2127: }
2128:
2129: # ======================================================= Existing Custom Roles
2130:
2131: sub my_custom_roles {
2132: my ($crstype,$udom,$uname) = @_;
2133: my %returnhash=();
2134: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
2135: my %rolehash=&Apache::lonnet::dump('roles',$udom,$uname);
2136: foreach my $key (keys(%rolehash)) {
2137: if ($key=~/^rolesdef\_(\w+)$/) {
2138: my $role = $1;
2139: if ($crstype eq 'Community') {
2140: next if ($rolehash{$key} =~ /bre\&S/);
2141: }
2142: $returnhash{$role}=$role;
2143: }
2144: }
2145: return %returnhash;
2146: }
2147:
2148: sub print_userlist {
2149: my ($r,$mode,$permission,$context,$formname,$totcodes,$codetitles,
2150: $idlist,$idlist_titles,$showcredits) = @_;
2151: my $format = $env{'form.output'};
2152: if (! exists($env{'form.sortby'})) {
2153: $env{'form.sortby'} = 'username';
2154: }
2155: if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
2156: $env{'form.Status'} = 'Active';
2157: }
2158: my $onchange = "javascript:updateCols('Status');";
2159: my $status_select = &Apache::lonhtmlcommon::StatusOptions
2160: ($env{'form.Status'},undef,undef,$onchange);
2161:
2162: if ($env{'form.showrole'} eq '') {
2163: if ($context eq 'course') {
2164: $env{'form.showrole'} = 'st';
2165: } else {
2166: $env{'form.showrole'} = 'Any';
2167: }
2168: }
2169: if (! defined($env{'form.output'}) ||
2170: $env{'form.output'} !~ /^(csv|excel|html)$/ ) {
2171: $env{'form.output'} = 'html';
2172: }
2173:
2174: my @statuses;
2175: if ($env{'form.Status'} eq 'Any') {
2176: @statuses = ('previous','active','future');
2177: } elsif ($env{'form.Status'} eq 'Expired') {
2178: @statuses = ('previous');
2179: } elsif ($env{'form.Status'} eq 'Active') {
2180: @statuses = ('active');
2181: } elsif ($env{'form.Status'} eq 'Future') {
2182: @statuses = ('future');
2183: }
2184:
2185: # Interface output
2186: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
2187: '<input type="hidden" name="action" value="'.
2188: $env{'form.action'}.'" />');
2189: $r->print('<div>'."\n");
2190: if ($env{'form.action'} ne 'modifystudent') {
2191: my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
2192: 'excel' => "Excel",
2193: 'html' => 'HTML');
2194: my $output_selector = '<select size="1" name="output" onchange="javascript:updateCols('."'output'".');" >';
2195: foreach my $outputformat ('html','csv','excel') {
2196: my $option = '<option value="'.$outputformat.'"';
2197: if ($outputformat eq $env{'form.output'}) {
2198: $option .= ' selected="selected"';
2199: }
2200: $option .='>'.$lt{$outputformat}.'</option>';
2201: $output_selector .= "\n".$option;
2202: }
2203: $output_selector .= '</select>';
2204: $r->print('<span class="LC_nobreak">'
2205: .&mt('Output Format: [_1]',$output_selector)
2206: .'</span>'.(' 'x3));
2207: }
2208: $r->print('<span class="LC_nobreak">'
2209: .&mt('User Status: [_1]',$status_select)
2210: .'</span>'.(' 'x3)."\n");
2211: my $roleselected = '';
2212: if ($env{'form.showrole'} eq 'Any') {
2213: $roleselected = ' selected="selected"';
2214: }
2215: my ($cnum,$cdom);
2216: $r->print(&role_filter($context));
2217: if ($context eq 'course') {
2218: ($cnum,$cdom) = &get_course_identity();
2219: $r->print(§ion_group_filter($cnum,$cdom));
2220: }
2221: $r->print('</div><div class="LC_left_float">'.
2222: &column_checkboxes($context,$mode,$formname,$showcredits).
2223: '</div>');
2224: if ($env{'form.phase'} eq '') {
2225: $r->print('<br clear="all" />'.
2226: &list_submit_button(&mt('Display List of Users'))."\n".
2227: '<input type="hidden" name="phase" value="" /></form>');
2228: return;
2229: }
2230: if (!(($context eq 'domain') &&
2231: (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
2232: $r->print('<br clear="all" />'.
2233: &list_submit_button(&mt('Update Display'))."\n");
2234: }
2235:
2236: my @cols = &infocolumns($context,$mode,$showcredits);
2237: if (!@cols) {
2238: $r->print('<hr style="clear:both;" /><span class="LC_warning">'.
2239: &mt('No user information selected for display.').'</span>'.
2240: '<input type="hidden" name="phase" value="display" /></form>'."\n");
2241: return;
2242: }
2243: my ($indexhash,$keylist) = &make_keylist_array();
2244: my (%userlist,%userinfo,$clearcoursepick,$needauthorquota,$needauthorusage);
2245: if (($context eq 'domain') &&
2246: ($env{'form.roletype'} eq 'course') ||
2247: ($env{'form.roletype'} eq 'community')) {
2248: my ($crstype,$numcodes,$title,$warning);
2249: if ($env{'form.roletype'} eq 'course') {
2250: $crstype = 'Course';
2251: $numcodes = $totcodes;
2252: $title = &mt('Select Courses');
2253: $warning = &mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.');
2254: } elsif ($env{'form.roletype'} eq 'community') {
2255: $crstype = 'Community';
2256: $numcodes = 0;
2257: $title = &mt('Select Communities');
2258: $warning = &mt('Warning: data retrieval for multiple communities can take considerable time, as this operation is not currently optimized.');
2259: }
2260: my @standardnames = &Apache::loncommon::get_standard_codeitems();
2261: my $courseform =
2262: &Apache::lonhtmlcommon::course_selection($formname,$numcodes,
2263: $codetitles,$idlist,$idlist_titles,$crstype,
2264: \@standardnames);
2265: $r->print('<div class="LC_left_float">'.
2266: '<fieldset><legend>'.$title.'</legend>'."\n".
2267: $courseform."\n".
2268: '</fieldset></div><br clear="all" />'.
2269: '<p><input type="hidden" name="origroletype" value="'.$env{'form.roletype'}.'" />'.
2270: &list_submit_button(&mt('Update Display')).
2271: "\n".'</p><span class="LC_warning">'.$warning.'</span>'."\n");
2272: $clearcoursepick = 0;
2273: if (($env{'form.origroletype'} ne '') &&
2274: ($env{'form.origroletype'} ne $env{'form.roletype'})) {
2275: $clearcoursepick = 1;
2276: }
2277: if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
2278: $r->print('<hr />'.&mt('Searching ...').'<br /> <br />');
2279: }
2280: } else {
2281: $r->print('<hr style="clear:both;" /><div id="searching">'.&mt('Searching ...').'</div>');
2282: }
2283: $r->rflush();
2284: if ($context eq 'course') {
2285: if (($env{'form.showrole'} eq 'st') || ($env{'form.showrole'} eq 'Any')) {
2286: my $classlist = &Apache::loncoursedata::get_classlist();
2287: if (ref($classlist) eq 'HASH') {
2288: %userlist = %{$classlist};
2289: }
2290: }
2291: if ($env{'form.showrole'} ne 'st') {
2292: my $showroles;
2293: if ($env{'form.showrole'} ne 'Any') {
2294: $showroles = [$env{'form.showrole'}];
2295: } else {
2296: $showroles = undef;
2297: }
2298: my $withsec = 1;
2299: my $hidepriv = 1;
2300: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
2301: \@statuses,$showroles,undef,$withsec,$hidepriv);
2302: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
2303: \%advrolehash,$permission);
2304: }
2305: } else {
2306: my (%cstr_roles,%dom_roles);
2307: if ($context eq 'author') {
2308: # List co-authors and assistant co-authors
2309: my @possroles = &roles_by_context($context);
2310: %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
2311: \@statuses,\@possroles);
2312: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
2313: \%cstr_roles,$permission);
2314: } elsif ($context eq 'domain') {
2315: if ($env{'form.roletype'} eq 'domain') {
2316: if (grep(/^authorusage$/,@cols)) {
2317: $needauthorusage = 1;
2318: }
2319: if (grep(/^authorquota$/,@cols)) {
2320: $needauthorquota = 1;
2321: }
2322: %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'});
2323: foreach my $key (keys(%dom_roles)) {
2324: if (ref($dom_roles{$key}) eq 'HASH') {
2325: &gather_userinfo($context,$format,\%userlist,$indexhash,
2326: \%userinfo,$dom_roles{$key},$permission);
2327: }
2328: }
2329: } elsif ($env{'form.roletype'} eq 'author') {
2330: my %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'},['au']);
2331: my %coauthors;
2332: foreach my $key (keys(%dom_roles)) {
2333: if (ref($dom_roles{$key}) eq 'HASH') {
2334: if ($env{'form.showrole'} eq 'au') {
2335: &gather_userinfo($context,$format,\%userlist,$indexhash,
2336: \%userinfo,$dom_roles{$key},$permission);
2337: } else {
2338: my @possroles;
2339: if ($env{'form.showrole'} eq 'Any') {
2340: @possroles = &roles_by_context('author');
2341: } else {
2342: @possroles = ($env{'form.showrole'});
2343: }
2344: foreach my $author (sort(keys(%{$dom_roles{$key}}))) {
2345: my ($role,$authorname,$authordom) = split(/:/,$author,-1);
2346: my $extent = '/'.$authordom.'/'.$authorname;
2347: %{$coauthors{$extent}} =
2348: &Apache::lonnet::get_my_roles($authorname,
2349: $authordom,undef,\@statuses,\@possroles);
2350: }
2351: &gather_userinfo($context,$format,\%userlist,
2352: $indexhash,\%userinfo,\%coauthors,$permission);
2353: }
2354: }
2355: }
2356: } elsif (($env{'form.roletype'} eq 'course') ||
2357: ($env{'form.roletype'} eq 'community')) {
2358: if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
2359: my %courses = &process_coursepick();
2360: my %allusers;
2361: my $hidepriv = 1;
2362: foreach my $cid (keys(%courses)) {
2363: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
2364: next if ($cnum eq '' || $cdom eq '');
2365: my $custom = 1;
2366: my (@roles,@sections,%access,%users,%userdata,
2367: %statushash);
2368: if ($env{'form.showrole'} eq 'Any') {
2369: @roles = &course_roles($context,undef,$custom,
2370: $env{'form.roletype'});
2371: } else {
2372: @roles = ($env{'form.showrole'});
2373: }
2374: foreach my $role (@roles) {
2375: %{$users{$role}} = ();
2376: }
2377: foreach my $type (@statuses) {
2378: $access{$type} = $type;
2379: }
2380: &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash,$hidepriv);
2381: foreach my $user (keys(%userdata)) {
2382: next if (ref($userinfo{$user}) eq 'HASH');
2383: foreach my $item ('fullname','id') {
2384: $userinfo{$user}{$item} = $userdata{$user}[$indexhash->{$item}];
2385: }
2386: }
2387: foreach my $role (keys(%users)) {
2388: foreach my $user (keys(%{$users{$role}})) {
2389: my $uniqid = $user.':'.$role;
2390: $allusers{$uniqid}{$cid} = { desc => $cdesc,
2391: secs => $statushash{$user}{$role},
2392: };
2393: }
2394: }
2395: }
2396: &gather_userinfo($context,$format,\%userlist,$indexhash,
2397: \%userinfo,\%allusers,$permission);
2398: } else {
2399: $r->print('<input type="hidden" name="phase" value="'.
2400: $env{'form.phase'}.'" /></form>');
2401: return;
2402: }
2403: }
2404: }
2405: }
2406: if (keys(%userlist) == 0) {
2407: my $msg = '';
2408: if ($context eq 'author') {
2409: $msg = &mt('There are no co-authors to display.');
2410: } elsif ($context eq 'domain') {
2411: if ($env{'form.roletype'} eq 'domain') {
2412: $msg = &mt('There are no users with domain roles to display.');
2413: } elsif ($env{'form.roletype'} eq 'author') {
2414: $msg = &mt('There are no authors or co-authors to display.');
2415: } elsif ($env{'form.roletype'} eq 'course') {
2416: $msg = &mt('There are no course users to display');
2417: } elsif ($env{'form.roletype'} eq 'community') {
2418: $msg = &mt('There are no community users to display');
2419: }
2420: } elsif ($context eq 'course') {
2421: $r->print(&mt('There are no course users to display.')."\n");
2422: }
2423: $r->print('<p class="LC_info">'.$msg.'</p>'."\n") if $msg;
2424: } else {
2425: # Print out the available choices
2426: my $usercount;
2427: if ($env{'form.action'} eq 'modifystudent') {
2428: ($usercount) = &show_users_list($r,$context,'view',$permission,
2429: $env{'form.Status'},\%userlist,$keylist,'',
2430: $showcredits);
2431: } else {
2432: ($usercount) = &show_users_list($r,$context,$env{'form.output'},
2433: $permission,$env{'form.Status'},\%userlist,
2434: $keylist,'',$showcredits,$needauthorquota,$needauthorusage);
2435: }
2436: if (!$usercount) {
2437: $r->print('<br /><span class="LC_info">'
2438: .&mt('There are no users matching the search criteria.')
2439: .'</span>'
2440: );
2441: }
2442: }
2443: $r->print('<input type="hidden" name="phase" value="'.
2444: $env{'form.phase'}.'" /></form>');
2445: return;
2446: }
2447:
2448: sub role_filter {
2449: my ($context) = @_;
2450: my $output;
2451: my $roleselected = '';
2452: if ($env{'form.showrole'} eq 'Any') {
2453: $roleselected = ' selected="selected"';
2454: }
2455: my ($role_select);
2456: if ($context eq 'domain') {
2457: $role_select = &domain_roles_select();
2458: $output = '<span class="LC_nobreak">'
2459: .&mt('Role Type: [_1]',$role_select)
2460: .'</span>';
2461: } else {
2462: $role_select = '<select name="showrole" onchange="javascript:updateCols('."'showrole'".');">'."\n".
2463: '<option value="Any" '.$roleselected.'>'.
2464: &mt('Any role').'</option>';
2465: my ($roletype,$crstype);
2466: if ($context eq 'course') {
2467: $crstype = &Apache::loncommon::course_type();
2468: if ($crstype eq 'Community') {
2469: $roletype = 'community';
2470: } else {
2471: $roletype = 'course';
2472: }
2473: }
2474: my @poss_roles = &curr_role_permissions($context,'','',$roletype);
2475: foreach my $role (@poss_roles) {
2476: $roleselected = '';
2477: if ($role eq $env{'form.showrole'}) {
2478: $roleselected = ' selected="selected"';
2479: }
2480: my $plrole;
2481: if ($role eq 'cr') {
2482: $plrole = &mt('Custom role');
2483: } else {
2484: $plrole=&Apache::lonnet::plaintext($role,$crstype);
2485: }
2486: $role_select .= '<option value="'.$role.'"'.$roleselected.'>'.$plrole.'</option>';
2487: }
2488: $role_select .= '</select>';
2489: $output = '<span class="LC_nobreak">'
2490: .&mt('Role: [_1]',$role_select)
2491: .'</span>';
2492: }
2493: return $output;
2494: }
2495:
2496: sub section_group_filter {
2497: my ($cnum,$cdom) = @_;
2498: my @filters;
2499: if ($env{'request.course.sec'} eq '') {
2500: @filters = ('sec');
2501: }
2502: push(@filters,'grp');
2503: my %name = (
2504: sec => 'secfilter',
2505: grp => 'grpfilter',
2506: );
2507: my %title = &Apache::lonlocal::texthash (
2508: sec => 'Section(s)',
2509: grp => 'Group(s)',
2510: all => 'all',
2511: none => 'none',
2512: );
2513: my $output;
2514: foreach my $item (@filters) {
2515: my ($markup,@options);
2516: if ($env{'form.'.$name{$item}} eq '') {
2517: $env{'form.'.$name{$item}} = 'all';
2518: }
2519: if ($item eq 'sec') {
2520: if (($env{'form.showrole'} eq 'cc') || ($env{'form.showrole'} eq 'co')) {
2521: $env{'form.'.$name{$item}} = 'none';
2522: }
2523: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
2524: @options = sort(keys(%sections_count));
2525: } elsif ($item eq 'grp') {
2526: my %curr_groups = &Apache::longroup::coursegroups();
2527: @options = sort(keys(%curr_groups));
2528: }
2529: if (@options > 0) {
2530: my $currsel;
2531: $markup = '<select name="'.$name{$item}.'">'."\n";
2532: foreach my $option ('all','none',@options) {
2533: $currsel = '';
2534: if ($env{'form.'.$name{$item}} eq $option) {
2535: $currsel = ' selected="selected"';
2536: }
2537: $markup .= ' <option value="'.$option.'"'.$currsel.'>';
2538: if (($option eq 'all') || ($option eq 'none')) {
2539: $markup .= $title{$option};
2540: } else {
2541: $markup .= $option;
2542: }
2543: $markup .= '</option>'."\n";
2544: }
2545: $markup .= '</select>'."\n";
2546: $output .= (' 'x3).'<span class="LC_nobreak">'
2547: .'<label>'.$title{$item}.': '.$markup.'</label>'
2548: .'</span> ';
2549: }
2550: }
2551: return $output;
2552: }
2553:
2554: sub infocolumns {
2555: my ($context,$mode,$showcredits) = @_;
2556: my @cols;
2557: if (($mode eq 'pickauthor') || ($mode eq 'autoenroll')) {
2558: @cols = &get_cols_array($context,$mode,$showcredits);
2559: } else {
2560: my @posscols = &get_cols_array($context,$mode,$showcredits);
2561: if ($env{'form.phase'} ne '') {
2562: my @checkedcols = &Apache::loncommon::get_env_multiple('form.showcol');
2563: foreach my $col (@checkedcols) {
2564: if (grep(/^$col$/,@posscols)) {
2565: push(@cols,$col);
2566: }
2567: }
2568: } else {
2569: @cols = @posscols;
2570: }
2571: }
2572: return @cols;
2573: }
2574:
2575: sub get_cols_array {
2576: my ($context,$mode,$showcredits) = @_;
2577: my @cols;
2578: if ($mode eq 'pickauthor') {
2579: @cols = ('username','fullname','status','email');
2580: } else {
2581: @cols = ('username','domain','id','fullname');
2582: if ($context eq 'course') {
2583: push(@cols,'section');
2584: }
2585: push(@cols,('start','end','role'));
2586: unless (($mode eq 'autoenroll') && ($env{'form.Status'} ne 'Any')) {
2587: push(@cols,'status');
2588: }
2589: if ($context eq 'course') {
2590: push(@cols,'groups');
2591: }
2592: push(@cols,'email');
2593: if (($context eq 'course') && ($mode ne 'autoenroll')) {
2594: if ($showcredits) {
2595: push(@cols,'credits');
2596: }
2597: push(@cols,'lastlogin','clicker');
2598: }
2599: if (($context eq 'course') && ($mode ne 'autoenroll') &&
2600: ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
2601: push(@cols,'photo');
2602: }
2603: if ($context eq 'domain') {
2604: push (@cols,('authorusage','authorquota','extent'));
2605: }
2606: }
2607: return @cols;
2608: }
2609:
2610: sub column_checkboxes {
2611: my ($context,$mode,$formname,$showcredits) = @_;
2612: my @cols = &get_cols_array($context,$mode,$showcredits);
2613: my @showncols = &Apache::loncommon::get_env_multiple('form.showcol');
2614: my (%disabledchk,%unchecked);
2615: if ($env{'form.phase'} eq '') {
2616: $disabledchk{'status'} = 1;
2617: if ($context eq 'course') {
2618: $disabledchk{'role'} = 1;
2619: $unchecked{'photo'} = 1;
2620: $unchecked{'clicker'} = 1;
2621: if ($showcredits) {
2622: $unchecked{'credits'} = 1;
2623: }
2624: } elsif ($context eq 'domain') {
2625: $unchecked{'extent'} = 1;
2626: }
2627: $unchecked{'start'} = 1;
2628: $unchecked{'end'} = 1;
2629: } else {
2630: if ($env{'form.Status'} ne 'Any') {
2631: $disabledchk{'status'} = 1;
2632: }
2633: if (($env{'form.showrole'} ne 'Any') && ($env{'form.showrole'} ne 'cr')) {
2634: $disabledchk{'role'} = 1;
2635: }
2636: if ($context eq 'domain') {
2637: if (($env{'form.roletype'} eq 'course') ||
2638: ($env{'form.roletype'} eq 'community')) {
2639: $disabledchk{'status'} = 1;
2640: $disabledchk{'authorusage'} = 1;
2641: $disabledchk{'authorquota'} = 1;
2642: } elsif ($env{'form.roletype'} eq 'domain') {
2643: $disabledchk{'extent'} = 1;
2644: }
2645: }
2646: }
2647: my $numposs = scalar(@cols);
2648: my $numinrow = 7;
2649: my %lt = &get_column_names($context);
2650: my $output = '<fieldset><legend>'.&mt('Information to show').'</legend>'."\n".'<span class="LC_nobreak">'.
2651: '<input type="button" onclick="javascript:checkAll(document.'.$formname.'.showcol);" value="'.&mt('check all').'" />'.
2652: (' 'x3).
2653: '<input type="button" onclick="javascript:uncheckAll(document.'.$formname.'.showcol);" value="'.&mt('uncheck all').'" />'.
2654: '</span><table>';
2655:
2656: for (my $i=0; $i<$numposs; $i++) {
2657: my $rem = $i%($numinrow);
2658: if ($rem == 0) {
2659: if ($i > 0) {
2660: $output .= '</tr>';
2661: }
2662: $output .= '<tr>';
2663: }
2664: my $checked;
2665: if ($env{'form.phase'} eq '') {
2666: $checked = ' checked="checked"';
2667: if ($unchecked{$cols[$i]}) {
2668: $checked = '';
2669: }
2670: if ($disabledchk{$cols[$i]}) {
2671: $checked = ' disabled="disabled"';
2672: }
2673: } elsif (grep(/^\Q$cols[$i]\E$/,@showncols)) {
2674: $checked = ' checked="checked"';
2675: } elsif ($disabledchk{$cols[$i]}) {
2676: $checked = ' disabled="disabled"';
2677: }
2678: if ($i == $numposs-1) {
2679: my $colsleft = $numinrow-$rem;
2680: if ($colsleft > 1) {
2681: $output .= '<td colspan="'.$colsleft.'">';
2682: } else {
2683: $output .= '<td>';
2684: }
2685: } else {
2686: $output .= '<td>';
2687: }
2688: my $style;
2689: if ($cols[$i] eq 'extent') {
2690: if (($env{'form.roletype'} eq 'domain') || ($env{'form.roletype'} eq '')) {
2691: $style = ' style="display: none;"';
2692: }
2693: } elsif (($cols[$i] eq 'authorusage') || ($cols[$i] eq 'authorquota')) {
2694: if ($env{'form.roletype'} ne 'domain') {
2695: $style = ' style="display: none;"';
2696: }
2697: }
2698: $output .= '<span id="show'.$cols[$i].'"'.$style.'><label>'.
2699: '<input id="showcol'.$cols[$i].'" type="checkbox" name="showcol" value="'.$cols[$i].'"'.$checked.' /><span id="showcoltext'.$cols[$i].'">'.
2700: $lt{$cols[$i]}.'</span>'.
2701: '</label></span></td>';
2702: }
2703: $output .= '</tr></table></fieldset>';
2704: return $output;
2705: }
2706:
2707: sub list_submit_button {
2708: my ($text) = @_;
2709: return '<input type="button" name="updatedisplay" value="'.$text.'" onclick="javascript:display_update()" />';
2710: }
2711:
2712: sub get_column_names {
2713: my ($context) = @_;
2714: my %lt = &Apache::lonlocal::texthash(
2715: 'username' => "username",
2716: 'domain' => "domain",
2717: 'id' => 'ID',
2718: 'fullname' => "name",
2719: 'section' => "section",
2720: 'groups' => "active groups",
2721: 'start' => "start date",
2722: 'end' => "end date",
2723: 'status' => "status",
2724: 'role' => "role",
2725: 'credits' => "credits",
2726: 'type' => "enroll type/action",
2727: 'email' => "e-mail address",
2728: 'photo' => "photo",
2729: 'lastlogin' => "last login",
2730: 'extent' => "extent",
2731: 'authorusage' => "disk usage (%)",
2732: 'authorquota' => "disk quota (MB)",
2733: 'ca' => "check all",
2734: 'ua' => "uncheck all",
2735: 'clicker' => "clicker-ID",
2736: );
2737: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
2738: $lt{'extent'} = &mt('course(s): description, section(s), status');
2739: } elsif ($context eq 'domain' && $env{'form.roletype'} eq 'community') {
2740: $lt{'extent'} = &mt('community(s): description, section(s), status');
2741: } elsif (($context eq 'author') ||
2742: ($context eq 'domain' && $env{'form.roletype'} eq 'author')) {
2743: $lt{'extent'} = &mt('author');
2744: }
2745: return %lt;
2746: }
2747:
2748: sub gather_userinfo {
2749: my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_;
2750: my $viewablesec;
2751: if ($context eq 'course') {
2752: $viewablesec = &viewable_section($permission);
2753: }
2754: foreach my $item (keys(%{$rolehash})) {
2755: my %userdata;
2756: if ($context eq 'author') {
2757: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
2758: split(/:/,$item);
2759: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
2760: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2761: $item,$userlist);
2762: } elsif ($context eq 'course') {
2763: ($userdata{'username'},$userdata{'domain'},$userdata{'role'},
2764: $userdata{'section'}) = split(/:/,$item,-1);
2765: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
2766: if (($viewablesec ne '') && ($userdata{'section'} ne '')) {
2767: next if ($viewablesec ne $userdata{'section'});
2768: }
2769: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2770: $item,$userlist);
2771: } elsif ($context eq 'domain') {
2772: if ($env{'form.roletype'} eq 'domain') {
2773: ($userdata{'role'},$userdata{'username'},$userdata{'domain'}) =
2774: split(/:/,$item);
2775: ($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
2776: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2777: $item,$userlist);
2778: } elsif ($env{'form.roletype'} eq 'author') {
2779: if (ref($rolehash->{$item}) eq 'HASH') {
2780: $userdata{'extent'} = $item;
2781: foreach my $key (keys(%{$rolehash->{$item}})) {
2782: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) = split(/:/,$key);
2783: ($userdata{'start'},$userdata{'end'}) =
2784: split(/:/,$rolehash->{$item}{$key});
2785: my $uniqid = $key.':'.$item;
2786: &build_user_record($context,\%userdata,$userinfo,
2787: $indexhash,$uniqid,$userlist);
2788: }
2789: }
2790: } elsif (($env{'form.roletype'} eq 'course') ||
2791: ($env{'form.roletype'} eq 'community')) {
2792: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
2793: split(/:/,$item);
2794: if (ref($rolehash->{$item}) eq 'HASH') {
2795: my $numcids = keys(%{$rolehash->{$item}});
2796: foreach my $cid (sort(keys(%{$rolehash->{$item}}))) {
2797: if (ref($rolehash->{$item}{$cid}) eq 'HASH') {
2798: my $spanstart = '';
2799: my $spanend = '; ';
2800: my $space = ', ';
2801: if ($format eq 'html' || $format eq 'view') {
2802: $spanstart = '<span class="LC_nobreak">';
2803: # FIXME: actions on courses disabled for now
2804: # if ($permission->{'cusr'}) {
2805: # if ($numcids > 1) {
2806: # $spanstart .= '<input type="radio" name="'.$item.'" value="'.$cid.'" /> ';
2807: # } else {
2808: # $spanstart .= '<input type="hidden" name="'.$item.'" value="'.$cid.'" /> ';
2809: # }
2810: # }
2811: $spanend = '</span><br />';
2812: $space = ', ';
2813: }
2814: $userdata{'extent'} .= $spanstart.
2815: $rolehash->{$item}{$cid}{'desc'}.$space;
2816: if (ref($rolehash->{$item}{$cid}{'secs'}) eq 'HASH') {
2817: foreach my $sec (sort(keys(%{$rolehash->{$item}{$cid}{'secs'}}))) {
2818: if (($env{'form.Status'} eq 'Any') ||
2819: ($env{'form.Status'} eq $rolehash->{$item}{$cid}{'secs'}{$sec})) {
2820: $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
2821: $userdata{'status'} = $rolehash->{$item}{$cid}{'secs'}{$sec};
2822: }
2823: }
2824: }
2825: }
2826: }
2827: }
2828: if ($userdata{'status'} ne '') {
2829: &build_user_record($context,\%userdata,$userinfo,
2830: $indexhash,$item,$userlist);
2831: }
2832: }
2833: }
2834: }
2835: return;
2836: }
2837:
2838: sub build_user_record {
2839: my ($context,$userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
2840: next if ($userdata->{'start'} eq '-1' && $userdata->{'end'} eq '-1');
2841: if (!(($context eq 'domain') && (($env{'form.roletype'} eq 'course')
2842: && ($env{'form.roletype'} eq 'community')))) {
2843: &process_date_info($userdata);
2844: }
2845: my $username = $userdata->{'username'};
2846: my $domain = $userdata->{'domain'};
2847: if (ref($userinfo->{$username.':'.$domain}) eq 'HASH') {
2848: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
2849: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
2850: } else {
2851: &aggregate_user_info($domain,$username,$userinfo);
2852: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
2853: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
2854: }
2855: foreach my $key (keys(%{$indexhash})) {
2856: if (defined($userdata->{$key})) {
2857: $userlist->{$record_key}[$indexhash->{$key}] = $userdata->{$key};
2858: }
2859: }
2860: return;
2861: }
2862:
2863: sub courses_selector {
2864: my ($cdom,$formname) = @_;
2865: my %codes = ();
2866: my @codetitles = ();
2867: my %cat_titles = ();
2868: my %cat_order = ();
2869: my %idlist = ();
2870: my %idnums = ();
2871: my %idlist_titles = ();
2872: my $caller = 'global';
2873: my $format_reply;
2874: my $jscript = '';
2875:
2876: my $totcodes = 0;
2877: my $instcats = &Apache::lonnet::get_dom_instcats($cdom);
2878: if (ref($instcats) eq 'HASH') {
2879: if ((ref($instcats->{'codetitles'}) eq 'ARRAY') && (ref($instcats->{'codes'}) eq 'HASH') &&
2880: (ref($instcats->{'cat_titles'}) eq 'HASH') && (ref($instcats->{'cat_order'}) eq 'HASH')) {
2881: %codes = %{$instcats->{'codes'}};
2882: @codetitles = @{$instcats->{'codetitles'}};
2883: %cat_titles = %{$instcats->{'cat_titles'}};
2884: %cat_order = %{$instcats->{'cat_order'}};
2885: $totcodes = scalar(keys(%codes));
2886: my $numtypes = @codetitles;
2887: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
2888: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
2889: my $longtitles_str = join('","',@{$longtitles});
2890: my $allidlist = $idlist{$codetitles[0]};
2891: $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
2892: $jscript .= $scripttext;
2893: $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,\@codetitles);
2894: }
2895: }
2896: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
2897:
2898: my %elements = (
2899: Year => 'selectbox',
2900: coursepick => 'radio',
2901: coursetotal => 'text',
2902: courselist => 'text',
2903: );
2904: $jscript .= &Apache::lonhtmlcommon::set_form_elements(\%elements);
2905: if ($env{'form.coursepick'} eq 'category') {
2906: $jscript .= qq|
2907: function setCourseCat(formname) {
2908: if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
2909: return;
2910: }
2911: courseSet('$codetitles[0]');
2912: for (var j=0; j<formname.Semester.length; j++) {
2913: if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
2914: formname.Semester.options[j].selected = true;
2915: }
2916: }
2917: if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
2918: return;
2919: }
2920: courseSet('$codetitles[1]');
2921: for (var j=0; j<formname.Department.length; j++) {
2922: if (formname.Department.options[j].value == "$env{'form.Department'}") {
2923: formname.Department.options[j].selected = true;
2924: }
2925: }
2926: if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
2927: return;
2928: }
2929: courseSet('$codetitles[2]');
2930: for (var j=0; j<formname.Number.length; j++) {
2931: if (formname.Number.options[j].value == "$env{'form.Number'}") {
2932: formname.Number.options[j].selected = true;
2933: }
2934: }
2935: }
2936: |;
2937: }
2938: return ($cb_jscript,$jscript,$totcodes,\@codetitles,\%idlist,
2939: \%idlist_titles);
2940: }
2941:
2942: sub course_selector_loadcode {
2943: my ($formname) = @_;
2944: my $loadcode;
2945: if ($env{'form.coursepick'} ne '') {
2946: $loadcode = 'javascript:setFormElements(document.'.$formname.')';
2947: if ($env{'form.coursepick'} eq 'category') {
2948: $loadcode .= ';javascript:setCourseCat(document.'.$formname.')';
2949: }
2950: }
2951: return $loadcode;
2952: }
2953:
2954: sub process_coursepick {
2955: my $coursefilter = $env{'form.coursepick'};
2956: my $cdom = $env{'request.role.domain'};
2957: my %courses;
2958: my $crssrch = 'Course';
2959: if ($env{'form.roletype'} eq 'community') {
2960: $crssrch = 'Community';
2961: }
2962: if ($coursefilter eq 'all') {
2963: %courses = &Apache::lonnet::courseiddump($cdom,'.','.','.','.','.',
2964: undef,undef,$crssrch);
2965: } elsif ($coursefilter eq 'category') {
2966: my $instcode = &instcode_from_coursefilter();
2967: %courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.',
2968: undef,undef,$crssrch);
2969: } elsif ($coursefilter eq 'specific') {
2970: if ($env{'form.coursetotal'} > 1) {
2971: my @course_ids = split(/&&/,$env{'form.courselist'});
2972: foreach my $cid (@course_ids) {
2973: $courses{$cid} = '';
2974: }
2975: } else {
2976: $courses{$env{'form.courselist'}} = '';
2977: }
2978: }
2979: return %courses;
2980: }
2981:
2982: sub instcode_from_coursefilter {
2983: my $instcode = '';
2984: my @cats = ('Semester','Year','Department','Number');
2985: foreach my $category (@cats) {
2986: if (defined($env{'form.'.$category})) {
2987: unless ($env{'form.'.$category} eq '-1') {
2988: $instcode .= $env{'form.'.$category};
2989: }
2990: }
2991: }
2992: if ($instcode eq '') {
2993: $instcode = '.';
2994: }
2995: return $instcode;
2996: }
2997:
2998: sub make_keylist_array {
2999: my ($index,$keylist);
3000: $index->{'domain'} = &Apache::loncoursedata::CL_SDOM();
3001: $index->{'username'} = &Apache::loncoursedata::CL_SNAME();
3002: $index->{'end'} = &Apache::loncoursedata::CL_END();
3003: $index->{'start'} = &Apache::loncoursedata::CL_START();
3004: $index->{'id'} = &Apache::loncoursedata::CL_ID();
3005: $index->{'section'} = &Apache::loncoursedata::CL_SECTION();
3006: $index->{'fullname'} = &Apache::loncoursedata::CL_FULLNAME();
3007: $index->{'status'} = &Apache::loncoursedata::CL_STATUS();
3008: $index->{'type'} = &Apache::loncoursedata::CL_TYPE();
3009: $index->{'lockedtype'} = &Apache::loncoursedata::CL_LOCKEDTYPE();
3010: $index->{'groups'} = &Apache::loncoursedata::CL_GROUP();
3011: $index->{'email'} = &Apache::loncoursedata::CL_PERMANENTEMAIL();
3012: $index->{'role'} = &Apache::loncoursedata::CL_ROLE();
3013: $index->{'extent'} = &Apache::loncoursedata::CL_EXTENT();
3014: $index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
3015: $index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();
3016: $index->{'credits'} = &Apache::loncoursedata::CL_CREDITS();
3017: $index->{'instsec'} = &Apache::loncoursedata::CL_INSTSEC();
3018: $index->{'authorquota'} = &Apache::loncoursedata::CL_AUTHORQUOTA();
3019: $index->{'authorusage'} = &Apache::loncoursedata::CL_AUTHORUSAGE();
3020: foreach my $key (keys(%{$index})) {
3021: $keylist->[$index->{$key}] = $key;
3022: }
3023: return ($index,$keylist);
3024: }
3025:
3026: sub aggregate_user_info {
3027: my ($udom,$uname,$userinfo) = @_;
3028: my %info=&Apache::lonnet::get('environment',
3029: ['firstname','middlename',
3030: 'lastname','generation','id'],
3031: $udom,$uname);
3032: my ($tmp) = keys(%info);
3033: my ($fullname,$id);
3034: if ($tmp =~/^(con_lost|error|no_such_host)/i) {
3035: $fullname = 'not available';
3036: $id = 'not available';
3037: &Apache::lonnet::logthis('unable to retrieve environment '.
3038: 'for '.$uname.':'.$udom);
3039: } else {
3040: $fullname = &Apache::lonnet::format_name(@info{qw/firstname middlename lastname generation/},'lastname');
3041: $id = $info{'id'};
3042: }
3043: $userinfo->{$uname.':'.$udom} = {
3044: fullname => $fullname,
3045: id => $id,
3046: };
3047: return;
3048: }
3049:
3050: sub process_date_info {
3051: my ($userdata) = @_;
3052: my $now = time;
3053: $userdata->{'status'} = 'Active';
3054: if ($userdata->{'start'} > 0) {
3055: if ($now < $userdata->{'start'}) {
3056: $userdata->{'status'} = 'Future';
3057: }
3058: }
3059: if ($userdata->{'end'} > 0) {
3060: if ($now > $userdata->{'end'}) {
3061: $userdata->{'status'} = 'Expired';
3062: }
3063: }
3064: return;
3065: }
3066:
3067: sub show_users_list {
3068: my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname,
3069: $showcredits,$needauthorquota,$needauthorusage)=@_;
3070: if ($formname eq '') {
3071: $formname = 'studentform';
3072: }
3073: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
3074: #
3075: # Variables for excel output
3076: my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
3077: #
3078: # Variables for csv output
3079: my ($CSVfile,$CSVfilename);
3080: #
3081: my $sortby = $env{'form.sortby'};
3082: my @sortable = ('username','domain','id','fullname','start','end','email','role');
3083: if ($context eq 'course') {
3084: push(@sortable,('section','groups','type'));
3085: if ($showcredits) {
3086: push(@sortable,'credits');
3087: }
3088: } else {
3089: push(@sortable,'extent');
3090: if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
3091: (($env{'form.showrole'} eq 'Any') || ($env{'form.showrole'} eq 'au'))) {
3092: push(@sortable,('authorusage','authorquota'));
3093: }
3094: }
3095: if ($mode eq 'pickauthor') {
3096: @sortable = ('username','fullname','email','status');
3097: }
3098: my %is_sortable;
3099: map { $is_sortable{$_} = 1; } @sortable;
3100: unless ($is_sortable{$sortby}) {
3101: $sortby = 'username';
3102: }
3103: my $setting = $env{'form.roletype'};
3104: my ($cid,$cdom,$cnum,$classgroups,$crstype,$defaultcredits);
3105: if ($context eq 'course') {
3106: $cid = $env{'request.course.id'};
3107: $crstype = &Apache::loncommon::course_type();
3108: ($cnum,$cdom) = &get_course_identity($cid);
3109: $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
3110: ($classgroups) = &Apache::loncoursedata::get_group_memberships(
3111: $userlist,$keylist,$cdom,$cnum);
3112: if ($mode eq 'autoenroll') {
3113: $env{'form.showrole'} = 'st';
3114: } else {
3115: if ($env{'course.'.$cid.'.internal.showphoto'}) {
3116: $r->print('
3117: <script type="text/javascript">
3118: // <![CDATA[
3119: function photowindow(photolink) {
3120: var title = "Photo_Viewer";
3121: var options = "scrollbars=1,resizable=1,menubar=0";
3122: options += ",width=240,height=240";
3123: stdeditbrowser = open(photolink,title,options,"1");
3124: stdeditbrowser.focus();
3125: }
3126: // ]]>
3127: </script>
3128: ');
3129: }
3130: }
3131: } elsif ($context eq 'domain') {
3132: if ($setting eq 'community') {
3133: $crstype = 'Community';
3134: } elsif ($setting eq 'course') {
3135: $crstype = 'Course';
3136: }
3137: }
3138: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
3139: my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
3140: my $verify_action_js = &bulkaction_javascript($formname);
3141: $r->print(<<END);
3142:
3143: <script type="text/javascript" language="Javascript">
3144: // <![CDATA[
3145:
3146: $verify_action_js
3147:
3148: function username_display_launch(username,domain) {
3149: var target;
3150: if (!document.$formname.usernamelink.length) {
3151: target = document.$formname.usernamelink.value;
3152: } else {
3153: for (var i=0; i<document.$formname.usernamelink.length; i++) {
3154: if (document.$formname.usernamelink[i].checked) {
3155: target = document.$formname.usernamelink[i].value;
3156: }
3157: }
3158: }
3159: if ((target == 'modify') || (target == 'activity')) {
3160: var nextaction = 'singleuser';
3161: if (target == 'activity') {
3162: nextaction = 'accesslogs';
3163: }
3164: if (document.$formname.userwin.checked == true) {
3165: var url = '/adm/createuser?srchterm='+username+'&srchdomain='+domain+'&phase=get_user_info&srchin=dom&srchby=uname&srchtype=exact&popup=1&action='+nextaction;
3166: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3167: modifywin = window.open(url,'',options,1);
3168: modifywin.focus();
3169: return;
3170: } else {
3171: document.$formname.srchterm.value=username;
3172: document.$formname.srchdomain.value=domain;
3173: document.$formname.phase.value='get_user_info';
3174: document.$formname.action.value = nextaction;
3175: document.$formname.submit();
3176: }
3177: }
3178: if (target == 'aboutme') {
3179: if (document.$formname.userwin.checked == true) {
3180: var url = '/adm/'+domain+'/'+username+'/aboutme?popup=1';
3181: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3182: aboutmewin = window.open(url,'',options,1);
3183: aboutmewin.focus();
3184: return;
3185: } else {
3186: document.location.href = '/adm/'+domain+'/'+username+'/aboutme';
3187: }
3188: }
3189: if (target == 'track') {
3190: if (document.$formname.userwin.checked == true) {
3191: var url = '/adm/trackstudent?selected_student='+username+':'+domain+'&only_body=1';
3192: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3193: var trackwin = window.open(url,'',options,1);
3194: trackwin.focus();
3195: return;
3196: } else {
3197: document.location.href = '/adm/trackstudent?selected_student='+username+':'+domain;
3198: }
3199: }
3200: }
3201: // ]]>
3202: </script>
3203: $date_sec_selector
3204: <input type="hidden" name="state" value="$env{'form.state'}" />
3205: END
3206: }
3207: $r->print(<<END);
3208: <input type="hidden" name="sortby" value="$sortby" />
3209: END
3210: my @cols = &infocolumns($context,$mode,$showcredits);
3211: my %coltxt = &get_column_names($context);
3212: my %acttxt = &Apache::lonlocal::texthash(
3213: 'pr' => "Proceed",
3214: 'ac' => "Action to take for selected users",
3215: 'link' => "Behavior of clickable username link for each user",
3216: 'aboutme' => "Display a user's personal information page",
3217: 'owin' => "Open in a new window",
3218: 'modify' => "Modify a user's information",
3219: 'track' => "View a user's recent activity",
3220: 'activity' => "View a user's access log",
3221: );
3222: my %lt = (%coltxt,%acttxt);
3223: my $rolefilter = $env{'form.showrole'};
3224: if ($env{'form.showrole'} eq 'cr') {
3225: $rolefilter = &mt('custom');
3226: } elsif ($env{'form.showrole'} ne 'Any') {
3227: $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'},$crstype);
3228: }
3229: my $results_description;
3230: if ($mode ne 'autoenroll') {
3231: $results_description = &results_header_row($rolefilter,$statusmode,
3232: $context,$permission,$mode,$crstype);
3233: $r->print('<b>'.$results_description.'</b><br clear="all" />');
3234: }
3235: my ($output,$actionselect,%canchange,%canchangesec);
3236: if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
3237: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
3238: if ($permission->{'cusr'}) {
3239: unless (($context eq 'domain') &&
3240: (($setting eq 'course') || ($setting eq 'community'))) {
3241: $actionselect =
3242: &select_actions($context,$setting,$statusmode,$formname);
3243: }
3244: }
3245: $r->print(<<END);
3246: <input type="hidden" name="srchby" value="uname" />
3247: <input type="hidden" name="srchin" value="dom" />
3248: <input type="hidden" name="srchtype" value="exact" />
3249: <input type="hidden" name="srchterm" value="" />
3250: <input type="hidden" name="srchdomain" value="" />
3251: END
3252: if ($actionselect) {
3253: $output .= <<"END";
3254: <div class="LC_left_float"><fieldset><legend>$lt{'ac'}</legend>
3255: $actionselect
3256: <br/><br /><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.$formname.actionlist)" />
3257: <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>
3258: END
3259: my @allroles;
3260: if ($env{'form.showrole'} eq 'Any') {
3261: my $custom = 1;
3262: if ($context eq 'domain') {
3263: @allroles = &roles_by_context($setting,$custom,$crstype);
3264: } else {
3265: @allroles = &roles_by_context($context,$custom,$crstype);
3266: }
3267: } else {
3268: @allroles = ($env{'form.showrole'});
3269: }
3270: foreach my $role (@allroles) {
3271: if ($context eq 'domain') {
3272: if ($setting eq 'domain') {
3273: if (&Apache::lonnet::allowed('c'.$role,
3274: $env{'request.role.domain'})) {
3275: $canchange{$role} = 1;
3276: }
3277: } elsif ($setting eq 'author') {
3278: if (&Apache::lonnet::allowed('c'.$role,
3279: $env{'request.role.domain'})) {
3280: $canchange{$role} = 1;
3281: }
3282: }
3283: } elsif ($context eq 'author') {
3284: if (&Apache::lonnet::allowed('c'.$role,
3285: $env{'user.domain'}.'/'.$env{'user.name'})) {
3286: $canchange{$role} = 1;
3287: }
3288: } elsif ($context eq 'course') {
3289: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
3290: $canchange{$role} = 1;
3291: } elsif ($env{'request.course.sec'} ne '') {
3292: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
3293: $canchangesec{$role} = $env{'request.course.sec'};
3294: }
3295: } elsif ((($role eq 'co') && ($crstype eq 'Community')) ||
3296: (($role eq 'cc') && ($crstype eq 'Course'))) {
3297: if (&is_courseowner($env{'request.course.id'},
3298: $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
3299: $canchange{$role} = 1;
3300: }
3301: }
3302: }
3303: }
3304: }
3305: $output .= '<div class="LC_left_float"><fieldset><legend>'.$lt{'link'}.'</legend>'.
3306: '<table><tr>';
3307: my @linkdests = ('aboutme');
3308: if ($permission->{'cusr'}) {
3309: unshift (@linkdests,'modify');
3310: }
3311: if ($context eq 'course') {
3312: if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) ||
3313: &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.
3314: $env{'request.course.sec'})) {
3315: push(@linkdests,'track');
3316: }
3317: } elsif ($context eq 'domain') {
3318: if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
3319: push(@linkdests,'activity');
3320: }
3321: }
3322: $output .= '<td>';
3323: my $usernamelink = $env{'form.usernamelink'};
3324: if ($usernamelink eq '') {
3325: $usernamelink = 'aboutme';
3326: }
3327: foreach my $item (@linkdests) {
3328: my $checkedstr = '';
3329: if ($item eq $usernamelink) {
3330: $checkedstr = ' checked="checked"';
3331: }
3332: $output .= '<span class="LC_nobreak"><label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.' /> '.$lt{$item}.'</label></span><br />';
3333: }
3334: my $checkwin;
3335: if ($env{'form.userwin'}) {
3336: $checkwin = ' checked="checked"';
3337: }
3338: $output .=
3339: '</td><td valign="top" style="border-left: 1px solid;">'
3340: .'<span class="LC_nobreak"><label>'
3341: .'<input type="checkbox" name="userwin" value="1"'.$checkwin.' />'.$lt{'owin'}
3342: .'</label></span></td></tr></table></fieldset></div>';
3343: }
3344: $output .= "\n".'<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
3345: &Apache::loncommon::start_data_table().
3346: &Apache::loncommon::start_data_table_header_row();
3347: if ($mode eq 'autoenroll') {
3348: $output .= "
3349: <th><a href=\"javascript:document.$formname.sortby.value='type';document.$formname.submit();\">$lt{'type'}</a></th>
3350: ";
3351: } else {
3352: $output .= "\n".'<th> </th>'."\n";
3353: if ($actionselect) {
3354: $output .= '<th class="LC_nobreak" valign="top">'.&mt('Select').'</th>'."\n";
3355: }
3356: }
3357: foreach my $item (@cols) {
3358: $output .= '<th class="LC_nobreak" valign="top">';
3359: if ($is_sortable{$item}) {
3360: $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>";
3361: } else {
3362: $output .= $lt{$item};
3363: }
3364: $output .= "</th>\n";
3365: }
3366: my %role_types = &role_type_names();
3367: $output .= &Apache::loncommon::end_data_table_header_row();
3368: # Done with the HTML header line
3369: } elsif ($mode eq 'csv') {
3370: #
3371: # Open a file
3372: $CSVfilename = '/prtspool/'.
3373: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
3374: time.'_'.rand(1000000000).'.csv';
3375: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
3376: $r->log_error("Couldn't open $CSVfilename for output $!");
3377: $r->print(
3378: '<p class="LC_error">'
3379: .&mt('Problems occurred in writing the CSV file.')
3380: .' '.&mt('This error has been logged.')
3381: .' '.&mt('Please alert your LON-CAPA administrator.')
3382: .'</p>'
3383: );
3384: $CSVfile = undef;
3385: }
3386: #
3387: # Write headers and data to file
3388: print $CSVfile '"'.$results_description.'"'."\n";
3389: print $CSVfile '"'.join('","',map {
3390: &Apache::loncommon::csv_translate($lt{$_})
3391: } (@cols))."\"\n";
3392: } elsif ($mode eq 'excel') {
3393: # Create the excel spreadsheet
3394: ($excel_workbook,$excel_filename,$format) =
3395: &Apache::loncommon::create_workbook($r);
3396: return if (! defined($excel_workbook));
3397: $excel_sheet = $excel_workbook->addworksheet('userlist');
3398: $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
3399: #
3400: my @colnames = map {$lt{$_}} (@cols);
3401:
3402: $excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
3403: }
3404:
3405: # Done with header lines in all formats
3406: my %index;
3407: my $i;
3408: foreach my $idx (@$keylist) {
3409: $index{$idx} = $i++;
3410: }
3411: my $usercount = 0;
3412: my ($secfilter,$grpfilter);
3413: if ($context eq 'course') {
3414: $secfilter = $env{'form.secfilter'};
3415: $grpfilter = $env{'form.grpfilter'};
3416: if ($secfilter eq '') {
3417: $secfilter = 'all';
3418: }
3419: if ($grpfilter eq '') {
3420: $grpfilter = 'all';
3421: }
3422: }
3423: my %ltstatus = &Apache::lonlocal::texthash(
3424: Active => 'Active',
3425: Future => 'Future',
3426: Expired => 'Expired',
3427: );
3428: # If this is for a single course get last course "log-in".
3429: my %crslogins;
3430: if ($context eq 'course') {
3431: %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$cnum);
3432: }
3433: # Get groups, role, permanent e-mail so we can sort on them if
3434: # necessary.
3435: foreach my $user (keys(%{$userlist})) {
3436: if ($user eq '' ) {
3437: delete($userlist->{$user});
3438: next;
3439: }
3440: if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) {
3441: delete($userlist->{$user});
3442: next;
3443: }
3444: my ($uname,$udom,$role,$groups,$email);
3445: if (($statusmode ne 'Any') &&
3446: ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
3447: delete($userlist->{$user});
3448: next;
3449: }
3450: if ($context eq 'domain') {
3451: if ($env{'form.roletype'} eq 'domain') {
3452: ($role,$uname,$udom) = split(/:/,$user);
3453: if (($uname eq $env{'request.role.domain'}.'-domainconfig') &&
3454: ($udom eq $env{'request.role.domain'})) {
3455: delete($userlist->{$user});
3456: next;
3457: }
3458: } elsif ($env{'form.roletype'} eq 'author') {
3459: ($uname,$udom,$role) = split(/:/,$user,-1);
3460: } elsif (($env{'form.roletype'} eq 'course') ||
3461: ($env{'form.roletype'} eq 'community')) {
3462: ($uname,$udom,$role) = split(/:/,$user);
3463: }
3464: } else {
3465: ($uname,$udom,$role) = split(/:/,$user,-1);
3466: if (($context eq 'course') && $role eq '') {
3467: $role = 'st';
3468: }
3469: }
3470: $userlist->{$user}->[$index{'role'}] = $role;
3471: if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
3472: delete($userlist->{$user});
3473: next;
3474: }
3475: if ($context eq 'course') {
3476: my @ac_groups;
3477: if (ref($classgroups) eq 'HASH') {
3478: $groups = $classgroups->{$user};
3479: }
3480: if (ref($groups->{'active'}) eq 'HASH') {
3481: @ac_groups = keys(%{$groups->{'active'}});
3482: $userlist->{$user}->[$index{'groups'}] = join(', ',@ac_groups);
3483: }
3484: if ($mode ne 'autoenroll') {
3485: my $section = $userlist->{$user}->[$index{'section'}];
3486: if (($env{'request.course.sec'} ne '') &&
3487: ($section ne $env{'request.course.sec'})) {
3488: if ($role eq 'st') {
3489: delete($userlist->{$user});
3490: next;
3491: }
3492: }
3493: if ($secfilter eq 'none') {
3494: if ($section ne '') {
3495: delete($userlist->{$user});
3496: next;
3497: }
3498: } elsif ($secfilter ne 'all') {
3499: if ($section ne $secfilter) {
3500: delete($userlist->{$user});
3501: next;
3502: }
3503: }
3504: if ($grpfilter eq 'none') {
3505: if (@ac_groups > 0) {
3506: delete($userlist->{$user});
3507: next;
3508: }
3509: } elsif ($grpfilter ne 'all') {
3510: if (!grep(/^\Q$grpfilter\E$/,@ac_groups)) {
3511: delete($userlist->{$user});
3512: next;
3513: }
3514: }
3515: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
3516: if ((grep/^photo$/,@cols) && ($role eq 'st')) {
3517: $userlist->{$user}->[$index{'photo'}] =
3518: &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg');
3519: $userlist->{$user}->[$index{'thumbnail'}] =
3520: &Apache::lonnet::retrievestudentphoto($udom,$uname,
3521: 'gif','thumbnail');
3522: }
3523: }
3524: if (($role eq 'st') && ($defaultcredits)) {
3525: if ($userlist->{$user}->[$index{'credits'}] eq '') {
3526: $userlist->{$user}->[$index{'credits'}] = $defaultcredits;
3527: }
3528: }
3529: }
3530: }
3531: my %emails = &Apache::loncommon::getemails($uname,$udom);
3532: if ($emails{'permanentemail'} =~ /\S/) {
3533: $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
3534: }
3535: if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
3536: ($role eq 'au')) {
3537: my ($disk_quota,$current_disk_usage,$percent);
3538: if (($needauthorusage) || ($needauthorquota)) {
3539: $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author');
3540: }
3541: if ($needauthorusage) {
3542: $current_disk_usage =
3543: &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname");
3544: if ($disk_quota == 0) {
3545: $percent = 100.0;
3546: } else {
3547: $percent = $current_disk_usage/(10 * $disk_quota);
3548: }
3549: $userlist->{$user}->[$index{'authorusage'}] = sprintf("%.0f",$percent);
3550: }
3551: if ($needauthorquota) {
3552: $userlist->{$user}->[$index{'authorquota'}] = sprintf("%.2f",$disk_quota);
3553: }
3554: }
3555: $usercount ++;
3556: }
3557: my $autocount = 0;
3558: my $manualcount = 0;
3559: my $lockcount = 0;
3560: my $unlockcount = 0;
3561: if ($usercount) {
3562: $r->print($output);
3563: } else {
3564: if ($mode eq 'autoenroll') {
3565: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
3566: } else {
3567: return;
3568: }
3569: }
3570: #
3571: # Sort the users
3572: my $index = $index{$sortby};
3573: my $second = $index{'username'};
3574: my $third = $index{'domain'};
3575: my @sorted_users;
3576: if (($sortby eq 'authorquota') || ($sortby eq 'authorusage')) {
3577: @sorted_users = sort {
3578: $userlist->{$b}->[$index] <=> $userlist->{$a}->[$index] ||
3579: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
3580: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
3581: } (keys(%$userlist));
3582: } else {
3583: @sorted_users = sort {
3584: lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index]) ||
3585: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
3586: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
3587: } (keys(%$userlist));
3588: }
3589: my $rowcount = 0;
3590: my $disabled;
3591: if ($mode eq 'autoenroll') {
3592: unless ($permission->{'cusr'}) {
3593: $disabled = ' disabled="disabled"';
3594: }
3595: }
3596: foreach my $user (@sorted_users) {
3597: my %in;
3598: my $sdata = $userlist->{$user};
3599: $rowcount ++;
3600: foreach my $item (@{$keylist}) {
3601: $in{$item} = $sdata->[$index{$item}];
3602: }
3603: my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
3604: if ($clickers!~/\w/) { $clickers='-'; }
3605: $in{'clicker'} = $clickers;
3606: my $role = $in{'role'};
3607: $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
3608: unless ($mode eq 'excel') {
3609: if (! defined($in{'start'}) || $in{'start'} == 0) {
3610: $in{'start'} = &mt('none');
3611: } else {
3612: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
3613: }
3614: if (! defined($in{'end'}) || $in{'end'} == 0) {
3615: $in{'end'} = &mt('none');
3616: } else {
3617: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
3618: }
3619: }
3620: if ($context eq 'course') {
3621: my $lastlogin = $crslogins{$in{'username'}.':'.$in{'domain'}.':'.$in{'section'}.':'.$role};
3622: if ($lastlogin ne '') {
3623: $in{'lastlogin'} = &Apache::lonlocal::locallocaltime($lastlogin);
3624: }
3625: }
3626: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
3627: $r->print(&Apache::loncommon::start_data_table_row());
3628: my $checkval;
3629: if ($mode eq 'autoenroll') {
3630: my $cellentry;
3631: if ($in{'type'} eq 'auto') {
3632: $cellentry = '<b>'.&mt('auto').'</b> <label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Change').'</label>';
3633: $autocount ++;
3634: } else {
3635: $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">';
3636: $manualcount ++;
3637: if ($in{'lockedtype'}) {
3638: $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Unlock').'</label>';
3639: $unlockcount ++;
3640: } else {
3641: $cellentry .= '<label><input type="checkbox" name="lockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Lock').'</label>';
3642: $lockcount ++;
3643: }
3644: $cellentry .= '</span></td></tr></table>';
3645: }
3646: $r->print("<td>$cellentry</td>\n");
3647: } else {
3648: if ($mode ne 'pickauthor') {
3649: $r->print("<td>$rowcount</td>\n");
3650: }
3651: if ($actionselect) {
3652: my $showcheckbox;
3653: if ($role =~ /^cr\//) {
3654: $showcheckbox = $canchange{'cr'};
3655: } else {
3656: $showcheckbox = $canchange{$role};
3657: }
3658: if (!$showcheckbox) {
3659: if ($context eq 'course') {
3660: if ($canchangesec{$role} ne '') {
3661: if ($canchangesec{$role} eq $in{'section'}) {
3662: $showcheckbox = 1;
3663: }
3664: }
3665: }
3666: }
3667: if ($showcheckbox) {
3668: $checkval = $user;
3669: if ($context eq 'course') {
3670: if (($role eq 'co' || $role eq 'cc') &&
3671: ($user =~ /^\Q$env{'user.name'}:$env{'user.domain'}:$role\E/)) {
3672: $showcheckbox = 0;
3673: } else {
3674: if ($role eq 'st') {
3675: $checkval .= ':st';
3676: }
3677: $checkval .= ':'.$in{'section'};
3678: if ($role eq 'st') {
3679: $checkval .= ':'.$in{'type'}.':'.
3680: $in{'lockedtype'}.':'.
3681: $in{'credits'}.':'.
3682: &escape($in{'instsec'});
3683: }
3684: }
3685: }
3686: if ($showcheckbox) {
3687: $r->print('<td><input type="checkbox" name="'.
3688: 'actionlist" value="'.
3689: &HTML::Entities::encode($checkval,'&<>"').'" />');
3690: foreach my $item ('start','end') {
3691: $r->print('<input type="hidden" name="'.
3692: &HTML::Entities::encode($checkval.'_'.$item,'&<>"').'"'.
3693: ' value="'.$sdata->[$index{$item}].'" />');
3694: }
3695: $r->print('</td>');
3696: } else {
3697: $r->print('<td> </td>');
3698: }
3699: } else {
3700: $r->print('<td> </td>');
3701: }
3702: } elsif ($mode eq 'pickauthor') {
3703: $r->print('<td><input type="button" name="chooseauthor" onclick="javascript:gochoose('."'$in{'username'}'".');" value="'.&mt('Select').'" /></td>');
3704: }
3705: }
3706: foreach my $item (@cols) {
3707: if ($item eq 'username') {
3708: $r->print('<td>'.&print_username_link($mode,\%in).'</td>');
3709: } elsif ($item eq 'status') {
3710: my $showitem = $in{$item};
3711: if (defined($ltstatus{$in{$item}})) {
3712: $showitem = $ltstatus{$in{$item}};
3713: }
3714: $r->print('<td>'.$showitem.'</td>'."\n");
3715: } elsif ($item eq 'photo') {
3716: if (($context eq 'course') && ($mode ne 'autoenroll') &&
3717: ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
3718: if ($role eq 'st') {
3719: $r->print('<td align="right"><a href="javascript:photowindow('."'".$in{'photo'}."'".')"><img src="'.$in{'thumbnail'}.'" border="1" alt="" /></a></td>');
3720: } else {
3721: $r->print('<td> </td>');
3722: }
3723: }
3724: } elsif ($item eq 'clicker') {
3725: if (($context eq 'course') && ($mode ne 'autoenroll')) {
3726: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
3727: my $clickers =
3728: (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
3729: if ($clickers!~/\w/) { $clickers='-'; }
3730: $r->print('<td>'.$clickers.'</td>');
3731: } else {
3732: $r->print('<td> </td>'."\n");
3733: }
3734: }
3735: } elsif (($item eq 'authorquota') || ($item eq 'authorusage')) {
3736: $r->print('<td align="right">'.$in{$item}.'</td>'."\n");
3737: } else {
3738: $r->print('<td>'.$in{$item}.'</td>'."\n");
3739: }
3740: }
3741: $r->print(&Apache::loncommon::end_data_table_row());
3742: } elsif ($mode eq 'csv') {
3743: next if (! defined($CSVfile));
3744: # no need to bother with $linkto
3745: my @line = ();
3746: foreach my $item (@cols) {
3747: push @line,&Apache::loncommon::csv_translate($in{$item});
3748: }
3749: print $CSVfile '"'.join('","',@line)."\"\n";
3750: } elsif ($mode eq 'excel') {
3751: my $col = 0;
3752: foreach my $item (@cols) {
3753: if ($item eq 'start' || $item eq 'end') {
3754: if ((defined($in{$item})) && ($in{$item} != 0)) {
3755: $excel_sheet->write($row,$col++,
3756: &Apache::lonstathelpers::calc_serial($in{$item}),
3757: $format->{'date'});
3758: } else {
3759: $excel_sheet->write($row,$col++,'none');
3760: }
3761: } else {
3762: $excel_sheet->write($row,$col++,$in{$item});
3763: }
3764: }
3765: $row++;
3766: }
3767: }
3768: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
3769: $r->print(&Apache::loncommon::end_data_table().'<br />');
3770: } elsif ($mode eq 'excel') {
3771: $excel_workbook->close();
3772: $r->print('<p>'.&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '<a href="'.$excel_filename.'">','</a>')."</p>\n");
3773: } elsif ($mode eq 'csv') {
3774: close($CSVfile);
3775: $r->print('<p>'.&mt('[_1]Your CSV file[_2] is ready for download.', '<a href="'.$CSVfilename.'">','</a>')."</p>\n");
3776: $r->rflush();
3777: }
3778: if ($mode eq 'autoenroll') {
3779: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
3780: } else {
3781: return ($usercount);
3782: }
3783: }
3784:
3785: sub bulkaction_javascript {
3786: my ($formname,$caller) = @_;
3787: my $docstart = 'document';
3788: if ($caller eq 'popup') {
3789: $docstart = 'opener.document';
3790: }
3791: my %lt = &Apache::lonlocal::texthash(
3792: acwi => 'Access will be set to start immediately',
3793: asyo => 'as you did not select an end date in the pop-up window',
3794: accw => 'Access will be set to continue indefinitely',
3795: asyd => 'as you did not select an end date in the pop-up window',
3796: sewi => "Sections will be switched to 'No section'",
3797: ayes => "as you either selected the 'No section' option",
3798: oryo => 'or you did not select a section in the pop-up window',
3799: arol => 'A role with no section will be added',
3800: swbs => 'Sections will be switched to:',
3801: rwba => 'Roles will be added for section(s):',
3802: );
3803: my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
3804: my $noaction = &mt("You need to select an action to take for the user(s) you have selected");
3805: my $singconfirm = &mt(' for a single user?');
3806: my $multconfirm = &mt(' for multiple users?');
3807: &js_escape(\$alert);
3808: &js_escape(\$noaction);
3809: &js_escape(\$singconfirm);
3810: &js_escape(\$multconfirm);
3811: my $output = <<"ENDJS";
3812: function verify_action (field) {
3813: var numchecked = 0;
3814: var singconf = '$singconfirm';
3815: var multconf = '$multconfirm';
3816: if ($docstart.$formname.elements[field].length > 0) {
3817: for (i=0; i<$docstart.$formname.elements[field].length; i++) {
3818: if ($docstart.$formname.elements[field][i].checked == true) {
3819: numchecked ++;
3820: }
3821: }
3822: } else {
3823: if ($docstart.$formname.elements[field].checked == true) {
3824: numchecked ++;
3825: }
3826: }
3827: if (numchecked == 0) {
3828: alert("$alert");
3829: return;
3830: } else {
3831: var message = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].text;
3832: var choice = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].value;
3833: if (choice == '') {
3834: alert("$noaction");
3835: return;
3836: } else {
3837: if (numchecked == 1) {
3838: message += singconf;
3839: } else {
3840: message += multconf;
3841: }
3842: ENDJS
3843: if ($caller ne 'popup') {
3844: $output .= <<"NEWWIN";
3845: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate' || choice == 'chgsec') {
3846: opendatebrowser(document.$formname,'$formname','go');
3847: return;
3848:
3849: } else {
3850: if (confirm(message)) {
3851: document.$formname.phase.value = 'bulkchange';
3852: document.$formname.submit();
3853: return;
3854: }
3855: }
3856: NEWWIN
3857: } else {
3858: $output .= <<"POPUP";
3859: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
3860: var datemsg = '';
3861: if (($docstart.$formname.startdate_month.value == '') &&
3862: ($docstart.$formname.startdate_day.value == '') &&
3863: ($docstart.$formname.startdate_year.value == '')) {
3864: datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
3865: }
3866: if (($docstart.$formname.enddate_month.value == '') &&
3867: ($docstart.$formname.enddate_day.value == '') &&
3868: ($docstart.$formname.enddate_year.value == '')) {
3869: datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
3870: }
3871: if (datemsg != '') {
3872: message += "\\n"+datemsg;
3873: }
3874: }
3875: if (choice == 'chgsec') {
3876: var rolefilter = $docstart.$formname.showrole.options[$docstart.$formname.showrole.selectedIndex].value;
3877: var retained = $docstart.$formname.retainsec.value;
3878: var secshow = $docstart.$formname.newsecs.value;
3879: if (secshow == '') {
3880: if (rolefilter == 'st' || retained == 0 || retained == "") {
3881: message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
3882: } else {
3883: message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
3884: }
3885: } else {
3886: if (rolefilter == 'st' || retained == 0 || retained == "") {
3887: message += "\\n\\n$lt{'swbs'} "+secshow+".\\n";
3888: } else {
3889: message += "\\n\\n$lt{'rwba'} "+secshow+".\\n";
3890: }
3891: }
3892: }
3893: if (confirm(message)) {
3894: $docstart.$formname.phase.value = 'bulkchange';
3895: $docstart.$formname.submit();
3896: window.close();
3897: }
3898: POPUP
3899: }
3900: $output .= '
3901: }
3902: }
3903: }
3904: ';
3905: return $output;
3906: }
3907:
3908: sub print_username_link {
3909: my ($mode,$in) = @_;
3910: my $output;
3911: if ($mode eq 'autoenroll') {
3912: $output = $in->{'username'};
3913: } else {
3914: $output = '<a href="javascript:username_display_launch('.
3915: "'$in->{'username'}','$in->{'domain'}'".')">'.
3916: $in->{'username'}.'</a>';
3917: }
3918: return $output;
3919: }
3920:
3921: sub role_type_names {
3922: my %lt = &Apache::lonlocal::texthash (
3923: 'domain' => 'Domain Roles',
3924: 'author' => 'Co-Author Roles',
3925: 'course' => 'Course Roles',
3926: 'community' => 'Community Roles',
3927: );
3928: return %lt;
3929: }
3930:
3931: sub select_actions {
3932: my ($context,$setting,$statusmode,$formname) = @_;
3933: my %lt = &Apache::lonlocal::texthash(
3934: revoke => "Revoke user roles",
3935: delete => "Delete user roles",
3936: reenable => "Re-enable expired user roles",
3937: activate => "Make future user roles active now",
3938: chgdates => "Change starting/ending dates",
3939: chgsec => "Change section associated with user roles",
3940: );
3941: # FIXME Add an option to change credits for student roles.
3942: my ($output,$options,%choices);
3943: # FIXME Disable actions for now for roletype=course in domain context
3944: if ($context eq 'domain' && $setting eq 'course') {
3945: return;
3946: }
3947: if ($context eq 'course') {
3948: if ($env{'form.showrole'} ne 'Any') {
3949: my $showactions;
3950: if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},
3951: $env{'request.course.id'})) {
3952: $showactions = 1;
3953: } elsif ($env{'request.course.sec'} ne '') {
3954: if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
3955: $showactions = 1;
3956: }
3957: }
3958: unless ($showactions) {
3959: unless (&is_courseowner($env{'request.course.id'},
3960: $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
3961: return;
3962: }
3963: }
3964: }
3965: }
3966: if ($statusmode eq 'Any') {
3967: $options .= '
3968: <option value="chgdates">'.$lt{'chgdates'}.'</option>';
3969: $choices{'dates'} = 1;
3970: } else {
3971: if ($statusmode eq 'Future') {
3972: $options .= '
3973: <option value="activate">'.$lt{'activate'}.'</option>';
3974: $choices{'dates'} = 1;
3975: } elsif ($statusmode eq 'Expired') {
3976: $options .= '
3977: <option value="reenable">'.$lt{'reenable'}.'</option>';
3978: $choices{'dates'} = 1;
3979: }
3980: if ($statusmode eq 'Active' || $statusmode eq 'Future') {
3981: $options .= '
3982: <option value="chgdates">'.$lt{'chgdates'}.'</option>
3983: <option value="revoke">'.$lt{'revoke'}.'</option>';
3984: $choices{'dates'} = 1;
3985: }
3986: }
3987: if ($context eq 'domain') {
3988: $options .= '
3989: <option value="delete">'.$lt{'delete'}.'</option>';
3990: }
3991: if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
3992: if (($statusmode ne 'Expired') && ($env{'request.course.sec'} eq '')) {
3993: $options .= '
3994: <option value="chgsec">'.$lt{'chgsec'}.'</option>';
3995: $choices{'sections'} = 1;
3996: }
3997: }
3998: if ($options) {
3999: $output = '<select name="bulkaction">'."\n".
4000: '<option value="" selected="selected">'.
4001: &mt('Please select').'</option>'."\n".$options."\n".'</select>';
4002: if ($choices{'dates'}) {
4003: $output .=
4004: '<input type="hidden" name="startdate_month" value="" />'."\n".
4005: '<input type="hidden" name="startdate_day" value="" />'."\n".
4006: '<input type="hidden" name="startdate_year" value="" />'."\n".
4007: '<input type="hidden" name="startdate_hour" value="" />'."\n".
4008: '<input type="hidden" name="startdate_minute" value="" />'."\n".
4009: '<input type="hidden" name="startdate_second" value="" />'."\n".
4010: '<input type="hidden" name="enddate_month" value="" />'."\n".
4011: '<input type="hidden" name="enddate_day" value="" />'."\n".
4012: '<input type="hidden" name="enddate_year" value="" />'."\n".
4013: '<input type="hidden" name="enddate_hour" value="" />'."\n".
4014: '<input type="hidden" name="enddate_minute" value="" />'."\n".
4015: '<input type="hidden" name="enddate_second" value="" />'."\n".
4016: '<input type="hidden" name="no_end_date" value="" />'."\n";
4017: if ($context eq 'course') {
4018: $output .= '<input type="hidden" name="makedatesdefault" value="" />'."\n";
4019: }
4020: }
4021: if ($choices{'sections'}) {
4022: $output .= '<input type="hidden" name="retainsec" value="" />'."\n".
4023: '<input type="hidden" name="newsecs" value="" />'."\n";
4024: }
4025: }
4026: return $output;
4027: }
4028:
4029: sub date_section_javascript {
4030: my ($context,$setting) = @_;
4031: my $title = 'Date_And_Section_Selector';
4032: my %nopopup = &Apache::lonlocal::texthash (
4033: revoke => "Check the boxes for any users for whom roles are to be revoked, and click 'Proceed'",
4034: delete => "Check the boxes for any users for whom roles are to be deleted, and click 'Proceed'",
4035: none => "Choose an action to take for selected users",
4036: );
4037: my $output = <<"ENDONE";
4038: <script type="text/javascript">
4039: // <![CDATA[
4040: function opendatebrowser(callingform,formname,calledby) {
4041: var bulkaction = callingform.bulkaction.options[callingform.bulkaction.selectedIndex].value;
4042: var url = '/adm/createuser?';
4043: var type = '';
4044: var showrole = callingform.showrole.options[callingform.showrole.selectedIndex].value;
4045: ENDONE
4046: if ($context eq 'domain') {
4047: $output .= '
4048: type = callingform.roletype.options[callingform.roletype.selectedIndex].value;
4049: ';
4050: }
4051: my $width= '700';
4052: my $height = '400';
4053: $output .= <<"ENDTWO";
4054: url += 'action=dateselect&callingform=' + formname +
4055: '&roletype='+type+'&showrole='+showrole +'&bulkaction='+bulkaction;
4056: var title = '$title';
4057: var options = 'scrollbars=1,resizable=1,menubar=0';
4058: options += ',width=$width,height=$height';
4059: stdeditbrowser = open(url,title,options,'1');
4060: stdeditbrowser.focus();
4061: }
4062: // ]]>
4063: </script>
4064: ENDTWO
4065: return $output;
4066: }
4067:
4068: sub date_section_selector {
4069: my ($context,$permission,$crstype,$showcredits) = @_;
4070: my $callingform = $env{'form.callingform'};
4071: my $formname = 'dateselect';
4072: my $groupslist = &get_groupslist();
4073: my $sec_js =
4074: &setsections_javascript($formname,$groupslist,undef,undef,$crstype,
4075: $showcredits);
4076: my $output = <<"END";
4077: <script type="text/javascript">
4078: // <![CDATA[
4079:
4080: $sec_js
4081:
4082: function saveselections(formname) {
4083:
4084: END
4085: if ($env{'form.bulkaction'} eq 'chgsec') {
4086: $output .= <<"END";
4087: if (formname.retainsec.length > 1) {
4088: for (var i=0; i<formname.retainsec.length; i++) {
4089: if (formname.retainsec[i].checked == true) {
4090: opener.document.$callingform.retainsec.value = formname.retainsec[i].value;
4091: }
4092: }
4093: } else {
4094: opener.document.$callingform.retainsec.value = formname.retainsec.value;
4095: }
4096: setSections(formname,'$crstype');
4097: if (seccheck == 'ok') {
4098: opener.document.$callingform.newsecs.value = formname.sections.value;
4099: } else {
4100: return;
4101: }
4102: END
4103: } else {
4104: if ($context eq 'course') {
4105: if (($env{'form.bulkaction'} eq 'reenable') ||
4106: ($env{'form.bulkaction'} eq 'activate') ||
4107: ($env{'form.bulkaction'} eq 'chgdates')) {
4108: if ($env{'request.course.sec'} eq '') {
4109: $output .= <<"END";
4110:
4111: if (formname.makedatesdefault.checked == true) {
4112: opener.document.$callingform.makedatesdefault.value = 1;
4113: }
4114: else {
4115: opener.document.$callingform.makedatesdefault.value = 0;
4116: }
4117:
4118: END
4119: }
4120: }
4121: }
4122: $output .= <<"END";
4123: opener.document.$callingform.startdate_month.value = formname.startdate_month.options[formname.startdate_month.selectedIndex].value;
4124: opener.document.$callingform.startdate_day.value = formname.startdate_day.value;
4125: opener.document.$callingform.startdate_year.value = formname.startdate_year.value;
4126: opener.document.$callingform.startdate_hour.value = formname.startdate_hour.options[formname.startdate_hour.selectedIndex].value;
4127: opener.document.$callingform.startdate_minute.value = formname.startdate_minute.value;
4128: opener.document.$callingform.startdate_second.value = formname.startdate_second.value;
4129: opener.document.$callingform.enddate_month.value = formname.enddate_month.options[formname.enddate_month.selectedIndex].value;
4130: opener.document.$callingform.enddate_day.value = formname.enddate_day.value;
4131: opener.document.$callingform.enddate_year.value = formname.enddate_year.value;
4132: opener.document.$callingform.enddate_hour.value = formname.enddate_hour.options[formname.enddate_hour.selectedIndex].value;
4133: opener.document.$callingform.enddate_minute.value = formname.enddate_minute.value;
4134: opener.document.$callingform.enddate_second.value = formname.enddate_second.value;
4135: if (formname.no_end_date.checked) {
4136: opener.document.$callingform.no_end_date.value = '1';
4137: } else {
4138: opener.document.$callingform.no_end_date.value = '0';
4139: }
4140: END
4141: }
4142: my $verify_action_js = &bulkaction_javascript($callingform,'popup');
4143: $output .= <<"ENDJS";
4144: verify_action('actionlist');
4145: }
4146:
4147: $verify_action_js
4148:
4149: // ]]>
4150: </script>
4151: ENDJS
4152: my %lt = &Apache::lonlocal::texthash (
4153: chac => 'Access dates to apply for selected users',
4154: chse => 'Changes in section affiliation to apply to selected users',
4155: 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.',
4156: forn => 'For a course role that is not "student", users may have roles in more than one section at a time.',
4157: reta => "Retain each user's current section affiliations?",
4158: dnap => '(Does not apply to student roles).',
4159: );
4160: my ($date_items,$headertext);
4161: if ($env{'form.bulkaction'} eq 'chgsec') {
4162: $headertext = $lt{'chse'};
4163: } else {
4164: $headertext = $lt{'chac'};
4165: my $starttime;
4166: if (($env{'form.bulkaction'} eq 'activate') ||
4167: ($env{'form.bulkaction'} eq 'reenable')) {
4168: $starttime = time;
4169: }
4170: $date_items = &date_setting_table($starttime,undef,$context,
4171: $env{'form.bulkaction'},$formname,
4172: $permission,$crstype);
4173: }
4174: $output .= '<h3>'.$headertext.'</h3>'.
4175: '<form name="'.$formname.'" method="post" action="">'."\n".
4176: $date_items;
4177: if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
4178: my ($cnum,$cdom) = &get_course_identity();
4179: if ($crstype eq 'Community') {
4180: $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.');
4181: $lt{'forn'} = &mt('For a community role that is not "member", users may have roles in more than one section at a time.');
4182: $lt{'dnap'} = &mt('(Does not apply to member roles).');
4183: }
4184: my $info;
4185: if ($env{'form.showrole'} eq 'st') {
4186: $output .= '<p>'.$lt{'fors'}.'</p>';
4187: } elsif ($env{'form.showrole'} eq 'Any') {
4188: $output .= '<p>'.$lt{'fors'}.'</p>'.
4189: '<p>'.$lt{'forn'}.' ';
4190: $info = $lt{'reta'};
4191: } else {
4192: $output .= '<p>'.$lt{'forn'}.' ';
4193: $info = $lt{'reta'};
4194: }
4195: if ($info) {
4196: $info .= '<span class="LC_nobreak">'.
4197: '<label><input type="radio" name="retainsec" value="1" '.
4198: 'checked="checked" />'.&mt('Yes').'</label> '.
4199: '<label><input type="radio" name="retainsec" value="0" />'.
4200: &mt('No').'</label></span>';
4201: if ($env{'form.showrole'} eq 'Any') {
4202: $info .= '<br />'.$lt{'dnap'};
4203: }
4204: $info .= '</p>';
4205: } else {
4206: $info = '<input type="hidden" name="retainsec" value="0" />';
4207: }
4208: my $rowtitle = &mt('New section to assign');
4209: my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,
4210: $permission,$context,'chgsec',$crstype);
4211: $output .= $info.$secbox;
4212: }
4213: $output .= '<p>'.
4214: '<input type="button" name="dateselection" value="'.&mt('Save').'" onclick="javascript:saveselections(this.form)" /></p>'."\n".
4215: '</form>';
4216: return $output;
4217: }
4218:
4219: sub section_picker {
4220: my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode,$crstype,
4221: $showcredits,$credits) = @_;
4222: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
4223: my $sections_select .= &course_sections(\%sections_count,$role);
4224: my $secbox = '<div>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
4225: if ($mode eq 'upload') {
4226: my ($options,$cb_script,$coursepick) =
4227: &default_role_selector($context,1,$crstype,$showcredits);
4228: $secbox .= &Apache::lonhtmlcommon::row_title(&mt('role'),'LC_oddrow_value').
4229: $options. &Apache::lonhtmlcommon::row_closure(1)."\n";
4230: }
4231: $secbox .= &Apache::lonhtmlcommon::row_title($rowtitle,'LC_oddrow_value')."\n";
4232: if ($env{'request.course.sec'} eq '') {
4233: $secbox .= '<table class="LC_createuser"><tr class="LC_section_row">'."\n".
4234: '<td align="center">'.&mt('Existing sections')."\n".
4235: '<br />'.$sections_select.'</td><td align="center">'.
4236: &mt('New section').'<br />'."\n".
4237: '<input type="text" name="newsec" size="15" value="" />'."\n".
4238: '<input type="hidden" name="sections" value="" />'."\n".
4239: '</td></tr></table>'."\n";
4240: } else {
4241: $secbox .= '<input type="hidden" name="sections" value="'.
4242: $env{'request.course.sec'}.'" />'.
4243: $env{'request.course.sec'};
4244: }
4245: $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n";
4246: unless ($mode eq 'chgsec') {
4247: if ($showcredits) {
4248: $secbox .=
4249: &Apache::lonhtmlcommon::row_title(&mt('credits (students)'),
4250: 'LC_evenrow_value')."\n".
4251: '<input type="text" name="credits" size="3" value="'.$credits.'" />'."\n".
4252: &Apache::lonhtmlcommon::row_closure(1)."\n";
4253: }
4254: }
4255: $secbox .= &Apache::lonhtmlcommon::end_pick_box().'</div>';
4256: return $secbox;
4257: }
4258:
4259: sub results_header_row {
4260: my ($rolefilter,$statusmode,$context,$permission,$mode,$crstype) = @_;
4261: my ($description,$showfilter);
4262: if ($rolefilter ne 'Any') {
4263: $showfilter = $rolefilter;
4264: }
4265: if ($context eq 'course') {
4266: if ($mode eq 'csv' || $mode eq 'excel') {
4267: if ($crstype eq 'Community') {
4268: $description = &mt('Community - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
4269: } else {
4270: $description = &mt('Course - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
4271: }
4272: }
4273: if ($statusmode eq 'Expired') {
4274: if ($crstype eq 'Community') {
4275: $description .= &mt('Users in community with expired [_1] roles',$showfilter);
4276: } else {
4277: $description .= &mt('Users in course with expired [_1] roles',$showfilter);
4278: }
4279: } elsif ($statusmode eq 'Future') {
4280: if ($crstype eq 'Community') {
4281: $description .= &mt('Users in community with future [_1] roles',$showfilter);
4282: } else {
4283: $description .= &mt('Users in course with future [_1] roles',$showfilter);
4284: }
4285: } elsif ($statusmode eq 'Active') {
4286: if ($crstype eq 'Community') {
4287: $description .= &mt('Users in community with active [_1] roles',$showfilter);
4288: } else {
4289: $description .= &mt('Users in course with active [_1] roles',$showfilter);
4290: }
4291: } else {
4292: if ($rolefilter eq 'Any') {
4293: if ($crstype eq 'Community') {
4294: $description .= &mt('All users in community');
4295: } else {
4296: $description .= &mt('All users in course');
4297: }
4298: } else {
4299: if ($crstype eq 'Community') {
4300: $description .= &mt('All users in community with [_1] roles',$rolefilter);
4301: } else {
4302: $description .= &mt('All users in course with [_1] roles',$rolefilter);
4303: }
4304: }
4305: }
4306: my $constraint;
4307: my $viewablesec = &viewable_section($permission);
4308: if ($viewablesec ne '') {
4309: if ($env{'form.showrole'} eq 'st') {
4310: $constraint = &mt('only users in section "[_1]"',$viewablesec);
4311: } elsif (($env{'form.showrole'} ne 'cc') && ($env{'form.showrole'} ne 'co')) {
4312: $constraint = &mt('only users affiliated with no section or section "[_1]"',$viewablesec);
4313: }
4314: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
4315: if ($env{'form.grpfilter'} eq 'none') {
4316: $constraint .= &mt(' and not in any group');
4317: } else {
4318: $constraint .= &mt(' and members of group: "[_1]"',$env{'form.grpfilter'});
4319: }
4320: }
4321: } else {
4322: if (($env{'form.secfilter'} ne 'all') && ($env{'form.secfilter'} ne '')) {
4323: if ($env{'form.secfilter'} eq 'none') {
4324: $constraint = &mt('only users affiliated with no section');
4325: } else {
4326: $constraint = &mt('only users affiliated with section "[_1]"',$env{'form.secfilter'});
4327: }
4328: }
4329: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
4330: if ($env{'form.grpfilter'} eq 'none') {
4331: if ($constraint eq '') {
4332: $constraint = &mt('only users not in any group');
4333: } else {
4334: $constraint .= &mt(' and also not in any group');
4335: }
4336: } else {
4337: if ($constraint eq '') {
4338: $constraint = &mt('only members of group: "[_1]"',$env{'form.grpfilter'});
4339: } else {
4340: $constraint .= &mt(' and also members of group: "[_1]"'.$env{'form.grpfilter'});
4341: }
4342: }
4343: }
4344: }
4345: if ($constraint ne '') {
4346: $description .= ' ('.$constraint.')';
4347: }
4348: } elsif ($context eq 'author') {
4349: $description =
4350: &mt('Author space for [_1]'
4351: ,'<span class="LC_cusr_emph">'
4352: .&Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'})
4353: .'</span>')
4354: .': ';
4355: if ($statusmode eq 'Expired') {
4356: $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
4357: } elsif ($statusmode eq 'Future') {
4358: $description .= &mt('Co-authors with future [_1] roles',$showfilter);
4359: } elsif ($statusmode eq 'Active') {
4360: $description .= &mt('Co-authors with active [_1] roles',$showfilter);
4361: } else {
4362: if ($rolefilter eq 'Any') {
4363: $description .= &mt('All co-authors');
4364: } else {
4365: $description .= &mt('All co-authors with [_1] roles',$rolefilter);
4366: }
4367: }
4368: } elsif ($context eq 'domain') {
4369: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
4370: $description = &mt('Domain - [_1]:',$domdesc).' ';
4371: if ($env{'form.roletype'} eq 'domain') {
4372: if ($statusmode eq 'Expired') {
4373: $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
4374: } elsif ($statusmode eq 'Future') {
4375: $description .= &mt('Users in domain with future [_1] roles',$showfilter);
4376: } elsif ($statusmode eq 'Active') {
4377: $description .= &mt('Users in domain with active [_1] roles',$showfilter);
4378: } else {
4379: if ($rolefilter eq 'Any') {
4380: $description .= &mt('All users in domain');
4381: } else {
4382: $description .= &mt('All users in domain with [_1] roles',$rolefilter);
4383: }
4384: }
4385: } elsif ($env{'form.roletype'} eq 'author') {
4386: if ($statusmode eq 'Expired') {
4387: $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
4388: } elsif ($statusmode eq 'Future') {
4389: $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
4390: } elsif ($statusmode eq 'Active') {
4391: $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
4392: } else {
4393: if ($rolefilter eq 'Any') {
4394: $description .= &mt('All users with co-author roles in domain',$showfilter);
4395: } else {
4396: $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
4397: }
4398: }
4399: } elsif (($env{'form.roletype'} eq 'course') ||
4400: ($env{'form.roletype'} eq 'community')) {
4401: my $coursefilter = $env{'form.coursepick'};
4402: if ($env{'form.roletype'} eq 'course') {
4403: if ($coursefilter eq 'category') {
4404: my $instcode = &instcode_from_coursefilter();
4405: if ($instcode eq '.') {
4406: $description .= &mt('All courses in domain').' - ';
4407: } else {
4408: $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
4409: }
4410: } elsif ($coursefilter eq 'selected') {
4411: $description .= &mt('Selected courses in domain').' - ';
4412: } elsif ($coursefilter eq 'all') {
4413: $description .= &mt('All courses in domain').' - ';
4414: }
4415: } elsif ($env{'form.roletype'} eq 'community') {
4416: if ($coursefilter eq 'selected') {
4417: $description .= &mt('Selected communities in domain').' - ';
4418: } elsif ($coursefilter eq 'all') {
4419: $description .= &mt('All communities in domain').' - ';
4420: }
4421: }
4422: if ($statusmode eq 'Expired') {
4423: $description .= &mt('users with expired [_1] roles',$showfilter);
4424: } elsif ($statusmode eq 'Future') {
4425: $description .= &mt('users with future [_1] roles',$showfilter);
4426: } elsif ($statusmode eq 'Active') {
4427: $description .= &mt('users with active [_1] roles',$showfilter);
4428: } else {
4429: if ($rolefilter eq 'Any') {
4430: $description .= &mt('all users');
4431: } else {
4432: $description .= &mt('users with [_1] roles',$rolefilter);
4433: }
4434: }
4435: }
4436: }
4437: return $description;
4438: }
4439:
4440: sub viewable_section {
4441: my ($permission) = @_;
4442: my $viewablesec;
4443: if (ref($permission) eq 'HASH') {
4444: if (exists($permission->{'view_section'})) {
4445: $viewablesec = $permission->{'view_section'};
4446: } elsif (exists($permission->{'cusr_section'})) {
4447: $viewablesec = $permission->{'cusr_section'};
4448: }
4449: }
4450: return $viewablesec;
4451: }
4452:
4453:
4454: #################################################
4455: #################################################
4456: sub show_drop_list {
4457: my ($r,$classlist,$nosort,$permission,$crstype) = @_;
4458: my $cid = $env{'request.course.id'};
4459: my ($cnum,$cdom) = &get_course_identity($cid);
4460: if (! exists($env{'form.sortby'})) {
4461: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
4462: ['sortby']);
4463: }
4464: my $sortby = $env{'form.sortby'};
4465: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
4466: $sortby = 'username';
4467: }
4468: my $action = "drop";
4469: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
4470: $r->print(<<END);
4471: <input type="hidden" name="sortby" value="$sortby" />
4472: <input type="hidden" name="action" value="$action" />
4473: <input type="hidden" name="state" value="done" />
4474: <script type="text/javascript" language="Javascript">
4475: // <![CDATA[
4476: $check_uncheck_js
4477: // ]]>
4478: </script>
4479: <input type="hidden" name="phase" value="four" />
4480: END
4481: my ($indexhash,$keylist) = &make_keylist_array();
4482: my $studentcount = 0;
4483: if (ref($classlist) eq 'HASH') {
4484: foreach my $student (keys(%{$classlist})) {
4485: my $sdata = $classlist->{$student};
4486: my $status = $sdata->[$indexhash->{'status'}];
4487: my $section = $sdata->[$indexhash->{'section'}];
4488: if ($status ne 'Active') {
4489: delete($classlist->{$student});
4490: next;
4491: }
4492: if ($env{'request.course.sec'} ne '') {
4493: if ($section ne $env{'request.course.sec'}) {
4494: delete($classlist->{$student});
4495: next;
4496: }
4497: }
4498: $studentcount ++;
4499: }
4500: }
4501: if (!$studentcount) {
4502: my $msg = '';
4503: if ($crstype eq 'Community') {
4504: $msg = &mt('There are no members to drop.');
4505: } else {
4506: $msg = &mt('There are no students to drop.');
4507: }
4508: $r->print('<p class="LC_info">'.$msg.'</p>');
4509: return;
4510: }
4511: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
4512: $classlist,$keylist,$cdom,$cnum);
4513: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
4514: 'dom' => "domain",
4515: 'id' => "ID",
4516: 'sn' => "student name",
4517: 'mn' => "member name",
4518: 'sec' => "section",
4519: 'start' => "start date",
4520: 'end' => "end date",
4521: 'groups' => "active groups",
4522: );
4523: my $nametitle = $lt{'sn'};
4524: if ($crstype eq 'Community') {
4525: $nametitle = $lt{'mn'};
4526: }
4527: if ($nosort) {
4528: $r->print(&Apache::loncommon::start_data_table().
4529: &Apache::loncommon::start_data_table_header_row());
4530: $r->print(<<END);
4531: <th> </th>
4532: <th>$lt{'usrn'}</th>
4533: <th>$lt{'dom'}</th>
4534: <th>$lt{'id'}</th>
4535: <th>$nametitle</th>
4536: <th>$lt{'sec'}</th>
4537: <th>$lt{'start'}</th>
4538: <th>$lt{'end'}</th>
4539: <th>$lt{'groups'}</th>
4540: END
4541: $r->print(&Apache::loncommon::end_data_table_header_row());
4542: } else {
4543: $r->print(&Apache::loncommon::start_data_table().
4544: &Apache::loncommon::start_data_table_header_row());
4545: $r->print(<<END);
4546: <th> </th>
4547: <th>
4548: <a href="/adm/createuser?action=$action&sortby=username">$lt{'usrn'}</a>
4549: </th><th>
4550: <a href="/adm/createuser?action=$action&sortby=domain">$lt{'dom'}</a>
4551: </th><th>
4552: <a href="/adm/createuser?action=$action&sortby=id">$lt{'id'}</a>
4553: </th><th>
4554: <a href="/adm/createuser?action=$action&sortby=fullname">$nametitle</a>
4555: </th><th>
4556: <a href="/adm/createuser?action=$action&sortby=section">$lt{'sec'}</a>
4557: </th><th>
4558: <a href="/adm/createuser?action=$action&sortby=start">$lt{'start'}</a>
4559: </th><th>
4560: <a href="/adm/createuser?action=$action&sortby=end">$lt{'end'}</a>
4561: </th><th>
4562: <a href="/adm/createuser?action=$action&sortby=groups">$lt{'groups'}</a>
4563: </th>
4564: END
4565: $r->print(&Apache::loncommon::end_data_table_header_row());
4566: }
4567: #
4568: # Sort the students
4569: my $index = $indexhash->{$sortby};
4570: my $second = $indexhash->{'username'};
4571: my $third = $indexhash->{'domain'};
4572: my @Sorted_Students = sort {
4573: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
4574: ||
4575: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
4576: ||
4577: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
4578: } (keys(%{$classlist}));
4579: foreach my $student (@Sorted_Students) {
4580: my $error;
4581: my $sdata = $classlist->{$student};
4582: my $username = $sdata->[$indexhash->{'username'}];
4583: my $domain = $sdata->[$indexhash->{'domain'}];
4584: my $section = $sdata->[$indexhash->{'section'}];
4585: my $name = $sdata->[$indexhash->{'fullname'}];
4586: my $id = $sdata->[$indexhash->{'id'}];
4587: my $start = $sdata->[$indexhash->{'start'}];
4588: my $end = $sdata->[$indexhash->{'end'}];
4589: my $groups = $classgroups->{$student};
4590: my $active_groups;
4591: if (ref($groups->{active}) eq 'HASH') {
4592: $active_groups = join(', ',keys(%{$groups->{'active'}}));
4593: }
4594: if (! defined($start) || $start == 0) {
4595: $start = &mt('none');
4596: } else {
4597: $start = &Apache::lonlocal::locallocaltime($start);
4598: }
4599: if (! defined($end) || $end == 0) {
4600: $end = &mt('none');
4601: } else {
4602: $end = &Apache::lonlocal::locallocaltime($end);
4603: }
4604: my $studentkey = $student.':'.$section;
4605: my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$indexhash->{'start'}].'" />';
4606: #
4607: $r->print(&Apache::loncommon::start_data_table_row());
4608: $r->print(<<"END");
4609: <td><input type="checkbox" name="droplist" value="$studentkey" /></td>
4610: <td>$username</td>
4611: <td>$domain</td>
4612: <td>$id</td>
4613: <td>$name</td>
4614: <td>$section</td>
4615: <td>$start $startitem</td>
4616: <td>$end</td>
4617: <td>$active_groups</td>
4618: END
4619: $r->print(&Apache::loncommon::end_data_table_row());
4620: }
4621: $r->print(&Apache::loncommon::end_data_table().'<br />');
4622: %lt=&Apache::lonlocal::texthash(
4623: 'dp' => "Drop Students",
4624: 'dm' => "Drop Members",
4625: 'ca' => "check all",
4626: 'ua' => "uncheck all",
4627: );
4628: my $btn = $lt{'dp'};
4629: if ($crstype eq 'Community') {
4630: $btn = $lt{'dm'};
4631: }
4632: $r->print(<<"END");
4633: <p>
4634: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)" />
4635: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)" />
4636: </p>
4637: <p>
4638: <input type="submit" value="$btn" />
4639: </p>
4640: END
4641: return;
4642: }
4643:
4644: #
4645: # Print out the initial form to get the file containing a list of users
4646: #
4647: sub print_first_users_upload_form {
4648: my ($r,$context) = @_;
4649: my $str;
4650: $str = '<input type="hidden" name="phase" value="two" />';
4651: $str .= '<input type="hidden" name="action" value="upload" />';
4652: $str .= '<input type="hidden" name="state" value="got_file" />';
4653:
4654: $str .= &Apache::grades::checkforfile_js();
4655:
4656: $str .= '<h2>'.&mt('Upload a file containing information about users').'</h2>'."\n";
4657:
4658: # Excel and CSV Help
4659: $str .= '<div class="LC_columnSection">'
4660: .&Apache::loncommon::help_open_topic("Course_Create_Class_List",
4661: &mt("How do I create a users list from a spreadsheet"))
4662: .' '.&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
4663: &mt("How do I create a CSV file from a spreadsheet"))
4664: ."</div>\n";
4665: $str .= &Apache::lonhtmlcommon::start_pick_box()
4666: .&Apache::lonhtmlcommon::row_title(&mt('File'));
4667: if (&Apache::lonlocal::current_language() ne 'en') {
4668: if ($context eq 'course') {
4669: $str .= '<p class="LC_info">'."\n"
4670: .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n"
4671: .'</p>'."\n";
4672: }
4673: }
4674: $str .= &Apache::loncommon::upfile_select_html()
4675: .&Apache::lonhtmlcommon::row_closure()
4676: .&Apache::lonhtmlcommon::row_title(
4677: '<label for="noFirstLine">'
4678: .&mt('Ignore First Line')
4679: .'</label>')
4680: .'<input type="checkbox" name="noFirstLine" id="noFirstLine" />'
4681: .&Apache::lonhtmlcommon::row_closure(1)
4682: .&Apache::lonhtmlcommon::end_pick_box();
4683:
4684: $str .= '<p>'
4685: .'<input type="button" name="fileupload" value="'.&mt('Next').'"'
4686: .' onclick="javascript:checkUpload(this.form);" />'
4687: .'</p>';
4688:
4689: $r->print($str);
4690: return;
4691: }
4692:
4693: # ================================================= Drop/Add from uploaded file
4694: sub upfile_drop_add {
4695: my ($r,$context,$permission,$showcredits) = @_;
4696: my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'});
4697: if ($datatoken ne '') {
4698: &Apache::loncommon::load_tmp_file($r,$datatoken);
4699: }
4700: my @userdata=&Apache::loncommon::upfile_record_sep();
4701: if($env{'form.noFirstLine'}){shift(@userdata);}
4702: my @keyfields = split(/\,/,$env{'form.keyfields'});
4703: my %fields=();
4704: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
4705: if ($env{'form.upfile_associate'} eq 'reverse') {
4706: if ($env{'form.f'.$i} ne 'none') {
4707: $fields{$keyfields[$i]}=$env{'form.f'.$i};
4708: }
4709: } else {
4710: $fields{$env{'form.f'.$i}}=$keyfields[$i];
4711: }
4712: }
4713: #
4714: # Store the field choices away
4715: my @storefields = qw/username names fname mname lname gen id
4716: sec ipwd email role domain inststatus/;
4717: if ($showcredits) {
4718: push (@storefields,'credits');
4719: }
4720: my %fieldstype;
4721: foreach my $field (@storefields) {
4722: $env{'form.'.$field.'_choice'}=$fields{$field};
4723: $fieldstype{$field.'_choice'} = 'scalar';
4724: }
4725: &Apache::loncommon::store_course_settings('enrollment_upload',\%fieldstype);
4726: my ($cid,$crstype,$setting,$crsdom,$crsnum);
4727: if ($context eq 'domain') {
4728: $setting = $env{'form.roleaction'};
4729: }
4730: if ($env{'request.course.id'} ne '') {
4731: $cid = $env{'request.course.id'};
4732: $crstype = &Apache::loncommon::course_type();
4733: $crsdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4734: $crsnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4735: } elsif ($setting eq 'course') {
4736: if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
4737: $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
4738: $crstype = &Apache::loncommon::course_type($cid);
4739: $crsdom = $env{'form.dcdomain'};
4740: $crsnum = $env{'form.dccourse'};
4741: }
4742: }
4743: my ($startdate,$enddate) = &get_dates_from_form();
4744: if ($env{'form.makedatesdefault'}) {
4745: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
4746: }
4747: # Determine domain and desired host (home server)
4748: my $defdom=$env{'request.role.domain'};
4749: my $domain;
4750: if ($env{'form.defaultdomain'} ne '') {
4751: if (($context eq 'course') || ($setting eq 'course')) {
4752: if ($env{'form.defaultdomain'} eq $crsdom) {
4753: $domain = $env{'form.defaultdomain'};
4754: } else {
4755: if (&Apache::lonnet::will_trust('enroll',$crsdom,$env{'form.defaultdomain'})) {
4756: $domain = $env{'form.defaultdomain'};
4757: } else {
4758: $r->print('<span class="LC_error">'.&mt('Error').': '.
4759: &mt('Enrollment of users not permitted for specified default domain: [_1].',
4760: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
4761: return 'untrusted';
4762: }
4763: }
4764: } elsif ($context eq 'author') {
4765: if ($env{'form.defaultdomain'} eq $defdom) {
4766: $domain = $env{'form.defaultdomain'};
4767: } else {
4768: if ((&Apache::lonnet::will_trust('othcoau',$defdom,$env{'form.defaultdomain'})) &&
4769: (&Apache::lonnet::will_trust('coaurem',$env{'form.defaultdomain'},$defdom))) {
4770: $domain = $env{'form.defaultdomain'};
4771: } else {
4772: $r->print('<span class="LC_error">'.&mt('Error').': '.
4773: &mt('Addition of users not permitted for specified default domain: [_1].',
4774: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
4775: return 'untrusted';
4776: }
4777: }
4778: } elsif (($context eq 'domain') && ($setting eq 'domain')) {
4779: if ($env{'form.defaultdomain'} eq $defdom) {
4780: $domain = $env{'form.defaultdomain'};
4781: } else {
4782: if (&Apache::lonnet::will_trust('domroles',$defdom,$env{'form.defaultdomain'})) {
4783: $domain = $env{'form.defaultdomain'};
4784: } else {
4785: $r->print('<span class="LC_error">'.&mt('Error').': '.
4786: &mt('Addition of users not permitted for specified default domain: [_1].',
4787: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
4788: return 'untrusted';
4789: }
4790: }
4791: }
4792: } else {
4793: $domain = $defdom;
4794: }
4795: my $desiredhost = $env{'form.lcserver'};
4796: if (lc($desiredhost) eq 'default') {
4797: $desiredhost = undef;
4798: } else {
4799: my %home_servers = &Apache::lonnet::get_servers($defdom,'library');
4800: if (! exists($home_servers{$desiredhost})) {
4801: $r->print('<p class="LC_error">'.&mt('Error').': '.
4802: &mt('Invalid home server specified').'</p>');
4803: return 'invalidhome';
4804: }
4805: }
4806: # Determine authentication mechanism
4807: my $changeauth;
4808: if ($context eq 'domain') {
4809: $changeauth = $env{'form.changeauth'};
4810: }
4811: my $amode = '';
4812: my $genpwd = '';
4813: my @genpwdfail;
4814: if ($env{'form.login'} eq 'krb') {
4815: $amode='krb';
4816: $amode.=$env{'form.krbver'};
4817: $genpwd=$env{'form.krbarg'};
4818: } elsif ($env{'form.login'} eq 'int') {
4819: $amode='internal';
4820: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
4821: $genpwd=$env{'form.intarg'};
4822: @genpwdfail =
4823: &Apache::loncommon::check_passwd_rules($domain,$genpwd);
4824: }
4825: } elsif ($env{'form.login'} eq 'loc') {
4826: $amode='localauth';
4827: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
4828: $genpwd=$env{'form.locarg'};
4829: }
4830: } elsif ($env{'form.login'} eq 'lti') {
4831: $amode='lti';
4832: }
4833: if ($amode =~ /^krb/) {
4834: if (! defined($genpwd) || $genpwd eq '') {
4835: $r->print('<span class="Error">'.
4836: &mt('Unable to enroll users').' '.
4837: &mt('No Kerberos domain was specified.').'</span></p>');
4838: $amode = ''; # This causes the loop below to be skipped
4839: }
4840: }
4841: my ($defaultsec,$defaultrole,$defaultcredits,$commoncredits);
4842: if ($context eq 'domain') {
4843: if ($setting eq 'domain') {
4844: $defaultrole = $env{'form.defaultrole'};
4845: } elsif ($setting eq 'course') {
4846: $defaultrole = $env{'form.courserole'};
4847: $defaultsec = $env{'form.sections'};
4848: if ($showcredits) {
4849: $commoncredits = $env{'form.credits'};
4850: if ($crstype ne 'Community') {
4851: my %coursehash=&Apache::lonnet::coursedescription($cid);
4852: $defaultcredits = $coursehash{'internal.defaultcredits'};
4853: }
4854: }
4855: }
4856: } elsif ($context eq 'author') {
4857: $defaultrole = $env{'form.defaultrole'};
4858: } elsif ($context eq 'course') {
4859: $defaultrole = $env{'form.defaultrole'};
4860: $defaultsec = $env{'form.sections'};
4861: if ($showcredits) {
4862: $commoncredits = $env{'form.credits'};
4863: $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
4864: }
4865: }
4866: # Check to see if user information can be changed
4867: my @userinfo = ('firstname','middlename','lastname','generation',
4868: 'permanentemail','id');
4869: my %canmodify;
4870: if (&Apache::lonnet::allowed('mau',$domain)) {
4871: push(@userinfo,'inststatus');
4872: foreach my $field (@userinfo) {
4873: $canmodify{$field} = 1;
4874: }
4875: }
4876: my (%userlist,%modifiable_fields,@poss_roles);
4877: my $secidx = &Apache::loncoursedata::CL_SECTION();
4878: my @courseroles = &roles_by_context('course',1,$crstype);
4879: if (!&Apache::lonnet::allowed('mau',$domain)) {
4880: if ($context eq 'course' || $context eq 'author') {
4881: @poss_roles = &curr_role_permissions($context,'','',$crstype);
4882: my @statuses = ('active','future');
4883: my ($indexhash,$keylist) = &make_keylist_array();
4884: my %info;
4885: foreach my $role (@poss_roles) {
4886: %{$modifiable_fields{$role}} = &can_modify_userinfo($context,$domain,
4887: \@userinfo,[$role]);
4888: }
4889: if ($context eq 'course') {
4890: my ($cnum,$cdom) = &get_course_identity();
4891: my $roster = &Apache::loncoursedata::get_classlist();
4892: if (ref($roster) eq 'HASH') {
4893: %userlist = %{$roster};
4894: }
4895: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
4896: \@statuses,\@poss_roles);
4897: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
4898: \%advrolehash,$permission);
4899: } elsif ($context eq 'author') {
4900: my %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
4901: \@statuses,\@poss_roles);
4902: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
4903: \%cstr_roles,$permission);
4904: }
4905: }
4906: }
4907: if ($datatoken eq '') {
4908: $r->print('<p class="LC_error">'.&mt('Error').': '.
4909: &mt('Invalid datatoken').'</p>');
4910: return 'missingdata';
4911: }
4912: if ( $domain eq &LONCAPA::clean_domain($domain)
4913: && ($amode ne '')) {
4914: #######################################
4915: ## Add/Modify Users ##
4916: #######################################
4917: if ($context eq 'course') {
4918: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
4919: } elsif ($context eq 'author') {
4920: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
4921: } else {
4922: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
4923: }
4924: $r->rflush;
4925: my (%got_role_approvals,%got_instdoms,%process_by,%instdoms,
4926: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
4927:
4928: my %counts = (
4929: user => 0,
4930: auth => 0,
4931: role => 0,
4932: );
4933: my $flushc=0;
4934: my %student=();
4935: my (%curr_groups,@sections,@cleansec,$defaultwarn,$groupwarn);
4936: my %userchg;
4937: if ($context eq 'course' || $setting eq 'course') {
4938: if ($context eq 'course') {
4939: # Get information about course groups
4940: %curr_groups = &Apache::longroup::coursegroups();
4941: } elsif ($setting eq 'course') {
4942: if ($cid) {
4943: %curr_groups =
4944: &Apache::longroup::coursegroups($env{'form.dcdomain'},
4945: $env{'form.dccourse'});
4946: }
4947: }
4948: # determine section number
4949: if ($defaultsec =~ /,/) {
4950: push(@sections,split(/,/,$defaultsec));
4951: } else {
4952: push(@sections,$defaultsec);
4953: }
4954: # remove non alphanumeric values from section
4955: foreach my $item (@sections) {
4956: $item =~ s/\W//g;
4957: if ($item eq "none" || $item eq 'all') {
4958: $defaultwarn = &mt('Default section name [_1] could not be used as it is a reserved word.',$item);
4959: } elsif ($item ne '' && exists($curr_groups{$item})) {
4960: $groupwarn = &mt('Default section name "[_1]" is the name of a course group. Section names and group names must be distinct.',$item);
4961: } elsif ($item ne '') {
4962: push(@cleansec,$item);
4963: }
4964: }
4965: if ($defaultwarn) {
4966: $r->print($defaultwarn.'<br />');
4967: }
4968: if ($groupwarn) {
4969: $r->print($groupwarn.'<br />');
4970: }
4971: }
4972: my (%curr_rules,%got_rules,%alerts,%cancreate);
4973: my %customroles = &my_custom_roles($crstype);
4974: my @permitted_roles =
4975: &roles_on_upload($context,$setting,$crstype,%customroles);
4976: my %longtypes = &Apache::lonlocal::texthash(
4977: official => 'Institutional',
4978: unofficial => 'Non-institutional',
4979: );
4980: my $newuserdom = $env{'request.role.domain'};
4981: map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes);
4982: # Get new users list
4983: my (%existinguser,%userinfo,%disallow,%rulematch,%inst_results,%alerts,%checkuname,
4984: %showpasswdrules,$haspasswdmap);
4985: my $counter = -1;
4986: my (%willtrust,%trustchecked);
4987: foreach my $line (@userdata) {
4988: $counter ++;
4989: my @secs;
4990: my %entries=&Apache::loncommon::record_sep($line);
4991: # Determine user name
4992: $entries{$fields{'username'}} =~ s/^\s+|\s+$//g;
4993: unless (($entries{$fields{'username'}} eq '') ||
4994: (!defined($entries{$fields{'username'}}))) {
4995: my ($fname, $mname, $lname,$gen) = ('','','','');
4996: if (defined($fields{'names'})) {
4997: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
4998: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
4999: } else {
5000: if (defined($fields{'fname'})) {
5001: $fname=$entries{$fields{'fname'}};
5002: }
5003: if (defined($fields{'mname'})) {
5004: $mname=$entries{$fields{'mname'}};
5005: }
5006: if (defined($fields{'lname'})) {
5007: $lname=$entries{$fields{'lname'}};
5008: }
5009: if (defined($fields{'gen'})) {
5010: $gen=$entries{$fields{'gen'}};
5011: }
5012: }
5013:
5014: if ($entries{$fields{'username'}}
5015: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
5016: my $nowhitespace;
5017: if ($entries{$fields{'username'}} =~ /\s/) {
5018: $nowhitespace = ' - '.&mt('usernames may not contain spaces.');
5019: }
5020: $disallow{$counter} =
5021: &mt('Unacceptable username [_1] for user [_2] [_3] [_4] [_5]',
5022: '"<b>'.$entries{$fields{'username'}}.'</b>"',
5023: $fname,$mname,$lname,$gen).$nowhitespace;
5024: next;
5025: } else {
5026: $entries{$fields{'domain'}} =~ s/^\s+|\s+$//g;
5027: if ($entries{$fields{'domain'}}
5028: ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
5029: $disallow{$counter} =
5030: &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
5031: '"<b>'.$entries{$fields{'domain'}}.'</b>"',
5032: $fname,$mname,$lname,$gen);
5033: next;
5034: } elsif ($entries{$fields{'domain'}} ne $domain) {
5035: my $possdom = $entries{$fields{'domain'}};
5036: if ($context eq 'course' || $setting eq 'course') {
5037: unless ($trustchecked{$possdom}) {
5038: $willtrust{$possdom} = &Apache::lonnet::will_trust('enroll',$domain,$possdom);
5039: $trustchecked{$possdom} = 1;
5040: }
5041: } elsif ($context eq 'author') {
5042: unless ($trustchecked{$possdom}) {
5043: $willtrust{$possdom} = &Apache::lonnet::will_trust('othcoau',$domain,$possdom);
5044: }
5045: if ($willtrust{$possdom}) {
5046: $willtrust{$possdom} = &Apache::lonnet::will_trust('coaurem',$possdom,$domain);
5047: }
5048: }
5049: unless ($willtrust{$possdom}) {
5050: $disallow{$counter} =
5051: &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
5052: '"<b>'.$possdom.'</b>"',
5053: $fname,$mname,$lname,$gen);
5054: next;
5055: }
5056: }
5057: my $username = $entries{$fields{'username'}};
5058: my $userdomain = $entries{$fields{'domain'}};
5059: if ($userdomain eq '') {
5060: $userdomain = $domain;
5061: }
5062: if (defined($fields{'sec'})) {
5063: if (defined($entries{$fields{'sec'}})) {
5064: $entries{$fields{'sec'}} =~ s/\W//g;
5065: my $item = $entries{$fields{'sec'}};
5066: if ($item eq "none" || $item eq 'all') {
5067: $disallow{$counter} =
5068: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a reserved word.',
5069: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item);
5070: next;
5071: } elsif (exists($curr_groups{$item})) {
5072: $disallow{$counter} =
5073: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a course group.',
5074: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item).' '.
5075: &mt('Section names and group names must be distinct.');
5076: next;
5077: } else {
5078: push(@secs,$item);
5079: }
5080: }
5081: }
5082: if ($env{'request.course.sec'} ne '') {
5083: @secs = ($env{'request.course.sec'});
5084: if (ref($userlist{$username.':'.$userdomain}) eq 'ARRAY') {
5085: my $currsec = $userlist{$username.':'.$userdomain}[$secidx];
5086: if ($currsec ne $env{'request.course.sec'}) {
5087: $disallow{$counter} =
5088: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]".',
5089: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$secs[0]);
5090: if ($currsec eq '') {
5091: $disallow{$counter} .=
5092: &mt('This user already has an active/future student role in the course, unaffiliated to any section.');
5093:
5094: } else {
5095: $disallow{$counter} .=
5096: &mt('This user already has an active/future role in section "[_1]" of the course.',$currsec);
5097: }
5098: $disallow{$counter} .=
5099: '<br />'.
5100: &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.',
5101: $secs[0]);
5102: next;
5103: }
5104: }
5105: } elsif ($context eq 'course' || $setting eq 'course') {
5106: if (@secs == 0) {
5107: @secs = @cleansec;
5108: }
5109: }
5110: # determine id number
5111: my $id='';
5112: if (defined($fields{'id'})) {
5113: if (defined($entries{$fields{'id'}})) {
5114: $id=$entries{$fields{'id'}};
5115: }
5116: $id=~tr/A-Z/a-z/;
5117: }
5118: # determine email address
5119: my $email='';
5120: if (defined($fields{'email'})) {
5121: $entries{$fields{'email'}} =~ s/^\s+|\s+$//g;
5122: if (defined($entries{$fields{'email'}})) {
5123: $email=$entries{$fields{'email'}};
5124: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
5125: }
5126: }
5127: # determine affiliation
5128: my $inststatus='';
5129: if (defined($fields{'inststatus'})) {
5130: if (defined($entries{$fields{'inststatus'}})) {
5131: $inststatus=$entries{$fields{'inststatus'}};
5132: }
5133: }
5134: # determine user password
5135: my $password;
5136: my $passwdfromfile;
5137: if (defined($fields{'ipwd'})) {
5138: if ($entries{$fields{'ipwd'}}) {
5139: $password=$entries{$fields{'ipwd'}};
5140: $passwdfromfile = 1;
5141: if ($env{'form.login'} eq 'int') {
5142: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
5143: if (($uhome eq 'no_host') || ($changeauth)) {
5144: my @brokepwdrules =
5145: &Apache::loncommon::check_passwd_rules($domain,$password);
5146: if (@brokepwdrules) {
5147: $disallow{$counter} = &mt('[_1]: Password included in file for this user did not meet requirements.',
5148: '<b>'.$username.'</b>');
5149: map { $showpasswdrules{$_} = 1; } @brokepwdrules;
5150: next;
5151: }
5152: }
5153: }
5154: }
5155: }
5156: unless ($passwdfromfile) {
5157: if ($env{'form.login'} eq 'int') {
5158: if (@genpwdfail) {
5159: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
5160: if (($uhome eq 'no_host') || ($changeauth)) {
5161: $disallow{$counter} = &mt('[_1]: No specific password in file for this user; default password did not meet requirements',
5162: '<b>'.$username.'</b>');
5163: unless ($haspasswdmap) {
5164: map { $showpasswdrules{$_} = 1; } @genpwdfail;
5165: $haspasswdmap = 1;
5166: }
5167: }
5168: next;
5169: }
5170: }
5171: $password = $genpwd;
5172: }
5173: # determine user role
5174: my $role = '';
5175: if (defined($fields{'role'})) {
5176: if ($entries{$fields{'role'}}) {
5177: $entries{$fields{'role'}} =~ s/(\s+$|^\s+)//g;
5178: if ($entries{$fields{'role'}} ne '') {
5179: if (grep(/^\Q$entries{$fields{'role'}}\E$/,@permitted_roles)) {
5180: $role = $entries{$fields{'role'}};
5181: }
5182: }
5183: if ($role eq '') {
5184: my $rolestr = join(', ',@permitted_roles);
5185: $disallow{$counter} =
5186: &mt('[_1]: You do not have permission to add the requested role [_2] for the user.'
5187: ,'<b>'.$entries{$fields{'username'}}.'</b>'
5188: ,$entries{$fields{'role'}})
5189: .'<br />'
5190: .&mt('Allowable role(s) is/are: [_1].',$rolestr);
5191: next;
5192: }
5193: }
5194: }
5195: if ($role eq '') {
5196: $role = $defaultrole;
5197: }
5198: # Clean up whitespace
5199: foreach (\$id,\$fname,\$mname,\$lname,\$gen,\$inststatus) {
5200: $$_ =~ s/(\s+$|^\s+)//g;
5201: }
5202: my $credits;
5203: if ($showcredits) {
5204: if (($role eq 'st') && ($crstype ne 'Community')) {
5205: $credits = $entries{$fields{'credits'}};
5206: if ($credits ne '') {
5207: $credits =~ s/[^\d\.]//g;
5208: }
5209: if ($credits eq '') {
5210: $credits = $commoncredits;
5211: }
5212: if ($credits eq $defaultcredits) {
5213: undef($credits);
5214: }
5215: }
5216: }
5217: # check against rules
5218: my $checkid = 0;
5219: my $newuser = 0;
5220: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
5221: if ($uhome eq 'no_host') {
5222: if ($userdomain ne $newuserdom) {
5223: if ($context eq 'course') {
5224: $disallow{$counter} =
5225: &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
5226: '<b>'.$username.'</b>',$userdomain);
5227: } elsif ($context eq 'author') {
5228: $disallow{$counter} =
5229: &mt('[_1]: The domain specified ([_2]) is different to that of the author.',
5230: '<b>'.$username.'</b>',$userdomain);
5231: } else {
5232: $disallow{$counter} =
5233: &mt('[_1]: The domain specified ([_2]) is different to that of your current role.',
5234: '<b>'.$username.'</b>',$userdomain);
5235: }
5236: $disallow{$counter} .=
5237: &mt('The user does not already exist, and you may not create a new user in a different domain.');
5238: next;
5239: } else {
5240: unless (($password ne '') || ($env{'form.login'} eq 'loc') || ($env{'form.login'} eq 'lti')) {
5241: $disallow{$counter} =
5242: &mt('[_1]: This is a new user but no default password was provided, and the authentication type requires one.',
5243: '<b>'.$username.'</b>');
5244: next;
5245: }
5246: }
5247: $checkid = 1;
5248: $newuser = 1;
5249: $checkuname{$username.':'.$newuserdom} = { 'newuser' => $newuser, 'id' => $id };
5250: } else {
5251: if ($context eq 'course' || $context eq 'author') {
5252: if ($userdomain eq $domain ) {
5253: if ($role eq '') {
5254: my @checkroles;
5255: foreach my $role (@poss_roles) {
5256: my $endkey;
5257: if ($role ne 'st') {
5258: $endkey = ':'.$role;
5259: }
5260: if (exists($userlist{$username.':'.$userdomain.$endkey})) {
5261: if (!grep(/^\Q$role\E$/,@checkroles)) {
5262: push(@checkroles,$role);
5263: }
5264: }
5265: }
5266: if (@checkroles > 0) {
5267: %canmodify = &can_modify_userinfo($context,$domain,\@userinfo,\@checkroles);
5268: }
5269: } elsif (ref($modifiable_fields{$role}) eq 'HASH') {
5270: %canmodify = %{$modifiable_fields{$role}};
5271: }
5272: }
5273: my @newinfo = (\$fname,\$mname,\$lname,\$gen,\$email,\$id);
5274: for (my $i=0; $i<@newinfo; $i++) {
5275: if (${$newinfo[$i]} ne '') {
5276: if (!$canmodify{$userinfo[$i]}) {
5277: ${$newinfo[$i]} = '';
5278: }
5279: }
5280: }
5281: }
5282: if ($id) {
5283: $existinguser{$userdomain}{$username} = $id;
5284: }
5285: }
5286: $userinfo{$counter} = {
5287: username => $username,
5288: domain => $userdomain,
5289: fname => $fname,
5290: mname => $mname,
5291: lname => $lname,
5292: gen => $gen,
5293: email => $email,
5294: id => $id,
5295: password => $password,
5296: inststatus => $inststatus,
5297: role => $role,
5298: sections => \@secs,
5299: credits => $credits,
5300: newuser => $newuser,
5301: checkid => $checkid,
5302: };
5303: }
5304: }
5305: } # end of foreach (@userdata)
5306: if ($counter > -1) {
5307: my $total = $counter + 1;
5308: my %checkids;
5309: if ((keys(%existinguser)) || (keys(%checkuname))) {
5310: $r->print(&mt('Please be patient -- checking for institutional data ...'));
5311: $r->rflush();
5312: if (keys(%existinguser)) {
5313: foreach my $dom (keys(%existinguser)) {
5314: if (ref($existinguser{$dom}) eq 'HASH') {
5315: my %idhash = &Apache::lonnet::idrget($dom,keys(%{$existinguser{$dom}}));
5316: foreach my $username (keys(%{$existinguser{$dom}})) {
5317: if ($idhash{$username} ne $existinguser{$dom}{$username}) {
5318: $checkids{$username.':'.$dom} = {
5319: 'id' => $existinguser{$dom}{$username},
5320: };
5321: }
5322: }
5323: if (keys(%checkids)) {
5324: &Apache::loncommon::user_rule_check(\%checkids,{ 'id' => 1 },
5325: \%alerts,\%rulematch,
5326: \%inst_results,\%curr_rules,
5327: \%got_rules);
5328: }
5329: }
5330: }
5331: }
5332: if (keys(%checkuname)) {
5333: &Apache::loncommon::user_rule_check(\%checkuname,{ 'username' => 1, 'id' => 1, },
5334: \%alerts,\%rulematch,\%inst_results,
5335: \%curr_rules,\%got_rules);
5336: }
5337: $r->print(' '.&mt('done').'<br /><br />');
5338: $r->rflush();
5339: }
5340: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,$total);
5341: $r->print('<ul>');
5342: for (my $i=0; $i<=$counter; $i++) {
5343: if ($disallow{$i}) {
5344: $r->print('<li>'.$disallow{$i}.'</li>');
5345: } elsif (ref($userinfo{$i}) eq 'HASH') {
5346: my $password = $userinfo{$i}{'password'};
5347: my $newuser = $userinfo{$i}{'newuser'};
5348: my $checkid = $userinfo{$i}{'checkid'};
5349: my $id = $userinfo{$i}{'id'};
5350: my $role = $userinfo{$i}{'role'};
5351: my @secs;
5352: if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
5353: @secs = @{$userinfo{$i}{'sections'}};
5354: }
5355: my $fname = $userinfo{$i}{'fname'};
5356: my $mname = $userinfo{$i}{'mname'};
5357: my $lname = $userinfo{$i}{'lname'};
5358: my $gen = $userinfo{$i}{'gen'};
5359: my $email = $userinfo{$i}{'email'};
5360: my $inststatus = $userinfo{$i}{'inststatus'};
5361: my $credits = $userinfo{$i}{'credits'};
5362: my $username = $userinfo{$i}{'username'};
5363: my $userdomain = $userinfo{$i}{'domain'};
5364: my $user = $username.':'.$userdomain;
5365: if ($newuser) {
5366: if (ref($alerts{'username'}) eq 'HASH') {
5367: if (ref($alerts{'username'}{$userdomain}) eq 'HASH') {
5368: if ($alerts{'username'}{$userdomain}{$username}) {
5369: $r->print('<li>'.
5370: &mt('[_1]: matches the username format at your institution, but is not known to your directory service.','<b>'.$username.'</b>').'<br />'.
5371: &mt('Consequently, the user was not created.').'</li>');
5372: next;
5373: }
5374: }
5375: }
5376: if (ref($inst_results{$user}) eq 'HASH') {
5377: if ($inst_results{$user}{'firstname'} ne '') {
5378: $fname = $inst_results{$user}{'firstname'};
5379: }
5380: if ($inst_results{$user}{'middlename'} ne '') {
5381: $mname = $inst_results{$user}{'middlename'};
5382: }
5383: if ($inst_results{$user}{'lasttname'} ne '') {
5384: $lname = $inst_results{$user}{'lastname'};
5385: }
5386: if ($inst_results{$user}{'permanentemail'} ne '') {
5387: $email = $inst_results{$user}{'permanentemail'};
5388: }
5389: if ($inst_results{$user}{'id'} ne '') {
5390: $id = $inst_results{$user}{'id'};
5391: $checkid = 0;
5392: }
5393: if (ref($inst_results{$user}{'inststatus'}) eq 'ARRAY') {
5394: $inststatus = join(':',@{$inst_results{$user}{'inststatus'}});
5395: }
5396: }
5397: if (($checkid) && ($id ne '')) {
5398: if (ref($alerts{'id'}) eq 'HASH') {
5399: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
5400: if ($alerts{'id'}{$userdomain}{$username}) {
5401: $r->print('<li>'.
5402: &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
5403: '<b>'.$username.'</b>').'<br />'.
5404: &mt('Consequently, the user was not created.').'</li>');
5405: next;
5406: }
5407: }
5408: }
5409: }
5410: my $usertype = 'unofficial';
5411: if (ref($rulematch{$user}) eq 'HASH') {
5412: if ($rulematch{$user}{'username'}) {
5413: $usertype = 'official';
5414: }
5415: }
5416: unless ($cancreate{$usertype}) {
5417: my $showtype = $longtypes{$usertype};
5418: $r->print('<li>'.
5419: &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].','<b>'.$username.'</b>',$showtype).'</li>');
5420: next;
5421: }
5422: } elsif ($id ne '') {
5423: if (exists($checkids{$user})) {
5424: $checkid = 1;
5425: if (ref($alerts{'id'}) eq 'HASH') {
5426: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
5427: if ($alerts{'id'}{$userdomain}{$username}) {
5428: $r->print('<li>'.
5429: &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
5430: '<b>'.$username.'</b>').'<br />'.
5431: &mt('Consequently, the ID was not changed.').'</li>');
5432: $id = '';
5433: }
5434: }
5435: }
5436: }
5437: }
5438: my $multiple = 0;
5439: my ($userresult,$authresult,$roleresult,$idresult);
5440: my (%userres,%authres,%roleres,%idres);
5441: my $singlesec = '';
5442: if ($role eq 'st') {
5443: if (($context eq 'domain') && ($changeauth eq 'Yes') && (!$newuser)) {
5444: if ((&Apache::lonnet::allowed('mau',$userdomain)) &&
5445: (&Apache::lonnet::homeserver($username,$userdomain) ne 'no_host')) {
5446: if ((($amode =~ /^krb4|krb5|internal$/) && $password ne '') ||
5447: ($amode eq 'localauth')) {
5448: $authresult =
5449: &Apache::lonnet::modifyuserauth($userdomain,$username,$amode,$password);
5450: }
5451: }
5452: }
5453: my $sec;
5454: if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
5455: if (@secs > 0) {
5456: $sec = $secs[0];
5457: }
5458: }
5459: if ($userdomain ne $env{'request.role.domain'}) {
5460: my $item = "/$crsdom/$crsnum" ;
5461: if ($sec ne '') {
5462: $item .= "/$sec";
5463: }
5464: $item .= '_st';
5465: next if (&restricted_dom($context,$item,$userdomain,$username,$role,$startdate,
5466: $enddate,$crsdom,$crsnum,$sec,$credits,\%process_by,
5467: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
5468: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
5469: }
5470: &modifystudent($userdomain,$username,$cid,$sec,
5471: $desiredhost,$context);
5472: $roleresult =
5473: &Apache::lonnet::modifystudent
5474: ($userdomain,$username,$id,$amode,$password,
5475: $fname,$mname,$lname,$gen,$sec,$enddate,
5476: $startdate,$env{'form.forceid'},
5477: $desiredhost,$email,'manual','',$cid,
5478: '',$context,$inststatus,$credits);
5479: $userresult = $roleresult;
5480: } else {
5481: my $possrole;
5482: if ($role ne '') {
5483: if ($context eq 'course' || $setting eq 'course') {
5484: if ($customroles{$role}) {
5485: $role = 'cr_'.$env{'user.domain'}.'_'.
5486: $env{'user.name'}.'_'.$role;
5487: }
5488: $possrole = $role;
5489: if ($possrole =~ /^cr_/) {
5490: $possrole =~ s{_}{/}g;
5491: }
5492: if (($role ne 'cc') && ($role ne 'co')) {
5493: if (@secs > 1) {
5494: $multiple = 1;
5495: my $prefix = "/$crsdom/$crsnum";
5496: foreach my $sec (@secs) {
5497: if ($userdomain ne $env{'request.role.domain'}) {
5498: my $item = $prefix;
5499: if ($sec ne '') {
5500: $item .= "/$sec";
5501: }
5502: $item .= '_'.$possrole;
5503: next if (&restricted_dom($context,$item,$userdomain,$username,$possrole,
5504: $startdate,$enddate,$crsdom,$crsnum,$sec,
5505: $credits,\%process_by,\%instdoms,\%got_role_approvals,
5506: \%got_instdoms,\%reject,\%pending,\%notifydc,
5507: \%status,\%unauthorized,\%currqueued));
5508: }
5509: ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
5510: &modifyuserrole($context,$setting,
5511: $changeauth,$cid,$userdomain,$username,
5512: $id,$amode,$password,$fname,
5513: $mname,$lname,$gen,$sec,
5514: $env{'form.forceid'},$desiredhost,
5515: $email,$role,$enddate,
5516: $startdate,$checkid,$inststatus);
5517: }
5518: } elsif (@secs > 0) {
5519: $singlesec = $secs[0];
5520: }
5521: }
5522: } else {
5523: $possrole = $role;
5524: }
5525: }
5526: if (!$multiple) {
5527: if (($userdomain ne $env{'request.role.domain'}) && ($role ne '')) {
5528: my $item = "/$crsdom/$crsnum";
5529: if ($singlesec ne '') {
5530: $item .= "/$singlesec";
5531: }
5532: $item .= '_'.$possrole;
5533: next if (&restricted_dom($context,$item,$userdomain,$username,$possrole,$startdate,$enddate,
5534: $crsdom,$crsnum,$singlesec,$credits,\%process_by,\%instdoms,
5535: \%got_role_approvals,\%got_instdoms,\%reject,\%pending,\%notifydc,
5536: \%status,\%unauthorized,\%currqueued));
5537: }
5538: ($userresult,$authresult,$roleresult,$idresult) =
5539: &modifyuserrole($context,$setting,
5540: $changeauth,$cid,$userdomain,$username,
5541: $id,$amode,$password,$fname,
5542: $mname,$lname,$gen,$singlesec,
5543: $env{'form.forceid'},$desiredhost,
5544: $email,$role,$enddate,$startdate,
5545: $checkid,$inststatus);
5546: }
5547: }
5548: if ($multiple) {
5549: foreach my $sec (sort(keys(%userres))) {
5550: $flushc =
5551: &user_change_result($r,$userres{$sec},$authres{$sec},
5552: $roleres{$sec},$idres{$sec},\%counts,$flushc,
5553: $username,$userdomain,\%userchg);
5554:
5555: }
5556: } else {
5557: $flushc =
5558: &user_change_result($r,$userresult,$authresult,
5559: $roleresult,$idresult,\%counts,$flushc,
5560: $username,$userdomain,\%userchg);
5561: }
5562: }
5563: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last user');
5564: } # end of loop
5565: $r->print('</ul>');
5566: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
5567: }
5568: # Flush the course logs so reverse user roles immediately updated
5569: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
5570: $r->print("</p>\n<p>\n".&mt('Processed [quant,_1,user].',$counts{'user'}).
5571: "</p>\n");
5572: if ($counts{'role'} > 0) {
5573: $r->print("<p>\n".
5574: &mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.
5575: &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.').
5576: "</p>\n");
5577: } else {
5578: $r->print('<p>'.&mt('No roles added').'</p>');
5579: }
5580: if ($counts{'auth'} > 0) {
5581: $r->print("<p>\n".
5582: &mt('Authentication changed for [_1] existing users.',
5583: $counts{'auth'})."</p>\n");
5584: }
5585: $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
5586: $r->print(&passwdrule_alerts($domain,\%showpasswdrules));
5587: if ((keys(%reject)) || (keys(%unauthorized))) {
5588: $r->print(&print_roles_rejected($context,\%reject,\%unauthorized));
5589: }
5590: if ((keys(%pending)) || (keys(%currqueued))) {
5591: $r->print(&print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
5592: }
5593: #####################################
5594: # Display list of students to drop #
5595: #####################################
5596: if ($env{'form.fullup'} eq 'yes') {
5597: $r->print('<h3>'.&mt('Students to Drop')."</h3>\n");
5598: # Get current classlist
5599: my $classlist = &Apache::loncoursedata::get_classlist();
5600: if (! defined($classlist)) {
5601: $r->print('<p class="LC_info">'.
5602: &mt('There are no students with current/future access to the course.').
5603: '</p>'."\n");
5604: } elsif (ref($classlist) eq 'HASH') {
5605: # Remove the students we just added from the list of students.
5606: foreach my $line (@userdata) {
5607: my %entries=&Apache::loncommon::record_sep($line);
5608: unless (($entries{$fields{'username'}} eq '') ||
5609: (!defined($entries{$fields{'username'}}))) {
5610: delete($classlist->{$entries{$fields{'username'}}.
5611: ':'.$domain});
5612: }
5613: }
5614: # Print out list of dropped students.
5615: &show_drop_list($r,$classlist,'nosort',$permission);
5616: }
5617: }
5618: } # end of unless
5619: return 'ok';
5620: }
5621:
5622: sub print_namespacing_alerts {
5623: my ($domain,$alerts,$curr_rules) = @_;
5624: my $output;
5625: if (ref($alerts) eq 'HASH') {
5626: if (keys(%{$alerts}) > 0) {
5627: if (ref($alerts->{'username'}) eq 'HASH') {
5628: foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
5629: my $count;
5630: if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
5631: $count = keys(%{$alerts->{'username'}{$dom}});
5632: }
5633: my $domdesc = &Apache::lonnet::domain($domain,'description');
5634: if (ref($curr_rules->{$dom}) eq 'HASH') {
5635: $output .= &Apache::loncommon::instrule_disallow_msg(
5636: 'username',$domdesc,$count,'upload');
5637: }
5638: $output .= &Apache::loncommon::user_rule_formats($dom,
5639: $domdesc,$curr_rules->{$dom}{'username'},
5640: 'username');
5641: }
5642: }
5643: if (ref($alerts->{'id'}) eq 'HASH') {
5644: foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
5645: my $count;
5646: if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
5647: $count = keys(%{$alerts->{'id'}{$dom}});
5648: }
5649: my $domdesc = &Apache::lonnet::domain($domain,'description');
5650: if (ref($curr_rules->{$dom}) eq 'HASH') {
5651: $output .= &Apache::loncommon::instrule_disallow_msg(
5652: 'id',$domdesc,$count,'upload');
5653: }
5654: $output .= &Apache::loncommon::user_rule_formats($dom,
5655: $domdesc,$curr_rules->{$dom}{'id'},'id');
5656: }
5657: }
5658: }
5659: }
5660: }
5661:
5662: sub passwdrule_alerts {
5663: my ($domain,$passwdrules) = @_;
5664: my $warning;
5665: if (ref($passwdrules) eq 'HASH') {
5666: my %showrules = %{$passwdrules};
5667: if (keys(%showrules)) {
5668: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
5669: $warning = '<b>'.&mt('Password requirement(s) unmet for one or more users:').'</b><ul>';
5670: if ($showrules{'min'}) {
5671: my $min = $passwdconf{'min'};
5672: if ($min eq '') {
5673: $min = $Apache::lonnet::passwdmin;
5674: }
5675: $warning .= '<li>'.&mt('minimum [quant,_1,character]',$min).'</li>';
5676: }
5677: if ($showrules{'max'}) {
5678: $warning .= '<li>'.&mt('maximum [quant,_1,character]',$passwdconf{'max'}).'</li>';
5679: }
5680: if ($showrules{'uc'}) {
5681: $warning .= '<li>'.&mt('contain at least one upper case letter').'</li>';
5682: }
5683: if ($showrules{'lc'}) {
5684: $warning .= '<li>'.&mt('contain at least one lower case letter').'</li>';
5685: }
5686: if ($showrules{'num'}) {
5687: $warning .= '<li>'.&mt('contain at least one number').'</li>';
5688: }
5689: if ($showrules{'spec'}) {
5690: $warning .= '<li>'.&mt('contain at least one non-alphanumeric').'</li>';
5691: }
5692: $warning .= '</ul>';
5693: }
5694: }
5695: return $warning;
5696: }
5697:
5698: sub user_change_result {
5699: my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
5700: $username,$userdomain,$userchg) = @_;
5701: my $okresult = 0;
5702: my @status;
5703: if ($userresult ne 'ok') {
5704: if ($userresult =~ /^error:(.+)$/) {
5705: my $error = $1;
5706: push(@status,
5707: &mt('[_1]: Unable to add/modify: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
5708: }
5709: } else {
5710: $counts->{'user'} ++;
5711: $okresult = 1;
5712: }
5713: if ($authresult ne 'ok') {
5714: if ($authresult =~ /^error:(.+)$/) {
5715: my $error = $1;
5716: push(@status,
5717: &mt('[_1]: Unable to modify authentication: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
5718: }
5719: } else {
5720: $counts->{'auth'} ++;
5721: $okresult = 1;
5722: }
5723: if ($roleresult ne 'ok') {
5724: if ($roleresult =~ /^error:(.+)$/) {
5725: my $error = $1;
5726: push(@status,
5727: &mt('[_1]: Unable to add role: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
5728: }
5729: } else {
5730: $counts->{'role'} ++;
5731: $okresult = 1;
5732: }
5733: if ($okresult) {
5734: $flushc++;
5735: $userchg->{$username.':'.$userdomain}=1;
5736: if ($flushc>15) {
5737: $r->rflush;
5738: $flushc=0;
5739: }
5740: }
5741: if ($idresult) {
5742: push(@status,$idresult);
5743: }
5744: if (@status) {
5745: $r->print('<li>'.join('<br />',@status).'</li>');
5746: }
5747: return $flushc;
5748: }
5749:
5750: # ========================================================= Menu Phase Two Drop
5751: sub print_drop_menu {
5752: my ($r,$context,$permission,$crstype) = @_;
5753: my $heading;
5754: if ($crstype eq 'Community') {
5755: $heading = &mt("Drop Members");
5756: } else {
5757: $heading = &mt("Drop Students");
5758: }
5759: $r->print('<h3>'.$heading.'</h3>'."\n".
5760: '<form name="studentform" method="post" action="">'."\n");
5761: my $classlist = &Apache::loncoursedata::get_classlist();
5762: if (! defined($classlist)) {
5763: my $msg = '';
5764: if ($crstype eq 'Community') {
5765: $msg = &mt('There are no members currently enrolled.');
5766: } else {
5767: $msg = &mt('There are no students currently enrolled.');
5768: }
5769: $r->print('<p class="LC_info">'.$msg."</p>\n");
5770: } else {
5771: &show_drop_list($r,$classlist,'nosort',$permission,$crstype);
5772: }
5773: $r->print('</form>');
5774: return;
5775: }
5776:
5777: # ================================================================== Phase four
5778:
5779: sub update_user_list {
5780: my ($r,$context,$setting,$choice,$crstype) = @_;
5781: my $now = time;
5782: my $count=0;
5783: if ($context eq 'course') {
5784: $crstype = &Apache::loncommon::course_type();
5785: }
5786: my (@changelist,%got_role_approvals,%got_instdoms,%process_by,%instdoms,
5787: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
5788: if ($choice eq 'drop') {
5789: @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
5790: } else {
5791: @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
5792: }
5793: my %result_text = ( ok => { 'revoke' => 'Revoked',
5794: 'delete' => 'Deleted',
5795: 'reenable' => 'Re-enabled',
5796: 'activate' => 'Activated',
5797: 'chgdates' => 'Changed Access Dates for',
5798: 'chgsec' => 'Changed section(s) for',
5799: 'drop' => 'Dropped',
5800: },
5801: error => {'revoke' => 'revoking',
5802: 'delete' => 'deleting',
5803: 'reenable' => 're-enabling',
5804: 'activate' => 'activating',
5805: 'chgdates' => 'changing access dates for',
5806: 'chgsec' => 'changing section for',
5807: 'drop' => 'dropping',
5808: },
5809: );
5810: my ($startdate,$enddate);
5811: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
5812: ($startdate,$enddate) = &get_dates_from_form();
5813: }
5814: foreach my $item (@changelist) {
5815: my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,
5816: @sections,$scopestem,$singlesec,$showsecs,$warn_singlesec,
5817: $nothingtodo,$keepnosection,$credits,$instsec,$cdom,$cnum);
5818: if ($choice eq 'drop') {
5819: ($uname,$udom,$sec) = split(/:/,$item,-1);
5820: $role = 'st';
5821: $cid = $env{'request.course.id'};
5822: $scopestem = '/'.$cid;
5823: $scopestem =~s/\_/\//g;
5824: if ($sec eq '') {
5825: $scope = $scopestem;
5826: } else {
5827: $scope = $scopestem.'/'.$sec;
5828: }
5829: } elsif ($context eq 'course') {
5830: ($uname,$udom,$role,$sec,$type,$locktype,$credits,$instsec) =
5831: split(/\:/,$item,8);
5832: $instsec = &unescape($instsec);
5833: $cid = $env{'request.course.id'};
5834: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5835: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5836: $scopestem = '/'.$cid;
5837: $scopestem =~s/\_/\//g;
5838: if ($sec eq '') {
5839: $scope = $scopestem;
5840: } else {
5841: $scope = $scopestem.'/'.$sec;
5842: }
5843: } elsif ($context eq 'author') {
5844: ($uname,$udom,$role) = split(/\:/,$item,-1);
5845: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
5846: $cdom = $env{'user.domain'};
5847: $cnum = $env{'user.name'};
5848: } elsif ($context eq 'domain') {
5849: if ($setting eq 'domain') {
5850: ($role,$uname,$udom) = split(/\:/,$item,-1);
5851: $scope = '/'.$env{'request.role.domain'}.'/';
5852: $cdom = $env{'request.role.domain'};
5853: } elsif ($setting eq 'author') {
5854: ($uname,$udom,$role,$scope) = split(/\:/,$item);
5855: (undef,$cdom,$cnum) = split(/\//,$scope);
5856: } elsif ($setting eq 'course') {
5857: ($uname,$udom,$role,$cid,$sec,$type,$locktype,$credits,$instsec) =
5858: split(/\:/,$item,9);
5859: ($cdom,$cnum) = split('_',$cid);
5860: $instsec = &unescape($instsec);
5861: $scope = '/'.$cid;
5862: $scope =~s/\_/\//g;
5863: if ($sec ne '') {
5864: $scope .= '/'.$sec;
5865: }
5866: }
5867: }
5868: my $plrole = &Apache::lonnet::plaintext($role,$crstype);
5869: my $start = $env{'form.'.$item.'_start'};
5870: my $end = $env{'form.'.$item.'_end'};
5871: if ($choice eq 'drop') {
5872: # drop students
5873: $end = $now;
5874: $type = 'manual';
5875: $result =
5876: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
5877: } elsif ($choice eq 'revoke') {
5878: # revoke or delete user role
5879: $end = $now;
5880: if ($role eq 'st') {
5881: $result =
5882: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
5883: } else {
5884: $result =
5885: &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
5886: '','',$context);
5887: }
5888: } elsif ($choice eq 'delete') {
5889: if ($role eq 'st') {
5890: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
5891: }
5892: $result =
5893: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
5894: $start,1,'',$context);
5895: } else {
5896: #reenable, activate, change access dates or change section
5897: if ($choice ne 'chgsec') {
5898: $start = $startdate;
5899: $end = $enddate;
5900: }
5901: my $id = $scope.'_'.$role;
5902: if ($choice eq 'reenable') {
5903: next if (&restricted_dom($context,$id,$udom,$uname,$role,$now,$end,$cdom,$cnum,
5904: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
5905: \%got_instdoms,\%reject,\%pending,\%notifydc,
5906: \%status,\%unauthorized,\%currqueued));
5907: if ($role eq 'st') {
5908: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
5909: } else {
5910: $result =
5911: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
5912: $now,'','',$context);
5913: }
5914: } elsif ($choice eq 'activate') {
5915: next if (&restricted_dom($context,$id,$udom,$uname,$role,$now,$end,$cdom,$cnum,
5916: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
5917: \%got_instdoms,\%reject,\%pending,\%notifydc,
5918: \%status,\%unauthorized,\%currqueued));
5919: if ($role eq 'st') {
5920: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
5921: } else {
5922: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
5923: $now,'','',$context);
5924: }
5925: } elsif ($choice eq 'chgdates') {
5926: next if (&restricted_dom($context,$id,$udom,$uname,$role,$start,$end,$cdom,$cnum,
5927: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
5928: \%got_instdoms,\%reject,\%pending,\%notifydc,
5929: \%status,\%unauthorized,\%currqueued));
5930: if ($role eq 'st') {
5931: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
5932: } else {
5933: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
5934: $start,'','',$context);
5935: }
5936: } elsif ($choice eq 'chgsec') {
5937: my (@newsecs,$revresult,$nochg,@retained);
5938: if (($role ne 'cc') && ($role ne 'co')) {
5939: my @secs = sort(split(/,/,$env{'form.newsecs'}));
5940: if (@secs) {
5941: my %curr_groups = &Apache::longroup::coursegroups();
5942: foreach my $sec (@secs) {
5943: next if (($sec =~ /\W/) || ($sec eq 'none') ||
5944: (exists($curr_groups{$sec})));
5945: push(@newsecs,$sec);
5946: }
5947: }
5948: }
5949: # remove existing section if not to be retained.
5950: if (!$env{'form.retainsec'} || ($role eq 'st')) {
5951: if ($sec eq '') {
5952: if (@newsecs == 0) {
5953: $result = 'ok';
5954: $nochg = 1;
5955: $nothingtodo = 1;
5956: } else {
5957: $revresult =
5958: &Apache::lonnet::revokerole($udom,$uname,
5959: $scope,$role,
5960: '','',$context);
5961: }
5962: } else {
5963: if (@newsecs > 0) {
5964: if (grep(/^\Q$sec\E$/,@newsecs)) {
5965: push(@retained,$sec);
5966: } else {
5967: $revresult =
5968: &Apache::lonnet::revokerole($udom,$uname,
5969: $scope,$role,
5970: '','',$context);
5971: }
5972: } else {
5973: $revresult =
5974: &Apache::lonnet::revokerole($udom,$uname,
5975: $scope,$role,
5976: '','',$context);
5977: }
5978: }
5979: } else {
5980: if ($sec eq '') {
5981: $nochg = 1;
5982: $keepnosection = 1;
5983: } else {
5984: push(@retained,$sec);
5985: }
5986: }
5987: # add new sections
5988: my (@diffs,@shownew);
5989: if (@retained) {
5990: @diffs = &Apache::loncommon::compare_arrays(\@retained,\@newsecs);
5991: } else {
5992: @diffs = @newsecs;
5993: }
5994: if (@newsecs == 0) {
5995: if ($nochg) {
5996: $result = 'ok';
5997: $nothingtodo = 1;
5998: } else {
5999: if ($role eq 'st') {
6000: $result =
6001: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
6002: } else {
6003: my $newscope = $scopestem;
6004: $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
6005: }
6006: }
6007: $showsecs = &mt('No section');
6008: } elsif (@diffs == 0) {
6009: $result = 'ok';
6010: $nothingtodo = 1;
6011: } else {
6012: foreach my $newsec (@newsecs) {
6013: if (!grep(/^\Q$newsec\E$/,@retained)) {
6014: if ($role eq 'st') {
6015: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
6016: if (@newsecs > 1) {
6017: my $showsingle;
6018: if ($newsec eq '') {
6019: $showsingle = &mt('No section');
6020: } else {
6021: $showsingle = $newsec;
6022: }
6023: if ($crstype eq 'Community') {
6024: $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>');
6025: } else {
6026: $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>');
6027: }
6028: $showsecs = $showsingle;
6029: last;
6030: } else {
6031: if ($newsec eq '') {
6032: $showsecs = &mt('No section');
6033: } else {
6034: $showsecs = $newsec;
6035: }
6036: }
6037: } else {
6038: my $newscope = $scopestem;
6039: if ($newsec ne '') {
6040: $newscope .= '/'.$newsec;
6041: push(@shownew,$newsec);
6042: }
6043: $result = &Apache::lonnet::assignrole($udom,$uname,
6044: $newscope,$role,$end,$start);
6045:
6046: }
6047: }
6048: }
6049: }
6050: unless ($role eq 'st') {
6051: unless ($showsecs) {
6052: my @tolist = sort(@shownew,@retained);
6053: if ($keepnosection) {
6054: push(@tolist,&mt('No section'));
6055: }
6056: $showsecs = join(', ',@tolist);
6057: }
6058: }
6059: }
6060: }
6061: my $extent = $scope;
6062: if ($choice eq 'drop' || $context eq 'course') {
6063: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
6064: if ($cdesc) {
6065: $extent = $cdesc;
6066: }
6067: }
6068: if ($result eq 'ok' || $result eq 'ok:') {
6069: my $dates;
6070: if (($choice eq 'chgsec') || ($choice eq 'chgdates')) {
6071: $dates = &dates_feedback($start,$end,$now);
6072: }
6073: if ($choice eq 'chgsec') {
6074: if ($nothingtodo) {
6075: $r->print(&mt("Section assignment for role of '[_1]' in [_2] for '[_3]' unchanged.",$plrole,$extent,'<i>'.
6076: &Apache::loncommon::plainname($uname,$udom).
6077: '</i>').' ');
6078: if ($sec eq '') {
6079: $r->print(&mt('[_1]No section[_2] - [_3]','<b>','</b>',$dates));
6080: } else {
6081: $r->print(&mt('Section(s): [_1] - [_2]',
6082: '<b>'.$showsecs.'</b>',$dates));
6083: }
6084: $r->print('<br />');
6085: } else {
6086: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' to [_4] - [_5]",$plrole,$extent,
6087: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
6088: '<b>'.$showsecs.'</b>',$dates).'<br />');
6089: $count ++;
6090: }
6091: if ($warn_singlesec) {
6092: $r->print('<div class="LC_warning">'.$warn_singlesec.'</div>');
6093: }
6094: } elsif ($choice eq 'chgdates') {
6095: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' - [_4]",$plrole,$extent,
6096: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
6097: $dates).'<br />');
6098: $count ++;
6099: } else {
6100: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]'.",$plrole,$extent,
6101: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>').
6102: '<br />');
6103: $count ++;
6104: }
6105: } else {
6106: $r->print(
6107: &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for '[_3]': [_4].",
6108: $plrole,$extent,
6109: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
6110: $result).'<br />');
6111: }
6112: }
6113: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
6114: if ($choice eq 'drop') {
6115: $r->print('<input type="hidden" name="action" value="listusers" />'."\n".
6116: '<input type="hidden" name="Status" value="Active" />'."\n".
6117: '<input type="hidden" name="showrole" value="st" />'."\n");
6118: } else {
6119: foreach my $item ('action','sortby','roletype','showrole','Status','secfilter','grpfilter') {
6120: if ($env{'form.'.$item} ne '') {
6121: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.
6122: '" />'."\n");
6123: }
6124: }
6125: }
6126: $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} [quant,_1,user role,user roles,no user roles].",$count).'</b></p>');
6127: if ($count > 0) {
6128: if ($choice eq 'revoke' || $choice eq 'drop') {
6129: $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>');
6130: }
6131: # Flush the course logs so reverse user roles immediately updated
6132: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
6133: }
6134: if ($env{'form.makedatesdefault'}) {
6135: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
6136: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
6137: }
6138: }
6139: if ((keys(%reject)) || (keys(%unauthorized))) {
6140: $r->print(&print_roles_rejected($context,\%reject,\%unauthorized));
6141: }
6142: if ((keys(%pending)) || (keys(%currqueued))) {
6143: $r->print(&print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
6144: }
6145: my $linktext = &mt('Display User Lists');
6146: if ($choice eq 'drop') {
6147: $linktext = &mt('Display current class roster');
6148: }
6149: $r->print(
6150: &Apache::lonhtmlcommon::actionbox(
6151: ['<a href="javascript:document.studentform.submit()">'.$linktext.'</a>'])
6152: .'</form>'."\n");
6153: }
6154:
6155: sub dates_feedback {
6156: my ($start,$end,$now) = @_;
6157: my $dates;
6158: if ($start < $now) {
6159: if ($end == 0) {
6160: $dates = &mt('role(s) active now; no end date');
6161: } elsif ($end > $now) {
6162: $dates = &mt('role(s) active now; ends [_1].',&Apache::lonlocal::locallocaltime($end));
6163: } else {
6164: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
6165: }
6166: } else {
6167: if ($end == 0 || $end > $now) {
6168: $dates = &mt('future role(s); starts: [_1].',&Apache::lonlocal::locallocaltime($start));
6169: } else {
6170: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
6171: }
6172: }
6173: return $dates;
6174: }
6175:
6176: sub classlist_drop {
6177: my ($scope,$uname,$udom,$now) = @_;
6178: my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
6179: if (&Apache::lonnet::is_course($cdom,$cnum)) {
6180: if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
6181: my %user;
6182: my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
6183: return &mt('Drop from classlist: [_1]',
6184: '<b>'.$result.'</b>').'<br />';
6185: }
6186: }
6187: }
6188:
6189: sub active_student_roles {
6190: my ($cnum,$cdom,$uname,$udom) = @_;
6191: my %roles =
6192: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
6193: ['future','active'],['st']);
6194: return exists($roles{"$cnum:$cdom:st"});
6195: }
6196:
6197: sub section_check_js {
6198: my $groupslist= &get_groupslist();
6199: my %js_lt = &Apache::lonlocal::texthash(
6200: mayn => 'may not be used as the name for a section, as it is a reserved word.',
6201: plch => 'Please choose a different section name.',
6202: mnot => 'may not be used as a section name, as it is the name of a course group.',
6203: secn => 'Section names and group names must be distinct. Please choose a different section name.',
6204: );
6205: &js_escape(\%js_lt);
6206: return <<"END";
6207: function validate(caller) {
6208: var groups = new Array($groupslist);
6209: var secname = caller.value;
6210: if ((secname == 'all') || (secname == 'none')) {
6211: alert("'"+secname+"' $js_lt{'mayn'}\\n$js_lt{'plch'}");
6212: return 'error';
6213: }
6214: if (secname != '') {
6215: for (var k=0; k<groups.length; k++) {
6216: if (secname == groups[k]) {
6217: alert("'"+secname+"' $js_lt{'mnot'}\\n$js_lt{'secn'}");
6218: return 'error';
6219: }
6220: }
6221: }
6222: return 'ok';
6223: }
6224: END
6225: }
6226:
6227: sub set_login {
6228: my ($dom,$authformkrb,$authformint,$authformloc,$authformlti) = @_;
6229: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6230: my $response;
6231: my ($authnum,%can_assign) =
6232: &Apache::loncommon::get_assignable_auth($dom);
6233: if ($authnum) {
6234: $response = &Apache::loncommon::start_data_table();
6235: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
6236: $response .= &Apache::loncommon::start_data_table_row().
6237: '<td>'.$authformkrb.'</td>'.
6238: &Apache::loncommon::end_data_table_row()."\n";
6239: }
6240: if ($can_assign{'int'}) {
6241: $response .= &Apache::loncommon::start_data_table_row().
6242: '<td>'.$authformint.'</td>'.
6243: &Apache::loncommon::end_data_table_row()."\n"
6244: }
6245: if ($can_assign{'loc'}) {
6246: $response .= &Apache::loncommon::start_data_table_row().
6247: '<td>'.$authformloc.'</td>'.
6248: &Apache::loncommon::end_data_table_row()."\n";
6249: }
6250: if ($can_assign{'lti'}) {
6251: $response .= &Apache::loncommon::start_data_table_row().
6252: '<td>'.$authformlti.'</td>'.
6253: &Apache::loncommon::end_data_table_row()."\n";
6254: }
6255: $response .= &Apache::loncommon::end_data_table();
6256: }
6257: return $response;
6258: }
6259:
6260: sub course_sections {
6261: my ($sections_count,$role,$current_sec,$disabled) = @_;
6262: my $output = '';
6263: my @sections = (sort {$a <=> $b} keys(%{$sections_count}));
6264: my $numsec = scalar(@sections);
6265: my $is_selected = ' selected="selected"';
6266: if ($numsec <= 1) {
6267: $output = '<select name="currsec_'.$role.'"'.$disabled.'>'."\n".
6268: ' <option value="">'.&mt('Select').'</option>'."\n";
6269: if ($current_sec eq 'none') {
6270: $output .=
6271: ' <option value=""'.$is_selected.'>'.&mt('No section').'</option>'."\n";
6272: } else {
6273: $output .=
6274: ' <option value="">'.&mt('No section').'</option>'."\n";
6275: }
6276: if ($numsec == 1) {
6277: if ($current_sec eq $sections[0]) {
6278: $output .=
6279: ' <option value="'.$sections[0].'"'.$is_selected.'>'.$sections[0].'</option>'."\n";
6280: } else {
6281: $output .=
6282: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
6283: }
6284: }
6285: } else {
6286: $output = '<select name="currsec_'.$role.'" ';
6287: my $multiple = 4;
6288: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
6289: if ($role eq 'st') {
6290: $output .= $disabled.'>'."\n".
6291: ' <option value="">'.&mt('Select').'</option>'."\n";
6292: if ($current_sec eq 'none') {
6293: $output .=
6294: ' <option value=""'.$is_selected.'>'.&mt('No section')."</option>\n";
6295: } else {
6296: $output .=
6297: ' <option value="">'.&mt('No section')."</option>\n";
6298: }
6299: } else {
6300: $output .= 'multiple="multiple" size="'.$multiple.'"'.$disabled.'>'."\n";
6301: }
6302: foreach my $sec (@sections) {
6303: if ($current_sec eq $sec) {
6304: $output .= '<option value="'.$sec.'"'.$is_selected.'>'.$sec."</option>\n";
6305: } else {
6306: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
6307: }
6308: }
6309: }
6310: $output .= '</select>';
6311: return $output;
6312: }
6313:
6314: sub get_groupslist {
6315: my $groupslist;
6316: my %curr_groups = &Apache::longroup::coursegroups();
6317: if (%curr_groups) {
6318: $groupslist = join('","',sort(keys(%curr_groups)));
6319: $groupslist = '"'.$groupslist.'"';
6320: }
6321: return $groupslist;
6322: }
6323:
6324: sub setsections_javascript {
6325: my ($formname,$groupslist,$mode,$checkauth,$crstype,$showcredits) = @_;
6326: my ($checkincluded,$finish,$rolecode,$setsection_js);
6327: if ($mode eq 'upload') {
6328: $checkincluded = 'formname.name == "'.$formname.'"';
6329: $finish = "return 'ok';";
6330: $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
6331: } elsif ($formname eq 'cu') {
6332: if (($crstype eq 'Course') && ($showcredits)) {
6333: $checkincluded = "((role == 'st') && (formname.elements[i-2].checked == true)) || ((role != 'st') && (formname.elements[i-1].checked == true))";
6334: } else {
6335: $checkincluded = 'formname.elements[i-1].checked == true';
6336: }
6337: if ($checkauth) {
6338: $finish = "var authcheck = auth_check();\n".
6339: " if (authcheck == 'ok') {\n".
6340: " formname.submit();\n".
6341: " }\n";
6342: } else {
6343: $finish = 'formname.submit()';
6344: }
6345: $rolecode = "var match = str.split('_');
6346: var role = match[3];\n";
6347: } elsif (($formname eq 'enrollstudent') || ($formname eq 'selfenroll')) {
6348: $checkincluded = 'formname.name == "'.$formname.'"';
6349: if ($checkauth) {
6350: $finish = "var authcheck = auth_check();\n".
6351: " if (authcheck == 'ok') {\n".
6352: " formname.submit();\n".
6353: " }\n";
6354: } else {
6355: $finish = 'formname.submit()';
6356: }
6357: $rolecode = "var match = str.split('_');
6358: var role = match[1];\n";
6359: } else {
6360: $checkincluded = 'formname.name == "'.$formname.'"';
6361: $finish = "seccheck = 'ok';";
6362: $rolecode = "var match = str.split('_');
6363: var role = match[1];\n";
6364: $setsection_js = "var seccheck = 'alert';";
6365: }
6366: my %alerts = &Apache::lonlocal::texthash(
6367: secd => 'Section designations do not apply to Course Coordinator roles.',
6368: sedn => 'Section designations do not apply to Coordinator roles.',
6369: accr => 'A course coordinator role will be added with access to all sections.',
6370: acor => 'A coordinator role will be added with access to all sections',
6371: inea => 'In each course, each user may only have one student role at a time.',
6372: inco => 'In each community, each user may only have one member role at a time.',
6373: youh => 'You had selected',
6374: secs => 'sections.',
6375: plmo => 'Please modify your selections so they include no more than one section.',
6376: mayn => 'may not be used as the name for a section, as it is a reserved word.',
6377: plch => 'Please choose a different section name.',
6378: mnot => 'may not be used as a section name, as it is the name of a course group.',
6379: secn => 'Section names and group names must be distinct. Please choose a different section name.',
6380: nonw => 'Section names may only contain letters or numbers.',
6381: );
6382: &js_escape(\%alerts);
6383: $setsection_js .= <<"ENDSECCODE";
6384:
6385: function setSections(formname,crstype) {
6386: var re1 = /^currsec_/;
6387: var re2 =/\\W/;
6388: var trimleading = /^\\s+/;
6389: var trimtrailing = /\\s+\$/;
6390: var groups = new Array($groupslist);
6391: for (var i=0;i<formname.elements.length;i++) {
6392: var str = formname.elements[i].name;
6393: if (typeof(str) === "undefined") {
6394: continue;
6395: }
6396: var checkcurr = str.match(re1);
6397: if (checkcurr != null) {
6398: var num = i;
6399: $rolecode
6400: if ($checkincluded) {
6401: if (role == 'cc' || role == 'co') {
6402: if (role == 'cc') {
6403: alert("$alerts{'secd'}\\n$alerts{'accr'}");
6404: } else {
6405: alert("$alerts{'sedn'}\\n$alerts{'acor'}");
6406: }
6407: } else {
6408: var sections = '';
6409: var numsec = 0;
6410: var fromexisting = new Array();
6411: for (var j=0; j<formname.elements[num].length; j++) {
6412: if (formname.elements[num].options[j].selected == true ) {
6413: var addsec = formname.elements[num].options[j].value;
6414: if ((addsec != "") && (addsec != null)) {
6415: fromexisting.push(addsec);
6416: if (numsec == 0) {
6417: sections = addsec;
6418: } else {
6419: sections = sections + "," + addsec;
6420: }
6421: numsec ++;
6422: }
6423: }
6424: }
6425: var newsecs = formname.elements[num+1].value;
6426: var validsecs = new Array();
6427: var validsecstr = '';
6428: var badsecs = new Array();
6429: if (newsecs != null && newsecs != "") {
6430: var numsplit;
6431: if (newsecs.indexOf(',') == -1) {
6432: numsplit = new Array(newsecs);
6433: } else {
6434: numsplit = newsecs.split(/,/g);
6435: }
6436: for (var m=0; m<numsplit.length; m++) {
6437: var newsec = numsplit[m];
6438: newsec = newsec.replace(trimleading,'');
6439: newsec = newsec.replace(trimtrailing,'');
6440: if (re2.test(newsec) == true) {
6441: badsecs.push(newsec);
6442: } else {
6443: if (newsec != '') {
6444: var isnew = 1;
6445: if (fromexisting != null) {
6446: for (var n=0; n<fromexisting.length; n++) {
6447: if (newsec == fromexisting[n]) {
6448: isnew = 0;
6449: }
6450: }
6451: }
6452: if (isnew == 1) {
6453: validsecs.push(newsec);
6454: }
6455: }
6456: }
6457: }
6458: if (badsecs.length > 0) {
6459: alert("$alerts{'nonw'}\\n$alerts{'plch'}");
6460: return;
6461: }
6462: numsec = numsec + validsecs.length;
6463: }
6464: if ((role == 'st') && (numsec > 1)) {
6465: if (crstype == 'Community') {
6466: alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
6467: } else {
6468: alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
6469: }
6470: return;
6471: } else {
6472: if (validsecs != null) {
6473: for (var j=0; j<validsecs.length; j++) {
6474: if (validsecstr == '' || validsecstr == null) {
6475: validsecstr = validsecs[j];
6476: } else {
6477: validsecstr += ','+validsecs[j];
6478: }
6479: if ((validsecs[j] == 'all') ||
6480: (validsecs[j] == 'none')) {
6481: alert("'"+validsecs[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
6482: return;
6483: }
6484: for (var k=0; k<groups.length; k++) {
6485: if (validsecs[j] == groups[k]) {
6486: alert("'"+validsecs[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
6487: return;
6488: }
6489: }
6490: }
6491: }
6492: }
6493: if ((validsecstr != '') && (validsecstr != null)) {
6494: if ((sections == '') || (sections == null)) {
6495: sections = validsecstr;
6496: } else {
6497: sections = sections + "," + validsecstr;
6498: }
6499: }
6500: formname.elements[num+2].value = sections;
6501: }
6502: }
6503: }
6504: }
6505: $finish
6506: }
6507: ENDSECCODE
6508: return $setsection_js;
6509: }
6510:
6511: sub can_create_user {
6512: my ($dom,$context,$usertype) = @_;
6513: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6514: my $cancreate = 1;
6515: if (&Apache::lonnet::allowed('mau',$dom)) {
6516: return $cancreate;
6517: } elsif ($context eq 'domain') {
6518: $cancreate = 0;
6519: return $cancreate;
6520: }
6521: if (ref($domconf{'usercreation'}) eq 'HASH') {
6522: if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
6523: if ($context eq 'course' || $context eq 'author' || $context eq 'requestcrs') {
6524: my $creation = $domconf{'usercreation'}{'cancreate'}{$context};
6525: if ($creation eq 'none') {
6526: $cancreate = 0;
6527: } elsif ($creation ne 'any') {
6528: if (defined($usertype)) {
6529: if ($creation ne $usertype) {
6530: $cancreate = 0;
6531: }
6532: }
6533: }
6534: }
6535: }
6536: }
6537: return $cancreate;
6538: }
6539:
6540: sub can_modify_userinfo {
6541: my ($context,$dom,$fields,$userroles) = @_;
6542: my %domconfig =
6543: &Apache::lonnet::get_dom('configuration',['usermodification'],
6544: $dom);
6545: my %canmodify;
6546: if (ref($fields) eq 'ARRAY') {
6547: foreach my $field (@{$fields}) {
6548: $canmodify{$field} = 0;
6549: if (&Apache::lonnet::allowed('mau',$dom)) {
6550: $canmodify{$field} = 1;
6551: } else {
6552: if (ref($domconfig{'usermodification'}) eq 'HASH') {
6553: if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
6554: if (ref($userroles) eq 'ARRAY') {
6555: foreach my $role (@{$userroles}) {
6556: my $testrole;
6557: if ($context eq 'selfcreate') {
6558: $testrole = $role;
6559: } else {
6560: if ($role =~ /^cr\//) {
6561: $testrole = 'cr';
6562: } else {
6563: $testrole = $role;
6564: }
6565: }
6566: if (ref($domconfig{'usermodification'}{$context}{$testrole}) eq 'HASH') {
6567: if ($domconfig{'usermodification'}{$context}{$testrole}{$field}) {
6568: $canmodify{$field} = 1;
6569: last;
6570: }
6571: }
6572: }
6573: } else {
6574: foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
6575: if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
6576: if ($domconfig{'usermodification'}{$context}{$key}{$field}) {
6577: $canmodify{$field} = 1;
6578: last;
6579: }
6580: }
6581: }
6582: }
6583: }
6584: } elsif ($context eq 'course') {
6585: if (ref($userroles) eq 'ARRAY') {
6586: if (grep(/^st$/,@{$userroles})) {
6587: $canmodify{$field} = 1;
6588: }
6589: } else {
6590: $canmodify{$field} = 1;
6591: }
6592: }
6593: }
6594: }
6595: }
6596: return %canmodify;
6597: }
6598:
6599: sub can_change_internalpass {
6600: my ($uname,$udom,$crstype,$permission) = @_;
6601: my $canchange;
6602: if (&Apache::lonnet::allowed('mau',$udom)) {
6603: $canchange = 1;
6604: } elsif ((ref($permission) eq 'HASH') && ($permission->{'mip'}) &&
6605: ($udom eq $env{'request.role.domain'})) {
6606: unless ($env{'course.'.$env{'request.course.id'}.'.internal.nopasswdchg'}) {
6607: my ($cnum,$cdom) = &get_course_identity();
6608: if ((&Apache::lonnet::is_course_owner($cdom,$cnum)) && ($udom eq $env{'user.domain'})) {
6609: my @userstatuses = ('default');
6610: my %userenv = &Apache::lonnet::userenvironment($udom,$uname,'inststatus');
6611: if ($userenv{'inststatus'} ne '') {
6612: @userstatuses = split(/:/,$userenv{'inststatus'});
6613: }
6614: my $noupdate = 1;
6615: my %passwdconf = &Apache::lonnet::get_passwdconf($cdom);
6616: if (ref($passwdconf{'crsownerchg'}) eq 'HASH') {
6617: if (ref($passwdconf{'crsownerchg'}{'for'}) eq 'ARRAY') {
6618: foreach my $status (@userstatuses) {
6619: if (grep(/^\Q$status\E$/,@{$passwdconf{'crsownerchg'}{'for'}})) {
6620: undef($noupdate);
6621: last;
6622: }
6623: }
6624: }
6625: }
6626: if ($noupdate) {
6627: return;
6628: }
6629: my %owned = &Apache::lonnet::courseiddump($cdom,'.',1,'.',
6630: $env{'user.name'}.':'.$env{'user.domain'},
6631: undef,undef,undef,'.');
6632: my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
6633: ['active','future']);
6634: foreach my $key (keys(%roleshash)) {
6635: my ($name,$domain,$role) = split(/:/,$key);
6636: if ($role eq 'st') {
6637: next if (($name eq $cnum) && ($domain eq $cdom));
6638: if ($owned{$domain.'_'.$name}) {
6639: if (ref($owned{$domain.'_'.$name}) eq 'HASH') {
6640: if ($owned{$domain.'_'.$name}{'nopasswdchg'}) {
6641: $noupdate = 1;
6642: last;
6643: }
6644: }
6645: } else {
6646: $noupdate = 1;
6647: last;
6648: }
6649: } else {
6650: $noupdate = 1;
6651: last;
6652: }
6653: }
6654: unless ($noupdate) {
6655: $canchange = 1;
6656: }
6657: }
6658: }
6659: }
6660: return $canchange;
6661: }
6662:
6663: sub check_usertype {
6664: my ($dom,$uname,$rules,$curr_rules,$got_rules) = @_;
6665: my $usertype;
6666: if ((ref($got_rules) eq 'HASH') && (ref($curr_rules) eq 'HASH')) {
6667: if (!$got_rules->{$dom}) {
6668: my %domconfig = &Apache::lonnet::get_dom('configuration',
6669: ['usercreation'],$dom);
6670: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6671: foreach my $item ('username','id') {
6672: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
6673: $curr_rules->{$dom}{$item} =
6674: $domconfig{'usercreation'}{$item.'_rule'};
6675: }
6676: }
6677: }
6678: $got_rules->{$dom} = 1;
6679: }
6680: if (ref($rules) eq 'HASH') {
6681: my @user_rules;
6682: if (ref($curr_rules->{$dom}{'username'}) eq 'ARRAY') {
6683: foreach my $rule (keys(%{$rules})) {
6684: if (grep(/^\Q$rule\E/,@{$curr_rules->{$dom}{'username'}})) {
6685: push(@user_rules,$rule);
6686: }
6687: }
6688: }
6689: if (@user_rules > 0) {
6690: my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
6691: if (keys(%rule_check) > 0) {
6692: $usertype = 'unofficial';
6693: foreach my $item (keys(%rule_check)) {
6694: if ($rule_check{$item}) {
6695: $usertype = 'official';
6696: last;
6697: }
6698: }
6699: }
6700: }
6701: }
6702: }
6703: return $usertype;
6704: }
6705:
6706: sub roles_by_context {
6707: my ($context,$custom,$crstype) = @_;
6708: my @allroles;
6709: if ($context eq 'course') {
6710: @allroles = ('st');
6711: if ($env{'request.role'} =~ m{^dc\./}) {
6712: push(@allroles,'ad');
6713: }
6714: push(@allroles,('ta','ep','in'));
6715: if ($crstype eq 'Community') {
6716: push(@allroles,'co');
6717: } else {
6718: push(@allroles,'cc');
6719: }
6720: if ($custom) {
6721: push(@allroles,'cr');
6722: }
6723: } elsif ($context eq 'author') {
6724: @allroles = ('ca','aa');
6725: } elsif ($context eq 'domain') {
6726: @allroles = ('li','ad','dg','dh','da','sc','au','dc');
6727: }
6728: return @allroles;
6729: }
6730:
6731: sub get_permission {
6732: my ($context,$crstype) = @_;
6733: my %permission;
6734: if ($context eq 'course') {
6735: my $custom = 1;
6736: my @allroles = &roles_by_context($context,$custom,$crstype);
6737: foreach my $role (@allroles) {
6738: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
6739: $permission{'cusr'} = 1;
6740: last;
6741: }
6742: }
6743: if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
6744: $permission{'custom'} = 1;
6745: }
6746: if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
6747: $permission{'view'} = 1;
6748: }
6749: if (!$permission{'view'}) {
6750: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
6751: $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
6752: if ($permission{'view'}) {
6753: $permission{'view_section'} = $env{'request.course.sec'};
6754: }
6755: }
6756: if (!$permission{'cusr'}) {
6757: if ($env{'request.course.sec'} ne '') {
6758: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
6759: $permission{'cusr'} = (&Apache::lonnet::allowed('cst',$scope));
6760: if ($permission{'cusr'}) {
6761: $permission{'cusr_section'} = $env{'request.course.sec'};
6762: }
6763: }
6764: }
6765: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
6766: $permission{'grp_manage'} = 1;
6767: }
6768: if ($permission{'cusr'}) {
6769: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6770: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6771: my %coursehash = (
6772: 'internal.selfenrollmgrdc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrdc'},
6773: 'internal.selfenrollmgrcc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrcc'},
6774: 'internal.coursecode' => $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},
6775: 'internal.textbook' =>$env{'course.'.$env{'request.course.id'}.'.internal.textbook'},
6776: );
6777: my ($managed_by_cc,$managed_by_dc) = &selfenrollment_administration($cdom,$cnum,$crstype,\%coursehash);
6778: if (ref($managed_by_cc) eq 'ARRAY') {
6779: if (@{$managed_by_cc}) {
6780: $permission{'selfenrolladmin'} = 1;
6781: }
6782: }
6783: unless ($permission{'selfenrolladmin'}) {
6784: $permission{'selfenrollview'} = 1;
6785: }
6786: }
6787: if ($env{'request.course.id'}) {
6788: my $user;
6789: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
6790: $user = $env{'user.name'}.':'.$env{'user.domain'};
6791: }
6792: if (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'} eq
6793: $user)) {
6794: $permission{'owner'} = 1;
6795: if (&Apache::lonnet::allowed('mip',$env{'request.course.id'})) {
6796: $permission{'mip'} = 1;
6797: }
6798: } elsif (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.co-owners'} ne '')) {
6799: if (grep(/^\Q$user\E$/,split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.co-owners'}))) {
6800: $permission{'co-owner'} = 1;
6801: }
6802: }
6803: }
6804: } elsif ($context eq 'author') {
6805: $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
6806: $permission{'view'} = $permission{'cusr'};
6807: } else {
6808: my @allroles = &roles_by_context($context);
6809: foreach my $role (@allroles) {
6810: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
6811: $permission{'cusr'} = 1;
6812: last;
6813: }
6814: }
6815: if (!$permission{'cusr'}) {
6816: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
6817: $permission{'cusr'} = 1;
6818: }
6819: }
6820: if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
6821: $permission{'custom'} = 1;
6822: }
6823: if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
6824: $permission{'activity'} = 1;
6825: }
6826: if (&Apache::lonnet::allowed('vur',$env{'request.role.domain'})) {
6827: $permission{'view'} = 1;
6828: }
6829: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
6830: $permission{'owner'} = 1;
6831: }
6832: }
6833: my $allowed = 0;
6834: foreach my $key (keys(%permission)) {
6835: next if (($key eq 'owner') || ($key eq 'co-owner'));
6836: if ($permission{$key}) { $allowed=1; last; }
6837: }
6838: return (\%permission,$allowed);
6839: }
6840:
6841: # ==================================================== Figure out author access
6842:
6843: sub authorpriv {
6844: my ($auname,$audom)=@_;
6845: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
6846: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; } return 1;
6847: }
6848:
6849: sub roles_on_upload {
6850: my ($context,$setting,$crstype,%customroles) = @_;
6851: my (@possible_roles,@permitted_roles);
6852: @possible_roles = &curr_role_permissions($context,$setting,1,$crstype);
6853: foreach my $role (@possible_roles) {
6854: if ($role eq 'cr') {
6855: push(@permitted_roles,keys(%customroles));
6856: } else {
6857: push(@permitted_roles,$role);
6858: }
6859: }
6860: return @permitted_roles;
6861: }
6862:
6863: sub get_course_identity {
6864: my ($cid) = @_;
6865: my ($cnum,$cdom,$cdesc);
6866: if ($cid eq '') {
6867: $cid = $env{'request.course.id'}
6868: }
6869: if ($cid ne '') {
6870: $cnum = $env{'course.'.$cid.'.num'};
6871: $cdom = $env{'course.'.$cid.'.domain'};
6872: $cdesc = $env{'course.'.$cid.'.description'};
6873: if ($cnum eq '' || $cdom eq '') {
6874: my %coursehash =
6875: &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
6876: $cdom = $coursehash{'domain'};
6877: $cnum = $coursehash{'num'};
6878: $cdesc = $coursehash{'description'};
6879: }
6880: }
6881: return ($cnum,$cdom,$cdesc);
6882: }
6883:
6884: sub dc_setcourse_js {
6885: my ($formname,$mode,$context,$showcredits,$domain) = @_;
6886: my ($dc_setcourse_code,$authen_check);
6887: my $cctext = &Apache::lonnet::plaintext('cc');
6888: my $cotext = &Apache::lonnet::plaintext('co');
6889: my %alerts = §ioncheck_alerts();
6890: my $role = 'role';
6891: if ($mode eq 'upload') {
6892: $role = 'courserole';
6893: } else {
6894: $authen_check = &verify_authen($formname,$context,$domain);
6895: }
6896: $dc_setcourse_code = (<<"SCRIPTTOP");
6897: $authen_check
6898:
6899: function setCourse() {
6900: var course = document.$formname.dccourse.value;
6901: if (course != "") {
6902: if (document.$formname.dcdomain.value != document.$formname.origdom.value) {
6903: alert("$alerts{'curd'}");
6904: return;
6905: }
6906: var userrole = document.$formname.$role.options[document.$formname.$role.selectedIndex].value
6907: var section="";
6908: var numsections = 0;
6909: var newsecs = new Array();
6910: for (var i=0; i<document.$formname.currsec.length; i++) {
6911: if (document.$formname.currsec.options[i].selected == true ) {
6912: if (document.$formname.currsec.options[i].value != "" && document.$formname.currsec.options[i].value != null) {
6913: if (numsections == 0) {
6914: section = document.$formname.currsec.options[i].value
6915: numsections = 1;
6916: }
6917: else {
6918: section = section + "," + document.$formname.currsec.options[i].value
6919: numsections ++;
6920: }
6921: }
6922: }
6923: }
6924: if (document.$formname.newsec.value != "" && document.$formname.newsec.value != null) {
6925: if (numsections == 0) {
6926: section = document.$formname.newsec.value
6927: }
6928: else {
6929: section = section + "," + document.$formname.newsec.value
6930: }
6931: newsecs = document.$formname.newsec.value.split(/,/g);
6932: numsections = numsections + newsecs.length;
6933: }
6934: if ((userrole == 'st') && (numsections > 1)) {
6935: if (document.$formname.crstype.value == 'Community') {
6936: alert("$alerts{'inco'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
6937: } else {
6938: alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
6939: }
6940: return;
6941: }
6942: for (var j=0; j<newsecs.length; j++) {
6943: if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
6944: alert("'"+newsecs[j]+"' $alerts{'mayn'}.\\n$alerts{'plsc'}.");
6945: return;
6946: }
6947: if (document.$formname.groups.value != '') {
6948: var groups = document.$formname.groups.value.split(/,/g);
6949: for (var k=0; k<groups.length; k++) {
6950: if (newsecs[j] == groups[k]) {
6951: if (document.$formname.crstype.value == 'Community') {
6952: alert("'"+newsecs[j]+"' $alerts{'mayc'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
6953: } else {
6954: alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
6955: }
6956: return;
6957: }
6958: }
6959: }
6960: }
6961: if ((userrole == 'cc') && (numsections > 0)) {
6962: alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
6963: section = "";
6964: }
6965: if ((userrole == 'co') && (numsections > 0)) {
6966: alert("$alerts{'secd'} $cotext $alerts{'role'}.\\n$alerts{'accr'}.");
6967: section = "";
6968: }
6969: SCRIPTTOP
6970: if ($mode ne 'upload') {
6971: $dc_setcourse_code .= (<<"SCRIPTMID");
6972: var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
6973: var numcourse = getIndex(document.$formname.dccourse);
6974: if (numcourse == "-1") {
6975: if (document.$formname.type == 'Community') {
6976: alert("$alerts{'thwc'}");
6977: } else {
6978: alert("$alerts{'thwa'}");
6979: }
6980: return;
6981: }
6982: else {
6983: document.$formname.elements[numcourse].name = "act"+coursename;
6984: var numnewsec = getIndex(document.$formname.newsec);
6985: if (numnewsec != "-1") {
6986: document.$formname.elements[numnewsec].name = "sec"+coursename;
6987: document.$formname.elements[numnewsec].value = section;
6988: }
6989: var numstart = getIndex(document.$formname.start);
6990: if (numstart != "-1") {
6991: document.$formname.elements[numstart].name = "start"+coursename;
6992: }
6993: var numend = getIndex(document.$formname.end);
6994: if (numend != "-1") {
6995: document.$formname.elements[numend].name = "end"+coursename
6996: }
6997: SCRIPTMID
6998: if ($showcredits) {
6999: $dc_setcourse_code .= <<ENDCRED;
7000: var numcredits = getIndex(document.$formname.credits);
7001: if (numcredits != "-1") {
7002: document.$formname.elements[numcredits].name = "credits"+coursename;
7003: }
7004: ENDCRED
7005: }
7006: $dc_setcourse_code .= <<ENDSCRIPT;
7007: }
7008: }
7009: var authcheck = auth_check();
7010: if (authcheck == 'ok') {
7011: document.$formname.submit();
7012: }
7013: }
7014: ENDSCRIPT
7015: } else {
7016: $dc_setcourse_code .= "
7017: document.$formname.sections.value = section;
7018: }
7019: return 'ok';
7020: }
7021: ";
7022: }
7023: $dc_setcourse_code .= (<<"ENDSCRIPT");
7024:
7025: function getIndex(caller) {
7026: for (var i=0;i<document.$formname.elements.length;i++) {
7027: if (document.$formname.elements[i] == caller) {
7028: return i;
7029: }
7030: }
7031: return -1;
7032: }
7033: ENDSCRIPT
7034: return $dc_setcourse_code;
7035: }
7036:
7037: sub verify_authen {
7038: my ($formname,$context,$domain) = @_;
7039: my %alerts = &authcheck_alerts();
7040: my $finish = "return 'ok';";
7041: if ($context eq 'author') {
7042: $finish = "document.$formname.submit();";
7043: }
7044: my ($numrules,$intargjs) =
7045: &Apache::loncommon::passwd_validation_js('argpicked',$domain);
7046: my $outcome = <<"ENDSCRIPT";
7047:
7048: function auth_check() {
7049: var logintype;
7050: if (document.$formname.login.length) {
7051: if (document.$formname.login.length > 0) {
7052: var loginpicked = 0;
7053: for (var i=0; i<document.$formname.login.length; i++) {
7054: if (document.$formname.login[i].checked == true) {
7055: loginpicked = 1;
7056: logintype = document.$formname.login[i].value;
7057: }
7058: }
7059: if (loginpicked == 0) {
7060: alert("$alerts{'authen'}");
7061: return;
7062: }
7063: }
7064: } else {
7065: logintype = document.$formname.login.value;
7066: }
7067: if (logintype == 'nochange') {
7068: return 'ok';
7069: }
7070: var argpicked = document.$formname.elements[logintype+'arg'].value;
7071: if ((argpicked == null) || (argpicked == '') || (typeof argpicked == 'undefined')) {
7072: var alertmsg = '';
7073: switch (logintype) {
7074: case 'krb':
7075: alertmsg = '$alerts{'krb'}';
7076: break;
7077: case 'int':
7078: alertmsg = '$alerts{'ipass'}';
7079: break;
7080: case 'fsys':
7081: alertmsg = '$alerts{'ipass'}';
7082: break;
7083: case 'loc':
7084: alertmsg = '';
7085: break;
7086: default:
7087: alertmsg = '';
7088: }
7089: if (alertmsg != '') {
7090: alert(alertmsg);
7091: return;
7092: }
7093: } else if (logintype == 'int') {
7094: var numrules = $numrules;
7095: if (numrules > 0) {
7096: $intargjs
7097: }
7098: }
7099: $finish
7100: }
7101: ENDSCRIPT
7102: }
7103:
7104: sub sectioncheck_alerts {
7105: my %alerts = &Apache::lonlocal::texthash(
7106: curd => 'You must select a course or community in the current domain',
7107: inea => 'In each course, each user may only have one student role at a time',
7108: inco => 'In each community, each user may only have one member role at a time',
7109: youh => 'You had selected',
7110: sect => 'sections',
7111: plsm => 'Please modify your selections so they include no more than one section',
7112: mayn => 'may not be used as the name for a section, as it is a reserved word',
7113: plsc => 'Please choose a different section name',
7114: mayt => 'may not be used as the name for a section, as it is the name of a course group',
7115: mayc => 'may not be used as the name for a section, as it is the name of a community group',
7116: secn => 'Section names and group names must be distinct',
7117: secd => 'Section designations do not apply to ',
7118: role => 'roles',
7119: accr => 'role will be added with access to all sections',
7120: thwa => 'There was a problem with your course selection',
7121: thwc => 'There was a problem with your community selection',
7122: );
7123: &js_escape(\%alerts);
7124: return %alerts;
7125: }
7126:
7127: sub authcheck_alerts {
7128: my %alerts =
7129: &Apache::lonlocal::texthash(
7130: authen => 'You must choose an authentication type.',
7131: krb => 'You need to specify the Kerberos domain.',
7132: ipass => 'You need to specify the initial password.',
7133: );
7134: &js_escape(\%alerts);
7135: return %alerts;
7136: }
7137:
7138: sub is_courseowner {
7139: my ($thiscourse,$courseowner) = @_;
7140: if ($courseowner eq '') {
7141: if ($env{'request.course.id'} eq $thiscourse) {
7142: $courseowner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
7143: }
7144: }
7145: if ($courseowner ne '') {
7146: if ($courseowner eq $env{'user.name'}.':'.$env{'user.domain'}) {
7147: return 1;
7148: }
7149: }
7150: return;
7151: }
7152:
7153: sub get_selfenroll_titles {
7154: my @row = ('types','registered','enroll_dates','access_dates','section',
7155: 'approval','limit');
7156: my %lt = &Apache::lonlocal::texthash (
7157: types => 'Users allowed to self-enroll',
7158: registered => 'Registration status (official courses)' ,
7159: enroll_dates => 'Dates self-enrollment available',
7160: access_dates => 'Access dates for self-enrolling users',
7161: section => "Self-enrolling users' section",
7162: approval => 'Processing of requests',
7163: limit => 'Enrollment limit',
7164: );
7165: return (\@row,\%lt);
7166: }
7167:
7168: sub selfenroll_default_descs {
7169: my %desc = (
7170: types => {
7171: dom => &mt('Course domain'),
7172: all => &mt('Any domain'),
7173: '' => &mt('None'),
7174: },
7175: limit => {
7176: none => &mt('No limit'),
7177: allstudents => &mt('Limit by total students'),
7178: selfenrolled => &mt('Limit by total self-enrolled'),
7179: },
7180: approval => {
7181: '0' => &mt('Processed automatically'),
7182: '1' => &mt('Queued for approval'),
7183: '2' => &mt('Queued, pending validation'),
7184: },
7185: registered => {
7186: 0 => 'No registration required',
7187: 1 => 'Registered students only',
7188: },
7189: );
7190: return %desc;
7191: }
7192:
7193: sub selfenroll_validation_types {
7194: my @items = ('url','fields','button','markup');
7195: my %names = &Apache::lonlocal::texthash (
7196: url => 'Web address of validation server/script',
7197: fields => 'Form fields to send to validator',
7198: button => 'Text for validation button',
7199: markup => 'Validation description (HTML)',
7200: );
7201: my @fields = ('username','domain','uniquecode','course','coursetype','description');
7202: return (\@items,\%names,\@fields);
7203: }
7204:
7205: sub get_extended_type {
7206: my ($cdom,$cnum,$crstype,$current) = @_;
7207: my $type = 'unofficial';
7208: my %settings;
7209: if (ref($current) eq 'HASH') {
7210: %settings = %{$current};
7211: } else {
7212: %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook'],$cdom,$cnum);
7213: }
7214: if ($crstype eq 'Community') {
7215: $type = 'community';
7216: } elsif ($crstype eq 'Placement') {
7217: $type = 'placement';
7218: } elsif ($settings{'internal.coursecode'}) {
7219: $type = 'official';
7220: } elsif ($settings{'internal.textbook'}) {
7221: $type = 'textbook';
7222: }
7223: return $type;
7224: }
7225:
7226: sub selfenrollment_administration {
7227: my ($cdom,$cnum,$crstype,$coursehash) = @_;
7228: my %settings;
7229: if (ref($coursehash) eq 'HASH') {
7230: %settings = %{$coursehash};
7231: } else {
7232: %settings = &Apache::lonnet::get('environment',
7233: ['internal.selfenrollmgrdc','internal.selfenrollmgrcc',
7234: 'internal.coursecode','internal.textbook'],$cdom,$cnum);
7235: }
7236: my ($possconfigs) = &get_selfenroll_titles();
7237: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
7238: my $selfenrolltype = &get_extended_type($cdom,$cnum,$crstype,\%settings);
7239:
7240: my (@in_course,@in_domain);
7241: if ($settings{'internal.selfenrollmgrcc'} ne '') {
7242: @in_course = split(/,/,$settings{'internal.selfenrollmgrcc'});
7243: my @diffs = &Apache::loncommon::compare_arrays($possconfigs,\@in_course);
7244: unless (@diffs) {
7245: return (\@in_course,\@in_domain);
7246: }
7247: }
7248: if ($settings{'internal.selfenrollmgrdc'} ne '') {
7249: @in_domain = split(/,/,$settings{'internal.selfenrollmgrdc'});
7250: my @diffs = &Apache::loncommon::compare_arrays(\@in_domain,$possconfigs);
7251: unless (@diffs) {
7252: return (\@in_course,\@in_domain);
7253: }
7254: }
7255: my @combined = @in_course;
7256: push(@combined,@in_domain);
7257: my @diffs = &Apache::loncommon::compare_arrays(\@combined,$possconfigs);
7258: unless (@diffs) {
7259: return (\@in_course,\@in_domain);
7260: }
7261: if ($domdefaults{$selfenrolltype.'selfenrolladmdc'} eq '') {
7262: push(@in_course,@diffs);
7263: } else {
7264: my @defaultdc = split(/,/,$domdefaults{$selfenrolltype.'selfenrolladmdc'});
7265: foreach my $item (@diffs) {
7266: if (grep(/^\Q$item\E$/,@defaultdc)) {
7267: push(@in_domain,$item);
7268: } else {
7269: push(@in_course,$item);
7270: }
7271: }
7272: }
7273: return (\@in_course,\@in_domain);
7274: }
7275:
7276: sub custom_role_header {
7277: my ($context,$crstype,$templaterolerefs,$prefix) = @_;
7278: my %lt = &Apache::lonlocal::texthash(
7279: sele => 'Select a Template',
7280: );
7281: my ($context_code,$button_code);
7282: if ($context eq 'domain') {
7283: $context_code = &custom_coursetype_switch($crstype,$prefix);
7284: }
7285: if (ref($templaterolerefs) eq 'ARRAY') {
7286: foreach my $role (@{$templaterolerefs}) {
7287: my $display = 'inline';
7288: if (($context eq 'domain') && ($role eq 'co')) {
7289: $display = 'none';
7290: }
7291: $button_code .= &make_button_code($role,$crstype,$display,$prefix).' ';
7292: }
7293: }
7294: return <<"END";
7295: <div class="LC_left_float">
7296: <fieldset>
7297: <legend>$lt{'sele'}</legend>
7298: $button_code
7299: </fieldset></div>
7300: $context_code
7301: <br clear="all" />
7302: END
7303: }
7304:
7305: sub custom_coursetype_switch {
7306: my ($crstype,$prefix) = @_;
7307: my ($checkedcourse,$checkedcommunity);
7308: if ($crstype eq 'Community') {
7309: $checkedcommunity = ' checked="checked"';
7310: } else {
7311: $checkedcourse = ' checked="checked"';
7312: }
7313: my %lt = &Apache::lonlocal::texthash(
7314: cont => 'Context',
7315: cour => 'Course',
7316: comm => 'Community',
7317: );
7318: return <<"END";
7319: <div class="LC_left_float">
7320: <fieldset>
7321: <legend>$lt{'cont'}</legend>
7322: <label>
7323: <input type="radio" name="${prefix}_custrolecrstype" value="Course"$checkedcourse onclick="javascript:customSwitchType('$prefix');" />
7324: $lt{'cour'}
7325: </label>
7326: <label>
7327: <input type="radio" name="${prefix}_custrolecrstype" value="Community"$checkedcommunity onclick="javascript:customSwitchType('$prefix');" />
7328: $lt{'comm'}
7329: </label>
7330: </fieldset>
7331: </div>
7332: END
7333: }
7334:
7335: sub custom_role_table {
7336: my ($crstype,$full,$levels,$levelscurrent,$prefix,$add_class,$id) = @_;
7337: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7338: (ref($levelscurrent) eq 'HASH'));
7339: my %lt=&Apache::lonlocal::texthash (
7340: 'prv' => "Privilege",
7341: 'crl' => "Course Level",
7342: 'dml' => "Domain Level",
7343: 'ssl' => "System Level");
7344: my %cr = (
7345: course => '_c',
7346: domain => '_d',
7347: system => '_s',
7348: );
7349:
7350: my $output=&Apache::loncommon::start_data_table($add_class,$id).
7351: &Apache::loncommon::start_data_table_header_row().
7352: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
7353: '</th><th>'.$lt{'ssl'}.'</th>'.
7354: &Apache::loncommon::end_data_table_header_row();
7355: foreach my $priv (sort(keys(%{$full}))) {
7356: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7357: $output .= &Apache::loncommon::start_data_table_row().
7358: '<td><span id="'.$prefix.$priv.'">'.$privtext.'</span></td>';
7359: foreach my $type ('course','domain','system') {
7360: if (($type eq 'system') && ($priv eq 'bre') && ($crstype eq 'Community')) {
7361: $output .= '<td> </td>';
7362: } else {
7363: $output .= '<td>'.
7364: ($levels->{$type}{$priv}?'<input type="checkbox" id="'.$prefix.$priv.$cr{$type}.'"'.
7365: ' name="'.$prefix.$priv.$cr{$type}.'"'.
7366: ($levelscurrent->{$type}{$priv}?' checked="checked"':'').' />':' ').
7367: '</td>';
7368: }
7369: }
7370: $output .= &Apache::loncommon::end_data_table_row();
7371: }
7372: $output .= &Apache::loncommon::end_data_table();
7373: return $output;
7374: }
7375:
7376: sub custom_role_privs {
7377: my ($privs,$full,$levels,$levelscurrent)= @_;
7378: return unless ((ref($privs) eq 'HASH') && (ref($full) eq 'HASH') &&
7379: (ref($levels) eq 'HASH') && (ref($levelscurrent) eq 'HASH'));
7380: my %cr = (
7381: course => 'cr:c',
7382: domain => 'cr:d',
7383: system => 'cr:s',
7384: );
7385: foreach my $type ('course','domain','system') {
7386: foreach my $item (split(/\:/,$Apache::lonnet::pr{$cr{$type}})) {
7387: my ($priv,$restrict)=split(/\&/,$item);
7388: if (!$restrict) { $restrict='F'; }
7389: $levels->{$type}->{$priv}=$restrict;
7390: if ($privs->{$type}=~/\:$priv/) {
7391: $levelscurrent->{$type}->{$priv}=1;
7392: }
7393: $full->{$priv}=1;
7394: }
7395: }
7396: return;
7397: }
7398:
7399: sub custom_template_roles {
7400: my ($context,$crstype) = @_;
7401: my @template_roles = ("in","ta","ep");
7402: if (($context eq 'domain') || ($context eq 'domprefs')) {
7403: push(@template_roles,"ad");
7404: }
7405: push(@template_roles,"st");
7406: if ($context eq 'domain') {
7407: unshift(@template_roles,('co','cc'));
7408: } else {
7409: if ($crstype eq 'Community') {
7410: unshift(@template_roles,'co');
7411: } else {
7412: unshift(@template_roles,'cc');
7413: }
7414: }
7415: return @template_roles;
7416: }
7417:
7418: sub custom_roledefs_js {
7419: my ($context,$crstype,$formname,$full,$templaterolesref,$jsback) = @_;
7420: my $button_code = "\n";
7421: my $head_script = "\n";
7422: my (%roletitlestr,$rolenamestr);
7423: my %role_titles = (
7424: Course => [],
7425: Community => [],
7426: );
7427: $head_script .= '<script type="text/javascript">'."\n"
7428: .'// <![CDATA['."\n";
7429: if (ref($templaterolesref) eq 'ARRAY') {
7430: if ($context eq 'domain') {
7431: $rolenamestr = join("','",@{$templaterolesref});
7432: }
7433: foreach my $role (@{$templaterolesref}) {
7434: $head_script .= &make_script_template($role,$crstype,$formname);
7435: if ($context eq 'domain') {
7436: foreach my $type ('Course','Community') {
7437: push(@{$role_titles{$type}},&Apache::lonnet::plaintext($role,$type));
7438: }
7439: }
7440: }
7441: }
7442: if ($context eq 'domain') {
7443: foreach my $type ('Course','Community') {
7444: $roletitlestr{$type} = join("','",@{$role_titles{$type}});
7445: }
7446: my %pt = (
7447: Community => {
7448: cst => &mt('Grant/revoke role of Member'),
7449: mdc => &mt('Edit community contents'),
7450: pch => &mt('Post discussion on community resources'),
7451: pfo => &mt('Print for other users and entire community'),
7452: },
7453: Course => {
7454: cst => &mt('Grant/revoke role of Student'),
7455: mdc => &mt('Edit course contents'),
7456: pch => &mt('Post discussion on course resources'),
7457: pfo => &mt('Print for other users and entire course'),
7458: },
7459: );
7460: $head_script .= <<"ENDJS";
7461: function customSwitchType(prefix) {
7462: var privnames = new Array('cst','mdc','pch','pfo');
7463: var privtxtcrs = new Array('$pt{Course}{cst}','$pt{Course}{mdc}','$pt{Course}{pch}','$pt{Course}{pfo}');
7464: var privtxtcom = new Array('$pt{Community}{cst}','$pt{Community}{mdc}','$pt{Community}{pch}','$pt{Community}{pfo}');
7465: var rolenames = new Array('$rolenamestr');
7466: var rolescrs = new Array('$roletitlestr{Course}');
7467: var rolescom = new Array('$roletitlestr{Community}');
7468: var radio = prefix+'_custrolecrstype';
7469: if (document.$formname.elements[radio].length > 1) {
7470: for (var i=0; i<document.$formname.elements[radio].length; i++) {
7471: if (document.$formname.elements[radio][i].checked) {
7472: if ((document.getElementById(prefix+'bre_s')) && (document.getElementById(prefix+'bro_s'))) {
7473: if (document.$formname.elements[radio][i].value == 'Community') {
7474: if (document.getElementById(prefix+'bre_s').checked) {
7475: document.getElementById(prefix+'bro_s').checked = true;
7476: document.getElementById(prefix+'bre_s').checked = false;
7477:
7478: }
7479: document.getElementById(prefix+'bre_s').style.visibility = 'hidden';
7480: } else {
7481: document.getElementById(prefix+'bre_s').style.visibility = 'visible';
7482: if (document.getElementById(prefix+'bro_s').checked) {
7483: document.getElementById(prefix+'bre_s').checked = true;
7484: document.getElementById(prefix+'bro_s').checked = false;
7485: }
7486: }
7487: }
7488: for (var j=0; j<privnames.length; j++) {
7489: if (document.getElementById(prefix+privnames[j])) {
7490: if (document.getElementById(prefix+privnames[j])) {
7491: if (document.$formname.elements[radio][i].value == 'Course') {
7492: document.getElementById(prefix+privnames[j]).innerHTML = privtxtcrs[j];
7493: } else {
7494: document.getElementById(prefix+privnames[j]).innerHTML = privtxtcom[j];
7495: }
7496: }
7497: }
7498: }
7499: for (var j=0; j<rolenames.length; j++) {
7500: if (document.getElementById(prefix+rolenames[j])) {
7501: if (document.getElementById(prefix+rolenames[j])) {
7502: if (document.$formname.elements[radio][i].value == 'Course') {
7503: document.getElementById(prefix+rolenames[j]).value = rolescrs[j];
7504: if (rolenames[j] == 'cc') {
7505: document.getElementById(prefix+rolenames[j]).style.display = 'inline';
7506: }
7507: if (rolenames[j] == 'co') {
7508: document.getElementById(prefix+rolenames[j]).style.display = 'none';
7509: }
7510: } else {
7511: document.getElementById(prefix+rolenames[j]).value = rolescom[j];
7512: if (rolenames[j] == 'cc') {
7513: document.getElementById(prefix+rolenames[j]).style.display = 'none';
7514: }
7515: if (rolenames[j] == 'co') {
7516: document.getElementById(prefix+rolenames[j]).style.display = 'inline';
7517: }
7518: }
7519: }
7520: }
7521: }
7522: }
7523: }
7524: }
7525: return;
7526: }
7527: ENDJS
7528: }
7529: $head_script .= "\n".$jsback."\n"
7530: .'// ]]>'."\n"
7531: .'</script>'."\n";
7532: return $head_script;
7533: }
7534:
7535: # --------------------------------------------------------
7536: sub make_script_template {
7537: my ($role,$crstype,$formname) = @_;
7538: my $return_script = 'function set_'.$role.'(prefix) {'."\n";
7539: my (%full_by_level,%role_priv);
7540: foreach my $level ('c','d','s') {
7541: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
7542: next if (($level eq 's') && ($crstype eq 'Community') && ($item eq 'bre&S'));
7543: my ($priv,$restrict)=split(/\&/,$item);
7544: $full_by_level{$level}{$priv}=1;
7545: }
7546: $role_priv{$level} = {};
7547: my @temp = split(/:/,$Apache::lonnet::pr{$role.':'.$level});
7548: foreach my $priv (@temp) {
7549: my ($priv_item, $dummy) = split(/\&/,$priv);
7550: $role_priv{$level}{$priv_item} = 1;
7551: }
7552: }
7553: my %to_check = (
7554: c => ['c','d','s'],
7555: d => ['d','s'],
7556: s => ['s'],
7557: );
7558: foreach my $level ('c','d','s') {
7559: if (ref($full_by_level{$level}) eq 'HASH') {
7560: foreach my $priv (keys(%{$full_by_level{$level}})) {
7561: my $value = 'false';
7562: if (ref($to_check{$level}) eq 'ARRAY') {
7563: foreach my $lett (@{$to_check{$level}}) {
7564: if (exists($role_priv{$lett}{$priv})) {
7565: $value = 'true';
7566: last;
7567: }
7568: }
7569: $return_script .= "document.$formname.elements[prefix+'".$priv."_".$level."'].checked = $value;\n";
7570: }
7571: }
7572: }
7573: }
7574: $return_script .= '}'."\n";
7575: return ($return_script);
7576: }
7577: # ----------------------------------------------------------
7578: sub make_button_code {
7579: my ($role,$crstype,$display,$prefix) = @_;
7580: my $label = &Apache::lonnet::plaintext($role,$crstype);
7581: my $button_code = '<input type="button" onclick="set_'.$role."('$prefix'".')" '.
7582: 'id="'.$prefix.$role.'" value="'.$label.'" '.
7583: 'style="display:'.$display.'" />';
7584: return ($button_code);
7585: }
7586:
7587: sub custom_role_update {
7588: my ($rolename,$prefix) = @_;
7589: # ------------------------------------------------------- What can be assigned?
7590: my %privs = (
7591: c => '',
7592: d => '',
7593: s => '',
7594: );
7595: foreach my $level (keys(%privs)) {
7596: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
7597: my ($priv,$restrict)=split(/\&/,$item);
7598: if (!$restrict) { $restrict=''; }
7599: if ($env{'form.'.$prefix.$priv.'_'.$level}) {
7600: $privs{$level} .=':'.$item;
7601: }
7602: }
7603: }
7604: return %privs;
7605: }
7606:
7607: sub adhoc_status_types {
7608: my ($cdom,$context,$role,$selectedref,$othertitle,$usertypes,$types,$disabled) = @_;
7609: my $output = &Apache::loncommon::start_data_table();
7610: my $numinrow = 3;
7611: my $rem;
7612: if (ref($types) eq 'ARRAY') {
7613: for (my $i=0; $i<@{$types}; $i++) {
7614: if (defined($usertypes->{$types->[$i]})) {
7615: my $rem = $i%($numinrow);
7616: if ($rem == 0) {
7617: if ($i > 0) {
7618: $output .= &Apache::loncommon::end_data_table_row();
7619: }
7620: $output .= &Apache::loncommon::start_data_table_row();
7621: }
7622: my $check;
7623: if (ref($selectedref) eq 'ARRAY') {
7624: if (grep(/^\Q$types->[$i]\E$/,@{$selectedref})) {
7625: $check = ' checked="checked"';
7626: }
7627: }
7628: $output .= '<td>'.
7629: '<span class="LC_nobreak"><label>'.
7630: '<input type="checkbox" name="'.$context.$role.'_status" '.
7631: 'value="'.$types->[$i].'"'.$check.$disabled.' />'.
7632: $usertypes->{$types->[$i]}.'</label></span></td>';
7633: }
7634: }
7635: $rem = @{$types}%($numinrow);
7636: }
7637: my $colsleft = $numinrow - $rem;
7638: if (($rem == 0) && (@{$types} > 0)) {
7639: $output .= &Apache::loncommon::start_data_table_row();
7640: }
7641: if ($colsleft > 1) {
7642: $output .= '<td colspan="'.$colsleft.'">';
7643: } else {
7644: $output .= '<td>';
7645: }
7646: my $defcheck;
7647: if (ref($selectedref) eq 'ARRAY') {
7648: if (grep(/^default$/,@{$selectedref})) {
7649: $defcheck = ' checked="checked"';
7650: }
7651: }
7652: $output .= '<span class="LC_nobreak"><label>'.
7653: '<input type="checkbox" name="'.$context.$role.'_status"'.
7654: 'value="default"'.$defcheck.$disabled.' />'.
7655: $othertitle.'</label></span></td>'.
7656: &Apache::loncommon::end_data_table_row().
7657: &Apache::loncommon::end_data_table();
7658: return $output;
7659: }
7660:
7661: sub adhoc_staff {
7662: my ($access,$context,$role,$selectedref,$adhocref,$disabled) = @_;
7663: my $output;
7664: if (ref($adhocref) eq 'HASH') {
7665: my %by_fullname;
7666: my $numinrow = 4;
7667: my $rem;
7668: my @personnel = keys(%{$adhocref});
7669: if (@personnel) {
7670: foreach my $person (@personnel) {
7671: my ($uname,$udom) = split(/:/,$person);
7672: my $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
7673: $by_fullname{$fullname} = $person;
7674: }
7675: my @sorted = sort(keys(%by_fullname));
7676: my $count = scalar(@sorted);
7677: $output = &Apache::loncommon::start_data_table();
7678: for (my $i=0; $i<$count; $i++) {
7679: my $rem = $i%($numinrow);
7680: if ($rem == 0) {
7681: if ($i > 0) {
7682: $output .= &Apache::loncommon::end_data_table_row();
7683: }
7684: $output .= &Apache::loncommon::start_data_table_row();
7685: }
7686: my $check;
7687: my $user = $by_fullname{$sorted[$i]};
7688: if (ref($selectedref) eq 'ARRAY') {
7689: if (grep(/^\Q$user\E$/,@{$selectedref})) {
7690: $check = ' checked="checked"';
7691: }
7692: }
7693: if ($i == $count-1) {
7694: my $colsleft = $numinrow - $rem;
7695: if ($colsleft > 1) {
7696: $output .= '<td colspan="'.$colsleft.'">';
7697: } else {
7698: $output .= '<td>';
7699: }
7700: } else {
7701: $output .= '<td>';
7702: }
7703: $output .= '<span class="LC_nobreak"><label>'.
7704: '<input type="checkbox" name="'.$context.$role.'_staff_'.$access.'" '.
7705: 'value="'.$user.'"'.$check.$disabled.' />'.$sorted[$i].
7706: '</label></span></td>';
7707: if ($i == $count-1) {
7708: $output .= &Apache::loncommon::end_data_table_row();
7709: }
7710: }
7711: $output .= &Apache::loncommon::end_data_table();
7712: }
7713: }
7714: return $output;
7715: }
7716:
7717:
7718: 1;
7719:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>