Annotation of loncom/interface/lonuserutils.pm, revision 1.225
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
1.225 ! raeburn 4: # $Id: lonuserutils.pm,v 1.224 2025/01/13 00:57:39 raeburn Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ###############################################################
30:
31: package Apache::lonuserutils;
32:
1.175 raeburn 33: =pod
34:
35: =head1 NAME
36:
37: Apache::lonuserutils.pm
38:
39: =head1 SYNOPSIS
40:
41: Utilities for management of users and custom roles
42:
43: Provides subroutines called by loncreateuser.pm
44:
45: =head1 OVERVIEW
46:
47: =cut
48:
1.1 raeburn 49: use strict;
50: use Apache::lonnet;
51: use Apache::loncommon();
52: use Apache::lonhtmlcommon;
1.212 raeburn 53: use Apache::loncoursequeueadmin;
1.1 raeburn 54: use Apache::lonlocal;
1.8 raeburn 55: use Apache::longroup;
1.174 raeburn 56: use HTML::Entities;
1.8 raeburn 57: use LONCAPA qw(:DEFAULT :match);
1.1 raeburn 58:
59: ###############################################################
60: ###############################################################
61: # Drop student from all sections of a course, except optional $csec
62: sub modifystudent {
1.52 raeburn 63: my ($udom,$unam,$courseid,$csec,$desiredhost,$context)=@_;
1.1 raeburn 64: # if $csec is undefined, drop the student from all the courses matching
65: # this one. If $csec is defined, drop them from all other sections of
66: # this course and add them to section $csec
1.17 raeburn 67: my ($cnum,$cdom) = &get_course_identity($courseid);
1.138 raeburn 68: my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
1.1 raeburn 69: my ($tmp) = keys(%roles);
70: # Bail out if we were unable to get the students roles
71: return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
72: # Go through the roles looking for enrollment in this course
73: my $result = '';
74: foreach my $course (keys(%roles)) {
75: if ($course=~m{^/\Q$cdom\E/\Q$cnum\E(?:\/)*(?:\s+)*(\w+)*\_st$}) {
76: # We are in this course
77: my $section=$1;
78: $section='' if ($course eq "/$cdom/$cnum".'_st');
79: if (defined($csec) && $section eq $csec) {
80: $result .= 'ok:';
81: } elsif ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
82: my (undef,$end,$start)=split(/\_/,$roles{$course});
83: my $now=time;
84: # if this is an active role
85: if (!($start && ($now<$start)) || !($end && ($now>$end))) {
86: my $reply=&Apache::lonnet::modifystudent
87: # dom name id mode pass f m l g
88: ($udom,$unam,'', '', '',undef,undef,undef,undef,
1.22 raeburn 89: $section,time,undef,undef,$desiredhost,'','manual',
1.52 raeburn 90: '',$courseid,'',$context);
1.1 raeburn 91: $result .= $reply.':';
92: }
93: }
94: }
95: }
96: if ($result eq '') {
1.37 raeburn 97: $result = &mt('Unable to find section for this student');
1.1 raeburn 98: } else {
99: $result =~ s/(ok:)+/ok/g;
100: }
101: return $result;
102: }
103:
104: sub modifyuserrole {
105: my ($context,$setting,$changeauth,$cid,$udom,$uname,$uid,$umode,$upass,
106: $first,$middle,$last,$gene,$sec,$forceid,$desiredhome,$email,$role,
1.220 raeburn 107: $end,$start,$checkid,$inststatus,$emptyok) = @_;
1.5 raeburn 108: my ($scope,$userresult,$authresult,$roleresult,$idresult);
1.1 raeburn 109: if ($setting eq 'course' || $context eq 'course') {
110: $scope = '/'.$cid;
111: $scope =~ s/\_/\//g;
1.103 raeburn 112: if (($role ne 'cc') && ($role ne 'co') && ($sec ne '')) {
1.1 raeburn 113: $scope .='/'.$sec;
114: }
1.5 raeburn 115: } elsif ($context eq 'domain') {
1.1 raeburn 116: $scope = '/'.$env{'request.role.domain'}.'/';
1.13 raeburn 117: } elsif ($context eq 'author') {
1.218 raeburn 118: if ($env{'request.role'} =~ m{^ca\.(/$match_domain/$match_username)$}) {
119: $scope = $1;
120: } else {
121: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
122: }
1.1 raeburn 123: }
124: if ($context eq 'domain') {
125: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
126: if ($uhome ne 'no_host') {
1.5 raeburn 127: if (($changeauth eq 'Yes') && (&Apache::lonnet::allowed('mau',$udom))) {
1.1 raeburn 128: if ((($umode =~ /^krb4|krb5|internal$/) && $upass ne '') ||
129: ($umode eq 'localauth')) {
130: $authresult = &Apache::lonnet::modifyuserauth($udom,$uname,$umode,$upass);
131: }
132: }
1.5 raeburn 133: if (($forceid) && (&Apache::lonnet::allowed('mau',$udom)) &&
134: ($env{'form.recurseid'}) && ($checkid)) {
135: my %userupdate = (
136: lastname => $last,
137: middlename => $middle,
138: firstname => $first,
139: generation => $gene,
140: id => $uid,
141: );
1.220 raeburn 142:
143: # When "Update ID in user's course(s)" and "Force change of existing ID"
144: # checkboxes both checked, prevent replacement of name information
145: # in classlist.db file(s) for the user's course(s) with blank(s),
146: # in the case where the uploaded csv file was without column(s) for
147: # the particular field. Fields are: First Name, Middle Names/Initials,
148: # Last Name (or the composite: Last Name, First Names), and Generation.
149:
150: my %emptyallowed;
151: if ((ref($emptyok) eq 'HASH') && (keys(%{$emptyok}) > 0)) {
152: %emptyallowed = %{$emptyok};
153: }
154: foreach my $field (keys(%userupdate)) {
155: if ($userupdate{$field} eq '') {
156: unless ($emptyallowed{$field}) {
157: delete($userupdate{$field});
158: }
159: }
160: }
1.5 raeburn 161: $idresult = &propagate_id_change($uname,$udom,\%userupdate);
162: }
1.1 raeburn 163: }
164: }
165: $userresult =
166: &Apache::lonnet::modifyuser($udom,$uname,$uid,$umode,$upass,$first,
167: $middle,$last,$gene,$forceid,$desiredhome,
1.84 raeburn 168: $email,$inststatus);
1.1 raeburn 169: if ($userresult eq 'ok') {
1.5 raeburn 170: if ($role ne '') {
1.22 raeburn 171: $role =~ s/_/\//g;
1.1 raeburn 172: $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
1.52 raeburn 173: $role,$end,$start,'',
174: '',$context);
1.1 raeburn 175: }
176: }
1.5 raeburn 177: return ($userresult,$authresult,$roleresult,$idresult);
1.1 raeburn 178: }
179:
1.212 raeburn 180: sub role_approval {
181: my ($dom,$context,$process_by,$notifydc) = @_;
182: if (ref($process_by) eq 'HASH') {
183: my %domconfig = &Apache::lonnet::get_dom('configuration',['privacy'],$dom);
184: if (ref($domconfig{'privacy'}) eq 'HASH') {
185: if (ref($notifydc) eq 'ARRAY') {
186: if ($domconfig{'privacy'}{'notify'} ne '') {
187: @{$notifydc} = split(/,/,$domconfig{'privacy'}{'notify'});
188: }
189: }
190: if (ref($domconfig{'privacy'}{'approval'}) eq 'HASH') {
191: my %approvalconf = %{$domconfig{'privacy'}{'approval'}};
192: foreach my $key ('instdom','extdom') {
193: if (ref($approvalconf{$key}) eq 'HASH') {
194: if (keys(%{$approvalconf{$key}})) {
195: $process_by->{$key} = $approvalconf{$key}{$context};
196: }
197: }
198: }
199: }
200: }
201: }
202: return;
203: }
204:
205: sub get_instdoms {
206: my ($udom,$instdoms) = @_;
207: return unless (ref($instdoms) eq 'ARRAY');
208: my @intdoms;
209: my %iphost = &Apache::lonnet::get_iphost();
210: my $primary_id = &Apache::lonnet::domain($udom,'primary');
211: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
212: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
213: foreach my $id (@{$iphost{$primary_ip}}) {
214: my $intdom = &Apache::lonnet::internet_dom($id);
215: unless(grep(/^\Q$intdom\E$/,@intdoms)) {
216: push(@intdoms,$intdom);
217: }
218: }
219: }
220: foreach my $ip (keys(%iphost)) {
221: if (ref($iphost{$ip}) eq 'ARRAY') {
222: foreach my $id (@{$iphost{$ip}}) {
223: my $location = &Apache::lonnet::internet_dom($id);
224: if ($location) {
225: if (grep(/^\Q$location\E$/,@intdoms)) {
226: my $dom = &Apache::lonnet::host_domain($id);
227: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
228: push(@{$instdoms},$dom);
229: }
230: }
231: }
232: }
233: }
234: }
235: return;
236: }
237:
238: sub restricted_dom {
239: my ($context,$key,$udom,$uname,$role,$start,$end,$cdom,$cnum,$csec,$credits,
240: $process_by,$instdoms,$got_role_approvals,$got_instdoms,$reject,$pending,
1.213 raeburn 241: $notifydc,$status,$unauthorized,$currqueued) = @_;
1.212 raeburn 242: return if ($udom eq $cdom);
243: return unless ((ref($process_by) eq 'HASH') && (ref($instdoms) eq 'HASH') &&
244: (ref($got_role_approvals) eq 'HASH') && (ref($got_instdoms) eq 'HASH') &&
245: (ref($reject) eq 'HASH') && (ref($pending) eq 'HASH') &&
1.213 raeburn 246: (ref($notifydc) eq 'HASH') && (ref($status) eq 'HASH') &&
247: (ref($unauthorized) eq 'HASH') && (ref($currqueued) eq 'HASH'));
1.212 raeburn 248: my (%approval,@notify,$gotdata,$skip);
249: if (ref($got_role_approvals->{$context}) eq 'HASH') {
250: if ($got_role_approvals->{$context}{$udom}) {
251: $gotdata = 1;
252: if (ref($process_by->{$context}{$udom}) eq 'HASH') {
253: %approval = %{$process_by->{$context}{$udom}};
254: }
255: }
256: }
257: unless ($gotdata) {
258: &role_approval($udom,$context,\%approval,\@notify);
259: $process_by->{$context} = {
260: $udom => \%approval,
261: };
262: $got_role_approvals->{$context} = {
263: $udom => 1,
264: };
265: $notifydc->{$udom} = \@notify;
266: }
267: if (ref($process_by->{$context}) eq 'HASH') {
268: if (ref($process_by->{$context}{$udom}) eq 'HASH') {
269: my @inst;
270: if ($got_instdoms->{$udom}) {
271: if (ref($instdoms->{$udom}) eq 'ARRAY') {
272: @inst = @{$instdoms->{$udom}};
273: }
274: } else {
275: &get_instdoms(\@inst);
276: $instdoms->{$udom} = \@inst;
277: $got_instdoms->{$udom} = 1;
278: }
279: if (grep(/^\Q$cdom\E$/,@inst)) {
280: if (exists($approval{'instdom'})) {
281: my $rule = $approval{'instdom'};
1.213 raeburn 282: if (($rule eq 'none') || ($rule eq 'user') || ($rule eq 'domain')) {
283: my ($id,$currstatus,$curradj) = &get_othdomreq_status($key,$uname,$udom,$role,$cdom,$cnum,$csec);
284: if (($currstatus ne '') && ($curradj eq $rule)) {
285: $status->{$key}->{$uname.':'.$udom} = $currstatus;
286: }
287: if ($rule eq 'none') {
288: $reject->{$key}->{$uname.':'.$udom} = {
289: cdom => $cdom,
290: cnum => $cnum,
291: csec => $csec,
292: udom => $udom,
293: uname => $uname,
294: role => $role,
295: };
296: $skip = 1;
297: } elsif (($rule eq 'user') || ($rule eq 'domain')) {
298: if ($curradj eq $rule) {
299: unless ($currstatus eq 'approved') {
300: if ($currstatus eq 'rejected') {
301: $unauthorized->{$key}->{$uname.':'.$udom} = {
302: cdom => $cdom,
303: cnum => $cnum,
304: csec => $csec,
305: udom => $udom,
306: uname => $uname,
307: role => $role,
308: };
309: } elsif ($currstatus eq 'pending') {
310: $currqueued->{$key}->{$uname.':'.$udom} = {
311: cdom => $cdom,
312: cnum => $cnum,
313: csec => $csec,
314: udom => $udom,
315: uname => $uname,
316: role => $role,
317: adj => $rule,
318: };
319: }
320: $skip = 1;
321: }
322: } else {
323: $pending->{$key}->{$uname.':'.$udom} = {
324: cdom => $cdom,
325: cnum => $cnum,
326: csec => $csec,
327: udom => $udom,
328: uname => $uname,
329: role => $role,
330: start => $start,
331: end => $end,
332: adj => $rule,
333: };
334: if (($role eq 'st') && ($credits ne '')) {
335: $pending->{$key}->{$uname.':'.$udom}->{'credits'} = $credits;
336: }
337: $skip = 1;
338: }
1.212 raeburn 339: }
340: }
341: }
342: } elsif (exists($approval{'extdom'})) {
343: my $rule = $approval{'extdom'};
1.213 raeburn 344: if (($rule eq 'none') || ($rule eq 'user') || ($rule eq 'domain')) {
345: my ($id,$currstatus,$curradj) = &get_othdomreq_status($key,$uname,$udom,$role,$cdom,$cnum,$csec);
346: if (($currstatus ne '') && ($curradj eq $rule)) {
347: $status->{$key}->{$uname.':'.$udom} = $currstatus;
348: }
349: if ($rule eq 'none') {
350: $reject->{$key}->{$uname.':'.$udom} = {
351: cdom => $cdom,
352: cnum => $cnum,
353: csec => $csec,
354: udom => $udom,
355: uname => $uname,
356: role => $role,
357: };
358: $skip = 1;
359: } elsif (($rule eq 'user') || ($rule eq 'domain')) {
360: if ($curradj eq $rule) {
361: unless ($currstatus eq 'approved') {
362: if ($currstatus eq 'rejected') {
363: $unauthorized->{$key}->{$uname.':'.$udom} = {
364: cdom => $cdom,
365: cnum => $cnum,
366: csec => $csec,
367: udom => $udom,
368: uname => $uname,
369: role => $role,
370: };
371: } elsif ($currstatus eq 'pending') {
372: $currqueued->{$key}->{$uname.':'.$udom} = {
373: cdom => $cdom,
374: cnum => $cnum,
375: csec => $csec,
376: udom => $udom,
377: uname => $uname,
378: role => $role,
379: adj => $rule,
380: };
381: }
382: $skip = 1;
383: }
384: } else {
385: $pending->{$key}->{$uname.':'.$udom} = {
386: cdom => $cdom,
387: cnum => $cnum,
388: csec => $csec,
389: udom => $udom,
390: uname => $uname,
391: role => $role,
392: start => $start,
393: end => $end,
394: adj => $rule,
395: };
396: if (($role eq 'st') && ($credits ne '')) {
397: $pending->{$key}->{$uname.':'.$udom}->{'credits'} = $credits;
398: }
399: $skip = 1;
400: }
1.212 raeburn 401: }
402: }
403: }
404: }
405: }
406: return $skip;
407: }
408:
1.213 raeburn 409: sub get_othdomreq_status {
410: my ($key,$uname,$udom,$role,$cdom,$cnum,$csec) = @_;
411: my $id = $uname.':'.$udom.':'.$role;
412: my ($dbnum,$currstatus,$curradj);
413: if (($role eq 'ca') || ($role eq 'aa')) {
414: $dbnum = $cnum;
415: } elsif ($key eq $cdom.'_'.$role) {
416: $dbnum = &Apache::lonnet::get_domainconfiguser($cdom);
417: } else {
418: $id .= ':'.$csec;
419: $dbnum = $cnum;
420: }
421: my $statusid = 'status&'.$id;
422: my %curr = &Apache::lonnet::get('nohist_othdomqueued',[$id,$statusid],$cdom,$dbnum);
423: if (ref($curr{$id}) eq 'HASH') {
424: $curradj = $curr{$id}{'adj'};
425: }
426: $currstatus = $curr{$statusid};
427: return ($id,$currstatus,$curradj);
428: }
429:
1.212 raeburn 430: sub print_roles_rejected {
1.213 raeburn 431: my ($context,$reject,$unauthorized) = @_;
432: return unless ((ref($reject) eq 'HASH') || (ref($unauthorized) eq 'HASH'));
1.212 raeburn 433: my $output;
434: if (keys(%{$reject}) > 0) {
435: $output = '<p class="LC_warning">'.
436: &mt("The following roles could not be assigned because the user is from another domain, and that domain's policies disallow it").'<ul>';
437: foreach my $key (sort(keys(%{$reject}))) {
438: if (ref($reject->{$key}) eq 'HASH') {
1.213 raeburn 439: foreach my $user (sort(keys(%{$reject->{$key}}))) {
440: if (ref($reject->{$key}->{$user}) eq 'HASH') {
441: my ($crstype,$role,$cdom,$cnum,$csec,$title,$plainrole);
442: $role = $reject->{$key}->{$user}{'role'};
443: $cdom = $reject->{$key}->{$user}{'cdom'};
444: $cnum = $reject->{$key}->{$user}{'cnum'};
445: $csec = $reject->{$key}->{$user}{'csec'};
446: if (($context eq 'domain') && ($cnum ne '')) {
447: if (($role eq 'ca') || ($role eq 'aa')) {
448: $title = &Apache::loncommon::plainname($cnum,$cdom);
449: } else {
450: if (&Apache::lonnet::is_course($cdom,$cnum)) {
451: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
452: $crstype = $coursedata{'type'};
453: $title = $coursedata{'description'};
454: }
455: }
456: } elsif ($context eq 'course') {
457: $crstype = &Apache::loncommon::course_type();
458: }
459: my $plainrole = &Apache::lonnet::plaintext($role,$crstype);
460: $output .= '<li>'.&mt('User: [_1]',$reject->{$key}->{$user}{'uname'}).' | '.
461: &mt('Domain: [_1]',$reject->{$key}->{$user}{'udom'}).' | '.
462: &mt('Role: [_1]',$plainrole);
463: if ($crstype) {
464: if ($csec ne'') {
465: $output .= ' | '.&mt('Section: [_1]',$csec);
466: }
467: } elsif (($context eq 'domain') && (($role eq 'ca') || ($role eq 'aa'))) {
468: $output .= ' | '.&mt('Authoring Space belonging to: [_1]',$title);
469:
470: }
471: if (($context eq 'domain') && ($crstype)) {
472: $output .= ' | '.&mt("$crstype: [_1]",$title);
473: }
474: $output .= '</li>';
1.212 raeburn 475: }
476: }
1.213 raeburn 477: }
478: }
479: $output .= '</ul></p>';
480: }
481: if (keys(%{$unauthorized}) > 0) {
482: $output = '<p class="LC_warning">'.
483: &mt("The following roles could not be assigned because the user is from another domain, and that domain's policies require approval by the user themselves or by a domain coordinator in that domain, and approval has been withheld.").'<ul>';
484: foreach my $key (sort(keys(%{$unauthorized}))) {
485: if (ref($unauthorized->{$key}) eq 'HASH') {
486: foreach my $user (sort(keys(%{$unauthorized->{$key}}))) {
487: if (ref($unauthorized->{$key}->{$user}) eq 'HASH') {
488: my ($crstype,$role,$cdom,$cnum,$csec,$title,$plainrole);
489: $role = $unauthorized->{$key}->{$user}{'role'};
490: $cdom = $unauthorized->{$key}->{$user}{'cdom'};
491: $cnum = $unauthorized->{$key}->{$user}{'cnum'};
492: $csec = $unauthorized->{$key}->{$user}{'csec'};
493: if (($context eq 'domain') && ($cnum ne '')) {
494: if (($role eq 'ca') || ($role eq 'aa')) {
495: $title = &mt('Authoring Space belonging to: [_1]',
496: &Apache::loncommon::plainname($cnum,$cdom));
497: } else {
498: if (&Apache::lonnet::is_course($cdom,$cnum)) {
499: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
500: $crstype = $coursedata{'type'};
501: $title = &mt("$crstype: [_1]",$coursedata{'description'});
502: }
503: }
504: } elsif ($context eq 'course') {
505: $crstype = &Apache::loncommon::course_type();
506: }
507: $plainrole = &Apache::lonnet::plaintext($role,$crstype);
508: $output .= '<li>'.&mt('User: [_1]',$unauthorized->{$key}->{$user}{'uname'}).' | '.
509: &mt('Domain: [_1]',$unauthorized->{$key}->{$user}{'udom'}).' | '.
510: &mt('Role: [_1]',$plainrole);
511: if ($crstype) {
512: if ($csec ne'') {
513: $output .= ' | '.&mt('Section: [_1]',$csec);
514: }
515: }
516: if ($title ne '') {
517: $output .= ' | '.$title;
518: }
519: $output .= '</li>';
520: }
1.212 raeburn 521: }
522: }
523: }
1.213 raeburn 524: $output .= '</ul></p>';
1.212 raeburn 525: }
526: return $output;
527: }
528:
529: sub print_roles_queued {
1.213 raeburn 530: my ($context,$pending,$notifydc,$currqueued) = @_;
531: return unless ((ref($pending) eq 'HASH') && (ref($notifydc) eq 'HASH') &&
532: (ref($currqueued) eq 'HASH'));
1.212 raeburn 533: my $output;
534: if (keys(%{$pending}) > 0) {
535: my $now = time;
536: $output = '<p class="LC_warning">'.
537: &mt("The following role assignments have been queued because the user is from another domain, and that domain's policies require approval by the user themselves or by a domain coordinator in that domain").'<ul>';
538: my (%todom,%touser,%crsqueue,%caqueue,%domqueue);
539: my $requester = $env{'user.name'}.':'.$env{'user.domain'};
540: foreach my $key (sort(keys(%{$pending}))) {
541: if (ref($pending->{$key}) eq 'HASH') {
1.213 raeburn 542: foreach my $user (sort(keys(%{$pending->{$key}}))) {
543: if (ref($pending->{$key}->{$user}) eq 'HASH') {
544: my $role = $pending->{$key}->{$user}{'role'};
545: my $uname = $pending->{$key}->{$user}{'uname'};
546: my $udom = $pending->{$key}->{$user}{'udom'};
547: my $csec = $pending->{$key}->{$user}{'csec'};
548: my $cdom = $pending->{$key}->{$user}{'cdom'};
549: my $cnum = $pending->{$key}->{$user}{'cnum'};
550: my $adj = $pending->{$key}->{$user}{'adj'};
551: my $start = $pending->{$key}->{$user}{'start'};
552: my $end = $pending->{$key}->{$user}{'end'};
553: my $credits = $pending->{$key}->{$user}{'credits'};
554: my $now = time;
555: my ($crstype,$title,$plainrole,$extent,$id,$status);
556: if ($context eq 'course') {
557: $crstype = &Apache::loncommon::course_type();
558: $title = $env{'course.'.$env{'request.course.id'}.'.description'};
559: } elsif ($context eq 'domain') {
560: if (&Apache::lonnet::is_course($cdom,$cnum)) {
561: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
562: $crstype = $coursedata{'type'};
563: $title = $coursedata{'description'};
564: } elsif (($role eq 'ca') || ($role eq 'aa')) {
565: $title = &Apache::loncommon::plainname($cnum,$cdom);
566: }
567: }
568: $plainrole = &Apache::lonnet::plaintext($role,$crstype);
569: $extent = "/$cdom/$cnum";
570: $id = $uname.':'.$udom.':'.$role;
571: if (($context eq 'course') || ($crstype)) {
572: $id .= ':'.$csec;
573: }
574: $output .= '<li>'.&mt('User: [_1]',$uname).' | '.
575: &mt('Domain: [_1]',$udom).' | '.
576: &mt('Role: [_1]',$plainrole);
577: if ($crstype) {
578: if ($csec ne'') {
579: $output .= ' | '.&mt('Section: [_1]',$csec);
580: }
581: } elsif (($context eq 'domain') && (($role eq 'ca') || ($role eq 'aa'))) {
582: $output .= ' | '.&mt('Authoring Space belonging to: [_1]',$title);
583: }
584: if (($context eq 'domain') && ($crstype)) {
585: $output .= ' | '.&mt("$crstype: [_1]",$title);
586: }
587: if (($crstype) && ($csec ne '')) {
588: $extent .= "/$csec";
589: }
590: if ($adj eq 'user') {
591: $output .= '<br />'.&mt('Message sent to user for approval');
592: $touser{$uname.':'.$udom}{'pending:'.$extent.':'.$role} = {
593: timestamp => $now,
594: requester => $requester,
595: start => $start,
596: end => $end,
597: credits => $credits,
598: context => $context,
599: };
600: } elsif ($adj eq 'domain') {
601: $output .= '<br />'.&mt("Message sent to user's domain coordinator for approval");
602: $todom{$udom}{'pending:'.$uname.':'.$extent.':'.$role} = {
603: timestamp => $now,
604: requester => $requester,
605: start => $start,
606: end => $end,
607: credits => $credits,
608: context => $context,
609: };
610: }
611: $output .= '</li>';
612: if (($context eq 'course') || ($crstype)) {
613: $crsqueue{$cdom.'_'.$cnum}{$id} = {
614: timestamp => $now,
615: requester => $requester,
616: adj => $adj,
617: };
618: $crsqueue{$cdom.'_'.$cnum}{'status&'.$id} = 'pending';
619: } elsif (($context eq 'author') ||
620: (($context eq 'domain') && (($role eq 'ca') || ($role eq 'aa')))) {
621: $caqueue{$cnum.':'.$cdom}{$id} = {
622: timestamp => $now,
623: requester => $requester,
624: adj => $adj,
625: };
626: $caqueue{$cnum.':'.$cdom}{'status&'.$id} = 'pending';
627: } elsif ($context eq 'domain') {
628: $domqueue{$id} = {
629: timestamp => $now,
630: requester => $requester,
631: adj => $adj,
632: };
633: $domqueue{'status&'.$id} = 'pending';
634: }
635: }
1.212 raeburn 636: }
637: }
638: }
639: $output .= '</ul></p>';
640: if (keys(%touser)) {
641: foreach my $key (keys(%touser)) {
1.214 raeburn 642: my ($uname,$udom) = split(/:/,$key);
1.213 raeburn 643: if (&Apache::lonnet::put('nohist_queuedrolereqs',$touser{$key},$udom,$uname) eq 'ok') {
1.212 raeburn 644: my $owndomdesc = &Apache::lonnet::domain($udom);
645: &Apache::loncoursequeueadmin::send_selfserve_notification($uname.':'.$udom,
646: '','',$owndomdesc,$now,'othdomroleuser',$requester);
647: }
648: }
649: }
650: if (keys(%todom)) {
651: foreach my $dom (keys(%todom)) {
652: if (ref($todom{$dom}) eq 'HASH') {
653: my $confname = &Apache::lonnet::get_domainconfiguser($dom);
1.213 raeburn 654: if (&Apache::lonnet::put('nohist_queuedrolereqs',$todom{$dom},$dom,$confname) eq 'ok') {
1.212 raeburn 655: if (ref($notifydc->{$dom}) eq 'ARRAY') {
656: if (@{$notifydc->{$dom}} > 0) {
657: my $notifylist = join(',',@{$notifydc->{$dom}});
658: &Apache::loncoursequeueadmin::send_selfserve_notification($notifylist,
659: '','','',$now,'othdomroledc',$requester);
660: }
661: }
662: }
663: }
664: }
665: }
666: if (keys(%crsqueue)) {
667: foreach my $key (keys(%crsqueue)) {
668: my ($cdom,$cnum) = split(/_/,$key);
669: if (ref($crsqueue{$key}) eq 'HASH') {
1.213 raeburn 670: &Apache::lonnet::put('nohist_othdomqueued',$crsqueue{$key},$cdom,$cnum);
1.212 raeburn 671: }
672: }
673: }
674: if (keys(%caqueue)) {
675: foreach my $key (keys(%caqueue)) {
676: my ($auname,$audom) = split(/:/,$key);
677: if (ref($caqueue{$key}) eq 'HASH') {
1.213 raeburn 678: &Apache::lonnet::put('nohist_othdomqueued',$caqueue{$key},$audom,$auname);
1.212 raeburn 679: }
680: }
681: }
682: if (keys(%domqueue)) {
683: my $confname = &Apache::lonnet::get_domainconfiguser($env{'request.role.domain'});
1.213 raeburn 684: &Apache::lonnet::put('nohist_othdomqueued',\%domqueue,$env{'request.role.domain'},$confname);
1.212 raeburn 685: }
686: }
1.213 raeburn 687: if (keys(%{$currqueued}) > 0) {
688: $output = '<p class="LC_warning">'.
689: &mt("The following role assignments were already queued because the user is from another domain, and that domain's policies require approval by the user themselves or by a domain coordinator in that domain").'<ul>';
690: my $requester = $env{'user.name'}.':'.$env{'user.domain'};
691: foreach my $key (sort(keys(%{$currqueued}))) {
692: if (ref($currqueued->{$key}) eq 'HASH') {
693: foreach my $user (sort(keys(%{$currqueued->{$key}}))) {
694: if (ref($currqueued->{$key}->{$user}) eq 'HASH') {
695: my $role = $currqueued->{$key}->{$user}{'role'};
696: my $csec = $currqueued->{$key}->{$user}{'csec'};
697: my $cdom = $currqueued->{$key}->{$user}{'cdom'};
698: my $cnum = $currqueued->{$key}->{$user}{'cnum'};
699: my ($crstype,$title,$plainrole);
700: if ($context eq 'course') {
701: $crstype = &Apache::loncommon::course_type();
702: } elsif (($context eq 'domain') && ($cnum ne '')) {
703: if (($role eq 'ca') || ($role eq 'aa')) {
704: $title = &mt('Authoring Space belonging to: [_1]',
705: &Apache::loncommon::plainname($cnum,$cdom));
706: } elsif (&Apache::lonnet::is_course($cdom,$cnum)) {
707: my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
708: $crstype = $coursedata{'type'};
709: $title = &mt("$crstype: [_1]",$coursedata{'description'});
710: }
711: }
712: $plainrole = &Apache::lonnet::plaintext($role,$crstype);
713: $output .= '<li>'.&mt('User: [_1]',$currqueued->{$key}->{$user}{'uname'}).' | '.
714: &mt('Domain: [_1]',$currqueued->{$key}->{$user}{'udom'}).' | '.
715: &mt('Role: [_1]',$plainrole);
716: if ($title ne '') {
717: $output .= ' | '.$title;
718: }
719: if ($crstype) {
720: if ($csec ne '') {
721: $output .= ' | '.&mt('Section: [_1]',$csec);
722: }
723: }
724: $output .= '</li>';
725: }
726: }
727: }
728: }
729: $output .= '</ul></p>';
730: }
1.212 raeburn 731: return $output;
732: }
733:
1.5 raeburn 734: sub propagate_id_change {
735: my ($uname,$udom,$user) = @_;
1.12 raeburn 736: my (@types,@roles);
1.5 raeburn 737: @types = ('active','future');
738: @roles = ('st');
739: my $idresult;
740: my %roleshash = &Apache::lonnet::get_my_roles($uname,
1.12 raeburn 741: $udom,'userroles',\@types,\@roles);
742: my %args = (
743: one_time => 1,
744: );
1.5 raeburn 745: foreach my $item (keys(%roleshash)) {
1.22 raeburn 746: my ($cnum,$cdom,$role) = split(/:/,$item,-1);
1.5 raeburn 747: my ($start,$end) = split(/:/,$roleshash{$item});
748: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.12 raeburn 749: my $result = &update_classlist($cdom,$cnum,$udom,$uname,$user);
750: my %coursehash =
751: &Apache::lonnet::coursedescription($cdom.'_'.$cnum,\%args);
752: my $cdesc = $coursehash{'description'};
753: if ($cdesc eq '') {
754: $cdesc = $cdom.'_'.$cnum;
755: }
1.5 raeburn 756: if ($result eq 'ok') {
1.12 raeburn 757: $idresult .= &mt('Classlist update for "[_1]" in "[_2]".',$uname.':'.$udom,$cdesc).'<br />'."\n";
1.5 raeburn 758: } else {
1.12 raeburn 759: $idresult .= &mt('Error: "[_1]" during classlist update for "[_2]" in "[_3]".',$result,$uname.':'.$udom,$cdesc).'<br />'."\n";
1.5 raeburn 760: }
761: }
762: }
763: return $idresult;
764: }
765:
766: sub update_classlist {
1.63 raeburn 767: my ($cdom,$cnum,$udom,$uname,$user,$newend) = @_;
1.6 albertel 768: my ($uid,$classlistentry);
1.5 raeburn 769: my $fullname =
770: &Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
771: $user->{'lastname'},$user->{'generation'},
772: 'lastname');
773: my %classhash = &Apache::lonnet::get('classlist',[$uname.':'.$udom],
774: $cdom,$cnum);
775: my @classinfo = split(/:/,$classhash{$uname.':'.$udom});
776: my $ididx=&Apache::loncoursedata::CL_ID() - 2;
777: my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2;
1.63 raeburn 778: my $endidx = &Apache::loncoursedata::CL_END() - 2;
779: my $startidx = &Apache::loncoursedata::CL_START() - 2;
1.5 raeburn 780: for (my $i=0; $i<@classinfo; $i++) {
1.63 raeburn 781: if ($i == $endidx) {
782: if ($newend ne '') {
783: $classlistentry .= $newend.':';
784: } else {
785: $classlistentry .= $classinfo[$i].':';
786: }
787: } elsif ($i == $startidx) {
788: if ($newend ne '') {
789: if ($classinfo[$i] > $newend) {
790: $classlistentry .= $newend.':';
791: } else {
792: $classlistentry .= $classinfo[$i].':';
793: }
794: } else {
795: $classlistentry .= $classinfo[$i].':';
796: }
797: } elsif ($i == $ididx) {
1.5 raeburn 798: if (defined($user->{'id'})) {
799: $classlistentry .= $user->{'id'}.':';
800: } else {
801: $classlistentry .= $classinfo[$i].':';
802: }
803: } elsif ($i == $nameidx) {
1.63 raeburn 804: if (defined($user->{'lastname'})) {
805: $classlistentry .= $fullname.':';
806: } else {
807: $classlistentry .= $classinfo[$i].':';
808: }
1.5 raeburn 809: } else {
810: $classlistentry .= $classinfo[$i].':';
811: }
812: }
813: $classlistentry =~ s/:$//;
814: my $reply=&Apache::lonnet::cput('classlist',
815: {"$uname:$udom" => $classlistentry},
816: $cdom,$cnum);
817: if (($reply eq 'ok') || ($reply eq 'delayed')) {
818: return 'ok';
819: } else {
820: return 'error: '.$reply;
821: }
822: }
823:
824:
1.1 raeburn 825: ###############################################################
826: ###############################################################
1.2 raeburn 827: # build a role type and role selection form
828: sub domain_roles_select {
829: # Set up the role type and role selection boxes when in
830: # domain context
831: #
832: # Role types
1.101 raeburn 833: my @roletypes = ('domain','author','course','community');
1.2 raeburn 834: my %lt = &role_type_names();
1.149 raeburn 835: my $onchangefirst = "updateCols('showrole')";
836: my $onchangesecond = "updateCols('showrole')";
1.1 raeburn 837: #
838: # build up the menu information to be passed to
839: # &Apache::loncommon::linked_select_forms
840: my %select_menus;
1.2 raeburn 841: if ($env{'form.roletype'} eq '') {
842: $env{'form.roletype'} = 'domain';
843: }
844: foreach my $roletype (@roletypes) {
1.1 raeburn 845: # set up the text for this domain
1.2 raeburn 846: $select_menus{$roletype}->{'text'}= $lt{$roletype};
1.102 raeburn 847: my $crstype;
848: if ($roletype eq 'community') {
849: $crstype = 'Community';
850: }
1.1 raeburn 851: # we want a choice of 'default' as the default in the second menu
1.2 raeburn 852: if ($env{'form.roletype'} ne '') {
853: $select_menus{$roletype}->{'default'} = $env{'form.showrole'};
854: } else {
855: $select_menus{$roletype}->{'default'} = 'Any';
856: }
1.1 raeburn 857: # Now build up the other items in the second menu
1.2 raeburn 858: my @roles;
859: if ($roletype eq 'domain') {
860: @roles = &domain_roles();
1.13 raeburn 861: } elsif ($roletype eq 'author') {
1.2 raeburn 862: @roles = &construction_space_roles();
863: } else {
1.17 raeburn 864: my $custom = 1;
1.101 raeburn 865: @roles = &course_roles('domain',undef,$custom,$roletype);
1.1 raeburn 866: }
1.2 raeburn 867: my $order = ['Any',@roles];
868: $select_menus{$roletype}->{'order'} = $order;
869: foreach my $role (@roles) {
1.5 raeburn 870: if ($role eq 'cr') {
871: $select_menus{$roletype}->{'select2'}->{$role} =
872: &mt('Custom role');
873: } else {
874: $select_menus{$roletype}->{'select2'}->{$role} =
1.102 raeburn 875: &Apache::lonnet::plaintext($role,$crstype);
1.5 raeburn 876: }
1.2 raeburn 877: }
878: $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
1.1 raeburn 879: }
1.2 raeburn 880: my $result = &Apache::loncommon::linked_select_forms
881: ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
1.101 raeburn 882: 'roletype','showrole',\%select_menus,
1.149 raeburn 883: ['domain','author','course','community'],$onchangefirst,
884: $onchangesecond);
1.1 raeburn 885: return $result;
886: }
887:
888: ###############################################################
889: ###############################################################
890: sub hidden_input {
891: my ($name,$value) = @_;
892: return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n";
893: }
894:
895: sub print_upload_manager_header {
1.123 raeburn 896: my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype,
897: $can_assign)=@_;
1.1 raeburn 898: my $javascript;
899: #
900: if (! exists($env{'form.upfile_associate'})) {
901: $env{'form.upfile_associate'} = 'forward';
902: }
903: if ($env{'form.associate'} eq 'Reverse Association') {
904: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
905: $env{'form.upfile_associate'} = 'reverse';
906: } else {
907: $env{'form.upfile_associate'} = 'forward';
908: }
909: }
910: if ($env{'form.upfile_associate'} eq 'reverse') {
1.123 raeburn 911: $javascript=&upload_manager_javascript_reverse_associate($can_assign);
1.1 raeburn 912: } else {
1.123 raeburn 913: $javascript=&upload_manager_javascript_forward_associate($can_assign);
1.1 raeburn 914: }
915: #
916: # Deal with restored settings
917: my $password_choice = '';
918: if (exists($env{'form.ipwd_choice'}) &&
919: $env{'form.ipwd_choice'} ne '') {
920: # If a column was specified for password, assume it is for an
921: # internal password. This is a bug waiting to be filed (could be
922: # local or krb auth instead of internal) but I do not have the
923: # time to mess around with this now.
924: $password_choice = 'int';
925: }
926: #
1.22 raeburn 927: my $groupslist;
928: if ($context eq 'course') {
929: $groupslist = &get_groupslist();
930: }
1.1 raeburn 931: my $javascript_validations =
1.22 raeburn 932: &javascript_validations('upload',$krbdefdom,$password_choice,undef,
933: $env{'request.role.domain'},$context,
1.103 raeburn 934: $groupslist,$crstype);
1.91 bisitz 935: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.147 bisitz 936: $r->print(
937: '<h3>'.&mt('Identify fields in uploaded list')."</h3>\n".
938: '<p class="LC_info">'.
939: &mt('Total number of records found in file: [_1]'
940: ,'<b>'.$distotal.'</b>').
941: "</p>\n"
942: );
943: if ($distotal == 0) {
944: $r->print('<p class="LC_warning">'.&mt('None found').'</p>');
945: }
946: $r->print(
947: '<p>'.
948: &mt('Enter as many fields as you can.').'<br />'.
949: &mt('The system will inform you and bring you back to this page,[_1]if the data selected are insufficient to add users.','<br />').
950: "</p>\n"
951: );
1.1 raeburn 952: $r->print(&hidden_input('action','upload').
953: &hidden_input('state','got_file').
954: &hidden_input('associate','').
955: &hidden_input('datatoken',$datatoken).
956: &hidden_input('fileupload',$env{'form.fileupload'}).
957: &hidden_input('upfiletype',$env{'form.upfiletype'}).
958: &hidden_input('upfile_associate',$env{'form.upfile_associate'}));
1.147 bisitz 959: $r->print(
960: '<div class="LC_left_float">'.
961: '<fieldset><legend>'.&mt('Functions').'</legend>'.
962: '<label><input type="checkbox" name="noFirstLine"'.$checked.' />'.
963: &mt('Ignore First Line').'</label>'.
964: ' <input type="button" value="'.&mt('Reverse Association').'" '.
1.59 bisitz 965: 'name="Reverse Association" '.
1.147 bisitz 966: 'onclick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />'.
967: '</fieldset></div><br clear="all" />'
968: );
969: $r->print(
970: '<script type="text/javascript" language="Javascript">'."\n".
971: '// <![CDATA['."\n".
972: $javascript."\n".$javascript_validations."\n".
973: '// ]]>'."\n".
974: '</script>'
975: );
1.1 raeburn 976: }
977:
978: ###############################################################
979: ###############################################################
980: sub javascript_validations {
1.22 raeburn 981: my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain,
1.103 raeburn 982: $context,$groupslist,$crstype)=@_;
1.22 raeburn 983: my %param = (
984: kerb_def_dom => $krbdefdom,
985: curr_authtype => $curr_authtype,
986: );
1.37 raeburn 987: if ($mode eq 'upload') {
1.22 raeburn 988: $param{'formname'} = 'studentform';
1.1 raeburn 989: } elsif ($mode eq 'createcourse') {
1.22 raeburn 990: $param{'formname'} = 'ccrs';
1.1 raeburn 991: } elsif ($mode eq 'modifycourse') {
1.22 raeburn 992: $param{'formname'} = 'cmod';
993: $param{'mode'} = 'modifycourse',
994: $param{'curr_autharg'} = $curr_authfield;
995: }
996:
1.150 raeburn 997: my $showcredits;
998: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
1.160 raeburn 999: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
1.150 raeburn 1000: $showcredits = 1;
1001: }
1002:
1.22 raeburn 1003: my ($setsection_call,$setsections_js);
1004: my $finish = " vf.submit();\n";
1005: if ($mode eq 'upload') {
1006: if (($context eq 'course') || ($context eq 'domain')) {
1007: if ($context eq 'course') {
1008: if ($env{'request.course.sec'} eq '') {
1.109 raeburn 1009: $setsection_call = 'setSections(document.'.$param{'formname'}.",'$crstype'".');';
1.22 raeburn 1010: $setsections_js =
1011: &setsections_javascript($param{'formname'},$groupslist,
1.150 raeburn 1012: $mode,'',$crstype,$showcredits);
1.22 raeburn 1013: } else {
1014: $setsection_call = "'ok'";
1015: }
1016: } elsif ($context eq 'domain') {
1017: $setsection_call = 'setCourse()';
1.150 raeburn 1018: $setsections_js = &dc_setcourse_js($param{'formname'},$mode,
1.196 raeburn 1019: $context,$showcredits,$domain);
1.22 raeburn 1020: }
1021: $finish = " var checkSec = $setsection_call\n".
1022: " if (checkSec == 'ok') {\n".
1023: " vf.submit();\n".
1024: " }\n";
1025: }
1.1 raeburn 1026: }
1.22 raeburn 1027: my $authheader = &Apache::loncommon::authform_header(%param);
1.1 raeburn 1028:
1029: my %alert = &Apache::lonlocal::texthash
1030: (username => 'You need to specify the username field.',
1031: authen => 'You must choose an authentication type.',
1032: krb => 'You need to specify the Kerberos domain.',
1033: ipass => 'You need to specify the initial password.',
1034: name => 'The optional name field was not specified.',
1.93 bisitz 1035: snum => 'The optional student/employee ID field was not specified.',
1.1 raeburn 1036: section => 'The optional section field was not specified.',
1.75 schafran 1037: email => 'The optional e-mail address field was not specified.',
1.1 raeburn 1038: role => 'The optional role field was not specified.',
1.57 raeburn 1039: domain => 'The optional domain field was not specified.',
1.1 raeburn 1040: continue => 'Continue adding users?',
1041: );
1.150 raeburn 1042: if ($showcredits) {
1043: $alert{'credits'} = &mt('The optional credits field was not specified');
1044: }
1.84 raeburn 1045: if (($mode eq 'upload') && ($context eq 'domain')) {
1046: $alert{'inststatus'} = &mt('The optional affiliation field was not specified');
1047: }
1.170 damieng 1048: &js_escape(\%alert);
1.37 raeburn 1049: my $function_name = <<"END";
1.22 raeburn 1050: $setsections_js
1051:
1.150 raeburn 1052: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits) {
1.1 raeburn 1053: END
1054: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($domain);
1055: my $auth_checks;
1056: if ($mode eq 'createcourse') {
1057: $auth_checks .= (<<END);
1058: if (vf.autoadds[0].checked == true) {
1059: if (current.radiovalue == null || current.radiovalue == 'nochange') {
1060: alert('$alert{'authen'}');
1061: return;
1062: }
1063: }
1064: END
1065: } else {
1066: $auth_checks .= (<<END);
1067: var foundatype=0;
1068: if (founduname==0) {
1069: alert('$alert{'username'}');
1070: return;
1071: }
1072:
1073: END
1074: if ($authnum > 1) {
1075: $auth_checks .= (<<END);
1076: if (current.radiovalue == null || current.radiovalue == '' || current.radiovalue == 'nochange') {
1077: // They did not check any of the login radiobuttons.
1078: alert('$alert{'authen'}');
1079: return;
1080: }
1081: END
1082: }
1083: }
1084: if ($mode eq 'createcourse') {
1085: $auth_checks .= "
1086: if ( (vf.autoadds[0].checked == true) &&
1087: (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') ) {
1088: ";
1089: } elsif ($mode eq 'modifycourse') {
1090: $auth_checks .= "
1.215 raeburn 1091: if ((current.argfield !== null) && (current.argfield !== undefined) && (current.argfield !== '') && (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '')) {
1.1 raeburn 1092: ";
1093: }
1094: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
1095: $auth_checks .= (<<END);
1096: var alertmsg = '';
1097: switch (current.radiovalue) {
1098: case 'krb':
1099: alertmsg = '$alert{'krb'}';
1100: break;
1101: default:
1102: alertmsg = '';
1103: }
1104: if (alertmsg != '') {
1105: alert(alertmsg);
1106: return;
1107: }
1108: }
1.150 raeburn 1109: /* regexp here to check for non \d \. in credits */
1.1 raeburn 1110: END
1111: } else {
1.196 raeburn 1112: my ($numrules,$intargjs) =
1.210 raeburn 1113: &Apache::loncommon::passwd_validation_js('vf.elements[current.argfield].value',$domain);
1.1 raeburn 1114: $auth_checks .= (<<END);
1115: foundatype=1;
1116: if (current.argfield == null || current.argfield == '') {
1.196 raeburn 1117: // The login radiobutton checked does not have an associated textbox
1118: } else if (vf.elements[current.argfield].value == '') {
1.1 raeburn 1119: var alertmsg = '';
1.38 raeburn 1120: switch (current.radiovalue) {
1.1 raeburn 1121: case 'krb':
1122: alertmsg = '$alert{'krb'}';
1123: break;
1.196 raeburn 1124: case 'int':
1.1 raeburn 1125: alertmsg = '$alert{'ipass'}';
1126: break;
1127: case 'fsys':
1.196 raeburn 1128: alertmsg = '$alert{'ipass'}';
1.1 raeburn 1129: break;
1.209 raeburn 1130: case 'loc':
1131: alertmsg = '';
1132: break;
1.194 raeburn 1133: case 'lti':
1.1 raeburn 1134: default:
1135: alertmsg = '';
1136: }
1137: if (alertmsg != '') {
1138: alert(alertmsg);
1139: return;
1140: }
1.196 raeburn 1141: } else if (current.radiovalue == 'int') {
1142: if ($numrules > 0) {
1143: $intargjs
1144: }
1.1 raeburn 1145: }
1146: END
1147: }
1148: my $section_checks;
1149: my $optional_checks = '';
1150: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
1151: $optional_checks = (<<END);
1152: vf.submit();
1153: }
1154: END
1155: } else {
1156: $section_checks = §ion_check_js();
1157: $optional_checks = (<<END);
1158: var message='';
1159: if (foundname==0) {
1160: message='$alert{'name'}';
1161: }
1162: if (foundid==0) {
1163: if (message!='') {
1164: message+='\\n';
1165: }
1166: message+='$alert{'snum'}';
1167: }
1168: if (foundsec==0) {
1169: if (message!='') {
1170: message+='\\n';
1171: }
1.130 raeburn 1172: message+='$alert{'section'}';
1.1 raeburn 1173: }
1174: if (foundemail==0) {
1175: if (message!='') {
1176: message+='\\n';
1177: }
1178: message+='$alert{'email'}';
1179: }
1.57 raeburn 1180: if (foundrole==0) {
1181: if (message!='') {
1182: message+='\\n';
1183: }
1184: message+='$alert{'role'}';
1185: }
1186: if (founddomain==0) {
1187: if (message!='') {
1188: message+='\\n';
1189: }
1190: message+='$alert{'domain'}';
1191: }
1.84 raeburn 1192: END
1.150 raeburn 1193: if ($showcredits) {
1194: $optional_checks .= <<END;
1195: if (foundcredits==0) {
1196: if (message!='') {
1197: message+='\\n';
1198: }
1199: message+='$alert{'credits'}';
1200: }
1201: END
1202: }
1.84 raeburn 1203: if (($mode eq 'upload') && ($context eq 'domain')) {
1204: $optional_checks .= (<<END);
1205:
1206: if (foundinststatus==0) {
1207: if (message!='') {
1208: message+='\\n';
1209: }
1210: message+='$alert{'inststatus'}';
1211: }
1212: END
1213: }
1214: $optional_checks .= (<<END);
1215:
1.1 raeburn 1216: if (message!='') {
1217: message+= '\\n$alert{'continue'}';
1218: if (confirm(message)) {
1219: vf.state.value='enrolling';
1.22 raeburn 1220: $finish
1.1 raeburn 1221: }
1222: } else {
1223: vf.state.value='enrolling';
1.22 raeburn 1224: $finish
1.1 raeburn 1225: }
1226: }
1227: END
1228: }
1.37 raeburn 1229: my $result = $function_name.$auth_checks.$optional_checks."\n".
1230: $section_checks.$authheader;
1.1 raeburn 1231: return $result;
1232: }
1.196 raeburn 1233:
1.1 raeburn 1234: ###############################################################
1235: ###############################################################
1236: sub upload_manager_javascript_forward_associate {
1.123 raeburn 1237: my ($can_assign) = @_;
1.132 raeburn 1238: my ($auth_update,$numbuttons,$argreset);
1.123 raeburn 1239: if (ref($can_assign) eq 'HASH') {
1.132 raeburn 1240: if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
1241: $argreset .= " vf.krbarg.value='';\n";
1242: $numbuttons ++ ;
1243: }
1244: if ($can_assign->{'int'}) {
1245: $argreset .= " vf.intarg.value='';\n";
1246: $numbuttons ++;
1247: }
1248: if ($can_assign->{'loc'}) {
1249: $argreset .= " vf.locarg.value='';\n";
1250: $numbuttons ++;
1251: }
1252: if (!$can_assign->{'int'}) {
1.170 damieng 1253: my $warning = &mt('You may not specify an initial password for each user, as this is only available when new users use LON-CAPA internal authentication.')."\n".
1.132 raeburn 1254: &mt('Your current role does not have rights to create users with that authentication type.');
1.170 damieng 1255: &js_escape(\$warning);
1.132 raeburn 1256: $auth_update = <<"END";
1257: // Currently the initial password field is only supported for internal auth
1258: // (see bug 6368).
1259: if (nw==9) {
1260: eval('vf.f'+tf+'.selectedIndex=0;')
1261: alert('$warning');
1262: }
1263: END
1264: } elsif ($numbuttons > 1) {
1.123 raeburn 1265: $auth_update = <<"END";
1266: // If we set the password, make the password form below correspond to
1267: // the new value.
1268: if (nw==9) {
1269: changed_radio('int',document.studentform);
1270: set_auth_radio_buttons('int',document.studentform);
1.132 raeburn 1271: $argreset
1272: }
1273:
1.123 raeburn 1274: END
1275: }
1276: }
1277:
1.1 raeburn 1278: return(<<ENDPICK);
1279: function verify(vf,sec_caller) {
1280: var founduname=0;
1281: var foundpwd=0;
1282: var foundname=0;
1283: var foundid=0;
1284: var foundsec=0;
1285: var foundemail=0;
1286: var foundrole=0;
1.57 raeburn 1287: var founddomain=0;
1.84 raeburn 1288: var foundinststatus=0;
1.150 raeburn 1289: var foundcredits=0;
1.1 raeburn 1290: var tw;
1291: for (i=0;i<=vf.nfields.value;i++) {
1292: tw=eval('vf.f'+i+'.selectedIndex');
1293: if (tw==1) { founduname=1; }
1294: if ((tw>=2) && (tw<=6)) { foundname=1; }
1295: if (tw==7) { foundid=1; }
1296: if (tw==8) { foundsec=1; }
1297: if (tw==9) { foundpwd=1; }
1298: if (tw==10) { foundemail=1; }
1299: if (tw==11) { foundrole=1; }
1.57 raeburn 1300: if (tw==12) { founddomain=1; }
1.84 raeburn 1301: if (tw==13) { foundinststatus=1; }
1.150 raeburn 1302: if (tw==14) { foundcredits=1; }
1.1 raeburn 1303: }
1.150 raeburn 1304: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits);
1.1 raeburn 1305: }
1306:
1307: //
1308: // vf = this.form
1309: // tf = column number
1310: //
1311: // values of nw
1312: //
1313: // 0 = none
1314: // 1 = username
1315: // 2 = names (lastname, firstnames)
1316: // 3 = fname (firstname)
1317: // 4 = mname (middlename)
1318: // 5 = lname (lastname)
1319: // 6 = gen (generation)
1320: // 7 = id
1321: // 8 = section
1322: // 9 = ipwd (password)
1323: // 10 = email address
1324: // 11 = role
1.57 raeburn 1325: // 12 = domain
1.84 raeburn 1326: // 13 = inststatus
1.150 raeburn 1327: // 14 = foundcredits
1.1 raeburn 1328:
1329: function flip(vf,tf) {
1330: var nw=eval('vf.f'+tf+'.selectedIndex');
1331: var i;
1332: // make sure no other columns are labeled the same as this one
1333: for (i=0;i<=vf.nfields.value;i++) {
1334: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
1335: eval('vf.f'+i+'.selectedIndex=0;')
1336: }
1337: }
1338: // If we set this to 'lastname, firstnames', clear out all the ones
1339: // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
1340: if (nw==2) {
1341: for (i=0;i<=vf.nfields.value;i++) {
1342: if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
1343: (eval('vf.f'+i+'.selectedIndex')<=6)) {
1344: eval('vf.f'+i+'.selectedIndex=0;')
1345: }
1346: }
1347: }
1348: // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
1349: // clear out any that are set to 'lastname, firstnames' (2)
1350: if ((nw>=3) && (nw<=6)) {
1351: for (i=0;i<=vf.nfields.value;i++) {
1352: if (eval('vf.f'+i+'.selectedIndex')==2) {
1353: eval('vf.f'+i+'.selectedIndex=0;')
1354: }
1355: }
1356: }
1.123 raeburn 1357: $auth_update
1.1 raeburn 1358: }
1359:
1360: function clearpwd(vf) {
1361: var i;
1362: for (i=0;i<=vf.nfields.value;i++) {
1363: if (eval('vf.f'+i+'.selectedIndex')==9) {
1364: eval('vf.f'+i+'.selectedIndex=0;')
1365: }
1366: }
1367: }
1368:
1369: ENDPICK
1370: }
1371:
1372: ###############################################################
1373: ###############################################################
1374: sub upload_manager_javascript_reverse_associate {
1.123 raeburn 1375: my ($can_assign) = @_;
1.132 raeburn 1376: my ($auth_update,$numbuttons,$argreset);
1.123 raeburn 1377: if (ref($can_assign) eq 'HASH') {
1.132 raeburn 1378: if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
1379: $argreset .= " vf.krbarg.value='';\n";
1380: $numbuttons ++ ;
1381: }
1382: if ($can_assign->{'int'}) {
1383: $argreset .= " vf.intarg.value='';\n";
1384: $numbuttons ++;
1385: }
1386: if ($can_assign->{'loc'}) {
1387: $argreset .= " vf.locarg.value='';\n";
1388: $numbuttons ++;
1389: }
1390: if (!$can_assign->{'int'}) {
1391: my $warning = &mt('You may not specify an initial password, as this is only available when new users use LON-CAPA internal authentication.\n').
1392: &mt('Your current role does not have rights to create users with that authentication type.');
1.170 damieng 1393: &js_escape(\$warning);
1.132 raeburn 1394: $auth_update = <<"END";
1395: // Currently the initial password field is only supported for internal auth
1396: // (see bug 6368).
1397: if (tf==8 && nw!=0) {
1398: eval('vf.f'+tf+'.selectedIndex=0;')
1399: alert('$warning');
1400: }
1401: END
1402: } elsif ($numbuttons > 1) {
1.123 raeburn 1403: $auth_update = <<"END";
1404: // initial password specified, pick internal authentication
1405: if (tf==8 && nw!=0) {
1406: changed_radio('int',document.studentform);
1407: set_auth_radio_buttons('int',document.studentform);
1.132 raeburn 1408: $argreset
1409: }
1410:
1.123 raeburn 1411: END
1412: }
1413: }
1.132 raeburn 1414:
1.1 raeburn 1415: return(<<ENDPICK);
1416: function verify(vf,sec_caller) {
1417: var founduname=0;
1418: var foundpwd=0;
1419: var foundname=0;
1420: var foundid=0;
1421: var foundsec=0;
1.131 raeburn 1422: var foundemail=0;
1.1 raeburn 1423: var foundrole=0;
1.57 raeburn 1424: var founddomain=0;
1.84 raeburn 1425: var foundinststatus=0;
1.150 raeburn 1426: var foundcredits=0;
1.1 raeburn 1427: var tw;
1428: for (i=0;i<=vf.nfields.value;i++) {
1429: tw=eval('vf.f'+i+'.selectedIndex');
1430: if (i==0 && tw!=0) { founduname=1; }
1431: if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
1432: if (i==6 && tw!=0) { foundid=1; }
1433: if (i==7 && tw!=0) { foundsec=1; }
1434: if (i==8 && tw!=0) { foundpwd=1; }
1.130 raeburn 1435: if (i==9 && tw!=0) { foundemail=1; }
1436: if (i==10 && tw!=0) { foundrole=1; }
1437: if (i==11 && tw!=0) { founddomain=1; }
1438: if (i==12 && tw!=0) { foundinstatus=1; }
1.150 raeburn 1439: if (i==13 && tw!=0) { foundcredits=1; }
1.1 raeburn 1440: }
1.150 raeburn 1441: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits);
1.1 raeburn 1442: }
1443:
1444: function flip(vf,tf) {
1445: var nw=eval('vf.f'+tf+'.selectedIndex');
1446: var i;
1447: // picked the all one name field, reset the other name ones to blank
1448: if (tf==1 && nw!=0) {
1449: for (i=2;i<=5;i++) {
1450: eval('vf.f'+i+'.selectedIndex=0;')
1451: }
1452: }
1453: //picked one of the piecewise name fields, reset the all in
1454: //one field to blank
1455: if ((tf>=2) && (tf<=5) && (nw!=0)) {
1456: eval('vf.f1.selectedIndex=0;')
1457: }
1.123 raeburn 1458: $auth_update
1.1 raeburn 1459: }
1460:
1461: function clearpwd(vf) {
1462: var i;
1463: if (eval('vf.f8.selectedIndex')!=0) {
1464: eval('vf.f8.selectedIndex=0;')
1465: }
1466: }
1467: ENDPICK
1468: }
1469:
1470: ###############################################################
1471: ###############################################################
1472: sub print_upload_manager_footer {
1.150 raeburn 1473: my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context,$permission,$crstype,
1474: $showcredits) = @_;
1.22 raeburn 1475: my $form = 'document.studentform';
1476: my $formname = 'studentform';
1.1 raeburn 1477: my ($krbdef,$krbdefdom) =
1478: &Apache::loncommon::get_kerberos_defaults($defdom);
1.22 raeburn 1479: my %param = ( formname => $form,
1.1 raeburn 1480: kerb_def_dom => $krbdefdom,
1481: kerb_def_auth => $krbdef
1482: );
1483: if (exists($env{'form.ipwd_choice'}) &&
1484: defined($env{'form.ipwd_choice'}) &&
1485: $env{'form.ipwd_choice'} ne '') {
1486: $param{'curr_authtype'} = 'int';
1487: }
1488: my $krbform = &Apache::loncommon::authform_kerberos(%param);
1489: my $intform = &Apache::loncommon::authform_internal(%param);
1490: my $locform = &Apache::loncommon::authform_local(%param);
1.194 raeburn 1491: my $ltiform = &Apache::loncommon::authform_lti(%param);
1.22 raeburn 1492: my $date_table = &date_setting_table(undef,undef,$context,undef,
1.101 raeburn 1493: $formname,$permission,$crstype);
1.95 bisitz 1494:
1.1 raeburn 1495: my $Str = "\n".'<div class="LC_left_float">';
1496: $Str .= &hidden_input('nfields',$i);
1497: $Str .= &hidden_input('keyfields',$keyfields);
1.95 bisitz 1498:
1499: $Str .= '<h3>'.&mt('Options').'</h3>'
1500: .&Apache::lonhtmlcommon::start_pick_box();
1501:
1502: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Login Type'));
1.1 raeburn 1503: if ($context eq 'domain') {
1.95 bisitz 1504: $Str .= '<p>'
1505: .&mt('Change authentication for existing users in domain "[_1]" to these settings?'
1506: ,$defdom)
1507: .' <span class="LC_nobreak"><label>'
1508: .'<input type="radio" name="changeauth" value="No" checked="checked" />'
1509: .&mt('No').'</label>'
1510: .' <label>'
1511: .'<input type="radio" name="changeauth" value="Yes" />'
1512: .&mt('Yes').'</label>'
1513: .'</span></p>';
1.1 raeburn 1514: } else {
1.95 bisitz 1515: $Str .= '<p class="LC_info">'."\n".
1516: &mt('This will not take effect if the user already exists.').
1.1 raeburn 1517: &Apache::loncommon::help_open_topic('Auth_Options').
1518: "</p>\n";
1519: }
1.194 raeburn 1520: $Str .= &set_login($defdom,$krbform,$intform,$locform,$ltiform);
1.95 bisitz 1521:
1.1 raeburn 1522: my ($home_server_pick,$numlib) =
1523: &Apache::loncommon::home_server_form_item($defdom,'lcserver',
1524: 'default','hide');
1525: if ($numlib > 1) {
1.97 raeburn 1526: $Str .= &Apache::lonhtmlcommon::row_closure()
1527: .&Apache::lonhtmlcommon::row_title(
1.95 bisitz 1528: &mt('LON-CAPA Home Server for New Users'))
1529: .&mt('LON-CAPA domain: [_1] with home server:','"'.$defdom.'"')
1530: .$home_server_pick
1531: .&Apache::lonhtmlcommon::row_closure();
1532: } else {
1.97 raeburn 1533: $Str .= $home_server_pick.
1534: &Apache::lonhtmlcommon::row_closure();
1.95 bisitz 1535: }
1536:
1.188 raeburn 1537: my ($trusted,$untrusted);
1.185 raeburn 1538: if ($context eq 'course') {
1.188 raeburn 1539: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.185 raeburn 1540: } elsif ($context eq 'author') {
1.188 raeburn 1541: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.185 raeburn 1542: }
1.95 bisitz 1543: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain'))
1.188 raeburn 1544: .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1,undef,$trusted,$untrusted)
1.95 bisitz 1545: .&Apache::lonhtmlcommon::row_closure();
1546:
1547: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Starting and Ending Dates'))
1548: ."<p>\n".$date_table."</p>\n"
1549: .&Apache::lonhtmlcommon::row_closure();
1550:
1.1 raeburn 1551: if ($context eq 'domain') {
1.95 bisitz 1552: $Str .= &Apache::lonhtmlcommon::row_title(
1553: &mt('Settings for assigning roles'))
1554: .&mt('Pick the action to take on roles for these users:').'<br />'
1555: .'<span class="LC_nobreak"><label>'
1556: .'<input type="radio" name="roleaction" value="norole" checked="checked" />'
1557: .' '.&mt('No role changes').'</label>'
1558: .' <label>'
1559: .'<input type="radio" name="roleaction" value="domain" />'
1560: .' '.&mt('Add a domain role').'</label>'
1561: .' <label>'
1562: .'<input type="radio" name="roleaction" value="course" />'
1.103 raeburn 1563: .' '.&mt('Add a course/community role').'</label>'
1.95 bisitz 1564: .'</span>';
1565: } elsif ($context eq 'author') {
1566: $Str .= &Apache::lonhtmlcommon::row_title(
1567: &mt('Default role'))
1568: .&mt('Choose the role to assign to users without a value specified in the uploaded file.')
1.1 raeburn 1569: } elsif ($context eq 'course') {
1.150 raeburn 1570: if ($showcredits) {
1571: $Str .= &Apache::lonhtmlcommon::row_title(
1572: &mt('Default role, section and credits'))
1573: .&mt('Choose the role and/or section(s) and/or credits to assign to users without values specified in the uploaded file.');
1574: } else {
1575: $Str .= &Apache::lonhtmlcommon::row_title(
1.95 bisitz 1576: &mt('Default role and section'))
1.150 raeburn 1577: .&mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file.');
1578: }
1.95 bisitz 1579: } else {
1580: $Str .= &Apache::lonhtmlcommon::row_title(
1581: &mt('Default role and/or section(s)'))
1582: .&mt('Role and/or section(s) for users without values specified in the uploaded file.');
1.1 raeburn 1583: }
1.22 raeburn 1584: if (($context eq 'domain') || ($context eq 'author')) {
1.95 bisitz 1585: $Str .= '<br />';
1.150 raeburn 1586: my ($options,$cb_script,$coursepick) =
1587: &default_role_selector($context,1,'',$showcredits);
1.22 raeburn 1588: if ($context eq 'domain') {
1.95 bisitz 1589: $Str .= '<p>'
1590: .'<b>'.&mt('Domain Level').'</b><br />'
1591: .$options
1592: .'</p><p>'
1593: .'<b>'.&mt('Course Level').'</b>'
1594: .'</p>'
1595: .$cb_script.$coursepick
1596: .&Apache::lonhtmlcommon::row_closure();
1.22 raeburn 1597: } elsif ($context eq 'author') {
1.95 bisitz 1598: $Str .= $options
1599: .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
1.22 raeburn 1600: }
1.1 raeburn 1601: } else {
1.22 raeburn 1602: my ($cnum,$cdom) = &get_course_identity();
1603: my $rowtitle = &mt('section');
1.150 raeburn 1604: my $defaultcredits;
1605: if ($showcredits) {
1606: $defaultcredits = &get_defaultcredits();
1607: }
1608: my $secbox = §ion_picker($cdom,$cnum,'Any',$rowtitle,$permission,
1609: $context,'upload',$crstype,$showcredits,
1610: $defaultcredits);
1.95 bisitz 1611: $Str .= $secbox
1612: .&Apache::lonhtmlcommon::row_closure();
1.101 raeburn 1613: my %lt;
1614: if ($crstype eq 'Community') {
1615: %lt = &Apache::lonlocal::texthash (
1616: disp => 'Display members with current/future access who are not in the uploaded file',
1617: stus => 'Members selected from this list can be dropped.'
1618: );
1619: } else {
1620: %lt = &Apache::lonlocal::texthash (
1621: disp => 'Display students with current/future access who are not in the uploaded file',
1622: stus => 'Students selected from this list can be dropped.'
1623: );
1624: }
1.95 bisitz 1625: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Full Update'))
1.101 raeburn 1626: .'<label><input type="checkbox" name="fullup" value="yes" />'
1627: .' '.$lt{'disp'}
1.95 bisitz 1628: .'</label><br />'
1.101 raeburn 1629: .$lt{'stus'}
1.95 bisitz 1630: .&Apache::lonhtmlcommon::row_closure();
1.1 raeburn 1631: }
1.5 raeburn 1632: if ($context eq 'course' || $context eq 'domain') {
1.161 bisitz 1633: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID'))
1634: .&forceid_change($context)
1635: .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
1.5 raeburn 1636: }
1.95 bisitz 1637:
1638: $Str .= &Apache::lonhtmlcommon::end_pick_box();
1.73 bisitz 1639: $Str .= '</div>';
1.95 bisitz 1640:
1641: # Footer
1642: $Str .= '<div class="LC_clear_float_footer">'
1643: .'<hr />';
1.1 raeburn 1644: if ($context eq 'course') {
1.95 bisitz 1645: $Str .= '<p class="LC_info">'
1.103 raeburn 1646: .&mt('Note: This operation may be time consuming when adding several users.')
1.95 bisitz 1647: .'</p>';
1.73 bisitz 1648: }
1.95 bisitz 1649: $Str .= '<p><input type="button"'
1.96 bisitz 1650: .' onclick="javascript:verify(this.form,this.form.csec)"'
1651: .' value="'.&mt('Update Users').'" />'
1.95 bisitz 1652: .'</p>'."\n"
1.73 bisitz 1653: .'</div>';
1.1 raeburn 1654: $r->print($Str);
1655: return;
1656: }
1657:
1.150 raeburn 1658: sub get_defaultcredits {
1659: my ($cdom,$cnum) = @_;
1660:
1661: if ($cdom eq '' || $cnum eq '') {
1662: return unless ($env{'request.course.id'});
1663: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1664: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1665: }
1666: return unless(($cdom =~ /^$match_domain$/) && ($cnum =~ /^$match_courseid$/));
1667: my ($defaultcredits,$domdefcredits);
1668: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
1.160 raeburn 1669: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
1.150 raeburn 1670: my $instcode = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
1671: if ($instcode) {
1672: $domdefcredits = $domdefaults{'officialcredits'};
1.160 raeburn 1673: } elsif ($env{'course.'.$cdom.'_'.$cnum.'.internal.textbook'}) {
1674: $domdefcredits = $domdefaults{'textbookcredits'};
1.150 raeburn 1675: } else {
1676: $domdefcredits = $domdefaults{'unofficialcredits'};
1677: }
1678: } else {
1679: return;
1680: }
1681:
1682: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
1683: $defaultcredits = $env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'};
1684: } elsif (exists($env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'})) {
1685: $defaultcredits = $env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'};
1686: } else {
1687: my %crsinfo =
1688: &Apache::lonnet::coursedescription("$cdom/$cnum",{'one_time' => 1});
1689: $defaultcredits = $crsinfo{'internal.defaultcredits'};
1690: }
1691: if ($defaultcredits eq '') {
1692: $defaultcredits = $domdefcredits;
1693: }
1694: return $defaultcredits;
1695: }
1696:
1.5 raeburn 1697: sub forceid_change {
1698: my ($context) = @_;
1699: my $output =
1.161 bisitz 1700: '<label><input type="checkbox" name="forceid" value="yes" />'
1.164 bisitz 1701: .&mt('Force change of existing ID')
1.163 raeburn 1702: .'</label>'.&Apache::loncommon::help_open_topic('ForceIDChange')."\n";
1.5 raeburn 1703: if ($context eq 'domain') {
1.163 raeburn 1704: $output .=
1705: '<br />'
1706: .'<label><input type="checkbox" name="recurseid" value="yes" />'
1707: .&mt("Update ID in user's course(s).").'</label>'."\n";
1.5 raeburn 1708: }
1709: return $output;
1710: }
1711:
1.1 raeburn 1712: ###############################################################
1713: ###############################################################
1714: sub print_upload_manager_form {
1.150 raeburn 1715: my ($r,$context,$permission,$crstype,$showcredits) = @_;
1.1 raeburn 1716: my $firstLine;
1717: my $datatoken;
1718: if (!$env{'form.datatoken'}) {
1719: $datatoken=&Apache::loncommon::upfile_store($r);
1720: } else {
1.189 raeburn 1721: $datatoken=&Apache::loncommon::valid_datatoken($env{'form.datatoken'});
1722: if ($datatoken ne '') {
1723: &Apache::loncommon::load_tmp_file($r,$datatoken);
1724: }
1.1 raeburn 1725: }
1.193 raeburn 1726: if ($datatoken eq '') {
1727: $r->print('<p class="LC_error">'.&mt('Error').': '.
1728: &mt('Invalid datatoken').'</p>');
1729: return 'missingdata';
1730: }
1.1 raeburn 1731: my @records=&Apache::loncommon::upfile_record_sep();
1732: if($env{'form.noFirstLine'}){
1733: $firstLine=shift(@records);
1734: }
1735: my $total=$#records;
1736: my $distotal=$total+1;
1737: my $today=time;
1738: my $halfyear=$today+15552000;
1739: #
1740: # Restore memorized settings
1741: my $col_setting_names = { 'username_choice' => 'scalar', # column settings
1742: 'names_choice' => 'scalar',
1743: 'fname_choice' => 'scalar',
1744: 'mname_choice' => 'scalar',
1745: 'lname_choice' => 'scalar',
1746: 'gen_choice' => 'scalar',
1747: 'id_choice' => 'scalar',
1748: 'sec_choice' => 'scalar',
1749: 'ipwd_choice' => 'scalar',
1750: 'email_choice' => 'scalar',
1751: 'role_choice' => 'scalar',
1.57 raeburn 1752: 'domain_choice' => 'scalar',
1.84 raeburn 1753: 'inststatus_choice' => 'scalar',
1.1 raeburn 1754: };
1.150 raeburn 1755: if ($showcredits) {
1756: $col_setting_names->{'credits_choice'} = 'scalar';
1757: }
1.1 raeburn 1758: if ($context eq 'course') {
1759: &Apache::loncommon::restore_course_settings('enrollment_upload',
1760: $col_setting_names);
1761: } else {
1762: &Apache::loncommon::restore_settings($context,'user_upload',
1763: $col_setting_names);
1764: }
1.150 raeburn 1765: my $defdom = $env{'request.role.domain'};
1.1 raeburn 1766: #
1767: # Determine kerberos parameters as appropriate
1768: my ($krbdef,$krbdefdom) =
1769: &Apache::loncommon::get_kerberos_defaults($defdom);
1770: #
1.123 raeburn 1771: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($defdom);
1.22 raeburn 1772: &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
1.123 raeburn 1773: $permission,$crstype,\%can_assign);
1.1 raeburn 1774: my $i;
1775: my $keyfields;
1776: if ($total>=0) {
1777: my @field=
1778: (['username',&mt('Username'), $env{'form.username_choice'}],
1779: ['names',&mt('Last Name, First Names'),$env{'form.names_choice'}],
1780: ['fname',&mt('First Name'), $env{'form.fname_choice'}],
1781: ['mname',&mt('Middle Names/Initials'),$env{'form.mname_choice'}],
1782: ['lname',&mt('Last Name'), $env{'form.lname_choice'}],
1783: ['gen', &mt('Generation'), $env{'form.gen_choice'}],
1.61 bisitz 1784: ['id', &mt('Student/Employee ID'),$env{'form.id_choice'}],
1.1 raeburn 1785: ['sec', &mt('Section'), $env{'form.sec_choice'}],
1786: ['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
1787: ['email',&mt('E-mail Address'), $env{'form.email_choice'}],
1.57 raeburn 1788: ['role',&mt('Role'), $env{'form.role_choice'}],
1.84 raeburn 1789: ['domain',&mt('Domain'), $env{'form.domain_choice'}],
1790: ['inststatus',&mt('Affiliation'), $env{'form.inststatus_choice'}]);
1.150 raeburn 1791: if ($showcredits) {
1792: push(@field,
1793: ['credits',&mt('Student Credits'), $env{'form.credits_choice'}]);
1794: }
1.1 raeburn 1795: if ($env{'form.upfile_associate'} eq 'reverse') {
1796: &Apache::loncommon::csv_print_samples($r,\@records);
1797: $i=&Apache::loncommon::csv_print_select_table($r,\@records,
1798: \@field);
1799: foreach (@field) {
1800: $keyfields.=$_->[0].',';
1801: }
1802: chop($keyfields);
1803: } else {
1804: unshift(@field,['none','']);
1805: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
1806: \@field);
1807: my %sone=&Apache::loncommon::record_sep($records[0]);
1808: $keyfields=join(',',sort(keys(%sone)));
1809: }
1810: }
1811: &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
1.150 raeburn 1812: $context,$permission,$crstype,$showcredits);
1.193 raeburn 1813: return 'ok';
1.1 raeburn 1814: }
1815:
1816: sub setup_date_selectors {
1.22 raeburn 1817: my ($starttime,$endtime,$mode,$nolink,$formname) = @_;
1818: if ($formname eq '') {
1819: $formname = 'studentform';
1820: }
1.1 raeburn 1821: if (! defined($starttime)) {
1822: $starttime = time;
1823: unless ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1824: if (exists($env{'course.'.$env{'request.course.id'}.
1825: '.default_enrollment_start_date'})) {
1826: $starttime = $env{'course.'.$env{'request.course.id'}.
1827: '.default_enrollment_start_date'};
1828: }
1829: }
1830: }
1831: if (! defined($endtime)) {
1832: $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1833: unless ($mode eq 'createcourse') {
1834: if (exists($env{'course.'.$env{'request.course.id'}.
1835: '.default_enrollment_end_date'})) {
1836: $endtime = $env{'course.'.$env{'request.course.id'}.
1837: '.default_enrollment_end_date'};
1838: }
1839: }
1840: }
1.11 raeburn 1841:
1842: my $startdateform =
1.22 raeburn 1843: &Apache::lonhtmlcommon::date_setter($formname,'startdate',$starttime,
1.11 raeburn 1844: undef,undef,undef,undef,undef,undef,undef,$nolink);
1845:
1846: my $enddateform =
1.22 raeburn 1847: &Apache::lonhtmlcommon::date_setter($formname,'enddate',$endtime,
1.11 raeburn 1848: undef,undef,undef,undef,undef,undef,undef,$nolink);
1849:
1.1 raeburn 1850: if ($mode eq 'create_enrolldates') {
1851: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1852: 'startenroll',
1853: $starttime);
1854: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1855: 'endenroll',
1856: $endtime);
1857: }
1858: if ($mode eq 'create_defaultdates') {
1859: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1860: 'startaccess',
1861: $starttime);
1862: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1863: 'endaccess',
1864: $endtime);
1865: }
1866: return ($startdateform,$enddateform);
1867: }
1868:
1869:
1870: sub get_dates_from_form {
1.54 raeburn 1871: my ($startname,$endname) = @_;
1872: if ($startname eq '') {
1873: $startname = 'startdate';
1874: }
1875: if ($endname eq '') {
1876: $endname = 'enddate';
1877: }
1878: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
1879: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.1 raeburn 1880: if ($env{'form.no_end_date'}) {
1881: $enddate = 0;
1882: }
1883: return ($startdate,$enddate);
1884: }
1885:
1886: sub date_setting_table {
1.101 raeburn 1887: my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission,$crstype) = @_;
1.11 raeburn 1888: my $nolink;
1889: if ($bulkaction) {
1890: $nolink = 1;
1891: }
1892: my ($startform,$endform) =
1.22 raeburn 1893: &setup_date_selectors($starttime,$endtime,$mode,$nolink,$formname);
1.1 raeburn 1894: my $dateDefault;
1895: if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1896: $dateDefault = ' ';
1.13 raeburn 1897: } elsif ($mode ne 'author' && $mode ne 'domain') {
1.11 raeburn 1898: if (($bulkaction eq 'reenable') ||
1899: ($bulkaction eq 'activate') ||
1.22 raeburn 1900: ($bulkaction eq 'chgdates') ||
1901: ($env{'form.action'} eq 'upload')) {
1902: if ($env{'request.course.sec'} eq '') {
1903: $dateDefault = '<span class="LC_nobreak">'.
1.101 raeburn 1904: '<label><input type="checkbox" name="makedatesdefault" value="1" /> ';
1905: if ($crstype eq 'Community') {
1906: $dateDefault .= &mt("make these dates the default access dates for future community enrollment");
1907: } else {
1908: $dateDefault .= &mt("make these dates the default access dates for future course enrollment");
1909: }
1910: $dateDefault .= '</label></span>';
1.22 raeburn 1911: }
1.11 raeburn 1912: }
1.1 raeburn 1913: }
1.11 raeburn 1914: my $perpetual = '<span class="LC_nobreak"><label><input type="checkbox" name="no_end_date"';
1.1 raeburn 1915: if (defined($endtime) && $endtime == 0) {
1.70 bisitz 1916: $perpetual .= ' checked="checked"';
1.1 raeburn 1917: }
1.11 raeburn 1918: $perpetual.= ' /> '.&mt('no ending date').'</label></span>';
1.1 raeburn 1919: if ($mode eq 'create_enrolldates') {
1920: $perpetual = ' ';
1921: }
1.11 raeburn 1922: my $result = &Apache::lonhtmlcommon::start_pick_box()."\n";
1923: $result .= &Apache::lonhtmlcommon::row_title(&mt('Starting Date'),
1924: 'LC_oddrow_value')."\n".
1925: $startform."\n".
1926: &Apache::lonhtmlcommon::row_closure(1).
1927: &Apache::lonhtmlcommon::row_title(&mt('Ending Date'),
1928: 'LC_oddrow_value')."\n".
1929: $endform.' '.$perpetual.
1930: &Apache::lonhtmlcommon::row_closure(1).
1.22 raeburn 1931: &Apache::lonhtmlcommon::end_pick_box();
1.1 raeburn 1932: if ($dateDefault) {
1933: $result .= $dateDefault.'<br />'."\n";
1934: }
1935: return $result;
1936: }
1937:
1938: sub make_dates_default {
1.101 raeburn 1939: my ($startdate,$enddate,$context,$crstype) = @_;
1.1 raeburn 1940: my $result = '';
1941: if ($context eq 'course') {
1.17 raeburn 1942: my ($cnum,$cdom) = &get_course_identity();
1.1 raeburn 1943: my $put_result = &Apache::lonnet::put('environment',
1944: {'default_enrollment_start_date'=>$startdate,
1.17 raeburn 1945: 'default_enrollment_end_date' =>$enddate},$cdom,$cnum);
1.1 raeburn 1946: if ($put_result eq 'ok') {
1.101 raeburn 1947: if ($crstype eq 'Community') {
1948: $result .= &mt('Set default start and end access dates for community.');
1949: } else {
1950: $result .= &mt('Set default start and end access dates for course.');
1951: }
1952: $result .= '<br />'."\n";
1.1 raeburn 1953: #
1954: # Refresh the course environment
1955: &Apache::lonnet::coursedescription($env{'request.course.id'},
1956: {'freshen_cache' => 1});
1957: } else {
1.101 raeburn 1958: if ($crstype eq 'Community') {
1959: $result .= &mt('Unable to set default access dates for community');
1960: } else {
1961: $result .= &mt('Unable to set default access dates for course');
1962: }
1963: $result .= ':'.$put_result.'<br />';
1.1 raeburn 1964: }
1965: }
1966: return $result;
1967: }
1968:
1969: sub default_role_selector {
1.150 raeburn 1970: my ($context,$checkpriv,$crstype,$showcredits) = @_;
1.1 raeburn 1971: my %customroles;
1972: my ($options,$coursepick,$cb_jscript);
1.13 raeburn 1973: if ($context ne 'author') {
1.104 raeburn 1974: %customroles = &my_custom_roles($crstype);
1.1 raeburn 1975: }
1976:
1977: my %lt=&Apache::lonlocal::texthash(
1978: 'rol' => "Role",
1979: 'grs' => "Section",
1980: 'exs' => "Existing sections",
1981: 'new' => "New section",
1.150 raeburn 1982: 'crd' => "Credits",
1.1 raeburn 1983: );
1984: $options = '<select name="defaultrole">'."\n".
1985: ' <option value="">'.&mt('Please select').'</option>'."\n";
1986: if ($context eq 'course') {
1.101 raeburn 1987: $options .= &default_course_roles($context,$checkpriv,$crstype,%customroles);
1.13 raeburn 1988: } elsif ($context eq 'author') {
1.2 raeburn 1989: my @roles = &construction_space_roles($checkpriv);
1.1 raeburn 1990: foreach my $role (@roles) {
1991: my $plrole=&Apache::lonnet::plaintext($role);
1992: $options .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1993: }
1994: } elsif ($context eq 'domain') {
1.2 raeburn 1995: my @roles = &domain_roles($checkpriv);
1.1 raeburn 1996: foreach my $role (@roles) {
1997: my $plrole=&Apache::lonnet::plaintext($role);
1998: $options .= ' <option value="'.$role.'">'.$plrole.'</option>';
1999: }
2000: my $courseform = &Apache::loncommon::selectcourse_link
1.103 raeburn 2001: ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course/Community');
1.150 raeburn 2002: my ($credit_elem,$creditsinput);
2003: if ($showcredits) {
2004: $credit_elem = 'credits';
2005: $creditsinput = '<td><input type="text" name="credits" value="" /></td>';
2006: }
1.1 raeburn 2007: $cb_jscript =
1.150 raeburn 2008: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform','courserole','Course/Community',$credit_elem);
1.1 raeburn 2009: $coursepick = &Apache::loncommon::start_data_table().
2010: &Apache::loncommon::start_data_table_header_row().
2011: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th>'.
2012: '<th>'.$lt{'grs'}.'</th>'.
1.150 raeburn 2013: '<th>'.$lt{'crd'}.'</th>'.
1.1 raeburn 2014: &Apache::loncommon::end_data_table_header_row().
2015: &Apache::loncommon::start_data_table_row()."\n".
1.103 raeburn 2016: '<td><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'studentform','dccourse','dcdomain','coursedesc','','','','crstype'".')" /></td>'."\n".
1.1 raeburn 2017: '<td><select name="courserole">'."\n".
1.101 raeburn 2018: &default_course_roles($context,$checkpriv,'Course',%customroles)."\n".
1.1 raeburn 2019: '</select></td><td>'.
2020: '<table class="LC_createuser">'.
1.162 bisitz 2021: '<tr class="LC_section_row"><td valign="top">'.
1.22 raeburn 2022: $lt{'exs'}.'<br /><select name="currsec">'.
1.162 bisitz 2023: ' <option value=""><--'.&mt('Pick course first').
1.1 raeburn 2024: '</select></td>'.
2025: '<td> </td>'.
2026: '<td valign="top">'.$lt{'new'}.'<br />'.
2027: '<input type="text" name="newsec" value="" size="5" />'.
1.22 raeburn 2028: '<input type="hidden" name="groups" value="" />'.
2029: '<input type="hidden" name="sections" value="" />'.
2030: '<input type="hidden" name="origdom" value="'.
2031: $env{'request.role.domain'}.'" />'.
2032: '<input type="hidden" name="dccourse" value="" />'.
2033: '<input type="hidden" name="dcdomain" value="" />'.
1.103 raeburn 2034: '<input type="hidden" name="crstype" value="" />'.
1.150 raeburn 2035: '</td></tr></table></td>'.$creditsinput.
1.1 raeburn 2036: &Apache::loncommon::end_data_table_row().
1.22 raeburn 2037: &Apache::loncommon::end_data_table()."\n";
1.1 raeburn 2038: }
2039: $options .= '</select>';
2040: return ($options,$cb_jscript,$coursepick);
2041: }
2042:
2043: sub default_course_roles {
1.101 raeburn 2044: my ($context,$checkpriv,$crstype,%customroles) = @_;
1.1 raeburn 2045: my $output;
1.17 raeburn 2046: my $custom = 1;
1.101 raeburn 2047: my @roles = &course_roles($context,$checkpriv,$custom,lc($crstype));
1.1 raeburn 2048: foreach my $role (@roles) {
1.22 raeburn 2049: if ($role ne 'cr') {
1.101 raeburn 2050: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.22 raeburn 2051: $output .= ' <option value="'.$role.'">'.$plrole.'</option>';
2052: }
1.1 raeburn 2053: }
2054: if (keys(%customroles) > 0) {
1.22 raeburn 2055: if (grep(/^cr$/,@roles)) {
2056: foreach my $cust (sort(keys(%customroles))) {
2057: my $custrole='cr_'.$env{'user.domain'}.
2058: '_'.$env{'user.name'}.'_'.$cust;
2059: $output .= ' <option value="'.$custrole.'">'.$cust.'</option>';
2060: }
1.1 raeburn 2061: }
2062: }
2063: return $output;
2064: }
2065:
2066: sub construction_space_roles {
1.2 raeburn 2067: my ($checkpriv) = @_;
1.17 raeburn 2068: my @allroles = &roles_by_context('author');
1.1 raeburn 2069: my @roles;
1.2 raeburn 2070: if ($checkpriv) {
2071: foreach my $role (@allroles) {
2072: if (&Apache::lonnet::allowed('c'.$role,$env{'user.domain'}.'/'.$env{'user.name'})) {
2073: push(@roles,$role);
1.218 raeburn 2074: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2075: my ($audom,$auname) = ($1,$2);
2076: if (($role eq 'ca') || ($role eq 'aa')) {
2077: if ((&Apache::lonnet::allowed('v'.$role,,$audom.'/'.$auname)) &&
2078: ($env{"environment.internal.manager./$audom/$auname"})) {
2079: push(@roles,$role);
2080: }
2081: }
1.2 raeburn 2082: }
1.1 raeburn 2083: }
1.2 raeburn 2084: return @roles;
2085: } else {
2086: return @allroles;
1.1 raeburn 2087: }
2088: }
2089:
2090: sub domain_roles {
1.2 raeburn 2091: my ($checkpriv) = @_;
1.17 raeburn 2092: my @allroles = &roles_by_context('domain');
1.1 raeburn 2093: my @roles;
1.2 raeburn 2094: if ($checkpriv) {
2095: foreach my $role (@allroles) {
2096: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
2097: push(@roles,$role);
2098: }
1.1 raeburn 2099: }
1.2 raeburn 2100: return @roles;
2101: } else {
2102: return @allroles;
1.1 raeburn 2103: }
2104: }
2105:
2106: sub course_roles {
1.101 raeburn 2107: my ($context,$checkpriv,$custom,$roletype) = @_;
1.102 raeburn 2108: my $crstype;
2109: if ($roletype eq 'community') {
2110: $crstype = 'Community' ;
2111: } else {
2112: $crstype = 'Course';
2113: }
2114: my @allroles = &roles_by_context('course',$custom,$crstype);
1.1 raeburn 2115: my @roles;
2116: if ($context eq 'domain') {
2117: @roles = @allroles;
2118: } elsif ($context eq 'course') {
2119: if ($env{'request.course.id'}) {
1.2 raeburn 2120: if ($checkpriv) {
2121: foreach my $role (@allroles) {
2122: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
2123: push(@roles,$role);
2124: } else {
1.101 raeburn 2125: if ((($role ne 'cc') && ($role ne 'co')) && ($env{'request.course.sec'} ne '')) {
1.22 raeburn 2126: if (&Apache::lonnet::allowed('c'.$role,
1.2 raeburn 2127: $env{'request.course.id'}.'/'.
1.22 raeburn 2128: $env{'request.course.sec'})) {
1.2 raeburn 2129: push(@roles,$role);
2130: }
1.1 raeburn 2131: }
2132: }
2133: }
1.2 raeburn 2134: } else {
2135: @roles = @allroles;
1.1 raeburn 2136: }
2137: }
2138: }
2139: return @roles;
2140: }
2141:
2142: sub curr_role_permissions {
1.101 raeburn 2143: my ($context,$setting,$checkpriv,$type) = @_;
1.17 raeburn 2144: my $custom = 1;
1.1 raeburn 2145: my @roles;
1.13 raeburn 2146: if ($context eq 'author') {
1.2 raeburn 2147: @roles = &construction_space_roles($checkpriv);
1.1 raeburn 2148: } elsif ($context eq 'domain') {
2149: if ($setting eq 'course') {
1.101 raeburn 2150: @roles = &course_roles($context,$checkpriv,$custom,$type);
1.1 raeburn 2151: } else {
1.2 raeburn 2152: @roles = &domain_roles($checkpriv);
1.1 raeburn 2153: }
2154: } elsif ($context eq 'course') {
1.101 raeburn 2155: @roles = &course_roles($context,$checkpriv,$custom,$type);
1.1 raeburn 2156: }
2157: return @roles;
2158: }
2159:
2160: # ======================================================= Existing Custom Roles
2161:
2162: sub my_custom_roles {
1.175 raeburn 2163: my ($crstype,$udom,$uname) = @_;
1.1 raeburn 2164: my %returnhash=();
1.137 raeburn 2165: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
1.175 raeburn 2166: my %rolehash=&Apache::lonnet::dump('roles',$udom,$uname);
1.104 raeburn 2167: foreach my $key (keys(%rolehash)) {
1.1 raeburn 2168: if ($key=~/^rolesdef\_(\w+)$/) {
1.207 raeburn 2169: my $role = $1;
1.104 raeburn 2170: if ($crstype eq 'Community') {
2171: next if ($rolehash{$key} =~ /bre\&S/);
2172: }
1.207 raeburn 2173: $returnhash{$role}=$role;
1.1 raeburn 2174: }
2175: }
2176: return %returnhash;
2177: }
2178:
1.2 raeburn 2179: sub print_userlist {
2180: my ($r,$mode,$permission,$context,$formname,$totcodes,$codetitles,
1.150 raeburn 2181: $idlist,$idlist_titles,$showcredits) = @_;
1.2 raeburn 2182: my $format = $env{'form.output'};
1.1 raeburn 2183: if (! exists($env{'form.sortby'})) {
2184: $env{'form.sortby'} = 'username';
2185: }
1.221 raeburn 2186: my ($showstart,$showend);
2187: if (($env{'form.Status'} eq '') && ($env{'form.phase'} eq '') &&
2188: ($env{'form.showrole'} eq '') && ($context eq 'course') &&
2189: ($env{'request.course.id'} ne '') &&
2190: ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'} ne '')) {
2191: my $now = time;
2192: my $startaccess = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
2193: my $endaccess = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
2194: if (($startaccess) && ($startaccess > $now)) {
2195: $env{'form.Status'} = 'Future';
2196: $showstart = 1;
2197: }
2198: if (($endaccess ne '') && ($endaccess != 0) && ($endaccess < $now)) {
2199: $env{'form.Status'} = 'Expired';
2200: undef($showstart);
2201: $showend = 1;
2202: }
2203: }
1.2 raeburn 2204: if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
2205: $env{'form.Status'} = 'Active';
1.1 raeburn 2206: }
1.140 raeburn 2207: my $onchange = "javascript:updateCols('Status');";
1.1 raeburn 2208: my $status_select = &Apache::lonhtmlcommon::StatusOptions
1.140 raeburn 2209: ($env{'form.Status'},undef,undef,$onchange);
1.1 raeburn 2210:
1.2 raeburn 2211: if ($env{'form.showrole'} eq '') {
1.13 raeburn 2212: if ($context eq 'course') {
2213: $env{'form.showrole'} = 'st';
2214: } else {
2215: $env{'form.showrole'} = 'Any';
2216: }
1.2 raeburn 2217: }
1.1 raeburn 2218: if (! defined($env{'form.output'}) ||
2219: $env{'form.output'} !~ /^(csv|excel|html)$/ ) {
2220: $env{'form.output'} = 'html';
2221: }
2222:
1.2 raeburn 2223: my @statuses;
2224: if ($env{'form.Status'} eq 'Any') {
2225: @statuses = ('previous','active','future');
2226: } elsif ($env{'form.Status'} eq 'Expired') {
2227: @statuses = ('previous');
2228: } elsif ($env{'form.Status'} eq 'Active') {
2229: @statuses = ('active');
2230: } elsif ($env{'form.Status'} eq 'Future') {
2231: @statuses = ('future');
2232: }
1.1 raeburn 2233:
2234: # Interface output
1.2 raeburn 2235: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
2236: '<input type="hidden" name="action" value="'.
1.1 raeburn 2237: $env{'form.action'}.'" />');
1.140 raeburn 2238: $r->print('<div>'."\n");
1.1 raeburn 2239: if ($env{'form.action'} ne 'modifystudent') {
2240: my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
2241: 'excel' => "Excel",
2242: 'html' => 'HTML');
1.140 raeburn 2243: my $output_selector = '<select size="1" name="output" onchange="javascript:updateCols('."'output'".');" >';
1.1 raeburn 2244: foreach my $outputformat ('html','csv','excel') {
1.96 bisitz 2245: my $option = '<option value="'.$outputformat.'"';
1.1 raeburn 2246: if ($outputformat eq $env{'form.output'}) {
1.96 bisitz 2247: $option .= ' selected="selected"';
1.1 raeburn 2248: }
2249: $option .='>'.$lt{$outputformat}.'</option>';
2250: $output_selector .= "\n".$option;
2251: }
2252: $output_selector .= '</select>';
1.140 raeburn 2253: $r->print('<span class="LC_nobreak">'
1.70 bisitz 2254: .&mt('Output Format: [_1]',$output_selector)
1.140 raeburn 2255: .'</span>'.(' 'x3));
1.70 bisitz 2256: }
1.140 raeburn 2257: $r->print('<span class="LC_nobreak">'
1.70 bisitz 2258: .&mt('User Status: [_1]',$status_select)
1.140 raeburn 2259: .'</span>'.(' 'x3)."\n");
1.2 raeburn 2260: my $roleselected = '';
2261: if ($env{'form.showrole'} eq 'Any') {
1.91 bisitz 2262: $roleselected = ' selected="selected"';
1.2 raeburn 2263: }
1.53 raeburn 2264: my ($cnum,$cdom);
2265: $r->print(&role_filter($context));
2266: if ($context eq 'course') {
2267: ($cnum,$cdom) = &get_course_identity();
2268: $r->print(§ion_group_filter($cnum,$cdom));
1.2 raeburn 2269: }
1.140 raeburn 2270: $r->print('</div><div class="LC_left_float">'.
1.221 raeburn 2271: &column_checkboxes($context,$mode,$formname,$showcredits,$showstart,$showend).
1.149 raeburn 2272: '</div>');
1.78 raeburn 2273: if ($env{'form.phase'} eq '') {
1.149 raeburn 2274: $r->print('<br clear="all" />'.
2275: &list_submit_button(&mt('Display List of Users'))."\n".
1.78 raeburn 2276: '<input type="hidden" name="phase" value="" /></form>');
2277: return;
2278: }
1.106 raeburn 2279: if (!(($context eq 'domain') &&
2280: (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
1.149 raeburn 2281: $r->print('<br clear="all" />'.
2282: &list_submit_button(&mt('Update Display'))."\n");
1.140 raeburn 2283: }
2284:
1.150 raeburn 2285: my @cols = &infocolumns($context,$mode,$showcredits);
1.140 raeburn 2286: if (!@cols) {
1.152 bisitz 2287: $r->print('<hr style="clear:both;" /><span class="LC_warning">'.
1.140 raeburn 2288: &mt('No user information selected for display.').'</span>'.
2289: '<input type="hidden" name="phase" value="display" /></form>'."\n");
2290: return;
1.2 raeburn 2291: }
2292: my ($indexhash,$keylist) = &make_keylist_array();
1.159 raeburn 2293: my (%userlist,%userinfo,$clearcoursepick,$needauthorquota,$needauthorusage);
1.102 raeburn 2294: if (($context eq 'domain') &&
2295: ($env{'form.roletype'} eq 'course') ||
2296: ($env{'form.roletype'} eq 'community')) {
2297: my ($crstype,$numcodes,$title,$warning);
2298: if ($env{'form.roletype'} eq 'course') {
2299: $crstype = 'Course';
2300: $numcodes = $totcodes;
2301: $title = &mt('Select Courses');
2302: $warning = &mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.');
2303: } elsif ($env{'form.roletype'} eq 'community') {
2304: $crstype = 'Community';
2305: $numcodes = 0;
2306: $title = &mt('Select Communities');
2307: $warning = &mt('Warning: data retrieval for multiple communities can take considerable time, as this operation is not currently optimized.');
2308: }
1.120 raeburn 2309: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1.3 raeburn 2310: my $courseform =
1.102 raeburn 2311: &Apache::lonhtmlcommon::course_selection($formname,$numcodes,
1.120 raeburn 2312: $codetitles,$idlist,$idlist_titles,$crstype,
2313: \@standardnames);
1.148 bisitz 2314: $r->print('<div class="LC_left_float">'.
2315: '<fieldset><legend>'.$title.'</legend>'."\n".
1.3 raeburn 2316: $courseform."\n".
1.148 bisitz 2317: '</fieldset></div><br clear="all" />'.
1.106 raeburn 2318: '<p><input type="hidden" name="origroletype" value="'.$env{'form.roletype'}.'" />'.
2319: &list_submit_button(&mt('Update Display')).
1.102 raeburn 2320: "\n".'</p><span class="LC_warning">'.$warning.'</span>'."\n");
1.106 raeburn 2321: $clearcoursepick = 0;
2322: if (($env{'form.origroletype'} ne '') &&
2323: ($env{'form.origroletype'} ne $env{'form.roletype'})) {
2324: $clearcoursepick = 1;
2325: }
2326: if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
1.147 bisitz 2327: $r->print('<hr />'.&mt('Searching ...').'<br /> <br />');
1.11 raeburn 2328: }
2329: } else {
1.152 bisitz 2330: $r->print('<hr style="clear:both;" /><div id="searching">'.&mt('Searching ...').'</div>');
1.3 raeburn 2331: }
2332: $r->rflush();
1.1 raeburn 2333: if ($context eq 'course') {
1.46 raeburn 2334: if (($env{'form.showrole'} eq 'st') || ($env{'form.showrole'} eq 'Any')) {
1.45 raeburn 2335: my $classlist = &Apache::loncoursedata::get_classlist();
1.66 raeburn 2336: if (ref($classlist) eq 'HASH') {
2337: %userlist = %{$classlist};
2338: }
1.45 raeburn 2339: }
1.43 raeburn 2340: if ($env{'form.showrole'} ne 'st') {
2341: my $showroles;
2342: if ($env{'form.showrole'} ne 'Any') {
2343: $showroles = [$env{'form.showrole'}];
1.3 raeburn 2344: } else {
1.43 raeburn 2345: $showroles = undef;
1.1 raeburn 2346: }
1.43 raeburn 2347: my $withsec = 1;
2348: my $hidepriv = 1;
2349: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
2350: \@statuses,$showroles,undef,$withsec,$hidepriv);
2351: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
2352: \%advrolehash,$permission);
1.1 raeburn 2353: }
1.2 raeburn 2354: } else {
2355: my (%cstr_roles,%dom_roles);
1.13 raeburn 2356: if ($context eq 'author') {
1.218 raeburn 2357: my @possroles = &roles_by_context($context);
2358: my @allowedroles;
1.2 raeburn 2359: # List co-authors and assistant co-authors
1.218 raeburn 2360: my ($auname,$audom);
2361: if ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2362: ($audom,$auname) = ($1,$2);
2363: foreach my $role (@possroles) {
2364: if ((&Apache::lonnet::allowed('v'.$role,"$audom/$auname")) ||
2365: (&Apache::lonnet::allowed('c'.$role,"$audom/$auname"))) {
2366: push(@allowedroles,$role);
2367: }
2368: }
2369: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
2370: if ($1 eq $env{'user.domain'}) {
2371: $auname = $env{'user.name'};
2372: $audom = $env{'user.domain'};
2373: }
2374: @allowedroles = @possroles;
2375: }
2376: if (($auname ne '') && ($audom ne '')) {
2377: %cstr_roles = &Apache::lonnet::get_my_roles($auname,$audom,undef,
2378: \@statuses,\@allowedroles);
2379: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
2380: \%cstr_roles,$permission);
2381: }
1.2 raeburn 2382: } elsif ($context eq 'domain') {
2383: if ($env{'form.roletype'} eq 'domain') {
1.159 raeburn 2384: if (grep(/^authorusage$/,@cols)) {
2385: $needauthorusage = 1;
2386: }
2387: if (grep(/^authorquota$/,@cols)) {
2388: $needauthorquota = 1;
2389: }
1.2 raeburn 2390: %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'});
2391: foreach my $key (keys(%dom_roles)) {
2392: if (ref($dom_roles{$key}) eq 'HASH') {
2393: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 2394: \%userinfo,$dom_roles{$key},$permission);
1.2 raeburn 2395: }
2396: }
1.13 raeburn 2397: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 2398: my %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'},['au']);
2399: my %coauthors;
2400: foreach my $key (keys(%dom_roles)) {
2401: if (ref($dom_roles{$key}) eq 'HASH') {
2402: if ($env{'form.showrole'} eq 'au') {
2403: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 2404: \%userinfo,$dom_roles{$key},$permission);
1.2 raeburn 2405: } else {
2406: my @possroles;
2407: if ($env{'form.showrole'} eq 'Any') {
1.22 raeburn 2408: @possroles = &roles_by_context('author');
1.2 raeburn 2409: } else {
2410: @possroles = ($env{'form.showrole'});
2411: }
2412: foreach my $author (sort(keys(%{$dom_roles{$key}}))) {
1.22 raeburn 2413: my ($role,$authorname,$authordom) = split(/:/,$author,-1);
1.2 raeburn 2414: my $extent = '/'.$authordom.'/'.$authorname;
2415: %{$coauthors{$extent}} =
2416: &Apache::lonnet::get_my_roles($authorname,
2417: $authordom,undef,\@statuses,\@possroles);
2418: }
2419: &gather_userinfo($context,$format,\%userlist,
1.11 raeburn 2420: $indexhash,\%userinfo,\%coauthors,$permission);
1.2 raeburn 2421: }
2422: }
2423: }
1.101 raeburn 2424: } elsif (($env{'form.roletype'} eq 'course') ||
2425: ($env{'form.roletype'} eq 'community')) {
1.106 raeburn 2426: if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
1.2 raeburn 2427: my %courses = &process_coursepick();
1.39 raeburn 2428: my %allusers;
2429: my $hidepriv = 1;
1.2 raeburn 2430: foreach my $cid (keys(%courses)) {
1.17 raeburn 2431: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
1.11 raeburn 2432: next if ($cnum eq '' || $cdom eq '');
1.17 raeburn 2433: my $custom = 1;
1.2 raeburn 2434: my (@roles,@sections,%access,%users,%userdata,
1.6 albertel 2435: %statushash);
1.2 raeburn 2436: if ($env{'form.showrole'} eq 'Any') {
1.101 raeburn 2437: @roles = &course_roles($context,undef,$custom,
2438: $env{'form.roletype'});
1.2 raeburn 2439: } else {
2440: @roles = ($env{'form.showrole'});
2441: }
2442: foreach my $role (@roles) {
2443: %{$users{$role}} = ();
2444: }
2445: foreach my $type (@statuses) {
2446: $access{$type} = $type;
2447: }
1.39 raeburn 2448: &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash,$hidepriv);
1.2 raeburn 2449: foreach my $user (keys(%userdata)) {
2450: next if (ref($userinfo{$user}) eq 'HASH');
2451: foreach my $item ('fullname','id') {
2452: $userinfo{$user}{$item} = $userdata{$user}[$indexhash->{$item}];
2453: }
2454: }
2455: foreach my $role (keys(%users)) {
2456: foreach my $user (keys(%{$users{$role}})) {
2457: my $uniqid = $user.':'.$role;
2458: $allusers{$uniqid}{$cid} = { desc => $cdesc,
2459: secs => $statushash{$user}{$role},
2460: };
2461: }
2462: }
2463: }
2464: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 2465: \%userinfo,\%allusers,$permission);
1.2 raeburn 2466: } else {
1.10 raeburn 2467: $r->print('<input type="hidden" name="phase" value="'.
2468: $env{'form.phase'}.'" /></form>');
1.2 raeburn 2469: return;
2470: }
1.1 raeburn 2471: }
2472: }
1.3 raeburn 2473: }
2474: if (keys(%userlist) == 0) {
1.142 bisitz 2475: my $msg = '';
1.13 raeburn 2476: if ($context eq 'author') {
1.142 bisitz 2477: $msg = &mt('There are no co-authors to display.');
1.3 raeburn 2478: } elsif ($context eq 'domain') {
2479: if ($env{'form.roletype'} eq 'domain') {
1.142 bisitz 2480: $msg = &mt('There are no users with domain roles to display.');
1.13 raeburn 2481: } elsif ($env{'form.roletype'} eq 'author') {
1.142 bisitz 2482: $msg = &mt('There are no authors or co-authors to display.');
1.3 raeburn 2483: } elsif ($env{'form.roletype'} eq 'course') {
1.142 bisitz 2484: $msg = &mt('There are no course users to display');
1.101 raeburn 2485: } elsif ($env{'form.roletype'} eq 'community') {
1.142 bisitz 2486: $msg = &mt('There are no community users to display');
1.2 raeburn 2487: }
1.3 raeburn 2488: } elsif ($context eq 'course') {
2489: $r->print(&mt('There are no course users to display.')."\n");
2490: }
1.148 bisitz 2491: $r->print('<p class="LC_info">'.$msg.'</p>'."\n") if $msg;
1.3 raeburn 2492: } else {
2493: # Print out the available choices
1.4 raeburn 2494: my $usercount;
1.3 raeburn 2495: if ($env{'form.action'} eq 'modifystudent') {
1.10 raeburn 2496: ($usercount) = &show_users_list($r,$context,'view',$permission,
1.150 raeburn 2497: $env{'form.Status'},\%userlist,$keylist,'',
2498: $showcredits);
1.1 raeburn 2499: } else {
1.4 raeburn 2500: ($usercount) = &show_users_list($r,$context,$env{'form.output'},
1.150 raeburn 2501: $permission,$env{'form.Status'},\%userlist,
1.159 raeburn 2502: $keylist,'',$showcredits,$needauthorquota,$needauthorusage);
1.4 raeburn 2503: }
2504: if (!$usercount) {
1.142 bisitz 2505: $r->print('<br /><span class="LC_info">'
1.72 bisitz 2506: .&mt('There are no users matching the search criteria.')
2507: .'</span>'
2508: );
1.2 raeburn 2509: }
2510: }
1.10 raeburn 2511: $r->print('<input type="hidden" name="phase" value="'.
2512: $env{'form.phase'}.'" /></form>');
1.140 raeburn 2513: return;
1.2 raeburn 2514: }
2515:
1.53 raeburn 2516: sub role_filter {
2517: my ($context) = @_;
2518: my $output;
2519: my $roleselected = '';
2520: if ($env{'form.showrole'} eq 'Any') {
1.91 bisitz 2521: $roleselected = ' selected="selected"';
1.53 raeburn 2522: }
2523: my ($role_select);
2524: if ($context eq 'domain') {
2525: $role_select = &domain_roles_select();
1.140 raeburn 2526: $output = '<span class="LC_nobreak">'
1.70 bisitz 2527: .&mt('Role Type: [_1]',$role_select)
1.140 raeburn 2528: .'</span>';
1.53 raeburn 2529: } else {
1.140 raeburn 2530: $role_select = '<select name="showrole" onchange="javascript:updateCols('."'showrole'".');">'."\n".
1.53 raeburn 2531: '<option value="Any" '.$roleselected.'>'.
2532: &mt('Any role').'</option>';
1.101 raeburn 2533: my ($roletype,$crstype);
2534: if ($context eq 'course') {
2535: $crstype = &Apache::loncommon::course_type();
2536: if ($crstype eq 'Community') {
2537: $roletype = 'community';
2538: } else {
2539: $roletype = 'course';
2540: }
2541: }
2542: my @poss_roles = &curr_role_permissions($context,'','',$roletype);
1.53 raeburn 2543: foreach my $role (@poss_roles) {
2544: $roleselected = '';
2545: if ($role eq $env{'form.showrole'}) {
1.91 bisitz 2546: $roleselected = ' selected="selected"';
1.53 raeburn 2547: }
2548: my $plrole;
2549: if ($role eq 'cr') {
2550: $plrole = &mt('Custom role');
2551: } else {
1.101 raeburn 2552: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.53 raeburn 2553: }
2554: $role_select .= '<option value="'.$role.'"'.$roleselected.'>'.$plrole.'</option>';
2555: }
2556: $role_select .= '</select>';
1.140 raeburn 2557: $output = '<span class="LC_nobreak">'
1.70 bisitz 2558: .&mt('Role: [_1]',$role_select)
1.140 raeburn 2559: .'</span>';
1.53 raeburn 2560: }
2561: return $output;
2562: }
2563:
1.33 raeburn 2564: sub section_group_filter {
2565: my ($cnum,$cdom) = @_;
2566: my @filters;
2567: if ($env{'request.course.sec'} eq '') {
2568: @filters = ('sec');
2569: }
2570: push(@filters,'grp');
2571: my %name = (
2572: sec => 'secfilter',
2573: grp => 'grpfilter',
2574: );
2575: my %title = &Apache::lonlocal::texthash (
2576: sec => 'Section(s)',
2577: grp => 'Group(s)',
2578: all => 'all',
2579: none => 'none',
2580: );
1.47 raeburn 2581: my $output;
1.33 raeburn 2582: foreach my $item (@filters) {
1.47 raeburn 2583: my ($markup,@options);
1.33 raeburn 2584: if ($env{'form.'.$name{$item}} eq '') {
2585: $env{'form.'.$name{$item}} = 'all';
2586: }
2587: if ($item eq 'sec') {
1.103 raeburn 2588: if (($env{'form.showrole'} eq 'cc') || ($env{'form.showrole'} eq 'co')) {
1.33 raeburn 2589: $env{'form.'.$name{$item}} = 'none';
2590: }
2591: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
2592: @options = sort(keys(%sections_count));
2593: } elsif ($item eq 'grp') {
2594: my %curr_groups = &Apache::longroup::coursegroups();
2595: @options = sort(keys(%curr_groups));
2596: }
2597: if (@options > 0) {
2598: my $currsel;
1.112 bisitz 2599: $markup = '<select name="'.$name{$item}.'">'."\n";
1.33 raeburn 2600: foreach my $option ('all','none',@options) {
2601: $currsel = '';
2602: if ($env{'form.'.$name{$item}} eq $option) {
1.96 bisitz 2603: $currsel = ' selected="selected"';
1.33 raeburn 2604: }
2605: $markup .= ' <option value="'.$option.'"'.$currsel.'>';
2606: if (($option eq 'all') || ($option eq 'none')) {
2607: $markup .= $title{$option};
2608: } else {
2609: $markup .= $option;
2610: }
2611: $markup .= '</option>'."\n";
2612: }
2613: $markup .= '</select>'."\n";
1.111 bisitz 2614: $output .= (' 'x3).'<span class="LC_nobreak">'
2615: .'<label>'.$title{$item}.': '.$markup.'</label>'
2616: .'</span> ';
1.33 raeburn 2617: }
2618: }
2619: return $output;
2620: }
2621:
1.140 raeburn 2622: sub infocolumns {
1.150 raeburn 2623: my ($context,$mode,$showcredits) = @_;
1.140 raeburn 2624: my @cols;
2625: if (($mode eq 'pickauthor') || ($mode eq 'autoenroll')) {
1.150 raeburn 2626: @cols = &get_cols_array($context,$mode,$showcredits);
1.140 raeburn 2627: } else {
1.150 raeburn 2628: my @posscols = &get_cols_array($context,$mode,$showcredits);
1.140 raeburn 2629: if ($env{'form.phase'} ne '') {
2630: my @checkedcols = &Apache::loncommon::get_env_multiple('form.showcol');
2631: foreach my $col (@checkedcols) {
2632: if (grep(/^$col$/,@posscols)) {
2633: push(@cols,$col);
2634: }
2635: }
2636: } else {
2637: @cols = @posscols;
2638: }
2639: }
2640: return @cols;
2641: }
2642:
2643: sub get_cols_array {
1.150 raeburn 2644: my ($context,$mode,$showcredits) = @_;
1.140 raeburn 2645: my @cols;
2646: if ($mode eq 'pickauthor') {
2647: @cols = ('username','fullname','status','email');
2648: } else {
2649: @cols = ('username','domain','id','fullname');
2650: if ($context eq 'course') {
2651: push(@cols,'section');
2652: }
2653: push(@cols,('start','end','role'));
2654: unless (($mode eq 'autoenroll') && ($env{'form.Status'} ne 'Any')) {
2655: push(@cols,'status');
2656: }
2657: if ($context eq 'course') {
2658: push(@cols,'groups');
2659: }
2660: push(@cols,'email');
2661: if (($context eq 'course') && ($mode ne 'autoenroll')) {
1.150 raeburn 2662: if ($showcredits) {
2663: push(@cols,'credits');
2664: }
1.140 raeburn 2665: push(@cols,'lastlogin','clicker');
2666: }
2667: if (($context eq 'course') && ($mode ne 'autoenroll') &&
2668: ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
1.156 raeburn 2669: push(@cols,'photo');
1.140 raeburn 2670: }
1.149 raeburn 2671: if ($context eq 'domain') {
1.219 raeburn 2672: push(@cols,('authorusage','authorquota','extent'));
2673: }
2674: if ($context eq 'author') {
2675: push(@cols,'manager');
1.149 raeburn 2676: }
1.140 raeburn 2677: }
2678: return @cols;
2679: }
2680:
2681: sub column_checkboxes {
1.221 raeburn 2682: my ($context,$mode,$formname,$showcredits,$showstart,$showend) = @_;
1.150 raeburn 2683: my @cols = &get_cols_array($context,$mode,$showcredits);
1.140 raeburn 2684: my @showncols = &Apache::loncommon::get_env_multiple('form.showcol');
2685: my (%disabledchk,%unchecked);
2686: if ($env{'form.phase'} eq '') {
2687: $disabledchk{'status'} = 1;
2688: if ($context eq 'course') {
2689: $disabledchk{'role'} = 1;
2690: $unchecked{'photo'} = 1;
1.149 raeburn 2691: $unchecked{'clicker'} = 1;
1.150 raeburn 2692: if ($showcredits) {
2693: $unchecked{'credits'} = 1;
2694: }
1.221 raeburn 2695: my %curr_groups = &Apache::longroup::coursegroups();
2696: unless (keys(%curr_groups)) {
2697: $unchecked{'groups'} = 1;
2698: }
2699: } elsif ($context eq 'domain') {
1.149 raeburn 2700: $unchecked{'extent'} = 1;
1.140 raeburn 2701: }
1.221 raeburn 2702: if ($showstart) {
2703: $unchecked{'lastlogin'} = 1;
2704: } else {
2705: $unchecked{'start'} = 1;
2706: }
2707: unless ($showend) {
2708: $unchecked{'end'} = 1;
2709: }
1.140 raeburn 2710: } else {
2711: if ($env{'form.Status'} ne 'Any') {
2712: $disabledchk{'status'} = 1;
2713: }
1.146 raeburn 2714: if (($env{'form.showrole'} ne 'Any') && ($env{'form.showrole'} ne 'cr')) {
2715: $disabledchk{'role'} = 1;
1.140 raeburn 2716: }
1.149 raeburn 2717: if ($context eq 'domain') {
2718: if (($env{'form.roletype'} eq 'course') ||
2719: ($env{'form.roletype'} eq 'community')) {
2720: $disabledchk{'status'} = 1;
1.159 raeburn 2721: $disabledchk{'authorusage'} = 1;
2722: $disabledchk{'authorquota'} = 1;
1.149 raeburn 2723: } elsif ($env{'form.roletype'} eq 'domain') {
2724: $disabledchk{'extent'} = 1;
2725: }
1.219 raeburn 2726: } elsif ($context eq 'author') {
2727: if (($env{'form.Status'} eq 'Expired') ||
2728: ($env{'form.showrole'} eq 'aa')) {
2729: $disabledchk{'manager'} = 1;
2730: }
1.149 raeburn 2731: }
1.140 raeburn 2732: }
2733: my $numposs = scalar(@cols);
1.149 raeburn 2734: my $numinrow = 7;
1.140 raeburn 2735: my %lt = &get_column_names($context);
2736: my $output = '<fieldset><legend>'.&mt('Information to show').'</legend>'."\n".'<span class="LC_nobreak">'.
2737: '<input type="button" onclick="javascript:checkAll(document.'.$formname.'.showcol);" value="'.&mt('check all').'" />'.
2738: (' 'x3).
2739: '<input type="button" onclick="javascript:uncheckAll(document.'.$formname.'.showcol);" value="'.&mt('uncheck all').'" />'.
2740: '</span><table>';
2741:
2742: for (my $i=0; $i<$numposs; $i++) {
2743: my $rem = $i%($numinrow);
2744: if ($rem == 0) {
2745: if ($i > 0) {
2746: $output .= '</tr>';
2747: }
2748: $output .= '<tr>';
2749: }
2750: my $checked;
2751: if ($env{'form.phase'} eq '') {
2752: $checked = ' checked="checked"';
2753: if ($unchecked{$cols[$i]}) {
2754: $checked = '';
2755: }
2756: if ($disabledchk{$cols[$i]}) {
2757: $checked = ' disabled="disabled"';
2758: }
2759: } elsif (grep(/^\Q$cols[$i]\E$/,@showncols)) {
2760: $checked = ' checked="checked"';
2761: } elsif ($disabledchk{$cols[$i]}) {
2762: $checked = ' disabled="disabled"';
2763: }
2764: if ($i == $numposs-1) {
2765: my $colsleft = $numinrow-$rem;
2766: if ($colsleft > 1) {
2767: $output .= '<td colspan="'.$colsleft.'">';
2768: } else {
2769: $output .= '<td>';
2770: }
2771: } else {
2772: $output .= '<td>';
2773: }
1.149 raeburn 2774: my $style;
2775: if ($cols[$i] eq 'extent') {
2776: if (($env{'form.roletype'} eq 'domain') || ($env{'form.roletype'} eq '')) {
2777: $style = ' style="display: none;"';
2778: }
1.159 raeburn 2779: } elsif (($cols[$i] eq 'authorusage') || ($cols[$i] eq 'authorquota')) {
2780: if ($env{'form.roletype'} ne 'domain') {
2781: $style = ' style="display: none;"';
2782: }
2783: }
1.149 raeburn 2784: $output .= '<span id="show'.$cols[$i].'"'.$style.'><label>'.
2785: '<input id="showcol'.$cols[$i].'" type="checkbox" name="showcol" value="'.$cols[$i].'"'.$checked.' /><span id="showcoltext'.$cols[$i].'">'.
2786: $lt{$cols[$i]}.'</span>'.
2787: '</label></span></td>';
1.140 raeburn 2788: }
2789: $output .= '</tr></table></fieldset>';
2790: return $output;
2791: }
2792:
1.2 raeburn 2793: sub list_submit_button {
2794: my ($text) = @_;
1.11 raeburn 2795: return '<input type="button" name="updatedisplay" value="'.$text.'" onclick="javascript:display_update()" />';
1.2 raeburn 2796: }
2797:
1.140 raeburn 2798: sub get_column_names {
2799: my ($context) = @_;
2800: my %lt = &Apache::lonlocal::texthash(
2801: 'username' => "username",
2802: 'domain' => "domain",
2803: 'id' => 'ID',
2804: 'fullname' => "name",
2805: 'section' => "section",
2806: 'groups' => "active groups",
2807: 'start' => "start date",
2808: 'end' => "end date",
2809: 'status' => "status",
2810: 'role' => "role",
1.150 raeburn 2811: 'credits' => "credits",
1.140 raeburn 2812: 'type' => "enroll type/action",
2813: 'email' => "e-mail address",
2814: 'photo' => "photo",
2815: 'lastlogin' => "last login",
2816: 'extent' => "extent",
1.159 raeburn 2817: 'authorusage' => "disk usage (%)",
2818: 'authorquota' => "disk quota (MB)",
1.140 raeburn 2819: 'ca' => "check all",
2820: 'ua' => "uncheck all",
2821: 'clicker' => "clicker-ID",
1.219 raeburn 2822: 'manager' => "co-author manager",
1.140 raeburn 2823: );
2824: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
1.149 raeburn 2825: $lt{'extent'} = &mt('course(s): description, section(s), status');
1.140 raeburn 2826: } elsif ($context eq 'domain' && $env{'form.roletype'} eq 'community') {
1.154 raeburn 2827: $lt{'extent'} = &mt('community(s): description, section(s), status');
1.149 raeburn 2828: } elsif (($context eq 'author') ||
2829: ($context eq 'domain' && $env{'form.roletype'} eq 'author')) {
2830: $lt{'extent'} = &mt('author');
1.140 raeburn 2831: }
2832: return %lt;
2833: }
2834:
1.2 raeburn 2835: sub gather_userinfo {
1.11 raeburn 2836: my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_;
1.52 raeburn 2837: my $viewablesec;
2838: if ($context eq 'course') {
2839: $viewablesec = &viewable_section($permission);
2840: }
1.2 raeburn 2841: foreach my $item (keys(%{$rolehash})) {
2842: my %userdata;
1.22 raeburn 2843: if ($context eq 'author') {
1.2 raeburn 2844: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
2845: split(/:/,$item);
2846: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
1.222 raeburn 2847: next if (($userdata{'username'} eq '') && ($userdata{'domain'} eq ''));
1.24 raeburn 2848: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2849: $item,$userlist);
1.22 raeburn 2850: } elsif ($context eq 'course') {
2851: ($userdata{'username'},$userdata{'domain'},$userdata{'role'},
2852: $userdata{'section'}) = split(/:/,$item,-1);
2853: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
2854: if (($viewablesec ne '') && ($userdata{'section'} ne '')) {
2855: next if ($viewablesec ne $userdata{'section'});
2856: }
1.24 raeburn 2857: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2858: $item,$userlist);
1.2 raeburn 2859: } elsif ($context eq 'domain') {
2860: if ($env{'form.roletype'} eq 'domain') {
2861: ($userdata{'role'},$userdata{'username'},$userdata{'domain'}) =
2862: split(/:/,$item);
2863: ($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
1.24 raeburn 2864: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2865: $item,$userlist);
1.13 raeburn 2866: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 2867: if (ref($rolehash->{$item}) eq 'HASH') {
2868: $userdata{'extent'} = $item;
2869: foreach my $key (keys(%{$rolehash->{$item}})) {
2870: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) = split(/:/,$key);
2871: ($userdata{'start'},$userdata{'end'}) =
2872: split(/:/,$rolehash->{$item}{$key});
2873: my $uniqid = $key.':'.$item;
1.25 raeburn 2874: &build_user_record($context,\%userdata,$userinfo,
2875: $indexhash,$uniqid,$userlist);
1.2 raeburn 2876: }
2877: }
1.102 raeburn 2878: } elsif (($env{'form.roletype'} eq 'course') ||
2879: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 2880: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
2881: split(/:/,$item);
2882: if (ref($rolehash->{$item}) eq 'HASH') {
1.11 raeburn 2883: my $numcids = keys(%{$rolehash->{$item}});
1.2 raeburn 2884: foreach my $cid (sort(keys(%{$rolehash->{$item}}))) {
2885: if (ref($rolehash->{$item}{$cid}) eq 'HASH') {
2886: my $spanstart = '';
2887: my $spanend = '; ';
2888: my $space = ', ';
2889: if ($format eq 'html' || $format eq 'view') {
2890: $spanstart = '<span class="LC_nobreak">';
1.23 raeburn 2891: # FIXME: actions on courses disabled for now
2892: # if ($permission->{'cusr'}) {
2893: # if ($numcids > 1) {
1.25 raeburn 2894: # $spanstart .= '<input type="radio" name="'.$item.'" value="'.$cid.'" /> ';
1.23 raeburn 2895: # } else {
1.25 raeburn 2896: # $spanstart .= '<input type="hidden" name="'.$item.'" value="'.$cid.'" /> ';
1.23 raeburn 2897: # }
2898: # }
1.2 raeburn 2899: $spanend = '</span><br />';
2900: $space = ', ';
2901: }
2902: $userdata{'extent'} .= $spanstart.
2903: $rolehash->{$item}{$cid}{'desc'}.$space;
2904: if (ref($rolehash->{$item}{$cid}{'secs'}) eq 'HASH') {
2905: foreach my $sec (sort(keys(%{$rolehash->{$item}{$cid}{'secs'}}))) {
1.25 raeburn 2906: if (($env{'form.Status'} eq 'Any') ||
2907: ($env{'form.Status'} eq $rolehash->{$item}{$cid}{'secs'}{$sec})) {
2908: $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
2909: $userdata{'status'} = $rolehash->{$item}{$cid}{'secs'}{$sec};
2910: }
1.2 raeburn 2911: }
2912: }
2913: }
2914: }
2915: }
1.25 raeburn 2916: if ($userdata{'status'} ne '') {
2917: &build_user_record($context,\%userdata,$userinfo,
2918: $indexhash,$item,$userlist);
2919: }
1.2 raeburn 2920: }
2921: }
2922: }
2923: return;
2924: }
2925:
2926: sub build_user_record {
1.24 raeburn 2927: my ($context,$userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
1.11 raeburn 2928: next if ($userdata->{'start'} eq '-1' && $userdata->{'end'} eq '-1');
1.102 raeburn 2929: if (!(($context eq 'domain') && (($env{'form.roletype'} eq 'course')
2930: && ($env{'form.roletype'} eq 'community')))) {
1.24 raeburn 2931: &process_date_info($userdata);
2932: }
1.2 raeburn 2933: my $username = $userdata->{'username'};
2934: my $domain = $userdata->{'domain'};
2935: if (ref($userinfo->{$username.':'.$domain}) eq 'HASH') {
1.24 raeburn 2936: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
1.2 raeburn 2937: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
2938: } else {
2939: &aggregate_user_info($domain,$username,$userinfo);
2940: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
2941: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
2942: }
2943: foreach my $key (keys(%{$indexhash})) {
2944: if (defined($userdata->{$key})) {
2945: $userlist->{$record_key}[$indexhash->{$key}] = $userdata->{$key};
2946: }
2947: }
2948: return;
2949: }
2950:
2951: sub courses_selector {
2952: my ($cdom,$formname) = @_;
2953: my %codes = ();
2954: my @codetitles = ();
2955: my %cat_titles = ();
2956: my %cat_order = ();
2957: my %idlist = ();
2958: my %idnums = ();
2959: my %idlist_titles = ();
2960: my $caller = 'global';
2961: my $format_reply;
2962: my $jscript = '';
2963:
1.7 albertel 2964: my $totcodes = 0;
1.201 raeburn 2965: my $instcats = &Apache::lonnet::get_dom_instcats($cdom);
2966: if (ref($instcats) eq 'HASH') {
2967: if ((ref($instcats->{'codetitles'}) eq 'ARRAY') && (ref($instcats->{'codes'}) eq 'HASH') &&
2968: (ref($instcats->{'cat_titles'}) eq 'HASH') && (ref($instcats->{'cat_order'}) eq 'HASH')) {
2969: %codes = %{$instcats->{'codes'}};
2970: @codetitles = @{$instcats->{'codetitles'}};
2971: %cat_titles = %{$instcats->{'cat_titles'}};
2972: %cat_order = %{$instcats->{'cat_order'}};
2973: $totcodes = scalar(keys(%codes));
1.2 raeburn 2974: my $numtypes = @codetitles;
2975: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
2976: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
2977: my $longtitles_str = join('","',@{$longtitles});
2978: my $allidlist = $idlist{$codetitles[0]};
2979: $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
2980: $jscript .= $scripttext;
1.181 raeburn 2981: $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,\@codetitles);
1.2 raeburn 2982: }
2983: }
2984: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
2985:
2986: my %elements = (
2987: Year => 'selectbox',
2988: coursepick => 'radio',
2989: coursetotal => 'text',
2990: courselist => 'text',
2991: );
2992: $jscript .= &Apache::lonhtmlcommon::set_form_elements(\%elements);
2993: if ($env{'form.coursepick'} eq 'category') {
2994: $jscript .= qq|
2995: function setCourseCat(formname) {
2996: if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
2997: return;
2998: }
1.120 raeburn 2999: courseSet('$codetitles[0]');
1.2 raeburn 3000: for (var j=0; j<formname.Semester.length; j++) {
3001: if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
3002: formname.Semester.options[j].selected = true;
3003: }
3004: }
3005: if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
3006: return;
3007: }
1.120 raeburn 3008: courseSet('$codetitles[1]');
1.2 raeburn 3009: for (var j=0; j<formname.Department.length; j++) {
1.187 raeburn 3010: if (formname.Department.options[j].value == "$env{'form.Department'}") {
3011: formname.Department.options[j].selected = true;
1.2 raeburn 3012: }
3013: }
3014: if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
3015: return;
3016: }
1.120 raeburn 3017: courseSet('$codetitles[2]');
1.2 raeburn 3018: for (var j=0; j<formname.Number.length; j++) {
3019: if (formname.Number.options[j].value == "$env{'form.Number'}") {
3020: formname.Number.options[j].selected = true;
3021: }
3022: }
3023: }
3024: |;
3025: }
3026: return ($cb_jscript,$jscript,$totcodes,\@codetitles,\%idlist,
3027: \%idlist_titles);
3028: }
3029:
3030: sub course_selector_loadcode {
3031: my ($formname) = @_;
3032: my $loadcode;
3033: if ($env{'form.coursepick'} ne '') {
3034: $loadcode = 'javascript:setFormElements(document.'.$formname.')';
3035: if ($env{'form.coursepick'} eq 'category') {
3036: $loadcode .= ';javascript:setCourseCat(document.'.$formname.')';
3037: }
3038: }
3039: return $loadcode;
3040: }
3041:
3042: sub process_coursepick {
3043: my $coursefilter = $env{'form.coursepick'};
3044: my $cdom = $env{'request.role.domain'};
3045: my %courses;
1.105 raeburn 3046: my $crssrch = 'Course';
3047: if ($env{'form.roletype'} eq 'community') {
3048: $crssrch = 'Community';
3049: }
1.2 raeburn 3050: if ($coursefilter eq 'all') {
3051: %courses = &Apache::lonnet::courseiddump($cdom,'.','.','.','.','.',
1.105 raeburn 3052: undef,undef,$crssrch);
1.2 raeburn 3053: } elsif ($coursefilter eq 'category') {
3054: my $instcode = &instcode_from_coursefilter();
3055: %courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.',
1.105 raeburn 3056: undef,undef,$crssrch);
1.2 raeburn 3057: } elsif ($coursefilter eq 'specific') {
3058: if ($env{'form.coursetotal'} > 1) {
3059: my @course_ids = split(/&&/,$env{'form.courselist'});
3060: foreach my $cid (@course_ids) {
3061: $courses{$cid} = '';
1.1 raeburn 3062: }
1.2 raeburn 3063: } else {
3064: $courses{$env{'form.courselist'}} = '';
1.1 raeburn 3065: }
1.2 raeburn 3066: }
3067: return %courses;
3068: }
3069:
3070: sub instcode_from_coursefilter {
3071: my $instcode = '';
3072: my @cats = ('Semester','Year','Department','Number');
3073: foreach my $category (@cats) {
3074: if (defined($env{'form.'.$category})) {
3075: unless ($env{'form.'.$category} eq '-1') {
3076: $instcode .= $env{'form.'.$category};
3077: }
3078: }
3079: }
3080: if ($instcode eq '') {
3081: $instcode = '.';
3082: }
3083: return $instcode;
3084: }
3085:
3086: sub make_keylist_array {
3087: my ($index,$keylist);
3088: $index->{'domain'} = &Apache::loncoursedata::CL_SDOM();
3089: $index->{'username'} = &Apache::loncoursedata::CL_SNAME();
3090: $index->{'end'} = &Apache::loncoursedata::CL_END();
3091: $index->{'start'} = &Apache::loncoursedata::CL_START();
3092: $index->{'id'} = &Apache::loncoursedata::CL_ID();
3093: $index->{'section'} = &Apache::loncoursedata::CL_SECTION();
3094: $index->{'fullname'} = &Apache::loncoursedata::CL_FULLNAME();
3095: $index->{'status'} = &Apache::loncoursedata::CL_STATUS();
3096: $index->{'type'} = &Apache::loncoursedata::CL_TYPE();
3097: $index->{'lockedtype'} = &Apache::loncoursedata::CL_LOCKEDTYPE();
3098: $index->{'groups'} = &Apache::loncoursedata::CL_GROUP();
3099: $index->{'email'} = &Apache::loncoursedata::CL_PERMANENTEMAIL();
3100: $index->{'role'} = &Apache::loncoursedata::CL_ROLE();
3101: $index->{'extent'} = &Apache::loncoursedata::CL_EXTENT();
1.44 raeburn 3102: $index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
1.47 raeburn 3103: $index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();
1.150 raeburn 3104: $index->{'credits'} = &Apache::loncoursedata::CL_CREDITS();
1.174 raeburn 3105: $index->{'instsec'} = &Apache::loncoursedata::CL_INSTSEC();
1.159 raeburn 3106: $index->{'authorquota'} = &Apache::loncoursedata::CL_AUTHORQUOTA();
3107: $index->{'authorusage'} = &Apache::loncoursedata::CL_AUTHORUSAGE();
1.219 raeburn 3108: $index->{'manager'} = &Apache::loncoursedata::CL_CAMANAGER();
1.2 raeburn 3109: foreach my $key (keys(%{$index})) {
3110: $keylist->[$index->{$key}] = $key;
3111: }
3112: return ($index,$keylist);
3113: }
3114:
3115: sub aggregate_user_info {
3116: my ($udom,$uname,$userinfo) = @_;
3117: my %info=&Apache::lonnet::get('environment',
3118: ['firstname','middlename',
3119: 'lastname','generation','id'],
3120: $udom,$uname);
3121: my ($tmp) = keys(%info);
3122: my ($fullname,$id);
3123: if ($tmp =~/^(con_lost|error|no_such_host)/i) {
3124: $fullname = 'not available';
3125: $id = 'not available';
3126: &Apache::lonnet::logthis('unable to retrieve environment '.
3127: 'for '.$uname.':'.$udom);
1.1 raeburn 3128: } else {
1.2 raeburn 3129: $fullname = &Apache::lonnet::format_name(@info{qw/firstname middlename lastname generation/},'lastname');
3130: $id = $info{'id'};
3131: }
3132: $userinfo->{$uname.':'.$udom} = {
3133: fullname => $fullname,
3134: id => $id,
3135: };
3136: return;
3137: }
1.1 raeburn 3138:
1.2 raeburn 3139: sub process_date_info {
3140: my ($userdata) = @_;
3141: my $now = time;
1.83 raeburn 3142: $userdata->{'status'} = 'Active';
1.2 raeburn 3143: if ($userdata->{'start'} > 0) {
3144: if ($now < $userdata->{'start'}) {
1.83 raeburn 3145: $userdata->{'status'} = 'Future';
1.2 raeburn 3146: }
1.1 raeburn 3147: }
1.2 raeburn 3148: if ($userdata->{'end'} > 0) {
3149: if ($now > $userdata->{'end'}) {
1.83 raeburn 3150: $userdata->{'status'} = 'Expired';
1.2 raeburn 3151: }
3152: }
3153: return;
1.1 raeburn 3154: }
3155:
3156: sub show_users_list {
1.150 raeburn 3157: my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname,
1.159 raeburn 3158: $showcredits,$needauthorquota,$needauthorusage)=@_;
1.55 raeburn 3159: if ($formname eq '') {
3160: $formname = 'studentform';
3161: }
1.159 raeburn 3162: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1 raeburn 3163: #
3164: # Variables for excel output
3165: my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
3166: #
3167: # Variables for csv output
3168: my ($CSVfile,$CSVfilename);
3169: #
3170: my $sortby = $env{'form.sortby'};
1.3 raeburn 3171: my @sortable = ('username','domain','id','fullname','start','end','email','role');
1.2 raeburn 3172: if ($context eq 'course') {
1.3 raeburn 3173: push(@sortable,('section','groups','type'));
1.150 raeburn 3174: if ($showcredits) {
3175: push(@sortable,'credits');
3176: }
1.2 raeburn 3177: } else {
1.3 raeburn 3178: push(@sortable,'extent');
1.159 raeburn 3179: if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
3180: (($env{'form.showrole'} eq 'Any') || ($env{'form.showrole'} eq 'au'))) {
3181: push(@sortable,('authorusage','authorquota'));
3182: }
1.219 raeburn 3183: if ($context eq 'author') {
3184: push(@sortable,'manager');
3185: }
1.3 raeburn 3186: }
1.55 raeburn 3187: if ($mode eq 'pickauthor') {
3188: @sortable = ('username','fullname','email','status');
3189: }
1.156 raeburn 3190: my %is_sortable;
1.158 raeburn 3191: map { $is_sortable{$_} = 1; } @sortable;
1.156 raeburn 3192: unless ($is_sortable{$sortby}) {
1.3 raeburn 3193: $sortby = 'username';
1.1 raeburn 3194: }
1.22 raeburn 3195: my $setting = $env{'form.roletype'};
1.150 raeburn 3196: my ($cid,$cdom,$cnum,$classgroups,$crstype,$defaultcredits);
1.1 raeburn 3197: if ($context eq 'course') {
1.22 raeburn 3198: $cid = $env{'request.course.id'};
1.101 raeburn 3199: $crstype = &Apache::loncommon::course_type();
1.17 raeburn 3200: ($cnum,$cdom) = &get_course_identity($cid);
1.150 raeburn 3201: $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
1.2 raeburn 3202: ($classgroups) = &Apache::loncoursedata::get_group_memberships(
3203: $userlist,$keylist,$cdom,$cnum);
1.16 raeburn 3204: if ($mode eq 'autoenroll') {
3205: $env{'form.showrole'} = 'st';
3206: } else {
3207: if ($env{'course.'.$cid.'.internal.showphoto'}) {
3208: $r->print('
1.1 raeburn 3209: <script type="text/javascript">
1.96 bisitz 3210: // <![CDATA[
1.1 raeburn 3211: function photowindow(photolink) {
3212: var title = "Photo_Viewer";
3213: var options = "scrollbars=1,resizable=1,menubar=0";
3214: options += ",width=240,height=240";
3215: stdeditbrowser = open(photolink,title,options,"1");
3216: stdeditbrowser.focus();
3217: }
1.96 bisitz 3218: // ]]>
1.1 raeburn 3219: </script>
1.16 raeburn 3220: ');
3221: }
3222: }
1.102 raeburn 3223: } elsif ($context eq 'domain') {
3224: if ($setting eq 'community') {
3225: $crstype = 'Community';
1.105 raeburn 3226: } elsif ($setting eq 'course') {
1.102 raeburn 3227: $crstype = 'Course';
3228: }
1.1 raeburn 3229: }
1.55 raeburn 3230: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
1.40 raeburn 3231: my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
1.56 raeburn 3232: my $verify_action_js = &bulkaction_javascript($formname);
1.1 raeburn 3233: $r->print(<<END);
1.10 raeburn 3234:
3235: <script type="text/javascript" language="Javascript">
1.96 bisitz 3236: // <![CDATA[
1.11 raeburn 3237:
1.56 raeburn 3238: $verify_action_js
1.10 raeburn 3239:
3240: function username_display_launch(username,domain) {
3241: var target;
1.177 raeburn 3242: if (!document.$formname.usernamelink.length) {
3243: target = document.$formname.usernamelink.value;
3244: } else {
3245: for (var i=0; i<document.$formname.usernamelink.length; i++) {
3246: if (document.$formname.usernamelink[i].checked) {
3247: target = document.$formname.usernamelink[i].value;
3248: }
1.10 raeburn 3249: }
3250: }
1.179 raeburn 3251: if ((target == 'modify') || (target == 'activity')) {
3252: var nextaction = 'singleuser';
3253: if (target == 'activity') {
3254: nextaction = 'accesslogs';
3255: }
1.55 raeburn 3256: if (document.$formname.userwin.checked == true) {
1.179 raeburn 3257: var url = '/adm/createuser?srchterm='+username+'&srchdomain='+domain+'&phase=get_user_info&srchin=dom&srchby=uname&srchtype=exact&popup=1&action='+nextaction;
1.50 raeburn 3258: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3259: modifywin = window.open(url,'',options,1);
3260: modifywin.focus();
3261: return;
3262: } else {
1.55 raeburn 3263: document.$formname.srchterm.value=username;
3264: document.$formname.srchdomain.value=domain;
3265: document.$formname.phase.value='get_user_info';
1.179 raeburn 3266: document.$formname.action.value = nextaction;
1.55 raeburn 3267: document.$formname.submit();
1.50 raeburn 3268: }
1.10 raeburn 3269: }
1.48 raeburn 3270: if (target == 'aboutme') {
1.55 raeburn 3271: if (document.$formname.userwin.checked == true) {
1.50 raeburn 3272: var url = '/adm/'+domain+'/'+username+'/aboutme?popup=1';
3273: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3274: aboutmewin = window.open(url,'',options,1);
3275: aboutmewin.focus();
3276: return;
3277: } else {
3278: document.location.href = '/adm/'+domain+'/'+username+'/aboutme';
3279: }
1.48 raeburn 3280: }
1.98 raeburn 3281: if (target == 'track') {
3282: if (document.$formname.userwin.checked == true) {
3283: var url = '/adm/trackstudent?selected_student='+username+':'+domain+'&only_body=1';
3284: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
3285: var trackwin = window.open(url,'',options,1);
3286: trackwin.focus();
3287: return;
3288: } else {
3289: document.location.href = '/adm/trackstudent?selected_student='+username+':'+domain;
3290: }
3291: }
1.10 raeburn 3292: }
1.96 bisitz 3293: // ]]>
1.10 raeburn 3294: </script>
1.11 raeburn 3295: $date_sec_selector
1.1 raeburn 3296: <input type="hidden" name="state" value="$env{'form.state'}" />
3297: END
3298: }
3299: $r->print(<<END);
3300: <input type="hidden" name="sortby" value="$sortby" />
3301: END
1.150 raeburn 3302: my @cols = &infocolumns($context,$mode,$showcredits);
1.140 raeburn 3303: my %coltxt = &get_column_names($context);
3304: my %acttxt = &Apache::lonlocal::texthash(
1.11 raeburn 3305: 'pr' => "Proceed",
3306: 'ac' => "Action to take for selected users",
1.56 raeburn 3307: 'link' => "Behavior of clickable username link for each user",
1.82 weissno 3308: 'aboutme' => "Display a user's personal information page",
1.50 raeburn 3309: 'owin' => "Open in a new window",
1.10 raeburn 3310: 'modify' => "Modify a user's information",
1.98 raeburn 3311: 'track' => "View a user's recent activity",
1.179 raeburn 3312: 'activity' => "View a user's access log",
1.1 raeburn 3313: );
1.140 raeburn 3314: my %lt = (%coltxt,%acttxt);
1.4 raeburn 3315: my $rolefilter = $env{'form.showrole'};
1.5 raeburn 3316: if ($env{'form.showrole'} eq 'cr') {
3317: $rolefilter = &mt('custom');
3318: } elsif ($env{'form.showrole'} ne 'Any') {
1.101 raeburn 3319: $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'},$crstype);
1.2 raeburn 3320: }
1.16 raeburn 3321: my $results_description;
3322: if ($mode ne 'autoenroll') {
3323: $results_description = &results_header_row($rolefilter,$statusmode,
1.102 raeburn 3324: $context,$permission,$mode,$crstype);
1.140 raeburn 3325: $r->print('<b>'.$results_description.'</b><br clear="all" />');
1.16 raeburn 3326: }
1.26 raeburn 3327: my ($output,$actionselect,%canchange,%canchangesec);
1.55 raeburn 3328: if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
3329: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
1.16 raeburn 3330: if ($permission->{'cusr'}) {
1.105 raeburn 3331: unless (($context eq 'domain') &&
3332: (($setting eq 'course') || ($setting eq 'community'))) {
3333: $actionselect =
3334: &select_actions($context,$setting,$statusmode,$formname);
3335: }
1.16 raeburn 3336: }
3337: $r->print(<<END);
1.10 raeburn 3338: <input type="hidden" name="srchby" value="uname" />
3339: <input type="hidden" name="srchin" value="dom" />
3340: <input type="hidden" name="srchtype" value="exact" />
3341: <input type="hidden" name="srchterm" value="" />
1.11 raeburn 3342: <input type="hidden" name="srchdomain" value="" />
1.1 raeburn 3343: END
1.16 raeburn 3344: if ($actionselect) {
1.41 raeburn 3345: $output .= <<"END";
1.94 bisitz 3346: <div class="LC_left_float"><fieldset><legend>$lt{'ac'}</legend>
1.56 raeburn 3347: $actionselect
3348: <br/><br /><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.$formname.actionlist)" />
3349: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.$formname.actionlist)" /><br /><input type="button" value="$lt{'pr'}" onclick="javascript:verify_action('actionlist')" /></fieldset></div>
1.11 raeburn 3350: END
1.26 raeburn 3351: my @allroles;
3352: if ($env{'form.showrole'} eq 'Any') {
3353: my $custom = 1;
3354: if ($context eq 'domain') {
1.101 raeburn 3355: @allroles = &roles_by_context($setting,$custom,$crstype);
1.26 raeburn 3356: } else {
1.101 raeburn 3357: @allroles = &roles_by_context($context,$custom,$crstype);
1.26 raeburn 3358: }
3359: } else {
3360: @allroles = ($env{'form.showrole'});
3361: }
3362: foreach my $role (@allroles) {
3363: if ($context eq 'domain') {
3364: if ($setting eq 'domain') {
3365: if (&Apache::lonnet::allowed('c'.$role,
3366: $env{'request.role.domain'})) {
3367: $canchange{$role} = 1;
3368: }
1.31 raeburn 3369: } elsif ($setting eq 'author') {
3370: if (&Apache::lonnet::allowed('c'.$role,
3371: $env{'request.role.domain'})) {
3372: $canchange{$role} = 1;
3373: }
1.26 raeburn 3374: }
3375: } elsif ($context eq 'author') {
3376: if (&Apache::lonnet::allowed('c'.$role,
3377: $env{'user.domain'}.'/'.$env{'user.name'})) {
3378: $canchange{$role} = 1;
3379: }
3380: } elsif ($context eq 'course') {
3381: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
3382: $canchange{$role} = 1;
3383: } elsif ($env{'request.course.sec'} ne '') {
3384: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
3385: $canchangesec{$role} = $env{'request.course.sec'};
3386: }
1.141 raeburn 3387: } elsif ((($role eq 'co') && ($crstype eq 'Community')) ||
3388: (($role eq 'cc') && ($crstype eq 'Course'))) {
3389: if (&is_courseowner($env{'request.course.id'},
3390: $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
3391: $canchange{$role} = 1;
3392: }
1.26 raeburn 3393: }
3394: }
3395: }
1.16 raeburn 3396: }
1.94 bisitz 3397: $output .= '<div class="LC_left_float"><fieldset><legend>'.$lt{'link'}.'</legend>'.
1.56 raeburn 3398: '<table><tr>';
3399: my @linkdests = ('aboutme');
3400: if ($permission->{'cusr'}) {
3401: unshift (@linkdests,'modify');
3402: }
1.179 raeburn 3403: if ($context eq 'course') {
3404: if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) ||
3405: &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.
3406: $env{'request.course.sec'})) {
3407: push(@linkdests,'track');
3408: }
3409: } elsif ($context eq 'domain') {
3410: if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
3411: push(@linkdests,'activity');
3412: }
1.98 raeburn 3413: }
1.56 raeburn 3414: $output .= '<td>';
3415: my $usernamelink = $env{'form.usernamelink'};
3416: if ($usernamelink eq '') {
3417: $usernamelink = 'aboutme';
3418: }
3419: foreach my $item (@linkdests) {
3420: my $checkedstr = '';
3421: if ($item eq $usernamelink) {
1.86 bisitz 3422: $checkedstr = ' checked="checked"';
1.56 raeburn 3423: }
1.86 bisitz 3424: $output .= '<span class="LC_nobreak"><label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.' /> '.$lt{$item}.'</label></span><br />';
1.56 raeburn 3425: }
3426: my $checkwin;
3427: if ($env{'form.userwin'}) {
1.86 bisitz 3428: $checkwin = ' checked="checked"';
1.56 raeburn 3429: }
1.144 bisitz 3430: $output .=
3431: '</td><td valign="top" style="border-left: 1px solid;">'
3432: .'<span class="LC_nobreak"><label>'
3433: .'<input type="checkbox" name="userwin" value="1"'.$checkwin.' />'.$lt{'owin'}
3434: .'</label></span></td></tr></table></fieldset></div>';
1.4 raeburn 3435: }
1.184 raeburn 3436: $output .= "\n".'<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
1.1 raeburn 3437: &Apache::loncommon::start_data_table().
1.4 raeburn 3438: &Apache::loncommon::start_data_table_header_row();
1.1 raeburn 3439: if ($mode eq 'autoenroll') {
1.4 raeburn 3440: $output .= "
1.55 raeburn 3441: <th><a href=\"javascript:document.$formname.sortby.value='type';document.$formname.submit();\">$lt{'type'}</a></th>
1.4 raeburn 3442: ";
1.1 raeburn 3443: } else {
1.105 raeburn 3444: $output .= "\n".'<th> </th>'."\n";
1.11 raeburn 3445: if ($actionselect) {
1.159 raeburn 3446: $output .= '<th class="LC_nobreak" valign="top">'.&mt('Select').'</th>'."\n";
1.11 raeburn 3447: }
1.1 raeburn 3448: }
3449: foreach my $item (@cols) {
1.159 raeburn 3450: $output .= '<th class="LC_nobreak" valign="top">';
1.156 raeburn 3451: if ($is_sortable{$item}) {
1.159 raeburn 3452: $output .= "<a href=\"javascript:document.$formname.sortby.value='$item';document.$formname.submit();\" style=\"text-decoration:none;\">$lt{$item}<span class=\"LC_fontsize_small\"> ▼</span></a>";
1.156 raeburn 3453: } else {
3454: $output .= $lt{$item};
3455: }
3456: $output .= "</th>\n";
1.1 raeburn 3457: }
1.2 raeburn 3458: my %role_types = &role_type_names();
1.16 raeburn 3459: $output .= &Apache::loncommon::end_data_table_header_row();
1.1 raeburn 3460: # Done with the HTML header line
3461: } elsif ($mode eq 'csv') {
3462: #
3463: # Open a file
3464: $CSVfilename = '/prtspool/'.
1.2 raeburn 3465: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
3466: time.'_'.rand(1000000000).'.csv';
1.1 raeburn 3467: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
3468: $r->log_error("Couldn't open $CSVfilename for output $!");
1.108 bisitz 3469: $r->print(
3470: '<p class="LC_error">'
3471: .&mt('Problems occurred in writing the CSV file.')
3472: .' '.&mt('This error has been logged.')
3473: .' '.&mt('Please alert your LON-CAPA administrator.')
3474: .'</p>'
3475: );
1.1 raeburn 3476: $CSVfile = undef;
3477: }
3478: #
3479: # Write headers and data to file
1.2 raeburn 3480: print $CSVfile '"'.$results_description.'"'."\n";
1.1 raeburn 3481: print $CSVfile '"'.join('","',map {
3482: &Apache::loncommon::csv_translate($lt{$_})
1.67 droeschl 3483: } (@cols))."\"\n";
1.1 raeburn 3484: } elsif ($mode eq 'excel') {
3485: # Create the excel spreadsheet
3486: ($excel_workbook,$excel_filename,$format) =
3487: &Apache::loncommon::create_workbook($r);
3488: return if (! defined($excel_workbook));
3489: $excel_sheet = $excel_workbook->addworksheet('userlist');
1.2 raeburn 3490: $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
1.1 raeburn 3491: #
3492: my @colnames = map {$lt{$_}} (@cols);
1.67 droeschl 3493:
1.1 raeburn 3494: $excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
3495: }
3496:
3497: # Done with header lines in all formats
3498: my %index;
3499: my $i;
1.2 raeburn 3500: foreach my $idx (@$keylist) {
3501: $index{$idx} = $i++;
3502: }
1.219 raeburn 3503: my $now = time;
1.4 raeburn 3504: my $usercount = 0;
1.33 raeburn 3505: my ($secfilter,$grpfilter);
3506: if ($context eq 'course') {
3507: $secfilter = $env{'form.secfilter'};
3508: $grpfilter = $env{'form.grpfilter'};
3509: if ($secfilter eq '') {
3510: $secfilter = 'all';
3511: }
3512: if ($grpfilter eq '') {
3513: $grpfilter = 'all';
3514: }
3515: }
1.83 raeburn 3516: my %ltstatus = &Apache::lonlocal::texthash(
3517: Active => 'Active',
3518: Future => 'Future',
3519: Expired => 'Expired',
3520: );
1.225 ! raeburn 3521: my (%crslogins,%camanagers,%othdoms);
1.139 raeburn 3522: if ($context eq 'course') {
1.219 raeburn 3523: # If this is for a single course get last course "log-in".
1.139 raeburn 3524: %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$cnum);
1.219 raeburn 3525: } elsif ($context eq 'author') {
1.222 raeburn 3526: my $authormanagers;
3527: if ($env{'request.role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)$}) {
3528: my %envhash = &Apache::lonnet::userenvironment($1,$2,'authormanagers');
3529: $authormanagers = $envhash{'authormanagers'};
3530: } else {
3531: $authormanagers = $env{'environment.authormanagers'};
3532: }
3533: if ($authormanagers ne '') {
3534: map { $camanagers{$_.':ca'} = 1; } split(/,/,$authormanagers);
3535: }
1.139 raeburn 3536: }
1.2 raeburn 3537: # Get groups, role, permanent e-mail so we can sort on them if
3538: # necessary.
1.225 ! raeburn 3539: # Compare user's domain with $env{'request.role.dom'}, and if
! 3540: # different add to the domains for which to retrieve data on
! 3541: # viewable user information, by institutional status, for users
! 3542: # from "other" domains.
1.2 raeburn 3543: foreach my $user (keys(%{$userlist})) {
1.43 raeburn 3544: if ($user eq '' ) {
3545: delete($userlist->{$user});
3546: next;
3547: }
1.11 raeburn 3548: if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) {
3549: delete($userlist->{$user});
3550: next;
3551: }
1.2 raeburn 3552: my ($uname,$udom,$role,$groups,$email);
1.5 raeburn 3553: if (($statusmode ne 'Any') &&
3554: ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
3555: delete($userlist->{$user});
3556: next;
3557: }
1.2 raeburn 3558: if ($context eq 'domain') {
3559: if ($env{'form.roletype'} eq 'domain') {
3560: ($role,$uname,$udom) = split(/:/,$user);
1.11 raeburn 3561: if (($uname eq $env{'request.role.domain'}.'-domainconfig') &&
3562: ($udom eq $env{'request.role.domain'})) {
3563: delete($userlist->{$user});
3564: next;
3565: }
1.13 raeburn 3566: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 3567: ($uname,$udom,$role) = split(/:/,$user,-1);
1.102 raeburn 3568: } elsif (($env{'form.roletype'} eq 'course') ||
3569: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 3570: ($uname,$udom,$role) = split(/:/,$user);
3571: }
3572: } else {
3573: ($uname,$udom,$role) = split(/:/,$user,-1);
3574: if (($context eq 'course') && $role eq '') {
3575: $role = 'st';
3576: }
3577: }
3578: $userlist->{$user}->[$index{'role'}] = $role;
3579: if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
3580: delete($userlist->{$user});
3581: next;
3582: }
1.33 raeburn 3583: if ($context eq 'course') {
3584: my @ac_groups;
3585: if (ref($classgroups) eq 'HASH') {
3586: $groups = $classgroups->{$user};
3587: }
3588: if (ref($groups->{'active'}) eq 'HASH') {
3589: @ac_groups = keys(%{$groups->{'active'}});
3590: $userlist->{$user}->[$index{'groups'}] = join(', ',@ac_groups);
3591: }
3592: if ($mode ne 'autoenroll') {
3593: my $section = $userlist->{$user}->[$index{'section'}];
1.43 raeburn 3594: if (($env{'request.course.sec'} ne '') &&
3595: ($section ne $env{'request.course.sec'})) {
3596: if ($role eq 'st') {
3597: delete($userlist->{$user});
3598: next;
3599: }
3600: }
1.33 raeburn 3601: if ($secfilter eq 'none') {
3602: if ($section ne '') {
3603: delete($userlist->{$user});
3604: next;
3605: }
3606: } elsif ($secfilter ne 'all') {
3607: if ($section ne $secfilter) {
3608: delete($userlist->{$user});
3609: next;
3610: }
3611: }
3612: if ($grpfilter eq 'none') {
3613: if (@ac_groups > 0) {
3614: delete($userlist->{$user});
3615: next;
3616: }
3617: } elsif ($grpfilter ne 'all') {
3618: if (!grep(/^\Q$grpfilter\E$/,@ac_groups)) {
3619: delete($userlist->{$user});
3620: next;
3621: }
3622: }
1.44 raeburn 3623: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
1.140 raeburn 3624: if ((grep/^photo$/,@cols) && ($role eq 'st')) {
1.44 raeburn 3625: $userlist->{$user}->[$index{'photo'}] =
1.47 raeburn 3626: &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg');
3627: $userlist->{$user}->[$index{'thumbnail'}] =
1.44 raeburn 3628: &Apache::lonnet::retrievestudentphoto($udom,$uname,
3629: 'gif','thumbnail');
3630: }
3631: }
1.150 raeburn 3632: if (($role eq 'st') && ($defaultcredits)) {
3633: if ($userlist->{$user}->[$index{'credits'}] eq '') {
3634: $userlist->{$user}->[$index{'credits'}] = $defaultcredits;
3635: }
3636: }
1.33 raeburn 3637: }
1.2 raeburn 3638: }
1.219 raeburn 3639: if ($context eq 'author') {
3640: if (($camanagers{$user}) &&
3641: ((!defined($userlist->{$user}->[$index{'end'}])) ||
3642: ($userlist->{$user}->[$index{'end'}] == 0) ||
3643: ($userlist->{$user}->[$index{'end'}] > $now))) {
3644: $userlist->{$user}->[$index{'manager'}] = &mt('Yes');
3645: } else {
3646: $userlist->{$user}->[$index{'manager'}] = &mt('No');
3647: }
3648: }
1.2 raeburn 3649: my %emails = &Apache::loncommon::getemails($uname,$udom);
3650: if ($emails{'permanentemail'} =~ /\S/) {
3651: $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
3652: }
1.159 raeburn 3653: if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
3654: ($role eq 'au')) {
3655: my ($disk_quota,$current_disk_usage,$percent);
3656: if (($needauthorusage) || ($needauthorquota)) {
3657: $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author');
3658: }
3659: if ($needauthorusage) {
3660: $current_disk_usage =
3661: &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname");
3662: if ($disk_quota == 0) {
3663: $percent = 100.0;
3664: } else {
3665: $percent = $current_disk_usage/(10 * $disk_quota);
3666: }
3667: $userlist->{$user}->[$index{'authorusage'}] = sprintf("%.0f",$percent);
3668: }
3669: if ($needauthorquota) {
3670: $userlist->{$user}->[$index{'authorquota'}] = sprintf("%.2f",$disk_quota);
3671: }
3672: }
1.225 ! raeburn 3673: unless ($env{'request.role.domain'} eq $udom) {
! 3674: $othdoms{$udom} = 1;
! 3675: }
1.4 raeburn 3676: $usercount ++;
3677: }
3678: my $autocount = 0;
3679: my $manualcount = 0;
3680: my $lockcount = 0;
3681: my $unlockcount = 0;
3682: if ($usercount) {
3683: $r->print($output);
3684: } else {
3685: if ($mode eq 'autoenroll') {
3686: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
3687: } else {
3688: return;
3689: }
1.1 raeburn 3690: }
1.2 raeburn 3691: #
3692: # Sort the users
1.1 raeburn 3693: my $index = $index{$sortby};
3694: my $second = $index{'username'};
3695: my $third = $index{'domain'};
1.159 raeburn 3696: my @sorted_users;
3697: if (($sortby eq 'authorquota') || ($sortby eq 'authorusage')) {
3698: @sorted_users = sort {
3699: $userlist->{$b}->[$index] <=> $userlist->{$a}->[$index] ||
3700: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
3701: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
3702: } (keys(%$userlist));
3703: } else {
3704: @sorted_users = sort {
3705: lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index]) ||
3706: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
3707: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
3708: } (keys(%$userlist));
3709: }
1.4 raeburn 3710: my $rowcount = 0;
1.178 raeburn 3711: my $disabled;
3712: if ($mode eq 'autoenroll') {
3713: unless ($permission->{'cusr'}) {
3714: $disabled = ' disabled="disabled"';
3715: }
3716: }
1.225 ! raeburn 3717: my (%shownfields_by_dom,%checkshown);
! 3718: if (keys(%othdoms)) {
! 3719: my @userinfo = ('firstname','middlename','lastname','generation',
! 3720: 'permanentemail','id');
! 3721: foreach my $dom (keys(%othdoms)) {
! 3722: my %shownfields = &get_othdom_shownfields($dom,\@userinfo);
! 3723: $shownfields_by_dom{$dom} = \%shownfields;
! 3724: }
! 3725: foreach my $item (@userinfo) {
! 3726: if ($item eq 'id') {
! 3727: if (grep(/^\Q$item\E$/,@cols)) {
! 3728: $checkshown{$item} = 1;
! 3729: }
! 3730: } elsif ($item eq 'permamentemail') {
! 3731: if (grep(/^email$/,@cols)) {
! 3732: $checkshown{$item} = 1;
! 3733: }
! 3734: } elsif (grep(/^fullname$/,@cols)) {
! 3735: $checkshown{$item} = 1;
! 3736: }
! 3737: }
! 3738: }
1.2 raeburn 3739: foreach my $user (@sorted_users) {
1.4 raeburn 3740: my %in;
1.2 raeburn 3741: my $sdata = $userlist->{$user};
1.225 ! raeburn 3742: $rowcount ++;
1.2 raeburn 3743: foreach my $item (@{$keylist}) {
3744: $in{$item} = $sdata->[$index{$item}];
3745: }
1.225 ! raeburn 3746: if ((grep(/^clicker$/,@cols)) || (keys(%checkshown) && (exists($othdoms{$in{'domain'}})))) {
! 3747: my %info = &Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers','inststatus',
! 3748: 'firstname','middlename','lastname','generation');
! 3749: if (grep(/^clicker$/,@cols)) {
! 3750: if ($info{'clickers'} !~/\w/) { $info{'clickers'} = '-'; }
! 3751: $in{'clicker'} = $info{'clickers'};
! 3752: }
! 3753: if (keys(%checkshown) && exists($othdoms{$in{'domain'}})) {
! 3754: my @statuses;
! 3755: if ($info{'inststatus'} ne '') {
! 3756: @statuses = split(/:/,$info{'inststatus'});
! 3757: } else {
! 3758: @statuses = ('default');
! 3759: }
! 3760: if (ref($shownfields_by_dom{$in{'domain'}}) eq 'HASH') {
! 3761: my (%shown,$rebuildname,%names);
! 3762: foreach my $type (@statuses) {
! 3763: if (ref($shownfields_by_dom{$in{'domain'}}{$type}) eq 'HASH') {
! 3764: foreach my $key (keys(%{$shownfields_by_dom{$in{'domain'}}{$type}})) {
! 3765: $shown{$key} = 1;
! 3766: }
! 3767: }
! 3768: }
! 3769: foreach my $item ('id','permanentemail') {
! 3770: if ($checkshown{$item} && !$shown{$item}) {
! 3771: if ($item eq 'permanentemail') {
! 3772: $in{'email'} = &mt('not shown');
! 3773: } else {
! 3774: $in{$item} = &mt('not shown');
! 3775: }
! 3776: }
! 3777: }
! 3778: foreach my $item ('firstname','middlename','lastname','generation') {
! 3779: if ($checkshown{$item} && !$shown{$item}) {
! 3780: $rebuildname = 1;
! 3781: } else {
! 3782: $names{$item} = $info{$item};
! 3783: }
! 3784: }
! 3785: if ($rebuildname) {
! 3786: $in{'fullname'} = &Apache::lonnet::format_name($names{'firstname'},
! 3787: $names{'middlename'},
! 3788: $names{'lastname'},
! 3789: $names{'generation'},'lastname');
! 3790: }
! 3791: }
! 3792: }
1.223 raeburn 3793: }
1.67 droeschl 3794: my $role = $in{'role'};
1.102 raeburn 3795: $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
1.136 raeburn 3796: unless ($mode eq 'excel') {
3797: if (! defined($in{'start'}) || $in{'start'} == 0) {
3798: $in{'start'} = &mt('none');
3799: } else {
3800: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
3801: }
3802: if (! defined($in{'end'}) || $in{'end'} == 0) {
3803: $in{'end'} = &mt('none');
3804: } else {
3805: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
3806: }
1.1 raeburn 3807: }
1.139 raeburn 3808: if ($context eq 'course') {
3809: my $lastlogin = $crslogins{$in{'username'}.':'.$in{'domain'}.':'.$in{'section'}.':'.$role};
3810: if ($lastlogin ne '') {
3811: $in{'lastlogin'} = &Apache::lonlocal::locallocaltime($lastlogin);
3812: }
3813: }
1.55 raeburn 3814: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2 raeburn 3815: $r->print(&Apache::loncommon::start_data_table_row());
1.11 raeburn 3816: my $checkval;
1.16 raeburn 3817: if ($mode eq 'autoenroll') {
3818: my $cellentry;
3819: if ($in{'type'} eq 'auto') {
1.178 raeburn 3820: $cellentry = '<b>'.&mt('auto').'</b> <label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Change').'</label>';
1.16 raeburn 3821: $autocount ++;
3822: } else {
1.178 raeburn 3823: $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 3824: $manualcount ++;
3825: if ($in{'lockedtype'}) {
1.178 raeburn 3826: $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Unlock').'</label>';
1.16 raeburn 3827: $unlockcount ++;
3828: } else {
1.178 raeburn 3829: $cellentry .= '<label><input type="checkbox" name="lockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Lock').'</label>';
1.16 raeburn 3830: $lockcount ++;
1.11 raeburn 3831: }
1.76 bisitz 3832: $cellentry .= '</span></td></tr></table>';
1.16 raeburn 3833: }
3834: $r->print("<td>$cellentry</td>\n");
3835: } else {
1.55 raeburn 3836: if ($mode ne 'pickauthor') {
3837: $r->print("<td>$rowcount</td>\n");
3838: }
1.16 raeburn 3839: if ($actionselect) {
1.26 raeburn 3840: my $showcheckbox;
3841: if ($role =~ /^cr\//) {
3842: $showcheckbox = $canchange{'cr'};
3843: } else {
3844: $showcheckbox = $canchange{$role};
3845: }
3846: if (!$showcheckbox) {
3847: if ($context eq 'course') {
3848: if ($canchangesec{$role} ne '') {
3849: if ($canchangesec{$role} eq $in{'section'}) {
3850: $showcheckbox = 1;
3851: }
3852: }
1.16 raeburn 3853: }
1.26 raeburn 3854: }
3855: if ($showcheckbox) {
3856: $checkval = $user;
3857: if ($context eq 'course') {
1.141 raeburn 3858: if (($role eq 'co' || $role eq 'cc') &&
3859: ($user =~ /^\Q$env{'user.name'}:$env{'user.domain'}:$role\E/)) {
3860: $showcheckbox = 0;
3861: } else {
3862: if ($role eq 'st') {
3863: $checkval .= ':st';
3864: }
3865: $checkval .= ':'.$in{'section'};
3866: if ($role eq 'st') {
3867: $checkval .= ':'.$in{'type'}.':'.
1.150 raeburn 3868: $in{'lockedtype'}.':'.
1.174 raeburn 3869: $in{'credits'}.':'.
3870: &escape($in{'instsec'});
1.141 raeburn 3871: }
3872: }
3873: }
3874: if ($showcheckbox) {
3875: $r->print('<td><input type="checkbox" name="'.
1.183 raeburn 3876: 'actionlist" value="'.
3877: &HTML::Entities::encode($checkval,'&<>"').'" />');
3878: foreach my $item ('start','end') {
3879: $r->print('<input type="hidden" name="'.
3880: &HTML::Entities::encode($checkval.'_'.$item,'&<>"').'"'.
3881: ' value="'.$sdata->[$index{$item}].'" />');
3882: }
3883: $r->print('</td>');
1.141 raeburn 3884: } else {
3885: $r->print('<td> </td>');
1.16 raeburn 3886: }
1.26 raeburn 3887: } else {
3888: $r->print('<td> </td>');
1.16 raeburn 3889: }
1.55 raeburn 3890: } elsif ($mode eq 'pickauthor') {
3891: $r->print('<td><input type="button" name="chooseauthor" onclick="javascript:gochoose('."'$in{'username'}'".');" value="'.&mt('Select').'" /></td>');
1.11 raeburn 3892: }
3893: }
1.2 raeburn 3894: foreach my $item (@cols) {
1.10 raeburn 3895: if ($item eq 'username') {
1.48 raeburn 3896: $r->print('<td>'.&print_username_link($mode,\%in).'</td>');
1.83 raeburn 3897: } elsif ($item eq 'status') {
3898: my $showitem = $in{$item};
3899: if (defined($ltstatus{$in{$item}})) {
3900: $showitem = $ltstatus{$in{$item}};
3901: }
3902: $r->print('<td>'.$showitem.'</td>'."\n");
1.140 raeburn 3903: } elsif ($item eq 'photo') {
3904: if (($context eq 'course') && ($mode ne 'autoenroll') &&
3905: ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
3906: if ($role eq 'st') {
3907: $r->print('<td align="right"><a href="javascript:photowindow('."'".$in{'photo'}."'".')"><img src="'.$in{'thumbnail'}.'" border="1" alt="" /></a></td>');
3908: } else {
3909: $r->print('<td> </td>');
3910: }
3911: }
3912: } elsif ($item eq 'clicker') {
3913: if (($context eq 'course') && ($mode ne 'autoenroll')) {
3914: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
1.223 raeburn 3915: $r->print('<td>'.$in{'clicker'}.'</td>');
1.140 raeburn 3916: } else {
1.225 ! raeburn 3917: $r->print('<td> </td>'."\n");
! 3918: }
1.149 raeburn 3919: }
1.159 raeburn 3920: } elsif (($item eq 'authorquota') || ($item eq 'authorusage')) {
3921: $r->print('<td align="right">'.$in{$item}.'</td>'."\n");
1.10 raeburn 3922: } else {
3923: $r->print('<td>'.$in{$item}.'</td>'."\n");
3924: }
1.2 raeburn 3925: }
3926: $r->print(&Apache::loncommon::end_data_table_row());
3927: } elsif ($mode eq 'csv') {
3928: next if (! defined($CSVfile));
3929: # no need to bother with $linkto
3930: my @line = ();
3931: foreach my $item (@cols) {
3932: push @line,&Apache::loncommon::csv_translate($in{$item});
3933: }
1.67 droeschl 3934: print $CSVfile '"'.join('","',@line)."\"\n";
1.2 raeburn 3935: } elsif ($mode eq 'excel') {
3936: my $col = 0;
3937: foreach my $item (@cols) {
3938: if ($item eq 'start' || $item eq 'end') {
1.136 raeburn 3939: if ((defined($in{$item})) && ($in{$item} != 0)) {
1.2 raeburn 3940: $excel_sheet->write($row,$col++,
1.136 raeburn 3941: &Apache::lonstathelpers::calc_serial($in{$item}),
1.2 raeburn 3942: $format->{'date'});
3943: } else {
3944: $excel_sheet->write($row,$col++,'none');
3945: }
3946: } else {
3947: $excel_sheet->write($row,$col++,$in{$item});
3948: }
3949: }
3950: $row++;
1.1 raeburn 3951: }
3952: }
1.55 raeburn 3953: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2 raeburn 3954: $r->print(&Apache::loncommon::end_data_table().'<br />');
3955: } elsif ($mode eq 'excel') {
3956: $excel_workbook->close();
1.162 bisitz 3957: $r->print('<p>'.&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '<a href="'.$excel_filename.'">','</a>')."</p>\n");
1.2 raeburn 3958: } elsif ($mode eq 'csv') {
3959: close($CSVfile);
1.162 bisitz 3960: $r->print('<p>'.&mt('[_1]Your CSV file[_2] is ready for download.', '<a href="'.$CSVfilename.'">','</a>')."</p>\n");
1.2 raeburn 3961: $r->rflush();
3962: }
3963: if ($mode eq 'autoenroll') {
3964: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
1.4 raeburn 3965: } else {
3966: return ($usercount);
1.2 raeburn 3967: }
1.1 raeburn 3968: }
3969:
1.56 raeburn 3970: sub bulkaction_javascript {
3971: my ($formname,$caller) = @_;
3972: my $docstart = 'document';
3973: if ($caller eq 'popup') {
3974: $docstart = 'opener.document';
3975: }
3976: my %lt = &Apache::lonlocal::texthash(
3977: acwi => 'Access will be set to start immediately',
3978: asyo => 'as you did not select an end date in the pop-up window',
3979: accw => 'Access will be set to continue indefinitely',
3980: asyd => 'as you did not select an end date in the pop-up window',
3981: sewi => "Sections will be switched to 'No section'",
3982: ayes => "as you either selected the 'No section' option",
3983: oryo => 'or you did not select a section in the pop-up window',
3984: arol => 'A role with no section will be added',
3985: swbs => 'Sections will be switched to:',
3986: rwba => 'Roles will be added for section(s):',
3987: );
3988: my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
3989: my $noaction = &mt("You need to select an action to take for the user(s) you have selected");
3990: my $singconfirm = &mt(' for a single user?');
3991: my $multconfirm = &mt(' for multiple users?');
1.170 damieng 3992: &js_escape(\$alert);
3993: &js_escape(\$noaction);
3994: &js_escape(\$singconfirm);
3995: &js_escape(\$multconfirm);
1.56 raeburn 3996: my $output = <<"ENDJS";
3997: function verify_action (field) {
3998: var numchecked = 0;
3999: var singconf = '$singconfirm';
4000: var multconf = '$multconfirm';
4001: if ($docstart.$formname.elements[field].length > 0) {
4002: for (i=0; i<$docstart.$formname.elements[field].length; i++) {
4003: if ($docstart.$formname.elements[field][i].checked == true) {
4004: numchecked ++;
4005: }
4006: }
4007: } else {
4008: if ($docstart.$formname.elements[field].checked == true) {
4009: numchecked ++;
4010: }
4011: }
4012: if (numchecked == 0) {
4013: alert("$alert");
4014: return;
4015: } else {
4016: var message = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].text;
4017: var choice = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].value;
4018: if (choice == '') {
4019: alert("$noaction");
4020: return;
4021: } else {
4022: if (numchecked == 1) {
4023: message += singconf;
4024: } else {
4025: message += multconf;
4026: }
4027: ENDJS
4028: if ($caller ne 'popup') {
4029: $output .= <<"NEWWIN";
4030: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate' || choice == 'chgsec') {
4031: opendatebrowser(document.$formname,'$formname','go');
4032: return;
4033:
4034: } else {
4035: if (confirm(message)) {
4036: document.$formname.phase.value = 'bulkchange';
4037: document.$formname.submit();
4038: return;
4039: }
4040: }
4041: NEWWIN
4042: } else {
4043: $output .= <<"POPUP";
4044: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
4045: var datemsg = '';
4046: if (($docstart.$formname.startdate_month.value == '') &&
4047: ($docstart.$formname.startdate_day.value == '') &&
4048: ($docstart.$formname.startdate_year.value == '')) {
4049: datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
4050: }
4051: if (($docstart.$formname.enddate_month.value == '') &&
4052: ($docstart.$formname.enddate_day.value == '') &&
4053: ($docstart.$formname.enddate_year.value == '')) {
4054: datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
4055: }
4056: if (datemsg != '') {
4057: message += "\\n"+datemsg;
4058: }
4059: }
4060: if (choice == 'chgsec') {
4061: var rolefilter = $docstart.$formname.showrole.options[$docstart.$formname.showrole.selectedIndex].value;
4062: var retained = $docstart.$formname.retainsec.value;
4063: var secshow = $docstart.$formname.newsecs.value;
4064: if (secshow == '') {
4065: if (rolefilter == 'st' || retained == 0 || retained == "") {
4066: message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
4067: } else {
4068: message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
4069: }
4070: } else {
4071: if (rolefilter == 'st' || retained == 0 || retained == "") {
4072: message += "\\n\\n$lt{'swbs'} "+secshow+".\\n";
4073: } else {
4074: message += "\\n\\n$lt{'rwba'} "+secshow+".\\n";
4075: }
4076: }
4077: }
4078: if (confirm(message)) {
4079: $docstart.$formname.phase.value = 'bulkchange';
4080: $docstart.$formname.submit();
4081: window.close();
4082: }
4083: POPUP
4084: }
4085: $output .= '
4086: }
4087: }
4088: }
4089: ';
4090: return $output;
4091: }
4092:
1.10 raeburn 4093: sub print_username_link {
1.48 raeburn 4094: my ($mode,$in) = @_;
1.10 raeburn 4095: my $output;
1.16 raeburn 4096: if ($mode eq 'autoenroll') {
4097: $output = $in->{'username'};
1.10 raeburn 4098: } else {
4099: $output = '<a href="javascript:username_display_launch('.
1.112 bisitz 4100: "'$in->{'username'}','$in->{'domain'}'".')">'.
1.10 raeburn 4101: $in->{'username'}.'</a>';
4102: }
4103: return $output;
4104: }
4105:
1.2 raeburn 4106: sub role_type_names {
4107: my %lt = &Apache::lonlocal::texthash (
1.13 raeburn 4108: 'domain' => 'Domain Roles',
4109: 'author' => 'Co-Author Roles',
4110: 'course' => 'Course Roles',
1.101 raeburn 4111: 'community' => 'Community Roles',
1.2 raeburn 4112: );
4113: return %lt;
4114: }
4115:
1.11 raeburn 4116: sub select_actions {
1.55 raeburn 4117: my ($context,$setting,$statusmode,$formname) = @_;
1.11 raeburn 4118: my %lt = &Apache::lonlocal::texthash(
4119: revoke => "Revoke user roles",
4120: delete => "Delete user roles",
4121: reenable => "Re-enable expired user roles",
4122: activate => "Make future user roles active now",
4123: chgdates => "Change starting/ending dates",
4124: chgsec => "Change section associated with user roles",
4125: );
1.150 raeburn 4126: # FIXME Add an option to change credits for student roles.
1.11 raeburn 4127: my ($output,$options,%choices);
1.23 raeburn 4128: # FIXME Disable actions for now for roletype=course in domain context
4129: if ($context eq 'domain' && $setting eq 'course') {
4130: return;
4131: }
1.26 raeburn 4132: if ($context eq 'course') {
4133: if ($env{'form.showrole'} ne 'Any') {
1.141 raeburn 4134: my $showactions;
4135: if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},
4136: $env{'request.course.id'})) {
4137: $showactions = 1;
4138: } elsif ($env{'request.course.sec'} ne '') {
4139: if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
4140: $showactions = 1;
4141: }
4142: }
4143: unless ($showactions) {
4144: unless (&is_courseowner($env{'request.course.id'},
4145: $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
4146: return;
4147: }
1.26 raeburn 4148: }
4149: }
4150: }
1.11 raeburn 4151: if ($statusmode eq 'Any') {
4152: $options .= '
4153: <option value="chgdates">'.$lt{'chgdates'}.'</option>';
4154: $choices{'dates'} = 1;
4155: } else {
4156: if ($statusmode eq 'Future') {
4157: $options .= '
4158: <option value="activate">'.$lt{'activate'}.'</option>';
4159: $choices{'dates'} = 1;
4160: } elsif ($statusmode eq 'Expired') {
4161: $options .= '
4162: <option value="reenable">'.$lt{'reenable'}.'</option>';
4163: $choices{'dates'} = 1;
4164: }
1.13 raeburn 4165: if ($statusmode eq 'Active' || $statusmode eq 'Future') {
4166: $options .= '
4167: <option value="chgdates">'.$lt{'chgdates'}.'</option>
4168: <option value="revoke">'.$lt{'revoke'}.'</option>';
4169: $choices{'dates'} = 1;
4170: }
1.11 raeburn 4171: }
4172: if ($context eq 'domain') {
4173: $options .= '
4174: <option value="delete">'.$lt{'delete'}.'</option>';
4175: }
4176: if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
1.26 raeburn 4177: if (($statusmode ne 'Expired') && ($env{'request.course.sec'} eq '')) {
1.11 raeburn 4178: $options .= '
4179: <option value="chgsec">'.$lt{'chgsec'}.'</option>';
4180: $choices{'sections'} = 1;
4181: }
4182: }
4183: if ($options) {
1.56 raeburn 4184: $output = '<select name="bulkaction">'."\n".
1.11 raeburn 4185: '<option value="" selected="selected">'.
4186: &mt('Please select').'</option>'."\n".$options."\n".'</select>';
4187: if ($choices{'dates'}) {
4188: $output .=
4189: '<input type="hidden" name="startdate_month" value="" />'."\n".
4190: '<input type="hidden" name="startdate_day" value="" />'."\n".
4191: '<input type="hidden" name="startdate_year" value="" />'."\n".
4192: '<input type="hidden" name="startdate_hour" value="" />'."\n".
4193: '<input type="hidden" name="startdate_minute" value="" />'."\n".
4194: '<input type="hidden" name="startdate_second" value="" />'."\n".
4195: '<input type="hidden" name="enddate_month" value="" />'."\n".
4196: '<input type="hidden" name="enddate_day" value="" />'."\n".
4197: '<input type="hidden" name="enddate_year" value="" />'."\n".
4198: '<input type="hidden" name="enddate_hour" value="" />'."\n".
4199: '<input type="hidden" name="enddate_minute" value="" />'."\n".
1.56 raeburn 4200: '<input type="hidden" name="enddate_second" value="" />'."\n".
4201: '<input type="hidden" name="no_end_date" value="" />'."\n";
1.11 raeburn 4202: if ($context eq 'course') {
4203: $output .= '<input type="hidden" name="makedatesdefault" value="" />'."\n";
4204: }
4205: }
4206: if ($choices{'sections'}) {
1.91 bisitz 4207: $output .= '<input type="hidden" name="retainsec" value="" />'."\n".
4208: '<input type="hidden" name="newsecs" value="" />'."\n";
1.11 raeburn 4209: }
4210: }
4211: return $output;
4212: }
4213:
4214: sub date_section_javascript {
4215: my ($context,$setting) = @_;
1.49 raeburn 4216: my $title = 'Date_And_Section_Selector';
1.41 raeburn 4217: my %nopopup = &Apache::lonlocal::texthash (
4218: revoke => "Check the boxes for any users for whom roles are to be revoked, and click 'Proceed'",
4219: delete => "Check the boxes for any users for whom roles are to be deleted, and click 'Proceed'",
4220: none => "Choose an action to take for selected users",
4221: );
1.96 bisitz 4222: my $output = <<"ENDONE";
4223: <script type="text/javascript">
4224: // <![CDATA[
1.41 raeburn 4225: function opendatebrowser(callingform,formname,calledby) {
1.11 raeburn 4226: var bulkaction = callingform.bulkaction.options[callingform.bulkaction.selectedIndex].value;
4227: var url = '/adm/createuser?';
4228: var type = '';
4229: var showrole = callingform.showrole.options[callingform.showrole.selectedIndex].value;
4230: ENDONE
4231: if ($context eq 'domain') {
4232: $output .= '
4233: type = callingform.roletype.options[callingform.roletype.selectedIndex].value;
4234: ';
4235: }
4236: my $width= '700';
4237: my $height = '400';
4238: $output .= <<"ENDTWO";
4239: url += 'action=dateselect&callingform=' + formname +
4240: '&roletype='+type+'&showrole='+showrole +'&bulkaction='+bulkaction;
4241: var title = '$title';
4242: var options = 'scrollbars=1,resizable=1,menubar=0';
4243: options += ',width=$width,height=$height';
4244: stdeditbrowser = open(url,title,options,'1');
4245: stdeditbrowser.focus();
4246: }
1.96 bisitz 4247: // ]]>
1.11 raeburn 4248: </script>
4249: ENDTWO
4250: return $output;
4251: }
4252:
4253: sub date_section_selector {
1.150 raeburn 4254: my ($context,$permission,$crstype,$showcredits) = @_;
1.11 raeburn 4255: my $callingform = $env{'form.callingform'};
4256: my $formname = 'dateselect';
4257: my $groupslist = &get_groupslist();
1.150 raeburn 4258: my $sec_js =
4259: &setsections_javascript($formname,$groupslist,undef,undef,$crstype,
4260: $showcredits);
1.11 raeburn 4261: my $output = <<"END";
4262: <script type="text/javascript">
1.96 bisitz 4263: // <![CDATA[
1.11 raeburn 4264:
4265: $sec_js
4266:
4267: function saveselections(formname) {
4268:
4269: END
4270: if ($env{'form.bulkaction'} eq 'chgsec') {
4271: $output .= <<"END";
1.40 raeburn 4272: if (formname.retainsec.length > 1) {
4273: for (var i=0; i<formname.retainsec.length; i++) {
4274: if (formname.retainsec[i].checked == true) {
4275: opener.document.$callingform.retainsec.value = formname.retainsec[i].value;
4276: }
4277: }
4278: } else {
4279: opener.document.$callingform.retainsec.value = formname.retainsec.value;
4280: }
1.103 raeburn 4281: setSections(formname,'$crstype');
1.11 raeburn 4282: if (seccheck == 'ok') {
4283: opener.document.$callingform.newsecs.value = formname.sections.value;
1.205 raeburn 4284: } else {
4285: return;
1.11 raeburn 4286: }
4287: END
4288: } else {
4289: if ($context eq 'course') {
4290: if (($env{'form.bulkaction'} eq 'reenable') ||
4291: ($env{'form.bulkaction'} eq 'activate') ||
4292: ($env{'form.bulkaction'} eq 'chgdates')) {
1.26 raeburn 4293: if ($env{'request.course.sec'} eq '') {
4294: $output .= <<"END";
1.11 raeburn 4295:
4296: if (formname.makedatesdefault.checked == true) {
4297: opener.document.$callingform.makedatesdefault.value = 1;
4298: }
4299: else {
4300: opener.document.$callingform.makedatesdefault.value = 0;
4301: }
4302:
4303: END
1.26 raeburn 4304: }
1.11 raeburn 4305: }
4306: }
4307: $output .= <<"END";
4308: opener.document.$callingform.startdate_month.value = formname.startdate_month.options[formname.startdate_month.selectedIndex].value;
4309: opener.document.$callingform.startdate_day.value = formname.startdate_day.value;
4310: opener.document.$callingform.startdate_year.value = formname.startdate_year.value;
4311: opener.document.$callingform.startdate_hour.value = formname.startdate_hour.options[formname.startdate_hour.selectedIndex].value;
4312: opener.document.$callingform.startdate_minute.value = formname.startdate_minute.value;
4313: opener.document.$callingform.startdate_second.value = formname.startdate_second.value;
4314: opener.document.$callingform.enddate_month.value = formname.enddate_month.options[formname.enddate_month.selectedIndex].value;
4315: opener.document.$callingform.enddate_day.value = formname.enddate_day.value;
4316: opener.document.$callingform.enddate_year.value = formname.enddate_year.value;
4317: opener.document.$callingform.enddate_hour.value = formname.enddate_hour.options[formname.enddate_hour.selectedIndex].value;
4318: opener.document.$callingform.enddate_minute.value = formname.enddate_minute.value;
4319: opener.document.$callingform.enddate_second.value = formname.enddate_second.value;
1.56 raeburn 4320: if (formname.no_end_date.checked) {
4321: opener.document.$callingform.no_end_date.value = '1';
4322: } else {
4323: opener.document.$callingform.no_end_date.value = '0';
4324: }
1.11 raeburn 4325: END
4326: }
1.56 raeburn 4327: my $verify_action_js = &bulkaction_javascript($callingform,'popup');
4328: $output .= <<"ENDJS";
4329: verify_action('actionlist');
1.11 raeburn 4330: }
1.56 raeburn 4331:
4332: $verify_action_js
4333:
1.96 bisitz 4334: // ]]>
1.11 raeburn 4335: </script>
1.56 raeburn 4336: ENDJS
1.11 raeburn 4337: my %lt = &Apache::lonlocal::texthash (
4338: chac => 'Access dates to apply for selected users',
4339: chse => 'Changes in section affiliation to apply to selected users',
1.118 raeburn 4340: 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.',
4341: forn => 'For a course role that is not "student", users may have roles in more than one section at a time.',
4342: reta => "Retain each user's current section affiliations?",
1.103 raeburn 4343: dnap => '(Does not apply to student roles).',
1.11 raeburn 4344: );
4345: my ($date_items,$headertext);
4346: if ($env{'form.bulkaction'} eq 'chgsec') {
4347: $headertext = $lt{'chse'};
4348: } else {
4349: $headertext = $lt{'chac'};
4350: my $starttime;
4351: if (($env{'form.bulkaction'} eq 'activate') ||
4352: ($env{'form.bulkaction'} eq 'reenable')) {
4353: $starttime = time;
4354: }
4355: $date_items = &date_setting_table($starttime,undef,$context,
1.21 raeburn 4356: $env{'form.bulkaction'},$formname,
1.101 raeburn 4357: $permission,$crstype);
1.11 raeburn 4358: }
4359: $output .= '<h3>'.$headertext.'</h3>'.
1.118 raeburn 4360: '<form name="'.$formname.'" method="post" action="">'."\n".
1.11 raeburn 4361: $date_items;
4362: if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
1.17 raeburn 4363: my ($cnum,$cdom) = &get_course_identity();
1.103 raeburn 4364: if ($crstype eq 'Community') {
1.118 raeburn 4365: $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.');
4366: $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 4367: $lt{'dnap'} = &mt('(Does not apply to member roles).');
4368: }
1.11 raeburn 4369: my $info;
4370: if ($env{'form.showrole'} eq 'st') {
4371: $output .= '<p>'.$lt{'fors'}.'</p>';
1.26 raeburn 4372: } elsif ($env{'form.showrole'} eq 'Any') {
1.11 raeburn 4373: $output .= '<p>'.$lt{'fors'}.'</p>'.
4374: '<p>'.$lt{'forn'}.' ';
4375: $info = $lt{'reta'};
4376: } else {
4377: $output .= '<p>'.$lt{'forn'}.' ';
4378: $info = $lt{'reta'};
4379: }
4380: if ($info) {
4381: $info .= '<span class="LC_nobreak">'.
4382: '<label><input type="radio" name="retainsec" value="1" '.
4383: 'checked="checked" />'.&mt('Yes').'</label> '.
4384: '<label><input type="radio" name="retainsec" value="0" />'.
4385: &mt('No').'</label></span>';
4386: if ($env{'form.showrole'} eq 'Any') {
4387: $info .= '<br />'.$lt{'dnap'};
4388: }
4389: $info .= '</p>';
4390: } else {
4391: $info = '<input type="hidden" name="retainsec" value="0" />';
4392: }
1.21 raeburn 4393: my $rowtitle = &mt('New section to assign');
1.150 raeburn 4394: my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,
4395: $permission,$context,'chgsec',$crstype);
1.11 raeburn 4396: $output .= $info.$secbox;
4397: }
4398: $output .= '<p>'.
1.81 schafran 4399: '<input type="button" name="dateselection" value="'.&mt('Save').'" onclick="javascript:saveselections(this.form)" /></p>'."\n".
1.11 raeburn 4400: '</form>';
4401: return $output;
4402: }
4403:
1.17 raeburn 4404: sub section_picker {
1.150 raeburn 4405: my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode,$crstype,
4406: $showcredits,$credits) = @_;
1.17 raeburn 4407: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
4408: my $sections_select .= &course_sections(\%sections_count,$role);
1.118 raeburn 4409: my $secbox = '<div>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
1.17 raeburn 4410: if ($mode eq 'upload') {
4411: my ($options,$cb_script,$coursepick) =
1.150 raeburn 4412: &default_role_selector($context,1,$crstype,$showcredits);
1.59 bisitz 4413: $secbox .= &Apache::lonhtmlcommon::row_title(&mt('role'),'LC_oddrow_value').
1.17 raeburn 4414: $options. &Apache::lonhtmlcommon::row_closure(1)."\n";
4415: }
4416: $secbox .= &Apache::lonhtmlcommon::row_title($rowtitle,'LC_oddrow_value')."\n";
4417: if ($env{'request.course.sec'} eq '') {
4418: $secbox .= '<table class="LC_createuser"><tr class="LC_section_row">'."\n".
4419: '<td align="center">'.&mt('Existing sections')."\n".
4420: '<br />'.$sections_select.'</td><td align="center">'.
4421: &mt('New section').'<br />'."\n".
1.118 raeburn 4422: '<input type="text" name="newsec" size="15" value="" />'."\n".
1.17 raeburn 4423: '<input type="hidden" name="sections" value="" />'."\n".
4424: '</td></tr></table>'."\n";
4425: } else {
1.149 raeburn 4426: $secbox .= '<input type="hidden" name="sections" value="'.
1.17 raeburn 4427: $env{'request.course.sec'}.'" />'.
4428: $env{'request.course.sec'};
4429: }
1.150 raeburn 4430: $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n";
4431: unless ($mode eq 'chgsec') {
4432: if ($showcredits) {
4433: $secbox .=
4434: &Apache::lonhtmlcommon::row_title(&mt('credits (students)'),
4435: 'LC_evenrow_value')."\n".
4436: '<input type="text" name="credits" size="3" value="'.$credits.'" />'."\n".
4437: &Apache::lonhtmlcommon::row_closure(1)."\n";
4438: }
4439: }
4440: $secbox .= &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.17 raeburn 4441: return $secbox;
4442: }
4443:
1.2 raeburn 4444: sub results_header_row {
1.102 raeburn 4445: my ($rolefilter,$statusmode,$context,$permission,$mode,$crstype) = @_;
1.5 raeburn 4446: my ($description,$showfilter);
4447: if ($rolefilter ne 'Any') {
4448: $showfilter = $rolefilter;
4449: }
1.2 raeburn 4450: if ($context eq 'course') {
1.24 raeburn 4451: if ($mode eq 'csv' || $mode eq 'excel') {
1.102 raeburn 4452: if ($crstype eq 'Community') {
4453: $description = &mt('Community - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
4454: } else {
4455: $description = &mt('Course - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
4456: }
1.24 raeburn 4457: }
1.2 raeburn 4458: if ($statusmode eq 'Expired') {
1.102 raeburn 4459: if ($crstype eq 'Community') {
4460: $description .= &mt('Users in community with expired [_1] roles',$showfilter);
4461: } else {
4462: $description .= &mt('Users in course with expired [_1] roles',$showfilter);
4463: }
1.11 raeburn 4464: } elsif ($statusmode eq 'Future') {
1.102 raeburn 4465: if ($crstype eq 'Community') {
4466: $description .= &mt('Users in community with future [_1] roles',$showfilter);
4467: } else {
4468: $description .= &mt('Users in course with future [_1] roles',$showfilter);
4469: }
1.2 raeburn 4470: } elsif ($statusmode eq 'Active') {
1.102 raeburn 4471: if ($crstype eq 'Community') {
4472: $description .= &mt('Users in community with active [_1] roles',$showfilter);
4473: } else {
4474: $description .= &mt('Users in course with active [_1] roles',$showfilter);
4475: }
1.2 raeburn 4476: } else {
4477: if ($rolefilter eq 'Any') {
1.102 raeburn 4478: if ($crstype eq 'Community') {
4479: $description .= &mt('All users in community');
4480: } else {
4481: $description .= &mt('All users in course');
4482: }
1.2 raeburn 4483: } else {
1.102 raeburn 4484: if ($crstype eq 'Community') {
4485: $description .= &mt('All users in community with [_1] roles',$rolefilter);
4486: } else {
4487: $description .= &mt('All users in course with [_1] roles',$rolefilter);
4488: }
1.2 raeburn 4489: }
4490: }
1.33 raeburn 4491: my $constraint;
1.26 raeburn 4492: my $viewablesec = &viewable_section($permission);
4493: if ($viewablesec ne '') {
1.15 raeburn 4494: if ($env{'form.showrole'} eq 'st') {
1.33 raeburn 4495: $constraint = &mt('only users in section "[_1]"',$viewablesec);
1.103 raeburn 4496: } elsif (($env{'form.showrole'} ne 'cc') && ($env{'form.showrole'} ne 'co')) {
1.33 raeburn 4497: $constraint = &mt('only users affiliated with no section or section "[_1]"',$viewablesec);
4498: }
4499: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
4500: if ($env{'form.grpfilter'} eq 'none') {
4501: $constraint .= &mt(' and not in any group');
4502: } else {
4503: $constraint .= &mt(' and members of group: "[_1]"',$env{'form.grpfilter'});
4504: }
4505: }
4506: } else {
4507: if (($env{'form.secfilter'} ne 'all') && ($env{'form.secfilter'} ne '')) {
4508: if ($env{'form.secfilter'} eq 'none') {
4509: $constraint = &mt('only users affiliated with no section');
4510: } else {
4511: $constraint = &mt('only users affiliated with section "[_1]"',$env{'form.secfilter'});
4512: }
4513: }
4514: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
4515: if ($env{'form.grpfilter'} eq 'none') {
4516: if ($constraint eq '') {
4517: $constraint = &mt('only users not in any group');
4518: } else {
4519: $constraint .= &mt(' and also not in any group');
4520: }
4521: } else {
4522: if ($constraint eq '') {
4523: $constraint = &mt('only members of group: "[_1]"',$env{'form.grpfilter'});
4524: } else {
4525: $constraint .= &mt(' and also members of group: "[_1]"'.$env{'form.grpfilter'});
4526: }
4527: }
1.15 raeburn 4528: }
4529: }
1.33 raeburn 4530: if ($constraint ne '') {
4531: $description .= ' ('.$constraint.')';
4532: }
1.13 raeburn 4533: } elsif ($context eq 'author') {
1.222 raeburn 4534: my ($auname,$audom);
4535: if ($env{'request.role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)$}) {
4536: ($audom,$auname) = ($1,$2);
4537: } else {
4538: ($audom,$auname) = ($env{'user.domain'},$env{'user.name'});
4539: }
1.14 raeburn 4540: $description =
1.73 bisitz 4541: &mt('Author space for [_1]'
4542: ,'<span class="LC_cusr_emph">'
1.222 raeburn 4543: .&Apache::loncommon::plainname($auname,$audom)
1.73 bisitz 4544: .'</span>')
4545: .': ';
1.2 raeburn 4546: if ($statusmode eq 'Expired') {
1.5 raeburn 4547: $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
1.2 raeburn 4548: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4549: $description .= &mt('Co-authors with future [_1] roles',$showfilter);
1.2 raeburn 4550: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4551: $description .= &mt('Co-authors with active [_1] roles',$showfilter);
1.2 raeburn 4552: } else {
4553: if ($rolefilter eq 'Any') {
1.5 raeburn 4554: $description .= &mt('All co-authors');
1.2 raeburn 4555: } else {
4556: $description .= &mt('All co-authors with [_1] roles',$rolefilter);
4557: }
4558: }
4559: } elsif ($context eq 'domain') {
4560: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.73 bisitz 4561: $description = &mt('Domain - [_1]:',$domdesc).' ';
1.2 raeburn 4562: if ($env{'form.roletype'} eq 'domain') {
4563: if ($statusmode eq 'Expired') {
1.5 raeburn 4564: $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
1.2 raeburn 4565: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4566: $description .= &mt('Users in domain with future [_1] roles',$showfilter);
1.2 raeburn 4567: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4568: $description .= &mt('Users in domain with active [_1] roles',$showfilter);
1.2 raeburn 4569: } else {
4570: if ($rolefilter eq 'Any') {
1.5 raeburn 4571: $description .= &mt('All users in domain');
1.2 raeburn 4572: } else {
4573: $description .= &mt('All users in domain with [_1] roles',$rolefilter);
4574: }
4575: }
1.13 raeburn 4576: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 4577: if ($statusmode eq 'Expired') {
1.5 raeburn 4578: $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
1.2 raeburn 4579: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4580: $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
1.2 raeburn 4581: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4582: $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
1.2 raeburn 4583: } else {
4584: if ($rolefilter eq 'Any') {
1.5 raeburn 4585: $description .= &mt('All users with co-author roles in domain',$showfilter);
1.2 raeburn 4586: } else {
1.116 bisitz 4587: $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
1.2 raeburn 4588: }
4589: }
1.102 raeburn 4590: } elsif (($env{'form.roletype'} eq 'course') ||
4591: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 4592: my $coursefilter = $env{'form.coursepick'};
1.102 raeburn 4593: if ($env{'form.roletype'} eq 'course') {
4594: if ($coursefilter eq 'category') {
4595: my $instcode = &instcode_from_coursefilter();
4596: if ($instcode eq '.') {
4597: $description .= &mt('All courses in domain').' - ';
4598: } else {
4599: $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
4600: }
4601: } elsif ($coursefilter eq 'selected') {
4602: $description .= &mt('Selected courses in domain').' - ';
4603: } elsif ($coursefilter eq 'all') {
1.2 raeburn 4604: $description .= &mt('All courses in domain').' - ';
4605: }
1.102 raeburn 4606: } elsif ($env{'form.roletype'} eq 'community') {
4607: if ($coursefilter eq 'selected') {
4608: $description .= &mt('Selected communities in domain').' - ';
4609: } elsif ($coursefilter eq 'all') {
4610: $description .= &mt('All communities in domain').' - ';
4611: }
1.2 raeburn 4612: }
4613: if ($statusmode eq 'Expired') {
1.5 raeburn 4614: $description .= &mt('users with expired [_1] roles',$showfilter);
1.2 raeburn 4615: } elsif ($statusmode eq 'Future') {
1.5 raeburn 4616: $description .= &mt('users with future [_1] roles',$showfilter);
1.2 raeburn 4617: } elsif ($statusmode eq 'Active') {
1.5 raeburn 4618: $description .= &mt('users with active [_1] roles',$showfilter);
1.2 raeburn 4619: } else {
4620: if ($rolefilter eq 'Any') {
4621: $description .= &mt('all users');
4622: } else {
4623: $description .= &mt('users with [_1] roles',$rolefilter);
4624: }
4625: }
4626: }
4627: }
4628: return $description;
4629: }
1.22 raeburn 4630:
4631: sub viewable_section {
4632: my ($permission) = @_;
4633: my $viewablesec;
4634: if (ref($permission) eq 'HASH') {
4635: if (exists($permission->{'view_section'})) {
4636: $viewablesec = $permission->{'view_section'};
4637: } elsif (exists($permission->{'cusr_section'})) {
4638: $viewablesec = $permission->{'cusr_section'};
4639: }
4640: }
4641: return $viewablesec;
4642: }
4643:
1.2 raeburn 4644:
1.1 raeburn 4645: #################################################
4646: #################################################
4647: sub show_drop_list {
1.101 raeburn 4648: my ($r,$classlist,$nosort,$permission,$crstype) = @_;
1.29 raeburn 4649: my $cid = $env{'request.course.id'};
1.17 raeburn 4650: my ($cnum,$cdom) = &get_course_identity($cid);
1.1 raeburn 4651: if (! exists($env{'form.sortby'})) {
4652: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
4653: ['sortby']);
4654: }
4655: my $sortby = $env{'form.sortby'};
4656: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
4657: $sortby = 'username';
4658: }
4659: my $action = "drop";
1.17 raeburn 4660: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
1.1 raeburn 4661: $r->print(<<END);
4662: <input type="hidden" name="sortby" value="$sortby" />
4663: <input type="hidden" name="action" value="$action" />
4664: <input type="hidden" name="state" value="done" />
1.17 raeburn 4665: <script type="text/javascript" language="Javascript">
1.96 bisitz 4666: // <![CDATA[
1.17 raeburn 4667: $check_uncheck_js
1.96 bisitz 4668: // ]]>
1.1 raeburn 4669: </script>
1.86 bisitz 4670: <input type="hidden" name="phase" value="four" />
1.1 raeburn 4671: END
1.30 raeburn 4672: my ($indexhash,$keylist) = &make_keylist_array();
4673: my $studentcount = 0;
4674: if (ref($classlist) eq 'HASH') {
4675: foreach my $student (keys(%{$classlist})) {
4676: my $sdata = $classlist->{$student};
4677: my $status = $sdata->[$indexhash->{'status'}];
4678: my $section = $sdata->[$indexhash->{'section'}];
4679: if ($status ne 'Active') {
4680: delete($classlist->{$student});
4681: next;
4682: }
4683: if ($env{'request.course.sec'} ne '') {
4684: if ($section ne $env{'request.course.sec'}) {
4685: delete($classlist->{$student});
4686: next;
4687: }
4688: }
4689: $studentcount ++;
4690: }
4691: }
4692: if (!$studentcount) {
1.143 bisitz 4693: my $msg = '';
1.101 raeburn 4694: if ($crstype eq 'Community') {
1.143 bisitz 4695: $msg = &mt('There are no members to drop.');
1.101 raeburn 4696: } else {
1.143 bisitz 4697: $msg = &mt('There are no students to drop.');
1.101 raeburn 4698: }
1.143 bisitz 4699: $r->print('<p class="LC_info">'.$msg.'</p>');
1.30 raeburn 4700: return;
4701: }
4702: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
4703: $classlist,$keylist,$cdom,$cnum);
4704: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
4705: 'dom' => "domain",
1.162 bisitz 4706: 'id' => "ID",
1.30 raeburn 4707: 'sn' => "student name",
1.101 raeburn 4708: 'mn' => "member name",
1.30 raeburn 4709: 'sec' => "section",
4710: 'start' => "start date",
4711: 'end' => "end date",
4712: 'groups' => "active groups",
4713: );
1.101 raeburn 4714: my $nametitle = $lt{'sn'};
4715: if ($crstype eq 'Community') {
4716: $nametitle = $lt{'mn'};
4717: }
1.1 raeburn 4718: if ($nosort) {
1.17 raeburn 4719: $r->print(&Apache::loncommon::start_data_table().
4720: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 4721: $r->print(<<END);
4722: <th> </th>
4723: <th>$lt{'usrn'}</th>
4724: <th>$lt{'dom'}</th>
1.162 bisitz 4725: <th>$lt{'id'}</th>
1.101 raeburn 4726: <th>$nametitle</th>
1.1 raeburn 4727: <th>$lt{'sec'}</th>
4728: <th>$lt{'start'}</th>
4729: <th>$lt{'end'}</th>
4730: <th>$lt{'groups'}</th>
4731: END
1.17 raeburn 4732: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 4733: } else {
1.17 raeburn 4734: $r->print(&Apache::loncommon::start_data_table().
4735: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 4736: $r->print(<<END);
1.17 raeburn 4737: <th> </th>
1.1 raeburn 4738: <th>
1.162 bisitz 4739: <a href="/adm/createuser?action=$action&sortby=username">$lt{'usrn'}</a>
1.1 raeburn 4740: </th><th>
1.162 bisitz 4741: <a href="/adm/createuser?action=$action&sortby=domain">$lt{'dom'}</a>
1.1 raeburn 4742: </th><th>
1.162 bisitz 4743: <a href="/adm/createuser?action=$action&sortby=id">$lt{'id'}</a>
1.1 raeburn 4744: </th><th>
1.162 bisitz 4745: <a href="/adm/createuser?action=$action&sortby=fullname">$nametitle</a>
1.1 raeburn 4746: </th><th>
1.162 bisitz 4747: <a href="/adm/createuser?action=$action&sortby=section">$lt{'sec'}</a>
1.1 raeburn 4748: </th><th>
1.162 bisitz 4749: <a href="/adm/createuser?action=$action&sortby=start">$lt{'start'}</a>
1.1 raeburn 4750: </th><th>
1.162 bisitz 4751: <a href="/adm/createuser?action=$action&sortby=end">$lt{'end'}</a>
1.1 raeburn 4752: </th><th>
1.162 bisitz 4753: <a href="/adm/createuser?action=$action&sortby=groups">$lt{'groups'}</a>
1.1 raeburn 4754: </th>
4755: END
1.17 raeburn 4756: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 4757: }
4758: #
4759: # Sort the students
1.30 raeburn 4760: my $index = $indexhash->{$sortby};
4761: my $second = $indexhash->{'username'};
4762: my $third = $indexhash->{'domain'};
1.1 raeburn 4763: my @Sorted_Students = sort {
4764: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
4765: ||
4766: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
4767: ||
4768: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
1.30 raeburn 4769: } (keys(%{$classlist}));
1.1 raeburn 4770: foreach my $student (@Sorted_Students) {
4771: my $error;
4772: my $sdata = $classlist->{$student};
1.30 raeburn 4773: my $username = $sdata->[$indexhash->{'username'}];
4774: my $domain = $sdata->[$indexhash->{'domain'}];
4775: my $section = $sdata->[$indexhash->{'section'}];
4776: my $name = $sdata->[$indexhash->{'fullname'}];
4777: my $id = $sdata->[$indexhash->{'id'}];
4778: my $start = $sdata->[$indexhash->{'start'}];
4779: my $end = $sdata->[$indexhash->{'end'}];
1.1 raeburn 4780: my $groups = $classgroups->{$student};
4781: my $active_groups;
4782: if (ref($groups->{active}) eq 'HASH') {
4783: $active_groups = join(', ',keys(%{$groups->{'active'}}));
4784: }
4785: if (! defined($start) || $start == 0) {
4786: $start = &mt('none');
4787: } else {
4788: $start = &Apache::lonlocal::locallocaltime($start);
4789: }
4790: if (! defined($end) || $end == 0) {
4791: $end = &mt('none');
4792: } else {
4793: $end = &Apache::lonlocal::locallocaltime($end);
4794: }
1.17 raeburn 4795: my $studentkey = $student.':'.$section;
1.30 raeburn 4796: my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$indexhash->{'start'}].'" />';
1.1 raeburn 4797: #
4798: $r->print(&Apache::loncommon::start_data_table_row());
4799: $r->print(<<"END");
1.86 bisitz 4800: <td><input type="checkbox" name="droplist" value="$studentkey" /></td>
1.1 raeburn 4801: <td>$username</td>
4802: <td>$domain</td>
4803: <td>$id</td>
4804: <td>$name</td>
4805: <td>$section</td>
1.29 raeburn 4806: <td>$start $startitem</td>
1.1 raeburn 4807: <td>$end</td>
4808: <td>$active_groups</td>
4809: END
4810: $r->print(&Apache::loncommon::end_data_table_row());
4811: }
4812: $r->print(&Apache::loncommon::end_data_table().'<br />');
4813: %lt=&Apache::lonlocal::texthash(
1.29 raeburn 4814: 'dp' => "Drop Students",
1.101 raeburn 4815: 'dm' => "Drop Members",
1.1 raeburn 4816: 'ca' => "check all",
4817: 'ua' => "uncheck all",
4818: );
1.101 raeburn 4819: my $btn = $lt{'dp'};
4820: if ($crstype eq 'Community') {
4821: $btn = $lt{'dm'};
4822: }
1.1 raeburn 4823: $r->print(<<"END");
1.89 bisitz 4824: <p>
1.86 bisitz 4825: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)" />
4826: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)" />
1.89 bisitz 4827: </p>
4828: <p>
1.101 raeburn 4829: <input type="submit" value="$btn" />
1.89 bisitz 4830: </p>
1.1 raeburn 4831: END
4832: return;
4833: }
4834:
4835: #
4836: # Print out the initial form to get the file containing a list of users
4837: #
4838: sub print_first_users_upload_form {
4839: my ($r,$context) = @_;
4840: my $str;
1.86 bisitz 4841: $str = '<input type="hidden" name="phase" value="two" />';
1.1 raeburn 4842: $str .= '<input type="hidden" name="action" value="upload" />';
1.101 raeburn 4843: $str .= '<input type="hidden" name="state" value="got_file" />';
1.95 bisitz 4844:
1.147 bisitz 4845: $str .= &Apache::grades::checkforfile_js();
4846:
1.85 bisitz 4847: $str .= '<h2>'.&mt('Upload a file containing information about users').'</h2>'."\n";
1.95 bisitz 4848:
4849: # Excel and CSV Help
1.147 bisitz 4850: $str .= '<div class="LC_columnSection">'
1.95 bisitz 4851: .&Apache::loncommon::help_open_topic("Course_Create_Class_List",
4852: &mt("How do I create a users list from a spreadsheet"))
1.147 bisitz 4853: .' '.&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1.95 bisitz 4854: &mt("How do I create a CSV file from a spreadsheet"))
1.147 bisitz 4855: ."</div>\n";
1.95 bisitz 4856: $str .= &Apache::lonhtmlcommon::start_pick_box()
1.103 raeburn 4857: .&Apache::lonhtmlcommon::row_title(&mt('File'));
4858: if (&Apache::lonlocal::current_language() ne 'en') {
4859: if ($context eq 'course') {
4860: $str .= '<p class="LC_info">'."\n"
4861: .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n"
4862: .'</p>'."\n";
4863: }
4864: }
4865: $str .= &Apache::loncommon::upfile_select_html()
1.95 bisitz 4866: .&Apache::lonhtmlcommon::row_closure()
4867: .&Apache::lonhtmlcommon::row_title(
4868: '<label for="noFirstLine">'
4869: .&mt('Ignore First Line')
4870: .'</label>')
4871: .'<input type="checkbox" name="noFirstLine" id="noFirstLine" />'
4872: .&Apache::lonhtmlcommon::row_closure(1)
4873: .&Apache::lonhtmlcommon::end_pick_box();
4874:
4875: $str .= '<p>'
1.198 raeburn 4876: .'<input type="button" name="fileupload" value="'.&mt('Next').'"'
1.147 bisitz 4877: .' onclick="javascript:checkUpload(this.form);" />'
1.95 bisitz 4878: .'</p>';
4879:
1.1 raeburn 4880: $r->print($str);
4881: return;
4882: }
4883:
4884: # ================================================= Drop/Add from uploaded file
4885: sub upfile_drop_add {
1.150 raeburn 4886: my ($r,$context,$permission,$showcredits) = @_;
1.189 raeburn 4887: my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'});
4888: if ($datatoken ne '') {
4889: &Apache::loncommon::load_tmp_file($r,$datatoken);
4890: }
1.1 raeburn 4891: my @userdata=&Apache::loncommon::upfile_record_sep();
4892: if($env{'form.noFirstLine'}){shift(@userdata);}
4893: my @keyfields = split(/\,/,$env{'form.keyfields'});
4894: my %fields=();
4895: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
4896: if ($env{'form.upfile_associate'} eq 'reverse') {
4897: if ($env{'form.f'.$i} ne 'none') {
4898: $fields{$keyfields[$i]}=$env{'form.f'.$i};
4899: }
4900: } else {
4901: $fields{$env{'form.f'.$i}}=$keyfields[$i];
4902: }
4903: }
4904: #
4905: # Store the field choices away
1.150 raeburn 4906: my @storefields = qw/username names fname mname lname gen id
4907: sec ipwd email role domain inststatus/;
4908: if ($showcredits) {
4909: push (@storefields,'credits');
4910: }
4911: my %fieldstype;
4912: foreach my $field (@storefields) {
1.1 raeburn 4913: $env{'form.'.$field.'_choice'}=$fields{$field};
1.150 raeburn 4914: $fieldstype{$field.'_choice'} = 'scalar';
1.1 raeburn 4915: }
1.150 raeburn 4916: &Apache::loncommon::store_course_settings('enrollment_upload',\%fieldstype);
1.220 raeburn 4917: my ($cid,$crstype,$setting,$crsdom,$crsnum,$oldcrsuserdoms,%emptyok);
1.101 raeburn 4918: if ($context eq 'domain') {
4919: $setting = $env{'form.roleaction'};
1.220 raeburn 4920: if (exists($fields{'names'})) {
4921: map { $emptyok{$_} = 1; } ('lastname','firstname','middlename');
4922: } else {
4923: if (exists($fields{'lname'})) {
4924: $emptyok{'lastname'} = 1;
4925: }
4926: if (exists($fields{'fname'})) {
4927: $emptyok{'firstname'} = 1;
4928: }
4929: if (exists($fields{'mname'})) {
4930: $emptyok{'middlename'} = 1;
4931: }
4932: }
4933: if (exists($fields{'gen'})) {
4934: $emptyok{'generation'} = 1;
4935: }
1.101 raeburn 4936: }
4937: if ($env{'request.course.id'} ne '') {
4938: $cid = $env{'request.course.id'};
4939: $crstype = &Apache::loncommon::course_type();
1.185 raeburn 4940: $crsdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.212 raeburn 4941: $crsnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.101 raeburn 4942: } elsif ($setting eq 'course') {
4943: if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
4944: $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
4945: $crstype = &Apache::loncommon::course_type($cid);
1.185 raeburn 4946: $crsdom = $env{'form.dcdomain'};
1.212 raeburn 4947: $crsnum = $env{'form.dccourse'};
1.217 raeburn 4948: if (exists($env{'course.'.$cid.'.internal.userdomains'})) {
4949: $oldcrsuserdoms = 1;
4950: }
4951: my %coursedesc = &Apache::lonnet::coursedescription($cid,{ one_time => 1 });
4952: $env{'course.'.$cid.'.internal.userdomains'} = $coursedesc{'internal.userdomains'};
1.101 raeburn 4953: }
4954: }
1.1 raeburn 4955: my ($startdate,$enddate) = &get_dates_from_form();
4956: if ($env{'form.makedatesdefault'}) {
1.101 raeburn 4957: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
1.1 raeburn 4958: }
4959: # Determine domain and desired host (home server)
1.57 raeburn 4960: my $defdom=$env{'request.role.domain'};
4961: my $domain;
4962: if ($env{'form.defaultdomain'} ne '') {
1.185 raeburn 4963: if (($context eq 'course') || ($setting eq 'course')) {
1.190 raeburn 4964: if ($env{'form.defaultdomain'} eq $crsdom) {
4965: $domain = $env{'form.defaultdomain'};
4966: } else {
1.185 raeburn 4967: if (&Apache::lonnet::will_trust('enroll',$crsdom,$env{'form.defaultdomain'})) {
4968: $domain = $env{'form.defaultdomain'};
4969: } else {
1.192 raeburn 4970: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4971: &mt('Enrollment of users not permitted for specified default domain: [_1].',
4972: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4973: return 'untrusted';
1.185 raeburn 4974: }
4975: }
4976: } elsif ($context eq 'author') {
1.190 raeburn 4977: if ($env{'form.defaultdomain'} eq $defdom) {
4978: $domain = $env{'form.defaultdomain'};
4979: } else {
1.185 raeburn 4980: if ((&Apache::lonnet::will_trust('othcoau',$defdom,$env{'form.defaultdomain'})) &&
1.186 raeburn 4981: (&Apache::lonnet::will_trust('coaurem',$env{'form.defaultdomain'},$defdom))) {
1.185 raeburn 4982: $domain = $env{'form.defaultdomain'};
4983: } else {
1.192 raeburn 4984: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4985: &mt('Addition of users not permitted for specified default domain: [_1].',
4986: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4987: return 'untrusted';
1.185 raeburn 4988: }
4989: }
4990: } elsif (($context eq 'domain') && ($setting eq 'domain')) {
1.190 raeburn 4991: if ($env{'form.defaultdomain'} eq $defdom) {
4992: $domain = $env{'form.defaultdomain'};
4993: } else {
1.185 raeburn 4994: if (&Apache::lonnet::will_trust('domroles',$defdom,$env{'form.defaultdomain'})) {
4995: $domain = $env{'form.defaultdomain'};
4996: } else {
1.192 raeburn 4997: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4998: &mt('Addition of users not permitted for specified default domain: [_1].',
4999: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 5000: return 'untrusted';
1.185 raeburn 5001: }
5002: }
5003: }
1.57 raeburn 5004: } else {
5005: $domain = $defdom;
5006: }
1.1 raeburn 5007: my $desiredhost = $env{'form.lcserver'};
5008: if (lc($desiredhost) eq 'default') {
5009: $desiredhost = undef;
5010: } else {
1.57 raeburn 5011: my %home_servers = &Apache::lonnet::get_servers($defdom,'library');
1.1 raeburn 5012: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 5013: $r->print('<p class="LC_error">'.&mt('Error').': '.
5014: &mt('Invalid home server specified').'</p>');
5015: return 'invalidhome';
1.1 raeburn 5016: }
5017: }
5018: # Determine authentication mechanism
5019: my $changeauth;
5020: if ($context eq 'domain') {
5021: $changeauth = $env{'form.changeauth'};
5022: }
5023: my $amode = '';
5024: my $genpwd = '';
1.200 raeburn 5025: my @genpwdfail;
1.1 raeburn 5026: if ($env{'form.login'} eq 'krb') {
5027: $amode='krb';
5028: $amode.=$env{'form.krbver'};
5029: $genpwd=$env{'form.krbarg'};
5030: } elsif ($env{'form.login'} eq 'int') {
5031: $amode='internal';
5032: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
5033: $genpwd=$env{'form.intarg'};
1.200 raeburn 5034: @genpwdfail =
1.202 raeburn 5035: &Apache::loncommon::check_passwd_rules($domain,$genpwd);
1.1 raeburn 5036: }
5037: } elsif ($env{'form.login'} eq 'loc') {
5038: $amode='localauth';
5039: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
5040: $genpwd=$env{'form.locarg'};
5041: }
1.194 raeburn 5042: } elsif ($env{'form.login'} eq 'lti') {
5043: $amode='lti';
1.1 raeburn 5044: }
5045: if ($amode =~ /^krb/) {
5046: if (! defined($genpwd) || $genpwd eq '') {
1.193 raeburn 5047: $r->print('<span class="Error">'.
1.1 raeburn 5048: &mt('Unable to enroll users').' '.
5049: &mt('No Kerberos domain was specified.').'</span></p>');
5050: $amode = ''; # This causes the loop below to be skipped
5051: }
5052: }
1.150 raeburn 5053: my ($defaultsec,$defaultrole,$defaultcredits,$commoncredits);
1.1 raeburn 5054: if ($context eq 'domain') {
5055: if ($setting eq 'domain') {
5056: $defaultrole = $env{'form.defaultrole'};
5057: } elsif ($setting eq 'course') {
5058: $defaultrole = $env{'form.courserole'};
1.27 raeburn 5059: $defaultsec = $env{'form.sections'};
1.150 raeburn 5060: if ($showcredits) {
5061: $commoncredits = $env{'form.credits'};
5062: if ($crstype ne 'Community') {
5063: my %coursehash=&Apache::lonnet::coursedescription($cid);
5064: $defaultcredits = $coursehash{'internal.defaultcredits'};
5065: }
5066: }
1.149 raeburn 5067: }
1.13 raeburn 5068: } elsif ($context eq 'author') {
1.1 raeburn 5069: $defaultrole = $env{'form.defaultrole'};
1.27 raeburn 5070: } elsif ($context eq 'course') {
5071: $defaultrole = $env{'form.defaultrole'};
5072: $defaultsec = $env{'form.sections'};
1.150 raeburn 5073: if ($showcredits) {
5074: $commoncredits = $env{'form.credits'};
5075: $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
5076: }
1.1 raeburn 5077: }
1.27 raeburn 5078: # Check to see if user information can be changed
5079: my @userinfo = ('firstname','middlename','lastname','generation',
5080: 'permanentemail','id');
5081: my %canmodify;
5082: if (&Apache::lonnet::allowed('mau',$domain)) {
1.84 raeburn 5083: push(@userinfo,'inststatus');
1.27 raeburn 5084: foreach my $field (@userinfo) {
5085: $canmodify{$field} = 1;
5086: }
5087: }
5088: my (%userlist,%modifiable_fields,@poss_roles);
5089: my $secidx = &Apache::loncoursedata::CL_SECTION();
1.102 raeburn 5090: my @courseroles = &roles_by_context('course',1,$crstype);
1.27 raeburn 5091: if (!&Apache::lonnet::allowed('mau',$domain)) {
5092: if ($context eq 'course' || $context eq 'author') {
1.101 raeburn 5093: @poss_roles = &curr_role_permissions($context,'','',$crstype);
1.27 raeburn 5094: my @statuses = ('active','future');
5095: my ($indexhash,$keylist) = &make_keylist_array();
5096: my %info;
5097: foreach my $role (@poss_roles) {
5098: %{$modifiable_fields{$role}} = &can_modify_userinfo($context,$domain,
5099: \@userinfo,[$role]);
5100: }
5101: if ($context eq 'course') {
5102: my ($cnum,$cdom) = &get_course_identity();
5103: my $roster = &Apache::loncoursedata::get_classlist();
1.66 raeburn 5104: if (ref($roster) eq 'HASH') {
5105: %userlist = %{$roster};
5106: }
1.27 raeburn 5107: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
5108: \@statuses,\@poss_roles);
5109: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
5110: \%advrolehash,$permission);
5111: } elsif ($context eq 'author') {
5112: my %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
5113: \@statuses,\@poss_roles);
5114: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
5115: \%cstr_roles,$permission);
5116: }
5117: }
1.1 raeburn 5118: }
1.193 raeburn 5119: if ($datatoken eq '') {
5120: $r->print('<p class="LC_error">'.&mt('Error').': '.
5121: &mt('Invalid datatoken').'</p>');
5122: return 'missingdata';
5123: }
1.1 raeburn 5124: if ( $domain eq &LONCAPA::clean_domain($domain)
5125: && ($amode ne '')) {
5126: #######################################
5127: ## Add/Modify Users ##
5128: #######################################
5129: if ($context eq 'course') {
5130: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
1.13 raeburn 5131: } elsif ($context eq 'author') {
1.1 raeburn 5132: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
5133: } else {
5134: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
5135: }
1.87 bisitz 5136: $r->rflush;
1.212 raeburn 5137: my (%got_role_approvals,%got_instdoms,%process_by,%instdoms,
1.213 raeburn 5138: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
1.87 bisitz 5139:
1.1 raeburn 5140: my %counts = (
5141: user => 0,
5142: auth => 0,
5143: role => 0,
5144: );
5145: my $flushc=0;
5146: my %student=();
1.42 raeburn 5147: my (%curr_groups,@sections,@cleansec,$defaultwarn,$groupwarn);
1.1 raeburn 5148: my %userchg;
1.27 raeburn 5149: if ($context eq 'course' || $setting eq 'course') {
5150: if ($context eq 'course') {
5151: # Get information about course groups
5152: %curr_groups = &Apache::longroup::coursegroups();
5153: } elsif ($setting eq 'course') {
5154: if ($cid) {
5155: %curr_groups =
5156: &Apache::longroup::coursegroups($env{'form.dcdomain'},
5157: $env{'form.dccourse'});
5158: }
5159: }
5160: # determine section number
5161: if ($defaultsec =~ /,/) {
5162: push(@sections,split(/,/,$defaultsec));
5163: } else {
5164: push(@sections,$defaultsec);
5165: }
5166: # remove non alphanumeric values from section
5167: foreach my $item (@sections) {
5168: $item =~ s/\W//g;
5169: if ($item eq "none" || $item eq 'all') {
5170: $defaultwarn = &mt('Default section name [_1] could not be used as it is a reserved word.',$item);
5171: } elsif ($item ne '' && exists($curr_groups{$item})) {
5172: $groupwarn = &mt('Default section name "[_1]" is the name of a course group. Section names and group names must be distinct.',$item);
5173: } elsif ($item ne '') {
5174: push(@cleansec,$item);
5175: }
5176: }
5177: if ($defaultwarn) {
5178: $r->print($defaultwarn.'<br />');
5179: }
5180: if ($groupwarn) {
5181: $r->print($groupwarn.'<br />');
5182: }
1.1 raeburn 5183: }
1.124 raeburn 5184: my (%curr_rules,%got_rules,%alerts,%cancreate);
1.104 raeburn 5185: my %customroles = &my_custom_roles($crstype);
1.101 raeburn 5186: my @permitted_roles =
1.124 raeburn 5187: &roles_on_upload($context,$setting,$crstype,%customroles);
5188: my %longtypes = &Apache::lonlocal::texthash(
5189: official => 'Institutional',
5190: unofficial => 'Non-institutional',
5191: );
1.135 raeburn 5192: my $newuserdom = $env{'request.role.domain'};
5193: map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes);
1.1 raeburn 5194: # Get new users list
1.200 raeburn 5195: my (%existinguser,%userinfo,%disallow,%rulematch,%inst_results,%alerts,%checkuname,
5196: %showpasswdrules,$haspasswdmap);
1.171 raeburn 5197: my $counter = -1;
1.185 raeburn 5198: my (%willtrust,%trustchecked);
1.27 raeburn 5199: foreach my $line (@userdata) {
1.171 raeburn 5200: $counter ++;
1.42 raeburn 5201: my @secs;
1.27 raeburn 5202: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 5203: # Determine user name
1.128 raeburn 5204: $entries{$fields{'username'}} =~ s/^\s+|\s+$//g;
1.1 raeburn 5205: unless (($entries{$fields{'username'}} eq '') ||
5206: (!defined($entries{$fields{'username'}}))) {
5207: my ($fname, $mname, $lname,$gen) = ('','','','');
5208: if (defined($fields{'names'})) {
5209: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
5210: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
5211: } else {
5212: if (defined($fields{'fname'})) {
5213: $fname=$entries{$fields{'fname'}};
5214: }
5215: if (defined($fields{'mname'})) {
5216: $mname=$entries{$fields{'mname'}};
5217: }
5218: if (defined($fields{'lname'})) {
5219: $lname=$entries{$fields{'lname'}};
5220: }
5221: if (defined($fields{'gen'})) {
5222: $gen=$entries{$fields{'gen'}};
5223: }
5224: }
1.128 raeburn 5225:
1.1 raeburn 5226: if ($entries{$fields{'username'}}
5227: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
1.128 raeburn 5228: my $nowhitespace;
5229: if ($entries{$fields{'username'}} =~ /\s/) {
5230: $nowhitespace = ' - '.&mt('usernames may not contain spaces.');
5231: }
1.171 raeburn 5232: $disallow{$counter} =
1.157 bisitz 5233: &mt('Unacceptable username [_1] for user [_2] [_3] [_4] [_5]',
1.171 raeburn 5234: '"<b>'.$entries{$fields{'username'}}.'</b>"',
5235: $fname,$mname,$lname,$gen).$nowhitespace;
1.27 raeburn 5236: next;
1.1 raeburn 5237: } else {
1.129 raeburn 5238: $entries{$fields{'domain'}} =~ s/^\s+|\s+$//g;
1.71 droeschl 5239: if ($entries{$fields{'domain'}}
1.57 raeburn 5240: ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
1.171 raeburn 5241: $disallow{$counter} =
1.157 bisitz 5242: &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
1.171 raeburn 5243: '"<b>'.$entries{$fields{'domain'}}.'</b>"',
5244: $fname,$mname,$lname,$gen);
5245: next;
1.185 raeburn 5246: } elsif ($entries{$fields{'domain'}} ne $domain) {
5247: my $possdom = $entries{$fields{'domain'}};
5248: if ($context eq 'course' || $setting eq 'course') {
5249: unless ($trustchecked{$possdom}) {
5250: $willtrust{$possdom} = &Apache::lonnet::will_trust('enroll',$domain,$possdom);
5251: $trustchecked{$possdom} = 1;
5252: }
5253: } elsif ($context eq 'author') {
5254: unless ($trustchecked{$possdom}) {
5255: $willtrust{$possdom} = &Apache::lonnet::will_trust('othcoau',$domain,$possdom);
5256: }
5257: if ($willtrust{$possdom}) {
5258: $willtrust{$possdom} = &Apache::lonnet::will_trust('coaurem',$possdom,$domain);
5259: }
5260: }
5261: unless ($willtrust{$possdom}) {
5262: $disallow{$counter} =
5263: &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
5264: '"<b>'.$possdom.'</b>"',
5265: $fname,$mname,$lname,$gen);
5266: next;
5267: }
1.57 raeburn 5268: }
1.5 raeburn 5269: my $username = $entries{$fields{'username'}};
1.57 raeburn 5270: my $userdomain = $entries{$fields{'domain'}};
5271: if ($userdomain eq '') {
5272: $userdomain = $domain;
5273: }
1.27 raeburn 5274: if (defined($fields{'sec'})) {
5275: if (defined($entries{$fields{'sec'}})) {
1.42 raeburn 5276: $entries{$fields{'sec'}} =~ s/\W//g;
1.27 raeburn 5277: my $item = $entries{$fields{'sec'}};
5278: if ($item eq "none" || $item eq 'all') {
1.171 raeburn 5279: $disallow{$counter} =
5280: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a reserved word.',
5281: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item);
1.27 raeburn 5282: next;
5283: } elsif (exists($curr_groups{$item})) {
1.171 raeburn 5284: $disallow{$counter} =
5285: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a course group.',
5286: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item).' '.
5287: &mt('Section names and group names must be distinct.');
1.27 raeburn 5288: next;
5289: } else {
5290: push(@secs,$item);
5291: }
5292: }
5293: }
5294: if ($env{'request.course.sec'} ne '') {
5295: @secs = ($env{'request.course.sec'});
1.57 raeburn 5296: if (ref($userlist{$username.':'.$userdomain}) eq 'ARRAY') {
5297: my $currsec = $userlist{$username.':'.$userdomain}[$secidx];
1.27 raeburn 5298: if ($currsec ne $env{'request.course.sec'}) {
1.171 raeburn 5299: $disallow{$counter} =
5300: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]".',
5301: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$secs[0]);
1.27 raeburn 5302: if ($currsec eq '') {
1.171 raeburn 5303: $disallow{$counter} .=
5304: &mt('This user already has an active/future student role in the course, unaffiliated to any section.');
1.27 raeburn 5305:
5306: } else {
1.171 raeburn 5307: $disallow{$counter} .=
5308: &mt('This user already has an active/future role in section "[_1]" of the course.',$currsec);
1.27 raeburn 5309: }
1.171 raeburn 5310: $disallow{$counter} .=
5311: '<br />'.
5312: &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.',
5313: $secs[0]);
1.27 raeburn 5314: next;
1.1 raeburn 5315: }
5316: }
1.27 raeburn 5317: } elsif ($context eq 'course' || $setting eq 'course') {
5318: if (@secs == 0) {
5319: @secs = @cleansec;
1.1 raeburn 5320: }
5321: }
5322: # determine id number
5323: my $id='';
5324: if (defined($fields{'id'})) {
5325: if (defined($entries{$fields{'id'}})) {
5326: $id=$entries{$fields{'id'}};
5327: }
5328: $id=~tr/A-Z/a-z/;
5329: }
5330: # determine email address
5331: my $email='';
5332: if (defined($fields{'email'})) {
1.129 raeburn 5333: $entries{$fields{'email'}} =~ s/^\s+|\s+$//g;
1.1 raeburn 5334: if (defined($entries{$fields{'email'}})) {
5335: $email=$entries{$fields{'email'}};
1.84 raeburn 5336: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
5337: }
5338: }
5339: # determine affiliation
5340: my $inststatus='';
5341: if (defined($fields{'inststatus'})) {
5342: if (defined($entries{$fields{'inststatus'}})) {
5343: $inststatus=$entries{$fields{'inststatus'}};
5344: }
1.1 raeburn 5345: }
5346: # determine user password
1.200 raeburn 5347: my $password;
5348: my $passwdfromfile;
1.1 raeburn 5349: if (defined($fields{'ipwd'})) {
5350: if ($entries{$fields{'ipwd'}}) {
5351: $password=$entries{$fields{'ipwd'}};
1.200 raeburn 5352: $passwdfromfile = 1;
5353: if ($env{'form.login'} eq 'int') {
5354: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
5355: if (($uhome eq 'no_host') || ($changeauth)) {
5356: my @brokepwdrules =
5357: &Apache::loncommon::check_passwd_rules($domain,$password);
5358: if (@brokepwdrules) {
5359: $disallow{$counter} = &mt('[_1]: Password included in file for this user did not meet requirements.',
5360: '<b>'.$username.'</b>');
5361: map { $showpasswdrules{$_} = 1; } @brokepwdrules;
5362: next;
5363: }
5364: }
5365: }
5366: }
5367: }
5368: unless ($passwdfromfile) {
5369: if ($env{'form.login'} eq 'int') {
5370: if (@genpwdfail) {
5371: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
5372: if (($uhome eq 'no_host') || ($changeauth)) {
5373: $disallow{$counter} = &mt('[_1]: No specific password in file for this user; default password did not meet requirements',
5374: '<b>'.$username.'</b>');
5375: unless ($haspasswdmap) {
5376: map { $showpasswdrules{$_} = 1; } @genpwdfail;
5377: $haspasswdmap = 1;
5378: }
5379: }
5380: next;
5381: }
1.1 raeburn 5382: }
1.200 raeburn 5383: $password = $genpwd;
1.1 raeburn 5384: }
5385: # determine user role
5386: my $role = '';
5387: if (defined($fields{'role'})) {
5388: if ($entries{$fields{'role'}}) {
1.42 raeburn 5389: $entries{$fields{'role'}} =~ s/(\s+$|^\s+)//g;
5390: if ($entries{$fields{'role'}} ne '') {
5391: if (grep(/^\Q$entries{$fields{'role'}}\E$/,@permitted_roles)) {
5392: $role = $entries{$fields{'role'}};
1.27 raeburn 5393: }
5394: }
5395: if ($role eq '') {
5396: my $rolestr = join(', ',@permitted_roles);
1.171 raeburn 5397: $disallow{$counter} =
5398: &mt('[_1]: You do not have permission to add the requested role [_2] for the user.'
5399: ,'<b>'.$entries{$fields{'username'}}.'</b>'
5400: ,$entries{$fields{'role'}})
5401: .'<br />'
5402: .&mt('Allowable role(s) is/are: [_1].',$rolestr);
1.1 raeburn 5403: next;
5404: }
5405: }
5406: }
5407: if ($role eq '') {
5408: $role = $defaultrole;
5409: }
5410: # Clean up whitespace
1.129 raeburn 5411: foreach (\$id,\$fname,\$mname,\$lname,\$gen,\$inststatus) {
1.1 raeburn 5412: $$_ =~ s/(\s+$|^\s+)//g;
5413: }
1.150 raeburn 5414: my $credits;
5415: if ($showcredits) {
5416: if (($role eq 'st') && ($crstype ne 'Community')) {
5417: $credits = $entries{$fields{'credits'}};
5418: if ($credits ne '') {
5419: $credits =~ s/[^\d\.]//g;
5420: }
5421: if ($credits eq '') {
5422: $credits = $commoncredits;
5423: }
5424: if ($credits eq $defaultcredits) {
5425: undef($credits);
5426: }
5427: }
5428: }
1.5 raeburn 5429: # check against rules
5430: my $checkid = 0;
5431: my $newuser = 0;
1.57 raeburn 5432: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
1.5 raeburn 5433: if ($uhome eq 'no_host') {
1.135 raeburn 5434: if ($userdomain ne $newuserdom) {
5435: if ($context eq 'course') {
1.171 raeburn 5436: $disallow{$counter} =
5437: &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
5438: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 5439: } elsif ($context eq 'author') {
1.171 raeburn 5440: $disallow{$counter} =
5441: &mt('[_1]: The domain specified ([_2]) is different to that of the author.',
5442: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 5443: } else {
1.171 raeburn 5444: $disallow{$counter} =
5445: &mt('[_1]: The domain specified ([_2]) is different to that of your current role.',
5446: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 5447: }
1.171 raeburn 5448: $disallow{$counter} .=
5449: &mt('The user does not already exist, and you may not create a new user in a different domain.');
1.124 raeburn 5450: next;
1.171 raeburn 5451: } else {
1.194 raeburn 5452: unless (($password ne '') || ($env{'form.login'} eq 'loc') || ($env{'form.login'} eq 'lti')) {
1.171 raeburn 5453: $disallow{$counter} =
5454: &mt('[_1]: This is a new user but no default password was provided, and the authentication type requires one.',
5455: '<b>'.$username.'</b>');
5456: next;
5457: }
1.124 raeburn 5458: }
1.5 raeburn 5459: $checkid = 1;
5460: $newuser = 1;
1.172 raeburn 5461: $checkuname{$username.':'.$newuserdom} = { 'newuser' => $newuser, 'id' => $id };
1.13 raeburn 5462: } else {
1.27 raeburn 5463: if ($context eq 'course' || $context eq 'author') {
1.57 raeburn 5464: if ($userdomain eq $domain ) {
5465: if ($role eq '') {
5466: my @checkroles;
5467: foreach my $role (@poss_roles) {
5468: my $endkey;
5469: if ($role ne 'st') {
5470: $endkey = ':'.$role;
5471: }
5472: if (exists($userlist{$username.':'.$userdomain.$endkey})) {
5473: if (!grep(/^\Q$role\E$/,@checkroles)) {
5474: push(@checkroles,$role);
5475: }
5476: }
1.27 raeburn 5477: }
1.57 raeburn 5478: if (@checkroles > 0) {
5479: %canmodify = &can_modify_userinfo($context,$domain,\@userinfo,\@checkroles);
1.27 raeburn 5480: }
1.57 raeburn 5481: } elsif (ref($modifiable_fields{$role}) eq 'HASH') {
5482: %canmodify = %{$modifiable_fields{$role}};
1.27 raeburn 5483: }
5484: }
1.57 raeburn 5485: my @newinfo = (\$fname,\$mname,\$lname,\$gen,\$email,\$id);
1.84 raeburn 5486: for (my $i=0; $i<@newinfo; $i++) {
1.57 raeburn 5487: if (${$newinfo[$i]} ne '') {
5488: if (!$canmodify{$userinfo[$i]}) {
5489: ${$newinfo[$i]} = '';
5490: }
1.27 raeburn 5491: }
5492: }
5493: }
1.171 raeburn 5494: if ($id) {
5495: $existinguser{$userdomain}{$username} = $id;
5496: }
1.5 raeburn 5497: }
1.171 raeburn 5498: $userinfo{$counter} = {
5499: username => $username,
5500: domain => $userdomain,
5501: fname => $fname,
5502: mname => $mname,
5503: lname => $lname,
5504: gen => $gen,
5505: email => $email,
5506: id => $id,
5507: password => $password,
5508: inststatus => $inststatus,
5509: role => $role,
5510: sections => \@secs,
5511: credits => $credits,
5512: newuser => $newuser,
5513: checkid => $checkid,
5514: };
5515: }
5516: }
5517: } # end of foreach (@userdata)
5518: if ($counter > -1) {
5519: my $total = $counter + 1;
5520: my %checkids;
1.172 raeburn 5521: if ((keys(%existinguser)) || (keys(%checkuname))) {
5522: $r->print(&mt('Please be patient -- checking for institutional data ...'));
5523: $r->rflush();
5524: if (keys(%existinguser)) {
5525: foreach my $dom (keys(%existinguser)) {
5526: if (ref($existinguser{$dom}) eq 'HASH') {
5527: my %idhash = &Apache::lonnet::idrget($dom,keys(%{$existinguser{$dom}}));
5528: foreach my $username (keys(%{$existinguser{$dom}})) {
5529: if ($idhash{$username} ne $existinguser{$dom}{$username}) {
5530: $checkids{$username.':'.$dom} = {
5531: 'id' => $existinguser{$dom}{$username},
5532: };
5533: }
5534: }
5535: if (keys(%checkids)) {
5536: &Apache::loncommon::user_rule_check(\%checkids,{ 'id' => 1 },
5537: \%alerts,\%rulematch,
5538: \%inst_results,\%curr_rules,
5539: \%got_rules);
1.171 raeburn 5540: }
5541: }
5542: }
5543: }
1.172 raeburn 5544: if (keys(%checkuname)) {
5545: &Apache::loncommon::user_rule_check(\%checkuname,{ 'username' => 1, 'id' => 1, },
5546: \%alerts,\%rulematch,\%inst_results,
5547: \%curr_rules,\%got_rules);
5548: }
5549: $r->print(' '.&mt('done').'<br /><br />');
5550: $r->rflush();
1.171 raeburn 5551: }
1.172 raeburn 5552: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,$total);
1.171 raeburn 5553: $r->print('<ul>');
5554: for (my $i=0; $i<=$counter; $i++) {
5555: if ($disallow{$i}) {
5556: $r->print('<li>'.$disallow{$i}.'</li>');
5557: } elsif (ref($userinfo{$i}) eq 'HASH') {
5558: my $password = $userinfo{$i}{'password'};
5559: my $newuser = $userinfo{$i}{'newuser'};
5560: my $checkid = $userinfo{$i}{'checkid'};
5561: my $id = $userinfo{$i}{'id'};
5562: my $role = $userinfo{$i}{'role'};
5563: my @secs;
5564: if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
5565: @secs = @{$userinfo{$i}{'sections'}};
5566: }
5567: my $fname = $userinfo{$i}{'fname'};
5568: my $mname = $userinfo{$i}{'mname'};
5569: my $lname = $userinfo{$i}{'lname'};
5570: my $gen = $userinfo{$i}{'gen'};
5571: my $email = $userinfo{$i}{'email'};
5572: my $inststatus = $userinfo{$i}{'inststatus'};
5573: my $credits = $userinfo{$i}{'credits'};
5574: my $username = $userinfo{$i}{'username'};
5575: my $userdomain = $userinfo{$i}{'domain'};
5576: my $user = $username.':'.$userdomain;
5577: if ($newuser) {
5578: if (ref($alerts{'username'}) eq 'HASH') {
5579: if (ref($alerts{'username'}{$userdomain}) eq 'HASH') {
5580: if ($alerts{'username'}{$userdomain}{$username}) {
5581: $r->print('<li>'.
5582: &mt('[_1]: matches the username format at your institution, but is not known to your directory service.','<b>'.$username.'</b>').'<br />'.
5583: &mt('Consequently, the user was not created.').'</li>');
5584: next;
5585: }
5586: }
5587: }
1.172 raeburn 5588: if (ref($inst_results{$user}) eq 'HASH') {
5589: if ($inst_results{$user}{'firstname'} ne '') {
5590: $fname = $inst_results{$user}{'firstname'};
5591: }
5592: if ($inst_results{$user}{'middlename'} ne '') {
5593: $mname = $inst_results{$user}{'middlename'};
5594: }
5595: if ($inst_results{$user}{'lasttname'} ne '') {
5596: $lname = $inst_results{$user}{'lastname'};
5597: }
5598: if ($inst_results{$user}{'permanentemail'} ne '') {
5599: $email = $inst_results{$user}{'permanentemail'};
5600: }
5601: if ($inst_results{$user}{'id'} ne '') {
5602: $id = $inst_results{$user}{'id'};
5603: $checkid = 0;
5604: }
5605: if (ref($inst_results{$user}{'inststatus'}) eq 'ARRAY') {
5606: $inststatus = join(':',@{$inst_results{$user}{'inststatus'}});
5607: }
5608: }
5609: if (($checkid) && ($id ne '')) {
5610: if (ref($alerts{'id'}) eq 'HASH') {
5611: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
5612: if ($alerts{'id'}{$userdomain}{$username}) {
5613: $r->print('<li>'.
5614: &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
5615: '<b>'.$username.'</b>').'<br />'.
5616: &mt('Consequently, the user was not created.').'</li>');
5617: next;
5618: }
5619: }
5620: }
5621: }
1.171 raeburn 5622: my $usertype = 'unofficial';
5623: if (ref($rulematch{$user}) eq 'HASH') {
5624: if ($rulematch{$user}{'username'}) {
5625: $usertype = 'official';
1.5 raeburn 5626: }
5627: }
1.171 raeburn 5628: unless ($cancreate{$usertype}) {
5629: my $showtype = $longtypes{$usertype};
5630: $r->print('<li>'.
5631: &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].','<b>'.$username.'</b>',$showtype).'</li>');
5632: next;
5633: }
1.172 raeburn 5634: } elsif ($id ne '') {
1.171 raeburn 5635: if (exists($checkids{$user})) {
5636: $checkid = 1;
1.5 raeburn 5637: if (ref($alerts{'id'}) eq 'HASH') {
1.57 raeburn 5638: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
1.172 raeburn 5639: if ($alerts{'id'}{$userdomain}{$username}) {
1.171 raeburn 5640: $r->print('<li>'.
1.172 raeburn 5641: &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 5642: '<b>'.$username.'</b>').'<br />'.
1.172 raeburn 5643: &mt('Consequently, the ID was not changed.').'</li>');
5644: $id = '';
1.124 raeburn 5645: }
1.5 raeburn 5646: }
5647: }
5648: }
5649: }
1.171 raeburn 5650: my $multiple = 0;
5651: my ($userresult,$authresult,$roleresult,$idresult);
5652: my (%userres,%authres,%roleres,%idres);
5653: my $singlesec = '';
5654: if ($role eq 'st') {
1.206 raeburn 5655: if (($context eq 'domain') && ($changeauth eq 'Yes') && (!$newuser)) {
5656: if ((&Apache::lonnet::allowed('mau',$userdomain)) &&
5657: (&Apache::lonnet::homeserver($username,$userdomain) ne 'no_host')) {
5658: if ((($amode =~ /^krb4|krb5|internal$/) && $password ne '') ||
5659: ($amode eq 'localauth')) {
5660: $authresult =
5661: &Apache::lonnet::modifyuserauth($userdomain,$username,$amode,$password);
5662: }
5663: }
5664: }
1.171 raeburn 5665: my $sec;
5666: if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
1.42 raeburn 5667: if (@secs > 0) {
5668: $sec = $secs[0];
1.27 raeburn 5669: }
1.171 raeburn 5670: }
1.212 raeburn 5671: if ($userdomain ne $env{'request.role.domain'}) {
5672: my $item = "/$crsdom/$crsnum" ;
5673: if ($sec ne '') {
5674: $item .= "/$sec";
5675: }
5676: $item .= '_st';
5677: next if (&restricted_dom($context,$item,$userdomain,$username,$role,$startdate,
5678: $enddate,$crsdom,$crsnum,$sec,$credits,\%process_by,
5679: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.213 raeburn 5680: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.212 raeburn 5681: }
1.171 raeburn 5682: &modifystudent($userdomain,$username,$cid,$sec,
5683: $desiredhost,$context);
5684: $roleresult =
5685: &Apache::lonnet::modifystudent
5686: ($userdomain,$username,$id,$amode,$password,
5687: $fname,$mname,$lname,$gen,$sec,$enddate,
5688: $startdate,$env{'form.forceid'},
5689: $desiredhost,$email,'manual','',$cid,
5690: '',$context,$inststatus,$credits);
5691: $userresult = $roleresult;
5692: } else {
1.212 raeburn 5693: my $possrole;
5694: if ($role ne '') {
1.171 raeburn 5695: if ($context eq 'course' || $setting eq 'course') {
5696: if ($customroles{$role}) {
5697: $role = 'cr_'.$env{'user.domain'}.'_'.
5698: $env{'user.name'}.'_'.$role;
5699: }
1.212 raeburn 5700: $possrole = $role;
5701: if ($possrole =~ /^cr_/) {
5702: $possrole =~ s{_}{/}g;
5703: }
5704: if (($role ne 'cc') && ($role ne 'co')) {
1.171 raeburn 5705: if (@secs > 1) {
5706: $multiple = 1;
1.212 raeburn 5707: my $prefix = "/$crsdom/$crsnum";
1.171 raeburn 5708: foreach my $sec (@secs) {
1.212 raeburn 5709: if ($userdomain ne $env{'request.role.domain'}) {
5710: my $item = $prefix;
5711: if ($sec ne '') {
5712: $item .= "/$sec";
5713: }
5714: $item .= '_'.$possrole;
5715: next if (&restricted_dom($context,$item,$userdomain,$username,$possrole,
5716: $startdate,$enddate,$crsdom,$crsnum,$sec,
5717: $credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 5718: \%got_instdoms,\%reject,\%pending,\%notifydc,
5719: \%status,\%unauthorized,\%currqueued));
1.212 raeburn 5720: }
1.171 raeburn 5721: ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
5722: &modifyuserrole($context,$setting,
5723: $changeauth,$cid,$userdomain,$username,
5724: $id,$amode,$password,$fname,
5725: $mname,$lname,$gen,$sec,
5726: $env{'form.forceid'},$desiredhost,
5727: $email,$role,$enddate,
5728: $startdate,$checkid,$inststatus);
1.42 raeburn 5729: }
1.171 raeburn 5730: } elsif (@secs > 0) {
5731: $singlesec = $secs[0];
1.27 raeburn 5732: }
5733: }
1.212 raeburn 5734: } else {
5735: $possrole = $role;
1.27 raeburn 5736: }
1.204 raeburn 5737: }
5738: if (!$multiple) {
1.212 raeburn 5739: if (($userdomain ne $env{'request.role.domain'}) && ($role ne '')) {
5740: my $item = "/$crsdom/$crsnum";
5741: if ($singlesec ne '') {
5742: $item .= "/$singlesec";
5743: }
5744: $item .= '_'.$possrole;
5745: next if (&restricted_dom($context,$item,$userdomain,$username,$possrole,$startdate,$enddate,
5746: $crsdom,$crsnum,$singlesec,$credits,\%process_by,\%instdoms,
1.213 raeburn 5747: \%got_role_approvals,\%got_instdoms,\%reject,\%pending,\%notifydc,
5748: \%status,\%unauthorized,\%currqueued));
1.212 raeburn 5749: }
1.204 raeburn 5750: ($userresult,$authresult,$roleresult,$idresult) =
5751: &modifyuserrole($context,$setting,
5752: $changeauth,$cid,$userdomain,$username,
5753: $id,$amode,$password,$fname,
5754: $mname,$lname,$gen,$singlesec,
5755: $env{'form.forceid'},$desiredhost,
5756: $email,$role,$enddate,$startdate,
1.220 raeburn 5757: $checkid,$inststatus,\%emptyok);
1.27 raeburn 5758: }
1.171 raeburn 5759: }
5760: if ($multiple) {
5761: foreach my $sec (sort(keys(%userres))) {
5762: $flushc =
1.27 raeburn 5763: &user_change_result($r,$userres{$sec},$authres{$sec},
5764: $roleres{$sec},$idres{$sec},\%counts,$flushc,
1.57 raeburn 5765: $username,$userdomain,\%userchg);
1.27 raeburn 5766:
1.1 raeburn 5767: }
5768: } else {
1.171 raeburn 5769: $flushc =
5770: &user_change_result($r,$userresult,$authresult,
5771: $roleresult,$idresult,\%counts,$flushc,
5772: $username,$userdomain,\%userchg);
1.1 raeburn 5773: }
5774: }
1.172 raeburn 5775: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last user');
1.171 raeburn 5776: } # end of loop
1.172 raeburn 5777: $r->print('</ul>');
1.171 raeburn 5778: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.217 raeburn 5779: if (($context eq 'domain') && ($setting eq 'course')) {
5780: unless ($oldcrsuserdoms) {
5781: if (exists($env{'course.'.$cid.'.internal.userdomains'})) {
5782: delete($env{'course.'.$cid.'.internal.userdomains'});
5783: }
5784: }
5785: }
1.171 raeburn 5786: }
1.1 raeburn 5787: # Flush the course logs so reverse user roles immediately updated
1.126 raeburn 5788: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.29 raeburn 5789: $r->print("</p>\n<p>\n".&mt('Processed [quant,_1,user].',$counts{'user'}).
1.1 raeburn 5790: "</p>\n");
5791: if ($counts{'role'} > 0) {
5792: $r->print("<p>\n".
1.192 raeburn 5793: &mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.
5794: &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.').
5795: "</p>\n");
1.29 raeburn 5796: } else {
5797: $r->print('<p>'.&mt('No roles added').'</p>');
1.1 raeburn 5798: }
5799: if ($counts{'auth'} > 0) {
5800: $r->print("<p>\n".
5801: &mt('Authentication changed for [_1] existing users.',
5802: $counts{'auth'})."</p>\n");
5803: }
1.13 raeburn 5804: $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
1.200 raeburn 5805: $r->print(&passwdrule_alerts($domain,\%showpasswdrules));
1.213 raeburn 5806: if ((keys(%reject)) || (keys(%unauthorized))) {
5807: $r->print(&print_roles_rejected($context,\%reject,\%unauthorized));
1.212 raeburn 5808: }
1.213 raeburn 5809: if ((keys(%pending)) || (keys(%currqueued))) {
5810: $r->print(&print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.212 raeburn 5811: }
1.1 raeburn 5812: #####################################
1.29 raeburn 5813: # Display list of students to drop #
1.1 raeburn 5814: #####################################
5815: if ($env{'form.fullup'} eq 'yes') {
1.29 raeburn 5816: $r->print('<h3>'.&mt('Students to Drop')."</h3>\n");
1.1 raeburn 5817: # Get current classlist
1.30 raeburn 5818: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 5819: if (! defined($classlist)) {
1.192 raeburn 5820: $r->print('<p class="LC_info">'.
5821: &mt('There are no students with current/future access to the course.').
5822: '</p>'."\n");
1.66 raeburn 5823: } elsif (ref($classlist) eq 'HASH') {
1.1 raeburn 5824: # Remove the students we just added from the list of students.
1.30 raeburn 5825: foreach my $line (@userdata) {
5826: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 5827: unless (($entries{$fields{'username'}} eq '') ||
5828: (!defined($entries{$fields{'username'}}))) {
5829: delete($classlist->{$entries{$fields{'username'}}.
5830: ':'.$domain});
5831: }
5832: }
5833: # Print out list of dropped students.
1.30 raeburn 5834: &show_drop_list($r,$classlist,'nosort',$permission);
1.1 raeburn 5835: }
5836: }
5837: } # end of unless
1.193 raeburn 5838: return 'ok';
1.1 raeburn 5839: }
5840:
1.13 raeburn 5841: sub print_namespacing_alerts {
5842: my ($domain,$alerts,$curr_rules) = @_;
5843: my $output;
5844: if (ref($alerts) eq 'HASH') {
5845: if (keys(%{$alerts}) > 0) {
5846: if (ref($alerts->{'username'}) eq 'HASH') {
5847: foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
5848: my $count;
5849: if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
5850: $count = keys(%{$alerts->{'username'}{$dom}});
5851: }
5852: my $domdesc = &Apache::lonnet::domain($domain,'description');
5853: if (ref($curr_rules->{$dom}) eq 'HASH') {
5854: $output .= &Apache::loncommon::instrule_disallow_msg(
5855: 'username',$domdesc,$count,'upload');
5856: }
5857: $output .= &Apache::loncommon::user_rule_formats($dom,
5858: $domdesc,$curr_rules->{$dom}{'username'},
5859: 'username');
5860: }
5861: }
5862: if (ref($alerts->{'id'}) eq 'HASH') {
5863: foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
5864: my $count;
5865: if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
5866: $count = keys(%{$alerts->{'id'}{$dom}});
5867: }
5868: my $domdesc = &Apache::lonnet::domain($domain,'description');
5869: if (ref($curr_rules->{$dom}) eq 'HASH') {
5870: $output .= &Apache::loncommon::instrule_disallow_msg(
5871: 'id',$domdesc,$count,'upload');
5872: }
5873: $output .= &Apache::loncommon::user_rule_formats($dom,
5874: $domdesc,$curr_rules->{$dom}{'id'},'id');
5875: }
5876: }
5877: }
5878: }
5879: }
5880:
1.200 raeburn 5881: sub passwdrule_alerts {
5882: my ($domain,$passwdrules) = @_;
5883: my $warning;
5884: if (ref($passwdrules) eq 'HASH') {
5885: my %showrules = %{$passwdrules};
5886: if (keys(%showrules)) {
5887: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
5888: $warning = '<b>'.&mt('Password requirement(s) unmet for one or more users:').'</b><ul>';
5889: if ($showrules{'min'}) {
1.208 raeburn 5890: my $min = $passwdconf{'min'};
5891: if ($min eq '') {
5892: $min = $Apache::lonnet::passwdmin;
5893: }
5894: $warning .= '<li>'.&mt('minimum [quant,_1,character]',$min).'</li>';
1.200 raeburn 5895: }
5896: if ($showrules{'max'}) {
5897: $warning .= '<li>'.&mt('maximum [quant,_1,character]',$passwdconf{'max'}).'</li>';
5898: }
5899: if ($showrules{'uc'}) {
5900: $warning .= '<li>'.&mt('contain at least one upper case letter').'</li>';
5901: }
5902: if ($showrules{'lc'}) {
5903: $warning .= '<li>'.&mt('contain at least one lower case letter').'</li>';
5904: }
5905: if ($showrules{'num'}) {
5906: $warning .= '<li>'.&mt('contain at least one number').'</li>';
5907: }
5908: if ($showrules{'spec'}) {
5909: $warning .= '<li>'.&mt('contain at least one non-alphanumeric').'</li>';
5910: }
5911: $warning .= '</ul>';
5912: }
5913: }
5914: return $warning;
5915: }
5916:
1.1 raeburn 5917: sub user_change_result {
1.29 raeburn 5918: my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
1.57 raeburn 5919: $username,$userdomain,$userchg) = @_;
1.1 raeburn 5920: my $okresult = 0;
1.171 raeburn 5921: my @status;
1.1 raeburn 5922: if ($userresult ne 'ok') {
5923: if ($userresult =~ /^error:(.+)$/) {
5924: my $error = $1;
1.171 raeburn 5925: push(@status,
5926: &mt('[_1]: Unable to add/modify: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5927: }
5928: } else {
5929: $counts->{'user'} ++;
5930: $okresult = 1;
5931: }
5932: if ($authresult ne 'ok') {
5933: if ($authresult =~ /^error:(.+)$/) {
5934: my $error = $1;
1.171 raeburn 5935: push(@status,
5936: &mt('[_1]: Unable to modify authentication: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5937: }
5938: } else {
5939: $counts->{'auth'} ++;
5940: $okresult = 1;
5941: }
5942: if ($roleresult ne 'ok') {
5943: if ($roleresult =~ /^error:(.+)$/) {
5944: my $error = $1;
1.171 raeburn 5945: push(@status,
5946: &mt('[_1]: Unable to add role: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5947: }
5948: } else {
5949: $counts->{'role'} ++;
5950: $okresult = 1;
5951: }
5952: if ($okresult) {
5953: $flushc++;
1.57 raeburn 5954: $userchg->{$username.':'.$userdomain}=1;
1.1 raeburn 5955: if ($flushc>15) {
5956: $r->rflush;
5957: $flushc=0;
5958: }
5959: }
1.29 raeburn 5960: if ($idresult) {
1.171 raeburn 5961: push(@status,$idresult);
5962: }
5963: if (@status) {
5964: $r->print('<li>'.join('<br />',@status).'</li>');
1.29 raeburn 5965: }
1.1 raeburn 5966: return $flushc;
5967: }
5968:
5969: # ========================================================= Menu Phase Two Drop
1.17 raeburn 5970: sub print_drop_menu {
1.101 raeburn 5971: my ($r,$context,$permission,$crstype) = @_;
5972: my $heading;
5973: if ($crstype eq 'Community') {
5974: $heading = &mt("Drop Members");
5975: } else {
5976: $heading = &mt("Drop Students");
5977: }
5978: $r->print('<h3>'.$heading.'</h3>'."\n".
1.153 bisitz 5979: '<form name="studentform" method="post" action="">'."\n");
1.30 raeburn 5980: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 5981: if (! defined($classlist)) {
1.143 bisitz 5982: my $msg = '';
1.101 raeburn 5983: if ($crstype eq 'Community') {
1.143 bisitz 5984: $msg = &mt('There are no members currently enrolled.');
1.101 raeburn 5985: } else {
1.143 bisitz 5986: $msg = &mt('There are no students currently enrolled.');
1.101 raeburn 5987: }
1.143 bisitz 5988: $r->print('<p class="LC_info">'.$msg."</p>\n");
1.30 raeburn 5989: } else {
1.101 raeburn 5990: &show_drop_list($r,$classlist,'nosort',$permission,$crstype);
1.1 raeburn 5991: }
1.162 bisitz 5992: $r->print('</form>');
1.1 raeburn 5993: return;
5994: }
5995:
5996: # ================================================================== Phase four
5997:
1.11 raeburn 5998: sub update_user_list {
1.118 raeburn 5999: my ($r,$context,$setting,$choice,$crstype) = @_;
1.11 raeburn 6000: my $now = time;
1.1 raeburn 6001: my $count=0;
1.101 raeburn 6002: if ($context eq 'course') {
6003: $crstype = &Apache::loncommon::course_type();
6004: }
1.212 raeburn 6005: my (@changelist,%got_role_approvals,%got_instdoms,%process_by,%instdoms,
1.213 raeburn 6006: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
1.29 raeburn 6007: if ($choice eq 'drop') {
6008: @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
6009: } else {
1.11 raeburn 6010: @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
6011: }
6012: my %result_text = ( ok => { 'revoke' => 'Revoked',
6013: 'delete' => 'Deleted',
6014: 'reenable' => 'Re-enabled',
1.17 raeburn 6015: 'activate' => 'Activated',
6016: 'chgdates' => 'Changed Access Dates for',
1.118 raeburn 6017: 'chgsec' => 'Changed section(s) for',
1.17 raeburn 6018: 'drop' => 'Dropped',
1.11 raeburn 6019: },
6020: error => {'revoke' => 'revoking',
6021: 'delete' => 'deleting',
6022: 'reenable' => 're-enabling',
6023: 'activate' => 'activating',
1.17 raeburn 6024: 'chgdates' => 'changing access dates for',
6025: 'chgsec' => 'changing section for',
6026: 'drop' => 'dropping',
1.11 raeburn 6027: },
6028: );
6029: my ($startdate,$enddate);
6030: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
6031: ($startdate,$enddate) = &get_dates_from_form();
6032: }
6033: foreach my $item (@changelist) {
1.118 raeburn 6034: my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,
6035: @sections,$scopestem,$singlesec,$showsecs,$warn_singlesec,
1.212 raeburn 6036: $nothingtodo,$keepnosection,$credits,$instsec,$cdom,$cnum);
1.17 raeburn 6037: if ($choice eq 'drop') {
6038: ($uname,$udom,$sec) = split(/:/,$item,-1);
6039: $role = 'st';
6040: $cid = $env{'request.course.id'};
6041: $scopestem = '/'.$cid;
6042: $scopestem =~s/\_/\//g;
6043: if ($sec eq '') {
6044: $scope = $scopestem;
6045: } else {
6046: $scope = $scopestem.'/'.$sec;
6047: }
6048: } elsif ($context eq 'course') {
1.174 raeburn 6049: ($uname,$udom,$role,$sec,$type,$locktype,$credits,$instsec) =
6050: split(/\:/,$item,8);
6051: $instsec = &unescape($instsec);
1.11 raeburn 6052: $cid = $env{'request.course.id'};
1.212 raeburn 6053: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6054: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.11 raeburn 6055: $scopestem = '/'.$cid;
6056: $scopestem =~s/\_/\//g;
6057: if ($sec eq '') {
6058: $scope = $scopestem;
6059: } else {
6060: $scope = $scopestem.'/'.$sec;
6061: }
1.13 raeburn 6062: } elsif ($context eq 'author') {
1.11 raeburn 6063: ($uname,$udom,$role) = split(/\:/,$item,-1);
6064: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
1.212 raeburn 6065: $cdom = $env{'user.domain'};
6066: $cnum = $env{'user.name'};
1.11 raeburn 6067: } elsif ($context eq 'domain') {
6068: if ($setting eq 'domain') {
6069: ($role,$uname,$udom) = split(/\:/,$item,-1);
6070: $scope = '/'.$env{'request.role.domain'}.'/';
1.212 raeburn 6071: $cdom = $env{'request.role.domain'};
1.13 raeburn 6072: } elsif ($setting eq 'author') {
1.11 raeburn 6073: ($uname,$udom,$role,$scope) = split(/\:/,$item);
1.212 raeburn 6074: (undef,$cdom,$cnum) = split(/\//,$scope);
1.11 raeburn 6075: } elsif ($setting eq 'course') {
1.174 raeburn 6076: ($uname,$udom,$role,$cid,$sec,$type,$locktype,$credits,$instsec) =
6077: split(/\:/,$item,9);
1.212 raeburn 6078: ($cdom,$cnum) = split('_',$cid);
1.174 raeburn 6079: $instsec = &unescape($instsec);
1.11 raeburn 6080: $scope = '/'.$cid;
6081: $scope =~s/\_/\//g;
6082: if ($sec ne '') {
6083: $scope .= '/'.$sec;
6084: }
6085: }
6086: }
1.101 raeburn 6087: my $plrole = &Apache::lonnet::plaintext($role,$crstype);
1.11 raeburn 6088: my $start = $env{'form.'.$item.'_start'};
6089: my $end = $env{'form.'.$item.'_end'};
1.17 raeburn 6090: if ($choice eq 'drop') {
6091: # drop students
6092: $end = $now;
6093: $type = 'manual';
6094: $result =
1.52 raeburn 6095: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.17 raeburn 6096: } elsif ($choice eq 'revoke') {
6097: # revoke or delete user role
1.11 raeburn 6098: $end = $now;
6099: if ($role eq 'st') {
6100: $result =
1.174 raeburn 6101: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.11 raeburn 6102: } else {
6103: $result =
1.52 raeburn 6104: &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
6105: '','',$context);
1.11 raeburn 6106: }
6107: } elsif ($choice eq 'delete') {
6108: if ($role eq 'st') {
1.174 raeburn 6109: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.29 raeburn 6110: }
6111: $result =
6112: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
1.52 raeburn 6113: $start,1,'',$context);
1.11 raeburn 6114: } else {
6115: #reenable, activate, change access dates or change section
6116: if ($choice ne 'chgsec') {
6117: $start = $startdate;
6118: $end = $enddate;
6119: }
1.212 raeburn 6120: my $id = $scope.'_'.$role;
1.11 raeburn 6121: if ($choice eq 'reenable') {
1.212 raeburn 6122: next if (&restricted_dom($context,$id,$udom,$uname,$role,$now,$end,$cdom,$cnum,
6123: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 6124: \%got_instdoms,\%reject,\%pending,\%notifydc,
6125: \%status,\%unauthorized,\%currqueued));
1.11 raeburn 6126: if ($role eq 'st') {
1.174 raeburn 6127: $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 6128: } else {
6129: $result =
6130: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 6131: $now,'','',$context);
1.11 raeburn 6132: }
6133: } elsif ($choice eq 'activate') {
1.212 raeburn 6134: next if (&restricted_dom($context,$id,$udom,$uname,$role,$now,$end,$cdom,$cnum,
6135: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 6136: \%got_instdoms,\%reject,\%pending,\%notifydc,
6137: \%status,\%unauthorized,\%currqueued));
1.11 raeburn 6138: if ($role eq 'st') {
1.174 raeburn 6139: $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 6140: } else {
6141: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 6142: $now,'','',$context);
1.11 raeburn 6143: }
6144: } elsif ($choice eq 'chgdates') {
1.212 raeburn 6145: next if (&restricted_dom($context,$id,$udom,$uname,$role,$start,$end,$cdom,$cnum,
6146: $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
1.213 raeburn 6147: \%got_instdoms,\%reject,\%pending,\%notifydc,
6148: \%status,\%unauthorized,\%currqueued));
1.11 raeburn 6149: if ($role eq 'st') {
1.174 raeburn 6150: $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 6151: } else {
6152: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 6153: $start,'','',$context);
1.11 raeburn 6154: }
6155: } elsif ($choice eq 'chgsec') {
6156: my (@newsecs,$revresult,$nochg,@retained);
1.103 raeburn 6157: if (($role ne 'cc') && ($role ne 'co')) {
1.117 raeburn 6158: my @secs = sort(split(/,/,$env{'form.newsecs'}));
6159: if (@secs) {
6160: my %curr_groups = &Apache::longroup::coursegroups();
6161: foreach my $sec (@secs) {
6162: next if (($sec =~ /\W/) || ($sec eq 'none') ||
6163: (exists($curr_groups{$sec})));
6164: push(@newsecs,$sec);
6165: }
6166: }
1.11 raeburn 6167: }
6168: # remove existing section if not to be retained.
1.118 raeburn 6169: if (!$env{'form.retainsec'} || ($role eq 'st')) {
1.11 raeburn 6170: if ($sec eq '') {
6171: if (@newsecs == 0) {
1.118 raeburn 6172: $result = 'ok';
1.11 raeburn 6173: $nochg = 1;
1.118 raeburn 6174: $nothingtodo = 1;
1.40 raeburn 6175: } else {
6176: $revresult =
6177: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 6178: $scope,$role,
6179: '','',$context);
1.40 raeburn 6180: }
1.11 raeburn 6181: } else {
1.28 raeburn 6182: if (@newsecs > 0) {
6183: if (grep(/^\Q$sec\E$/,@newsecs)) {
6184: push(@retained,$sec);
6185: } else {
6186: $revresult =
6187: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 6188: $scope,$role,
6189: '','',$context);
1.28 raeburn 6190: }
6191: } else {
1.11 raeburn 6192: $revresult =
1.28 raeburn 6193: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 6194: $scope,$role,
6195: '','',$context);
1.11 raeburn 6196: }
6197: }
6198: } else {
1.28 raeburn 6199: if ($sec eq '') {
6200: $nochg = 1;
1.118 raeburn 6201: $keepnosection = 1;
6202: } else {
1.28 raeburn 6203: push(@retained,$sec);
6204: }
1.11 raeburn 6205: }
6206: # add new sections
1.118 raeburn 6207: my (@diffs,@shownew);
6208: if (@retained) {
6209: @diffs = &Apache::loncommon::compare_arrays(\@retained,\@newsecs);
6210: } else {
6211: @diffs = @newsecs;
6212: }
1.11 raeburn 6213: if (@newsecs == 0) {
1.118 raeburn 6214: if ($nochg) {
6215: $result = 'ok';
6216: $nothingtodo = 1;
6217: } else {
1.28 raeburn 6218: if ($role eq 'st') {
6219: $result =
1.174 raeburn 6220: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.28 raeburn 6221: } else {
6222: my $newscope = $scopestem;
1.52 raeburn 6223: $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
1.11 raeburn 6224: }
6225: }
1.118 raeburn 6226: $showsecs = &mt('No section');
6227: } elsif (@diffs == 0) {
6228: $result = 'ok';
6229: $nothingtodo = 1;
1.11 raeburn 6230: } else {
1.118 raeburn 6231: foreach my $newsec (@newsecs) {
1.11 raeburn 6232: if (!grep(/^\Q$newsec\E$/,@retained)) {
6233: if ($role eq 'st') {
1.174 raeburn 6234: $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 6235: if (@newsecs > 1) {
6236: my $showsingle;
6237: if ($newsec eq '') {
6238: $showsingle = &mt('No section');
6239: } else {
6240: $showsingle = $newsec;
6241: }
6242: if ($crstype eq 'Community') {
6243: $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>');
6244: } else {
6245: $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>');
6246: }
6247: $showsecs = $showsingle;
6248: last;
6249: } else {
6250: if ($newsec eq '') {
6251: $showsecs = &mt('No section');
6252: } else {
6253: $showsecs = $newsec;
6254: }
6255: }
1.11 raeburn 6256: } else {
6257: my $newscope = $scopestem;
6258: if ($newsec ne '') {
6259: $newscope .= '/'.$newsec;
1.118 raeburn 6260: push(@shownew,$newsec);
1.11 raeburn 6261: }
6262: $result = &Apache::lonnet::assignrole($udom,$uname,
6263: $newscope,$role,$end,$start);
1.118 raeburn 6264:
1.11 raeburn 6265: }
6266: }
6267: }
6268: }
1.118 raeburn 6269: unless ($role eq 'st') {
6270: unless ($showsecs) {
6271: my @tolist = sort(@shownew,@retained);
6272: if ($keepnosection) {
6273: push(@tolist,&mt('No section'));
6274: }
6275: $showsecs = join(', ',@tolist);
6276: }
6277: }
1.11 raeburn 6278: }
6279: }
1.17 raeburn 6280: my $extent = $scope;
6281: if ($choice eq 'drop' || $context eq 'course') {
6282: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
6283: if ($cdesc) {
6284: $extent = $cdesc;
6285: }
6286: }
1.1 raeburn 6287: if ($result eq 'ok' || $result eq 'ok:') {
1.118 raeburn 6288: my $dates;
6289: if (($choice eq 'chgsec') || ($choice eq 'chgdates')) {
6290: $dates = &dates_feedback($start,$end,$now);
6291: }
6292: if ($choice eq 'chgsec') {
6293: if ($nothingtodo) {
6294: $r->print(&mt("Section assignment for role of '[_1]' in [_2] for '[_3]' unchanged.",$plrole,$extent,'<i>'.
6295: &Apache::loncommon::plainname($uname,$udom).
6296: '</i>').' ');
6297: if ($sec eq '') {
6298: $r->print(&mt('[_1]No section[_2] - [_3]','<b>','</b>',$dates));
6299: } else {
6300: $r->print(&mt('Section(s): [_1] - [_2]',
6301: '<b>'.$showsecs.'</b>',$dates));
6302: }
6303: $r->print('<br />');
6304: } else {
6305: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' to [_4] - [_5]",$plrole,$extent,
6306: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
6307: '<b>'.$showsecs.'</b>',$dates).'<br />');
6308: $count ++;
6309: }
6310: if ($warn_singlesec) {
6311: $r->print('<div class="LC_warning">'.$warn_singlesec.'</div>');
6312: }
6313: } elsif ($choice eq 'chgdates') {
6314: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' - [_4]",$plrole,$extent,
1.121 raeburn 6315: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
1.118 raeburn 6316: $dates).'<br />');
6317: $count ++;
6318: } else {
6319: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]'.",$plrole,$extent,
1.121 raeburn 6320: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>').
1.118 raeburn 6321: '<br />');
6322: $count ++;
6323: }
1.1 raeburn 6324: } else {
6325: $r->print(
1.118 raeburn 6326: &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for '[_3]': [_4].",
6327: $plrole,$extent,
1.121 raeburn 6328: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
1.118 raeburn 6329: $result).'<br />');
1.11 raeburn 6330: }
6331: }
1.32 raeburn 6332: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
1.33 raeburn 6333: if ($choice eq 'drop') {
6334: $r->print('<input type="hidden" name="action" value="listusers" />'."\n".
6335: '<input type="hidden" name="Status" value="Active" />'."\n".
6336: '<input type="hidden" name="showrole" value="st" />'."\n");
6337: } else {
6338: foreach my $item ('action','sortby','roletype','showrole','Status','secfilter','grpfilter') {
6339: if ($env{'form.'.$item} ne '') {
6340: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.
6341: '" />'."\n");
6342: }
1.32 raeburn 6343: }
6344: }
1.144 bisitz 6345: $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} [quant,_1,user role,user roles,no user roles].",$count).'</b></p>');
1.11 raeburn 6346: if ($count > 0) {
1.17 raeburn 6347: if ($choice eq 'revoke' || $choice eq 'drop') {
1.74 bisitz 6348: $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>');
1.11 raeburn 6349: }
6350: # Flush the course logs so reverse user roles immediately updated
1.126 raeburn 6351: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.11 raeburn 6352: }
6353: if ($env{'form.makedatesdefault'}) {
6354: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
1.101 raeburn 6355: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
1.1 raeburn 6356: }
6357: }
1.213 raeburn 6358: if ((keys(%reject)) || (keys(%unauthorized))) {
6359: $r->print(&print_roles_rejected($context,\%reject,\%unauthorized));
1.212 raeburn 6360: }
1.213 raeburn 6361: if ((keys(%pending)) || (keys(%currqueued))) {
6362: $r->print(&print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.212 raeburn 6363: }
1.33 raeburn 6364: my $linktext = &mt('Display User Lists');
6365: if ($choice eq 'drop') {
6366: $linktext = &mt('Display current class roster');
6367: }
1.144 bisitz 6368: $r->print(
6369: &Apache::lonhtmlcommon::actionbox(
6370: ['<a href="javascript:document.studentform.submit()">'.$linktext.'</a>'])
6371: .'</form>'."\n");
1.1 raeburn 6372: }
6373:
1.118 raeburn 6374: sub dates_feedback {
6375: my ($start,$end,$now) = @_;
6376: my $dates;
6377: if ($start < $now) {
6378: if ($end == 0) {
1.147 bisitz 6379: $dates = &mt('role(s) active now; no end date');
1.118 raeburn 6380: } elsif ($end > $now) {
6381: $dates = &mt('role(s) active now; ends [_1].',&Apache::lonlocal::locallocaltime($end));
6382: } else {
6383: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
6384: }
6385: } else {
6386: if ($end == 0 || $end > $now) {
6387: $dates = &mt('future role(s); starts: [_1].',&Apache::lonlocal::locallocaltime($start));
6388: } else {
6389: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
6390: }
6391: }
6392: return $dates;
6393: }
6394:
1.8 raeburn 6395: sub classlist_drop {
1.29 raeburn 6396: my ($scope,$uname,$udom,$now) = @_;
1.8 raeburn 6397: my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
1.29 raeburn 6398: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.8 raeburn 6399: if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
1.63 raeburn 6400: my %user;
6401: my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
1.8 raeburn 6402: return &mt('Drop from classlist: [_1]',
6403: '<b>'.$result.'</b>').'<br />';
6404: }
6405: }
6406: }
6407:
6408: sub active_student_roles {
6409: my ($cnum,$cdom,$uname,$udom) = @_;
6410: my %roles =
6411: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
6412: ['future','active'],['st']);
6413: return exists($roles{"$cnum:$cdom:st"});
6414: }
6415:
1.1 raeburn 6416: sub section_check_js {
1.8 raeburn 6417: my $groupslist= &get_groupslist();
1.170 damieng 6418: my %js_lt = &Apache::lonlocal::texthash(
6419: mayn => 'may not be used as the name for a section, as it is a reserved word.',
6420: plch => 'Please choose a different section name.',
6421: mnot => 'may not be used as a section name, as it is the name of a course group.',
6422: secn => 'Section names and group names must be distinct. Please choose a different section name.',
6423: );
6424: &js_escape(\%js_lt);
1.1 raeburn 6425: return <<"END";
6426: function validate(caller) {
1.9 raeburn 6427: var groups = new Array($groupslist);
1.1 raeburn 6428: var secname = caller.value;
6429: if ((secname == 'all') || (secname == 'none')) {
1.170 damieng 6430: alert("'"+secname+"' $js_lt{'mayn'}\\n$js_lt{'plch'}");
1.1 raeburn 6431: return 'error';
6432: }
6433: if (secname != '') {
6434: for (var k=0; k<groups.length; k++) {
6435: if (secname == groups[k]) {
1.170 damieng 6436: alert("'"+secname+"' $js_lt{'mnot'}\\n$js_lt{'secn'}");
1.1 raeburn 6437: return 'error';
6438: }
6439: }
6440: }
6441: return 'ok';
6442: }
6443: END
6444: }
6445:
6446: sub set_login {
1.194 raeburn 6447: my ($dom,$authformkrb,$authformint,$authformloc,$authformlti) = @_;
1.1 raeburn 6448: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6449: my $response;
6450: my ($authnum,%can_assign) =
6451: &Apache::loncommon::get_assignable_auth($dom);
6452: if ($authnum) {
6453: $response = &Apache::loncommon::start_data_table();
6454: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
6455: $response .= &Apache::loncommon::start_data_table_row().
6456: '<td>'.$authformkrb.'</td>'.
6457: &Apache::loncommon::end_data_table_row()."\n";
6458: }
6459: if ($can_assign{'int'}) {
6460: $response .= &Apache::loncommon::start_data_table_row().
6461: '<td>'.$authformint.'</td>'.
6462: &Apache::loncommon::end_data_table_row()."\n"
6463: }
6464: if ($can_assign{'loc'}) {
6465: $response .= &Apache::loncommon::start_data_table_row().
6466: '<td>'.$authformloc.'</td>'.
6467: &Apache::loncommon::end_data_table_row()."\n";
6468: }
1.194 raeburn 6469: if ($can_assign{'lti'}) {
6470: $response .= &Apache::loncommon::start_data_table_row().
6471: '<td>'.$authformlti.'</td>'.
6472: &Apache::loncommon::end_data_table_row()."\n";
6473: }
1.1 raeburn 6474: $response .= &Apache::loncommon::end_data_table();
6475: }
6476: return $response;
6477: }
6478:
1.8 raeburn 6479: sub course_sections {
1.178 raeburn 6480: my ($sections_count,$role,$current_sec,$disabled) = @_;
1.8 raeburn 6481: my $output = '';
1.169 raeburn 6482: my @sections = (sort {$a <=> $b} keys(%{$sections_count}));
1.29 raeburn 6483: my $numsec = scalar(@sections);
1.92 bisitz 6484: my $is_selected = ' selected="selected"';
1.29 raeburn 6485: if ($numsec <= 1) {
1.178 raeburn 6486: $output = '<select name="currsec_'.$role.'"'.$disabled.'>'."\n".
1.51 raeburn 6487: ' <option value="">'.&mt('Select').'</option>'."\n";
6488: if ($current_sec eq 'none') {
6489: $output .=
6490: ' <option value=""'.$is_selected.'>'.&mt('No section').'</option>'."\n";
6491: } else {
6492: $output .=
1.29 raeburn 6493: ' <option value="">'.&mt('No section').'</option>'."\n";
1.51 raeburn 6494: }
1.29 raeburn 6495: if ($numsec == 1) {
1.51 raeburn 6496: if ($current_sec eq $sections[0]) {
6497: $output .=
6498: ' <option value="'.$sections[0].'"'.$is_selected.'>'.$sections[0].'</option>'."\n";
6499: } else {
6500: $output .=
1.8 raeburn 6501: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
1.51 raeburn 6502: }
1.29 raeburn 6503: }
1.8 raeburn 6504: } else {
6505: $output = '<select name="currsec_'.$role.'" ';
6506: my $multiple = 4;
6507: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
1.29 raeburn 6508: if ($role eq 'st') {
1.178 raeburn 6509: $output .= $disabled.'>'."\n".
1.51 raeburn 6510: ' <option value="">'.&mt('Select').'</option>'."\n";
6511: if ($current_sec eq 'none') {
6512: $output .=
6513: ' <option value=""'.$is_selected.'>'.&mt('No section')."</option>\n";
6514: } else {
6515: $output .=
1.29 raeburn 6516: ' <option value="">'.&mt('No section')."</option>\n";
1.51 raeburn 6517: }
1.29 raeburn 6518: } else {
1.178 raeburn 6519: $output .= 'multiple="multiple" size="'.$multiple.'"'.$disabled.'>'."\n";
1.29 raeburn 6520: }
1.8 raeburn 6521: foreach my $sec (@sections) {
1.51 raeburn 6522: if ($current_sec eq $sec) {
6523: $output .= '<option value="'.$sec.'"'.$is_selected.'>'.$sec."</option>\n";
6524: } else {
6525: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
6526: }
1.8 raeburn 6527: }
6528: }
6529: $output .= '</select>';
6530: return $output;
6531: }
6532:
6533: sub get_groupslist {
6534: my $groupslist;
6535: my %curr_groups = &Apache::longroup::coursegroups();
6536: if (%curr_groups) {
6537: $groupslist = join('","',sort(keys(%curr_groups)));
6538: $groupslist = '"'.$groupslist.'"';
6539: }
1.11 raeburn 6540: return $groupslist;
1.8 raeburn 6541: }
6542:
6543: sub setsections_javascript {
1.150 raeburn 6544: my ($formname,$groupslist,$mode,$checkauth,$crstype,$showcredits) = @_;
1.28 raeburn 6545: my ($checkincluded,$finish,$rolecode,$setsection_js);
6546: if ($mode eq 'upload') {
6547: $checkincluded = 'formname.name == "'.$formname.'"';
6548: $finish = "return 'ok';";
6549: $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
6550: } elsif ($formname eq 'cu') {
1.150 raeburn 6551: if (($crstype eq 'Course') && ($showcredits)) {
6552: $checkincluded = "((role == 'st') && (formname.elements[i-2].checked == true)) || ((role != 'st') && (formname.elements[i-1].checked == true))";
6553: } else {
6554: $checkincluded = 'formname.elements[i-1].checked == true';
6555: }
1.37 raeburn 6556: if ($checkauth) {
6557: $finish = "var authcheck = auth_check();\n".
6558: " if (authcheck == 'ok') {\n".
6559: " formname.submit();\n".
6560: " }\n";
6561: } else {
6562: $finish = 'formname.submit()';
6563: }
1.28 raeburn 6564: $rolecode = "var match = str.split('_');
6565: var role = match[3];\n";
1.165 raeburn 6566: } elsif (($formname eq 'enrollstudent') || ($formname eq 'selfenroll')) {
1.28 raeburn 6567: $checkincluded = 'formname.name == "'.$formname.'"';
1.37 raeburn 6568: if ($checkauth) {
6569: $finish = "var authcheck = auth_check();\n".
6570: " if (authcheck == 'ok') {\n".
6571: " formname.submit();\n".
6572: " }\n";
6573: } else {
6574: $finish = 'formname.submit()';
6575: }
1.28 raeburn 6576: $rolecode = "var match = str.split('_');
6577: var role = match[1];\n";
1.8 raeburn 6578: } else {
1.28 raeburn 6579: $checkincluded = 'formname.name == "'.$formname.'"';
1.8 raeburn 6580: $finish = "seccheck = 'ok';";
1.28 raeburn 6581: $rolecode = "var match = str.split('_');
6582: var role = match[1];\n";
1.11 raeburn 6583: $setsection_js = "var seccheck = 'alert';";
1.8 raeburn 6584: }
6585: my %alerts = &Apache::lonlocal::texthash(
6586: secd => 'Section designations do not apply to Course Coordinator roles.',
1.103 raeburn 6587: sedn => 'Section designations do not apply to Coordinator roles.',
1.8 raeburn 6588: accr => 'A course coordinator role will be added with access to all sections.',
1.103 raeburn 6589: acor => 'A coordinator role will be added with access to all sections',
1.8 raeburn 6590: inea => 'In each course, each user may only have one student role at a time.',
1.125 raeburn 6591: inco => 'In each community, each user may only have one member role at a time.',
1.145 raeburn 6592: youh => 'You had selected',
1.8 raeburn 6593: secs => 'sections.',
6594: plmo => 'Please modify your selections so they include no more than one section.',
6595: mayn => 'may not be used as the name for a section, as it is a reserved word.',
6596: plch => 'Please choose a different section name.',
6597: mnot => 'may not be used as a section name, as it is the name of a course group.',
6598: secn => 'Section names and group names must be distinct. Please choose a different section name.',
1.113 raeburn 6599: nonw => 'Section names may only contain letters or numbers.',
1.170 damieng 6600: );
6601: &js_escape(\%alerts);
1.8 raeburn 6602: $setsection_js .= <<"ENDSECCODE";
6603:
1.103 raeburn 6604: function setSections(formname,crstype) {
1.8 raeburn 6605: var re1 = /^currsec_/;
1.113 raeburn 6606: var re2 =/\\W/;
1.115 raeburn 6607: var trimleading = /^\\s+/;
6608: var trimtrailing = /\\s+\$/;
1.8 raeburn 6609: var groups = new Array($groupslist);
6610: for (var i=0;i<formname.elements.length;i++) {
6611: var str = formname.elements[i].name;
1.168 raeburn 6612: if (typeof(str) === "undefined") {
6613: continue;
6614: }
1.8 raeburn 6615: var checkcurr = str.match(re1);
6616: if (checkcurr != null) {
1.115 raeburn 6617: var num = i;
1.150 raeburn 6618: $rolecode
1.8 raeburn 6619: if ($checkincluded) {
1.103 raeburn 6620: if (role == 'cc' || role == 'co') {
6621: if (role == 'cc') {
6622: alert("$alerts{'secd'}\\n$alerts{'accr'}");
6623: } else {
6624: alert("$alerts{'sedn'}\\n$alerts{'acor'}");
6625: }
6626: } else {
1.8 raeburn 6627: var sections = '';
6628: var numsec = 0;
1.115 raeburn 6629: var fromexisting = new Array();
6630: for (var j=0; j<formname.elements[num].length; j++) {
6631: if (formname.elements[num].options[j].selected == true ) {
6632: var addsec = formname.elements[num].options[j].value;
1.119 raeburn 6633: if ((addsec != "") && (addsec != null)) {
1.115 raeburn 6634: fromexisting.push(addsec);
1.8 raeburn 6635: if (numsec == 0) {
1.115 raeburn 6636: sections = addsec;
6637: } else {
6638: sections = sections + "," + addsec;
1.8 raeburn 6639: }
1.115 raeburn 6640: numsec ++;
1.8 raeburn 6641: }
6642: }
6643: }
1.115 raeburn 6644: var newsecs = formname.elements[num+1].value;
1.113 raeburn 6645: var validsecs = new Array();
1.115 raeburn 6646: var validsecstr = '';
1.113 raeburn 6647: var badsecs = new Array();
1.8 raeburn 6648: if (newsecs != null && newsecs != "") {
1.115 raeburn 6649: var numsplit;
6650: if (newsecs.indexOf(',') == -1) {
6651: numsplit = new Array(newsecs);
6652: } else {
6653: numsplit = newsecs.split(/,/g);
6654: }
1.117 raeburn 6655: for (var m=0; m<numsplit.length; m++) {
6656: var newsec = numsplit[m];
1.115 raeburn 6657: newsec = newsec.replace(trimleading,'');
6658: newsec = newsec.replace(trimtrailing,'');
6659: if (re2.test(newsec) == true) {
6660: badsecs.push(newsec);
1.113 raeburn 6661: } else {
1.115 raeburn 6662: if (newsec != '') {
6663: var isnew = 1;
6664: if (fromexisting != null) {
1.117 raeburn 6665: for (var n=0; n<fromexisting.length; n++) {
6666: if (newsec == fromexisting[n]) {
1.115 raeburn 6667: isnew = 0;
6668: }
6669: }
6670: }
6671: if (isnew == 1) {
6672: validsecs.push(newsec);
6673: }
6674: }
1.113 raeburn 6675: }
6676: }
6677: if (badsecs.length > 0) {
6678: alert("$alerts{'nonw'}\\n$alerts{'plch'}");
6679: return;
6680: }
6681: numsec = numsec + validsecs.length;
1.8 raeburn 6682: }
6683: if ((role == 'st') && (numsec > 1)) {
1.103 raeburn 6684: if (crstype == 'Community') {
6685: alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
6686: } else {
6687: alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
6688: }
1.8 raeburn 6689: return;
1.115 raeburn 6690: } else {
6691: if (validsecs != null) {
6692: for (var j=0; j<validsecs.length; j++) {
6693: if (validsecstr == '' || validsecstr == null) {
6694: validsecstr = validsecs[j];
6695: } else {
6696: validsecstr += ','+validsecs[j];
6697: }
6698: if ((validsecs[j] == 'all') ||
6699: (validsecs[j] == 'none')) {
6700: alert("'"+validsecs[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
1.8 raeburn 6701: return;
6702: }
6703: for (var k=0; k<groups.length; k++) {
1.115 raeburn 6704: if (validsecs[j] == groups[k]) {
6705: alert("'"+validsecs[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
1.8 raeburn 6706: return;
6707: }
6708: }
6709: }
6710: }
6711: }
1.115 raeburn 6712: if ((validsecstr != '') && (validsecstr != null)) {
1.117 raeburn 6713: if ((sections == '') || (sections == null)) {
6714: sections = validsecstr;
6715: } else {
1.115 raeburn 6716: sections = sections + "," + validsecstr;
6717: }
6718: }
6719: formname.elements[num+2].value = sections;
1.8 raeburn 6720: }
6721: }
6722: }
6723: }
6724: $finish
6725: }
6726: ENDSECCODE
1.11 raeburn 6727: return $setsection_js;
1.8 raeburn 6728: }
6729:
1.15 raeburn 6730: sub can_create_user {
6731: my ($dom,$context,$usertype) = @_;
6732: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
6733: my $cancreate = 1;
1.28 raeburn 6734: if (&Apache::lonnet::allowed('mau',$dom)) {
6735: return $cancreate;
1.178 raeburn 6736: } elsif ($context eq 'domain') {
6737: $cancreate = 0;
6738: return $cancreate;
1.28 raeburn 6739: }
1.15 raeburn 6740: if (ref($domconf{'usercreation'}) eq 'HASH') {
6741: if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
1.100 raeburn 6742: if ($context eq 'course' || $context eq 'author' || $context eq 'requestcrs') {
1.15 raeburn 6743: my $creation = $domconf{'usercreation'}{'cancreate'}{$context};
6744: if ($creation eq 'none') {
6745: $cancreate = 0;
6746: } elsif ($creation ne 'any') {
6747: if (defined($usertype)) {
6748: if ($creation ne $usertype) {
6749: $cancreate = 0;
6750: }
6751: }
6752: }
6753: }
6754: }
6755: }
6756: return $cancreate;
6757: }
6758:
1.20 raeburn 6759: sub can_modify_userinfo {
6760: my ($context,$dom,$fields,$userroles) = @_;
6761: my %domconfig =
6762: &Apache::lonnet::get_dom('configuration',['usermodification'],
6763: $dom);
1.222 raeburn 6764: if (($context eq 'author') &&
6765: ($env{'request.role'} =~ m{^(ca|aa)\./$match_domain/$match_username$})) {
6766: $context = 'coauthor';
6767: }
1.20 raeburn 6768: my %canmodify;
6769: if (ref($fields) eq 'ARRAY') {
6770: foreach my $field (@{$fields}) {
6771: $canmodify{$field} = 0;
6772: if (&Apache::lonnet::allowed('mau',$dom)) {
6773: $canmodify{$field} = 1;
1.224 raeburn 6774: } elsif (($context ne 'selfcreate') &&
6775: ($env{'request.role.dom'} ne $dom) &&
6776: ($env{'user.domain'} ne $dom)) {
6777: $canmodify{$field} = 0;
1.20 raeburn 6778: } else {
6779: if (ref($domconfig{'usermodification'}) eq 'HASH') {
6780: if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
6781: if (ref($userroles) eq 'ARRAY') {
6782: foreach my $role (@{$userroles}) {
6783: my $testrole;
1.60 raeburn 6784: if ($context eq 'selfcreate') {
6785: $testrole = $role;
1.20 raeburn 6786: } else {
1.60 raeburn 6787: if ($role =~ /^cr\//) {
6788: $testrole = 'cr';
6789: } else {
6790: $testrole = $role;
6791: }
1.20 raeburn 6792: }
6793: if (ref($domconfig{'usermodification'}{$context}{$testrole}) eq 'HASH') {
6794: if ($domconfig{'usermodification'}{$context}{$testrole}{$field}) {
6795: $canmodify{$field} = 1;
6796: last;
6797: }
6798: }
6799: }
6800: } else {
6801: foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
6802: if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
6803: if ($domconfig{'usermodification'}{$context}{$key}{$field}) {
6804: $canmodify{$field} = 1;
6805: last;
6806: }
6807: }
6808: }
6809: }
6810: }
6811: } elsif ($context eq 'course') {
6812: if (ref($userroles) eq 'ARRAY') {
6813: if (grep(/^st$/,@{$userroles})) {
6814: $canmodify{$field} = 1;
6815: }
6816: } else {
6817: $canmodify{$field} = 1;
6818: }
6819: }
6820: }
6821: }
6822: }
6823: return %canmodify;
6824: }
6825:
1.195 raeburn 6826: sub can_change_internalpass {
6827: my ($uname,$udom,$crstype,$permission) = @_;
6828: my $canchange;
6829: if (&Apache::lonnet::allowed('mau',$udom)) {
6830: $canchange = 1;
6831: } elsif ((ref($permission) eq 'HASH') && ($permission->{'mip'}) &&
6832: ($udom eq $env{'request.role.domain'})) {
6833: unless ($env{'course.'.$env{'request.course.id'}.'.internal.nopasswdchg'}) {
6834: my ($cnum,$cdom) = &get_course_identity();
6835: if ((&Apache::lonnet::is_course_owner($cdom,$cnum)) && ($udom eq $env{'user.domain'})) {
1.199 raeburn 6836: my @userstatuses = ('default');
6837: my %userenv = &Apache::lonnet::userenvironment($udom,$uname,'inststatus');
6838: if ($userenv{'inststatus'} ne '') {
6839: @userstatuses = split(/:/,$userenv{'inststatus'});
6840: }
6841: my $noupdate = 1;
6842: my %passwdconf = &Apache::lonnet::get_passwdconf($cdom);
6843: if (ref($passwdconf{'crsownerchg'}) eq 'HASH') {
6844: if (ref($passwdconf{'crsownerchg'}{'for'}) eq 'ARRAY') {
6845: foreach my $status (@userstatuses) {
6846: if (grep(/^\Q$status\E$/,@{$passwdconf{'crsownerchg'}{'for'}})) {
6847: undef($noupdate);
6848: last;
6849: }
6850: }
6851: }
6852: }
6853: if ($noupdate) {
6854: return;
6855: }
1.195 raeburn 6856: my %owned = &Apache::lonnet::courseiddump($cdom,'.',1,'.',
6857: $env{'user.name'}.':'.$env{'user.domain'},
6858: undef,undef,undef,'.');
6859: my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
6860: ['active','future']);
6861: foreach my $key (keys(%roleshash)) {
6862: my ($name,$domain,$role) = split(/:/,$key);
6863: if ($role eq 'st') {
6864: next if (($name eq $cnum) && ($domain eq $cdom));
6865: if ($owned{$domain.'_'.$name}) {
6866: if (ref($owned{$domain.'_'.$name}) eq 'HASH') {
6867: if ($owned{$domain.'_'.$name}{'nopasswdchg'}) {
6868: $noupdate = 1;
6869: last;
6870: }
6871: }
6872: } else {
6873: $noupdate = 1;
6874: last;
6875: }
6876: } else {
6877: $noupdate = 1;
6878: last;
6879: }
6880: }
6881: unless ($noupdate) {
6882: $canchange = 1;
6883: }
6884: }
6885: }
6886: }
6887: return $canchange;
6888: }
6889:
1.18 raeburn 6890: sub check_usertype {
1.134 raeburn 6891: my ($dom,$uname,$rules,$curr_rules,$got_rules) = @_;
1.18 raeburn 6892: my $usertype;
1.134 raeburn 6893: if ((ref($got_rules) eq 'HASH') && (ref($curr_rules) eq 'HASH')) {
6894: if (!$got_rules->{$dom}) {
6895: my %domconfig = &Apache::lonnet::get_dom('configuration',
6896: ['usercreation'],$dom);
6897: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6898: foreach my $item ('username','id') {
6899: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
6900: $curr_rules->{$dom}{$item} =
6901: $domconfig{'usercreation'}{$item.'_rule'};
6902: }
6903: }
6904: }
6905: $got_rules->{$dom} = 1;
6906: }
6907: if (ref($rules) eq 'HASH') {
6908: my @user_rules;
6909: if (ref($curr_rules->{$dom}{'username'}) eq 'ARRAY') {
6910: foreach my $rule (keys(%{$rules})) {
6911: if (grep(/^\Q$rule\E/,@{$curr_rules->{$dom}{'username'}})) {
6912: push(@user_rules,$rule);
6913: }
6914: }
6915: }
6916: if (@user_rules > 0) {
6917: my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
6918: if (keys(%rule_check) > 0) {
6919: $usertype = 'unofficial';
6920: foreach my $item (keys(%rule_check)) {
6921: if ($rule_check{$item}) {
6922: $usertype = 'official';
6923: last;
6924: }
1.18 raeburn 6925: }
6926: }
6927: }
6928: }
6929: }
6930: return $usertype;
6931: }
6932:
1.17 raeburn 6933: sub roles_by_context {
1.101 raeburn 6934: my ($context,$custom,$crstype) = @_;
1.17 raeburn 6935: my @allroles;
6936: if ($context eq 'course') {
1.99 raeburn 6937: @allroles = ('st');
6938: if ($env{'request.role'} =~ m{^dc\./}) {
6939: push(@allroles,'ad');
6940: }
1.101 raeburn 6941: push(@allroles,('ta','ep','in'));
6942: if ($crstype eq 'Community') {
6943: push(@allroles,'co');
6944: } else {
6945: push(@allroles,'cc');
6946: }
1.17 raeburn 6947: if ($custom) {
6948: push(@allroles,'cr');
6949: }
6950: } elsif ($context eq 'author') {
6951: @allroles = ('ca','aa');
6952: } elsif ($context eq 'domain') {
1.182 raeburn 6953: @allroles = ('li','ad','dg','dh','da','sc','au','dc');
1.17 raeburn 6954: }
6955: return @allroles;
6956: }
6957:
1.16 raeburn 6958: sub get_permission {
1.101 raeburn 6959: my ($context,$crstype) = @_;
1.16 raeburn 6960: my %permission;
6961: if ($context eq 'course') {
1.17 raeburn 6962: my $custom = 1;
1.101 raeburn 6963: my @allroles = &roles_by_context($context,$custom,$crstype);
1.17 raeburn 6964: foreach my $role (@allroles) {
6965: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
6966: $permission{'cusr'} = 1;
6967: last;
6968: }
1.16 raeburn 6969: }
6970: if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
6971: $permission{'custom'} = 1;
6972: }
6973: if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
6974: $permission{'view'} = 1;
6975: }
6976: if (!$permission{'view'}) {
6977: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
6978: $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
6979: if ($permission{'view'}) {
6980: $permission{'view_section'} = $env{'request.course.sec'};
6981: }
6982: }
1.17 raeburn 6983: if (!$permission{'cusr'}) {
6984: if ($env{'request.course.sec'} ne '') {
6985: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
6986: $permission{'cusr'} = (&Apache::lonnet::allowed('cst',$scope));
6987: if ($permission{'cusr'}) {
6988: $permission{'cusr_section'} = $env{'request.course.sec'};
6989: }
6990: }
6991: }
1.16 raeburn 6992: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
6993: $permission{'grp_manage'} = 1;
6994: }
1.165 raeburn 6995: if ($permission{'cusr'}) {
6996: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6997: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6998: my %coursehash = (
6999: 'internal.selfenrollmgrdc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrdc'},
7000: 'internal.selfenrollmgrcc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrcc'},
7001: 'internal.coursecode' => $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},
7002: 'internal.textbook' =>$env{'course.'.$env{'request.course.id'}.'.internal.textbook'},
7003: );
7004: my ($managed_by_cc,$managed_by_dc) = &selfenrollment_administration($cdom,$cnum,$crstype,\%coursehash);
7005: if (ref($managed_by_cc) eq 'ARRAY') {
7006: if (@{$managed_by_cc}) {
7007: $permission{'selfenrolladmin'} = 1;
7008: }
7009: }
1.216 raeburn 7010: unless ($permission{'selfenrolladmin'}) {
7011: $permission{'selfenrollview'} = 1;
7012: }
1.165 raeburn 7013: }
1.180 raeburn 7014: if ($env{'request.course.id'}) {
1.195 raeburn 7015: my $user;
7016: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
7017: $user = $env{'user.name'}.':'.$env{'user.domain'};
7018: }
1.180 raeburn 7019: if (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'} eq
7020: $user)) {
7021: $permission{'owner'} = 1;
1.195 raeburn 7022: if (&Apache::lonnet::allowed('mip',$env{'request.course.id'})) {
7023: $permission{'mip'} = 1;
7024: }
1.180 raeburn 7025: } elsif (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.co-owners'} ne '')) {
7026: if (grep(/^\Q$user\E$/,split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.co-owners'}))) {
7027: $permission{'co-owner'} = 1;
7028: }
7029: }
7030: }
1.16 raeburn 7031: } elsif ($context eq 'author') {
1.218 raeburn 7032: my $audom = $env{'request.role.domain'};
7033: my $auname = $env{'user.name'};
7034: if ((&Apache::lonnet::allowed('cca',"$audom/$auname")) ||
7035: (&Apache::lonnet::allowed('caa',"$audom/$auname"))) {
7036: $permission{'author'} = 1;
7037: $permission{'cusr'} = 1;
7038: $permission{'view'} = 1;
7039: }
7040: } elsif ($context eq 'coauthor') {
7041: my ($audom,$auname) = ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$});
7042: if ((&Apache::lonnet::allowed('vca',"$audom/$auname")) ||
7043: (&Apache::lonnet::allowed('vaa',"$audom/$auname"))) {
7044: if ($env{"environment.internal.manager./$audom/$auname"}) {
7045: $permission{'cusr'} = 1;
7046: $permission{'view'} = 1;
7047: }
7048: }
1.16 raeburn 7049: } else {
1.17 raeburn 7050: my @allroles = &roles_by_context($context);
7051: foreach my $role (@allroles) {
1.28 raeburn 7052: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
7053: $permission{'cusr'} = 1;
1.17 raeburn 7054: last;
7055: }
7056: }
7057: if (!$permission{'cusr'}) {
7058: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
7059: $permission{'cusr'} = 1;
7060: }
1.16 raeburn 7061: }
7062: if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
7063: $permission{'custom'} = 1;
7064: }
1.176 raeburn 7065: if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
7066: $permission{'activity'} = 1;
7067: }
1.178 raeburn 7068: if (&Apache::lonnet::allowed('vur',$env{'request.role.domain'})) {
7069: $permission{'view'} = 1;
7070: }
1.180 raeburn 7071: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
7072: $permission{'owner'} = 1;
7073: }
1.16 raeburn 7074: }
7075: my $allowed = 0;
1.211 raeburn 7076: foreach my $key (keys(%permission)) {
1.218 raeburn 7077: next if (($key eq 'owner') || ($key eq 'co-owner') || ($key eq 'author'));
1.211 raeburn 7078: if ($permission{$key}) { $allowed=1; last; }
1.16 raeburn 7079: }
7080: return (\%permission,$allowed);
7081: }
7082:
7083: # ==================================================== Figure out author access
7084:
7085: sub authorpriv {
7086: my ($auname,$audom)=@_;
7087: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
7088: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; } return 1;
7089: }
7090:
1.218 raeburn 7091: sub coauthorpriv {
7092: my ($auname,$audom)=@_;
7093: my $uname = $env{'user.name'};
7094: my $udom = $env{'user.domain'};
7095: if (((&Apache::lonnet::allowed('vca',"$udom/$uname")) ||
7096: (&Apache::lonnet::allowed('vaa',"$udom/$uname"))) &&
7097: ($env{"environment.internal.manager./$audom/$auname"})) {
7098: return 1;
7099: }
7100: return '';
7101: }
7102:
1.27 raeburn 7103: sub roles_on_upload {
1.101 raeburn 7104: my ($context,$setting,$crstype,%customroles) = @_;
1.27 raeburn 7105: my (@possible_roles,@permitted_roles);
1.101 raeburn 7106: @possible_roles = &curr_role_permissions($context,$setting,1,$crstype);
1.27 raeburn 7107: foreach my $role (@possible_roles) {
7108: if ($role eq 'cr') {
7109: push(@permitted_roles,keys(%customroles));
7110: } else {
7111: push(@permitted_roles,$role);
7112: }
7113: }
1.42 raeburn 7114: return @permitted_roles;
1.27 raeburn 7115: }
7116:
1.17 raeburn 7117: sub get_course_identity {
7118: my ($cid) = @_;
7119: my ($cnum,$cdom,$cdesc);
7120: if ($cid eq '') {
7121: $cid = $env{'request.course.id'}
7122: }
7123: if ($cid ne '') {
7124: $cnum = $env{'course.'.$cid.'.num'};
7125: $cdom = $env{'course.'.$cid.'.domain'};
7126: $cdesc = $env{'course.'.$cid.'.description'};
7127: if ($cnum eq '' || $cdom eq '') {
7128: my %coursehash =
7129: &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
7130: $cdom = $coursehash{'domain'};
7131: $cnum = $coursehash{'num'};
7132: $cdesc = $coursehash{'description'};
7133: }
7134: }
7135: return ($cnum,$cdom,$cdesc);
7136: }
7137:
1.19 raeburn 7138: sub dc_setcourse_js {
1.196 raeburn 7139: my ($formname,$mode,$context,$showcredits,$domain) = @_;
1.37 raeburn 7140: my ($dc_setcourse_code,$authen_check);
1.19 raeburn 7141: my $cctext = &Apache::lonnet::plaintext('cc');
1.103 raeburn 7142: my $cotext = &Apache::lonnet::plaintext('co');
1.19 raeburn 7143: my %alerts = §ioncheck_alerts();
7144: my $role = 'role';
7145: if ($mode eq 'upload') {
7146: $role = 'courserole';
1.37 raeburn 7147: } else {
1.196 raeburn 7148: $authen_check = &verify_authen($formname,$context,$domain);
1.19 raeburn 7149: }
7150: $dc_setcourse_code = (<<"SCRIPTTOP");
1.37 raeburn 7151: $authen_check
7152:
1.19 raeburn 7153: function setCourse() {
7154: var course = document.$formname.dccourse.value;
7155: if (course != "") {
7156: if (document.$formname.dcdomain.value != document.$formname.origdom.value) {
7157: alert("$alerts{'curd'}");
7158: return;
7159: }
7160: var userrole = document.$formname.$role.options[document.$formname.$role.selectedIndex].value
7161: var section="";
7162: var numsections = 0;
7163: var newsecs = new Array();
7164: for (var i=0; i<document.$formname.currsec.length; i++) {
7165: if (document.$formname.currsec.options[i].selected == true ) {
7166: if (document.$formname.currsec.options[i].value != "" && document.$formname.currsec.options[i].value != null) {
7167: if (numsections == 0) {
7168: section = document.$formname.currsec.options[i].value
7169: numsections = 1;
7170: }
7171: else {
7172: section = section + "," + document.$formname.currsec.options[i].value
7173: numsections ++;
7174: }
7175: }
7176: }
7177: }
7178: if (document.$formname.newsec.value != "" && document.$formname.newsec.value != null) {
7179: if (numsections == 0) {
7180: section = document.$formname.newsec.value
7181: }
7182: else {
7183: section = section + "," + document.$formname.newsec.value
7184: }
7185: newsecs = document.$formname.newsec.value.split(/,/g);
7186: numsections = numsections + newsecs.length;
7187: }
7188: if ((userrole == 'st') && (numsections > 1)) {
1.103 raeburn 7189: if (document.$formname.crstype.value == 'Community') {
7190: alert("$alerts{'inco'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
7191: } else {
7192: alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
7193: }
1.19 raeburn 7194: return;
7195: }
7196: for (var j=0; j<newsecs.length; j++) {
7197: if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
7198: alert("'"+newsecs[j]+"' $alerts{'mayn'}.\\n$alerts{'plsc'}.");
7199: return;
7200: }
7201: if (document.$formname.groups.value != '') {
7202: var groups = document.$formname.groups.value.split(/,/g);
7203: for (var k=0; k<groups.length; k++) {
7204: if (newsecs[j] == groups[k]) {
1.103 raeburn 7205: if (document.$formname.crstype.value == 'Community') {
7206: alert("'"+newsecs[j]+"' $alerts{'mayc'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
7207: } else {
7208: alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
7209: }
1.19 raeburn 7210: return;
7211: }
7212: }
7213: }
7214: }
7215: if ((userrole == 'cc') && (numsections > 0)) {
7216: alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
7217: section = "";
7218: }
1.103 raeburn 7219: if ((userrole == 'co') && (numsections > 0)) {
7220: alert("$alerts{'secd'} $cotext $alerts{'role'}.\\n$alerts{'accr'}.");
7221: section = "";
7222: }
1.19 raeburn 7223: SCRIPTTOP
7224: if ($mode ne 'upload') {
1.150 raeburn 7225: $dc_setcourse_code .= (<<"SCRIPTMID");
1.19 raeburn 7226: var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
7227: var numcourse = getIndex(document.$formname.dccourse);
7228: if (numcourse == "-1") {
1.103 raeburn 7229: if (document.$formname.type == 'Community') {
7230: alert("$alerts{'thwc'}");
7231: } else {
7232: alert("$alerts{'thwa'}");
7233: }
1.19 raeburn 7234: return;
7235: }
7236: else {
7237: document.$formname.elements[numcourse].name = "act"+coursename;
7238: var numnewsec = getIndex(document.$formname.newsec);
7239: if (numnewsec != "-1") {
7240: document.$formname.elements[numnewsec].name = "sec"+coursename;
7241: document.$formname.elements[numnewsec].value = section;
7242: }
7243: var numstart = getIndex(document.$formname.start);
7244: if (numstart != "-1") {
7245: document.$formname.elements[numstart].name = "start"+coursename;
7246: }
7247: var numend = getIndex(document.$formname.end);
7248: if (numend != "-1") {
7249: document.$formname.elements[numend].name = "end"+coursename
7250: }
1.150 raeburn 7251: SCRIPTMID
7252: if ($showcredits) {
7253: $dc_setcourse_code .= <<ENDCRED;
7254: var numcredits = getIndex(document.$formname.credits);
7255: if (numcredits != "-1") {
7256: document.$formname.elements[numcredits].name = "credits"+coursename;
7257: }
7258: ENDCRED
7259: }
7260: $dc_setcourse_code .= <<ENDSCRIPT;
1.19 raeburn 7261: }
7262: }
1.37 raeburn 7263: var authcheck = auth_check();
7264: if (authcheck == 'ok') {
7265: document.$formname.submit();
7266: }
1.19 raeburn 7267: }
7268: ENDSCRIPT
7269: } else {
7270: $dc_setcourse_code .= "
7271: document.$formname.sections.value = section;
7272: }
7273: return 'ok';
7274: }
7275: ";
7276: }
7277: $dc_setcourse_code .= (<<"ENDSCRIPT");
7278:
7279: function getIndex(caller) {
7280: for (var i=0;i<document.$formname.elements.length;i++) {
7281: if (document.$formname.elements[i] == caller) {
7282: return i;
7283: }
7284: }
7285: return -1;
7286: }
7287: ENDSCRIPT
1.37 raeburn 7288: return $dc_setcourse_code;
7289: }
7290:
7291: sub verify_authen {
1.196 raeburn 7292: my ($formname,$context,$domain) = @_;
1.37 raeburn 7293: my %alerts = &authcheck_alerts();
7294: my $finish = "return 'ok';";
7295: if ($context eq 'author') {
7296: $finish = "document.$formname.submit();";
7297: }
1.196 raeburn 7298: my ($numrules,$intargjs) =
1.210 raeburn 7299: &Apache::loncommon::passwd_validation_js('argpicked',$domain);
1.37 raeburn 7300: my $outcome = <<"ENDSCRIPT";
7301:
7302: function auth_check() {
7303: var logintype;
7304: if (document.$formname.login.length) {
7305: if (document.$formname.login.length > 0) {
7306: var loginpicked = 0;
7307: for (var i=0; i<document.$formname.login.length; i++) {
7308: if (document.$formname.login[i].checked == true) {
7309: loginpicked = 1;
7310: logintype = document.$formname.login[i].value;
7311: }
7312: }
7313: if (loginpicked == 0) {
7314: alert("$alerts{'authen'}");
7315: return;
7316: }
7317: }
7318: } else {
7319: logintype = document.$formname.login.value;
7320: }
7321: if (logintype == 'nochange') {
7322: return 'ok';
7323: }
7324: var argpicked = document.$formname.elements[logintype+'arg'].value;
7325: if ((argpicked == null) || (argpicked == '') || (typeof argpicked == 'undefined')) {
7326: var alertmsg = '';
7327: switch (logintype) {
7328: case 'krb':
7329: alertmsg = '$alerts{'krb'}';
7330: break;
7331: case 'int':
7332: alertmsg = '$alerts{'ipass'}';
1.196 raeburn 7333: break;
1.37 raeburn 7334: case 'fsys':
7335: alertmsg = '$alerts{'ipass'}';
7336: break;
7337: case 'loc':
7338: alertmsg = '';
7339: break;
7340: default:
7341: alertmsg = '';
7342: }
7343: if (alertmsg != '') {
7344: alert(alertmsg);
7345: return;
7346: }
1.196 raeburn 7347: } else if (logintype == 'int') {
7348: var numrules = $numrules;
7349: if (numrules > 0) {
7350: $intargjs
7351: }
1.37 raeburn 7352: }
7353: $finish
7354: }
7355: ENDSCRIPT
1.19 raeburn 7356: }
7357:
7358: sub sectioncheck_alerts {
7359: my %alerts = &Apache::lonlocal::texthash(
1.103 raeburn 7360: curd => 'You must select a course or community in the current domain',
1.19 raeburn 7361: inea => 'In each course, each user may only have one student role at a time',
1.103 raeburn 7362: inco => 'In each community, each user may only have one member role at a time',
1.19 raeburn 7363: youh => 'You had selected',
7364: sect => 'sections',
7365: plsm => 'Please modify your selections so they include no more than one section',
7366: mayn => 'may not be used as the name for a section, as it is a reserved word',
7367: plsc => 'Please choose a different section name',
7368: mayt => 'may not be used as the name for a section, as it is the name of a course group',
1.103 raeburn 7369: mayc => 'may not be used as the name for a section, as it is the name of a community group',
1.19 raeburn 7370: secn => 'Section names and group names must be distinct',
7371: secd => 'Section designations do not apply to ',
7372: role => 'roles',
7373: accr => 'role will be added with access to all sections',
1.103 raeburn 7374: thwa => 'There was a problem with your course selection',
7375: thwc => 'There was a problem with your community selection',
1.19 raeburn 7376: );
1.170 damieng 7377: &js_escape(\%alerts);
1.19 raeburn 7378: return %alerts;
7379: }
1.17 raeburn 7380:
1.37 raeburn 7381: sub authcheck_alerts {
7382: my %alerts =
7383: &Apache::lonlocal::texthash(
7384: authen => 'You must choose an authentication type.',
7385: krb => 'You need to specify the Kerberos domain.',
7386: ipass => 'You need to specify the initial password.',
7387: );
1.170 damieng 7388: &js_escape(\%alerts);
1.37 raeburn 7389: return %alerts;
7390: }
7391:
1.141 raeburn 7392: sub is_courseowner {
7393: my ($thiscourse,$courseowner) = @_;
7394: if ($courseowner eq '') {
7395: if ($env{'request.course.id'} eq $thiscourse) {
7396: $courseowner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
7397: }
7398: }
7399: if ($courseowner ne '') {
7400: if ($courseowner eq $env{'user.name'}.':'.$env{'user.domain'}) {
7401: return 1;
7402: }
7403: }
7404: return;
7405: }
7406:
1.165 raeburn 7407: sub get_selfenroll_titles {
7408: my @row = ('types','registered','enroll_dates','access_dates','section',
7409: 'approval','limit');
7410: my %lt = &Apache::lonlocal::texthash (
7411: types => 'Users allowed to self-enroll',
7412: registered => 'Registration status (official courses)' ,
7413: enroll_dates => 'Dates self-enrollment available',
7414: access_dates => 'Access dates for self-enrolling users',
7415: section => "Self-enrolling users' section",
7416: approval => 'Processing of requests',
7417: limit => 'Enrollment limit',
7418: );
7419: return (\@row,\%lt);
7420: }
7421:
7422: sub selfenroll_default_descs {
7423: my %desc = (
7424: types => {
7425: dom => &mt('Course domain'),
7426: all => &mt('Any domain'),
7427: '' => &mt('None'),
7428: },
7429: limit => {
7430: none => &mt('No limit'),
7431: allstudents => &mt('Limit by total students'),
7432: selfenrolled => &mt('Limit by total self-enrolled'),
7433: },
7434: approval => {
7435: '0' => &mt('Processed automatically'),
7436: '1' => &mt('Queued for approval'),
7437: '2' => &mt('Queued, pending validation'),
7438: },
7439: registered => {
7440: 0 => 'No registration required',
7441: 1 => 'Registered students only',
7442: },
7443: );
7444: return %desc;
7445: }
7446:
7447: sub selfenroll_validation_types {
7448: my @items = ('url','fields','button','markup');
7449: my %names = &Apache::lonlocal::texthash (
7450: url => 'Web address of validation server/script',
7451: fields => 'Form fields to send to validator',
7452: button => 'Text for validation button',
7453: markup => 'Validation description (HTML)',
7454: );
1.167 raeburn 7455: my @fields = ('username','domain','uniquecode','course','coursetype','description');
1.165 raeburn 7456: return (\@items,\%names,\@fields);
7457: }
7458:
7459: sub get_extended_type {
7460: my ($cdom,$cnum,$crstype,$current) = @_;
7461: my $type = 'unofficial';
7462: my %settings;
7463: if (ref($current) eq 'HASH') {
7464: %settings = %{$current};
7465: } else {
7466: %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook'],$cdom,$cnum);
7467: }
7468: if ($crstype eq 'Community') {
7469: $type = 'community';
1.173 raeburn 7470: } elsif ($crstype eq 'Placement') {
7471: $type = 'placement';
1.165 raeburn 7472: } elsif ($settings{'internal.coursecode'}) {
7473: $type = 'official';
7474: } elsif ($settings{'internal.textbook'}) {
7475: $type = 'textbook';
7476: }
7477: return $type;
7478: }
7479:
7480: sub selfenrollment_administration {
7481: my ($cdom,$cnum,$crstype,$coursehash) = @_;
7482: my %settings;
7483: if (ref($coursehash) eq 'HASH') {
7484: %settings = %{$coursehash};
7485: } else {
7486: %settings = &Apache::lonnet::get('environment',
7487: ['internal.selfenrollmgrdc','internal.selfenrollmgrcc',
7488: 'internal.coursecode','internal.textbook'],$cdom,$cnum);
7489: }
7490: my ($possconfigs) = &get_selfenroll_titles();
7491: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
7492: my $selfenrolltype = &get_extended_type($cdom,$cnum,$crstype,\%settings);
7493:
7494: my (@in_course,@in_domain);
7495: if ($settings{'internal.selfenrollmgrcc'} ne '') {
7496: @in_course = split(/,/,$settings{'internal.selfenrollmgrcc'});
7497: my @diffs = &Apache::loncommon::compare_arrays($possconfigs,\@in_course);
7498: unless (@diffs) {
7499: return (\@in_course,\@in_domain);
7500: }
7501: }
7502: if ($settings{'internal.selfenrollmgrdc'} ne '') {
1.215 raeburn 7503: @in_domain = split(/,/,$settings{'internal.selfenrollmgrdc'});
1.165 raeburn 7504: my @diffs = &Apache::loncommon::compare_arrays(\@in_domain,$possconfigs);
7505: unless (@diffs) {
7506: return (\@in_course,\@in_domain);
7507: }
7508: }
7509: my @combined = @in_course;
7510: push(@combined,@in_domain);
7511: my @diffs = &Apache::loncommon::compare_arrays(\@combined,$possconfigs);
7512: unless (@diffs) {
7513: return (\@in_course,\@in_domain);
7514: }
7515: if ($domdefaults{$selfenrolltype.'selfenrolladmdc'} eq '') {
7516: push(@in_course,@diffs);
7517: } else {
7518: my @defaultdc = split(/,/,$domdefaults{$selfenrolltype.'selfenrolladmdc'});
7519: foreach my $item (@diffs) {
7520: if (grep(/^\Q$item\E$/,@defaultdc)) {
7521: push(@in_domain,$item);
7522: } else {
7523: push(@in_course,$item);
7524: }
7525: }
7526: }
7527: return (\@in_course,\@in_domain);
7528: }
7529:
1.175 raeburn 7530: sub custom_role_header {
7531: my ($context,$crstype,$templaterolerefs,$prefix) = @_;
7532: my %lt = &Apache::lonlocal::texthash(
7533: sele => 'Select a Template',
7534: );
7535: my ($context_code,$button_code);
7536: if ($context eq 'domain') {
7537: $context_code = &custom_coursetype_switch($crstype,$prefix);
7538: }
7539: if (ref($templaterolerefs) eq 'ARRAY') {
7540: foreach my $role (@{$templaterolerefs}) {
7541: my $display = 'inline';
7542: if (($context eq 'domain') && ($role eq 'co')) {
7543: $display = 'none';
7544: }
7545: $button_code .= &make_button_code($role,$crstype,$display,$prefix).' ';
7546: }
7547: }
7548: return <<"END";
7549: <div class="LC_left_float">
7550: <fieldset>
7551: <legend>$lt{'sele'}</legend>
7552: $button_code
7553: </fieldset></div>
7554: $context_code
7555: <br clear="all" />
7556: END
7557: }
7558:
7559: sub custom_coursetype_switch {
7560: my ($crstype,$prefix) = @_;
7561: my ($checkedcourse,$checkedcommunity);
7562: if ($crstype eq 'Community') {
7563: $checkedcommunity = ' checked="checked"';
7564: } else {
7565: $checkedcourse = ' checked="checked"';
7566: }
7567: my %lt = &Apache::lonlocal::texthash(
7568: cont => 'Context',
7569: cour => 'Course',
7570: comm => 'Community',
7571: );
7572: return <<"END";
7573: <div class="LC_left_float">
7574: <fieldset>
7575: <legend>$lt{'cont'}</legend>
7576: <label>
7577: <input type="radio" name="${prefix}_custrolecrstype" value="Course"$checkedcourse onclick="javascript:customSwitchType('$prefix');" />
7578: $lt{'cour'}
7579: </label>
7580: <label>
7581: <input type="radio" name="${prefix}_custrolecrstype" value="Community"$checkedcommunity onclick="javascript:customSwitchType('$prefix');" />
7582: $lt{'comm'}
7583: </label>
7584: </fieldset>
7585: </div>
7586: END
7587: }
7588:
7589: sub custom_role_table {
1.180 raeburn 7590: my ($crstype,$full,$levels,$levelscurrent,$prefix,$add_class,$id) = @_;
1.175 raeburn 7591: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7592: (ref($levelscurrent) eq 'HASH'));
7593: my %lt=&Apache::lonlocal::texthash (
7594: 'prv' => "Privilege",
7595: 'crl' => "Course Level",
7596: 'dml' => "Domain Level",
7597: 'ssl' => "System Level");
7598: my %cr = (
7599: course => '_c',
7600: domain => '_d',
7601: system => '_s',
7602: );
7603:
1.180 raeburn 7604: my $output=&Apache::loncommon::start_data_table($add_class,$id).
1.175 raeburn 7605: &Apache::loncommon::start_data_table_header_row().
7606: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
7607: '</th><th>'.$lt{'ssl'}.'</th>'.
7608: &Apache::loncommon::end_data_table_header_row();
7609: foreach my $priv (sort(keys(%{$full}))) {
7610: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7611: $output .= &Apache::loncommon::start_data_table_row().
7612: '<td><span id="'.$prefix.$priv.'">'.$privtext.'</span></td>';
7613: foreach my $type ('course','domain','system') {
7614: if (($type eq 'system') && ($priv eq 'bre') && ($crstype eq 'Community')) {
7615: $output .= '<td> </td>';
7616: } else {
7617: $output .= '<td>'.
7618: ($levels->{$type}{$priv}?'<input type="checkbox" id="'.$prefix.$priv.$cr{$type}.'"'.
7619: ' name="'.$prefix.$priv.$cr{$type}.'"'.
7620: ($levelscurrent->{$type}{$priv}?' checked="checked"':'').' />':' ').
7621: '</td>';
7622: }
7623: }
7624: $output .= &Apache::loncommon::end_data_table_row();
7625: }
7626: $output .= &Apache::loncommon::end_data_table();
7627: return $output;
7628: }
7629:
7630: sub custom_role_privs {
7631: my ($privs,$full,$levels,$levelscurrent)= @_;
7632: return unless ((ref($privs) eq 'HASH') && (ref($full) eq 'HASH') &&
7633: (ref($levels) eq 'HASH') && (ref($levelscurrent) eq 'HASH'));
7634: my %cr = (
7635: course => 'cr:c',
7636: domain => 'cr:d',
7637: system => 'cr:s',
7638: );
7639: foreach my $type ('course','domain','system') {
7640: foreach my $item (split(/\:/,$Apache::lonnet::pr{$cr{$type}})) {
7641: my ($priv,$restrict)=split(/\&/,$item);
7642: if (!$restrict) { $restrict='F'; }
7643: $levels->{$type}->{$priv}=$restrict;
7644: if ($privs->{$type}=~/\:$priv/) {
7645: $levelscurrent->{$type}->{$priv}=1;
7646: }
7647: $full->{$priv}=1;
7648: }
7649: }
7650: return;
7651: }
7652:
7653: sub custom_template_roles {
7654: my ($context,$crstype) = @_;
7655: my @template_roles = ("in","ta","ep");
7656: if (($context eq 'domain') || ($context eq 'domprefs')) {
7657: push(@template_roles,"ad");
7658: }
7659: push(@template_roles,"st");
7660: if ($context eq 'domain') {
7661: unshift(@template_roles,('co','cc'));
7662: } else {
7663: if ($crstype eq 'Community') {
7664: unshift(@template_roles,'co');
7665: } else {
7666: unshift(@template_roles,'cc');
7667: }
7668: }
7669: return @template_roles;
7670: }
7671:
7672: sub custom_roledefs_js {
7673: my ($context,$crstype,$formname,$full,$templaterolesref,$jsback) = @_;
7674: my $button_code = "\n";
7675: my $head_script = "\n";
7676: my (%roletitlestr,$rolenamestr);
7677: my %role_titles = (
7678: Course => [],
7679: Community => [],
7680: );
7681: $head_script .= '<script type="text/javascript">'."\n"
7682: .'// <![CDATA['."\n";
7683: if (ref($templaterolesref) eq 'ARRAY') {
7684: if ($context eq 'domain') {
7685: $rolenamestr = join("','",@{$templaterolesref});
7686: }
7687: foreach my $role (@{$templaterolesref}) {
7688: $head_script .= &make_script_template($role,$crstype,$formname);
7689: if ($context eq 'domain') {
7690: foreach my $type ('Course','Community') {
7691: push(@{$role_titles{$type}},&Apache::lonnet::plaintext($role,$type));
7692: }
7693: }
7694: }
7695: }
7696: if ($context eq 'domain') {
7697: foreach my $type ('Course','Community') {
7698: $roletitlestr{$type} = join("','",@{$role_titles{$type}});
7699: }
7700: my %pt = (
7701: Community => {
7702: cst => &mt('Grant/revoke role of Member'),
7703: mdc => &mt('Edit community contents'),
7704: pch => &mt('Post discussion on community resources'),
7705: pfo => &mt('Print for other users and entire community'),
7706: },
7707: Course => {
7708: cst => &mt('Grant/revoke role of Student'),
7709: mdc => &mt('Edit course contents'),
7710: pch => &mt('Post discussion on course resources'),
7711: pfo => &mt('Print for other users and entire course'),
7712: },
7713: );
7714: $head_script .= <<"ENDJS";
7715: function customSwitchType(prefix) {
7716: var privnames = new Array('cst','mdc','pch','pfo');
7717: var privtxtcrs = new Array('$pt{Course}{cst}','$pt{Course}{mdc}','$pt{Course}{pch}','$pt{Course}{pfo}');
7718: var privtxtcom = new Array('$pt{Community}{cst}','$pt{Community}{mdc}','$pt{Community}{pch}','$pt{Community}{pfo}');
7719: var rolenames = new Array('$rolenamestr');
7720: var rolescrs = new Array('$roletitlestr{Course}');
7721: var rolescom = new Array('$roletitlestr{Community}');
7722: var radio = prefix+'_custrolecrstype';
7723: if (document.$formname.elements[radio].length > 1) {
7724: for (var i=0; i<document.$formname.elements[radio].length; i++) {
7725: if (document.$formname.elements[radio][i].checked) {
7726: if ((document.getElementById(prefix+'bre_s')) && (document.getElementById(prefix+'bro_s'))) {
7727: if (document.$formname.elements[radio][i].value == 'Community') {
7728: if (document.getElementById(prefix+'bre_s').checked) {
7729: document.getElementById(prefix+'bro_s').checked = true;
7730: document.getElementById(prefix+'bre_s').checked = false;
7731:
7732: }
7733: document.getElementById(prefix+'bre_s').style.visibility = 'hidden';
7734: } else {
7735: document.getElementById(prefix+'bre_s').style.visibility = 'visible';
7736: if (document.getElementById(prefix+'bro_s').checked) {
7737: document.getElementById(prefix+'bre_s').checked = true;
7738: document.getElementById(prefix+'bro_s').checked = false;
7739: }
7740: }
7741: }
7742: for (var j=0; j<privnames.length; j++) {
7743: if (document.getElementById(prefix+privnames[j])) {
7744: if (document.getElementById(prefix+privnames[j])) {
7745: if (document.$formname.elements[radio][i].value == 'Course') {
7746: document.getElementById(prefix+privnames[j]).innerHTML = privtxtcrs[j];
7747: } else {
7748: document.getElementById(prefix+privnames[j]).innerHTML = privtxtcom[j];
7749: }
7750: }
7751: }
7752: }
7753: for (var j=0; j<rolenames.length; j++) {
7754: if (document.getElementById(prefix+rolenames[j])) {
7755: if (document.getElementById(prefix+rolenames[j])) {
7756: if (document.$formname.elements[radio][i].value == 'Course') {
7757: document.getElementById(prefix+rolenames[j]).value = rolescrs[j];
7758: if (rolenames[j] == 'cc') {
7759: document.getElementById(prefix+rolenames[j]).style.display = 'inline';
7760: }
7761: if (rolenames[j] == 'co') {
7762: document.getElementById(prefix+rolenames[j]).style.display = 'none';
7763: }
7764: } else {
7765: document.getElementById(prefix+rolenames[j]).value = rolescom[j];
7766: if (rolenames[j] == 'cc') {
7767: document.getElementById(prefix+rolenames[j]).style.display = 'none';
7768: }
7769: if (rolenames[j] == 'co') {
7770: document.getElementById(prefix+rolenames[j]).style.display = 'inline';
7771: }
7772: }
7773: }
7774: }
7775: }
7776: }
7777: }
7778: }
7779: return;
7780: }
7781: ENDJS
7782: }
7783: $head_script .= "\n".$jsback."\n"
7784: .'// ]]>'."\n"
7785: .'</script>'."\n";
7786: return $head_script;
7787: }
7788:
7789: # --------------------------------------------------------
7790: sub make_script_template {
7791: my ($role,$crstype,$formname) = @_;
7792: my $return_script = 'function set_'.$role.'(prefix) {'."\n";
7793: my (%full_by_level,%role_priv);
7794: foreach my $level ('c','d','s') {
7795: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
7796: next if (($level eq 's') && ($crstype eq 'Community') && ($item eq 'bre&S'));
7797: my ($priv,$restrict)=split(/\&/,$item);
7798: $full_by_level{$level}{$priv}=1;
7799: }
7800: $role_priv{$level} = {};
7801: my @temp = split(/:/,$Apache::lonnet::pr{$role.':'.$level});
7802: foreach my $priv (@temp) {
7803: my ($priv_item, $dummy) = split(/\&/,$priv);
7804: $role_priv{$level}{$priv_item} = 1;
7805: }
7806: }
7807: my %to_check = (
7808: c => ['c','d','s'],
7809: d => ['d','s'],
7810: s => ['s'],
7811: );
7812: foreach my $level ('c','d','s') {
7813: if (ref($full_by_level{$level}) eq 'HASH') {
7814: foreach my $priv (keys(%{$full_by_level{$level}})) {
7815: my $value = 'false';
7816: if (ref($to_check{$level}) eq 'ARRAY') {
7817: foreach my $lett (@{$to_check{$level}}) {
7818: if (exists($role_priv{$lett}{$priv})) {
7819: $value = 'true';
7820: last;
7821: }
7822: }
7823: $return_script .= "document.$formname.elements[prefix+'".$priv."_".$level."'].checked = $value;\n";
7824: }
7825: }
7826: }
7827: }
7828: $return_script .= '}'."\n";
7829: return ($return_script);
7830: }
7831: # ----------------------------------------------------------
7832: sub make_button_code {
7833: my ($role,$crstype,$display,$prefix) = @_;
7834: my $label = &Apache::lonnet::plaintext($role,$crstype);
7835: my $button_code = '<input type="button" onclick="set_'.$role."('$prefix'".')" '.
7836: 'id="'.$prefix.$role.'" value="'.$label.'" '.
7837: 'style="display:'.$display.'" />';
7838: return ($button_code);
7839: }
7840:
7841: sub custom_role_update {
7842: my ($rolename,$prefix) = @_;
7843: # ------------------------------------------------------- What can be assigned?
7844: my %privs = (
7845: c => '',
7846: d => '',
7847: s => '',
7848: );
7849: foreach my $level (keys(%privs)) {
7850: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
7851: my ($priv,$restrict)=split(/\&/,$item);
7852: if (!$restrict) { $restrict=''; }
7853: if ($env{'form.'.$prefix.$priv.'_'.$level}) {
7854: $privs{$level} .=':'.$item;
7855: }
7856: }
7857: }
7858: return %privs;
7859: }
7860:
1.180 raeburn 7861: sub adhoc_status_types {
7862: my ($cdom,$context,$role,$selectedref,$othertitle,$usertypes,$types,$disabled) = @_;
7863: my $output = &Apache::loncommon::start_data_table();
7864: my $numinrow = 3;
7865: my $rem;
7866: if (ref($types) eq 'ARRAY') {
7867: for (my $i=0; $i<@{$types}; $i++) {
7868: if (defined($usertypes->{$types->[$i]})) {
7869: my $rem = $i%($numinrow);
7870: if ($rem == 0) {
7871: if ($i > 0) {
7872: $output .= &Apache::loncommon::end_data_table_row();
7873: }
7874: $output .= &Apache::loncommon::start_data_table_row();
7875: }
7876: my $check;
7877: if (ref($selectedref) eq 'ARRAY') {
7878: if (grep(/^\Q$types->[$i]\E$/,@{$selectedref})) {
7879: $check = ' checked="checked"';
7880: }
7881: }
7882: $output .= '<td>'.
7883: '<span class="LC_nobreak"><label>'.
7884: '<input type="checkbox" name="'.$context.$role.'_status" '.
7885: 'value="'.$types->[$i].'"'.$check.$disabled.' />'.
7886: $usertypes->{$types->[$i]}.'</label></span></td>';
7887: }
7888: }
7889: $rem = @{$types}%($numinrow);
7890: }
7891: my $colsleft = $numinrow - $rem;
7892: if (($rem == 0) && (@{$types} > 0)) {
7893: $output .= &Apache::loncommon::start_data_table_row();
7894: }
7895: if ($colsleft > 1) {
7896: $output .= '<td colspan="'.$colsleft.'">';
7897: } else {
7898: $output .= '<td>';
7899: }
7900: my $defcheck;
7901: if (ref($selectedref) eq 'ARRAY') {
7902: if (grep(/^default$/,@{$selectedref})) {
7903: $defcheck = ' checked="checked"';
7904: }
7905: }
7906: $output .= '<span class="LC_nobreak"><label>'.
7907: '<input type="checkbox" name="'.$context.$role.'_status"'.
7908: 'value="default"'.$defcheck.$disabled.' />'.
7909: $othertitle.'</label></span></td>'.
7910: &Apache::loncommon::end_data_table_row().
7911: &Apache::loncommon::end_data_table();
7912: return $output;
7913: }
7914:
7915: sub adhoc_staff {
7916: my ($access,$context,$role,$selectedref,$adhocref,$disabled) = @_;
7917: my $output;
7918: if (ref($adhocref) eq 'HASH') {
7919: my %by_fullname;
7920: my $numinrow = 4;
7921: my $rem;
7922: my @personnel = keys(%{$adhocref});
7923: if (@personnel) {
7924: foreach my $person (@personnel) {
7925: my ($uname,$udom) = split(/:/,$person);
7926: my $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
7927: $by_fullname{$fullname} = $person;
7928: }
7929: my @sorted = sort(keys(%by_fullname));
7930: my $count = scalar(@sorted);
7931: $output = &Apache::loncommon::start_data_table();
7932: for (my $i=0; $i<$count; $i++) {
7933: my $rem = $i%($numinrow);
7934: if ($rem == 0) {
7935: if ($i > 0) {
7936: $output .= &Apache::loncommon::end_data_table_row();
7937: }
7938: $output .= &Apache::loncommon::start_data_table_row();
7939: }
7940: my $check;
7941: my $user = $by_fullname{$sorted[$i]};
7942: if (ref($selectedref) eq 'ARRAY') {
7943: if (grep(/^\Q$user\E$/,@{$selectedref})) {
7944: $check = ' checked="checked"';
7945: }
7946: }
7947: if ($i == $count-1) {
7948: my $colsleft = $numinrow - $rem;
7949: if ($colsleft > 1) {
7950: $output .= '<td colspan="'.$colsleft.'">';
7951: } else {
7952: $output .= '<td>';
7953: }
7954: } else {
7955: $output .= '<td>';
7956: }
7957: $output .= '<span class="LC_nobreak"><label>'.
7958: '<input type="checkbox" name="'.$context.$role.'_staff_'.$access.'" '.
7959: 'value="'.$user.'"'.$check.$disabled.' />'.$sorted[$i].
7960: '</label></span></td>';
7961: if ($i == $count-1) {
7962: $output .= &Apache::loncommon::end_data_table_row();
7963: }
7964: }
7965: $output .= &Apache::loncommon::end_data_table();
7966: }
7967: }
7968: return $output;
7969: }
7970:
1.225 ! raeburn 7971: sub get_othdom_shownfields {
! 7972: my ($dom,$userinfo) = @_;
! 7973: return unless (ref($userinfo) eq 'ARRAY');
! 7974: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
! 7975: my @insttypes;
! 7976: if (ref($domdefaults{'inststatustypes'}) eq 'HASH') {
! 7977: @insttypes = keys(%{$domdefaults{'inststatustypes'}});
! 7978: }
! 7979: push(@insttypes,'default');
! 7980: my %shownfields;
! 7981: if (ref($domdefaults{'privacyothdom'}) eq 'HASH') {
! 7982: %shownfields = %{$domdefaults{'privacyothdom'}};
! 7983: } else {
! 7984: foreach my $type (@insttypes) {
! 7985: foreach my $field (@{$userinfo}) {
! 7986: $shownfields{$type}{$field} = 1;
! 7987: }
! 7988: }
! 7989: }
! 7990: return %shownfields;
! 7991: }
1.180 raeburn 7992:
1.1 raeburn 7993: 1;
7994:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>