File:
[LON-CAPA] /
loncom /
interface /
lonuserutils.pm
Revision
1.5:
download - view:
text,
annotated -
select for diffs
Thu Nov 15 21:24:51 2007 UTC (16 years, 9 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
Propagating changes in ID made by Domain Coordinator to classlist.db file in any courses in which user has active or future student roles. Update name changes too.
loncommon.pm
- Pass ref to %got_rules to &user_rule_check(), so retrieval of rules only occurs once per domain. Retrieve rules for both username and ID
- &instrule_disallow_msg() takes a fourth argument ($mode) so message is different for messages generated for uploaded CSV file of users and single user modification.
loncreateuser.pm
- Propagate name changes and ID change to courses if Domain Coordinator is updating user data.
- Only display permanent e-mail on results page (no personal data changes) if one is defined.
- &print_user_modification_page() takes additional argument - $context - if domain adds the checkbox to force an ID change.
lonuserutils.pm
- check for $context was mistakenly checking $setting
- check whether Domain Coordinator wishes to change authentication for existing users should be $checkauth eq 'Yes'
- propagate name changes and ID change to courses if Domain Coordinator is updating user data, and had checked boxes for force ID change, and force course changes
- &update_classlist() moved to lonuserutils.pm from Autoupdate.pl
- &propagate_id_change() added to propagate ID and name changes to courses
- include cr (for Custom role) in option for Course roles for DC when setting filters for user lists.
- summary of filters used (displayed above tabular data) is customized to be an appropriate message for the choice of filters used in all cases.
- &Apache::lonnet::flushcourselogs() after processing adds/modifications in CSV file of users called in all contexts.
Autoupdate.pl
- &update_classlist() moved to lonuserutils.pm
1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
4: # $Id: lonuserutils.pm,v 1.5 2007/11/15 21:24:51 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 LONCAPA();
39:
40: ###############################################################
41: ###############################################################
42: # Drop student from all sections of a course, except optional $csec
43: sub modifystudent {
44: my ($udom,$unam,$courseid,$csec,$desiredhost)=@_;
45: # if $csec is undefined, drop the student from all the courses matching
46: # this one. If $csec is defined, drop them from all other sections of
47: # this course and add them to section $csec
48: my $cdom = $env{'course.'.$courseid.'.domain'};
49: my $cnum = $env{'course.'.$courseid.'.num'};
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);
72: $result .= $reply.':';
73: }
74: }
75: }
76: }
77: if ($result eq '') {
78: $result = 'Unable to find section for this student';
79: } else {
80: $result =~ s/(ok:)+/ok/g;
81: }
82: return $result;
83: }
84:
85: sub modifyuserrole {
86: my ($context,$setting,$changeauth,$cid,$udom,$uname,$uid,$umode,$upass,
87: $first,$middle,$last,$gene,$sec,$forceid,$desiredhome,$email,$role,
88: $end,$start,$checkid) = @_;
89: my ($scope,$userresult,$authresult,$roleresult,$idresult);
90: if ($setting eq 'course' || $context eq 'course') {
91: $scope = '/'.$cid;
92: $scope =~ s/\_/\//g;
93: if ($role ne 'cc' && $sec ne '') {
94: $scope .='/'.$sec;
95: }
96: } elsif ($context eq 'domain') {
97: $scope = '/'.$env{'request.role.domain'}.'/';
98: } elsif ($context eq 'construction_space') {
99: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
100: }
101: if ($context eq 'domain') {
102: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
103: if ($uhome ne 'no_host') {
104: if (($changeauth eq 'Yes') && (&Apache::lonnet::allowed('mau',$udom))) {
105: if ((($umode =~ /^krb4|krb5|internal$/) && $upass ne '') ||
106: ($umode eq 'localauth')) {
107: $authresult = &Apache::lonnet::modifyuserauth($udom,$uname,$umode,$upass);
108: }
109: }
110: if (($forceid) && (&Apache::lonnet::allowed('mau',$udom)) &&
111: ($env{'form.recurseid'}) && ($checkid)) {
112: my %userupdate = (
113: lastname => $last,
114: middlename => $middle,
115: firstname => $first,
116: generation => $gene,
117: id => $uid,
118: );
119: $idresult = &propagate_id_change($uname,$udom,\%userupdate);
120: }
121: }
122: }
123: $userresult =
124: &Apache::lonnet::modifyuser($udom,$uname,$uid,$umode,$upass,$first,
125: $middle,$last,$gene,$forceid,$desiredhome,
126: $email,$role,$start,$end);
127: if ($userresult eq 'ok') {
128: if ($role ne '') {
129: $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
130: $role,$end,$start);
131: }
132: }
133: return ($userresult,$authresult,$roleresult,$idresult);
134: }
135:
136: sub propagate_id_change {
137: my ($uname,$udom,$user) = @_;
138: my (@types,@roles,@cdoms);
139: @types = ('active','future');
140: @roles = ('st');
141: my $idresult;
142: my %roleshash = &Apache::lonnet::get_my_roles($uname,
143: $udom,'userroles',\@types,\@roles,\@cdoms);
144: foreach my $item (keys(%roleshash)) {
145: my ($cnum,$cdom,$role) = split(/:/,$item);
146: my ($start,$end) = split(/:/,$roleshash{$item});
147: if (&Apache::lonnet::is_course($cdom,$cnum)) {
148: my %userupdate;
149: my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%userupdate);
150: if ($result eq 'ok') {
151: $idresult .= "Classlist change: $uname:$udom - class -> $cnum:$cdom\n";
152: } else {
153: $idresult .= "Error - $result -during classlist update for $uname:$udom in $cnum:$cdom\n";
154: }
155: }
156: }
157: return $idresult;
158: }
159:
160: sub update_classlist {
161: my ($cdom,$cnum,$udom,$uname,$user) = @_;
162: my ($uid,$fullname,$classlistentry);
163: my $fullname =
164: &Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
165: $user->{'lastname'},$user->{'generation'},
166: 'lastname');
167: my %classhash = &Apache::lonnet::get('classlist',[$uname.':'.$udom],
168: $cdom,$cnum);
169: my @classinfo = split(/:/,$classhash{$uname.':'.$udom});
170: my $ididx=&Apache::loncoursedata::CL_ID() - 2;
171: my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2;
172: for (my $i=0; $i<@classinfo; $i++) {
173: if ($i == $ididx) {
174: if (defined($user->{'id'})) {
175: $classlistentry .= $user->{'id'}.':';
176: } else {
177: $classlistentry .= $classinfo[$i].':';
178: }
179: } elsif ($i == $nameidx) {
180: $classlistentry .= $fullname.':';
181: } else {
182: $classlistentry .= $classinfo[$i].':';
183: }
184: }
185: $classlistentry =~ s/:$//;
186: my $reply=&Apache::lonnet::cput('classlist',
187: {"$uname:$udom" => $classlistentry},
188: $cdom,$cnum);
189: if (($reply eq 'ok') || ($reply eq 'delayed')) {
190: return 'ok';
191: } else {
192: return 'error: '.$reply;
193: }
194: }
195:
196:
197: ###############################################################
198: ###############################################################
199: # build a role type and role selection form
200: sub domain_roles_select {
201: # Set up the role type and role selection boxes when in
202: # domain context
203: #
204: # Role types
205: my @roletypes = ('domain','construction_space','course');
206: my %lt = &role_type_names();
207: #
208: # build up the menu information to be passed to
209: # &Apache::loncommon::linked_select_forms
210: my %select_menus;
211: if ($env{'form.roletype'} eq '') {
212: $env{'form.roletype'} = 'domain';
213: }
214: foreach my $roletype (@roletypes) {
215: # set up the text for this domain
216: $select_menus{$roletype}->{'text'}= $lt{$roletype};
217: # we want a choice of 'default' as the default in the second menu
218: if ($env{'form.roletype'} ne '') {
219: $select_menus{$roletype}->{'default'} = $env{'form.showrole'};
220: } else {
221: $select_menus{$roletype}->{'default'} = 'Any';
222: }
223: # Now build up the other items in the second menu
224: my @roles;
225: if ($roletype eq 'domain') {
226: @roles = &domain_roles();
227: } elsif ($roletype eq 'construction_space') {
228: @roles = &construction_space_roles();
229: } else {
230: @roles = &course_roles('domain');
231: unshift(@roles,'cr');
232: }
233: my $order = ['Any',@roles];
234: $select_menus{$roletype}->{'order'} = $order;
235: foreach my $role (@roles) {
236: if ($role eq 'cr') {
237: $select_menus{$roletype}->{'select2'}->{$role} =
238: &mt('Custom role');
239: } else {
240: $select_menus{$roletype}->{'select2'}->{$role} =
241: &Apache::lonnet::plaintext($role);
242: }
243: }
244: $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
245: }
246: my $result = &Apache::loncommon::linked_select_forms
247: ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
248: 'roletype','showrole',\%select_menus,['domain','construction_space','course']);
249: return $result;
250: }
251:
252: ###############################################################
253: ###############################################################
254: sub hidden_input {
255: my ($name,$value) = @_;
256: return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n";
257: }
258:
259: sub print_upload_manager_header {
260: my ($r,$datatoken,$distotal,$krbdefdom,$context)=@_;
261: my $javascript;
262: #
263: if (! exists($env{'form.upfile_associate'})) {
264: $env{'form.upfile_associate'} = 'forward';
265: }
266: if ($env{'form.associate'} eq 'Reverse Association') {
267: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
268: $env{'form.upfile_associate'} = 'reverse';
269: } else {
270: $env{'form.upfile_associate'} = 'forward';
271: }
272: }
273: if ($env{'form.upfile_associate'} eq 'reverse') {
274: $javascript=&upload_manager_javascript_reverse_associate();
275: } else {
276: $javascript=&upload_manager_javascript_forward_associate();
277: }
278: #
279: # Deal with restored settings
280: my $password_choice = '';
281: if (exists($env{'form.ipwd_choice'}) &&
282: $env{'form.ipwd_choice'} ne '') {
283: # If a column was specified for password, assume it is for an
284: # internal password. This is a bug waiting to be filed (could be
285: # local or krb auth instead of internal) but I do not have the
286: # time to mess around with this now.
287: $password_choice = 'int';
288: }
289: #
290: my $javascript_validations =
291: &javascript_validations('auth',$krbdefdom,$password_choice,undef,
292: $env{'request.role.domain'});
293: my $checked=(($env{'form.noFirstLine'})?' checked="checked" ':'');
294: $r->print(&mt('Total number of records found in file: <b>[_1]</b>.',$distotal).
295: "<br />\n");
296: $r->print('<div class="LC_left_float"><h3>'.
297: &mt('Identify fields in uploaded list')."</h3>\n");
298: $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");
299: $r->print(&hidden_input('action','upload').
300: &hidden_input('state','got_file').
301: &hidden_input('associate','').
302: &hidden_input('datatoken',$datatoken).
303: &hidden_input('fileupload',$env{'form.fileupload'}).
304: &hidden_input('upfiletype',$env{'form.upfiletype'}).
305: &hidden_input('upfile_associate',$env{'form.upfile_associate'}));
306: $r->print('<br /><input type="button" value="Reverse Association" '.
307: 'name="'.&mt('Reverse Association').'" '.
308: 'onClick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />');
309: $r->print('<label><input type="checkbox" name="noFirstLine"'.$checked.'/>'.
310: &mt('Ignore First Line').'</label>');
311: $r->print("<br /><br />\n".
312: '<script type="text/javascript" language="Javascript">'."\n".
313: $javascript."\n".$javascript_validations.'</script>');
314: }
315:
316: ###############################################################
317: ###############################################################
318: sub javascript_validations {
319: my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain)=@_;
320: my $authheader;
321: if ($mode eq 'auth') {
322: my %param = ( formname => 'studentform',
323: kerb_def_dom => $krbdefdom,
324: curr_authtype => $curr_authtype);
325: $authheader = &Apache::loncommon::authform_header(%param);
326: } elsif ($mode eq 'createcourse') {
327: my %param = ( formname => 'ccrs',
328: kerb_def_dom => $krbdefdom,
329: curr_authtype => $curr_authtype );
330: $authheader = &Apache::loncommon::authform_header(%param);
331: } elsif ($mode eq 'modifycourse') {
332: my %param = ( formname => 'cmod',
333: kerb_def_dom => $krbdefdom,
334: mode => 'modifycourse',
335: curr_authtype => $curr_authtype,
336: curr_autharg => $curr_authfield );
337: $authheader = &Apache::loncommon::authform_header(%param);
338: }
339:
340: my %alert = &Apache::lonlocal::texthash
341: (username => 'You need to specify the username field.',
342: authen => 'You must choose an authentication type.',
343: krb => 'You need to specify the Kerberos domain.',
344: ipass => 'You need to specify the initial password.',
345: name => 'The optional name field was not specified.',
346: snum => 'The optional ID number field was not specified.',
347: section => 'The optional section field was not specified.',
348: email => 'The optional email address field was not specified.',
349: role => 'The optional role field was not specified.',
350: continue => 'Continue adding users?',
351: );
352:
353: # my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
354: my $function_name =(<<END);
355: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail) {
356: END
357: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($domain);
358: my $auth_checks;
359: if ($mode eq 'createcourse') {
360: $auth_checks .= (<<END);
361: if (vf.autoadds[0].checked == true) {
362: if (current.radiovalue == null || current.radiovalue == 'nochange') {
363: alert('$alert{'authen'}');
364: return;
365: }
366: }
367: END
368: } else {
369: $auth_checks .= (<<END);
370: var foundatype=0;
371: if (founduname==0) {
372: alert('$alert{'username'}');
373: return;
374: }
375:
376: END
377: if ($authnum > 1) {
378: $auth_checks .= (<<END);
379: if (current.radiovalue == null || current.radiovalue == '' || current.radiovalue == 'nochange') {
380: // They did not check any of the login radiobuttons.
381: alert('$alert{'authen'}');
382: return;
383: }
384: END
385: }
386: }
387: if ($mode eq 'createcourse') {
388: $auth_checks .= "
389: if ( (vf.autoadds[0].checked == true) &&
390: (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') ) {
391: ";
392: } elsif ($mode eq 'modifycourse') {
393: $auth_checks .= "
394: if (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') {
395: ";
396: }
397: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
398: $auth_checks .= (<<END);
399: var alertmsg = '';
400: switch (current.radiovalue) {
401: case 'krb':
402: alertmsg = '$alert{'krb'}';
403: break;
404: default:
405: alertmsg = '';
406: }
407: if (alertmsg != '') {
408: alert(alertmsg);
409: return;
410: }
411: }
412: END
413: } else {
414: $auth_checks .= (<<END);
415: foundatype=1;
416: if (current.argfield == null || current.argfield == '') {
417: var alertmsg = '';
418: switch (current.value) {
419: case 'krb':
420: alertmsg = '$alert{'krb'}';
421: break;
422: case 'loc':
423: case 'fsys':
424: alertmsg = '$alert{'ipass'}';
425: break;
426: case 'fsys':
427: alertmsg = '';
428: break;
429: default:
430: alertmsg = '';
431: }
432: if (alertmsg != '') {
433: alert(alertmsg);
434: return;
435: }
436: }
437: END
438: }
439: my $section_checks;
440: my $optional_checks = '';
441: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
442: $optional_checks = (<<END);
443: vf.submit();
444: }
445: END
446: } else {
447: $section_checks = §ion_check_js();
448: $optional_checks = (<<END);
449: var message='';
450: if (foundname==0) {
451: message='$alert{'name'}';
452: }
453: if (foundid==0) {
454: if (message!='') {
455: message+='\\n';
456: }
457: message+='$alert{'snum'}';
458: }
459: if (foundsec==0) {
460: if (message!='') {
461: message+='\\n';
462: }
463: }
464: if (foundemail==0) {
465: if (message!='') {
466: message+='\\n';
467: }
468: message+='$alert{'email'}';
469: }
470: if (message!='') {
471: message+= '\\n$alert{'continue'}';
472: if (confirm(message)) {
473: vf.state.value='enrolling';
474: vf.submit();
475: }
476: } else {
477: vf.state.value='enrolling';
478: vf.submit();
479: }
480: }
481: END
482: }
483: my $result = $function_name;
484: if ( ($mode eq 'auth') || ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
485: $result .= $auth_checks;
486: }
487: $result .= $optional_checks."\n".$section_checks;
488: if ( ($mode eq 'auth') || ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
489: $result .= $authheader;
490: }
491: return $result;
492: }
493: ###############################################################
494: ###############################################################
495: sub upload_manager_javascript_forward_associate {
496: return(<<ENDPICK);
497: function verify(vf,sec_caller) {
498: var founduname=0;
499: var foundpwd=0;
500: var foundname=0;
501: var foundid=0;
502: var foundsec=0;
503: var foundemail=0;
504: var foundrole=0;
505: var tw;
506: for (i=0;i<=vf.nfields.value;i++) {
507: tw=eval('vf.f'+i+'.selectedIndex');
508: if (tw==1) { founduname=1; }
509: if ((tw>=2) && (tw<=6)) { foundname=1; }
510: if (tw==7) { foundid=1; }
511: if (tw==8) { foundsec=1; }
512: if (tw==9) { foundpwd=1; }
513: if (tw==10) { foundemail=1; }
514: if (tw==11) { foundrole=1; }
515: }
516: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole);
517: }
518:
519: //
520: // vf = this.form
521: // tf = column number
522: //
523: // values of nw
524: //
525: // 0 = none
526: // 1 = username
527: // 2 = names (lastname, firstnames)
528: // 3 = fname (firstname)
529: // 4 = mname (middlename)
530: // 5 = lname (lastname)
531: // 6 = gen (generation)
532: // 7 = id
533: // 8 = section
534: // 9 = ipwd (password)
535: // 10 = email address
536: // 11 = role
537:
538: function flip(vf,tf) {
539: var nw=eval('vf.f'+tf+'.selectedIndex');
540: var i;
541: // make sure no other columns are labeled the same as this one
542: for (i=0;i<=vf.nfields.value;i++) {
543: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
544: eval('vf.f'+i+'.selectedIndex=0;')
545: }
546: }
547: // If we set this to 'lastname, firstnames', clear out all the ones
548: // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
549: if (nw==2) {
550: for (i=0;i<=vf.nfields.value;i++) {
551: if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
552: (eval('vf.f'+i+'.selectedIndex')<=6)) {
553: eval('vf.f'+i+'.selectedIndex=0;')
554: }
555: }
556: }
557: // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
558: // clear out any that are set to 'lastname, firstnames' (2)
559: if ((nw>=3) && (nw<=6)) {
560: for (i=0;i<=vf.nfields.value;i++) {
561: if (eval('vf.f'+i+'.selectedIndex')==2) {
562: eval('vf.f'+i+'.selectedIndex=0;')
563: }
564: }
565: }
566: // If we set the password, make the password form below correspond to
567: // the new value.
568: if (nw==9) {
569: changed_radio('int',document.studentform);
570: set_auth_radio_buttons('int',document.studentform);
571: vf.intarg.value='';
572: vf.krbarg.value='';
573: vf.locarg.value='';
574: }
575: }
576:
577: function clearpwd(vf) {
578: var i;
579: for (i=0;i<=vf.nfields.value;i++) {
580: if (eval('vf.f'+i+'.selectedIndex')==9) {
581: eval('vf.f'+i+'.selectedIndex=0;')
582: }
583: }
584: }
585:
586: ENDPICK
587: }
588:
589: ###############################################################
590: ###############################################################
591: sub upload_manager_javascript_reverse_associate {
592: return(<<ENDPICK);
593: function verify(vf,sec_caller) {
594: var founduname=0;
595: var foundpwd=0;
596: var foundname=0;
597: var foundid=0;
598: var foundsec=0;
599: var foundrole=0;
600: var tw;
601: for (i=0;i<=vf.nfields.value;i++) {
602: tw=eval('vf.f'+i+'.selectedIndex');
603: if (i==0 && tw!=0) { founduname=1; }
604: if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
605: if (i==6 && tw!=0) { foundid=1; }
606: if (i==7 && tw!=0) { foundsec=1; }
607: if (i==8 && tw!=0) { foundpwd=1; }
608: if (i==9 && tw!=0) { foundrole=1; }
609: }
610: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundrole);
611: }
612:
613: function flip(vf,tf) {
614: var nw=eval('vf.f'+tf+'.selectedIndex');
615: var i;
616: // picked the all one name field, reset the other name ones to blank
617: if (tf==1 && nw!=0) {
618: for (i=2;i<=5;i++) {
619: eval('vf.f'+i+'.selectedIndex=0;')
620: }
621: }
622: //picked one of the piecewise name fields, reset the all in
623: //one field to blank
624: if ((tf>=2) && (tf<=5) && (nw!=0)) {
625: eval('vf.f1.selectedIndex=0;')
626: }
627: // intial password specified, pick internal authentication
628: if (tf==8 && nw!=0) {
629: changed_radio('int',document.studentform);
630: set_auth_radio_buttons('int',document.studentform);
631: vf.krbarg.value='';
632: vf.intarg.value='';
633: vf.locarg.value='';
634: }
635: }
636:
637: function clearpwd(vf) {
638: var i;
639: if (eval('vf.f8.selectedIndex')!=0) {
640: eval('vf.f8.selectedIndex=0;')
641: }
642: }
643: ENDPICK
644: }
645:
646: ###############################################################
647: ###############################################################
648: sub print_upload_manager_footer {
649: my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context)=@_;
650: my $formname;
651: if ($context eq 'course') {
652: $formname = 'document.studentform';
653: } elsif ($context eq 'construction_space') {
654: $formname = 'document.studentform';
655: } elsif ($context eq 'domain') {
656: $formname = 'document.studentform';
657: }
658: my ($krbdef,$krbdefdom) =
659: &Apache::loncommon::get_kerberos_defaults($defdom);
660: my %param = ( formname => $formname,
661: kerb_def_dom => $krbdefdom,
662: kerb_def_auth => $krbdef
663: );
664: if (exists($env{'form.ipwd_choice'}) &&
665: defined($env{'form.ipwd_choice'}) &&
666: $env{'form.ipwd_choice'} ne '') {
667: $param{'curr_authtype'} = 'int';
668: }
669: my $krbform = &Apache::loncommon::authform_kerberos(%param);
670: my $intform = &Apache::loncommon::authform_internal(%param);
671: my $locform = &Apache::loncommon::authform_local(%param);
672: my $date_table = &date_setting_table(undef,undef,$context);
673:
674: my $Str = "\n".'<div class="LC_left_float">';
675: $Str .= &hidden_input('nfields',$i);
676: $Str .= &hidden_input('keyfields',$keyfields);
677: $Str .= "<h3>".&mt('Login Type')."</h3>\n";
678: if ($context eq 'domain') {
679: $Str .= '<p>'.&mt('Change authentication for existing users to these settings?').' <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>';
680: } else {
681: $Str .= "<p>\n".
682: &mt('Note: this will not take effect if the user already exists').
683: &Apache::loncommon::help_open_topic('Auth_Options').
684: "</p>\n";
685: }
686: $Str .= &set_login($defdom,$krbform,$intform,$locform);
687: my ($home_server_pick,$numlib) =
688: &Apache::loncommon::home_server_form_item($defdom,'lcserver',
689: 'default','hide');
690: if ($numlib > 1) {
691: $Str .= '<h3>'.&mt('LON-CAPA Home Server for New Users')."</h3>\n".
692: &mt('LON-CAPA domain: [_1] with home server: [_2]',$defdom,
693: $home_server_pick).'<br />';
694: } else {
695: $Str .= $home_server_pick;
696: }
697: $Str .= '<h3>'.&mt('Starting and Ending Dates').
698: "</h3>\n";
699: $Str .= "<p>\n".$date_table."</p>\n";
700: if ($context eq 'domain') {
701: $Str .= '<h3>'.&mt('Settings for assigning roles:').'</h3>'."\n".
702: &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>';
703: }
704: if ($context eq 'construction_space') {
705: $Str .= '<h3>'.&mt('Default role')."</h3>\n".
706: &mt('Choose the role to assign to users without one specified in the uploaded file');
707: } elsif ($context eq 'course') {
708: $Str .= '<h3>'.&mt('Default role and section')."</h3>\n".
709: &mt('Choose the role and/or section to assign to users without one specified in the uploaded file');
710: } else {
711: $Str .= '<br /><br /><b>'.&mt('Default role and/or section')."</b><br />\n".
712: &mt('Role and/or section for users without one in the uploaded file.');
713: }
714: $Str .= '<br /><br />';
715: my ($options,$cb_script,$coursepick) = &default_role_selector($context,'defaultrole',1);
716: if ($context eq 'domain') {
717: $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;
718: } elsif ($context eq 'construction_space') {
719: $Str .= $options;
720: } else {
721: $Str .= '<table><tr><td><span class="LC_nobreak"<b>'.&mt('role').': </b>'.
722: $options.'</span></td><td> </td><td><span class="LC_nobreak">'.
723: '<b>'.&mt('section').': </b><input type="text" name="section" value="" size="12" /></span></td></tr></table>';
724: }
725: if ($context eq 'course') {
726: $Str .= "<h3>".&mt('Full Update')."</h3>\n".
727: '<label><input type="checkbox" name="fullup" value="yes">'.
728: ' '.&mt('Full update (also print list of users not enrolled anymore)').
729: "</label></p>\n";
730: }
731: if ($context eq 'course' || $context eq 'domain') {
732: $Str .= &forceid_change($context);
733: }
734: $Str .= '</div><div class="LC_clear_float_footer"><br /><input type="button"'.
735: 'onClick="javascript:verify(this.form,this.form.csec)" '.
736: 'value="Update Users" />'."<br />\n";
737: if ($context eq 'course') {
738: $Str .= &mt('Note: for large courses, this operation may be time '.
739: 'consuming');
740: }
741: $Str .= '</div>';
742: $r->print($Str);
743: return;
744: }
745:
746: sub forceid_change {
747: my ($context) = @_;
748: my $output =
749: "<h3>".&mt('ID/Student Number')."</h3>\n".
750: "<p>\n".'<label><input type="checkbox" name="forceid" value="yes">'.
751: &mt('Disable ID/Student Number Safeguard and Force Change '.
752: 'of Conflicting IDs').'</label><br />'."\n".
753: &mt('(only do if you know what you are doing.)')."</br><br />\n";
754: if ($context eq 'domain') {
755: $output .= '<label><input type="checkbox" name="recurseid"'.
756: ' value="yes">'.
757: &mt('Update ID/Student Number in courses in which user is an Active or Future student, (if forcing change).').
758: '</label></p>'."\n";
759: }
760: return $output;
761: }
762:
763: ###############################################################
764: ###############################################################
765: sub print_upload_manager_form {
766: my ($r,$context) = @_;
767: my $firstLine;
768: my $datatoken;
769: if (!$env{'form.datatoken'}) {
770: $datatoken=&Apache::loncommon::upfile_store($r);
771: } else {
772: $datatoken=$env{'form.datatoken'};
773: &Apache::loncommon::load_tmp_file($r);
774: }
775: my @records=&Apache::loncommon::upfile_record_sep();
776: if($env{'form.noFirstLine'}){
777: $firstLine=shift(@records);
778: }
779: my $total=$#records;
780: my $distotal=$total+1;
781: my $today=time;
782: my $halfyear=$today+15552000;
783: #
784: # Restore memorized settings
785: my $col_setting_names = { 'username_choice' => 'scalar', # column settings
786: 'names_choice' => 'scalar',
787: 'fname_choice' => 'scalar',
788: 'mname_choice' => 'scalar',
789: 'lname_choice' => 'scalar',
790: 'gen_choice' => 'scalar',
791: 'id_choice' => 'scalar',
792: 'sec_choice' => 'scalar',
793: 'ipwd_choice' => 'scalar',
794: 'email_choice' => 'scalar',
795: 'role_choice' => 'scalar',
796: };
797: my $defdom = $env{'request.role.domain'};
798: if ($context eq 'course') {
799: &Apache::loncommon::restore_course_settings('enrollment_upload',
800: $col_setting_names);
801: } else {
802: &Apache::loncommon::restore_settings($context,'user_upload',
803: $col_setting_names);
804: }
805: #
806: # Determine kerberos parameters as appropriate
807: my ($krbdef,$krbdefdom) =
808: &Apache::loncommon::get_kerberos_defaults($defdom);
809: #
810: &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context);
811: my $i;
812: my $keyfields;
813: if ($total>=0) {
814: my @field=
815: (['username',&mt('Username'), $env{'form.username_choice'}],
816: ['names',&mt('Last Name, First Names'),$env{'form.names_choice'}],
817: ['fname',&mt('First Name'), $env{'form.fname_choice'}],
818: ['mname',&mt('Middle Names/Initials'),$env{'form.mname_choice'}],
819: ['lname',&mt('Last Name'), $env{'form.lname_choice'}],
820: ['gen', &mt('Generation'), $env{'form.gen_choice'}],
821: ['id', &mt('ID/Student Number'),$env{'form.id_choice'}],
822: ['sec', &mt('Section'), $env{'form.sec_choice'}],
823: ['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
824: ['email',&mt('E-mail Address'), $env{'form.email_choice'}],
825: ['role',&mt('Role'), $env{'form.role_choice'}]);
826: if ($env{'form.upfile_associate'} eq 'reverse') {
827: &Apache::loncommon::csv_print_samples($r,\@records);
828: $i=&Apache::loncommon::csv_print_select_table($r,\@records,
829: \@field);
830: foreach (@field) {
831: $keyfields.=$_->[0].',';
832: }
833: chop($keyfields);
834: } else {
835: unshift(@field,['none','']);
836: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
837: \@field);
838: my %sone=&Apache::loncommon::record_sep($records[0]);
839: $keyfields=join(',',sort(keys(%sone)));
840: }
841: }
842: $r->print('</div>');
843: &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
844: $context);
845: }
846:
847: sub setup_date_selectors {
848: my ($starttime,$endtime,$mode) = @_;
849: if (! defined($starttime)) {
850: $starttime = time;
851: unless ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
852: if (exists($env{'course.'.$env{'request.course.id'}.
853: '.default_enrollment_start_date'})) {
854: $starttime = $env{'course.'.$env{'request.course.id'}.
855: '.default_enrollment_start_date'};
856: }
857: }
858: }
859: if (! defined($endtime)) {
860: $endtime = time+(6*30*24*60*60); # 6 months from now, approx
861: unless ($mode eq 'createcourse') {
862: if (exists($env{'course.'.$env{'request.course.id'}.
863: '.default_enrollment_end_date'})) {
864: $endtime = $env{'course.'.$env{'request.course.id'}.
865: '.default_enrollment_end_date'};
866: }
867: }
868: }
869: my $startdateform = &Apache::lonhtmlcommon::date_setter('studentform',
870: 'startdate',
871: $starttime);
872: my $enddateform = &Apache::lonhtmlcommon::date_setter('studentform',
873: 'enddate',
874: $endtime);
875: if ($mode eq 'create_enrolldates') {
876: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
877: 'startenroll',
878: $starttime);
879: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
880: 'endenroll',
881: $endtime);
882: }
883: if ($mode eq 'create_defaultdates') {
884: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
885: 'startaccess',
886: $starttime);
887: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
888: 'endaccess',
889: $endtime);
890: }
891: return ($startdateform,$enddateform);
892: }
893:
894:
895: sub get_dates_from_form {
896: my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
897: my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
898: if ($env{'form.no_end_date'}) {
899: $enddate = 0;
900: }
901: return ($startdate,$enddate);
902: }
903:
904: sub date_setting_table {
905: my ($starttime,$endtime,$mode) = @_;
906: my ($startform,$endform)=&setup_date_selectors($starttime,$endtime,$mode);
907: my $dateDefault;
908: if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
909: $dateDefault = ' ';
910: } elsif ($mode ne 'construction_space' && $mode ne 'domain') {
911: $dateDefault = '<nobr>'.
912: '<label><input type="checkbox" name="makedatesdefault" /> '.
913: &mt('make these dates the default for future enrollment').
914: '</label></nobr>';
915: }
916: my $perpetual = '<nobr><label><input type="checkbox" name="no_end_date"';
917: if (defined($endtime) && $endtime == 0) {
918: $perpetual .= ' checked';
919: }
920: $perpetual.= ' /> '.&mt('no ending date').'</label></nobr>';
921: if ($mode eq 'create_enrolldates') {
922: $perpetual = ' ';
923: }
924: my $result = &Apache::lonhtmlcommon::start_pick_box()."\n".
925: &Apache::lonhtmlcommon::row_title(&mt('Starting Date'),
926: 'LC_oddrow_value')."\n".
927: $startform."\n".
928: &Apache::lonhtmlcommon::row_closure(1).
929: &Apache::lonhtmlcommon::row_title(&mt('Ending Date'),
930: 'LC_oddrow_value')."\n".
931: $endform.' '.$perpetual.
932: &Apache::lonhtmlcommon::row_closure(1).
933: &Apache::lonhtmlcommon::end_pick_box().'<br />';
934: if ($dateDefault) {
935: $result .= $dateDefault.'<br />'."\n";
936: }
937: return $result;
938: }
939:
940: sub make_dates_default {
941: my ($startdate,$enddate,$context) = @_;
942: my $result = '';
943: if ($context eq 'course') {
944: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
945: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
946: my $put_result = &Apache::lonnet::put('environment',
947: {'default_enrollment_start_date'=>$startdate,
948: 'default_enrollment_end_date' =>$enddate},$dom,$crs);
949: if ($put_result eq 'ok') {
950: $result .= "Set default start and end dates for course<br />";
951: #
952: # Refresh the course environment
953: &Apache::lonnet::coursedescription($env{'request.course.id'},
954: {'freshen_cache' => 1});
955: } else {
956: $result .= &mt('Unable to set default dates for course').":".$put_result.
957: '<br />';
958: }
959: }
960: return $result;
961: }
962:
963: sub default_role_selector {
964: my ($context,$checkpriv) = @_;
965: my %customroles;
966: my ($options,$coursepick,$cb_jscript);
967: if ($context ne 'construction_space') {
968: %customroles = &my_custom_roles();
969: }
970:
971: my %lt=&Apache::lonlocal::texthash(
972: 'rol' => "Role",
973: 'grs' => "Section",
974: 'exs' => "Existing sections",
975: 'new' => "New section",
976: );
977: $options = '<select name="defaultrole">'."\n".
978: ' <option value="">'.&mt('Please select').'</option>'."\n";
979: if ($context eq 'course') {
980: $options .= &default_course_roles($context,$checkpriv,%customroles);
981: } elsif ($context eq 'construction_space') {
982: my @roles = &construction_space_roles($checkpriv);
983: foreach my $role (@roles) {
984: my $plrole=&Apache::lonnet::plaintext($role);
985: $options .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
986: }
987: } elsif ($context eq 'domain') {
988: my @roles = &domain_roles($checkpriv);
989: foreach my $role (@roles) {
990: my $plrole=&Apache::lonnet::plaintext($role);
991: $options .= ' <option value="'.$role.'">'.$plrole.'</option>';
992: }
993: my $courseform = &Apache::loncommon::selectcourse_link
994: ('studentform','defaultcourse','defaultdomain','defaultdesc',"$env{'request.role.domain'}",undef,'Course');
995: $cb_jscript =
996: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'defaultsec','studentform');
997: $coursepick = &Apache::loncommon::start_data_table().
998: &Apache::loncommon::start_data_table_header_row().
999: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th>'.
1000: '<th>'.$lt{'grs'}.'</th>'.
1001: &Apache::loncommon::end_data_table_header_row().
1002: &Apache::loncommon::start_data_table_row()."\n".
1003: '<td><input type="text" name="defaultdesc" value="" onFocus="this.blur();opencrsbrowser('."'studentform','defcourse','defdomain','coursedesc',''".')" /></td>'."\n".
1004: '<td><select name="courserole">'."\n".
1005: &default_course_roles($context,$checkpriv,%customroles)."\n".
1006: '</select></td><td>'.
1007: '<table class="LC_createuser">'.
1008: '<tr class="LC_section_row"><td valign"top">'.
1009: $lt{'exs'}.'<br /><select name="defaultsec">'.
1010: ' <option value=""><--'.&mt('Pick course first').
1011: '</select></td>'.
1012: '<td> </td>'.
1013: '<td valign="top">'.$lt{'new'}.'<br />'.
1014: '<input type="text" name="newsec" value="" size="5" />'.
1015: '<input type="hidden" name="groups" value="" /></td>'.
1016: '</tr></table></td>'.
1017: &Apache::loncommon::end_data_table_row().
1018: &Apache::loncommon::end_data_table()."\n".
1019: '<input type="hidden" name="defaultcourse" value="" />'.
1020: '<input type="hidden" name="defaultdomain" value="" />';
1021: }
1022: $options .= '</select>';
1023: return ($options,$cb_jscript,$coursepick);
1024: }
1025:
1026: sub default_course_roles {
1027: my ($context,$checkpriv,%customroles) = @_;
1028: my $output;
1029: my @roles = &course_roles($context,$checkpriv);
1030: foreach my $role (@roles) {
1031: my $plrole=&Apache::lonnet::plaintext($role);
1032: $output .= ' <option value="'.$role.'">'.$plrole.'</option>';
1033: }
1034: if (keys(%customroles) > 0) {
1035: my %customroles = &my_custom_roles();
1036: foreach my $cust (sort(keys(%customroles))) {
1037: my $custrole='cr_cr_'.$env{'user.domain'}.
1038: '_'.$env{'user.name'}.'_'.$cust;
1039: $output .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1040: }
1041: }
1042: return $output;
1043: }
1044:
1045: sub construction_space_roles {
1046: my ($checkpriv) = @_;
1047: my @allroles = ('ca','aa');
1048: my @roles;
1049: if ($checkpriv) {
1050: foreach my $role (@allroles) {
1051: if (&Apache::lonnet::allowed('c'.$role,$env{'user.domain'}.'/'.$env{'user.name'})) {
1052: push(@roles,$role);
1053: }
1054: }
1055: return @roles;
1056: } else {
1057: return @allroles;
1058: }
1059: }
1060:
1061: sub domain_roles {
1062: my ($checkpriv) = @_;
1063: my @allroles = ('dc','li','dg','au','sc');
1064: my @roles;
1065: if ($checkpriv) {
1066: foreach my $role (@allroles) {
1067: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
1068: push(@roles,$role);
1069: }
1070: }
1071: return @roles;
1072: } else {
1073: return @allroles;
1074: }
1075: }
1076:
1077: sub course_roles {
1078: my ($context,$checkpriv) = @_;
1079: my @allroles = ('st','ta','ep','in','cc');
1080: my @roles;
1081: if ($context eq 'domain') {
1082: @roles = @allroles;
1083: } elsif ($context eq 'course') {
1084: if ($env{'request.course.id'}) {
1085: if ($checkpriv) {
1086: foreach my $role (@allroles) {
1087: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
1088: push(@roles,$role);
1089: } else {
1090: if ($role ne 'cc' && $env{'request.course.section'} ne '') {
1091: if (!&Apache::lonnet::allowed('c'.$role,
1092: $env{'request.course.id'}.'/'.
1093: $env{'request.course.section'})) {
1094: push(@roles,$role);
1095: }
1096: }
1097: }
1098: }
1099: } else {
1100: @roles = @allroles;
1101: }
1102: }
1103: }
1104: return @roles;
1105: }
1106:
1107: sub curr_role_permissions {
1108: my ($context,$setting,$checkpriv) = @_;
1109: my @roles;
1110: if ($context eq 'construction_space') {
1111: @roles = &construction_space_roles($checkpriv);
1112: } elsif ($context eq 'domain') {
1113: if ($setting eq 'course') {
1114: @roles = &course_roles($context,$checkpriv);
1115: } else {
1116: @roles = &domain_roles($checkpriv);
1117: }
1118: } elsif ($context eq 'course') {
1119: @roles = &course_roles($context,$checkpriv);
1120: }
1121: return @roles;
1122: }
1123:
1124: # ======================================================= Existing Custom Roles
1125:
1126: sub my_custom_roles {
1127: my %returnhash=();
1128: my %rolehash=&Apache::lonnet::dump('roles');
1129: foreach my $key (keys %rolehash) {
1130: if ($key=~/^rolesdef\_(\w+)$/) {
1131: $returnhash{$1}=$1;
1132: }
1133: }
1134: return %returnhash;
1135: }
1136:
1137: sub print_userlist {
1138: my ($r,$mode,$permission,$context,$formname,$totcodes,$codetitles,
1139: $idlist,$idlist_titles) = @_;
1140: my $format = $env{'form.output'};
1141: if (! exists($env{'form.sortby'})) {
1142: $env{'form.sortby'} = 'username';
1143: }
1144: if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
1145: $env{'form.Status'} = 'Active';
1146: }
1147: my $status_select = &Apache::lonhtmlcommon::StatusOptions
1148: ($env{'form.Status'});
1149:
1150: if ($env{'form.showrole'} eq '') {
1151: $env{'form.showrole'} = 'Any';
1152: }
1153: if (! defined($env{'form.output'}) ||
1154: $env{'form.output'} !~ /^(csv|excel|html)$/ ) {
1155: $env{'form.output'} = 'html';
1156: }
1157:
1158: my @statuses;
1159: if ($env{'form.Status'} eq 'Any') {
1160: @statuses = ('previous','active','future');
1161: } elsif ($env{'form.Status'} eq 'Expired') {
1162: @statuses = ('previous');
1163: } elsif ($env{'form.Status'} eq 'Active') {
1164: @statuses = ('active');
1165: } elsif ($env{'form.Status'} eq 'Future') {
1166: @statuses = ('future');
1167: }
1168:
1169: # if ($context eq 'course') {
1170: # $r->print(&display_adv_courseroles());
1171: # }
1172: #
1173: # Interface output
1174: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
1175: '<input type="hidden" name="action" value="'.
1176: $env{'form.action'}.'" />');
1177: $r->print("<p>\n");
1178: if ($env{'form.action'} ne 'modifystudent') {
1179: my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
1180: 'excel' => "Excel",
1181: 'html' => 'HTML');
1182: my $output_selector = '<select size="1" name="output" >';
1183: foreach my $outputformat ('html','csv','excel') {
1184: my $option = '<option value="'.$outputformat.'" ';
1185: if ($outputformat eq $env{'form.output'}) {
1186: $option .= 'selected ';
1187: }
1188: $option .='>'.$lt{$outputformat}.'</option>';
1189: $output_selector .= "\n".$option;
1190: }
1191: $output_selector .= '</select>';
1192: $r->print('<label>'.&mt('Output Format: [_1]',$output_selector).'</label>'.(' 'x3));
1193: }
1194: $r->print('<label>'.&mt('User Status: [_1]',$status_select).'</label>'.(' 'x3)."\n");
1195: my $roleselected = '';
1196: if ($env{'form.showrole'} eq 'Any') {
1197: $roleselected = ' selected="selected" ';
1198: }
1199: my $role_select;
1200: if ($context eq 'domain') {
1201: $role_select = &domain_roles_select();
1202: $r->print('<label>'.&mt('Role Type: [_1]',$role_select).'</label>');
1203: } else {
1204: $role_select = '<select name="showrole">'."\n".
1205: '<option value="Any" '.$roleselected.'>'.
1206: &mt('Any role').'</option>';
1207: my @poss_roles = &curr_role_permissions($context);
1208: foreach my $role (@poss_roles) {
1209: $roleselected = '';
1210: if ($role eq $env{'form.showrole'}) {
1211: $roleselected = ' selected="selected" ';
1212: }
1213: my $plrole=&Apache::lonnet::plaintext($role);
1214: $role_select .= '<option value="'.$role.'"'.$roleselected.'>'.$plrole.'</option>';
1215: }
1216: $roleselected = '';
1217: if ($env{'form.showrole'} eq 'cr') {
1218: $roleselected = ' selected="selected" ';
1219: }
1220: $role_select .= '<option value="cr"'.$roleselected.'>'.&mt('Custom role').'</option>'.
1221: '</select>';
1222: $r->print('<label>'.&mt('Role: [_1]',$role_select).'</label>');
1223: }
1224: if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) {
1225: $r->print(&list_submit_button(&mt('Update Display'))."\n</p>\n");
1226: }
1227: my ($indexhash,$keylist) = &make_keylist_array();
1228: my (%userlist,%userinfo);
1229: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
1230: my $courseform =
1231: &Apache::lonhtmlcommon::course_selection($formname,$totcodes,
1232: $codetitles,$idlist,$idlist_titles);
1233: $r->print('<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n".
1234: &Apache::lonhtmlcommon::start_pick_box()."\n".
1235: &Apache::lonhtmlcommon::row_title(&mt('Select Course(s)'),
1236: 'LC_oddrow_value')."\n".
1237: $courseform."\n".
1238: &Apache::lonhtmlcommon::row_closure(1).
1239: &Apache::lonhtmlcommon::end_pick_box().'</p>'.
1240: '<p>'.&list_submit_button(&mt('Update Display')).
1241: "\n</p>\n");
1242: }
1243: $r->print('<hr />'.&mt('Searching').' ...<br /> <br />');
1244: $r->rflush();
1245: if ($context eq 'course') {
1246: my $classlist = &Apache::loncoursedata::get_classlist();
1247: my $secidx = &Apache::loncoursedata::CL_SECTION();
1248: foreach my $student (keys(%{$classlist})) {
1249: if (exists($permission->{'view_section'})) {
1250: if ($classlist->{$student}[$secidx] ne $permission->{'view_section'}) {
1251: next;
1252: } else {
1253: $userlist{$student} = $classlist->{$student};
1254: }
1255: } else {
1256: $userlist{$student} = $classlist->{$student};
1257: }
1258: }
1259: my $cid =$env{'request.course.id'};
1260: my $cdom=$env{'course.'.$cid.'.domain'};
1261: my $cnum=$env{'course.'.$cid.'.num'};
1262: my $showroles;
1263: if ($env{'form.showrole'} ne 'Any') {
1264: $showroles = [$env{'form.showrole'}];
1265: } else {
1266: $showroles = undef;
1267: }
1268: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
1269: \@statuses,$showroles);
1270: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
1271: \%advrolehash);
1272: } else {
1273: my (%cstr_roles,%dom_roles);
1274: if ($context eq 'construction_space') {
1275: # List co-authors and assistant co-authors
1276: my @possroles = ('ca','aa');
1277: %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
1278: \@statuses,\@possroles);
1279: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
1280: \%cstr_roles);
1281: } elsif ($context eq 'domain') {
1282: if ($env{'form.roletype'} eq 'domain') {
1283: %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'});
1284: foreach my $key (keys(%dom_roles)) {
1285: if (ref($dom_roles{$key}) eq 'HASH') {
1286: &gather_userinfo($context,$format,\%userlist,$indexhash,
1287: \%userinfo,$dom_roles{$key});
1288: }
1289: }
1290: } elsif ($env{'form.roletype'} eq 'construction_space') {
1291: my %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'},['au']);
1292: my %coauthors;
1293: foreach my $key (keys(%dom_roles)) {
1294: if (ref($dom_roles{$key}) eq 'HASH') {
1295: if ($env{'form.showrole'} eq 'au') {
1296: &gather_userinfo($context,$format,\%userlist,$indexhash,
1297: \%userinfo,$dom_roles{$key});
1298: } else {
1299: my @possroles;
1300: if ($env{'form.showrole'} eq 'Any') {
1301: @possroles = ('ca','aa');
1302: } else {
1303: @possroles = ($env{'form.showrole'});
1304: }
1305: foreach my $author (sort(keys(%{$dom_roles{$key}}))) {
1306: my ($role,$authorname,$authordom) = split(/:/,$author);
1307: my $extent = '/'.$authordom.'/'.$authorname;
1308: %{$coauthors{$extent}} =
1309: &Apache::lonnet::get_my_roles($authorname,
1310: $authordom,undef,\@statuses,\@possroles);
1311: }
1312: &gather_userinfo($context,$format,\%userlist,
1313: $indexhash,\%userinfo,\%coauthors);
1314: }
1315: }
1316: }
1317: } elsif ($env{'form.roletype'} eq 'course') {
1318: if ($env{'form.coursepick'}) {
1319: my %courses = &process_coursepick();
1320: my %allusers;
1321: foreach my $cid (keys(%courses)) {
1322: my %coursehash =
1323: &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1324: my $cdom = $coursehash{'domain'};
1325: my $cnum = $coursehash{'num'};
1326: my $cdesc = $coursehash{'description'};
1327: my (@roles,@sections,%access,%users,%userdata,
1328: %users,%statushash);
1329: if ($env{'form.showrole'} eq 'Any') {
1330: @roles = &course_roles($context);
1331: unshift(@roles,'cr');
1332: } else {
1333: @roles = ($env{'form.showrole'});
1334: }
1335: foreach my $role (@roles) {
1336: %{$users{$role}} = ();
1337: }
1338: foreach my $type (@statuses) {
1339: $access{$type} = $type;
1340: }
1341: &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash);
1342: foreach my $user (keys(%userdata)) {
1343: next if (ref($userinfo{$user}) eq 'HASH');
1344: foreach my $item ('fullname','id') {
1345: $userinfo{$user}{$item} = $userdata{$user}[$indexhash->{$item}];
1346: }
1347: }
1348: foreach my $role (keys(%users)) {
1349: foreach my $user (keys(%{$users{$role}})) {
1350: my $uniqid = $user.':'.$role;
1351: $allusers{$uniqid}{$cid} = { desc => $cdesc,
1352: secs => $statushash{$user}{$role},
1353: };
1354: }
1355: }
1356: }
1357: &gather_userinfo($context,$format,\%userlist,$indexhash,
1358: \%userinfo,\%allusers);
1359: } else {
1360: return;
1361: }
1362: }
1363: }
1364: }
1365: if (keys(%userlist) == 0) {
1366: if ($context eq 'construction_space') {
1367: $r->print(&mt('There are no co-authors to display.')."\n");
1368: } elsif ($context eq 'domain') {
1369: if ($env{'form.roletype'} eq 'domain') {
1370: $r->print(&mt('There are no users with domain roles to display.')."\n");
1371: } elsif ($env{'form.roletype'} eq 'construction_space') {
1372: $r->print(&mt('There are no authors or co-authors to display.')."\n");
1373: } elsif ($env{'form.roletype'} eq 'course') {
1374: $r->print(&mt('There are no course users to display')."\n");
1375: }
1376: } elsif ($context eq 'course') {
1377: $r->print(&mt('There are no course users to display.')."\n");
1378: }
1379: } else {
1380: # Print out the available choices
1381: my $usercount;
1382: if ($env{'form.action'} eq 'modifystudent') {
1383: ($usercount) = &show_users_list($r,$context,'view','modify',
1384: $env{'form.Status'},\%userlist,$keylist);
1385: } else {
1386: ($usercount) = &show_users_list($r,$context,$env{'form.output'},
1387: 'aboutme',$env{'form.Status'},\%userlist,$keylist);
1388: }
1389: if (!$usercount) {
1390: $r->print('<br />'.&mt('There are no users matching the search criteria.'));
1391: }
1392: }
1393: $r->print('</form>');
1394: }
1395:
1396: sub list_submit_button {
1397: my ($text) = @_;
1398: return '<input type="submit" value="'.$text.'" />';
1399: }
1400:
1401: sub gather_userinfo {
1402: my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash) = @_;
1403: foreach my $item (keys(%{$rolehash})) {
1404: @{$userlist->{$item}} = ();
1405: my %userdata;
1406: if ($context eq 'construction_space' || $context eq 'course') {
1407: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
1408: split(/:/,$item);
1409: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
1410: &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
1411: } elsif ($context eq 'domain') {
1412: if ($env{'form.roletype'} eq 'domain') {
1413: ($userdata{'role'},$userdata{'username'},$userdata{'domain'}) =
1414: split(/:/,$item);
1415: ($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
1416: &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
1417: } elsif ($env{'form.roletype'} eq 'construction_space') {
1418: if (ref($rolehash->{$item}) eq 'HASH') {
1419: $userdata{'extent'} = $item;
1420: foreach my $key (keys(%{$rolehash->{$item}})) {
1421: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) = split(/:/,$key);
1422: ($userdata{'start'},$userdata{'end'}) =
1423: split(/:/,$rolehash->{$item}{$key});
1424: my $uniqid = $key.':'.$item;
1425: &build_user_record(\%userdata,$userinfo,$indexhash,$uniqid,$userlist);
1426: }
1427: }
1428: } elsif ($env{'form.roletype'} eq 'course') {
1429: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
1430: split(/:/,$item);
1431: if (ref($rolehash->{$item}) eq 'HASH') {
1432: foreach my $cid (sort(keys(%{$rolehash->{$item}}))) {
1433: if (ref($rolehash->{$item}{$cid}) eq 'HASH') {
1434: my $spanstart = '';
1435: my $spanend = '; ';
1436: my $space = ', ';
1437: if ($format eq 'html' || $format eq 'view') {
1438: $spanstart = '<span class="LC_nobreak">';
1439: $spanend = '</span><br />';
1440: $space = ', ';
1441: }
1442: $userdata{'extent'} .= $spanstart.
1443: $rolehash->{$item}{$cid}{'desc'}.$space;
1444: if (ref($rolehash->{$item}{$cid}{'secs'}) eq 'HASH') {
1445: foreach my $sec (sort(keys(%{$rolehash->{$item}{$cid}{'secs'}}))) {
1446: $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
1447: }
1448: }
1449: }
1450: }
1451: }
1452: &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
1453: }
1454: }
1455: }
1456: return;
1457: }
1458:
1459: sub build_user_record {
1460: my ($userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
1461: &process_date_info($userdata);
1462: my $username = $userdata->{'username'};
1463: my $domain = $userdata->{'domain'};
1464: if (ref($userinfo->{$username.':'.$domain}) eq 'HASH') {
1465: $userdata->{'fullname'} =
1466: $userinfo->{$username.':'.$domain}{'fullname'};
1467: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
1468: } else {
1469: &aggregate_user_info($domain,$username,$userinfo);
1470: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
1471: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
1472: }
1473: foreach my $key (keys(%{$indexhash})) {
1474: if (defined($userdata->{$key})) {
1475: $userlist->{$record_key}[$indexhash->{$key}] = $userdata->{$key};
1476: }
1477: }
1478: return;
1479: }
1480:
1481: sub courses_selector {
1482: my ($cdom,$formname) = @_;
1483: my %coursecodes = ();
1484: my %codes = ();
1485: my @codetitles = ();
1486: my %cat_titles = ();
1487: my %cat_order = ();
1488: my %idlist = ();
1489: my %idnums = ();
1490: my %idlist_titles = ();
1491: my $caller = 'global';
1492: my $totcodes = 0;
1493: my $format_reply;
1494: my $jscript = '';
1495:
1496: my $totcodes =
1497: &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,
1498: $cdom,$totcodes);
1499: if ($totcodes > 0) {
1500: $format_reply =
1501: &Apache::lonnet::auto_instcode_format($caller,$cdom,\%coursecodes,
1502: \%codes,\@codetitles,\%cat_titles,\%cat_order);
1503: if ($format_reply eq 'ok') {
1504: my $numtypes = @codetitles;
1505: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
1506: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
1507: my $longtitles_str = join('","',@{$longtitles});
1508: my $allidlist = $idlist{$codetitles[0]};
1509: $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
1510: $jscript .= $scripttext;
1511: $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,@codetitles);
1512: }
1513: }
1514: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
1515:
1516: my %elements = (
1517: Year => 'selectbox',
1518: coursepick => 'radio',
1519: coursetotal => 'text',
1520: courselist => 'text',
1521: );
1522: $jscript .= &Apache::lonhtmlcommon::set_form_elements(\%elements);
1523: if ($env{'form.coursepick'} eq 'category') {
1524: $jscript .= qq|
1525: function setCourseCat(formname) {
1526: if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
1527: return;
1528: }
1529: courseSet('Year');
1530: for (var j=0; j<formname.Semester.length; j++) {
1531: if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
1532: formname.Semester.options[j].selected = true;
1533: }
1534: }
1535: if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
1536: return;
1537: }
1538: courseSet('Semester');
1539: for (var j=0; j<formname.Department.length; j++) {
1540: if (formname.Department.options[j].value == "$env{'form.Department'}") { formname.Department.options[j].selected = true;
1541: }
1542: }
1543: if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
1544: return;
1545: }
1546: courseSet('Department');
1547: for (var j=0; j<formname.Number.length; j++) {
1548: if (formname.Number.options[j].value == "$env{'form.Number'}") {
1549: formname.Number.options[j].selected = true;
1550: }
1551: }
1552: }
1553: |;
1554: }
1555: return ($cb_jscript,$jscript,$totcodes,\@codetitles,\%idlist,
1556: \%idlist_titles);
1557: }
1558:
1559: sub course_selector_loadcode {
1560: my ($formname) = @_;
1561: my $loadcode;
1562: if ($env{'form.coursepick'} ne '') {
1563: $loadcode = 'javascript:setFormElements(document.'.$formname.')';
1564: if ($env{'form.coursepick'} eq 'category') {
1565: $loadcode .= ';javascript:setCourseCat(document.'.$formname.')';
1566: }
1567: }
1568: return $loadcode;
1569: }
1570:
1571: sub process_coursepick {
1572: my $coursefilter = $env{'form.coursepick'};
1573: my $cdom = $env{'request.role.domain'};
1574: my %courses;
1575: if ($coursefilter eq 'all') {
1576: %courses = &Apache::lonnet::courseiddump($cdom,'.','.','.','.','.',
1577: undef,undef,'Course');
1578: } elsif ($coursefilter eq 'category') {
1579: my $instcode = &instcode_from_coursefilter();
1580: %courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.',
1581: undef,undef,'Course');
1582: } elsif ($coursefilter eq 'specific') {
1583: if ($env{'form.coursetotal'} > 1) {
1584: my @course_ids = split(/&&/,$env{'form.courselist'});
1585: foreach my $cid (@course_ids) {
1586: $courses{$cid} = '';
1587: }
1588: } else {
1589: $courses{$env{'form.courselist'}} = '';
1590: }
1591: }
1592: return %courses;
1593: }
1594:
1595: sub instcode_from_coursefilter {
1596: my $instcode = '';
1597: my @cats = ('Semester','Year','Department','Number');
1598: foreach my $category (@cats) {
1599: if (defined($env{'form.'.$category})) {
1600: unless ($env{'form.'.$category} eq '-1') {
1601: $instcode .= $env{'form.'.$category};
1602: }
1603: }
1604: }
1605: if ($instcode eq '') {
1606: $instcode = '.';
1607: }
1608: return $instcode;
1609: }
1610:
1611: sub display_adv_courseroles {
1612: my $output;
1613: #
1614: # List course personnel
1615: my %coursepersonnel =
1616: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'});
1617: #
1618: $output = '<br />'.&Apache::loncommon::start_data_table();
1619: foreach my $role (sort(keys(%coursepersonnel))) {
1620: next if ($role =~ /^\s*$/);
1621: $output .= &Apache::loncommon::start_data_table_row().
1622: '<td>'.$role.'</td><td>';
1623: foreach my $user (split(',',$coursepersonnel{$role})) {
1624: my ($puname,$pudom)=split(':',$user);
1625: $output .= ' '.&Apache::loncommon::aboutmewrapper(
1626: &Apache::loncommon::plainname($puname,$pudom),
1627: $puname,$pudom);
1628: }
1629: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
1630: }
1631: $output .= &Apache::loncommon::end_data_table();
1632: }
1633:
1634: sub make_keylist_array {
1635: my ($index,$keylist);
1636: $index->{'domain'} = &Apache::loncoursedata::CL_SDOM();
1637: $index->{'username'} = &Apache::loncoursedata::CL_SNAME();
1638: $index->{'end'} = &Apache::loncoursedata::CL_END();
1639: $index->{'start'} = &Apache::loncoursedata::CL_START();
1640: $index->{'id'} = &Apache::loncoursedata::CL_ID();
1641: $index->{'section'} = &Apache::loncoursedata::CL_SECTION();
1642: $index->{'fullname'} = &Apache::loncoursedata::CL_FULLNAME();
1643: $index->{'status'} = &Apache::loncoursedata::CL_STATUS();
1644: $index->{'type'} = &Apache::loncoursedata::CL_TYPE();
1645: $index->{'lockedtype'} = &Apache::loncoursedata::CL_LOCKEDTYPE();
1646: $index->{'groups'} = &Apache::loncoursedata::CL_GROUP();
1647: $index->{'email'} = &Apache::loncoursedata::CL_PERMANENTEMAIL();
1648: $index->{'role'} = &Apache::loncoursedata::CL_ROLE();
1649: $index->{'extent'} = &Apache::loncoursedata::CL_EXTENT();
1650: foreach my $key (keys(%{$index})) {
1651: $keylist->[$index->{$key}] = $key;
1652: }
1653: return ($index,$keylist);
1654: }
1655:
1656: sub aggregate_user_info {
1657: my ($udom,$uname,$userinfo) = @_;
1658: my %info=&Apache::lonnet::get('environment',
1659: ['firstname','middlename',
1660: 'lastname','generation','id'],
1661: $udom,$uname);
1662: my ($tmp) = keys(%info);
1663: my ($fullname,$id);
1664: if ($tmp =~/^(con_lost|error|no_such_host)/i) {
1665: $fullname = 'not available';
1666: $id = 'not available';
1667: &Apache::lonnet::logthis('unable to retrieve environment '.
1668: 'for '.$uname.':'.$udom);
1669: } else {
1670: $fullname = &Apache::lonnet::format_name(@info{qw/firstname middlename lastname generation/},'lastname');
1671: $id = $info{'id'};
1672: }
1673: $userinfo->{$uname.':'.$udom} = {
1674: fullname => $fullname,
1675: id => $id,
1676: };
1677: return;
1678: }
1679:
1680: sub process_date_info {
1681: my ($userdata) = @_;
1682: my $now = time;
1683: $userdata->{'status'} = 'Active';
1684: if ($userdata->{'start'} > 0) {
1685: if ($now < $userdata->{'start'}) {
1686: $userdata->{'status'} = 'Future';
1687: }
1688: }
1689: if ($userdata->{'end'} > 0) {
1690: if ($now > $userdata->{'end'}) {
1691: $userdata->{'status'} = 'Expired';
1692: }
1693: }
1694: return;
1695: }
1696:
1697: sub show_users_list {
1698: my ($r,$context,$mode,$linkto,$statusmode,$userlist,$keylist)=@_;
1699: #
1700: # Variables for excel output
1701: my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
1702: #
1703: # Variables for csv output
1704: my ($CSVfile,$CSVfilename);
1705: #
1706: my $sortby = $env{'form.sortby'};
1707: my @sortable = ('username','domain','id','fullname','start','end','email','role');
1708: if ($context eq 'course') {
1709: push(@sortable,('section','groups','type'));
1710: } else {
1711: push(@sortable,'extent');
1712: }
1713: if (!grep(/^\Q$sortby\E$/,@sortable)) {
1714: $sortby = 'username';
1715: }
1716: my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers);
1717: if ($context eq 'course') {
1718: $cid=$env{'request.course.id'};
1719: $cdom = $env{'course.'.$cid.'.domain'};
1720: $cnum = $env{'course.'.$cid.'.num'};
1721: ($classgroups) = &Apache::loncoursedata::get_group_memberships(
1722: $userlist,$keylist,$cdom,$cnum);
1723: if (! exists($env{'form.displayphotos'})) {
1724: $env{'form.displayphotos'} = 'off';
1725: }
1726: $displayphotos = $env{'form.displayphotos'};
1727: if (! exists($env{'form.displayclickers'})) {
1728: $env{'form.displayclickers'} = 'off';
1729: }
1730: $displayclickers = $env{'form.displayclickers'};
1731: if ($env{'course.'.$cid.'.internal.showphoto'}) {
1732: $r->print('
1733: <script type="text/javascript">
1734: function photowindow(photolink) {
1735: var title = "Photo_Viewer";
1736: var options = "scrollbars=1,resizable=1,menubar=0";
1737: options += ",width=240,height=240";
1738: stdeditbrowser = open(photolink,title,options,"1");
1739: stdeditbrowser.focus();
1740: }
1741: </script>
1742: ');
1743: }
1744: $r->print(<<END);
1745: <input type="hidden" name="displayphotos" value="$displayphotos" />
1746: <input type="hidden" name="displayclickers" value="$displayclickers" />
1747: END
1748: }
1749: unless ($mode eq 'autoenroll') {
1750: $r->print(<<END);
1751: <input type="hidden" name="state" value="$env{'form.state'}" />
1752: END
1753: }
1754: $r->print(<<END);
1755: <input type="hidden" name="sortby" value="$sortby" />
1756: END
1757:
1758: my %lt=&Apache::lonlocal::texthash(
1759: 'username' => "username",
1760: 'domain' => "domain",
1761: 'id' => 'ID',
1762: 'fullname' => "name",
1763: 'section' => "section",
1764: 'groups' => "active groups",
1765: 'start' => "start date",
1766: 'end' => "end date",
1767: 'status' => "status",
1768: 'role' => "role",
1769: 'type' => "enroll type/action",
1770: 'email' => "email address",
1771: 'clicker' => "clicker id",
1772: 'photo' => "photo",
1773: 'extent' => "extent",
1774: );
1775: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
1776: $lt{'extent'} = &mt('Course(s): description, section(s), status');
1777: } elsif ($context eq 'construction_space') {
1778: $lt{'extent'} = &mt('Author');
1779: }
1780: my @cols = ('username','domain','id','fullname');
1781: if ($context eq 'course') {
1782: push(@cols,'section');
1783: }
1784: if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) {
1785: push(@cols,('start','end'));
1786: }
1787: if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
1788: push(@cols,'role');
1789: }
1790: if ($context eq 'domain' && ($env{'form.roletype'} eq 'construction_space' ||
1791: $env{'form.roletype'} eq 'course')) {
1792: push (@cols,'extent');
1793: }
1794: if (($statusmode eq 'Any') &&
1795: (!($context eq 'domain' && $env{'form.roletype'} eq 'course'))) {
1796: push(@cols,'status');
1797: }
1798: if ($context eq 'course') {
1799: push(@cols,'groups');
1800: }
1801: push(@cols,'email');
1802:
1803: my $rolefilter = $env{'form.showrole'};
1804: if ($env{'form.showrole'} eq 'cr') {
1805: $rolefilter = &mt('custom');
1806: } elsif ($env{'form.showrole'} ne 'Any') {
1807: $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'});
1808: }
1809: my $results_description = &results_header_row($rolefilter,$statusmode,
1810: $context);
1811: $r->print('<b>'.$results_description.'</b><br />');
1812: my $output;
1813: if ($mode eq 'html' || $mode eq 'view') {
1814: $r->print(<<END);
1815: <input type="hidden" name="sname" value="" />
1816: <input type="hidden" name="sdom" value="" />
1817: END
1818: if ($linkto eq 'aboutme') {
1819: $output = &mt("Select a user name to view the user's personal page.");
1820: } elsif ($linkto eq 'modify') {
1821: $output = &mt("Select a user name to modify the user's information");
1822: }
1823: $output .= "\n<p>\n".
1824: &Apache::loncommon::start_data_table().
1825: &Apache::loncommon::start_data_table_header_row();
1826: if ($mode eq 'autoenroll') {
1827: $output .= "
1828: <th><a href=\"javascript:document.studentform.sortby.value='type';document.studentform.submit();\">$lt{'type'}</a></th>
1829: ";
1830: } else {
1831: $output .= "
1832: <th>Count</th>
1833: ";
1834: }
1835: foreach my $item (@cols) {
1836: $output .= "<th><a href=\"javascript:document.studentform.sortby.value='$item';document.studentform.submit();\">$lt{$item}</a></th>\n";
1837: }
1838: my %role_types = &role_type_names();
1839: if ($context eq 'course') {
1840: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
1841: # Clicker display on or off?
1842: my %clicker_options = &Apache::lonlocal::texthash(
1843: 'on' => 'Show',
1844: 'off' => 'Hide',
1845: );
1846: my $clickerchg = 'on';
1847: if ($displayclickers eq 'on') {
1848: $clickerchg = 'off';
1849: }
1850: $output .= ' <th>'."\n".' '.
1851: '<a href="javascript:document.studentform.displayclickers.value='.
1852: "'".$clickerchg."'".';document.studentform.submit();">'.
1853: $clicker_options{$clickerchg}.'</a> '.$lt{'clicker'}."\n".
1854: ' </th>'."\n";
1855:
1856: # Photo display on or off?
1857: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
1858: my %photo_options = &Apache::lonlocal::texthash(
1859: 'on' => 'Show',
1860: 'off' => 'Hide',
1861: );
1862: my $photochg = 'on';
1863: if ($displayphotos eq 'on') {
1864: $photochg = 'off';
1865: }
1866: $output .= ' <th>'."\n".' '.
1867: '<a href="javascript:document.studentform.displayphotos.value='.
1868: "'".$photochg."'".';document.studentform.submit();">'.
1869: $photo_options{$photochg}.'</a> '.$lt{'photo'}."\n".
1870: ' </th>'."\n";
1871: }
1872: }
1873: $output .= &Apache::loncommon::end_data_table_header_row();
1874: }
1875: # Done with the HTML header line
1876: } elsif ($mode eq 'csv') {
1877: #
1878: # Open a file
1879: $CSVfilename = '/prtspool/'.
1880: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1881: time.'_'.rand(1000000000).'.csv';
1882: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
1883: $r->log_error("Couldn't open $CSVfilename for output $!");
1884: $r->print("Problems occured in writing the csv file. ".
1885: "This error has been logged. ".
1886: "Please alert your LON-CAPA administrator.");
1887: $CSVfile = undef;
1888: }
1889: #
1890: # Write headers and data to file
1891: print $CSVfile '"'.$results_description.'"'."\n";
1892: print $CSVfile '"'.join('","',map {
1893: &Apache::loncommon::csv_translate($lt{$_})
1894: } (@cols)).'"'."\n";
1895: } elsif ($mode eq 'excel') {
1896: # Create the excel spreadsheet
1897: ($excel_workbook,$excel_filename,$format) =
1898: &Apache::loncommon::create_workbook($r);
1899: return if (! defined($excel_workbook));
1900: $excel_sheet = $excel_workbook->addworksheet('userlist');
1901: $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
1902: #
1903: my @colnames = map {$lt{$_}} (@cols);
1904: $excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
1905: }
1906:
1907: # Done with header lines in all formats
1908:
1909: my %index;
1910: my $i;
1911: foreach my $idx (@$keylist) {
1912: $index{$idx} = $i++;
1913: }
1914: my $usercount = 0;
1915: # Get groups, role, permanent e-mail so we can sort on them if
1916: # necessary.
1917: foreach my $user (keys(%{$userlist})) {
1918: my ($uname,$udom,$role,$groups,$email);
1919: if (($statusmode ne 'Any') &&
1920: ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
1921: delete($userlist->{$user});
1922: next;
1923: }
1924: if ($context eq 'domain') {
1925: if ($env{'form.roletype'} eq 'domain') {
1926: ($role,$uname,$udom) = split(/:/,$user);
1927:
1928: } elsif ($env{'form.roletype'} eq 'construction_space') {
1929: ($uname,$udom,$role) = split(/:/,$user,-1);
1930: } elsif ($env{'form.roletype'} eq 'course') {
1931: ($uname,$udom,$role) = split(/:/,$user);
1932: }
1933: } else {
1934: ($uname,$udom,$role) = split(/:/,$user,-1);
1935: if (($context eq 'course') && $role eq '') {
1936: $role = 'st';
1937: }
1938: }
1939: $userlist->{$user}->[$index{'role'}] = $role;
1940: if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
1941: delete($userlist->{$user});
1942: next;
1943: }
1944: if (ref($classgroups) eq 'HASH') {
1945: $groups = $classgroups->{$user};
1946: }
1947: if (ref($groups->{active}) eq 'HASH') {
1948: $userlist->{$user}->[$index{'groups'}] = join(', ',keys(%{$groups->{'active'}}));
1949: }
1950: my %emails = &Apache::loncommon::getemails($uname,$udom);
1951: if ($emails{'permanentemail'} =~ /\S/) {
1952: $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
1953: }
1954: $usercount ++;
1955: }
1956: my $autocount = 0;
1957: my $manualcount = 0;
1958: my $lockcount = 0;
1959: my $unlockcount = 0;
1960: if ($usercount) {
1961: $r->print($output);
1962: } else {
1963: if ($mode eq 'autoenroll') {
1964: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
1965: } else {
1966: return;
1967: }
1968: }
1969: #
1970: # Sort the users
1971: my $index = $index{$sortby};
1972: my $second = $index{'username'};
1973: my $third = $index{'domain'};
1974: my @sorted_users = sort {
1975: lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index])
1976: ||
1977: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
1978: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
1979: } (keys(%$userlist));
1980: my $rowcount = 0;
1981: foreach my $user (@sorted_users) {
1982: my %in;
1983: my $sdata = $userlist->{$user};
1984: $rowcount ++;
1985: foreach my $item (@{$keylist}) {
1986: $in{$item} = $sdata->[$index{$item}];
1987: }
1988: $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}]);
1989: if (! defined($in{'start'}) || $in{'start'} == 0) {
1990: $in{'start'} = &mt('none');
1991: } else {
1992: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
1993: }
1994: if (! defined($in{'end'}) || $in{'end'} == 0) {
1995: $in{'end'} = &mt('none');
1996: } else {
1997: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
1998: }
1999: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
2000: $r->print(&Apache::loncommon::start_data_table_row());
2001: $r->print("<td>$rowcount</td>\n");
2002: if ($linkto eq 'aboutme') {
2003: $in{'username'} =
2004: &Apache::loncommon::aboutmewrapper($in{'username'},
2005: $in{'username'},
2006: $in{'domain'});
2007: } elsif ($linkto eq 'modify') {
2008: $in{'username'} = '<a href="'.
2009: "javascript:document.studentform.sname.value='".
2010: $in{'username'}.
2011: "';document.studentform.sdom.value='".$in{'domain'}.
2012: "';document.studentform.state.value='selected".
2013: "';document.studentform.submit();".'">'.
2014: $in{'username'}."</a>\n";
2015: }
2016: foreach my $item (@cols) {
2017: $r->print('<td>'.$in{$item}.'</td>'."\n");
2018: }
2019: if ($context eq 'course') {
2020: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
2021: if ($displayclickers eq 'on') {
2022: my $clickers =
2023: (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
2024: if ($clickers!~/\w/) { $clickers='-'; }
2025: $r->print('<td>'.$clickers.'</td>');
2026: } else {
2027: $r->print(' <td> </td> ');
2028: }
2029: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
2030: if ($displayphotos eq 'on' && $sdata->[$index{'role'}] eq 'st') {
2031: my $imgurl =
2032: &Apache::lonnet::retrievestudentphoto($in{'domain'},$in{'username'},
2033: 'gif','thumbnail');
2034: $r->print(' <td align="right"><a href="javascript:photowindow('."'".&Apache::lonnet::studentphoto($in{'domain'},$in{'username'},'jpg')."'".')"><img src="'.$imgurl.'" border="1"></a></td>');
2035: } else {
2036: $r->print(' <td> </td> ');
2037: }
2038: }
2039: }
2040: }
2041: $r->print(&Apache::loncommon::end_data_table_row());
2042: } elsif ($mode eq 'csv') {
2043: next if (! defined($CSVfile));
2044: # no need to bother with $linkto
2045: if (! defined($in{'start'}) || $in{'start'} == 0) {
2046: $in{'start'} = &mt('none');
2047: } else {
2048: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
2049: }
2050: if (! defined($in{'end'}) || $in{'end'} == 0) {
2051: $in{'end'} = &mt('none');
2052: } else {
2053: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
2054: }
2055: my @line = ();
2056: foreach my $item (@cols) {
2057: push @line,&Apache::loncommon::csv_translate($in{$item});
2058: }
2059: print $CSVfile '"'.join('","',@line).'"'."\n";
2060: } elsif ($mode eq 'excel') {
2061: my $col = 0;
2062: foreach my $item (@cols) {
2063: if ($item eq 'start' || $item eq 'end') {
2064: if (defined($item) && $item != 0) {
2065: $excel_sheet->write($row,$col++,
2066: &Apache::lonstathelpers::calc_serial($in{item}),
2067: $format->{'date'});
2068: } else {
2069: $excel_sheet->write($row,$col++,'none');
2070: }
2071: } else {
2072: $excel_sheet->write($row,$col++,$in{$item});
2073: }
2074: }
2075: $row++;
2076: }
2077: }
2078: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
2079: $r->print(&Apache::loncommon::end_data_table().'<br />');
2080: } elsif ($mode eq 'excel') {
2081: $excel_workbook->close();
2082: $r->print('<p><a href="'.$excel_filename.'">'.
2083: &mt('Your Excel spreadsheet').'</a> '.&mt('is ready for download').'.</p>'."\n");
2084: } elsif ($mode eq 'csv') {
2085: close($CSVfile);
2086: $r->print('<a href="'.$CSVfilename.'">'.
2087: &mt('Your CSV file').'</a> is ready for download.'.
2088: "\n");
2089: $r->rflush();
2090: }
2091: if ($mode eq 'autoenroll') {
2092: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
2093: } else {
2094: return ($usercount);
2095: }
2096: }
2097:
2098: sub role_type_names {
2099: my %lt = &Apache::lonlocal::texthash (
2100: 'domain' => 'Domain Roles',
2101: 'construction_space' => 'Co-Author Roles',
2102: 'course' => 'Course Roles',
2103: );
2104: return %lt;
2105: }
2106:
2107: sub results_header_row {
2108: my ($rolefilter,$statusmode,$context) = @_;
2109: my ($description,$showfilter);
2110: if ($rolefilter ne 'Any') {
2111: $showfilter = $rolefilter;
2112: }
2113: if ($context eq 'course') {
2114: $description = &mt('Course - ').$env{'course.'.$env{'request.course.id'}.'.description'}.': ';
2115: if ($statusmode eq 'Expired') {
2116: $description .= &mt('Users in course with expired [_1] roles',$showfilter);
2117: }
2118: if ($statusmode eq 'Future') {
2119: $description .= &mt('Users in course with future [_1] roles',$showfilter);
2120: } elsif ($statusmode eq 'Active') {
2121: $description .= &mt('Users in course with active [_1] roles',$showfilter);
2122: } else {
2123: if ($rolefilter eq 'Any') {
2124: $description .= &mt('All users in course');
2125: } else {
2126: $description .= &mt('All users in course with [_1] roles',$rolefilter);
2127: }
2128: }
2129: } elsif ($context eq 'construction_space') {
2130: $description = &mt('Author space for [_1].').' ';
2131: if ($statusmode eq 'Expired') {
2132: $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
2133: } elsif ($statusmode eq 'Future') {
2134: $description .= &mt('Co-authors with future [_1] roles',$showfilter);
2135: } elsif ($statusmode eq 'Active') {
2136: $description .= &mt('Co-authors with active [_1] roles',$showfilter);
2137: } else {
2138: if ($rolefilter eq 'Any') {
2139: $description .= &mt('All co-authors');
2140: } else {
2141: $description .= &mt('All co-authors with [_1] roles',$rolefilter);
2142: }
2143: }
2144: } elsif ($context eq 'domain') {
2145: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
2146: $description = &mt('Domain - ').$domdesc.': ';
2147: if ($env{'form.roletype'} eq 'domain') {
2148: if ($statusmode eq 'Expired') {
2149: $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
2150: } elsif ($statusmode eq 'Future') {
2151: $description .= &mt('Users in domain with future [_1] roles',$showfilter);
2152: } elsif ($statusmode eq 'Active') {
2153: $description .= &mt('Users in domain with active [_1] roles',$showfilter);
2154: } else {
2155: if ($rolefilter eq 'Any') {
2156: $description .= &mt('All users in domain');
2157: } else {
2158: $description .= &mt('All users in domain with [_1] roles',$rolefilter);
2159: }
2160: }
2161: } elsif ($env{'form.roletype'} eq 'construction_space') {
2162: if ($statusmode eq 'Expired') {
2163: $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
2164: } elsif ($statusmode eq 'Future') {
2165: $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
2166: } elsif ($statusmode eq 'Active') {
2167: $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
2168: } else {
2169: if ($rolefilter eq 'Any') {
2170: $description .= &mt('All users with co-author roles in domain',$showfilter);
2171: } else {
2172: $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
2173: }
2174: }
2175: } elsif ($env{'form.roletype'} eq 'course') {
2176: my $coursefilter = $env{'form.coursepick'};
2177: if ($coursefilter eq 'category') {
2178: my $instcode = &instcode_from_coursefilter();
2179: if ($instcode eq '.') {
2180: $description .= &mt('All courses in domain').' - ';
2181: } else {
2182: $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
2183: }
2184: } elsif ($coursefilter eq 'selected') {
2185: $description .= &mt('Selected courses in domain').' - ';
2186: } elsif ($coursefilter eq 'all') {
2187: $description .= &mt('All courses in domain').' - ';
2188: }
2189: if ($statusmode eq 'Expired') {
2190: $description .= &mt('users with expired [_1] roles',$showfilter);
2191: } elsif ($statusmode eq 'Future') {
2192: $description .= &mt('users with future [_1] roles',$showfilter);
2193: } elsif ($statusmode eq 'Active') {
2194: $description .= &mt('users with active [_1] roles',$showfilter);
2195: } else {
2196: if ($rolefilter eq 'Any') {
2197: $description .= &mt('all users');
2198: } else {
2199: $description .= &mt('users with [_1] roles',$rolefilter);
2200: }
2201: }
2202: }
2203: }
2204: return $description;
2205: }
2206:
2207: #################################################
2208: #################################################
2209: sub show_drop_list {
2210: my ($r,$classlist,$keylist,$nosort)=@_;
2211: my $cid=$env{'request.course.id'};
2212: if (! exists($env{'form.sortby'})) {
2213: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2214: ['sortby']);
2215: }
2216: my $sortby = $env{'form.sortby'};
2217: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
2218: $sortby = 'username';
2219: }
2220: my $cdom = $env{'course.'.$cid.'.domain'};
2221: my $cnum = $env{'course.'.$cid,'.num'};
2222: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
2223: $classlist,$keylist,$cdom,$cnum);
2224: #
2225: my $action = "drop";
2226: $r->print(<<END);
2227: <input type="hidden" name="sortby" value="$sortby" />
2228: <input type="hidden" name="action" value="$action" />
2229: <input type="hidden" name="state" value="done" />
2230: <script>
2231: function checkAll(field) {
2232: for (i = 0; i < field.length; i++)
2233: field[i].checked = true ;
2234: }
2235:
2236: function uncheckAll(field) {
2237: for (i = 0; i < field.length; i++)
2238: field[i].checked = false ;
2239: }
2240: </script>
2241: <p>
2242: <input type="hidden" name="phase" value="four">
2243: END
2244:
2245: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
2246: 'dom' => "domain",
2247: 'sn' => "student name",
2248: 'sec' => "section",
2249: 'start' => "start date",
2250: 'end' => "end date",
2251: 'groups' => "active groups",
2252: );
2253: if ($nosort) {
2254: $r->print(&Apache::loncommon::start_data_table());
2255: $r->print(<<END);
2256: <tr>
2257: <th> </th>
2258: <th>$lt{'usrn'}</th>
2259: <th>$lt{'dom'}</th>
2260: <th>ID</th>
2261: <th>$lt{'sn'}</th>
2262: <th>$lt{'sec'}</th>
2263: <th>$lt{'start'}</th>
2264: <th>$lt{'end'}</th>
2265: <th>$lt{'groups'}</th>
2266: </tr>
2267: END
2268:
2269: } else {
2270: $r->print(&Apache::loncommon::start_data_table());
2271: $r->print(<<END);
2272: <tr><th> </th>
2273: <th>
2274: <a href="/adm/dropadd?action=$action&sortby=username">$lt{'usrn'}</a>
2275: </th><th>
2276: <a href="/adm/dropadd?action=$action&sortby=domain">$lt{'dom'}</a>
2277: </th><th>
2278: <a href="/adm/dropadd?action=$action&sortby=id">ID</a>
2279: </th><th>
2280: <a href="/adm/dropadd?action=$action&sortby=fullname">$lt{'sn'}</a>
2281: </th><th>
2282: <a href="/adm/dropadd?action=$action&sortby=section">$lt{'sec'}</a>
2283: </th><th>
2284: <a href="/adm/dropadd?action=$action&sortby=start">$lt{'start'}</a>
2285: </th><th>
2286: <a href="/adm/dropadd?action=$action&sortby=end">$lt{'end'}</a>
2287: </th><th>
2288: <a href="/adm/dropadd?action=$action&sortby=groups">$lt{'groups'}</a>
2289: </th>
2290: </tr>
2291: END
2292: }
2293: #
2294: # Sort the students
2295: my %index;
2296: my $i;
2297: foreach (@$keylist) {
2298: $index{$_} = $i++;
2299: }
2300: $index{'groups'} = scalar(@$keylist);
2301: my $index = $index{$sortby};
2302: my $second = $index{'username'};
2303: my $third = $index{'domain'};
2304: my @Sorted_Students = sort {
2305: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
2306: ||
2307: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
2308: ||
2309: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
2310: } (keys(%$classlist));
2311: foreach my $student (@Sorted_Students) {
2312: my $error;
2313: my $sdata = $classlist->{$student};
2314: my $username = $sdata->[$index{'username'}];
2315: my $domain = $sdata->[$index{'domain'}];
2316: my $section = $sdata->[$index{'section'}];
2317: my $name = $sdata->[$index{'fullname'}];
2318: my $id = $sdata->[$index{'id'}];
2319: my $start = $sdata->[$index{'start'}];
2320: my $end = $sdata->[$index{'end'}];
2321: my $groups = $classgroups->{$student};
2322: my $active_groups;
2323: if (ref($groups->{active}) eq 'HASH') {
2324: $active_groups = join(', ',keys(%{$groups->{'active'}}));
2325: }
2326: if (! defined($start) || $start == 0) {
2327: $start = &mt('none');
2328: } else {
2329: $start = &Apache::lonlocal::locallocaltime($start);
2330: }
2331: if (! defined($end) || $end == 0) {
2332: $end = &mt('none');
2333: } else {
2334: $end = &Apache::lonlocal::locallocaltime($end);
2335: }
2336: my $status = $sdata->[$index{'status'}];
2337: next if ($status ne 'Active');
2338: #
2339: $r->print(&Apache::loncommon::start_data_table_row());
2340: $r->print(<<"END");
2341: <td><input type="checkbox" name="droplist" value="$student"></td>
2342: <td>$username</td>
2343: <td>$domain</td>
2344: <td>$id</td>
2345: <td>$name</td>
2346: <td>$section</td>
2347: <td>$start</td>
2348: <td>$end</td>
2349: <td>$active_groups</td>
2350: END
2351: $r->print(&Apache::loncommon::end_data_table_row());
2352: }
2353: $r->print(&Apache::loncommon::end_data_table().'<br />');
2354: %lt=&Apache::lonlocal::texthash(
2355: 'dp' => "Expire Users' Roles",
2356: 'ca' => "check all",
2357: 'ua' => "uncheck all",
2358: );
2359: $r->print(<<"END");
2360: </p><p>
2361: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)">
2362: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)">
2363: <p><input type=submit value="$lt{'dp'}"></p>
2364: END
2365: return;
2366: }
2367:
2368: #
2369: # Print out the initial form to get the file containing a list of users
2370: #
2371: sub print_first_users_upload_form {
2372: my ($r,$context) = @_;
2373: my $str;
2374: $str = '<input type="hidden" name="phase" value="two">';
2375: $str .= '<input type="hidden" name="action" value="upload" />';
2376: $str .= '<input type="hidden" name="state" value="got_file" />';
2377: $str .= "<h3>".&mt('Upload a file containing information about users')."</h3>\n";
2378: $str .= &Apache::loncommon::upfile_select_html();
2379: $str .= "<p>\n";
2380: $str .= '<input type="submit" name="fileupload" value="'.
2381: &mt('Upload file of users').'">'."\n";
2382: $str .= '<label><input type="checkbox" name="noFirstLine" /> '.
2383: &mt('Ignore First Line')."</label></p>\n";
2384: $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List",
2385: &mt("How do I create a users list from a spreadsheet")).
2386: "<br />\n";
2387: $str .= &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
2388: &mt("How do I create a CSV file from a spreadsheet")).
2389: "<br />\n";
2390: $str .= &Apache::loncommon::end_page();
2391: $r->print($str);
2392: return;
2393: }
2394:
2395: # ================================================= Drop/Add from uploaded file
2396: sub upfile_drop_add {
2397: my ($r,$context) = @_;
2398: &Apache::loncommon::load_tmp_file($r);
2399: my @userdata=&Apache::loncommon::upfile_record_sep();
2400: if($env{'form.noFirstLine'}){shift(@userdata);}
2401: my @keyfields = split(/\,/,$env{'form.keyfields'});
2402: my %fields=();
2403: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
2404: if ($env{'form.upfile_associate'} eq 'reverse') {
2405: if ($env{'form.f'.$i} ne 'none') {
2406: $fields{$keyfields[$i]}=$env{'form.f'.$i};
2407: }
2408: } else {
2409: $fields{$env{'form.f'.$i}}=$keyfields[$i];
2410: }
2411: }
2412: #
2413: # Store the field choices away
2414: foreach my $field (qw/username names
2415: fname mname lname gen id sec ipwd email role/) {
2416: $env{'form.'.$field.'_choice'}=$fields{$field};
2417: }
2418: &Apache::loncommon::store_course_settings('enrollment_upload',
2419: { 'username_choice' => 'scalar',
2420: 'names_choice' => 'scalar',
2421: 'fname_choice' => 'scalar',
2422: 'mname_choice' => 'scalar',
2423: 'lname_choice' => 'scalar',
2424: 'gen_choice' => 'scalar',
2425: 'id_choice' => 'scalar',
2426: 'sec_choice' => 'scalar',
2427: 'ipwd_choice' => 'scalar',
2428: 'email_choice' => 'scalar',
2429: 'role_choice' => 'scalar' });
2430: #
2431: my ($startdate,$enddate) = &get_dates_from_form();
2432: if ($env{'form.makedatesdefault'}) {
2433: $r->print(&make_dates_default($startdate,$enddate));
2434: }
2435: # Determine domain and desired host (home server)
2436: my $domain=$env{'request.role.domain'};
2437: my $desiredhost = $env{'form.lcserver'};
2438: if (lc($desiredhost) eq 'default') {
2439: $desiredhost = undef;
2440: } else {
2441: my %home_servers = &Apache::lonnet::get_servers($domain,'library');
2442: if (! exists($home_servers{$desiredhost})) {
2443: $r->print('<span class="LC_error">'.&mt('Error').
2444: &mt('Invalid home server specified').'</span>');
2445: $r->print(&Apache::loncommon::end_page());
2446: return;
2447: }
2448: }
2449: # Determine authentication mechanism
2450: my $changeauth;
2451: if ($context eq 'domain') {
2452: $changeauth = $env{'form.changeauth'};
2453: }
2454: my $amode = '';
2455: my $genpwd = '';
2456: if ($env{'form.login'} eq 'krb') {
2457: $amode='krb';
2458: $amode.=$env{'form.krbver'};
2459: $genpwd=$env{'form.krbarg'};
2460: } elsif ($env{'form.login'} eq 'int') {
2461: $amode='internal';
2462: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
2463: $genpwd=$env{'form.intarg'};
2464: }
2465: } elsif ($env{'form.login'} eq 'loc') {
2466: $amode='localauth';
2467: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
2468: $genpwd=$env{'form.locarg'};
2469: }
2470: }
2471: if ($amode =~ /^krb/) {
2472: if (! defined($genpwd) || $genpwd eq '') {
2473: $r->print('<span class="Error">'.
2474: &mt('Unable to enroll users').' '.
2475: &mt('No Kerberos domain was specified.').'</span></p>');
2476: $amode = ''; # This causes the loop below to be skipped
2477: }
2478: }
2479: my ($cid,$defaultsec,$defaultrole,$setting);
2480: if ($context eq 'domain') {
2481: $setting = $env{'form.roleaction'};
2482: if ($setting eq 'domain') {
2483: $defaultrole = $env{'form.defaultrole'};
2484: } elsif ($setting eq 'course') {
2485: $defaultrole = $env{'form.courserole'};
2486: }
2487: } elsif ($context eq 'construction_space') {
2488: $defaultrole = $env{'form.defaultrole'};
2489: }
2490: if ($context eq 'domain' && $setting eq 'course') {
2491: if ($env{'form.newsec'} ne '') {
2492: $defaultsec = $env{'form.newsec'};
2493: } elsif ($env{'form.defaultsec'} ne '') {
2494: $defaultsec = $env{'form.defaultsec'}
2495: }
2496: }
2497: if ($env{'request.course.id'} ne '') {
2498: $cid = $env{'request.course.id'};
2499: } elsif ($env{'form.defaultdomain'} ne '' && $env{'form.defaultcourse'} ne '') {
2500: $cid = $env{'form.defaultdomain'}.'_'.
2501: $env{'form.defaultcourse'};
2502: }
2503: if ( $domain eq &LONCAPA::clean_domain($domain)
2504: && ($amode ne '')) {
2505: #######################################
2506: ## Add/Modify Users ##
2507: #######################################
2508: if ($context eq 'course') {
2509: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
2510: } elsif ($context eq 'construction_space') {
2511: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
2512: } else {
2513: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
2514: }
2515: my %counts = (
2516: user => 0,
2517: auth => 0,
2518: role => 0,
2519: );
2520: my $flushc=0;
2521: my %student=();
2522: my %curr_groups;
2523: my %userchg;
2524: if ($context eq 'course') {
2525: # Get information about course groups
2526: %curr_groups = &Apache::longroup::coursegroups();
2527: }
2528: my (%curr_rules,%got_rules,%alerts);
2529: # Get new users list
2530: foreach (@userdata) {
2531: my %entries=&Apache::loncommon::record_sep($_);
2532: # Determine user name
2533: unless (($entries{$fields{'username'}} eq '') ||
2534: (!defined($entries{$fields{'username'}}))) {
2535: my ($fname, $mname, $lname,$gen) = ('','','','');
2536: if (defined($fields{'names'})) {
2537: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
2538: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
2539: } else {
2540: if (defined($fields{'fname'})) {
2541: $fname=$entries{$fields{'fname'}};
2542: }
2543: if (defined($fields{'mname'})) {
2544: $mname=$entries{$fields{'mname'}};
2545: }
2546: if (defined($fields{'lname'})) {
2547: $lname=$entries{$fields{'lname'}};
2548: }
2549: if (defined($fields{'gen'})) {
2550: $gen=$entries{$fields{'gen'}};
2551: }
2552: }
2553: if ($entries{$fields{'username'}}
2554: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
2555: $r->print('<br />'.
2556: &mt('<b>[_1]</b>: Unacceptable username for user [_2] [_3] [_4] [_5]',
2557: $entries{$fields{'username'}},$fname,$mname,$lname,$gen).
2558: '</b>');
2559: } else {
2560: my $username = $entries{$fields{'username'}};
2561: my $sec;
2562: if ($context eq 'course' || $setting eq 'course') {
2563: # determine section number
2564: if (defined($fields{'sec'})) {
2565: if (defined($entries{$fields{'sec'}})) {
2566: $sec=$entries{$fields{'sec'}};
2567: }
2568: } else {
2569: $sec = $defaultsec;
2570: }
2571: # remove non alphanumeric values from section
2572: $sec =~ s/\W//g;
2573: if ($sec eq "none" || $sec eq 'all') {
2574: $r->print('<br />'.
2575: &mt('<b>[_1]</b>: Unable to enroll: section name "[_2]" for user [_3] [_4] [_5] [_6] is a reserved word.',
2576: $username,$sec,$fname,$mname,$lname,$gen));
2577: next;
2578: } elsif (($sec ne '') && (exists($curr_groups{$sec}))) {
2579: $r->print('<br />'.
2580: &mt('<b>[_1]</b>: Unable to enroll: section name "[_2]" for user [_3] [_4] [_5] [_6] is a course group. Section names and group names must be distinct.',
2581: $username,$sec,$fname,$mname,$lname,$gen));
2582: next;
2583: }
2584: }
2585: # determine id number
2586: my $id='';
2587: if (defined($fields{'id'})) {
2588: if (defined($entries{$fields{'id'}})) {
2589: $id=$entries{$fields{'id'}};
2590: }
2591: $id=~tr/A-Z/a-z/;
2592: }
2593: # determine email address
2594: my $email='';
2595: if (defined($fields{'email'})) {
2596: if (defined($entries{$fields{'email'}})) {
2597: $email=$entries{$fields{'email'}};
2598: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; } }
2599: }
2600: # determine user password
2601: my $password = $genpwd;
2602: if (defined($fields{'ipwd'})) {
2603: if ($entries{$fields{'ipwd'}}) {
2604: $password=$entries{$fields{'ipwd'}};
2605: }
2606: }
2607: # determine user role
2608: my $role = '';
2609: if (defined($fields{'role'})) {
2610: if ($entries{$fields{'role'}}) {
2611: my @poss_roles =
2612: &curr_role_permissions($context,$setting);
2613: if (grep(/^\Q$entries{$fields{'role'}}\E/,@poss_roles)) {
2614: $role=$entries{$fields{'role'}};
2615: } else {
2616: my $rolestr = join(', ',@poss_roles);
2617: $r->print('<br />'.
2618: &mt('<b>[_1]</b>: You do not have permission to add the requested role [_2] for the user.',$entries{$fields{'username'}},$entries{$fields{'role'}}).'<br />'.&mt('Allowable role(s) is/are: [_1].',$rolestr)."\n");
2619: next;
2620: }
2621: }
2622: }
2623: if ($role eq '') {
2624: $role = $defaultrole;
2625: }
2626: # Clean up whitespace
2627: foreach (\$domain,\$username,\$id,\$fname,\$mname,
2628: \$lname,\$gen,\$sec,\$role) {
2629: $$_ =~ s/(\s+$|^\s+)//g;
2630: }
2631: # check against rules
2632: my $checkid = 0;
2633: my $newuser = 0;
2634: my (%rulematch,%inst_results,%idinst_results);
2635: my $uhome=&Apache::lonnet::homeserver($username,$domain);
2636: if ($uhome eq 'no_host') {
2637: $checkid = 1;
2638: $newuser = 1;
2639: my $checkhash;
2640: my $checks = { 'username' => 1 };
2641: $checkhash->{$username.':'.$domain} = { 'newuser' => 1, };
2642: &Apache::loncommon::user_rule_check($checkhash,$checks,
2643: \%alerts,\%rulematch,\%inst_results,\%curr_rules,
2644: \%got_rules);
2645: if (ref($alerts{'username'}) eq 'HASH') {
2646: if (ref($alerts{'username'}{$domain}) eq 'HASH') {
2647: next if ($alerts{'username'}{$domain}{$username});
2648: }
2649: }
2650: }
2651: if ($id ne '') {
2652: if (!$newuser) {
2653: my %idhash = &Apache::lonnet::idrget($domain,($username));
2654: if ($idhash{$username} ne $id) {
2655: $checkid = 1;
2656: }
2657: }
2658: if ($checkid) {
2659: my $checkhash;
2660: my $checks = { 'id' => 1 };
2661: $checkhash->{$username.':'.$domain} = { 'newuser' => $newuser,
2662: 'id' => $id };
2663: &Apache::loncommon::user_rule_check($checkhash,$checks,
2664: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,
2665: \%got_rules);
2666: if (ref($alerts{'id'}) eq 'HASH') {
2667: if (ref($alerts{'id'}{$domain}) eq 'HASH') {
2668: next if ($alerts{'id'}{$domain}{$id});
2669: }
2670: }
2671: }
2672: }
2673: if ($password || $env{'form.login'} eq 'loc') {
2674: my ($userresult,$authresult,$roleresult);
2675: if ($role eq 'st') {
2676: &modifystudent($domain,$username,$cid,$sec,
2677: $desiredhost);
2678: $roleresult =
2679: &Apache::lonnet::modifystudent
2680: ($domain,$username,$id,$amode,$password,
2681: $fname,$mname,$lname,$gen,$sec,$enddate,
2682: $startdate,$env{'form.forceid'},
2683: $desiredhost,$email);
2684: } else {
2685: ($userresult,$authresult,$roleresult) =
2686: &modifyuserrole($context,$setting,
2687: $changeauth,$cid,$domain,$username,
2688: $id,$amode,$password,$fname,
2689: $mname,$lname,$gen,$sec,
2690: $env{'form.forceid'},$desiredhost,
2691: $email,$role,$enddate,$startdate,$checkid);
2692: }
2693: $flushc =
2694: &user_change_result($r,$userresult,$authresult,
2695: $roleresult,\%counts,$flushc,
2696: $username,%userchg);
2697: } else {
2698: if ($context eq 'course') {
2699: $r->print('<br />'.
2700: &mt('<b>[_1]</b>: Unable to enroll. No password specified.',$username)
2701: );
2702: } elsif ($context eq 'construction_space') {
2703: $r->print('<br />'.
2704: &mt('<b>[_1]</b>: Unable to add co-author. No password specified.',$username)
2705: );
2706: } else {
2707: $r->print('<br />'.
2708: &mt('<b>[_1]</b>: Unable to add user. No password specified.',$username)
2709: );
2710: }
2711: }
2712: }
2713: }
2714: } # end of foreach (@userdata)
2715: # Flush the course logs so reverse user roles immediately updated
2716: &Apache::lonnet::flushcourselogs();
2717: $r->print("</p>\n<p>\n".&mt('Processed [_1] user(s).',$counts{'user'}).
2718: "</p>\n");
2719: if ($counts{'role'} > 0) {
2720: $r->print("<p>\n".
2721: &mt('Roles added for [_1] users. If user is active, the new role will be available when the user next logs in to LON-CAPA.',$counts{'role'})."</p>\n");
2722: }
2723: if ($counts{'auth'} > 0) {
2724: $r->print("<p>\n".
2725: &mt('Authentication changed for [_1] existing users.',
2726: $counts{'auth'})."</p>\n");
2727: }
2728: if (keys(%alerts) > 0) {
2729: if (ref($alerts{'username'}) eq 'HASH') {
2730: foreach my $dom (sort(keys(%{$alerts{'username'}}))) {
2731: my $count;
2732: if (ref($alerts{'username'}{$dom}) eq 'HASH') {
2733: $count = keys(%{$alerts{'username'}{$dom}});
2734: }
2735: my $domdesc = &Apache::lonnet::domain($domain,'description');
2736: if (ref($curr_rules{$dom}) eq 'HASH') {
2737: $r->print(&Apache::loncommon::instrule_disallow_msg(
2738: 'username',$domdesc,$count,'upload'));
2739: }
2740: $r->print(&Apache::loncommon::user_rule_formats($dom,
2741: $domdesc,$curr_rules{$dom}{'username'},
2742: 'username'));
2743: }
2744: }
2745: if (ref($alerts{'id'}) eq 'HASH') {
2746: foreach my $dom (sort(keys(%{$alerts{'id'}}))) {
2747: my $count;
2748: if (ref($alerts{'id'}{$dom}) eq 'HASH') {
2749: $count = keys(%{$alerts{'id'}{$dom}});
2750: }
2751: my $domdesc = &Apache::lonnet::domain($domain,'description');
2752: if (ref($curr_rules{$dom}) eq 'HASH') {
2753: $r->print(&Apache::loncommon::instrule_disallow_msg(
2754: 'id',$domdesc,$count,'upload'));
2755: }
2756: $r->print(&Apache::loncommon::user_rule_formats($dom,
2757: $domdesc,$curr_rules{$dom}{'id'},'id'));
2758: }
2759: }
2760: }
2761: $r->print('<form name="uploadresult" action="/adm/createuser">');
2762: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','prevphase','currstate']));
2763: $r->print('</form>');
2764: #####################################
2765: # Drop students #
2766: #####################################
2767: if ($env{'form.fullup'} eq 'yes') {
2768: $r->print('<h3>'.&mt('Dropping Students')."</h3>\n");
2769: # Get current classlist
2770: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
2771: if (! defined($classlist)) {
2772: $r->print(&mt('There are no students currently enrolled.').
2773: "\n");
2774: } else {
2775: # Remove the students we just added from the list of students.
2776: foreach (@userdata) {
2777: my %entries=&Apache::loncommon::record_sep($_);
2778: unless (($entries{$fields{'username'}} eq '') ||
2779: (!defined($entries{$fields{'username'}}))) {
2780: delete($classlist->{$entries{$fields{'username'}}.
2781: ':'.$domain});
2782: }
2783: }
2784: # Print out list of dropped students.
2785: &show_drop_list($r,$classlist,$keylist,'nosort');
2786: }
2787: }
2788: } # end of unless
2789: }
2790:
2791: sub user_change_result {
2792: my ($r,$userresult,$authresult,$roleresult,$counts,$flushc,$username,
2793: $userchg) = @_;
2794: my $okresult = 0;
2795: if ($userresult ne 'ok') {
2796: if ($userresult =~ /^error:(.+)$/) {
2797: my $error = $1;
2798: $r->print('<br />'.
2799: &mt('<b>[_1]</b>: Unable to add/modify: [_2]',$username,$error));
2800: }
2801: } else {
2802: $counts->{'user'} ++;
2803: $okresult = 1;
2804: }
2805: if ($authresult ne 'ok') {
2806: if ($authresult =~ /^error:(.+)$/) {
2807: my $error = $1;
2808: $r->print('<br />'.
2809: &mt('<b>[_1]</b>: Unable to modify authentication: [_2]',$username,$error));
2810: }
2811: } else {
2812: $counts->{'auth'} ++;
2813: $okresult = 1;
2814: }
2815: if ($roleresult ne 'ok') {
2816: if ($roleresult =~ /^error:(.+)$/) {
2817: my $error = $1;
2818: $r->print('<br />'.
2819: &mt('<b>[_1]</b>: Unable to add role: [_2]',$username,$error));
2820: }
2821: } else {
2822: $counts->{'role'} ++;
2823: $okresult = 1;
2824: }
2825: if ($okresult) {
2826: $flushc++;
2827: $userchg->{$username}=1;
2828: $r->print('. ');
2829: if ($flushc>15) {
2830: $r->rflush;
2831: $flushc=0;
2832: }
2833: }
2834: return $flushc;
2835: }
2836:
2837: # ========================================================= Menu Phase Two Drop
2838: sub print_expire_menu {
2839: my ($r,$context) = @_;
2840: $r->print("<h3>".&mt("Expire Users' Roles")."</h3>");
2841: my $cid=$env{'request.course.id'};
2842: my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
2843: if (! defined($classlist)) {
2844: $r->print(&mt('There are no students currently enrolled.')."\n");
2845: return;
2846: }
2847: # Print out the available choices
2848: &show_drop_list($r,$classlist,$keylist);
2849: return;
2850: }
2851:
2852:
2853: # ================================================================== Phase four
2854:
2855: sub expire_user_list {
2856: my ($r,$context) = @_;
2857: my $count=0;
2858: my @droplist = &Apache::loncommon::get_env_multiple('form.droplist');
2859: foreach (@droplist) {
2860: my ($uname,$udom)=split(/\:/,$_);
2861: # drop student
2862: my $result = &modifystudent($udom,$uname,$env{'request.course.id'});
2863: if ($result eq 'ok' || $result eq 'ok:') {
2864: $r->print(&mt('Dropped [_1]',$uname.'@'.$udom).'<br>');
2865: $count++;
2866: } else {
2867: $r->print(
2868: &mt('Error dropping [_1]:[_2]',$uname.'@'.$udom,$result).
2869: '<br />');
2870: }
2871: }
2872: $r->print('<p><b>'.&mt('Dropped [_1] user(s).',$count).'</b></p>');
2873: $r->print('<p>'.&mt('Re-enrollment will re-activate data.')) if ($count);
2874: }
2875:
2876: sub section_check_js {
2877: my $groupslist;
2878: my %curr_groups = &Apache::longroup::coursegroups();
2879: if (%curr_groups) {
2880: $groupslist = join('","',sort(keys(%curr_groups)));
2881: }
2882: return <<"END";
2883: function validate(caller) {
2884: var groups = new Array("$groupslist");
2885: var secname = caller.value;
2886: if ((secname == 'all') || (secname == 'none')) {
2887: alert("'"+secname+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
2888: return 'error';
2889: }
2890: if (secname != '') {
2891: for (var k=0; k<groups.length; k++) {
2892: if (secname == groups[k]) {
2893: 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.");
2894: return 'error';
2895: }
2896: }
2897: }
2898: return 'ok';
2899: }
2900: END
2901: }
2902:
2903: sub set_login {
2904: my ($dom,$authformkrb,$authformint,$authformloc) = @_;
2905: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2906: my $response;
2907: my ($authnum,%can_assign) =
2908: &Apache::loncommon::get_assignable_auth($dom);
2909: if ($authnum) {
2910: $response = &Apache::loncommon::start_data_table();
2911: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2912: $response .= &Apache::loncommon::start_data_table_row().
2913: '<td>'.$authformkrb.'</td>'.
2914: &Apache::loncommon::end_data_table_row()."\n";
2915: }
2916: if ($can_assign{'int'}) {
2917: $response .= &Apache::loncommon::start_data_table_row().
2918: '<td>'.$authformint.'</td>'.
2919: &Apache::loncommon::end_data_table_row()."\n"
2920: }
2921: if ($can_assign{'loc'}) {
2922: $response .= &Apache::loncommon::start_data_table_row().
2923: '<td>'.$authformloc.'</td>'.
2924: &Apache::loncommon::end_data_table_row()."\n";
2925: }
2926: $response .= &Apache::loncommon::end_data_table();
2927: }
2928: return $response;
2929: }
2930:
2931: 1;
2932:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>