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