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