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