File:
[LON-CAPA] /
loncom /
interface /
lonuserutils.pm
Revision
1.13:
download - view:
text,
annotated -
select for diffs
Tue Dec 11 01:17:16 2007 UTC (16 years, 8 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- default role for display of user lists in course context set to "student"
- context type 'construction_space' renamed 'author', for consistency with domainprefs.
- move generation of alert messages from namespacing checks for username and student/employeeID moved to &print_namespacing_alerts().
- adding chgdates as an option for modification of selected users with both active and future roles.
1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
4: # $Id: lonuserutils.pm,v 1.13 2007/12/11 01:17:16 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 (! exists($env{'form.displayphotos'})) {
1768: $env{'form.displayphotos'} = 'off';
1769: }
1770: $displayphotos = $env{'form.displayphotos'};
1771: if (! exists($env{'form.displayclickers'})) {
1772: $env{'form.displayclickers'} = 'off';
1773: }
1774: $displayclickers = $env{'form.displayclickers'};
1775: if ($env{'course.'.$cid.'.internal.showphoto'}) {
1776: $r->print('
1777: <script type="text/javascript">
1778: function photowindow(photolink) {
1779: var title = "Photo_Viewer";
1780: var options = "scrollbars=1,resizable=1,menubar=0";
1781: options += ",width=240,height=240";
1782: stdeditbrowser = open(photolink,title,options,"1");
1783: stdeditbrowser.focus();
1784: }
1785: </script>
1786: ');
1787: }
1788: $r->print(<<END);
1789: <input type="hidden" name="displayphotos" value="$displayphotos" />
1790: <input type="hidden" name="displayclickers" value="$displayclickers" />
1791: END
1792: }
1793: unless ($mode eq 'autoenroll') {
1794: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
1795: my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
1796: my $singconfirm = &mt(' for a single user');
1797: my $multconfirm = &mt(' for multiple users');
1798: my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
1799: $r->print(<<END);
1800:
1801: <script type="text/javascript" language="Javascript">
1802: $check_uncheck_js
1803:
1804: function verify_action (field) {
1805: var numchecked = 0;
1806: var singconf = '$singconfirm';
1807: var multconf = '$multconfirm';
1808: if (field.length > 0) {
1809: for (i = 0; i < field.length; i++) {
1810: if (field[i].checked == true) {
1811: numchecked ++;
1812: }
1813: }
1814: } else {
1815: if (field.checked == true) {
1816: numchecked ++;
1817: }
1818: }
1819: if (numchecked == 0) {
1820: alert("$alert");
1821: }
1822: else {
1823: var message = document.studentform.bulkaction[document.studentform.bulkaction.selectedIndex].text;
1824: if (numchecked == 1) {
1825: message += singconf;
1826: }
1827: else {
1828: message += multconf;
1829: }
1830: if (confirm(message)) {
1831: document.studentform.phase.value = 'bulkchange';
1832: document.studentform.submit();
1833: }
1834: }
1835: }
1836:
1837: function username_display_launch(username,domain) {
1838: var target;
1839: for (var i=0; i<document.studentform.usernamelink.length; i++) {
1840: if (document.studentform.usernamelink[i].checked) {
1841: target = document.studentform.usernamelink[i].value;
1842: }
1843: }
1844: if (target == 'modify') {
1845: document.studentform.srchterm.value=username;
1846: document.studentform.srchdomain.value=domain;
1847: document.studentform.phase.value='get_user_info';
1848: document.studentform.action.value = 'singleuser';
1849: document.studentform.submit();
1850: }
1851: else {
1852: document.location.href = '/adm/'+domain+'/'+username+'/aboutme';
1853: }
1854: }
1855: </script>
1856: $date_sec_selector
1857: <input type="hidden" name="state" value="$env{'form.state'}" />
1858: END
1859: }
1860: $r->print(<<END);
1861: <input type="hidden" name="sortby" value="$sortby" />
1862: END
1863:
1864: my %lt=&Apache::lonlocal::texthash(
1865: 'username' => "username",
1866: 'domain' => "domain",
1867: 'id' => 'ID',
1868: 'fullname' => "name",
1869: 'section' => "section",
1870: 'groups' => "active groups",
1871: 'start' => "start date",
1872: 'end' => "end date",
1873: 'status' => "status",
1874: 'role' => "role",
1875: 'type' => "enroll type/action",
1876: 'email' => "email address",
1877: 'clicker' => "clicker id",
1878: 'photo' => "photo",
1879: 'extent' => "extent",
1880: 'pr' => "Proceed",
1881: 'ca' => "check all",
1882: 'ua' => "uncheck all",
1883: 'ac' => "Action to take for selected users",
1884: 'link' => "Behavior of username links",
1885: 'aboutme' => "Display a user's personal page",
1886: 'modify' => "Modify a user's information",
1887: );
1888: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
1889: $lt{'extent'} = &mt('Course(s): description, section(s), status');
1890: } elsif ($context eq 'author') {
1891: $lt{'extent'} = &mt('Author');
1892: }
1893: my @cols = ('username','domain','id','fullname');
1894: if ($context eq 'course') {
1895: push(@cols,'section');
1896: }
1897: if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) {
1898: push(@cols,('start','end'));
1899: }
1900: if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
1901: push(@cols,'role');
1902: }
1903: if ($context eq 'domain' && ($env{'form.roletype'} eq 'author' ||
1904: $env{'form.roletype'} eq 'course')) {
1905: push (@cols,'extent');
1906: }
1907: if (($statusmode eq 'Any') &&
1908: (!($context eq 'domain' && $env{'form.roletype'} eq 'course'))) {
1909: push(@cols,'status');
1910: }
1911: if ($context eq 'course') {
1912: push(@cols,'groups');
1913: }
1914: push(@cols,'email');
1915:
1916: my $rolefilter = $env{'form.showrole'};
1917: if ($env{'form.showrole'} eq 'cr') {
1918: $rolefilter = &mt('custom');
1919: } elsif ($env{'form.showrole'} ne 'Any') {
1920: $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'});
1921: }
1922: my $results_description = &results_header_row($rolefilter,$statusmode,
1923: $context);
1924: $r->print('<b>'.$results_description.'</b><br />');
1925: my ($output,$actionselect);
1926: if ($mode eq 'html' || $mode eq 'view') {
1927: if ($permission->{'cusr'}) {
1928: $actionselect = &select_actions($context,$setting,$statusmode);
1929: }
1930: $r->print(<<END);
1931: <input type="hidden" name="srchby" value="uname" />
1932: <input type="hidden" name="srchin" value="dom" />
1933: <input type="hidden" name="srchtype" value="exact" />
1934: <input type="hidden" name="srchterm" value="" />
1935: <input type="hidden" name="srchdomain" value="" />
1936: END
1937: if ($mode ne 'autoenroll') {
1938: $output = '<p>';
1939: my @linkdests = ('aboutme');
1940: if ($permission->{'cusr'}) {
1941: push (@linkdests,'modify');
1942: $output .= '<span class="LC_nobreak">'.$lt{'link'}.': ';
1943: my $usernamelink = $env{'form.usernamelink'};
1944: if ($usernamelink eq '') {
1945: $usernamelink = 'aboutme';
1946: }
1947: foreach my $item (@linkdests) {
1948: my $checkedstr = '';
1949: if ($item eq $usernamelink) {
1950: $checkedstr = ' checked="checked" ';
1951: }
1952: $output .= '<label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.'> '.$lt{$item}.'</label> ';
1953: }
1954: $output .= '</span><br />';
1955: } else {
1956: $output .= &mt("Click on a username to view the user's personal page.").'<br />';
1957: }
1958: if ($actionselect) {
1959: $output .= <<"END";
1960: $lt{'ac'}: $actionselect <input type="button" value="$lt{'pr'}" onclick="javascript:verify_action(document.studentform.actionlist)" /></p>
1961: <p><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.actionlist)" />
1962: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.actionlist)" />
1963: END
1964: }
1965: }
1966: $output .= "\n<p>\n".
1967: &Apache::loncommon::start_data_table().
1968: &Apache::loncommon::start_data_table_header_row();
1969: if ($mode eq 'autoenroll') {
1970: $output .= "
1971: <th><a href=\"javascript:document.studentform.sortby.value='type';document.studentform.submit();\">$lt{'type'}</a></th>
1972: ";
1973: } else {
1974: $output .= "\n".'<th>'.&mt('Count').'</th>'."\n";
1975: if ($actionselect) {
1976: $output .= '<th>'.&mt('Select').'</th>'."\n";
1977: }
1978: }
1979: foreach my $item (@cols) {
1980: $output .= "<th><a href=\"javascript:document.studentform.sortby.value='$item';document.studentform.submit();\">$lt{$item}</a></th>\n";
1981: }
1982: my %role_types = &role_type_names();
1983: if ($context eq 'course') {
1984: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
1985: # Clicker display on or off?
1986: my %clicker_options = &Apache::lonlocal::texthash(
1987: 'on' => 'Show',
1988: 'off' => 'Hide',
1989: );
1990: my $clickerchg = 'on';
1991: if ($displayclickers eq 'on') {
1992: $clickerchg = 'off';
1993: }
1994: $output .= ' <th>'."\n".' '.
1995: '<a href="javascript:document.studentform.displayclickers.value='.
1996: "'".$clickerchg."'".';document.studentform.submit();">'.
1997: $clicker_options{$clickerchg}.'</a> '.$lt{'clicker'}."\n".
1998: ' </th>'."\n";
1999:
2000: # Photo display on or off?
2001: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
2002: my %photo_options = &Apache::lonlocal::texthash(
2003: 'on' => 'Show',
2004: 'off' => 'Hide',
2005: );
2006: my $photochg = 'on';
2007: if ($displayphotos eq 'on') {
2008: $photochg = 'off';
2009: }
2010: $output .= ' <th>'."\n".' '.
2011: '<a href="javascript:document.studentform.displayphotos.value='.
2012: "'".$photochg."'".';document.studentform.submit();">'.
2013: $photo_options{$photochg}.'</a> '.$lt{'photo'}."\n".
2014: ' </th>'."\n";
2015: }
2016: }
2017: $output .= &Apache::loncommon::end_data_table_header_row();
2018: }
2019: # Done with the HTML header line
2020: } elsif ($mode eq 'csv') {
2021: #
2022: # Open a file
2023: $CSVfilename = '/prtspool/'.
2024: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
2025: time.'_'.rand(1000000000).'.csv';
2026: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
2027: $r->log_error("Couldn't open $CSVfilename for output $!");
2028: $r->print("Problems occured in writing the csv file. ".
2029: "This error has been logged. ".
2030: "Please alert your LON-CAPA administrator.");
2031: $CSVfile = undef;
2032: }
2033: #
2034: # Write headers and data to file
2035: print $CSVfile '"'.$results_description.'"'."\n";
2036: print $CSVfile '"'.join('","',map {
2037: &Apache::loncommon::csv_translate($lt{$_})
2038: } (@cols)).'"'."\n";
2039: } elsif ($mode eq 'excel') {
2040: # Create the excel spreadsheet
2041: ($excel_workbook,$excel_filename,$format) =
2042: &Apache::loncommon::create_workbook($r);
2043: return if (! defined($excel_workbook));
2044: $excel_sheet = $excel_workbook->addworksheet('userlist');
2045: $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
2046: #
2047: my @colnames = map {$lt{$_}} (@cols);
2048: $excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
2049: }
2050:
2051: # Done with header lines in all formats
2052:
2053: my %index;
2054: my $i;
2055: foreach my $idx (@$keylist) {
2056: $index{$idx} = $i++;
2057: }
2058: my $usercount = 0;
2059: # Get groups, role, permanent e-mail so we can sort on them if
2060: # necessary.
2061: foreach my $user (keys(%{$userlist})) {
2062: if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) {
2063: delete($userlist->{$user});
2064: next;
2065: }
2066: my ($uname,$udom,$role,$groups,$email);
2067: if (($statusmode ne 'Any') &&
2068: ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
2069: delete($userlist->{$user});
2070: next;
2071: }
2072: if ($context eq 'domain') {
2073: if ($env{'form.roletype'} eq 'domain') {
2074: ($role,$uname,$udom) = split(/:/,$user);
2075: if (($uname eq $env{'request.role.domain'}.'-domainconfig') &&
2076: ($udom eq $env{'request.role.domain'})) {
2077: delete($userlist->{$user});
2078: next;
2079: }
2080: } elsif ($env{'form.roletype'} eq 'author') {
2081: ($uname,$udom,$role) = split(/:/,$user,-1);
2082: } elsif ($env{'form.roletype'} eq 'course') {
2083: ($uname,$udom,$role) = split(/:/,$user);
2084: }
2085: } else {
2086: ($uname,$udom,$role) = split(/:/,$user,-1);
2087: if (($context eq 'course') && $role eq '') {
2088: $role = 'st';
2089: }
2090: }
2091: $userlist->{$user}->[$index{'role'}] = $role;
2092: if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
2093: delete($userlist->{$user});
2094: next;
2095: }
2096: if (ref($classgroups) eq 'HASH') {
2097: $groups = $classgroups->{$user};
2098: }
2099: if (ref($groups->{active}) eq 'HASH') {
2100: $userlist->{$user}->[$index{'groups'}] = join(', ',keys(%{$groups->{'active'}}));
2101: }
2102: my %emails = &Apache::loncommon::getemails($uname,$udom);
2103: if ($emails{'permanentemail'} =~ /\S/) {
2104: $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
2105: }
2106: $usercount ++;
2107: }
2108: my $autocount = 0;
2109: my $manualcount = 0;
2110: my $lockcount = 0;
2111: my $unlockcount = 0;
2112: if ($usercount) {
2113: $r->print($output);
2114: } else {
2115: if ($mode eq 'autoenroll') {
2116: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
2117: } else {
2118: return;
2119: }
2120: }
2121: #
2122: # Sort the users
2123: my $index = $index{$sortby};
2124: my $second = $index{'username'};
2125: my $third = $index{'domain'};
2126: my @sorted_users = sort {
2127: lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index])
2128: ||
2129: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
2130: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
2131: } (keys(%$userlist));
2132: my $rowcount = 0;
2133: foreach my $user (@sorted_users) {
2134: my %in;
2135: my $sdata = $userlist->{$user};
2136: $rowcount ++;
2137: foreach my $item (@{$keylist}) {
2138: $in{$item} = $sdata->[$index{$item}];
2139: }
2140: my $role = $in{'role'};
2141: $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}]);
2142: if (! defined($in{'start'}) || $in{'start'} == 0) {
2143: $in{'start'} = &mt('none');
2144: } else {
2145: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
2146: }
2147: if (! defined($in{'end'}) || $in{'end'} == 0) {
2148: $in{'end'} = &mt('none');
2149: } else {
2150: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
2151: }
2152: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
2153: $r->print(&Apache::loncommon::start_data_table_row());
2154: $r->print("<td>$rowcount</td>\n");
2155: my $checkval;
2156: if ($mode ne 'autoenroll' && $actionselect) {
2157: $checkval = $user;
2158: if ($context eq 'course') {
2159: if ($role eq 'st') {
2160: $checkval .= ':st';
2161: }
2162: $checkval .= ':'.$in{'section'};
2163: if ($role eq 'st') {
2164: $checkval .= ':'.$in{'type'}.':'.$in{'lockedtype'};
2165: }
2166: }
2167: $r->print('<td><input type="checkbox" name="actionlist" value="'.
2168: $checkval.'"></td>');
2169: }
2170: foreach my $item (@cols) {
2171: if ($item eq 'username') {
2172: $r->print('<td>'.&print_username_link($permission,\%in).'</td>');
2173: } elsif (($item eq 'start' || $item eq 'end') && ($mode ne 'autoeroll') && ($actionselect)) {
2174: $r->print('<td>'.$in{$item}.'<input type="hidden" name="'.$checkval.'_'.$item.'" value="'.$sdata->[$index{$item}].'" /></td>'."\n");
2175: } else {
2176: $r->print('<td>'.$in{$item}.'</td>'."\n");
2177: }
2178: }
2179: if ($context eq 'course') {
2180: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
2181: if ($displayclickers eq 'on') {
2182: my $clickers =
2183: (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
2184: if ($clickers!~/\w/) { $clickers='-'; }
2185: $r->print('<td>'.$clickers.'</td>');
2186: } else {
2187: $r->print(' <td> </td> ');
2188: }
2189: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
2190: if ($displayphotos eq 'on' && $sdata->[$index{'role'}] eq 'st') {
2191: my $imgurl =
2192: &Apache::lonnet::retrievestudentphoto($in{'domain'},$in{'username'},
2193: 'gif','thumbnail');
2194: $r->print(' <td align="right"><a href="javascript:photowindow('."'".&Apache::lonnet::studentphoto($in{'domain'},$in{'username'},'jpg')."'".')"><img src="'.$imgurl.'" border="1"></a></td>');
2195: } else {
2196: $r->print(' <td> </td> ');
2197: }
2198: }
2199: }
2200: }
2201: $r->print(&Apache::loncommon::end_data_table_row());
2202: } elsif ($mode eq 'csv') {
2203: next if (! defined($CSVfile));
2204: # no need to bother with $linkto
2205: if (! defined($in{'start'}) || $in{'start'} == 0) {
2206: $in{'start'} = &mt('none');
2207: } else {
2208: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
2209: }
2210: if (! defined($in{'end'}) || $in{'end'} == 0) {
2211: $in{'end'} = &mt('none');
2212: } else {
2213: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
2214: }
2215: my @line = ();
2216: foreach my $item (@cols) {
2217: push @line,&Apache::loncommon::csv_translate($in{$item});
2218: }
2219: print $CSVfile '"'.join('","',@line).'"'."\n";
2220: } elsif ($mode eq 'excel') {
2221: my $col = 0;
2222: foreach my $item (@cols) {
2223: if ($item eq 'start' || $item eq 'end') {
2224: if (defined($item) && $item != 0) {
2225: $excel_sheet->write($row,$col++,
2226: &Apache::lonstathelpers::calc_serial($in{item}),
2227: $format->{'date'});
2228: } else {
2229: $excel_sheet->write($row,$col++,'none');
2230: }
2231: } else {
2232: $excel_sheet->write($row,$col++,$in{$item});
2233: }
2234: }
2235: $row++;
2236: }
2237: }
2238: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
2239: $r->print(&Apache::loncommon::end_data_table().'<br />');
2240: } elsif ($mode eq 'excel') {
2241: $excel_workbook->close();
2242: $r->print('<p><a href="'.$excel_filename.'">'.
2243: &mt('Your Excel spreadsheet').'</a> '.&mt('is ready for download').'.</p>'."\n");
2244: } elsif ($mode eq 'csv') {
2245: close($CSVfile);
2246: $r->print('<a href="'.$CSVfilename.'">'.
2247: &mt('Your CSV file').'</a> is ready for download.'.
2248: "\n");
2249: $r->rflush();
2250: }
2251: if ($mode eq 'autoenroll') {
2252: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
2253: } else {
2254: return ($usercount);
2255: }
2256: }
2257:
2258: sub print_username_link {
2259: my ($permission,$in) = @_;
2260: my $output;
2261: if (!$permission->{'cusr'}) {
2262: $output = &Apache::loncommon::aboutmewrapper($in->{'username'},
2263: $in->{'username'},
2264: $in->{'domain'});
2265: } else {
2266: $output = '<a href="javascript:username_display_launch('.
2267: "'$in->{'username'}','$in->{'domain'}'".')" />'.
2268: $in->{'username'}.'</a>';
2269: }
2270: return $output;
2271: }
2272:
2273: sub role_type_names {
2274: my %lt = &Apache::lonlocal::texthash (
2275: 'domain' => 'Domain Roles',
2276: 'author' => 'Co-Author Roles',
2277: 'course' => 'Course Roles',
2278: );
2279: return %lt;
2280: }
2281:
2282: sub select_actions {
2283: my ($context,$setting,$statusmode) = @_;
2284: my %lt = &Apache::lonlocal::texthash(
2285: revoke => "Revoke user roles",
2286: delete => "Delete user roles",
2287: reenable => "Re-enable expired user roles",
2288: activate => "Make future user roles active now",
2289: chgdates => "Change starting/ending dates",
2290: chgsec => "Change section associated with user roles",
2291: );
2292: my ($output,$options,%choices);
2293: if ($statusmode eq 'Any') {
2294: $options .= '
2295: <option value="chgdates">'.$lt{'chgdates'}.'</option>';
2296: $choices{'dates'} = 1;
2297: } else {
2298: if ($statusmode eq 'Future') {
2299: $options .= '
2300: <option value="activate">'.$lt{'activate'}.'</option>';
2301: $choices{'dates'} = 1;
2302: } elsif ($statusmode eq 'Expired') {
2303: $options .= '
2304: <option value="reenable">'.$lt{'reenable'}.'</option>';
2305: $choices{'dates'} = 1;
2306: }
2307: if ($statusmode eq 'Active' || $statusmode eq 'Future') {
2308: $options .= '
2309: <option value="chgdates">'.$lt{'chgdates'}.'</option>
2310: <option value="revoke">'.$lt{'revoke'}.'</option>';
2311: $choices{'dates'} = 1;
2312: }
2313: }
2314: if ($context eq 'domain') {
2315: $options .= '
2316: <option value="delete">'.$lt{'delete'}.'</option>';
2317: }
2318: if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
2319: if ($statusmode ne 'Expired') {
2320: $options .= '
2321: <option value="chgsec">'.$lt{'chgsec'}.'</option>';
2322: $choices{'sections'} = 1;
2323: }
2324: }
2325: if ($options) {
2326: $output = '<select name="bulkaction" onchange="javascript:opendatebrowser(this.form,'."'studentform'".')" />'."\n".
2327: '<option value="" selected="selected">'.
2328: &mt('Please select').'</option>'."\n".$options."\n".'</select>';
2329: if ($choices{'dates'}) {
2330: $output .=
2331: '<input type="hidden" name="startdate_month" value="" />'."\n".
2332: '<input type="hidden" name="startdate_day" value="" />'."\n".
2333: '<input type="hidden" name="startdate_year" value="" />'."\n".
2334: '<input type="hidden" name="startdate_hour" value="" />'."\n".
2335: '<input type="hidden" name="startdate_minute" value="" />'."\n".
2336: '<input type="hidden" name="startdate_second" value="" />'."\n".
2337: '<input type="hidden" name="enddate_month" value="" />'."\n".
2338: '<input type="hidden" name="enddate_day" value="" />'."\n".
2339: '<input type="hidden" name="enddate_year" value="" />'."\n".
2340: '<input type="hidden" name="enddate_hour" value="" />'."\n".
2341: '<input type="hidden" name="enddate_minute" value="" />'."\n".
2342: '<input type="hidden" name="enddate_second" value="" />'."\n";
2343: if ($context eq 'course') {
2344: $output .= '<input type="hidden" name="makedatesdefault" value="" />'."\n";
2345: }
2346: }
2347: if ($choices{'sections'}) {
2348: $output .= '<input type="hidden" name="retainsec" value= "" />'."\n".
2349: '<input type="hidden" name="newsecs" value= "" />'."\n";
2350: }
2351: }
2352: return $output;
2353: }
2354:
2355: sub date_section_javascript {
2356: my ($context,$setting) = @_;
2357: my $title;
2358: if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
2359: $title = &mt('Date and Section selector');
2360: } else {
2361: $title = &mt('Date selector');
2362: }
2363: my $output = '
2364: <script type="text/javascript">
2365: var stdeditbrowser;'."\n";
2366: $output .= <<"ENDONE";
2367: function opendatebrowser(callingform,formname) {
2368: var bulkaction = callingform.bulkaction.options[callingform.bulkaction.selectedIndex].value;
2369: if (bulkaction == 'revoke' || bulkaction == 'delete' || bulkaction == '') {
2370: return;
2371: }
2372: var url = '/adm/createuser?';
2373: var type = '';
2374: var showrole = callingform.showrole.options[callingform.showrole.selectedIndex].value;
2375: ENDONE
2376: if ($context eq 'domain') {
2377: $output .= '
2378: type = callingform.roletype.options[callingform.roletype.selectedIndex].value;
2379: ';
2380: }
2381: my $width= '700';
2382: my $height = '400';
2383: $output .= <<"ENDTWO";
2384: url += 'action=dateselect&callingform=' + formname +
2385: '&roletype='+type+'&showrole='+showrole +'&bulkaction='+bulkaction;
2386: var title = '$title';
2387: var options = 'scrollbars=1,resizable=1,menubar=0';
2388: options += ',width=$width,height=$height';
2389: stdeditbrowser = open(url,title,options,'1');
2390: stdeditbrowser.focus();
2391: }
2392: </script>
2393: ENDTWO
2394: return $output;
2395: }
2396:
2397: sub date_section_selector {
2398: my ($context) = @_;
2399: my $callingform = $env{'form.callingform'};
2400: my $formname = 'dateselect';
2401: my $groupslist = &get_groupslist();
2402: my $sec_js = &setsections_javascript($formname,$groupslist);
2403: my $output = <<"END";
2404: <script type="text/javascript">
2405:
2406: $sec_js
2407:
2408: function saveselections(formname) {
2409:
2410: END
2411: if ($env{'form.bulkaction'} eq 'chgsec') {
2412: $output .= <<"END";
2413: opener.document.$callingform.retainsec.value = formname.retainsec.value;
2414: setSections(formname);
2415: if (seccheck == 'ok') {
2416: opener.document.$callingform.newsecs.value = formname.sections.value;
2417: window.close();
2418: }
2419: return;
2420: END
2421: } else {
2422: if ($context eq 'course') {
2423: if (($env{'form.bulkaction'} eq 'reenable') ||
2424: ($env{'form.bulkaction'} eq 'activate') ||
2425: ($env{'form.bulkaction'} eq 'chgdates')) {
2426: $output .= <<"END";
2427:
2428: if (formname.makedatesdefault.checked == true) {
2429: opener.document.$callingform.makedatesdefault.value = 1;
2430: }
2431: else {
2432: opener.document.$callingform.makedatesdefault.value = 0;
2433: }
2434:
2435: END
2436: }
2437: }
2438: $output .= <<"END";
2439: opener.document.$callingform.startdate_month.value = formname.startdate_month.options[formname.startdate_month.selectedIndex].value;
2440: opener.document.$callingform.startdate_day.value = formname.startdate_day.value;
2441: opener.document.$callingform.startdate_year.value = formname.startdate_year.value;
2442: opener.document.$callingform.startdate_hour.value = formname.startdate_hour.options[formname.startdate_hour.selectedIndex].value;
2443: opener.document.$callingform.startdate_minute.value = formname.startdate_minute.value;
2444: opener.document.$callingform.startdate_second.value = formname.startdate_second.value;
2445: opener.document.$callingform.enddate_month.value = formname.enddate_month.options[formname.enddate_month.selectedIndex].value;
2446: opener.document.$callingform.enddate_day.value = formname.enddate_day.value;
2447: opener.document.$callingform.enddate_year.value = formname.enddate_year.value;
2448: opener.document.$callingform.enddate_hour.value = formname.enddate_hour.options[formname.enddate_hour.selectedIndex].value;
2449: opener.document.$callingform.enddate_minute.value = formname.enddate_minute.value;
2450: opener.document.$callingform.enddate_second.value = formname.enddate_second.value;
2451: window.close();
2452: END
2453: }
2454: $output .= '
2455: }
2456: </script>
2457: ';
2458: my %lt = &Apache::lonlocal::texthash (
2459: chac => 'Access dates to apply for selected users',
2460: chse => 'Changes in section affiliation to apply to selected users',
2461: 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.',
2462: 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.',
2463: reta => "Retain each user's current section affiliations?",
2464: dnap => '(Does not apply to student roles).',
2465: );
2466: my ($date_items,$headertext);
2467: if ($env{'form.bulkaction'} eq 'chgsec') {
2468: $headertext = $lt{'chse'};
2469: } else {
2470: $headertext = $lt{'chac'};
2471: my $starttime;
2472: if (($env{'form.bulkaction'} eq 'activate') ||
2473: ($env{'form.bulkaction'} eq 'reenable')) {
2474: $starttime = time;
2475: }
2476: $date_items = &date_setting_table($starttime,undef,$context,
2477: $env{'form.bulkaction'});
2478: }
2479: $output .= '<h3>'.$headertext.'</h3>'.
2480: '<form name="'.$formname.'" method="post">'."\n".
2481: $date_items;
2482: if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
2483: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2484: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2485: my %sections_count =
2486: &Apache::loncommon::get_sections($cdom,$cnum);
2487: my $info;
2488: if ($env{'form.showrole'} eq 'st') {
2489: $output .= '<p>'.$lt{'fors'}.'</p>';
2490: } elsif ($env{'form.shorole'} eq 'Any') {
2491: $output .= '<p>'.$lt{'fors'}.'</p>'.
2492: '<p>'.$lt{'forn'}.' ';
2493: $info = $lt{'reta'};
2494: } else {
2495: $output .= '<p>'.$lt{'forn'}.' ';
2496: $info = $lt{'reta'};
2497: }
2498: if ($info) {
2499: $info .= '<span class="LC_nobreak">'.
2500: '<label><input type="radio" name="retainsec" value="1" '.
2501: 'checked="checked" />'.&mt('Yes').'</label> '.
2502: '<label><input type="radio" name="retainsec" value="0" />'.
2503: &mt('No').'</label></span>';
2504: if ($env{'form.showrole'} eq 'Any') {
2505: $info .= '<br />'.$lt{'dnap'};
2506: }
2507: $info .= '</p>';
2508: } else {
2509: $info = '<input type="hidden" name="retainsec" value="0" />';
2510: }
2511: my $sections_select .= &course_sections(\%sections_count,$env{'form.showrole'});
2512: my $secbox = '<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n".
2513: &Apache::lonhtmlcommon::row_title(&mt('New section to assign'),'LC_oddrow_value')."\n".
2514: '<table class="LC_createuser"><tr class="LC_section_row">'."\n".
2515: '<td align="center">'.&mt('Existing sections')."\n".
2516: '<br />'.$sections_select.'</td><td align="center">'.
2517: &mt('New section').'<br />'."\n".
2518: '<input type="text" name="newsec" size="15" />'."\n".
2519: '<input type="hidden" name="sections" value="" />'."\n".
2520: '</td></tr></table>'."\n".
2521: &Apache::lonhtmlcommon::row_closure(1)."\n".
2522: &Apache::lonhtmlcommon::end_pick_box().'</p>';
2523: $output .= $info.$secbox;
2524: }
2525: $output .= '<p>'.
2526: &mt('Use "Save" to update the main window with your selections.').'<br /><br />'.
2527: '<input type="button" name="dateselection" value="'.&mt('Save').'" onclick="javascript:saveselections(this.form)" /></p>'."\n".
2528: '</form>';
2529: return $output;
2530: }
2531:
2532: sub results_header_row {
2533: my ($rolefilter,$statusmode,$context) = @_;
2534: my ($description,$showfilter);
2535: if ($rolefilter ne 'Any') {
2536: $showfilter = $rolefilter;
2537: }
2538: if ($context eq 'course') {
2539: $description = &mt('Course - ').$env{'course.'.$env{'request.course.id'}.'.description'}.': ';
2540: if ($statusmode eq 'Expired') {
2541: $description .= &mt('Users in course with expired [_1] roles',$showfilter);
2542: } elsif ($statusmode eq 'Future') {
2543: $description .= &mt('Users in course with future [_1] roles',$showfilter);
2544: } elsif ($statusmode eq 'Active') {
2545: $description .= &mt('Users in course with active [_1] roles',$showfilter);
2546: } else {
2547: if ($rolefilter eq 'Any') {
2548: $description .= &mt('All users in course');
2549: } else {
2550: $description .= &mt('All users in course with [_1] roles',$rolefilter);
2551: }
2552: }
2553: } elsif ($context eq 'author') {
2554: $description = &mt('Author space for [_1].').' ';
2555: if ($statusmode eq 'Expired') {
2556: $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
2557: } elsif ($statusmode eq 'Future') {
2558: $description .= &mt('Co-authors with future [_1] roles',$showfilter);
2559: } elsif ($statusmode eq 'Active') {
2560: $description .= &mt('Co-authors with active [_1] roles',$showfilter);
2561: } else {
2562: if ($rolefilter eq 'Any') {
2563: $description .= &mt('All co-authors');
2564: } else {
2565: $description .= &mt('All co-authors with [_1] roles',$rolefilter);
2566: }
2567: }
2568: } elsif ($context eq 'domain') {
2569: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
2570: $description = &mt('Domain - ').$domdesc.': ';
2571: if ($env{'form.roletype'} eq 'domain') {
2572: if ($statusmode eq 'Expired') {
2573: $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
2574: } elsif ($statusmode eq 'Future') {
2575: $description .= &mt('Users in domain with future [_1] roles',$showfilter);
2576: } elsif ($statusmode eq 'Active') {
2577: $description .= &mt('Users in domain with active [_1] roles',$showfilter);
2578: } else {
2579: if ($rolefilter eq 'Any') {
2580: $description .= &mt('All users in domain');
2581: } else {
2582: $description .= &mt('All users in domain with [_1] roles',$rolefilter);
2583: }
2584: }
2585: } elsif ($env{'form.roletype'} eq 'author') {
2586: if ($statusmode eq 'Expired') {
2587: $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
2588: } elsif ($statusmode eq 'Future') {
2589: $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
2590: } elsif ($statusmode eq 'Active') {
2591: $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
2592: } else {
2593: if ($rolefilter eq 'Any') {
2594: $description .= &mt('All users with co-author roles in domain',$showfilter);
2595: } else {
2596: $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
2597: }
2598: }
2599: } elsif ($env{'form.roletype'} eq 'course') {
2600: my $coursefilter = $env{'form.coursepick'};
2601: if ($coursefilter eq 'category') {
2602: my $instcode = &instcode_from_coursefilter();
2603: if ($instcode eq '.') {
2604: $description .= &mt('All courses in domain').' - ';
2605: } else {
2606: $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
2607: }
2608: } elsif ($coursefilter eq 'selected') {
2609: $description .= &mt('Selected courses in domain').' - ';
2610: } elsif ($coursefilter eq 'all') {
2611: $description .= &mt('All courses in domain').' - ';
2612: }
2613: if ($statusmode eq 'Expired') {
2614: $description .= &mt('users with expired [_1] roles',$showfilter);
2615: } elsif ($statusmode eq 'Future') {
2616: $description .= &mt('users with future [_1] roles',$showfilter);
2617: } elsif ($statusmode eq 'Active') {
2618: $description .= &mt('users with active [_1] roles',$showfilter);
2619: } else {
2620: if ($rolefilter eq 'Any') {
2621: $description .= &mt('all users');
2622: } else {
2623: $description .= &mt('users with [_1] roles',$rolefilter);
2624: }
2625: }
2626: }
2627: }
2628: return $description;
2629: }
2630:
2631: #################################################
2632: #################################################
2633: sub show_drop_list {
2634: my ($r,$classlist,$keylist,$nosort)=@_;
2635: my $cid=$env{'request.course.id'};
2636: if (! exists($env{'form.sortby'})) {
2637: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2638: ['sortby']);
2639: }
2640: my $sortby = $env{'form.sortby'};
2641: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
2642: $sortby = 'username';
2643: }
2644: my $cdom = $env{'course.'.$cid.'.domain'};
2645: my $cnum = $env{'course.'.$cid,'.num'};
2646: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
2647: $classlist,$keylist,$cdom,$cnum);
2648: #
2649: my $action = "drop";
2650: $r->print(<<END);
2651: <input type="hidden" name="sortby" value="$sortby" />
2652: <input type="hidden" name="action" value="$action" />
2653: <input type="hidden" name="state" value="done" />
2654: <script>
2655: function checkAll(field) {
2656: for (i = 0; i < field.length; i++)
2657: field[i].checked = true ;
2658: }
2659:
2660: function uncheckAll(field) {
2661: for (i = 0; i < field.length; i++)
2662: field[i].checked = false ;
2663: }
2664: </script>
2665: <p>
2666: <input type="hidden" name="phase" value="four">
2667: END
2668:
2669: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
2670: 'dom' => "domain",
2671: 'sn' => "student name",
2672: 'sec' => "section",
2673: 'start' => "start date",
2674: 'end' => "end date",
2675: 'groups' => "active groups",
2676: );
2677: if ($nosort) {
2678: $r->print(&Apache::loncommon::start_data_table());
2679: $r->print(<<END);
2680: <tr>
2681: <th> </th>
2682: <th>$lt{'usrn'}</th>
2683: <th>$lt{'dom'}</th>
2684: <th>ID</th>
2685: <th>$lt{'sn'}</th>
2686: <th>$lt{'sec'}</th>
2687: <th>$lt{'start'}</th>
2688: <th>$lt{'end'}</th>
2689: <th>$lt{'groups'}</th>
2690: </tr>
2691: END
2692:
2693: } else {
2694: $r->print(&Apache::loncommon::start_data_table());
2695: $r->print(<<END);
2696: <tr><th> </th>
2697: <th>
2698: <a href="/adm/dropadd?action=$action&sortby=username">$lt{'usrn'}</a>
2699: </th><th>
2700: <a href="/adm/dropadd?action=$action&sortby=domain">$lt{'dom'}</a>
2701: </th><th>
2702: <a href="/adm/dropadd?action=$action&sortby=id">ID</a>
2703: </th><th>
2704: <a href="/adm/dropadd?action=$action&sortby=fullname">$lt{'sn'}</a>
2705: </th><th>
2706: <a href="/adm/dropadd?action=$action&sortby=section">$lt{'sec'}</a>
2707: </th><th>
2708: <a href="/adm/dropadd?action=$action&sortby=start">$lt{'start'}</a>
2709: </th><th>
2710: <a href="/adm/dropadd?action=$action&sortby=end">$lt{'end'}</a>
2711: </th><th>
2712: <a href="/adm/dropadd?action=$action&sortby=groups">$lt{'groups'}</a>
2713: </th>
2714: </tr>
2715: END
2716: }
2717: #
2718: # Sort the students
2719: my %index;
2720: my $i;
2721: foreach (@$keylist) {
2722: $index{$_} = $i++;
2723: }
2724: $index{'groups'} = scalar(@$keylist);
2725: my $index = $index{$sortby};
2726: my $second = $index{'username'};
2727: my $third = $index{'domain'};
2728: my @Sorted_Students = sort {
2729: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
2730: ||
2731: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
2732: ||
2733: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
2734: } (keys(%$classlist));
2735: foreach my $student (@Sorted_Students) {
2736: my $error;
2737: my $sdata = $classlist->{$student};
2738: my $username = $sdata->[$index{'username'}];
2739: my $domain = $sdata->[$index{'domain'}];
2740: my $section = $sdata->[$index{'section'}];
2741: my $name = $sdata->[$index{'fullname'}];
2742: my $id = $sdata->[$index{'id'}];
2743: my $start = $sdata->[$index{'start'}];
2744: my $end = $sdata->[$index{'end'}];
2745: my $groups = $classgroups->{$student};
2746: my $active_groups;
2747: if (ref($groups->{active}) eq 'HASH') {
2748: $active_groups = join(', ',keys(%{$groups->{'active'}}));
2749: }
2750: if (! defined($start) || $start == 0) {
2751: $start = &mt('none');
2752: } else {
2753: $start = &Apache::lonlocal::locallocaltime($start);
2754: }
2755: if (! defined($end) || $end == 0) {
2756: $end = &mt('none');
2757: } else {
2758: $end = &Apache::lonlocal::locallocaltime($end);
2759: }
2760: my $status = $sdata->[$index{'status'}];
2761: next if ($status ne 'Active');
2762: #
2763: $r->print(&Apache::loncommon::start_data_table_row());
2764: $r->print(<<"END");
2765: <td><input type="checkbox" name="droplist" value="$student"></td>
2766: <td>$username</td>
2767: <td>$domain</td>
2768: <td>$id</td>
2769: <td>$name</td>
2770: <td>$section</td>
2771: <td>$start</td>
2772: <td>$end</td>
2773: <td>$active_groups</td>
2774: END
2775: $r->print(&Apache::loncommon::end_data_table_row());
2776: }
2777: $r->print(&Apache::loncommon::end_data_table().'<br />');
2778: %lt=&Apache::lonlocal::texthash(
2779: 'dp' => "Expire Users' Roles",
2780: 'ca' => "check all",
2781: 'ua' => "uncheck all",
2782: );
2783: $r->print(<<"END");
2784: </p><p>
2785: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)">
2786: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)">
2787: <p><input type=submit value="$lt{'dp'}"></p>
2788: END
2789: return;
2790: }
2791:
2792: #
2793: # Print out the initial form to get the file containing a list of users
2794: #
2795: sub print_first_users_upload_form {
2796: my ($r,$context) = @_;
2797: my $str;
2798: $str = '<input type="hidden" name="phase" value="two">';
2799: $str .= '<input type="hidden" name="action" value="upload" />';
2800: $str .= '<input type="hidden" name="state" value="got_file" />';
2801: $str .= "<h3>".&mt('Upload a file containing information about users')."</h3>\n";
2802: $str .= &Apache::loncommon::upfile_select_html();
2803: $str .= "<p>\n";
2804: $str .= '<input type="submit" name="fileupload" value="'.
2805: &mt('Upload file of users').'">'."\n";
2806: $str .= '<label><input type="checkbox" name="noFirstLine" /> '.
2807: &mt('Ignore First Line')."</label></p>\n";
2808: $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List",
2809: &mt("How do I create a users list from a spreadsheet")).
2810: "<br />\n";
2811: $str .= &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
2812: &mt("How do I create a CSV file from a spreadsheet")).
2813: "<br />\n";
2814: $str .= &Apache::loncommon::end_page();
2815: $r->print($str);
2816: return;
2817: }
2818:
2819: # ================================================= Drop/Add from uploaded file
2820: sub upfile_drop_add {
2821: my ($r,$context) = @_;
2822: &Apache::loncommon::load_tmp_file($r);
2823: my @userdata=&Apache::loncommon::upfile_record_sep();
2824: if($env{'form.noFirstLine'}){shift(@userdata);}
2825: my @keyfields = split(/\,/,$env{'form.keyfields'});
2826: my %fields=();
2827: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
2828: if ($env{'form.upfile_associate'} eq 'reverse') {
2829: if ($env{'form.f'.$i} ne 'none') {
2830: $fields{$keyfields[$i]}=$env{'form.f'.$i};
2831: }
2832: } else {
2833: $fields{$env{'form.f'.$i}}=$keyfields[$i];
2834: }
2835: }
2836: #
2837: # Store the field choices away
2838: foreach my $field (qw/username names
2839: fname mname lname gen id sec ipwd email role/) {
2840: $env{'form.'.$field.'_choice'}=$fields{$field};
2841: }
2842: &Apache::loncommon::store_course_settings('enrollment_upload',
2843: { 'username_choice' => 'scalar',
2844: 'names_choice' => 'scalar',
2845: 'fname_choice' => 'scalar',
2846: 'mname_choice' => 'scalar',
2847: 'lname_choice' => 'scalar',
2848: 'gen_choice' => 'scalar',
2849: 'id_choice' => 'scalar',
2850: 'sec_choice' => 'scalar',
2851: 'ipwd_choice' => 'scalar',
2852: 'email_choice' => 'scalar',
2853: 'role_choice' => 'scalar' });
2854: #
2855: my ($startdate,$enddate) = &get_dates_from_form();
2856: if ($env{'form.makedatesdefault'}) {
2857: $r->print(&make_dates_default($startdate,$enddate));
2858: }
2859: # Determine domain and desired host (home server)
2860: my $domain=$env{'request.role.domain'};
2861: my $desiredhost = $env{'form.lcserver'};
2862: if (lc($desiredhost) eq 'default') {
2863: $desiredhost = undef;
2864: } else {
2865: my %home_servers = &Apache::lonnet::get_servers($domain,'library');
2866: if (! exists($home_servers{$desiredhost})) {
2867: $r->print('<span class="LC_error">'.&mt('Error').
2868: &mt('Invalid home server specified').'</span>');
2869: $r->print(&Apache::loncommon::end_page());
2870: return;
2871: }
2872: }
2873: # Determine authentication mechanism
2874: my $changeauth;
2875: if ($context eq 'domain') {
2876: $changeauth = $env{'form.changeauth'};
2877: }
2878: my $amode = '';
2879: my $genpwd = '';
2880: if ($env{'form.login'} eq 'krb') {
2881: $amode='krb';
2882: $amode.=$env{'form.krbver'};
2883: $genpwd=$env{'form.krbarg'};
2884: } elsif ($env{'form.login'} eq 'int') {
2885: $amode='internal';
2886: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
2887: $genpwd=$env{'form.intarg'};
2888: }
2889: } elsif ($env{'form.login'} eq 'loc') {
2890: $amode='localauth';
2891: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
2892: $genpwd=$env{'form.locarg'};
2893: }
2894: }
2895: if ($amode =~ /^krb/) {
2896: if (! defined($genpwd) || $genpwd eq '') {
2897: $r->print('<span class="Error">'.
2898: &mt('Unable to enroll users').' '.
2899: &mt('No Kerberos domain was specified.').'</span></p>');
2900: $amode = ''; # This causes the loop below to be skipped
2901: }
2902: }
2903: my ($cid,$defaultsec,$defaultrole,$setting);
2904: if ($context eq 'domain') {
2905: $setting = $env{'form.roleaction'};
2906: if ($setting eq 'domain') {
2907: $defaultrole = $env{'form.defaultrole'};
2908: } elsif ($setting eq 'course') {
2909: $defaultrole = $env{'form.courserole'};
2910: }
2911: } elsif ($context eq 'author') {
2912: $defaultrole = $env{'form.defaultrole'};
2913: }
2914: if ($context eq 'domain' && $setting eq 'course') {
2915: if ($env{'form.newsec'} ne '') {
2916: $defaultsec = $env{'form.newsec'};
2917: } elsif ($env{'form.defaultsec'} ne '') {
2918: $defaultsec = $env{'form.defaultsec'}
2919: }
2920: }
2921: if ($env{'request.course.id'} ne '') {
2922: $cid = $env{'request.course.id'};
2923: } elsif ($env{'form.defaultdomain'} ne '' && $env{'form.defaultcourse'} ne '') {
2924: $cid = $env{'form.defaultdomain'}.'_'.
2925: $env{'form.defaultcourse'};
2926: }
2927: if ( $domain eq &LONCAPA::clean_domain($domain)
2928: && ($amode ne '')) {
2929: #######################################
2930: ## Add/Modify Users ##
2931: #######################################
2932: if ($context eq 'course') {
2933: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
2934: } elsif ($context eq 'author') {
2935: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
2936: } else {
2937: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
2938: }
2939: my %counts = (
2940: user => 0,
2941: auth => 0,
2942: role => 0,
2943: );
2944: my $flushc=0;
2945: my %student=();
2946: my %curr_groups;
2947: my %userchg;
2948: if ($context eq 'course') {
2949: # Get information about course groups
2950: %curr_groups = &Apache::longroup::coursegroups();
2951: }
2952: my (%curr_rules,%got_rules,%alerts);
2953: # Get new users list
2954: foreach (@userdata) {
2955: my %entries=&Apache::loncommon::record_sep($_);
2956: # Determine user name
2957: unless (($entries{$fields{'username'}} eq '') ||
2958: (!defined($entries{$fields{'username'}}))) {
2959: my ($fname, $mname, $lname,$gen) = ('','','','');
2960: if (defined($fields{'names'})) {
2961: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
2962: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
2963: } else {
2964: if (defined($fields{'fname'})) {
2965: $fname=$entries{$fields{'fname'}};
2966: }
2967: if (defined($fields{'mname'})) {
2968: $mname=$entries{$fields{'mname'}};
2969: }
2970: if (defined($fields{'lname'})) {
2971: $lname=$entries{$fields{'lname'}};
2972: }
2973: if (defined($fields{'gen'})) {
2974: $gen=$entries{$fields{'gen'}};
2975: }
2976: }
2977: if ($entries{$fields{'username'}}
2978: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
2979: $r->print('<br />'.
2980: &mt('<b>[_1]</b>: Unacceptable username for user [_2] [_3] [_4] [_5]',
2981: $entries{$fields{'username'}},$fname,$mname,$lname,$gen).
2982: '</b>');
2983: } else {
2984: my $username = $entries{$fields{'username'}};
2985: my $sec;
2986: if ($context eq 'course' || $setting eq 'course') {
2987: # determine section number
2988: if (defined($fields{'sec'})) {
2989: if (defined($entries{$fields{'sec'}})) {
2990: $sec=$entries{$fields{'sec'}};
2991: }
2992: } else {
2993: $sec = $defaultsec;
2994: }
2995: # remove non alphanumeric values from section
2996: $sec =~ s/\W//g;
2997: if ($sec eq "none" || $sec eq 'all') {
2998: $r->print('<br />'.
2999: &mt('<b>[_1]</b>: Unable to enroll: section name "[_2]" for user [_3] [_4] [_5] [_6] is a reserved word.',
3000: $username,$sec,$fname,$mname,$lname,$gen));
3001: next;
3002: } elsif (($sec ne '') && (exists($curr_groups{$sec}))) {
3003: $r->print('<br />'.
3004: &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.',
3005: $username,$sec,$fname,$mname,$lname,$gen));
3006: next;
3007: }
3008: }
3009: # determine id number
3010: my $id='';
3011: if (defined($fields{'id'})) {
3012: if (defined($entries{$fields{'id'}})) {
3013: $id=$entries{$fields{'id'}};
3014: }
3015: $id=~tr/A-Z/a-z/;
3016: }
3017: # determine email address
3018: my $email='';
3019: if (defined($fields{'email'})) {
3020: if (defined($entries{$fields{'email'}})) {
3021: $email=$entries{$fields{'email'}};
3022: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; } }
3023: }
3024: # determine user password
3025: my $password = $genpwd;
3026: if (defined($fields{'ipwd'})) {
3027: if ($entries{$fields{'ipwd'}}) {
3028: $password=$entries{$fields{'ipwd'}};
3029: }
3030: }
3031: # determine user role
3032: my $role = '';
3033: if (defined($fields{'role'})) {
3034: if ($entries{$fields{'role'}}) {
3035: my @poss_roles =
3036: &curr_role_permissions($context,$setting);
3037: if (grep(/^\Q$entries{$fields{'role'}}\E/,@poss_roles)) {
3038: $role=$entries{$fields{'role'}};
3039: } else {
3040: my $rolestr = join(', ',@poss_roles);
3041: $r->print('<br />'.
3042: &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");
3043: next;
3044: }
3045: }
3046: }
3047: if ($role eq '') {
3048: $role = $defaultrole;
3049: }
3050: # Clean up whitespace
3051: foreach (\$domain,\$username,\$id,\$fname,\$mname,
3052: \$lname,\$gen,\$sec,\$role) {
3053: $$_ =~ s/(\s+$|^\s+)//g;
3054: }
3055: # check against rules
3056: my $checkid = 0;
3057: my $newuser = 0;
3058: my (%rulematch,%inst_results,%idinst_results);
3059: my $uhome=&Apache::lonnet::homeserver($username,$domain);
3060: if ($uhome eq 'no_host') {
3061: $checkid = 1;
3062: $newuser = 1;
3063: my $checkhash;
3064: my $checks = { 'username' => 1 };
3065: $checkhash->{$username.':'.$domain} = { 'newuser' => 1, };
3066: &Apache::loncommon::user_rule_check($checkhash,$checks,
3067: \%alerts,\%rulematch,\%inst_results,\%curr_rules,
3068: \%got_rules);
3069: if (ref($alerts{'username'}) eq 'HASH') {
3070: if (ref($alerts{'username'}{$domain}) eq 'HASH') {
3071: next if ($alerts{'username'}{$domain}{$username});
3072: }
3073: }
3074: } else {
3075: # FIXME check if user info can be updated.
3076: }
3077: if ($id ne '') {
3078: if (!$newuser) {
3079: my %idhash = &Apache::lonnet::idrget($domain,($username));
3080: if ($idhash{$username} ne $id) {
3081: $checkid = 1;
3082: }
3083: }
3084: if ($checkid) {
3085: my $checkhash;
3086: my $checks = { 'id' => 1 };
3087: $checkhash->{$username.':'.$domain} = { 'newuser' => $newuser,
3088: 'id' => $id };
3089: &Apache::loncommon::user_rule_check($checkhash,$checks,
3090: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,
3091: \%got_rules);
3092: if (ref($alerts{'id'}) eq 'HASH') {
3093: if (ref($alerts{'id'}{$domain}) eq 'HASH') {
3094: next if ($alerts{'id'}{$domain}{$id});
3095: }
3096: }
3097: }
3098: }
3099: if ($password || $env{'form.login'} eq 'loc') {
3100: my ($userresult,$authresult,$roleresult);
3101: if ($role eq 'st') {
3102: &modifystudent($domain,$username,$cid,$sec,
3103: $desiredhost);
3104: $roleresult =
3105: &Apache::lonnet::modifystudent
3106: ($domain,$username,$id,$amode,$password,
3107: $fname,$mname,$lname,$gen,$sec,$enddate,
3108: $startdate,$env{'form.forceid'},
3109: $desiredhost,$email);
3110: } else {
3111: ($userresult,$authresult,$roleresult) =
3112: &modifyuserrole($context,$setting,
3113: $changeauth,$cid,$domain,$username,
3114: $id,$amode,$password,$fname,
3115: $mname,$lname,$gen,$sec,
3116: $env{'form.forceid'},$desiredhost,
3117: $email,$role,$enddate,$startdate,$checkid);
3118: }
3119: $flushc =
3120: &user_change_result($r,$userresult,$authresult,
3121: $roleresult,\%counts,$flushc,
3122: $username,%userchg);
3123: } else {
3124: if ($context eq 'course') {
3125: $r->print('<br />'.
3126: &mt('<b>[_1]</b>: Unable to enroll. No password specified.',$username)
3127: );
3128: } elsif ($context eq 'author') {
3129: $r->print('<br />'.
3130: &mt('<b>[_1]</b>: Unable to add co-author. No password specified.',$username)
3131: );
3132: } else {
3133: $r->print('<br />'.
3134: &mt('<b>[_1]</b>: Unable to add user. No password specified.',$username)
3135: );
3136: }
3137: }
3138: }
3139: }
3140: } # end of foreach (@userdata)
3141: # Flush the course logs so reverse user roles immediately updated
3142: &Apache::lonnet::flushcourselogs();
3143: $r->print("</p>\n<p>\n".&mt('Processed [_1] user(s).',$counts{'user'}).
3144: "</p>\n");
3145: if ($counts{'role'} > 0) {
3146: $r->print("<p>\n".
3147: &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");
3148: }
3149: if ($counts{'auth'} > 0) {
3150: $r->print("<p>\n".
3151: &mt('Authentication changed for [_1] existing users.',
3152: $counts{'auth'})."</p>\n");
3153: }
3154: $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
3155: $r->print('<form name="uploadresult" action="/adm/createuser">');
3156: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','prevphase','currstate']));
3157: $r->print('</form>');
3158: #####################################
3159: # Drop students #
3160: #####################################
3161: if ($env{'form.fullup'} eq 'yes') {
3162: $r->print('<h3>'.&mt('Dropping Students')."</h3>\n");
3163: # Get current classlist
3164: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
3165: if (! defined($classlist)) {
3166: $r->print(&mt('There are no students currently enrolled.').
3167: "\n");
3168: } else {
3169: # Remove the students we just added from the list of students.
3170: foreach (@userdata) {
3171: my %entries=&Apache::loncommon::record_sep($_);
3172: unless (($entries{$fields{'username'}} eq '') ||
3173: (!defined($entries{$fields{'username'}}))) {
3174: delete($classlist->{$entries{$fields{'username'}}.
3175: ':'.$domain});
3176: }
3177: }
3178: # Print out list of dropped students.
3179: &show_drop_list($r,$classlist,$keylist,'nosort');
3180: }
3181: }
3182: } # end of unless
3183: }
3184:
3185: sub print_namespacing_alerts {
3186: my ($domain,$alerts,$curr_rules) = @_;
3187: my $output;
3188: if (ref($alerts) eq 'HASH') {
3189: if (keys(%{$alerts}) > 0) {
3190: if (ref($alerts->{'username'}) eq 'HASH') {
3191: foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
3192: my $count;
3193: if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
3194: $count = keys(%{$alerts->{'username'}{$dom}});
3195: }
3196: my $domdesc = &Apache::lonnet::domain($domain,'description');
3197: if (ref($curr_rules->{$dom}) eq 'HASH') {
3198: $output .= &Apache::loncommon::instrule_disallow_msg(
3199: 'username',$domdesc,$count,'upload');
3200: }
3201: $output .= &Apache::loncommon::user_rule_formats($dom,
3202: $domdesc,$curr_rules->{$dom}{'username'},
3203: 'username');
3204: }
3205: }
3206: if (ref($alerts->{'id'}) eq 'HASH') {
3207: foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
3208: my $count;
3209: if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
3210: $count = keys(%{$alerts->{'id'}{$dom}});
3211: }
3212: my $domdesc = &Apache::lonnet::domain($domain,'description');
3213: if (ref($curr_rules->{$dom}) eq 'HASH') {
3214: $output .= &Apache::loncommon::instrule_disallow_msg(
3215: 'id',$domdesc,$count,'upload');
3216: }
3217: $output .= &Apache::loncommon::user_rule_formats($dom,
3218: $domdesc,$curr_rules->{$dom}{'id'},'id');
3219: }
3220: }
3221: }
3222: }
3223: }
3224:
3225: sub user_change_result {
3226: my ($r,$userresult,$authresult,$roleresult,$counts,$flushc,$username,
3227: $userchg) = @_;
3228: my $okresult = 0;
3229: if ($userresult ne 'ok') {
3230: if ($userresult =~ /^error:(.+)$/) {
3231: my $error = $1;
3232: $r->print('<br />'.
3233: &mt('<b>[_1]</b>: Unable to add/modify: [_2]',$username,$error));
3234: }
3235: } else {
3236: $counts->{'user'} ++;
3237: $okresult = 1;
3238: }
3239: if ($authresult ne 'ok') {
3240: if ($authresult =~ /^error:(.+)$/) {
3241: my $error = $1;
3242: $r->print('<br />'.
3243: &mt('<b>[_1]</b>: Unable to modify authentication: [_2]',$username,$error));
3244: }
3245: } else {
3246: $counts->{'auth'} ++;
3247: $okresult = 1;
3248: }
3249: if ($roleresult ne 'ok') {
3250: if ($roleresult =~ /^error:(.+)$/) {
3251: my $error = $1;
3252: $r->print('<br />'.
3253: &mt('<b>[_1]</b>: Unable to add role: [_2]',$username,$error));
3254: }
3255: } else {
3256: $counts->{'role'} ++;
3257: $okresult = 1;
3258: }
3259: if ($okresult) {
3260: $flushc++;
3261: $userchg->{$username}=1;
3262: $r->print('. ');
3263: if ($flushc>15) {
3264: $r->rflush;
3265: $flushc=0;
3266: }
3267: }
3268: return $flushc;
3269: }
3270:
3271: # ========================================================= Menu Phase Two Drop
3272: sub print_expire_menu {
3273: my ($r,$context) = @_;
3274: $r->print("<h3>".&mt("Expire Users' Roles")."</h3>");
3275: my $cid=$env{'request.course.id'};
3276: my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
3277: if (! defined($classlist)) {
3278: $r->print(&mt('There are no students currently enrolled.')."\n");
3279: return;
3280: }
3281: # Print out the available choices
3282: &show_drop_list($r,$classlist,$keylist);
3283: return;
3284: }
3285:
3286:
3287: # ================================================================== Phase four
3288:
3289: sub update_user_list {
3290: my ($r,$context,$setting,$choice) = @_;
3291: my $now = time;
3292: my $count=0;
3293: my @changelist;
3294: if ($choice ne '') {
3295: @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
3296: } else {
3297: @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
3298: }
3299: my %result_text = ( ok => { 'revoke' => 'Revoked',
3300: 'delete' => 'Deleted',
3301: 'reenable' => 'Re-enabled',
3302: 'activate' => 'Activated',
3303: },
3304: error => {'revoke' => 'revoking',
3305: 'delete' => 'deleting',
3306: 'reenable' => 're-enabling',
3307: 'activate' => 'activating',
3308: },
3309: );
3310: my ($startdate,$enddate);
3311: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
3312: ($startdate,$enddate) = &get_dates_from_form();
3313: }
3314: foreach my $item (@changelist) {
3315: my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,@sections,
3316: $scopestem);
3317: if ($context eq 'course') {
3318: ($uname,$udom,$role,$sec,$type,$locktype) = split(/\:/,$item,-1);
3319: $cid = $env{'request.course.id'};
3320: $scopestem = '/'.$cid;
3321: $scopestem =~s/\_/\//g;
3322: if ($sec eq '') {
3323: $scope = $scopestem;
3324: } else {
3325: $scope = $scopestem.'/'.$sec;
3326: }
3327: } elsif ($context eq 'author') {
3328: ($uname,$udom,$role) = split(/\:/,$item,-1);
3329: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
3330: } elsif ($context eq 'domain') {
3331: if ($setting eq 'domain') {
3332: ($role,$uname,$udom) = split(/\:/,$item,-1);
3333: $scope = '/'.$env{'request.role.domain'}.'/';
3334: } elsif ($setting eq 'author') {
3335: ($uname,$udom,$role,$scope) = split(/\:/,$item);
3336: } elsif ($setting eq 'course') {
3337: ($uname,$udom,$role,$cid,$sec,$type,$locktype) =
3338: split(/\:/,$item);
3339: $scope = '/'.$cid;
3340: $scope =~s/\_/\//g;
3341: if ($sec ne '') {
3342: $scope .= '/'.$sec;
3343: }
3344: }
3345: }
3346: my $plrole = &Apache::lonnet::plaintext($role);
3347: my ($uid,$first,$middle,$last,$gene,$sec);
3348: my $start = $env{'form.'.$item.'_start'};
3349: my $end = $env{'form.'.$item.'_end'};
3350: # revoke or delete user role
3351: if ($choice eq 'revoke') {
3352: $end = $now;
3353: if ($role eq 'st') {
3354: $result =
3355: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
3356: } else {
3357: $result =
3358: &Apache::lonnet::revokerole($udom,$uname,$scope,$role);
3359: }
3360: } elsif ($choice eq 'delete') {
3361: $start = -1;
3362: $end = -1;
3363: if ($role eq 'st') {
3364: # FIXME - how does role deletion affect classlist?
3365: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
3366: } else {
3367: $result =
3368: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
3369: 0,1);
3370: }
3371: } else {
3372: #reenable, activate, change access dates or change section
3373: if ($choice ne 'chgsec') {
3374: $start = $startdate;
3375: $end = $enddate;
3376: }
3377: if ($choice eq 'reenable') {
3378: if ($role eq 'st') {
3379: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
3380: } else {
3381: $result =
3382: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
3383: $now);
3384: }
3385: } elsif ($choice eq 'activate') {
3386: if ($role eq 'st') {
3387: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
3388: } else {
3389: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
3390: $now);
3391: }
3392: } elsif ($choice eq 'chgdates') {
3393: if ($role eq 'st') {
3394: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
3395: } else {
3396: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
3397: $start);
3398: }
3399: } elsif ($choice eq 'chgsec') {
3400: my (@newsecs,$revresult,$nochg,@retained);
3401: if ($role ne 'cc') {
3402: @newsecs = split(/,/,$env{'form.newsecs'});
3403: }
3404: # remove existing section if not to be retained.
3405: if (!$env{'form.retainsec'}) {
3406: if ($sec eq '') {
3407: if (@newsecs == 0) {
3408: $result = &mt('No change in section assignment (none)');
3409: $nochg = 1;
3410: }
3411: } else {
3412: if (!grep(/^\Q$sec\E$/,@newsecs)) {
3413: $revresult =
3414: &Apache::lonnet::revokerole($udom,$uname,$scope,$role);
3415: } else {
3416: push(@retained,$sec);
3417: }
3418: }
3419: } else {
3420: push(@retained,$sec);
3421: }
3422: # add new sections
3423: if (@newsecs == 0) {
3424: if (!$nochg) {
3425: if ($sec ne '') {
3426: if ($role eq 'st') {
3427: $result =
3428: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid);
3429: } else {
3430: my $newscope = $scopestem;
3431: $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start);
3432: }
3433: }
3434: }
3435: } else {
3436: foreach my $newsec (@newsecs) {
3437: if (!grep(/^\Q$newsec\E$/,@retained)) {
3438: if ($role eq 'st') {
3439: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid);
3440: } else {
3441: my $newscope = $scopestem;
3442: if ($newsec ne '') {
3443: $newscope .= '/'.$newsec;
3444: }
3445: $result = &Apache::lonnet::assignrole($udom,$uname,
3446: $newscope,$role,$end,$start);
3447: }
3448: }
3449: }
3450: }
3451: }
3452: }
3453: if ($result eq 'ok' || $result eq 'ok:') {
3454: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]",
3455: $plrole,$scope,$uname.':'.$udom).'<br />');
3456: $count++;
3457: } else {
3458: $r->print(
3459: &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]:[_4]",
3460: $plrole,$scope,$uname.':'.$udom,$result).'<br />');
3461: }
3462: }
3463: $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,users].",$count).'</b></p>');
3464: if ($count > 0) {
3465: if ($choice eq 'revoke') {
3466: $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.</p>'));
3467: }
3468: # Flush the course logs so reverse user roles immediately updated
3469: &Apache::lonnet::flushcourselogs();
3470: }
3471: if ($env{'form.makedatesdefault'}) {
3472: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
3473: $r->print(&make_dates_default($startdate,$enddate));
3474: }
3475: }
3476: }
3477:
3478: sub classlist_drop {
3479: my ($scope,$uname,$udom,$now,$action) = @_;
3480: my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
3481: my $cid=$cdom.'_'.$cnum;
3482: my $user = $uname.':'.$udom;
3483: if ($action eq 'drop') {
3484: if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
3485: my $result =
3486: &Apache::lonnet::cput('classlist',
3487: { $user => $now },
3488: $env{'course.'.$cid.'.domain'},
3489: $env{'course.'.$cid.'.num'});
3490: return &mt('Drop from classlist: [_1]',
3491: '<b>'.$result.'</b>').'<br />';
3492: }
3493: }
3494: }
3495:
3496: sub active_student_roles {
3497: my ($cnum,$cdom,$uname,$udom) = @_;
3498: my %roles =
3499: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
3500: ['future','active'],['st']);
3501: return exists($roles{"$cnum:$cdom:st"});
3502: }
3503:
3504: sub section_check_js {
3505: my $groupslist= &get_groupslist();
3506: return <<"END";
3507: function validate(caller) {
3508: var groups = new Array($groupslist);
3509: var secname = caller.value;
3510: if ((secname == 'all') || (secname == 'none')) {
3511: alert("'"+secname+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
3512: return 'error';
3513: }
3514: if (secname != '') {
3515: for (var k=0; k<groups.length; k++) {
3516: if (secname == groups[k]) {
3517: 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.");
3518: return 'error';
3519: }
3520: }
3521: }
3522: return 'ok';
3523: }
3524: END
3525: }
3526:
3527: sub set_login {
3528: my ($dom,$authformkrb,$authformint,$authformloc) = @_;
3529: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3530: my $response;
3531: my ($authnum,%can_assign) =
3532: &Apache::loncommon::get_assignable_auth($dom);
3533: if ($authnum) {
3534: $response = &Apache::loncommon::start_data_table();
3535: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
3536: $response .= &Apache::loncommon::start_data_table_row().
3537: '<td>'.$authformkrb.'</td>'.
3538: &Apache::loncommon::end_data_table_row()."\n";
3539: }
3540: if ($can_assign{'int'}) {
3541: $response .= &Apache::loncommon::start_data_table_row().
3542: '<td>'.$authformint.'</td>'.
3543: &Apache::loncommon::end_data_table_row()."\n"
3544: }
3545: if ($can_assign{'loc'}) {
3546: $response .= &Apache::loncommon::start_data_table_row().
3547: '<td>'.$authformloc.'</td>'.
3548: &Apache::loncommon::end_data_table_row()."\n";
3549: }
3550: $response .= &Apache::loncommon::end_data_table();
3551: }
3552: return $response;
3553: }
3554:
3555: sub course_sections {
3556: my ($sections_count,$role) = @_;
3557: my $output = '';
3558: my @sections = (sort {$a <=> $b} keys %{$sections_count});
3559: if (scalar(@sections) == 1) {
3560: $output = '<select name="currsec_'.$role.'" >'."\n".
3561: ' <option value="">Select</option>'."\n".
3562: ' <option value="">No section</option>'."\n".
3563: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
3564: } else {
3565: $output = '<select name="currsec_'.$role.'" ';
3566: my $multiple = 4;
3567: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
3568: $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
3569: foreach my $sec (@sections) {
3570: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
3571: }
3572: }
3573: $output .= '</select>';
3574: return $output;
3575: }
3576:
3577: sub get_groupslist {
3578: my $groupslist;
3579: my %curr_groups = &Apache::longroup::coursegroups();
3580: if (%curr_groups) {
3581: $groupslist = join('","',sort(keys(%curr_groups)));
3582: $groupslist = '"'.$groupslist.'"';
3583: }
3584: return $groupslist;
3585: }
3586:
3587: sub setsections_javascript {
3588: my ($form,$groupslist) = @_;
3589: my ($checkincluded,$finish,$roleplace,$setsection_js);
3590: if ($form eq 'cu') {
3591: $checkincluded = 'formname.elements[i-1].checked == true';
3592: $finish = 'formname.submit()';
3593: $roleplace = 3;
3594: } else {
3595: $checkincluded = 'formname.name == "'.$form.'"';
3596: $finish = "seccheck = 'ok';";
3597: $roleplace = 1;
3598: $setsection_js = "var seccheck = 'alert';";
3599: }
3600: my %alerts = &Apache::lonlocal::texthash(
3601: secd => 'Section designations do not apply to Course Coordinator roles.',
3602: accr => 'A course coordinator role will be added with access to all sections.',
3603: inea => 'In each course, each user may only have one student role at a time.',
3604: youh => 'You had selected ',
3605: secs => 'sections.',
3606: plmo => 'Please modify your selections so they include no more than one section.',
3607: mayn => 'may not be used as the name for a section, as it is a reserved word.',
3608: plch => 'Please choose a different section name.',
3609: mnot => 'may not be used as a section name, as it is the name of a course group.',
3610: secn => 'Section names and group names must be distinct. Please choose a different section name.',
3611: );
3612: $setsection_js .= <<"ENDSECCODE";
3613:
3614: function setSections(formname) {
3615: var re1 = /^currsec_/;
3616: var groups = new Array($groupslist);
3617: for (var i=0;i<formname.elements.length;i++) {
3618: var str = formname.elements[i].name;
3619: var checkcurr = str.match(re1);
3620: if (checkcurr != null) {
3621: if ($checkincluded) {
3622: var match = str.split('_');
3623: var role = match[$roleplace];
3624: if (role == 'cc') {
3625: alert("$alerts{'secd'}\\n$alerts{'accr'}");
3626: }
3627: else {
3628: var sections = '';
3629: var numsec = 0;
3630: var sections;
3631: for (var j=0; j<formname.elements[i].length; j++) {
3632: if (formname.elements[i].options[j].selected == true ) {
3633: if (formname.elements[i].options[j].value != "") {
3634: if (numsec == 0) {
3635: if (formname.elements[i].options[j].value != "") {
3636: sections = formname.elements[i].options[j].value;
3637: numsec ++;
3638: }
3639: }
3640: else {
3641: sections = sections + "," + formname.elements[i].options[j].value
3642: numsec ++;
3643: }
3644: }
3645: }
3646: }
3647: if (numsec > 0) {
3648: if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) {
3649: sections = sections + "," + formname.elements[i+1].value;
3650: }
3651: }
3652: else {
3653: sections = formname.elements[i+1].value;
3654: }
3655: var newsecs = formname.elements[i+1].value;
3656: var numsplit;
3657: if (newsecs != null && newsecs != "") {
3658: numsplit = newsecs.split(/,/g);
3659: numsec = numsec + numsplit.length;
3660: }
3661:
3662: if ((role == 'st') && (numsec > 1)) {
3663: alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}")
3664: return;
3665: }
3666: else {
3667: if (numsplit != null) {
3668: for (var j=0; j<numsplit.length; j++) {
3669: if ((numsplit[j] == 'all') ||
3670: (numsplit[j] == 'none')) {
3671: alert("'"+numsplit[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
3672: return;
3673: }
3674: for (var k=0; k<groups.length; k++) {
3675: if (numsplit[j] == groups[k]) {
3676: alert("'"+numsplit[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
3677: return;
3678: }
3679: }
3680: }
3681: }
3682: formname.elements[i+2].value = sections;
3683: }
3684: }
3685: }
3686: }
3687: }
3688: $finish
3689: }
3690: ENDSECCODE
3691: return $setsection_js;
3692: }
3693:
3694: 1;
3695:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>