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