1: # The LearningOnline Network with CAPA
2: # Handler to drop and add students in courses
3: #
4: # $Id: londropadd.pm,v 1.172 2007/10/11 02:16:25 albertel 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: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
30: ##############################################################
31:
32: package Apache::londropadd;
33:
34: use strict;
35: use Apache::lonnet;
36: use Apache::loncommon();
37: use Apache::lonhtmlcommon();
38: use Apache::Constants qw(:common :http REDIRECT);
39: use Spreadsheet::WriteExcel;
40: use Apache::lonstathelpers();
41: use Apache::lonlocal;
42: use Apache::longroup;
43: use LONCAPA();
44:
45: ###############################################################
46: ###############################################################
47: sub header {
48: my ($jscript,$loaditems) = @_;
49: my $start_page;
50: if (ref($loaditems) eq 'HASH') {
51: $start_page=&Apache::loncommon::start_page('Enrollment Manager',$jscript,{'add_entries' => $loaditems,});
52: } else {
53: $start_page=&Apache::loncommon::start_page('Enrollment Manager',$jscript);
54: }
55: return(<<ENDHEAD);
56: $start_page
57: <form method="post" enctype="multipart/form-data"
58: action="/adm/dropadd" name="studentform">
59: ENDHEAD
60: }
61:
62: ###############################################################
63: ###############################################################
64: # Drop student from all sections of a course, except optional $csec
65: sub modifystudent {
66: my ($udom,$unam,$courseid,$csec,$desiredhost)=@_;
67: # if $csec is undefined, drop the student from all the courses matching
68: # this one. If $csec is defined, drop them from all other sections of
69: # this course and add them to section $csec
70: my $cdom = $env{'course.'.$courseid.'.domain'};
71: my $cnum = $env{'course.'.$courseid.'.num'};
72: my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
73: my ($tmp) = keys(%roles);
74: # Bail out if we were unable to get the students roles
75: return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
76: # Go through the roles looking for enrollment in this course
77: my $result = '';
78: foreach my $course (keys(%roles)) {
79: if ($course=~m{^/\Q$cdom\E/\Q$cnum\E(?:\/)*(?:\s+)*(\w+)*\_st$}) {
80: # We are in this course
81: my $section=$1;
82: $section='' if ($course eq "/$cdom/$cnum".'_st');
83: if (defined($csec) && $section eq $csec) {
84: $result .= 'ok:';
85: } elsif ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
86: my (undef,$end,$start)=split(/\_/,$roles{$course});
87: my $now=time;
88: # if this is an active role
89: if (!($start && ($now<$start)) || !($end && ($now>$end))) {
90: my $reply=&Apache::lonnet::modifystudent
91: # dom name id mode pass f m l g
92: ($udom,$unam,'', '', '',undef,undef,undef,undef,
93: $section,time,undef,undef,$desiredhost);
94: $result .= $reply.':';
95: }
96: }
97: }
98: }
99: if ($result eq '') {
100: $result = 'Unable to find section for this student';
101: } else {
102: $result =~ s/(ok:)+/ok/g;
103: }
104: return $result;
105: }
106:
107: ###############################################################
108: ###############################################################
109: # build a domain and server selection form
110: sub domain_form {
111: my ($defdom) = @_;
112: # Set up domain and server selection forms
113: #
114: # Get the domains
115: my @domains = &Apache::lonnet::all_domains();
116: # build up the menu information to be passed to
117: # &Apache::loncommon::linked_select_forms
118: my %select_menus;
119: foreach my $dom (@domains) {
120: # set up the text for this domain
121: $select_menus{$dom}->{'text'}= $dom;
122: # we want a choice of 'default' as the default in the second menu
123: $select_menus{$dom}->{'default'}= 'default';
124: $select_menus{$dom}->{'select2'}->{'default'} = 'default';
125: # Now build up the other items in the second menu
126: my %servers = &Apache::lonnet::get_servers($dom,'library');
127: foreach my $server (keys(%servers)) {
128: $select_menus{$dom}->{'select2'}->{$server}
129: = "$server $servers{$server}";
130: }
131: }
132: my $result = &Apache::loncommon::linked_select_forms
133: ('studentform',' with home server ',$defdom,
134: 'lcdomain','lcserver',\%select_menus);
135: return $result;
136: }
137:
138: ###############################################################
139: ###############################################################
140: # Menu Phase One
141: sub print_main_menu {
142: my ($r,$permission)=@_;
143: #
144: my $cid =$env{'request.course.id'};
145: my $cdom=$env{'course.'.$cid.'.domain'};
146: my $cnum=$env{'course.'.$cid.'.num'};
147: my @menu =
148: (
149: { text => 'Upload a class list',
150: help => 'Course_Create_Class_List',
151: action => 'upload',
152: permission => $permission->{'enrl'},
153: },
154: { text => 'Enroll a single student',
155: help => 'Course_Add_Student',
156: action => 'enrollstudent',
157: permission => $permission->{'enrl'},
158: },
159: { text => 'Modify student data',
160: help => 'Course_Modify_Student_Data',
161: action => 'modifystudent',
162: permission => $permission->{'enrl'},
163: },
164: { text => 'View Class List',
165: help => 'Course_View_Class_List',
166: action => 'classlist',
167: permission => $permission->{'view'},
168: },
169: { text => 'Drop Students',
170: help => 'Course_Drop_Student',
171: action => 'drop',
172: permission => $permission->{'enrl'},
173: },
174: { text => 'Automated Enrollment Manager',
175: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
176: && $permission->{'enrl'}),
177: url => '/adm/populate',
178: },
179: { text => 'Create a new group',
180: help => 'Course_Create_Group',
181: permission => $permission->{'grp_manage'},
182: url => '/adm/coursegroups?refpage=enrl&action=create',
183: },
184: { text => 'Modify an existing group',
185: help => 'Course_Modify_Group',
186: permission => $permission->{'grp_manage'},
187: url => '/adm/coursegroups?refpage=enrl&action=modify',
188: },
189: { text => 'Delete an existing group',
190: help => 'Course_Delete_Group',
191: permission => $permission->{'grp_manage'},
192: url => '/adm/coursegroups?refpage=enrl&action=delete',
193: },
194: { text => 'Re-enable a deleted group',
195: help => 'Course_Reenable_Group',
196: permission => $permission->{'grp_manage'},
197: url => '/adm/coursegroups?refpage=enrl&action=reenable',
198: },
199: { text => 'Enter an existing group',
200: help => 'Course_Display_Group',
201: permission => $permission->{'grp_view'},
202: url => '/adm/coursegroups?refpage=enrl&action=view',
203: },
204: );
205: my $menu_html = '';
206: foreach my $menu_item (@menu) {
207: next if (! $menu_item->{'permission'});
208: $menu_html.='<p>';
209: $menu_html.='<font size="+1">';
210: if (exists($menu_item->{'url'})) {
211: $menu_html.=qq{<a href="$menu_item->{'url'}">};
212: } else {
213: $menu_html.=
214: qq{<a href="/adm/dropadd?action=$menu_item->{'action'}">};
215: }
216: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
217: if (exists($menu_item->{'help'})) {
218: $menu_html.=
219: &Apache::loncommon::help_open_topic($menu_item->{'help'});
220: }
221: $menu_html.='</p>'.$/;
222: }
223: $r->print($menu_html);
224: return;
225: }
226:
227: ###############################################################
228: ###############################################################
229: sub hidden_input {
230: my ($name,$value) = @_;
231: return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n";
232: }
233:
234: sub print_upload_manager_header {
235: my ($r,$datatoken,$distotal,$krbdefdom)=@_;
236: my $javascript;
237: #
238: if (! exists($env{'form.upfile_associate'})) {
239: $env{'form.upfile_associate'} = 'forward';
240: }
241: if ($env{'form.associate'} eq 'Reverse Association') {
242: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
243: $env{'form.upfile_associate'} = 'reverse';
244: } else {
245: $env{'form.upfile_associate'} = 'forward';
246: }
247: }
248: if ($env{'form.upfile_associate'} eq 'reverse') {
249: $javascript=&upload_manager_javascript_reverse_associate();
250: } else {
251: $javascript=&upload_manager_javascript_forward_associate();
252: }
253: #
254: # Deal with restored settings
255: my $password_choice = '';
256: if (exists($env{'form.ipwd_choice'}) &&
257: $env{'form.ipwd_choice'} ne '') {
258: # If a column was specified for password, assume it is for an
259: # internal password. This is a bug waiting to be filed (could be
260: # local or krb auth instead of internal) but I do not have the
261: # time to mess around with this now.
262: $password_choice = 'int';
263: }
264: #
265: my $javascript_validations =
266: &javascript_validations('auth',$krbdefdom,$password_choice,undef,
267: $env{'request.role.domain'});
268: my $checked=(($env{'form.noFirstLine'})?' checked="checked" ':'');
269: $r->print('<h3>'.&mt('Uploading Class List')."</h3>\n".
270: "<hr>\n".
271: '<h3>'.&mt('Identify fields')."</h3>\n");
272: $r->print("<p>\n".
273: &mt('Total number of records found in file: [_1].',$distotal).
274: "\n".
275: "</p><hr>\n");
276: $r->print(&mt('Enter as many fields as you can. The system will inform you and bring you back to this page if the data selected is insufficient to enroll students in your class.')."<hr>\n");
277: $r->print(&hidden_input('action','upload').
278: &hidden_input('state','got_file').
279: &hidden_input('associate','').
280: &hidden_input('datatoken',$datatoken).
281: &hidden_input('fileupload',$env{'form.fileupload'}).
282: &hidden_input('upfiletype',$env{'form.upfiletype'}).
283: &hidden_input('upfile_associate',$env{'form.upfile_associate'}));
284: $r->print('<input type="button" value="Reverse Association" '.
285: 'name="'.&mt('Reverse Association').'" '.
286: 'onClick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />');
287: $r->print('<label><input type="checkbox" name="noFirstLine"'.$checked.'/>'.
288: &mt('Ignore First Line').'</label>');
289: $r->print("<hr />\n".
290: '<script type="text/javascript" language="Javascript">'."\n".
291: $javascript."\n".$javascript_validations.'</script>');
292: }
293:
294: ###############################################################
295: ###############################################################
296: sub javascript_validations {
297: my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain)=@_;
298: my $authheader;
299: if ($mode eq 'auth') {
300: my %param = ( formname => 'studentform',
301: kerb_def_dom => $krbdefdom,
302: curr_authtype => $curr_authtype);
303: $authheader = &Apache::loncommon::authform_header(%param);
304: } elsif ($mode eq 'createcourse') {
305: my %param = ( formname => 'ccrs',
306: kerb_def_dom => $krbdefdom,
307: curr_authtype => $curr_authtype );
308: $authheader = &Apache::loncommon::authform_header(%param);
309: } elsif ($mode eq 'modifycourse') {
310: my %param = ( formname => 'cmod',
311: kerb_def_dom => $krbdefdom,
312: mode => 'modifycourse',
313: curr_authtype => $curr_authtype,
314: curr_autharg => $curr_authfield );
315: $authheader = &Apache::loncommon::authform_header(%param);
316: }
317:
318:
319: my %alert = &Apache::lonlocal::texthash
320: (username => 'You need to specify the username field.',
321: authen => 'You must choose an authentication type.',
322: krb => 'You need to specify the Kerberos domain.',
323: ipass => 'You need to specify the initial password.',
324: name => 'The optional name field was not specified.',
325: snum => 'The optional student number field was not specified.',
326: section => 'The optional section field was not specified.',
327: email => 'The optional email address field was not specified.',
328: continue => 'Continue enrollment?',
329: );
330:
331: # my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
332: my $function_name =(<<END);
333: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail) {
334: END
335: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($domain);
336: my $auth_checks;
337: if ($mode eq 'createcourse') {
338: $auth_checks .= (<<END);
339: if (vf.autoadds[0].checked == true) {
340: if (current.radiovalue == null || current.radiovalue == 'nochange') {
341: alert('$alert{'authen'}');
342: return;
343: }
344: }
345: END
346: } else {
347: $auth_checks .= (<<END);
348: var foundatype=0;
349: if (founduname==0) {
350: alert('$alert{'username'}');
351: return;
352: }
353:
354: END
355: if ($authnum > 1) {
356: $auth_checks .= (<<END);
357: // alert('current.radiovalue = '+current.radiovalue);
358: if (current.radiovalue == null || current.radiovalue == '' || current.radiovalue == 'nochange') {
359: // They did not check any of the login radiobuttons.
360: alert('$alert{'authen'}');
361: return;
362: }
363: END
364: }
365: }
366: if ($mode eq 'createcourse') {
367: $auth_checks .= "
368: if ( (vf.autoadds[0].checked == true) &&
369: (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') ) {
370: ";
371: } elsif ($mode eq 'modifycourse') {
372: $auth_checks .= "
373: if (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') {
374: ";
375: }
376: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
377: $auth_checks .= (<<END);
378: var alertmsg = '';
379: switch (current.radiovalue) {
380: case 'krb':
381: alertmsg = '$alert{'krb'}';
382: break;
383: default:
384: alertmsg = '';
385: }
386: if (alertmsg != '') {
387: alert(alertmsg);
388: return;
389: }
390: }
391: END
392: } else {
393: $auth_checks .= (<<END);
394: foundatype=1;
395: if (current.argfield == null || current.argfield == '') {
396: var alertmsg = '';
397: switch (current.value) {
398: case 'krb':
399: alertmsg = '$alert{'krb'}';
400: break;
401: case 'loc':
402: case 'fsys':
403: alertmsg = '$alert{'ipass'}';
404: break;
405: case 'fsys':
406: alertmsg = '';
407: break;
408: default:
409: alertmsg = '';
410: }
411: if (alertmsg != '') {
412: alert(alertmsg);
413: return;
414: }
415: }
416: END
417: }
418: my $section_checks;
419: my $optional_checks = '';
420: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
421: $optional_checks = (<<END);
422: vf.submit();
423: }
424: END
425: } else {
426: $section_checks = §ion_check_js();
427: $optional_checks = (<<END);
428: var message='';
429: if (foundname==0) {
430: message='$alert{'name'}';
431: }
432: if (foundid==0) {
433: if (message!='') {
434: message+='\\n';
435: }
436: message+='$alert{'snum'}';
437: }
438: if (foundsec==0) {
439: if (message!='') {
440: message+='\\n';
441: }
442: message+='$alert{'section'}';
443: }
444: if (foundemail==0) {
445: if (message!='') {
446: message+='\\n';
447: }
448: message+='$alert{'email'}';
449: }
450: if (message!='') {
451: message+= '\\n$alert{'continue'}';
452: if (confirm(message)) {
453: vf.state.value='enrolling';
454: vf.submit();
455: }
456: } else {
457: vf.state.value='enrolling';
458: vf.submit();
459: }
460: }
461: END
462: }
463: my $result = $function_name;
464: if ( ($mode eq 'auth') || ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
465: $result .= $auth_checks;
466: }
467: $result .= $optional_checks."\n".$section_checks;
468: if ( ($mode eq 'auth') || ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
469: $result .= $authheader;
470: }
471: return $result;
472: }
473:
474: ###############################################################
475: ###############################################################
476: sub upload_manager_javascript_forward_associate {
477: return(<<ENDPICK);
478: function verify(vf,sec_caller) {
479: var founduname=0;
480: var foundpwd=0;
481: var foundname=0;
482: var foundid=0;
483: var foundsec=0;
484: var foundemail=0;
485: var tw;
486: for (i=0;i<=vf.nfields.value;i++) {
487: tw=eval('vf.f'+i+'.selectedIndex');
488: if (tw==1) { founduname=1; }
489: if ((tw>=2) && (tw<=6)) { foundname=1; }
490: if (tw==7) { foundid=1; }
491: if (tw==8) { foundsec=1; }
492: if (tw==9) { foundpwd=1; }
493: if (tw==10) { foundemail=1; }
494: }
495: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail);
496: }
497:
498: //
499: // vf = this.form
500: // tf = column number
501: //
502: // values of nw
503: //
504: // 0 = none
505: // 1 = username
506: // 2 = names (lastname, firstnames)
507: // 3 = fname (firstname)
508: // 4 = mname (middlename)
509: // 5 = lname (lastname)
510: // 6 = gen (generation)
511: // 7 = id
512: // 8 = section
513: // 9 = ipwd (password)
514: // 10 = email address
515:
516: function flip(vf,tf) {
517: var nw=eval('vf.f'+tf+'.selectedIndex');
518: var i;
519: // make sure no other columns are labeled the same as this one
520: for (i=0;i<=vf.nfields.value;i++) {
521: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
522: eval('vf.f'+i+'.selectedIndex=0;')
523: }
524: }
525: // If we set this to 'lastname, firstnames', clear out all the ones
526: // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
527: if (nw==2) {
528: for (i=0;i<=vf.nfields.value;i++) {
529: if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
530: (eval('vf.f'+i+'.selectedIndex')<=6)) {
531: eval('vf.f'+i+'.selectedIndex=0;')
532: }
533: }
534: }
535: // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
536: // clear out any that are set to 'lastname, firstnames' (2)
537: if ((nw>=3) && (nw<=6)) {
538: for (i=0;i<=vf.nfields.value;i++) {
539: if (eval('vf.f'+i+'.selectedIndex')==2) {
540: eval('vf.f'+i+'.selectedIndex=0;')
541: }
542: }
543: }
544: // If we set the password, make the password form below correspond to
545: // the new value.
546: if (nw==9) {
547: changed_radio('int',document.studentform);
548: set_auth_radio_buttons('int',document.studentform);
549: vf.intarg.value='';
550: vf.krbarg.value='';
551: vf.locarg.value='';
552: }
553: }
554:
555: function clearpwd(vf) {
556: var i;
557: for (i=0;i<=vf.nfields.value;i++) {
558: if (eval('vf.f'+i+'.selectedIndex')==9) {
559: eval('vf.f'+i+'.selectedIndex=0;')
560: }
561: }
562: }
563:
564: ENDPICK
565: }
566:
567: ###############################################################
568: ###############################################################
569: sub upload_manager_javascript_reverse_associate {
570: return(<<ENDPICK);
571: function verify(vf,sec_caller) {
572: var founduname=0;
573: var foundpwd=0;
574: var foundname=0;
575: var foundid=0;
576: var foundsec=0;
577: var tw;
578: for (i=0;i<=vf.nfields.value;i++) {
579: tw=eval('vf.f'+i+'.selectedIndex');
580: if (i==0 && tw!=0) { founduname=1; }
581: if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
582: if (i==6 && tw!=0) { foundid=1; }
583: if (i==7 && tw!=0) { foundsec=1; }
584: if (i==8 && tw!=0) { foundpwd=1; }
585: }
586: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
587: }
588:
589: function flip(vf,tf) {
590: var nw=eval('vf.f'+tf+'.selectedIndex');
591: var i;
592: // picked the all one one name field, reset the other name ones to blank
593: if (tf==1 && nw!=0) {
594: for (i=2;i<=5;i++) {
595: eval('vf.f'+i+'.selectedIndex=0;')
596: }
597: }
598: //picked one of the piecewise name fields, reset the all in
599: //one field to blank
600: if ((tf>=2) && (tf<=5) && (nw!=0)) {
601: eval('vf.f1.selectedIndex=0;')
602: }
603: // intial password specified, pick internal authentication
604: if (tf==8 && nw!=0) {
605: changed_radio('int',document.studentform);
606: set_auth_radio_buttons('int',document.studentform);
607: vf.krbarg.value='';
608: vf.intarg.value='';
609: vf.locarg.value='';
610: }
611: }
612:
613: function clearpwd(vf) {
614: var i;
615: if (eval('vf.f8.selectedIndex')!=0) {
616: eval('vf.f8.selectedIndex=0;')
617: }
618: }
619: ENDPICK
620: }
621:
622: ###############################################################
623: ###############################################################
624: sub print_upload_manager_footer {
625: my ($r,$i,$keyfields,$defdom,$today,$halfyear)=@_;
626:
627: my ($krbdef,$krbdefdom) =
628: &Apache::loncommon::get_kerberos_defaults($defdom);
629: my %param = ( formname => 'document.studentform',
630: kerb_def_dom => $krbdefdom,
631: kerb_def_auth => $krbdef
632: );
633: if (exists($env{'form.ipwd_choice'}) &&
634: defined($env{'form.ipwd_choice'}) &&
635: $env{'form.ipwd_choice'} ne '') {
636: $param{'curr_authtype'} = 'int';
637: }
638: my $krbform = &Apache::loncommon::authform_kerberos(%param);
639: my $intform = &Apache::loncommon::authform_internal(%param);
640: my $locform = &Apache::loncommon::authform_local(%param);
641: my $domform = &domain_form($defdom);
642: my $date_table = &date_setting_table();
643: my $Str = "</table>\n";
644: $Str .= &hidden_input('nfields',$i);
645: $Str .= &hidden_input('keyfields',$keyfields);
646: $Str .= '<h3>'.&mt('Login Type')."</h3>\n";
647: $Str .= "<p>\n".
648: &mt('Note: this will not take effect if the user already exists').
649: &Apache::loncommon::help_open_topic('Auth_Options').
650: "</p><p>\n";
651: $Str .= $krbform."\n</p><p>\n".
652: $intform."\n</p><p>\n".
653: $locform."\n</p>\n";
654: $Str .= '<h3>'.&mt('LON-CAPA Domain for Students')."</h3>\n";
655: $Str .= "<p>\n".&mt('LON-CAPA domain: [_1]',$domform)."\n</p>\n";
656: $Str .= "<h3>".&mt('Starting and Ending Dates')."</h3>\n";
657: $Str .= "<p>\n".$date_table."</p>\n";
658: $Str .= "<h3>".&mt('Full Update')."</h3>\n";
659: $Str .= '<label><input type="checkbox" name="fullup" value="yes">'.
660: ' '.&mt('Full update (also print list of users not enrolled anymore)').
661: "</label></p>\n";
662: $Str .= "<h3>".&mt('Student Number')."</h3>\n";
663: $Str .= "<p>\n".'<label><input type="checkbox" name="forceid" value="yes">';
664: $Str .= &mt('Disable ID/Student Number Safeguard and Force Change '.
665: 'of Conflicting IDs (only do if you know what you are doing)').
666: "</label>\n</p><p>\n";
667: $Str .= '<input type="button"'.
668: 'onClick="javascript:verify(this.form,this.form.csec)" '.
669: 'value="Update Class List" />'."<br />\n";
670: $Str .= &mt('Note: for large courses, this operation may be time '.
671: 'consuming');
672: $r->print($Str);
673: return;
674: }
675:
676: ###############################################################
677: ###############################################################
678: sub print_upload_manager_form {
679: my $r=shift;
680:
681: my $firstLine;
682: my $datatoken;
683: if (!$env{'form.datatoken'}) {
684: $datatoken=&Apache::loncommon::upfile_store($r);
685: } else {
686: $datatoken=$env{'form.datatoken'};
687: &Apache::loncommon::load_tmp_file($r);
688: }
689: my @records=&Apache::loncommon::upfile_record_sep();
690: if($env{'form.noFirstLine'}){
691: $firstLine=shift(@records);
692: }
693: my $total=$#records;
694: my $distotal=$total+1;
695: my $today=time;
696: my $halfyear=$today+15552000;
697: #
698: # Restore memorized settings
699: &Apache::loncommon::restore_course_settings
700: ('enrollment_upload',{ 'username_choice' => 'scalar', # column settings
701: 'names_choice' => 'scalar',
702: 'fname_choice' => 'scalar',
703: 'mname_choice' => 'scalar',
704: 'lname_choice' => 'scalar',
705: 'gen_choice' => 'scalar',
706: 'id_choice' => 'scalar',
707: 'sec_choice' => 'scalar',
708: 'ipwd_choice' => 'scalar',
709: 'email_choice' => 'scalar',
710: });
711: #
712: # Determine kerberos parameters as appropriate
713: my $defdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
714: my ($krbdef,$krbdefdom) =
715: &Apache::loncommon::get_kerberos_defaults($defdom);
716: #
717: &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom);
718: my $i;
719: my $keyfields;
720: if ($total>=0) {
721: my @field=
722: (['username',&mt('Username'), $env{'form.username_choice'}],
723: ['names',&mt('Last Name, First Names'),$env{'form.names_choice'}],
724: ['fname',&mt('First Name'), $env{'form.fname_choice'}],
725: ['mname',&mt('Middle Names/Initials'),$env{'form.mname_choice'}],
726: ['lname',&mt('Last Name'), $env{'form.lname_choice'}],
727: ['gen', &mt('Generation'), $env{'form.gen_choice'}],
728: ['id', &mt('ID/Student Number'),$env{'form.id_choice'}],
729: ['sec', &mt('Section'), $env{'form.sec_choice'}],
730: ['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
731: ['email',&mt('EMail Address'), $env{'form.email_choice'}]);
732: if ($env{'form.upfile_associate'} eq 'reverse') {
733: &Apache::loncommon::csv_print_samples($r,\@records);
734: $i=&Apache::loncommon::csv_print_select_table($r,\@records,
735: \@field);
736: foreach (@field) {
737: $keyfields.=$_->[0].',';
738: }
739: chop($keyfields);
740: } else {
741: unshift(@field,['none','']);
742: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
743: \@field);
744: my %sone=&Apache::loncommon::record_sep($records[0]);
745: $keyfields=join(',',sort(keys(%sone)));
746: }
747: }
748: &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear);
749: }
750:
751: ###############################################################
752: ###############################################################
753: sub enroll_single_student {
754: my ($r,$srcharray) = @_;
755: # Remove non alphanumeric values from section
756: $env{'form.csec'}=~s/\W//g;
757: #
758: # We do the dates first because the action of making them the defaul
759: # in the course is entirely separate from the action of enrolling the
760: # student. Also, a failure in setting the dates as default is not fatal
761: # to the process of enrolling / modifying a student.
762: my ($startdate,$enddate) = &get_dates_from_form();
763: if ($env{'form.makedatesdefault'}) {
764: $r->print(&make_dates_default($startdate,$enddate));
765: }
766:
767: $r->print('<h3>'.&mt('Enrolling Student').'</h3>');
768: $r->print('<p>'.&mt('Enrolling [_1] : [_2]',$env{'form.cuname'},
769: $env{'form.lcdomain'}).'</p>');
770: if (($env{'form.cuname'})
771: && ($env{'form.cuname'}
772: eq &LONCAPA::clean_username($env{'form.cuname'}))
773: && ($env{'form.lcdomain'})
774: && ($env{'form.lcdomain'}
775: eq &LONCAPA::clean_domain($env{'form.lcdomain'}))) {
776: # Deal with home server selection
777: my $domain=$env{'form.lcdomain'};
778: my $desiredhost = $env{'form.lcserver'};
779: if (lc($desiredhost) eq 'default') {
780: $desiredhost = undef;
781: } else {
782: my %home_servers =&Apache::lonnet::get_servers($domain,'library');
783: if (! exists($home_servers{$desiredhost})) {
784: $r->print('<font color="#ff0000">'.&mt('Error').':</font>'.
785: &mt('Invalid home server specified'));
786: return;
787: }
788: }
789: $r->print(" ".&mt('with server')." $desiredhost :") if (defined($desiredhost));
790: # End of home server selection logic
791: my $amode='';
792: my $genpwd='';
793: if ($env{'form.login'} eq 'krb') {
794: $amode='krb';
795: $amode.=$env{'form.krbver'};
796: $genpwd=$env{'form.krbarg'};
797: } elsif ($env{'form.login'} eq 'int') {
798: $amode='internal';
799: $genpwd=$env{'form.intarg'};
800: } elsif ($env{'form.login'} eq 'loc') {
801: $amode='localauth';
802: $genpwd=$env{'form.locarg'};
803: if (!$genpwd) { $genpwd=" "; }
804: }
805: my $home = &Apache::lonnet::homeserver($env{'form.cuname'},
806: $env{'form.lcdomain'});
807: if ((($amode) && ($genpwd)) || ($home ne 'no_host')) {
808: # Clean out any old roles the student has in this class.
809: &modifystudent($env{'form.lcdomain'},$env{'form.cuname'},
810: $env{'request.course.id'},$env{'form.csec'},
811: $desiredhost);
812: my $login_result = &Apache::lonnet::modifystudent
813: ($env{'form.lcdomain'},$env{'form.cuname'},
814: $env{'form.cstid'},$amode,$genpwd,
815: $env{'form.cfirst'},$env{'form.cmiddle'},
816: $env{'form.clast'},$env{'form.cgen'},
817: $env{'form.csec'},$enddate,
818: $startdate,$env{'form.forceid'},
819: $desiredhost,$env{'form.emailaddress'});
820: if ($login_result =~ /^ok/) {
821: $r->print($login_result);
822: $r->print("<p> ".&mt('If active, the new role will be available when the student next logs in to LON-CAPA.')."</p>");
823: } else {
824: $r->print(&mt('unable to enroll').": ".$login_result);
825: }
826: } else {
827: $r->print('<p><font color="#ff0000">'.&mt('ERROR').'</font> ');
828: if ($amode =~ /^krb/) {
829: $r->print(&mt('Missing Kerberos domain information.').' ');
830: } else {
831: $r->print(&mt('Invalid login mode or password.').' ');
832: }
833: $r->print('<b>'.&mt('Unable to enroll').' '.$env{'form.cuname'}.'.</b></p>');
834: }
835: } else {
836: $r->print(&mt('Invalid username or domain'));
837: }
838: $r->print("<p><a href='/adm/dropadd?action=enrollstudent'>".&mt("Enroll another student")."</a></p>");
839: if (ref($srcharray) eq 'ARRAY') {
840: foreach my $item (@{$srcharray},'ccuname','ccdomain') {
841: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
842: }
843: }
844: foreach my $item ('sortby','seluname','seludom') {
845: if (exists($env{'form.'.$item})) {
846: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
847: }
848: }
849: $r->print('<input type="hidden" name="phase" value="get_user_info" />'."\n".
850: '<input type="hidden" name="currstate" value="" />'."\n".
851: '<input type="hidden" name="prevphase" value="" />'."\n".
852: '<input type="hidden" name="action" value="enrollstudent" />'."\n".
853: '<input type="hidden" name="state" value="gotusername" />');
854: }
855:
856: sub setup_date_selectors {
857: my ($starttime,$endtime,$mode) = @_;
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: my $startdateform = &Apache::lonhtmlcommon::date_setter('studentform',
879: 'startdate',
880: $starttime);
881: my $enddateform = &Apache::lonhtmlcommon::date_setter('studentform',
882: 'enddate',
883: $endtime);
884: if ($mode eq 'create_enrolldates') {
885: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
886: 'startenroll',
887: $starttime);
888: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
889: 'endenroll',
890: $endtime);
891: }
892: if ($mode eq 'create_defaultdates') {
893: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
894: 'startaccess',
895: $starttime);
896: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
897: 'endaccess',
898: $endtime);
899: }
900: return ($startdateform,$enddateform);
901: }
902:
903: sub get_dates_from_form {
904: my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
905: my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
906: if ($env{'form.no_end_date'}) {
907: $enddate = 0;
908: }
909: return ($startdate,$enddate);
910: }
911:
912: sub date_setting_table {
913: my ($starttime,$endtime,$mode) = @_;
914: my ($startform,$endform)=&setup_date_selectors($starttime,$endtime,$mode);
915: my $dateDefault = '<nobr>'.
916: '<label><input type="checkbox" name="makedatesdefault" /> '.
917: &mt('make these dates the default for future enrollment').
918: '</label></nobr>';
919: if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
920: $dateDefault = ' ';
921: }
922: my $perpetual = '<nobr><label><input type="checkbox" name="no_end_date"';
923: if (defined($endtime) && $endtime == 0) {
924: $perpetual .= ' checked';
925: }
926: $perpetual.= ' /> '.&mt('no ending date').'</label></nobr>';
927: if ($mode eq 'create_enrolldates') {
928: $perpetual = ' ';
929: }
930: my $result = '';
931: $result .= "<table>\n";
932: $result .= '<tr><td align="right">'.&mt('Starting Date').'</td>'.
933: '<td>'.$startform.'</td>'.
934: '<td>'.$dateDefault.'</td>'."</tr>\n";
935: $result .= '<tr><td align="right">'.&mt('Ending Date').'</td>'.
936: '<td>'.$endform.'</td>'.
937: '<td>'.$perpetual.'</td>'."</tr>\n";
938: $result .= "</table>\n";
939: return $result;
940: }
941:
942: sub make_dates_default {
943: my ($startdate,$enddate) = @_;
944: my $result = '';
945: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
946: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
947: my $put_result = &Apache::lonnet::put('environment',
948: {'default_enrollment_start_date'=>$startdate,
949: 'default_enrollment_end_date' =>$enddate},$dom,$crs);
950: if ($put_result eq 'ok') {
951: $result .= "Set default start and end dates for course<br />";
952: #
953: # Refresh the course environment
954: &Apache::lonnet::coursedescription($env{'request.course.id'},
955: {'freshen_cache' => 1});
956: } else {
957: $result .= &mt('Unable to set default dates for course').":".$put_result.
958: '<br />';
959: }
960: return $result;
961: }
962:
963: ##
964: ## Single student enrollment routines (some of them)
965: ##
966: sub get_student_username_domain_form {
967: my ($r,$elements,$response,$srch,$forcenewuser) = @_;
968: my $loaditems = {
969: 'onload' => "javascript:setFormElements(document.studentform)",
970: };
971: $r->print(&header(undef,$loaditems));
972: &Apache::lonhtmlcommon::add_breadcrumb
973: ({href=>"javascript:backPage(document.studentform,'','')",
974: text=>"Single user search"});
975: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enroll Student',
976: 'Course_Add_Student'));
977: my $defdom=$env{'request.role.domain'};
978:
979: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
980: '<script type="text/javascript">'."\n".
981: &Apache::lonhtmlcommon::set_form_elements($elements->{'studentform'}).
982: '</script>'."\n";
983:
984: my %lt=&Apache::lonlocal::texthash(
985: 'eos' => "Enroll One Student",
986: 'usr' => "Username",
987: 'dom' => "Domain",
988: 'been' => "Begin Enrollment",
989: );
990: $r->print(<<END);
991: $jscript
992: <h3>$lt{'eos'}</h3>
993: END
994: $r->print($response);
995: $r->print(&single_user_entry_form($defdom,$srch,$forcenewuser));
996: return;
997: }
998:
999: sub single_user_entry_form {
1000: my ($dom,$srch,$forcenewuser) = @_;
1001: my $userpicker =
1002: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1003: 'document.studentform');
1004: my $srchbutton = &mt('Search');
1005: my $output = <<"ENDDOCUMENT";
1006: <input type="hidden" name="action" value="enrollstudent" />
1007: <input type="hidden" name="state" value="gotusername" />
1008: <input type="hidden" name="phase" value="get_user_info" />
1009: $userpicker
1010: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.studentform)" />
1011: ENDDOCUMENT
1012: return $output;
1013: }
1014:
1015: sub print_enroll_single_student_form {
1016: my ($r,$jscript,$ccuname,$ccdomain,$srch) = @_;
1017: $r->print(&header($jscript));
1018: &Apache::lonhtmlcommon::add_breadcrumb
1019: ({href=>"javascript:backPage(document.studentform,'','')",
1020: text=>"Single user search"});
1021: if ($env{'form.phase'} eq 'userpicked') {
1022: &Apache::lonhtmlcommon::add_breadcrumb
1023: ({href=>"javascript:backPage(document.studentform,'get_user_info','select')",
1024: text=>"Select user",});
1025: }
1026: &Apache::lonhtmlcommon::add_breadcrumb
1027: ({href=>"javascript:backPage(document.studentform,'$env{'form.phase'}','modify')",
1028: text=>"Set enrollment",});
1029: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enroll Student',
1030: 'Course_Add_Student'));
1031: $r->print("<h3>".&mt('Enroll One Student')."</h3>");
1032: #
1033: my $home = &Apache::lonnet::homeserver($ccuname,$ccdomain);
1034: # $new_user flags whether we are creating a new user or using an old one
1035: my $new_user = 1;
1036: if ($home ne 'no_host') {
1037: $new_user = 0;
1038: }
1039: #
1040: my $user_data_html = '';
1041: my $javascript_validations = '';
1042: if ($new_user) {
1043: my $usertoadd;
1044: my $instsrch = {
1045: srchin => 'instd',
1046: srchby => 'uname',
1047: srchtype => 'exact',
1048: srchterm => $ccuname,
1049: srchdomain => $ccdomain,
1050: };
1051: if (($instsrch->{'srchterm'} ne '') && ($instsrch->{'srchdomain'} ne '')) {
1052: $usertoadd = $instsrch->{'srchterm'}.':'.$instsrch->{'srchdomain'};
1053: }
1054: my (%dirsrch_results,%inst_results);
1055: if ($usertoadd) {
1056: if (&Apache::loncreateuser::directorysrch_check($instsrch) eq 'ok') {
1057: %dirsrch_results = &Apache::lonnet::inst_directory_query($instsrch);
1058: if (ref($dirsrch_results{$usertoadd}) eq 'HASH') {
1059: %inst_results = %{$dirsrch_results{$usertoadd}};
1060: }
1061: }
1062: }
1063:
1064: my $defdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1065: # Set up authentication forms
1066: my ($krbdef,$krbdefdom) =
1067: &Apache::loncommon::get_kerberos_defaults($ccdomain);
1068: $javascript_validations =
1069: &javascript_validations('auth',$krbdefdom,undef,undef,$ccdomain);
1070: my %param = ( formname => 'document.studentform',
1071: kerb_def_dom => $krbdefdom,
1072: kerb_def_auth => $krbdef
1073: );
1074: my $krbform = &Apache::loncommon::authform_kerberos(%param);
1075: my $intform = &Apache::loncommon::authform_internal(%param);
1076: my $locform = &Apache::loncommon::authform_local(%param);
1077: #
1078: # Set up domain selection form
1079: my $homeserver_form = '';
1080: my %servers = &Apache::lonnet::get_servers($ccdomain,'library');
1081: $homeserver_form = '<select name="lcserver" size="1">'."\n".
1082: '<option value="default" selected>default</option>'."\n";
1083: while (my ($servername,$serverdescription) = each (%servers)) {
1084: $homeserver_form .= '<option value="'.$servername.'">'.
1085: $serverdescription."</option>\n";
1086: }
1087: $homeserver_form .= "</select>\n";
1088: #
1089: #
1090: my %lt=&Apache::lonlocal::texthash(
1091: 'udf' => "Personal Data",
1092: 'fn' => "First Name",
1093: 'mn' => "Middle Name",
1094: 'ln' => "Last Name",
1095: 'gen' => "Generation",
1096: 'hs' => "Home Server",
1097: 'pswd' => "Login Data",
1098: 'psam' => "Please select an authentication mechanism",
1099: 'mail' => "Email Address"
1100: );
1101: my $authhelp=&Apache::loncommon::help_open_topic('Auth_Options');
1102: $user_data_html = <<END;
1103: <h3>$lt{'udf'} $ccuname:$ccdomain</h3>
1104: <table>
1105: <tr><td class="LC_dropadd_labeltext"><label for="cfirst">$lt{'fn'}</label>:</td>
1106: <td><input type="text" name="cfirst" size="15" value="$inst_results{'firstname'}" /></td></tr>
1107: <tr><td class="LC_dropadd_labeltext"><label for="cmiddle">$lt{'mn'}</label>:</td>
1108: <td><input type="text" name="cmiddle" size="15" value="$inst_results{'middlename'}" /></td></tr>
1109: <tr><td class="LC_dropadd_labeltext"><label for="clast">$lt{'ln'}</label>:</td>
1110: <td><input type="text" name="clast" size="15" value="$inst_results{'lastname'}" /></td></tr>
1111: <tr><td class="LC_dropadd_labeltext"><label for="cgen">$lt{'gen'}</label>:</td>
1112: <td><input type="text" name="cgen" size="5" value="$inst_results{'generation'}" /> </td></tr>
1113: <tr><td class="LC_dropadd_labeltext"><label for="lcserver">$lt{'hs'}</label>:</td>
1114: <td>$homeserver_form</td></tr>
1115: <tr><td class="LC_dropadd_labeltext"><label for="emailaddress">$lt{'mail'}</label>:</td>
1116: <td><input type="text" name="emailaddress" size="20" value="$inst_results{'permanentemail'}" /></td></tr>
1117: </table>
1118: <h3>$lt{'pswd'}</h3>
1119: $lt{'psam'}$authhelp
1120: <p>
1121: END
1122: if ($krbform ne '') {
1123: $user_data_html .= $krbform.'<br />';
1124: }
1125: if ($intform ne '') {
1126: $user_data_html .= $intform.'<br />';
1127: }
1128: if ($locform ne '') {
1129: $user_data_html .= $locform.'<br />';
1130: }
1131: $user_data_html .= "\n</p>\n"
1132: } else {
1133: # User already exists. Do not worry about authentication
1134: my %uenv = &Apache::lonnet::dump('environment',$ccdomain,$ccuname);
1135: $javascript_validations = &javascript_validations('noauth');
1136: my %lt=&Apache::lonlocal::texthash(
1137: 'udf' => "User Data for",
1138: 'fn' => "First Name",
1139: 'mn' => "Middle Name",
1140: 'ln' => "Last Name",
1141: 'gen' => "Generation",
1142: 'mail' => "Email Address",
1143: );
1144: $user_data_html = <<END;
1145: <h3>$lt{'udf'} $ccuname:$ccdomain</h3>
1146: <input type="hidden" name="lcserver" value="default" />
1147: <table>
1148: <tr><td class="LC_dropadd_labeltext"><label for="cfirst">$lt{'fn'}</label>:</td>
1149: <td><input type="text" name="cfirst" value="$uenv{'firstname'}" size="15" /></td></tr>
1150: <tr><td class="LC_dropadd_labeltext"><label for="cmiddle">$lt{'mn'}</label>:</td>
1151: <td><input type="text" name="cmiddle" value="$uenv{'middlename'}" size="15" /></td></tr>
1152: <tr><td class="LC_dropadd_labeltext"><label for="clast">$lt{'ln'}</label>:</td>
1153: <td><input type="text" name="clast" value="$uenv{'lastname'}" size="15" /></td></tr>
1154: <tr><td class="LC_dropadd_labeltext"><label for="cgen">$lt{'gen'}</label>:</td>
1155: <td><input type="text" name="cgen" value="$uenv{'generation'}" size="5" /> </td></tr>
1156: <tr><td class="LC_dropadd_labeltext"><label for="emailaddress">$lt{'mail'}</label>:</td>
1157: <td><input type="text" name="emailaddress" value="$uenv{'permanentemail'}" size="20" /></td></tr>
1158: </table>
1159: END
1160: }
1161: my $date_table = &date_setting_table();
1162: # Print it all out
1163: my %lt=&Apache::lonlocal::texthash(
1164: 'cd' => "Course Data",
1165: 'gs' => "Section",
1166: 'idsn' => "ID/Student Number",
1167: 'disn' => "Disable ID/Student Number Safeguard and Force Change of Conflicting IDs (only do if you know what you are doing)",
1168: 'eas' => "Enroll as student",
1169: );
1170: $r->print(<<END);
1171: <input type="hidden" name="action" value="enrollstudent" />
1172: <input type="hidden" name="state" value="gotusername" />
1173: <input type="hidden" name="cuname" value="$ccuname" />
1174: <input type="hidden" name="lcdomain" value="$ccdomain" />
1175: <script type="text/javascript" language="Javascript">
1176: function verify(vf,sec_caller) {
1177: var founduname=0;
1178: var foundpwd=0;
1179: var foundname=0;
1180: var foundid=0;
1181: var foundsec=0;
1182: var tw;
1183: if ((typeof(vf.cuname.value) !="undefined") && (vf.cuname.value!='') &&
1184: (typeof(vf.lcdomain.value)!="undefined") && (vf.lcdomain.value!='')) {
1185: founduname=1;
1186: }
1187: if ((typeof(vf.cfirst.value)!="undefined") && (vf.cfirst.value!='') &&
1188: (typeof(vf.clast.value) !="undefined") && (vf.clast.value!='')) {
1189: foundname=1;
1190: }
1191: if ((typeof(vf.csec.value)!="undefined") && (vf.csec.value!='')) {
1192: foundsec=1;
1193: if (validate(sec_caller) == "error") {
1194: return;
1195: }
1196: }
1197: if ((typeof(vf.cstid.value)!="undefined") && (vf.cstid.value!='')) {
1198: foundid=1;
1199: }
1200: if (founduname==0) {
1201: alert('You need to specify at least the username and domain fields');
1202: return;
1203: }
1204: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
1205: }
1206:
1207: $javascript_validations
1208:
1209: function clearpwd(vf) {
1210: //nothing else needs clearing
1211: }
1212:
1213: </script>
1214:
1215: $user_data_html
1216:
1217: <h3>$lt{'cd'}</h3>
1218:
1219: <p><label for="csec">$lt{'gs'}</label>: <input type="text" name="csec" size="5" />
1220: </p>
1221: $date_table
1222: <h3>$lt{'idsn'}</h3>
1223: <p>
1224: <label for="cstid">$lt{'idsn'}</label>: <input type="text" name="cstid" size="10" />
1225: </p><p>
1226: <label>
1227: <input type="checkbox" name="forceid" value="yes" />
1228: $lt{'disn'}
1229: </label>
1230: </p><p>
1231: <input type="button" onClick="verify(this.form,this.form.csec)" value="$lt{'eas'}" />
1232: </p>
1233: END
1234: $r->print('<input type="hidden" name="currstate" value="" />'."\n".
1235: '<input type="hidden" name="phase" value="" />'."\n".
1236: '<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />'."\n");
1237: if (ref($srch) eq 'HASH') {
1238: foreach my $item (sort(keys(%{$srch}))) {
1239: $r->print('<input type="hidden" name="'.$item.'" value="'.$srch->{$item}.'" />'."\n");
1240: }
1241: }
1242: foreach my $item ('sortby','seluname','seludom') {
1243: if (exists($env{'form.'.$item})) {
1244: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1245: }
1246: }
1247: return;
1248: }
1249:
1250: # ========================================================= Menu Phase Two Drop
1251: sub print_drop_menu {
1252: my $r=shift;
1253: $r->print("<h3>".&mt('Drop Students')."</h3>");
1254: my $cid=$env{'request.course.id'};
1255: my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
1256: if (! defined($classlist)) {
1257: $r->print(&mt('There are no students currently enrolled.')."\n");
1258: return;
1259: }
1260: # Print out the available choices
1261: &show_drop_list($r,$classlist,$keylist);
1262: return;
1263: }
1264:
1265: # ============================================== view classlist
1266: sub print_html_classlist {
1267: my ($r,$mode,$permission) = @_;
1268: if (! exists($env{'form.sortby'})) {
1269: $env{'form.sortby'} = 'username';
1270: }
1271: if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
1272: $env{'form.Status'} = 'Active';
1273: }
1274: my $status_select = &Apache::lonhtmlcommon::StatusOptions
1275: ($env{'form.Status'});
1276: my $cid =$env{'request.course.id'};
1277: my $cdom=$env{'course.'.$cid.'.domain'};
1278: my $cnum=$env{'course.'.$cid.'.num'};
1279: #
1280: # List course personnel
1281: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1282: #
1283: if (! defined($env{'form.output'}) ||
1284: $env{'form.output'} !~ /^(csv|excel|html)$/ ) {
1285: $env{'form.output'} = 'html';
1286: }
1287: #
1288: $r->print('<br />'.&Apache::loncommon::start_data_table());
1289: foreach my $role (sort keys %coursepersonnel) {
1290: next if ($role =~ /^\s*$/);
1291: $r->print(&Apache::loncommon::start_data_table_row().
1292: '<td>'.$role.'</td><td>');
1293: foreach my $user (split(',',$coursepersonnel{$role})) {
1294: my ($puname,$pudom)=split(':',$user);
1295: $r->print(' '.&Apache::loncommon::aboutmewrapper(
1296: &Apache::loncommon::plainname($puname,
1297: $pudom),
1298: $puname,$pudom));
1299: }
1300: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1301: }
1302: $r->print(&Apache::loncommon::end_data_table());
1303: #
1304: # Interface output
1305: $r->print('<input type="hidden" name="action" value="'.
1306: $env{'form.action'}.'" />');
1307: $r->print("<p>\n");
1308: if ($env{'form.action'} ne 'modifystudent') {
1309: my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
1310: 'excel' => "Excel",
1311: 'html' => 'HTML');
1312: my $output_selector = '<select size="1" name="output" >';
1313: foreach my $outputformat ('html','csv','excel') {
1314: my $option = '<option value="'.$outputformat.'" ';
1315: if ($outputformat eq $env{'form.output'}) {
1316: $option .= 'selected ';
1317: }
1318: $option .='>'.$lt{$outputformat}.'</option>';
1319: $output_selector .= "\n".$option;
1320: }
1321: $output_selector .= '</select>';
1322: $r->print('<label>'.&mt('Output Format: [_1]',$output_selector).'</label>'.(' 'x3));
1323: }
1324: $r->print('<label>'.&mt('Student Status: [_1]',$status_select)."</label>\n");
1325: $r->print('<input type="submit" value="'.&mt('Update Display').'" />'.
1326: "\n</p>\n");
1327: #
1328: # Print the classlist
1329: $r->print('<h2>'.&mt('Current Class List').'</h2>');
1330: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
1331:
1332: if (exists($permission->{'view_section'})) {
1333: my $sec = &Apache::loncoursedata::CL_SECTION();
1334: foreach my $student (keys(%{$classlist})) {
1335: if ($classlist->{$student}[$sec] ne $permission->{'view_section'}) {
1336: delete($classlist->{$student});
1337: }
1338: }
1339: }
1340:
1341: if (! defined($classlist)) {
1342: $r->print(&mt('There are no students currently enrolled.')."\n");
1343: } else {
1344: # Print out the available choices
1345: if ($env{'form.action'} eq 'modifystudent') {
1346: &show_class_list($r,'view','modify',
1347: $env{'form.Status'},$classlist,$keylist);
1348: } else {
1349: &show_class_list($r,$env{'form.output'},'aboutme',
1350: $env{'form.Status'},$classlist,$keylist);
1351: }
1352: }
1353: }
1354:
1355: # =================================================== Show student list to drop
1356: sub show_class_list {
1357: my ($r,$mode,$linkto,$statusmode,$classlist,$keylist)=@_;
1358: my $cid=$env{'request.course.id'};
1359: my $cdom = $env{'course.'.$cid.'.domain'};
1360: my $cnum = $env{'course.'.$cid.'.num'};
1361: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
1362: $classlist,$keylist,$cdom,$cnum);
1363: #
1364: # Variables for excel output
1365: my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
1366: #
1367: # Variables for csv output
1368: my ($CSVfile,$CSVfilename);
1369: #
1370: my $sortby = $env{'form.sortby'};
1371: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end|type)$/) {
1372: $sortby = 'username';
1373: }
1374: if (! exists($env{'form.displayphotos'})) {
1375: $env{'form.displayphotos'} = 'off';
1376: }
1377: my $displayphotos = $env{'form.displayphotos'};
1378:
1379: if (! exists($env{'form.displayclickers'})) {
1380: $env{'form.displayclickers'} = 'off';
1381: }
1382: my $displayclickers = $env{'form.displayclickers'};
1383:
1384: # Print out header
1385: unless ($mode eq 'autoenroll') {
1386: $r->print(<<END);
1387: <input type="hidden" name="state" value="$env{'form.state'}" />
1388: END
1389: }
1390: $r->print(<<END);
1391: <input type="hidden" name="sortby" value="$sortby" />
1392: <input type="hidden" name="displayphotos" value="$displayphotos" />
1393: <input type="hidden" name="displayclickers" value="$displayclickers" />
1394: END
1395: if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll') {
1396: if ($linkto eq 'aboutme') {
1397: $r->print(&mt("Select a user name to view the user's personal page."));
1398: } elsif ($linkto eq 'modify') {
1399: $r->print(&mt("Select a user name to modify the student's information"));
1400: }
1401: my %lt=&Apache::lonlocal::texthash(
1402: 'usrn' => "username",
1403: 'dom' => "domain",
1404: 'sn' => "student name",
1405: 'sec' => "section",
1406: 'grp' => "active groups",
1407: 'start' => "start date",
1408: 'end' => "end date",
1409: 'type' => "enroll type/action",
1410: 'email' => "email address",
1411: 'clicker'=> "clicker id",
1412: 'photo' => "photo",
1413: );
1414: unless ($mode eq 'autoenroll') {
1415: $r->print(<<END);
1416: <input type="hidden" name="sname" value="" />
1417: <input type="hidden" name="sdom" value="" />
1418: END
1419: }
1420: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
1421: $r->print('
1422: <script type="text/javascript">
1423: function photowindow(photolink) {
1424: var title = "Photo_Viewer";
1425: var options = "scrollbars=1,resizable=1,menubar=0";
1426: options += ",width=240,height=240";
1427: stdeditbrowser = open(photolink,title,options,"1");
1428: stdeditbrowser.focus();
1429: }
1430: </script>
1431: ');
1432: }
1433: $r->print("
1434: <p>
1435: ".&Apache::loncommon::start_data_table()."
1436: <tr>
1437: ");
1438: if ($mode eq 'autoenroll') {
1439: $r->print("
1440: <th><a href=\"javascript:document.studentform.sortby.value='type';document.studentform.submit();\">$lt{'type'}</a></th>
1441: ");
1442: } else {
1443: $r->print("
1444: <th>Count</th>
1445: ");
1446: }
1447: $r->print(<<END);
1448: <th>
1449: <a href="javascript:document.studentform.sortby.value='username';document.studentform.submit();">$lt{'usrn'}</a>
1450: </th><th>
1451: <a href="javascript:document.studentform.sortby.value='domain';document.studentform.submit();">$lt{'dom'}</a>
1452: </th><th>
1453: <a href="javascript:document.studentform.sortby.value='id';document.studentform.submit();">ID</a>
1454: </th><th>
1455: <a href="javascript:document.studentform.sortby.value='fullname';document.studentform.submit();">$lt{'sn'}</a>
1456: </th><th>
1457: <a href="javascript:document.studentform.sortby.value='section';document.studentform.submit();">$lt{'sec'}</a>
1458: </th><th>
1459: <a href="javascript:document.studentform.sortby.value='start';document.studentform.submit();">$lt{'start'}</a>
1460: </th><th>
1461: <a href="javascript:document.studentform.sortby.value='end';document.studentform.submit();">$lt{'end'}</a>
1462: </th><th>
1463: <a href="javascript:document.studentform.sortby.value='groups';document.studentform.submit();">$lt{'grp'}</a>
1464: </th><th>
1465: <a href="javascript:document.studentform.sortby.value='email';document.studentform.submit();">$lt{'email'}</a>
1466: </th>
1467: END
1468:
1469: # Clicker display on or off?
1470:
1471: my %clicker_options = &Apache::lonlocal::texthash(
1472: 'on' => 'Show',
1473: 'off' => 'Hide',
1474: );
1475: my $clickerchg = 'on';
1476: if ($displayclickers eq 'on') {
1477: $clickerchg = 'off';
1478: }
1479: $r->print(' <th>'."\n".' '.
1480: '<a href="javascript:document.studentform.displayclickers.value='.
1481: "'".$clickerchg."'".';document.studentform.submit();">'.
1482: $clicker_options{$clickerchg}.'</a> '.$lt{'clicker'}."\n".
1483: ' </th>'."\n");
1484:
1485: # Photo display on or off?
1486: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
1487: my %photo_options = &Apache::lonlocal::texthash(
1488: 'on' => 'Show',
1489: 'off' => 'Hide',
1490: );
1491: my $photochg = 'on';
1492: if ($displayphotos eq 'on') {
1493: $photochg = 'off';
1494: }
1495: $r->print(' <th>'."\n".' '.
1496: '<a href="javascript:document.studentform.displayphotos.value='.
1497: "'".$photochg."'".';document.studentform.submit();">'.
1498: $photo_options{$photochg}.'</a> '.$lt{'photo'}."\n".
1499: ' </th>'."\n");
1500: }
1501: $r->print(" </tr>\n");
1502:
1503: # Done with the HTML header line
1504:
1505: } elsif ($mode eq 'csv') {
1506: #
1507: # Open a file
1508: $CSVfilename = '/prtspool/'.
1509: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1510: time.'_'.rand(1000000000).'.csv';
1511: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
1512: $r->log_error("Couldn't open $CSVfilename for output $!");
1513: $r->print("Problems occured in writing the csv file. ".
1514: "This error has been logged. ".
1515: "Please alert your LON-CAPA administrator.");
1516: $CSVfile = undef;
1517: }
1518: #
1519: # Write headers and data to file
1520: if($statusmode eq 'Expired') {
1521: print $CSVfile '"'.&mt('Students with expired roles').'"'."\n";
1522: }
1523: if($statusmode eq 'Future') {
1524: print $CSVfile '"'.&mt('Students with future roles').'"'."\n";
1525: }
1526: if ($statusmode eq 'Any') {
1527: print $CSVfile '"'.join('","',map {
1528: &Apache::loncommon::csv_translate(&mt($_))
1529: } ("username","domain","ID","student name",
1530: "section","start date","end date","status",
1531: "active groups","email address"))
1532: .'"'."\n";
1533: } else {
1534: print $CSVfile '"'.join('","',map {
1535: &Apache::loncommon::csv_translate(&mt($_))
1536: } ("username","domain","ID","student name",
1537: "section","start date","end date",
1538: "active groups","email address")).'"'."\n";
1539: }
1540: } elsif ($mode eq 'excel') {
1541: # Create the excel spreadsheet
1542: ($excel_workbook,$excel_filename,$format) =
1543: &Apache::loncommon::create_workbook($r);
1544: return if (! defined($excel_workbook));
1545: $excel_sheet = $excel_workbook->addworksheet('classlist');
1546: #
1547: my $description = 'Class List for '.
1548: $env{'course.'.$env{'request.course.id'}.'.description'};
1549: $excel_sheet->write($row++,0,$description,$format->{'h1'});
1550: #
1551: $excel_sheet->write($row++,0,["username","domain","ID",
1552: "student name","section",
1553: "start date","end date","status",
1554: "active groups","email address"],
1555: $format->{'bold'});
1556: }
1557:
1558: # Done with header lines in all formats
1559:
1560: #
1561: # Sort the students
1562: my %index;
1563: my $i;
1564: foreach (@$keylist) {
1565: $index{$_} = $i++;
1566: }
1567: $index{'groups'} = scalar(@{$keylist});
1568: my $index = $index{$sortby};
1569: my $second = $index{'username'};
1570: my $third = $index{'domain'};
1571: my @Sorted_Students = sort {
1572: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
1573: ||
1574: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
1575: ||
1576: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
1577: } (keys(%$classlist));
1578: my $studentcount = 0;
1579: my $autocount = 0;
1580: my $manualcount = 0;
1581: my $unlockcount = 0;
1582: my $lockcount = 0;
1583: foreach my $student (@Sorted_Students) {
1584: my $sdata = $classlist->{$student};
1585: my $groups = $classgroups->{$student};
1586: my $username = $sdata->[$index{'username'}];
1587: my $domain = $sdata->[$index{'domain'}];
1588: my $section = $sdata->[$index{'section'}];
1589: my $active_groups;
1590: if (ref($groups->{active}) eq 'HASH') {
1591: $active_groups = join(', ',keys(%{$groups->{'active'}}));
1592: }
1593: my $name = $sdata->[$index{'fullname'}];
1594: my $id = $sdata->[$index{'id'}];
1595: my $status = $sdata->[$index{'status'}];
1596: next if (($statusmode ne 'Any') && ($status ne $statusmode));
1597: my $start = $sdata->[$index{'start'}];
1598: my $end = $sdata->[$index{'end'}];
1599: my $type = $sdata->[$index{'type'}];
1600:
1601: my %emails = &Apache::loncommon::getemails($username,$domain);
1602: my $email;
1603: if ($emails{'permanentemail'} =~ /\S/) {
1604: $email = $emails{'permanentemail'};
1605: }
1606:
1607: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
1608: if (! defined($start) || $start == 0) {
1609: $start = &mt('none');
1610: } else {
1611: $start = &Apache::lonlocal::locallocaltime($start);
1612: }
1613: if (! defined($end) || $end == 0) {
1614: $end = &mt('none');
1615: } else {
1616: $end = &Apache::lonlocal::locallocaltime($end);
1617: }
1618: $r->print(&Apache::loncommon::start_data_table_row());
1619: if ($mode eq 'autoenroll') {
1620: my $lockedtype = $sdata->[$index{'lockedtype'}];
1621: $studentcount++;
1622: my $cellentry;
1623: if ($type eq 'auto') {
1624: $cellentry = '<b>'.&mt('auto').'</b> <label><input type="checkbox" name="chgauto" value="'.$username.':'.$domain.'" /> Change</label>';
1625: $autocount ++;
1626: } else {
1627: $cellentry = '<table border="0" cellspacing="0"><tr><td rowspan="2"><b>'.&mt('manual').'</b></td><td><nobr><label><input type="checkbox" name="chgmanual" value="'.$username.':'.$domain.'" /> Change</label></nobr></td></tr><tr><td><nobr>';
1628: $manualcount ++;
1629: if ($lockedtype) {
1630: $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$username.':'.$domain.'" /> '.&mt('Unlock').'</label>';
1631: $unlockcount ++;
1632: } else {
1633: $cellentry .= '<label><input type="checkbox" name="lockchg" value="'.$username.':'.$domain.'" /> '.&mt('Lock').'</label>';
1634: $lockcount ++;
1635: }
1636: $cellentry .= '</nobr></td></tr></table>';
1637: }
1638: $r->print("<td>$cellentry<td>\n ");
1639: } else {
1640: $r->print("<td>".(++$studentcount)."</td><td>\n ");
1641: }
1642: if ($linkto eq 'nothing') {
1643: $r->print($username);
1644: } elsif ($linkto eq 'aboutme') {
1645: $r->print(&Apache::loncommon::aboutmewrapper($username,
1646: $username,
1647: $domain));
1648: } elsif ($linkto eq 'modify') {
1649: $r->print('<a href="'.
1650: "javascript:document.studentform.sname.value='".
1651: $username.
1652: "';document.studentform.sdom.value='".$domain.
1653: "';document.studentform.state.value='selected".
1654: "';document.studentform.submit();".'">'.
1655: $username."</a>\n");
1656: }
1657: $r->print(<<"END");
1658: </td>
1659: <td>$domain</td>
1660: <td>$id</td>
1661: <td>$name</td>
1662: <td>$section</td>
1663: <td>$start</td>
1664: <td>$end</td>
1665: <td>$active_groups</td>
1666: <td>$email</td>
1667: END
1668:
1669: # Clickers
1670: if ($displayclickers eq 'on') {
1671: my $clickers =
1672: (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
1673: if ($clickers!~/\w/) { $clickers='-'; }
1674: $r->print('<td>'.$clickers.'</td>');
1675: } else {
1676: $r->print(' <td> </td> ');
1677: }
1678:
1679: # Photos
1680:
1681: if ($env{'course.'.$env{'request.course.id'}.
1682: '.internal.showphoto'}) {
1683: if ($displayphotos eq 'on') {
1684: my $imgurl =
1685: &Apache::lonnet::retrievestudentphoto($domain,
1686: $username,'gif',
1687: 'thumbnail');
1688:
1689: $r->print(' <td align="right"><a href="javascript:photowindow('."'".&Apache::lonnet::studentphoto($domain,$username,'jpg')."'".')"><img src="'.$imgurl.'" border="1"></a></td>');
1690: } else {
1691: $r->print(' <td> </td> ');
1692: }
1693: }
1694: $r->print(&Apache::loncommon::end_data_table_row());
1695: } elsif ($mode eq 'csv') {
1696: next if (! defined($CSVfile));
1697: # no need to bother with $linkto
1698: if (! defined($start) || $start == 0) {
1699: $start = &mt('none');
1700: } else {
1701: $start = &Apache::lonlocal::locallocaltime($start);
1702: }
1703: if (! defined($end) || $end == 0) {
1704: $end = &mt('none');
1705: } else {
1706: $end = &Apache::lonlocal::locallocaltime($end);
1707: }
1708: my @line = ();
1709: foreach ($username,$domain,$id,$name,$section,$start,$end) {
1710: push @line,&Apache::loncommon::csv_translate($_);
1711: }
1712: if ($statusmode eq 'Any') {
1713: push @line,&Apache::loncommon::csv_translate($status);
1714: }
1715: push @line,&Apache::loncommon::csv_translate($active_groups);
1716: push @line,&Apache::loncommon::csv_translate($email);
1717: print $CSVfile '"'.join('","',@line).'"'."\n";
1718: } elsif ($mode eq 'excel') {
1719: $excel_sheet->write($row,0,[$username,$domain,$id,
1720: $name,$section]);
1721: my $col = 5;
1722: foreach my $time ($start,$end) {
1723: if (defined($time) && $time != 0) {
1724: $excel_sheet->write($row,$col++,
1725: &Apache::lonstathelpers::calc_serial($time),
1726: $format->{'date'});
1727: } else {
1728: $excel_sheet->write($row,$col++,'none');
1729: }
1730: }
1731: $excel_sheet->write($row,$col++,$status);
1732: $excel_sheet->write($row,$col++,$active_groups);
1733: $excel_sheet->write($row,$col++,$email);
1734: $row++;
1735: }
1736: }
1737: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
1738: $r->print(&Apache::loncommon::end_data_table().'<br />');
1739: } elsif ($mode eq 'excel') {
1740: $excel_workbook->close();
1741: $r->print('<p><a href="'.$excel_filename.'">'.
1742: &mt('Your Excel spreadsheet').'</a> '.&mt('is ready for download').'.</p>'."\n");
1743: } elsif ($mode eq 'csv') {
1744: close($CSVfile);
1745: $r->print('<a href="'.$CSVfilename.'">'.
1746: &mt('Your CSV file').'</a> is ready for download.'.
1747: "\n");
1748: $r->rflush();
1749: }
1750: if ($mode eq 'autoenroll') {
1751: return ($studentcount,$autocount,$manualcount,$lockcount,$unlockcount);
1752: }
1753: return;
1754: }
1755:
1756:
1757: #
1758: # print out form for modification of a single students data
1759: #
1760: sub print_modify_student_form {
1761: my $r = shift();
1762: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1763: ['sdom','sname']);
1764: my $sname = $env{'form.sname'};
1765: my $sdom = $env{'form.sdom'};
1766: my $sortby = $env{'form.sortby'};
1767: # determine the students name information
1768: my %info=&Apache::lonnet::get('environment',
1769: ['firstname','middlename',
1770: 'lastname','generation','id',
1771: 'permanentemail'], $sdom, $sname);
1772: my ($tmp) = keys(%info);
1773: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1774: $r->print('<font color="#ff0000" size="+2">'.&mt('Error').'</font>'.
1775: '<p>'.
1776: &mt('Unable to retrieve environment data for').' '.$sname.
1777: &mt('in domain').' '.$sdom.'</p><p>'.
1778: &mt('Please contact your LON-CAPA administrator regarding this situation.').'</p>'.&Apache::loncommon::end_page());
1779: return;
1780: }
1781: # determine the students starting and ending times and section
1782: my ($starttime,$endtime,$section) = &get_enrollment_data($sname,$sdom);
1783: if ($starttime =~ /^error/) {
1784: $r->print('<h2>'&mt('Error').'</h2>');
1785: $r->print('<p>'.$starttime.'</p>');
1786: return;
1787: }
1788: #
1789: # Deal with date forms
1790: my $current_date_description = '';
1791: my $textdate = '';
1792:
1793: if (! defined($starttime) || $starttime == 0) {
1794: $current_date_description = &mt('Current Starting Date: not set').
1795: '<br />';
1796: } else {
1797: $current_date_description =
1798: &mt('Current Starting Date: [_1]',
1799: &Apache::lonlocal::locallocaltime($starttime)).'<br />';
1800: }
1801: if (! defined($endtime) || $endtime == 0) {
1802: $current_date_description.= &mt('Current Ending Date: not set').
1803: '<br />';
1804: } else {
1805: $current_date_description.=
1806: &mt('Current Ending Date: [_1]',
1807: &Apache::lonlocal::locallocaltime($endtime)).'<br />';
1808:
1809: }
1810: my $date_table = &date_setting_table($starttime,$endtime);
1811: #
1812: if (! exists($env{'form.Status'}) ||
1813: $env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
1814: $env{'form.Status'} = 'crap';
1815: }
1816: # Make sure student is enrolled in course
1817: my %lt=&Apache::lonlocal::texthash(
1818: 'mef' => "Modify Enrollment for",
1819: 'odcc' => "Only domain coordinators can change a users password.",
1820: 'sn' => "Student Name",
1821: 'fn' => "First",
1822: 'mn' => "Middle",
1823: 'ln' => "Last",
1824: 'gen' => "Generation",
1825: 'email' => "E-mail address",
1826: 'sid' => "Student ID",
1827: 'disn' => "Disable ID/Student Number Safeguard and Force Change of Conflicting IDs (only do if you know what you are doing)",
1828: 'sec' => "Section",
1829: 'sm' => "Submit Modifications",
1830: );
1831: # Check if section name is valid
1832: my $section_check = §ion_check_js();
1833: $r->print(<<"END");
1834: <script type="text/javascript">
1835: $section_check
1836: function secverify(formname,caller) {
1837: if (validate(caller) == "error") {
1838: return;
1839: } else {
1840: formname.submit();
1841: }
1842: }
1843: </script>
1844: <p>
1845: <font size="+1">
1846: $lt{'odcc'}
1847: </font>
1848: </p>
1849: <input type="hidden" name="slogin" value="$sname" />
1850: <input type="hidden" name="sdomain" value="$sdom" />
1851: <input type="hidden" name="action" value="modifystudent" />
1852: <input type="hidden" name="state" value="done" />
1853: <input type="hidden" name="sortby" value="$sortby" />
1854: <input type="hidden" name="Status" value="$env{'form.Status'}" />
1855: <h3>$lt{'mef'} $info{'firstname'} $info{'middlename'}
1856: $info{'lastname'} $info{'generation'}, $sname:$sdom</h3>
1857: <p>
1858: <b>$lt{'sn'}</b>
1859: <table>
1860: <tr><th>$lt{'fn'}</th><th>$lt{'mn'}</th><th>$lt{'ln'}</th><th>$lt{'gen'}</th></tr>
1861: <tr><td>
1862: <input type="text" name="firstname" value="$info{'firstname'}" /></td><td>
1863: <input type="text" name="middlename" value="$info{'middlename'}" /></td><td>
1864: <input type="text" name="lastname" value="$info{'lastname'}" /></td><td>
1865: <input type="text" name="generation" value="$info{'generation'}" /></td></tr>
1866: </table>
1867: </p><p>
1868: <b>$lt{'email'}</b>: <input type="text" name="permanentemail" value="$info{'permanentemail'}" size="30" />
1869: </p><p>
1870: <b>$lt{'sid'}</b>: <input type="text" name="id" value="$info{'id'}" size="12" />
1871: </p><p>
1872: <label>
1873: <input type="checkbox" name="forceid" />
1874: $lt{'disn'}
1875: </label>
1876: </p><p>
1877: <b>$lt{'sec'}</b>: <input type="text" name="section" value="$section" size="14" />
1878: </p>
1879: <p>$current_date_description</p>
1880: <p>$date_table</p>
1881: <input type="button" value="$lt{'sm'}" onClick="secverify(this.form,this.form.section)" />
1882: END
1883: $r->print(&Apache::loncommon::end_page());
1884: return;
1885: }
1886:
1887: #
1888: # modify a single students section
1889: #
1890: sub modify_single_student {
1891: my ($r) = @_;
1892: #
1893: # Remove non alphanumeric values from the section
1894: $env{'form.section'} =~ s/\W//g;
1895: #
1896: # Do the date defaults first
1897: my ($starttime,$endtime) = &get_dates_from_form();
1898: if ($env{'form.makedatesdefault'}) {
1899: $r->print(&make_dates_default($starttime,$endtime));
1900: }
1901: # Get the 'sortby' and 'Status' variables so the user goes back to their
1902: # previous screen
1903: my $sortby = $env{'form.sortby'};
1904: my $status = $env{'form.Status'};
1905: #
1906: # We always need this information
1907: my $slogin = $env{'form.slogin'};
1908: my $sdom = $env{'form.sdomain'};
1909: #
1910: # Get the old data
1911: my %old=&Apache::lonnet::get('environment',
1912: ['firstname','middlename',
1913: 'lastname','generation','id',
1914: 'permanentemail'],$sdom, $slogin);
1915: $old{'section'} = &Apache::lonnet::getsection($sdom,$slogin,
1916: $env{'request.course.id'});
1917: my ($tmp) = keys(%old);
1918: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1919: $r->print(&mt('There was an error determining the environment values for')." $slogin : $sdom.");
1920: return;
1921: }
1922: undef $tmp;
1923: #
1924: # Get the new data
1925: my $firstname = $env{'form.firstname'};
1926: my $middlename = $env{'form.middlename'};
1927: my $lastname = $env{'form.lastname'};
1928: my $generation = $env{'form.generation'};
1929: my $permanentemail = $env{'form.permanentemail'};
1930: my $section = $env{'form.section'};
1931: my $courseid = $env{'request.course.id'};
1932: my $sid = $env{'form.id'};
1933: my $displayable_starttime = localtime($starttime);
1934: my $displayable_endtime = localtime($endtime);
1935: #
1936: # check for forceid override
1937: if ((defined($old{'id'})) && ($old{'id'} ne '') &&
1938: ($sid ne $old{'id'}) && (! exists($env{'form.forceid'}))) {
1939: $r->print("<font color=\"ff0000\">".&mt('You changed the students id but did not disable the ID change safeguard. The students id will not be changed.')."</font>");
1940: $sid = $old{'id'};
1941: }
1942: #
1943: # talk to the user about what we are going to do
1944: my %lt=&Apache::lonlocal::texthash(
1945: 'mdu' => "Modifying data for user",
1946: 'si' => "Student Information",
1947: 'fd' => "Field",
1948: 'ov' => "Old Value",
1949: 'nv' => "New Value",
1950: 'fn' => "First name",
1951: 'mn' => "Middle name",
1952: 'ln' => "Last name",
1953: 'gen' => "Generation",
1954: 'em' => "E-mail address",
1955: 'sec' => "Section",
1956: 'ri' => "Role Information",
1957: 'st' => "Start Time",
1958: 'et' => "End Time",
1959: );
1960: $r->print(<<END);
1961: <h3>$lt{'mdu'} $slogin:$sdom </h3>
1962: END
1963: $r->print(<<END);
1964: <table>
1965: <tr>
1966: <td>
1967: <table class="LC_nested_outer">
1968: <tr>
1969: <th>$lt{si}</th>
1970: </tr>
1971: <tr>
1972: <td>
1973: <table class="LC_nested">
1974: <tr class="LC_info_row">
1975: <td class="LC_left_item"> $lt{'fd'} </td>
1976: <td class="LC_left_item"> $lt{'ov'} </td>
1977: <td class="LC_left_item"> $lt{'nv'} </td>
1978: </tr>
1979: <tr class="LC_odd_row">
1980: <td class="LC_left_item"> <b>$lt{'fn'}</b> </td>
1981: <td class="LC_left_item"> $old{'firstname'} </td>
1982: <td class="LC_left_item"> $firstname </td>
1983: </tr>
1984: <tr>
1985: <td class="LC_left_item"> <b>$lt{'mn'}</b> </td>
1986: <td class="LC_left_item"> $old{'middlename'} </td>
1987: <td class="LC_left_item"> $middlename </td>
1988: </tr>
1989: <tr class="LC_odd_row">
1990: <td class="LC_left_item"> <b>$lt{'ln'}</b> </td>
1991: <td class="LC_left_item"> $old{'lastname'} </td>
1992: <td class="LC_left_item"> $lastname </td>
1993: </tr>
1994: <tr>
1995: <td class="LC_left_item"> <b>$lt{'gen'}</b> </td>
1996: <td class="LC_left_item"> $old{'generation'} </td>
1997: <td class="LC_left_item"> $generation </td>
1998: </tr>
1999: <tr class="LC_odd_row">
2000: <td class="LC_left_item"> <b>ID</b> </td>
2001: <td class="LC_left_item"> $old{'id'} </td>
2002: <td class="LC_left_item"> $sid </td>
2003: </tr>
2004: <tr>
2005: <td class="LC_left_item"> <b>$lt{'em'}</b> </td>
2006: <td class="LC_left_item"> $old{'permanentemail'} </td>
2007: <td class="LC_left_item"> $permanentemail </td>
2008: <tr class="LC_odd_row">
2009: <td> <b>$lt{'sec'}</b> </td>
2010: <td> $old{'section'} </td>
2011: <td> $section</td>
2012: </tr>
2013: </table>
2014: </td>
2015: </tr>
2016: </table>
2017: <br />
2018: <table class="LC_nested_outer">
2019: <tr>
2020: <th>$lt{'ri'}</th>
2021: </tr>
2022: <tr>
2023: <td>
2024: <table class="LC_nested">
2025: <tr class="LC_odd_row">
2026: <td class="LC_left_item"><b>$lt{'st'}:</b></td>
2027: <td class="LC_right_item"> $displayable_starttime </td>
2028: </tr>
2029: <tr>
2030: <td class="LC_left_item"><b>$lt{'et'}:</b></td>
2031: <td class="LC_right_item"> $displayable_endtime </td>
2032: </tr>
2033: </table>
2034: </td>
2035: </tr>
2036: </table>
2037: </td>
2038: </tr>
2039: </table>
2040: <p>
2041: END
2042: #
2043: # Send request(s) to modify data (final undef is for 'desiredhost',
2044: # which is a moot point because the student already has an account.
2045: my $modify_section_results = &modifystudent($sdom,$slogin,
2046: $env{'request.course.id'},
2047: $section,undef);
2048: if ($modify_section_results !~ /^ok/) {
2049: $r->print(&mt('An error occured during the attempt to change the section for this student.')."<br />");
2050: }
2051: my $roleresults = &Apache::lonnet::modifystudent
2052: ($sdom,$slogin,$sid,undef,undef,$firstname,$middlename,$lastname,
2053: $generation,$section,$endtime,$starttime,$env{'form.forceid'},
2054: undef,$permanentemail);
2055: if ($old{'permanentemail'} ne $permanentemail) {
2056: &Apache::loncommon::flush_email_cache($slogin,$sdom);
2057: }
2058: if ($roleresults eq 'refused' ) {
2059: $r->print(&mt('Your request to change the role information for this student was refused. You do not appear to have sufficient authority to change student information.'));
2060: } elsif ($roleresults !~ /ok/) {
2061: $r->print(&mt('An error occurred during the attempt to change the role information for this student.')." <br />".
2062: &mt('The error reported was')." ".
2063: $roleresults);
2064: &Apache::lonnet::logthis("londropadd:failed attempt to modify student".
2065: " data for ".$slogin." : ".$sdom." by ".
2066: $env{'user.name'}." : ".$env{'user.domain'}.
2067: ":".$roleresults);
2068: } else { # everything is okay!
2069: $r->print(&mt('Student information updated successfully.')." <br />".
2070: &mt('The student must log out and log in again to see these changes.'));
2071: }
2072: my $Masd=&mt('Modify another students data');
2073: $r->print(<<END);
2074: </p><p>
2075: <input type="hidden" name="action" value="modifystudent" />
2076: <input type="hidden" name="sortby" value="$sortby" />
2077: <input type="hidden" name="Status" value="$status" />
2078: <a href="javascript:document.studentform.submit();">$Masd</a>
2079: END
2080: $r->print(&Apache::loncommon::end_page());
2081: return;
2082: }
2083:
2084: sub get_enrollment_data {
2085: my ($sname,$sdomain) = @_;
2086: my $courseid = $env{'request.course.id'};
2087: my $cdom = $env{'course.'.$courseid.'.domain'};
2088: my $cnum = $env{'course.'.$courseid.'.num'};
2089: my %roles = &Apache::lonnet::dump('roles',$sdomain,$sname);
2090: my ($tmp) = keys(%roles);
2091: # Bail out if we were unable to get the students roles
2092: return ('error'.$tmp) if ($tmp =~ /^(con_lost|error|no_such_host)/i);
2093: # Go through the roles looking for enrollment in this course
2094: my ($end,$start) = (undef,undef);
2095: my $section = '';
2096: my $count = scalar(keys(%roles));
2097: while (my ($course,$role) = each(%roles)) {
2098: if ($course=~m{^/\Q$cdom\E/\Q$cnum\E/*\s*(\w+)*_st$} ) {
2099: #
2100: # Get active role
2101: $section=$1;
2102: (undef,$end,$start)=split(/\_/,$role);
2103: my $now=time;
2104: my $notactive=0;
2105: if ($start) {
2106: if ($now<$start) { $notactive=1; }
2107: }
2108: if ($end) {
2109: if ($now>$end) { $notactive=1; }
2110: }
2111: unless ($notactive) { return ($start,$end,$section); }
2112: }
2113: }
2114: return ($start,$end,$section);
2115: }
2116:
2117: #################################################
2118: #################################################
2119:
2120: =pod
2121:
2122: =item show_drop_list
2123:
2124: Display a list of students to drop
2125: Inputs:
2126:
2127: =over 4
2128:
2129: =item $r, Apache request
2130:
2131: =item $classlist, hash pointer returned from loncoursedata::get_classlist();
2132:
2133: =item $keylist, array pointer returned from loncoursedata::get_classlist()
2134: which describes the order elements are stored in the %$classlist values.
2135:
2136: =item $nosort, if true, sorting links are omitted.
2137:
2138: =back
2139:
2140: =cut
2141:
2142: #################################################
2143: #################################################
2144: sub show_drop_list {
2145: my ($r,$classlist,$keylist,$nosort)=@_;
2146: my $cid=$env{'request.course.id'};
2147: if (! exists($env{'form.sortby'})) {
2148: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2149: ['sortby']);
2150: }
2151: my $sortby = $env{'form.sortby'};
2152: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
2153: $sortby = 'username';
2154: }
2155: my $cdom = $env{'course.'.$cid.'.domain'};
2156: my $cnum = $env{'course.'.$cid,'.num'};
2157: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
2158: $classlist,$keylist,$cdom,$cnum);
2159: #
2160: my $action = "drop";
2161: $r->print(<<END);
2162: <input type="hidden" name="sortby" value="$sortby" />
2163: <input type="hidden" name="action" value="$action" />
2164: <input type="hidden" name="state" value="done" />
2165: <script>
2166: function checkAll(field) {
2167: for (i = 0; i < field.length; i++)
2168: field[i].checked = true ;
2169: }
2170:
2171: function uncheckAll(field) {
2172: for (i = 0; i < field.length; i++)
2173: field[i].checked = false ;
2174: }
2175: </script>
2176: <p>
2177: <input type="hidden" name="phase" value="four">
2178: END
2179:
2180: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
2181: 'dom' => "domain",
2182: 'sn' => "student name",
2183: 'sec' => "section",
2184: 'start' => "start date",
2185: 'end' => "end date",
2186: 'groups' => "active groups",
2187: );
2188: if ($nosort) {
2189: $r->print(&Apache::loncommon::start_data_table());
2190: $r->print(<<END);
2191: <tr>
2192: <th> </th>
2193: <th>$lt{'usrn'}</th>
2194: <th>$lt{'dom'}</th>
2195: <th>ID</th>
2196: <th>$lt{'sn'}</th>
2197: <th>$lt{'sec'}</th>
2198: <th>$lt{'start'}</th>
2199: <th>$lt{'end'}</th>
2200: <th>$lt{'groups'}</th>
2201: </tr>
2202: END
2203:
2204: } else {
2205: $r->print(&Apache::loncommon::start_data_table());
2206: $r->print(<<END);
2207: <tr><th> </th>
2208: <th>
2209: <a href="/adm/dropadd?action=$action&sortby=username">$lt{'usrn'}</a>
2210: </th><th>
2211: <a href="/adm/dropadd?action=$action&sortby=domain">$lt{'dom'}</a>
2212: </th><th>
2213: <a href="/adm/dropadd?action=$action&sortby=id">ID</a>
2214: </th><th>
2215: <a href="/adm/dropadd?action=$action&sortby=fullname">$lt{'sn'}</a>
2216: </th><th>
2217: <a href="/adm/dropadd?action=$action&sortby=section">$lt{'sec'}</a>
2218: </th><th>
2219: <a href="/adm/dropadd?action=$action&sortby=start">$lt{'start'}</a>
2220: </th><th>
2221: <a href="/adm/dropadd?action=$action&sortby=end">$lt{'end'}</a>
2222: </th><th>
2223: <a href="/adm/dropadd?action=$action&sortby=groups">$lt{'groups'}</a>
2224: </th>
2225: </tr>
2226: END
2227: }
2228: #
2229: # Sort the students
2230: my %index;
2231: my $i;
2232: foreach (@$keylist) {
2233: $index{$_} = $i++;
2234: }
2235: $index{'groups'} = scalar(@$keylist);
2236: my $index = $index{$sortby};
2237: my $second = $index{'username'};
2238: my $third = $index{'domain'};
2239: my @Sorted_Students = sort {
2240: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
2241: ||
2242: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
2243: ||
2244: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
2245: } (keys(%$classlist));
2246: foreach my $student (@Sorted_Students) {
2247: my $error;
2248: my $sdata = $classlist->{$student};
2249: my $username = $sdata->[$index{'username'}];
2250: my $domain = $sdata->[$index{'domain'}];
2251: my $section = $sdata->[$index{'section'}];
2252: my $name = $sdata->[$index{'fullname'}];
2253: my $id = $sdata->[$index{'id'}];
2254: my $start = $sdata->[$index{'start'}];
2255: my $end = $sdata->[$index{'end'}];
2256: my $groups = $classgroups->{$student};
2257: my $active_groups;
2258: if (ref($groups->{active}) eq 'HASH') {
2259: $active_groups = join(', ',keys(%{$groups->{'active'}}));
2260: }
2261: if (! defined($start) || $start == 0) {
2262: $start = &mt('none');
2263: } else {
2264: $start = &Apache::lonlocal::locallocaltime($start);
2265: }
2266: if (! defined($end) || $end == 0) {
2267: $end = &mt('none');
2268: } else {
2269: $end = &Apache::lonlocal::locallocaltime($end);
2270: }
2271: my $status = $sdata->[$index{'status'}];
2272: next if ($status ne 'Active');
2273: #
2274: $r->print(&Apache::loncommon::start_data_table_row());
2275: $r->print(<<"END");
2276: <td><input type="checkbox" name="droplist" value="$student"></td>
2277: <td>$username</td>
2278: <td>$domain</td>
2279: <td>$id</td>
2280: <td>$name</td>
2281: <td>$section</td>
2282: <td>$start</td>
2283: <td>$end</td>
2284: <td>$active_groups</td>
2285: END
2286: $r->print(&Apache::loncommon::end_data_table_row());
2287: }
2288: $r->print(&Apache::loncommon::end_data_table().'<br />');
2289: %lt=&Apache::lonlocal::texthash(
2290: 'dp' => "Drop Students",
2291: 'ca' => "check all",
2292: 'ua' => "uncheck all",
2293: );
2294: $r->print(<<"END");
2295: </p><p>
2296: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)">
2297: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)">
2298: <p><input type=submit value="$lt{'dp'}"></p>
2299: END
2300: return;
2301: }
2302:
2303: #
2304: # Print out the initial form to get the courselist file
2305: #
2306: sub print_first_courselist_upload_form {
2307: my $r=shift;
2308: my $str;
2309: $str = '<input type="hidden" name="phase" value="two">';
2310: $str .= '<input type="hidden" name="action" value="upload" />';
2311: $str .= '<input type="hidden" name="state" value="got_file" />';
2312: $str .= "<h3>".&mt('Upload a class list')."</h3>\n";
2313: $str .= &Apache::loncommon::upfile_select_html();
2314: $str .= "<p>\n";
2315: $str .= '<input type="submit" name="fileupload" value="'.
2316: &mt('Upload class list').'">'."\n";
2317: $str .= '<label><input type="checkbox" name="noFirstLine" /> '.
2318: &mt('Ignore First Line')."</label></p>\n";
2319: $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List",
2320: &mt("How do I create a class list from a spreadsheet")).
2321: "<br />\n";
2322: $str .= &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
2323: &mt("How do I create a CSV file from a spreadsheet")).
2324: "<br />\n";
2325: $str .= &Apache::loncommon::end_page();
2326: $r->print($str);
2327: return;
2328: }
2329:
2330: # ================================================= Drop/Add from uploaded file
2331: sub upfile_drop_add {
2332: my $r=shift;
2333: &Apache::loncommon::load_tmp_file($r);
2334: my @studentdata=&Apache::loncommon::upfile_record_sep();
2335: if($env{'form.noFirstLine'}){shift(@studentdata);}
2336: my @keyfields = split(/\,/,$env{'form.keyfields'});
2337: my $cid = $env{'request.course.id'};
2338: my %fields=();
2339: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
2340: if ($env{'form.upfile_associate'} eq 'reverse') {
2341: if ($env{'form.f'.$i} ne 'none') {
2342: $fields{$keyfields[$i]}=$env{'form.f'.$i};
2343: }
2344: } else {
2345: $fields{$env{'form.f'.$i}}=$keyfields[$i];
2346: }
2347: }
2348: #
2349: # Store the field choices away
2350: foreach my $field (qw/username names
2351: fname mname lname gen id sec ipwd email/) {
2352: $env{'form.'.$field.'_choice'}=$fields{$field};
2353: }
2354: &Apache::loncommon::store_course_settings('enrollment_upload',
2355: { 'username_choice' => 'scalar',
2356: 'names_choice' => 'scalar',
2357: 'fname_choice' => 'scalar',
2358: 'mname_choice' => 'scalar',
2359: 'lname_choice' => 'scalar',
2360: 'gen_choice' => 'scalar',
2361: 'id_choice' => 'scalar',
2362: 'sec_choice' => 'scalar',
2363: 'ipwd_choice' => 'scalar',
2364: 'email_choice' => 'scalar' });
2365:
2366: #
2367: my ($startdate,$enddate) = &get_dates_from_form();
2368: if ($env{'form.makedatesdefault'}) {
2369: $r->print(&make_dates_default($startdate,$enddate));
2370: }
2371: # Determine domain and desired host (home server)
2372: my $domain=$env{'form.lcdomain'};
2373: my $desiredhost = $env{'form.lcserver'};
2374: if (lc($desiredhost) eq 'default') {
2375: $desiredhost = undef;
2376: } else {
2377: my %home_servers = &Apache::lonnet::get_servers($domain,'library');
2378: if (! exists($home_servers{$desiredhost})) {
2379: $r->print('<font color="#ff0000">'.&mt('Error').'</font>'.
2380: &mt('Invalid home server specified'));
2381: $r->print(&Apache::loncommon::end_page());
2382: return;
2383: }
2384: }
2385: # Determine authentication mechanism
2386: my $amode = '';
2387: my $genpwd = '';
2388: if ($env{'form.login'} eq 'krb') {
2389: $amode='krb';
2390: $amode.=$env{'form.krbver'};
2391: $genpwd=$env{'form.krbarg'};
2392: } elsif ($env{'form.login'} eq 'int') {
2393: $amode='internal';
2394: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
2395: $genpwd=$env{'form.intarg'};
2396: }
2397: } elsif ($env{'form.login'} eq 'loc') {
2398: $amode='localauth';
2399: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
2400: $genpwd=$env{'form.locarg'};
2401: }
2402: }
2403: if ($amode =~ /^krb/) {
2404: if (! defined($genpwd) || $genpwd eq '') {
2405: $r->print('<font color="red" size="+1">'.
2406: &mt('Unable to enroll students').'</font> '.
2407: &mt('No Kerberos domain was specified.').'</p>');
2408: $amode = ''; # This causes the loop below to be skipped
2409: }
2410: }
2411: if ( $domain eq &LONCAPA::clean_domain($domain)
2412: && ($amode ne '')) {
2413: #######################################
2414: ## Enroll Students ##
2415: #######################################
2416: $r->print('<h3>'.&mt('Enrolling Students')."</h3>\n<p>\n");
2417: my $count=0;
2418: my $flushc=0;
2419: my %student=();
2420: # Get information about course groups
2421: my %curr_groups = &Apache::longroup::coursegroups();
2422: # Get new classlist
2423: foreach (@studentdata) {
2424: my %entries=&Apache::loncommon::record_sep($_);
2425: # Determine student name
2426: unless (($entries{$fields{'username'}} eq '') ||
2427: (!defined($entries{$fields{'username'}}))) {
2428: my ($fname, $mname, $lname,$gen) = ('','','','');
2429: if (defined($fields{'names'})) {
2430: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
2431: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
2432: } else {
2433: if (defined($fields{'fname'})) {
2434: $fname=$entries{$fields{'fname'}};
2435: }
2436: if (defined($fields{'mname'})) {
2437: $mname=$entries{$fields{'mname'}};
2438: }
2439: if (defined($fields{'lname'})) {
2440: $lname=$entries{$fields{'lname'}};
2441: }
2442: if (defined($fields{'gen'})) {
2443: $gen=$entries{$fields{'gen'}};
2444: }
2445: }
2446: if ($entries{$fields{'username'}}
2447: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
2448: $r->print('<br />'.
2449: &mt('<b>[_1]</b>: Unacceptable username for user [_2] [_3] [_4] [_5]',
2450: $entries{$fields{'username'}},$fname,$mname,$lname,$gen).
2451: '</b>');
2452: } else {
2453: # determine section number
2454: my $sec='';
2455: my $username=$entries{$fields{'username'}};
2456: if (defined($fields{'sec'})) {
2457: if (defined($entries{$fields{'sec'}})) {
2458: $sec=$entries{$fields{'sec'}};
2459: }
2460: }
2461: # remove non alphanumeric values from section
2462: $sec =~ s/\W//g;
2463: if ($sec eq "none" || $sec eq 'all') {
2464: $r->print('<br />'.
2465: &mt('<b>[_1]</b>: Unable to enroll: section name "[_2]" for user [_3] [_4] [_5] [_6] is a reserved word.',
2466: $username,$sec,$fname,$mname,$lname,$gen));
2467: next;
2468: } elsif (($sec ne '') && (exists($curr_groups{$sec}))) {
2469: $r->print('<br />'.
2470: &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.',
2471: $username,$sec,$fname,$mname,$lname,$gen));
2472: next;
2473: }
2474: # determine student id number
2475: my $id='';
2476: if (defined($fields{'id'})) {
2477: if (defined($entries{$fields{'id'}})) {
2478: $id=$entries{$fields{'id'}};
2479: }
2480: $id=~tr/A-Z/a-z/;
2481: }
2482: # determine email address
2483: my $email='';
2484: if (defined($fields{'email'})) {
2485: if (defined($entries{$fields{'email'}})) {
2486: $email=$entries{$fields{'email'}};
2487: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
2488: }
2489: }
2490: # determine student password
2491: my $password='';
2492: if ($genpwd) {
2493: $password=$genpwd;
2494: } else {
2495: if (defined($fields{'ipwd'})) {
2496: if ($entries{$fields{'ipwd'}}) {
2497: $password=$entries{$fields{'ipwd'}};
2498: }
2499: }
2500: }
2501: # Clean up whitespace
2502: foreach (\$domain,\$username,\$id,\$fname,\$mname,
2503: \$lname,\$gen,\$sec) {
2504: $$_ =~ s/(\s+$|^\s+)//g;
2505: }
2506: if ($password || $env{'form.login'} eq 'loc') {
2507: &modifystudent($domain,$username,$cid,$sec,
2508: $desiredhost);
2509: my $reply=&Apache::lonnet::modifystudent
2510: ($domain,$username,$id,$amode,$password,
2511: $fname,$mname,$lname,$gen,$sec,$enddate,
2512: $startdate,$env{'form.forceid'},$desiredhost,
2513: $email);
2514: if ($reply ne 'ok') {
2515: $reply =~ s/^error://;
2516: $r->print('<br />'.
2517: &mt('<b>[_1]</b>: Unable to enroll: [_2]',$username,$reply));
2518: } else {
2519: $count++; $flushc++;
2520: $student{$username}=1;
2521: $r->print('. ');
2522: if ($flushc>15) {
2523: $r->rflush;
2524: $flushc=0;
2525: }
2526: }
2527: } else {
2528: $r->print('<br />'.
2529: &mt('<b>[_1]</b>: Unable to enroll. No password specified.',$username)
2530: );
2531: }
2532: }
2533: }
2534: } # end of foreach (@studentdata)
2535: $r->print("</p>\n<p>\n".&mt('Processed [_1] student(s).',$count).
2536: "</p>\n");
2537: $r->print("<p>\n".
2538: &mt('If active, the new role will be available when the '.
2539: 'students next log in to LON-CAPA.')."</p>\n");
2540: #####################################
2541: # Drop students #
2542: #####################################
2543: if ($env{'form.fullup'} eq 'yes') {
2544: $r->print('<h3>'.&mt('Dropping Students')."</h3>\n");
2545: # Get current classlist
2546: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
2547: if (! defined($classlist)) {
2548: $r->print(&mt('There are no students currently enrolled.').
2549: "\n");
2550: } else {
2551: # Remove the students we just added from the list of students.
2552: foreach (@studentdata) {
2553: my %entries=&Apache::loncommon::record_sep($_);
2554: unless (($entries{$fields{'username'}} eq '') ||
2555: (!defined($entries{$fields{'username'}}))) {
2556: delete($classlist->{$entries{$fields{'username'}}.
2557: ':'.$domain});
2558: }
2559: }
2560: # Print out list of dropped students.
2561: &show_drop_list($r,$classlist,$keylist,'nosort');
2562: }
2563: }
2564: } # end of unless
2565: }
2566:
2567: # ================================================================== Phase four
2568: sub drop_student_list {
2569: my $r=shift;
2570: my $count=0;
2571: my @droplist = &Apache::loncommon::get_env_multiple('form.droplist');
2572: foreach (@droplist) {
2573: my ($uname,$udom)=split(/\:/,$_);
2574: # drop student
2575: my $result = &modifystudent($udom,$uname,$env{'request.course.id'});
2576: if ($result eq 'ok' || $result eq 'ok:') {
2577: $r->print(&mt('Dropped [_1]',$uname.'@'.$udom).'<br>');
2578: $count++;
2579: } else {
2580: $r->print(
2581: &mt('Error dropping [_1]:[_2]',$uname.'@'.$udom,$result).
2582: '<br />');
2583: }
2584: }
2585: $r->print('<p><b>'.&mt('Dropped [_1] student(s).',$count).'</b></p>');
2586: $r->print('<p>'.&mt('Re-enrollment will re-activate data.')) if ($count);
2587: }
2588:
2589: sub section_check_js {
2590: my $groupslist;
2591: my %curr_groups = &Apache::longroup::coursegroups();
2592: if (%curr_groups) {
2593: $groupslist = join('","',sort(keys(%curr_groups)));
2594: }
2595: return <<"END";
2596: function validate(caller) {
2597: var groups = new Array("$groupslist");
2598: var secname = caller.value;
2599: if ((secname == 'all') || (secname == 'none')) {
2600: alert("'"+secname+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
2601: return 'error';
2602: }
2603: if (secname != '') {
2604: for (var k=0; k<groups.length; k++) {
2605: if (secname == groups[k]) {
2606: 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.");
2607: return 'error';
2608: }
2609: }
2610: }
2611: return 'ok';
2612: }
2613: END
2614: }
2615:
2616: sub get_permission {
2617: my %permission;
2618: $permission{'view'} =
2619: &Apache::lonnet::allowed('vcl',$env{'request.course.id'});
2620: if (!$permission{'view'}) {
2621: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
2622: $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
2623: if ($permission{'view'}) {
2624: $permission{'view_section'} = $env{'request.course.sec'};
2625: }
2626: }
2627:
2628: $permission{'enrl'} =
2629: &Apache::lonnet::allowed('cst',$env{'request.course.id'});
2630:
2631: $permission{'grp_view'} =
2632: &Apache::lonnet::allowed('vcg',$env{'request.course.id'});
2633: $permission{'grp_manage'} =
2634: &Apache::lonnet::allowed('mdg',$env{'request.course.id'});
2635: my $allowed = 0;
2636: foreach my $perm (values(%permission)) {
2637: if ($perm) { $allowed=1; last; }
2638: }
2639: return (\%permission,$allowed);
2640: }
2641:
2642: ###################################################################
2643: ###################################################################
2644:
2645: =pod
2646:
2647: =item &handler
2648:
2649: The typical handler you see in all these modules. Takes $r, the
2650: http request, as an argument.
2651:
2652: The response to the request is governed by two form variables
2653:
2654: form.action form.state response
2655: ---------------------------------------------------
2656: undefined undefined print main menu
2657: upload undefined print courselist upload menu
2658: upload got_file deal with uploaded file,
2659: print the upload managing menu
2660: upload enrolling enroll students based on upload
2661: drop undefined print the classlist ready to drop
2662: drop done drop the selected students
2663: enrollstudent undefined print student username domain form
2664: enrollstudent gotusername print single student enroll menu
2665: enrollstudent enrolling enroll student
2666: classlist undefined print html classlist
2667: classlist csv print csv classlist
2668: modifystudent undefined print classlist to select student to modify
2669: modifystudent selected print modify student menu
2670: modifystudent done make modifications to student record
2671:
2672: =cut
2673:
2674: ###################################################################
2675: ###################################################################
2676: sub handler {
2677: my $r=shift;
2678: if ($r->header_only) {
2679: &Apache::loncommon::content_type($r,'text/html');
2680: $r->send_http_header;
2681: return OK;
2682: }
2683: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2684: ['action','state']);
2685:
2686: &Apache::lonhtmlcommon::clear_breadcrumbs();
2687: &Apache::lonhtmlcommon::add_breadcrumb
2688: ({href=>"/adm/dropadd",
2689: text=>"Enrollment Manager",
2690: faq=>9,bug=>'Instructor Interface',});
2691: # Needs to be in a course
2692: if (! ($env{'request.course.fn'})) {
2693: # Not in a course
2694: $env{'user.error.msg'}=
2695: "/adm/dropadd:cst:0:0:Cannot manage or view course groups, ".
2696: "or drop or add students";
2697: return HTTP_NOT_ACCEPTABLE;
2698: }
2699: #
2700:
2701: my ($permission,$allowed) = &get_permission();
2702:
2703: if (!$allowed) {
2704: $env{'user.error.msg'}=
2705: "/adm/dropadd:cst:0:0:Cannot manage or view course groups, ".
2706: "or drop or add students";
2707: return HTTP_NOT_ACCEPTABLE;
2708: }
2709:
2710: #
2711: # Only output the header information if they did not request csv format
2712: #
2713: # Start page
2714: &Apache::loncommon::content_type($r,'text/html');
2715: $r->send_http_header;
2716: #
2717: # Main switch on form.action and form.state, as appropriate
2718: if (! exists($env{'form.action'})) {
2719: $r->print(&header());
2720: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enrollment Manager'));
2721: my $action = &print_main_menu($r,$permission);
2722: } elsif ($env{'form.action'} eq 'upload' && $permission->{'enrl'}) {
2723: $r->print(&header());
2724: &Apache::lonhtmlcommon::add_breadcrumb
2725: ({href=>'/adm/dropadd?action=upload&state=',
2726: text=>"Upload Classlist"});
2727: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Upload Classlist',
2728: 'Course_Create_Class_List'));
2729: if (! exists($env{'form.state'})) {
2730: &print_first_courselist_upload_form($r);
2731: } elsif ($env{'form.state'} eq 'got_file') {
2732: &print_upload_manager_form($r);
2733: } elsif ($env{'form.state'} eq 'enrolling') {
2734: if ($env{'form.datatoken'}) {
2735: &upfile_drop_add($r);
2736: } else {
2737: # Hmmm, this is an error
2738: }
2739: } else {
2740: &print_first_courselist_upload_form($r);
2741: }
2742: } elsif ($env{'form.action'} eq 'drop' && $permission->{'enrl'}) {
2743: $r->print(&header());
2744: &Apache::lonhtmlcommon::add_breadcrumb
2745: ({href=>'/adm/dropadd?action=drop',
2746: text=>"Drop Students"});
2747: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
2748: 'Course_Drop_Student'));
2749: if (! exists($env{'form.state'})) {
2750: &print_drop_menu($r);
2751: } elsif ($env{'form.state'} eq 'done') {
2752: &drop_student_list($r);
2753: } else {
2754: &print_drop_menu($r);
2755: }
2756: } elsif ($env{'form.action'} eq 'enrollstudent' && $permission->{'enrl'}) {
2757: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
2758: my ($jsback,$elements) = &Apache::loncreateuser::crumb_utilities();
2759: my $jscript = '<script type="text/javascript">'.$jsback.'</script>';
2760: &Apache::loncreateuser::restore_prev_selections();
2761: my $srch;
2762: foreach my $item (@search) {
2763: $srch->{$item} = $env{'form.'.$item};
2764: }
2765:
2766: if ($env{'form.state'} eq 'gotusername') {
2767: if ($env{'form.phase'} eq 'get_user_info') {
2768: my ($currstate,$response,$forcenewuser,$results) =
2769: &Apache::loncreateuser::user_search_result($srch);
2770: if ($env{'form.currstate'} eq 'modify') {
2771: $currstate = $env{'form.currstate'};
2772: }
2773: if ($currstate eq 'select') {
2774: $r->print(&header());
2775: &Apache::lonhtmlcommon::add_breadcrumb
2776: ({href=>"javascript:backPage(document.usersrchform,'','')",
2777: text=>"Single user search"},
2778: {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
2779: text=>"Select User",});
2780: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enroll Student',
2781: 'Course_Add_Student'));
2782: &Apache::loncreateuser::print_user_selection_page($r,
2783: $response,$srch,$results,'enrollstudent',\@search);
2784: } elsif ($currstate eq 'modify') {
2785: my ($ccuname,$ccdomain);
2786: if (($srch->{'srchby'} eq 'uname') &&
2787: ($srch->{'srchtype'} eq 'exact')) {
2788: $ccuname = $srch->{'srchterm'};
2789: $ccdomain= $srch->{'srchdomain'};
2790: } else {
2791: my @matchedunames = keys(%{$results});
2792: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
2793: }
2794: $ccuname =&LONCAPA::clean_username($ccuname);
2795: $ccdomain=&LONCAPA::clean_domain($ccdomain);
2796: &print_enroll_single_student_form($r,$jscript,$ccuname,
2797: $ccdomain,$srch,$response);
2798: } elsif ($currstate eq 'query') {
2799: $r->print(&header($jscript));
2800: &Apache::lonhtmlcommon::add_breadcrumb
2801: ({href=>"javascript:backPage(document.studentform,'','')",
2802: text=>"Single user search"});
2803: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enroll Student',
2804: 'Course_Add_Student'));
2805: &Apache::loncreateuser::print_user_query_page($r,'enrollstudent');
2806: } else {
2807: &get_student_username_domain_form($r,$elements,$response,
2808: $srch,$forcenewuser);
2809: }
2810: } elsif ($env{'form.phase'} eq 'userpicked') {
2811: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
2812: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
2813: &print_enroll_single_student_form($r,$jscript,$ccuname,
2814: $ccdomain,$srch);
2815: } else {
2816: &get_student_username_domain_form($r,$elements,undef,$srch);
2817: }
2818: } elsif ($env{'form.state'} eq 'enrolling') {
2819: $r->print(&header($jscript));
2820: &Apache::lonhtmlcommon::add_breadcrumb
2821: ({href=>"javascript:backPage(document.studentform,'','')",
2822: text=>"Single user search"});
2823: if ($env{'form.prevphase'} eq 'userpicked') {
2824: &Apache::lonhtmlcommon::add_breadcrumb
2825: ({href=>"javascript:backPage(document.studentform,'get_user_info','select')",
2826: text=>"Select user",});
2827: }
2828: &Apache::lonhtmlcommon::add_breadcrumb
2829: ({href=>"javascript:backPage(document.studentform,'$env{'form.prevphase'}','modify')",
2830: text=>"Set enrollment",},
2831: {href=>"javascript:backPage(document.studentform,$env{'form.phase'},'')",
2832: text=>"Result",});
2833: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enroll Student',
2834: 'Course_Add_Student'));
2835: &enroll_single_student($r,\@search);
2836: } else {
2837: &get_student_username_domain_form($r,$elements,undef,$srch);
2838: }
2839: } elsif ($env{'form.action'} eq 'classlist' && $permission->{'view'}) {
2840: $r->print(&header());
2841: &Apache::lonhtmlcommon::add_breadcrumb
2842: ({href=>'/adm/dropadd?action=classlist',
2843: text=>"View Classlist"});
2844: $r->print(&Apache::lonhtmlcommon::breadcrumbs('View Classlist',
2845: 'Course_View_Class_List'));
2846: if (! exists($env{'form.state'})) {
2847: &print_html_classlist($r,undef,$permission);
2848: } elsif ($env{'form.state'} eq 'csv') {
2849: &print_html_classlist($r,'csv',$permission);
2850: } elsif ($env{'form.state'} eq 'excel') {
2851: &print_html_classlist($r,'excel',$permission);
2852: } else {
2853: &print_html_classlist($r,undef,$permission);
2854: }
2855: } elsif ($env{'form.action'} eq 'modifystudent' && $permission->{'enrl'}) {
2856: $r->print(&header());
2857: &Apache::lonhtmlcommon::add_breadcrumb
2858: ({href=>'/adm/dropadd?action=modifystudent',
2859: text=>"Modify Student Data"});
2860: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Modify Student Data',
2861: 'Course_Modify_Student_Data'));
2862: if (! exists($env{'form.state'})) {
2863: &print_html_classlist($r,undef,$permission);
2864: } elsif ($env{'form.state'} eq 'selected') {
2865: &print_modify_student_form($r);
2866: } elsif ($env{'form.state'} eq 'done') {
2867: &modify_single_student($r);
2868: } else {
2869: &print_html_classlist($r,undef,$permission);
2870: }
2871: } else {
2872: # We should not end up here, but I guess it is possible
2873: &Apache::lonnet::logthis("Undetermined state in londropadd.pm. ".
2874: "form.action = ".$env{'form.action'}.
2875: "Someone should fix this.");
2876: $r->print(&header());
2877: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enrollment Manager'));
2878: &print_main_menu($r,$permission);
2879: }
2880: #
2881: # Finish up
2882: $r->print('</form>'.&Apache::loncommon::end_page());
2883: return OK;
2884: }
2885:
2886: ###################################################################
2887: ###################################################################
2888:
2889: 1;
2890: __END__
2891:
2892:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>