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