File:
[LON-CAPA] /
loncom /
interface /
Attic /
londropadd.pm
Revision
1.38:
download - view:
text,
annotated -
select for diffs
Fri May 3 16:30:48 2002 UTC (22 years, 2 months ago) by
matthew
Branches:
MAIN
CVS tags:
HEAD
Fixes BUG 329.
Changed 'ERROR: $error' to "ERROR: $error".
Previously the check for an error was independent of the display of the list
of students to drop. Now any error in retrieving the list of students will
prevent the drop list from being displayed.
1: # The LearningOnline Network with CAPA
2: # Handler to drop and add students in courses
3: #
4: # $Id: londropadd.pm,v 1.38 2002/05/03 16:30:48 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: # YEAR=2000
35: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
36: #
37: # 10/11,10/12,10/16 Gerd Kortemeyer)
38: #
39: # 11/20,11/21,11/22,11/23,11/24,11/25,11/27,11/28,
40: # 12/08,12/12 Gerd Kortemeyer)
41: #
42: # 12/26,12/27,12/28,
43: # YEAR=2001
44: # 01/01/01,01/15,02/10,02/13,02/14,02/22 Gerd Kortemeyer
45: # 8/6 Scott Harrison
46: # Guy Albertelli
47: # 9/25 Gerd Kortemeyer
48: # 12/19 Guy Albertelli
49: # YEAR=2002
50: # 1/4 Gerd Kortemeyer
51:
52: package Apache::londropadd;
53:
54: use strict;
55: use Apache::lonnet();
56: use Apache::loncommon();
57: use Apache::Constants qw(:common :http REDIRECT);
58:
59: # ================================================================ Print header
60:
61: sub header {
62: return(<<ENDHEAD);
63: <html>
64: <head>
65: <title>LON-CAPA Student Drop/Add</title>
66: </head>
67: <body bgcolor="#FFFFFF">
68: <img align=right src=/adm/lonIcons/lonlogos.gif>
69: <h1>Drop/Add Students</h1>
70: <form method="post" enctype="multipart/form-data"
71: action="/adm/dropadd" name="studentform">
72: <h2>Course: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}</h2>
73: ENDHEAD
74: }
75:
76: # =========== Drop student from all sections of a course, except optional $csec
77: sub modifystudent {
78: my ($udom,$unam,$courseid,$csec,$desiredhost)=@_;
79: # if $csec is undefined, drop the student from all the courses matching
80: # this one. If $csec is defined, drop them from all other sections of
81: # this course and add them to section $csec
82: $courseid=~s/\_/\//g;
83: $courseid=~s/^(\w)/\/$1/;
84: my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
85: my ($tmp) = keys(%roles);
86: # Bail out if we were unable to get the students roles
87: return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
88: # Go through the roles looking for enrollment in this course
89: my $result = '';
90: foreach my $course (keys(%roles)) {
91: if ($course=~/^$courseid(?:\/)*(?:\s+)*(\w+)*\_st$/) {
92: # We are in this course
93: my $section=$1;
94: $section='' if ($course eq $courseid.'_st');
95: if ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
96: my (undef,$end,$start)=split(/\_/,$roles{$course});
97: my $now=time;
98: if (!($start && ($now<$start)) || !($end && ($now>$end))) {
99: my $reply=&Apache::lonnet::modifystudent
100: ($udom,$unam,'','','','','','','',
101: $section,time,undef,undef,$desiredhost);
102: $result .= $reply.':';
103: }
104: }
105: }
106: }
107: if ($result eq '') {
108: $result eq 'Unable to find section for this student';
109: } else {
110: $result =~ s/(ok:)+/ok/g;
111: }
112: return $result;
113: }
114:
115: # ============ build a domain and server selection form
116: sub domain_form {
117: my ($defdom) = @_;
118: # Set up domain and server selection forms
119: #
120: # Get the domains
121: my @domains = &Apache::loncommon::get_domains();
122: # build up the menu information to be passed to
123: # &Apache::loncommon::linked_select_forms
124: my %select_menus;
125: foreach my $dom (@domains) {
126: # set up the text for this domain
127: $select_menus{$dom}->{'text'}= $dom;
128: # we want a choice of 'default' as the default in the second menu
129: $select_menus{$dom}->{'default'}= 'default';
130: $select_menus{$dom}->{'select2'}->{'default'} = 'default';
131: # Now build up the other items in the second menu
132: my %servers = &Apache::loncommon::get_home_servers($dom);
133: foreach my $server (keys(%servers)) {
134: $select_menus{$dom}->{'select2'}->{$server}
135: = "$server $servers{$server}";
136: }
137: }
138: my $result = &Apache::loncommon::linked_select_forms
139: ('studentform',' with home server ',$defdom,
140: 'lcdomain','lcserver',\%select_menus);
141: return $result;
142: }
143:
144: # ============================================================== Menu Phase One
145: sub menu_phase_one {
146: my $r=shift;
147: my $upfile_select=&Apache::loncommon::upfile_select_html();
148: $r->print(<<ENDUPFORM);
149: <input type=hidden name=phase value=two>
150: <hr>
151: <h3>Upload a courselist</h3>
152: $upfile_select
153: <p><input type=submit name=fileupload value="Upload Courselist">
154: <hr>
155: <h3>Enroll a single student</h3>
156: <p><input type=submit name=enroll value="Enroll Student">
157: <hr>
158: <h3>Drop students</h3>
159: <p><input type=submit name=drop value="Selection List">
160: ENDUPFORM
161: }
162:
163: sub phase_two_header {
164: my ($r,$datatoken,$distotal,$krbdefdom)=@_;
165: my $javascript;
166: if ($ENV{'form.upfile_associate'} eq 'reverse') {
167: $javascript=&phase_two_javascript_reverse_associate();
168: } else {
169: $javascript=&phase_two_javascript_forward_associate();
170: }
171: my $javascript_validations=&javascript_validations($krbdefdom);
172: $r->print(<<ENDPICK);
173: <hr>
174: <h3>Identify fields</h3>
175: Total number of records found in file: $distotal <hr />
176: Enter as many fields as you can. The system will inform you and bring you back
177: to this page if the data selected is insufficient to run your class.<hr />
178: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
179: <input type="hidden" name="associate" value="" />
180: <input type="hidden" name="phase" value="three" />
181: <input type="hidden" name="datatoken" value="$datatoken" />
182: <input type="hidden" name="fileupload" value="$ENV{'form.fileupload'}" />
183: <input type="hidden" name="upfiletype" value="$ENV{'form.upfiletype'}" />
184: <input type="hidden" name="upfile_associate"
185: value="$ENV{'form.upfile_associate'}" />
186: <hr />
187: <script type="text/javascript" language="Javascript">
188: $javascript
189: $javascript_validations
190: </script>
191: ENDPICK
192: }
193:
194: sub javascript_validations {
195: my ($krbdefdom)=@_;
196: my %param = ( formname => 'studentform',
197: kerb_def_dom => $krbdefdom );
198: my $authheader = &Apache::loncommon::authform_header(%param);
199: return (<<ENDPICK);
200: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec) {
201: var foundatype=0;
202: var message='';
203: if (founduname==0) {
204: alert('You need to specify the username field');
205: return;
206: }
207: if (current.radiovalue == null || current.radiovalue == 'nochange') {
208: // They did not check any of the login radiobuttons.
209: alert('You must choose an authentication type');
210: return;
211: }
212: foundatype=1;
213: if (current.argfield == null || current.argfield == '') {
214: var alertmsg = '';
215: switch (current.value) {
216: case 'krb':
217: alertmsg = 'You need to specify the Kerberos domain';
218: break;
219: case 'loc':
220: case 'fsys':
221: alertmsg = 'You need to specify the initial password';
222: break;
223: case 'fsys':
224: alertmsg = '';
225: break;
226: default:
227: alertmsg = '';
228: }
229: if (alertmsg != '') {
230: alert(alertmsg);
231: return;
232: }
233: }
234:
235: if (foundname==0) { message='No name fields specified. '; }
236: if (foundid==0) { message+='No ID or student number field specified. '; }
237: if (foundsec==0) { message+='No section or group field specified. '; }
238: if (vf.startdate.value=='') {
239: message+='No starting date set. ';
240: }
241: if (vf.enddate.value=='') {
242: message+='No ending date set. ';
243: }
244: if ((vf.enddate.value!='') && (vf.startdate.value!='')) {
245: if (Math.round(vf.enddate.value)<Math.round(vf.startdate.value)) {
246: alert('Ending date is before starting date');
247: return;
248: }
249: }
250: if (message!='') {
251: message+='Continue enrollment?';
252: if (confirm(message)) {
253: pclose();
254: vf.submit();
255: }
256: } else {
257: pclose();
258: vf.submit();
259: }
260: }
261:
262:
263: function pclose() {
264: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
265: "height=350,width=350,scrollbars=no,menubar=no");
266: parmwin.close();
267: }
268:
269: function pjump(type,dis,value,marker,ret,call) {
270: parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
271: +"&value="+escape(value)+"&marker="+escape(marker)
272: +"&return="+escape(ret)
273: +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
274: "height=350,width=350,scrollbars=no,menubar=no");
275:
276: }
277:
278: function dateset() {
279: if (document.studentform.pres_marker.value=='end') {
280: document.studentform.enddate.value=
281: document.studentform.pres_value.value;
282: }
283: if (document.studentform.pres_marker.value=='start') {
284: document.studentform.startdate.value=
285: document.studentform.pres_value.value;
286: }
287: pclose();
288: }
289:
290: $authheader
291: ENDPICK
292:
293: }
294:
295: sub phase_two_javascript_forward_associate {
296: return(<<ENDPICK);
297: function verify(vf) {
298: var founduname=0;
299: var foundpwd=0;
300: var foundname=0;
301: var foundid=0;
302: var foundsec=0;
303: var tw;
304: for (i=0;i<=vf.nfields.value;i++) {
305: tw=eval('vf.f'+i+'.selectedIndex');
306: if (tw==1) { founduname=1; }
307: if ((tw>=2) && (tw<=6)) { foundname=1; }
308: if (tw==7) { foundid=1; }
309: if (tw==8) { foundsec=1; }
310: if (tw==9) { foundpwd=1; }
311: }
312: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
313: }
314:
315: function flip(vf,tf) {
316: var nw=eval('vf.f'+tf+'.selectedIndex');
317: var i;
318: for (i=0;i<=vf.nfields.value;i++) {
319: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
320: eval('vf.f'+i+'.selectedIndex=0;')
321: }
322: }
323: if (tf==1 && nw!=0) {
324: for (i=2;i<=5;i++) {
325: eval('vf.f'+i+'.selectedIndex=0;')
326: }
327: }
328: if (nw==2) {
329: for (i=0;i<=vf.nfields.value;i++) {
330: if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
331: (eval('vf.f'+i+'.selectedIndex')<=6)) {
332: eval('vf.f'+i+'.selectedIndex=0;')
333: }
334: }
335: }
336: if ((nw>=3) && (nw<=6)) {
337: for (i=0;i<=vf.nfields.value;i++) {
338: if (eval('vf.f'+i+'.selectedIndex')==2) {
339: eval('vf.f'+i+'.selectedIndex=0;')
340: }
341: }
342: }
343: if (nw==9) {
344: changed_radio('int',document.studentform);
345: set_auth_radio_buttons('int',document.studentform);
346: vf.intarg.value='';
347: vf.krbarg.value='';
348: vf.locarg.value='';
349: }
350: }
351:
352: function clearpwd(vf) {
353: var i;
354: for (i=0;i<=vf.nfields.value;i++) {
355: if (eval('vf.f'+i+'.selectedIndex')==9) {
356: eval('vf.f'+i+'.selectedIndex=0;')
357: }
358: }
359: }
360:
361: ENDPICK
362: }
363:
364: sub phase_two_javascript_reverse_associate {
365: return(<<ENDPICK);
366: function verify(vf) {
367: var founduname=0;
368: var foundpwd=0;
369: var foundname=0;
370: var foundid=0;
371: var foundsec=0;
372: var tw;
373: for (i=0;i<=vf.nfields.value;i++) {
374: tw=eval('vf.f'+i+'.selectedIndex');
375: if (i==0 && tw!=0) { founduname=1; }
376: if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
377: if (i==6 && tw!=0) { foundid=1; }
378: if (i==7 && tw!=0) { foundsec=1; }
379: if (i==8 && tw!=0) { foundpwd=1; }
380: }
381: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
382: }
383:
384: function flip(vf,tf) {
385: var nw=eval('vf.f'+tf+'.selectedIndex');
386: var i;
387: // picked the all one one name field, reset the other name ones to blank
388: if (tf==1 && nw!=0) {
389: for (i=2;i<=5;i++) {
390: eval('vf.f'+i+'.selectedIndex=0;')
391: }
392: }
393: //picked one of the piecewise name fields, reset the all in
394: //one field to blank
395: if ((tf>=2) && (tf<=5) && (nw!=0)) {
396: eval('vf.f1.selectedIndex=0;')
397: }
398: // intial password specified, pick internal authentication
399: if (tf==8 && nw!=0) {
400: changed_radio('int',document.studentform);
401: set_auth_radio_buttons('int',document.studentform);
402: vf.krbarg.value='';
403: vf.intarg.value='';
404: vf.locarg.value='';
405: }
406: }
407:
408: function clearpwd(vf) {
409: var i;
410: if (eval('vf.f8.selectedIndex')!=0) {
411: eval('vf.f8.selectedIndex=0;')
412: }
413: }
414: ENDPICK
415: }
416:
417: sub phase_two_end {
418: my ($r,$i,$keyfields,$defdom,$today,$halfyear)=@_;
419: my %param = ( formname => 'document.studentform');
420: my $krbform = &Apache::loncommon::authform_kerberos(%param);
421: my $intform = &Apache::loncommon::authform_internal(%param);
422: my $locform = &Apache::loncommon::authform_local(%param);
423: my $domform = &domain_form($defdom);
424: $r->print(<<ENDPICK);
425: </table>
426: <input type=hidden name=nfields value=$i>
427: <input type=hidden name=keyfields value="$keyfields">
428: <h3>Login Type</h3>
429: <p>Note: this will not take effect if the user already exists</p>
430: <p>
431: $krbform
432: </p>
433: <p>
434: $intform
435: </p>
436: <p>
437: $locform
438: </p>
439: <h3>LON-CAPA Domain for Students</h3>
440: LON-CAPA domain: $domform <p>
441: <h3>Starting and Ending Dates</h3>
442: <input type="hidden" value='' name="pres_value" >
443: <input type="hidden" value='' name="pres_type" >
444: <input type="hidden" value='' name="pres_marker" >
445: <input type="hidden" value='$today' name="startdate" >
446: <input type="hidden" value='$halfyear' name="enddate" >
447: <a
448: href="javascript:pjump('date_start','Enrollment Starting Date',document.studentform.startdate.value,'start','studentform.pres','dateset');"
449: >Set Starting Date</a><p>
450:
451: <a
452: href="javascript:pjump('date_end','Enrollment Ending Date',document.studentform.enddate.value,'end','studentform.pres','dateset');"
453: >Set Ending Date</a><p>
454: <h3>Full Update</h3>
455: <input type=checkbox name=fullup value=yes> Full update
456: (also print list of users not enrolled anymore)<p>
457: <h3>ID/Student Number</h3>
458: <input type=checkbox name=forceid value=yes>
459: Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
460: (only do if you know what you are doing)<p>
461: <input type="button" onClick="javascript:verify(this.form)" value="Update Courselist" /><br />
462: Note: for large courses, this operation might be time consuming.
463: ENDPICK
464: }
465:
466: # ======================================================= Menu Phase Two Upload
467: sub menu_phase_two_upload {
468: my $r=shift;
469:
470: my $datatoken;
471: if (!$ENV{'form.datatoken'}) {
472: $datatoken=&Apache::loncommon::upfile_store($r);
473: } else {
474: $datatoken=$ENV{'form.datatoken'};
475: &Apache::loncommon::load_tmp_file($r);
476: }
477: my @records=&Apache::loncommon::upfile_record_sep();
478: my $total=$#records;
479: my $distotal=$total+1;
480: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
481: my $krbdefdom=$1;
482: $krbdefdom=~tr/a-z/A-Z/;
483: my $today=time;
484: my $halfyear=$today+15552000;
485: my $defdom=$r->dir_config('lonDefDomain');
486: &phase_two_header($r,$datatoken,$distotal,$krbdefdom);
487: my $i;
488: my $keyfields;
489: if ($total>=0) {
490: my @d=(['username','Username'],['names','Last Name, First Names'],
491: ['fname','First Name'],['mname','Middle Names/Initials'],
492: ['lname','Last Name'],['gen','Generation'],
493: ['id','ID/Student Number'],['sec','Group/Section'],
494: ['ipwd','Initial Password']);
495: if ($ENV{'form.upfile_associate'} eq 'reverse') {
496: &Apache::loncommon::csv_print_samples($r,\@records);
497: $i=&Apache::loncommon::csv_print_select_table($r,\@records,\@d);
498: foreach (@d) { $keyfields.=$_->[0].','; }
499: chop($keyfields);
500: } else {
501: unshift(@d,['none','']);
502: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,\@d);
503: my %sone=&Apache::loncommon::record_sep($records[0]);
504: $keyfields=join(',',sort(keys(%sone)));
505: }
506: }
507: &phase_two_end($r,$i,$keyfields,$defdom,$today,$halfyear);
508: }
509:
510: # ======================================================= Enroll single student
511: sub enroll_single_student {
512: my $r=shift;
513: $r->print('<h3>Enrolling Student</h3>');
514: $r->print('<p>Enrolling '.$ENV{'form.cuname'}." in domain ".
515: $ENV{'form.lcdomain'}.'</p>');
516: if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&
517: ($ENV{'form.lcdomain'})&&($ENV{'form.lcdomain'}!~/\W/)) {
518: # Deal with home server selection
519: my $domain=$ENV{'form.lcdomain'};
520: my $desiredhost = $ENV{'form.lcserver'};
521: if (lc($desiredhost) eq 'default') {
522: $desiredhost = undef;
523: } else {
524: my %home_servers = &Apache::loncommon::get_home_servers($domain);
525: if (! exists($home_servers{$desiredhost})) {
526: $r->print('<font color="#ff0000">Error:</font>'.
527: 'Invalid home server specified');
528: return;
529: }
530: }
531: $r->print(" with server $desiredhost :") if (defined($desiredhost));
532: # End of home server selection logic
533: my $amode='';
534: my $genpwd='';
535: if ($ENV{'form.login'} eq 'krb') {
536: $amode='krb4';
537: $genpwd=$ENV{'form.krbarg'};
538: } elsif ($ENV{'form.login'} eq 'int') {
539: $amode='internal';
540: $genpwd=$ENV{'form.intarg'};
541: } elsif ($ENV{'form.login'} eq 'loc') {
542: $amode='localauth';
543: $genpwd=$ENV{'form.locarg'};
544: if (!$genpwd) { $genpwd=" "; }
545: }
546: my $home = &Apache::lonnet::homeserver($ENV{'form.cuname'},
547: $ENV{'form.lcdomain'});
548: if ((($amode) && ($genpwd)) || ($home ne 'no_host')) {
549: &modifystudent($ENV{'form.lcdomain'},$ENV{'form.cuname'},
550: $ENV{'request.course.id'},$ENV{'form.csec'},
551: $desiredhost);
552: $r->print(&Apache::lonnet::modifystudent(
553: $ENV{'form.lcdomain'},$ENV{'form.cuname'},
554: $ENV{'form.cstid'},$amode,$genpwd,
555: $ENV{'form.cfirst'},$ENV{'form.cmiddle'},
556: $ENV{'form.clast'},$ENV{'form.cgen'},
557: $ENV{'form.csec'},$ENV{'form.enddate'},
558: $ENV{'form.startdate'},$ENV{'form.forceid'},
559: $desiredhost));
560: } else {
561: $r->print('<p><font color="#ff0000">ERROR</font> '.
562: 'Invalid login mode or password. '.
563: 'Unable to enroll '.$ENV{'form.cuname'}.'.</p>');
564: }
565: } else {
566: $r->print('Invalid username or domain');
567: }
568: }
569:
570: # ======================================================= Menu Phase Two Enroll
571: sub menu_phase_two_enroll {
572: my $r=shift;
573: my ($krbdefdom) = $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
574: $krbdefdom=~tr/a-z/A-Z/;
575: my $today = time;
576: my $halfyear = $today+15552000;
577: my $defdom=$r->dir_config('lonDefDomain');
578: my $javascript_validations=&javascript_validations($krbdefdom);
579: # Set up authentication forms
580: my %param = ( formname => 'document.studentform');
581: my $krbform = &Apache::loncommon::authform_kerberos(%param);
582: my $intform = &Apache::loncommon::authform_internal(%param);
583: my $locform = &Apache::loncommon::authform_local(%param);
584: # Set up domain selection form
585: my $domform = &domain_form($defdom);
586: # Print it all out
587: $r->print(<<ENDSENROLL);
588: <script type="text/javascript" language="Javascript">
589: function verify(vf) {
590: var founduname=0;
591: var foundpwd=0;
592: var foundname=0;
593: var foundid=0;
594: var foundsec=0;
595: var tw;
596: if ((typeof(vf.cuname.value) !="undefined") && (vf.cuname.value!='') &&
597: (typeof(vf.lcdomain.value)!="undefined") && (vf.lcdomain.value!='')) {
598: founduname=1;
599: }
600: if ((typeof(vf.cfirst.value)!="undefined") && (vf.cfirst.value!='') &&
601: (typeof(vf.clast.value) !="undefined") && (vf.clast.value!='')) {
602: foundname=1;
603: }
604: if ((typeof(vf.csec.value)!="undefined") && (vf.csec.value!='')) {
605: foundsec=1;
606: }
607: if ((typeof(vf.cstid.value)!="undefined") && (vf.cstid.value!='')) {
608: foundid=1;
609: }
610: if (founduname==0) {
611: alert('You need to specify at least the username and domain fields');
612: return;
613: }
614: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
615: }
616:
617: $javascript_validations
618:
619: function clearpwd(vf) {
620: //nothing else needs clearing
621: }
622:
623: </script>
624: <h3>Personal Data</h3>
625: First Name: <input type="text" name="cfirst" size="15"><br>
626: Middle Name: <input type="text" name="cmiddle" size="15"><br>
627: Last Name: <input type="text" name="clast" size="15"><br>
628: Generation: <input type="text" name="cgen" size="5">
629:
630: <p>ID/Student Number: <input type="text" name="cstid" size="10"></p>
631:
632: <p>Group/Section: <input type=text name=csec size=5></p>
633:
634: <h3>Login Data</h3>
635: <p>Username: <input type="text" name="cuname" size="15"></p>
636: <p>Domain: $domform</p>
637: <p>Note: login settings below will not take effect if the user already exists
638: </p><p>
639: $krbform
640: </p><p>
641: $intform
642: </p><p>
643: $locform
644: </p><p>
645: <h3>Starting and Ending Dates</h3>
646: <input type="hidden" value='' name="pres_value">
647: <input type="hidden" value='' name="pres_type">
648: <input type="hidden" value='' name="pres_marker">
649: <input type="hidden" value='$today' name=startdate>
650: <input type="hidden" value='$halfyear' name=enddate>
651: </p><p>
652: <a
653: href="javascript:pjump('date_start','Enrollment Starting Date',document.studentform.startdate.value,'start','studentform.pres','dateset');"
654: >Set Starting Date</a>
655: </p><p>
656: <a
657: href="javascript:pjump('date_end','Enrollment Ending Date',document.studentform.enddate.value,'end','studentform.pres','dateset');"
658: >Set Ending Date</a>
659: </p><p>
660: <h3>ID/Student Number</h3>
661: <input type="checkbox" name="forceid" value="yes">
662: Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
663: (only do if you know what you are doing)<p>
664: <input type="button" onClick="verify(this.form)" value="Enroll as student"><br>
665: <input type="hidden" name="phase" value="five">
666: </p>
667: ENDSENROLL
668: }
669:
670: # =================================================== get the current classlist
671: sub get_current_classlist {
672: my ($domain,$identifier) = @_;
673: # domain is the domain the class is being run in
674: # identifier is the internal, unique identifier for the class.
675: my %currentlist=();
676: my $now=time;
677: my %results=&Apache::lonnet::dump('classlist',$domain,$identifier);
678: my ($tmp) = keys(%results);
679: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
680: foreach my $student (keys(%results)) {
681: # Extract the start and end dates
682: my ($end,$start)=split(/\:/,$results{$student});
683: # If the class isn't over, put it in the list
684: unless (($end) && ($now>$end)) {
685: $currentlist{$student}=1;
686: }
687: }
688: return (undef,%currentlist);
689: } else {
690: $tmp =~ s/^error://;
691: return ($tmp,undef);
692: }
693: }
694:
695: # ========================================================= Menu Phase Two Drop
696: sub menu_phase_two_drop {
697: my $r=shift;
698: my $cid=$ENV{'request.course.id'};
699: my ($error,%currentlist)=&get_current_classlist
700: ($ENV{'course.'.$cid.'.domain'},$ENV{'course.'.$cid.'.num'});
701: if (defined($error)) {
702: $r->print("<pre>ERROR:$error</pre>");
703: } elsif (!defined(%currentlist)) {
704: $r->print("There are no students currently enrolled.\n");
705: } else {
706: # Print out the available choices
707: &show_drop_list($r,%currentlist);
708: }
709: }
710:
711: # =================================================== Show student list to drop
712: sub show_drop_list {
713: my ($r,%currentlist)=@_;
714: my $cid=$ENV{'request.course.id'};
715: $r->print(<<'END');
716: <script>
717: function checkAll(field)
718: {
719: for (i = 0; i < field.length; i++)
720: field[i].checked = true ;
721: }
722:
723: function uncheckAll(field)
724: {
725: for (i = 0; i < field.length; i++)
726: field[i].checked = false ;
727: }
728: </script>
729: <p>
730: <input type="hidden" name="phase" value="four">
731: <table border=2>
732: <tr><th> </th><th>username</th><th>domain</th>
733: <th>ID</th><th>student name</th><th>generation</th>
734: <th>section</th></tr>
735: END
736: foreach (sort keys %currentlist) {
737: my ($sname,$sdom)=split(/\:/,$_);
738: my %reply=&Apache::lonnet::idrget($sdom,$sname);
739: my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid);
740: my %info=&Apache::lonnet::get('environment',
741: ['firstname','middlename',
742: 'lastname','generation'],
743: $sdom, $sname);
744: my ($tmp) = keys(%info);
745: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
746: $r->print('<tr><td colspan="7"><font color="red">'.
747: 'Internal error: unable to get environment '.
748: 'for '.$sname.' in domain '.$sdom.'</font></td></tr>');
749: } else {
750: $r->print(<<"END");
751: <tr>
752: <td><input type="checkbox" name="droplist" value="$_"></td>
753: <td>$sname</td>
754: <td>$sdom</td>
755: <td>$reply{$sname}</td>
756: <td>$info{'lastname'}, $info{'firstname'} $info{'middlename'}</td>
757: <td>$info{'generation'}</td>
758: <td>$ssec</td>
759: </tr>
760: END
761: }
762: }
763: $r->print('</table><br>');
764: $r->print(<<"END");
765: </p><p>
766: <input type="button" value="check all" onclick="javascript:checkAll(document.studentform.droplist)">
767: <input type="button" value="uncheck all" onclick="javascript:uncheckAll(document.studentform.droplist)">
768: <p><input type=submit value="Drop Students"></p>
769: END
770: }
771:
772: # ================================================= Drop/Add from uploaded file
773: sub upfile_drop_add {
774: my $r=shift;
775: &Apache::loncommon::load_tmp_file($r);
776: my @studentdata=&Apache::loncommon::upfile_record_sep();
777: my @keyfields = split(/\,/,$ENV{'form.keyfields'});
778: my $cid = $ENV{'request.course.id'};
779: my %fields=();
780: for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
781: if ($ENV{'form.upfile_associate'} eq 'reverse') {
782: if ($ENV{'form.f'.$i} ne 'none') {
783: $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
784: }
785: } else {
786: $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
787: }
788: }
789: #
790: my $startdate = $ENV{'form.startdate'};
791: my $enddate = $ENV{'form.enddate'};
792: if ($startdate=~/\D/) { $startdate=''; }
793: if ($enddate=~/\D/) { $enddate=''; }
794: # Determine domain and desired host (home server)
795: my $domain=$ENV{'form.lcdomain'};
796: my $desiredhost = $ENV{'form.lcserver'};
797: if (lc($desiredhost) eq 'default') {
798: $desiredhost = undef;
799: } else {
800: my %home_servers = &Apache::loncommon::get_home_servers($domain);
801: if (! exists($home_servers{$desiredhost})) {
802: $r->print('<font color="#ff0000">Error:</font>'.
803: 'Invalid home server specified');
804: return;
805: }
806: }
807: # Determine authentication mechanism
808: my $amode = '';
809: my $genpwd = '';
810: if ($ENV{'form.login'} eq 'krb') {
811: $amode='krb4';
812: $genpwd=$ENV{'form.krbarg'};
813: } elsif ($ENV{'form.login'} eq 'int') {
814: $amode='internal';
815: if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
816: $genpwd=$ENV{'form.intarg'};
817: }
818: } elsif ($ENV{'form.login'} eq 'loc') {
819: $amode='localauth';
820: if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
821: $genpwd=$ENV{'form.locarg'};
822: }
823: }
824: unless (($domain=~/\W/) || ($amode eq '')) {
825: #######################################
826: ## Enroll Students ##
827: #######################################
828: $r->print('<h3>Enrolling Students</h3>');
829: my $count=0;
830: my $flushc=0;
831: my %student=();
832: # Get new classlist
833: foreach (@studentdata) {
834: my %entries=&Apache::loncommon::record_sep($_);
835: # Determine student name
836: unless (($entries{$fields{'username'}} eq '') ||
837: (!defined($entries{$fields{'username'}}))) {
838: my ($fname, $mname, $lname,$gen) = ('','','','');
839: if (defined($fields{'names'})) {
840: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
841: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
842: } else {
843: if (defined($fields{'fname'})) {
844: $fname=$entries{$fields{'fname'}};
845: }
846: if (defined($fields{'mname'})) {
847: $mname=$entries{$fields{'mname'}};
848: }
849: if (defined($fields{'lname'})) {
850: $lname=$entries{$fields{'lname'}};
851: }
852: if (defined($fields{'gen'})) {
853: $gen=$entries{$fields{'gen'}};
854: }
855: }
856: if ($entries{$fields{'username'}}=~/\W/) {
857: $r->print('<p><b>Unacceptable username: '.
858: $entries{$fields{'username'}}.' for user '.
859: $fname.' '.$mname.' '.$lname.' '.$gen.'</b><p>');
860: } else {
861: # determine section number
862: my $sec='';
863: my $username=$entries{$fields{'username'}};
864: if (defined($fields{'sec'})) {
865: if (defined($entries{$fields{'sec'}})) {
866: $sec=$entries{$fields{'sec'}};
867: }
868: }
869: # determine student id number
870: my $id='';
871: if (defined($fields{'id'})) {
872: if (defined($entries{$fields{'id'}})) {
873: $id=$entries{$fields{'id'}};
874: }
875: $id=~tr/A-Z/a-z/;
876: }
877: # determine student password
878: my $password='';
879: if ($genpwd) {
880: $password=$genpwd;
881: } else {
882: if (defined($fields{'ipwd'})) {
883: if ($entries{$fields{'ipwd'}}) {
884: $password=$entries{$fields{'ipwd'}};
885: }
886: }
887: }
888: if ($password) {
889: &modifystudent($domain,$username,$cid,$sec,
890: $desiredhost);
891: my $reply=&Apache::lonnet::modifystudent
892: ($domain,$username,$id,$amode,$password,
893: $fname,$mname,$lname,$gen,$sec,$enddate,
894: $startdate,$ENV{'form.forceid'},$desiredhost);
895: if ($reply ne 'ok') {
896: $r->print('<p><b>'.
897: 'Error enrolling '.$username.': '.
898: $reply.'</b></p>');
899: } else {
900: $count++; $flushc++;
901: $student{$username}=1;
902: $r->print('. ');
903: if ($flushc>15) {
904: $r->rflush;
905: $flushc=0;
906: }
907: }
908: } else {
909: $r->print("<p><b>No password for $username</b><p>");
910: }
911: }
912: }
913: } # end of foreach (@studentdata)
914: $r->print('<p>Processed Students: '.$count);
915: #####################################
916: # Drop students #
917: #####################################
918: if ($ENV{'form.fullup'} eq 'yes') {
919: $r->print('<h3>Dropping Students</h3>');
920: # Get current classlist
921: my ($error,%currentlist)=&get_current_classlist
922: ($ENV{'course.'.$cid.'.domain'},
923: $ENV{'course.'.$cid.'.num'});
924: if (defined($error)) {
925: $r->print('<pre>ERROR:$error</pre>');
926: }
927: if (defined(%currentlist)) {
928: # Drop the students
929: foreach (@studentdata) {
930: my %entries=&Apache::loncommon::record_sep($_);
931: unless (($entries{$fields{'username'}} eq '') ||
932: (!defined($entries{$fields{'username'}}))) {
933: delete($currentlist{$entries{$fields{'username'}}.
934: ':'.$domain});
935: }
936: }
937: # Print out list of dropped students
938: &show_drop_list($r,%currentlist);
939: } else {
940: $r->print("There are no students currently enrolled.\n");
941: }
942: }
943: } # end of unless
944: }
945:
946: # ================================================================== Phase four
947: sub drop_student_list {
948: my $r=shift;
949: my $count=0;
950: my @droplist;
951: if (ref($ENV{'form.droplist'})) {
952: @droplist = @{$ENV{'form.droplist'}};
953: } else {
954: @droplist = ($ENV{'form.droplist'});
955: }
956: foreach (@droplist) {
957: my ($uname,$udom)=split(/\:/,$_);
958: my $result = &modifystudent($udom,$uname,$ENV{'request.course.id'});
959: if ($result eq 'ok' || $result eq 'ok:') {
960: $r->print('Dropped '.$uname.' at '.$udom.'<br>');
961: } else {
962: $r->print('Error dropping '.$uname.' at '.$udom.': '.$result.
963: '<br />');
964: }
965: $count++;
966: }
967: $r->print('<p><b>Dropped '.$count.' student(s).</b>');
968: $r->print('<p>Re-enrollment will re-activate data.');
969: }
970:
971: # ================================================================ Main Handler
972: sub handler {
973: my $r=shift;
974: if ($r->header_only) {
975: $r->content_type('text/html');
976: $r->send_http_header;
977: return OK;
978: }
979: # Needs to be in a course
980: if (($ENV{'request.course.fn'}) &&
981: (&Apache::lonnet::allowed('cst',$ENV{'request.course.id'}))) {
982: # Start page
983: $r->content_type('text/html');
984: $r->send_http_header;
985: $r->print(&header());
986: # Phase one, initial screen
987: unless ($ENV{'form.phase'}) {
988: &menu_phase_one($r);
989: }
990: # Phase two
991: if ($ENV{'form.associate'} eq 'Reverse Association') {
992: $ENV{'form.phase'} = 'two';
993: if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
994: $ENV{'form.upfile_associate'} = 'reverse';
995: } else {
996: $ENV{'form.upfile_associate'} = 'forward';
997: }
998: }
999: if ($ENV{'form.phase'} eq 'two') {
1000: if ($ENV{'form.fileupload'}) {
1001: &menu_phase_two_upload($r);
1002: } elsif ($ENV{'form.enroll'}) {
1003: &menu_phase_two_enroll($r);
1004: } elsif ($ENV{'form.drop'}) {
1005: &menu_phase_two_drop($r);
1006: }
1007: }
1008: # Phase three
1009: if ($ENV{'form.phase'} eq 'three') {
1010: if ($ENV{'form.datatoken'}) {
1011: &upfile_drop_add($r);
1012: }
1013: }
1014: # Phase four
1015: if ($ENV{'form.phase'} eq 'four') {
1016: &drop_student_list($r);
1017: }
1018: # Phase five
1019: if ($ENV{'form.phase'} eq 'five') {
1020: &enroll_single_student($r);
1021: }
1022: # End
1023: $r->print('</form></body></html>');
1024: } else {
1025: # Not in a course, or not allowed to modify parms
1026: $ENV{'user.error.msg'}=
1027: "/adm/dropadd:cst:0:0:Cannot drop or add students";
1028: return HTTP_NOT_ACCEPTABLE;
1029: }
1030: return OK;
1031: }
1032:
1033: 1;
1034: __END__
1035:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>