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