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