File:
[LON-CAPA] /
loncom /
interface /
lonuserutils.pm
Revision
1.78:
download - view:
text,
annotated -
select for diffs
Mon Jan 5 05:31:03 2009 UTC (15 years, 7 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
Bug 5807.
- A 'Display List of Users' button is shown the first time the List Users page is displayed. No users are shown at this stage.
- Thereafter the button reverts to 'Update Display', and users are listed based on the selected criteria.
1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
4: # $Id: lonuserutils.pm,v 1.78 2009/01/05 05:31:03 raeburn Exp $
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:
33: use strict;
34: use Apache::lonnet;
35: use Apache::loncommon();
36: use Apache::lonhtmlcommon;
37: use Apache::lonlocal;
38: use Apache::longroup;
39: use LONCAPA qw(:DEFAULT :match);
40:
41: ###############################################################
42: ###############################################################
43: # Drop student from all sections of a course, except optional $csec
44: sub modifystudent {
45: my ($udom,$unam,$courseid,$csec,$desiredhost,$context)=@_;
46: # if $csec is undefined, drop the student from all the courses matching
47: # this one. If $csec is defined, drop them from all other sections of
48: # this course and add them to section $csec
49: my ($cnum,$cdom) = &get_course_identity($courseid);
50: my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
51: my ($tmp) = keys(%roles);
52: # Bail out if we were unable to get the students roles
53: return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
54: # Go through the roles looking for enrollment in this course
55: my $result = '';
56: foreach my $course (keys(%roles)) {
57: if ($course=~m{^/\Q$cdom\E/\Q$cnum\E(?:\/)*(?:\s+)*(\w+)*\_st$}) {
58: # We are in this course
59: my $section=$1;
60: $section='' if ($course eq "/$cdom/$cnum".'_st');
61: if (defined($csec) && $section eq $csec) {
62: $result .= 'ok:';
63: } elsif ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
64: my (undef,$end,$start)=split(/\_/,$roles{$course});
65: my $now=time;
66: # if this is an active role
67: if (!($start && ($now<$start)) || !($end && ($now>$end))) {
68: my $reply=&Apache::lonnet::modifystudent
69: # dom name id mode pass f m l g
70: ($udom,$unam,'', '', '',undef,undef,undef,undef,
71: $section,time,undef,undef,$desiredhost,'','manual',
72: '',$courseid,'',$context);
73: $result .= $reply.':';
74: }
75: }
76: }
77: }
78: if ($result eq '') {
79: $result = &mt('Unable to find section for this student');
80: } else {
81: $result =~ s/(ok:)+/ok/g;
82: }
83: return $result;
84: }
85:
86: sub modifyuserrole {
87: my ($context,$setting,$changeauth,$cid,$udom,$uname,$uid,$umode,$upass,
88: $first,$middle,$last,$gene,$sec,$forceid,$desiredhome,$email,$role,
89: $end,$start,$checkid) = @_;
90: my ($scope,$userresult,$authresult,$roleresult,$idresult);
91: if ($setting eq 'course' || $context eq 'course') {
92: $scope = '/'.$cid;
93: $scope =~ s/\_/\//g;
94: if ($role ne 'cc' && $sec ne '') {
95: $scope .='/'.$sec;
96: }
97: } elsif ($context eq 'domain') {
98: $scope = '/'.$env{'request.role.domain'}.'/';
99: } elsif ($context eq 'author') {
100: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
101: }
102: if ($context eq 'domain') {
103: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
104: if ($uhome ne 'no_host') {
105: if (($changeauth eq 'Yes') && (&Apache::lonnet::allowed('mau',$udom))) {
106: if ((($umode =~ /^krb4|krb5|internal$/) && $upass ne '') ||
107: ($umode eq 'localauth')) {
108: $authresult = &Apache::lonnet::modifyuserauth($udom,$uname,$umode,$upass);
109: }
110: }
111: if (($forceid) && (&Apache::lonnet::allowed('mau',$udom)) &&
112: ($env{'form.recurseid'}) && ($checkid)) {
113: my %userupdate = (
114: lastname => $last,
115: middlename => $middle,
116: firstname => $first,
117: generation => $gene,
118: id => $uid,
119: );
120: $idresult = &propagate_id_change($uname,$udom,\%userupdate);
121: }
122: }
123: }
124: $userresult =
125: &Apache::lonnet::modifyuser($udom,$uname,$uid,$umode,$upass,$first,
126: $middle,$last,$gene,$forceid,$desiredhome,
127: $email,$role,$start,$end);
128: if ($userresult eq 'ok') {
129: if ($role ne '') {
130: $role =~ s/_/\//g;
131: $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
132: $role,$end,$start,'',
133: '',$context);
134: }
135: }
136: return ($userresult,$authresult,$roleresult,$idresult);
137: }
138:
139: sub propagate_id_change {
140: my ($uname,$udom,$user) = @_;
141: my (@types,@roles);
142: @types = ('active','future');
143: @roles = ('st');
144: my $idresult;
145: my %roleshash = &Apache::lonnet::get_my_roles($uname,
146: $udom,'userroles',\@types,\@roles);
147: my %args = (
148: one_time => 1,
149: );
150: foreach my $item (keys(%roleshash)) {
151: my ($cnum,$cdom,$role) = split(/:/,$item,-1);
152: my ($start,$end) = split(/:/,$roleshash{$item});
153: if (&Apache::lonnet::is_course($cdom,$cnum)) {
154: my $result = &update_classlist($cdom,$cnum,$udom,$uname,$user);
155: my %coursehash =
156: &Apache::lonnet::coursedescription($cdom.'_'.$cnum,\%args);
157: my $cdesc = $coursehash{'description'};
158: if ($cdesc eq '') {
159: $cdesc = $cdom.'_'.$cnum;
160: }
161: if ($result eq 'ok') {
162: $idresult .= &mt('Classlist update for "[_1]" in "[_2]".',$uname.':'.$udom,$cdesc).'<br />'."\n";
163: } else {
164: $idresult .= &mt('Error: "[_1]" during classlist update for "[_2]" in "[_3]".',$result,$uname.':'.$udom,$cdesc).'<br />'."\n";
165: }
166: }
167: }
168: return $idresult;
169: }
170:
171: sub update_classlist {
172: my ($cdom,$cnum,$udom,$uname,$user,$newend) = @_;
173: my ($uid,$classlistentry);
174: my $fullname =
175: &Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
176: $user->{'lastname'},$user->{'generation'},
177: 'lastname');
178: my %classhash = &Apache::lonnet::get('classlist',[$uname.':'.$udom],
179: $cdom,$cnum);
180: my @classinfo = split(/:/,$classhash{$uname.':'.$udom});
181: my $ididx=&Apache::loncoursedata::CL_ID() - 2;
182: my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2;
183: my $endidx = &Apache::loncoursedata::CL_END() - 2;
184: my $startidx = &Apache::loncoursedata::CL_START() - 2;
185: for (my $i=0; $i<@classinfo; $i++) {
186: if ($i == $endidx) {
187: if ($newend ne '') {
188: $classlistentry .= $newend.':';
189: } else {
190: $classlistentry .= $classinfo[$i].':';
191: }
192: } elsif ($i == $startidx) {
193: if ($newend ne '') {
194: if ($classinfo[$i] > $newend) {
195: $classlistentry .= $newend.':';
196: } else {
197: $classlistentry .= $classinfo[$i].':';
198: }
199: } else {
200: $classlistentry .= $classinfo[$i].':';
201: }
202: } elsif ($i == $ididx) {
203: if (defined($user->{'id'})) {
204: $classlistentry .= $user->{'id'}.':';
205: } else {
206: $classlistentry .= $classinfo[$i].':';
207: }
208: } elsif ($i == $nameidx) {
209: if (defined($user->{'lastname'})) {
210: $classlistentry .= $fullname.':';
211: } else {
212: $classlistentry .= $classinfo[$i].':';
213: }
214: } else {
215: $classlistentry .= $classinfo[$i].':';
216: }
217: }
218: $classlistentry =~ s/:$//;
219: my $reply=&Apache::lonnet::cput('classlist',
220: {"$uname:$udom" => $classlistentry},
221: $cdom,$cnum);
222: if (($reply eq 'ok') || ($reply eq 'delayed')) {
223: return 'ok';
224: } else {
225: return 'error: '.$reply;
226: }
227: }
228:
229:
230: ###############################################################
231: ###############################################################
232: # build a role type and role selection form
233: sub domain_roles_select {
234: # Set up the role type and role selection boxes when in
235: # domain context
236: #
237: # Role types
238: my @roletypes = ('domain','author','course');
239: my %lt = &role_type_names();
240: #
241: # build up the menu information to be passed to
242: # &Apache::loncommon::linked_select_forms
243: my %select_menus;
244: if ($env{'form.roletype'} eq '') {
245: $env{'form.roletype'} = 'domain';
246: }
247: foreach my $roletype (@roletypes) {
248: # set up the text for this domain
249: $select_menus{$roletype}->{'text'}= $lt{$roletype};
250: # we want a choice of 'default' as the default in the second menu
251: if ($env{'form.roletype'} ne '') {
252: $select_menus{$roletype}->{'default'} = $env{'form.showrole'};
253: } else {
254: $select_menus{$roletype}->{'default'} = 'Any';
255: }
256: # Now build up the other items in the second menu
257: my @roles;
258: if ($roletype eq 'domain') {
259: @roles = &domain_roles();
260: } elsif ($roletype eq 'author') {
261: @roles = &construction_space_roles();
262: } else {
263: my $custom = 1;
264: @roles = &course_roles('domain',undef,$custom);
265: }
266: my $order = ['Any',@roles];
267: $select_menus{$roletype}->{'order'} = $order;
268: foreach my $role (@roles) {
269: if ($role eq 'cr') {
270: $select_menus{$roletype}->{'select2'}->{$role} =
271: &mt('Custom role');
272: } else {
273: $select_menus{$roletype}->{'select2'}->{$role} =
274: &Apache::lonnet::plaintext($role);
275: }
276: }
277: $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
278: }
279: my $result = &Apache::loncommon::linked_select_forms
280: ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
281: 'roletype','showrole',\%select_menus,['domain','author','course']);
282: return $result;
283: }
284:
285: ###############################################################
286: ###############################################################
287: sub hidden_input {
288: my ($name,$value) = @_;
289: return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n";
290: }
291:
292: sub print_upload_manager_header {
293: my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission)=@_;
294: my $javascript;
295: #
296: if (! exists($env{'form.upfile_associate'})) {
297: $env{'form.upfile_associate'} = 'forward';
298: }
299: if ($env{'form.associate'} eq 'Reverse Association') {
300: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
301: $env{'form.upfile_associate'} = 'reverse';
302: } else {
303: $env{'form.upfile_associate'} = 'forward';
304: }
305: }
306: if ($env{'form.upfile_associate'} eq 'reverse') {
307: $javascript=&upload_manager_javascript_reverse_associate();
308: } else {
309: $javascript=&upload_manager_javascript_forward_associate();
310: }
311: #
312: # Deal with restored settings
313: my $password_choice = '';
314: if (exists($env{'form.ipwd_choice'}) &&
315: $env{'form.ipwd_choice'} ne '') {
316: # If a column was specified for password, assume it is for an
317: # internal password. This is a bug waiting to be filed (could be
318: # local or krb auth instead of internal) but I do not have the
319: # time to mess around with this now.
320: $password_choice = 'int';
321: }
322: #
323: my $groupslist;
324: if ($context eq 'course') {
325: $groupslist = &get_groupslist();
326: }
327: my $javascript_validations =
328: &javascript_validations('upload',$krbdefdom,$password_choice,undef,
329: $env{'request.role.domain'},$context,
330: $groupslist);
331: my $checked=(($env{'form.noFirstLine'})?' checked="checked" ':'');
332: $r->print(&mt('Total number of records found in file: [_1]','<b>'.$distotal.'</b>').
333: "<br />\n");
334: $r->print('<div class="LC_left_float"><h3>'.
335: &mt('Identify fields in uploaded list')."</h3>\n");
336: $r->print(&mt('Enter as many fields as you can.<br /> The system will inform you and bring you back to this page, <br /> if the data selected are insufficient to add users.')."<br />\n");
337: $r->print(&hidden_input('action','upload').
338: &hidden_input('state','got_file').
339: &hidden_input('associate','').
340: &hidden_input('datatoken',$datatoken).
341: &hidden_input('fileupload',$env{'form.fileupload'}).
342: &hidden_input('upfiletype',$env{'form.upfiletype'}).
343: &hidden_input('upfile_associate',$env{'form.upfile_associate'}));
344: $r->print('<br /><label><input type="checkbox" name="noFirstLine"'.$checked.'/>'.
345: &mt('Ignore First Line').'</label><br />');
346: $r->print('<br /><input type="button" value="'.&mt('Reverse Association').'" '.
347: 'name="Reverse Association" '.
348: 'onClick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />');
349: $r->print("<br /><br />\n".
350: '<script type="text/javascript" language="Javascript">'."\n".
351: $javascript."\n".$javascript_validations.'</script>');
352: }
353:
354: ###############################################################
355: ###############################################################
356: sub javascript_validations {
357: my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain,
358: $context,$groupslist)=@_;
359: my %param = (
360: kerb_def_dom => $krbdefdom,
361: curr_authtype => $curr_authtype,
362: );
363: if ($mode eq 'upload') {
364: $param{'formname'} = 'studentform';
365: } elsif ($mode eq 'createcourse') {
366: $param{'formname'} = 'ccrs';
367: } elsif ($mode eq 'modifycourse') {
368: $param{'formname'} = 'cmod';
369: $param{'mode'} = 'modifycourse',
370: $param{'curr_autharg'} = $curr_authfield;
371: }
372:
373: my ($setsection_call,$setsections_js);
374: my $finish = " vf.submit();\n";
375: if ($mode eq 'upload') {
376: if (($context eq 'course') || ($context eq 'domain')) {
377: if ($context eq 'course') {
378: if ($env{'request.course.sec'} eq '') {
379: $setsection_call = 'setSections(document.'.$param{'formname'}.');';
380: $setsections_js =
381: &setsections_javascript($param{'formname'},$groupslist,
382: $mode);
383: } else {
384: $setsection_call = "'ok'";
385: }
386: } elsif ($context eq 'domain') {
387: $setsection_call = 'setCourse()';
388: $setsections_js = &dc_setcourse_js($param{'formname'},$mode,$context);
389: }
390: $finish = " var checkSec = $setsection_call\n".
391: " if (checkSec == 'ok') {\n".
392: " vf.submit();\n".
393: " }\n";
394: }
395: }
396: my $authheader = &Apache::loncommon::authform_header(%param);
397:
398: my %alert = &Apache::lonlocal::texthash
399: (username => 'You need to specify the username field.',
400: authen => 'You must choose an authentication type.',
401: krb => 'You need to specify the Kerberos domain.',
402: ipass => 'You need to specify the initial password.',
403: name => 'The optional name field was not specified.',
404: snum => 'The optional ID number field was not specified.',
405: section => 'The optional section field was not specified.',
406: email => 'The optional e-mail address field was not specified.',
407: role => 'The optional role field was not specified.',
408: domain => 'The optional domain field was not specified.',
409: continue => 'Continue adding users?',
410: );
411: my $function_name = <<"END";
412: $setsections_js
413:
414: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain) {
415: END
416: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($domain);
417: my $auth_checks;
418: if ($mode eq 'createcourse') {
419: $auth_checks .= (<<END);
420: if (vf.autoadds[0].checked == true) {
421: if (current.radiovalue == null || current.radiovalue == 'nochange') {
422: alert('$alert{'authen'}');
423: return;
424: }
425: }
426: END
427: } else {
428: $auth_checks .= (<<END);
429: var foundatype=0;
430: if (founduname==0) {
431: alert('$alert{'username'}');
432: return;
433: }
434:
435: END
436: if ($authnum > 1) {
437: $auth_checks .= (<<END);
438: if (current.radiovalue == null || current.radiovalue == '' || current.radiovalue == 'nochange') {
439: // They did not check any of the login radiobuttons.
440: alert('$alert{'authen'}');
441: return;
442: }
443: END
444: }
445: }
446: if ($mode eq 'createcourse') {
447: $auth_checks .= "
448: if ( (vf.autoadds[0].checked == true) &&
449: (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') ) {
450: ";
451: } elsif ($mode eq 'modifycourse') {
452: $auth_checks .= "
453: if (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') {
454: ";
455: }
456: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
457: $auth_checks .= (<<END);
458: var alertmsg = '';
459: switch (current.radiovalue) {
460: case 'krb':
461: alertmsg = '$alert{'krb'}';
462: break;
463: default:
464: alertmsg = '';
465: }
466: if (alertmsg != '') {
467: alert(alertmsg);
468: return;
469: }
470: }
471: END
472: } else {
473: $auth_checks .= (<<END);
474: foundatype=1;
475: if (current.argfield == null || current.argfield == '') {
476: var alertmsg = '';
477: switch (current.radiovalue) {
478: case 'krb':
479: alertmsg = '$alert{'krb'}';
480: break;
481: case 'loc':
482: case 'fsys':
483: alertmsg = '$alert{'ipass'}';
484: break;
485: case 'fsys':
486: alertmsg = '';
487: break;
488: default:
489: alertmsg = '';
490: }
491: if (alertmsg != '') {
492: alert(alertmsg);
493: return;
494: }
495: }
496: END
497: }
498: my $section_checks;
499: my $optional_checks = '';
500: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
501: $optional_checks = (<<END);
502: vf.submit();
503: }
504: END
505: } else {
506: $section_checks = §ion_check_js();
507: $optional_checks = (<<END);
508: var message='';
509: if (foundname==0) {
510: message='$alert{'name'}';
511: }
512: if (foundid==0) {
513: if (message!='') {
514: message+='\\n';
515: }
516: message+='$alert{'snum'}';
517: }
518: if (foundsec==0) {
519: if (message!='') {
520: message+='\\n';
521: }
522: }
523: if (foundemail==0) {
524: if (message!='') {
525: message+='\\n';
526: }
527: message+='$alert{'email'}';
528: }
529: if (foundrole==0) {
530: if (message!='') {
531: message+='\\n';
532: }
533: message+='$alert{'role'}';
534: }
535: if (founddomain==0) {
536: if (message!='') {
537: message+='\\n';
538: }
539: message+='$alert{'domain'}';
540: }
541: if (message!='') {
542: message+= '\\n$alert{'continue'}';
543: if (confirm(message)) {
544: vf.state.value='enrolling';
545: $finish
546: }
547: } else {
548: vf.state.value='enrolling';
549: $finish
550: }
551: }
552: END
553: }
554: my $result = $function_name.$auth_checks.$optional_checks."\n".
555: $section_checks.$authheader;
556: return $result;
557: }
558: ###############################################################
559: ###############################################################
560: sub upload_manager_javascript_forward_associate {
561: return(<<ENDPICK);
562: function verify(vf,sec_caller) {
563: var founduname=0;
564: var foundpwd=0;
565: var foundname=0;
566: var foundid=0;
567: var foundsec=0;
568: var foundemail=0;
569: var foundrole=0;
570: var founddomain=0;
571: var tw;
572: for (i=0;i<=vf.nfields.value;i++) {
573: tw=eval('vf.f'+i+'.selectedIndex');
574: if (tw==1) { founduname=1; }
575: if ((tw>=2) && (tw<=6)) { foundname=1; }
576: if (tw==7) { foundid=1; }
577: if (tw==8) { foundsec=1; }
578: if (tw==9) { foundpwd=1; }
579: if (tw==10) { foundemail=1; }
580: if (tw==11) { foundrole=1; }
581: if (tw==12) { founddomain=1; }
582: }
583: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain);
584: }
585:
586: //
587: // vf = this.form
588: // tf = column number
589: //
590: // values of nw
591: //
592: // 0 = none
593: // 1 = username
594: // 2 = names (lastname, firstnames)
595: // 3 = fname (firstname)
596: // 4 = mname (middlename)
597: // 5 = lname (lastname)
598: // 6 = gen (generation)
599: // 7 = id
600: // 8 = section
601: // 9 = ipwd (password)
602: // 10 = email address
603: // 11 = role
604: // 12 = domain
605:
606: function flip(vf,tf) {
607: var nw=eval('vf.f'+tf+'.selectedIndex');
608: var i;
609: // make sure no other columns are labeled the same as this one
610: for (i=0;i<=vf.nfields.value;i++) {
611: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
612: eval('vf.f'+i+'.selectedIndex=0;')
613: }
614: }
615: // If we set this to 'lastname, firstnames', clear out all the ones
616: // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
617: if (nw==2) {
618: for (i=0;i<=vf.nfields.value;i++) {
619: if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
620: (eval('vf.f'+i+'.selectedIndex')<=6)) {
621: eval('vf.f'+i+'.selectedIndex=0;')
622: }
623: }
624: }
625: // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
626: // clear out any that are set to 'lastname, firstnames' (2)
627: if ((nw>=3) && (nw<=6)) {
628: for (i=0;i<=vf.nfields.value;i++) {
629: if (eval('vf.f'+i+'.selectedIndex')==2) {
630: eval('vf.f'+i+'.selectedIndex=0;')
631: }
632: }
633: }
634: // If we set the password, make the password form below correspond to
635: // the new value.
636: if (nw==9) {
637: changed_radio('int',document.studentform);
638: set_auth_radio_buttons('int',document.studentform);
639: vf.intarg.value='';
640: vf.krbarg.value='';
641: vf.locarg.value='';
642: }
643: }
644:
645: function clearpwd(vf) {
646: var i;
647: for (i=0;i<=vf.nfields.value;i++) {
648: if (eval('vf.f'+i+'.selectedIndex')==9) {
649: eval('vf.f'+i+'.selectedIndex=0;')
650: }
651: }
652: }
653:
654: ENDPICK
655: }
656:
657: ###############################################################
658: ###############################################################
659: sub upload_manager_javascript_reverse_associate {
660: return(<<ENDPICK);
661: function verify(vf,sec_caller) {
662: var founduname=0;
663: var foundpwd=0;
664: var foundname=0;
665: var foundid=0;
666: var foundsec=0;
667: var foundrole=0;
668: var founddomain=0;
669: var tw;
670: for (i=0;i<=vf.nfields.value;i++) {
671: tw=eval('vf.f'+i+'.selectedIndex');
672: if (i==0 && tw!=0) { founduname=1; }
673: if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
674: if (i==6 && tw!=0) { foundid=1; }
675: if (i==7 && tw!=0) { foundsec=1; }
676: if (i==8 && tw!=0) { foundpwd=1; }
677: if (i==9 && tw!=0) { foundrole=1; }
678: if (i==10 && tw!=0) { founddomain=1; }
679: }
680: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundrole,founddomain);
681: }
682:
683: function flip(vf,tf) {
684: var nw=eval('vf.f'+tf+'.selectedIndex');
685: var i;
686: // picked the all one name field, reset the other name ones to blank
687: if (tf==1 && nw!=0) {
688: for (i=2;i<=5;i++) {
689: eval('vf.f'+i+'.selectedIndex=0;')
690: }
691: }
692: //picked one of the piecewise name fields, reset the all in
693: //one field to blank
694: if ((tf>=2) && (tf<=5) && (nw!=0)) {
695: eval('vf.f1.selectedIndex=0;')
696: }
697: // intial password specified, pick internal authentication
698: if (tf==8 && nw!=0) {
699: changed_radio('int',document.studentform);
700: set_auth_radio_buttons('int',document.studentform);
701: vf.krbarg.value='';
702: vf.intarg.value='';
703: vf.locarg.value='';
704: }
705: }
706:
707: function clearpwd(vf) {
708: var i;
709: if (eval('vf.f8.selectedIndex')!=0) {
710: eval('vf.f8.selectedIndex=0;')
711: }
712: }
713: ENDPICK
714: }
715:
716: ###############################################################
717: ###############################################################
718: sub print_upload_manager_footer {
719: my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context,$permission) = @_;
720: my $form = 'document.studentform';
721: my $formname = 'studentform';
722: my ($krbdef,$krbdefdom) =
723: &Apache::loncommon::get_kerberos_defaults($defdom);
724: my %param = ( formname => $form,
725: kerb_def_dom => $krbdefdom,
726: kerb_def_auth => $krbdef
727: );
728: if (exists($env{'form.ipwd_choice'}) &&
729: defined($env{'form.ipwd_choice'}) &&
730: $env{'form.ipwd_choice'} ne '') {
731: $param{'curr_authtype'} = 'int';
732: }
733: my $krbform = &Apache::loncommon::authform_kerberos(%param);
734: my $intform = &Apache::loncommon::authform_internal(%param);
735: my $locform = &Apache::loncommon::authform_local(%param);
736: my $date_table = &date_setting_table(undef,undef,$context,undef,
737: $formname,$permission);
738: my $Str = "\n".'<div class="LC_left_float">';
739: $Str .= &hidden_input('nfields',$i);
740: $Str .= &hidden_input('keyfields',$keyfields);
741: $Str .= "<h3>".&mt('Login Type')."</h3>\n";
742: if ($context eq 'domain') {
743: $Str .= '<p>'.&mt('Change authentication for existing users in domain "[_1]" to these settings?',$defdom).' <span class="LC_nobreak"><label><input type="radio" name="changeauth" value="No" checked="checked" />'.&mt('No').'</label> <label><input type="radio" name="changeauth" value="Yes" />'.&mt('Yes').'</label></span></p>';
744: } else {
745: $Str .= "<p>\n".
746: &mt('Note: This will not take effect if the user already exists.').
747: &Apache::loncommon::help_open_topic('Auth_Options').
748: "</p>\n";
749: }
750: $Str .= &set_login($defdom,$krbform,$intform,$locform);
751: my ($home_server_pick,$numlib) =
752: &Apache::loncommon::home_server_form_item($defdom,'lcserver',
753: 'default','hide');
754: if ($numlib > 1) {
755: $Str .= '<h3>'.&mt('LON-CAPA Home Server for New Users')."</h3>\n".
756: &mt('LON-CAPA domain: [_1] with home server: [_2]',$defdom,
757: $home_server_pick).'<br />';
758: } else {
759: $Str .= $home_server_pick;
760: }
761: $Str .= '<h3>'.&mt('Default domain').'</h3>'."\n".
762: &Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1);
763: $Str .= '<h3>'.&mt('Starting and Ending Dates').
764: "</h3>\n";
765: $Str .= "<p>\n".$date_table."</p>\n";
766: if ($context eq 'domain') {
767: $Str .= '<h3>'.&mt('Settings for assigning roles:').'</h3>'."\n".
768: &mt('Pick the action to take on roles for these users:').'<br /><span class="LC_nobreak"><label><input type="radio" name="roleaction" value="norole" checked="checked" /> '.&mt('No role changes').'</label> <label><input type="radio" name="roleaction" value="domain" /> '.&mt('Add a domain role').'</label> <label><input type="radio" name="roleaction" value="course" /> '.&mt('Add a course role').'</label></span>';
769: }
770: if ($context eq 'author') {
771: $Str .= '<h3>'.&mt('Default role')."</h3>\n".
772: &mt('Choose the role to assign to users without a value specified in the uploaded file');
773: } elsif ($context eq 'course') {
774: $Str .= '<h3>'.&mt('Default role and section')."</h3>\n".
775: &mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file');
776: } else {
777: $Str .= '<br /><br /><b>'.&mt('Default role and/or section(s)')."</b><br />\n".
778: &mt('Role and/or section(s) for users without values specified in the uploaded file.');
779: }
780: $Str .= '<br />';
781: if (($context eq 'domain') || ($context eq 'author')) {
782: my ($options,$cb_script,$coursepick) = &default_role_selector($context,1);
783: if ($context eq 'domain') {
784: $Str .= '<span class="LC_role_level">'.&mt('Domain Level').'</span><br />'.$options.'<br /><br /><span class="LC_role_level">'.&mt('Course Level').'</span><br />'.$cb_script.$coursepick;
785: } elsif ($context eq 'author') {
786: $Str .= $options;
787: }
788: } else {
789: my ($cnum,$cdom) = &get_course_identity();
790: my $rowtitle = &mt('section');
791: my $secbox = §ion_picker($cdom,$cnum,'Any',$rowtitle,
792: $permission,$context,'upload');
793: $Str .= $secbox."<h3>".&mt('Full Update')."</h3>\n".
794: '<p><label><input type="checkbox" name="fullup" value="yes">'.
795: ' '.&mt('Display students with current/future access who are not in the uploaded file.').'</label><br />'.&mt('Students selected from this list can be dropped.').'</p>'."\n";
796: }
797: if ($context eq 'course' || $context eq 'domain') {
798: $Str .= &forceid_change($context);
799: }
800: $Str .= '</div>';
801: $Str .= '<div class="LC_clear_float_footer">';
802: if ($context eq 'course') {
803: $Str .= '<div class="LC_info">'
804: .&mt('Note: For large courses, this operation may be time consuming.')
805: .'</div>';
806: }
807: $Str .= '<input type="button"'
808: .'onClick="javascript:verify(this.form,this.form.csec)" '
809: .'value="'.&mt('Update Users').'" />'."\n"
810: .'</div>';
811: $r->print($Str);
812: return;
813: }
814:
815: sub forceid_change {
816: my ($context) = @_;
817: my $output =
818: "<h3>".&mt('Student/Employee ID')."</h3>\n".
819: "<p>\n".'<label><input type="checkbox" name="forceid" value="yes">'.
820: &mt('Disable Student/Employee ID Safeguard and force change of conflicting IDs').
821: '</label><br />'."\n".
822: &mt('(only do if you know what you are doing.)')."\n";
823: if ($context eq 'domain') {
824: $output .= '<br /><label><input type="checkbox" name="recurseid"'.
825: ' value="yes">'.
826: &mt('Update Student/Employee ID in courses in which user is active/future student,[_1](if forcing change).','<br />').
827: '</label>'."\n";
828: }
829: $output .= '</p>';
830: return $output;
831: }
832:
833: ###############################################################
834: ###############################################################
835: sub print_upload_manager_form {
836: my ($r,$context,$permission) = @_;
837: my $firstLine;
838: my $datatoken;
839: if (!$env{'form.datatoken'}) {
840: $datatoken=&Apache::loncommon::upfile_store($r);
841: } else {
842: $datatoken=$env{'form.datatoken'};
843: &Apache::loncommon::load_tmp_file($r);
844: }
845: my @records=&Apache::loncommon::upfile_record_sep();
846: if($env{'form.noFirstLine'}){
847: $firstLine=shift(@records);
848: }
849: my $total=$#records;
850: my $distotal=$total+1;
851: my $today=time;
852: my $halfyear=$today+15552000;
853: #
854: # Restore memorized settings
855: my $col_setting_names = { 'username_choice' => 'scalar', # column settings
856: 'names_choice' => 'scalar',
857: 'fname_choice' => 'scalar',
858: 'mname_choice' => 'scalar',
859: 'lname_choice' => 'scalar',
860: 'gen_choice' => 'scalar',
861: 'id_choice' => 'scalar',
862: 'sec_choice' => 'scalar',
863: 'ipwd_choice' => 'scalar',
864: 'email_choice' => 'scalar',
865: 'role_choice' => 'scalar',
866: 'domain_choice' => 'scalar',
867: };
868: my $defdom = $env{'request.role.domain'};
869: if ($context eq 'course') {
870: &Apache::loncommon::restore_course_settings('enrollment_upload',
871: $col_setting_names);
872: } else {
873: &Apache::loncommon::restore_settings($context,'user_upload',
874: $col_setting_names);
875: }
876: #
877: # Determine kerberos parameters as appropriate
878: my ($krbdef,$krbdefdom) =
879: &Apache::loncommon::get_kerberos_defaults($defdom);
880: #
881: &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
882: $permission);
883: my $i;
884: my $keyfields;
885: if ($total>=0) {
886: my @field=
887: (['username',&mt('Username'), $env{'form.username_choice'}],
888: ['names',&mt('Last Name, First Names'),$env{'form.names_choice'}],
889: ['fname',&mt('First Name'), $env{'form.fname_choice'}],
890: ['mname',&mt('Middle Names/Initials'),$env{'form.mname_choice'}],
891: ['lname',&mt('Last Name'), $env{'form.lname_choice'}],
892: ['gen', &mt('Generation'), $env{'form.gen_choice'}],
893: ['id', &mt('Student/Employee ID'),$env{'form.id_choice'}],
894: ['sec', &mt('Section'), $env{'form.sec_choice'}],
895: ['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
896: ['email',&mt('E-mail Address'), $env{'form.email_choice'}],
897: ['role',&mt('Role'), $env{'form.role_choice'}],
898: ['domain',&mt('Domain'), $env{'form.domain_choice'}]);
899: if ($env{'form.upfile_associate'} eq 'reverse') {
900: &Apache::loncommon::csv_print_samples($r,\@records);
901: $i=&Apache::loncommon::csv_print_select_table($r,\@records,
902: \@field);
903: foreach (@field) {
904: $keyfields.=$_->[0].',';
905: }
906: chop($keyfields);
907: } else {
908: unshift(@field,['none','']);
909: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
910: \@field);
911: my %sone=&Apache::loncommon::record_sep($records[0]);
912: $keyfields=join(',',sort(keys(%sone)));
913: }
914: }
915: $r->print('</div>');
916: &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
917: $context,$permission);
918: }
919:
920: sub setup_date_selectors {
921: my ($starttime,$endtime,$mode,$nolink,$formname) = @_;
922: if ($formname eq '') {
923: $formname = 'studentform';
924: }
925: if (! defined($starttime)) {
926: $starttime = time;
927: unless ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
928: if (exists($env{'course.'.$env{'request.course.id'}.
929: '.default_enrollment_start_date'})) {
930: $starttime = $env{'course.'.$env{'request.course.id'}.
931: '.default_enrollment_start_date'};
932: }
933: }
934: }
935: if (! defined($endtime)) {
936: $endtime = time+(6*30*24*60*60); # 6 months from now, approx
937: unless ($mode eq 'createcourse') {
938: if (exists($env{'course.'.$env{'request.course.id'}.
939: '.default_enrollment_end_date'})) {
940: $endtime = $env{'course.'.$env{'request.course.id'}.
941: '.default_enrollment_end_date'};
942: }
943: }
944: }
945:
946: my $startdateform =
947: &Apache::lonhtmlcommon::date_setter($formname,'startdate',$starttime,
948: undef,undef,undef,undef,undef,undef,undef,$nolink);
949:
950: my $enddateform =
951: &Apache::lonhtmlcommon::date_setter($formname,'enddate',$endtime,
952: undef,undef,undef,undef,undef,undef,undef,$nolink);
953:
954: if ($mode eq 'create_enrolldates') {
955: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
956: 'startenroll',
957: $starttime);
958: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
959: 'endenroll',
960: $endtime);
961: }
962: if ($mode eq 'create_defaultdates') {
963: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
964: 'startaccess',
965: $starttime);
966: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
967: 'endaccess',
968: $endtime);
969: }
970: return ($startdateform,$enddateform);
971: }
972:
973:
974: sub get_dates_from_form {
975: my ($startname,$endname) = @_;
976: if ($startname eq '') {
977: $startname = 'startdate';
978: }
979: if ($endname eq '') {
980: $endname = 'enddate';
981: }
982: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
983: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
984: if ($env{'form.no_end_date'}) {
985: $enddate = 0;
986: }
987: return ($startdate,$enddate);
988: }
989:
990: sub date_setting_table {
991: my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission) = @_;
992: my $nolink;
993: if ($bulkaction) {
994: $nolink = 1;
995: }
996: my ($startform,$endform) =
997: &setup_date_selectors($starttime,$endtime,$mode,$nolink,$formname);
998: my $dateDefault;
999: if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1000: $dateDefault = ' ';
1001: } elsif ($mode ne 'author' && $mode ne 'domain') {
1002: if (($bulkaction eq 'reenable') ||
1003: ($bulkaction eq 'activate') ||
1004: ($bulkaction eq 'chgdates') ||
1005: ($env{'form.action'} eq 'upload')) {
1006: if ($env{'request.course.sec'} eq '') {
1007: $dateDefault = '<span class="LC_nobreak">'.
1008: '<label><input type="checkbox" name="makedatesdefault" value="1" /> '.
1009: &mt('make these dates the default access dates for future student enrollment').
1010: '</label></span>';
1011: }
1012: }
1013: }
1014: my $perpetual = '<span class="LC_nobreak"><label><input type="checkbox" name="no_end_date"';
1015: if (defined($endtime) && $endtime == 0) {
1016: $perpetual .= ' checked="checked"';
1017: }
1018: $perpetual.= ' /> '.&mt('no ending date').'</label></span>';
1019: if ($mode eq 'create_enrolldates') {
1020: $perpetual = ' ';
1021: }
1022: my $result = &Apache::lonhtmlcommon::start_pick_box()."\n";
1023: $result .= &Apache::lonhtmlcommon::row_title(&mt('Starting Date'),
1024: 'LC_oddrow_value')."\n".
1025: $startform."\n".
1026: &Apache::lonhtmlcommon::row_closure(1).
1027: &Apache::lonhtmlcommon::row_title(&mt('Ending Date'),
1028: 'LC_oddrow_value')."\n".
1029: $endform.' '.$perpetual.
1030: &Apache::lonhtmlcommon::row_closure(1).
1031: &Apache::lonhtmlcommon::end_pick_box();
1032: if ($dateDefault) {
1033: $result .= $dateDefault.'<br />'."\n";
1034: }
1035: return $result;
1036: }
1037:
1038: sub make_dates_default {
1039: my ($startdate,$enddate,$context) = @_;
1040: my $result = '';
1041: if ($context eq 'course') {
1042: my ($cnum,$cdom) = &get_course_identity();
1043: my $put_result = &Apache::lonnet::put('environment',
1044: {'default_enrollment_start_date'=>$startdate,
1045: 'default_enrollment_end_date' =>$enddate},$cdom,$cnum);
1046: if ($put_result eq 'ok') {
1047: $result .= &mt('Set default start and end access dates for course.').
1048: '<br />'."\n";
1049: #
1050: # Refresh the course environment
1051: &Apache::lonnet::coursedescription($env{'request.course.id'},
1052: {'freshen_cache' => 1});
1053: } else {
1054: $result .= &mt('Unable to set default access dates for course.').":".$put_result.
1055: '<br />';
1056: }
1057: }
1058: return $result;
1059: }
1060:
1061: sub default_role_selector {
1062: my ($context,$checkpriv) = @_;
1063: my %customroles;
1064: my ($options,$coursepick,$cb_jscript);
1065: if ($context ne 'author') {
1066: %customroles = &my_custom_roles();
1067: }
1068:
1069: my %lt=&Apache::lonlocal::texthash(
1070: 'rol' => "Role",
1071: 'grs' => "Section",
1072: 'exs' => "Existing sections",
1073: 'new' => "New section",
1074: );
1075: $options = '<select name="defaultrole">'."\n".
1076: ' <option value="">'.&mt('Please select').'</option>'."\n";
1077: if ($context eq 'course') {
1078: $options .= &default_course_roles($context,$checkpriv,%customroles);
1079: } elsif ($context eq 'author') {
1080: my @roles = &construction_space_roles($checkpriv);
1081: foreach my $role (@roles) {
1082: my $plrole=&Apache::lonnet::plaintext($role);
1083: $options .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1084: }
1085: } elsif ($context eq 'domain') {
1086: my @roles = &domain_roles($checkpriv);
1087: foreach my $role (@roles) {
1088: my $plrole=&Apache::lonnet::plaintext($role);
1089: $options .= ' <option value="'.$role.'">'.$plrole.'</option>';
1090: }
1091: my $courseform = &Apache::loncommon::selectcourse_link
1092: ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course');
1093: $cb_jscript =
1094: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform');
1095: $coursepick = &Apache::loncommon::start_data_table().
1096: &Apache::loncommon::start_data_table_header_row().
1097: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th>'.
1098: '<th>'.$lt{'grs'}.'</th>'.
1099: &Apache::loncommon::end_data_table_header_row().
1100: &Apache::loncommon::start_data_table_row()."\n".
1101: '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'studentform','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
1102: '<td><select name="courserole">'."\n".
1103: &default_course_roles($context,$checkpriv,%customroles)."\n".
1104: '</select></td><td>'.
1105: '<table class="LC_createuser">'.
1106: '<tr class="LC_section_row"><td valign"top">'.
1107: $lt{'exs'}.'<br /><select name="currsec">'.
1108: ' <option value=""><--'.&mt('Pick course first').
1109: '</select></td>'.
1110: '<td> </td>'.
1111: '<td valign="top">'.$lt{'new'}.'<br />'.
1112: '<input type="text" name="newsec" value="" size="5" />'.
1113: '<input type="hidden" name="groups" value="" />'.
1114: '<input type="hidden" name="sections" value="" />'.
1115: '<input type="hidden" name="origdom" value="'.
1116: $env{'request.role.domain'}.'" />'.
1117: '<input type="hidden" name="dccourse" value="" />'.
1118: '<input type="hidden" name="dcdomain" value="" />'.
1119: '</td></tr></table></td>'.
1120: &Apache::loncommon::end_data_table_row().
1121: &Apache::loncommon::end_data_table()."\n";
1122: }
1123: $options .= '</select>';
1124: return ($options,$cb_jscript,$coursepick);
1125: }
1126:
1127: sub default_course_roles {
1128: my ($context,$checkpriv,%customroles) = @_;
1129: my $output;
1130: my $custom = 1;
1131: my @roles = &course_roles($context,$checkpriv,$custom);
1132: foreach my $role (@roles) {
1133: if ($role ne 'cr') {
1134: my $plrole=&Apache::lonnet::plaintext($role);
1135: $output .= ' <option value="'.$role.'">'.$plrole.'</option>';
1136: }
1137: }
1138: if (keys(%customroles) > 0) {
1139: if (grep(/^cr$/,@roles)) {
1140: foreach my $cust (sort(keys(%customroles))) {
1141: my $custrole='cr_'.$env{'user.domain'}.
1142: '_'.$env{'user.name'}.'_'.$cust;
1143: $output .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1144: }
1145: }
1146: }
1147: return $output;
1148: }
1149:
1150: sub construction_space_roles {
1151: my ($checkpriv) = @_;
1152: my @allroles = &roles_by_context('author');
1153: my @roles;
1154: if ($checkpriv) {
1155: foreach my $role (@allroles) {
1156: if (&Apache::lonnet::allowed('c'.$role,$env{'user.domain'}.'/'.$env{'user.name'})) {
1157: push(@roles,$role);
1158: }
1159: }
1160: return @roles;
1161: } else {
1162: return @allroles;
1163: }
1164: }
1165:
1166: sub domain_roles {
1167: my ($checkpriv) = @_;
1168: my @allroles = &roles_by_context('domain');
1169: my @roles;
1170: if ($checkpriv) {
1171: foreach my $role (@allroles) {
1172: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
1173: push(@roles,$role);
1174: }
1175: }
1176: return @roles;
1177: } else {
1178: return @allroles;
1179: }
1180: }
1181:
1182: sub course_roles {
1183: my ($context,$checkpriv,$custom) = @_;
1184: my @allroles = &roles_by_context('course',$custom);
1185: my @roles;
1186: if ($context eq 'domain') {
1187: @roles = @allroles;
1188: } elsif ($context eq 'course') {
1189: if ($env{'request.course.id'}) {
1190: if ($checkpriv) {
1191: foreach my $role (@allroles) {
1192: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
1193: push(@roles,$role);
1194: } else {
1195: if ($role ne 'cc' && $env{'request.course.sec'} ne '') {
1196: if (&Apache::lonnet::allowed('c'.$role,
1197: $env{'request.course.id'}.'/'.
1198: $env{'request.course.sec'})) {
1199: push(@roles,$role);
1200: }
1201: }
1202: }
1203: }
1204: } else {
1205: @roles = @allroles;
1206: }
1207: }
1208: }
1209: return @roles;
1210: }
1211:
1212: sub curr_role_permissions {
1213: my ($context,$setting,$checkpriv) = @_;
1214: my $custom = 1;
1215: my @roles;
1216: if ($context eq 'author') {
1217: @roles = &construction_space_roles($checkpriv);
1218: } elsif ($context eq 'domain') {
1219: if ($setting eq 'course') {
1220: @roles = &course_roles($context,$checkpriv,$custom);
1221: } else {
1222: @roles = &domain_roles($checkpriv);
1223: }
1224: } elsif ($context eq 'course') {
1225: @roles = &course_roles($context,$checkpriv,$custom);
1226: }
1227: return @roles;
1228: }
1229:
1230: # ======================================================= Existing Custom Roles
1231:
1232: sub my_custom_roles {
1233: my %returnhash=();
1234: my %rolehash=&Apache::lonnet::dump('roles');
1235: foreach my $key (keys %rolehash) {
1236: if ($key=~/^rolesdef\_(\w+)$/) {
1237: $returnhash{$1}=$1;
1238: }
1239: }
1240: return %returnhash;
1241: }
1242:
1243: sub print_userlist {
1244: my ($r,$mode,$permission,$context,$formname,$totcodes,$codetitles,
1245: $idlist,$idlist_titles) = @_;
1246: my $format = $env{'form.output'};
1247: if (! exists($env{'form.sortby'})) {
1248: $env{'form.sortby'} = 'username';
1249: }
1250: if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
1251: $env{'form.Status'} = 'Active';
1252: }
1253: my $status_select = &Apache::lonhtmlcommon::StatusOptions
1254: ($env{'form.Status'});
1255:
1256: if ($env{'form.showrole'} eq '') {
1257: if ($context eq 'course') {
1258: $env{'form.showrole'} = 'st';
1259: } else {
1260: $env{'form.showrole'} = 'Any';
1261: }
1262: }
1263: if (! defined($env{'form.output'}) ||
1264: $env{'form.output'} !~ /^(csv|excel|html)$/ ) {
1265: $env{'form.output'} = 'html';
1266: }
1267:
1268: my @statuses;
1269: if ($env{'form.Status'} eq 'Any') {
1270: @statuses = ('previous','active','future');
1271: } elsif ($env{'form.Status'} eq 'Expired') {
1272: @statuses = ('previous');
1273: } elsif ($env{'form.Status'} eq 'Active') {
1274: @statuses = ('active');
1275: } elsif ($env{'form.Status'} eq 'Future') {
1276: @statuses = ('future');
1277: }
1278:
1279: # if ($context eq 'course') {
1280: # $r->print(&display_adv_courseroles());
1281: # }
1282: #
1283: # Interface output
1284: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
1285: '<input type="hidden" name="action" value="'.
1286: $env{'form.action'}.'" />');
1287: $r->print("<p>\n");
1288: if ($env{'form.action'} ne 'modifystudent') {
1289: my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
1290: 'excel' => "Excel",
1291: 'html' => 'HTML');
1292: my $output_selector = '<select size="1" name="output" >';
1293: foreach my $outputformat ('html','csv','excel') {
1294: my $option = '<option value="'.$outputformat.'" ';
1295: if ($outputformat eq $env{'form.output'}) {
1296: $option .= 'selected ';
1297: }
1298: $option .='>'.$lt{$outputformat}.'</option>';
1299: $output_selector .= "\n".$option;
1300: }
1301: $output_selector .= '</select>';
1302: $r->print('<label><span class="LC_nobreak">'
1303: .&mt('Output Format: [_1]',$output_selector)
1304: .'</span></label>'.(' 'x3));
1305: }
1306: $r->print('<label><span class="LC_nobreak">'
1307: .&mt('User Status: [_1]',$status_select)
1308: .'</span></label>'.(' 'x3)."\n");
1309: my $roleselected = '';
1310: if ($env{'form.showrole'} eq 'Any') {
1311: $roleselected = ' selected="selected" ';
1312: }
1313: my ($cnum,$cdom);
1314: $r->print(&role_filter($context));
1315: if ($context eq 'course') {
1316: ($cnum,$cdom) = &get_course_identity();
1317: $r->print(§ion_group_filter($cnum,$cdom));
1318: }
1319: if ($env{'form.phase'} eq '') {
1320: $r->print('<br /><br />'.&list_submit_button(&mt('Display List of Users')).
1321: "\n</p>\n".
1322: '<input type="hidden" name="phase" value="" /></form>');
1323: return;
1324: }
1325: if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) {
1326: $r->print(' '.&list_submit_button(&mt('Update Display')).
1327: "\n</p>\n");
1328: }
1329: my ($indexhash,$keylist) = &make_keylist_array();
1330: my (%userlist,%userinfo);
1331: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
1332: my $courseform =
1333: &Apache::lonhtmlcommon::course_selection($formname,$totcodes,
1334: $codetitles,$idlist,$idlist_titles);
1335: $r->print('<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n".
1336: &Apache::lonhtmlcommon::start_pick_box()."\n".
1337: &Apache::lonhtmlcommon::row_title(&mt('Select Course(s)'),
1338: 'LC_oddrow_value')."\n".
1339: $courseform."\n".
1340: &Apache::lonhtmlcommon::row_closure(1).
1341: &Apache::lonhtmlcommon::end_pick_box().'</p>'.
1342: '<p>'.&list_submit_button(&mt('Update Display')).
1343: "\n".'</p><span class="LC_warning">'.&mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.').'</span>'."\n");
1344: if ($env{'form.coursepick'}) {
1345: $r->print('<hr />'.&mt('Searching').' ...<br /> <br />');
1346: }
1347: } else {
1348: $r->print('<hr />'.&mt('Searching').' ...<br /> <br />');
1349: }
1350: $r->rflush();
1351: if ($context eq 'course') {
1352: if (($env{'form.showrole'} eq 'st') || ($env{'form.showrole'} eq 'Any')) {
1353: my $classlist = &Apache::loncoursedata::get_classlist();
1354: if (ref($classlist) eq 'HASH') {
1355: %userlist = %{$classlist};
1356: }
1357: }
1358: if ($env{'form.showrole'} ne 'st') {
1359: my $showroles;
1360: if ($env{'form.showrole'} ne 'Any') {
1361: $showroles = [$env{'form.showrole'}];
1362: } else {
1363: $showroles = undef;
1364: }
1365: my $withsec = 1;
1366: my $hidepriv = 1;
1367: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
1368: \@statuses,$showroles,undef,$withsec,$hidepriv);
1369: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
1370: \%advrolehash,$permission);
1371: }
1372: } else {
1373: my (%cstr_roles,%dom_roles);
1374: if ($context eq 'author') {
1375: # List co-authors and assistant co-authors
1376: my @possroles = &roles_by_context($context);
1377: %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
1378: \@statuses,\@possroles);
1379: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
1380: \%cstr_roles,$permission);
1381: } elsif ($context eq 'domain') {
1382: if ($env{'form.roletype'} eq 'domain') {
1383: %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'});
1384: foreach my $key (keys(%dom_roles)) {
1385: if (ref($dom_roles{$key}) eq 'HASH') {
1386: &gather_userinfo($context,$format,\%userlist,$indexhash,
1387: \%userinfo,$dom_roles{$key},$permission);
1388: }
1389: }
1390: } elsif ($env{'form.roletype'} eq 'author') {
1391: my %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'},['au']);
1392: my %coauthors;
1393: foreach my $key (keys(%dom_roles)) {
1394: if (ref($dom_roles{$key}) eq 'HASH') {
1395: if ($env{'form.showrole'} eq 'au') {
1396: &gather_userinfo($context,$format,\%userlist,$indexhash,
1397: \%userinfo,$dom_roles{$key},$permission);
1398: } else {
1399: my @possroles;
1400: if ($env{'form.showrole'} eq 'Any') {
1401: @possroles = &roles_by_context('author');
1402: } else {
1403: @possroles = ($env{'form.showrole'});
1404: }
1405: foreach my $author (sort(keys(%{$dom_roles{$key}}))) {
1406: my ($role,$authorname,$authordom) = split(/:/,$author,-1);
1407: my $extent = '/'.$authordom.'/'.$authorname;
1408: %{$coauthors{$extent}} =
1409: &Apache::lonnet::get_my_roles($authorname,
1410: $authordom,undef,\@statuses,\@possroles);
1411: }
1412: &gather_userinfo($context,$format,\%userlist,
1413: $indexhash,\%userinfo,\%coauthors,$permission);
1414: }
1415: }
1416: }
1417: } elsif ($env{'form.roletype'} eq 'course') {
1418: if ($env{'form.coursepick'}) {
1419: my %courses = &process_coursepick();
1420: my %allusers;
1421: my $hidepriv = 1;
1422: foreach my $cid (keys(%courses)) {
1423: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
1424: next if ($cnum eq '' || $cdom eq '');
1425: my $custom = 1;
1426: my (@roles,@sections,%access,%users,%userdata,
1427: %statushash);
1428: if ($env{'form.showrole'} eq 'Any') {
1429: @roles = &course_roles($context,undef,$custom);
1430: } else {
1431: @roles = ($env{'form.showrole'});
1432: }
1433: foreach my $role (@roles) {
1434: %{$users{$role}} = ();
1435: }
1436: foreach my $type (@statuses) {
1437: $access{$type} = $type;
1438: }
1439: &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash,$hidepriv);
1440: foreach my $user (keys(%userdata)) {
1441: next if (ref($userinfo{$user}) eq 'HASH');
1442: foreach my $item ('fullname','id') {
1443: $userinfo{$user}{$item} = $userdata{$user}[$indexhash->{$item}];
1444: }
1445: }
1446: foreach my $role (keys(%users)) {
1447: foreach my $user (keys(%{$users{$role}})) {
1448: my $uniqid = $user.':'.$role;
1449: $allusers{$uniqid}{$cid} = { desc => $cdesc,
1450: secs => $statushash{$user}{$role},
1451: };
1452: }
1453: }
1454: }
1455: &gather_userinfo($context,$format,\%userlist,$indexhash,
1456: \%userinfo,\%allusers,$permission);
1457: } else {
1458: $r->print('<input type="hidden" name="phase" value="'.
1459: $env{'form.phase'}.'" /></form>');
1460: return;
1461: }
1462: }
1463: }
1464: }
1465: if (keys(%userlist) == 0) {
1466: if ($context eq 'author') {
1467: $r->print(&mt('There are no co-authors to display.')."\n");
1468: } elsif ($context eq 'domain') {
1469: if ($env{'form.roletype'} eq 'domain') {
1470: $r->print(&mt('There are no users with domain roles to display.')."\n");
1471: } elsif ($env{'form.roletype'} eq 'author') {
1472: $r->print(&mt('There are no authors or co-authors to display.')."\n");
1473: } elsif ($env{'form.roletype'} eq 'course') {
1474: $r->print(&mt('There are no course users to display')."\n");
1475: }
1476: } elsif ($context eq 'course') {
1477: $r->print(&mt('There are no course users to display.')."\n");
1478: }
1479: } else {
1480: # Print out the available choices
1481: my $usercount;
1482: if ($env{'form.action'} eq 'modifystudent') {
1483: ($usercount) = &show_users_list($r,$context,'view',$permission,
1484: $env{'form.Status'},\%userlist,$keylist);
1485: } else {
1486: ($usercount) = &show_users_list($r,$context,$env{'form.output'},
1487: $permission,$env{'form.Status'},\%userlist,$keylist);
1488: }
1489: if (!$usercount) {
1490: $r->print('<br /><span class="LC_warning">'
1491: .&mt('There are no users matching the search criteria.')
1492: .'</span>'
1493: );
1494: }
1495: }
1496: $r->print('<input type="hidden" name="phase" value="'.
1497: $env{'form.phase'}.'" /></form>');
1498: }
1499:
1500: sub role_filter {
1501: my ($context) = @_;
1502: my $output;
1503: my $roleselected = '';
1504: if ($env{'form.showrole'} eq 'Any') {
1505: $roleselected = ' selected="selected" ';
1506: }
1507: my ($role_select);
1508: if ($context eq 'domain') {
1509: $role_select = &domain_roles_select();
1510: $output = '<label><span class="LC_nobreak">'
1511: .&mt('Role Type: [_1]',$role_select)
1512: .'</span></label>';
1513: } else {
1514: $role_select = '<select name="showrole">'."\n".
1515: '<option value="Any" '.$roleselected.'>'.
1516: &mt('Any role').'</option>';
1517: my @poss_roles = &curr_role_permissions($context);
1518: foreach my $role (@poss_roles) {
1519: $roleselected = '';
1520: if ($role eq $env{'form.showrole'}) {
1521: $roleselected = ' selected="selected" ';
1522: }
1523: my $plrole;
1524: if ($role eq 'cr') {
1525: $plrole = &mt('Custom role');
1526: } else {
1527: $plrole=&Apache::lonnet::plaintext($role);
1528: }
1529: $role_select .= '<option value="'.$role.'"'.$roleselected.'>'.$plrole.'</option>';
1530: }
1531: $role_select .= '</select>';
1532: $output = '<label><span class="LC_nobreak">'
1533: .&mt('Role: [_1]',$role_select)
1534: .'</span></label>';
1535: }
1536: return $output;
1537: }
1538:
1539: sub section_group_filter {
1540: my ($cnum,$cdom) = @_;
1541: my @filters;
1542: if ($env{'request.course.sec'} eq '') {
1543: @filters = ('sec');
1544: }
1545: push(@filters,'grp');
1546: my %name = (
1547: sec => 'secfilter',
1548: grp => 'grpfilter',
1549: );
1550: my %title = &Apache::lonlocal::texthash (
1551: sec => 'Section(s)',
1552: grp => 'Group(s)',
1553: all => 'all',
1554: none => 'none',
1555: );
1556: my $output;
1557: foreach my $item (@filters) {
1558: my ($markup,@options);
1559: if ($env{'form.'.$name{$item}} eq '') {
1560: $env{'form.'.$name{$item}} = 'all';
1561: }
1562: if ($item eq 'sec') {
1563: if ($env{'form.showrole'} eq 'cc') {
1564: $env{'form.'.$name{$item}} = 'none';
1565: }
1566: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
1567: @options = sort(keys(%sections_count));
1568: } elsif ($item eq 'grp') {
1569: my %curr_groups = &Apache::longroup::coursegroups();
1570: @options = sort(keys(%curr_groups));
1571: }
1572: if (@options > 0) {
1573: my $currsel;
1574: $markup = '<select name="'.$name{$item}.'" />'."\n";
1575: foreach my $option ('all','none',@options) {
1576: $currsel = '';
1577: if ($env{'form.'.$name{$item}} eq $option) {
1578: $currsel = ' selected="selected" ';
1579: }
1580: $markup .= ' <option value="'.$option.'"'.$currsel.'>';
1581: if (($option eq 'all') || ($option eq 'none')) {
1582: $markup .= $title{$option};
1583: } else {
1584: $markup .= $option;
1585: }
1586: $markup .= '</option>'."\n";
1587: }
1588: $markup .= '</select>'."\n";
1589: $output .= (' 'x3).'<label>'.$title{$item}.': '.$markup.'</label>';
1590: }
1591: }
1592: return $output;
1593: }
1594:
1595: sub list_submit_button {
1596: my ($text) = @_;
1597: return '<input type="button" name="updatedisplay" value="'.$text.'" onclick="javascript:display_update()" />';
1598: }
1599:
1600: sub gather_userinfo {
1601: my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_;
1602: my $viewablesec;
1603: if ($context eq 'course') {
1604: $viewablesec = &viewable_section($permission);
1605: }
1606: foreach my $item (keys(%{$rolehash})) {
1607: my %userdata;
1608: if ($context eq 'author') {
1609: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
1610: split(/:/,$item);
1611: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
1612: &build_user_record($context,\%userdata,$userinfo,$indexhash,
1613: $item,$userlist);
1614: } elsif ($context eq 'course') {
1615: ($userdata{'username'},$userdata{'domain'},$userdata{'role'},
1616: $userdata{'section'}) = split(/:/,$item,-1);
1617: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
1618: if (($viewablesec ne '') && ($userdata{'section'} ne '')) {
1619: next if ($viewablesec ne $userdata{'section'});
1620: }
1621: &build_user_record($context,\%userdata,$userinfo,$indexhash,
1622: $item,$userlist);
1623: } elsif ($context eq 'domain') {
1624: if ($env{'form.roletype'} eq 'domain') {
1625: ($userdata{'role'},$userdata{'username'},$userdata{'domain'}) =
1626: split(/:/,$item);
1627: ($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
1628: &build_user_record($context,\%userdata,$userinfo,$indexhash,
1629: $item,$userlist);
1630: } elsif ($env{'form.roletype'} eq 'author') {
1631: if (ref($rolehash->{$item}) eq 'HASH') {
1632: $userdata{'extent'} = $item;
1633: foreach my $key (keys(%{$rolehash->{$item}})) {
1634: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) = split(/:/,$key);
1635: ($userdata{'start'},$userdata{'end'}) =
1636: split(/:/,$rolehash->{$item}{$key});
1637: my $uniqid = $key.':'.$item;
1638: &build_user_record($context,\%userdata,$userinfo,
1639: $indexhash,$uniqid,$userlist);
1640: }
1641: }
1642: } elsif ($env{'form.roletype'} eq 'course') {
1643: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
1644: split(/:/,$item);
1645: if (ref($rolehash->{$item}) eq 'HASH') {
1646: my $numcids = keys(%{$rolehash->{$item}});
1647: foreach my $cid (sort(keys(%{$rolehash->{$item}}))) {
1648: if (ref($rolehash->{$item}{$cid}) eq 'HASH') {
1649: my $spanstart = '';
1650: my $spanend = '; ';
1651: my $space = ', ';
1652: if ($format eq 'html' || $format eq 'view') {
1653: $spanstart = '<span class="LC_nobreak">';
1654: # FIXME: actions on courses disabled for now
1655: # if ($permission->{'cusr'}) {
1656: # if ($numcids > 1) {
1657: # $spanstart .= '<input type="radio" name="'.$item.'" value="'.$cid.'" /> ';
1658: # } else {
1659: # $spanstart .= '<input type="hidden" name="'.$item.'" value="'.$cid.'" /> ';
1660: # }
1661: # }
1662: $spanend = '</span><br />';
1663: $space = ', ';
1664: }
1665: $userdata{'extent'} .= $spanstart.
1666: $rolehash->{$item}{$cid}{'desc'}.$space;
1667: if (ref($rolehash->{$item}{$cid}{'secs'}) eq 'HASH') {
1668: foreach my $sec (sort(keys(%{$rolehash->{$item}{$cid}{'secs'}}))) {
1669: if (($env{'form.Status'} eq 'Any') ||
1670: ($env{'form.Status'} eq $rolehash->{$item}{$cid}{'secs'}{$sec})) {
1671: $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
1672: $userdata{'status'} = $rolehash->{$item}{$cid}{'secs'}{$sec};
1673: }
1674: }
1675: }
1676: }
1677: }
1678: }
1679: if ($userdata{'status'} ne '') {
1680: &build_user_record($context,\%userdata,$userinfo,
1681: $indexhash,$item,$userlist);
1682: }
1683: }
1684: }
1685: }
1686: return;
1687: }
1688:
1689: sub build_user_record {
1690: my ($context,$userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
1691: next if ($userdata->{'start'} eq '-1' && $userdata->{'end'} eq '-1');
1692: if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) {
1693: &process_date_info($userdata);
1694: }
1695: my $username = $userdata->{'username'};
1696: my $domain = $userdata->{'domain'};
1697: if (ref($userinfo->{$username.':'.$domain}) eq 'HASH') {
1698: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
1699: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
1700: } else {
1701: &aggregate_user_info($domain,$username,$userinfo);
1702: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
1703: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
1704: }
1705: foreach my $key (keys(%{$indexhash})) {
1706: if (defined($userdata->{$key})) {
1707: $userlist->{$record_key}[$indexhash->{$key}] = $userdata->{$key};
1708: }
1709: }
1710: return;
1711: }
1712:
1713: sub courses_selector {
1714: my ($cdom,$formname) = @_;
1715: my %coursecodes = ();
1716: my %codes = ();
1717: my @codetitles = ();
1718: my %cat_titles = ();
1719: my %cat_order = ();
1720: my %idlist = ();
1721: my %idnums = ();
1722: my %idlist_titles = ();
1723: my $caller = 'global';
1724: my $format_reply;
1725: my $jscript = '';
1726:
1727: my $totcodes = 0;
1728: $totcodes =
1729: &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,
1730: $cdom,$totcodes);
1731: if ($totcodes > 0) {
1732: $format_reply =
1733: &Apache::lonnet::auto_instcode_format($caller,$cdom,\%coursecodes,
1734: \%codes,\@codetitles,\%cat_titles,\%cat_order);
1735: if ($format_reply eq 'ok') {
1736: my $numtypes = @codetitles;
1737: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
1738: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
1739: my $longtitles_str = join('","',@{$longtitles});
1740: my $allidlist = $idlist{$codetitles[0]};
1741: $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
1742: $jscript .= $scripttext;
1743: $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,@codetitles);
1744: }
1745: }
1746: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
1747:
1748: my %elements = (
1749: Year => 'selectbox',
1750: coursepick => 'radio',
1751: coursetotal => 'text',
1752: courselist => 'text',
1753: );
1754: $jscript .= &Apache::lonhtmlcommon::set_form_elements(\%elements);
1755: if ($env{'form.coursepick'} eq 'category') {
1756: $jscript .= qq|
1757: function setCourseCat(formname) {
1758: if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
1759: return;
1760: }
1761: courseSet('Year');
1762: for (var j=0; j<formname.Semester.length; j++) {
1763: if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
1764: formname.Semester.options[j].selected = true;
1765: }
1766: }
1767: if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
1768: return;
1769: }
1770: courseSet('Semester');
1771: for (var j=0; j<formname.Department.length; j++) {
1772: if (formname.Department.options[j].value == "$env{'form.Department'}") { formname.Department.options[j].selected = true;
1773: }
1774: }
1775: if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
1776: return;
1777: }
1778: courseSet('Department');
1779: for (var j=0; j<formname.Number.length; j++) {
1780: if (formname.Number.options[j].value == "$env{'form.Number'}") {
1781: formname.Number.options[j].selected = true;
1782: }
1783: }
1784: }
1785: |;
1786: }
1787: return ($cb_jscript,$jscript,$totcodes,\@codetitles,\%idlist,
1788: \%idlist_titles);
1789: }
1790:
1791: sub course_selector_loadcode {
1792: my ($formname) = @_;
1793: my $loadcode;
1794: if ($env{'form.coursepick'} ne '') {
1795: $loadcode = 'javascript:setFormElements(document.'.$formname.')';
1796: if ($env{'form.coursepick'} eq 'category') {
1797: $loadcode .= ';javascript:setCourseCat(document.'.$formname.')';
1798: }
1799: }
1800: return $loadcode;
1801: }
1802:
1803: sub process_coursepick {
1804: my $coursefilter = $env{'form.coursepick'};
1805: my $cdom = $env{'request.role.domain'};
1806: my %courses;
1807: if ($coursefilter eq 'all') {
1808: %courses = &Apache::lonnet::courseiddump($cdom,'.','.','.','.','.',
1809: undef,undef,'Course');
1810: } elsif ($coursefilter eq 'category') {
1811: my $instcode = &instcode_from_coursefilter();
1812: %courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.',
1813: undef,undef,'Course');
1814: } elsif ($coursefilter eq 'specific') {
1815: if ($env{'form.coursetotal'} > 1) {
1816: my @course_ids = split(/&&/,$env{'form.courselist'});
1817: foreach my $cid (@course_ids) {
1818: $courses{$cid} = '';
1819: }
1820: } else {
1821: $courses{$env{'form.courselist'}} = '';
1822: }
1823: }
1824: return %courses;
1825: }
1826:
1827: sub instcode_from_coursefilter {
1828: my $instcode = '';
1829: my @cats = ('Semester','Year','Department','Number');
1830: foreach my $category (@cats) {
1831: if (defined($env{'form.'.$category})) {
1832: unless ($env{'form.'.$category} eq '-1') {
1833: $instcode .= $env{'form.'.$category};
1834: }
1835: }
1836: }
1837: if ($instcode eq '') {
1838: $instcode = '.';
1839: }
1840: return $instcode;
1841: }
1842:
1843: sub display_adv_courseroles {
1844: my $output;
1845: #
1846: # List course personnel
1847: my %coursepersonnel =
1848: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'});
1849: #
1850: $output = '<br />'.&Apache::loncommon::start_data_table();
1851: foreach my $role (sort(keys(%coursepersonnel))) {
1852: next if ($role =~ /^\s*$/);
1853: $output .= &Apache::loncommon::start_data_table_row().
1854: '<td>'.$role.'</td><td>';
1855: foreach my $user (split(',',$coursepersonnel{$role})) {
1856: my ($puname,$pudom)=split(':',$user);
1857: $output .= ' '.&Apache::loncommon::aboutmewrapper(
1858: &Apache::loncommon::plainname($puname,$pudom),
1859: $puname,$pudom);
1860: }
1861: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
1862: }
1863: $output .= &Apache::loncommon::end_data_table();
1864: }
1865:
1866: sub make_keylist_array {
1867: my ($index,$keylist);
1868: $index->{'domain'} = &Apache::loncoursedata::CL_SDOM();
1869: $index->{'username'} = &Apache::loncoursedata::CL_SNAME();
1870: $index->{'end'} = &Apache::loncoursedata::CL_END();
1871: $index->{'start'} = &Apache::loncoursedata::CL_START();
1872: $index->{'id'} = &Apache::loncoursedata::CL_ID();
1873: $index->{'section'} = &Apache::loncoursedata::CL_SECTION();
1874: $index->{'fullname'} = &Apache::loncoursedata::CL_FULLNAME();
1875: $index->{'status'} = &Apache::loncoursedata::CL_STATUS();
1876: $index->{'type'} = &Apache::loncoursedata::CL_TYPE();
1877: $index->{'lockedtype'} = &Apache::loncoursedata::CL_LOCKEDTYPE();
1878: $index->{'groups'} = &Apache::loncoursedata::CL_GROUP();
1879: $index->{'email'} = &Apache::loncoursedata::CL_PERMANENTEMAIL();
1880: $index->{'role'} = &Apache::loncoursedata::CL_ROLE();
1881: $index->{'extent'} = &Apache::loncoursedata::CL_EXTENT();
1882: $index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
1883: $index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();
1884: foreach my $key (keys(%{$index})) {
1885: $keylist->[$index->{$key}] = $key;
1886: }
1887: return ($index,$keylist);
1888: }
1889:
1890: sub aggregate_user_info {
1891: my ($udom,$uname,$userinfo) = @_;
1892: my %info=&Apache::lonnet::get('environment',
1893: ['firstname','middlename',
1894: 'lastname','generation','id'],
1895: $udom,$uname);
1896: my ($tmp) = keys(%info);
1897: my ($fullname,$id);
1898: if ($tmp =~/^(con_lost|error|no_such_host)/i) {
1899: $fullname = 'not available';
1900: $id = 'not available';
1901: &Apache::lonnet::logthis('unable to retrieve environment '.
1902: 'for '.$uname.':'.$udom);
1903: } else {
1904: $fullname = &Apache::lonnet::format_name(@info{qw/firstname middlename lastname generation/},'lastname');
1905: $id = $info{'id'};
1906: }
1907: $userinfo->{$uname.':'.$udom} = {
1908: fullname => $fullname,
1909: id => $id,
1910: };
1911: return;
1912: }
1913:
1914: sub process_date_info {
1915: my ($userdata) = @_;
1916: my $now = time;
1917: $userdata->{'status'} = &mt('Active');
1918: if ($userdata->{'start'} > 0) {
1919: if ($now < $userdata->{'start'}) {
1920: $userdata->{'status'} = &mt('Future');
1921: }
1922: }
1923: if ($userdata->{'end'} > 0) {
1924: if ($now > $userdata->{'end'}) {
1925: $userdata->{'status'} = &mt('Expired');
1926: }
1927: }
1928: return;
1929: }
1930:
1931: sub show_users_list {
1932: my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname)=@_;
1933: if ($formname eq '') {
1934: $formname = 'studentform';
1935: }
1936: #
1937: # Variables for excel output
1938: my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
1939: #
1940: # Variables for csv output
1941: my ($CSVfile,$CSVfilename);
1942: #
1943: my $sortby = $env{'form.sortby'};
1944: my @sortable = ('username','domain','id','fullname','start','end','email','role');
1945: if ($context eq 'course') {
1946: push(@sortable,('section','groups','type'));
1947: } else {
1948: push(@sortable,'extent');
1949: }
1950: if ($mode eq 'pickauthor') {
1951: @sortable = ('username','fullname','email','status');
1952: }
1953: if (!grep(/^\Q$sortby\E$/,@sortable)) {
1954: $sortby = 'username';
1955: }
1956: my $setting = $env{'form.roletype'};
1957: my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers);
1958: if ($context eq 'course') {
1959: $cid = $env{'request.course.id'};
1960: ($cnum,$cdom) = &get_course_identity($cid);
1961: ($classgroups) = &Apache::loncoursedata::get_group_memberships(
1962: $userlist,$keylist,$cdom,$cnum);
1963: if ($mode eq 'autoenroll') {
1964: $env{'form.showrole'} = 'st';
1965: } else {
1966: if (! exists($env{'form.displayphotos'})) {
1967: $env{'form.displayphotos'} = 'off';
1968: }
1969: $displayphotos = $env{'form.displayphotos'};
1970: if (! exists($env{'form.displayclickers'})) {
1971: $env{'form.displayclickers'} = 'off';
1972: }
1973: $displayclickers = $env{'form.displayclickers'};
1974: if ($env{'course.'.$cid.'.internal.showphoto'}) {
1975: $r->print('
1976: <script type="text/javascript">
1977: function photowindow(photolink) {
1978: var title = "Photo_Viewer";
1979: var options = "scrollbars=1,resizable=1,menubar=0";
1980: options += ",width=240,height=240";
1981: stdeditbrowser = open(photolink,title,options,"1");
1982: stdeditbrowser.focus();
1983: }
1984: </script>
1985: ');
1986: }
1987: $r->print(<<END);
1988: <input type="hidden" name="displayphotos" value="$displayphotos" />
1989: <input type="hidden" name="displayclickers" value="$displayclickers" />
1990: END
1991: }
1992: }
1993: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
1994: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
1995: my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
1996: my $verify_action_js = &bulkaction_javascript($formname);
1997: $r->print(<<END);
1998:
1999: <script type="text/javascript" language="Javascript">
2000: $check_uncheck_js
2001:
2002: $verify_action_js
2003:
2004: function username_display_launch(username,domain) {
2005: var target;
2006: for (var i=0; i<document.$formname.usernamelink.length; i++) {
2007: if (document.$formname.usernamelink[i].checked) {
2008: target = document.$formname.usernamelink[i].value;
2009: }
2010: }
2011: if (target == 'modify') {
2012: if (document.$formname.userwin.checked == true) {
2013: var url = '/adm/createuser?srchterm='+username+'&srchdomain='+domain+'&phase=get_user_info&action=singleuser&srchin=dom&srchby=uname&srchtype=exact&popup=1';
2014: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
2015: modifywin = window.open(url,'',options,1);
2016: modifywin.focus();
2017: return;
2018: } else {
2019: document.$formname.srchterm.value=username;
2020: document.$formname.srchdomain.value=domain;
2021: document.$formname.phase.value='get_user_info';
2022: document.$formname.action.value = 'singleuser';
2023: document.$formname.submit();
2024: }
2025: }
2026: if (target == 'aboutme') {
2027: if (document.$formname.userwin.checked == true) {
2028: var url = '/adm/'+domain+'/'+username+'/aboutme?popup=1';
2029: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
2030: aboutmewin = window.open(url,'',options,1);
2031: aboutmewin.focus();
2032: return;
2033: } else {
2034: document.location.href = '/adm/'+domain+'/'+username+'/aboutme';
2035: }
2036: }
2037: }
2038: </script>
2039: $date_sec_selector
2040: <input type="hidden" name="state" value="$env{'form.state'}" />
2041: END
2042: }
2043: $r->print(<<END);
2044: <input type="hidden" name="sortby" value="$sortby" />
2045: END
2046:
2047: my %lt=&Apache::lonlocal::texthash(
2048: 'username' => "username",
2049: 'domain' => "domain",
2050: 'id' => 'ID',
2051: 'fullname' => "name",
2052: 'section' => "section",
2053: 'groups' => "active groups",
2054: 'start' => "start date",
2055: 'end' => "end date",
2056: 'status' => "status",
2057: 'role' => "role",
2058: 'type' => "enroll type/action",
2059: 'email' => "email address",
2060: 'photo' => "photo",
2061: 'extent' => "extent",
2062: 'pr' => "Proceed",
2063: 'ca' => "check all",
2064: 'ua' => "uncheck all",
2065: 'ac' => "Action to take for selected users",
2066: 'link' => "Behavior of clickable username link for each user",
2067: 'aboutme' => "Display a user's personal page",
2068: 'owin' => "Open in a new window",
2069: 'modify' => "Modify a user's information",
2070: 'clicker' => "Clicker-ID",
2071: );
2072: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
2073: $lt{'extent'} = &mt('Course(s): description, section(s), status');
2074: } elsif ($context eq 'author') {
2075: $lt{'extent'} = &mt('Author');
2076: }
2077: my @cols;
2078: if ($mode eq 'pickauthor') {
2079: @cols = ('username','fullname','status','email');
2080: } else {
2081: @cols = ('username','domain','id','fullname');
2082: if ($context eq 'course') {
2083: push(@cols,'section');
2084: }
2085: if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) {
2086: push(@cols,('start','end'));
2087: }
2088: if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
2089: push(@cols,'role');
2090: }
2091: if ($context eq 'domain' && ($env{'form.roletype'} eq 'author' ||
2092: $env{'form.roletype'} eq 'course')) {
2093: push (@cols,'extent');
2094: }
2095: if (($statusmode eq 'Any') &&
2096: (!($context eq 'domain' && $env{'form.roletype'} eq 'course'))) {
2097: push(@cols,'status');
2098: }
2099: if ($context eq 'course') {
2100: push(@cols,'groups');
2101: }
2102: push(@cols,'email');
2103: }
2104:
2105: my $rolefilter = $env{'form.showrole'};
2106: if ($env{'form.showrole'} eq 'cr') {
2107: $rolefilter = &mt('custom');
2108: } elsif ($env{'form.showrole'} ne 'Any') {
2109: $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'});
2110: }
2111: my $results_description;
2112: if ($mode ne 'autoenroll') {
2113: $results_description = &results_header_row($rolefilter,$statusmode,
2114: $context,$permission,$mode);
2115: $r->print('<b>'.$results_description.'</b><br /><br />');
2116: }
2117: my ($output,$actionselect,%canchange,%canchangesec);
2118: if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
2119: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
2120: if ($permission->{'cusr'}) {
2121: $actionselect = &select_actions($context,$setting,$statusmode,$formname);
2122: }
2123: $r->print(<<END);
2124: <input type="hidden" name="srchby" value="uname" />
2125: <input type="hidden" name="srchin" value="dom" />
2126: <input type="hidden" name="srchtype" value="exact" />
2127: <input type="hidden" name="srchterm" value="" />
2128: <input type="hidden" name="srchdomain" value="" />
2129: END
2130: if ($actionselect) {
2131: $output .= <<"END";
2132: <div class="LC_left_float"><fieldset><legend><b>$lt{'ac'}</b></legend>
2133: $actionselect
2134: <br/><br /><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.$formname.actionlist)" />
2135: <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>
2136: END
2137: my @allroles;
2138: if ($env{'form.showrole'} eq 'Any') {
2139: my $custom = 1;
2140: if ($context eq 'domain') {
2141: @allroles = &roles_by_context($setting,$custom);
2142: } else {
2143: @allroles = &roles_by_context($context,$custom);
2144: }
2145: } else {
2146: @allroles = ($env{'form.showrole'});
2147: }
2148: foreach my $role (@allroles) {
2149: if ($context eq 'domain') {
2150: if ($setting eq 'domain') {
2151: if (&Apache::lonnet::allowed('c'.$role,
2152: $env{'request.role.domain'})) {
2153: $canchange{$role} = 1;
2154: }
2155: } elsif ($setting eq 'author') {
2156: if (&Apache::lonnet::allowed('c'.$role,
2157: $env{'request.role.domain'})) {
2158: $canchange{$role} = 1;
2159: }
2160: }
2161: } elsif ($context eq 'author') {
2162: if (&Apache::lonnet::allowed('c'.$role,
2163: $env{'user.domain'}.'/'.$env{'user.name'})) {
2164: $canchange{$role} = 1;
2165: }
2166: } elsif ($context eq 'course') {
2167: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
2168: $canchange{$role} = 1;
2169: } elsif ($env{'request.course.sec'} ne '') {
2170: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
2171: $canchangesec{$role} = $env{'request.course.sec'};
2172: }
2173: }
2174: }
2175: }
2176: }
2177: $output .= '<div class="LC_left_float"><fieldset><legend><b>'.$lt{'link'}.'</b></legend>'.
2178: '<table><tr>';
2179: my @linkdests = ('aboutme');
2180: if ($permission->{'cusr'}) {
2181: unshift (@linkdests,'modify');
2182: }
2183: $output .= '<td>';
2184: my $usernamelink = $env{'form.usernamelink'};
2185: if ($usernamelink eq '') {
2186: $usernamelink = 'aboutme';
2187: }
2188: foreach my $item (@linkdests) {
2189: my $checkedstr = '';
2190: if ($item eq $usernamelink) {
2191: $checkedstr = ' checked="checked" ';
2192: }
2193: $output .= '<span class="LC_nobreak"><label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.'> '.$lt{$item}.'</label></span><br />';
2194: }
2195: my $checkwin;
2196: if ($env{'form.userwin'}) {
2197: $checkwin = 'checked = "checked"';
2198: }
2199: $output .= '</td><td valign="top"><span class="LC_nobreak"><input type="checkbox" name="userwin" value="1" '.$checkwin.'/>'.$lt{'owin'}.'</span></td></tr></table></fieldset></div>';
2200: }
2201: $output .= "\n".'<div class="LC_clear_float_footer"> </div>'."\n".
2202: &Apache::loncommon::start_data_table().
2203: &Apache::loncommon::start_data_table_header_row();
2204: if ($mode eq 'autoenroll') {
2205: $output .= "
2206: <th><a href=\"javascript:document.$formname.sortby.value='type';document.$formname.submit();\">$lt{'type'}</a></th>
2207: ";
2208: } else {
2209: if ($mode eq 'pickauthor') {
2210: $output .= "\n".'<th> </th>'."\n";
2211: } else {
2212: $output .= "\n".'<th>'.&mt('Count').'</th>'."\n";
2213: }
2214: if ($actionselect) {
2215: $output .= '<th>'.&mt('Select').'</th>'."\n";
2216: }
2217: }
2218: foreach my $item (@cols) {
2219: $output .= "<th><a href=\"javascript:document.$formname.sortby.value='$item';document.$formname.submit();\">$lt{$item}</a></th>\n";
2220: }
2221: my %role_types = &role_type_names();
2222: if ($context eq 'course' && $mode ne 'autoenroll') {
2223: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
2224: # Clicker display on or off?
2225: my %clicker_options = (
2226: 'on' => 'Show',
2227: 'off' => 'Hide',
2228: );
2229: my $clickerchg = 'on';
2230: if ($displayclickers eq 'on') {
2231: $clickerchg = 'off';
2232: }
2233: $output .= ' <th>'."\n".' '
2234: .&mt('[_1]'.$clicker_options{$clickerchg}.'[_2] clicker id'
2235: ,'<a href="javascript:document.'.$formname.'.displayclickers.value='
2236: ."'".$clickerchg."'".';document.'.$formname.'.submit();">'
2237: ,'</a>')
2238: ."\n".' </th>'."\n";
2239:
2240: # Photo display on or off?
2241: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
2242: my %photo_options = &Apache::lonlocal::texthash(
2243: 'on' => 'Show',
2244: 'off' => 'Hide',
2245: );
2246: my $photochg = 'on';
2247: if ($displayphotos eq 'on') {
2248: $photochg = 'off';
2249: }
2250: $output .= ' <th>'."\n".' '.
2251: '<a href="javascript:document.'.$formname.'.displayphotos.value='.
2252: "'".$photochg."'".';document.'.$formname.'.submit();">'.
2253: $photo_options{$photochg}.'</a> '.$lt{'photo'}."\n".
2254: ' </th>'."\n";
2255: }
2256: }
2257: }
2258: $output .= &Apache::loncommon::end_data_table_header_row();
2259: # Done with the HTML header line
2260: } elsif ($mode eq 'csv') {
2261: #
2262: # Open a file
2263: $CSVfilename = '/prtspool/'.
2264: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
2265: time.'_'.rand(1000000000).'.csv';
2266: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
2267: $r->log_error("Couldn't open $CSVfilename for output $!");
2268: $r->print(&mt('Problems occurred in writing the CSV file. '
2269: .'This error has been logged. '
2270: .'Please alert your LON-CAPA administrator.'));
2271: $CSVfile = undef;
2272: }
2273: #
2274: push @cols,'clicker';
2275: # Write headers and data to file
2276: print $CSVfile '"'.$results_description.'"'."\n";
2277: print $CSVfile '"'.join('","',map {
2278: &Apache::loncommon::csv_translate($lt{$_})
2279: } (@cols))."\"\n";
2280: } elsif ($mode eq 'excel') {
2281: push @cols,'clicker';
2282: # Create the excel spreadsheet
2283: ($excel_workbook,$excel_filename,$format) =
2284: &Apache::loncommon::create_workbook($r);
2285: return if (! defined($excel_workbook));
2286: $excel_sheet = $excel_workbook->addworksheet('userlist');
2287: $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
2288: #
2289: my @colnames = map {$lt{$_}} (@cols);
2290:
2291: $excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
2292: }
2293:
2294: # Done with header lines in all formats
2295: my %index;
2296: my $i;
2297: foreach my $idx (@$keylist) {
2298: $index{$idx} = $i++;
2299: }
2300: my $usercount = 0;
2301: my ($secfilter,$grpfilter);
2302: if ($context eq 'course') {
2303: $secfilter = $env{'form.secfilter'};
2304: $grpfilter = $env{'form.grpfilter'};
2305: if ($secfilter eq '') {
2306: $secfilter = 'all';
2307: }
2308: if ($grpfilter eq '') {
2309: $grpfilter = 'all';
2310: }
2311: }
2312: # Get groups, role, permanent e-mail so we can sort on them if
2313: # necessary.
2314: foreach my $user (keys(%{$userlist})) {
2315: if ($user eq '' ) {
2316: delete($userlist->{$user});
2317: next;
2318: }
2319: if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) {
2320: delete($userlist->{$user});
2321: next;
2322: }
2323: my ($uname,$udom,$role,$groups,$email);
2324: if (($statusmode ne 'Any') &&
2325: ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
2326: delete($userlist->{$user});
2327: next;
2328: }
2329: if ($context eq 'domain') {
2330: if ($env{'form.roletype'} eq 'domain') {
2331: ($role,$uname,$udom) = split(/:/,$user);
2332: if (($uname eq $env{'request.role.domain'}.'-domainconfig') &&
2333: ($udom eq $env{'request.role.domain'})) {
2334: delete($userlist->{$user});
2335: next;
2336: }
2337: } elsif ($env{'form.roletype'} eq 'author') {
2338: ($uname,$udom,$role) = split(/:/,$user,-1);
2339: } elsif ($env{'form.roletype'} eq 'course') {
2340: ($uname,$udom,$role) = split(/:/,$user);
2341: }
2342: } else {
2343: ($uname,$udom,$role) = split(/:/,$user,-1);
2344: if (($context eq 'course') && $role eq '') {
2345: $role = 'st';
2346: }
2347: }
2348: $userlist->{$user}->[$index{'role'}] = $role;
2349: if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
2350: delete($userlist->{$user});
2351: next;
2352: }
2353: if ($context eq 'course') {
2354: my @ac_groups;
2355: if (ref($classgroups) eq 'HASH') {
2356: $groups = $classgroups->{$user};
2357: }
2358: if (ref($groups->{'active'}) eq 'HASH') {
2359: @ac_groups = keys(%{$groups->{'active'}});
2360: $userlist->{$user}->[$index{'groups'}] = join(', ',@ac_groups);
2361: }
2362: if ($mode ne 'autoenroll') {
2363: my $section = $userlist->{$user}->[$index{'section'}];
2364: if (($env{'request.course.sec'} ne '') &&
2365: ($section ne $env{'request.course.sec'})) {
2366: if ($role eq 'st') {
2367: delete($userlist->{$user});
2368: next;
2369: }
2370: }
2371: if ($secfilter eq 'none') {
2372: if ($section ne '') {
2373: delete($userlist->{$user});
2374: next;
2375: }
2376: } elsif ($secfilter ne 'all') {
2377: if ($section ne $secfilter) {
2378: delete($userlist->{$user});
2379: next;
2380: }
2381: }
2382: if ($grpfilter eq 'none') {
2383: if (@ac_groups > 0) {
2384: delete($userlist->{$user});
2385: next;
2386: }
2387: } elsif ($grpfilter ne 'all') {
2388: if (!grep(/^\Q$grpfilter\E$/,@ac_groups)) {
2389: delete($userlist->{$user});
2390: next;
2391: }
2392: }
2393: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
2394: if (($displayphotos eq 'on') && ($role eq 'st')) {
2395: $userlist->{$user}->[$index{'photo'}] =
2396: &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg');
2397: $userlist->{$user}->[$index{'thumbnail'}] =
2398: &Apache::lonnet::retrievestudentphoto($udom,$uname,
2399: 'gif','thumbnail');
2400: }
2401: }
2402: }
2403: }
2404: my %emails = &Apache::loncommon::getemails($uname,$udom);
2405: if ($emails{'permanentemail'} =~ /\S/) {
2406: $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
2407: }
2408: $usercount ++;
2409: }
2410: my $autocount = 0;
2411: my $manualcount = 0;
2412: my $lockcount = 0;
2413: my $unlockcount = 0;
2414: if ($usercount) {
2415: $r->print($output);
2416: } else {
2417: if ($mode eq 'autoenroll') {
2418: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
2419: } else {
2420: return;
2421: }
2422: }
2423: #
2424: # Sort the users
2425: my $index = $index{$sortby};
2426: my $second = $index{'username'};
2427: my $third = $index{'domain'};
2428: my @sorted_users = sort {
2429: lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index])
2430: ||
2431: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
2432: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
2433: } (keys(%$userlist));
2434: my $rowcount = 0;
2435: foreach my $user (@sorted_users) {
2436: my %in;
2437: my $sdata = $userlist->{$user};
2438: $rowcount ++;
2439: foreach my $item (@{$keylist}) {
2440: $in{$item} = $sdata->[$index{$item}];
2441: }
2442: my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
2443: if ($clickers!~/\w/) { $clickers='-'; }
2444: $in{'clicker'} = $clickers;
2445: my $role = $in{'role'};
2446: $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}]);
2447: if (! defined($in{'start'}) || $in{'start'} == 0) {
2448: $in{'start'} = &mt('none');
2449: } else {
2450: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
2451: }
2452: if (! defined($in{'end'}) || $in{'end'} == 0) {
2453: $in{'end'} = &mt('none');
2454: } else {
2455: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
2456: }
2457: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
2458: $r->print(&Apache::loncommon::start_data_table_row());
2459: my $checkval;
2460: if ($mode eq 'autoenroll') {
2461: my $cellentry;
2462: if ($in{'type'} eq 'auto') {
2463: $cellentry = '<b>'.&mt('auto').'</b> <label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'" /> Change</label>';
2464: $autocount ++;
2465: } else {
2466: $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'}.'" /> Change</label></span></td></tr><tr><td><span class="LC_nobreak">';
2467: $manualcount ++;
2468: if ($in{'lockedtype'}) {
2469: $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'" /> '.&mt('Unlock').'</label>';
2470: $unlockcount ++;
2471: } else {
2472: $cellentry .= '<label><input type="checkbox" name="lockchg" value="'.$in{'username'}.':'.$in{'domain'}.'" /> '.&mt('Lock').'</label>';
2473: $lockcount ++;
2474: }
2475: $cellentry .= '</span></td></tr></table>';
2476: }
2477: $r->print("<td>$cellentry</td>\n");
2478: } else {
2479: if ($mode ne 'pickauthor') {
2480: $r->print("<td>$rowcount</td>\n");
2481: }
2482: if ($actionselect) {
2483: my $showcheckbox;
2484: if ($role =~ /^cr\//) {
2485: $showcheckbox = $canchange{'cr'};
2486: } else {
2487: $showcheckbox = $canchange{$role};
2488: }
2489: if (!$showcheckbox) {
2490: if ($context eq 'course') {
2491: if ($canchangesec{$role} ne '') {
2492: if ($canchangesec{$role} eq $in{'section'}) {
2493: $showcheckbox = 1;
2494: }
2495: }
2496: }
2497: }
2498: if ($showcheckbox) {
2499: $checkval = $user;
2500: if ($context eq 'course') {
2501: if ($role eq 'st') {
2502: $checkval .= ':st';
2503: }
2504: $checkval .= ':'.$in{'section'};
2505: if ($role eq 'st') {
2506: $checkval .= ':'.$in{'type'}.':'.
2507: $in{'lockedtype'};
2508: }
2509: }
2510: $r->print('<td><input type="checkbox" name="'.
2511: 'actionlist" value="'.$checkval.'"></td>');
2512: } else {
2513: $r->print('<td> </td>');
2514: }
2515: } elsif ($mode eq 'pickauthor') {
2516: $r->print('<td><input type="button" name="chooseauthor" onclick="javascript:gochoose('."'$in{'username'}'".');" value="'.&mt('Select').'" /></td>');
2517: }
2518: }
2519: foreach my $item (@cols) {
2520: if ($item eq 'username') {
2521: $r->print('<td>'.&print_username_link($mode,\%in).'</td>');
2522: } elsif (($item eq 'start' || $item eq 'end') && ($actionselect)) {
2523: $r->print('<td>'.$in{$item}.'<input type="hidden" name="'.$checkval.'_'.$item.'" value="'.$sdata->[$index{$item}].'" /></td>'."\n");
2524: } else {
2525: $r->print('<td>'.$in{$item}.'</td>'."\n");
2526: }
2527: }
2528: if (($context eq 'course') && ($mode ne 'autoenroll')) {
2529: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
2530: if ($displayclickers eq 'on') {
2531: my $clickers =
2532: (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
2533: if ($clickers!~/\w/) { $clickers='-'; }
2534: $r->print('<td>'.$clickers.'</td>');
2535: } else {
2536: $r->print(' <td> </td> ');
2537: }
2538: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
2539: if ($displayphotos eq 'on' && $role eq 'st' && $in{'photo'} ne '') {
2540: $r->print(' <td align="right"><a href="javascript:photowindow('."'".$in{'photo'}."'".')"><img src="'.$in{'thumbnail'}.'" border="1"></a></td>');
2541: } else {
2542: $r->print(' <td> </td> ');
2543: }
2544: }
2545: }
2546: }
2547: $r->print(&Apache::loncommon::end_data_table_row());
2548: } elsif ($mode eq 'csv') {
2549: next if (! defined($CSVfile));
2550: # no need to bother with $linkto
2551: if (! defined($in{'start'}) || $in{'start'} == 0) {
2552: $in{'start'} = &mt('none');
2553: } else {
2554: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
2555: }
2556: if (! defined($in{'end'}) || $in{'end'} == 0) {
2557: $in{'end'} = &mt('none');
2558: } else {
2559: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
2560: }
2561: my @line = ();
2562: foreach my $item (@cols) {
2563: push @line,&Apache::loncommon::csv_translate($in{$item});
2564: }
2565: print $CSVfile '"'.join('","',@line)."\"\n";
2566: } elsif ($mode eq 'excel') {
2567: my $col = 0;
2568: foreach my $item (@cols) {
2569: if ($item eq 'start' || $item eq 'end') {
2570: if (defined($item) && $item != 0) {
2571: $excel_sheet->write($row,$col++,
2572: &Apache::lonstathelpers::calc_serial($in{item}),
2573: $format->{'date'});
2574: } else {
2575: $excel_sheet->write($row,$col++,'none');
2576: }
2577: } else {
2578: $excel_sheet->write($row,$col++,$in{$item});
2579: }
2580: }
2581: $row++;
2582: }
2583: }
2584: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
2585: $r->print(&Apache::loncommon::end_data_table().'<br />');
2586: } elsif ($mode eq 'excel') {
2587: $excel_workbook->close();
2588: $r->print(&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '<p><a href="'.$excel_filename.'">','</a>')."</p>\n");
2589: } elsif ($mode eq 'csv') {
2590: close($CSVfile);
2591: $r->print(&mt('[_1]Your CSV file[_2] is ready for download.', '<p><a href="'.$CSVfilename.'">','</a>')."</p>\n");
2592: $r->rflush();
2593: }
2594: if ($mode eq 'autoenroll') {
2595: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
2596: } else {
2597: return ($usercount);
2598: }
2599: }
2600:
2601: sub bulkaction_javascript {
2602: my ($formname,$caller) = @_;
2603: my $docstart = 'document';
2604: if ($caller eq 'popup') {
2605: $docstart = 'opener.document';
2606: }
2607: my %lt = &Apache::lonlocal::texthash(
2608: acwi => 'Access will be set to start immediately',
2609: asyo => 'as you did not select an end date in the pop-up window',
2610: accw => 'Access will be set to continue indefinitely',
2611: asyd => 'as you did not select an end date in the pop-up window',
2612: sewi => "Sections will be switched to 'No section'",
2613: ayes => "as you either selected the 'No section' option",
2614: oryo => 'or you did not select a section in the pop-up window',
2615: arol => 'A role with no section will be added',
2616: swbs => 'Sections will be switched to:',
2617: rwba => 'Roles will be added for section(s):',
2618: );
2619: my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
2620: my $noaction = &mt("You need to select an action to take for the user(s) you have selected");
2621: my $singconfirm = &mt(' for a single user?');
2622: my $multconfirm = &mt(' for multiple users?');
2623: my $output = <<"ENDJS";
2624: function verify_action (field) {
2625: var numchecked = 0;
2626: var singconf = '$singconfirm';
2627: var multconf = '$multconfirm';
2628: if ($docstart.$formname.elements[field].length > 0) {
2629: for (i=0; i<$docstart.$formname.elements[field].length; i++) {
2630: if ($docstart.$formname.elements[field][i].checked == true) {
2631: numchecked ++;
2632: }
2633: }
2634: } else {
2635: if ($docstart.$formname.elements[field].checked == true) {
2636: numchecked ++;
2637: }
2638: }
2639: if (numchecked == 0) {
2640: alert("$alert");
2641: return;
2642: } else {
2643: var message = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].text;
2644: var choice = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].value;
2645: if (choice == '') {
2646: alert("$noaction");
2647: return;
2648: } else {
2649: if (numchecked == 1) {
2650: message += singconf;
2651: } else {
2652: message += multconf;
2653: }
2654: ENDJS
2655: if ($caller ne 'popup') {
2656: $output .= <<"NEWWIN";
2657: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate' || choice == 'chgsec') {
2658: opendatebrowser(document.$formname,'$formname','go');
2659: return;
2660:
2661: } else {
2662: if (confirm(message)) {
2663: document.$formname.phase.value = 'bulkchange';
2664: document.$formname.submit();
2665: return;
2666: }
2667: }
2668: NEWWIN
2669: } else {
2670: $output .= <<"POPUP";
2671: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
2672: var datemsg = '';
2673: if (($docstart.$formname.startdate_month.value == '') &&
2674: ($docstart.$formname.startdate_day.value == '') &&
2675: ($docstart.$formname.startdate_year.value == '')) {
2676: datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
2677: }
2678: if (($docstart.$formname.enddate_month.value == '') &&
2679: ($docstart.$formname.enddate_day.value == '') &&
2680: ($docstart.$formname.enddate_year.value == '')) {
2681: datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
2682: }
2683: if (datemsg != '') {
2684: message += "\\n"+datemsg;
2685: }
2686: }
2687: if (choice == 'chgsec') {
2688: var rolefilter = $docstart.$formname.showrole.options[$docstart.$formname.showrole.selectedIndex].value;
2689: var retained = $docstart.$formname.retainsec.value;
2690: var secshow = $docstart.$formname.newsecs.value;
2691: if (secshow == '') {
2692: if (rolefilter == 'st' || retained == 0 || retained == "") {
2693: message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
2694: } else {
2695: message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
2696: }
2697: } else {
2698: if (rolefilter == 'st' || retained == 0 || retained == "") {
2699: message += "\\n\\n$lt{'swbs'} "+secshow+".\\n";
2700: } else {
2701: message += "\\n\\n$lt{'rwba'} "+secshow+".\\n";
2702: }
2703: }
2704: }
2705: if (confirm(message)) {
2706: $docstart.$formname.phase.value = 'bulkchange';
2707: $docstart.$formname.submit();
2708: window.close();
2709: }
2710: POPUP
2711: }
2712: $output .= '
2713: }
2714: }
2715: }
2716: ';
2717: return $output;
2718: }
2719:
2720: sub print_username_link {
2721: my ($mode,$in) = @_;
2722: my $output;
2723: if ($mode eq 'autoenroll') {
2724: $output = $in->{'username'};
2725: } else {
2726: $output = '<a href="javascript:username_display_launch('.
2727: "'$in->{'username'}','$in->{'domain'}'".')" />'.
2728: $in->{'username'}.'</a>';
2729: }
2730: return $output;
2731: }
2732:
2733: sub role_type_names {
2734: my %lt = &Apache::lonlocal::texthash (
2735: 'domain' => 'Domain Roles',
2736: 'author' => 'Co-Author Roles',
2737: 'course' => 'Course Roles',
2738: );
2739: return %lt;
2740: }
2741:
2742: sub select_actions {
2743: my ($context,$setting,$statusmode,$formname) = @_;
2744: my %lt = &Apache::lonlocal::texthash(
2745: revoke => "Revoke user roles",
2746: delete => "Delete user roles",
2747: reenable => "Re-enable expired user roles",
2748: activate => "Make future user roles active now",
2749: chgdates => "Change starting/ending dates",
2750: chgsec => "Change section associated with user roles",
2751: );
2752: my ($output,$options,%choices);
2753: # FIXME Disable actions for now for roletype=course in domain context
2754: if ($context eq 'domain' && $setting eq 'course') {
2755: return;
2756: }
2757: if ($context eq 'course') {
2758: if ($env{'form.showrole'} ne 'Any') {
2759: if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},
2760: $env{'request.course.id'})) {
2761: if ($env{'request.course.sec'} eq '') {
2762: return;
2763: } else {
2764: if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
2765: return;
2766: }
2767: }
2768: }
2769: }
2770: }
2771: if ($statusmode eq 'Any') {
2772: $options .= '
2773: <option value="chgdates">'.$lt{'chgdates'}.'</option>';
2774: $choices{'dates'} = 1;
2775: } else {
2776: if ($statusmode eq 'Future') {
2777: $options .= '
2778: <option value="activate">'.$lt{'activate'}.'</option>';
2779: $choices{'dates'} = 1;
2780: } elsif ($statusmode eq 'Expired') {
2781: $options .= '
2782: <option value="reenable">'.$lt{'reenable'}.'</option>';
2783: $choices{'dates'} = 1;
2784: }
2785: if ($statusmode eq 'Active' || $statusmode eq 'Future') {
2786: $options .= '
2787: <option value="chgdates">'.$lt{'chgdates'}.'</option>
2788: <option value="revoke">'.$lt{'revoke'}.'</option>';
2789: $choices{'dates'} = 1;
2790: }
2791: }
2792: if ($context eq 'domain') {
2793: $options .= '
2794: <option value="delete">'.$lt{'delete'}.'</option>';
2795: }
2796: if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
2797: if (($statusmode ne 'Expired') && ($env{'request.course.sec'} eq '')) {
2798: $options .= '
2799: <option value="chgsec">'.$lt{'chgsec'}.'</option>';
2800: $choices{'sections'} = 1;
2801: }
2802: }
2803: if ($options) {
2804: $output = '<select name="bulkaction">'."\n".
2805: '<option value="" selected="selected">'.
2806: &mt('Please select').'</option>'."\n".$options."\n".'</select>';
2807: if ($choices{'dates'}) {
2808: $output .=
2809: '<input type="hidden" name="startdate_month" value="" />'."\n".
2810: '<input type="hidden" name="startdate_day" value="" />'."\n".
2811: '<input type="hidden" name="startdate_year" value="" />'."\n".
2812: '<input type="hidden" name="startdate_hour" value="" />'."\n".
2813: '<input type="hidden" name="startdate_minute" value="" />'."\n".
2814: '<input type="hidden" name="startdate_second" value="" />'."\n".
2815: '<input type="hidden" name="enddate_month" value="" />'."\n".
2816: '<input type="hidden" name="enddate_day" value="" />'."\n".
2817: '<input type="hidden" name="enddate_year" value="" />'."\n".
2818: '<input type="hidden" name="enddate_hour" value="" />'."\n".
2819: '<input type="hidden" name="enddate_minute" value="" />'."\n".
2820: '<input type="hidden" name="enddate_second" value="" />'."\n".
2821: '<input type="hidden" name="no_end_date" value="" />'."\n";
2822: if ($context eq 'course') {
2823: $output .= '<input type="hidden" name="makedatesdefault" value="" />'."\n";
2824: }
2825: }
2826: if ($choices{'sections'}) {
2827: $output .= '<input type="hidden" name="retainsec" value= "" />'."\n".
2828: '<input type="hidden" name="newsecs" value= "" />'."\n";
2829: }
2830: }
2831: return $output;
2832: }
2833:
2834: sub date_section_javascript {
2835: my ($context,$setting) = @_;
2836: my $title = 'Date_And_Section_Selector';
2837: my %nopopup = &Apache::lonlocal::texthash (
2838: revoke => "Check the boxes for any users for whom roles are to be revoked, and click 'Proceed'",
2839: delete => "Check the boxes for any users for whom roles are to be deleted, and click 'Proceed'",
2840: none => "Choose an action to take for selected users",
2841: );
2842: my $output = '
2843: <script type="text/javascript">'."\n";
2844: $output .= <<"ENDONE";
2845: function opendatebrowser(callingform,formname,calledby) {
2846: var bulkaction = callingform.bulkaction.options[callingform.bulkaction.selectedIndex].value;
2847: var url = '/adm/createuser?';
2848: var type = '';
2849: var showrole = callingform.showrole.options[callingform.showrole.selectedIndex].value;
2850: ENDONE
2851: if ($context eq 'domain') {
2852: $output .= '
2853: type = callingform.roletype.options[callingform.roletype.selectedIndex].value;
2854: ';
2855: }
2856: my $width= '700';
2857: my $height = '400';
2858: $output .= <<"ENDTWO";
2859: url += 'action=dateselect&callingform=' + formname +
2860: '&roletype='+type+'&showrole='+showrole +'&bulkaction='+bulkaction;
2861: var title = '$title';
2862: var options = 'scrollbars=1,resizable=1,menubar=0';
2863: options += ',width=$width,height=$height';
2864: stdeditbrowser = open(url,title,options,'1');
2865: stdeditbrowser.focus();
2866: }
2867: </script>
2868: ENDTWO
2869: return $output;
2870: }
2871:
2872: sub date_section_selector {
2873: my ($context,$permission) = @_;
2874: my $callingform = $env{'form.callingform'};
2875: my $formname = 'dateselect';
2876: my $groupslist = &get_groupslist();
2877: my $sec_js = &setsections_javascript($formname,$groupslist);
2878: my $output = <<"END";
2879: <script type="text/javascript">
2880:
2881: $sec_js
2882:
2883: function saveselections(formname) {
2884:
2885: END
2886: if ($env{'form.bulkaction'} eq 'chgsec') {
2887: $output .= <<"END";
2888: if (formname.retainsec.length > 1) {
2889: for (var i=0; i<formname.retainsec.length; i++) {
2890: if (formname.retainsec[i].checked == true) {
2891: opener.document.$callingform.retainsec.value = formname.retainsec[i].value;
2892: }
2893: }
2894: } else {
2895: opener.document.$callingform.retainsec.value = formname.retainsec.value;
2896: }
2897: setSections(formname);
2898: if (seccheck == 'ok') {
2899: opener.document.$callingform.newsecs.value = formname.sections.value;
2900: }
2901: END
2902: } else {
2903: if ($context eq 'course') {
2904: if (($env{'form.bulkaction'} eq 'reenable') ||
2905: ($env{'form.bulkaction'} eq 'activate') ||
2906: ($env{'form.bulkaction'} eq 'chgdates')) {
2907: if ($env{'request.course.sec'} eq '') {
2908: $output .= <<"END";
2909:
2910: if (formname.makedatesdefault.checked == true) {
2911: opener.document.$callingform.makedatesdefault.value = 1;
2912: }
2913: else {
2914: opener.document.$callingform.makedatesdefault.value = 0;
2915: }
2916:
2917: END
2918: }
2919: }
2920: }
2921: $output .= <<"END";
2922: opener.document.$callingform.startdate_month.value = formname.startdate_month.options[formname.startdate_month.selectedIndex].value;
2923: opener.document.$callingform.startdate_day.value = formname.startdate_day.value;
2924: opener.document.$callingform.startdate_year.value = formname.startdate_year.value;
2925: opener.document.$callingform.startdate_hour.value = formname.startdate_hour.options[formname.startdate_hour.selectedIndex].value;
2926: opener.document.$callingform.startdate_minute.value = formname.startdate_minute.value;
2927: opener.document.$callingform.startdate_second.value = formname.startdate_second.value;
2928: opener.document.$callingform.enddate_month.value = formname.enddate_month.options[formname.enddate_month.selectedIndex].value;
2929: opener.document.$callingform.enddate_day.value = formname.enddate_day.value;
2930: opener.document.$callingform.enddate_year.value = formname.enddate_year.value;
2931: opener.document.$callingform.enddate_hour.value = formname.enddate_hour.options[formname.enddate_hour.selectedIndex].value;
2932: opener.document.$callingform.enddate_minute.value = formname.enddate_minute.value;
2933: opener.document.$callingform.enddate_second.value = formname.enddate_second.value;
2934: if (formname.no_end_date.checked) {
2935: opener.document.$callingform.no_end_date.value = '1';
2936: } else {
2937: opener.document.$callingform.no_end_date.value = '0';
2938: }
2939: END
2940: }
2941: my $verify_action_js = &bulkaction_javascript($callingform,'popup');
2942: $output .= <<"ENDJS";
2943: verify_action('actionlist');
2944: }
2945:
2946: $verify_action_js
2947:
2948: </script>
2949: ENDJS
2950: my %lt = &Apache::lonlocal::texthash (
2951: chac => 'Access dates to apply for selected users',
2952: chse => 'Changes in section affiliation to apply to selected users',
2953: 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.',
2954: forn => 'For a role in a course that is not a student role, a user may have roles in more than one section of a course at a time.',
2955: reta => "Retain each user's current section affiliations?",
2956: dnap => '(Does not apply to student roles).',
2957: );
2958: my ($date_items,$headertext);
2959: if ($env{'form.bulkaction'} eq 'chgsec') {
2960: $headertext = $lt{'chse'};
2961: } else {
2962: $headertext = $lt{'chac'};
2963: my $starttime;
2964: if (($env{'form.bulkaction'} eq 'activate') ||
2965: ($env{'form.bulkaction'} eq 'reenable')) {
2966: $starttime = time;
2967: }
2968: $date_items = &date_setting_table($starttime,undef,$context,
2969: $env{'form.bulkaction'},$formname,
2970: $permission);
2971: }
2972: $output .= '<h3>'.$headertext.'</h3>'.
2973: '<form name="'.$formname.'" method="post">'."\n".
2974: $date_items;
2975: if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
2976: my ($cnum,$cdom) = &get_course_identity();
2977: my $info;
2978: if ($env{'form.showrole'} eq 'st') {
2979: $output .= '<p>'.$lt{'fors'}.'</p>';
2980: } elsif ($env{'form.showrole'} eq 'Any') {
2981: $output .= '<p>'.$lt{'fors'}.'</p>'.
2982: '<p>'.$lt{'forn'}.' ';
2983: $info = $lt{'reta'};
2984: } else {
2985: $output .= '<p>'.$lt{'forn'}.' ';
2986: $info = $lt{'reta'};
2987: }
2988: if ($info) {
2989: $info .= '<span class="LC_nobreak">'.
2990: '<label><input type="radio" name="retainsec" value="1" '.
2991: 'checked="checked" />'.&mt('Yes').'</label> '.
2992: '<label><input type="radio" name="retainsec" value="0" />'.
2993: &mt('No').'</label></span>';
2994: if ($env{'form.showrole'} eq 'Any') {
2995: $info .= '<br />'.$lt{'dnap'};
2996: }
2997: $info .= '</p>';
2998: } else {
2999: $info = '<input type="hidden" name="retainsec" value="0" />';
3000: }
3001: my $rowtitle = &mt('New section to assign');
3002: my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,$permission,$context);
3003: $output .= $info.$secbox;
3004: }
3005: $output .= '<p>'.
3006: '<input type="button" name="dateselection" value="'.&mt('Make changes').'" onclick="javascript:saveselections(this.form)" /></p>'."\n".
3007: '</form>';
3008: return $output;
3009: }
3010:
3011: sub section_picker {
3012: my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode) = @_;
3013: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
3014: my $sections_select .= &course_sections(\%sections_count,$role);
3015: my $secbox = '<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
3016: if ($mode eq 'upload') {
3017: my ($options,$cb_script,$coursepick) =
3018: &default_role_selector($context,1);
3019: $secbox .= &Apache::lonhtmlcommon::row_title(&mt('role'),'LC_oddrow_value').
3020: $options. &Apache::lonhtmlcommon::row_closure(1)."\n";
3021: }
3022: $secbox .= &Apache::lonhtmlcommon::row_title($rowtitle,'LC_oddrow_value')."\n";
3023: if ($env{'request.course.sec'} eq '') {
3024: $secbox .= '<table class="LC_createuser"><tr class="LC_section_row">'."\n".
3025: '<td align="center">'.&mt('Existing sections')."\n".
3026: '<br />'.$sections_select.'</td><td align="center">'.
3027: &mt('New section').'<br />'."\n".
3028: '<input type="text" name="newsec" size="15" />'."\n".
3029: '<input type="hidden" name="sections" value="" />'."\n".
3030: '</td></tr></table>'."\n";
3031: } else {
3032: $secbox .= '<input type="hidden" name="sections" value="'.
3033: $env{'request.course.sec'}.'" />'.
3034: $env{'request.course.sec'};
3035: }
3036: $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n".
3037: &Apache::lonhtmlcommon::end_pick_box().'</p>';
3038: return $secbox;
3039: }
3040:
3041: sub results_header_row {
3042: my ($rolefilter,$statusmode,$context,$permission,$mode) = @_;
3043: my ($description,$showfilter);
3044: if ($rolefilter ne 'Any') {
3045: $showfilter = $rolefilter;
3046: }
3047: if ($context eq 'course') {
3048: if ($mode eq 'csv' || $mode eq 'excel') {
3049: $description = &mt('Course - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
3050: }
3051: if ($statusmode eq 'Expired') {
3052: $description .= &mt('Users in course with expired [_1] roles',$showfilter);
3053: } elsif ($statusmode eq 'Future') {
3054: $description .= &mt('Users in course with future [_1] roles',$showfilter);
3055: } elsif ($statusmode eq 'Active') {
3056: $description .= &mt('Users in course with active [_1] roles',$showfilter);
3057: } else {
3058: if ($rolefilter eq 'Any') {
3059: $description .= &mt('All users in course');
3060: } else {
3061: $description .= &mt('All users in course with [_1] roles',$rolefilter);
3062: }
3063: }
3064: my $constraint;
3065: my $viewablesec = &viewable_section($permission);
3066: if ($viewablesec ne '') {
3067: if ($env{'form.showrole'} eq 'st') {
3068: $constraint = &mt('only users in section "[_1]"',$viewablesec);
3069: } elsif ($env{'form.showrole'} ne 'cc') {
3070: $constraint = &mt('only users affiliated with no section or section "[_1]"',$viewablesec);
3071: }
3072: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
3073: if ($env{'form.grpfilter'} eq 'none') {
3074: $constraint .= &mt(' and not in any group');
3075: } else {
3076: $constraint .= &mt(' and members of group: "[_1]"',$env{'form.grpfilter'});
3077: }
3078: }
3079: } else {
3080: if (($env{'form.secfilter'} ne 'all') && ($env{'form.secfilter'} ne '')) {
3081: if ($env{'form.secfilter'} eq 'none') {
3082: $constraint = &mt('only users affiliated with no section');
3083: } else {
3084: $constraint = &mt('only users affiliated with section "[_1]"',$env{'form.secfilter'});
3085: }
3086: }
3087: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
3088: if ($env{'form.grpfilter'} eq 'none') {
3089: if ($constraint eq '') {
3090: $constraint = &mt('only users not in any group');
3091: } else {
3092: $constraint .= &mt(' and also not in any group');
3093: }
3094: } else {
3095: if ($constraint eq '') {
3096: $constraint = &mt('only members of group: "[_1]"',$env{'form.grpfilter'});
3097: } else {
3098: $constraint .= &mt(' and also members of group: "[_1]"'.$env{'form.grpfilter'});
3099: }
3100: }
3101: }
3102: }
3103: if ($constraint ne '') {
3104: $description .= ' ('.$constraint.')';
3105: }
3106: } elsif ($context eq 'author') {
3107: $description =
3108: &mt('Author space for [_1]'
3109: ,'<span class="LC_cusr_emph">'
3110: .&Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'})
3111: .'</span>')
3112: .': ';
3113: if ($statusmode eq 'Expired') {
3114: $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
3115: } elsif ($statusmode eq 'Future') {
3116: $description .= &mt('Co-authors with future [_1] roles',$showfilter);
3117: } elsif ($statusmode eq 'Active') {
3118: $description .= &mt('Co-authors with active [_1] roles',$showfilter);
3119: } else {
3120: if ($rolefilter eq 'Any') {
3121: $description .= &mt('All co-authors');
3122: } else {
3123: $description .= &mt('All co-authors with [_1] roles',$rolefilter);
3124: }
3125: }
3126: } elsif ($context eq 'domain') {
3127: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
3128: $description = &mt('Domain - [_1]:',$domdesc).' ';
3129: if ($env{'form.roletype'} eq 'domain') {
3130: if ($statusmode eq 'Expired') {
3131: $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
3132: } elsif ($statusmode eq 'Future') {
3133: $description .= &mt('Users in domain with future [_1] roles',$showfilter);
3134: } elsif ($statusmode eq 'Active') {
3135: $description .= &mt('Users in domain with active [_1] roles',$showfilter);
3136: } else {
3137: if ($rolefilter eq 'Any') {
3138: $description .= &mt('All users in domain');
3139: } else {
3140: $description .= &mt('All users in domain with [_1] roles',$rolefilter);
3141: }
3142: }
3143: } elsif ($env{'form.roletype'} eq 'author') {
3144: if ($statusmode eq 'Expired') {
3145: $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
3146: } elsif ($statusmode eq 'Future') {
3147: $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
3148: } elsif ($statusmode eq 'Active') {
3149: $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
3150: } else {
3151: if ($rolefilter eq 'Any') {
3152: $description .= &mt('All users with co-author roles in domain',$showfilter);
3153: } else {
3154: $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
3155: }
3156: }
3157: } elsif ($env{'form.roletype'} eq 'course') {
3158: my $coursefilter = $env{'form.coursepick'};
3159: if ($coursefilter eq 'category') {
3160: my $instcode = &instcode_from_coursefilter();
3161: if ($instcode eq '.') {
3162: $description .= &mt('All courses in domain').' - ';
3163: } else {
3164: $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
3165: }
3166: } elsif ($coursefilter eq 'selected') {
3167: $description .= &mt('Selected courses in domain').' - ';
3168: } elsif ($coursefilter eq 'all') {
3169: $description .= &mt('All courses in domain').' - ';
3170: }
3171: if ($statusmode eq 'Expired') {
3172: $description .= &mt('users with expired [_1] roles',$showfilter);
3173: } elsif ($statusmode eq 'Future') {
3174: $description .= &mt('users with future [_1] roles',$showfilter);
3175: } elsif ($statusmode eq 'Active') {
3176: $description .= &mt('users with active [_1] roles',$showfilter);
3177: } else {
3178: if ($rolefilter eq 'Any') {
3179: $description .= &mt('all users');
3180: } else {
3181: $description .= &mt('users with [_1] roles',$rolefilter);
3182: }
3183: }
3184: }
3185: }
3186: return $description;
3187: }
3188:
3189: sub viewable_section {
3190: my ($permission) = @_;
3191: my $viewablesec;
3192: if (ref($permission) eq 'HASH') {
3193: if (exists($permission->{'view_section'})) {
3194: $viewablesec = $permission->{'view_section'};
3195: } elsif (exists($permission->{'cusr_section'})) {
3196: $viewablesec = $permission->{'cusr_section'};
3197: }
3198: }
3199: return $viewablesec;
3200: }
3201:
3202:
3203: #################################################
3204: #################################################
3205: sub show_drop_list {
3206: my ($r,$classlist,$nosort,$permission) = @_;
3207: my $cid = $env{'request.course.id'};
3208: my ($cnum,$cdom) = &get_course_identity($cid);
3209: if (! exists($env{'form.sortby'})) {
3210: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
3211: ['sortby']);
3212: }
3213: my $sortby = $env{'form.sortby'};
3214: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
3215: $sortby = 'username';
3216: }
3217: my $action = "drop";
3218: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
3219: $r->print(<<END);
3220: <input type="hidden" name="sortby" value="$sortby" />
3221: <input type="hidden" name="action" value="$action" />
3222: <input type="hidden" name="state" value="done" />
3223: <script type="text/javascript" language="Javascript">
3224: $check_uncheck_js
3225: </script>
3226: <p>
3227: <input type="hidden" name="phase" value="four">
3228: END
3229: my ($indexhash,$keylist) = &make_keylist_array();
3230: my $studentcount = 0;
3231: if (ref($classlist) eq 'HASH') {
3232: foreach my $student (keys(%{$classlist})) {
3233: my $sdata = $classlist->{$student};
3234: my $status = $sdata->[$indexhash->{'status'}];
3235: my $section = $sdata->[$indexhash->{'section'}];
3236: if ($status ne 'Active') {
3237: delete($classlist->{$student});
3238: next;
3239: }
3240: if ($env{'request.course.sec'} ne '') {
3241: if ($section ne $env{'request.course.sec'}) {
3242: delete($classlist->{$student});
3243: next;
3244: }
3245: }
3246: $studentcount ++;
3247: }
3248: }
3249: if (!$studentcount) {
3250: $r->print(&mt('There are no students to drop.'));
3251: return;
3252: }
3253: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
3254: $classlist,$keylist,$cdom,$cnum);
3255: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
3256: 'dom' => "domain",
3257: 'sn' => "student name",
3258: 'sec' => "section",
3259: 'start' => "start date",
3260: 'end' => "end date",
3261: 'groups' => "active groups",
3262: );
3263: if ($nosort) {
3264: $r->print(&Apache::loncommon::start_data_table().
3265: &Apache::loncommon::start_data_table_header_row());
3266: $r->print(<<END);
3267: <th> </th>
3268: <th>$lt{'usrn'}</th>
3269: <th>$lt{'dom'}</th>
3270: <th>ID</th>
3271: <th>$lt{'sn'}</th>
3272: <th>$lt{'sec'}</th>
3273: <th>$lt{'start'}</th>
3274: <th>$lt{'end'}</th>
3275: <th>$lt{'groups'}</th>
3276: END
3277: $r->print(&Apache::loncommon::end_data_table_header_row());
3278: } else {
3279: $r->print(&Apache::loncommon::start_data_table().
3280: &Apache::loncommon::start_data_table_header_row());
3281: $r->print(<<END);
3282: <th> </th>
3283: <th>
3284: <a href="/adm/createuser?action=$action&sortby=username">$lt{'usrn'}</a>
3285: </th><th>
3286: <a href="/adm/createuser?action=$action&sortby=domain">$lt{'dom'}</a>
3287: </th><th>
3288: <a href="/adm/createuser?action=$action&sortby=id">ID</a>
3289: </th><th>
3290: <a href="/adm/createuser?action=$action&sortby=fullname">$lt{'sn'}</a>
3291: </th><th>
3292: <a href="/adm/createuser?action=$action&sortby=section">$lt{'sec'}</a>
3293: </th><th>
3294: <a href="/adm/createuser?action=$action&sortby=start">$lt{'start'}</a>
3295: </th><th>
3296: <a href="/adm/createuser?action=$action&sortby=end">$lt{'end'}</a>
3297: </th><th>
3298: <a href="/adm/createuser?action=$action&sortby=groups">$lt{'groups'}</a>
3299: </th>
3300: END
3301: $r->print(&Apache::loncommon::end_data_table_header_row());
3302: }
3303: #
3304: # Sort the students
3305: my $index = $indexhash->{$sortby};
3306: my $second = $indexhash->{'username'};
3307: my $third = $indexhash->{'domain'};
3308: my @Sorted_Students = sort {
3309: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
3310: ||
3311: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
3312: ||
3313: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
3314: } (keys(%{$classlist}));
3315: foreach my $student (@Sorted_Students) {
3316: my $error;
3317: my $sdata = $classlist->{$student};
3318: my $username = $sdata->[$indexhash->{'username'}];
3319: my $domain = $sdata->[$indexhash->{'domain'}];
3320: my $section = $sdata->[$indexhash->{'section'}];
3321: my $name = $sdata->[$indexhash->{'fullname'}];
3322: my $id = $sdata->[$indexhash->{'id'}];
3323: my $start = $sdata->[$indexhash->{'start'}];
3324: my $end = $sdata->[$indexhash->{'end'}];
3325: my $groups = $classgroups->{$student};
3326: my $active_groups;
3327: if (ref($groups->{active}) eq 'HASH') {
3328: $active_groups = join(', ',keys(%{$groups->{'active'}}));
3329: }
3330: if (! defined($start) || $start == 0) {
3331: $start = &mt('none');
3332: } else {
3333: $start = &Apache::lonlocal::locallocaltime($start);
3334: }
3335: if (! defined($end) || $end == 0) {
3336: $end = &mt('none');
3337: } else {
3338: $end = &Apache::lonlocal::locallocaltime($end);
3339: }
3340: my $studentkey = $student.':'.$section;
3341: my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$indexhash->{'start'}].'" />';
3342: #
3343: $r->print(&Apache::loncommon::start_data_table_row());
3344: $r->print(<<"END");
3345: <td><input type="checkbox" name="droplist" value="$studentkey"></td>
3346: <td>$username</td>
3347: <td>$domain</td>
3348: <td>$id</td>
3349: <td>$name</td>
3350: <td>$section</td>
3351: <td>$start $startitem</td>
3352: <td>$end</td>
3353: <td>$active_groups</td>
3354: END
3355: $r->print(&Apache::loncommon::end_data_table_row());
3356: }
3357: $r->print(&Apache::loncommon::end_data_table().'<br />');
3358: %lt=&Apache::lonlocal::texthash(
3359: 'dp' => "Drop Students",
3360: 'ca' => "check all",
3361: 'ua' => "uncheck all",
3362: );
3363: $r->print(<<"END");
3364: </p><p>
3365: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)">
3366: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)">
3367: <p><input type=submit value="$lt{'dp'}"></p>
3368: END
3369: return;
3370: }
3371:
3372: #
3373: # Print out the initial form to get the file containing a list of users
3374: #
3375: sub print_first_users_upload_form {
3376: my ($r,$context) = @_;
3377: my $str;
3378: $str = '<input type="hidden" name="phase" value="two">';
3379: $str .= '<input type="hidden" name="action" value="upload" />';
3380: $str .= '<input type="hidden" name="state" value="got_file" />';
3381: $str .= "<h3>".&mt('Upload a file containing information about users')."</h3>\n";
3382: $str .= &Apache::loncommon::upfile_select_html();
3383: $str .= '<p>';
3384: $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List",
3385: &mt("How do I create a users list from a spreadsheet")).
3386: "<br />\n";
3387: $str .= &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
3388: &mt("How do I create a CSV file from a spreadsheet"));
3389: $str .= "</p>\n";
3390: $str .= "<p>\n";
3391: $str .= '<label><input type="checkbox" name="noFirstLine" /> '.
3392: &mt('Ignore First Line')."</label></p>\n";
3393: $str .= '<input type="submit" name="fileupload" value="'.
3394: &mt('Go to next step').'">'."<br />\n";
3395: $str .= &Apache::loncommon::end_page();
3396: $r->print($str);
3397: return;
3398: }
3399:
3400: # ================================================= Drop/Add from uploaded file
3401: sub upfile_drop_add {
3402: my ($r,$context,$permission) = @_;
3403: &Apache::loncommon::load_tmp_file($r);
3404: my @userdata=&Apache::loncommon::upfile_record_sep();
3405: if($env{'form.noFirstLine'}){shift(@userdata);}
3406: my @keyfields = split(/\,/,$env{'form.keyfields'});
3407: my %fields=();
3408: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
3409: if ($env{'form.upfile_associate'} eq 'reverse') {
3410: if ($env{'form.f'.$i} ne 'none') {
3411: $fields{$keyfields[$i]}=$env{'form.f'.$i};
3412: }
3413: } else {
3414: $fields{$env{'form.f'.$i}}=$keyfields[$i];
3415: }
3416: }
3417: if ($env{'form.fullup'} ne 'yes') {
3418: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
3419: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />');
3420: }
3421: #
3422: # Store the field choices away
3423: foreach my $field (qw/username names
3424: fname mname lname gen id sec ipwd email role domain/) {
3425: $env{'form.'.$field.'_choice'}=$fields{$field};
3426: }
3427: &Apache::loncommon::store_course_settings('enrollment_upload',
3428: { 'username_choice' => 'scalar',
3429: 'names_choice' => 'scalar',
3430: 'fname_choice' => 'scalar',
3431: 'mname_choice' => 'scalar',
3432: 'lname_choice' => 'scalar',
3433: 'gen_choice' => 'scalar',
3434: 'id_choice' => 'scalar',
3435: 'sec_choice' => 'scalar',
3436: 'ipwd_choice' => 'scalar',
3437: 'email_choice' => 'scalar',
3438: 'role_choice' => 'scalar',
3439: 'domain_choice' => 'scalar'});
3440: #
3441: my ($startdate,$enddate) = &get_dates_from_form();
3442: if ($env{'form.makedatesdefault'}) {
3443: $r->print(&make_dates_default($startdate,$enddate,$context));
3444: }
3445: # Determine domain and desired host (home server)
3446: my $defdom=$env{'request.role.domain'};
3447: my $domain;
3448: if ($env{'form.defaultdomain'} ne '') {
3449: $domain = $env{'form.defaultdomain'};
3450: } else {
3451: $domain = $defdom;
3452: }
3453: my $desiredhost = $env{'form.lcserver'};
3454: if (lc($desiredhost) eq 'default') {
3455: $desiredhost = undef;
3456: } else {
3457: my %home_servers = &Apache::lonnet::get_servers($defdom,'library');
3458: if (! exists($home_servers{$desiredhost})) {
3459: $r->print('<span class="LC_error">'.&mt('Error').
3460: &mt('Invalid home server specified').'</span>');
3461: $r->print(&Apache::loncommon::end_page());
3462: return;
3463: }
3464: }
3465: # Determine authentication mechanism
3466: my $changeauth;
3467: if ($context eq 'domain') {
3468: $changeauth = $env{'form.changeauth'};
3469: }
3470: my $amode = '';
3471: my $genpwd = '';
3472: if ($env{'form.login'} eq 'krb') {
3473: $amode='krb';
3474: $amode.=$env{'form.krbver'};
3475: $genpwd=$env{'form.krbarg'};
3476: } elsif ($env{'form.login'} eq 'int') {
3477: $amode='internal';
3478: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
3479: $genpwd=$env{'form.intarg'};
3480: }
3481: } elsif ($env{'form.login'} eq 'loc') {
3482: $amode='localauth';
3483: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
3484: $genpwd=$env{'form.locarg'};
3485: }
3486: }
3487: if ($amode =~ /^krb/) {
3488: if (! defined($genpwd) || $genpwd eq '') {
3489: $r->print('<span class="Error">'.
3490: &mt('Unable to enroll users').' '.
3491: &mt('No Kerberos domain was specified.').'</span></p>');
3492: $amode = ''; # This causes the loop below to be skipped
3493: }
3494: }
3495: my ($cid,$defaultsec,$defaultrole,$setting);
3496: if ($context eq 'domain') {
3497: $setting = $env{'form.roleaction'};
3498: if ($setting eq 'domain') {
3499: $defaultrole = $env{'form.defaultrole'};
3500: } elsif ($setting eq 'course') {
3501: $defaultrole = $env{'form.courserole'};
3502: $defaultsec = $env{'form.sections'};
3503: }
3504: } elsif ($context eq 'author') {
3505: $defaultrole = $env{'form.defaultrole'};
3506: } elsif ($context eq 'course') {
3507: $defaultrole = $env{'form.defaultrole'};
3508: $defaultsec = $env{'form.sections'};
3509: }
3510: if ($env{'request.course.id'} ne '') {
3511: $cid = $env{'request.course.id'};
3512: } elsif ($setting eq 'course') {
3513: if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
3514: $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
3515: }
3516: }
3517: # Check to see if user information can be changed
3518: my @userinfo = ('firstname','middlename','lastname','generation',
3519: 'permanentemail','id');
3520: my %canmodify;
3521: if (&Apache::lonnet::allowed('mau',$domain)) {
3522: foreach my $field (@userinfo) {
3523: $canmodify{$field} = 1;
3524: }
3525: }
3526: my (%userlist,%modifiable_fields,@poss_roles);
3527: my $secidx = &Apache::loncoursedata::CL_SECTION();
3528: my @courseroles = &roles_by_context('course',1);
3529: if (!&Apache::lonnet::allowed('mau',$domain)) {
3530: if ($context eq 'course' || $context eq 'author') {
3531: @poss_roles = &curr_role_permissions($context);
3532: my @statuses = ('active','future');
3533: my ($indexhash,$keylist) = &make_keylist_array();
3534: my %info;
3535: foreach my $role (@poss_roles) {
3536: %{$modifiable_fields{$role}} = &can_modify_userinfo($context,$domain,
3537: \@userinfo,[$role]);
3538: }
3539: if ($context eq 'course') {
3540: my ($cnum,$cdom) = &get_course_identity();
3541: my $roster = &Apache::loncoursedata::get_classlist();
3542: if (ref($roster) eq 'HASH') {
3543: %userlist = %{$roster};
3544: }
3545: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
3546: \@statuses,\@poss_roles);
3547: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
3548: \%advrolehash,$permission);
3549: } elsif ($context eq 'author') {
3550: my %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
3551: \@statuses,\@poss_roles);
3552: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
3553: \%cstr_roles,$permission);
3554:
3555: }
3556: }
3557: }
3558: if ( $domain eq &LONCAPA::clean_domain($domain)
3559: && ($amode ne '')) {
3560: #######################################
3561: ## Add/Modify Users ##
3562: #######################################
3563: if ($context eq 'course') {
3564: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
3565: } elsif ($context eq 'author') {
3566: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
3567: } else {
3568: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
3569: }
3570: my %counts = (
3571: user => 0,
3572: auth => 0,
3573: role => 0,
3574: );
3575: my $flushc=0;
3576: my %student=();
3577: my (%curr_groups,@sections,@cleansec,$defaultwarn,$groupwarn);
3578: my %userchg;
3579: if ($context eq 'course' || $setting eq 'course') {
3580: if ($context eq 'course') {
3581: # Get information about course groups
3582: %curr_groups = &Apache::longroup::coursegroups();
3583: } elsif ($setting eq 'course') {
3584: if ($cid) {
3585: %curr_groups =
3586: &Apache::longroup::coursegroups($env{'form.dcdomain'},
3587: $env{'form.dccourse'});
3588: }
3589: }
3590: # determine section number
3591: if ($defaultsec =~ /,/) {
3592: push(@sections,split(/,/,$defaultsec));
3593: } else {
3594: push(@sections,$defaultsec);
3595: }
3596: # remove non alphanumeric values from section
3597: foreach my $item (@sections) {
3598: $item =~ s/\W//g;
3599: if ($item eq "none" || $item eq 'all') {
3600: $defaultwarn = &mt('Default section name [_1] could not be used as it is a reserved word.',$item);
3601: } elsif ($item ne '' && exists($curr_groups{$item})) {
3602: $groupwarn = &mt('Default section name "[_1]" is the name of a course group. Section names and group names must be distinct.',$item);
3603: } elsif ($item ne '') {
3604: push(@cleansec,$item);
3605: }
3606: }
3607: if ($defaultwarn) {
3608: $r->print($defaultwarn.'<br />');
3609: }
3610: if ($groupwarn) {
3611: $r->print($groupwarn.'<br />');
3612: }
3613: }
3614: my (%curr_rules,%got_rules,%alerts);
3615: my %customroles = &my_custom_roles();
3616: my @permitted_roles = &roles_on_upload($context,$setting,%customroles);
3617: # Get new users list
3618: foreach my $line (@userdata) {
3619: my @secs;
3620: my %entries=&Apache::loncommon::record_sep($line);
3621: # Determine user name
3622: unless (($entries{$fields{'username'}} eq '') ||
3623: (!defined($entries{$fields{'username'}}))) {
3624: my ($fname, $mname, $lname,$gen) = ('','','','');
3625: if (defined($fields{'names'})) {
3626: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
3627: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
3628: } else {
3629: if (defined($fields{'fname'})) {
3630: $fname=$entries{$fields{'fname'}};
3631: }
3632: if (defined($fields{'mname'})) {
3633: $mname=$entries{$fields{'mname'}};
3634: }
3635: if (defined($fields{'lname'})) {
3636: $lname=$entries{$fields{'lname'}};
3637: }
3638: if (defined($fields{'gen'})) {
3639: $gen=$entries{$fields{'gen'}};
3640: }
3641: }
3642: if ($entries{$fields{'username'}}
3643: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
3644: $r->print('<br />'.
3645: &mt('[_1]: Unacceptable username for user [_2] [_3] [_4] [_5]',
3646: '<b>'.$entries{$fields{'username'}}.'</b>',$fname,$mname,$lname,$gen));
3647: next;
3648: } else {
3649: if ($entries{$fields{'domain'}}
3650: ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
3651: $r->print('<br />'. '<b>'.$entries{$fields{'domain'}}.
3652: '</b>: '.&mt('Unacceptable domain for user [_2] [_3] [_4] [_5]',$fname,$mname,$lname,$gen));
3653: next;
3654: }
3655: my $username = $entries{$fields{'username'}};
3656: my $userdomain = $entries{$fields{'domain'}};
3657: if ($userdomain eq '') {
3658: $userdomain = $domain;
3659: }
3660: if (defined($fields{'sec'})) {
3661: if (defined($entries{$fields{'sec'}})) {
3662: $entries{$fields{'sec'}} =~ s/\W//g;
3663: my $item = $entries{$fields{'sec'}};
3664: if ($item eq "none" || $item eq 'all') {
3665: $r->print('<br />'.&mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a reserved word.','<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item));
3666: next;
3667: } elsif (exists($curr_groups{$item})) {
3668: $r->print('<br />'.&mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a course group.','<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item).' '.&mt('Section names and group names must be distinct.'));
3669: next;
3670: } else {
3671: push(@secs,$item);
3672: }
3673: }
3674: }
3675: if ($env{'request.course.sec'} ne '') {
3676: @secs = ($env{'request.course.sec'});
3677: if (ref($userlist{$username.':'.$userdomain}) eq 'ARRAY') {
3678: my $currsec = $userlist{$username.':'.$userdomain}[$secidx];
3679: if ($currsec ne $env{'request.course.sec'}) {
3680: $r->print('<br />'.&mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]".','<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$secs[0]).'<br />');
3681: if ($currsec eq '') {
3682: $r->print(&mt('This user already has an active/future student role in the course, unaffiliated to any section.'));
3683:
3684: } else {
3685: $r->print(&mt('This user already has an active/future role in section "[_1]" of the course.',$currsec));
3686: }
3687: $r->print('<br />'.&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.',$secs[0]).'<br />');
3688: next;
3689: }
3690: }
3691: } elsif ($context eq 'course' || $setting eq 'course') {
3692: if (@secs == 0) {
3693: @secs = @cleansec;
3694: }
3695: }
3696: # determine id number
3697: my $id='';
3698: if (defined($fields{'id'})) {
3699: if (defined($entries{$fields{'id'}})) {
3700: $id=$entries{$fields{'id'}};
3701: }
3702: $id=~tr/A-Z/a-z/;
3703: }
3704: # determine email address
3705: my $email='';
3706: if (defined($fields{'email'})) {
3707: if (defined($entries{$fields{'email'}})) {
3708: $email=$entries{$fields{'email'}};
3709: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; } }
3710: }
3711: # determine user password
3712: my $password = $genpwd;
3713: if (defined($fields{'ipwd'})) {
3714: if ($entries{$fields{'ipwd'}}) {
3715: $password=$entries{$fields{'ipwd'}};
3716: }
3717: }
3718: # determine user role
3719: my $role = '';
3720: if (defined($fields{'role'})) {
3721: if ($entries{$fields{'role'}}) {
3722: $entries{$fields{'role'}} =~ s/(\s+$|^\s+)//g;
3723: if ($entries{$fields{'role'}} ne '') {
3724: if (grep(/^\Q$entries{$fields{'role'}}\E$/,@permitted_roles)) {
3725: $role = $entries{$fields{'role'}};
3726: }
3727: }
3728: if ($role eq '') {
3729: my $rolestr = join(', ',@permitted_roles);
3730: $r->print('<br />'
3731: .&mt('[_1]: You do not have permission to add the requested role [_2] for the user.'
3732: ,'<b>'.$entries{$fields{'username'}}.'</b>'
3733: ,$entries{$fields{'role'}})
3734: .'<br />'
3735: .&mt('Allowable role(s) is/are: [_1].',$rolestr)."\n"
3736: );
3737: next;
3738: }
3739: }
3740: }
3741: if ($role eq '') {
3742: $role = $defaultrole;
3743: }
3744: # Clean up whitespace
3745: foreach (\$id,\$fname,\$mname,\$lname,\$gen) {
3746: $$_ =~ s/(\s+$|^\s+)//g;
3747: }
3748: # check against rules
3749: my $checkid = 0;
3750: my $newuser = 0;
3751: my (%rulematch,%inst_results,%idinst_results);
3752: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
3753: if ($uhome eq 'no_host') {
3754: next if ($userdomain ne $domain);
3755: $checkid = 1;
3756: $newuser = 1;
3757: my $checkhash;
3758: my $checks = { 'username' => 1 };
3759: $checkhash->{$username.':'.$domain} = { 'newuser' => 1, };
3760: &Apache::loncommon::user_rule_check($checkhash,$checks,
3761: \%alerts,\%rulematch,\%inst_results,\%curr_rules,
3762: \%got_rules);
3763: if (ref($alerts{'username'}) eq 'HASH') {
3764: if (ref($alerts{'username'}{$domain}) eq 'HASH') {
3765: next if ($alerts{'username'}{$domain}{$username});
3766: }
3767: }
3768: } else {
3769: if ($context eq 'course' || $context eq 'author') {
3770: if ($userdomain eq $domain ) {
3771: if ($role eq '') {
3772: my @checkroles;
3773: foreach my $role (@poss_roles) {
3774: my $endkey;
3775: if ($role ne 'st') {
3776: $endkey = ':'.$role;
3777: }
3778: if (exists($userlist{$username.':'.$userdomain.$endkey})) {
3779: if (!grep(/^\Q$role\E$/,@checkroles)) {
3780: push(@checkroles,$role);
3781: }
3782: }
3783: }
3784: if (@checkroles > 0) {
3785: %canmodify = &can_modify_userinfo($context,$domain,\@userinfo,\@checkroles);
3786: }
3787: } elsif (ref($modifiable_fields{$role}) eq 'HASH') {
3788: %canmodify = %{$modifiable_fields{$role}};
3789: }
3790: }
3791: my @newinfo = (\$fname,\$mname,\$lname,\$gen,\$email,\$id);
3792: for (my $i=0; $i<@userinfo; $i++) {
3793: if (${$newinfo[$i]} ne '') {
3794: if (!$canmodify{$userinfo[$i]}) {
3795: ${$newinfo[$i]} = '';
3796: }
3797: }
3798: }
3799: }
3800: }
3801: if ($id ne '') {
3802: if (!$newuser) {
3803: my %idhash = &Apache::lonnet::idrget($userdomain,($username));
3804: if ($idhash{$username} ne $id) {
3805: $checkid = 1;
3806: }
3807: }
3808: if ($checkid) {
3809: my $checkhash;
3810: my $checks = { 'id' => 1 };
3811: $checkhash->{$username.':'.$userdomain} = { 'newuser' => $newuser,
3812: 'id' => $id };
3813: &Apache::loncommon::user_rule_check($checkhash,$checks,
3814: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,
3815: \%got_rules);
3816: if (ref($alerts{'id'}) eq 'HASH') {
3817: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
3818: next if ($alerts{'id'}{$userdomain}{$id});
3819: }
3820: }
3821: }
3822: }
3823: if ($password || $env{'form.login'} eq 'loc') {
3824: my $multiple = 0;
3825: my ($userresult,$authresult,$roleresult,$idresult);
3826: my (%userres,%authres,%roleres,%idres);
3827: my $singlesec = '';
3828: if ($role eq 'st') {
3829: my $sec;
3830: if (@secs > 0) {
3831: $sec = $secs[0];
3832: }
3833: &modifystudent($userdomain,$username,$cid,$sec,
3834: $desiredhost,$context);
3835: $roleresult =
3836: &Apache::lonnet::modifystudent
3837: ($userdomain,$username,$id,$amode,$password,
3838: $fname,$mname,$lname,$gen,$sec,$enddate,
3839: $startdate,$env{'form.forceid'},
3840: $desiredhost,$email,'manual','',$cid,
3841: '',$context);
3842: $userresult = $roleresult;
3843: } else {
3844: if ($role ne '') {
3845: if ($context eq 'course' || $setting eq 'course') {
3846: if ($customroles{$role}) {
3847: $role = 'cr_'.$env{'user.domain'}.'_'.
3848: $env{'user.name'}.'_'.$role;
3849: }
3850: if ($role ne 'cc') {
3851: if (@secs > 1) {
3852: $multiple = 1;
3853: foreach my $sec (@secs) {
3854: ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
3855: &modifyuserrole($context,$setting,
3856: $changeauth,$cid,$userdomain,$username,
3857: $id,$amode,$password,$fname,
3858: $mname,$lname,$gen,$sec,
3859: $env{'form.forceid'},$desiredhost,
3860: $email,$role,$enddate,
3861: $startdate,$checkid);
3862: }
3863: } elsif (@secs > 0) {
3864: $singlesec = $secs[0];
3865: }
3866: }
3867: }
3868: }
3869: if (!$multiple) {
3870: ($userresult,$authresult,$roleresult,$idresult) =
3871: &modifyuserrole($context,$setting,
3872: $changeauth,$cid,$userdomain,$username,
3873: $id,$amode,$password,$fname,
3874: $mname,$lname,$gen,$singlesec,
3875: $env{'form.forceid'},$desiredhost,
3876: $email,$role,$enddate,$startdate,$checkid);
3877: }
3878: }
3879: if ($multiple) {
3880: foreach my $sec (sort(keys(%userres))) {
3881: $flushc =
3882: &user_change_result($r,$userres{$sec},$authres{$sec},
3883: $roleres{$sec},$idres{$sec},\%counts,$flushc,
3884: $username,$userdomain,\%userchg);
3885:
3886: }
3887: } else {
3888: $flushc =
3889: &user_change_result($r,$userresult,$authresult,
3890: $roleresult,$idresult,\%counts,$flushc,
3891: $username,$userdomain,\%userchg);
3892: }
3893: } else {
3894: if ($context eq 'course') {
3895: $r->print('<br />'.
3896: &mt('[_1]: Unable to enroll. No password specified.','<b>'.$username.'</b>')
3897: );
3898: } elsif ($context eq 'author') {
3899: $r->print('<br />'.
3900: &mt('[_1]: Unable to add co-author. No password specified.','<b>'.$username.'</b>')
3901: );
3902: } else {
3903: $r->print('<br />'.
3904: &mt('[_1]: Unable to add user. No password specified.','<b>'.$username.'</b>')
3905: );
3906: }
3907: }
3908: }
3909: }
3910: } # end of foreach (@userdata)
3911: # Flush the course logs so reverse user roles immediately updated
3912: &Apache::lonnet::flushcourselogs();
3913: $r->print("</p>\n<p>\n".&mt('Processed [quant,_1,user].',$counts{'user'}).
3914: "</p>\n");
3915: if ($counts{'role'} > 0) {
3916: $r->print("<p>\n".
3917: &mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.&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.')."</p>\n");
3918: } else {
3919: $r->print('<p>'.&mt('No roles added').'</p>');
3920: }
3921: if ($counts{'auth'} > 0) {
3922: $r->print("<p>\n".
3923: &mt('Authentication changed for [_1] existing users.',
3924: $counts{'auth'})."</p>\n");
3925: }
3926: $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
3927: #####################################
3928: # Display list of students to drop #
3929: #####################################
3930: if ($env{'form.fullup'} eq 'yes') {
3931: $r->print('<h3>'.&mt('Students to Drop')."</h3>\n");
3932: # Get current classlist
3933: my $classlist = &Apache::loncoursedata::get_classlist();
3934: if (! defined($classlist)) {
3935: $r->print('<form name="studentform" method="post" action="/adm/createuser" />'.
3936: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
3937: &mt('There are no students with current/future access to the course.').
3938: '</form>'."\n");
3939: } elsif (ref($classlist) eq 'HASH') {
3940: # Remove the students we just added from the list of students.
3941: foreach my $line (@userdata) {
3942: my %entries=&Apache::loncommon::record_sep($line);
3943: unless (($entries{$fields{'username'}} eq '') ||
3944: (!defined($entries{$fields{'username'}}))) {
3945: delete($classlist->{$entries{$fields{'username'}}.
3946: ':'.$domain});
3947: }
3948: }
3949: # Print out list of dropped students.
3950: &show_drop_list($r,$classlist,'nosort',$permission);
3951: }
3952: }
3953: } # end of unless
3954: if ($env{'form.fullup'} ne 'yes') {
3955: $r->print('</form>');
3956: }
3957: }
3958:
3959: sub print_namespacing_alerts {
3960: my ($domain,$alerts,$curr_rules) = @_;
3961: my $output;
3962: if (ref($alerts) eq 'HASH') {
3963: if (keys(%{$alerts}) > 0) {
3964: if (ref($alerts->{'username'}) eq 'HASH') {
3965: foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
3966: my $count;
3967: if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
3968: $count = keys(%{$alerts->{'username'}{$dom}});
3969: }
3970: my $domdesc = &Apache::lonnet::domain($domain,'description');
3971: if (ref($curr_rules->{$dom}) eq 'HASH') {
3972: $output .= &Apache::loncommon::instrule_disallow_msg(
3973: 'username',$domdesc,$count,'upload');
3974: }
3975: $output .= &Apache::loncommon::user_rule_formats($dom,
3976: $domdesc,$curr_rules->{$dom}{'username'},
3977: 'username');
3978: }
3979: }
3980: if (ref($alerts->{'id'}) eq 'HASH') {
3981: foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
3982: my $count;
3983: if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
3984: $count = keys(%{$alerts->{'id'}{$dom}});
3985: }
3986: my $domdesc = &Apache::lonnet::domain($domain,'description');
3987: if (ref($curr_rules->{$dom}) eq 'HASH') {
3988: $output .= &Apache::loncommon::instrule_disallow_msg(
3989: 'id',$domdesc,$count,'upload');
3990: }
3991: $output .= &Apache::loncommon::user_rule_formats($dom,
3992: $domdesc,$curr_rules->{$dom}{'id'},'id');
3993: }
3994: }
3995: }
3996: }
3997: }
3998:
3999: sub user_change_result {
4000: my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
4001: $username,$userdomain,$userchg) = @_;
4002: my $okresult = 0;
4003: if ($userresult ne 'ok') {
4004: if ($userresult =~ /^error:(.+)$/) {
4005: my $error = $1;
4006: $r->print('<br />'.
4007: &mt('[_1]: Unable to add/modify: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
4008: }
4009: } else {
4010: $counts->{'user'} ++;
4011: $okresult = 1;
4012: }
4013: if ($authresult ne 'ok') {
4014: if ($authresult =~ /^error:(.+)$/) {
4015: my $error = $1;
4016: $r->print('<br />'.
4017: &mt('[_1]: Unable to modify authentication: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
4018: }
4019: } else {
4020: $counts->{'auth'} ++;
4021: $okresult = 1;
4022: }
4023: if ($roleresult ne 'ok') {
4024: if ($roleresult =~ /^error:(.+)$/) {
4025: my $error = $1;
4026: $r->print('<br />'.
4027: &mt('[_1]: Unable to add role: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
4028: }
4029: } else {
4030: $counts->{'role'} ++;
4031: $okresult = 1;
4032: }
4033: if ($okresult) {
4034: $flushc++;
4035: $userchg->{$username.':'.$userdomain}=1;
4036: $r->print('. ');
4037: if ($flushc>15) {
4038: $r->rflush;
4039: $flushc=0;
4040: }
4041: }
4042: if ($idresult) {
4043: $r->print($idresult);
4044: }
4045: return $flushc;
4046: }
4047:
4048: # ========================================================= Menu Phase Two Drop
4049: sub print_drop_menu {
4050: my ($r,$context,$permission) = @_;
4051: $r->print('<h3>'.&mt("Drop Students").'</h3>'."\n".
4052: '<form name="studentform" method="post">'."\n");
4053: my $classlist = &Apache::loncoursedata::get_classlist();
4054: if (! defined($classlist)) {
4055: $r->print(&mt('There are no students currently enrolled.')."\n");
4056: } else {
4057: &show_drop_list($r,$classlist,'nosort',$permission);
4058: }
4059: $r->print('</form>'. &Apache::loncommon::end_page());
4060: return;
4061: }
4062:
4063: # ================================================================== Phase four
4064:
4065: sub update_user_list {
4066: my ($r,$context,$setting,$choice) = @_;
4067: my $now = time;
4068: my $count=0;
4069: my @changelist;
4070: if ($choice eq 'drop') {
4071: @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
4072: } else {
4073: @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
4074: }
4075: my %result_text = ( ok => { 'revoke' => 'Revoked',
4076: 'delete' => 'Deleted',
4077: 'reenable' => 'Re-enabled',
4078: 'activate' => 'Activated',
4079: 'chgdates' => 'Changed Access Dates for',
4080: 'chgsec' => 'Changed section for',
4081: 'drop' => 'Dropped',
4082: },
4083: error => {'revoke' => 'revoking',
4084: 'delete' => 'deleting',
4085: 'reenable' => 're-enabling',
4086: 'activate' => 'activating',
4087: 'chgdates' => 'changing access dates for',
4088: 'chgsec' => 'changing section for',
4089: 'drop' => 'dropping',
4090: },
4091: );
4092: my ($startdate,$enddate);
4093: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
4094: ($startdate,$enddate) = &get_dates_from_form();
4095: }
4096: foreach my $item (@changelist) {
4097: my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,@sections,
4098: $scopestem);
4099: if ($choice eq 'drop') {
4100: ($uname,$udom,$sec) = split(/:/,$item,-1);
4101: $role = 'st';
4102: $cid = $env{'request.course.id'};
4103: $scopestem = '/'.$cid;
4104: $scopestem =~s/\_/\//g;
4105: if ($sec eq '') {
4106: $scope = $scopestem;
4107: } else {
4108: $scope = $scopestem.'/'.$sec;
4109: }
4110: } elsif ($context eq 'course') {
4111: ($uname,$udom,$role,$sec,$type,$locktype) = split(/\:/,$item,-1);
4112: $cid = $env{'request.course.id'};
4113: $scopestem = '/'.$cid;
4114: $scopestem =~s/\_/\//g;
4115: if ($sec eq '') {
4116: $scope = $scopestem;
4117: } else {
4118: $scope = $scopestem.'/'.$sec;
4119: }
4120: } elsif ($context eq 'author') {
4121: ($uname,$udom,$role) = split(/\:/,$item,-1);
4122: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
4123: } elsif ($context eq 'domain') {
4124: if ($setting eq 'domain') {
4125: ($role,$uname,$udom) = split(/\:/,$item,-1);
4126: $scope = '/'.$env{'request.role.domain'}.'/';
4127: } elsif ($setting eq 'author') {
4128: ($uname,$udom,$role,$scope) = split(/\:/,$item);
4129: } elsif ($setting eq 'course') {
4130: ($uname,$udom,$role,$cid,$sec,$type,$locktype) =
4131: split(/\:/,$item);
4132: $scope = '/'.$cid;
4133: $scope =~s/\_/\//g;
4134: if ($sec ne '') {
4135: $scope .= '/'.$sec;
4136: }
4137: }
4138: }
4139: my $plrole = &Apache::lonnet::plaintext($role);
4140: my $start = $env{'form.'.$item.'_start'};
4141: my $end = $env{'form.'.$item.'_end'};
4142: if ($choice eq 'drop') {
4143: # drop students
4144: $end = $now;
4145: $type = 'manual';
4146: $result =
4147: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
4148: } elsif ($choice eq 'revoke') {
4149: # revoke or delete user role
4150: $end = $now;
4151: if ($role eq 'st') {
4152: $result =
4153: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
4154: } else {
4155: $result =
4156: &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
4157: '','',$context);
4158: }
4159: } elsif ($choice eq 'delete') {
4160: if ($role eq 'st') {
4161: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context);
4162: }
4163: $result =
4164: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
4165: $start,1,'',$context);
4166: } else {
4167: #reenable, activate, change access dates or change section
4168: if ($choice ne 'chgsec') {
4169: $start = $startdate;
4170: $end = $enddate;
4171: }
4172: if ($choice eq 'reenable') {
4173: if ($role eq 'st') {
4174: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
4175: } else {
4176: $result =
4177: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
4178: $now,'','',$context);
4179: }
4180: } elsif ($choice eq 'activate') {
4181: if ($role eq 'st') {
4182: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
4183: } else {
4184: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
4185: $now,'','',$context);
4186: }
4187: } elsif ($choice eq 'chgdates') {
4188: if ($role eq 'st') {
4189: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
4190: } else {
4191: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
4192: $start,'','',$context);
4193: }
4194: } elsif ($choice eq 'chgsec') {
4195: my (@newsecs,$revresult,$nochg,@retained);
4196: if ($role ne 'cc') {
4197: @newsecs = split(/,/,$env{'form.newsecs'});
4198: }
4199: # remove existing section if not to be retained.
4200: if (!$env{'form.retainsec'}) {
4201: if ($sec eq '') {
4202: if (@newsecs == 0) {
4203: $result = &mt('No change in section assignment (none)');
4204: $nochg = 1;
4205: } else {
4206: $revresult =
4207: &Apache::lonnet::revokerole($udom,$uname,
4208: $scope,$role,
4209: '','',$context);
4210: }
4211: } else {
4212: if (@newsecs > 0) {
4213: if (grep(/^\Q$sec\E$/,@newsecs)) {
4214: push(@retained,$sec);
4215: } else {
4216: $revresult =
4217: &Apache::lonnet::revokerole($udom,$uname,
4218: $scope,$role,
4219: '','',$context);
4220: }
4221: } else {
4222: $revresult =
4223: &Apache::lonnet::revokerole($udom,$uname,
4224: $scope,$role,
4225: '','',$context);
4226: }
4227: }
4228: } else {
4229: if ($sec eq '') {
4230: $nochg = 1;
4231: } else {
4232: push(@retained,$sec);
4233: }
4234: }
4235: # add new sections
4236: if (@newsecs == 0) {
4237: if (!$nochg) {
4238: if ($role eq 'st') {
4239: $result =
4240: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context);
4241: } else {
4242: my $newscope = $scopestem;
4243: $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
4244: }
4245: }
4246: } else {
4247: foreach my $newsec (@newsecs) {
4248: if (!grep(/^\Q$newsec\E$/,@retained)) {
4249: if ($role eq 'st') {
4250: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context);
4251: } else {
4252: my $newscope = $scopestem;
4253: if ($newsec ne '') {
4254: $newscope .= '/'.$newsec;
4255: }
4256: $result = &Apache::lonnet::assignrole($udom,$uname,
4257: $newscope,$role,$end,$start);
4258: }
4259: }
4260: }
4261: }
4262: }
4263: }
4264: my $extent = $scope;
4265: if ($choice eq 'drop' || $context eq 'course') {
4266: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
4267: if ($cdesc) {
4268: $extent = $cdesc;
4269: }
4270: }
4271: if ($result eq 'ok' || $result eq 'ok:') {
4272: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]",
4273: $plrole,$extent,$uname.':'.$udom).'<br />');
4274: $count++;
4275: } else {
4276: $r->print(
4277: &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]: [_4].",
4278: $plrole,$extent,$uname.':'.$udom,$result).'<br />');
4279: }
4280: }
4281: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
4282: if ($choice eq 'drop') {
4283: $r->print('<input type="hidden" name="action" value="listusers" />'."\n".
4284: '<input type="hidden" name="Status" value="Active" />'."\n".
4285: '<input type="hidden" name="showrole" value="st" />'."\n");
4286: } else {
4287: foreach my $item ('action','sortby','roletype','showrole','Status','secfilter','grpfilter') {
4288: if ($env{'form.'.$item} ne '') {
4289: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.
4290: '" />'."\n");
4291: }
4292: }
4293: }
4294: $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,no users].",$count).'</b></p>');
4295: if ($count > 0) {
4296: if ($choice eq 'revoke' || $choice eq 'drop') {
4297: $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>');
4298: }
4299: # Flush the course logs so reverse user roles immediately updated
4300: &Apache::lonnet::flushcourselogs();
4301: }
4302: if ($env{'form.makedatesdefault'}) {
4303: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
4304: $r->print(&make_dates_default($startdate,$enddate,$context));
4305: }
4306: }
4307: my $linktext = &mt('Display User Lists');
4308: if ($choice eq 'drop') {
4309: $linktext = &mt('Display current class roster');
4310: }
4311: $r->print('<a href="javascript:document.studentform.submit()">'.$linktext.'</a></form>'."\n");
4312: }
4313:
4314: sub classlist_drop {
4315: my ($scope,$uname,$udom,$now) = @_;
4316: my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
4317: if (&Apache::lonnet::is_course($cdom,$cnum)) {
4318: if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
4319: my %user;
4320: my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
4321: return &mt('Drop from classlist: [_1]',
4322: '<b>'.$result.'</b>').'<br />';
4323: }
4324: }
4325: }
4326:
4327: sub active_student_roles {
4328: my ($cnum,$cdom,$uname,$udom) = @_;
4329: my %roles =
4330: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
4331: ['future','active'],['st']);
4332: return exists($roles{"$cnum:$cdom:st"});
4333: }
4334:
4335: sub section_check_js {
4336: my $groupslist= &get_groupslist();
4337: return <<"END";
4338: function validate(caller) {
4339: var groups = new Array($groupslist);
4340: var secname = caller.value;
4341: if ((secname == 'all') || (secname == 'none')) {
4342: alert("'"+secname+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
4343: return 'error';
4344: }
4345: if (secname != '') {
4346: for (var k=0; k<groups.length; k++) {
4347: if (secname == groups[k]) {
4348: alert("'"+secname+"' may not be used as the name for a section, as it is the name of a course group.\\nSection names and group names must be distinct. Please choose a different section name.");
4349: return 'error';
4350: }
4351: }
4352: }
4353: return 'ok';
4354: }
4355: END
4356: }
4357:
4358: sub set_login {
4359: my ($dom,$authformkrb,$authformint,$authformloc) = @_;
4360: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4361: my $response;
4362: my ($authnum,%can_assign) =
4363: &Apache::loncommon::get_assignable_auth($dom);
4364: if ($authnum) {
4365: $response = &Apache::loncommon::start_data_table();
4366: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
4367: $response .= &Apache::loncommon::start_data_table_row().
4368: '<td>'.$authformkrb.'</td>'.
4369: &Apache::loncommon::end_data_table_row()."\n";
4370: }
4371: if ($can_assign{'int'}) {
4372: $response .= &Apache::loncommon::start_data_table_row().
4373: '<td>'.$authformint.'</td>'.
4374: &Apache::loncommon::end_data_table_row()."\n"
4375: }
4376: if ($can_assign{'loc'}) {
4377: $response .= &Apache::loncommon::start_data_table_row().
4378: '<td>'.$authformloc.'</td>'.
4379: &Apache::loncommon::end_data_table_row()."\n";
4380: }
4381: $response .= &Apache::loncommon::end_data_table();
4382: }
4383: return $response;
4384: }
4385:
4386: sub course_sections {
4387: my ($sections_count,$role,$current_sec) = @_;
4388: my $output = '';
4389: my @sections = (sort {$a <=> $b} keys %{$sections_count});
4390: my $numsec = scalar(@sections);
4391: my $is_selected = ' selected="selected" ';
4392: if ($numsec <= 1) {
4393: $output = '<select name="currsec_'.$role.'" >'."\n".
4394: ' <option value="">'.&mt('Select').'</option>'."\n";
4395: if ($current_sec eq 'none') {
4396: $output .=
4397: ' <option value=""'.$is_selected.'>'.&mt('No section').'</option>'."\n";
4398: } else {
4399: $output .=
4400: ' <option value="">'.&mt('No section').'</option>'."\n";
4401: }
4402: if ($numsec == 1) {
4403: if ($current_sec eq $sections[0]) {
4404: $output .=
4405: ' <option value="'.$sections[0].'"'.$is_selected.'>'.$sections[0].'</option>'."\n";
4406: } else {
4407: $output .=
4408: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
4409: }
4410: }
4411: } else {
4412: $output = '<select name="currsec_'.$role.'" ';
4413: my $multiple = 4;
4414: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
4415: if ($role eq 'st') {
4416: $output .= '>'."\n".
4417: ' <option value="">'.&mt('Select').'</option>'."\n";
4418: if ($current_sec eq 'none') {
4419: $output .=
4420: ' <option value=""'.$is_selected.'>'.&mt('No section')."</option>\n";
4421: } else {
4422: $output .=
4423: ' <option value="">'.&mt('No section')."</option>\n";
4424: }
4425: } else {
4426: $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
4427: }
4428: foreach my $sec (@sections) {
4429: if ($current_sec eq $sec) {
4430: $output .= '<option value="'.$sec.'"'.$is_selected.'>'.$sec."</option>\n";
4431: } else {
4432: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
4433: }
4434: }
4435: }
4436: $output .= '</select>';
4437: return $output;
4438: }
4439:
4440: sub get_groupslist {
4441: my $groupslist;
4442: my %curr_groups = &Apache::longroup::coursegroups();
4443: if (%curr_groups) {
4444: $groupslist = join('","',sort(keys(%curr_groups)));
4445: $groupslist = '"'.$groupslist.'"';
4446: }
4447: return $groupslist;
4448: }
4449:
4450: sub setsections_javascript {
4451: my ($formname,$groupslist,$mode,$checkauth) = @_;
4452: my ($checkincluded,$finish,$rolecode,$setsection_js);
4453: if ($mode eq 'upload') {
4454: $checkincluded = 'formname.name == "'.$formname.'"';
4455: $finish = "return 'ok';";
4456: $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
4457: } elsif ($formname eq 'cu') {
4458: $checkincluded = 'formname.elements[i-1].checked == true';
4459: if ($checkauth) {
4460: $finish = "var authcheck = auth_check();\n".
4461: " if (authcheck == 'ok') {\n".
4462: " formname.submit();\n".
4463: " }\n";
4464: } else {
4465: $finish = 'formname.submit()';
4466: }
4467: $rolecode = "var match = str.split('_');
4468: var role = match[3];\n";
4469: } elsif ($formname eq 'enrollstudent') {
4470: $checkincluded = 'formname.name == "'.$formname.'"';
4471: if ($checkauth) {
4472: $finish = "var authcheck = auth_check();\n".
4473: " if (authcheck == 'ok') {\n".
4474: " formname.submit();\n".
4475: " }\n";
4476: } else {
4477: $finish = 'formname.submit()';
4478: }
4479: $rolecode = "var match = str.split('_');
4480: var role = match[1];\n";
4481: } else {
4482: $checkincluded = 'formname.name == "'.$formname.'"';
4483: $finish = "seccheck = 'ok';";
4484: $rolecode = "var match = str.split('_');
4485: var role = match[1];\n";
4486: $setsection_js = "var seccheck = 'alert';";
4487: }
4488: my %alerts = &Apache::lonlocal::texthash(
4489: secd => 'Section designations do not apply to Course Coordinator roles.',
4490: accr => 'A course coordinator role will be added with access to all sections.',
4491: inea => 'In each course, each user may only have one student role at a time.',
4492: youh => 'You had selected ',
4493: secs => 'sections.',
4494: plmo => 'Please modify your selections so they include no more than one section.',
4495: mayn => 'may not be used as the name for a section, as it is a reserved word.',
4496: plch => 'Please choose a different section name.',
4497: mnot => 'may not be used as a section name, as it is the name of a course group.',
4498: secn => 'Section names and group names must be distinct. Please choose a different section name.',
4499: );
4500: $setsection_js .= <<"ENDSECCODE";
4501:
4502: function setSections(formname) {
4503: var re1 = /^currsec_/;
4504: var groups = new Array($groupslist);
4505: for (var i=0;i<formname.elements.length;i++) {
4506: var str = formname.elements[i].name;
4507: var checkcurr = str.match(re1);
4508: if (checkcurr != null) {
4509: if ($checkincluded) {
4510: $rolecode
4511: if (role == 'cc') {
4512: alert("$alerts{'secd'}\\n$alerts{'accr'}");
4513: }
4514: else {
4515: var sections = '';
4516: var numsec = 0;
4517: var sections;
4518: for (var j=0; j<formname.elements[i].length; j++) {
4519: if (formname.elements[i].options[j].selected == true ) {
4520: if (formname.elements[i].options[j].value != "") {
4521: if (numsec == 0) {
4522: if (formname.elements[i].options[j].value != "") {
4523: sections = formname.elements[i].options[j].value;
4524: numsec ++;
4525: }
4526: }
4527: else {
4528: sections = sections + "," + formname.elements[i].options[j].value
4529: numsec ++;
4530: }
4531: }
4532: }
4533: }
4534: if (numsec > 0) {
4535: if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) {
4536: sections = sections + "," + formname.elements[i+1].value;
4537: }
4538: }
4539: else {
4540: sections = formname.elements[i+1].value;
4541: }
4542: var newsecs = formname.elements[i+1].value;
4543: var numsplit;
4544: if (newsecs != null && newsecs != "") {
4545: numsplit = newsecs.split(/,/g);
4546: numsec = numsec + numsplit.length;
4547: }
4548:
4549: if ((role == 'st') && (numsec > 1)) {
4550: alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}")
4551: return;
4552: }
4553: else {
4554: if (numsplit != null) {
4555: for (var j=0; j<numsplit.length; j++) {
4556: if ((numsplit[j] == 'all') ||
4557: (numsplit[j] == 'none')) {
4558: alert("'"+numsplit[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
4559: return;
4560: }
4561: for (var k=0; k<groups.length; k++) {
4562: if (numsplit[j] == groups[k]) {
4563: alert("'"+numsplit[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
4564: return;
4565: }
4566: }
4567: }
4568: }
4569: formname.elements[i+2].value = sections;
4570: }
4571: }
4572: }
4573: }
4574: }
4575: $finish
4576: }
4577: ENDSECCODE
4578: return $setsection_js;
4579: }
4580:
4581: sub can_create_user {
4582: my ($dom,$context,$usertype) = @_;
4583: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4584: my $cancreate = 1;
4585: if (&Apache::lonnet::allowed('mau',$dom)) {
4586: return $cancreate;
4587: }
4588: if (ref($domconf{'usercreation'}) eq 'HASH') {
4589: if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
4590: if ($context eq 'course' || $context eq 'author') {
4591: my $creation = $domconf{'usercreation'}{'cancreate'}{$context};
4592: if ($creation eq 'none') {
4593: $cancreate = 0;
4594: } elsif ($creation ne 'any') {
4595: if (defined($usertype)) {
4596: if ($creation ne $usertype) {
4597: $cancreate = 0;
4598: }
4599: }
4600: }
4601: }
4602: }
4603: }
4604: return $cancreate;
4605: }
4606:
4607: sub can_modify_userinfo {
4608: my ($context,$dom,$fields,$userroles) = @_;
4609: my %domconfig =
4610: &Apache::lonnet::get_dom('configuration',['usermodification'],
4611: $dom);
4612: my %canmodify;
4613: if (ref($fields) eq 'ARRAY') {
4614: foreach my $field (@{$fields}) {
4615: $canmodify{$field} = 0;
4616: if (&Apache::lonnet::allowed('mau',$dom)) {
4617: $canmodify{$field} = 1;
4618: } else {
4619: if (ref($domconfig{'usermodification'}) eq 'HASH') {
4620: if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
4621: if (ref($userroles) eq 'ARRAY') {
4622: foreach my $role (@{$userroles}) {
4623: my $testrole;
4624: if ($context eq 'selfcreate') {
4625: $testrole = $role;
4626: } else {
4627: if ($role =~ /^cr\//) {
4628: $testrole = 'cr';
4629: } else {
4630: $testrole = $role;
4631: }
4632: }
4633: if (ref($domconfig{'usermodification'}{$context}{$testrole}) eq 'HASH') {
4634: if ($domconfig{'usermodification'}{$context}{$testrole}{$field}) {
4635: $canmodify{$field} = 1;
4636: last;
4637: }
4638: }
4639: }
4640: } else {
4641: foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
4642: if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
4643: if ($domconfig{'usermodification'}{$context}{$key}{$field}) {
4644: $canmodify{$field} = 1;
4645: last;
4646: }
4647: }
4648: }
4649: }
4650: }
4651: } elsif ($context eq 'course') {
4652: if (ref($userroles) eq 'ARRAY') {
4653: if (grep(/^st$/,@{$userroles})) {
4654: $canmodify{$field} = 1;
4655: }
4656: } else {
4657: $canmodify{$field} = 1;
4658: }
4659: }
4660: }
4661: }
4662: }
4663: return %canmodify;
4664: }
4665:
4666: sub check_usertype {
4667: my ($dom,$uname,$rules) = @_;
4668: my $usertype;
4669: if (ref($rules) eq 'HASH') {
4670: my @user_rules = keys(%{$rules});
4671: if (@user_rules > 0) {
4672: my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
4673: if (keys(%rule_check) > 0) {
4674: $usertype = 'unofficial';
4675: foreach my $item (keys(%rule_check)) {
4676: if ($rule_check{$item}) {
4677: $usertype = 'official';
4678: last;
4679: }
4680: }
4681: }
4682: }
4683: }
4684: return $usertype;
4685: }
4686:
4687: sub roles_by_context {
4688: my ($context,$custom) = @_;
4689: my @allroles;
4690: if ($context eq 'course') {
4691: @allroles = ('st','ad','ta','ep','in','cc');
4692: if ($custom) {
4693: push(@allroles,'cr');
4694: }
4695: } elsif ($context eq 'author') {
4696: @allroles = ('ca','aa');
4697: } elsif ($context eq 'domain') {
4698: @allroles = ('li','dg','sc','au','dc');
4699: }
4700: return @allroles;
4701: }
4702:
4703: sub get_permission {
4704: my ($context,$roles) = @_;
4705: my %permission;
4706: if ($context eq 'course') {
4707: my $custom = 1;
4708: my @allroles = &roles_by_context($context,$custom);
4709: foreach my $role (@allroles) {
4710: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
4711: $permission{'cusr'} = 1;
4712: last;
4713: }
4714: }
4715: if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
4716: $permission{'custom'} = 1;
4717: }
4718: if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
4719: $permission{'view'} = 1;
4720: }
4721: if (!$permission{'view'}) {
4722: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
4723: $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
4724: if ($permission{'view'}) {
4725: $permission{'view_section'} = $env{'request.course.sec'};
4726: }
4727: }
4728: if (!$permission{'cusr'}) {
4729: if ($env{'request.course.sec'} ne '') {
4730: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
4731: $permission{'cusr'} = (&Apache::lonnet::allowed('cst',$scope));
4732: if ($permission{'cusr'}) {
4733: $permission{'cusr_section'} = $env{'request.course.sec'};
4734: }
4735: }
4736: }
4737: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
4738: $permission{'grp_manage'} = 1;
4739: }
4740: } elsif ($context eq 'author') {
4741: $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
4742: $permission{'view'} = $permission{'cusr'};
4743: } else {
4744: my @allroles = &roles_by_context($context);
4745: foreach my $role (@allroles) {
4746: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
4747: $permission{'cusr'} = 1;
4748: last;
4749: }
4750: }
4751: if (!$permission{'cusr'}) {
4752: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
4753: $permission{'cusr'} = 1;
4754: }
4755: }
4756: if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
4757: $permission{'custom'} = 1;
4758: }
4759: $permission{'view'} = $permission{'cusr'};
4760: }
4761: my $allowed = 0;
4762: foreach my $perm (values(%permission)) {
4763: if ($perm) { $allowed=1; last; }
4764: }
4765: return (\%permission,$allowed);
4766: }
4767:
4768: # ==================================================== Figure out author access
4769:
4770: sub authorpriv {
4771: my ($auname,$audom)=@_;
4772: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
4773: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; } return 1;
4774: }
4775:
4776: sub roles_on_upload {
4777: my ($context,$setting,%customroles) = @_;
4778: my (@possible_roles,@permitted_roles);
4779: @possible_roles = &curr_role_permissions($context,$setting,1);
4780: foreach my $role (@possible_roles) {
4781: if ($role eq 'cr') {
4782: push(@permitted_roles,keys(%customroles));
4783: } else {
4784: push(@permitted_roles,$role);
4785: }
4786: }
4787: return @permitted_roles;
4788: }
4789:
4790: sub get_course_identity {
4791: my ($cid) = @_;
4792: my ($cnum,$cdom,$cdesc);
4793: if ($cid eq '') {
4794: $cid = $env{'request.course.id'}
4795: }
4796: if ($cid ne '') {
4797: $cnum = $env{'course.'.$cid.'.num'};
4798: $cdom = $env{'course.'.$cid.'.domain'};
4799: $cdesc = $env{'course.'.$cid.'.description'};
4800: if ($cnum eq '' || $cdom eq '') {
4801: my %coursehash =
4802: &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
4803: $cdom = $coursehash{'domain'};
4804: $cnum = $coursehash{'num'};
4805: $cdesc = $coursehash{'description'};
4806: }
4807: }
4808: return ($cnum,$cdom,$cdesc);
4809: }
4810:
4811: sub dc_setcourse_js {
4812: my ($formname,$mode,$context) = @_;
4813: my ($dc_setcourse_code,$authen_check);
4814: my $cctext = &Apache::lonnet::plaintext('cc');
4815: my %alerts = §ioncheck_alerts();
4816: my $role = 'role';
4817: if ($mode eq 'upload') {
4818: $role = 'courserole';
4819: } else {
4820: $authen_check = &verify_authen($formname,$context);
4821: }
4822: $dc_setcourse_code = (<<"SCRIPTTOP");
4823: $authen_check
4824:
4825: function setCourse() {
4826: var course = document.$formname.dccourse.value;
4827: if (course != "") {
4828: if (document.$formname.dcdomain.value != document.$formname.origdom.value) {
4829: alert("$alerts{'curd'}");
4830: return;
4831: }
4832: var userrole = document.$formname.$role.options[document.$formname.$role.selectedIndex].value
4833: var section="";
4834: var numsections = 0;
4835: var newsecs = new Array();
4836: for (var i=0; i<document.$formname.currsec.length; i++) {
4837: if (document.$formname.currsec.options[i].selected == true ) {
4838: if (document.$formname.currsec.options[i].value != "" && document.$formname.currsec.options[i].value != null) {
4839: if (numsections == 0) {
4840: section = document.$formname.currsec.options[i].value
4841: numsections = 1;
4842: }
4843: else {
4844: section = section + "," + document.$formname.currsec.options[i].value
4845: numsections ++;
4846: }
4847: }
4848: }
4849: }
4850: if (document.$formname.newsec.value != "" && document.$formname.newsec.value != null) {
4851: if (numsections == 0) {
4852: section = document.$formname.newsec.value
4853: }
4854: else {
4855: section = section + "," + document.$formname.newsec.value
4856: }
4857: newsecs = document.$formname.newsec.value.split(/,/g);
4858: numsections = numsections + newsecs.length;
4859: }
4860: if ((userrole == 'st') && (numsections > 1)) {
4861: alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
4862: return;
4863: }
4864: for (var j=0; j<newsecs.length; j++) {
4865: if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
4866: alert("'"+newsecs[j]+"' $alerts{'mayn'}.\\n$alerts{'plsc'}.");
4867: return;
4868: }
4869: if (document.$formname.groups.value != '') {
4870: var groups = document.$formname.groups.value.split(/,/g);
4871: for (var k=0; k<groups.length; k++) {
4872: if (newsecs[j] == groups[k]) {
4873: alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
4874: return;
4875: }
4876: }
4877: }
4878: }
4879: if ((userrole == 'cc') && (numsections > 0)) {
4880: alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
4881: section = "";
4882: }
4883: SCRIPTTOP
4884: if ($mode ne 'upload') {
4885: $dc_setcourse_code .= (<<"ENDSCRIPT");
4886: var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
4887: var numcourse = getIndex(document.$formname.dccourse);
4888: if (numcourse == "-1") {
4889: alert("$alerts{'thwa'}");
4890: return;
4891: }
4892: else {
4893: document.$formname.elements[numcourse].name = "act"+coursename;
4894: var numnewsec = getIndex(document.$formname.newsec);
4895: if (numnewsec != "-1") {
4896: document.$formname.elements[numnewsec].name = "sec"+coursename;
4897: document.$formname.elements[numnewsec].value = section;
4898: }
4899: var numstart = getIndex(document.$formname.start);
4900: if (numstart != "-1") {
4901: document.$formname.elements[numstart].name = "start"+coursename;
4902: }
4903: var numend = getIndex(document.$formname.end);
4904: if (numend != "-1") {
4905: document.$formname.elements[numend].name = "end"+coursename
4906: }
4907: }
4908: }
4909: var authcheck = auth_check();
4910: if (authcheck == 'ok') {
4911: document.$formname.submit();
4912: }
4913: }
4914: ENDSCRIPT
4915: } else {
4916: $dc_setcourse_code .= "
4917: document.$formname.sections.value = section;
4918: }
4919: return 'ok';
4920: }
4921: ";
4922: }
4923: $dc_setcourse_code .= (<<"ENDSCRIPT");
4924:
4925: function getIndex(caller) {
4926: for (var i=0;i<document.$formname.elements.length;i++) {
4927: if (document.$formname.elements[i] == caller) {
4928: return i;
4929: }
4930: }
4931: return -1;
4932: }
4933: ENDSCRIPT
4934: return $dc_setcourse_code;
4935: }
4936:
4937: sub verify_authen {
4938: my ($formname,$context) = @_;
4939: my %alerts = &authcheck_alerts();
4940: my $finish = "return 'ok';";
4941: if ($context eq 'author') {
4942: $finish = "document.$formname.submit();";
4943: }
4944: my $outcome = <<"ENDSCRIPT";
4945:
4946: function auth_check() {
4947: var logintype;
4948: if (document.$formname.login.length) {
4949: if (document.$formname.login.length > 0) {
4950: var loginpicked = 0;
4951: for (var i=0; i<document.$formname.login.length; i++) {
4952: if (document.$formname.login[i].checked == true) {
4953: loginpicked = 1;
4954: logintype = document.$formname.login[i].value;
4955: }
4956: }
4957: if (loginpicked == 0) {
4958: alert("$alerts{'authen'}");
4959: return;
4960: }
4961: }
4962: } else {
4963: logintype = document.$formname.login.value;
4964: }
4965: if (logintype == 'nochange') {
4966: return 'ok';
4967: }
4968: var argpicked = document.$formname.elements[logintype+'arg'].value;
4969: if ((argpicked == null) || (argpicked == '') || (typeof argpicked == 'undefined')) {
4970: var alertmsg = '';
4971: switch (logintype) {
4972: case 'krb':
4973: alertmsg = '$alerts{'krb'}';
4974: break;
4975: case 'int':
4976: alertmsg = '$alerts{'ipass'}';
4977: case 'fsys':
4978: alertmsg = '$alerts{'ipass'}';
4979: break;
4980: case 'loc':
4981: alertmsg = '';
4982: break;
4983: default:
4984: alertmsg = '';
4985: }
4986: if (alertmsg != '') {
4987: alert(alertmsg);
4988: return;
4989: }
4990: }
4991: $finish
4992: }
4993: ENDSCRIPT
4994: }
4995:
4996: sub sectioncheck_alerts {
4997: my %alerts = &Apache::lonlocal::texthash(
4998: curd => 'You must select a course in the current domain',
4999: inea => 'In each course, each user may only have one student role at a time',
5000: youh => 'You had selected',
5001: sect => 'sections',
5002: plsm => 'Please modify your selections so they include no more than one section',
5003: mayn => 'may not be used as the name for a section, as it is a reserved word',
5004: plsc => 'Please choose a different section name',
5005: mayt => 'may not be used as the name for a section, as it is the name of a course group',
5006: secn => 'Section names and group names must be distinct',
5007: secd => 'Section designations do not apply to ',
5008: role => 'roles',
5009: accr => 'role will be added with access to all sections',
5010: thwa => 'There was a problem with your course selection'
5011: );
5012: return %alerts;
5013: }
5014:
5015: sub authcheck_alerts {
5016: my %alerts =
5017: &Apache::lonlocal::texthash(
5018: authen => 'You must choose an authentication type.',
5019: krb => 'You need to specify the Kerberos domain.',
5020: ipass => 'You need to specify the initial password.',
5021: );
5022: return %alerts;
5023: }
5024:
5025: 1;
5026:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>