Annotation of loncom/interface/lonuserutils.pm, revision 1.224
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
1.224 ! raeburn 4: # $Id: lonuserutils.pm,v 1.223 2025/01/12 23:34:20 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.223 raeburn 3717: if (grep(/^clicker$/,@cols)) {
3718: my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
3719: if ($clickers!~/\w/) { $clickers='-'; }
3720: $in{'clicker'} = $clickers;
3721: }
1.67 droeschl 3722: my $role = $in{'role'};
1.102 raeburn 3723: $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
1.136 raeburn 3724: unless ($mode eq 'excel') {
3725: if (! defined($in{'start'}) || $in{'start'} == 0) {
3726: $in{'start'} = &mt('none');
3727: } else {
3728: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
3729: }
3730: if (! defined($in{'end'}) || $in{'end'} == 0) {
3731: $in{'end'} = &mt('none');
3732: } else {
3733: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
3734: }
1.1 raeburn 3735: }
1.139 raeburn 3736: if ($context eq 'course') {
3737: my $lastlogin = $crslogins{$in{'username'}.':'.$in{'domain'}.':'.$in{'section'}.':'.$role};
3738: if ($lastlogin ne '') {
3739: $in{'lastlogin'} = &Apache::lonlocal::locallocaltime($lastlogin);
3740: }
3741: }
1.55 raeburn 3742: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2 raeburn 3743: $r->print(&Apache::loncommon::start_data_table_row());
1.11 raeburn 3744: my $checkval;
1.16 raeburn 3745: if ($mode eq 'autoenroll') {
3746: my $cellentry;
3747: if ($in{'type'} eq 'auto') {
1.178 raeburn 3748: $cellentry = '<b>'.&mt('auto').'</b> <label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Change').'</label>';
1.16 raeburn 3749: $autocount ++;
3750: } else {
1.178 raeburn 3751: $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 3752: $manualcount ++;
3753: if ($in{'lockedtype'}) {
1.178 raeburn 3754: $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Unlock').'</label>';
1.16 raeburn 3755: $unlockcount ++;
3756: } else {
1.178 raeburn 3757: $cellentry .= '<label><input type="checkbox" name="lockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Lock').'</label>';
1.16 raeburn 3758: $lockcount ++;
1.11 raeburn 3759: }
1.76 bisitz 3760: $cellentry .= '</span></td></tr></table>';
1.16 raeburn 3761: }
3762: $r->print("<td>$cellentry</td>\n");
3763: } else {
1.55 raeburn 3764: if ($mode ne 'pickauthor') {
3765: $r->print("<td>$rowcount</td>\n");
3766: }
1.16 raeburn 3767: if ($actionselect) {
1.26 raeburn 3768: my $showcheckbox;
3769: if ($role =~ /^cr\//) {
3770: $showcheckbox = $canchange{'cr'};
3771: } else {
3772: $showcheckbox = $canchange{$role};
3773: }
3774: if (!$showcheckbox) {
3775: if ($context eq 'course') {
3776: if ($canchangesec{$role} ne '') {
3777: if ($canchangesec{$role} eq $in{'section'}) {
3778: $showcheckbox = 1;
3779: }
3780: }
1.16 raeburn 3781: }
1.26 raeburn 3782: }
3783: if ($showcheckbox) {
3784: $checkval = $user;
3785: if ($context eq 'course') {
1.141 raeburn 3786: if (($role eq 'co' || $role eq 'cc') &&
3787: ($user =~ /^\Q$env{'user.name'}:$env{'user.domain'}:$role\E/)) {
3788: $showcheckbox = 0;
3789: } else {
3790: if ($role eq 'st') {
3791: $checkval .= ':st';
3792: }
3793: $checkval .= ':'.$in{'section'};
3794: if ($role eq 'st') {
3795: $checkval .= ':'.$in{'type'}.':'.
1.150 raeburn 3796: $in{'lockedtype'}.':'.
1.174 raeburn 3797: $in{'credits'}.':'.
3798: &escape($in{'instsec'});
1.141 raeburn 3799: }
3800: }
3801: }
3802: if ($showcheckbox) {
3803: $r->print('<td><input type="checkbox" name="'.
1.183 raeburn 3804: 'actionlist" value="'.
3805: &HTML::Entities::encode($checkval,'&<>"').'" />');
3806: foreach my $item ('start','end') {
3807: $r->print('<input type="hidden" name="'.
3808: &HTML::Entities::encode($checkval.'_'.$item,'&<>"').'"'.
3809: ' value="'.$sdata->[$index{$item}].'" />');
3810: }
3811: $r->print('</td>');
1.141 raeburn 3812: } else {
3813: $r->print('<td> </td>');
1.16 raeburn 3814: }
1.26 raeburn 3815: } else {
3816: $r->print('<td> </td>');
1.16 raeburn 3817: }
1.55 raeburn 3818: } elsif ($mode eq 'pickauthor') {
3819: $r->print('<td><input type="button" name="chooseauthor" onclick="javascript:gochoose('."'$in{'username'}'".');" value="'.&mt('Select').'" /></td>');
1.11 raeburn 3820: }
3821: }
1.2 raeburn 3822: foreach my $item (@cols) {
1.10 raeburn 3823: if ($item eq 'username') {
1.48 raeburn 3824: $r->print('<td>'.&print_username_link($mode,\%in).'</td>');
1.83 raeburn 3825: } elsif ($item eq 'status') {
3826: my $showitem = $in{$item};
3827: if (defined($ltstatus{$in{$item}})) {
3828: $showitem = $ltstatus{$in{$item}};
3829: }
3830: $r->print('<td>'.$showitem.'</td>'."\n");
1.140 raeburn 3831: } elsif ($item eq 'photo') {
3832: if (($context eq 'course') && ($mode ne 'autoenroll') &&
3833: ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
3834: if ($role eq 'st') {
3835: $r->print('<td align="right"><a href="javascript:photowindow('."'".$in{'photo'}."'".')"><img src="'.$in{'thumbnail'}.'" border="1" alt="" /></a></td>');
3836: } else {
3837: $r->print('<td> </td>');
3838: }
3839: }
3840: } elsif ($item eq 'clicker') {
3841: if (($context eq 'course') && ($mode ne 'autoenroll')) {
3842: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
1.223 raeburn 3843: $r->print('<td>'.$in{'clicker'}.'</td>');
1.140 raeburn 3844: } else {
3845: $r->print('<td> </td>'."\n");
3846: }
1.149 raeburn 3847: }
1.159 raeburn 3848: } elsif (($item eq 'authorquota') || ($item eq 'authorusage')) {
3849: $r->print('<td align="right">'.$in{$item}.'</td>'."\n");
1.10 raeburn 3850: } else {
3851: $r->print('<td>'.$in{$item}.'</td>'."\n");
3852: }
1.2 raeburn 3853: }
3854: $r->print(&Apache::loncommon::end_data_table_row());
3855: } elsif ($mode eq 'csv') {
3856: next if (! defined($CSVfile));
3857: # no need to bother with $linkto
3858: my @line = ();
3859: foreach my $item (@cols) {
3860: push @line,&Apache::loncommon::csv_translate($in{$item});
3861: }
1.67 droeschl 3862: print $CSVfile '"'.join('","',@line)."\"\n";
1.2 raeburn 3863: } elsif ($mode eq 'excel') {
3864: my $col = 0;
3865: foreach my $item (@cols) {
3866: if ($item eq 'start' || $item eq 'end') {
1.136 raeburn 3867: if ((defined($in{$item})) && ($in{$item} != 0)) {
1.2 raeburn 3868: $excel_sheet->write($row,$col++,
1.136 raeburn 3869: &Apache::lonstathelpers::calc_serial($in{$item}),
1.2 raeburn 3870: $format->{'date'});
3871: } else {
3872: $excel_sheet->write($row,$col++,'none');
3873: }
3874: } else {
3875: $excel_sheet->write($row,$col++,$in{$item});
3876: }
3877: }
3878: $row++;
1.1 raeburn 3879: }
3880: }
1.55 raeburn 3881: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2 raeburn 3882: $r->print(&Apache::loncommon::end_data_table().'<br />');
3883: } elsif ($mode eq 'excel') {
3884: $excel_workbook->close();
1.162 bisitz 3885: $r->print('<p>'.&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '<a href="'.$excel_filename.'">','</a>')."</p>\n");
1.2 raeburn 3886: } elsif ($mode eq 'csv') {
3887: close($CSVfile);
1.162 bisitz 3888: $r->print('<p>'.&mt('[_1]Your CSV file[_2] is ready for download.', '<a href="'.$CSVfilename.'">','</a>')."</p>\n");
1.2 raeburn 3889: $r->rflush();
3890: }
3891: if ($mode eq 'autoenroll') {
3892: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
1.4 raeburn 3893: } else {
3894: return ($usercount);
1.2 raeburn 3895: }
1.1 raeburn 3896: }
3897:
1.56 raeburn 3898: sub bulkaction_javascript {
3899: my ($formname,$caller) = @_;
3900: my $docstart = 'document';
3901: if ($caller eq 'popup') {
3902: $docstart = 'opener.document';
3903: }
3904: my %lt = &Apache::lonlocal::texthash(
3905: acwi => 'Access will be set to start immediately',
3906: asyo => 'as you did not select an end date in the pop-up window',
3907: accw => 'Access will be set to continue indefinitely',
3908: asyd => 'as you did not select an end date in the pop-up window',
3909: sewi => "Sections will be switched to 'No section'",
3910: ayes => "as you either selected the 'No section' option",
3911: oryo => 'or you did not select a section in the pop-up window',
3912: arol => 'A role with no section will be added',
3913: swbs => 'Sections will be switched to:',
3914: rwba => 'Roles will be added for section(s):',
3915: );
3916: my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
3917: my $noaction = &mt("You need to select an action to take for the user(s) you have selected");
3918: my $singconfirm = &mt(' for a single user?');
3919: my $multconfirm = &mt(' for multiple users?');
1.170 damieng 3920: &js_escape(\$alert);
3921: &js_escape(\$noaction);
3922: &js_escape(\$singconfirm);
3923: &js_escape(\$multconfirm);
1.56 raeburn 3924: my $output = <<"ENDJS";
3925: function verify_action (field) {
3926: var numchecked = 0;
3927: var singconf = '$singconfirm';
3928: var multconf = '$multconfirm';
3929: if ($docstart.$formname.elements[field].length > 0) {
3930: for (i=0; i<$docstart.$formname.elements[field].length; i++) {
3931: if ($docstart.$formname.elements[field][i].checked == true) {
3932: numchecked ++;
3933: }
3934: }
3935: } else {
3936: if ($docstart.$formname.elements[field].checked == true) {
3937: numchecked ++;
3938: }
3939: }
3940: if (numchecked == 0) {
3941: alert("$alert");
3942: return;
3943: } else {
3944: var message = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].text;
3945: var choice = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].value;
3946: if (choice == '') {
3947: alert("$noaction");
3948: return;
3949: } else {
3950: if (numchecked == 1) {
3951: message += singconf;
3952: } else {
3953: message += multconf;
3954: }
3955: ENDJS
3956: if ($caller ne 'popup') {
3957: $output .= <<"NEWWIN";
3958: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate' || choice == 'chgsec') {
3959: opendatebrowser(document.$formname,'$formname','go');
3960: return;
3961:
3962: } else {
3963: if (confirm(message)) {
3964: document.$formname.phase.value = 'bulkchange';
3965: document.$formname.submit();
3966: return;
3967: }
3968: }
3969: NEWWIN
3970: } else {
3971: $output .= <<"POPUP";
3972: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
3973: var datemsg = '';
3974: if (($docstart.$formname.startdate_month.value == '') &&
3975: ($docstart.$formname.startdate_day.value == '') &&
3976: ($docstart.$formname.startdate_year.value == '')) {
3977: datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
3978: }
3979: if (($docstart.$formname.enddate_month.value == '') &&
3980: ($docstart.$formname.enddate_day.value == '') &&
3981: ($docstart.$formname.enddate_year.value == '')) {
3982: datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
3983: }
3984: if (datemsg != '') {
3985: message += "\\n"+datemsg;
3986: }
3987: }
3988: if (choice == 'chgsec') {
3989: var rolefilter = $docstart.$formname.showrole.options[$docstart.$formname.showrole.selectedIndex].value;
3990: var retained = $docstart.$formname.retainsec.value;
3991: var secshow = $docstart.$formname.newsecs.value;
3992: if (secshow == '') {
3993: if (rolefilter == 'st' || retained == 0 || retained == "") {
3994: message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
3995: } else {
3996: message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
3997: }
3998: } else {
3999: if (rolefilter == 'st' || retained == 0 || retained == "") {
4000: message += "\\n\\n$lt{'swbs'} "+secshow+".\\n";
4001: } else {
4002: message += "\\n\\n$lt{'rwba'} "+secshow+".\\n";
4003: }
4004: }
4005: }
4006: if (confirm(message)) {
4007: $docstart.$formname.phase.value = 'bulkchange';
4008: $docstart.$formname.submit();
4009: window.close();
4010: }
4011: POPUP
4012: }
4013: $output .= '
4014: }
4015: }
4016: }
4017: ';
4018: return $output;
4019: }
4020:
1.10 raeburn 4021: sub print_username_link {
1.48 raeburn 4022: my ($mode,$in) = @_;
1.10 raeburn 4023: my $output;
1.16 raeburn 4024: if ($mode eq 'autoenroll') {
4025: $output = $in->{'username'};
1.10 raeburn 4026: } else {
4027: $output = '<a href="javascript:username_display_launch('.
1.112 bisitz 4028: "'$in->{'username'}','$in->{'domain'}'".')">'.
1.10 raeburn 4029: $in->{'username'}.'</a>';
4030: }
4031: return $output;
4032: }
4033:
1.2 raeburn 4034: sub role_type_names {
4035: my %lt = &Apache::lonlocal::texthash (
1.13 raeburn 4036: 'domain' => 'Domain Roles',
4037: 'author' => 'Co-Author Roles',
4038: 'course' => 'Course Roles',
1.101 raeburn 4039: 'community' => 'Community Roles',
1.2 raeburn 4040: );
4041: return %lt;
4042: }
4043:
1.11 raeburn 4044: sub select_actions {
1.55 raeburn 4045: my ($context,$setting,$statusmode,$formname) = @_;
1.11 raeburn 4046: my %lt = &Apache::lonlocal::texthash(
4047: revoke => "Revoke user roles",
4048: delete => "Delete user roles",
4049: reenable => "Re-enable expired user roles",
4050: activate => "Make future user roles active now",
4051: chgdates => "Change starting/ending dates",
4052: chgsec => "Change section associated with user roles",
4053: );
1.150 raeburn 4054: # FIXME Add an option to change credits for student roles.
1.11 raeburn 4055: my ($output,$options,%choices);
1.23 raeburn 4056: # FIXME Disable actions for now for roletype=course in domain context
4057: if ($context eq 'domain' && $setting eq 'course') {
4058: return;
4059: }
1.26 raeburn 4060: if ($context eq 'course') {
4061: if ($env{'form.showrole'} ne 'Any') {
1.141 raeburn 4062: my $showactions;
4063: if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},
4064: $env{'request.course.id'})) {
4065: $showactions = 1;
4066: } elsif ($env{'request.course.sec'} ne '') {
4067: if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
4068: $showactions = 1;
4069: }
4070: }
4071: unless ($showactions) {
4072: unless (&is_courseowner($env{'request.course.id'},
4073: $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
4074: return;
4075: }
1.26 raeburn 4076: }
4077: }
4078: }
1.11 raeburn 4079: if ($statusmode eq 'Any') {
4080: $options .= '
4081: <option value="chgdates">'.$lt{'chgdates'}.'</option>';
4082: $choices{'dates'} = 1;
4083: } else {
4084: if ($statusmode eq 'Future') {
4085: $options .= '
4086: <option value="activate">'.$lt{'activate'}.'</option>';
4087: $choices{'dates'} = 1;
4088: } elsif ($statusmode eq 'Expired') {
4089: $options .= '
4090: <option value="reenable">'.$lt{'reenable'}.'</option>';
4091: $choices{'dates'} = 1;
4092: }
1.13 raeburn 4093: if ($statusmode eq 'Active' || $statusmode eq 'Future') {
4094: $options .= '
4095: <option value="chgdates">'.$lt{'chgdates'}.'</option>
4096: <option value="revoke">'.$lt{'revoke'}.'</option>';
4097: $choices{'dates'} = 1;
4098: }
1.11 raeburn 4099: }
4100: if ($context eq 'domain') {
4101: $options .= '
4102: <option value="delete">'.$lt{'delete'}.'</option>';
4103: }
4104: if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
1.26 raeburn 4105: if (($statusmode ne 'Expired') && ($env{'request.course.sec'} eq '')) {
1.11 raeburn 4106: $options .= '
4107: <option value="chgsec">'.$lt{'chgsec'}.'</option>';
4108: $choices{'sections'} = 1;
4109: }
4110: }
4111: if ($options) {
1.56 raeburn 4112: $output = '<select name="bulkaction">'."\n".
1.11 raeburn 4113: '<option value="" selected="selected">'.
4114: &mt('Please select').'</option>'."\n".$options."\n".'</select>';
4115: if ($choices{'dates'}) {
4116: $output .=
4117: '<input type="hidden" name="startdate_month" value="" />'."\n".
4118: '<input type="hidden" name="startdate_day" value="" />'."\n".
4119: '<input type="hidden" name="startdate_year" value="" />'."\n".
4120: '<input type="hidden" name="startdate_hour" value="" />'."\n".
4121: '<input type="hidden" name="startdate_minute" value="" />'."\n".
4122: '<input type="hidden" name="startdate_second" value="" />'."\n".
4123: '<input type="hidden" name="enddate_month" value="" />'."\n".
4124: '<input type="hidden" name="enddate_day" value="" />'."\n".
4125: '<input type="hidden" name="enddate_year" value="" />'."\n".
4126: '<input type="hidden" name="enddate_hour" value="" />'."\n".
4127: '<input type="hidden" name="enddate_minute" value="" />'."\n".
1.56 raeburn 4128: '<input type="hidden" name="enddate_second" value="" />'."\n".
4129: '<input type="hidden" name="no_end_date" value="" />'."\n";
1.11 raeburn 4130: if ($context eq 'course') {
4131: $output .= '<input type="hidden" name="makedatesdefault" value="" />'."\n";
4132: }
4133: }
4134: if ($choices{'sections'}) {
1.91 bisitz 4135: $output .= '<input type="hidden" name="retainsec" value="" />'."\n".
4136: '<input type="hidden" name="newsecs" value="" />'."\n";
1.11 raeburn 4137: }
4138: }
4139: return $output;
4140: }
4141:
4142: sub date_section_javascript {
4143: my ($context,$setting) = @_;
1.49 raeburn 4144: my $title = 'Date_And_Section_Selector';
1.41 raeburn 4145: my %nopopup = &Apache::lonlocal::texthash (
4146: revoke => "Check the boxes for any users for whom roles are to be revoked, and click 'Proceed'",
4147: delete => "Check the boxes for any users for whom roles are to be deleted, and click 'Proceed'",
4148: none => "Choose an action to take for selected users",
4149: );
1.96 bisitz 4150: my $output = <<"ENDONE";
4151: <script type="text/javascript">
4152: // <![CDATA[
1.41 raeburn 4153: function opendatebrowser(callingform,formname,calledby) {
1.11 raeburn 4154: var bulkaction = callingform.bulkaction.options[callingform.bulkaction.selectedIndex].value;
4155: var url = '/adm/createuser?';
4156: var type = '';
4157: var showrole = callingform.showrole.options[callingform.showrole.selectedIndex].value;
4158: ENDONE
4159: if ($context eq 'domain') {
4160: $output .= '
4161: type = callingform.roletype.options[callingform.roletype.selectedIndex].value;
4162: ';
4163: }
4164: my $width= '700';
4165: my $height = '400';
4166: $output .= <<"ENDTWO";
4167: url += 'action=dateselect&callingform=' + formname +
4168: '&roletype='+type+'&showrole='+showrole +'&bulkaction='+bulkaction;
4169: var title = '$title';
4170: var options = 'scrollbars=1,resizable=1,menubar=0';
4171: options += ',width=$width,height=$height';
4172: stdeditbrowser = open(url,title,options,'1');
4173: stdeditbrowser.focus();
4174: }
1.96 bisitz 4175: // ]]>
1.11 raeburn 4176: </script>
4177: ENDTWO
4178: return $output;
4179: }
4180:
4181: sub date_section_selector {
1.150 raeburn 4182: my ($context,$permission,$crstype,$showcredits) = @_;
1.11 raeburn 4183: my $callingform = $env{'form.callingform'};
4184: my $formname = 'dateselect';
4185: my $groupslist = &get_groupslist();
1.150 raeburn 4186: my $sec_js =
4187: &setsections_javascript($formname,$groupslist,undef,undef,$crstype,
4188: $showcredits);
1.11 raeburn 4189: my $output = <<"END";
4190: <script type="text/javascript">
1.96 bisitz 4191: // <![CDATA[
1.11 raeburn 4192:
4193: $sec_js
4194:
4195: function saveselections(formname) {
4196:
4197: END
4198: if ($env{'form.bulkaction'} eq 'chgsec') {
4199: $output .= <<"END";
1.40 raeburn 4200: if (formname.retainsec.length > 1) {
4201: for (var i=0; i<formname.retainsec.length; i++) {
4202: if (formname.retainsec[i].checked == true) {
4203: opener.document.$callingform.retainsec.value = formname.retainsec[i].value;
4204: }
4205: }
4206: } else {
4207: opener.document.$callingform.retainsec.value = formname.retainsec.value;
4208: }
1.103 raeburn 4209: setSections(formname,'$crstype');
1.11 raeburn 4210: if (seccheck == 'ok') {
4211: opener.document.$callingform.newsecs.value = formname.sections.value;
1.205 raeburn 4212: } else {
4213: return;
1.11 raeburn 4214: }
4215: END
4216: } else {
4217: if ($context eq 'course') {
4218: if (($env{'form.bulkaction'} eq 'reenable') ||
4219: ($env{'form.bulkaction'} eq 'activate') ||
4220: ($env{'form.bulkaction'} eq 'chgdates')) {
1.26 raeburn 4221: if ($env{'request.course.sec'} eq '') {
4222: $output .= <<"END";
1.11 raeburn 4223:
4224: if (formname.makedatesdefault.checked == true) {
4225: opener.document.$callingform.makedatesdefault.value = 1;
4226: }
4227: else {
4228: opener.document.$callingform.makedatesdefault.value = 0;
4229: }
4230:
4231: END
1.26 raeburn 4232: }
1.11 raeburn 4233: }
4234: }
4235: $output .= <<"END";
4236: opener.document.$callingform.startdate_month.value = formname.startdate_month.options[formname.startdate_month.selectedIndex].value;
4237: opener.document.$callingform.startdate_day.value = formname.startdate_day.value;
4238: opener.document.$callingform.startdate_year.value = formname.startdate_year.value;
4239: opener.document.$callingform.startdate_hour.value = formname.startdate_hour.options[formname.startdate_hour.selectedIndex].value;
4240: opener.document.$callingform.startdate_minute.value = formname.startdate_minute.value;
4241: opener.document.$callingform.startdate_second.value = formname.startdate_second.value;
4242: opener.document.$callingform.enddate_month.value = formname.enddate_month.options[formname.enddate_month.selectedIndex].value;
4243: opener.document.$callingform.enddate_day.value = formname.enddate_day.value;
4244: opener.document.$callingform.enddate_year.value = formname.enddate_year.value;
4245: opener.document.$callingform.enddate_hour.value = formname.enddate_hour.options[formname.enddate_hour.selectedIndex].value;
4246: opener.document.$callingform.enddate_minute.value = formname.enddate_minute.value;
4247: opener.document.$callingform.enddate_second.value = formname.enddate_second.value;
1.56 raeburn 4248: if (formname.no_end_date.checked) {
4249: opener.document.$callingform.no_end_date.value = '1';
4250: } else {
4251: opener.document.$callingform.no_end_date.value = '0';
4252: }
1.11 raeburn 4253: END
4254: }
1.56 raeburn 4255: my $verify_action_js = &bulkaction_javascript($callingform,'popup');
4256: $output .= <<"ENDJS";
4257: verify_action('actionlist');
1.11 raeburn 4258: }
1.56 raeburn 4259:
4260: $verify_action_js
4261:
1.96 bisitz 4262: // ]]>
1.11 raeburn 4263: </script>
1.56 raeburn 4264: ENDJS
1.11 raeburn 4265: my %lt = &Apache::lonlocal::texthash (
4266: chac => 'Access dates to apply for selected users',
4267: chse => 'Changes in section affiliation to apply to selected users',
1.118 raeburn 4268: 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.',
4269: forn => 'For a course role that is not "student", users may have roles in more than one section at a time.',
4270: reta => "Retain each user's current section affiliations?",
1.103 raeburn 4271: dnap => '(Does not apply to student roles).',
1.11 raeburn 4272: );
4273: my ($date_items,$headertext);
4274: if ($env{'form.bulkaction'} eq 'chgsec') {
4275: $headertext = $lt{'chse'};
4276: } else {
4277: $headertext = $lt{'chac'};
4278: my $starttime;
4279: if (($env{'form.bulkaction'} eq 'activate') ||
4280: ($env{'form.bulkaction'} eq 'reenable')) {
4281: $starttime = time;
4282: }
4283: $date_items = &date_setting_table($starttime,undef,$context,
1.21 raeburn 4284: $env{'form.bulkaction'},$formname,
1.101 raeburn 4285: $permission,$crstype);
1.11 raeburn 4286: }
4287: $output .= '<h3>'.$headertext.'</h3>'.
1.118 raeburn 4288: '<form name="'.$formname.'" method="post" action="">'."\n".
1.11 raeburn 4289: $date_items;
4290: if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
1.17 raeburn 4291: my ($cnum,$cdom) = &get_course_identity();
1.103 raeburn 4292: if ($crstype eq 'Community') {
1.118 raeburn 4293: $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.');
4294: $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 4295: $lt{'dnap'} = &mt('(Does not apply to member roles).');
4296: }
1.11 raeburn 4297: my $info;
4298: if ($env{'form.showrole'} eq 'st') {
4299: $output .= '<p>'.$lt{'fors'}.'</p>';
1.26 raeburn 4300: } elsif ($env{'form.showrole'} eq 'Any') {
1.11 raeburn 4301: $output .= '<p>'.$lt{'fors'}.'</p>'.
4302: '<p>'.$lt{'forn'}.' ';
4303: $info = $lt{'reta'};
4304: } else {
4305: $output .= '<p>'.$lt{'forn'}.' ';
4306: $info = $lt{'reta'};
4307: }
4308: if ($info) {
4309: $info .= '<span class="LC_nobreak">'.
4310: '<label><input type="radio" name="retainsec" value="1" '.
4311: 'checked="checked" />'.&mt('Yes').'</label> '.
4312: '<label><input type="radio" name="retainsec" value="0" />'.
4313: &mt('No').'</label></span>';
4314: if ($env{'form.showrole'} eq 'Any') {
4315: $info .= '<br />'.$lt{'dnap'};
4316: }
4317: $info .= '</p>';
4318: } else {
4319: $info = '<input type="hidden" name="retainsec" value="0" />';
4320: }
1.21 raeburn 4321: my $rowtitle = &mt('New section to assign');
1.150 raeburn 4322: my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,
4323: $permission,$context,'chgsec',$crstype);
1.11 raeburn 4324: $output .= $info.$secbox;
4325: }
4326: $output .= '<p>'.
1.81 schafran 4327: '<input type="button" name="dateselection" value="'.&mt('Save').'" onclick="javascript:saveselections(this.form)" /></p>'."\n".
1.11 raeburn 4328: '</form>';
4329: return $output;
4330: }
4331:
1.17 raeburn 4332: sub section_picker {
1.150 raeburn 4333: my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode,$crstype,
4334: $showcredits,$credits) = @_;
1.17 raeburn 4335: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
4336: my $sections_select .= &course_sections(\%sections_count,$role);
1.118 raeburn 4337: my $secbox = '<div>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
1.17 raeburn 4338: if ($mode eq 'upload') {
4339: my ($options,$cb_script,$coursepick) =
1.150 raeburn 4340: &default_role_selector($context,1,$crstype,$showcredits);
1.59 bisitz 4341: $secbox .= &Apache::lonhtmlcommon::row_title(&mt('role'),'LC_oddrow_value').
1.17 raeburn 4342: $options. &Apache::lonhtmlcommon::row_closure(1)."\n";
4343: }
4344: $secbox .= &Apache::lonhtmlcommon::row_title($rowtitle,'LC_oddrow_value')."\n";
4345: if ($env{'request.course.sec'} eq '') {
4346: $secbox .= '<table class="LC_createuser"><tr class="LC_section_row">'."\n".
4347: '<td align="center">'.&mt('Existing sections')."\n".
4348: '<br />'.$sections_select.'</td><td align="center">'.
4349: &mt('New section').'<br />'."\n".
1.118 raeburn 4350: '<input type="text" name="newsec" size="15" value="" />'."\n".
1.17 raeburn 4351: '<input type="hidden" name="sections" value="" />'."\n".
4352: '</td></tr></table>'."\n";
4353: } else {
1.149 raeburn 4354: $secbox .= '<input type="hidden" name="sections" value="'.
1.17 raeburn 4355: $env{'request.course.sec'}.'" />'.
4356: $env{'request.course.sec'};
4357: }
1.150 raeburn 4358: $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n";
4359: unless ($mode eq 'chgsec') {
4360: if ($showcredits) {
4361: $secbox .=
4362: &Apache::lonhtmlcommon::row_title(&mt('credits (students)'),
4363: 'LC_evenrow_value')."\n".
4364: '<input type="text" name="credits" size="3" value="'.$credits.'" />'."\n".
4365: &Apache::lonhtmlcommon::row_closure(1)."\n";
4366: }
4367: }
4368: $secbox .= &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.17 raeburn 4369: return $secbox;
4370: }
4371:
1.2 raeburn 4372: sub results_header_row {
1.102 raeburn 4373: my ($rolefilter,$statusmode,$context,$permission,$mode,$crstype) = @_;
1.5 raeburn 4374: my ($description,$showfilter);
4375: if ($rolefilter ne 'Any') {
4376: $showfilter = $rolefilter;
4377: }
1.2 raeburn 4378: if ($context eq 'course') {
1.24 raeburn 4379: if ($mode eq 'csv' || $mode eq 'excel') {
1.102 raeburn 4380: if ($crstype eq 'Community') {
4381: $description = &mt('Community - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
4382: } else {
4383: $description = &mt('Course - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
4384: }
1.24 raeburn 4385: }
1.2 raeburn 4386: if ($statusmode eq 'Expired') {
1.102 raeburn 4387: if ($crstype eq 'Community') {
4388: $description .= &mt('Users in community with expired [_1] roles',$showfilter);
4389: } else {
4390: $description .= &mt('Users in course with expired [_1] roles',$showfilter);
4391: }
1.11 raeburn 4392: } elsif ($statusmode eq 'Future') {
1.102 raeburn 4393: if ($crstype eq 'Community') {
4394: $description .= &mt('Users in community with future [_1] roles',$showfilter);
4395: } else {
4396: $description .= &mt('Users in course with future [_1] roles',$showfilter);
4397: }
1.2 raeburn 4398: } elsif ($statusmode eq 'Active') {
1.102 raeburn 4399: if ($crstype eq 'Community') {
4400: $description .= &mt('Users in community with active [_1] roles',$showfilter);
4401: } else {
4402: $description .= &mt('Users in course with active [_1] roles',$showfilter);
4403: }
1.2 raeburn 4404: } else {
4405: if ($rolefilter eq 'Any') {
1.102 raeburn 4406: if ($crstype eq 'Community') {
4407: $description .= &mt('All users in community');
4408: } else {
4409: $description .= &mt('All users in course');
4410: }
1.2 raeburn 4411: } else {
1.102 raeburn 4412: if ($crstype eq 'Community') {
4413: $description .= &mt('All users in community with [_1] roles',$rolefilter);
4414: } else {
4415: $description .= &mt('All users in course with [_1] roles',$rolefilter);
4416: }
1.2 raeburn 4417: }
4418: }
1.33 raeburn 4419: my $constraint;
1.26 raeburn 4420: my $viewablesec = &viewable_section($permission);
4421: if ($viewablesec ne '') {
1.15 raeburn 4422: if ($env{'form.showrole'} eq 'st') {
1.33 raeburn 4423: $constraint = &mt('only users in section "[_1]"',$viewablesec);
1.103 raeburn 4424: } elsif (($env{'form.showrole'} ne 'cc') && ($env{'form.showrole'} ne 'co')) {
1.33 raeburn 4425: $constraint = &mt('only users affiliated with no section or section "[_1]"',$viewablesec);
4426: }
4427: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
4428: if ($env{'form.grpfilter'} eq 'none') {
4429: $constraint .= &mt(' and not in any group');
4430: } else {
4431: $constraint .= &mt(' and members of group: "[_1]"',$env{'form.grpfilter'});
4432: }
4433: }
4434: } else {
4435: if (($env{'form.secfilter'} ne 'all') && ($env{'form.secfilter'} ne '')) {
4436: if ($env{'form.secfilter'} eq 'none') {
4437: $constraint = &mt('only users affiliated with no section');
4438: } else {
4439: $constraint = &mt('only users affiliated with section "[_1]"',$env{'form.secfilter'});
4440: }
4441: }
4442: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
4443: if ($env{'form.grpfilter'} eq 'none') {
4444: if ($constraint eq '') {
4445: $constraint = &mt('only users not in any group');
4446: } else {
4447: $constraint .= &mt(' and also not in any group');
4448: }
4449: } else {
4450: if ($constraint eq '') {
4451: $constraint = &mt('only members of group: "[_1]"',$env{'form.grpfilter'});
4452: } else {
4453: $constraint .= &mt(' and also members of group: "[_1]"'.$env{'form.grpfilter'});
4454: }
4455: }
1.15 raeburn 4456: }
4457: }
1.33 raeburn 4458: if ($constraint ne '') {
4459: $description .= ' ('.$constraint.')';
4460: }
1.13 raeburn 4461: } elsif ($context eq 'author') {
1.222 raeburn 4462: my ($auname,$audom);
4463: if ($env{'request.role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)$}) {
4464: ($audom,$auname) = ($1,$2);
4465: } else {
4466: ($audom,$auname) = ($env{'user.domain'},$env{'user.name'});
4467: }
1.14 raeburn 4468: $description =
1.73 bisitz 4469: &mt('Author space for [_1]'
4470: ,'<span class="LC_cusr_emph">'
1.222 raeburn 4471: .&Apache::loncommon::plainname($auname,$audom)
1.73 bisitz 4472: .'</span>')
4473: .': ';
1.2 raeburn 4474: if ($statusmode eq 'Expired') {
1.5 raeburn 4475: $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
1.2 raeburn 4476: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4477: $description .= &mt('Co-authors with future [_1] roles',$showfilter);
1.2 raeburn 4478: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4479: $description .= &mt('Co-authors with active [_1] roles',$showfilter);
1.2 raeburn 4480: } else {
4481: if ($rolefilter eq 'Any') {
1.5 raeburn 4482: $description .= &mt('All co-authors');
1.2 raeburn 4483: } else {
4484: $description .= &mt('All co-authors with [_1] roles',$rolefilter);
4485: }
4486: }
4487: } elsif ($context eq 'domain') {
4488: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.73 bisitz 4489: $description = &mt('Domain - [_1]:',$domdesc).' ';
1.2 raeburn 4490: if ($env{'form.roletype'} eq 'domain') {
4491: if ($statusmode eq 'Expired') {
1.5 raeburn 4492: $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
1.2 raeburn 4493: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4494: $description .= &mt('Users in domain with future [_1] roles',$showfilter);
1.2 raeburn 4495: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4496: $description .= &mt('Users in domain with active [_1] roles',$showfilter);
1.2 raeburn 4497: } else {
4498: if ($rolefilter eq 'Any') {
1.5 raeburn 4499: $description .= &mt('All users in domain');
1.2 raeburn 4500: } else {
4501: $description .= &mt('All users in domain with [_1] roles',$rolefilter);
4502: }
4503: }
1.13 raeburn 4504: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 4505: if ($statusmode eq 'Expired') {
1.5 raeburn 4506: $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
1.2 raeburn 4507: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4508: $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
1.2 raeburn 4509: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4510: $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
1.2 raeburn 4511: } else {
4512: if ($rolefilter eq 'Any') {
1.5 raeburn 4513: $description .= &mt('All users with co-author roles in domain',$showfilter);
1.2 raeburn 4514: } else {
1.116 bisitz 4515: $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
1.2 raeburn 4516: }
4517: }
1.102 raeburn 4518: } elsif (($env{'form.roletype'} eq 'course') ||
4519: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 4520: my $coursefilter = $env{'form.coursepick'};
1.102 raeburn 4521: if ($env{'form.roletype'} eq 'course') {
4522: if ($coursefilter eq 'category') {
4523: my $instcode = &instcode_from_coursefilter();
4524: if ($instcode eq '.') {
4525: $description .= &mt('All courses in domain').' - ';
4526: } else {
4527: $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
4528: }
4529: } elsif ($coursefilter eq 'selected') {
4530: $description .= &mt('Selected courses in domain').' - ';
4531: } elsif ($coursefilter eq 'all') {
1.2 raeburn 4532: $description .= &mt('All courses in domain').' - ';
4533: }
1.102 raeburn 4534: } elsif ($env{'form.roletype'} eq 'community') {
4535: if ($coursefilter eq 'selected') {
4536: $description .= &mt('Selected communities in domain').' - ';
4537: } elsif ($coursefilter eq 'all') {
4538: $description .= &mt('All communities in domain').' - ';
4539: }
1.2 raeburn 4540: }
4541: if ($statusmode eq 'Expired') {
1.5 raeburn 4542: $description .= &mt('users with expired [_1] roles',$showfilter);
1.2 raeburn 4543: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4544: $description .= &mt('users with future [_1] roles',$showfilter);
1.2 raeburn 4545: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4546: $description .= &mt('users with active [_1] roles',$showfilter);
1.2 raeburn 4547: } else {
4548: if ($rolefilter eq 'Any') {
4549: $description .= &mt('all users');
4550: } else {
4551: $description .= &mt('users with [_1] roles',$rolefilter);
4552: }
4553: }
4554: }
4555: }
4556: return $description;
4557: }
1.22 raeburn 4558:
4559: sub viewable_section {
4560: my ($permission) = @_;
4561: my $viewablesec;
4562: if (ref($permission) eq 'HASH') {
4563: if (exists($permission->{'view_section'})) {
4564: $viewablesec = $permission->{'view_section'};
4565: } elsif (exists($permission->{'cusr_section'})) {
4566: $viewablesec = $permission->{'cusr_section'};
4567: }
4568: }
4569: return $viewablesec;
4570: }
4571:
1.2 raeburn 4572:
1.1 raeburn 4573: #################################################
4574: #################################################
4575: sub show_drop_list {
1.101 raeburn 4576: my ($r,$classlist,$nosort,$permission,$crstype) = @_;
1.29 raeburn 4577: my $cid = $env{'request.course.id'};
1.17 raeburn 4578: my ($cnum,$cdom) = &get_course_identity($cid);
1.1 raeburn 4579: if (! exists($env{'form.sortby'})) {
4580: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
4581: ['sortby']);
4582: }
4583: my $sortby = $env{'form.sortby'};
4584: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
4585: $sortby = 'username';
4586: }
4587: my $action = "drop";
1.17 raeburn 4588: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
1.1 raeburn 4589: $r->print(<<END);
4590: <input type="hidden" name="sortby" value="$sortby" />
4591: <input type="hidden" name="action" value="$action" />
4592: <input type="hidden" name="state" value="done" />
1.17 raeburn 4593: <script type="text/javascript" language="Javascript">
1.96 bisitz 4594: // <![CDATA[
1.17 raeburn 4595: $check_uncheck_js
1.96 bisitz 4596: // ]]>
1.1 raeburn 4597: </script>
1.86 bisitz 4598: <input type="hidden" name="phase" value="four" />
1.1 raeburn 4599: END
1.30 raeburn 4600: my ($indexhash,$keylist) = &make_keylist_array();
4601: my $studentcount = 0;
4602: if (ref($classlist) eq 'HASH') {
4603: foreach my $student (keys(%{$classlist})) {
4604: my $sdata = $classlist->{$student};
4605: my $status = $sdata->[$indexhash->{'status'}];
4606: my $section = $sdata->[$indexhash->{'section'}];
4607: if ($status ne 'Active') {
4608: delete($classlist->{$student});
4609: next;
4610: }
4611: if ($env{'request.course.sec'} ne '') {
4612: if ($section ne $env{'request.course.sec'}) {
4613: delete($classlist->{$student});
4614: next;
4615: }
4616: }
4617: $studentcount ++;
4618: }
4619: }
4620: if (!$studentcount) {
1.143 bisitz 4621: my $msg = '';
1.101 raeburn 4622: if ($crstype eq 'Community') {
1.143 bisitz 4623: $msg = &mt('There are no members to drop.');
1.101 raeburn 4624: } else {
1.143 bisitz 4625: $msg = &mt('There are no students to drop.');
1.101 raeburn 4626: }
1.143 bisitz 4627: $r->print('<p class="LC_info">'.$msg.'</p>');
1.30 raeburn 4628: return;
4629: }
4630: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
4631: $classlist,$keylist,$cdom,$cnum);
4632: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
4633: 'dom' => "domain",
1.162 bisitz 4634: 'id' => "ID",
1.30 raeburn 4635: 'sn' => "student name",
1.101 raeburn 4636: 'mn' => "member name",
1.30 raeburn 4637: 'sec' => "section",
4638: 'start' => "start date",
4639: 'end' => "end date",
4640: 'groups' => "active groups",
4641: );
1.101 raeburn 4642: my $nametitle = $lt{'sn'};
4643: if ($crstype eq 'Community') {
4644: $nametitle = $lt{'mn'};
4645: }
1.1 raeburn 4646: if ($nosort) {
1.17 raeburn 4647: $r->print(&Apache::loncommon::start_data_table().
4648: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 4649: $r->print(<<END);
4650: <th> </th>
4651: <th>$lt{'usrn'}</th>
4652: <th>$lt{'dom'}</th>
1.162 bisitz 4653: <th>$lt{'id'}</th>
1.101 raeburn 4654: <th>$nametitle</th>
1.1 raeburn 4655: <th>$lt{'sec'}</th>
4656: <th>$lt{'start'}</th>
4657: <th>$lt{'end'}</th>
4658: <th>$lt{'groups'}</th>
4659: END
1.17 raeburn 4660: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 4661: } else {
1.17 raeburn 4662: $r->print(&Apache::loncommon::start_data_table().
4663: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 4664: $r->print(<<END);
1.17 raeburn 4665: <th> </th>
1.1 raeburn 4666: <th>
1.162 bisitz 4667: <a href="/adm/createuser?action=$action&sortby=username">$lt{'usrn'}</a>
1.1 raeburn 4668: </th><th>
1.162 bisitz 4669: <a href="/adm/createuser?action=$action&sortby=domain">$lt{'dom'}</a>
1.1 raeburn 4670: </th><th>
1.162 bisitz 4671: <a href="/adm/createuser?action=$action&sortby=id">$lt{'id'}</a>
1.1 raeburn 4672: </th><th>
1.162 bisitz 4673: <a href="/adm/createuser?action=$action&sortby=fullname">$nametitle</a>
1.1 raeburn 4674: </th><th>
1.162 bisitz 4675: <a href="/adm/createuser?action=$action&sortby=section">$lt{'sec'}</a>
1.1 raeburn 4676: </th><th>
1.162 bisitz 4677: <a href="/adm/createuser?action=$action&sortby=start">$lt{'start'}</a>
1.1 raeburn 4678: </th><th>
1.162 bisitz 4679: <a href="/adm/createuser?action=$action&sortby=end">$lt{'end'}</a>
1.1 raeburn 4680: </th><th>
1.162 bisitz 4681: <a href="/adm/createuser?action=$action&sortby=groups">$lt{'groups'}</a>
1.1 raeburn 4682: </th>
4683: END
1.17 raeburn 4684: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 4685: }
4686: #
4687: # Sort the students
1.30 raeburn 4688: my $index = $indexhash->{$sortby};
4689: my $second = $indexhash->{'username'};
4690: my $third = $indexhash->{'domain'};
1.1 raeburn 4691: my @Sorted_Students = sort {
4692: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
4693: ||
4694: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
4695: ||
4696: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
1.30 raeburn 4697: } (keys(%{$classlist}));
1.1 raeburn 4698: foreach my $student (@Sorted_Students) {
4699: my $error;
4700: my $sdata = $classlist->{$student};
1.30 raeburn 4701: my $username = $sdata->[$indexhash->{'username'}];
4702: my $domain = $sdata->[$indexhash->{'domain'}];
4703: my $section = $sdata->[$indexhash->{'section'}];
4704: my $name = $sdata->[$indexhash->{'fullname'}];
4705: my $id = $sdata->[$indexhash->{'id'}];
4706: my $start = $sdata->[$indexhash->{'start'}];
4707: my $end = $sdata->[$indexhash->{'end'}];
1.1 raeburn 4708: my $groups = $classgroups->{$student};
4709: my $active_groups;
4710: if (ref($groups->{active}) eq 'HASH') {
4711: $active_groups = join(', ',keys(%{$groups->{'active'}}));
4712: }
4713: if (! defined($start) || $start == 0) {
4714: $start = &mt('none');
4715: } else {
4716: $start = &Apache::lonlocal::locallocaltime($start);
4717: }
4718: if (! defined($end) || $end == 0) {
4719: $end = &mt('none');
4720: } else {
4721: $end = &Apache::lonlocal::locallocaltime($end);
4722: }
1.17 raeburn 4723: my $studentkey = $student.':'.$section;
1.30 raeburn 4724: my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$indexhash->{'start'}].'" />';
1.1 raeburn 4725: #
4726: $r->print(&Apache::loncommon::start_data_table_row());
4727: $r->print(<<"END");
1.86 bisitz 4728: <td><input type="checkbox" name="droplist" value="$studentkey" /></td>
1.1 raeburn 4729: <td>$username</td>
4730: <td>$domain</td>
4731: <td>$id</td>
4732: <td>$name</td>
4733: <td>$section</td>
1.29 raeburn 4734: <td>$start $startitem</td>
1.1 raeburn 4735: <td>$end</td>
4736: <td>$active_groups</td>
4737: END
4738: $r->print(&Apache::loncommon::end_data_table_row());
4739: }
4740: $r->print(&Apache::loncommon::end_data_table().'<br />');
4741: %lt=&Apache::lonlocal::texthash(
1.29 raeburn 4742: 'dp' => "Drop Students",
1.101 raeburn 4743: 'dm' => "Drop Members",
1.1 raeburn 4744: 'ca' => "check all",
4745: 'ua' => "uncheck all",
4746: );
1.101 raeburn 4747: my $btn = $lt{'dp'};
4748: if ($crstype eq 'Community') {
4749: $btn = $lt{'dm'};
4750: }
1.1 raeburn 4751: $r->print(<<"END");
1.89 bisitz 4752: <p>
1.86 bisitz 4753: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)" />
4754: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)" />
1.89 bisitz 4755: </p>
4756: <p>
1.101 raeburn 4757: <input type="submit" value="$btn" />
1.89 bisitz 4758: </p>
1.1 raeburn 4759: END
4760: return;
4761: }
4762:
4763: #
4764: # Print out the initial form to get the file containing a list of users
4765: #
4766: sub print_first_users_upload_form {
4767: my ($r,$context) = @_;
4768: my $str;
1.86 bisitz 4769: $str = '<input type="hidden" name="phase" value="two" />';
1.1 raeburn 4770: $str .= '<input type="hidden" name="action" value="upload" />';
1.101 raeburn 4771: $str .= '<input type="hidden" name="state" value="got_file" />';
1.95 bisitz 4772:
1.147 bisitz 4773: $str .= &Apache::grades::checkforfile_js();
4774:
1.85 bisitz 4775: $str .= '<h2>'.&mt('Upload a file containing information about users').'</h2>'."\n";
1.95 bisitz 4776:
4777: # Excel and CSV Help
1.147 bisitz 4778: $str .= '<div class="LC_columnSection">'
1.95 bisitz 4779: .&Apache::loncommon::help_open_topic("Course_Create_Class_List",
4780: &mt("How do I create a users list from a spreadsheet"))
1.147 bisitz 4781: .' '.&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1.95 bisitz 4782: &mt("How do I create a CSV file from a spreadsheet"))
1.147 bisitz 4783: ."</div>\n";
1.95 bisitz 4784: $str .= &Apache::lonhtmlcommon::start_pick_box()
1.103 raeburn 4785: .&Apache::lonhtmlcommon::row_title(&mt('File'));
4786: if (&Apache::lonlocal::current_language() ne 'en') {
4787: if ($context eq 'course') {
4788: $str .= '<p class="LC_info">'."\n"
4789: .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n"
4790: .'</p>'."\n";
4791: }
4792: }
4793: $str .= &Apache::loncommon::upfile_select_html()
1.95 bisitz 4794: .&Apache::lonhtmlcommon::row_closure()
4795: .&Apache::lonhtmlcommon::row_title(
4796: '<label for="noFirstLine">'
4797: .&mt('Ignore First Line')
4798: .'</label>')
4799: .'<input type="checkbox" name="noFirstLine" id="noFirstLine" />'
4800: .&Apache::lonhtmlcommon::row_closure(1)
4801: .&Apache::lonhtmlcommon::end_pick_box();
4802:
4803: $str .= '<p>'
1.198 raeburn 4804: .'<input type="button" name="fileupload" value="'.&mt('Next').'"'
1.147 bisitz 4805: .' onclick="javascript:checkUpload(this.form);" />'
1.95 bisitz 4806: .'</p>';
4807:
1.1 raeburn 4808: $r->print($str);
4809: return;
4810: }
4811:
4812: # ================================================= Drop/Add from uploaded file
4813: sub upfile_drop_add {
1.150 raeburn 4814: my ($r,$context,$permission,$showcredits) = @_;
1.189 raeburn 4815: my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'});
4816: if ($datatoken ne '') {
4817: &Apache::loncommon::load_tmp_file($r,$datatoken);
4818: }
1.1 raeburn 4819: my @userdata=&Apache::loncommon::upfile_record_sep();
4820: if($env{'form.noFirstLine'}){shift(@userdata);}
4821: my @keyfields = split(/\,/,$env{'form.keyfields'});
4822: my %fields=();
4823: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
4824: if ($env{'form.upfile_associate'} eq 'reverse') {
4825: if ($env{'form.f'.$i} ne 'none') {
4826: $fields{$keyfields[$i]}=$env{'form.f'.$i};
4827: }
4828: } else {
4829: $fields{$env{'form.f'.$i}}=$keyfields[$i];
4830: }
4831: }
4832: #
4833: # Store the field choices away
1.150 raeburn 4834: my @storefields = qw/username names fname mname lname gen id
4835: sec ipwd email role domain inststatus/;
4836: if ($showcredits) {
4837: push (@storefields,'credits');
4838: }
4839: my %fieldstype;
4840: foreach my $field (@storefields) {
1.1 raeburn 4841: $env{'form.'.$field.'_choice'}=$fields{$field};
1.150 raeburn 4842: $fieldstype{$field.'_choice'} = 'scalar';
1.1 raeburn 4843: }
1.150 raeburn 4844: &Apache::loncommon::store_course_settings('enrollment_upload',\%fieldstype);
1.220 raeburn 4845: my ($cid,$crstype,$setting,$crsdom,$crsnum,$oldcrsuserdoms,%emptyok);
1.101 raeburn 4846: if ($context eq 'domain') {
4847: $setting = $env{'form.roleaction'};
1.220 raeburn 4848: if (exists($fields{'names'})) {
4849: map { $emptyok{$_} = 1; } ('lastname','firstname','middlename');
4850: } else {
4851: if (exists($fields{'lname'})) {
4852: $emptyok{'lastname'} = 1;
4853: }
4854: if (exists($fields{'fname'})) {
4855: $emptyok{'firstname'} = 1;
4856: }
4857: if (exists($fields{'mname'})) {
4858: $emptyok{'middlename'} = 1;
4859: }
4860: }
4861: if (exists($fields{'gen'})) {
4862: $emptyok{'generation'} = 1;
4863: }
1.101 raeburn 4864: }
4865: if ($env{'request.course.id'} ne '') {
4866: $cid = $env{'request.course.id'};
4867: $crstype = &Apache::loncommon::course_type();
1.185 raeburn 4868: $crsdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.212 raeburn 4869: $crsnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.101 raeburn 4870: } elsif ($setting eq 'course') {
4871: if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
4872: $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
4873: $crstype = &Apache::loncommon::course_type($cid);
1.185 raeburn 4874: $crsdom = $env{'form.dcdomain'};
1.212 raeburn 4875: $crsnum = $env{'form.dccourse'};
1.217 raeburn 4876: if (exists($env{'course.'.$cid.'.internal.userdomains'})) {
4877: $oldcrsuserdoms = 1;
4878: }
4879: my %coursedesc = &Apache::lonnet::coursedescription($cid,{ one_time => 1 });
4880: $env{'course.'.$cid.'.internal.userdomains'} = $coursedesc{'internal.userdomains'};
1.101 raeburn 4881: }
4882: }
1.1 raeburn 4883: my ($startdate,$enddate) = &get_dates_from_form();
4884: if ($env{'form.makedatesdefault'}) {
1.101 raeburn 4885: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
1.1 raeburn 4886: }
4887: # Determine domain and desired host (home server)
1.57 raeburn 4888: my $defdom=$env{'request.role.domain'};
4889: my $domain;
4890: if ($env{'form.defaultdomain'} ne '') {
1.185 raeburn 4891: if (($context eq 'course') || ($setting eq 'course')) {
1.190 raeburn 4892: if ($env{'form.defaultdomain'} eq $crsdom) {
4893: $domain = $env{'form.defaultdomain'};
4894: } else {
1.185 raeburn 4895: if (&Apache::lonnet::will_trust('enroll',$crsdom,$env{'form.defaultdomain'})) {
4896: $domain = $env{'form.defaultdomain'};
4897: } else {
1.192 raeburn 4898: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4899: &mt('Enrollment of users not permitted for specified default domain: [_1].',
4900: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4901: return 'untrusted';
1.185 raeburn 4902: }
4903: }
4904: } elsif ($context eq 'author') {
1.190 raeburn 4905: if ($env{'form.defaultdomain'} eq $defdom) {
4906: $domain = $env{'form.defaultdomain'};
4907: } else {
1.185 raeburn 4908: if ((&Apache::lonnet::will_trust('othcoau',$defdom,$env{'form.defaultdomain'})) &&
1.186 raeburn 4909: (&Apache::lonnet::will_trust('coaurem',$env{'form.defaultdomain'},$defdom))) {
1.185 raeburn 4910: $domain = $env{'form.defaultdomain'};
4911: } else {
1.192 raeburn 4912: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4913: &mt('Addition of users not permitted for specified default domain: [_1].',
4914: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4915: return 'untrusted';
1.185 raeburn 4916: }
4917: }
4918: } elsif (($context eq 'domain') && ($setting eq 'domain')) {
1.190 raeburn 4919: if ($env{'form.defaultdomain'} eq $defdom) {
4920: $domain = $env{'form.defaultdomain'};
4921: } else {
1.185 raeburn 4922: if (&Apache::lonnet::will_trust('domroles',$defdom,$env{'form.defaultdomain'})) {
4923: $domain = $env{'form.defaultdomain'};
4924: } else {
1.192 raeburn 4925: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4926: &mt('Addition of users not permitted for specified default domain: [_1].',
4927: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4928: return 'untrusted';
1.185 raeburn 4929: }
4930: }
4931: }
1.57 raeburn 4932: } else {
4933: $domain = $defdom;
4934: }
1.1 raeburn 4935: my $desiredhost = $env{'form.lcserver'};
4936: if (lc($desiredhost) eq 'default') {
4937: $desiredhost = undef;
4938: } else {
1.57 raeburn 4939: my %home_servers = &Apache::lonnet::get_servers($defdom,'library');
1.1 raeburn 4940: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 4941: $r->print('<p class="LC_error">'.&mt('Error').': '.
4942: &mt('Invalid home server specified').'</p>');
4943: return 'invalidhome';
1.1 raeburn 4944: }
4945: }
4946: # Determine authentication mechanism
4947: my $changeauth;
4948: if ($context eq 'domain') {
4949: $changeauth = $env{'form.changeauth'};
4950: }
4951: my $amode = '';
4952: my $genpwd = '';
1.200 raeburn 4953: my @genpwdfail;
1.1 raeburn 4954: if ($env{'form.login'} eq 'krb') {
4955: $amode='krb';
4956: $amode.=$env{'form.krbver'};
4957: $genpwd=$env{'form.krbarg'};
4958: } elsif ($env{'form.login'} eq 'int') {
4959: $amode='internal';
4960: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
4961: $genpwd=$env{'form.intarg'};
1.200 raeburn 4962: @genpwdfail =
1.202 raeburn 4963: &Apache::loncommon::check_passwd_rules($domain,$genpwd);
1.1 raeburn 4964: }
4965: } elsif ($env{'form.login'} eq 'loc') {
4966: $amode='localauth';
4967: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
4968: $genpwd=$env{'form.locarg'};
4969: }
1.194 raeburn 4970: } elsif ($env{'form.login'} eq 'lti') {
4971: $amode='lti';
1.1 raeburn 4972: }
4973: if ($amode =~ /^krb/) {
4974: if (! defined($genpwd) || $genpwd eq '') {
1.193 raeburn 4975: $r->print('<span class="Error">'.
1.1 raeburn 4976: &mt('Unable to enroll users').' '.
4977: &mt('No Kerberos domain was specified.').'</span></p>');
4978: $amode = ''; # This causes the loop below to be skipped
4979: }
4980: }
1.150 raeburn 4981: my ($defaultsec,$defaultrole,$defaultcredits,$commoncredits);
1.1 raeburn 4982: if ($context eq 'domain') {
4983: if ($setting eq 'domain') {
4984: $defaultrole = $env{'form.defaultrole'};
4985: } elsif ($setting eq 'course') {
4986: $defaultrole = $env{'form.courserole'};
1.27 raeburn 4987: $defaultsec = $env{'form.sections'};
1.150 raeburn 4988: if ($showcredits) {
4989: $commoncredits = $env{'form.credits'};
4990: if ($crstype ne 'Community') {
4991: my %coursehash=&Apache::lonnet::coursedescription($cid);
4992: $defaultcredits = $coursehash{'internal.defaultcredits'};
4993: }
4994: }
1.149 raeburn 4995: }
1.13 raeburn 4996: } elsif ($context eq 'author') {
1.1 raeburn 4997: $defaultrole = $env{'form.defaultrole'};
1.27 raeburn 4998: } elsif ($context eq 'course') {
4999: $defaultrole = $env{'form.defaultrole'};
5000: $defaultsec = $env{'form.sections'};
1.150 raeburn 5001: if ($showcredits) {
5002: $commoncredits = $env{'form.credits'};
5003: $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
5004: }
1.1 raeburn 5005: }
1.27 raeburn 5006: # Check to see if user information can be changed
5007: my @userinfo = ('firstname','middlename','lastname','generation',
5008: 'permanentemail','id');
5009: my %canmodify;
5010: if (&Apache::lonnet::allowed('mau',$domain)) {
1.84 raeburn 5011: push(@userinfo,'inststatus');
1.27 raeburn 5012: foreach my $field (@userinfo) {
5013: $canmodify{$field} = 1;
5014: }
5015: }
5016: my (%userlist,%modifiable_fields,@poss_roles);
5017: my $secidx = &Apache::loncoursedata::CL_SECTION();
1.102 raeburn 5018: my @courseroles = &roles_by_context('course',1,$crstype);
1.27 raeburn 5019: if (!&Apache::lonnet::allowed('mau',$domain)) {
5020: if ($context eq 'course' || $context eq 'author') {
1.101 raeburn 5021: @poss_roles = &curr_role_permissions($context,'','',$crstype);
1.27 raeburn 5022: my @statuses = ('active','future');
5023: my ($indexhash,$keylist) = &make_keylist_array();
5024: my %info;
5025: foreach my $role (@poss_roles) {
5026: %{$modifiable_fields{$role}} = &can_modify_userinfo($context,$domain,
5027: \@userinfo,[$role]);
5028: }
5029: if ($context eq 'course') {
5030: my ($cnum,$cdom) = &get_course_identity();
5031: my $roster = &Apache::loncoursedata::get_classlist();
1.66 raeburn 5032: if (ref($roster) eq 'HASH') {
5033: %userlist = %{$roster};
5034: }
1.27 raeburn 5035: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
5036: \@statuses,\@poss_roles);
5037: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
5038: \%advrolehash,$permission);
5039: } elsif ($context eq 'author') {
5040: my %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
5041: \@statuses,\@poss_roles);
5042: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
5043: \%cstr_roles,$permission);
5044: }
5045: }
1.1 raeburn 5046: }
1.193 raeburn 5047: if ($datatoken eq '') {
5048: $r->print('<p class="LC_error">'.&mt('Error').': '.
5049: &mt('Invalid datatoken').'</p>');
5050: return 'missingdata';
5051: }
1.1 raeburn 5052: if ( $domain eq &LONCAPA::clean_domain($domain)
5053: && ($amode ne '')) {
5054: #######################################
5055: ## Add/Modify Users ##
5056: #######################################
5057: if ($context eq 'course') {
5058: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
1.13 raeburn 5059: } elsif ($context eq 'author') {
1.1 raeburn 5060: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
5061: } else {
5062: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
5063: }
1.87 bisitz 5064: $r->rflush;
1.212 raeburn 5065: my (%got_role_approvals,%got_instdoms,%process_by,%instdoms,
1.213 raeburn 5066: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
1.87 bisitz 5067:
1.1 raeburn 5068: my %counts = (
5069: user => 0,
5070: auth => 0,
5071: role => 0,
5072: );
5073: my $flushc=0;
5074: my %student=();
1.42 raeburn 5075: my (%curr_groups,@sections,@cleansec,$defaultwarn,$groupwarn);
1.1 raeburn 5076: my %userchg;
1.27 raeburn 5077: if ($context eq 'course' || $setting eq 'course') {
5078: if ($context eq 'course') {
5079: # Get information about course groups
5080: %curr_groups = &Apache::longroup::coursegroups();
5081: } elsif ($setting eq 'course') {
5082: if ($cid) {
5083: %curr_groups =
5084: &Apache::longroup::coursegroups($env{'form.dcdomain'},
5085: $env{'form.dccourse'});
5086: }
5087: }
5088: # determine section number
5089: if ($defaultsec =~ /,/) {
5090: push(@sections,split(/,/,$defaultsec));
5091: } else {
5092: push(@sections,$defaultsec);
5093: }
5094: # remove non alphanumeric values from section
5095: foreach my $item (@sections) {
5096: $item =~ s/\W//g;
5097: if ($item eq "none" || $item eq 'all') {
5098: $defaultwarn = &mt('Default section name [_1] could not be used as it is a reserved word.',$item);
5099: } elsif ($item ne '' && exists($curr_groups{$item})) {
5100: $groupwarn = &mt('Default section name "[_1]" is the name of a course group. Section names and group names must be distinct.',$item);
5101: } elsif ($item ne '') {
5102: push(@cleansec,$item);
5103: }
5104: }
5105: if ($defaultwarn) {
5106: $r->print($defaultwarn.'<br />');
5107: }
5108: if ($groupwarn) {
5109: $r->print($groupwarn.'<br />');
5110: }
1.1 raeburn 5111: }
1.124 raeburn 5112: my (%curr_rules,%got_rules,%alerts,%cancreate);
1.104 raeburn 5113: my %customroles = &my_custom_roles($crstype);
1.101 raeburn 5114: my @permitted_roles =
1.124 raeburn 5115: &roles_on_upload($context,$setting,$crstype,%customroles);
5116: my %longtypes = &Apache::lonlocal::texthash(
5117: official => 'Institutional',
5118: unofficial => 'Non-institutional',
5119: );
1.135 raeburn 5120: my $newuserdom = $env{'request.role.domain'};
5121: map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes);
1.1 raeburn 5122: # Get new users list
1.200 raeburn 5123: my (%existinguser,%userinfo,%disallow,%rulematch,%inst_results,%alerts,%checkuname,
5124: %showpasswdrules,$haspasswdmap);
1.171 raeburn 5125: my $counter = -1;
1.185 raeburn 5126: my (%willtrust,%trustchecked);
1.27 raeburn 5127: foreach my $line (@userdata) {
1.171 raeburn 5128: $counter ++;
1.42 raeburn 5129: my @secs;
1.27 raeburn 5130: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 5131: # Determine user name
1.128 raeburn 5132: $entries{$fields{'username'}} =~ s/^\s+|\s+$//g;
1.1 raeburn 5133: unless (($entries{$fields{'username'}} eq '') ||
5134: (!defined($entries{$fields{'username'}}))) {
5135: my ($fname, $mname, $lname,$gen) = ('','','','');
5136: if (defined($fields{'names'})) {
5137: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
5138: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
5139: } else {
5140: if (defined($fields{'fname'})) {
5141: $fname=$entries{$fields{'fname'}};
5142: }
5143: if (defined($fields{'mname'})) {
5144: $mname=$entries{$fields{'mname'}};
5145: }
5146: if (defined($fields{'lname'})) {
5147: $lname=$entries{$fields{'lname'}};
5148: }
5149: if (defined($fields{'gen'})) {
5150: $gen=$entries{$fields{'gen'}};
5151: }
5152: }
1.128 raeburn 5153:
1.1 raeburn 5154: if ($entries{$fields{'username'}}
5155: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
1.128 raeburn 5156: my $nowhitespace;
5157: if ($entries{$fields{'username'}} =~ /\s/) {
5158: $nowhitespace = ' - '.&mt('usernames may not contain spaces.');
5159: }
1.171 raeburn 5160: $disallow{$counter} =
1.157 bisitz 5161: &mt('Unacceptable username [_1] for user [_2] [_3] [_4] [_5]',
1.171 raeburn 5162: '"<b>'.$entries{$fields{'username'}}.'</b>"',
5163: $fname,$mname,$lname,$gen).$nowhitespace;
1.27 raeburn 5164: next;
1.1 raeburn 5165: } else {
1.129 raeburn 5166: $entries{$fields{'domain'}} =~ s/^\s+|\s+$//g;
1.71 droeschl 5167: if ($entries{$fields{'domain'}}
1.57 raeburn 5168: ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
1.171 raeburn 5169: $disallow{$counter} =
1.157 bisitz 5170: &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
1.171 raeburn 5171: '"<b>'.$entries{$fields{'domain'}}.'</b>"',
5172: $fname,$mname,$lname,$gen);
5173: next;
1.185 raeburn 5174: } elsif ($entries{$fields{'domain'}} ne $domain) {
5175: my $possdom = $entries{$fields{'domain'}};
5176: if ($context eq 'course' || $setting eq 'course') {
5177: unless ($trustchecked{$possdom}) {
5178: $willtrust{$possdom} = &Apache::lonnet::will_trust('enroll',$domain,$possdom);
5179: $trustchecked{$possdom} = 1;
5180: }
5181: } elsif ($context eq 'author') {
5182: unless ($trustchecked{$possdom}) {
5183: $willtrust{$possdom} = &Apache::lonnet::will_trust('othcoau',$domain,$possdom);
5184: }
5185: if ($willtrust{$possdom}) {
5186: $willtrust{$possdom} = &Apache::lonnet::will_trust('coaurem',$possdom,$domain);
5187: }
5188: }
5189: unless ($willtrust{$possdom}) {
5190: $disallow{$counter} =
5191: &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
5192: '"<b>'.$possdom.'</b>"',
5193: $fname,$mname,$lname,$gen);
5194: next;
5195: }
1.57 raeburn 5196: }
1.5 raeburn 5197: my $username = $entries{$fields{'username'}};
1.57 raeburn 5198: my $userdomain = $entries{$fields{'domain'}};
5199: if ($userdomain eq '') {
5200: $userdomain = $domain;
5201: }
1.27 raeburn 5202: if (defined($fields{'sec'})) {
5203: if (defined($entries{$fields{'sec'}})) {
1.42 raeburn 5204: $entries{$fields{'sec'}} =~ s/\W//g;
1.27 raeburn 5205: my $item = $entries{$fields{'sec'}};
5206: if ($item eq "none" || $item eq 'all') {
1.171 raeburn 5207: $disallow{$counter} =
5208: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a reserved word.',
5209: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item);
1.27 raeburn 5210: next;
5211: } elsif (exists($curr_groups{$item})) {
1.171 raeburn 5212: $disallow{$counter} =
5213: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a course group.',
5214: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item).' '.
5215: &mt('Section names and group names must be distinct.');
1.27 raeburn 5216: next;
5217: } else {
5218: push(@secs,$item);
5219: }
5220: }
5221: }
5222: if ($env{'request.course.sec'} ne '') {
5223: @secs = ($env{'request.course.sec'});
1.57 raeburn 5224: if (ref($userlist{$username.':'.$userdomain}) eq 'ARRAY') {
5225: my $currsec = $userlist{$username.':'.$userdomain}[$secidx];
1.27 raeburn 5226: if ($currsec ne $env{'request.course.sec'}) {
1.171 raeburn 5227: $disallow{$counter} =
5228: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]".',
5229: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$secs[0]);
1.27 raeburn 5230: if ($currsec eq '') {
1.171 raeburn 5231: $disallow{$counter} .=
5232: &mt('This user already has an active/future student role in the course, unaffiliated to any section.');
1.27 raeburn 5233:
5234: } else {
1.171 raeburn 5235: $disallow{$counter} .=
5236: &mt('This user already has an active/future role in section "[_1]" of the course.',$currsec);
1.27 raeburn 5237: }
1.171 raeburn 5238: $disallow{$counter} .=
5239: '<br />'.
5240: &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.',
5241: $secs[0]);
1.27 raeburn 5242: next;
1.1 raeburn 5243: }
5244: }
1.27 raeburn 5245: } elsif ($context eq 'course' || $setting eq 'course') {
5246: if (@secs == 0) {
5247: @secs = @cleansec;
1.1 raeburn 5248: }
5249: }
5250: # determine id number
5251: my $id='';
5252: if (defined($fields{'id'})) {
5253: if (defined($entries{$fields{'id'}})) {
5254: $id=$entries{$fields{'id'}};
5255: }
5256: $id=~tr/A-Z/a-z/;
5257: }
5258: # determine email address
5259: my $email='';
5260: if (defined($fields{'email'})) {
1.129 raeburn 5261: $entries{$fields{'email'}} =~ s/^\s+|\s+$//g;
1.1 raeburn 5262: if (defined($entries{$fields{'email'}})) {
5263: $email=$entries{$fields{'email'}};
1.84 raeburn 5264: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
5265: }
5266: }
5267: # determine affiliation
5268: my $inststatus='';
5269: if (defined($fields{'inststatus'})) {
5270: if (defined($entries{$fields{'inststatus'}})) {
5271: $inststatus=$entries{$fields{'inststatus'}};
5272: }
1.1 raeburn 5273: }
5274: # determine user password
1.200 raeburn 5275: my $password;
5276: my $passwdfromfile;
1.1 raeburn 5277: if (defined($fields{'ipwd'})) {
5278: if ($entries{$fields{'ipwd'}}) {
5279: $password=$entries{$fields{'ipwd'}};
1.200 raeburn 5280: $passwdfromfile = 1;
5281: if ($env{'form.login'} eq 'int') {
5282: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
5283: if (($uhome eq 'no_host') || ($changeauth)) {
5284: my @brokepwdrules =
5285: &Apache::loncommon::check_passwd_rules($domain,$password);
5286: if (@brokepwdrules) {
5287: $disallow{$counter} = &mt('[_1]: Password included in file for this user did not meet requirements.',
5288: '<b>'.$username.'</b>');
5289: map { $showpasswdrules{$_} = 1; } @brokepwdrules;
5290: next;
5291: }
5292: }
5293: }
5294: }
5295: }
5296: unless ($passwdfromfile) {
5297: if ($env{'form.login'} eq 'int') {
5298: if (@genpwdfail) {
5299: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
5300: if (($uhome eq 'no_host') || ($changeauth)) {
5301: $disallow{$counter} = &mt('[_1]: No specific password in file for this user; default password did not meet requirements',
5302: '<b>'.$username.'</b>');
5303: unless ($haspasswdmap) {
5304: map { $showpasswdrules{$_} = 1; } @genpwdfail;
5305: $haspasswdmap = 1;
5306: }
5307: }
5308: next;
5309: }
1.1 raeburn 5310: }
1.200 raeburn 5311: $password = $genpwd;
1.1 raeburn 5312: }
5313: # determine user role
5314: my $role = '';
5315: if (defined($fields{'role'})) {
5316: if ($entries{$fields{'role'}}) {
1.42 raeburn 5317: $entries{$fields{'role'}} =~ s/(\s+$|^\s+)//g;
5318: if ($entries{$fields{'role'}} ne '') {
5319: if (grep(/^\Q$entries{$fields{'role'}}\E$/,@permitted_roles)) {
5320: $role = $entries{$fields{'role'}};
1.27 raeburn 5321: }
5322: }
5323: if ($role eq '') {
5324: my $rolestr = join(', ',@permitted_roles);
1.171 raeburn 5325: $disallow{$counter} =
5326: &mt('[_1]: You do not have permission to add the requested role [_2] for the user.'
5327: ,'<b>'.$entries{$fields{'username'}}.'</b>'
5328: ,$entries{$fields{'role'}})
5329: .'<br />'
5330: .&mt('Allowable role(s) is/are: [_1].',$rolestr);
1.1 raeburn 5331: next;
5332: }
5333: }
5334: }
5335: if ($role eq '') {
5336: $role = $defaultrole;
5337: }
5338: # Clean up whitespace
1.129 raeburn 5339: foreach (\$id,\$fname,\$mname,\$lname,\$gen,\$inststatus) {
1.1 raeburn 5340: $$_ =~ s/(\s+$|^\s+)//g;
5341: }
1.150 raeburn 5342: my $credits;
5343: if ($showcredits) {
5344: if (($role eq 'st') && ($crstype ne 'Community')) {
5345: $credits = $entries{$fields{'credits'}};
5346: if ($credits ne '') {
5347: $credits =~ s/[^\d\.]//g;
5348: }
5349: if ($credits eq '') {
5350: $credits = $commoncredits;
5351: }
5352: if ($credits eq $defaultcredits) {
5353: undef($credits);
5354: }
5355: }
5356: }
1.5 raeburn 5357: # check against rules
5358: my $checkid = 0;
5359: my $newuser = 0;
1.57 raeburn 5360: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
1.5 raeburn 5361: if ($uhome eq 'no_host') {
1.135 raeburn 5362: if ($userdomain ne $newuserdom) {
5363: if ($context eq 'course') {
1.171 raeburn 5364: $disallow{$counter} =
5365: &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
5366: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 5367: } elsif ($context eq 'author') {
1.171 raeburn 5368: $disallow{$counter} =
5369: &mt('[_1]: The domain specified ([_2]) is different to that of the author.',
5370: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 5371: } else {
1.171 raeburn 5372: $disallow{$counter} =
5373: &mt('[_1]: The domain specified ([_2]) is different to that of your current role.',
5374: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 5375: }
1.171 raeburn 5376: $disallow{$counter} .=
5377: &mt('The user does not already exist, and you may not create a new user in a different domain.');
1.124 raeburn 5378: next;
1.171 raeburn 5379: } else {
1.194 raeburn 5380: unless (($password ne '') || ($env{'form.login'} eq 'loc') || ($env{'form.login'} eq 'lti')) {
1.171 raeburn 5381: $disallow{$counter} =
5382: &mt('[_1]: This is a new user but no default password was provided, and the authentication type requires one.',
5383: '<b>'.$username.'</b>');
5384: next;
5385: }
1.124 raeburn 5386: }
1.5 raeburn 5387: $checkid = 1;
5388: $newuser = 1;
1.172 raeburn 5389: $checkuname{$username.':'.$newuserdom} = { 'newuser' => $newuser, 'id' => $id };
1.13 raeburn 5390: } else {
1.27 raeburn 5391: if ($context eq 'course' || $context eq 'author') {
1.57 raeburn 5392: if ($userdomain eq $domain ) {
5393: if ($role eq '') {
5394: my @checkroles;
5395: foreach my $role (@poss_roles) {
5396: my $endkey;
5397: if ($role ne 'st') {
5398: $endkey = ':'.$role;
5399: }
5400: if (exists($userlist{$username.':'.$userdomain.$endkey})) {
5401: if (!grep(/^\Q$role\E$/,@checkroles)) {
5402: push(@checkroles,$role);
5403: }
5404: }
1.27 raeburn 5405: }
1.57 raeburn 5406: if (@checkroles > 0) {
5407: %canmodify = &can_modify_userinfo($context,$domain,\@userinfo,\@checkroles);
1.27 raeburn 5408: }
1.57 raeburn 5409: } elsif (ref($modifiable_fields{$role}) eq 'HASH') {
5410: %canmodify = %{$modifiable_fields{$role}};
1.27 raeburn 5411: }
5412: }
1.57 raeburn 5413: my @newinfo = (\$fname,\$mname,\$lname,\$gen,\$email,\$id);
1.84 raeburn 5414: for (my $i=0; $i<@newinfo; $i++) {
1.57 raeburn 5415: if (${$newinfo[$i]} ne '') {
5416: if (!$canmodify{$userinfo[$i]}) {
5417: ${$newinfo[$i]} = '';
5418: }
1.27 raeburn 5419: }
5420: }
5421: }
1.171 raeburn 5422: if ($id) {
5423: $existinguser{$userdomain}{$username} = $id;
5424: }
1.5 raeburn 5425: }
1.171 raeburn 5426: $userinfo{$counter} = {
5427: username => $username,
5428: domain => $userdomain,
5429: fname => $fname,
5430: mname => $mname,
5431: lname => $lname,
5432: gen => $gen,
5433: email => $email,
5434: id => $id,
5435: password => $password,
5436: inststatus => $inststatus,
5437: role => $role,
5438: sections => \@secs,
5439: credits => $credits,
5440: newuser => $newuser,
5441: checkid => $checkid,
5442: };
5443: }
5444: }
5445: } # end of foreach (@userdata)
5446: if ($counter > -1) {
5447: my $total = $counter + 1;
5448: my %checkids;
1.172 raeburn 5449: if ((keys(%existinguser)) || (keys(%checkuname))) {
5450: $r->print(&mt('Please be patient -- checking for institutional data ...'));
5451: $r->rflush();
5452: if (keys(%existinguser)) {
5453: foreach my $dom (keys(%existinguser)) {
5454: if (ref($existinguser{$dom}) eq 'HASH') {
5455: my %idhash = &Apache::lonnet::idrget($dom,keys(%{$existinguser{$dom}}));
5456: foreach my $username (keys(%{$existinguser{$dom}})) {
5457: if ($idhash{$username} ne $existinguser{$dom}{$username}) {
5458: $checkids{$username.':'.$dom} = {
5459: 'id' => $existinguser{$dom}{$username},
5460: };
5461: }
5462: }
5463: if (keys(%checkids)) {
5464: &Apache::loncommon::user_rule_check(\%checkids,{ 'id' => 1 },
5465: \%alerts,\%rulematch,
5466: \%inst_results,\%curr_rules,
5467: \%got_rules);
1.171 raeburn 5468: }
5469: }
5470: }
5471: }
1.172 raeburn 5472: if (keys(%checkuname)) {
5473: &Apache::loncommon::user_rule_check(\%checkuname,{ 'username' => 1, 'id' => 1, },
5474: \%alerts,\%rulematch,\%inst_results,
5475: \%curr_rules,\%got_rules);
5476: }
5477: $r->print(' '.&mt('done').'<br /><br />');
5478: $r->rflush();
1.171 raeburn 5479: }
1.172 raeburn 5480: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,$total);
1.171 raeburn 5481: $r->print('<ul>');
5482: for (my $i=0; $i<=$counter; $i++) {
5483: if ($disallow{$i}) {
5484: $r->print('<li>'.$disallow{$i}.'</li>');
5485: } elsif (ref($userinfo{$i}) eq 'HASH') {
5486: my $password = $userinfo{$i}{'password'};
5487: my $newuser = $userinfo{$i}{'newuser'};
5488: my $checkid = $userinfo{$i}{'checkid'};
5489: my $id = $userinfo{$i}{'id'};
5490: my $role = $userinfo{$i}{'role'};
5491: my @secs;
5492: if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
5493: @secs = @{$userinfo{$i}{'sections'}};
5494: }
5495: my $fname = $userinfo{$i}{'fname'};
5496: my $mname = $userinfo{$i}{'mname'};
5497: my $lname = $userinfo{$i}{'lname'};
5498: my $gen = $userinfo{$i}{'gen'};
5499: my $email = $userinfo{$i}{'email'};
5500: my $inststatus = $userinfo{$i}{'inststatus'};
5501: my $credits = $userinfo{$i}{'credits'};
5502: my $username = $userinfo{$i}{'username'};
5503: my $userdomain = $userinfo{$i}{'domain'};
5504: my $user = $username.':'.$userdomain;
5505: if ($newuser) {
5506: if (ref($alerts{'username'}) eq 'HASH') {
5507: if (ref($alerts{'username'}{$userdomain}) eq 'HASH') {
5508: if ($alerts{'username'}{$userdomain}{$username}) {
5509: $r->print('<li>'.
5510: &mt('[_1]: matches the username format at your institution, but is not known to your directory service.','<b>'.$username.'</b>').'<br />'.
5511: &mt('Consequently, the user was not created.').'</li>');
5512: next;
5513: }
5514: }
5515: }
1.172 raeburn 5516: if (ref($inst_results{$user}) eq 'HASH') {
5517: if ($inst_results{$user}{'firstname'} ne '') {
5518: $fname = $inst_results{$user}{'firstname'};
5519: }
5520: if ($inst_results{$user}{'middlename'} ne '') {
5521: $mname = $inst_results{$user}{'middlename'};
5522: }
5523: if ($inst_results{$user}{'lasttname'} ne '') {
5524: $lname = $inst_results{$user}{'lastname'};
5525: }
5526: if ($inst_results{$user}{'permanentemail'} ne '') {
5527: $email = $inst_results{$user}{'permanentemail'};
5528: }
5529: if ($inst_results{$user}{'id'} ne '') {
5530: $id = $inst_results{$user}{'id'};
5531: $checkid = 0;
5532: }
5533: if (ref($inst_results{$user}{'inststatus'}) eq 'ARRAY') {
5534: $inststatus = join(':',@{$inst_results{$user}{'inststatus'}});
5535: }
5536: }
5537: if (($checkid) && ($id ne '')) {
5538: if (ref($alerts{'id'}) eq 'HASH') {
5539: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
5540: if ($alerts{'id'}{$userdomain}{$username}) {
5541: $r->print('<li>'.
5542: &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
5543: '<b>'.$username.'</b>').'<br />'.
5544: &mt('Consequently, the user was not created.').'</li>');
5545: next;
5546: }
5547: }
5548: }
5549: }
1.171 raeburn 5550: my $usertype = 'unofficial';
5551: if (ref($rulematch{$user}) eq 'HASH') {
5552: if ($rulematch{$user}{'username'}) {
5553: $usertype = 'official';
1.5 raeburn 5554: }
5555: }
1.171 raeburn 5556: unless ($cancreate{$usertype}) {
5557: my $showtype = $longtypes{$usertype};
5558: $r->print('<li>'.
5559: &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].','<b>'.$username.'</b>',$showtype).'</li>');
5560: next;
5561: }
1.172 raeburn 5562: } elsif ($id ne '') {
1.171 raeburn 5563: if (exists($checkids{$user})) {
5564: $checkid = 1;
1.5 raeburn 5565: if (ref($alerts{'id'}) eq 'HASH') {
1.57 raeburn 5566: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
1.172 raeburn 5567: if ($alerts{'id'}{$userdomain}{$username}) {
1.171 raeburn 5568: $r->print('<li>'.
1.172 raeburn 5569: &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 5570: '<b>'.$username.'</b>').'<br />'.
1.172 raeburn 5571: &mt('Consequently, the ID was not changed.').'</li>');
5572: $id = '';
1.124 raeburn 5573: }
1.5 raeburn 5574: }
5575: }
5576: }
5577: }
1.171 raeburn 5578: my $multiple = 0;
5579: my ($userresult,$authresult,$roleresult,$idresult);
5580: my (%userres,%authres,%roleres,%idres);
5581: my $singlesec = '';
5582: if ($role eq 'st') {
1.206 raeburn 5583: if (($context eq 'domain') && ($changeauth eq 'Yes') && (!$newuser)) {
5584: if ((&Apache::lonnet::allowed('mau',$userdomain)) &&
5585: (&Apache::lonnet::homeserver($username,$userdomain) ne 'no_host')) {
5586: if ((($amode =~ /^krb4|krb5|internal$/) && $password ne '') ||
5587: ($amode eq 'localauth')) {
5588: $authresult =
5589: &Apache::lonnet::modifyuserauth($userdomain,$username,$amode,$password);
5590: }
5591: }
5592: }
1.171 raeburn 5593: my $sec;
5594: if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
1.42 raeburn 5595: if (@secs > 0) {
5596: $sec = $secs[0];
1.27 raeburn 5597: }
1.171 raeburn 5598: }
1.212 raeburn 5599: if ($userdomain ne $env{'request.role.domain'}) {
5600: my $item = "/$crsdom/$crsnum" ;
5601: if ($sec ne '') {
5602: $item .= "/$sec";
5603: }
5604: $item .= '_st';
5605: next if (&restricted_dom($context,$item,$userdomain,$username,$role,$startdate,
5606: $enddate,$crsdom,$crsnum,$sec,$credits,\%process_by,
5607: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.213 raeburn 5608: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.212 raeburn 5609: }
1.171 raeburn 5610: &modifystudent($userdomain,$username,$cid,$sec,
5611: $desiredhost,$context);
5612: $roleresult =
5613: &Apache::lonnet::modifystudent
5614: ($userdomain,$username,$id,$amode,$password,
5615: $fname,$mname,$lname,$gen,$sec,$enddate,
5616: $startdate,$env{'form.forceid'},
5617: $desiredhost,$email,'manual','',$cid,
5618: '',$context,$inststatus,$credits);
5619: $userresult = $roleresult;
5620: } else {
1.212 raeburn 5621: my $possrole;
5622: if ($role ne '') {
1.171 raeburn 5623: if ($context eq 'course' || $setting eq 'course') {
5624: if ($customroles{$role}) {
5625: $role = 'cr_'.$env{'user.domain'}.'_'.
5626: $env{'user.name'}.'_'.$role;
5627: }
1.212 raeburn 5628: $possrole = $role;
5629: if ($possrole =~ /^cr_/) {
5630: $possrole =~ s{_}{/}g;
5631: }
5632: if (($role ne 'cc') && ($role ne 'co')) {
1.171 raeburn 5633: if (@secs > 1) {
5634: $multiple = 1;
1.212 raeburn 5635: my $prefix = "/$crsdom/$crsnum";
1.171 raeburn 5636: foreach my $sec (@secs) {
1.212 raeburn 5637: if ($userdomain ne $env{'request.role.domain'}) {
5638: my $item = $prefix;
5639: if ($sec ne '') {
5640: $item .= "/$sec";
5641: }
5642: $item .= '_'.$possrole;
5643: next if (&restricted_dom($context,$item,$userdomain,$username,$possrole,
5644: $startdate,$enddate,$crsdom,$crsnum,$sec,
5645: $credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 5646: \%got_instdoms,\%reject,\%pending,\%notifydc,
5647: \%status,\%unauthorized,\%currqueued));
1.212 raeburn 5648: }
1.171 raeburn 5649: ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
5650: &modifyuserrole($context,$setting,
5651: $changeauth,$cid,$userdomain,$username,
5652: $id,$amode,$password,$fname,
5653: $mname,$lname,$gen,$sec,
5654: $env{'form.forceid'},$desiredhost,
5655: $email,$role,$enddate,
5656: $startdate,$checkid,$inststatus);
1.42 raeburn 5657: }
1.171 raeburn 5658: } elsif (@secs > 0) {
5659: $singlesec = $secs[0];
1.27 raeburn 5660: }
5661: }
1.212 raeburn 5662: } else {
5663: $possrole = $role;
1.27 raeburn 5664: }
1.204 raeburn 5665: }
5666: if (!$multiple) {
1.212 raeburn 5667: if (($userdomain ne $env{'request.role.domain'}) && ($role ne '')) {
5668: my $item = "/$crsdom/$crsnum";
5669: if ($singlesec ne '') {
5670: $item .= "/$singlesec";
5671: }
5672: $item .= '_'.$possrole;
5673: next if (&restricted_dom($context,$item,$userdomain,$username,$possrole,$startdate,$enddate,
5674: $crsdom,$crsnum,$singlesec,$credits,\%process_by,\%instdoms,
1.213 raeburn 5675: \%got_role_approvals,\%got_instdoms,\%reject,\%pending,\%notifydc,
5676: \%status,\%unauthorized,\%currqueued));
1.212 raeburn 5677: }
1.204 raeburn 5678: ($userresult,$authresult,$roleresult,$idresult) =
5679: &modifyuserrole($context,$setting,
5680: $changeauth,$cid,$userdomain,$username,
5681: $id,$amode,$password,$fname,
5682: $mname,$lname,$gen,$singlesec,
5683: $env{'form.forceid'},$desiredhost,
5684: $email,$role,$enddate,$startdate,
1.220 raeburn 5685: $checkid,$inststatus,\%emptyok);
1.27 raeburn 5686: }
1.171 raeburn 5687: }
5688: if ($multiple) {
5689: foreach my $sec (sort(keys(%userres))) {
5690: $flushc =
1.27 raeburn 5691: &user_change_result($r,$userres{$sec},$authres{$sec},
5692: $roleres{$sec},$idres{$sec},\%counts,$flushc,
1.57 raeburn 5693: $username,$userdomain,\%userchg);
1.27 raeburn 5694:
1.1 raeburn 5695: }
5696: } else {
1.171 raeburn 5697: $flushc =
5698: &user_change_result($r,$userresult,$authresult,
5699: $roleresult,$idresult,\%counts,$flushc,
5700: $username,$userdomain,\%userchg);
1.1 raeburn 5701: }
5702: }
1.172 raeburn 5703: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last user');
1.171 raeburn 5704: } # end of loop
1.172 raeburn 5705: $r->print('</ul>');
1.171 raeburn 5706: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.217 raeburn 5707: if (($context eq 'domain') && ($setting eq 'course')) {
5708: unless ($oldcrsuserdoms) {
5709: if (exists($env{'course.'.$cid.'.internal.userdomains'})) {
5710: delete($env{'course.'.$cid.'.internal.userdomains'});
5711: }
5712: }
5713: }
1.171 raeburn 5714: }
1.1 raeburn 5715: # Flush the course logs so reverse user roles immediately updated
1.126 raeburn 5716: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.29 raeburn 5717: $r->print("</p>\n<p>\n".&mt('Processed [quant,_1,user].',$counts{'user'}).
1.1 raeburn 5718: "</p>\n");
5719: if ($counts{'role'} > 0) {
5720: $r->print("<p>\n".
1.192 raeburn 5721: &mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.
5722: &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.').
5723: "</p>\n");
1.29 raeburn 5724: } else {
5725: $r->print('<p>'.&mt('No roles added').'</p>');
1.1 raeburn 5726: }
5727: if ($counts{'auth'} > 0) {
5728: $r->print("<p>\n".
5729: &mt('Authentication changed for [_1] existing users.',
5730: $counts{'auth'})."</p>\n");
5731: }
1.13 raeburn 5732: $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
1.200 raeburn 5733: $r->print(&passwdrule_alerts($domain,\%showpasswdrules));
1.213 raeburn 5734: if ((keys(%reject)) || (keys(%unauthorized))) {
5735: $r->print(&print_roles_rejected($context,\%reject,\%unauthorized));
1.212 raeburn 5736: }
1.213 raeburn 5737: if ((keys(%pending)) || (keys(%currqueued))) {
5738: $r->print(&print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.212 raeburn 5739: }
1.1 raeburn 5740: #####################################
1.29 raeburn 5741: # Display list of students to drop #
1.1 raeburn 5742: #####################################
5743: if ($env{'form.fullup'} eq 'yes') {
1.29 raeburn 5744: $r->print('<h3>'.&mt('Students to Drop')."</h3>\n");
1.1 raeburn 5745: # Get current classlist
1.30 raeburn 5746: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 5747: if (! defined($classlist)) {
1.192 raeburn 5748: $r->print('<p class="LC_info">'.
5749: &mt('There are no students with current/future access to the course.').
5750: '</p>'."\n");
1.66 raeburn 5751: } elsif (ref($classlist) eq 'HASH') {
1.1 raeburn 5752: # Remove the students we just added from the list of students.
1.30 raeburn 5753: foreach my $line (@userdata) {
5754: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 5755: unless (($entries{$fields{'username'}} eq '') ||
5756: (!defined($entries{$fields{'username'}}))) {
5757: delete($classlist->{$entries{$fields{'username'}}.
5758: ':'.$domain});
5759: }
5760: }
5761: # Print out list of dropped students.
1.30 raeburn 5762: &show_drop_list($r,$classlist,'nosort',$permission);
1.1 raeburn 5763: }
5764: }
5765: } # end of unless
1.193 raeburn 5766: return 'ok';
1.1 raeburn 5767: }
5768:
1.13 raeburn 5769: sub print_namespacing_alerts {
5770: my ($domain,$alerts,$curr_rules) = @_;
5771: my $output;
5772: if (ref($alerts) eq 'HASH') {
5773: if (keys(%{$alerts}) > 0) {
5774: if (ref($alerts->{'username'}) eq 'HASH') {
5775: foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
5776: my $count;
5777: if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
5778: $count = keys(%{$alerts->{'username'}{$dom}});
5779: }
5780: my $domdesc = &Apache::lonnet::domain($domain,'description');
5781: if (ref($curr_rules->{$dom}) eq 'HASH') {
5782: $output .= &Apache::loncommon::instrule_disallow_msg(
5783: 'username',$domdesc,$count,'upload');
5784: }
5785: $output .= &Apache::loncommon::user_rule_formats($dom,
5786: $domdesc,$curr_rules->{$dom}{'username'},
5787: 'username');
5788: }
5789: }
5790: if (ref($alerts->{'id'}) eq 'HASH') {
5791: foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
5792: my $count;
5793: if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
5794: $count = keys(%{$alerts->{'id'}{$dom}});
5795: }
5796: my $domdesc = &Apache::lonnet::domain($domain,'description');
5797: if (ref($curr_rules->{$dom}) eq 'HASH') {
5798: $output .= &Apache::loncommon::instrule_disallow_msg(
5799: 'id',$domdesc,$count,'upload');
5800: }
5801: $output .= &Apache::loncommon::user_rule_formats($dom,
5802: $domdesc,$curr_rules->{$dom}{'id'},'id');
5803: }
5804: }
5805: }
5806: }
5807: }
5808:
1.200 raeburn 5809: sub passwdrule_alerts {
5810: my ($domain,$passwdrules) = @_;
5811: my $warning;
5812: if (ref($passwdrules) eq 'HASH') {
5813: my %showrules = %{$passwdrules};
5814: if (keys(%showrules)) {
5815: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
5816: $warning = '<b>'.&mt('Password requirement(s) unmet for one or more users:').'</b><ul>';
5817: if ($showrules{'min'}) {
1.208 raeburn 5818: my $min = $passwdconf{'min'};
5819: if ($min eq '') {
5820: $min = $Apache::lonnet::passwdmin;
5821: }
5822: $warning .= '<li>'.&mt('minimum [quant,_1,character]',$min).'</li>';
1.200 raeburn 5823: }
5824: if ($showrules{'max'}) {
5825: $warning .= '<li>'.&mt('maximum [quant,_1,character]',$passwdconf{'max'}).'</li>';
5826: }
5827: if ($showrules{'uc'}) {
5828: $warning .= '<li>'.&mt('contain at least one upper case letter').'</li>';
5829: }
5830: if ($showrules{'lc'}) {
5831: $warning .= '<li>'.&mt('contain at least one lower case letter').'</li>';
5832: }
5833: if ($showrules{'num'}) {
5834: $warning .= '<li>'.&mt('contain at least one number').'</li>';
5835: }
5836: if ($showrules{'spec'}) {
5837: $warning .= '<li>'.&mt('contain at least one non-alphanumeric').'</li>';
5838: }
5839: $warning .= '</ul>';
5840: }
5841: }
5842: return $warning;
5843: }
5844:
1.1 raeburn 5845: sub user_change_result {
1.29 raeburn 5846: my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
1.57 raeburn 5847: $username,$userdomain,$userchg) = @_;
1.1 raeburn 5848: my $okresult = 0;
1.171 raeburn 5849: my @status;
1.1 raeburn 5850: if ($userresult ne 'ok') {
5851: if ($userresult =~ /^error:(.+)$/) {
5852: my $error = $1;
1.171 raeburn 5853: push(@status,
5854: &mt('[_1]: Unable to add/modify: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5855: }
5856: } else {
5857: $counts->{'user'} ++;
5858: $okresult = 1;
5859: }
5860: if ($authresult ne 'ok') {
5861: if ($authresult =~ /^error:(.+)$/) {
5862: my $error = $1;
1.171 raeburn 5863: push(@status,
5864: &mt('[_1]: Unable to modify authentication: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5865: }
5866: } else {
5867: $counts->{'auth'} ++;
5868: $okresult = 1;
5869: }
5870: if ($roleresult ne 'ok') {
5871: if ($roleresult =~ /^error:(.+)$/) {
5872: my $error = $1;
1.171 raeburn 5873: push(@status,
5874: &mt('[_1]: Unable to add role: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5875: }
5876: } else {
5877: $counts->{'role'} ++;
5878: $okresult = 1;
5879: }
5880: if ($okresult) {
5881: $flushc++;
1.57 raeburn 5882: $userchg->{$username.':'.$userdomain}=1;
1.1 raeburn 5883: if ($flushc>15) {
5884: $r->rflush;
5885: $flushc=0;
5886: }
5887: }
1.29 raeburn 5888: if ($idresult) {
1.171 raeburn 5889: push(@status,$idresult);
5890: }
5891: if (@status) {
5892: $r->print('<li>'.join('<br />',@status).'</li>');
1.29 raeburn 5893: }
1.1 raeburn 5894: return $flushc;
5895: }
5896:
5897: # ========================================================= Menu Phase Two Drop
1.17 raeburn 5898: sub print_drop_menu {
1.101 raeburn 5899: my ($r,$context,$permission,$crstype) = @_;
5900: my $heading;
5901: if ($crstype eq 'Community') {
5902: $heading = &mt("Drop Members");
5903: } else {
5904: $heading = &mt("Drop Students");
5905: }
5906: $r->print('<h3>'.$heading.'</h3>'."\n".
1.153 bisitz 5907: '<form name="studentform" method="post" action="">'."\n");
1.30 raeburn 5908: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 5909: if (! defined($classlist)) {
1.143 bisitz 5910: my $msg = '';
1.101 raeburn 5911: if ($crstype eq 'Community') {
1.143 bisitz 5912: $msg = &mt('There are no members currently enrolled.');
1.101 raeburn 5913: } else {
1.143 bisitz 5914: $msg = &mt('There are no students currently enrolled.');
1.101 raeburn 5915: }
1.143 bisitz 5916: $r->print('<p class="LC_info">'.$msg."</p>\n");
1.30 raeburn 5917: } else {
1.101 raeburn 5918: &show_drop_list($r,$classlist,'nosort',$permission,$crstype);
1.1 raeburn 5919: }
1.162 bisitz 5920: $r->print('</form>');
1.1 raeburn 5921: return;
5922: }
5923:
5924: # ================================================================== Phase four
5925:
1.11 raeburn 5926: sub update_user_list {
1.118 raeburn 5927: my ($r,$context,$setting,$choice,$crstype) = @_;
1.11 raeburn 5928: my $now = time;
1.1 raeburn 5929: my $count=0;
1.101 raeburn 5930: if ($context eq 'course') {
5931: $crstype = &Apache::loncommon::course_type();
5932: }
1.212 raeburn 5933: my (@changelist,%got_role_approvals,%got_instdoms,%process_by,%instdoms,
1.213 raeburn 5934: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
1.29 raeburn 5935: if ($choice eq 'drop') {
5936: @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
5937: } else {
1.11 raeburn 5938: @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
5939: }
5940: my %result_text = ( ok => { 'revoke' => 'Revoked',
5941: 'delete' => 'Deleted',
5942: 'reenable' => 'Re-enabled',
1.17 raeburn 5943: 'activate' => 'Activated',
5944: 'chgdates' => 'Changed Access Dates for',
1.118 raeburn 5945: 'chgsec' => 'Changed section(s) for',
1.17 raeburn 5946: 'drop' => 'Dropped',
1.11 raeburn 5947: },
5948: error => {'revoke' => 'revoking',
5949: 'delete' => 'deleting',
5950: 'reenable' => 're-enabling',
5951: 'activate' => 'activating',
1.17 raeburn 5952: 'chgdates' => 'changing access dates for',
5953: 'chgsec' => 'changing section for',
5954: 'drop' => 'dropping',
1.11 raeburn 5955: },
5956: );
5957: my ($startdate,$enddate);
5958: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
5959: ($startdate,$enddate) = &get_dates_from_form();
5960: }
5961: foreach my $item (@changelist) {
1.118 raeburn 5962: my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,
5963: @sections,$scopestem,$singlesec,$showsecs,$warn_singlesec,
1.212 raeburn 5964: $nothingtodo,$keepnosection,$credits,$instsec,$cdom,$cnum);
1.17 raeburn 5965: if ($choice eq 'drop') {
5966: ($uname,$udom,$sec) = split(/:/,$item,-1);
5967: $role = 'st';
5968: $cid = $env{'request.course.id'};
5969: $scopestem = '/'.$cid;
5970: $scopestem =~s/\_/\//g;
5971: if ($sec eq '') {
5972: $scope = $scopestem;
5973: } else {
5974: $scope = $scopestem.'/'.$sec;
5975: }
5976: } elsif ($context eq 'course') {
1.174 raeburn 5977: ($uname,$udom,$role,$sec,$type,$locktype,$credits,$instsec) =
5978: split(/\:/,$item,8);
5979: $instsec = &unescape($instsec);
1.11 raeburn 5980: $cid = $env{'request.course.id'};
1.212 raeburn 5981: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5982: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.11 raeburn 5983: $scopestem = '/'.$cid;
5984: $scopestem =~s/\_/\//g;
5985: if ($sec eq '') {
5986: $scope = $scopestem;
5987: } else {
5988: $scope = $scopestem.'/'.$sec;
5989: }
1.13 raeburn 5990: } elsif ($context eq 'author') {
1.11 raeburn 5991: ($uname,$udom,$role) = split(/\:/,$item,-1);
5992: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
1.212 raeburn 5993: $cdom = $env{'user.domain'};
5994: $cnum = $env{'user.name'};
1.11 raeburn 5995: } elsif ($context eq 'domain') {
5996: if ($setting eq 'domain') {
5997: ($role,$uname,$udom) = split(/\:/,$item,-1);
5998: $scope = '/'.$env{'request.role.domain'}.'/';
1.212 raeburn 5999: $cdom = $env{'request.role.domain'};
1.13 raeburn 6000: } elsif ($setting eq 'author') {
1.11 raeburn 6001: ($uname,$udom,$role,$scope) = split(/\:/,$item);
1.212 raeburn 6002: (undef,$cdom,$cnum) = split(/\//,$scope);
1.11 raeburn 6003: } elsif ($setting eq 'course') {
1.174 raeburn 6004: ($uname,$udom,$role,$cid,$sec,$type,$locktype,$credits,$instsec) =
6005: split(/\:/,$item,9);
1.212 raeburn 6006: ($cdom,$cnum) = split('_',$cid);
1.174 raeburn 6007: $instsec = &unescape($instsec);
1.11 raeburn 6008: $scope = '/'.$cid;
6009: $scope =~s/\_/\//g;
6010: if ($sec ne '') {
6011: $scope .= '/'.$sec;
6012: }
6013: }
6014: }
1.101 raeburn 6015: my $plrole = &Apache::lonnet::plaintext($role,$crstype);
1.11 raeburn 6016: my $start = $env{'form.'.$item.'_start'};
6017: my $end = $env{'form.'.$item.'_end'};
1.17 raeburn 6018: if ($choice eq 'drop') {
6019: # drop students
6020: $end = $now;
6021: $type = 'manual';
6022: $result =
1.52 raeburn 6023: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.17 raeburn 6024: } elsif ($choice eq 'revoke') {
6025: # revoke or delete user role
1.11 raeburn 6026: $end = $now;
6027: if ($role eq 'st') {
6028: $result =
1.174 raeburn 6029: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.11 raeburn 6030: } else {
6031: $result =
1.52 raeburn 6032: &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
6033: '','',$context);
1.11 raeburn 6034: }
6035: } elsif ($choice eq 'delete') {
6036: if ($role eq 'st') {
1.174 raeburn 6037: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.29 raeburn 6038: }
6039: $result =
6040: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
1.52 raeburn 6041: $start,1,'',$context);
1.11 raeburn 6042: } else {
6043: #reenable, activate, change access dates or change section
6044: if ($choice ne 'chgsec') {
6045: $start = $startdate;
6046: $end = $enddate;
6047: }
1.212 raeburn 6048: my $id = $scope.'_'.$role;
1.11 raeburn 6049: if ($choice eq 'reenable') {
1.212 raeburn 6050: next if (&restricted_dom($context,$id,$udom,$uname,$role,$now,$end,$cdom,$cnum,
6051: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 6052: \%got_instdoms,\%reject,\%pending,\%notifydc,
6053: \%status,\%unauthorized,\%currqueued));
1.11 raeburn 6054: if ($role eq 'st') {
1.174 raeburn 6055: $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 6056: } else {
6057: $result =
6058: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 6059: $now,'','',$context);
1.11 raeburn 6060: }
6061: } elsif ($choice eq 'activate') {
1.212 raeburn 6062: next if (&restricted_dom($context,$id,$udom,$uname,$role,$now,$end,$cdom,$cnum,
6063: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 6064: \%got_instdoms,\%reject,\%pending,\%notifydc,
6065: \%status,\%unauthorized,\%currqueued));
1.11 raeburn 6066: if ($role eq 'st') {
1.174 raeburn 6067: $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 6068: } else {
6069: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 6070: $now,'','',$context);
1.11 raeburn 6071: }
6072: } elsif ($choice eq 'chgdates') {
1.212 raeburn 6073: next if (&restricted_dom($context,$id,$udom,$uname,$role,$start,$end,$cdom,$cnum,
6074: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 6075: \%got_instdoms,\%reject,\%pending,\%notifydc,
6076: \%status,\%unauthorized,\%currqueued));
1.11 raeburn 6077: if ($role eq 'st') {
1.174 raeburn 6078: $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 6079: } else {
6080: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 6081: $start,'','',$context);
1.11 raeburn 6082: }
6083: } elsif ($choice eq 'chgsec') {
6084: my (@newsecs,$revresult,$nochg,@retained);
1.103 raeburn 6085: if (($role ne 'cc') && ($role ne 'co')) {
1.117 raeburn 6086: my @secs = sort(split(/,/,$env{'form.newsecs'}));
6087: if (@secs) {
6088: my %curr_groups = &Apache::longroup::coursegroups();
6089: foreach my $sec (@secs) {
6090: next if (($sec =~ /\W/) || ($sec eq 'none') ||
6091: (exists($curr_groups{$sec})));
6092: push(@newsecs,$sec);
6093: }
6094: }
1.11 raeburn 6095: }
6096: # remove existing section if not to be retained.
1.118 raeburn 6097: if (!$env{'form.retainsec'} || ($role eq 'st')) {
1.11 raeburn 6098: if ($sec eq '') {
6099: if (@newsecs == 0) {
1.118 raeburn 6100: $result = 'ok';
1.11 raeburn 6101: $nochg = 1;
1.118 raeburn 6102: $nothingtodo = 1;
1.40 raeburn 6103: } else {
6104: $revresult =
6105: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 6106: $scope,$role,
6107: '','',$context);
1.40 raeburn 6108: }
1.11 raeburn 6109: } else {
1.28 raeburn 6110: if (@newsecs > 0) {
6111: if (grep(/^\Q$sec\E$/,@newsecs)) {
6112: push(@retained,$sec);
6113: } else {
6114: $revresult =
6115: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 6116: $scope,$role,
6117: '','',$context);
1.28 raeburn 6118: }
6119: } else {
1.11 raeburn 6120: $revresult =
1.28 raeburn 6121: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 6122: $scope,$role,
6123: '','',$context);
1.11 raeburn 6124: }
6125: }
6126: } else {
1.28 raeburn 6127: if ($sec eq '') {
6128: $nochg = 1;
1.118 raeburn 6129: $keepnosection = 1;
6130: } else {
1.28 raeburn 6131: push(@retained,$sec);
6132: }
1.11 raeburn 6133: }
6134: # add new sections
1.118 raeburn 6135: my (@diffs,@shownew);
6136: if (@retained) {
6137: @diffs = &Apache::loncommon::compare_arrays(\@retained,\@newsecs);
6138: } else {
6139: @diffs = @newsecs;
6140: }
1.11 raeburn 6141: if (@newsecs == 0) {
1.118 raeburn 6142: if ($nochg) {
6143: $result = 'ok';
6144: $nothingtodo = 1;
6145: } else {
1.28 raeburn 6146: if ($role eq 'st') {
6147: $result =
1.174 raeburn 6148: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.28 raeburn 6149: } else {
6150: my $newscope = $scopestem;
1.52 raeburn 6151: $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
1.11 raeburn 6152: }
6153: }
1.118 raeburn 6154: $showsecs = &mt('No section');
6155: } elsif (@diffs == 0) {
6156: $result = 'ok';
6157: $nothingtodo = 1;
1.11 raeburn 6158: } else {
1.118 raeburn 6159: foreach my $newsec (@newsecs) {
1.11 raeburn 6160: if (!grep(/^\Q$newsec\E$/,@retained)) {
6161: if ($role eq 'st') {
1.174 raeburn 6162: $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 6163: if (@newsecs > 1) {
6164: my $showsingle;
6165: if ($newsec eq '') {
6166: $showsingle = &mt('No section');
6167: } else {
6168: $showsingle = $newsec;
6169: }
6170: if ($crstype eq 'Community') {
6171: $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>');
6172: } else {
6173: $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>');
6174: }
6175: $showsecs = $showsingle;
6176: last;
6177: } else {
6178: if ($newsec eq '') {
6179: $showsecs = &mt('No section');
6180: } else {
6181: $showsecs = $newsec;
6182: }
6183: }
1.11 raeburn 6184: } else {
6185: my $newscope = $scopestem;
6186: if ($newsec ne '') {
6187: $newscope .= '/'.$newsec;
1.118 raeburn 6188: push(@shownew,$newsec);
1.11 raeburn 6189: }
6190: $result = &Apache::lonnet::assignrole($udom,$uname,
6191: $newscope,$role,$end,$start);
1.118 raeburn 6192:
1.11 raeburn 6193: }
6194: }
6195: }
6196: }
1.118 raeburn 6197: unless ($role eq 'st') {
6198: unless ($showsecs) {
6199: my @tolist = sort(@shownew,@retained);
6200: if ($keepnosection) {
6201: push(@tolist,&mt('No section'));
6202: }
6203: $showsecs = join(', ',@tolist);
6204: }
6205: }
1.11 raeburn 6206: }
6207: }
1.17 raeburn 6208: my $extent = $scope;
6209: if ($choice eq 'drop' || $context eq 'course') {
6210: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
6211: if ($cdesc) {
6212: $extent = $cdesc;
6213: }
6214: }
1.1 raeburn 6215: if ($result eq 'ok' || $result eq 'ok:') {
1.118 raeburn 6216: my $dates;
6217: if (($choice eq 'chgsec') || ($choice eq 'chgdates')) {
6218: $dates = &dates_feedback($start,$end,$now);
6219: }
6220: if ($choice eq 'chgsec') {
6221: if ($nothingtodo) {
6222: $r->print(&mt("Section assignment for role of '[_1]' in [_2] for '[_3]' unchanged.",$plrole,$extent,'<i>'.
6223: &Apache::loncommon::plainname($uname,$udom).
6224: '</i>').' ');
6225: if ($sec eq '') {
6226: $r->print(&mt('[_1]No section[_2] - [_3]','<b>','</b>',$dates));
6227: } else {
6228: $r->print(&mt('Section(s): [_1] - [_2]',
6229: '<b>'.$showsecs.'</b>',$dates));
6230: }
6231: $r->print('<br />');
6232: } else {
6233: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' to [_4] - [_5]",$plrole,$extent,
6234: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
6235: '<b>'.$showsecs.'</b>',$dates).'<br />');
6236: $count ++;
6237: }
6238: if ($warn_singlesec) {
6239: $r->print('<div class="LC_warning">'.$warn_singlesec.'</div>');
6240: }
6241: } elsif ($choice eq 'chgdates') {
6242: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' - [_4]",$plrole,$extent,
1.121 raeburn 6243: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
1.118 raeburn 6244: $dates).'<br />');
6245: $count ++;
6246: } else {
6247: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]'.",$plrole,$extent,
1.121 raeburn 6248: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>').
1.118 raeburn 6249: '<br />');
6250: $count ++;
6251: }
1.1 raeburn 6252: } else {
6253: $r->print(
1.118 raeburn 6254: &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for '[_3]': [_4].",
6255: $plrole,$extent,
1.121 raeburn 6256: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
1.118 raeburn 6257: $result).'<br />');
1.11 raeburn 6258: }
6259: }
1.32 raeburn 6260: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
1.33 raeburn 6261: if ($choice eq 'drop') {
6262: $r->print('<input type="hidden" name="action" value="listusers" />'."\n".
6263: '<input type="hidden" name="Status" value="Active" />'."\n".
6264: '<input type="hidden" name="showrole" value="st" />'."\n");
6265: } else {
6266: foreach my $item ('action','sortby','roletype','showrole','Status','secfilter','grpfilter') {
6267: if ($env{'form.'.$item} ne '') {
6268: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.
6269: '" />'."\n");
6270: }
1.32 raeburn 6271: }
6272: }
1.144 bisitz 6273: $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} [quant,_1,user role,user roles,no user roles].",$count).'</b></p>');
1.11 raeburn 6274: if ($count > 0) {
1.17 raeburn 6275: if ($choice eq 'revoke' || $choice eq 'drop') {
1.74 bisitz 6276: $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>');
1.11 raeburn 6277: }
6278: # Flush the course logs so reverse user roles immediately updated
1.126 raeburn 6279: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.11 raeburn 6280: }
6281: if ($env{'form.makedatesdefault'}) {
6282: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
1.101 raeburn 6283: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
1.1 raeburn 6284: }
6285: }
1.213 raeburn 6286: if ((keys(%reject)) || (keys(%unauthorized))) {
6287: $r->print(&print_roles_rejected($context,\%reject,\%unauthorized));
1.212 raeburn 6288: }
1.213 raeburn 6289: if ((keys(%pending)) || (keys(%currqueued))) {
6290: $r->print(&print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.212 raeburn 6291: }
1.33 raeburn 6292: my $linktext = &mt('Display User Lists');
6293: if ($choice eq 'drop') {
6294: $linktext = &mt('Display current class roster');
6295: }
1.144 bisitz 6296: $r->print(
6297: &Apache::lonhtmlcommon::actionbox(
6298: ['<a href="javascript:document.studentform.submit()">'.$linktext.'</a>'])
6299: .'</form>'."\n");
1.1 raeburn 6300: }
6301:
1.118 raeburn 6302: sub dates_feedback {
6303: my ($start,$end,$now) = @_;
6304: my $dates;
6305: if ($start < $now) {
6306: if ($end == 0) {
1.147 bisitz 6307: $dates = &mt('role(s) active now; no end date');
1.118 raeburn 6308: } elsif ($end > $now) {
6309: $dates = &mt('role(s) active now; ends [_1].',&Apache::lonlocal::locallocaltime($end));
6310: } else {
6311: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
6312: }
6313: } else {
6314: if ($end == 0 || $end > $now) {
6315: $dates = &mt('future role(s); starts: [_1].',&Apache::lonlocal::locallocaltime($start));
6316: } else {
6317: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
6318: }
6319: }
6320: return $dates;
6321: }
6322:
1.8 raeburn 6323: sub classlist_drop {
1.29 raeburn 6324: my ($scope,$uname,$udom,$now) = @_;
1.8 raeburn 6325: my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
1.29 raeburn 6326: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.8 raeburn 6327: if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
1.63 raeburn 6328: my %user;
6329: my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
1.8 raeburn 6330: return &mt('Drop from classlist: [_1]',
6331: '<b>'.$result.'</b>').'<br />';
6332: }
6333: }
6334: }
6335:
6336: sub active_student_roles {
6337: my ($cnum,$cdom,$uname,$udom) = @_;
6338: my %roles =
6339: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
6340: ['future','active'],['st']);
6341: return exists($roles{"$cnum:$cdom:st"});
6342: }
6343:
1.1 raeburn 6344: sub section_check_js {
1.8 raeburn 6345: my $groupslist= &get_groupslist();
1.170 damieng 6346: my %js_lt = &Apache::lonlocal::texthash(
6347: mayn => 'may not be used as the name for a section, as it is a reserved word.',
6348: plch => 'Please choose a different section name.',
6349: mnot => 'may not be used as a section name, as it is the name of a course group.',
6350: secn => 'Section names and group names must be distinct. Please choose a different section name.',
6351: );
6352: &js_escape(\%js_lt);
1.1 raeburn 6353: return <<"END";
6354: function validate(caller) {
1.9 raeburn 6355: var groups = new Array($groupslist);
1.1 raeburn 6356: var secname = caller.value;
6357: if ((secname == 'all') || (secname == 'none')) {
1.170 damieng 6358: alert("'"+secname+"' $js_lt{'mayn'}\\n$js_lt{'plch'}");
1.1 raeburn 6359: return 'error';
6360: }
6361: if (secname != '') {
6362: for (var k=0; k<groups.length; k++) {
6363: if (secname == groups[k]) {
1.170 damieng 6364: alert("'"+secname+"' $js_lt{'mnot'}\\n$js_lt{'secn'}");
1.1 raeburn 6365: return 'error';
6366: }
6367: }
6368: }
6369: return 'ok';
6370: }
6371: END
6372: }
6373:
6374: sub set_login {
1.194 raeburn 6375: my ($dom,$authformkrb,$authformint,$authformloc,$authformlti) = @_;
1.1 raeburn 6376: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6377: my $response;
6378: my ($authnum,%can_assign) =
6379: &Apache::loncommon::get_assignable_auth($dom);
6380: if ($authnum) {
6381: $response = &Apache::loncommon::start_data_table();
6382: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
6383: $response .= &Apache::loncommon::start_data_table_row().
6384: '<td>'.$authformkrb.'</td>'.
6385: &Apache::loncommon::end_data_table_row()."\n";
6386: }
6387: if ($can_assign{'int'}) {
6388: $response .= &Apache::loncommon::start_data_table_row().
6389: '<td>'.$authformint.'</td>'.
6390: &Apache::loncommon::end_data_table_row()."\n"
6391: }
6392: if ($can_assign{'loc'}) {
6393: $response .= &Apache::loncommon::start_data_table_row().
6394: '<td>'.$authformloc.'</td>'.
6395: &Apache::loncommon::end_data_table_row()."\n";
6396: }
1.194 raeburn 6397: if ($can_assign{'lti'}) {
6398: $response .= &Apache::loncommon::start_data_table_row().
6399: '<td>'.$authformlti.'</td>'.
6400: &Apache::loncommon::end_data_table_row()."\n";
6401: }
1.1 raeburn 6402: $response .= &Apache::loncommon::end_data_table();
6403: }
6404: return $response;
6405: }
6406:
1.8 raeburn 6407: sub course_sections {
1.178 raeburn 6408: my ($sections_count,$role,$current_sec,$disabled) = @_;
1.8 raeburn 6409: my $output = '';
1.169 raeburn 6410: my @sections = (sort {$a <=> $b} keys(%{$sections_count}));
1.29 raeburn 6411: my $numsec = scalar(@sections);
1.92 bisitz 6412: my $is_selected = ' selected="selected"';
1.29 raeburn 6413: if ($numsec <= 1) {
1.178 raeburn 6414: $output = '<select name="currsec_'.$role.'"'.$disabled.'>'."\n".
1.51 raeburn 6415: ' <option value="">'.&mt('Select').'</option>'."\n";
6416: if ($current_sec eq 'none') {
6417: $output .=
6418: ' <option value=""'.$is_selected.'>'.&mt('No section').'</option>'."\n";
6419: } else {
6420: $output .=
1.29 raeburn 6421: ' <option value="">'.&mt('No section').'</option>'."\n";
1.51 raeburn 6422: }
1.29 raeburn 6423: if ($numsec == 1) {
1.51 raeburn 6424: if ($current_sec eq $sections[0]) {
6425: $output .=
6426: ' <option value="'.$sections[0].'"'.$is_selected.'>'.$sections[0].'</option>'."\n";
6427: } else {
6428: $output .=
1.8 raeburn 6429: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
1.51 raeburn 6430: }
1.29 raeburn 6431: }
1.8 raeburn 6432: } else {
6433: $output = '<select name="currsec_'.$role.'" ';
6434: my $multiple = 4;
6435: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
1.29 raeburn 6436: if ($role eq 'st') {
1.178 raeburn 6437: $output .= $disabled.'>'."\n".
1.51 raeburn 6438: ' <option value="">'.&mt('Select').'</option>'."\n";
6439: if ($current_sec eq 'none') {
6440: $output .=
6441: ' <option value=""'.$is_selected.'>'.&mt('No section')."</option>\n";
6442: } else {
6443: $output .=
1.29 raeburn 6444: ' <option value="">'.&mt('No section')."</option>\n";
1.51 raeburn 6445: }
1.29 raeburn 6446: } else {
1.178 raeburn 6447: $output .= 'multiple="multiple" size="'.$multiple.'"'.$disabled.'>'."\n";
1.29 raeburn 6448: }
1.8 raeburn 6449: foreach my $sec (@sections) {
1.51 raeburn 6450: if ($current_sec eq $sec) {
6451: $output .= '<option value="'.$sec.'"'.$is_selected.'>'.$sec."</option>\n";
6452: } else {
6453: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
6454: }
1.8 raeburn 6455: }
6456: }
6457: $output .= '</select>';
6458: return $output;
6459: }
6460:
6461: sub get_groupslist {
6462: my $groupslist;
6463: my %curr_groups = &Apache::longroup::coursegroups();
6464: if (%curr_groups) {
6465: $groupslist = join('","',sort(keys(%curr_groups)));
6466: $groupslist = '"'.$groupslist.'"';
6467: }
1.11 raeburn 6468: return $groupslist;
1.8 raeburn 6469: }
6470:
6471: sub setsections_javascript {
1.150 raeburn 6472: my ($formname,$groupslist,$mode,$checkauth,$crstype,$showcredits) = @_;
1.28 raeburn 6473: my ($checkincluded,$finish,$rolecode,$setsection_js);
6474: if ($mode eq 'upload') {
6475: $checkincluded = 'formname.name == "'.$formname.'"';
6476: $finish = "return 'ok';";
6477: $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
6478: } elsif ($formname eq 'cu') {
1.150 raeburn 6479: if (($crstype eq 'Course') && ($showcredits)) {
6480: $checkincluded = "((role == 'st') && (formname.elements[i-2].checked == true)) || ((role != 'st') && (formname.elements[i-1].checked == true))";
6481: } else {
6482: $checkincluded = 'formname.elements[i-1].checked == true';
6483: }
1.37 raeburn 6484: if ($checkauth) {
6485: $finish = "var authcheck = auth_check();\n".
6486: " if (authcheck == 'ok') {\n".
6487: " formname.submit();\n".
6488: " }\n";
6489: } else {
6490: $finish = 'formname.submit()';
6491: }
1.28 raeburn 6492: $rolecode = "var match = str.split('_');
6493: var role = match[3];\n";
1.165 raeburn 6494: } elsif (($formname eq 'enrollstudent') || ($formname eq 'selfenroll')) {
1.28 raeburn 6495: $checkincluded = 'formname.name == "'.$formname.'"';
1.37 raeburn 6496: if ($checkauth) {
6497: $finish = "var authcheck = auth_check();\n".
6498: " if (authcheck == 'ok') {\n".
6499: " formname.submit();\n".
6500: " }\n";
6501: } else {
6502: $finish = 'formname.submit()';
6503: }
1.28 raeburn 6504: $rolecode = "var match = str.split('_');
6505: var role = match[1];\n";
1.8 raeburn 6506: } else {
1.28 raeburn 6507: $checkincluded = 'formname.name == "'.$formname.'"';
1.8 raeburn 6508: $finish = "seccheck = 'ok';";
1.28 raeburn 6509: $rolecode = "var match = str.split('_');
6510: var role = match[1];\n";
1.11 raeburn 6511: $setsection_js = "var seccheck = 'alert';";
1.8 raeburn 6512: }
6513: my %alerts = &Apache::lonlocal::texthash(
6514: secd => 'Section designations do not apply to Course Coordinator roles.',
1.103 raeburn 6515: sedn => 'Section designations do not apply to Coordinator roles.',
1.8 raeburn 6516: accr => 'A course coordinator role will be added with access to all sections.',
1.103 raeburn 6517: acor => 'A coordinator role will be added with access to all sections',
1.8 raeburn 6518: inea => 'In each course, each user may only have one student role at a time.',
1.125 raeburn 6519: inco => 'In each community, each user may only have one member role at a time.',
1.145 raeburn 6520: youh => 'You had selected',
1.8 raeburn 6521: secs => 'sections.',
6522: plmo => 'Please modify your selections so they include no more than one section.',
6523: mayn => 'may not be used as the name for a section, as it is a reserved word.',
6524: plch => 'Please choose a different section name.',
6525: mnot => 'may not be used as a section name, as it is the name of a course group.',
6526: secn => 'Section names and group names must be distinct. Please choose a different section name.',
1.113 raeburn 6527: nonw => 'Section names may only contain letters or numbers.',
1.170 damieng 6528: );
6529: &js_escape(\%alerts);
1.8 raeburn 6530: $setsection_js .= <<"ENDSECCODE";
6531:
1.103 raeburn 6532: function setSections(formname,crstype) {
1.8 raeburn 6533: var re1 = /^currsec_/;
1.113 raeburn 6534: var re2 =/\\W/;
1.115 raeburn 6535: var trimleading = /^\\s+/;
6536: var trimtrailing = /\\s+\$/;
1.8 raeburn 6537: var groups = new Array($groupslist);
6538: for (var i=0;i<formname.elements.length;i++) {
6539: var str = formname.elements[i].name;
1.168 raeburn 6540: if (typeof(str) === "undefined") {
6541: continue;
6542: }
1.8 raeburn 6543: var checkcurr = str.match(re1);
6544: if (checkcurr != null) {
1.115 raeburn 6545: var num = i;
1.150 raeburn 6546: $rolecode
1.8 raeburn 6547: if ($checkincluded) {
1.103 raeburn 6548: if (role == 'cc' || role == 'co') {
6549: if (role == 'cc') {
6550: alert("$alerts{'secd'}\\n$alerts{'accr'}");
6551: } else {
6552: alert("$alerts{'sedn'}\\n$alerts{'acor'}");
6553: }
6554: } else {
1.8 raeburn 6555: var sections = '';
6556: var numsec = 0;
1.115 raeburn 6557: var fromexisting = new Array();
6558: for (var j=0; j<formname.elements[num].length; j++) {
6559: if (formname.elements[num].options[j].selected == true ) {
6560: var addsec = formname.elements[num].options[j].value;
1.119 raeburn 6561: if ((addsec != "") && (addsec != null)) {
1.115 raeburn 6562: fromexisting.push(addsec);
1.8 raeburn 6563: if (numsec == 0) {
1.115 raeburn 6564: sections = addsec;
6565: } else {
6566: sections = sections + "," + addsec;
1.8 raeburn 6567: }
1.115 raeburn 6568: numsec ++;
1.8 raeburn 6569: }
6570: }
6571: }
1.115 raeburn 6572: var newsecs = formname.elements[num+1].value;
1.113 raeburn 6573: var validsecs = new Array();
1.115 raeburn 6574: var validsecstr = '';
1.113 raeburn 6575: var badsecs = new Array();
1.8 raeburn 6576: if (newsecs != null && newsecs != "") {
1.115 raeburn 6577: var numsplit;
6578: if (newsecs.indexOf(',') == -1) {
6579: numsplit = new Array(newsecs);
6580: } else {
6581: numsplit = newsecs.split(/,/g);
6582: }
1.117 raeburn 6583: for (var m=0; m<numsplit.length; m++) {
6584: var newsec = numsplit[m];
1.115 raeburn 6585: newsec = newsec.replace(trimleading,'');
6586: newsec = newsec.replace(trimtrailing,'');
6587: if (re2.test(newsec) == true) {
6588: badsecs.push(newsec);
1.113 raeburn 6589: } else {
1.115 raeburn 6590: if (newsec != '') {
6591: var isnew = 1;
6592: if (fromexisting != null) {
1.117 raeburn 6593: for (var n=0; n<fromexisting.length; n++) {
6594: if (newsec == fromexisting[n]) {
1.115 raeburn 6595: isnew = 0;
6596: }
6597: }
6598: }
6599: if (isnew == 1) {
6600: validsecs.push(newsec);
6601: }
6602: }
1.113 raeburn 6603: }
6604: }
6605: if (badsecs.length > 0) {
6606: alert("$alerts{'nonw'}\\n$alerts{'plch'}");
6607: return;
6608: }
6609: numsec = numsec + validsecs.length;
1.8 raeburn 6610: }
6611: if ((role == 'st') && (numsec > 1)) {
1.103 raeburn 6612: if (crstype == 'Community') {
6613: alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
6614: } else {
6615: alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
6616: }
1.8 raeburn 6617: return;
1.115 raeburn 6618: } else {
6619: if (validsecs != null) {
6620: for (var j=0; j<validsecs.length; j++) {
6621: if (validsecstr == '' || validsecstr == null) {
6622: validsecstr = validsecs[j];
6623: } else {
6624: validsecstr += ','+validsecs[j];
6625: }
6626: if ((validsecs[j] == 'all') ||
6627: (validsecs[j] == 'none')) {
6628: alert("'"+validsecs[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
1.8 raeburn 6629: return;
6630: }
6631: for (var k=0; k<groups.length; k++) {
1.115 raeburn 6632: if (validsecs[j] == groups[k]) {
6633: alert("'"+validsecs[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
1.8 raeburn 6634: return;
6635: }
6636: }
6637: }
6638: }
6639: }
1.115 raeburn 6640: if ((validsecstr != '') && (validsecstr != null)) {
1.117 raeburn 6641: if ((sections == '') || (sections == null)) {
6642: sections = validsecstr;
6643: } else {
1.115 raeburn 6644: sections = sections + "," + validsecstr;
6645: }
6646: }
6647: formname.elements[num+2].value = sections;
1.8 raeburn 6648: }
6649: }
6650: }
6651: }
6652: $finish
6653: }
6654: ENDSECCODE
1.11 raeburn 6655: return $setsection_js;
1.8 raeburn 6656: }
6657:
1.15 raeburn 6658: sub can_create_user {
6659: my ($dom,$context,$usertype) = @_;
6660: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6661: my $cancreate = 1;
1.28 raeburn 6662: if (&Apache::lonnet::allowed('mau',$dom)) {
6663: return $cancreate;
1.178 raeburn 6664: } elsif ($context eq 'domain') {
6665: $cancreate = 0;
6666: return $cancreate;
1.28 raeburn 6667: }
1.15 raeburn 6668: if (ref($domconf{'usercreation'}) eq 'HASH') {
6669: if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
1.100 raeburn 6670: if ($context eq 'course' || $context eq 'author' || $context eq 'requestcrs') {
1.15 raeburn 6671: my $creation = $domconf{'usercreation'}{'cancreate'}{$context};
6672: if ($creation eq 'none') {
6673: $cancreate = 0;
6674: } elsif ($creation ne 'any') {
6675: if (defined($usertype)) {
6676: if ($creation ne $usertype) {
6677: $cancreate = 0;
6678: }
6679: }
6680: }
6681: }
6682: }
6683: }
6684: return $cancreate;
6685: }
6686:
1.20 raeburn 6687: sub can_modify_userinfo {
6688: my ($context,$dom,$fields,$userroles) = @_;
6689: my %domconfig =
6690: &Apache::lonnet::get_dom('configuration',['usermodification'],
6691: $dom);
1.222 raeburn 6692: if (($context eq 'author') &&
6693: ($env{'request.role'} =~ m{^(ca|aa)\./$match_domain/$match_username$})) {
6694: $context = 'coauthor';
6695: }
1.20 raeburn 6696: my %canmodify;
6697: if (ref($fields) eq 'ARRAY') {
6698: foreach my $field (@{$fields}) {
6699: $canmodify{$field} = 0;
6700: if (&Apache::lonnet::allowed('mau',$dom)) {
6701: $canmodify{$field} = 1;
1.224 ! raeburn 6702: } elsif (($context ne 'selfcreate') &&
! 6703: ($env{'request.role.dom'} ne $dom) &&
! 6704: ($env{'user.domain'} ne $dom)) {
! 6705: $canmodify{$field} = 0;
1.20 raeburn 6706: } else {
6707: if (ref($domconfig{'usermodification'}) eq 'HASH') {
6708: if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
6709: if (ref($userroles) eq 'ARRAY') {
6710: foreach my $role (@{$userroles}) {
6711: my $testrole;
1.60 raeburn 6712: if ($context eq 'selfcreate') {
6713: $testrole = $role;
1.20 raeburn 6714: } else {
1.60 raeburn 6715: if ($role =~ /^cr\//) {
6716: $testrole = 'cr';
6717: } else {
6718: $testrole = $role;
6719: }
1.20 raeburn 6720: }
6721: if (ref($domconfig{'usermodification'}{$context}{$testrole}) eq 'HASH') {
6722: if ($domconfig{'usermodification'}{$context}{$testrole}{$field}) {
6723: $canmodify{$field} = 1;
6724: last;
6725: }
6726: }
6727: }
6728: } else {
6729: foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
6730: if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
6731: if ($domconfig{'usermodification'}{$context}{$key}{$field}) {
6732: $canmodify{$field} = 1;
6733: last;
6734: }
6735: }
6736: }
6737: }
6738: }
6739: } elsif ($context eq 'course') {
6740: if (ref($userroles) eq 'ARRAY') {
6741: if (grep(/^st$/,@{$userroles})) {
6742: $canmodify{$field} = 1;
6743: }
6744: } else {
6745: $canmodify{$field} = 1;
6746: }
6747: }
6748: }
6749: }
6750: }
6751: return %canmodify;
6752: }
6753:
1.195 raeburn 6754: sub can_change_internalpass {
6755: my ($uname,$udom,$crstype,$permission) = @_;
6756: my $canchange;
6757: if (&Apache::lonnet::allowed('mau',$udom)) {
6758: $canchange = 1;
6759: } elsif ((ref($permission) eq 'HASH') && ($permission->{'mip'}) &&
6760: ($udom eq $env{'request.role.domain'})) {
6761: unless ($env{'course.'.$env{'request.course.id'}.'.internal.nopasswdchg'}) {
6762: my ($cnum,$cdom) = &get_course_identity();
6763: if ((&Apache::lonnet::is_course_owner($cdom,$cnum)) && ($udom eq $env{'user.domain'})) {
1.199 raeburn 6764: my @userstatuses = ('default');
6765: my %userenv = &Apache::lonnet::userenvironment($udom,$uname,'inststatus');
6766: if ($userenv{'inststatus'} ne '') {
6767: @userstatuses = split(/:/,$userenv{'inststatus'});
6768: }
6769: my $noupdate = 1;
6770: my %passwdconf = &Apache::lonnet::get_passwdconf($cdom);
6771: if (ref($passwdconf{'crsownerchg'}) eq 'HASH') {
6772: if (ref($passwdconf{'crsownerchg'}{'for'}) eq 'ARRAY') {
6773: foreach my $status (@userstatuses) {
6774: if (grep(/^\Q$status\E$/,@{$passwdconf{'crsownerchg'}{'for'}})) {
6775: undef($noupdate);
6776: last;
6777: }
6778: }
6779: }
6780: }
6781: if ($noupdate) {
6782: return;
6783: }
1.195 raeburn 6784: my %owned = &Apache::lonnet::courseiddump($cdom,'.',1,'.',
6785: $env{'user.name'}.':'.$env{'user.domain'},
6786: undef,undef,undef,'.');
6787: my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
6788: ['active','future']);
6789: foreach my $key (keys(%roleshash)) {
6790: my ($name,$domain,$role) = split(/:/,$key);
6791: if ($role eq 'st') {
6792: next if (($name eq $cnum) && ($domain eq $cdom));
6793: if ($owned{$domain.'_'.$name}) {
6794: if (ref($owned{$domain.'_'.$name}) eq 'HASH') {
6795: if ($owned{$domain.'_'.$name}{'nopasswdchg'}) {
6796: $noupdate = 1;
6797: last;
6798: }
6799: }
6800: } else {
6801: $noupdate = 1;
6802: last;
6803: }
6804: } else {
6805: $noupdate = 1;
6806: last;
6807: }
6808: }
6809: unless ($noupdate) {
6810: $canchange = 1;
6811: }
6812: }
6813: }
6814: }
6815: return $canchange;
6816: }
6817:
1.18 raeburn 6818: sub check_usertype {
1.134 raeburn 6819: my ($dom,$uname,$rules,$curr_rules,$got_rules) = @_;
1.18 raeburn 6820: my $usertype;
1.134 raeburn 6821: if ((ref($got_rules) eq 'HASH') && (ref($curr_rules) eq 'HASH')) {
6822: if (!$got_rules->{$dom}) {
6823: my %domconfig = &Apache::lonnet::get_dom('configuration',
6824: ['usercreation'],$dom);
6825: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6826: foreach my $item ('username','id') {
6827: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
6828: $curr_rules->{$dom}{$item} =
6829: $domconfig{'usercreation'}{$item.'_rule'};
6830: }
6831: }
6832: }
6833: $got_rules->{$dom} = 1;
6834: }
6835: if (ref($rules) eq 'HASH') {
6836: my @user_rules;
6837: if (ref($curr_rules->{$dom}{'username'}) eq 'ARRAY') {
6838: foreach my $rule (keys(%{$rules})) {
6839: if (grep(/^\Q$rule\E/,@{$curr_rules->{$dom}{'username'}})) {
6840: push(@user_rules,$rule);
6841: }
6842: }
6843: }
6844: if (@user_rules > 0) {
6845: my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
6846: if (keys(%rule_check) > 0) {
6847: $usertype = 'unofficial';
6848: foreach my $item (keys(%rule_check)) {
6849: if ($rule_check{$item}) {
6850: $usertype = 'official';
6851: last;
6852: }
1.18 raeburn 6853: }
6854: }
6855: }
6856: }
6857: }
6858: return $usertype;
6859: }
6860:
1.17 raeburn 6861: sub roles_by_context {
1.101 raeburn 6862: my ($context,$custom,$crstype) = @_;
1.17 raeburn 6863: my @allroles;
6864: if ($context eq 'course') {
1.99 raeburn 6865: @allroles = ('st');
6866: if ($env{'request.role'} =~ m{^dc\./}) {
6867: push(@allroles,'ad');
6868: }
1.101 raeburn 6869: push(@allroles,('ta','ep','in'));
6870: if ($crstype eq 'Community') {
6871: push(@allroles,'co');
6872: } else {
6873: push(@allroles,'cc');
6874: }
1.17 raeburn 6875: if ($custom) {
6876: push(@allroles,'cr');
6877: }
6878: } elsif ($context eq 'author') {
6879: @allroles = ('ca','aa');
6880: } elsif ($context eq 'domain') {
1.182 raeburn 6881: @allroles = ('li','ad','dg','dh','da','sc','au','dc');
1.17 raeburn 6882: }
6883: return @allroles;
6884: }
6885:
1.16 raeburn 6886: sub get_permission {
1.101 raeburn 6887: my ($context,$crstype) = @_;
1.16 raeburn 6888: my %permission;
6889: if ($context eq 'course') {
1.17 raeburn 6890: my $custom = 1;
1.101 raeburn 6891: my @allroles = &roles_by_context($context,$custom,$crstype);
1.17 raeburn 6892: foreach my $role (@allroles) {
6893: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
6894: $permission{'cusr'} = 1;
6895: last;
6896: }
1.16 raeburn 6897: }
6898: if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
6899: $permission{'custom'} = 1;
6900: }
6901: if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
6902: $permission{'view'} = 1;
6903: }
6904: if (!$permission{'view'}) {
6905: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
6906: $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
6907: if ($permission{'view'}) {
6908: $permission{'view_section'} = $env{'request.course.sec'};
6909: }
6910: }
1.17 raeburn 6911: if (!$permission{'cusr'}) {
6912: if ($env{'request.course.sec'} ne '') {
6913: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
6914: $permission{'cusr'} = (&Apache::lonnet::allowed('cst',$scope));
6915: if ($permission{'cusr'}) {
6916: $permission{'cusr_section'} = $env{'request.course.sec'};
6917: }
6918: }
6919: }
1.16 raeburn 6920: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
6921: $permission{'grp_manage'} = 1;
6922: }
1.165 raeburn 6923: if ($permission{'cusr'}) {
6924: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6925: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6926: my %coursehash = (
6927: 'internal.selfenrollmgrdc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrdc'},
6928: 'internal.selfenrollmgrcc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrcc'},
6929: 'internal.coursecode' => $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},
6930: 'internal.textbook' =>$env{'course.'.$env{'request.course.id'}.'.internal.textbook'},
6931: );
6932: my ($managed_by_cc,$managed_by_dc) = &selfenrollment_administration($cdom,$cnum,$crstype,\%coursehash);
6933: if (ref($managed_by_cc) eq 'ARRAY') {
6934: if (@{$managed_by_cc}) {
6935: $permission{'selfenrolladmin'} = 1;
6936: }
6937: }
1.216 raeburn 6938: unless ($permission{'selfenrolladmin'}) {
6939: $permission{'selfenrollview'} = 1;
6940: }
1.165 raeburn 6941: }
1.180 raeburn 6942: if ($env{'request.course.id'}) {
1.195 raeburn 6943: my $user;
6944: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
6945: $user = $env{'user.name'}.':'.$env{'user.domain'};
6946: }
1.180 raeburn 6947: if (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'} eq
6948: $user)) {
6949: $permission{'owner'} = 1;
1.195 raeburn 6950: if (&Apache::lonnet::allowed('mip',$env{'request.course.id'})) {
6951: $permission{'mip'} = 1;
6952: }
1.180 raeburn 6953: } elsif (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.co-owners'} ne '')) {
6954: if (grep(/^\Q$user\E$/,split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.co-owners'}))) {
6955: $permission{'co-owner'} = 1;
6956: }
6957: }
6958: }
1.16 raeburn 6959: } elsif ($context eq 'author') {
1.218 raeburn 6960: my $audom = $env{'request.role.domain'};
6961: my $auname = $env{'user.name'};
6962: if ((&Apache::lonnet::allowed('cca',"$audom/$auname")) ||
6963: (&Apache::lonnet::allowed('caa',"$audom/$auname"))) {
6964: $permission{'author'} = 1;
6965: $permission{'cusr'} = 1;
6966: $permission{'view'} = 1;
6967: }
6968: } elsif ($context eq 'coauthor') {
6969: my ($audom,$auname) = ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$});
6970: if ((&Apache::lonnet::allowed('vca',"$audom/$auname")) ||
6971: (&Apache::lonnet::allowed('vaa',"$audom/$auname"))) {
6972: if ($env{"environment.internal.manager./$audom/$auname"}) {
6973: $permission{'cusr'} = 1;
6974: $permission{'view'} = 1;
6975: }
6976: }
1.16 raeburn 6977: } else {
1.17 raeburn 6978: my @allroles = &roles_by_context($context);
6979: foreach my $role (@allroles) {
1.28 raeburn 6980: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
6981: $permission{'cusr'} = 1;
1.17 raeburn 6982: last;
6983: }
6984: }
6985: if (!$permission{'cusr'}) {
6986: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
6987: $permission{'cusr'} = 1;
6988: }
1.16 raeburn 6989: }
6990: if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
6991: $permission{'custom'} = 1;
6992: }
1.176 raeburn 6993: if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
6994: $permission{'activity'} = 1;
6995: }
1.178 raeburn 6996: if (&Apache::lonnet::allowed('vur',$env{'request.role.domain'})) {
6997: $permission{'view'} = 1;
6998: }
1.180 raeburn 6999: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
7000: $permission{'owner'} = 1;
7001: }
1.16 raeburn 7002: }
7003: my $allowed = 0;
1.211 raeburn 7004: foreach my $key (keys(%permission)) {
1.218 raeburn 7005: next if (($key eq 'owner') || ($key eq 'co-owner') || ($key eq 'author'));
1.211 raeburn 7006: if ($permission{$key}) { $allowed=1; last; }
1.16 raeburn 7007: }
7008: return (\%permission,$allowed);
7009: }
7010:
7011: # ==================================================== Figure out author access
7012:
7013: sub authorpriv {
7014: my ($auname,$audom)=@_;
7015: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
7016: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; } return 1;
7017: }
7018:
1.218 raeburn 7019: sub coauthorpriv {
7020: my ($auname,$audom)=@_;
7021: my $uname = $env{'user.name'};
7022: my $udom = $env{'user.domain'};
7023: if (((&Apache::lonnet::allowed('vca',"$udom/$uname")) ||
7024: (&Apache::lonnet::allowed('vaa',"$udom/$uname"))) &&
7025: ($env{"environment.internal.manager./$audom/$auname"})) {
7026: return 1;
7027: }
7028: return '';
7029: }
7030:
1.27 raeburn 7031: sub roles_on_upload {
1.101 raeburn 7032: my ($context,$setting,$crstype,%customroles) = @_;
1.27 raeburn 7033: my (@possible_roles,@permitted_roles);
1.101 raeburn 7034: @possible_roles = &curr_role_permissions($context,$setting,1,$crstype);
1.27 raeburn 7035: foreach my $role (@possible_roles) {
7036: if ($role eq 'cr') {
7037: push(@permitted_roles,keys(%customroles));
7038: } else {
7039: push(@permitted_roles,$role);
7040: }
7041: }
1.42 raeburn 7042: return @permitted_roles;
1.27 raeburn 7043: }
7044:
1.17 raeburn 7045: sub get_course_identity {
7046: my ($cid) = @_;
7047: my ($cnum,$cdom,$cdesc);
7048: if ($cid eq '') {
7049: $cid = $env{'request.course.id'}
7050: }
7051: if ($cid ne '') {
7052: $cnum = $env{'course.'.$cid.'.num'};
7053: $cdom = $env{'course.'.$cid.'.domain'};
7054: $cdesc = $env{'course.'.$cid.'.description'};
7055: if ($cnum eq '' || $cdom eq '') {
7056: my %coursehash =
7057: &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
7058: $cdom = $coursehash{'domain'};
7059: $cnum = $coursehash{'num'};
7060: $cdesc = $coursehash{'description'};
7061: }
7062: }
7063: return ($cnum,$cdom,$cdesc);
7064: }
7065:
1.19 raeburn 7066: sub dc_setcourse_js {
1.196 raeburn 7067: my ($formname,$mode,$context,$showcredits,$domain) = @_;
1.37 raeburn 7068: my ($dc_setcourse_code,$authen_check);
1.19 raeburn 7069: my $cctext = &Apache::lonnet::plaintext('cc');
1.103 raeburn 7070: my $cotext = &Apache::lonnet::plaintext('co');
1.19 raeburn 7071: my %alerts = §ioncheck_alerts();
7072: my $role = 'role';
7073: if ($mode eq 'upload') {
7074: $role = 'courserole';
1.37 raeburn 7075: } else {
1.196 raeburn 7076: $authen_check = &verify_authen($formname,$context,$domain);
1.19 raeburn 7077: }
7078: $dc_setcourse_code = (<<"SCRIPTTOP");
1.37 raeburn 7079: $authen_check
7080:
1.19 raeburn 7081: function setCourse() {
7082: var course = document.$formname.dccourse.value;
7083: if (course != "") {
7084: if (document.$formname.dcdomain.value != document.$formname.origdom.value) {
7085: alert("$alerts{'curd'}");
7086: return;
7087: }
7088: var userrole = document.$formname.$role.options[document.$formname.$role.selectedIndex].value
7089: var section="";
7090: var numsections = 0;
7091: var newsecs = new Array();
7092: for (var i=0; i<document.$formname.currsec.length; i++) {
7093: if (document.$formname.currsec.options[i].selected == true ) {
7094: if (document.$formname.currsec.options[i].value != "" && document.$formname.currsec.options[i].value != null) {
7095: if (numsections == 0) {
7096: section = document.$formname.currsec.options[i].value
7097: numsections = 1;
7098: }
7099: else {
7100: section = section + "," + document.$formname.currsec.options[i].value
7101: numsections ++;
7102: }
7103: }
7104: }
7105: }
7106: if (document.$formname.newsec.value != "" && document.$formname.newsec.value != null) {
7107: if (numsections == 0) {
7108: section = document.$formname.newsec.value
7109: }
7110: else {
7111: section = section + "," + document.$formname.newsec.value
7112: }
7113: newsecs = document.$formname.newsec.value.split(/,/g);
7114: numsections = numsections + newsecs.length;
7115: }
7116: if ((userrole == 'st') && (numsections > 1)) {
1.103 raeburn 7117: if (document.$formname.crstype.value == 'Community') {
7118: alert("$alerts{'inco'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
7119: } else {
7120: alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
7121: }
1.19 raeburn 7122: return;
7123: }
7124: for (var j=0; j<newsecs.length; j++) {
7125: if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
7126: alert("'"+newsecs[j]+"' $alerts{'mayn'}.\\n$alerts{'plsc'}.");
7127: return;
7128: }
7129: if (document.$formname.groups.value != '') {
7130: var groups = document.$formname.groups.value.split(/,/g);
7131: for (var k=0; k<groups.length; k++) {
7132: if (newsecs[j] == groups[k]) {
1.103 raeburn 7133: if (document.$formname.crstype.value == 'Community') {
7134: alert("'"+newsecs[j]+"' $alerts{'mayc'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
7135: } else {
7136: alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
7137: }
1.19 raeburn 7138: return;
7139: }
7140: }
7141: }
7142: }
7143: if ((userrole == 'cc') && (numsections > 0)) {
7144: alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
7145: section = "";
7146: }
1.103 raeburn 7147: if ((userrole == 'co') && (numsections > 0)) {
7148: alert("$alerts{'secd'} $cotext $alerts{'role'}.\\n$alerts{'accr'}.");
7149: section = "";
7150: }
1.19 raeburn 7151: SCRIPTTOP
7152: if ($mode ne 'upload') {
1.150 raeburn 7153: $dc_setcourse_code .= (<<"SCRIPTMID");
1.19 raeburn 7154: var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
7155: var numcourse = getIndex(document.$formname.dccourse);
7156: if (numcourse == "-1") {
1.103 raeburn 7157: if (document.$formname.type == 'Community') {
7158: alert("$alerts{'thwc'}");
7159: } else {
7160: alert("$alerts{'thwa'}");
7161: }
1.19 raeburn 7162: return;
7163: }
7164: else {
7165: document.$formname.elements[numcourse].name = "act"+coursename;
7166: var numnewsec = getIndex(document.$formname.newsec);
7167: if (numnewsec != "-1") {
7168: document.$formname.elements[numnewsec].name = "sec"+coursename;
7169: document.$formname.elements[numnewsec].value = section;
7170: }
7171: var numstart = getIndex(document.$formname.start);
7172: if (numstart != "-1") {
7173: document.$formname.elements[numstart].name = "start"+coursename;
7174: }
7175: var numend = getIndex(document.$formname.end);
7176: if (numend != "-1") {
7177: document.$formname.elements[numend].name = "end"+coursename
7178: }
1.150 raeburn 7179: SCRIPTMID
7180: if ($showcredits) {
7181: $dc_setcourse_code .= <<ENDCRED;
7182: var numcredits = getIndex(document.$formname.credits);
7183: if (numcredits != "-1") {
7184: document.$formname.elements[numcredits].name = "credits"+coursename;
7185: }
7186: ENDCRED
7187: }
7188: $dc_setcourse_code .= <<ENDSCRIPT;
1.19 raeburn 7189: }
7190: }
1.37 raeburn 7191: var authcheck = auth_check();
7192: if (authcheck == 'ok') {
7193: document.$formname.submit();
7194: }
1.19 raeburn 7195: }
7196: ENDSCRIPT
7197: } else {
7198: $dc_setcourse_code .= "
7199: document.$formname.sections.value = section;
7200: }
7201: return 'ok';
7202: }
7203: ";
7204: }
7205: $dc_setcourse_code .= (<<"ENDSCRIPT");
7206:
7207: function getIndex(caller) {
7208: for (var i=0;i<document.$formname.elements.length;i++) {
7209: if (document.$formname.elements[i] == caller) {
7210: return i;
7211: }
7212: }
7213: return -1;
7214: }
7215: ENDSCRIPT
1.37 raeburn 7216: return $dc_setcourse_code;
7217: }
7218:
7219: sub verify_authen {
1.196 raeburn 7220: my ($formname,$context,$domain) = @_;
1.37 raeburn 7221: my %alerts = &authcheck_alerts();
7222: my $finish = "return 'ok';";
7223: if ($context eq 'author') {
7224: $finish = "document.$formname.submit();";
7225: }
1.196 raeburn 7226: my ($numrules,$intargjs) =
1.210 raeburn 7227: &Apache::loncommon::passwd_validation_js('argpicked',$domain);
1.37 raeburn 7228: my $outcome = <<"ENDSCRIPT";
7229:
7230: function auth_check() {
7231: var logintype;
7232: if (document.$formname.login.length) {
7233: if (document.$formname.login.length > 0) {
7234: var loginpicked = 0;
7235: for (var i=0; i<document.$formname.login.length; i++) {
7236: if (document.$formname.login[i].checked == true) {
7237: loginpicked = 1;
7238: logintype = document.$formname.login[i].value;
7239: }
7240: }
7241: if (loginpicked == 0) {
7242: alert("$alerts{'authen'}");
7243: return;
7244: }
7245: }
7246: } else {
7247: logintype = document.$formname.login.value;
7248: }
7249: if (logintype == 'nochange') {
7250: return 'ok';
7251: }
7252: var argpicked = document.$formname.elements[logintype+'arg'].value;
7253: if ((argpicked == null) || (argpicked == '') || (typeof argpicked == 'undefined')) {
7254: var alertmsg = '';
7255: switch (logintype) {
7256: case 'krb':
7257: alertmsg = '$alerts{'krb'}';
7258: break;
7259: case 'int':
7260: alertmsg = '$alerts{'ipass'}';
1.196 raeburn 7261: break;
1.37 raeburn 7262: case 'fsys':
7263: alertmsg = '$alerts{'ipass'}';
7264: break;
7265: case 'loc':
7266: alertmsg = '';
7267: break;
7268: default:
7269: alertmsg = '';
7270: }
7271: if (alertmsg != '') {
7272: alert(alertmsg);
7273: return;
7274: }
1.196 raeburn 7275: } else if (logintype == 'int') {
7276: var numrules = $numrules;
7277: if (numrules > 0) {
7278: $intargjs
7279: }
1.37 raeburn 7280: }
7281: $finish
7282: }
7283: ENDSCRIPT
1.19 raeburn 7284: }
7285:
7286: sub sectioncheck_alerts {
7287: my %alerts = &Apache::lonlocal::texthash(
1.103 raeburn 7288: curd => 'You must select a course or community in the current domain',
1.19 raeburn 7289: inea => 'In each course, each user may only have one student role at a time',
1.103 raeburn 7290: inco => 'In each community, each user may only have one member role at a time',
1.19 raeburn 7291: youh => 'You had selected',
7292: sect => 'sections',
7293: plsm => 'Please modify your selections so they include no more than one section',
7294: mayn => 'may not be used as the name for a section, as it is a reserved word',
7295: plsc => 'Please choose a different section name',
7296: mayt => 'may not be used as the name for a section, as it is the name of a course group',
1.103 raeburn 7297: mayc => 'may not be used as the name for a section, as it is the name of a community group',
1.19 raeburn 7298: secn => 'Section names and group names must be distinct',
7299: secd => 'Section designations do not apply to ',
7300: role => 'roles',
7301: accr => 'role will be added with access to all sections',
1.103 raeburn 7302: thwa => 'There was a problem with your course selection',
7303: thwc => 'There was a problem with your community selection',
1.19 raeburn 7304: );
1.170 damieng 7305: &js_escape(\%alerts);
1.19 raeburn 7306: return %alerts;
7307: }
1.17 raeburn 7308:
1.37 raeburn 7309: sub authcheck_alerts {
7310: my %alerts =
7311: &Apache::lonlocal::texthash(
7312: authen => 'You must choose an authentication type.',
7313: krb => 'You need to specify the Kerberos domain.',
7314: ipass => 'You need to specify the initial password.',
7315: );
1.170 damieng 7316: &js_escape(\%alerts);
1.37 raeburn 7317: return %alerts;
7318: }
7319:
1.141 raeburn 7320: sub is_courseowner {
7321: my ($thiscourse,$courseowner) = @_;
7322: if ($courseowner eq '') {
7323: if ($env{'request.course.id'} eq $thiscourse) {
7324: $courseowner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
7325: }
7326: }
7327: if ($courseowner ne '') {
7328: if ($courseowner eq $env{'user.name'}.':'.$env{'user.domain'}) {
7329: return 1;
7330: }
7331: }
7332: return;
7333: }
7334:
1.165 raeburn 7335: sub get_selfenroll_titles {
7336: my @row = ('types','registered','enroll_dates','access_dates','section',
7337: 'approval','limit');
7338: my %lt = &Apache::lonlocal::texthash (
7339: types => 'Users allowed to self-enroll',
7340: registered => 'Registration status (official courses)' ,
7341: enroll_dates => 'Dates self-enrollment available',
7342: access_dates => 'Access dates for self-enrolling users',
7343: section => "Self-enrolling users' section",
7344: approval => 'Processing of requests',
7345: limit => 'Enrollment limit',
7346: );
7347: return (\@row,\%lt);
7348: }
7349:
7350: sub selfenroll_default_descs {
7351: my %desc = (
7352: types => {
7353: dom => &mt('Course domain'),
7354: all => &mt('Any domain'),
7355: '' => &mt('None'),
7356: },
7357: limit => {
7358: none => &mt('No limit'),
7359: allstudents => &mt('Limit by total students'),
7360: selfenrolled => &mt('Limit by total self-enrolled'),
7361: },
7362: approval => {
7363: '0' => &mt('Processed automatically'),
7364: '1' => &mt('Queued for approval'),
7365: '2' => &mt('Queued, pending validation'),
7366: },
7367: registered => {
7368: 0 => 'No registration required',
7369: 1 => 'Registered students only',
7370: },
7371: );
7372: return %desc;
7373: }
7374:
7375: sub selfenroll_validation_types {
7376: my @items = ('url','fields','button','markup');
7377: my %names = &Apache::lonlocal::texthash (
7378: url => 'Web address of validation server/script',
7379: fields => 'Form fields to send to validator',
7380: button => 'Text for validation button',
7381: markup => 'Validation description (HTML)',
7382: );
1.167 raeburn 7383: my @fields = ('username','domain','uniquecode','course','coursetype','description');
1.165 raeburn 7384: return (\@items,\%names,\@fields);
7385: }
7386:
7387: sub get_extended_type {
7388: my ($cdom,$cnum,$crstype,$current) = @_;
7389: my $type = 'unofficial';
7390: my %settings;
7391: if (ref($current) eq 'HASH') {
7392: %settings = %{$current};
7393: } else {
7394: %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook'],$cdom,$cnum);
7395: }
7396: if ($crstype eq 'Community') {
7397: $type = 'community';
1.173 raeburn 7398: } elsif ($crstype eq 'Placement') {
7399: $type = 'placement';
1.165 raeburn 7400: } elsif ($settings{'internal.coursecode'}) {
7401: $type = 'official';
7402: } elsif ($settings{'internal.textbook'}) {
7403: $type = 'textbook';
7404: }
7405: return $type;
7406: }
7407:
7408: sub selfenrollment_administration {
7409: my ($cdom,$cnum,$crstype,$coursehash) = @_;
7410: my %settings;
7411: if (ref($coursehash) eq 'HASH') {
7412: %settings = %{$coursehash};
7413: } else {
7414: %settings = &Apache::lonnet::get('environment',
7415: ['internal.selfenrollmgrdc','internal.selfenrollmgrcc',
7416: 'internal.coursecode','internal.textbook'],$cdom,$cnum);
7417: }
7418: my ($possconfigs) = &get_selfenroll_titles();
7419: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
7420: my $selfenrolltype = &get_extended_type($cdom,$cnum,$crstype,\%settings);
7421:
7422: my (@in_course,@in_domain);
7423: if ($settings{'internal.selfenrollmgrcc'} ne '') {
7424: @in_course = split(/,/,$settings{'internal.selfenrollmgrcc'});
7425: my @diffs = &Apache::loncommon::compare_arrays($possconfigs,\@in_course);
7426: unless (@diffs) {
7427: return (\@in_course,\@in_domain);
7428: }
7429: }
7430: if ($settings{'internal.selfenrollmgrdc'} ne '') {
1.215 raeburn 7431: @in_domain = split(/,/,$settings{'internal.selfenrollmgrdc'});
1.165 raeburn 7432: my @diffs = &Apache::loncommon::compare_arrays(\@in_domain,$possconfigs);
7433: unless (@diffs) {
7434: return (\@in_course,\@in_domain);
7435: }
7436: }
7437: my @combined = @in_course;
7438: push(@combined,@in_domain);
7439: my @diffs = &Apache::loncommon::compare_arrays(\@combined,$possconfigs);
7440: unless (@diffs) {
7441: return (\@in_course,\@in_domain);
7442: }
7443: if ($domdefaults{$selfenrolltype.'selfenrolladmdc'} eq '') {
7444: push(@in_course,@diffs);
7445: } else {
7446: my @defaultdc = split(/,/,$domdefaults{$selfenrolltype.'selfenrolladmdc'});
7447: foreach my $item (@diffs) {
7448: if (grep(/^\Q$item\E$/,@defaultdc)) {
7449: push(@in_domain,$item);
7450: } else {
7451: push(@in_course,$item);
7452: }
7453: }
7454: }
7455: return (\@in_course,\@in_domain);
7456: }
7457:
1.175 raeburn 7458: sub custom_role_header {
7459: my ($context,$crstype,$templaterolerefs,$prefix) = @_;
7460: my %lt = &Apache::lonlocal::texthash(
7461: sele => 'Select a Template',
7462: );
7463: my ($context_code,$button_code);
7464: if ($context eq 'domain') {
7465: $context_code = &custom_coursetype_switch($crstype,$prefix);
7466: }
7467: if (ref($templaterolerefs) eq 'ARRAY') {
7468: foreach my $role (@{$templaterolerefs}) {
7469: my $display = 'inline';
7470: if (($context eq 'domain') && ($role eq 'co')) {
7471: $display = 'none';
7472: }
7473: $button_code .= &make_button_code($role,$crstype,$display,$prefix).' ';
7474: }
7475: }
7476: return <<"END";
7477: <div class="LC_left_float">
7478: <fieldset>
7479: <legend>$lt{'sele'}</legend>
7480: $button_code
7481: </fieldset></div>
7482: $context_code
7483: <br clear="all" />
7484: END
7485: }
7486:
7487: sub custom_coursetype_switch {
7488: my ($crstype,$prefix) = @_;
7489: my ($checkedcourse,$checkedcommunity);
7490: if ($crstype eq 'Community') {
7491: $checkedcommunity = ' checked="checked"';
7492: } else {
7493: $checkedcourse = ' checked="checked"';
7494: }
7495: my %lt = &Apache::lonlocal::texthash(
7496: cont => 'Context',
7497: cour => 'Course',
7498: comm => 'Community',
7499: );
7500: return <<"END";
7501: <div class="LC_left_float">
7502: <fieldset>
7503: <legend>$lt{'cont'}</legend>
7504: <label>
7505: <input type="radio" name="${prefix}_custrolecrstype" value="Course"$checkedcourse onclick="javascript:customSwitchType('$prefix');" />
7506: $lt{'cour'}
7507: </label>
7508: <label>
7509: <input type="radio" name="${prefix}_custrolecrstype" value="Community"$checkedcommunity onclick="javascript:customSwitchType('$prefix');" />
7510: $lt{'comm'}
7511: </label>
7512: </fieldset>
7513: </div>
7514: END
7515: }
7516:
7517: sub custom_role_table {
1.180 raeburn 7518: my ($crstype,$full,$levels,$levelscurrent,$prefix,$add_class,$id) = @_;
1.175 raeburn 7519: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7520: (ref($levelscurrent) eq 'HASH'));
7521: my %lt=&Apache::lonlocal::texthash (
7522: 'prv' => "Privilege",
7523: 'crl' => "Course Level",
7524: 'dml' => "Domain Level",
7525: 'ssl' => "System Level");
7526: my %cr = (
7527: course => '_c',
7528: domain => '_d',
7529: system => '_s',
7530: );
7531:
1.180 raeburn 7532: my $output=&Apache::loncommon::start_data_table($add_class,$id).
1.175 raeburn 7533: &Apache::loncommon::start_data_table_header_row().
7534: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
7535: '</th><th>'.$lt{'ssl'}.'</th>'.
7536: &Apache::loncommon::end_data_table_header_row();
7537: foreach my $priv (sort(keys(%{$full}))) {
7538: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7539: $output .= &Apache::loncommon::start_data_table_row().
7540: '<td><span id="'.$prefix.$priv.'">'.$privtext.'</span></td>';
7541: foreach my $type ('course','domain','system') {
7542: if (($type eq 'system') && ($priv eq 'bre') && ($crstype eq 'Community')) {
7543: $output .= '<td> </td>';
7544: } else {
7545: $output .= '<td>'.
7546: ($levels->{$type}{$priv}?'<input type="checkbox" id="'.$prefix.$priv.$cr{$type}.'"'.
7547: ' name="'.$prefix.$priv.$cr{$type}.'"'.
7548: ($levelscurrent->{$type}{$priv}?' checked="checked"':'').' />':' ').
7549: '</td>';
7550: }
7551: }
7552: $output .= &Apache::loncommon::end_data_table_row();
7553: }
7554: $output .= &Apache::loncommon::end_data_table();
7555: return $output;
7556: }
7557:
7558: sub custom_role_privs {
7559: my ($privs,$full,$levels,$levelscurrent)= @_;
7560: return unless ((ref($privs) eq 'HASH') && (ref($full) eq 'HASH') &&
7561: (ref($levels) eq 'HASH') && (ref($levelscurrent) eq 'HASH'));
7562: my %cr = (
7563: course => 'cr:c',
7564: domain => 'cr:d',
7565: system => 'cr:s',
7566: );
7567: foreach my $type ('course','domain','system') {
7568: foreach my $item (split(/\:/,$Apache::lonnet::pr{$cr{$type}})) {
7569: my ($priv,$restrict)=split(/\&/,$item);
7570: if (!$restrict) { $restrict='F'; }
7571: $levels->{$type}->{$priv}=$restrict;
7572: if ($privs->{$type}=~/\:$priv/) {
7573: $levelscurrent->{$type}->{$priv}=1;
7574: }
7575: $full->{$priv}=1;
7576: }
7577: }
7578: return;
7579: }
7580:
7581: sub custom_template_roles {
7582: my ($context,$crstype) = @_;
7583: my @template_roles = ("in","ta","ep");
7584: if (($context eq 'domain') || ($context eq 'domprefs')) {
7585: push(@template_roles,"ad");
7586: }
7587: push(@template_roles,"st");
7588: if ($context eq 'domain') {
7589: unshift(@template_roles,('co','cc'));
7590: } else {
7591: if ($crstype eq 'Community') {
7592: unshift(@template_roles,'co');
7593: } else {
7594: unshift(@template_roles,'cc');
7595: }
7596: }
7597: return @template_roles;
7598: }
7599:
7600: sub custom_roledefs_js {
7601: my ($context,$crstype,$formname,$full,$templaterolesref,$jsback) = @_;
7602: my $button_code = "\n";
7603: my $head_script = "\n";
7604: my (%roletitlestr,$rolenamestr);
7605: my %role_titles = (
7606: Course => [],
7607: Community => [],
7608: );
7609: $head_script .= '<script type="text/javascript">'."\n"
7610: .'// <![CDATA['."\n";
7611: if (ref($templaterolesref) eq 'ARRAY') {
7612: if ($context eq 'domain') {
7613: $rolenamestr = join("','",@{$templaterolesref});
7614: }
7615: foreach my $role (@{$templaterolesref}) {
7616: $head_script .= &make_script_template($role,$crstype,$formname);
7617: if ($context eq 'domain') {
7618: foreach my $type ('Course','Community') {
7619: push(@{$role_titles{$type}},&Apache::lonnet::plaintext($role,$type));
7620: }
7621: }
7622: }
7623: }
7624: if ($context eq 'domain') {
7625: foreach my $type ('Course','Community') {
7626: $roletitlestr{$type} = join("','",@{$role_titles{$type}});
7627: }
7628: my %pt = (
7629: Community => {
7630: cst => &mt('Grant/revoke role of Member'),
7631: mdc => &mt('Edit community contents'),
7632: pch => &mt('Post discussion on community resources'),
7633: pfo => &mt('Print for other users and entire community'),
7634: },
7635: Course => {
7636: cst => &mt('Grant/revoke role of Student'),
7637: mdc => &mt('Edit course contents'),
7638: pch => &mt('Post discussion on course resources'),
7639: pfo => &mt('Print for other users and entire course'),
7640: },
7641: );
7642: $head_script .= <<"ENDJS";
7643: function customSwitchType(prefix) {
7644: var privnames = new Array('cst','mdc','pch','pfo');
7645: var privtxtcrs = new Array('$pt{Course}{cst}','$pt{Course}{mdc}','$pt{Course}{pch}','$pt{Course}{pfo}');
7646: var privtxtcom = new Array('$pt{Community}{cst}','$pt{Community}{mdc}','$pt{Community}{pch}','$pt{Community}{pfo}');
7647: var rolenames = new Array('$rolenamestr');
7648: var rolescrs = new Array('$roletitlestr{Course}');
7649: var rolescom = new Array('$roletitlestr{Community}');
7650: var radio = prefix+'_custrolecrstype';
7651: if (document.$formname.elements[radio].length > 1) {
7652: for (var i=0; i<document.$formname.elements[radio].length; i++) {
7653: if (document.$formname.elements[radio][i].checked) {
7654: if ((document.getElementById(prefix+'bre_s')) && (document.getElementById(prefix+'bro_s'))) {
7655: if (document.$formname.elements[radio][i].value == 'Community') {
7656: if (document.getElementById(prefix+'bre_s').checked) {
7657: document.getElementById(prefix+'bro_s').checked = true;
7658: document.getElementById(prefix+'bre_s').checked = false;
7659:
7660: }
7661: document.getElementById(prefix+'bre_s').style.visibility = 'hidden';
7662: } else {
7663: document.getElementById(prefix+'bre_s').style.visibility = 'visible';
7664: if (document.getElementById(prefix+'bro_s').checked) {
7665: document.getElementById(prefix+'bre_s').checked = true;
7666: document.getElementById(prefix+'bro_s').checked = false;
7667: }
7668: }
7669: }
7670: for (var j=0; j<privnames.length; j++) {
7671: if (document.getElementById(prefix+privnames[j])) {
7672: if (document.getElementById(prefix+privnames[j])) {
7673: if (document.$formname.elements[radio][i].value == 'Course') {
7674: document.getElementById(prefix+privnames[j]).innerHTML = privtxtcrs[j];
7675: } else {
7676: document.getElementById(prefix+privnames[j]).innerHTML = privtxtcom[j];
7677: }
7678: }
7679: }
7680: }
7681: for (var j=0; j<rolenames.length; j++) {
7682: if (document.getElementById(prefix+rolenames[j])) {
7683: if (document.getElementById(prefix+rolenames[j])) {
7684: if (document.$formname.elements[radio][i].value == 'Course') {
7685: document.getElementById(prefix+rolenames[j]).value = rolescrs[j];
7686: if (rolenames[j] == 'cc') {
7687: document.getElementById(prefix+rolenames[j]).style.display = 'inline';
7688: }
7689: if (rolenames[j] == 'co') {
7690: document.getElementById(prefix+rolenames[j]).style.display = 'none';
7691: }
7692: } else {
7693: document.getElementById(prefix+rolenames[j]).value = rolescom[j];
7694: if (rolenames[j] == 'cc') {
7695: document.getElementById(prefix+rolenames[j]).style.display = 'none';
7696: }
7697: if (rolenames[j] == 'co') {
7698: document.getElementById(prefix+rolenames[j]).style.display = 'inline';
7699: }
7700: }
7701: }
7702: }
7703: }
7704: }
7705: }
7706: }
7707: return;
7708: }
7709: ENDJS
7710: }
7711: $head_script .= "\n".$jsback."\n"
7712: .'// ]]>'."\n"
7713: .'</script>'."\n";
7714: return $head_script;
7715: }
7716:
7717: # --------------------------------------------------------
7718: sub make_script_template {
7719: my ($role,$crstype,$formname) = @_;
7720: my $return_script = 'function set_'.$role.'(prefix) {'."\n";
7721: my (%full_by_level,%role_priv);
7722: foreach my $level ('c','d','s') {
7723: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
7724: next if (($level eq 's') && ($crstype eq 'Community') && ($item eq 'bre&S'));
7725: my ($priv,$restrict)=split(/\&/,$item);
7726: $full_by_level{$level}{$priv}=1;
7727: }
7728: $role_priv{$level} = {};
7729: my @temp = split(/:/,$Apache::lonnet::pr{$role.':'.$level});
7730: foreach my $priv (@temp) {
7731: my ($priv_item, $dummy) = split(/\&/,$priv);
7732: $role_priv{$level}{$priv_item} = 1;
7733: }
7734: }
7735: my %to_check = (
7736: c => ['c','d','s'],
7737: d => ['d','s'],
7738: s => ['s'],
7739: );
7740: foreach my $level ('c','d','s') {
7741: if (ref($full_by_level{$level}) eq 'HASH') {
7742: foreach my $priv (keys(%{$full_by_level{$level}})) {
7743: my $value = 'false';
7744: if (ref($to_check{$level}) eq 'ARRAY') {
7745: foreach my $lett (@{$to_check{$level}}) {
7746: if (exists($role_priv{$lett}{$priv})) {
7747: $value = 'true';
7748: last;
7749: }
7750: }
7751: $return_script .= "document.$formname.elements[prefix+'".$priv."_".$level."'].checked = $value;\n";
7752: }
7753: }
7754: }
7755: }
7756: $return_script .= '}'."\n";
7757: return ($return_script);
7758: }
7759: # ----------------------------------------------------------
7760: sub make_button_code {
7761: my ($role,$crstype,$display,$prefix) = @_;
7762: my $label = &Apache::lonnet::plaintext($role,$crstype);
7763: my $button_code = '<input type="button" onclick="set_'.$role."('$prefix'".')" '.
7764: 'id="'.$prefix.$role.'" value="'.$label.'" '.
7765: 'style="display:'.$display.'" />';
7766: return ($button_code);
7767: }
7768:
7769: sub custom_role_update {
7770: my ($rolename,$prefix) = @_;
7771: # ------------------------------------------------------- What can be assigned?
7772: my %privs = (
7773: c => '',
7774: d => '',
7775: s => '',
7776: );
7777: foreach my $level (keys(%privs)) {
7778: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
7779: my ($priv,$restrict)=split(/\&/,$item);
7780: if (!$restrict) { $restrict=''; }
7781: if ($env{'form.'.$prefix.$priv.'_'.$level}) {
7782: $privs{$level} .=':'.$item;
7783: }
7784: }
7785: }
7786: return %privs;
7787: }
7788:
1.180 raeburn 7789: sub adhoc_status_types {
7790: my ($cdom,$context,$role,$selectedref,$othertitle,$usertypes,$types,$disabled) = @_;
7791: my $output = &Apache::loncommon::start_data_table();
7792: my $numinrow = 3;
7793: my $rem;
7794: if (ref($types) eq 'ARRAY') {
7795: for (my $i=0; $i<@{$types}; $i++) {
7796: if (defined($usertypes->{$types->[$i]})) {
7797: my $rem = $i%($numinrow);
7798: if ($rem == 0) {
7799: if ($i > 0) {
7800: $output .= &Apache::loncommon::end_data_table_row();
7801: }
7802: $output .= &Apache::loncommon::start_data_table_row();
7803: }
7804: my $check;
7805: if (ref($selectedref) eq 'ARRAY') {
7806: if (grep(/^\Q$types->[$i]\E$/,@{$selectedref})) {
7807: $check = ' checked="checked"';
7808: }
7809: }
7810: $output .= '<td>'.
7811: '<span class="LC_nobreak"><label>'.
7812: '<input type="checkbox" name="'.$context.$role.'_status" '.
7813: 'value="'.$types->[$i].'"'.$check.$disabled.' />'.
7814: $usertypes->{$types->[$i]}.'</label></span></td>';
7815: }
7816: }
7817: $rem = @{$types}%($numinrow);
7818: }
7819: my $colsleft = $numinrow - $rem;
7820: if (($rem == 0) && (@{$types} > 0)) {
7821: $output .= &Apache::loncommon::start_data_table_row();
7822: }
7823: if ($colsleft > 1) {
7824: $output .= '<td colspan="'.$colsleft.'">';
7825: } else {
7826: $output .= '<td>';
7827: }
7828: my $defcheck;
7829: if (ref($selectedref) eq 'ARRAY') {
7830: if (grep(/^default$/,@{$selectedref})) {
7831: $defcheck = ' checked="checked"';
7832: }
7833: }
7834: $output .= '<span class="LC_nobreak"><label>'.
7835: '<input type="checkbox" name="'.$context.$role.'_status"'.
7836: 'value="default"'.$defcheck.$disabled.' />'.
7837: $othertitle.'</label></span></td>'.
7838: &Apache::loncommon::end_data_table_row().
7839: &Apache::loncommon::end_data_table();
7840: return $output;
7841: }
7842:
7843: sub adhoc_staff {
7844: my ($access,$context,$role,$selectedref,$adhocref,$disabled) = @_;
7845: my $output;
7846: if (ref($adhocref) eq 'HASH') {
7847: my %by_fullname;
7848: my $numinrow = 4;
7849: my $rem;
7850: my @personnel = keys(%{$adhocref});
7851: if (@personnel) {
7852: foreach my $person (@personnel) {
7853: my ($uname,$udom) = split(/:/,$person);
7854: my $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
7855: $by_fullname{$fullname} = $person;
7856: }
7857: my @sorted = sort(keys(%by_fullname));
7858: my $count = scalar(@sorted);
7859: $output = &Apache::loncommon::start_data_table();
7860: for (my $i=0; $i<$count; $i++) {
7861: my $rem = $i%($numinrow);
7862: if ($rem == 0) {
7863: if ($i > 0) {
7864: $output .= &Apache::loncommon::end_data_table_row();
7865: }
7866: $output .= &Apache::loncommon::start_data_table_row();
7867: }
7868: my $check;
7869: my $user = $by_fullname{$sorted[$i]};
7870: if (ref($selectedref) eq 'ARRAY') {
7871: if (grep(/^\Q$user\E$/,@{$selectedref})) {
7872: $check = ' checked="checked"';
7873: }
7874: }
7875: if ($i == $count-1) {
7876: my $colsleft = $numinrow - $rem;
7877: if ($colsleft > 1) {
7878: $output .= '<td colspan="'.$colsleft.'">';
7879: } else {
7880: $output .= '<td>';
7881: }
7882: } else {
7883: $output .= '<td>';
7884: }
7885: $output .= '<span class="LC_nobreak"><label>'.
7886: '<input type="checkbox" name="'.$context.$role.'_staff_'.$access.'" '.
7887: 'value="'.$user.'"'.$check.$disabled.' />'.$sorted[$i].
7888: '</label></span></td>';
7889: if ($i == $count-1) {
7890: $output .= &Apache::loncommon::end_data_table_row();
7891: }
7892: }
7893: $output .= &Apache::loncommon::end_data_table();
7894: }
7895: }
7896: return $output;
7897: }
7898:
7899:
1.1 raeburn 7900: 1;
7901:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>