Annotation of loncom/interface/lonuserutils.pm, revision 1.216
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
1.216 ! raeburn 4: # $Id: lonuserutils.pm,v 1.215 2023/08/01 07:48: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.1 raeburn 118: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
119: }
120: if ($context eq 'domain') {
121: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
122: if ($uhome ne 'no_host') {
1.5 raeburn 123: if (($changeauth eq 'Yes') && (&Apache::lonnet::allowed('mau',$udom))) {
1.1 raeburn 124: if ((($umode =~ /^krb4|krb5|internal$/) && $upass ne '') ||
125: ($umode eq 'localauth')) {
126: $authresult = &Apache::lonnet::modifyuserauth($udom,$uname,$umode,$upass);
127: }
128: }
1.5 raeburn 129: if (($forceid) && (&Apache::lonnet::allowed('mau',$udom)) &&
130: ($env{'form.recurseid'}) && ($checkid)) {
131: my %userupdate = (
132: lastname => $last,
133: middlename => $middle,
134: firstname => $first,
135: generation => $gene,
136: id => $uid,
137: );
138: $idresult = &propagate_id_change($uname,$udom,\%userupdate);
139: }
1.1 raeburn 140: }
141: }
142: $userresult =
143: &Apache::lonnet::modifyuser($udom,$uname,$uid,$umode,$upass,$first,
144: $middle,$last,$gene,$forceid,$desiredhome,
1.84 raeburn 145: $email,$inststatus);
1.1 raeburn 146: if ($userresult eq 'ok') {
1.5 raeburn 147: if ($role ne '') {
1.22 raeburn 148: $role =~ s/_/\//g;
1.1 raeburn 149: $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
1.52 raeburn 150: $role,$end,$start,'',
151: '',$context);
1.1 raeburn 152: }
153: }
1.5 raeburn 154: return ($userresult,$authresult,$roleresult,$idresult);
1.1 raeburn 155: }
156:
1.212 raeburn 157: sub role_approval {
158: my ($dom,$context,$process_by,$notifydc) = @_;
159: if (ref($process_by) eq 'HASH') {
160: my %domconfig = &Apache::lonnet::get_dom('configuration',['privacy'],$dom);
161: if (ref($domconfig{'privacy'}) eq 'HASH') {
162: if (ref($notifydc) eq 'ARRAY') {
163: if ($domconfig{'privacy'}{'notify'} ne '') {
164: @{$notifydc} = split(/,/,$domconfig{'privacy'}{'notify'});
165: }
166: }
167: if (ref($domconfig{'privacy'}{'approval'}) eq 'HASH') {
168: my %approvalconf = %{$domconfig{'privacy'}{'approval'}};
169: foreach my $key ('instdom','extdom') {
170: if (ref($approvalconf{$key}) eq 'HASH') {
171: if (keys(%{$approvalconf{$key}})) {
172: $process_by->{$key} = $approvalconf{$key}{$context};
173: }
174: }
175: }
176: }
177: }
178: }
179: return;
180: }
181:
182: sub get_instdoms {
183: my ($udom,$instdoms) = @_;
184: return unless (ref($instdoms) eq 'ARRAY');
185: my @intdoms;
186: my %iphost = &Apache::lonnet::get_iphost();
187: my $primary_id = &Apache::lonnet::domain($udom,'primary');
188: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
189: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
190: foreach my $id (@{$iphost{$primary_ip}}) {
191: my $intdom = &Apache::lonnet::internet_dom($id);
192: unless(grep(/^\Q$intdom\E$/,@intdoms)) {
193: push(@intdoms,$intdom);
194: }
195: }
196: }
197: foreach my $ip (keys(%iphost)) {
198: if (ref($iphost{$ip}) eq 'ARRAY') {
199: foreach my $id (@{$iphost{$ip}}) {
200: my $location = &Apache::lonnet::internet_dom($id);
201: if ($location) {
202: if (grep(/^\Q$location\E$/,@intdoms)) {
203: my $dom = &Apache::lonnet::host_domain($id);
204: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
205: push(@{$instdoms},$dom);
206: }
207: }
208: }
209: }
210: }
211: }
212: return;
213: }
214:
215: sub restricted_dom {
216: my ($context,$key,$udom,$uname,$role,$start,$end,$cdom,$cnum,$csec,$credits,
217: $process_by,$instdoms,$got_role_approvals,$got_instdoms,$reject,$pending,
1.213 raeburn 218: $notifydc,$status,$unauthorized,$currqueued) = @_;
1.212 raeburn 219: return if ($udom eq $cdom);
220: return unless ((ref($process_by) eq 'HASH') && (ref($instdoms) eq 'HASH') &&
221: (ref($got_role_approvals) eq 'HASH') && (ref($got_instdoms) eq 'HASH') &&
222: (ref($reject) eq 'HASH') && (ref($pending) eq 'HASH') &&
1.213 raeburn 223: (ref($notifydc) eq 'HASH') && (ref($status) eq 'HASH') &&
224: (ref($unauthorized) eq 'HASH') && (ref($currqueued) eq 'HASH'));
1.212 raeburn 225: my (%approval,@notify,$gotdata,$skip);
226: if (ref($got_role_approvals->{$context}) eq 'HASH') {
227: if ($got_role_approvals->{$context}{$udom}) {
228: $gotdata = 1;
229: if (ref($process_by->{$context}{$udom}) eq 'HASH') {
230: %approval = %{$process_by->{$context}{$udom}};
231: }
232: }
233: }
234: unless ($gotdata) {
235: &role_approval($udom,$context,\%approval,\@notify);
236: $process_by->{$context} = {
237: $udom => \%approval,
238: };
239: $got_role_approvals->{$context} = {
240: $udom => 1,
241: };
242: $notifydc->{$udom} = \@notify;
243: }
244: if (ref($process_by->{$context}) eq 'HASH') {
245: if (ref($process_by->{$context}{$udom}) eq 'HASH') {
246: my @inst;
247: if ($got_instdoms->{$udom}) {
248: if (ref($instdoms->{$udom}) eq 'ARRAY') {
249: @inst = @{$instdoms->{$udom}};
250: }
251: } else {
252: &get_instdoms(\@inst);
253: $instdoms->{$udom} = \@inst;
254: $got_instdoms->{$udom} = 1;
255: }
256: if (grep(/^\Q$cdom\E$/,@inst)) {
257: if (exists($approval{'instdom'})) {
258: my $rule = $approval{'instdom'};
1.213 raeburn 259: if (($rule eq 'none') || ($rule eq 'user') || ($rule eq 'domain')) {
260: my ($id,$currstatus,$curradj) = &get_othdomreq_status($key,$uname,$udom,$role,$cdom,$cnum,$csec);
261: if (($currstatus ne '') && ($curradj eq $rule)) {
262: $status->{$key}->{$uname.':'.$udom} = $currstatus;
263: }
264: if ($rule eq 'none') {
265: $reject->{$key}->{$uname.':'.$udom} = {
266: cdom => $cdom,
267: cnum => $cnum,
268: csec => $csec,
269: udom => $udom,
270: uname => $uname,
271: role => $role,
272: };
273: $skip = 1;
274: } elsif (($rule eq 'user') || ($rule eq 'domain')) {
275: if ($curradj eq $rule) {
276: unless ($currstatus eq 'approved') {
277: if ($currstatus eq 'rejected') {
278: $unauthorized->{$key}->{$uname.':'.$udom} = {
279: cdom => $cdom,
280: cnum => $cnum,
281: csec => $csec,
282: udom => $udom,
283: uname => $uname,
284: role => $role,
285: };
286: } elsif ($currstatus eq 'pending') {
287: $currqueued->{$key}->{$uname.':'.$udom} = {
288: cdom => $cdom,
289: cnum => $cnum,
290: csec => $csec,
291: udom => $udom,
292: uname => $uname,
293: role => $role,
294: adj => $rule,
295: };
296: }
297: $skip = 1;
298: }
299: } else {
300: $pending->{$key}->{$uname.':'.$udom} = {
301: cdom => $cdom,
302: cnum => $cnum,
303: csec => $csec,
304: udom => $udom,
305: uname => $uname,
306: role => $role,
307: start => $start,
308: end => $end,
309: adj => $rule,
310: };
311: if (($role eq 'st') && ($credits ne '')) {
312: $pending->{$key}->{$uname.':'.$udom}->{'credits'} = $credits;
313: }
314: $skip = 1;
315: }
1.212 raeburn 316: }
317: }
318: }
319: } elsif (exists($approval{'extdom'})) {
320: my $rule = $approval{'extdom'};
1.213 raeburn 321: if (($rule eq 'none') || ($rule eq 'user') || ($rule eq 'domain')) {
322: my ($id,$currstatus,$curradj) = &get_othdomreq_status($key,$uname,$udom,$role,$cdom,$cnum,$csec);
323: if (($currstatus ne '') && ($curradj eq $rule)) {
324: $status->{$key}->{$uname.':'.$udom} = $currstatus;
325: }
326: if ($rule eq 'none') {
327: $reject->{$key}->{$uname.':'.$udom} = {
328: cdom => $cdom,
329: cnum => $cnum,
330: csec => $csec,
331: udom => $udom,
332: uname => $uname,
333: role => $role,
334: };
335: $skip = 1;
336: } elsif (($rule eq 'user') || ($rule eq 'domain')) {
337: if ($curradj eq $rule) {
338: unless ($currstatus eq 'approved') {
339: if ($currstatus eq 'rejected') {
340: $unauthorized->{$key}->{$uname.':'.$udom} = {
341: cdom => $cdom,
342: cnum => $cnum,
343: csec => $csec,
344: udom => $udom,
345: uname => $uname,
346: role => $role,
347: };
348: } elsif ($currstatus eq 'pending') {
349: $currqueued->{$key}->{$uname.':'.$udom} = {
350: cdom => $cdom,
351: cnum => $cnum,
352: csec => $csec,
353: udom => $udom,
354: uname => $uname,
355: role => $role,
356: adj => $rule,
357: };
358: }
359: $skip = 1;
360: }
361: } else {
362: $pending->{$key}->{$uname.':'.$udom} = {
363: cdom => $cdom,
364: cnum => $cnum,
365: csec => $csec,
366: udom => $udom,
367: uname => $uname,
368: role => $role,
369: start => $start,
370: end => $end,
371: adj => $rule,
372: };
373: if (($role eq 'st') && ($credits ne '')) {
374: $pending->{$key}->{$uname.':'.$udom}->{'credits'} = $credits;
375: }
376: $skip = 1;
377: }
1.212 raeburn 378: }
379: }
380: }
381: }
382: }
383: return $skip;
384: }
385:
1.213 raeburn 386: sub get_othdomreq_status {
387: my ($key,$uname,$udom,$role,$cdom,$cnum,$csec) = @_;
388: my $id = $uname.':'.$udom.':'.$role;
389: my ($dbnum,$currstatus,$curradj);
390: if (($role eq 'ca') || ($role eq 'aa')) {
391: $dbnum = $cnum;
392: } elsif ($key eq $cdom.'_'.$role) {
393: $dbnum = &Apache::lonnet::get_domainconfiguser($cdom);
394: } else {
395: $id .= ':'.$csec;
396: $dbnum = $cnum;
397: }
398: my $statusid = 'status&'.$id;
399: my %curr = &Apache::lonnet::get('nohist_othdomqueued',[$id,$statusid],$cdom,$dbnum);
400: if (ref($curr{$id}) eq 'HASH') {
401: $curradj = $curr{$id}{'adj'};
402: }
403: $currstatus = $curr{$statusid};
404: return ($id,$currstatus,$curradj);
405: }
406:
1.212 raeburn 407: sub print_roles_rejected {
1.213 raeburn 408: my ($context,$reject,$unauthorized) = @_;
409: return unless ((ref($reject) eq 'HASH') || (ref($unauthorized) eq 'HASH'));
1.212 raeburn 410: my $output;
411: if (keys(%{$reject}) > 0) {
412: $output = '<p class="LC_warning">'.
413: &mt("The following roles could not be assigned because the user is from another domain, and that domain's policies disallow it").'<ul>';
414: foreach my $key (sort(keys(%{$reject}))) {
415: if (ref($reject->{$key}) eq 'HASH') {
1.213 raeburn 416: foreach my $user (sort(keys(%{$reject->{$key}}))) {
417: if (ref($reject->{$key}->{$user}) eq 'HASH') {
418: my ($crstype,$role,$cdom,$cnum,$csec,$title,$plainrole);
419: $role = $reject->{$key}->{$user}{'role'};
420: $cdom = $reject->{$key}->{$user}{'cdom'};
421: $cnum = $reject->{$key}->{$user}{'cnum'};
422: $csec = $reject->{$key}->{$user}{'csec'};
423: if (($context eq 'domain') && ($cnum ne '')) {
424: if (($role eq 'ca') || ($role eq 'aa')) {
425: $title = &Apache::loncommon::plainname($cnum,$cdom);
426: } else {
427: if (&Apache::lonnet::is_course($cdom,$cnum)) {
428: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
429: $crstype = $coursedata{'type'};
430: $title = $coursedata{'description'};
431: }
432: }
433: } elsif ($context eq 'course') {
434: $crstype = &Apache::loncommon::course_type();
435: }
436: my $plainrole = &Apache::lonnet::plaintext($role,$crstype);
437: $output .= '<li>'.&mt('User: [_1]',$reject->{$key}->{$user}{'uname'}).' | '.
438: &mt('Domain: [_1]',$reject->{$key}->{$user}{'udom'}).' | '.
439: &mt('Role: [_1]',$plainrole);
440: if ($crstype) {
441: if ($csec ne'') {
442: $output .= ' | '.&mt('Section: [_1]',$csec);
443: }
444: } elsif (($context eq 'domain') && (($role eq 'ca') || ($role eq 'aa'))) {
445: $output .= ' | '.&mt('Authoring Space belonging to: [_1]',$title);
446:
447: }
448: if (($context eq 'domain') && ($crstype)) {
449: $output .= ' | '.&mt("$crstype: [_1]",$title);
450: }
451: $output .= '</li>';
1.212 raeburn 452: }
453: }
1.213 raeburn 454: }
455: }
456: $output .= '</ul></p>';
457: }
458: if (keys(%{$unauthorized}) > 0) {
459: $output = '<p class="LC_warning">'.
460: &mt("The following roles could not be assigned because the user is from another domain, and that domain's policies require approval by the user themselves or by a domain coordinator in that domain, and approval has been withheld.").'<ul>';
461: foreach my $key (sort(keys(%{$unauthorized}))) {
462: if (ref($unauthorized->{$key}) eq 'HASH') {
463: foreach my $user (sort(keys(%{$unauthorized->{$key}}))) {
464: if (ref($unauthorized->{$key}->{$user}) eq 'HASH') {
465: my ($crstype,$role,$cdom,$cnum,$csec,$title,$plainrole);
466: $role = $unauthorized->{$key}->{$user}{'role'};
467: $cdom = $unauthorized->{$key}->{$user}{'cdom'};
468: $cnum = $unauthorized->{$key}->{$user}{'cnum'};
469: $csec = $unauthorized->{$key}->{$user}{'csec'};
470: if (($context eq 'domain') && ($cnum ne '')) {
471: if (($role eq 'ca') || ($role eq 'aa')) {
472: $title = &mt('Authoring Space belonging to: [_1]',
473: &Apache::loncommon::plainname($cnum,$cdom));
474: } else {
475: if (&Apache::lonnet::is_course($cdom,$cnum)) {
476: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
477: $crstype = $coursedata{'type'};
478: $title = &mt("$crstype: [_1]",$coursedata{'description'});
479: }
480: }
481: } elsif ($context eq 'course') {
482: $crstype = &Apache::loncommon::course_type();
483: }
484: $plainrole = &Apache::lonnet::plaintext($role,$crstype);
485: $output .= '<li>'.&mt('User: [_1]',$unauthorized->{$key}->{$user}{'uname'}).' | '.
486: &mt('Domain: [_1]',$unauthorized->{$key}->{$user}{'udom'}).' | '.
487: &mt('Role: [_1]',$plainrole);
488: if ($crstype) {
489: if ($csec ne'') {
490: $output .= ' | '.&mt('Section: [_1]',$csec);
491: }
492: }
493: if ($title ne '') {
494: $output .= ' | '.$title;
495: }
496: $output .= '</li>';
497: }
1.212 raeburn 498: }
499: }
500: }
1.213 raeburn 501: $output .= '</ul></p>';
1.212 raeburn 502: }
503: return $output;
504: }
505:
506: sub print_roles_queued {
1.213 raeburn 507: my ($context,$pending,$notifydc,$currqueued) = @_;
508: return unless ((ref($pending) eq 'HASH') && (ref($notifydc) eq 'HASH') &&
509: (ref($currqueued) eq 'HASH'));
1.212 raeburn 510: my $output;
511: if (keys(%{$pending}) > 0) {
512: my $now = time;
513: $output = '<p class="LC_warning">'.
514: &mt("The following role assignments have been queued because the user is from another domain, and that domain's policies require approval by the user themselves or by a domain coordinator in that domain").'<ul>';
515: my (%todom,%touser,%crsqueue,%caqueue,%domqueue);
516: my $requester = $env{'user.name'}.':'.$env{'user.domain'};
517: foreach my $key (sort(keys(%{$pending}))) {
518: if (ref($pending->{$key}) eq 'HASH') {
1.213 raeburn 519: foreach my $user (sort(keys(%{$pending->{$key}}))) {
520: if (ref($pending->{$key}->{$user}) eq 'HASH') {
521: my $role = $pending->{$key}->{$user}{'role'};
522: my $uname = $pending->{$key}->{$user}{'uname'};
523: my $udom = $pending->{$key}->{$user}{'udom'};
524: my $csec = $pending->{$key}->{$user}{'csec'};
525: my $cdom = $pending->{$key}->{$user}{'cdom'};
526: my $cnum = $pending->{$key}->{$user}{'cnum'};
527: my $adj = $pending->{$key}->{$user}{'adj'};
528: my $start = $pending->{$key}->{$user}{'start'};
529: my $end = $pending->{$key}->{$user}{'end'};
530: my $credits = $pending->{$key}->{$user}{'credits'};
531: my $now = time;
532: my ($crstype,$title,$plainrole,$extent,$id,$status);
533: if ($context eq 'course') {
534: $crstype = &Apache::loncommon::course_type();
535: $title = $env{'course.'.$env{'request.course.id'}.'.description'};
536: } elsif ($context eq 'domain') {
537: if (&Apache::lonnet::is_course($cdom,$cnum)) {
538: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
539: $crstype = $coursedata{'type'};
540: $title = $coursedata{'description'};
541: } elsif (($role eq 'ca') || ($role eq 'aa')) {
542: $title = &Apache::loncommon::plainname($cnum,$cdom);
543: }
544: }
545: $plainrole = &Apache::lonnet::plaintext($role,$crstype);
546: $extent = "/$cdom/$cnum";
547: $id = $uname.':'.$udom.':'.$role;
548: if (($context eq 'course') || ($crstype)) {
549: $id .= ':'.$csec;
550: }
551: $output .= '<li>'.&mt('User: [_1]',$uname).' | '.
552: &mt('Domain: [_1]',$udom).' | '.
553: &mt('Role: [_1]',$plainrole);
554: if ($crstype) {
555: if ($csec ne'') {
556: $output .= ' | '.&mt('Section: [_1]',$csec);
557: }
558: } elsif (($context eq 'domain') && (($role eq 'ca') || ($role eq 'aa'))) {
559: $output .= ' | '.&mt('Authoring Space belonging to: [_1]',$title);
560: }
561: if (($context eq 'domain') && ($crstype)) {
562: $output .= ' | '.&mt("$crstype: [_1]",$title);
563: }
564: if (($crstype) && ($csec ne '')) {
565: $extent .= "/$csec";
566: }
567: if ($adj eq 'user') {
568: $output .= '<br />'.&mt('Message sent to user for approval');
569: $touser{$uname.':'.$udom}{'pending:'.$extent.':'.$role} = {
570: timestamp => $now,
571: requester => $requester,
572: start => $start,
573: end => $end,
574: credits => $credits,
575: context => $context,
576: };
577: } elsif ($adj eq 'domain') {
578: $output .= '<br />'.&mt("Message sent to user's domain coordinator for approval");
579: $todom{$udom}{'pending:'.$uname.':'.$extent.':'.$role} = {
580: timestamp => $now,
581: requester => $requester,
582: start => $start,
583: end => $end,
584: credits => $credits,
585: context => $context,
586: };
587: }
588: $output .= '</li>';
589: if (($context eq 'course') || ($crstype)) {
590: $crsqueue{$cdom.'_'.$cnum}{$id} = {
591: timestamp => $now,
592: requester => $requester,
593: adj => $adj,
594: };
595: $crsqueue{$cdom.'_'.$cnum}{'status&'.$id} = 'pending';
596: } elsif (($context eq 'author') ||
597: (($context eq 'domain') && (($role eq 'ca') || ($role eq 'aa')))) {
598: $caqueue{$cnum.':'.$cdom}{$id} = {
599: timestamp => $now,
600: requester => $requester,
601: adj => $adj,
602: };
603: $caqueue{$cnum.':'.$cdom}{'status&'.$id} = 'pending';
604: } elsif ($context eq 'domain') {
605: $domqueue{$id} = {
606: timestamp => $now,
607: requester => $requester,
608: adj => $adj,
609: };
610: $domqueue{'status&'.$id} = 'pending';
611: }
612: }
1.212 raeburn 613: }
614: }
615: }
616: $output .= '</ul></p>';
617: if (keys(%touser)) {
618: foreach my $key (keys(%touser)) {
1.214 raeburn 619: my ($uname,$udom) = split(/:/,$key);
1.213 raeburn 620: if (&Apache::lonnet::put('nohist_queuedrolereqs',$touser{$key},$udom,$uname) eq 'ok') {
1.212 raeburn 621: my $owndomdesc = &Apache::lonnet::domain($udom);
622: &Apache::loncoursequeueadmin::send_selfserve_notification($uname.':'.$udom,
623: '','',$owndomdesc,$now,'othdomroleuser',$requester);
624: }
625: }
626: }
627: if (keys(%todom)) {
628: foreach my $dom (keys(%todom)) {
629: if (ref($todom{$dom}) eq 'HASH') {
630: my $confname = &Apache::lonnet::get_domainconfiguser($dom);
1.213 raeburn 631: if (&Apache::lonnet::put('nohist_queuedrolereqs',$todom{$dom},$dom,$confname) eq 'ok') {
1.212 raeburn 632: if (ref($notifydc->{$dom}) eq 'ARRAY') {
633: if (@{$notifydc->{$dom}} > 0) {
634: my $notifylist = join(',',@{$notifydc->{$dom}});
635: &Apache::loncoursequeueadmin::send_selfserve_notification($notifylist,
636: '','','',$now,'othdomroledc',$requester);
637: }
638: }
639: }
640: }
641: }
642: }
643: if (keys(%crsqueue)) {
644: foreach my $key (keys(%crsqueue)) {
645: my ($cdom,$cnum) = split(/_/,$key);
646: if (ref($crsqueue{$key}) eq 'HASH') {
1.213 raeburn 647: &Apache::lonnet::put('nohist_othdomqueued',$crsqueue{$key},$cdom,$cnum);
1.212 raeburn 648: }
649: }
650: }
651: if (keys(%caqueue)) {
652: foreach my $key (keys(%caqueue)) {
653: my ($auname,$audom) = split(/:/,$key);
654: if (ref($caqueue{$key}) eq 'HASH') {
1.213 raeburn 655: &Apache::lonnet::put('nohist_othdomqueued',$caqueue{$key},$audom,$auname);
1.212 raeburn 656: }
657: }
658: }
659: if (keys(%domqueue)) {
660: my $confname = &Apache::lonnet::get_domainconfiguser($env{'request.role.domain'});
1.213 raeburn 661: &Apache::lonnet::put('nohist_othdomqueued',\%domqueue,$env{'request.role.domain'},$confname);
1.212 raeburn 662: }
663: }
1.213 raeburn 664: if (keys(%{$currqueued}) > 0) {
665: $output = '<p class="LC_warning">'.
666: &mt("The following role assignments were already queued because the user is from another domain, and that domain's policies require approval by the user themselves or by a domain coordinator in that domain").'<ul>';
667: my $requester = $env{'user.name'}.':'.$env{'user.domain'};
668: foreach my $key (sort(keys(%{$currqueued}))) {
669: if (ref($currqueued->{$key}) eq 'HASH') {
670: foreach my $user (sort(keys(%{$currqueued->{$key}}))) {
671: if (ref($currqueued->{$key}->{$user}) eq 'HASH') {
672: my $role = $currqueued->{$key}->{$user}{'role'};
673: my $csec = $currqueued->{$key}->{$user}{'csec'};
674: my $cdom = $currqueued->{$key}->{$user}{'cdom'};
675: my $cnum = $currqueued->{$key}->{$user}{'cnum'};
676: my ($crstype,$title,$plainrole);
677: if ($context eq 'course') {
678: $crstype = &Apache::loncommon::course_type();
679: } elsif (($context eq 'domain') && ($cnum ne '')) {
680: if (($role eq 'ca') || ($role eq 'aa')) {
681: $title = &mt('Authoring Space belonging to: [_1]',
682: &Apache::loncommon::plainname($cnum,$cdom));
683: } elsif (&Apache::lonnet::is_course($cdom,$cnum)) {
684: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
685: $crstype = $coursedata{'type'};
686: $title = &mt("$crstype: [_1]",$coursedata{'description'});
687: }
688: }
689: $plainrole = &Apache::lonnet::plaintext($role,$crstype);
690: $output .= '<li>'.&mt('User: [_1]',$currqueued->{$key}->{$user}{'uname'}).' | '.
691: &mt('Domain: [_1]',$currqueued->{$key}->{$user}{'udom'}).' | '.
692: &mt('Role: [_1]',$plainrole);
693: if ($title ne '') {
694: $output .= ' | '.$title;
695: }
696: if ($crstype) {
697: if ($csec ne '') {
698: $output .= ' | '.&mt('Section: [_1]',$csec);
699: }
700: }
701: $output .= '</li>';
702: }
703: }
704: }
705: }
706: $output .= '</ul></p>';
707: }
1.212 raeburn 708: return $output;
709: }
710:
1.5 raeburn 711: sub propagate_id_change {
712: my ($uname,$udom,$user) = @_;
1.12 raeburn 713: my (@types,@roles);
1.5 raeburn 714: @types = ('active','future');
715: @roles = ('st');
716: my $idresult;
717: my %roleshash = &Apache::lonnet::get_my_roles($uname,
1.12 raeburn 718: $udom,'userroles',\@types,\@roles);
719: my %args = (
720: one_time => 1,
721: );
1.5 raeburn 722: foreach my $item (keys(%roleshash)) {
1.22 raeburn 723: my ($cnum,$cdom,$role) = split(/:/,$item,-1);
1.5 raeburn 724: my ($start,$end) = split(/:/,$roleshash{$item});
725: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.12 raeburn 726: my $result = &update_classlist($cdom,$cnum,$udom,$uname,$user);
727: my %coursehash =
728: &Apache::lonnet::coursedescription($cdom.'_'.$cnum,\%args);
729: my $cdesc = $coursehash{'description'};
730: if ($cdesc eq '') {
731: $cdesc = $cdom.'_'.$cnum;
732: }
1.5 raeburn 733: if ($result eq 'ok') {
1.12 raeburn 734: $idresult .= &mt('Classlist update for "[_1]" in "[_2]".',$uname.':'.$udom,$cdesc).'<br />'."\n";
1.5 raeburn 735: } else {
1.12 raeburn 736: $idresult .= &mt('Error: "[_1]" during classlist update for "[_2]" in "[_3]".',$result,$uname.':'.$udom,$cdesc).'<br />'."\n";
1.5 raeburn 737: }
738: }
739: }
740: return $idresult;
741: }
742:
743: sub update_classlist {
1.63 raeburn 744: my ($cdom,$cnum,$udom,$uname,$user,$newend) = @_;
1.6 albertel 745: my ($uid,$classlistentry);
1.5 raeburn 746: my $fullname =
747: &Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
748: $user->{'lastname'},$user->{'generation'},
749: 'lastname');
750: my %classhash = &Apache::lonnet::get('classlist',[$uname.':'.$udom],
751: $cdom,$cnum);
752: my @classinfo = split(/:/,$classhash{$uname.':'.$udom});
753: my $ididx=&Apache::loncoursedata::CL_ID() - 2;
754: my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2;
1.63 raeburn 755: my $endidx = &Apache::loncoursedata::CL_END() - 2;
756: my $startidx = &Apache::loncoursedata::CL_START() - 2;
1.5 raeburn 757: for (my $i=0; $i<@classinfo; $i++) {
1.63 raeburn 758: if ($i == $endidx) {
759: if ($newend ne '') {
760: $classlistentry .= $newend.':';
761: } else {
762: $classlistentry .= $classinfo[$i].':';
763: }
764: } elsif ($i == $startidx) {
765: if ($newend ne '') {
766: if ($classinfo[$i] > $newend) {
767: $classlistentry .= $newend.':';
768: } else {
769: $classlistentry .= $classinfo[$i].':';
770: }
771: } else {
772: $classlistentry .= $classinfo[$i].':';
773: }
774: } elsif ($i == $ididx) {
1.5 raeburn 775: if (defined($user->{'id'})) {
776: $classlistentry .= $user->{'id'}.':';
777: } else {
778: $classlistentry .= $classinfo[$i].':';
779: }
780: } elsif ($i == $nameidx) {
1.63 raeburn 781: if (defined($user->{'lastname'})) {
782: $classlistentry .= $fullname.':';
783: } else {
784: $classlistentry .= $classinfo[$i].':';
785: }
1.5 raeburn 786: } else {
787: $classlistentry .= $classinfo[$i].':';
788: }
789: }
790: $classlistentry =~ s/:$//;
791: my $reply=&Apache::lonnet::cput('classlist',
792: {"$uname:$udom" => $classlistentry},
793: $cdom,$cnum);
794: if (($reply eq 'ok') || ($reply eq 'delayed')) {
795: return 'ok';
796: } else {
797: return 'error: '.$reply;
798: }
799: }
800:
801:
1.1 raeburn 802: ###############################################################
803: ###############################################################
1.2 raeburn 804: # build a role type and role selection form
805: sub domain_roles_select {
806: # Set up the role type and role selection boxes when in
807: # domain context
808: #
809: # Role types
1.101 raeburn 810: my @roletypes = ('domain','author','course','community');
1.2 raeburn 811: my %lt = &role_type_names();
1.149 raeburn 812: my $onchangefirst = "updateCols('showrole')";
813: my $onchangesecond = "updateCols('showrole')";
1.1 raeburn 814: #
815: # build up the menu information to be passed to
816: # &Apache::loncommon::linked_select_forms
817: my %select_menus;
1.2 raeburn 818: if ($env{'form.roletype'} eq '') {
819: $env{'form.roletype'} = 'domain';
820: }
821: foreach my $roletype (@roletypes) {
1.1 raeburn 822: # set up the text for this domain
1.2 raeburn 823: $select_menus{$roletype}->{'text'}= $lt{$roletype};
1.102 raeburn 824: my $crstype;
825: if ($roletype eq 'community') {
826: $crstype = 'Community';
827: }
1.1 raeburn 828: # we want a choice of 'default' as the default in the second menu
1.2 raeburn 829: if ($env{'form.roletype'} ne '') {
830: $select_menus{$roletype}->{'default'} = $env{'form.showrole'};
831: } else {
832: $select_menus{$roletype}->{'default'} = 'Any';
833: }
1.1 raeburn 834: # Now build up the other items in the second menu
1.2 raeburn 835: my @roles;
836: if ($roletype eq 'domain') {
837: @roles = &domain_roles();
1.13 raeburn 838: } elsif ($roletype eq 'author') {
1.2 raeburn 839: @roles = &construction_space_roles();
840: } else {
1.17 raeburn 841: my $custom = 1;
1.101 raeburn 842: @roles = &course_roles('domain',undef,$custom,$roletype);
1.1 raeburn 843: }
1.2 raeburn 844: my $order = ['Any',@roles];
845: $select_menus{$roletype}->{'order'} = $order;
846: foreach my $role (@roles) {
1.5 raeburn 847: if ($role eq 'cr') {
848: $select_menus{$roletype}->{'select2'}->{$role} =
849: &mt('Custom role');
850: } else {
851: $select_menus{$roletype}->{'select2'}->{$role} =
1.102 raeburn 852: &Apache::lonnet::plaintext($role,$crstype);
1.5 raeburn 853: }
1.2 raeburn 854: }
855: $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
1.1 raeburn 856: }
1.2 raeburn 857: my $result = &Apache::loncommon::linked_select_forms
858: ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
1.101 raeburn 859: 'roletype','showrole',\%select_menus,
1.149 raeburn 860: ['domain','author','course','community'],$onchangefirst,
861: $onchangesecond);
1.1 raeburn 862: return $result;
863: }
864:
865: ###############################################################
866: ###############################################################
867: sub hidden_input {
868: my ($name,$value) = @_;
869: return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n";
870: }
871:
872: sub print_upload_manager_header {
1.123 raeburn 873: my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype,
874: $can_assign)=@_;
1.1 raeburn 875: my $javascript;
876: #
877: if (! exists($env{'form.upfile_associate'})) {
878: $env{'form.upfile_associate'} = 'forward';
879: }
880: if ($env{'form.associate'} eq 'Reverse Association') {
881: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
882: $env{'form.upfile_associate'} = 'reverse';
883: } else {
884: $env{'form.upfile_associate'} = 'forward';
885: }
886: }
887: if ($env{'form.upfile_associate'} eq 'reverse') {
1.123 raeburn 888: $javascript=&upload_manager_javascript_reverse_associate($can_assign);
1.1 raeburn 889: } else {
1.123 raeburn 890: $javascript=&upload_manager_javascript_forward_associate($can_assign);
1.1 raeburn 891: }
892: #
893: # Deal with restored settings
894: my $password_choice = '';
895: if (exists($env{'form.ipwd_choice'}) &&
896: $env{'form.ipwd_choice'} ne '') {
897: # If a column was specified for password, assume it is for an
898: # internal password. This is a bug waiting to be filed (could be
899: # local or krb auth instead of internal) but I do not have the
900: # time to mess around with this now.
901: $password_choice = 'int';
902: }
903: #
1.22 raeburn 904: my $groupslist;
905: if ($context eq 'course') {
906: $groupslist = &get_groupslist();
907: }
1.1 raeburn 908: my $javascript_validations =
1.22 raeburn 909: &javascript_validations('upload',$krbdefdom,$password_choice,undef,
910: $env{'request.role.domain'},$context,
1.103 raeburn 911: $groupslist,$crstype);
1.91 bisitz 912: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.147 bisitz 913: $r->print(
914: '<h3>'.&mt('Identify fields in uploaded list')."</h3>\n".
915: '<p class="LC_info">'.
916: &mt('Total number of records found in file: [_1]'
917: ,'<b>'.$distotal.'</b>').
918: "</p>\n"
919: );
920: if ($distotal == 0) {
921: $r->print('<p class="LC_warning">'.&mt('None found').'</p>');
922: }
923: $r->print(
924: '<p>'.
925: &mt('Enter as many fields as you can.').'<br />'.
926: &mt('The system will inform you and bring you back to this page,[_1]if the data selected are insufficient to add users.','<br />').
927: "</p>\n"
928: );
1.1 raeburn 929: $r->print(&hidden_input('action','upload').
930: &hidden_input('state','got_file').
931: &hidden_input('associate','').
932: &hidden_input('datatoken',$datatoken).
933: &hidden_input('fileupload',$env{'form.fileupload'}).
934: &hidden_input('upfiletype',$env{'form.upfiletype'}).
935: &hidden_input('upfile_associate',$env{'form.upfile_associate'}));
1.147 bisitz 936: $r->print(
937: '<div class="LC_left_float">'.
938: '<fieldset><legend>'.&mt('Functions').'</legend>'.
939: '<label><input type="checkbox" name="noFirstLine"'.$checked.' />'.
940: &mt('Ignore First Line').'</label>'.
941: ' <input type="button" value="'.&mt('Reverse Association').'" '.
1.59 bisitz 942: 'name="Reverse Association" '.
1.147 bisitz 943: 'onclick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />'.
944: '</fieldset></div><br clear="all" />'
945: );
946: $r->print(
947: '<script type="text/javascript" language="Javascript">'."\n".
948: '// <![CDATA['."\n".
949: $javascript."\n".$javascript_validations."\n".
950: '// ]]>'."\n".
951: '</script>'
952: );
1.1 raeburn 953: }
954:
955: ###############################################################
956: ###############################################################
957: sub javascript_validations {
1.22 raeburn 958: my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain,
1.103 raeburn 959: $context,$groupslist,$crstype)=@_;
1.22 raeburn 960: my %param = (
961: kerb_def_dom => $krbdefdom,
962: curr_authtype => $curr_authtype,
963: );
1.37 raeburn 964: if ($mode eq 'upload') {
1.22 raeburn 965: $param{'formname'} = 'studentform';
1.1 raeburn 966: } elsif ($mode eq 'createcourse') {
1.22 raeburn 967: $param{'formname'} = 'ccrs';
1.1 raeburn 968: } elsif ($mode eq 'modifycourse') {
1.22 raeburn 969: $param{'formname'} = 'cmod';
970: $param{'mode'} = 'modifycourse',
971: $param{'curr_autharg'} = $curr_authfield;
972: }
973:
1.150 raeburn 974: my $showcredits;
975: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
1.160 raeburn 976: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
1.150 raeburn 977: $showcredits = 1;
978: }
979:
1.22 raeburn 980: my ($setsection_call,$setsections_js);
981: my $finish = " vf.submit();\n";
982: if ($mode eq 'upload') {
983: if (($context eq 'course') || ($context eq 'domain')) {
984: if ($context eq 'course') {
985: if ($env{'request.course.sec'} eq '') {
1.109 raeburn 986: $setsection_call = 'setSections(document.'.$param{'formname'}.",'$crstype'".');';
1.22 raeburn 987: $setsections_js =
988: &setsections_javascript($param{'formname'},$groupslist,
1.150 raeburn 989: $mode,'',$crstype,$showcredits);
1.22 raeburn 990: } else {
991: $setsection_call = "'ok'";
992: }
993: } elsif ($context eq 'domain') {
994: $setsection_call = 'setCourse()';
1.150 raeburn 995: $setsections_js = &dc_setcourse_js($param{'formname'},$mode,
1.196 raeburn 996: $context,$showcredits,$domain);
1.22 raeburn 997: }
998: $finish = " var checkSec = $setsection_call\n".
999: " if (checkSec == 'ok') {\n".
1000: " vf.submit();\n".
1001: " }\n";
1002: }
1.1 raeburn 1003: }
1.22 raeburn 1004: my $authheader = &Apache::loncommon::authform_header(%param);
1.1 raeburn 1005:
1006: my %alert = &Apache::lonlocal::texthash
1007: (username => 'You need to specify the username field.',
1008: authen => 'You must choose an authentication type.',
1009: krb => 'You need to specify the Kerberos domain.',
1010: ipass => 'You need to specify the initial password.',
1011: name => 'The optional name field was not specified.',
1.93 bisitz 1012: snum => 'The optional student/employee ID field was not specified.',
1.1 raeburn 1013: section => 'The optional section field was not specified.',
1.75 schafran 1014: email => 'The optional e-mail address field was not specified.',
1.1 raeburn 1015: role => 'The optional role field was not specified.',
1.57 raeburn 1016: domain => 'The optional domain field was not specified.',
1.1 raeburn 1017: continue => 'Continue adding users?',
1018: );
1.150 raeburn 1019: if ($showcredits) {
1020: $alert{'credits'} = &mt('The optional credits field was not specified');
1021: }
1.84 raeburn 1022: if (($mode eq 'upload') && ($context eq 'domain')) {
1023: $alert{'inststatus'} = &mt('The optional affiliation field was not specified');
1024: }
1.170 damieng 1025: &js_escape(\%alert);
1.37 raeburn 1026: my $function_name = <<"END";
1.22 raeburn 1027: $setsections_js
1028:
1.150 raeburn 1029: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits) {
1.1 raeburn 1030: END
1031: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($domain);
1032: my $auth_checks;
1033: if ($mode eq 'createcourse') {
1034: $auth_checks .= (<<END);
1035: if (vf.autoadds[0].checked == true) {
1036: if (current.radiovalue == null || current.radiovalue == 'nochange') {
1037: alert('$alert{'authen'}');
1038: return;
1039: }
1040: }
1041: END
1042: } else {
1043: $auth_checks .= (<<END);
1044: var foundatype=0;
1045: if (founduname==0) {
1046: alert('$alert{'username'}');
1047: return;
1048: }
1049:
1050: END
1051: if ($authnum > 1) {
1052: $auth_checks .= (<<END);
1053: if (current.radiovalue == null || current.radiovalue == '' || current.radiovalue == 'nochange') {
1054: // They did not check any of the login radiobuttons.
1055: alert('$alert{'authen'}');
1056: return;
1057: }
1058: END
1059: }
1060: }
1061: if ($mode eq 'createcourse') {
1062: $auth_checks .= "
1063: if ( (vf.autoadds[0].checked == true) &&
1064: (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') ) {
1065: ";
1066: } elsif ($mode eq 'modifycourse') {
1067: $auth_checks .= "
1.215 raeburn 1068: if ((current.argfield !== null) && (current.argfield !== undefined) && (current.argfield !== '') && (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '')) {
1.1 raeburn 1069: ";
1070: }
1071: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
1072: $auth_checks .= (<<END);
1073: var alertmsg = '';
1074: switch (current.radiovalue) {
1075: case 'krb':
1076: alertmsg = '$alert{'krb'}';
1077: break;
1078: default:
1079: alertmsg = '';
1080: }
1081: if (alertmsg != '') {
1082: alert(alertmsg);
1083: return;
1084: }
1085: }
1.150 raeburn 1086: /* regexp here to check for non \d \. in credits */
1.1 raeburn 1087: END
1088: } else {
1.196 raeburn 1089: my ($numrules,$intargjs) =
1.210 raeburn 1090: &Apache::loncommon::passwd_validation_js('vf.elements[current.argfield].value',$domain);
1.1 raeburn 1091: $auth_checks .= (<<END);
1092: foundatype=1;
1093: if (current.argfield == null || current.argfield == '') {
1.196 raeburn 1094: // The login radiobutton checked does not have an associated textbox
1095: } else if (vf.elements[current.argfield].value == '') {
1.1 raeburn 1096: var alertmsg = '';
1.38 raeburn 1097: switch (current.radiovalue) {
1.1 raeburn 1098: case 'krb':
1099: alertmsg = '$alert{'krb'}';
1100: break;
1.196 raeburn 1101: case 'int':
1.1 raeburn 1102: alertmsg = '$alert{'ipass'}';
1103: break;
1104: case 'fsys':
1.196 raeburn 1105: alertmsg = '$alert{'ipass'}';
1.1 raeburn 1106: break;
1.209 raeburn 1107: case 'loc':
1108: alertmsg = '';
1109: break;
1.194 raeburn 1110: case 'lti':
1.1 raeburn 1111: default:
1112: alertmsg = '';
1113: }
1114: if (alertmsg != '') {
1115: alert(alertmsg);
1116: return;
1117: }
1.196 raeburn 1118: } else if (current.radiovalue == 'int') {
1119: if ($numrules > 0) {
1120: $intargjs
1121: }
1.1 raeburn 1122: }
1123: END
1124: }
1125: my $section_checks;
1126: my $optional_checks = '';
1127: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
1128: $optional_checks = (<<END);
1129: vf.submit();
1130: }
1131: END
1132: } else {
1133: $section_checks = §ion_check_js();
1134: $optional_checks = (<<END);
1135: var message='';
1136: if (foundname==0) {
1137: message='$alert{'name'}';
1138: }
1139: if (foundid==0) {
1140: if (message!='') {
1141: message+='\\n';
1142: }
1143: message+='$alert{'snum'}';
1144: }
1145: if (foundsec==0) {
1146: if (message!='') {
1147: message+='\\n';
1148: }
1.130 raeburn 1149: message+='$alert{'section'}';
1.1 raeburn 1150: }
1151: if (foundemail==0) {
1152: if (message!='') {
1153: message+='\\n';
1154: }
1155: message+='$alert{'email'}';
1156: }
1.57 raeburn 1157: if (foundrole==0) {
1158: if (message!='') {
1159: message+='\\n';
1160: }
1161: message+='$alert{'role'}';
1162: }
1163: if (founddomain==0) {
1164: if (message!='') {
1165: message+='\\n';
1166: }
1167: message+='$alert{'domain'}';
1168: }
1.84 raeburn 1169: END
1.150 raeburn 1170: if ($showcredits) {
1171: $optional_checks .= <<END;
1172: if (foundcredits==0) {
1173: if (message!='') {
1174: message+='\\n';
1175: }
1176: message+='$alert{'credits'}';
1177: }
1178: END
1179: }
1.84 raeburn 1180: if (($mode eq 'upload') && ($context eq 'domain')) {
1181: $optional_checks .= (<<END);
1182:
1183: if (foundinststatus==0) {
1184: if (message!='') {
1185: message+='\\n';
1186: }
1187: message+='$alert{'inststatus'}';
1188: }
1189: END
1190: }
1191: $optional_checks .= (<<END);
1192:
1.1 raeburn 1193: if (message!='') {
1194: message+= '\\n$alert{'continue'}';
1195: if (confirm(message)) {
1196: vf.state.value='enrolling';
1.22 raeburn 1197: $finish
1.1 raeburn 1198: }
1199: } else {
1200: vf.state.value='enrolling';
1.22 raeburn 1201: $finish
1.1 raeburn 1202: }
1203: }
1204: END
1205: }
1.37 raeburn 1206: my $result = $function_name.$auth_checks.$optional_checks."\n".
1207: $section_checks.$authheader;
1.1 raeburn 1208: return $result;
1209: }
1.196 raeburn 1210:
1.1 raeburn 1211: ###############################################################
1212: ###############################################################
1213: sub upload_manager_javascript_forward_associate {
1.123 raeburn 1214: my ($can_assign) = @_;
1.132 raeburn 1215: my ($auth_update,$numbuttons,$argreset);
1.123 raeburn 1216: if (ref($can_assign) eq 'HASH') {
1.132 raeburn 1217: if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
1218: $argreset .= " vf.krbarg.value='';\n";
1219: $numbuttons ++ ;
1220: }
1221: if ($can_assign->{'int'}) {
1222: $argreset .= " vf.intarg.value='';\n";
1223: $numbuttons ++;
1224: }
1225: if ($can_assign->{'loc'}) {
1226: $argreset .= " vf.locarg.value='';\n";
1227: $numbuttons ++;
1228: }
1229: if (!$can_assign->{'int'}) {
1.170 damieng 1230: my $warning = &mt('You may not specify an initial password for each user, as this is only available when new users use LON-CAPA internal authentication.')."\n".
1.132 raeburn 1231: &mt('Your current role does not have rights to create users with that authentication type.');
1.170 damieng 1232: &js_escape(\$warning);
1.132 raeburn 1233: $auth_update = <<"END";
1234: // Currently the initial password field is only supported for internal auth
1235: // (see bug 6368).
1236: if (nw==9) {
1237: eval('vf.f'+tf+'.selectedIndex=0;')
1238: alert('$warning');
1239: }
1240: END
1241: } elsif ($numbuttons > 1) {
1.123 raeburn 1242: $auth_update = <<"END";
1243: // If we set the password, make the password form below correspond to
1244: // the new value.
1245: if (nw==9) {
1246: changed_radio('int',document.studentform);
1247: set_auth_radio_buttons('int',document.studentform);
1.132 raeburn 1248: $argreset
1249: }
1250:
1.123 raeburn 1251: END
1252: }
1253: }
1254:
1.1 raeburn 1255: return(<<ENDPICK);
1256: function verify(vf,sec_caller) {
1257: var founduname=0;
1258: var foundpwd=0;
1259: var foundname=0;
1260: var foundid=0;
1261: var foundsec=0;
1262: var foundemail=0;
1263: var foundrole=0;
1.57 raeburn 1264: var founddomain=0;
1.84 raeburn 1265: var foundinststatus=0;
1.150 raeburn 1266: var foundcredits=0;
1.1 raeburn 1267: var tw;
1268: for (i=0;i<=vf.nfields.value;i++) {
1269: tw=eval('vf.f'+i+'.selectedIndex');
1270: if (tw==1) { founduname=1; }
1271: if ((tw>=2) && (tw<=6)) { foundname=1; }
1272: if (tw==7) { foundid=1; }
1273: if (tw==8) { foundsec=1; }
1274: if (tw==9) { foundpwd=1; }
1275: if (tw==10) { foundemail=1; }
1276: if (tw==11) { foundrole=1; }
1.57 raeburn 1277: if (tw==12) { founddomain=1; }
1.84 raeburn 1278: if (tw==13) { foundinststatus=1; }
1.150 raeburn 1279: if (tw==14) { foundcredits=1; }
1.1 raeburn 1280: }
1.150 raeburn 1281: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits);
1.1 raeburn 1282: }
1283:
1284: //
1285: // vf = this.form
1286: // tf = column number
1287: //
1288: // values of nw
1289: //
1290: // 0 = none
1291: // 1 = username
1292: // 2 = names (lastname, firstnames)
1293: // 3 = fname (firstname)
1294: // 4 = mname (middlename)
1295: // 5 = lname (lastname)
1296: // 6 = gen (generation)
1297: // 7 = id
1298: // 8 = section
1299: // 9 = ipwd (password)
1300: // 10 = email address
1301: // 11 = role
1.57 raeburn 1302: // 12 = domain
1.84 raeburn 1303: // 13 = inststatus
1.150 raeburn 1304: // 14 = foundcredits
1.1 raeburn 1305:
1306: function flip(vf,tf) {
1307: var nw=eval('vf.f'+tf+'.selectedIndex');
1308: var i;
1309: // make sure no other columns are labeled the same as this one
1310: for (i=0;i<=vf.nfields.value;i++) {
1311: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
1312: eval('vf.f'+i+'.selectedIndex=0;')
1313: }
1314: }
1315: // If we set this to 'lastname, firstnames', clear out all the ones
1316: // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
1317: if (nw==2) {
1318: for (i=0;i<=vf.nfields.value;i++) {
1319: if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
1320: (eval('vf.f'+i+'.selectedIndex')<=6)) {
1321: eval('vf.f'+i+'.selectedIndex=0;')
1322: }
1323: }
1324: }
1325: // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
1326: // clear out any that are set to 'lastname, firstnames' (2)
1327: if ((nw>=3) && (nw<=6)) {
1328: for (i=0;i<=vf.nfields.value;i++) {
1329: if (eval('vf.f'+i+'.selectedIndex')==2) {
1330: eval('vf.f'+i+'.selectedIndex=0;')
1331: }
1332: }
1333: }
1.123 raeburn 1334: $auth_update
1.1 raeburn 1335: }
1336:
1337: function clearpwd(vf) {
1338: var i;
1339: for (i=0;i<=vf.nfields.value;i++) {
1340: if (eval('vf.f'+i+'.selectedIndex')==9) {
1341: eval('vf.f'+i+'.selectedIndex=0;')
1342: }
1343: }
1344: }
1345:
1346: ENDPICK
1347: }
1348:
1349: ###############################################################
1350: ###############################################################
1351: sub upload_manager_javascript_reverse_associate {
1.123 raeburn 1352: my ($can_assign) = @_;
1.132 raeburn 1353: my ($auth_update,$numbuttons,$argreset);
1.123 raeburn 1354: if (ref($can_assign) eq 'HASH') {
1.132 raeburn 1355: if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
1356: $argreset .= " vf.krbarg.value='';\n";
1357: $numbuttons ++ ;
1358: }
1359: if ($can_assign->{'int'}) {
1360: $argreset .= " vf.intarg.value='';\n";
1361: $numbuttons ++;
1362: }
1363: if ($can_assign->{'loc'}) {
1364: $argreset .= " vf.locarg.value='';\n";
1365: $numbuttons ++;
1366: }
1367: if (!$can_assign->{'int'}) {
1368: my $warning = &mt('You may not specify an initial password, as this is only available when new users use LON-CAPA internal authentication.\n').
1369: &mt('Your current role does not have rights to create users with that authentication type.');
1.170 damieng 1370: &js_escape(\$warning);
1.132 raeburn 1371: $auth_update = <<"END";
1372: // Currently the initial password field is only supported for internal auth
1373: // (see bug 6368).
1374: if (tf==8 && nw!=0) {
1375: eval('vf.f'+tf+'.selectedIndex=0;')
1376: alert('$warning');
1377: }
1378: END
1379: } elsif ($numbuttons > 1) {
1.123 raeburn 1380: $auth_update = <<"END";
1381: // initial password specified, pick internal authentication
1382: if (tf==8 && nw!=0) {
1383: changed_radio('int',document.studentform);
1384: set_auth_radio_buttons('int',document.studentform);
1.132 raeburn 1385: $argreset
1386: }
1387:
1.123 raeburn 1388: END
1389: }
1390: }
1.132 raeburn 1391:
1.1 raeburn 1392: return(<<ENDPICK);
1393: function verify(vf,sec_caller) {
1394: var founduname=0;
1395: var foundpwd=0;
1396: var foundname=0;
1397: var foundid=0;
1398: var foundsec=0;
1.131 raeburn 1399: var foundemail=0;
1.1 raeburn 1400: var foundrole=0;
1.57 raeburn 1401: var founddomain=0;
1.84 raeburn 1402: var foundinststatus=0;
1.150 raeburn 1403: var foundcredits=0;
1.1 raeburn 1404: var tw;
1405: for (i=0;i<=vf.nfields.value;i++) {
1406: tw=eval('vf.f'+i+'.selectedIndex');
1407: if (i==0 && tw!=0) { founduname=1; }
1408: if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
1409: if (i==6 && tw!=0) { foundid=1; }
1410: if (i==7 && tw!=0) { foundsec=1; }
1411: if (i==8 && tw!=0) { foundpwd=1; }
1.130 raeburn 1412: if (i==9 && tw!=0) { foundemail=1; }
1413: if (i==10 && tw!=0) { foundrole=1; }
1414: if (i==11 && tw!=0) { founddomain=1; }
1415: if (i==12 && tw!=0) { foundinstatus=1; }
1.150 raeburn 1416: if (i==13 && tw!=0) { foundcredits=1; }
1.1 raeburn 1417: }
1.150 raeburn 1418: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits);
1.1 raeburn 1419: }
1420:
1421: function flip(vf,tf) {
1422: var nw=eval('vf.f'+tf+'.selectedIndex');
1423: var i;
1424: // picked the all one name field, reset the other name ones to blank
1425: if (tf==1 && nw!=0) {
1426: for (i=2;i<=5;i++) {
1427: eval('vf.f'+i+'.selectedIndex=0;')
1428: }
1429: }
1430: //picked one of the piecewise name fields, reset the all in
1431: //one field to blank
1432: if ((tf>=2) && (tf<=5) && (nw!=0)) {
1433: eval('vf.f1.selectedIndex=0;')
1434: }
1.123 raeburn 1435: $auth_update
1.1 raeburn 1436: }
1437:
1438: function clearpwd(vf) {
1439: var i;
1440: if (eval('vf.f8.selectedIndex')!=0) {
1441: eval('vf.f8.selectedIndex=0;')
1442: }
1443: }
1444: ENDPICK
1445: }
1446:
1447: ###############################################################
1448: ###############################################################
1449: sub print_upload_manager_footer {
1.150 raeburn 1450: my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context,$permission,$crstype,
1451: $showcredits) = @_;
1.22 raeburn 1452: my $form = 'document.studentform';
1453: my $formname = 'studentform';
1.1 raeburn 1454: my ($krbdef,$krbdefdom) =
1455: &Apache::loncommon::get_kerberos_defaults($defdom);
1.22 raeburn 1456: my %param = ( formname => $form,
1.1 raeburn 1457: kerb_def_dom => $krbdefdom,
1458: kerb_def_auth => $krbdef
1459: );
1460: if (exists($env{'form.ipwd_choice'}) &&
1461: defined($env{'form.ipwd_choice'}) &&
1462: $env{'form.ipwd_choice'} ne '') {
1463: $param{'curr_authtype'} = 'int';
1464: }
1465: my $krbform = &Apache::loncommon::authform_kerberos(%param);
1466: my $intform = &Apache::loncommon::authform_internal(%param);
1467: my $locform = &Apache::loncommon::authform_local(%param);
1.194 raeburn 1468: my $ltiform = &Apache::loncommon::authform_lti(%param);
1.22 raeburn 1469: my $date_table = &date_setting_table(undef,undef,$context,undef,
1.101 raeburn 1470: $formname,$permission,$crstype);
1.95 bisitz 1471:
1.1 raeburn 1472: my $Str = "\n".'<div class="LC_left_float">';
1473: $Str .= &hidden_input('nfields',$i);
1474: $Str .= &hidden_input('keyfields',$keyfields);
1.95 bisitz 1475:
1476: $Str .= '<h3>'.&mt('Options').'</h3>'
1477: .&Apache::lonhtmlcommon::start_pick_box();
1478:
1479: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Login Type'));
1.1 raeburn 1480: if ($context eq 'domain') {
1.95 bisitz 1481: $Str .= '<p>'
1482: .&mt('Change authentication for existing users in domain "[_1]" to these settings?'
1483: ,$defdom)
1484: .' <span class="LC_nobreak"><label>'
1485: .'<input type="radio" name="changeauth" value="No" checked="checked" />'
1486: .&mt('No').'</label>'
1487: .' <label>'
1488: .'<input type="radio" name="changeauth" value="Yes" />'
1489: .&mt('Yes').'</label>'
1490: .'</span></p>';
1.1 raeburn 1491: } else {
1.95 bisitz 1492: $Str .= '<p class="LC_info">'."\n".
1493: &mt('This will not take effect if the user already exists.').
1.1 raeburn 1494: &Apache::loncommon::help_open_topic('Auth_Options').
1495: "</p>\n";
1496: }
1.194 raeburn 1497: $Str .= &set_login($defdom,$krbform,$intform,$locform,$ltiform);
1.95 bisitz 1498:
1.1 raeburn 1499: my ($home_server_pick,$numlib) =
1500: &Apache::loncommon::home_server_form_item($defdom,'lcserver',
1501: 'default','hide');
1502: if ($numlib > 1) {
1.97 raeburn 1503: $Str .= &Apache::lonhtmlcommon::row_closure()
1504: .&Apache::lonhtmlcommon::row_title(
1.95 bisitz 1505: &mt('LON-CAPA Home Server for New Users'))
1506: .&mt('LON-CAPA domain: [_1] with home server:','"'.$defdom.'"')
1507: .$home_server_pick
1508: .&Apache::lonhtmlcommon::row_closure();
1509: } else {
1.97 raeburn 1510: $Str .= $home_server_pick.
1511: &Apache::lonhtmlcommon::row_closure();
1.95 bisitz 1512: }
1513:
1.188 raeburn 1514: my ($trusted,$untrusted);
1.185 raeburn 1515: if ($context eq 'course') {
1.188 raeburn 1516: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.185 raeburn 1517: } elsif ($context eq 'author') {
1.188 raeburn 1518: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.185 raeburn 1519: }
1.95 bisitz 1520: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain'))
1.188 raeburn 1521: .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1,undef,$trusted,$untrusted)
1.95 bisitz 1522: .&Apache::lonhtmlcommon::row_closure();
1523:
1524: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Starting and Ending Dates'))
1525: ."<p>\n".$date_table."</p>\n"
1526: .&Apache::lonhtmlcommon::row_closure();
1527:
1.1 raeburn 1528: if ($context eq 'domain') {
1.95 bisitz 1529: $Str .= &Apache::lonhtmlcommon::row_title(
1530: &mt('Settings for assigning roles'))
1531: .&mt('Pick the action to take on roles for these users:').'<br />'
1532: .'<span class="LC_nobreak"><label>'
1533: .'<input type="radio" name="roleaction" value="norole" checked="checked" />'
1534: .' '.&mt('No role changes').'</label>'
1535: .' <label>'
1536: .'<input type="radio" name="roleaction" value="domain" />'
1537: .' '.&mt('Add a domain role').'</label>'
1538: .' <label>'
1539: .'<input type="radio" name="roleaction" value="course" />'
1.103 raeburn 1540: .' '.&mt('Add a course/community role').'</label>'
1.95 bisitz 1541: .'</span>';
1542: } elsif ($context eq 'author') {
1543: $Str .= &Apache::lonhtmlcommon::row_title(
1544: &mt('Default role'))
1545: .&mt('Choose the role to assign to users without a value specified in the uploaded file.')
1.1 raeburn 1546: } elsif ($context eq 'course') {
1.150 raeburn 1547: if ($showcredits) {
1548: $Str .= &Apache::lonhtmlcommon::row_title(
1549: &mt('Default role, section and credits'))
1550: .&mt('Choose the role and/or section(s) and/or credits to assign to users without values specified in the uploaded file.');
1551: } else {
1552: $Str .= &Apache::lonhtmlcommon::row_title(
1.95 bisitz 1553: &mt('Default role and section'))
1.150 raeburn 1554: .&mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file.');
1555: }
1.95 bisitz 1556: } else {
1557: $Str .= &Apache::lonhtmlcommon::row_title(
1558: &mt('Default role and/or section(s)'))
1559: .&mt('Role and/or section(s) for users without values specified in the uploaded file.');
1.1 raeburn 1560: }
1.22 raeburn 1561: if (($context eq 'domain') || ($context eq 'author')) {
1.95 bisitz 1562: $Str .= '<br />';
1.150 raeburn 1563: my ($options,$cb_script,$coursepick) =
1564: &default_role_selector($context,1,'',$showcredits);
1.22 raeburn 1565: if ($context eq 'domain') {
1.95 bisitz 1566: $Str .= '<p>'
1567: .'<b>'.&mt('Domain Level').'</b><br />'
1568: .$options
1569: .'</p><p>'
1570: .'<b>'.&mt('Course Level').'</b>'
1571: .'</p>'
1572: .$cb_script.$coursepick
1573: .&Apache::lonhtmlcommon::row_closure();
1.22 raeburn 1574: } elsif ($context eq 'author') {
1.95 bisitz 1575: $Str .= $options
1576: .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
1.22 raeburn 1577: }
1.1 raeburn 1578: } else {
1.22 raeburn 1579: my ($cnum,$cdom) = &get_course_identity();
1580: my $rowtitle = &mt('section');
1.150 raeburn 1581: my $defaultcredits;
1582: if ($showcredits) {
1583: $defaultcredits = &get_defaultcredits();
1584: }
1585: my $secbox = §ion_picker($cdom,$cnum,'Any',$rowtitle,$permission,
1586: $context,'upload',$crstype,$showcredits,
1587: $defaultcredits);
1.95 bisitz 1588: $Str .= $secbox
1589: .&Apache::lonhtmlcommon::row_closure();
1.101 raeburn 1590: my %lt;
1591: if ($crstype eq 'Community') {
1592: %lt = &Apache::lonlocal::texthash (
1593: disp => 'Display members with current/future access who are not in the uploaded file',
1594: stus => 'Members selected from this list can be dropped.'
1595: );
1596: } else {
1597: %lt = &Apache::lonlocal::texthash (
1598: disp => 'Display students with current/future access who are not in the uploaded file',
1599: stus => 'Students selected from this list can be dropped.'
1600: );
1601: }
1.95 bisitz 1602: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Full Update'))
1.101 raeburn 1603: .'<label><input type="checkbox" name="fullup" value="yes" />'
1604: .' '.$lt{'disp'}
1.95 bisitz 1605: .'</label><br />'
1.101 raeburn 1606: .$lt{'stus'}
1.95 bisitz 1607: .&Apache::lonhtmlcommon::row_closure();
1.1 raeburn 1608: }
1.5 raeburn 1609: if ($context eq 'course' || $context eq 'domain') {
1.161 bisitz 1610: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID'))
1611: .&forceid_change($context)
1612: .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
1.5 raeburn 1613: }
1.95 bisitz 1614:
1615: $Str .= &Apache::lonhtmlcommon::end_pick_box();
1.73 bisitz 1616: $Str .= '</div>';
1.95 bisitz 1617:
1618: # Footer
1619: $Str .= '<div class="LC_clear_float_footer">'
1620: .'<hr />';
1.1 raeburn 1621: if ($context eq 'course') {
1.95 bisitz 1622: $Str .= '<p class="LC_info">'
1.103 raeburn 1623: .&mt('Note: This operation may be time consuming when adding several users.')
1.95 bisitz 1624: .'</p>';
1.73 bisitz 1625: }
1.95 bisitz 1626: $Str .= '<p><input type="button"'
1.96 bisitz 1627: .' onclick="javascript:verify(this.form,this.form.csec)"'
1628: .' value="'.&mt('Update Users').'" />'
1.95 bisitz 1629: .'</p>'."\n"
1.73 bisitz 1630: .'</div>';
1.1 raeburn 1631: $r->print($Str);
1632: return;
1633: }
1634:
1.150 raeburn 1635: sub get_defaultcredits {
1636: my ($cdom,$cnum) = @_;
1637:
1638: if ($cdom eq '' || $cnum eq '') {
1639: return unless ($env{'request.course.id'});
1640: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1641: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1642: }
1643: return unless(($cdom =~ /^$match_domain$/) && ($cnum =~ /^$match_courseid$/));
1644: my ($defaultcredits,$domdefcredits);
1645: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
1.160 raeburn 1646: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
1.150 raeburn 1647: my $instcode = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
1648: if ($instcode) {
1649: $domdefcredits = $domdefaults{'officialcredits'};
1.160 raeburn 1650: } elsif ($env{'course.'.$cdom.'_'.$cnum.'.internal.textbook'}) {
1651: $domdefcredits = $domdefaults{'textbookcredits'};
1.150 raeburn 1652: } else {
1653: $domdefcredits = $domdefaults{'unofficialcredits'};
1654: }
1655: } else {
1656: return;
1657: }
1658:
1659: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
1660: $defaultcredits = $env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'};
1661: } elsif (exists($env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'})) {
1662: $defaultcredits = $env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'};
1663: } else {
1664: my %crsinfo =
1665: &Apache::lonnet::coursedescription("$cdom/$cnum",{'one_time' => 1});
1666: $defaultcredits = $crsinfo{'internal.defaultcredits'};
1667: }
1668: if ($defaultcredits eq '') {
1669: $defaultcredits = $domdefcredits;
1670: }
1671: return $defaultcredits;
1672: }
1673:
1.5 raeburn 1674: sub forceid_change {
1675: my ($context) = @_;
1676: my $output =
1.161 bisitz 1677: '<label><input type="checkbox" name="forceid" value="yes" />'
1.164 bisitz 1678: .&mt('Force change of existing ID')
1.163 raeburn 1679: .'</label>'.&Apache::loncommon::help_open_topic('ForceIDChange')."\n";
1.5 raeburn 1680: if ($context eq 'domain') {
1.163 raeburn 1681: $output .=
1682: '<br />'
1683: .'<label><input type="checkbox" name="recurseid" value="yes" />'
1684: .&mt("Update ID in user's course(s).").'</label>'."\n";
1.5 raeburn 1685: }
1686: return $output;
1687: }
1688:
1.1 raeburn 1689: ###############################################################
1690: ###############################################################
1691: sub print_upload_manager_form {
1.150 raeburn 1692: my ($r,$context,$permission,$crstype,$showcredits) = @_;
1.1 raeburn 1693: my $firstLine;
1694: my $datatoken;
1695: if (!$env{'form.datatoken'}) {
1696: $datatoken=&Apache::loncommon::upfile_store($r);
1697: } else {
1.189 raeburn 1698: $datatoken=&Apache::loncommon::valid_datatoken($env{'form.datatoken'});
1699: if ($datatoken ne '') {
1700: &Apache::loncommon::load_tmp_file($r,$datatoken);
1701: }
1.1 raeburn 1702: }
1.193 raeburn 1703: if ($datatoken eq '') {
1704: $r->print('<p class="LC_error">'.&mt('Error').': '.
1705: &mt('Invalid datatoken').'</p>');
1706: return 'missingdata';
1707: }
1.1 raeburn 1708: my @records=&Apache::loncommon::upfile_record_sep();
1709: if($env{'form.noFirstLine'}){
1710: $firstLine=shift(@records);
1711: }
1712: my $total=$#records;
1713: my $distotal=$total+1;
1714: my $today=time;
1715: my $halfyear=$today+15552000;
1716: #
1717: # Restore memorized settings
1718: my $col_setting_names = { 'username_choice' => 'scalar', # column settings
1719: 'names_choice' => 'scalar',
1720: 'fname_choice' => 'scalar',
1721: 'mname_choice' => 'scalar',
1722: 'lname_choice' => 'scalar',
1723: 'gen_choice' => 'scalar',
1724: 'id_choice' => 'scalar',
1725: 'sec_choice' => 'scalar',
1726: 'ipwd_choice' => 'scalar',
1727: 'email_choice' => 'scalar',
1728: 'role_choice' => 'scalar',
1.57 raeburn 1729: 'domain_choice' => 'scalar',
1.84 raeburn 1730: 'inststatus_choice' => 'scalar',
1.1 raeburn 1731: };
1.150 raeburn 1732: if ($showcredits) {
1733: $col_setting_names->{'credits_choice'} = 'scalar';
1734: }
1.1 raeburn 1735: if ($context eq 'course') {
1736: &Apache::loncommon::restore_course_settings('enrollment_upload',
1737: $col_setting_names);
1738: } else {
1739: &Apache::loncommon::restore_settings($context,'user_upload',
1740: $col_setting_names);
1741: }
1.150 raeburn 1742: my $defdom = $env{'request.role.domain'};
1.1 raeburn 1743: #
1744: # Determine kerberos parameters as appropriate
1745: my ($krbdef,$krbdefdom) =
1746: &Apache::loncommon::get_kerberos_defaults($defdom);
1747: #
1.123 raeburn 1748: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($defdom);
1.22 raeburn 1749: &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
1.123 raeburn 1750: $permission,$crstype,\%can_assign);
1.1 raeburn 1751: my $i;
1752: my $keyfields;
1753: if ($total>=0) {
1754: my @field=
1755: (['username',&mt('Username'), $env{'form.username_choice'}],
1756: ['names',&mt('Last Name, First Names'),$env{'form.names_choice'}],
1757: ['fname',&mt('First Name'), $env{'form.fname_choice'}],
1758: ['mname',&mt('Middle Names/Initials'),$env{'form.mname_choice'}],
1759: ['lname',&mt('Last Name'), $env{'form.lname_choice'}],
1760: ['gen', &mt('Generation'), $env{'form.gen_choice'}],
1.61 bisitz 1761: ['id', &mt('Student/Employee ID'),$env{'form.id_choice'}],
1.1 raeburn 1762: ['sec', &mt('Section'), $env{'form.sec_choice'}],
1763: ['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
1764: ['email',&mt('E-mail Address'), $env{'form.email_choice'}],
1.57 raeburn 1765: ['role',&mt('Role'), $env{'form.role_choice'}],
1.84 raeburn 1766: ['domain',&mt('Domain'), $env{'form.domain_choice'}],
1767: ['inststatus',&mt('Affiliation'), $env{'form.inststatus_choice'}]);
1.150 raeburn 1768: if ($showcredits) {
1769: push(@field,
1770: ['credits',&mt('Student Credits'), $env{'form.credits_choice'}]);
1771: }
1.1 raeburn 1772: if ($env{'form.upfile_associate'} eq 'reverse') {
1773: &Apache::loncommon::csv_print_samples($r,\@records);
1774: $i=&Apache::loncommon::csv_print_select_table($r,\@records,
1775: \@field);
1776: foreach (@field) {
1777: $keyfields.=$_->[0].',';
1778: }
1779: chop($keyfields);
1780: } else {
1781: unshift(@field,['none','']);
1782: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
1783: \@field);
1784: my %sone=&Apache::loncommon::record_sep($records[0]);
1785: $keyfields=join(',',sort(keys(%sone)));
1786: }
1787: }
1788: &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
1.150 raeburn 1789: $context,$permission,$crstype,$showcredits);
1.193 raeburn 1790: return 'ok';
1.1 raeburn 1791: }
1792:
1793: sub setup_date_selectors {
1.22 raeburn 1794: my ($starttime,$endtime,$mode,$nolink,$formname) = @_;
1795: if ($formname eq '') {
1796: $formname = 'studentform';
1797: }
1.1 raeburn 1798: if (! defined($starttime)) {
1799: $starttime = time;
1800: unless ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1801: if (exists($env{'course.'.$env{'request.course.id'}.
1802: '.default_enrollment_start_date'})) {
1803: $starttime = $env{'course.'.$env{'request.course.id'}.
1804: '.default_enrollment_start_date'};
1805: }
1806: }
1807: }
1808: if (! defined($endtime)) {
1809: $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1810: unless ($mode eq 'createcourse') {
1811: if (exists($env{'course.'.$env{'request.course.id'}.
1812: '.default_enrollment_end_date'})) {
1813: $endtime = $env{'course.'.$env{'request.course.id'}.
1814: '.default_enrollment_end_date'};
1815: }
1816: }
1817: }
1.11 raeburn 1818:
1819: my $startdateform =
1.22 raeburn 1820: &Apache::lonhtmlcommon::date_setter($formname,'startdate',$starttime,
1.11 raeburn 1821: undef,undef,undef,undef,undef,undef,undef,$nolink);
1822:
1823: my $enddateform =
1.22 raeburn 1824: &Apache::lonhtmlcommon::date_setter($formname,'enddate',$endtime,
1.11 raeburn 1825: undef,undef,undef,undef,undef,undef,undef,$nolink);
1826:
1.1 raeburn 1827: if ($mode eq 'create_enrolldates') {
1828: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1829: 'startenroll',
1830: $starttime);
1831: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1832: 'endenroll',
1833: $endtime);
1834: }
1835: if ($mode eq 'create_defaultdates') {
1836: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1837: 'startaccess',
1838: $starttime);
1839: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1840: 'endaccess',
1841: $endtime);
1842: }
1843: return ($startdateform,$enddateform);
1844: }
1845:
1846:
1847: sub get_dates_from_form {
1.54 raeburn 1848: my ($startname,$endname) = @_;
1849: if ($startname eq '') {
1850: $startname = 'startdate';
1851: }
1852: if ($endname eq '') {
1853: $endname = 'enddate';
1854: }
1855: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
1856: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.1 raeburn 1857: if ($env{'form.no_end_date'}) {
1858: $enddate = 0;
1859: }
1860: return ($startdate,$enddate);
1861: }
1862:
1863: sub date_setting_table {
1.101 raeburn 1864: my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission,$crstype) = @_;
1.11 raeburn 1865: my $nolink;
1866: if ($bulkaction) {
1867: $nolink = 1;
1868: }
1869: my ($startform,$endform) =
1.22 raeburn 1870: &setup_date_selectors($starttime,$endtime,$mode,$nolink,$formname);
1.1 raeburn 1871: my $dateDefault;
1872: if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1873: $dateDefault = ' ';
1.13 raeburn 1874: } elsif ($mode ne 'author' && $mode ne 'domain') {
1.11 raeburn 1875: if (($bulkaction eq 'reenable') ||
1876: ($bulkaction eq 'activate') ||
1.22 raeburn 1877: ($bulkaction eq 'chgdates') ||
1878: ($env{'form.action'} eq 'upload')) {
1879: if ($env{'request.course.sec'} eq '') {
1880: $dateDefault = '<span class="LC_nobreak">'.
1.101 raeburn 1881: '<label><input type="checkbox" name="makedatesdefault" value="1" /> ';
1882: if ($crstype eq 'Community') {
1883: $dateDefault .= &mt("make these dates the default access dates for future community enrollment");
1884: } else {
1885: $dateDefault .= &mt("make these dates the default access dates for future course enrollment");
1886: }
1887: $dateDefault .= '</label></span>';
1.22 raeburn 1888: }
1.11 raeburn 1889: }
1.1 raeburn 1890: }
1.11 raeburn 1891: my $perpetual = '<span class="LC_nobreak"><label><input type="checkbox" name="no_end_date"';
1.1 raeburn 1892: if (defined($endtime) && $endtime == 0) {
1.70 bisitz 1893: $perpetual .= ' checked="checked"';
1.1 raeburn 1894: }
1.11 raeburn 1895: $perpetual.= ' /> '.&mt('no ending date').'</label></span>';
1.1 raeburn 1896: if ($mode eq 'create_enrolldates') {
1897: $perpetual = ' ';
1898: }
1.11 raeburn 1899: my $result = &Apache::lonhtmlcommon::start_pick_box()."\n";
1900: $result .= &Apache::lonhtmlcommon::row_title(&mt('Starting Date'),
1901: 'LC_oddrow_value')."\n".
1902: $startform."\n".
1903: &Apache::lonhtmlcommon::row_closure(1).
1904: &Apache::lonhtmlcommon::row_title(&mt('Ending Date'),
1905: 'LC_oddrow_value')."\n".
1906: $endform.' '.$perpetual.
1907: &Apache::lonhtmlcommon::row_closure(1).
1.22 raeburn 1908: &Apache::lonhtmlcommon::end_pick_box();
1.1 raeburn 1909: if ($dateDefault) {
1910: $result .= $dateDefault.'<br />'."\n";
1911: }
1912: return $result;
1913: }
1914:
1915: sub make_dates_default {
1.101 raeburn 1916: my ($startdate,$enddate,$context,$crstype) = @_;
1.1 raeburn 1917: my $result = '';
1918: if ($context eq 'course') {
1.17 raeburn 1919: my ($cnum,$cdom) = &get_course_identity();
1.1 raeburn 1920: my $put_result = &Apache::lonnet::put('environment',
1921: {'default_enrollment_start_date'=>$startdate,
1.17 raeburn 1922: 'default_enrollment_end_date' =>$enddate},$cdom,$cnum);
1.1 raeburn 1923: if ($put_result eq 'ok') {
1.101 raeburn 1924: if ($crstype eq 'Community') {
1925: $result .= &mt('Set default start and end access dates for community.');
1926: } else {
1927: $result .= &mt('Set default start and end access dates for course.');
1928: }
1929: $result .= '<br />'."\n";
1.1 raeburn 1930: #
1931: # Refresh the course environment
1932: &Apache::lonnet::coursedescription($env{'request.course.id'},
1933: {'freshen_cache' => 1});
1934: } else {
1.101 raeburn 1935: if ($crstype eq 'Community') {
1936: $result .= &mt('Unable to set default access dates for community');
1937: } else {
1938: $result .= &mt('Unable to set default access dates for course');
1939: }
1940: $result .= ':'.$put_result.'<br />';
1.1 raeburn 1941: }
1942: }
1943: return $result;
1944: }
1945:
1946: sub default_role_selector {
1.150 raeburn 1947: my ($context,$checkpriv,$crstype,$showcredits) = @_;
1.1 raeburn 1948: my %customroles;
1949: my ($options,$coursepick,$cb_jscript);
1.13 raeburn 1950: if ($context ne 'author') {
1.104 raeburn 1951: %customroles = &my_custom_roles($crstype);
1.1 raeburn 1952: }
1953:
1954: my %lt=&Apache::lonlocal::texthash(
1955: 'rol' => "Role",
1956: 'grs' => "Section",
1957: 'exs' => "Existing sections",
1958: 'new' => "New section",
1.150 raeburn 1959: 'crd' => "Credits",
1.1 raeburn 1960: );
1961: $options = '<select name="defaultrole">'."\n".
1962: ' <option value="">'.&mt('Please select').'</option>'."\n";
1963: if ($context eq 'course') {
1.101 raeburn 1964: $options .= &default_course_roles($context,$checkpriv,$crstype,%customroles);
1.13 raeburn 1965: } elsif ($context eq 'author') {
1.2 raeburn 1966: my @roles = &construction_space_roles($checkpriv);
1.1 raeburn 1967: foreach my $role (@roles) {
1968: my $plrole=&Apache::lonnet::plaintext($role);
1969: $options .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1970: }
1971: } elsif ($context eq 'domain') {
1.2 raeburn 1972: my @roles = &domain_roles($checkpriv);
1.1 raeburn 1973: foreach my $role (@roles) {
1974: my $plrole=&Apache::lonnet::plaintext($role);
1975: $options .= ' <option value="'.$role.'">'.$plrole.'</option>';
1976: }
1977: my $courseform = &Apache::loncommon::selectcourse_link
1.103 raeburn 1978: ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course/Community');
1.150 raeburn 1979: my ($credit_elem,$creditsinput);
1980: if ($showcredits) {
1981: $credit_elem = 'credits';
1982: $creditsinput = '<td><input type="text" name="credits" value="" /></td>';
1983: }
1.1 raeburn 1984: $cb_jscript =
1.150 raeburn 1985: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform','courserole','Course/Community',$credit_elem);
1.1 raeburn 1986: $coursepick = &Apache::loncommon::start_data_table().
1987: &Apache::loncommon::start_data_table_header_row().
1988: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th>'.
1989: '<th>'.$lt{'grs'}.'</th>'.
1.150 raeburn 1990: '<th>'.$lt{'crd'}.'</th>'.
1.1 raeburn 1991: &Apache::loncommon::end_data_table_header_row().
1992: &Apache::loncommon::start_data_table_row()."\n".
1.103 raeburn 1993: '<td><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'studentform','dccourse','dcdomain','coursedesc','','','','crstype'".')" /></td>'."\n".
1.1 raeburn 1994: '<td><select name="courserole">'."\n".
1.101 raeburn 1995: &default_course_roles($context,$checkpriv,'Course',%customroles)."\n".
1.1 raeburn 1996: '</select></td><td>'.
1997: '<table class="LC_createuser">'.
1.162 bisitz 1998: '<tr class="LC_section_row"><td valign="top">'.
1.22 raeburn 1999: $lt{'exs'}.'<br /><select name="currsec">'.
1.162 bisitz 2000: ' <option value=""><--'.&mt('Pick course first').
1.1 raeburn 2001: '</select></td>'.
2002: '<td> </td>'.
2003: '<td valign="top">'.$lt{'new'}.'<br />'.
2004: '<input type="text" name="newsec" value="" size="5" />'.
1.22 raeburn 2005: '<input type="hidden" name="groups" value="" />'.
2006: '<input type="hidden" name="sections" value="" />'.
2007: '<input type="hidden" name="origdom" value="'.
2008: $env{'request.role.domain'}.'" />'.
2009: '<input type="hidden" name="dccourse" value="" />'.
2010: '<input type="hidden" name="dcdomain" value="" />'.
1.103 raeburn 2011: '<input type="hidden" name="crstype" value="" />'.
1.150 raeburn 2012: '</td></tr></table></td>'.$creditsinput.
1.1 raeburn 2013: &Apache::loncommon::end_data_table_row().
1.22 raeburn 2014: &Apache::loncommon::end_data_table()."\n";
1.1 raeburn 2015: }
2016: $options .= '</select>';
2017: return ($options,$cb_jscript,$coursepick);
2018: }
2019:
2020: sub default_course_roles {
1.101 raeburn 2021: my ($context,$checkpriv,$crstype,%customroles) = @_;
1.1 raeburn 2022: my $output;
1.17 raeburn 2023: my $custom = 1;
1.101 raeburn 2024: my @roles = &course_roles($context,$checkpriv,$custom,lc($crstype));
1.1 raeburn 2025: foreach my $role (@roles) {
1.22 raeburn 2026: if ($role ne 'cr') {
1.101 raeburn 2027: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.22 raeburn 2028: $output .= ' <option value="'.$role.'">'.$plrole.'</option>';
2029: }
1.1 raeburn 2030: }
2031: if (keys(%customroles) > 0) {
1.22 raeburn 2032: if (grep(/^cr$/,@roles)) {
2033: foreach my $cust (sort(keys(%customroles))) {
2034: my $custrole='cr_'.$env{'user.domain'}.
2035: '_'.$env{'user.name'}.'_'.$cust;
2036: $output .= ' <option value="'.$custrole.'">'.$cust.'</option>';
2037: }
1.1 raeburn 2038: }
2039: }
2040: return $output;
2041: }
2042:
2043: sub construction_space_roles {
1.2 raeburn 2044: my ($checkpriv) = @_;
1.17 raeburn 2045: my @allroles = &roles_by_context('author');
1.1 raeburn 2046: my @roles;
1.2 raeburn 2047: if ($checkpriv) {
2048: foreach my $role (@allroles) {
2049: if (&Apache::lonnet::allowed('c'.$role,$env{'user.domain'}.'/'.$env{'user.name'})) {
2050: push(@roles,$role);
2051: }
1.1 raeburn 2052: }
1.2 raeburn 2053: return @roles;
2054: } else {
2055: return @allroles;
1.1 raeburn 2056: }
2057: }
2058:
2059: sub domain_roles {
1.2 raeburn 2060: my ($checkpriv) = @_;
1.17 raeburn 2061: my @allroles = &roles_by_context('domain');
1.1 raeburn 2062: my @roles;
1.2 raeburn 2063: if ($checkpriv) {
2064: foreach my $role (@allroles) {
2065: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
2066: push(@roles,$role);
2067: }
1.1 raeburn 2068: }
1.2 raeburn 2069: return @roles;
2070: } else {
2071: return @allroles;
1.1 raeburn 2072: }
2073: }
2074:
2075: sub course_roles {
1.101 raeburn 2076: my ($context,$checkpriv,$custom,$roletype) = @_;
1.102 raeburn 2077: my $crstype;
2078: if ($roletype eq 'community') {
2079: $crstype = 'Community' ;
2080: } else {
2081: $crstype = 'Course';
2082: }
2083: my @allroles = &roles_by_context('course',$custom,$crstype);
1.1 raeburn 2084: my @roles;
2085: if ($context eq 'domain') {
2086: @roles = @allroles;
2087: } elsif ($context eq 'course') {
2088: if ($env{'request.course.id'}) {
1.2 raeburn 2089: if ($checkpriv) {
2090: foreach my $role (@allroles) {
2091: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
2092: push(@roles,$role);
2093: } else {
1.101 raeburn 2094: if ((($role ne 'cc') && ($role ne 'co')) && ($env{'request.course.sec'} ne '')) {
1.22 raeburn 2095: if (&Apache::lonnet::allowed('c'.$role,
1.2 raeburn 2096: $env{'request.course.id'}.'/'.
1.22 raeburn 2097: $env{'request.course.sec'})) {
1.2 raeburn 2098: push(@roles,$role);
2099: }
1.1 raeburn 2100: }
2101: }
2102: }
1.2 raeburn 2103: } else {
2104: @roles = @allroles;
1.1 raeburn 2105: }
2106: }
2107: }
2108: return @roles;
2109: }
2110:
2111: sub curr_role_permissions {
1.101 raeburn 2112: my ($context,$setting,$checkpriv,$type) = @_;
1.17 raeburn 2113: my $custom = 1;
1.1 raeburn 2114: my @roles;
1.13 raeburn 2115: if ($context eq 'author') {
1.2 raeburn 2116: @roles = &construction_space_roles($checkpriv);
1.1 raeburn 2117: } elsif ($context eq 'domain') {
2118: if ($setting eq 'course') {
1.101 raeburn 2119: @roles = &course_roles($context,$checkpriv,$custom,$type);
1.1 raeburn 2120: } else {
1.2 raeburn 2121: @roles = &domain_roles($checkpriv);
1.1 raeburn 2122: }
2123: } elsif ($context eq 'course') {
1.101 raeburn 2124: @roles = &course_roles($context,$checkpriv,$custom,$type);
1.1 raeburn 2125: }
2126: return @roles;
2127: }
2128:
2129: # ======================================================= Existing Custom Roles
2130:
2131: sub my_custom_roles {
1.175 raeburn 2132: my ($crstype,$udom,$uname) = @_;
1.1 raeburn 2133: my %returnhash=();
1.137 raeburn 2134: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
1.175 raeburn 2135: my %rolehash=&Apache::lonnet::dump('roles',$udom,$uname);
1.104 raeburn 2136: foreach my $key (keys(%rolehash)) {
1.1 raeburn 2137: if ($key=~/^rolesdef\_(\w+)$/) {
1.207 raeburn 2138: my $role = $1;
1.104 raeburn 2139: if ($crstype eq 'Community') {
2140: next if ($rolehash{$key} =~ /bre\&S/);
2141: }
1.207 raeburn 2142: $returnhash{$role}=$role;
1.1 raeburn 2143: }
2144: }
2145: return %returnhash;
2146: }
2147:
1.2 raeburn 2148: sub print_userlist {
2149: my ($r,$mode,$permission,$context,$formname,$totcodes,$codetitles,
1.150 raeburn 2150: $idlist,$idlist_titles,$showcredits) = @_;
1.2 raeburn 2151: my $format = $env{'form.output'};
1.1 raeburn 2152: if (! exists($env{'form.sortby'})) {
2153: $env{'form.sortby'} = 'username';
2154: }
1.2 raeburn 2155: if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
2156: $env{'form.Status'} = 'Active';
1.1 raeburn 2157: }
1.140 raeburn 2158: my $onchange = "javascript:updateCols('Status');";
1.1 raeburn 2159: my $status_select = &Apache::lonhtmlcommon::StatusOptions
1.140 raeburn 2160: ($env{'form.Status'},undef,undef,$onchange);
1.1 raeburn 2161:
1.2 raeburn 2162: if ($env{'form.showrole'} eq '') {
1.13 raeburn 2163: if ($context eq 'course') {
2164: $env{'form.showrole'} = 'st';
2165: } else {
2166: $env{'form.showrole'} = 'Any';
2167: }
1.2 raeburn 2168: }
1.1 raeburn 2169: if (! defined($env{'form.output'}) ||
2170: $env{'form.output'} !~ /^(csv|excel|html)$/ ) {
2171: $env{'form.output'} = 'html';
2172: }
2173:
1.2 raeburn 2174: my @statuses;
2175: if ($env{'form.Status'} eq 'Any') {
2176: @statuses = ('previous','active','future');
2177: } elsif ($env{'form.Status'} eq 'Expired') {
2178: @statuses = ('previous');
2179: } elsif ($env{'form.Status'} eq 'Active') {
2180: @statuses = ('active');
2181: } elsif ($env{'form.Status'} eq 'Future') {
2182: @statuses = ('future');
2183: }
1.1 raeburn 2184:
2185: # Interface output
1.2 raeburn 2186: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
2187: '<input type="hidden" name="action" value="'.
1.1 raeburn 2188: $env{'form.action'}.'" />');
1.140 raeburn 2189: $r->print('<div>'."\n");
1.1 raeburn 2190: if ($env{'form.action'} ne 'modifystudent') {
2191: my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
2192: 'excel' => "Excel",
2193: 'html' => 'HTML');
1.140 raeburn 2194: my $output_selector = '<select size="1" name="output" onchange="javascript:updateCols('."'output'".');" >';
1.1 raeburn 2195: foreach my $outputformat ('html','csv','excel') {
1.96 bisitz 2196: my $option = '<option value="'.$outputformat.'"';
1.1 raeburn 2197: if ($outputformat eq $env{'form.output'}) {
1.96 bisitz 2198: $option .= ' selected="selected"';
1.1 raeburn 2199: }
2200: $option .='>'.$lt{$outputformat}.'</option>';
2201: $output_selector .= "\n".$option;
2202: }
2203: $output_selector .= '</select>';
1.140 raeburn 2204: $r->print('<span class="LC_nobreak">'
1.70 bisitz 2205: .&mt('Output Format: [_1]',$output_selector)
1.140 raeburn 2206: .'</span>'.(' 'x3));
1.70 bisitz 2207: }
1.140 raeburn 2208: $r->print('<span class="LC_nobreak">'
1.70 bisitz 2209: .&mt('User Status: [_1]',$status_select)
1.140 raeburn 2210: .'</span>'.(' 'x3)."\n");
1.2 raeburn 2211: my $roleselected = '';
2212: if ($env{'form.showrole'} eq 'Any') {
1.91 bisitz 2213: $roleselected = ' selected="selected"';
1.2 raeburn 2214: }
1.53 raeburn 2215: my ($cnum,$cdom);
2216: $r->print(&role_filter($context));
2217: if ($context eq 'course') {
2218: ($cnum,$cdom) = &get_course_identity();
2219: $r->print(§ion_group_filter($cnum,$cdom));
1.2 raeburn 2220: }
1.140 raeburn 2221: $r->print('</div><div class="LC_left_float">'.
1.150 raeburn 2222: &column_checkboxes($context,$mode,$formname,$showcredits).
1.149 raeburn 2223: '</div>');
1.78 raeburn 2224: if ($env{'form.phase'} eq '') {
1.149 raeburn 2225: $r->print('<br clear="all" />'.
2226: &list_submit_button(&mt('Display List of Users'))."\n".
1.78 raeburn 2227: '<input type="hidden" name="phase" value="" /></form>');
2228: return;
2229: }
1.106 raeburn 2230: if (!(($context eq 'domain') &&
2231: (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
1.149 raeburn 2232: $r->print('<br clear="all" />'.
2233: &list_submit_button(&mt('Update Display'))."\n");
1.140 raeburn 2234: }
2235:
1.150 raeburn 2236: my @cols = &infocolumns($context,$mode,$showcredits);
1.140 raeburn 2237: if (!@cols) {
1.152 bisitz 2238: $r->print('<hr style="clear:both;" /><span class="LC_warning">'.
1.140 raeburn 2239: &mt('No user information selected for display.').'</span>'.
2240: '<input type="hidden" name="phase" value="display" /></form>'."\n");
2241: return;
1.2 raeburn 2242: }
2243: my ($indexhash,$keylist) = &make_keylist_array();
1.159 raeburn 2244: my (%userlist,%userinfo,$clearcoursepick,$needauthorquota,$needauthorusage);
1.102 raeburn 2245: if (($context eq 'domain') &&
2246: ($env{'form.roletype'} eq 'course') ||
2247: ($env{'form.roletype'} eq 'community')) {
2248: my ($crstype,$numcodes,$title,$warning);
2249: if ($env{'form.roletype'} eq 'course') {
2250: $crstype = 'Course';
2251: $numcodes = $totcodes;
2252: $title = &mt('Select Courses');
2253: $warning = &mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.');
2254: } elsif ($env{'form.roletype'} eq 'community') {
2255: $crstype = 'Community';
2256: $numcodes = 0;
2257: $title = &mt('Select Communities');
2258: $warning = &mt('Warning: data retrieval for multiple communities can take considerable time, as this operation is not currently optimized.');
2259: }
1.120 raeburn 2260: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1.3 raeburn 2261: my $courseform =
1.102 raeburn 2262: &Apache::lonhtmlcommon::course_selection($formname,$numcodes,
1.120 raeburn 2263: $codetitles,$idlist,$idlist_titles,$crstype,
2264: \@standardnames);
1.148 bisitz 2265: $r->print('<div class="LC_left_float">'.
2266: '<fieldset><legend>'.$title.'</legend>'."\n".
1.3 raeburn 2267: $courseform."\n".
1.148 bisitz 2268: '</fieldset></div><br clear="all" />'.
1.106 raeburn 2269: '<p><input type="hidden" name="origroletype" value="'.$env{'form.roletype'}.'" />'.
2270: &list_submit_button(&mt('Update Display')).
1.102 raeburn 2271: "\n".'</p><span class="LC_warning">'.$warning.'</span>'."\n");
1.106 raeburn 2272: $clearcoursepick = 0;
2273: if (($env{'form.origroletype'} ne '') &&
2274: ($env{'form.origroletype'} ne $env{'form.roletype'})) {
2275: $clearcoursepick = 1;
2276: }
2277: if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
1.147 bisitz 2278: $r->print('<hr />'.&mt('Searching ...').'<br /> <br />');
1.11 raeburn 2279: }
2280: } else {
1.152 bisitz 2281: $r->print('<hr style="clear:both;" /><div id="searching">'.&mt('Searching ...').'</div>');
1.3 raeburn 2282: }
2283: $r->rflush();
1.1 raeburn 2284: if ($context eq 'course') {
1.46 raeburn 2285: if (($env{'form.showrole'} eq 'st') || ($env{'form.showrole'} eq 'Any')) {
1.45 raeburn 2286: my $classlist = &Apache::loncoursedata::get_classlist();
1.66 raeburn 2287: if (ref($classlist) eq 'HASH') {
2288: %userlist = %{$classlist};
2289: }
1.45 raeburn 2290: }
1.43 raeburn 2291: if ($env{'form.showrole'} ne 'st') {
2292: my $showroles;
2293: if ($env{'form.showrole'} ne 'Any') {
2294: $showroles = [$env{'form.showrole'}];
1.3 raeburn 2295: } else {
1.43 raeburn 2296: $showroles = undef;
1.1 raeburn 2297: }
1.43 raeburn 2298: my $withsec = 1;
2299: my $hidepriv = 1;
2300: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
2301: \@statuses,$showroles,undef,$withsec,$hidepriv);
2302: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
2303: \%advrolehash,$permission);
1.1 raeburn 2304: }
1.2 raeburn 2305: } else {
2306: my (%cstr_roles,%dom_roles);
1.13 raeburn 2307: if ($context eq 'author') {
1.2 raeburn 2308: # List co-authors and assistant co-authors
1.17 raeburn 2309: my @possroles = &roles_by_context($context);
1.2 raeburn 2310: %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
2311: \@statuses,\@possroles);
2312: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
1.11 raeburn 2313: \%cstr_roles,$permission);
1.2 raeburn 2314: } elsif ($context eq 'domain') {
2315: if ($env{'form.roletype'} eq 'domain') {
1.159 raeburn 2316: if (grep(/^authorusage$/,@cols)) {
2317: $needauthorusage = 1;
2318: }
2319: if (grep(/^authorquota$/,@cols)) {
2320: $needauthorquota = 1;
2321: }
1.2 raeburn 2322: %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'});
2323: foreach my $key (keys(%dom_roles)) {
2324: if (ref($dom_roles{$key}) eq 'HASH') {
2325: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 2326: \%userinfo,$dom_roles{$key},$permission);
1.2 raeburn 2327: }
2328: }
1.13 raeburn 2329: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 2330: my %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'},['au']);
2331: my %coauthors;
2332: foreach my $key (keys(%dom_roles)) {
2333: if (ref($dom_roles{$key}) eq 'HASH') {
2334: if ($env{'form.showrole'} eq 'au') {
2335: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 2336: \%userinfo,$dom_roles{$key},$permission);
1.2 raeburn 2337: } else {
2338: my @possroles;
2339: if ($env{'form.showrole'} eq 'Any') {
1.22 raeburn 2340: @possroles = &roles_by_context('author');
1.2 raeburn 2341: } else {
2342: @possroles = ($env{'form.showrole'});
2343: }
2344: foreach my $author (sort(keys(%{$dom_roles{$key}}))) {
1.22 raeburn 2345: my ($role,$authorname,$authordom) = split(/:/,$author,-1);
1.2 raeburn 2346: my $extent = '/'.$authordom.'/'.$authorname;
2347: %{$coauthors{$extent}} =
2348: &Apache::lonnet::get_my_roles($authorname,
2349: $authordom,undef,\@statuses,\@possroles);
2350: }
2351: &gather_userinfo($context,$format,\%userlist,
1.11 raeburn 2352: $indexhash,\%userinfo,\%coauthors,$permission);
1.2 raeburn 2353: }
2354: }
2355: }
1.101 raeburn 2356: } elsif (($env{'form.roletype'} eq 'course') ||
2357: ($env{'form.roletype'} eq 'community')) {
1.106 raeburn 2358: if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
1.2 raeburn 2359: my %courses = &process_coursepick();
1.39 raeburn 2360: my %allusers;
2361: my $hidepriv = 1;
1.2 raeburn 2362: foreach my $cid (keys(%courses)) {
1.17 raeburn 2363: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
1.11 raeburn 2364: next if ($cnum eq '' || $cdom eq '');
1.17 raeburn 2365: my $custom = 1;
1.2 raeburn 2366: my (@roles,@sections,%access,%users,%userdata,
1.6 albertel 2367: %statushash);
1.2 raeburn 2368: if ($env{'form.showrole'} eq 'Any') {
1.101 raeburn 2369: @roles = &course_roles($context,undef,$custom,
2370: $env{'form.roletype'});
1.2 raeburn 2371: } else {
2372: @roles = ($env{'form.showrole'});
2373: }
2374: foreach my $role (@roles) {
2375: %{$users{$role}} = ();
2376: }
2377: foreach my $type (@statuses) {
2378: $access{$type} = $type;
2379: }
1.39 raeburn 2380: &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash,$hidepriv);
1.2 raeburn 2381: foreach my $user (keys(%userdata)) {
2382: next if (ref($userinfo{$user}) eq 'HASH');
2383: foreach my $item ('fullname','id') {
2384: $userinfo{$user}{$item} = $userdata{$user}[$indexhash->{$item}];
2385: }
2386: }
2387: foreach my $role (keys(%users)) {
2388: foreach my $user (keys(%{$users{$role}})) {
2389: my $uniqid = $user.':'.$role;
2390: $allusers{$uniqid}{$cid} = { desc => $cdesc,
2391: secs => $statushash{$user}{$role},
2392: };
2393: }
2394: }
2395: }
2396: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 2397: \%userinfo,\%allusers,$permission);
1.2 raeburn 2398: } else {
1.10 raeburn 2399: $r->print('<input type="hidden" name="phase" value="'.
2400: $env{'form.phase'}.'" /></form>');
1.2 raeburn 2401: return;
2402: }
1.1 raeburn 2403: }
2404: }
1.3 raeburn 2405: }
2406: if (keys(%userlist) == 0) {
1.142 bisitz 2407: my $msg = '';
1.13 raeburn 2408: if ($context eq 'author') {
1.142 bisitz 2409: $msg = &mt('There are no co-authors to display.');
1.3 raeburn 2410: } elsif ($context eq 'domain') {
2411: if ($env{'form.roletype'} eq 'domain') {
1.142 bisitz 2412: $msg = &mt('There are no users with domain roles to display.');
1.13 raeburn 2413: } elsif ($env{'form.roletype'} eq 'author') {
1.142 bisitz 2414: $msg = &mt('There are no authors or co-authors to display.');
1.3 raeburn 2415: } elsif ($env{'form.roletype'} eq 'course') {
1.142 bisitz 2416: $msg = &mt('There are no course users to display');
1.101 raeburn 2417: } elsif ($env{'form.roletype'} eq 'community') {
1.142 bisitz 2418: $msg = &mt('There are no community users to display');
1.2 raeburn 2419: }
1.3 raeburn 2420: } elsif ($context eq 'course') {
2421: $r->print(&mt('There are no course users to display.')."\n");
2422: }
1.148 bisitz 2423: $r->print('<p class="LC_info">'.$msg.'</p>'."\n") if $msg;
1.3 raeburn 2424: } else {
2425: # Print out the available choices
1.4 raeburn 2426: my $usercount;
1.3 raeburn 2427: if ($env{'form.action'} eq 'modifystudent') {
1.10 raeburn 2428: ($usercount) = &show_users_list($r,$context,'view',$permission,
1.150 raeburn 2429: $env{'form.Status'},\%userlist,$keylist,'',
2430: $showcredits);
1.1 raeburn 2431: } else {
1.4 raeburn 2432: ($usercount) = &show_users_list($r,$context,$env{'form.output'},
1.150 raeburn 2433: $permission,$env{'form.Status'},\%userlist,
1.159 raeburn 2434: $keylist,'',$showcredits,$needauthorquota,$needauthorusage);
1.4 raeburn 2435: }
2436: if (!$usercount) {
1.142 bisitz 2437: $r->print('<br /><span class="LC_info">'
1.72 bisitz 2438: .&mt('There are no users matching the search criteria.')
2439: .'</span>'
2440: );
1.2 raeburn 2441: }
2442: }
1.10 raeburn 2443: $r->print('<input type="hidden" name="phase" value="'.
2444: $env{'form.phase'}.'" /></form>');
1.140 raeburn 2445: return;
1.2 raeburn 2446: }
2447:
1.53 raeburn 2448: sub role_filter {
2449: my ($context) = @_;
2450: my $output;
2451: my $roleselected = '';
2452: if ($env{'form.showrole'} eq 'Any') {
1.91 bisitz 2453: $roleselected = ' selected="selected"';
1.53 raeburn 2454: }
2455: my ($role_select);
2456: if ($context eq 'domain') {
2457: $role_select = &domain_roles_select();
1.140 raeburn 2458: $output = '<span class="LC_nobreak">'
1.70 bisitz 2459: .&mt('Role Type: [_1]',$role_select)
1.140 raeburn 2460: .'</span>';
1.53 raeburn 2461: } else {
1.140 raeburn 2462: $role_select = '<select name="showrole" onchange="javascript:updateCols('."'showrole'".');">'."\n".
1.53 raeburn 2463: '<option value="Any" '.$roleselected.'>'.
2464: &mt('Any role').'</option>';
1.101 raeburn 2465: my ($roletype,$crstype);
2466: if ($context eq 'course') {
2467: $crstype = &Apache::loncommon::course_type();
2468: if ($crstype eq 'Community') {
2469: $roletype = 'community';
2470: } else {
2471: $roletype = 'course';
2472: }
2473: }
2474: my @poss_roles = &curr_role_permissions($context,'','',$roletype);
1.53 raeburn 2475: foreach my $role (@poss_roles) {
2476: $roleselected = '';
2477: if ($role eq $env{'form.showrole'}) {
1.91 bisitz 2478: $roleselected = ' selected="selected"';
1.53 raeburn 2479: }
2480: my $plrole;
2481: if ($role eq 'cr') {
2482: $plrole = &mt('Custom role');
2483: } else {
1.101 raeburn 2484: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.53 raeburn 2485: }
2486: $role_select .= '<option value="'.$role.'"'.$roleselected.'>'.$plrole.'</option>';
2487: }
2488: $role_select .= '</select>';
1.140 raeburn 2489: $output = '<span class="LC_nobreak">'
1.70 bisitz 2490: .&mt('Role: [_1]',$role_select)
1.140 raeburn 2491: .'</span>';
1.53 raeburn 2492: }
2493: return $output;
2494: }
2495:
1.33 raeburn 2496: sub section_group_filter {
2497: my ($cnum,$cdom) = @_;
2498: my @filters;
2499: if ($env{'request.course.sec'} eq '') {
2500: @filters = ('sec');
2501: }
2502: push(@filters,'grp');
2503: my %name = (
2504: sec => 'secfilter',
2505: grp => 'grpfilter',
2506: );
2507: my %title = &Apache::lonlocal::texthash (
2508: sec => 'Section(s)',
2509: grp => 'Group(s)',
2510: all => 'all',
2511: none => 'none',
2512: );
1.47 raeburn 2513: my $output;
1.33 raeburn 2514: foreach my $item (@filters) {
1.47 raeburn 2515: my ($markup,@options);
1.33 raeburn 2516: if ($env{'form.'.$name{$item}} eq '') {
2517: $env{'form.'.$name{$item}} = 'all';
2518: }
2519: if ($item eq 'sec') {
1.103 raeburn 2520: if (($env{'form.showrole'} eq 'cc') || ($env{'form.showrole'} eq 'co')) {
1.33 raeburn 2521: $env{'form.'.$name{$item}} = 'none';
2522: }
2523: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
2524: @options = sort(keys(%sections_count));
2525: } elsif ($item eq 'grp') {
2526: my %curr_groups = &Apache::longroup::coursegroups();
2527: @options = sort(keys(%curr_groups));
2528: }
2529: if (@options > 0) {
2530: my $currsel;
1.112 bisitz 2531: $markup = '<select name="'.$name{$item}.'">'."\n";
1.33 raeburn 2532: foreach my $option ('all','none',@options) {
2533: $currsel = '';
2534: if ($env{'form.'.$name{$item}} eq $option) {
1.96 bisitz 2535: $currsel = ' selected="selected"';
1.33 raeburn 2536: }
2537: $markup .= ' <option value="'.$option.'"'.$currsel.'>';
2538: if (($option eq 'all') || ($option eq 'none')) {
2539: $markup .= $title{$option};
2540: } else {
2541: $markup .= $option;
2542: }
2543: $markup .= '</option>'."\n";
2544: }
2545: $markup .= '</select>'."\n";
1.111 bisitz 2546: $output .= (' 'x3).'<span class="LC_nobreak">'
2547: .'<label>'.$title{$item}.': '.$markup.'</label>'
2548: .'</span> ';
1.33 raeburn 2549: }
2550: }
2551: return $output;
2552: }
2553:
1.140 raeburn 2554: sub infocolumns {
1.150 raeburn 2555: my ($context,$mode,$showcredits) = @_;
1.140 raeburn 2556: my @cols;
2557: if (($mode eq 'pickauthor') || ($mode eq 'autoenroll')) {
1.150 raeburn 2558: @cols = &get_cols_array($context,$mode,$showcredits);
1.140 raeburn 2559: } else {
1.150 raeburn 2560: my @posscols = &get_cols_array($context,$mode,$showcredits);
1.140 raeburn 2561: if ($env{'form.phase'} ne '') {
2562: my @checkedcols = &Apache::loncommon::get_env_multiple('form.showcol');
2563: foreach my $col (@checkedcols) {
2564: if (grep(/^$col$/,@posscols)) {
2565: push(@cols,$col);
2566: }
2567: }
2568: } else {
2569: @cols = @posscols;
2570: }
2571: }
2572: return @cols;
2573: }
2574:
2575: sub get_cols_array {
1.150 raeburn 2576: my ($context,$mode,$showcredits) = @_;
1.140 raeburn 2577: my @cols;
2578: if ($mode eq 'pickauthor') {
2579: @cols = ('username','fullname','status','email');
2580: } else {
2581: @cols = ('username','domain','id','fullname');
2582: if ($context eq 'course') {
2583: push(@cols,'section');
2584: }
2585: push(@cols,('start','end','role'));
2586: unless (($mode eq 'autoenroll') && ($env{'form.Status'} ne 'Any')) {
2587: push(@cols,'status');
2588: }
2589: if ($context eq 'course') {
2590: push(@cols,'groups');
2591: }
2592: push(@cols,'email');
2593: if (($context eq 'course') && ($mode ne 'autoenroll')) {
1.150 raeburn 2594: if ($showcredits) {
2595: push(@cols,'credits');
2596: }
1.140 raeburn 2597: push(@cols,'lastlogin','clicker');
2598: }
2599: if (($context eq 'course') && ($mode ne 'autoenroll') &&
2600: ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
1.156 raeburn 2601: push(@cols,'photo');
1.140 raeburn 2602: }
1.149 raeburn 2603: if ($context eq 'domain') {
1.159 raeburn 2604: push (@cols,('authorusage','authorquota','extent'));
1.149 raeburn 2605: }
1.140 raeburn 2606: }
2607: return @cols;
2608: }
2609:
2610: sub column_checkboxes {
1.150 raeburn 2611: my ($context,$mode,$formname,$showcredits) = @_;
2612: my @cols = &get_cols_array($context,$mode,$showcredits);
1.140 raeburn 2613: my @showncols = &Apache::loncommon::get_env_multiple('form.showcol');
2614: my (%disabledchk,%unchecked);
2615: if ($env{'form.phase'} eq '') {
2616: $disabledchk{'status'} = 1;
2617: if ($context eq 'course') {
2618: $disabledchk{'role'} = 1;
2619: $unchecked{'photo'} = 1;
1.149 raeburn 2620: $unchecked{'clicker'} = 1;
1.150 raeburn 2621: if ($showcredits) {
2622: $unchecked{'credits'} = 1;
2623: }
1.149 raeburn 2624: } elsif ($context eq 'domain') {
2625: $unchecked{'extent'} = 1;
1.140 raeburn 2626: }
2627: $unchecked{'start'} = 1;
2628: $unchecked{'end'} = 1;
2629: } else {
2630: if ($env{'form.Status'} ne 'Any') {
2631: $disabledchk{'status'} = 1;
2632: }
1.146 raeburn 2633: if (($env{'form.showrole'} ne 'Any') && ($env{'form.showrole'} ne 'cr')) {
2634: $disabledchk{'role'} = 1;
1.140 raeburn 2635: }
1.149 raeburn 2636: if ($context eq 'domain') {
2637: if (($env{'form.roletype'} eq 'course') ||
2638: ($env{'form.roletype'} eq 'community')) {
2639: $disabledchk{'status'} = 1;
1.159 raeburn 2640: $disabledchk{'authorusage'} = 1;
2641: $disabledchk{'authorquota'} = 1;
1.149 raeburn 2642: } elsif ($env{'form.roletype'} eq 'domain') {
2643: $disabledchk{'extent'} = 1;
2644: }
2645: }
1.140 raeburn 2646: }
2647: my $numposs = scalar(@cols);
1.149 raeburn 2648: my $numinrow = 7;
1.140 raeburn 2649: my %lt = &get_column_names($context);
2650: my $output = '<fieldset><legend>'.&mt('Information to show').'</legend>'."\n".'<span class="LC_nobreak">'.
2651: '<input type="button" onclick="javascript:checkAll(document.'.$formname.'.showcol);" value="'.&mt('check all').'" />'.
2652: (' 'x3).
2653: '<input type="button" onclick="javascript:uncheckAll(document.'.$formname.'.showcol);" value="'.&mt('uncheck all').'" />'.
2654: '</span><table>';
2655:
2656: for (my $i=0; $i<$numposs; $i++) {
2657: my $rem = $i%($numinrow);
2658: if ($rem == 0) {
2659: if ($i > 0) {
2660: $output .= '</tr>';
2661: }
2662: $output .= '<tr>';
2663: }
2664: my $checked;
2665: if ($env{'form.phase'} eq '') {
2666: $checked = ' checked="checked"';
2667: if ($unchecked{$cols[$i]}) {
2668: $checked = '';
2669: }
2670: if ($disabledchk{$cols[$i]}) {
2671: $checked = ' disabled="disabled"';
2672: }
2673: } elsif (grep(/^\Q$cols[$i]\E$/,@showncols)) {
2674: $checked = ' checked="checked"';
2675: } elsif ($disabledchk{$cols[$i]}) {
2676: $checked = ' disabled="disabled"';
2677: }
2678: if ($i == $numposs-1) {
2679: my $colsleft = $numinrow-$rem;
2680: if ($colsleft > 1) {
2681: $output .= '<td colspan="'.$colsleft.'">';
2682: } else {
2683: $output .= '<td>';
2684: }
2685: } else {
2686: $output .= '<td>';
2687: }
1.149 raeburn 2688: my $style;
2689: if ($cols[$i] eq 'extent') {
2690: if (($env{'form.roletype'} eq 'domain') || ($env{'form.roletype'} eq '')) {
2691: $style = ' style="display: none;"';
2692: }
1.159 raeburn 2693: } elsif (($cols[$i] eq 'authorusage') || ($cols[$i] eq 'authorquota')) {
2694: if ($env{'form.roletype'} ne 'domain') {
2695: $style = ' style="display: none;"';
2696: }
2697: }
1.149 raeburn 2698: $output .= '<span id="show'.$cols[$i].'"'.$style.'><label>'.
2699: '<input id="showcol'.$cols[$i].'" type="checkbox" name="showcol" value="'.$cols[$i].'"'.$checked.' /><span id="showcoltext'.$cols[$i].'">'.
2700: $lt{$cols[$i]}.'</span>'.
2701: '</label></span></td>';
1.140 raeburn 2702: }
2703: $output .= '</tr></table></fieldset>';
2704: return $output;
2705: }
2706:
1.2 raeburn 2707: sub list_submit_button {
2708: my ($text) = @_;
1.11 raeburn 2709: return '<input type="button" name="updatedisplay" value="'.$text.'" onclick="javascript:display_update()" />';
1.2 raeburn 2710: }
2711:
1.140 raeburn 2712: sub get_column_names {
2713: my ($context) = @_;
2714: my %lt = &Apache::lonlocal::texthash(
2715: 'username' => "username",
2716: 'domain' => "domain",
2717: 'id' => 'ID',
2718: 'fullname' => "name",
2719: 'section' => "section",
2720: 'groups' => "active groups",
2721: 'start' => "start date",
2722: 'end' => "end date",
2723: 'status' => "status",
2724: 'role' => "role",
1.150 raeburn 2725: 'credits' => "credits",
1.140 raeburn 2726: 'type' => "enroll type/action",
2727: 'email' => "e-mail address",
2728: 'photo' => "photo",
2729: 'lastlogin' => "last login",
2730: 'extent' => "extent",
1.159 raeburn 2731: 'authorusage' => "disk usage (%)",
2732: 'authorquota' => "disk quota (MB)",
1.140 raeburn 2733: 'ca' => "check all",
2734: 'ua' => "uncheck all",
2735: 'clicker' => "clicker-ID",
2736: );
2737: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
1.149 raeburn 2738: $lt{'extent'} = &mt('course(s): description, section(s), status');
1.140 raeburn 2739: } elsif ($context eq 'domain' && $env{'form.roletype'} eq 'community') {
1.154 raeburn 2740: $lt{'extent'} = &mt('community(s): description, section(s), status');
1.149 raeburn 2741: } elsif (($context eq 'author') ||
2742: ($context eq 'domain' && $env{'form.roletype'} eq 'author')) {
2743: $lt{'extent'} = &mt('author');
1.140 raeburn 2744: }
2745: return %lt;
2746: }
2747:
1.2 raeburn 2748: sub gather_userinfo {
1.11 raeburn 2749: my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_;
1.52 raeburn 2750: my $viewablesec;
2751: if ($context eq 'course') {
2752: $viewablesec = &viewable_section($permission);
2753: }
1.2 raeburn 2754: foreach my $item (keys(%{$rolehash})) {
2755: my %userdata;
1.22 raeburn 2756: if ($context eq 'author') {
1.2 raeburn 2757: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
2758: split(/:/,$item);
2759: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
1.24 raeburn 2760: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2761: $item,$userlist);
1.22 raeburn 2762: } elsif ($context eq 'course') {
2763: ($userdata{'username'},$userdata{'domain'},$userdata{'role'},
2764: $userdata{'section'}) = split(/:/,$item,-1);
2765: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
2766: if (($viewablesec ne '') && ($userdata{'section'} ne '')) {
2767: next if ($viewablesec ne $userdata{'section'});
2768: }
1.24 raeburn 2769: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2770: $item,$userlist);
1.2 raeburn 2771: } elsif ($context eq 'domain') {
2772: if ($env{'form.roletype'} eq 'domain') {
2773: ($userdata{'role'},$userdata{'username'},$userdata{'domain'}) =
2774: split(/:/,$item);
2775: ($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
1.24 raeburn 2776: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2777: $item,$userlist);
1.13 raeburn 2778: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 2779: if (ref($rolehash->{$item}) eq 'HASH') {
2780: $userdata{'extent'} = $item;
2781: foreach my $key (keys(%{$rolehash->{$item}})) {
2782: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) = split(/:/,$key);
2783: ($userdata{'start'},$userdata{'end'}) =
2784: split(/:/,$rolehash->{$item}{$key});
2785: my $uniqid = $key.':'.$item;
1.25 raeburn 2786: &build_user_record($context,\%userdata,$userinfo,
2787: $indexhash,$uniqid,$userlist);
1.2 raeburn 2788: }
2789: }
1.102 raeburn 2790: } elsif (($env{'form.roletype'} eq 'course') ||
2791: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 2792: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
2793: split(/:/,$item);
2794: if (ref($rolehash->{$item}) eq 'HASH') {
1.11 raeburn 2795: my $numcids = keys(%{$rolehash->{$item}});
1.2 raeburn 2796: foreach my $cid (sort(keys(%{$rolehash->{$item}}))) {
2797: if (ref($rolehash->{$item}{$cid}) eq 'HASH') {
2798: my $spanstart = '';
2799: my $spanend = '; ';
2800: my $space = ', ';
2801: if ($format eq 'html' || $format eq 'view') {
2802: $spanstart = '<span class="LC_nobreak">';
1.23 raeburn 2803: # FIXME: actions on courses disabled for now
2804: # if ($permission->{'cusr'}) {
2805: # if ($numcids > 1) {
1.25 raeburn 2806: # $spanstart .= '<input type="radio" name="'.$item.'" value="'.$cid.'" /> ';
1.23 raeburn 2807: # } else {
1.25 raeburn 2808: # $spanstart .= '<input type="hidden" name="'.$item.'" value="'.$cid.'" /> ';
1.23 raeburn 2809: # }
2810: # }
1.2 raeburn 2811: $spanend = '</span><br />';
2812: $space = ', ';
2813: }
2814: $userdata{'extent'} .= $spanstart.
2815: $rolehash->{$item}{$cid}{'desc'}.$space;
2816: if (ref($rolehash->{$item}{$cid}{'secs'}) eq 'HASH') {
2817: foreach my $sec (sort(keys(%{$rolehash->{$item}{$cid}{'secs'}}))) {
1.25 raeburn 2818: if (($env{'form.Status'} eq 'Any') ||
2819: ($env{'form.Status'} eq $rolehash->{$item}{$cid}{'secs'}{$sec})) {
2820: $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
2821: $userdata{'status'} = $rolehash->{$item}{$cid}{'secs'}{$sec};
2822: }
1.2 raeburn 2823: }
2824: }
2825: }
2826: }
2827: }
1.25 raeburn 2828: if ($userdata{'status'} ne '') {
2829: &build_user_record($context,\%userdata,$userinfo,
2830: $indexhash,$item,$userlist);
2831: }
1.2 raeburn 2832: }
2833: }
2834: }
2835: return;
2836: }
2837:
2838: sub build_user_record {
1.24 raeburn 2839: my ($context,$userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
1.11 raeburn 2840: next if ($userdata->{'start'} eq '-1' && $userdata->{'end'} eq '-1');
1.102 raeburn 2841: if (!(($context eq 'domain') && (($env{'form.roletype'} eq 'course')
2842: && ($env{'form.roletype'} eq 'community')))) {
1.24 raeburn 2843: &process_date_info($userdata);
2844: }
1.2 raeburn 2845: my $username = $userdata->{'username'};
2846: my $domain = $userdata->{'domain'};
2847: if (ref($userinfo->{$username.':'.$domain}) eq 'HASH') {
1.24 raeburn 2848: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
1.2 raeburn 2849: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
2850: } else {
2851: &aggregate_user_info($domain,$username,$userinfo);
2852: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
2853: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
2854: }
2855: foreach my $key (keys(%{$indexhash})) {
2856: if (defined($userdata->{$key})) {
2857: $userlist->{$record_key}[$indexhash->{$key}] = $userdata->{$key};
2858: }
2859: }
2860: return;
2861: }
2862:
2863: sub courses_selector {
2864: my ($cdom,$formname) = @_;
2865: my %codes = ();
2866: my @codetitles = ();
2867: my %cat_titles = ();
2868: my %cat_order = ();
2869: my %idlist = ();
2870: my %idnums = ();
2871: my %idlist_titles = ();
2872: my $caller = 'global';
2873: my $format_reply;
2874: my $jscript = '';
2875:
1.7 albertel 2876: my $totcodes = 0;
1.201 raeburn 2877: my $instcats = &Apache::lonnet::get_dom_instcats($cdom);
2878: if (ref($instcats) eq 'HASH') {
2879: if ((ref($instcats->{'codetitles'}) eq 'ARRAY') && (ref($instcats->{'codes'}) eq 'HASH') &&
2880: (ref($instcats->{'cat_titles'}) eq 'HASH') && (ref($instcats->{'cat_order'}) eq 'HASH')) {
2881: %codes = %{$instcats->{'codes'}};
2882: @codetitles = @{$instcats->{'codetitles'}};
2883: %cat_titles = %{$instcats->{'cat_titles'}};
2884: %cat_order = %{$instcats->{'cat_order'}};
2885: $totcodes = scalar(keys(%codes));
1.2 raeburn 2886: my $numtypes = @codetitles;
2887: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
2888: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
2889: my $longtitles_str = join('","',@{$longtitles});
2890: my $allidlist = $idlist{$codetitles[0]};
2891: $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
2892: $jscript .= $scripttext;
1.181 raeburn 2893: $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,\@codetitles);
1.2 raeburn 2894: }
2895: }
2896: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
2897:
2898: my %elements = (
2899: Year => 'selectbox',
2900: coursepick => 'radio',
2901: coursetotal => 'text',
2902: courselist => 'text',
2903: );
2904: $jscript .= &Apache::lonhtmlcommon::set_form_elements(\%elements);
2905: if ($env{'form.coursepick'} eq 'category') {
2906: $jscript .= qq|
2907: function setCourseCat(formname) {
2908: if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
2909: return;
2910: }
1.120 raeburn 2911: courseSet('$codetitles[0]');
1.2 raeburn 2912: for (var j=0; j<formname.Semester.length; j++) {
2913: if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
2914: formname.Semester.options[j].selected = true;
2915: }
2916: }
2917: if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
2918: return;
2919: }
1.120 raeburn 2920: courseSet('$codetitles[1]');
1.2 raeburn 2921: for (var j=0; j<formname.Department.length; j++) {
1.187 raeburn 2922: if (formname.Department.options[j].value == "$env{'form.Department'}") {
2923: formname.Department.options[j].selected = true;
1.2 raeburn 2924: }
2925: }
2926: if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
2927: return;
2928: }
1.120 raeburn 2929: courseSet('$codetitles[2]');
1.2 raeburn 2930: for (var j=0; j<formname.Number.length; j++) {
2931: if (formname.Number.options[j].value == "$env{'form.Number'}") {
2932: formname.Number.options[j].selected = true;
2933: }
2934: }
2935: }
2936: |;
2937: }
2938: return ($cb_jscript,$jscript,$totcodes,\@codetitles,\%idlist,
2939: \%idlist_titles);
2940: }
2941:
2942: sub course_selector_loadcode {
2943: my ($formname) = @_;
2944: my $loadcode;
2945: if ($env{'form.coursepick'} ne '') {
2946: $loadcode = 'javascript:setFormElements(document.'.$formname.')';
2947: if ($env{'form.coursepick'} eq 'category') {
2948: $loadcode .= ';javascript:setCourseCat(document.'.$formname.')';
2949: }
2950: }
2951: return $loadcode;
2952: }
2953:
2954: sub process_coursepick {
2955: my $coursefilter = $env{'form.coursepick'};
2956: my $cdom = $env{'request.role.domain'};
2957: my %courses;
1.105 raeburn 2958: my $crssrch = 'Course';
2959: if ($env{'form.roletype'} eq 'community') {
2960: $crssrch = 'Community';
2961: }
1.2 raeburn 2962: if ($coursefilter eq 'all') {
2963: %courses = &Apache::lonnet::courseiddump($cdom,'.','.','.','.','.',
1.105 raeburn 2964: undef,undef,$crssrch);
1.2 raeburn 2965: } elsif ($coursefilter eq 'category') {
2966: my $instcode = &instcode_from_coursefilter();
2967: %courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.',
1.105 raeburn 2968: undef,undef,$crssrch);
1.2 raeburn 2969: } elsif ($coursefilter eq 'specific') {
2970: if ($env{'form.coursetotal'} > 1) {
2971: my @course_ids = split(/&&/,$env{'form.courselist'});
2972: foreach my $cid (@course_ids) {
2973: $courses{$cid} = '';
1.1 raeburn 2974: }
1.2 raeburn 2975: } else {
2976: $courses{$env{'form.courselist'}} = '';
1.1 raeburn 2977: }
1.2 raeburn 2978: }
2979: return %courses;
2980: }
2981:
2982: sub instcode_from_coursefilter {
2983: my $instcode = '';
2984: my @cats = ('Semester','Year','Department','Number');
2985: foreach my $category (@cats) {
2986: if (defined($env{'form.'.$category})) {
2987: unless ($env{'form.'.$category} eq '-1') {
2988: $instcode .= $env{'form.'.$category};
2989: }
2990: }
2991: }
2992: if ($instcode eq '') {
2993: $instcode = '.';
2994: }
2995: return $instcode;
2996: }
2997:
2998: sub make_keylist_array {
2999: my ($index,$keylist);
3000: $index->{'domain'} = &Apache::loncoursedata::CL_SDOM();
3001: $index->{'username'} = &Apache::loncoursedata::CL_SNAME();
3002: $index->{'end'} = &Apache::loncoursedata::CL_END();
3003: $index->{'start'} = &Apache::loncoursedata::CL_START();
3004: $index->{'id'} = &Apache::loncoursedata::CL_ID();
3005: $index->{'section'} = &Apache::loncoursedata::CL_SECTION();
3006: $index->{'fullname'} = &Apache::loncoursedata::CL_FULLNAME();
3007: $index->{'status'} = &Apache::loncoursedata::CL_STATUS();
3008: $index->{'type'} = &Apache::loncoursedata::CL_TYPE();
3009: $index->{'lockedtype'} = &Apache::loncoursedata::CL_LOCKEDTYPE();
3010: $index->{'groups'} = &Apache::loncoursedata::CL_GROUP();
3011: $index->{'email'} = &Apache::loncoursedata::CL_PERMANENTEMAIL();
3012: $index->{'role'} = &Apache::loncoursedata::CL_ROLE();
3013: $index->{'extent'} = &Apache::loncoursedata::CL_EXTENT();
1.44 raeburn 3014: $index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
1.47 raeburn 3015: $index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();
1.150 raeburn 3016: $index->{'credits'} = &Apache::loncoursedata::CL_CREDITS();
1.174 raeburn 3017: $index->{'instsec'} = &Apache::loncoursedata::CL_INSTSEC();
1.159 raeburn 3018: $index->{'authorquota'} = &Apache::loncoursedata::CL_AUTHORQUOTA();
3019: $index->{'authorusage'} = &Apache::loncoursedata::CL_AUTHORUSAGE();
1.2 raeburn 3020: foreach my $key (keys(%{$index})) {
3021: $keylist->[$index->{$key}] = $key;
3022: }
3023: return ($index,$keylist);
3024: }
3025:
3026: sub aggregate_user_info {
3027: my ($udom,$uname,$userinfo) = @_;
3028: my %info=&Apache::lonnet::get('environment',
3029: ['firstname','middlename',
3030: 'lastname','generation','id'],
3031: $udom,$uname);
3032: my ($tmp) = keys(%info);
3033: my ($fullname,$id);
3034: if ($tmp =~/^(con_lost|error|no_such_host)/i) {
3035: $fullname = 'not available';
3036: $id = 'not available';
3037: &Apache::lonnet::logthis('unable to retrieve environment '.
3038: 'for '.$uname.':'.$udom);
1.1 raeburn 3039: } else {
1.2 raeburn 3040: $fullname = &Apache::lonnet::format_name(@info{qw/firstname middlename lastname generation/},'lastname');
3041: $id = $info{'id'};
3042: }
3043: $userinfo->{$uname.':'.$udom} = {
3044: fullname => $fullname,
3045: id => $id,
3046: };
3047: return;
3048: }
1.1 raeburn 3049:
1.2 raeburn 3050: sub process_date_info {
3051: my ($userdata) = @_;
3052: my $now = time;
1.83 raeburn 3053: $userdata->{'status'} = 'Active';
1.2 raeburn 3054: if ($userdata->{'start'} > 0) {
3055: if ($now < $userdata->{'start'}) {
1.83 raeburn 3056: $userdata->{'status'} = 'Future';
1.2 raeburn 3057: }
1.1 raeburn 3058: }
1.2 raeburn 3059: if ($userdata->{'end'} > 0) {
3060: if ($now > $userdata->{'end'}) {
1.83 raeburn 3061: $userdata->{'status'} = 'Expired';
1.2 raeburn 3062: }
3063: }
3064: return;
1.1 raeburn 3065: }
3066:
3067: sub show_users_list {
1.150 raeburn 3068: my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname,
1.159 raeburn 3069: $showcredits,$needauthorquota,$needauthorusage)=@_;
1.55 raeburn 3070: if ($formname eq '') {
3071: $formname = 'studentform';
3072: }
1.159 raeburn 3073: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1 raeburn 3074: #
3075: # Variables for excel output
3076: my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
3077: #
3078: # Variables for csv output
3079: my ($CSVfile,$CSVfilename);
3080: #
3081: my $sortby = $env{'form.sortby'};
1.3 raeburn 3082: my @sortable = ('username','domain','id','fullname','start','end','email','role');
1.2 raeburn 3083: if ($context eq 'course') {
1.3 raeburn 3084: push(@sortable,('section','groups','type'));
1.150 raeburn 3085: if ($showcredits) {
3086: push(@sortable,'credits');
3087: }
1.2 raeburn 3088: } else {
1.3 raeburn 3089: push(@sortable,'extent');
1.159 raeburn 3090: if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
3091: (($env{'form.showrole'} eq 'Any') || ($env{'form.showrole'} eq 'au'))) {
3092: push(@sortable,('authorusage','authorquota'));
3093: }
1.3 raeburn 3094: }
1.55 raeburn 3095: if ($mode eq 'pickauthor') {
3096: @sortable = ('username','fullname','email','status');
3097: }
1.156 raeburn 3098: my %is_sortable;
1.158 raeburn 3099: map { $is_sortable{$_} = 1; } @sortable;
1.156 raeburn 3100: unless ($is_sortable{$sortby}) {
1.3 raeburn 3101: $sortby = 'username';
1.1 raeburn 3102: }
1.22 raeburn 3103: my $setting = $env{'form.roletype'};
1.150 raeburn 3104: my ($cid,$cdom,$cnum,$classgroups,$crstype,$defaultcredits);
1.1 raeburn 3105: if ($context eq 'course') {
1.22 raeburn 3106: $cid = $env{'request.course.id'};
1.101 raeburn 3107: $crstype = &Apache::loncommon::course_type();
1.17 raeburn 3108: ($cnum,$cdom) = &get_course_identity($cid);
1.150 raeburn 3109: $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
1.2 raeburn 3110: ($classgroups) = &Apache::loncoursedata::get_group_memberships(
3111: $userlist,$keylist,$cdom,$cnum);
1.16 raeburn 3112: if ($mode eq 'autoenroll') {
3113: $env{'form.showrole'} = 'st';
3114: } else {
3115: if ($env{'course.'.$cid.'.internal.showphoto'}) {
3116: $r->print('
1.1 raeburn 3117: <script type="text/javascript">
1.96 bisitz 3118: // <![CDATA[
1.1 raeburn 3119: function photowindow(photolink) {
3120: var title = "Photo_Viewer";
3121: var options = "scrollbars=1,resizable=1,menubar=0";
3122: options += ",width=240,height=240";
3123: stdeditbrowser = open(photolink,title,options,"1");
3124: stdeditbrowser.focus();
3125: }
1.96 bisitz 3126: // ]]>
1.1 raeburn 3127: </script>
1.16 raeburn 3128: ');
3129: }
3130: }
1.102 raeburn 3131: } elsif ($context eq 'domain') {
3132: if ($setting eq 'community') {
3133: $crstype = 'Community';
1.105 raeburn 3134: } elsif ($setting eq 'course') {
1.102 raeburn 3135: $crstype = 'Course';
3136: }
1.1 raeburn 3137: }
1.55 raeburn 3138: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
1.40 raeburn 3139: my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
1.56 raeburn 3140: my $verify_action_js = &bulkaction_javascript($formname);
1.1 raeburn 3141: $r->print(<<END);
1.10 raeburn 3142:
3143: <script type="text/javascript" language="Javascript">
1.96 bisitz 3144: // <![CDATA[
1.11 raeburn 3145:
1.56 raeburn 3146: $verify_action_js
1.10 raeburn 3147:
3148: function username_display_launch(username,domain) {
3149: var target;
1.177 raeburn 3150: if (!document.$formname.usernamelink.length) {
3151: target = document.$formname.usernamelink.value;
3152: } else {
3153: for (var i=0; i<document.$formname.usernamelink.length; i++) {
3154: if (document.$formname.usernamelink[i].checked) {
3155: target = document.$formname.usernamelink[i].value;
3156: }
1.10 raeburn 3157: }
3158: }
1.179 raeburn 3159: if ((target == 'modify') || (target == 'activity')) {
3160: var nextaction = 'singleuser';
3161: if (target == 'activity') {
3162: nextaction = 'accesslogs';
3163: }
1.55 raeburn 3164: if (document.$formname.userwin.checked == true) {
1.179 raeburn 3165: 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 3166: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3167: modifywin = window.open(url,'',options,1);
3168: modifywin.focus();
3169: return;
3170: } else {
1.55 raeburn 3171: document.$formname.srchterm.value=username;
3172: document.$formname.srchdomain.value=domain;
3173: document.$formname.phase.value='get_user_info';
1.179 raeburn 3174: document.$formname.action.value = nextaction;
1.55 raeburn 3175: document.$formname.submit();
1.50 raeburn 3176: }
1.10 raeburn 3177: }
1.48 raeburn 3178: if (target == 'aboutme') {
1.55 raeburn 3179: if (document.$formname.userwin.checked == true) {
1.50 raeburn 3180: var url = '/adm/'+domain+'/'+username+'/aboutme?popup=1';
3181: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3182: aboutmewin = window.open(url,'',options,1);
3183: aboutmewin.focus();
3184: return;
3185: } else {
3186: document.location.href = '/adm/'+domain+'/'+username+'/aboutme';
3187: }
1.48 raeburn 3188: }
1.98 raeburn 3189: if (target == 'track') {
3190: if (document.$formname.userwin.checked == true) {
3191: var url = '/adm/trackstudent?selected_student='+username+':'+domain+'&only_body=1';
3192: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3193: var trackwin = window.open(url,'',options,1);
3194: trackwin.focus();
3195: return;
3196: } else {
3197: document.location.href = '/adm/trackstudent?selected_student='+username+':'+domain;
3198: }
3199: }
1.10 raeburn 3200: }
1.96 bisitz 3201: // ]]>
1.10 raeburn 3202: </script>
1.11 raeburn 3203: $date_sec_selector
1.1 raeburn 3204: <input type="hidden" name="state" value="$env{'form.state'}" />
3205: END
3206: }
3207: $r->print(<<END);
3208: <input type="hidden" name="sortby" value="$sortby" />
3209: END
1.150 raeburn 3210: my @cols = &infocolumns($context,$mode,$showcredits);
1.140 raeburn 3211: my %coltxt = &get_column_names($context);
3212: my %acttxt = &Apache::lonlocal::texthash(
1.11 raeburn 3213: 'pr' => "Proceed",
3214: 'ac' => "Action to take for selected users",
1.56 raeburn 3215: 'link' => "Behavior of clickable username link for each user",
1.82 weissno 3216: 'aboutme' => "Display a user's personal information page",
1.50 raeburn 3217: 'owin' => "Open in a new window",
1.10 raeburn 3218: 'modify' => "Modify a user's information",
1.98 raeburn 3219: 'track' => "View a user's recent activity",
1.179 raeburn 3220: 'activity' => "View a user's access log",
1.1 raeburn 3221: );
1.140 raeburn 3222: my %lt = (%coltxt,%acttxt);
1.4 raeburn 3223: my $rolefilter = $env{'form.showrole'};
1.5 raeburn 3224: if ($env{'form.showrole'} eq 'cr') {
3225: $rolefilter = &mt('custom');
3226: } elsif ($env{'form.showrole'} ne 'Any') {
1.101 raeburn 3227: $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'},$crstype);
1.2 raeburn 3228: }
1.16 raeburn 3229: my $results_description;
3230: if ($mode ne 'autoenroll') {
3231: $results_description = &results_header_row($rolefilter,$statusmode,
1.102 raeburn 3232: $context,$permission,$mode,$crstype);
1.140 raeburn 3233: $r->print('<b>'.$results_description.'</b><br clear="all" />');
1.16 raeburn 3234: }
1.26 raeburn 3235: my ($output,$actionselect,%canchange,%canchangesec);
1.55 raeburn 3236: if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
3237: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
1.16 raeburn 3238: if ($permission->{'cusr'}) {
1.105 raeburn 3239: unless (($context eq 'domain') &&
3240: (($setting eq 'course') || ($setting eq 'community'))) {
3241: $actionselect =
3242: &select_actions($context,$setting,$statusmode,$formname);
3243: }
1.16 raeburn 3244: }
3245: $r->print(<<END);
1.10 raeburn 3246: <input type="hidden" name="srchby" value="uname" />
3247: <input type="hidden" name="srchin" value="dom" />
3248: <input type="hidden" name="srchtype" value="exact" />
3249: <input type="hidden" name="srchterm" value="" />
1.11 raeburn 3250: <input type="hidden" name="srchdomain" value="" />
1.1 raeburn 3251: END
1.16 raeburn 3252: if ($actionselect) {
1.41 raeburn 3253: $output .= <<"END";
1.94 bisitz 3254: <div class="LC_left_float"><fieldset><legend>$lt{'ac'}</legend>
1.56 raeburn 3255: $actionselect
3256: <br/><br /><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.$formname.actionlist)" />
3257: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.$formname.actionlist)" /><br /><input type="button" value="$lt{'pr'}" onclick="javascript:verify_action('actionlist')" /></fieldset></div>
1.11 raeburn 3258: END
1.26 raeburn 3259: my @allroles;
3260: if ($env{'form.showrole'} eq 'Any') {
3261: my $custom = 1;
3262: if ($context eq 'domain') {
1.101 raeburn 3263: @allroles = &roles_by_context($setting,$custom,$crstype);
1.26 raeburn 3264: } else {
1.101 raeburn 3265: @allroles = &roles_by_context($context,$custom,$crstype);
1.26 raeburn 3266: }
3267: } else {
3268: @allroles = ($env{'form.showrole'});
3269: }
3270: foreach my $role (@allroles) {
3271: if ($context eq 'domain') {
3272: if ($setting eq 'domain') {
3273: if (&Apache::lonnet::allowed('c'.$role,
3274: $env{'request.role.domain'})) {
3275: $canchange{$role} = 1;
3276: }
1.31 raeburn 3277: } elsif ($setting eq 'author') {
3278: if (&Apache::lonnet::allowed('c'.$role,
3279: $env{'request.role.domain'})) {
3280: $canchange{$role} = 1;
3281: }
1.26 raeburn 3282: }
3283: } elsif ($context eq 'author') {
3284: if (&Apache::lonnet::allowed('c'.$role,
3285: $env{'user.domain'}.'/'.$env{'user.name'})) {
3286: $canchange{$role} = 1;
3287: }
3288: } elsif ($context eq 'course') {
3289: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
3290: $canchange{$role} = 1;
3291: } elsif ($env{'request.course.sec'} ne '') {
3292: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
3293: $canchangesec{$role} = $env{'request.course.sec'};
3294: }
1.141 raeburn 3295: } elsif ((($role eq 'co') && ($crstype eq 'Community')) ||
3296: (($role eq 'cc') && ($crstype eq 'Course'))) {
3297: if (&is_courseowner($env{'request.course.id'},
3298: $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
3299: $canchange{$role} = 1;
3300: }
1.26 raeburn 3301: }
3302: }
3303: }
1.16 raeburn 3304: }
1.94 bisitz 3305: $output .= '<div class="LC_left_float"><fieldset><legend>'.$lt{'link'}.'</legend>'.
1.56 raeburn 3306: '<table><tr>';
3307: my @linkdests = ('aboutme');
3308: if ($permission->{'cusr'}) {
3309: unshift (@linkdests,'modify');
3310: }
1.179 raeburn 3311: if ($context eq 'course') {
3312: if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) ||
3313: &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.
3314: $env{'request.course.sec'})) {
3315: push(@linkdests,'track');
3316: }
3317: } elsif ($context eq 'domain') {
3318: if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
3319: push(@linkdests,'activity');
3320: }
1.98 raeburn 3321: }
1.56 raeburn 3322: $output .= '<td>';
3323: my $usernamelink = $env{'form.usernamelink'};
3324: if ($usernamelink eq '') {
3325: $usernamelink = 'aboutme';
3326: }
3327: foreach my $item (@linkdests) {
3328: my $checkedstr = '';
3329: if ($item eq $usernamelink) {
1.86 bisitz 3330: $checkedstr = ' checked="checked"';
1.56 raeburn 3331: }
1.86 bisitz 3332: $output .= '<span class="LC_nobreak"><label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.' /> '.$lt{$item}.'</label></span><br />';
1.56 raeburn 3333: }
3334: my $checkwin;
3335: if ($env{'form.userwin'}) {
1.86 bisitz 3336: $checkwin = ' checked="checked"';
1.56 raeburn 3337: }
1.144 bisitz 3338: $output .=
3339: '</td><td valign="top" style="border-left: 1px solid;">'
3340: .'<span class="LC_nobreak"><label>'
3341: .'<input type="checkbox" name="userwin" value="1"'.$checkwin.' />'.$lt{'owin'}
3342: .'</label></span></td></tr></table></fieldset></div>';
1.4 raeburn 3343: }
1.184 raeburn 3344: $output .= "\n".'<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
1.1 raeburn 3345: &Apache::loncommon::start_data_table().
1.4 raeburn 3346: &Apache::loncommon::start_data_table_header_row();
1.1 raeburn 3347: if ($mode eq 'autoenroll') {
1.4 raeburn 3348: $output .= "
1.55 raeburn 3349: <th><a href=\"javascript:document.$formname.sortby.value='type';document.$formname.submit();\">$lt{'type'}</a></th>
1.4 raeburn 3350: ";
1.1 raeburn 3351: } else {
1.105 raeburn 3352: $output .= "\n".'<th> </th>'."\n";
1.11 raeburn 3353: if ($actionselect) {
1.159 raeburn 3354: $output .= '<th class="LC_nobreak" valign="top">'.&mt('Select').'</th>'."\n";
1.11 raeburn 3355: }
1.1 raeburn 3356: }
3357: foreach my $item (@cols) {
1.159 raeburn 3358: $output .= '<th class="LC_nobreak" valign="top">';
1.156 raeburn 3359: if ($is_sortable{$item}) {
1.159 raeburn 3360: $output .= "<a href=\"javascript:document.$formname.sortby.value='$item';document.$formname.submit();\" style=\"text-decoration:none;\">$lt{$item}<span class=\"LC_fontsize_small\"> ▼</span></a>";
1.156 raeburn 3361: } else {
3362: $output .= $lt{$item};
3363: }
3364: $output .= "</th>\n";
1.1 raeburn 3365: }
1.2 raeburn 3366: my %role_types = &role_type_names();
1.16 raeburn 3367: $output .= &Apache::loncommon::end_data_table_header_row();
1.1 raeburn 3368: # Done with the HTML header line
3369: } elsif ($mode eq 'csv') {
3370: #
3371: # Open a file
3372: $CSVfilename = '/prtspool/'.
1.2 raeburn 3373: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
3374: time.'_'.rand(1000000000).'.csv';
1.1 raeburn 3375: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
3376: $r->log_error("Couldn't open $CSVfilename for output $!");
1.108 bisitz 3377: $r->print(
3378: '<p class="LC_error">'
3379: .&mt('Problems occurred in writing the CSV file.')
3380: .' '.&mt('This error has been logged.')
3381: .' '.&mt('Please alert your LON-CAPA administrator.')
3382: .'</p>'
3383: );
1.1 raeburn 3384: $CSVfile = undef;
3385: }
3386: #
3387: # Write headers and data to file
1.2 raeburn 3388: print $CSVfile '"'.$results_description.'"'."\n";
1.1 raeburn 3389: print $CSVfile '"'.join('","',map {
3390: &Apache::loncommon::csv_translate($lt{$_})
1.67 droeschl 3391: } (@cols))."\"\n";
1.1 raeburn 3392: } elsif ($mode eq 'excel') {
3393: # Create the excel spreadsheet
3394: ($excel_workbook,$excel_filename,$format) =
3395: &Apache::loncommon::create_workbook($r);
3396: return if (! defined($excel_workbook));
3397: $excel_sheet = $excel_workbook->addworksheet('userlist');
1.2 raeburn 3398: $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
1.1 raeburn 3399: #
3400: my @colnames = map {$lt{$_}} (@cols);
1.67 droeschl 3401:
1.1 raeburn 3402: $excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
3403: }
3404:
3405: # Done with header lines in all formats
3406: my %index;
3407: my $i;
1.2 raeburn 3408: foreach my $idx (@$keylist) {
3409: $index{$idx} = $i++;
3410: }
1.4 raeburn 3411: my $usercount = 0;
1.33 raeburn 3412: my ($secfilter,$grpfilter);
3413: if ($context eq 'course') {
3414: $secfilter = $env{'form.secfilter'};
3415: $grpfilter = $env{'form.grpfilter'};
3416: if ($secfilter eq '') {
3417: $secfilter = 'all';
3418: }
3419: if ($grpfilter eq '') {
3420: $grpfilter = 'all';
3421: }
3422: }
1.83 raeburn 3423: my %ltstatus = &Apache::lonlocal::texthash(
3424: Active => 'Active',
3425: Future => 'Future',
3426: Expired => 'Expired',
3427: );
1.139 raeburn 3428: # If this is for a single course get last course "log-in".
3429: my %crslogins;
3430: if ($context eq 'course') {
3431: %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$cnum);
3432: }
1.2 raeburn 3433: # Get groups, role, permanent e-mail so we can sort on them if
3434: # necessary.
3435: foreach my $user (keys(%{$userlist})) {
1.43 raeburn 3436: if ($user eq '' ) {
3437: delete($userlist->{$user});
3438: next;
3439: }
1.11 raeburn 3440: if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) {
3441: delete($userlist->{$user});
3442: next;
3443: }
1.2 raeburn 3444: my ($uname,$udom,$role,$groups,$email);
1.5 raeburn 3445: if (($statusmode ne 'Any') &&
3446: ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
3447: delete($userlist->{$user});
3448: next;
3449: }
1.2 raeburn 3450: if ($context eq 'domain') {
3451: if ($env{'form.roletype'} eq 'domain') {
3452: ($role,$uname,$udom) = split(/:/,$user);
1.11 raeburn 3453: if (($uname eq $env{'request.role.domain'}.'-domainconfig') &&
3454: ($udom eq $env{'request.role.domain'})) {
3455: delete($userlist->{$user});
3456: next;
3457: }
1.13 raeburn 3458: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 3459: ($uname,$udom,$role) = split(/:/,$user,-1);
1.102 raeburn 3460: } elsif (($env{'form.roletype'} eq 'course') ||
3461: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 3462: ($uname,$udom,$role) = split(/:/,$user);
3463: }
3464: } else {
3465: ($uname,$udom,$role) = split(/:/,$user,-1);
3466: if (($context eq 'course') && $role eq '') {
3467: $role = 'st';
3468: }
3469: }
3470: $userlist->{$user}->[$index{'role'}] = $role;
3471: if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
3472: delete($userlist->{$user});
3473: next;
3474: }
1.33 raeburn 3475: if ($context eq 'course') {
3476: my @ac_groups;
3477: if (ref($classgroups) eq 'HASH') {
3478: $groups = $classgroups->{$user};
3479: }
3480: if (ref($groups->{'active'}) eq 'HASH') {
3481: @ac_groups = keys(%{$groups->{'active'}});
3482: $userlist->{$user}->[$index{'groups'}] = join(', ',@ac_groups);
3483: }
3484: if ($mode ne 'autoenroll') {
3485: my $section = $userlist->{$user}->[$index{'section'}];
1.43 raeburn 3486: if (($env{'request.course.sec'} ne '') &&
3487: ($section ne $env{'request.course.sec'})) {
3488: if ($role eq 'st') {
3489: delete($userlist->{$user});
3490: next;
3491: }
3492: }
1.33 raeburn 3493: if ($secfilter eq 'none') {
3494: if ($section ne '') {
3495: delete($userlist->{$user});
3496: next;
3497: }
3498: } elsif ($secfilter ne 'all') {
3499: if ($section ne $secfilter) {
3500: delete($userlist->{$user});
3501: next;
3502: }
3503: }
3504: if ($grpfilter eq 'none') {
3505: if (@ac_groups > 0) {
3506: delete($userlist->{$user});
3507: next;
3508: }
3509: } elsif ($grpfilter ne 'all') {
3510: if (!grep(/^\Q$grpfilter\E$/,@ac_groups)) {
3511: delete($userlist->{$user});
3512: next;
3513: }
3514: }
1.44 raeburn 3515: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
1.140 raeburn 3516: if ((grep/^photo$/,@cols) && ($role eq 'st')) {
1.44 raeburn 3517: $userlist->{$user}->[$index{'photo'}] =
1.47 raeburn 3518: &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg');
3519: $userlist->{$user}->[$index{'thumbnail'}] =
1.44 raeburn 3520: &Apache::lonnet::retrievestudentphoto($udom,$uname,
3521: 'gif','thumbnail');
3522: }
3523: }
1.150 raeburn 3524: if (($role eq 'st') && ($defaultcredits)) {
3525: if ($userlist->{$user}->[$index{'credits'}] eq '') {
3526: $userlist->{$user}->[$index{'credits'}] = $defaultcredits;
3527: }
3528: }
1.33 raeburn 3529: }
1.2 raeburn 3530: }
3531: my %emails = &Apache::loncommon::getemails($uname,$udom);
3532: if ($emails{'permanentemail'} =~ /\S/) {
3533: $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
3534: }
1.159 raeburn 3535: if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
3536: ($role eq 'au')) {
3537: my ($disk_quota,$current_disk_usage,$percent);
3538: if (($needauthorusage) || ($needauthorquota)) {
3539: $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author');
3540: }
3541: if ($needauthorusage) {
3542: $current_disk_usage =
3543: &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname");
3544: if ($disk_quota == 0) {
3545: $percent = 100.0;
3546: } else {
3547: $percent = $current_disk_usage/(10 * $disk_quota);
3548: }
3549: $userlist->{$user}->[$index{'authorusage'}] = sprintf("%.0f",$percent);
3550: }
3551: if ($needauthorquota) {
3552: $userlist->{$user}->[$index{'authorquota'}] = sprintf("%.2f",$disk_quota);
3553: }
3554: }
1.4 raeburn 3555: $usercount ++;
3556: }
3557: my $autocount = 0;
3558: my $manualcount = 0;
3559: my $lockcount = 0;
3560: my $unlockcount = 0;
3561: if ($usercount) {
3562: $r->print($output);
3563: } else {
3564: if ($mode eq 'autoenroll') {
3565: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
3566: } else {
3567: return;
3568: }
1.1 raeburn 3569: }
1.2 raeburn 3570: #
3571: # Sort the users
1.1 raeburn 3572: my $index = $index{$sortby};
3573: my $second = $index{'username'};
3574: my $third = $index{'domain'};
1.159 raeburn 3575: my @sorted_users;
3576: if (($sortby eq 'authorquota') || ($sortby eq 'authorusage')) {
3577: @sorted_users = sort {
3578: $userlist->{$b}->[$index] <=> $userlist->{$a}->[$index] ||
3579: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
3580: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
3581: } (keys(%$userlist));
3582: } else {
3583: @sorted_users = sort {
3584: lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index]) ||
3585: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
3586: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
3587: } (keys(%$userlist));
3588: }
1.4 raeburn 3589: my $rowcount = 0;
1.178 raeburn 3590: my $disabled;
3591: if ($mode eq 'autoenroll') {
3592: unless ($permission->{'cusr'}) {
3593: $disabled = ' disabled="disabled"';
3594: }
3595: }
1.2 raeburn 3596: foreach my $user (@sorted_users) {
1.4 raeburn 3597: my %in;
1.2 raeburn 3598: my $sdata = $userlist->{$user};
1.4 raeburn 3599: $rowcount ++;
1.2 raeburn 3600: foreach my $item (@{$keylist}) {
3601: $in{$item} = $sdata->[$index{$item}];
3602: }
1.67 droeschl 3603: my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
3604: if ($clickers!~/\w/) { $clickers='-'; }
1.159 raeburn 3605: $in{'clicker'} = $clickers;
1.67 droeschl 3606: my $role = $in{'role'};
1.102 raeburn 3607: $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
1.136 raeburn 3608: unless ($mode eq 'excel') {
3609: if (! defined($in{'start'}) || $in{'start'} == 0) {
3610: $in{'start'} = &mt('none');
3611: } else {
3612: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
3613: }
3614: if (! defined($in{'end'}) || $in{'end'} == 0) {
3615: $in{'end'} = &mt('none');
3616: } else {
3617: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
3618: }
1.1 raeburn 3619: }
1.139 raeburn 3620: if ($context eq 'course') {
3621: my $lastlogin = $crslogins{$in{'username'}.':'.$in{'domain'}.':'.$in{'section'}.':'.$role};
3622: if ($lastlogin ne '') {
3623: $in{'lastlogin'} = &Apache::lonlocal::locallocaltime($lastlogin);
3624: }
3625: }
1.55 raeburn 3626: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2 raeburn 3627: $r->print(&Apache::loncommon::start_data_table_row());
1.11 raeburn 3628: my $checkval;
1.16 raeburn 3629: if ($mode eq 'autoenroll') {
3630: my $cellentry;
3631: if ($in{'type'} eq 'auto') {
1.178 raeburn 3632: $cellentry = '<b>'.&mt('auto').'</b> <label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Change').'</label>';
1.16 raeburn 3633: $autocount ++;
3634: } else {
1.178 raeburn 3635: $cellentry = '<table border="0" cellspacing="0"><tr><td rowspan="2"><b>'.&mt('manual').'</b></td><td><span class="LC_nobreak"><label><input type="checkbox" name="chgmanual" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Change').'</label></span></td></tr><tr><td><span class="LC_nobreak">';
1.16 raeburn 3636: $manualcount ++;
3637: if ($in{'lockedtype'}) {
1.178 raeburn 3638: $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Unlock').'</label>';
1.16 raeburn 3639: $unlockcount ++;
3640: } else {
1.178 raeburn 3641: $cellentry .= '<label><input type="checkbox" name="lockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Lock').'</label>';
1.16 raeburn 3642: $lockcount ++;
1.11 raeburn 3643: }
1.76 bisitz 3644: $cellentry .= '</span></td></tr></table>';
1.16 raeburn 3645: }
3646: $r->print("<td>$cellentry</td>\n");
3647: } else {
1.55 raeburn 3648: if ($mode ne 'pickauthor') {
3649: $r->print("<td>$rowcount</td>\n");
3650: }
1.16 raeburn 3651: if ($actionselect) {
1.26 raeburn 3652: my $showcheckbox;
3653: if ($role =~ /^cr\//) {
3654: $showcheckbox = $canchange{'cr'};
3655: } else {
3656: $showcheckbox = $canchange{$role};
3657: }
3658: if (!$showcheckbox) {
3659: if ($context eq 'course') {
3660: if ($canchangesec{$role} ne '') {
3661: if ($canchangesec{$role} eq $in{'section'}) {
3662: $showcheckbox = 1;
3663: }
3664: }
1.16 raeburn 3665: }
1.26 raeburn 3666: }
3667: if ($showcheckbox) {
3668: $checkval = $user;
3669: if ($context eq 'course') {
1.141 raeburn 3670: if (($role eq 'co' || $role eq 'cc') &&
3671: ($user =~ /^\Q$env{'user.name'}:$env{'user.domain'}:$role\E/)) {
3672: $showcheckbox = 0;
3673: } else {
3674: if ($role eq 'st') {
3675: $checkval .= ':st';
3676: }
3677: $checkval .= ':'.$in{'section'};
3678: if ($role eq 'st') {
3679: $checkval .= ':'.$in{'type'}.':'.
1.150 raeburn 3680: $in{'lockedtype'}.':'.
1.174 raeburn 3681: $in{'credits'}.':'.
3682: &escape($in{'instsec'});
1.141 raeburn 3683: }
3684: }
3685: }
3686: if ($showcheckbox) {
3687: $r->print('<td><input type="checkbox" name="'.
1.183 raeburn 3688: 'actionlist" value="'.
3689: &HTML::Entities::encode($checkval,'&<>"').'" />');
3690: foreach my $item ('start','end') {
3691: $r->print('<input type="hidden" name="'.
3692: &HTML::Entities::encode($checkval.'_'.$item,'&<>"').'"'.
3693: ' value="'.$sdata->[$index{$item}].'" />');
3694: }
3695: $r->print('</td>');
1.141 raeburn 3696: } else {
3697: $r->print('<td> </td>');
1.16 raeburn 3698: }
1.26 raeburn 3699: } else {
3700: $r->print('<td> </td>');
1.16 raeburn 3701: }
1.55 raeburn 3702: } elsif ($mode eq 'pickauthor') {
3703: $r->print('<td><input type="button" name="chooseauthor" onclick="javascript:gochoose('."'$in{'username'}'".');" value="'.&mt('Select').'" /></td>');
1.11 raeburn 3704: }
3705: }
1.2 raeburn 3706: foreach my $item (@cols) {
1.10 raeburn 3707: if ($item eq 'username') {
1.48 raeburn 3708: $r->print('<td>'.&print_username_link($mode,\%in).'</td>');
1.83 raeburn 3709: } elsif ($item eq 'status') {
3710: my $showitem = $in{$item};
3711: if (defined($ltstatus{$in{$item}})) {
3712: $showitem = $ltstatus{$in{$item}};
3713: }
3714: $r->print('<td>'.$showitem.'</td>'."\n");
1.140 raeburn 3715: } elsif ($item eq 'photo') {
3716: if (($context eq 'course') && ($mode ne 'autoenroll') &&
3717: ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
3718: if ($role eq 'st') {
3719: $r->print('<td align="right"><a href="javascript:photowindow('."'".$in{'photo'}."'".')"><img src="'.$in{'thumbnail'}.'" border="1" alt="" /></a></td>');
3720: } else {
3721: $r->print('<td> </td>');
3722: }
3723: }
3724: } elsif ($item eq 'clicker') {
3725: if (($context eq 'course') && ($mode ne 'autoenroll')) {
3726: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
3727: my $clickers =
3728: (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
3729: if ($clickers!~/\w/) { $clickers='-'; }
3730: $r->print('<td>'.$clickers.'</td>');
3731: } else {
3732: $r->print('<td> </td>'."\n");
3733: }
1.149 raeburn 3734: }
1.159 raeburn 3735: } elsif (($item eq 'authorquota') || ($item eq 'authorusage')) {
3736: $r->print('<td align="right">'.$in{$item}.'</td>'."\n");
1.10 raeburn 3737: } else {
3738: $r->print('<td>'.$in{$item}.'</td>'."\n");
3739: }
1.2 raeburn 3740: }
3741: $r->print(&Apache::loncommon::end_data_table_row());
3742: } elsif ($mode eq 'csv') {
3743: next if (! defined($CSVfile));
3744: # no need to bother with $linkto
3745: my @line = ();
3746: foreach my $item (@cols) {
3747: push @line,&Apache::loncommon::csv_translate($in{$item});
3748: }
1.67 droeschl 3749: print $CSVfile '"'.join('","',@line)."\"\n";
1.2 raeburn 3750: } elsif ($mode eq 'excel') {
3751: my $col = 0;
3752: foreach my $item (@cols) {
3753: if ($item eq 'start' || $item eq 'end') {
1.136 raeburn 3754: if ((defined($in{$item})) && ($in{$item} != 0)) {
1.2 raeburn 3755: $excel_sheet->write($row,$col++,
1.136 raeburn 3756: &Apache::lonstathelpers::calc_serial($in{$item}),
1.2 raeburn 3757: $format->{'date'});
3758: } else {
3759: $excel_sheet->write($row,$col++,'none');
3760: }
3761: } else {
3762: $excel_sheet->write($row,$col++,$in{$item});
3763: }
3764: }
3765: $row++;
1.1 raeburn 3766: }
3767: }
1.55 raeburn 3768: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2 raeburn 3769: $r->print(&Apache::loncommon::end_data_table().'<br />');
3770: } elsif ($mode eq 'excel') {
3771: $excel_workbook->close();
1.162 bisitz 3772: $r->print('<p>'.&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '<a href="'.$excel_filename.'">','</a>')."</p>\n");
1.2 raeburn 3773: } elsif ($mode eq 'csv') {
3774: close($CSVfile);
1.162 bisitz 3775: $r->print('<p>'.&mt('[_1]Your CSV file[_2] is ready for download.', '<a href="'.$CSVfilename.'">','</a>')."</p>\n");
1.2 raeburn 3776: $r->rflush();
3777: }
3778: if ($mode eq 'autoenroll') {
3779: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
1.4 raeburn 3780: } else {
3781: return ($usercount);
1.2 raeburn 3782: }
1.1 raeburn 3783: }
3784:
1.56 raeburn 3785: sub bulkaction_javascript {
3786: my ($formname,$caller) = @_;
3787: my $docstart = 'document';
3788: if ($caller eq 'popup') {
3789: $docstart = 'opener.document';
3790: }
3791: my %lt = &Apache::lonlocal::texthash(
3792: acwi => 'Access will be set to start immediately',
3793: asyo => 'as you did not select an end date in the pop-up window',
3794: accw => 'Access will be set to continue indefinitely',
3795: asyd => 'as you did not select an end date in the pop-up window',
3796: sewi => "Sections will be switched to 'No section'",
3797: ayes => "as you either selected the 'No section' option",
3798: oryo => 'or you did not select a section in the pop-up window',
3799: arol => 'A role with no section will be added',
3800: swbs => 'Sections will be switched to:',
3801: rwba => 'Roles will be added for section(s):',
3802: );
3803: my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
3804: my $noaction = &mt("You need to select an action to take for the user(s) you have selected");
3805: my $singconfirm = &mt(' for a single user?');
3806: my $multconfirm = &mt(' for multiple users?');
1.170 damieng 3807: &js_escape(\$alert);
3808: &js_escape(\$noaction);
3809: &js_escape(\$singconfirm);
3810: &js_escape(\$multconfirm);
1.56 raeburn 3811: my $output = <<"ENDJS";
3812: function verify_action (field) {
3813: var numchecked = 0;
3814: var singconf = '$singconfirm';
3815: var multconf = '$multconfirm';
3816: if ($docstart.$formname.elements[field].length > 0) {
3817: for (i=0; i<$docstart.$formname.elements[field].length; i++) {
3818: if ($docstart.$formname.elements[field][i].checked == true) {
3819: numchecked ++;
3820: }
3821: }
3822: } else {
3823: if ($docstart.$formname.elements[field].checked == true) {
3824: numchecked ++;
3825: }
3826: }
3827: if (numchecked == 0) {
3828: alert("$alert");
3829: return;
3830: } else {
3831: var message = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].text;
3832: var choice = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].value;
3833: if (choice == '') {
3834: alert("$noaction");
3835: return;
3836: } else {
3837: if (numchecked == 1) {
3838: message += singconf;
3839: } else {
3840: message += multconf;
3841: }
3842: ENDJS
3843: if ($caller ne 'popup') {
3844: $output .= <<"NEWWIN";
3845: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate' || choice == 'chgsec') {
3846: opendatebrowser(document.$formname,'$formname','go');
3847: return;
3848:
3849: } else {
3850: if (confirm(message)) {
3851: document.$formname.phase.value = 'bulkchange';
3852: document.$formname.submit();
3853: return;
3854: }
3855: }
3856: NEWWIN
3857: } else {
3858: $output .= <<"POPUP";
3859: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
3860: var datemsg = '';
3861: if (($docstart.$formname.startdate_month.value == '') &&
3862: ($docstart.$formname.startdate_day.value == '') &&
3863: ($docstart.$formname.startdate_year.value == '')) {
3864: datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
3865: }
3866: if (($docstart.$formname.enddate_month.value == '') &&
3867: ($docstart.$formname.enddate_day.value == '') &&
3868: ($docstart.$formname.enddate_year.value == '')) {
3869: datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
3870: }
3871: if (datemsg != '') {
3872: message += "\\n"+datemsg;
3873: }
3874: }
3875: if (choice == 'chgsec') {
3876: var rolefilter = $docstart.$formname.showrole.options[$docstart.$formname.showrole.selectedIndex].value;
3877: var retained = $docstart.$formname.retainsec.value;
3878: var secshow = $docstart.$formname.newsecs.value;
3879: if (secshow == '') {
3880: if (rolefilter == 'st' || retained == 0 || retained == "") {
3881: message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
3882: } else {
3883: message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
3884: }
3885: } else {
3886: if (rolefilter == 'st' || retained == 0 || retained == "") {
3887: message += "\\n\\n$lt{'swbs'} "+secshow+".\\n";
3888: } else {
3889: message += "\\n\\n$lt{'rwba'} "+secshow+".\\n";
3890: }
3891: }
3892: }
3893: if (confirm(message)) {
3894: $docstart.$formname.phase.value = 'bulkchange';
3895: $docstart.$formname.submit();
3896: window.close();
3897: }
3898: POPUP
3899: }
3900: $output .= '
3901: }
3902: }
3903: }
3904: ';
3905: return $output;
3906: }
3907:
1.10 raeburn 3908: sub print_username_link {
1.48 raeburn 3909: my ($mode,$in) = @_;
1.10 raeburn 3910: my $output;
1.16 raeburn 3911: if ($mode eq 'autoenroll') {
3912: $output = $in->{'username'};
1.10 raeburn 3913: } else {
3914: $output = '<a href="javascript:username_display_launch('.
1.112 bisitz 3915: "'$in->{'username'}','$in->{'domain'}'".')">'.
1.10 raeburn 3916: $in->{'username'}.'</a>';
3917: }
3918: return $output;
3919: }
3920:
1.2 raeburn 3921: sub role_type_names {
3922: my %lt = &Apache::lonlocal::texthash (
1.13 raeburn 3923: 'domain' => 'Domain Roles',
3924: 'author' => 'Co-Author Roles',
3925: 'course' => 'Course Roles',
1.101 raeburn 3926: 'community' => 'Community Roles',
1.2 raeburn 3927: );
3928: return %lt;
3929: }
3930:
1.11 raeburn 3931: sub select_actions {
1.55 raeburn 3932: my ($context,$setting,$statusmode,$formname) = @_;
1.11 raeburn 3933: my %lt = &Apache::lonlocal::texthash(
3934: revoke => "Revoke user roles",
3935: delete => "Delete user roles",
3936: reenable => "Re-enable expired user roles",
3937: activate => "Make future user roles active now",
3938: chgdates => "Change starting/ending dates",
3939: chgsec => "Change section associated with user roles",
3940: );
1.150 raeburn 3941: # FIXME Add an option to change credits for student roles.
1.11 raeburn 3942: my ($output,$options,%choices);
1.23 raeburn 3943: # FIXME Disable actions for now for roletype=course in domain context
3944: if ($context eq 'domain' && $setting eq 'course') {
3945: return;
3946: }
1.26 raeburn 3947: if ($context eq 'course') {
3948: if ($env{'form.showrole'} ne 'Any') {
1.141 raeburn 3949: my $showactions;
3950: if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},
3951: $env{'request.course.id'})) {
3952: $showactions = 1;
3953: } elsif ($env{'request.course.sec'} ne '') {
3954: if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
3955: $showactions = 1;
3956: }
3957: }
3958: unless ($showactions) {
3959: unless (&is_courseowner($env{'request.course.id'},
3960: $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
3961: return;
3962: }
1.26 raeburn 3963: }
3964: }
3965: }
1.11 raeburn 3966: if ($statusmode eq 'Any') {
3967: $options .= '
3968: <option value="chgdates">'.$lt{'chgdates'}.'</option>';
3969: $choices{'dates'} = 1;
3970: } else {
3971: if ($statusmode eq 'Future') {
3972: $options .= '
3973: <option value="activate">'.$lt{'activate'}.'</option>';
3974: $choices{'dates'} = 1;
3975: } elsif ($statusmode eq 'Expired') {
3976: $options .= '
3977: <option value="reenable">'.$lt{'reenable'}.'</option>';
3978: $choices{'dates'} = 1;
3979: }
1.13 raeburn 3980: if ($statusmode eq 'Active' || $statusmode eq 'Future') {
3981: $options .= '
3982: <option value="chgdates">'.$lt{'chgdates'}.'</option>
3983: <option value="revoke">'.$lt{'revoke'}.'</option>';
3984: $choices{'dates'} = 1;
3985: }
1.11 raeburn 3986: }
3987: if ($context eq 'domain') {
3988: $options .= '
3989: <option value="delete">'.$lt{'delete'}.'</option>';
3990: }
3991: if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
1.26 raeburn 3992: if (($statusmode ne 'Expired') && ($env{'request.course.sec'} eq '')) {
1.11 raeburn 3993: $options .= '
3994: <option value="chgsec">'.$lt{'chgsec'}.'</option>';
3995: $choices{'sections'} = 1;
3996: }
3997: }
3998: if ($options) {
1.56 raeburn 3999: $output = '<select name="bulkaction">'."\n".
1.11 raeburn 4000: '<option value="" selected="selected">'.
4001: &mt('Please select').'</option>'."\n".$options."\n".'</select>';
4002: if ($choices{'dates'}) {
4003: $output .=
4004: '<input type="hidden" name="startdate_month" value="" />'."\n".
4005: '<input type="hidden" name="startdate_day" value="" />'."\n".
4006: '<input type="hidden" name="startdate_year" value="" />'."\n".
4007: '<input type="hidden" name="startdate_hour" value="" />'."\n".
4008: '<input type="hidden" name="startdate_minute" value="" />'."\n".
4009: '<input type="hidden" name="startdate_second" value="" />'."\n".
4010: '<input type="hidden" name="enddate_month" value="" />'."\n".
4011: '<input type="hidden" name="enddate_day" value="" />'."\n".
4012: '<input type="hidden" name="enddate_year" value="" />'."\n".
4013: '<input type="hidden" name="enddate_hour" value="" />'."\n".
4014: '<input type="hidden" name="enddate_minute" value="" />'."\n".
1.56 raeburn 4015: '<input type="hidden" name="enddate_second" value="" />'."\n".
4016: '<input type="hidden" name="no_end_date" value="" />'."\n";
1.11 raeburn 4017: if ($context eq 'course') {
4018: $output .= '<input type="hidden" name="makedatesdefault" value="" />'."\n";
4019: }
4020: }
4021: if ($choices{'sections'}) {
1.91 bisitz 4022: $output .= '<input type="hidden" name="retainsec" value="" />'."\n".
4023: '<input type="hidden" name="newsecs" value="" />'."\n";
1.11 raeburn 4024: }
4025: }
4026: return $output;
4027: }
4028:
4029: sub date_section_javascript {
4030: my ($context,$setting) = @_;
1.49 raeburn 4031: my $title = 'Date_And_Section_Selector';
1.41 raeburn 4032: my %nopopup = &Apache::lonlocal::texthash (
4033: revoke => "Check the boxes for any users for whom roles are to be revoked, and click 'Proceed'",
4034: delete => "Check the boxes for any users for whom roles are to be deleted, and click 'Proceed'",
4035: none => "Choose an action to take for selected users",
4036: );
1.96 bisitz 4037: my $output = <<"ENDONE";
4038: <script type="text/javascript">
4039: // <![CDATA[
1.41 raeburn 4040: function opendatebrowser(callingform,formname,calledby) {
1.11 raeburn 4041: var bulkaction = callingform.bulkaction.options[callingform.bulkaction.selectedIndex].value;
4042: var url = '/adm/createuser?';
4043: var type = '';
4044: var showrole = callingform.showrole.options[callingform.showrole.selectedIndex].value;
4045: ENDONE
4046: if ($context eq 'domain') {
4047: $output .= '
4048: type = callingform.roletype.options[callingform.roletype.selectedIndex].value;
4049: ';
4050: }
4051: my $width= '700';
4052: my $height = '400';
4053: $output .= <<"ENDTWO";
4054: url += 'action=dateselect&callingform=' + formname +
4055: '&roletype='+type+'&showrole='+showrole +'&bulkaction='+bulkaction;
4056: var title = '$title';
4057: var options = 'scrollbars=1,resizable=1,menubar=0';
4058: options += ',width=$width,height=$height';
4059: stdeditbrowser = open(url,title,options,'1');
4060: stdeditbrowser.focus();
4061: }
1.96 bisitz 4062: // ]]>
1.11 raeburn 4063: </script>
4064: ENDTWO
4065: return $output;
4066: }
4067:
4068: sub date_section_selector {
1.150 raeburn 4069: my ($context,$permission,$crstype,$showcredits) = @_;
1.11 raeburn 4070: my $callingform = $env{'form.callingform'};
4071: my $formname = 'dateselect';
4072: my $groupslist = &get_groupslist();
1.150 raeburn 4073: my $sec_js =
4074: &setsections_javascript($formname,$groupslist,undef,undef,$crstype,
4075: $showcredits);
1.11 raeburn 4076: my $output = <<"END";
4077: <script type="text/javascript">
1.96 bisitz 4078: // <![CDATA[
1.11 raeburn 4079:
4080: $sec_js
4081:
4082: function saveselections(formname) {
4083:
4084: END
4085: if ($env{'form.bulkaction'} eq 'chgsec') {
4086: $output .= <<"END";
1.40 raeburn 4087: if (formname.retainsec.length > 1) {
4088: for (var i=0; i<formname.retainsec.length; i++) {
4089: if (formname.retainsec[i].checked == true) {
4090: opener.document.$callingform.retainsec.value = formname.retainsec[i].value;
4091: }
4092: }
4093: } else {
4094: opener.document.$callingform.retainsec.value = formname.retainsec.value;
4095: }
1.103 raeburn 4096: setSections(formname,'$crstype');
1.11 raeburn 4097: if (seccheck == 'ok') {
4098: opener.document.$callingform.newsecs.value = formname.sections.value;
1.205 raeburn 4099: } else {
4100: return;
1.11 raeburn 4101: }
4102: END
4103: } else {
4104: if ($context eq 'course') {
4105: if (($env{'form.bulkaction'} eq 'reenable') ||
4106: ($env{'form.bulkaction'} eq 'activate') ||
4107: ($env{'form.bulkaction'} eq 'chgdates')) {
1.26 raeburn 4108: if ($env{'request.course.sec'} eq '') {
4109: $output .= <<"END";
1.11 raeburn 4110:
4111: if (formname.makedatesdefault.checked == true) {
4112: opener.document.$callingform.makedatesdefault.value = 1;
4113: }
4114: else {
4115: opener.document.$callingform.makedatesdefault.value = 0;
4116: }
4117:
4118: END
1.26 raeburn 4119: }
1.11 raeburn 4120: }
4121: }
4122: $output .= <<"END";
4123: opener.document.$callingform.startdate_month.value = formname.startdate_month.options[formname.startdate_month.selectedIndex].value;
4124: opener.document.$callingform.startdate_day.value = formname.startdate_day.value;
4125: opener.document.$callingform.startdate_year.value = formname.startdate_year.value;
4126: opener.document.$callingform.startdate_hour.value = formname.startdate_hour.options[formname.startdate_hour.selectedIndex].value;
4127: opener.document.$callingform.startdate_minute.value = formname.startdate_minute.value;
4128: opener.document.$callingform.startdate_second.value = formname.startdate_second.value;
4129: opener.document.$callingform.enddate_month.value = formname.enddate_month.options[formname.enddate_month.selectedIndex].value;
4130: opener.document.$callingform.enddate_day.value = formname.enddate_day.value;
4131: opener.document.$callingform.enddate_year.value = formname.enddate_year.value;
4132: opener.document.$callingform.enddate_hour.value = formname.enddate_hour.options[formname.enddate_hour.selectedIndex].value;
4133: opener.document.$callingform.enddate_minute.value = formname.enddate_minute.value;
4134: opener.document.$callingform.enddate_second.value = formname.enddate_second.value;
1.56 raeburn 4135: if (formname.no_end_date.checked) {
4136: opener.document.$callingform.no_end_date.value = '1';
4137: } else {
4138: opener.document.$callingform.no_end_date.value = '0';
4139: }
1.11 raeburn 4140: END
4141: }
1.56 raeburn 4142: my $verify_action_js = &bulkaction_javascript($callingform,'popup');
4143: $output .= <<"ENDJS";
4144: verify_action('actionlist');
1.11 raeburn 4145: }
1.56 raeburn 4146:
4147: $verify_action_js
4148:
1.96 bisitz 4149: // ]]>
1.11 raeburn 4150: </script>
1.56 raeburn 4151: ENDJS
1.11 raeburn 4152: my %lt = &Apache::lonlocal::texthash (
4153: chac => 'Access dates to apply for selected users',
4154: chse => 'Changes in section affiliation to apply to selected users',
1.118 raeburn 4155: fors => 'For student roles, changing the section will result in a section switch as students may only be in one section of a course at a time.',
4156: forn => 'For a course role that is not "student", users may have roles in more than one section at a time.',
4157: reta => "Retain each user's current section affiliations?",
1.103 raeburn 4158: dnap => '(Does not apply to student roles).',
1.11 raeburn 4159: );
4160: my ($date_items,$headertext);
4161: if ($env{'form.bulkaction'} eq 'chgsec') {
4162: $headertext = $lt{'chse'};
4163: } else {
4164: $headertext = $lt{'chac'};
4165: my $starttime;
4166: if (($env{'form.bulkaction'} eq 'activate') ||
4167: ($env{'form.bulkaction'} eq 'reenable')) {
4168: $starttime = time;
4169: }
4170: $date_items = &date_setting_table($starttime,undef,$context,
1.21 raeburn 4171: $env{'form.bulkaction'},$formname,
1.101 raeburn 4172: $permission,$crstype);
1.11 raeburn 4173: }
4174: $output .= '<h3>'.$headertext.'</h3>'.
1.118 raeburn 4175: '<form name="'.$formname.'" method="post" action="">'."\n".
1.11 raeburn 4176: $date_items;
4177: if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
1.17 raeburn 4178: my ($cnum,$cdom) = &get_course_identity();
1.103 raeburn 4179: if ($crstype eq 'Community') {
1.118 raeburn 4180: $lt{'fors'} = &mt('For member roles, changing the section will result in a section switch, as members may only be in one section of a community at a time.');
4181: $lt{'forn'} = &mt('For a community role that is not "member", users may have roles in more than one section at a time.');
1.103 raeburn 4182: $lt{'dnap'} = &mt('(Does not apply to member roles).');
4183: }
1.11 raeburn 4184: my $info;
4185: if ($env{'form.showrole'} eq 'st') {
4186: $output .= '<p>'.$lt{'fors'}.'</p>';
1.26 raeburn 4187: } elsif ($env{'form.showrole'} eq 'Any') {
1.11 raeburn 4188: $output .= '<p>'.$lt{'fors'}.'</p>'.
4189: '<p>'.$lt{'forn'}.' ';
4190: $info = $lt{'reta'};
4191: } else {
4192: $output .= '<p>'.$lt{'forn'}.' ';
4193: $info = $lt{'reta'};
4194: }
4195: if ($info) {
4196: $info .= '<span class="LC_nobreak">'.
4197: '<label><input type="radio" name="retainsec" value="1" '.
4198: 'checked="checked" />'.&mt('Yes').'</label> '.
4199: '<label><input type="radio" name="retainsec" value="0" />'.
4200: &mt('No').'</label></span>';
4201: if ($env{'form.showrole'} eq 'Any') {
4202: $info .= '<br />'.$lt{'dnap'};
4203: }
4204: $info .= '</p>';
4205: } else {
4206: $info = '<input type="hidden" name="retainsec" value="0" />';
4207: }
1.21 raeburn 4208: my $rowtitle = &mt('New section to assign');
1.150 raeburn 4209: my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,
4210: $permission,$context,'chgsec',$crstype);
1.11 raeburn 4211: $output .= $info.$secbox;
4212: }
4213: $output .= '<p>'.
1.81 schafran 4214: '<input type="button" name="dateselection" value="'.&mt('Save').'" onclick="javascript:saveselections(this.form)" /></p>'."\n".
1.11 raeburn 4215: '</form>';
4216: return $output;
4217: }
4218:
1.17 raeburn 4219: sub section_picker {
1.150 raeburn 4220: my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode,$crstype,
4221: $showcredits,$credits) = @_;
1.17 raeburn 4222: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
4223: my $sections_select .= &course_sections(\%sections_count,$role);
1.118 raeburn 4224: my $secbox = '<div>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
1.17 raeburn 4225: if ($mode eq 'upload') {
4226: my ($options,$cb_script,$coursepick) =
1.150 raeburn 4227: &default_role_selector($context,1,$crstype,$showcredits);
1.59 bisitz 4228: $secbox .= &Apache::lonhtmlcommon::row_title(&mt('role'),'LC_oddrow_value').
1.17 raeburn 4229: $options. &Apache::lonhtmlcommon::row_closure(1)."\n";
4230: }
4231: $secbox .= &Apache::lonhtmlcommon::row_title($rowtitle,'LC_oddrow_value')."\n";
4232: if ($env{'request.course.sec'} eq '') {
4233: $secbox .= '<table class="LC_createuser"><tr class="LC_section_row">'."\n".
4234: '<td align="center">'.&mt('Existing sections')."\n".
4235: '<br />'.$sections_select.'</td><td align="center">'.
4236: &mt('New section').'<br />'."\n".
1.118 raeburn 4237: '<input type="text" name="newsec" size="15" value="" />'."\n".
1.17 raeburn 4238: '<input type="hidden" name="sections" value="" />'."\n".
4239: '</td></tr></table>'."\n";
4240: } else {
1.149 raeburn 4241: $secbox .= '<input type="hidden" name="sections" value="'.
1.17 raeburn 4242: $env{'request.course.sec'}.'" />'.
4243: $env{'request.course.sec'};
4244: }
1.150 raeburn 4245: $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n";
4246: unless ($mode eq 'chgsec') {
4247: if ($showcredits) {
4248: $secbox .=
4249: &Apache::lonhtmlcommon::row_title(&mt('credits (students)'),
4250: 'LC_evenrow_value')."\n".
4251: '<input type="text" name="credits" size="3" value="'.$credits.'" />'."\n".
4252: &Apache::lonhtmlcommon::row_closure(1)."\n";
4253: }
4254: }
4255: $secbox .= &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.17 raeburn 4256: return $secbox;
4257: }
4258:
1.2 raeburn 4259: sub results_header_row {
1.102 raeburn 4260: my ($rolefilter,$statusmode,$context,$permission,$mode,$crstype) = @_;
1.5 raeburn 4261: my ($description,$showfilter);
4262: if ($rolefilter ne 'Any') {
4263: $showfilter = $rolefilter;
4264: }
1.2 raeburn 4265: if ($context eq 'course') {
1.24 raeburn 4266: if ($mode eq 'csv' || $mode eq 'excel') {
1.102 raeburn 4267: if ($crstype eq 'Community') {
4268: $description = &mt('Community - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
4269: } else {
4270: $description = &mt('Course - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
4271: }
1.24 raeburn 4272: }
1.2 raeburn 4273: if ($statusmode eq 'Expired') {
1.102 raeburn 4274: if ($crstype eq 'Community') {
4275: $description .= &mt('Users in community with expired [_1] roles',$showfilter);
4276: } else {
4277: $description .= &mt('Users in course with expired [_1] roles',$showfilter);
4278: }
1.11 raeburn 4279: } elsif ($statusmode eq 'Future') {
1.102 raeburn 4280: if ($crstype eq 'Community') {
4281: $description .= &mt('Users in community with future [_1] roles',$showfilter);
4282: } else {
4283: $description .= &mt('Users in course with future [_1] roles',$showfilter);
4284: }
1.2 raeburn 4285: } elsif ($statusmode eq 'Active') {
1.102 raeburn 4286: if ($crstype eq 'Community') {
4287: $description .= &mt('Users in community with active [_1] roles',$showfilter);
4288: } else {
4289: $description .= &mt('Users in course with active [_1] roles',$showfilter);
4290: }
1.2 raeburn 4291: } else {
4292: if ($rolefilter eq 'Any') {
1.102 raeburn 4293: if ($crstype eq 'Community') {
4294: $description .= &mt('All users in community');
4295: } else {
4296: $description .= &mt('All users in course');
4297: }
1.2 raeburn 4298: } else {
1.102 raeburn 4299: if ($crstype eq 'Community') {
4300: $description .= &mt('All users in community with [_1] roles',$rolefilter);
4301: } else {
4302: $description .= &mt('All users in course with [_1] roles',$rolefilter);
4303: }
1.2 raeburn 4304: }
4305: }
1.33 raeburn 4306: my $constraint;
1.26 raeburn 4307: my $viewablesec = &viewable_section($permission);
4308: if ($viewablesec ne '') {
1.15 raeburn 4309: if ($env{'form.showrole'} eq 'st') {
1.33 raeburn 4310: $constraint = &mt('only users in section "[_1]"',$viewablesec);
1.103 raeburn 4311: } elsif (($env{'form.showrole'} ne 'cc') && ($env{'form.showrole'} ne 'co')) {
1.33 raeburn 4312: $constraint = &mt('only users affiliated with no section or section "[_1]"',$viewablesec);
4313: }
4314: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
4315: if ($env{'form.grpfilter'} eq 'none') {
4316: $constraint .= &mt(' and not in any group');
4317: } else {
4318: $constraint .= &mt(' and members of group: "[_1]"',$env{'form.grpfilter'});
4319: }
4320: }
4321: } else {
4322: if (($env{'form.secfilter'} ne 'all') && ($env{'form.secfilter'} ne '')) {
4323: if ($env{'form.secfilter'} eq 'none') {
4324: $constraint = &mt('only users affiliated with no section');
4325: } else {
4326: $constraint = &mt('only users affiliated with section "[_1]"',$env{'form.secfilter'});
4327: }
4328: }
4329: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
4330: if ($env{'form.grpfilter'} eq 'none') {
4331: if ($constraint eq '') {
4332: $constraint = &mt('only users not in any group');
4333: } else {
4334: $constraint .= &mt(' and also not in any group');
4335: }
4336: } else {
4337: if ($constraint eq '') {
4338: $constraint = &mt('only members of group: "[_1]"',$env{'form.grpfilter'});
4339: } else {
4340: $constraint .= &mt(' and also members of group: "[_1]"'.$env{'form.grpfilter'});
4341: }
4342: }
1.15 raeburn 4343: }
4344: }
1.33 raeburn 4345: if ($constraint ne '') {
4346: $description .= ' ('.$constraint.')';
4347: }
1.13 raeburn 4348: } elsif ($context eq 'author') {
1.14 raeburn 4349: $description =
1.73 bisitz 4350: &mt('Author space for [_1]'
4351: ,'<span class="LC_cusr_emph">'
4352: .&Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'})
4353: .'</span>')
4354: .': ';
1.2 raeburn 4355: if ($statusmode eq 'Expired') {
1.5 raeburn 4356: $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
1.2 raeburn 4357: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4358: $description .= &mt('Co-authors with future [_1] roles',$showfilter);
1.2 raeburn 4359: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4360: $description .= &mt('Co-authors with active [_1] roles',$showfilter);
1.2 raeburn 4361: } else {
4362: if ($rolefilter eq 'Any') {
1.5 raeburn 4363: $description .= &mt('All co-authors');
1.2 raeburn 4364: } else {
4365: $description .= &mt('All co-authors with [_1] roles',$rolefilter);
4366: }
4367: }
4368: } elsif ($context eq 'domain') {
4369: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.73 bisitz 4370: $description = &mt('Domain - [_1]:',$domdesc).' ';
1.2 raeburn 4371: if ($env{'form.roletype'} eq 'domain') {
4372: if ($statusmode eq 'Expired') {
1.5 raeburn 4373: $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
1.2 raeburn 4374: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4375: $description .= &mt('Users in domain with future [_1] roles',$showfilter);
1.2 raeburn 4376: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4377: $description .= &mt('Users in domain with active [_1] roles',$showfilter);
1.2 raeburn 4378: } else {
4379: if ($rolefilter eq 'Any') {
1.5 raeburn 4380: $description .= &mt('All users in domain');
1.2 raeburn 4381: } else {
4382: $description .= &mt('All users in domain with [_1] roles',$rolefilter);
4383: }
4384: }
1.13 raeburn 4385: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 4386: if ($statusmode eq 'Expired') {
1.5 raeburn 4387: $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
1.2 raeburn 4388: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4389: $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
1.2 raeburn 4390: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4391: $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
1.2 raeburn 4392: } else {
4393: if ($rolefilter eq 'Any') {
1.5 raeburn 4394: $description .= &mt('All users with co-author roles in domain',$showfilter);
1.2 raeburn 4395: } else {
1.116 bisitz 4396: $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
1.2 raeburn 4397: }
4398: }
1.102 raeburn 4399: } elsif (($env{'form.roletype'} eq 'course') ||
4400: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 4401: my $coursefilter = $env{'form.coursepick'};
1.102 raeburn 4402: if ($env{'form.roletype'} eq 'course') {
4403: if ($coursefilter eq 'category') {
4404: my $instcode = &instcode_from_coursefilter();
4405: if ($instcode eq '.') {
4406: $description .= &mt('All courses in domain').' - ';
4407: } else {
4408: $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
4409: }
4410: } elsif ($coursefilter eq 'selected') {
4411: $description .= &mt('Selected courses in domain').' - ';
4412: } elsif ($coursefilter eq 'all') {
1.2 raeburn 4413: $description .= &mt('All courses in domain').' - ';
4414: }
1.102 raeburn 4415: } elsif ($env{'form.roletype'} eq 'community') {
4416: if ($coursefilter eq 'selected') {
4417: $description .= &mt('Selected communities in domain').' - ';
4418: } elsif ($coursefilter eq 'all') {
4419: $description .= &mt('All communities in domain').' - ';
4420: }
1.2 raeburn 4421: }
4422: if ($statusmode eq 'Expired') {
1.5 raeburn 4423: $description .= &mt('users with expired [_1] roles',$showfilter);
1.2 raeburn 4424: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4425: $description .= &mt('users with future [_1] roles',$showfilter);
1.2 raeburn 4426: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4427: $description .= &mt('users with active [_1] roles',$showfilter);
1.2 raeburn 4428: } else {
4429: if ($rolefilter eq 'Any') {
4430: $description .= &mt('all users');
4431: } else {
4432: $description .= &mt('users with [_1] roles',$rolefilter);
4433: }
4434: }
4435: }
4436: }
4437: return $description;
4438: }
1.22 raeburn 4439:
4440: sub viewable_section {
4441: my ($permission) = @_;
4442: my $viewablesec;
4443: if (ref($permission) eq 'HASH') {
4444: if (exists($permission->{'view_section'})) {
4445: $viewablesec = $permission->{'view_section'};
4446: } elsif (exists($permission->{'cusr_section'})) {
4447: $viewablesec = $permission->{'cusr_section'};
4448: }
4449: }
4450: return $viewablesec;
4451: }
4452:
1.2 raeburn 4453:
1.1 raeburn 4454: #################################################
4455: #################################################
4456: sub show_drop_list {
1.101 raeburn 4457: my ($r,$classlist,$nosort,$permission,$crstype) = @_;
1.29 raeburn 4458: my $cid = $env{'request.course.id'};
1.17 raeburn 4459: my ($cnum,$cdom) = &get_course_identity($cid);
1.1 raeburn 4460: if (! exists($env{'form.sortby'})) {
4461: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
4462: ['sortby']);
4463: }
4464: my $sortby = $env{'form.sortby'};
4465: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
4466: $sortby = 'username';
4467: }
4468: my $action = "drop";
1.17 raeburn 4469: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
1.1 raeburn 4470: $r->print(<<END);
4471: <input type="hidden" name="sortby" value="$sortby" />
4472: <input type="hidden" name="action" value="$action" />
4473: <input type="hidden" name="state" value="done" />
1.17 raeburn 4474: <script type="text/javascript" language="Javascript">
1.96 bisitz 4475: // <![CDATA[
1.17 raeburn 4476: $check_uncheck_js
1.96 bisitz 4477: // ]]>
1.1 raeburn 4478: </script>
1.86 bisitz 4479: <input type="hidden" name="phase" value="four" />
1.1 raeburn 4480: END
1.30 raeburn 4481: my ($indexhash,$keylist) = &make_keylist_array();
4482: my $studentcount = 0;
4483: if (ref($classlist) eq 'HASH') {
4484: foreach my $student (keys(%{$classlist})) {
4485: my $sdata = $classlist->{$student};
4486: my $status = $sdata->[$indexhash->{'status'}];
4487: my $section = $sdata->[$indexhash->{'section'}];
4488: if ($status ne 'Active') {
4489: delete($classlist->{$student});
4490: next;
4491: }
4492: if ($env{'request.course.sec'} ne '') {
4493: if ($section ne $env{'request.course.sec'}) {
4494: delete($classlist->{$student});
4495: next;
4496: }
4497: }
4498: $studentcount ++;
4499: }
4500: }
4501: if (!$studentcount) {
1.143 bisitz 4502: my $msg = '';
1.101 raeburn 4503: if ($crstype eq 'Community') {
1.143 bisitz 4504: $msg = &mt('There are no members to drop.');
1.101 raeburn 4505: } else {
1.143 bisitz 4506: $msg = &mt('There are no students to drop.');
1.101 raeburn 4507: }
1.143 bisitz 4508: $r->print('<p class="LC_info">'.$msg.'</p>');
1.30 raeburn 4509: return;
4510: }
4511: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
4512: $classlist,$keylist,$cdom,$cnum);
4513: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
4514: 'dom' => "domain",
1.162 bisitz 4515: 'id' => "ID",
1.30 raeburn 4516: 'sn' => "student name",
1.101 raeburn 4517: 'mn' => "member name",
1.30 raeburn 4518: 'sec' => "section",
4519: 'start' => "start date",
4520: 'end' => "end date",
4521: 'groups' => "active groups",
4522: );
1.101 raeburn 4523: my $nametitle = $lt{'sn'};
4524: if ($crstype eq 'Community') {
4525: $nametitle = $lt{'mn'};
4526: }
1.1 raeburn 4527: if ($nosort) {
1.17 raeburn 4528: $r->print(&Apache::loncommon::start_data_table().
4529: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 4530: $r->print(<<END);
4531: <th> </th>
4532: <th>$lt{'usrn'}</th>
4533: <th>$lt{'dom'}</th>
1.162 bisitz 4534: <th>$lt{'id'}</th>
1.101 raeburn 4535: <th>$nametitle</th>
1.1 raeburn 4536: <th>$lt{'sec'}</th>
4537: <th>$lt{'start'}</th>
4538: <th>$lt{'end'}</th>
4539: <th>$lt{'groups'}</th>
4540: END
1.17 raeburn 4541: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 4542: } else {
1.17 raeburn 4543: $r->print(&Apache::loncommon::start_data_table().
4544: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 4545: $r->print(<<END);
1.17 raeburn 4546: <th> </th>
1.1 raeburn 4547: <th>
1.162 bisitz 4548: <a href="/adm/createuser?action=$action&sortby=username">$lt{'usrn'}</a>
1.1 raeburn 4549: </th><th>
1.162 bisitz 4550: <a href="/adm/createuser?action=$action&sortby=domain">$lt{'dom'}</a>
1.1 raeburn 4551: </th><th>
1.162 bisitz 4552: <a href="/adm/createuser?action=$action&sortby=id">$lt{'id'}</a>
1.1 raeburn 4553: </th><th>
1.162 bisitz 4554: <a href="/adm/createuser?action=$action&sortby=fullname">$nametitle</a>
1.1 raeburn 4555: </th><th>
1.162 bisitz 4556: <a href="/adm/createuser?action=$action&sortby=section">$lt{'sec'}</a>
1.1 raeburn 4557: </th><th>
1.162 bisitz 4558: <a href="/adm/createuser?action=$action&sortby=start">$lt{'start'}</a>
1.1 raeburn 4559: </th><th>
1.162 bisitz 4560: <a href="/adm/createuser?action=$action&sortby=end">$lt{'end'}</a>
1.1 raeburn 4561: </th><th>
1.162 bisitz 4562: <a href="/adm/createuser?action=$action&sortby=groups">$lt{'groups'}</a>
1.1 raeburn 4563: </th>
4564: END
1.17 raeburn 4565: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 4566: }
4567: #
4568: # Sort the students
1.30 raeburn 4569: my $index = $indexhash->{$sortby};
4570: my $second = $indexhash->{'username'};
4571: my $third = $indexhash->{'domain'};
1.1 raeburn 4572: my @Sorted_Students = sort {
4573: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
4574: ||
4575: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
4576: ||
4577: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
1.30 raeburn 4578: } (keys(%{$classlist}));
1.1 raeburn 4579: foreach my $student (@Sorted_Students) {
4580: my $error;
4581: my $sdata = $classlist->{$student};
1.30 raeburn 4582: my $username = $sdata->[$indexhash->{'username'}];
4583: my $domain = $sdata->[$indexhash->{'domain'}];
4584: my $section = $sdata->[$indexhash->{'section'}];
4585: my $name = $sdata->[$indexhash->{'fullname'}];
4586: my $id = $sdata->[$indexhash->{'id'}];
4587: my $start = $sdata->[$indexhash->{'start'}];
4588: my $end = $sdata->[$indexhash->{'end'}];
1.1 raeburn 4589: my $groups = $classgroups->{$student};
4590: my $active_groups;
4591: if (ref($groups->{active}) eq 'HASH') {
4592: $active_groups = join(', ',keys(%{$groups->{'active'}}));
4593: }
4594: if (! defined($start) || $start == 0) {
4595: $start = &mt('none');
4596: } else {
4597: $start = &Apache::lonlocal::locallocaltime($start);
4598: }
4599: if (! defined($end) || $end == 0) {
4600: $end = &mt('none');
4601: } else {
4602: $end = &Apache::lonlocal::locallocaltime($end);
4603: }
1.17 raeburn 4604: my $studentkey = $student.':'.$section;
1.30 raeburn 4605: my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$indexhash->{'start'}].'" />';
1.1 raeburn 4606: #
4607: $r->print(&Apache::loncommon::start_data_table_row());
4608: $r->print(<<"END");
1.86 bisitz 4609: <td><input type="checkbox" name="droplist" value="$studentkey" /></td>
1.1 raeburn 4610: <td>$username</td>
4611: <td>$domain</td>
4612: <td>$id</td>
4613: <td>$name</td>
4614: <td>$section</td>
1.29 raeburn 4615: <td>$start $startitem</td>
1.1 raeburn 4616: <td>$end</td>
4617: <td>$active_groups</td>
4618: END
4619: $r->print(&Apache::loncommon::end_data_table_row());
4620: }
4621: $r->print(&Apache::loncommon::end_data_table().'<br />');
4622: %lt=&Apache::lonlocal::texthash(
1.29 raeburn 4623: 'dp' => "Drop Students",
1.101 raeburn 4624: 'dm' => "Drop Members",
1.1 raeburn 4625: 'ca' => "check all",
4626: 'ua' => "uncheck all",
4627: );
1.101 raeburn 4628: my $btn = $lt{'dp'};
4629: if ($crstype eq 'Community') {
4630: $btn = $lt{'dm'};
4631: }
1.1 raeburn 4632: $r->print(<<"END");
1.89 bisitz 4633: <p>
1.86 bisitz 4634: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)" />
4635: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)" />
1.89 bisitz 4636: </p>
4637: <p>
1.101 raeburn 4638: <input type="submit" value="$btn" />
1.89 bisitz 4639: </p>
1.1 raeburn 4640: END
4641: return;
4642: }
4643:
4644: #
4645: # Print out the initial form to get the file containing a list of users
4646: #
4647: sub print_first_users_upload_form {
4648: my ($r,$context) = @_;
4649: my $str;
1.86 bisitz 4650: $str = '<input type="hidden" name="phase" value="two" />';
1.1 raeburn 4651: $str .= '<input type="hidden" name="action" value="upload" />';
1.101 raeburn 4652: $str .= '<input type="hidden" name="state" value="got_file" />';
1.95 bisitz 4653:
1.147 bisitz 4654: $str .= &Apache::grades::checkforfile_js();
4655:
1.85 bisitz 4656: $str .= '<h2>'.&mt('Upload a file containing information about users').'</h2>'."\n";
1.95 bisitz 4657:
4658: # Excel and CSV Help
1.147 bisitz 4659: $str .= '<div class="LC_columnSection">'
1.95 bisitz 4660: .&Apache::loncommon::help_open_topic("Course_Create_Class_List",
4661: &mt("How do I create a users list from a spreadsheet"))
1.147 bisitz 4662: .' '.&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1.95 bisitz 4663: &mt("How do I create a CSV file from a spreadsheet"))
1.147 bisitz 4664: ."</div>\n";
1.95 bisitz 4665: $str .= &Apache::lonhtmlcommon::start_pick_box()
1.103 raeburn 4666: .&Apache::lonhtmlcommon::row_title(&mt('File'));
4667: if (&Apache::lonlocal::current_language() ne 'en') {
4668: if ($context eq 'course') {
4669: $str .= '<p class="LC_info">'."\n"
4670: .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n"
4671: .'</p>'."\n";
4672: }
4673: }
4674: $str .= &Apache::loncommon::upfile_select_html()
1.95 bisitz 4675: .&Apache::lonhtmlcommon::row_closure()
4676: .&Apache::lonhtmlcommon::row_title(
4677: '<label for="noFirstLine">'
4678: .&mt('Ignore First Line')
4679: .'</label>')
4680: .'<input type="checkbox" name="noFirstLine" id="noFirstLine" />'
4681: .&Apache::lonhtmlcommon::row_closure(1)
4682: .&Apache::lonhtmlcommon::end_pick_box();
4683:
4684: $str .= '<p>'
1.198 raeburn 4685: .'<input type="button" name="fileupload" value="'.&mt('Next').'"'
1.147 bisitz 4686: .' onclick="javascript:checkUpload(this.form);" />'
1.95 bisitz 4687: .'</p>';
4688:
1.1 raeburn 4689: $r->print($str);
4690: return;
4691: }
4692:
4693: # ================================================= Drop/Add from uploaded file
4694: sub upfile_drop_add {
1.150 raeburn 4695: my ($r,$context,$permission,$showcredits) = @_;
1.189 raeburn 4696: my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'});
4697: if ($datatoken ne '') {
4698: &Apache::loncommon::load_tmp_file($r,$datatoken);
4699: }
1.1 raeburn 4700: my @userdata=&Apache::loncommon::upfile_record_sep();
4701: if($env{'form.noFirstLine'}){shift(@userdata);}
4702: my @keyfields = split(/\,/,$env{'form.keyfields'});
4703: my %fields=();
4704: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
4705: if ($env{'form.upfile_associate'} eq 'reverse') {
4706: if ($env{'form.f'.$i} ne 'none') {
4707: $fields{$keyfields[$i]}=$env{'form.f'.$i};
4708: }
4709: } else {
4710: $fields{$env{'form.f'.$i}}=$keyfields[$i];
4711: }
4712: }
4713: #
4714: # Store the field choices away
1.150 raeburn 4715: my @storefields = qw/username names fname mname lname gen id
4716: sec ipwd email role domain inststatus/;
4717: if ($showcredits) {
4718: push (@storefields,'credits');
4719: }
4720: my %fieldstype;
4721: foreach my $field (@storefields) {
1.1 raeburn 4722: $env{'form.'.$field.'_choice'}=$fields{$field};
1.150 raeburn 4723: $fieldstype{$field.'_choice'} = 'scalar';
1.1 raeburn 4724: }
1.150 raeburn 4725: &Apache::loncommon::store_course_settings('enrollment_upload',\%fieldstype);
1.212 raeburn 4726: my ($cid,$crstype,$setting,$crsdom,$crsnum);
1.101 raeburn 4727: if ($context eq 'domain') {
4728: $setting = $env{'form.roleaction'};
4729: }
4730: if ($env{'request.course.id'} ne '') {
4731: $cid = $env{'request.course.id'};
4732: $crstype = &Apache::loncommon::course_type();
1.185 raeburn 4733: $crsdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.212 raeburn 4734: $crsnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.101 raeburn 4735: } elsif ($setting eq 'course') {
4736: if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
4737: $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
4738: $crstype = &Apache::loncommon::course_type($cid);
1.185 raeburn 4739: $crsdom = $env{'form.dcdomain'};
1.212 raeburn 4740: $crsnum = $env{'form.dccourse'};
1.101 raeburn 4741: }
4742: }
1.1 raeburn 4743: my ($startdate,$enddate) = &get_dates_from_form();
4744: if ($env{'form.makedatesdefault'}) {
1.101 raeburn 4745: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
1.1 raeburn 4746: }
4747: # Determine domain and desired host (home server)
1.57 raeburn 4748: my $defdom=$env{'request.role.domain'};
4749: my $domain;
4750: if ($env{'form.defaultdomain'} ne '') {
1.185 raeburn 4751: if (($context eq 'course') || ($setting eq 'course')) {
1.190 raeburn 4752: if ($env{'form.defaultdomain'} eq $crsdom) {
4753: $domain = $env{'form.defaultdomain'};
4754: } else {
1.185 raeburn 4755: if (&Apache::lonnet::will_trust('enroll',$crsdom,$env{'form.defaultdomain'})) {
4756: $domain = $env{'form.defaultdomain'};
4757: } else {
1.192 raeburn 4758: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4759: &mt('Enrollment of users not permitted for specified default domain: [_1].',
4760: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4761: return 'untrusted';
1.185 raeburn 4762: }
4763: }
4764: } elsif ($context eq 'author') {
1.190 raeburn 4765: if ($env{'form.defaultdomain'} eq $defdom) {
4766: $domain = $env{'form.defaultdomain'};
4767: } else {
1.185 raeburn 4768: if ((&Apache::lonnet::will_trust('othcoau',$defdom,$env{'form.defaultdomain'})) &&
1.186 raeburn 4769: (&Apache::lonnet::will_trust('coaurem',$env{'form.defaultdomain'},$defdom))) {
1.185 raeburn 4770: $domain = $env{'form.defaultdomain'};
4771: } else {
1.192 raeburn 4772: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4773: &mt('Addition of users not permitted for specified default domain: [_1].',
4774: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4775: return 'untrusted';
1.185 raeburn 4776: }
4777: }
4778: } elsif (($context eq 'domain') && ($setting eq 'domain')) {
1.190 raeburn 4779: if ($env{'form.defaultdomain'} eq $defdom) {
4780: $domain = $env{'form.defaultdomain'};
4781: } else {
1.185 raeburn 4782: if (&Apache::lonnet::will_trust('domroles',$defdom,$env{'form.defaultdomain'})) {
4783: $domain = $env{'form.defaultdomain'};
4784: } else {
1.192 raeburn 4785: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4786: &mt('Addition of users not permitted for specified default domain: [_1].',
4787: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4788: return 'untrusted';
1.185 raeburn 4789: }
4790: }
4791: }
1.57 raeburn 4792: } else {
4793: $domain = $defdom;
4794: }
1.1 raeburn 4795: my $desiredhost = $env{'form.lcserver'};
4796: if (lc($desiredhost) eq 'default') {
4797: $desiredhost = undef;
4798: } else {
1.57 raeburn 4799: my %home_servers = &Apache::lonnet::get_servers($defdom,'library');
1.1 raeburn 4800: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 4801: $r->print('<p class="LC_error">'.&mt('Error').': '.
4802: &mt('Invalid home server specified').'</p>');
4803: return 'invalidhome';
1.1 raeburn 4804: }
4805: }
4806: # Determine authentication mechanism
4807: my $changeauth;
4808: if ($context eq 'domain') {
4809: $changeauth = $env{'form.changeauth'};
4810: }
4811: my $amode = '';
4812: my $genpwd = '';
1.200 raeburn 4813: my @genpwdfail;
1.1 raeburn 4814: if ($env{'form.login'} eq 'krb') {
4815: $amode='krb';
4816: $amode.=$env{'form.krbver'};
4817: $genpwd=$env{'form.krbarg'};
4818: } elsif ($env{'form.login'} eq 'int') {
4819: $amode='internal';
4820: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
4821: $genpwd=$env{'form.intarg'};
1.200 raeburn 4822: @genpwdfail =
1.202 raeburn 4823: &Apache::loncommon::check_passwd_rules($domain,$genpwd);
1.1 raeburn 4824: }
4825: } elsif ($env{'form.login'} eq 'loc') {
4826: $amode='localauth';
4827: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
4828: $genpwd=$env{'form.locarg'};
4829: }
1.194 raeburn 4830: } elsif ($env{'form.login'} eq 'lti') {
4831: $amode='lti';
1.1 raeburn 4832: }
4833: if ($amode =~ /^krb/) {
4834: if (! defined($genpwd) || $genpwd eq '') {
1.193 raeburn 4835: $r->print('<span class="Error">'.
1.1 raeburn 4836: &mt('Unable to enroll users').' '.
4837: &mt('No Kerberos domain was specified.').'</span></p>');
4838: $amode = ''; # This causes the loop below to be skipped
4839: }
4840: }
1.150 raeburn 4841: my ($defaultsec,$defaultrole,$defaultcredits,$commoncredits);
1.1 raeburn 4842: if ($context eq 'domain') {
4843: if ($setting eq 'domain') {
4844: $defaultrole = $env{'form.defaultrole'};
4845: } elsif ($setting eq 'course') {
4846: $defaultrole = $env{'form.courserole'};
1.27 raeburn 4847: $defaultsec = $env{'form.sections'};
1.150 raeburn 4848: if ($showcredits) {
4849: $commoncredits = $env{'form.credits'};
4850: if ($crstype ne 'Community') {
4851: my %coursehash=&Apache::lonnet::coursedescription($cid);
4852: $defaultcredits = $coursehash{'internal.defaultcredits'};
4853: }
4854: }
1.149 raeburn 4855: }
1.13 raeburn 4856: } elsif ($context eq 'author') {
1.1 raeburn 4857: $defaultrole = $env{'form.defaultrole'};
1.27 raeburn 4858: } elsif ($context eq 'course') {
4859: $defaultrole = $env{'form.defaultrole'};
4860: $defaultsec = $env{'form.sections'};
1.150 raeburn 4861: if ($showcredits) {
4862: $commoncredits = $env{'form.credits'};
4863: $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
4864: }
1.1 raeburn 4865: }
1.27 raeburn 4866: # Check to see if user information can be changed
4867: my @userinfo = ('firstname','middlename','lastname','generation',
4868: 'permanentemail','id');
4869: my %canmodify;
4870: if (&Apache::lonnet::allowed('mau',$domain)) {
1.84 raeburn 4871: push(@userinfo,'inststatus');
1.27 raeburn 4872: foreach my $field (@userinfo) {
4873: $canmodify{$field} = 1;
4874: }
4875: }
4876: my (%userlist,%modifiable_fields,@poss_roles);
4877: my $secidx = &Apache::loncoursedata::CL_SECTION();
1.102 raeburn 4878: my @courseroles = &roles_by_context('course',1,$crstype);
1.27 raeburn 4879: if (!&Apache::lonnet::allowed('mau',$domain)) {
4880: if ($context eq 'course' || $context eq 'author') {
1.101 raeburn 4881: @poss_roles = &curr_role_permissions($context,'','',$crstype);
1.27 raeburn 4882: my @statuses = ('active','future');
4883: my ($indexhash,$keylist) = &make_keylist_array();
4884: my %info;
4885: foreach my $role (@poss_roles) {
4886: %{$modifiable_fields{$role}} = &can_modify_userinfo($context,$domain,
4887: \@userinfo,[$role]);
4888: }
4889: if ($context eq 'course') {
4890: my ($cnum,$cdom) = &get_course_identity();
4891: my $roster = &Apache::loncoursedata::get_classlist();
1.66 raeburn 4892: if (ref($roster) eq 'HASH') {
4893: %userlist = %{$roster};
4894: }
1.27 raeburn 4895: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
4896: \@statuses,\@poss_roles);
4897: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
4898: \%advrolehash,$permission);
4899: } elsif ($context eq 'author') {
4900: my %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
4901: \@statuses,\@poss_roles);
4902: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
4903: \%cstr_roles,$permission);
4904: }
4905: }
1.1 raeburn 4906: }
1.193 raeburn 4907: if ($datatoken eq '') {
4908: $r->print('<p class="LC_error">'.&mt('Error').': '.
4909: &mt('Invalid datatoken').'</p>');
4910: return 'missingdata';
4911: }
1.1 raeburn 4912: if ( $domain eq &LONCAPA::clean_domain($domain)
4913: && ($amode ne '')) {
4914: #######################################
4915: ## Add/Modify Users ##
4916: #######################################
4917: if ($context eq 'course') {
4918: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
1.13 raeburn 4919: } elsif ($context eq 'author') {
1.1 raeburn 4920: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
4921: } else {
4922: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
4923: }
1.87 bisitz 4924: $r->rflush;
1.212 raeburn 4925: my (%got_role_approvals,%got_instdoms,%process_by,%instdoms,
1.213 raeburn 4926: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
1.87 bisitz 4927:
1.1 raeburn 4928: my %counts = (
4929: user => 0,
4930: auth => 0,
4931: role => 0,
4932: );
4933: my $flushc=0;
4934: my %student=();
1.42 raeburn 4935: my (%curr_groups,@sections,@cleansec,$defaultwarn,$groupwarn);
1.1 raeburn 4936: my %userchg;
1.27 raeburn 4937: if ($context eq 'course' || $setting eq 'course') {
4938: if ($context eq 'course') {
4939: # Get information about course groups
4940: %curr_groups = &Apache::longroup::coursegroups();
4941: } elsif ($setting eq 'course') {
4942: if ($cid) {
4943: %curr_groups =
4944: &Apache::longroup::coursegroups($env{'form.dcdomain'},
4945: $env{'form.dccourse'});
4946: }
4947: }
4948: # determine section number
4949: if ($defaultsec =~ /,/) {
4950: push(@sections,split(/,/,$defaultsec));
4951: } else {
4952: push(@sections,$defaultsec);
4953: }
4954: # remove non alphanumeric values from section
4955: foreach my $item (@sections) {
4956: $item =~ s/\W//g;
4957: if ($item eq "none" || $item eq 'all') {
4958: $defaultwarn = &mt('Default section name [_1] could not be used as it is a reserved word.',$item);
4959: } elsif ($item ne '' && exists($curr_groups{$item})) {
4960: $groupwarn = &mt('Default section name "[_1]" is the name of a course group. Section names and group names must be distinct.',$item);
4961: } elsif ($item ne '') {
4962: push(@cleansec,$item);
4963: }
4964: }
4965: if ($defaultwarn) {
4966: $r->print($defaultwarn.'<br />');
4967: }
4968: if ($groupwarn) {
4969: $r->print($groupwarn.'<br />');
4970: }
1.1 raeburn 4971: }
1.124 raeburn 4972: my (%curr_rules,%got_rules,%alerts,%cancreate);
1.104 raeburn 4973: my %customroles = &my_custom_roles($crstype);
1.101 raeburn 4974: my @permitted_roles =
1.124 raeburn 4975: &roles_on_upload($context,$setting,$crstype,%customroles);
4976: my %longtypes = &Apache::lonlocal::texthash(
4977: official => 'Institutional',
4978: unofficial => 'Non-institutional',
4979: );
1.135 raeburn 4980: my $newuserdom = $env{'request.role.domain'};
4981: map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes);
1.1 raeburn 4982: # Get new users list
1.200 raeburn 4983: my (%existinguser,%userinfo,%disallow,%rulematch,%inst_results,%alerts,%checkuname,
4984: %showpasswdrules,$haspasswdmap);
1.171 raeburn 4985: my $counter = -1;
1.185 raeburn 4986: my (%willtrust,%trustchecked);
1.27 raeburn 4987: foreach my $line (@userdata) {
1.171 raeburn 4988: $counter ++;
1.42 raeburn 4989: my @secs;
1.27 raeburn 4990: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 4991: # Determine user name
1.128 raeburn 4992: $entries{$fields{'username'}} =~ s/^\s+|\s+$//g;
1.1 raeburn 4993: unless (($entries{$fields{'username'}} eq '') ||
4994: (!defined($entries{$fields{'username'}}))) {
4995: my ($fname, $mname, $lname,$gen) = ('','','','');
4996: if (defined($fields{'names'})) {
4997: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
4998: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
4999: } else {
5000: if (defined($fields{'fname'})) {
5001: $fname=$entries{$fields{'fname'}};
5002: }
5003: if (defined($fields{'mname'})) {
5004: $mname=$entries{$fields{'mname'}};
5005: }
5006: if (defined($fields{'lname'})) {
5007: $lname=$entries{$fields{'lname'}};
5008: }
5009: if (defined($fields{'gen'})) {
5010: $gen=$entries{$fields{'gen'}};
5011: }
5012: }
1.128 raeburn 5013:
1.1 raeburn 5014: if ($entries{$fields{'username'}}
5015: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
1.128 raeburn 5016: my $nowhitespace;
5017: if ($entries{$fields{'username'}} =~ /\s/) {
5018: $nowhitespace = ' - '.&mt('usernames may not contain spaces.');
5019: }
1.171 raeburn 5020: $disallow{$counter} =
1.157 bisitz 5021: &mt('Unacceptable username [_1] for user [_2] [_3] [_4] [_5]',
1.171 raeburn 5022: '"<b>'.$entries{$fields{'username'}}.'</b>"',
5023: $fname,$mname,$lname,$gen).$nowhitespace;
1.27 raeburn 5024: next;
1.1 raeburn 5025: } else {
1.129 raeburn 5026: $entries{$fields{'domain'}} =~ s/^\s+|\s+$//g;
1.71 droeschl 5027: if ($entries{$fields{'domain'}}
1.57 raeburn 5028: ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
1.171 raeburn 5029: $disallow{$counter} =
1.157 bisitz 5030: &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
1.171 raeburn 5031: '"<b>'.$entries{$fields{'domain'}}.'</b>"',
5032: $fname,$mname,$lname,$gen);
5033: next;
1.185 raeburn 5034: } elsif ($entries{$fields{'domain'}} ne $domain) {
5035: my $possdom = $entries{$fields{'domain'}};
5036: if ($context eq 'course' || $setting eq 'course') {
5037: unless ($trustchecked{$possdom}) {
5038: $willtrust{$possdom} = &Apache::lonnet::will_trust('enroll',$domain,$possdom);
5039: $trustchecked{$possdom} = 1;
5040: }
5041: } elsif ($context eq 'author') {
5042: unless ($trustchecked{$possdom}) {
5043: $willtrust{$possdom} = &Apache::lonnet::will_trust('othcoau',$domain,$possdom);
5044: }
5045: if ($willtrust{$possdom}) {
5046: $willtrust{$possdom} = &Apache::lonnet::will_trust('coaurem',$possdom,$domain);
5047: }
5048: }
5049: unless ($willtrust{$possdom}) {
5050: $disallow{$counter} =
5051: &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
5052: '"<b>'.$possdom.'</b>"',
5053: $fname,$mname,$lname,$gen);
5054: next;
5055: }
1.57 raeburn 5056: }
1.5 raeburn 5057: my $username = $entries{$fields{'username'}};
1.57 raeburn 5058: my $userdomain = $entries{$fields{'domain'}};
5059: if ($userdomain eq '') {
5060: $userdomain = $domain;
5061: }
1.27 raeburn 5062: if (defined($fields{'sec'})) {
5063: if (defined($entries{$fields{'sec'}})) {
1.42 raeburn 5064: $entries{$fields{'sec'}} =~ s/\W//g;
1.27 raeburn 5065: my $item = $entries{$fields{'sec'}};
5066: if ($item eq "none" || $item eq 'all') {
1.171 raeburn 5067: $disallow{$counter} =
5068: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a reserved word.',
5069: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item);
1.27 raeburn 5070: next;
5071: } elsif (exists($curr_groups{$item})) {
1.171 raeburn 5072: $disallow{$counter} =
5073: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a course group.',
5074: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item).' '.
5075: &mt('Section names and group names must be distinct.');
1.27 raeburn 5076: next;
5077: } else {
5078: push(@secs,$item);
5079: }
5080: }
5081: }
5082: if ($env{'request.course.sec'} ne '') {
5083: @secs = ($env{'request.course.sec'});
1.57 raeburn 5084: if (ref($userlist{$username.':'.$userdomain}) eq 'ARRAY') {
5085: my $currsec = $userlist{$username.':'.$userdomain}[$secidx];
1.27 raeburn 5086: if ($currsec ne $env{'request.course.sec'}) {
1.171 raeburn 5087: $disallow{$counter} =
5088: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]".',
5089: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$secs[0]);
1.27 raeburn 5090: if ($currsec eq '') {
1.171 raeburn 5091: $disallow{$counter} .=
5092: &mt('This user already has an active/future student role in the course, unaffiliated to any section.');
1.27 raeburn 5093:
5094: } else {
1.171 raeburn 5095: $disallow{$counter} .=
5096: &mt('This user already has an active/future role in section "[_1]" of the course.',$currsec);
1.27 raeburn 5097: }
1.171 raeburn 5098: $disallow{$counter} .=
5099: '<br />'.
5100: &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments in other sections.',
5101: $secs[0]);
1.27 raeburn 5102: next;
1.1 raeburn 5103: }
5104: }
1.27 raeburn 5105: } elsif ($context eq 'course' || $setting eq 'course') {
5106: if (@secs == 0) {
5107: @secs = @cleansec;
1.1 raeburn 5108: }
5109: }
5110: # determine id number
5111: my $id='';
5112: if (defined($fields{'id'})) {
5113: if (defined($entries{$fields{'id'}})) {
5114: $id=$entries{$fields{'id'}};
5115: }
5116: $id=~tr/A-Z/a-z/;
5117: }
5118: # determine email address
5119: my $email='';
5120: if (defined($fields{'email'})) {
1.129 raeburn 5121: $entries{$fields{'email'}} =~ s/^\s+|\s+$//g;
1.1 raeburn 5122: if (defined($entries{$fields{'email'}})) {
5123: $email=$entries{$fields{'email'}};
1.84 raeburn 5124: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
5125: }
5126: }
5127: # determine affiliation
5128: my $inststatus='';
5129: if (defined($fields{'inststatus'})) {
5130: if (defined($entries{$fields{'inststatus'}})) {
5131: $inststatus=$entries{$fields{'inststatus'}};
5132: }
1.1 raeburn 5133: }
5134: # determine user password
1.200 raeburn 5135: my $password;
5136: my $passwdfromfile;
1.1 raeburn 5137: if (defined($fields{'ipwd'})) {
5138: if ($entries{$fields{'ipwd'}}) {
5139: $password=$entries{$fields{'ipwd'}};
1.200 raeburn 5140: $passwdfromfile = 1;
5141: if ($env{'form.login'} eq 'int') {
5142: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
5143: if (($uhome eq 'no_host') || ($changeauth)) {
5144: my @brokepwdrules =
5145: &Apache::loncommon::check_passwd_rules($domain,$password);
5146: if (@brokepwdrules) {
5147: $disallow{$counter} = &mt('[_1]: Password included in file for this user did not meet requirements.',
5148: '<b>'.$username.'</b>');
5149: map { $showpasswdrules{$_} = 1; } @brokepwdrules;
5150: next;
5151: }
5152: }
5153: }
5154: }
5155: }
5156: unless ($passwdfromfile) {
5157: if ($env{'form.login'} eq 'int') {
5158: if (@genpwdfail) {
5159: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
5160: if (($uhome eq 'no_host') || ($changeauth)) {
5161: $disallow{$counter} = &mt('[_1]: No specific password in file for this user; default password did not meet requirements',
5162: '<b>'.$username.'</b>');
5163: unless ($haspasswdmap) {
5164: map { $showpasswdrules{$_} = 1; } @genpwdfail;
5165: $haspasswdmap = 1;
5166: }
5167: }
5168: next;
5169: }
1.1 raeburn 5170: }
1.200 raeburn 5171: $password = $genpwd;
1.1 raeburn 5172: }
5173: # determine user role
5174: my $role = '';
5175: if (defined($fields{'role'})) {
5176: if ($entries{$fields{'role'}}) {
1.42 raeburn 5177: $entries{$fields{'role'}} =~ s/(\s+$|^\s+)//g;
5178: if ($entries{$fields{'role'}} ne '') {
5179: if (grep(/^\Q$entries{$fields{'role'}}\E$/,@permitted_roles)) {
5180: $role = $entries{$fields{'role'}};
1.27 raeburn 5181: }
5182: }
5183: if ($role eq '') {
5184: my $rolestr = join(', ',@permitted_roles);
1.171 raeburn 5185: $disallow{$counter} =
5186: &mt('[_1]: You do not have permission to add the requested role [_2] for the user.'
5187: ,'<b>'.$entries{$fields{'username'}}.'</b>'
5188: ,$entries{$fields{'role'}})
5189: .'<br />'
5190: .&mt('Allowable role(s) is/are: [_1].',$rolestr);
1.1 raeburn 5191: next;
5192: }
5193: }
5194: }
5195: if ($role eq '') {
5196: $role = $defaultrole;
5197: }
5198: # Clean up whitespace
1.129 raeburn 5199: foreach (\$id,\$fname,\$mname,\$lname,\$gen,\$inststatus) {
1.1 raeburn 5200: $$_ =~ s/(\s+$|^\s+)//g;
5201: }
1.150 raeburn 5202: my $credits;
5203: if ($showcredits) {
5204: if (($role eq 'st') && ($crstype ne 'Community')) {
5205: $credits = $entries{$fields{'credits'}};
5206: if ($credits ne '') {
5207: $credits =~ s/[^\d\.]//g;
5208: }
5209: if ($credits eq '') {
5210: $credits = $commoncredits;
5211: }
5212: if ($credits eq $defaultcredits) {
5213: undef($credits);
5214: }
5215: }
5216: }
1.5 raeburn 5217: # check against rules
5218: my $checkid = 0;
5219: my $newuser = 0;
1.57 raeburn 5220: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
1.5 raeburn 5221: if ($uhome eq 'no_host') {
1.135 raeburn 5222: if ($userdomain ne $newuserdom) {
5223: if ($context eq 'course') {
1.171 raeburn 5224: $disallow{$counter} =
5225: &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
5226: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 5227: } elsif ($context eq 'author') {
1.171 raeburn 5228: $disallow{$counter} =
5229: &mt('[_1]: The domain specified ([_2]) is different to that of the author.',
5230: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 5231: } else {
1.171 raeburn 5232: $disallow{$counter} =
5233: &mt('[_1]: The domain specified ([_2]) is different to that of your current role.',
5234: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 5235: }
1.171 raeburn 5236: $disallow{$counter} .=
5237: &mt('The user does not already exist, and you may not create a new user in a different domain.');
1.124 raeburn 5238: next;
1.171 raeburn 5239: } else {
1.194 raeburn 5240: unless (($password ne '') || ($env{'form.login'} eq 'loc') || ($env{'form.login'} eq 'lti')) {
1.171 raeburn 5241: $disallow{$counter} =
5242: &mt('[_1]: This is a new user but no default password was provided, and the authentication type requires one.',
5243: '<b>'.$username.'</b>');
5244: next;
5245: }
1.124 raeburn 5246: }
1.5 raeburn 5247: $checkid = 1;
5248: $newuser = 1;
1.172 raeburn 5249: $checkuname{$username.':'.$newuserdom} = { 'newuser' => $newuser, 'id' => $id };
1.13 raeburn 5250: } else {
1.27 raeburn 5251: if ($context eq 'course' || $context eq 'author') {
1.57 raeburn 5252: if ($userdomain eq $domain ) {
5253: if ($role eq '') {
5254: my @checkroles;
5255: foreach my $role (@poss_roles) {
5256: my $endkey;
5257: if ($role ne 'st') {
5258: $endkey = ':'.$role;
5259: }
5260: if (exists($userlist{$username.':'.$userdomain.$endkey})) {
5261: if (!grep(/^\Q$role\E$/,@checkroles)) {
5262: push(@checkroles,$role);
5263: }
5264: }
1.27 raeburn 5265: }
1.57 raeburn 5266: if (@checkroles > 0) {
5267: %canmodify = &can_modify_userinfo($context,$domain,\@userinfo,\@checkroles);
1.27 raeburn 5268: }
1.57 raeburn 5269: } elsif (ref($modifiable_fields{$role}) eq 'HASH') {
5270: %canmodify = %{$modifiable_fields{$role}};
1.27 raeburn 5271: }
5272: }
1.57 raeburn 5273: my @newinfo = (\$fname,\$mname,\$lname,\$gen,\$email,\$id);
1.84 raeburn 5274: for (my $i=0; $i<@newinfo; $i++) {
1.57 raeburn 5275: if (${$newinfo[$i]} ne '') {
5276: if (!$canmodify{$userinfo[$i]}) {
5277: ${$newinfo[$i]} = '';
5278: }
1.27 raeburn 5279: }
5280: }
5281: }
1.171 raeburn 5282: if ($id) {
5283: $existinguser{$userdomain}{$username} = $id;
5284: }
1.5 raeburn 5285: }
1.171 raeburn 5286: $userinfo{$counter} = {
5287: username => $username,
5288: domain => $userdomain,
5289: fname => $fname,
5290: mname => $mname,
5291: lname => $lname,
5292: gen => $gen,
5293: email => $email,
5294: id => $id,
5295: password => $password,
5296: inststatus => $inststatus,
5297: role => $role,
5298: sections => \@secs,
5299: credits => $credits,
5300: newuser => $newuser,
5301: checkid => $checkid,
5302: };
5303: }
5304: }
5305: } # end of foreach (@userdata)
5306: if ($counter > -1) {
5307: my $total = $counter + 1;
5308: my %checkids;
1.172 raeburn 5309: if ((keys(%existinguser)) || (keys(%checkuname))) {
5310: $r->print(&mt('Please be patient -- checking for institutional data ...'));
5311: $r->rflush();
5312: if (keys(%existinguser)) {
5313: foreach my $dom (keys(%existinguser)) {
5314: if (ref($existinguser{$dom}) eq 'HASH') {
5315: my %idhash = &Apache::lonnet::idrget($dom,keys(%{$existinguser{$dom}}));
5316: foreach my $username (keys(%{$existinguser{$dom}})) {
5317: if ($idhash{$username} ne $existinguser{$dom}{$username}) {
5318: $checkids{$username.':'.$dom} = {
5319: 'id' => $existinguser{$dom}{$username},
5320: };
5321: }
5322: }
5323: if (keys(%checkids)) {
5324: &Apache::loncommon::user_rule_check(\%checkids,{ 'id' => 1 },
5325: \%alerts,\%rulematch,
5326: \%inst_results,\%curr_rules,
5327: \%got_rules);
1.171 raeburn 5328: }
5329: }
5330: }
5331: }
1.172 raeburn 5332: if (keys(%checkuname)) {
5333: &Apache::loncommon::user_rule_check(\%checkuname,{ 'username' => 1, 'id' => 1, },
5334: \%alerts,\%rulematch,\%inst_results,
5335: \%curr_rules,\%got_rules);
5336: }
5337: $r->print(' '.&mt('done').'<br /><br />');
5338: $r->rflush();
1.171 raeburn 5339: }
1.172 raeburn 5340: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,$total);
1.171 raeburn 5341: $r->print('<ul>');
5342: for (my $i=0; $i<=$counter; $i++) {
5343: if ($disallow{$i}) {
5344: $r->print('<li>'.$disallow{$i}.'</li>');
5345: } elsif (ref($userinfo{$i}) eq 'HASH') {
5346: my $password = $userinfo{$i}{'password'};
5347: my $newuser = $userinfo{$i}{'newuser'};
5348: my $checkid = $userinfo{$i}{'checkid'};
5349: my $id = $userinfo{$i}{'id'};
5350: my $role = $userinfo{$i}{'role'};
5351: my @secs;
5352: if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
5353: @secs = @{$userinfo{$i}{'sections'}};
5354: }
5355: my $fname = $userinfo{$i}{'fname'};
5356: my $mname = $userinfo{$i}{'mname'};
5357: my $lname = $userinfo{$i}{'lname'};
5358: my $gen = $userinfo{$i}{'gen'};
5359: my $email = $userinfo{$i}{'email'};
5360: my $inststatus = $userinfo{$i}{'inststatus'};
5361: my $credits = $userinfo{$i}{'credits'};
5362: my $username = $userinfo{$i}{'username'};
5363: my $userdomain = $userinfo{$i}{'domain'};
5364: my $user = $username.':'.$userdomain;
5365: if ($newuser) {
5366: if (ref($alerts{'username'}) eq 'HASH') {
5367: if (ref($alerts{'username'}{$userdomain}) eq 'HASH') {
5368: if ($alerts{'username'}{$userdomain}{$username}) {
5369: $r->print('<li>'.
5370: &mt('[_1]: matches the username format at your institution, but is not known to your directory service.','<b>'.$username.'</b>').'<br />'.
5371: &mt('Consequently, the user was not created.').'</li>');
5372: next;
5373: }
5374: }
5375: }
1.172 raeburn 5376: if (ref($inst_results{$user}) eq 'HASH') {
5377: if ($inst_results{$user}{'firstname'} ne '') {
5378: $fname = $inst_results{$user}{'firstname'};
5379: }
5380: if ($inst_results{$user}{'middlename'} ne '') {
5381: $mname = $inst_results{$user}{'middlename'};
5382: }
5383: if ($inst_results{$user}{'lasttname'} ne '') {
5384: $lname = $inst_results{$user}{'lastname'};
5385: }
5386: if ($inst_results{$user}{'permanentemail'} ne '') {
5387: $email = $inst_results{$user}{'permanentemail'};
5388: }
5389: if ($inst_results{$user}{'id'} ne '') {
5390: $id = $inst_results{$user}{'id'};
5391: $checkid = 0;
5392: }
5393: if (ref($inst_results{$user}{'inststatus'}) eq 'ARRAY') {
5394: $inststatus = join(':',@{$inst_results{$user}{'inststatus'}});
5395: }
5396: }
5397: if (($checkid) && ($id ne '')) {
5398: if (ref($alerts{'id'}) eq 'HASH') {
5399: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
5400: if ($alerts{'id'}{$userdomain}{$username}) {
5401: $r->print('<li>'.
5402: &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
5403: '<b>'.$username.'</b>').'<br />'.
5404: &mt('Consequently, the user was not created.').'</li>');
5405: next;
5406: }
5407: }
5408: }
5409: }
1.171 raeburn 5410: my $usertype = 'unofficial';
5411: if (ref($rulematch{$user}) eq 'HASH') {
5412: if ($rulematch{$user}{'username'}) {
5413: $usertype = 'official';
1.5 raeburn 5414: }
5415: }
1.171 raeburn 5416: unless ($cancreate{$usertype}) {
5417: my $showtype = $longtypes{$usertype};
5418: $r->print('<li>'.
5419: &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].','<b>'.$username.'</b>',$showtype).'</li>');
5420: next;
5421: }
1.172 raeburn 5422: } elsif ($id ne '') {
1.171 raeburn 5423: if (exists($checkids{$user})) {
5424: $checkid = 1;
1.5 raeburn 5425: if (ref($alerts{'id'}) eq 'HASH') {
1.57 raeburn 5426: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
1.172 raeburn 5427: if ($alerts{'id'}{$userdomain}{$username}) {
1.171 raeburn 5428: $r->print('<li>'.
1.172 raeburn 5429: &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 5430: '<b>'.$username.'</b>').'<br />'.
1.172 raeburn 5431: &mt('Consequently, the ID was not changed.').'</li>');
5432: $id = '';
1.124 raeburn 5433: }
1.5 raeburn 5434: }
5435: }
5436: }
5437: }
1.171 raeburn 5438: my $multiple = 0;
5439: my ($userresult,$authresult,$roleresult,$idresult);
5440: my (%userres,%authres,%roleres,%idres);
5441: my $singlesec = '';
5442: if ($role eq 'st') {
1.206 raeburn 5443: if (($context eq 'domain') && ($changeauth eq 'Yes') && (!$newuser)) {
5444: if ((&Apache::lonnet::allowed('mau',$userdomain)) &&
5445: (&Apache::lonnet::homeserver($username,$userdomain) ne 'no_host')) {
5446: if ((($amode =~ /^krb4|krb5|internal$/) && $password ne '') ||
5447: ($amode eq 'localauth')) {
5448: $authresult =
5449: &Apache::lonnet::modifyuserauth($userdomain,$username,$amode,$password);
5450: }
5451: }
5452: }
1.171 raeburn 5453: my $sec;
5454: if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
1.42 raeburn 5455: if (@secs > 0) {
5456: $sec = $secs[0];
1.27 raeburn 5457: }
1.171 raeburn 5458: }
1.212 raeburn 5459: if ($userdomain ne $env{'request.role.domain'}) {
5460: my $item = "/$crsdom/$crsnum" ;
5461: if ($sec ne '') {
5462: $item .= "/$sec";
5463: }
5464: $item .= '_st';
5465: next if (&restricted_dom($context,$item,$userdomain,$username,$role,$startdate,
5466: $enddate,$crsdom,$crsnum,$sec,$credits,\%process_by,
5467: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.213 raeburn 5468: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.212 raeburn 5469: }
1.171 raeburn 5470: &modifystudent($userdomain,$username,$cid,$sec,
5471: $desiredhost,$context);
5472: $roleresult =
5473: &Apache::lonnet::modifystudent
5474: ($userdomain,$username,$id,$amode,$password,
5475: $fname,$mname,$lname,$gen,$sec,$enddate,
5476: $startdate,$env{'form.forceid'},
5477: $desiredhost,$email,'manual','',$cid,
5478: '',$context,$inststatus,$credits);
5479: $userresult = $roleresult;
5480: } else {
1.212 raeburn 5481: my $possrole;
5482: if ($role ne '') {
1.171 raeburn 5483: if ($context eq 'course' || $setting eq 'course') {
5484: if ($customroles{$role}) {
5485: $role = 'cr_'.$env{'user.domain'}.'_'.
5486: $env{'user.name'}.'_'.$role;
5487: }
1.212 raeburn 5488: $possrole = $role;
5489: if ($possrole =~ /^cr_/) {
5490: $possrole =~ s{_}{/}g;
5491: }
5492: if (($role ne 'cc') && ($role ne 'co')) {
1.171 raeburn 5493: if (@secs > 1) {
5494: $multiple = 1;
1.212 raeburn 5495: my $prefix = "/$crsdom/$crsnum";
1.171 raeburn 5496: foreach my $sec (@secs) {
1.212 raeburn 5497: if ($userdomain ne $env{'request.role.domain'}) {
5498: my $item = $prefix;
5499: if ($sec ne '') {
5500: $item .= "/$sec";
5501: }
5502: $item .= '_'.$possrole;
5503: next if (&restricted_dom($context,$item,$userdomain,$username,$possrole,
5504: $startdate,$enddate,$crsdom,$crsnum,$sec,
5505: $credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 5506: \%got_instdoms,\%reject,\%pending,\%notifydc,
5507: \%status,\%unauthorized,\%currqueued));
1.212 raeburn 5508: }
1.171 raeburn 5509: ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
5510: &modifyuserrole($context,$setting,
5511: $changeauth,$cid,$userdomain,$username,
5512: $id,$amode,$password,$fname,
5513: $mname,$lname,$gen,$sec,
5514: $env{'form.forceid'},$desiredhost,
5515: $email,$role,$enddate,
5516: $startdate,$checkid,$inststatus);
1.42 raeburn 5517: }
1.171 raeburn 5518: } elsif (@secs > 0) {
5519: $singlesec = $secs[0];
1.27 raeburn 5520: }
5521: }
1.212 raeburn 5522: } else {
5523: $possrole = $role;
1.27 raeburn 5524: }
1.204 raeburn 5525: }
5526: if (!$multiple) {
1.212 raeburn 5527: if (($userdomain ne $env{'request.role.domain'}) && ($role ne '')) {
5528: my $item = "/$crsdom/$crsnum";
5529: if ($singlesec ne '') {
5530: $item .= "/$singlesec";
5531: }
5532: $item .= '_'.$possrole;
5533: next if (&restricted_dom($context,$item,$userdomain,$username,$possrole,$startdate,$enddate,
5534: $crsdom,$crsnum,$singlesec,$credits,\%process_by,\%instdoms,
1.213 raeburn 5535: \%got_role_approvals,\%got_instdoms,\%reject,\%pending,\%notifydc,
5536: \%status,\%unauthorized,\%currqueued));
1.212 raeburn 5537: }
1.204 raeburn 5538: ($userresult,$authresult,$roleresult,$idresult) =
5539: &modifyuserrole($context,$setting,
5540: $changeauth,$cid,$userdomain,$username,
5541: $id,$amode,$password,$fname,
5542: $mname,$lname,$gen,$singlesec,
5543: $env{'form.forceid'},$desiredhost,
5544: $email,$role,$enddate,$startdate,
5545: $checkid,$inststatus);
1.27 raeburn 5546: }
1.171 raeburn 5547: }
5548: if ($multiple) {
5549: foreach my $sec (sort(keys(%userres))) {
5550: $flushc =
1.27 raeburn 5551: &user_change_result($r,$userres{$sec},$authres{$sec},
5552: $roleres{$sec},$idres{$sec},\%counts,$flushc,
1.57 raeburn 5553: $username,$userdomain,\%userchg);
1.27 raeburn 5554:
1.1 raeburn 5555: }
5556: } else {
1.171 raeburn 5557: $flushc =
5558: &user_change_result($r,$userresult,$authresult,
5559: $roleresult,$idresult,\%counts,$flushc,
5560: $username,$userdomain,\%userchg);
1.1 raeburn 5561: }
5562: }
1.172 raeburn 5563: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last user');
1.171 raeburn 5564: } # end of loop
1.172 raeburn 5565: $r->print('</ul>');
1.171 raeburn 5566: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
5567: }
1.1 raeburn 5568: # Flush the course logs so reverse user roles immediately updated
1.126 raeburn 5569: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.29 raeburn 5570: $r->print("</p>\n<p>\n".&mt('Processed [quant,_1,user].',$counts{'user'}).
1.1 raeburn 5571: "</p>\n");
5572: if ($counts{'role'} > 0) {
5573: $r->print("<p>\n".
1.192 raeburn 5574: &mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.
5575: &mt('If a user is currently logged-in to LON-CAPA, any new roles which are active will be available when the user next logs in.').
5576: "</p>\n");
1.29 raeburn 5577: } else {
5578: $r->print('<p>'.&mt('No roles added').'</p>');
1.1 raeburn 5579: }
5580: if ($counts{'auth'} > 0) {
5581: $r->print("<p>\n".
5582: &mt('Authentication changed for [_1] existing users.',
5583: $counts{'auth'})."</p>\n");
5584: }
1.13 raeburn 5585: $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
1.200 raeburn 5586: $r->print(&passwdrule_alerts($domain,\%showpasswdrules));
1.213 raeburn 5587: if ((keys(%reject)) || (keys(%unauthorized))) {
5588: $r->print(&print_roles_rejected($context,\%reject,\%unauthorized));
1.212 raeburn 5589: }
1.213 raeburn 5590: if ((keys(%pending)) || (keys(%currqueued))) {
5591: $r->print(&print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.212 raeburn 5592: }
1.1 raeburn 5593: #####################################
1.29 raeburn 5594: # Display list of students to drop #
1.1 raeburn 5595: #####################################
5596: if ($env{'form.fullup'} eq 'yes') {
1.29 raeburn 5597: $r->print('<h3>'.&mt('Students to Drop')."</h3>\n");
1.1 raeburn 5598: # Get current classlist
1.30 raeburn 5599: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 5600: if (! defined($classlist)) {
1.192 raeburn 5601: $r->print('<p class="LC_info">'.
5602: &mt('There are no students with current/future access to the course.').
5603: '</p>'."\n");
1.66 raeburn 5604: } elsif (ref($classlist) eq 'HASH') {
1.1 raeburn 5605: # Remove the students we just added from the list of students.
1.30 raeburn 5606: foreach my $line (@userdata) {
5607: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 5608: unless (($entries{$fields{'username'}} eq '') ||
5609: (!defined($entries{$fields{'username'}}))) {
5610: delete($classlist->{$entries{$fields{'username'}}.
5611: ':'.$domain});
5612: }
5613: }
5614: # Print out list of dropped students.
1.30 raeburn 5615: &show_drop_list($r,$classlist,'nosort',$permission);
1.1 raeburn 5616: }
5617: }
5618: } # end of unless
1.193 raeburn 5619: return 'ok';
1.1 raeburn 5620: }
5621:
1.13 raeburn 5622: sub print_namespacing_alerts {
5623: my ($domain,$alerts,$curr_rules) = @_;
5624: my $output;
5625: if (ref($alerts) eq 'HASH') {
5626: if (keys(%{$alerts}) > 0) {
5627: if (ref($alerts->{'username'}) eq 'HASH') {
5628: foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
5629: my $count;
5630: if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
5631: $count = keys(%{$alerts->{'username'}{$dom}});
5632: }
5633: my $domdesc = &Apache::lonnet::domain($domain,'description');
5634: if (ref($curr_rules->{$dom}) eq 'HASH') {
5635: $output .= &Apache::loncommon::instrule_disallow_msg(
5636: 'username',$domdesc,$count,'upload');
5637: }
5638: $output .= &Apache::loncommon::user_rule_formats($dom,
5639: $domdesc,$curr_rules->{$dom}{'username'},
5640: 'username');
5641: }
5642: }
5643: if (ref($alerts->{'id'}) eq 'HASH') {
5644: foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
5645: my $count;
5646: if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
5647: $count = keys(%{$alerts->{'id'}{$dom}});
5648: }
5649: my $domdesc = &Apache::lonnet::domain($domain,'description');
5650: if (ref($curr_rules->{$dom}) eq 'HASH') {
5651: $output .= &Apache::loncommon::instrule_disallow_msg(
5652: 'id',$domdesc,$count,'upload');
5653: }
5654: $output .= &Apache::loncommon::user_rule_formats($dom,
5655: $domdesc,$curr_rules->{$dom}{'id'},'id');
5656: }
5657: }
5658: }
5659: }
5660: }
5661:
1.200 raeburn 5662: sub passwdrule_alerts {
5663: my ($domain,$passwdrules) = @_;
5664: my $warning;
5665: if (ref($passwdrules) eq 'HASH') {
5666: my %showrules = %{$passwdrules};
5667: if (keys(%showrules)) {
5668: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
5669: $warning = '<b>'.&mt('Password requirement(s) unmet for one or more users:').'</b><ul>';
5670: if ($showrules{'min'}) {
1.208 raeburn 5671: my $min = $passwdconf{'min'};
5672: if ($min eq '') {
5673: $min = $Apache::lonnet::passwdmin;
5674: }
5675: $warning .= '<li>'.&mt('minimum [quant,_1,character]',$min).'</li>';
1.200 raeburn 5676: }
5677: if ($showrules{'max'}) {
5678: $warning .= '<li>'.&mt('maximum [quant,_1,character]',$passwdconf{'max'}).'</li>';
5679: }
5680: if ($showrules{'uc'}) {
5681: $warning .= '<li>'.&mt('contain at least one upper case letter').'</li>';
5682: }
5683: if ($showrules{'lc'}) {
5684: $warning .= '<li>'.&mt('contain at least one lower case letter').'</li>';
5685: }
5686: if ($showrules{'num'}) {
5687: $warning .= '<li>'.&mt('contain at least one number').'</li>';
5688: }
5689: if ($showrules{'spec'}) {
5690: $warning .= '<li>'.&mt('contain at least one non-alphanumeric').'</li>';
5691: }
5692: $warning .= '</ul>';
5693: }
5694: }
5695: return $warning;
5696: }
5697:
1.1 raeburn 5698: sub user_change_result {
1.29 raeburn 5699: my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
1.57 raeburn 5700: $username,$userdomain,$userchg) = @_;
1.1 raeburn 5701: my $okresult = 0;
1.171 raeburn 5702: my @status;
1.1 raeburn 5703: if ($userresult ne 'ok') {
5704: if ($userresult =~ /^error:(.+)$/) {
5705: my $error = $1;
1.171 raeburn 5706: push(@status,
5707: &mt('[_1]: Unable to add/modify: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5708: }
5709: } else {
5710: $counts->{'user'} ++;
5711: $okresult = 1;
5712: }
5713: if ($authresult ne 'ok') {
5714: if ($authresult =~ /^error:(.+)$/) {
5715: my $error = $1;
1.171 raeburn 5716: push(@status,
5717: &mt('[_1]: Unable to modify authentication: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5718: }
5719: } else {
5720: $counts->{'auth'} ++;
5721: $okresult = 1;
5722: }
5723: if ($roleresult ne 'ok') {
5724: if ($roleresult =~ /^error:(.+)$/) {
5725: my $error = $1;
1.171 raeburn 5726: push(@status,
5727: &mt('[_1]: Unable to add role: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5728: }
5729: } else {
5730: $counts->{'role'} ++;
5731: $okresult = 1;
5732: }
5733: if ($okresult) {
5734: $flushc++;
1.57 raeburn 5735: $userchg->{$username.':'.$userdomain}=1;
1.1 raeburn 5736: if ($flushc>15) {
5737: $r->rflush;
5738: $flushc=0;
5739: }
5740: }
1.29 raeburn 5741: if ($idresult) {
1.171 raeburn 5742: push(@status,$idresult);
5743: }
5744: if (@status) {
5745: $r->print('<li>'.join('<br />',@status).'</li>');
1.29 raeburn 5746: }
1.1 raeburn 5747: return $flushc;
5748: }
5749:
5750: # ========================================================= Menu Phase Two Drop
1.17 raeburn 5751: sub print_drop_menu {
1.101 raeburn 5752: my ($r,$context,$permission,$crstype) = @_;
5753: my $heading;
5754: if ($crstype eq 'Community') {
5755: $heading = &mt("Drop Members");
5756: } else {
5757: $heading = &mt("Drop Students");
5758: }
5759: $r->print('<h3>'.$heading.'</h3>'."\n".
1.153 bisitz 5760: '<form name="studentform" method="post" action="">'."\n");
1.30 raeburn 5761: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 5762: if (! defined($classlist)) {
1.143 bisitz 5763: my $msg = '';
1.101 raeburn 5764: if ($crstype eq 'Community') {
1.143 bisitz 5765: $msg = &mt('There are no members currently enrolled.');
1.101 raeburn 5766: } else {
1.143 bisitz 5767: $msg = &mt('There are no students currently enrolled.');
1.101 raeburn 5768: }
1.143 bisitz 5769: $r->print('<p class="LC_info">'.$msg."</p>\n");
1.30 raeburn 5770: } else {
1.101 raeburn 5771: &show_drop_list($r,$classlist,'nosort',$permission,$crstype);
1.1 raeburn 5772: }
1.162 bisitz 5773: $r->print('</form>');
1.1 raeburn 5774: return;
5775: }
5776:
5777: # ================================================================== Phase four
5778:
1.11 raeburn 5779: sub update_user_list {
1.118 raeburn 5780: my ($r,$context,$setting,$choice,$crstype) = @_;
1.11 raeburn 5781: my $now = time;
1.1 raeburn 5782: my $count=0;
1.101 raeburn 5783: if ($context eq 'course') {
5784: $crstype = &Apache::loncommon::course_type();
5785: }
1.212 raeburn 5786: my (@changelist,%got_role_approvals,%got_instdoms,%process_by,%instdoms,
1.213 raeburn 5787: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
1.29 raeburn 5788: if ($choice eq 'drop') {
5789: @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
5790: } else {
1.11 raeburn 5791: @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
5792: }
5793: my %result_text = ( ok => { 'revoke' => 'Revoked',
5794: 'delete' => 'Deleted',
5795: 'reenable' => 'Re-enabled',
1.17 raeburn 5796: 'activate' => 'Activated',
5797: 'chgdates' => 'Changed Access Dates for',
1.118 raeburn 5798: 'chgsec' => 'Changed section(s) for',
1.17 raeburn 5799: 'drop' => 'Dropped',
1.11 raeburn 5800: },
5801: error => {'revoke' => 'revoking',
5802: 'delete' => 'deleting',
5803: 'reenable' => 're-enabling',
5804: 'activate' => 'activating',
1.17 raeburn 5805: 'chgdates' => 'changing access dates for',
5806: 'chgsec' => 'changing section for',
5807: 'drop' => 'dropping',
1.11 raeburn 5808: },
5809: );
5810: my ($startdate,$enddate);
5811: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
5812: ($startdate,$enddate) = &get_dates_from_form();
5813: }
5814: foreach my $item (@changelist) {
1.118 raeburn 5815: my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,
5816: @sections,$scopestem,$singlesec,$showsecs,$warn_singlesec,
1.212 raeburn 5817: $nothingtodo,$keepnosection,$credits,$instsec,$cdom,$cnum);
1.17 raeburn 5818: if ($choice eq 'drop') {
5819: ($uname,$udom,$sec) = split(/:/,$item,-1);
5820: $role = 'st';
5821: $cid = $env{'request.course.id'};
5822: $scopestem = '/'.$cid;
5823: $scopestem =~s/\_/\//g;
5824: if ($sec eq '') {
5825: $scope = $scopestem;
5826: } else {
5827: $scope = $scopestem.'/'.$sec;
5828: }
5829: } elsif ($context eq 'course') {
1.174 raeburn 5830: ($uname,$udom,$role,$sec,$type,$locktype,$credits,$instsec) =
5831: split(/\:/,$item,8);
5832: $instsec = &unescape($instsec);
1.11 raeburn 5833: $cid = $env{'request.course.id'};
1.212 raeburn 5834: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5835: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.11 raeburn 5836: $scopestem = '/'.$cid;
5837: $scopestem =~s/\_/\//g;
5838: if ($sec eq '') {
5839: $scope = $scopestem;
5840: } else {
5841: $scope = $scopestem.'/'.$sec;
5842: }
1.13 raeburn 5843: } elsif ($context eq 'author') {
1.11 raeburn 5844: ($uname,$udom,$role) = split(/\:/,$item,-1);
5845: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
1.212 raeburn 5846: $cdom = $env{'user.domain'};
5847: $cnum = $env{'user.name'};
1.11 raeburn 5848: } elsif ($context eq 'domain') {
5849: if ($setting eq 'domain') {
5850: ($role,$uname,$udom) = split(/\:/,$item,-1);
5851: $scope = '/'.$env{'request.role.domain'}.'/';
1.212 raeburn 5852: $cdom = $env{'request.role.domain'};
1.13 raeburn 5853: } elsif ($setting eq 'author') {
1.11 raeburn 5854: ($uname,$udom,$role,$scope) = split(/\:/,$item);
1.212 raeburn 5855: (undef,$cdom,$cnum) = split(/\//,$scope);
1.11 raeburn 5856: } elsif ($setting eq 'course') {
1.174 raeburn 5857: ($uname,$udom,$role,$cid,$sec,$type,$locktype,$credits,$instsec) =
5858: split(/\:/,$item,9);
1.212 raeburn 5859: ($cdom,$cnum) = split('_',$cid);
1.174 raeburn 5860: $instsec = &unescape($instsec);
1.11 raeburn 5861: $scope = '/'.$cid;
5862: $scope =~s/\_/\//g;
5863: if ($sec ne '') {
5864: $scope .= '/'.$sec;
5865: }
5866: }
5867: }
1.101 raeburn 5868: my $plrole = &Apache::lonnet::plaintext($role,$crstype);
1.11 raeburn 5869: my $start = $env{'form.'.$item.'_start'};
5870: my $end = $env{'form.'.$item.'_end'};
1.17 raeburn 5871: if ($choice eq 'drop') {
5872: # drop students
5873: $end = $now;
5874: $type = 'manual';
5875: $result =
1.52 raeburn 5876: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.17 raeburn 5877: } elsif ($choice eq 'revoke') {
5878: # revoke or delete user role
1.11 raeburn 5879: $end = $now;
5880: if ($role eq 'st') {
5881: $result =
1.174 raeburn 5882: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.11 raeburn 5883: } else {
5884: $result =
1.52 raeburn 5885: &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
5886: '','',$context);
1.11 raeburn 5887: }
5888: } elsif ($choice eq 'delete') {
5889: if ($role eq 'st') {
1.174 raeburn 5890: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.29 raeburn 5891: }
5892: $result =
5893: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
1.52 raeburn 5894: $start,1,'',$context);
1.11 raeburn 5895: } else {
5896: #reenable, activate, change access dates or change section
5897: if ($choice ne 'chgsec') {
5898: $start = $startdate;
5899: $end = $enddate;
5900: }
1.212 raeburn 5901: my $id = $scope.'_'.$role;
1.11 raeburn 5902: if ($choice eq 'reenable') {
1.212 raeburn 5903: next if (&restricted_dom($context,$id,$udom,$uname,$role,$now,$end,$cdom,$cnum,
5904: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 5905: \%got_instdoms,\%reject,\%pending,\%notifydc,
5906: \%status,\%unauthorized,\%currqueued));
1.11 raeburn 5907: if ($role eq 'st') {
1.174 raeburn 5908: $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 5909: } else {
5910: $result =
5911: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 5912: $now,'','',$context);
1.11 raeburn 5913: }
5914: } elsif ($choice eq 'activate') {
1.212 raeburn 5915: next if (&restricted_dom($context,$id,$udom,$uname,$role,$now,$end,$cdom,$cnum,
5916: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 5917: \%got_instdoms,\%reject,\%pending,\%notifydc,
5918: \%status,\%unauthorized,\%currqueued));
1.11 raeburn 5919: if ($role eq 'st') {
1.174 raeburn 5920: $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 5921: } else {
5922: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 5923: $now,'','',$context);
1.11 raeburn 5924: }
5925: } elsif ($choice eq 'chgdates') {
1.212 raeburn 5926: next if (&restricted_dom($context,$id,$udom,$uname,$role,$start,$end,$cdom,$cnum,
5927: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 5928: \%got_instdoms,\%reject,\%pending,\%notifydc,
5929: \%status,\%unauthorized,\%currqueued));
1.11 raeburn 5930: if ($role eq 'st') {
1.174 raeburn 5931: $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 5932: } else {
5933: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 5934: $start,'','',$context);
1.11 raeburn 5935: }
5936: } elsif ($choice eq 'chgsec') {
5937: my (@newsecs,$revresult,$nochg,@retained);
1.103 raeburn 5938: if (($role ne 'cc') && ($role ne 'co')) {
1.117 raeburn 5939: my @secs = sort(split(/,/,$env{'form.newsecs'}));
5940: if (@secs) {
5941: my %curr_groups = &Apache::longroup::coursegroups();
5942: foreach my $sec (@secs) {
5943: next if (($sec =~ /\W/) || ($sec eq 'none') ||
5944: (exists($curr_groups{$sec})));
5945: push(@newsecs,$sec);
5946: }
5947: }
1.11 raeburn 5948: }
5949: # remove existing section if not to be retained.
1.118 raeburn 5950: if (!$env{'form.retainsec'} || ($role eq 'st')) {
1.11 raeburn 5951: if ($sec eq '') {
5952: if (@newsecs == 0) {
1.118 raeburn 5953: $result = 'ok';
1.11 raeburn 5954: $nochg = 1;
1.118 raeburn 5955: $nothingtodo = 1;
1.40 raeburn 5956: } else {
5957: $revresult =
5958: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 5959: $scope,$role,
5960: '','',$context);
1.40 raeburn 5961: }
1.11 raeburn 5962: } else {
1.28 raeburn 5963: if (@newsecs > 0) {
5964: if (grep(/^\Q$sec\E$/,@newsecs)) {
5965: push(@retained,$sec);
5966: } else {
5967: $revresult =
5968: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 5969: $scope,$role,
5970: '','',$context);
1.28 raeburn 5971: }
5972: } else {
1.11 raeburn 5973: $revresult =
1.28 raeburn 5974: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 5975: $scope,$role,
5976: '','',$context);
1.11 raeburn 5977: }
5978: }
5979: } else {
1.28 raeburn 5980: if ($sec eq '') {
5981: $nochg = 1;
1.118 raeburn 5982: $keepnosection = 1;
5983: } else {
1.28 raeburn 5984: push(@retained,$sec);
5985: }
1.11 raeburn 5986: }
5987: # add new sections
1.118 raeburn 5988: my (@diffs,@shownew);
5989: if (@retained) {
5990: @diffs = &Apache::loncommon::compare_arrays(\@retained,\@newsecs);
5991: } else {
5992: @diffs = @newsecs;
5993: }
1.11 raeburn 5994: if (@newsecs == 0) {
1.118 raeburn 5995: if ($nochg) {
5996: $result = 'ok';
5997: $nothingtodo = 1;
5998: } else {
1.28 raeburn 5999: if ($role eq 'st') {
6000: $result =
1.174 raeburn 6001: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.28 raeburn 6002: } else {
6003: my $newscope = $scopestem;
1.52 raeburn 6004: $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
1.11 raeburn 6005: }
6006: }
1.118 raeburn 6007: $showsecs = &mt('No section');
6008: } elsif (@diffs == 0) {
6009: $result = 'ok';
6010: $nothingtodo = 1;
1.11 raeburn 6011: } else {
1.118 raeburn 6012: foreach my $newsec (@newsecs) {
1.11 raeburn 6013: if (!grep(/^\Q$newsec\E$/,@retained)) {
6014: if ($role eq 'st') {
1.174 raeburn 6015: $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 6016: if (@newsecs > 1) {
6017: my $showsingle;
6018: if ($newsec eq '') {
6019: $showsingle = &mt('No section');
6020: } else {
6021: $showsingle = $newsec;
6022: }
6023: if ($crstype eq 'Community') {
6024: $warn_singlesec = &mt('Although more than one section was indicated, a role was only added for the first section - [_1], as each community member may only be in one section at a time.','<i>'.$showsingle.'</i>');
6025: } else {
6026: $warn_singlesec = &mt('Although more than one section was indicated, a role was only added for the first section - [_1], as each student may only be in one section of a course at a time.','<i>'.$showsingle.'</i>');
6027: }
6028: $showsecs = $showsingle;
6029: last;
6030: } else {
6031: if ($newsec eq '') {
6032: $showsecs = &mt('No section');
6033: } else {
6034: $showsecs = $newsec;
6035: }
6036: }
1.11 raeburn 6037: } else {
6038: my $newscope = $scopestem;
6039: if ($newsec ne '') {
6040: $newscope .= '/'.$newsec;
1.118 raeburn 6041: push(@shownew,$newsec);
1.11 raeburn 6042: }
6043: $result = &Apache::lonnet::assignrole($udom,$uname,
6044: $newscope,$role,$end,$start);
1.118 raeburn 6045:
1.11 raeburn 6046: }
6047: }
6048: }
6049: }
1.118 raeburn 6050: unless ($role eq 'st') {
6051: unless ($showsecs) {
6052: my @tolist = sort(@shownew,@retained);
6053: if ($keepnosection) {
6054: push(@tolist,&mt('No section'));
6055: }
6056: $showsecs = join(', ',@tolist);
6057: }
6058: }
1.11 raeburn 6059: }
6060: }
1.17 raeburn 6061: my $extent = $scope;
6062: if ($choice eq 'drop' || $context eq 'course') {
6063: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
6064: if ($cdesc) {
6065: $extent = $cdesc;
6066: }
6067: }
1.1 raeburn 6068: if ($result eq 'ok' || $result eq 'ok:') {
1.118 raeburn 6069: my $dates;
6070: if (($choice eq 'chgsec') || ($choice eq 'chgdates')) {
6071: $dates = &dates_feedback($start,$end,$now);
6072: }
6073: if ($choice eq 'chgsec') {
6074: if ($nothingtodo) {
6075: $r->print(&mt("Section assignment for role of '[_1]' in [_2] for '[_3]' unchanged.",$plrole,$extent,'<i>'.
6076: &Apache::loncommon::plainname($uname,$udom).
6077: '</i>').' ');
6078: if ($sec eq '') {
6079: $r->print(&mt('[_1]No section[_2] - [_3]','<b>','</b>',$dates));
6080: } else {
6081: $r->print(&mt('Section(s): [_1] - [_2]',
6082: '<b>'.$showsecs.'</b>',$dates));
6083: }
6084: $r->print('<br />');
6085: } else {
6086: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' to [_4] - [_5]",$plrole,$extent,
6087: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
6088: '<b>'.$showsecs.'</b>',$dates).'<br />');
6089: $count ++;
6090: }
6091: if ($warn_singlesec) {
6092: $r->print('<div class="LC_warning">'.$warn_singlesec.'</div>');
6093: }
6094: } elsif ($choice eq 'chgdates') {
6095: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' - [_4]",$plrole,$extent,
1.121 raeburn 6096: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
1.118 raeburn 6097: $dates).'<br />');
6098: $count ++;
6099: } else {
6100: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]'.",$plrole,$extent,
1.121 raeburn 6101: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>').
1.118 raeburn 6102: '<br />');
6103: $count ++;
6104: }
1.1 raeburn 6105: } else {
6106: $r->print(
1.118 raeburn 6107: &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for '[_3]': [_4].",
6108: $plrole,$extent,
1.121 raeburn 6109: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
1.118 raeburn 6110: $result).'<br />');
1.11 raeburn 6111: }
6112: }
1.32 raeburn 6113: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
1.33 raeburn 6114: if ($choice eq 'drop') {
6115: $r->print('<input type="hidden" name="action" value="listusers" />'."\n".
6116: '<input type="hidden" name="Status" value="Active" />'."\n".
6117: '<input type="hidden" name="showrole" value="st" />'."\n");
6118: } else {
6119: foreach my $item ('action','sortby','roletype','showrole','Status','secfilter','grpfilter') {
6120: if ($env{'form.'.$item} ne '') {
6121: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.
6122: '" />'."\n");
6123: }
1.32 raeburn 6124: }
6125: }
1.144 bisitz 6126: $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} [quant,_1,user role,user roles,no user roles].",$count).'</b></p>');
1.11 raeburn 6127: if ($count > 0) {
1.17 raeburn 6128: if ($choice eq 'revoke' || $choice eq 'drop') {
1.74 bisitz 6129: $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>');
1.11 raeburn 6130: }
6131: # Flush the course logs so reverse user roles immediately updated
1.126 raeburn 6132: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.11 raeburn 6133: }
6134: if ($env{'form.makedatesdefault'}) {
6135: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
1.101 raeburn 6136: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
1.1 raeburn 6137: }
6138: }
1.213 raeburn 6139: if ((keys(%reject)) || (keys(%unauthorized))) {
6140: $r->print(&print_roles_rejected($context,\%reject,\%unauthorized));
1.212 raeburn 6141: }
1.213 raeburn 6142: if ((keys(%pending)) || (keys(%currqueued))) {
6143: $r->print(&print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.212 raeburn 6144: }
1.33 raeburn 6145: my $linktext = &mt('Display User Lists');
6146: if ($choice eq 'drop') {
6147: $linktext = &mt('Display current class roster');
6148: }
1.144 bisitz 6149: $r->print(
6150: &Apache::lonhtmlcommon::actionbox(
6151: ['<a href="javascript:document.studentform.submit()">'.$linktext.'</a>'])
6152: .'</form>'."\n");
1.1 raeburn 6153: }
6154:
1.118 raeburn 6155: sub dates_feedback {
6156: my ($start,$end,$now) = @_;
6157: my $dates;
6158: if ($start < $now) {
6159: if ($end == 0) {
1.147 bisitz 6160: $dates = &mt('role(s) active now; no end date');
1.118 raeburn 6161: } elsif ($end > $now) {
6162: $dates = &mt('role(s) active now; ends [_1].',&Apache::lonlocal::locallocaltime($end));
6163: } else {
6164: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
6165: }
6166: } else {
6167: if ($end == 0 || $end > $now) {
6168: $dates = &mt('future role(s); starts: [_1].',&Apache::lonlocal::locallocaltime($start));
6169: } else {
6170: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
6171: }
6172: }
6173: return $dates;
6174: }
6175:
1.8 raeburn 6176: sub classlist_drop {
1.29 raeburn 6177: my ($scope,$uname,$udom,$now) = @_;
1.8 raeburn 6178: my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
1.29 raeburn 6179: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.8 raeburn 6180: if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
1.63 raeburn 6181: my %user;
6182: my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
1.8 raeburn 6183: return &mt('Drop from classlist: [_1]',
6184: '<b>'.$result.'</b>').'<br />';
6185: }
6186: }
6187: }
6188:
6189: sub active_student_roles {
6190: my ($cnum,$cdom,$uname,$udom) = @_;
6191: my %roles =
6192: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
6193: ['future','active'],['st']);
6194: return exists($roles{"$cnum:$cdom:st"});
6195: }
6196:
1.1 raeburn 6197: sub section_check_js {
1.8 raeburn 6198: my $groupslist= &get_groupslist();
1.170 damieng 6199: my %js_lt = &Apache::lonlocal::texthash(
6200: mayn => 'may not be used as the name for a section, as it is a reserved word.',
6201: plch => 'Please choose a different section name.',
6202: mnot => 'may not be used as a section name, as it is the name of a course group.',
6203: secn => 'Section names and group names must be distinct. Please choose a different section name.',
6204: );
6205: &js_escape(\%js_lt);
1.1 raeburn 6206: return <<"END";
6207: function validate(caller) {
1.9 raeburn 6208: var groups = new Array($groupslist);
1.1 raeburn 6209: var secname = caller.value;
6210: if ((secname == 'all') || (secname == 'none')) {
1.170 damieng 6211: alert("'"+secname+"' $js_lt{'mayn'}\\n$js_lt{'plch'}");
1.1 raeburn 6212: return 'error';
6213: }
6214: if (secname != '') {
6215: for (var k=0; k<groups.length; k++) {
6216: if (secname == groups[k]) {
1.170 damieng 6217: alert("'"+secname+"' $js_lt{'mnot'}\\n$js_lt{'secn'}");
1.1 raeburn 6218: return 'error';
6219: }
6220: }
6221: }
6222: return 'ok';
6223: }
6224: END
6225: }
6226:
6227: sub set_login {
1.194 raeburn 6228: my ($dom,$authformkrb,$authformint,$authformloc,$authformlti) = @_;
1.1 raeburn 6229: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6230: my $response;
6231: my ($authnum,%can_assign) =
6232: &Apache::loncommon::get_assignable_auth($dom);
6233: if ($authnum) {
6234: $response = &Apache::loncommon::start_data_table();
6235: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
6236: $response .= &Apache::loncommon::start_data_table_row().
6237: '<td>'.$authformkrb.'</td>'.
6238: &Apache::loncommon::end_data_table_row()."\n";
6239: }
6240: if ($can_assign{'int'}) {
6241: $response .= &Apache::loncommon::start_data_table_row().
6242: '<td>'.$authformint.'</td>'.
6243: &Apache::loncommon::end_data_table_row()."\n"
6244: }
6245: if ($can_assign{'loc'}) {
6246: $response .= &Apache::loncommon::start_data_table_row().
6247: '<td>'.$authformloc.'</td>'.
6248: &Apache::loncommon::end_data_table_row()."\n";
6249: }
1.194 raeburn 6250: if ($can_assign{'lti'}) {
6251: $response .= &Apache::loncommon::start_data_table_row().
6252: '<td>'.$authformlti.'</td>'.
6253: &Apache::loncommon::end_data_table_row()."\n";
6254: }
1.1 raeburn 6255: $response .= &Apache::loncommon::end_data_table();
6256: }
6257: return $response;
6258: }
6259:
1.8 raeburn 6260: sub course_sections {
1.178 raeburn 6261: my ($sections_count,$role,$current_sec,$disabled) = @_;
1.8 raeburn 6262: my $output = '';
1.169 raeburn 6263: my @sections = (sort {$a <=> $b} keys(%{$sections_count}));
1.29 raeburn 6264: my $numsec = scalar(@sections);
1.92 bisitz 6265: my $is_selected = ' selected="selected"';
1.29 raeburn 6266: if ($numsec <= 1) {
1.178 raeburn 6267: $output = '<select name="currsec_'.$role.'"'.$disabled.'>'."\n".
1.51 raeburn 6268: ' <option value="">'.&mt('Select').'</option>'."\n";
6269: if ($current_sec eq 'none') {
6270: $output .=
6271: ' <option value=""'.$is_selected.'>'.&mt('No section').'</option>'."\n";
6272: } else {
6273: $output .=
1.29 raeburn 6274: ' <option value="">'.&mt('No section').'</option>'."\n";
1.51 raeburn 6275: }
1.29 raeburn 6276: if ($numsec == 1) {
1.51 raeburn 6277: if ($current_sec eq $sections[0]) {
6278: $output .=
6279: ' <option value="'.$sections[0].'"'.$is_selected.'>'.$sections[0].'</option>'."\n";
6280: } else {
6281: $output .=
1.8 raeburn 6282: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
1.51 raeburn 6283: }
1.29 raeburn 6284: }
1.8 raeburn 6285: } else {
6286: $output = '<select name="currsec_'.$role.'" ';
6287: my $multiple = 4;
6288: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
1.29 raeburn 6289: if ($role eq 'st') {
1.178 raeburn 6290: $output .= $disabled.'>'."\n".
1.51 raeburn 6291: ' <option value="">'.&mt('Select').'</option>'."\n";
6292: if ($current_sec eq 'none') {
6293: $output .=
6294: ' <option value=""'.$is_selected.'>'.&mt('No section')."</option>\n";
6295: } else {
6296: $output .=
1.29 raeburn 6297: ' <option value="">'.&mt('No section')."</option>\n";
1.51 raeburn 6298: }
1.29 raeburn 6299: } else {
1.178 raeburn 6300: $output .= 'multiple="multiple" size="'.$multiple.'"'.$disabled.'>'."\n";
1.29 raeburn 6301: }
1.8 raeburn 6302: foreach my $sec (@sections) {
1.51 raeburn 6303: if ($current_sec eq $sec) {
6304: $output .= '<option value="'.$sec.'"'.$is_selected.'>'.$sec."</option>\n";
6305: } else {
6306: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
6307: }
1.8 raeburn 6308: }
6309: }
6310: $output .= '</select>';
6311: return $output;
6312: }
6313:
6314: sub get_groupslist {
6315: my $groupslist;
6316: my %curr_groups = &Apache::longroup::coursegroups();
6317: if (%curr_groups) {
6318: $groupslist = join('","',sort(keys(%curr_groups)));
6319: $groupslist = '"'.$groupslist.'"';
6320: }
1.11 raeburn 6321: return $groupslist;
1.8 raeburn 6322: }
6323:
6324: sub setsections_javascript {
1.150 raeburn 6325: my ($formname,$groupslist,$mode,$checkauth,$crstype,$showcredits) = @_;
1.28 raeburn 6326: my ($checkincluded,$finish,$rolecode,$setsection_js);
6327: if ($mode eq 'upload') {
6328: $checkincluded = 'formname.name == "'.$formname.'"';
6329: $finish = "return 'ok';";
6330: $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
6331: } elsif ($formname eq 'cu') {
1.150 raeburn 6332: if (($crstype eq 'Course') && ($showcredits)) {
6333: $checkincluded = "((role == 'st') && (formname.elements[i-2].checked == true)) || ((role != 'st') && (formname.elements[i-1].checked == true))";
6334: } else {
6335: $checkincluded = 'formname.elements[i-1].checked == true';
6336: }
1.37 raeburn 6337: if ($checkauth) {
6338: $finish = "var authcheck = auth_check();\n".
6339: " if (authcheck == 'ok') {\n".
6340: " formname.submit();\n".
6341: " }\n";
6342: } else {
6343: $finish = 'formname.submit()';
6344: }
1.28 raeburn 6345: $rolecode = "var match = str.split('_');
6346: var role = match[3];\n";
1.165 raeburn 6347: } elsif (($formname eq 'enrollstudent') || ($formname eq 'selfenroll')) {
1.28 raeburn 6348: $checkincluded = 'formname.name == "'.$formname.'"';
1.37 raeburn 6349: if ($checkauth) {
6350: $finish = "var authcheck = auth_check();\n".
6351: " if (authcheck == 'ok') {\n".
6352: " formname.submit();\n".
6353: " }\n";
6354: } else {
6355: $finish = 'formname.submit()';
6356: }
1.28 raeburn 6357: $rolecode = "var match = str.split('_');
6358: var role = match[1];\n";
1.8 raeburn 6359: } else {
1.28 raeburn 6360: $checkincluded = 'formname.name == "'.$formname.'"';
1.8 raeburn 6361: $finish = "seccheck = 'ok';";
1.28 raeburn 6362: $rolecode = "var match = str.split('_');
6363: var role = match[1];\n";
1.11 raeburn 6364: $setsection_js = "var seccheck = 'alert';";
1.8 raeburn 6365: }
6366: my %alerts = &Apache::lonlocal::texthash(
6367: secd => 'Section designations do not apply to Course Coordinator roles.',
1.103 raeburn 6368: sedn => 'Section designations do not apply to Coordinator roles.',
1.8 raeburn 6369: accr => 'A course coordinator role will be added with access to all sections.',
1.103 raeburn 6370: acor => 'A coordinator role will be added with access to all sections',
1.8 raeburn 6371: inea => 'In each course, each user may only have one student role at a time.',
1.125 raeburn 6372: inco => 'In each community, each user may only have one member role at a time.',
1.145 raeburn 6373: youh => 'You had selected',
1.8 raeburn 6374: secs => 'sections.',
6375: plmo => 'Please modify your selections so they include no more than one section.',
6376: mayn => 'may not be used as the name for a section, as it is a reserved word.',
6377: plch => 'Please choose a different section name.',
6378: mnot => 'may not be used as a section name, as it is the name of a course group.',
6379: secn => 'Section names and group names must be distinct. Please choose a different section name.',
1.113 raeburn 6380: nonw => 'Section names may only contain letters or numbers.',
1.170 damieng 6381: );
6382: &js_escape(\%alerts);
1.8 raeburn 6383: $setsection_js .= <<"ENDSECCODE";
6384:
1.103 raeburn 6385: function setSections(formname,crstype) {
1.8 raeburn 6386: var re1 = /^currsec_/;
1.113 raeburn 6387: var re2 =/\\W/;
1.115 raeburn 6388: var trimleading = /^\\s+/;
6389: var trimtrailing = /\\s+\$/;
1.8 raeburn 6390: var groups = new Array($groupslist);
6391: for (var i=0;i<formname.elements.length;i++) {
6392: var str = formname.elements[i].name;
1.168 raeburn 6393: if (typeof(str) === "undefined") {
6394: continue;
6395: }
1.8 raeburn 6396: var checkcurr = str.match(re1);
6397: if (checkcurr != null) {
1.115 raeburn 6398: var num = i;
1.150 raeburn 6399: $rolecode
1.8 raeburn 6400: if ($checkincluded) {
1.103 raeburn 6401: if (role == 'cc' || role == 'co') {
6402: if (role == 'cc') {
6403: alert("$alerts{'secd'}\\n$alerts{'accr'}");
6404: } else {
6405: alert("$alerts{'sedn'}\\n$alerts{'acor'}");
6406: }
6407: } else {
1.8 raeburn 6408: var sections = '';
6409: var numsec = 0;
1.115 raeburn 6410: var fromexisting = new Array();
6411: for (var j=0; j<formname.elements[num].length; j++) {
6412: if (formname.elements[num].options[j].selected == true ) {
6413: var addsec = formname.elements[num].options[j].value;
1.119 raeburn 6414: if ((addsec != "") && (addsec != null)) {
1.115 raeburn 6415: fromexisting.push(addsec);
1.8 raeburn 6416: if (numsec == 0) {
1.115 raeburn 6417: sections = addsec;
6418: } else {
6419: sections = sections + "," + addsec;
1.8 raeburn 6420: }
1.115 raeburn 6421: numsec ++;
1.8 raeburn 6422: }
6423: }
6424: }
1.115 raeburn 6425: var newsecs = formname.elements[num+1].value;
1.113 raeburn 6426: var validsecs = new Array();
1.115 raeburn 6427: var validsecstr = '';
1.113 raeburn 6428: var badsecs = new Array();
1.8 raeburn 6429: if (newsecs != null && newsecs != "") {
1.115 raeburn 6430: var numsplit;
6431: if (newsecs.indexOf(',') == -1) {
6432: numsplit = new Array(newsecs);
6433: } else {
6434: numsplit = newsecs.split(/,/g);
6435: }
1.117 raeburn 6436: for (var m=0; m<numsplit.length; m++) {
6437: var newsec = numsplit[m];
1.115 raeburn 6438: newsec = newsec.replace(trimleading,'');
6439: newsec = newsec.replace(trimtrailing,'');
6440: if (re2.test(newsec) == true) {
6441: badsecs.push(newsec);
1.113 raeburn 6442: } else {
1.115 raeburn 6443: if (newsec != '') {
6444: var isnew = 1;
6445: if (fromexisting != null) {
1.117 raeburn 6446: for (var n=0; n<fromexisting.length; n++) {
6447: if (newsec == fromexisting[n]) {
1.115 raeburn 6448: isnew = 0;
6449: }
6450: }
6451: }
6452: if (isnew == 1) {
6453: validsecs.push(newsec);
6454: }
6455: }
1.113 raeburn 6456: }
6457: }
6458: if (badsecs.length > 0) {
6459: alert("$alerts{'nonw'}\\n$alerts{'plch'}");
6460: return;
6461: }
6462: numsec = numsec + validsecs.length;
1.8 raeburn 6463: }
6464: if ((role == 'st') && (numsec > 1)) {
1.103 raeburn 6465: if (crstype == 'Community') {
6466: alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
6467: } else {
6468: alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
6469: }
1.8 raeburn 6470: return;
1.115 raeburn 6471: } else {
6472: if (validsecs != null) {
6473: for (var j=0; j<validsecs.length; j++) {
6474: if (validsecstr == '' || validsecstr == null) {
6475: validsecstr = validsecs[j];
6476: } else {
6477: validsecstr += ','+validsecs[j];
6478: }
6479: if ((validsecs[j] == 'all') ||
6480: (validsecs[j] == 'none')) {
6481: alert("'"+validsecs[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
1.8 raeburn 6482: return;
6483: }
6484: for (var k=0; k<groups.length; k++) {
1.115 raeburn 6485: if (validsecs[j] == groups[k]) {
6486: alert("'"+validsecs[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
1.8 raeburn 6487: return;
6488: }
6489: }
6490: }
6491: }
6492: }
1.115 raeburn 6493: if ((validsecstr != '') && (validsecstr != null)) {
1.117 raeburn 6494: if ((sections == '') || (sections == null)) {
6495: sections = validsecstr;
6496: } else {
1.115 raeburn 6497: sections = sections + "," + validsecstr;
6498: }
6499: }
6500: formname.elements[num+2].value = sections;
1.8 raeburn 6501: }
6502: }
6503: }
6504: }
6505: $finish
6506: }
6507: ENDSECCODE
1.11 raeburn 6508: return $setsection_js;
1.8 raeburn 6509: }
6510:
1.15 raeburn 6511: sub can_create_user {
6512: my ($dom,$context,$usertype) = @_;
6513: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6514: my $cancreate = 1;
1.28 raeburn 6515: if (&Apache::lonnet::allowed('mau',$dom)) {
6516: return $cancreate;
1.178 raeburn 6517: } elsif ($context eq 'domain') {
6518: $cancreate = 0;
6519: return $cancreate;
1.28 raeburn 6520: }
1.15 raeburn 6521: if (ref($domconf{'usercreation'}) eq 'HASH') {
6522: if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
1.100 raeburn 6523: if ($context eq 'course' || $context eq 'author' || $context eq 'requestcrs') {
1.15 raeburn 6524: my $creation = $domconf{'usercreation'}{'cancreate'}{$context};
6525: if ($creation eq 'none') {
6526: $cancreate = 0;
6527: } elsif ($creation ne 'any') {
6528: if (defined($usertype)) {
6529: if ($creation ne $usertype) {
6530: $cancreate = 0;
6531: }
6532: }
6533: }
6534: }
6535: }
6536: }
6537: return $cancreate;
6538: }
6539:
1.20 raeburn 6540: sub can_modify_userinfo {
6541: my ($context,$dom,$fields,$userroles) = @_;
6542: my %domconfig =
6543: &Apache::lonnet::get_dom('configuration',['usermodification'],
6544: $dom);
6545: my %canmodify;
6546: if (ref($fields) eq 'ARRAY') {
6547: foreach my $field (@{$fields}) {
6548: $canmodify{$field} = 0;
6549: if (&Apache::lonnet::allowed('mau',$dom)) {
6550: $canmodify{$field} = 1;
6551: } else {
6552: if (ref($domconfig{'usermodification'}) eq 'HASH') {
6553: if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
6554: if (ref($userroles) eq 'ARRAY') {
6555: foreach my $role (@{$userroles}) {
6556: my $testrole;
1.60 raeburn 6557: if ($context eq 'selfcreate') {
6558: $testrole = $role;
1.20 raeburn 6559: } else {
1.60 raeburn 6560: if ($role =~ /^cr\//) {
6561: $testrole = 'cr';
6562: } else {
6563: $testrole = $role;
6564: }
1.20 raeburn 6565: }
6566: if (ref($domconfig{'usermodification'}{$context}{$testrole}) eq 'HASH') {
6567: if ($domconfig{'usermodification'}{$context}{$testrole}{$field}) {
6568: $canmodify{$field} = 1;
6569: last;
6570: }
6571: }
6572: }
6573: } else {
6574: foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
6575: if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
6576: if ($domconfig{'usermodification'}{$context}{$key}{$field}) {
6577: $canmodify{$field} = 1;
6578: last;
6579: }
6580: }
6581: }
6582: }
6583: }
6584: } elsif ($context eq 'course') {
6585: if (ref($userroles) eq 'ARRAY') {
6586: if (grep(/^st$/,@{$userroles})) {
6587: $canmodify{$field} = 1;
6588: }
6589: } else {
6590: $canmodify{$field} = 1;
6591: }
6592: }
6593: }
6594: }
6595: }
6596: return %canmodify;
6597: }
6598:
1.195 raeburn 6599: sub can_change_internalpass {
6600: my ($uname,$udom,$crstype,$permission) = @_;
6601: my $canchange;
6602: if (&Apache::lonnet::allowed('mau',$udom)) {
6603: $canchange = 1;
6604: } elsif ((ref($permission) eq 'HASH') && ($permission->{'mip'}) &&
6605: ($udom eq $env{'request.role.domain'})) {
6606: unless ($env{'course.'.$env{'request.course.id'}.'.internal.nopasswdchg'}) {
6607: my ($cnum,$cdom) = &get_course_identity();
6608: if ((&Apache::lonnet::is_course_owner($cdom,$cnum)) && ($udom eq $env{'user.domain'})) {
1.199 raeburn 6609: my @userstatuses = ('default');
6610: my %userenv = &Apache::lonnet::userenvironment($udom,$uname,'inststatus');
6611: if ($userenv{'inststatus'} ne '') {
6612: @userstatuses = split(/:/,$userenv{'inststatus'});
6613: }
6614: my $noupdate = 1;
6615: my %passwdconf = &Apache::lonnet::get_passwdconf($cdom);
6616: if (ref($passwdconf{'crsownerchg'}) eq 'HASH') {
6617: if (ref($passwdconf{'crsownerchg'}{'for'}) eq 'ARRAY') {
6618: foreach my $status (@userstatuses) {
6619: if (grep(/^\Q$status\E$/,@{$passwdconf{'crsownerchg'}{'for'}})) {
6620: undef($noupdate);
6621: last;
6622: }
6623: }
6624: }
6625: }
6626: if ($noupdate) {
6627: return;
6628: }
1.195 raeburn 6629: my %owned = &Apache::lonnet::courseiddump($cdom,'.',1,'.',
6630: $env{'user.name'}.':'.$env{'user.domain'},
6631: undef,undef,undef,'.');
6632: my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
6633: ['active','future']);
6634: foreach my $key (keys(%roleshash)) {
6635: my ($name,$domain,$role) = split(/:/,$key);
6636: if ($role eq 'st') {
6637: next if (($name eq $cnum) && ($domain eq $cdom));
6638: if ($owned{$domain.'_'.$name}) {
6639: if (ref($owned{$domain.'_'.$name}) eq 'HASH') {
6640: if ($owned{$domain.'_'.$name}{'nopasswdchg'}) {
6641: $noupdate = 1;
6642: last;
6643: }
6644: }
6645: } else {
6646: $noupdate = 1;
6647: last;
6648: }
6649: } else {
6650: $noupdate = 1;
6651: last;
6652: }
6653: }
6654: unless ($noupdate) {
6655: $canchange = 1;
6656: }
6657: }
6658: }
6659: }
6660: return $canchange;
6661: }
6662:
1.18 raeburn 6663: sub check_usertype {
1.134 raeburn 6664: my ($dom,$uname,$rules,$curr_rules,$got_rules) = @_;
1.18 raeburn 6665: my $usertype;
1.134 raeburn 6666: if ((ref($got_rules) eq 'HASH') && (ref($curr_rules) eq 'HASH')) {
6667: if (!$got_rules->{$dom}) {
6668: my %domconfig = &Apache::lonnet::get_dom('configuration',
6669: ['usercreation'],$dom);
6670: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6671: foreach my $item ('username','id') {
6672: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
6673: $curr_rules->{$dom}{$item} =
6674: $domconfig{'usercreation'}{$item.'_rule'};
6675: }
6676: }
6677: }
6678: $got_rules->{$dom} = 1;
6679: }
6680: if (ref($rules) eq 'HASH') {
6681: my @user_rules;
6682: if (ref($curr_rules->{$dom}{'username'}) eq 'ARRAY') {
6683: foreach my $rule (keys(%{$rules})) {
6684: if (grep(/^\Q$rule\E/,@{$curr_rules->{$dom}{'username'}})) {
6685: push(@user_rules,$rule);
6686: }
6687: }
6688: }
6689: if (@user_rules > 0) {
6690: my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
6691: if (keys(%rule_check) > 0) {
6692: $usertype = 'unofficial';
6693: foreach my $item (keys(%rule_check)) {
6694: if ($rule_check{$item}) {
6695: $usertype = 'official';
6696: last;
6697: }
1.18 raeburn 6698: }
6699: }
6700: }
6701: }
6702: }
6703: return $usertype;
6704: }
6705:
1.17 raeburn 6706: sub roles_by_context {
1.101 raeburn 6707: my ($context,$custom,$crstype) = @_;
1.17 raeburn 6708: my @allroles;
6709: if ($context eq 'course') {
1.99 raeburn 6710: @allroles = ('st');
6711: if ($env{'request.role'} =~ m{^dc\./}) {
6712: push(@allroles,'ad');
6713: }
1.101 raeburn 6714: push(@allroles,('ta','ep','in'));
6715: if ($crstype eq 'Community') {
6716: push(@allroles,'co');
6717: } else {
6718: push(@allroles,'cc');
6719: }
1.17 raeburn 6720: if ($custom) {
6721: push(@allroles,'cr');
6722: }
6723: } elsif ($context eq 'author') {
6724: @allroles = ('ca','aa');
6725: } elsif ($context eq 'domain') {
1.182 raeburn 6726: @allroles = ('li','ad','dg','dh','da','sc','au','dc');
1.17 raeburn 6727: }
6728: return @allroles;
6729: }
6730:
1.16 raeburn 6731: sub get_permission {
1.101 raeburn 6732: my ($context,$crstype) = @_;
1.16 raeburn 6733: my %permission;
6734: if ($context eq 'course') {
1.17 raeburn 6735: my $custom = 1;
1.101 raeburn 6736: my @allroles = &roles_by_context($context,$custom,$crstype);
1.17 raeburn 6737: foreach my $role (@allroles) {
6738: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
6739: $permission{'cusr'} = 1;
6740: last;
6741: }
1.16 raeburn 6742: }
6743: if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
6744: $permission{'custom'} = 1;
6745: }
6746: if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
6747: $permission{'view'} = 1;
6748: }
6749: if (!$permission{'view'}) {
6750: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
6751: $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
6752: if ($permission{'view'}) {
6753: $permission{'view_section'} = $env{'request.course.sec'};
6754: }
6755: }
1.17 raeburn 6756: if (!$permission{'cusr'}) {
6757: if ($env{'request.course.sec'} ne '') {
6758: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
6759: $permission{'cusr'} = (&Apache::lonnet::allowed('cst',$scope));
6760: if ($permission{'cusr'}) {
6761: $permission{'cusr_section'} = $env{'request.course.sec'};
6762: }
6763: }
6764: }
1.16 raeburn 6765: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
6766: $permission{'grp_manage'} = 1;
6767: }
1.165 raeburn 6768: if ($permission{'cusr'}) {
6769: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6770: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6771: my %coursehash = (
6772: 'internal.selfenrollmgrdc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrdc'},
6773: 'internal.selfenrollmgrcc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrcc'},
6774: 'internal.coursecode' => $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},
6775: 'internal.textbook' =>$env{'course.'.$env{'request.course.id'}.'.internal.textbook'},
6776: );
6777: my ($managed_by_cc,$managed_by_dc) = &selfenrollment_administration($cdom,$cnum,$crstype,\%coursehash);
6778: if (ref($managed_by_cc) eq 'ARRAY') {
6779: if (@{$managed_by_cc}) {
6780: $permission{'selfenrolladmin'} = 1;
6781: }
6782: }
1.216 ! raeburn 6783: unless ($permission{'selfenrolladmin'}) {
! 6784: $permission{'selfenrollview'} = 1;
! 6785: }
1.165 raeburn 6786: }
1.180 raeburn 6787: if ($env{'request.course.id'}) {
1.195 raeburn 6788: my $user;
6789: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
6790: $user = $env{'user.name'}.':'.$env{'user.domain'};
6791: }
1.180 raeburn 6792: if (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'} eq
6793: $user)) {
6794: $permission{'owner'} = 1;
1.195 raeburn 6795: if (&Apache::lonnet::allowed('mip',$env{'request.course.id'})) {
6796: $permission{'mip'} = 1;
6797: }
1.180 raeburn 6798: } elsif (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.co-owners'} ne '')) {
6799: if (grep(/^\Q$user\E$/,split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.co-owners'}))) {
6800: $permission{'co-owner'} = 1;
6801: }
6802: }
6803: }
1.16 raeburn 6804: } elsif ($context eq 'author') {
6805: $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
6806: $permission{'view'} = $permission{'cusr'};
6807: } else {
1.17 raeburn 6808: my @allroles = &roles_by_context($context);
6809: foreach my $role (@allroles) {
1.28 raeburn 6810: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
6811: $permission{'cusr'} = 1;
1.17 raeburn 6812: last;
6813: }
6814: }
6815: if (!$permission{'cusr'}) {
6816: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
6817: $permission{'cusr'} = 1;
6818: }
1.16 raeburn 6819: }
6820: if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
6821: $permission{'custom'} = 1;
6822: }
1.176 raeburn 6823: if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
6824: $permission{'activity'} = 1;
6825: }
1.178 raeburn 6826: if (&Apache::lonnet::allowed('vur',$env{'request.role.domain'})) {
6827: $permission{'view'} = 1;
6828: }
1.180 raeburn 6829: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
6830: $permission{'owner'} = 1;
6831: }
1.16 raeburn 6832: }
6833: my $allowed = 0;
1.211 raeburn 6834: foreach my $key (keys(%permission)) {
6835: next if (($key eq 'owner') || ($key eq 'co-owner'));
6836: if ($permission{$key}) { $allowed=1; last; }
1.16 raeburn 6837: }
6838: return (\%permission,$allowed);
6839: }
6840:
6841: # ==================================================== Figure out author access
6842:
6843: sub authorpriv {
6844: my ($auname,$audom)=@_;
6845: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
6846: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; } return 1;
6847: }
6848:
1.27 raeburn 6849: sub roles_on_upload {
1.101 raeburn 6850: my ($context,$setting,$crstype,%customroles) = @_;
1.27 raeburn 6851: my (@possible_roles,@permitted_roles);
1.101 raeburn 6852: @possible_roles = &curr_role_permissions($context,$setting,1,$crstype);
1.27 raeburn 6853: foreach my $role (@possible_roles) {
6854: if ($role eq 'cr') {
6855: push(@permitted_roles,keys(%customroles));
6856: } else {
6857: push(@permitted_roles,$role);
6858: }
6859: }
1.42 raeburn 6860: return @permitted_roles;
1.27 raeburn 6861: }
6862:
1.17 raeburn 6863: sub get_course_identity {
6864: my ($cid) = @_;
6865: my ($cnum,$cdom,$cdesc);
6866: if ($cid eq '') {
6867: $cid = $env{'request.course.id'}
6868: }
6869: if ($cid ne '') {
6870: $cnum = $env{'course.'.$cid.'.num'};
6871: $cdom = $env{'course.'.$cid.'.domain'};
6872: $cdesc = $env{'course.'.$cid.'.description'};
6873: if ($cnum eq '' || $cdom eq '') {
6874: my %coursehash =
6875: &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
6876: $cdom = $coursehash{'domain'};
6877: $cnum = $coursehash{'num'};
6878: $cdesc = $coursehash{'description'};
6879: }
6880: }
6881: return ($cnum,$cdom,$cdesc);
6882: }
6883:
1.19 raeburn 6884: sub dc_setcourse_js {
1.196 raeburn 6885: my ($formname,$mode,$context,$showcredits,$domain) = @_;
1.37 raeburn 6886: my ($dc_setcourse_code,$authen_check);
1.19 raeburn 6887: my $cctext = &Apache::lonnet::plaintext('cc');
1.103 raeburn 6888: my $cotext = &Apache::lonnet::plaintext('co');
1.19 raeburn 6889: my %alerts = §ioncheck_alerts();
6890: my $role = 'role';
6891: if ($mode eq 'upload') {
6892: $role = 'courserole';
1.37 raeburn 6893: } else {
1.196 raeburn 6894: $authen_check = &verify_authen($formname,$context,$domain);
1.19 raeburn 6895: }
6896: $dc_setcourse_code = (<<"SCRIPTTOP");
1.37 raeburn 6897: $authen_check
6898:
1.19 raeburn 6899: function setCourse() {
6900: var course = document.$formname.dccourse.value;
6901: if (course != "") {
6902: if (document.$formname.dcdomain.value != document.$formname.origdom.value) {
6903: alert("$alerts{'curd'}");
6904: return;
6905: }
6906: var userrole = document.$formname.$role.options[document.$formname.$role.selectedIndex].value
6907: var section="";
6908: var numsections = 0;
6909: var newsecs = new Array();
6910: for (var i=0; i<document.$formname.currsec.length; i++) {
6911: if (document.$formname.currsec.options[i].selected == true ) {
6912: if (document.$formname.currsec.options[i].value != "" && document.$formname.currsec.options[i].value != null) {
6913: if (numsections == 0) {
6914: section = document.$formname.currsec.options[i].value
6915: numsections = 1;
6916: }
6917: else {
6918: section = section + "," + document.$formname.currsec.options[i].value
6919: numsections ++;
6920: }
6921: }
6922: }
6923: }
6924: if (document.$formname.newsec.value != "" && document.$formname.newsec.value != null) {
6925: if (numsections == 0) {
6926: section = document.$formname.newsec.value
6927: }
6928: else {
6929: section = section + "," + document.$formname.newsec.value
6930: }
6931: newsecs = document.$formname.newsec.value.split(/,/g);
6932: numsections = numsections + newsecs.length;
6933: }
6934: if ((userrole == 'st') && (numsections > 1)) {
1.103 raeburn 6935: if (document.$formname.crstype.value == 'Community') {
6936: alert("$alerts{'inco'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
6937: } else {
6938: alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
6939: }
1.19 raeburn 6940: return;
6941: }
6942: for (var j=0; j<newsecs.length; j++) {
6943: if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
6944: alert("'"+newsecs[j]+"' $alerts{'mayn'}.\\n$alerts{'plsc'}.");
6945: return;
6946: }
6947: if (document.$formname.groups.value != '') {
6948: var groups = document.$formname.groups.value.split(/,/g);
6949: for (var k=0; k<groups.length; k++) {
6950: if (newsecs[j] == groups[k]) {
1.103 raeburn 6951: if (document.$formname.crstype.value == 'Community') {
6952: alert("'"+newsecs[j]+"' $alerts{'mayc'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
6953: } else {
6954: alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
6955: }
1.19 raeburn 6956: return;
6957: }
6958: }
6959: }
6960: }
6961: if ((userrole == 'cc') && (numsections > 0)) {
6962: alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
6963: section = "";
6964: }
1.103 raeburn 6965: if ((userrole == 'co') && (numsections > 0)) {
6966: alert("$alerts{'secd'} $cotext $alerts{'role'}.\\n$alerts{'accr'}.");
6967: section = "";
6968: }
1.19 raeburn 6969: SCRIPTTOP
6970: if ($mode ne 'upload') {
1.150 raeburn 6971: $dc_setcourse_code .= (<<"SCRIPTMID");
1.19 raeburn 6972: var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
6973: var numcourse = getIndex(document.$formname.dccourse);
6974: if (numcourse == "-1") {
1.103 raeburn 6975: if (document.$formname.type == 'Community') {
6976: alert("$alerts{'thwc'}");
6977: } else {
6978: alert("$alerts{'thwa'}");
6979: }
1.19 raeburn 6980: return;
6981: }
6982: else {
6983: document.$formname.elements[numcourse].name = "act"+coursename;
6984: var numnewsec = getIndex(document.$formname.newsec);
6985: if (numnewsec != "-1") {
6986: document.$formname.elements[numnewsec].name = "sec"+coursename;
6987: document.$formname.elements[numnewsec].value = section;
6988: }
6989: var numstart = getIndex(document.$formname.start);
6990: if (numstart != "-1") {
6991: document.$formname.elements[numstart].name = "start"+coursename;
6992: }
6993: var numend = getIndex(document.$formname.end);
6994: if (numend != "-1") {
6995: document.$formname.elements[numend].name = "end"+coursename
6996: }
1.150 raeburn 6997: SCRIPTMID
6998: if ($showcredits) {
6999: $dc_setcourse_code .= <<ENDCRED;
7000: var numcredits = getIndex(document.$formname.credits);
7001: if (numcredits != "-1") {
7002: document.$formname.elements[numcredits].name = "credits"+coursename;
7003: }
7004: ENDCRED
7005: }
7006: $dc_setcourse_code .= <<ENDSCRIPT;
1.19 raeburn 7007: }
7008: }
1.37 raeburn 7009: var authcheck = auth_check();
7010: if (authcheck == 'ok') {
7011: document.$formname.submit();
7012: }
1.19 raeburn 7013: }
7014: ENDSCRIPT
7015: } else {
7016: $dc_setcourse_code .= "
7017: document.$formname.sections.value = section;
7018: }
7019: return 'ok';
7020: }
7021: ";
7022: }
7023: $dc_setcourse_code .= (<<"ENDSCRIPT");
7024:
7025: function getIndex(caller) {
7026: for (var i=0;i<document.$formname.elements.length;i++) {
7027: if (document.$formname.elements[i] == caller) {
7028: return i;
7029: }
7030: }
7031: return -1;
7032: }
7033: ENDSCRIPT
1.37 raeburn 7034: return $dc_setcourse_code;
7035: }
7036:
7037: sub verify_authen {
1.196 raeburn 7038: my ($formname,$context,$domain) = @_;
1.37 raeburn 7039: my %alerts = &authcheck_alerts();
7040: my $finish = "return 'ok';";
7041: if ($context eq 'author') {
7042: $finish = "document.$formname.submit();";
7043: }
1.196 raeburn 7044: my ($numrules,$intargjs) =
1.210 raeburn 7045: &Apache::loncommon::passwd_validation_js('argpicked',$domain);
1.37 raeburn 7046: my $outcome = <<"ENDSCRIPT";
7047:
7048: function auth_check() {
7049: var logintype;
7050: if (document.$formname.login.length) {
7051: if (document.$formname.login.length > 0) {
7052: var loginpicked = 0;
7053: for (var i=0; i<document.$formname.login.length; i++) {
7054: if (document.$formname.login[i].checked == true) {
7055: loginpicked = 1;
7056: logintype = document.$formname.login[i].value;
7057: }
7058: }
7059: if (loginpicked == 0) {
7060: alert("$alerts{'authen'}");
7061: return;
7062: }
7063: }
7064: } else {
7065: logintype = document.$formname.login.value;
7066: }
7067: if (logintype == 'nochange') {
7068: return 'ok';
7069: }
7070: var argpicked = document.$formname.elements[logintype+'arg'].value;
7071: if ((argpicked == null) || (argpicked == '') || (typeof argpicked == 'undefined')) {
7072: var alertmsg = '';
7073: switch (logintype) {
7074: case 'krb':
7075: alertmsg = '$alerts{'krb'}';
7076: break;
7077: case 'int':
7078: alertmsg = '$alerts{'ipass'}';
1.196 raeburn 7079: break;
1.37 raeburn 7080: case 'fsys':
7081: alertmsg = '$alerts{'ipass'}';
7082: break;
7083: case 'loc':
7084: alertmsg = '';
7085: break;
7086: default:
7087: alertmsg = '';
7088: }
7089: if (alertmsg != '') {
7090: alert(alertmsg);
7091: return;
7092: }
1.196 raeburn 7093: } else if (logintype == 'int') {
7094: var numrules = $numrules;
7095: if (numrules > 0) {
7096: $intargjs
7097: }
1.37 raeburn 7098: }
7099: $finish
7100: }
7101: ENDSCRIPT
1.19 raeburn 7102: }
7103:
7104: sub sectioncheck_alerts {
7105: my %alerts = &Apache::lonlocal::texthash(
1.103 raeburn 7106: curd => 'You must select a course or community in the current domain',
1.19 raeburn 7107: inea => 'In each course, each user may only have one student role at a time',
1.103 raeburn 7108: inco => 'In each community, each user may only have one member role at a time',
1.19 raeburn 7109: youh => 'You had selected',
7110: sect => 'sections',
7111: plsm => 'Please modify your selections so they include no more than one section',
7112: mayn => 'may not be used as the name for a section, as it is a reserved word',
7113: plsc => 'Please choose a different section name',
7114: mayt => 'may not be used as the name for a section, as it is the name of a course group',
1.103 raeburn 7115: mayc => 'may not be used as the name for a section, as it is the name of a community group',
1.19 raeburn 7116: secn => 'Section names and group names must be distinct',
7117: secd => 'Section designations do not apply to ',
7118: role => 'roles',
7119: accr => 'role will be added with access to all sections',
1.103 raeburn 7120: thwa => 'There was a problem with your course selection',
7121: thwc => 'There was a problem with your community selection',
1.19 raeburn 7122: );
1.170 damieng 7123: &js_escape(\%alerts);
1.19 raeburn 7124: return %alerts;
7125: }
1.17 raeburn 7126:
1.37 raeburn 7127: sub authcheck_alerts {
7128: my %alerts =
7129: &Apache::lonlocal::texthash(
7130: authen => 'You must choose an authentication type.',
7131: krb => 'You need to specify the Kerberos domain.',
7132: ipass => 'You need to specify the initial password.',
7133: );
1.170 damieng 7134: &js_escape(\%alerts);
1.37 raeburn 7135: return %alerts;
7136: }
7137:
1.141 raeburn 7138: sub is_courseowner {
7139: my ($thiscourse,$courseowner) = @_;
7140: if ($courseowner eq '') {
7141: if ($env{'request.course.id'} eq $thiscourse) {
7142: $courseowner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
7143: }
7144: }
7145: if ($courseowner ne '') {
7146: if ($courseowner eq $env{'user.name'}.':'.$env{'user.domain'}) {
7147: return 1;
7148: }
7149: }
7150: return;
7151: }
7152:
1.165 raeburn 7153: sub get_selfenroll_titles {
7154: my @row = ('types','registered','enroll_dates','access_dates','section',
7155: 'approval','limit');
7156: my %lt = &Apache::lonlocal::texthash (
7157: types => 'Users allowed to self-enroll',
7158: registered => 'Registration status (official courses)' ,
7159: enroll_dates => 'Dates self-enrollment available',
7160: access_dates => 'Access dates for self-enrolling users',
7161: section => "Self-enrolling users' section",
7162: approval => 'Processing of requests',
7163: limit => 'Enrollment limit',
7164: );
7165: return (\@row,\%lt);
7166: }
7167:
7168: sub selfenroll_default_descs {
7169: my %desc = (
7170: types => {
7171: dom => &mt('Course domain'),
7172: all => &mt('Any domain'),
7173: '' => &mt('None'),
7174: },
7175: limit => {
7176: none => &mt('No limit'),
7177: allstudents => &mt('Limit by total students'),
7178: selfenrolled => &mt('Limit by total self-enrolled'),
7179: },
7180: approval => {
7181: '0' => &mt('Processed automatically'),
7182: '1' => &mt('Queued for approval'),
7183: '2' => &mt('Queued, pending validation'),
7184: },
7185: registered => {
7186: 0 => 'No registration required',
7187: 1 => 'Registered students only',
7188: },
7189: );
7190: return %desc;
7191: }
7192:
7193: sub selfenroll_validation_types {
7194: my @items = ('url','fields','button','markup');
7195: my %names = &Apache::lonlocal::texthash (
7196: url => 'Web address of validation server/script',
7197: fields => 'Form fields to send to validator',
7198: button => 'Text for validation button',
7199: markup => 'Validation description (HTML)',
7200: );
1.167 raeburn 7201: my @fields = ('username','domain','uniquecode','course','coursetype','description');
1.165 raeburn 7202: return (\@items,\%names,\@fields);
7203: }
7204:
7205: sub get_extended_type {
7206: my ($cdom,$cnum,$crstype,$current) = @_;
7207: my $type = 'unofficial';
7208: my %settings;
7209: if (ref($current) eq 'HASH') {
7210: %settings = %{$current};
7211: } else {
7212: %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook'],$cdom,$cnum);
7213: }
7214: if ($crstype eq 'Community') {
7215: $type = 'community';
1.173 raeburn 7216: } elsif ($crstype eq 'Placement') {
7217: $type = 'placement';
1.165 raeburn 7218: } elsif ($settings{'internal.coursecode'}) {
7219: $type = 'official';
7220: } elsif ($settings{'internal.textbook'}) {
7221: $type = 'textbook';
7222: }
7223: return $type;
7224: }
7225:
7226: sub selfenrollment_administration {
7227: my ($cdom,$cnum,$crstype,$coursehash) = @_;
7228: my %settings;
7229: if (ref($coursehash) eq 'HASH') {
7230: %settings = %{$coursehash};
7231: } else {
7232: %settings = &Apache::lonnet::get('environment',
7233: ['internal.selfenrollmgrdc','internal.selfenrollmgrcc',
7234: 'internal.coursecode','internal.textbook'],$cdom,$cnum);
7235: }
7236: my ($possconfigs) = &get_selfenroll_titles();
7237: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
7238: my $selfenrolltype = &get_extended_type($cdom,$cnum,$crstype,\%settings);
7239:
7240: my (@in_course,@in_domain);
7241: if ($settings{'internal.selfenrollmgrcc'} ne '') {
7242: @in_course = split(/,/,$settings{'internal.selfenrollmgrcc'});
7243: my @diffs = &Apache::loncommon::compare_arrays($possconfigs,\@in_course);
7244: unless (@diffs) {
7245: return (\@in_course,\@in_domain);
7246: }
7247: }
7248: if ($settings{'internal.selfenrollmgrdc'} ne '') {
1.215 raeburn 7249: @in_domain = split(/,/,$settings{'internal.selfenrollmgrdc'});
1.165 raeburn 7250: my @diffs = &Apache::loncommon::compare_arrays(\@in_domain,$possconfigs);
7251: unless (@diffs) {
7252: return (\@in_course,\@in_domain);
7253: }
7254: }
7255: my @combined = @in_course;
7256: push(@combined,@in_domain);
7257: my @diffs = &Apache::loncommon::compare_arrays(\@combined,$possconfigs);
7258: unless (@diffs) {
7259: return (\@in_course,\@in_domain);
7260: }
7261: if ($domdefaults{$selfenrolltype.'selfenrolladmdc'} eq '') {
7262: push(@in_course,@diffs);
7263: } else {
7264: my @defaultdc = split(/,/,$domdefaults{$selfenrolltype.'selfenrolladmdc'});
7265: foreach my $item (@diffs) {
7266: if (grep(/^\Q$item\E$/,@defaultdc)) {
7267: push(@in_domain,$item);
7268: } else {
7269: push(@in_course,$item);
7270: }
7271: }
7272: }
7273: return (\@in_course,\@in_domain);
7274: }
7275:
1.175 raeburn 7276: sub custom_role_header {
7277: my ($context,$crstype,$templaterolerefs,$prefix) = @_;
7278: my %lt = &Apache::lonlocal::texthash(
7279: sele => 'Select a Template',
7280: );
7281: my ($context_code,$button_code);
7282: if ($context eq 'domain') {
7283: $context_code = &custom_coursetype_switch($crstype,$prefix);
7284: }
7285: if (ref($templaterolerefs) eq 'ARRAY') {
7286: foreach my $role (@{$templaterolerefs}) {
7287: my $display = 'inline';
7288: if (($context eq 'domain') && ($role eq 'co')) {
7289: $display = 'none';
7290: }
7291: $button_code .= &make_button_code($role,$crstype,$display,$prefix).' ';
7292: }
7293: }
7294: return <<"END";
7295: <div class="LC_left_float">
7296: <fieldset>
7297: <legend>$lt{'sele'}</legend>
7298: $button_code
7299: </fieldset></div>
7300: $context_code
7301: <br clear="all" />
7302: END
7303: }
7304:
7305: sub custom_coursetype_switch {
7306: my ($crstype,$prefix) = @_;
7307: my ($checkedcourse,$checkedcommunity);
7308: if ($crstype eq 'Community') {
7309: $checkedcommunity = ' checked="checked"';
7310: } else {
7311: $checkedcourse = ' checked="checked"';
7312: }
7313: my %lt = &Apache::lonlocal::texthash(
7314: cont => 'Context',
7315: cour => 'Course',
7316: comm => 'Community',
7317: );
7318: return <<"END";
7319: <div class="LC_left_float">
7320: <fieldset>
7321: <legend>$lt{'cont'}</legend>
7322: <label>
7323: <input type="radio" name="${prefix}_custrolecrstype" value="Course"$checkedcourse onclick="javascript:customSwitchType('$prefix');" />
7324: $lt{'cour'}
7325: </label>
7326: <label>
7327: <input type="radio" name="${prefix}_custrolecrstype" value="Community"$checkedcommunity onclick="javascript:customSwitchType('$prefix');" />
7328: $lt{'comm'}
7329: </label>
7330: </fieldset>
7331: </div>
7332: END
7333: }
7334:
7335: sub custom_role_table {
1.180 raeburn 7336: my ($crstype,$full,$levels,$levelscurrent,$prefix,$add_class,$id) = @_;
1.175 raeburn 7337: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7338: (ref($levelscurrent) eq 'HASH'));
7339: my %lt=&Apache::lonlocal::texthash (
7340: 'prv' => "Privilege",
7341: 'crl' => "Course Level",
7342: 'dml' => "Domain Level",
7343: 'ssl' => "System Level");
7344: my %cr = (
7345: course => '_c',
7346: domain => '_d',
7347: system => '_s',
7348: );
7349:
1.180 raeburn 7350: my $output=&Apache::loncommon::start_data_table($add_class,$id).
1.175 raeburn 7351: &Apache::loncommon::start_data_table_header_row().
7352: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
7353: '</th><th>'.$lt{'ssl'}.'</th>'.
7354: &Apache::loncommon::end_data_table_header_row();
7355: foreach my $priv (sort(keys(%{$full}))) {
7356: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7357: $output .= &Apache::loncommon::start_data_table_row().
7358: '<td><span id="'.$prefix.$priv.'">'.$privtext.'</span></td>';
7359: foreach my $type ('course','domain','system') {
7360: if (($type eq 'system') && ($priv eq 'bre') && ($crstype eq 'Community')) {
7361: $output .= '<td> </td>';
7362: } else {
7363: $output .= '<td>'.
7364: ($levels->{$type}{$priv}?'<input type="checkbox" id="'.$prefix.$priv.$cr{$type}.'"'.
7365: ' name="'.$prefix.$priv.$cr{$type}.'"'.
7366: ($levelscurrent->{$type}{$priv}?' checked="checked"':'').' />':' ').
7367: '</td>';
7368: }
7369: }
7370: $output .= &Apache::loncommon::end_data_table_row();
7371: }
7372: $output .= &Apache::loncommon::end_data_table();
7373: return $output;
7374: }
7375:
7376: sub custom_role_privs {
7377: my ($privs,$full,$levels,$levelscurrent)= @_;
7378: return unless ((ref($privs) eq 'HASH') && (ref($full) eq 'HASH') &&
7379: (ref($levels) eq 'HASH') && (ref($levelscurrent) eq 'HASH'));
7380: my %cr = (
7381: course => 'cr:c',
7382: domain => 'cr:d',
7383: system => 'cr:s',
7384: );
7385: foreach my $type ('course','domain','system') {
7386: foreach my $item (split(/\:/,$Apache::lonnet::pr{$cr{$type}})) {
7387: my ($priv,$restrict)=split(/\&/,$item);
7388: if (!$restrict) { $restrict='F'; }
7389: $levels->{$type}->{$priv}=$restrict;
7390: if ($privs->{$type}=~/\:$priv/) {
7391: $levelscurrent->{$type}->{$priv}=1;
7392: }
7393: $full->{$priv}=1;
7394: }
7395: }
7396: return;
7397: }
7398:
7399: sub custom_template_roles {
7400: my ($context,$crstype) = @_;
7401: my @template_roles = ("in","ta","ep");
7402: if (($context eq 'domain') || ($context eq 'domprefs')) {
7403: push(@template_roles,"ad");
7404: }
7405: push(@template_roles,"st");
7406: if ($context eq 'domain') {
7407: unshift(@template_roles,('co','cc'));
7408: } else {
7409: if ($crstype eq 'Community') {
7410: unshift(@template_roles,'co');
7411: } else {
7412: unshift(@template_roles,'cc');
7413: }
7414: }
7415: return @template_roles;
7416: }
7417:
7418: sub custom_roledefs_js {
7419: my ($context,$crstype,$formname,$full,$templaterolesref,$jsback) = @_;
7420: my $button_code = "\n";
7421: my $head_script = "\n";
7422: my (%roletitlestr,$rolenamestr);
7423: my %role_titles = (
7424: Course => [],
7425: Community => [],
7426: );
7427: $head_script .= '<script type="text/javascript">'."\n"
7428: .'// <![CDATA['."\n";
7429: if (ref($templaterolesref) eq 'ARRAY') {
7430: if ($context eq 'domain') {
7431: $rolenamestr = join("','",@{$templaterolesref});
7432: }
7433: foreach my $role (@{$templaterolesref}) {
7434: $head_script .= &make_script_template($role,$crstype,$formname);
7435: if ($context eq 'domain') {
7436: foreach my $type ('Course','Community') {
7437: push(@{$role_titles{$type}},&Apache::lonnet::plaintext($role,$type));
7438: }
7439: }
7440: }
7441: }
7442: if ($context eq 'domain') {
7443: foreach my $type ('Course','Community') {
7444: $roletitlestr{$type} = join("','",@{$role_titles{$type}});
7445: }
7446: my %pt = (
7447: Community => {
7448: cst => &mt('Grant/revoke role of Member'),
7449: mdc => &mt('Edit community contents'),
7450: pch => &mt('Post discussion on community resources'),
7451: pfo => &mt('Print for other users and entire community'),
7452: },
7453: Course => {
7454: cst => &mt('Grant/revoke role of Student'),
7455: mdc => &mt('Edit course contents'),
7456: pch => &mt('Post discussion on course resources'),
7457: pfo => &mt('Print for other users and entire course'),
7458: },
7459: );
7460: $head_script .= <<"ENDJS";
7461: function customSwitchType(prefix) {
7462: var privnames = new Array('cst','mdc','pch','pfo');
7463: var privtxtcrs = new Array('$pt{Course}{cst}','$pt{Course}{mdc}','$pt{Course}{pch}','$pt{Course}{pfo}');
7464: var privtxtcom = new Array('$pt{Community}{cst}','$pt{Community}{mdc}','$pt{Community}{pch}','$pt{Community}{pfo}');
7465: var rolenames = new Array('$rolenamestr');
7466: var rolescrs = new Array('$roletitlestr{Course}');
7467: var rolescom = new Array('$roletitlestr{Community}');
7468: var radio = prefix+'_custrolecrstype';
7469: if (document.$formname.elements[radio].length > 1) {
7470: for (var i=0; i<document.$formname.elements[radio].length; i++) {
7471: if (document.$formname.elements[radio][i].checked) {
7472: if ((document.getElementById(prefix+'bre_s')) && (document.getElementById(prefix+'bro_s'))) {
7473: if (document.$formname.elements[radio][i].value == 'Community') {
7474: if (document.getElementById(prefix+'bre_s').checked) {
7475: document.getElementById(prefix+'bro_s').checked = true;
7476: document.getElementById(prefix+'bre_s').checked = false;
7477:
7478: }
7479: document.getElementById(prefix+'bre_s').style.visibility = 'hidden';
7480: } else {
7481: document.getElementById(prefix+'bre_s').style.visibility = 'visible';
7482: if (document.getElementById(prefix+'bro_s').checked) {
7483: document.getElementById(prefix+'bre_s').checked = true;
7484: document.getElementById(prefix+'bro_s').checked = false;
7485: }
7486: }
7487: }
7488: for (var j=0; j<privnames.length; j++) {
7489: if (document.getElementById(prefix+privnames[j])) {
7490: if (document.getElementById(prefix+privnames[j])) {
7491: if (document.$formname.elements[radio][i].value == 'Course') {
7492: document.getElementById(prefix+privnames[j]).innerHTML = privtxtcrs[j];
7493: } else {
7494: document.getElementById(prefix+privnames[j]).innerHTML = privtxtcom[j];
7495: }
7496: }
7497: }
7498: }
7499: for (var j=0; j<rolenames.length; j++) {
7500: if (document.getElementById(prefix+rolenames[j])) {
7501: if (document.getElementById(prefix+rolenames[j])) {
7502: if (document.$formname.elements[radio][i].value == 'Course') {
7503: document.getElementById(prefix+rolenames[j]).value = rolescrs[j];
7504: if (rolenames[j] == 'cc') {
7505: document.getElementById(prefix+rolenames[j]).style.display = 'inline';
7506: }
7507: if (rolenames[j] == 'co') {
7508: document.getElementById(prefix+rolenames[j]).style.display = 'none';
7509: }
7510: } else {
7511: document.getElementById(prefix+rolenames[j]).value = rolescom[j];
7512: if (rolenames[j] == 'cc') {
7513: document.getElementById(prefix+rolenames[j]).style.display = 'none';
7514: }
7515: if (rolenames[j] == 'co') {
7516: document.getElementById(prefix+rolenames[j]).style.display = 'inline';
7517: }
7518: }
7519: }
7520: }
7521: }
7522: }
7523: }
7524: }
7525: return;
7526: }
7527: ENDJS
7528: }
7529: $head_script .= "\n".$jsback."\n"
7530: .'// ]]>'."\n"
7531: .'</script>'."\n";
7532: return $head_script;
7533: }
7534:
7535: # --------------------------------------------------------
7536: sub make_script_template {
7537: my ($role,$crstype,$formname) = @_;
7538: my $return_script = 'function set_'.$role.'(prefix) {'."\n";
7539: my (%full_by_level,%role_priv);
7540: foreach my $level ('c','d','s') {
7541: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
7542: next if (($level eq 's') && ($crstype eq 'Community') && ($item eq 'bre&S'));
7543: my ($priv,$restrict)=split(/\&/,$item);
7544: $full_by_level{$level}{$priv}=1;
7545: }
7546: $role_priv{$level} = {};
7547: my @temp = split(/:/,$Apache::lonnet::pr{$role.':'.$level});
7548: foreach my $priv (@temp) {
7549: my ($priv_item, $dummy) = split(/\&/,$priv);
7550: $role_priv{$level}{$priv_item} = 1;
7551: }
7552: }
7553: my %to_check = (
7554: c => ['c','d','s'],
7555: d => ['d','s'],
7556: s => ['s'],
7557: );
7558: foreach my $level ('c','d','s') {
7559: if (ref($full_by_level{$level}) eq 'HASH') {
7560: foreach my $priv (keys(%{$full_by_level{$level}})) {
7561: my $value = 'false';
7562: if (ref($to_check{$level}) eq 'ARRAY') {
7563: foreach my $lett (@{$to_check{$level}}) {
7564: if (exists($role_priv{$lett}{$priv})) {
7565: $value = 'true';
7566: last;
7567: }
7568: }
7569: $return_script .= "document.$formname.elements[prefix+'".$priv."_".$level."'].checked = $value;\n";
7570: }
7571: }
7572: }
7573: }
7574: $return_script .= '}'."\n";
7575: return ($return_script);
7576: }
7577: # ----------------------------------------------------------
7578: sub make_button_code {
7579: my ($role,$crstype,$display,$prefix) = @_;
7580: my $label = &Apache::lonnet::plaintext($role,$crstype);
7581: my $button_code = '<input type="button" onclick="set_'.$role."('$prefix'".')" '.
7582: 'id="'.$prefix.$role.'" value="'.$label.'" '.
7583: 'style="display:'.$display.'" />';
7584: return ($button_code);
7585: }
7586:
7587: sub custom_role_update {
7588: my ($rolename,$prefix) = @_;
7589: # ------------------------------------------------------- What can be assigned?
7590: my %privs = (
7591: c => '',
7592: d => '',
7593: s => '',
7594: );
7595: foreach my $level (keys(%privs)) {
7596: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
7597: my ($priv,$restrict)=split(/\&/,$item);
7598: if (!$restrict) { $restrict=''; }
7599: if ($env{'form.'.$prefix.$priv.'_'.$level}) {
7600: $privs{$level} .=':'.$item;
7601: }
7602: }
7603: }
7604: return %privs;
7605: }
7606:
1.180 raeburn 7607: sub adhoc_status_types {
7608: my ($cdom,$context,$role,$selectedref,$othertitle,$usertypes,$types,$disabled) = @_;
7609: my $output = &Apache::loncommon::start_data_table();
7610: my $numinrow = 3;
7611: my $rem;
7612: if (ref($types) eq 'ARRAY') {
7613: for (my $i=0; $i<@{$types}; $i++) {
7614: if (defined($usertypes->{$types->[$i]})) {
7615: my $rem = $i%($numinrow);
7616: if ($rem == 0) {
7617: if ($i > 0) {
7618: $output .= &Apache::loncommon::end_data_table_row();
7619: }
7620: $output .= &Apache::loncommon::start_data_table_row();
7621: }
7622: my $check;
7623: if (ref($selectedref) eq 'ARRAY') {
7624: if (grep(/^\Q$types->[$i]\E$/,@{$selectedref})) {
7625: $check = ' checked="checked"';
7626: }
7627: }
7628: $output .= '<td>'.
7629: '<span class="LC_nobreak"><label>'.
7630: '<input type="checkbox" name="'.$context.$role.'_status" '.
7631: 'value="'.$types->[$i].'"'.$check.$disabled.' />'.
7632: $usertypes->{$types->[$i]}.'</label></span></td>';
7633: }
7634: }
7635: $rem = @{$types}%($numinrow);
7636: }
7637: my $colsleft = $numinrow - $rem;
7638: if (($rem == 0) && (@{$types} > 0)) {
7639: $output .= &Apache::loncommon::start_data_table_row();
7640: }
7641: if ($colsleft > 1) {
7642: $output .= '<td colspan="'.$colsleft.'">';
7643: } else {
7644: $output .= '<td>';
7645: }
7646: my $defcheck;
7647: if (ref($selectedref) eq 'ARRAY') {
7648: if (grep(/^default$/,@{$selectedref})) {
7649: $defcheck = ' checked="checked"';
7650: }
7651: }
7652: $output .= '<span class="LC_nobreak"><label>'.
7653: '<input type="checkbox" name="'.$context.$role.'_status"'.
7654: 'value="default"'.$defcheck.$disabled.' />'.
7655: $othertitle.'</label></span></td>'.
7656: &Apache::loncommon::end_data_table_row().
7657: &Apache::loncommon::end_data_table();
7658: return $output;
7659: }
7660:
7661: sub adhoc_staff {
7662: my ($access,$context,$role,$selectedref,$adhocref,$disabled) = @_;
7663: my $output;
7664: if (ref($adhocref) eq 'HASH') {
7665: my %by_fullname;
7666: my $numinrow = 4;
7667: my $rem;
7668: my @personnel = keys(%{$adhocref});
7669: if (@personnel) {
7670: foreach my $person (@personnel) {
7671: my ($uname,$udom) = split(/:/,$person);
7672: my $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
7673: $by_fullname{$fullname} = $person;
7674: }
7675: my @sorted = sort(keys(%by_fullname));
7676: my $count = scalar(@sorted);
7677: $output = &Apache::loncommon::start_data_table();
7678: for (my $i=0; $i<$count; $i++) {
7679: my $rem = $i%($numinrow);
7680: if ($rem == 0) {
7681: if ($i > 0) {
7682: $output .= &Apache::loncommon::end_data_table_row();
7683: }
7684: $output .= &Apache::loncommon::start_data_table_row();
7685: }
7686: my $check;
7687: my $user = $by_fullname{$sorted[$i]};
7688: if (ref($selectedref) eq 'ARRAY') {
7689: if (grep(/^\Q$user\E$/,@{$selectedref})) {
7690: $check = ' checked="checked"';
7691: }
7692: }
7693: if ($i == $count-1) {
7694: my $colsleft = $numinrow - $rem;
7695: if ($colsleft > 1) {
7696: $output .= '<td colspan="'.$colsleft.'">';
7697: } else {
7698: $output .= '<td>';
7699: }
7700: } else {
7701: $output .= '<td>';
7702: }
7703: $output .= '<span class="LC_nobreak"><label>'.
7704: '<input type="checkbox" name="'.$context.$role.'_staff_'.$access.'" '.
7705: 'value="'.$user.'"'.$check.$disabled.' />'.$sorted[$i].
7706: '</label></span></td>';
7707: if ($i == $count-1) {
7708: $output .= &Apache::loncommon::end_data_table_row();
7709: }
7710: }
7711: $output .= &Apache::loncommon::end_data_table();
7712: }
7713: }
7714: return $output;
7715: }
7716:
7717:
1.1 raeburn 7718: 1;
7719:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>