Annotation of loncom/interface/lonuserutils.pm, revision 1.222
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
1.222 ! raeburn 4: # $Id: lonuserutils.pm,v 1.221 2024/01/05 04:01:40 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.220 raeburn 107: $end,$start,$checkid,$inststatus,$emptyok) = @_;
1.5 raeburn 108: my ($scope,$userresult,$authresult,$roleresult,$idresult);
1.1 raeburn 109: if ($setting eq 'course' || $context eq 'course') {
110: $scope = '/'.$cid;
111: $scope =~ s/\_/\//g;
1.103 raeburn 112: if (($role ne 'cc') && ($role ne 'co') && ($sec ne '')) {
1.1 raeburn 113: $scope .='/'.$sec;
114: }
1.5 raeburn 115: } elsif ($context eq 'domain') {
1.1 raeburn 116: $scope = '/'.$env{'request.role.domain'}.'/';
1.13 raeburn 117: } elsif ($context eq 'author') {
1.218 raeburn 118: if ($env{'request.role'} =~ m{^ca\.(/$match_domain/$match_username)$}) {
119: $scope = $1;
120: } else {
121: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
122: }
1.1 raeburn 123: }
124: if ($context eq 'domain') {
125: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
126: if ($uhome ne 'no_host') {
1.5 raeburn 127: if (($changeauth eq 'Yes') && (&Apache::lonnet::allowed('mau',$udom))) {
1.1 raeburn 128: if ((($umode =~ /^krb4|krb5|internal$/) && $upass ne '') ||
129: ($umode eq 'localauth')) {
130: $authresult = &Apache::lonnet::modifyuserauth($udom,$uname,$umode,$upass);
131: }
132: }
1.5 raeburn 133: if (($forceid) && (&Apache::lonnet::allowed('mau',$udom)) &&
134: ($env{'form.recurseid'}) && ($checkid)) {
135: my %userupdate = (
136: lastname => $last,
137: middlename => $middle,
138: firstname => $first,
139: generation => $gene,
140: id => $uid,
141: );
1.220 raeburn 142:
143: # When "Update ID in user's course(s)" and "Force change of existing ID"
144: # checkboxes both checked, prevent replacement of name information
145: # in classlist.db file(s) for the user's course(s) with blank(s),
146: # in the case where the uploaded csv file was without column(s) for
147: # the particular field. Fields are: First Name, Middle Names/Initials,
148: # Last Name (or the composite: Last Name, First Names), and Generation.
149:
150: my %emptyallowed;
151: if ((ref($emptyok) eq 'HASH') && (keys(%{$emptyok}) > 0)) {
152: %emptyallowed = %{$emptyok};
153: }
154: foreach my $field (keys(%userupdate)) {
155: if ($userupdate{$field} eq '') {
156: unless ($emptyallowed{$field}) {
157: delete($userupdate{$field});
158: }
159: }
160: }
1.5 raeburn 161: $idresult = &propagate_id_change($uname,$udom,\%userupdate);
162: }
1.1 raeburn 163: }
164: }
165: $userresult =
166: &Apache::lonnet::modifyuser($udom,$uname,$uid,$umode,$upass,$first,
167: $middle,$last,$gene,$forceid,$desiredhome,
1.84 raeburn 168: $email,$inststatus);
1.1 raeburn 169: if ($userresult eq 'ok') {
1.5 raeburn 170: if ($role ne '') {
1.22 raeburn 171: $role =~ s/_/\//g;
1.1 raeburn 172: $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
1.52 raeburn 173: $role,$end,$start,'',
174: '',$context);
1.1 raeburn 175: }
176: }
1.5 raeburn 177: return ($userresult,$authresult,$roleresult,$idresult);
1.1 raeburn 178: }
179:
1.212 raeburn 180: sub role_approval {
181: my ($dom,$context,$process_by,$notifydc) = @_;
182: if (ref($process_by) eq 'HASH') {
183: my %domconfig = &Apache::lonnet::get_dom('configuration',['privacy'],$dom);
184: if (ref($domconfig{'privacy'}) eq 'HASH') {
185: if (ref($notifydc) eq 'ARRAY') {
186: if ($domconfig{'privacy'}{'notify'} ne '') {
187: @{$notifydc} = split(/,/,$domconfig{'privacy'}{'notify'});
188: }
189: }
190: if (ref($domconfig{'privacy'}{'approval'}) eq 'HASH') {
191: my %approvalconf = %{$domconfig{'privacy'}{'approval'}};
192: foreach my $key ('instdom','extdom') {
193: if (ref($approvalconf{$key}) eq 'HASH') {
194: if (keys(%{$approvalconf{$key}})) {
195: $process_by->{$key} = $approvalconf{$key}{$context};
196: }
197: }
198: }
199: }
200: }
201: }
202: return;
203: }
204:
205: sub get_instdoms {
206: my ($udom,$instdoms) = @_;
207: return unless (ref($instdoms) eq 'ARRAY');
208: my @intdoms;
209: my %iphost = &Apache::lonnet::get_iphost();
210: my $primary_id = &Apache::lonnet::domain($udom,'primary');
211: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
212: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
213: foreach my $id (@{$iphost{$primary_ip}}) {
214: my $intdom = &Apache::lonnet::internet_dom($id);
215: unless(grep(/^\Q$intdom\E$/,@intdoms)) {
216: push(@intdoms,$intdom);
217: }
218: }
219: }
220: foreach my $ip (keys(%iphost)) {
221: if (ref($iphost{$ip}) eq 'ARRAY') {
222: foreach my $id (@{$iphost{$ip}}) {
223: my $location = &Apache::lonnet::internet_dom($id);
224: if ($location) {
225: if (grep(/^\Q$location\E$/,@intdoms)) {
226: my $dom = &Apache::lonnet::host_domain($id);
227: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
228: push(@{$instdoms},$dom);
229: }
230: }
231: }
232: }
233: }
234: }
235: return;
236: }
237:
238: sub restricted_dom {
239: my ($context,$key,$udom,$uname,$role,$start,$end,$cdom,$cnum,$csec,$credits,
240: $process_by,$instdoms,$got_role_approvals,$got_instdoms,$reject,$pending,
1.213 raeburn 241: $notifydc,$status,$unauthorized,$currqueued) = @_;
1.212 raeburn 242: return if ($udom eq $cdom);
243: return unless ((ref($process_by) eq 'HASH') && (ref($instdoms) eq 'HASH') &&
244: (ref($got_role_approvals) eq 'HASH') && (ref($got_instdoms) eq 'HASH') &&
245: (ref($reject) eq 'HASH') && (ref($pending) eq 'HASH') &&
1.213 raeburn 246: (ref($notifydc) eq 'HASH') && (ref($status) eq 'HASH') &&
247: (ref($unauthorized) eq 'HASH') && (ref($currqueued) eq 'HASH'));
1.212 raeburn 248: my (%approval,@notify,$gotdata,$skip);
249: if (ref($got_role_approvals->{$context}) eq 'HASH') {
250: if ($got_role_approvals->{$context}{$udom}) {
251: $gotdata = 1;
252: if (ref($process_by->{$context}{$udom}) eq 'HASH') {
253: %approval = %{$process_by->{$context}{$udom}};
254: }
255: }
256: }
257: unless ($gotdata) {
258: &role_approval($udom,$context,\%approval,\@notify);
259: $process_by->{$context} = {
260: $udom => \%approval,
261: };
262: $got_role_approvals->{$context} = {
263: $udom => 1,
264: };
265: $notifydc->{$udom} = \@notify;
266: }
267: if (ref($process_by->{$context}) eq 'HASH') {
268: if (ref($process_by->{$context}{$udom}) eq 'HASH') {
269: my @inst;
270: if ($got_instdoms->{$udom}) {
271: if (ref($instdoms->{$udom}) eq 'ARRAY') {
272: @inst = @{$instdoms->{$udom}};
273: }
274: } else {
275: &get_instdoms(\@inst);
276: $instdoms->{$udom} = \@inst;
277: $got_instdoms->{$udom} = 1;
278: }
279: if (grep(/^\Q$cdom\E$/,@inst)) {
280: if (exists($approval{'instdom'})) {
281: my $rule = $approval{'instdom'};
1.213 raeburn 282: if (($rule eq 'none') || ($rule eq 'user') || ($rule eq 'domain')) {
283: my ($id,$currstatus,$curradj) = &get_othdomreq_status($key,$uname,$udom,$role,$cdom,$cnum,$csec);
284: if (($currstatus ne '') && ($curradj eq $rule)) {
285: $status->{$key}->{$uname.':'.$udom} = $currstatus;
286: }
287: if ($rule eq 'none') {
288: $reject->{$key}->{$uname.':'.$udom} = {
289: cdom => $cdom,
290: cnum => $cnum,
291: csec => $csec,
292: udom => $udom,
293: uname => $uname,
294: role => $role,
295: };
296: $skip = 1;
297: } elsif (($rule eq 'user') || ($rule eq 'domain')) {
298: if ($curradj eq $rule) {
299: unless ($currstatus eq 'approved') {
300: if ($currstatus eq 'rejected') {
301: $unauthorized->{$key}->{$uname.':'.$udom} = {
302: cdom => $cdom,
303: cnum => $cnum,
304: csec => $csec,
305: udom => $udom,
306: uname => $uname,
307: role => $role,
308: };
309: } elsif ($currstatus eq 'pending') {
310: $currqueued->{$key}->{$uname.':'.$udom} = {
311: cdom => $cdom,
312: cnum => $cnum,
313: csec => $csec,
314: udom => $udom,
315: uname => $uname,
316: role => $role,
317: adj => $rule,
318: };
319: }
320: $skip = 1;
321: }
322: } else {
323: $pending->{$key}->{$uname.':'.$udom} = {
324: cdom => $cdom,
325: cnum => $cnum,
326: csec => $csec,
327: udom => $udom,
328: uname => $uname,
329: role => $role,
330: start => $start,
331: end => $end,
332: adj => $rule,
333: };
334: if (($role eq 'st') && ($credits ne '')) {
335: $pending->{$key}->{$uname.':'.$udom}->{'credits'} = $credits;
336: }
337: $skip = 1;
338: }
1.212 raeburn 339: }
340: }
341: }
342: } elsif (exists($approval{'extdom'})) {
343: my $rule = $approval{'extdom'};
1.213 raeburn 344: if (($rule eq 'none') || ($rule eq 'user') || ($rule eq 'domain')) {
345: my ($id,$currstatus,$curradj) = &get_othdomreq_status($key,$uname,$udom,$role,$cdom,$cnum,$csec);
346: if (($currstatus ne '') && ($curradj eq $rule)) {
347: $status->{$key}->{$uname.':'.$udom} = $currstatus;
348: }
349: if ($rule eq 'none') {
350: $reject->{$key}->{$uname.':'.$udom} = {
351: cdom => $cdom,
352: cnum => $cnum,
353: csec => $csec,
354: udom => $udom,
355: uname => $uname,
356: role => $role,
357: };
358: $skip = 1;
359: } elsif (($rule eq 'user') || ($rule eq 'domain')) {
360: if ($curradj eq $rule) {
361: unless ($currstatus eq 'approved') {
362: if ($currstatus eq 'rejected') {
363: $unauthorized->{$key}->{$uname.':'.$udom} = {
364: cdom => $cdom,
365: cnum => $cnum,
366: csec => $csec,
367: udom => $udom,
368: uname => $uname,
369: role => $role,
370: };
371: } elsif ($currstatus eq 'pending') {
372: $currqueued->{$key}->{$uname.':'.$udom} = {
373: cdom => $cdom,
374: cnum => $cnum,
375: csec => $csec,
376: udom => $udom,
377: uname => $uname,
378: role => $role,
379: adj => $rule,
380: };
381: }
382: $skip = 1;
383: }
384: } else {
385: $pending->{$key}->{$uname.':'.$udom} = {
386: cdom => $cdom,
387: cnum => $cnum,
388: csec => $csec,
389: udom => $udom,
390: uname => $uname,
391: role => $role,
392: start => $start,
393: end => $end,
394: adj => $rule,
395: };
396: if (($role eq 'st') && ($credits ne '')) {
397: $pending->{$key}->{$uname.':'.$udom}->{'credits'} = $credits;
398: }
399: $skip = 1;
400: }
1.212 raeburn 401: }
402: }
403: }
404: }
405: }
406: return $skip;
407: }
408:
1.213 raeburn 409: sub get_othdomreq_status {
410: my ($key,$uname,$udom,$role,$cdom,$cnum,$csec) = @_;
411: my $id = $uname.':'.$udom.':'.$role;
412: my ($dbnum,$currstatus,$curradj);
413: if (($role eq 'ca') || ($role eq 'aa')) {
414: $dbnum = $cnum;
415: } elsif ($key eq $cdom.'_'.$role) {
416: $dbnum = &Apache::lonnet::get_domainconfiguser($cdom);
417: } else {
418: $id .= ':'.$csec;
419: $dbnum = $cnum;
420: }
421: my $statusid = 'status&'.$id;
422: my %curr = &Apache::lonnet::get('nohist_othdomqueued',[$id,$statusid],$cdom,$dbnum);
423: if (ref($curr{$id}) eq 'HASH') {
424: $curradj = $curr{$id}{'adj'};
425: }
426: $currstatus = $curr{$statusid};
427: return ($id,$currstatus,$curradj);
428: }
429:
1.212 raeburn 430: sub print_roles_rejected {
1.213 raeburn 431: my ($context,$reject,$unauthorized) = @_;
432: return unless ((ref($reject) eq 'HASH') || (ref($unauthorized) eq 'HASH'));
1.212 raeburn 433: my $output;
434: if (keys(%{$reject}) > 0) {
435: $output = '<p class="LC_warning">'.
436: &mt("The following roles could not be assigned because the user is from another domain, and that domain's policies disallow it").'<ul>';
437: foreach my $key (sort(keys(%{$reject}))) {
438: if (ref($reject->{$key}) eq 'HASH') {
1.213 raeburn 439: foreach my $user (sort(keys(%{$reject->{$key}}))) {
440: if (ref($reject->{$key}->{$user}) eq 'HASH') {
441: my ($crstype,$role,$cdom,$cnum,$csec,$title,$plainrole);
442: $role = $reject->{$key}->{$user}{'role'};
443: $cdom = $reject->{$key}->{$user}{'cdom'};
444: $cnum = $reject->{$key}->{$user}{'cnum'};
445: $csec = $reject->{$key}->{$user}{'csec'};
446: if (($context eq 'domain') && ($cnum ne '')) {
447: if (($role eq 'ca') || ($role eq 'aa')) {
448: $title = &Apache::loncommon::plainname($cnum,$cdom);
449: } else {
450: if (&Apache::lonnet::is_course($cdom,$cnum)) {
451: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
452: $crstype = $coursedata{'type'};
453: $title = $coursedata{'description'};
454: }
455: }
456: } elsif ($context eq 'course') {
457: $crstype = &Apache::loncommon::course_type();
458: }
459: my $plainrole = &Apache::lonnet::plaintext($role,$crstype);
460: $output .= '<li>'.&mt('User: [_1]',$reject->{$key}->{$user}{'uname'}).' | '.
461: &mt('Domain: [_1]',$reject->{$key}->{$user}{'udom'}).' | '.
462: &mt('Role: [_1]',$plainrole);
463: if ($crstype) {
464: if ($csec ne'') {
465: $output .= ' | '.&mt('Section: [_1]',$csec);
466: }
467: } elsif (($context eq 'domain') && (($role eq 'ca') || ($role eq 'aa'))) {
468: $output .= ' | '.&mt('Authoring Space belonging to: [_1]',$title);
469:
470: }
471: if (($context eq 'domain') && ($crstype)) {
472: $output .= ' | '.&mt("$crstype: [_1]",$title);
473: }
474: $output .= '</li>';
1.212 raeburn 475: }
476: }
1.213 raeburn 477: }
478: }
479: $output .= '</ul></p>';
480: }
481: if (keys(%{$unauthorized}) > 0) {
482: $output = '<p class="LC_warning">'.
483: &mt("The following roles could not be assigned because the user is from another domain, and that domain's policies require approval by the user themselves or by a domain coordinator in that domain, and approval has been withheld.").'<ul>';
484: foreach my $key (sort(keys(%{$unauthorized}))) {
485: if (ref($unauthorized->{$key}) eq 'HASH') {
486: foreach my $user (sort(keys(%{$unauthorized->{$key}}))) {
487: if (ref($unauthorized->{$key}->{$user}) eq 'HASH') {
488: my ($crstype,$role,$cdom,$cnum,$csec,$title,$plainrole);
489: $role = $unauthorized->{$key}->{$user}{'role'};
490: $cdom = $unauthorized->{$key}->{$user}{'cdom'};
491: $cnum = $unauthorized->{$key}->{$user}{'cnum'};
492: $csec = $unauthorized->{$key}->{$user}{'csec'};
493: if (($context eq 'domain') && ($cnum ne '')) {
494: if (($role eq 'ca') || ($role eq 'aa')) {
495: $title = &mt('Authoring Space belonging to: [_1]',
496: &Apache::loncommon::plainname($cnum,$cdom));
497: } else {
498: if (&Apache::lonnet::is_course($cdom,$cnum)) {
499: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
500: $crstype = $coursedata{'type'};
501: $title = &mt("$crstype: [_1]",$coursedata{'description'});
502: }
503: }
504: } elsif ($context eq 'course') {
505: $crstype = &Apache::loncommon::course_type();
506: }
507: $plainrole = &Apache::lonnet::plaintext($role,$crstype);
508: $output .= '<li>'.&mt('User: [_1]',$unauthorized->{$key}->{$user}{'uname'}).' | '.
509: &mt('Domain: [_1]',$unauthorized->{$key}->{$user}{'udom'}).' | '.
510: &mt('Role: [_1]',$plainrole);
511: if ($crstype) {
512: if ($csec ne'') {
513: $output .= ' | '.&mt('Section: [_1]',$csec);
514: }
515: }
516: if ($title ne '') {
517: $output .= ' | '.$title;
518: }
519: $output .= '</li>';
520: }
1.212 raeburn 521: }
522: }
523: }
1.213 raeburn 524: $output .= '</ul></p>';
1.212 raeburn 525: }
526: return $output;
527: }
528:
529: sub print_roles_queued {
1.213 raeburn 530: my ($context,$pending,$notifydc,$currqueued) = @_;
531: return unless ((ref($pending) eq 'HASH') && (ref($notifydc) eq 'HASH') &&
532: (ref($currqueued) eq 'HASH'));
1.212 raeburn 533: my $output;
534: if (keys(%{$pending}) > 0) {
535: my $now = time;
536: $output = '<p class="LC_warning">'.
537: &mt("The following role assignments have been queued because the user is from another domain, and that domain's policies require approval by the user themselves or by a domain coordinator in that domain").'<ul>';
538: my (%todom,%touser,%crsqueue,%caqueue,%domqueue);
539: my $requester = $env{'user.name'}.':'.$env{'user.domain'};
540: foreach my $key (sort(keys(%{$pending}))) {
541: if (ref($pending->{$key}) eq 'HASH') {
1.213 raeburn 542: foreach my $user (sort(keys(%{$pending->{$key}}))) {
543: if (ref($pending->{$key}->{$user}) eq 'HASH') {
544: my $role = $pending->{$key}->{$user}{'role'};
545: my $uname = $pending->{$key}->{$user}{'uname'};
546: my $udom = $pending->{$key}->{$user}{'udom'};
547: my $csec = $pending->{$key}->{$user}{'csec'};
548: my $cdom = $pending->{$key}->{$user}{'cdom'};
549: my $cnum = $pending->{$key}->{$user}{'cnum'};
550: my $adj = $pending->{$key}->{$user}{'adj'};
551: my $start = $pending->{$key}->{$user}{'start'};
552: my $end = $pending->{$key}->{$user}{'end'};
553: my $credits = $pending->{$key}->{$user}{'credits'};
554: my $now = time;
555: my ($crstype,$title,$plainrole,$extent,$id,$status);
556: if ($context eq 'course') {
557: $crstype = &Apache::loncommon::course_type();
558: $title = $env{'course.'.$env{'request.course.id'}.'.description'};
559: } elsif ($context eq 'domain') {
560: if (&Apache::lonnet::is_course($cdom,$cnum)) {
561: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
562: $crstype = $coursedata{'type'};
563: $title = $coursedata{'description'};
564: } elsif (($role eq 'ca') || ($role eq 'aa')) {
565: $title = &Apache::loncommon::plainname($cnum,$cdom);
566: }
567: }
568: $plainrole = &Apache::lonnet::plaintext($role,$crstype);
569: $extent = "/$cdom/$cnum";
570: $id = $uname.':'.$udom.':'.$role;
571: if (($context eq 'course') || ($crstype)) {
572: $id .= ':'.$csec;
573: }
574: $output .= '<li>'.&mt('User: [_1]',$uname).' | '.
575: &mt('Domain: [_1]',$udom).' | '.
576: &mt('Role: [_1]',$plainrole);
577: if ($crstype) {
578: if ($csec ne'') {
579: $output .= ' | '.&mt('Section: [_1]',$csec);
580: }
581: } elsif (($context eq 'domain') && (($role eq 'ca') || ($role eq 'aa'))) {
582: $output .= ' | '.&mt('Authoring Space belonging to: [_1]',$title);
583: }
584: if (($context eq 'domain') && ($crstype)) {
585: $output .= ' | '.&mt("$crstype: [_1]",$title);
586: }
587: if (($crstype) && ($csec ne '')) {
588: $extent .= "/$csec";
589: }
590: if ($adj eq 'user') {
591: $output .= '<br />'.&mt('Message sent to user for approval');
592: $touser{$uname.':'.$udom}{'pending:'.$extent.':'.$role} = {
593: timestamp => $now,
594: requester => $requester,
595: start => $start,
596: end => $end,
597: credits => $credits,
598: context => $context,
599: };
600: } elsif ($adj eq 'domain') {
601: $output .= '<br />'.&mt("Message sent to user's domain coordinator for approval");
602: $todom{$udom}{'pending:'.$uname.':'.$extent.':'.$role} = {
603: timestamp => $now,
604: requester => $requester,
605: start => $start,
606: end => $end,
607: credits => $credits,
608: context => $context,
609: };
610: }
611: $output .= '</li>';
612: if (($context eq 'course') || ($crstype)) {
613: $crsqueue{$cdom.'_'.$cnum}{$id} = {
614: timestamp => $now,
615: requester => $requester,
616: adj => $adj,
617: };
618: $crsqueue{$cdom.'_'.$cnum}{'status&'.$id} = 'pending';
619: } elsif (($context eq 'author') ||
620: (($context eq 'domain') && (($role eq 'ca') || ($role eq 'aa')))) {
621: $caqueue{$cnum.':'.$cdom}{$id} = {
622: timestamp => $now,
623: requester => $requester,
624: adj => $adj,
625: };
626: $caqueue{$cnum.':'.$cdom}{'status&'.$id} = 'pending';
627: } elsif ($context eq 'domain') {
628: $domqueue{$id} = {
629: timestamp => $now,
630: requester => $requester,
631: adj => $adj,
632: };
633: $domqueue{'status&'.$id} = 'pending';
634: }
635: }
1.212 raeburn 636: }
637: }
638: }
639: $output .= '</ul></p>';
640: if (keys(%touser)) {
641: foreach my $key (keys(%touser)) {
1.214 raeburn 642: my ($uname,$udom) = split(/:/,$key);
1.213 raeburn 643: if (&Apache::lonnet::put('nohist_queuedrolereqs',$touser{$key},$udom,$uname) eq 'ok') {
1.212 raeburn 644: my $owndomdesc = &Apache::lonnet::domain($udom);
645: &Apache::loncoursequeueadmin::send_selfserve_notification($uname.':'.$udom,
646: '','',$owndomdesc,$now,'othdomroleuser',$requester);
647: }
648: }
649: }
650: if (keys(%todom)) {
651: foreach my $dom (keys(%todom)) {
652: if (ref($todom{$dom}) eq 'HASH') {
653: my $confname = &Apache::lonnet::get_domainconfiguser($dom);
1.213 raeburn 654: if (&Apache::lonnet::put('nohist_queuedrolereqs',$todom{$dom},$dom,$confname) eq 'ok') {
1.212 raeburn 655: if (ref($notifydc->{$dom}) eq 'ARRAY') {
656: if (@{$notifydc->{$dom}} > 0) {
657: my $notifylist = join(',',@{$notifydc->{$dom}});
658: &Apache::loncoursequeueadmin::send_selfserve_notification($notifylist,
659: '','','',$now,'othdomroledc',$requester);
660: }
661: }
662: }
663: }
664: }
665: }
666: if (keys(%crsqueue)) {
667: foreach my $key (keys(%crsqueue)) {
668: my ($cdom,$cnum) = split(/_/,$key);
669: if (ref($crsqueue{$key}) eq 'HASH') {
1.213 raeburn 670: &Apache::lonnet::put('nohist_othdomqueued',$crsqueue{$key},$cdom,$cnum);
1.212 raeburn 671: }
672: }
673: }
674: if (keys(%caqueue)) {
675: foreach my $key (keys(%caqueue)) {
676: my ($auname,$audom) = split(/:/,$key);
677: if (ref($caqueue{$key}) eq 'HASH') {
1.213 raeburn 678: &Apache::lonnet::put('nohist_othdomqueued',$caqueue{$key},$audom,$auname);
1.212 raeburn 679: }
680: }
681: }
682: if (keys(%domqueue)) {
683: my $confname = &Apache::lonnet::get_domainconfiguser($env{'request.role.domain'});
1.213 raeburn 684: &Apache::lonnet::put('nohist_othdomqueued',\%domqueue,$env{'request.role.domain'},$confname);
1.212 raeburn 685: }
686: }
1.213 raeburn 687: if (keys(%{$currqueued}) > 0) {
688: $output = '<p class="LC_warning">'.
689: &mt("The following role assignments were already queued because the user is from another domain, and that domain's policies require approval by the user themselves or by a domain coordinator in that domain").'<ul>';
690: my $requester = $env{'user.name'}.':'.$env{'user.domain'};
691: foreach my $key (sort(keys(%{$currqueued}))) {
692: if (ref($currqueued->{$key}) eq 'HASH') {
693: foreach my $user (sort(keys(%{$currqueued->{$key}}))) {
694: if (ref($currqueued->{$key}->{$user}) eq 'HASH') {
695: my $role = $currqueued->{$key}->{$user}{'role'};
696: my $csec = $currqueued->{$key}->{$user}{'csec'};
697: my $cdom = $currqueued->{$key}->{$user}{'cdom'};
698: my $cnum = $currqueued->{$key}->{$user}{'cnum'};
699: my ($crstype,$title,$plainrole);
700: if ($context eq 'course') {
701: $crstype = &Apache::loncommon::course_type();
702: } elsif (($context eq 'domain') && ($cnum ne '')) {
703: if (($role eq 'ca') || ($role eq 'aa')) {
704: $title = &mt('Authoring Space belonging to: [_1]',
705: &Apache::loncommon::plainname($cnum,$cdom));
706: } elsif (&Apache::lonnet::is_course($cdom,$cnum)) {
707: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
708: $crstype = $coursedata{'type'};
709: $title = &mt("$crstype: [_1]",$coursedata{'description'});
710: }
711: }
712: $plainrole = &Apache::lonnet::plaintext($role,$crstype);
713: $output .= '<li>'.&mt('User: [_1]',$currqueued->{$key}->{$user}{'uname'}).' | '.
714: &mt('Domain: [_1]',$currqueued->{$key}->{$user}{'udom'}).' | '.
715: &mt('Role: [_1]',$plainrole);
716: if ($title ne '') {
717: $output .= ' | '.$title;
718: }
719: if ($crstype) {
720: if ($csec ne '') {
721: $output .= ' | '.&mt('Section: [_1]',$csec);
722: }
723: }
724: $output .= '</li>';
725: }
726: }
727: }
728: }
729: $output .= '</ul></p>';
730: }
1.212 raeburn 731: return $output;
732: }
733:
1.5 raeburn 734: sub propagate_id_change {
735: my ($uname,$udom,$user) = @_;
1.12 raeburn 736: my (@types,@roles);
1.5 raeburn 737: @types = ('active','future');
738: @roles = ('st');
739: my $idresult;
740: my %roleshash = &Apache::lonnet::get_my_roles($uname,
1.12 raeburn 741: $udom,'userroles',\@types,\@roles);
742: my %args = (
743: one_time => 1,
744: );
1.5 raeburn 745: foreach my $item (keys(%roleshash)) {
1.22 raeburn 746: my ($cnum,$cdom,$role) = split(/:/,$item,-1);
1.5 raeburn 747: my ($start,$end) = split(/:/,$roleshash{$item});
748: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.12 raeburn 749: my $result = &update_classlist($cdom,$cnum,$udom,$uname,$user);
750: my %coursehash =
751: &Apache::lonnet::coursedescription($cdom.'_'.$cnum,\%args);
752: my $cdesc = $coursehash{'description'};
753: if ($cdesc eq '') {
754: $cdesc = $cdom.'_'.$cnum;
755: }
1.5 raeburn 756: if ($result eq 'ok') {
1.12 raeburn 757: $idresult .= &mt('Classlist update for "[_1]" in "[_2]".',$uname.':'.$udom,$cdesc).'<br />'."\n";
1.5 raeburn 758: } else {
1.12 raeburn 759: $idresult .= &mt('Error: "[_1]" during classlist update for "[_2]" in "[_3]".',$result,$uname.':'.$udom,$cdesc).'<br />'."\n";
1.5 raeburn 760: }
761: }
762: }
763: return $idresult;
764: }
765:
766: sub update_classlist {
1.63 raeburn 767: my ($cdom,$cnum,$udom,$uname,$user,$newend) = @_;
1.6 albertel 768: my ($uid,$classlistentry);
1.5 raeburn 769: my $fullname =
770: &Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
771: $user->{'lastname'},$user->{'generation'},
772: 'lastname');
773: my %classhash = &Apache::lonnet::get('classlist',[$uname.':'.$udom],
774: $cdom,$cnum);
775: my @classinfo = split(/:/,$classhash{$uname.':'.$udom});
776: my $ididx=&Apache::loncoursedata::CL_ID() - 2;
777: my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2;
1.63 raeburn 778: my $endidx = &Apache::loncoursedata::CL_END() - 2;
779: my $startidx = &Apache::loncoursedata::CL_START() - 2;
1.5 raeburn 780: for (my $i=0; $i<@classinfo; $i++) {
1.63 raeburn 781: if ($i == $endidx) {
782: if ($newend ne '') {
783: $classlistentry .= $newend.':';
784: } else {
785: $classlistentry .= $classinfo[$i].':';
786: }
787: } elsif ($i == $startidx) {
788: if ($newend ne '') {
789: if ($classinfo[$i] > $newend) {
790: $classlistentry .= $newend.':';
791: } else {
792: $classlistentry .= $classinfo[$i].':';
793: }
794: } else {
795: $classlistentry .= $classinfo[$i].':';
796: }
797: } elsif ($i == $ididx) {
1.5 raeburn 798: if (defined($user->{'id'})) {
799: $classlistentry .= $user->{'id'}.':';
800: } else {
801: $classlistentry .= $classinfo[$i].':';
802: }
803: } elsif ($i == $nameidx) {
1.63 raeburn 804: if (defined($user->{'lastname'})) {
805: $classlistentry .= $fullname.':';
806: } else {
807: $classlistentry .= $classinfo[$i].':';
808: }
1.5 raeburn 809: } else {
810: $classlistentry .= $classinfo[$i].':';
811: }
812: }
813: $classlistentry =~ s/:$//;
814: my $reply=&Apache::lonnet::cput('classlist',
815: {"$uname:$udom" => $classlistentry},
816: $cdom,$cnum);
817: if (($reply eq 'ok') || ($reply eq 'delayed')) {
818: return 'ok';
819: } else {
820: return 'error: '.$reply;
821: }
822: }
823:
824:
1.1 raeburn 825: ###############################################################
826: ###############################################################
1.2 raeburn 827: # build a role type and role selection form
828: sub domain_roles_select {
829: # Set up the role type and role selection boxes when in
830: # domain context
831: #
832: # Role types
1.101 raeburn 833: my @roletypes = ('domain','author','course','community');
1.2 raeburn 834: my %lt = &role_type_names();
1.149 raeburn 835: my $onchangefirst = "updateCols('showrole')";
836: my $onchangesecond = "updateCols('showrole')";
1.1 raeburn 837: #
838: # build up the menu information to be passed to
839: # &Apache::loncommon::linked_select_forms
840: my %select_menus;
1.2 raeburn 841: if ($env{'form.roletype'} eq '') {
842: $env{'form.roletype'} = 'domain';
843: }
844: foreach my $roletype (@roletypes) {
1.1 raeburn 845: # set up the text for this domain
1.2 raeburn 846: $select_menus{$roletype}->{'text'}= $lt{$roletype};
1.102 raeburn 847: my $crstype;
848: if ($roletype eq 'community') {
849: $crstype = 'Community';
850: }
1.1 raeburn 851: # we want a choice of 'default' as the default in the second menu
1.2 raeburn 852: if ($env{'form.roletype'} ne '') {
853: $select_menus{$roletype}->{'default'} = $env{'form.showrole'};
854: } else {
855: $select_menus{$roletype}->{'default'} = 'Any';
856: }
1.1 raeburn 857: # Now build up the other items in the second menu
1.2 raeburn 858: my @roles;
859: if ($roletype eq 'domain') {
860: @roles = &domain_roles();
1.13 raeburn 861: } elsif ($roletype eq 'author') {
1.2 raeburn 862: @roles = &construction_space_roles();
863: } else {
1.17 raeburn 864: my $custom = 1;
1.101 raeburn 865: @roles = &course_roles('domain',undef,$custom,$roletype);
1.1 raeburn 866: }
1.2 raeburn 867: my $order = ['Any',@roles];
868: $select_menus{$roletype}->{'order'} = $order;
869: foreach my $role (@roles) {
1.5 raeburn 870: if ($role eq 'cr') {
871: $select_menus{$roletype}->{'select2'}->{$role} =
872: &mt('Custom role');
873: } else {
874: $select_menus{$roletype}->{'select2'}->{$role} =
1.102 raeburn 875: &Apache::lonnet::plaintext($role,$crstype);
1.5 raeburn 876: }
1.2 raeburn 877: }
878: $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
1.1 raeburn 879: }
1.2 raeburn 880: my $result = &Apache::loncommon::linked_select_forms
881: ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
1.101 raeburn 882: 'roletype','showrole',\%select_menus,
1.149 raeburn 883: ['domain','author','course','community'],$onchangefirst,
884: $onchangesecond);
1.1 raeburn 885: return $result;
886: }
887:
888: ###############################################################
889: ###############################################################
890: sub hidden_input {
891: my ($name,$value) = @_;
892: return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n";
893: }
894:
895: sub print_upload_manager_header {
1.123 raeburn 896: my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype,
897: $can_assign)=@_;
1.1 raeburn 898: my $javascript;
899: #
900: if (! exists($env{'form.upfile_associate'})) {
901: $env{'form.upfile_associate'} = 'forward';
902: }
903: if ($env{'form.associate'} eq 'Reverse Association') {
904: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
905: $env{'form.upfile_associate'} = 'reverse';
906: } else {
907: $env{'form.upfile_associate'} = 'forward';
908: }
909: }
910: if ($env{'form.upfile_associate'} eq 'reverse') {
1.123 raeburn 911: $javascript=&upload_manager_javascript_reverse_associate($can_assign);
1.1 raeburn 912: } else {
1.123 raeburn 913: $javascript=&upload_manager_javascript_forward_associate($can_assign);
1.1 raeburn 914: }
915: #
916: # Deal with restored settings
917: my $password_choice = '';
918: if (exists($env{'form.ipwd_choice'}) &&
919: $env{'form.ipwd_choice'} ne '') {
920: # If a column was specified for password, assume it is for an
921: # internal password. This is a bug waiting to be filed (could be
922: # local or krb auth instead of internal) but I do not have the
923: # time to mess around with this now.
924: $password_choice = 'int';
925: }
926: #
1.22 raeburn 927: my $groupslist;
928: if ($context eq 'course') {
929: $groupslist = &get_groupslist();
930: }
1.1 raeburn 931: my $javascript_validations =
1.22 raeburn 932: &javascript_validations('upload',$krbdefdom,$password_choice,undef,
933: $env{'request.role.domain'},$context,
1.103 raeburn 934: $groupslist,$crstype);
1.91 bisitz 935: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.147 bisitz 936: $r->print(
937: '<h3>'.&mt('Identify fields in uploaded list')."</h3>\n".
938: '<p class="LC_info">'.
939: &mt('Total number of records found in file: [_1]'
940: ,'<b>'.$distotal.'</b>').
941: "</p>\n"
942: );
943: if ($distotal == 0) {
944: $r->print('<p class="LC_warning">'.&mt('None found').'</p>');
945: }
946: $r->print(
947: '<p>'.
948: &mt('Enter as many fields as you can.').'<br />'.
949: &mt('The system will inform you and bring you back to this page,[_1]if the data selected are insufficient to add users.','<br />').
950: "</p>\n"
951: );
1.1 raeburn 952: $r->print(&hidden_input('action','upload').
953: &hidden_input('state','got_file').
954: &hidden_input('associate','').
955: &hidden_input('datatoken',$datatoken).
956: &hidden_input('fileupload',$env{'form.fileupload'}).
957: &hidden_input('upfiletype',$env{'form.upfiletype'}).
958: &hidden_input('upfile_associate',$env{'form.upfile_associate'}));
1.147 bisitz 959: $r->print(
960: '<div class="LC_left_float">'.
961: '<fieldset><legend>'.&mt('Functions').'</legend>'.
962: '<label><input type="checkbox" name="noFirstLine"'.$checked.' />'.
963: &mt('Ignore First Line').'</label>'.
964: ' <input type="button" value="'.&mt('Reverse Association').'" '.
1.59 bisitz 965: 'name="Reverse Association" '.
1.147 bisitz 966: 'onclick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />'.
967: '</fieldset></div><br clear="all" />'
968: );
969: $r->print(
970: '<script type="text/javascript" language="Javascript">'."\n".
971: '// <![CDATA['."\n".
972: $javascript."\n".$javascript_validations."\n".
973: '// ]]>'."\n".
974: '</script>'
975: );
1.1 raeburn 976: }
977:
978: ###############################################################
979: ###############################################################
980: sub javascript_validations {
1.22 raeburn 981: my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain,
1.103 raeburn 982: $context,$groupslist,$crstype)=@_;
1.22 raeburn 983: my %param = (
984: kerb_def_dom => $krbdefdom,
985: curr_authtype => $curr_authtype,
986: );
1.37 raeburn 987: if ($mode eq 'upload') {
1.22 raeburn 988: $param{'formname'} = 'studentform';
1.1 raeburn 989: } elsif ($mode eq 'createcourse') {
1.22 raeburn 990: $param{'formname'} = 'ccrs';
1.1 raeburn 991: } elsif ($mode eq 'modifycourse') {
1.22 raeburn 992: $param{'formname'} = 'cmod';
993: $param{'mode'} = 'modifycourse',
994: $param{'curr_autharg'} = $curr_authfield;
995: }
996:
1.150 raeburn 997: my $showcredits;
998: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
1.160 raeburn 999: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
1.150 raeburn 1000: $showcredits = 1;
1001: }
1002:
1.22 raeburn 1003: my ($setsection_call,$setsections_js);
1004: my $finish = " vf.submit();\n";
1005: if ($mode eq 'upload') {
1006: if (($context eq 'course') || ($context eq 'domain')) {
1007: if ($context eq 'course') {
1008: if ($env{'request.course.sec'} eq '') {
1.109 raeburn 1009: $setsection_call = 'setSections(document.'.$param{'formname'}.",'$crstype'".');';
1.22 raeburn 1010: $setsections_js =
1011: &setsections_javascript($param{'formname'},$groupslist,
1.150 raeburn 1012: $mode,'',$crstype,$showcredits);
1.22 raeburn 1013: } else {
1014: $setsection_call = "'ok'";
1015: }
1016: } elsif ($context eq 'domain') {
1017: $setsection_call = 'setCourse()';
1.150 raeburn 1018: $setsections_js = &dc_setcourse_js($param{'formname'},$mode,
1.196 raeburn 1019: $context,$showcredits,$domain);
1.22 raeburn 1020: }
1021: $finish = " var checkSec = $setsection_call\n".
1022: " if (checkSec == 'ok') {\n".
1023: " vf.submit();\n".
1024: " }\n";
1025: }
1.1 raeburn 1026: }
1.22 raeburn 1027: my $authheader = &Apache::loncommon::authform_header(%param);
1.1 raeburn 1028:
1029: my %alert = &Apache::lonlocal::texthash
1030: (username => 'You need to specify the username field.',
1031: authen => 'You must choose an authentication type.',
1032: krb => 'You need to specify the Kerberos domain.',
1033: ipass => 'You need to specify the initial password.',
1034: name => 'The optional name field was not specified.',
1.93 bisitz 1035: snum => 'The optional student/employee ID field was not specified.',
1.1 raeburn 1036: section => 'The optional section field was not specified.',
1.75 schafran 1037: email => 'The optional e-mail address field was not specified.',
1.1 raeburn 1038: role => 'The optional role field was not specified.',
1.57 raeburn 1039: domain => 'The optional domain field was not specified.',
1.1 raeburn 1040: continue => 'Continue adding users?',
1041: );
1.150 raeburn 1042: if ($showcredits) {
1043: $alert{'credits'} = &mt('The optional credits field was not specified');
1044: }
1.84 raeburn 1045: if (($mode eq 'upload') && ($context eq 'domain')) {
1046: $alert{'inststatus'} = &mt('The optional affiliation field was not specified');
1047: }
1.170 damieng 1048: &js_escape(\%alert);
1.37 raeburn 1049: my $function_name = <<"END";
1.22 raeburn 1050: $setsections_js
1051:
1.150 raeburn 1052: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits) {
1.1 raeburn 1053: END
1054: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($domain);
1055: my $auth_checks;
1056: if ($mode eq 'createcourse') {
1057: $auth_checks .= (<<END);
1058: if (vf.autoadds[0].checked == true) {
1059: if (current.radiovalue == null || current.radiovalue == 'nochange') {
1060: alert('$alert{'authen'}');
1061: return;
1062: }
1063: }
1064: END
1065: } else {
1066: $auth_checks .= (<<END);
1067: var foundatype=0;
1068: if (founduname==0) {
1069: alert('$alert{'username'}');
1070: return;
1071: }
1072:
1073: END
1074: if ($authnum > 1) {
1075: $auth_checks .= (<<END);
1076: if (current.radiovalue == null || current.radiovalue == '' || current.radiovalue == 'nochange') {
1077: // They did not check any of the login radiobuttons.
1078: alert('$alert{'authen'}');
1079: return;
1080: }
1081: END
1082: }
1083: }
1084: if ($mode eq 'createcourse') {
1085: $auth_checks .= "
1086: if ( (vf.autoadds[0].checked == true) &&
1087: (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') ) {
1088: ";
1089: } elsif ($mode eq 'modifycourse') {
1090: $auth_checks .= "
1.215 raeburn 1091: if ((current.argfield !== null) && (current.argfield !== undefined) && (current.argfield !== '') && (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '')) {
1.1 raeburn 1092: ";
1093: }
1094: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
1095: $auth_checks .= (<<END);
1096: var alertmsg = '';
1097: switch (current.radiovalue) {
1098: case 'krb':
1099: alertmsg = '$alert{'krb'}';
1100: break;
1101: default:
1102: alertmsg = '';
1103: }
1104: if (alertmsg != '') {
1105: alert(alertmsg);
1106: return;
1107: }
1108: }
1.150 raeburn 1109: /* regexp here to check for non \d \. in credits */
1.1 raeburn 1110: END
1111: } else {
1.196 raeburn 1112: my ($numrules,$intargjs) =
1.210 raeburn 1113: &Apache::loncommon::passwd_validation_js('vf.elements[current.argfield].value',$domain);
1.1 raeburn 1114: $auth_checks .= (<<END);
1115: foundatype=1;
1116: if (current.argfield == null || current.argfield == '') {
1.196 raeburn 1117: // The login radiobutton checked does not have an associated textbox
1118: } else if (vf.elements[current.argfield].value == '') {
1.1 raeburn 1119: var alertmsg = '';
1.38 raeburn 1120: switch (current.radiovalue) {
1.1 raeburn 1121: case 'krb':
1122: alertmsg = '$alert{'krb'}';
1123: break;
1.196 raeburn 1124: case 'int':
1.1 raeburn 1125: alertmsg = '$alert{'ipass'}';
1126: break;
1127: case 'fsys':
1.196 raeburn 1128: alertmsg = '$alert{'ipass'}';
1.1 raeburn 1129: break;
1.209 raeburn 1130: case 'loc':
1131: alertmsg = '';
1132: break;
1.194 raeburn 1133: case 'lti':
1.1 raeburn 1134: default:
1135: alertmsg = '';
1136: }
1137: if (alertmsg != '') {
1138: alert(alertmsg);
1139: return;
1140: }
1.196 raeburn 1141: } else if (current.radiovalue == 'int') {
1142: if ($numrules > 0) {
1143: $intargjs
1144: }
1.1 raeburn 1145: }
1146: END
1147: }
1148: my $section_checks;
1149: my $optional_checks = '';
1150: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
1151: $optional_checks = (<<END);
1152: vf.submit();
1153: }
1154: END
1155: } else {
1156: $section_checks = §ion_check_js();
1157: $optional_checks = (<<END);
1158: var message='';
1159: if (foundname==0) {
1160: message='$alert{'name'}';
1161: }
1162: if (foundid==0) {
1163: if (message!='') {
1164: message+='\\n';
1165: }
1166: message+='$alert{'snum'}';
1167: }
1168: if (foundsec==0) {
1169: if (message!='') {
1170: message+='\\n';
1171: }
1.130 raeburn 1172: message+='$alert{'section'}';
1.1 raeburn 1173: }
1174: if (foundemail==0) {
1175: if (message!='') {
1176: message+='\\n';
1177: }
1178: message+='$alert{'email'}';
1179: }
1.57 raeburn 1180: if (foundrole==0) {
1181: if (message!='') {
1182: message+='\\n';
1183: }
1184: message+='$alert{'role'}';
1185: }
1186: if (founddomain==0) {
1187: if (message!='') {
1188: message+='\\n';
1189: }
1190: message+='$alert{'domain'}';
1191: }
1.84 raeburn 1192: END
1.150 raeburn 1193: if ($showcredits) {
1194: $optional_checks .= <<END;
1195: if (foundcredits==0) {
1196: if (message!='') {
1197: message+='\\n';
1198: }
1199: message+='$alert{'credits'}';
1200: }
1201: END
1202: }
1.84 raeburn 1203: if (($mode eq 'upload') && ($context eq 'domain')) {
1204: $optional_checks .= (<<END);
1205:
1206: if (foundinststatus==0) {
1207: if (message!='') {
1208: message+='\\n';
1209: }
1210: message+='$alert{'inststatus'}';
1211: }
1212: END
1213: }
1214: $optional_checks .= (<<END);
1215:
1.1 raeburn 1216: if (message!='') {
1217: message+= '\\n$alert{'continue'}';
1218: if (confirm(message)) {
1219: vf.state.value='enrolling';
1.22 raeburn 1220: $finish
1.1 raeburn 1221: }
1222: } else {
1223: vf.state.value='enrolling';
1.22 raeburn 1224: $finish
1.1 raeburn 1225: }
1226: }
1227: END
1228: }
1.37 raeburn 1229: my $result = $function_name.$auth_checks.$optional_checks."\n".
1230: $section_checks.$authheader;
1.1 raeburn 1231: return $result;
1232: }
1.196 raeburn 1233:
1.1 raeburn 1234: ###############################################################
1235: ###############################################################
1236: sub upload_manager_javascript_forward_associate {
1.123 raeburn 1237: my ($can_assign) = @_;
1.132 raeburn 1238: my ($auth_update,$numbuttons,$argreset);
1.123 raeburn 1239: if (ref($can_assign) eq 'HASH') {
1.132 raeburn 1240: if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
1241: $argreset .= " vf.krbarg.value='';\n";
1242: $numbuttons ++ ;
1243: }
1244: if ($can_assign->{'int'}) {
1245: $argreset .= " vf.intarg.value='';\n";
1246: $numbuttons ++;
1247: }
1248: if ($can_assign->{'loc'}) {
1249: $argreset .= " vf.locarg.value='';\n";
1250: $numbuttons ++;
1251: }
1252: if (!$can_assign->{'int'}) {
1.170 damieng 1253: my $warning = &mt('You may not specify an initial password for each user, as this is only available when new users use LON-CAPA internal authentication.')."\n".
1.132 raeburn 1254: &mt('Your current role does not have rights to create users with that authentication type.');
1.170 damieng 1255: &js_escape(\$warning);
1.132 raeburn 1256: $auth_update = <<"END";
1257: // Currently the initial password field is only supported for internal auth
1258: // (see bug 6368).
1259: if (nw==9) {
1260: eval('vf.f'+tf+'.selectedIndex=0;')
1261: alert('$warning');
1262: }
1263: END
1264: } elsif ($numbuttons > 1) {
1.123 raeburn 1265: $auth_update = <<"END";
1266: // If we set the password, make the password form below correspond to
1267: // the new value.
1268: if (nw==9) {
1269: changed_radio('int',document.studentform);
1270: set_auth_radio_buttons('int',document.studentform);
1.132 raeburn 1271: $argreset
1272: }
1273:
1.123 raeburn 1274: END
1275: }
1276: }
1277:
1.1 raeburn 1278: return(<<ENDPICK);
1279: function verify(vf,sec_caller) {
1280: var founduname=0;
1281: var foundpwd=0;
1282: var foundname=0;
1283: var foundid=0;
1284: var foundsec=0;
1285: var foundemail=0;
1286: var foundrole=0;
1.57 raeburn 1287: var founddomain=0;
1.84 raeburn 1288: var foundinststatus=0;
1.150 raeburn 1289: var foundcredits=0;
1.1 raeburn 1290: var tw;
1291: for (i=0;i<=vf.nfields.value;i++) {
1292: tw=eval('vf.f'+i+'.selectedIndex');
1293: if (tw==1) { founduname=1; }
1294: if ((tw>=2) && (tw<=6)) { foundname=1; }
1295: if (tw==7) { foundid=1; }
1296: if (tw==8) { foundsec=1; }
1297: if (tw==9) { foundpwd=1; }
1298: if (tw==10) { foundemail=1; }
1299: if (tw==11) { foundrole=1; }
1.57 raeburn 1300: if (tw==12) { founddomain=1; }
1.84 raeburn 1301: if (tw==13) { foundinststatus=1; }
1.150 raeburn 1302: if (tw==14) { foundcredits=1; }
1.1 raeburn 1303: }
1.150 raeburn 1304: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits);
1.1 raeburn 1305: }
1306:
1307: //
1308: // vf = this.form
1309: // tf = column number
1310: //
1311: // values of nw
1312: //
1313: // 0 = none
1314: // 1 = username
1315: // 2 = names (lastname, firstnames)
1316: // 3 = fname (firstname)
1317: // 4 = mname (middlename)
1318: // 5 = lname (lastname)
1319: // 6 = gen (generation)
1320: // 7 = id
1321: // 8 = section
1322: // 9 = ipwd (password)
1323: // 10 = email address
1324: // 11 = role
1.57 raeburn 1325: // 12 = domain
1.84 raeburn 1326: // 13 = inststatus
1.150 raeburn 1327: // 14 = foundcredits
1.1 raeburn 1328:
1329: function flip(vf,tf) {
1330: var nw=eval('vf.f'+tf+'.selectedIndex');
1331: var i;
1332: // make sure no other columns are labeled the same as this one
1333: for (i=0;i<=vf.nfields.value;i++) {
1334: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
1335: eval('vf.f'+i+'.selectedIndex=0;')
1336: }
1337: }
1338: // If we set this to 'lastname, firstnames', clear out all the ones
1339: // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
1340: if (nw==2) {
1341: for (i=0;i<=vf.nfields.value;i++) {
1342: if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
1343: (eval('vf.f'+i+'.selectedIndex')<=6)) {
1344: eval('vf.f'+i+'.selectedIndex=0;')
1345: }
1346: }
1347: }
1348: // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
1349: // clear out any that are set to 'lastname, firstnames' (2)
1350: if ((nw>=3) && (nw<=6)) {
1351: for (i=0;i<=vf.nfields.value;i++) {
1352: if (eval('vf.f'+i+'.selectedIndex')==2) {
1353: eval('vf.f'+i+'.selectedIndex=0;')
1354: }
1355: }
1356: }
1.123 raeburn 1357: $auth_update
1.1 raeburn 1358: }
1359:
1360: function clearpwd(vf) {
1361: var i;
1362: for (i=0;i<=vf.nfields.value;i++) {
1363: if (eval('vf.f'+i+'.selectedIndex')==9) {
1364: eval('vf.f'+i+'.selectedIndex=0;')
1365: }
1366: }
1367: }
1368:
1369: ENDPICK
1370: }
1371:
1372: ###############################################################
1373: ###############################################################
1374: sub upload_manager_javascript_reverse_associate {
1.123 raeburn 1375: my ($can_assign) = @_;
1.132 raeburn 1376: my ($auth_update,$numbuttons,$argreset);
1.123 raeburn 1377: if (ref($can_assign) eq 'HASH') {
1.132 raeburn 1378: if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
1379: $argreset .= " vf.krbarg.value='';\n";
1380: $numbuttons ++ ;
1381: }
1382: if ($can_assign->{'int'}) {
1383: $argreset .= " vf.intarg.value='';\n";
1384: $numbuttons ++;
1385: }
1386: if ($can_assign->{'loc'}) {
1387: $argreset .= " vf.locarg.value='';\n";
1388: $numbuttons ++;
1389: }
1390: if (!$can_assign->{'int'}) {
1391: my $warning = &mt('You may not specify an initial password, as this is only available when new users use LON-CAPA internal authentication.\n').
1392: &mt('Your current role does not have rights to create users with that authentication type.');
1.170 damieng 1393: &js_escape(\$warning);
1.132 raeburn 1394: $auth_update = <<"END";
1395: // Currently the initial password field is only supported for internal auth
1396: // (see bug 6368).
1397: if (tf==8 && nw!=0) {
1398: eval('vf.f'+tf+'.selectedIndex=0;')
1399: alert('$warning');
1400: }
1401: END
1402: } elsif ($numbuttons > 1) {
1.123 raeburn 1403: $auth_update = <<"END";
1404: // initial password specified, pick internal authentication
1405: if (tf==8 && nw!=0) {
1406: changed_radio('int',document.studentform);
1407: set_auth_radio_buttons('int',document.studentform);
1.132 raeburn 1408: $argreset
1409: }
1410:
1.123 raeburn 1411: END
1412: }
1413: }
1.132 raeburn 1414:
1.1 raeburn 1415: return(<<ENDPICK);
1416: function verify(vf,sec_caller) {
1417: var founduname=0;
1418: var foundpwd=0;
1419: var foundname=0;
1420: var foundid=0;
1421: var foundsec=0;
1.131 raeburn 1422: var foundemail=0;
1.1 raeburn 1423: var foundrole=0;
1.57 raeburn 1424: var founddomain=0;
1.84 raeburn 1425: var foundinststatus=0;
1.150 raeburn 1426: var foundcredits=0;
1.1 raeburn 1427: var tw;
1428: for (i=0;i<=vf.nfields.value;i++) {
1429: tw=eval('vf.f'+i+'.selectedIndex');
1430: if (i==0 && tw!=0) { founduname=1; }
1431: if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
1432: if (i==6 && tw!=0) { foundid=1; }
1433: if (i==7 && tw!=0) { foundsec=1; }
1434: if (i==8 && tw!=0) { foundpwd=1; }
1.130 raeburn 1435: if (i==9 && tw!=0) { foundemail=1; }
1436: if (i==10 && tw!=0) { foundrole=1; }
1437: if (i==11 && tw!=0) { founddomain=1; }
1438: if (i==12 && tw!=0) { foundinstatus=1; }
1.150 raeburn 1439: if (i==13 && tw!=0) { foundcredits=1; }
1.1 raeburn 1440: }
1.150 raeburn 1441: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits);
1.1 raeburn 1442: }
1443:
1444: function flip(vf,tf) {
1445: var nw=eval('vf.f'+tf+'.selectedIndex');
1446: var i;
1447: // picked the all one name field, reset the other name ones to blank
1448: if (tf==1 && nw!=0) {
1449: for (i=2;i<=5;i++) {
1450: eval('vf.f'+i+'.selectedIndex=0;')
1451: }
1452: }
1453: //picked one of the piecewise name fields, reset the all in
1454: //one field to blank
1455: if ((tf>=2) && (tf<=5) && (nw!=0)) {
1456: eval('vf.f1.selectedIndex=0;')
1457: }
1.123 raeburn 1458: $auth_update
1.1 raeburn 1459: }
1460:
1461: function clearpwd(vf) {
1462: var i;
1463: if (eval('vf.f8.selectedIndex')!=0) {
1464: eval('vf.f8.selectedIndex=0;')
1465: }
1466: }
1467: ENDPICK
1468: }
1469:
1470: ###############################################################
1471: ###############################################################
1472: sub print_upload_manager_footer {
1.150 raeburn 1473: my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context,$permission,$crstype,
1474: $showcredits) = @_;
1.22 raeburn 1475: my $form = 'document.studentform';
1476: my $formname = 'studentform';
1.1 raeburn 1477: my ($krbdef,$krbdefdom) =
1478: &Apache::loncommon::get_kerberos_defaults($defdom);
1.22 raeburn 1479: my %param = ( formname => $form,
1.1 raeburn 1480: kerb_def_dom => $krbdefdom,
1481: kerb_def_auth => $krbdef
1482: );
1483: if (exists($env{'form.ipwd_choice'}) &&
1484: defined($env{'form.ipwd_choice'}) &&
1485: $env{'form.ipwd_choice'} ne '') {
1486: $param{'curr_authtype'} = 'int';
1487: }
1488: my $krbform = &Apache::loncommon::authform_kerberos(%param);
1489: my $intform = &Apache::loncommon::authform_internal(%param);
1490: my $locform = &Apache::loncommon::authform_local(%param);
1.194 raeburn 1491: my $ltiform = &Apache::loncommon::authform_lti(%param);
1.22 raeburn 1492: my $date_table = &date_setting_table(undef,undef,$context,undef,
1.101 raeburn 1493: $formname,$permission,$crstype);
1.95 bisitz 1494:
1.1 raeburn 1495: my $Str = "\n".'<div class="LC_left_float">';
1496: $Str .= &hidden_input('nfields',$i);
1497: $Str .= &hidden_input('keyfields',$keyfields);
1.95 bisitz 1498:
1499: $Str .= '<h3>'.&mt('Options').'</h3>'
1500: .&Apache::lonhtmlcommon::start_pick_box();
1501:
1502: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Login Type'));
1.1 raeburn 1503: if ($context eq 'domain') {
1.95 bisitz 1504: $Str .= '<p>'
1505: .&mt('Change authentication for existing users in domain "[_1]" to these settings?'
1506: ,$defdom)
1507: .' <span class="LC_nobreak"><label>'
1508: .'<input type="radio" name="changeauth" value="No" checked="checked" />'
1509: .&mt('No').'</label>'
1510: .' <label>'
1511: .'<input type="radio" name="changeauth" value="Yes" />'
1512: .&mt('Yes').'</label>'
1513: .'</span></p>';
1.1 raeburn 1514: } else {
1.95 bisitz 1515: $Str .= '<p class="LC_info">'."\n".
1516: &mt('This will not take effect if the user already exists.').
1.1 raeburn 1517: &Apache::loncommon::help_open_topic('Auth_Options').
1518: "</p>\n";
1519: }
1.194 raeburn 1520: $Str .= &set_login($defdom,$krbform,$intform,$locform,$ltiform);
1.95 bisitz 1521:
1.1 raeburn 1522: my ($home_server_pick,$numlib) =
1523: &Apache::loncommon::home_server_form_item($defdom,'lcserver',
1524: 'default','hide');
1525: if ($numlib > 1) {
1.97 raeburn 1526: $Str .= &Apache::lonhtmlcommon::row_closure()
1527: .&Apache::lonhtmlcommon::row_title(
1.95 bisitz 1528: &mt('LON-CAPA Home Server for New Users'))
1529: .&mt('LON-CAPA domain: [_1] with home server:','"'.$defdom.'"')
1530: .$home_server_pick
1531: .&Apache::lonhtmlcommon::row_closure();
1532: } else {
1.97 raeburn 1533: $Str .= $home_server_pick.
1534: &Apache::lonhtmlcommon::row_closure();
1.95 bisitz 1535: }
1536:
1.188 raeburn 1537: my ($trusted,$untrusted);
1.185 raeburn 1538: if ($context eq 'course') {
1.188 raeburn 1539: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.185 raeburn 1540: } elsif ($context eq 'author') {
1.188 raeburn 1541: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.185 raeburn 1542: }
1.95 bisitz 1543: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain'))
1.188 raeburn 1544: .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1,undef,$trusted,$untrusted)
1.95 bisitz 1545: .&Apache::lonhtmlcommon::row_closure();
1546:
1547: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Starting and Ending Dates'))
1548: ."<p>\n".$date_table."</p>\n"
1549: .&Apache::lonhtmlcommon::row_closure();
1550:
1.1 raeburn 1551: if ($context eq 'domain') {
1.95 bisitz 1552: $Str .= &Apache::lonhtmlcommon::row_title(
1553: &mt('Settings for assigning roles'))
1554: .&mt('Pick the action to take on roles for these users:').'<br />'
1555: .'<span class="LC_nobreak"><label>'
1556: .'<input type="radio" name="roleaction" value="norole" checked="checked" />'
1557: .' '.&mt('No role changes').'</label>'
1558: .' <label>'
1559: .'<input type="radio" name="roleaction" value="domain" />'
1560: .' '.&mt('Add a domain role').'</label>'
1561: .' <label>'
1562: .'<input type="radio" name="roleaction" value="course" />'
1.103 raeburn 1563: .' '.&mt('Add a course/community role').'</label>'
1.95 bisitz 1564: .'</span>';
1565: } elsif ($context eq 'author') {
1566: $Str .= &Apache::lonhtmlcommon::row_title(
1567: &mt('Default role'))
1568: .&mt('Choose the role to assign to users without a value specified in the uploaded file.')
1.1 raeburn 1569: } elsif ($context eq 'course') {
1.150 raeburn 1570: if ($showcredits) {
1571: $Str .= &Apache::lonhtmlcommon::row_title(
1572: &mt('Default role, section and credits'))
1573: .&mt('Choose the role and/or section(s) and/or credits to assign to users without values specified in the uploaded file.');
1574: } else {
1575: $Str .= &Apache::lonhtmlcommon::row_title(
1.95 bisitz 1576: &mt('Default role and section'))
1.150 raeburn 1577: .&mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file.');
1578: }
1.95 bisitz 1579: } else {
1580: $Str .= &Apache::lonhtmlcommon::row_title(
1581: &mt('Default role and/or section(s)'))
1582: .&mt('Role and/or section(s) for users without values specified in the uploaded file.');
1.1 raeburn 1583: }
1.22 raeburn 1584: if (($context eq 'domain') || ($context eq 'author')) {
1.95 bisitz 1585: $Str .= '<br />';
1.150 raeburn 1586: my ($options,$cb_script,$coursepick) =
1587: &default_role_selector($context,1,'',$showcredits);
1.22 raeburn 1588: if ($context eq 'domain') {
1.95 bisitz 1589: $Str .= '<p>'
1590: .'<b>'.&mt('Domain Level').'</b><br />'
1591: .$options
1592: .'</p><p>'
1593: .'<b>'.&mt('Course Level').'</b>'
1594: .'</p>'
1595: .$cb_script.$coursepick
1596: .&Apache::lonhtmlcommon::row_closure();
1.22 raeburn 1597: } elsif ($context eq 'author') {
1.95 bisitz 1598: $Str .= $options
1599: .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
1.22 raeburn 1600: }
1.1 raeburn 1601: } else {
1.22 raeburn 1602: my ($cnum,$cdom) = &get_course_identity();
1603: my $rowtitle = &mt('section');
1.150 raeburn 1604: my $defaultcredits;
1605: if ($showcredits) {
1606: $defaultcredits = &get_defaultcredits();
1607: }
1608: my $secbox = §ion_picker($cdom,$cnum,'Any',$rowtitle,$permission,
1609: $context,'upload',$crstype,$showcredits,
1610: $defaultcredits);
1.95 bisitz 1611: $Str .= $secbox
1612: .&Apache::lonhtmlcommon::row_closure();
1.101 raeburn 1613: my %lt;
1614: if ($crstype eq 'Community') {
1615: %lt = &Apache::lonlocal::texthash (
1616: disp => 'Display members with current/future access who are not in the uploaded file',
1617: stus => 'Members selected from this list can be dropped.'
1618: );
1619: } else {
1620: %lt = &Apache::lonlocal::texthash (
1621: disp => 'Display students with current/future access who are not in the uploaded file',
1622: stus => 'Students selected from this list can be dropped.'
1623: );
1624: }
1.95 bisitz 1625: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Full Update'))
1.101 raeburn 1626: .'<label><input type="checkbox" name="fullup" value="yes" />'
1627: .' '.$lt{'disp'}
1.95 bisitz 1628: .'</label><br />'
1.101 raeburn 1629: .$lt{'stus'}
1.95 bisitz 1630: .&Apache::lonhtmlcommon::row_closure();
1.1 raeburn 1631: }
1.5 raeburn 1632: if ($context eq 'course' || $context eq 'domain') {
1.161 bisitz 1633: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID'))
1634: .&forceid_change($context)
1635: .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
1.5 raeburn 1636: }
1.95 bisitz 1637:
1638: $Str .= &Apache::lonhtmlcommon::end_pick_box();
1.73 bisitz 1639: $Str .= '</div>';
1.95 bisitz 1640:
1641: # Footer
1642: $Str .= '<div class="LC_clear_float_footer">'
1643: .'<hr />';
1.1 raeburn 1644: if ($context eq 'course') {
1.95 bisitz 1645: $Str .= '<p class="LC_info">'
1.103 raeburn 1646: .&mt('Note: This operation may be time consuming when adding several users.')
1.95 bisitz 1647: .'</p>';
1.73 bisitz 1648: }
1.95 bisitz 1649: $Str .= '<p><input type="button"'
1.96 bisitz 1650: .' onclick="javascript:verify(this.form,this.form.csec)"'
1651: .' value="'.&mt('Update Users').'" />'
1.95 bisitz 1652: .'</p>'."\n"
1.73 bisitz 1653: .'</div>';
1.1 raeburn 1654: $r->print($Str);
1655: return;
1656: }
1657:
1.150 raeburn 1658: sub get_defaultcredits {
1659: my ($cdom,$cnum) = @_;
1660:
1661: if ($cdom eq '' || $cnum eq '') {
1662: return unless ($env{'request.course.id'});
1663: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1664: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1665: }
1666: return unless(($cdom =~ /^$match_domain$/) && ($cnum =~ /^$match_courseid$/));
1667: my ($defaultcredits,$domdefcredits);
1668: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
1.160 raeburn 1669: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
1.150 raeburn 1670: my $instcode = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
1671: if ($instcode) {
1672: $domdefcredits = $domdefaults{'officialcredits'};
1.160 raeburn 1673: } elsif ($env{'course.'.$cdom.'_'.$cnum.'.internal.textbook'}) {
1674: $domdefcredits = $domdefaults{'textbookcredits'};
1.150 raeburn 1675: } else {
1676: $domdefcredits = $domdefaults{'unofficialcredits'};
1677: }
1678: } else {
1679: return;
1680: }
1681:
1682: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
1683: $defaultcredits = $env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'};
1684: } elsif (exists($env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'})) {
1685: $defaultcredits = $env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'};
1686: } else {
1687: my %crsinfo =
1688: &Apache::lonnet::coursedescription("$cdom/$cnum",{'one_time' => 1});
1689: $defaultcredits = $crsinfo{'internal.defaultcredits'};
1690: }
1691: if ($defaultcredits eq '') {
1692: $defaultcredits = $domdefcredits;
1693: }
1694: return $defaultcredits;
1695: }
1696:
1.5 raeburn 1697: sub forceid_change {
1698: my ($context) = @_;
1699: my $output =
1.161 bisitz 1700: '<label><input type="checkbox" name="forceid" value="yes" />'
1.164 bisitz 1701: .&mt('Force change of existing ID')
1.163 raeburn 1702: .'</label>'.&Apache::loncommon::help_open_topic('ForceIDChange')."\n";
1.5 raeburn 1703: if ($context eq 'domain') {
1.163 raeburn 1704: $output .=
1705: '<br />'
1706: .'<label><input type="checkbox" name="recurseid" value="yes" />'
1707: .&mt("Update ID in user's course(s).").'</label>'."\n";
1.5 raeburn 1708: }
1709: return $output;
1710: }
1711:
1.1 raeburn 1712: ###############################################################
1713: ###############################################################
1714: sub print_upload_manager_form {
1.150 raeburn 1715: my ($r,$context,$permission,$crstype,$showcredits) = @_;
1.1 raeburn 1716: my $firstLine;
1717: my $datatoken;
1718: if (!$env{'form.datatoken'}) {
1719: $datatoken=&Apache::loncommon::upfile_store($r);
1720: } else {
1.189 raeburn 1721: $datatoken=&Apache::loncommon::valid_datatoken($env{'form.datatoken'});
1722: if ($datatoken ne '') {
1723: &Apache::loncommon::load_tmp_file($r,$datatoken);
1724: }
1.1 raeburn 1725: }
1.193 raeburn 1726: if ($datatoken eq '') {
1727: $r->print('<p class="LC_error">'.&mt('Error').': '.
1728: &mt('Invalid datatoken').'</p>');
1729: return 'missingdata';
1730: }
1.1 raeburn 1731: my @records=&Apache::loncommon::upfile_record_sep();
1732: if($env{'form.noFirstLine'}){
1733: $firstLine=shift(@records);
1734: }
1735: my $total=$#records;
1736: my $distotal=$total+1;
1737: my $today=time;
1738: my $halfyear=$today+15552000;
1739: #
1740: # Restore memorized settings
1741: my $col_setting_names = { 'username_choice' => 'scalar', # column settings
1742: 'names_choice' => 'scalar',
1743: 'fname_choice' => 'scalar',
1744: 'mname_choice' => 'scalar',
1745: 'lname_choice' => 'scalar',
1746: 'gen_choice' => 'scalar',
1747: 'id_choice' => 'scalar',
1748: 'sec_choice' => 'scalar',
1749: 'ipwd_choice' => 'scalar',
1750: 'email_choice' => 'scalar',
1751: 'role_choice' => 'scalar',
1.57 raeburn 1752: 'domain_choice' => 'scalar',
1.84 raeburn 1753: 'inststatus_choice' => 'scalar',
1.1 raeburn 1754: };
1.150 raeburn 1755: if ($showcredits) {
1756: $col_setting_names->{'credits_choice'} = 'scalar';
1757: }
1.1 raeburn 1758: if ($context eq 'course') {
1759: &Apache::loncommon::restore_course_settings('enrollment_upload',
1760: $col_setting_names);
1761: } else {
1762: &Apache::loncommon::restore_settings($context,'user_upload',
1763: $col_setting_names);
1764: }
1.150 raeburn 1765: my $defdom = $env{'request.role.domain'};
1.1 raeburn 1766: #
1767: # Determine kerberos parameters as appropriate
1768: my ($krbdef,$krbdefdom) =
1769: &Apache::loncommon::get_kerberos_defaults($defdom);
1770: #
1.123 raeburn 1771: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($defdom);
1.22 raeburn 1772: &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
1.123 raeburn 1773: $permission,$crstype,\%can_assign);
1.1 raeburn 1774: my $i;
1775: my $keyfields;
1776: if ($total>=0) {
1777: my @field=
1778: (['username',&mt('Username'), $env{'form.username_choice'}],
1779: ['names',&mt('Last Name, First Names'),$env{'form.names_choice'}],
1780: ['fname',&mt('First Name'), $env{'form.fname_choice'}],
1781: ['mname',&mt('Middle Names/Initials'),$env{'form.mname_choice'}],
1782: ['lname',&mt('Last Name'), $env{'form.lname_choice'}],
1783: ['gen', &mt('Generation'), $env{'form.gen_choice'}],
1.61 bisitz 1784: ['id', &mt('Student/Employee ID'),$env{'form.id_choice'}],
1.1 raeburn 1785: ['sec', &mt('Section'), $env{'form.sec_choice'}],
1786: ['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
1787: ['email',&mt('E-mail Address'), $env{'form.email_choice'}],
1.57 raeburn 1788: ['role',&mt('Role'), $env{'form.role_choice'}],
1.84 raeburn 1789: ['domain',&mt('Domain'), $env{'form.domain_choice'}],
1790: ['inststatus',&mt('Affiliation'), $env{'form.inststatus_choice'}]);
1.150 raeburn 1791: if ($showcredits) {
1792: push(@field,
1793: ['credits',&mt('Student Credits'), $env{'form.credits_choice'}]);
1794: }
1.1 raeburn 1795: if ($env{'form.upfile_associate'} eq 'reverse') {
1796: &Apache::loncommon::csv_print_samples($r,\@records);
1797: $i=&Apache::loncommon::csv_print_select_table($r,\@records,
1798: \@field);
1799: foreach (@field) {
1800: $keyfields.=$_->[0].',';
1801: }
1802: chop($keyfields);
1803: } else {
1804: unshift(@field,['none','']);
1805: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
1806: \@field);
1807: my %sone=&Apache::loncommon::record_sep($records[0]);
1808: $keyfields=join(',',sort(keys(%sone)));
1809: }
1810: }
1811: &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
1.150 raeburn 1812: $context,$permission,$crstype,$showcredits);
1.193 raeburn 1813: return 'ok';
1.1 raeburn 1814: }
1815:
1816: sub setup_date_selectors {
1.22 raeburn 1817: my ($starttime,$endtime,$mode,$nolink,$formname) = @_;
1818: if ($formname eq '') {
1819: $formname = 'studentform';
1820: }
1.1 raeburn 1821: if (! defined($starttime)) {
1822: $starttime = time;
1823: unless ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1824: if (exists($env{'course.'.$env{'request.course.id'}.
1825: '.default_enrollment_start_date'})) {
1826: $starttime = $env{'course.'.$env{'request.course.id'}.
1827: '.default_enrollment_start_date'};
1828: }
1829: }
1830: }
1831: if (! defined($endtime)) {
1832: $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1833: unless ($mode eq 'createcourse') {
1834: if (exists($env{'course.'.$env{'request.course.id'}.
1835: '.default_enrollment_end_date'})) {
1836: $endtime = $env{'course.'.$env{'request.course.id'}.
1837: '.default_enrollment_end_date'};
1838: }
1839: }
1840: }
1.11 raeburn 1841:
1842: my $startdateform =
1.22 raeburn 1843: &Apache::lonhtmlcommon::date_setter($formname,'startdate',$starttime,
1.11 raeburn 1844: undef,undef,undef,undef,undef,undef,undef,$nolink);
1845:
1846: my $enddateform =
1.22 raeburn 1847: &Apache::lonhtmlcommon::date_setter($formname,'enddate',$endtime,
1.11 raeburn 1848: undef,undef,undef,undef,undef,undef,undef,$nolink);
1849:
1.1 raeburn 1850: if ($mode eq 'create_enrolldates') {
1851: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1852: 'startenroll',
1853: $starttime);
1854: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1855: 'endenroll',
1856: $endtime);
1857: }
1858: if ($mode eq 'create_defaultdates') {
1859: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1860: 'startaccess',
1861: $starttime);
1862: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1863: 'endaccess',
1864: $endtime);
1865: }
1866: return ($startdateform,$enddateform);
1867: }
1868:
1869:
1870: sub get_dates_from_form {
1.54 raeburn 1871: my ($startname,$endname) = @_;
1872: if ($startname eq '') {
1873: $startname = 'startdate';
1874: }
1875: if ($endname eq '') {
1876: $endname = 'enddate';
1877: }
1878: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
1879: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.1 raeburn 1880: if ($env{'form.no_end_date'}) {
1881: $enddate = 0;
1882: }
1883: return ($startdate,$enddate);
1884: }
1885:
1886: sub date_setting_table {
1.101 raeburn 1887: my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission,$crstype) = @_;
1.11 raeburn 1888: my $nolink;
1889: if ($bulkaction) {
1890: $nolink = 1;
1891: }
1892: my ($startform,$endform) =
1.22 raeburn 1893: &setup_date_selectors($starttime,$endtime,$mode,$nolink,$formname);
1.1 raeburn 1894: my $dateDefault;
1895: if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1896: $dateDefault = ' ';
1.13 raeburn 1897: } elsif ($mode ne 'author' && $mode ne 'domain') {
1.11 raeburn 1898: if (($bulkaction eq 'reenable') ||
1899: ($bulkaction eq 'activate') ||
1.22 raeburn 1900: ($bulkaction eq 'chgdates') ||
1901: ($env{'form.action'} eq 'upload')) {
1902: if ($env{'request.course.sec'} eq '') {
1903: $dateDefault = '<span class="LC_nobreak">'.
1.101 raeburn 1904: '<label><input type="checkbox" name="makedatesdefault" value="1" /> ';
1905: if ($crstype eq 'Community') {
1906: $dateDefault .= &mt("make these dates the default access dates for future community enrollment");
1907: } else {
1908: $dateDefault .= &mt("make these dates the default access dates for future course enrollment");
1909: }
1910: $dateDefault .= '</label></span>';
1.22 raeburn 1911: }
1.11 raeburn 1912: }
1.1 raeburn 1913: }
1.11 raeburn 1914: my $perpetual = '<span class="LC_nobreak"><label><input type="checkbox" name="no_end_date"';
1.1 raeburn 1915: if (defined($endtime) && $endtime == 0) {
1.70 bisitz 1916: $perpetual .= ' checked="checked"';
1.1 raeburn 1917: }
1.11 raeburn 1918: $perpetual.= ' /> '.&mt('no ending date').'</label></span>';
1.1 raeburn 1919: if ($mode eq 'create_enrolldates') {
1920: $perpetual = ' ';
1921: }
1.11 raeburn 1922: my $result = &Apache::lonhtmlcommon::start_pick_box()."\n";
1923: $result .= &Apache::lonhtmlcommon::row_title(&mt('Starting Date'),
1924: 'LC_oddrow_value')."\n".
1925: $startform."\n".
1926: &Apache::lonhtmlcommon::row_closure(1).
1927: &Apache::lonhtmlcommon::row_title(&mt('Ending Date'),
1928: 'LC_oddrow_value')."\n".
1929: $endform.' '.$perpetual.
1930: &Apache::lonhtmlcommon::row_closure(1).
1.22 raeburn 1931: &Apache::lonhtmlcommon::end_pick_box();
1.1 raeburn 1932: if ($dateDefault) {
1933: $result .= $dateDefault.'<br />'."\n";
1934: }
1935: return $result;
1936: }
1937:
1938: sub make_dates_default {
1.101 raeburn 1939: my ($startdate,$enddate,$context,$crstype) = @_;
1.1 raeburn 1940: my $result = '';
1941: if ($context eq 'course') {
1.17 raeburn 1942: my ($cnum,$cdom) = &get_course_identity();
1.1 raeburn 1943: my $put_result = &Apache::lonnet::put('environment',
1944: {'default_enrollment_start_date'=>$startdate,
1.17 raeburn 1945: 'default_enrollment_end_date' =>$enddate},$cdom,$cnum);
1.1 raeburn 1946: if ($put_result eq 'ok') {
1.101 raeburn 1947: if ($crstype eq 'Community') {
1948: $result .= &mt('Set default start and end access dates for community.');
1949: } else {
1950: $result .= &mt('Set default start and end access dates for course.');
1951: }
1952: $result .= '<br />'."\n";
1.1 raeburn 1953: #
1954: # Refresh the course environment
1955: &Apache::lonnet::coursedescription($env{'request.course.id'},
1956: {'freshen_cache' => 1});
1957: } else {
1.101 raeburn 1958: if ($crstype eq 'Community') {
1959: $result .= &mt('Unable to set default access dates for community');
1960: } else {
1961: $result .= &mt('Unable to set default access dates for course');
1962: }
1963: $result .= ':'.$put_result.'<br />';
1.1 raeburn 1964: }
1965: }
1966: return $result;
1967: }
1968:
1969: sub default_role_selector {
1.150 raeburn 1970: my ($context,$checkpriv,$crstype,$showcredits) = @_;
1.1 raeburn 1971: my %customroles;
1972: my ($options,$coursepick,$cb_jscript);
1.13 raeburn 1973: if ($context ne 'author') {
1.104 raeburn 1974: %customroles = &my_custom_roles($crstype);
1.1 raeburn 1975: }
1976:
1977: my %lt=&Apache::lonlocal::texthash(
1978: 'rol' => "Role",
1979: 'grs' => "Section",
1980: 'exs' => "Existing sections",
1981: 'new' => "New section",
1.150 raeburn 1982: 'crd' => "Credits",
1.1 raeburn 1983: );
1984: $options = '<select name="defaultrole">'."\n".
1985: ' <option value="">'.&mt('Please select').'</option>'."\n";
1986: if ($context eq 'course') {
1.101 raeburn 1987: $options .= &default_course_roles($context,$checkpriv,$crstype,%customroles);
1.13 raeburn 1988: } elsif ($context eq 'author') {
1.2 raeburn 1989: my @roles = &construction_space_roles($checkpriv);
1.1 raeburn 1990: foreach my $role (@roles) {
1991: my $plrole=&Apache::lonnet::plaintext($role);
1992: $options .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1993: }
1994: } elsif ($context eq 'domain') {
1.2 raeburn 1995: my @roles = &domain_roles($checkpriv);
1.1 raeburn 1996: foreach my $role (@roles) {
1997: my $plrole=&Apache::lonnet::plaintext($role);
1998: $options .= ' <option value="'.$role.'">'.$plrole.'</option>';
1999: }
2000: my $courseform = &Apache::loncommon::selectcourse_link
1.103 raeburn 2001: ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course/Community');
1.150 raeburn 2002: my ($credit_elem,$creditsinput);
2003: if ($showcredits) {
2004: $credit_elem = 'credits';
2005: $creditsinput = '<td><input type="text" name="credits" value="" /></td>';
2006: }
1.1 raeburn 2007: $cb_jscript =
1.150 raeburn 2008: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform','courserole','Course/Community',$credit_elem);
1.1 raeburn 2009: $coursepick = &Apache::loncommon::start_data_table().
2010: &Apache::loncommon::start_data_table_header_row().
2011: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th>'.
2012: '<th>'.$lt{'grs'}.'</th>'.
1.150 raeburn 2013: '<th>'.$lt{'crd'}.'</th>'.
1.1 raeburn 2014: &Apache::loncommon::end_data_table_header_row().
2015: &Apache::loncommon::start_data_table_row()."\n".
1.103 raeburn 2016: '<td><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'studentform','dccourse','dcdomain','coursedesc','','','','crstype'".')" /></td>'."\n".
1.1 raeburn 2017: '<td><select name="courserole">'."\n".
1.101 raeburn 2018: &default_course_roles($context,$checkpriv,'Course',%customroles)."\n".
1.1 raeburn 2019: '</select></td><td>'.
2020: '<table class="LC_createuser">'.
1.162 bisitz 2021: '<tr class="LC_section_row"><td valign="top">'.
1.22 raeburn 2022: $lt{'exs'}.'<br /><select name="currsec">'.
1.162 bisitz 2023: ' <option value=""><--'.&mt('Pick course first').
1.1 raeburn 2024: '</select></td>'.
2025: '<td> </td>'.
2026: '<td valign="top">'.$lt{'new'}.'<br />'.
2027: '<input type="text" name="newsec" value="" size="5" />'.
1.22 raeburn 2028: '<input type="hidden" name="groups" value="" />'.
2029: '<input type="hidden" name="sections" value="" />'.
2030: '<input type="hidden" name="origdom" value="'.
2031: $env{'request.role.domain'}.'" />'.
2032: '<input type="hidden" name="dccourse" value="" />'.
2033: '<input type="hidden" name="dcdomain" value="" />'.
1.103 raeburn 2034: '<input type="hidden" name="crstype" value="" />'.
1.150 raeburn 2035: '</td></tr></table></td>'.$creditsinput.
1.1 raeburn 2036: &Apache::loncommon::end_data_table_row().
1.22 raeburn 2037: &Apache::loncommon::end_data_table()."\n";
1.1 raeburn 2038: }
2039: $options .= '</select>';
2040: return ($options,$cb_jscript,$coursepick);
2041: }
2042:
2043: sub default_course_roles {
1.101 raeburn 2044: my ($context,$checkpriv,$crstype,%customroles) = @_;
1.1 raeburn 2045: my $output;
1.17 raeburn 2046: my $custom = 1;
1.101 raeburn 2047: my @roles = &course_roles($context,$checkpriv,$custom,lc($crstype));
1.1 raeburn 2048: foreach my $role (@roles) {
1.22 raeburn 2049: if ($role ne 'cr') {
1.101 raeburn 2050: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.22 raeburn 2051: $output .= ' <option value="'.$role.'">'.$plrole.'</option>';
2052: }
1.1 raeburn 2053: }
2054: if (keys(%customroles) > 0) {
1.22 raeburn 2055: if (grep(/^cr$/,@roles)) {
2056: foreach my $cust (sort(keys(%customroles))) {
2057: my $custrole='cr_'.$env{'user.domain'}.
2058: '_'.$env{'user.name'}.'_'.$cust;
2059: $output .= ' <option value="'.$custrole.'">'.$cust.'</option>';
2060: }
1.1 raeburn 2061: }
2062: }
2063: return $output;
2064: }
2065:
2066: sub construction_space_roles {
1.2 raeburn 2067: my ($checkpriv) = @_;
1.17 raeburn 2068: my @allroles = &roles_by_context('author');
1.1 raeburn 2069: my @roles;
1.2 raeburn 2070: if ($checkpriv) {
2071: foreach my $role (@allroles) {
2072: if (&Apache::lonnet::allowed('c'.$role,$env{'user.domain'}.'/'.$env{'user.name'})) {
2073: push(@roles,$role);
1.218 raeburn 2074: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2075: my ($audom,$auname) = ($1,$2);
2076: if (($role eq 'ca') || ($role eq 'aa')) {
2077: if ((&Apache::lonnet::allowed('v'.$role,,$audom.'/'.$auname)) &&
2078: ($env{"environment.internal.manager./$audom/$auname"})) {
2079: push(@roles,$role);
2080: }
2081: }
1.2 raeburn 2082: }
1.1 raeburn 2083: }
1.2 raeburn 2084: return @roles;
2085: } else {
2086: return @allroles;
1.1 raeburn 2087: }
2088: }
2089:
2090: sub domain_roles {
1.2 raeburn 2091: my ($checkpriv) = @_;
1.17 raeburn 2092: my @allroles = &roles_by_context('domain');
1.1 raeburn 2093: my @roles;
1.2 raeburn 2094: if ($checkpriv) {
2095: foreach my $role (@allroles) {
2096: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
2097: push(@roles,$role);
2098: }
1.1 raeburn 2099: }
1.2 raeburn 2100: return @roles;
2101: } else {
2102: return @allroles;
1.1 raeburn 2103: }
2104: }
2105:
2106: sub course_roles {
1.101 raeburn 2107: my ($context,$checkpriv,$custom,$roletype) = @_;
1.102 raeburn 2108: my $crstype;
2109: if ($roletype eq 'community') {
2110: $crstype = 'Community' ;
2111: } else {
2112: $crstype = 'Course';
2113: }
2114: my @allroles = &roles_by_context('course',$custom,$crstype);
1.1 raeburn 2115: my @roles;
2116: if ($context eq 'domain') {
2117: @roles = @allroles;
2118: } elsif ($context eq 'course') {
2119: if ($env{'request.course.id'}) {
1.2 raeburn 2120: if ($checkpriv) {
2121: foreach my $role (@allroles) {
2122: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
2123: push(@roles,$role);
2124: } else {
1.101 raeburn 2125: if ((($role ne 'cc') && ($role ne 'co')) && ($env{'request.course.sec'} ne '')) {
1.22 raeburn 2126: if (&Apache::lonnet::allowed('c'.$role,
1.2 raeburn 2127: $env{'request.course.id'}.'/'.
1.22 raeburn 2128: $env{'request.course.sec'})) {
1.2 raeburn 2129: push(@roles,$role);
2130: }
1.1 raeburn 2131: }
2132: }
2133: }
1.2 raeburn 2134: } else {
2135: @roles = @allroles;
1.1 raeburn 2136: }
2137: }
2138: }
2139: return @roles;
2140: }
2141:
2142: sub curr_role_permissions {
1.101 raeburn 2143: my ($context,$setting,$checkpriv,$type) = @_;
1.17 raeburn 2144: my $custom = 1;
1.1 raeburn 2145: my @roles;
1.13 raeburn 2146: if ($context eq 'author') {
1.2 raeburn 2147: @roles = &construction_space_roles($checkpriv);
1.1 raeburn 2148: } elsif ($context eq 'domain') {
2149: if ($setting eq 'course') {
1.101 raeburn 2150: @roles = &course_roles($context,$checkpriv,$custom,$type);
1.1 raeburn 2151: } else {
1.2 raeburn 2152: @roles = &domain_roles($checkpriv);
1.1 raeburn 2153: }
2154: } elsif ($context eq 'course') {
1.101 raeburn 2155: @roles = &course_roles($context,$checkpriv,$custom,$type);
1.1 raeburn 2156: }
2157: return @roles;
2158: }
2159:
2160: # ======================================================= Existing Custom Roles
2161:
2162: sub my_custom_roles {
1.175 raeburn 2163: my ($crstype,$udom,$uname) = @_;
1.1 raeburn 2164: my %returnhash=();
1.137 raeburn 2165: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
1.175 raeburn 2166: my %rolehash=&Apache::lonnet::dump('roles',$udom,$uname);
1.104 raeburn 2167: foreach my $key (keys(%rolehash)) {
1.1 raeburn 2168: if ($key=~/^rolesdef\_(\w+)$/) {
1.207 raeburn 2169: my $role = $1;
1.104 raeburn 2170: if ($crstype eq 'Community') {
2171: next if ($rolehash{$key} =~ /bre\&S/);
2172: }
1.207 raeburn 2173: $returnhash{$role}=$role;
1.1 raeburn 2174: }
2175: }
2176: return %returnhash;
2177: }
2178:
1.2 raeburn 2179: sub print_userlist {
2180: my ($r,$mode,$permission,$context,$formname,$totcodes,$codetitles,
1.150 raeburn 2181: $idlist,$idlist_titles,$showcredits) = @_;
1.2 raeburn 2182: my $format = $env{'form.output'};
1.1 raeburn 2183: if (! exists($env{'form.sortby'})) {
2184: $env{'form.sortby'} = 'username';
2185: }
1.221 raeburn 2186: my ($showstart,$showend);
2187: if (($env{'form.Status'} eq '') && ($env{'form.phase'} eq '') &&
2188: ($env{'form.showrole'} eq '') && ($context eq 'course') &&
2189: ($env{'request.course.id'} ne '') &&
2190: ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'} ne '')) {
2191: my $now = time;
2192: my $startaccess = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
2193: my $endaccess = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
2194: if (($startaccess) && ($startaccess > $now)) {
2195: $env{'form.Status'} = 'Future';
2196: $showstart = 1;
2197: }
2198: if (($endaccess ne '') && ($endaccess != 0) && ($endaccess < $now)) {
2199: $env{'form.Status'} = 'Expired';
2200: undef($showstart);
2201: $showend = 1;
2202: }
2203: }
1.2 raeburn 2204: if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
2205: $env{'form.Status'} = 'Active';
1.1 raeburn 2206: }
1.140 raeburn 2207: my $onchange = "javascript:updateCols('Status');";
1.1 raeburn 2208: my $status_select = &Apache::lonhtmlcommon::StatusOptions
1.140 raeburn 2209: ($env{'form.Status'},undef,undef,$onchange);
1.1 raeburn 2210:
1.2 raeburn 2211: if ($env{'form.showrole'} eq '') {
1.13 raeburn 2212: if ($context eq 'course') {
2213: $env{'form.showrole'} = 'st';
2214: } else {
2215: $env{'form.showrole'} = 'Any';
2216: }
1.2 raeburn 2217: }
1.1 raeburn 2218: if (! defined($env{'form.output'}) ||
2219: $env{'form.output'} !~ /^(csv|excel|html)$/ ) {
2220: $env{'form.output'} = 'html';
2221: }
2222:
1.2 raeburn 2223: my @statuses;
2224: if ($env{'form.Status'} eq 'Any') {
2225: @statuses = ('previous','active','future');
2226: } elsif ($env{'form.Status'} eq 'Expired') {
2227: @statuses = ('previous');
2228: } elsif ($env{'form.Status'} eq 'Active') {
2229: @statuses = ('active');
2230: } elsif ($env{'form.Status'} eq 'Future') {
2231: @statuses = ('future');
2232: }
1.1 raeburn 2233:
2234: # Interface output
1.2 raeburn 2235: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
2236: '<input type="hidden" name="action" value="'.
1.1 raeburn 2237: $env{'form.action'}.'" />');
1.140 raeburn 2238: $r->print('<div>'."\n");
1.1 raeburn 2239: if ($env{'form.action'} ne 'modifystudent') {
2240: my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
2241: 'excel' => "Excel",
2242: 'html' => 'HTML');
1.140 raeburn 2243: my $output_selector = '<select size="1" name="output" onchange="javascript:updateCols('."'output'".');" >';
1.1 raeburn 2244: foreach my $outputformat ('html','csv','excel') {
1.96 bisitz 2245: my $option = '<option value="'.$outputformat.'"';
1.1 raeburn 2246: if ($outputformat eq $env{'form.output'}) {
1.96 bisitz 2247: $option .= ' selected="selected"';
1.1 raeburn 2248: }
2249: $option .='>'.$lt{$outputformat}.'</option>';
2250: $output_selector .= "\n".$option;
2251: }
2252: $output_selector .= '</select>';
1.140 raeburn 2253: $r->print('<span class="LC_nobreak">'
1.70 bisitz 2254: .&mt('Output Format: [_1]',$output_selector)
1.140 raeburn 2255: .'</span>'.(' 'x3));
1.70 bisitz 2256: }
1.140 raeburn 2257: $r->print('<span class="LC_nobreak">'
1.70 bisitz 2258: .&mt('User Status: [_1]',$status_select)
1.140 raeburn 2259: .'</span>'.(' 'x3)."\n");
1.2 raeburn 2260: my $roleselected = '';
2261: if ($env{'form.showrole'} eq 'Any') {
1.91 bisitz 2262: $roleselected = ' selected="selected"';
1.2 raeburn 2263: }
1.53 raeburn 2264: my ($cnum,$cdom);
2265: $r->print(&role_filter($context));
2266: if ($context eq 'course') {
2267: ($cnum,$cdom) = &get_course_identity();
2268: $r->print(§ion_group_filter($cnum,$cdom));
1.2 raeburn 2269: }
1.140 raeburn 2270: $r->print('</div><div class="LC_left_float">'.
1.221 raeburn 2271: &column_checkboxes($context,$mode,$formname,$showcredits,$showstart,$showend).
1.149 raeburn 2272: '</div>');
1.78 raeburn 2273: if ($env{'form.phase'} eq '') {
1.149 raeburn 2274: $r->print('<br clear="all" />'.
2275: &list_submit_button(&mt('Display List of Users'))."\n".
1.78 raeburn 2276: '<input type="hidden" name="phase" value="" /></form>');
2277: return;
2278: }
1.106 raeburn 2279: if (!(($context eq 'domain') &&
2280: (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
1.149 raeburn 2281: $r->print('<br clear="all" />'.
2282: &list_submit_button(&mt('Update Display'))."\n");
1.140 raeburn 2283: }
2284:
1.150 raeburn 2285: my @cols = &infocolumns($context,$mode,$showcredits);
1.140 raeburn 2286: if (!@cols) {
1.152 bisitz 2287: $r->print('<hr style="clear:both;" /><span class="LC_warning">'.
1.140 raeburn 2288: &mt('No user information selected for display.').'</span>'.
2289: '<input type="hidden" name="phase" value="display" /></form>'."\n");
2290: return;
1.2 raeburn 2291: }
2292: my ($indexhash,$keylist) = &make_keylist_array();
1.159 raeburn 2293: my (%userlist,%userinfo,$clearcoursepick,$needauthorquota,$needauthorusage);
1.102 raeburn 2294: if (($context eq 'domain') &&
2295: ($env{'form.roletype'} eq 'course') ||
2296: ($env{'form.roletype'} eq 'community')) {
2297: my ($crstype,$numcodes,$title,$warning);
2298: if ($env{'form.roletype'} eq 'course') {
2299: $crstype = 'Course';
2300: $numcodes = $totcodes;
2301: $title = &mt('Select Courses');
2302: $warning = &mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.');
2303: } elsif ($env{'form.roletype'} eq 'community') {
2304: $crstype = 'Community';
2305: $numcodes = 0;
2306: $title = &mt('Select Communities');
2307: $warning = &mt('Warning: data retrieval for multiple communities can take considerable time, as this operation is not currently optimized.');
2308: }
1.120 raeburn 2309: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1.3 raeburn 2310: my $courseform =
1.102 raeburn 2311: &Apache::lonhtmlcommon::course_selection($formname,$numcodes,
1.120 raeburn 2312: $codetitles,$idlist,$idlist_titles,$crstype,
2313: \@standardnames);
1.148 bisitz 2314: $r->print('<div class="LC_left_float">'.
2315: '<fieldset><legend>'.$title.'</legend>'."\n".
1.3 raeburn 2316: $courseform."\n".
1.148 bisitz 2317: '</fieldset></div><br clear="all" />'.
1.106 raeburn 2318: '<p><input type="hidden" name="origroletype" value="'.$env{'form.roletype'}.'" />'.
2319: &list_submit_button(&mt('Update Display')).
1.102 raeburn 2320: "\n".'</p><span class="LC_warning">'.$warning.'</span>'."\n");
1.106 raeburn 2321: $clearcoursepick = 0;
2322: if (($env{'form.origroletype'} ne '') &&
2323: ($env{'form.origroletype'} ne $env{'form.roletype'})) {
2324: $clearcoursepick = 1;
2325: }
2326: if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
1.147 bisitz 2327: $r->print('<hr />'.&mt('Searching ...').'<br /> <br />');
1.11 raeburn 2328: }
2329: } else {
1.152 bisitz 2330: $r->print('<hr style="clear:both;" /><div id="searching">'.&mt('Searching ...').'</div>');
1.3 raeburn 2331: }
2332: $r->rflush();
1.1 raeburn 2333: if ($context eq 'course') {
1.46 raeburn 2334: if (($env{'form.showrole'} eq 'st') || ($env{'form.showrole'} eq 'Any')) {
1.45 raeburn 2335: my $classlist = &Apache::loncoursedata::get_classlist();
1.66 raeburn 2336: if (ref($classlist) eq 'HASH') {
2337: %userlist = %{$classlist};
2338: }
1.45 raeburn 2339: }
1.43 raeburn 2340: if ($env{'form.showrole'} ne 'st') {
2341: my $showroles;
2342: if ($env{'form.showrole'} ne 'Any') {
2343: $showroles = [$env{'form.showrole'}];
1.3 raeburn 2344: } else {
1.43 raeburn 2345: $showroles = undef;
1.1 raeburn 2346: }
1.43 raeburn 2347: my $withsec = 1;
2348: my $hidepriv = 1;
2349: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
2350: \@statuses,$showroles,undef,$withsec,$hidepriv);
2351: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
2352: \%advrolehash,$permission);
1.1 raeburn 2353: }
1.2 raeburn 2354: } else {
2355: my (%cstr_roles,%dom_roles);
1.13 raeburn 2356: if ($context eq 'author') {
1.218 raeburn 2357: my @possroles = &roles_by_context($context);
2358: my @allowedroles;
1.2 raeburn 2359: # List co-authors and assistant co-authors
1.218 raeburn 2360: my ($auname,$audom);
2361: if ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2362: ($audom,$auname) = ($1,$2);
2363: foreach my $role (@possroles) {
2364: if ((&Apache::lonnet::allowed('v'.$role,"$audom/$auname")) ||
2365: (&Apache::lonnet::allowed('c'.$role,"$audom/$auname"))) {
2366: push(@allowedroles,$role);
2367: }
2368: }
2369: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
2370: if ($1 eq $env{'user.domain'}) {
2371: $auname = $env{'user.name'};
2372: $audom = $env{'user.domain'};
2373: }
2374: @allowedroles = @possroles;
2375: }
2376: if (($auname ne '') && ($audom ne '')) {
2377: %cstr_roles = &Apache::lonnet::get_my_roles($auname,$audom,undef,
2378: \@statuses,\@allowedroles);
2379: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
2380: \%cstr_roles,$permission);
2381: }
1.2 raeburn 2382: } elsif ($context eq 'domain') {
2383: if ($env{'form.roletype'} eq 'domain') {
1.159 raeburn 2384: if (grep(/^authorusage$/,@cols)) {
2385: $needauthorusage = 1;
2386: }
2387: if (grep(/^authorquota$/,@cols)) {
2388: $needauthorquota = 1;
2389: }
1.2 raeburn 2390: %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'});
2391: foreach my $key (keys(%dom_roles)) {
2392: if (ref($dom_roles{$key}) eq 'HASH') {
2393: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 2394: \%userinfo,$dom_roles{$key},$permission);
1.2 raeburn 2395: }
2396: }
1.13 raeburn 2397: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 2398: my %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'},['au']);
2399: my %coauthors;
2400: foreach my $key (keys(%dom_roles)) {
2401: if (ref($dom_roles{$key}) eq 'HASH') {
2402: if ($env{'form.showrole'} eq 'au') {
2403: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 2404: \%userinfo,$dom_roles{$key},$permission);
1.2 raeburn 2405: } else {
2406: my @possroles;
2407: if ($env{'form.showrole'} eq 'Any') {
1.22 raeburn 2408: @possroles = &roles_by_context('author');
1.2 raeburn 2409: } else {
2410: @possroles = ($env{'form.showrole'});
2411: }
2412: foreach my $author (sort(keys(%{$dom_roles{$key}}))) {
1.22 raeburn 2413: my ($role,$authorname,$authordom) = split(/:/,$author,-1);
1.2 raeburn 2414: my $extent = '/'.$authordom.'/'.$authorname;
2415: %{$coauthors{$extent}} =
2416: &Apache::lonnet::get_my_roles($authorname,
2417: $authordom,undef,\@statuses,\@possroles);
2418: }
2419: &gather_userinfo($context,$format,\%userlist,
1.11 raeburn 2420: $indexhash,\%userinfo,\%coauthors,$permission);
1.2 raeburn 2421: }
2422: }
2423: }
1.101 raeburn 2424: } elsif (($env{'form.roletype'} eq 'course') ||
2425: ($env{'form.roletype'} eq 'community')) {
1.106 raeburn 2426: if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
1.2 raeburn 2427: my %courses = &process_coursepick();
1.39 raeburn 2428: my %allusers;
2429: my $hidepriv = 1;
1.2 raeburn 2430: foreach my $cid (keys(%courses)) {
1.17 raeburn 2431: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
1.11 raeburn 2432: next if ($cnum eq '' || $cdom eq '');
1.17 raeburn 2433: my $custom = 1;
1.2 raeburn 2434: my (@roles,@sections,%access,%users,%userdata,
1.6 albertel 2435: %statushash);
1.2 raeburn 2436: if ($env{'form.showrole'} eq 'Any') {
1.101 raeburn 2437: @roles = &course_roles($context,undef,$custom,
2438: $env{'form.roletype'});
1.2 raeburn 2439: } else {
2440: @roles = ($env{'form.showrole'});
2441: }
2442: foreach my $role (@roles) {
2443: %{$users{$role}} = ();
2444: }
2445: foreach my $type (@statuses) {
2446: $access{$type} = $type;
2447: }
1.39 raeburn 2448: &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash,$hidepriv);
1.2 raeburn 2449: foreach my $user (keys(%userdata)) {
2450: next if (ref($userinfo{$user}) eq 'HASH');
2451: foreach my $item ('fullname','id') {
2452: $userinfo{$user}{$item} = $userdata{$user}[$indexhash->{$item}];
2453: }
2454: }
2455: foreach my $role (keys(%users)) {
2456: foreach my $user (keys(%{$users{$role}})) {
2457: my $uniqid = $user.':'.$role;
2458: $allusers{$uniqid}{$cid} = { desc => $cdesc,
2459: secs => $statushash{$user}{$role},
2460: };
2461: }
2462: }
2463: }
2464: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 2465: \%userinfo,\%allusers,$permission);
1.2 raeburn 2466: } else {
1.10 raeburn 2467: $r->print('<input type="hidden" name="phase" value="'.
2468: $env{'form.phase'}.'" /></form>');
1.2 raeburn 2469: return;
2470: }
1.1 raeburn 2471: }
2472: }
1.3 raeburn 2473: }
2474: if (keys(%userlist) == 0) {
1.142 bisitz 2475: my $msg = '';
1.13 raeburn 2476: if ($context eq 'author') {
1.142 bisitz 2477: $msg = &mt('There are no co-authors to display.');
1.3 raeburn 2478: } elsif ($context eq 'domain') {
2479: if ($env{'form.roletype'} eq 'domain') {
1.142 bisitz 2480: $msg = &mt('There are no users with domain roles to display.');
1.13 raeburn 2481: } elsif ($env{'form.roletype'} eq 'author') {
1.142 bisitz 2482: $msg = &mt('There are no authors or co-authors to display.');
1.3 raeburn 2483: } elsif ($env{'form.roletype'} eq 'course') {
1.142 bisitz 2484: $msg = &mt('There are no course users to display');
1.101 raeburn 2485: } elsif ($env{'form.roletype'} eq 'community') {
1.142 bisitz 2486: $msg = &mt('There are no community users to display');
1.2 raeburn 2487: }
1.3 raeburn 2488: } elsif ($context eq 'course') {
2489: $r->print(&mt('There are no course users to display.')."\n");
2490: }
1.148 bisitz 2491: $r->print('<p class="LC_info">'.$msg.'</p>'."\n") if $msg;
1.3 raeburn 2492: } else {
2493: # Print out the available choices
1.4 raeburn 2494: my $usercount;
1.3 raeburn 2495: if ($env{'form.action'} eq 'modifystudent') {
1.10 raeburn 2496: ($usercount) = &show_users_list($r,$context,'view',$permission,
1.150 raeburn 2497: $env{'form.Status'},\%userlist,$keylist,'',
2498: $showcredits);
1.1 raeburn 2499: } else {
1.4 raeburn 2500: ($usercount) = &show_users_list($r,$context,$env{'form.output'},
1.150 raeburn 2501: $permission,$env{'form.Status'},\%userlist,
1.159 raeburn 2502: $keylist,'',$showcredits,$needauthorquota,$needauthorusage);
1.4 raeburn 2503: }
2504: if (!$usercount) {
1.142 bisitz 2505: $r->print('<br /><span class="LC_info">'
1.72 bisitz 2506: .&mt('There are no users matching the search criteria.')
2507: .'</span>'
2508: );
1.2 raeburn 2509: }
2510: }
1.10 raeburn 2511: $r->print('<input type="hidden" name="phase" value="'.
2512: $env{'form.phase'}.'" /></form>');
1.140 raeburn 2513: return;
1.2 raeburn 2514: }
2515:
1.53 raeburn 2516: sub role_filter {
2517: my ($context) = @_;
2518: my $output;
2519: my $roleselected = '';
2520: if ($env{'form.showrole'} eq 'Any') {
1.91 bisitz 2521: $roleselected = ' selected="selected"';
1.53 raeburn 2522: }
2523: my ($role_select);
2524: if ($context eq 'domain') {
2525: $role_select = &domain_roles_select();
1.140 raeburn 2526: $output = '<span class="LC_nobreak">'
1.70 bisitz 2527: .&mt('Role Type: [_1]',$role_select)
1.140 raeburn 2528: .'</span>';
1.53 raeburn 2529: } else {
1.140 raeburn 2530: $role_select = '<select name="showrole" onchange="javascript:updateCols('."'showrole'".');">'."\n".
1.53 raeburn 2531: '<option value="Any" '.$roleselected.'>'.
2532: &mt('Any role').'</option>';
1.101 raeburn 2533: my ($roletype,$crstype);
2534: if ($context eq 'course') {
2535: $crstype = &Apache::loncommon::course_type();
2536: if ($crstype eq 'Community') {
2537: $roletype = 'community';
2538: } else {
2539: $roletype = 'course';
2540: }
2541: }
2542: my @poss_roles = &curr_role_permissions($context,'','',$roletype);
1.53 raeburn 2543: foreach my $role (@poss_roles) {
2544: $roleselected = '';
2545: if ($role eq $env{'form.showrole'}) {
1.91 bisitz 2546: $roleselected = ' selected="selected"';
1.53 raeburn 2547: }
2548: my $plrole;
2549: if ($role eq 'cr') {
2550: $plrole = &mt('Custom role');
2551: } else {
1.101 raeburn 2552: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.53 raeburn 2553: }
2554: $role_select .= '<option value="'.$role.'"'.$roleselected.'>'.$plrole.'</option>';
2555: }
2556: $role_select .= '</select>';
1.140 raeburn 2557: $output = '<span class="LC_nobreak">'
1.70 bisitz 2558: .&mt('Role: [_1]',$role_select)
1.140 raeburn 2559: .'</span>';
1.53 raeburn 2560: }
2561: return $output;
2562: }
2563:
1.33 raeburn 2564: sub section_group_filter {
2565: my ($cnum,$cdom) = @_;
2566: my @filters;
2567: if ($env{'request.course.sec'} eq '') {
2568: @filters = ('sec');
2569: }
2570: push(@filters,'grp');
2571: my %name = (
2572: sec => 'secfilter',
2573: grp => 'grpfilter',
2574: );
2575: my %title = &Apache::lonlocal::texthash (
2576: sec => 'Section(s)',
2577: grp => 'Group(s)',
2578: all => 'all',
2579: none => 'none',
2580: );
1.47 raeburn 2581: my $output;
1.33 raeburn 2582: foreach my $item (@filters) {
1.47 raeburn 2583: my ($markup,@options);
1.33 raeburn 2584: if ($env{'form.'.$name{$item}} eq '') {
2585: $env{'form.'.$name{$item}} = 'all';
2586: }
2587: if ($item eq 'sec') {
1.103 raeburn 2588: if (($env{'form.showrole'} eq 'cc') || ($env{'form.showrole'} eq 'co')) {
1.33 raeburn 2589: $env{'form.'.$name{$item}} = 'none';
2590: }
2591: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
2592: @options = sort(keys(%sections_count));
2593: } elsif ($item eq 'grp') {
2594: my %curr_groups = &Apache::longroup::coursegroups();
2595: @options = sort(keys(%curr_groups));
2596: }
2597: if (@options > 0) {
2598: my $currsel;
1.112 bisitz 2599: $markup = '<select name="'.$name{$item}.'">'."\n";
1.33 raeburn 2600: foreach my $option ('all','none',@options) {
2601: $currsel = '';
2602: if ($env{'form.'.$name{$item}} eq $option) {
1.96 bisitz 2603: $currsel = ' selected="selected"';
1.33 raeburn 2604: }
2605: $markup .= ' <option value="'.$option.'"'.$currsel.'>';
2606: if (($option eq 'all') || ($option eq 'none')) {
2607: $markup .= $title{$option};
2608: } else {
2609: $markup .= $option;
2610: }
2611: $markup .= '</option>'."\n";
2612: }
2613: $markup .= '</select>'."\n";
1.111 bisitz 2614: $output .= (' 'x3).'<span class="LC_nobreak">'
2615: .'<label>'.$title{$item}.': '.$markup.'</label>'
2616: .'</span> ';
1.33 raeburn 2617: }
2618: }
2619: return $output;
2620: }
2621:
1.140 raeburn 2622: sub infocolumns {
1.150 raeburn 2623: my ($context,$mode,$showcredits) = @_;
1.140 raeburn 2624: my @cols;
2625: if (($mode eq 'pickauthor') || ($mode eq 'autoenroll')) {
1.150 raeburn 2626: @cols = &get_cols_array($context,$mode,$showcredits);
1.140 raeburn 2627: } else {
1.150 raeburn 2628: my @posscols = &get_cols_array($context,$mode,$showcredits);
1.140 raeburn 2629: if ($env{'form.phase'} ne '') {
2630: my @checkedcols = &Apache::loncommon::get_env_multiple('form.showcol');
2631: foreach my $col (@checkedcols) {
2632: if (grep(/^$col$/,@posscols)) {
2633: push(@cols,$col);
2634: }
2635: }
2636: } else {
2637: @cols = @posscols;
2638: }
2639: }
2640: return @cols;
2641: }
2642:
2643: sub get_cols_array {
1.150 raeburn 2644: my ($context,$mode,$showcredits) = @_;
1.140 raeburn 2645: my @cols;
2646: if ($mode eq 'pickauthor') {
2647: @cols = ('username','fullname','status','email');
2648: } else {
2649: @cols = ('username','domain','id','fullname');
2650: if ($context eq 'course') {
2651: push(@cols,'section');
2652: }
2653: push(@cols,('start','end','role'));
2654: unless (($mode eq 'autoenroll') && ($env{'form.Status'} ne 'Any')) {
2655: push(@cols,'status');
2656: }
2657: if ($context eq 'course') {
2658: push(@cols,'groups');
2659: }
2660: push(@cols,'email');
2661: if (($context eq 'course') && ($mode ne 'autoenroll')) {
1.150 raeburn 2662: if ($showcredits) {
2663: push(@cols,'credits');
2664: }
1.140 raeburn 2665: push(@cols,'lastlogin','clicker');
2666: }
2667: if (($context eq 'course') && ($mode ne 'autoenroll') &&
2668: ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
1.156 raeburn 2669: push(@cols,'photo');
1.140 raeburn 2670: }
1.149 raeburn 2671: if ($context eq 'domain') {
1.219 raeburn 2672: push(@cols,('authorusage','authorquota','extent'));
2673: }
2674: if ($context eq 'author') {
2675: push(@cols,'manager');
1.149 raeburn 2676: }
1.140 raeburn 2677: }
2678: return @cols;
2679: }
2680:
2681: sub column_checkboxes {
1.221 raeburn 2682: my ($context,$mode,$formname,$showcredits,$showstart,$showend) = @_;
1.150 raeburn 2683: my @cols = &get_cols_array($context,$mode,$showcredits);
1.140 raeburn 2684: my @showncols = &Apache::loncommon::get_env_multiple('form.showcol');
2685: my (%disabledchk,%unchecked);
2686: if ($env{'form.phase'} eq '') {
2687: $disabledchk{'status'} = 1;
2688: if ($context eq 'course') {
2689: $disabledchk{'role'} = 1;
2690: $unchecked{'photo'} = 1;
1.149 raeburn 2691: $unchecked{'clicker'} = 1;
1.150 raeburn 2692: if ($showcredits) {
2693: $unchecked{'credits'} = 1;
2694: }
1.221 raeburn 2695: my %curr_groups = &Apache::longroup::coursegroups();
2696: unless (keys(%curr_groups)) {
2697: $unchecked{'groups'} = 1;
2698: }
2699: } elsif ($context eq 'domain') {
1.149 raeburn 2700: $unchecked{'extent'} = 1;
1.140 raeburn 2701: }
1.221 raeburn 2702: if ($showstart) {
2703: $unchecked{'lastlogin'} = 1;
2704: } else {
2705: $unchecked{'start'} = 1;
2706: }
2707: unless ($showend) {
2708: $unchecked{'end'} = 1;
2709: }
1.140 raeburn 2710: } else {
2711: if ($env{'form.Status'} ne 'Any') {
2712: $disabledchk{'status'} = 1;
2713: }
1.146 raeburn 2714: if (($env{'form.showrole'} ne 'Any') && ($env{'form.showrole'} ne 'cr')) {
2715: $disabledchk{'role'} = 1;
1.140 raeburn 2716: }
1.149 raeburn 2717: if ($context eq 'domain') {
2718: if (($env{'form.roletype'} eq 'course') ||
2719: ($env{'form.roletype'} eq 'community')) {
2720: $disabledchk{'status'} = 1;
1.159 raeburn 2721: $disabledchk{'authorusage'} = 1;
2722: $disabledchk{'authorquota'} = 1;
1.149 raeburn 2723: } elsif ($env{'form.roletype'} eq 'domain') {
2724: $disabledchk{'extent'} = 1;
2725: }
1.219 raeburn 2726: } elsif ($context eq 'author') {
2727: if (($env{'form.Status'} eq 'Expired') ||
2728: ($env{'form.showrole'} eq 'aa')) {
2729: $disabledchk{'manager'} = 1;
2730: }
1.149 raeburn 2731: }
1.140 raeburn 2732: }
2733: my $numposs = scalar(@cols);
1.149 raeburn 2734: my $numinrow = 7;
1.140 raeburn 2735: my %lt = &get_column_names($context);
2736: my $output = '<fieldset><legend>'.&mt('Information to show').'</legend>'."\n".'<span class="LC_nobreak">'.
2737: '<input type="button" onclick="javascript:checkAll(document.'.$formname.'.showcol);" value="'.&mt('check all').'" />'.
2738: (' 'x3).
2739: '<input type="button" onclick="javascript:uncheckAll(document.'.$formname.'.showcol);" value="'.&mt('uncheck all').'" />'.
2740: '</span><table>';
2741:
2742: for (my $i=0; $i<$numposs; $i++) {
2743: my $rem = $i%($numinrow);
2744: if ($rem == 0) {
2745: if ($i > 0) {
2746: $output .= '</tr>';
2747: }
2748: $output .= '<tr>';
2749: }
2750: my $checked;
2751: if ($env{'form.phase'} eq '') {
2752: $checked = ' checked="checked"';
2753: if ($unchecked{$cols[$i]}) {
2754: $checked = '';
2755: }
2756: if ($disabledchk{$cols[$i]}) {
2757: $checked = ' disabled="disabled"';
2758: }
2759: } elsif (grep(/^\Q$cols[$i]\E$/,@showncols)) {
2760: $checked = ' checked="checked"';
2761: } elsif ($disabledchk{$cols[$i]}) {
2762: $checked = ' disabled="disabled"';
2763: }
2764: if ($i == $numposs-1) {
2765: my $colsleft = $numinrow-$rem;
2766: if ($colsleft > 1) {
2767: $output .= '<td colspan="'.$colsleft.'">';
2768: } else {
2769: $output .= '<td>';
2770: }
2771: } else {
2772: $output .= '<td>';
2773: }
1.149 raeburn 2774: my $style;
2775: if ($cols[$i] eq 'extent') {
2776: if (($env{'form.roletype'} eq 'domain') || ($env{'form.roletype'} eq '')) {
2777: $style = ' style="display: none;"';
2778: }
1.159 raeburn 2779: } elsif (($cols[$i] eq 'authorusage') || ($cols[$i] eq 'authorquota')) {
2780: if ($env{'form.roletype'} ne 'domain') {
2781: $style = ' style="display: none;"';
2782: }
2783: }
1.149 raeburn 2784: $output .= '<span id="show'.$cols[$i].'"'.$style.'><label>'.
2785: '<input id="showcol'.$cols[$i].'" type="checkbox" name="showcol" value="'.$cols[$i].'"'.$checked.' /><span id="showcoltext'.$cols[$i].'">'.
2786: $lt{$cols[$i]}.'</span>'.
2787: '</label></span></td>';
1.140 raeburn 2788: }
2789: $output .= '</tr></table></fieldset>';
2790: return $output;
2791: }
2792:
1.2 raeburn 2793: sub list_submit_button {
2794: my ($text) = @_;
1.11 raeburn 2795: return '<input type="button" name="updatedisplay" value="'.$text.'" onclick="javascript:display_update()" />';
1.2 raeburn 2796: }
2797:
1.140 raeburn 2798: sub get_column_names {
2799: my ($context) = @_;
2800: my %lt = &Apache::lonlocal::texthash(
2801: 'username' => "username",
2802: 'domain' => "domain",
2803: 'id' => 'ID',
2804: 'fullname' => "name",
2805: 'section' => "section",
2806: 'groups' => "active groups",
2807: 'start' => "start date",
2808: 'end' => "end date",
2809: 'status' => "status",
2810: 'role' => "role",
1.150 raeburn 2811: 'credits' => "credits",
1.140 raeburn 2812: 'type' => "enroll type/action",
2813: 'email' => "e-mail address",
2814: 'photo' => "photo",
2815: 'lastlogin' => "last login",
2816: 'extent' => "extent",
1.159 raeburn 2817: 'authorusage' => "disk usage (%)",
2818: 'authorquota' => "disk quota (MB)",
1.140 raeburn 2819: 'ca' => "check all",
2820: 'ua' => "uncheck all",
2821: 'clicker' => "clicker-ID",
1.219 raeburn 2822: 'manager' => "co-author manager",
1.140 raeburn 2823: );
2824: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
1.149 raeburn 2825: $lt{'extent'} = &mt('course(s): description, section(s), status');
1.140 raeburn 2826: } elsif ($context eq 'domain' && $env{'form.roletype'} eq 'community') {
1.154 raeburn 2827: $lt{'extent'} = &mt('community(s): description, section(s), status');
1.149 raeburn 2828: } elsif (($context eq 'author') ||
2829: ($context eq 'domain' && $env{'form.roletype'} eq 'author')) {
2830: $lt{'extent'} = &mt('author');
1.140 raeburn 2831: }
2832: return %lt;
2833: }
2834:
1.2 raeburn 2835: sub gather_userinfo {
1.11 raeburn 2836: my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_;
1.52 raeburn 2837: my $viewablesec;
2838: if ($context eq 'course') {
2839: $viewablesec = &viewable_section($permission);
2840: }
1.2 raeburn 2841: foreach my $item (keys(%{$rolehash})) {
2842: my %userdata;
1.22 raeburn 2843: if ($context eq 'author') {
1.2 raeburn 2844: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
2845: split(/:/,$item);
2846: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
1.222 ! raeburn 2847: next if (($userdata{'username'} eq '') && ($userdata{'domain'} eq ''));
1.24 raeburn 2848: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2849: $item,$userlist);
1.22 raeburn 2850: } elsif ($context eq 'course') {
2851: ($userdata{'username'},$userdata{'domain'},$userdata{'role'},
2852: $userdata{'section'}) = split(/:/,$item,-1);
2853: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
2854: if (($viewablesec ne '') && ($userdata{'section'} ne '')) {
2855: next if ($viewablesec ne $userdata{'section'});
2856: }
1.24 raeburn 2857: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2858: $item,$userlist);
1.2 raeburn 2859: } elsif ($context eq 'domain') {
2860: if ($env{'form.roletype'} eq 'domain') {
2861: ($userdata{'role'},$userdata{'username'},$userdata{'domain'}) =
2862: split(/:/,$item);
2863: ($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
1.24 raeburn 2864: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2865: $item,$userlist);
1.13 raeburn 2866: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 2867: if (ref($rolehash->{$item}) eq 'HASH') {
2868: $userdata{'extent'} = $item;
2869: foreach my $key (keys(%{$rolehash->{$item}})) {
2870: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) = split(/:/,$key);
2871: ($userdata{'start'},$userdata{'end'}) =
2872: split(/:/,$rolehash->{$item}{$key});
2873: my $uniqid = $key.':'.$item;
1.25 raeburn 2874: &build_user_record($context,\%userdata,$userinfo,
2875: $indexhash,$uniqid,$userlist);
1.2 raeburn 2876: }
2877: }
1.102 raeburn 2878: } elsif (($env{'form.roletype'} eq 'course') ||
2879: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 2880: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
2881: split(/:/,$item);
2882: if (ref($rolehash->{$item}) eq 'HASH') {
1.11 raeburn 2883: my $numcids = keys(%{$rolehash->{$item}});
1.2 raeburn 2884: foreach my $cid (sort(keys(%{$rolehash->{$item}}))) {
2885: if (ref($rolehash->{$item}{$cid}) eq 'HASH') {
2886: my $spanstart = '';
2887: my $spanend = '; ';
2888: my $space = ', ';
2889: if ($format eq 'html' || $format eq 'view') {
2890: $spanstart = '<span class="LC_nobreak">';
1.23 raeburn 2891: # FIXME: actions on courses disabled for now
2892: # if ($permission->{'cusr'}) {
2893: # if ($numcids > 1) {
1.25 raeburn 2894: # $spanstart .= '<input type="radio" name="'.$item.'" value="'.$cid.'" /> ';
1.23 raeburn 2895: # } else {
1.25 raeburn 2896: # $spanstart .= '<input type="hidden" name="'.$item.'" value="'.$cid.'" /> ';
1.23 raeburn 2897: # }
2898: # }
1.2 raeburn 2899: $spanend = '</span><br />';
2900: $space = ', ';
2901: }
2902: $userdata{'extent'} .= $spanstart.
2903: $rolehash->{$item}{$cid}{'desc'}.$space;
2904: if (ref($rolehash->{$item}{$cid}{'secs'}) eq 'HASH') {
2905: foreach my $sec (sort(keys(%{$rolehash->{$item}{$cid}{'secs'}}))) {
1.25 raeburn 2906: if (($env{'form.Status'} eq 'Any') ||
2907: ($env{'form.Status'} eq $rolehash->{$item}{$cid}{'secs'}{$sec})) {
2908: $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
2909: $userdata{'status'} = $rolehash->{$item}{$cid}{'secs'}{$sec};
2910: }
1.2 raeburn 2911: }
2912: }
2913: }
2914: }
2915: }
1.25 raeburn 2916: if ($userdata{'status'} ne '') {
2917: &build_user_record($context,\%userdata,$userinfo,
2918: $indexhash,$item,$userlist);
2919: }
1.2 raeburn 2920: }
2921: }
2922: }
2923: return;
2924: }
2925:
2926: sub build_user_record {
1.24 raeburn 2927: my ($context,$userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
1.11 raeburn 2928: next if ($userdata->{'start'} eq '-1' && $userdata->{'end'} eq '-1');
1.102 raeburn 2929: if (!(($context eq 'domain') && (($env{'form.roletype'} eq 'course')
2930: && ($env{'form.roletype'} eq 'community')))) {
1.24 raeburn 2931: &process_date_info($userdata);
2932: }
1.2 raeburn 2933: my $username = $userdata->{'username'};
2934: my $domain = $userdata->{'domain'};
2935: if (ref($userinfo->{$username.':'.$domain}) eq 'HASH') {
1.24 raeburn 2936: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
1.2 raeburn 2937: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
2938: } else {
2939: &aggregate_user_info($domain,$username,$userinfo);
2940: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
2941: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
2942: }
2943: foreach my $key (keys(%{$indexhash})) {
2944: if (defined($userdata->{$key})) {
2945: $userlist->{$record_key}[$indexhash->{$key}] = $userdata->{$key};
2946: }
2947: }
2948: return;
2949: }
2950:
2951: sub courses_selector {
2952: my ($cdom,$formname) = @_;
2953: my %codes = ();
2954: my @codetitles = ();
2955: my %cat_titles = ();
2956: my %cat_order = ();
2957: my %idlist = ();
2958: my %idnums = ();
2959: my %idlist_titles = ();
2960: my $caller = 'global';
2961: my $format_reply;
2962: my $jscript = '';
2963:
1.7 albertel 2964: my $totcodes = 0;
1.201 raeburn 2965: my $instcats = &Apache::lonnet::get_dom_instcats($cdom);
2966: if (ref($instcats) eq 'HASH') {
2967: if ((ref($instcats->{'codetitles'}) eq 'ARRAY') && (ref($instcats->{'codes'}) eq 'HASH') &&
2968: (ref($instcats->{'cat_titles'}) eq 'HASH') && (ref($instcats->{'cat_order'}) eq 'HASH')) {
2969: %codes = %{$instcats->{'codes'}};
2970: @codetitles = @{$instcats->{'codetitles'}};
2971: %cat_titles = %{$instcats->{'cat_titles'}};
2972: %cat_order = %{$instcats->{'cat_order'}};
2973: $totcodes = scalar(keys(%codes));
1.2 raeburn 2974: my $numtypes = @codetitles;
2975: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
2976: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
2977: my $longtitles_str = join('","',@{$longtitles});
2978: my $allidlist = $idlist{$codetitles[0]};
2979: $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
2980: $jscript .= $scripttext;
1.181 raeburn 2981: $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,\@codetitles);
1.2 raeburn 2982: }
2983: }
2984: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
2985:
2986: my %elements = (
2987: Year => 'selectbox',
2988: coursepick => 'radio',
2989: coursetotal => 'text',
2990: courselist => 'text',
2991: );
2992: $jscript .= &Apache::lonhtmlcommon::set_form_elements(\%elements);
2993: if ($env{'form.coursepick'} eq 'category') {
2994: $jscript .= qq|
2995: function setCourseCat(formname) {
2996: if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
2997: return;
2998: }
1.120 raeburn 2999: courseSet('$codetitles[0]');
1.2 raeburn 3000: for (var j=0; j<formname.Semester.length; j++) {
3001: if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
3002: formname.Semester.options[j].selected = true;
3003: }
3004: }
3005: if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
3006: return;
3007: }
1.120 raeburn 3008: courseSet('$codetitles[1]');
1.2 raeburn 3009: for (var j=0; j<formname.Department.length; j++) {
1.187 raeburn 3010: if (formname.Department.options[j].value == "$env{'form.Department'}") {
3011: formname.Department.options[j].selected = true;
1.2 raeburn 3012: }
3013: }
3014: if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
3015: return;
3016: }
1.120 raeburn 3017: courseSet('$codetitles[2]');
1.2 raeburn 3018: for (var j=0; j<formname.Number.length; j++) {
3019: if (formname.Number.options[j].value == "$env{'form.Number'}") {
3020: formname.Number.options[j].selected = true;
3021: }
3022: }
3023: }
3024: |;
3025: }
3026: return ($cb_jscript,$jscript,$totcodes,\@codetitles,\%idlist,
3027: \%idlist_titles);
3028: }
3029:
3030: sub course_selector_loadcode {
3031: my ($formname) = @_;
3032: my $loadcode;
3033: if ($env{'form.coursepick'} ne '') {
3034: $loadcode = 'javascript:setFormElements(document.'.$formname.')';
3035: if ($env{'form.coursepick'} eq 'category') {
3036: $loadcode .= ';javascript:setCourseCat(document.'.$formname.')';
3037: }
3038: }
3039: return $loadcode;
3040: }
3041:
3042: sub process_coursepick {
3043: my $coursefilter = $env{'form.coursepick'};
3044: my $cdom = $env{'request.role.domain'};
3045: my %courses;
1.105 raeburn 3046: my $crssrch = 'Course';
3047: if ($env{'form.roletype'} eq 'community') {
3048: $crssrch = 'Community';
3049: }
1.2 raeburn 3050: if ($coursefilter eq 'all') {
3051: %courses = &Apache::lonnet::courseiddump($cdom,'.','.','.','.','.',
1.105 raeburn 3052: undef,undef,$crssrch);
1.2 raeburn 3053: } elsif ($coursefilter eq 'category') {
3054: my $instcode = &instcode_from_coursefilter();
3055: %courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.',
1.105 raeburn 3056: undef,undef,$crssrch);
1.2 raeburn 3057: } elsif ($coursefilter eq 'specific') {
3058: if ($env{'form.coursetotal'} > 1) {
3059: my @course_ids = split(/&&/,$env{'form.courselist'});
3060: foreach my $cid (@course_ids) {
3061: $courses{$cid} = '';
1.1 raeburn 3062: }
1.2 raeburn 3063: } else {
3064: $courses{$env{'form.courselist'}} = '';
1.1 raeburn 3065: }
1.2 raeburn 3066: }
3067: return %courses;
3068: }
3069:
3070: sub instcode_from_coursefilter {
3071: my $instcode = '';
3072: my @cats = ('Semester','Year','Department','Number');
3073: foreach my $category (@cats) {
3074: if (defined($env{'form.'.$category})) {
3075: unless ($env{'form.'.$category} eq '-1') {
3076: $instcode .= $env{'form.'.$category};
3077: }
3078: }
3079: }
3080: if ($instcode eq '') {
3081: $instcode = '.';
3082: }
3083: return $instcode;
3084: }
3085:
3086: sub make_keylist_array {
3087: my ($index,$keylist);
3088: $index->{'domain'} = &Apache::loncoursedata::CL_SDOM();
3089: $index->{'username'} = &Apache::loncoursedata::CL_SNAME();
3090: $index->{'end'} = &Apache::loncoursedata::CL_END();
3091: $index->{'start'} = &Apache::loncoursedata::CL_START();
3092: $index->{'id'} = &Apache::loncoursedata::CL_ID();
3093: $index->{'section'} = &Apache::loncoursedata::CL_SECTION();
3094: $index->{'fullname'} = &Apache::loncoursedata::CL_FULLNAME();
3095: $index->{'status'} = &Apache::loncoursedata::CL_STATUS();
3096: $index->{'type'} = &Apache::loncoursedata::CL_TYPE();
3097: $index->{'lockedtype'} = &Apache::loncoursedata::CL_LOCKEDTYPE();
3098: $index->{'groups'} = &Apache::loncoursedata::CL_GROUP();
3099: $index->{'email'} = &Apache::loncoursedata::CL_PERMANENTEMAIL();
3100: $index->{'role'} = &Apache::loncoursedata::CL_ROLE();
3101: $index->{'extent'} = &Apache::loncoursedata::CL_EXTENT();
1.44 raeburn 3102: $index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
1.47 raeburn 3103: $index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();
1.150 raeburn 3104: $index->{'credits'} = &Apache::loncoursedata::CL_CREDITS();
1.174 raeburn 3105: $index->{'instsec'} = &Apache::loncoursedata::CL_INSTSEC();
1.159 raeburn 3106: $index->{'authorquota'} = &Apache::loncoursedata::CL_AUTHORQUOTA();
3107: $index->{'authorusage'} = &Apache::loncoursedata::CL_AUTHORUSAGE();
1.219 raeburn 3108: $index->{'manager'} = &Apache::loncoursedata::CL_CAMANAGER();
1.2 raeburn 3109: foreach my $key (keys(%{$index})) {
3110: $keylist->[$index->{$key}] = $key;
3111: }
3112: return ($index,$keylist);
3113: }
3114:
3115: sub aggregate_user_info {
3116: my ($udom,$uname,$userinfo) = @_;
3117: my %info=&Apache::lonnet::get('environment',
3118: ['firstname','middlename',
3119: 'lastname','generation','id'],
3120: $udom,$uname);
3121: my ($tmp) = keys(%info);
3122: my ($fullname,$id);
3123: if ($tmp =~/^(con_lost|error|no_such_host)/i) {
3124: $fullname = 'not available';
3125: $id = 'not available';
3126: &Apache::lonnet::logthis('unable to retrieve environment '.
3127: 'for '.$uname.':'.$udom);
1.1 raeburn 3128: } else {
1.2 raeburn 3129: $fullname = &Apache::lonnet::format_name(@info{qw/firstname middlename lastname generation/},'lastname');
3130: $id = $info{'id'};
3131: }
3132: $userinfo->{$uname.':'.$udom} = {
3133: fullname => $fullname,
3134: id => $id,
3135: };
3136: return;
3137: }
1.1 raeburn 3138:
1.2 raeburn 3139: sub process_date_info {
3140: my ($userdata) = @_;
3141: my $now = time;
1.83 raeburn 3142: $userdata->{'status'} = 'Active';
1.2 raeburn 3143: if ($userdata->{'start'} > 0) {
3144: if ($now < $userdata->{'start'}) {
1.83 raeburn 3145: $userdata->{'status'} = 'Future';
1.2 raeburn 3146: }
1.1 raeburn 3147: }
1.2 raeburn 3148: if ($userdata->{'end'} > 0) {
3149: if ($now > $userdata->{'end'}) {
1.83 raeburn 3150: $userdata->{'status'} = 'Expired';
1.2 raeburn 3151: }
3152: }
3153: return;
1.1 raeburn 3154: }
3155:
3156: sub show_users_list {
1.150 raeburn 3157: my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname,
1.159 raeburn 3158: $showcredits,$needauthorquota,$needauthorusage)=@_;
1.55 raeburn 3159: if ($formname eq '') {
3160: $formname = 'studentform';
3161: }
1.159 raeburn 3162: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1 raeburn 3163: #
3164: # Variables for excel output
3165: my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
3166: #
3167: # Variables for csv output
3168: my ($CSVfile,$CSVfilename);
3169: #
3170: my $sortby = $env{'form.sortby'};
1.3 raeburn 3171: my @sortable = ('username','domain','id','fullname','start','end','email','role');
1.2 raeburn 3172: if ($context eq 'course') {
1.3 raeburn 3173: push(@sortable,('section','groups','type'));
1.150 raeburn 3174: if ($showcredits) {
3175: push(@sortable,'credits');
3176: }
1.2 raeburn 3177: } else {
1.3 raeburn 3178: push(@sortable,'extent');
1.159 raeburn 3179: if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
3180: (($env{'form.showrole'} eq 'Any') || ($env{'form.showrole'} eq 'au'))) {
3181: push(@sortable,('authorusage','authorquota'));
3182: }
1.219 raeburn 3183: if ($context eq 'author') {
3184: push(@sortable,'manager');
3185: }
1.3 raeburn 3186: }
1.55 raeburn 3187: if ($mode eq 'pickauthor') {
3188: @sortable = ('username','fullname','email','status');
3189: }
1.156 raeburn 3190: my %is_sortable;
1.158 raeburn 3191: map { $is_sortable{$_} = 1; } @sortable;
1.156 raeburn 3192: unless ($is_sortable{$sortby}) {
1.3 raeburn 3193: $sortby = 'username';
1.1 raeburn 3194: }
1.22 raeburn 3195: my $setting = $env{'form.roletype'};
1.150 raeburn 3196: my ($cid,$cdom,$cnum,$classgroups,$crstype,$defaultcredits);
1.1 raeburn 3197: if ($context eq 'course') {
1.22 raeburn 3198: $cid = $env{'request.course.id'};
1.101 raeburn 3199: $crstype = &Apache::loncommon::course_type();
1.17 raeburn 3200: ($cnum,$cdom) = &get_course_identity($cid);
1.150 raeburn 3201: $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
1.2 raeburn 3202: ($classgroups) = &Apache::loncoursedata::get_group_memberships(
3203: $userlist,$keylist,$cdom,$cnum);
1.16 raeburn 3204: if ($mode eq 'autoenroll') {
3205: $env{'form.showrole'} = 'st';
3206: } else {
3207: if ($env{'course.'.$cid.'.internal.showphoto'}) {
3208: $r->print('
1.1 raeburn 3209: <script type="text/javascript">
1.96 bisitz 3210: // <![CDATA[
1.1 raeburn 3211: function photowindow(photolink) {
3212: var title = "Photo_Viewer";
3213: var options = "scrollbars=1,resizable=1,menubar=0";
3214: options += ",width=240,height=240";
3215: stdeditbrowser = open(photolink,title,options,"1");
3216: stdeditbrowser.focus();
3217: }
1.96 bisitz 3218: // ]]>
1.1 raeburn 3219: </script>
1.16 raeburn 3220: ');
3221: }
3222: }
1.102 raeburn 3223: } elsif ($context eq 'domain') {
3224: if ($setting eq 'community') {
3225: $crstype = 'Community';
1.105 raeburn 3226: } elsif ($setting eq 'course') {
1.102 raeburn 3227: $crstype = 'Course';
3228: }
1.1 raeburn 3229: }
1.55 raeburn 3230: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
1.40 raeburn 3231: my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
1.56 raeburn 3232: my $verify_action_js = &bulkaction_javascript($formname);
1.1 raeburn 3233: $r->print(<<END);
1.10 raeburn 3234:
3235: <script type="text/javascript" language="Javascript">
1.96 bisitz 3236: // <![CDATA[
1.11 raeburn 3237:
1.56 raeburn 3238: $verify_action_js
1.10 raeburn 3239:
3240: function username_display_launch(username,domain) {
3241: var target;
1.177 raeburn 3242: if (!document.$formname.usernamelink.length) {
3243: target = document.$formname.usernamelink.value;
3244: } else {
3245: for (var i=0; i<document.$formname.usernamelink.length; i++) {
3246: if (document.$formname.usernamelink[i].checked) {
3247: target = document.$formname.usernamelink[i].value;
3248: }
1.10 raeburn 3249: }
3250: }
1.179 raeburn 3251: if ((target == 'modify') || (target == 'activity')) {
3252: var nextaction = 'singleuser';
3253: if (target == 'activity') {
3254: nextaction = 'accesslogs';
3255: }
1.55 raeburn 3256: if (document.$formname.userwin.checked == true) {
1.179 raeburn 3257: 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 3258: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3259: modifywin = window.open(url,'',options,1);
3260: modifywin.focus();
3261: return;
3262: } else {
1.55 raeburn 3263: document.$formname.srchterm.value=username;
3264: document.$formname.srchdomain.value=domain;
3265: document.$formname.phase.value='get_user_info';
1.179 raeburn 3266: document.$formname.action.value = nextaction;
1.55 raeburn 3267: document.$formname.submit();
1.50 raeburn 3268: }
1.10 raeburn 3269: }
1.48 raeburn 3270: if (target == 'aboutme') {
1.55 raeburn 3271: if (document.$formname.userwin.checked == true) {
1.50 raeburn 3272: var url = '/adm/'+domain+'/'+username+'/aboutme?popup=1';
3273: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3274: aboutmewin = window.open(url,'',options,1);
3275: aboutmewin.focus();
3276: return;
3277: } else {
3278: document.location.href = '/adm/'+domain+'/'+username+'/aboutme';
3279: }
1.48 raeburn 3280: }
1.98 raeburn 3281: if (target == 'track') {
3282: if (document.$formname.userwin.checked == true) {
3283: var url = '/adm/trackstudent?selected_student='+username+':'+domain+'&only_body=1';
3284: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3285: var trackwin = window.open(url,'',options,1);
3286: trackwin.focus();
3287: return;
3288: } else {
3289: document.location.href = '/adm/trackstudent?selected_student='+username+':'+domain;
3290: }
3291: }
1.10 raeburn 3292: }
1.96 bisitz 3293: // ]]>
1.10 raeburn 3294: </script>
1.11 raeburn 3295: $date_sec_selector
1.1 raeburn 3296: <input type="hidden" name="state" value="$env{'form.state'}" />
3297: END
3298: }
3299: $r->print(<<END);
3300: <input type="hidden" name="sortby" value="$sortby" />
3301: END
1.150 raeburn 3302: my @cols = &infocolumns($context,$mode,$showcredits);
1.140 raeburn 3303: my %coltxt = &get_column_names($context);
3304: my %acttxt = &Apache::lonlocal::texthash(
1.11 raeburn 3305: 'pr' => "Proceed",
3306: 'ac' => "Action to take for selected users",
1.56 raeburn 3307: 'link' => "Behavior of clickable username link for each user",
1.82 weissno 3308: 'aboutme' => "Display a user's personal information page",
1.50 raeburn 3309: 'owin' => "Open in a new window",
1.10 raeburn 3310: 'modify' => "Modify a user's information",
1.98 raeburn 3311: 'track' => "View a user's recent activity",
1.179 raeburn 3312: 'activity' => "View a user's access log",
1.1 raeburn 3313: );
1.140 raeburn 3314: my %lt = (%coltxt,%acttxt);
1.4 raeburn 3315: my $rolefilter = $env{'form.showrole'};
1.5 raeburn 3316: if ($env{'form.showrole'} eq 'cr') {
3317: $rolefilter = &mt('custom');
3318: } elsif ($env{'form.showrole'} ne 'Any') {
1.101 raeburn 3319: $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'},$crstype);
1.2 raeburn 3320: }
1.16 raeburn 3321: my $results_description;
3322: if ($mode ne 'autoenroll') {
3323: $results_description = &results_header_row($rolefilter,$statusmode,
1.102 raeburn 3324: $context,$permission,$mode,$crstype);
1.140 raeburn 3325: $r->print('<b>'.$results_description.'</b><br clear="all" />');
1.16 raeburn 3326: }
1.26 raeburn 3327: my ($output,$actionselect,%canchange,%canchangesec);
1.55 raeburn 3328: if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
3329: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
1.16 raeburn 3330: if ($permission->{'cusr'}) {
1.105 raeburn 3331: unless (($context eq 'domain') &&
3332: (($setting eq 'course') || ($setting eq 'community'))) {
3333: $actionselect =
3334: &select_actions($context,$setting,$statusmode,$formname);
3335: }
1.16 raeburn 3336: }
3337: $r->print(<<END);
1.10 raeburn 3338: <input type="hidden" name="srchby" value="uname" />
3339: <input type="hidden" name="srchin" value="dom" />
3340: <input type="hidden" name="srchtype" value="exact" />
3341: <input type="hidden" name="srchterm" value="" />
1.11 raeburn 3342: <input type="hidden" name="srchdomain" value="" />
1.1 raeburn 3343: END
1.16 raeburn 3344: if ($actionselect) {
1.41 raeburn 3345: $output .= <<"END";
1.94 bisitz 3346: <div class="LC_left_float"><fieldset><legend>$lt{'ac'}</legend>
1.56 raeburn 3347: $actionselect
3348: <br/><br /><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.$formname.actionlist)" />
3349: <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 3350: END
1.26 raeburn 3351: my @allroles;
3352: if ($env{'form.showrole'} eq 'Any') {
3353: my $custom = 1;
3354: if ($context eq 'domain') {
1.101 raeburn 3355: @allroles = &roles_by_context($setting,$custom,$crstype);
1.26 raeburn 3356: } else {
1.101 raeburn 3357: @allroles = &roles_by_context($context,$custom,$crstype);
1.26 raeburn 3358: }
3359: } else {
3360: @allroles = ($env{'form.showrole'});
3361: }
3362: foreach my $role (@allroles) {
3363: if ($context eq 'domain') {
3364: if ($setting eq 'domain') {
3365: if (&Apache::lonnet::allowed('c'.$role,
3366: $env{'request.role.domain'})) {
3367: $canchange{$role} = 1;
3368: }
1.31 raeburn 3369: } elsif ($setting eq 'author') {
3370: if (&Apache::lonnet::allowed('c'.$role,
3371: $env{'request.role.domain'})) {
3372: $canchange{$role} = 1;
3373: }
1.26 raeburn 3374: }
3375: } elsif ($context eq 'author') {
3376: if (&Apache::lonnet::allowed('c'.$role,
3377: $env{'user.domain'}.'/'.$env{'user.name'})) {
3378: $canchange{$role} = 1;
3379: }
3380: } elsif ($context eq 'course') {
3381: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
3382: $canchange{$role} = 1;
3383: } elsif ($env{'request.course.sec'} ne '') {
3384: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
3385: $canchangesec{$role} = $env{'request.course.sec'};
3386: }
1.141 raeburn 3387: } elsif ((($role eq 'co') && ($crstype eq 'Community')) ||
3388: (($role eq 'cc') && ($crstype eq 'Course'))) {
3389: if (&is_courseowner($env{'request.course.id'},
3390: $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
3391: $canchange{$role} = 1;
3392: }
1.26 raeburn 3393: }
3394: }
3395: }
1.16 raeburn 3396: }
1.94 bisitz 3397: $output .= '<div class="LC_left_float"><fieldset><legend>'.$lt{'link'}.'</legend>'.
1.56 raeburn 3398: '<table><tr>';
3399: my @linkdests = ('aboutme');
3400: if ($permission->{'cusr'}) {
3401: unshift (@linkdests,'modify');
3402: }
1.179 raeburn 3403: if ($context eq 'course') {
3404: if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) ||
3405: &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.
3406: $env{'request.course.sec'})) {
3407: push(@linkdests,'track');
3408: }
3409: } elsif ($context eq 'domain') {
3410: if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
3411: push(@linkdests,'activity');
3412: }
1.98 raeburn 3413: }
1.56 raeburn 3414: $output .= '<td>';
3415: my $usernamelink = $env{'form.usernamelink'};
3416: if ($usernamelink eq '') {
3417: $usernamelink = 'aboutme';
3418: }
3419: foreach my $item (@linkdests) {
3420: my $checkedstr = '';
3421: if ($item eq $usernamelink) {
1.86 bisitz 3422: $checkedstr = ' checked="checked"';
1.56 raeburn 3423: }
1.86 bisitz 3424: $output .= '<span class="LC_nobreak"><label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.' /> '.$lt{$item}.'</label></span><br />';
1.56 raeburn 3425: }
3426: my $checkwin;
3427: if ($env{'form.userwin'}) {
1.86 bisitz 3428: $checkwin = ' checked="checked"';
1.56 raeburn 3429: }
1.144 bisitz 3430: $output .=
3431: '</td><td valign="top" style="border-left: 1px solid;">'
3432: .'<span class="LC_nobreak"><label>'
3433: .'<input type="checkbox" name="userwin" value="1"'.$checkwin.' />'.$lt{'owin'}
3434: .'</label></span></td></tr></table></fieldset></div>';
1.4 raeburn 3435: }
1.184 raeburn 3436: $output .= "\n".'<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
1.1 raeburn 3437: &Apache::loncommon::start_data_table().
1.4 raeburn 3438: &Apache::loncommon::start_data_table_header_row();
1.1 raeburn 3439: if ($mode eq 'autoenroll') {
1.4 raeburn 3440: $output .= "
1.55 raeburn 3441: <th><a href=\"javascript:document.$formname.sortby.value='type';document.$formname.submit();\">$lt{'type'}</a></th>
1.4 raeburn 3442: ";
1.1 raeburn 3443: } else {
1.105 raeburn 3444: $output .= "\n".'<th> </th>'."\n";
1.11 raeburn 3445: if ($actionselect) {
1.159 raeburn 3446: $output .= '<th class="LC_nobreak" valign="top">'.&mt('Select').'</th>'."\n";
1.11 raeburn 3447: }
1.1 raeburn 3448: }
3449: foreach my $item (@cols) {
1.159 raeburn 3450: $output .= '<th class="LC_nobreak" valign="top">';
1.156 raeburn 3451: if ($is_sortable{$item}) {
1.159 raeburn 3452: $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 3453: } else {
3454: $output .= $lt{$item};
3455: }
3456: $output .= "</th>\n";
1.1 raeburn 3457: }
1.2 raeburn 3458: my %role_types = &role_type_names();
1.16 raeburn 3459: $output .= &Apache::loncommon::end_data_table_header_row();
1.1 raeburn 3460: # Done with the HTML header line
3461: } elsif ($mode eq 'csv') {
3462: #
3463: # Open a file
3464: $CSVfilename = '/prtspool/'.
1.2 raeburn 3465: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
3466: time.'_'.rand(1000000000).'.csv';
1.1 raeburn 3467: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
3468: $r->log_error("Couldn't open $CSVfilename for output $!");
1.108 bisitz 3469: $r->print(
3470: '<p class="LC_error">'
3471: .&mt('Problems occurred in writing the CSV file.')
3472: .' '.&mt('This error has been logged.')
3473: .' '.&mt('Please alert your LON-CAPA administrator.')
3474: .'</p>'
3475: );
1.1 raeburn 3476: $CSVfile = undef;
3477: }
3478: #
3479: # Write headers and data to file
1.2 raeburn 3480: print $CSVfile '"'.$results_description.'"'."\n";
1.1 raeburn 3481: print $CSVfile '"'.join('","',map {
3482: &Apache::loncommon::csv_translate($lt{$_})
1.67 droeschl 3483: } (@cols))."\"\n";
1.1 raeburn 3484: } elsif ($mode eq 'excel') {
3485: # Create the excel spreadsheet
3486: ($excel_workbook,$excel_filename,$format) =
3487: &Apache::loncommon::create_workbook($r);
3488: return if (! defined($excel_workbook));
3489: $excel_sheet = $excel_workbook->addworksheet('userlist');
1.2 raeburn 3490: $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
1.1 raeburn 3491: #
3492: my @colnames = map {$lt{$_}} (@cols);
1.67 droeschl 3493:
1.1 raeburn 3494: $excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
3495: }
3496:
3497: # Done with header lines in all formats
3498: my %index;
3499: my $i;
1.2 raeburn 3500: foreach my $idx (@$keylist) {
3501: $index{$idx} = $i++;
3502: }
1.219 raeburn 3503: my $now = time;
1.4 raeburn 3504: my $usercount = 0;
1.33 raeburn 3505: my ($secfilter,$grpfilter);
3506: if ($context eq 'course') {
3507: $secfilter = $env{'form.secfilter'};
3508: $grpfilter = $env{'form.grpfilter'};
3509: if ($secfilter eq '') {
3510: $secfilter = 'all';
3511: }
3512: if ($grpfilter eq '') {
3513: $grpfilter = 'all';
3514: }
3515: }
1.83 raeburn 3516: my %ltstatus = &Apache::lonlocal::texthash(
3517: Active => 'Active',
3518: Future => 'Future',
3519: Expired => 'Expired',
3520: );
1.219 raeburn 3521: my (%crslogins,%camanagers);
1.139 raeburn 3522: if ($context eq 'course') {
1.219 raeburn 3523: # If this is for a single course get last course "log-in".
1.139 raeburn 3524: %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$cnum);
1.219 raeburn 3525: } elsif ($context eq 'author') {
1.222 ! raeburn 3526: my $authormanagers;
! 3527: if ($env{'request.role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)$}) {
! 3528: my %envhash = &Apache::lonnet::userenvironment($1,$2,'authormanagers');
! 3529: $authormanagers = $envhash{'authormanagers'};
! 3530: } else {
! 3531: $authormanagers = $env{'environment.authormanagers'};
! 3532: }
! 3533: if ($authormanagers ne '') {
! 3534: map { $camanagers{$_.':ca'} = 1; } split(/,/,$authormanagers);
! 3535: }
1.139 raeburn 3536: }
1.2 raeburn 3537: # Get groups, role, permanent e-mail so we can sort on them if
3538: # necessary.
3539: foreach my $user (keys(%{$userlist})) {
1.43 raeburn 3540: if ($user eq '' ) {
3541: delete($userlist->{$user});
3542: next;
3543: }
1.11 raeburn 3544: if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) {
3545: delete($userlist->{$user});
3546: next;
3547: }
1.2 raeburn 3548: my ($uname,$udom,$role,$groups,$email);
1.5 raeburn 3549: if (($statusmode ne 'Any') &&
3550: ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
3551: delete($userlist->{$user});
3552: next;
3553: }
1.2 raeburn 3554: if ($context eq 'domain') {
3555: if ($env{'form.roletype'} eq 'domain') {
3556: ($role,$uname,$udom) = split(/:/,$user);
1.11 raeburn 3557: if (($uname eq $env{'request.role.domain'}.'-domainconfig') &&
3558: ($udom eq $env{'request.role.domain'})) {
3559: delete($userlist->{$user});
3560: next;
3561: }
1.13 raeburn 3562: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 3563: ($uname,$udom,$role) = split(/:/,$user,-1);
1.102 raeburn 3564: } elsif (($env{'form.roletype'} eq 'course') ||
3565: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 3566: ($uname,$udom,$role) = split(/:/,$user);
3567: }
3568: } else {
3569: ($uname,$udom,$role) = split(/:/,$user,-1);
3570: if (($context eq 'course') && $role eq '') {
3571: $role = 'st';
3572: }
3573: }
3574: $userlist->{$user}->[$index{'role'}] = $role;
3575: if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
3576: delete($userlist->{$user});
3577: next;
3578: }
1.33 raeburn 3579: if ($context eq 'course') {
3580: my @ac_groups;
3581: if (ref($classgroups) eq 'HASH') {
3582: $groups = $classgroups->{$user};
3583: }
3584: if (ref($groups->{'active'}) eq 'HASH') {
3585: @ac_groups = keys(%{$groups->{'active'}});
3586: $userlist->{$user}->[$index{'groups'}] = join(', ',@ac_groups);
3587: }
3588: if ($mode ne 'autoenroll') {
3589: my $section = $userlist->{$user}->[$index{'section'}];
1.43 raeburn 3590: if (($env{'request.course.sec'} ne '') &&
3591: ($section ne $env{'request.course.sec'})) {
3592: if ($role eq 'st') {
3593: delete($userlist->{$user});
3594: next;
3595: }
3596: }
1.33 raeburn 3597: if ($secfilter eq 'none') {
3598: if ($section ne '') {
3599: delete($userlist->{$user});
3600: next;
3601: }
3602: } elsif ($secfilter ne 'all') {
3603: if ($section ne $secfilter) {
3604: delete($userlist->{$user});
3605: next;
3606: }
3607: }
3608: if ($grpfilter eq 'none') {
3609: if (@ac_groups > 0) {
3610: delete($userlist->{$user});
3611: next;
3612: }
3613: } elsif ($grpfilter ne 'all') {
3614: if (!grep(/^\Q$grpfilter\E$/,@ac_groups)) {
3615: delete($userlist->{$user});
3616: next;
3617: }
3618: }
1.44 raeburn 3619: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
1.140 raeburn 3620: if ((grep/^photo$/,@cols) && ($role eq 'st')) {
1.44 raeburn 3621: $userlist->{$user}->[$index{'photo'}] =
1.47 raeburn 3622: &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg');
3623: $userlist->{$user}->[$index{'thumbnail'}] =
1.44 raeburn 3624: &Apache::lonnet::retrievestudentphoto($udom,$uname,
3625: 'gif','thumbnail');
3626: }
3627: }
1.150 raeburn 3628: if (($role eq 'st') && ($defaultcredits)) {
3629: if ($userlist->{$user}->[$index{'credits'}] eq '') {
3630: $userlist->{$user}->[$index{'credits'}] = $defaultcredits;
3631: }
3632: }
1.33 raeburn 3633: }
1.2 raeburn 3634: }
1.219 raeburn 3635: if ($context eq 'author') {
3636: if (($camanagers{$user}) &&
3637: ((!defined($userlist->{$user}->[$index{'end'}])) ||
3638: ($userlist->{$user}->[$index{'end'}] == 0) ||
3639: ($userlist->{$user}->[$index{'end'}] > $now))) {
3640: $userlist->{$user}->[$index{'manager'}] = &mt('Yes');
3641: } else {
3642: $userlist->{$user}->[$index{'manager'}] = &mt('No');
3643: }
3644: }
1.2 raeburn 3645: my %emails = &Apache::loncommon::getemails($uname,$udom);
3646: if ($emails{'permanentemail'} =~ /\S/) {
3647: $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
3648: }
1.159 raeburn 3649: if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
3650: ($role eq 'au')) {
3651: my ($disk_quota,$current_disk_usage,$percent);
3652: if (($needauthorusage) || ($needauthorquota)) {
3653: $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author');
3654: }
3655: if ($needauthorusage) {
3656: $current_disk_usage =
3657: &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname");
3658: if ($disk_quota == 0) {
3659: $percent = 100.0;
3660: } else {
3661: $percent = $current_disk_usage/(10 * $disk_quota);
3662: }
3663: $userlist->{$user}->[$index{'authorusage'}] = sprintf("%.0f",$percent);
3664: }
3665: if ($needauthorquota) {
3666: $userlist->{$user}->[$index{'authorquota'}] = sprintf("%.2f",$disk_quota);
3667: }
3668: }
1.4 raeburn 3669: $usercount ++;
3670: }
3671: my $autocount = 0;
3672: my $manualcount = 0;
3673: my $lockcount = 0;
3674: my $unlockcount = 0;
3675: if ($usercount) {
3676: $r->print($output);
3677: } else {
3678: if ($mode eq 'autoenroll') {
3679: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
3680: } else {
3681: return;
3682: }
1.1 raeburn 3683: }
1.2 raeburn 3684: #
3685: # Sort the users
1.1 raeburn 3686: my $index = $index{$sortby};
3687: my $second = $index{'username'};
3688: my $third = $index{'domain'};
1.159 raeburn 3689: my @sorted_users;
3690: if (($sortby eq 'authorquota') || ($sortby eq 'authorusage')) {
3691: @sorted_users = sort {
3692: $userlist->{$b}->[$index] <=> $userlist->{$a}->[$index] ||
3693: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
3694: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
3695: } (keys(%$userlist));
3696: } else {
3697: @sorted_users = sort {
3698: lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index]) ||
3699: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
3700: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
3701: } (keys(%$userlist));
3702: }
1.4 raeburn 3703: my $rowcount = 0;
1.178 raeburn 3704: my $disabled;
3705: if ($mode eq 'autoenroll') {
3706: unless ($permission->{'cusr'}) {
3707: $disabled = ' disabled="disabled"';
3708: }
3709: }
1.2 raeburn 3710: foreach my $user (@sorted_users) {
1.4 raeburn 3711: my %in;
1.2 raeburn 3712: my $sdata = $userlist->{$user};
1.4 raeburn 3713: $rowcount ++;
1.2 raeburn 3714: foreach my $item (@{$keylist}) {
3715: $in{$item} = $sdata->[$index{$item}];
3716: }
1.67 droeschl 3717: my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
3718: if ($clickers!~/\w/) { $clickers='-'; }
1.159 raeburn 3719: $in{'clicker'} = $clickers;
1.67 droeschl 3720: my $role = $in{'role'};
1.102 raeburn 3721: $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
1.136 raeburn 3722: unless ($mode eq 'excel') {
3723: if (! defined($in{'start'}) || $in{'start'} == 0) {
3724: $in{'start'} = &mt('none');
3725: } else {
3726: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
3727: }
3728: if (! defined($in{'end'}) || $in{'end'} == 0) {
3729: $in{'end'} = &mt('none');
3730: } else {
3731: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
3732: }
1.1 raeburn 3733: }
1.139 raeburn 3734: if ($context eq 'course') {
3735: my $lastlogin = $crslogins{$in{'username'}.':'.$in{'domain'}.':'.$in{'section'}.':'.$role};
3736: if ($lastlogin ne '') {
3737: $in{'lastlogin'} = &Apache::lonlocal::locallocaltime($lastlogin);
3738: }
3739: }
1.55 raeburn 3740: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2 raeburn 3741: $r->print(&Apache::loncommon::start_data_table_row());
1.11 raeburn 3742: my $checkval;
1.16 raeburn 3743: if ($mode eq 'autoenroll') {
3744: my $cellentry;
3745: if ($in{'type'} eq 'auto') {
1.178 raeburn 3746: $cellentry = '<b>'.&mt('auto').'</b> <label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Change').'</label>';
1.16 raeburn 3747: $autocount ++;
3748: } else {
1.178 raeburn 3749: $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 3750: $manualcount ++;
3751: if ($in{'lockedtype'}) {
1.178 raeburn 3752: $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Unlock').'</label>';
1.16 raeburn 3753: $unlockcount ++;
3754: } else {
1.178 raeburn 3755: $cellentry .= '<label><input type="checkbox" name="lockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Lock').'</label>';
1.16 raeburn 3756: $lockcount ++;
1.11 raeburn 3757: }
1.76 bisitz 3758: $cellentry .= '</span></td></tr></table>';
1.16 raeburn 3759: }
3760: $r->print("<td>$cellentry</td>\n");
3761: } else {
1.55 raeburn 3762: if ($mode ne 'pickauthor') {
3763: $r->print("<td>$rowcount</td>\n");
3764: }
1.16 raeburn 3765: if ($actionselect) {
1.26 raeburn 3766: my $showcheckbox;
3767: if ($role =~ /^cr\//) {
3768: $showcheckbox = $canchange{'cr'};
3769: } else {
3770: $showcheckbox = $canchange{$role};
3771: }
3772: if (!$showcheckbox) {
3773: if ($context eq 'course') {
3774: if ($canchangesec{$role} ne '') {
3775: if ($canchangesec{$role} eq $in{'section'}) {
3776: $showcheckbox = 1;
3777: }
3778: }
1.16 raeburn 3779: }
1.26 raeburn 3780: }
3781: if ($showcheckbox) {
3782: $checkval = $user;
3783: if ($context eq 'course') {
1.141 raeburn 3784: if (($role eq 'co' || $role eq 'cc') &&
3785: ($user =~ /^\Q$env{'user.name'}:$env{'user.domain'}:$role\E/)) {
3786: $showcheckbox = 0;
3787: } else {
3788: if ($role eq 'st') {
3789: $checkval .= ':st';
3790: }
3791: $checkval .= ':'.$in{'section'};
3792: if ($role eq 'st') {
3793: $checkval .= ':'.$in{'type'}.':'.
1.150 raeburn 3794: $in{'lockedtype'}.':'.
1.174 raeburn 3795: $in{'credits'}.':'.
3796: &escape($in{'instsec'});
1.141 raeburn 3797: }
3798: }
3799: }
3800: if ($showcheckbox) {
3801: $r->print('<td><input type="checkbox" name="'.
1.183 raeburn 3802: 'actionlist" value="'.
3803: &HTML::Entities::encode($checkval,'&<>"').'" />');
3804: foreach my $item ('start','end') {
3805: $r->print('<input type="hidden" name="'.
3806: &HTML::Entities::encode($checkval.'_'.$item,'&<>"').'"'.
3807: ' value="'.$sdata->[$index{$item}].'" />');
3808: }
3809: $r->print('</td>');
1.141 raeburn 3810: } else {
3811: $r->print('<td> </td>');
1.16 raeburn 3812: }
1.26 raeburn 3813: } else {
3814: $r->print('<td> </td>');
1.16 raeburn 3815: }
1.55 raeburn 3816: } elsif ($mode eq 'pickauthor') {
3817: $r->print('<td><input type="button" name="chooseauthor" onclick="javascript:gochoose('."'$in{'username'}'".');" value="'.&mt('Select').'" /></td>');
1.11 raeburn 3818: }
3819: }
1.2 raeburn 3820: foreach my $item (@cols) {
1.10 raeburn 3821: if ($item eq 'username') {
1.48 raeburn 3822: $r->print('<td>'.&print_username_link($mode,\%in).'</td>');
1.83 raeburn 3823: } elsif ($item eq 'status') {
3824: my $showitem = $in{$item};
3825: if (defined($ltstatus{$in{$item}})) {
3826: $showitem = $ltstatus{$in{$item}};
3827: }
3828: $r->print('<td>'.$showitem.'</td>'."\n");
1.140 raeburn 3829: } elsif ($item eq 'photo') {
3830: if (($context eq 'course') && ($mode ne 'autoenroll') &&
3831: ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
3832: if ($role eq 'st') {
3833: $r->print('<td align="right"><a href="javascript:photowindow('."'".$in{'photo'}."'".')"><img src="'.$in{'thumbnail'}.'" border="1" alt="" /></a></td>');
3834: } else {
3835: $r->print('<td> </td>');
3836: }
3837: }
3838: } elsif ($item eq 'clicker') {
3839: if (($context eq 'course') && ($mode ne 'autoenroll')) {
3840: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
3841: my $clickers =
3842: (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
3843: if ($clickers!~/\w/) { $clickers='-'; }
3844: $r->print('<td>'.$clickers.'</td>');
3845: } else {
3846: $r->print('<td> </td>'."\n");
3847: }
1.149 raeburn 3848: }
1.159 raeburn 3849: } elsif (($item eq 'authorquota') || ($item eq 'authorusage')) {
3850: $r->print('<td align="right">'.$in{$item}.'</td>'."\n");
1.10 raeburn 3851: } else {
3852: $r->print('<td>'.$in{$item}.'</td>'."\n");
3853: }
1.2 raeburn 3854: }
3855: $r->print(&Apache::loncommon::end_data_table_row());
3856: } elsif ($mode eq 'csv') {
3857: next if (! defined($CSVfile));
3858: # no need to bother with $linkto
3859: my @line = ();
3860: foreach my $item (@cols) {
3861: push @line,&Apache::loncommon::csv_translate($in{$item});
3862: }
1.67 droeschl 3863: print $CSVfile '"'.join('","',@line)."\"\n";
1.2 raeburn 3864: } elsif ($mode eq 'excel') {
3865: my $col = 0;
3866: foreach my $item (@cols) {
3867: if ($item eq 'start' || $item eq 'end') {
1.136 raeburn 3868: if ((defined($in{$item})) && ($in{$item} != 0)) {
1.2 raeburn 3869: $excel_sheet->write($row,$col++,
1.136 raeburn 3870: &Apache::lonstathelpers::calc_serial($in{$item}),
1.2 raeburn 3871: $format->{'date'});
3872: } else {
3873: $excel_sheet->write($row,$col++,'none');
3874: }
3875: } else {
3876: $excel_sheet->write($row,$col++,$in{$item});
3877: }
3878: }
3879: $row++;
1.1 raeburn 3880: }
3881: }
1.55 raeburn 3882: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2 raeburn 3883: $r->print(&Apache::loncommon::end_data_table().'<br />');
3884: } elsif ($mode eq 'excel') {
3885: $excel_workbook->close();
1.162 bisitz 3886: $r->print('<p>'.&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '<a href="'.$excel_filename.'">','</a>')."</p>\n");
1.2 raeburn 3887: } elsif ($mode eq 'csv') {
3888: close($CSVfile);
1.162 bisitz 3889: $r->print('<p>'.&mt('[_1]Your CSV file[_2] is ready for download.', '<a href="'.$CSVfilename.'">','</a>')."</p>\n");
1.2 raeburn 3890: $r->rflush();
3891: }
3892: if ($mode eq 'autoenroll') {
3893: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
1.4 raeburn 3894: } else {
3895: return ($usercount);
1.2 raeburn 3896: }
1.1 raeburn 3897: }
3898:
1.56 raeburn 3899: sub bulkaction_javascript {
3900: my ($formname,$caller) = @_;
3901: my $docstart = 'document';
3902: if ($caller eq 'popup') {
3903: $docstart = 'opener.document';
3904: }
3905: my %lt = &Apache::lonlocal::texthash(
3906: acwi => 'Access will be set to start immediately',
3907: asyo => 'as you did not select an end date in the pop-up window',
3908: accw => 'Access will be set to continue indefinitely',
3909: asyd => 'as you did not select an end date in the pop-up window',
3910: sewi => "Sections will be switched to 'No section'",
3911: ayes => "as you either selected the 'No section' option",
3912: oryo => 'or you did not select a section in the pop-up window',
3913: arol => 'A role with no section will be added',
3914: swbs => 'Sections will be switched to:',
3915: rwba => 'Roles will be added for section(s):',
3916: );
3917: my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
3918: my $noaction = &mt("You need to select an action to take for the user(s) you have selected");
3919: my $singconfirm = &mt(' for a single user?');
3920: my $multconfirm = &mt(' for multiple users?');
1.170 damieng 3921: &js_escape(\$alert);
3922: &js_escape(\$noaction);
3923: &js_escape(\$singconfirm);
3924: &js_escape(\$multconfirm);
1.56 raeburn 3925: my $output = <<"ENDJS";
3926: function verify_action (field) {
3927: var numchecked = 0;
3928: var singconf = '$singconfirm';
3929: var multconf = '$multconfirm';
3930: if ($docstart.$formname.elements[field].length > 0) {
3931: for (i=0; i<$docstart.$formname.elements[field].length; i++) {
3932: if ($docstart.$formname.elements[field][i].checked == true) {
3933: numchecked ++;
3934: }
3935: }
3936: } else {
3937: if ($docstart.$formname.elements[field].checked == true) {
3938: numchecked ++;
3939: }
3940: }
3941: if (numchecked == 0) {
3942: alert("$alert");
3943: return;
3944: } else {
3945: var message = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].text;
3946: var choice = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].value;
3947: if (choice == '') {
3948: alert("$noaction");
3949: return;
3950: } else {
3951: if (numchecked == 1) {
3952: message += singconf;
3953: } else {
3954: message += multconf;
3955: }
3956: ENDJS
3957: if ($caller ne 'popup') {
3958: $output .= <<"NEWWIN";
3959: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate' || choice == 'chgsec') {
3960: opendatebrowser(document.$formname,'$formname','go');
3961: return;
3962:
3963: } else {
3964: if (confirm(message)) {
3965: document.$formname.phase.value = 'bulkchange';
3966: document.$formname.submit();
3967: return;
3968: }
3969: }
3970: NEWWIN
3971: } else {
3972: $output .= <<"POPUP";
3973: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
3974: var datemsg = '';
3975: if (($docstart.$formname.startdate_month.value == '') &&
3976: ($docstart.$formname.startdate_day.value == '') &&
3977: ($docstart.$formname.startdate_year.value == '')) {
3978: datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
3979: }
3980: if (($docstart.$formname.enddate_month.value == '') &&
3981: ($docstart.$formname.enddate_day.value == '') &&
3982: ($docstart.$formname.enddate_year.value == '')) {
3983: datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
3984: }
3985: if (datemsg != '') {
3986: message += "\\n"+datemsg;
3987: }
3988: }
3989: if (choice == 'chgsec') {
3990: var rolefilter = $docstart.$formname.showrole.options[$docstart.$formname.showrole.selectedIndex].value;
3991: var retained = $docstart.$formname.retainsec.value;
3992: var secshow = $docstart.$formname.newsecs.value;
3993: if (secshow == '') {
3994: if (rolefilter == 'st' || retained == 0 || retained == "") {
3995: message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
3996: } else {
3997: message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
3998: }
3999: } else {
4000: if (rolefilter == 'st' || retained == 0 || retained == "") {
4001: message += "\\n\\n$lt{'swbs'} "+secshow+".\\n";
4002: } else {
4003: message += "\\n\\n$lt{'rwba'} "+secshow+".\\n";
4004: }
4005: }
4006: }
4007: if (confirm(message)) {
4008: $docstart.$formname.phase.value = 'bulkchange';
4009: $docstart.$formname.submit();
4010: window.close();
4011: }
4012: POPUP
4013: }
4014: $output .= '
4015: }
4016: }
4017: }
4018: ';
4019: return $output;
4020: }
4021:
1.10 raeburn 4022: sub print_username_link {
1.48 raeburn 4023: my ($mode,$in) = @_;
1.10 raeburn 4024: my $output;
1.16 raeburn 4025: if ($mode eq 'autoenroll') {
4026: $output = $in->{'username'};
1.10 raeburn 4027: } else {
4028: $output = '<a href="javascript:username_display_launch('.
1.112 bisitz 4029: "'$in->{'username'}','$in->{'domain'}'".')">'.
1.10 raeburn 4030: $in->{'username'}.'</a>';
4031: }
4032: return $output;
4033: }
4034:
1.2 raeburn 4035: sub role_type_names {
4036: my %lt = &Apache::lonlocal::texthash (
1.13 raeburn 4037: 'domain' => 'Domain Roles',
4038: 'author' => 'Co-Author Roles',
4039: 'course' => 'Course Roles',
1.101 raeburn 4040: 'community' => 'Community Roles',
1.2 raeburn 4041: );
4042: return %lt;
4043: }
4044:
1.11 raeburn 4045: sub select_actions {
1.55 raeburn 4046: my ($context,$setting,$statusmode,$formname) = @_;
1.11 raeburn 4047: my %lt = &Apache::lonlocal::texthash(
4048: revoke => "Revoke user roles",
4049: delete => "Delete user roles",
4050: reenable => "Re-enable expired user roles",
4051: activate => "Make future user roles active now",
4052: chgdates => "Change starting/ending dates",
4053: chgsec => "Change section associated with user roles",
4054: );
1.150 raeburn 4055: # FIXME Add an option to change credits for student roles.
1.11 raeburn 4056: my ($output,$options,%choices);
1.23 raeburn 4057: # FIXME Disable actions for now for roletype=course in domain context
4058: if ($context eq 'domain' && $setting eq 'course') {
4059: return;
4060: }
1.26 raeburn 4061: if ($context eq 'course') {
4062: if ($env{'form.showrole'} ne 'Any') {
1.141 raeburn 4063: my $showactions;
4064: if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},
4065: $env{'request.course.id'})) {
4066: $showactions = 1;
4067: } elsif ($env{'request.course.sec'} ne '') {
4068: if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
4069: $showactions = 1;
4070: }
4071: }
4072: unless ($showactions) {
4073: unless (&is_courseowner($env{'request.course.id'},
4074: $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
4075: return;
4076: }
1.26 raeburn 4077: }
4078: }
4079: }
1.11 raeburn 4080: if ($statusmode eq 'Any') {
4081: $options .= '
4082: <option value="chgdates">'.$lt{'chgdates'}.'</option>';
4083: $choices{'dates'} = 1;
4084: } else {
4085: if ($statusmode eq 'Future') {
4086: $options .= '
4087: <option value="activate">'.$lt{'activate'}.'</option>';
4088: $choices{'dates'} = 1;
4089: } elsif ($statusmode eq 'Expired') {
4090: $options .= '
4091: <option value="reenable">'.$lt{'reenable'}.'</option>';
4092: $choices{'dates'} = 1;
4093: }
1.13 raeburn 4094: if ($statusmode eq 'Active' || $statusmode eq 'Future') {
4095: $options .= '
4096: <option value="chgdates">'.$lt{'chgdates'}.'</option>
4097: <option value="revoke">'.$lt{'revoke'}.'</option>';
4098: $choices{'dates'} = 1;
4099: }
1.11 raeburn 4100: }
4101: if ($context eq 'domain') {
4102: $options .= '
4103: <option value="delete">'.$lt{'delete'}.'</option>';
4104: }
4105: if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
1.26 raeburn 4106: if (($statusmode ne 'Expired') && ($env{'request.course.sec'} eq '')) {
1.11 raeburn 4107: $options .= '
4108: <option value="chgsec">'.$lt{'chgsec'}.'</option>';
4109: $choices{'sections'} = 1;
4110: }
4111: }
4112: if ($options) {
1.56 raeburn 4113: $output = '<select name="bulkaction">'."\n".
1.11 raeburn 4114: '<option value="" selected="selected">'.
4115: &mt('Please select').'</option>'."\n".$options."\n".'</select>';
4116: if ($choices{'dates'}) {
4117: $output .=
4118: '<input type="hidden" name="startdate_month" value="" />'."\n".
4119: '<input type="hidden" name="startdate_day" value="" />'."\n".
4120: '<input type="hidden" name="startdate_year" value="" />'."\n".
4121: '<input type="hidden" name="startdate_hour" value="" />'."\n".
4122: '<input type="hidden" name="startdate_minute" value="" />'."\n".
4123: '<input type="hidden" name="startdate_second" value="" />'."\n".
4124: '<input type="hidden" name="enddate_month" value="" />'."\n".
4125: '<input type="hidden" name="enddate_day" value="" />'."\n".
4126: '<input type="hidden" name="enddate_year" value="" />'."\n".
4127: '<input type="hidden" name="enddate_hour" value="" />'."\n".
4128: '<input type="hidden" name="enddate_minute" value="" />'."\n".
1.56 raeburn 4129: '<input type="hidden" name="enddate_second" value="" />'."\n".
4130: '<input type="hidden" name="no_end_date" value="" />'."\n";
1.11 raeburn 4131: if ($context eq 'course') {
4132: $output .= '<input type="hidden" name="makedatesdefault" value="" />'."\n";
4133: }
4134: }
4135: if ($choices{'sections'}) {
1.91 bisitz 4136: $output .= '<input type="hidden" name="retainsec" value="" />'."\n".
4137: '<input type="hidden" name="newsecs" value="" />'."\n";
1.11 raeburn 4138: }
4139: }
4140: return $output;
4141: }
4142:
4143: sub date_section_javascript {
4144: my ($context,$setting) = @_;
1.49 raeburn 4145: my $title = 'Date_And_Section_Selector';
1.41 raeburn 4146: my %nopopup = &Apache::lonlocal::texthash (
4147: revoke => "Check the boxes for any users for whom roles are to be revoked, and click 'Proceed'",
4148: delete => "Check the boxes for any users for whom roles are to be deleted, and click 'Proceed'",
4149: none => "Choose an action to take for selected users",
4150: );
1.96 bisitz 4151: my $output = <<"ENDONE";
4152: <script type="text/javascript">
4153: // <![CDATA[
1.41 raeburn 4154: function opendatebrowser(callingform,formname,calledby) {
1.11 raeburn 4155: var bulkaction = callingform.bulkaction.options[callingform.bulkaction.selectedIndex].value;
4156: var url = '/adm/createuser?';
4157: var type = '';
4158: var showrole = callingform.showrole.options[callingform.showrole.selectedIndex].value;
4159: ENDONE
4160: if ($context eq 'domain') {
4161: $output .= '
4162: type = callingform.roletype.options[callingform.roletype.selectedIndex].value;
4163: ';
4164: }
4165: my $width= '700';
4166: my $height = '400';
4167: $output .= <<"ENDTWO";
4168: url += 'action=dateselect&callingform=' + formname +
4169: '&roletype='+type+'&showrole='+showrole +'&bulkaction='+bulkaction;
4170: var title = '$title';
4171: var options = 'scrollbars=1,resizable=1,menubar=0';
4172: options += ',width=$width,height=$height';
4173: stdeditbrowser = open(url,title,options,'1');
4174: stdeditbrowser.focus();
4175: }
1.96 bisitz 4176: // ]]>
1.11 raeburn 4177: </script>
4178: ENDTWO
4179: return $output;
4180: }
4181:
4182: sub date_section_selector {
1.150 raeburn 4183: my ($context,$permission,$crstype,$showcredits) = @_;
1.11 raeburn 4184: my $callingform = $env{'form.callingform'};
4185: my $formname = 'dateselect';
4186: my $groupslist = &get_groupslist();
1.150 raeburn 4187: my $sec_js =
4188: &setsections_javascript($formname,$groupslist,undef,undef,$crstype,
4189: $showcredits);
1.11 raeburn 4190: my $output = <<"END";
4191: <script type="text/javascript">
1.96 bisitz 4192: // <![CDATA[
1.11 raeburn 4193:
4194: $sec_js
4195:
4196: function saveselections(formname) {
4197:
4198: END
4199: if ($env{'form.bulkaction'} eq 'chgsec') {
4200: $output .= <<"END";
1.40 raeburn 4201: if (formname.retainsec.length > 1) {
4202: for (var i=0; i<formname.retainsec.length; i++) {
4203: if (formname.retainsec[i].checked == true) {
4204: opener.document.$callingform.retainsec.value = formname.retainsec[i].value;
4205: }
4206: }
4207: } else {
4208: opener.document.$callingform.retainsec.value = formname.retainsec.value;
4209: }
1.103 raeburn 4210: setSections(formname,'$crstype');
1.11 raeburn 4211: if (seccheck == 'ok') {
4212: opener.document.$callingform.newsecs.value = formname.sections.value;
1.205 raeburn 4213: } else {
4214: return;
1.11 raeburn 4215: }
4216: END
4217: } else {
4218: if ($context eq 'course') {
4219: if (($env{'form.bulkaction'} eq 'reenable') ||
4220: ($env{'form.bulkaction'} eq 'activate') ||
4221: ($env{'form.bulkaction'} eq 'chgdates')) {
1.26 raeburn 4222: if ($env{'request.course.sec'} eq '') {
4223: $output .= <<"END";
1.11 raeburn 4224:
4225: if (formname.makedatesdefault.checked == true) {
4226: opener.document.$callingform.makedatesdefault.value = 1;
4227: }
4228: else {
4229: opener.document.$callingform.makedatesdefault.value = 0;
4230: }
4231:
4232: END
1.26 raeburn 4233: }
1.11 raeburn 4234: }
4235: }
4236: $output .= <<"END";
4237: opener.document.$callingform.startdate_month.value = formname.startdate_month.options[formname.startdate_month.selectedIndex].value;
4238: opener.document.$callingform.startdate_day.value = formname.startdate_day.value;
4239: opener.document.$callingform.startdate_year.value = formname.startdate_year.value;
4240: opener.document.$callingform.startdate_hour.value = formname.startdate_hour.options[formname.startdate_hour.selectedIndex].value;
4241: opener.document.$callingform.startdate_minute.value = formname.startdate_minute.value;
4242: opener.document.$callingform.startdate_second.value = formname.startdate_second.value;
4243: opener.document.$callingform.enddate_month.value = formname.enddate_month.options[formname.enddate_month.selectedIndex].value;
4244: opener.document.$callingform.enddate_day.value = formname.enddate_day.value;
4245: opener.document.$callingform.enddate_year.value = formname.enddate_year.value;
4246: opener.document.$callingform.enddate_hour.value = formname.enddate_hour.options[formname.enddate_hour.selectedIndex].value;
4247: opener.document.$callingform.enddate_minute.value = formname.enddate_minute.value;
4248: opener.document.$callingform.enddate_second.value = formname.enddate_second.value;
1.56 raeburn 4249: if (formname.no_end_date.checked) {
4250: opener.document.$callingform.no_end_date.value = '1';
4251: } else {
4252: opener.document.$callingform.no_end_date.value = '0';
4253: }
1.11 raeburn 4254: END
4255: }
1.56 raeburn 4256: my $verify_action_js = &bulkaction_javascript($callingform,'popup');
4257: $output .= <<"ENDJS";
4258: verify_action('actionlist');
1.11 raeburn 4259: }
1.56 raeburn 4260:
4261: $verify_action_js
4262:
1.96 bisitz 4263: // ]]>
1.11 raeburn 4264: </script>
1.56 raeburn 4265: ENDJS
1.11 raeburn 4266: my %lt = &Apache::lonlocal::texthash (
4267: chac => 'Access dates to apply for selected users',
4268: chse => 'Changes in section affiliation to apply to selected users',
1.118 raeburn 4269: 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.',
4270: forn => 'For a course role that is not "student", users may have roles in more than one section at a time.',
4271: reta => "Retain each user's current section affiliations?",
1.103 raeburn 4272: dnap => '(Does not apply to student roles).',
1.11 raeburn 4273: );
4274: my ($date_items,$headertext);
4275: if ($env{'form.bulkaction'} eq 'chgsec') {
4276: $headertext = $lt{'chse'};
4277: } else {
4278: $headertext = $lt{'chac'};
4279: my $starttime;
4280: if (($env{'form.bulkaction'} eq 'activate') ||
4281: ($env{'form.bulkaction'} eq 'reenable')) {
4282: $starttime = time;
4283: }
4284: $date_items = &date_setting_table($starttime,undef,$context,
1.21 raeburn 4285: $env{'form.bulkaction'},$formname,
1.101 raeburn 4286: $permission,$crstype);
1.11 raeburn 4287: }
4288: $output .= '<h3>'.$headertext.'</h3>'.
1.118 raeburn 4289: '<form name="'.$formname.'" method="post" action="">'."\n".
1.11 raeburn 4290: $date_items;
4291: if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
1.17 raeburn 4292: my ($cnum,$cdom) = &get_course_identity();
1.103 raeburn 4293: if ($crstype eq 'Community') {
1.118 raeburn 4294: $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.');
4295: $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 4296: $lt{'dnap'} = &mt('(Does not apply to member roles).');
4297: }
1.11 raeburn 4298: my $info;
4299: if ($env{'form.showrole'} eq 'st') {
4300: $output .= '<p>'.$lt{'fors'}.'</p>';
1.26 raeburn 4301: } elsif ($env{'form.showrole'} eq 'Any') {
1.11 raeburn 4302: $output .= '<p>'.$lt{'fors'}.'</p>'.
4303: '<p>'.$lt{'forn'}.' ';
4304: $info = $lt{'reta'};
4305: } else {
4306: $output .= '<p>'.$lt{'forn'}.' ';
4307: $info = $lt{'reta'};
4308: }
4309: if ($info) {
4310: $info .= '<span class="LC_nobreak">'.
4311: '<label><input type="radio" name="retainsec" value="1" '.
4312: 'checked="checked" />'.&mt('Yes').'</label> '.
4313: '<label><input type="radio" name="retainsec" value="0" />'.
4314: &mt('No').'</label></span>';
4315: if ($env{'form.showrole'} eq 'Any') {
4316: $info .= '<br />'.$lt{'dnap'};
4317: }
4318: $info .= '</p>';
4319: } else {
4320: $info = '<input type="hidden" name="retainsec" value="0" />';
4321: }
1.21 raeburn 4322: my $rowtitle = &mt('New section to assign');
1.150 raeburn 4323: my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,
4324: $permission,$context,'chgsec',$crstype);
1.11 raeburn 4325: $output .= $info.$secbox;
4326: }
4327: $output .= '<p>'.
1.81 schafran 4328: '<input type="button" name="dateselection" value="'.&mt('Save').'" onclick="javascript:saveselections(this.form)" /></p>'."\n".
1.11 raeburn 4329: '</form>';
4330: return $output;
4331: }
4332:
1.17 raeburn 4333: sub section_picker {
1.150 raeburn 4334: my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode,$crstype,
4335: $showcredits,$credits) = @_;
1.17 raeburn 4336: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
4337: my $sections_select .= &course_sections(\%sections_count,$role);
1.118 raeburn 4338: my $secbox = '<div>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
1.17 raeburn 4339: if ($mode eq 'upload') {
4340: my ($options,$cb_script,$coursepick) =
1.150 raeburn 4341: &default_role_selector($context,1,$crstype,$showcredits);
1.59 bisitz 4342: $secbox .= &Apache::lonhtmlcommon::row_title(&mt('role'),'LC_oddrow_value').
1.17 raeburn 4343: $options. &Apache::lonhtmlcommon::row_closure(1)."\n";
4344: }
4345: $secbox .= &Apache::lonhtmlcommon::row_title($rowtitle,'LC_oddrow_value')."\n";
4346: if ($env{'request.course.sec'} eq '') {
4347: $secbox .= '<table class="LC_createuser"><tr class="LC_section_row">'."\n".
4348: '<td align="center">'.&mt('Existing sections')."\n".
4349: '<br />'.$sections_select.'</td><td align="center">'.
4350: &mt('New section').'<br />'."\n".
1.118 raeburn 4351: '<input type="text" name="newsec" size="15" value="" />'."\n".
1.17 raeburn 4352: '<input type="hidden" name="sections" value="" />'."\n".
4353: '</td></tr></table>'."\n";
4354: } else {
1.149 raeburn 4355: $secbox .= '<input type="hidden" name="sections" value="'.
1.17 raeburn 4356: $env{'request.course.sec'}.'" />'.
4357: $env{'request.course.sec'};
4358: }
1.150 raeburn 4359: $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n";
4360: unless ($mode eq 'chgsec') {
4361: if ($showcredits) {
4362: $secbox .=
4363: &Apache::lonhtmlcommon::row_title(&mt('credits (students)'),
4364: 'LC_evenrow_value')."\n".
4365: '<input type="text" name="credits" size="3" value="'.$credits.'" />'."\n".
4366: &Apache::lonhtmlcommon::row_closure(1)."\n";
4367: }
4368: }
4369: $secbox .= &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.17 raeburn 4370: return $secbox;
4371: }
4372:
1.2 raeburn 4373: sub results_header_row {
1.102 raeburn 4374: my ($rolefilter,$statusmode,$context,$permission,$mode,$crstype) = @_;
1.5 raeburn 4375: my ($description,$showfilter);
4376: if ($rolefilter ne 'Any') {
4377: $showfilter = $rolefilter;
4378: }
1.2 raeburn 4379: if ($context eq 'course') {
1.24 raeburn 4380: if ($mode eq 'csv' || $mode eq 'excel') {
1.102 raeburn 4381: if ($crstype eq 'Community') {
4382: $description = &mt('Community - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
4383: } else {
4384: $description = &mt('Course - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
4385: }
1.24 raeburn 4386: }
1.2 raeburn 4387: if ($statusmode eq 'Expired') {
1.102 raeburn 4388: if ($crstype eq 'Community') {
4389: $description .= &mt('Users in community with expired [_1] roles',$showfilter);
4390: } else {
4391: $description .= &mt('Users in course with expired [_1] roles',$showfilter);
4392: }
1.11 raeburn 4393: } elsif ($statusmode eq 'Future') {
1.102 raeburn 4394: if ($crstype eq 'Community') {
4395: $description .= &mt('Users in community with future [_1] roles',$showfilter);
4396: } else {
4397: $description .= &mt('Users in course with future [_1] roles',$showfilter);
4398: }
1.2 raeburn 4399: } elsif ($statusmode eq 'Active') {
1.102 raeburn 4400: if ($crstype eq 'Community') {
4401: $description .= &mt('Users in community with active [_1] roles',$showfilter);
4402: } else {
4403: $description .= &mt('Users in course with active [_1] roles',$showfilter);
4404: }
1.2 raeburn 4405: } else {
4406: if ($rolefilter eq 'Any') {
1.102 raeburn 4407: if ($crstype eq 'Community') {
4408: $description .= &mt('All users in community');
4409: } else {
4410: $description .= &mt('All users in course');
4411: }
1.2 raeburn 4412: } else {
1.102 raeburn 4413: if ($crstype eq 'Community') {
4414: $description .= &mt('All users in community with [_1] roles',$rolefilter);
4415: } else {
4416: $description .= &mt('All users in course with [_1] roles',$rolefilter);
4417: }
1.2 raeburn 4418: }
4419: }
1.33 raeburn 4420: my $constraint;
1.26 raeburn 4421: my $viewablesec = &viewable_section($permission);
4422: if ($viewablesec ne '') {
1.15 raeburn 4423: if ($env{'form.showrole'} eq 'st') {
1.33 raeburn 4424: $constraint = &mt('only users in section "[_1]"',$viewablesec);
1.103 raeburn 4425: } elsif (($env{'form.showrole'} ne 'cc') && ($env{'form.showrole'} ne 'co')) {
1.33 raeburn 4426: $constraint = &mt('only users affiliated with no section or section "[_1]"',$viewablesec);
4427: }
4428: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
4429: if ($env{'form.grpfilter'} eq 'none') {
4430: $constraint .= &mt(' and not in any group');
4431: } else {
4432: $constraint .= &mt(' and members of group: "[_1]"',$env{'form.grpfilter'});
4433: }
4434: }
4435: } else {
4436: if (($env{'form.secfilter'} ne 'all') && ($env{'form.secfilter'} ne '')) {
4437: if ($env{'form.secfilter'} eq 'none') {
4438: $constraint = &mt('only users affiliated with no section');
4439: } else {
4440: $constraint = &mt('only users affiliated with section "[_1]"',$env{'form.secfilter'});
4441: }
4442: }
4443: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
4444: if ($env{'form.grpfilter'} eq 'none') {
4445: if ($constraint eq '') {
4446: $constraint = &mt('only users not in any group');
4447: } else {
4448: $constraint .= &mt(' and also not in any group');
4449: }
4450: } else {
4451: if ($constraint eq '') {
4452: $constraint = &mt('only members of group: "[_1]"',$env{'form.grpfilter'});
4453: } else {
4454: $constraint .= &mt(' and also members of group: "[_1]"'.$env{'form.grpfilter'});
4455: }
4456: }
1.15 raeburn 4457: }
4458: }
1.33 raeburn 4459: if ($constraint ne '') {
4460: $description .= ' ('.$constraint.')';
4461: }
1.13 raeburn 4462: } elsif ($context eq 'author') {
1.222 ! raeburn 4463: my ($auname,$audom);
! 4464: if ($env{'request.role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)$}) {
! 4465: ($audom,$auname) = ($1,$2);
! 4466: } else {
! 4467: ($audom,$auname) = ($env{'user.domain'},$env{'user.name'});
! 4468: }
1.14 raeburn 4469: $description =
1.73 bisitz 4470: &mt('Author space for [_1]'
4471: ,'<span class="LC_cusr_emph">'
1.222 ! raeburn 4472: .&Apache::loncommon::plainname($auname,$audom)
1.73 bisitz 4473: .'</span>')
4474: .': ';
1.2 raeburn 4475: if ($statusmode eq 'Expired') {
1.5 raeburn 4476: $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
1.2 raeburn 4477: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4478: $description .= &mt('Co-authors with future [_1] roles',$showfilter);
1.2 raeburn 4479: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4480: $description .= &mt('Co-authors with active [_1] roles',$showfilter);
1.2 raeburn 4481: } else {
4482: if ($rolefilter eq 'Any') {
1.5 raeburn 4483: $description .= &mt('All co-authors');
1.2 raeburn 4484: } else {
4485: $description .= &mt('All co-authors with [_1] roles',$rolefilter);
4486: }
4487: }
4488: } elsif ($context eq 'domain') {
4489: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.73 bisitz 4490: $description = &mt('Domain - [_1]:',$domdesc).' ';
1.2 raeburn 4491: if ($env{'form.roletype'} eq 'domain') {
4492: if ($statusmode eq 'Expired') {
1.5 raeburn 4493: $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
1.2 raeburn 4494: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4495: $description .= &mt('Users in domain with future [_1] roles',$showfilter);
1.2 raeburn 4496: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4497: $description .= &mt('Users in domain with active [_1] roles',$showfilter);
1.2 raeburn 4498: } else {
4499: if ($rolefilter eq 'Any') {
1.5 raeburn 4500: $description .= &mt('All users in domain');
1.2 raeburn 4501: } else {
4502: $description .= &mt('All users in domain with [_1] roles',$rolefilter);
4503: }
4504: }
1.13 raeburn 4505: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 4506: if ($statusmode eq 'Expired') {
1.5 raeburn 4507: $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
1.2 raeburn 4508: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4509: $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
1.2 raeburn 4510: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4511: $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
1.2 raeburn 4512: } else {
4513: if ($rolefilter eq 'Any') {
1.5 raeburn 4514: $description .= &mt('All users with co-author roles in domain',$showfilter);
1.2 raeburn 4515: } else {
1.116 bisitz 4516: $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
1.2 raeburn 4517: }
4518: }
1.102 raeburn 4519: } elsif (($env{'form.roletype'} eq 'course') ||
4520: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 4521: my $coursefilter = $env{'form.coursepick'};
1.102 raeburn 4522: if ($env{'form.roletype'} eq 'course') {
4523: if ($coursefilter eq 'category') {
4524: my $instcode = &instcode_from_coursefilter();
4525: if ($instcode eq '.') {
4526: $description .= &mt('All courses in domain').' - ';
4527: } else {
4528: $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
4529: }
4530: } elsif ($coursefilter eq 'selected') {
4531: $description .= &mt('Selected courses in domain').' - ';
4532: } elsif ($coursefilter eq 'all') {
1.2 raeburn 4533: $description .= &mt('All courses in domain').' - ';
4534: }
1.102 raeburn 4535: } elsif ($env{'form.roletype'} eq 'community') {
4536: if ($coursefilter eq 'selected') {
4537: $description .= &mt('Selected communities in domain').' - ';
4538: } elsif ($coursefilter eq 'all') {
4539: $description .= &mt('All communities in domain').' - ';
4540: }
1.2 raeburn 4541: }
4542: if ($statusmode eq 'Expired') {
1.5 raeburn 4543: $description .= &mt('users with expired [_1] roles',$showfilter);
1.2 raeburn 4544: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4545: $description .= &mt('users with future [_1] roles',$showfilter);
1.2 raeburn 4546: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4547: $description .= &mt('users with active [_1] roles',$showfilter);
1.2 raeburn 4548: } else {
4549: if ($rolefilter eq 'Any') {
4550: $description .= &mt('all users');
4551: } else {
4552: $description .= &mt('users with [_1] roles',$rolefilter);
4553: }
4554: }
4555: }
4556: }
4557: return $description;
4558: }
1.22 raeburn 4559:
4560: sub viewable_section {
4561: my ($permission) = @_;
4562: my $viewablesec;
4563: if (ref($permission) eq 'HASH') {
4564: if (exists($permission->{'view_section'})) {
4565: $viewablesec = $permission->{'view_section'};
4566: } elsif (exists($permission->{'cusr_section'})) {
4567: $viewablesec = $permission->{'cusr_section'};
4568: }
4569: }
4570: return $viewablesec;
4571: }
4572:
1.2 raeburn 4573:
1.1 raeburn 4574: #################################################
4575: #################################################
4576: sub show_drop_list {
1.101 raeburn 4577: my ($r,$classlist,$nosort,$permission,$crstype) = @_;
1.29 raeburn 4578: my $cid = $env{'request.course.id'};
1.17 raeburn 4579: my ($cnum,$cdom) = &get_course_identity($cid);
1.1 raeburn 4580: if (! exists($env{'form.sortby'})) {
4581: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
4582: ['sortby']);
4583: }
4584: my $sortby = $env{'form.sortby'};
4585: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
4586: $sortby = 'username';
4587: }
4588: my $action = "drop";
1.17 raeburn 4589: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
1.1 raeburn 4590: $r->print(<<END);
4591: <input type="hidden" name="sortby" value="$sortby" />
4592: <input type="hidden" name="action" value="$action" />
4593: <input type="hidden" name="state" value="done" />
1.17 raeburn 4594: <script type="text/javascript" language="Javascript">
1.96 bisitz 4595: // <![CDATA[
1.17 raeburn 4596: $check_uncheck_js
1.96 bisitz 4597: // ]]>
1.1 raeburn 4598: </script>
1.86 bisitz 4599: <input type="hidden" name="phase" value="four" />
1.1 raeburn 4600: END
1.30 raeburn 4601: my ($indexhash,$keylist) = &make_keylist_array();
4602: my $studentcount = 0;
4603: if (ref($classlist) eq 'HASH') {
4604: foreach my $student (keys(%{$classlist})) {
4605: my $sdata = $classlist->{$student};
4606: my $status = $sdata->[$indexhash->{'status'}];
4607: my $section = $sdata->[$indexhash->{'section'}];
4608: if ($status ne 'Active') {
4609: delete($classlist->{$student});
4610: next;
4611: }
4612: if ($env{'request.course.sec'} ne '') {
4613: if ($section ne $env{'request.course.sec'}) {
4614: delete($classlist->{$student});
4615: next;
4616: }
4617: }
4618: $studentcount ++;
4619: }
4620: }
4621: if (!$studentcount) {
1.143 bisitz 4622: my $msg = '';
1.101 raeburn 4623: if ($crstype eq 'Community') {
1.143 bisitz 4624: $msg = &mt('There are no members to drop.');
1.101 raeburn 4625: } else {
1.143 bisitz 4626: $msg = &mt('There are no students to drop.');
1.101 raeburn 4627: }
1.143 bisitz 4628: $r->print('<p class="LC_info">'.$msg.'</p>');
1.30 raeburn 4629: return;
4630: }
4631: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
4632: $classlist,$keylist,$cdom,$cnum);
4633: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
4634: 'dom' => "domain",
1.162 bisitz 4635: 'id' => "ID",
1.30 raeburn 4636: 'sn' => "student name",
1.101 raeburn 4637: 'mn' => "member name",
1.30 raeburn 4638: 'sec' => "section",
4639: 'start' => "start date",
4640: 'end' => "end date",
4641: 'groups' => "active groups",
4642: );
1.101 raeburn 4643: my $nametitle = $lt{'sn'};
4644: if ($crstype eq 'Community') {
4645: $nametitle = $lt{'mn'};
4646: }
1.1 raeburn 4647: if ($nosort) {
1.17 raeburn 4648: $r->print(&Apache::loncommon::start_data_table().
4649: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 4650: $r->print(<<END);
4651: <th> </th>
4652: <th>$lt{'usrn'}</th>
4653: <th>$lt{'dom'}</th>
1.162 bisitz 4654: <th>$lt{'id'}</th>
1.101 raeburn 4655: <th>$nametitle</th>
1.1 raeburn 4656: <th>$lt{'sec'}</th>
4657: <th>$lt{'start'}</th>
4658: <th>$lt{'end'}</th>
4659: <th>$lt{'groups'}</th>
4660: END
1.17 raeburn 4661: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 4662: } else {
1.17 raeburn 4663: $r->print(&Apache::loncommon::start_data_table().
4664: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 4665: $r->print(<<END);
1.17 raeburn 4666: <th> </th>
1.1 raeburn 4667: <th>
1.162 bisitz 4668: <a href="/adm/createuser?action=$action&sortby=username">$lt{'usrn'}</a>
1.1 raeburn 4669: </th><th>
1.162 bisitz 4670: <a href="/adm/createuser?action=$action&sortby=domain">$lt{'dom'}</a>
1.1 raeburn 4671: </th><th>
1.162 bisitz 4672: <a href="/adm/createuser?action=$action&sortby=id">$lt{'id'}</a>
1.1 raeburn 4673: </th><th>
1.162 bisitz 4674: <a href="/adm/createuser?action=$action&sortby=fullname">$nametitle</a>
1.1 raeburn 4675: </th><th>
1.162 bisitz 4676: <a href="/adm/createuser?action=$action&sortby=section">$lt{'sec'}</a>
1.1 raeburn 4677: </th><th>
1.162 bisitz 4678: <a href="/adm/createuser?action=$action&sortby=start">$lt{'start'}</a>
1.1 raeburn 4679: </th><th>
1.162 bisitz 4680: <a href="/adm/createuser?action=$action&sortby=end">$lt{'end'}</a>
1.1 raeburn 4681: </th><th>
1.162 bisitz 4682: <a href="/adm/createuser?action=$action&sortby=groups">$lt{'groups'}</a>
1.1 raeburn 4683: </th>
4684: END
1.17 raeburn 4685: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 4686: }
4687: #
4688: # Sort the students
1.30 raeburn 4689: my $index = $indexhash->{$sortby};
4690: my $second = $indexhash->{'username'};
4691: my $third = $indexhash->{'domain'};
1.1 raeburn 4692: my @Sorted_Students = sort {
4693: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
4694: ||
4695: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
4696: ||
4697: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
1.30 raeburn 4698: } (keys(%{$classlist}));
1.1 raeburn 4699: foreach my $student (@Sorted_Students) {
4700: my $error;
4701: my $sdata = $classlist->{$student};
1.30 raeburn 4702: my $username = $sdata->[$indexhash->{'username'}];
4703: my $domain = $sdata->[$indexhash->{'domain'}];
4704: my $section = $sdata->[$indexhash->{'section'}];
4705: my $name = $sdata->[$indexhash->{'fullname'}];
4706: my $id = $sdata->[$indexhash->{'id'}];
4707: my $start = $sdata->[$indexhash->{'start'}];
4708: my $end = $sdata->[$indexhash->{'end'}];
1.1 raeburn 4709: my $groups = $classgroups->{$student};
4710: my $active_groups;
4711: if (ref($groups->{active}) eq 'HASH') {
4712: $active_groups = join(', ',keys(%{$groups->{'active'}}));
4713: }
4714: if (! defined($start) || $start == 0) {
4715: $start = &mt('none');
4716: } else {
4717: $start = &Apache::lonlocal::locallocaltime($start);
4718: }
4719: if (! defined($end) || $end == 0) {
4720: $end = &mt('none');
4721: } else {
4722: $end = &Apache::lonlocal::locallocaltime($end);
4723: }
1.17 raeburn 4724: my $studentkey = $student.':'.$section;
1.30 raeburn 4725: my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$indexhash->{'start'}].'" />';
1.1 raeburn 4726: #
4727: $r->print(&Apache::loncommon::start_data_table_row());
4728: $r->print(<<"END");
1.86 bisitz 4729: <td><input type="checkbox" name="droplist" value="$studentkey" /></td>
1.1 raeburn 4730: <td>$username</td>
4731: <td>$domain</td>
4732: <td>$id</td>
4733: <td>$name</td>
4734: <td>$section</td>
1.29 raeburn 4735: <td>$start $startitem</td>
1.1 raeburn 4736: <td>$end</td>
4737: <td>$active_groups</td>
4738: END
4739: $r->print(&Apache::loncommon::end_data_table_row());
4740: }
4741: $r->print(&Apache::loncommon::end_data_table().'<br />');
4742: %lt=&Apache::lonlocal::texthash(
1.29 raeburn 4743: 'dp' => "Drop Students",
1.101 raeburn 4744: 'dm' => "Drop Members",
1.1 raeburn 4745: 'ca' => "check all",
4746: 'ua' => "uncheck all",
4747: );
1.101 raeburn 4748: my $btn = $lt{'dp'};
4749: if ($crstype eq 'Community') {
4750: $btn = $lt{'dm'};
4751: }
1.1 raeburn 4752: $r->print(<<"END");
1.89 bisitz 4753: <p>
1.86 bisitz 4754: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)" />
4755: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)" />
1.89 bisitz 4756: </p>
4757: <p>
1.101 raeburn 4758: <input type="submit" value="$btn" />
1.89 bisitz 4759: </p>
1.1 raeburn 4760: END
4761: return;
4762: }
4763:
4764: #
4765: # Print out the initial form to get the file containing a list of users
4766: #
4767: sub print_first_users_upload_form {
4768: my ($r,$context) = @_;
4769: my $str;
1.86 bisitz 4770: $str = '<input type="hidden" name="phase" value="two" />';
1.1 raeburn 4771: $str .= '<input type="hidden" name="action" value="upload" />';
1.101 raeburn 4772: $str .= '<input type="hidden" name="state" value="got_file" />';
1.95 bisitz 4773:
1.147 bisitz 4774: $str .= &Apache::grades::checkforfile_js();
4775:
1.85 bisitz 4776: $str .= '<h2>'.&mt('Upload a file containing information about users').'</h2>'."\n";
1.95 bisitz 4777:
4778: # Excel and CSV Help
1.147 bisitz 4779: $str .= '<div class="LC_columnSection">'
1.95 bisitz 4780: .&Apache::loncommon::help_open_topic("Course_Create_Class_List",
4781: &mt("How do I create a users list from a spreadsheet"))
1.147 bisitz 4782: .' '.&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1.95 bisitz 4783: &mt("How do I create a CSV file from a spreadsheet"))
1.147 bisitz 4784: ."</div>\n";
1.95 bisitz 4785: $str .= &Apache::lonhtmlcommon::start_pick_box()
1.103 raeburn 4786: .&Apache::lonhtmlcommon::row_title(&mt('File'));
4787: if (&Apache::lonlocal::current_language() ne 'en') {
4788: if ($context eq 'course') {
4789: $str .= '<p class="LC_info">'."\n"
4790: .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n"
4791: .'</p>'."\n";
4792: }
4793: }
4794: $str .= &Apache::loncommon::upfile_select_html()
1.95 bisitz 4795: .&Apache::lonhtmlcommon::row_closure()
4796: .&Apache::lonhtmlcommon::row_title(
4797: '<label for="noFirstLine">'
4798: .&mt('Ignore First Line')
4799: .'</label>')
4800: .'<input type="checkbox" name="noFirstLine" id="noFirstLine" />'
4801: .&Apache::lonhtmlcommon::row_closure(1)
4802: .&Apache::lonhtmlcommon::end_pick_box();
4803:
4804: $str .= '<p>'
1.198 raeburn 4805: .'<input type="button" name="fileupload" value="'.&mt('Next').'"'
1.147 bisitz 4806: .' onclick="javascript:checkUpload(this.form);" />'
1.95 bisitz 4807: .'</p>';
4808:
1.1 raeburn 4809: $r->print($str);
4810: return;
4811: }
4812:
4813: # ================================================= Drop/Add from uploaded file
4814: sub upfile_drop_add {
1.150 raeburn 4815: my ($r,$context,$permission,$showcredits) = @_;
1.189 raeburn 4816: my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'});
4817: if ($datatoken ne '') {
4818: &Apache::loncommon::load_tmp_file($r,$datatoken);
4819: }
1.1 raeburn 4820: my @userdata=&Apache::loncommon::upfile_record_sep();
4821: if($env{'form.noFirstLine'}){shift(@userdata);}
4822: my @keyfields = split(/\,/,$env{'form.keyfields'});
4823: my %fields=();
4824: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
4825: if ($env{'form.upfile_associate'} eq 'reverse') {
4826: if ($env{'form.f'.$i} ne 'none') {
4827: $fields{$keyfields[$i]}=$env{'form.f'.$i};
4828: }
4829: } else {
4830: $fields{$env{'form.f'.$i}}=$keyfields[$i];
4831: }
4832: }
4833: #
4834: # Store the field choices away
1.150 raeburn 4835: my @storefields = qw/username names fname mname lname gen id
4836: sec ipwd email role domain inststatus/;
4837: if ($showcredits) {
4838: push (@storefields,'credits');
4839: }
4840: my %fieldstype;
4841: foreach my $field (@storefields) {
1.1 raeburn 4842: $env{'form.'.$field.'_choice'}=$fields{$field};
1.150 raeburn 4843: $fieldstype{$field.'_choice'} = 'scalar';
1.1 raeburn 4844: }
1.150 raeburn 4845: &Apache::loncommon::store_course_settings('enrollment_upload',\%fieldstype);
1.220 raeburn 4846: my ($cid,$crstype,$setting,$crsdom,$crsnum,$oldcrsuserdoms,%emptyok);
1.101 raeburn 4847: if ($context eq 'domain') {
4848: $setting = $env{'form.roleaction'};
1.220 raeburn 4849: if (exists($fields{'names'})) {
4850: map { $emptyok{$_} = 1; } ('lastname','firstname','middlename');
4851: } else {
4852: if (exists($fields{'lname'})) {
4853: $emptyok{'lastname'} = 1;
4854: }
4855: if (exists($fields{'fname'})) {
4856: $emptyok{'firstname'} = 1;
4857: }
4858: if (exists($fields{'mname'})) {
4859: $emptyok{'middlename'} = 1;
4860: }
4861: }
4862: if (exists($fields{'gen'})) {
4863: $emptyok{'generation'} = 1;
4864: }
1.101 raeburn 4865: }
4866: if ($env{'request.course.id'} ne '') {
4867: $cid = $env{'request.course.id'};
4868: $crstype = &Apache::loncommon::course_type();
1.185 raeburn 4869: $crsdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.212 raeburn 4870: $crsnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.101 raeburn 4871: } elsif ($setting eq 'course') {
4872: if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
4873: $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
4874: $crstype = &Apache::loncommon::course_type($cid);
1.185 raeburn 4875: $crsdom = $env{'form.dcdomain'};
1.212 raeburn 4876: $crsnum = $env{'form.dccourse'};
1.217 raeburn 4877: if (exists($env{'course.'.$cid.'.internal.userdomains'})) {
4878: $oldcrsuserdoms = 1;
4879: }
4880: my %coursedesc = &Apache::lonnet::coursedescription($cid,{ one_time => 1 });
4881: $env{'course.'.$cid.'.internal.userdomains'} = $coursedesc{'internal.userdomains'};
1.101 raeburn 4882: }
4883: }
1.1 raeburn 4884: my ($startdate,$enddate) = &get_dates_from_form();
4885: if ($env{'form.makedatesdefault'}) {
1.101 raeburn 4886: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
1.1 raeburn 4887: }
4888: # Determine domain and desired host (home server)
1.57 raeburn 4889: my $defdom=$env{'request.role.domain'};
4890: my $domain;
4891: if ($env{'form.defaultdomain'} ne '') {
1.185 raeburn 4892: if (($context eq 'course') || ($setting eq 'course')) {
1.190 raeburn 4893: if ($env{'form.defaultdomain'} eq $crsdom) {
4894: $domain = $env{'form.defaultdomain'};
4895: } else {
1.185 raeburn 4896: if (&Apache::lonnet::will_trust('enroll',$crsdom,$env{'form.defaultdomain'})) {
4897: $domain = $env{'form.defaultdomain'};
4898: } else {
1.192 raeburn 4899: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4900: &mt('Enrollment of users not permitted for specified default domain: [_1].',
4901: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4902: return 'untrusted';
1.185 raeburn 4903: }
4904: }
4905: } elsif ($context eq 'author') {
1.190 raeburn 4906: if ($env{'form.defaultdomain'} eq $defdom) {
4907: $domain = $env{'form.defaultdomain'};
4908: } else {
1.185 raeburn 4909: if ((&Apache::lonnet::will_trust('othcoau',$defdom,$env{'form.defaultdomain'})) &&
1.186 raeburn 4910: (&Apache::lonnet::will_trust('coaurem',$env{'form.defaultdomain'},$defdom))) {
1.185 raeburn 4911: $domain = $env{'form.defaultdomain'};
4912: } else {
1.192 raeburn 4913: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4914: &mt('Addition of users not permitted for specified default domain: [_1].',
4915: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4916: return 'untrusted';
1.185 raeburn 4917: }
4918: }
4919: } elsif (($context eq 'domain') && ($setting eq 'domain')) {
1.190 raeburn 4920: if ($env{'form.defaultdomain'} eq $defdom) {
4921: $domain = $env{'form.defaultdomain'};
4922: } else {
1.185 raeburn 4923: if (&Apache::lonnet::will_trust('domroles',$defdom,$env{'form.defaultdomain'})) {
4924: $domain = $env{'form.defaultdomain'};
4925: } else {
1.192 raeburn 4926: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4927: &mt('Addition of users not permitted for specified default domain: [_1].',
4928: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4929: return 'untrusted';
1.185 raeburn 4930: }
4931: }
4932: }
1.57 raeburn 4933: } else {
4934: $domain = $defdom;
4935: }
1.1 raeburn 4936: my $desiredhost = $env{'form.lcserver'};
4937: if (lc($desiredhost) eq 'default') {
4938: $desiredhost = undef;
4939: } else {
1.57 raeburn 4940: my %home_servers = &Apache::lonnet::get_servers($defdom,'library');
1.1 raeburn 4941: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 4942: $r->print('<p class="LC_error">'.&mt('Error').': '.
4943: &mt('Invalid home server specified').'</p>');
4944: return 'invalidhome';
1.1 raeburn 4945: }
4946: }
4947: # Determine authentication mechanism
4948: my $changeauth;
4949: if ($context eq 'domain') {
4950: $changeauth = $env{'form.changeauth'};
4951: }
4952: my $amode = '';
4953: my $genpwd = '';
1.200 raeburn 4954: my @genpwdfail;
1.1 raeburn 4955: if ($env{'form.login'} eq 'krb') {
4956: $amode='krb';
4957: $amode.=$env{'form.krbver'};
4958: $genpwd=$env{'form.krbarg'};
4959: } elsif ($env{'form.login'} eq 'int') {
4960: $amode='internal';
4961: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
4962: $genpwd=$env{'form.intarg'};
1.200 raeburn 4963: @genpwdfail =
1.202 raeburn 4964: &Apache::loncommon::check_passwd_rules($domain,$genpwd);
1.1 raeburn 4965: }
4966: } elsif ($env{'form.login'} eq 'loc') {
4967: $amode='localauth';
4968: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
4969: $genpwd=$env{'form.locarg'};
4970: }
1.194 raeburn 4971: } elsif ($env{'form.login'} eq 'lti') {
4972: $amode='lti';
1.1 raeburn 4973: }
4974: if ($amode =~ /^krb/) {
4975: if (! defined($genpwd) || $genpwd eq '') {
1.193 raeburn 4976: $r->print('<span class="Error">'.
1.1 raeburn 4977: &mt('Unable to enroll users').' '.
4978: &mt('No Kerberos domain was specified.').'</span></p>');
4979: $amode = ''; # This causes the loop below to be skipped
4980: }
4981: }
1.150 raeburn 4982: my ($defaultsec,$defaultrole,$defaultcredits,$commoncredits);
1.1 raeburn 4983: if ($context eq 'domain') {
4984: if ($setting eq 'domain') {
4985: $defaultrole = $env{'form.defaultrole'};
4986: } elsif ($setting eq 'course') {
4987: $defaultrole = $env{'form.courserole'};
1.27 raeburn 4988: $defaultsec = $env{'form.sections'};
1.150 raeburn 4989: if ($showcredits) {
4990: $commoncredits = $env{'form.credits'};
4991: if ($crstype ne 'Community') {
4992: my %coursehash=&Apache::lonnet::coursedescription($cid);
4993: $defaultcredits = $coursehash{'internal.defaultcredits'};
4994: }
4995: }
1.149 raeburn 4996: }
1.13 raeburn 4997: } elsif ($context eq 'author') {
1.1 raeburn 4998: $defaultrole = $env{'form.defaultrole'};
1.27 raeburn 4999: } elsif ($context eq 'course') {
5000: $defaultrole = $env{'form.defaultrole'};
5001: $defaultsec = $env{'form.sections'};
1.150 raeburn 5002: if ($showcredits) {
5003: $commoncredits = $env{'form.credits'};
5004: $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
5005: }
1.1 raeburn 5006: }
1.27 raeburn 5007: # Check to see if user information can be changed
5008: my @userinfo = ('firstname','middlename','lastname','generation',
5009: 'permanentemail','id');
5010: my %canmodify;
5011: if (&Apache::lonnet::allowed('mau',$domain)) {
1.84 raeburn 5012: push(@userinfo,'inststatus');
1.27 raeburn 5013: foreach my $field (@userinfo) {
5014: $canmodify{$field} = 1;
5015: }
5016: }
5017: my (%userlist,%modifiable_fields,@poss_roles);
5018: my $secidx = &Apache::loncoursedata::CL_SECTION();
1.102 raeburn 5019: my @courseroles = &roles_by_context('course',1,$crstype);
1.27 raeburn 5020: if (!&Apache::lonnet::allowed('mau',$domain)) {
5021: if ($context eq 'course' || $context eq 'author') {
1.101 raeburn 5022: @poss_roles = &curr_role_permissions($context,'','',$crstype);
1.27 raeburn 5023: my @statuses = ('active','future');
5024: my ($indexhash,$keylist) = &make_keylist_array();
5025: my %info;
5026: foreach my $role (@poss_roles) {
5027: %{$modifiable_fields{$role}} = &can_modify_userinfo($context,$domain,
5028: \@userinfo,[$role]);
5029: }
5030: if ($context eq 'course') {
5031: my ($cnum,$cdom) = &get_course_identity();
5032: my $roster = &Apache::loncoursedata::get_classlist();
1.66 raeburn 5033: if (ref($roster) eq 'HASH') {
5034: %userlist = %{$roster};
5035: }
1.27 raeburn 5036: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
5037: \@statuses,\@poss_roles);
5038: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
5039: \%advrolehash,$permission);
5040: } elsif ($context eq 'author') {
5041: my %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
5042: \@statuses,\@poss_roles);
5043: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
5044: \%cstr_roles,$permission);
5045: }
5046: }
1.1 raeburn 5047: }
1.193 raeburn 5048: if ($datatoken eq '') {
5049: $r->print('<p class="LC_error">'.&mt('Error').': '.
5050: &mt('Invalid datatoken').'</p>');
5051: return 'missingdata';
5052: }
1.1 raeburn 5053: if ( $domain eq &LONCAPA::clean_domain($domain)
5054: && ($amode ne '')) {
5055: #######################################
5056: ## Add/Modify Users ##
5057: #######################################
5058: if ($context eq 'course') {
5059: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
1.13 raeburn 5060: } elsif ($context eq 'author') {
1.1 raeburn 5061: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
5062: } else {
5063: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
5064: }
1.87 bisitz 5065: $r->rflush;
1.212 raeburn 5066: my (%got_role_approvals,%got_instdoms,%process_by,%instdoms,
1.213 raeburn 5067: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
1.87 bisitz 5068:
1.1 raeburn 5069: my %counts = (
5070: user => 0,
5071: auth => 0,
5072: role => 0,
5073: );
5074: my $flushc=0;
5075: my %student=();
1.42 raeburn 5076: my (%curr_groups,@sections,@cleansec,$defaultwarn,$groupwarn);
1.1 raeburn 5077: my %userchg;
1.27 raeburn 5078: if ($context eq 'course' || $setting eq 'course') {
5079: if ($context eq 'course') {
5080: # Get information about course groups
5081: %curr_groups = &Apache::longroup::coursegroups();
5082: } elsif ($setting eq 'course') {
5083: if ($cid) {
5084: %curr_groups =
5085: &Apache::longroup::coursegroups($env{'form.dcdomain'},
5086: $env{'form.dccourse'});
5087: }
5088: }
5089: # determine section number
5090: if ($defaultsec =~ /,/) {
5091: push(@sections,split(/,/,$defaultsec));
5092: } else {
5093: push(@sections,$defaultsec);
5094: }
5095: # remove non alphanumeric values from section
5096: foreach my $item (@sections) {
5097: $item =~ s/\W//g;
5098: if ($item eq "none" || $item eq 'all') {
5099: $defaultwarn = &mt('Default section name [_1] could not be used as it is a reserved word.',$item);
5100: } elsif ($item ne '' && exists($curr_groups{$item})) {
5101: $groupwarn = &mt('Default section name "[_1]" is the name of a course group. Section names and group names must be distinct.',$item);
5102: } elsif ($item ne '') {
5103: push(@cleansec,$item);
5104: }
5105: }
5106: if ($defaultwarn) {
5107: $r->print($defaultwarn.'<br />');
5108: }
5109: if ($groupwarn) {
5110: $r->print($groupwarn.'<br />');
5111: }
1.1 raeburn 5112: }
1.124 raeburn 5113: my (%curr_rules,%got_rules,%alerts,%cancreate);
1.104 raeburn 5114: my %customroles = &my_custom_roles($crstype);
1.101 raeburn 5115: my @permitted_roles =
1.124 raeburn 5116: &roles_on_upload($context,$setting,$crstype,%customroles);
5117: my %longtypes = &Apache::lonlocal::texthash(
5118: official => 'Institutional',
5119: unofficial => 'Non-institutional',
5120: );
1.135 raeburn 5121: my $newuserdom = $env{'request.role.domain'};
5122: map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes);
1.1 raeburn 5123: # Get new users list
1.200 raeburn 5124: my (%existinguser,%userinfo,%disallow,%rulematch,%inst_results,%alerts,%checkuname,
5125: %showpasswdrules,$haspasswdmap);
1.171 raeburn 5126: my $counter = -1;
1.185 raeburn 5127: my (%willtrust,%trustchecked);
1.27 raeburn 5128: foreach my $line (@userdata) {
1.171 raeburn 5129: $counter ++;
1.42 raeburn 5130: my @secs;
1.27 raeburn 5131: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 5132: # Determine user name
1.128 raeburn 5133: $entries{$fields{'username'}} =~ s/^\s+|\s+$//g;
1.1 raeburn 5134: unless (($entries{$fields{'username'}} eq '') ||
5135: (!defined($entries{$fields{'username'}}))) {
5136: my ($fname, $mname, $lname,$gen) = ('','','','');
5137: if (defined($fields{'names'})) {
5138: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
5139: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
5140: } else {
5141: if (defined($fields{'fname'})) {
5142: $fname=$entries{$fields{'fname'}};
5143: }
5144: if (defined($fields{'mname'})) {
5145: $mname=$entries{$fields{'mname'}};
5146: }
5147: if (defined($fields{'lname'})) {
5148: $lname=$entries{$fields{'lname'}};
5149: }
5150: if (defined($fields{'gen'})) {
5151: $gen=$entries{$fields{'gen'}};
5152: }
5153: }
1.128 raeburn 5154:
1.1 raeburn 5155: if ($entries{$fields{'username'}}
5156: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
1.128 raeburn 5157: my $nowhitespace;
5158: if ($entries{$fields{'username'}} =~ /\s/) {
5159: $nowhitespace = ' - '.&mt('usernames may not contain spaces.');
5160: }
1.171 raeburn 5161: $disallow{$counter} =
1.157 bisitz 5162: &mt('Unacceptable username [_1] for user [_2] [_3] [_4] [_5]',
1.171 raeburn 5163: '"<b>'.$entries{$fields{'username'}}.'</b>"',
5164: $fname,$mname,$lname,$gen).$nowhitespace;
1.27 raeburn 5165: next;
1.1 raeburn 5166: } else {
1.129 raeburn 5167: $entries{$fields{'domain'}} =~ s/^\s+|\s+$//g;
1.71 droeschl 5168: if ($entries{$fields{'domain'}}
1.57 raeburn 5169: ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
1.171 raeburn 5170: $disallow{$counter} =
1.157 bisitz 5171: &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
1.171 raeburn 5172: '"<b>'.$entries{$fields{'domain'}}.'</b>"',
5173: $fname,$mname,$lname,$gen);
5174: next;
1.185 raeburn 5175: } elsif ($entries{$fields{'domain'}} ne $domain) {
5176: my $possdom = $entries{$fields{'domain'}};
5177: if ($context eq 'course' || $setting eq 'course') {
5178: unless ($trustchecked{$possdom}) {
5179: $willtrust{$possdom} = &Apache::lonnet::will_trust('enroll',$domain,$possdom);
5180: $trustchecked{$possdom} = 1;
5181: }
5182: } elsif ($context eq 'author') {
5183: unless ($trustchecked{$possdom}) {
5184: $willtrust{$possdom} = &Apache::lonnet::will_trust('othcoau',$domain,$possdom);
5185: }
5186: if ($willtrust{$possdom}) {
5187: $willtrust{$possdom} = &Apache::lonnet::will_trust('coaurem',$possdom,$domain);
5188: }
5189: }
5190: unless ($willtrust{$possdom}) {
5191: $disallow{$counter} =
5192: &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
5193: '"<b>'.$possdom.'</b>"',
5194: $fname,$mname,$lname,$gen);
5195: next;
5196: }
1.57 raeburn 5197: }
1.5 raeburn 5198: my $username = $entries{$fields{'username'}};
1.57 raeburn 5199: my $userdomain = $entries{$fields{'domain'}};
5200: if ($userdomain eq '') {
5201: $userdomain = $domain;
5202: }
1.27 raeburn 5203: if (defined($fields{'sec'})) {
5204: if (defined($entries{$fields{'sec'}})) {
1.42 raeburn 5205: $entries{$fields{'sec'}} =~ s/\W//g;
1.27 raeburn 5206: my $item = $entries{$fields{'sec'}};
5207: if ($item eq "none" || $item eq 'all') {
1.171 raeburn 5208: $disallow{$counter} =
5209: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a reserved word.',
5210: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item);
1.27 raeburn 5211: next;
5212: } elsif (exists($curr_groups{$item})) {
1.171 raeburn 5213: $disallow{$counter} =
5214: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a course group.',
5215: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item).' '.
5216: &mt('Section names and group names must be distinct.');
1.27 raeburn 5217: next;
5218: } else {
5219: push(@secs,$item);
5220: }
5221: }
5222: }
5223: if ($env{'request.course.sec'} ne '') {
5224: @secs = ($env{'request.course.sec'});
1.57 raeburn 5225: if (ref($userlist{$username.':'.$userdomain}) eq 'ARRAY') {
5226: my $currsec = $userlist{$username.':'.$userdomain}[$secidx];
1.27 raeburn 5227: if ($currsec ne $env{'request.course.sec'}) {
1.171 raeburn 5228: $disallow{$counter} =
5229: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]".',
5230: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$secs[0]);
1.27 raeburn 5231: if ($currsec eq '') {
1.171 raeburn 5232: $disallow{$counter} .=
5233: &mt('This user already has an active/future student role in the course, unaffiliated to any section.');
1.27 raeburn 5234:
5235: } else {
1.171 raeburn 5236: $disallow{$counter} .=
5237: &mt('This user already has an active/future role in section "[_1]" of the course.',$currsec);
1.27 raeburn 5238: }
1.171 raeburn 5239: $disallow{$counter} .=
5240: '<br />'.
5241: &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.',
5242: $secs[0]);
1.27 raeburn 5243: next;
1.1 raeburn 5244: }
5245: }
1.27 raeburn 5246: } elsif ($context eq 'course' || $setting eq 'course') {
5247: if (@secs == 0) {
5248: @secs = @cleansec;
1.1 raeburn 5249: }
5250: }
5251: # determine id number
5252: my $id='';
5253: if (defined($fields{'id'})) {
5254: if (defined($entries{$fields{'id'}})) {
5255: $id=$entries{$fields{'id'}};
5256: }
5257: $id=~tr/A-Z/a-z/;
5258: }
5259: # determine email address
5260: my $email='';
5261: if (defined($fields{'email'})) {
1.129 raeburn 5262: $entries{$fields{'email'}} =~ s/^\s+|\s+$//g;
1.1 raeburn 5263: if (defined($entries{$fields{'email'}})) {
5264: $email=$entries{$fields{'email'}};
1.84 raeburn 5265: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
5266: }
5267: }
5268: # determine affiliation
5269: my $inststatus='';
5270: if (defined($fields{'inststatus'})) {
5271: if (defined($entries{$fields{'inststatus'}})) {
5272: $inststatus=$entries{$fields{'inststatus'}};
5273: }
1.1 raeburn 5274: }
5275: # determine user password
1.200 raeburn 5276: my $password;
5277: my $passwdfromfile;
1.1 raeburn 5278: if (defined($fields{'ipwd'})) {
5279: if ($entries{$fields{'ipwd'}}) {
5280: $password=$entries{$fields{'ipwd'}};
1.200 raeburn 5281: $passwdfromfile = 1;
5282: if ($env{'form.login'} eq 'int') {
5283: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
5284: if (($uhome eq 'no_host') || ($changeauth)) {
5285: my @brokepwdrules =
5286: &Apache::loncommon::check_passwd_rules($domain,$password);
5287: if (@brokepwdrules) {
5288: $disallow{$counter} = &mt('[_1]: Password included in file for this user did not meet requirements.',
5289: '<b>'.$username.'</b>');
5290: map { $showpasswdrules{$_} = 1; } @brokepwdrules;
5291: next;
5292: }
5293: }
5294: }
5295: }
5296: }
5297: unless ($passwdfromfile) {
5298: if ($env{'form.login'} eq 'int') {
5299: if (@genpwdfail) {
5300: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
5301: if (($uhome eq 'no_host') || ($changeauth)) {
5302: $disallow{$counter} = &mt('[_1]: No specific password in file for this user; default password did not meet requirements',
5303: '<b>'.$username.'</b>');
5304: unless ($haspasswdmap) {
5305: map { $showpasswdrules{$_} = 1; } @genpwdfail;
5306: $haspasswdmap = 1;
5307: }
5308: }
5309: next;
5310: }
1.1 raeburn 5311: }
1.200 raeburn 5312: $password = $genpwd;
1.1 raeburn 5313: }
5314: # determine user role
5315: my $role = '';
5316: if (defined($fields{'role'})) {
5317: if ($entries{$fields{'role'}}) {
1.42 raeburn 5318: $entries{$fields{'role'}} =~ s/(\s+$|^\s+)//g;
5319: if ($entries{$fields{'role'}} ne '') {
5320: if (grep(/^\Q$entries{$fields{'role'}}\E$/,@permitted_roles)) {
5321: $role = $entries{$fields{'role'}};
1.27 raeburn 5322: }
5323: }
5324: if ($role eq '') {
5325: my $rolestr = join(', ',@permitted_roles);
1.171 raeburn 5326: $disallow{$counter} =
5327: &mt('[_1]: You do not have permission to add the requested role [_2] for the user.'
5328: ,'<b>'.$entries{$fields{'username'}}.'</b>'
5329: ,$entries{$fields{'role'}})
5330: .'<br />'
5331: .&mt('Allowable role(s) is/are: [_1].',$rolestr);
1.1 raeburn 5332: next;
5333: }
5334: }
5335: }
5336: if ($role eq '') {
5337: $role = $defaultrole;
5338: }
5339: # Clean up whitespace
1.129 raeburn 5340: foreach (\$id,\$fname,\$mname,\$lname,\$gen,\$inststatus) {
1.1 raeburn 5341: $$_ =~ s/(\s+$|^\s+)//g;
5342: }
1.150 raeburn 5343: my $credits;
5344: if ($showcredits) {
5345: if (($role eq 'st') && ($crstype ne 'Community')) {
5346: $credits = $entries{$fields{'credits'}};
5347: if ($credits ne '') {
5348: $credits =~ s/[^\d\.]//g;
5349: }
5350: if ($credits eq '') {
5351: $credits = $commoncredits;
5352: }
5353: if ($credits eq $defaultcredits) {
5354: undef($credits);
5355: }
5356: }
5357: }
1.5 raeburn 5358: # check against rules
5359: my $checkid = 0;
5360: my $newuser = 0;
1.57 raeburn 5361: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
1.5 raeburn 5362: if ($uhome eq 'no_host') {
1.135 raeburn 5363: if ($userdomain ne $newuserdom) {
5364: if ($context eq 'course') {
1.171 raeburn 5365: $disallow{$counter} =
5366: &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
5367: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 5368: } elsif ($context eq 'author') {
1.171 raeburn 5369: $disallow{$counter} =
5370: &mt('[_1]: The domain specified ([_2]) is different to that of the author.',
5371: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 5372: } else {
1.171 raeburn 5373: $disallow{$counter} =
5374: &mt('[_1]: The domain specified ([_2]) is different to that of your current role.',
5375: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 5376: }
1.171 raeburn 5377: $disallow{$counter} .=
5378: &mt('The user does not already exist, and you may not create a new user in a different domain.');
1.124 raeburn 5379: next;
1.171 raeburn 5380: } else {
1.194 raeburn 5381: unless (($password ne '') || ($env{'form.login'} eq 'loc') || ($env{'form.login'} eq 'lti')) {
1.171 raeburn 5382: $disallow{$counter} =
5383: &mt('[_1]: This is a new user but no default password was provided, and the authentication type requires one.',
5384: '<b>'.$username.'</b>');
5385: next;
5386: }
1.124 raeburn 5387: }
1.5 raeburn 5388: $checkid = 1;
5389: $newuser = 1;
1.172 raeburn 5390: $checkuname{$username.':'.$newuserdom} = { 'newuser' => $newuser, 'id' => $id };
1.13 raeburn 5391: } else {
1.27 raeburn 5392: if ($context eq 'course' || $context eq 'author') {
1.57 raeburn 5393: if ($userdomain eq $domain ) {
5394: if ($role eq '') {
5395: my @checkroles;
5396: foreach my $role (@poss_roles) {
5397: my $endkey;
5398: if ($role ne 'st') {
5399: $endkey = ':'.$role;
5400: }
5401: if (exists($userlist{$username.':'.$userdomain.$endkey})) {
5402: if (!grep(/^\Q$role\E$/,@checkroles)) {
5403: push(@checkroles,$role);
5404: }
5405: }
1.27 raeburn 5406: }
1.57 raeburn 5407: if (@checkroles > 0) {
5408: %canmodify = &can_modify_userinfo($context,$domain,\@userinfo,\@checkroles);
1.27 raeburn 5409: }
1.57 raeburn 5410: } elsif (ref($modifiable_fields{$role}) eq 'HASH') {
5411: %canmodify = %{$modifiable_fields{$role}};
1.27 raeburn 5412: }
5413: }
1.57 raeburn 5414: my @newinfo = (\$fname,\$mname,\$lname,\$gen,\$email,\$id);
1.84 raeburn 5415: for (my $i=0; $i<@newinfo; $i++) {
1.57 raeburn 5416: if (${$newinfo[$i]} ne '') {
5417: if (!$canmodify{$userinfo[$i]}) {
5418: ${$newinfo[$i]} = '';
5419: }
1.27 raeburn 5420: }
5421: }
5422: }
1.171 raeburn 5423: if ($id) {
5424: $existinguser{$userdomain}{$username} = $id;
5425: }
1.5 raeburn 5426: }
1.171 raeburn 5427: $userinfo{$counter} = {
5428: username => $username,
5429: domain => $userdomain,
5430: fname => $fname,
5431: mname => $mname,
5432: lname => $lname,
5433: gen => $gen,
5434: email => $email,
5435: id => $id,
5436: password => $password,
5437: inststatus => $inststatus,
5438: role => $role,
5439: sections => \@secs,
5440: credits => $credits,
5441: newuser => $newuser,
5442: checkid => $checkid,
5443: };
5444: }
5445: }
5446: } # end of foreach (@userdata)
5447: if ($counter > -1) {
5448: my $total = $counter + 1;
5449: my %checkids;
1.172 raeburn 5450: if ((keys(%existinguser)) || (keys(%checkuname))) {
5451: $r->print(&mt('Please be patient -- checking for institutional data ...'));
5452: $r->rflush();
5453: if (keys(%existinguser)) {
5454: foreach my $dom (keys(%existinguser)) {
5455: if (ref($existinguser{$dom}) eq 'HASH') {
5456: my %idhash = &Apache::lonnet::idrget($dom,keys(%{$existinguser{$dom}}));
5457: foreach my $username (keys(%{$existinguser{$dom}})) {
5458: if ($idhash{$username} ne $existinguser{$dom}{$username}) {
5459: $checkids{$username.':'.$dom} = {
5460: 'id' => $existinguser{$dom}{$username},
5461: };
5462: }
5463: }
5464: if (keys(%checkids)) {
5465: &Apache::loncommon::user_rule_check(\%checkids,{ 'id' => 1 },
5466: \%alerts,\%rulematch,
5467: \%inst_results,\%curr_rules,
5468: \%got_rules);
1.171 raeburn 5469: }
5470: }
5471: }
5472: }
1.172 raeburn 5473: if (keys(%checkuname)) {
5474: &Apache::loncommon::user_rule_check(\%checkuname,{ 'username' => 1, 'id' => 1, },
5475: \%alerts,\%rulematch,\%inst_results,
5476: \%curr_rules,\%got_rules);
5477: }
5478: $r->print(' '.&mt('done').'<br /><br />');
5479: $r->rflush();
1.171 raeburn 5480: }
1.172 raeburn 5481: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,$total);
1.171 raeburn 5482: $r->print('<ul>');
5483: for (my $i=0; $i<=$counter; $i++) {
5484: if ($disallow{$i}) {
5485: $r->print('<li>'.$disallow{$i}.'</li>');
5486: } elsif (ref($userinfo{$i}) eq 'HASH') {
5487: my $password = $userinfo{$i}{'password'};
5488: my $newuser = $userinfo{$i}{'newuser'};
5489: my $checkid = $userinfo{$i}{'checkid'};
5490: my $id = $userinfo{$i}{'id'};
5491: my $role = $userinfo{$i}{'role'};
5492: my @secs;
5493: if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
5494: @secs = @{$userinfo{$i}{'sections'}};
5495: }
5496: my $fname = $userinfo{$i}{'fname'};
5497: my $mname = $userinfo{$i}{'mname'};
5498: my $lname = $userinfo{$i}{'lname'};
5499: my $gen = $userinfo{$i}{'gen'};
5500: my $email = $userinfo{$i}{'email'};
5501: my $inststatus = $userinfo{$i}{'inststatus'};
5502: my $credits = $userinfo{$i}{'credits'};
5503: my $username = $userinfo{$i}{'username'};
5504: my $userdomain = $userinfo{$i}{'domain'};
5505: my $user = $username.':'.$userdomain;
5506: if ($newuser) {
5507: if (ref($alerts{'username'}) eq 'HASH') {
5508: if (ref($alerts{'username'}{$userdomain}) eq 'HASH') {
5509: if ($alerts{'username'}{$userdomain}{$username}) {
5510: $r->print('<li>'.
5511: &mt('[_1]: matches the username format at your institution, but is not known to your directory service.','<b>'.$username.'</b>').'<br />'.
5512: &mt('Consequently, the user was not created.').'</li>');
5513: next;
5514: }
5515: }
5516: }
1.172 raeburn 5517: if (ref($inst_results{$user}) eq 'HASH') {
5518: if ($inst_results{$user}{'firstname'} ne '') {
5519: $fname = $inst_results{$user}{'firstname'};
5520: }
5521: if ($inst_results{$user}{'middlename'} ne '') {
5522: $mname = $inst_results{$user}{'middlename'};
5523: }
5524: if ($inst_results{$user}{'lasttname'} ne '') {
5525: $lname = $inst_results{$user}{'lastname'};
5526: }
5527: if ($inst_results{$user}{'permanentemail'} ne '') {
5528: $email = $inst_results{$user}{'permanentemail'};
5529: }
5530: if ($inst_results{$user}{'id'} ne '') {
5531: $id = $inst_results{$user}{'id'};
5532: $checkid = 0;
5533: }
5534: if (ref($inst_results{$user}{'inststatus'}) eq 'ARRAY') {
5535: $inststatus = join(':',@{$inst_results{$user}{'inststatus'}});
5536: }
5537: }
5538: if (($checkid) && ($id ne '')) {
5539: if (ref($alerts{'id'}) eq 'HASH') {
5540: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
5541: if ($alerts{'id'}{$userdomain}{$username}) {
5542: $r->print('<li>'.
5543: &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
5544: '<b>'.$username.'</b>').'<br />'.
5545: &mt('Consequently, the user was not created.').'</li>');
5546: next;
5547: }
5548: }
5549: }
5550: }
1.171 raeburn 5551: my $usertype = 'unofficial';
5552: if (ref($rulematch{$user}) eq 'HASH') {
5553: if ($rulematch{$user}{'username'}) {
5554: $usertype = 'official';
1.5 raeburn 5555: }
5556: }
1.171 raeburn 5557: unless ($cancreate{$usertype}) {
5558: my $showtype = $longtypes{$usertype};
5559: $r->print('<li>'.
5560: &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].','<b>'.$username.'</b>',$showtype).'</li>');
5561: next;
5562: }
1.172 raeburn 5563: } elsif ($id ne '') {
1.171 raeburn 5564: if (exists($checkids{$user})) {
5565: $checkid = 1;
1.5 raeburn 5566: if (ref($alerts{'id'}) eq 'HASH') {
1.57 raeburn 5567: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
1.172 raeburn 5568: if ($alerts{'id'}{$userdomain}{$username}) {
1.171 raeburn 5569: $r->print('<li>'.
1.172 raeburn 5570: &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 5571: '<b>'.$username.'</b>').'<br />'.
1.172 raeburn 5572: &mt('Consequently, the ID was not changed.').'</li>');
5573: $id = '';
1.124 raeburn 5574: }
1.5 raeburn 5575: }
5576: }
5577: }
5578: }
1.171 raeburn 5579: my $multiple = 0;
5580: my ($userresult,$authresult,$roleresult,$idresult);
5581: my (%userres,%authres,%roleres,%idres);
5582: my $singlesec = '';
5583: if ($role eq 'st') {
1.206 raeburn 5584: if (($context eq 'domain') && ($changeauth eq 'Yes') && (!$newuser)) {
5585: if ((&Apache::lonnet::allowed('mau',$userdomain)) &&
5586: (&Apache::lonnet::homeserver($username,$userdomain) ne 'no_host')) {
5587: if ((($amode =~ /^krb4|krb5|internal$/) && $password ne '') ||
5588: ($amode eq 'localauth')) {
5589: $authresult =
5590: &Apache::lonnet::modifyuserauth($userdomain,$username,$amode,$password);
5591: }
5592: }
5593: }
1.171 raeburn 5594: my $sec;
5595: if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
1.42 raeburn 5596: if (@secs > 0) {
5597: $sec = $secs[0];
1.27 raeburn 5598: }
1.171 raeburn 5599: }
1.212 raeburn 5600: if ($userdomain ne $env{'request.role.domain'}) {
5601: my $item = "/$crsdom/$crsnum" ;
5602: if ($sec ne '') {
5603: $item .= "/$sec";
5604: }
5605: $item .= '_st';
5606: next if (&restricted_dom($context,$item,$userdomain,$username,$role,$startdate,
5607: $enddate,$crsdom,$crsnum,$sec,$credits,\%process_by,
5608: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.213 raeburn 5609: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.212 raeburn 5610: }
1.171 raeburn 5611: &modifystudent($userdomain,$username,$cid,$sec,
5612: $desiredhost,$context);
5613: $roleresult =
5614: &Apache::lonnet::modifystudent
5615: ($userdomain,$username,$id,$amode,$password,
5616: $fname,$mname,$lname,$gen,$sec,$enddate,
5617: $startdate,$env{'form.forceid'},
5618: $desiredhost,$email,'manual','',$cid,
5619: '',$context,$inststatus,$credits);
5620: $userresult = $roleresult;
5621: } else {
1.212 raeburn 5622: my $possrole;
5623: if ($role ne '') {
1.171 raeburn 5624: if ($context eq 'course' || $setting eq 'course') {
5625: if ($customroles{$role}) {
5626: $role = 'cr_'.$env{'user.domain'}.'_'.
5627: $env{'user.name'}.'_'.$role;
5628: }
1.212 raeburn 5629: $possrole = $role;
5630: if ($possrole =~ /^cr_/) {
5631: $possrole =~ s{_}{/}g;
5632: }
5633: if (($role ne 'cc') && ($role ne 'co')) {
1.171 raeburn 5634: if (@secs > 1) {
5635: $multiple = 1;
1.212 raeburn 5636: my $prefix = "/$crsdom/$crsnum";
1.171 raeburn 5637: foreach my $sec (@secs) {
1.212 raeburn 5638: if ($userdomain ne $env{'request.role.domain'}) {
5639: my $item = $prefix;
5640: if ($sec ne '') {
5641: $item .= "/$sec";
5642: }
5643: $item .= '_'.$possrole;
5644: next if (&restricted_dom($context,$item,$userdomain,$username,$possrole,
5645: $startdate,$enddate,$crsdom,$crsnum,$sec,
5646: $credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 5647: \%got_instdoms,\%reject,\%pending,\%notifydc,
5648: \%status,\%unauthorized,\%currqueued));
1.212 raeburn 5649: }
1.171 raeburn 5650: ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
5651: &modifyuserrole($context,$setting,
5652: $changeauth,$cid,$userdomain,$username,
5653: $id,$amode,$password,$fname,
5654: $mname,$lname,$gen,$sec,
5655: $env{'form.forceid'},$desiredhost,
5656: $email,$role,$enddate,
5657: $startdate,$checkid,$inststatus);
1.42 raeburn 5658: }
1.171 raeburn 5659: } elsif (@secs > 0) {
5660: $singlesec = $secs[0];
1.27 raeburn 5661: }
5662: }
1.212 raeburn 5663: } else {
5664: $possrole = $role;
1.27 raeburn 5665: }
1.204 raeburn 5666: }
5667: if (!$multiple) {
1.212 raeburn 5668: if (($userdomain ne $env{'request.role.domain'}) && ($role ne '')) {
5669: my $item = "/$crsdom/$crsnum";
5670: if ($singlesec ne '') {
5671: $item .= "/$singlesec";
5672: }
5673: $item .= '_'.$possrole;
5674: next if (&restricted_dom($context,$item,$userdomain,$username,$possrole,$startdate,$enddate,
5675: $crsdom,$crsnum,$singlesec,$credits,\%process_by,\%instdoms,
1.213 raeburn 5676: \%got_role_approvals,\%got_instdoms,\%reject,\%pending,\%notifydc,
5677: \%status,\%unauthorized,\%currqueued));
1.212 raeburn 5678: }
1.204 raeburn 5679: ($userresult,$authresult,$roleresult,$idresult) =
5680: &modifyuserrole($context,$setting,
5681: $changeauth,$cid,$userdomain,$username,
5682: $id,$amode,$password,$fname,
5683: $mname,$lname,$gen,$singlesec,
5684: $env{'form.forceid'},$desiredhost,
5685: $email,$role,$enddate,$startdate,
1.220 raeburn 5686: $checkid,$inststatus,\%emptyok);
1.27 raeburn 5687: }
1.171 raeburn 5688: }
5689: if ($multiple) {
5690: foreach my $sec (sort(keys(%userres))) {
5691: $flushc =
1.27 raeburn 5692: &user_change_result($r,$userres{$sec},$authres{$sec},
5693: $roleres{$sec},$idres{$sec},\%counts,$flushc,
1.57 raeburn 5694: $username,$userdomain,\%userchg);
1.27 raeburn 5695:
1.1 raeburn 5696: }
5697: } else {
1.171 raeburn 5698: $flushc =
5699: &user_change_result($r,$userresult,$authresult,
5700: $roleresult,$idresult,\%counts,$flushc,
5701: $username,$userdomain,\%userchg);
1.1 raeburn 5702: }
5703: }
1.172 raeburn 5704: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last user');
1.171 raeburn 5705: } # end of loop
1.172 raeburn 5706: $r->print('</ul>');
1.171 raeburn 5707: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.217 raeburn 5708: if (($context eq 'domain') && ($setting eq 'course')) {
5709: unless ($oldcrsuserdoms) {
5710: if (exists($env{'course.'.$cid.'.internal.userdomains'})) {
5711: delete($env{'course.'.$cid.'.internal.userdomains'});
5712: }
5713: }
5714: }
1.171 raeburn 5715: }
1.1 raeburn 5716: # Flush the course logs so reverse user roles immediately updated
1.126 raeburn 5717: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.29 raeburn 5718: $r->print("</p>\n<p>\n".&mt('Processed [quant,_1,user].',$counts{'user'}).
1.1 raeburn 5719: "</p>\n");
5720: if ($counts{'role'} > 0) {
5721: $r->print("<p>\n".
1.192 raeburn 5722: &mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.
5723: &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.').
5724: "</p>\n");
1.29 raeburn 5725: } else {
5726: $r->print('<p>'.&mt('No roles added').'</p>');
1.1 raeburn 5727: }
5728: if ($counts{'auth'} > 0) {
5729: $r->print("<p>\n".
5730: &mt('Authentication changed for [_1] existing users.',
5731: $counts{'auth'})."</p>\n");
5732: }
1.13 raeburn 5733: $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
1.200 raeburn 5734: $r->print(&passwdrule_alerts($domain,\%showpasswdrules));
1.213 raeburn 5735: if ((keys(%reject)) || (keys(%unauthorized))) {
5736: $r->print(&print_roles_rejected($context,\%reject,\%unauthorized));
1.212 raeburn 5737: }
1.213 raeburn 5738: if ((keys(%pending)) || (keys(%currqueued))) {
5739: $r->print(&print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.212 raeburn 5740: }
1.1 raeburn 5741: #####################################
1.29 raeburn 5742: # Display list of students to drop #
1.1 raeburn 5743: #####################################
5744: if ($env{'form.fullup'} eq 'yes') {
1.29 raeburn 5745: $r->print('<h3>'.&mt('Students to Drop')."</h3>\n");
1.1 raeburn 5746: # Get current classlist
1.30 raeburn 5747: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 5748: if (! defined($classlist)) {
1.192 raeburn 5749: $r->print('<p class="LC_info">'.
5750: &mt('There are no students with current/future access to the course.').
5751: '</p>'."\n");
1.66 raeburn 5752: } elsif (ref($classlist) eq 'HASH') {
1.1 raeburn 5753: # Remove the students we just added from the list of students.
1.30 raeburn 5754: foreach my $line (@userdata) {
5755: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 5756: unless (($entries{$fields{'username'}} eq '') ||
5757: (!defined($entries{$fields{'username'}}))) {
5758: delete($classlist->{$entries{$fields{'username'}}.
5759: ':'.$domain});
5760: }
5761: }
5762: # Print out list of dropped students.
1.30 raeburn 5763: &show_drop_list($r,$classlist,'nosort',$permission);
1.1 raeburn 5764: }
5765: }
5766: } # end of unless
1.193 raeburn 5767: return 'ok';
1.1 raeburn 5768: }
5769:
1.13 raeburn 5770: sub print_namespacing_alerts {
5771: my ($domain,$alerts,$curr_rules) = @_;
5772: my $output;
5773: if (ref($alerts) eq 'HASH') {
5774: if (keys(%{$alerts}) > 0) {
5775: if (ref($alerts->{'username'}) eq 'HASH') {
5776: foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
5777: my $count;
5778: if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
5779: $count = keys(%{$alerts->{'username'}{$dom}});
5780: }
5781: my $domdesc = &Apache::lonnet::domain($domain,'description');
5782: if (ref($curr_rules->{$dom}) eq 'HASH') {
5783: $output .= &Apache::loncommon::instrule_disallow_msg(
5784: 'username',$domdesc,$count,'upload');
5785: }
5786: $output .= &Apache::loncommon::user_rule_formats($dom,
5787: $domdesc,$curr_rules->{$dom}{'username'},
5788: 'username');
5789: }
5790: }
5791: if (ref($alerts->{'id'}) eq 'HASH') {
5792: foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
5793: my $count;
5794: if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
5795: $count = keys(%{$alerts->{'id'}{$dom}});
5796: }
5797: my $domdesc = &Apache::lonnet::domain($domain,'description');
5798: if (ref($curr_rules->{$dom}) eq 'HASH') {
5799: $output .= &Apache::loncommon::instrule_disallow_msg(
5800: 'id',$domdesc,$count,'upload');
5801: }
5802: $output .= &Apache::loncommon::user_rule_formats($dom,
5803: $domdesc,$curr_rules->{$dom}{'id'},'id');
5804: }
5805: }
5806: }
5807: }
5808: }
5809:
1.200 raeburn 5810: sub passwdrule_alerts {
5811: my ($domain,$passwdrules) = @_;
5812: my $warning;
5813: if (ref($passwdrules) eq 'HASH') {
5814: my %showrules = %{$passwdrules};
5815: if (keys(%showrules)) {
5816: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
5817: $warning = '<b>'.&mt('Password requirement(s) unmet for one or more users:').'</b><ul>';
5818: if ($showrules{'min'}) {
1.208 raeburn 5819: my $min = $passwdconf{'min'};
5820: if ($min eq '') {
5821: $min = $Apache::lonnet::passwdmin;
5822: }
5823: $warning .= '<li>'.&mt('minimum [quant,_1,character]',$min).'</li>';
1.200 raeburn 5824: }
5825: if ($showrules{'max'}) {
5826: $warning .= '<li>'.&mt('maximum [quant,_1,character]',$passwdconf{'max'}).'</li>';
5827: }
5828: if ($showrules{'uc'}) {
5829: $warning .= '<li>'.&mt('contain at least one upper case letter').'</li>';
5830: }
5831: if ($showrules{'lc'}) {
5832: $warning .= '<li>'.&mt('contain at least one lower case letter').'</li>';
5833: }
5834: if ($showrules{'num'}) {
5835: $warning .= '<li>'.&mt('contain at least one number').'</li>';
5836: }
5837: if ($showrules{'spec'}) {
5838: $warning .= '<li>'.&mt('contain at least one non-alphanumeric').'</li>';
5839: }
5840: $warning .= '</ul>';
5841: }
5842: }
5843: return $warning;
5844: }
5845:
1.1 raeburn 5846: sub user_change_result {
1.29 raeburn 5847: my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
1.57 raeburn 5848: $username,$userdomain,$userchg) = @_;
1.1 raeburn 5849: my $okresult = 0;
1.171 raeburn 5850: my @status;
1.1 raeburn 5851: if ($userresult ne 'ok') {
5852: if ($userresult =~ /^error:(.+)$/) {
5853: my $error = $1;
1.171 raeburn 5854: push(@status,
5855: &mt('[_1]: Unable to add/modify: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5856: }
5857: } else {
5858: $counts->{'user'} ++;
5859: $okresult = 1;
5860: }
5861: if ($authresult ne 'ok') {
5862: if ($authresult =~ /^error:(.+)$/) {
5863: my $error = $1;
1.171 raeburn 5864: push(@status,
5865: &mt('[_1]: Unable to modify authentication: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5866: }
5867: } else {
5868: $counts->{'auth'} ++;
5869: $okresult = 1;
5870: }
5871: if ($roleresult ne 'ok') {
5872: if ($roleresult =~ /^error:(.+)$/) {
5873: my $error = $1;
1.171 raeburn 5874: push(@status,
5875: &mt('[_1]: Unable to add role: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5876: }
5877: } else {
5878: $counts->{'role'} ++;
5879: $okresult = 1;
5880: }
5881: if ($okresult) {
5882: $flushc++;
1.57 raeburn 5883: $userchg->{$username.':'.$userdomain}=1;
1.1 raeburn 5884: if ($flushc>15) {
5885: $r->rflush;
5886: $flushc=0;
5887: }
5888: }
1.29 raeburn 5889: if ($idresult) {
1.171 raeburn 5890: push(@status,$idresult);
5891: }
5892: if (@status) {
5893: $r->print('<li>'.join('<br />',@status).'</li>');
1.29 raeburn 5894: }
1.1 raeburn 5895: return $flushc;
5896: }
5897:
5898: # ========================================================= Menu Phase Two Drop
1.17 raeburn 5899: sub print_drop_menu {
1.101 raeburn 5900: my ($r,$context,$permission,$crstype) = @_;
5901: my $heading;
5902: if ($crstype eq 'Community') {
5903: $heading = &mt("Drop Members");
5904: } else {
5905: $heading = &mt("Drop Students");
5906: }
5907: $r->print('<h3>'.$heading.'</h3>'."\n".
1.153 bisitz 5908: '<form name="studentform" method="post" action="">'."\n");
1.30 raeburn 5909: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 5910: if (! defined($classlist)) {
1.143 bisitz 5911: my $msg = '';
1.101 raeburn 5912: if ($crstype eq 'Community') {
1.143 bisitz 5913: $msg = &mt('There are no members currently enrolled.');
1.101 raeburn 5914: } else {
1.143 bisitz 5915: $msg = &mt('There are no students currently enrolled.');
1.101 raeburn 5916: }
1.143 bisitz 5917: $r->print('<p class="LC_info">'.$msg."</p>\n");
1.30 raeburn 5918: } else {
1.101 raeburn 5919: &show_drop_list($r,$classlist,'nosort',$permission,$crstype);
1.1 raeburn 5920: }
1.162 bisitz 5921: $r->print('</form>');
1.1 raeburn 5922: return;
5923: }
5924:
5925: # ================================================================== Phase four
5926:
1.11 raeburn 5927: sub update_user_list {
1.118 raeburn 5928: my ($r,$context,$setting,$choice,$crstype) = @_;
1.11 raeburn 5929: my $now = time;
1.1 raeburn 5930: my $count=0;
1.101 raeburn 5931: if ($context eq 'course') {
5932: $crstype = &Apache::loncommon::course_type();
5933: }
1.212 raeburn 5934: my (@changelist,%got_role_approvals,%got_instdoms,%process_by,%instdoms,
1.213 raeburn 5935: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
1.29 raeburn 5936: if ($choice eq 'drop') {
5937: @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
5938: } else {
1.11 raeburn 5939: @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
5940: }
5941: my %result_text = ( ok => { 'revoke' => 'Revoked',
5942: 'delete' => 'Deleted',
5943: 'reenable' => 'Re-enabled',
1.17 raeburn 5944: 'activate' => 'Activated',
5945: 'chgdates' => 'Changed Access Dates for',
1.118 raeburn 5946: 'chgsec' => 'Changed section(s) for',
1.17 raeburn 5947: 'drop' => 'Dropped',
1.11 raeburn 5948: },
5949: error => {'revoke' => 'revoking',
5950: 'delete' => 'deleting',
5951: 'reenable' => 're-enabling',
5952: 'activate' => 'activating',
1.17 raeburn 5953: 'chgdates' => 'changing access dates for',
5954: 'chgsec' => 'changing section for',
5955: 'drop' => 'dropping',
1.11 raeburn 5956: },
5957: );
5958: my ($startdate,$enddate);
5959: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
5960: ($startdate,$enddate) = &get_dates_from_form();
5961: }
5962: foreach my $item (@changelist) {
1.118 raeburn 5963: my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,
5964: @sections,$scopestem,$singlesec,$showsecs,$warn_singlesec,
1.212 raeburn 5965: $nothingtodo,$keepnosection,$credits,$instsec,$cdom,$cnum);
1.17 raeburn 5966: if ($choice eq 'drop') {
5967: ($uname,$udom,$sec) = split(/:/,$item,-1);
5968: $role = 'st';
5969: $cid = $env{'request.course.id'};
5970: $scopestem = '/'.$cid;
5971: $scopestem =~s/\_/\//g;
5972: if ($sec eq '') {
5973: $scope = $scopestem;
5974: } else {
5975: $scope = $scopestem.'/'.$sec;
5976: }
5977: } elsif ($context eq 'course') {
1.174 raeburn 5978: ($uname,$udom,$role,$sec,$type,$locktype,$credits,$instsec) =
5979: split(/\:/,$item,8);
5980: $instsec = &unescape($instsec);
1.11 raeburn 5981: $cid = $env{'request.course.id'};
1.212 raeburn 5982: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5983: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.11 raeburn 5984: $scopestem = '/'.$cid;
5985: $scopestem =~s/\_/\//g;
5986: if ($sec eq '') {
5987: $scope = $scopestem;
5988: } else {
5989: $scope = $scopestem.'/'.$sec;
5990: }
1.13 raeburn 5991: } elsif ($context eq 'author') {
1.11 raeburn 5992: ($uname,$udom,$role) = split(/\:/,$item,-1);
5993: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
1.212 raeburn 5994: $cdom = $env{'user.domain'};
5995: $cnum = $env{'user.name'};
1.11 raeburn 5996: } elsif ($context eq 'domain') {
5997: if ($setting eq 'domain') {
5998: ($role,$uname,$udom) = split(/\:/,$item,-1);
5999: $scope = '/'.$env{'request.role.domain'}.'/';
1.212 raeburn 6000: $cdom = $env{'request.role.domain'};
1.13 raeburn 6001: } elsif ($setting eq 'author') {
1.11 raeburn 6002: ($uname,$udom,$role,$scope) = split(/\:/,$item);
1.212 raeburn 6003: (undef,$cdom,$cnum) = split(/\//,$scope);
1.11 raeburn 6004: } elsif ($setting eq 'course') {
1.174 raeburn 6005: ($uname,$udom,$role,$cid,$sec,$type,$locktype,$credits,$instsec) =
6006: split(/\:/,$item,9);
1.212 raeburn 6007: ($cdom,$cnum) = split('_',$cid);
1.174 raeburn 6008: $instsec = &unescape($instsec);
1.11 raeburn 6009: $scope = '/'.$cid;
6010: $scope =~s/\_/\//g;
6011: if ($sec ne '') {
6012: $scope .= '/'.$sec;
6013: }
6014: }
6015: }
1.101 raeburn 6016: my $plrole = &Apache::lonnet::plaintext($role,$crstype);
1.11 raeburn 6017: my $start = $env{'form.'.$item.'_start'};
6018: my $end = $env{'form.'.$item.'_end'};
1.17 raeburn 6019: if ($choice eq 'drop') {
6020: # drop students
6021: $end = $now;
6022: $type = 'manual';
6023: $result =
1.52 raeburn 6024: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.17 raeburn 6025: } elsif ($choice eq 'revoke') {
6026: # revoke or delete user role
1.11 raeburn 6027: $end = $now;
6028: if ($role eq 'st') {
6029: $result =
1.174 raeburn 6030: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.11 raeburn 6031: } else {
6032: $result =
1.52 raeburn 6033: &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
6034: '','',$context);
1.11 raeburn 6035: }
6036: } elsif ($choice eq 'delete') {
6037: if ($role eq 'st') {
1.174 raeburn 6038: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.29 raeburn 6039: }
6040: $result =
6041: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
1.52 raeburn 6042: $start,1,'',$context);
1.11 raeburn 6043: } else {
6044: #reenable, activate, change access dates or change section
6045: if ($choice ne 'chgsec') {
6046: $start = $startdate;
6047: $end = $enddate;
6048: }
1.212 raeburn 6049: my $id = $scope.'_'.$role;
1.11 raeburn 6050: if ($choice eq 'reenable') {
1.212 raeburn 6051: next if (&restricted_dom($context,$id,$udom,$uname,$role,$now,$end,$cdom,$cnum,
6052: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 6053: \%got_instdoms,\%reject,\%pending,\%notifydc,
6054: \%status,\%unauthorized,\%currqueued));
1.11 raeburn 6055: if ($role eq 'st') {
1.174 raeburn 6056: $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 6057: } else {
6058: $result =
6059: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 6060: $now,'','',$context);
1.11 raeburn 6061: }
6062: } elsif ($choice eq 'activate') {
1.212 raeburn 6063: next if (&restricted_dom($context,$id,$udom,$uname,$role,$now,$end,$cdom,$cnum,
6064: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 6065: \%got_instdoms,\%reject,\%pending,\%notifydc,
6066: \%status,\%unauthorized,\%currqueued));
1.11 raeburn 6067: if ($role eq 'st') {
1.174 raeburn 6068: $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 6069: } else {
6070: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 6071: $now,'','',$context);
1.11 raeburn 6072: }
6073: } elsif ($choice eq 'chgdates') {
1.212 raeburn 6074: next if (&restricted_dom($context,$id,$udom,$uname,$role,$start,$end,$cdom,$cnum,
6075: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 6076: \%got_instdoms,\%reject,\%pending,\%notifydc,
6077: \%status,\%unauthorized,\%currqueued));
1.11 raeburn 6078: if ($role eq 'st') {
1.174 raeburn 6079: $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 6080: } else {
6081: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 6082: $start,'','',$context);
1.11 raeburn 6083: }
6084: } elsif ($choice eq 'chgsec') {
6085: my (@newsecs,$revresult,$nochg,@retained);
1.103 raeburn 6086: if (($role ne 'cc') && ($role ne 'co')) {
1.117 raeburn 6087: my @secs = sort(split(/,/,$env{'form.newsecs'}));
6088: if (@secs) {
6089: my %curr_groups = &Apache::longroup::coursegroups();
6090: foreach my $sec (@secs) {
6091: next if (($sec =~ /\W/) || ($sec eq 'none') ||
6092: (exists($curr_groups{$sec})));
6093: push(@newsecs,$sec);
6094: }
6095: }
1.11 raeburn 6096: }
6097: # remove existing section if not to be retained.
1.118 raeburn 6098: if (!$env{'form.retainsec'} || ($role eq 'st')) {
1.11 raeburn 6099: if ($sec eq '') {
6100: if (@newsecs == 0) {
1.118 raeburn 6101: $result = 'ok';
1.11 raeburn 6102: $nochg = 1;
1.118 raeburn 6103: $nothingtodo = 1;
1.40 raeburn 6104: } else {
6105: $revresult =
6106: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 6107: $scope,$role,
6108: '','',$context);
1.40 raeburn 6109: }
1.11 raeburn 6110: } else {
1.28 raeburn 6111: if (@newsecs > 0) {
6112: if (grep(/^\Q$sec\E$/,@newsecs)) {
6113: push(@retained,$sec);
6114: } else {
6115: $revresult =
6116: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 6117: $scope,$role,
6118: '','',$context);
1.28 raeburn 6119: }
6120: } else {
1.11 raeburn 6121: $revresult =
1.28 raeburn 6122: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 6123: $scope,$role,
6124: '','',$context);
1.11 raeburn 6125: }
6126: }
6127: } else {
1.28 raeburn 6128: if ($sec eq '') {
6129: $nochg = 1;
1.118 raeburn 6130: $keepnosection = 1;
6131: } else {
1.28 raeburn 6132: push(@retained,$sec);
6133: }
1.11 raeburn 6134: }
6135: # add new sections
1.118 raeburn 6136: my (@diffs,@shownew);
6137: if (@retained) {
6138: @diffs = &Apache::loncommon::compare_arrays(\@retained,\@newsecs);
6139: } else {
6140: @diffs = @newsecs;
6141: }
1.11 raeburn 6142: if (@newsecs == 0) {
1.118 raeburn 6143: if ($nochg) {
6144: $result = 'ok';
6145: $nothingtodo = 1;
6146: } else {
1.28 raeburn 6147: if ($role eq 'st') {
6148: $result =
1.174 raeburn 6149: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.28 raeburn 6150: } else {
6151: my $newscope = $scopestem;
1.52 raeburn 6152: $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
1.11 raeburn 6153: }
6154: }
1.118 raeburn 6155: $showsecs = &mt('No section');
6156: } elsif (@diffs == 0) {
6157: $result = 'ok';
6158: $nothingtodo = 1;
1.11 raeburn 6159: } else {
1.118 raeburn 6160: foreach my $newsec (@newsecs) {
1.11 raeburn 6161: if (!grep(/^\Q$newsec\E$/,@retained)) {
6162: if ($role eq 'st') {
1.174 raeburn 6163: $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 6164: if (@newsecs > 1) {
6165: my $showsingle;
6166: if ($newsec eq '') {
6167: $showsingle = &mt('No section');
6168: } else {
6169: $showsingle = $newsec;
6170: }
6171: if ($crstype eq 'Community') {
6172: $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>');
6173: } else {
6174: $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>');
6175: }
6176: $showsecs = $showsingle;
6177: last;
6178: } else {
6179: if ($newsec eq '') {
6180: $showsecs = &mt('No section');
6181: } else {
6182: $showsecs = $newsec;
6183: }
6184: }
1.11 raeburn 6185: } else {
6186: my $newscope = $scopestem;
6187: if ($newsec ne '') {
6188: $newscope .= '/'.$newsec;
1.118 raeburn 6189: push(@shownew,$newsec);
1.11 raeburn 6190: }
6191: $result = &Apache::lonnet::assignrole($udom,$uname,
6192: $newscope,$role,$end,$start);
1.118 raeburn 6193:
1.11 raeburn 6194: }
6195: }
6196: }
6197: }
1.118 raeburn 6198: unless ($role eq 'st') {
6199: unless ($showsecs) {
6200: my @tolist = sort(@shownew,@retained);
6201: if ($keepnosection) {
6202: push(@tolist,&mt('No section'));
6203: }
6204: $showsecs = join(', ',@tolist);
6205: }
6206: }
1.11 raeburn 6207: }
6208: }
1.17 raeburn 6209: my $extent = $scope;
6210: if ($choice eq 'drop' || $context eq 'course') {
6211: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
6212: if ($cdesc) {
6213: $extent = $cdesc;
6214: }
6215: }
1.1 raeburn 6216: if ($result eq 'ok' || $result eq 'ok:') {
1.118 raeburn 6217: my $dates;
6218: if (($choice eq 'chgsec') || ($choice eq 'chgdates')) {
6219: $dates = &dates_feedback($start,$end,$now);
6220: }
6221: if ($choice eq 'chgsec') {
6222: if ($nothingtodo) {
6223: $r->print(&mt("Section assignment for role of '[_1]' in [_2] for '[_3]' unchanged.",$plrole,$extent,'<i>'.
6224: &Apache::loncommon::plainname($uname,$udom).
6225: '</i>').' ');
6226: if ($sec eq '') {
6227: $r->print(&mt('[_1]No section[_2] - [_3]','<b>','</b>',$dates));
6228: } else {
6229: $r->print(&mt('Section(s): [_1] - [_2]',
6230: '<b>'.$showsecs.'</b>',$dates));
6231: }
6232: $r->print('<br />');
6233: } else {
6234: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' to [_4] - [_5]",$plrole,$extent,
6235: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
6236: '<b>'.$showsecs.'</b>',$dates).'<br />');
6237: $count ++;
6238: }
6239: if ($warn_singlesec) {
6240: $r->print('<div class="LC_warning">'.$warn_singlesec.'</div>');
6241: }
6242: } elsif ($choice eq 'chgdates') {
6243: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' - [_4]",$plrole,$extent,
1.121 raeburn 6244: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
1.118 raeburn 6245: $dates).'<br />');
6246: $count ++;
6247: } else {
6248: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]'.",$plrole,$extent,
1.121 raeburn 6249: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>').
1.118 raeburn 6250: '<br />');
6251: $count ++;
6252: }
1.1 raeburn 6253: } else {
6254: $r->print(
1.118 raeburn 6255: &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for '[_3]': [_4].",
6256: $plrole,$extent,
1.121 raeburn 6257: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
1.118 raeburn 6258: $result).'<br />');
1.11 raeburn 6259: }
6260: }
1.32 raeburn 6261: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
1.33 raeburn 6262: if ($choice eq 'drop') {
6263: $r->print('<input type="hidden" name="action" value="listusers" />'."\n".
6264: '<input type="hidden" name="Status" value="Active" />'."\n".
6265: '<input type="hidden" name="showrole" value="st" />'."\n");
6266: } else {
6267: foreach my $item ('action','sortby','roletype','showrole','Status','secfilter','grpfilter') {
6268: if ($env{'form.'.$item} ne '') {
6269: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.
6270: '" />'."\n");
6271: }
1.32 raeburn 6272: }
6273: }
1.144 bisitz 6274: $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} [quant,_1,user role,user roles,no user roles].",$count).'</b></p>');
1.11 raeburn 6275: if ($count > 0) {
1.17 raeburn 6276: if ($choice eq 'revoke' || $choice eq 'drop') {
1.74 bisitz 6277: $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>');
1.11 raeburn 6278: }
6279: # Flush the course logs so reverse user roles immediately updated
1.126 raeburn 6280: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.11 raeburn 6281: }
6282: if ($env{'form.makedatesdefault'}) {
6283: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
1.101 raeburn 6284: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
1.1 raeburn 6285: }
6286: }
1.213 raeburn 6287: if ((keys(%reject)) || (keys(%unauthorized))) {
6288: $r->print(&print_roles_rejected($context,\%reject,\%unauthorized));
1.212 raeburn 6289: }
1.213 raeburn 6290: if ((keys(%pending)) || (keys(%currqueued))) {
6291: $r->print(&print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.212 raeburn 6292: }
1.33 raeburn 6293: my $linktext = &mt('Display User Lists');
6294: if ($choice eq 'drop') {
6295: $linktext = &mt('Display current class roster');
6296: }
1.144 bisitz 6297: $r->print(
6298: &Apache::lonhtmlcommon::actionbox(
6299: ['<a href="javascript:document.studentform.submit()">'.$linktext.'</a>'])
6300: .'</form>'."\n");
1.1 raeburn 6301: }
6302:
1.118 raeburn 6303: sub dates_feedback {
6304: my ($start,$end,$now) = @_;
6305: my $dates;
6306: if ($start < $now) {
6307: if ($end == 0) {
1.147 bisitz 6308: $dates = &mt('role(s) active now; no end date');
1.118 raeburn 6309: } elsif ($end > $now) {
6310: $dates = &mt('role(s) active now; ends [_1].',&Apache::lonlocal::locallocaltime($end));
6311: } else {
6312: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
6313: }
6314: } else {
6315: if ($end == 0 || $end > $now) {
6316: $dates = &mt('future role(s); starts: [_1].',&Apache::lonlocal::locallocaltime($start));
6317: } else {
6318: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
6319: }
6320: }
6321: return $dates;
6322: }
6323:
1.8 raeburn 6324: sub classlist_drop {
1.29 raeburn 6325: my ($scope,$uname,$udom,$now) = @_;
1.8 raeburn 6326: my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
1.29 raeburn 6327: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.8 raeburn 6328: if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
1.63 raeburn 6329: my %user;
6330: my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
1.8 raeburn 6331: return &mt('Drop from classlist: [_1]',
6332: '<b>'.$result.'</b>').'<br />';
6333: }
6334: }
6335: }
6336:
6337: sub active_student_roles {
6338: my ($cnum,$cdom,$uname,$udom) = @_;
6339: my %roles =
6340: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
6341: ['future','active'],['st']);
6342: return exists($roles{"$cnum:$cdom:st"});
6343: }
6344:
1.1 raeburn 6345: sub section_check_js {
1.8 raeburn 6346: my $groupslist= &get_groupslist();
1.170 damieng 6347: my %js_lt = &Apache::lonlocal::texthash(
6348: mayn => 'may not be used as the name for a section, as it is a reserved word.',
6349: plch => 'Please choose a different section name.',
6350: mnot => 'may not be used as a section name, as it is the name of a course group.',
6351: secn => 'Section names and group names must be distinct. Please choose a different section name.',
6352: );
6353: &js_escape(\%js_lt);
1.1 raeburn 6354: return <<"END";
6355: function validate(caller) {
1.9 raeburn 6356: var groups = new Array($groupslist);
1.1 raeburn 6357: var secname = caller.value;
6358: if ((secname == 'all') || (secname == 'none')) {
1.170 damieng 6359: alert("'"+secname+"' $js_lt{'mayn'}\\n$js_lt{'plch'}");
1.1 raeburn 6360: return 'error';
6361: }
6362: if (secname != '') {
6363: for (var k=0; k<groups.length; k++) {
6364: if (secname == groups[k]) {
1.170 damieng 6365: alert("'"+secname+"' $js_lt{'mnot'}\\n$js_lt{'secn'}");
1.1 raeburn 6366: return 'error';
6367: }
6368: }
6369: }
6370: return 'ok';
6371: }
6372: END
6373: }
6374:
6375: sub set_login {
1.194 raeburn 6376: my ($dom,$authformkrb,$authformint,$authformloc,$authformlti) = @_;
1.1 raeburn 6377: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6378: my $response;
6379: my ($authnum,%can_assign) =
6380: &Apache::loncommon::get_assignable_auth($dom);
6381: if ($authnum) {
6382: $response = &Apache::loncommon::start_data_table();
6383: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
6384: $response .= &Apache::loncommon::start_data_table_row().
6385: '<td>'.$authformkrb.'</td>'.
6386: &Apache::loncommon::end_data_table_row()."\n";
6387: }
6388: if ($can_assign{'int'}) {
6389: $response .= &Apache::loncommon::start_data_table_row().
6390: '<td>'.$authformint.'</td>'.
6391: &Apache::loncommon::end_data_table_row()."\n"
6392: }
6393: if ($can_assign{'loc'}) {
6394: $response .= &Apache::loncommon::start_data_table_row().
6395: '<td>'.$authformloc.'</td>'.
6396: &Apache::loncommon::end_data_table_row()."\n";
6397: }
1.194 raeburn 6398: if ($can_assign{'lti'}) {
6399: $response .= &Apache::loncommon::start_data_table_row().
6400: '<td>'.$authformlti.'</td>'.
6401: &Apache::loncommon::end_data_table_row()."\n";
6402: }
1.1 raeburn 6403: $response .= &Apache::loncommon::end_data_table();
6404: }
6405: return $response;
6406: }
6407:
1.8 raeburn 6408: sub course_sections {
1.178 raeburn 6409: my ($sections_count,$role,$current_sec,$disabled) = @_;
1.8 raeburn 6410: my $output = '';
1.169 raeburn 6411: my @sections = (sort {$a <=> $b} keys(%{$sections_count}));
1.29 raeburn 6412: my $numsec = scalar(@sections);
1.92 bisitz 6413: my $is_selected = ' selected="selected"';
1.29 raeburn 6414: if ($numsec <= 1) {
1.178 raeburn 6415: $output = '<select name="currsec_'.$role.'"'.$disabled.'>'."\n".
1.51 raeburn 6416: ' <option value="">'.&mt('Select').'</option>'."\n";
6417: if ($current_sec eq 'none') {
6418: $output .=
6419: ' <option value=""'.$is_selected.'>'.&mt('No section').'</option>'."\n";
6420: } else {
6421: $output .=
1.29 raeburn 6422: ' <option value="">'.&mt('No section').'</option>'."\n";
1.51 raeburn 6423: }
1.29 raeburn 6424: if ($numsec == 1) {
1.51 raeburn 6425: if ($current_sec eq $sections[0]) {
6426: $output .=
6427: ' <option value="'.$sections[0].'"'.$is_selected.'>'.$sections[0].'</option>'."\n";
6428: } else {
6429: $output .=
1.8 raeburn 6430: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
1.51 raeburn 6431: }
1.29 raeburn 6432: }
1.8 raeburn 6433: } else {
6434: $output = '<select name="currsec_'.$role.'" ';
6435: my $multiple = 4;
6436: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
1.29 raeburn 6437: if ($role eq 'st') {
1.178 raeburn 6438: $output .= $disabled.'>'."\n".
1.51 raeburn 6439: ' <option value="">'.&mt('Select').'</option>'."\n";
6440: if ($current_sec eq 'none') {
6441: $output .=
6442: ' <option value=""'.$is_selected.'>'.&mt('No section')."</option>\n";
6443: } else {
6444: $output .=
1.29 raeburn 6445: ' <option value="">'.&mt('No section')."</option>\n";
1.51 raeburn 6446: }
1.29 raeburn 6447: } else {
1.178 raeburn 6448: $output .= 'multiple="multiple" size="'.$multiple.'"'.$disabled.'>'."\n";
1.29 raeburn 6449: }
1.8 raeburn 6450: foreach my $sec (@sections) {
1.51 raeburn 6451: if ($current_sec eq $sec) {
6452: $output .= '<option value="'.$sec.'"'.$is_selected.'>'.$sec."</option>\n";
6453: } else {
6454: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
6455: }
1.8 raeburn 6456: }
6457: }
6458: $output .= '</select>';
6459: return $output;
6460: }
6461:
6462: sub get_groupslist {
6463: my $groupslist;
6464: my %curr_groups = &Apache::longroup::coursegroups();
6465: if (%curr_groups) {
6466: $groupslist = join('","',sort(keys(%curr_groups)));
6467: $groupslist = '"'.$groupslist.'"';
6468: }
1.11 raeburn 6469: return $groupslist;
1.8 raeburn 6470: }
6471:
6472: sub setsections_javascript {
1.150 raeburn 6473: my ($formname,$groupslist,$mode,$checkauth,$crstype,$showcredits) = @_;
1.28 raeburn 6474: my ($checkincluded,$finish,$rolecode,$setsection_js);
6475: if ($mode eq 'upload') {
6476: $checkincluded = 'formname.name == "'.$formname.'"';
6477: $finish = "return 'ok';";
6478: $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
6479: } elsif ($formname eq 'cu') {
1.150 raeburn 6480: if (($crstype eq 'Course') && ($showcredits)) {
6481: $checkincluded = "((role == 'st') && (formname.elements[i-2].checked == true)) || ((role != 'st') && (formname.elements[i-1].checked == true))";
6482: } else {
6483: $checkincluded = 'formname.elements[i-1].checked == true';
6484: }
1.37 raeburn 6485: if ($checkauth) {
6486: $finish = "var authcheck = auth_check();\n".
6487: " if (authcheck == 'ok') {\n".
6488: " formname.submit();\n".
6489: " }\n";
6490: } else {
6491: $finish = 'formname.submit()';
6492: }
1.28 raeburn 6493: $rolecode = "var match = str.split('_');
6494: var role = match[3];\n";
1.165 raeburn 6495: } elsif (($formname eq 'enrollstudent') || ($formname eq 'selfenroll')) {
1.28 raeburn 6496: $checkincluded = 'formname.name == "'.$formname.'"';
1.37 raeburn 6497: if ($checkauth) {
6498: $finish = "var authcheck = auth_check();\n".
6499: " if (authcheck == 'ok') {\n".
6500: " formname.submit();\n".
6501: " }\n";
6502: } else {
6503: $finish = 'formname.submit()';
6504: }
1.28 raeburn 6505: $rolecode = "var match = str.split('_');
6506: var role = match[1];\n";
1.8 raeburn 6507: } else {
1.28 raeburn 6508: $checkincluded = 'formname.name == "'.$formname.'"';
1.8 raeburn 6509: $finish = "seccheck = 'ok';";
1.28 raeburn 6510: $rolecode = "var match = str.split('_');
6511: var role = match[1];\n";
1.11 raeburn 6512: $setsection_js = "var seccheck = 'alert';";
1.8 raeburn 6513: }
6514: my %alerts = &Apache::lonlocal::texthash(
6515: secd => 'Section designations do not apply to Course Coordinator roles.',
1.103 raeburn 6516: sedn => 'Section designations do not apply to Coordinator roles.',
1.8 raeburn 6517: accr => 'A course coordinator role will be added with access to all sections.',
1.103 raeburn 6518: acor => 'A coordinator role will be added with access to all sections',
1.8 raeburn 6519: inea => 'In each course, each user may only have one student role at a time.',
1.125 raeburn 6520: inco => 'In each community, each user may only have one member role at a time.',
1.145 raeburn 6521: youh => 'You had selected',
1.8 raeburn 6522: secs => 'sections.',
6523: plmo => 'Please modify your selections so they include no more than one section.',
6524: mayn => 'may not be used as the name for a section, as it is a reserved word.',
6525: plch => 'Please choose a different section name.',
6526: mnot => 'may not be used as a section name, as it is the name of a course group.',
6527: secn => 'Section names and group names must be distinct. Please choose a different section name.',
1.113 raeburn 6528: nonw => 'Section names may only contain letters or numbers.',
1.170 damieng 6529: );
6530: &js_escape(\%alerts);
1.8 raeburn 6531: $setsection_js .= <<"ENDSECCODE";
6532:
1.103 raeburn 6533: function setSections(formname,crstype) {
1.8 raeburn 6534: var re1 = /^currsec_/;
1.113 raeburn 6535: var re2 =/\\W/;
1.115 raeburn 6536: var trimleading = /^\\s+/;
6537: var trimtrailing = /\\s+\$/;
1.8 raeburn 6538: var groups = new Array($groupslist);
6539: for (var i=0;i<formname.elements.length;i++) {
6540: var str = formname.elements[i].name;
1.168 raeburn 6541: if (typeof(str) === "undefined") {
6542: continue;
6543: }
1.8 raeburn 6544: var checkcurr = str.match(re1);
6545: if (checkcurr != null) {
1.115 raeburn 6546: var num = i;
1.150 raeburn 6547: $rolecode
1.8 raeburn 6548: if ($checkincluded) {
1.103 raeburn 6549: if (role == 'cc' || role == 'co') {
6550: if (role == 'cc') {
6551: alert("$alerts{'secd'}\\n$alerts{'accr'}");
6552: } else {
6553: alert("$alerts{'sedn'}\\n$alerts{'acor'}");
6554: }
6555: } else {
1.8 raeburn 6556: var sections = '';
6557: var numsec = 0;
1.115 raeburn 6558: var fromexisting = new Array();
6559: for (var j=0; j<formname.elements[num].length; j++) {
6560: if (formname.elements[num].options[j].selected == true ) {
6561: var addsec = formname.elements[num].options[j].value;
1.119 raeburn 6562: if ((addsec != "") && (addsec != null)) {
1.115 raeburn 6563: fromexisting.push(addsec);
1.8 raeburn 6564: if (numsec == 0) {
1.115 raeburn 6565: sections = addsec;
6566: } else {
6567: sections = sections + "," + addsec;
1.8 raeburn 6568: }
1.115 raeburn 6569: numsec ++;
1.8 raeburn 6570: }
6571: }
6572: }
1.115 raeburn 6573: var newsecs = formname.elements[num+1].value;
1.113 raeburn 6574: var validsecs = new Array();
1.115 raeburn 6575: var validsecstr = '';
1.113 raeburn 6576: var badsecs = new Array();
1.8 raeburn 6577: if (newsecs != null && newsecs != "") {
1.115 raeburn 6578: var numsplit;
6579: if (newsecs.indexOf(',') == -1) {
6580: numsplit = new Array(newsecs);
6581: } else {
6582: numsplit = newsecs.split(/,/g);
6583: }
1.117 raeburn 6584: for (var m=0; m<numsplit.length; m++) {
6585: var newsec = numsplit[m];
1.115 raeburn 6586: newsec = newsec.replace(trimleading,'');
6587: newsec = newsec.replace(trimtrailing,'');
6588: if (re2.test(newsec) == true) {
6589: badsecs.push(newsec);
1.113 raeburn 6590: } else {
1.115 raeburn 6591: if (newsec != '') {
6592: var isnew = 1;
6593: if (fromexisting != null) {
1.117 raeburn 6594: for (var n=0; n<fromexisting.length; n++) {
6595: if (newsec == fromexisting[n]) {
1.115 raeburn 6596: isnew = 0;
6597: }
6598: }
6599: }
6600: if (isnew == 1) {
6601: validsecs.push(newsec);
6602: }
6603: }
1.113 raeburn 6604: }
6605: }
6606: if (badsecs.length > 0) {
6607: alert("$alerts{'nonw'}\\n$alerts{'plch'}");
6608: return;
6609: }
6610: numsec = numsec + validsecs.length;
1.8 raeburn 6611: }
6612: if ((role == 'st') && (numsec > 1)) {
1.103 raeburn 6613: if (crstype == 'Community') {
6614: alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
6615: } else {
6616: alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
6617: }
1.8 raeburn 6618: return;
1.115 raeburn 6619: } else {
6620: if (validsecs != null) {
6621: for (var j=0; j<validsecs.length; j++) {
6622: if (validsecstr == '' || validsecstr == null) {
6623: validsecstr = validsecs[j];
6624: } else {
6625: validsecstr += ','+validsecs[j];
6626: }
6627: if ((validsecs[j] == 'all') ||
6628: (validsecs[j] == 'none')) {
6629: alert("'"+validsecs[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
1.8 raeburn 6630: return;
6631: }
6632: for (var k=0; k<groups.length; k++) {
1.115 raeburn 6633: if (validsecs[j] == groups[k]) {
6634: alert("'"+validsecs[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
1.8 raeburn 6635: return;
6636: }
6637: }
6638: }
6639: }
6640: }
1.115 raeburn 6641: if ((validsecstr != '') && (validsecstr != null)) {
1.117 raeburn 6642: if ((sections == '') || (sections == null)) {
6643: sections = validsecstr;
6644: } else {
1.115 raeburn 6645: sections = sections + "," + validsecstr;
6646: }
6647: }
6648: formname.elements[num+2].value = sections;
1.8 raeburn 6649: }
6650: }
6651: }
6652: }
6653: $finish
6654: }
6655: ENDSECCODE
1.11 raeburn 6656: return $setsection_js;
1.8 raeburn 6657: }
6658:
1.15 raeburn 6659: sub can_create_user {
6660: my ($dom,$context,$usertype) = @_;
6661: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6662: my $cancreate = 1;
1.28 raeburn 6663: if (&Apache::lonnet::allowed('mau',$dom)) {
6664: return $cancreate;
1.178 raeburn 6665: } elsif ($context eq 'domain') {
6666: $cancreate = 0;
6667: return $cancreate;
1.28 raeburn 6668: }
1.15 raeburn 6669: if (ref($domconf{'usercreation'}) eq 'HASH') {
6670: if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
1.100 raeburn 6671: if ($context eq 'course' || $context eq 'author' || $context eq 'requestcrs') {
1.15 raeburn 6672: my $creation = $domconf{'usercreation'}{'cancreate'}{$context};
6673: if ($creation eq 'none') {
6674: $cancreate = 0;
6675: } elsif ($creation ne 'any') {
6676: if (defined($usertype)) {
6677: if ($creation ne $usertype) {
6678: $cancreate = 0;
6679: }
6680: }
6681: }
6682: }
6683: }
6684: }
6685: return $cancreate;
6686: }
6687:
1.20 raeburn 6688: sub can_modify_userinfo {
6689: my ($context,$dom,$fields,$userroles) = @_;
6690: my %domconfig =
6691: &Apache::lonnet::get_dom('configuration',['usermodification'],
6692: $dom);
1.222 ! raeburn 6693: if (($context eq 'author') &&
! 6694: ($env{'request.role'} =~ m{^(ca|aa)\./$match_domain/$match_username$})) {
! 6695: $context = 'coauthor';
! 6696: }
1.20 raeburn 6697: my %canmodify;
6698: if (ref($fields) eq 'ARRAY') {
6699: foreach my $field (@{$fields}) {
6700: $canmodify{$field} = 0;
6701: if (&Apache::lonnet::allowed('mau',$dom)) {
6702: $canmodify{$field} = 1;
6703: } else {
6704: if (ref($domconfig{'usermodification'}) eq 'HASH') {
6705: if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
6706: if (ref($userroles) eq 'ARRAY') {
6707: foreach my $role (@{$userroles}) {
6708: my $testrole;
1.60 raeburn 6709: if ($context eq 'selfcreate') {
6710: $testrole = $role;
1.20 raeburn 6711: } else {
1.60 raeburn 6712: if ($role =~ /^cr\//) {
6713: $testrole = 'cr';
6714: } else {
6715: $testrole = $role;
6716: }
1.20 raeburn 6717: }
6718: if (ref($domconfig{'usermodification'}{$context}{$testrole}) eq 'HASH') {
6719: if ($domconfig{'usermodification'}{$context}{$testrole}{$field}) {
6720: $canmodify{$field} = 1;
6721: last;
6722: }
6723: }
6724: }
6725: } else {
6726: foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
6727: if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
6728: if ($domconfig{'usermodification'}{$context}{$key}{$field}) {
6729: $canmodify{$field} = 1;
6730: last;
6731: }
6732: }
6733: }
6734: }
6735: }
6736: } elsif ($context eq 'course') {
6737: if (ref($userroles) eq 'ARRAY') {
6738: if (grep(/^st$/,@{$userroles})) {
6739: $canmodify{$field} = 1;
6740: }
6741: } else {
6742: $canmodify{$field} = 1;
6743: }
6744: }
6745: }
6746: }
6747: }
6748: return %canmodify;
6749: }
6750:
1.195 raeburn 6751: sub can_change_internalpass {
6752: my ($uname,$udom,$crstype,$permission) = @_;
6753: my $canchange;
6754: if (&Apache::lonnet::allowed('mau',$udom)) {
6755: $canchange = 1;
6756: } elsif ((ref($permission) eq 'HASH') && ($permission->{'mip'}) &&
6757: ($udom eq $env{'request.role.domain'})) {
6758: unless ($env{'course.'.$env{'request.course.id'}.'.internal.nopasswdchg'}) {
6759: my ($cnum,$cdom) = &get_course_identity();
6760: if ((&Apache::lonnet::is_course_owner($cdom,$cnum)) && ($udom eq $env{'user.domain'})) {
1.199 raeburn 6761: my @userstatuses = ('default');
6762: my %userenv = &Apache::lonnet::userenvironment($udom,$uname,'inststatus');
6763: if ($userenv{'inststatus'} ne '') {
6764: @userstatuses = split(/:/,$userenv{'inststatus'});
6765: }
6766: my $noupdate = 1;
6767: my %passwdconf = &Apache::lonnet::get_passwdconf($cdom);
6768: if (ref($passwdconf{'crsownerchg'}) eq 'HASH') {
6769: if (ref($passwdconf{'crsownerchg'}{'for'}) eq 'ARRAY') {
6770: foreach my $status (@userstatuses) {
6771: if (grep(/^\Q$status\E$/,@{$passwdconf{'crsownerchg'}{'for'}})) {
6772: undef($noupdate);
6773: last;
6774: }
6775: }
6776: }
6777: }
6778: if ($noupdate) {
6779: return;
6780: }
1.195 raeburn 6781: my %owned = &Apache::lonnet::courseiddump($cdom,'.',1,'.',
6782: $env{'user.name'}.':'.$env{'user.domain'},
6783: undef,undef,undef,'.');
6784: my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
6785: ['active','future']);
6786: foreach my $key (keys(%roleshash)) {
6787: my ($name,$domain,$role) = split(/:/,$key);
6788: if ($role eq 'st') {
6789: next if (($name eq $cnum) && ($domain eq $cdom));
6790: if ($owned{$domain.'_'.$name}) {
6791: if (ref($owned{$domain.'_'.$name}) eq 'HASH') {
6792: if ($owned{$domain.'_'.$name}{'nopasswdchg'}) {
6793: $noupdate = 1;
6794: last;
6795: }
6796: }
6797: } else {
6798: $noupdate = 1;
6799: last;
6800: }
6801: } else {
6802: $noupdate = 1;
6803: last;
6804: }
6805: }
6806: unless ($noupdate) {
6807: $canchange = 1;
6808: }
6809: }
6810: }
6811: }
6812: return $canchange;
6813: }
6814:
1.18 raeburn 6815: sub check_usertype {
1.134 raeburn 6816: my ($dom,$uname,$rules,$curr_rules,$got_rules) = @_;
1.18 raeburn 6817: my $usertype;
1.134 raeburn 6818: if ((ref($got_rules) eq 'HASH') && (ref($curr_rules) eq 'HASH')) {
6819: if (!$got_rules->{$dom}) {
6820: my %domconfig = &Apache::lonnet::get_dom('configuration',
6821: ['usercreation'],$dom);
6822: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6823: foreach my $item ('username','id') {
6824: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
6825: $curr_rules->{$dom}{$item} =
6826: $domconfig{'usercreation'}{$item.'_rule'};
6827: }
6828: }
6829: }
6830: $got_rules->{$dom} = 1;
6831: }
6832: if (ref($rules) eq 'HASH') {
6833: my @user_rules;
6834: if (ref($curr_rules->{$dom}{'username'}) eq 'ARRAY') {
6835: foreach my $rule (keys(%{$rules})) {
6836: if (grep(/^\Q$rule\E/,@{$curr_rules->{$dom}{'username'}})) {
6837: push(@user_rules,$rule);
6838: }
6839: }
6840: }
6841: if (@user_rules > 0) {
6842: my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
6843: if (keys(%rule_check) > 0) {
6844: $usertype = 'unofficial';
6845: foreach my $item (keys(%rule_check)) {
6846: if ($rule_check{$item}) {
6847: $usertype = 'official';
6848: last;
6849: }
1.18 raeburn 6850: }
6851: }
6852: }
6853: }
6854: }
6855: return $usertype;
6856: }
6857:
1.17 raeburn 6858: sub roles_by_context {
1.101 raeburn 6859: my ($context,$custom,$crstype) = @_;
1.17 raeburn 6860: my @allroles;
6861: if ($context eq 'course') {
1.99 raeburn 6862: @allroles = ('st');
6863: if ($env{'request.role'} =~ m{^dc\./}) {
6864: push(@allroles,'ad');
6865: }
1.101 raeburn 6866: push(@allroles,('ta','ep','in'));
6867: if ($crstype eq 'Community') {
6868: push(@allroles,'co');
6869: } else {
6870: push(@allroles,'cc');
6871: }
1.17 raeburn 6872: if ($custom) {
6873: push(@allroles,'cr');
6874: }
6875: } elsif ($context eq 'author') {
6876: @allroles = ('ca','aa');
6877: } elsif ($context eq 'domain') {
1.182 raeburn 6878: @allroles = ('li','ad','dg','dh','da','sc','au','dc');
1.17 raeburn 6879: }
6880: return @allroles;
6881: }
6882:
1.16 raeburn 6883: sub get_permission {
1.101 raeburn 6884: my ($context,$crstype) = @_;
1.16 raeburn 6885: my %permission;
6886: if ($context eq 'course') {
1.17 raeburn 6887: my $custom = 1;
1.101 raeburn 6888: my @allroles = &roles_by_context($context,$custom,$crstype);
1.17 raeburn 6889: foreach my $role (@allroles) {
6890: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
6891: $permission{'cusr'} = 1;
6892: last;
6893: }
1.16 raeburn 6894: }
6895: if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
6896: $permission{'custom'} = 1;
6897: }
6898: if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
6899: $permission{'view'} = 1;
6900: }
6901: if (!$permission{'view'}) {
6902: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
6903: $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
6904: if ($permission{'view'}) {
6905: $permission{'view_section'} = $env{'request.course.sec'};
6906: }
6907: }
1.17 raeburn 6908: if (!$permission{'cusr'}) {
6909: if ($env{'request.course.sec'} ne '') {
6910: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
6911: $permission{'cusr'} = (&Apache::lonnet::allowed('cst',$scope));
6912: if ($permission{'cusr'}) {
6913: $permission{'cusr_section'} = $env{'request.course.sec'};
6914: }
6915: }
6916: }
1.16 raeburn 6917: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
6918: $permission{'grp_manage'} = 1;
6919: }
1.165 raeburn 6920: if ($permission{'cusr'}) {
6921: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6922: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6923: my %coursehash = (
6924: 'internal.selfenrollmgrdc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrdc'},
6925: 'internal.selfenrollmgrcc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrcc'},
6926: 'internal.coursecode' => $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},
6927: 'internal.textbook' =>$env{'course.'.$env{'request.course.id'}.'.internal.textbook'},
6928: );
6929: my ($managed_by_cc,$managed_by_dc) = &selfenrollment_administration($cdom,$cnum,$crstype,\%coursehash);
6930: if (ref($managed_by_cc) eq 'ARRAY') {
6931: if (@{$managed_by_cc}) {
6932: $permission{'selfenrolladmin'} = 1;
6933: }
6934: }
1.216 raeburn 6935: unless ($permission{'selfenrolladmin'}) {
6936: $permission{'selfenrollview'} = 1;
6937: }
1.165 raeburn 6938: }
1.180 raeburn 6939: if ($env{'request.course.id'}) {
1.195 raeburn 6940: my $user;
6941: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
6942: $user = $env{'user.name'}.':'.$env{'user.domain'};
6943: }
1.180 raeburn 6944: if (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'} eq
6945: $user)) {
6946: $permission{'owner'} = 1;
1.195 raeburn 6947: if (&Apache::lonnet::allowed('mip',$env{'request.course.id'})) {
6948: $permission{'mip'} = 1;
6949: }
1.180 raeburn 6950: } elsif (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.co-owners'} ne '')) {
6951: if (grep(/^\Q$user\E$/,split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.co-owners'}))) {
6952: $permission{'co-owner'} = 1;
6953: }
6954: }
6955: }
1.16 raeburn 6956: } elsif ($context eq 'author') {
1.218 raeburn 6957: my $audom = $env{'request.role.domain'};
6958: my $auname = $env{'user.name'};
6959: if ((&Apache::lonnet::allowed('cca',"$audom/$auname")) ||
6960: (&Apache::lonnet::allowed('caa',"$audom/$auname"))) {
6961: $permission{'author'} = 1;
6962: $permission{'cusr'} = 1;
6963: $permission{'view'} = 1;
6964: }
6965: } elsif ($context eq 'coauthor') {
6966: my ($audom,$auname) = ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$});
6967: if ((&Apache::lonnet::allowed('vca',"$audom/$auname")) ||
6968: (&Apache::lonnet::allowed('vaa',"$audom/$auname"))) {
6969: if ($env{"environment.internal.manager./$audom/$auname"}) {
6970: $permission{'cusr'} = 1;
6971: $permission{'view'} = 1;
6972: }
6973: }
1.16 raeburn 6974: } else {
1.17 raeburn 6975: my @allroles = &roles_by_context($context);
6976: foreach my $role (@allroles) {
1.28 raeburn 6977: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
6978: $permission{'cusr'} = 1;
1.17 raeburn 6979: last;
6980: }
6981: }
6982: if (!$permission{'cusr'}) {
6983: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
6984: $permission{'cusr'} = 1;
6985: }
1.16 raeburn 6986: }
6987: if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
6988: $permission{'custom'} = 1;
6989: }
1.176 raeburn 6990: if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
6991: $permission{'activity'} = 1;
6992: }
1.178 raeburn 6993: if (&Apache::lonnet::allowed('vur',$env{'request.role.domain'})) {
6994: $permission{'view'} = 1;
6995: }
1.180 raeburn 6996: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
6997: $permission{'owner'} = 1;
6998: }
1.16 raeburn 6999: }
7000: my $allowed = 0;
1.211 raeburn 7001: foreach my $key (keys(%permission)) {
1.218 raeburn 7002: next if (($key eq 'owner') || ($key eq 'co-owner') || ($key eq 'author'));
1.211 raeburn 7003: if ($permission{$key}) { $allowed=1; last; }
1.16 raeburn 7004: }
7005: return (\%permission,$allowed);
7006: }
7007:
7008: # ==================================================== Figure out author access
7009:
7010: sub authorpriv {
7011: my ($auname,$audom)=@_;
7012: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
7013: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; } return 1;
7014: }
7015:
1.218 raeburn 7016: sub coauthorpriv {
7017: my ($auname,$audom)=@_;
7018: my $uname = $env{'user.name'};
7019: my $udom = $env{'user.domain'};
7020: if (((&Apache::lonnet::allowed('vca',"$udom/$uname")) ||
7021: (&Apache::lonnet::allowed('vaa',"$udom/$uname"))) &&
7022: ($env{"environment.internal.manager./$audom/$auname"})) {
7023: return 1;
7024: }
7025: return '';
7026: }
7027:
1.27 raeburn 7028: sub roles_on_upload {
1.101 raeburn 7029: my ($context,$setting,$crstype,%customroles) = @_;
1.27 raeburn 7030: my (@possible_roles,@permitted_roles);
1.101 raeburn 7031: @possible_roles = &curr_role_permissions($context,$setting,1,$crstype);
1.27 raeburn 7032: foreach my $role (@possible_roles) {
7033: if ($role eq 'cr') {
7034: push(@permitted_roles,keys(%customroles));
7035: } else {
7036: push(@permitted_roles,$role);
7037: }
7038: }
1.42 raeburn 7039: return @permitted_roles;
1.27 raeburn 7040: }
7041:
1.17 raeburn 7042: sub get_course_identity {
7043: my ($cid) = @_;
7044: my ($cnum,$cdom,$cdesc);
7045: if ($cid eq '') {
7046: $cid = $env{'request.course.id'}
7047: }
7048: if ($cid ne '') {
7049: $cnum = $env{'course.'.$cid.'.num'};
7050: $cdom = $env{'course.'.$cid.'.domain'};
7051: $cdesc = $env{'course.'.$cid.'.description'};
7052: if ($cnum eq '' || $cdom eq '') {
7053: my %coursehash =
7054: &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
7055: $cdom = $coursehash{'domain'};
7056: $cnum = $coursehash{'num'};
7057: $cdesc = $coursehash{'description'};
7058: }
7059: }
7060: return ($cnum,$cdom,$cdesc);
7061: }
7062:
1.19 raeburn 7063: sub dc_setcourse_js {
1.196 raeburn 7064: my ($formname,$mode,$context,$showcredits,$domain) = @_;
1.37 raeburn 7065: my ($dc_setcourse_code,$authen_check);
1.19 raeburn 7066: my $cctext = &Apache::lonnet::plaintext('cc');
1.103 raeburn 7067: my $cotext = &Apache::lonnet::plaintext('co');
1.19 raeburn 7068: my %alerts = §ioncheck_alerts();
7069: my $role = 'role';
7070: if ($mode eq 'upload') {
7071: $role = 'courserole';
1.37 raeburn 7072: } else {
1.196 raeburn 7073: $authen_check = &verify_authen($formname,$context,$domain);
1.19 raeburn 7074: }
7075: $dc_setcourse_code = (<<"SCRIPTTOP");
1.37 raeburn 7076: $authen_check
7077:
1.19 raeburn 7078: function setCourse() {
7079: var course = document.$formname.dccourse.value;
7080: if (course != "") {
7081: if (document.$formname.dcdomain.value != document.$formname.origdom.value) {
7082: alert("$alerts{'curd'}");
7083: return;
7084: }
7085: var userrole = document.$formname.$role.options[document.$formname.$role.selectedIndex].value
7086: var section="";
7087: var numsections = 0;
7088: var newsecs = new Array();
7089: for (var i=0; i<document.$formname.currsec.length; i++) {
7090: if (document.$formname.currsec.options[i].selected == true ) {
7091: if (document.$formname.currsec.options[i].value != "" && document.$formname.currsec.options[i].value != null) {
7092: if (numsections == 0) {
7093: section = document.$formname.currsec.options[i].value
7094: numsections = 1;
7095: }
7096: else {
7097: section = section + "," + document.$formname.currsec.options[i].value
7098: numsections ++;
7099: }
7100: }
7101: }
7102: }
7103: if (document.$formname.newsec.value != "" && document.$formname.newsec.value != null) {
7104: if (numsections == 0) {
7105: section = document.$formname.newsec.value
7106: }
7107: else {
7108: section = section + "," + document.$formname.newsec.value
7109: }
7110: newsecs = document.$formname.newsec.value.split(/,/g);
7111: numsections = numsections + newsecs.length;
7112: }
7113: if ((userrole == 'st') && (numsections > 1)) {
1.103 raeburn 7114: if (document.$formname.crstype.value == 'Community') {
7115: alert("$alerts{'inco'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
7116: } else {
7117: alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
7118: }
1.19 raeburn 7119: return;
7120: }
7121: for (var j=0; j<newsecs.length; j++) {
7122: if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
7123: alert("'"+newsecs[j]+"' $alerts{'mayn'}.\\n$alerts{'plsc'}.");
7124: return;
7125: }
7126: if (document.$formname.groups.value != '') {
7127: var groups = document.$formname.groups.value.split(/,/g);
7128: for (var k=0; k<groups.length; k++) {
7129: if (newsecs[j] == groups[k]) {
1.103 raeburn 7130: if (document.$formname.crstype.value == 'Community') {
7131: alert("'"+newsecs[j]+"' $alerts{'mayc'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
7132: } else {
7133: alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
7134: }
1.19 raeburn 7135: return;
7136: }
7137: }
7138: }
7139: }
7140: if ((userrole == 'cc') && (numsections > 0)) {
7141: alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
7142: section = "";
7143: }
1.103 raeburn 7144: if ((userrole == 'co') && (numsections > 0)) {
7145: alert("$alerts{'secd'} $cotext $alerts{'role'}.\\n$alerts{'accr'}.");
7146: section = "";
7147: }
1.19 raeburn 7148: SCRIPTTOP
7149: if ($mode ne 'upload') {
1.150 raeburn 7150: $dc_setcourse_code .= (<<"SCRIPTMID");
1.19 raeburn 7151: var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
7152: var numcourse = getIndex(document.$formname.dccourse);
7153: if (numcourse == "-1") {
1.103 raeburn 7154: if (document.$formname.type == 'Community') {
7155: alert("$alerts{'thwc'}");
7156: } else {
7157: alert("$alerts{'thwa'}");
7158: }
1.19 raeburn 7159: return;
7160: }
7161: else {
7162: document.$formname.elements[numcourse].name = "act"+coursename;
7163: var numnewsec = getIndex(document.$formname.newsec);
7164: if (numnewsec != "-1") {
7165: document.$formname.elements[numnewsec].name = "sec"+coursename;
7166: document.$formname.elements[numnewsec].value = section;
7167: }
7168: var numstart = getIndex(document.$formname.start);
7169: if (numstart != "-1") {
7170: document.$formname.elements[numstart].name = "start"+coursename;
7171: }
7172: var numend = getIndex(document.$formname.end);
7173: if (numend != "-1") {
7174: document.$formname.elements[numend].name = "end"+coursename
7175: }
1.150 raeburn 7176: SCRIPTMID
7177: if ($showcredits) {
7178: $dc_setcourse_code .= <<ENDCRED;
7179: var numcredits = getIndex(document.$formname.credits);
7180: if (numcredits != "-1") {
7181: document.$formname.elements[numcredits].name = "credits"+coursename;
7182: }
7183: ENDCRED
7184: }
7185: $dc_setcourse_code .= <<ENDSCRIPT;
1.19 raeburn 7186: }
7187: }
1.37 raeburn 7188: var authcheck = auth_check();
7189: if (authcheck == 'ok') {
7190: document.$formname.submit();
7191: }
1.19 raeburn 7192: }
7193: ENDSCRIPT
7194: } else {
7195: $dc_setcourse_code .= "
7196: document.$formname.sections.value = section;
7197: }
7198: return 'ok';
7199: }
7200: ";
7201: }
7202: $dc_setcourse_code .= (<<"ENDSCRIPT");
7203:
7204: function getIndex(caller) {
7205: for (var i=0;i<document.$formname.elements.length;i++) {
7206: if (document.$formname.elements[i] == caller) {
7207: return i;
7208: }
7209: }
7210: return -1;
7211: }
7212: ENDSCRIPT
1.37 raeburn 7213: return $dc_setcourse_code;
7214: }
7215:
7216: sub verify_authen {
1.196 raeburn 7217: my ($formname,$context,$domain) = @_;
1.37 raeburn 7218: my %alerts = &authcheck_alerts();
7219: my $finish = "return 'ok';";
7220: if ($context eq 'author') {
7221: $finish = "document.$formname.submit();";
7222: }
1.196 raeburn 7223: my ($numrules,$intargjs) =
1.210 raeburn 7224: &Apache::loncommon::passwd_validation_js('argpicked',$domain);
1.37 raeburn 7225: my $outcome = <<"ENDSCRIPT";
7226:
7227: function auth_check() {
7228: var logintype;
7229: if (document.$formname.login.length) {
7230: if (document.$formname.login.length > 0) {
7231: var loginpicked = 0;
7232: for (var i=0; i<document.$formname.login.length; i++) {
7233: if (document.$formname.login[i].checked == true) {
7234: loginpicked = 1;
7235: logintype = document.$formname.login[i].value;
7236: }
7237: }
7238: if (loginpicked == 0) {
7239: alert("$alerts{'authen'}");
7240: return;
7241: }
7242: }
7243: } else {
7244: logintype = document.$formname.login.value;
7245: }
7246: if (logintype == 'nochange') {
7247: return 'ok';
7248: }
7249: var argpicked = document.$formname.elements[logintype+'arg'].value;
7250: if ((argpicked == null) || (argpicked == '') || (typeof argpicked == 'undefined')) {
7251: var alertmsg = '';
7252: switch (logintype) {
7253: case 'krb':
7254: alertmsg = '$alerts{'krb'}';
7255: break;
7256: case 'int':
7257: alertmsg = '$alerts{'ipass'}';
1.196 raeburn 7258: break;
1.37 raeburn 7259: case 'fsys':
7260: alertmsg = '$alerts{'ipass'}';
7261: break;
7262: case 'loc':
7263: alertmsg = '';
7264: break;
7265: default:
7266: alertmsg = '';
7267: }
7268: if (alertmsg != '') {
7269: alert(alertmsg);
7270: return;
7271: }
1.196 raeburn 7272: } else if (logintype == 'int') {
7273: var numrules = $numrules;
7274: if (numrules > 0) {
7275: $intargjs
7276: }
1.37 raeburn 7277: }
7278: $finish
7279: }
7280: ENDSCRIPT
1.19 raeburn 7281: }
7282:
7283: sub sectioncheck_alerts {
7284: my %alerts = &Apache::lonlocal::texthash(
1.103 raeburn 7285: curd => 'You must select a course or community in the current domain',
1.19 raeburn 7286: inea => 'In each course, each user may only have one student role at a time',
1.103 raeburn 7287: inco => 'In each community, each user may only have one member role at a time',
1.19 raeburn 7288: youh => 'You had selected',
7289: sect => 'sections',
7290: plsm => 'Please modify your selections so they include no more than one section',
7291: mayn => 'may not be used as the name for a section, as it is a reserved word',
7292: plsc => 'Please choose a different section name',
7293: mayt => 'may not be used as the name for a section, as it is the name of a course group',
1.103 raeburn 7294: mayc => 'may not be used as the name for a section, as it is the name of a community group',
1.19 raeburn 7295: secn => 'Section names and group names must be distinct',
7296: secd => 'Section designations do not apply to ',
7297: role => 'roles',
7298: accr => 'role will be added with access to all sections',
1.103 raeburn 7299: thwa => 'There was a problem with your course selection',
7300: thwc => 'There was a problem with your community selection',
1.19 raeburn 7301: );
1.170 damieng 7302: &js_escape(\%alerts);
1.19 raeburn 7303: return %alerts;
7304: }
1.17 raeburn 7305:
1.37 raeburn 7306: sub authcheck_alerts {
7307: my %alerts =
7308: &Apache::lonlocal::texthash(
7309: authen => 'You must choose an authentication type.',
7310: krb => 'You need to specify the Kerberos domain.',
7311: ipass => 'You need to specify the initial password.',
7312: );
1.170 damieng 7313: &js_escape(\%alerts);
1.37 raeburn 7314: return %alerts;
7315: }
7316:
1.141 raeburn 7317: sub is_courseowner {
7318: my ($thiscourse,$courseowner) = @_;
7319: if ($courseowner eq '') {
7320: if ($env{'request.course.id'} eq $thiscourse) {
7321: $courseowner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
7322: }
7323: }
7324: if ($courseowner ne '') {
7325: if ($courseowner eq $env{'user.name'}.':'.$env{'user.domain'}) {
7326: return 1;
7327: }
7328: }
7329: return;
7330: }
7331:
1.165 raeburn 7332: sub get_selfenroll_titles {
7333: my @row = ('types','registered','enroll_dates','access_dates','section',
7334: 'approval','limit');
7335: my %lt = &Apache::lonlocal::texthash (
7336: types => 'Users allowed to self-enroll',
7337: registered => 'Registration status (official courses)' ,
7338: enroll_dates => 'Dates self-enrollment available',
7339: access_dates => 'Access dates for self-enrolling users',
7340: section => "Self-enrolling users' section",
7341: approval => 'Processing of requests',
7342: limit => 'Enrollment limit',
7343: );
7344: return (\@row,\%lt);
7345: }
7346:
7347: sub selfenroll_default_descs {
7348: my %desc = (
7349: types => {
7350: dom => &mt('Course domain'),
7351: all => &mt('Any domain'),
7352: '' => &mt('None'),
7353: },
7354: limit => {
7355: none => &mt('No limit'),
7356: allstudents => &mt('Limit by total students'),
7357: selfenrolled => &mt('Limit by total self-enrolled'),
7358: },
7359: approval => {
7360: '0' => &mt('Processed automatically'),
7361: '1' => &mt('Queued for approval'),
7362: '2' => &mt('Queued, pending validation'),
7363: },
7364: registered => {
7365: 0 => 'No registration required',
7366: 1 => 'Registered students only',
7367: },
7368: );
7369: return %desc;
7370: }
7371:
7372: sub selfenroll_validation_types {
7373: my @items = ('url','fields','button','markup');
7374: my %names = &Apache::lonlocal::texthash (
7375: url => 'Web address of validation server/script',
7376: fields => 'Form fields to send to validator',
7377: button => 'Text for validation button',
7378: markup => 'Validation description (HTML)',
7379: );
1.167 raeburn 7380: my @fields = ('username','domain','uniquecode','course','coursetype','description');
1.165 raeburn 7381: return (\@items,\%names,\@fields);
7382: }
7383:
7384: sub get_extended_type {
7385: my ($cdom,$cnum,$crstype,$current) = @_;
7386: my $type = 'unofficial';
7387: my %settings;
7388: if (ref($current) eq 'HASH') {
7389: %settings = %{$current};
7390: } else {
7391: %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook'],$cdom,$cnum);
7392: }
7393: if ($crstype eq 'Community') {
7394: $type = 'community';
1.173 raeburn 7395: } elsif ($crstype eq 'Placement') {
7396: $type = 'placement';
1.165 raeburn 7397: } elsif ($settings{'internal.coursecode'}) {
7398: $type = 'official';
7399: } elsif ($settings{'internal.textbook'}) {
7400: $type = 'textbook';
7401: }
7402: return $type;
7403: }
7404:
7405: sub selfenrollment_administration {
7406: my ($cdom,$cnum,$crstype,$coursehash) = @_;
7407: my %settings;
7408: if (ref($coursehash) eq 'HASH') {
7409: %settings = %{$coursehash};
7410: } else {
7411: %settings = &Apache::lonnet::get('environment',
7412: ['internal.selfenrollmgrdc','internal.selfenrollmgrcc',
7413: 'internal.coursecode','internal.textbook'],$cdom,$cnum);
7414: }
7415: my ($possconfigs) = &get_selfenroll_titles();
7416: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
7417: my $selfenrolltype = &get_extended_type($cdom,$cnum,$crstype,\%settings);
7418:
7419: my (@in_course,@in_domain);
7420: if ($settings{'internal.selfenrollmgrcc'} ne '') {
7421: @in_course = split(/,/,$settings{'internal.selfenrollmgrcc'});
7422: my @diffs = &Apache::loncommon::compare_arrays($possconfigs,\@in_course);
7423: unless (@diffs) {
7424: return (\@in_course,\@in_domain);
7425: }
7426: }
7427: if ($settings{'internal.selfenrollmgrdc'} ne '') {
1.215 raeburn 7428: @in_domain = split(/,/,$settings{'internal.selfenrollmgrdc'});
1.165 raeburn 7429: my @diffs = &Apache::loncommon::compare_arrays(\@in_domain,$possconfigs);
7430: unless (@diffs) {
7431: return (\@in_course,\@in_domain);
7432: }
7433: }
7434: my @combined = @in_course;
7435: push(@combined,@in_domain);
7436: my @diffs = &Apache::loncommon::compare_arrays(\@combined,$possconfigs);
7437: unless (@diffs) {
7438: return (\@in_course,\@in_domain);
7439: }
7440: if ($domdefaults{$selfenrolltype.'selfenrolladmdc'} eq '') {
7441: push(@in_course,@diffs);
7442: } else {
7443: my @defaultdc = split(/,/,$domdefaults{$selfenrolltype.'selfenrolladmdc'});
7444: foreach my $item (@diffs) {
7445: if (grep(/^\Q$item\E$/,@defaultdc)) {
7446: push(@in_domain,$item);
7447: } else {
7448: push(@in_course,$item);
7449: }
7450: }
7451: }
7452: return (\@in_course,\@in_domain);
7453: }
7454:
1.175 raeburn 7455: sub custom_role_header {
7456: my ($context,$crstype,$templaterolerefs,$prefix) = @_;
7457: my %lt = &Apache::lonlocal::texthash(
7458: sele => 'Select a Template',
7459: );
7460: my ($context_code,$button_code);
7461: if ($context eq 'domain') {
7462: $context_code = &custom_coursetype_switch($crstype,$prefix);
7463: }
7464: if (ref($templaterolerefs) eq 'ARRAY') {
7465: foreach my $role (@{$templaterolerefs}) {
7466: my $display = 'inline';
7467: if (($context eq 'domain') && ($role eq 'co')) {
7468: $display = 'none';
7469: }
7470: $button_code .= &make_button_code($role,$crstype,$display,$prefix).' ';
7471: }
7472: }
7473: return <<"END";
7474: <div class="LC_left_float">
7475: <fieldset>
7476: <legend>$lt{'sele'}</legend>
7477: $button_code
7478: </fieldset></div>
7479: $context_code
7480: <br clear="all" />
7481: END
7482: }
7483:
7484: sub custom_coursetype_switch {
7485: my ($crstype,$prefix) = @_;
7486: my ($checkedcourse,$checkedcommunity);
7487: if ($crstype eq 'Community') {
7488: $checkedcommunity = ' checked="checked"';
7489: } else {
7490: $checkedcourse = ' checked="checked"';
7491: }
7492: my %lt = &Apache::lonlocal::texthash(
7493: cont => 'Context',
7494: cour => 'Course',
7495: comm => 'Community',
7496: );
7497: return <<"END";
7498: <div class="LC_left_float">
7499: <fieldset>
7500: <legend>$lt{'cont'}</legend>
7501: <label>
7502: <input type="radio" name="${prefix}_custrolecrstype" value="Course"$checkedcourse onclick="javascript:customSwitchType('$prefix');" />
7503: $lt{'cour'}
7504: </label>
7505: <label>
7506: <input type="radio" name="${prefix}_custrolecrstype" value="Community"$checkedcommunity onclick="javascript:customSwitchType('$prefix');" />
7507: $lt{'comm'}
7508: </label>
7509: </fieldset>
7510: </div>
7511: END
7512: }
7513:
7514: sub custom_role_table {
1.180 raeburn 7515: my ($crstype,$full,$levels,$levelscurrent,$prefix,$add_class,$id) = @_;
1.175 raeburn 7516: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7517: (ref($levelscurrent) eq 'HASH'));
7518: my %lt=&Apache::lonlocal::texthash (
7519: 'prv' => "Privilege",
7520: 'crl' => "Course Level",
7521: 'dml' => "Domain Level",
7522: 'ssl' => "System Level");
7523: my %cr = (
7524: course => '_c',
7525: domain => '_d',
7526: system => '_s',
7527: );
7528:
1.180 raeburn 7529: my $output=&Apache::loncommon::start_data_table($add_class,$id).
1.175 raeburn 7530: &Apache::loncommon::start_data_table_header_row().
7531: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
7532: '</th><th>'.$lt{'ssl'}.'</th>'.
7533: &Apache::loncommon::end_data_table_header_row();
7534: foreach my $priv (sort(keys(%{$full}))) {
7535: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7536: $output .= &Apache::loncommon::start_data_table_row().
7537: '<td><span id="'.$prefix.$priv.'">'.$privtext.'</span></td>';
7538: foreach my $type ('course','domain','system') {
7539: if (($type eq 'system') && ($priv eq 'bre') && ($crstype eq 'Community')) {
7540: $output .= '<td> </td>';
7541: } else {
7542: $output .= '<td>'.
7543: ($levels->{$type}{$priv}?'<input type="checkbox" id="'.$prefix.$priv.$cr{$type}.'"'.
7544: ' name="'.$prefix.$priv.$cr{$type}.'"'.
7545: ($levelscurrent->{$type}{$priv}?' checked="checked"':'').' />':' ').
7546: '</td>';
7547: }
7548: }
7549: $output .= &Apache::loncommon::end_data_table_row();
7550: }
7551: $output .= &Apache::loncommon::end_data_table();
7552: return $output;
7553: }
7554:
7555: sub custom_role_privs {
7556: my ($privs,$full,$levels,$levelscurrent)= @_;
7557: return unless ((ref($privs) eq 'HASH') && (ref($full) eq 'HASH') &&
7558: (ref($levels) eq 'HASH') && (ref($levelscurrent) eq 'HASH'));
7559: my %cr = (
7560: course => 'cr:c',
7561: domain => 'cr:d',
7562: system => 'cr:s',
7563: );
7564: foreach my $type ('course','domain','system') {
7565: foreach my $item (split(/\:/,$Apache::lonnet::pr{$cr{$type}})) {
7566: my ($priv,$restrict)=split(/\&/,$item);
7567: if (!$restrict) { $restrict='F'; }
7568: $levels->{$type}->{$priv}=$restrict;
7569: if ($privs->{$type}=~/\:$priv/) {
7570: $levelscurrent->{$type}->{$priv}=1;
7571: }
7572: $full->{$priv}=1;
7573: }
7574: }
7575: return;
7576: }
7577:
7578: sub custom_template_roles {
7579: my ($context,$crstype) = @_;
7580: my @template_roles = ("in","ta","ep");
7581: if (($context eq 'domain') || ($context eq 'domprefs')) {
7582: push(@template_roles,"ad");
7583: }
7584: push(@template_roles,"st");
7585: if ($context eq 'domain') {
7586: unshift(@template_roles,('co','cc'));
7587: } else {
7588: if ($crstype eq 'Community') {
7589: unshift(@template_roles,'co');
7590: } else {
7591: unshift(@template_roles,'cc');
7592: }
7593: }
7594: return @template_roles;
7595: }
7596:
7597: sub custom_roledefs_js {
7598: my ($context,$crstype,$formname,$full,$templaterolesref,$jsback) = @_;
7599: my $button_code = "\n";
7600: my $head_script = "\n";
7601: my (%roletitlestr,$rolenamestr);
7602: my %role_titles = (
7603: Course => [],
7604: Community => [],
7605: );
7606: $head_script .= '<script type="text/javascript">'."\n"
7607: .'// <![CDATA['."\n";
7608: if (ref($templaterolesref) eq 'ARRAY') {
7609: if ($context eq 'domain') {
7610: $rolenamestr = join("','",@{$templaterolesref});
7611: }
7612: foreach my $role (@{$templaterolesref}) {
7613: $head_script .= &make_script_template($role,$crstype,$formname);
7614: if ($context eq 'domain') {
7615: foreach my $type ('Course','Community') {
7616: push(@{$role_titles{$type}},&Apache::lonnet::plaintext($role,$type));
7617: }
7618: }
7619: }
7620: }
7621: if ($context eq 'domain') {
7622: foreach my $type ('Course','Community') {
7623: $roletitlestr{$type} = join("','",@{$role_titles{$type}});
7624: }
7625: my %pt = (
7626: Community => {
7627: cst => &mt('Grant/revoke role of Member'),
7628: mdc => &mt('Edit community contents'),
7629: pch => &mt('Post discussion on community resources'),
7630: pfo => &mt('Print for other users and entire community'),
7631: },
7632: Course => {
7633: cst => &mt('Grant/revoke role of Student'),
7634: mdc => &mt('Edit course contents'),
7635: pch => &mt('Post discussion on course resources'),
7636: pfo => &mt('Print for other users and entire course'),
7637: },
7638: );
7639: $head_script .= <<"ENDJS";
7640: function customSwitchType(prefix) {
7641: var privnames = new Array('cst','mdc','pch','pfo');
7642: var privtxtcrs = new Array('$pt{Course}{cst}','$pt{Course}{mdc}','$pt{Course}{pch}','$pt{Course}{pfo}');
7643: var privtxtcom = new Array('$pt{Community}{cst}','$pt{Community}{mdc}','$pt{Community}{pch}','$pt{Community}{pfo}');
7644: var rolenames = new Array('$rolenamestr');
7645: var rolescrs = new Array('$roletitlestr{Course}');
7646: var rolescom = new Array('$roletitlestr{Community}');
7647: var radio = prefix+'_custrolecrstype';
7648: if (document.$formname.elements[radio].length > 1) {
7649: for (var i=0; i<document.$formname.elements[radio].length; i++) {
7650: if (document.$formname.elements[radio][i].checked) {
7651: if ((document.getElementById(prefix+'bre_s')) && (document.getElementById(prefix+'bro_s'))) {
7652: if (document.$formname.elements[radio][i].value == 'Community') {
7653: if (document.getElementById(prefix+'bre_s').checked) {
7654: document.getElementById(prefix+'bro_s').checked = true;
7655: document.getElementById(prefix+'bre_s').checked = false;
7656:
7657: }
7658: document.getElementById(prefix+'bre_s').style.visibility = 'hidden';
7659: } else {
7660: document.getElementById(prefix+'bre_s').style.visibility = 'visible';
7661: if (document.getElementById(prefix+'bro_s').checked) {
7662: document.getElementById(prefix+'bre_s').checked = true;
7663: document.getElementById(prefix+'bro_s').checked = false;
7664: }
7665: }
7666: }
7667: for (var j=0; j<privnames.length; j++) {
7668: if (document.getElementById(prefix+privnames[j])) {
7669: if (document.getElementById(prefix+privnames[j])) {
7670: if (document.$formname.elements[radio][i].value == 'Course') {
7671: document.getElementById(prefix+privnames[j]).innerHTML = privtxtcrs[j];
7672: } else {
7673: document.getElementById(prefix+privnames[j]).innerHTML = privtxtcom[j];
7674: }
7675: }
7676: }
7677: }
7678: for (var j=0; j<rolenames.length; j++) {
7679: if (document.getElementById(prefix+rolenames[j])) {
7680: if (document.getElementById(prefix+rolenames[j])) {
7681: if (document.$formname.elements[radio][i].value == 'Course') {
7682: document.getElementById(prefix+rolenames[j]).value = rolescrs[j];
7683: if (rolenames[j] == 'cc') {
7684: document.getElementById(prefix+rolenames[j]).style.display = 'inline';
7685: }
7686: if (rolenames[j] == 'co') {
7687: document.getElementById(prefix+rolenames[j]).style.display = 'none';
7688: }
7689: } else {
7690: document.getElementById(prefix+rolenames[j]).value = rolescom[j];
7691: if (rolenames[j] == 'cc') {
7692: document.getElementById(prefix+rolenames[j]).style.display = 'none';
7693: }
7694: if (rolenames[j] == 'co') {
7695: document.getElementById(prefix+rolenames[j]).style.display = 'inline';
7696: }
7697: }
7698: }
7699: }
7700: }
7701: }
7702: }
7703: }
7704: return;
7705: }
7706: ENDJS
7707: }
7708: $head_script .= "\n".$jsback."\n"
7709: .'// ]]>'."\n"
7710: .'</script>'."\n";
7711: return $head_script;
7712: }
7713:
7714: # --------------------------------------------------------
7715: sub make_script_template {
7716: my ($role,$crstype,$formname) = @_;
7717: my $return_script = 'function set_'.$role.'(prefix) {'."\n";
7718: my (%full_by_level,%role_priv);
7719: foreach my $level ('c','d','s') {
7720: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
7721: next if (($level eq 's') && ($crstype eq 'Community') && ($item eq 'bre&S'));
7722: my ($priv,$restrict)=split(/\&/,$item);
7723: $full_by_level{$level}{$priv}=1;
7724: }
7725: $role_priv{$level} = {};
7726: my @temp = split(/:/,$Apache::lonnet::pr{$role.':'.$level});
7727: foreach my $priv (@temp) {
7728: my ($priv_item, $dummy) = split(/\&/,$priv);
7729: $role_priv{$level}{$priv_item} = 1;
7730: }
7731: }
7732: my %to_check = (
7733: c => ['c','d','s'],
7734: d => ['d','s'],
7735: s => ['s'],
7736: );
7737: foreach my $level ('c','d','s') {
7738: if (ref($full_by_level{$level}) eq 'HASH') {
7739: foreach my $priv (keys(%{$full_by_level{$level}})) {
7740: my $value = 'false';
7741: if (ref($to_check{$level}) eq 'ARRAY') {
7742: foreach my $lett (@{$to_check{$level}}) {
7743: if (exists($role_priv{$lett}{$priv})) {
7744: $value = 'true';
7745: last;
7746: }
7747: }
7748: $return_script .= "document.$formname.elements[prefix+'".$priv."_".$level."'].checked = $value;\n";
7749: }
7750: }
7751: }
7752: }
7753: $return_script .= '}'."\n";
7754: return ($return_script);
7755: }
7756: # ----------------------------------------------------------
7757: sub make_button_code {
7758: my ($role,$crstype,$display,$prefix) = @_;
7759: my $label = &Apache::lonnet::plaintext($role,$crstype);
7760: my $button_code = '<input type="button" onclick="set_'.$role."('$prefix'".')" '.
7761: 'id="'.$prefix.$role.'" value="'.$label.'" '.
7762: 'style="display:'.$display.'" />';
7763: return ($button_code);
7764: }
7765:
7766: sub custom_role_update {
7767: my ($rolename,$prefix) = @_;
7768: # ------------------------------------------------------- What can be assigned?
7769: my %privs = (
7770: c => '',
7771: d => '',
7772: s => '',
7773: );
7774: foreach my $level (keys(%privs)) {
7775: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
7776: my ($priv,$restrict)=split(/\&/,$item);
7777: if (!$restrict) { $restrict=''; }
7778: if ($env{'form.'.$prefix.$priv.'_'.$level}) {
7779: $privs{$level} .=':'.$item;
7780: }
7781: }
7782: }
7783: return %privs;
7784: }
7785:
1.180 raeburn 7786: sub adhoc_status_types {
7787: my ($cdom,$context,$role,$selectedref,$othertitle,$usertypes,$types,$disabled) = @_;
7788: my $output = &Apache::loncommon::start_data_table();
7789: my $numinrow = 3;
7790: my $rem;
7791: if (ref($types) eq 'ARRAY') {
7792: for (my $i=0; $i<@{$types}; $i++) {
7793: if (defined($usertypes->{$types->[$i]})) {
7794: my $rem = $i%($numinrow);
7795: if ($rem == 0) {
7796: if ($i > 0) {
7797: $output .= &Apache::loncommon::end_data_table_row();
7798: }
7799: $output .= &Apache::loncommon::start_data_table_row();
7800: }
7801: my $check;
7802: if (ref($selectedref) eq 'ARRAY') {
7803: if (grep(/^\Q$types->[$i]\E$/,@{$selectedref})) {
7804: $check = ' checked="checked"';
7805: }
7806: }
7807: $output .= '<td>'.
7808: '<span class="LC_nobreak"><label>'.
7809: '<input type="checkbox" name="'.$context.$role.'_status" '.
7810: 'value="'.$types->[$i].'"'.$check.$disabled.' />'.
7811: $usertypes->{$types->[$i]}.'</label></span></td>';
7812: }
7813: }
7814: $rem = @{$types}%($numinrow);
7815: }
7816: my $colsleft = $numinrow - $rem;
7817: if (($rem == 0) && (@{$types} > 0)) {
7818: $output .= &Apache::loncommon::start_data_table_row();
7819: }
7820: if ($colsleft > 1) {
7821: $output .= '<td colspan="'.$colsleft.'">';
7822: } else {
7823: $output .= '<td>';
7824: }
7825: my $defcheck;
7826: if (ref($selectedref) eq 'ARRAY') {
7827: if (grep(/^default$/,@{$selectedref})) {
7828: $defcheck = ' checked="checked"';
7829: }
7830: }
7831: $output .= '<span class="LC_nobreak"><label>'.
7832: '<input type="checkbox" name="'.$context.$role.'_status"'.
7833: 'value="default"'.$defcheck.$disabled.' />'.
7834: $othertitle.'</label></span></td>'.
7835: &Apache::loncommon::end_data_table_row().
7836: &Apache::loncommon::end_data_table();
7837: return $output;
7838: }
7839:
7840: sub adhoc_staff {
7841: my ($access,$context,$role,$selectedref,$adhocref,$disabled) = @_;
7842: my $output;
7843: if (ref($adhocref) eq 'HASH') {
7844: my %by_fullname;
7845: my $numinrow = 4;
7846: my $rem;
7847: my @personnel = keys(%{$adhocref});
7848: if (@personnel) {
7849: foreach my $person (@personnel) {
7850: my ($uname,$udom) = split(/:/,$person);
7851: my $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
7852: $by_fullname{$fullname} = $person;
7853: }
7854: my @sorted = sort(keys(%by_fullname));
7855: my $count = scalar(@sorted);
7856: $output = &Apache::loncommon::start_data_table();
7857: for (my $i=0; $i<$count; $i++) {
7858: my $rem = $i%($numinrow);
7859: if ($rem == 0) {
7860: if ($i > 0) {
7861: $output .= &Apache::loncommon::end_data_table_row();
7862: }
7863: $output .= &Apache::loncommon::start_data_table_row();
7864: }
7865: my $check;
7866: my $user = $by_fullname{$sorted[$i]};
7867: if (ref($selectedref) eq 'ARRAY') {
7868: if (grep(/^\Q$user\E$/,@{$selectedref})) {
7869: $check = ' checked="checked"';
7870: }
7871: }
7872: if ($i == $count-1) {
7873: my $colsleft = $numinrow - $rem;
7874: if ($colsleft > 1) {
7875: $output .= '<td colspan="'.$colsleft.'">';
7876: } else {
7877: $output .= '<td>';
7878: }
7879: } else {
7880: $output .= '<td>';
7881: }
7882: $output .= '<span class="LC_nobreak"><label>'.
7883: '<input type="checkbox" name="'.$context.$role.'_staff_'.$access.'" '.
7884: 'value="'.$user.'"'.$check.$disabled.' />'.$sorted[$i].
7885: '</label></span></td>';
7886: if ($i == $count-1) {
7887: $output .= &Apache::loncommon::end_data_table_row();
7888: }
7889: }
7890: $output .= &Apache::loncommon::end_data_table();
7891: }
7892: }
7893: return $output;
7894: }
7895:
7896:
1.1 raeburn 7897: 1;
7898:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>