1: # The LearningOnline Network with CAPA
2: # Handler to drop and add students in courses
3: #
4: # $Id: londropadd.pm,v 1.89 2003/11/06 22:49:59 matthew 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: # (Handler to set parameters for assessments
29: #
30: # (Handler to resolve ambiguous file locations
31: #
32: # (TeX Content Handler
33: #
34: ###############################################################
35: ##############################################################
36:
37: package Apache::londropadd;
38:
39: use strict;
40: use Apache::lonnet();
41: use Apache::loncommon();
42: use Apache::lonhtmlcommon();
43: use Apache::Constants qw(:common :http REDIRECT);
44: use Spreadsheet::WriteExcel;
45: use Apache::lonlocal;
46:
47: ###############################################################
48: ###############################################################
49: sub header {
50: my $bodytag=&Apache::loncommon::bodytag('Enrollment Manager');
51: my $title = &mt('LON-CAPA Enrollment Manager');
52: return(<<ENDHEAD);
53: <html>
54: <head>
55: <title>$title</title>
56: </head>
57: $bodytag
58: <form method="post" enctype="multipart/form-data"
59: action="/adm/dropadd" name="studentform">
60: ENDHEAD
61: }
62:
63: ###############################################################
64: ###############################################################
65: # Drop student from all sections of a course, except optional $csec
66: sub modifystudent {
67: my ($udom,$unam,$courseid,$csec,$desiredhost)=@_;
68: # if $csec is undefined, drop the student from all the courses matching
69: # this one. If $csec is defined, drop them from all other sections of
70: # this course and add them to section $csec
71: $courseid=~s/\_/\//g;
72: $courseid=~s/^(\w)/\/$1/;
73: my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
74: my ($tmp) = keys(%roles);
75: # Bail out if we were unable to get the students roles
76: return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
77: # Go through the roles looking for enrollment in this course
78: my $result = '';
79: foreach my $course (keys(%roles)) {
80: if ($course=~/^$courseid(?:\/)*(?:\s+)*(\w+)*\_st$/) {
81: # We are in this course
82: my $section=$1;
83: $section='' if ($course eq $courseid.'_st');
84: if (defined($csec) && $section eq $csec) {
85: $result .= 'ok:';
86: } elsif ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
87: my (undef,$end,$start)=split(/\_/,$roles{$course});
88: my $now=time;
89: # if this is an active role
90: if (!($start && ($now<$start)) || !($end && ($now>$end))) {
91: my $reply=&Apache::lonnet::modifystudent
92: # dom name id mode pass f m l g
93: ($udom,$unam,'', '', '',undef,undef,undef,undef,
94: $section,time,undef,undef,$desiredhost);
95: $result .= $reply.':';
96: }
97: }
98: }
99: }
100: if ($result eq '') {
101: $result = 'Unable to find section for this student';
102: } else {
103: $result =~ s/(ok:)+/ok/g;
104: }
105: return $result;
106: }
107:
108: ###############################################################
109: ###############################################################
110: # build a domain and server selection form
111: sub domain_form {
112: my ($defdom) = @_;
113: # Set up domain and server selection forms
114: #
115: # Get the domains
116: my @domains = &Apache::loncommon::get_domains();
117: # build up the menu information to be passed to
118: # &Apache::loncommon::linked_select_forms
119: my %select_menus;
120: foreach my $dom (@domains) {
121: # set up the text for this domain
122: $select_menus{$dom}->{'text'}= $dom;
123: # we want a choice of 'default' as the default in the second menu
124: $select_menus{$dom}->{'default'}= 'default';
125: $select_menus{$dom}->{'select2'}->{'default'} = 'default';
126: # Now build up the other items in the second menu
127: my %servers = &Apache::loncommon::get_library_servers($dom);
128: foreach my $server (keys(%servers)) {
129: $select_menus{$dom}->{'select2'}->{$server}
130: = "$server $servers{$server}";
131: }
132: }
133: my $result = &Apache::loncommon::linked_select_forms
134: ('studentform',' with home server ',$defdom,
135: 'lcdomain','lcserver',\%select_menus);
136: return $result;
137: }
138:
139: ###############################################################
140: ###############################################################
141: # Menu Phase One
142: sub print_main_menu {
143: my $r=shift;
144: my %Text = &Apache::lonlocal::texthash
145: ('upload' => 'Upload a class list',
146: 'enrollone' => 'Enroll a single student',
147: 'modify' => 'Modify student data',
148: 'view' => 'View Class List',
149: 'drop' => 'Drop Students');
150:
151: $r->print(<<END);
152: <p>
153: <font size="+1">
154: <a href="/adm/dropadd?action=upload">$Text{'upload'}</a>
155: </font>
156: </p><p>
157: <font size="+1">
158: <a href="/adm/dropadd?action=enrollstudent">$Text{'enrollone'}</a>
159: </font>
160: </p><p>
161: <font size="+1">
162: <a href="/adm/dropadd?action=modifystudent">$Text{'modify'}</a>
163: </font>
164: </p><p>
165: <font size="+1">
166: <a href="/adm/dropadd?action=classlist">$Text{'view'}</a>
167: </font>
168: </p><p>
169: <font size="+1">
170: <a href="/adm/dropadd?action=drop">$Text{'drop'}</a>
171: </font>
172: </p>
173: END
174: }
175:
176: ###############################################################
177: ###############################################################
178: sub hidden_input {
179: my ($name,$value) = @_;
180: return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n";
181: }
182:
183: sub print_upload_manager_header {
184: my ($r,$datatoken,$distotal,$krbdefdom)=@_;
185: my $javascript;
186: if (! exists($ENV{'form.upfile_associate'})) {
187: $ENV{'form.upfile_associate'} = 'forward';
188: }
189: if ($ENV{'form.associate'} eq 'Reverse Association') {
190: if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
191: $ENV{'form.upfile_associate'} = 'reverse';
192: } else {
193: $ENV{'form.upfile_associate'} = 'forward';
194: }
195: }
196: if ($ENV{'form.upfile_associate'} eq 'reverse') {
197: $javascript=&upload_manager_javascript_reverse_associate();
198: } else {
199: $javascript=&upload_manager_javascript_forward_associate();
200: }
201: my $javascript_validations=&javascript_validations('auth',$krbdefdom);
202: my $checked=(($ENV{'form.noFirstLine'})?' checked="1"':'');
203: $r->print('<h3>'.&mt('Uploading Class List')."</h3>\n".
204: "<hr>\n".
205: '<h3>'.&mt('Identify fields')."</h3>\n");
206: $r->print("<p>\n".
207: &mt('Total number of records found in file: [_1].',$distotal).
208: "\n".
209: "</p><hr>\n");
210: $r->print(&mt('Enter as many fields as you can. '.
211: 'The system will inform you and bring you back to '.
212: 'this page if the data selected is insufficient to '.
213: 'enroll students in your class.')."<hr>\n");
214: $r->print(&hidden_input('action','upload').
215: &hidden_input('state','got_file').
216: &hidden_input('associate','').
217: &hidden_input('datatoken',$datatoken).
218: &hidden_input('fileupload',$ENV{'form.fileupload'}).
219: &hidden_input('upfiletype',$ENV{'form.upfiletype'}).
220: &hidden_input('upfile_associate',$ENV{'form.upfile_associate'}));
221: $r->print('<input type="button" value="Reverse Association" '.
222: 'name="'.&mt('Reverse Association').'" '.
223: 'onClick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />');
224: $r->print('<input type="checkbox" name="noFirstLine" $checked />'.
225: &mt('Ignore First Line'));
226: $r->print("<hr />\n".
227: '<script type="text/javascript" language="Javascript">'."\n".
228: $javascript."\n".$javascript_validations.'</script>');
229: }
230:
231: ###############################################################
232: ###############################################################
233: sub javascript_validations {
234: my ($mode,$krbdefdom)=@_;
235: my $authheader;
236: if ($mode eq 'auth') {
237: my %param = ( formname => 'studentform',
238: kerb_def_dom => $krbdefdom );
239: $authheader = &Apache::loncommon::authform_header(%param);
240: }
241: my %alert = &Apache::lonlocal::texthash
242: (username => 'You need to specify the username field.',
243: authen => 'You must choose an authentication type.',
244: krb => 'You need to specify the Kerberos domain.',
245: ipass => 'You need to specify the initial password.',
246: name => 'The optional name field was not specified.',
247: snum => 'The optional student number field was not specified.',
248: section => 'The optional section or group field was not specified.',
249: email => 'The optional email address field was not specified.',
250: continue => 'Continue enrollment?',
251: );
252:
253: # my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
254: my $function_name =(<<END);
255: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail) {
256: END
257: my $auth_checks = (<<END);
258: var foundatype=0;
259: if (founduname==0) {
260: alert('$alert{'username'}');
261: return;
262: }
263: // alert('current.radiovalue = '+current.radiovalue);
264: if (current.radiovalue == null || current.radiovalue == 'nochange') {
265: // They did not check any of the login radiobuttons.
266: alert('$alert{'authen'}');
267: return;
268: }
269: foundatype=1;
270: if (current.argfield == null || current.argfield == '') {
271: var alertmsg = '';
272: switch (current.value) {
273: case 'krb':
274: alertmsg = '$alert{'krb'}';
275: break;
276: case 'loc':
277: case 'fsys':
278: alertmsg = '$alert{'ipass'}';
279: break;
280: case 'fsys':
281: alertmsg = '';
282: break;
283: default:
284: alertmsg = '';
285: }
286: if (alertmsg != '') {
287: alert(alertmsg);
288: return;
289: }
290: }
291: END
292: my $optional_checks = (<<END);
293: var message='';
294: if (foundname==0) {
295: message='$alert{'name'}';
296: }
297: if (foundid==0) {
298: if (message!='') {
299: message+='\\n';
300: }
301: message+='$alert{'snum'}';
302: }
303: if (foundsec==0) {
304: if (message!='') {
305: message+='\\n';
306: }
307: message+='$alert{'section'}';
308: }
309: if (foundemail==0) {
310: if (message!='') {
311: message+='\\n';
312: }
313: message+='$alert{'email'}';
314: }
315: if (message!='') {
316: message+= '\\n$alert{'continue'}';
317: if (confirm(message)) {
318: vf.state.value='enrolling';
319: vf.submit();
320: }
321: } else {
322: vf.state.value='enrolling';
323: vf.submit();
324: }
325: }
326:
327: END
328: my $result = $function_name;
329: if ($mode eq 'auth') {
330: $result .= $auth_checks;
331: }
332: $result .= $optional_checks;
333: if ($mode eq 'auth') {
334: $result .= $authheader;
335: }
336: return $result;
337: }
338:
339: ###############################################################
340: ###############################################################
341: sub upload_manager_javascript_forward_associate {
342: return(<<ENDPICK);
343: function verify(vf) {
344: var founduname=0;
345: var foundpwd=0;
346: var foundname=0;
347: var foundid=0;
348: var foundsec=0;
349: var foundemail=0;
350: var tw;
351: for (i=0;i<=vf.nfields.value;i++) {
352: tw=eval('vf.f'+i+'.selectedIndex');
353: if (tw==1) { founduname=1; }
354: if ((tw>=2) && (tw<=6)) { foundname=1; }
355: if (tw==7) { foundid=1; }
356: if (tw==8) { foundsec=1; }
357: if (tw==9) { foundpwd=1; }
358: if (tw==10) { foundemail=1; }
359: }
360: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail);
361: }
362:
363: //
364: // vf = this.form
365: // tf = column number
366: //
367: // values of nw
368: //
369: // 0 = none
370: // 1 = username
371: // 2 = names (lastname, firstnames)
372: // 3 = fname (firstname)
373: // 4 = mname (middlename)
374: // 5 = lname (lastname)
375: // 6 = gen (generation)
376: // 7 = id
377: // 8 = section
378: // 9 = ipwd (password)
379: // 10 = email address
380:
381: function flip(vf,tf) {
382: var nw=eval('vf.f'+tf+'.selectedIndex');
383: var i;
384: // make sure no other columns are labeled the same as this one
385: for (i=0;i<=vf.nfields.value;i++) {
386: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
387: eval('vf.f'+i+'.selectedIndex=0;')
388: }
389: }
390: // If we set this to 'lastname, firstnames', clear out all the ones
391: // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
392: if (nw==2) {
393: for (i=0;i<=vf.nfields.value;i++) {
394: if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
395: (eval('vf.f'+i+'.selectedIndex')<=6)) {
396: eval('vf.f'+i+'.selectedIndex=0;')
397: }
398: }
399: }
400: // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
401: // clear out any that are set to 'lastname, firstnames' (2)
402: if ((nw>=3) && (nw<=6)) {
403: for (i=0;i<=vf.nfields.value;i++) {
404: if (eval('vf.f'+i+'.selectedIndex')==2) {
405: eval('vf.f'+i+'.selectedIndex=0;')
406: }
407: }
408: }
409: // If we set the password, make the password form below correspond to
410: // the new value.
411: if (nw==9) {
412: changed_radio('int',document.studentform);
413: set_auth_radio_buttons('int',document.studentform);
414: vf.intarg.value='';
415: vf.krbarg.value='';
416: vf.locarg.value='';
417: }
418: }
419:
420: function clearpwd(vf) {
421: var i;
422: for (i=0;i<=vf.nfields.value;i++) {
423: if (eval('vf.f'+i+'.selectedIndex')==9) {
424: eval('vf.f'+i+'.selectedIndex=0;')
425: }
426: }
427: }
428:
429: ENDPICK
430: }
431:
432: ###############################################################
433: ###############################################################
434: sub upload_manager_javascript_reverse_associate {
435: return(<<ENDPICK);
436: function verify(vf) {
437: var founduname=0;
438: var foundpwd=0;
439: var foundname=0;
440: var foundid=0;
441: var foundsec=0;
442: var tw;
443: for (i=0;i<=vf.nfields.value;i++) {
444: tw=eval('vf.f'+i+'.selectedIndex');
445: if (i==0 && tw!=0) { founduname=1; }
446: if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
447: if (i==6 && tw!=0) { foundid=1; }
448: if (i==7 && tw!=0) { foundsec=1; }
449: if (i==8 && tw!=0) { foundpwd=1; }
450: }
451: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
452: }
453:
454: function flip(vf,tf) {
455: var nw=eval('vf.f'+tf+'.selectedIndex');
456: var i;
457: // picked the all one one name field, reset the other name ones to blank
458: if (tf==1 && nw!=0) {
459: for (i=2;i<=5;i++) {
460: eval('vf.f'+i+'.selectedIndex=0;')
461: }
462: }
463: //picked one of the piecewise name fields, reset the all in
464: //one field to blank
465: if ((tf>=2) && (tf<=5) && (nw!=0)) {
466: eval('vf.f1.selectedIndex=0;')
467: }
468: // intial password specified, pick internal authentication
469: if (tf==8 && nw!=0) {
470: changed_radio('int',document.studentform);
471: set_auth_radio_buttons('int',document.studentform);
472: vf.krbarg.value='';
473: vf.intarg.value='';
474: vf.locarg.value='';
475: }
476: }
477:
478: function clearpwd(vf) {
479: var i;
480: if (eval('vf.f8.selectedIndex')!=0) {
481: eval('vf.f8.selectedIndex=0;')
482: }
483: }
484: ENDPICK
485: }
486:
487: ###############################################################
488: ###############################################################
489: sub print_upload_manager_footer {
490: my ($r,$i,$keyfields,$defdom,$today,$halfyear)=@_;
491:
492: my ($krbdef,$krbdefdom) =
493: &Apache::loncommon::get_kerberos_defaults($defdom);
494: my %param = ( formname => 'document.studentform',
495: kerb_def_dom => $krbdefdom,
496: kerb_def_auth => $krbdef
497: );
498: my $krbform = &Apache::loncommon::authform_kerberos(%param);
499: my $intform = &Apache::loncommon::authform_internal(%param);
500: my $locform = &Apache::loncommon::authform_local(%param);
501: my $domform = &domain_form($defdom);
502: my $date_table = &date_setting_table();
503: $r->print(<<ENDPICK);
504: </table>
505: <input type="hidden" name="nfields" value="$i">
506: <input type="hidden" name="keyfields" value="$keyfields">
507: <h3>Login Type</h3>
508: <p>Note: this will not take effect if the user already exists</p>
509: <p>
510: $krbform
511: </p>
512: <p>
513: $intform
514: </p>
515: <p>
516: $locform
517: </p>
518: <h3>LON-CAPA Domain for Students</h3>
519: LON-CAPA domain: $domform <p>
520: <h3>Starting and Ending Dates</h3>
521: <p>
522: $date_table
523: </p>
524: <h3>Full Update</h3>
525: <input type=checkbox name=fullup value=yes> Full update
526: (also print list of users not enrolled anymore)<p>
527: <h3>ID/Student Number</h3>
528: <input type=checkbox name=forceid value=yes>
529: Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
530: (only do if you know what you are doing)<p>
531: <input type="button" onClick="javascript:verify(this.form)" value="Update Courselist" /><br />
532: Note: for large courses, this operation may be time consuming.
533: ENDPICK
534: }
535:
536: # ======================================================= Menu Phase Two Upload
537: sub print_upload_manager_form {
538: my $r=shift;
539: my $firstLine;
540: my $datatoken;
541: if (!$ENV{'form.datatoken'}) {
542: $datatoken=&Apache::loncommon::upfile_store($r);
543: } else {
544: $datatoken=$ENV{'form.datatoken'};
545: &Apache::loncommon::load_tmp_file($r);
546: }
547: my @records=&Apache::loncommon::upfile_record_sep();
548: if($ENV{'form.noFirstLine'}){$firstLine=shift(@records);}
549: my $total=$#records;
550: my $distotal=$total+1;
551: my $today=time;
552: my $halfyear=$today+15552000;
553: my $defdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
554: my ($krbdef,$krbdefdom) =
555: &Apache::loncommon::get_kerberos_defaults($defdom);
556: &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom);
557: my $i;
558: my $keyfields;
559: if ($total>=0) {
560: my @d=(['username','Username'],
561: ['names','Last Name, First Names'],
562: ['fname','First Name'],
563: ['mname','Middle Names/Initials'],
564: ['lname','Last Name'],
565: ['gen','Generation'],
566: ['id','ID/Student Number'],
567: ['sec','Group/Section'],
568: ['ipwd','Initial Password'],
569: ['email','EMail Address']);
570: if ($ENV{'form.upfile_associate'} eq 'reverse') {
571: &Apache::loncommon::csv_print_samples($r,\@records);
572: $i=&Apache::loncommon::csv_print_select_table($r,\@records,\@d);
573: foreach (@d) { $keyfields.=$_->[0].','; }
574: chop($keyfields);
575: } else {
576: unshift(@d,['none','']);
577: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,\@d);
578: my %sone=&Apache::loncommon::record_sep($records[0]);
579: $keyfields=join(',',sort(keys(%sone)));
580: }
581: }
582: &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear);
583: }
584:
585: # ======================================================= Enroll single student
586: sub enroll_single_student {
587: my $r=shift;
588: # Remove non alphanumeric values from section
589: $ENV{'form.csec'}=~s/\W//g;
590: #
591: # We do the dates first because the action of making them the defaul
592: # in the course is entirely seperate from the action of enrolling the
593: # student. Also, a failure in setting the dates as default is not fatal
594: # to the process of enrolling / modifying a student.
595: my ($startdate,$enddate) = &get_dates_from_form();
596: if ($ENV{'form.makedatesdefault'}) {
597: $r->print(&make_dates_default($startdate,$enddate));
598: }
599:
600: $r->print('<h3>Enrolling Student</h3>');
601: $r->print('<p>Enrolling '.$ENV{'form.cuname'}." \@ ".
602: $ENV{'form.lcdomain'}.'</p>');
603: if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&
604: ($ENV{'form.lcdomain'})&&($ENV{'form.lcdomain'}!~/\W/)) {
605: # Deal with home server selection
606: my $domain=$ENV{'form.lcdomain'};
607: my $desiredhost = $ENV{'form.lcserver'};
608: if (lc($desiredhost) eq 'default') {
609: $desiredhost = undef;
610: } else {
611: my %home_servers =&Apache::loncommon::get_library_servers($domain);
612: if (! exists($home_servers{$desiredhost})) {
613: $r->print('<font color="#ff0000">Error:</font>'.
614: 'Invalid home server specified');
615: return;
616: }
617: }
618: $r->print(" with server $desiredhost :") if (defined($desiredhost));
619: # End of home server selection logic
620: my $amode='';
621: my $genpwd='';
622: if ($ENV{'form.login'} eq 'krb') {
623: $amode='krb';
624: $amode.=$ENV{'form.krbver'};
625: $genpwd=$ENV{'form.krbarg'};
626: } elsif ($ENV{'form.login'} eq 'int') {
627: $amode='internal';
628: $genpwd=$ENV{'form.intarg'};
629: } elsif ($ENV{'form.login'} eq 'loc') {
630: $amode='localauth';
631: $genpwd=$ENV{'form.locarg'};
632: if (!$genpwd) { $genpwd=" "; }
633: }
634: my $home = &Apache::lonnet::homeserver($ENV{'form.cuname'},
635: $ENV{'form.lcdomain'});
636: if ((($amode) && ($genpwd)) || ($home ne 'no_host')) {
637: # Clean out any old roles the student has in this class.
638: &modifystudent($ENV{'form.lcdomain'},$ENV{'form.cuname'},
639: $ENV{'request.course.id'},$ENV{'form.csec'},
640: $desiredhost);
641: my $login_result = &Apache::lonnet::modifystudent
642: ($ENV{'form.lcdomain'},$ENV{'form.cuname'},
643: $ENV{'form.cstid'},$amode,$genpwd,
644: $ENV{'form.cfirst'},$ENV{'form.cmiddle'},
645: $ENV{'form.clast'},$ENV{'form.cgen'},
646: $ENV{'form.csec'},$enddate,
647: $startdate,$ENV{'form.forceid'},
648: $desiredhost);
649: if ($login_result =~ /^ok/) {
650: $r->print($login_result);
651: $r->print("<p> If active, the new role will be available ".
652: "when the student next logs in to LON-CAPA.</p>");
653: } else {
654: $r->print("unable to enroll: ".$login_result);
655: }
656: } else {
657: $r->print('<p><font color="#ff0000">ERROR</font> ');
658: if ($amode =~ /^krb/) {
659: $r->print('Missing Kerberos domain information. ');
660: } else {
661: $r->print('Invalid login mode or password. ');
662: }
663: $r->print('<b>Unable to enroll '.$ENV{'form.cuname'}.'.</b></p>');
664: }
665: } else {
666: $r->print('Invalid username or domain');
667: }
668: }
669:
670: sub setup_date_selectors {
671: my ($starttime,$endtime) = @_;
672: if (! defined($starttime)) {
673: $starttime = time;
674: if (exists($ENV{'course.'.$ENV{'request.course.id'}.
675: '.default_enrollment_start_date'})) {
676: $starttime = $ENV{'course.'.$ENV{'request.course.id'}.
677: '.default_enrollment_start_date'};
678: }
679: }
680: if (! defined($endtime)) {
681: $endtime = time+(6*30*24*60*60); # 6 months from now, approx
682: if (exists($ENV{'course.'.$ENV{'request.course.id'}.
683: '.default_enrollment_end_date'})) {
684: $endtime = $ENV{'course.'.$ENV{'request.course.id'}.
685: '.default_enrollment_end_date'};
686: }
687: }
688: my $startdateform = &Apache::lonhtmlcommon::date_setter('studentform',
689: 'startdate',
690: $starttime);
691: my $enddateform = &Apache::lonhtmlcommon::date_setter('studentform',
692: 'enddate',
693: $endtime);
694: return ($startdateform,$enddateform);
695: }
696:
697: sub get_dates_from_form {
698: my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
699: my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
700: if ($ENV{'form.no_end_date'}) {
701: $enddate = 0;
702: }
703: return ($startdate,$enddate);
704: }
705:
706: sub date_setting_table {
707: my ($starttime,$endtime) = @_;
708: my ($startform,$endform)=&setup_date_selectors($starttime,$endtime);
709: my $dateDefault = '<nobr>'.
710: '<input type="checkbox" name="makedatesdefault" />'.
711: ' make these dates the default for future enrollment';
712: my $perpetual = '<nobr><input type="checkbox" name="no_end_date"';
713: if (defined($endtime) && $endtime == 0) {
714: $perpetual .= ' checked';
715: }
716: $perpetual.= ' />'.' no ending date</nobr>';
717: my $result = '';
718: $result .= "<table>\n";
719: $result .= '<tr><td align="right">Starting Date</td>'.
720: '<td>'.$startform.'</td>'.
721: '<td>'.$dateDefault.'</td>'."</tr>\n";
722: $result .= '<tr><td align="right">Ending Date</td>'.
723: '<td>'.$endform.'</td>'.
724: '<td>'.$perpetual.'</td>'."</tr>\n";
725: $result .= "</table>\n";
726: return $result;
727: }
728:
729: sub make_dates_default {
730: my ($startdate,$enddate) = @_;
731: my $result = '';
732: my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
733: my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
734: my $put_result = &Apache::lonnet::put('environment',
735: {'default_enrollment_start_date'=>$startdate,
736: 'default_enrollment_end_date' =>$enddate},$dom,$crs);
737: if ($put_result eq 'ok') {
738: $result .= "Set default start and end dates for course<br />";
739: #
740: # Refresh the course environment
741: &Apache::lonnet::coursedescription($ENV{'request.course.id'});
742: } else {
743: $result .= "Unable to set default dates for course:".$put_result.
744: '<br />';
745: }
746: return $result;
747: }
748:
749: ##
750: ## Single student enrollment routines (some of them)
751: ##
752: sub get_student_username_domain_form {
753: my $r = shift;
754: my $domform = &Apache::loncommon::select_dom_form
755: ($ENV{'course.'.$ENV{'request.course.id'}.'.domain'},'cudomain',0);
756: $r->print(<<END);
757: <input type="hidden" name="action" value="enrollstudent" />
758: <input type="hidden" name="state" value="gotusername" />
759: <h3>Enroll One Student</h3>
760: <table>
761: <tr><th>Username:</th>
762: <td><input type="text" name="cuname" size="15" /></td></tr>
763: <tr><th>Domain:</th>
764: <td>$domform</td></tr>
765: <tr><th> </th>
766: <td>
767: <input type="submit" name="Begin Enrollment" value="Begin Enrollment" />
768: </td></tr>
769: </table>
770: END
771: return;
772: }
773:
774: sub print_enroll_single_student_form {
775: my $r=shift;
776: $r->print("<h3>Enroll One Student</h3>");
777: #
778: my $username = $ENV{'form.cuname'};
779: my $domain = $ENV{'form.cudomain'};
780: my $home = &Apache::lonnet::homeserver($username,$domain);
781: # $new_user flags whether we are creating a new user or using an old one
782: my $new_user = 1;
783: if ($home ne 'no_host') {
784: $new_user = 0;
785: }
786: #
787: my $user_data_html = '';
788: my $javascript_validations = '';
789: if ($new_user) {
790: my $defdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
791: # Set up authentication forms
792: my ($krbdef,$krbdefdom) =
793: &Apache::loncommon::get_kerberos_defaults($domain);
794: $javascript_validations=&javascript_validations('auth',$krbdefdom);
795: my %param = ( formname => 'document.studentform',
796: kerb_def_dom => $krbdefdom,
797: kerb_def_auth => $krbdef
798: );
799: my $krbform = &Apache::loncommon::authform_kerberos(%param);
800: my $intform = &Apache::loncommon::authform_internal(%param);
801: my $locform = &Apache::loncommon::authform_local(%param);
802: #
803: # Set up domain selection form
804: my $homeserver_form = '';
805: my %servers = &Apache::loncommon::get_library_servers($domain);
806: $homeserver_form = '<select name="lcserver" size="1">'."\n".
807: '<option value="default" selected>default</option>'."\n";
808: while (my ($servername,$serverdescription) = each (%servers)) {
809: $homeserver_form .= '<option value="'.$servername.'">'.
810: $serverdescription."</option>\n";
811: }
812: $homeserver_form .= "</select>\n";
813: #
814: #
815: $user_data_html = <<END;
816: <h3>User Data for $username\@$domain</h3>
817: <table>
818: <tr><th>First Name:</th>
819: <td><input type="text" name="cfirst" size="15"></td></tr>
820: <tr><th>Middle Name:</th>
821: <td><input type="text" name="cmiddle" size="15"></td></tr>
822: <tr><th>Last Name:</th>
823: <td><input type="text" name="clast" size="15"></td></tr>
824: <tr><th>Generation:</th>
825: <td><input type="text" name="cgen" size="5"> </td></tr>
826: <tr><th>Home Server:</th>
827: <td>$homeserver_form</td></tr>
828: </table>
829: <h3>Password</h3>
830: Please select an authentication mechanism
831: <table>
832: <p>
833: $krbform
834: <br />
835: $intform
836: <br />
837: $locform
838: </p>
839: END
840: } else {
841: # User already exists. Do not worry about authentication
842: my %uenv = &Apache::lonnet::dump('environment',$domain,$username);
843: $javascript_validations = &javascript_validations('noauth');
844: $user_data_html = <<END;
845: <h3>User Data for $username\@$domain</h3>
846: <input type="hidden" name="lcserver" value="default" />
847: <table>
848: <tr><th>First Name:</th>
849: <td>
850: <input type="text" name="cfirst" value="$uenv{'firstname'}" size="15" />
851: </td></tr>
852: <tr><th>Middle Name:</th>
853: <td>
854: <input type="text" name="cmiddle" value="$uenv{'middlename'}" size="15" />
855: </td></tr>
856: <tr><th>Last Name:</th>
857: <td>
858: <input type="text" name="clast"value="$uenv{'lastname'}" size="15" />
859: </td></tr>
860: <tr><th>Generation:</th>
861: <td>
862: <input type="text" name="cgen" value="$uenv{'generation'}" size="5" />
863: </td></tr>
864: </table>
865: END
866: }
867: my $date_table = &date_setting_table();
868: # Print it all out
869: $r->print(<<END);
870: <input type="hidden" name="action" value="enrollstudent" />
871: <input type="hidden" name="state" value="done" />
872: <input type="hidden" name="cuname" value="$username" />
873: <input type="hidden" name="lcdomain" value="$domain" />
874: <script type="text/javascript" language="Javascript">
875: function verify(vf) {
876: var founduname=0;
877: var foundpwd=0;
878: var foundname=0;
879: var foundid=0;
880: var foundsec=0;
881: var tw;
882: if ((typeof(vf.cuname.value) !="undefined") && (vf.cuname.value!='') &&
883: (typeof(vf.lcdomain.value)!="undefined") && (vf.lcdomain.value!='')) {
884: founduname=1;
885: }
886: if ((typeof(vf.cfirst.value)!="undefined") && (vf.cfirst.value!='') &&
887: (typeof(vf.clast.value) !="undefined") && (vf.clast.value!='')) {
888: foundname=1;
889: }
890: if ((typeof(vf.csec.value)!="undefined") && (vf.csec.value!='')) {
891: foundsec=1;
892: }
893: if ((typeof(vf.cstid.value)!="undefined") && (vf.cstid.value!='')) {
894: foundid=1;
895: }
896: if (founduname==0) {
897: alert('You need to specify at least the username and domain fields');
898: return;
899: }
900: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
901: }
902:
903: $javascript_validations
904:
905: function clearpwd(vf) {
906: //nothing else needs clearing
907: }
908:
909: </script>
910:
911: $user_data_html
912:
913: <h3>Course Data</h3>
914:
915: <p>Group/Section: <input type="text" name="csec" size="5" />
916: <p>
917: $date_table
918: </p>
919: <h3>ID/Student Number</h3>
920: <p>
921: ID/Student Number: <input type="text" name="cstid" size="10">
922: </p><p>
923: <input type="checkbox" name="forceid" value="yes">
924: Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
925: (only do if you know what you are doing)
926: </p><p>
927: <input type="button" onClick="verify(this.form)" value="Enroll as student">
928: </p>
929: END
930: return;
931: }
932:
933: # ========================================================= Menu Phase Two Drop
934: sub print_drop_menu {
935: my $r=shift;
936: $r->print("<h3>Drop Students</h3>");
937: my $cid=$ENV{'request.course.id'};
938: my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
939: if (! defined($classlist)) {
940: $r->print("There are no students currently enrolled.\n");
941: return;
942: }
943: # Print out the available choices
944: &show_drop_list($r,$classlist,$keylist);
945: return;
946: }
947:
948: # ============================================== view classlist
949: sub print_html_classlist {
950: my $r=shift;
951: if (! exists($ENV{'form.sortby'})) {
952: $ENV{'form.sortby'} = 'username';
953: }
954: if ($ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) {
955: $ENV{'form.Status'} = 'Active';
956: }
957: my $status_select = &Apache::lonhtmlcommon::StatusOptions
958: ($ENV{'form.Status'},'studentform');
959: $r->print(<<END);
960: <input type="hidden" name="action" value="$ENV{'form.action'}" />
961: <input type="hidden" name="state" value="" />
962: <p>
963: <font size="+1">Current Class List</font>
964:
965: END
966: if ($ENV{'form.action'} ne 'modifystudent') {
967: $r->print(<<END);
968: <font size="+1">
969: <a href="javascript:document.studentform.state.value='csv';document.studentform.submit();">CSV format</a>
970:
971: <a href="javascript:document.studentform.state.value='excel';document.studentform.submit();">Excel format</a>
972: </font>
973:
974: Student Status:
975: END
976: }
977: $r->print($status_select."</p>\n");
978: my $cid=$ENV{'request.course.id'};
979: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
980: if (! defined($classlist)) {
981: $r->print("There are no students currently enrolled.\n");
982: } else {
983: # Print out the available choices
984: if ($ENV{'form.action'} eq 'modifystudent') {
985: &show_class_list($r,'view','modify','modifystudent',
986: $ENV{'form.Status'},$classlist,$keylist);
987: } else {
988: &show_class_list($r,'view','aboutme','classlist',
989: $ENV{'form.Status'},$classlist,$keylist);
990: }
991: }
992: }
993:
994: # ============================================== view classlist
995: sub print_formatted_classlist {
996: my $r=shift;
997: my $mode = shift;
998: my $cid=$ENV{'request.course.id'};
999: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
1000: if (! defined($classlist)) {
1001: $r->print("There are no students currently enrolled.\n");
1002: } else {
1003: &show_class_list($r,$mode,'nolink','csv',
1004: $ENV{'form.Status'},$classlist,$keylist);
1005: }
1006: }
1007:
1008: # =================================================== Show student list to drop
1009: sub show_class_list {
1010: my ($r,$mode,$linkto,$action,$statusmode,$classlist,$keylist)=@_;
1011: my $cid=$ENV{'request.course.id'};
1012: #
1013: # Variables for excel output
1014: my ($excel_workbook, $excel_sheet, $excel_filename,$row);
1015: #
1016: my $sortby = $ENV{'form.sortby'};
1017: if ($sortby !~ /^(username|domain|section|fullname|id)$/) {
1018: $sortby = 'username';
1019: }
1020: # Print out header
1021: if ($mode eq 'view') {
1022: if ($linkto eq 'aboutme') {
1023: $r->print('Select a user name to view the users personal page.');
1024: } elsif ($linkto eq 'modify') {
1025: $r->print('Select a user name to modify the students information');
1026: }
1027: $r->print(<<END);
1028:
1029: <input type="hidden" name="sortby" value="$sortby" />
1030: <input type="hidden" name="sname" value="" />
1031: <input type="hidden" name="sdom" value="" />
1032: <p>
1033: <table border=2>
1034: <tr><th>
1035: <a href="javascript:document.studentform.sortby.value='username';document.studentform.submit();">username</a>
1036: </th><th>
1037: <a href="javascript:document.studentform.sortby.value='domain';document.studentform.submit();">domain</a>
1038: </th><th>
1039: <a href="javascript:document.studentform.sortby.value='id';document.studentform.submit();">ID</a>
1040: </th><th>
1041: <a href="javascript:document.studentform.sortby.value='fullname';document.studentform.submit();">student name</a>
1042: </th><th>
1043: <a href="javascript:document.studentform.sortby.value='section';document.studentform.submit();">section</a>
1044: </th>
1045: </tr>
1046: END
1047: } elsif ($mode eq 'csv') {
1048: if($statusmode eq 'Expired') {
1049: $r->print('"Students with expired roles"');
1050: }
1051: if ($statusmode eq 'Any') {
1052: $r->print('"'.join('","',("username","domain","ID","student name",
1053: "section","status")).'"'."\n");
1054: } else {
1055: $r->print('"'.join('","',("username","domain","ID","student name",
1056: "section")).'"'."\n");
1057: }
1058: } elsif ($mode eq 'excel') {
1059: # Create the excel spreadsheet
1060: $excel_filename = '/prtspool/'.
1061: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
1062: time.'_'.rand(1000000000).'.xls';
1063: $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.
1064: $excel_filename);
1065: $excel_workbook->set_tempdir('/home/httpd/perl/tmp');
1066: $excel_sheet = $excel_workbook->addworksheet('classlist');
1067: #
1068: my $description = 'Class List for '.
1069: $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
1070: $excel_sheet->write($row++,0,$description);
1071: #
1072: $excel_sheet->write($row++,0,["username","domain","ID",
1073: "student name","section","status"]);
1074: }
1075: #
1076: # Sort the students
1077: my %index;
1078: my $i;
1079: foreach (@$keylist) {
1080: $index{$_} = $i++;
1081: }
1082: my $index = $index{$sortby};
1083: my $second = $index{'username'};
1084: my $third = $index{'domain'};
1085: my @Sorted_Students = sort {
1086: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
1087: ||
1088: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
1089: ||
1090: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
1091: } (keys(%$classlist));
1092: foreach my $student (@Sorted_Students) {
1093: my $username = $classlist->{$student}->[$index{'username'}];
1094: my $domain = $classlist->{$student}->[$index{'domain'}];
1095: my $section = $classlist->{$student}->[$index{'section'}];
1096: my $name = $classlist->{$student}->[$index{'fullname'}];
1097: my $id = $classlist->{$student}->[$index{'id'}];
1098: my $status = $classlist->{$student}->[$index{'status'}];
1099: next if (($statusmode ne 'Any') && ($status ne $statusmode));
1100: if ($mode eq 'view') {
1101: $r->print("<tr>\n <td>\n ");
1102: if ($linkto eq 'nothing') {
1103: $r->print($username);
1104: } elsif ($linkto eq 'aboutme') {
1105: $r->print(&Apache::loncommon::aboutmewrapper($username,
1106: $username,
1107: $domain));
1108: } elsif ($linkto eq 'modify') {
1109: $r->print('<a href="'.
1110: "javascript:document.studentform.sname.value='".
1111: $username.
1112: "';document.studentform.sdom.value='".$domain.
1113: "';document.studentform.state.value='selected".
1114: "';document.studentform.submit();".'">'.
1115: $username."</a>\n");
1116: }
1117: $r->print(<<"END");
1118: </td>
1119: <td>$domain</td>
1120: <td>$id</td>
1121: <td>$name</td>
1122: <td>$section</td>
1123: </tr>
1124: END
1125: } elsif ($mode eq 'csv') {
1126: # no need to bother with $linkto
1127: my @line = ();
1128: foreach ($username,$domain,$id,$name,$section) {
1129: push @line,&Apache::loncommon::csv_translate($_);
1130: }
1131: if ($statusmode eq 'Any') {
1132: push @line,&Apache::loncommon::csv_translate($status);
1133: }
1134: my $tmp = $";
1135: $" = '","';
1136: $r->print("\"@line\"\n");
1137: $" = $tmp;
1138: } elsif ($mode eq 'excel') {
1139: $excel_sheet->write($row++,0,[$username,$domain,$id,
1140: $name,$section,$status]);
1141: }
1142: }
1143: if ($mode eq 'view') {
1144: $r->print('</table><br>');
1145: } elsif ($mode eq 'excel') {
1146: $excel_workbook->close();
1147: $r->print('<p><a href="'.$excel_filename.'">'.
1148: 'Your Excel spreadsheet</a> is ready for download.</p>'."\n");
1149: }
1150: }
1151:
1152:
1153: #
1154: # print out form for modification of a single students data
1155: #
1156: sub print_modify_student_form {
1157: my $r = shift();
1158: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1159: ['sdom','sname']);
1160: my $sname = $ENV{'form.sname'};
1161: my $sdom = $ENV{'form.sdom'};
1162: my $sortby = $ENV{'form.sortby'};
1163: # determine the students name information
1164: my %info=&Apache::lonnet::get('environment',
1165: ['firstname','middlename',
1166: 'lastname','generation','id'],
1167: $sdom, $sname);
1168: my ($tmp) = keys(%info);
1169: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1170: $r->print('<font color="#ff0000" size="+2">Error</font>'.
1171: '<p>'.
1172: 'Unable to retrieve environment data for '.$sname.
1173: 'in domain '.$sdom.'</p><p>'.
1174: 'Please contact your LON-CAPA administrator '.
1175: 'regarding this situation.</p></body></html>');
1176: return;
1177: }
1178: # determine the students starting and ending times and section
1179: my ($starttime,$endtime,$section) = &get_enrollment_data($sname,$sdom);
1180: if ($starttime =~ /^error/) {
1181: $r->print('<h2>Error</h2>');
1182: $r->print('<p>'.$starttime.'</p>');
1183: return;
1184: }
1185: # Deal with date forms
1186: my $date_table = &date_setting_table($starttime,$endtime);
1187: #
1188: if (! exists($ENV{'form.Status'}) ||
1189: $ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) {
1190: $ENV{'form.Status'} = 'crap';
1191: }
1192: # Make sure student is enrolled in course
1193: $r->print(<<END);
1194: <p>
1195: <font size="+1">
1196: Only domain coordinators can change a users password.
1197: </font>
1198: </p>
1199: <input type="hidden" name="slogin" value="$sname" />
1200: <input type="hidden" name="sdomain" value="$sdom" />
1201: <input type="hidden" name="action" value="modifystudent" />
1202: <input type="hidden" name="state" value="done" />
1203: <input type="hidden" name="sortby" value="$sortby" />
1204: <input type="hidden" name="Status" value="$ENV{'form.Status'}" />
1205:
1206: <h2>Modify Enrollment for $info{'firstname'} $info{'middlename'}
1207: $info{'lastname'} $info{'generation'}, $sname\@$sdom</h2>
1208: <p>
1209: <b>Student Name</b>
1210: <table>
1211: <tr><th>First</th><th>Middle</th><th>Last</th><th>Generation</th></tr>
1212: <tr><td>
1213: <input type="text" name="firstname" value="$info{'firstname'}" /></td><td>
1214: <input type="text" name="middlename" value="$info{'middlename'}" /></td><td>
1215: <input type="text" name="lastname" value="$info{'lastname'}" /></td><td>
1216: <input type="text" name="generation" value="$info{'generation'}" /></td></tr>
1217: </table>
1218: </p><p>
1219: <b>Student ID</b>: <input type="text" name="id" value="$info{'id'}" size="12"/>
1220: </p><p>
1221: <input type="checkbox" name="forceid" >
1222: Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
1223: (only do if you know what you are doing)
1224: </p><p>
1225: <b>Section</b>: <input type="text" name="section" value="$section" size="4"/>
1226: </p>
1227: <p>$date_table</p>
1228: <input type="submit" value="Submit Modifications" />
1229: </body></html>
1230: END
1231: return;
1232: }
1233:
1234: #
1235: # modify a single students section
1236: #
1237: sub modify_single_student {
1238: my $r = shift;
1239: #
1240: # Remove non alphanumeric values from the section
1241: $ENV{'form.section'} =~ s/\W//g;
1242: #
1243: # Do the date defaults first
1244: my ($starttime,$endtime) = &get_dates_from_form();
1245: if ($ENV{'form.makedatesdefault'}) {
1246: $r->print(&make_dates_default($starttime,$endtime));
1247: }
1248: # Get the 'sortby' and 'Status' variables so the user goes back to their
1249: # previous screen
1250: my $sortby = $ENV{'form.sortby'};
1251: my $status = $ENV{'form.Status'};
1252: #
1253: # We always need this information
1254: my $slogin = $ENV{'form.slogin'};
1255: my $sdom = $ENV{'form.sdomain'};
1256: #
1257: # Get the old data
1258: my %old=&Apache::lonnet::get('environment',
1259: ['firstname','middlename',
1260: 'lastname','generation','id'],
1261: $sdom, $slogin);
1262: $old{'section'} = &Apache::lonnet::getsection($sdom,$slogin,
1263: $ENV{'request.course.id'});
1264: my ($tmp) = keys(%old);
1265: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1266: $r->print("There was an error determining the environment values ".
1267: " for $slogin \@ $sdom.");
1268: return;
1269: }
1270: undef $tmp;
1271: #
1272: # Get the new data
1273: my $firstname = $ENV{'form.firstname'};
1274: my $middlename = $ENV{'form.middlename'};
1275: my $lastname = $ENV{'form.lastname'};
1276: my $generation = $ENV{'form.generation'};
1277: my $section = $ENV{'form.section'};
1278: my $courseid = $ENV{'request.course.id'};
1279: my $sid = $ENV{'form.id'};
1280: my $displayable_starttime = localtime($starttime);
1281: my $displayable_endtime = localtime($endtime);
1282: #
1283: # check for forceid override
1284: if ((defined($old{'id'})) && ($old{'id'} ne '') &&
1285: ($sid ne $old{'id'}) && (! exists($ENV{'form.forceid'}))) {
1286: $r->print("<font color=\"ff0000\">You changed the students id ".
1287: " but did not disable the ID change safeguard.".
1288: " The students id will not be changed.</font>");
1289: $sid = $old{'id'};
1290: }
1291: #
1292: # talk to the user about what we are going to do
1293: $r->print(<<END);
1294: <h2>Modifying data for user $slogin \@ $sdom </h2>
1295: <h3>Student Information</h3>
1296: <table rules="rows" border="1" cellpadding="3" >
1297: <tr>
1298: <th> Field </th>
1299: <th> Old Value </th>
1300: <th> New Value </th>
1301: </tr>
1302: <tr>
1303: <td> <b>First name</b> </td>
1304: <td> $old{'firstname'} </td>
1305: <td> $firstname </td>
1306: </tr><tr>
1307: <td> <b>Middle name</b> </td>
1308: <td> $old{'middlename'} </td>
1309: <td> $middlename </td>
1310: </tr><tr>
1311: <td> <b>Last name</b> </td>
1312: <td> $old{'lastname'} </td>
1313: <td> $lastname </td>
1314: </tr><tr>
1315: <td> <b>Generation</b> </td>
1316: <td> $old{'generation'} </td>
1317: <td> $generation </td>
1318: </tr><tr>
1319: <td> <b>ID</b> </td>
1320: <td> $old{'id'} </td>
1321: <td> $sid </td>
1322: </tr><tr>
1323: <td> <b>Section</b> </td>
1324: <td> $old{'section'} </td>
1325: <td> $section</td>
1326: </tr>
1327: </table>
1328: <h3>Role Information</h3>
1329: <table>
1330: <tr><td align="right"><b>Start Time:</b></td><td> $displayable_starttime </td></tr>
1331: <tr><td align="right"><b>End Time:</b></td><td> $displayable_endtime </td></tr>
1332: </table>
1333: <p>
1334: END
1335: #
1336: # Send request(s) to modify data (final undef is for 'desiredhost',
1337: # which is a moot point because the student already has an account.
1338: my $modify_section_results = &modifystudent($sdom,$slogin,
1339: $ENV{'request.course.id'},
1340: $section,undef);
1341: if ($modify_section_results !~ /^ok/) {
1342: $r->print("An error occured during the attempt to change the ".
1343: "section for this student.<br />");
1344: }
1345: my $roleresults = &Apache::lonnet::modifystudent
1346: ($sdom,$slogin,$sid,undef,undef,$firstname,$middlename,$lastname,
1347: $generation,$section,$endtime,$starttime,$ENV{'form.forceid'});
1348: if ($roleresults eq 'refused' ) {
1349: $r->print("Your request to change the role information for this ".
1350: "student was refused. You do not appear to have ".
1351: "sufficient authority to change student information.");
1352: } elsif ($roleresults !~ /ok/) {
1353: $r->print("An error occurred during the attempt to change the role".
1354: " information for this student. <br />".
1355: "The error reported was ".
1356: $roleresults);
1357: &Apache::lonnet::logthis("londropadd:failed attempt to modify student".
1358: " data for ".$slogin." \@ ".$sdom." by ".
1359: $ENV{'user.name'}." \@ ".$ENV{'user.domain'}.
1360: ":".$roleresults);
1361: } else { # everything is okay!
1362: $r->print("Student information updated successfully. <br />".
1363: "The student must log out and log in again to see ".
1364: "these changes.");
1365: }
1366: $r->print(<<END);
1367: </p><p>
1368: <input type="hidden" name="action" value="modifystudent" />
1369: <input type="hidden" name="sortby" value="$sortby" />
1370: <input type="hidden" name="Status" value="$status" />
1371: <a href="javascript:document.studentform.submit();">Modify another students data</a>
1372: </body></html>
1373: END
1374: return;
1375: }
1376:
1377: sub get_enrollment_data {
1378: my ($sname,$sdomain) = @_;
1379: my $courseid = $ENV{'request.course.id'};
1380: $courseid =~ s:_:/:g;
1381: my %roles = &Apache::lonnet::dump('roles',$sdomain,$sname);
1382: my ($tmp) = keys(%roles);
1383: # Bail out if we were unable to get the students roles
1384: return ('error'.$tmp) if ($tmp =~ /^(con_lost|error|no_such_host)/i);
1385: # Go through the roles looking for enrollment in this course
1386: my ($end,$start) = (undef,undef);
1387: my $section = '';
1388: my $count = scalar(keys(%roles));
1389: while (my ($course,$role) = each(%roles)) {
1390: if ($course=~ /^\/$courseid\/*\s*(\w+)*_st$/ ) {
1391: #
1392: # Get active role
1393: $section=$1;
1394: (undef,$end,$start)=split(/\_/,$role);
1395: my $now=time;
1396: my $notactive=0;
1397: if ($start) {
1398: if ($now<$start) { $notactive=1; }
1399: }
1400: if ($end) {
1401: if ($now>$end) { $notactive=1; }
1402: }
1403: unless ($notactive) { return ($start,$end,$section); }
1404: }
1405: }
1406: return ($start,$end,$section);
1407: }
1408:
1409: #################################################
1410: #################################################
1411:
1412: =pod
1413:
1414: =item show_drop_list
1415:
1416: Display a list of students to drop
1417: Inputs:
1418:
1419: =over 4
1420:
1421: =item $r, Apache request
1422:
1423: =item $classlist, hash pointer returned from loncoursedata::get_classlist();
1424:
1425: =item $keylist, array pointer returned from loncoursedata::get_classlist()
1426: which describes the order elements are stored in the %$classlist values.
1427:
1428: =item $nosort, if true, sorting links are omitted.
1429:
1430: =back
1431:
1432: =cut
1433:
1434: #################################################
1435: #################################################
1436: sub show_drop_list {
1437: my ($r,$classlist,$keylist,$nosort)=@_;
1438: my $cid=$ENV{'request.course.id'};
1439: if (! exists($ENV{'form.sortby'})) {
1440: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1441: ['sortby']);
1442: }
1443: my $sortby = $ENV{'form.sortby'};
1444: if ($sortby !~ /^(username|domain|section|fullname|id)$/) {
1445: $sortby = 'username';
1446: }
1447: #
1448: my $action = "drop";
1449: $r->print(<<END);
1450: <input type="hidden" name="sortby" value="$sortby" />
1451: <input type="hidden" name="action" value="$action" />
1452: <input type="hidden" name="state" value="done" />
1453: <script>
1454: function checkAll(field) {
1455: for (i = 0; i < field.length; i++)
1456: field[i].checked = true ;
1457: }
1458:
1459: function uncheckAll(field) {
1460: for (i = 0; i < field.length; i++)
1461: field[i].checked = false ;
1462: }
1463: </script>
1464: <p>
1465: <input type="hidden" name="phase" value="four">
1466: END
1467:
1468: if ($nosort) {
1469: $r->print(<<END);
1470: <table border=2>
1471: <tr>
1472: <th> </th>
1473: <th>username</th>
1474: <th>domain</th>
1475: <th>ID</th>
1476: <th>student name</th>
1477: <th>section</th>
1478: </tr>
1479: END
1480:
1481: } else {
1482: $r->print(<<END);
1483: <table border=2>
1484: <tr><th> </th>
1485: <th>
1486: <a href="/adm/dropadd?action=$action&sortby=username">username</a>
1487: </th><th>
1488: <a href="/adm/dropadd?action=$action&sortby=domain">domain</a>
1489: </th><th>
1490: <a href="/adm/dropadd?action=$action&sortby=id">ID</a>
1491: </th><th>
1492: <a href="/adm/dropadd?action=$action&sortby=fullname">student name</a>
1493: </th><th>
1494: <a href="/adm/dropadd?action=$action&sortby=section">section</a>
1495: </th>
1496: </tr>
1497: END
1498: }
1499: #
1500: # Sort the students
1501: my %index;
1502: my $i;
1503: foreach (@$keylist) {
1504: $index{$_} = $i++;
1505: }
1506: my $index = $index{$sortby};
1507: my $second = $index{'username'};
1508: my $third = $index{'domain'};
1509: my @Sorted_Students = sort {
1510: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
1511: ||
1512: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
1513: ||
1514: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
1515: } (keys(%$classlist));
1516: foreach my $student (@Sorted_Students) {
1517: my $error;
1518: my $username = $classlist->{$student}->[$index{'username'}];
1519: my $domain = $classlist->{$student}->[$index{'domain'}];
1520: my $section = $classlist->{$student}->[$index{'section'}];
1521: my $name = $classlist->{$student}->[$index{'fullname'}];
1522: my $id = $classlist->{$student}->[$index{'id'}];
1523: my $status = $classlist->{$student}->[$index{'status'}];
1524: next if ($status ne 'Active');
1525: #
1526: $r->print(<<"END");
1527: <tr>
1528: <td><input type="checkbox" name="droplist" value="$student"></td>
1529: <td>$username</td>
1530: <td>$domain</td>
1531: <td>$id</td>
1532: <td>$name</td>
1533: <td>$section</td>
1534: </tr>
1535: END
1536: }
1537: $r->print('</table><br>');
1538: $r->print(<<"END");
1539: </p><p>
1540: <input type="button" value="check all" onclick="javascript:checkAll(document.studentform.droplist)">
1541: <input type="button" value="uncheck all" onclick="javascript:uncheckAll(document.studentform.droplist)">
1542: <p><input type=submit value="Drop Students"></p>
1543: END
1544: return;
1545: }
1546:
1547: #
1548: # Print out the initial form to get the courselist file
1549: #
1550: sub print_first_courselist_upload_form {
1551: my $r=shift;
1552: my $str;
1553: $str = '<input type="hidden" name="phase" value="two">';
1554: $str .= '<input type="hidden" name="action" value="upload" />';
1555: $str .= '<input type="hidden" name="state" value="got_file" />';
1556: $str .= "<h3>".&mt('Upload a class list')."</h3>\n";
1557: $str .= &Apache::loncommon::upfile_select_html();
1558: $str .= "<p>\n";
1559: $str .= '<input type="submit" name="fileupload" value="'.
1560: &mt('Upload class list').'">'."\n";
1561: $str .= '<input type="checkbox" name="noFirstLine" /> '.
1562: &mt('Ignore First Line')."</p>\n";
1563: $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List",
1564: "How do I create a class list from a spreadsheet").
1565: "<br />\n";
1566: $str .= &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1567: "How do I create a CSV file from a spreadsheet").
1568: "<br />\n";
1569: $str .= "</body>\n</html>\n";
1570: $r->print($str);
1571: return;
1572: }
1573:
1574: # ================================================= Drop/Add from uploaded file
1575: sub upfile_drop_add {
1576: my $r=shift;
1577: &Apache::loncommon::load_tmp_file($r);
1578: my @studentdata=&Apache::loncommon::upfile_record_sep();
1579: if($ENV{'form.noFirstLine'}){shift(@studentdata);}
1580: my @keyfields = split(/\,/,$ENV{'form.keyfields'});
1581: my $cid = $ENV{'request.course.id'};
1582: my %fields=();
1583: for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
1584: if ($ENV{'form.upfile_associate'} eq 'reverse') {
1585: if ($ENV{'form.f'.$i} ne 'none') {
1586: $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
1587: }
1588: } else {
1589: $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
1590: }
1591: }
1592: #
1593: my ($startdate,$enddate) = &get_dates_from_form();
1594: if ($ENV{'form.makedatesdefault'}) {
1595: $r->print(&make_dates_default($startdate,$enddate));
1596: }
1597: # Determine domain and desired host (home server)
1598: my $domain=$ENV{'form.lcdomain'};
1599: my $desiredhost = $ENV{'form.lcserver'};
1600: if (lc($desiredhost) eq 'default') {
1601: $desiredhost = undef;
1602: } else {
1603: my %home_servers = &Apache::loncommon::get_library_servers($domain);
1604: if (! exists($home_servers{$desiredhost})) {
1605: $r->print('<font color="#ff0000">'.&mt('Error').'</font>'.
1606: &mt('Invalid home server specified'));
1607: $r->print("</body>\n</html>\n");
1608: return;
1609: }
1610: }
1611: # Determine authentication mechanism
1612: my $amode = '';
1613: my $genpwd = '';
1614: if ($ENV{'form.login'} eq 'krb') {
1615: $amode='krb';
1616: $amode.=$ENV{'form.krbver'};
1617: $genpwd=$ENV{'form.krbarg'};
1618: } elsif ($ENV{'form.login'} eq 'int') {
1619: $amode='internal';
1620: if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
1621: $genpwd=$ENV{'form.intarg'};
1622: }
1623: } elsif ($ENV{'form.login'} eq 'loc') {
1624: $amode='localauth';
1625: if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
1626: $genpwd=$ENV{'form.locarg'};
1627: }
1628: }
1629: if ($amode =~ /^krb/) {
1630: if (! defined($genpwd) || $genpwd eq '') {
1631: $r->print('<font color="red" size="+1">'.
1632: &mt('Unable to enroll students').'</font> '.
1633: &mt('No Kerberos domain was specified.').'</p>');
1634: $amode = ''; # This causes the loop below to be skipped
1635: }
1636: }
1637: unless (($domain=~/\W/) || ($amode eq '')) {
1638: #######################################
1639: ## Enroll Students ##
1640: #######################################
1641: $r->print('<h3>'.&mt('Enrolling Students')."</h3>\n<p>\n");
1642: my $count=0;
1643: my $flushc=0;
1644: my %student=();
1645: # Get new classlist
1646: foreach (@studentdata) {
1647: my %entries=&Apache::loncommon::record_sep($_);
1648: # Determine student name
1649: unless (($entries{$fields{'username'}} eq '') ||
1650: (!defined($entries{$fields{'username'}}))) {
1651: my ($fname, $mname, $lname,$gen) = ('','','','');
1652: if (defined($fields{'names'})) {
1653: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
1654: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
1655: } else {
1656: if (defined($fields{'fname'})) {
1657: $fname=$entries{$fields{'fname'}};
1658: }
1659: if (defined($fields{'mname'})) {
1660: $mname=$entries{$fields{'mname'}};
1661: }
1662: if (defined($fields{'lname'})) {
1663: $lname=$entries{$fields{'lname'}};
1664: }
1665: if (defined($fields{'gen'})) {
1666: $gen=$entries{$fields{'gen'}};
1667: }
1668: }
1669: if ($entries{$fields{'username'}}=~/\W/) {
1670: $r->print('<br />'.
1671: &mt('<b>[_1]</b>: Unacceptable username for user [_2] [_3] [_4] [_5]',
1672: $entries{$fields{'username'}},$fname,$mname,$lname,$gen).
1673: '</b>');
1674: } else {
1675: # determine section number
1676: my $sec='';
1677: my $username=$entries{$fields{'username'}};
1678: if (defined($fields{'sec'})) {
1679: if (defined($entries{$fields{'sec'}})) {
1680: $sec=$entries{$fields{'sec'}};
1681: }
1682: }
1683: # remove non alphanumeric values from section
1684: $sec =~ s/\W//g;
1685: # determine student id number
1686: my $id='';
1687: if (defined($fields{'id'})) {
1688: if (defined($entries{$fields{'id'}})) {
1689: $id=$entries{$fields{'id'}};
1690: }
1691: $id=~tr/A-Z/a-z/;
1692: }
1693: # determine email address
1694: my $email='';
1695: if (defined($fields{'email'})) {
1696: if (defined($entries{$fields{'email'}})) {
1697: $email=$entries{$fields{'email'}};
1698: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
1699: }
1700: }
1701: # determine student password
1702: my $password='';
1703: if ($genpwd) {
1704: $password=$genpwd;
1705: } else {
1706: if (defined($fields{'ipwd'})) {
1707: if ($entries{$fields{'ipwd'}}) {
1708: $password=$entries{$fields{'ipwd'}};
1709: }
1710: }
1711: }
1712: # Clean up whitespace
1713: foreach (\$domain,\$username,\$id,\$fname,\$mname,
1714: \$lname,\$gen,\$sec) {
1715: $$_ =~ s/(\s+$|^\s+)//g;
1716: }
1717: if ($password || $ENV{'form.login'} eq 'loc') {
1718: &modifystudent($domain,$username,$cid,$sec,
1719: $desiredhost);
1720: my $reply=&Apache::lonnet::modifystudent
1721: ($domain,$username,$id,$amode,$password,
1722: $fname,$mname,$lname,$gen,$sec,$enddate,
1723: $startdate,$ENV{'form.forceid'},$desiredhost,
1724: $email);
1725: if ($reply ne 'ok') {
1726: $reply =~ s/^error://;
1727: $r->print('<br />'.
1728: &mt('<b>[_1]</b>: Unable to enroll: [_2]',$username,$reply));
1729: } else {
1730: $count++; $flushc++;
1731: $student{$username}=1;
1732: $r->print('. ');
1733: if ($flushc>15) {
1734: $r->rflush;
1735: $flushc=0;
1736: }
1737: }
1738: } else {
1739: $r->print('<br />'.
1740: &mt('<b>[_1]</b>: Unable to enroll. No password specified.',$username)
1741: );
1742: }
1743: }
1744: }
1745: } # end of foreach (@studentdata)
1746: $r->print("</p>\n<p>\n".&mt('Processed [_1] student(s).',$count).
1747: "</p>\n");
1748: $r->print("<p>\n".
1749: &mt('If active, the new role will be available when the '.
1750: 'students next log in to LON-CAPA.')."</p>\n");
1751: #####################################
1752: # Drop students #
1753: #####################################
1754: if ($ENV{'form.fullup'} eq 'yes') {
1755: $r->print('<h3>'.&mt('Dropping Students')."</h3>\n");
1756: # Get current classlist
1757: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
1758: if (! defined($classlist)) {
1759: $r->print(&mt('There are no students currently enrolled.').
1760: "\n");
1761: } else {
1762: # Remove the students we just added from the list of students.
1763: foreach (@studentdata) {
1764: my %entries=&Apache::loncommon::record_sep($_);
1765: unless (($entries{$fields{'username'}} eq '') ||
1766: (!defined($entries{$fields{'username'}}))) {
1767: delete($classlist->{$entries{$fields{'username'}}.
1768: ':'.$domain});
1769: }
1770: }
1771: # Print out list of dropped students.
1772: &show_drop_list($r,$classlist,$keylist,'nosort');
1773: }
1774: }
1775: } # end of unless
1776: }
1777:
1778: # ================================================================== Phase four
1779: sub drop_student_list {
1780: my $r=shift;
1781: my $count=0;
1782: my @droplist;
1783: if (ref($ENV{'form.droplist'})) {
1784: @droplist = @{$ENV{'form.droplist'}};
1785: } else {
1786: @droplist = ($ENV{'form.droplist'});
1787: }
1788: foreach (@droplist) {
1789: my ($uname,$udom)=split(/\:/,$_);
1790: # drop student
1791: my $result = &modifystudent($udom,$uname,$ENV{'request.course.id'});
1792: if ($result eq 'ok' || $result eq 'ok:') {
1793: $r->print(&mt('Dropped [_1]',$uname.'@'.$udom).'<br>');
1794: $count++;
1795: } else {
1796: $r->print(
1797: &mt('Error dropping [_1]:[_2]',$uname.'@'.$udom,$result).
1798: '<br />');
1799: }
1800: }
1801: $r->print('<p><b>'.&mt('Dropped [_1] student(s).',$count).'</b></p>');
1802: $r->print('<p>'.&mt('Re-enrollment will re-activate data.')) if ($count);
1803: }
1804:
1805: ###################################################################
1806: ###################################################################
1807:
1808: =pod
1809:
1810: =item &handler
1811:
1812: The typical handler you see in all these modules. Takes $r, the
1813: http request, as an argument.
1814:
1815: The response to the request is governed by two form variables
1816:
1817: form.action form.state response
1818: ---------------------------------------------------
1819: undefined undefined print main menu
1820: upload undefined print courselist upload menu
1821: upload got_file deal with uploaded file,
1822: print the upload managing menu
1823: upload enrolling enroll students based on upload
1824: drop undefined print the classlist ready to drop
1825: drop done drop the selected students
1826: enrollstudent undefined print student username domain form
1827: enrollstudent gotusername print single student enroll menu
1828: enrollstudent enrolling enroll student
1829: classlist undefined print html classlist
1830: classlist csv print csv classlist
1831: modifystudent undefined print classlist to select student to modify
1832: modifystudent selected print modify student menu
1833: modifystudent done make modifications to student record
1834:
1835: =cut
1836:
1837: ###################################################################
1838: ###################################################################
1839: sub handler {
1840: my $r=shift;
1841: if ($r->header_only) {
1842: &Apache::loncommon::content_type($r,'text/html');
1843: $r->send_http_header;
1844: return OK;
1845: }
1846: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1847: ['action','state']);
1848: # Needs to be in a course
1849: if (! (($ENV{'request.course.fn'}) &&
1850: (&Apache::lonnet::allowed('cst',$ENV{'request.course.id'})))) {
1851: # Not in a course, or not allowed to modify parms
1852: $ENV{'user.error.msg'}=
1853: "/adm/dropadd:cst:0:0:Cannot drop or add students";
1854: return HTTP_NOT_ACCEPTABLE;
1855: }
1856: #
1857: # Only output the header information if they did not request csv format
1858: #
1859: if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) {
1860: $r->content_type('text/csv');
1861: } else {
1862: # Start page
1863: &Apache::loncommon::content_type($r,'text/html');
1864: $r->send_http_header;
1865: $r->print(&header());
1866: }
1867: #
1868: # Main switch on form.action and form.state, as appropriate
1869: if (! exists($ENV{'form.action'})) {
1870: &print_main_menu($r);
1871: } elsif ($ENV{'form.action'} eq 'upload') {
1872: if (! exists($ENV{'form.state'})) {
1873: &print_first_courselist_upload_form($r);
1874: } elsif ($ENV{'form.state'} eq 'got_file') {
1875: &print_upload_manager_form($r);
1876: } elsif ($ENV{'form.state'} eq 'enrolling') {
1877: if ($ENV{'form.datatoken'}) {
1878: &upfile_drop_add($r);
1879: } else {
1880: # Hmmm, this is an error
1881: }
1882: } else {
1883: &print_first_courselist_upload_form($r);
1884: }
1885: } elsif ($ENV{'form.action'} eq 'drop') {
1886: if (! exists($ENV{'form.state'})) {
1887: &print_drop_menu($r);
1888: } elsif ($ENV{'form.state'} eq 'done') {
1889: &drop_student_list($r);
1890: } else {
1891: &print_drop_menu($r);
1892: }
1893: } elsif ($ENV{'form.action'} eq 'enrollstudent') {
1894: if (! exists($ENV{'form.state'})) {
1895: &get_student_username_domain_form($r);
1896: } elsif ($ENV{'form.state'} eq 'gotusername') {
1897: &print_enroll_single_student_form($r);
1898: } elsif ($ENV{'form.state'} eq 'enrolling') {
1899: &enroll_single_student($r);
1900: } else {
1901: &get_student_username_domain_form($r);
1902: }
1903: } elsif ($ENV{'form.action'} eq 'classlist') {
1904: if (! exists($ENV{'form.state'})) {
1905: &print_html_classlist($r);
1906: } elsif ($ENV{'form.state'} eq 'csv') {
1907: &print_formatted_classlist($r,'csv');
1908: } elsif ($ENV{'form.state'} eq 'excel') {
1909: &print_formatted_classlist($r,'excel');
1910: } else {
1911: &print_html_classlist($r);
1912: }
1913: } elsif ($ENV{'form.action'} eq 'modifystudent') {
1914: if (! exists($ENV{'form.state'})) {
1915: &print_html_classlist($r);
1916: } elsif ($ENV{'form.state'} eq 'selected') {
1917: &print_modify_student_form($r);
1918: } elsif ($ENV{'form.state'} eq 'done') {
1919: &modify_single_student($r);
1920: } else {
1921: &print_html_classlist($r);
1922: }
1923: } else {
1924: # We should not end up here, but I guess it is possible
1925: &Apache::lonnet::logthis("Undetermined state in londropadd.pm. ".
1926: "form.action = ".$ENV{'form.action'}.
1927: "Someone should fix this.");
1928: &print_main_menu($r);
1929: }
1930: #
1931: # Finish up
1932: if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) {
1933: $r->print("\n");
1934: } else {
1935: $r->print('</form></body></html>');
1936: }
1937: return OK;
1938: }
1939:
1940: ###################################################################
1941: ###################################################################
1942:
1943: 1;
1944: __END__
1945:
1946:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>