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