Annotation of loncom/interface/lonuserutils.pm, revision 1.218
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
1.218 ! raeburn 4: # $Id: lonuserutils.pm,v 1.217 2023/10/02 21:01:21 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.159 raeburn 2635: push (@cols,('authorusage','authorquota','extent'));
1.149 raeburn 2636: }
1.140 raeburn 2637: }
2638: return @cols;
2639: }
2640:
2641: sub column_checkboxes {
1.150 raeburn 2642: my ($context,$mode,$formname,$showcredits) = @_;
2643: my @cols = &get_cols_array($context,$mode,$showcredits);
1.140 raeburn 2644: my @showncols = &Apache::loncommon::get_env_multiple('form.showcol');
2645: my (%disabledchk,%unchecked);
2646: if ($env{'form.phase'} eq '') {
2647: $disabledchk{'status'} = 1;
2648: if ($context eq 'course') {
2649: $disabledchk{'role'} = 1;
2650: $unchecked{'photo'} = 1;
1.149 raeburn 2651: $unchecked{'clicker'} = 1;
1.150 raeburn 2652: if ($showcredits) {
2653: $unchecked{'credits'} = 1;
2654: }
1.149 raeburn 2655: } elsif ($context eq 'domain') {
2656: $unchecked{'extent'} = 1;
1.140 raeburn 2657: }
2658: $unchecked{'start'} = 1;
2659: $unchecked{'end'} = 1;
2660: } else {
2661: if ($env{'form.Status'} ne 'Any') {
2662: $disabledchk{'status'} = 1;
2663: }
1.146 raeburn 2664: if (($env{'form.showrole'} ne 'Any') && ($env{'form.showrole'} ne 'cr')) {
2665: $disabledchk{'role'} = 1;
1.140 raeburn 2666: }
1.149 raeburn 2667: if ($context eq 'domain') {
2668: if (($env{'form.roletype'} eq 'course') ||
2669: ($env{'form.roletype'} eq 'community')) {
2670: $disabledchk{'status'} = 1;
1.159 raeburn 2671: $disabledchk{'authorusage'} = 1;
2672: $disabledchk{'authorquota'} = 1;
1.149 raeburn 2673: } elsif ($env{'form.roletype'} eq 'domain') {
2674: $disabledchk{'extent'} = 1;
2675: }
2676: }
1.140 raeburn 2677: }
2678: my $numposs = scalar(@cols);
1.149 raeburn 2679: my $numinrow = 7;
1.140 raeburn 2680: my %lt = &get_column_names($context);
2681: my $output = '<fieldset><legend>'.&mt('Information to show').'</legend>'."\n".'<span class="LC_nobreak">'.
2682: '<input type="button" onclick="javascript:checkAll(document.'.$formname.'.showcol);" value="'.&mt('check all').'" />'.
2683: (' 'x3).
2684: '<input type="button" onclick="javascript:uncheckAll(document.'.$formname.'.showcol);" value="'.&mt('uncheck all').'" />'.
2685: '</span><table>';
2686:
2687: for (my $i=0; $i<$numposs; $i++) {
2688: my $rem = $i%($numinrow);
2689: if ($rem == 0) {
2690: if ($i > 0) {
2691: $output .= '</tr>';
2692: }
2693: $output .= '<tr>';
2694: }
2695: my $checked;
2696: if ($env{'form.phase'} eq '') {
2697: $checked = ' checked="checked"';
2698: if ($unchecked{$cols[$i]}) {
2699: $checked = '';
2700: }
2701: if ($disabledchk{$cols[$i]}) {
2702: $checked = ' disabled="disabled"';
2703: }
2704: } elsif (grep(/^\Q$cols[$i]\E$/,@showncols)) {
2705: $checked = ' checked="checked"';
2706: } elsif ($disabledchk{$cols[$i]}) {
2707: $checked = ' disabled="disabled"';
2708: }
2709: if ($i == $numposs-1) {
2710: my $colsleft = $numinrow-$rem;
2711: if ($colsleft > 1) {
2712: $output .= '<td colspan="'.$colsleft.'">';
2713: } else {
2714: $output .= '<td>';
2715: }
2716: } else {
2717: $output .= '<td>';
2718: }
1.149 raeburn 2719: my $style;
2720: if ($cols[$i] eq 'extent') {
2721: if (($env{'form.roletype'} eq 'domain') || ($env{'form.roletype'} eq '')) {
2722: $style = ' style="display: none;"';
2723: }
1.159 raeburn 2724: } elsif (($cols[$i] eq 'authorusage') || ($cols[$i] eq 'authorquota')) {
2725: if ($env{'form.roletype'} ne 'domain') {
2726: $style = ' style="display: none;"';
2727: }
2728: }
1.149 raeburn 2729: $output .= '<span id="show'.$cols[$i].'"'.$style.'><label>'.
2730: '<input id="showcol'.$cols[$i].'" type="checkbox" name="showcol" value="'.$cols[$i].'"'.$checked.' /><span id="showcoltext'.$cols[$i].'">'.
2731: $lt{$cols[$i]}.'</span>'.
2732: '</label></span></td>';
1.140 raeburn 2733: }
2734: $output .= '</tr></table></fieldset>';
2735: return $output;
2736: }
2737:
1.2 raeburn 2738: sub list_submit_button {
2739: my ($text) = @_;
1.11 raeburn 2740: return '<input type="button" name="updatedisplay" value="'.$text.'" onclick="javascript:display_update()" />';
1.2 raeburn 2741: }
2742:
1.140 raeburn 2743: sub get_column_names {
2744: my ($context) = @_;
2745: my %lt = &Apache::lonlocal::texthash(
2746: 'username' => "username",
2747: 'domain' => "domain",
2748: 'id' => 'ID',
2749: 'fullname' => "name",
2750: 'section' => "section",
2751: 'groups' => "active groups",
2752: 'start' => "start date",
2753: 'end' => "end date",
2754: 'status' => "status",
2755: 'role' => "role",
1.150 raeburn 2756: 'credits' => "credits",
1.140 raeburn 2757: 'type' => "enroll type/action",
2758: 'email' => "e-mail address",
2759: 'photo' => "photo",
2760: 'lastlogin' => "last login",
2761: 'extent' => "extent",
1.159 raeburn 2762: 'authorusage' => "disk usage (%)",
2763: 'authorquota' => "disk quota (MB)",
1.140 raeburn 2764: 'ca' => "check all",
2765: 'ua' => "uncheck all",
2766: 'clicker' => "clicker-ID",
2767: );
2768: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
1.149 raeburn 2769: $lt{'extent'} = &mt('course(s): description, section(s), status');
1.140 raeburn 2770: } elsif ($context eq 'domain' && $env{'form.roletype'} eq 'community') {
1.154 raeburn 2771: $lt{'extent'} = &mt('community(s): description, section(s), status');
1.149 raeburn 2772: } elsif (($context eq 'author') ||
2773: ($context eq 'domain' && $env{'form.roletype'} eq 'author')) {
2774: $lt{'extent'} = &mt('author');
1.140 raeburn 2775: }
2776: return %lt;
2777: }
2778:
1.2 raeburn 2779: sub gather_userinfo {
1.11 raeburn 2780: my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_;
1.52 raeburn 2781: my $viewablesec;
2782: if ($context eq 'course') {
2783: $viewablesec = &viewable_section($permission);
2784: }
1.2 raeburn 2785: foreach my $item (keys(%{$rolehash})) {
2786: my %userdata;
1.22 raeburn 2787: if ($context eq 'author') {
1.2 raeburn 2788: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
2789: split(/:/,$item);
2790: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
1.24 raeburn 2791: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2792: $item,$userlist);
1.22 raeburn 2793: } elsif ($context eq 'course') {
2794: ($userdata{'username'},$userdata{'domain'},$userdata{'role'},
2795: $userdata{'section'}) = split(/:/,$item,-1);
2796: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
2797: if (($viewablesec ne '') && ($userdata{'section'} ne '')) {
2798: next if ($viewablesec ne $userdata{'section'});
2799: }
1.24 raeburn 2800: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2801: $item,$userlist);
1.2 raeburn 2802: } elsif ($context eq 'domain') {
2803: if ($env{'form.roletype'} eq 'domain') {
2804: ($userdata{'role'},$userdata{'username'},$userdata{'domain'}) =
2805: split(/:/,$item);
2806: ($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
1.24 raeburn 2807: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2808: $item,$userlist);
1.13 raeburn 2809: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 2810: if (ref($rolehash->{$item}) eq 'HASH') {
2811: $userdata{'extent'} = $item;
2812: foreach my $key (keys(%{$rolehash->{$item}})) {
2813: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) = split(/:/,$key);
2814: ($userdata{'start'},$userdata{'end'}) =
2815: split(/:/,$rolehash->{$item}{$key});
2816: my $uniqid = $key.':'.$item;
1.25 raeburn 2817: &build_user_record($context,\%userdata,$userinfo,
2818: $indexhash,$uniqid,$userlist);
1.2 raeburn 2819: }
2820: }
1.102 raeburn 2821: } elsif (($env{'form.roletype'} eq 'course') ||
2822: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 2823: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
2824: split(/:/,$item);
2825: if (ref($rolehash->{$item}) eq 'HASH') {
1.11 raeburn 2826: my $numcids = keys(%{$rolehash->{$item}});
1.2 raeburn 2827: foreach my $cid (sort(keys(%{$rolehash->{$item}}))) {
2828: if (ref($rolehash->{$item}{$cid}) eq 'HASH') {
2829: my $spanstart = '';
2830: my $spanend = '; ';
2831: my $space = ', ';
2832: if ($format eq 'html' || $format eq 'view') {
2833: $spanstart = '<span class="LC_nobreak">';
1.23 raeburn 2834: # FIXME: actions on courses disabled for now
2835: # if ($permission->{'cusr'}) {
2836: # if ($numcids > 1) {
1.25 raeburn 2837: # $spanstart .= '<input type="radio" name="'.$item.'" value="'.$cid.'" /> ';
1.23 raeburn 2838: # } else {
1.25 raeburn 2839: # $spanstart .= '<input type="hidden" name="'.$item.'" value="'.$cid.'" /> ';
1.23 raeburn 2840: # }
2841: # }
1.2 raeburn 2842: $spanend = '</span><br />';
2843: $space = ', ';
2844: }
2845: $userdata{'extent'} .= $spanstart.
2846: $rolehash->{$item}{$cid}{'desc'}.$space;
2847: if (ref($rolehash->{$item}{$cid}{'secs'}) eq 'HASH') {
2848: foreach my $sec (sort(keys(%{$rolehash->{$item}{$cid}{'secs'}}))) {
1.25 raeburn 2849: if (($env{'form.Status'} eq 'Any') ||
2850: ($env{'form.Status'} eq $rolehash->{$item}{$cid}{'secs'}{$sec})) {
2851: $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
2852: $userdata{'status'} = $rolehash->{$item}{$cid}{'secs'}{$sec};
2853: }
1.2 raeburn 2854: }
2855: }
2856: }
2857: }
2858: }
1.25 raeburn 2859: if ($userdata{'status'} ne '') {
2860: &build_user_record($context,\%userdata,$userinfo,
2861: $indexhash,$item,$userlist);
2862: }
1.2 raeburn 2863: }
2864: }
2865: }
2866: return;
2867: }
2868:
2869: sub build_user_record {
1.24 raeburn 2870: my ($context,$userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
1.11 raeburn 2871: next if ($userdata->{'start'} eq '-1' && $userdata->{'end'} eq '-1');
1.102 raeburn 2872: if (!(($context eq 'domain') && (($env{'form.roletype'} eq 'course')
2873: && ($env{'form.roletype'} eq 'community')))) {
1.24 raeburn 2874: &process_date_info($userdata);
2875: }
1.2 raeburn 2876: my $username = $userdata->{'username'};
2877: my $domain = $userdata->{'domain'};
2878: if (ref($userinfo->{$username.':'.$domain}) eq 'HASH') {
1.24 raeburn 2879: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
1.2 raeburn 2880: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
2881: } else {
2882: &aggregate_user_info($domain,$username,$userinfo);
2883: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
2884: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
2885: }
2886: foreach my $key (keys(%{$indexhash})) {
2887: if (defined($userdata->{$key})) {
2888: $userlist->{$record_key}[$indexhash->{$key}] = $userdata->{$key};
2889: }
2890: }
2891: return;
2892: }
2893:
2894: sub courses_selector {
2895: my ($cdom,$formname) = @_;
2896: my %codes = ();
2897: my @codetitles = ();
2898: my %cat_titles = ();
2899: my %cat_order = ();
2900: my %idlist = ();
2901: my %idnums = ();
2902: my %idlist_titles = ();
2903: my $caller = 'global';
2904: my $format_reply;
2905: my $jscript = '';
2906:
1.7 albertel 2907: my $totcodes = 0;
1.201 raeburn 2908: my $instcats = &Apache::lonnet::get_dom_instcats($cdom);
2909: if (ref($instcats) eq 'HASH') {
2910: if ((ref($instcats->{'codetitles'}) eq 'ARRAY') && (ref($instcats->{'codes'}) eq 'HASH') &&
2911: (ref($instcats->{'cat_titles'}) eq 'HASH') && (ref($instcats->{'cat_order'}) eq 'HASH')) {
2912: %codes = %{$instcats->{'codes'}};
2913: @codetitles = @{$instcats->{'codetitles'}};
2914: %cat_titles = %{$instcats->{'cat_titles'}};
2915: %cat_order = %{$instcats->{'cat_order'}};
2916: $totcodes = scalar(keys(%codes));
1.2 raeburn 2917: my $numtypes = @codetitles;
2918: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
2919: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
2920: my $longtitles_str = join('","',@{$longtitles});
2921: my $allidlist = $idlist{$codetitles[0]};
2922: $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
2923: $jscript .= $scripttext;
1.181 raeburn 2924: $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,\@codetitles);
1.2 raeburn 2925: }
2926: }
2927: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
2928:
2929: my %elements = (
2930: Year => 'selectbox',
2931: coursepick => 'radio',
2932: coursetotal => 'text',
2933: courselist => 'text',
2934: );
2935: $jscript .= &Apache::lonhtmlcommon::set_form_elements(\%elements);
2936: if ($env{'form.coursepick'} eq 'category') {
2937: $jscript .= qq|
2938: function setCourseCat(formname) {
2939: if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
2940: return;
2941: }
1.120 raeburn 2942: courseSet('$codetitles[0]');
1.2 raeburn 2943: for (var j=0; j<formname.Semester.length; j++) {
2944: if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
2945: formname.Semester.options[j].selected = true;
2946: }
2947: }
2948: if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
2949: return;
2950: }
1.120 raeburn 2951: courseSet('$codetitles[1]');
1.2 raeburn 2952: for (var j=0; j<formname.Department.length; j++) {
1.187 raeburn 2953: if (formname.Department.options[j].value == "$env{'form.Department'}") {
2954: formname.Department.options[j].selected = true;
1.2 raeburn 2955: }
2956: }
2957: if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
2958: return;
2959: }
1.120 raeburn 2960: courseSet('$codetitles[2]');
1.2 raeburn 2961: for (var j=0; j<formname.Number.length; j++) {
2962: if (formname.Number.options[j].value == "$env{'form.Number'}") {
2963: formname.Number.options[j].selected = true;
2964: }
2965: }
2966: }
2967: |;
2968: }
2969: return ($cb_jscript,$jscript,$totcodes,\@codetitles,\%idlist,
2970: \%idlist_titles);
2971: }
2972:
2973: sub course_selector_loadcode {
2974: my ($formname) = @_;
2975: my $loadcode;
2976: if ($env{'form.coursepick'} ne '') {
2977: $loadcode = 'javascript:setFormElements(document.'.$formname.')';
2978: if ($env{'form.coursepick'} eq 'category') {
2979: $loadcode .= ';javascript:setCourseCat(document.'.$formname.')';
2980: }
2981: }
2982: return $loadcode;
2983: }
2984:
2985: sub process_coursepick {
2986: my $coursefilter = $env{'form.coursepick'};
2987: my $cdom = $env{'request.role.domain'};
2988: my %courses;
1.105 raeburn 2989: my $crssrch = 'Course';
2990: if ($env{'form.roletype'} eq 'community') {
2991: $crssrch = 'Community';
2992: }
1.2 raeburn 2993: if ($coursefilter eq 'all') {
2994: %courses = &Apache::lonnet::courseiddump($cdom,'.','.','.','.','.',
1.105 raeburn 2995: undef,undef,$crssrch);
1.2 raeburn 2996: } elsif ($coursefilter eq 'category') {
2997: my $instcode = &instcode_from_coursefilter();
2998: %courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.',
1.105 raeburn 2999: undef,undef,$crssrch);
1.2 raeburn 3000: } elsif ($coursefilter eq 'specific') {
3001: if ($env{'form.coursetotal'} > 1) {
3002: my @course_ids = split(/&&/,$env{'form.courselist'});
3003: foreach my $cid (@course_ids) {
3004: $courses{$cid} = '';
1.1 raeburn 3005: }
1.2 raeburn 3006: } else {
3007: $courses{$env{'form.courselist'}} = '';
1.1 raeburn 3008: }
1.2 raeburn 3009: }
3010: return %courses;
3011: }
3012:
3013: sub instcode_from_coursefilter {
3014: my $instcode = '';
3015: my @cats = ('Semester','Year','Department','Number');
3016: foreach my $category (@cats) {
3017: if (defined($env{'form.'.$category})) {
3018: unless ($env{'form.'.$category} eq '-1') {
3019: $instcode .= $env{'form.'.$category};
3020: }
3021: }
3022: }
3023: if ($instcode eq '') {
3024: $instcode = '.';
3025: }
3026: return $instcode;
3027: }
3028:
3029: sub make_keylist_array {
3030: my ($index,$keylist);
3031: $index->{'domain'} = &Apache::loncoursedata::CL_SDOM();
3032: $index->{'username'} = &Apache::loncoursedata::CL_SNAME();
3033: $index->{'end'} = &Apache::loncoursedata::CL_END();
3034: $index->{'start'} = &Apache::loncoursedata::CL_START();
3035: $index->{'id'} = &Apache::loncoursedata::CL_ID();
3036: $index->{'section'} = &Apache::loncoursedata::CL_SECTION();
3037: $index->{'fullname'} = &Apache::loncoursedata::CL_FULLNAME();
3038: $index->{'status'} = &Apache::loncoursedata::CL_STATUS();
3039: $index->{'type'} = &Apache::loncoursedata::CL_TYPE();
3040: $index->{'lockedtype'} = &Apache::loncoursedata::CL_LOCKEDTYPE();
3041: $index->{'groups'} = &Apache::loncoursedata::CL_GROUP();
3042: $index->{'email'} = &Apache::loncoursedata::CL_PERMANENTEMAIL();
3043: $index->{'role'} = &Apache::loncoursedata::CL_ROLE();
3044: $index->{'extent'} = &Apache::loncoursedata::CL_EXTENT();
1.44 raeburn 3045: $index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
1.47 raeburn 3046: $index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();
1.150 raeburn 3047: $index->{'credits'} = &Apache::loncoursedata::CL_CREDITS();
1.174 raeburn 3048: $index->{'instsec'} = &Apache::loncoursedata::CL_INSTSEC();
1.159 raeburn 3049: $index->{'authorquota'} = &Apache::loncoursedata::CL_AUTHORQUOTA();
3050: $index->{'authorusage'} = &Apache::loncoursedata::CL_AUTHORUSAGE();
1.2 raeburn 3051: foreach my $key (keys(%{$index})) {
3052: $keylist->[$index->{$key}] = $key;
3053: }
3054: return ($index,$keylist);
3055: }
3056:
3057: sub aggregate_user_info {
3058: my ($udom,$uname,$userinfo) = @_;
3059: my %info=&Apache::lonnet::get('environment',
3060: ['firstname','middlename',
3061: 'lastname','generation','id'],
3062: $udom,$uname);
3063: my ($tmp) = keys(%info);
3064: my ($fullname,$id);
3065: if ($tmp =~/^(con_lost|error|no_such_host)/i) {
3066: $fullname = 'not available';
3067: $id = 'not available';
3068: &Apache::lonnet::logthis('unable to retrieve environment '.
3069: 'for '.$uname.':'.$udom);
1.1 raeburn 3070: } else {
1.2 raeburn 3071: $fullname = &Apache::lonnet::format_name(@info{qw/firstname middlename lastname generation/},'lastname');
3072: $id = $info{'id'};
3073: }
3074: $userinfo->{$uname.':'.$udom} = {
3075: fullname => $fullname,
3076: id => $id,
3077: };
3078: return;
3079: }
1.1 raeburn 3080:
1.2 raeburn 3081: sub process_date_info {
3082: my ($userdata) = @_;
3083: my $now = time;
1.83 raeburn 3084: $userdata->{'status'} = 'Active';
1.2 raeburn 3085: if ($userdata->{'start'} > 0) {
3086: if ($now < $userdata->{'start'}) {
1.83 raeburn 3087: $userdata->{'status'} = 'Future';
1.2 raeburn 3088: }
1.1 raeburn 3089: }
1.2 raeburn 3090: if ($userdata->{'end'} > 0) {
3091: if ($now > $userdata->{'end'}) {
1.83 raeburn 3092: $userdata->{'status'} = 'Expired';
1.2 raeburn 3093: }
3094: }
3095: return;
1.1 raeburn 3096: }
3097:
3098: sub show_users_list {
1.150 raeburn 3099: my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname,
1.159 raeburn 3100: $showcredits,$needauthorquota,$needauthorusage)=@_;
1.55 raeburn 3101: if ($formname eq '') {
3102: $formname = 'studentform';
3103: }
1.159 raeburn 3104: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1 raeburn 3105: #
3106: # Variables for excel output
3107: my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
3108: #
3109: # Variables for csv output
3110: my ($CSVfile,$CSVfilename);
3111: #
3112: my $sortby = $env{'form.sortby'};
1.3 raeburn 3113: my @sortable = ('username','domain','id','fullname','start','end','email','role');
1.2 raeburn 3114: if ($context eq 'course') {
1.3 raeburn 3115: push(@sortable,('section','groups','type'));
1.150 raeburn 3116: if ($showcredits) {
3117: push(@sortable,'credits');
3118: }
1.2 raeburn 3119: } else {
1.3 raeburn 3120: push(@sortable,'extent');
1.159 raeburn 3121: if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
3122: (($env{'form.showrole'} eq 'Any') || ($env{'form.showrole'} eq 'au'))) {
3123: push(@sortable,('authorusage','authorquota'));
3124: }
1.3 raeburn 3125: }
1.55 raeburn 3126: if ($mode eq 'pickauthor') {
3127: @sortable = ('username','fullname','email','status');
3128: }
1.156 raeburn 3129: my %is_sortable;
1.158 raeburn 3130: map { $is_sortable{$_} = 1; } @sortable;
1.156 raeburn 3131: unless ($is_sortable{$sortby}) {
1.3 raeburn 3132: $sortby = 'username';
1.1 raeburn 3133: }
1.22 raeburn 3134: my $setting = $env{'form.roletype'};
1.150 raeburn 3135: my ($cid,$cdom,$cnum,$classgroups,$crstype,$defaultcredits);
1.1 raeburn 3136: if ($context eq 'course') {
1.22 raeburn 3137: $cid = $env{'request.course.id'};
1.101 raeburn 3138: $crstype = &Apache::loncommon::course_type();
1.17 raeburn 3139: ($cnum,$cdom) = &get_course_identity($cid);
1.150 raeburn 3140: $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
1.2 raeburn 3141: ($classgroups) = &Apache::loncoursedata::get_group_memberships(
3142: $userlist,$keylist,$cdom,$cnum);
1.16 raeburn 3143: if ($mode eq 'autoenroll') {
3144: $env{'form.showrole'} = 'st';
3145: } else {
3146: if ($env{'course.'.$cid.'.internal.showphoto'}) {
3147: $r->print('
1.1 raeburn 3148: <script type="text/javascript">
1.96 bisitz 3149: // <![CDATA[
1.1 raeburn 3150: function photowindow(photolink) {
3151: var title = "Photo_Viewer";
3152: var options = "scrollbars=1,resizable=1,menubar=0";
3153: options += ",width=240,height=240";
3154: stdeditbrowser = open(photolink,title,options,"1");
3155: stdeditbrowser.focus();
3156: }
1.96 bisitz 3157: // ]]>
1.1 raeburn 3158: </script>
1.16 raeburn 3159: ');
3160: }
3161: }
1.102 raeburn 3162: } elsif ($context eq 'domain') {
3163: if ($setting eq 'community') {
3164: $crstype = 'Community';
1.105 raeburn 3165: } elsif ($setting eq 'course') {
1.102 raeburn 3166: $crstype = 'Course';
3167: }
1.1 raeburn 3168: }
1.55 raeburn 3169: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
1.40 raeburn 3170: my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
1.56 raeburn 3171: my $verify_action_js = &bulkaction_javascript($formname);
1.1 raeburn 3172: $r->print(<<END);
1.10 raeburn 3173:
3174: <script type="text/javascript" language="Javascript">
1.96 bisitz 3175: // <![CDATA[
1.11 raeburn 3176:
1.56 raeburn 3177: $verify_action_js
1.10 raeburn 3178:
3179: function username_display_launch(username,domain) {
3180: var target;
1.177 raeburn 3181: if (!document.$formname.usernamelink.length) {
3182: target = document.$formname.usernamelink.value;
3183: } else {
3184: for (var i=0; i<document.$formname.usernamelink.length; i++) {
3185: if (document.$formname.usernamelink[i].checked) {
3186: target = document.$formname.usernamelink[i].value;
3187: }
1.10 raeburn 3188: }
3189: }
1.179 raeburn 3190: if ((target == 'modify') || (target == 'activity')) {
3191: var nextaction = 'singleuser';
3192: if (target == 'activity') {
3193: nextaction = 'accesslogs';
3194: }
1.55 raeburn 3195: if (document.$formname.userwin.checked == true) {
1.179 raeburn 3196: 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 3197: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3198: modifywin = window.open(url,'',options,1);
3199: modifywin.focus();
3200: return;
3201: } else {
1.55 raeburn 3202: document.$formname.srchterm.value=username;
3203: document.$formname.srchdomain.value=domain;
3204: document.$formname.phase.value='get_user_info';
1.179 raeburn 3205: document.$formname.action.value = nextaction;
1.55 raeburn 3206: document.$formname.submit();
1.50 raeburn 3207: }
1.10 raeburn 3208: }
1.48 raeburn 3209: if (target == 'aboutme') {
1.55 raeburn 3210: if (document.$formname.userwin.checked == true) {
1.50 raeburn 3211: var url = '/adm/'+domain+'/'+username+'/aboutme?popup=1';
3212: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3213: aboutmewin = window.open(url,'',options,1);
3214: aboutmewin.focus();
3215: return;
3216: } else {
3217: document.location.href = '/adm/'+domain+'/'+username+'/aboutme';
3218: }
1.48 raeburn 3219: }
1.98 raeburn 3220: if (target == 'track') {
3221: if (document.$formname.userwin.checked == true) {
3222: var url = '/adm/trackstudent?selected_student='+username+':'+domain+'&only_body=1';
3223: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3224: var trackwin = window.open(url,'',options,1);
3225: trackwin.focus();
3226: return;
3227: } else {
3228: document.location.href = '/adm/trackstudent?selected_student='+username+':'+domain;
3229: }
3230: }
1.10 raeburn 3231: }
1.96 bisitz 3232: // ]]>
1.10 raeburn 3233: </script>
1.11 raeburn 3234: $date_sec_selector
1.1 raeburn 3235: <input type="hidden" name="state" value="$env{'form.state'}" />
3236: END
3237: }
3238: $r->print(<<END);
3239: <input type="hidden" name="sortby" value="$sortby" />
3240: END
1.150 raeburn 3241: my @cols = &infocolumns($context,$mode,$showcredits);
1.140 raeburn 3242: my %coltxt = &get_column_names($context);
3243: my %acttxt = &Apache::lonlocal::texthash(
1.11 raeburn 3244: 'pr' => "Proceed",
3245: 'ac' => "Action to take for selected users",
1.56 raeburn 3246: 'link' => "Behavior of clickable username link for each user",
1.82 weissno 3247: 'aboutme' => "Display a user's personal information page",
1.50 raeburn 3248: 'owin' => "Open in a new window",
1.10 raeburn 3249: 'modify' => "Modify a user's information",
1.98 raeburn 3250: 'track' => "View a user's recent activity",
1.179 raeburn 3251: 'activity' => "View a user's access log",
1.1 raeburn 3252: );
1.140 raeburn 3253: my %lt = (%coltxt,%acttxt);
1.4 raeburn 3254: my $rolefilter = $env{'form.showrole'};
1.5 raeburn 3255: if ($env{'form.showrole'} eq 'cr') {
3256: $rolefilter = &mt('custom');
3257: } elsif ($env{'form.showrole'} ne 'Any') {
1.101 raeburn 3258: $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'},$crstype);
1.2 raeburn 3259: }
1.16 raeburn 3260: my $results_description;
3261: if ($mode ne 'autoenroll') {
3262: $results_description = &results_header_row($rolefilter,$statusmode,
1.102 raeburn 3263: $context,$permission,$mode,$crstype);
1.140 raeburn 3264: $r->print('<b>'.$results_description.'</b><br clear="all" />');
1.16 raeburn 3265: }
1.26 raeburn 3266: my ($output,$actionselect,%canchange,%canchangesec);
1.55 raeburn 3267: if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
3268: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
1.16 raeburn 3269: if ($permission->{'cusr'}) {
1.105 raeburn 3270: unless (($context eq 'domain') &&
3271: (($setting eq 'course') || ($setting eq 'community'))) {
3272: $actionselect =
3273: &select_actions($context,$setting,$statusmode,$formname);
3274: }
1.16 raeburn 3275: }
3276: $r->print(<<END);
1.10 raeburn 3277: <input type="hidden" name="srchby" value="uname" />
3278: <input type="hidden" name="srchin" value="dom" />
3279: <input type="hidden" name="srchtype" value="exact" />
3280: <input type="hidden" name="srchterm" value="" />
1.11 raeburn 3281: <input type="hidden" name="srchdomain" value="" />
1.1 raeburn 3282: END
1.16 raeburn 3283: if ($actionselect) {
1.41 raeburn 3284: $output .= <<"END";
1.94 bisitz 3285: <div class="LC_left_float"><fieldset><legend>$lt{'ac'}</legend>
1.56 raeburn 3286: $actionselect
3287: <br/><br /><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.$formname.actionlist)" />
3288: <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 3289: END
1.26 raeburn 3290: my @allroles;
3291: if ($env{'form.showrole'} eq 'Any') {
3292: my $custom = 1;
3293: if ($context eq 'domain') {
1.101 raeburn 3294: @allroles = &roles_by_context($setting,$custom,$crstype);
1.26 raeburn 3295: } else {
1.101 raeburn 3296: @allroles = &roles_by_context($context,$custom,$crstype);
1.26 raeburn 3297: }
3298: } else {
3299: @allroles = ($env{'form.showrole'});
3300: }
3301: foreach my $role (@allroles) {
3302: if ($context eq 'domain') {
3303: if ($setting eq 'domain') {
3304: if (&Apache::lonnet::allowed('c'.$role,
3305: $env{'request.role.domain'})) {
3306: $canchange{$role} = 1;
3307: }
1.31 raeburn 3308: } elsif ($setting eq 'author') {
3309: if (&Apache::lonnet::allowed('c'.$role,
3310: $env{'request.role.domain'})) {
3311: $canchange{$role} = 1;
3312: }
1.26 raeburn 3313: }
3314: } elsif ($context eq 'author') {
3315: if (&Apache::lonnet::allowed('c'.$role,
3316: $env{'user.domain'}.'/'.$env{'user.name'})) {
3317: $canchange{$role} = 1;
3318: }
3319: } elsif ($context eq 'course') {
3320: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
3321: $canchange{$role} = 1;
3322: } elsif ($env{'request.course.sec'} ne '') {
3323: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
3324: $canchangesec{$role} = $env{'request.course.sec'};
3325: }
1.141 raeburn 3326: } elsif ((($role eq 'co') && ($crstype eq 'Community')) ||
3327: (($role eq 'cc') && ($crstype eq 'Course'))) {
3328: if (&is_courseowner($env{'request.course.id'},
3329: $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
3330: $canchange{$role} = 1;
3331: }
1.26 raeburn 3332: }
3333: }
3334: }
1.16 raeburn 3335: }
1.94 bisitz 3336: $output .= '<div class="LC_left_float"><fieldset><legend>'.$lt{'link'}.'</legend>'.
1.56 raeburn 3337: '<table><tr>';
3338: my @linkdests = ('aboutme');
3339: if ($permission->{'cusr'}) {
3340: unshift (@linkdests,'modify');
3341: }
1.179 raeburn 3342: if ($context eq 'course') {
3343: if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) ||
3344: &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.
3345: $env{'request.course.sec'})) {
3346: push(@linkdests,'track');
3347: }
3348: } elsif ($context eq 'domain') {
3349: if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
3350: push(@linkdests,'activity');
3351: }
1.98 raeburn 3352: }
1.56 raeburn 3353: $output .= '<td>';
3354: my $usernamelink = $env{'form.usernamelink'};
3355: if ($usernamelink eq '') {
3356: $usernamelink = 'aboutme';
3357: }
3358: foreach my $item (@linkdests) {
3359: my $checkedstr = '';
3360: if ($item eq $usernamelink) {
1.86 bisitz 3361: $checkedstr = ' checked="checked"';
1.56 raeburn 3362: }
1.86 bisitz 3363: $output .= '<span class="LC_nobreak"><label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.' /> '.$lt{$item}.'</label></span><br />';
1.56 raeburn 3364: }
3365: my $checkwin;
3366: if ($env{'form.userwin'}) {
1.86 bisitz 3367: $checkwin = ' checked="checked"';
1.56 raeburn 3368: }
1.144 bisitz 3369: $output .=
3370: '</td><td valign="top" style="border-left: 1px solid;">'
3371: .'<span class="LC_nobreak"><label>'
3372: .'<input type="checkbox" name="userwin" value="1"'.$checkwin.' />'.$lt{'owin'}
3373: .'</label></span></td></tr></table></fieldset></div>';
1.4 raeburn 3374: }
1.184 raeburn 3375: $output .= "\n".'<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
1.1 raeburn 3376: &Apache::loncommon::start_data_table().
1.4 raeburn 3377: &Apache::loncommon::start_data_table_header_row();
1.1 raeburn 3378: if ($mode eq 'autoenroll') {
1.4 raeburn 3379: $output .= "
1.55 raeburn 3380: <th><a href=\"javascript:document.$formname.sortby.value='type';document.$formname.submit();\">$lt{'type'}</a></th>
1.4 raeburn 3381: ";
1.1 raeburn 3382: } else {
1.105 raeburn 3383: $output .= "\n".'<th> </th>'."\n";
1.11 raeburn 3384: if ($actionselect) {
1.159 raeburn 3385: $output .= '<th class="LC_nobreak" valign="top">'.&mt('Select').'</th>'."\n";
1.11 raeburn 3386: }
1.1 raeburn 3387: }
3388: foreach my $item (@cols) {
1.159 raeburn 3389: $output .= '<th class="LC_nobreak" valign="top">';
1.156 raeburn 3390: if ($is_sortable{$item}) {
1.159 raeburn 3391: $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 3392: } else {
3393: $output .= $lt{$item};
3394: }
3395: $output .= "</th>\n";
1.1 raeburn 3396: }
1.2 raeburn 3397: my %role_types = &role_type_names();
1.16 raeburn 3398: $output .= &Apache::loncommon::end_data_table_header_row();
1.1 raeburn 3399: # Done with the HTML header line
3400: } elsif ($mode eq 'csv') {
3401: #
3402: # Open a file
3403: $CSVfilename = '/prtspool/'.
1.2 raeburn 3404: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
3405: time.'_'.rand(1000000000).'.csv';
1.1 raeburn 3406: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
3407: $r->log_error("Couldn't open $CSVfilename for output $!");
1.108 bisitz 3408: $r->print(
3409: '<p class="LC_error">'
3410: .&mt('Problems occurred in writing the CSV file.')
3411: .' '.&mt('This error has been logged.')
3412: .' '.&mt('Please alert your LON-CAPA administrator.')
3413: .'</p>'
3414: );
1.1 raeburn 3415: $CSVfile = undef;
3416: }
3417: #
3418: # Write headers and data to file
1.2 raeburn 3419: print $CSVfile '"'.$results_description.'"'."\n";
1.1 raeburn 3420: print $CSVfile '"'.join('","',map {
3421: &Apache::loncommon::csv_translate($lt{$_})
1.67 droeschl 3422: } (@cols))."\"\n";
1.1 raeburn 3423: } elsif ($mode eq 'excel') {
3424: # Create the excel spreadsheet
3425: ($excel_workbook,$excel_filename,$format) =
3426: &Apache::loncommon::create_workbook($r);
3427: return if (! defined($excel_workbook));
3428: $excel_sheet = $excel_workbook->addworksheet('userlist');
1.2 raeburn 3429: $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
1.1 raeburn 3430: #
3431: my @colnames = map {$lt{$_}} (@cols);
1.67 droeschl 3432:
1.1 raeburn 3433: $excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
3434: }
3435:
3436: # Done with header lines in all formats
3437: my %index;
3438: my $i;
1.2 raeburn 3439: foreach my $idx (@$keylist) {
3440: $index{$idx} = $i++;
3441: }
1.4 raeburn 3442: my $usercount = 0;
1.33 raeburn 3443: my ($secfilter,$grpfilter);
3444: if ($context eq 'course') {
3445: $secfilter = $env{'form.secfilter'};
3446: $grpfilter = $env{'form.grpfilter'};
3447: if ($secfilter eq '') {
3448: $secfilter = 'all';
3449: }
3450: if ($grpfilter eq '') {
3451: $grpfilter = 'all';
3452: }
3453: }
1.83 raeburn 3454: my %ltstatus = &Apache::lonlocal::texthash(
3455: Active => 'Active',
3456: Future => 'Future',
3457: Expired => 'Expired',
3458: );
1.139 raeburn 3459: # If this is for a single course get last course "log-in".
3460: my %crslogins;
3461: if ($context eq 'course') {
3462: %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$cnum);
3463: }
1.2 raeburn 3464: # Get groups, role, permanent e-mail so we can sort on them if
3465: # necessary.
3466: foreach my $user (keys(%{$userlist})) {
1.43 raeburn 3467: if ($user eq '' ) {
3468: delete($userlist->{$user});
3469: next;
3470: }
1.11 raeburn 3471: if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) {
3472: delete($userlist->{$user});
3473: next;
3474: }
1.2 raeburn 3475: my ($uname,$udom,$role,$groups,$email);
1.5 raeburn 3476: if (($statusmode ne 'Any') &&
3477: ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
3478: delete($userlist->{$user});
3479: next;
3480: }
1.2 raeburn 3481: if ($context eq 'domain') {
3482: if ($env{'form.roletype'} eq 'domain') {
3483: ($role,$uname,$udom) = split(/:/,$user);
1.11 raeburn 3484: if (($uname eq $env{'request.role.domain'}.'-domainconfig') &&
3485: ($udom eq $env{'request.role.domain'})) {
3486: delete($userlist->{$user});
3487: next;
3488: }
1.13 raeburn 3489: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 3490: ($uname,$udom,$role) = split(/:/,$user,-1);
1.102 raeburn 3491: } elsif (($env{'form.roletype'} eq 'course') ||
3492: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 3493: ($uname,$udom,$role) = split(/:/,$user);
3494: }
3495: } else {
3496: ($uname,$udom,$role) = split(/:/,$user,-1);
3497: if (($context eq 'course') && $role eq '') {
3498: $role = 'st';
3499: }
3500: }
3501: $userlist->{$user}->[$index{'role'}] = $role;
3502: if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
3503: delete($userlist->{$user});
3504: next;
3505: }
1.33 raeburn 3506: if ($context eq 'course') {
3507: my @ac_groups;
3508: if (ref($classgroups) eq 'HASH') {
3509: $groups = $classgroups->{$user};
3510: }
3511: if (ref($groups->{'active'}) eq 'HASH') {
3512: @ac_groups = keys(%{$groups->{'active'}});
3513: $userlist->{$user}->[$index{'groups'}] = join(', ',@ac_groups);
3514: }
3515: if ($mode ne 'autoenroll') {
3516: my $section = $userlist->{$user}->[$index{'section'}];
1.43 raeburn 3517: if (($env{'request.course.sec'} ne '') &&
3518: ($section ne $env{'request.course.sec'})) {
3519: if ($role eq 'st') {
3520: delete($userlist->{$user});
3521: next;
3522: }
3523: }
1.33 raeburn 3524: if ($secfilter eq 'none') {
3525: if ($section ne '') {
3526: delete($userlist->{$user});
3527: next;
3528: }
3529: } elsif ($secfilter ne 'all') {
3530: if ($section ne $secfilter) {
3531: delete($userlist->{$user});
3532: next;
3533: }
3534: }
3535: if ($grpfilter eq 'none') {
3536: if (@ac_groups > 0) {
3537: delete($userlist->{$user});
3538: next;
3539: }
3540: } elsif ($grpfilter ne 'all') {
3541: if (!grep(/^\Q$grpfilter\E$/,@ac_groups)) {
3542: delete($userlist->{$user});
3543: next;
3544: }
3545: }
1.44 raeburn 3546: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
1.140 raeburn 3547: if ((grep/^photo$/,@cols) && ($role eq 'st')) {
1.44 raeburn 3548: $userlist->{$user}->[$index{'photo'}] =
1.47 raeburn 3549: &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg');
3550: $userlist->{$user}->[$index{'thumbnail'}] =
1.44 raeburn 3551: &Apache::lonnet::retrievestudentphoto($udom,$uname,
3552: 'gif','thumbnail');
3553: }
3554: }
1.150 raeburn 3555: if (($role eq 'st') && ($defaultcredits)) {
3556: if ($userlist->{$user}->[$index{'credits'}] eq '') {
3557: $userlist->{$user}->[$index{'credits'}] = $defaultcredits;
3558: }
3559: }
1.33 raeburn 3560: }
1.2 raeburn 3561: }
3562: my %emails = &Apache::loncommon::getemails($uname,$udom);
3563: if ($emails{'permanentemail'} =~ /\S/) {
3564: $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
3565: }
1.159 raeburn 3566: if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
3567: ($role eq 'au')) {
3568: my ($disk_quota,$current_disk_usage,$percent);
3569: if (($needauthorusage) || ($needauthorquota)) {
3570: $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author');
3571: }
3572: if ($needauthorusage) {
3573: $current_disk_usage =
3574: &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname");
3575: if ($disk_quota == 0) {
3576: $percent = 100.0;
3577: } else {
3578: $percent = $current_disk_usage/(10 * $disk_quota);
3579: }
3580: $userlist->{$user}->[$index{'authorusage'}] = sprintf("%.0f",$percent);
3581: }
3582: if ($needauthorquota) {
3583: $userlist->{$user}->[$index{'authorquota'}] = sprintf("%.2f",$disk_quota);
3584: }
3585: }
1.4 raeburn 3586: $usercount ++;
3587: }
3588: my $autocount = 0;
3589: my $manualcount = 0;
3590: my $lockcount = 0;
3591: my $unlockcount = 0;
3592: if ($usercount) {
3593: $r->print($output);
3594: } else {
3595: if ($mode eq 'autoenroll') {
3596: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
3597: } else {
3598: return;
3599: }
1.1 raeburn 3600: }
1.2 raeburn 3601: #
3602: # Sort the users
1.1 raeburn 3603: my $index = $index{$sortby};
3604: my $second = $index{'username'};
3605: my $third = $index{'domain'};
1.159 raeburn 3606: my @sorted_users;
3607: if (($sortby eq 'authorquota') || ($sortby eq 'authorusage')) {
3608: @sorted_users = sort {
3609: $userlist->{$b}->[$index] <=> $userlist->{$a}->[$index] ||
3610: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
3611: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
3612: } (keys(%$userlist));
3613: } else {
3614: @sorted_users = sort {
3615: lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index]) ||
3616: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
3617: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
3618: } (keys(%$userlist));
3619: }
1.4 raeburn 3620: my $rowcount = 0;
1.178 raeburn 3621: my $disabled;
3622: if ($mode eq 'autoenroll') {
3623: unless ($permission->{'cusr'}) {
3624: $disabled = ' disabled="disabled"';
3625: }
3626: }
1.2 raeburn 3627: foreach my $user (@sorted_users) {
1.4 raeburn 3628: my %in;
1.2 raeburn 3629: my $sdata = $userlist->{$user};
1.4 raeburn 3630: $rowcount ++;
1.2 raeburn 3631: foreach my $item (@{$keylist}) {
3632: $in{$item} = $sdata->[$index{$item}];
3633: }
1.67 droeschl 3634: my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
3635: if ($clickers!~/\w/) { $clickers='-'; }
1.159 raeburn 3636: $in{'clicker'} = $clickers;
1.67 droeschl 3637: my $role = $in{'role'};
1.102 raeburn 3638: $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
1.136 raeburn 3639: unless ($mode eq 'excel') {
3640: if (! defined($in{'start'}) || $in{'start'} == 0) {
3641: $in{'start'} = &mt('none');
3642: } else {
3643: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
3644: }
3645: if (! defined($in{'end'}) || $in{'end'} == 0) {
3646: $in{'end'} = &mt('none');
3647: } else {
3648: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
3649: }
1.1 raeburn 3650: }
1.139 raeburn 3651: if ($context eq 'course') {
3652: my $lastlogin = $crslogins{$in{'username'}.':'.$in{'domain'}.':'.$in{'section'}.':'.$role};
3653: if ($lastlogin ne '') {
3654: $in{'lastlogin'} = &Apache::lonlocal::locallocaltime($lastlogin);
3655: }
3656: }
1.55 raeburn 3657: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2 raeburn 3658: $r->print(&Apache::loncommon::start_data_table_row());
1.11 raeburn 3659: my $checkval;
1.16 raeburn 3660: if ($mode eq 'autoenroll') {
3661: my $cellentry;
3662: if ($in{'type'} eq 'auto') {
1.178 raeburn 3663: $cellentry = '<b>'.&mt('auto').'</b> <label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Change').'</label>';
1.16 raeburn 3664: $autocount ++;
3665: } else {
1.178 raeburn 3666: $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 3667: $manualcount ++;
3668: if ($in{'lockedtype'}) {
1.178 raeburn 3669: $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Unlock').'</label>';
1.16 raeburn 3670: $unlockcount ++;
3671: } else {
1.178 raeburn 3672: $cellentry .= '<label><input type="checkbox" name="lockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Lock').'</label>';
1.16 raeburn 3673: $lockcount ++;
1.11 raeburn 3674: }
1.76 bisitz 3675: $cellentry .= '</span></td></tr></table>';
1.16 raeburn 3676: }
3677: $r->print("<td>$cellentry</td>\n");
3678: } else {
1.55 raeburn 3679: if ($mode ne 'pickauthor') {
3680: $r->print("<td>$rowcount</td>\n");
3681: }
1.16 raeburn 3682: if ($actionselect) {
1.26 raeburn 3683: my $showcheckbox;
3684: if ($role =~ /^cr\//) {
3685: $showcheckbox = $canchange{'cr'};
3686: } else {
3687: $showcheckbox = $canchange{$role};
3688: }
3689: if (!$showcheckbox) {
3690: if ($context eq 'course') {
3691: if ($canchangesec{$role} ne '') {
3692: if ($canchangesec{$role} eq $in{'section'}) {
3693: $showcheckbox = 1;
3694: }
3695: }
1.16 raeburn 3696: }
1.26 raeburn 3697: }
3698: if ($showcheckbox) {
3699: $checkval = $user;
3700: if ($context eq 'course') {
1.141 raeburn 3701: if (($role eq 'co' || $role eq 'cc') &&
3702: ($user =~ /^\Q$env{'user.name'}:$env{'user.domain'}:$role\E/)) {
3703: $showcheckbox = 0;
3704: } else {
3705: if ($role eq 'st') {
3706: $checkval .= ':st';
3707: }
3708: $checkval .= ':'.$in{'section'};
3709: if ($role eq 'st') {
3710: $checkval .= ':'.$in{'type'}.':'.
1.150 raeburn 3711: $in{'lockedtype'}.':'.
1.174 raeburn 3712: $in{'credits'}.':'.
3713: &escape($in{'instsec'});
1.141 raeburn 3714: }
3715: }
3716: }
3717: if ($showcheckbox) {
3718: $r->print('<td><input type="checkbox" name="'.
1.183 raeburn 3719: 'actionlist" value="'.
3720: &HTML::Entities::encode($checkval,'&<>"').'" />');
3721: foreach my $item ('start','end') {
3722: $r->print('<input type="hidden" name="'.
3723: &HTML::Entities::encode($checkval.'_'.$item,'&<>"').'"'.
3724: ' value="'.$sdata->[$index{$item}].'" />');
3725: }
3726: $r->print('</td>');
1.141 raeburn 3727: } else {
3728: $r->print('<td> </td>');
1.16 raeburn 3729: }
1.26 raeburn 3730: } else {
3731: $r->print('<td> </td>');
1.16 raeburn 3732: }
1.55 raeburn 3733: } elsif ($mode eq 'pickauthor') {
3734: $r->print('<td><input type="button" name="chooseauthor" onclick="javascript:gochoose('."'$in{'username'}'".');" value="'.&mt('Select').'" /></td>');
1.11 raeburn 3735: }
3736: }
1.2 raeburn 3737: foreach my $item (@cols) {
1.10 raeburn 3738: if ($item eq 'username') {
1.48 raeburn 3739: $r->print('<td>'.&print_username_link($mode,\%in).'</td>');
1.83 raeburn 3740: } elsif ($item eq 'status') {
3741: my $showitem = $in{$item};
3742: if (defined($ltstatus{$in{$item}})) {
3743: $showitem = $ltstatus{$in{$item}};
3744: }
3745: $r->print('<td>'.$showitem.'</td>'."\n");
1.140 raeburn 3746: } elsif ($item eq 'photo') {
3747: if (($context eq 'course') && ($mode ne 'autoenroll') &&
3748: ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
3749: if ($role eq 'st') {
3750: $r->print('<td align="right"><a href="javascript:photowindow('."'".$in{'photo'}."'".')"><img src="'.$in{'thumbnail'}.'" border="1" alt="" /></a></td>');
3751: } else {
3752: $r->print('<td> </td>');
3753: }
3754: }
3755: } elsif ($item eq 'clicker') {
3756: if (($context eq 'course') && ($mode ne 'autoenroll')) {
3757: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
3758: my $clickers =
3759: (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
3760: if ($clickers!~/\w/) { $clickers='-'; }
3761: $r->print('<td>'.$clickers.'</td>');
3762: } else {
3763: $r->print('<td> </td>'."\n");
3764: }
1.149 raeburn 3765: }
1.159 raeburn 3766: } elsif (($item eq 'authorquota') || ($item eq 'authorusage')) {
3767: $r->print('<td align="right">'.$in{$item}.'</td>'."\n");
1.10 raeburn 3768: } else {
3769: $r->print('<td>'.$in{$item}.'</td>'."\n");
3770: }
1.2 raeburn 3771: }
3772: $r->print(&Apache::loncommon::end_data_table_row());
3773: } elsif ($mode eq 'csv') {
3774: next if (! defined($CSVfile));
3775: # no need to bother with $linkto
3776: my @line = ();
3777: foreach my $item (@cols) {
3778: push @line,&Apache::loncommon::csv_translate($in{$item});
3779: }
1.67 droeschl 3780: print $CSVfile '"'.join('","',@line)."\"\n";
1.2 raeburn 3781: } elsif ($mode eq 'excel') {
3782: my $col = 0;
3783: foreach my $item (@cols) {
3784: if ($item eq 'start' || $item eq 'end') {
1.136 raeburn 3785: if ((defined($in{$item})) && ($in{$item} != 0)) {
1.2 raeburn 3786: $excel_sheet->write($row,$col++,
1.136 raeburn 3787: &Apache::lonstathelpers::calc_serial($in{$item}),
1.2 raeburn 3788: $format->{'date'});
3789: } else {
3790: $excel_sheet->write($row,$col++,'none');
3791: }
3792: } else {
3793: $excel_sheet->write($row,$col++,$in{$item});
3794: }
3795: }
3796: $row++;
1.1 raeburn 3797: }
3798: }
1.55 raeburn 3799: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2 raeburn 3800: $r->print(&Apache::loncommon::end_data_table().'<br />');
3801: } elsif ($mode eq 'excel') {
3802: $excel_workbook->close();
1.162 bisitz 3803: $r->print('<p>'.&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '<a href="'.$excel_filename.'">','</a>')."</p>\n");
1.2 raeburn 3804: } elsif ($mode eq 'csv') {
3805: close($CSVfile);
1.162 bisitz 3806: $r->print('<p>'.&mt('[_1]Your CSV file[_2] is ready for download.', '<a href="'.$CSVfilename.'">','</a>')."</p>\n");
1.2 raeburn 3807: $r->rflush();
3808: }
3809: if ($mode eq 'autoenroll') {
3810: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
1.4 raeburn 3811: } else {
3812: return ($usercount);
1.2 raeburn 3813: }
1.1 raeburn 3814: }
3815:
1.56 raeburn 3816: sub bulkaction_javascript {
3817: my ($formname,$caller) = @_;
3818: my $docstart = 'document';
3819: if ($caller eq 'popup') {
3820: $docstart = 'opener.document';
3821: }
3822: my %lt = &Apache::lonlocal::texthash(
3823: acwi => 'Access will be set to start immediately',
3824: asyo => 'as you did not select an end date in the pop-up window',
3825: accw => 'Access will be set to continue indefinitely',
3826: asyd => 'as you did not select an end date in the pop-up window',
3827: sewi => "Sections will be switched to 'No section'",
3828: ayes => "as you either selected the 'No section' option",
3829: oryo => 'or you did not select a section in the pop-up window',
3830: arol => 'A role with no section will be added',
3831: swbs => 'Sections will be switched to:',
3832: rwba => 'Roles will be added for section(s):',
3833: );
3834: my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
3835: my $noaction = &mt("You need to select an action to take for the user(s) you have selected");
3836: my $singconfirm = &mt(' for a single user?');
3837: my $multconfirm = &mt(' for multiple users?');
1.170 damieng 3838: &js_escape(\$alert);
3839: &js_escape(\$noaction);
3840: &js_escape(\$singconfirm);
3841: &js_escape(\$multconfirm);
1.56 raeburn 3842: my $output = <<"ENDJS";
3843: function verify_action (field) {
3844: var numchecked = 0;
3845: var singconf = '$singconfirm';
3846: var multconf = '$multconfirm';
3847: if ($docstart.$formname.elements[field].length > 0) {
3848: for (i=0; i<$docstart.$formname.elements[field].length; i++) {
3849: if ($docstart.$formname.elements[field][i].checked == true) {
3850: numchecked ++;
3851: }
3852: }
3853: } else {
3854: if ($docstart.$formname.elements[field].checked == true) {
3855: numchecked ++;
3856: }
3857: }
3858: if (numchecked == 0) {
3859: alert("$alert");
3860: return;
3861: } else {
3862: var message = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].text;
3863: var choice = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].value;
3864: if (choice == '') {
3865: alert("$noaction");
3866: return;
3867: } else {
3868: if (numchecked == 1) {
3869: message += singconf;
3870: } else {
3871: message += multconf;
3872: }
3873: ENDJS
3874: if ($caller ne 'popup') {
3875: $output .= <<"NEWWIN";
3876: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate' || choice == 'chgsec') {
3877: opendatebrowser(document.$formname,'$formname','go');
3878: return;
3879:
3880: } else {
3881: if (confirm(message)) {
3882: document.$formname.phase.value = 'bulkchange';
3883: document.$formname.submit();
3884: return;
3885: }
3886: }
3887: NEWWIN
3888: } else {
3889: $output .= <<"POPUP";
3890: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
3891: var datemsg = '';
3892: if (($docstart.$formname.startdate_month.value == '') &&
3893: ($docstart.$formname.startdate_day.value == '') &&
3894: ($docstart.$formname.startdate_year.value == '')) {
3895: datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
3896: }
3897: if (($docstart.$formname.enddate_month.value == '') &&
3898: ($docstart.$formname.enddate_day.value == '') &&
3899: ($docstart.$formname.enddate_year.value == '')) {
3900: datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
3901: }
3902: if (datemsg != '') {
3903: message += "\\n"+datemsg;
3904: }
3905: }
3906: if (choice == 'chgsec') {
3907: var rolefilter = $docstart.$formname.showrole.options[$docstart.$formname.showrole.selectedIndex].value;
3908: var retained = $docstart.$formname.retainsec.value;
3909: var secshow = $docstart.$formname.newsecs.value;
3910: if (secshow == '') {
3911: if (rolefilter == 'st' || retained == 0 || retained == "") {
3912: message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
3913: } else {
3914: message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
3915: }
3916: } else {
3917: if (rolefilter == 'st' || retained == 0 || retained == "") {
3918: message += "\\n\\n$lt{'swbs'} "+secshow+".\\n";
3919: } else {
3920: message += "\\n\\n$lt{'rwba'} "+secshow+".\\n";
3921: }
3922: }
3923: }
3924: if (confirm(message)) {
3925: $docstart.$formname.phase.value = 'bulkchange';
3926: $docstart.$formname.submit();
3927: window.close();
3928: }
3929: POPUP
3930: }
3931: $output .= '
3932: }
3933: }
3934: }
3935: ';
3936: return $output;
3937: }
3938:
1.10 raeburn 3939: sub print_username_link {
1.48 raeburn 3940: my ($mode,$in) = @_;
1.10 raeburn 3941: my $output;
1.16 raeburn 3942: if ($mode eq 'autoenroll') {
3943: $output = $in->{'username'};
1.10 raeburn 3944: } else {
3945: $output = '<a href="javascript:username_display_launch('.
1.112 bisitz 3946: "'$in->{'username'}','$in->{'domain'}'".')">'.
1.10 raeburn 3947: $in->{'username'}.'</a>';
3948: }
3949: return $output;
3950: }
3951:
1.2 raeburn 3952: sub role_type_names {
3953: my %lt = &Apache::lonlocal::texthash (
1.13 raeburn 3954: 'domain' => 'Domain Roles',
3955: 'author' => 'Co-Author Roles',
3956: 'course' => 'Course Roles',
1.101 raeburn 3957: 'community' => 'Community Roles',
1.2 raeburn 3958: );
3959: return %lt;
3960: }
3961:
1.11 raeburn 3962: sub select_actions {
1.55 raeburn 3963: my ($context,$setting,$statusmode,$formname) = @_;
1.11 raeburn 3964: my %lt = &Apache::lonlocal::texthash(
3965: revoke => "Revoke user roles",
3966: delete => "Delete user roles",
3967: reenable => "Re-enable expired user roles",
3968: activate => "Make future user roles active now",
3969: chgdates => "Change starting/ending dates",
3970: chgsec => "Change section associated with user roles",
3971: );
1.150 raeburn 3972: # FIXME Add an option to change credits for student roles.
1.11 raeburn 3973: my ($output,$options,%choices);
1.23 raeburn 3974: # FIXME Disable actions for now for roletype=course in domain context
3975: if ($context eq 'domain' && $setting eq 'course') {
3976: return;
3977: }
1.26 raeburn 3978: if ($context eq 'course') {
3979: if ($env{'form.showrole'} ne 'Any') {
1.141 raeburn 3980: my $showactions;
3981: if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},
3982: $env{'request.course.id'})) {
3983: $showactions = 1;
3984: } elsif ($env{'request.course.sec'} ne '') {
3985: if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
3986: $showactions = 1;
3987: }
3988: }
3989: unless ($showactions) {
3990: unless (&is_courseowner($env{'request.course.id'},
3991: $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
3992: return;
3993: }
1.26 raeburn 3994: }
3995: }
3996: }
1.11 raeburn 3997: if ($statusmode eq 'Any') {
3998: $options .= '
3999: <option value="chgdates">'.$lt{'chgdates'}.'</option>';
4000: $choices{'dates'} = 1;
4001: } else {
4002: if ($statusmode eq 'Future') {
4003: $options .= '
4004: <option value="activate">'.$lt{'activate'}.'</option>';
4005: $choices{'dates'} = 1;
4006: } elsif ($statusmode eq 'Expired') {
4007: $options .= '
4008: <option value="reenable">'.$lt{'reenable'}.'</option>';
4009: $choices{'dates'} = 1;
4010: }
1.13 raeburn 4011: if ($statusmode eq 'Active' || $statusmode eq 'Future') {
4012: $options .= '
4013: <option value="chgdates">'.$lt{'chgdates'}.'</option>
4014: <option value="revoke">'.$lt{'revoke'}.'</option>';
4015: $choices{'dates'} = 1;
4016: }
1.11 raeburn 4017: }
4018: if ($context eq 'domain') {
4019: $options .= '
4020: <option value="delete">'.$lt{'delete'}.'</option>';
4021: }
4022: if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
1.26 raeburn 4023: if (($statusmode ne 'Expired') && ($env{'request.course.sec'} eq '')) {
1.11 raeburn 4024: $options .= '
4025: <option value="chgsec">'.$lt{'chgsec'}.'</option>';
4026: $choices{'sections'} = 1;
4027: }
4028: }
4029: if ($options) {
1.56 raeburn 4030: $output = '<select name="bulkaction">'."\n".
1.11 raeburn 4031: '<option value="" selected="selected">'.
4032: &mt('Please select').'</option>'."\n".$options."\n".'</select>';
4033: if ($choices{'dates'}) {
4034: $output .=
4035: '<input type="hidden" name="startdate_month" value="" />'."\n".
4036: '<input type="hidden" name="startdate_day" value="" />'."\n".
4037: '<input type="hidden" name="startdate_year" value="" />'."\n".
4038: '<input type="hidden" name="startdate_hour" value="" />'."\n".
4039: '<input type="hidden" name="startdate_minute" value="" />'."\n".
4040: '<input type="hidden" name="startdate_second" value="" />'."\n".
4041: '<input type="hidden" name="enddate_month" value="" />'."\n".
4042: '<input type="hidden" name="enddate_day" value="" />'."\n".
4043: '<input type="hidden" name="enddate_year" value="" />'."\n".
4044: '<input type="hidden" name="enddate_hour" value="" />'."\n".
4045: '<input type="hidden" name="enddate_minute" value="" />'."\n".
1.56 raeburn 4046: '<input type="hidden" name="enddate_second" value="" />'."\n".
4047: '<input type="hidden" name="no_end_date" value="" />'."\n";
1.11 raeburn 4048: if ($context eq 'course') {
4049: $output .= '<input type="hidden" name="makedatesdefault" value="" />'."\n";
4050: }
4051: }
4052: if ($choices{'sections'}) {
1.91 bisitz 4053: $output .= '<input type="hidden" name="retainsec" value="" />'."\n".
4054: '<input type="hidden" name="newsecs" value="" />'."\n";
1.11 raeburn 4055: }
4056: }
4057: return $output;
4058: }
4059:
4060: sub date_section_javascript {
4061: my ($context,$setting) = @_;
1.49 raeburn 4062: my $title = 'Date_And_Section_Selector';
1.41 raeburn 4063: my %nopopup = &Apache::lonlocal::texthash (
4064: revoke => "Check the boxes for any users for whom roles are to be revoked, and click 'Proceed'",
4065: delete => "Check the boxes for any users for whom roles are to be deleted, and click 'Proceed'",
4066: none => "Choose an action to take for selected users",
4067: );
1.96 bisitz 4068: my $output = <<"ENDONE";
4069: <script type="text/javascript">
4070: // <![CDATA[
1.41 raeburn 4071: function opendatebrowser(callingform,formname,calledby) {
1.11 raeburn 4072: var bulkaction = callingform.bulkaction.options[callingform.bulkaction.selectedIndex].value;
4073: var url = '/adm/createuser?';
4074: var type = '';
4075: var showrole = callingform.showrole.options[callingform.showrole.selectedIndex].value;
4076: ENDONE
4077: if ($context eq 'domain') {
4078: $output .= '
4079: type = callingform.roletype.options[callingform.roletype.selectedIndex].value;
4080: ';
4081: }
4082: my $width= '700';
4083: my $height = '400';
4084: $output .= <<"ENDTWO";
4085: url += 'action=dateselect&callingform=' + formname +
4086: '&roletype='+type+'&showrole='+showrole +'&bulkaction='+bulkaction;
4087: var title = '$title';
4088: var options = 'scrollbars=1,resizable=1,menubar=0';
4089: options += ',width=$width,height=$height';
4090: stdeditbrowser = open(url,title,options,'1');
4091: stdeditbrowser.focus();
4092: }
1.96 bisitz 4093: // ]]>
1.11 raeburn 4094: </script>
4095: ENDTWO
4096: return $output;
4097: }
4098:
4099: sub date_section_selector {
1.150 raeburn 4100: my ($context,$permission,$crstype,$showcredits) = @_;
1.11 raeburn 4101: my $callingform = $env{'form.callingform'};
4102: my $formname = 'dateselect';
4103: my $groupslist = &get_groupslist();
1.150 raeburn 4104: my $sec_js =
4105: &setsections_javascript($formname,$groupslist,undef,undef,$crstype,
4106: $showcredits);
1.11 raeburn 4107: my $output = <<"END";
4108: <script type="text/javascript">
1.96 bisitz 4109: // <![CDATA[
1.11 raeburn 4110:
4111: $sec_js
4112:
4113: function saveselections(formname) {
4114:
4115: END
4116: if ($env{'form.bulkaction'} eq 'chgsec') {
4117: $output .= <<"END";
1.40 raeburn 4118: if (formname.retainsec.length > 1) {
4119: for (var i=0; i<formname.retainsec.length; i++) {
4120: if (formname.retainsec[i].checked == true) {
4121: opener.document.$callingform.retainsec.value = formname.retainsec[i].value;
4122: }
4123: }
4124: } else {
4125: opener.document.$callingform.retainsec.value = formname.retainsec.value;
4126: }
1.103 raeburn 4127: setSections(formname,'$crstype');
1.11 raeburn 4128: if (seccheck == 'ok') {
4129: opener.document.$callingform.newsecs.value = formname.sections.value;
1.205 raeburn 4130: } else {
4131: return;
1.11 raeburn 4132: }
4133: END
4134: } else {
4135: if ($context eq 'course') {
4136: if (($env{'form.bulkaction'} eq 'reenable') ||
4137: ($env{'form.bulkaction'} eq 'activate') ||
4138: ($env{'form.bulkaction'} eq 'chgdates')) {
1.26 raeburn 4139: if ($env{'request.course.sec'} eq '') {
4140: $output .= <<"END";
1.11 raeburn 4141:
4142: if (formname.makedatesdefault.checked == true) {
4143: opener.document.$callingform.makedatesdefault.value = 1;
4144: }
4145: else {
4146: opener.document.$callingform.makedatesdefault.value = 0;
4147: }
4148:
4149: END
1.26 raeburn 4150: }
1.11 raeburn 4151: }
4152: }
4153: $output .= <<"END";
4154: opener.document.$callingform.startdate_month.value = formname.startdate_month.options[formname.startdate_month.selectedIndex].value;
4155: opener.document.$callingform.startdate_day.value = formname.startdate_day.value;
4156: opener.document.$callingform.startdate_year.value = formname.startdate_year.value;
4157: opener.document.$callingform.startdate_hour.value = formname.startdate_hour.options[formname.startdate_hour.selectedIndex].value;
4158: opener.document.$callingform.startdate_minute.value = formname.startdate_minute.value;
4159: opener.document.$callingform.startdate_second.value = formname.startdate_second.value;
4160: opener.document.$callingform.enddate_month.value = formname.enddate_month.options[formname.enddate_month.selectedIndex].value;
4161: opener.document.$callingform.enddate_day.value = formname.enddate_day.value;
4162: opener.document.$callingform.enddate_year.value = formname.enddate_year.value;
4163: opener.document.$callingform.enddate_hour.value = formname.enddate_hour.options[formname.enddate_hour.selectedIndex].value;
4164: opener.document.$callingform.enddate_minute.value = formname.enddate_minute.value;
4165: opener.document.$callingform.enddate_second.value = formname.enddate_second.value;
1.56 raeburn 4166: if (formname.no_end_date.checked) {
4167: opener.document.$callingform.no_end_date.value = '1';
4168: } else {
4169: opener.document.$callingform.no_end_date.value = '0';
4170: }
1.11 raeburn 4171: END
4172: }
1.56 raeburn 4173: my $verify_action_js = &bulkaction_javascript($callingform,'popup');
4174: $output .= <<"ENDJS";
4175: verify_action('actionlist');
1.11 raeburn 4176: }
1.56 raeburn 4177:
4178: $verify_action_js
4179:
1.96 bisitz 4180: // ]]>
1.11 raeburn 4181: </script>
1.56 raeburn 4182: ENDJS
1.11 raeburn 4183: my %lt = &Apache::lonlocal::texthash (
4184: chac => 'Access dates to apply for selected users',
4185: chse => 'Changes in section affiliation to apply to selected users',
1.118 raeburn 4186: 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.',
4187: forn => 'For a course role that is not "student", users may have roles in more than one section at a time.',
4188: reta => "Retain each user's current section affiliations?",
1.103 raeburn 4189: dnap => '(Does not apply to student roles).',
1.11 raeburn 4190: );
4191: my ($date_items,$headertext);
4192: if ($env{'form.bulkaction'} eq 'chgsec') {
4193: $headertext = $lt{'chse'};
4194: } else {
4195: $headertext = $lt{'chac'};
4196: my $starttime;
4197: if (($env{'form.bulkaction'} eq 'activate') ||
4198: ($env{'form.bulkaction'} eq 'reenable')) {
4199: $starttime = time;
4200: }
4201: $date_items = &date_setting_table($starttime,undef,$context,
1.21 raeburn 4202: $env{'form.bulkaction'},$formname,
1.101 raeburn 4203: $permission,$crstype);
1.11 raeburn 4204: }
4205: $output .= '<h3>'.$headertext.'</h3>'.
1.118 raeburn 4206: '<form name="'.$formname.'" method="post" action="">'."\n".
1.11 raeburn 4207: $date_items;
4208: if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
1.17 raeburn 4209: my ($cnum,$cdom) = &get_course_identity();
1.103 raeburn 4210: if ($crstype eq 'Community') {
1.118 raeburn 4211: $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.');
4212: $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 4213: $lt{'dnap'} = &mt('(Does not apply to member roles).');
4214: }
1.11 raeburn 4215: my $info;
4216: if ($env{'form.showrole'} eq 'st') {
4217: $output .= '<p>'.$lt{'fors'}.'</p>';
1.26 raeburn 4218: } elsif ($env{'form.showrole'} eq 'Any') {
1.11 raeburn 4219: $output .= '<p>'.$lt{'fors'}.'</p>'.
4220: '<p>'.$lt{'forn'}.' ';
4221: $info = $lt{'reta'};
4222: } else {
4223: $output .= '<p>'.$lt{'forn'}.' ';
4224: $info = $lt{'reta'};
4225: }
4226: if ($info) {
4227: $info .= '<span class="LC_nobreak">'.
4228: '<label><input type="radio" name="retainsec" value="1" '.
4229: 'checked="checked" />'.&mt('Yes').'</label> '.
4230: '<label><input type="radio" name="retainsec" value="0" />'.
4231: &mt('No').'</label></span>';
4232: if ($env{'form.showrole'} eq 'Any') {
4233: $info .= '<br />'.$lt{'dnap'};
4234: }
4235: $info .= '</p>';
4236: } else {
4237: $info = '<input type="hidden" name="retainsec" value="0" />';
4238: }
1.21 raeburn 4239: my $rowtitle = &mt('New section to assign');
1.150 raeburn 4240: my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,
4241: $permission,$context,'chgsec',$crstype);
1.11 raeburn 4242: $output .= $info.$secbox;
4243: }
4244: $output .= '<p>'.
1.81 schafran 4245: '<input type="button" name="dateselection" value="'.&mt('Save').'" onclick="javascript:saveselections(this.form)" /></p>'."\n".
1.11 raeburn 4246: '</form>';
4247: return $output;
4248: }
4249:
1.17 raeburn 4250: sub section_picker {
1.150 raeburn 4251: my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode,$crstype,
4252: $showcredits,$credits) = @_;
1.17 raeburn 4253: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
4254: my $sections_select .= &course_sections(\%sections_count,$role);
1.118 raeburn 4255: my $secbox = '<div>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
1.17 raeburn 4256: if ($mode eq 'upload') {
4257: my ($options,$cb_script,$coursepick) =
1.150 raeburn 4258: &default_role_selector($context,1,$crstype,$showcredits);
1.59 bisitz 4259: $secbox .= &Apache::lonhtmlcommon::row_title(&mt('role'),'LC_oddrow_value').
1.17 raeburn 4260: $options. &Apache::lonhtmlcommon::row_closure(1)."\n";
4261: }
4262: $secbox .= &Apache::lonhtmlcommon::row_title($rowtitle,'LC_oddrow_value')."\n";
4263: if ($env{'request.course.sec'} eq '') {
4264: $secbox .= '<table class="LC_createuser"><tr class="LC_section_row">'."\n".
4265: '<td align="center">'.&mt('Existing sections')."\n".
4266: '<br />'.$sections_select.'</td><td align="center">'.
4267: &mt('New section').'<br />'."\n".
1.118 raeburn 4268: '<input type="text" name="newsec" size="15" value="" />'."\n".
1.17 raeburn 4269: '<input type="hidden" name="sections" value="" />'."\n".
4270: '</td></tr></table>'."\n";
4271: } else {
1.149 raeburn 4272: $secbox .= '<input type="hidden" name="sections" value="'.
1.17 raeburn 4273: $env{'request.course.sec'}.'" />'.
4274: $env{'request.course.sec'};
4275: }
1.150 raeburn 4276: $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n";
4277: unless ($mode eq 'chgsec') {
4278: if ($showcredits) {
4279: $secbox .=
4280: &Apache::lonhtmlcommon::row_title(&mt('credits (students)'),
4281: 'LC_evenrow_value')."\n".
4282: '<input type="text" name="credits" size="3" value="'.$credits.'" />'."\n".
4283: &Apache::lonhtmlcommon::row_closure(1)."\n";
4284: }
4285: }
4286: $secbox .= &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.17 raeburn 4287: return $secbox;
4288: }
4289:
1.2 raeburn 4290: sub results_header_row {
1.102 raeburn 4291: my ($rolefilter,$statusmode,$context,$permission,$mode,$crstype) = @_;
1.5 raeburn 4292: my ($description,$showfilter);
4293: if ($rolefilter ne 'Any') {
4294: $showfilter = $rolefilter;
4295: }
1.2 raeburn 4296: if ($context eq 'course') {
1.24 raeburn 4297: if ($mode eq 'csv' || $mode eq 'excel') {
1.102 raeburn 4298: if ($crstype eq 'Community') {
4299: $description = &mt('Community - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
4300: } else {
4301: $description = &mt('Course - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
4302: }
1.24 raeburn 4303: }
1.2 raeburn 4304: if ($statusmode eq 'Expired') {
1.102 raeburn 4305: if ($crstype eq 'Community') {
4306: $description .= &mt('Users in community with expired [_1] roles',$showfilter);
4307: } else {
4308: $description .= &mt('Users in course with expired [_1] roles',$showfilter);
4309: }
1.11 raeburn 4310: } elsif ($statusmode eq 'Future') {
1.102 raeburn 4311: if ($crstype eq 'Community') {
4312: $description .= &mt('Users in community with future [_1] roles',$showfilter);
4313: } else {
4314: $description .= &mt('Users in course with future [_1] roles',$showfilter);
4315: }
1.2 raeburn 4316: } elsif ($statusmode eq 'Active') {
1.102 raeburn 4317: if ($crstype eq 'Community') {
4318: $description .= &mt('Users in community with active [_1] roles',$showfilter);
4319: } else {
4320: $description .= &mt('Users in course with active [_1] roles',$showfilter);
4321: }
1.2 raeburn 4322: } else {
4323: if ($rolefilter eq 'Any') {
1.102 raeburn 4324: if ($crstype eq 'Community') {
4325: $description .= &mt('All users in community');
4326: } else {
4327: $description .= &mt('All users in course');
4328: }
1.2 raeburn 4329: } else {
1.102 raeburn 4330: if ($crstype eq 'Community') {
4331: $description .= &mt('All users in community with [_1] roles',$rolefilter);
4332: } else {
4333: $description .= &mt('All users in course with [_1] roles',$rolefilter);
4334: }
1.2 raeburn 4335: }
4336: }
1.33 raeburn 4337: my $constraint;
1.26 raeburn 4338: my $viewablesec = &viewable_section($permission);
4339: if ($viewablesec ne '') {
1.15 raeburn 4340: if ($env{'form.showrole'} eq 'st') {
1.33 raeburn 4341: $constraint = &mt('only users in section "[_1]"',$viewablesec);
1.103 raeburn 4342: } elsif (($env{'form.showrole'} ne 'cc') && ($env{'form.showrole'} ne 'co')) {
1.33 raeburn 4343: $constraint = &mt('only users affiliated with no section or section "[_1]"',$viewablesec);
4344: }
4345: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
4346: if ($env{'form.grpfilter'} eq 'none') {
4347: $constraint .= &mt(' and not in any group');
4348: } else {
4349: $constraint .= &mt(' and members of group: "[_1]"',$env{'form.grpfilter'});
4350: }
4351: }
4352: } else {
4353: if (($env{'form.secfilter'} ne 'all') && ($env{'form.secfilter'} ne '')) {
4354: if ($env{'form.secfilter'} eq 'none') {
4355: $constraint = &mt('only users affiliated with no section');
4356: } else {
4357: $constraint = &mt('only users affiliated with section "[_1]"',$env{'form.secfilter'});
4358: }
4359: }
4360: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
4361: if ($env{'form.grpfilter'} eq 'none') {
4362: if ($constraint eq '') {
4363: $constraint = &mt('only users not in any group');
4364: } else {
4365: $constraint .= &mt(' and also not in any group');
4366: }
4367: } else {
4368: if ($constraint eq '') {
4369: $constraint = &mt('only members of group: "[_1]"',$env{'form.grpfilter'});
4370: } else {
4371: $constraint .= &mt(' and also members of group: "[_1]"'.$env{'form.grpfilter'});
4372: }
4373: }
1.15 raeburn 4374: }
4375: }
1.33 raeburn 4376: if ($constraint ne '') {
4377: $description .= ' ('.$constraint.')';
4378: }
1.13 raeburn 4379: } elsif ($context eq 'author') {
1.14 raeburn 4380: $description =
1.73 bisitz 4381: &mt('Author space for [_1]'
4382: ,'<span class="LC_cusr_emph">'
4383: .&Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'})
4384: .'</span>')
4385: .': ';
1.2 raeburn 4386: if ($statusmode eq 'Expired') {
1.5 raeburn 4387: $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
1.2 raeburn 4388: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4389: $description .= &mt('Co-authors with future [_1] roles',$showfilter);
1.2 raeburn 4390: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4391: $description .= &mt('Co-authors with active [_1] roles',$showfilter);
1.2 raeburn 4392: } else {
4393: if ($rolefilter eq 'Any') {
1.5 raeburn 4394: $description .= &mt('All co-authors');
1.2 raeburn 4395: } else {
4396: $description .= &mt('All co-authors with [_1] roles',$rolefilter);
4397: }
4398: }
4399: } elsif ($context eq 'domain') {
4400: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.73 bisitz 4401: $description = &mt('Domain - [_1]:',$domdesc).' ';
1.2 raeburn 4402: if ($env{'form.roletype'} eq 'domain') {
4403: if ($statusmode eq 'Expired') {
1.5 raeburn 4404: $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
1.2 raeburn 4405: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4406: $description .= &mt('Users in domain with future [_1] roles',$showfilter);
1.2 raeburn 4407: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4408: $description .= &mt('Users in domain with active [_1] roles',$showfilter);
1.2 raeburn 4409: } else {
4410: if ($rolefilter eq 'Any') {
1.5 raeburn 4411: $description .= &mt('All users in domain');
1.2 raeburn 4412: } else {
4413: $description .= &mt('All users in domain with [_1] roles',$rolefilter);
4414: }
4415: }
1.13 raeburn 4416: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 4417: if ($statusmode eq 'Expired') {
1.5 raeburn 4418: $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
1.2 raeburn 4419: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4420: $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
1.2 raeburn 4421: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4422: $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
1.2 raeburn 4423: } else {
4424: if ($rolefilter eq 'Any') {
1.5 raeburn 4425: $description .= &mt('All users with co-author roles in domain',$showfilter);
1.2 raeburn 4426: } else {
1.116 bisitz 4427: $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
1.2 raeburn 4428: }
4429: }
1.102 raeburn 4430: } elsif (($env{'form.roletype'} eq 'course') ||
4431: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 4432: my $coursefilter = $env{'form.coursepick'};
1.102 raeburn 4433: if ($env{'form.roletype'} eq 'course') {
4434: if ($coursefilter eq 'category') {
4435: my $instcode = &instcode_from_coursefilter();
4436: if ($instcode eq '.') {
4437: $description .= &mt('All courses in domain').' - ';
4438: } else {
4439: $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
4440: }
4441: } elsif ($coursefilter eq 'selected') {
4442: $description .= &mt('Selected courses in domain').' - ';
4443: } elsif ($coursefilter eq 'all') {
1.2 raeburn 4444: $description .= &mt('All courses in domain').' - ';
4445: }
1.102 raeburn 4446: } elsif ($env{'form.roletype'} eq 'community') {
4447: if ($coursefilter eq 'selected') {
4448: $description .= &mt('Selected communities in domain').' - ';
4449: } elsif ($coursefilter eq 'all') {
4450: $description .= &mt('All communities in domain').' - ';
4451: }
1.2 raeburn 4452: }
4453: if ($statusmode eq 'Expired') {
1.5 raeburn 4454: $description .= &mt('users with expired [_1] roles',$showfilter);
1.2 raeburn 4455: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4456: $description .= &mt('users with future [_1] roles',$showfilter);
1.2 raeburn 4457: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4458: $description .= &mt('users with active [_1] roles',$showfilter);
1.2 raeburn 4459: } else {
4460: if ($rolefilter eq 'Any') {
4461: $description .= &mt('all users');
4462: } else {
4463: $description .= &mt('users with [_1] roles',$rolefilter);
4464: }
4465: }
4466: }
4467: }
4468: return $description;
4469: }
1.22 raeburn 4470:
4471: sub viewable_section {
4472: my ($permission) = @_;
4473: my $viewablesec;
4474: if (ref($permission) eq 'HASH') {
4475: if (exists($permission->{'view_section'})) {
4476: $viewablesec = $permission->{'view_section'};
4477: } elsif (exists($permission->{'cusr_section'})) {
4478: $viewablesec = $permission->{'cusr_section'};
4479: }
4480: }
4481: return $viewablesec;
4482: }
4483:
1.2 raeburn 4484:
1.1 raeburn 4485: #################################################
4486: #################################################
4487: sub show_drop_list {
1.101 raeburn 4488: my ($r,$classlist,$nosort,$permission,$crstype) = @_;
1.29 raeburn 4489: my $cid = $env{'request.course.id'};
1.17 raeburn 4490: my ($cnum,$cdom) = &get_course_identity($cid);
1.1 raeburn 4491: if (! exists($env{'form.sortby'})) {
4492: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
4493: ['sortby']);
4494: }
4495: my $sortby = $env{'form.sortby'};
4496: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
4497: $sortby = 'username';
4498: }
4499: my $action = "drop";
1.17 raeburn 4500: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
1.1 raeburn 4501: $r->print(<<END);
4502: <input type="hidden" name="sortby" value="$sortby" />
4503: <input type="hidden" name="action" value="$action" />
4504: <input type="hidden" name="state" value="done" />
1.17 raeburn 4505: <script type="text/javascript" language="Javascript">
1.96 bisitz 4506: // <![CDATA[
1.17 raeburn 4507: $check_uncheck_js
1.96 bisitz 4508: // ]]>
1.1 raeburn 4509: </script>
1.86 bisitz 4510: <input type="hidden" name="phase" value="four" />
1.1 raeburn 4511: END
1.30 raeburn 4512: my ($indexhash,$keylist) = &make_keylist_array();
4513: my $studentcount = 0;
4514: if (ref($classlist) eq 'HASH') {
4515: foreach my $student (keys(%{$classlist})) {
4516: my $sdata = $classlist->{$student};
4517: my $status = $sdata->[$indexhash->{'status'}];
4518: my $section = $sdata->[$indexhash->{'section'}];
4519: if ($status ne 'Active') {
4520: delete($classlist->{$student});
4521: next;
4522: }
4523: if ($env{'request.course.sec'} ne '') {
4524: if ($section ne $env{'request.course.sec'}) {
4525: delete($classlist->{$student});
4526: next;
4527: }
4528: }
4529: $studentcount ++;
4530: }
4531: }
4532: if (!$studentcount) {
1.143 bisitz 4533: my $msg = '';
1.101 raeburn 4534: if ($crstype eq 'Community') {
1.143 bisitz 4535: $msg = &mt('There are no members to drop.');
1.101 raeburn 4536: } else {
1.143 bisitz 4537: $msg = &mt('There are no students to drop.');
1.101 raeburn 4538: }
1.143 bisitz 4539: $r->print('<p class="LC_info">'.$msg.'</p>');
1.30 raeburn 4540: return;
4541: }
4542: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
4543: $classlist,$keylist,$cdom,$cnum);
4544: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
4545: 'dom' => "domain",
1.162 bisitz 4546: 'id' => "ID",
1.30 raeburn 4547: 'sn' => "student name",
1.101 raeburn 4548: 'mn' => "member name",
1.30 raeburn 4549: 'sec' => "section",
4550: 'start' => "start date",
4551: 'end' => "end date",
4552: 'groups' => "active groups",
4553: );
1.101 raeburn 4554: my $nametitle = $lt{'sn'};
4555: if ($crstype eq 'Community') {
4556: $nametitle = $lt{'mn'};
4557: }
1.1 raeburn 4558: if ($nosort) {
1.17 raeburn 4559: $r->print(&Apache::loncommon::start_data_table().
4560: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 4561: $r->print(<<END);
4562: <th> </th>
4563: <th>$lt{'usrn'}</th>
4564: <th>$lt{'dom'}</th>
1.162 bisitz 4565: <th>$lt{'id'}</th>
1.101 raeburn 4566: <th>$nametitle</th>
1.1 raeburn 4567: <th>$lt{'sec'}</th>
4568: <th>$lt{'start'}</th>
4569: <th>$lt{'end'}</th>
4570: <th>$lt{'groups'}</th>
4571: END
1.17 raeburn 4572: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 4573: } else {
1.17 raeburn 4574: $r->print(&Apache::loncommon::start_data_table().
4575: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 4576: $r->print(<<END);
1.17 raeburn 4577: <th> </th>
1.1 raeburn 4578: <th>
1.162 bisitz 4579: <a href="/adm/createuser?action=$action&sortby=username">$lt{'usrn'}</a>
1.1 raeburn 4580: </th><th>
1.162 bisitz 4581: <a href="/adm/createuser?action=$action&sortby=domain">$lt{'dom'}</a>
1.1 raeburn 4582: </th><th>
1.162 bisitz 4583: <a href="/adm/createuser?action=$action&sortby=id">$lt{'id'}</a>
1.1 raeburn 4584: </th><th>
1.162 bisitz 4585: <a href="/adm/createuser?action=$action&sortby=fullname">$nametitle</a>
1.1 raeburn 4586: </th><th>
1.162 bisitz 4587: <a href="/adm/createuser?action=$action&sortby=section">$lt{'sec'}</a>
1.1 raeburn 4588: </th><th>
1.162 bisitz 4589: <a href="/adm/createuser?action=$action&sortby=start">$lt{'start'}</a>
1.1 raeburn 4590: </th><th>
1.162 bisitz 4591: <a href="/adm/createuser?action=$action&sortby=end">$lt{'end'}</a>
1.1 raeburn 4592: </th><th>
1.162 bisitz 4593: <a href="/adm/createuser?action=$action&sortby=groups">$lt{'groups'}</a>
1.1 raeburn 4594: </th>
4595: END
1.17 raeburn 4596: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 4597: }
4598: #
4599: # Sort the students
1.30 raeburn 4600: my $index = $indexhash->{$sortby};
4601: my $second = $indexhash->{'username'};
4602: my $third = $indexhash->{'domain'};
1.1 raeburn 4603: my @Sorted_Students = sort {
4604: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
4605: ||
4606: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
4607: ||
4608: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
1.30 raeburn 4609: } (keys(%{$classlist}));
1.1 raeburn 4610: foreach my $student (@Sorted_Students) {
4611: my $error;
4612: my $sdata = $classlist->{$student};
1.30 raeburn 4613: my $username = $sdata->[$indexhash->{'username'}];
4614: my $domain = $sdata->[$indexhash->{'domain'}];
4615: my $section = $sdata->[$indexhash->{'section'}];
4616: my $name = $sdata->[$indexhash->{'fullname'}];
4617: my $id = $sdata->[$indexhash->{'id'}];
4618: my $start = $sdata->[$indexhash->{'start'}];
4619: my $end = $sdata->[$indexhash->{'end'}];
1.1 raeburn 4620: my $groups = $classgroups->{$student};
4621: my $active_groups;
4622: if (ref($groups->{active}) eq 'HASH') {
4623: $active_groups = join(', ',keys(%{$groups->{'active'}}));
4624: }
4625: if (! defined($start) || $start == 0) {
4626: $start = &mt('none');
4627: } else {
4628: $start = &Apache::lonlocal::locallocaltime($start);
4629: }
4630: if (! defined($end) || $end == 0) {
4631: $end = &mt('none');
4632: } else {
4633: $end = &Apache::lonlocal::locallocaltime($end);
4634: }
1.17 raeburn 4635: my $studentkey = $student.':'.$section;
1.30 raeburn 4636: my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$indexhash->{'start'}].'" />';
1.1 raeburn 4637: #
4638: $r->print(&Apache::loncommon::start_data_table_row());
4639: $r->print(<<"END");
1.86 bisitz 4640: <td><input type="checkbox" name="droplist" value="$studentkey" /></td>
1.1 raeburn 4641: <td>$username</td>
4642: <td>$domain</td>
4643: <td>$id</td>
4644: <td>$name</td>
4645: <td>$section</td>
1.29 raeburn 4646: <td>$start $startitem</td>
1.1 raeburn 4647: <td>$end</td>
4648: <td>$active_groups</td>
4649: END
4650: $r->print(&Apache::loncommon::end_data_table_row());
4651: }
4652: $r->print(&Apache::loncommon::end_data_table().'<br />');
4653: %lt=&Apache::lonlocal::texthash(
1.29 raeburn 4654: 'dp' => "Drop Students",
1.101 raeburn 4655: 'dm' => "Drop Members",
1.1 raeburn 4656: 'ca' => "check all",
4657: 'ua' => "uncheck all",
4658: );
1.101 raeburn 4659: my $btn = $lt{'dp'};
4660: if ($crstype eq 'Community') {
4661: $btn = $lt{'dm'};
4662: }
1.1 raeburn 4663: $r->print(<<"END");
1.89 bisitz 4664: <p>
1.86 bisitz 4665: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)" />
4666: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)" />
1.89 bisitz 4667: </p>
4668: <p>
1.101 raeburn 4669: <input type="submit" value="$btn" />
1.89 bisitz 4670: </p>
1.1 raeburn 4671: END
4672: return;
4673: }
4674:
4675: #
4676: # Print out the initial form to get the file containing a list of users
4677: #
4678: sub print_first_users_upload_form {
4679: my ($r,$context) = @_;
4680: my $str;
1.86 bisitz 4681: $str = '<input type="hidden" name="phase" value="two" />';
1.1 raeburn 4682: $str .= '<input type="hidden" name="action" value="upload" />';
1.101 raeburn 4683: $str .= '<input type="hidden" name="state" value="got_file" />';
1.95 bisitz 4684:
1.147 bisitz 4685: $str .= &Apache::grades::checkforfile_js();
4686:
1.85 bisitz 4687: $str .= '<h2>'.&mt('Upload a file containing information about users').'</h2>'."\n";
1.95 bisitz 4688:
4689: # Excel and CSV Help
1.147 bisitz 4690: $str .= '<div class="LC_columnSection">'
1.95 bisitz 4691: .&Apache::loncommon::help_open_topic("Course_Create_Class_List",
4692: &mt("How do I create a users list from a spreadsheet"))
1.147 bisitz 4693: .' '.&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1.95 bisitz 4694: &mt("How do I create a CSV file from a spreadsheet"))
1.147 bisitz 4695: ."</div>\n";
1.95 bisitz 4696: $str .= &Apache::lonhtmlcommon::start_pick_box()
1.103 raeburn 4697: .&Apache::lonhtmlcommon::row_title(&mt('File'));
4698: if (&Apache::lonlocal::current_language() ne 'en') {
4699: if ($context eq 'course') {
4700: $str .= '<p class="LC_info">'."\n"
4701: .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n"
4702: .'</p>'."\n";
4703: }
4704: }
4705: $str .= &Apache::loncommon::upfile_select_html()
1.95 bisitz 4706: .&Apache::lonhtmlcommon::row_closure()
4707: .&Apache::lonhtmlcommon::row_title(
4708: '<label for="noFirstLine">'
4709: .&mt('Ignore First Line')
4710: .'</label>')
4711: .'<input type="checkbox" name="noFirstLine" id="noFirstLine" />'
4712: .&Apache::lonhtmlcommon::row_closure(1)
4713: .&Apache::lonhtmlcommon::end_pick_box();
4714:
4715: $str .= '<p>'
1.198 raeburn 4716: .'<input type="button" name="fileupload" value="'.&mt('Next').'"'
1.147 bisitz 4717: .' onclick="javascript:checkUpload(this.form);" />'
1.95 bisitz 4718: .'</p>';
4719:
1.1 raeburn 4720: $r->print($str);
4721: return;
4722: }
4723:
4724: # ================================================= Drop/Add from uploaded file
4725: sub upfile_drop_add {
1.150 raeburn 4726: my ($r,$context,$permission,$showcredits) = @_;
1.189 raeburn 4727: my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'});
4728: if ($datatoken ne '') {
4729: &Apache::loncommon::load_tmp_file($r,$datatoken);
4730: }
1.1 raeburn 4731: my @userdata=&Apache::loncommon::upfile_record_sep();
4732: if($env{'form.noFirstLine'}){shift(@userdata);}
4733: my @keyfields = split(/\,/,$env{'form.keyfields'});
4734: my %fields=();
4735: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
4736: if ($env{'form.upfile_associate'} eq 'reverse') {
4737: if ($env{'form.f'.$i} ne 'none') {
4738: $fields{$keyfields[$i]}=$env{'form.f'.$i};
4739: }
4740: } else {
4741: $fields{$env{'form.f'.$i}}=$keyfields[$i];
4742: }
4743: }
4744: #
4745: # Store the field choices away
1.150 raeburn 4746: my @storefields = qw/username names fname mname lname gen id
4747: sec ipwd email role domain inststatus/;
4748: if ($showcredits) {
4749: push (@storefields,'credits');
4750: }
4751: my %fieldstype;
4752: foreach my $field (@storefields) {
1.1 raeburn 4753: $env{'form.'.$field.'_choice'}=$fields{$field};
1.150 raeburn 4754: $fieldstype{$field.'_choice'} = 'scalar';
1.1 raeburn 4755: }
1.150 raeburn 4756: &Apache::loncommon::store_course_settings('enrollment_upload',\%fieldstype);
1.217 raeburn 4757: my ($cid,$crstype,$setting,$crsdom,$crsnum,$oldcrsuserdoms);
1.101 raeburn 4758: if ($context eq 'domain') {
4759: $setting = $env{'form.roleaction'};
4760: }
4761: if ($env{'request.course.id'} ne '') {
4762: $cid = $env{'request.course.id'};
4763: $crstype = &Apache::loncommon::course_type();
1.185 raeburn 4764: $crsdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.212 raeburn 4765: $crsnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.101 raeburn 4766: } elsif ($setting eq 'course') {
4767: if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
4768: $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
4769: $crstype = &Apache::loncommon::course_type($cid);
1.185 raeburn 4770: $crsdom = $env{'form.dcdomain'};
1.212 raeburn 4771: $crsnum = $env{'form.dccourse'};
1.217 raeburn 4772: if (exists($env{'course.'.$cid.'.internal.userdomains'})) {
4773: $oldcrsuserdoms = 1;
4774: }
4775: my %coursedesc = &Apache::lonnet::coursedescription($cid,{ one_time => 1 });
4776: $env{'course.'.$cid.'.internal.userdomains'} = $coursedesc{'internal.userdomains'};
1.101 raeburn 4777: }
4778: }
1.1 raeburn 4779: my ($startdate,$enddate) = &get_dates_from_form();
4780: if ($env{'form.makedatesdefault'}) {
1.101 raeburn 4781: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
1.1 raeburn 4782: }
4783: # Determine domain and desired host (home server)
1.57 raeburn 4784: my $defdom=$env{'request.role.domain'};
4785: my $domain;
4786: if ($env{'form.defaultdomain'} ne '') {
1.185 raeburn 4787: if (($context eq 'course') || ($setting eq 'course')) {
1.190 raeburn 4788: if ($env{'form.defaultdomain'} eq $crsdom) {
4789: $domain = $env{'form.defaultdomain'};
4790: } else {
1.185 raeburn 4791: if (&Apache::lonnet::will_trust('enroll',$crsdom,$env{'form.defaultdomain'})) {
4792: $domain = $env{'form.defaultdomain'};
4793: } else {
1.192 raeburn 4794: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4795: &mt('Enrollment of users not permitted for specified default domain: [_1].',
4796: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4797: return 'untrusted';
1.185 raeburn 4798: }
4799: }
4800: } elsif ($context eq 'author') {
1.190 raeburn 4801: if ($env{'form.defaultdomain'} eq $defdom) {
4802: $domain = $env{'form.defaultdomain'};
4803: } else {
1.185 raeburn 4804: if ((&Apache::lonnet::will_trust('othcoau',$defdom,$env{'form.defaultdomain'})) &&
1.186 raeburn 4805: (&Apache::lonnet::will_trust('coaurem',$env{'form.defaultdomain'},$defdom))) {
1.185 raeburn 4806: $domain = $env{'form.defaultdomain'};
4807: } else {
1.192 raeburn 4808: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4809: &mt('Addition of users not permitted for specified default domain: [_1].',
4810: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4811: return 'untrusted';
1.185 raeburn 4812: }
4813: }
4814: } elsif (($context eq 'domain') && ($setting eq 'domain')) {
1.190 raeburn 4815: if ($env{'form.defaultdomain'} eq $defdom) {
4816: $domain = $env{'form.defaultdomain'};
4817: } else {
1.185 raeburn 4818: if (&Apache::lonnet::will_trust('domroles',$defdom,$env{'form.defaultdomain'})) {
4819: $domain = $env{'form.defaultdomain'};
4820: } else {
1.192 raeburn 4821: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4822: &mt('Addition of users not permitted for specified default domain: [_1].',
4823: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4824: return 'untrusted';
1.185 raeburn 4825: }
4826: }
4827: }
1.57 raeburn 4828: } else {
4829: $domain = $defdom;
4830: }
1.1 raeburn 4831: my $desiredhost = $env{'form.lcserver'};
4832: if (lc($desiredhost) eq 'default') {
4833: $desiredhost = undef;
4834: } else {
1.57 raeburn 4835: my %home_servers = &Apache::lonnet::get_servers($defdom,'library');
1.1 raeburn 4836: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 4837: $r->print('<p class="LC_error">'.&mt('Error').': '.
4838: &mt('Invalid home server specified').'</p>');
4839: return 'invalidhome';
1.1 raeburn 4840: }
4841: }
4842: # Determine authentication mechanism
4843: my $changeauth;
4844: if ($context eq 'domain') {
4845: $changeauth = $env{'form.changeauth'};
4846: }
4847: my $amode = '';
4848: my $genpwd = '';
1.200 raeburn 4849: my @genpwdfail;
1.1 raeburn 4850: if ($env{'form.login'} eq 'krb') {
4851: $amode='krb';
4852: $amode.=$env{'form.krbver'};
4853: $genpwd=$env{'form.krbarg'};
4854: } elsif ($env{'form.login'} eq 'int') {
4855: $amode='internal';
4856: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
4857: $genpwd=$env{'form.intarg'};
1.200 raeburn 4858: @genpwdfail =
1.202 raeburn 4859: &Apache::loncommon::check_passwd_rules($domain,$genpwd);
1.1 raeburn 4860: }
4861: } elsif ($env{'form.login'} eq 'loc') {
4862: $amode='localauth';
4863: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
4864: $genpwd=$env{'form.locarg'};
4865: }
1.194 raeburn 4866: } elsif ($env{'form.login'} eq 'lti') {
4867: $amode='lti';
1.1 raeburn 4868: }
4869: if ($amode =~ /^krb/) {
4870: if (! defined($genpwd) || $genpwd eq '') {
1.193 raeburn 4871: $r->print('<span class="Error">'.
1.1 raeburn 4872: &mt('Unable to enroll users').' '.
4873: &mt('No Kerberos domain was specified.').'</span></p>');
4874: $amode = ''; # This causes the loop below to be skipped
4875: }
4876: }
1.150 raeburn 4877: my ($defaultsec,$defaultrole,$defaultcredits,$commoncredits);
1.1 raeburn 4878: if ($context eq 'domain') {
4879: if ($setting eq 'domain') {
4880: $defaultrole = $env{'form.defaultrole'};
4881: } elsif ($setting eq 'course') {
4882: $defaultrole = $env{'form.courserole'};
1.27 raeburn 4883: $defaultsec = $env{'form.sections'};
1.150 raeburn 4884: if ($showcredits) {
4885: $commoncredits = $env{'form.credits'};
4886: if ($crstype ne 'Community') {
4887: my %coursehash=&Apache::lonnet::coursedescription($cid);
4888: $defaultcredits = $coursehash{'internal.defaultcredits'};
4889: }
4890: }
1.149 raeburn 4891: }
1.13 raeburn 4892: } elsif ($context eq 'author') {
1.1 raeburn 4893: $defaultrole = $env{'form.defaultrole'};
1.27 raeburn 4894: } elsif ($context eq 'course') {
4895: $defaultrole = $env{'form.defaultrole'};
4896: $defaultsec = $env{'form.sections'};
1.150 raeburn 4897: if ($showcredits) {
4898: $commoncredits = $env{'form.credits'};
4899: $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
4900: }
1.1 raeburn 4901: }
1.27 raeburn 4902: # Check to see if user information can be changed
4903: my @userinfo = ('firstname','middlename','lastname','generation',
4904: 'permanentemail','id');
4905: my %canmodify;
4906: if (&Apache::lonnet::allowed('mau',$domain)) {
1.84 raeburn 4907: push(@userinfo,'inststatus');
1.27 raeburn 4908: foreach my $field (@userinfo) {
4909: $canmodify{$field} = 1;
4910: }
4911: }
4912: my (%userlist,%modifiable_fields,@poss_roles);
4913: my $secidx = &Apache::loncoursedata::CL_SECTION();
1.102 raeburn 4914: my @courseroles = &roles_by_context('course',1,$crstype);
1.27 raeburn 4915: if (!&Apache::lonnet::allowed('mau',$domain)) {
4916: if ($context eq 'course' || $context eq 'author') {
1.101 raeburn 4917: @poss_roles = &curr_role_permissions($context,'','',$crstype);
1.27 raeburn 4918: my @statuses = ('active','future');
4919: my ($indexhash,$keylist) = &make_keylist_array();
4920: my %info;
4921: foreach my $role (@poss_roles) {
4922: %{$modifiable_fields{$role}} = &can_modify_userinfo($context,$domain,
4923: \@userinfo,[$role]);
4924: }
4925: if ($context eq 'course') {
4926: my ($cnum,$cdom) = &get_course_identity();
4927: my $roster = &Apache::loncoursedata::get_classlist();
1.66 raeburn 4928: if (ref($roster) eq 'HASH') {
4929: %userlist = %{$roster};
4930: }
1.27 raeburn 4931: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
4932: \@statuses,\@poss_roles);
4933: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
4934: \%advrolehash,$permission);
4935: } elsif ($context eq 'author') {
4936: my %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
4937: \@statuses,\@poss_roles);
4938: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
4939: \%cstr_roles,$permission);
4940: }
4941: }
1.1 raeburn 4942: }
1.193 raeburn 4943: if ($datatoken eq '') {
4944: $r->print('<p class="LC_error">'.&mt('Error').': '.
4945: &mt('Invalid datatoken').'</p>');
4946: return 'missingdata';
4947: }
1.1 raeburn 4948: if ( $domain eq &LONCAPA::clean_domain($domain)
4949: && ($amode ne '')) {
4950: #######################################
4951: ## Add/Modify Users ##
4952: #######################################
4953: if ($context eq 'course') {
4954: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
1.13 raeburn 4955: } elsif ($context eq 'author') {
1.1 raeburn 4956: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
4957: } else {
4958: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
4959: }
1.87 bisitz 4960: $r->rflush;
1.212 raeburn 4961: my (%got_role_approvals,%got_instdoms,%process_by,%instdoms,
1.213 raeburn 4962: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
1.87 bisitz 4963:
1.1 raeburn 4964: my %counts = (
4965: user => 0,
4966: auth => 0,
4967: role => 0,
4968: );
4969: my $flushc=0;
4970: my %student=();
1.42 raeburn 4971: my (%curr_groups,@sections,@cleansec,$defaultwarn,$groupwarn);
1.1 raeburn 4972: my %userchg;
1.27 raeburn 4973: if ($context eq 'course' || $setting eq 'course') {
4974: if ($context eq 'course') {
4975: # Get information about course groups
4976: %curr_groups = &Apache::longroup::coursegroups();
4977: } elsif ($setting eq 'course') {
4978: if ($cid) {
4979: %curr_groups =
4980: &Apache::longroup::coursegroups($env{'form.dcdomain'},
4981: $env{'form.dccourse'});
4982: }
4983: }
4984: # determine section number
4985: if ($defaultsec =~ /,/) {
4986: push(@sections,split(/,/,$defaultsec));
4987: } else {
4988: push(@sections,$defaultsec);
4989: }
4990: # remove non alphanumeric values from section
4991: foreach my $item (@sections) {
4992: $item =~ s/\W//g;
4993: if ($item eq "none" || $item eq 'all') {
4994: $defaultwarn = &mt('Default section name [_1] could not be used as it is a reserved word.',$item);
4995: } elsif ($item ne '' && exists($curr_groups{$item})) {
4996: $groupwarn = &mt('Default section name "[_1]" is the name of a course group. Section names and group names must be distinct.',$item);
4997: } elsif ($item ne '') {
4998: push(@cleansec,$item);
4999: }
5000: }
5001: if ($defaultwarn) {
5002: $r->print($defaultwarn.'<br />');
5003: }
5004: if ($groupwarn) {
5005: $r->print($groupwarn.'<br />');
5006: }
1.1 raeburn 5007: }
1.124 raeburn 5008: my (%curr_rules,%got_rules,%alerts,%cancreate);
1.104 raeburn 5009: my %customroles = &my_custom_roles($crstype);
1.101 raeburn 5010: my @permitted_roles =
1.124 raeburn 5011: &roles_on_upload($context,$setting,$crstype,%customroles);
5012: my %longtypes = &Apache::lonlocal::texthash(
5013: official => 'Institutional',
5014: unofficial => 'Non-institutional',
5015: );
1.135 raeburn 5016: my $newuserdom = $env{'request.role.domain'};
5017: map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes);
1.1 raeburn 5018: # Get new users list
1.200 raeburn 5019: my (%existinguser,%userinfo,%disallow,%rulematch,%inst_results,%alerts,%checkuname,
5020: %showpasswdrules,$haspasswdmap);
1.171 raeburn 5021: my $counter = -1;
1.185 raeburn 5022: my (%willtrust,%trustchecked);
1.27 raeburn 5023: foreach my $line (@userdata) {
1.171 raeburn 5024: $counter ++;
1.42 raeburn 5025: my @secs;
1.27 raeburn 5026: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 5027: # Determine user name
1.128 raeburn 5028: $entries{$fields{'username'}} =~ s/^\s+|\s+$//g;
1.1 raeburn 5029: unless (($entries{$fields{'username'}} eq '') ||
5030: (!defined($entries{$fields{'username'}}))) {
5031: my ($fname, $mname, $lname,$gen) = ('','','','');
5032: if (defined($fields{'names'})) {
5033: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
5034: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
5035: } else {
5036: if (defined($fields{'fname'})) {
5037: $fname=$entries{$fields{'fname'}};
5038: }
5039: if (defined($fields{'mname'})) {
5040: $mname=$entries{$fields{'mname'}};
5041: }
5042: if (defined($fields{'lname'})) {
5043: $lname=$entries{$fields{'lname'}};
5044: }
5045: if (defined($fields{'gen'})) {
5046: $gen=$entries{$fields{'gen'}};
5047: }
5048: }
1.128 raeburn 5049:
1.1 raeburn 5050: if ($entries{$fields{'username'}}
5051: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
1.128 raeburn 5052: my $nowhitespace;
5053: if ($entries{$fields{'username'}} =~ /\s/) {
5054: $nowhitespace = ' - '.&mt('usernames may not contain spaces.');
5055: }
1.171 raeburn 5056: $disallow{$counter} =
1.157 bisitz 5057: &mt('Unacceptable username [_1] for user [_2] [_3] [_4] [_5]',
1.171 raeburn 5058: '"<b>'.$entries{$fields{'username'}}.'</b>"',
5059: $fname,$mname,$lname,$gen).$nowhitespace;
1.27 raeburn 5060: next;
1.1 raeburn 5061: } else {
1.129 raeburn 5062: $entries{$fields{'domain'}} =~ s/^\s+|\s+$//g;
1.71 droeschl 5063: if ($entries{$fields{'domain'}}
1.57 raeburn 5064: ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
1.171 raeburn 5065: $disallow{$counter} =
1.157 bisitz 5066: &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
1.171 raeburn 5067: '"<b>'.$entries{$fields{'domain'}}.'</b>"',
5068: $fname,$mname,$lname,$gen);
5069: next;
1.185 raeburn 5070: } elsif ($entries{$fields{'domain'}} ne $domain) {
5071: my $possdom = $entries{$fields{'domain'}};
5072: if ($context eq 'course' || $setting eq 'course') {
5073: unless ($trustchecked{$possdom}) {
5074: $willtrust{$possdom} = &Apache::lonnet::will_trust('enroll',$domain,$possdom);
5075: $trustchecked{$possdom} = 1;
5076: }
5077: } elsif ($context eq 'author') {
5078: unless ($trustchecked{$possdom}) {
5079: $willtrust{$possdom} = &Apache::lonnet::will_trust('othcoau',$domain,$possdom);
5080: }
5081: if ($willtrust{$possdom}) {
5082: $willtrust{$possdom} = &Apache::lonnet::will_trust('coaurem',$possdom,$domain);
5083: }
5084: }
5085: unless ($willtrust{$possdom}) {
5086: $disallow{$counter} =
5087: &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
5088: '"<b>'.$possdom.'</b>"',
5089: $fname,$mname,$lname,$gen);
5090: next;
5091: }
1.57 raeburn 5092: }
1.5 raeburn 5093: my $username = $entries{$fields{'username'}};
1.57 raeburn 5094: my $userdomain = $entries{$fields{'domain'}};
5095: if ($userdomain eq '') {
5096: $userdomain = $domain;
5097: }
1.27 raeburn 5098: if (defined($fields{'sec'})) {
5099: if (defined($entries{$fields{'sec'}})) {
1.42 raeburn 5100: $entries{$fields{'sec'}} =~ s/\W//g;
1.27 raeburn 5101: my $item = $entries{$fields{'sec'}};
5102: if ($item eq "none" || $item eq 'all') {
1.171 raeburn 5103: $disallow{$counter} =
5104: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a reserved word.',
5105: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item);
1.27 raeburn 5106: next;
5107: } elsif (exists($curr_groups{$item})) {
1.171 raeburn 5108: $disallow{$counter} =
5109: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a course group.',
5110: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item).' '.
5111: &mt('Section names and group names must be distinct.');
1.27 raeburn 5112: next;
5113: } else {
5114: push(@secs,$item);
5115: }
5116: }
5117: }
5118: if ($env{'request.course.sec'} ne '') {
5119: @secs = ($env{'request.course.sec'});
1.57 raeburn 5120: if (ref($userlist{$username.':'.$userdomain}) eq 'ARRAY') {
5121: my $currsec = $userlist{$username.':'.$userdomain}[$secidx];
1.27 raeburn 5122: if ($currsec ne $env{'request.course.sec'}) {
1.171 raeburn 5123: $disallow{$counter} =
5124: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]".',
5125: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$secs[0]);
1.27 raeburn 5126: if ($currsec eq '') {
1.171 raeburn 5127: $disallow{$counter} .=
5128: &mt('This user already has an active/future student role in the course, unaffiliated to any section.');
1.27 raeburn 5129:
5130: } else {
1.171 raeburn 5131: $disallow{$counter} .=
5132: &mt('This user already has an active/future role in section "[_1]" of the course.',$currsec);
1.27 raeburn 5133: }
1.171 raeburn 5134: $disallow{$counter} .=
5135: '<br />'.
5136: &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.',
5137: $secs[0]);
1.27 raeburn 5138: next;
1.1 raeburn 5139: }
5140: }
1.27 raeburn 5141: } elsif ($context eq 'course' || $setting eq 'course') {
5142: if (@secs == 0) {
5143: @secs = @cleansec;
1.1 raeburn 5144: }
5145: }
5146: # determine id number
5147: my $id='';
5148: if (defined($fields{'id'})) {
5149: if (defined($entries{$fields{'id'}})) {
5150: $id=$entries{$fields{'id'}};
5151: }
5152: $id=~tr/A-Z/a-z/;
5153: }
5154: # determine email address
5155: my $email='';
5156: if (defined($fields{'email'})) {
1.129 raeburn 5157: $entries{$fields{'email'}} =~ s/^\s+|\s+$//g;
1.1 raeburn 5158: if (defined($entries{$fields{'email'}})) {
5159: $email=$entries{$fields{'email'}};
1.84 raeburn 5160: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
5161: }
5162: }
5163: # determine affiliation
5164: my $inststatus='';
5165: if (defined($fields{'inststatus'})) {
5166: if (defined($entries{$fields{'inststatus'}})) {
5167: $inststatus=$entries{$fields{'inststatus'}};
5168: }
1.1 raeburn 5169: }
5170: # determine user password
1.200 raeburn 5171: my $password;
5172: my $passwdfromfile;
1.1 raeburn 5173: if (defined($fields{'ipwd'})) {
5174: if ($entries{$fields{'ipwd'}}) {
5175: $password=$entries{$fields{'ipwd'}};
1.200 raeburn 5176: $passwdfromfile = 1;
5177: if ($env{'form.login'} eq 'int') {
5178: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
5179: if (($uhome eq 'no_host') || ($changeauth)) {
5180: my @brokepwdrules =
5181: &Apache::loncommon::check_passwd_rules($domain,$password);
5182: if (@brokepwdrules) {
5183: $disallow{$counter} = &mt('[_1]: Password included in file for this user did not meet requirements.',
5184: '<b>'.$username.'</b>');
5185: map { $showpasswdrules{$_} = 1; } @brokepwdrules;
5186: next;
5187: }
5188: }
5189: }
5190: }
5191: }
5192: unless ($passwdfromfile) {
5193: if ($env{'form.login'} eq 'int') {
5194: if (@genpwdfail) {
5195: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
5196: if (($uhome eq 'no_host') || ($changeauth)) {
5197: $disallow{$counter} = &mt('[_1]: No specific password in file for this user; default password did not meet requirements',
5198: '<b>'.$username.'</b>');
5199: unless ($haspasswdmap) {
5200: map { $showpasswdrules{$_} = 1; } @genpwdfail;
5201: $haspasswdmap = 1;
5202: }
5203: }
5204: next;
5205: }
1.1 raeburn 5206: }
1.200 raeburn 5207: $password = $genpwd;
1.1 raeburn 5208: }
5209: # determine user role
5210: my $role = '';
5211: if (defined($fields{'role'})) {
5212: if ($entries{$fields{'role'}}) {
1.42 raeburn 5213: $entries{$fields{'role'}} =~ s/(\s+$|^\s+)//g;
5214: if ($entries{$fields{'role'}} ne '') {
5215: if (grep(/^\Q$entries{$fields{'role'}}\E$/,@permitted_roles)) {
5216: $role = $entries{$fields{'role'}};
1.27 raeburn 5217: }
5218: }
5219: if ($role eq '') {
5220: my $rolestr = join(', ',@permitted_roles);
1.171 raeburn 5221: $disallow{$counter} =
5222: &mt('[_1]: You do not have permission to add the requested role [_2] for the user.'
5223: ,'<b>'.$entries{$fields{'username'}}.'</b>'
5224: ,$entries{$fields{'role'}})
5225: .'<br />'
5226: .&mt('Allowable role(s) is/are: [_1].',$rolestr);
1.1 raeburn 5227: next;
5228: }
5229: }
5230: }
5231: if ($role eq '') {
5232: $role = $defaultrole;
5233: }
5234: # Clean up whitespace
1.129 raeburn 5235: foreach (\$id,\$fname,\$mname,\$lname,\$gen,\$inststatus) {
1.1 raeburn 5236: $$_ =~ s/(\s+$|^\s+)//g;
5237: }
1.150 raeburn 5238: my $credits;
5239: if ($showcredits) {
5240: if (($role eq 'st') && ($crstype ne 'Community')) {
5241: $credits = $entries{$fields{'credits'}};
5242: if ($credits ne '') {
5243: $credits =~ s/[^\d\.]//g;
5244: }
5245: if ($credits eq '') {
5246: $credits = $commoncredits;
5247: }
5248: if ($credits eq $defaultcredits) {
5249: undef($credits);
5250: }
5251: }
5252: }
1.5 raeburn 5253: # check against rules
5254: my $checkid = 0;
5255: my $newuser = 0;
1.57 raeburn 5256: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
1.5 raeburn 5257: if ($uhome eq 'no_host') {
1.135 raeburn 5258: if ($userdomain ne $newuserdom) {
5259: if ($context eq 'course') {
1.171 raeburn 5260: $disallow{$counter} =
5261: &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
5262: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 5263: } elsif ($context eq 'author') {
1.171 raeburn 5264: $disallow{$counter} =
5265: &mt('[_1]: The domain specified ([_2]) is different to that of the author.',
5266: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 5267: } else {
1.171 raeburn 5268: $disallow{$counter} =
5269: &mt('[_1]: The domain specified ([_2]) is different to that of your current role.',
5270: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 5271: }
1.171 raeburn 5272: $disallow{$counter} .=
5273: &mt('The user does not already exist, and you may not create a new user in a different domain.');
1.124 raeburn 5274: next;
1.171 raeburn 5275: } else {
1.194 raeburn 5276: unless (($password ne '') || ($env{'form.login'} eq 'loc') || ($env{'form.login'} eq 'lti')) {
1.171 raeburn 5277: $disallow{$counter} =
5278: &mt('[_1]: This is a new user but no default password was provided, and the authentication type requires one.',
5279: '<b>'.$username.'</b>');
5280: next;
5281: }
1.124 raeburn 5282: }
1.5 raeburn 5283: $checkid = 1;
5284: $newuser = 1;
1.172 raeburn 5285: $checkuname{$username.':'.$newuserdom} = { 'newuser' => $newuser, 'id' => $id };
1.13 raeburn 5286: } else {
1.27 raeburn 5287: if ($context eq 'course' || $context eq 'author') {
1.57 raeburn 5288: if ($userdomain eq $domain ) {
5289: if ($role eq '') {
5290: my @checkroles;
5291: foreach my $role (@poss_roles) {
5292: my $endkey;
5293: if ($role ne 'st') {
5294: $endkey = ':'.$role;
5295: }
5296: if (exists($userlist{$username.':'.$userdomain.$endkey})) {
5297: if (!grep(/^\Q$role\E$/,@checkroles)) {
5298: push(@checkroles,$role);
5299: }
5300: }
1.27 raeburn 5301: }
1.57 raeburn 5302: if (@checkroles > 0) {
5303: %canmodify = &can_modify_userinfo($context,$domain,\@userinfo,\@checkroles);
1.27 raeburn 5304: }
1.57 raeburn 5305: } elsif (ref($modifiable_fields{$role}) eq 'HASH') {
5306: %canmodify = %{$modifiable_fields{$role}};
1.27 raeburn 5307: }
5308: }
1.57 raeburn 5309: my @newinfo = (\$fname,\$mname,\$lname,\$gen,\$email,\$id);
1.84 raeburn 5310: for (my $i=0; $i<@newinfo; $i++) {
1.57 raeburn 5311: if (${$newinfo[$i]} ne '') {
5312: if (!$canmodify{$userinfo[$i]}) {
5313: ${$newinfo[$i]} = '';
5314: }
1.27 raeburn 5315: }
5316: }
5317: }
1.171 raeburn 5318: if ($id) {
5319: $existinguser{$userdomain}{$username} = $id;
5320: }
1.5 raeburn 5321: }
1.171 raeburn 5322: $userinfo{$counter} = {
5323: username => $username,
5324: domain => $userdomain,
5325: fname => $fname,
5326: mname => $mname,
5327: lname => $lname,
5328: gen => $gen,
5329: email => $email,
5330: id => $id,
5331: password => $password,
5332: inststatus => $inststatus,
5333: role => $role,
5334: sections => \@secs,
5335: credits => $credits,
5336: newuser => $newuser,
5337: checkid => $checkid,
5338: };
5339: }
5340: }
5341: } # end of foreach (@userdata)
5342: if ($counter > -1) {
5343: my $total = $counter + 1;
5344: my %checkids;
1.172 raeburn 5345: if ((keys(%existinguser)) || (keys(%checkuname))) {
5346: $r->print(&mt('Please be patient -- checking for institutional data ...'));
5347: $r->rflush();
5348: if (keys(%existinguser)) {
5349: foreach my $dom (keys(%existinguser)) {
5350: if (ref($existinguser{$dom}) eq 'HASH') {
5351: my %idhash = &Apache::lonnet::idrget($dom,keys(%{$existinguser{$dom}}));
5352: foreach my $username (keys(%{$existinguser{$dom}})) {
5353: if ($idhash{$username} ne $existinguser{$dom}{$username}) {
5354: $checkids{$username.':'.$dom} = {
5355: 'id' => $existinguser{$dom}{$username},
5356: };
5357: }
5358: }
5359: if (keys(%checkids)) {
5360: &Apache::loncommon::user_rule_check(\%checkids,{ 'id' => 1 },
5361: \%alerts,\%rulematch,
5362: \%inst_results,\%curr_rules,
5363: \%got_rules);
1.171 raeburn 5364: }
5365: }
5366: }
5367: }
1.172 raeburn 5368: if (keys(%checkuname)) {
5369: &Apache::loncommon::user_rule_check(\%checkuname,{ 'username' => 1, 'id' => 1, },
5370: \%alerts,\%rulematch,\%inst_results,
5371: \%curr_rules,\%got_rules);
5372: }
5373: $r->print(' '.&mt('done').'<br /><br />');
5374: $r->rflush();
1.171 raeburn 5375: }
1.172 raeburn 5376: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,$total);
1.171 raeburn 5377: $r->print('<ul>');
5378: for (my $i=0; $i<=$counter; $i++) {
5379: if ($disallow{$i}) {
5380: $r->print('<li>'.$disallow{$i}.'</li>');
5381: } elsif (ref($userinfo{$i}) eq 'HASH') {
5382: my $password = $userinfo{$i}{'password'};
5383: my $newuser = $userinfo{$i}{'newuser'};
5384: my $checkid = $userinfo{$i}{'checkid'};
5385: my $id = $userinfo{$i}{'id'};
5386: my $role = $userinfo{$i}{'role'};
5387: my @secs;
5388: if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
5389: @secs = @{$userinfo{$i}{'sections'}};
5390: }
5391: my $fname = $userinfo{$i}{'fname'};
5392: my $mname = $userinfo{$i}{'mname'};
5393: my $lname = $userinfo{$i}{'lname'};
5394: my $gen = $userinfo{$i}{'gen'};
5395: my $email = $userinfo{$i}{'email'};
5396: my $inststatus = $userinfo{$i}{'inststatus'};
5397: my $credits = $userinfo{$i}{'credits'};
5398: my $username = $userinfo{$i}{'username'};
5399: my $userdomain = $userinfo{$i}{'domain'};
5400: my $user = $username.':'.$userdomain;
5401: if ($newuser) {
5402: if (ref($alerts{'username'}) eq 'HASH') {
5403: if (ref($alerts{'username'}{$userdomain}) eq 'HASH') {
5404: if ($alerts{'username'}{$userdomain}{$username}) {
5405: $r->print('<li>'.
5406: &mt('[_1]: matches the username format at your institution, but is not known to your directory service.','<b>'.$username.'</b>').'<br />'.
5407: &mt('Consequently, the user was not created.').'</li>');
5408: next;
5409: }
5410: }
5411: }
1.172 raeburn 5412: if (ref($inst_results{$user}) eq 'HASH') {
5413: if ($inst_results{$user}{'firstname'} ne '') {
5414: $fname = $inst_results{$user}{'firstname'};
5415: }
5416: if ($inst_results{$user}{'middlename'} ne '') {
5417: $mname = $inst_results{$user}{'middlename'};
5418: }
5419: if ($inst_results{$user}{'lasttname'} ne '') {
5420: $lname = $inst_results{$user}{'lastname'};
5421: }
5422: if ($inst_results{$user}{'permanentemail'} ne '') {
5423: $email = $inst_results{$user}{'permanentemail'};
5424: }
5425: if ($inst_results{$user}{'id'} ne '') {
5426: $id = $inst_results{$user}{'id'};
5427: $checkid = 0;
5428: }
5429: if (ref($inst_results{$user}{'inststatus'}) eq 'ARRAY') {
5430: $inststatus = join(':',@{$inst_results{$user}{'inststatus'}});
5431: }
5432: }
5433: if (($checkid) && ($id ne '')) {
5434: if (ref($alerts{'id'}) eq 'HASH') {
5435: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
5436: if ($alerts{'id'}{$userdomain}{$username}) {
5437: $r->print('<li>'.
5438: &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
5439: '<b>'.$username.'</b>').'<br />'.
5440: &mt('Consequently, the user was not created.').'</li>');
5441: next;
5442: }
5443: }
5444: }
5445: }
1.171 raeburn 5446: my $usertype = 'unofficial';
5447: if (ref($rulematch{$user}) eq 'HASH') {
5448: if ($rulematch{$user}{'username'}) {
5449: $usertype = 'official';
1.5 raeburn 5450: }
5451: }
1.171 raeburn 5452: unless ($cancreate{$usertype}) {
5453: my $showtype = $longtypes{$usertype};
5454: $r->print('<li>'.
5455: &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].','<b>'.$username.'</b>',$showtype).'</li>');
5456: next;
5457: }
1.172 raeburn 5458: } elsif ($id ne '') {
1.171 raeburn 5459: if (exists($checkids{$user})) {
5460: $checkid = 1;
1.5 raeburn 5461: if (ref($alerts{'id'}) eq 'HASH') {
1.57 raeburn 5462: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
1.172 raeburn 5463: if ($alerts{'id'}{$userdomain}{$username}) {
1.171 raeburn 5464: $r->print('<li>'.
1.172 raeburn 5465: &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 5466: '<b>'.$username.'</b>').'<br />'.
1.172 raeburn 5467: &mt('Consequently, the ID was not changed.').'</li>');
5468: $id = '';
1.124 raeburn 5469: }
1.5 raeburn 5470: }
5471: }
5472: }
5473: }
1.171 raeburn 5474: my $multiple = 0;
5475: my ($userresult,$authresult,$roleresult,$idresult);
5476: my (%userres,%authres,%roleres,%idres);
5477: my $singlesec = '';
5478: if ($role eq 'st') {
1.206 raeburn 5479: if (($context eq 'domain') && ($changeauth eq 'Yes') && (!$newuser)) {
5480: if ((&Apache::lonnet::allowed('mau',$userdomain)) &&
5481: (&Apache::lonnet::homeserver($username,$userdomain) ne 'no_host')) {
5482: if ((($amode =~ /^krb4|krb5|internal$/) && $password ne '') ||
5483: ($amode eq 'localauth')) {
5484: $authresult =
5485: &Apache::lonnet::modifyuserauth($userdomain,$username,$amode,$password);
5486: }
5487: }
5488: }
1.171 raeburn 5489: my $sec;
5490: if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
1.42 raeburn 5491: if (@secs > 0) {
5492: $sec = $secs[0];
1.27 raeburn 5493: }
1.171 raeburn 5494: }
1.212 raeburn 5495: if ($userdomain ne $env{'request.role.domain'}) {
5496: my $item = "/$crsdom/$crsnum" ;
5497: if ($sec ne '') {
5498: $item .= "/$sec";
5499: }
5500: $item .= '_st';
5501: next if (&restricted_dom($context,$item,$userdomain,$username,$role,$startdate,
5502: $enddate,$crsdom,$crsnum,$sec,$credits,\%process_by,
5503: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.213 raeburn 5504: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.212 raeburn 5505: }
1.171 raeburn 5506: &modifystudent($userdomain,$username,$cid,$sec,
5507: $desiredhost,$context);
5508: $roleresult =
5509: &Apache::lonnet::modifystudent
5510: ($userdomain,$username,$id,$amode,$password,
5511: $fname,$mname,$lname,$gen,$sec,$enddate,
5512: $startdate,$env{'form.forceid'},
5513: $desiredhost,$email,'manual','',$cid,
5514: '',$context,$inststatus,$credits);
5515: $userresult = $roleresult;
5516: } else {
1.212 raeburn 5517: my $possrole;
5518: if ($role ne '') {
1.171 raeburn 5519: if ($context eq 'course' || $setting eq 'course') {
5520: if ($customroles{$role}) {
5521: $role = 'cr_'.$env{'user.domain'}.'_'.
5522: $env{'user.name'}.'_'.$role;
5523: }
1.212 raeburn 5524: $possrole = $role;
5525: if ($possrole =~ /^cr_/) {
5526: $possrole =~ s{_}{/}g;
5527: }
5528: if (($role ne 'cc') && ($role ne 'co')) {
1.171 raeburn 5529: if (@secs > 1) {
5530: $multiple = 1;
1.212 raeburn 5531: my $prefix = "/$crsdom/$crsnum";
1.171 raeburn 5532: foreach my $sec (@secs) {
1.212 raeburn 5533: if ($userdomain ne $env{'request.role.domain'}) {
5534: my $item = $prefix;
5535: if ($sec ne '') {
5536: $item .= "/$sec";
5537: }
5538: $item .= '_'.$possrole;
5539: next if (&restricted_dom($context,$item,$userdomain,$username,$possrole,
5540: $startdate,$enddate,$crsdom,$crsnum,$sec,
5541: $credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 5542: \%got_instdoms,\%reject,\%pending,\%notifydc,
5543: \%status,\%unauthorized,\%currqueued));
1.212 raeburn 5544: }
1.171 raeburn 5545: ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
5546: &modifyuserrole($context,$setting,
5547: $changeauth,$cid,$userdomain,$username,
5548: $id,$amode,$password,$fname,
5549: $mname,$lname,$gen,$sec,
5550: $env{'form.forceid'},$desiredhost,
5551: $email,$role,$enddate,
5552: $startdate,$checkid,$inststatus);
1.42 raeburn 5553: }
1.171 raeburn 5554: } elsif (@secs > 0) {
5555: $singlesec = $secs[0];
1.27 raeburn 5556: }
5557: }
1.212 raeburn 5558: } else {
5559: $possrole = $role;
1.27 raeburn 5560: }
1.204 raeburn 5561: }
5562: if (!$multiple) {
1.212 raeburn 5563: if (($userdomain ne $env{'request.role.domain'}) && ($role ne '')) {
5564: my $item = "/$crsdom/$crsnum";
5565: if ($singlesec ne '') {
5566: $item .= "/$singlesec";
5567: }
5568: $item .= '_'.$possrole;
5569: next if (&restricted_dom($context,$item,$userdomain,$username,$possrole,$startdate,$enddate,
5570: $crsdom,$crsnum,$singlesec,$credits,\%process_by,\%instdoms,
1.213 raeburn 5571: \%got_role_approvals,\%got_instdoms,\%reject,\%pending,\%notifydc,
5572: \%status,\%unauthorized,\%currqueued));
1.212 raeburn 5573: }
1.204 raeburn 5574: ($userresult,$authresult,$roleresult,$idresult) =
5575: &modifyuserrole($context,$setting,
5576: $changeauth,$cid,$userdomain,$username,
5577: $id,$amode,$password,$fname,
5578: $mname,$lname,$gen,$singlesec,
5579: $env{'form.forceid'},$desiredhost,
5580: $email,$role,$enddate,$startdate,
5581: $checkid,$inststatus);
1.27 raeburn 5582: }
1.171 raeburn 5583: }
5584: if ($multiple) {
5585: foreach my $sec (sort(keys(%userres))) {
5586: $flushc =
1.27 raeburn 5587: &user_change_result($r,$userres{$sec},$authres{$sec},
5588: $roleres{$sec},$idres{$sec},\%counts,$flushc,
1.57 raeburn 5589: $username,$userdomain,\%userchg);
1.27 raeburn 5590:
1.1 raeburn 5591: }
5592: } else {
1.171 raeburn 5593: $flushc =
5594: &user_change_result($r,$userresult,$authresult,
5595: $roleresult,$idresult,\%counts,$flushc,
5596: $username,$userdomain,\%userchg);
1.1 raeburn 5597: }
5598: }
1.172 raeburn 5599: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last user');
1.171 raeburn 5600: } # end of loop
1.172 raeburn 5601: $r->print('</ul>');
1.171 raeburn 5602: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.217 raeburn 5603: if (($context eq 'domain') && ($setting eq 'course')) {
5604: unless ($oldcrsuserdoms) {
5605: if (exists($env{'course.'.$cid.'.internal.userdomains'})) {
5606: delete($env{'course.'.$cid.'.internal.userdomains'});
5607: }
5608: }
5609: }
1.171 raeburn 5610: }
1.1 raeburn 5611: # Flush the course logs so reverse user roles immediately updated
1.126 raeburn 5612: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.29 raeburn 5613: $r->print("</p>\n<p>\n".&mt('Processed [quant,_1,user].',$counts{'user'}).
1.1 raeburn 5614: "</p>\n");
5615: if ($counts{'role'} > 0) {
5616: $r->print("<p>\n".
1.192 raeburn 5617: &mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.
5618: &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.').
5619: "</p>\n");
1.29 raeburn 5620: } else {
5621: $r->print('<p>'.&mt('No roles added').'</p>');
1.1 raeburn 5622: }
5623: if ($counts{'auth'} > 0) {
5624: $r->print("<p>\n".
5625: &mt('Authentication changed for [_1] existing users.',
5626: $counts{'auth'})."</p>\n");
5627: }
1.13 raeburn 5628: $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
1.200 raeburn 5629: $r->print(&passwdrule_alerts($domain,\%showpasswdrules));
1.213 raeburn 5630: if ((keys(%reject)) || (keys(%unauthorized))) {
5631: $r->print(&print_roles_rejected($context,\%reject,\%unauthorized));
1.212 raeburn 5632: }
1.213 raeburn 5633: if ((keys(%pending)) || (keys(%currqueued))) {
5634: $r->print(&print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.212 raeburn 5635: }
1.1 raeburn 5636: #####################################
1.29 raeburn 5637: # Display list of students to drop #
1.1 raeburn 5638: #####################################
5639: if ($env{'form.fullup'} eq 'yes') {
1.29 raeburn 5640: $r->print('<h3>'.&mt('Students to Drop')."</h3>\n");
1.1 raeburn 5641: # Get current classlist
1.30 raeburn 5642: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 5643: if (! defined($classlist)) {
1.192 raeburn 5644: $r->print('<p class="LC_info">'.
5645: &mt('There are no students with current/future access to the course.').
5646: '</p>'."\n");
1.66 raeburn 5647: } elsif (ref($classlist) eq 'HASH') {
1.1 raeburn 5648: # Remove the students we just added from the list of students.
1.30 raeburn 5649: foreach my $line (@userdata) {
5650: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 5651: unless (($entries{$fields{'username'}} eq '') ||
5652: (!defined($entries{$fields{'username'}}))) {
5653: delete($classlist->{$entries{$fields{'username'}}.
5654: ':'.$domain});
5655: }
5656: }
5657: # Print out list of dropped students.
1.30 raeburn 5658: &show_drop_list($r,$classlist,'nosort',$permission);
1.1 raeburn 5659: }
5660: }
5661: } # end of unless
1.193 raeburn 5662: return 'ok';
1.1 raeburn 5663: }
5664:
1.13 raeburn 5665: sub print_namespacing_alerts {
5666: my ($domain,$alerts,$curr_rules) = @_;
5667: my $output;
5668: if (ref($alerts) eq 'HASH') {
5669: if (keys(%{$alerts}) > 0) {
5670: if (ref($alerts->{'username'}) eq 'HASH') {
5671: foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
5672: my $count;
5673: if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
5674: $count = keys(%{$alerts->{'username'}{$dom}});
5675: }
5676: my $domdesc = &Apache::lonnet::domain($domain,'description');
5677: if (ref($curr_rules->{$dom}) eq 'HASH') {
5678: $output .= &Apache::loncommon::instrule_disallow_msg(
5679: 'username',$domdesc,$count,'upload');
5680: }
5681: $output .= &Apache::loncommon::user_rule_formats($dom,
5682: $domdesc,$curr_rules->{$dom}{'username'},
5683: 'username');
5684: }
5685: }
5686: if (ref($alerts->{'id'}) eq 'HASH') {
5687: foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
5688: my $count;
5689: if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
5690: $count = keys(%{$alerts->{'id'}{$dom}});
5691: }
5692: my $domdesc = &Apache::lonnet::domain($domain,'description');
5693: if (ref($curr_rules->{$dom}) eq 'HASH') {
5694: $output .= &Apache::loncommon::instrule_disallow_msg(
5695: 'id',$domdesc,$count,'upload');
5696: }
5697: $output .= &Apache::loncommon::user_rule_formats($dom,
5698: $domdesc,$curr_rules->{$dom}{'id'},'id');
5699: }
5700: }
5701: }
5702: }
5703: }
5704:
1.200 raeburn 5705: sub passwdrule_alerts {
5706: my ($domain,$passwdrules) = @_;
5707: my $warning;
5708: if (ref($passwdrules) eq 'HASH') {
5709: my %showrules = %{$passwdrules};
5710: if (keys(%showrules)) {
5711: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
5712: $warning = '<b>'.&mt('Password requirement(s) unmet for one or more users:').'</b><ul>';
5713: if ($showrules{'min'}) {
1.208 raeburn 5714: my $min = $passwdconf{'min'};
5715: if ($min eq '') {
5716: $min = $Apache::lonnet::passwdmin;
5717: }
5718: $warning .= '<li>'.&mt('minimum [quant,_1,character]',$min).'</li>';
1.200 raeburn 5719: }
5720: if ($showrules{'max'}) {
5721: $warning .= '<li>'.&mt('maximum [quant,_1,character]',$passwdconf{'max'}).'</li>';
5722: }
5723: if ($showrules{'uc'}) {
5724: $warning .= '<li>'.&mt('contain at least one upper case letter').'</li>';
5725: }
5726: if ($showrules{'lc'}) {
5727: $warning .= '<li>'.&mt('contain at least one lower case letter').'</li>';
5728: }
5729: if ($showrules{'num'}) {
5730: $warning .= '<li>'.&mt('contain at least one number').'</li>';
5731: }
5732: if ($showrules{'spec'}) {
5733: $warning .= '<li>'.&mt('contain at least one non-alphanumeric').'</li>';
5734: }
5735: $warning .= '</ul>';
5736: }
5737: }
5738: return $warning;
5739: }
5740:
1.1 raeburn 5741: sub user_change_result {
1.29 raeburn 5742: my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
1.57 raeburn 5743: $username,$userdomain,$userchg) = @_;
1.1 raeburn 5744: my $okresult = 0;
1.171 raeburn 5745: my @status;
1.1 raeburn 5746: if ($userresult ne 'ok') {
5747: if ($userresult =~ /^error:(.+)$/) {
5748: my $error = $1;
1.171 raeburn 5749: push(@status,
5750: &mt('[_1]: Unable to add/modify: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5751: }
5752: } else {
5753: $counts->{'user'} ++;
5754: $okresult = 1;
5755: }
5756: if ($authresult ne 'ok') {
5757: if ($authresult =~ /^error:(.+)$/) {
5758: my $error = $1;
1.171 raeburn 5759: push(@status,
5760: &mt('[_1]: Unable to modify authentication: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5761: }
5762: } else {
5763: $counts->{'auth'} ++;
5764: $okresult = 1;
5765: }
5766: if ($roleresult ne 'ok') {
5767: if ($roleresult =~ /^error:(.+)$/) {
5768: my $error = $1;
1.171 raeburn 5769: push(@status,
5770: &mt('[_1]: Unable to add role: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5771: }
5772: } else {
5773: $counts->{'role'} ++;
5774: $okresult = 1;
5775: }
5776: if ($okresult) {
5777: $flushc++;
1.57 raeburn 5778: $userchg->{$username.':'.$userdomain}=1;
1.1 raeburn 5779: if ($flushc>15) {
5780: $r->rflush;
5781: $flushc=0;
5782: }
5783: }
1.29 raeburn 5784: if ($idresult) {
1.171 raeburn 5785: push(@status,$idresult);
5786: }
5787: if (@status) {
5788: $r->print('<li>'.join('<br />',@status).'</li>');
1.29 raeburn 5789: }
1.1 raeburn 5790: return $flushc;
5791: }
5792:
5793: # ========================================================= Menu Phase Two Drop
1.17 raeburn 5794: sub print_drop_menu {
1.101 raeburn 5795: my ($r,$context,$permission,$crstype) = @_;
5796: my $heading;
5797: if ($crstype eq 'Community') {
5798: $heading = &mt("Drop Members");
5799: } else {
5800: $heading = &mt("Drop Students");
5801: }
5802: $r->print('<h3>'.$heading.'</h3>'."\n".
1.153 bisitz 5803: '<form name="studentform" method="post" action="">'."\n");
1.30 raeburn 5804: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 5805: if (! defined($classlist)) {
1.143 bisitz 5806: my $msg = '';
1.101 raeburn 5807: if ($crstype eq 'Community') {
1.143 bisitz 5808: $msg = &mt('There are no members currently enrolled.');
1.101 raeburn 5809: } else {
1.143 bisitz 5810: $msg = &mt('There are no students currently enrolled.');
1.101 raeburn 5811: }
1.143 bisitz 5812: $r->print('<p class="LC_info">'.$msg."</p>\n");
1.30 raeburn 5813: } else {
1.101 raeburn 5814: &show_drop_list($r,$classlist,'nosort',$permission,$crstype);
1.1 raeburn 5815: }
1.162 bisitz 5816: $r->print('</form>');
1.1 raeburn 5817: return;
5818: }
5819:
5820: # ================================================================== Phase four
5821:
1.11 raeburn 5822: sub update_user_list {
1.118 raeburn 5823: my ($r,$context,$setting,$choice,$crstype) = @_;
1.11 raeburn 5824: my $now = time;
1.1 raeburn 5825: my $count=0;
1.101 raeburn 5826: if ($context eq 'course') {
5827: $crstype = &Apache::loncommon::course_type();
5828: }
1.212 raeburn 5829: my (@changelist,%got_role_approvals,%got_instdoms,%process_by,%instdoms,
1.213 raeburn 5830: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
1.29 raeburn 5831: if ($choice eq 'drop') {
5832: @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
5833: } else {
1.11 raeburn 5834: @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
5835: }
5836: my %result_text = ( ok => { 'revoke' => 'Revoked',
5837: 'delete' => 'Deleted',
5838: 'reenable' => 'Re-enabled',
1.17 raeburn 5839: 'activate' => 'Activated',
5840: 'chgdates' => 'Changed Access Dates for',
1.118 raeburn 5841: 'chgsec' => 'Changed section(s) for',
1.17 raeburn 5842: 'drop' => 'Dropped',
1.11 raeburn 5843: },
5844: error => {'revoke' => 'revoking',
5845: 'delete' => 'deleting',
5846: 'reenable' => 're-enabling',
5847: 'activate' => 'activating',
1.17 raeburn 5848: 'chgdates' => 'changing access dates for',
5849: 'chgsec' => 'changing section for',
5850: 'drop' => 'dropping',
1.11 raeburn 5851: },
5852: );
5853: my ($startdate,$enddate);
5854: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
5855: ($startdate,$enddate) = &get_dates_from_form();
5856: }
5857: foreach my $item (@changelist) {
1.118 raeburn 5858: my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,
5859: @sections,$scopestem,$singlesec,$showsecs,$warn_singlesec,
1.212 raeburn 5860: $nothingtodo,$keepnosection,$credits,$instsec,$cdom,$cnum);
1.17 raeburn 5861: if ($choice eq 'drop') {
5862: ($uname,$udom,$sec) = split(/:/,$item,-1);
5863: $role = 'st';
5864: $cid = $env{'request.course.id'};
5865: $scopestem = '/'.$cid;
5866: $scopestem =~s/\_/\//g;
5867: if ($sec eq '') {
5868: $scope = $scopestem;
5869: } else {
5870: $scope = $scopestem.'/'.$sec;
5871: }
5872: } elsif ($context eq 'course') {
1.174 raeburn 5873: ($uname,$udom,$role,$sec,$type,$locktype,$credits,$instsec) =
5874: split(/\:/,$item,8);
5875: $instsec = &unescape($instsec);
1.11 raeburn 5876: $cid = $env{'request.course.id'};
1.212 raeburn 5877: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5878: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.11 raeburn 5879: $scopestem = '/'.$cid;
5880: $scopestem =~s/\_/\//g;
5881: if ($sec eq '') {
5882: $scope = $scopestem;
5883: } else {
5884: $scope = $scopestem.'/'.$sec;
5885: }
1.13 raeburn 5886: } elsif ($context eq 'author') {
1.11 raeburn 5887: ($uname,$udom,$role) = split(/\:/,$item,-1);
5888: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
1.212 raeburn 5889: $cdom = $env{'user.domain'};
5890: $cnum = $env{'user.name'};
1.11 raeburn 5891: } elsif ($context eq 'domain') {
5892: if ($setting eq 'domain') {
5893: ($role,$uname,$udom) = split(/\:/,$item,-1);
5894: $scope = '/'.$env{'request.role.domain'}.'/';
1.212 raeburn 5895: $cdom = $env{'request.role.domain'};
1.13 raeburn 5896: } elsif ($setting eq 'author') {
1.11 raeburn 5897: ($uname,$udom,$role,$scope) = split(/\:/,$item);
1.212 raeburn 5898: (undef,$cdom,$cnum) = split(/\//,$scope);
1.11 raeburn 5899: } elsif ($setting eq 'course') {
1.174 raeburn 5900: ($uname,$udom,$role,$cid,$sec,$type,$locktype,$credits,$instsec) =
5901: split(/\:/,$item,9);
1.212 raeburn 5902: ($cdom,$cnum) = split('_',$cid);
1.174 raeburn 5903: $instsec = &unescape($instsec);
1.11 raeburn 5904: $scope = '/'.$cid;
5905: $scope =~s/\_/\//g;
5906: if ($sec ne '') {
5907: $scope .= '/'.$sec;
5908: }
5909: }
5910: }
1.101 raeburn 5911: my $plrole = &Apache::lonnet::plaintext($role,$crstype);
1.11 raeburn 5912: my $start = $env{'form.'.$item.'_start'};
5913: my $end = $env{'form.'.$item.'_end'};
1.17 raeburn 5914: if ($choice eq 'drop') {
5915: # drop students
5916: $end = $now;
5917: $type = 'manual';
5918: $result =
1.52 raeburn 5919: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.17 raeburn 5920: } elsif ($choice eq 'revoke') {
5921: # revoke or delete user role
1.11 raeburn 5922: $end = $now;
5923: if ($role eq 'st') {
5924: $result =
1.174 raeburn 5925: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.11 raeburn 5926: } else {
5927: $result =
1.52 raeburn 5928: &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
5929: '','',$context);
1.11 raeburn 5930: }
5931: } elsif ($choice eq 'delete') {
5932: if ($role eq 'st') {
1.174 raeburn 5933: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.29 raeburn 5934: }
5935: $result =
5936: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
1.52 raeburn 5937: $start,1,'',$context);
1.11 raeburn 5938: } else {
5939: #reenable, activate, change access dates or change section
5940: if ($choice ne 'chgsec') {
5941: $start = $startdate;
5942: $end = $enddate;
5943: }
1.212 raeburn 5944: my $id = $scope.'_'.$role;
1.11 raeburn 5945: if ($choice eq 'reenable') {
1.212 raeburn 5946: next if (&restricted_dom($context,$id,$udom,$uname,$role,$now,$end,$cdom,$cnum,
5947: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 5948: \%got_instdoms,\%reject,\%pending,\%notifydc,
5949: \%status,\%unauthorized,\%currqueued));
1.11 raeburn 5950: if ($role eq 'st') {
1.174 raeburn 5951: $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 5952: } else {
5953: $result =
5954: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 5955: $now,'','',$context);
1.11 raeburn 5956: }
5957: } elsif ($choice eq 'activate') {
1.212 raeburn 5958: next if (&restricted_dom($context,$id,$udom,$uname,$role,$now,$end,$cdom,$cnum,
5959: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 5960: \%got_instdoms,\%reject,\%pending,\%notifydc,
5961: \%status,\%unauthorized,\%currqueued));
1.11 raeburn 5962: if ($role eq 'st') {
1.174 raeburn 5963: $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 5964: } else {
5965: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 5966: $now,'','',$context);
1.11 raeburn 5967: }
5968: } elsif ($choice eq 'chgdates') {
1.212 raeburn 5969: next if (&restricted_dom($context,$id,$udom,$uname,$role,$start,$end,$cdom,$cnum,
5970: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 5971: \%got_instdoms,\%reject,\%pending,\%notifydc,
5972: \%status,\%unauthorized,\%currqueued));
1.11 raeburn 5973: if ($role eq 'st') {
1.174 raeburn 5974: $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 5975: } else {
5976: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 5977: $start,'','',$context);
1.11 raeburn 5978: }
5979: } elsif ($choice eq 'chgsec') {
5980: my (@newsecs,$revresult,$nochg,@retained);
1.103 raeburn 5981: if (($role ne 'cc') && ($role ne 'co')) {
1.117 raeburn 5982: my @secs = sort(split(/,/,$env{'form.newsecs'}));
5983: if (@secs) {
5984: my %curr_groups = &Apache::longroup::coursegroups();
5985: foreach my $sec (@secs) {
5986: next if (($sec =~ /\W/) || ($sec eq 'none') ||
5987: (exists($curr_groups{$sec})));
5988: push(@newsecs,$sec);
5989: }
5990: }
1.11 raeburn 5991: }
5992: # remove existing section if not to be retained.
1.118 raeburn 5993: if (!$env{'form.retainsec'} || ($role eq 'st')) {
1.11 raeburn 5994: if ($sec eq '') {
5995: if (@newsecs == 0) {
1.118 raeburn 5996: $result = 'ok';
1.11 raeburn 5997: $nochg = 1;
1.118 raeburn 5998: $nothingtodo = 1;
1.40 raeburn 5999: } else {
6000: $revresult =
6001: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 6002: $scope,$role,
6003: '','',$context);
1.40 raeburn 6004: }
1.11 raeburn 6005: } else {
1.28 raeburn 6006: if (@newsecs > 0) {
6007: if (grep(/^\Q$sec\E$/,@newsecs)) {
6008: push(@retained,$sec);
6009: } else {
6010: $revresult =
6011: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 6012: $scope,$role,
6013: '','',$context);
1.28 raeburn 6014: }
6015: } else {
1.11 raeburn 6016: $revresult =
1.28 raeburn 6017: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 6018: $scope,$role,
6019: '','',$context);
1.11 raeburn 6020: }
6021: }
6022: } else {
1.28 raeburn 6023: if ($sec eq '') {
6024: $nochg = 1;
1.118 raeburn 6025: $keepnosection = 1;
6026: } else {
1.28 raeburn 6027: push(@retained,$sec);
6028: }
1.11 raeburn 6029: }
6030: # add new sections
1.118 raeburn 6031: my (@diffs,@shownew);
6032: if (@retained) {
6033: @diffs = &Apache::loncommon::compare_arrays(\@retained,\@newsecs);
6034: } else {
6035: @diffs = @newsecs;
6036: }
1.11 raeburn 6037: if (@newsecs == 0) {
1.118 raeburn 6038: if ($nochg) {
6039: $result = 'ok';
6040: $nothingtodo = 1;
6041: } else {
1.28 raeburn 6042: if ($role eq 'st') {
6043: $result =
1.174 raeburn 6044: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.28 raeburn 6045: } else {
6046: my $newscope = $scopestem;
1.52 raeburn 6047: $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
1.11 raeburn 6048: }
6049: }
1.118 raeburn 6050: $showsecs = &mt('No section');
6051: } elsif (@diffs == 0) {
6052: $result = 'ok';
6053: $nothingtodo = 1;
1.11 raeburn 6054: } else {
1.118 raeburn 6055: foreach my $newsec (@newsecs) {
1.11 raeburn 6056: if (!grep(/^\Q$newsec\E$/,@retained)) {
6057: if ($role eq 'st') {
1.174 raeburn 6058: $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 6059: if (@newsecs > 1) {
6060: my $showsingle;
6061: if ($newsec eq '') {
6062: $showsingle = &mt('No section');
6063: } else {
6064: $showsingle = $newsec;
6065: }
6066: if ($crstype eq 'Community') {
6067: $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>');
6068: } else {
6069: $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>');
6070: }
6071: $showsecs = $showsingle;
6072: last;
6073: } else {
6074: if ($newsec eq '') {
6075: $showsecs = &mt('No section');
6076: } else {
6077: $showsecs = $newsec;
6078: }
6079: }
1.11 raeburn 6080: } else {
6081: my $newscope = $scopestem;
6082: if ($newsec ne '') {
6083: $newscope .= '/'.$newsec;
1.118 raeburn 6084: push(@shownew,$newsec);
1.11 raeburn 6085: }
6086: $result = &Apache::lonnet::assignrole($udom,$uname,
6087: $newscope,$role,$end,$start);
1.118 raeburn 6088:
1.11 raeburn 6089: }
6090: }
6091: }
6092: }
1.118 raeburn 6093: unless ($role eq 'st') {
6094: unless ($showsecs) {
6095: my @tolist = sort(@shownew,@retained);
6096: if ($keepnosection) {
6097: push(@tolist,&mt('No section'));
6098: }
6099: $showsecs = join(', ',@tolist);
6100: }
6101: }
1.11 raeburn 6102: }
6103: }
1.17 raeburn 6104: my $extent = $scope;
6105: if ($choice eq 'drop' || $context eq 'course') {
6106: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
6107: if ($cdesc) {
6108: $extent = $cdesc;
6109: }
6110: }
1.1 raeburn 6111: if ($result eq 'ok' || $result eq 'ok:') {
1.118 raeburn 6112: my $dates;
6113: if (($choice eq 'chgsec') || ($choice eq 'chgdates')) {
6114: $dates = &dates_feedback($start,$end,$now);
6115: }
6116: if ($choice eq 'chgsec') {
6117: if ($nothingtodo) {
6118: $r->print(&mt("Section assignment for role of '[_1]' in [_2] for '[_3]' unchanged.",$plrole,$extent,'<i>'.
6119: &Apache::loncommon::plainname($uname,$udom).
6120: '</i>').' ');
6121: if ($sec eq '') {
6122: $r->print(&mt('[_1]No section[_2] - [_3]','<b>','</b>',$dates));
6123: } else {
6124: $r->print(&mt('Section(s): [_1] - [_2]',
6125: '<b>'.$showsecs.'</b>',$dates));
6126: }
6127: $r->print('<br />');
6128: } else {
6129: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' to [_4] - [_5]",$plrole,$extent,
6130: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
6131: '<b>'.$showsecs.'</b>',$dates).'<br />');
6132: $count ++;
6133: }
6134: if ($warn_singlesec) {
6135: $r->print('<div class="LC_warning">'.$warn_singlesec.'</div>');
6136: }
6137: } elsif ($choice eq 'chgdates') {
6138: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' - [_4]",$plrole,$extent,
1.121 raeburn 6139: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
1.118 raeburn 6140: $dates).'<br />');
6141: $count ++;
6142: } else {
6143: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]'.",$plrole,$extent,
1.121 raeburn 6144: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>').
1.118 raeburn 6145: '<br />');
6146: $count ++;
6147: }
1.1 raeburn 6148: } else {
6149: $r->print(
1.118 raeburn 6150: &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for '[_3]': [_4].",
6151: $plrole,$extent,
1.121 raeburn 6152: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
1.118 raeburn 6153: $result).'<br />');
1.11 raeburn 6154: }
6155: }
1.32 raeburn 6156: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
1.33 raeburn 6157: if ($choice eq 'drop') {
6158: $r->print('<input type="hidden" name="action" value="listusers" />'."\n".
6159: '<input type="hidden" name="Status" value="Active" />'."\n".
6160: '<input type="hidden" name="showrole" value="st" />'."\n");
6161: } else {
6162: foreach my $item ('action','sortby','roletype','showrole','Status','secfilter','grpfilter') {
6163: if ($env{'form.'.$item} ne '') {
6164: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.
6165: '" />'."\n");
6166: }
1.32 raeburn 6167: }
6168: }
1.144 bisitz 6169: $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} [quant,_1,user role,user roles,no user roles].",$count).'</b></p>');
1.11 raeburn 6170: if ($count > 0) {
1.17 raeburn 6171: if ($choice eq 'revoke' || $choice eq 'drop') {
1.74 bisitz 6172: $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>');
1.11 raeburn 6173: }
6174: # Flush the course logs so reverse user roles immediately updated
1.126 raeburn 6175: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.11 raeburn 6176: }
6177: if ($env{'form.makedatesdefault'}) {
6178: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
1.101 raeburn 6179: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
1.1 raeburn 6180: }
6181: }
1.213 raeburn 6182: if ((keys(%reject)) || (keys(%unauthorized))) {
6183: $r->print(&print_roles_rejected($context,\%reject,\%unauthorized));
1.212 raeburn 6184: }
1.213 raeburn 6185: if ((keys(%pending)) || (keys(%currqueued))) {
6186: $r->print(&print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.212 raeburn 6187: }
1.33 raeburn 6188: my $linktext = &mt('Display User Lists');
6189: if ($choice eq 'drop') {
6190: $linktext = &mt('Display current class roster');
6191: }
1.144 bisitz 6192: $r->print(
6193: &Apache::lonhtmlcommon::actionbox(
6194: ['<a href="javascript:document.studentform.submit()">'.$linktext.'</a>'])
6195: .'</form>'."\n");
1.1 raeburn 6196: }
6197:
1.118 raeburn 6198: sub dates_feedback {
6199: my ($start,$end,$now) = @_;
6200: my $dates;
6201: if ($start < $now) {
6202: if ($end == 0) {
1.147 bisitz 6203: $dates = &mt('role(s) active now; no end date');
1.118 raeburn 6204: } elsif ($end > $now) {
6205: $dates = &mt('role(s) active now; ends [_1].',&Apache::lonlocal::locallocaltime($end));
6206: } else {
6207: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
6208: }
6209: } else {
6210: if ($end == 0 || $end > $now) {
6211: $dates = &mt('future role(s); starts: [_1].',&Apache::lonlocal::locallocaltime($start));
6212: } else {
6213: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
6214: }
6215: }
6216: return $dates;
6217: }
6218:
1.8 raeburn 6219: sub classlist_drop {
1.29 raeburn 6220: my ($scope,$uname,$udom,$now) = @_;
1.8 raeburn 6221: my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
1.29 raeburn 6222: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.8 raeburn 6223: if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
1.63 raeburn 6224: my %user;
6225: my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
1.8 raeburn 6226: return &mt('Drop from classlist: [_1]',
6227: '<b>'.$result.'</b>').'<br />';
6228: }
6229: }
6230: }
6231:
6232: sub active_student_roles {
6233: my ($cnum,$cdom,$uname,$udom) = @_;
6234: my %roles =
6235: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
6236: ['future','active'],['st']);
6237: return exists($roles{"$cnum:$cdom:st"});
6238: }
6239:
1.1 raeburn 6240: sub section_check_js {
1.8 raeburn 6241: my $groupslist= &get_groupslist();
1.170 damieng 6242: my %js_lt = &Apache::lonlocal::texthash(
6243: mayn => 'may not be used as the name for a section, as it is a reserved word.',
6244: plch => 'Please choose a different section name.',
6245: mnot => 'may not be used as a section name, as it is the name of a course group.',
6246: secn => 'Section names and group names must be distinct. Please choose a different section name.',
6247: );
6248: &js_escape(\%js_lt);
1.1 raeburn 6249: return <<"END";
6250: function validate(caller) {
1.9 raeburn 6251: var groups = new Array($groupslist);
1.1 raeburn 6252: var secname = caller.value;
6253: if ((secname == 'all') || (secname == 'none')) {
1.170 damieng 6254: alert("'"+secname+"' $js_lt{'mayn'}\\n$js_lt{'plch'}");
1.1 raeburn 6255: return 'error';
6256: }
6257: if (secname != '') {
6258: for (var k=0; k<groups.length; k++) {
6259: if (secname == groups[k]) {
1.170 damieng 6260: alert("'"+secname+"' $js_lt{'mnot'}\\n$js_lt{'secn'}");
1.1 raeburn 6261: return 'error';
6262: }
6263: }
6264: }
6265: return 'ok';
6266: }
6267: END
6268: }
6269:
6270: sub set_login {
1.194 raeburn 6271: my ($dom,$authformkrb,$authformint,$authformloc,$authformlti) = @_;
1.1 raeburn 6272: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6273: my $response;
6274: my ($authnum,%can_assign) =
6275: &Apache::loncommon::get_assignable_auth($dom);
6276: if ($authnum) {
6277: $response = &Apache::loncommon::start_data_table();
6278: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
6279: $response .= &Apache::loncommon::start_data_table_row().
6280: '<td>'.$authformkrb.'</td>'.
6281: &Apache::loncommon::end_data_table_row()."\n";
6282: }
6283: if ($can_assign{'int'}) {
6284: $response .= &Apache::loncommon::start_data_table_row().
6285: '<td>'.$authformint.'</td>'.
6286: &Apache::loncommon::end_data_table_row()."\n"
6287: }
6288: if ($can_assign{'loc'}) {
6289: $response .= &Apache::loncommon::start_data_table_row().
6290: '<td>'.$authformloc.'</td>'.
6291: &Apache::loncommon::end_data_table_row()."\n";
6292: }
1.194 raeburn 6293: if ($can_assign{'lti'}) {
6294: $response .= &Apache::loncommon::start_data_table_row().
6295: '<td>'.$authformlti.'</td>'.
6296: &Apache::loncommon::end_data_table_row()."\n";
6297: }
1.1 raeburn 6298: $response .= &Apache::loncommon::end_data_table();
6299: }
6300: return $response;
6301: }
6302:
1.8 raeburn 6303: sub course_sections {
1.178 raeburn 6304: my ($sections_count,$role,$current_sec,$disabled) = @_;
1.8 raeburn 6305: my $output = '';
1.169 raeburn 6306: my @sections = (sort {$a <=> $b} keys(%{$sections_count}));
1.29 raeburn 6307: my $numsec = scalar(@sections);
1.92 bisitz 6308: my $is_selected = ' selected="selected"';
1.29 raeburn 6309: if ($numsec <= 1) {
1.178 raeburn 6310: $output = '<select name="currsec_'.$role.'"'.$disabled.'>'."\n".
1.51 raeburn 6311: ' <option value="">'.&mt('Select').'</option>'."\n";
6312: if ($current_sec eq 'none') {
6313: $output .=
6314: ' <option value=""'.$is_selected.'>'.&mt('No section').'</option>'."\n";
6315: } else {
6316: $output .=
1.29 raeburn 6317: ' <option value="">'.&mt('No section').'</option>'."\n";
1.51 raeburn 6318: }
1.29 raeburn 6319: if ($numsec == 1) {
1.51 raeburn 6320: if ($current_sec eq $sections[0]) {
6321: $output .=
6322: ' <option value="'.$sections[0].'"'.$is_selected.'>'.$sections[0].'</option>'."\n";
6323: } else {
6324: $output .=
1.8 raeburn 6325: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
1.51 raeburn 6326: }
1.29 raeburn 6327: }
1.8 raeburn 6328: } else {
6329: $output = '<select name="currsec_'.$role.'" ';
6330: my $multiple = 4;
6331: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
1.29 raeburn 6332: if ($role eq 'st') {
1.178 raeburn 6333: $output .= $disabled.'>'."\n".
1.51 raeburn 6334: ' <option value="">'.&mt('Select').'</option>'."\n";
6335: if ($current_sec eq 'none') {
6336: $output .=
6337: ' <option value=""'.$is_selected.'>'.&mt('No section')."</option>\n";
6338: } else {
6339: $output .=
1.29 raeburn 6340: ' <option value="">'.&mt('No section')."</option>\n";
1.51 raeburn 6341: }
1.29 raeburn 6342: } else {
1.178 raeburn 6343: $output .= 'multiple="multiple" size="'.$multiple.'"'.$disabled.'>'."\n";
1.29 raeburn 6344: }
1.8 raeburn 6345: foreach my $sec (@sections) {
1.51 raeburn 6346: if ($current_sec eq $sec) {
6347: $output .= '<option value="'.$sec.'"'.$is_selected.'>'.$sec."</option>\n";
6348: } else {
6349: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
6350: }
1.8 raeburn 6351: }
6352: }
6353: $output .= '</select>';
6354: return $output;
6355: }
6356:
6357: sub get_groupslist {
6358: my $groupslist;
6359: my %curr_groups = &Apache::longroup::coursegroups();
6360: if (%curr_groups) {
6361: $groupslist = join('","',sort(keys(%curr_groups)));
6362: $groupslist = '"'.$groupslist.'"';
6363: }
1.11 raeburn 6364: return $groupslist;
1.8 raeburn 6365: }
6366:
6367: sub setsections_javascript {
1.150 raeburn 6368: my ($formname,$groupslist,$mode,$checkauth,$crstype,$showcredits) = @_;
1.28 raeburn 6369: my ($checkincluded,$finish,$rolecode,$setsection_js);
6370: if ($mode eq 'upload') {
6371: $checkincluded = 'formname.name == "'.$formname.'"';
6372: $finish = "return 'ok';";
6373: $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
6374: } elsif ($formname eq 'cu') {
1.150 raeburn 6375: if (($crstype eq 'Course') && ($showcredits)) {
6376: $checkincluded = "((role == 'st') && (formname.elements[i-2].checked == true)) || ((role != 'st') && (formname.elements[i-1].checked == true))";
6377: } else {
6378: $checkincluded = 'formname.elements[i-1].checked == true';
6379: }
1.37 raeburn 6380: if ($checkauth) {
6381: $finish = "var authcheck = auth_check();\n".
6382: " if (authcheck == 'ok') {\n".
6383: " formname.submit();\n".
6384: " }\n";
6385: } else {
6386: $finish = 'formname.submit()';
6387: }
1.28 raeburn 6388: $rolecode = "var match = str.split('_');
6389: var role = match[3];\n";
1.165 raeburn 6390: } elsif (($formname eq 'enrollstudent') || ($formname eq 'selfenroll')) {
1.28 raeburn 6391: $checkincluded = 'formname.name == "'.$formname.'"';
1.37 raeburn 6392: if ($checkauth) {
6393: $finish = "var authcheck = auth_check();\n".
6394: " if (authcheck == 'ok') {\n".
6395: " formname.submit();\n".
6396: " }\n";
6397: } else {
6398: $finish = 'formname.submit()';
6399: }
1.28 raeburn 6400: $rolecode = "var match = str.split('_');
6401: var role = match[1];\n";
1.8 raeburn 6402: } else {
1.28 raeburn 6403: $checkincluded = 'formname.name == "'.$formname.'"';
1.8 raeburn 6404: $finish = "seccheck = 'ok';";
1.28 raeburn 6405: $rolecode = "var match = str.split('_');
6406: var role = match[1];\n";
1.11 raeburn 6407: $setsection_js = "var seccheck = 'alert';";
1.8 raeburn 6408: }
6409: my %alerts = &Apache::lonlocal::texthash(
6410: secd => 'Section designations do not apply to Course Coordinator roles.',
1.103 raeburn 6411: sedn => 'Section designations do not apply to Coordinator roles.',
1.8 raeburn 6412: accr => 'A course coordinator role will be added with access to all sections.',
1.103 raeburn 6413: acor => 'A coordinator role will be added with access to all sections',
1.8 raeburn 6414: inea => 'In each course, each user may only have one student role at a time.',
1.125 raeburn 6415: inco => 'In each community, each user may only have one member role at a time.',
1.145 raeburn 6416: youh => 'You had selected',
1.8 raeburn 6417: secs => 'sections.',
6418: plmo => 'Please modify your selections so they include no more than one section.',
6419: mayn => 'may not be used as the name for a section, as it is a reserved word.',
6420: plch => 'Please choose a different section name.',
6421: mnot => 'may not be used as a section name, as it is the name of a course group.',
6422: secn => 'Section names and group names must be distinct. Please choose a different section name.',
1.113 raeburn 6423: nonw => 'Section names may only contain letters or numbers.',
1.170 damieng 6424: );
6425: &js_escape(\%alerts);
1.8 raeburn 6426: $setsection_js .= <<"ENDSECCODE";
6427:
1.103 raeburn 6428: function setSections(formname,crstype) {
1.8 raeburn 6429: var re1 = /^currsec_/;
1.113 raeburn 6430: var re2 =/\\W/;
1.115 raeburn 6431: var trimleading = /^\\s+/;
6432: var trimtrailing = /\\s+\$/;
1.8 raeburn 6433: var groups = new Array($groupslist);
6434: for (var i=0;i<formname.elements.length;i++) {
6435: var str = formname.elements[i].name;
1.168 raeburn 6436: if (typeof(str) === "undefined") {
6437: continue;
6438: }
1.8 raeburn 6439: var checkcurr = str.match(re1);
6440: if (checkcurr != null) {
1.115 raeburn 6441: var num = i;
1.150 raeburn 6442: $rolecode
1.8 raeburn 6443: if ($checkincluded) {
1.103 raeburn 6444: if (role == 'cc' || role == 'co') {
6445: if (role == 'cc') {
6446: alert("$alerts{'secd'}\\n$alerts{'accr'}");
6447: } else {
6448: alert("$alerts{'sedn'}\\n$alerts{'acor'}");
6449: }
6450: } else {
1.8 raeburn 6451: var sections = '';
6452: var numsec = 0;
1.115 raeburn 6453: var fromexisting = new Array();
6454: for (var j=0; j<formname.elements[num].length; j++) {
6455: if (formname.elements[num].options[j].selected == true ) {
6456: var addsec = formname.elements[num].options[j].value;
1.119 raeburn 6457: if ((addsec != "") && (addsec != null)) {
1.115 raeburn 6458: fromexisting.push(addsec);
1.8 raeburn 6459: if (numsec == 0) {
1.115 raeburn 6460: sections = addsec;
6461: } else {
6462: sections = sections + "," + addsec;
1.8 raeburn 6463: }
1.115 raeburn 6464: numsec ++;
1.8 raeburn 6465: }
6466: }
6467: }
1.115 raeburn 6468: var newsecs = formname.elements[num+1].value;
1.113 raeburn 6469: var validsecs = new Array();
1.115 raeburn 6470: var validsecstr = '';
1.113 raeburn 6471: var badsecs = new Array();
1.8 raeburn 6472: if (newsecs != null && newsecs != "") {
1.115 raeburn 6473: var numsplit;
6474: if (newsecs.indexOf(',') == -1) {
6475: numsplit = new Array(newsecs);
6476: } else {
6477: numsplit = newsecs.split(/,/g);
6478: }
1.117 raeburn 6479: for (var m=0; m<numsplit.length; m++) {
6480: var newsec = numsplit[m];
1.115 raeburn 6481: newsec = newsec.replace(trimleading,'');
6482: newsec = newsec.replace(trimtrailing,'');
6483: if (re2.test(newsec) == true) {
6484: badsecs.push(newsec);
1.113 raeburn 6485: } else {
1.115 raeburn 6486: if (newsec != '') {
6487: var isnew = 1;
6488: if (fromexisting != null) {
1.117 raeburn 6489: for (var n=0; n<fromexisting.length; n++) {
6490: if (newsec == fromexisting[n]) {
1.115 raeburn 6491: isnew = 0;
6492: }
6493: }
6494: }
6495: if (isnew == 1) {
6496: validsecs.push(newsec);
6497: }
6498: }
1.113 raeburn 6499: }
6500: }
6501: if (badsecs.length > 0) {
6502: alert("$alerts{'nonw'}\\n$alerts{'plch'}");
6503: return;
6504: }
6505: numsec = numsec + validsecs.length;
1.8 raeburn 6506: }
6507: if ((role == 'st') && (numsec > 1)) {
1.103 raeburn 6508: if (crstype == 'Community') {
6509: alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
6510: } else {
6511: alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
6512: }
1.8 raeburn 6513: return;
1.115 raeburn 6514: } else {
6515: if (validsecs != null) {
6516: for (var j=0; j<validsecs.length; j++) {
6517: if (validsecstr == '' || validsecstr == null) {
6518: validsecstr = validsecs[j];
6519: } else {
6520: validsecstr += ','+validsecs[j];
6521: }
6522: if ((validsecs[j] == 'all') ||
6523: (validsecs[j] == 'none')) {
6524: alert("'"+validsecs[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
1.8 raeburn 6525: return;
6526: }
6527: for (var k=0; k<groups.length; k++) {
1.115 raeburn 6528: if (validsecs[j] == groups[k]) {
6529: alert("'"+validsecs[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
1.8 raeburn 6530: return;
6531: }
6532: }
6533: }
6534: }
6535: }
1.115 raeburn 6536: if ((validsecstr != '') && (validsecstr != null)) {
1.117 raeburn 6537: if ((sections == '') || (sections == null)) {
6538: sections = validsecstr;
6539: } else {
1.115 raeburn 6540: sections = sections + "," + validsecstr;
6541: }
6542: }
6543: formname.elements[num+2].value = sections;
1.8 raeburn 6544: }
6545: }
6546: }
6547: }
6548: $finish
6549: }
6550: ENDSECCODE
1.11 raeburn 6551: return $setsection_js;
1.8 raeburn 6552: }
6553:
1.15 raeburn 6554: sub can_create_user {
6555: my ($dom,$context,$usertype) = @_;
6556: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6557: my $cancreate = 1;
1.28 raeburn 6558: if (&Apache::lonnet::allowed('mau',$dom)) {
6559: return $cancreate;
1.178 raeburn 6560: } elsif ($context eq 'domain') {
6561: $cancreate = 0;
6562: return $cancreate;
1.28 raeburn 6563: }
1.15 raeburn 6564: if (ref($domconf{'usercreation'}) eq 'HASH') {
6565: if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
1.100 raeburn 6566: if ($context eq 'course' || $context eq 'author' || $context eq 'requestcrs') {
1.15 raeburn 6567: my $creation = $domconf{'usercreation'}{'cancreate'}{$context};
6568: if ($creation eq 'none') {
6569: $cancreate = 0;
6570: } elsif ($creation ne 'any') {
6571: if (defined($usertype)) {
6572: if ($creation ne $usertype) {
6573: $cancreate = 0;
6574: }
6575: }
6576: }
6577: }
6578: }
6579: }
6580: return $cancreate;
6581: }
6582:
1.20 raeburn 6583: sub can_modify_userinfo {
6584: my ($context,$dom,$fields,$userroles) = @_;
6585: my %domconfig =
6586: &Apache::lonnet::get_dom('configuration',['usermodification'],
6587: $dom);
6588: my %canmodify;
6589: if (ref($fields) eq 'ARRAY') {
6590: foreach my $field (@{$fields}) {
6591: $canmodify{$field} = 0;
6592: if (&Apache::lonnet::allowed('mau',$dom)) {
6593: $canmodify{$field} = 1;
6594: } else {
6595: if (ref($domconfig{'usermodification'}) eq 'HASH') {
6596: if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
6597: if (ref($userroles) eq 'ARRAY') {
6598: foreach my $role (@{$userroles}) {
6599: my $testrole;
1.60 raeburn 6600: if ($context eq 'selfcreate') {
6601: $testrole = $role;
1.20 raeburn 6602: } else {
1.60 raeburn 6603: if ($role =~ /^cr\//) {
6604: $testrole = 'cr';
6605: } else {
6606: $testrole = $role;
6607: }
1.20 raeburn 6608: }
6609: if (ref($domconfig{'usermodification'}{$context}{$testrole}) eq 'HASH') {
6610: if ($domconfig{'usermodification'}{$context}{$testrole}{$field}) {
6611: $canmodify{$field} = 1;
6612: last;
6613: }
6614: }
6615: }
6616: } else {
6617: foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
6618: if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
6619: if ($domconfig{'usermodification'}{$context}{$key}{$field}) {
6620: $canmodify{$field} = 1;
6621: last;
6622: }
6623: }
6624: }
6625: }
6626: }
6627: } elsif ($context eq 'course') {
6628: if (ref($userroles) eq 'ARRAY') {
6629: if (grep(/^st$/,@{$userroles})) {
6630: $canmodify{$field} = 1;
6631: }
6632: } else {
6633: $canmodify{$field} = 1;
6634: }
6635: }
6636: }
6637: }
6638: }
6639: return %canmodify;
6640: }
6641:
1.195 raeburn 6642: sub can_change_internalpass {
6643: my ($uname,$udom,$crstype,$permission) = @_;
6644: my $canchange;
6645: if (&Apache::lonnet::allowed('mau',$udom)) {
6646: $canchange = 1;
6647: } elsif ((ref($permission) eq 'HASH') && ($permission->{'mip'}) &&
6648: ($udom eq $env{'request.role.domain'})) {
6649: unless ($env{'course.'.$env{'request.course.id'}.'.internal.nopasswdchg'}) {
6650: my ($cnum,$cdom) = &get_course_identity();
6651: if ((&Apache::lonnet::is_course_owner($cdom,$cnum)) && ($udom eq $env{'user.domain'})) {
1.199 raeburn 6652: my @userstatuses = ('default');
6653: my %userenv = &Apache::lonnet::userenvironment($udom,$uname,'inststatus');
6654: if ($userenv{'inststatus'} ne '') {
6655: @userstatuses = split(/:/,$userenv{'inststatus'});
6656: }
6657: my $noupdate = 1;
6658: my %passwdconf = &Apache::lonnet::get_passwdconf($cdom);
6659: if (ref($passwdconf{'crsownerchg'}) eq 'HASH') {
6660: if (ref($passwdconf{'crsownerchg'}{'for'}) eq 'ARRAY') {
6661: foreach my $status (@userstatuses) {
6662: if (grep(/^\Q$status\E$/,@{$passwdconf{'crsownerchg'}{'for'}})) {
6663: undef($noupdate);
6664: last;
6665: }
6666: }
6667: }
6668: }
6669: if ($noupdate) {
6670: return;
6671: }
1.195 raeburn 6672: my %owned = &Apache::lonnet::courseiddump($cdom,'.',1,'.',
6673: $env{'user.name'}.':'.$env{'user.domain'},
6674: undef,undef,undef,'.');
6675: my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
6676: ['active','future']);
6677: foreach my $key (keys(%roleshash)) {
6678: my ($name,$domain,$role) = split(/:/,$key);
6679: if ($role eq 'st') {
6680: next if (($name eq $cnum) && ($domain eq $cdom));
6681: if ($owned{$domain.'_'.$name}) {
6682: if (ref($owned{$domain.'_'.$name}) eq 'HASH') {
6683: if ($owned{$domain.'_'.$name}{'nopasswdchg'}) {
6684: $noupdate = 1;
6685: last;
6686: }
6687: }
6688: } else {
6689: $noupdate = 1;
6690: last;
6691: }
6692: } else {
6693: $noupdate = 1;
6694: last;
6695: }
6696: }
6697: unless ($noupdate) {
6698: $canchange = 1;
6699: }
6700: }
6701: }
6702: }
6703: return $canchange;
6704: }
6705:
1.18 raeburn 6706: sub check_usertype {
1.134 raeburn 6707: my ($dom,$uname,$rules,$curr_rules,$got_rules) = @_;
1.18 raeburn 6708: my $usertype;
1.134 raeburn 6709: if ((ref($got_rules) eq 'HASH') && (ref($curr_rules) eq 'HASH')) {
6710: if (!$got_rules->{$dom}) {
6711: my %domconfig = &Apache::lonnet::get_dom('configuration',
6712: ['usercreation'],$dom);
6713: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6714: foreach my $item ('username','id') {
6715: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
6716: $curr_rules->{$dom}{$item} =
6717: $domconfig{'usercreation'}{$item.'_rule'};
6718: }
6719: }
6720: }
6721: $got_rules->{$dom} = 1;
6722: }
6723: if (ref($rules) eq 'HASH') {
6724: my @user_rules;
6725: if (ref($curr_rules->{$dom}{'username'}) eq 'ARRAY') {
6726: foreach my $rule (keys(%{$rules})) {
6727: if (grep(/^\Q$rule\E/,@{$curr_rules->{$dom}{'username'}})) {
6728: push(@user_rules,$rule);
6729: }
6730: }
6731: }
6732: if (@user_rules > 0) {
6733: my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
6734: if (keys(%rule_check) > 0) {
6735: $usertype = 'unofficial';
6736: foreach my $item (keys(%rule_check)) {
6737: if ($rule_check{$item}) {
6738: $usertype = 'official';
6739: last;
6740: }
1.18 raeburn 6741: }
6742: }
6743: }
6744: }
6745: }
6746: return $usertype;
6747: }
6748:
1.17 raeburn 6749: sub roles_by_context {
1.101 raeburn 6750: my ($context,$custom,$crstype) = @_;
1.17 raeburn 6751: my @allroles;
6752: if ($context eq 'course') {
1.99 raeburn 6753: @allroles = ('st');
6754: if ($env{'request.role'} =~ m{^dc\./}) {
6755: push(@allroles,'ad');
6756: }
1.101 raeburn 6757: push(@allroles,('ta','ep','in'));
6758: if ($crstype eq 'Community') {
6759: push(@allroles,'co');
6760: } else {
6761: push(@allroles,'cc');
6762: }
1.17 raeburn 6763: if ($custom) {
6764: push(@allroles,'cr');
6765: }
6766: } elsif ($context eq 'author') {
6767: @allroles = ('ca','aa');
6768: } elsif ($context eq 'domain') {
1.182 raeburn 6769: @allroles = ('li','ad','dg','dh','da','sc','au','dc');
1.17 raeburn 6770: }
6771: return @allroles;
6772: }
6773:
1.16 raeburn 6774: sub get_permission {
1.101 raeburn 6775: my ($context,$crstype) = @_;
1.16 raeburn 6776: my %permission;
6777: if ($context eq 'course') {
1.17 raeburn 6778: my $custom = 1;
1.101 raeburn 6779: my @allroles = &roles_by_context($context,$custom,$crstype);
1.17 raeburn 6780: foreach my $role (@allroles) {
6781: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
6782: $permission{'cusr'} = 1;
6783: last;
6784: }
1.16 raeburn 6785: }
6786: if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
6787: $permission{'custom'} = 1;
6788: }
6789: if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
6790: $permission{'view'} = 1;
6791: }
6792: if (!$permission{'view'}) {
6793: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
6794: $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
6795: if ($permission{'view'}) {
6796: $permission{'view_section'} = $env{'request.course.sec'};
6797: }
6798: }
1.17 raeburn 6799: if (!$permission{'cusr'}) {
6800: if ($env{'request.course.sec'} ne '') {
6801: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
6802: $permission{'cusr'} = (&Apache::lonnet::allowed('cst',$scope));
6803: if ($permission{'cusr'}) {
6804: $permission{'cusr_section'} = $env{'request.course.sec'};
6805: }
6806: }
6807: }
1.16 raeburn 6808: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
6809: $permission{'grp_manage'} = 1;
6810: }
1.165 raeburn 6811: if ($permission{'cusr'}) {
6812: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6813: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6814: my %coursehash = (
6815: 'internal.selfenrollmgrdc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrdc'},
6816: 'internal.selfenrollmgrcc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrcc'},
6817: 'internal.coursecode' => $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},
6818: 'internal.textbook' =>$env{'course.'.$env{'request.course.id'}.'.internal.textbook'},
6819: );
6820: my ($managed_by_cc,$managed_by_dc) = &selfenrollment_administration($cdom,$cnum,$crstype,\%coursehash);
6821: if (ref($managed_by_cc) eq 'ARRAY') {
6822: if (@{$managed_by_cc}) {
6823: $permission{'selfenrolladmin'} = 1;
6824: }
6825: }
1.216 raeburn 6826: unless ($permission{'selfenrolladmin'}) {
6827: $permission{'selfenrollview'} = 1;
6828: }
1.165 raeburn 6829: }
1.180 raeburn 6830: if ($env{'request.course.id'}) {
1.195 raeburn 6831: my $user;
6832: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
6833: $user = $env{'user.name'}.':'.$env{'user.domain'};
6834: }
1.180 raeburn 6835: if (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'} eq
6836: $user)) {
6837: $permission{'owner'} = 1;
1.195 raeburn 6838: if (&Apache::lonnet::allowed('mip',$env{'request.course.id'})) {
6839: $permission{'mip'} = 1;
6840: }
1.180 raeburn 6841: } elsif (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.co-owners'} ne '')) {
6842: if (grep(/^\Q$user\E$/,split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.co-owners'}))) {
6843: $permission{'co-owner'} = 1;
6844: }
6845: }
6846: }
1.16 raeburn 6847: } elsif ($context eq 'author') {
1.218 ! raeburn 6848: my $audom = $env{'request.role.domain'};
! 6849: my $auname = $env{'user.name'};
! 6850: if ((&Apache::lonnet::allowed('cca',"$audom/$auname")) ||
! 6851: (&Apache::lonnet::allowed('caa',"$audom/$auname"))) {
! 6852: $permission{'author'} = 1;
! 6853: $permission{'cusr'} = 1;
! 6854: $permission{'view'} = 1;
! 6855: }
! 6856: } elsif ($context eq 'coauthor') {
! 6857: my ($audom,$auname) = ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$});
! 6858: if ((&Apache::lonnet::allowed('vca',"$audom/$auname")) ||
! 6859: (&Apache::lonnet::allowed('vaa',"$audom/$auname"))) {
! 6860: if ($env{"environment.internal.manager./$audom/$auname"}) {
! 6861: $permission{'cusr'} = 1;
! 6862: $permission{'view'} = 1;
! 6863: }
! 6864: }
1.16 raeburn 6865: } else {
1.17 raeburn 6866: my @allroles = &roles_by_context($context);
6867: foreach my $role (@allroles) {
1.28 raeburn 6868: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
6869: $permission{'cusr'} = 1;
1.17 raeburn 6870: last;
6871: }
6872: }
6873: if (!$permission{'cusr'}) {
6874: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
6875: $permission{'cusr'} = 1;
6876: }
1.16 raeburn 6877: }
6878: if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
6879: $permission{'custom'} = 1;
6880: }
1.176 raeburn 6881: if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
6882: $permission{'activity'} = 1;
6883: }
1.178 raeburn 6884: if (&Apache::lonnet::allowed('vur',$env{'request.role.domain'})) {
6885: $permission{'view'} = 1;
6886: }
1.180 raeburn 6887: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
6888: $permission{'owner'} = 1;
6889: }
1.16 raeburn 6890: }
6891: my $allowed = 0;
1.211 raeburn 6892: foreach my $key (keys(%permission)) {
1.218 ! raeburn 6893: next if (($key eq 'owner') || ($key eq 'co-owner') || ($key eq 'author'));
1.211 raeburn 6894: if ($permission{$key}) { $allowed=1; last; }
1.16 raeburn 6895: }
6896: return (\%permission,$allowed);
6897: }
6898:
6899: # ==================================================== Figure out author access
6900:
6901: sub authorpriv {
6902: my ($auname,$audom)=@_;
6903: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
6904: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; } return 1;
6905: }
6906:
1.218 ! raeburn 6907: sub coauthorpriv {
! 6908: my ($auname,$audom)=@_;
! 6909: my $uname = $env{'user.name'};
! 6910: my $udom = $env{'user.domain'};
! 6911: if (((&Apache::lonnet::allowed('vca',"$udom/$uname")) ||
! 6912: (&Apache::lonnet::allowed('vaa',"$udom/$uname"))) &&
! 6913: ($env{"environment.internal.manager./$audom/$auname"})) {
! 6914: return 1;
! 6915: }
! 6916: return '';
! 6917: }
! 6918:
1.27 raeburn 6919: sub roles_on_upload {
1.101 raeburn 6920: my ($context,$setting,$crstype,%customroles) = @_;
1.27 raeburn 6921: my (@possible_roles,@permitted_roles);
1.101 raeburn 6922: @possible_roles = &curr_role_permissions($context,$setting,1,$crstype);
1.27 raeburn 6923: foreach my $role (@possible_roles) {
6924: if ($role eq 'cr') {
6925: push(@permitted_roles,keys(%customroles));
6926: } else {
6927: push(@permitted_roles,$role);
6928: }
6929: }
1.42 raeburn 6930: return @permitted_roles;
1.27 raeburn 6931: }
6932:
1.17 raeburn 6933: sub get_course_identity {
6934: my ($cid) = @_;
6935: my ($cnum,$cdom,$cdesc);
6936: if ($cid eq '') {
6937: $cid = $env{'request.course.id'}
6938: }
6939: if ($cid ne '') {
6940: $cnum = $env{'course.'.$cid.'.num'};
6941: $cdom = $env{'course.'.$cid.'.domain'};
6942: $cdesc = $env{'course.'.$cid.'.description'};
6943: if ($cnum eq '' || $cdom eq '') {
6944: my %coursehash =
6945: &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
6946: $cdom = $coursehash{'domain'};
6947: $cnum = $coursehash{'num'};
6948: $cdesc = $coursehash{'description'};
6949: }
6950: }
6951: return ($cnum,$cdom,$cdesc);
6952: }
6953:
1.19 raeburn 6954: sub dc_setcourse_js {
1.196 raeburn 6955: my ($formname,$mode,$context,$showcredits,$domain) = @_;
1.37 raeburn 6956: my ($dc_setcourse_code,$authen_check);
1.19 raeburn 6957: my $cctext = &Apache::lonnet::plaintext('cc');
1.103 raeburn 6958: my $cotext = &Apache::lonnet::plaintext('co');
1.19 raeburn 6959: my %alerts = §ioncheck_alerts();
6960: my $role = 'role';
6961: if ($mode eq 'upload') {
6962: $role = 'courserole';
1.37 raeburn 6963: } else {
1.196 raeburn 6964: $authen_check = &verify_authen($formname,$context,$domain);
1.19 raeburn 6965: }
6966: $dc_setcourse_code = (<<"SCRIPTTOP");
1.37 raeburn 6967: $authen_check
6968:
1.19 raeburn 6969: function setCourse() {
6970: var course = document.$formname.dccourse.value;
6971: if (course != "") {
6972: if (document.$formname.dcdomain.value != document.$formname.origdom.value) {
6973: alert("$alerts{'curd'}");
6974: return;
6975: }
6976: var userrole = document.$formname.$role.options[document.$formname.$role.selectedIndex].value
6977: var section="";
6978: var numsections = 0;
6979: var newsecs = new Array();
6980: for (var i=0; i<document.$formname.currsec.length; i++) {
6981: if (document.$formname.currsec.options[i].selected == true ) {
6982: if (document.$formname.currsec.options[i].value != "" && document.$formname.currsec.options[i].value != null) {
6983: if (numsections == 0) {
6984: section = document.$formname.currsec.options[i].value
6985: numsections = 1;
6986: }
6987: else {
6988: section = section + "," + document.$formname.currsec.options[i].value
6989: numsections ++;
6990: }
6991: }
6992: }
6993: }
6994: if (document.$formname.newsec.value != "" && document.$formname.newsec.value != null) {
6995: if (numsections == 0) {
6996: section = document.$formname.newsec.value
6997: }
6998: else {
6999: section = section + "," + document.$formname.newsec.value
7000: }
7001: newsecs = document.$formname.newsec.value.split(/,/g);
7002: numsections = numsections + newsecs.length;
7003: }
7004: if ((userrole == 'st') && (numsections > 1)) {
1.103 raeburn 7005: if (document.$formname.crstype.value == 'Community') {
7006: alert("$alerts{'inco'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
7007: } else {
7008: alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
7009: }
1.19 raeburn 7010: return;
7011: }
7012: for (var j=0; j<newsecs.length; j++) {
7013: if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
7014: alert("'"+newsecs[j]+"' $alerts{'mayn'}.\\n$alerts{'plsc'}.");
7015: return;
7016: }
7017: if (document.$formname.groups.value != '') {
7018: var groups = document.$formname.groups.value.split(/,/g);
7019: for (var k=0; k<groups.length; k++) {
7020: if (newsecs[j] == groups[k]) {
1.103 raeburn 7021: if (document.$formname.crstype.value == 'Community') {
7022: alert("'"+newsecs[j]+"' $alerts{'mayc'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
7023: } else {
7024: alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
7025: }
1.19 raeburn 7026: return;
7027: }
7028: }
7029: }
7030: }
7031: if ((userrole == 'cc') && (numsections > 0)) {
7032: alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
7033: section = "";
7034: }
1.103 raeburn 7035: if ((userrole == 'co') && (numsections > 0)) {
7036: alert("$alerts{'secd'} $cotext $alerts{'role'}.\\n$alerts{'accr'}.");
7037: section = "";
7038: }
1.19 raeburn 7039: SCRIPTTOP
7040: if ($mode ne 'upload') {
1.150 raeburn 7041: $dc_setcourse_code .= (<<"SCRIPTMID");
1.19 raeburn 7042: var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
7043: var numcourse = getIndex(document.$formname.dccourse);
7044: if (numcourse == "-1") {
1.103 raeburn 7045: if (document.$formname.type == 'Community') {
7046: alert("$alerts{'thwc'}");
7047: } else {
7048: alert("$alerts{'thwa'}");
7049: }
1.19 raeburn 7050: return;
7051: }
7052: else {
7053: document.$formname.elements[numcourse].name = "act"+coursename;
7054: var numnewsec = getIndex(document.$formname.newsec);
7055: if (numnewsec != "-1") {
7056: document.$formname.elements[numnewsec].name = "sec"+coursename;
7057: document.$formname.elements[numnewsec].value = section;
7058: }
7059: var numstart = getIndex(document.$formname.start);
7060: if (numstart != "-1") {
7061: document.$formname.elements[numstart].name = "start"+coursename;
7062: }
7063: var numend = getIndex(document.$formname.end);
7064: if (numend != "-1") {
7065: document.$formname.elements[numend].name = "end"+coursename
7066: }
1.150 raeburn 7067: SCRIPTMID
7068: if ($showcredits) {
7069: $dc_setcourse_code .= <<ENDCRED;
7070: var numcredits = getIndex(document.$formname.credits);
7071: if (numcredits != "-1") {
7072: document.$formname.elements[numcredits].name = "credits"+coursename;
7073: }
7074: ENDCRED
7075: }
7076: $dc_setcourse_code .= <<ENDSCRIPT;
1.19 raeburn 7077: }
7078: }
1.37 raeburn 7079: var authcheck = auth_check();
7080: if (authcheck == 'ok') {
7081: document.$formname.submit();
7082: }
1.19 raeburn 7083: }
7084: ENDSCRIPT
7085: } else {
7086: $dc_setcourse_code .= "
7087: document.$formname.sections.value = section;
7088: }
7089: return 'ok';
7090: }
7091: ";
7092: }
7093: $dc_setcourse_code .= (<<"ENDSCRIPT");
7094:
7095: function getIndex(caller) {
7096: for (var i=0;i<document.$formname.elements.length;i++) {
7097: if (document.$formname.elements[i] == caller) {
7098: return i;
7099: }
7100: }
7101: return -1;
7102: }
7103: ENDSCRIPT
1.37 raeburn 7104: return $dc_setcourse_code;
7105: }
7106:
7107: sub verify_authen {
1.196 raeburn 7108: my ($formname,$context,$domain) = @_;
1.37 raeburn 7109: my %alerts = &authcheck_alerts();
7110: my $finish = "return 'ok';";
7111: if ($context eq 'author') {
7112: $finish = "document.$formname.submit();";
7113: }
1.196 raeburn 7114: my ($numrules,$intargjs) =
1.210 raeburn 7115: &Apache::loncommon::passwd_validation_js('argpicked',$domain);
1.37 raeburn 7116: my $outcome = <<"ENDSCRIPT";
7117:
7118: function auth_check() {
7119: var logintype;
7120: if (document.$formname.login.length) {
7121: if (document.$formname.login.length > 0) {
7122: var loginpicked = 0;
7123: for (var i=0; i<document.$formname.login.length; i++) {
7124: if (document.$formname.login[i].checked == true) {
7125: loginpicked = 1;
7126: logintype = document.$formname.login[i].value;
7127: }
7128: }
7129: if (loginpicked == 0) {
7130: alert("$alerts{'authen'}");
7131: return;
7132: }
7133: }
7134: } else {
7135: logintype = document.$formname.login.value;
7136: }
7137: if (logintype == 'nochange') {
7138: return 'ok';
7139: }
7140: var argpicked = document.$formname.elements[logintype+'arg'].value;
7141: if ((argpicked == null) || (argpicked == '') || (typeof argpicked == 'undefined')) {
7142: var alertmsg = '';
7143: switch (logintype) {
7144: case 'krb':
7145: alertmsg = '$alerts{'krb'}';
7146: break;
7147: case 'int':
7148: alertmsg = '$alerts{'ipass'}';
1.196 raeburn 7149: break;
1.37 raeburn 7150: case 'fsys':
7151: alertmsg = '$alerts{'ipass'}';
7152: break;
7153: case 'loc':
7154: alertmsg = '';
7155: break;
7156: default:
7157: alertmsg = '';
7158: }
7159: if (alertmsg != '') {
7160: alert(alertmsg);
7161: return;
7162: }
1.196 raeburn 7163: } else if (logintype == 'int') {
7164: var numrules = $numrules;
7165: if (numrules > 0) {
7166: $intargjs
7167: }
1.37 raeburn 7168: }
7169: $finish
7170: }
7171: ENDSCRIPT
1.19 raeburn 7172: }
7173:
7174: sub sectioncheck_alerts {
7175: my %alerts = &Apache::lonlocal::texthash(
1.103 raeburn 7176: curd => 'You must select a course or community in the current domain',
1.19 raeburn 7177: inea => 'In each course, each user may only have one student role at a time',
1.103 raeburn 7178: inco => 'In each community, each user may only have one member role at a time',
1.19 raeburn 7179: youh => 'You had selected',
7180: sect => 'sections',
7181: plsm => 'Please modify your selections so they include no more than one section',
7182: mayn => 'may not be used as the name for a section, as it is a reserved word',
7183: plsc => 'Please choose a different section name',
7184: mayt => 'may not be used as the name for a section, as it is the name of a course group',
1.103 raeburn 7185: mayc => 'may not be used as the name for a section, as it is the name of a community group',
1.19 raeburn 7186: secn => 'Section names and group names must be distinct',
7187: secd => 'Section designations do not apply to ',
7188: role => 'roles',
7189: accr => 'role will be added with access to all sections',
1.103 raeburn 7190: thwa => 'There was a problem with your course selection',
7191: thwc => 'There was a problem with your community selection',
1.19 raeburn 7192: );
1.170 damieng 7193: &js_escape(\%alerts);
1.19 raeburn 7194: return %alerts;
7195: }
1.17 raeburn 7196:
1.37 raeburn 7197: sub authcheck_alerts {
7198: my %alerts =
7199: &Apache::lonlocal::texthash(
7200: authen => 'You must choose an authentication type.',
7201: krb => 'You need to specify the Kerberos domain.',
7202: ipass => 'You need to specify the initial password.',
7203: );
1.170 damieng 7204: &js_escape(\%alerts);
1.37 raeburn 7205: return %alerts;
7206: }
7207:
1.141 raeburn 7208: sub is_courseowner {
7209: my ($thiscourse,$courseowner) = @_;
7210: if ($courseowner eq '') {
7211: if ($env{'request.course.id'} eq $thiscourse) {
7212: $courseowner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
7213: }
7214: }
7215: if ($courseowner ne '') {
7216: if ($courseowner eq $env{'user.name'}.':'.$env{'user.domain'}) {
7217: return 1;
7218: }
7219: }
7220: return;
7221: }
7222:
1.165 raeburn 7223: sub get_selfenroll_titles {
7224: my @row = ('types','registered','enroll_dates','access_dates','section',
7225: 'approval','limit');
7226: my %lt = &Apache::lonlocal::texthash (
7227: types => 'Users allowed to self-enroll',
7228: registered => 'Registration status (official courses)' ,
7229: enroll_dates => 'Dates self-enrollment available',
7230: access_dates => 'Access dates for self-enrolling users',
7231: section => "Self-enrolling users' section",
7232: approval => 'Processing of requests',
7233: limit => 'Enrollment limit',
7234: );
7235: return (\@row,\%lt);
7236: }
7237:
7238: sub selfenroll_default_descs {
7239: my %desc = (
7240: types => {
7241: dom => &mt('Course domain'),
7242: all => &mt('Any domain'),
7243: '' => &mt('None'),
7244: },
7245: limit => {
7246: none => &mt('No limit'),
7247: allstudents => &mt('Limit by total students'),
7248: selfenrolled => &mt('Limit by total self-enrolled'),
7249: },
7250: approval => {
7251: '0' => &mt('Processed automatically'),
7252: '1' => &mt('Queued for approval'),
7253: '2' => &mt('Queued, pending validation'),
7254: },
7255: registered => {
7256: 0 => 'No registration required',
7257: 1 => 'Registered students only',
7258: },
7259: );
7260: return %desc;
7261: }
7262:
7263: sub selfenroll_validation_types {
7264: my @items = ('url','fields','button','markup');
7265: my %names = &Apache::lonlocal::texthash (
7266: url => 'Web address of validation server/script',
7267: fields => 'Form fields to send to validator',
7268: button => 'Text for validation button',
7269: markup => 'Validation description (HTML)',
7270: );
1.167 raeburn 7271: my @fields = ('username','domain','uniquecode','course','coursetype','description');
1.165 raeburn 7272: return (\@items,\%names,\@fields);
7273: }
7274:
7275: sub get_extended_type {
7276: my ($cdom,$cnum,$crstype,$current) = @_;
7277: my $type = 'unofficial';
7278: my %settings;
7279: if (ref($current) eq 'HASH') {
7280: %settings = %{$current};
7281: } else {
7282: %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook'],$cdom,$cnum);
7283: }
7284: if ($crstype eq 'Community') {
7285: $type = 'community';
1.173 raeburn 7286: } elsif ($crstype eq 'Placement') {
7287: $type = 'placement';
1.165 raeburn 7288: } elsif ($settings{'internal.coursecode'}) {
7289: $type = 'official';
7290: } elsif ($settings{'internal.textbook'}) {
7291: $type = 'textbook';
7292: }
7293: return $type;
7294: }
7295:
7296: sub selfenrollment_administration {
7297: my ($cdom,$cnum,$crstype,$coursehash) = @_;
7298: my %settings;
7299: if (ref($coursehash) eq 'HASH') {
7300: %settings = %{$coursehash};
7301: } else {
7302: %settings = &Apache::lonnet::get('environment',
7303: ['internal.selfenrollmgrdc','internal.selfenrollmgrcc',
7304: 'internal.coursecode','internal.textbook'],$cdom,$cnum);
7305: }
7306: my ($possconfigs) = &get_selfenroll_titles();
7307: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
7308: my $selfenrolltype = &get_extended_type($cdom,$cnum,$crstype,\%settings);
7309:
7310: my (@in_course,@in_domain);
7311: if ($settings{'internal.selfenrollmgrcc'} ne '') {
7312: @in_course = split(/,/,$settings{'internal.selfenrollmgrcc'});
7313: my @diffs = &Apache::loncommon::compare_arrays($possconfigs,\@in_course);
7314: unless (@diffs) {
7315: return (\@in_course,\@in_domain);
7316: }
7317: }
7318: if ($settings{'internal.selfenrollmgrdc'} ne '') {
1.215 raeburn 7319: @in_domain = split(/,/,$settings{'internal.selfenrollmgrdc'});
1.165 raeburn 7320: my @diffs = &Apache::loncommon::compare_arrays(\@in_domain,$possconfigs);
7321: unless (@diffs) {
7322: return (\@in_course,\@in_domain);
7323: }
7324: }
7325: my @combined = @in_course;
7326: push(@combined,@in_domain);
7327: my @diffs = &Apache::loncommon::compare_arrays(\@combined,$possconfigs);
7328: unless (@diffs) {
7329: return (\@in_course,\@in_domain);
7330: }
7331: if ($domdefaults{$selfenrolltype.'selfenrolladmdc'} eq '') {
7332: push(@in_course,@diffs);
7333: } else {
7334: my @defaultdc = split(/,/,$domdefaults{$selfenrolltype.'selfenrolladmdc'});
7335: foreach my $item (@diffs) {
7336: if (grep(/^\Q$item\E$/,@defaultdc)) {
7337: push(@in_domain,$item);
7338: } else {
7339: push(@in_course,$item);
7340: }
7341: }
7342: }
7343: return (\@in_course,\@in_domain);
7344: }
7345:
1.175 raeburn 7346: sub custom_role_header {
7347: my ($context,$crstype,$templaterolerefs,$prefix) = @_;
7348: my %lt = &Apache::lonlocal::texthash(
7349: sele => 'Select a Template',
7350: );
7351: my ($context_code,$button_code);
7352: if ($context eq 'domain') {
7353: $context_code = &custom_coursetype_switch($crstype,$prefix);
7354: }
7355: if (ref($templaterolerefs) eq 'ARRAY') {
7356: foreach my $role (@{$templaterolerefs}) {
7357: my $display = 'inline';
7358: if (($context eq 'domain') && ($role eq 'co')) {
7359: $display = 'none';
7360: }
7361: $button_code .= &make_button_code($role,$crstype,$display,$prefix).' ';
7362: }
7363: }
7364: return <<"END";
7365: <div class="LC_left_float">
7366: <fieldset>
7367: <legend>$lt{'sele'}</legend>
7368: $button_code
7369: </fieldset></div>
7370: $context_code
7371: <br clear="all" />
7372: END
7373: }
7374:
7375: sub custom_coursetype_switch {
7376: my ($crstype,$prefix) = @_;
7377: my ($checkedcourse,$checkedcommunity);
7378: if ($crstype eq 'Community') {
7379: $checkedcommunity = ' checked="checked"';
7380: } else {
7381: $checkedcourse = ' checked="checked"';
7382: }
7383: my %lt = &Apache::lonlocal::texthash(
7384: cont => 'Context',
7385: cour => 'Course',
7386: comm => 'Community',
7387: );
7388: return <<"END";
7389: <div class="LC_left_float">
7390: <fieldset>
7391: <legend>$lt{'cont'}</legend>
7392: <label>
7393: <input type="radio" name="${prefix}_custrolecrstype" value="Course"$checkedcourse onclick="javascript:customSwitchType('$prefix');" />
7394: $lt{'cour'}
7395: </label>
7396: <label>
7397: <input type="radio" name="${prefix}_custrolecrstype" value="Community"$checkedcommunity onclick="javascript:customSwitchType('$prefix');" />
7398: $lt{'comm'}
7399: </label>
7400: </fieldset>
7401: </div>
7402: END
7403: }
7404:
7405: sub custom_role_table {
1.180 raeburn 7406: my ($crstype,$full,$levels,$levelscurrent,$prefix,$add_class,$id) = @_;
1.175 raeburn 7407: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7408: (ref($levelscurrent) eq 'HASH'));
7409: my %lt=&Apache::lonlocal::texthash (
7410: 'prv' => "Privilege",
7411: 'crl' => "Course Level",
7412: 'dml' => "Domain Level",
7413: 'ssl' => "System Level");
7414: my %cr = (
7415: course => '_c',
7416: domain => '_d',
7417: system => '_s',
7418: );
7419:
1.180 raeburn 7420: my $output=&Apache::loncommon::start_data_table($add_class,$id).
1.175 raeburn 7421: &Apache::loncommon::start_data_table_header_row().
7422: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
7423: '</th><th>'.$lt{'ssl'}.'</th>'.
7424: &Apache::loncommon::end_data_table_header_row();
7425: foreach my $priv (sort(keys(%{$full}))) {
7426: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7427: $output .= &Apache::loncommon::start_data_table_row().
7428: '<td><span id="'.$prefix.$priv.'">'.$privtext.'</span></td>';
7429: foreach my $type ('course','domain','system') {
7430: if (($type eq 'system') && ($priv eq 'bre') && ($crstype eq 'Community')) {
7431: $output .= '<td> </td>';
7432: } else {
7433: $output .= '<td>'.
7434: ($levels->{$type}{$priv}?'<input type="checkbox" id="'.$prefix.$priv.$cr{$type}.'"'.
7435: ' name="'.$prefix.$priv.$cr{$type}.'"'.
7436: ($levelscurrent->{$type}{$priv}?' checked="checked"':'').' />':' ').
7437: '</td>';
7438: }
7439: }
7440: $output .= &Apache::loncommon::end_data_table_row();
7441: }
7442: $output .= &Apache::loncommon::end_data_table();
7443: return $output;
7444: }
7445:
7446: sub custom_role_privs {
7447: my ($privs,$full,$levels,$levelscurrent)= @_;
7448: return unless ((ref($privs) eq 'HASH') && (ref($full) eq 'HASH') &&
7449: (ref($levels) eq 'HASH') && (ref($levelscurrent) eq 'HASH'));
7450: my %cr = (
7451: course => 'cr:c',
7452: domain => 'cr:d',
7453: system => 'cr:s',
7454: );
7455: foreach my $type ('course','domain','system') {
7456: foreach my $item (split(/\:/,$Apache::lonnet::pr{$cr{$type}})) {
7457: my ($priv,$restrict)=split(/\&/,$item);
7458: if (!$restrict) { $restrict='F'; }
7459: $levels->{$type}->{$priv}=$restrict;
7460: if ($privs->{$type}=~/\:$priv/) {
7461: $levelscurrent->{$type}->{$priv}=1;
7462: }
7463: $full->{$priv}=1;
7464: }
7465: }
7466: return;
7467: }
7468:
7469: sub custom_template_roles {
7470: my ($context,$crstype) = @_;
7471: my @template_roles = ("in","ta","ep");
7472: if (($context eq 'domain') || ($context eq 'domprefs')) {
7473: push(@template_roles,"ad");
7474: }
7475: push(@template_roles,"st");
7476: if ($context eq 'domain') {
7477: unshift(@template_roles,('co','cc'));
7478: } else {
7479: if ($crstype eq 'Community') {
7480: unshift(@template_roles,'co');
7481: } else {
7482: unshift(@template_roles,'cc');
7483: }
7484: }
7485: return @template_roles;
7486: }
7487:
7488: sub custom_roledefs_js {
7489: my ($context,$crstype,$formname,$full,$templaterolesref,$jsback) = @_;
7490: my $button_code = "\n";
7491: my $head_script = "\n";
7492: my (%roletitlestr,$rolenamestr);
7493: my %role_titles = (
7494: Course => [],
7495: Community => [],
7496: );
7497: $head_script .= '<script type="text/javascript">'."\n"
7498: .'// <![CDATA['."\n";
7499: if (ref($templaterolesref) eq 'ARRAY') {
7500: if ($context eq 'domain') {
7501: $rolenamestr = join("','",@{$templaterolesref});
7502: }
7503: foreach my $role (@{$templaterolesref}) {
7504: $head_script .= &make_script_template($role,$crstype,$formname);
7505: if ($context eq 'domain') {
7506: foreach my $type ('Course','Community') {
7507: push(@{$role_titles{$type}},&Apache::lonnet::plaintext($role,$type));
7508: }
7509: }
7510: }
7511: }
7512: if ($context eq 'domain') {
7513: foreach my $type ('Course','Community') {
7514: $roletitlestr{$type} = join("','",@{$role_titles{$type}});
7515: }
7516: my %pt = (
7517: Community => {
7518: cst => &mt('Grant/revoke role of Member'),
7519: mdc => &mt('Edit community contents'),
7520: pch => &mt('Post discussion on community resources'),
7521: pfo => &mt('Print for other users and entire community'),
7522: },
7523: Course => {
7524: cst => &mt('Grant/revoke role of Student'),
7525: mdc => &mt('Edit course contents'),
7526: pch => &mt('Post discussion on course resources'),
7527: pfo => &mt('Print for other users and entire course'),
7528: },
7529: );
7530: $head_script .= <<"ENDJS";
7531: function customSwitchType(prefix) {
7532: var privnames = new Array('cst','mdc','pch','pfo');
7533: var privtxtcrs = new Array('$pt{Course}{cst}','$pt{Course}{mdc}','$pt{Course}{pch}','$pt{Course}{pfo}');
7534: var privtxtcom = new Array('$pt{Community}{cst}','$pt{Community}{mdc}','$pt{Community}{pch}','$pt{Community}{pfo}');
7535: var rolenames = new Array('$rolenamestr');
7536: var rolescrs = new Array('$roletitlestr{Course}');
7537: var rolescom = new Array('$roletitlestr{Community}');
7538: var radio = prefix+'_custrolecrstype';
7539: if (document.$formname.elements[radio].length > 1) {
7540: for (var i=0; i<document.$formname.elements[radio].length; i++) {
7541: if (document.$formname.elements[radio][i].checked) {
7542: if ((document.getElementById(prefix+'bre_s')) && (document.getElementById(prefix+'bro_s'))) {
7543: if (document.$formname.elements[radio][i].value == 'Community') {
7544: if (document.getElementById(prefix+'bre_s').checked) {
7545: document.getElementById(prefix+'bro_s').checked = true;
7546: document.getElementById(prefix+'bre_s').checked = false;
7547:
7548: }
7549: document.getElementById(prefix+'bre_s').style.visibility = 'hidden';
7550: } else {
7551: document.getElementById(prefix+'bre_s').style.visibility = 'visible';
7552: if (document.getElementById(prefix+'bro_s').checked) {
7553: document.getElementById(prefix+'bre_s').checked = true;
7554: document.getElementById(prefix+'bro_s').checked = false;
7555: }
7556: }
7557: }
7558: for (var j=0; j<privnames.length; j++) {
7559: if (document.getElementById(prefix+privnames[j])) {
7560: if (document.getElementById(prefix+privnames[j])) {
7561: if (document.$formname.elements[radio][i].value == 'Course') {
7562: document.getElementById(prefix+privnames[j]).innerHTML = privtxtcrs[j];
7563: } else {
7564: document.getElementById(prefix+privnames[j]).innerHTML = privtxtcom[j];
7565: }
7566: }
7567: }
7568: }
7569: for (var j=0; j<rolenames.length; j++) {
7570: if (document.getElementById(prefix+rolenames[j])) {
7571: if (document.getElementById(prefix+rolenames[j])) {
7572: if (document.$formname.elements[radio][i].value == 'Course') {
7573: document.getElementById(prefix+rolenames[j]).value = rolescrs[j];
7574: if (rolenames[j] == 'cc') {
7575: document.getElementById(prefix+rolenames[j]).style.display = 'inline';
7576: }
7577: if (rolenames[j] == 'co') {
7578: document.getElementById(prefix+rolenames[j]).style.display = 'none';
7579: }
7580: } else {
7581: document.getElementById(prefix+rolenames[j]).value = rolescom[j];
7582: if (rolenames[j] == 'cc') {
7583: document.getElementById(prefix+rolenames[j]).style.display = 'none';
7584: }
7585: if (rolenames[j] == 'co') {
7586: document.getElementById(prefix+rolenames[j]).style.display = 'inline';
7587: }
7588: }
7589: }
7590: }
7591: }
7592: }
7593: }
7594: }
7595: return;
7596: }
7597: ENDJS
7598: }
7599: $head_script .= "\n".$jsback."\n"
7600: .'// ]]>'."\n"
7601: .'</script>'."\n";
7602: return $head_script;
7603: }
7604:
7605: # --------------------------------------------------------
7606: sub make_script_template {
7607: my ($role,$crstype,$formname) = @_;
7608: my $return_script = 'function set_'.$role.'(prefix) {'."\n";
7609: my (%full_by_level,%role_priv);
7610: foreach my $level ('c','d','s') {
7611: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
7612: next if (($level eq 's') && ($crstype eq 'Community') && ($item eq 'bre&S'));
7613: my ($priv,$restrict)=split(/\&/,$item);
7614: $full_by_level{$level}{$priv}=1;
7615: }
7616: $role_priv{$level} = {};
7617: my @temp = split(/:/,$Apache::lonnet::pr{$role.':'.$level});
7618: foreach my $priv (@temp) {
7619: my ($priv_item, $dummy) = split(/\&/,$priv);
7620: $role_priv{$level}{$priv_item} = 1;
7621: }
7622: }
7623: my %to_check = (
7624: c => ['c','d','s'],
7625: d => ['d','s'],
7626: s => ['s'],
7627: );
7628: foreach my $level ('c','d','s') {
7629: if (ref($full_by_level{$level}) eq 'HASH') {
7630: foreach my $priv (keys(%{$full_by_level{$level}})) {
7631: my $value = 'false';
7632: if (ref($to_check{$level}) eq 'ARRAY') {
7633: foreach my $lett (@{$to_check{$level}}) {
7634: if (exists($role_priv{$lett}{$priv})) {
7635: $value = 'true';
7636: last;
7637: }
7638: }
7639: $return_script .= "document.$formname.elements[prefix+'".$priv."_".$level."'].checked = $value;\n";
7640: }
7641: }
7642: }
7643: }
7644: $return_script .= '}'."\n";
7645: return ($return_script);
7646: }
7647: # ----------------------------------------------------------
7648: sub make_button_code {
7649: my ($role,$crstype,$display,$prefix) = @_;
7650: my $label = &Apache::lonnet::plaintext($role,$crstype);
7651: my $button_code = '<input type="button" onclick="set_'.$role."('$prefix'".')" '.
7652: 'id="'.$prefix.$role.'" value="'.$label.'" '.
7653: 'style="display:'.$display.'" />';
7654: return ($button_code);
7655: }
7656:
7657: sub custom_role_update {
7658: my ($rolename,$prefix) = @_;
7659: # ------------------------------------------------------- What can be assigned?
7660: my %privs = (
7661: c => '',
7662: d => '',
7663: s => '',
7664: );
7665: foreach my $level (keys(%privs)) {
7666: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
7667: my ($priv,$restrict)=split(/\&/,$item);
7668: if (!$restrict) { $restrict=''; }
7669: if ($env{'form.'.$prefix.$priv.'_'.$level}) {
7670: $privs{$level} .=':'.$item;
7671: }
7672: }
7673: }
7674: return %privs;
7675: }
7676:
1.180 raeburn 7677: sub adhoc_status_types {
7678: my ($cdom,$context,$role,$selectedref,$othertitle,$usertypes,$types,$disabled) = @_;
7679: my $output = &Apache::loncommon::start_data_table();
7680: my $numinrow = 3;
7681: my $rem;
7682: if (ref($types) eq 'ARRAY') {
7683: for (my $i=0; $i<@{$types}; $i++) {
7684: if (defined($usertypes->{$types->[$i]})) {
7685: my $rem = $i%($numinrow);
7686: if ($rem == 0) {
7687: if ($i > 0) {
7688: $output .= &Apache::loncommon::end_data_table_row();
7689: }
7690: $output .= &Apache::loncommon::start_data_table_row();
7691: }
7692: my $check;
7693: if (ref($selectedref) eq 'ARRAY') {
7694: if (grep(/^\Q$types->[$i]\E$/,@{$selectedref})) {
7695: $check = ' checked="checked"';
7696: }
7697: }
7698: $output .= '<td>'.
7699: '<span class="LC_nobreak"><label>'.
7700: '<input type="checkbox" name="'.$context.$role.'_status" '.
7701: 'value="'.$types->[$i].'"'.$check.$disabled.' />'.
7702: $usertypes->{$types->[$i]}.'</label></span></td>';
7703: }
7704: }
7705: $rem = @{$types}%($numinrow);
7706: }
7707: my $colsleft = $numinrow - $rem;
7708: if (($rem == 0) && (@{$types} > 0)) {
7709: $output .= &Apache::loncommon::start_data_table_row();
7710: }
7711: if ($colsleft > 1) {
7712: $output .= '<td colspan="'.$colsleft.'">';
7713: } else {
7714: $output .= '<td>';
7715: }
7716: my $defcheck;
7717: if (ref($selectedref) eq 'ARRAY') {
7718: if (grep(/^default$/,@{$selectedref})) {
7719: $defcheck = ' checked="checked"';
7720: }
7721: }
7722: $output .= '<span class="LC_nobreak"><label>'.
7723: '<input type="checkbox" name="'.$context.$role.'_status"'.
7724: 'value="default"'.$defcheck.$disabled.' />'.
7725: $othertitle.'</label></span></td>'.
7726: &Apache::loncommon::end_data_table_row().
7727: &Apache::loncommon::end_data_table();
7728: return $output;
7729: }
7730:
7731: sub adhoc_staff {
7732: my ($access,$context,$role,$selectedref,$adhocref,$disabled) = @_;
7733: my $output;
7734: if (ref($adhocref) eq 'HASH') {
7735: my %by_fullname;
7736: my $numinrow = 4;
7737: my $rem;
7738: my @personnel = keys(%{$adhocref});
7739: if (@personnel) {
7740: foreach my $person (@personnel) {
7741: my ($uname,$udom) = split(/:/,$person);
7742: my $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
7743: $by_fullname{$fullname} = $person;
7744: }
7745: my @sorted = sort(keys(%by_fullname));
7746: my $count = scalar(@sorted);
7747: $output = &Apache::loncommon::start_data_table();
7748: for (my $i=0; $i<$count; $i++) {
7749: my $rem = $i%($numinrow);
7750: if ($rem == 0) {
7751: if ($i > 0) {
7752: $output .= &Apache::loncommon::end_data_table_row();
7753: }
7754: $output .= &Apache::loncommon::start_data_table_row();
7755: }
7756: my $check;
7757: my $user = $by_fullname{$sorted[$i]};
7758: if (ref($selectedref) eq 'ARRAY') {
7759: if (grep(/^\Q$user\E$/,@{$selectedref})) {
7760: $check = ' checked="checked"';
7761: }
7762: }
7763: if ($i == $count-1) {
7764: my $colsleft = $numinrow - $rem;
7765: if ($colsleft > 1) {
7766: $output .= '<td colspan="'.$colsleft.'">';
7767: } else {
7768: $output .= '<td>';
7769: }
7770: } else {
7771: $output .= '<td>';
7772: }
7773: $output .= '<span class="LC_nobreak"><label>'.
7774: '<input type="checkbox" name="'.$context.$role.'_staff_'.$access.'" '.
7775: 'value="'.$user.'"'.$check.$disabled.' />'.$sorted[$i].
7776: '</label></span></td>';
7777: if ($i == $count-1) {
7778: $output .= &Apache::loncommon::end_data_table_row();
7779: }
7780: }
7781: $output .= &Apache::loncommon::end_data_table();
7782: }
7783: }
7784: return $output;
7785: }
7786:
7787:
1.1 raeburn 7788: 1;
7789:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>