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