File:
[LON-CAPA] /
loncom /
interface /
lonuserutils.pm
Revision
1.16:
download - view:
text,
annotated -
select for diffs
Fri Dec 14 00:20:53 2007 UTC (16 years, 8 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
&authorpriv() and &get_permission() moved from loncreateuser.pm to lonuserutils.pm to be more generally available.
- classlist display in Autoenrollment Manager (used for locking/unlocking users and/or toggling user type between auto and manual) now uses lonuserutils::show_users_list().
lonpopulate.pm
- link in breadcrumb trail to dropadd replaced with createuser
- style
- localization
- tables displaying result of auto/manual lock/unlock changes for student enrollments use loncommon::start_date_table* and end_data_table*
1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
4: # $Id: lonuserutils.pm,v 1.16 2007/12/14 00:20:53 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ###############################################################
30:
31: package Apache::lonuserutils;
32:
33: use strict;
34: use Apache::lonnet;
35: use Apache::loncommon();
36: use Apache::lonhtmlcommon;
37: use Apache::lonlocal;
38: use Apache::longroup;
39: use LONCAPA qw(:DEFAULT :match);
40:
41: ###############################################################
42: ###############################################################
43: # Drop student from all sections of a course, except optional $csec
44: sub modifystudent {
45: my ($udom,$unam,$courseid,$csec,$desiredhost)=@_;
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,
89: $end,$start,$checkid) = @_;
90: my ($scope,$userresult,$authresult,$roleresult,$idresult);
91: if ($setting eq 'course' || $context eq 'course') {
92: $scope = '/'.$cid;
93: $scope =~ s/\_/\//g;
94: if ($role ne 'cc' && $sec ne '') {
95: $scope .='/'.$sec;
96: }
97: } elsif ($context eq 'domain') {
98: $scope = '/'.$env{'request.role.domain'}.'/';
99: } elsif ($context eq 'author') {
100: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
101: }
102: if ($context eq 'domain') {
103: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
104: if ($uhome ne 'no_host') {
105: if (($changeauth eq 'Yes') && (&Apache::lonnet::allowed('mau',$udom))) {
106: if ((($umode =~ /^krb4|krb5|internal$/) && $upass ne '') ||
107: ($umode eq 'localauth')) {
108: $authresult = &Apache::lonnet::modifyuserauth($udom,$uname,$umode,$upass);
109: }
110: }
111: if (($forceid) && (&Apache::lonnet::allowed('mau',$udom)) &&
112: ($env{'form.recurseid'}) && ($checkid)) {
113: my %userupdate = (
114: lastname => $last,
115: middlename => $middle,
116: firstname => $first,
117: generation => $gene,
118: id => $uid,
119: );
120: $idresult = &propagate_id_change($uname,$udom,\%userupdate);
121: }
122: }
123: }
124: $userresult =
125: &Apache::lonnet::modifyuser($udom,$uname,$uid,$umode,$upass,$first,
126: $middle,$last,$gene,$forceid,$desiredhome,
127: $email,$role,$start,$end);
128: if ($userresult eq 'ok') {
129: if ($role ne '') {
130: $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
131: $role,$end,$start);
132: }
133: }
134: return ($userresult,$authresult,$roleresult,$idresult);
135: }
136:
137: sub propagate_id_change {
138: my ($uname,$udom,$user) = @_;
139: my (@types,@roles);
140: @types = ('active','future');
141: @roles = ('st');
142: my $idresult;
143: my %roleshash = &Apache::lonnet::get_my_roles($uname,
144: $udom,'userroles',\@types,\@roles);
145: my %args = (
146: one_time => 1,
147: );
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)) {
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: }
159: if ($result eq 'ok') {
160: $idresult .= &mt('Classlist update for "[_1]" in "[_2]".',$uname.':'.$udom,$cdesc).'<br />'."\n";
161: } else {
162: $idresult .= &mt('Error: "[_1]" during classlist update for "[_2]" in "[_3]".',$result,$uname.':'.$udom,$cdesc).'<br />'."\n";
163: }
164: }
165: }
166: return $idresult;
167: }
168:
169: sub update_classlist {
170: my ($cdom,$cnum,$udom,$uname,$user) = @_;
171: my ($uid,$classlistentry);
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:
206: ###############################################################
207: ###############################################################
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','author','course');
215: my %lt = &role_type_names();
216: #
217: # build up the menu information to be passed to
218: # &Apache::loncommon::linked_select_forms
219: my %select_menus;
220: if ($env{'form.roletype'} eq '') {
221: $env{'form.roletype'} = 'domain';
222: }
223: foreach my $roletype (@roletypes) {
224: # set up the text for this domain
225: $select_menus{$roletype}->{'text'}= $lt{$roletype};
226: # we want a choice of 'default' as the default in the second menu
227: if ($env{'form.roletype'} ne '') {
228: $select_menus{$roletype}->{'default'} = $env{'form.showrole'};
229: } else {
230: $select_menus{$roletype}->{'default'} = 'Any';
231: }
232: # Now build up the other items in the second menu
233: my @roles;
234: if ($roletype eq 'domain') {
235: @roles = &domain_roles();
236: } elsif ($roletype eq 'author') {
237: @roles = &construction_space_roles();
238: } else {
239: @roles = &course_roles('domain');
240: unshift(@roles,'cr');
241: }
242: my $order = ['Any',@roles];
243: $select_menus{$roletype}->{'order'} = $order;
244: foreach my $role (@roles) {
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: }
252: }
253: $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
254: }
255: my $result = &Apache::loncommon::linked_select_forms
256: ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
257: 'roletype','showrole',\%select_menus,['domain','author','course']);
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 'author') {
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 'author') {
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 />';
724: my ($options,$cb_script,$coursepick) = &default_role_selector($context,'defaultrole',1);
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;
727: } elsif ($context eq 'author') {
728: $Str .= $options;
729: } else {
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>';
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: }
740: if ($context eq 'course' || $context eq 'domain') {
741: $Str .= &forceid_change($context);
742: }
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:
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 Active/Future student,<br />(if forcing change).').
767: '</label></p>'."\n";
768: }
769: return $output;
770: }
771:
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 {
857: my ($starttime,$endtime,$mode,$nolink) = @_;
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: }
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:
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 {
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);
924: my $dateDefault;
925: if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
926: $dateDefault = ' ';
927: } elsif ($mode ne 'author' && $mode ne 'domain') {
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: }
936: }
937: my $perpetual = '<span class="LC_nobreak"><label><input type="checkbox" name="no_end_date"';
938: if (defined($endtime) && $endtime == 0) {
939: $perpetual .= ' checked';
940: }
941: $perpetual.= ' /> '.&mt('no ending date').'</label></span>';
942: if ($mode eq 'create_enrolldates') {
943: $perpetual = ' ';
944: }
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 />';
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') {
971: $result .= &mt('Set default start and end dates for course').
972: '<br />'."\n";
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 {
986: my ($context,$checkpriv) = @_;
987: my %customroles;
988: my ($options,$coursepick,$cb_jscript);
989: if ($context ne 'author') {
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') {
1002: $options .= &default_course_roles($context,$checkpriv,%customroles);
1003: } elsif ($context eq 'author') {
1004: my @roles = &construction_space_roles($checkpriv);
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') {
1010: my @roles = &domain_roles($checkpriv);
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".
1027: &default_course_roles($context,$checkpriv,%customroles)."\n".
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 {
1049: my ($context,$checkpriv,%customroles) = @_;
1050: my $output;
1051: my @roles = &course_roles($context,$checkpriv);
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) {
1057: my %customroles = &my_custom_roles();
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 {
1068: my ($checkpriv) = @_;
1069: my @allroles = ('ca','aa');
1070: my @roles;
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: }
1076: }
1077: return @roles;
1078: } else {
1079: return @allroles;
1080: }
1081: }
1082:
1083: sub domain_roles {
1084: my ($checkpriv) = @_;
1085: my @allroles = ('dc','li','dg','au','sc');
1086: my @roles;
1087: if ($checkpriv) {
1088: foreach my $role (@allroles) {
1089: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
1090: push(@roles,$role);
1091: }
1092: }
1093: return @roles;
1094: } else {
1095: return @allroles;
1096: }
1097: }
1098:
1099: sub course_roles {
1100: my ($context,$checkpriv) = @_;
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'}) {
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: }
1118: }
1119: }
1120: }
1121: } else {
1122: @roles = @allroles;
1123: }
1124: }
1125: }
1126: return @roles;
1127: }
1128:
1129: sub curr_role_permissions {
1130: my ($context,$setting,$checkpriv) = @_;
1131: my @roles;
1132: if ($context eq 'author') {
1133: @roles = &construction_space_roles($checkpriv);
1134: } elsif ($context eq 'domain') {
1135: if ($setting eq 'course') {
1136: @roles = &course_roles($context,$checkpriv);
1137: } else {
1138: @roles = &domain_roles($checkpriv);
1139: }
1140: } elsif ($context eq 'course') {
1141: @roles = &course_roles($context,$checkpriv);
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:
1159: sub print_userlist {
1160: my ($r,$mode,$permission,$context,$formname,$totcodes,$codetitles,
1161: $idlist,$idlist_titles) = @_;
1162: my $format = $env{'form.output'};
1163: if (! exists($env{'form.sortby'})) {
1164: $env{'form.sortby'} = 'username';
1165: }
1166: if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
1167: $env{'form.Status'} = 'Active';
1168: }
1169: my $status_select = &Apache::lonhtmlcommon::StatusOptions
1170: ($env{'form.Status'});
1171:
1172: if ($env{'form.showrole'} eq '') {
1173: if ($context eq 'course') {
1174: $env{'form.showrole'} = 'st';
1175: } else {
1176: $env{'form.showrole'} = 'Any';
1177: }
1178: }
1179: if (! defined($env{'form.output'}) ||
1180: $env{'form.output'} !~ /^(csv|excel|html)$/ ) {
1181: $env{'form.output'} = 'html';
1182: }
1183:
1184: my @statuses;
1185: if ($env{'form.Status'} eq 'Any') {
1186: @statuses = ('previous','active','future');
1187: } elsif ($env{'form.Status'} eq 'Expired') {
1188: @statuses = ('previous');
1189: } elsif ($env{'form.Status'} eq 'Active') {
1190: @statuses = ('active');
1191: } elsif ($env{'form.Status'} eq 'Future') {
1192: @statuses = ('future');
1193: }
1194:
1195: # if ($context eq 'course') {
1196: # $r->print(&display_adv_courseroles());
1197: # }
1198: #
1199: # Interface output
1200: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
1201: '<input type="hidden" name="action" value="'.
1202: $env{'form.action'}.'" />');
1203: $r->print("<p>\n");
1204: if ($env{'form.action'} ne 'modifystudent') {
1205: my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
1206: 'excel' => "Excel",
1207: 'html' => 'HTML');
1208: my $output_selector = '<select size="1" name="output" >';
1209: foreach my $outputformat ('html','csv','excel') {
1210: my $option = '<option value="'.$outputformat.'" ';
1211: if ($outputformat eq $env{'form.output'}) {
1212: $option .= 'selected ';
1213: }
1214: $option .='>'.$lt{$outputformat}.'</option>';
1215: $output_selector .= "\n".$option;
1216: }
1217: $output_selector .= '</select>';
1218: $r->print('<label>'.&mt('Output Format: [_1]',$output_selector).'</label>'.(' 'x3));
1219: }
1220: $r->print('<label>'.&mt('User Status: [_1]',$status_select).'</label>'.(' 'x3)."\n");
1221: my $roleselected = '';
1222: if ($env{'form.showrole'} eq 'Any') {
1223: $roleselected = ' selected="selected" ';
1224: }
1225: my $role_select;
1226: if ($context eq 'domain') {
1227: $role_select = &domain_roles_select();
1228: $r->print('<label>'.&mt('Role Type: [_1]',$role_select).'</label>');
1229: } else {
1230: $role_select = '<select name="showrole">'."\n".
1231: '<option value="Any" '.$roleselected.'>'.
1232: &mt('Any role').'</option>';
1233: my @poss_roles = &curr_role_permissions($context);
1234: foreach my $role (@poss_roles) {
1235: $roleselected = '';
1236: if ($role eq $env{'form.showrole'}) {
1237: $roleselected = ' selected="selected" ';
1238: }
1239: my $plrole=&Apache::lonnet::plaintext($role);
1240: $role_select .= '<option value="'.$role.'"'.$roleselected.'>'.$plrole.'</option>';
1241: }
1242: $roleselected = '';
1243: if ($env{'form.showrole'} eq 'cr') {
1244: $roleselected = ' selected="selected" ';
1245: }
1246: $role_select .= '<option value="cr"'.$roleselected.'>'.&mt('Custom role').'</option>'.
1247: '</select>';
1248: $r->print('<label>'.&mt('Role: [_1]',$role_select).'</label>');
1249: }
1250: if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) {
1251: $r->print(&list_submit_button(&mt('Update Display'))."\n</p>\n");
1252: }
1253: my ($indexhash,$keylist) = &make_keylist_array();
1254: my (%userlist,%userinfo);
1255: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
1256: my $courseform =
1257: &Apache::lonhtmlcommon::course_selection($formname,$totcodes,
1258: $codetitles,$idlist,$idlist_titles);
1259: $r->print('<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n".
1260: &Apache::lonhtmlcommon::start_pick_box()."\n".
1261: &Apache::lonhtmlcommon::row_title(&mt('Select Course(s)'),
1262: 'LC_oddrow_value')."\n".
1263: $courseform."\n".
1264: &Apache::lonhtmlcommon::row_closure(1).
1265: &Apache::lonhtmlcommon::end_pick_box().'</p>'.
1266: '<p>'.&list_submit_button(&mt('Update Display')).
1267: "\n</p>\n");
1268: if ($env{'form.coursepick'}) {
1269: $r->print('<hr />'.&mt('Searching').' ...<br /> <br />');
1270: }
1271: } else {
1272: $r->print('<hr />'.&mt('Searching').' ...<br /> <br />');
1273: }
1274: $r->rflush();
1275: if ($context eq 'course') {
1276: my $classlist = &Apache::loncoursedata::get_classlist();
1277: my $secidx = &Apache::loncoursedata::CL_SECTION();
1278: foreach my $student (keys(%{$classlist})) {
1279: if (exists($permission->{'view_section'})) {
1280: if ($classlist->{$student}[$secidx] ne $permission->{'view_section'}) {
1281: next;
1282: } else {
1283: $userlist{$student} = $classlist->{$student};
1284: }
1285: } else {
1286: $userlist{$student} = $classlist->{$student};
1287: }
1288: }
1289: my $cid =$env{'request.course.id'};
1290: my $cdom=$env{'course.'.$cid.'.domain'};
1291: my $cnum=$env{'course.'.$cid.'.num'};
1292: my $showroles;
1293: if ($env{'form.showrole'} ne 'Any') {
1294: $showroles = [$env{'form.showrole'}];
1295: } else {
1296: $showroles = undef;
1297: }
1298: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
1299: \@statuses,$showroles);
1300: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
1301: \%advrolehash,$permission);
1302: } else {
1303: my (%cstr_roles,%dom_roles);
1304: if ($context eq 'author') {
1305: # List co-authors and assistant co-authors
1306: my @possroles = ('ca','aa');
1307: %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
1308: \@statuses,\@possroles);
1309: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
1310: \%cstr_roles,$permission);
1311: } elsif ($context eq 'domain') {
1312: if ($env{'form.roletype'} eq 'domain') {
1313: %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'});
1314: foreach my $key (keys(%dom_roles)) {
1315: if (ref($dom_roles{$key}) eq 'HASH') {
1316: &gather_userinfo($context,$format,\%userlist,$indexhash,
1317: \%userinfo,$dom_roles{$key},$permission);
1318: }
1319: }
1320: } elsif ($env{'form.roletype'} eq 'author') {
1321: my %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'},['au']);
1322: my %coauthors;
1323: foreach my $key (keys(%dom_roles)) {
1324: if (ref($dom_roles{$key}) eq 'HASH') {
1325: if ($env{'form.showrole'} eq 'au') {
1326: &gather_userinfo($context,$format,\%userlist,$indexhash,
1327: \%userinfo,$dom_roles{$key},$permission);
1328: } else {
1329: my @possroles;
1330: if ($env{'form.showrole'} eq 'Any') {
1331: @possroles = ('ca','aa');
1332: } else {
1333: @possroles = ($env{'form.showrole'});
1334: }
1335: foreach my $author (sort(keys(%{$dom_roles{$key}}))) {
1336: my ($role,$authorname,$authordom) = split(/:/,$author);
1337: my $extent = '/'.$authordom.'/'.$authorname;
1338: %{$coauthors{$extent}} =
1339: &Apache::lonnet::get_my_roles($authorname,
1340: $authordom,undef,\@statuses,\@possroles);
1341: }
1342: &gather_userinfo($context,$format,\%userlist,
1343: $indexhash,\%userinfo,\%coauthors,$permission);
1344: }
1345: }
1346: }
1347: } elsif ($env{'form.roletype'} eq 'course') {
1348: if ($env{'form.coursepick'}) {
1349: my %courses = &process_coursepick();
1350: my %allusers;
1351: foreach my $cid (keys(%courses)) {
1352: my %coursehash =
1353: &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1354: my $cdom = $coursehash{'domain'};
1355: my $cnum = $coursehash{'num'};
1356: next if ($cnum eq '' || $cdom eq '');
1357: my $cdesc = $coursehash{'description'};
1358: my (@roles,@sections,%access,%users,%userdata,
1359: %statushash);
1360: if ($env{'form.showrole'} eq 'Any') {
1361: @roles = &course_roles($context);
1362: unshift(@roles,'cr');
1363: } else {
1364: @roles = ($env{'form.showrole'});
1365: }
1366: foreach my $role (@roles) {
1367: %{$users{$role}} = ();
1368: }
1369: foreach my $type (@statuses) {
1370: $access{$type} = $type;
1371: }
1372: &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash);
1373: foreach my $user (keys(%userdata)) {
1374: next if (ref($userinfo{$user}) eq 'HASH');
1375: foreach my $item ('fullname','id') {
1376: $userinfo{$user}{$item} = $userdata{$user}[$indexhash->{$item}];
1377: }
1378: }
1379: foreach my $role (keys(%users)) {
1380: foreach my $user (keys(%{$users{$role}})) {
1381: my $uniqid = $user.':'.$role;
1382: $allusers{$uniqid}{$cid} = { desc => $cdesc,
1383: secs => $statushash{$user}{$role},
1384: };
1385: }
1386: }
1387: }
1388: &gather_userinfo($context,$format,\%userlist,$indexhash,
1389: \%userinfo,\%allusers,$permission);
1390: } else {
1391: $r->print('<input type="hidden" name="phase" value="'.
1392: $env{'form.phase'}.'" /></form>');
1393: return;
1394: }
1395: }
1396: }
1397: }
1398: if (keys(%userlist) == 0) {
1399: if ($context eq 'author') {
1400: $r->print(&mt('There are no co-authors to display.')."\n");
1401: } elsif ($context eq 'domain') {
1402: if ($env{'form.roletype'} eq 'domain') {
1403: $r->print(&mt('There are no users with domain roles to display.')."\n");
1404: } elsif ($env{'form.roletype'} eq 'author') {
1405: $r->print(&mt('There are no authors or co-authors to display.')."\n");
1406: } elsif ($env{'form.roletype'} eq 'course') {
1407: $r->print(&mt('There are no course users to display')."\n");
1408: }
1409: } elsif ($context eq 'course') {
1410: $r->print(&mt('There are no course users to display.')."\n");
1411: }
1412: } else {
1413: # Print out the available choices
1414: my $usercount;
1415: if ($env{'form.action'} eq 'modifystudent') {
1416: ($usercount) = &show_users_list($r,$context,'view',$permission,
1417: $env{'form.Status'},\%userlist,$keylist);
1418: } else {
1419: ($usercount) = &show_users_list($r,$context,$env{'form.output'},
1420: $permission,$env{'form.Status'},\%userlist,$keylist);
1421: }
1422: if (!$usercount) {
1423: $r->print('<br />'.&mt('There are no users matching the search criteria.'));
1424: }
1425: }
1426: $r->print('<input type="hidden" name="phase" value="'.
1427: $env{'form.phase'}.'" /></form>');
1428: }
1429:
1430: sub list_submit_button {
1431: my ($text) = @_;
1432: return '<input type="button" name="updatedisplay" value="'.$text.'" onclick="javascript:display_update()" />';
1433: }
1434:
1435: sub gather_userinfo {
1436: my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_;
1437: foreach my $item (keys(%{$rolehash})) {
1438: @{$userlist->{$item}} = ();
1439: my %userdata;
1440: if ($context eq 'author' || $context eq 'course') {
1441: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
1442: split(/:/,$item);
1443: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
1444: &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
1445: } elsif ($context eq 'domain') {
1446: if ($env{'form.roletype'} eq 'domain') {
1447: ($userdata{'role'},$userdata{'username'},$userdata{'domain'}) =
1448: split(/:/,$item);
1449: ($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
1450: &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
1451: } elsif ($env{'form.roletype'} eq 'author') {
1452: if (ref($rolehash->{$item}) eq 'HASH') {
1453: $userdata{'extent'} = $item;
1454: foreach my $key (keys(%{$rolehash->{$item}})) {
1455: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) = split(/:/,$key);
1456: ($userdata{'start'},$userdata{'end'}) =
1457: split(/:/,$rolehash->{$item}{$key});
1458: my $uniqid = $key.':'.$item;
1459: &build_user_record(\%userdata,$userinfo,$indexhash,$uniqid,$userlist);
1460: }
1461: }
1462: } elsif ($env{'form.roletype'} eq 'course') {
1463: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
1464: split(/:/,$item);
1465: if (ref($rolehash->{$item}) eq 'HASH') {
1466: my $numcids = keys(%{$rolehash->{$item}});
1467: foreach my $cid (sort(keys(%{$rolehash->{$item}}))) {
1468: if (ref($rolehash->{$item}{$cid}) eq 'HASH') {
1469: my $spanstart = '';
1470: my $spanend = '; ';
1471: my $space = ', ';
1472: if ($format eq 'html' || $format eq 'view') {
1473: $spanstart = '<span class="LC_nobreak">';
1474: if ($permission->{'cusr'}) {
1475: if ($numcids > 1) {
1476: $spanstart .= '<input type="radio" name="'.$item.'" value="'.$cid.'" />';
1477: } else {
1478: $spanstart .= '<input type="hidden" name="'.$item.'" value="'.$cid.'" />';
1479: }
1480: }
1481: $spanend = '</span><br />';
1482: $space = ', ';
1483: }
1484: $userdata{'extent'} .= $spanstart.
1485: $rolehash->{$item}{$cid}{'desc'}.$space;
1486: if (ref($rolehash->{$item}{$cid}{'secs'}) eq 'HASH') {
1487: foreach my $sec (sort(keys(%{$rolehash->{$item}{$cid}{'secs'}}))) {
1488: $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
1489: }
1490: }
1491: }
1492: }
1493: }
1494: &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
1495: }
1496: }
1497: }
1498: return;
1499: }
1500:
1501: sub build_user_record {
1502: my ($userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
1503: next if ($userdata->{'start'} eq '-1' && $userdata->{'end'} eq '-1');
1504: &process_date_info($userdata);
1505: my $username = $userdata->{'username'};
1506: my $domain = $userdata->{'domain'};
1507: if (ref($userinfo->{$username.':'.$domain}) eq 'HASH') {
1508: $userdata->{'fullname'} =
1509: $userinfo->{$username.':'.$domain}{'fullname'};
1510: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
1511: } else {
1512: &aggregate_user_info($domain,$username,$userinfo);
1513: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
1514: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
1515: }
1516: foreach my $key (keys(%{$indexhash})) {
1517: if (defined($userdata->{$key})) {
1518: $userlist->{$record_key}[$indexhash->{$key}] = $userdata->{$key};
1519: }
1520: }
1521: return;
1522: }
1523:
1524: sub courses_selector {
1525: my ($cdom,$formname) = @_;
1526: my %coursecodes = ();
1527: my %codes = ();
1528: my @codetitles = ();
1529: my %cat_titles = ();
1530: my %cat_order = ();
1531: my %idlist = ();
1532: my %idnums = ();
1533: my %idlist_titles = ();
1534: my $caller = 'global';
1535: my $format_reply;
1536: my $jscript = '';
1537:
1538: my $totcodes = 0;
1539: $totcodes =
1540: &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,
1541: $cdom,$totcodes);
1542: if ($totcodes > 0) {
1543: $format_reply =
1544: &Apache::lonnet::auto_instcode_format($caller,$cdom,\%coursecodes,
1545: \%codes,\@codetitles,\%cat_titles,\%cat_order);
1546: if ($format_reply eq 'ok') {
1547: my $numtypes = @codetitles;
1548: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
1549: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
1550: my $longtitles_str = join('","',@{$longtitles});
1551: my $allidlist = $idlist{$codetitles[0]};
1552: $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
1553: $jscript .= $scripttext;
1554: $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,@codetitles);
1555: }
1556: }
1557: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
1558:
1559: my %elements = (
1560: Year => 'selectbox',
1561: coursepick => 'radio',
1562: coursetotal => 'text',
1563: courselist => 'text',
1564: );
1565: $jscript .= &Apache::lonhtmlcommon::set_form_elements(\%elements);
1566: if ($env{'form.coursepick'} eq 'category') {
1567: $jscript .= qq|
1568: function setCourseCat(formname) {
1569: if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
1570: return;
1571: }
1572: courseSet('Year');
1573: for (var j=0; j<formname.Semester.length; j++) {
1574: if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
1575: formname.Semester.options[j].selected = true;
1576: }
1577: }
1578: if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
1579: return;
1580: }
1581: courseSet('Semester');
1582: for (var j=0; j<formname.Department.length; j++) {
1583: if (formname.Department.options[j].value == "$env{'form.Department'}") { formname.Department.options[j].selected = true;
1584: }
1585: }
1586: if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
1587: return;
1588: }
1589: courseSet('Department');
1590: for (var j=0; j<formname.Number.length; j++) {
1591: if (formname.Number.options[j].value == "$env{'form.Number'}") {
1592: formname.Number.options[j].selected = true;
1593: }
1594: }
1595: }
1596: |;
1597: }
1598: return ($cb_jscript,$jscript,$totcodes,\@codetitles,\%idlist,
1599: \%idlist_titles);
1600: }
1601:
1602: sub course_selector_loadcode {
1603: my ($formname) = @_;
1604: my $loadcode;
1605: if ($env{'form.coursepick'} ne '') {
1606: $loadcode = 'javascript:setFormElements(document.'.$formname.')';
1607: if ($env{'form.coursepick'} eq 'category') {
1608: $loadcode .= ';javascript:setCourseCat(document.'.$formname.')';
1609: }
1610: }
1611: return $loadcode;
1612: }
1613:
1614: sub process_coursepick {
1615: my $coursefilter = $env{'form.coursepick'};
1616: my $cdom = $env{'request.role.domain'};
1617: my %courses;
1618: if ($coursefilter eq 'all') {
1619: %courses = &Apache::lonnet::courseiddump($cdom,'.','.','.','.','.',
1620: undef,undef,'Course');
1621: } elsif ($coursefilter eq 'category') {
1622: my $instcode = &instcode_from_coursefilter();
1623: %courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.',
1624: undef,undef,'Course');
1625: } elsif ($coursefilter eq 'specific') {
1626: if ($env{'form.coursetotal'} > 1) {
1627: my @course_ids = split(/&&/,$env{'form.courselist'});
1628: foreach my $cid (@course_ids) {
1629: $courses{$cid} = '';
1630: }
1631: } else {
1632: $courses{$env{'form.courselist'}} = '';
1633: }
1634: }
1635: return %courses;
1636: }
1637:
1638: sub instcode_from_coursefilter {
1639: my $instcode = '';
1640: my @cats = ('Semester','Year','Department','Number');
1641: foreach my $category (@cats) {
1642: if (defined($env{'form.'.$category})) {
1643: unless ($env{'form.'.$category} eq '-1') {
1644: $instcode .= $env{'form.'.$category};
1645: }
1646: }
1647: }
1648: if ($instcode eq '') {
1649: $instcode = '.';
1650: }
1651: return $instcode;
1652: }
1653:
1654: sub display_adv_courseroles {
1655: my $output;
1656: #
1657: # List course personnel
1658: my %coursepersonnel =
1659: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'});
1660: #
1661: $output = '<br />'.&Apache::loncommon::start_data_table();
1662: foreach my $role (sort(keys(%coursepersonnel))) {
1663: next if ($role =~ /^\s*$/);
1664: $output .= &Apache::loncommon::start_data_table_row().
1665: '<td>'.$role.'</td><td>';
1666: foreach my $user (split(',',$coursepersonnel{$role})) {
1667: my ($puname,$pudom)=split(':',$user);
1668: $output .= ' '.&Apache::loncommon::aboutmewrapper(
1669: &Apache::loncommon::plainname($puname,$pudom),
1670: $puname,$pudom);
1671: }
1672: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
1673: }
1674: $output .= &Apache::loncommon::end_data_table();
1675: }
1676:
1677: sub make_keylist_array {
1678: my ($index,$keylist);
1679: $index->{'domain'} = &Apache::loncoursedata::CL_SDOM();
1680: $index->{'username'} = &Apache::loncoursedata::CL_SNAME();
1681: $index->{'end'} = &Apache::loncoursedata::CL_END();
1682: $index->{'start'} = &Apache::loncoursedata::CL_START();
1683: $index->{'id'} = &Apache::loncoursedata::CL_ID();
1684: $index->{'section'} = &Apache::loncoursedata::CL_SECTION();
1685: $index->{'fullname'} = &Apache::loncoursedata::CL_FULLNAME();
1686: $index->{'status'} = &Apache::loncoursedata::CL_STATUS();
1687: $index->{'type'} = &Apache::loncoursedata::CL_TYPE();
1688: $index->{'lockedtype'} = &Apache::loncoursedata::CL_LOCKEDTYPE();
1689: $index->{'groups'} = &Apache::loncoursedata::CL_GROUP();
1690: $index->{'email'} = &Apache::loncoursedata::CL_PERMANENTEMAIL();
1691: $index->{'role'} = &Apache::loncoursedata::CL_ROLE();
1692: $index->{'extent'} = &Apache::loncoursedata::CL_EXTENT();
1693: foreach my $key (keys(%{$index})) {
1694: $keylist->[$index->{$key}] = $key;
1695: }
1696: return ($index,$keylist);
1697: }
1698:
1699: sub aggregate_user_info {
1700: my ($udom,$uname,$userinfo) = @_;
1701: my %info=&Apache::lonnet::get('environment',
1702: ['firstname','middlename',
1703: 'lastname','generation','id'],
1704: $udom,$uname);
1705: my ($tmp) = keys(%info);
1706: my ($fullname,$id);
1707: if ($tmp =~/^(con_lost|error|no_such_host)/i) {
1708: $fullname = 'not available';
1709: $id = 'not available';
1710: &Apache::lonnet::logthis('unable to retrieve environment '.
1711: 'for '.$uname.':'.$udom);
1712: } else {
1713: $fullname = &Apache::lonnet::format_name(@info{qw/firstname middlename lastname generation/},'lastname');
1714: $id = $info{'id'};
1715: }
1716: $userinfo->{$uname.':'.$udom} = {
1717: fullname => $fullname,
1718: id => $id,
1719: };
1720: return;
1721: }
1722:
1723: sub process_date_info {
1724: my ($userdata) = @_;
1725: my $now = time;
1726: $userdata->{'status'} = 'Active';
1727: if ($userdata->{'start'} > 0) {
1728: if ($now < $userdata->{'start'}) {
1729: $userdata->{'status'} = 'Future';
1730: }
1731: }
1732: if ($userdata->{'end'} > 0) {
1733: if ($now > $userdata->{'end'}) {
1734: $userdata->{'status'} = 'Expired';
1735: }
1736: }
1737: return;
1738: }
1739:
1740: sub show_users_list {
1741: my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist)=@_;
1742: #
1743: # Variables for excel output
1744: my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
1745: #
1746: # Variables for csv output
1747: my ($CSVfile,$CSVfilename);
1748: #
1749: my $sortby = $env{'form.sortby'};
1750: my @sortable = ('username','domain','id','fullname','start','end','email','role');
1751: if ($context eq 'course') {
1752: push(@sortable,('section','groups','type'));
1753: } else {
1754: push(@sortable,'extent');
1755: }
1756: if (!grep(/^\Q$sortby\E$/,@sortable)) {
1757: $sortby = 'username';
1758: }
1759: my $setting = $env{'form.roleaction'};
1760: my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers);
1761: if ($context eq 'course') {
1762: $cid=$env{'request.course.id'};
1763: $cdom = $env{'course.'.$cid.'.domain'};
1764: $cnum = $env{'course.'.$cid.'.num'};
1765: ($classgroups) = &Apache::loncoursedata::get_group_memberships(
1766: $userlist,$keylist,$cdom,$cnum);
1767: if ($mode eq 'autoenroll') {
1768: $env{'form.showrole'} = 'st';
1769: } else {
1770: if (! exists($env{'form.displayphotos'})) {
1771: $env{'form.displayphotos'} = 'off';
1772: }
1773: $displayphotos = $env{'form.displayphotos'};
1774: if (! exists($env{'form.displayclickers'})) {
1775: $env{'form.displayclickers'} = 'off';
1776: }
1777: $displayclickers = $env{'form.displayclickers'};
1778: if ($env{'course.'.$cid.'.internal.showphoto'}) {
1779: $r->print('
1780: <script type="text/javascript">
1781: function photowindow(photolink) {
1782: var title = "Photo_Viewer";
1783: var options = "scrollbars=1,resizable=1,menubar=0";
1784: options += ",width=240,height=240";
1785: stdeditbrowser = open(photolink,title,options,"1");
1786: stdeditbrowser.focus();
1787: }
1788: </script>
1789: ');
1790: }
1791: $r->print(<<END);
1792: <input type="hidden" name="displayphotos" value="$displayphotos" />
1793: <input type="hidden" name="displayclickers" value="$displayclickers" />
1794: END
1795: }
1796: }
1797: if ($mode ne 'autoenroll') {
1798: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
1799: my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
1800: my $singconfirm = &mt(' for a single user');
1801: my $multconfirm = &mt(' for multiple users');
1802: my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
1803: $r->print(<<END);
1804:
1805: <script type="text/javascript" language="Javascript">
1806: $check_uncheck_js
1807:
1808: function verify_action (field) {
1809: var numchecked = 0;
1810: var singconf = '$singconfirm';
1811: var multconf = '$multconfirm';
1812: if (field.length > 0) {
1813: for (i = 0; i < field.length; i++) {
1814: if (field[i].checked == true) {
1815: numchecked ++;
1816: }
1817: }
1818: } else {
1819: if (field.checked == true) {
1820: numchecked ++;
1821: }
1822: }
1823: if (numchecked == 0) {
1824: alert("$alert");
1825: }
1826: else {
1827: var message = document.studentform.bulkaction[document.studentform.bulkaction.selectedIndex].text;
1828: if (numchecked == 1) {
1829: message += singconf;
1830: }
1831: else {
1832: message += multconf;
1833: }
1834: if (confirm(message)) {
1835: document.studentform.phase.value = 'bulkchange';
1836: document.studentform.submit();
1837: }
1838: }
1839: }
1840:
1841: function username_display_launch(username,domain) {
1842: var target;
1843: for (var i=0; i<document.studentform.usernamelink.length; i++) {
1844: if (document.studentform.usernamelink[i].checked) {
1845: target = document.studentform.usernamelink[i].value;
1846: }
1847: }
1848: if (target == 'modify') {
1849: document.studentform.srchterm.value=username;
1850: document.studentform.srchdomain.value=domain;
1851: document.studentform.phase.value='get_user_info';
1852: document.studentform.action.value = 'singleuser';
1853: document.studentform.submit();
1854: }
1855: else {
1856: document.location.href = '/adm/'+domain+'/'+username+'/aboutme';
1857: }
1858: }
1859: </script>
1860: $date_sec_selector
1861: <input type="hidden" name="state" value="$env{'form.state'}" />
1862: END
1863: }
1864: $r->print(<<END);
1865: <input type="hidden" name="sortby" value="$sortby" />
1866: END
1867:
1868: my %lt=&Apache::lonlocal::texthash(
1869: 'username' => "username",
1870: 'domain' => "domain",
1871: 'id' => 'ID',
1872: 'fullname' => "name",
1873: 'section' => "section",
1874: 'groups' => "active groups",
1875: 'start' => "start date",
1876: 'end' => "end date",
1877: 'status' => "status",
1878: 'role' => "role",
1879: 'type' => "enroll type/action",
1880: 'email' => "email address",
1881: 'clicker' => "clicker id",
1882: 'photo' => "photo",
1883: 'extent' => "extent",
1884: 'pr' => "Proceed",
1885: 'ca' => "check all",
1886: 'ua' => "uncheck all",
1887: 'ac' => "Action to take for selected users",
1888: 'link' => "Behavior of username links",
1889: 'aboutme' => "Display a user's personal page",
1890: 'modify' => "Modify a user's information",
1891: );
1892: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
1893: $lt{'extent'} = &mt('Course(s): description, section(s), status');
1894: } elsif ($context eq 'author') {
1895: $lt{'extent'} = &mt('Author');
1896: }
1897: my @cols = ('username','domain','id','fullname');
1898: if ($context eq 'course') {
1899: push(@cols,'section');
1900: }
1901: if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) {
1902: push(@cols,('start','end'));
1903: }
1904: if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
1905: push(@cols,'role');
1906: }
1907: if ($context eq 'domain' && ($env{'form.roletype'} eq 'author' ||
1908: $env{'form.roletype'} eq 'course')) {
1909: push (@cols,'extent');
1910: }
1911: if (($statusmode eq 'Any') &&
1912: (!($context eq 'domain' && $env{'form.roletype'} eq 'course'))) {
1913: push(@cols,'status');
1914: }
1915: if ($context eq 'course') {
1916: push(@cols,'groups');
1917: }
1918: push(@cols,'email');
1919:
1920: my $rolefilter = $env{'form.showrole'};
1921: if ($env{'form.showrole'} eq 'cr') {
1922: $rolefilter = &mt('custom');
1923: } elsif ($env{'form.showrole'} ne 'Any') {
1924: $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'});
1925: }
1926: my $results_description;
1927: if ($mode ne 'autoenroll') {
1928: $results_description = &results_header_row($rolefilter,$statusmode,
1929: $context,$permission);
1930: $r->print('<b>'.$results_description.'</b><br />');
1931: }
1932: my ($output,$actionselect);
1933: if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll') {
1934: if ($mode ne 'autoenroll') {
1935: if ($permission->{'cusr'}) {
1936: $actionselect = &select_actions($context,$setting,$statusmode);
1937: }
1938: $r->print(<<END);
1939: <input type="hidden" name="srchby" value="uname" />
1940: <input type="hidden" name="srchin" value="dom" />
1941: <input type="hidden" name="srchtype" value="exact" />
1942: <input type="hidden" name="srchterm" value="" />
1943: <input type="hidden" name="srchdomain" value="" />
1944: END
1945: $output = '<p>';
1946: my @linkdests = ('aboutme');
1947: if ($permission->{'cusr'}) {
1948: push (@linkdests,'modify');
1949: $output .= '<span class="LC_nobreak">'.$lt{'link'}.': ';
1950: my $usernamelink = $env{'form.usernamelink'};
1951: if ($usernamelink eq '') {
1952: $usernamelink = 'aboutme';
1953: }
1954: foreach my $item (@linkdests) {
1955: my $checkedstr = '';
1956: if ($item eq $usernamelink) {
1957: $checkedstr = ' checked="checked" ';
1958: }
1959: $output .= '<label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.'> '.$lt{$item}.'</label> ';
1960: }
1961: $output .= '</span><br />';
1962: } else {
1963: $output .= &mt("Click on a username to view the user's personal page.").'<br />';
1964: }
1965: if ($actionselect) {
1966: $output .= <<"END";
1967: $lt{'ac'}: $actionselect <input type="button" value="$lt{'pr'}" onclick="javascript:verify_action(document.studentform.actionlist)" /></p>
1968: <p><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.actionlist)" />
1969: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.actionlist)" />
1970: END
1971: }
1972: }
1973: $output .= "\n<p>\n".
1974: &Apache::loncommon::start_data_table().
1975: &Apache::loncommon::start_data_table_header_row();
1976: if ($mode eq 'autoenroll') {
1977: $output .= "
1978: <th><a href=\"javascript:document.studentform.sortby.value='type';document.studentform.submit();\">$lt{'type'}</a></th>
1979: ";
1980: } else {
1981: $output .= "\n".'<th>'.&mt('Count').'</th>'."\n";
1982: if ($actionselect) {
1983: $output .= '<th>'.&mt('Select').'</th>'."\n";
1984: }
1985: }
1986: foreach my $item (@cols) {
1987: $output .= "<th><a href=\"javascript:document.studentform.sortby.value='$item';document.studentform.submit();\">$lt{$item}</a></th>\n";
1988: }
1989: my %role_types = &role_type_names();
1990: if ($context eq 'course' && $mode ne 'autoenroll') {
1991: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
1992: # Clicker display on or off?
1993: my %clicker_options = &Apache::lonlocal::texthash(
1994: 'on' => 'Show',
1995: 'off' => 'Hide',
1996: );
1997: my $clickerchg = 'on';
1998: if ($displayclickers eq 'on') {
1999: $clickerchg = 'off';
2000: }
2001: $output .= ' <th>'."\n".' '.
2002: '<a href="javascript:document.studentform.displayclickers.value='.
2003: "'".$clickerchg."'".';document.studentform.submit();">'.
2004: $clicker_options{$clickerchg}.'</a> '.$lt{'clicker'}."\n".
2005: ' </th>'."\n";
2006:
2007: # Photo display on or off?
2008: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
2009: my %photo_options = &Apache::lonlocal::texthash(
2010: 'on' => 'Show',
2011: 'off' => 'Hide',
2012: );
2013: my $photochg = 'on';
2014: if ($displayphotos eq 'on') {
2015: $photochg = 'off';
2016: }
2017: $output .= ' <th>'."\n".' '.
2018: '<a href="javascript:document.studentform.displayphotos.value='.
2019: "'".$photochg."'".';document.studentform.submit();">'.
2020: $photo_options{$photochg}.'</a> '.$lt{'photo'}."\n".
2021: ' </th>'."\n";
2022: }
2023: }
2024: }
2025: $output .= &Apache::loncommon::end_data_table_header_row();
2026: # Done with the HTML header line
2027: } elsif ($mode eq 'csv') {
2028: #
2029: # Open a file
2030: $CSVfilename = '/prtspool/'.
2031: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
2032: time.'_'.rand(1000000000).'.csv';
2033: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
2034: $r->log_error("Couldn't open $CSVfilename for output $!");
2035: $r->print("Problems occured in writing the csv file. ".
2036: "This error has been logged. ".
2037: "Please alert your LON-CAPA administrator.");
2038: $CSVfile = undef;
2039: }
2040: #
2041: # Write headers and data to file
2042: print $CSVfile '"'.$results_description.'"'."\n";
2043: print $CSVfile '"'.join('","',map {
2044: &Apache::loncommon::csv_translate($lt{$_})
2045: } (@cols)).'"'."\n";
2046: } elsif ($mode eq 'excel') {
2047: # Create the excel spreadsheet
2048: ($excel_workbook,$excel_filename,$format) =
2049: &Apache::loncommon::create_workbook($r);
2050: return if (! defined($excel_workbook));
2051: $excel_sheet = $excel_workbook->addworksheet('userlist');
2052: $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
2053: #
2054: my @colnames = map {$lt{$_}} (@cols);
2055: $excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
2056: }
2057:
2058: # Done with header lines in all formats
2059:
2060: my %index;
2061: my $i;
2062: foreach my $idx (@$keylist) {
2063: $index{$idx} = $i++;
2064: }
2065: my $usercount = 0;
2066: # Get groups, role, permanent e-mail so we can sort on them if
2067: # necessary.
2068: foreach my $user (keys(%{$userlist})) {
2069: if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) {
2070: delete($userlist->{$user});
2071: next;
2072: }
2073: my ($uname,$udom,$role,$groups,$email);
2074: if (($statusmode ne 'Any') &&
2075: ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
2076: delete($userlist->{$user});
2077: next;
2078: }
2079: if ($context eq 'domain') {
2080: if ($env{'form.roletype'} eq 'domain') {
2081: ($role,$uname,$udom) = split(/:/,$user);
2082: if (($uname eq $env{'request.role.domain'}.'-domainconfig') &&
2083: ($udom eq $env{'request.role.domain'})) {
2084: delete($userlist->{$user});
2085: next;
2086: }
2087: } elsif ($env{'form.roletype'} eq 'author') {
2088: ($uname,$udom,$role) = split(/:/,$user,-1);
2089: } elsif ($env{'form.roletype'} eq 'course') {
2090: ($uname,$udom,$role) = split(/:/,$user);
2091: }
2092: } else {
2093: ($uname,$udom,$role) = split(/:/,$user,-1);
2094: if (($context eq 'course') && $role eq '') {
2095: $role = 'st';
2096: }
2097: }
2098: $userlist->{$user}->[$index{'role'}] = $role;
2099: if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
2100: delete($userlist->{$user});
2101: next;
2102: }
2103: if (ref($classgroups) eq 'HASH') {
2104: $groups = $classgroups->{$user};
2105: }
2106: if (ref($groups->{active}) eq 'HASH') {
2107: $userlist->{$user}->[$index{'groups'}] = join(', ',keys(%{$groups->{'active'}}));
2108: }
2109: my %emails = &Apache::loncommon::getemails($uname,$udom);
2110: if ($emails{'permanentemail'} =~ /\S/) {
2111: $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
2112: }
2113: $usercount ++;
2114: }
2115: my $autocount = 0;
2116: my $manualcount = 0;
2117: my $lockcount = 0;
2118: my $unlockcount = 0;
2119: if ($usercount) {
2120: $r->print($output);
2121: } else {
2122: if ($mode eq 'autoenroll') {
2123: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
2124: } else {
2125: return;
2126: }
2127: }
2128: #
2129: # Sort the users
2130: my $index = $index{$sortby};
2131: my $second = $index{'username'};
2132: my $third = $index{'domain'};
2133: my @sorted_users = sort {
2134: lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index])
2135: ||
2136: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
2137: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
2138: } (keys(%$userlist));
2139: my $rowcount = 0;
2140: foreach my $user (@sorted_users) {
2141: my %in;
2142: my $sdata = $userlist->{$user};
2143: $rowcount ++;
2144: foreach my $item (@{$keylist}) {
2145: $in{$item} = $sdata->[$index{$item}];
2146: }
2147: my $role = $in{'role'};
2148: $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}]);
2149: if (! defined($in{'start'}) || $in{'start'} == 0) {
2150: $in{'start'} = &mt('none');
2151: } else {
2152: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
2153: }
2154: if (! defined($in{'end'}) || $in{'end'} == 0) {
2155: $in{'end'} = &mt('none');
2156: } else {
2157: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
2158: }
2159: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
2160: $r->print(&Apache::loncommon::start_data_table_row());
2161: my $checkval;
2162: if ($mode eq 'autoenroll') {
2163: my $cellentry;
2164: if ($in{'type'} eq 'auto') {
2165: $cellentry = '<b>'.&mt('auto').'</b> <label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'" /> Change</label>';
2166: $autocount ++;
2167: } else {
2168: $cellentry = '<table border="0" cellspacing="0"><tr><td rowspan="2"><b>'.&mt('manual').'</b></td><td><nobr><label><input type="checkbox" name="chgmanual" value="'.$in{'username'}.':'.$in{'domain'}.'" /> Change</label></nobr></td></tr><tr><td><nobr>';
2169: $manualcount ++;
2170: if ($in{'lockedtype'}) {
2171: $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'" /> '.&mt('Unlock').'</label>';
2172: $unlockcount ++;
2173: } else {
2174: $cellentry .= '<label><input type="checkbox" name="lockchg" value="'.$in{'username'}.':'.$in{'domain'}.'" /> '.&mt('Lock').'</label>';
2175: $lockcount ++;
2176: }
2177: $cellentry .= '</nobr></td></tr></table>';
2178: }
2179: $r->print("<td>$cellentry</td>\n");
2180: } else {
2181: $r->print("<td>$rowcount</td>\n");
2182: $checkval;
2183: if ($actionselect) {
2184: $checkval = $user;
2185: if ($context eq 'course') {
2186: if ($role eq 'st') {
2187: $checkval .= ':st';
2188: }
2189: $checkval .= ':'.$in{'section'};
2190: if ($role eq 'st') {
2191: $checkval .= ':'.$in{'type'}.':'.$in{'lockedtype'};
2192: }
2193: }
2194: $r->print('<td><input type="checkbox" name="actionlist" value="'.
2195: $checkval.'"></td>');
2196: }
2197: }
2198: foreach my $item (@cols) {
2199: if ($item eq 'username') {
2200: $r->print('<td>'.&print_username_link($mode,$permission,
2201: \%in).'</td>');
2202: } elsif (($item eq 'start' || $item eq 'end') && ($actionselect)) {
2203: $r->print('<td>'.$in{$item}.'<input type="hidden" name="'.$checkval.'_'.$item.'" value="'.$sdata->[$index{$item}].'" /></td>'."\n");
2204: } else {
2205: $r->print('<td>'.$in{$item}.'</td>'."\n");
2206: }
2207: }
2208: if (($context eq 'course') && ($mode ne 'autoenroll')) {
2209: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
2210: if ($displayclickers eq 'on') {
2211: my $clickers =
2212: (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
2213: if ($clickers!~/\w/) { $clickers='-'; }
2214: $r->print('<td>'.$clickers.'</td>');
2215: } else {
2216: $r->print(' <td> </td> ');
2217: }
2218: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
2219: if ($displayphotos eq 'on' && $sdata->[$index{'role'}] eq 'st') {
2220: my $imgurl =
2221: &Apache::lonnet::retrievestudentphoto($in{'domain'},$in{'username'},
2222: 'gif','thumbnail');
2223: $r->print(' <td align="right"><a href="javascript:photowindow('."'".&Apache::lonnet::studentphoto($in{'domain'},$in{'username'},'jpg')."'".')"><img src="'.$imgurl.'" border="1"></a></td>');
2224: } else {
2225: $r->print(' <td> </td> ');
2226: }
2227: }
2228: }
2229: }
2230: $r->print(&Apache::loncommon::end_data_table_row());
2231: } elsif ($mode eq 'csv') {
2232: next if (! defined($CSVfile));
2233: # no need to bother with $linkto
2234: if (! defined($in{'start'}) || $in{'start'} == 0) {
2235: $in{'start'} = &mt('none');
2236: } else {
2237: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
2238: }
2239: if (! defined($in{'end'}) || $in{'end'} == 0) {
2240: $in{'end'} = &mt('none');
2241: } else {
2242: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
2243: }
2244: my @line = ();
2245: foreach my $item (@cols) {
2246: push @line,&Apache::loncommon::csv_translate($in{$item});
2247: }
2248: print $CSVfile '"'.join('","',@line).'"'."\n";
2249: } elsif ($mode eq 'excel') {
2250: my $col = 0;
2251: foreach my $item (@cols) {
2252: if ($item eq 'start' || $item eq 'end') {
2253: if (defined($item) && $item != 0) {
2254: $excel_sheet->write($row,$col++,
2255: &Apache::lonstathelpers::calc_serial($in{item}),
2256: $format->{'date'});
2257: } else {
2258: $excel_sheet->write($row,$col++,'none');
2259: }
2260: } else {
2261: $excel_sheet->write($row,$col++,$in{$item});
2262: }
2263: }
2264: $row++;
2265: }
2266: }
2267: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
2268: $r->print(&Apache::loncommon::end_data_table().'<br />');
2269: } elsif ($mode eq 'excel') {
2270: $excel_workbook->close();
2271: $r->print('<p><a href="'.$excel_filename.'">'.
2272: &mt('Your Excel spreadsheet').'</a> '.&mt('is ready for download').'.</p>'."\n");
2273: } elsif ($mode eq 'csv') {
2274: close($CSVfile);
2275: $r->print('<a href="'.$CSVfilename.'">'.
2276: &mt('Your CSV file').'</a> is ready for download.'.
2277: "\n");
2278: $r->rflush();
2279: }
2280: if ($mode eq 'autoenroll') {
2281: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
2282: } else {
2283: return ($usercount);
2284: }
2285: }
2286:
2287: sub print_username_link {
2288: my ($mode,$permission,$in) = @_;
2289: my $output;
2290: if ($mode eq 'autoenroll') {
2291: $output = $in->{'username'};
2292: } elsif (!$permission->{'cusr'}) {
2293: $output = &Apache::loncommon::aboutmewrapper($in->{'username'},
2294: $in->{'username'},
2295: $in->{'domain'});
2296: } else {
2297: $output = '<a href="javascript:username_display_launch('.
2298: "'$in->{'username'}','$in->{'domain'}'".')" />'.
2299: $in->{'username'}.'</a>';
2300: }
2301: return $output;
2302: }
2303:
2304: sub role_type_names {
2305: my %lt = &Apache::lonlocal::texthash (
2306: 'domain' => 'Domain Roles',
2307: 'author' => 'Co-Author Roles',
2308: 'course' => 'Course Roles',
2309: );
2310: return %lt;
2311: }
2312:
2313: sub select_actions {
2314: my ($context,$setting,$statusmode) = @_;
2315: my %lt = &Apache::lonlocal::texthash(
2316: revoke => "Revoke user roles",
2317: delete => "Delete user roles",
2318: reenable => "Re-enable expired user roles",
2319: activate => "Make future user roles active now",
2320: chgdates => "Change starting/ending dates",
2321: chgsec => "Change section associated with user roles",
2322: );
2323: my ($output,$options,%choices);
2324: if ($statusmode eq 'Any') {
2325: $options .= '
2326: <option value="chgdates">'.$lt{'chgdates'}.'</option>';
2327: $choices{'dates'} = 1;
2328: } else {
2329: if ($statusmode eq 'Future') {
2330: $options .= '
2331: <option value="activate">'.$lt{'activate'}.'</option>';
2332: $choices{'dates'} = 1;
2333: } elsif ($statusmode eq 'Expired') {
2334: $options .= '
2335: <option value="reenable">'.$lt{'reenable'}.'</option>';
2336: $choices{'dates'} = 1;
2337: }
2338: if ($statusmode eq 'Active' || $statusmode eq 'Future') {
2339: $options .= '
2340: <option value="chgdates">'.$lt{'chgdates'}.'</option>
2341: <option value="revoke">'.$lt{'revoke'}.'</option>';
2342: $choices{'dates'} = 1;
2343: }
2344: }
2345: if ($context eq 'domain') {
2346: $options .= '
2347: <option value="delete">'.$lt{'delete'}.'</option>';
2348: }
2349: if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
2350: if ($statusmode ne 'Expired') {
2351: $options .= '
2352: <option value="chgsec">'.$lt{'chgsec'}.'</option>';
2353: $choices{'sections'} = 1;
2354: }
2355: }
2356: if ($options) {
2357: $output = '<select name="bulkaction" onchange="javascript:opendatebrowser(this.form,'."'studentform'".')" />'."\n".
2358: '<option value="" selected="selected">'.
2359: &mt('Please select').'</option>'."\n".$options."\n".'</select>';
2360: if ($choices{'dates'}) {
2361: $output .=
2362: '<input type="hidden" name="startdate_month" value="" />'."\n".
2363: '<input type="hidden" name="startdate_day" value="" />'."\n".
2364: '<input type="hidden" name="startdate_year" value="" />'."\n".
2365: '<input type="hidden" name="startdate_hour" value="" />'."\n".
2366: '<input type="hidden" name="startdate_minute" value="" />'."\n".
2367: '<input type="hidden" name="startdate_second" value="" />'."\n".
2368: '<input type="hidden" name="enddate_month" value="" />'."\n".
2369: '<input type="hidden" name="enddate_day" value="" />'."\n".
2370: '<input type="hidden" name="enddate_year" value="" />'."\n".
2371: '<input type="hidden" name="enddate_hour" value="" />'."\n".
2372: '<input type="hidden" name="enddate_minute" value="" />'."\n".
2373: '<input type="hidden" name="enddate_second" value="" />'."\n";
2374: if ($context eq 'course') {
2375: $output .= '<input type="hidden" name="makedatesdefault" value="" />'."\n";
2376: }
2377: }
2378: if ($choices{'sections'}) {
2379: $output .= '<input type="hidden" name="retainsec" value= "" />'."\n".
2380: '<input type="hidden" name="newsecs" value= "" />'."\n";
2381: }
2382: }
2383: return $output;
2384: }
2385:
2386: sub date_section_javascript {
2387: my ($context,$setting) = @_;
2388: my $title;
2389: if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
2390: $title = &mt('Date and Section selector');
2391: } else {
2392: $title = &mt('Date selector');
2393: }
2394: my $output = '
2395: <script type="text/javascript">
2396: var stdeditbrowser;'."\n";
2397: $output .= <<"ENDONE";
2398: function opendatebrowser(callingform,formname) {
2399: var bulkaction = callingform.bulkaction.options[callingform.bulkaction.selectedIndex].value;
2400: if (bulkaction == 'revoke' || bulkaction == 'delete' || bulkaction == '') {
2401: return;
2402: }
2403: var url = '/adm/createuser?';
2404: var type = '';
2405: var showrole = callingform.showrole.options[callingform.showrole.selectedIndex].value;
2406: ENDONE
2407: if ($context eq 'domain') {
2408: $output .= '
2409: type = callingform.roletype.options[callingform.roletype.selectedIndex].value;
2410: ';
2411: }
2412: my $width= '700';
2413: my $height = '400';
2414: $output .= <<"ENDTWO";
2415: url += 'action=dateselect&callingform=' + formname +
2416: '&roletype='+type+'&showrole='+showrole +'&bulkaction='+bulkaction;
2417: var title = '$title';
2418: var options = 'scrollbars=1,resizable=1,menubar=0';
2419: options += ',width=$width,height=$height';
2420: stdeditbrowser = open(url,title,options,'1');
2421: stdeditbrowser.focus();
2422: }
2423: </script>
2424: ENDTWO
2425: return $output;
2426: }
2427:
2428: sub date_section_selector {
2429: my ($context) = @_;
2430: my $callingform = $env{'form.callingform'};
2431: my $formname = 'dateselect';
2432: my $groupslist = &get_groupslist();
2433: my $sec_js = &setsections_javascript($formname,$groupslist);
2434: my $output = <<"END";
2435: <script type="text/javascript">
2436:
2437: $sec_js
2438:
2439: function saveselections(formname) {
2440:
2441: END
2442: if ($env{'form.bulkaction'} eq 'chgsec') {
2443: $output .= <<"END";
2444: opener.document.$callingform.retainsec.value = formname.retainsec.value;
2445: setSections(formname);
2446: if (seccheck == 'ok') {
2447: opener.document.$callingform.newsecs.value = formname.sections.value;
2448: window.close();
2449: }
2450: return;
2451: END
2452: } else {
2453: if ($context eq 'course') {
2454: if (($env{'form.bulkaction'} eq 'reenable') ||
2455: ($env{'form.bulkaction'} eq 'activate') ||
2456: ($env{'form.bulkaction'} eq 'chgdates')) {
2457: $output .= <<"END";
2458:
2459: if (formname.makedatesdefault.checked == true) {
2460: opener.document.$callingform.makedatesdefault.value = 1;
2461: }
2462: else {
2463: opener.document.$callingform.makedatesdefault.value = 0;
2464: }
2465:
2466: END
2467: }
2468: }
2469: $output .= <<"END";
2470: opener.document.$callingform.startdate_month.value = formname.startdate_month.options[formname.startdate_month.selectedIndex].value;
2471: opener.document.$callingform.startdate_day.value = formname.startdate_day.value;
2472: opener.document.$callingform.startdate_year.value = formname.startdate_year.value;
2473: opener.document.$callingform.startdate_hour.value = formname.startdate_hour.options[formname.startdate_hour.selectedIndex].value;
2474: opener.document.$callingform.startdate_minute.value = formname.startdate_minute.value;
2475: opener.document.$callingform.startdate_second.value = formname.startdate_second.value;
2476: opener.document.$callingform.enddate_month.value = formname.enddate_month.options[formname.enddate_month.selectedIndex].value;
2477: opener.document.$callingform.enddate_day.value = formname.enddate_day.value;
2478: opener.document.$callingform.enddate_year.value = formname.enddate_year.value;
2479: opener.document.$callingform.enddate_hour.value = formname.enddate_hour.options[formname.enddate_hour.selectedIndex].value;
2480: opener.document.$callingform.enddate_minute.value = formname.enddate_minute.value;
2481: opener.document.$callingform.enddate_second.value = formname.enddate_second.value;
2482: window.close();
2483: END
2484: }
2485: $output .= '
2486: }
2487: </script>
2488: ';
2489: my %lt = &Apache::lonlocal::texthash (
2490: chac => 'Access dates to apply for selected users',
2491: chse => 'Changes in section affiliation to apply to selected users',
2492: 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.',
2493: 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.',
2494: reta => "Retain each user's current section affiliations?",
2495: dnap => '(Does not apply to student roles).',
2496: );
2497: my ($date_items,$headertext);
2498: if ($env{'form.bulkaction'} eq 'chgsec') {
2499: $headertext = $lt{'chse'};
2500: } else {
2501: $headertext = $lt{'chac'};
2502: my $starttime;
2503: if (($env{'form.bulkaction'} eq 'activate') ||
2504: ($env{'form.bulkaction'} eq 'reenable')) {
2505: $starttime = time;
2506: }
2507: $date_items = &date_setting_table($starttime,undef,$context,
2508: $env{'form.bulkaction'});
2509: }
2510: $output .= '<h3>'.$headertext.'</h3>'.
2511: '<form name="'.$formname.'" method="post">'."\n".
2512: $date_items;
2513: if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
2514: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2515: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2516: my %sections_count =
2517: &Apache::loncommon::get_sections($cdom,$cnum);
2518: my $info;
2519: if ($env{'form.showrole'} eq 'st') {
2520: $output .= '<p>'.$lt{'fors'}.'</p>';
2521: } elsif ($env{'form.shorole'} eq 'Any') {
2522: $output .= '<p>'.$lt{'fors'}.'</p>'.
2523: '<p>'.$lt{'forn'}.' ';
2524: $info = $lt{'reta'};
2525: } else {
2526: $output .= '<p>'.$lt{'forn'}.' ';
2527: $info = $lt{'reta'};
2528: }
2529: if ($info) {
2530: $info .= '<span class="LC_nobreak">'.
2531: '<label><input type="radio" name="retainsec" value="1" '.
2532: 'checked="checked" />'.&mt('Yes').'</label> '.
2533: '<label><input type="radio" name="retainsec" value="0" />'.
2534: &mt('No').'</label></span>';
2535: if ($env{'form.showrole'} eq 'Any') {
2536: $info .= '<br />'.$lt{'dnap'};
2537: }
2538: $info .= '</p>';
2539: } else {
2540: $info = '<input type="hidden" name="retainsec" value="0" />';
2541: }
2542: my $sections_select .= &course_sections(\%sections_count,$env{'form.showrole'});
2543: my $secbox = '<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n".
2544: &Apache::lonhtmlcommon::row_title(&mt('New section to assign'),'LC_oddrow_value')."\n".
2545: '<table class="LC_createuser"><tr class="LC_section_row">'."\n".
2546: '<td align="center">'.&mt('Existing sections')."\n".
2547: '<br />'.$sections_select.'</td><td align="center">'.
2548: &mt('New section').'<br />'."\n".
2549: '<input type="text" name="newsec" size="15" />'."\n".
2550: '<input type="hidden" name="sections" value="" />'."\n".
2551: '</td></tr></table>'."\n".
2552: &Apache::lonhtmlcommon::row_closure(1)."\n".
2553: &Apache::lonhtmlcommon::end_pick_box().'</p>';
2554: $output .= $info.$secbox;
2555: }
2556: $output .= '<p>'.
2557: &mt('Use "Save" to update the main window with your selections.').'<br /><br />'.
2558: '<input type="button" name="dateselection" value="'.&mt('Save').'" onclick="javascript:saveselections(this.form)" /></p>'."\n".
2559: '</form>';
2560: return $output;
2561: }
2562:
2563: sub results_header_row {
2564: my ($rolefilter,$statusmode,$context,$permission) = @_;
2565: my ($description,$showfilter);
2566: if ($rolefilter ne 'Any') {
2567: $showfilter = $rolefilter;
2568: }
2569: if ($context eq 'course') {
2570: $description = &mt('Course - ').$env{'course.'.$env{'request.course.id'}.'.description'}.': ';
2571: if ($statusmode eq 'Expired') {
2572: $description .= &mt('Users in course with expired [_1] roles',$showfilter);
2573: } elsif ($statusmode eq 'Future') {
2574: $description .= &mt('Users in course with future [_1] roles',$showfilter);
2575: } elsif ($statusmode eq 'Active') {
2576: $description .= &mt('Users in course with active [_1] roles',$showfilter);
2577: } else {
2578: if ($rolefilter eq 'Any') {
2579: $description .= &mt('All users in course');
2580: } else {
2581: $description .= &mt('All users in course with [_1] roles',$rolefilter);
2582: }
2583: }
2584: if (exists($permission->{'view_section'})) {
2585: if ($env{'form.showrole'} eq 'st') {
2586: $description .= ' '.&mt('(section [_1] only)',$permission->{'view_section'});
2587: } elsif ($env{'form.showrole'} eq 'any') {
2588: $description .= ' '.&mt('(section [_1] only)',$permission->{'view_section'});
2589: }
2590: }
2591: } elsif ($context eq 'author') {
2592: $description =
2593: &mt('Author space for <span class="LC_cusr_emph">[_1]</span>',
2594: &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'})).': ';
2595: if ($statusmode eq 'Expired') {
2596: $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
2597: } elsif ($statusmode eq 'Future') {
2598: $description .= &mt('Co-authors with future [_1] roles',$showfilter);
2599: } elsif ($statusmode eq 'Active') {
2600: $description .= &mt('Co-authors with active [_1] roles',$showfilter);
2601: } else {
2602: if ($rolefilter eq 'Any') {
2603: $description .= &mt('All co-authors');
2604: } else {
2605: $description .= &mt('All co-authors with [_1] roles',$rolefilter);
2606: }
2607: }
2608: } elsif ($context eq 'domain') {
2609: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
2610: $description = &mt('Domain - ').$domdesc.': ';
2611: if ($env{'form.roletype'} eq 'domain') {
2612: if ($statusmode eq 'Expired') {
2613: $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
2614: } elsif ($statusmode eq 'Future') {
2615: $description .= &mt('Users in domain with future [_1] roles',$showfilter);
2616: } elsif ($statusmode eq 'Active') {
2617: $description .= &mt('Users in domain with active [_1] roles',$showfilter);
2618: } else {
2619: if ($rolefilter eq 'Any') {
2620: $description .= &mt('All users in domain');
2621: } else {
2622: $description .= &mt('All users in domain with [_1] roles',$rolefilter);
2623: }
2624: }
2625: } elsif ($env{'form.roletype'} eq 'author') {
2626: if ($statusmode eq 'Expired') {
2627: $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
2628: } elsif ($statusmode eq 'Future') {
2629: $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
2630: } elsif ($statusmode eq 'Active') {
2631: $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
2632: } else {
2633: if ($rolefilter eq 'Any') {
2634: $description .= &mt('All users with co-author roles in domain',$showfilter);
2635: } else {
2636: $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
2637: }
2638: }
2639: } elsif ($env{'form.roletype'} eq 'course') {
2640: my $coursefilter = $env{'form.coursepick'};
2641: if ($coursefilter eq 'category') {
2642: my $instcode = &instcode_from_coursefilter();
2643: if ($instcode eq '.') {
2644: $description .= &mt('All courses in domain').' - ';
2645: } else {
2646: $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
2647: }
2648: } elsif ($coursefilter eq 'selected') {
2649: $description .= &mt('Selected courses in domain').' - ';
2650: } elsif ($coursefilter eq 'all') {
2651: $description .= &mt('All courses in domain').' - ';
2652: }
2653: if ($statusmode eq 'Expired') {
2654: $description .= &mt('users with expired [_1] roles',$showfilter);
2655: } elsif ($statusmode eq 'Future') {
2656: $description .= &mt('users with future [_1] roles',$showfilter);
2657: } elsif ($statusmode eq 'Active') {
2658: $description .= &mt('users with active [_1] roles',$showfilter);
2659: } else {
2660: if ($rolefilter eq 'Any') {
2661: $description .= &mt('all users');
2662: } else {
2663: $description .= &mt('users with [_1] roles',$rolefilter);
2664: }
2665: }
2666: }
2667: }
2668: return $description;
2669: }
2670:
2671: #################################################
2672: #################################################
2673: sub show_drop_list {
2674: my ($r,$classlist,$keylist,$nosort)=@_;
2675: my $cid=$env{'request.course.id'};
2676: if (! exists($env{'form.sortby'})) {
2677: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2678: ['sortby']);
2679: }
2680: my $sortby = $env{'form.sortby'};
2681: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
2682: $sortby = 'username';
2683: }
2684: my $cdom = $env{'course.'.$cid.'.domain'};
2685: my $cnum = $env{'course.'.$cid,'.num'};
2686: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
2687: $classlist,$keylist,$cdom,$cnum);
2688: #
2689: my $action = "drop";
2690: $r->print(<<END);
2691: <input type="hidden" name="sortby" value="$sortby" />
2692: <input type="hidden" name="action" value="$action" />
2693: <input type="hidden" name="state" value="done" />
2694: <script>
2695: function checkAll(field) {
2696: for (i = 0; i < field.length; i++)
2697: field[i].checked = true ;
2698: }
2699:
2700: function uncheckAll(field) {
2701: for (i = 0; i < field.length; i++)
2702: field[i].checked = false ;
2703: }
2704: </script>
2705: <p>
2706: <input type="hidden" name="phase" value="four">
2707: END
2708:
2709: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
2710: 'dom' => "domain",
2711: 'sn' => "student name",
2712: 'sec' => "section",
2713: 'start' => "start date",
2714: 'end' => "end date",
2715: 'groups' => "active groups",
2716: );
2717: if ($nosort) {
2718: $r->print(&Apache::loncommon::start_data_table());
2719: $r->print(<<END);
2720: <tr>
2721: <th> </th>
2722: <th>$lt{'usrn'}</th>
2723: <th>$lt{'dom'}</th>
2724: <th>ID</th>
2725: <th>$lt{'sn'}</th>
2726: <th>$lt{'sec'}</th>
2727: <th>$lt{'start'}</th>
2728: <th>$lt{'end'}</th>
2729: <th>$lt{'groups'}</th>
2730: </tr>
2731: END
2732:
2733: } else {
2734: $r->print(&Apache::loncommon::start_data_table());
2735: $r->print(<<END);
2736: <tr><th> </th>
2737: <th>
2738: <a href="/adm/dropadd?action=$action&sortby=username">$lt{'usrn'}</a>
2739: </th><th>
2740: <a href="/adm/dropadd?action=$action&sortby=domain">$lt{'dom'}</a>
2741: </th><th>
2742: <a href="/adm/dropadd?action=$action&sortby=id">ID</a>
2743: </th><th>
2744: <a href="/adm/dropadd?action=$action&sortby=fullname">$lt{'sn'}</a>
2745: </th><th>
2746: <a href="/adm/dropadd?action=$action&sortby=section">$lt{'sec'}</a>
2747: </th><th>
2748: <a href="/adm/dropadd?action=$action&sortby=start">$lt{'start'}</a>
2749: </th><th>
2750: <a href="/adm/dropadd?action=$action&sortby=end">$lt{'end'}</a>
2751: </th><th>
2752: <a href="/adm/dropadd?action=$action&sortby=groups">$lt{'groups'}</a>
2753: </th>
2754: </tr>
2755: END
2756: }
2757: #
2758: # Sort the students
2759: my %index;
2760: my $i;
2761: foreach (@$keylist) {
2762: $index{$_} = $i++;
2763: }
2764: $index{'groups'} = scalar(@$keylist);
2765: my $index = $index{$sortby};
2766: my $second = $index{'username'};
2767: my $third = $index{'domain'};
2768: my @Sorted_Students = sort {
2769: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
2770: ||
2771: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
2772: ||
2773: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
2774: } (keys(%$classlist));
2775: foreach my $student (@Sorted_Students) {
2776: my $error;
2777: my $sdata = $classlist->{$student};
2778: my $username = $sdata->[$index{'username'}];
2779: my $domain = $sdata->[$index{'domain'}];
2780: my $section = $sdata->[$index{'section'}];
2781: my $name = $sdata->[$index{'fullname'}];
2782: my $id = $sdata->[$index{'id'}];
2783: my $start = $sdata->[$index{'start'}];
2784: my $end = $sdata->[$index{'end'}];
2785: my $groups = $classgroups->{$student};
2786: my $active_groups;
2787: if (ref($groups->{active}) eq 'HASH') {
2788: $active_groups = join(', ',keys(%{$groups->{'active'}}));
2789: }
2790: if (! defined($start) || $start == 0) {
2791: $start = &mt('none');
2792: } else {
2793: $start = &Apache::lonlocal::locallocaltime($start);
2794: }
2795: if (! defined($end) || $end == 0) {
2796: $end = &mt('none');
2797: } else {
2798: $end = &Apache::lonlocal::locallocaltime($end);
2799: }
2800: my $status = $sdata->[$index{'status'}];
2801: next if ($status ne 'Active');
2802: #
2803: $r->print(&Apache::loncommon::start_data_table_row());
2804: $r->print(<<"END");
2805: <td><input type="checkbox" name="droplist" value="$student"></td>
2806: <td>$username</td>
2807: <td>$domain</td>
2808: <td>$id</td>
2809: <td>$name</td>
2810: <td>$section</td>
2811: <td>$start</td>
2812: <td>$end</td>
2813: <td>$active_groups</td>
2814: END
2815: $r->print(&Apache::loncommon::end_data_table_row());
2816: }
2817: $r->print(&Apache::loncommon::end_data_table().'<br />');
2818: %lt=&Apache::lonlocal::texthash(
2819: 'dp' => "Expire Users' Roles",
2820: 'ca' => "check all",
2821: 'ua' => "uncheck all",
2822: );
2823: $r->print(<<"END");
2824: </p><p>
2825: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)">
2826: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)">
2827: <p><input type=submit value="$lt{'dp'}"></p>
2828: END
2829: return;
2830: }
2831:
2832: #
2833: # Print out the initial form to get the file containing a list of users
2834: #
2835: sub print_first_users_upload_form {
2836: my ($r,$context) = @_;
2837: my $str;
2838: $str = '<input type="hidden" name="phase" value="two">';
2839: $str .= '<input type="hidden" name="action" value="upload" />';
2840: $str .= '<input type="hidden" name="state" value="got_file" />';
2841: $str .= "<h3>".&mt('Upload a file containing information about users')."</h3>\n";
2842: $str .= &Apache::loncommon::upfile_select_html();
2843: $str .= "<p>\n";
2844: $str .= '<input type="submit" name="fileupload" value="'.
2845: &mt('Upload file of users').'">'."\n";
2846: $str .= '<label><input type="checkbox" name="noFirstLine" /> '.
2847: &mt('Ignore First Line')."</label></p>\n";
2848: $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List",
2849: &mt("How do I create a users list from a spreadsheet")).
2850: "<br />\n";
2851: $str .= &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
2852: &mt("How do I create a CSV file from a spreadsheet")).
2853: "<br />\n";
2854: $str .= &Apache::loncommon::end_page();
2855: $r->print($str);
2856: return;
2857: }
2858:
2859: # ================================================= Drop/Add from uploaded file
2860: sub upfile_drop_add {
2861: my ($r,$context) = @_;
2862: &Apache::loncommon::load_tmp_file($r);
2863: my @userdata=&Apache::loncommon::upfile_record_sep();
2864: if($env{'form.noFirstLine'}){shift(@userdata);}
2865: my @keyfields = split(/\,/,$env{'form.keyfields'});
2866: my %fields=();
2867: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
2868: if ($env{'form.upfile_associate'} eq 'reverse') {
2869: if ($env{'form.f'.$i} ne 'none') {
2870: $fields{$keyfields[$i]}=$env{'form.f'.$i};
2871: }
2872: } else {
2873: $fields{$env{'form.f'.$i}}=$keyfields[$i];
2874: }
2875: }
2876: #
2877: # Store the field choices away
2878: foreach my $field (qw/username names
2879: fname mname lname gen id sec ipwd email role/) {
2880: $env{'form.'.$field.'_choice'}=$fields{$field};
2881: }
2882: &Apache::loncommon::store_course_settings('enrollment_upload',
2883: { 'username_choice' => 'scalar',
2884: 'names_choice' => 'scalar',
2885: 'fname_choice' => 'scalar',
2886: 'mname_choice' => 'scalar',
2887: 'lname_choice' => 'scalar',
2888: 'gen_choice' => 'scalar',
2889: 'id_choice' => 'scalar',
2890: 'sec_choice' => 'scalar',
2891: 'ipwd_choice' => 'scalar',
2892: 'email_choice' => 'scalar',
2893: 'role_choice' => 'scalar' });
2894: #
2895: my ($startdate,$enddate) = &get_dates_from_form();
2896: if ($env{'form.makedatesdefault'}) {
2897: $r->print(&make_dates_default($startdate,$enddate));
2898: }
2899: # Determine domain and desired host (home server)
2900: my $domain=$env{'request.role.domain'};
2901: my $desiredhost = $env{'form.lcserver'};
2902: if (lc($desiredhost) eq 'default') {
2903: $desiredhost = undef;
2904: } else {
2905: my %home_servers = &Apache::lonnet::get_servers($domain,'library');
2906: if (! exists($home_servers{$desiredhost})) {
2907: $r->print('<span class="LC_error">'.&mt('Error').
2908: &mt('Invalid home server specified').'</span>');
2909: $r->print(&Apache::loncommon::end_page());
2910: return;
2911: }
2912: }
2913: # Determine authentication mechanism
2914: my $changeauth;
2915: if ($context eq 'domain') {
2916: $changeauth = $env{'form.changeauth'};
2917: }
2918: my $amode = '';
2919: my $genpwd = '';
2920: if ($env{'form.login'} eq 'krb') {
2921: $amode='krb';
2922: $amode.=$env{'form.krbver'};
2923: $genpwd=$env{'form.krbarg'};
2924: } elsif ($env{'form.login'} eq 'int') {
2925: $amode='internal';
2926: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
2927: $genpwd=$env{'form.intarg'};
2928: }
2929: } elsif ($env{'form.login'} eq 'loc') {
2930: $amode='localauth';
2931: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
2932: $genpwd=$env{'form.locarg'};
2933: }
2934: }
2935: if ($amode =~ /^krb/) {
2936: if (! defined($genpwd) || $genpwd eq '') {
2937: $r->print('<span class="Error">'.
2938: &mt('Unable to enroll users').' '.
2939: &mt('No Kerberos domain was specified.').'</span></p>');
2940: $amode = ''; # This causes the loop below to be skipped
2941: }
2942: }
2943: my ($cid,$defaultsec,$defaultrole,$setting);
2944: if ($context eq 'domain') {
2945: $setting = $env{'form.roleaction'};
2946: if ($setting eq 'domain') {
2947: $defaultrole = $env{'form.defaultrole'};
2948: } elsif ($setting eq 'course') {
2949: $defaultrole = $env{'form.courserole'};
2950: }
2951: } elsif ($context eq 'author') {
2952: $defaultrole = $env{'form.defaultrole'};
2953: }
2954: if ($context eq 'domain' && $setting eq 'course') {
2955: if ($env{'form.newsec'} ne '') {
2956: $defaultsec = $env{'form.newsec'};
2957: } elsif ($env{'form.defaultsec'} ne '') {
2958: $defaultsec = $env{'form.defaultsec'}
2959: }
2960: }
2961: if ($env{'request.course.id'} ne '') {
2962: $cid = $env{'request.course.id'};
2963: } elsif ($env{'form.defaultdomain'} ne '' && $env{'form.defaultcourse'} ne '') {
2964: $cid = $env{'form.defaultdomain'}.'_'.
2965: $env{'form.defaultcourse'};
2966: }
2967: if ( $domain eq &LONCAPA::clean_domain($domain)
2968: && ($amode ne '')) {
2969: #######################################
2970: ## Add/Modify Users ##
2971: #######################################
2972: if ($context eq 'course') {
2973: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
2974: } elsif ($context eq 'author') {
2975: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
2976: } else {
2977: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
2978: }
2979: my %counts = (
2980: user => 0,
2981: auth => 0,
2982: role => 0,
2983: );
2984: my $flushc=0;
2985: my %student=();
2986: my %curr_groups;
2987: my %userchg;
2988: if ($context eq 'course') {
2989: # Get information about course groups
2990: %curr_groups = &Apache::longroup::coursegroups();
2991: }
2992: my (%curr_rules,%got_rules,%alerts);
2993: # Get new users list
2994: foreach (@userdata) {
2995: my %entries=&Apache::loncommon::record_sep($_);
2996: # Determine user name
2997: unless (($entries{$fields{'username'}} eq '') ||
2998: (!defined($entries{$fields{'username'}}))) {
2999: my ($fname, $mname, $lname,$gen) = ('','','','');
3000: if (defined($fields{'names'})) {
3001: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
3002: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
3003: } else {
3004: if (defined($fields{'fname'})) {
3005: $fname=$entries{$fields{'fname'}};
3006: }
3007: if (defined($fields{'mname'})) {
3008: $mname=$entries{$fields{'mname'}};
3009: }
3010: if (defined($fields{'lname'})) {
3011: $lname=$entries{$fields{'lname'}};
3012: }
3013: if (defined($fields{'gen'})) {
3014: $gen=$entries{$fields{'gen'}};
3015: }
3016: }
3017: if ($entries{$fields{'username'}}
3018: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
3019: $r->print('<br />'.
3020: &mt('<b>[_1]</b>: Unacceptable username for user [_2] [_3] [_4] [_5]',
3021: $entries{$fields{'username'}},$fname,$mname,$lname,$gen).
3022: '</b>');
3023: } else {
3024: my $username = $entries{$fields{'username'}};
3025: my $sec;
3026: if ($context eq 'course' || $setting eq 'course') {
3027: # determine section number
3028: if (defined($fields{'sec'})) {
3029: if (defined($entries{$fields{'sec'}})) {
3030: $sec=$entries{$fields{'sec'}};
3031: }
3032: } else {
3033: $sec = $defaultsec;
3034: }
3035: # remove non alphanumeric values from section
3036: $sec =~ s/\W//g;
3037: if ($sec eq "none" || $sec eq 'all') {
3038: $r->print('<br />'.
3039: &mt('<b>[_1]</b>: Unable to enroll: section name "[_2]" for user [_3] [_4] [_5] [_6] is a reserved word.',
3040: $username,$sec,$fname,$mname,$lname,$gen));
3041: next;
3042: } elsif (($sec ne '') && (exists($curr_groups{$sec}))) {
3043: $r->print('<br />'.
3044: &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.',
3045: $username,$sec,$fname,$mname,$lname,$gen));
3046: next;
3047: }
3048: }
3049: # determine id number
3050: my $id='';
3051: if (defined($fields{'id'})) {
3052: if (defined($entries{$fields{'id'}})) {
3053: $id=$entries{$fields{'id'}};
3054: }
3055: $id=~tr/A-Z/a-z/;
3056: }
3057: # determine email address
3058: my $email='';
3059: if (defined($fields{'email'})) {
3060: if (defined($entries{$fields{'email'}})) {
3061: $email=$entries{$fields{'email'}};
3062: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; } }
3063: }
3064: # determine user password
3065: my $password = $genpwd;
3066: if (defined($fields{'ipwd'})) {
3067: if ($entries{$fields{'ipwd'}}) {
3068: $password=$entries{$fields{'ipwd'}};
3069: }
3070: }
3071: # determine user role
3072: my $role = '';
3073: if (defined($fields{'role'})) {
3074: if ($entries{$fields{'role'}}) {
3075: my @poss_roles =
3076: &curr_role_permissions($context,$setting);
3077: if (grep(/^\Q$entries{$fields{'role'}}\E/,@poss_roles)) {
3078: $role=$entries{$fields{'role'}};
3079: } else {
3080: my $rolestr = join(', ',@poss_roles);
3081: $r->print('<br />'.
3082: &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");
3083: next;
3084: }
3085: }
3086: }
3087: if ($role eq '') {
3088: $role = $defaultrole;
3089: }
3090: # Clean up whitespace
3091: foreach (\$domain,\$username,\$id,\$fname,\$mname,
3092: \$lname,\$gen,\$sec,\$role) {
3093: $$_ =~ s/(\s+$|^\s+)//g;
3094: }
3095: # check against rules
3096: my $checkid = 0;
3097: my $newuser = 0;
3098: my (%rulematch,%inst_results,%idinst_results);
3099: my $uhome=&Apache::lonnet::homeserver($username,$domain);
3100: if ($uhome eq 'no_host') {
3101: $checkid = 1;
3102: $newuser = 1;
3103: my $checkhash;
3104: my $checks = { 'username' => 1 };
3105: $checkhash->{$username.':'.$domain} = { 'newuser' => 1, };
3106: &Apache::loncommon::user_rule_check($checkhash,$checks,
3107: \%alerts,\%rulematch,\%inst_results,\%curr_rules,
3108: \%got_rules);
3109: if (ref($alerts{'username'}) eq 'HASH') {
3110: if (ref($alerts{'username'}{$domain}) eq 'HASH') {
3111: next if ($alerts{'username'}{$domain}{$username});
3112: }
3113: }
3114: } else {
3115: # FIXME check if user info can be updated.
3116: }
3117: if ($id ne '') {
3118: if (!$newuser) {
3119: my %idhash = &Apache::lonnet::idrget($domain,($username));
3120: if ($idhash{$username} ne $id) {
3121: $checkid = 1;
3122: }
3123: }
3124: if ($checkid) {
3125: my $checkhash;
3126: my $checks = { 'id' => 1 };
3127: $checkhash->{$username.':'.$domain} = { 'newuser' => $newuser,
3128: 'id' => $id };
3129: &Apache::loncommon::user_rule_check($checkhash,$checks,
3130: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,
3131: \%got_rules);
3132: if (ref($alerts{'id'}) eq 'HASH') {
3133: if (ref($alerts{'id'}{$domain}) eq 'HASH') {
3134: next if ($alerts{'id'}{$domain}{$id});
3135: }
3136: }
3137: }
3138: }
3139: if ($password || $env{'form.login'} eq 'loc') {
3140: my ($userresult,$authresult,$roleresult);
3141: if ($role eq 'st') {
3142: &modifystudent($domain,$username,$cid,$sec,
3143: $desiredhost);
3144: $roleresult =
3145: &Apache::lonnet::modifystudent
3146: ($domain,$username,$id,$amode,$password,
3147: $fname,$mname,$lname,$gen,$sec,$enddate,
3148: $startdate,$env{'form.forceid'},
3149: $desiredhost,$email);
3150: } else {
3151: ($userresult,$authresult,$roleresult) =
3152: &modifyuserrole($context,$setting,
3153: $changeauth,$cid,$domain,$username,
3154: $id,$amode,$password,$fname,
3155: $mname,$lname,$gen,$sec,
3156: $env{'form.forceid'},$desiredhost,
3157: $email,$role,$enddate,$startdate,$checkid);
3158: }
3159: $flushc =
3160: &user_change_result($r,$userresult,$authresult,
3161: $roleresult,\%counts,$flushc,
3162: $username,%userchg);
3163: } else {
3164: if ($context eq 'course') {
3165: $r->print('<br />'.
3166: &mt('<b>[_1]</b>: Unable to enroll. No password specified.',$username)
3167: );
3168: } elsif ($context eq 'author') {
3169: $r->print('<br />'.
3170: &mt('<b>[_1]</b>: Unable to add co-author. No password specified.',$username)
3171: );
3172: } else {
3173: $r->print('<br />'.
3174: &mt('<b>[_1]</b>: Unable to add user. No password specified.',$username)
3175: );
3176: }
3177: }
3178: }
3179: }
3180: } # end of foreach (@userdata)
3181: # Flush the course logs so reverse user roles immediately updated
3182: &Apache::lonnet::flushcourselogs();
3183: $r->print("</p>\n<p>\n".&mt('Processed [_1] user(s).',$counts{'user'}).
3184: "</p>\n");
3185: if ($counts{'role'} > 0) {
3186: $r->print("<p>\n".
3187: &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");
3188: }
3189: if ($counts{'auth'} > 0) {
3190: $r->print("<p>\n".
3191: &mt('Authentication changed for [_1] existing users.',
3192: $counts{'auth'})."</p>\n");
3193: }
3194: $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
3195: $r->print('<form name="uploadresult" action="/adm/createuser">');
3196: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','prevphase','currstate']));
3197: $r->print('</form>');
3198: #####################################
3199: # Drop students #
3200: #####################################
3201: if ($env{'form.fullup'} eq 'yes') {
3202: $r->print('<h3>'.&mt('Dropping Students')."</h3>\n");
3203: # Get current classlist
3204: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
3205: if (! defined($classlist)) {
3206: $r->print(&mt('There are no students currently enrolled.').
3207: "\n");
3208: } else {
3209: # Remove the students we just added from the list of students.
3210: foreach (@userdata) {
3211: my %entries=&Apache::loncommon::record_sep($_);
3212: unless (($entries{$fields{'username'}} eq '') ||
3213: (!defined($entries{$fields{'username'}}))) {
3214: delete($classlist->{$entries{$fields{'username'}}.
3215: ':'.$domain});
3216: }
3217: }
3218: # Print out list of dropped students.
3219: &show_drop_list($r,$classlist,$keylist,'nosort');
3220: }
3221: }
3222: } # end of unless
3223: }
3224:
3225: sub print_namespacing_alerts {
3226: my ($domain,$alerts,$curr_rules) = @_;
3227: my $output;
3228: if (ref($alerts) eq 'HASH') {
3229: if (keys(%{$alerts}) > 0) {
3230: if (ref($alerts->{'username'}) eq 'HASH') {
3231: foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
3232: my $count;
3233: if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
3234: $count = keys(%{$alerts->{'username'}{$dom}});
3235: }
3236: my $domdesc = &Apache::lonnet::domain($domain,'description');
3237: if (ref($curr_rules->{$dom}) eq 'HASH') {
3238: $output .= &Apache::loncommon::instrule_disallow_msg(
3239: 'username',$domdesc,$count,'upload');
3240: }
3241: $output .= &Apache::loncommon::user_rule_formats($dom,
3242: $domdesc,$curr_rules->{$dom}{'username'},
3243: 'username');
3244: }
3245: }
3246: if (ref($alerts->{'id'}) eq 'HASH') {
3247: foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
3248: my $count;
3249: if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
3250: $count = keys(%{$alerts->{'id'}{$dom}});
3251: }
3252: my $domdesc = &Apache::lonnet::domain($domain,'description');
3253: if (ref($curr_rules->{$dom}) eq 'HASH') {
3254: $output .= &Apache::loncommon::instrule_disallow_msg(
3255: 'id',$domdesc,$count,'upload');
3256: }
3257: $output .= &Apache::loncommon::user_rule_formats($dom,
3258: $domdesc,$curr_rules->{$dom}{'id'},'id');
3259: }
3260: }
3261: }
3262: }
3263: }
3264:
3265: sub user_change_result {
3266: my ($r,$userresult,$authresult,$roleresult,$counts,$flushc,$username,
3267: $userchg) = @_;
3268: my $okresult = 0;
3269: if ($userresult ne 'ok') {
3270: if ($userresult =~ /^error:(.+)$/) {
3271: my $error = $1;
3272: $r->print('<br />'.
3273: &mt('<b>[_1]</b>: Unable to add/modify: [_2]',$username,$error));
3274: }
3275: } else {
3276: $counts->{'user'} ++;
3277: $okresult = 1;
3278: }
3279: if ($authresult ne 'ok') {
3280: if ($authresult =~ /^error:(.+)$/) {
3281: my $error = $1;
3282: $r->print('<br />'.
3283: &mt('<b>[_1]</b>: Unable to modify authentication: [_2]',$username,$error));
3284: }
3285: } else {
3286: $counts->{'auth'} ++;
3287: $okresult = 1;
3288: }
3289: if ($roleresult ne 'ok') {
3290: if ($roleresult =~ /^error:(.+)$/) {
3291: my $error = $1;
3292: $r->print('<br />'.
3293: &mt('<b>[_1]</b>: Unable to add role: [_2]',$username,$error));
3294: }
3295: } else {
3296: $counts->{'role'} ++;
3297: $okresult = 1;
3298: }
3299: if ($okresult) {
3300: $flushc++;
3301: $userchg->{$username}=1;
3302: $r->print('. ');
3303: if ($flushc>15) {
3304: $r->rflush;
3305: $flushc=0;
3306: }
3307: }
3308: return $flushc;
3309: }
3310:
3311: # ========================================================= Menu Phase Two Drop
3312: sub print_expire_menu {
3313: my ($r,$context) = @_;
3314: $r->print("<h3>".&mt("Expire Users' Roles")."</h3>");
3315: my $cid=$env{'request.course.id'};
3316: my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
3317: if (! defined($classlist)) {
3318: $r->print(&mt('There are no students currently enrolled.')."\n");
3319: return;
3320: }
3321: # Print out the available choices
3322: &show_drop_list($r,$classlist,$keylist);
3323: return;
3324: }
3325:
3326:
3327: # ================================================================== Phase four
3328:
3329: sub update_user_list {
3330: my ($r,$context,$setting,$choice) = @_;
3331: my $now = time;
3332: my $count=0;
3333: my @changelist;
3334: if ($choice ne '') {
3335: @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
3336: } else {
3337: @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
3338: }
3339: my %result_text = ( ok => { 'revoke' => 'Revoked',
3340: 'delete' => 'Deleted',
3341: 'reenable' => 'Re-enabled',
3342: 'activate' => 'Activated',
3343: },
3344: error => {'revoke' => 'revoking',
3345: 'delete' => 'deleting',
3346: 'reenable' => 're-enabling',
3347: 'activate' => 'activating',
3348: },
3349: );
3350: my ($startdate,$enddate);
3351: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
3352: ($startdate,$enddate) = &get_dates_from_form();
3353: }
3354: foreach my $item (@changelist) {
3355: my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,@sections,
3356: $scopestem);
3357: if ($context eq 'course') {
3358: ($uname,$udom,$role,$sec,$type,$locktype) = split(/\:/,$item,-1);
3359: $cid = $env{'request.course.id'};
3360: $scopestem = '/'.$cid;
3361: $scopestem =~s/\_/\//g;
3362: if ($sec eq '') {
3363: $scope = $scopestem;
3364: } else {
3365: $scope = $scopestem.'/'.$sec;
3366: }
3367: } elsif ($context eq 'author') {
3368: ($uname,$udom,$role) = split(/\:/,$item,-1);
3369: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
3370: } elsif ($context eq 'domain') {
3371: if ($setting eq 'domain') {
3372: ($role,$uname,$udom) = split(/\:/,$item,-1);
3373: $scope = '/'.$env{'request.role.domain'}.'/';
3374: } elsif ($setting eq 'author') {
3375: ($uname,$udom,$role,$scope) = split(/\:/,$item);
3376: } elsif ($setting eq 'course') {
3377: ($uname,$udom,$role,$cid,$sec,$type,$locktype) =
3378: split(/\:/,$item);
3379: $scope = '/'.$cid;
3380: $scope =~s/\_/\//g;
3381: if ($sec ne '') {
3382: $scope .= '/'.$sec;
3383: }
3384: }
3385: }
3386: my $plrole = &Apache::lonnet::plaintext($role);
3387: my ($uid,$first,$middle,$last,$gene,$sec);
3388: my $start = $env{'form.'.$item.'_start'};
3389: my $end = $env{'form.'.$item.'_end'};
3390: # revoke or delete user role
3391: if ($choice eq 'revoke') {
3392: $end = $now;
3393: if ($role eq 'st') {
3394: $result =
3395: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
3396: } else {
3397: $result =
3398: &Apache::lonnet::revokerole($udom,$uname,$scope,$role);
3399: }
3400: } elsif ($choice eq 'delete') {
3401: $start = -1;
3402: $end = -1;
3403: if ($role eq 'st') {
3404: # FIXME - how does role deletion affect classlist?
3405: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
3406: } else {
3407: $result =
3408: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
3409: 0,1);
3410: }
3411: } else {
3412: #reenable, activate, change access dates or change section
3413: if ($choice ne 'chgsec') {
3414: $start = $startdate;
3415: $end = $enddate;
3416: }
3417: if ($choice eq 'reenable') {
3418: if ($role eq 'st') {
3419: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
3420: } else {
3421: $result =
3422: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
3423: $now);
3424: }
3425: } elsif ($choice eq 'activate') {
3426: if ($role eq 'st') {
3427: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
3428: } else {
3429: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
3430: $now);
3431: }
3432: } elsif ($choice eq 'chgdates') {
3433: if ($role eq 'st') {
3434: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
3435: } else {
3436: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
3437: $start);
3438: }
3439: } elsif ($choice eq 'chgsec') {
3440: my (@newsecs,$revresult,$nochg,@retained);
3441: if ($role ne 'cc') {
3442: @newsecs = split(/,/,$env{'form.newsecs'});
3443: }
3444: # remove existing section if not to be retained.
3445: if (!$env{'form.retainsec'}) {
3446: if ($sec eq '') {
3447: if (@newsecs == 0) {
3448: $result = &mt('No change in section assignment (none)');
3449: $nochg = 1;
3450: }
3451: } else {
3452: if (!grep(/^\Q$sec\E$/,@newsecs)) {
3453: $revresult =
3454: &Apache::lonnet::revokerole($udom,$uname,$scope,$role);
3455: } else {
3456: push(@retained,$sec);
3457: }
3458: }
3459: } else {
3460: push(@retained,$sec);
3461: }
3462: # add new sections
3463: if (@newsecs == 0) {
3464: if (!$nochg) {
3465: if ($sec ne '') {
3466: if ($role eq 'st') {
3467: $result =
3468: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid);
3469: } else {
3470: my $newscope = $scopestem;
3471: $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start);
3472: }
3473: }
3474: }
3475: } else {
3476: foreach my $newsec (@newsecs) {
3477: if (!grep(/^\Q$newsec\E$/,@retained)) {
3478: if ($role eq 'st') {
3479: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid);
3480: } else {
3481: my $newscope = $scopestem;
3482: if ($newsec ne '') {
3483: $newscope .= '/'.$newsec;
3484: }
3485: $result = &Apache::lonnet::assignrole($udom,$uname,
3486: $newscope,$role,$end,$start);
3487: }
3488: }
3489: }
3490: }
3491: }
3492: }
3493: if ($result eq 'ok' || $result eq 'ok:') {
3494: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]",
3495: $plrole,$scope,$uname.':'.$udom).'<br />');
3496: $count++;
3497: } else {
3498: $r->print(
3499: &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]:[_4]",
3500: $plrole,$scope,$uname.':'.$udom,$result).'<br />');
3501: }
3502: }
3503: $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,users].",$count).'</b></p>');
3504: if ($count > 0) {
3505: if ($choice eq 'revoke') {
3506: $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.</p>'));
3507: }
3508: # Flush the course logs so reverse user roles immediately updated
3509: &Apache::lonnet::flushcourselogs();
3510: }
3511: if ($env{'form.makedatesdefault'}) {
3512: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
3513: $r->print(&make_dates_default($startdate,$enddate));
3514: }
3515: }
3516: }
3517:
3518: sub classlist_drop {
3519: my ($scope,$uname,$udom,$now,$action) = @_;
3520: my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
3521: my $cid=$cdom.'_'.$cnum;
3522: my $user = $uname.':'.$udom;
3523: if ($action eq 'drop') {
3524: if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
3525: my $result =
3526: &Apache::lonnet::cput('classlist',
3527: { $user => $now },
3528: $env{'course.'.$cid.'.domain'},
3529: $env{'course.'.$cid.'.num'});
3530: return &mt('Drop from classlist: [_1]',
3531: '<b>'.$result.'</b>').'<br />';
3532: }
3533: }
3534: }
3535:
3536: sub active_student_roles {
3537: my ($cnum,$cdom,$uname,$udom) = @_;
3538: my %roles =
3539: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
3540: ['future','active'],['st']);
3541: return exists($roles{"$cnum:$cdom:st"});
3542: }
3543:
3544: sub section_check_js {
3545: my $groupslist= &get_groupslist();
3546: return <<"END";
3547: function validate(caller) {
3548: var groups = new Array($groupslist);
3549: var secname = caller.value;
3550: if ((secname == 'all') || (secname == 'none')) {
3551: alert("'"+secname+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
3552: return 'error';
3553: }
3554: if (secname != '') {
3555: for (var k=0; k<groups.length; k++) {
3556: if (secname == groups[k]) {
3557: 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.");
3558: return 'error';
3559: }
3560: }
3561: }
3562: return 'ok';
3563: }
3564: END
3565: }
3566:
3567: sub set_login {
3568: my ($dom,$authformkrb,$authformint,$authformloc) = @_;
3569: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3570: my $response;
3571: my ($authnum,%can_assign) =
3572: &Apache::loncommon::get_assignable_auth($dom);
3573: if ($authnum) {
3574: $response = &Apache::loncommon::start_data_table();
3575: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
3576: $response .= &Apache::loncommon::start_data_table_row().
3577: '<td>'.$authformkrb.'</td>'.
3578: &Apache::loncommon::end_data_table_row()."\n";
3579: }
3580: if ($can_assign{'int'}) {
3581: $response .= &Apache::loncommon::start_data_table_row().
3582: '<td>'.$authformint.'</td>'.
3583: &Apache::loncommon::end_data_table_row()."\n"
3584: }
3585: if ($can_assign{'loc'}) {
3586: $response .= &Apache::loncommon::start_data_table_row().
3587: '<td>'.$authformloc.'</td>'.
3588: &Apache::loncommon::end_data_table_row()."\n";
3589: }
3590: $response .= &Apache::loncommon::end_data_table();
3591: }
3592: return $response;
3593: }
3594:
3595: sub course_sections {
3596: my ($sections_count,$role) = @_;
3597: my $output = '';
3598: my @sections = (sort {$a <=> $b} keys %{$sections_count});
3599: if (scalar(@sections) == 1) {
3600: $output = '<select name="currsec_'.$role.'" >'."\n".
3601: ' <option value="">Select</option>'."\n".
3602: ' <option value="">No section</option>'."\n".
3603: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
3604: } else {
3605: $output = '<select name="currsec_'.$role.'" ';
3606: my $multiple = 4;
3607: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
3608: $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
3609: foreach my $sec (@sections) {
3610: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
3611: }
3612: }
3613: $output .= '</select>';
3614: return $output;
3615: }
3616:
3617: sub get_groupslist {
3618: my $groupslist;
3619: my %curr_groups = &Apache::longroup::coursegroups();
3620: if (%curr_groups) {
3621: $groupslist = join('","',sort(keys(%curr_groups)));
3622: $groupslist = '"'.$groupslist.'"';
3623: }
3624: return $groupslist;
3625: }
3626:
3627: sub setsections_javascript {
3628: my ($form,$groupslist) = @_;
3629: my ($checkincluded,$finish,$roleplace,$setsection_js);
3630: if ($form eq 'cu') {
3631: $checkincluded = 'formname.elements[i-1].checked == true';
3632: $finish = 'formname.submit()';
3633: $roleplace = 3;
3634: } else {
3635: $checkincluded = 'formname.name == "'.$form.'"';
3636: $finish = "seccheck = 'ok';";
3637: $roleplace = 1;
3638: $setsection_js = "var seccheck = 'alert';";
3639: }
3640: my %alerts = &Apache::lonlocal::texthash(
3641: secd => 'Section designations do not apply to Course Coordinator roles.',
3642: accr => 'A course coordinator role will be added with access to all sections.',
3643: inea => 'In each course, each user may only have one student role at a time.',
3644: youh => 'You had selected ',
3645: secs => 'sections.',
3646: plmo => 'Please modify your selections so they include no more than one section.',
3647: mayn => 'may not be used as the name for a section, as it is a reserved word.',
3648: plch => 'Please choose a different section name.',
3649: mnot => 'may not be used as a section name, as it is the name of a course group.',
3650: secn => 'Section names and group names must be distinct. Please choose a different section name.',
3651: );
3652: $setsection_js .= <<"ENDSECCODE";
3653:
3654: function setSections(formname) {
3655: var re1 = /^currsec_/;
3656: var groups = new Array($groupslist);
3657: for (var i=0;i<formname.elements.length;i++) {
3658: var str = formname.elements[i].name;
3659: var checkcurr = str.match(re1);
3660: if (checkcurr != null) {
3661: if ($checkincluded) {
3662: var match = str.split('_');
3663: var role = match[$roleplace];
3664: if (role == 'cc') {
3665: alert("$alerts{'secd'}\\n$alerts{'accr'}");
3666: }
3667: else {
3668: var sections = '';
3669: var numsec = 0;
3670: var sections;
3671: for (var j=0; j<formname.elements[i].length; j++) {
3672: if (formname.elements[i].options[j].selected == true ) {
3673: if (formname.elements[i].options[j].value != "") {
3674: if (numsec == 0) {
3675: if (formname.elements[i].options[j].value != "") {
3676: sections = formname.elements[i].options[j].value;
3677: numsec ++;
3678: }
3679: }
3680: else {
3681: sections = sections + "," + formname.elements[i].options[j].value
3682: numsec ++;
3683: }
3684: }
3685: }
3686: }
3687: if (numsec > 0) {
3688: if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) {
3689: sections = sections + "," + formname.elements[i+1].value;
3690: }
3691: }
3692: else {
3693: sections = formname.elements[i+1].value;
3694: }
3695: var newsecs = formname.elements[i+1].value;
3696: var numsplit;
3697: if (newsecs != null && newsecs != "") {
3698: numsplit = newsecs.split(/,/g);
3699: numsec = numsec + numsplit.length;
3700: }
3701:
3702: if ((role == 'st') && (numsec > 1)) {
3703: alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}")
3704: return;
3705: }
3706: else {
3707: if (numsplit != null) {
3708: for (var j=0; j<numsplit.length; j++) {
3709: if ((numsplit[j] == 'all') ||
3710: (numsplit[j] == 'none')) {
3711: alert("'"+numsplit[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
3712: return;
3713: }
3714: for (var k=0; k<groups.length; k++) {
3715: if (numsplit[j] == groups[k]) {
3716: alert("'"+numsplit[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
3717: return;
3718: }
3719: }
3720: }
3721: }
3722: formname.elements[i+2].value = sections;
3723: }
3724: }
3725: }
3726: }
3727: }
3728: $finish
3729: }
3730: ENDSECCODE
3731: return $setsection_js;
3732: }
3733:
3734: sub can_create_user {
3735: my ($dom,$context,$usertype) = @_;
3736: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3737: my $cancreate = 1;
3738: if (ref($domconf{'usercreation'}) eq 'HASH') {
3739: if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
3740: if ($context eq 'course' || $context eq 'author') {
3741: my $creation = $domconf{'usercreation'}{'cancreate'}{$context};
3742: if ($creation eq 'none') {
3743: $cancreate = 0;
3744: } elsif ($creation ne 'any') {
3745: if (defined($usertype)) {
3746: if ($creation ne $usertype) {
3747: $cancreate = 0;
3748: }
3749: }
3750: }
3751: }
3752: }
3753: }
3754: return $cancreate;
3755: }
3756:
3757: sub get_permission {
3758: my ($context) = @_;
3759: my %permission;
3760: if ($context eq 'course') {
3761: if ((&Apache::lonnet::allowed('cta',$env{'request.course.id'})) ||
3762: (&Apache::lonnet::allowed('cin',$env{'request.course.id'})) ||
3763: (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) ||
3764: (&Apache::lonnet::allowed('cep',$env{'request.course.id'})) ||
3765: (&Apache::lonnet::allowed('cst',$env{'request.course.id'}))) {
3766: $permission{'cusr'} = 1;
3767: $permission{'view'} =
3768: &Apache::lonnet::allowed('vcl',$env{'request.course.id'});
3769:
3770: }
3771: if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
3772: $permission{'custom'} = 1;
3773: }
3774: if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
3775: $permission{'view'} = 1;
3776: }
3777: if (!$permission{'view'}) {
3778: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
3779: $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
3780: if ($permission{'view'}) {
3781: $permission{'view_section'} = $env{'request.course.sec'};
3782: }
3783: }
3784: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
3785: $permission{'grp_manage'} = 1;
3786: }
3787: } elsif ($context eq 'author') {
3788: $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
3789: $permission{'view'} = $permission{'cusr'};
3790: } else {
3791: if ((&Apache::lonnet::allowed('cad',$env{'request.role.domain'})) ||
3792: (&Apache::lonnet::allowed('cli',$env{'request.role.domain'})) ||
3793: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
3794: (&Apache::lonnet::allowed('csc',$env{'request.role.domain'})) ||
3795: (&Apache::lonnet::allowed('cdg',$env{'request.role.domain'})) ||
3796: (&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))) {
3797: $permission{'cusr'} = 1;
3798: }
3799: if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
3800: $permission{'custom'} = 1;
3801: }
3802: $permission{'view'} = $permission{'cusr'};
3803: }
3804: my $allowed = 0;
3805: foreach my $perm (values(%permission)) {
3806: if ($perm) { $allowed=1; last; }
3807: }
3808: return (\%permission,$allowed);
3809: }
3810:
3811: # ==================================================== Figure out author access
3812:
3813: sub authorpriv {
3814: my ($auname,$audom)=@_;
3815: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
3816: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; } return 1;
3817: }
3818:
3819: 1;
3820:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>