Annotation of loncom/interface/lonuserutils.pm, revision 1.219
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
1.219 ! raeburn 4: # $Id: lonuserutils.pm,v 1.218 2023/11/03 01:12:15 raeburn Exp $
1.1 raeburn 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:
1.175 raeburn 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:
1.1 raeburn 49: use strict;
50: use Apache::lonnet;
51: use Apache::loncommon();
52: use Apache::lonhtmlcommon;
1.212 raeburn 53: use Apache::loncoursequeueadmin;
1.1 raeburn 54: use Apache::lonlocal;
1.8 raeburn 55: use Apache::longroup;
1.174 raeburn 56: use HTML::Entities;
1.8 raeburn 57: use LONCAPA qw(:DEFAULT :match);
1.1 raeburn 58:
59: ###############################################################
60: ###############################################################
61: # Drop student from all sections of a course, except optional $csec
62: sub modifystudent {
1.52 raeburn 63: my ($udom,$unam,$courseid,$csec,$desiredhost,$context)=@_;
1.1 raeburn 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
1.17 raeburn 67: my ($cnum,$cdom) = &get_course_identity($courseid);
1.138 raeburn 68: my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
1.1 raeburn 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,
1.22 raeburn 89: $section,time,undef,undef,$desiredhost,'','manual',
1.52 raeburn 90: '',$courseid,'',$context);
1.1 raeburn 91: $result .= $reply.':';
92: }
93: }
94: }
95: }
96: if ($result eq '') {
1.37 raeburn 97: $result = &mt('Unable to find section for this student');
1.1 raeburn 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,
1.84 raeburn 107: $end,$start,$checkid,$inststatus) = @_;
1.5 raeburn 108: my ($scope,$userresult,$authresult,$roleresult,$idresult);
1.1 raeburn 109: if ($setting eq 'course' || $context eq 'course') {
110: $scope = '/'.$cid;
111: $scope =~ s/\_/\//g;
1.103 raeburn 112: if (($role ne 'cc') && ($role ne 'co') && ($sec ne '')) {
1.1 raeburn 113: $scope .='/'.$sec;
114: }
1.5 raeburn 115: } elsif ($context eq 'domain') {
1.1 raeburn 116: $scope = '/'.$env{'request.role.domain'}.'/';
1.13 raeburn 117: } elsif ($context eq 'author') {
1.218 raeburn 118: if ($env{'request.role'} =~ m{^ca\.(/$match_domain/$match_username)$}) {
119: $scope = $1;
120: } else {
121: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
122: }
1.1 raeburn 123: }
124: if ($context eq 'domain') {
125: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
126: if ($uhome ne 'no_host') {
1.5 raeburn 127: if (($changeauth eq 'Yes') && (&Apache::lonnet::allowed('mau',$udom))) {
1.1 raeburn 128: if ((($umode =~ /^krb4|krb5|internal$/) && $upass ne '') ||
129: ($umode eq 'localauth')) {
130: $authresult = &Apache::lonnet::modifyuserauth($udom,$uname,$umode,$upass);
131: }
132: }
1.5 raeburn 133: if (($forceid) && (&Apache::lonnet::allowed('mau',$udom)) &&
134: ($env{'form.recurseid'}) && ($checkid)) {
135: my %userupdate = (
136: lastname => $last,
137: middlename => $middle,
138: firstname => $first,
139: generation => $gene,
140: id => $uid,
141: );
142: $idresult = &propagate_id_change($uname,$udom,\%userupdate);
143: }
1.1 raeburn 144: }
145: }
146: $userresult =
147: &Apache::lonnet::modifyuser($udom,$uname,$uid,$umode,$upass,$first,
148: $middle,$last,$gene,$forceid,$desiredhome,
1.84 raeburn 149: $email,$inststatus);
1.1 raeburn 150: if ($userresult eq 'ok') {
1.5 raeburn 151: if ($role ne '') {
1.22 raeburn 152: $role =~ s/_/\//g;
1.1 raeburn 153: $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
1.52 raeburn 154: $role,$end,$start,'',
155: '',$context);
1.1 raeburn 156: }
157: }
1.5 raeburn 158: return ($userresult,$authresult,$roleresult,$idresult);
1.1 raeburn 159: }
160:
1.212 raeburn 161: sub role_approval {
162: my ($dom,$context,$process_by,$notifydc) = @_;
163: if (ref($process_by) eq 'HASH') {
164: my %domconfig = &Apache::lonnet::get_dom('configuration',['privacy'],$dom);
165: if (ref($domconfig{'privacy'}) eq 'HASH') {
166: if (ref($notifydc) eq 'ARRAY') {
167: if ($domconfig{'privacy'}{'notify'} ne '') {
168: @{$notifydc} = split(/,/,$domconfig{'privacy'}{'notify'});
169: }
170: }
171: if (ref($domconfig{'privacy'}{'approval'}) eq 'HASH') {
172: my %approvalconf = %{$domconfig{'privacy'}{'approval'}};
173: foreach my $key ('instdom','extdom') {
174: if (ref($approvalconf{$key}) eq 'HASH') {
175: if (keys(%{$approvalconf{$key}})) {
176: $process_by->{$key} = $approvalconf{$key}{$context};
177: }
178: }
179: }
180: }
181: }
182: }
183: return;
184: }
185:
186: sub get_instdoms {
187: my ($udom,$instdoms) = @_;
188: return unless (ref($instdoms) eq 'ARRAY');
189: my @intdoms;
190: my %iphost = &Apache::lonnet::get_iphost();
191: my $primary_id = &Apache::lonnet::domain($udom,'primary');
192: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
193: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
194: foreach my $id (@{$iphost{$primary_ip}}) {
195: my $intdom = &Apache::lonnet::internet_dom($id);
196: unless(grep(/^\Q$intdom\E$/,@intdoms)) {
197: push(@intdoms,$intdom);
198: }
199: }
200: }
201: foreach my $ip (keys(%iphost)) {
202: if (ref($iphost{$ip}) eq 'ARRAY') {
203: foreach my $id (@{$iphost{$ip}}) {
204: my $location = &Apache::lonnet::internet_dom($id);
205: if ($location) {
206: if (grep(/^\Q$location\E$/,@intdoms)) {
207: my $dom = &Apache::lonnet::host_domain($id);
208: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
209: push(@{$instdoms},$dom);
210: }
211: }
212: }
213: }
214: }
215: }
216: return;
217: }
218:
219: sub restricted_dom {
220: my ($context,$key,$udom,$uname,$role,$start,$end,$cdom,$cnum,$csec,$credits,
221: $process_by,$instdoms,$got_role_approvals,$got_instdoms,$reject,$pending,
1.213 raeburn 222: $notifydc,$status,$unauthorized,$currqueued) = @_;
1.212 raeburn 223: return if ($udom eq $cdom);
224: return unless ((ref($process_by) eq 'HASH') && (ref($instdoms) eq 'HASH') &&
225: (ref($got_role_approvals) eq 'HASH') && (ref($got_instdoms) eq 'HASH') &&
226: (ref($reject) eq 'HASH') && (ref($pending) eq 'HASH') &&
1.213 raeburn 227: (ref($notifydc) eq 'HASH') && (ref($status) eq 'HASH') &&
228: (ref($unauthorized) eq 'HASH') && (ref($currqueued) eq 'HASH'));
1.212 raeburn 229: my (%approval,@notify,$gotdata,$skip);
230: if (ref($got_role_approvals->{$context}) eq 'HASH') {
231: if ($got_role_approvals->{$context}{$udom}) {
232: $gotdata = 1;
233: if (ref($process_by->{$context}{$udom}) eq 'HASH') {
234: %approval = %{$process_by->{$context}{$udom}};
235: }
236: }
237: }
238: unless ($gotdata) {
239: &role_approval($udom,$context,\%approval,\@notify);
240: $process_by->{$context} = {
241: $udom => \%approval,
242: };
243: $got_role_approvals->{$context} = {
244: $udom => 1,
245: };
246: $notifydc->{$udom} = \@notify;
247: }
248: if (ref($process_by->{$context}) eq 'HASH') {
249: if (ref($process_by->{$context}{$udom}) eq 'HASH') {
250: my @inst;
251: if ($got_instdoms->{$udom}) {
252: if (ref($instdoms->{$udom}) eq 'ARRAY') {
253: @inst = @{$instdoms->{$udom}};
254: }
255: } else {
256: &get_instdoms(\@inst);
257: $instdoms->{$udom} = \@inst;
258: $got_instdoms->{$udom} = 1;
259: }
260: if (grep(/^\Q$cdom\E$/,@inst)) {
261: if (exists($approval{'instdom'})) {
262: my $rule = $approval{'instdom'};
1.213 raeburn 263: if (($rule eq 'none') || ($rule eq 'user') || ($rule eq 'domain')) {
264: my ($id,$currstatus,$curradj) = &get_othdomreq_status($key,$uname,$udom,$role,$cdom,$cnum,$csec);
265: if (($currstatus ne '') && ($curradj eq $rule)) {
266: $status->{$key}->{$uname.':'.$udom} = $currstatus;
267: }
268: if ($rule eq 'none') {
269: $reject->{$key}->{$uname.':'.$udom} = {
270: cdom => $cdom,
271: cnum => $cnum,
272: csec => $csec,
273: udom => $udom,
274: uname => $uname,
275: role => $role,
276: };
277: $skip = 1;
278: } elsif (($rule eq 'user') || ($rule eq 'domain')) {
279: if ($curradj eq $rule) {
280: unless ($currstatus eq 'approved') {
281: if ($currstatus eq 'rejected') {
282: $unauthorized->{$key}->{$uname.':'.$udom} = {
283: cdom => $cdom,
284: cnum => $cnum,
285: csec => $csec,
286: udom => $udom,
287: uname => $uname,
288: role => $role,
289: };
290: } elsif ($currstatus eq 'pending') {
291: $currqueued->{$key}->{$uname.':'.$udom} = {
292: cdom => $cdom,
293: cnum => $cnum,
294: csec => $csec,
295: udom => $udom,
296: uname => $uname,
297: role => $role,
298: adj => $rule,
299: };
300: }
301: $skip = 1;
302: }
303: } else {
304: $pending->{$key}->{$uname.':'.$udom} = {
305: cdom => $cdom,
306: cnum => $cnum,
307: csec => $csec,
308: udom => $udom,
309: uname => $uname,
310: role => $role,
311: start => $start,
312: end => $end,
313: adj => $rule,
314: };
315: if (($role eq 'st') && ($credits ne '')) {
316: $pending->{$key}->{$uname.':'.$udom}->{'credits'} = $credits;
317: }
318: $skip = 1;
319: }
1.212 raeburn 320: }
321: }
322: }
323: } elsif (exists($approval{'extdom'})) {
324: my $rule = $approval{'extdom'};
1.213 raeburn 325: if (($rule eq 'none') || ($rule eq 'user') || ($rule eq 'domain')) {
326: my ($id,$currstatus,$curradj) = &get_othdomreq_status($key,$uname,$udom,$role,$cdom,$cnum,$csec);
327: if (($currstatus ne '') && ($curradj eq $rule)) {
328: $status->{$key}->{$uname.':'.$udom} = $currstatus;
329: }
330: if ($rule eq 'none') {
331: $reject->{$key}->{$uname.':'.$udom} = {
332: cdom => $cdom,
333: cnum => $cnum,
334: csec => $csec,
335: udom => $udom,
336: uname => $uname,
337: role => $role,
338: };
339: $skip = 1;
340: } elsif (($rule eq 'user') || ($rule eq 'domain')) {
341: if ($curradj eq $rule) {
342: unless ($currstatus eq 'approved') {
343: if ($currstatus eq 'rejected') {
344: $unauthorized->{$key}->{$uname.':'.$udom} = {
345: cdom => $cdom,
346: cnum => $cnum,
347: csec => $csec,
348: udom => $udom,
349: uname => $uname,
350: role => $role,
351: };
352: } elsif ($currstatus eq 'pending') {
353: $currqueued->{$key}->{$uname.':'.$udom} = {
354: cdom => $cdom,
355: cnum => $cnum,
356: csec => $csec,
357: udom => $udom,
358: uname => $uname,
359: role => $role,
360: adj => $rule,
361: };
362: }
363: $skip = 1;
364: }
365: } else {
366: $pending->{$key}->{$uname.':'.$udom} = {
367: cdom => $cdom,
368: cnum => $cnum,
369: csec => $csec,
370: udom => $udom,
371: uname => $uname,
372: role => $role,
373: start => $start,
374: end => $end,
375: adj => $rule,
376: };
377: if (($role eq 'st') && ($credits ne '')) {
378: $pending->{$key}->{$uname.':'.$udom}->{'credits'} = $credits;
379: }
380: $skip = 1;
381: }
1.212 raeburn 382: }
383: }
384: }
385: }
386: }
387: return $skip;
388: }
389:
1.213 raeburn 390: sub get_othdomreq_status {
391: my ($key,$uname,$udom,$role,$cdom,$cnum,$csec) = @_;
392: my $id = $uname.':'.$udom.':'.$role;
393: my ($dbnum,$currstatus,$curradj);
394: if (($role eq 'ca') || ($role eq 'aa')) {
395: $dbnum = $cnum;
396: } elsif ($key eq $cdom.'_'.$role) {
397: $dbnum = &Apache::lonnet::get_domainconfiguser($cdom);
398: } else {
399: $id .= ':'.$csec;
400: $dbnum = $cnum;
401: }
402: my $statusid = 'status&'.$id;
403: my %curr = &Apache::lonnet::get('nohist_othdomqueued',[$id,$statusid],$cdom,$dbnum);
404: if (ref($curr{$id}) eq 'HASH') {
405: $curradj = $curr{$id}{'adj'};
406: }
407: $currstatus = $curr{$statusid};
408: return ($id,$currstatus,$curradj);
409: }
410:
1.212 raeburn 411: sub print_roles_rejected {
1.213 raeburn 412: my ($context,$reject,$unauthorized) = @_;
413: return unless ((ref($reject) eq 'HASH') || (ref($unauthorized) eq 'HASH'));
1.212 raeburn 414: my $output;
415: if (keys(%{$reject}) > 0) {
416: $output = '<p class="LC_warning">'.
417: &mt("The following roles could not be assigned because the user is from another domain, and that domain's policies disallow it").'<ul>';
418: foreach my $key (sort(keys(%{$reject}))) {
419: if (ref($reject->{$key}) eq 'HASH') {
1.213 raeburn 420: foreach my $user (sort(keys(%{$reject->{$key}}))) {
421: if (ref($reject->{$key}->{$user}) eq 'HASH') {
422: my ($crstype,$role,$cdom,$cnum,$csec,$title,$plainrole);
423: $role = $reject->{$key}->{$user}{'role'};
424: $cdom = $reject->{$key}->{$user}{'cdom'};
425: $cnum = $reject->{$key}->{$user}{'cnum'};
426: $csec = $reject->{$key}->{$user}{'csec'};
427: if (($context eq 'domain') && ($cnum ne '')) {
428: if (($role eq 'ca') || ($role eq 'aa')) {
429: $title = &Apache::loncommon::plainname($cnum,$cdom);
430: } else {
431: if (&Apache::lonnet::is_course($cdom,$cnum)) {
432: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
433: $crstype = $coursedata{'type'};
434: $title = $coursedata{'description'};
435: }
436: }
437: } elsif ($context eq 'course') {
438: $crstype = &Apache::loncommon::course_type();
439: }
440: my $plainrole = &Apache::lonnet::plaintext($role,$crstype);
441: $output .= '<li>'.&mt('User: [_1]',$reject->{$key}->{$user}{'uname'}).' | '.
442: &mt('Domain: [_1]',$reject->{$key}->{$user}{'udom'}).' | '.
443: &mt('Role: [_1]',$plainrole);
444: if ($crstype) {
445: if ($csec ne'') {
446: $output .= ' | '.&mt('Section: [_1]',$csec);
447: }
448: } elsif (($context eq 'domain') && (($role eq 'ca') || ($role eq 'aa'))) {
449: $output .= ' | '.&mt('Authoring Space belonging to: [_1]',$title);
450:
451: }
452: if (($context eq 'domain') && ($crstype)) {
453: $output .= ' | '.&mt("$crstype: [_1]",$title);
454: }
455: $output .= '</li>';
1.212 raeburn 456: }
457: }
1.213 raeburn 458: }
459: }
460: $output .= '</ul></p>';
461: }
462: if (keys(%{$unauthorized}) > 0) {
463: $output = '<p class="LC_warning">'.
464: &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>';
465: foreach my $key (sort(keys(%{$unauthorized}))) {
466: if (ref($unauthorized->{$key}) eq 'HASH') {
467: foreach my $user (sort(keys(%{$unauthorized->{$key}}))) {
468: if (ref($unauthorized->{$key}->{$user}) eq 'HASH') {
469: my ($crstype,$role,$cdom,$cnum,$csec,$title,$plainrole);
470: $role = $unauthorized->{$key}->{$user}{'role'};
471: $cdom = $unauthorized->{$key}->{$user}{'cdom'};
472: $cnum = $unauthorized->{$key}->{$user}{'cnum'};
473: $csec = $unauthorized->{$key}->{$user}{'csec'};
474: if (($context eq 'domain') && ($cnum ne '')) {
475: if (($role eq 'ca') || ($role eq 'aa')) {
476: $title = &mt('Authoring Space belonging to: [_1]',
477: &Apache::loncommon::plainname($cnum,$cdom));
478: } else {
479: if (&Apache::lonnet::is_course($cdom,$cnum)) {
480: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
481: $crstype = $coursedata{'type'};
482: $title = &mt("$crstype: [_1]",$coursedata{'description'});
483: }
484: }
485: } elsif ($context eq 'course') {
486: $crstype = &Apache::loncommon::course_type();
487: }
488: $plainrole = &Apache::lonnet::plaintext($role,$crstype);
489: $output .= '<li>'.&mt('User: [_1]',$unauthorized->{$key}->{$user}{'uname'}).' | '.
490: &mt('Domain: [_1]',$unauthorized->{$key}->{$user}{'udom'}).' | '.
491: &mt('Role: [_1]',$plainrole);
492: if ($crstype) {
493: if ($csec ne'') {
494: $output .= ' | '.&mt('Section: [_1]',$csec);
495: }
496: }
497: if ($title ne '') {
498: $output .= ' | '.$title;
499: }
500: $output .= '</li>';
501: }
1.212 raeburn 502: }
503: }
504: }
1.213 raeburn 505: $output .= '</ul></p>';
1.212 raeburn 506: }
507: return $output;
508: }
509:
510: sub print_roles_queued {
1.213 raeburn 511: my ($context,$pending,$notifydc,$currqueued) = @_;
512: return unless ((ref($pending) eq 'HASH') && (ref($notifydc) eq 'HASH') &&
513: (ref($currqueued) eq 'HASH'));
1.212 raeburn 514: my $output;
515: if (keys(%{$pending}) > 0) {
516: my $now = time;
517: $output = '<p class="LC_warning">'.
518: &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>';
519: my (%todom,%touser,%crsqueue,%caqueue,%domqueue);
520: my $requester = $env{'user.name'}.':'.$env{'user.domain'};
521: foreach my $key (sort(keys(%{$pending}))) {
522: if (ref($pending->{$key}) eq 'HASH') {
1.213 raeburn 523: foreach my $user (sort(keys(%{$pending->{$key}}))) {
524: if (ref($pending->{$key}->{$user}) eq 'HASH') {
525: my $role = $pending->{$key}->{$user}{'role'};
526: my $uname = $pending->{$key}->{$user}{'uname'};
527: my $udom = $pending->{$key}->{$user}{'udom'};
528: my $csec = $pending->{$key}->{$user}{'csec'};
529: my $cdom = $pending->{$key}->{$user}{'cdom'};
530: my $cnum = $pending->{$key}->{$user}{'cnum'};
531: my $adj = $pending->{$key}->{$user}{'adj'};
532: my $start = $pending->{$key}->{$user}{'start'};
533: my $end = $pending->{$key}->{$user}{'end'};
534: my $credits = $pending->{$key}->{$user}{'credits'};
535: my $now = time;
536: my ($crstype,$title,$plainrole,$extent,$id,$status);
537: if ($context eq 'course') {
538: $crstype = &Apache::loncommon::course_type();
539: $title = $env{'course.'.$env{'request.course.id'}.'.description'};
540: } elsif ($context eq 'domain') {
541: if (&Apache::lonnet::is_course($cdom,$cnum)) {
542: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
543: $crstype = $coursedata{'type'};
544: $title = $coursedata{'description'};
545: } elsif (($role eq 'ca') || ($role eq 'aa')) {
546: $title = &Apache::loncommon::plainname($cnum,$cdom);
547: }
548: }
549: $plainrole = &Apache::lonnet::plaintext($role,$crstype);
550: $extent = "/$cdom/$cnum";
551: $id = $uname.':'.$udom.':'.$role;
552: if (($context eq 'course') || ($crstype)) {
553: $id .= ':'.$csec;
554: }
555: $output .= '<li>'.&mt('User: [_1]',$uname).' | '.
556: &mt('Domain: [_1]',$udom).' | '.
557: &mt('Role: [_1]',$plainrole);
558: if ($crstype) {
559: if ($csec ne'') {
560: $output .= ' | '.&mt('Section: [_1]',$csec);
561: }
562: } elsif (($context eq 'domain') && (($role eq 'ca') || ($role eq 'aa'))) {
563: $output .= ' | '.&mt('Authoring Space belonging to: [_1]',$title);
564: }
565: if (($context eq 'domain') && ($crstype)) {
566: $output .= ' | '.&mt("$crstype: [_1]",$title);
567: }
568: if (($crstype) && ($csec ne '')) {
569: $extent .= "/$csec";
570: }
571: if ($adj eq 'user') {
572: $output .= '<br />'.&mt('Message sent to user for approval');
573: $touser{$uname.':'.$udom}{'pending:'.$extent.':'.$role} = {
574: timestamp => $now,
575: requester => $requester,
576: start => $start,
577: end => $end,
578: credits => $credits,
579: context => $context,
580: };
581: } elsif ($adj eq 'domain') {
582: $output .= '<br />'.&mt("Message sent to user's domain coordinator for approval");
583: $todom{$udom}{'pending:'.$uname.':'.$extent.':'.$role} = {
584: timestamp => $now,
585: requester => $requester,
586: start => $start,
587: end => $end,
588: credits => $credits,
589: context => $context,
590: };
591: }
592: $output .= '</li>';
593: if (($context eq 'course') || ($crstype)) {
594: $crsqueue{$cdom.'_'.$cnum}{$id} = {
595: timestamp => $now,
596: requester => $requester,
597: adj => $adj,
598: };
599: $crsqueue{$cdom.'_'.$cnum}{'status&'.$id} = 'pending';
600: } elsif (($context eq 'author') ||
601: (($context eq 'domain') && (($role eq 'ca') || ($role eq 'aa')))) {
602: $caqueue{$cnum.':'.$cdom}{$id} = {
603: timestamp => $now,
604: requester => $requester,
605: adj => $adj,
606: };
607: $caqueue{$cnum.':'.$cdom}{'status&'.$id} = 'pending';
608: } elsif ($context eq 'domain') {
609: $domqueue{$id} = {
610: timestamp => $now,
611: requester => $requester,
612: adj => $adj,
613: };
614: $domqueue{'status&'.$id} = 'pending';
615: }
616: }
1.212 raeburn 617: }
618: }
619: }
620: $output .= '</ul></p>';
621: if (keys(%touser)) {
622: foreach my $key (keys(%touser)) {
1.214 raeburn 623: my ($uname,$udom) = split(/:/,$key);
1.213 raeburn 624: if (&Apache::lonnet::put('nohist_queuedrolereqs',$touser{$key},$udom,$uname) eq 'ok') {
1.212 raeburn 625: my $owndomdesc = &Apache::lonnet::domain($udom);
626: &Apache::loncoursequeueadmin::send_selfserve_notification($uname.':'.$udom,
627: '','',$owndomdesc,$now,'othdomroleuser',$requester);
628: }
629: }
630: }
631: if (keys(%todom)) {
632: foreach my $dom (keys(%todom)) {
633: if (ref($todom{$dom}) eq 'HASH') {
634: my $confname = &Apache::lonnet::get_domainconfiguser($dom);
1.213 raeburn 635: if (&Apache::lonnet::put('nohist_queuedrolereqs',$todom{$dom},$dom,$confname) eq 'ok') {
1.212 raeburn 636: if (ref($notifydc->{$dom}) eq 'ARRAY') {
637: if (@{$notifydc->{$dom}} > 0) {
638: my $notifylist = join(',',@{$notifydc->{$dom}});
639: &Apache::loncoursequeueadmin::send_selfserve_notification($notifylist,
640: '','','',$now,'othdomroledc',$requester);
641: }
642: }
643: }
644: }
645: }
646: }
647: if (keys(%crsqueue)) {
648: foreach my $key (keys(%crsqueue)) {
649: my ($cdom,$cnum) = split(/_/,$key);
650: if (ref($crsqueue{$key}) eq 'HASH') {
1.213 raeburn 651: &Apache::lonnet::put('nohist_othdomqueued',$crsqueue{$key},$cdom,$cnum);
1.212 raeburn 652: }
653: }
654: }
655: if (keys(%caqueue)) {
656: foreach my $key (keys(%caqueue)) {
657: my ($auname,$audom) = split(/:/,$key);
658: if (ref($caqueue{$key}) eq 'HASH') {
1.213 raeburn 659: &Apache::lonnet::put('nohist_othdomqueued',$caqueue{$key},$audom,$auname);
1.212 raeburn 660: }
661: }
662: }
663: if (keys(%domqueue)) {
664: my $confname = &Apache::lonnet::get_domainconfiguser($env{'request.role.domain'});
1.213 raeburn 665: &Apache::lonnet::put('nohist_othdomqueued',\%domqueue,$env{'request.role.domain'},$confname);
1.212 raeburn 666: }
667: }
1.213 raeburn 668: if (keys(%{$currqueued}) > 0) {
669: $output = '<p class="LC_warning">'.
670: &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>';
671: my $requester = $env{'user.name'}.':'.$env{'user.domain'};
672: foreach my $key (sort(keys(%{$currqueued}))) {
673: if (ref($currqueued->{$key}) eq 'HASH') {
674: foreach my $user (sort(keys(%{$currqueued->{$key}}))) {
675: if (ref($currqueued->{$key}->{$user}) eq 'HASH') {
676: my $role = $currqueued->{$key}->{$user}{'role'};
677: my $csec = $currqueued->{$key}->{$user}{'csec'};
678: my $cdom = $currqueued->{$key}->{$user}{'cdom'};
679: my $cnum = $currqueued->{$key}->{$user}{'cnum'};
680: my ($crstype,$title,$plainrole);
681: if ($context eq 'course') {
682: $crstype = &Apache::loncommon::course_type();
683: } elsif (($context eq 'domain') && ($cnum ne '')) {
684: if (($role eq 'ca') || ($role eq 'aa')) {
685: $title = &mt('Authoring Space belonging to: [_1]',
686: &Apache::loncommon::plainname($cnum,$cdom));
687: } elsif (&Apache::lonnet::is_course($cdom,$cnum)) {
688: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
689: $crstype = $coursedata{'type'};
690: $title = &mt("$crstype: [_1]",$coursedata{'description'});
691: }
692: }
693: $plainrole = &Apache::lonnet::plaintext($role,$crstype);
694: $output .= '<li>'.&mt('User: [_1]',$currqueued->{$key}->{$user}{'uname'}).' | '.
695: &mt('Domain: [_1]',$currqueued->{$key}->{$user}{'udom'}).' | '.
696: &mt('Role: [_1]',$plainrole);
697: if ($title ne '') {
698: $output .= ' | '.$title;
699: }
700: if ($crstype) {
701: if ($csec ne '') {
702: $output .= ' | '.&mt('Section: [_1]',$csec);
703: }
704: }
705: $output .= '</li>';
706: }
707: }
708: }
709: }
710: $output .= '</ul></p>';
711: }
1.212 raeburn 712: return $output;
713: }
714:
1.5 raeburn 715: sub propagate_id_change {
716: my ($uname,$udom,$user) = @_;
1.12 raeburn 717: my (@types,@roles);
1.5 raeburn 718: @types = ('active','future');
719: @roles = ('st');
720: my $idresult;
721: my %roleshash = &Apache::lonnet::get_my_roles($uname,
1.12 raeburn 722: $udom,'userroles',\@types,\@roles);
723: my %args = (
724: one_time => 1,
725: );
1.5 raeburn 726: foreach my $item (keys(%roleshash)) {
1.22 raeburn 727: my ($cnum,$cdom,$role) = split(/:/,$item,-1);
1.5 raeburn 728: my ($start,$end) = split(/:/,$roleshash{$item});
729: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.12 raeburn 730: my $result = &update_classlist($cdom,$cnum,$udom,$uname,$user);
731: my %coursehash =
732: &Apache::lonnet::coursedescription($cdom.'_'.$cnum,\%args);
733: my $cdesc = $coursehash{'description'};
734: if ($cdesc eq '') {
735: $cdesc = $cdom.'_'.$cnum;
736: }
1.5 raeburn 737: if ($result eq 'ok') {
1.12 raeburn 738: $idresult .= &mt('Classlist update for "[_1]" in "[_2]".',$uname.':'.$udom,$cdesc).'<br />'."\n";
1.5 raeburn 739: } else {
1.12 raeburn 740: $idresult .= &mt('Error: "[_1]" during classlist update for "[_2]" in "[_3]".',$result,$uname.':'.$udom,$cdesc).'<br />'."\n";
1.5 raeburn 741: }
742: }
743: }
744: return $idresult;
745: }
746:
747: sub update_classlist {
1.63 raeburn 748: my ($cdom,$cnum,$udom,$uname,$user,$newend) = @_;
1.6 albertel 749: my ($uid,$classlistentry);
1.5 raeburn 750: my $fullname =
751: &Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
752: $user->{'lastname'},$user->{'generation'},
753: 'lastname');
754: my %classhash = &Apache::lonnet::get('classlist',[$uname.':'.$udom],
755: $cdom,$cnum);
756: my @classinfo = split(/:/,$classhash{$uname.':'.$udom});
757: my $ididx=&Apache::loncoursedata::CL_ID() - 2;
758: my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2;
1.63 raeburn 759: my $endidx = &Apache::loncoursedata::CL_END() - 2;
760: my $startidx = &Apache::loncoursedata::CL_START() - 2;
1.5 raeburn 761: for (my $i=0; $i<@classinfo; $i++) {
1.63 raeburn 762: if ($i == $endidx) {
763: if ($newend ne '') {
764: $classlistentry .= $newend.':';
765: } else {
766: $classlistentry .= $classinfo[$i].':';
767: }
768: } elsif ($i == $startidx) {
769: if ($newend ne '') {
770: if ($classinfo[$i] > $newend) {
771: $classlistentry .= $newend.':';
772: } else {
773: $classlistentry .= $classinfo[$i].':';
774: }
775: } else {
776: $classlistentry .= $classinfo[$i].':';
777: }
778: } elsif ($i == $ididx) {
1.5 raeburn 779: if (defined($user->{'id'})) {
780: $classlistentry .= $user->{'id'}.':';
781: } else {
782: $classlistentry .= $classinfo[$i].':';
783: }
784: } elsif ($i == $nameidx) {
1.63 raeburn 785: if (defined($user->{'lastname'})) {
786: $classlistentry .= $fullname.':';
787: } else {
788: $classlistentry .= $classinfo[$i].':';
789: }
1.5 raeburn 790: } else {
791: $classlistentry .= $classinfo[$i].':';
792: }
793: }
794: $classlistentry =~ s/:$//;
795: my $reply=&Apache::lonnet::cput('classlist',
796: {"$uname:$udom" => $classlistentry},
797: $cdom,$cnum);
798: if (($reply eq 'ok') || ($reply eq 'delayed')) {
799: return 'ok';
800: } else {
801: return 'error: '.$reply;
802: }
803: }
804:
805:
1.1 raeburn 806: ###############################################################
807: ###############################################################
1.2 raeburn 808: # build a role type and role selection form
809: sub domain_roles_select {
810: # Set up the role type and role selection boxes when in
811: # domain context
812: #
813: # Role types
1.101 raeburn 814: my @roletypes = ('domain','author','course','community');
1.2 raeburn 815: my %lt = &role_type_names();
1.149 raeburn 816: my $onchangefirst = "updateCols('showrole')";
817: my $onchangesecond = "updateCols('showrole')";
1.1 raeburn 818: #
819: # build up the menu information to be passed to
820: # &Apache::loncommon::linked_select_forms
821: my %select_menus;
1.2 raeburn 822: if ($env{'form.roletype'} eq '') {
823: $env{'form.roletype'} = 'domain';
824: }
825: foreach my $roletype (@roletypes) {
1.1 raeburn 826: # set up the text for this domain
1.2 raeburn 827: $select_menus{$roletype}->{'text'}= $lt{$roletype};
1.102 raeburn 828: my $crstype;
829: if ($roletype eq 'community') {
830: $crstype = 'Community';
831: }
1.1 raeburn 832: # we want a choice of 'default' as the default in the second menu
1.2 raeburn 833: if ($env{'form.roletype'} ne '') {
834: $select_menus{$roletype}->{'default'} = $env{'form.showrole'};
835: } else {
836: $select_menus{$roletype}->{'default'} = 'Any';
837: }
1.1 raeburn 838: # Now build up the other items in the second menu
1.2 raeburn 839: my @roles;
840: if ($roletype eq 'domain') {
841: @roles = &domain_roles();
1.13 raeburn 842: } elsif ($roletype eq 'author') {
1.2 raeburn 843: @roles = &construction_space_roles();
844: } else {
1.17 raeburn 845: my $custom = 1;
1.101 raeburn 846: @roles = &course_roles('domain',undef,$custom,$roletype);
1.1 raeburn 847: }
1.2 raeburn 848: my $order = ['Any',@roles];
849: $select_menus{$roletype}->{'order'} = $order;
850: foreach my $role (@roles) {
1.5 raeburn 851: if ($role eq 'cr') {
852: $select_menus{$roletype}->{'select2'}->{$role} =
853: &mt('Custom role');
854: } else {
855: $select_menus{$roletype}->{'select2'}->{$role} =
1.102 raeburn 856: &Apache::lonnet::plaintext($role,$crstype);
1.5 raeburn 857: }
1.2 raeburn 858: }
859: $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
1.1 raeburn 860: }
1.2 raeburn 861: my $result = &Apache::loncommon::linked_select_forms
862: ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
1.101 raeburn 863: 'roletype','showrole',\%select_menus,
1.149 raeburn 864: ['domain','author','course','community'],$onchangefirst,
865: $onchangesecond);
1.1 raeburn 866: return $result;
867: }
868:
869: ###############################################################
870: ###############################################################
871: sub hidden_input {
872: my ($name,$value) = @_;
873: return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n";
874: }
875:
876: sub print_upload_manager_header {
1.123 raeburn 877: my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype,
878: $can_assign)=@_;
1.1 raeburn 879: my $javascript;
880: #
881: if (! exists($env{'form.upfile_associate'})) {
882: $env{'form.upfile_associate'} = 'forward';
883: }
884: if ($env{'form.associate'} eq 'Reverse Association') {
885: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
886: $env{'form.upfile_associate'} = 'reverse';
887: } else {
888: $env{'form.upfile_associate'} = 'forward';
889: }
890: }
891: if ($env{'form.upfile_associate'} eq 'reverse') {
1.123 raeburn 892: $javascript=&upload_manager_javascript_reverse_associate($can_assign);
1.1 raeburn 893: } else {
1.123 raeburn 894: $javascript=&upload_manager_javascript_forward_associate($can_assign);
1.1 raeburn 895: }
896: #
897: # Deal with restored settings
898: my $password_choice = '';
899: if (exists($env{'form.ipwd_choice'}) &&
900: $env{'form.ipwd_choice'} ne '') {
901: # If a column was specified for password, assume it is for an
902: # internal password. This is a bug waiting to be filed (could be
903: # local or krb auth instead of internal) but I do not have the
904: # time to mess around with this now.
905: $password_choice = 'int';
906: }
907: #
1.22 raeburn 908: my $groupslist;
909: if ($context eq 'course') {
910: $groupslist = &get_groupslist();
911: }
1.1 raeburn 912: my $javascript_validations =
1.22 raeburn 913: &javascript_validations('upload',$krbdefdom,$password_choice,undef,
914: $env{'request.role.domain'},$context,
1.103 raeburn 915: $groupslist,$crstype);
1.91 bisitz 916: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.147 bisitz 917: $r->print(
918: '<h3>'.&mt('Identify fields in uploaded list')."</h3>\n".
919: '<p class="LC_info">'.
920: &mt('Total number of records found in file: [_1]'
921: ,'<b>'.$distotal.'</b>').
922: "</p>\n"
923: );
924: if ($distotal == 0) {
925: $r->print('<p class="LC_warning">'.&mt('None found').'</p>');
926: }
927: $r->print(
928: '<p>'.
929: &mt('Enter as many fields as you can.').'<br />'.
930: &mt('The system will inform you and bring you back to this page,[_1]if the data selected are insufficient to add users.','<br />').
931: "</p>\n"
932: );
1.1 raeburn 933: $r->print(&hidden_input('action','upload').
934: &hidden_input('state','got_file').
935: &hidden_input('associate','').
936: &hidden_input('datatoken',$datatoken).
937: &hidden_input('fileupload',$env{'form.fileupload'}).
938: &hidden_input('upfiletype',$env{'form.upfiletype'}).
939: &hidden_input('upfile_associate',$env{'form.upfile_associate'}));
1.147 bisitz 940: $r->print(
941: '<div class="LC_left_float">'.
942: '<fieldset><legend>'.&mt('Functions').'</legend>'.
943: '<label><input type="checkbox" name="noFirstLine"'.$checked.' />'.
944: &mt('Ignore First Line').'</label>'.
945: ' <input type="button" value="'.&mt('Reverse Association').'" '.
1.59 bisitz 946: 'name="Reverse Association" '.
1.147 bisitz 947: 'onclick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />'.
948: '</fieldset></div><br clear="all" />'
949: );
950: $r->print(
951: '<script type="text/javascript" language="Javascript">'."\n".
952: '// <![CDATA['."\n".
953: $javascript."\n".$javascript_validations."\n".
954: '// ]]>'."\n".
955: '</script>'
956: );
1.1 raeburn 957: }
958:
959: ###############################################################
960: ###############################################################
961: sub javascript_validations {
1.22 raeburn 962: my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain,
1.103 raeburn 963: $context,$groupslist,$crstype)=@_;
1.22 raeburn 964: my %param = (
965: kerb_def_dom => $krbdefdom,
966: curr_authtype => $curr_authtype,
967: );
1.37 raeburn 968: if ($mode eq 'upload') {
1.22 raeburn 969: $param{'formname'} = 'studentform';
1.1 raeburn 970: } elsif ($mode eq 'createcourse') {
1.22 raeburn 971: $param{'formname'} = 'ccrs';
1.1 raeburn 972: } elsif ($mode eq 'modifycourse') {
1.22 raeburn 973: $param{'formname'} = 'cmod';
974: $param{'mode'} = 'modifycourse',
975: $param{'curr_autharg'} = $curr_authfield;
976: }
977:
1.150 raeburn 978: my $showcredits;
979: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
1.160 raeburn 980: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
1.150 raeburn 981: $showcredits = 1;
982: }
983:
1.22 raeburn 984: my ($setsection_call,$setsections_js);
985: my $finish = " vf.submit();\n";
986: if ($mode eq 'upload') {
987: if (($context eq 'course') || ($context eq 'domain')) {
988: if ($context eq 'course') {
989: if ($env{'request.course.sec'} eq '') {
1.109 raeburn 990: $setsection_call = 'setSections(document.'.$param{'formname'}.",'$crstype'".');';
1.22 raeburn 991: $setsections_js =
992: &setsections_javascript($param{'formname'},$groupslist,
1.150 raeburn 993: $mode,'',$crstype,$showcredits);
1.22 raeburn 994: } else {
995: $setsection_call = "'ok'";
996: }
997: } elsif ($context eq 'domain') {
998: $setsection_call = 'setCourse()';
1.150 raeburn 999: $setsections_js = &dc_setcourse_js($param{'formname'},$mode,
1.196 raeburn 1000: $context,$showcredits,$domain);
1.22 raeburn 1001: }
1002: $finish = " var checkSec = $setsection_call\n".
1003: " if (checkSec == 'ok') {\n".
1004: " vf.submit();\n".
1005: " }\n";
1006: }
1.1 raeburn 1007: }
1.22 raeburn 1008: my $authheader = &Apache::loncommon::authform_header(%param);
1.1 raeburn 1009:
1010: my %alert = &Apache::lonlocal::texthash
1011: (username => 'You need to specify the username field.',
1012: authen => 'You must choose an authentication type.',
1013: krb => 'You need to specify the Kerberos domain.',
1014: ipass => 'You need to specify the initial password.',
1015: name => 'The optional name field was not specified.',
1.93 bisitz 1016: snum => 'The optional student/employee ID field was not specified.',
1.1 raeburn 1017: section => 'The optional section field was not specified.',
1.75 schafran 1018: email => 'The optional e-mail address field was not specified.',
1.1 raeburn 1019: role => 'The optional role field was not specified.',
1.57 raeburn 1020: domain => 'The optional domain field was not specified.',
1.1 raeburn 1021: continue => 'Continue adding users?',
1022: );
1.150 raeburn 1023: if ($showcredits) {
1024: $alert{'credits'} = &mt('The optional credits field was not specified');
1025: }
1.84 raeburn 1026: if (($mode eq 'upload') && ($context eq 'domain')) {
1027: $alert{'inststatus'} = &mt('The optional affiliation field was not specified');
1028: }
1.170 damieng 1029: &js_escape(\%alert);
1.37 raeburn 1030: my $function_name = <<"END";
1.22 raeburn 1031: $setsections_js
1032:
1.150 raeburn 1033: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits) {
1.1 raeburn 1034: END
1035: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($domain);
1036: my $auth_checks;
1037: if ($mode eq 'createcourse') {
1038: $auth_checks .= (<<END);
1039: if (vf.autoadds[0].checked == true) {
1040: if (current.radiovalue == null || current.radiovalue == 'nochange') {
1041: alert('$alert{'authen'}');
1042: return;
1043: }
1044: }
1045: END
1046: } else {
1047: $auth_checks .= (<<END);
1048: var foundatype=0;
1049: if (founduname==0) {
1050: alert('$alert{'username'}');
1051: return;
1052: }
1053:
1054: END
1055: if ($authnum > 1) {
1056: $auth_checks .= (<<END);
1057: if (current.radiovalue == null || current.radiovalue == '' || current.radiovalue == 'nochange') {
1058: // They did not check any of the login radiobuttons.
1059: alert('$alert{'authen'}');
1060: return;
1061: }
1062: END
1063: }
1064: }
1065: if ($mode eq 'createcourse') {
1066: $auth_checks .= "
1067: if ( (vf.autoadds[0].checked == true) &&
1068: (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') ) {
1069: ";
1070: } elsif ($mode eq 'modifycourse') {
1071: $auth_checks .= "
1.215 raeburn 1072: if ((current.argfield !== null) && (current.argfield !== undefined) && (current.argfield !== '') && (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '')) {
1.1 raeburn 1073: ";
1074: }
1075: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
1076: $auth_checks .= (<<END);
1077: var alertmsg = '';
1078: switch (current.radiovalue) {
1079: case 'krb':
1080: alertmsg = '$alert{'krb'}';
1081: break;
1082: default:
1083: alertmsg = '';
1084: }
1085: if (alertmsg != '') {
1086: alert(alertmsg);
1087: return;
1088: }
1089: }
1.150 raeburn 1090: /* regexp here to check for non \d \. in credits */
1.1 raeburn 1091: END
1092: } else {
1.196 raeburn 1093: my ($numrules,$intargjs) =
1.210 raeburn 1094: &Apache::loncommon::passwd_validation_js('vf.elements[current.argfield].value',$domain);
1.1 raeburn 1095: $auth_checks .= (<<END);
1096: foundatype=1;
1097: if (current.argfield == null || current.argfield == '') {
1.196 raeburn 1098: // The login radiobutton checked does not have an associated textbox
1099: } else if (vf.elements[current.argfield].value == '') {
1.1 raeburn 1100: var alertmsg = '';
1.38 raeburn 1101: switch (current.radiovalue) {
1.1 raeburn 1102: case 'krb':
1103: alertmsg = '$alert{'krb'}';
1104: break;
1.196 raeburn 1105: case 'int':
1.1 raeburn 1106: alertmsg = '$alert{'ipass'}';
1107: break;
1108: case 'fsys':
1.196 raeburn 1109: alertmsg = '$alert{'ipass'}';
1.1 raeburn 1110: break;
1.209 raeburn 1111: case 'loc':
1112: alertmsg = '';
1113: break;
1.194 raeburn 1114: case 'lti':
1.1 raeburn 1115: default:
1116: alertmsg = '';
1117: }
1118: if (alertmsg != '') {
1119: alert(alertmsg);
1120: return;
1121: }
1.196 raeburn 1122: } else if (current.radiovalue == 'int') {
1123: if ($numrules > 0) {
1124: $intargjs
1125: }
1.1 raeburn 1126: }
1127: END
1128: }
1129: my $section_checks;
1130: my $optional_checks = '';
1131: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
1132: $optional_checks = (<<END);
1133: vf.submit();
1134: }
1135: END
1136: } else {
1137: $section_checks = §ion_check_js();
1138: $optional_checks = (<<END);
1139: var message='';
1140: if (foundname==0) {
1141: message='$alert{'name'}';
1142: }
1143: if (foundid==0) {
1144: if (message!='') {
1145: message+='\\n';
1146: }
1147: message+='$alert{'snum'}';
1148: }
1149: if (foundsec==0) {
1150: if (message!='') {
1151: message+='\\n';
1152: }
1.130 raeburn 1153: message+='$alert{'section'}';
1.1 raeburn 1154: }
1155: if (foundemail==0) {
1156: if (message!='') {
1157: message+='\\n';
1158: }
1159: message+='$alert{'email'}';
1160: }
1.57 raeburn 1161: if (foundrole==0) {
1162: if (message!='') {
1163: message+='\\n';
1164: }
1165: message+='$alert{'role'}';
1166: }
1167: if (founddomain==0) {
1168: if (message!='') {
1169: message+='\\n';
1170: }
1171: message+='$alert{'domain'}';
1172: }
1.84 raeburn 1173: END
1.150 raeburn 1174: if ($showcredits) {
1175: $optional_checks .= <<END;
1176: if (foundcredits==0) {
1177: if (message!='') {
1178: message+='\\n';
1179: }
1180: message+='$alert{'credits'}';
1181: }
1182: END
1183: }
1.84 raeburn 1184: if (($mode eq 'upload') && ($context eq 'domain')) {
1185: $optional_checks .= (<<END);
1186:
1187: if (foundinststatus==0) {
1188: if (message!='') {
1189: message+='\\n';
1190: }
1191: message+='$alert{'inststatus'}';
1192: }
1193: END
1194: }
1195: $optional_checks .= (<<END);
1196:
1.1 raeburn 1197: if (message!='') {
1198: message+= '\\n$alert{'continue'}';
1199: if (confirm(message)) {
1200: vf.state.value='enrolling';
1.22 raeburn 1201: $finish
1.1 raeburn 1202: }
1203: } else {
1204: vf.state.value='enrolling';
1.22 raeburn 1205: $finish
1.1 raeburn 1206: }
1207: }
1208: END
1209: }
1.37 raeburn 1210: my $result = $function_name.$auth_checks.$optional_checks."\n".
1211: $section_checks.$authheader;
1.1 raeburn 1212: return $result;
1213: }
1.196 raeburn 1214:
1.1 raeburn 1215: ###############################################################
1216: ###############################################################
1217: sub upload_manager_javascript_forward_associate {
1.123 raeburn 1218: my ($can_assign) = @_;
1.132 raeburn 1219: my ($auth_update,$numbuttons,$argreset);
1.123 raeburn 1220: if (ref($can_assign) eq 'HASH') {
1.132 raeburn 1221: if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
1222: $argreset .= " vf.krbarg.value='';\n";
1223: $numbuttons ++ ;
1224: }
1225: if ($can_assign->{'int'}) {
1226: $argreset .= " vf.intarg.value='';\n";
1227: $numbuttons ++;
1228: }
1229: if ($can_assign->{'loc'}) {
1230: $argreset .= " vf.locarg.value='';\n";
1231: $numbuttons ++;
1232: }
1233: if (!$can_assign->{'int'}) {
1.170 damieng 1234: 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".
1.132 raeburn 1235: &mt('Your current role does not have rights to create users with that authentication type.');
1.170 damieng 1236: &js_escape(\$warning);
1.132 raeburn 1237: $auth_update = <<"END";
1238: // Currently the initial password field is only supported for internal auth
1239: // (see bug 6368).
1240: if (nw==9) {
1241: eval('vf.f'+tf+'.selectedIndex=0;')
1242: alert('$warning');
1243: }
1244: END
1245: } elsif ($numbuttons > 1) {
1.123 raeburn 1246: $auth_update = <<"END";
1247: // If we set the password, make the password form below correspond to
1248: // the new value.
1249: if (nw==9) {
1250: changed_radio('int',document.studentform);
1251: set_auth_radio_buttons('int',document.studentform);
1.132 raeburn 1252: $argreset
1253: }
1254:
1.123 raeburn 1255: END
1256: }
1257: }
1258:
1.1 raeburn 1259: return(<<ENDPICK);
1260: function verify(vf,sec_caller) {
1261: var founduname=0;
1262: var foundpwd=0;
1263: var foundname=0;
1264: var foundid=0;
1265: var foundsec=0;
1266: var foundemail=0;
1267: var foundrole=0;
1.57 raeburn 1268: var founddomain=0;
1.84 raeburn 1269: var foundinststatus=0;
1.150 raeburn 1270: var foundcredits=0;
1.1 raeburn 1271: var tw;
1272: for (i=0;i<=vf.nfields.value;i++) {
1273: tw=eval('vf.f'+i+'.selectedIndex');
1274: if (tw==1) { founduname=1; }
1275: if ((tw>=2) && (tw<=6)) { foundname=1; }
1276: if (tw==7) { foundid=1; }
1277: if (tw==8) { foundsec=1; }
1278: if (tw==9) { foundpwd=1; }
1279: if (tw==10) { foundemail=1; }
1280: if (tw==11) { foundrole=1; }
1.57 raeburn 1281: if (tw==12) { founddomain=1; }
1.84 raeburn 1282: if (tw==13) { foundinststatus=1; }
1.150 raeburn 1283: if (tw==14) { foundcredits=1; }
1.1 raeburn 1284: }
1.150 raeburn 1285: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits);
1.1 raeburn 1286: }
1287:
1288: //
1289: // vf = this.form
1290: // tf = column number
1291: //
1292: // values of nw
1293: //
1294: // 0 = none
1295: // 1 = username
1296: // 2 = names (lastname, firstnames)
1297: // 3 = fname (firstname)
1298: // 4 = mname (middlename)
1299: // 5 = lname (lastname)
1300: // 6 = gen (generation)
1301: // 7 = id
1302: // 8 = section
1303: // 9 = ipwd (password)
1304: // 10 = email address
1305: // 11 = role
1.57 raeburn 1306: // 12 = domain
1.84 raeburn 1307: // 13 = inststatus
1.150 raeburn 1308: // 14 = foundcredits
1.1 raeburn 1309:
1310: function flip(vf,tf) {
1311: var nw=eval('vf.f'+tf+'.selectedIndex');
1312: var i;
1313: // make sure no other columns are labeled the same as this one
1314: for (i=0;i<=vf.nfields.value;i++) {
1315: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
1316: eval('vf.f'+i+'.selectedIndex=0;')
1317: }
1318: }
1319: // If we set this to 'lastname, firstnames', clear out all the ones
1320: // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
1321: if (nw==2) {
1322: for (i=0;i<=vf.nfields.value;i++) {
1323: if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
1324: (eval('vf.f'+i+'.selectedIndex')<=6)) {
1325: eval('vf.f'+i+'.selectedIndex=0;')
1326: }
1327: }
1328: }
1329: // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
1330: // clear out any that are set to 'lastname, firstnames' (2)
1331: if ((nw>=3) && (nw<=6)) {
1332: for (i=0;i<=vf.nfields.value;i++) {
1333: if (eval('vf.f'+i+'.selectedIndex')==2) {
1334: eval('vf.f'+i+'.selectedIndex=0;')
1335: }
1336: }
1337: }
1.123 raeburn 1338: $auth_update
1.1 raeburn 1339: }
1340:
1341: function clearpwd(vf) {
1342: var i;
1343: for (i=0;i<=vf.nfields.value;i++) {
1344: if (eval('vf.f'+i+'.selectedIndex')==9) {
1345: eval('vf.f'+i+'.selectedIndex=0;')
1346: }
1347: }
1348: }
1349:
1350: ENDPICK
1351: }
1352:
1353: ###############################################################
1354: ###############################################################
1355: sub upload_manager_javascript_reverse_associate {
1.123 raeburn 1356: my ($can_assign) = @_;
1.132 raeburn 1357: my ($auth_update,$numbuttons,$argreset);
1.123 raeburn 1358: if (ref($can_assign) eq 'HASH') {
1.132 raeburn 1359: if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
1360: $argreset .= " vf.krbarg.value='';\n";
1361: $numbuttons ++ ;
1362: }
1363: if ($can_assign->{'int'}) {
1364: $argreset .= " vf.intarg.value='';\n";
1365: $numbuttons ++;
1366: }
1367: if ($can_assign->{'loc'}) {
1368: $argreset .= " vf.locarg.value='';\n";
1369: $numbuttons ++;
1370: }
1371: if (!$can_assign->{'int'}) {
1372: my $warning = &mt('You may not specify an initial password, as this is only available when new users use LON-CAPA internal authentication.\n').
1373: &mt('Your current role does not have rights to create users with that authentication type.');
1.170 damieng 1374: &js_escape(\$warning);
1.132 raeburn 1375: $auth_update = <<"END";
1376: // Currently the initial password field is only supported for internal auth
1377: // (see bug 6368).
1378: if (tf==8 && nw!=0) {
1379: eval('vf.f'+tf+'.selectedIndex=0;')
1380: alert('$warning');
1381: }
1382: END
1383: } elsif ($numbuttons > 1) {
1.123 raeburn 1384: $auth_update = <<"END";
1385: // initial password specified, pick internal authentication
1386: if (tf==8 && nw!=0) {
1387: changed_radio('int',document.studentform);
1388: set_auth_radio_buttons('int',document.studentform);
1.132 raeburn 1389: $argreset
1390: }
1391:
1.123 raeburn 1392: END
1393: }
1394: }
1.132 raeburn 1395:
1.1 raeburn 1396: return(<<ENDPICK);
1397: function verify(vf,sec_caller) {
1398: var founduname=0;
1399: var foundpwd=0;
1400: var foundname=0;
1401: var foundid=0;
1402: var foundsec=0;
1.131 raeburn 1403: var foundemail=0;
1.1 raeburn 1404: var foundrole=0;
1.57 raeburn 1405: var founddomain=0;
1.84 raeburn 1406: var foundinststatus=0;
1.150 raeburn 1407: var foundcredits=0;
1.1 raeburn 1408: var tw;
1409: for (i=0;i<=vf.nfields.value;i++) {
1410: tw=eval('vf.f'+i+'.selectedIndex');
1411: if (i==0 && tw!=0) { founduname=1; }
1412: if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
1413: if (i==6 && tw!=0) { foundid=1; }
1414: if (i==7 && tw!=0) { foundsec=1; }
1415: if (i==8 && tw!=0) { foundpwd=1; }
1.130 raeburn 1416: if (i==9 && tw!=0) { foundemail=1; }
1417: if (i==10 && tw!=0) { foundrole=1; }
1418: if (i==11 && tw!=0) { founddomain=1; }
1419: if (i==12 && tw!=0) { foundinstatus=1; }
1.150 raeburn 1420: if (i==13 && tw!=0) { foundcredits=1; }
1.1 raeburn 1421: }
1.150 raeburn 1422: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits);
1.1 raeburn 1423: }
1424:
1425: function flip(vf,tf) {
1426: var nw=eval('vf.f'+tf+'.selectedIndex');
1427: var i;
1428: // picked the all one name field, reset the other name ones to blank
1429: if (tf==1 && nw!=0) {
1430: for (i=2;i<=5;i++) {
1431: eval('vf.f'+i+'.selectedIndex=0;')
1432: }
1433: }
1434: //picked one of the piecewise name fields, reset the all in
1435: //one field to blank
1436: if ((tf>=2) && (tf<=5) && (nw!=0)) {
1437: eval('vf.f1.selectedIndex=0;')
1438: }
1.123 raeburn 1439: $auth_update
1.1 raeburn 1440: }
1441:
1442: function clearpwd(vf) {
1443: var i;
1444: if (eval('vf.f8.selectedIndex')!=0) {
1445: eval('vf.f8.selectedIndex=0;')
1446: }
1447: }
1448: ENDPICK
1449: }
1450:
1451: ###############################################################
1452: ###############################################################
1453: sub print_upload_manager_footer {
1.150 raeburn 1454: my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context,$permission,$crstype,
1455: $showcredits) = @_;
1.22 raeburn 1456: my $form = 'document.studentform';
1457: my $formname = 'studentform';
1.1 raeburn 1458: my ($krbdef,$krbdefdom) =
1459: &Apache::loncommon::get_kerberos_defaults($defdom);
1.22 raeburn 1460: my %param = ( formname => $form,
1.1 raeburn 1461: kerb_def_dom => $krbdefdom,
1462: kerb_def_auth => $krbdef
1463: );
1464: if (exists($env{'form.ipwd_choice'}) &&
1465: defined($env{'form.ipwd_choice'}) &&
1466: $env{'form.ipwd_choice'} ne '') {
1467: $param{'curr_authtype'} = 'int';
1468: }
1469: my $krbform = &Apache::loncommon::authform_kerberos(%param);
1470: my $intform = &Apache::loncommon::authform_internal(%param);
1471: my $locform = &Apache::loncommon::authform_local(%param);
1.194 raeburn 1472: my $ltiform = &Apache::loncommon::authform_lti(%param);
1.22 raeburn 1473: my $date_table = &date_setting_table(undef,undef,$context,undef,
1.101 raeburn 1474: $formname,$permission,$crstype);
1.95 bisitz 1475:
1.1 raeburn 1476: my $Str = "\n".'<div class="LC_left_float">';
1477: $Str .= &hidden_input('nfields',$i);
1478: $Str .= &hidden_input('keyfields',$keyfields);
1.95 bisitz 1479:
1480: $Str .= '<h3>'.&mt('Options').'</h3>'
1481: .&Apache::lonhtmlcommon::start_pick_box();
1482:
1483: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Login Type'));
1.1 raeburn 1484: if ($context eq 'domain') {
1.95 bisitz 1485: $Str .= '<p>'
1486: .&mt('Change authentication for existing users in domain "[_1]" to these settings?'
1487: ,$defdom)
1488: .' <span class="LC_nobreak"><label>'
1489: .'<input type="radio" name="changeauth" value="No" checked="checked" />'
1490: .&mt('No').'</label>'
1491: .' <label>'
1492: .'<input type="radio" name="changeauth" value="Yes" />'
1493: .&mt('Yes').'</label>'
1494: .'</span></p>';
1.1 raeburn 1495: } else {
1.95 bisitz 1496: $Str .= '<p class="LC_info">'."\n".
1497: &mt('This will not take effect if the user already exists.').
1.1 raeburn 1498: &Apache::loncommon::help_open_topic('Auth_Options').
1499: "</p>\n";
1500: }
1.194 raeburn 1501: $Str .= &set_login($defdom,$krbform,$intform,$locform,$ltiform);
1.95 bisitz 1502:
1.1 raeburn 1503: my ($home_server_pick,$numlib) =
1504: &Apache::loncommon::home_server_form_item($defdom,'lcserver',
1505: 'default','hide');
1506: if ($numlib > 1) {
1.97 raeburn 1507: $Str .= &Apache::lonhtmlcommon::row_closure()
1508: .&Apache::lonhtmlcommon::row_title(
1.95 bisitz 1509: &mt('LON-CAPA Home Server for New Users'))
1510: .&mt('LON-CAPA domain: [_1] with home server:','"'.$defdom.'"')
1511: .$home_server_pick
1512: .&Apache::lonhtmlcommon::row_closure();
1513: } else {
1.97 raeburn 1514: $Str .= $home_server_pick.
1515: &Apache::lonhtmlcommon::row_closure();
1.95 bisitz 1516: }
1517:
1.188 raeburn 1518: my ($trusted,$untrusted);
1.185 raeburn 1519: if ($context eq 'course') {
1.188 raeburn 1520: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.185 raeburn 1521: } elsif ($context eq 'author') {
1.188 raeburn 1522: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.185 raeburn 1523: }
1.95 bisitz 1524: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain'))
1.188 raeburn 1525: .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1,undef,$trusted,$untrusted)
1.95 bisitz 1526: .&Apache::lonhtmlcommon::row_closure();
1527:
1528: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Starting and Ending Dates'))
1529: ."<p>\n".$date_table."</p>\n"
1530: .&Apache::lonhtmlcommon::row_closure();
1531:
1.1 raeburn 1532: if ($context eq 'domain') {
1.95 bisitz 1533: $Str .= &Apache::lonhtmlcommon::row_title(
1534: &mt('Settings for assigning roles'))
1535: .&mt('Pick the action to take on roles for these users:').'<br />'
1536: .'<span class="LC_nobreak"><label>'
1537: .'<input type="radio" name="roleaction" value="norole" checked="checked" />'
1538: .' '.&mt('No role changes').'</label>'
1539: .' <label>'
1540: .'<input type="radio" name="roleaction" value="domain" />'
1541: .' '.&mt('Add a domain role').'</label>'
1542: .' <label>'
1543: .'<input type="radio" name="roleaction" value="course" />'
1.103 raeburn 1544: .' '.&mt('Add a course/community role').'</label>'
1.95 bisitz 1545: .'</span>';
1546: } elsif ($context eq 'author') {
1547: $Str .= &Apache::lonhtmlcommon::row_title(
1548: &mt('Default role'))
1549: .&mt('Choose the role to assign to users without a value specified in the uploaded file.')
1.1 raeburn 1550: } elsif ($context eq 'course') {
1.150 raeburn 1551: if ($showcredits) {
1552: $Str .= &Apache::lonhtmlcommon::row_title(
1553: &mt('Default role, section and credits'))
1554: .&mt('Choose the role and/or section(s) and/or credits to assign to users without values specified in the uploaded file.');
1555: } else {
1556: $Str .= &Apache::lonhtmlcommon::row_title(
1.95 bisitz 1557: &mt('Default role and section'))
1.150 raeburn 1558: .&mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file.');
1559: }
1.95 bisitz 1560: } else {
1561: $Str .= &Apache::lonhtmlcommon::row_title(
1562: &mt('Default role and/or section(s)'))
1563: .&mt('Role and/or section(s) for users without values specified in the uploaded file.');
1.1 raeburn 1564: }
1.22 raeburn 1565: if (($context eq 'domain') || ($context eq 'author')) {
1.95 bisitz 1566: $Str .= '<br />';
1.150 raeburn 1567: my ($options,$cb_script,$coursepick) =
1568: &default_role_selector($context,1,'',$showcredits);
1.22 raeburn 1569: if ($context eq 'domain') {
1.95 bisitz 1570: $Str .= '<p>'
1571: .'<b>'.&mt('Domain Level').'</b><br />'
1572: .$options
1573: .'</p><p>'
1574: .'<b>'.&mt('Course Level').'</b>'
1575: .'</p>'
1576: .$cb_script.$coursepick
1577: .&Apache::lonhtmlcommon::row_closure();
1.22 raeburn 1578: } elsif ($context eq 'author') {
1.95 bisitz 1579: $Str .= $options
1580: .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
1.22 raeburn 1581: }
1.1 raeburn 1582: } else {
1.22 raeburn 1583: my ($cnum,$cdom) = &get_course_identity();
1584: my $rowtitle = &mt('section');
1.150 raeburn 1585: my $defaultcredits;
1586: if ($showcredits) {
1587: $defaultcredits = &get_defaultcredits();
1588: }
1589: my $secbox = §ion_picker($cdom,$cnum,'Any',$rowtitle,$permission,
1590: $context,'upload',$crstype,$showcredits,
1591: $defaultcredits);
1.95 bisitz 1592: $Str .= $secbox
1593: .&Apache::lonhtmlcommon::row_closure();
1.101 raeburn 1594: my %lt;
1595: if ($crstype eq 'Community') {
1596: %lt = &Apache::lonlocal::texthash (
1597: disp => 'Display members with current/future access who are not in the uploaded file',
1598: stus => 'Members selected from this list can be dropped.'
1599: );
1600: } else {
1601: %lt = &Apache::lonlocal::texthash (
1602: disp => 'Display students with current/future access who are not in the uploaded file',
1603: stus => 'Students selected from this list can be dropped.'
1604: );
1605: }
1.95 bisitz 1606: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Full Update'))
1.101 raeburn 1607: .'<label><input type="checkbox" name="fullup" value="yes" />'
1608: .' '.$lt{'disp'}
1.95 bisitz 1609: .'</label><br />'
1.101 raeburn 1610: .$lt{'stus'}
1.95 bisitz 1611: .&Apache::lonhtmlcommon::row_closure();
1.1 raeburn 1612: }
1.5 raeburn 1613: if ($context eq 'course' || $context eq 'domain') {
1.161 bisitz 1614: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID'))
1615: .&forceid_change($context)
1616: .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
1.5 raeburn 1617: }
1.95 bisitz 1618:
1619: $Str .= &Apache::lonhtmlcommon::end_pick_box();
1.73 bisitz 1620: $Str .= '</div>';
1.95 bisitz 1621:
1622: # Footer
1623: $Str .= '<div class="LC_clear_float_footer">'
1624: .'<hr />';
1.1 raeburn 1625: if ($context eq 'course') {
1.95 bisitz 1626: $Str .= '<p class="LC_info">'
1.103 raeburn 1627: .&mt('Note: This operation may be time consuming when adding several users.')
1.95 bisitz 1628: .'</p>';
1.73 bisitz 1629: }
1.95 bisitz 1630: $Str .= '<p><input type="button"'
1.96 bisitz 1631: .' onclick="javascript:verify(this.form,this.form.csec)"'
1632: .' value="'.&mt('Update Users').'" />'
1.95 bisitz 1633: .'</p>'."\n"
1.73 bisitz 1634: .'</div>';
1.1 raeburn 1635: $r->print($Str);
1636: return;
1637: }
1638:
1.150 raeburn 1639: sub get_defaultcredits {
1640: my ($cdom,$cnum) = @_;
1641:
1642: if ($cdom eq '' || $cnum eq '') {
1643: return unless ($env{'request.course.id'});
1644: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1645: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1646: }
1647: return unless(($cdom =~ /^$match_domain$/) && ($cnum =~ /^$match_courseid$/));
1648: my ($defaultcredits,$domdefcredits);
1649: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
1.160 raeburn 1650: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
1.150 raeburn 1651: my $instcode = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
1652: if ($instcode) {
1653: $domdefcredits = $domdefaults{'officialcredits'};
1.160 raeburn 1654: } elsif ($env{'course.'.$cdom.'_'.$cnum.'.internal.textbook'}) {
1655: $domdefcredits = $domdefaults{'textbookcredits'};
1.150 raeburn 1656: } else {
1657: $domdefcredits = $domdefaults{'unofficialcredits'};
1658: }
1659: } else {
1660: return;
1661: }
1662:
1663: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
1664: $defaultcredits = $env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'};
1665: } elsif (exists($env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'})) {
1666: $defaultcredits = $env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'};
1667: } else {
1668: my %crsinfo =
1669: &Apache::lonnet::coursedescription("$cdom/$cnum",{'one_time' => 1});
1670: $defaultcredits = $crsinfo{'internal.defaultcredits'};
1671: }
1672: if ($defaultcredits eq '') {
1673: $defaultcredits = $domdefcredits;
1674: }
1675: return $defaultcredits;
1676: }
1677:
1.5 raeburn 1678: sub forceid_change {
1679: my ($context) = @_;
1680: my $output =
1.161 bisitz 1681: '<label><input type="checkbox" name="forceid" value="yes" />'
1.164 bisitz 1682: .&mt('Force change of existing ID')
1.163 raeburn 1683: .'</label>'.&Apache::loncommon::help_open_topic('ForceIDChange')."\n";
1.5 raeburn 1684: if ($context eq 'domain') {
1.163 raeburn 1685: $output .=
1686: '<br />'
1687: .'<label><input type="checkbox" name="recurseid" value="yes" />'
1688: .&mt("Update ID in user's course(s).").'</label>'."\n";
1.5 raeburn 1689: }
1690: return $output;
1691: }
1692:
1.1 raeburn 1693: ###############################################################
1694: ###############################################################
1695: sub print_upload_manager_form {
1.150 raeburn 1696: my ($r,$context,$permission,$crstype,$showcredits) = @_;
1.1 raeburn 1697: my $firstLine;
1698: my $datatoken;
1699: if (!$env{'form.datatoken'}) {
1700: $datatoken=&Apache::loncommon::upfile_store($r);
1701: } else {
1.189 raeburn 1702: $datatoken=&Apache::loncommon::valid_datatoken($env{'form.datatoken'});
1703: if ($datatoken ne '') {
1704: &Apache::loncommon::load_tmp_file($r,$datatoken);
1705: }
1.1 raeburn 1706: }
1.193 raeburn 1707: if ($datatoken eq '') {
1708: $r->print('<p class="LC_error">'.&mt('Error').': '.
1709: &mt('Invalid datatoken').'</p>');
1710: return 'missingdata';
1711: }
1.1 raeburn 1712: my @records=&Apache::loncommon::upfile_record_sep();
1713: if($env{'form.noFirstLine'}){
1714: $firstLine=shift(@records);
1715: }
1716: my $total=$#records;
1717: my $distotal=$total+1;
1718: my $today=time;
1719: my $halfyear=$today+15552000;
1720: #
1721: # Restore memorized settings
1722: my $col_setting_names = { 'username_choice' => 'scalar', # column settings
1723: 'names_choice' => 'scalar',
1724: 'fname_choice' => 'scalar',
1725: 'mname_choice' => 'scalar',
1726: 'lname_choice' => 'scalar',
1727: 'gen_choice' => 'scalar',
1728: 'id_choice' => 'scalar',
1729: 'sec_choice' => 'scalar',
1730: 'ipwd_choice' => 'scalar',
1731: 'email_choice' => 'scalar',
1732: 'role_choice' => 'scalar',
1.57 raeburn 1733: 'domain_choice' => 'scalar',
1.84 raeburn 1734: 'inststatus_choice' => 'scalar',
1.1 raeburn 1735: };
1.150 raeburn 1736: if ($showcredits) {
1737: $col_setting_names->{'credits_choice'} = 'scalar';
1738: }
1.1 raeburn 1739: if ($context eq 'course') {
1740: &Apache::loncommon::restore_course_settings('enrollment_upload',
1741: $col_setting_names);
1742: } else {
1743: &Apache::loncommon::restore_settings($context,'user_upload',
1744: $col_setting_names);
1745: }
1.150 raeburn 1746: my $defdom = $env{'request.role.domain'};
1.1 raeburn 1747: #
1748: # Determine kerberos parameters as appropriate
1749: my ($krbdef,$krbdefdom) =
1750: &Apache::loncommon::get_kerberos_defaults($defdom);
1751: #
1.123 raeburn 1752: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($defdom);
1.22 raeburn 1753: &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
1.123 raeburn 1754: $permission,$crstype,\%can_assign);
1.1 raeburn 1755: my $i;
1756: my $keyfields;
1757: if ($total>=0) {
1758: my @field=
1759: (['username',&mt('Username'), $env{'form.username_choice'}],
1760: ['names',&mt('Last Name, First Names'),$env{'form.names_choice'}],
1761: ['fname',&mt('First Name'), $env{'form.fname_choice'}],
1762: ['mname',&mt('Middle Names/Initials'),$env{'form.mname_choice'}],
1763: ['lname',&mt('Last Name'), $env{'form.lname_choice'}],
1764: ['gen', &mt('Generation'), $env{'form.gen_choice'}],
1.61 bisitz 1765: ['id', &mt('Student/Employee ID'),$env{'form.id_choice'}],
1.1 raeburn 1766: ['sec', &mt('Section'), $env{'form.sec_choice'}],
1767: ['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
1768: ['email',&mt('E-mail Address'), $env{'form.email_choice'}],
1.57 raeburn 1769: ['role',&mt('Role'), $env{'form.role_choice'}],
1.84 raeburn 1770: ['domain',&mt('Domain'), $env{'form.domain_choice'}],
1771: ['inststatus',&mt('Affiliation'), $env{'form.inststatus_choice'}]);
1.150 raeburn 1772: if ($showcredits) {
1773: push(@field,
1774: ['credits',&mt('Student Credits'), $env{'form.credits_choice'}]);
1775: }
1.1 raeburn 1776: if ($env{'form.upfile_associate'} eq 'reverse') {
1777: &Apache::loncommon::csv_print_samples($r,\@records);
1778: $i=&Apache::loncommon::csv_print_select_table($r,\@records,
1779: \@field);
1780: foreach (@field) {
1781: $keyfields.=$_->[0].',';
1782: }
1783: chop($keyfields);
1784: } else {
1785: unshift(@field,['none','']);
1786: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
1787: \@field);
1788: my %sone=&Apache::loncommon::record_sep($records[0]);
1789: $keyfields=join(',',sort(keys(%sone)));
1790: }
1791: }
1792: &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
1.150 raeburn 1793: $context,$permission,$crstype,$showcredits);
1.193 raeburn 1794: return 'ok';
1.1 raeburn 1795: }
1796:
1797: sub setup_date_selectors {
1.22 raeburn 1798: my ($starttime,$endtime,$mode,$nolink,$formname) = @_;
1799: if ($formname eq '') {
1800: $formname = 'studentform';
1801: }
1.1 raeburn 1802: if (! defined($starttime)) {
1803: $starttime = time;
1804: unless ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1805: if (exists($env{'course.'.$env{'request.course.id'}.
1806: '.default_enrollment_start_date'})) {
1807: $starttime = $env{'course.'.$env{'request.course.id'}.
1808: '.default_enrollment_start_date'};
1809: }
1810: }
1811: }
1812: if (! defined($endtime)) {
1813: $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1814: unless ($mode eq 'createcourse') {
1815: if (exists($env{'course.'.$env{'request.course.id'}.
1816: '.default_enrollment_end_date'})) {
1817: $endtime = $env{'course.'.$env{'request.course.id'}.
1818: '.default_enrollment_end_date'};
1819: }
1820: }
1821: }
1.11 raeburn 1822:
1823: my $startdateform =
1.22 raeburn 1824: &Apache::lonhtmlcommon::date_setter($formname,'startdate',$starttime,
1.11 raeburn 1825: undef,undef,undef,undef,undef,undef,undef,$nolink);
1826:
1827: my $enddateform =
1.22 raeburn 1828: &Apache::lonhtmlcommon::date_setter($formname,'enddate',$endtime,
1.11 raeburn 1829: undef,undef,undef,undef,undef,undef,undef,$nolink);
1830:
1.1 raeburn 1831: if ($mode eq 'create_enrolldates') {
1832: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1833: 'startenroll',
1834: $starttime);
1835: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1836: 'endenroll',
1837: $endtime);
1838: }
1839: if ($mode eq 'create_defaultdates') {
1840: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1841: 'startaccess',
1842: $starttime);
1843: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1844: 'endaccess',
1845: $endtime);
1846: }
1847: return ($startdateform,$enddateform);
1848: }
1849:
1850:
1851: sub get_dates_from_form {
1.54 raeburn 1852: my ($startname,$endname) = @_;
1853: if ($startname eq '') {
1854: $startname = 'startdate';
1855: }
1856: if ($endname eq '') {
1857: $endname = 'enddate';
1858: }
1859: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
1860: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.1 raeburn 1861: if ($env{'form.no_end_date'}) {
1862: $enddate = 0;
1863: }
1864: return ($startdate,$enddate);
1865: }
1866:
1867: sub date_setting_table {
1.101 raeburn 1868: my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission,$crstype) = @_;
1.11 raeburn 1869: my $nolink;
1870: if ($bulkaction) {
1871: $nolink = 1;
1872: }
1873: my ($startform,$endform) =
1.22 raeburn 1874: &setup_date_selectors($starttime,$endtime,$mode,$nolink,$formname);
1.1 raeburn 1875: my $dateDefault;
1876: if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1877: $dateDefault = ' ';
1.13 raeburn 1878: } elsif ($mode ne 'author' && $mode ne 'domain') {
1.11 raeburn 1879: if (($bulkaction eq 'reenable') ||
1880: ($bulkaction eq 'activate') ||
1.22 raeburn 1881: ($bulkaction eq 'chgdates') ||
1882: ($env{'form.action'} eq 'upload')) {
1883: if ($env{'request.course.sec'} eq '') {
1884: $dateDefault = '<span class="LC_nobreak">'.
1.101 raeburn 1885: '<label><input type="checkbox" name="makedatesdefault" value="1" /> ';
1886: if ($crstype eq 'Community') {
1887: $dateDefault .= &mt("make these dates the default access dates for future community enrollment");
1888: } else {
1889: $dateDefault .= &mt("make these dates the default access dates for future course enrollment");
1890: }
1891: $dateDefault .= '</label></span>';
1.22 raeburn 1892: }
1.11 raeburn 1893: }
1.1 raeburn 1894: }
1.11 raeburn 1895: my $perpetual = '<span class="LC_nobreak"><label><input type="checkbox" name="no_end_date"';
1.1 raeburn 1896: if (defined($endtime) && $endtime == 0) {
1.70 bisitz 1897: $perpetual .= ' checked="checked"';
1.1 raeburn 1898: }
1.11 raeburn 1899: $perpetual.= ' /> '.&mt('no ending date').'</label></span>';
1.1 raeburn 1900: if ($mode eq 'create_enrolldates') {
1901: $perpetual = ' ';
1902: }
1.11 raeburn 1903: my $result = &Apache::lonhtmlcommon::start_pick_box()."\n";
1904: $result .= &Apache::lonhtmlcommon::row_title(&mt('Starting Date'),
1905: 'LC_oddrow_value')."\n".
1906: $startform."\n".
1907: &Apache::lonhtmlcommon::row_closure(1).
1908: &Apache::lonhtmlcommon::row_title(&mt('Ending Date'),
1909: 'LC_oddrow_value')."\n".
1910: $endform.' '.$perpetual.
1911: &Apache::lonhtmlcommon::row_closure(1).
1.22 raeburn 1912: &Apache::lonhtmlcommon::end_pick_box();
1.1 raeburn 1913: if ($dateDefault) {
1914: $result .= $dateDefault.'<br />'."\n";
1915: }
1916: return $result;
1917: }
1918:
1919: sub make_dates_default {
1.101 raeburn 1920: my ($startdate,$enddate,$context,$crstype) = @_;
1.1 raeburn 1921: my $result = '';
1922: if ($context eq 'course') {
1.17 raeburn 1923: my ($cnum,$cdom) = &get_course_identity();
1.1 raeburn 1924: my $put_result = &Apache::lonnet::put('environment',
1925: {'default_enrollment_start_date'=>$startdate,
1.17 raeburn 1926: 'default_enrollment_end_date' =>$enddate},$cdom,$cnum);
1.1 raeburn 1927: if ($put_result eq 'ok') {
1.101 raeburn 1928: if ($crstype eq 'Community') {
1929: $result .= &mt('Set default start and end access dates for community.');
1930: } else {
1931: $result .= &mt('Set default start and end access dates for course.');
1932: }
1933: $result .= '<br />'."\n";
1.1 raeburn 1934: #
1935: # Refresh the course environment
1936: &Apache::lonnet::coursedescription($env{'request.course.id'},
1937: {'freshen_cache' => 1});
1938: } else {
1.101 raeburn 1939: if ($crstype eq 'Community') {
1940: $result .= &mt('Unable to set default access dates for community');
1941: } else {
1942: $result .= &mt('Unable to set default access dates for course');
1943: }
1944: $result .= ':'.$put_result.'<br />';
1.1 raeburn 1945: }
1946: }
1947: return $result;
1948: }
1949:
1950: sub default_role_selector {
1.150 raeburn 1951: my ($context,$checkpriv,$crstype,$showcredits) = @_;
1.1 raeburn 1952: my %customroles;
1953: my ($options,$coursepick,$cb_jscript);
1.13 raeburn 1954: if ($context ne 'author') {
1.104 raeburn 1955: %customroles = &my_custom_roles($crstype);
1.1 raeburn 1956: }
1957:
1958: my %lt=&Apache::lonlocal::texthash(
1959: 'rol' => "Role",
1960: 'grs' => "Section",
1961: 'exs' => "Existing sections",
1962: 'new' => "New section",
1.150 raeburn 1963: 'crd' => "Credits",
1.1 raeburn 1964: );
1965: $options = '<select name="defaultrole">'."\n".
1966: ' <option value="">'.&mt('Please select').'</option>'."\n";
1967: if ($context eq 'course') {
1.101 raeburn 1968: $options .= &default_course_roles($context,$checkpriv,$crstype,%customroles);
1.13 raeburn 1969: } elsif ($context eq 'author') {
1.2 raeburn 1970: my @roles = &construction_space_roles($checkpriv);
1.1 raeburn 1971: foreach my $role (@roles) {
1972: my $plrole=&Apache::lonnet::plaintext($role);
1973: $options .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1974: }
1975: } elsif ($context eq 'domain') {
1.2 raeburn 1976: my @roles = &domain_roles($checkpriv);
1.1 raeburn 1977: foreach my $role (@roles) {
1978: my $plrole=&Apache::lonnet::plaintext($role);
1979: $options .= ' <option value="'.$role.'">'.$plrole.'</option>';
1980: }
1981: my $courseform = &Apache::loncommon::selectcourse_link
1.103 raeburn 1982: ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course/Community');
1.150 raeburn 1983: my ($credit_elem,$creditsinput);
1984: if ($showcredits) {
1985: $credit_elem = 'credits';
1986: $creditsinput = '<td><input type="text" name="credits" value="" /></td>';
1987: }
1.1 raeburn 1988: $cb_jscript =
1.150 raeburn 1989: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform','courserole','Course/Community',$credit_elem);
1.1 raeburn 1990: $coursepick = &Apache::loncommon::start_data_table().
1991: &Apache::loncommon::start_data_table_header_row().
1992: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th>'.
1993: '<th>'.$lt{'grs'}.'</th>'.
1.150 raeburn 1994: '<th>'.$lt{'crd'}.'</th>'.
1.1 raeburn 1995: &Apache::loncommon::end_data_table_header_row().
1996: &Apache::loncommon::start_data_table_row()."\n".
1.103 raeburn 1997: '<td><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'studentform','dccourse','dcdomain','coursedesc','','','','crstype'".')" /></td>'."\n".
1.1 raeburn 1998: '<td><select name="courserole">'."\n".
1.101 raeburn 1999: &default_course_roles($context,$checkpriv,'Course',%customroles)."\n".
1.1 raeburn 2000: '</select></td><td>'.
2001: '<table class="LC_createuser">'.
1.162 bisitz 2002: '<tr class="LC_section_row"><td valign="top">'.
1.22 raeburn 2003: $lt{'exs'}.'<br /><select name="currsec">'.
1.162 bisitz 2004: ' <option value=""><--'.&mt('Pick course first').
1.1 raeburn 2005: '</select></td>'.
2006: '<td> </td>'.
2007: '<td valign="top">'.$lt{'new'}.'<br />'.
2008: '<input type="text" name="newsec" value="" size="5" />'.
1.22 raeburn 2009: '<input type="hidden" name="groups" value="" />'.
2010: '<input type="hidden" name="sections" value="" />'.
2011: '<input type="hidden" name="origdom" value="'.
2012: $env{'request.role.domain'}.'" />'.
2013: '<input type="hidden" name="dccourse" value="" />'.
2014: '<input type="hidden" name="dcdomain" value="" />'.
1.103 raeburn 2015: '<input type="hidden" name="crstype" value="" />'.
1.150 raeburn 2016: '</td></tr></table></td>'.$creditsinput.
1.1 raeburn 2017: &Apache::loncommon::end_data_table_row().
1.22 raeburn 2018: &Apache::loncommon::end_data_table()."\n";
1.1 raeburn 2019: }
2020: $options .= '</select>';
2021: return ($options,$cb_jscript,$coursepick);
2022: }
2023:
2024: sub default_course_roles {
1.101 raeburn 2025: my ($context,$checkpriv,$crstype,%customroles) = @_;
1.1 raeburn 2026: my $output;
1.17 raeburn 2027: my $custom = 1;
1.101 raeburn 2028: my @roles = &course_roles($context,$checkpriv,$custom,lc($crstype));
1.1 raeburn 2029: foreach my $role (@roles) {
1.22 raeburn 2030: if ($role ne 'cr') {
1.101 raeburn 2031: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.22 raeburn 2032: $output .= ' <option value="'.$role.'">'.$plrole.'</option>';
2033: }
1.1 raeburn 2034: }
2035: if (keys(%customroles) > 0) {
1.22 raeburn 2036: if (grep(/^cr$/,@roles)) {
2037: foreach my $cust (sort(keys(%customroles))) {
2038: my $custrole='cr_'.$env{'user.domain'}.
2039: '_'.$env{'user.name'}.'_'.$cust;
2040: $output .= ' <option value="'.$custrole.'">'.$cust.'</option>';
2041: }
1.1 raeburn 2042: }
2043: }
2044: return $output;
2045: }
2046:
2047: sub construction_space_roles {
1.2 raeburn 2048: my ($checkpriv) = @_;
1.17 raeburn 2049: my @allroles = &roles_by_context('author');
1.1 raeburn 2050: my @roles;
1.2 raeburn 2051: if ($checkpriv) {
2052: foreach my $role (@allroles) {
2053: if (&Apache::lonnet::allowed('c'.$role,$env{'user.domain'}.'/'.$env{'user.name'})) {
2054: push(@roles,$role);
1.218 raeburn 2055: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2056: my ($audom,$auname) = ($1,$2);
2057: if (($role eq 'ca') || ($role eq 'aa')) {
2058: if ((&Apache::lonnet::allowed('v'.$role,,$audom.'/'.$auname)) &&
2059: ($env{"environment.internal.manager./$audom/$auname"})) {
2060: push(@roles,$role);
2061: }
2062: }
1.2 raeburn 2063: }
1.1 raeburn 2064: }
1.2 raeburn 2065: return @roles;
2066: } else {
2067: return @allroles;
1.1 raeburn 2068: }
2069: }
2070:
2071: sub domain_roles {
1.2 raeburn 2072: my ($checkpriv) = @_;
1.17 raeburn 2073: my @allroles = &roles_by_context('domain');
1.1 raeburn 2074: my @roles;
1.2 raeburn 2075: if ($checkpriv) {
2076: foreach my $role (@allroles) {
2077: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
2078: push(@roles,$role);
2079: }
1.1 raeburn 2080: }
1.2 raeburn 2081: return @roles;
2082: } else {
2083: return @allroles;
1.1 raeburn 2084: }
2085: }
2086:
2087: sub course_roles {
1.101 raeburn 2088: my ($context,$checkpriv,$custom,$roletype) = @_;
1.102 raeburn 2089: my $crstype;
2090: if ($roletype eq 'community') {
2091: $crstype = 'Community' ;
2092: } else {
2093: $crstype = 'Course';
2094: }
2095: my @allroles = &roles_by_context('course',$custom,$crstype);
1.1 raeburn 2096: my @roles;
2097: if ($context eq 'domain') {
2098: @roles = @allroles;
2099: } elsif ($context eq 'course') {
2100: if ($env{'request.course.id'}) {
1.2 raeburn 2101: if ($checkpriv) {
2102: foreach my $role (@allroles) {
2103: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
2104: push(@roles,$role);
2105: } else {
1.101 raeburn 2106: if ((($role ne 'cc') && ($role ne 'co')) && ($env{'request.course.sec'} ne '')) {
1.22 raeburn 2107: if (&Apache::lonnet::allowed('c'.$role,
1.2 raeburn 2108: $env{'request.course.id'}.'/'.
1.22 raeburn 2109: $env{'request.course.sec'})) {
1.2 raeburn 2110: push(@roles,$role);
2111: }
1.1 raeburn 2112: }
2113: }
2114: }
1.2 raeburn 2115: } else {
2116: @roles = @allroles;
1.1 raeburn 2117: }
2118: }
2119: }
2120: return @roles;
2121: }
2122:
2123: sub curr_role_permissions {
1.101 raeburn 2124: my ($context,$setting,$checkpriv,$type) = @_;
1.17 raeburn 2125: my $custom = 1;
1.1 raeburn 2126: my @roles;
1.13 raeburn 2127: if ($context eq 'author') {
1.2 raeburn 2128: @roles = &construction_space_roles($checkpriv);
1.1 raeburn 2129: } elsif ($context eq 'domain') {
2130: if ($setting eq 'course') {
1.101 raeburn 2131: @roles = &course_roles($context,$checkpriv,$custom,$type);
1.1 raeburn 2132: } else {
1.2 raeburn 2133: @roles = &domain_roles($checkpriv);
1.1 raeburn 2134: }
2135: } elsif ($context eq 'course') {
1.101 raeburn 2136: @roles = &course_roles($context,$checkpriv,$custom,$type);
1.1 raeburn 2137: }
2138: return @roles;
2139: }
2140:
2141: # ======================================================= Existing Custom Roles
2142:
2143: sub my_custom_roles {
1.175 raeburn 2144: my ($crstype,$udom,$uname) = @_;
1.1 raeburn 2145: my %returnhash=();
1.137 raeburn 2146: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
1.175 raeburn 2147: my %rolehash=&Apache::lonnet::dump('roles',$udom,$uname);
1.104 raeburn 2148: foreach my $key (keys(%rolehash)) {
1.1 raeburn 2149: if ($key=~/^rolesdef\_(\w+)$/) {
1.207 raeburn 2150: my $role = $1;
1.104 raeburn 2151: if ($crstype eq 'Community') {
2152: next if ($rolehash{$key} =~ /bre\&S/);
2153: }
1.207 raeburn 2154: $returnhash{$role}=$role;
1.1 raeburn 2155: }
2156: }
2157: return %returnhash;
2158: }
2159:
1.2 raeburn 2160: sub print_userlist {
2161: my ($r,$mode,$permission,$context,$formname,$totcodes,$codetitles,
1.150 raeburn 2162: $idlist,$idlist_titles,$showcredits) = @_;
1.2 raeburn 2163: my $format = $env{'form.output'};
1.1 raeburn 2164: if (! exists($env{'form.sortby'})) {
2165: $env{'form.sortby'} = 'username';
2166: }
1.2 raeburn 2167: if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
2168: $env{'form.Status'} = 'Active';
1.1 raeburn 2169: }
1.140 raeburn 2170: my $onchange = "javascript:updateCols('Status');";
1.1 raeburn 2171: my $status_select = &Apache::lonhtmlcommon::StatusOptions
1.140 raeburn 2172: ($env{'form.Status'},undef,undef,$onchange);
1.1 raeburn 2173:
1.2 raeburn 2174: if ($env{'form.showrole'} eq '') {
1.13 raeburn 2175: if ($context eq 'course') {
2176: $env{'form.showrole'} = 'st';
2177: } else {
2178: $env{'form.showrole'} = 'Any';
2179: }
1.2 raeburn 2180: }
1.1 raeburn 2181: if (! defined($env{'form.output'}) ||
2182: $env{'form.output'} !~ /^(csv|excel|html)$/ ) {
2183: $env{'form.output'} = 'html';
2184: }
2185:
1.2 raeburn 2186: my @statuses;
2187: if ($env{'form.Status'} eq 'Any') {
2188: @statuses = ('previous','active','future');
2189: } elsif ($env{'form.Status'} eq 'Expired') {
2190: @statuses = ('previous');
2191: } elsif ($env{'form.Status'} eq 'Active') {
2192: @statuses = ('active');
2193: } elsif ($env{'form.Status'} eq 'Future') {
2194: @statuses = ('future');
2195: }
1.1 raeburn 2196:
2197: # Interface output
1.2 raeburn 2198: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
2199: '<input type="hidden" name="action" value="'.
1.1 raeburn 2200: $env{'form.action'}.'" />');
1.140 raeburn 2201: $r->print('<div>'."\n");
1.1 raeburn 2202: if ($env{'form.action'} ne 'modifystudent') {
2203: my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
2204: 'excel' => "Excel",
2205: 'html' => 'HTML');
1.140 raeburn 2206: my $output_selector = '<select size="1" name="output" onchange="javascript:updateCols('."'output'".');" >';
1.1 raeburn 2207: foreach my $outputformat ('html','csv','excel') {
1.96 bisitz 2208: my $option = '<option value="'.$outputformat.'"';
1.1 raeburn 2209: if ($outputformat eq $env{'form.output'}) {
1.96 bisitz 2210: $option .= ' selected="selected"';
1.1 raeburn 2211: }
2212: $option .='>'.$lt{$outputformat}.'</option>';
2213: $output_selector .= "\n".$option;
2214: }
2215: $output_selector .= '</select>';
1.140 raeburn 2216: $r->print('<span class="LC_nobreak">'
1.70 bisitz 2217: .&mt('Output Format: [_1]',$output_selector)
1.140 raeburn 2218: .'</span>'.(' 'x3));
1.70 bisitz 2219: }
1.140 raeburn 2220: $r->print('<span class="LC_nobreak">'
1.70 bisitz 2221: .&mt('User Status: [_1]',$status_select)
1.140 raeburn 2222: .'</span>'.(' 'x3)."\n");
1.2 raeburn 2223: my $roleselected = '';
2224: if ($env{'form.showrole'} eq 'Any') {
1.91 bisitz 2225: $roleselected = ' selected="selected"';
1.2 raeburn 2226: }
1.53 raeburn 2227: my ($cnum,$cdom);
2228: $r->print(&role_filter($context));
2229: if ($context eq 'course') {
2230: ($cnum,$cdom) = &get_course_identity();
2231: $r->print(§ion_group_filter($cnum,$cdom));
1.2 raeburn 2232: }
1.140 raeburn 2233: $r->print('</div><div class="LC_left_float">'.
1.150 raeburn 2234: &column_checkboxes($context,$mode,$formname,$showcredits).
1.149 raeburn 2235: '</div>');
1.78 raeburn 2236: if ($env{'form.phase'} eq '') {
1.149 raeburn 2237: $r->print('<br clear="all" />'.
2238: &list_submit_button(&mt('Display List of Users'))."\n".
1.78 raeburn 2239: '<input type="hidden" name="phase" value="" /></form>');
2240: return;
2241: }
1.106 raeburn 2242: if (!(($context eq 'domain') &&
2243: (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
1.149 raeburn 2244: $r->print('<br clear="all" />'.
2245: &list_submit_button(&mt('Update Display'))."\n");
1.140 raeburn 2246: }
2247:
1.150 raeburn 2248: my @cols = &infocolumns($context,$mode,$showcredits);
1.140 raeburn 2249: if (!@cols) {
1.152 bisitz 2250: $r->print('<hr style="clear:both;" /><span class="LC_warning">'.
1.140 raeburn 2251: &mt('No user information selected for display.').'</span>'.
2252: '<input type="hidden" name="phase" value="display" /></form>'."\n");
2253: return;
1.2 raeburn 2254: }
2255: my ($indexhash,$keylist) = &make_keylist_array();
1.159 raeburn 2256: my (%userlist,%userinfo,$clearcoursepick,$needauthorquota,$needauthorusage);
1.102 raeburn 2257: if (($context eq 'domain') &&
2258: ($env{'form.roletype'} eq 'course') ||
2259: ($env{'form.roletype'} eq 'community')) {
2260: my ($crstype,$numcodes,$title,$warning);
2261: if ($env{'form.roletype'} eq 'course') {
2262: $crstype = 'Course';
2263: $numcodes = $totcodes;
2264: $title = &mt('Select Courses');
2265: $warning = &mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.');
2266: } elsif ($env{'form.roletype'} eq 'community') {
2267: $crstype = 'Community';
2268: $numcodes = 0;
2269: $title = &mt('Select Communities');
2270: $warning = &mt('Warning: data retrieval for multiple communities can take considerable time, as this operation is not currently optimized.');
2271: }
1.120 raeburn 2272: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1.3 raeburn 2273: my $courseform =
1.102 raeburn 2274: &Apache::lonhtmlcommon::course_selection($formname,$numcodes,
1.120 raeburn 2275: $codetitles,$idlist,$idlist_titles,$crstype,
2276: \@standardnames);
1.148 bisitz 2277: $r->print('<div class="LC_left_float">'.
2278: '<fieldset><legend>'.$title.'</legend>'."\n".
1.3 raeburn 2279: $courseform."\n".
1.148 bisitz 2280: '</fieldset></div><br clear="all" />'.
1.106 raeburn 2281: '<p><input type="hidden" name="origroletype" value="'.$env{'form.roletype'}.'" />'.
2282: &list_submit_button(&mt('Update Display')).
1.102 raeburn 2283: "\n".'</p><span class="LC_warning">'.$warning.'</span>'."\n");
1.106 raeburn 2284: $clearcoursepick = 0;
2285: if (($env{'form.origroletype'} ne '') &&
2286: ($env{'form.origroletype'} ne $env{'form.roletype'})) {
2287: $clearcoursepick = 1;
2288: }
2289: if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
1.147 bisitz 2290: $r->print('<hr />'.&mt('Searching ...').'<br /> <br />');
1.11 raeburn 2291: }
2292: } else {
1.152 bisitz 2293: $r->print('<hr style="clear:both;" /><div id="searching">'.&mt('Searching ...').'</div>');
1.3 raeburn 2294: }
2295: $r->rflush();
1.1 raeburn 2296: if ($context eq 'course') {
1.46 raeburn 2297: if (($env{'form.showrole'} eq 'st') || ($env{'form.showrole'} eq 'Any')) {
1.45 raeburn 2298: my $classlist = &Apache::loncoursedata::get_classlist();
1.66 raeburn 2299: if (ref($classlist) eq 'HASH') {
2300: %userlist = %{$classlist};
2301: }
1.45 raeburn 2302: }
1.43 raeburn 2303: if ($env{'form.showrole'} ne 'st') {
2304: my $showroles;
2305: if ($env{'form.showrole'} ne 'Any') {
2306: $showroles = [$env{'form.showrole'}];
1.3 raeburn 2307: } else {
1.43 raeburn 2308: $showroles = undef;
1.1 raeburn 2309: }
1.43 raeburn 2310: my $withsec = 1;
2311: my $hidepriv = 1;
2312: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
2313: \@statuses,$showroles,undef,$withsec,$hidepriv);
2314: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
2315: \%advrolehash,$permission);
1.1 raeburn 2316: }
1.2 raeburn 2317: } else {
2318: my (%cstr_roles,%dom_roles);
1.13 raeburn 2319: if ($context eq 'author') {
1.218 raeburn 2320: my @possroles = &roles_by_context($context);
2321: my @allowedroles;
1.2 raeburn 2322: # List co-authors and assistant co-authors
1.218 raeburn 2323: my ($auname,$audom);
2324: if ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2325: ($audom,$auname) = ($1,$2);
2326: foreach my $role (@possroles) {
2327: if ((&Apache::lonnet::allowed('v'.$role,"$audom/$auname")) ||
2328: (&Apache::lonnet::allowed('c'.$role,"$audom/$auname"))) {
2329: push(@allowedroles,$role);
2330: }
2331: }
2332: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
2333: if ($1 eq $env{'user.domain'}) {
2334: $auname = $env{'user.name'};
2335: $audom = $env{'user.domain'};
2336: }
2337: @allowedroles = @possroles;
2338: }
2339: if (($auname ne '') && ($audom ne '')) {
2340: %cstr_roles = &Apache::lonnet::get_my_roles($auname,$audom,undef,
2341: \@statuses,\@allowedroles);
2342: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
2343: \%cstr_roles,$permission);
2344: }
1.2 raeburn 2345: } elsif ($context eq 'domain') {
2346: if ($env{'form.roletype'} eq 'domain') {
1.159 raeburn 2347: if (grep(/^authorusage$/,@cols)) {
2348: $needauthorusage = 1;
2349: }
2350: if (grep(/^authorquota$/,@cols)) {
2351: $needauthorquota = 1;
2352: }
1.2 raeburn 2353: %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'});
2354: foreach my $key (keys(%dom_roles)) {
2355: if (ref($dom_roles{$key}) eq 'HASH') {
2356: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 2357: \%userinfo,$dom_roles{$key},$permission);
1.2 raeburn 2358: }
2359: }
1.13 raeburn 2360: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 2361: my %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'},['au']);
2362: my %coauthors;
2363: foreach my $key (keys(%dom_roles)) {
2364: if (ref($dom_roles{$key}) eq 'HASH') {
2365: if ($env{'form.showrole'} eq 'au') {
2366: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 2367: \%userinfo,$dom_roles{$key},$permission);
1.2 raeburn 2368: } else {
2369: my @possroles;
2370: if ($env{'form.showrole'} eq 'Any') {
1.22 raeburn 2371: @possroles = &roles_by_context('author');
1.2 raeburn 2372: } else {
2373: @possroles = ($env{'form.showrole'});
2374: }
2375: foreach my $author (sort(keys(%{$dom_roles{$key}}))) {
1.22 raeburn 2376: my ($role,$authorname,$authordom) = split(/:/,$author,-1);
1.2 raeburn 2377: my $extent = '/'.$authordom.'/'.$authorname;
2378: %{$coauthors{$extent}} =
2379: &Apache::lonnet::get_my_roles($authorname,
2380: $authordom,undef,\@statuses,\@possroles);
2381: }
2382: &gather_userinfo($context,$format,\%userlist,
1.11 raeburn 2383: $indexhash,\%userinfo,\%coauthors,$permission);
1.2 raeburn 2384: }
2385: }
2386: }
1.101 raeburn 2387: } elsif (($env{'form.roletype'} eq 'course') ||
2388: ($env{'form.roletype'} eq 'community')) {
1.106 raeburn 2389: if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
1.2 raeburn 2390: my %courses = &process_coursepick();
1.39 raeburn 2391: my %allusers;
2392: my $hidepriv = 1;
1.2 raeburn 2393: foreach my $cid (keys(%courses)) {
1.17 raeburn 2394: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
1.11 raeburn 2395: next if ($cnum eq '' || $cdom eq '');
1.17 raeburn 2396: my $custom = 1;
1.2 raeburn 2397: my (@roles,@sections,%access,%users,%userdata,
1.6 albertel 2398: %statushash);
1.2 raeburn 2399: if ($env{'form.showrole'} eq 'Any') {
1.101 raeburn 2400: @roles = &course_roles($context,undef,$custom,
2401: $env{'form.roletype'});
1.2 raeburn 2402: } else {
2403: @roles = ($env{'form.showrole'});
2404: }
2405: foreach my $role (@roles) {
2406: %{$users{$role}} = ();
2407: }
2408: foreach my $type (@statuses) {
2409: $access{$type} = $type;
2410: }
1.39 raeburn 2411: &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash,$hidepriv);
1.2 raeburn 2412: foreach my $user (keys(%userdata)) {
2413: next if (ref($userinfo{$user}) eq 'HASH');
2414: foreach my $item ('fullname','id') {
2415: $userinfo{$user}{$item} = $userdata{$user}[$indexhash->{$item}];
2416: }
2417: }
2418: foreach my $role (keys(%users)) {
2419: foreach my $user (keys(%{$users{$role}})) {
2420: my $uniqid = $user.':'.$role;
2421: $allusers{$uniqid}{$cid} = { desc => $cdesc,
2422: secs => $statushash{$user}{$role},
2423: };
2424: }
2425: }
2426: }
2427: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 2428: \%userinfo,\%allusers,$permission);
1.2 raeburn 2429: } else {
1.10 raeburn 2430: $r->print('<input type="hidden" name="phase" value="'.
2431: $env{'form.phase'}.'" /></form>');
1.2 raeburn 2432: return;
2433: }
1.1 raeburn 2434: }
2435: }
1.3 raeburn 2436: }
2437: if (keys(%userlist) == 0) {
1.142 bisitz 2438: my $msg = '';
1.13 raeburn 2439: if ($context eq 'author') {
1.142 bisitz 2440: $msg = &mt('There are no co-authors to display.');
1.3 raeburn 2441: } elsif ($context eq 'domain') {
2442: if ($env{'form.roletype'} eq 'domain') {
1.142 bisitz 2443: $msg = &mt('There are no users with domain roles to display.');
1.13 raeburn 2444: } elsif ($env{'form.roletype'} eq 'author') {
1.142 bisitz 2445: $msg = &mt('There are no authors or co-authors to display.');
1.3 raeburn 2446: } elsif ($env{'form.roletype'} eq 'course') {
1.142 bisitz 2447: $msg = &mt('There are no course users to display');
1.101 raeburn 2448: } elsif ($env{'form.roletype'} eq 'community') {
1.142 bisitz 2449: $msg = &mt('There are no community users to display');
1.2 raeburn 2450: }
1.3 raeburn 2451: } elsif ($context eq 'course') {
2452: $r->print(&mt('There are no course users to display.')."\n");
2453: }
1.148 bisitz 2454: $r->print('<p class="LC_info">'.$msg.'</p>'."\n") if $msg;
1.3 raeburn 2455: } else {
2456: # Print out the available choices
1.4 raeburn 2457: my $usercount;
1.3 raeburn 2458: if ($env{'form.action'} eq 'modifystudent') {
1.10 raeburn 2459: ($usercount) = &show_users_list($r,$context,'view',$permission,
1.150 raeburn 2460: $env{'form.Status'},\%userlist,$keylist,'',
2461: $showcredits);
1.1 raeburn 2462: } else {
1.4 raeburn 2463: ($usercount) = &show_users_list($r,$context,$env{'form.output'},
1.150 raeburn 2464: $permission,$env{'form.Status'},\%userlist,
1.159 raeburn 2465: $keylist,'',$showcredits,$needauthorquota,$needauthorusage);
1.4 raeburn 2466: }
2467: if (!$usercount) {
1.142 bisitz 2468: $r->print('<br /><span class="LC_info">'
1.72 bisitz 2469: .&mt('There are no users matching the search criteria.')
2470: .'</span>'
2471: );
1.2 raeburn 2472: }
2473: }
1.10 raeburn 2474: $r->print('<input type="hidden" name="phase" value="'.
2475: $env{'form.phase'}.'" /></form>');
1.140 raeburn 2476: return;
1.2 raeburn 2477: }
2478:
1.53 raeburn 2479: sub role_filter {
2480: my ($context) = @_;
2481: my $output;
2482: my $roleselected = '';
2483: if ($env{'form.showrole'} eq 'Any') {
1.91 bisitz 2484: $roleselected = ' selected="selected"';
1.53 raeburn 2485: }
2486: my ($role_select);
2487: if ($context eq 'domain') {
2488: $role_select = &domain_roles_select();
1.140 raeburn 2489: $output = '<span class="LC_nobreak">'
1.70 bisitz 2490: .&mt('Role Type: [_1]',$role_select)
1.140 raeburn 2491: .'</span>';
1.53 raeburn 2492: } else {
1.140 raeburn 2493: $role_select = '<select name="showrole" onchange="javascript:updateCols('."'showrole'".');">'."\n".
1.53 raeburn 2494: '<option value="Any" '.$roleselected.'>'.
2495: &mt('Any role').'</option>';
1.101 raeburn 2496: my ($roletype,$crstype);
2497: if ($context eq 'course') {
2498: $crstype = &Apache::loncommon::course_type();
2499: if ($crstype eq 'Community') {
2500: $roletype = 'community';
2501: } else {
2502: $roletype = 'course';
2503: }
2504: }
2505: my @poss_roles = &curr_role_permissions($context,'','',$roletype);
1.53 raeburn 2506: foreach my $role (@poss_roles) {
2507: $roleselected = '';
2508: if ($role eq $env{'form.showrole'}) {
1.91 bisitz 2509: $roleselected = ' selected="selected"';
1.53 raeburn 2510: }
2511: my $plrole;
2512: if ($role eq 'cr') {
2513: $plrole = &mt('Custom role');
2514: } else {
1.101 raeburn 2515: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.53 raeburn 2516: }
2517: $role_select .= '<option value="'.$role.'"'.$roleselected.'>'.$plrole.'</option>';
2518: }
2519: $role_select .= '</select>';
1.140 raeburn 2520: $output = '<span class="LC_nobreak">'
1.70 bisitz 2521: .&mt('Role: [_1]',$role_select)
1.140 raeburn 2522: .'</span>';
1.53 raeburn 2523: }
2524: return $output;
2525: }
2526:
1.33 raeburn 2527: sub section_group_filter {
2528: my ($cnum,$cdom) = @_;
2529: my @filters;
2530: if ($env{'request.course.sec'} eq '') {
2531: @filters = ('sec');
2532: }
2533: push(@filters,'grp');
2534: my %name = (
2535: sec => 'secfilter',
2536: grp => 'grpfilter',
2537: );
2538: my %title = &Apache::lonlocal::texthash (
2539: sec => 'Section(s)',
2540: grp => 'Group(s)',
2541: all => 'all',
2542: none => 'none',
2543: );
1.47 raeburn 2544: my $output;
1.33 raeburn 2545: foreach my $item (@filters) {
1.47 raeburn 2546: my ($markup,@options);
1.33 raeburn 2547: if ($env{'form.'.$name{$item}} eq '') {
2548: $env{'form.'.$name{$item}} = 'all';
2549: }
2550: if ($item eq 'sec') {
1.103 raeburn 2551: if (($env{'form.showrole'} eq 'cc') || ($env{'form.showrole'} eq 'co')) {
1.33 raeburn 2552: $env{'form.'.$name{$item}} = 'none';
2553: }
2554: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
2555: @options = sort(keys(%sections_count));
2556: } elsif ($item eq 'grp') {
2557: my %curr_groups = &Apache::longroup::coursegroups();
2558: @options = sort(keys(%curr_groups));
2559: }
2560: if (@options > 0) {
2561: my $currsel;
1.112 bisitz 2562: $markup = '<select name="'.$name{$item}.'">'."\n";
1.33 raeburn 2563: foreach my $option ('all','none',@options) {
2564: $currsel = '';
2565: if ($env{'form.'.$name{$item}} eq $option) {
1.96 bisitz 2566: $currsel = ' selected="selected"';
1.33 raeburn 2567: }
2568: $markup .= ' <option value="'.$option.'"'.$currsel.'>';
2569: if (($option eq 'all') || ($option eq 'none')) {
2570: $markup .= $title{$option};
2571: } else {
2572: $markup .= $option;
2573: }
2574: $markup .= '</option>'."\n";
2575: }
2576: $markup .= '</select>'."\n";
1.111 bisitz 2577: $output .= (' 'x3).'<span class="LC_nobreak">'
2578: .'<label>'.$title{$item}.': '.$markup.'</label>'
2579: .'</span> ';
1.33 raeburn 2580: }
2581: }
2582: return $output;
2583: }
2584:
1.140 raeburn 2585: sub infocolumns {
1.150 raeburn 2586: my ($context,$mode,$showcredits) = @_;
1.140 raeburn 2587: my @cols;
2588: if (($mode eq 'pickauthor') || ($mode eq 'autoenroll')) {
1.150 raeburn 2589: @cols = &get_cols_array($context,$mode,$showcredits);
1.140 raeburn 2590: } else {
1.150 raeburn 2591: my @posscols = &get_cols_array($context,$mode,$showcredits);
1.140 raeburn 2592: if ($env{'form.phase'} ne '') {
2593: my @checkedcols = &Apache::loncommon::get_env_multiple('form.showcol');
2594: foreach my $col (@checkedcols) {
2595: if (grep(/^$col$/,@posscols)) {
2596: push(@cols,$col);
2597: }
2598: }
2599: } else {
2600: @cols = @posscols;
2601: }
2602: }
2603: return @cols;
2604: }
2605:
2606: sub get_cols_array {
1.150 raeburn 2607: my ($context,$mode,$showcredits) = @_;
1.140 raeburn 2608: my @cols;
2609: if ($mode eq 'pickauthor') {
2610: @cols = ('username','fullname','status','email');
2611: } else {
2612: @cols = ('username','domain','id','fullname');
2613: if ($context eq 'course') {
2614: push(@cols,'section');
2615: }
2616: push(@cols,('start','end','role'));
2617: unless (($mode eq 'autoenroll') && ($env{'form.Status'} ne 'Any')) {
2618: push(@cols,'status');
2619: }
2620: if ($context eq 'course') {
2621: push(@cols,'groups');
2622: }
2623: push(@cols,'email');
2624: if (($context eq 'course') && ($mode ne 'autoenroll')) {
1.150 raeburn 2625: if ($showcredits) {
2626: push(@cols,'credits');
2627: }
1.140 raeburn 2628: push(@cols,'lastlogin','clicker');
2629: }
2630: if (($context eq 'course') && ($mode ne 'autoenroll') &&
2631: ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
1.156 raeburn 2632: push(@cols,'photo');
1.140 raeburn 2633: }
1.149 raeburn 2634: if ($context eq 'domain') {
1.219 ! raeburn 2635: push(@cols,('authorusage','authorquota','extent'));
! 2636: }
! 2637: if ($context eq 'author') {
! 2638: push(@cols,'manager');
1.149 raeburn 2639: }
1.140 raeburn 2640: }
2641: return @cols;
2642: }
2643:
2644: sub column_checkboxes {
1.150 raeburn 2645: my ($context,$mode,$formname,$showcredits) = @_;
2646: my @cols = &get_cols_array($context,$mode,$showcredits);
1.140 raeburn 2647: my @showncols = &Apache::loncommon::get_env_multiple('form.showcol');
2648: my (%disabledchk,%unchecked);
2649: if ($env{'form.phase'} eq '') {
2650: $disabledchk{'status'} = 1;
2651: if ($context eq 'course') {
2652: $disabledchk{'role'} = 1;
2653: $unchecked{'photo'} = 1;
1.149 raeburn 2654: $unchecked{'clicker'} = 1;
1.150 raeburn 2655: if ($showcredits) {
2656: $unchecked{'credits'} = 1;
2657: }
1.149 raeburn 2658: } elsif ($context eq 'domain') {
2659: $unchecked{'extent'} = 1;
1.140 raeburn 2660: }
2661: $unchecked{'start'} = 1;
2662: $unchecked{'end'} = 1;
2663: } else {
2664: if ($env{'form.Status'} ne 'Any') {
2665: $disabledchk{'status'} = 1;
2666: }
1.146 raeburn 2667: if (($env{'form.showrole'} ne 'Any') && ($env{'form.showrole'} ne 'cr')) {
2668: $disabledchk{'role'} = 1;
1.140 raeburn 2669: }
1.149 raeburn 2670: if ($context eq 'domain') {
2671: if (($env{'form.roletype'} eq 'course') ||
2672: ($env{'form.roletype'} eq 'community')) {
2673: $disabledchk{'status'} = 1;
1.159 raeburn 2674: $disabledchk{'authorusage'} = 1;
2675: $disabledchk{'authorquota'} = 1;
1.149 raeburn 2676: } elsif ($env{'form.roletype'} eq 'domain') {
2677: $disabledchk{'extent'} = 1;
2678: }
1.219 ! raeburn 2679: } elsif ($context eq 'author') {
! 2680: if (($env{'form.Status'} eq 'Expired') ||
! 2681: ($env{'form.showrole'} eq 'aa')) {
! 2682: $disabledchk{'manager'} = 1;
! 2683: }
1.149 raeburn 2684: }
1.140 raeburn 2685: }
2686: my $numposs = scalar(@cols);
1.149 raeburn 2687: my $numinrow = 7;
1.140 raeburn 2688: my %lt = &get_column_names($context);
2689: my $output = '<fieldset><legend>'.&mt('Information to show').'</legend>'."\n".'<span class="LC_nobreak">'.
2690: '<input type="button" onclick="javascript:checkAll(document.'.$formname.'.showcol);" value="'.&mt('check all').'" />'.
2691: (' 'x3).
2692: '<input type="button" onclick="javascript:uncheckAll(document.'.$formname.'.showcol);" value="'.&mt('uncheck all').'" />'.
2693: '</span><table>';
2694:
2695: for (my $i=0; $i<$numposs; $i++) {
2696: my $rem = $i%($numinrow);
2697: if ($rem == 0) {
2698: if ($i > 0) {
2699: $output .= '</tr>';
2700: }
2701: $output .= '<tr>';
2702: }
2703: my $checked;
2704: if ($env{'form.phase'} eq '') {
2705: $checked = ' checked="checked"';
2706: if ($unchecked{$cols[$i]}) {
2707: $checked = '';
2708: }
2709: if ($disabledchk{$cols[$i]}) {
2710: $checked = ' disabled="disabled"';
2711: }
2712: } elsif (grep(/^\Q$cols[$i]\E$/,@showncols)) {
2713: $checked = ' checked="checked"';
2714: } elsif ($disabledchk{$cols[$i]}) {
2715: $checked = ' disabled="disabled"';
2716: }
2717: if ($i == $numposs-1) {
2718: my $colsleft = $numinrow-$rem;
2719: if ($colsleft > 1) {
2720: $output .= '<td colspan="'.$colsleft.'">';
2721: } else {
2722: $output .= '<td>';
2723: }
2724: } else {
2725: $output .= '<td>';
2726: }
1.149 raeburn 2727: my $style;
2728: if ($cols[$i] eq 'extent') {
2729: if (($env{'form.roletype'} eq 'domain') || ($env{'form.roletype'} eq '')) {
2730: $style = ' style="display: none;"';
2731: }
1.159 raeburn 2732: } elsif (($cols[$i] eq 'authorusage') || ($cols[$i] eq 'authorquota')) {
2733: if ($env{'form.roletype'} ne 'domain') {
2734: $style = ' style="display: none;"';
2735: }
2736: }
1.149 raeburn 2737: $output .= '<span id="show'.$cols[$i].'"'.$style.'><label>'.
2738: '<input id="showcol'.$cols[$i].'" type="checkbox" name="showcol" value="'.$cols[$i].'"'.$checked.' /><span id="showcoltext'.$cols[$i].'">'.
2739: $lt{$cols[$i]}.'</span>'.
2740: '</label></span></td>';
1.140 raeburn 2741: }
2742: $output .= '</tr></table></fieldset>';
2743: return $output;
2744: }
2745:
1.2 raeburn 2746: sub list_submit_button {
2747: my ($text) = @_;
1.11 raeburn 2748: return '<input type="button" name="updatedisplay" value="'.$text.'" onclick="javascript:display_update()" />';
1.2 raeburn 2749: }
2750:
1.140 raeburn 2751: sub get_column_names {
2752: my ($context) = @_;
2753: my %lt = &Apache::lonlocal::texthash(
2754: 'username' => "username",
2755: 'domain' => "domain",
2756: 'id' => 'ID',
2757: 'fullname' => "name",
2758: 'section' => "section",
2759: 'groups' => "active groups",
2760: 'start' => "start date",
2761: 'end' => "end date",
2762: 'status' => "status",
2763: 'role' => "role",
1.150 raeburn 2764: 'credits' => "credits",
1.140 raeburn 2765: 'type' => "enroll type/action",
2766: 'email' => "e-mail address",
2767: 'photo' => "photo",
2768: 'lastlogin' => "last login",
2769: 'extent' => "extent",
1.159 raeburn 2770: 'authorusage' => "disk usage (%)",
2771: 'authorquota' => "disk quota (MB)",
1.140 raeburn 2772: 'ca' => "check all",
2773: 'ua' => "uncheck all",
2774: 'clicker' => "clicker-ID",
1.219 ! raeburn 2775: 'manager' => "co-author manager",
1.140 raeburn 2776: );
2777: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
1.149 raeburn 2778: $lt{'extent'} = &mt('course(s): description, section(s), status');
1.140 raeburn 2779: } elsif ($context eq 'domain' && $env{'form.roletype'} eq 'community') {
1.154 raeburn 2780: $lt{'extent'} = &mt('community(s): description, section(s), status');
1.149 raeburn 2781: } elsif (($context eq 'author') ||
2782: ($context eq 'domain' && $env{'form.roletype'} eq 'author')) {
2783: $lt{'extent'} = &mt('author');
1.140 raeburn 2784: }
2785: return %lt;
2786: }
2787:
1.2 raeburn 2788: sub gather_userinfo {
1.11 raeburn 2789: my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_;
1.52 raeburn 2790: my $viewablesec;
2791: if ($context eq 'course') {
2792: $viewablesec = &viewable_section($permission);
2793: }
1.2 raeburn 2794: foreach my $item (keys(%{$rolehash})) {
2795: my %userdata;
1.22 raeburn 2796: if ($context eq 'author') {
1.2 raeburn 2797: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
2798: split(/:/,$item);
2799: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
1.24 raeburn 2800: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2801: $item,$userlist);
1.22 raeburn 2802: } elsif ($context eq 'course') {
2803: ($userdata{'username'},$userdata{'domain'},$userdata{'role'},
2804: $userdata{'section'}) = split(/:/,$item,-1);
2805: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
2806: if (($viewablesec ne '') && ($userdata{'section'} ne '')) {
2807: next if ($viewablesec ne $userdata{'section'});
2808: }
1.24 raeburn 2809: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2810: $item,$userlist);
1.2 raeburn 2811: } elsif ($context eq 'domain') {
2812: if ($env{'form.roletype'} eq 'domain') {
2813: ($userdata{'role'},$userdata{'username'},$userdata{'domain'}) =
2814: split(/:/,$item);
2815: ($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
1.24 raeburn 2816: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2817: $item,$userlist);
1.13 raeburn 2818: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 2819: if (ref($rolehash->{$item}) eq 'HASH') {
2820: $userdata{'extent'} = $item;
2821: foreach my $key (keys(%{$rolehash->{$item}})) {
2822: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) = split(/:/,$key);
2823: ($userdata{'start'},$userdata{'end'}) =
2824: split(/:/,$rolehash->{$item}{$key});
2825: my $uniqid = $key.':'.$item;
1.25 raeburn 2826: &build_user_record($context,\%userdata,$userinfo,
2827: $indexhash,$uniqid,$userlist);
1.2 raeburn 2828: }
2829: }
1.102 raeburn 2830: } elsif (($env{'form.roletype'} eq 'course') ||
2831: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 2832: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
2833: split(/:/,$item);
2834: if (ref($rolehash->{$item}) eq 'HASH') {
1.11 raeburn 2835: my $numcids = keys(%{$rolehash->{$item}});
1.2 raeburn 2836: foreach my $cid (sort(keys(%{$rolehash->{$item}}))) {
2837: if (ref($rolehash->{$item}{$cid}) eq 'HASH') {
2838: my $spanstart = '';
2839: my $spanend = '; ';
2840: my $space = ', ';
2841: if ($format eq 'html' || $format eq 'view') {
2842: $spanstart = '<span class="LC_nobreak">';
1.23 raeburn 2843: # FIXME: actions on courses disabled for now
2844: # if ($permission->{'cusr'}) {
2845: # if ($numcids > 1) {
1.25 raeburn 2846: # $spanstart .= '<input type="radio" name="'.$item.'" value="'.$cid.'" /> ';
1.23 raeburn 2847: # } else {
1.25 raeburn 2848: # $spanstart .= '<input type="hidden" name="'.$item.'" value="'.$cid.'" /> ';
1.23 raeburn 2849: # }
2850: # }
1.2 raeburn 2851: $spanend = '</span><br />';
2852: $space = ', ';
2853: }
2854: $userdata{'extent'} .= $spanstart.
2855: $rolehash->{$item}{$cid}{'desc'}.$space;
2856: if (ref($rolehash->{$item}{$cid}{'secs'}) eq 'HASH') {
2857: foreach my $sec (sort(keys(%{$rolehash->{$item}{$cid}{'secs'}}))) {
1.25 raeburn 2858: if (($env{'form.Status'} eq 'Any') ||
2859: ($env{'form.Status'} eq $rolehash->{$item}{$cid}{'secs'}{$sec})) {
2860: $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
2861: $userdata{'status'} = $rolehash->{$item}{$cid}{'secs'}{$sec};
2862: }
1.2 raeburn 2863: }
2864: }
2865: }
2866: }
2867: }
1.25 raeburn 2868: if ($userdata{'status'} ne '') {
2869: &build_user_record($context,\%userdata,$userinfo,
2870: $indexhash,$item,$userlist);
2871: }
1.2 raeburn 2872: }
2873: }
2874: }
2875: return;
2876: }
2877:
2878: sub build_user_record {
1.24 raeburn 2879: my ($context,$userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
1.11 raeburn 2880: next if ($userdata->{'start'} eq '-1' && $userdata->{'end'} eq '-1');
1.102 raeburn 2881: if (!(($context eq 'domain') && (($env{'form.roletype'} eq 'course')
2882: && ($env{'form.roletype'} eq 'community')))) {
1.24 raeburn 2883: &process_date_info($userdata);
2884: }
1.2 raeburn 2885: my $username = $userdata->{'username'};
2886: my $domain = $userdata->{'domain'};
2887: if (ref($userinfo->{$username.':'.$domain}) eq 'HASH') {
1.24 raeburn 2888: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
1.2 raeburn 2889: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
2890: } else {
2891: &aggregate_user_info($domain,$username,$userinfo);
2892: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
2893: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
2894: }
2895: foreach my $key (keys(%{$indexhash})) {
2896: if (defined($userdata->{$key})) {
2897: $userlist->{$record_key}[$indexhash->{$key}] = $userdata->{$key};
2898: }
2899: }
2900: return;
2901: }
2902:
2903: sub courses_selector {
2904: my ($cdom,$formname) = @_;
2905: my %codes = ();
2906: my @codetitles = ();
2907: my %cat_titles = ();
2908: my %cat_order = ();
2909: my %idlist = ();
2910: my %idnums = ();
2911: my %idlist_titles = ();
2912: my $caller = 'global';
2913: my $format_reply;
2914: my $jscript = '';
2915:
1.7 albertel 2916: my $totcodes = 0;
1.201 raeburn 2917: my $instcats = &Apache::lonnet::get_dom_instcats($cdom);
2918: if (ref($instcats) eq 'HASH') {
2919: if ((ref($instcats->{'codetitles'}) eq 'ARRAY') && (ref($instcats->{'codes'}) eq 'HASH') &&
2920: (ref($instcats->{'cat_titles'}) eq 'HASH') && (ref($instcats->{'cat_order'}) eq 'HASH')) {
2921: %codes = %{$instcats->{'codes'}};
2922: @codetitles = @{$instcats->{'codetitles'}};
2923: %cat_titles = %{$instcats->{'cat_titles'}};
2924: %cat_order = %{$instcats->{'cat_order'}};
2925: $totcodes = scalar(keys(%codes));
1.2 raeburn 2926: my $numtypes = @codetitles;
2927: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
2928: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
2929: my $longtitles_str = join('","',@{$longtitles});
2930: my $allidlist = $idlist{$codetitles[0]};
2931: $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
2932: $jscript .= $scripttext;
1.181 raeburn 2933: $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,\@codetitles);
1.2 raeburn 2934: }
2935: }
2936: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
2937:
2938: my %elements = (
2939: Year => 'selectbox',
2940: coursepick => 'radio',
2941: coursetotal => 'text',
2942: courselist => 'text',
2943: );
2944: $jscript .= &Apache::lonhtmlcommon::set_form_elements(\%elements);
2945: if ($env{'form.coursepick'} eq 'category') {
2946: $jscript .= qq|
2947: function setCourseCat(formname) {
2948: if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
2949: return;
2950: }
1.120 raeburn 2951: courseSet('$codetitles[0]');
1.2 raeburn 2952: for (var j=0; j<formname.Semester.length; j++) {
2953: if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
2954: formname.Semester.options[j].selected = true;
2955: }
2956: }
2957: if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
2958: return;
2959: }
1.120 raeburn 2960: courseSet('$codetitles[1]');
1.2 raeburn 2961: for (var j=0; j<formname.Department.length; j++) {
1.187 raeburn 2962: if (formname.Department.options[j].value == "$env{'form.Department'}") {
2963: formname.Department.options[j].selected = true;
1.2 raeburn 2964: }
2965: }
2966: if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
2967: return;
2968: }
1.120 raeburn 2969: courseSet('$codetitles[2]');
1.2 raeburn 2970: for (var j=0; j<formname.Number.length; j++) {
2971: if (formname.Number.options[j].value == "$env{'form.Number'}") {
2972: formname.Number.options[j].selected = true;
2973: }
2974: }
2975: }
2976: |;
2977: }
2978: return ($cb_jscript,$jscript,$totcodes,\@codetitles,\%idlist,
2979: \%idlist_titles);
2980: }
2981:
2982: sub course_selector_loadcode {
2983: my ($formname) = @_;
2984: my $loadcode;
2985: if ($env{'form.coursepick'} ne '') {
2986: $loadcode = 'javascript:setFormElements(document.'.$formname.')';
2987: if ($env{'form.coursepick'} eq 'category') {
2988: $loadcode .= ';javascript:setCourseCat(document.'.$formname.')';
2989: }
2990: }
2991: return $loadcode;
2992: }
2993:
2994: sub process_coursepick {
2995: my $coursefilter = $env{'form.coursepick'};
2996: my $cdom = $env{'request.role.domain'};
2997: my %courses;
1.105 raeburn 2998: my $crssrch = 'Course';
2999: if ($env{'form.roletype'} eq 'community') {
3000: $crssrch = 'Community';
3001: }
1.2 raeburn 3002: if ($coursefilter eq 'all') {
3003: %courses = &Apache::lonnet::courseiddump($cdom,'.','.','.','.','.',
1.105 raeburn 3004: undef,undef,$crssrch);
1.2 raeburn 3005: } elsif ($coursefilter eq 'category') {
3006: my $instcode = &instcode_from_coursefilter();
3007: %courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.',
1.105 raeburn 3008: undef,undef,$crssrch);
1.2 raeburn 3009: } elsif ($coursefilter eq 'specific') {
3010: if ($env{'form.coursetotal'} > 1) {
3011: my @course_ids = split(/&&/,$env{'form.courselist'});
3012: foreach my $cid (@course_ids) {
3013: $courses{$cid} = '';
1.1 raeburn 3014: }
1.2 raeburn 3015: } else {
3016: $courses{$env{'form.courselist'}} = '';
1.1 raeburn 3017: }
1.2 raeburn 3018: }
3019: return %courses;
3020: }
3021:
3022: sub instcode_from_coursefilter {
3023: my $instcode = '';
3024: my @cats = ('Semester','Year','Department','Number');
3025: foreach my $category (@cats) {
3026: if (defined($env{'form.'.$category})) {
3027: unless ($env{'form.'.$category} eq '-1') {
3028: $instcode .= $env{'form.'.$category};
3029: }
3030: }
3031: }
3032: if ($instcode eq '') {
3033: $instcode = '.';
3034: }
3035: return $instcode;
3036: }
3037:
3038: sub make_keylist_array {
3039: my ($index,$keylist);
3040: $index->{'domain'} = &Apache::loncoursedata::CL_SDOM();
3041: $index->{'username'} = &Apache::loncoursedata::CL_SNAME();
3042: $index->{'end'} = &Apache::loncoursedata::CL_END();
3043: $index->{'start'} = &Apache::loncoursedata::CL_START();
3044: $index->{'id'} = &Apache::loncoursedata::CL_ID();
3045: $index->{'section'} = &Apache::loncoursedata::CL_SECTION();
3046: $index->{'fullname'} = &Apache::loncoursedata::CL_FULLNAME();
3047: $index->{'status'} = &Apache::loncoursedata::CL_STATUS();
3048: $index->{'type'} = &Apache::loncoursedata::CL_TYPE();
3049: $index->{'lockedtype'} = &Apache::loncoursedata::CL_LOCKEDTYPE();
3050: $index->{'groups'} = &Apache::loncoursedata::CL_GROUP();
3051: $index->{'email'} = &Apache::loncoursedata::CL_PERMANENTEMAIL();
3052: $index->{'role'} = &Apache::loncoursedata::CL_ROLE();
3053: $index->{'extent'} = &Apache::loncoursedata::CL_EXTENT();
1.44 raeburn 3054: $index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
1.47 raeburn 3055: $index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();
1.150 raeburn 3056: $index->{'credits'} = &Apache::loncoursedata::CL_CREDITS();
1.174 raeburn 3057: $index->{'instsec'} = &Apache::loncoursedata::CL_INSTSEC();
1.159 raeburn 3058: $index->{'authorquota'} = &Apache::loncoursedata::CL_AUTHORQUOTA();
3059: $index->{'authorusage'} = &Apache::loncoursedata::CL_AUTHORUSAGE();
1.219 ! raeburn 3060: $index->{'manager'} = &Apache::loncoursedata::CL_CAMANAGER();
1.2 raeburn 3061: foreach my $key (keys(%{$index})) {
3062: $keylist->[$index->{$key}] = $key;
3063: }
3064: return ($index,$keylist);
3065: }
3066:
3067: sub aggregate_user_info {
3068: my ($udom,$uname,$userinfo) = @_;
3069: my %info=&Apache::lonnet::get('environment',
3070: ['firstname','middlename',
3071: 'lastname','generation','id'],
3072: $udom,$uname);
3073: my ($tmp) = keys(%info);
3074: my ($fullname,$id);
3075: if ($tmp =~/^(con_lost|error|no_such_host)/i) {
3076: $fullname = 'not available';
3077: $id = 'not available';
3078: &Apache::lonnet::logthis('unable to retrieve environment '.
3079: 'for '.$uname.':'.$udom);
1.1 raeburn 3080: } else {
1.2 raeburn 3081: $fullname = &Apache::lonnet::format_name(@info{qw/firstname middlename lastname generation/},'lastname');
3082: $id = $info{'id'};
3083: }
3084: $userinfo->{$uname.':'.$udom} = {
3085: fullname => $fullname,
3086: id => $id,
3087: };
3088: return;
3089: }
1.1 raeburn 3090:
1.2 raeburn 3091: sub process_date_info {
3092: my ($userdata) = @_;
3093: my $now = time;
1.83 raeburn 3094: $userdata->{'status'} = 'Active';
1.2 raeburn 3095: if ($userdata->{'start'} > 0) {
3096: if ($now < $userdata->{'start'}) {
1.83 raeburn 3097: $userdata->{'status'} = 'Future';
1.2 raeburn 3098: }
1.1 raeburn 3099: }
1.2 raeburn 3100: if ($userdata->{'end'} > 0) {
3101: if ($now > $userdata->{'end'}) {
1.83 raeburn 3102: $userdata->{'status'} = 'Expired';
1.2 raeburn 3103: }
3104: }
3105: return;
1.1 raeburn 3106: }
3107:
3108: sub show_users_list {
1.150 raeburn 3109: my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname,
1.159 raeburn 3110: $showcredits,$needauthorquota,$needauthorusage)=@_;
1.55 raeburn 3111: if ($formname eq '') {
3112: $formname = 'studentform';
3113: }
1.159 raeburn 3114: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1 raeburn 3115: #
3116: # Variables for excel output
3117: my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
3118: #
3119: # Variables for csv output
3120: my ($CSVfile,$CSVfilename);
3121: #
3122: my $sortby = $env{'form.sortby'};
1.3 raeburn 3123: my @sortable = ('username','domain','id','fullname','start','end','email','role');
1.2 raeburn 3124: if ($context eq 'course') {
1.3 raeburn 3125: push(@sortable,('section','groups','type'));
1.150 raeburn 3126: if ($showcredits) {
3127: push(@sortable,'credits');
3128: }
1.2 raeburn 3129: } else {
1.3 raeburn 3130: push(@sortable,'extent');
1.159 raeburn 3131: if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
3132: (($env{'form.showrole'} eq 'Any') || ($env{'form.showrole'} eq 'au'))) {
3133: push(@sortable,('authorusage','authorquota'));
3134: }
1.219 ! raeburn 3135: if ($context eq 'author') {
! 3136: push(@sortable,'manager');
! 3137: }
1.3 raeburn 3138: }
1.55 raeburn 3139: if ($mode eq 'pickauthor') {
3140: @sortable = ('username','fullname','email','status');
3141: }
1.156 raeburn 3142: my %is_sortable;
1.158 raeburn 3143: map { $is_sortable{$_} = 1; } @sortable;
1.156 raeburn 3144: unless ($is_sortable{$sortby}) {
1.3 raeburn 3145: $sortby = 'username';
1.1 raeburn 3146: }
1.22 raeburn 3147: my $setting = $env{'form.roletype'};
1.150 raeburn 3148: my ($cid,$cdom,$cnum,$classgroups,$crstype,$defaultcredits);
1.1 raeburn 3149: if ($context eq 'course') {
1.22 raeburn 3150: $cid = $env{'request.course.id'};
1.101 raeburn 3151: $crstype = &Apache::loncommon::course_type();
1.17 raeburn 3152: ($cnum,$cdom) = &get_course_identity($cid);
1.150 raeburn 3153: $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
1.2 raeburn 3154: ($classgroups) = &Apache::loncoursedata::get_group_memberships(
3155: $userlist,$keylist,$cdom,$cnum);
1.16 raeburn 3156: if ($mode eq 'autoenroll') {
3157: $env{'form.showrole'} = 'st';
3158: } else {
3159: if ($env{'course.'.$cid.'.internal.showphoto'}) {
3160: $r->print('
1.1 raeburn 3161: <script type="text/javascript">
1.96 bisitz 3162: // <![CDATA[
1.1 raeburn 3163: function photowindow(photolink) {
3164: var title = "Photo_Viewer";
3165: var options = "scrollbars=1,resizable=1,menubar=0";
3166: options += ",width=240,height=240";
3167: stdeditbrowser = open(photolink,title,options,"1");
3168: stdeditbrowser.focus();
3169: }
1.96 bisitz 3170: // ]]>
1.1 raeburn 3171: </script>
1.16 raeburn 3172: ');
3173: }
3174: }
1.102 raeburn 3175: } elsif ($context eq 'domain') {
3176: if ($setting eq 'community') {
3177: $crstype = 'Community';
1.105 raeburn 3178: } elsif ($setting eq 'course') {
1.102 raeburn 3179: $crstype = 'Course';
3180: }
1.1 raeburn 3181: }
1.55 raeburn 3182: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
1.40 raeburn 3183: my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
1.56 raeburn 3184: my $verify_action_js = &bulkaction_javascript($formname);
1.1 raeburn 3185: $r->print(<<END);
1.10 raeburn 3186:
3187: <script type="text/javascript" language="Javascript">
1.96 bisitz 3188: // <![CDATA[
1.11 raeburn 3189:
1.56 raeburn 3190: $verify_action_js
1.10 raeburn 3191:
3192: function username_display_launch(username,domain) {
3193: var target;
1.177 raeburn 3194: if (!document.$formname.usernamelink.length) {
3195: target = document.$formname.usernamelink.value;
3196: } else {
3197: for (var i=0; i<document.$formname.usernamelink.length; i++) {
3198: if (document.$formname.usernamelink[i].checked) {
3199: target = document.$formname.usernamelink[i].value;
3200: }
1.10 raeburn 3201: }
3202: }
1.179 raeburn 3203: if ((target == 'modify') || (target == 'activity')) {
3204: var nextaction = 'singleuser';
3205: if (target == 'activity') {
3206: nextaction = 'accesslogs';
3207: }
1.55 raeburn 3208: if (document.$formname.userwin.checked == true) {
1.179 raeburn 3209: var url = '/adm/createuser?srchterm='+username+'&srchdomain='+domain+'&phase=get_user_info&srchin=dom&srchby=uname&srchtype=exact&popup=1&action='+nextaction;
1.50 raeburn 3210: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3211: modifywin = window.open(url,'',options,1);
3212: modifywin.focus();
3213: return;
3214: } else {
1.55 raeburn 3215: document.$formname.srchterm.value=username;
3216: document.$formname.srchdomain.value=domain;
3217: document.$formname.phase.value='get_user_info';
1.179 raeburn 3218: document.$formname.action.value = nextaction;
1.55 raeburn 3219: document.$formname.submit();
1.50 raeburn 3220: }
1.10 raeburn 3221: }
1.48 raeburn 3222: if (target == 'aboutme') {
1.55 raeburn 3223: if (document.$formname.userwin.checked == true) {
1.50 raeburn 3224: var url = '/adm/'+domain+'/'+username+'/aboutme?popup=1';
3225: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3226: aboutmewin = window.open(url,'',options,1);
3227: aboutmewin.focus();
3228: return;
3229: } else {
3230: document.location.href = '/adm/'+domain+'/'+username+'/aboutme';
3231: }
1.48 raeburn 3232: }
1.98 raeburn 3233: if (target == 'track') {
3234: if (document.$formname.userwin.checked == true) {
3235: var url = '/adm/trackstudent?selected_student='+username+':'+domain+'&only_body=1';
3236: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3237: var trackwin = window.open(url,'',options,1);
3238: trackwin.focus();
3239: return;
3240: } else {
3241: document.location.href = '/adm/trackstudent?selected_student='+username+':'+domain;
3242: }
3243: }
1.10 raeburn 3244: }
1.96 bisitz 3245: // ]]>
1.10 raeburn 3246: </script>
1.11 raeburn 3247: $date_sec_selector
1.1 raeburn 3248: <input type="hidden" name="state" value="$env{'form.state'}" />
3249: END
3250: }
3251: $r->print(<<END);
3252: <input type="hidden" name="sortby" value="$sortby" />
3253: END
1.150 raeburn 3254: my @cols = &infocolumns($context,$mode,$showcredits);
1.140 raeburn 3255: my %coltxt = &get_column_names($context);
3256: my %acttxt = &Apache::lonlocal::texthash(
1.11 raeburn 3257: 'pr' => "Proceed",
3258: 'ac' => "Action to take for selected users",
1.56 raeburn 3259: 'link' => "Behavior of clickable username link for each user",
1.82 weissno 3260: 'aboutme' => "Display a user's personal information page",
1.50 raeburn 3261: 'owin' => "Open in a new window",
1.10 raeburn 3262: 'modify' => "Modify a user's information",
1.98 raeburn 3263: 'track' => "View a user's recent activity",
1.179 raeburn 3264: 'activity' => "View a user's access log",
1.1 raeburn 3265: );
1.140 raeburn 3266: my %lt = (%coltxt,%acttxt);
1.4 raeburn 3267: my $rolefilter = $env{'form.showrole'};
1.5 raeburn 3268: if ($env{'form.showrole'} eq 'cr') {
3269: $rolefilter = &mt('custom');
3270: } elsif ($env{'form.showrole'} ne 'Any') {
1.101 raeburn 3271: $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'},$crstype);
1.2 raeburn 3272: }
1.16 raeburn 3273: my $results_description;
3274: if ($mode ne 'autoenroll') {
3275: $results_description = &results_header_row($rolefilter,$statusmode,
1.102 raeburn 3276: $context,$permission,$mode,$crstype);
1.140 raeburn 3277: $r->print('<b>'.$results_description.'</b><br clear="all" />');
1.16 raeburn 3278: }
1.26 raeburn 3279: my ($output,$actionselect,%canchange,%canchangesec);
1.55 raeburn 3280: if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
3281: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
1.16 raeburn 3282: if ($permission->{'cusr'}) {
1.105 raeburn 3283: unless (($context eq 'domain') &&
3284: (($setting eq 'course') || ($setting eq 'community'))) {
3285: $actionselect =
3286: &select_actions($context,$setting,$statusmode,$formname);
3287: }
1.16 raeburn 3288: }
3289: $r->print(<<END);
1.10 raeburn 3290: <input type="hidden" name="srchby" value="uname" />
3291: <input type="hidden" name="srchin" value="dom" />
3292: <input type="hidden" name="srchtype" value="exact" />
3293: <input type="hidden" name="srchterm" value="" />
1.11 raeburn 3294: <input type="hidden" name="srchdomain" value="" />
1.1 raeburn 3295: END
1.16 raeburn 3296: if ($actionselect) {
1.41 raeburn 3297: $output .= <<"END";
1.94 bisitz 3298: <div class="LC_left_float"><fieldset><legend>$lt{'ac'}</legend>
1.56 raeburn 3299: $actionselect
3300: <br/><br /><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.$formname.actionlist)" />
3301: <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>
1.11 raeburn 3302: END
1.26 raeburn 3303: my @allroles;
3304: if ($env{'form.showrole'} eq 'Any') {
3305: my $custom = 1;
3306: if ($context eq 'domain') {
1.101 raeburn 3307: @allroles = &roles_by_context($setting,$custom,$crstype);
1.26 raeburn 3308: } else {
1.101 raeburn 3309: @allroles = &roles_by_context($context,$custom,$crstype);
1.26 raeburn 3310: }
3311: } else {
3312: @allroles = ($env{'form.showrole'});
3313: }
3314: foreach my $role (@allroles) {
3315: if ($context eq 'domain') {
3316: if ($setting eq 'domain') {
3317: if (&Apache::lonnet::allowed('c'.$role,
3318: $env{'request.role.domain'})) {
3319: $canchange{$role} = 1;
3320: }
1.31 raeburn 3321: } elsif ($setting eq 'author') {
3322: if (&Apache::lonnet::allowed('c'.$role,
3323: $env{'request.role.domain'})) {
3324: $canchange{$role} = 1;
3325: }
1.26 raeburn 3326: }
3327: } elsif ($context eq 'author') {
3328: if (&Apache::lonnet::allowed('c'.$role,
3329: $env{'user.domain'}.'/'.$env{'user.name'})) {
3330: $canchange{$role} = 1;
3331: }
3332: } elsif ($context eq 'course') {
3333: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
3334: $canchange{$role} = 1;
3335: } elsif ($env{'request.course.sec'} ne '') {
3336: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
3337: $canchangesec{$role} = $env{'request.course.sec'};
3338: }
1.141 raeburn 3339: } elsif ((($role eq 'co') && ($crstype eq 'Community')) ||
3340: (($role eq 'cc') && ($crstype eq 'Course'))) {
3341: if (&is_courseowner($env{'request.course.id'},
3342: $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
3343: $canchange{$role} = 1;
3344: }
1.26 raeburn 3345: }
3346: }
3347: }
1.16 raeburn 3348: }
1.94 bisitz 3349: $output .= '<div class="LC_left_float"><fieldset><legend>'.$lt{'link'}.'</legend>'.
1.56 raeburn 3350: '<table><tr>';
3351: my @linkdests = ('aboutme');
3352: if ($permission->{'cusr'}) {
3353: unshift (@linkdests,'modify');
3354: }
1.179 raeburn 3355: if ($context eq 'course') {
3356: if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) ||
3357: &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.
3358: $env{'request.course.sec'})) {
3359: push(@linkdests,'track');
3360: }
3361: } elsif ($context eq 'domain') {
3362: if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
3363: push(@linkdests,'activity');
3364: }
1.98 raeburn 3365: }
1.56 raeburn 3366: $output .= '<td>';
3367: my $usernamelink = $env{'form.usernamelink'};
3368: if ($usernamelink eq '') {
3369: $usernamelink = 'aboutme';
3370: }
3371: foreach my $item (@linkdests) {
3372: my $checkedstr = '';
3373: if ($item eq $usernamelink) {
1.86 bisitz 3374: $checkedstr = ' checked="checked"';
1.56 raeburn 3375: }
1.86 bisitz 3376: $output .= '<span class="LC_nobreak"><label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.' /> '.$lt{$item}.'</label></span><br />';
1.56 raeburn 3377: }
3378: my $checkwin;
3379: if ($env{'form.userwin'}) {
1.86 bisitz 3380: $checkwin = ' checked="checked"';
1.56 raeburn 3381: }
1.144 bisitz 3382: $output .=
3383: '</td><td valign="top" style="border-left: 1px solid;">'
3384: .'<span class="LC_nobreak"><label>'
3385: .'<input type="checkbox" name="userwin" value="1"'.$checkwin.' />'.$lt{'owin'}
3386: .'</label></span></td></tr></table></fieldset></div>';
1.4 raeburn 3387: }
1.184 raeburn 3388: $output .= "\n".'<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
1.1 raeburn 3389: &Apache::loncommon::start_data_table().
1.4 raeburn 3390: &Apache::loncommon::start_data_table_header_row();
1.1 raeburn 3391: if ($mode eq 'autoenroll') {
1.4 raeburn 3392: $output .= "
1.55 raeburn 3393: <th><a href=\"javascript:document.$formname.sortby.value='type';document.$formname.submit();\">$lt{'type'}</a></th>
1.4 raeburn 3394: ";
1.1 raeburn 3395: } else {
1.105 raeburn 3396: $output .= "\n".'<th> </th>'."\n";
1.11 raeburn 3397: if ($actionselect) {
1.159 raeburn 3398: $output .= '<th class="LC_nobreak" valign="top">'.&mt('Select').'</th>'."\n";
1.11 raeburn 3399: }
1.1 raeburn 3400: }
3401: foreach my $item (@cols) {
1.159 raeburn 3402: $output .= '<th class="LC_nobreak" valign="top">';
1.156 raeburn 3403: if ($is_sortable{$item}) {
1.159 raeburn 3404: $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>";
1.156 raeburn 3405: } else {
3406: $output .= $lt{$item};
3407: }
3408: $output .= "</th>\n";
1.1 raeburn 3409: }
1.2 raeburn 3410: my %role_types = &role_type_names();
1.16 raeburn 3411: $output .= &Apache::loncommon::end_data_table_header_row();
1.1 raeburn 3412: # Done with the HTML header line
3413: } elsif ($mode eq 'csv') {
3414: #
3415: # Open a file
3416: $CSVfilename = '/prtspool/'.
1.2 raeburn 3417: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
3418: time.'_'.rand(1000000000).'.csv';
1.1 raeburn 3419: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
3420: $r->log_error("Couldn't open $CSVfilename for output $!");
1.108 bisitz 3421: $r->print(
3422: '<p class="LC_error">'
3423: .&mt('Problems occurred in writing the CSV file.')
3424: .' '.&mt('This error has been logged.')
3425: .' '.&mt('Please alert your LON-CAPA administrator.')
3426: .'</p>'
3427: );
1.1 raeburn 3428: $CSVfile = undef;
3429: }
3430: #
3431: # Write headers and data to file
1.2 raeburn 3432: print $CSVfile '"'.$results_description.'"'."\n";
1.1 raeburn 3433: print $CSVfile '"'.join('","',map {
3434: &Apache::loncommon::csv_translate($lt{$_})
1.67 droeschl 3435: } (@cols))."\"\n";
1.1 raeburn 3436: } elsif ($mode eq 'excel') {
3437: # Create the excel spreadsheet
3438: ($excel_workbook,$excel_filename,$format) =
3439: &Apache::loncommon::create_workbook($r);
3440: return if (! defined($excel_workbook));
3441: $excel_sheet = $excel_workbook->addworksheet('userlist');
1.2 raeburn 3442: $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
1.1 raeburn 3443: #
3444: my @colnames = map {$lt{$_}} (@cols);
1.67 droeschl 3445:
1.1 raeburn 3446: $excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
3447: }
3448:
3449: # Done with header lines in all formats
3450: my %index;
3451: my $i;
1.2 raeburn 3452: foreach my $idx (@$keylist) {
3453: $index{$idx} = $i++;
3454: }
1.219 ! raeburn 3455: my $now = time;
1.4 raeburn 3456: my $usercount = 0;
1.33 raeburn 3457: my ($secfilter,$grpfilter);
3458: if ($context eq 'course') {
3459: $secfilter = $env{'form.secfilter'};
3460: $grpfilter = $env{'form.grpfilter'};
3461: if ($secfilter eq '') {
3462: $secfilter = 'all';
3463: }
3464: if ($grpfilter eq '') {
3465: $grpfilter = 'all';
3466: }
3467: }
1.83 raeburn 3468: my %ltstatus = &Apache::lonlocal::texthash(
3469: Active => 'Active',
3470: Future => 'Future',
3471: Expired => 'Expired',
3472: );
1.219 ! raeburn 3473: my (%crslogins,%camanagers);
1.139 raeburn 3474: if ($context eq 'course') {
1.219 ! raeburn 3475: # If this is for a single course get last course "log-in".
1.139 raeburn 3476: %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$cnum);
1.219 ! raeburn 3477: } elsif ($context eq 'author') {
! 3478: map { $camanagers{$_.':ca'} = 1; } split(/,/,$env{'environment.authormanagers'});
1.139 raeburn 3479: }
1.2 raeburn 3480: # Get groups, role, permanent e-mail so we can sort on them if
3481: # necessary.
3482: foreach my $user (keys(%{$userlist})) {
1.43 raeburn 3483: if ($user eq '' ) {
3484: delete($userlist->{$user});
3485: next;
3486: }
1.11 raeburn 3487: if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) {
3488: delete($userlist->{$user});
3489: next;
3490: }
1.2 raeburn 3491: my ($uname,$udom,$role,$groups,$email);
1.5 raeburn 3492: if (($statusmode ne 'Any') &&
3493: ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
3494: delete($userlist->{$user});
3495: next;
3496: }
1.2 raeburn 3497: if ($context eq 'domain') {
3498: if ($env{'form.roletype'} eq 'domain') {
3499: ($role,$uname,$udom) = split(/:/,$user);
1.11 raeburn 3500: if (($uname eq $env{'request.role.domain'}.'-domainconfig') &&
3501: ($udom eq $env{'request.role.domain'})) {
3502: delete($userlist->{$user});
3503: next;
3504: }
1.13 raeburn 3505: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 3506: ($uname,$udom,$role) = split(/:/,$user,-1);
1.102 raeburn 3507: } elsif (($env{'form.roletype'} eq 'course') ||
3508: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 3509: ($uname,$udom,$role) = split(/:/,$user);
3510: }
3511: } else {
3512: ($uname,$udom,$role) = split(/:/,$user,-1);
3513: if (($context eq 'course') && $role eq '') {
3514: $role = 'st';
3515: }
3516: }
3517: $userlist->{$user}->[$index{'role'}] = $role;
3518: if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
3519: delete($userlist->{$user});
3520: next;
3521: }
1.33 raeburn 3522: if ($context eq 'course') {
3523: my @ac_groups;
3524: if (ref($classgroups) eq 'HASH') {
3525: $groups = $classgroups->{$user};
3526: }
3527: if (ref($groups->{'active'}) eq 'HASH') {
3528: @ac_groups = keys(%{$groups->{'active'}});
3529: $userlist->{$user}->[$index{'groups'}] = join(', ',@ac_groups);
3530: }
3531: if ($mode ne 'autoenroll') {
3532: my $section = $userlist->{$user}->[$index{'section'}];
1.43 raeburn 3533: if (($env{'request.course.sec'} ne '') &&
3534: ($section ne $env{'request.course.sec'})) {
3535: if ($role eq 'st') {
3536: delete($userlist->{$user});
3537: next;
3538: }
3539: }
1.33 raeburn 3540: if ($secfilter eq 'none') {
3541: if ($section ne '') {
3542: delete($userlist->{$user});
3543: next;
3544: }
3545: } elsif ($secfilter ne 'all') {
3546: if ($section ne $secfilter) {
3547: delete($userlist->{$user});
3548: next;
3549: }
3550: }
3551: if ($grpfilter eq 'none') {
3552: if (@ac_groups > 0) {
3553: delete($userlist->{$user});
3554: next;
3555: }
3556: } elsif ($grpfilter ne 'all') {
3557: if (!grep(/^\Q$grpfilter\E$/,@ac_groups)) {
3558: delete($userlist->{$user});
3559: next;
3560: }
3561: }
1.44 raeburn 3562: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
1.140 raeburn 3563: if ((grep/^photo$/,@cols) && ($role eq 'st')) {
1.44 raeburn 3564: $userlist->{$user}->[$index{'photo'}] =
1.47 raeburn 3565: &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg');
3566: $userlist->{$user}->[$index{'thumbnail'}] =
1.44 raeburn 3567: &Apache::lonnet::retrievestudentphoto($udom,$uname,
3568: 'gif','thumbnail');
3569: }
3570: }
1.150 raeburn 3571: if (($role eq 'st') && ($defaultcredits)) {
3572: if ($userlist->{$user}->[$index{'credits'}] eq '') {
3573: $userlist->{$user}->[$index{'credits'}] = $defaultcredits;
3574: }
3575: }
1.33 raeburn 3576: }
1.2 raeburn 3577: }
1.219 ! raeburn 3578: if ($context eq 'author') {
! 3579: if (($camanagers{$user}) &&
! 3580: ((!defined($userlist->{$user}->[$index{'end'}])) ||
! 3581: ($userlist->{$user}->[$index{'end'}] == 0) ||
! 3582: ($userlist->{$user}->[$index{'end'}] > $now))) {
! 3583: $userlist->{$user}->[$index{'manager'}] = &mt('Yes');
! 3584: } else {
! 3585: $userlist->{$user}->[$index{'manager'}] = &mt('No');
! 3586: }
! 3587: }
1.2 raeburn 3588: my %emails = &Apache::loncommon::getemails($uname,$udom);
3589: if ($emails{'permanentemail'} =~ /\S/) {
3590: $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
3591: }
1.159 raeburn 3592: if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
3593: ($role eq 'au')) {
3594: my ($disk_quota,$current_disk_usage,$percent);
3595: if (($needauthorusage) || ($needauthorquota)) {
3596: $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author');
3597: }
3598: if ($needauthorusage) {
3599: $current_disk_usage =
3600: &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname");
3601: if ($disk_quota == 0) {
3602: $percent = 100.0;
3603: } else {
3604: $percent = $current_disk_usage/(10 * $disk_quota);
3605: }
3606: $userlist->{$user}->[$index{'authorusage'}] = sprintf("%.0f",$percent);
3607: }
3608: if ($needauthorquota) {
3609: $userlist->{$user}->[$index{'authorquota'}] = sprintf("%.2f",$disk_quota);
3610: }
3611: }
1.4 raeburn 3612: $usercount ++;
3613: }
3614: my $autocount = 0;
3615: my $manualcount = 0;
3616: my $lockcount = 0;
3617: my $unlockcount = 0;
3618: if ($usercount) {
3619: $r->print($output);
3620: } else {
3621: if ($mode eq 'autoenroll') {
3622: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
3623: } else {
3624: return;
3625: }
1.1 raeburn 3626: }
1.2 raeburn 3627: #
3628: # Sort the users
1.1 raeburn 3629: my $index = $index{$sortby};
3630: my $second = $index{'username'};
3631: my $third = $index{'domain'};
1.159 raeburn 3632: my @sorted_users;
3633: if (($sortby eq 'authorquota') || ($sortby eq 'authorusage')) {
3634: @sorted_users = sort {
3635: $userlist->{$b}->[$index] <=> $userlist->{$a}->[$index] ||
3636: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
3637: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
3638: } (keys(%$userlist));
3639: } else {
3640: @sorted_users = sort {
3641: lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index]) ||
3642: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
3643: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
3644: } (keys(%$userlist));
3645: }
1.4 raeburn 3646: my $rowcount = 0;
1.178 raeburn 3647: my $disabled;
3648: if ($mode eq 'autoenroll') {
3649: unless ($permission->{'cusr'}) {
3650: $disabled = ' disabled="disabled"';
3651: }
3652: }
1.2 raeburn 3653: foreach my $user (@sorted_users) {
1.4 raeburn 3654: my %in;
1.2 raeburn 3655: my $sdata = $userlist->{$user};
1.4 raeburn 3656: $rowcount ++;
1.2 raeburn 3657: foreach my $item (@{$keylist}) {
3658: $in{$item} = $sdata->[$index{$item}];
3659: }
1.67 droeschl 3660: my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
3661: if ($clickers!~/\w/) { $clickers='-'; }
1.159 raeburn 3662: $in{'clicker'} = $clickers;
1.67 droeschl 3663: my $role = $in{'role'};
1.102 raeburn 3664: $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
1.136 raeburn 3665: unless ($mode eq 'excel') {
3666: if (! defined($in{'start'}) || $in{'start'} == 0) {
3667: $in{'start'} = &mt('none');
3668: } else {
3669: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
3670: }
3671: if (! defined($in{'end'}) || $in{'end'} == 0) {
3672: $in{'end'} = &mt('none');
3673: } else {
3674: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
3675: }
1.1 raeburn 3676: }
1.139 raeburn 3677: if ($context eq 'course') {
3678: my $lastlogin = $crslogins{$in{'username'}.':'.$in{'domain'}.':'.$in{'section'}.':'.$role};
3679: if ($lastlogin ne '') {
3680: $in{'lastlogin'} = &Apache::lonlocal::locallocaltime($lastlogin);
3681: }
3682: }
1.55 raeburn 3683: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2 raeburn 3684: $r->print(&Apache::loncommon::start_data_table_row());
1.11 raeburn 3685: my $checkval;
1.16 raeburn 3686: if ($mode eq 'autoenroll') {
3687: my $cellentry;
3688: if ($in{'type'} eq 'auto') {
1.178 raeburn 3689: $cellentry = '<b>'.&mt('auto').'</b> <label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Change').'</label>';
1.16 raeburn 3690: $autocount ++;
3691: } else {
1.178 raeburn 3692: $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">';
1.16 raeburn 3693: $manualcount ++;
3694: if ($in{'lockedtype'}) {
1.178 raeburn 3695: $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Unlock').'</label>';
1.16 raeburn 3696: $unlockcount ++;
3697: } else {
1.178 raeburn 3698: $cellentry .= '<label><input type="checkbox" name="lockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Lock').'</label>';
1.16 raeburn 3699: $lockcount ++;
1.11 raeburn 3700: }
1.76 bisitz 3701: $cellentry .= '</span></td></tr></table>';
1.16 raeburn 3702: }
3703: $r->print("<td>$cellentry</td>\n");
3704: } else {
1.55 raeburn 3705: if ($mode ne 'pickauthor') {
3706: $r->print("<td>$rowcount</td>\n");
3707: }
1.16 raeburn 3708: if ($actionselect) {
1.26 raeburn 3709: my $showcheckbox;
3710: if ($role =~ /^cr\//) {
3711: $showcheckbox = $canchange{'cr'};
3712: } else {
3713: $showcheckbox = $canchange{$role};
3714: }
3715: if (!$showcheckbox) {
3716: if ($context eq 'course') {
3717: if ($canchangesec{$role} ne '') {
3718: if ($canchangesec{$role} eq $in{'section'}) {
3719: $showcheckbox = 1;
3720: }
3721: }
1.16 raeburn 3722: }
1.26 raeburn 3723: }
3724: if ($showcheckbox) {
3725: $checkval = $user;
3726: if ($context eq 'course') {
1.141 raeburn 3727: if (($role eq 'co' || $role eq 'cc') &&
3728: ($user =~ /^\Q$env{'user.name'}:$env{'user.domain'}:$role\E/)) {
3729: $showcheckbox = 0;
3730: } else {
3731: if ($role eq 'st') {
3732: $checkval .= ':st';
3733: }
3734: $checkval .= ':'.$in{'section'};
3735: if ($role eq 'st') {
3736: $checkval .= ':'.$in{'type'}.':'.
1.150 raeburn 3737: $in{'lockedtype'}.':'.
1.174 raeburn 3738: $in{'credits'}.':'.
3739: &escape($in{'instsec'});
1.141 raeburn 3740: }
3741: }
3742: }
3743: if ($showcheckbox) {
3744: $r->print('<td><input type="checkbox" name="'.
1.183 raeburn 3745: 'actionlist" value="'.
3746: &HTML::Entities::encode($checkval,'&<>"').'" />');
3747: foreach my $item ('start','end') {
3748: $r->print('<input type="hidden" name="'.
3749: &HTML::Entities::encode($checkval.'_'.$item,'&<>"').'"'.
3750: ' value="'.$sdata->[$index{$item}].'" />');
3751: }
3752: $r->print('</td>');
1.141 raeburn 3753: } else {
3754: $r->print('<td> </td>');
1.16 raeburn 3755: }
1.26 raeburn 3756: } else {
3757: $r->print('<td> </td>');
1.16 raeburn 3758: }
1.55 raeburn 3759: } elsif ($mode eq 'pickauthor') {
3760: $r->print('<td><input type="button" name="chooseauthor" onclick="javascript:gochoose('."'$in{'username'}'".');" value="'.&mt('Select').'" /></td>');
1.11 raeburn 3761: }
3762: }
1.2 raeburn 3763: foreach my $item (@cols) {
1.10 raeburn 3764: if ($item eq 'username') {
1.48 raeburn 3765: $r->print('<td>'.&print_username_link($mode,\%in).'</td>');
1.83 raeburn 3766: } elsif ($item eq 'status') {
3767: my $showitem = $in{$item};
3768: if (defined($ltstatus{$in{$item}})) {
3769: $showitem = $ltstatus{$in{$item}};
3770: }
3771: $r->print('<td>'.$showitem.'</td>'."\n");
1.140 raeburn 3772: } elsif ($item eq 'photo') {
3773: if (($context eq 'course') && ($mode ne 'autoenroll') &&
3774: ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
3775: if ($role eq 'st') {
3776: $r->print('<td align="right"><a href="javascript:photowindow('."'".$in{'photo'}."'".')"><img src="'.$in{'thumbnail'}.'" border="1" alt="" /></a></td>');
3777: } else {
3778: $r->print('<td> </td>');
3779: }
3780: }
3781: } elsif ($item eq 'clicker') {
3782: if (($context eq 'course') && ($mode ne 'autoenroll')) {
3783: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
3784: my $clickers =
3785: (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
3786: if ($clickers!~/\w/) { $clickers='-'; }
3787: $r->print('<td>'.$clickers.'</td>');
3788: } else {
3789: $r->print('<td> </td>'."\n");
3790: }
1.149 raeburn 3791: }
1.159 raeburn 3792: } elsif (($item eq 'authorquota') || ($item eq 'authorusage')) {
3793: $r->print('<td align="right">'.$in{$item}.'</td>'."\n");
1.10 raeburn 3794: } else {
3795: $r->print('<td>'.$in{$item}.'</td>'."\n");
3796: }
1.2 raeburn 3797: }
3798: $r->print(&Apache::loncommon::end_data_table_row());
3799: } elsif ($mode eq 'csv') {
3800: next if (! defined($CSVfile));
3801: # no need to bother with $linkto
3802: my @line = ();
3803: foreach my $item (@cols) {
3804: push @line,&Apache::loncommon::csv_translate($in{$item});
3805: }
1.67 droeschl 3806: print $CSVfile '"'.join('","',@line)."\"\n";
1.2 raeburn 3807: } elsif ($mode eq 'excel') {
3808: my $col = 0;
3809: foreach my $item (@cols) {
3810: if ($item eq 'start' || $item eq 'end') {
1.136 raeburn 3811: if ((defined($in{$item})) && ($in{$item} != 0)) {
1.2 raeburn 3812: $excel_sheet->write($row,$col++,
1.136 raeburn 3813: &Apache::lonstathelpers::calc_serial($in{$item}),
1.2 raeburn 3814: $format->{'date'});
3815: } else {
3816: $excel_sheet->write($row,$col++,'none');
3817: }
3818: } else {
3819: $excel_sheet->write($row,$col++,$in{$item});
3820: }
3821: }
3822: $row++;
1.1 raeburn 3823: }
3824: }
1.55 raeburn 3825: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2 raeburn 3826: $r->print(&Apache::loncommon::end_data_table().'<br />');
3827: } elsif ($mode eq 'excel') {
3828: $excel_workbook->close();
1.162 bisitz 3829: $r->print('<p>'.&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '<a href="'.$excel_filename.'">','</a>')."</p>\n");
1.2 raeburn 3830: } elsif ($mode eq 'csv') {
3831: close($CSVfile);
1.162 bisitz 3832: $r->print('<p>'.&mt('[_1]Your CSV file[_2] is ready for download.', '<a href="'.$CSVfilename.'">','</a>')."</p>\n");
1.2 raeburn 3833: $r->rflush();
3834: }
3835: if ($mode eq 'autoenroll') {
3836: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
1.4 raeburn 3837: } else {
3838: return ($usercount);
1.2 raeburn 3839: }
1.1 raeburn 3840: }
3841:
1.56 raeburn 3842: sub bulkaction_javascript {
3843: my ($formname,$caller) = @_;
3844: my $docstart = 'document';
3845: if ($caller eq 'popup') {
3846: $docstart = 'opener.document';
3847: }
3848: my %lt = &Apache::lonlocal::texthash(
3849: acwi => 'Access will be set to start immediately',
3850: asyo => 'as you did not select an end date in the pop-up window',
3851: accw => 'Access will be set to continue indefinitely',
3852: asyd => 'as you did not select an end date in the pop-up window',
3853: sewi => "Sections will be switched to 'No section'",
3854: ayes => "as you either selected the 'No section' option",
3855: oryo => 'or you did not select a section in the pop-up window',
3856: arol => 'A role with no section will be added',
3857: swbs => 'Sections will be switched to:',
3858: rwba => 'Roles will be added for section(s):',
3859: );
3860: my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
3861: my $noaction = &mt("You need to select an action to take for the user(s) you have selected");
3862: my $singconfirm = &mt(' for a single user?');
3863: my $multconfirm = &mt(' for multiple users?');
1.170 damieng 3864: &js_escape(\$alert);
3865: &js_escape(\$noaction);
3866: &js_escape(\$singconfirm);
3867: &js_escape(\$multconfirm);
1.56 raeburn 3868: my $output = <<"ENDJS";
3869: function verify_action (field) {
3870: var numchecked = 0;
3871: var singconf = '$singconfirm';
3872: var multconf = '$multconfirm';
3873: if ($docstart.$formname.elements[field].length > 0) {
3874: for (i=0; i<$docstart.$formname.elements[field].length; i++) {
3875: if ($docstart.$formname.elements[field][i].checked == true) {
3876: numchecked ++;
3877: }
3878: }
3879: } else {
3880: if ($docstart.$formname.elements[field].checked == true) {
3881: numchecked ++;
3882: }
3883: }
3884: if (numchecked == 0) {
3885: alert("$alert");
3886: return;
3887: } else {
3888: var message = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].text;
3889: var choice = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].value;
3890: if (choice == '') {
3891: alert("$noaction");
3892: return;
3893: } else {
3894: if (numchecked == 1) {
3895: message += singconf;
3896: } else {
3897: message += multconf;
3898: }
3899: ENDJS
3900: if ($caller ne 'popup') {
3901: $output .= <<"NEWWIN";
3902: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate' || choice == 'chgsec') {
3903: opendatebrowser(document.$formname,'$formname','go');
3904: return;
3905:
3906: } else {
3907: if (confirm(message)) {
3908: document.$formname.phase.value = 'bulkchange';
3909: document.$formname.submit();
3910: return;
3911: }
3912: }
3913: NEWWIN
3914: } else {
3915: $output .= <<"POPUP";
3916: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
3917: var datemsg = '';
3918: if (($docstart.$formname.startdate_month.value == '') &&
3919: ($docstart.$formname.startdate_day.value == '') &&
3920: ($docstart.$formname.startdate_year.value == '')) {
3921: datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
3922: }
3923: if (($docstart.$formname.enddate_month.value == '') &&
3924: ($docstart.$formname.enddate_day.value == '') &&
3925: ($docstart.$formname.enddate_year.value == '')) {
3926: datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
3927: }
3928: if (datemsg != '') {
3929: message += "\\n"+datemsg;
3930: }
3931: }
3932: if (choice == 'chgsec') {
3933: var rolefilter = $docstart.$formname.showrole.options[$docstart.$formname.showrole.selectedIndex].value;
3934: var retained = $docstart.$formname.retainsec.value;
3935: var secshow = $docstart.$formname.newsecs.value;
3936: if (secshow == '') {
3937: if (rolefilter == 'st' || retained == 0 || retained == "") {
3938: message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
3939: } else {
3940: message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
3941: }
3942: } else {
3943: if (rolefilter == 'st' || retained == 0 || retained == "") {
3944: message += "\\n\\n$lt{'swbs'} "+secshow+".\\n";
3945: } else {
3946: message += "\\n\\n$lt{'rwba'} "+secshow+".\\n";
3947: }
3948: }
3949: }
3950: if (confirm(message)) {
3951: $docstart.$formname.phase.value = 'bulkchange';
3952: $docstart.$formname.submit();
3953: window.close();
3954: }
3955: POPUP
3956: }
3957: $output .= '
3958: }
3959: }
3960: }
3961: ';
3962: return $output;
3963: }
3964:
1.10 raeburn 3965: sub print_username_link {
1.48 raeburn 3966: my ($mode,$in) = @_;
1.10 raeburn 3967: my $output;
1.16 raeburn 3968: if ($mode eq 'autoenroll') {
3969: $output = $in->{'username'};
1.10 raeburn 3970: } else {
3971: $output = '<a href="javascript:username_display_launch('.
1.112 bisitz 3972: "'$in->{'username'}','$in->{'domain'}'".')">'.
1.10 raeburn 3973: $in->{'username'}.'</a>';
3974: }
3975: return $output;
3976: }
3977:
1.2 raeburn 3978: sub role_type_names {
3979: my %lt = &Apache::lonlocal::texthash (
1.13 raeburn 3980: 'domain' => 'Domain Roles',
3981: 'author' => 'Co-Author Roles',
3982: 'course' => 'Course Roles',
1.101 raeburn 3983: 'community' => 'Community Roles',
1.2 raeburn 3984: );
3985: return %lt;
3986: }
3987:
1.11 raeburn 3988: sub select_actions {
1.55 raeburn 3989: my ($context,$setting,$statusmode,$formname) = @_;
1.11 raeburn 3990: my %lt = &Apache::lonlocal::texthash(
3991: revoke => "Revoke user roles",
3992: delete => "Delete user roles",
3993: reenable => "Re-enable expired user roles",
3994: activate => "Make future user roles active now",
3995: chgdates => "Change starting/ending dates",
3996: chgsec => "Change section associated with user roles",
3997: );
1.150 raeburn 3998: # FIXME Add an option to change credits for student roles.
1.11 raeburn 3999: my ($output,$options,%choices);
1.23 raeburn 4000: # FIXME Disable actions for now for roletype=course in domain context
4001: if ($context eq 'domain' && $setting eq 'course') {
4002: return;
4003: }
1.26 raeburn 4004: if ($context eq 'course') {
4005: if ($env{'form.showrole'} ne 'Any') {
1.141 raeburn 4006: my $showactions;
4007: if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},
4008: $env{'request.course.id'})) {
4009: $showactions = 1;
4010: } elsif ($env{'request.course.sec'} ne '') {
4011: if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
4012: $showactions = 1;
4013: }
4014: }
4015: unless ($showactions) {
4016: unless (&is_courseowner($env{'request.course.id'},
4017: $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
4018: return;
4019: }
1.26 raeburn 4020: }
4021: }
4022: }
1.11 raeburn 4023: if ($statusmode eq 'Any') {
4024: $options .= '
4025: <option value="chgdates">'.$lt{'chgdates'}.'</option>';
4026: $choices{'dates'} = 1;
4027: } else {
4028: if ($statusmode eq 'Future') {
4029: $options .= '
4030: <option value="activate">'.$lt{'activate'}.'</option>';
4031: $choices{'dates'} = 1;
4032: } elsif ($statusmode eq 'Expired') {
4033: $options .= '
4034: <option value="reenable">'.$lt{'reenable'}.'</option>';
4035: $choices{'dates'} = 1;
4036: }
1.13 raeburn 4037: if ($statusmode eq 'Active' || $statusmode eq 'Future') {
4038: $options .= '
4039: <option value="chgdates">'.$lt{'chgdates'}.'</option>
4040: <option value="revoke">'.$lt{'revoke'}.'</option>';
4041: $choices{'dates'} = 1;
4042: }
1.11 raeburn 4043: }
4044: if ($context eq 'domain') {
4045: $options .= '
4046: <option value="delete">'.$lt{'delete'}.'</option>';
4047: }
4048: if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
1.26 raeburn 4049: if (($statusmode ne 'Expired') && ($env{'request.course.sec'} eq '')) {
1.11 raeburn 4050: $options .= '
4051: <option value="chgsec">'.$lt{'chgsec'}.'</option>';
4052: $choices{'sections'} = 1;
4053: }
4054: }
4055: if ($options) {
1.56 raeburn 4056: $output = '<select name="bulkaction">'."\n".
1.11 raeburn 4057: '<option value="" selected="selected">'.
4058: &mt('Please select').'</option>'."\n".$options."\n".'</select>';
4059: if ($choices{'dates'}) {
4060: $output .=
4061: '<input type="hidden" name="startdate_month" value="" />'."\n".
4062: '<input type="hidden" name="startdate_day" value="" />'."\n".
4063: '<input type="hidden" name="startdate_year" value="" />'."\n".
4064: '<input type="hidden" name="startdate_hour" value="" />'."\n".
4065: '<input type="hidden" name="startdate_minute" value="" />'."\n".
4066: '<input type="hidden" name="startdate_second" value="" />'."\n".
4067: '<input type="hidden" name="enddate_month" value="" />'."\n".
4068: '<input type="hidden" name="enddate_day" value="" />'."\n".
4069: '<input type="hidden" name="enddate_year" value="" />'."\n".
4070: '<input type="hidden" name="enddate_hour" value="" />'."\n".
4071: '<input type="hidden" name="enddate_minute" value="" />'."\n".
1.56 raeburn 4072: '<input type="hidden" name="enddate_second" value="" />'."\n".
4073: '<input type="hidden" name="no_end_date" value="" />'."\n";
1.11 raeburn 4074: if ($context eq 'course') {
4075: $output .= '<input type="hidden" name="makedatesdefault" value="" />'."\n";
4076: }
4077: }
4078: if ($choices{'sections'}) {
1.91 bisitz 4079: $output .= '<input type="hidden" name="retainsec" value="" />'."\n".
4080: '<input type="hidden" name="newsecs" value="" />'."\n";
1.11 raeburn 4081: }
4082: }
4083: return $output;
4084: }
4085:
4086: sub date_section_javascript {
4087: my ($context,$setting) = @_;
1.49 raeburn 4088: my $title = 'Date_And_Section_Selector';
1.41 raeburn 4089: my %nopopup = &Apache::lonlocal::texthash (
4090: revoke => "Check the boxes for any users for whom roles are to be revoked, and click 'Proceed'",
4091: delete => "Check the boxes for any users for whom roles are to be deleted, and click 'Proceed'",
4092: none => "Choose an action to take for selected users",
4093: );
1.96 bisitz 4094: my $output = <<"ENDONE";
4095: <script type="text/javascript">
4096: // <![CDATA[
1.41 raeburn 4097: function opendatebrowser(callingform,formname,calledby) {
1.11 raeburn 4098: var bulkaction = callingform.bulkaction.options[callingform.bulkaction.selectedIndex].value;
4099: var url = '/adm/createuser?';
4100: var type = '';
4101: var showrole = callingform.showrole.options[callingform.showrole.selectedIndex].value;
4102: ENDONE
4103: if ($context eq 'domain') {
4104: $output .= '
4105: type = callingform.roletype.options[callingform.roletype.selectedIndex].value;
4106: ';
4107: }
4108: my $width= '700';
4109: my $height = '400';
4110: $output .= <<"ENDTWO";
4111: url += 'action=dateselect&callingform=' + formname +
4112: '&roletype='+type+'&showrole='+showrole +'&bulkaction='+bulkaction;
4113: var title = '$title';
4114: var options = 'scrollbars=1,resizable=1,menubar=0';
4115: options += ',width=$width,height=$height';
4116: stdeditbrowser = open(url,title,options,'1');
4117: stdeditbrowser.focus();
4118: }
1.96 bisitz 4119: // ]]>
1.11 raeburn 4120: </script>
4121: ENDTWO
4122: return $output;
4123: }
4124:
4125: sub date_section_selector {
1.150 raeburn 4126: my ($context,$permission,$crstype,$showcredits) = @_;
1.11 raeburn 4127: my $callingform = $env{'form.callingform'};
4128: my $formname = 'dateselect';
4129: my $groupslist = &get_groupslist();
1.150 raeburn 4130: my $sec_js =
4131: &setsections_javascript($formname,$groupslist,undef,undef,$crstype,
4132: $showcredits);
1.11 raeburn 4133: my $output = <<"END";
4134: <script type="text/javascript">
1.96 bisitz 4135: // <![CDATA[
1.11 raeburn 4136:
4137: $sec_js
4138:
4139: function saveselections(formname) {
4140:
4141: END
4142: if ($env{'form.bulkaction'} eq 'chgsec') {
4143: $output .= <<"END";
1.40 raeburn 4144: if (formname.retainsec.length > 1) {
4145: for (var i=0; i<formname.retainsec.length; i++) {
4146: if (formname.retainsec[i].checked == true) {
4147: opener.document.$callingform.retainsec.value = formname.retainsec[i].value;
4148: }
4149: }
4150: } else {
4151: opener.document.$callingform.retainsec.value = formname.retainsec.value;
4152: }
1.103 raeburn 4153: setSections(formname,'$crstype');
1.11 raeburn 4154: if (seccheck == 'ok') {
4155: opener.document.$callingform.newsecs.value = formname.sections.value;
1.205 raeburn 4156: } else {
4157: return;
1.11 raeburn 4158: }
4159: END
4160: } else {
4161: if ($context eq 'course') {
4162: if (($env{'form.bulkaction'} eq 'reenable') ||
4163: ($env{'form.bulkaction'} eq 'activate') ||
4164: ($env{'form.bulkaction'} eq 'chgdates')) {
1.26 raeburn 4165: if ($env{'request.course.sec'} eq '') {
4166: $output .= <<"END";
1.11 raeburn 4167:
4168: if (formname.makedatesdefault.checked == true) {
4169: opener.document.$callingform.makedatesdefault.value = 1;
4170: }
4171: else {
4172: opener.document.$callingform.makedatesdefault.value = 0;
4173: }
4174:
4175: END
1.26 raeburn 4176: }
1.11 raeburn 4177: }
4178: }
4179: $output .= <<"END";
4180: opener.document.$callingform.startdate_month.value = formname.startdate_month.options[formname.startdate_month.selectedIndex].value;
4181: opener.document.$callingform.startdate_day.value = formname.startdate_day.value;
4182: opener.document.$callingform.startdate_year.value = formname.startdate_year.value;
4183: opener.document.$callingform.startdate_hour.value = formname.startdate_hour.options[formname.startdate_hour.selectedIndex].value;
4184: opener.document.$callingform.startdate_minute.value = formname.startdate_minute.value;
4185: opener.document.$callingform.startdate_second.value = formname.startdate_second.value;
4186: opener.document.$callingform.enddate_month.value = formname.enddate_month.options[formname.enddate_month.selectedIndex].value;
4187: opener.document.$callingform.enddate_day.value = formname.enddate_day.value;
4188: opener.document.$callingform.enddate_year.value = formname.enddate_year.value;
4189: opener.document.$callingform.enddate_hour.value = formname.enddate_hour.options[formname.enddate_hour.selectedIndex].value;
4190: opener.document.$callingform.enddate_minute.value = formname.enddate_minute.value;
4191: opener.document.$callingform.enddate_second.value = formname.enddate_second.value;
1.56 raeburn 4192: if (formname.no_end_date.checked) {
4193: opener.document.$callingform.no_end_date.value = '1';
4194: } else {
4195: opener.document.$callingform.no_end_date.value = '0';
4196: }
1.11 raeburn 4197: END
4198: }
1.56 raeburn 4199: my $verify_action_js = &bulkaction_javascript($callingform,'popup');
4200: $output .= <<"ENDJS";
4201: verify_action('actionlist');
1.11 raeburn 4202: }
1.56 raeburn 4203:
4204: $verify_action_js
4205:
1.96 bisitz 4206: // ]]>
1.11 raeburn 4207: </script>
1.56 raeburn 4208: ENDJS
1.11 raeburn 4209: my %lt = &Apache::lonlocal::texthash (
4210: chac => 'Access dates to apply for selected users',
4211: chse => 'Changes in section affiliation to apply to selected users',
1.118 raeburn 4212: 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.',
4213: forn => 'For a course role that is not "student", users may have roles in more than one section at a time.',
4214: reta => "Retain each user's current section affiliations?",
1.103 raeburn 4215: dnap => '(Does not apply to student roles).',
1.11 raeburn 4216: );
4217: my ($date_items,$headertext);
4218: if ($env{'form.bulkaction'} eq 'chgsec') {
4219: $headertext = $lt{'chse'};
4220: } else {
4221: $headertext = $lt{'chac'};
4222: my $starttime;
4223: if (($env{'form.bulkaction'} eq 'activate') ||
4224: ($env{'form.bulkaction'} eq 'reenable')) {
4225: $starttime = time;
4226: }
4227: $date_items = &date_setting_table($starttime,undef,$context,
1.21 raeburn 4228: $env{'form.bulkaction'},$formname,
1.101 raeburn 4229: $permission,$crstype);
1.11 raeburn 4230: }
4231: $output .= '<h3>'.$headertext.'</h3>'.
1.118 raeburn 4232: '<form name="'.$formname.'" method="post" action="">'."\n".
1.11 raeburn 4233: $date_items;
4234: if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
1.17 raeburn 4235: my ($cnum,$cdom) = &get_course_identity();
1.103 raeburn 4236: if ($crstype eq 'Community') {
1.118 raeburn 4237: $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.');
4238: $lt{'forn'} = &mt('For a community role that is not "member", users may have roles in more than one section at a time.');
1.103 raeburn 4239: $lt{'dnap'} = &mt('(Does not apply to member roles).');
4240: }
1.11 raeburn 4241: my $info;
4242: if ($env{'form.showrole'} eq 'st') {
4243: $output .= '<p>'.$lt{'fors'}.'</p>';
1.26 raeburn 4244: } elsif ($env{'form.showrole'} eq 'Any') {
1.11 raeburn 4245: $output .= '<p>'.$lt{'fors'}.'</p>'.
4246: '<p>'.$lt{'forn'}.' ';
4247: $info = $lt{'reta'};
4248: } else {
4249: $output .= '<p>'.$lt{'forn'}.' ';
4250: $info = $lt{'reta'};
4251: }
4252: if ($info) {
4253: $info .= '<span class="LC_nobreak">'.
4254: '<label><input type="radio" name="retainsec" value="1" '.
4255: 'checked="checked" />'.&mt('Yes').'</label> '.
4256: '<label><input type="radio" name="retainsec" value="0" />'.
4257: &mt('No').'</label></span>';
4258: if ($env{'form.showrole'} eq 'Any') {
4259: $info .= '<br />'.$lt{'dnap'};
4260: }
4261: $info .= '</p>';
4262: } else {
4263: $info = '<input type="hidden" name="retainsec" value="0" />';
4264: }
1.21 raeburn 4265: my $rowtitle = &mt('New section to assign');
1.150 raeburn 4266: my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,
4267: $permission,$context,'chgsec',$crstype);
1.11 raeburn 4268: $output .= $info.$secbox;
4269: }
4270: $output .= '<p>'.
1.81 schafran 4271: '<input type="button" name="dateselection" value="'.&mt('Save').'" onclick="javascript:saveselections(this.form)" /></p>'."\n".
1.11 raeburn 4272: '</form>';
4273: return $output;
4274: }
4275:
1.17 raeburn 4276: sub section_picker {
1.150 raeburn 4277: my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode,$crstype,
4278: $showcredits,$credits) = @_;
1.17 raeburn 4279: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
4280: my $sections_select .= &course_sections(\%sections_count,$role);
1.118 raeburn 4281: my $secbox = '<div>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
1.17 raeburn 4282: if ($mode eq 'upload') {
4283: my ($options,$cb_script,$coursepick) =
1.150 raeburn 4284: &default_role_selector($context,1,$crstype,$showcredits);
1.59 bisitz 4285: $secbox .= &Apache::lonhtmlcommon::row_title(&mt('role'),'LC_oddrow_value').
1.17 raeburn 4286: $options. &Apache::lonhtmlcommon::row_closure(1)."\n";
4287: }
4288: $secbox .= &Apache::lonhtmlcommon::row_title($rowtitle,'LC_oddrow_value')."\n";
4289: if ($env{'request.course.sec'} eq '') {
4290: $secbox .= '<table class="LC_createuser"><tr class="LC_section_row">'."\n".
4291: '<td align="center">'.&mt('Existing sections')."\n".
4292: '<br />'.$sections_select.'</td><td align="center">'.
4293: &mt('New section').'<br />'."\n".
1.118 raeburn 4294: '<input type="text" name="newsec" size="15" value="" />'."\n".
1.17 raeburn 4295: '<input type="hidden" name="sections" value="" />'."\n".
4296: '</td></tr></table>'."\n";
4297: } else {
1.149 raeburn 4298: $secbox .= '<input type="hidden" name="sections" value="'.
1.17 raeburn 4299: $env{'request.course.sec'}.'" />'.
4300: $env{'request.course.sec'};
4301: }
1.150 raeburn 4302: $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n";
4303: unless ($mode eq 'chgsec') {
4304: if ($showcredits) {
4305: $secbox .=
4306: &Apache::lonhtmlcommon::row_title(&mt('credits (students)'),
4307: 'LC_evenrow_value')."\n".
4308: '<input type="text" name="credits" size="3" value="'.$credits.'" />'."\n".
4309: &Apache::lonhtmlcommon::row_closure(1)."\n";
4310: }
4311: }
4312: $secbox .= &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.17 raeburn 4313: return $secbox;
4314: }
4315:
1.2 raeburn 4316: sub results_header_row {
1.102 raeburn 4317: my ($rolefilter,$statusmode,$context,$permission,$mode,$crstype) = @_;
1.5 raeburn 4318: my ($description,$showfilter);
4319: if ($rolefilter ne 'Any') {
4320: $showfilter = $rolefilter;
4321: }
1.2 raeburn 4322: if ($context eq 'course') {
1.24 raeburn 4323: if ($mode eq 'csv' || $mode eq 'excel') {
1.102 raeburn 4324: if ($crstype eq 'Community') {
4325: $description = &mt('Community - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
4326: } else {
4327: $description = &mt('Course - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
4328: }
1.24 raeburn 4329: }
1.2 raeburn 4330: if ($statusmode eq 'Expired') {
1.102 raeburn 4331: if ($crstype eq 'Community') {
4332: $description .= &mt('Users in community with expired [_1] roles',$showfilter);
4333: } else {
4334: $description .= &mt('Users in course with expired [_1] roles',$showfilter);
4335: }
1.11 raeburn 4336: } elsif ($statusmode eq 'Future') {
1.102 raeburn 4337: if ($crstype eq 'Community') {
4338: $description .= &mt('Users in community with future [_1] roles',$showfilter);
4339: } else {
4340: $description .= &mt('Users in course with future [_1] roles',$showfilter);
4341: }
1.2 raeburn 4342: } elsif ($statusmode eq 'Active') {
1.102 raeburn 4343: if ($crstype eq 'Community') {
4344: $description .= &mt('Users in community with active [_1] roles',$showfilter);
4345: } else {
4346: $description .= &mt('Users in course with active [_1] roles',$showfilter);
4347: }
1.2 raeburn 4348: } else {
4349: if ($rolefilter eq 'Any') {
1.102 raeburn 4350: if ($crstype eq 'Community') {
4351: $description .= &mt('All users in community');
4352: } else {
4353: $description .= &mt('All users in course');
4354: }
1.2 raeburn 4355: } else {
1.102 raeburn 4356: if ($crstype eq 'Community') {
4357: $description .= &mt('All users in community with [_1] roles',$rolefilter);
4358: } else {
4359: $description .= &mt('All users in course with [_1] roles',$rolefilter);
4360: }
1.2 raeburn 4361: }
4362: }
1.33 raeburn 4363: my $constraint;
1.26 raeburn 4364: my $viewablesec = &viewable_section($permission);
4365: if ($viewablesec ne '') {
1.15 raeburn 4366: if ($env{'form.showrole'} eq 'st') {
1.33 raeburn 4367: $constraint = &mt('only users in section "[_1]"',$viewablesec);
1.103 raeburn 4368: } elsif (($env{'form.showrole'} ne 'cc') && ($env{'form.showrole'} ne 'co')) {
1.33 raeburn 4369: $constraint = &mt('only users affiliated with no section or section "[_1]"',$viewablesec);
4370: }
4371: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
4372: if ($env{'form.grpfilter'} eq 'none') {
4373: $constraint .= &mt(' and not in any group');
4374: } else {
4375: $constraint .= &mt(' and members of group: "[_1]"',$env{'form.grpfilter'});
4376: }
4377: }
4378: } else {
4379: if (($env{'form.secfilter'} ne 'all') && ($env{'form.secfilter'} ne '')) {
4380: if ($env{'form.secfilter'} eq 'none') {
4381: $constraint = &mt('only users affiliated with no section');
4382: } else {
4383: $constraint = &mt('only users affiliated with section "[_1]"',$env{'form.secfilter'});
4384: }
4385: }
4386: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
4387: if ($env{'form.grpfilter'} eq 'none') {
4388: if ($constraint eq '') {
4389: $constraint = &mt('only users not in any group');
4390: } else {
4391: $constraint .= &mt(' and also not in any group');
4392: }
4393: } else {
4394: if ($constraint eq '') {
4395: $constraint = &mt('only members of group: "[_1]"',$env{'form.grpfilter'});
4396: } else {
4397: $constraint .= &mt(' and also members of group: "[_1]"'.$env{'form.grpfilter'});
4398: }
4399: }
1.15 raeburn 4400: }
4401: }
1.33 raeburn 4402: if ($constraint ne '') {
4403: $description .= ' ('.$constraint.')';
4404: }
1.13 raeburn 4405: } elsif ($context eq 'author') {
1.14 raeburn 4406: $description =
1.73 bisitz 4407: &mt('Author space for [_1]'
4408: ,'<span class="LC_cusr_emph">'
4409: .&Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'})
4410: .'</span>')
4411: .': ';
1.2 raeburn 4412: if ($statusmode eq 'Expired') {
1.5 raeburn 4413: $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
1.2 raeburn 4414: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4415: $description .= &mt('Co-authors with future [_1] roles',$showfilter);
1.2 raeburn 4416: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4417: $description .= &mt('Co-authors with active [_1] roles',$showfilter);
1.2 raeburn 4418: } else {
4419: if ($rolefilter eq 'Any') {
1.5 raeburn 4420: $description .= &mt('All co-authors');
1.2 raeburn 4421: } else {
4422: $description .= &mt('All co-authors with [_1] roles',$rolefilter);
4423: }
4424: }
4425: } elsif ($context eq 'domain') {
4426: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.73 bisitz 4427: $description = &mt('Domain - [_1]:',$domdesc).' ';
1.2 raeburn 4428: if ($env{'form.roletype'} eq 'domain') {
4429: if ($statusmode eq 'Expired') {
1.5 raeburn 4430: $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
1.2 raeburn 4431: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4432: $description .= &mt('Users in domain with future [_1] roles',$showfilter);
1.2 raeburn 4433: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4434: $description .= &mt('Users in domain with active [_1] roles',$showfilter);
1.2 raeburn 4435: } else {
4436: if ($rolefilter eq 'Any') {
1.5 raeburn 4437: $description .= &mt('All users in domain');
1.2 raeburn 4438: } else {
4439: $description .= &mt('All users in domain with [_1] roles',$rolefilter);
4440: }
4441: }
1.13 raeburn 4442: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 4443: if ($statusmode eq 'Expired') {
1.5 raeburn 4444: $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
1.2 raeburn 4445: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4446: $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
1.2 raeburn 4447: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4448: $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
1.2 raeburn 4449: } else {
4450: if ($rolefilter eq 'Any') {
1.5 raeburn 4451: $description .= &mt('All users with co-author roles in domain',$showfilter);
1.2 raeburn 4452: } else {
1.116 bisitz 4453: $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
1.2 raeburn 4454: }
4455: }
1.102 raeburn 4456: } elsif (($env{'form.roletype'} eq 'course') ||
4457: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 4458: my $coursefilter = $env{'form.coursepick'};
1.102 raeburn 4459: if ($env{'form.roletype'} eq 'course') {
4460: if ($coursefilter eq 'category') {
4461: my $instcode = &instcode_from_coursefilter();
4462: if ($instcode eq '.') {
4463: $description .= &mt('All courses in domain').' - ';
4464: } else {
4465: $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
4466: }
4467: } elsif ($coursefilter eq 'selected') {
4468: $description .= &mt('Selected courses in domain').' - ';
4469: } elsif ($coursefilter eq 'all') {
1.2 raeburn 4470: $description .= &mt('All courses in domain').' - ';
4471: }
1.102 raeburn 4472: } elsif ($env{'form.roletype'} eq 'community') {
4473: if ($coursefilter eq 'selected') {
4474: $description .= &mt('Selected communities in domain').' - ';
4475: } elsif ($coursefilter eq 'all') {
4476: $description .= &mt('All communities in domain').' - ';
4477: }
1.2 raeburn 4478: }
4479: if ($statusmode eq 'Expired') {
1.5 raeburn 4480: $description .= &mt('users with expired [_1] roles',$showfilter);
1.2 raeburn 4481: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4482: $description .= &mt('users with future [_1] roles',$showfilter);
1.2 raeburn 4483: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4484: $description .= &mt('users with active [_1] roles',$showfilter);
1.2 raeburn 4485: } else {
4486: if ($rolefilter eq 'Any') {
4487: $description .= &mt('all users');
4488: } else {
4489: $description .= &mt('users with [_1] roles',$rolefilter);
4490: }
4491: }
4492: }
4493: }
4494: return $description;
4495: }
1.22 raeburn 4496:
4497: sub viewable_section {
4498: my ($permission) = @_;
4499: my $viewablesec;
4500: if (ref($permission) eq 'HASH') {
4501: if (exists($permission->{'view_section'})) {
4502: $viewablesec = $permission->{'view_section'};
4503: } elsif (exists($permission->{'cusr_section'})) {
4504: $viewablesec = $permission->{'cusr_section'};
4505: }
4506: }
4507: return $viewablesec;
4508: }
4509:
1.2 raeburn 4510:
1.1 raeburn 4511: #################################################
4512: #################################################
4513: sub show_drop_list {
1.101 raeburn 4514: my ($r,$classlist,$nosort,$permission,$crstype) = @_;
1.29 raeburn 4515: my $cid = $env{'request.course.id'};
1.17 raeburn 4516: my ($cnum,$cdom) = &get_course_identity($cid);
1.1 raeburn 4517: if (! exists($env{'form.sortby'})) {
4518: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
4519: ['sortby']);
4520: }
4521: my $sortby = $env{'form.sortby'};
4522: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
4523: $sortby = 'username';
4524: }
4525: my $action = "drop";
1.17 raeburn 4526: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
1.1 raeburn 4527: $r->print(<<END);
4528: <input type="hidden" name="sortby" value="$sortby" />
4529: <input type="hidden" name="action" value="$action" />
4530: <input type="hidden" name="state" value="done" />
1.17 raeburn 4531: <script type="text/javascript" language="Javascript">
1.96 bisitz 4532: // <![CDATA[
1.17 raeburn 4533: $check_uncheck_js
1.96 bisitz 4534: // ]]>
1.1 raeburn 4535: </script>
1.86 bisitz 4536: <input type="hidden" name="phase" value="four" />
1.1 raeburn 4537: END
1.30 raeburn 4538: my ($indexhash,$keylist) = &make_keylist_array();
4539: my $studentcount = 0;
4540: if (ref($classlist) eq 'HASH') {
4541: foreach my $student (keys(%{$classlist})) {
4542: my $sdata = $classlist->{$student};
4543: my $status = $sdata->[$indexhash->{'status'}];
4544: my $section = $sdata->[$indexhash->{'section'}];
4545: if ($status ne 'Active') {
4546: delete($classlist->{$student});
4547: next;
4548: }
4549: if ($env{'request.course.sec'} ne '') {
4550: if ($section ne $env{'request.course.sec'}) {
4551: delete($classlist->{$student});
4552: next;
4553: }
4554: }
4555: $studentcount ++;
4556: }
4557: }
4558: if (!$studentcount) {
1.143 bisitz 4559: my $msg = '';
1.101 raeburn 4560: if ($crstype eq 'Community') {
1.143 bisitz 4561: $msg = &mt('There are no members to drop.');
1.101 raeburn 4562: } else {
1.143 bisitz 4563: $msg = &mt('There are no students to drop.');
1.101 raeburn 4564: }
1.143 bisitz 4565: $r->print('<p class="LC_info">'.$msg.'</p>');
1.30 raeburn 4566: return;
4567: }
4568: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
4569: $classlist,$keylist,$cdom,$cnum);
4570: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
4571: 'dom' => "domain",
1.162 bisitz 4572: 'id' => "ID",
1.30 raeburn 4573: 'sn' => "student name",
1.101 raeburn 4574: 'mn' => "member name",
1.30 raeburn 4575: 'sec' => "section",
4576: 'start' => "start date",
4577: 'end' => "end date",
4578: 'groups' => "active groups",
4579: );
1.101 raeburn 4580: my $nametitle = $lt{'sn'};
4581: if ($crstype eq 'Community') {
4582: $nametitle = $lt{'mn'};
4583: }
1.1 raeburn 4584: if ($nosort) {
1.17 raeburn 4585: $r->print(&Apache::loncommon::start_data_table().
4586: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 4587: $r->print(<<END);
4588: <th> </th>
4589: <th>$lt{'usrn'}</th>
4590: <th>$lt{'dom'}</th>
1.162 bisitz 4591: <th>$lt{'id'}</th>
1.101 raeburn 4592: <th>$nametitle</th>
1.1 raeburn 4593: <th>$lt{'sec'}</th>
4594: <th>$lt{'start'}</th>
4595: <th>$lt{'end'}</th>
4596: <th>$lt{'groups'}</th>
4597: END
1.17 raeburn 4598: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 4599: } else {
1.17 raeburn 4600: $r->print(&Apache::loncommon::start_data_table().
4601: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 4602: $r->print(<<END);
1.17 raeburn 4603: <th> </th>
1.1 raeburn 4604: <th>
1.162 bisitz 4605: <a href="/adm/createuser?action=$action&sortby=username">$lt{'usrn'}</a>
1.1 raeburn 4606: </th><th>
1.162 bisitz 4607: <a href="/adm/createuser?action=$action&sortby=domain">$lt{'dom'}</a>
1.1 raeburn 4608: </th><th>
1.162 bisitz 4609: <a href="/adm/createuser?action=$action&sortby=id">$lt{'id'}</a>
1.1 raeburn 4610: </th><th>
1.162 bisitz 4611: <a href="/adm/createuser?action=$action&sortby=fullname">$nametitle</a>
1.1 raeburn 4612: </th><th>
1.162 bisitz 4613: <a href="/adm/createuser?action=$action&sortby=section">$lt{'sec'}</a>
1.1 raeburn 4614: </th><th>
1.162 bisitz 4615: <a href="/adm/createuser?action=$action&sortby=start">$lt{'start'}</a>
1.1 raeburn 4616: </th><th>
1.162 bisitz 4617: <a href="/adm/createuser?action=$action&sortby=end">$lt{'end'}</a>
1.1 raeburn 4618: </th><th>
1.162 bisitz 4619: <a href="/adm/createuser?action=$action&sortby=groups">$lt{'groups'}</a>
1.1 raeburn 4620: </th>
4621: END
1.17 raeburn 4622: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 4623: }
4624: #
4625: # Sort the students
1.30 raeburn 4626: my $index = $indexhash->{$sortby};
4627: my $second = $indexhash->{'username'};
4628: my $third = $indexhash->{'domain'};
1.1 raeburn 4629: my @Sorted_Students = sort {
4630: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
4631: ||
4632: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
4633: ||
4634: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
1.30 raeburn 4635: } (keys(%{$classlist}));
1.1 raeburn 4636: foreach my $student (@Sorted_Students) {
4637: my $error;
4638: my $sdata = $classlist->{$student};
1.30 raeburn 4639: my $username = $sdata->[$indexhash->{'username'}];
4640: my $domain = $sdata->[$indexhash->{'domain'}];
4641: my $section = $sdata->[$indexhash->{'section'}];
4642: my $name = $sdata->[$indexhash->{'fullname'}];
4643: my $id = $sdata->[$indexhash->{'id'}];
4644: my $start = $sdata->[$indexhash->{'start'}];
4645: my $end = $sdata->[$indexhash->{'end'}];
1.1 raeburn 4646: my $groups = $classgroups->{$student};
4647: my $active_groups;
4648: if (ref($groups->{active}) eq 'HASH') {
4649: $active_groups = join(', ',keys(%{$groups->{'active'}}));
4650: }
4651: if (! defined($start) || $start == 0) {
4652: $start = &mt('none');
4653: } else {
4654: $start = &Apache::lonlocal::locallocaltime($start);
4655: }
4656: if (! defined($end) || $end == 0) {
4657: $end = &mt('none');
4658: } else {
4659: $end = &Apache::lonlocal::locallocaltime($end);
4660: }
1.17 raeburn 4661: my $studentkey = $student.':'.$section;
1.30 raeburn 4662: my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$indexhash->{'start'}].'" />';
1.1 raeburn 4663: #
4664: $r->print(&Apache::loncommon::start_data_table_row());
4665: $r->print(<<"END");
1.86 bisitz 4666: <td><input type="checkbox" name="droplist" value="$studentkey" /></td>
1.1 raeburn 4667: <td>$username</td>
4668: <td>$domain</td>
4669: <td>$id</td>
4670: <td>$name</td>
4671: <td>$section</td>
1.29 raeburn 4672: <td>$start $startitem</td>
1.1 raeburn 4673: <td>$end</td>
4674: <td>$active_groups</td>
4675: END
4676: $r->print(&Apache::loncommon::end_data_table_row());
4677: }
4678: $r->print(&Apache::loncommon::end_data_table().'<br />');
4679: %lt=&Apache::lonlocal::texthash(
1.29 raeburn 4680: 'dp' => "Drop Students",
1.101 raeburn 4681: 'dm' => "Drop Members",
1.1 raeburn 4682: 'ca' => "check all",
4683: 'ua' => "uncheck all",
4684: );
1.101 raeburn 4685: my $btn = $lt{'dp'};
4686: if ($crstype eq 'Community') {
4687: $btn = $lt{'dm'};
4688: }
1.1 raeburn 4689: $r->print(<<"END");
1.89 bisitz 4690: <p>
1.86 bisitz 4691: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)" />
4692: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)" />
1.89 bisitz 4693: </p>
4694: <p>
1.101 raeburn 4695: <input type="submit" value="$btn" />
1.89 bisitz 4696: </p>
1.1 raeburn 4697: END
4698: return;
4699: }
4700:
4701: #
4702: # Print out the initial form to get the file containing a list of users
4703: #
4704: sub print_first_users_upload_form {
4705: my ($r,$context) = @_;
4706: my $str;
1.86 bisitz 4707: $str = '<input type="hidden" name="phase" value="two" />';
1.1 raeburn 4708: $str .= '<input type="hidden" name="action" value="upload" />';
1.101 raeburn 4709: $str .= '<input type="hidden" name="state" value="got_file" />';
1.95 bisitz 4710:
1.147 bisitz 4711: $str .= &Apache::grades::checkforfile_js();
4712:
1.85 bisitz 4713: $str .= '<h2>'.&mt('Upload a file containing information about users').'</h2>'."\n";
1.95 bisitz 4714:
4715: # Excel and CSV Help
1.147 bisitz 4716: $str .= '<div class="LC_columnSection">'
1.95 bisitz 4717: .&Apache::loncommon::help_open_topic("Course_Create_Class_List",
4718: &mt("How do I create a users list from a spreadsheet"))
1.147 bisitz 4719: .' '.&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1.95 bisitz 4720: &mt("How do I create a CSV file from a spreadsheet"))
1.147 bisitz 4721: ."</div>\n";
1.95 bisitz 4722: $str .= &Apache::lonhtmlcommon::start_pick_box()
1.103 raeburn 4723: .&Apache::lonhtmlcommon::row_title(&mt('File'));
4724: if (&Apache::lonlocal::current_language() ne 'en') {
4725: if ($context eq 'course') {
4726: $str .= '<p class="LC_info">'."\n"
4727: .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n"
4728: .'</p>'."\n";
4729: }
4730: }
4731: $str .= &Apache::loncommon::upfile_select_html()
1.95 bisitz 4732: .&Apache::lonhtmlcommon::row_closure()
4733: .&Apache::lonhtmlcommon::row_title(
4734: '<label for="noFirstLine">'
4735: .&mt('Ignore First Line')
4736: .'</label>')
4737: .'<input type="checkbox" name="noFirstLine" id="noFirstLine" />'
4738: .&Apache::lonhtmlcommon::row_closure(1)
4739: .&Apache::lonhtmlcommon::end_pick_box();
4740:
4741: $str .= '<p>'
1.198 raeburn 4742: .'<input type="button" name="fileupload" value="'.&mt('Next').'"'
1.147 bisitz 4743: .' onclick="javascript:checkUpload(this.form);" />'
1.95 bisitz 4744: .'</p>';
4745:
1.1 raeburn 4746: $r->print($str);
4747: return;
4748: }
4749:
4750: # ================================================= Drop/Add from uploaded file
4751: sub upfile_drop_add {
1.150 raeburn 4752: my ($r,$context,$permission,$showcredits) = @_;
1.189 raeburn 4753: my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'});
4754: if ($datatoken ne '') {
4755: &Apache::loncommon::load_tmp_file($r,$datatoken);
4756: }
1.1 raeburn 4757: my @userdata=&Apache::loncommon::upfile_record_sep();
4758: if($env{'form.noFirstLine'}){shift(@userdata);}
4759: my @keyfields = split(/\,/,$env{'form.keyfields'});
4760: my %fields=();
4761: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
4762: if ($env{'form.upfile_associate'} eq 'reverse') {
4763: if ($env{'form.f'.$i} ne 'none') {
4764: $fields{$keyfields[$i]}=$env{'form.f'.$i};
4765: }
4766: } else {
4767: $fields{$env{'form.f'.$i}}=$keyfields[$i];
4768: }
4769: }
4770: #
4771: # Store the field choices away
1.150 raeburn 4772: my @storefields = qw/username names fname mname lname gen id
4773: sec ipwd email role domain inststatus/;
4774: if ($showcredits) {
4775: push (@storefields,'credits');
4776: }
4777: my %fieldstype;
4778: foreach my $field (@storefields) {
1.1 raeburn 4779: $env{'form.'.$field.'_choice'}=$fields{$field};
1.150 raeburn 4780: $fieldstype{$field.'_choice'} = 'scalar';
1.1 raeburn 4781: }
1.150 raeburn 4782: &Apache::loncommon::store_course_settings('enrollment_upload',\%fieldstype);
1.217 raeburn 4783: my ($cid,$crstype,$setting,$crsdom,$crsnum,$oldcrsuserdoms);
1.101 raeburn 4784: if ($context eq 'domain') {
4785: $setting = $env{'form.roleaction'};
4786: }
4787: if ($env{'request.course.id'} ne '') {
4788: $cid = $env{'request.course.id'};
4789: $crstype = &Apache::loncommon::course_type();
1.185 raeburn 4790: $crsdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.212 raeburn 4791: $crsnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.101 raeburn 4792: } elsif ($setting eq 'course') {
4793: if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
4794: $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
4795: $crstype = &Apache::loncommon::course_type($cid);
1.185 raeburn 4796: $crsdom = $env{'form.dcdomain'};
1.212 raeburn 4797: $crsnum = $env{'form.dccourse'};
1.217 raeburn 4798: if (exists($env{'course.'.$cid.'.internal.userdomains'})) {
4799: $oldcrsuserdoms = 1;
4800: }
4801: my %coursedesc = &Apache::lonnet::coursedescription($cid,{ one_time => 1 });
4802: $env{'course.'.$cid.'.internal.userdomains'} = $coursedesc{'internal.userdomains'};
1.101 raeburn 4803: }
4804: }
1.1 raeburn 4805: my ($startdate,$enddate) = &get_dates_from_form();
4806: if ($env{'form.makedatesdefault'}) {
1.101 raeburn 4807: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
1.1 raeburn 4808: }
4809: # Determine domain and desired host (home server)
1.57 raeburn 4810: my $defdom=$env{'request.role.domain'};
4811: my $domain;
4812: if ($env{'form.defaultdomain'} ne '') {
1.185 raeburn 4813: if (($context eq 'course') || ($setting eq 'course')) {
1.190 raeburn 4814: if ($env{'form.defaultdomain'} eq $crsdom) {
4815: $domain = $env{'form.defaultdomain'};
4816: } else {
1.185 raeburn 4817: if (&Apache::lonnet::will_trust('enroll',$crsdom,$env{'form.defaultdomain'})) {
4818: $domain = $env{'form.defaultdomain'};
4819: } else {
1.192 raeburn 4820: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4821: &mt('Enrollment of users not permitted for specified default domain: [_1].',
4822: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4823: return 'untrusted';
1.185 raeburn 4824: }
4825: }
4826: } elsif ($context eq 'author') {
1.190 raeburn 4827: if ($env{'form.defaultdomain'} eq $defdom) {
4828: $domain = $env{'form.defaultdomain'};
4829: } else {
1.185 raeburn 4830: if ((&Apache::lonnet::will_trust('othcoau',$defdom,$env{'form.defaultdomain'})) &&
1.186 raeburn 4831: (&Apache::lonnet::will_trust('coaurem',$env{'form.defaultdomain'},$defdom))) {
1.185 raeburn 4832: $domain = $env{'form.defaultdomain'};
4833: } else {
1.192 raeburn 4834: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4835: &mt('Addition of users not permitted for specified default domain: [_1].',
4836: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4837: return 'untrusted';
1.185 raeburn 4838: }
4839: }
4840: } elsif (($context eq 'domain') && ($setting eq 'domain')) {
1.190 raeburn 4841: if ($env{'form.defaultdomain'} eq $defdom) {
4842: $domain = $env{'form.defaultdomain'};
4843: } else {
1.185 raeburn 4844: if (&Apache::lonnet::will_trust('domroles',$defdom,$env{'form.defaultdomain'})) {
4845: $domain = $env{'form.defaultdomain'};
4846: } else {
1.192 raeburn 4847: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4848: &mt('Addition of users not permitted for specified default domain: [_1].',
4849: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4850: return 'untrusted';
1.185 raeburn 4851: }
4852: }
4853: }
1.57 raeburn 4854: } else {
4855: $domain = $defdom;
4856: }
1.1 raeburn 4857: my $desiredhost = $env{'form.lcserver'};
4858: if (lc($desiredhost) eq 'default') {
4859: $desiredhost = undef;
4860: } else {
1.57 raeburn 4861: my %home_servers = &Apache::lonnet::get_servers($defdom,'library');
1.1 raeburn 4862: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 4863: $r->print('<p class="LC_error">'.&mt('Error').': '.
4864: &mt('Invalid home server specified').'</p>');
4865: return 'invalidhome';
1.1 raeburn 4866: }
4867: }
4868: # Determine authentication mechanism
4869: my $changeauth;
4870: if ($context eq 'domain') {
4871: $changeauth = $env{'form.changeauth'};
4872: }
4873: my $amode = '';
4874: my $genpwd = '';
1.200 raeburn 4875: my @genpwdfail;
1.1 raeburn 4876: if ($env{'form.login'} eq 'krb') {
4877: $amode='krb';
4878: $amode.=$env{'form.krbver'};
4879: $genpwd=$env{'form.krbarg'};
4880: } elsif ($env{'form.login'} eq 'int') {
4881: $amode='internal';
4882: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
4883: $genpwd=$env{'form.intarg'};
1.200 raeburn 4884: @genpwdfail =
1.202 raeburn 4885: &Apache::loncommon::check_passwd_rules($domain,$genpwd);
1.1 raeburn 4886: }
4887: } elsif ($env{'form.login'} eq 'loc') {
4888: $amode='localauth';
4889: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
4890: $genpwd=$env{'form.locarg'};
4891: }
1.194 raeburn 4892: } elsif ($env{'form.login'} eq 'lti') {
4893: $amode='lti';
1.1 raeburn 4894: }
4895: if ($amode =~ /^krb/) {
4896: if (! defined($genpwd) || $genpwd eq '') {
1.193 raeburn 4897: $r->print('<span class="Error">'.
1.1 raeburn 4898: &mt('Unable to enroll users').' '.
4899: &mt('No Kerberos domain was specified.').'</span></p>');
4900: $amode = ''; # This causes the loop below to be skipped
4901: }
4902: }
1.150 raeburn 4903: my ($defaultsec,$defaultrole,$defaultcredits,$commoncredits);
1.1 raeburn 4904: if ($context eq 'domain') {
4905: if ($setting eq 'domain') {
4906: $defaultrole = $env{'form.defaultrole'};
4907: } elsif ($setting eq 'course') {
4908: $defaultrole = $env{'form.courserole'};
1.27 raeburn 4909: $defaultsec = $env{'form.sections'};
1.150 raeburn 4910: if ($showcredits) {
4911: $commoncredits = $env{'form.credits'};
4912: if ($crstype ne 'Community') {
4913: my %coursehash=&Apache::lonnet::coursedescription($cid);
4914: $defaultcredits = $coursehash{'internal.defaultcredits'};
4915: }
4916: }
1.149 raeburn 4917: }
1.13 raeburn 4918: } elsif ($context eq 'author') {
1.1 raeburn 4919: $defaultrole = $env{'form.defaultrole'};
1.27 raeburn 4920: } elsif ($context eq 'course') {
4921: $defaultrole = $env{'form.defaultrole'};
4922: $defaultsec = $env{'form.sections'};
1.150 raeburn 4923: if ($showcredits) {
4924: $commoncredits = $env{'form.credits'};
4925: $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
4926: }
1.1 raeburn 4927: }
1.27 raeburn 4928: # Check to see if user information can be changed
4929: my @userinfo = ('firstname','middlename','lastname','generation',
4930: 'permanentemail','id');
4931: my %canmodify;
4932: if (&Apache::lonnet::allowed('mau',$domain)) {
1.84 raeburn 4933: push(@userinfo,'inststatus');
1.27 raeburn 4934: foreach my $field (@userinfo) {
4935: $canmodify{$field} = 1;
4936: }
4937: }
4938: my (%userlist,%modifiable_fields,@poss_roles);
4939: my $secidx = &Apache::loncoursedata::CL_SECTION();
1.102 raeburn 4940: my @courseroles = &roles_by_context('course',1,$crstype);
1.27 raeburn 4941: if (!&Apache::lonnet::allowed('mau',$domain)) {
4942: if ($context eq 'course' || $context eq 'author') {
1.101 raeburn 4943: @poss_roles = &curr_role_permissions($context,'','',$crstype);
1.27 raeburn 4944: my @statuses = ('active','future');
4945: my ($indexhash,$keylist) = &make_keylist_array();
4946: my %info;
4947: foreach my $role (@poss_roles) {
4948: %{$modifiable_fields{$role}} = &can_modify_userinfo($context,$domain,
4949: \@userinfo,[$role]);
4950: }
4951: if ($context eq 'course') {
4952: my ($cnum,$cdom) = &get_course_identity();
4953: my $roster = &Apache::loncoursedata::get_classlist();
1.66 raeburn 4954: if (ref($roster) eq 'HASH') {
4955: %userlist = %{$roster};
4956: }
1.27 raeburn 4957: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
4958: \@statuses,\@poss_roles);
4959: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
4960: \%advrolehash,$permission);
4961: } elsif ($context eq 'author') {
4962: my %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
4963: \@statuses,\@poss_roles);
4964: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
4965: \%cstr_roles,$permission);
4966: }
4967: }
1.1 raeburn 4968: }
1.193 raeburn 4969: if ($datatoken eq '') {
4970: $r->print('<p class="LC_error">'.&mt('Error').': '.
4971: &mt('Invalid datatoken').'</p>');
4972: return 'missingdata';
4973: }
1.1 raeburn 4974: if ( $domain eq &LONCAPA::clean_domain($domain)
4975: && ($amode ne '')) {
4976: #######################################
4977: ## Add/Modify Users ##
4978: #######################################
4979: if ($context eq 'course') {
4980: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
1.13 raeburn 4981: } elsif ($context eq 'author') {
1.1 raeburn 4982: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
4983: } else {
4984: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
4985: }
1.87 bisitz 4986: $r->rflush;
1.212 raeburn 4987: my (%got_role_approvals,%got_instdoms,%process_by,%instdoms,
1.213 raeburn 4988: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
1.87 bisitz 4989:
1.1 raeburn 4990: my %counts = (
4991: user => 0,
4992: auth => 0,
4993: role => 0,
4994: );
4995: my $flushc=0;
4996: my %student=();
1.42 raeburn 4997: my (%curr_groups,@sections,@cleansec,$defaultwarn,$groupwarn);
1.1 raeburn 4998: my %userchg;
1.27 raeburn 4999: if ($context eq 'course' || $setting eq 'course') {
5000: if ($context eq 'course') {
5001: # Get information about course groups
5002: %curr_groups = &Apache::longroup::coursegroups();
5003: } elsif ($setting eq 'course') {
5004: if ($cid) {
5005: %curr_groups =
5006: &Apache::longroup::coursegroups($env{'form.dcdomain'},
5007: $env{'form.dccourse'});
5008: }
5009: }
5010: # determine section number
5011: if ($defaultsec =~ /,/) {
5012: push(@sections,split(/,/,$defaultsec));
5013: } else {
5014: push(@sections,$defaultsec);
5015: }
5016: # remove non alphanumeric values from section
5017: foreach my $item (@sections) {
5018: $item =~ s/\W//g;
5019: if ($item eq "none" || $item eq 'all') {
5020: $defaultwarn = &mt('Default section name [_1] could not be used as it is a reserved word.',$item);
5021: } elsif ($item ne '' && exists($curr_groups{$item})) {
5022: $groupwarn = &mt('Default section name "[_1]" is the name of a course group. Section names and group names must be distinct.',$item);
5023: } elsif ($item ne '') {
5024: push(@cleansec,$item);
5025: }
5026: }
5027: if ($defaultwarn) {
5028: $r->print($defaultwarn.'<br />');
5029: }
5030: if ($groupwarn) {
5031: $r->print($groupwarn.'<br />');
5032: }
1.1 raeburn 5033: }
1.124 raeburn 5034: my (%curr_rules,%got_rules,%alerts,%cancreate);
1.104 raeburn 5035: my %customroles = &my_custom_roles($crstype);
1.101 raeburn 5036: my @permitted_roles =
1.124 raeburn 5037: &roles_on_upload($context,$setting,$crstype,%customroles);
5038: my %longtypes = &Apache::lonlocal::texthash(
5039: official => 'Institutional',
5040: unofficial => 'Non-institutional',
5041: );
1.135 raeburn 5042: my $newuserdom = $env{'request.role.domain'};
5043: map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes);
1.1 raeburn 5044: # Get new users list
1.200 raeburn 5045: my (%existinguser,%userinfo,%disallow,%rulematch,%inst_results,%alerts,%checkuname,
5046: %showpasswdrules,$haspasswdmap);
1.171 raeburn 5047: my $counter = -1;
1.185 raeburn 5048: my (%willtrust,%trustchecked);
1.27 raeburn 5049: foreach my $line (@userdata) {
1.171 raeburn 5050: $counter ++;
1.42 raeburn 5051: my @secs;
1.27 raeburn 5052: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 5053: # Determine user name
1.128 raeburn 5054: $entries{$fields{'username'}} =~ s/^\s+|\s+$//g;
1.1 raeburn 5055: unless (($entries{$fields{'username'}} eq '') ||
5056: (!defined($entries{$fields{'username'}}))) {
5057: my ($fname, $mname, $lname,$gen) = ('','','','');
5058: if (defined($fields{'names'})) {
5059: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
5060: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
5061: } else {
5062: if (defined($fields{'fname'})) {
5063: $fname=$entries{$fields{'fname'}};
5064: }
5065: if (defined($fields{'mname'})) {
5066: $mname=$entries{$fields{'mname'}};
5067: }
5068: if (defined($fields{'lname'})) {
5069: $lname=$entries{$fields{'lname'}};
5070: }
5071: if (defined($fields{'gen'})) {
5072: $gen=$entries{$fields{'gen'}};
5073: }
5074: }
1.128 raeburn 5075:
1.1 raeburn 5076: if ($entries{$fields{'username'}}
5077: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
1.128 raeburn 5078: my $nowhitespace;
5079: if ($entries{$fields{'username'}} =~ /\s/) {
5080: $nowhitespace = ' - '.&mt('usernames may not contain spaces.');
5081: }
1.171 raeburn 5082: $disallow{$counter} =
1.157 bisitz 5083: &mt('Unacceptable username [_1] for user [_2] [_3] [_4] [_5]',
1.171 raeburn 5084: '"<b>'.$entries{$fields{'username'}}.'</b>"',
5085: $fname,$mname,$lname,$gen).$nowhitespace;
1.27 raeburn 5086: next;
1.1 raeburn 5087: } else {
1.129 raeburn 5088: $entries{$fields{'domain'}} =~ s/^\s+|\s+$//g;
1.71 droeschl 5089: if ($entries{$fields{'domain'}}
1.57 raeburn 5090: ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
1.171 raeburn 5091: $disallow{$counter} =
1.157 bisitz 5092: &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
1.171 raeburn 5093: '"<b>'.$entries{$fields{'domain'}}.'</b>"',
5094: $fname,$mname,$lname,$gen);
5095: next;
1.185 raeburn 5096: } elsif ($entries{$fields{'domain'}} ne $domain) {
5097: my $possdom = $entries{$fields{'domain'}};
5098: if ($context eq 'course' || $setting eq 'course') {
5099: unless ($trustchecked{$possdom}) {
5100: $willtrust{$possdom} = &Apache::lonnet::will_trust('enroll',$domain,$possdom);
5101: $trustchecked{$possdom} = 1;
5102: }
5103: } elsif ($context eq 'author') {
5104: unless ($trustchecked{$possdom}) {
5105: $willtrust{$possdom} = &Apache::lonnet::will_trust('othcoau',$domain,$possdom);
5106: }
5107: if ($willtrust{$possdom}) {
5108: $willtrust{$possdom} = &Apache::lonnet::will_trust('coaurem',$possdom,$domain);
5109: }
5110: }
5111: unless ($willtrust{$possdom}) {
5112: $disallow{$counter} =
5113: &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
5114: '"<b>'.$possdom.'</b>"',
5115: $fname,$mname,$lname,$gen);
5116: next;
5117: }
1.57 raeburn 5118: }
1.5 raeburn 5119: my $username = $entries{$fields{'username'}};
1.57 raeburn 5120: my $userdomain = $entries{$fields{'domain'}};
5121: if ($userdomain eq '') {
5122: $userdomain = $domain;
5123: }
1.27 raeburn 5124: if (defined($fields{'sec'})) {
5125: if (defined($entries{$fields{'sec'}})) {
1.42 raeburn 5126: $entries{$fields{'sec'}} =~ s/\W//g;
1.27 raeburn 5127: my $item = $entries{$fields{'sec'}};
5128: if ($item eq "none" || $item eq 'all') {
1.171 raeburn 5129: $disallow{$counter} =
5130: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a reserved word.',
5131: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item);
1.27 raeburn 5132: next;
5133: } elsif (exists($curr_groups{$item})) {
1.171 raeburn 5134: $disallow{$counter} =
5135: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a course group.',
5136: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item).' '.
5137: &mt('Section names and group names must be distinct.');
1.27 raeburn 5138: next;
5139: } else {
5140: push(@secs,$item);
5141: }
5142: }
5143: }
5144: if ($env{'request.course.sec'} ne '') {
5145: @secs = ($env{'request.course.sec'});
1.57 raeburn 5146: if (ref($userlist{$username.':'.$userdomain}) eq 'ARRAY') {
5147: my $currsec = $userlist{$username.':'.$userdomain}[$secidx];
1.27 raeburn 5148: if ($currsec ne $env{'request.course.sec'}) {
1.171 raeburn 5149: $disallow{$counter} =
5150: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]".',
5151: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$secs[0]);
1.27 raeburn 5152: if ($currsec eq '') {
1.171 raeburn 5153: $disallow{$counter} .=
5154: &mt('This user already has an active/future student role in the course, unaffiliated to any section.');
1.27 raeburn 5155:
5156: } else {
1.171 raeburn 5157: $disallow{$counter} .=
5158: &mt('This user already has an active/future role in section "[_1]" of the course.',$currsec);
1.27 raeburn 5159: }
1.171 raeburn 5160: $disallow{$counter} .=
5161: '<br />'.
5162: &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.',
5163: $secs[0]);
1.27 raeburn 5164: next;
1.1 raeburn 5165: }
5166: }
1.27 raeburn 5167: } elsif ($context eq 'course' || $setting eq 'course') {
5168: if (@secs == 0) {
5169: @secs = @cleansec;
1.1 raeburn 5170: }
5171: }
5172: # determine id number
5173: my $id='';
5174: if (defined($fields{'id'})) {
5175: if (defined($entries{$fields{'id'}})) {
5176: $id=$entries{$fields{'id'}};
5177: }
5178: $id=~tr/A-Z/a-z/;
5179: }
5180: # determine email address
5181: my $email='';
5182: if (defined($fields{'email'})) {
1.129 raeburn 5183: $entries{$fields{'email'}} =~ s/^\s+|\s+$//g;
1.1 raeburn 5184: if (defined($entries{$fields{'email'}})) {
5185: $email=$entries{$fields{'email'}};
1.84 raeburn 5186: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
5187: }
5188: }
5189: # determine affiliation
5190: my $inststatus='';
5191: if (defined($fields{'inststatus'})) {
5192: if (defined($entries{$fields{'inststatus'}})) {
5193: $inststatus=$entries{$fields{'inststatus'}};
5194: }
1.1 raeburn 5195: }
5196: # determine user password
1.200 raeburn 5197: my $password;
5198: my $passwdfromfile;
1.1 raeburn 5199: if (defined($fields{'ipwd'})) {
5200: if ($entries{$fields{'ipwd'}}) {
5201: $password=$entries{$fields{'ipwd'}};
1.200 raeburn 5202: $passwdfromfile = 1;
5203: if ($env{'form.login'} eq 'int') {
5204: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
5205: if (($uhome eq 'no_host') || ($changeauth)) {
5206: my @brokepwdrules =
5207: &Apache::loncommon::check_passwd_rules($domain,$password);
5208: if (@brokepwdrules) {
5209: $disallow{$counter} = &mt('[_1]: Password included in file for this user did not meet requirements.',
5210: '<b>'.$username.'</b>');
5211: map { $showpasswdrules{$_} = 1; } @brokepwdrules;
5212: next;
5213: }
5214: }
5215: }
5216: }
5217: }
5218: unless ($passwdfromfile) {
5219: if ($env{'form.login'} eq 'int') {
5220: if (@genpwdfail) {
5221: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
5222: if (($uhome eq 'no_host') || ($changeauth)) {
5223: $disallow{$counter} = &mt('[_1]: No specific password in file for this user; default password did not meet requirements',
5224: '<b>'.$username.'</b>');
5225: unless ($haspasswdmap) {
5226: map { $showpasswdrules{$_} = 1; } @genpwdfail;
5227: $haspasswdmap = 1;
5228: }
5229: }
5230: next;
5231: }
1.1 raeburn 5232: }
1.200 raeburn 5233: $password = $genpwd;
1.1 raeburn 5234: }
5235: # determine user role
5236: my $role = '';
5237: if (defined($fields{'role'})) {
5238: if ($entries{$fields{'role'}}) {
1.42 raeburn 5239: $entries{$fields{'role'}} =~ s/(\s+$|^\s+)//g;
5240: if ($entries{$fields{'role'}} ne '') {
5241: if (grep(/^\Q$entries{$fields{'role'}}\E$/,@permitted_roles)) {
5242: $role = $entries{$fields{'role'}};
1.27 raeburn 5243: }
5244: }
5245: if ($role eq '') {
5246: my $rolestr = join(', ',@permitted_roles);
1.171 raeburn 5247: $disallow{$counter} =
5248: &mt('[_1]: You do not have permission to add the requested role [_2] for the user.'
5249: ,'<b>'.$entries{$fields{'username'}}.'</b>'
5250: ,$entries{$fields{'role'}})
5251: .'<br />'
5252: .&mt('Allowable role(s) is/are: [_1].',$rolestr);
1.1 raeburn 5253: next;
5254: }
5255: }
5256: }
5257: if ($role eq '') {
5258: $role = $defaultrole;
5259: }
5260: # Clean up whitespace
1.129 raeburn 5261: foreach (\$id,\$fname,\$mname,\$lname,\$gen,\$inststatus) {
1.1 raeburn 5262: $$_ =~ s/(\s+$|^\s+)//g;
5263: }
1.150 raeburn 5264: my $credits;
5265: if ($showcredits) {
5266: if (($role eq 'st') && ($crstype ne 'Community')) {
5267: $credits = $entries{$fields{'credits'}};
5268: if ($credits ne '') {
5269: $credits =~ s/[^\d\.]//g;
5270: }
5271: if ($credits eq '') {
5272: $credits = $commoncredits;
5273: }
5274: if ($credits eq $defaultcredits) {
5275: undef($credits);
5276: }
5277: }
5278: }
1.5 raeburn 5279: # check against rules
5280: my $checkid = 0;
5281: my $newuser = 0;
1.57 raeburn 5282: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
1.5 raeburn 5283: if ($uhome eq 'no_host') {
1.135 raeburn 5284: if ($userdomain ne $newuserdom) {
5285: if ($context eq 'course') {
1.171 raeburn 5286: $disallow{$counter} =
5287: &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
5288: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 5289: } elsif ($context eq 'author') {
1.171 raeburn 5290: $disallow{$counter} =
5291: &mt('[_1]: The domain specified ([_2]) is different to that of the author.',
5292: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 5293: } else {
1.171 raeburn 5294: $disallow{$counter} =
5295: &mt('[_1]: The domain specified ([_2]) is different to that of your current role.',
5296: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 5297: }
1.171 raeburn 5298: $disallow{$counter} .=
5299: &mt('The user does not already exist, and you may not create a new user in a different domain.');
1.124 raeburn 5300: next;
1.171 raeburn 5301: } else {
1.194 raeburn 5302: unless (($password ne '') || ($env{'form.login'} eq 'loc') || ($env{'form.login'} eq 'lti')) {
1.171 raeburn 5303: $disallow{$counter} =
5304: &mt('[_1]: This is a new user but no default password was provided, and the authentication type requires one.',
5305: '<b>'.$username.'</b>');
5306: next;
5307: }
1.124 raeburn 5308: }
1.5 raeburn 5309: $checkid = 1;
5310: $newuser = 1;
1.172 raeburn 5311: $checkuname{$username.':'.$newuserdom} = { 'newuser' => $newuser, 'id' => $id };
1.13 raeburn 5312: } else {
1.27 raeburn 5313: if ($context eq 'course' || $context eq 'author') {
1.57 raeburn 5314: if ($userdomain eq $domain ) {
5315: if ($role eq '') {
5316: my @checkroles;
5317: foreach my $role (@poss_roles) {
5318: my $endkey;
5319: if ($role ne 'st') {
5320: $endkey = ':'.$role;
5321: }
5322: if (exists($userlist{$username.':'.$userdomain.$endkey})) {
5323: if (!grep(/^\Q$role\E$/,@checkroles)) {
5324: push(@checkroles,$role);
5325: }
5326: }
1.27 raeburn 5327: }
1.57 raeburn 5328: if (@checkroles > 0) {
5329: %canmodify = &can_modify_userinfo($context,$domain,\@userinfo,\@checkroles);
1.27 raeburn 5330: }
1.57 raeburn 5331: } elsif (ref($modifiable_fields{$role}) eq 'HASH') {
5332: %canmodify = %{$modifiable_fields{$role}};
1.27 raeburn 5333: }
5334: }
1.57 raeburn 5335: my @newinfo = (\$fname,\$mname,\$lname,\$gen,\$email,\$id);
1.84 raeburn 5336: for (my $i=0; $i<@newinfo; $i++) {
1.57 raeburn 5337: if (${$newinfo[$i]} ne '') {
5338: if (!$canmodify{$userinfo[$i]}) {
5339: ${$newinfo[$i]} = '';
5340: }
1.27 raeburn 5341: }
5342: }
5343: }
1.171 raeburn 5344: if ($id) {
5345: $existinguser{$userdomain}{$username} = $id;
5346: }
1.5 raeburn 5347: }
1.171 raeburn 5348: $userinfo{$counter} = {
5349: username => $username,
5350: domain => $userdomain,
5351: fname => $fname,
5352: mname => $mname,
5353: lname => $lname,
5354: gen => $gen,
5355: email => $email,
5356: id => $id,
5357: password => $password,
5358: inststatus => $inststatus,
5359: role => $role,
5360: sections => \@secs,
5361: credits => $credits,
5362: newuser => $newuser,
5363: checkid => $checkid,
5364: };
5365: }
5366: }
5367: } # end of foreach (@userdata)
5368: if ($counter > -1) {
5369: my $total = $counter + 1;
5370: my %checkids;
1.172 raeburn 5371: if ((keys(%existinguser)) || (keys(%checkuname))) {
5372: $r->print(&mt('Please be patient -- checking for institutional data ...'));
5373: $r->rflush();
5374: if (keys(%existinguser)) {
5375: foreach my $dom (keys(%existinguser)) {
5376: if (ref($existinguser{$dom}) eq 'HASH') {
5377: my %idhash = &Apache::lonnet::idrget($dom,keys(%{$existinguser{$dom}}));
5378: foreach my $username (keys(%{$existinguser{$dom}})) {
5379: if ($idhash{$username} ne $existinguser{$dom}{$username}) {
5380: $checkids{$username.':'.$dom} = {
5381: 'id' => $existinguser{$dom}{$username},
5382: };
5383: }
5384: }
5385: if (keys(%checkids)) {
5386: &Apache::loncommon::user_rule_check(\%checkids,{ 'id' => 1 },
5387: \%alerts,\%rulematch,
5388: \%inst_results,\%curr_rules,
5389: \%got_rules);
1.171 raeburn 5390: }
5391: }
5392: }
5393: }
1.172 raeburn 5394: if (keys(%checkuname)) {
5395: &Apache::loncommon::user_rule_check(\%checkuname,{ 'username' => 1, 'id' => 1, },
5396: \%alerts,\%rulematch,\%inst_results,
5397: \%curr_rules,\%got_rules);
5398: }
5399: $r->print(' '.&mt('done').'<br /><br />');
5400: $r->rflush();
1.171 raeburn 5401: }
1.172 raeburn 5402: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,$total);
1.171 raeburn 5403: $r->print('<ul>');
5404: for (my $i=0; $i<=$counter; $i++) {
5405: if ($disallow{$i}) {
5406: $r->print('<li>'.$disallow{$i}.'</li>');
5407: } elsif (ref($userinfo{$i}) eq 'HASH') {
5408: my $password = $userinfo{$i}{'password'};
5409: my $newuser = $userinfo{$i}{'newuser'};
5410: my $checkid = $userinfo{$i}{'checkid'};
5411: my $id = $userinfo{$i}{'id'};
5412: my $role = $userinfo{$i}{'role'};
5413: my @secs;
5414: if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
5415: @secs = @{$userinfo{$i}{'sections'}};
5416: }
5417: my $fname = $userinfo{$i}{'fname'};
5418: my $mname = $userinfo{$i}{'mname'};
5419: my $lname = $userinfo{$i}{'lname'};
5420: my $gen = $userinfo{$i}{'gen'};
5421: my $email = $userinfo{$i}{'email'};
5422: my $inststatus = $userinfo{$i}{'inststatus'};
5423: my $credits = $userinfo{$i}{'credits'};
5424: my $username = $userinfo{$i}{'username'};
5425: my $userdomain = $userinfo{$i}{'domain'};
5426: my $user = $username.':'.$userdomain;
5427: if ($newuser) {
5428: if (ref($alerts{'username'}) eq 'HASH') {
5429: if (ref($alerts{'username'}{$userdomain}) eq 'HASH') {
5430: if ($alerts{'username'}{$userdomain}{$username}) {
5431: $r->print('<li>'.
5432: &mt('[_1]: matches the username format at your institution, but is not known to your directory service.','<b>'.$username.'</b>').'<br />'.
5433: &mt('Consequently, the user was not created.').'</li>');
5434: next;
5435: }
5436: }
5437: }
1.172 raeburn 5438: if (ref($inst_results{$user}) eq 'HASH') {
5439: if ($inst_results{$user}{'firstname'} ne '') {
5440: $fname = $inst_results{$user}{'firstname'};
5441: }
5442: if ($inst_results{$user}{'middlename'} ne '') {
5443: $mname = $inst_results{$user}{'middlename'};
5444: }
5445: if ($inst_results{$user}{'lasttname'} ne '') {
5446: $lname = $inst_results{$user}{'lastname'};
5447: }
5448: if ($inst_results{$user}{'permanentemail'} ne '') {
5449: $email = $inst_results{$user}{'permanentemail'};
5450: }
5451: if ($inst_results{$user}{'id'} ne '') {
5452: $id = $inst_results{$user}{'id'};
5453: $checkid = 0;
5454: }
5455: if (ref($inst_results{$user}{'inststatus'}) eq 'ARRAY') {
5456: $inststatus = join(':',@{$inst_results{$user}{'inststatus'}});
5457: }
5458: }
5459: if (($checkid) && ($id ne '')) {
5460: if (ref($alerts{'id'}) eq 'HASH') {
5461: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
5462: if ($alerts{'id'}{$userdomain}{$username}) {
5463: $r->print('<li>'.
5464: &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
5465: '<b>'.$username.'</b>').'<br />'.
5466: &mt('Consequently, the user was not created.').'</li>');
5467: next;
5468: }
5469: }
5470: }
5471: }
1.171 raeburn 5472: my $usertype = 'unofficial';
5473: if (ref($rulematch{$user}) eq 'HASH') {
5474: if ($rulematch{$user}{'username'}) {
5475: $usertype = 'official';
1.5 raeburn 5476: }
5477: }
1.171 raeburn 5478: unless ($cancreate{$usertype}) {
5479: my $showtype = $longtypes{$usertype};
5480: $r->print('<li>'.
5481: &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].','<b>'.$username.'</b>',$showtype).'</li>');
5482: next;
5483: }
1.172 raeburn 5484: } elsif ($id ne '') {
1.171 raeburn 5485: if (exists($checkids{$user})) {
5486: $checkid = 1;
1.5 raeburn 5487: if (ref($alerts{'id'}) eq 'HASH') {
1.57 raeburn 5488: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
1.172 raeburn 5489: if ($alerts{'id'}{$userdomain}{$username}) {
1.171 raeburn 5490: $r->print('<li>'.
1.172 raeburn 5491: &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
1.124 raeburn 5492: '<b>'.$username.'</b>').'<br />'.
1.172 raeburn 5493: &mt('Consequently, the ID was not changed.').'</li>');
5494: $id = '';
1.124 raeburn 5495: }
1.5 raeburn 5496: }
5497: }
5498: }
5499: }
1.171 raeburn 5500: my $multiple = 0;
5501: my ($userresult,$authresult,$roleresult,$idresult);
5502: my (%userres,%authres,%roleres,%idres);
5503: my $singlesec = '';
5504: if ($role eq 'st') {
1.206 raeburn 5505: if (($context eq 'domain') && ($changeauth eq 'Yes') && (!$newuser)) {
5506: if ((&Apache::lonnet::allowed('mau',$userdomain)) &&
5507: (&Apache::lonnet::homeserver($username,$userdomain) ne 'no_host')) {
5508: if ((($amode =~ /^krb4|krb5|internal$/) && $password ne '') ||
5509: ($amode eq 'localauth')) {
5510: $authresult =
5511: &Apache::lonnet::modifyuserauth($userdomain,$username,$amode,$password);
5512: }
5513: }
5514: }
1.171 raeburn 5515: my $sec;
5516: if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
1.42 raeburn 5517: if (@secs > 0) {
5518: $sec = $secs[0];
1.27 raeburn 5519: }
1.171 raeburn 5520: }
1.212 raeburn 5521: if ($userdomain ne $env{'request.role.domain'}) {
5522: my $item = "/$crsdom/$crsnum" ;
5523: if ($sec ne '') {
5524: $item .= "/$sec";
5525: }
5526: $item .= '_st';
5527: next if (&restricted_dom($context,$item,$userdomain,$username,$role,$startdate,
5528: $enddate,$crsdom,$crsnum,$sec,$credits,\%process_by,
5529: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.213 raeburn 5530: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.212 raeburn 5531: }
1.171 raeburn 5532: &modifystudent($userdomain,$username,$cid,$sec,
5533: $desiredhost,$context);
5534: $roleresult =
5535: &Apache::lonnet::modifystudent
5536: ($userdomain,$username,$id,$amode,$password,
5537: $fname,$mname,$lname,$gen,$sec,$enddate,
5538: $startdate,$env{'form.forceid'},
5539: $desiredhost,$email,'manual','',$cid,
5540: '',$context,$inststatus,$credits);
5541: $userresult = $roleresult;
5542: } else {
1.212 raeburn 5543: my $possrole;
5544: if ($role ne '') {
1.171 raeburn 5545: if ($context eq 'course' || $setting eq 'course') {
5546: if ($customroles{$role}) {
5547: $role = 'cr_'.$env{'user.domain'}.'_'.
5548: $env{'user.name'}.'_'.$role;
5549: }
1.212 raeburn 5550: $possrole = $role;
5551: if ($possrole =~ /^cr_/) {
5552: $possrole =~ s{_}{/}g;
5553: }
5554: if (($role ne 'cc') && ($role ne 'co')) {
1.171 raeburn 5555: if (@secs > 1) {
5556: $multiple = 1;
1.212 raeburn 5557: my $prefix = "/$crsdom/$crsnum";
1.171 raeburn 5558: foreach my $sec (@secs) {
1.212 raeburn 5559: if ($userdomain ne $env{'request.role.domain'}) {
5560: my $item = $prefix;
5561: if ($sec ne '') {
5562: $item .= "/$sec";
5563: }
5564: $item .= '_'.$possrole;
5565: next if (&restricted_dom($context,$item,$userdomain,$username,$possrole,
5566: $startdate,$enddate,$crsdom,$crsnum,$sec,
5567: $credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 5568: \%got_instdoms,\%reject,\%pending,\%notifydc,
5569: \%status,\%unauthorized,\%currqueued));
1.212 raeburn 5570: }
1.171 raeburn 5571: ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
5572: &modifyuserrole($context,$setting,
5573: $changeauth,$cid,$userdomain,$username,
5574: $id,$amode,$password,$fname,
5575: $mname,$lname,$gen,$sec,
5576: $env{'form.forceid'},$desiredhost,
5577: $email,$role,$enddate,
5578: $startdate,$checkid,$inststatus);
1.42 raeburn 5579: }
1.171 raeburn 5580: } elsif (@secs > 0) {
5581: $singlesec = $secs[0];
1.27 raeburn 5582: }
5583: }
1.212 raeburn 5584: } else {
5585: $possrole = $role;
1.27 raeburn 5586: }
1.204 raeburn 5587: }
5588: if (!$multiple) {
1.212 raeburn 5589: if (($userdomain ne $env{'request.role.domain'}) && ($role ne '')) {
5590: my $item = "/$crsdom/$crsnum";
5591: if ($singlesec ne '') {
5592: $item .= "/$singlesec";
5593: }
5594: $item .= '_'.$possrole;
5595: next if (&restricted_dom($context,$item,$userdomain,$username,$possrole,$startdate,$enddate,
5596: $crsdom,$crsnum,$singlesec,$credits,\%process_by,\%instdoms,
1.213 raeburn 5597: \%got_role_approvals,\%got_instdoms,\%reject,\%pending,\%notifydc,
5598: \%status,\%unauthorized,\%currqueued));
1.212 raeburn 5599: }
1.204 raeburn 5600: ($userresult,$authresult,$roleresult,$idresult) =
5601: &modifyuserrole($context,$setting,
5602: $changeauth,$cid,$userdomain,$username,
5603: $id,$amode,$password,$fname,
5604: $mname,$lname,$gen,$singlesec,
5605: $env{'form.forceid'},$desiredhost,
5606: $email,$role,$enddate,$startdate,
5607: $checkid,$inststatus);
1.27 raeburn 5608: }
1.171 raeburn 5609: }
5610: if ($multiple) {
5611: foreach my $sec (sort(keys(%userres))) {
5612: $flushc =
1.27 raeburn 5613: &user_change_result($r,$userres{$sec},$authres{$sec},
5614: $roleres{$sec},$idres{$sec},\%counts,$flushc,
1.57 raeburn 5615: $username,$userdomain,\%userchg);
1.27 raeburn 5616:
1.1 raeburn 5617: }
5618: } else {
1.171 raeburn 5619: $flushc =
5620: &user_change_result($r,$userresult,$authresult,
5621: $roleresult,$idresult,\%counts,$flushc,
5622: $username,$userdomain,\%userchg);
1.1 raeburn 5623: }
5624: }
1.172 raeburn 5625: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last user');
1.171 raeburn 5626: } # end of loop
1.172 raeburn 5627: $r->print('</ul>');
1.171 raeburn 5628: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.217 raeburn 5629: if (($context eq 'domain') && ($setting eq 'course')) {
5630: unless ($oldcrsuserdoms) {
5631: if (exists($env{'course.'.$cid.'.internal.userdomains'})) {
5632: delete($env{'course.'.$cid.'.internal.userdomains'});
5633: }
5634: }
5635: }
1.171 raeburn 5636: }
1.1 raeburn 5637: # Flush the course logs so reverse user roles immediately updated
1.126 raeburn 5638: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.29 raeburn 5639: $r->print("</p>\n<p>\n".&mt('Processed [quant,_1,user].',$counts{'user'}).
1.1 raeburn 5640: "</p>\n");
5641: if ($counts{'role'} > 0) {
5642: $r->print("<p>\n".
1.192 raeburn 5643: &mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.
5644: &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.').
5645: "</p>\n");
1.29 raeburn 5646: } else {
5647: $r->print('<p>'.&mt('No roles added').'</p>');
1.1 raeburn 5648: }
5649: if ($counts{'auth'} > 0) {
5650: $r->print("<p>\n".
5651: &mt('Authentication changed for [_1] existing users.',
5652: $counts{'auth'})."</p>\n");
5653: }
1.13 raeburn 5654: $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
1.200 raeburn 5655: $r->print(&passwdrule_alerts($domain,\%showpasswdrules));
1.213 raeburn 5656: if ((keys(%reject)) || (keys(%unauthorized))) {
5657: $r->print(&print_roles_rejected($context,\%reject,\%unauthorized));
1.212 raeburn 5658: }
1.213 raeburn 5659: if ((keys(%pending)) || (keys(%currqueued))) {
5660: $r->print(&print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.212 raeburn 5661: }
1.1 raeburn 5662: #####################################
1.29 raeburn 5663: # Display list of students to drop #
1.1 raeburn 5664: #####################################
5665: if ($env{'form.fullup'} eq 'yes') {
1.29 raeburn 5666: $r->print('<h3>'.&mt('Students to Drop')."</h3>\n");
1.1 raeburn 5667: # Get current classlist
1.30 raeburn 5668: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 5669: if (! defined($classlist)) {
1.192 raeburn 5670: $r->print('<p class="LC_info">'.
5671: &mt('There are no students with current/future access to the course.').
5672: '</p>'."\n");
1.66 raeburn 5673: } elsif (ref($classlist) eq 'HASH') {
1.1 raeburn 5674: # Remove the students we just added from the list of students.
1.30 raeburn 5675: foreach my $line (@userdata) {
5676: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 5677: unless (($entries{$fields{'username'}} eq '') ||
5678: (!defined($entries{$fields{'username'}}))) {
5679: delete($classlist->{$entries{$fields{'username'}}.
5680: ':'.$domain});
5681: }
5682: }
5683: # Print out list of dropped students.
1.30 raeburn 5684: &show_drop_list($r,$classlist,'nosort',$permission);
1.1 raeburn 5685: }
5686: }
5687: } # end of unless
1.193 raeburn 5688: return 'ok';
1.1 raeburn 5689: }
5690:
1.13 raeburn 5691: sub print_namespacing_alerts {
5692: my ($domain,$alerts,$curr_rules) = @_;
5693: my $output;
5694: if (ref($alerts) eq 'HASH') {
5695: if (keys(%{$alerts}) > 0) {
5696: if (ref($alerts->{'username'}) eq 'HASH') {
5697: foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
5698: my $count;
5699: if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
5700: $count = keys(%{$alerts->{'username'}{$dom}});
5701: }
5702: my $domdesc = &Apache::lonnet::domain($domain,'description');
5703: if (ref($curr_rules->{$dom}) eq 'HASH') {
5704: $output .= &Apache::loncommon::instrule_disallow_msg(
5705: 'username',$domdesc,$count,'upload');
5706: }
5707: $output .= &Apache::loncommon::user_rule_formats($dom,
5708: $domdesc,$curr_rules->{$dom}{'username'},
5709: 'username');
5710: }
5711: }
5712: if (ref($alerts->{'id'}) eq 'HASH') {
5713: foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
5714: my $count;
5715: if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
5716: $count = keys(%{$alerts->{'id'}{$dom}});
5717: }
5718: my $domdesc = &Apache::lonnet::domain($domain,'description');
5719: if (ref($curr_rules->{$dom}) eq 'HASH') {
5720: $output .= &Apache::loncommon::instrule_disallow_msg(
5721: 'id',$domdesc,$count,'upload');
5722: }
5723: $output .= &Apache::loncommon::user_rule_formats($dom,
5724: $domdesc,$curr_rules->{$dom}{'id'},'id');
5725: }
5726: }
5727: }
5728: }
5729: }
5730:
1.200 raeburn 5731: sub passwdrule_alerts {
5732: my ($domain,$passwdrules) = @_;
5733: my $warning;
5734: if (ref($passwdrules) eq 'HASH') {
5735: my %showrules = %{$passwdrules};
5736: if (keys(%showrules)) {
5737: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
5738: $warning = '<b>'.&mt('Password requirement(s) unmet for one or more users:').'</b><ul>';
5739: if ($showrules{'min'}) {
1.208 raeburn 5740: my $min = $passwdconf{'min'};
5741: if ($min eq '') {
5742: $min = $Apache::lonnet::passwdmin;
5743: }
5744: $warning .= '<li>'.&mt('minimum [quant,_1,character]',$min).'</li>';
1.200 raeburn 5745: }
5746: if ($showrules{'max'}) {
5747: $warning .= '<li>'.&mt('maximum [quant,_1,character]',$passwdconf{'max'}).'</li>';
5748: }
5749: if ($showrules{'uc'}) {
5750: $warning .= '<li>'.&mt('contain at least one upper case letter').'</li>';
5751: }
5752: if ($showrules{'lc'}) {
5753: $warning .= '<li>'.&mt('contain at least one lower case letter').'</li>';
5754: }
5755: if ($showrules{'num'}) {
5756: $warning .= '<li>'.&mt('contain at least one number').'</li>';
5757: }
5758: if ($showrules{'spec'}) {
5759: $warning .= '<li>'.&mt('contain at least one non-alphanumeric').'</li>';
5760: }
5761: $warning .= '</ul>';
5762: }
5763: }
5764: return $warning;
5765: }
5766:
1.1 raeburn 5767: sub user_change_result {
1.29 raeburn 5768: my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
1.57 raeburn 5769: $username,$userdomain,$userchg) = @_;
1.1 raeburn 5770: my $okresult = 0;
1.171 raeburn 5771: my @status;
1.1 raeburn 5772: if ($userresult ne 'ok') {
5773: if ($userresult =~ /^error:(.+)$/) {
5774: my $error = $1;
1.171 raeburn 5775: push(@status,
5776: &mt('[_1]: Unable to add/modify: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5777: }
5778: } else {
5779: $counts->{'user'} ++;
5780: $okresult = 1;
5781: }
5782: if ($authresult ne 'ok') {
5783: if ($authresult =~ /^error:(.+)$/) {
5784: my $error = $1;
1.171 raeburn 5785: push(@status,
5786: &mt('[_1]: Unable to modify authentication: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5787: }
5788: } else {
5789: $counts->{'auth'} ++;
5790: $okresult = 1;
5791: }
5792: if ($roleresult ne 'ok') {
5793: if ($roleresult =~ /^error:(.+)$/) {
5794: my $error = $1;
1.171 raeburn 5795: push(@status,
5796: &mt('[_1]: Unable to add role: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5797: }
5798: } else {
5799: $counts->{'role'} ++;
5800: $okresult = 1;
5801: }
5802: if ($okresult) {
5803: $flushc++;
1.57 raeburn 5804: $userchg->{$username.':'.$userdomain}=1;
1.1 raeburn 5805: if ($flushc>15) {
5806: $r->rflush;
5807: $flushc=0;
5808: }
5809: }
1.29 raeburn 5810: if ($idresult) {
1.171 raeburn 5811: push(@status,$idresult);
5812: }
5813: if (@status) {
5814: $r->print('<li>'.join('<br />',@status).'</li>');
1.29 raeburn 5815: }
1.1 raeburn 5816: return $flushc;
5817: }
5818:
5819: # ========================================================= Menu Phase Two Drop
1.17 raeburn 5820: sub print_drop_menu {
1.101 raeburn 5821: my ($r,$context,$permission,$crstype) = @_;
5822: my $heading;
5823: if ($crstype eq 'Community') {
5824: $heading = &mt("Drop Members");
5825: } else {
5826: $heading = &mt("Drop Students");
5827: }
5828: $r->print('<h3>'.$heading.'</h3>'."\n".
1.153 bisitz 5829: '<form name="studentform" method="post" action="">'."\n");
1.30 raeburn 5830: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 5831: if (! defined($classlist)) {
1.143 bisitz 5832: my $msg = '';
1.101 raeburn 5833: if ($crstype eq 'Community') {
1.143 bisitz 5834: $msg = &mt('There are no members currently enrolled.');
1.101 raeburn 5835: } else {
1.143 bisitz 5836: $msg = &mt('There are no students currently enrolled.');
1.101 raeburn 5837: }
1.143 bisitz 5838: $r->print('<p class="LC_info">'.$msg."</p>\n");
1.30 raeburn 5839: } else {
1.101 raeburn 5840: &show_drop_list($r,$classlist,'nosort',$permission,$crstype);
1.1 raeburn 5841: }
1.162 bisitz 5842: $r->print('</form>');
1.1 raeburn 5843: return;
5844: }
5845:
5846: # ================================================================== Phase four
5847:
1.11 raeburn 5848: sub update_user_list {
1.118 raeburn 5849: my ($r,$context,$setting,$choice,$crstype) = @_;
1.11 raeburn 5850: my $now = time;
1.1 raeburn 5851: my $count=0;
1.101 raeburn 5852: if ($context eq 'course') {
5853: $crstype = &Apache::loncommon::course_type();
5854: }
1.212 raeburn 5855: my (@changelist,%got_role_approvals,%got_instdoms,%process_by,%instdoms,
1.213 raeburn 5856: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
1.29 raeburn 5857: if ($choice eq 'drop') {
5858: @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
5859: } else {
1.11 raeburn 5860: @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
5861: }
5862: my %result_text = ( ok => { 'revoke' => 'Revoked',
5863: 'delete' => 'Deleted',
5864: 'reenable' => 'Re-enabled',
1.17 raeburn 5865: 'activate' => 'Activated',
5866: 'chgdates' => 'Changed Access Dates for',
1.118 raeburn 5867: 'chgsec' => 'Changed section(s) for',
1.17 raeburn 5868: 'drop' => 'Dropped',
1.11 raeburn 5869: },
5870: error => {'revoke' => 'revoking',
5871: 'delete' => 'deleting',
5872: 'reenable' => 're-enabling',
5873: 'activate' => 'activating',
1.17 raeburn 5874: 'chgdates' => 'changing access dates for',
5875: 'chgsec' => 'changing section for',
5876: 'drop' => 'dropping',
1.11 raeburn 5877: },
5878: );
5879: my ($startdate,$enddate);
5880: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
5881: ($startdate,$enddate) = &get_dates_from_form();
5882: }
5883: foreach my $item (@changelist) {
1.118 raeburn 5884: my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,
5885: @sections,$scopestem,$singlesec,$showsecs,$warn_singlesec,
1.212 raeburn 5886: $nothingtodo,$keepnosection,$credits,$instsec,$cdom,$cnum);
1.17 raeburn 5887: if ($choice eq 'drop') {
5888: ($uname,$udom,$sec) = split(/:/,$item,-1);
5889: $role = 'st';
5890: $cid = $env{'request.course.id'};
5891: $scopestem = '/'.$cid;
5892: $scopestem =~s/\_/\//g;
5893: if ($sec eq '') {
5894: $scope = $scopestem;
5895: } else {
5896: $scope = $scopestem.'/'.$sec;
5897: }
5898: } elsif ($context eq 'course') {
1.174 raeburn 5899: ($uname,$udom,$role,$sec,$type,$locktype,$credits,$instsec) =
5900: split(/\:/,$item,8);
5901: $instsec = &unescape($instsec);
1.11 raeburn 5902: $cid = $env{'request.course.id'};
1.212 raeburn 5903: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5904: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.11 raeburn 5905: $scopestem = '/'.$cid;
5906: $scopestem =~s/\_/\//g;
5907: if ($sec eq '') {
5908: $scope = $scopestem;
5909: } else {
5910: $scope = $scopestem.'/'.$sec;
5911: }
1.13 raeburn 5912: } elsif ($context eq 'author') {
1.11 raeburn 5913: ($uname,$udom,$role) = split(/\:/,$item,-1);
5914: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
1.212 raeburn 5915: $cdom = $env{'user.domain'};
5916: $cnum = $env{'user.name'};
1.11 raeburn 5917: } elsif ($context eq 'domain') {
5918: if ($setting eq 'domain') {
5919: ($role,$uname,$udom) = split(/\:/,$item,-1);
5920: $scope = '/'.$env{'request.role.domain'}.'/';
1.212 raeburn 5921: $cdom = $env{'request.role.domain'};
1.13 raeburn 5922: } elsif ($setting eq 'author') {
1.11 raeburn 5923: ($uname,$udom,$role,$scope) = split(/\:/,$item);
1.212 raeburn 5924: (undef,$cdom,$cnum) = split(/\//,$scope);
1.11 raeburn 5925: } elsif ($setting eq 'course') {
1.174 raeburn 5926: ($uname,$udom,$role,$cid,$sec,$type,$locktype,$credits,$instsec) =
5927: split(/\:/,$item,9);
1.212 raeburn 5928: ($cdom,$cnum) = split('_',$cid);
1.174 raeburn 5929: $instsec = &unescape($instsec);
1.11 raeburn 5930: $scope = '/'.$cid;
5931: $scope =~s/\_/\//g;
5932: if ($sec ne '') {
5933: $scope .= '/'.$sec;
5934: }
5935: }
5936: }
1.101 raeburn 5937: my $plrole = &Apache::lonnet::plaintext($role,$crstype);
1.11 raeburn 5938: my $start = $env{'form.'.$item.'_start'};
5939: my $end = $env{'form.'.$item.'_end'};
1.17 raeburn 5940: if ($choice eq 'drop') {
5941: # drop students
5942: $end = $now;
5943: $type = 'manual';
5944: $result =
1.52 raeburn 5945: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.17 raeburn 5946: } elsif ($choice eq 'revoke') {
5947: # revoke or delete user role
1.11 raeburn 5948: $end = $now;
5949: if ($role eq 'st') {
5950: $result =
1.174 raeburn 5951: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.11 raeburn 5952: } else {
5953: $result =
1.52 raeburn 5954: &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
5955: '','',$context);
1.11 raeburn 5956: }
5957: } elsif ($choice eq 'delete') {
5958: if ($role eq 'st') {
1.174 raeburn 5959: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.29 raeburn 5960: }
5961: $result =
5962: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
1.52 raeburn 5963: $start,1,'',$context);
1.11 raeburn 5964: } else {
5965: #reenable, activate, change access dates or change section
5966: if ($choice ne 'chgsec') {
5967: $start = $startdate;
5968: $end = $enddate;
5969: }
1.212 raeburn 5970: my $id = $scope.'_'.$role;
1.11 raeburn 5971: if ($choice eq 'reenable') {
1.212 raeburn 5972: next if (&restricted_dom($context,$id,$udom,$uname,$role,$now,$end,$cdom,$cnum,
5973: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 5974: \%got_instdoms,\%reject,\%pending,\%notifydc,
5975: \%status,\%unauthorized,\%currqueued));
1.11 raeburn 5976: if ($role eq 'st') {
1.174 raeburn 5977: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.11 raeburn 5978: } else {
5979: $result =
5980: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 5981: $now,'','',$context);
1.11 raeburn 5982: }
5983: } elsif ($choice eq 'activate') {
1.212 raeburn 5984: next if (&restricted_dom($context,$id,$udom,$uname,$role,$now,$end,$cdom,$cnum,
5985: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 5986: \%got_instdoms,\%reject,\%pending,\%notifydc,
5987: \%status,\%unauthorized,\%currqueued));
1.11 raeburn 5988: if ($role eq 'st') {
1.174 raeburn 5989: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.11 raeburn 5990: } else {
5991: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 5992: $now,'','',$context);
1.11 raeburn 5993: }
5994: } elsif ($choice eq 'chgdates') {
1.212 raeburn 5995: next if (&restricted_dom($context,$id,$udom,$uname,$role,$start,$end,$cdom,$cnum,
5996: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 5997: \%got_instdoms,\%reject,\%pending,\%notifydc,
5998: \%status,\%unauthorized,\%currqueued));
1.11 raeburn 5999: if ($role eq 'st') {
1.174 raeburn 6000: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.11 raeburn 6001: } else {
6002: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 6003: $start,'','',$context);
1.11 raeburn 6004: }
6005: } elsif ($choice eq 'chgsec') {
6006: my (@newsecs,$revresult,$nochg,@retained);
1.103 raeburn 6007: if (($role ne 'cc') && ($role ne 'co')) {
1.117 raeburn 6008: my @secs = sort(split(/,/,$env{'form.newsecs'}));
6009: if (@secs) {
6010: my %curr_groups = &Apache::longroup::coursegroups();
6011: foreach my $sec (@secs) {
6012: next if (($sec =~ /\W/) || ($sec eq 'none') ||
6013: (exists($curr_groups{$sec})));
6014: push(@newsecs,$sec);
6015: }
6016: }
1.11 raeburn 6017: }
6018: # remove existing section if not to be retained.
1.118 raeburn 6019: if (!$env{'form.retainsec'} || ($role eq 'st')) {
1.11 raeburn 6020: if ($sec eq '') {
6021: if (@newsecs == 0) {
1.118 raeburn 6022: $result = 'ok';
1.11 raeburn 6023: $nochg = 1;
1.118 raeburn 6024: $nothingtodo = 1;
1.40 raeburn 6025: } else {
6026: $revresult =
6027: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 6028: $scope,$role,
6029: '','',$context);
1.40 raeburn 6030: }
1.11 raeburn 6031: } else {
1.28 raeburn 6032: if (@newsecs > 0) {
6033: if (grep(/^\Q$sec\E$/,@newsecs)) {
6034: push(@retained,$sec);
6035: } else {
6036: $revresult =
6037: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 6038: $scope,$role,
6039: '','',$context);
1.28 raeburn 6040: }
6041: } else {
1.11 raeburn 6042: $revresult =
1.28 raeburn 6043: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 6044: $scope,$role,
6045: '','',$context);
1.11 raeburn 6046: }
6047: }
6048: } else {
1.28 raeburn 6049: if ($sec eq '') {
6050: $nochg = 1;
1.118 raeburn 6051: $keepnosection = 1;
6052: } else {
1.28 raeburn 6053: push(@retained,$sec);
6054: }
1.11 raeburn 6055: }
6056: # add new sections
1.118 raeburn 6057: my (@diffs,@shownew);
6058: if (@retained) {
6059: @diffs = &Apache::loncommon::compare_arrays(\@retained,\@newsecs);
6060: } else {
6061: @diffs = @newsecs;
6062: }
1.11 raeburn 6063: if (@newsecs == 0) {
1.118 raeburn 6064: if ($nochg) {
6065: $result = 'ok';
6066: $nothingtodo = 1;
6067: } else {
1.28 raeburn 6068: if ($role eq 'st') {
6069: $result =
1.174 raeburn 6070: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.28 raeburn 6071: } else {
6072: my $newscope = $scopestem;
1.52 raeburn 6073: $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
1.11 raeburn 6074: }
6075: }
1.118 raeburn 6076: $showsecs = &mt('No section');
6077: } elsif (@diffs == 0) {
6078: $result = 'ok';
6079: $nothingtodo = 1;
1.11 raeburn 6080: } else {
1.118 raeburn 6081: foreach my $newsec (@newsecs) {
1.11 raeburn 6082: if (!grep(/^\Q$newsec\E$/,@retained)) {
6083: if ($role eq 'st') {
1.174 raeburn 6084: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.118 raeburn 6085: if (@newsecs > 1) {
6086: my $showsingle;
6087: if ($newsec eq '') {
6088: $showsingle = &mt('No section');
6089: } else {
6090: $showsingle = $newsec;
6091: }
6092: if ($crstype eq 'Community') {
6093: $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>');
6094: } else {
6095: $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>');
6096: }
6097: $showsecs = $showsingle;
6098: last;
6099: } else {
6100: if ($newsec eq '') {
6101: $showsecs = &mt('No section');
6102: } else {
6103: $showsecs = $newsec;
6104: }
6105: }
1.11 raeburn 6106: } else {
6107: my $newscope = $scopestem;
6108: if ($newsec ne '') {
6109: $newscope .= '/'.$newsec;
1.118 raeburn 6110: push(@shownew,$newsec);
1.11 raeburn 6111: }
6112: $result = &Apache::lonnet::assignrole($udom,$uname,
6113: $newscope,$role,$end,$start);
1.118 raeburn 6114:
1.11 raeburn 6115: }
6116: }
6117: }
6118: }
1.118 raeburn 6119: unless ($role eq 'st') {
6120: unless ($showsecs) {
6121: my @tolist = sort(@shownew,@retained);
6122: if ($keepnosection) {
6123: push(@tolist,&mt('No section'));
6124: }
6125: $showsecs = join(', ',@tolist);
6126: }
6127: }
1.11 raeburn 6128: }
6129: }
1.17 raeburn 6130: my $extent = $scope;
6131: if ($choice eq 'drop' || $context eq 'course') {
6132: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
6133: if ($cdesc) {
6134: $extent = $cdesc;
6135: }
6136: }
1.1 raeburn 6137: if ($result eq 'ok' || $result eq 'ok:') {
1.118 raeburn 6138: my $dates;
6139: if (($choice eq 'chgsec') || ($choice eq 'chgdates')) {
6140: $dates = &dates_feedback($start,$end,$now);
6141: }
6142: if ($choice eq 'chgsec') {
6143: if ($nothingtodo) {
6144: $r->print(&mt("Section assignment for role of '[_1]' in [_2] for '[_3]' unchanged.",$plrole,$extent,'<i>'.
6145: &Apache::loncommon::plainname($uname,$udom).
6146: '</i>').' ');
6147: if ($sec eq '') {
6148: $r->print(&mt('[_1]No section[_2] - [_3]','<b>','</b>',$dates));
6149: } else {
6150: $r->print(&mt('Section(s): [_1] - [_2]',
6151: '<b>'.$showsecs.'</b>',$dates));
6152: }
6153: $r->print('<br />');
6154: } else {
6155: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' to [_4] - [_5]",$plrole,$extent,
6156: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
6157: '<b>'.$showsecs.'</b>',$dates).'<br />');
6158: $count ++;
6159: }
6160: if ($warn_singlesec) {
6161: $r->print('<div class="LC_warning">'.$warn_singlesec.'</div>');
6162: }
6163: } elsif ($choice eq 'chgdates') {
6164: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' - [_4]",$plrole,$extent,
1.121 raeburn 6165: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
1.118 raeburn 6166: $dates).'<br />');
6167: $count ++;
6168: } else {
6169: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]'.",$plrole,$extent,
1.121 raeburn 6170: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>').
1.118 raeburn 6171: '<br />');
6172: $count ++;
6173: }
1.1 raeburn 6174: } else {
6175: $r->print(
1.118 raeburn 6176: &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for '[_3]': [_4].",
6177: $plrole,$extent,
1.121 raeburn 6178: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
1.118 raeburn 6179: $result).'<br />');
1.11 raeburn 6180: }
6181: }
1.32 raeburn 6182: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
1.33 raeburn 6183: if ($choice eq 'drop') {
6184: $r->print('<input type="hidden" name="action" value="listusers" />'."\n".
6185: '<input type="hidden" name="Status" value="Active" />'."\n".
6186: '<input type="hidden" name="showrole" value="st" />'."\n");
6187: } else {
6188: foreach my $item ('action','sortby','roletype','showrole','Status','secfilter','grpfilter') {
6189: if ($env{'form.'.$item} ne '') {
6190: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.
6191: '" />'."\n");
6192: }
1.32 raeburn 6193: }
6194: }
1.144 bisitz 6195: $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} [quant,_1,user role,user roles,no user roles].",$count).'</b></p>');
1.11 raeburn 6196: if ($count > 0) {
1.17 raeburn 6197: if ($choice eq 'revoke' || $choice eq 'drop') {
1.74 bisitz 6198: $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>');
1.11 raeburn 6199: }
6200: # Flush the course logs so reverse user roles immediately updated
1.126 raeburn 6201: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.11 raeburn 6202: }
6203: if ($env{'form.makedatesdefault'}) {
6204: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
1.101 raeburn 6205: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
1.1 raeburn 6206: }
6207: }
1.213 raeburn 6208: if ((keys(%reject)) || (keys(%unauthorized))) {
6209: $r->print(&print_roles_rejected($context,\%reject,\%unauthorized));
1.212 raeburn 6210: }
1.213 raeburn 6211: if ((keys(%pending)) || (keys(%currqueued))) {
6212: $r->print(&print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.212 raeburn 6213: }
1.33 raeburn 6214: my $linktext = &mt('Display User Lists');
6215: if ($choice eq 'drop') {
6216: $linktext = &mt('Display current class roster');
6217: }
1.144 bisitz 6218: $r->print(
6219: &Apache::lonhtmlcommon::actionbox(
6220: ['<a href="javascript:document.studentform.submit()">'.$linktext.'</a>'])
6221: .'</form>'."\n");
1.1 raeburn 6222: }
6223:
1.118 raeburn 6224: sub dates_feedback {
6225: my ($start,$end,$now) = @_;
6226: my $dates;
6227: if ($start < $now) {
6228: if ($end == 0) {
1.147 bisitz 6229: $dates = &mt('role(s) active now; no end date');
1.118 raeburn 6230: } elsif ($end > $now) {
6231: $dates = &mt('role(s) active now; ends [_1].',&Apache::lonlocal::locallocaltime($end));
6232: } else {
6233: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
6234: }
6235: } else {
6236: if ($end == 0 || $end > $now) {
6237: $dates = &mt('future role(s); starts: [_1].',&Apache::lonlocal::locallocaltime($start));
6238: } else {
6239: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
6240: }
6241: }
6242: return $dates;
6243: }
6244:
1.8 raeburn 6245: sub classlist_drop {
1.29 raeburn 6246: my ($scope,$uname,$udom,$now) = @_;
1.8 raeburn 6247: my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
1.29 raeburn 6248: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.8 raeburn 6249: if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
1.63 raeburn 6250: my %user;
6251: my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
1.8 raeburn 6252: return &mt('Drop from classlist: [_1]',
6253: '<b>'.$result.'</b>').'<br />';
6254: }
6255: }
6256: }
6257:
6258: sub active_student_roles {
6259: my ($cnum,$cdom,$uname,$udom) = @_;
6260: my %roles =
6261: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
6262: ['future','active'],['st']);
6263: return exists($roles{"$cnum:$cdom:st"});
6264: }
6265:
1.1 raeburn 6266: sub section_check_js {
1.8 raeburn 6267: my $groupslist= &get_groupslist();
1.170 damieng 6268: my %js_lt = &Apache::lonlocal::texthash(
6269: mayn => 'may not be used as the name for a section, as it is a reserved word.',
6270: plch => 'Please choose a different section name.',
6271: mnot => 'may not be used as a section name, as it is the name of a course group.',
6272: secn => 'Section names and group names must be distinct. Please choose a different section name.',
6273: );
6274: &js_escape(\%js_lt);
1.1 raeburn 6275: return <<"END";
6276: function validate(caller) {
1.9 raeburn 6277: var groups = new Array($groupslist);
1.1 raeburn 6278: var secname = caller.value;
6279: if ((secname == 'all') || (secname == 'none')) {
1.170 damieng 6280: alert("'"+secname+"' $js_lt{'mayn'}\\n$js_lt{'plch'}");
1.1 raeburn 6281: return 'error';
6282: }
6283: if (secname != '') {
6284: for (var k=0; k<groups.length; k++) {
6285: if (secname == groups[k]) {
1.170 damieng 6286: alert("'"+secname+"' $js_lt{'mnot'}\\n$js_lt{'secn'}");
1.1 raeburn 6287: return 'error';
6288: }
6289: }
6290: }
6291: return 'ok';
6292: }
6293: END
6294: }
6295:
6296: sub set_login {
1.194 raeburn 6297: my ($dom,$authformkrb,$authformint,$authformloc,$authformlti) = @_;
1.1 raeburn 6298: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6299: my $response;
6300: my ($authnum,%can_assign) =
6301: &Apache::loncommon::get_assignable_auth($dom);
6302: if ($authnum) {
6303: $response = &Apache::loncommon::start_data_table();
6304: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
6305: $response .= &Apache::loncommon::start_data_table_row().
6306: '<td>'.$authformkrb.'</td>'.
6307: &Apache::loncommon::end_data_table_row()."\n";
6308: }
6309: if ($can_assign{'int'}) {
6310: $response .= &Apache::loncommon::start_data_table_row().
6311: '<td>'.$authformint.'</td>'.
6312: &Apache::loncommon::end_data_table_row()."\n"
6313: }
6314: if ($can_assign{'loc'}) {
6315: $response .= &Apache::loncommon::start_data_table_row().
6316: '<td>'.$authformloc.'</td>'.
6317: &Apache::loncommon::end_data_table_row()."\n";
6318: }
1.194 raeburn 6319: if ($can_assign{'lti'}) {
6320: $response .= &Apache::loncommon::start_data_table_row().
6321: '<td>'.$authformlti.'</td>'.
6322: &Apache::loncommon::end_data_table_row()."\n";
6323: }
1.1 raeburn 6324: $response .= &Apache::loncommon::end_data_table();
6325: }
6326: return $response;
6327: }
6328:
1.8 raeburn 6329: sub course_sections {
1.178 raeburn 6330: my ($sections_count,$role,$current_sec,$disabled) = @_;
1.8 raeburn 6331: my $output = '';
1.169 raeburn 6332: my @sections = (sort {$a <=> $b} keys(%{$sections_count}));
1.29 raeburn 6333: my $numsec = scalar(@sections);
1.92 bisitz 6334: my $is_selected = ' selected="selected"';
1.29 raeburn 6335: if ($numsec <= 1) {
1.178 raeburn 6336: $output = '<select name="currsec_'.$role.'"'.$disabled.'>'."\n".
1.51 raeburn 6337: ' <option value="">'.&mt('Select').'</option>'."\n";
6338: if ($current_sec eq 'none') {
6339: $output .=
6340: ' <option value=""'.$is_selected.'>'.&mt('No section').'</option>'."\n";
6341: } else {
6342: $output .=
1.29 raeburn 6343: ' <option value="">'.&mt('No section').'</option>'."\n";
1.51 raeburn 6344: }
1.29 raeburn 6345: if ($numsec == 1) {
1.51 raeburn 6346: if ($current_sec eq $sections[0]) {
6347: $output .=
6348: ' <option value="'.$sections[0].'"'.$is_selected.'>'.$sections[0].'</option>'."\n";
6349: } else {
6350: $output .=
1.8 raeburn 6351: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
1.51 raeburn 6352: }
1.29 raeburn 6353: }
1.8 raeburn 6354: } else {
6355: $output = '<select name="currsec_'.$role.'" ';
6356: my $multiple = 4;
6357: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
1.29 raeburn 6358: if ($role eq 'st') {
1.178 raeburn 6359: $output .= $disabled.'>'."\n".
1.51 raeburn 6360: ' <option value="">'.&mt('Select').'</option>'."\n";
6361: if ($current_sec eq 'none') {
6362: $output .=
6363: ' <option value=""'.$is_selected.'>'.&mt('No section')."</option>\n";
6364: } else {
6365: $output .=
1.29 raeburn 6366: ' <option value="">'.&mt('No section')."</option>\n";
1.51 raeburn 6367: }
1.29 raeburn 6368: } else {
1.178 raeburn 6369: $output .= 'multiple="multiple" size="'.$multiple.'"'.$disabled.'>'."\n";
1.29 raeburn 6370: }
1.8 raeburn 6371: foreach my $sec (@sections) {
1.51 raeburn 6372: if ($current_sec eq $sec) {
6373: $output .= '<option value="'.$sec.'"'.$is_selected.'>'.$sec."</option>\n";
6374: } else {
6375: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
6376: }
1.8 raeburn 6377: }
6378: }
6379: $output .= '</select>';
6380: return $output;
6381: }
6382:
6383: sub get_groupslist {
6384: my $groupslist;
6385: my %curr_groups = &Apache::longroup::coursegroups();
6386: if (%curr_groups) {
6387: $groupslist = join('","',sort(keys(%curr_groups)));
6388: $groupslist = '"'.$groupslist.'"';
6389: }
1.11 raeburn 6390: return $groupslist;
1.8 raeburn 6391: }
6392:
6393: sub setsections_javascript {
1.150 raeburn 6394: my ($formname,$groupslist,$mode,$checkauth,$crstype,$showcredits) = @_;
1.28 raeburn 6395: my ($checkincluded,$finish,$rolecode,$setsection_js);
6396: if ($mode eq 'upload') {
6397: $checkincluded = 'formname.name == "'.$formname.'"';
6398: $finish = "return 'ok';";
6399: $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
6400: } elsif ($formname eq 'cu') {
1.150 raeburn 6401: if (($crstype eq 'Course') && ($showcredits)) {
6402: $checkincluded = "((role == 'st') && (formname.elements[i-2].checked == true)) || ((role != 'st') && (formname.elements[i-1].checked == true))";
6403: } else {
6404: $checkincluded = 'formname.elements[i-1].checked == true';
6405: }
1.37 raeburn 6406: if ($checkauth) {
6407: $finish = "var authcheck = auth_check();\n".
6408: " if (authcheck == 'ok') {\n".
6409: " formname.submit();\n".
6410: " }\n";
6411: } else {
6412: $finish = 'formname.submit()';
6413: }
1.28 raeburn 6414: $rolecode = "var match = str.split('_');
6415: var role = match[3];\n";
1.165 raeburn 6416: } elsif (($formname eq 'enrollstudent') || ($formname eq 'selfenroll')) {
1.28 raeburn 6417: $checkincluded = 'formname.name == "'.$formname.'"';
1.37 raeburn 6418: if ($checkauth) {
6419: $finish = "var authcheck = auth_check();\n".
6420: " if (authcheck == 'ok') {\n".
6421: " formname.submit();\n".
6422: " }\n";
6423: } else {
6424: $finish = 'formname.submit()';
6425: }
1.28 raeburn 6426: $rolecode = "var match = str.split('_');
6427: var role = match[1];\n";
1.8 raeburn 6428: } else {
1.28 raeburn 6429: $checkincluded = 'formname.name == "'.$formname.'"';
1.8 raeburn 6430: $finish = "seccheck = 'ok';";
1.28 raeburn 6431: $rolecode = "var match = str.split('_');
6432: var role = match[1];\n";
1.11 raeburn 6433: $setsection_js = "var seccheck = 'alert';";
1.8 raeburn 6434: }
6435: my %alerts = &Apache::lonlocal::texthash(
6436: secd => 'Section designations do not apply to Course Coordinator roles.',
1.103 raeburn 6437: sedn => 'Section designations do not apply to Coordinator roles.',
1.8 raeburn 6438: accr => 'A course coordinator role will be added with access to all sections.',
1.103 raeburn 6439: acor => 'A coordinator role will be added with access to all sections',
1.8 raeburn 6440: inea => 'In each course, each user may only have one student role at a time.',
1.125 raeburn 6441: inco => 'In each community, each user may only have one member role at a time.',
1.145 raeburn 6442: youh => 'You had selected',
1.8 raeburn 6443: secs => 'sections.',
6444: plmo => 'Please modify your selections so they include no more than one section.',
6445: mayn => 'may not be used as the name for a section, as it is a reserved word.',
6446: plch => 'Please choose a different section name.',
6447: mnot => 'may not be used as a section name, as it is the name of a course group.',
6448: secn => 'Section names and group names must be distinct. Please choose a different section name.',
1.113 raeburn 6449: nonw => 'Section names may only contain letters or numbers.',
1.170 damieng 6450: );
6451: &js_escape(\%alerts);
1.8 raeburn 6452: $setsection_js .= <<"ENDSECCODE";
6453:
1.103 raeburn 6454: function setSections(formname,crstype) {
1.8 raeburn 6455: var re1 = /^currsec_/;
1.113 raeburn 6456: var re2 =/\\W/;
1.115 raeburn 6457: var trimleading = /^\\s+/;
6458: var trimtrailing = /\\s+\$/;
1.8 raeburn 6459: var groups = new Array($groupslist);
6460: for (var i=0;i<formname.elements.length;i++) {
6461: var str = formname.elements[i].name;
1.168 raeburn 6462: if (typeof(str) === "undefined") {
6463: continue;
6464: }
1.8 raeburn 6465: var checkcurr = str.match(re1);
6466: if (checkcurr != null) {
1.115 raeburn 6467: var num = i;
1.150 raeburn 6468: $rolecode
1.8 raeburn 6469: if ($checkincluded) {
1.103 raeburn 6470: if (role == 'cc' || role == 'co') {
6471: if (role == 'cc') {
6472: alert("$alerts{'secd'}\\n$alerts{'accr'}");
6473: } else {
6474: alert("$alerts{'sedn'}\\n$alerts{'acor'}");
6475: }
6476: } else {
1.8 raeburn 6477: var sections = '';
6478: var numsec = 0;
1.115 raeburn 6479: var fromexisting = new Array();
6480: for (var j=0; j<formname.elements[num].length; j++) {
6481: if (formname.elements[num].options[j].selected == true ) {
6482: var addsec = formname.elements[num].options[j].value;
1.119 raeburn 6483: if ((addsec != "") && (addsec != null)) {
1.115 raeburn 6484: fromexisting.push(addsec);
1.8 raeburn 6485: if (numsec == 0) {
1.115 raeburn 6486: sections = addsec;
6487: } else {
6488: sections = sections + "," + addsec;
1.8 raeburn 6489: }
1.115 raeburn 6490: numsec ++;
1.8 raeburn 6491: }
6492: }
6493: }
1.115 raeburn 6494: var newsecs = formname.elements[num+1].value;
1.113 raeburn 6495: var validsecs = new Array();
1.115 raeburn 6496: var validsecstr = '';
1.113 raeburn 6497: var badsecs = new Array();
1.8 raeburn 6498: if (newsecs != null && newsecs != "") {
1.115 raeburn 6499: var numsplit;
6500: if (newsecs.indexOf(',') == -1) {
6501: numsplit = new Array(newsecs);
6502: } else {
6503: numsplit = newsecs.split(/,/g);
6504: }
1.117 raeburn 6505: for (var m=0; m<numsplit.length; m++) {
6506: var newsec = numsplit[m];
1.115 raeburn 6507: newsec = newsec.replace(trimleading,'');
6508: newsec = newsec.replace(trimtrailing,'');
6509: if (re2.test(newsec) == true) {
6510: badsecs.push(newsec);
1.113 raeburn 6511: } else {
1.115 raeburn 6512: if (newsec != '') {
6513: var isnew = 1;
6514: if (fromexisting != null) {
1.117 raeburn 6515: for (var n=0; n<fromexisting.length; n++) {
6516: if (newsec == fromexisting[n]) {
1.115 raeburn 6517: isnew = 0;
6518: }
6519: }
6520: }
6521: if (isnew == 1) {
6522: validsecs.push(newsec);
6523: }
6524: }
1.113 raeburn 6525: }
6526: }
6527: if (badsecs.length > 0) {
6528: alert("$alerts{'nonw'}\\n$alerts{'plch'}");
6529: return;
6530: }
6531: numsec = numsec + validsecs.length;
1.8 raeburn 6532: }
6533: if ((role == 'st') && (numsec > 1)) {
1.103 raeburn 6534: if (crstype == 'Community') {
6535: alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
6536: } else {
6537: alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
6538: }
1.8 raeburn 6539: return;
1.115 raeburn 6540: } else {
6541: if (validsecs != null) {
6542: for (var j=0; j<validsecs.length; j++) {
6543: if (validsecstr == '' || validsecstr == null) {
6544: validsecstr = validsecs[j];
6545: } else {
6546: validsecstr += ','+validsecs[j];
6547: }
6548: if ((validsecs[j] == 'all') ||
6549: (validsecs[j] == 'none')) {
6550: alert("'"+validsecs[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
1.8 raeburn 6551: return;
6552: }
6553: for (var k=0; k<groups.length; k++) {
1.115 raeburn 6554: if (validsecs[j] == groups[k]) {
6555: alert("'"+validsecs[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
1.8 raeburn 6556: return;
6557: }
6558: }
6559: }
6560: }
6561: }
1.115 raeburn 6562: if ((validsecstr != '') && (validsecstr != null)) {
1.117 raeburn 6563: if ((sections == '') || (sections == null)) {
6564: sections = validsecstr;
6565: } else {
1.115 raeburn 6566: sections = sections + "," + validsecstr;
6567: }
6568: }
6569: formname.elements[num+2].value = sections;
1.8 raeburn 6570: }
6571: }
6572: }
6573: }
6574: $finish
6575: }
6576: ENDSECCODE
1.11 raeburn 6577: return $setsection_js;
1.8 raeburn 6578: }
6579:
1.15 raeburn 6580: sub can_create_user {
6581: my ($dom,$context,$usertype) = @_;
6582: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6583: my $cancreate = 1;
1.28 raeburn 6584: if (&Apache::lonnet::allowed('mau',$dom)) {
6585: return $cancreate;
1.178 raeburn 6586: } elsif ($context eq 'domain') {
6587: $cancreate = 0;
6588: return $cancreate;
1.28 raeburn 6589: }
1.15 raeburn 6590: if (ref($domconf{'usercreation'}) eq 'HASH') {
6591: if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
1.100 raeburn 6592: if ($context eq 'course' || $context eq 'author' || $context eq 'requestcrs') {
1.15 raeburn 6593: my $creation = $domconf{'usercreation'}{'cancreate'}{$context};
6594: if ($creation eq 'none') {
6595: $cancreate = 0;
6596: } elsif ($creation ne 'any') {
6597: if (defined($usertype)) {
6598: if ($creation ne $usertype) {
6599: $cancreate = 0;
6600: }
6601: }
6602: }
6603: }
6604: }
6605: }
6606: return $cancreate;
6607: }
6608:
1.20 raeburn 6609: sub can_modify_userinfo {
6610: my ($context,$dom,$fields,$userroles) = @_;
6611: my %domconfig =
6612: &Apache::lonnet::get_dom('configuration',['usermodification'],
6613: $dom);
6614: my %canmodify;
6615: if (ref($fields) eq 'ARRAY') {
6616: foreach my $field (@{$fields}) {
6617: $canmodify{$field} = 0;
6618: if (&Apache::lonnet::allowed('mau',$dom)) {
6619: $canmodify{$field} = 1;
6620: } else {
6621: if (ref($domconfig{'usermodification'}) eq 'HASH') {
6622: if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
6623: if (ref($userroles) eq 'ARRAY') {
6624: foreach my $role (@{$userroles}) {
6625: my $testrole;
1.60 raeburn 6626: if ($context eq 'selfcreate') {
6627: $testrole = $role;
1.20 raeburn 6628: } else {
1.60 raeburn 6629: if ($role =~ /^cr\//) {
6630: $testrole = 'cr';
6631: } else {
6632: $testrole = $role;
6633: }
1.20 raeburn 6634: }
6635: if (ref($domconfig{'usermodification'}{$context}{$testrole}) eq 'HASH') {
6636: if ($domconfig{'usermodification'}{$context}{$testrole}{$field}) {
6637: $canmodify{$field} = 1;
6638: last;
6639: }
6640: }
6641: }
6642: } else {
6643: foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
6644: if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
6645: if ($domconfig{'usermodification'}{$context}{$key}{$field}) {
6646: $canmodify{$field} = 1;
6647: last;
6648: }
6649: }
6650: }
6651: }
6652: }
6653: } elsif ($context eq 'course') {
6654: if (ref($userroles) eq 'ARRAY') {
6655: if (grep(/^st$/,@{$userroles})) {
6656: $canmodify{$field} = 1;
6657: }
6658: } else {
6659: $canmodify{$field} = 1;
6660: }
6661: }
6662: }
6663: }
6664: }
6665: return %canmodify;
6666: }
6667:
1.195 raeburn 6668: sub can_change_internalpass {
6669: my ($uname,$udom,$crstype,$permission) = @_;
6670: my $canchange;
6671: if (&Apache::lonnet::allowed('mau',$udom)) {
6672: $canchange = 1;
6673: } elsif ((ref($permission) eq 'HASH') && ($permission->{'mip'}) &&
6674: ($udom eq $env{'request.role.domain'})) {
6675: unless ($env{'course.'.$env{'request.course.id'}.'.internal.nopasswdchg'}) {
6676: my ($cnum,$cdom) = &get_course_identity();
6677: if ((&Apache::lonnet::is_course_owner($cdom,$cnum)) && ($udom eq $env{'user.domain'})) {
1.199 raeburn 6678: my @userstatuses = ('default');
6679: my %userenv = &Apache::lonnet::userenvironment($udom,$uname,'inststatus');
6680: if ($userenv{'inststatus'} ne '') {
6681: @userstatuses = split(/:/,$userenv{'inststatus'});
6682: }
6683: my $noupdate = 1;
6684: my %passwdconf = &Apache::lonnet::get_passwdconf($cdom);
6685: if (ref($passwdconf{'crsownerchg'}) eq 'HASH') {
6686: if (ref($passwdconf{'crsownerchg'}{'for'}) eq 'ARRAY') {
6687: foreach my $status (@userstatuses) {
6688: if (grep(/^\Q$status\E$/,@{$passwdconf{'crsownerchg'}{'for'}})) {
6689: undef($noupdate);
6690: last;
6691: }
6692: }
6693: }
6694: }
6695: if ($noupdate) {
6696: return;
6697: }
1.195 raeburn 6698: my %owned = &Apache::lonnet::courseiddump($cdom,'.',1,'.',
6699: $env{'user.name'}.':'.$env{'user.domain'},
6700: undef,undef,undef,'.');
6701: my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
6702: ['active','future']);
6703: foreach my $key (keys(%roleshash)) {
6704: my ($name,$domain,$role) = split(/:/,$key);
6705: if ($role eq 'st') {
6706: next if (($name eq $cnum) && ($domain eq $cdom));
6707: if ($owned{$domain.'_'.$name}) {
6708: if (ref($owned{$domain.'_'.$name}) eq 'HASH') {
6709: if ($owned{$domain.'_'.$name}{'nopasswdchg'}) {
6710: $noupdate = 1;
6711: last;
6712: }
6713: }
6714: } else {
6715: $noupdate = 1;
6716: last;
6717: }
6718: } else {
6719: $noupdate = 1;
6720: last;
6721: }
6722: }
6723: unless ($noupdate) {
6724: $canchange = 1;
6725: }
6726: }
6727: }
6728: }
6729: return $canchange;
6730: }
6731:
1.18 raeburn 6732: sub check_usertype {
1.134 raeburn 6733: my ($dom,$uname,$rules,$curr_rules,$got_rules) = @_;
1.18 raeburn 6734: my $usertype;
1.134 raeburn 6735: if ((ref($got_rules) eq 'HASH') && (ref($curr_rules) eq 'HASH')) {
6736: if (!$got_rules->{$dom}) {
6737: my %domconfig = &Apache::lonnet::get_dom('configuration',
6738: ['usercreation'],$dom);
6739: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6740: foreach my $item ('username','id') {
6741: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
6742: $curr_rules->{$dom}{$item} =
6743: $domconfig{'usercreation'}{$item.'_rule'};
6744: }
6745: }
6746: }
6747: $got_rules->{$dom} = 1;
6748: }
6749: if (ref($rules) eq 'HASH') {
6750: my @user_rules;
6751: if (ref($curr_rules->{$dom}{'username'}) eq 'ARRAY') {
6752: foreach my $rule (keys(%{$rules})) {
6753: if (grep(/^\Q$rule\E/,@{$curr_rules->{$dom}{'username'}})) {
6754: push(@user_rules,$rule);
6755: }
6756: }
6757: }
6758: if (@user_rules > 0) {
6759: my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
6760: if (keys(%rule_check) > 0) {
6761: $usertype = 'unofficial';
6762: foreach my $item (keys(%rule_check)) {
6763: if ($rule_check{$item}) {
6764: $usertype = 'official';
6765: last;
6766: }
1.18 raeburn 6767: }
6768: }
6769: }
6770: }
6771: }
6772: return $usertype;
6773: }
6774:
1.17 raeburn 6775: sub roles_by_context {
1.101 raeburn 6776: my ($context,$custom,$crstype) = @_;
1.17 raeburn 6777: my @allroles;
6778: if ($context eq 'course') {
1.99 raeburn 6779: @allroles = ('st');
6780: if ($env{'request.role'} =~ m{^dc\./}) {
6781: push(@allroles,'ad');
6782: }
1.101 raeburn 6783: push(@allroles,('ta','ep','in'));
6784: if ($crstype eq 'Community') {
6785: push(@allroles,'co');
6786: } else {
6787: push(@allroles,'cc');
6788: }
1.17 raeburn 6789: if ($custom) {
6790: push(@allroles,'cr');
6791: }
6792: } elsif ($context eq 'author') {
6793: @allroles = ('ca','aa');
6794: } elsif ($context eq 'domain') {
1.182 raeburn 6795: @allroles = ('li','ad','dg','dh','da','sc','au','dc');
1.17 raeburn 6796: }
6797: return @allroles;
6798: }
6799:
1.16 raeburn 6800: sub get_permission {
1.101 raeburn 6801: my ($context,$crstype) = @_;
1.16 raeburn 6802: my %permission;
6803: if ($context eq 'course') {
1.17 raeburn 6804: my $custom = 1;
1.101 raeburn 6805: my @allroles = &roles_by_context($context,$custom,$crstype);
1.17 raeburn 6806: foreach my $role (@allroles) {
6807: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
6808: $permission{'cusr'} = 1;
6809: last;
6810: }
1.16 raeburn 6811: }
6812: if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
6813: $permission{'custom'} = 1;
6814: }
6815: if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
6816: $permission{'view'} = 1;
6817: }
6818: if (!$permission{'view'}) {
6819: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
6820: $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
6821: if ($permission{'view'}) {
6822: $permission{'view_section'} = $env{'request.course.sec'};
6823: }
6824: }
1.17 raeburn 6825: if (!$permission{'cusr'}) {
6826: if ($env{'request.course.sec'} ne '') {
6827: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
6828: $permission{'cusr'} = (&Apache::lonnet::allowed('cst',$scope));
6829: if ($permission{'cusr'}) {
6830: $permission{'cusr_section'} = $env{'request.course.sec'};
6831: }
6832: }
6833: }
1.16 raeburn 6834: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
6835: $permission{'grp_manage'} = 1;
6836: }
1.165 raeburn 6837: if ($permission{'cusr'}) {
6838: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6839: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6840: my %coursehash = (
6841: 'internal.selfenrollmgrdc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrdc'},
6842: 'internal.selfenrollmgrcc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrcc'},
6843: 'internal.coursecode' => $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},
6844: 'internal.textbook' =>$env{'course.'.$env{'request.course.id'}.'.internal.textbook'},
6845: );
6846: my ($managed_by_cc,$managed_by_dc) = &selfenrollment_administration($cdom,$cnum,$crstype,\%coursehash);
6847: if (ref($managed_by_cc) eq 'ARRAY') {
6848: if (@{$managed_by_cc}) {
6849: $permission{'selfenrolladmin'} = 1;
6850: }
6851: }
1.216 raeburn 6852: unless ($permission{'selfenrolladmin'}) {
6853: $permission{'selfenrollview'} = 1;
6854: }
1.165 raeburn 6855: }
1.180 raeburn 6856: if ($env{'request.course.id'}) {
1.195 raeburn 6857: my $user;
6858: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
6859: $user = $env{'user.name'}.':'.$env{'user.domain'};
6860: }
1.180 raeburn 6861: if (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'} eq
6862: $user)) {
6863: $permission{'owner'} = 1;
1.195 raeburn 6864: if (&Apache::lonnet::allowed('mip',$env{'request.course.id'})) {
6865: $permission{'mip'} = 1;
6866: }
1.180 raeburn 6867: } elsif (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.co-owners'} ne '')) {
6868: if (grep(/^\Q$user\E$/,split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.co-owners'}))) {
6869: $permission{'co-owner'} = 1;
6870: }
6871: }
6872: }
1.16 raeburn 6873: } elsif ($context eq 'author') {
1.218 raeburn 6874: my $audom = $env{'request.role.domain'};
6875: my $auname = $env{'user.name'};
6876: if ((&Apache::lonnet::allowed('cca',"$audom/$auname")) ||
6877: (&Apache::lonnet::allowed('caa',"$audom/$auname"))) {
6878: $permission{'author'} = 1;
6879: $permission{'cusr'} = 1;
6880: $permission{'view'} = 1;
6881: }
6882: } elsif ($context eq 'coauthor') {
6883: my ($audom,$auname) = ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$});
6884: if ((&Apache::lonnet::allowed('vca',"$audom/$auname")) ||
6885: (&Apache::lonnet::allowed('vaa',"$audom/$auname"))) {
6886: if ($env{"environment.internal.manager./$audom/$auname"}) {
6887: $permission{'cusr'} = 1;
6888: $permission{'view'} = 1;
6889: }
6890: }
1.16 raeburn 6891: } else {
1.17 raeburn 6892: my @allroles = &roles_by_context($context);
6893: foreach my $role (@allroles) {
1.28 raeburn 6894: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
6895: $permission{'cusr'} = 1;
1.17 raeburn 6896: last;
6897: }
6898: }
6899: if (!$permission{'cusr'}) {
6900: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
6901: $permission{'cusr'} = 1;
6902: }
1.16 raeburn 6903: }
6904: if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
6905: $permission{'custom'} = 1;
6906: }
1.176 raeburn 6907: if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
6908: $permission{'activity'} = 1;
6909: }
1.178 raeburn 6910: if (&Apache::lonnet::allowed('vur',$env{'request.role.domain'})) {
6911: $permission{'view'} = 1;
6912: }
1.180 raeburn 6913: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
6914: $permission{'owner'} = 1;
6915: }
1.16 raeburn 6916: }
6917: my $allowed = 0;
1.211 raeburn 6918: foreach my $key (keys(%permission)) {
1.218 raeburn 6919: next if (($key eq 'owner') || ($key eq 'co-owner') || ($key eq 'author'));
1.211 raeburn 6920: if ($permission{$key}) { $allowed=1; last; }
1.16 raeburn 6921: }
6922: return (\%permission,$allowed);
6923: }
6924:
6925: # ==================================================== Figure out author access
6926:
6927: sub authorpriv {
6928: my ($auname,$audom)=@_;
6929: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
6930: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; } return 1;
6931: }
6932:
1.218 raeburn 6933: sub coauthorpriv {
6934: my ($auname,$audom)=@_;
6935: my $uname = $env{'user.name'};
6936: my $udom = $env{'user.domain'};
6937: if (((&Apache::lonnet::allowed('vca',"$udom/$uname")) ||
6938: (&Apache::lonnet::allowed('vaa',"$udom/$uname"))) &&
6939: ($env{"environment.internal.manager./$audom/$auname"})) {
6940: return 1;
6941: }
6942: return '';
6943: }
6944:
1.27 raeburn 6945: sub roles_on_upload {
1.101 raeburn 6946: my ($context,$setting,$crstype,%customroles) = @_;
1.27 raeburn 6947: my (@possible_roles,@permitted_roles);
1.101 raeburn 6948: @possible_roles = &curr_role_permissions($context,$setting,1,$crstype);
1.27 raeburn 6949: foreach my $role (@possible_roles) {
6950: if ($role eq 'cr') {
6951: push(@permitted_roles,keys(%customroles));
6952: } else {
6953: push(@permitted_roles,$role);
6954: }
6955: }
1.42 raeburn 6956: return @permitted_roles;
1.27 raeburn 6957: }
6958:
1.17 raeburn 6959: sub get_course_identity {
6960: my ($cid) = @_;
6961: my ($cnum,$cdom,$cdesc);
6962: if ($cid eq '') {
6963: $cid = $env{'request.course.id'}
6964: }
6965: if ($cid ne '') {
6966: $cnum = $env{'course.'.$cid.'.num'};
6967: $cdom = $env{'course.'.$cid.'.domain'};
6968: $cdesc = $env{'course.'.$cid.'.description'};
6969: if ($cnum eq '' || $cdom eq '') {
6970: my %coursehash =
6971: &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
6972: $cdom = $coursehash{'domain'};
6973: $cnum = $coursehash{'num'};
6974: $cdesc = $coursehash{'description'};
6975: }
6976: }
6977: return ($cnum,$cdom,$cdesc);
6978: }
6979:
1.19 raeburn 6980: sub dc_setcourse_js {
1.196 raeburn 6981: my ($formname,$mode,$context,$showcredits,$domain) = @_;
1.37 raeburn 6982: my ($dc_setcourse_code,$authen_check);
1.19 raeburn 6983: my $cctext = &Apache::lonnet::plaintext('cc');
1.103 raeburn 6984: my $cotext = &Apache::lonnet::plaintext('co');
1.19 raeburn 6985: my %alerts = §ioncheck_alerts();
6986: my $role = 'role';
6987: if ($mode eq 'upload') {
6988: $role = 'courserole';
1.37 raeburn 6989: } else {
1.196 raeburn 6990: $authen_check = &verify_authen($formname,$context,$domain);
1.19 raeburn 6991: }
6992: $dc_setcourse_code = (<<"SCRIPTTOP");
1.37 raeburn 6993: $authen_check
6994:
1.19 raeburn 6995: function setCourse() {
6996: var course = document.$formname.dccourse.value;
6997: if (course != "") {
6998: if (document.$formname.dcdomain.value != document.$formname.origdom.value) {
6999: alert("$alerts{'curd'}");
7000: return;
7001: }
7002: var userrole = document.$formname.$role.options[document.$formname.$role.selectedIndex].value
7003: var section="";
7004: var numsections = 0;
7005: var newsecs = new Array();
7006: for (var i=0; i<document.$formname.currsec.length; i++) {
7007: if (document.$formname.currsec.options[i].selected == true ) {
7008: if (document.$formname.currsec.options[i].value != "" && document.$formname.currsec.options[i].value != null) {
7009: if (numsections == 0) {
7010: section = document.$formname.currsec.options[i].value
7011: numsections = 1;
7012: }
7013: else {
7014: section = section + "," + document.$formname.currsec.options[i].value
7015: numsections ++;
7016: }
7017: }
7018: }
7019: }
7020: if (document.$formname.newsec.value != "" && document.$formname.newsec.value != null) {
7021: if (numsections == 0) {
7022: section = document.$formname.newsec.value
7023: }
7024: else {
7025: section = section + "," + document.$formname.newsec.value
7026: }
7027: newsecs = document.$formname.newsec.value.split(/,/g);
7028: numsections = numsections + newsecs.length;
7029: }
7030: if ((userrole == 'st') && (numsections > 1)) {
1.103 raeburn 7031: if (document.$formname.crstype.value == 'Community') {
7032: alert("$alerts{'inco'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
7033: } else {
7034: alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
7035: }
1.19 raeburn 7036: return;
7037: }
7038: for (var j=0; j<newsecs.length; j++) {
7039: if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
7040: alert("'"+newsecs[j]+"' $alerts{'mayn'}.\\n$alerts{'plsc'}.");
7041: return;
7042: }
7043: if (document.$formname.groups.value != '') {
7044: var groups = document.$formname.groups.value.split(/,/g);
7045: for (var k=0; k<groups.length; k++) {
7046: if (newsecs[j] == groups[k]) {
1.103 raeburn 7047: if (document.$formname.crstype.value == 'Community') {
7048: alert("'"+newsecs[j]+"' $alerts{'mayc'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
7049: } else {
7050: alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
7051: }
1.19 raeburn 7052: return;
7053: }
7054: }
7055: }
7056: }
7057: if ((userrole == 'cc') && (numsections > 0)) {
7058: alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
7059: section = "";
7060: }
1.103 raeburn 7061: if ((userrole == 'co') && (numsections > 0)) {
7062: alert("$alerts{'secd'} $cotext $alerts{'role'}.\\n$alerts{'accr'}.");
7063: section = "";
7064: }
1.19 raeburn 7065: SCRIPTTOP
7066: if ($mode ne 'upload') {
1.150 raeburn 7067: $dc_setcourse_code .= (<<"SCRIPTMID");
1.19 raeburn 7068: var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
7069: var numcourse = getIndex(document.$formname.dccourse);
7070: if (numcourse == "-1") {
1.103 raeburn 7071: if (document.$formname.type == 'Community') {
7072: alert("$alerts{'thwc'}");
7073: } else {
7074: alert("$alerts{'thwa'}");
7075: }
1.19 raeburn 7076: return;
7077: }
7078: else {
7079: document.$formname.elements[numcourse].name = "act"+coursename;
7080: var numnewsec = getIndex(document.$formname.newsec);
7081: if (numnewsec != "-1") {
7082: document.$formname.elements[numnewsec].name = "sec"+coursename;
7083: document.$formname.elements[numnewsec].value = section;
7084: }
7085: var numstart = getIndex(document.$formname.start);
7086: if (numstart != "-1") {
7087: document.$formname.elements[numstart].name = "start"+coursename;
7088: }
7089: var numend = getIndex(document.$formname.end);
7090: if (numend != "-1") {
7091: document.$formname.elements[numend].name = "end"+coursename
7092: }
1.150 raeburn 7093: SCRIPTMID
7094: if ($showcredits) {
7095: $dc_setcourse_code .= <<ENDCRED;
7096: var numcredits = getIndex(document.$formname.credits);
7097: if (numcredits != "-1") {
7098: document.$formname.elements[numcredits].name = "credits"+coursename;
7099: }
7100: ENDCRED
7101: }
7102: $dc_setcourse_code .= <<ENDSCRIPT;
1.19 raeburn 7103: }
7104: }
1.37 raeburn 7105: var authcheck = auth_check();
7106: if (authcheck == 'ok') {
7107: document.$formname.submit();
7108: }
1.19 raeburn 7109: }
7110: ENDSCRIPT
7111: } else {
7112: $dc_setcourse_code .= "
7113: document.$formname.sections.value = section;
7114: }
7115: return 'ok';
7116: }
7117: ";
7118: }
7119: $dc_setcourse_code .= (<<"ENDSCRIPT");
7120:
7121: function getIndex(caller) {
7122: for (var i=0;i<document.$formname.elements.length;i++) {
7123: if (document.$formname.elements[i] == caller) {
7124: return i;
7125: }
7126: }
7127: return -1;
7128: }
7129: ENDSCRIPT
1.37 raeburn 7130: return $dc_setcourse_code;
7131: }
7132:
7133: sub verify_authen {
1.196 raeburn 7134: my ($formname,$context,$domain) = @_;
1.37 raeburn 7135: my %alerts = &authcheck_alerts();
7136: my $finish = "return 'ok';";
7137: if ($context eq 'author') {
7138: $finish = "document.$formname.submit();";
7139: }
1.196 raeburn 7140: my ($numrules,$intargjs) =
1.210 raeburn 7141: &Apache::loncommon::passwd_validation_js('argpicked',$domain);
1.37 raeburn 7142: my $outcome = <<"ENDSCRIPT";
7143:
7144: function auth_check() {
7145: var logintype;
7146: if (document.$formname.login.length) {
7147: if (document.$formname.login.length > 0) {
7148: var loginpicked = 0;
7149: for (var i=0; i<document.$formname.login.length; i++) {
7150: if (document.$formname.login[i].checked == true) {
7151: loginpicked = 1;
7152: logintype = document.$formname.login[i].value;
7153: }
7154: }
7155: if (loginpicked == 0) {
7156: alert("$alerts{'authen'}");
7157: return;
7158: }
7159: }
7160: } else {
7161: logintype = document.$formname.login.value;
7162: }
7163: if (logintype == 'nochange') {
7164: return 'ok';
7165: }
7166: var argpicked = document.$formname.elements[logintype+'arg'].value;
7167: if ((argpicked == null) || (argpicked == '') || (typeof argpicked == 'undefined')) {
7168: var alertmsg = '';
7169: switch (logintype) {
7170: case 'krb':
7171: alertmsg = '$alerts{'krb'}';
7172: break;
7173: case 'int':
7174: alertmsg = '$alerts{'ipass'}';
1.196 raeburn 7175: break;
1.37 raeburn 7176: case 'fsys':
7177: alertmsg = '$alerts{'ipass'}';
7178: break;
7179: case 'loc':
7180: alertmsg = '';
7181: break;
7182: default:
7183: alertmsg = '';
7184: }
7185: if (alertmsg != '') {
7186: alert(alertmsg);
7187: return;
7188: }
1.196 raeburn 7189: } else if (logintype == 'int') {
7190: var numrules = $numrules;
7191: if (numrules > 0) {
7192: $intargjs
7193: }
1.37 raeburn 7194: }
7195: $finish
7196: }
7197: ENDSCRIPT
1.19 raeburn 7198: }
7199:
7200: sub sectioncheck_alerts {
7201: my %alerts = &Apache::lonlocal::texthash(
1.103 raeburn 7202: curd => 'You must select a course or community in the current domain',
1.19 raeburn 7203: inea => 'In each course, each user may only have one student role at a time',
1.103 raeburn 7204: inco => 'In each community, each user may only have one member role at a time',
1.19 raeburn 7205: youh => 'You had selected',
7206: sect => 'sections',
7207: plsm => 'Please modify your selections so they include no more than one section',
7208: mayn => 'may not be used as the name for a section, as it is a reserved word',
7209: plsc => 'Please choose a different section name',
7210: mayt => 'may not be used as the name for a section, as it is the name of a course group',
1.103 raeburn 7211: mayc => 'may not be used as the name for a section, as it is the name of a community group',
1.19 raeburn 7212: secn => 'Section names and group names must be distinct',
7213: secd => 'Section designations do not apply to ',
7214: role => 'roles',
7215: accr => 'role will be added with access to all sections',
1.103 raeburn 7216: thwa => 'There was a problem with your course selection',
7217: thwc => 'There was a problem with your community selection',
1.19 raeburn 7218: );
1.170 damieng 7219: &js_escape(\%alerts);
1.19 raeburn 7220: return %alerts;
7221: }
1.17 raeburn 7222:
1.37 raeburn 7223: sub authcheck_alerts {
7224: my %alerts =
7225: &Apache::lonlocal::texthash(
7226: authen => 'You must choose an authentication type.',
7227: krb => 'You need to specify the Kerberos domain.',
7228: ipass => 'You need to specify the initial password.',
7229: );
1.170 damieng 7230: &js_escape(\%alerts);
1.37 raeburn 7231: return %alerts;
7232: }
7233:
1.141 raeburn 7234: sub is_courseowner {
7235: my ($thiscourse,$courseowner) = @_;
7236: if ($courseowner eq '') {
7237: if ($env{'request.course.id'} eq $thiscourse) {
7238: $courseowner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
7239: }
7240: }
7241: if ($courseowner ne '') {
7242: if ($courseowner eq $env{'user.name'}.':'.$env{'user.domain'}) {
7243: return 1;
7244: }
7245: }
7246: return;
7247: }
7248:
1.165 raeburn 7249: sub get_selfenroll_titles {
7250: my @row = ('types','registered','enroll_dates','access_dates','section',
7251: 'approval','limit');
7252: my %lt = &Apache::lonlocal::texthash (
7253: types => 'Users allowed to self-enroll',
7254: registered => 'Registration status (official courses)' ,
7255: enroll_dates => 'Dates self-enrollment available',
7256: access_dates => 'Access dates for self-enrolling users',
7257: section => "Self-enrolling users' section",
7258: approval => 'Processing of requests',
7259: limit => 'Enrollment limit',
7260: );
7261: return (\@row,\%lt);
7262: }
7263:
7264: sub selfenroll_default_descs {
7265: my %desc = (
7266: types => {
7267: dom => &mt('Course domain'),
7268: all => &mt('Any domain'),
7269: '' => &mt('None'),
7270: },
7271: limit => {
7272: none => &mt('No limit'),
7273: allstudents => &mt('Limit by total students'),
7274: selfenrolled => &mt('Limit by total self-enrolled'),
7275: },
7276: approval => {
7277: '0' => &mt('Processed automatically'),
7278: '1' => &mt('Queued for approval'),
7279: '2' => &mt('Queued, pending validation'),
7280: },
7281: registered => {
7282: 0 => 'No registration required',
7283: 1 => 'Registered students only',
7284: },
7285: );
7286: return %desc;
7287: }
7288:
7289: sub selfenroll_validation_types {
7290: my @items = ('url','fields','button','markup');
7291: my %names = &Apache::lonlocal::texthash (
7292: url => 'Web address of validation server/script',
7293: fields => 'Form fields to send to validator',
7294: button => 'Text for validation button',
7295: markup => 'Validation description (HTML)',
7296: );
1.167 raeburn 7297: my @fields = ('username','domain','uniquecode','course','coursetype','description');
1.165 raeburn 7298: return (\@items,\%names,\@fields);
7299: }
7300:
7301: sub get_extended_type {
7302: my ($cdom,$cnum,$crstype,$current) = @_;
7303: my $type = 'unofficial';
7304: my %settings;
7305: if (ref($current) eq 'HASH') {
7306: %settings = %{$current};
7307: } else {
7308: %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook'],$cdom,$cnum);
7309: }
7310: if ($crstype eq 'Community') {
7311: $type = 'community';
1.173 raeburn 7312: } elsif ($crstype eq 'Placement') {
7313: $type = 'placement';
1.165 raeburn 7314: } elsif ($settings{'internal.coursecode'}) {
7315: $type = 'official';
7316: } elsif ($settings{'internal.textbook'}) {
7317: $type = 'textbook';
7318: }
7319: return $type;
7320: }
7321:
7322: sub selfenrollment_administration {
7323: my ($cdom,$cnum,$crstype,$coursehash) = @_;
7324: my %settings;
7325: if (ref($coursehash) eq 'HASH') {
7326: %settings = %{$coursehash};
7327: } else {
7328: %settings = &Apache::lonnet::get('environment',
7329: ['internal.selfenrollmgrdc','internal.selfenrollmgrcc',
7330: 'internal.coursecode','internal.textbook'],$cdom,$cnum);
7331: }
7332: my ($possconfigs) = &get_selfenroll_titles();
7333: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
7334: my $selfenrolltype = &get_extended_type($cdom,$cnum,$crstype,\%settings);
7335:
7336: my (@in_course,@in_domain);
7337: if ($settings{'internal.selfenrollmgrcc'} ne '') {
7338: @in_course = split(/,/,$settings{'internal.selfenrollmgrcc'});
7339: my @diffs = &Apache::loncommon::compare_arrays($possconfigs,\@in_course);
7340: unless (@diffs) {
7341: return (\@in_course,\@in_domain);
7342: }
7343: }
7344: if ($settings{'internal.selfenrollmgrdc'} ne '') {
1.215 raeburn 7345: @in_domain = split(/,/,$settings{'internal.selfenrollmgrdc'});
1.165 raeburn 7346: my @diffs = &Apache::loncommon::compare_arrays(\@in_domain,$possconfigs);
7347: unless (@diffs) {
7348: return (\@in_course,\@in_domain);
7349: }
7350: }
7351: my @combined = @in_course;
7352: push(@combined,@in_domain);
7353: my @diffs = &Apache::loncommon::compare_arrays(\@combined,$possconfigs);
7354: unless (@diffs) {
7355: return (\@in_course,\@in_domain);
7356: }
7357: if ($domdefaults{$selfenrolltype.'selfenrolladmdc'} eq '') {
7358: push(@in_course,@diffs);
7359: } else {
7360: my @defaultdc = split(/,/,$domdefaults{$selfenrolltype.'selfenrolladmdc'});
7361: foreach my $item (@diffs) {
7362: if (grep(/^\Q$item\E$/,@defaultdc)) {
7363: push(@in_domain,$item);
7364: } else {
7365: push(@in_course,$item);
7366: }
7367: }
7368: }
7369: return (\@in_course,\@in_domain);
7370: }
7371:
1.175 raeburn 7372: sub custom_role_header {
7373: my ($context,$crstype,$templaterolerefs,$prefix) = @_;
7374: my %lt = &Apache::lonlocal::texthash(
7375: sele => 'Select a Template',
7376: );
7377: my ($context_code,$button_code);
7378: if ($context eq 'domain') {
7379: $context_code = &custom_coursetype_switch($crstype,$prefix);
7380: }
7381: if (ref($templaterolerefs) eq 'ARRAY') {
7382: foreach my $role (@{$templaterolerefs}) {
7383: my $display = 'inline';
7384: if (($context eq 'domain') && ($role eq 'co')) {
7385: $display = 'none';
7386: }
7387: $button_code .= &make_button_code($role,$crstype,$display,$prefix).' ';
7388: }
7389: }
7390: return <<"END";
7391: <div class="LC_left_float">
7392: <fieldset>
7393: <legend>$lt{'sele'}</legend>
7394: $button_code
7395: </fieldset></div>
7396: $context_code
7397: <br clear="all" />
7398: END
7399: }
7400:
7401: sub custom_coursetype_switch {
7402: my ($crstype,$prefix) = @_;
7403: my ($checkedcourse,$checkedcommunity);
7404: if ($crstype eq 'Community') {
7405: $checkedcommunity = ' checked="checked"';
7406: } else {
7407: $checkedcourse = ' checked="checked"';
7408: }
7409: my %lt = &Apache::lonlocal::texthash(
7410: cont => 'Context',
7411: cour => 'Course',
7412: comm => 'Community',
7413: );
7414: return <<"END";
7415: <div class="LC_left_float">
7416: <fieldset>
7417: <legend>$lt{'cont'}</legend>
7418: <label>
7419: <input type="radio" name="${prefix}_custrolecrstype" value="Course"$checkedcourse onclick="javascript:customSwitchType('$prefix');" />
7420: $lt{'cour'}
7421: </label>
7422: <label>
7423: <input type="radio" name="${prefix}_custrolecrstype" value="Community"$checkedcommunity onclick="javascript:customSwitchType('$prefix');" />
7424: $lt{'comm'}
7425: </label>
7426: </fieldset>
7427: </div>
7428: END
7429: }
7430:
7431: sub custom_role_table {
1.180 raeburn 7432: my ($crstype,$full,$levels,$levelscurrent,$prefix,$add_class,$id) = @_;
1.175 raeburn 7433: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7434: (ref($levelscurrent) eq 'HASH'));
7435: my %lt=&Apache::lonlocal::texthash (
7436: 'prv' => "Privilege",
7437: 'crl' => "Course Level",
7438: 'dml' => "Domain Level",
7439: 'ssl' => "System Level");
7440: my %cr = (
7441: course => '_c',
7442: domain => '_d',
7443: system => '_s',
7444: );
7445:
1.180 raeburn 7446: my $output=&Apache::loncommon::start_data_table($add_class,$id).
1.175 raeburn 7447: &Apache::loncommon::start_data_table_header_row().
7448: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
7449: '</th><th>'.$lt{'ssl'}.'</th>'.
7450: &Apache::loncommon::end_data_table_header_row();
7451: foreach my $priv (sort(keys(%{$full}))) {
7452: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7453: $output .= &Apache::loncommon::start_data_table_row().
7454: '<td><span id="'.$prefix.$priv.'">'.$privtext.'</span></td>';
7455: foreach my $type ('course','domain','system') {
7456: if (($type eq 'system') && ($priv eq 'bre') && ($crstype eq 'Community')) {
7457: $output .= '<td> </td>';
7458: } else {
7459: $output .= '<td>'.
7460: ($levels->{$type}{$priv}?'<input type="checkbox" id="'.$prefix.$priv.$cr{$type}.'"'.
7461: ' name="'.$prefix.$priv.$cr{$type}.'"'.
7462: ($levelscurrent->{$type}{$priv}?' checked="checked"':'').' />':' ').
7463: '</td>';
7464: }
7465: }
7466: $output .= &Apache::loncommon::end_data_table_row();
7467: }
7468: $output .= &Apache::loncommon::end_data_table();
7469: return $output;
7470: }
7471:
7472: sub custom_role_privs {
7473: my ($privs,$full,$levels,$levelscurrent)= @_;
7474: return unless ((ref($privs) eq 'HASH') && (ref($full) eq 'HASH') &&
7475: (ref($levels) eq 'HASH') && (ref($levelscurrent) eq 'HASH'));
7476: my %cr = (
7477: course => 'cr:c',
7478: domain => 'cr:d',
7479: system => 'cr:s',
7480: );
7481: foreach my $type ('course','domain','system') {
7482: foreach my $item (split(/\:/,$Apache::lonnet::pr{$cr{$type}})) {
7483: my ($priv,$restrict)=split(/\&/,$item);
7484: if (!$restrict) { $restrict='F'; }
7485: $levels->{$type}->{$priv}=$restrict;
7486: if ($privs->{$type}=~/\:$priv/) {
7487: $levelscurrent->{$type}->{$priv}=1;
7488: }
7489: $full->{$priv}=1;
7490: }
7491: }
7492: return;
7493: }
7494:
7495: sub custom_template_roles {
7496: my ($context,$crstype) = @_;
7497: my @template_roles = ("in","ta","ep");
7498: if (($context eq 'domain') || ($context eq 'domprefs')) {
7499: push(@template_roles,"ad");
7500: }
7501: push(@template_roles,"st");
7502: if ($context eq 'domain') {
7503: unshift(@template_roles,('co','cc'));
7504: } else {
7505: if ($crstype eq 'Community') {
7506: unshift(@template_roles,'co');
7507: } else {
7508: unshift(@template_roles,'cc');
7509: }
7510: }
7511: return @template_roles;
7512: }
7513:
7514: sub custom_roledefs_js {
7515: my ($context,$crstype,$formname,$full,$templaterolesref,$jsback) = @_;
7516: my $button_code = "\n";
7517: my $head_script = "\n";
7518: my (%roletitlestr,$rolenamestr);
7519: my %role_titles = (
7520: Course => [],
7521: Community => [],
7522: );
7523: $head_script .= '<script type="text/javascript">'."\n"
7524: .'// <![CDATA['."\n";
7525: if (ref($templaterolesref) eq 'ARRAY') {
7526: if ($context eq 'domain') {
7527: $rolenamestr = join("','",@{$templaterolesref});
7528: }
7529: foreach my $role (@{$templaterolesref}) {
7530: $head_script .= &make_script_template($role,$crstype,$formname);
7531: if ($context eq 'domain') {
7532: foreach my $type ('Course','Community') {
7533: push(@{$role_titles{$type}},&Apache::lonnet::plaintext($role,$type));
7534: }
7535: }
7536: }
7537: }
7538: if ($context eq 'domain') {
7539: foreach my $type ('Course','Community') {
7540: $roletitlestr{$type} = join("','",@{$role_titles{$type}});
7541: }
7542: my %pt = (
7543: Community => {
7544: cst => &mt('Grant/revoke role of Member'),
7545: mdc => &mt('Edit community contents'),
7546: pch => &mt('Post discussion on community resources'),
7547: pfo => &mt('Print for other users and entire community'),
7548: },
7549: Course => {
7550: cst => &mt('Grant/revoke role of Student'),
7551: mdc => &mt('Edit course contents'),
7552: pch => &mt('Post discussion on course resources'),
7553: pfo => &mt('Print for other users and entire course'),
7554: },
7555: );
7556: $head_script .= <<"ENDJS";
7557: function customSwitchType(prefix) {
7558: var privnames = new Array('cst','mdc','pch','pfo');
7559: var privtxtcrs = new Array('$pt{Course}{cst}','$pt{Course}{mdc}','$pt{Course}{pch}','$pt{Course}{pfo}');
7560: var privtxtcom = new Array('$pt{Community}{cst}','$pt{Community}{mdc}','$pt{Community}{pch}','$pt{Community}{pfo}');
7561: var rolenames = new Array('$rolenamestr');
7562: var rolescrs = new Array('$roletitlestr{Course}');
7563: var rolescom = new Array('$roletitlestr{Community}');
7564: var radio = prefix+'_custrolecrstype';
7565: if (document.$formname.elements[radio].length > 1) {
7566: for (var i=0; i<document.$formname.elements[radio].length; i++) {
7567: if (document.$formname.elements[radio][i].checked) {
7568: if ((document.getElementById(prefix+'bre_s')) && (document.getElementById(prefix+'bro_s'))) {
7569: if (document.$formname.elements[radio][i].value == 'Community') {
7570: if (document.getElementById(prefix+'bre_s').checked) {
7571: document.getElementById(prefix+'bro_s').checked = true;
7572: document.getElementById(prefix+'bre_s').checked = false;
7573:
7574: }
7575: document.getElementById(prefix+'bre_s').style.visibility = 'hidden';
7576: } else {
7577: document.getElementById(prefix+'bre_s').style.visibility = 'visible';
7578: if (document.getElementById(prefix+'bro_s').checked) {
7579: document.getElementById(prefix+'bre_s').checked = true;
7580: document.getElementById(prefix+'bro_s').checked = false;
7581: }
7582: }
7583: }
7584: for (var j=0; j<privnames.length; j++) {
7585: if (document.getElementById(prefix+privnames[j])) {
7586: if (document.getElementById(prefix+privnames[j])) {
7587: if (document.$formname.elements[radio][i].value == 'Course') {
7588: document.getElementById(prefix+privnames[j]).innerHTML = privtxtcrs[j];
7589: } else {
7590: document.getElementById(prefix+privnames[j]).innerHTML = privtxtcom[j];
7591: }
7592: }
7593: }
7594: }
7595: for (var j=0; j<rolenames.length; j++) {
7596: if (document.getElementById(prefix+rolenames[j])) {
7597: if (document.getElementById(prefix+rolenames[j])) {
7598: if (document.$formname.elements[radio][i].value == 'Course') {
7599: document.getElementById(prefix+rolenames[j]).value = rolescrs[j];
7600: if (rolenames[j] == 'cc') {
7601: document.getElementById(prefix+rolenames[j]).style.display = 'inline';
7602: }
7603: if (rolenames[j] == 'co') {
7604: document.getElementById(prefix+rolenames[j]).style.display = 'none';
7605: }
7606: } else {
7607: document.getElementById(prefix+rolenames[j]).value = rolescom[j];
7608: if (rolenames[j] == 'cc') {
7609: document.getElementById(prefix+rolenames[j]).style.display = 'none';
7610: }
7611: if (rolenames[j] == 'co') {
7612: document.getElementById(prefix+rolenames[j]).style.display = 'inline';
7613: }
7614: }
7615: }
7616: }
7617: }
7618: }
7619: }
7620: }
7621: return;
7622: }
7623: ENDJS
7624: }
7625: $head_script .= "\n".$jsback."\n"
7626: .'// ]]>'."\n"
7627: .'</script>'."\n";
7628: return $head_script;
7629: }
7630:
7631: # --------------------------------------------------------
7632: sub make_script_template {
7633: my ($role,$crstype,$formname) = @_;
7634: my $return_script = 'function set_'.$role.'(prefix) {'."\n";
7635: my (%full_by_level,%role_priv);
7636: foreach my $level ('c','d','s') {
7637: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
7638: next if (($level eq 's') && ($crstype eq 'Community') && ($item eq 'bre&S'));
7639: my ($priv,$restrict)=split(/\&/,$item);
7640: $full_by_level{$level}{$priv}=1;
7641: }
7642: $role_priv{$level} = {};
7643: my @temp = split(/:/,$Apache::lonnet::pr{$role.':'.$level});
7644: foreach my $priv (@temp) {
7645: my ($priv_item, $dummy) = split(/\&/,$priv);
7646: $role_priv{$level}{$priv_item} = 1;
7647: }
7648: }
7649: my %to_check = (
7650: c => ['c','d','s'],
7651: d => ['d','s'],
7652: s => ['s'],
7653: );
7654: foreach my $level ('c','d','s') {
7655: if (ref($full_by_level{$level}) eq 'HASH') {
7656: foreach my $priv (keys(%{$full_by_level{$level}})) {
7657: my $value = 'false';
7658: if (ref($to_check{$level}) eq 'ARRAY') {
7659: foreach my $lett (@{$to_check{$level}}) {
7660: if (exists($role_priv{$lett}{$priv})) {
7661: $value = 'true';
7662: last;
7663: }
7664: }
7665: $return_script .= "document.$formname.elements[prefix+'".$priv."_".$level."'].checked = $value;\n";
7666: }
7667: }
7668: }
7669: }
7670: $return_script .= '}'."\n";
7671: return ($return_script);
7672: }
7673: # ----------------------------------------------------------
7674: sub make_button_code {
7675: my ($role,$crstype,$display,$prefix) = @_;
7676: my $label = &Apache::lonnet::plaintext($role,$crstype);
7677: my $button_code = '<input type="button" onclick="set_'.$role."('$prefix'".')" '.
7678: 'id="'.$prefix.$role.'" value="'.$label.'" '.
7679: 'style="display:'.$display.'" />';
7680: return ($button_code);
7681: }
7682:
7683: sub custom_role_update {
7684: my ($rolename,$prefix) = @_;
7685: # ------------------------------------------------------- What can be assigned?
7686: my %privs = (
7687: c => '',
7688: d => '',
7689: s => '',
7690: );
7691: foreach my $level (keys(%privs)) {
7692: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
7693: my ($priv,$restrict)=split(/\&/,$item);
7694: if (!$restrict) { $restrict=''; }
7695: if ($env{'form.'.$prefix.$priv.'_'.$level}) {
7696: $privs{$level} .=':'.$item;
7697: }
7698: }
7699: }
7700: return %privs;
7701: }
7702:
1.180 raeburn 7703: sub adhoc_status_types {
7704: my ($cdom,$context,$role,$selectedref,$othertitle,$usertypes,$types,$disabled) = @_;
7705: my $output = &Apache::loncommon::start_data_table();
7706: my $numinrow = 3;
7707: my $rem;
7708: if (ref($types) eq 'ARRAY') {
7709: for (my $i=0; $i<@{$types}; $i++) {
7710: if (defined($usertypes->{$types->[$i]})) {
7711: my $rem = $i%($numinrow);
7712: if ($rem == 0) {
7713: if ($i > 0) {
7714: $output .= &Apache::loncommon::end_data_table_row();
7715: }
7716: $output .= &Apache::loncommon::start_data_table_row();
7717: }
7718: my $check;
7719: if (ref($selectedref) eq 'ARRAY') {
7720: if (grep(/^\Q$types->[$i]\E$/,@{$selectedref})) {
7721: $check = ' checked="checked"';
7722: }
7723: }
7724: $output .= '<td>'.
7725: '<span class="LC_nobreak"><label>'.
7726: '<input type="checkbox" name="'.$context.$role.'_status" '.
7727: 'value="'.$types->[$i].'"'.$check.$disabled.' />'.
7728: $usertypes->{$types->[$i]}.'</label></span></td>';
7729: }
7730: }
7731: $rem = @{$types}%($numinrow);
7732: }
7733: my $colsleft = $numinrow - $rem;
7734: if (($rem == 0) && (@{$types} > 0)) {
7735: $output .= &Apache::loncommon::start_data_table_row();
7736: }
7737: if ($colsleft > 1) {
7738: $output .= '<td colspan="'.$colsleft.'">';
7739: } else {
7740: $output .= '<td>';
7741: }
7742: my $defcheck;
7743: if (ref($selectedref) eq 'ARRAY') {
7744: if (grep(/^default$/,@{$selectedref})) {
7745: $defcheck = ' checked="checked"';
7746: }
7747: }
7748: $output .= '<span class="LC_nobreak"><label>'.
7749: '<input type="checkbox" name="'.$context.$role.'_status"'.
7750: 'value="default"'.$defcheck.$disabled.' />'.
7751: $othertitle.'</label></span></td>'.
7752: &Apache::loncommon::end_data_table_row().
7753: &Apache::loncommon::end_data_table();
7754: return $output;
7755: }
7756:
7757: sub adhoc_staff {
7758: my ($access,$context,$role,$selectedref,$adhocref,$disabled) = @_;
7759: my $output;
7760: if (ref($adhocref) eq 'HASH') {
7761: my %by_fullname;
7762: my $numinrow = 4;
7763: my $rem;
7764: my @personnel = keys(%{$adhocref});
7765: if (@personnel) {
7766: foreach my $person (@personnel) {
7767: my ($uname,$udom) = split(/:/,$person);
7768: my $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
7769: $by_fullname{$fullname} = $person;
7770: }
7771: my @sorted = sort(keys(%by_fullname));
7772: my $count = scalar(@sorted);
7773: $output = &Apache::loncommon::start_data_table();
7774: for (my $i=0; $i<$count; $i++) {
7775: my $rem = $i%($numinrow);
7776: if ($rem == 0) {
7777: if ($i > 0) {
7778: $output .= &Apache::loncommon::end_data_table_row();
7779: }
7780: $output .= &Apache::loncommon::start_data_table_row();
7781: }
7782: my $check;
7783: my $user = $by_fullname{$sorted[$i]};
7784: if (ref($selectedref) eq 'ARRAY') {
7785: if (grep(/^\Q$user\E$/,@{$selectedref})) {
7786: $check = ' checked="checked"';
7787: }
7788: }
7789: if ($i == $count-1) {
7790: my $colsleft = $numinrow - $rem;
7791: if ($colsleft > 1) {
7792: $output .= '<td colspan="'.$colsleft.'">';
7793: } else {
7794: $output .= '<td>';
7795: }
7796: } else {
7797: $output .= '<td>';
7798: }
7799: $output .= '<span class="LC_nobreak"><label>'.
7800: '<input type="checkbox" name="'.$context.$role.'_staff_'.$access.'" '.
7801: 'value="'.$user.'"'.$check.$disabled.' />'.$sorted[$i].
7802: '</label></span></td>';
7803: if ($i == $count-1) {
7804: $output .= &Apache::loncommon::end_data_table_row();
7805: }
7806: }
7807: $output .= &Apache::loncommon::end_data_table();
7808: }
7809: }
7810: return $output;
7811: }
7812:
7813:
1.1 raeburn 7814: 1;
7815:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>