Annotation of loncom/interface/lonuserutils.pm, revision 1.6
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
1.6 ! albertel 4: # $Id: lonuserutils.pm,v 1.5 2007/11/15 21:24:51 raeburn Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ###############################################################
30:
31: package Apache::lonuserutils;
32:
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,
1.5 raeburn 88: $end,$start,$checkid) = @_;
89: my ($scope,$userresult,$authresult,$roleresult,$idresult);
1.1 raeburn 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: }
1.5 raeburn 96: } elsif ($context eq 'domain') {
1.1 raeburn 97: $scope = '/'.$env{'request.role.domain'}.'/';
1.5 raeburn 98: } elsif ($context eq 'construction_space') {
1.1 raeburn 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') {
1.5 raeburn 104: if (($changeauth eq 'Yes') && (&Apache::lonnet::allowed('mau',$udom))) {
1.1 raeburn 105: if ((($umode =~ /^krb4|krb5|internal$/) && $upass ne '') ||
106: ($umode eq 'localauth')) {
107: $authresult = &Apache::lonnet::modifyuserauth($udom,$uname,$umode,$upass);
108: }
109: }
1.5 raeburn 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: }
1.1 raeburn 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') {
1.5 raeburn 128: if ($role ne '') {
1.1 raeburn 129: $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
130: $role,$end,$start);
131: }
132: }
1.5 raeburn 133: return ($userresult,$authresult,$roleresult,$idresult);
1.1 raeburn 134: }
135:
1.5 raeburn 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) = @_;
1.6 ! albertel 162: my ($uid,$classlistentry);
1.5 raeburn 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:
1.1 raeburn 197: ###############################################################
198: ###############################################################
1.2 raeburn 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();
1.1 raeburn 207: #
208: # build up the menu information to be passed to
209: # &Apache::loncommon::linked_select_forms
210: my %select_menus;
1.2 raeburn 211: if ($env{'form.roletype'} eq '') {
212: $env{'form.roletype'} = 'domain';
213: }
214: foreach my $roletype (@roletypes) {
1.1 raeburn 215: # set up the text for this domain
1.2 raeburn 216: $select_menus{$roletype}->{'text'}= $lt{$roletype};
1.1 raeburn 217: # we want a choice of 'default' as the default in the second menu
1.2 raeburn 218: if ($env{'form.roletype'} ne '') {
219: $select_menus{$roletype}->{'default'} = $env{'form.showrole'};
220: } else {
221: $select_menus{$roletype}->{'default'} = 'Any';
222: }
1.1 raeburn 223: # Now build up the other items in the second menu
1.2 raeburn 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');
1.5 raeburn 231: unshift(@roles,'cr');
1.1 raeburn 232: }
1.2 raeburn 233: my $order = ['Any',@roles];
234: $select_menus{$roletype}->{'order'} = $order;
235: foreach my $role (@roles) {
1.5 raeburn 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: }
1.2 raeburn 243: }
244: $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
1.1 raeburn 245: }
1.2 raeburn 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']);
1.1 raeburn 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 />';
1.2 raeburn 715: my ($options,$cb_script,$coursepick) = &default_role_selector($context,'defaultrole',1);
1.1 raeburn 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;
1.5 raeburn 718: } elsif ($context eq 'construction_space') {
719: $Str .= $options;
1.1 raeburn 720: } else {
1.5 raeburn 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>';
1.1 raeburn 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: }
1.5 raeburn 731: if ($context eq 'course' || $context eq 'domain') {
732: $Str .= &forceid_change($context);
733: }
1.1 raeburn 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:
1.5 raeburn 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:
1.1 raeburn 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 {
1.2 raeburn 964: my ($context,$checkpriv) = @_;
1.1 raeburn 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') {
1.2 raeburn 980: $options .= &default_course_roles($context,$checkpriv,%customroles);
1.1 raeburn 981: } elsif ($context eq 'construction_space') {
1.2 raeburn 982: my @roles = &construction_space_roles($checkpriv);
1.1 raeburn 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') {
1.2 raeburn 988: my @roles = &domain_roles($checkpriv);
1.1 raeburn 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".
1.2 raeburn 1005: &default_course_roles($context,$checkpriv,%customroles)."\n".
1.1 raeburn 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 {
1.2 raeburn 1027: my ($context,$checkpriv,%customroles) = @_;
1.1 raeburn 1028: my $output;
1.2 raeburn 1029: my @roles = &course_roles($context,$checkpriv);
1.1 raeburn 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) {
1.2 raeburn 1035: my %customroles = &my_custom_roles();
1.1 raeburn 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 {
1.2 raeburn 1046: my ($checkpriv) = @_;
1.1 raeburn 1047: my @allroles = ('ca','aa');
1048: my @roles;
1.2 raeburn 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: }
1.1 raeburn 1054: }
1.2 raeburn 1055: return @roles;
1056: } else {
1057: return @allroles;
1.1 raeburn 1058: }
1059: }
1060:
1061: sub domain_roles {
1.2 raeburn 1062: my ($checkpriv) = @_;
1.1 raeburn 1063: my @allroles = ('dc','li','dg','au','sc');
1064: my @roles;
1.2 raeburn 1065: if ($checkpriv) {
1066: foreach my $role (@allroles) {
1067: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
1068: push(@roles,$role);
1069: }
1.1 raeburn 1070: }
1.2 raeburn 1071: return @roles;
1072: } else {
1073: return @allroles;
1.1 raeburn 1074: }
1075: }
1076:
1077: sub course_roles {
1.2 raeburn 1078: my ($context,$checkpriv) = @_;
1.1 raeburn 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'}) {
1.2 raeburn 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: }
1.1 raeburn 1096: }
1097: }
1098: }
1.2 raeburn 1099: } else {
1100: @roles = @allroles;
1.1 raeburn 1101: }
1102: }
1103: }
1104: return @roles;
1105: }
1106:
1107: sub curr_role_permissions {
1.2 raeburn 1108: my ($context,$setting,$checkpriv) = @_;
1.1 raeburn 1109: my @roles;
1110: if ($context eq 'construction_space') {
1.2 raeburn 1111: @roles = &construction_space_roles($checkpriv);
1.1 raeburn 1112: } elsif ($context eq 'domain') {
1113: if ($setting eq 'course') {
1.2 raeburn 1114: @roles = &course_roles($context,$checkpriv);
1.1 raeburn 1115: } else {
1.2 raeburn 1116: @roles = &domain_roles($checkpriv);
1.1 raeburn 1117: }
1118: } elsif ($context eq 'course') {
1.2 raeburn 1119: @roles = &course_roles($context,$checkpriv);
1.1 raeburn 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:
1.2 raeburn 1137: sub print_userlist {
1138: my ($r,$mode,$permission,$context,$formname,$totcodes,$codetitles,
1139: $idlist,$idlist_titles) = @_;
1140: my $format = $env{'form.output'};
1.1 raeburn 1141: if (! exists($env{'form.sortby'})) {
1142: $env{'form.sortby'} = 'username';
1143: }
1.2 raeburn 1144: if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
1145: $env{'form.Status'} = 'Active';
1.1 raeburn 1146: }
1147: my $status_select = &Apache::lonhtmlcommon::StatusOptions
1.2 raeburn 1148: ($env{'form.Status'});
1.1 raeburn 1149:
1.2 raeburn 1150: if ($env{'form.showrole'} eq '') {
1151: $env{'form.showrole'} = 'Any';
1152: }
1.1 raeburn 1153: if (! defined($env{'form.output'}) ||
1154: $env{'form.output'} !~ /^(csv|excel|html)$/ ) {
1155: $env{'form.output'} = 'html';
1156: }
1157:
1.2 raeburn 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: }
1.1 raeburn 1168:
1.2 raeburn 1169: # if ($context eq 'course') {
1170: # $r->print(&display_adv_courseroles());
1171: # }
1.1 raeburn 1172: #
1173: # Interface output
1.2 raeburn 1174: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
1175: '<input type="hidden" name="action" value="'.
1.1 raeburn 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: }
1.2 raeburn 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);
1.3 raeburn 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();
1.1 raeburn 1245: if ($context eq 'course') {
1.3 raeburn 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};
1.1 raeburn 1254: }
1.3 raeburn 1255: } else {
1256: $userlist{$student} = $classlist->{$student};
1.1 raeburn 1257: }
1258: }
1.2 raeburn 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'}];
1.1 raeburn 1265: } else {
1.2 raeburn 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,
1.6 ! albertel 1328: %statushash);
1.2 raeburn 1329: if ($env{'form.showrole'} eq 'Any') {
1330: @roles = &course_roles($context);
1.5 raeburn 1331: unshift(@roles,'cr');
1.2 raeburn 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: }
1.1 raeburn 1362: }
1363: }
1.3 raeburn 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");
1.2 raeburn 1375: }
1.3 raeburn 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
1.4 raeburn 1381: my $usercount;
1.3 raeburn 1382: if ($env{'form.action'} eq 'modifystudent') {
1.4 raeburn 1383: ($usercount) = &show_users_list($r,$context,'view','modify',
1384: $env{'form.Status'},\%userlist,$keylist);
1.1 raeburn 1385: } else {
1.4 raeburn 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.'));
1.2 raeburn 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 $format_reply;
1493: my $jscript = '';
1494:
1495: my $totcodes =
1496: &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,
1497: $cdom,$totcodes);
1498: if ($totcodes > 0) {
1499: $format_reply =
1500: &Apache::lonnet::auto_instcode_format($caller,$cdom,\%coursecodes,
1501: \%codes,\@codetitles,\%cat_titles,\%cat_order);
1502: if ($format_reply eq 'ok') {
1503: my $numtypes = @codetitles;
1504: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
1505: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
1506: my $longtitles_str = join('","',@{$longtitles});
1507: my $allidlist = $idlist{$codetitles[0]};
1508: $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
1509: $jscript .= $scripttext;
1510: $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,@codetitles);
1511: }
1512: }
1513: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
1514:
1515: my %elements = (
1516: Year => 'selectbox',
1517: coursepick => 'radio',
1518: coursetotal => 'text',
1519: courselist => 'text',
1520: );
1521: $jscript .= &Apache::lonhtmlcommon::set_form_elements(\%elements);
1522: if ($env{'form.coursepick'} eq 'category') {
1523: $jscript .= qq|
1524: function setCourseCat(formname) {
1525: if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
1526: return;
1527: }
1528: courseSet('Year');
1529: for (var j=0; j<formname.Semester.length; j++) {
1530: if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
1531: formname.Semester.options[j].selected = true;
1532: }
1533: }
1534: if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
1535: return;
1536: }
1537: courseSet('Semester');
1538: for (var j=0; j<formname.Department.length; j++) {
1539: if (formname.Department.options[j].value == "$env{'form.Department'}") { formname.Department.options[j].selected = true;
1540: }
1541: }
1542: if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
1543: return;
1544: }
1545: courseSet('Department');
1546: for (var j=0; j<formname.Number.length; j++) {
1547: if (formname.Number.options[j].value == "$env{'form.Number'}") {
1548: formname.Number.options[j].selected = true;
1549: }
1550: }
1551: }
1552: |;
1553: }
1554: return ($cb_jscript,$jscript,$totcodes,\@codetitles,\%idlist,
1555: \%idlist_titles);
1556: }
1557:
1558: sub course_selector_loadcode {
1559: my ($formname) = @_;
1560: my $loadcode;
1561: if ($env{'form.coursepick'} ne '') {
1562: $loadcode = 'javascript:setFormElements(document.'.$formname.')';
1563: if ($env{'form.coursepick'} eq 'category') {
1564: $loadcode .= ';javascript:setCourseCat(document.'.$formname.')';
1565: }
1566: }
1567: return $loadcode;
1568: }
1569:
1570: sub process_coursepick {
1571: my $coursefilter = $env{'form.coursepick'};
1572: my $cdom = $env{'request.role.domain'};
1573: my %courses;
1574: if ($coursefilter eq 'all') {
1575: %courses = &Apache::lonnet::courseiddump($cdom,'.','.','.','.','.',
1576: undef,undef,'Course');
1577: } elsif ($coursefilter eq 'category') {
1578: my $instcode = &instcode_from_coursefilter();
1579: %courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.',
1580: undef,undef,'Course');
1581: } elsif ($coursefilter eq 'specific') {
1582: if ($env{'form.coursetotal'} > 1) {
1583: my @course_ids = split(/&&/,$env{'form.courselist'});
1584: foreach my $cid (@course_ids) {
1585: $courses{$cid} = '';
1.1 raeburn 1586: }
1.2 raeburn 1587: } else {
1588: $courses{$env{'form.courselist'}} = '';
1.1 raeburn 1589: }
1.2 raeburn 1590: }
1591: return %courses;
1592: }
1593:
1594: sub instcode_from_coursefilter {
1595: my $instcode = '';
1596: my @cats = ('Semester','Year','Department','Number');
1597: foreach my $category (@cats) {
1598: if (defined($env{'form.'.$category})) {
1599: unless ($env{'form.'.$category} eq '-1') {
1600: $instcode .= $env{'form.'.$category};
1601: }
1602: }
1603: }
1604: if ($instcode eq '') {
1605: $instcode = '.';
1606: }
1607: return $instcode;
1608: }
1609:
1610: sub display_adv_courseroles {
1611: my $output;
1612: #
1613: # List course personnel
1614: my %coursepersonnel =
1615: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'});
1616: #
1617: $output = '<br />'.&Apache::loncommon::start_data_table();
1618: foreach my $role (sort(keys(%coursepersonnel))) {
1619: next if ($role =~ /^\s*$/);
1620: $output .= &Apache::loncommon::start_data_table_row().
1621: '<td>'.$role.'</td><td>';
1622: foreach my $user (split(',',$coursepersonnel{$role})) {
1623: my ($puname,$pudom)=split(':',$user);
1624: $output .= ' '.&Apache::loncommon::aboutmewrapper(
1625: &Apache::loncommon::plainname($puname,$pudom),
1626: $puname,$pudom);
1627: }
1628: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
1629: }
1630: $output .= &Apache::loncommon::end_data_table();
1631: }
1632:
1633: sub make_keylist_array {
1634: my ($index,$keylist);
1635: $index->{'domain'} = &Apache::loncoursedata::CL_SDOM();
1636: $index->{'username'} = &Apache::loncoursedata::CL_SNAME();
1637: $index->{'end'} = &Apache::loncoursedata::CL_END();
1638: $index->{'start'} = &Apache::loncoursedata::CL_START();
1639: $index->{'id'} = &Apache::loncoursedata::CL_ID();
1640: $index->{'section'} = &Apache::loncoursedata::CL_SECTION();
1641: $index->{'fullname'} = &Apache::loncoursedata::CL_FULLNAME();
1642: $index->{'status'} = &Apache::loncoursedata::CL_STATUS();
1643: $index->{'type'} = &Apache::loncoursedata::CL_TYPE();
1644: $index->{'lockedtype'} = &Apache::loncoursedata::CL_LOCKEDTYPE();
1645: $index->{'groups'} = &Apache::loncoursedata::CL_GROUP();
1646: $index->{'email'} = &Apache::loncoursedata::CL_PERMANENTEMAIL();
1647: $index->{'role'} = &Apache::loncoursedata::CL_ROLE();
1648: $index->{'extent'} = &Apache::loncoursedata::CL_EXTENT();
1649: foreach my $key (keys(%{$index})) {
1650: $keylist->[$index->{$key}] = $key;
1651: }
1652: return ($index,$keylist);
1653: }
1654:
1655: sub aggregate_user_info {
1656: my ($udom,$uname,$userinfo) = @_;
1657: my %info=&Apache::lonnet::get('environment',
1658: ['firstname','middlename',
1659: 'lastname','generation','id'],
1660: $udom,$uname);
1661: my ($tmp) = keys(%info);
1662: my ($fullname,$id);
1663: if ($tmp =~/^(con_lost|error|no_such_host)/i) {
1664: $fullname = 'not available';
1665: $id = 'not available';
1666: &Apache::lonnet::logthis('unable to retrieve environment '.
1667: 'for '.$uname.':'.$udom);
1.1 raeburn 1668: } else {
1.2 raeburn 1669: $fullname = &Apache::lonnet::format_name(@info{qw/firstname middlename lastname generation/},'lastname');
1670: $id = $info{'id'};
1671: }
1672: $userinfo->{$uname.':'.$udom} = {
1673: fullname => $fullname,
1674: id => $id,
1675: };
1676: return;
1677: }
1.1 raeburn 1678:
1.2 raeburn 1679: sub process_date_info {
1680: my ($userdata) = @_;
1681: my $now = time;
1682: $userdata->{'status'} = 'Active';
1683: if ($userdata->{'start'} > 0) {
1684: if ($now < $userdata->{'start'}) {
1685: $userdata->{'status'} = 'Future';
1686: }
1.1 raeburn 1687: }
1.2 raeburn 1688: if ($userdata->{'end'} > 0) {
1689: if ($now > $userdata->{'end'}) {
1690: $userdata->{'status'} = 'Expired';
1691: }
1692: }
1693: return;
1.1 raeburn 1694: }
1695:
1696: sub show_users_list {
1.2 raeburn 1697: my ($r,$context,$mode,$linkto,$statusmode,$userlist,$keylist)=@_;
1.1 raeburn 1698: #
1699: # Variables for excel output
1700: my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
1701: #
1702: # Variables for csv output
1703: my ($CSVfile,$CSVfilename);
1704: #
1705: my $sortby = $env{'form.sortby'};
1.3 raeburn 1706: my @sortable = ('username','domain','id','fullname','start','end','email','role');
1.2 raeburn 1707: if ($context eq 'course') {
1.3 raeburn 1708: push(@sortable,('section','groups','type'));
1.2 raeburn 1709: } else {
1.3 raeburn 1710: push(@sortable,'extent');
1711: }
1712: if (!grep(/^\Q$sortby\E$/,@sortable)) {
1713: $sortby = 'username';
1.1 raeburn 1714: }
1.2 raeburn 1715: my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers);
1.1 raeburn 1716: if ($context eq 'course') {
1717: $cid=$env{'request.course.id'};
1718: $cdom = $env{'course.'.$cid.'.domain'};
1719: $cnum = $env{'course.'.$cid.'.num'};
1.2 raeburn 1720: ($classgroups) = &Apache::loncoursedata::get_group_memberships(
1721: $userlist,$keylist,$cdom,$cnum);
1.1 raeburn 1722: if (! exists($env{'form.displayphotos'})) {
1723: $env{'form.displayphotos'} = 'off';
1724: }
1725: $displayphotos = $env{'form.displayphotos'};
1726: if (! exists($env{'form.displayclickers'})) {
1727: $env{'form.displayclickers'} = 'off';
1728: }
1729: $displayclickers = $env{'form.displayclickers'};
1730: if ($env{'course.'.$cid.'.internal.showphoto'}) {
1731: $r->print('
1732: <script type="text/javascript">
1733: function photowindow(photolink) {
1734: var title = "Photo_Viewer";
1735: var options = "scrollbars=1,resizable=1,menubar=0";
1736: options += ",width=240,height=240";
1737: stdeditbrowser = open(photolink,title,options,"1");
1738: stdeditbrowser.focus();
1739: }
1740: </script>
1741: ');
1742: }
1743: $r->print(<<END);
1744: <input type="hidden" name="displayphotos" value="$displayphotos" />
1745: <input type="hidden" name="displayclickers" value="$displayclickers" />
1746: END
1747: }
1748: unless ($mode eq 'autoenroll') {
1749: $r->print(<<END);
1750: <input type="hidden" name="state" value="$env{'form.state'}" />
1751: END
1752: }
1753: $r->print(<<END);
1754: <input type="hidden" name="sortby" value="$sortby" />
1755: END
1756:
1757: my %lt=&Apache::lonlocal::texthash(
1758: 'username' => "username",
1759: 'domain' => "domain",
1760: 'id' => 'ID',
1761: 'fullname' => "name",
1762: 'section' => "section",
1763: 'groups' => "active groups",
1764: 'start' => "start date",
1765: 'end' => "end date",
1766: 'status' => "status",
1.2 raeburn 1767: 'role' => "role",
1.1 raeburn 1768: 'type' => "enroll type/action",
1769: 'email' => "email address",
1770: 'clicker' => "clicker id",
1771: 'photo' => "photo",
1.2 raeburn 1772: 'extent' => "extent",
1.1 raeburn 1773: );
1.2 raeburn 1774: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
1775: $lt{'extent'} = &mt('Course(s): description, section(s), status');
1776: } elsif ($context eq 'construction_space') {
1777: $lt{'extent'} = &mt('Author');
1778: }
1.1 raeburn 1779: my @cols = ('username','domain','id','fullname');
1780: if ($context eq 'course') {
1781: push(@cols,'section');
1782: }
1.2 raeburn 1783: if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) {
1784: push(@cols,('start','end'));
1785: }
1.3 raeburn 1786: if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
1.2 raeburn 1787: push(@cols,'role');
1788: }
1789: if ($context eq 'domain' && ($env{'form.roletype'} eq 'construction_space' ||
1790: $env{'form.roletype'} eq 'course')) {
1791: push (@cols,'extent');
1792: }
1793: if (($statusmode eq 'Any') &&
1794: (!($context eq 'domain' && $env{'form.roletype'} eq 'course'))) {
1.1 raeburn 1795: push(@cols,'status');
1796: }
1797: if ($context eq 'course') {
1798: push(@cols,'groups');
1799: }
1800: push(@cols,'email');
1801:
1.4 raeburn 1802: my $rolefilter = $env{'form.showrole'};
1.5 raeburn 1803: if ($env{'form.showrole'} eq 'cr') {
1804: $rolefilter = &mt('custom');
1805: } elsif ($env{'form.showrole'} ne 'Any') {
1.2 raeburn 1806: $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'});
1807: }
1808: my $results_description = &results_header_row($rolefilter,$statusmode,
1809: $context);
1.3 raeburn 1810: $r->print('<b>'.$results_description.'</b><br />');
1.4 raeburn 1811: my $output;
1.1 raeburn 1812: if ($mode eq 'html' || $mode eq 'view') {
1813: $r->print(<<END);
1814: <input type="hidden" name="sname" value="" />
1815: <input type="hidden" name="sdom" value="" />
1816: END
1.4 raeburn 1817: if ($linkto eq 'aboutme') {
1818: $output = &mt("Select a user name to view the user's personal page.");
1819: } elsif ($linkto eq 'modify') {
1820: $output = &mt("Select a user name to modify the user's information");
1821: }
1822: $output .= "\n<p>\n".
1.1 raeburn 1823: &Apache::loncommon::start_data_table().
1.4 raeburn 1824: &Apache::loncommon::start_data_table_header_row();
1.1 raeburn 1825: if ($mode eq 'autoenroll') {
1.4 raeburn 1826: $output .= "
1.1 raeburn 1827: <th><a href=\"javascript:document.studentform.sortby.value='type';document.studentform.submit();\">$lt{'type'}</a></th>
1.4 raeburn 1828: ";
1.1 raeburn 1829: } else {
1.4 raeburn 1830: $output .= "
1.1 raeburn 1831: <th>Count</th>
1.4 raeburn 1832: ";
1.1 raeburn 1833: }
1834: foreach my $item (@cols) {
1.4 raeburn 1835: $output .= "<th><a href=\"javascript:document.studentform.sortby.value='$item';document.studentform.submit();\">$lt{$item}</a></th>\n";
1.1 raeburn 1836: }
1.2 raeburn 1837: my %role_types = &role_type_names();
1.1 raeburn 1838: if ($context eq 'course') {
1.4 raeburn 1839: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
1840: # Clicker display on or off?
1841: my %clicker_options = &Apache::lonlocal::texthash(
1842: 'on' => 'Show',
1843: 'off' => 'Hide',
1844: );
1845: my $clickerchg = 'on';
1846: if ($displayclickers eq 'on') {
1847: $clickerchg = 'off';
1848: }
1849: $output .= ' <th>'."\n".' '.
1850: '<a href="javascript:document.studentform.displayclickers.value='.
1.1 raeburn 1851: "'".$clickerchg."'".';document.studentform.submit();">'.
1852: $clicker_options{$clickerchg}.'</a> '.$lt{'clicker'}."\n".
1.4 raeburn 1853: ' </th>'."\n";
1.1 raeburn 1854:
1.4 raeburn 1855: # Photo display on or off?
1856: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
1857: my %photo_options = &Apache::lonlocal::texthash(
1858: 'on' => 'Show',
1859: 'off' => 'Hide',
1860: );
1861: my $photochg = 'on';
1862: if ($displayphotos eq 'on') {
1863: $photochg = 'off';
1864: }
1865: $output .= ' <th>'."\n".' '.
1866: '<a href="javascript:document.studentform.displayphotos.value='.
1.1 raeburn 1867: "'".$photochg."'".';document.studentform.submit();">'.
1868: $photo_options{$photochg}.'</a> '.$lt{'photo'}."\n".
1.4 raeburn 1869: ' </th>'."\n";
1870: }
1.1 raeburn 1871: }
1.4 raeburn 1872: $output .= &Apache::loncommon::end_data_table_header_row();
1873: }
1.1 raeburn 1874: # Done with the HTML header line
1875: } elsif ($mode eq 'csv') {
1876: #
1877: # Open a file
1878: $CSVfilename = '/prtspool/'.
1.2 raeburn 1879: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1880: time.'_'.rand(1000000000).'.csv';
1.1 raeburn 1881: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
1882: $r->log_error("Couldn't open $CSVfilename for output $!");
1883: $r->print("Problems occured in writing the csv file. ".
1884: "This error has been logged. ".
1885: "Please alert your LON-CAPA administrator.");
1886: $CSVfile = undef;
1887: }
1888: #
1889: # Write headers and data to file
1.2 raeburn 1890: print $CSVfile '"'.$results_description.'"'."\n";
1.1 raeburn 1891: print $CSVfile '"'.join('","',map {
1892: &Apache::loncommon::csv_translate($lt{$_})
1893: } (@cols)).'"'."\n";
1894: } elsif ($mode eq 'excel') {
1895: # Create the excel spreadsheet
1896: ($excel_workbook,$excel_filename,$format) =
1897: &Apache::loncommon::create_workbook($r);
1898: return if (! defined($excel_workbook));
1899: $excel_sheet = $excel_workbook->addworksheet('userlist');
1.2 raeburn 1900: $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
1.1 raeburn 1901: #
1902: my @colnames = map {$lt{$_}} (@cols);
1903: $excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
1904: }
1905:
1906: # Done with header lines in all formats
1907:
1908: my %index;
1909: my $i;
1.2 raeburn 1910: foreach my $idx (@$keylist) {
1911: $index{$idx} = $i++;
1912: }
1.4 raeburn 1913: my $usercount = 0;
1.2 raeburn 1914: # Get groups, role, permanent e-mail so we can sort on them if
1915: # necessary.
1916: foreach my $user (keys(%{$userlist})) {
1917: my ($uname,$udom,$role,$groups,$email);
1.5 raeburn 1918: if (($statusmode ne 'Any') &&
1919: ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
1920: delete($userlist->{$user});
1921: next;
1922: }
1.2 raeburn 1923: if ($context eq 'domain') {
1924: if ($env{'form.roletype'} eq 'domain') {
1925: ($role,$uname,$udom) = split(/:/,$user);
1926:
1927: } elsif ($env{'form.roletype'} eq 'construction_space') {
1928: ($uname,$udom,$role) = split(/:/,$user,-1);
1929: } elsif ($env{'form.roletype'} eq 'course') {
1930: ($uname,$udom,$role) = split(/:/,$user);
1931: }
1932: } else {
1933: ($uname,$udom,$role) = split(/:/,$user,-1);
1934: if (($context eq 'course') && $role eq '') {
1935: $role = 'st';
1936: }
1937: }
1938: $userlist->{$user}->[$index{'role'}] = $role;
1939: if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
1940: delete($userlist->{$user});
1941: next;
1942: }
1943: if (ref($classgroups) eq 'HASH') {
1944: $groups = $classgroups->{$user};
1945: }
1946: if (ref($groups->{active}) eq 'HASH') {
1947: $userlist->{$user}->[$index{'groups'}] = join(', ',keys(%{$groups->{'active'}}));
1948: }
1949: my %emails = &Apache::loncommon::getemails($uname,$udom);
1950: if ($emails{'permanentemail'} =~ /\S/) {
1951: $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
1952: }
1.4 raeburn 1953: $usercount ++;
1954: }
1955: my $autocount = 0;
1956: my $manualcount = 0;
1957: my $lockcount = 0;
1958: my $unlockcount = 0;
1959: if ($usercount) {
1960: $r->print($output);
1961: } else {
1962: if ($mode eq 'autoenroll') {
1963: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
1964: } else {
1965: return;
1966: }
1.1 raeburn 1967: }
1.2 raeburn 1968: #
1969: # Sort the users
1.1 raeburn 1970: my $index = $index{$sortby};
1971: my $second = $index{'username'};
1972: my $third = $index{'domain'};
1.2 raeburn 1973: my @sorted_users = sort {
1974: lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index])
1.1 raeburn 1975: ||
1.2 raeburn 1976: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
1977: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
1978: } (keys(%$userlist));
1.4 raeburn 1979: my $rowcount = 0;
1.2 raeburn 1980: foreach my $user (@sorted_users) {
1.4 raeburn 1981: my %in;
1.2 raeburn 1982: my $sdata = $userlist->{$user};
1.4 raeburn 1983: $rowcount ++;
1.2 raeburn 1984: foreach my $item (@{$keylist}) {
1985: $in{$item} = $sdata->[$index{$item}];
1986: }
1987: $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}]);
1988: if (! defined($in{'start'}) || $in{'start'} == 0) {
1989: $in{'start'} = &mt('none');
1990: } else {
1991: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
1.1 raeburn 1992: }
1.2 raeburn 1993: if (! defined($in{'end'}) || $in{'end'} == 0) {
1994: $in{'end'} = &mt('none');
1.1 raeburn 1995: } else {
1.2 raeburn 1996: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
1.1 raeburn 1997: }
1.2 raeburn 1998: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
1999: $r->print(&Apache::loncommon::start_data_table_row());
1.4 raeburn 2000: $r->print("<td>$rowcount</td>\n");
1.2 raeburn 2001: if ($linkto eq 'aboutme') {
2002: $in{'username'} =
2003: &Apache::loncommon::aboutmewrapper($in{'username'},
2004: $in{'username'},
2005: $in{'domain'});
2006: } elsif ($linkto eq 'modify') {
2007: $in{'username'} = '<a href="'.
2008: "javascript:document.studentform.sname.value='".
2009: $in{'username'}.
2010: "';document.studentform.sdom.value='".$in{'domain'}.
2011: "';document.studentform.state.value='selected".
2012: "';document.studentform.submit();".'">'.
2013: $in{'username'}."</a>\n";
2014: }
2015: foreach my $item (@cols) {
2016: $r->print('<td>'.$in{$item}.'</td>'."\n");
2017: }
2018: if ($context eq 'course') {
1.4 raeburn 2019: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
2020: if ($displayclickers eq 'on') {
2021: my $clickers =
1.2 raeburn 2022: (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
1.4 raeburn 2023: if ($clickers!~/\w/) { $clickers='-'; }
2024: $r->print('<td>'.$clickers.'</td>');
1.2 raeburn 2025: } else {
2026: $r->print(' <td> </td> ');
2027: }
1.4 raeburn 2028: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
2029: if ($displayphotos eq 'on' && $sdata->[$index{'role'}] eq 'st') {
2030: my $imgurl =
2031: &Apache::lonnet::retrievestudentphoto($in{'domain'},$in{'username'},
2032: 'gif','thumbnail');
2033: $r->print(' <td align="right"><a href="javascript:photowindow('."'".&Apache::lonnet::studentphoto($in{'domain'},$in{'username'},'jpg')."'".')"><img src="'.$imgurl.'" border="1"></a></td>');
2034: } else {
2035: $r->print(' <td> </td> ');
2036: }
2037: }
1.2 raeburn 2038: }
2039: }
2040: $r->print(&Apache::loncommon::end_data_table_row());
2041: } elsif ($mode eq 'csv') {
2042: next if (! defined($CSVfile));
2043: # no need to bother with $linkto
2044: if (! defined($in{'start'}) || $in{'start'} == 0) {
2045: $in{'start'} = &mt('none');
2046: } else {
2047: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
2048: }
2049: if (! defined($in{'end'}) || $in{'end'} == 0) {
2050: $in{'end'} = &mt('none');
2051: } else {
2052: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
2053: }
2054: my @line = ();
2055: foreach my $item (@cols) {
2056: push @line,&Apache::loncommon::csv_translate($in{$item});
2057: }
2058: print $CSVfile '"'.join('","',@line).'"'."\n";
2059: } elsif ($mode eq 'excel') {
2060: my $col = 0;
2061: foreach my $item (@cols) {
2062: if ($item eq 'start' || $item eq 'end') {
2063: if (defined($item) && $item != 0) {
2064: $excel_sheet->write($row,$col++,
2065: &Apache::lonstathelpers::calc_serial($in{item}),
2066: $format->{'date'});
2067: } else {
2068: $excel_sheet->write($row,$col++,'none');
2069: }
2070: } else {
2071: $excel_sheet->write($row,$col++,$in{$item});
2072: }
2073: }
2074: $row++;
1.1 raeburn 2075: }
2076: }
1.2 raeburn 2077: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
2078: $r->print(&Apache::loncommon::end_data_table().'<br />');
2079: } elsif ($mode eq 'excel') {
2080: $excel_workbook->close();
2081: $r->print('<p><a href="'.$excel_filename.'">'.
2082: &mt('Your Excel spreadsheet').'</a> '.&mt('is ready for download').'.</p>'."\n");
2083: } elsif ($mode eq 'csv') {
2084: close($CSVfile);
2085: $r->print('<a href="'.$CSVfilename.'">'.
2086: &mt('Your CSV file').'</a> is ready for download.'.
2087: "\n");
2088: $r->rflush();
2089: }
2090: if ($mode eq 'autoenroll') {
2091: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
1.4 raeburn 2092: } else {
2093: return ($usercount);
1.2 raeburn 2094: }
1.1 raeburn 2095: }
2096:
1.2 raeburn 2097: sub role_type_names {
2098: my %lt = &Apache::lonlocal::texthash (
2099: 'domain' => 'Domain Roles',
2100: 'construction_space' => 'Co-Author Roles',
2101: 'course' => 'Course Roles',
2102: );
2103: return %lt;
2104: }
2105:
2106: sub results_header_row {
2107: my ($rolefilter,$statusmode,$context) = @_;
1.5 raeburn 2108: my ($description,$showfilter);
2109: if ($rolefilter ne 'Any') {
2110: $showfilter = $rolefilter;
2111: }
1.2 raeburn 2112: if ($context eq 'course') {
1.3 raeburn 2113: $description = &mt('Course - ').$env{'course.'.$env{'request.course.id'}.'.description'}.': ';
1.2 raeburn 2114: if ($statusmode eq 'Expired') {
1.5 raeburn 2115: $description .= &mt('Users in course with expired [_1] roles',$showfilter);
1.2 raeburn 2116: }
2117: if ($statusmode eq 'Future') {
1.5 raeburn 2118: $description .= &mt('Users in course with future [_1] roles',$showfilter);
1.2 raeburn 2119: } elsif ($statusmode eq 'Active') {
1.5 raeburn 2120: $description .= &mt('Users in course with active [_1] roles',$showfilter);
1.2 raeburn 2121: } else {
2122: if ($rolefilter eq 'Any') {
2123: $description .= &mt('All users in course');
2124: } else {
2125: $description .= &mt('All users in course with [_1] roles',$rolefilter);
2126: }
2127: }
2128: } elsif ($context eq 'construction_space') {
2129: $description = &mt('Author space for [_1].').' ';
2130: if ($statusmode eq 'Expired') {
1.5 raeburn 2131: $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
1.2 raeburn 2132: } elsif ($statusmode eq 'Future') {
1.5 raeburn 2133: $description .= &mt('Co-authors with future [_1] roles',$showfilter);
1.2 raeburn 2134: } elsif ($statusmode eq 'Active') {
1.5 raeburn 2135: $description .= &mt('Co-authors with active [_1] roles',$showfilter);
1.2 raeburn 2136: } else {
2137: if ($rolefilter eq 'Any') {
1.5 raeburn 2138: $description .= &mt('All co-authors');
1.2 raeburn 2139: } else {
2140: $description .= &mt('All co-authors with [_1] roles',$rolefilter);
2141: }
2142: }
2143: } elsif ($context eq 'domain') {
2144: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
2145: $description = &mt('Domain - ').$domdesc.': ';
2146: if ($env{'form.roletype'} eq 'domain') {
2147: if ($statusmode eq 'Expired') {
1.5 raeburn 2148: $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
1.2 raeburn 2149: } elsif ($statusmode eq 'Future') {
1.5 raeburn 2150: $description .= &mt('Users in domain with future [_1] roles',$showfilter);
1.2 raeburn 2151: } elsif ($statusmode eq 'Active') {
1.5 raeburn 2152: $description .= &mt('Users in domain with active [_1] roles',$showfilter);
1.2 raeburn 2153: } else {
2154: if ($rolefilter eq 'Any') {
1.5 raeburn 2155: $description .= &mt('All users in domain');
1.2 raeburn 2156: } else {
2157: $description .= &mt('All users in domain with [_1] roles',$rolefilter);
2158: }
2159: }
2160: } elsif ($env{'form.roletype'} eq 'construction_space') {
2161: if ($statusmode eq 'Expired') {
1.5 raeburn 2162: $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
1.2 raeburn 2163: } elsif ($statusmode eq 'Future') {
1.5 raeburn 2164: $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
1.2 raeburn 2165: } elsif ($statusmode eq 'Active') {
1.5 raeburn 2166: $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
1.2 raeburn 2167: } else {
2168: if ($rolefilter eq 'Any') {
1.5 raeburn 2169: $description .= &mt('All users with co-author roles in domain',$showfilter);
1.2 raeburn 2170: } else {
2171: $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
2172: }
2173: }
2174: } elsif ($env{'form.roletype'} eq 'course') {
2175: my $coursefilter = $env{'form.coursepick'};
2176: if ($coursefilter eq 'category') {
2177: my $instcode = &instcode_from_coursefilter();
2178: if ($instcode eq '.') {
2179: $description .= &mt('All courses in domain').' - ';
2180: } else {
2181: $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
2182: }
2183: } elsif ($coursefilter eq 'selected') {
2184: $description .= &mt('Selected courses in domain').' - ';
2185: } elsif ($coursefilter eq 'all') {
2186: $description .= &mt('All courses in domain').' - ';
2187: }
2188: if ($statusmode eq 'Expired') {
1.5 raeburn 2189: $description .= &mt('users with expired [_1] roles',$showfilter);
1.2 raeburn 2190: } elsif ($statusmode eq 'Future') {
1.5 raeburn 2191: $description .= &mt('users with future [_1] roles',$showfilter);
1.2 raeburn 2192: } elsif ($statusmode eq 'Active') {
1.5 raeburn 2193: $description .= &mt('users with active [_1] roles',$showfilter);
1.2 raeburn 2194: } else {
2195: if ($rolefilter eq 'Any') {
2196: $description .= &mt('all users');
2197: } else {
2198: $description .= &mt('users with [_1] roles',$rolefilter);
2199: }
2200: }
2201: }
2202: }
2203: return $description;
2204: }
2205:
1.1 raeburn 2206: #################################################
2207: #################################################
2208: sub show_drop_list {
2209: my ($r,$classlist,$keylist,$nosort)=@_;
2210: my $cid=$env{'request.course.id'};
2211: if (! exists($env{'form.sortby'})) {
2212: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2213: ['sortby']);
2214: }
2215: my $sortby = $env{'form.sortby'};
2216: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
2217: $sortby = 'username';
2218: }
2219: my $cdom = $env{'course.'.$cid.'.domain'};
2220: my $cnum = $env{'course.'.$cid,'.num'};
2221: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
2222: $classlist,$keylist,$cdom,$cnum);
2223: #
2224: my $action = "drop";
2225: $r->print(<<END);
2226: <input type="hidden" name="sortby" value="$sortby" />
2227: <input type="hidden" name="action" value="$action" />
2228: <input type="hidden" name="state" value="done" />
2229: <script>
2230: function checkAll(field) {
2231: for (i = 0; i < field.length; i++)
2232: field[i].checked = true ;
2233: }
2234:
2235: function uncheckAll(field) {
2236: for (i = 0; i < field.length; i++)
2237: field[i].checked = false ;
2238: }
2239: </script>
2240: <p>
2241: <input type="hidden" name="phase" value="four">
2242: END
2243:
2244: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
2245: 'dom' => "domain",
2246: 'sn' => "student name",
2247: 'sec' => "section",
2248: 'start' => "start date",
2249: 'end' => "end date",
2250: 'groups' => "active groups",
2251: );
2252: if ($nosort) {
2253: $r->print(&Apache::loncommon::start_data_table());
2254: $r->print(<<END);
2255: <tr>
2256: <th> </th>
2257: <th>$lt{'usrn'}</th>
2258: <th>$lt{'dom'}</th>
2259: <th>ID</th>
2260: <th>$lt{'sn'}</th>
2261: <th>$lt{'sec'}</th>
2262: <th>$lt{'start'}</th>
2263: <th>$lt{'end'}</th>
2264: <th>$lt{'groups'}</th>
2265: </tr>
2266: END
2267:
2268: } else {
2269: $r->print(&Apache::loncommon::start_data_table());
2270: $r->print(<<END);
2271: <tr><th> </th>
2272: <th>
2273: <a href="/adm/dropadd?action=$action&sortby=username">$lt{'usrn'}</a>
2274: </th><th>
2275: <a href="/adm/dropadd?action=$action&sortby=domain">$lt{'dom'}</a>
2276: </th><th>
2277: <a href="/adm/dropadd?action=$action&sortby=id">ID</a>
2278: </th><th>
2279: <a href="/adm/dropadd?action=$action&sortby=fullname">$lt{'sn'}</a>
2280: </th><th>
2281: <a href="/adm/dropadd?action=$action&sortby=section">$lt{'sec'}</a>
2282: </th><th>
2283: <a href="/adm/dropadd?action=$action&sortby=start">$lt{'start'}</a>
2284: </th><th>
2285: <a href="/adm/dropadd?action=$action&sortby=end">$lt{'end'}</a>
2286: </th><th>
2287: <a href="/adm/dropadd?action=$action&sortby=groups">$lt{'groups'}</a>
2288: </th>
2289: </tr>
2290: END
2291: }
2292: #
2293: # Sort the students
2294: my %index;
2295: my $i;
2296: foreach (@$keylist) {
2297: $index{$_} = $i++;
2298: }
2299: $index{'groups'} = scalar(@$keylist);
2300: my $index = $index{$sortby};
2301: my $second = $index{'username'};
2302: my $third = $index{'domain'};
2303: my @Sorted_Students = sort {
2304: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
2305: ||
2306: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
2307: ||
2308: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
2309: } (keys(%$classlist));
2310: foreach my $student (@Sorted_Students) {
2311: my $error;
2312: my $sdata = $classlist->{$student};
2313: my $username = $sdata->[$index{'username'}];
2314: my $domain = $sdata->[$index{'domain'}];
2315: my $section = $sdata->[$index{'section'}];
2316: my $name = $sdata->[$index{'fullname'}];
2317: my $id = $sdata->[$index{'id'}];
2318: my $start = $sdata->[$index{'start'}];
2319: my $end = $sdata->[$index{'end'}];
2320: my $groups = $classgroups->{$student};
2321: my $active_groups;
2322: if (ref($groups->{active}) eq 'HASH') {
2323: $active_groups = join(', ',keys(%{$groups->{'active'}}));
2324: }
2325: if (! defined($start) || $start == 0) {
2326: $start = &mt('none');
2327: } else {
2328: $start = &Apache::lonlocal::locallocaltime($start);
2329: }
2330: if (! defined($end) || $end == 0) {
2331: $end = &mt('none');
2332: } else {
2333: $end = &Apache::lonlocal::locallocaltime($end);
2334: }
2335: my $status = $sdata->[$index{'status'}];
2336: next if ($status ne 'Active');
2337: #
2338: $r->print(&Apache::loncommon::start_data_table_row());
2339: $r->print(<<"END");
2340: <td><input type="checkbox" name="droplist" value="$student"></td>
2341: <td>$username</td>
2342: <td>$domain</td>
2343: <td>$id</td>
2344: <td>$name</td>
2345: <td>$section</td>
2346: <td>$start</td>
2347: <td>$end</td>
2348: <td>$active_groups</td>
2349: END
2350: $r->print(&Apache::loncommon::end_data_table_row());
2351: }
2352: $r->print(&Apache::loncommon::end_data_table().'<br />');
2353: %lt=&Apache::lonlocal::texthash(
2354: 'dp' => "Expire Users' Roles",
2355: 'ca' => "check all",
2356: 'ua' => "uncheck all",
2357: );
2358: $r->print(<<"END");
2359: </p><p>
2360: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)">
2361: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)">
2362: <p><input type=submit value="$lt{'dp'}"></p>
2363: END
2364: return;
2365: }
2366:
2367: #
2368: # Print out the initial form to get the file containing a list of users
2369: #
2370: sub print_first_users_upload_form {
2371: my ($r,$context) = @_;
2372: my $str;
2373: $str = '<input type="hidden" name="phase" value="two">';
2374: $str .= '<input type="hidden" name="action" value="upload" />';
2375: $str .= '<input type="hidden" name="state" value="got_file" />';
1.2 raeburn 2376: $str .= "<h3>".&mt('Upload a file containing information about users')."</h3>\n";
1.1 raeburn 2377: $str .= &Apache::loncommon::upfile_select_html();
2378: $str .= "<p>\n";
2379: $str .= '<input type="submit" name="fileupload" value="'.
1.2 raeburn 2380: &mt('Upload file of users').'">'."\n";
1.1 raeburn 2381: $str .= '<label><input type="checkbox" name="noFirstLine" /> '.
2382: &mt('Ignore First Line')."</label></p>\n";
2383: $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List",
2384: &mt("How do I create a users list from a spreadsheet")).
2385: "<br />\n";
2386: $str .= &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
2387: &mt("How do I create a CSV file from a spreadsheet")).
2388: "<br />\n";
2389: $str .= &Apache::loncommon::end_page();
2390: $r->print($str);
2391: return;
2392: }
2393:
2394: # ================================================= Drop/Add from uploaded file
2395: sub upfile_drop_add {
2396: my ($r,$context) = @_;
2397: &Apache::loncommon::load_tmp_file($r);
2398: my @userdata=&Apache::loncommon::upfile_record_sep();
2399: if($env{'form.noFirstLine'}){shift(@userdata);}
2400: my @keyfields = split(/\,/,$env{'form.keyfields'});
2401: my %fields=();
2402: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
2403: if ($env{'form.upfile_associate'} eq 'reverse') {
2404: if ($env{'form.f'.$i} ne 'none') {
2405: $fields{$keyfields[$i]}=$env{'form.f'.$i};
2406: }
2407: } else {
2408: $fields{$env{'form.f'.$i}}=$keyfields[$i];
2409: }
2410: }
2411: #
2412: # Store the field choices away
2413: foreach my $field (qw/username names
2414: fname mname lname gen id sec ipwd email role/) {
2415: $env{'form.'.$field.'_choice'}=$fields{$field};
2416: }
2417: &Apache::loncommon::store_course_settings('enrollment_upload',
2418: { 'username_choice' => 'scalar',
2419: 'names_choice' => 'scalar',
2420: 'fname_choice' => 'scalar',
2421: 'mname_choice' => 'scalar',
2422: 'lname_choice' => 'scalar',
2423: 'gen_choice' => 'scalar',
2424: 'id_choice' => 'scalar',
2425: 'sec_choice' => 'scalar',
2426: 'ipwd_choice' => 'scalar',
2427: 'email_choice' => 'scalar',
2428: 'role_choice' => 'scalar' });
2429: #
2430: my ($startdate,$enddate) = &get_dates_from_form();
2431: if ($env{'form.makedatesdefault'}) {
2432: $r->print(&make_dates_default($startdate,$enddate));
2433: }
2434: # Determine domain and desired host (home server)
2435: my $domain=$env{'request.role.domain'};
2436: my $desiredhost = $env{'form.lcserver'};
2437: if (lc($desiredhost) eq 'default') {
2438: $desiredhost = undef;
2439: } else {
2440: my %home_servers = &Apache::lonnet::get_servers($domain,'library');
2441: if (! exists($home_servers{$desiredhost})) {
2442: $r->print('<span class="LC_error">'.&mt('Error').
2443: &mt('Invalid home server specified').'</span>');
2444: $r->print(&Apache::loncommon::end_page());
2445: return;
2446: }
2447: }
2448: # Determine authentication mechanism
2449: my $changeauth;
2450: if ($context eq 'domain') {
2451: $changeauth = $env{'form.changeauth'};
2452: }
2453: my $amode = '';
2454: my $genpwd = '';
2455: if ($env{'form.login'} eq 'krb') {
2456: $amode='krb';
2457: $amode.=$env{'form.krbver'};
2458: $genpwd=$env{'form.krbarg'};
2459: } elsif ($env{'form.login'} eq 'int') {
2460: $amode='internal';
2461: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
2462: $genpwd=$env{'form.intarg'};
2463: }
2464: } elsif ($env{'form.login'} eq 'loc') {
2465: $amode='localauth';
2466: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
2467: $genpwd=$env{'form.locarg'};
2468: }
2469: }
2470: if ($amode =~ /^krb/) {
2471: if (! defined($genpwd) || $genpwd eq '') {
2472: $r->print('<span class="Error">'.
2473: &mt('Unable to enroll users').' '.
2474: &mt('No Kerberos domain was specified.').'</span></p>');
2475: $amode = ''; # This causes the loop below to be skipped
2476: }
2477: }
2478: my ($cid,$defaultsec,$defaultrole,$setting);
2479: if ($context eq 'domain') {
2480: $setting = $env{'form.roleaction'};
2481: if ($setting eq 'domain') {
2482: $defaultrole = $env{'form.defaultrole'};
2483: } elsif ($setting eq 'course') {
2484: $defaultrole = $env{'form.courserole'};
2485: }
2486: } elsif ($context eq 'construction_space') {
2487: $defaultrole = $env{'form.defaultrole'};
2488: }
2489: if ($context eq 'domain' && $setting eq 'course') {
2490: if ($env{'form.newsec'} ne '') {
2491: $defaultsec = $env{'form.newsec'};
2492: } elsif ($env{'form.defaultsec'} ne '') {
2493: $defaultsec = $env{'form.defaultsec'}
2494: }
2495: }
2496: if ($env{'request.course.id'} ne '') {
2497: $cid = $env{'request.course.id'};
2498: } elsif ($env{'form.defaultdomain'} ne '' && $env{'form.defaultcourse'} ne '') {
2499: $cid = $env{'form.defaultdomain'}.'_'.
2500: $env{'form.defaultcourse'};
2501: }
2502: if ( $domain eq &LONCAPA::clean_domain($domain)
2503: && ($amode ne '')) {
2504: #######################################
2505: ## Add/Modify Users ##
2506: #######################################
2507: if ($context eq 'course') {
2508: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
2509: } elsif ($context eq 'construction_space') {
2510: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
2511: } else {
2512: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
2513: }
2514: my %counts = (
2515: user => 0,
2516: auth => 0,
2517: role => 0,
2518: );
2519: my $flushc=0;
2520: my %student=();
2521: my %curr_groups;
2522: my %userchg;
2523: if ($context eq 'course') {
2524: # Get information about course groups
2525: %curr_groups = &Apache::longroup::coursegroups();
2526: }
1.5 raeburn 2527: my (%curr_rules,%got_rules,%alerts);
1.1 raeburn 2528: # Get new users list
2529: foreach (@userdata) {
2530: my %entries=&Apache::loncommon::record_sep($_);
2531: # Determine user name
2532: unless (($entries{$fields{'username'}} eq '') ||
2533: (!defined($entries{$fields{'username'}}))) {
2534: my ($fname, $mname, $lname,$gen) = ('','','','');
2535: if (defined($fields{'names'})) {
2536: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
2537: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
2538: } else {
2539: if (defined($fields{'fname'})) {
2540: $fname=$entries{$fields{'fname'}};
2541: }
2542: if (defined($fields{'mname'})) {
2543: $mname=$entries{$fields{'mname'}};
2544: }
2545: if (defined($fields{'lname'})) {
2546: $lname=$entries{$fields{'lname'}};
2547: }
2548: if (defined($fields{'gen'})) {
2549: $gen=$entries{$fields{'gen'}};
2550: }
2551: }
2552: if ($entries{$fields{'username'}}
2553: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
2554: $r->print('<br />'.
2555: &mt('<b>[_1]</b>: Unacceptable username for user [_2] [_3] [_4] [_5]',
2556: $entries{$fields{'username'}},$fname,$mname,$lname,$gen).
2557: '</b>');
2558: } else {
1.5 raeburn 2559: my $username = $entries{$fields{'username'}};
1.1 raeburn 2560: my $sec;
2561: if ($context eq 'course' || $setting eq 'course') {
2562: # determine section number
2563: if (defined($fields{'sec'})) {
2564: if (defined($entries{$fields{'sec'}})) {
2565: $sec=$entries{$fields{'sec'}};
2566: }
2567: } else {
2568: $sec = $defaultsec;
2569: }
2570: # remove non alphanumeric values from section
2571: $sec =~ s/\W//g;
2572: if ($sec eq "none" || $sec eq 'all') {
2573: $r->print('<br />'.
2574: &mt('<b>[_1]</b>: Unable to enroll: section name "[_2]" for user [_3] [_4] [_5] [_6] is a reserved word.',
2575: $username,$sec,$fname,$mname,$lname,$gen));
2576: next;
2577: } elsif (($sec ne '') && (exists($curr_groups{$sec}))) {
2578: $r->print('<br />'.
2579: &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.',
2580: $username,$sec,$fname,$mname,$lname,$gen));
2581: next;
2582: }
2583: }
2584: # determine id number
2585: my $id='';
2586: if (defined($fields{'id'})) {
2587: if (defined($entries{$fields{'id'}})) {
2588: $id=$entries{$fields{'id'}};
2589: }
2590: $id=~tr/A-Z/a-z/;
2591: }
2592: # determine email address
2593: my $email='';
2594: if (defined($fields{'email'})) {
2595: if (defined($entries{$fields{'email'}})) {
2596: $email=$entries{$fields{'email'}};
2597: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; } }
2598: }
2599: # determine user password
2600: my $password = $genpwd;
2601: if (defined($fields{'ipwd'})) {
2602: if ($entries{$fields{'ipwd'}}) {
2603: $password=$entries{$fields{'ipwd'}};
2604: }
2605: }
2606: # determine user role
2607: my $role = '';
2608: if (defined($fields{'role'})) {
2609: if ($entries{$fields{'role'}}) {
1.2 raeburn 2610: my @poss_roles =
1.1 raeburn 2611: &curr_role_permissions($context,$setting);
1.2 raeburn 2612: if (grep(/^\Q$entries{$fields{'role'}}\E/,@poss_roles)) {
1.1 raeburn 2613: $role=$entries{$fields{'role'}};
2614: } else {
2615: my $rolestr = join(', ',@poss_roles);
2616: $r->print('<br />'.
2617: &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");
2618: next;
2619: }
2620: }
2621: }
2622: if ($role eq '') {
2623: $role = $defaultrole;
2624: }
2625: # Clean up whitespace
2626: foreach (\$domain,\$username,\$id,\$fname,\$mname,
2627: \$lname,\$gen,\$sec,\$role) {
2628: $$_ =~ s/(\s+$|^\s+)//g;
2629: }
1.5 raeburn 2630: # check against rules
2631: my $checkid = 0;
2632: my $newuser = 0;
2633: my (%rulematch,%inst_results,%idinst_results);
2634: my $uhome=&Apache::lonnet::homeserver($username,$domain);
2635: if ($uhome eq 'no_host') {
2636: $checkid = 1;
2637: $newuser = 1;
2638: my $checkhash;
2639: my $checks = { 'username' => 1 };
2640: $checkhash->{$username.':'.$domain} = { 'newuser' => 1, };
2641: &Apache::loncommon::user_rule_check($checkhash,$checks,
2642: \%alerts,\%rulematch,\%inst_results,\%curr_rules,
2643: \%got_rules);
2644: if (ref($alerts{'username'}) eq 'HASH') {
2645: if (ref($alerts{'username'}{$domain}) eq 'HASH') {
2646: next if ($alerts{'username'}{$domain}{$username});
2647: }
2648: }
2649: }
2650: if ($id ne '') {
2651: if (!$newuser) {
2652: my %idhash = &Apache::lonnet::idrget($domain,($username));
2653: if ($idhash{$username} ne $id) {
2654: $checkid = 1;
2655: }
2656: }
2657: if ($checkid) {
2658: my $checkhash;
2659: my $checks = { 'id' => 1 };
2660: $checkhash->{$username.':'.$domain} = { 'newuser' => $newuser,
2661: 'id' => $id };
2662: &Apache::loncommon::user_rule_check($checkhash,$checks,
2663: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,
2664: \%got_rules);
2665: if (ref($alerts{'id'}) eq 'HASH') {
2666: if (ref($alerts{'id'}{$domain}) eq 'HASH') {
2667: next if ($alerts{'id'}{$domain}{$id});
2668: }
2669: }
2670: }
2671: }
1.1 raeburn 2672: if ($password || $env{'form.login'} eq 'loc') {
2673: my ($userresult,$authresult,$roleresult);
2674: if ($role eq 'st') {
2675: &modifystudent($domain,$username,$cid,$sec,
2676: $desiredhost);
2677: $roleresult =
2678: &Apache::lonnet::modifystudent
2679: ($domain,$username,$id,$amode,$password,
2680: $fname,$mname,$lname,$gen,$sec,$enddate,
2681: $startdate,$env{'form.forceid'},
2682: $desiredhost,$email);
2683: } else {
2684: ($userresult,$authresult,$roleresult) =
2685: &modifyuserrole($context,$setting,
2686: $changeauth,$cid,$domain,$username,
2687: $id,$amode,$password,$fname,
2688: $mname,$lname,$gen,$sec,
2689: $env{'form.forceid'},$desiredhost,
1.5 raeburn 2690: $email,$role,$enddate,$startdate,$checkid);
1.1 raeburn 2691: }
2692: $flushc =
2693: &user_change_result($r,$userresult,$authresult,
2694: $roleresult,\%counts,$flushc,
2695: $username,%userchg);
2696: } else {
2697: if ($context eq 'course') {
2698: $r->print('<br />'.
2699: &mt('<b>[_1]</b>: Unable to enroll. No password specified.',$username)
2700: );
2701: } elsif ($context eq 'construction_space') {
2702: $r->print('<br />'.
2703: &mt('<b>[_1]</b>: Unable to add co-author. No password specified.',$username)
2704: );
2705: } else {
2706: $r->print('<br />'.
2707: &mt('<b>[_1]</b>: Unable to add user. No password specified.',$username)
2708: );
2709: }
2710: }
2711: }
2712: }
2713: } # end of foreach (@userdata)
2714: # Flush the course logs so reverse user roles immediately updated
1.5 raeburn 2715: &Apache::lonnet::flushcourselogs();
1.1 raeburn 2716: $r->print("</p>\n<p>\n".&mt('Processed [_1] user(s).',$counts{'user'}).
2717: "</p>\n");
2718: if ($counts{'role'} > 0) {
2719: $r->print("<p>\n".
2720: &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");
2721: }
2722: if ($counts{'auth'} > 0) {
2723: $r->print("<p>\n".
2724: &mt('Authentication changed for [_1] existing users.',
2725: $counts{'auth'})."</p>\n");
2726: }
1.5 raeburn 2727: if (keys(%alerts) > 0) {
2728: if (ref($alerts{'username'}) eq 'HASH') {
2729: foreach my $dom (sort(keys(%{$alerts{'username'}}))) {
2730: my $count;
2731: if (ref($alerts{'username'}{$dom}) eq 'HASH') {
2732: $count = keys(%{$alerts{'username'}{$dom}});
2733: }
2734: my $domdesc = &Apache::lonnet::domain($domain,'description');
2735: if (ref($curr_rules{$dom}) eq 'HASH') {
2736: $r->print(&Apache::loncommon::instrule_disallow_msg(
2737: 'username',$domdesc,$count,'upload'));
2738: }
2739: $r->print(&Apache::loncommon::user_rule_formats($dom,
2740: $domdesc,$curr_rules{$dom}{'username'},
2741: 'username'));
2742: }
2743: }
2744: if (ref($alerts{'id'}) eq 'HASH') {
2745: foreach my $dom (sort(keys(%{$alerts{'id'}}))) {
2746: my $count;
2747: if (ref($alerts{'id'}{$dom}) eq 'HASH') {
2748: $count = keys(%{$alerts{'id'}{$dom}});
2749: }
2750: my $domdesc = &Apache::lonnet::domain($domain,'description');
2751: if (ref($curr_rules{$dom}) eq 'HASH') {
2752: $r->print(&Apache::loncommon::instrule_disallow_msg(
2753: 'id',$domdesc,$count,'upload'));
2754: }
2755: $r->print(&Apache::loncommon::user_rule_formats($dom,
2756: $domdesc,$curr_rules{$dom}{'id'},'id'));
2757: }
2758: }
2759: }
1.1 raeburn 2760: $r->print('<form name="uploadresult" action="/adm/createuser">');
2761: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','prevphase','currstate']));
2762: $r->print('</form>');
2763: #####################################
2764: # Drop students #
2765: #####################################
2766: if ($env{'form.fullup'} eq 'yes') {
2767: $r->print('<h3>'.&mt('Dropping Students')."</h3>\n");
2768: # Get current classlist
2769: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
2770: if (! defined($classlist)) {
2771: $r->print(&mt('There are no students currently enrolled.').
2772: "\n");
2773: } else {
2774: # Remove the students we just added from the list of students.
2775: foreach (@userdata) {
2776: my %entries=&Apache::loncommon::record_sep($_);
2777: unless (($entries{$fields{'username'}} eq '') ||
2778: (!defined($entries{$fields{'username'}}))) {
2779: delete($classlist->{$entries{$fields{'username'}}.
2780: ':'.$domain});
2781: }
2782: }
2783: # Print out list of dropped students.
2784: &show_drop_list($r,$classlist,$keylist,'nosort');
2785: }
2786: }
2787: } # end of unless
2788: }
2789:
2790: sub user_change_result {
2791: my ($r,$userresult,$authresult,$roleresult,$counts,$flushc,$username,
2792: $userchg) = @_;
2793: my $okresult = 0;
2794: if ($userresult ne 'ok') {
2795: if ($userresult =~ /^error:(.+)$/) {
2796: my $error = $1;
2797: $r->print('<br />'.
2798: &mt('<b>[_1]</b>: Unable to add/modify: [_2]',$username,$error));
2799: }
2800: } else {
2801: $counts->{'user'} ++;
2802: $okresult = 1;
2803: }
2804: if ($authresult ne 'ok') {
2805: if ($authresult =~ /^error:(.+)$/) {
2806: my $error = $1;
2807: $r->print('<br />'.
2808: &mt('<b>[_1]</b>: Unable to modify authentication: [_2]',$username,$error));
2809: }
2810: } else {
2811: $counts->{'auth'} ++;
2812: $okresult = 1;
2813: }
2814: if ($roleresult ne 'ok') {
2815: if ($roleresult =~ /^error:(.+)$/) {
2816: my $error = $1;
2817: $r->print('<br />'.
2818: &mt('<b>[_1]</b>: Unable to add role: [_2]',$username,$error));
2819: }
2820: } else {
2821: $counts->{'role'} ++;
2822: $okresult = 1;
2823: }
2824: if ($okresult) {
2825: $flushc++;
2826: $userchg->{$username}=1;
2827: $r->print('. ');
2828: if ($flushc>15) {
2829: $r->rflush;
2830: $flushc=0;
2831: }
2832: }
2833: return $flushc;
2834: }
2835:
2836: # ========================================================= Menu Phase Two Drop
2837: sub print_expire_menu {
2838: my ($r,$context) = @_;
2839: $r->print("<h3>".&mt("Expire Users' Roles")."</h3>");
2840: my $cid=$env{'request.course.id'};
2841: my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
2842: if (! defined($classlist)) {
2843: $r->print(&mt('There are no students currently enrolled.')."\n");
2844: return;
2845: }
2846: # Print out the available choices
2847: &show_drop_list($r,$classlist,$keylist);
2848: return;
2849: }
2850:
2851:
2852: # ================================================================== Phase four
2853:
2854: sub expire_user_list {
2855: my ($r,$context) = @_;
2856: my $count=0;
2857: my @droplist = &Apache::loncommon::get_env_multiple('form.droplist');
2858: foreach (@droplist) {
2859: my ($uname,$udom)=split(/\:/,$_);
2860: # drop student
2861: my $result = &modifystudent($udom,$uname,$env{'request.course.id'});
2862: if ($result eq 'ok' || $result eq 'ok:') {
2863: $r->print(&mt('Dropped [_1]',$uname.'@'.$udom).'<br>');
2864: $count++;
2865: } else {
2866: $r->print(
2867: &mt('Error dropping [_1]:[_2]',$uname.'@'.$udom,$result).
2868: '<br />');
2869: }
2870: }
2871: $r->print('<p><b>'.&mt('Dropped [_1] user(s).',$count).'</b></p>');
2872: $r->print('<p>'.&mt('Re-enrollment will re-activate data.')) if ($count);
2873: }
2874:
2875: sub section_check_js {
2876: my $groupslist;
2877: my %curr_groups = &Apache::longroup::coursegroups();
2878: if (%curr_groups) {
2879: $groupslist = join('","',sort(keys(%curr_groups)));
2880: }
2881: return <<"END";
2882: function validate(caller) {
2883: var groups = new Array("$groupslist");
2884: var secname = caller.value;
2885: if ((secname == 'all') || (secname == 'none')) {
2886: alert("'"+secname+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
2887: return 'error';
2888: }
2889: if (secname != '') {
2890: for (var k=0; k<groups.length; k++) {
2891: if (secname == groups[k]) {
2892: 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.");
2893: return 'error';
2894: }
2895: }
2896: }
2897: return 'ok';
2898: }
2899: END
2900: }
2901:
2902: sub set_login {
2903: my ($dom,$authformkrb,$authformint,$authformloc) = @_;
2904: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2905: my $response;
2906: my ($authnum,%can_assign) =
2907: &Apache::loncommon::get_assignable_auth($dom);
2908: if ($authnum) {
2909: $response = &Apache::loncommon::start_data_table();
2910: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2911: $response .= &Apache::loncommon::start_data_table_row().
2912: '<td>'.$authformkrb.'</td>'.
2913: &Apache::loncommon::end_data_table_row()."\n";
2914: }
2915: if ($can_assign{'int'}) {
2916: $response .= &Apache::loncommon::start_data_table_row().
2917: '<td>'.$authformint.'</td>'.
2918: &Apache::loncommon::end_data_table_row()."\n"
2919: }
2920: if ($can_assign{'loc'}) {
2921: $response .= &Apache::loncommon::start_data_table_row().
2922: '<td>'.$authformloc.'</td>'.
2923: &Apache::loncommon::end_data_table_row()."\n";
2924: }
2925: $response .= &Apache::loncommon::end_data_table();
2926: }
2927: return $response;
2928: }
2929:
2930: 1;
2931:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>