Annotation of loncom/interface/londropadd.pm, revision 1.11
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>
434: <input type=radio name=login value=krb onClick="clickkrb(this.form);">
435: Kerberos authenticated with domain
436: <input type=text size=10 name=krbdom onChange="setkrb(this.form);"><p>
437: <input type=radio name=login value=int onClick="clickint(this.form);">
438: Internally authenticated (with initial password
1.5 www 439: <input type=text size=10 name=intpwd onChange="setint(this.form);">)
440: <h3>LON-CAPA Domain for Students</h3>
1.4 www 441: LON-CAPA domain: <input type=text size=10 value=$defdom name=lcdomain><p>
1.5 www 442: <h3>Starting and Ending Dates</h3>
1.4 www 443: <input type="hidden" value='' name="pres_value">
444: <input type="hidden" value='' name="pres_type">
445: <input type="hidden" value='' name="pres_marker">
446: <input type="hidden" value='$today' name=startdate>
447: <input type="hidden" value='$halfyear' name=enddate>
448: <a
449: href="javascript:pjump('date_start','Enrollment Starting Date',document.studentform.startdate.value,'start','studentform.pres','dateset');"
450: >Set Starting Date</a><p>
451:
452: <a
453: href="javascript:pjump('date_end','Enrollment Ending Date',document.studentform.enddate.value,'end','studentform.pres','dateset');"
454: >Set Ending Date</a><p>
1.5 www 455: <h3>Full Update</h3>
456: <input type=checkbox name=fullup value=yes> Full update
1.11 ! www 457: (also print list of users not enrolled anymore)<p>
1.6 www 458: <input type=button onClick="verify(this.form)" value="Update Courselist"><br>
459: Note: for large courses, this operation might be time consuming.
1.3 www 460: ENDPICK
1.10 www 461: }
462:
463: # ======================================================= Menu Phase Two Enroll
464:
465: sub menu_phase_two_enroll {
466: my $r=shift;
1.11 ! www 467:
! 468: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
! 469: my $krbdefdom=$1;
! 470: $krbdefdom=~tr/a-z/A-Z/;
! 471:
! 472: my $today=time;
! 473: my $halfyear=$today+15552000;
! 474:
! 475: my $defdom=$r->dir_config('lonDefDomain');
! 476:
! 477: $r->print(<<ENDSENROLL);
! 478: <h3>Personal Data</h3>
! 479:
! 480: First Name: <input type=text name=cfirst size=15><br>
! 481: Middle Name: <input type=text name=cmiddle size=15><br>
! 482: Last Name: <input type=text name=clast size=15><br>
! 483: Generation: <input type=text name=cgen size=5><p>
! 484:
! 485: ID/Student Number: <input type=text name=cstid size=10><p>
! 486:
! 487: Group/Section: <input type=text name=csec size=5><p>
! 488:
! 489: Initial password (if applicable): <input type=text name=cinpwd size=10><p>
! 490:
! 491: <h3>Login Type</h3>
! 492: <input type=radio name=login value=krb onClick="clickkrb(this.form);">
! 493: Kerberos authenticated with domain
! 494: <input type=text size=10 name=krbdom onChange="setkrb(this.form);"><p>
! 495: <input type=radio name=login value=int onClick="clickint(this.form);">
! 496: Internally authenticated (with initial password
! 497: <input type=text size=10 name=intpwd onChange="setint(this.form);">)
! 498: <h3>LON-CAPA Domain for Students</h3>
! 499: LON-CAPA domain: <input type=text size=10 value=$defdom name=lcdomain><p>
! 500: <h3>Starting and Ending Dates</h3>
! 501: <input type="hidden" value='' name="pres_value">
! 502: <input type="hidden" value='' name="pres_type">
! 503: <input type="hidden" value='' name="pres_marker">
! 504: <input type="hidden" value='$today' name=startdate>
! 505: <input type="hidden" value='$halfyear' name=enddate>
! 506: <a
! 507: href="javascript:pjump('date_start','Enrollment Starting Date',document.studentform.startdate.value,'start','studentform.pres','dateset');"
! 508: >Set Starting Date</a><p>
! 509:
! 510: <a
! 511: href="javascript:pjump('date_end','Enrollment Ending Date',document.studentform.enddate.value,'end','studentform.pres','dateset');"
! 512: >Set Ending Date</a><p>
! 513: ENDSENROLL
1.10 www 514: }
515:
516: # ========================================================= Menu Phase Two Drop
517:
518: sub menu_phase_two_drop {
519: my $r=shift;
1.11 ! www 520: my $cid=$ENV{'request.course.id'};
! 521: my $classlst=&Apache::lonnet::reply
! 522: ('dump:'.$ENV{'course.'.$cid.'.domain'}.':'.
! 523: $ENV{'course.'.$cid.'.num'}.':classlist',
! 524: $ENV{'course.'.$cid.'.home'});
! 525: my %currentlist=();
! 526: my $now=time;
! 527: unless ($classlst=~/^error\:/) {
! 528: map {
! 529: my ($name,$value)=split(/\=/,$_);
! 530: my ($end,$start)=split(/\:/,
! 531: &Apache::lonnet::unescape($value));
! 532: my $active=1;
! 533: if (($end) && ($now>$end)) { $active=0; }
! 534: if ($active) {
! 535: $currentlist{&Apache::lonnet::unescape($name)}=1;
! 536: }
! 537: } split(/\&/,$classlst);
! 538: # ----------------------------------------------------------- Print out choices
! 539: &show_drop_list($r,%currentlist);
! 540: } else {
! 541: $r->print(
! 542: '<font color=red><h3>Could not access classlist: '.$classlst.
! 543: '</h3></font>');
! 544: }
! 545: }
! 546:
! 547: # =================================================== Show student list to drop
! 548:
! 549: sub show_drop_list {
! 550: my ($r,%currentlist)=@_;
! 551: my $cid=$ENV{'request.course.id'};
! 552:
! 553: $r->print('<input type=hidden name=phase value=four>');
! 554: $r->print('<table border=2>');
! 555: map {
! 556: my ($sname,$sdom)=split(/\:/,$_);
! 557: my %reply=&Apache::lonnet::idrget($sdom,$sname);
! 558: my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid);
! 559: my @reply=split(/[\&\=]/,&Apache::lonnet::reply(
! 560: 'get:'.$sdom.':'.$sname.
! 561: ':environment:firstname&middlename&lastname&generation',
! 562: &Apache::lonnet::homeserver($sname,$sdom)));
! 563: $r->print(
! 564: '<tr><td><input type=checkbox name="drop:'.$_.'"></td><td>'.
! 565: $sname.'</td><td>'.$sdom.'</td><td>'.
! 566: $reply{$sname}.'</td><td>'.
! 567: &Apache::lonnet::unescape($reply[2]).' '.
! 568: &Apache::lonnet::unescape($reply[3]).', '.
! 569: &Apache::lonnet::unescape($reply[0]).' '.
! 570: &Apache::lonnet::unescape($reply[1]).
! 571: '</td><td>'.
! 572: $ssec."</td></tr>\n");
! 573: } sort keys %currentlist;
! 574: $r->print('</table><br>');
! 575: $r->print('<input type=submit value="Drop Students">');
1.10 www 576: }
577:
578: # ================================================= Drop/Add from uploaded file
579:
580: sub upfile_drop_add {
581: my $r=shift;
582:
583: &load_tmp_file($r);
584: my @studentdata=&upfile_record_sep();
585:
586: my @keyfields=split(/\,/,$ENV{'form.keyfields'});
587: my $cid=$ENV{'request.course.id'};
588:
1.4 www 589: my %fields=();
590: for (my $i=0;$i<=$ENV{'form.nfields'};$i++) {
1.10 www 591: $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
1.4 www 592: }
593: my $startdate=$ENV{'form.startdate'};
594: my $enddate=$ENV{'form.enddate'};
595: if ($startdate=~/\D/) { $startdate=''; }
596: if ($enddate=~/\D/) { $enddate=''; }
1.5 www 597: my $domain=$ENV{'form.lcdomain'};
598: my $amode='';
599: my $genpwd='';
600: if ($ENV{'form.login'} eq 'krb') {
601: $amode='krb4';
602: $genpwd=$ENV{'form.krbdom'};
603: } elsif ($ENV{'form.login'} eq 'int') {
604: $amode='internal';
605: if ((defined($ENV{'form.intpwd'})) && ($ENV{'form.intpwd'})) {
606: $genpwd=$ENV{'form.intpwd'};
607: }
608: }
609: unless (($domain=~/\W/) || ($amode eq '')) {
610: $r->print('<h3>Enrolling Students</h3>');
1.7 www 611: my $count=0;
612: my $flushc=0;
613: my %student=();
1.5 www 614: # ----------------------------------------------------------- Get new classlist
615: # --------------------------------------------------------- Enroll new students
1.2 www 616: map {
1.10 www 617: my %entries=&record_sep($_);
618:
619: unless (($entries{$fields{'username'}} eq '') ||
620: (!defined($entries{$fields{'username'}}))) {
1.4 www 621: my $fname=''; my $mname=''; my $lname=''; my $gen='';
622: if (defined($fields{'names'})) {
623: ($lname,$fname,$mname)=
1.10 www 624: ($entries{$fields{'names'}}=~/([^\,]+)\,\s*(\w+)\s*(.*)$/);
1.4 www 625: } else {
626: if (defined($fields{'fname'})) {
1.10 www 627: $fname=$entries{$fields{'fname'}};
1.4 www 628: }
629: if (defined($fields{'mname'})) {
1.10 www 630: $mname=$entries{$fields{'mname'}};
1.4 www 631: }
632: if (defined($fields{'lname'})) {
1.10 www 633: $lname=$entries{$fields{'lname'}};
1.4 www 634: }
635: if (defined($fields{'gen'})) {
1.10 www 636: $gen=$entries{$fields{'gen'}};
1.4 www 637: }
638: }
1.10 www 639: if ($entries{$fields{'username'}}=~/\W/) {
1.4 www 640: $r->print('<p><b>Unacceptable username: '.
1.10 www 641: $entries{$fields{'username'}}.' for user '.
1.4 www 642: $fname.' '.$mname.' '.$lname.' '.$gen.'</b><p>');
1.5 www 643: } else {
644: my $sec='';
1.10 www 645: my $username=$entries{$fields{'username'}};
1.5 www 646: if (defined($fields{'sec'})) {
1.10 www 647: if (defined($entries{$fields{'sec'}})) {
648: $sec=$entries{$fields{'sec'}};
1.5 www 649: }
650: }
651: my $id='';
652: if (defined($fields{'id'})) {
1.10 www 653: if (defined($entries{$fields{'id'}})) {
654: $id=$entries{$fields{'id'}};
1.5 www 655: }
656: $id=~tr/A-Z/a-z/;
657: }
658: my $password='';
659: if ($genpwd) {
660: $password=$genpwd;
661: } else {
662: if (defined($fields{'ipwd'})) {
1.10 www 663: if ($entries{$fields{'ipwd'}}) {
664: $password=$entries{$fields{'ipwd'}};
1.5 www 665: }
666: }
667: }
1.10 www 668: if ($password) {
669: &dropstudent($domain,$username,$cid,$sec);
1.5 www 670: my $reply=&Apache::lonnet::modifystudent(
671: $domain,$username,$id,$amode,$password,
672: $fname,$mname,$lname,$gen,$sec,$enddate,$startdate);
673: unless ($reply eq 'ok') {
674: $r->print(
675: "<p><b>Error enrolling $username: $reply</b><p>");
1.10 www 676: } else {
1.7 www 677: $count++; $flushc++;
678: $student{$username}=1;
1.6 www 679: $r->print('. ');
1.7 www 680: if ($flushc>15) {
681: $r->rflush;
682: $flushc=0;
683: }
1.6 www 684: }
1.5 www 685: } else {
686: $r->print(
687: "<p><b>No password for $username</b><p>");
688: }
1.4 www 689: }
690: }
691: } @studentdata;
1.7 www 692: $r->print('<p>Processed Students: '.$count);
1.5 www 693: # --------------------------------------------------------------- Drop students
694: if ($ENV{'form.fullup'} eq 'yes') {
695: $r->print('<h3>Dropping Students</h3>');
696: # ------------------------------------------------------- Get current classlist
697: my $classlst=&Apache::lonnet::reply
698: ('dump:'.$ENV{'course.'.$cid.'.domain'}.':'.
699: $ENV{'course.'.$cid.'.num'}.':classlist',
700: $ENV{'course.'.$cid.'.home'});
701: my %currentlist=();
702: my $now=time;
703: unless ($classlst=~/^error\:/) {
1.7 www 704: map {
705: my ($name,$value)=split(/\=/,$_);
1.8 www 706: my ($end,$start)=split(/\:/,
1.7 www 707: &Apache::lonnet::unescape($value));
708: my $active=1;
709: if (($end) && ($now>$end)) { $active=0; }
710: if ($active) {
711: $currentlist{&Apache::lonnet::unescape($name)}=1;
712: }
713: } split(/\&/,$classlst);
1.10 www 714: # ------------------------------------------------ Now got up-to-date classlist
715: map {
716: my %entries=&record_sep($_);
717: unless (($entries{$fields{'username'}} eq '') ||
718: (!defined($entries{$fields{'username'}}))) {
719: delete($currentlist{
720: $entries{$fields{'username'}}.':'.
721: $domain});
722: }
723: } @studentdata;
724: # ----------------------------------------------------------- Print out choices
1.11 ! www 725: &show_drop_list($r,%currentlist);
1.5 www 726: } else {
727: $r->print(
728: '<font color=red><h3>Could not access classlist: '.$classlst.
729: '</h3></font>');
730: }
731: }
732: # ------------------------------------------------------------------------ Done
1.10 www 733:
734: }
735: }
736:
1.11 ! www 737: # ================================================================== Phase four
! 738:
! 739: sub drop_student_list {
! 740: my $r=shift;
! 741: my $count=0;
! 742: map {
! 743: if ($_=~/^form\.drop\:/) {
! 744: my ($dummy,$uname,$udom)=split(/\:/,$_);
! 745: &dropstudent($udom,$uname,$ENV{'request.course.id'});
! 746: $r->print('Dropped '.$uname.' at '.$udom.'<br>');
! 747: $count++;
! 748: }
! 749: } keys %ENV;
! 750: $r->print('<p><b>Dropped '.$count.' student(s).</b>');
! 751: $r->print('<p>Re-enrollment will re-activate data.');
! 752: }
! 753:
1.10 www 754: # ================================================================ Main Handler
755:
756: sub handler {
757: my $r=shift;
758:
759: if ($r->header_only) {
760: $r->content_type('text/html');
761: $r->send_http_header;
762: return OK;
763: }
764:
765: # ----------------------------------------------------- Needs to be in a course
766:
767: if (($ENV{'request.course.fn'}) &&
768: (&Apache::lonnet::allowed('cst',$ENV{'request.course.id'}))) {
769:
770: # ------------------------------------------------------------------ Start page
771: $r->content_type('text/html');
772: $r->send_http_header;
773: &header($r);
774:
775: # --------------------------------------------------- Phase one, initial screen
776: unless ($ENV{'form.phase'}) {
777: &menu_phase_one($r);
778: }
779: # ------------------------------------------------------------------- Phase two
780: if ($ENV{'form.phase'} eq 'two') {
781: if ($ENV{'form.fileupload'}) {
782: &menu_phase_two_upload($r);
783: } elsif ($ENV{'form.enroll'}) {
784: &menu_phase_two_enroll($r);
785: } elsif ($ENV{'form.drop'}) {
786: &menu_phase_two_drop($r);
787: }
788: }
789:
790:
791:
792:
793: # ----------------------------------------------------------------- Phase three
794: if ($ENV{'form.phase'} eq 'three') {
795: if ($ENV{'form.datatoken'}) {
796: &upfile_drop_add($r);
1.2 www 797: }
1.11 ! www 798: }
! 799: # ------------------------------------------------------------------ Phase four
! 800: if ($ENV{'form.phase'} eq 'four') {
! 801: &drop_student_list($r);
1.2 www 802: }
803: # ------------------------------------------------------------------------- End
1.1 www 804: $r->print('</form></body></html>');
805: } else {
806: # ----------------------------- Not in a course, or not allowed to modify parms
807: $ENV{'user.error.msg'}=
808: "/adm/dropadd:cst:0:0:Cannot drop or add students";
809: return HTTP_NOT_ACCEPTABLE;
810: }
811: return OK;
812: }
813:
814: 1;
815: __END__
816:
817:
818:
819:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>