Annotation of loncom/interface/londropadd.pm, revision 1.15
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: }
1.15 ! albertel 263: if (vf.login[2].checked) {
! 264: foundatype=1;
! 265: //An argument is not required
! 266: }
1.3 www 267: if (foundatype==0) {
268: alert('You need to set the login type');
269: return;
270: }
271: if (foundname==0) { message='No name fields specified. '; }
272: if (foundid==0) { message+='No ID or student number field specified. '; }
273: if (foundsec==0) { message+='No section or group field specified. '; }
1.4 www 274: if (vf.startdate.value=='') {
275: message+='No starting date set. ';
1.3 www 276: }
1.4 www 277: if (vf.enddate.value=='') {
278: message+='No ending date set. ';
279: }
280: if ((vf.enddate.value!='') && (vf.startdate.value!='')) {
1.10 www 281: if (Math.round(vf.enddate.value)<Math.round(vf.startdate.value)) {
1.4 www 282: alert('Ending date is before starting date');
283: return;
284: }
285: }
286: if (message!='') {
287: message+='Continue enrollment?';
288: if (confirm(message)) {
289: pclose();
290: vf.submit();
291: }
292: } else {
293: pclose();
294: vf.submit();
295: }
1.3 www 296: }
297:
298: function flip(vf,tf) {
299: var nw=eval('vf.f'+tf+'.selectedIndex');
300: var i;
301: for (i=0;i<=vf.nfields.value;i++) {
302: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
303: eval('vf.f'+i+'.selectedIndex=0;')
304: }
305: }
306: if (nw==2) {
307: for (i=0;i<=vf.nfields.value;i++) {
308: if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
309: (eval('vf.f'+i+'.selectedIndex')<=6)) {
310: eval('vf.f'+i+'.selectedIndex=0;')
311: }
312: }
313: }
314: if ((nw>=3) && (nw<=6)) {
315: for (i=0;i<=vf.nfields.value;i++) {
316: if (eval('vf.f'+i+'.selectedIndex')==2) {
317: eval('vf.f'+i+'.selectedIndex=0;')
318: }
319: }
320: }
321: if (nw==9) {
322: vf.login[1].checked=true;
323: vf.intpwd.value='';
324: vf.krbdom.value='';
1.15 ! albertel 325: vf.locarg.value='';
1.3 www 326: }
327:
328: }
329:
330: function clearpwd(vf) {
331: var i;
332: for (i=0;i<=vf.nfields.value;i++) {
333: if (eval('vf.f'+i+'.selectedIndex')==9) {
334: eval('vf.f'+i+'.selectedIndex=0;')
335: }
336: }
337: }
338:
339: function setkrb(vf) {
340: if (vf.krbdom.value!='') {
341: clearpwd(vf);
342: vf.login[0].checked=true;
343: vf.krbdom.value=vf.krbdom.value.toUpperCase();
344: vf.intpwd.value='';
345: }
346: }
347:
348: function setint(vf) {
349: if (vf.intpwd.value!='') {
350: clearpwd(vf);
351: vf.login[1].checked=true;
352: vf.krbdom.value='';
353: }
354: }
355:
356: function clickkrb(vf) {
357: vf.krbdom.value='$krbdefdom';
358: clearpwd(vf);
359: vf.intpwd.value='';
360: }
361:
362: function clickint(vf) {
363: vf.krbdom.value='';
364: }
365:
1.4 www 366: function pclose() {
367: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
368: "height=350,width=350,scrollbars=no,menubar=no");
369: parmwin.close();
370: }
371:
372: function pjump(type,dis,value,marker,ret,call) {
373: parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
374: +"&value="+escape(value)+"&marker="+escape(marker)
375: +"&return="+escape(ret)
376: +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
377: "height=350,width=350,scrollbars=no,menubar=no");
378:
379: }
380:
381: function dateset() {
382: if (document.studentform.pres_marker.value=='end') {
383: document.studentform.enddate.value=
384: document.studentform.pres_value.value;
385: }
386: if (document.studentform.pres_marker.value=='start') {
387: document.studentform.startdate.value=
388: document.studentform.pres_value.value;
389: }
390: pclose();
391: }
1.3 www 392:
393: </script>
1.2 www 394: <table border=2><tr><th>Field</th><th>Samples</th></tr>
395: ENDPICK
1.10 www 396: my %sone; my %stwo; my %sthree;
397: my $i=0;
398:
399: if ($total>=0) {
400: %sone=&record_sep($records[0]);
401: if ($total>=1) {
402: %stwo=&record_sep($records[1]);
403:
1.2 www 404: }
1.10 www 405: if ($total>=2) {
406: %sthree=&record_sep($records[2]);
1.2 www 407: }
1.10 www 408: map {
1.3 www 409: $r->print('<tr><td><select name=f'.$i.
410: ' onChange="flip(this.form,'.$i.');">');
1.2 www 411: map {
412: my ($value,$display)=split(/\:/,$_);
413: $r->print('<option value='.$value.'>'.$display.
414: '</option>');
415: } ('none: ','username:Username',
416: 'names:Last Name, First Names',
417: 'fname:First Name','mname:Middle Names/Initials',
418: 'lname:Last Name','gen:Generation',
1.3 www 419: 'id:ID/Student Number','sec:Group/Section',
420: 'ipwd:Initial Password');
1.2 www 421: $r->print('</select></td><td>');
1.13 www 422: if (defined($sone{$_})) {
423: $r->print($sone{$_}."</br>\n");
1.2 www 424: }
1.13 www 425: if (defined($stwo{$_})) {
426: $r->print($stwo{$_}."</br>\n");
1.2 www 427: }
1.13 www 428: if (defined($sthree{$_})) {
429: $r->print($sthree{$_}."</br>\n");
1.2 www 430: }
431: $r->print('</td></tr>');
1.10 www 432: $i++;
433: } sort keys %sone;
434: $i--;
1.2 www 435: }
1.10 www 436: my $keyfields=join(',',sort keys %sone);
1.3 www 437: $r->print(<<ENDPICK);
438: </table>
1.10 www 439: <input type=hidden name=nfields value=$i>
440: <input type=hidden name=keyfields value="$keyfields">
1.3 www 441: <h3>Login Type</h3>
1.15 ! albertel 442: <p>Note: this will not take effect if the user already exists</p>
! 443: <p>
! 444: <input type=radio name=login value=krb onClick="clickkrb(this.form);" />
1.3 www 445: Kerberos authenticated with domain
1.15 ! albertel 446: <input type=text size=10 name=krbdom onChange="setkrb(this.form);" />
! 447: </p>
! 448: <p>
! 449: <input type=radio name=login value=int onClick="clickint(this.form);" />
1.3 www 450: Internally authenticated (with initial password
1.15 ! albertel 451: <input type=text size=10 name=intpwd onChange="setint(this.form);" />)
! 452: </p>
! 453: <p>
! 454: <input type=radio name=login value=loc onClick="clickloc(this.form);" />
! 455: Local Authentication with argument
! 456: <input type=text size=10 name=locarg onChange="setloc(this.form);" />
! 457: </p>
1.5 www 458: <h3>LON-CAPA Domain for Students</h3>
1.4 www 459: LON-CAPA domain: <input type=text size=10 value=$defdom name=lcdomain><p>
1.5 www 460: <h3>Starting and Ending Dates</h3>
1.4 www 461: <input type="hidden" value='' name="pres_value">
462: <input type="hidden" value='' name="pres_type">
463: <input type="hidden" value='' name="pres_marker">
464: <input type="hidden" value='$today' name=startdate>
465: <input type="hidden" value='$halfyear' name=enddate>
466: <a
467: href="javascript:pjump('date_start','Enrollment Starting Date',document.studentform.startdate.value,'start','studentform.pres','dateset');"
468: >Set Starting Date</a><p>
469:
470: <a
471: href="javascript:pjump('date_end','Enrollment Ending Date',document.studentform.enddate.value,'end','studentform.pres','dateset');"
472: >Set Ending Date</a><p>
1.5 www 473: <h3>Full Update</h3>
474: <input type=checkbox name=fullup value=yes> Full update
1.11 www 475: (also print list of users not enrolled anymore)<p>
1.6 www 476: <input type=button onClick="verify(this.form)" value="Update Courselist"><br>
477: Note: for large courses, this operation might be time consuming.
1.3 www 478: ENDPICK
1.10 www 479: }
480:
1.12 www 481: # ======================================================= Enroll single student
482:
483: sub enroll_single_student {
484: my $r=shift;
485: $r->print('<h3>Enrolling Student</h3>');
486: if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&
487: ($ENV{'form.cdomain'})&&($ENV{'form.cdomain'}!~/\W/)) {
488: my $amode='';
489: my $genpwd='';
490: if ($ENV{'form.login'} eq 'krb') {
491: $amode='krb4';
492: $genpwd=$ENV{'form.krbdom'};
493: } elsif ($ENV{'form.login'} eq 'int') {
494: $amode='internal';
495: $genpwd=$ENV{'form.intpwd'};
1.15 ! albertel 496: } elsif ($ENV{'form.login'} eq 'loc') {
! 497: $amode='localauth';
! 498: $genpwd=$ENV{'form.locarg'};
! 499: if (!$genpwd) { $genpwd=" "; }
! 500: }
1.12 www 501: if (($amode) && ($genpwd)) {
502: &dropstudent($ENV{'form.cdomain'},$ENV{'form.cuname'},
503: $ENV{'request.course.id'},$ENV{'form.csec'});
504: $r->print(&Apache::lonnet::modifystudent(
505: $ENV{'form.cdomain'},$ENV{'form.cuname'},
506: $ENV{'form.cstid'},$amode,$genpwd,
507: $ENV{'form.cfirst'},$ENV{'form.cmiddle'},
508: $ENV{'form.clast'},$ENV{'form.cgen'},
509: $ENV{'form.csec'},$ENV{'form.enddate'},
510: $ENV{'form.startdate'}));
511: } else {
512: $r->print('Invalid login mode or password');
513: }
514: } else {
515: $r->print('Invalid username or domain');
516: }
517: }
518:
1.10 www 519: # ======================================================= Menu Phase Two Enroll
520:
521: sub menu_phase_two_enroll {
522: my $r=shift;
1.11 www 523:
524: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
525: my $krbdefdom=$1;
526: $krbdefdom=~tr/a-z/A-Z/;
527:
528: my $today=time;
529: my $halfyear=$today+15552000;
530:
531: my $defdom=$r->dir_config('lonDefDomain');
532:
533: $r->print(<<ENDSENROLL);
1.12 www 534: <script>
535: function verify(vf) {
536: var founduname=0;
537: var foundpwd=0;
538: var foundname=0;
539: var foundid=0;
540: var foundsec=0;
541: var foundatype=0;
542: var tw;
543: var message='';
1.14 harris41 544: if ((typeof(vf.cuname.value)!="undefined") && (vf.cuname.value!='') &&
545: (typeof(vf.cdomain.value)!="undefined") && (vf.cdomain.value!='')) {
1.12 www 546: founduname=1;
547: }
1.14 harris41 548: if ((typeof(vf.cfirst.value)!="undefined") && (vf.cfirst.value!='') &&
549: (typeof(vf.clast.value)!="undefined") && (vf.clast.value!='')) {
1.12 www 550: foundname=1;
551: }
1.14 harris41 552: if ((typeof(vf.csec.value)!="undefined") && (vf.csec.value!='')) {
1.12 www 553: foundsec=1;
554: }
1.14 harris41 555: if ((typeof(vf.cstid.value)!="undefined") && (vf.cstid.value!='')) {
1.12 www 556: foundid=1;
557: }
558: if (founduname==0) {
559: alert('You need to specify at least the username and domain fields');
560: return;
561: }
562: if (vf.login[0].checked) {
563: foundatype=1;
564: if (vf.krbdom.value=='') {
565: alert('You need to specify the Kerberos domain');
566: return;
567: }
568: }
569: if (vf.login[1].checked) {
570: foundatype=1;
571: if ((vf.intpwd.value=='') && (foundpwd==0)) {
572: alert('You need to specify the initial password');
573: return;
574: }
575: }
1.15 ! albertel 576: if (vf.login[2].checked) {
! 577: foundatype=1;
! 578: //An argument is not required
! 579: }
1.12 www 580: if (foundatype==0) {
581: alert('You need to set the login type');
582: return;
583: }
584: if (foundname==0) { message='No first and last name specified. '; }
585: if (foundid==0) { message+='No ID or student number field specified. '; }
586: if (foundsec==0) { message+='No section or group field specified. '; }
587: if (vf.startdate.value=='') {
588: message+='No starting date set. ';
589: }
590: if (vf.enddate.value=='') {
591: message+='No ending date set. ';
592: }
593: if ((vf.enddate.value!='') && (vf.startdate.value!='')) {
594: if (Math.round(vf.enddate.value)<Math.round(vf.startdate.value)) {
595: alert('Ending date is before starting date');
596: return;
597: }
598: }
599: if (message!='') {
600: message+='Continue enrollment?';
601: if (confirm(message)) {
602: pclose();
603: vf.submit();
604: }
605: } else {
606: pclose();
607: vf.submit();
608: }
609: }
610:
611: function setkrb(vf) {
612: if (vf.krbdom.value!='') {
613: vf.login[0].checked=true;
614: vf.krbdom.value=vf.krbdom.value.toUpperCase();
615: vf.intpwd.value='';
1.15 ! albertel 616: vf.locarg.value='';
1.12 www 617: }
618: }
619:
620: function setint(vf) {
621: if (vf.intpwd.value!='') {
622: vf.login[1].checked=true;
623: vf.krbdom.value='';
1.15 ! albertel 624: vf.locarg.value='';
! 625: }
! 626: }
! 627:
! 628: function setloc(vf) {
! 629: if (vf.locarg.value!='') {
! 630: vf.login[2].checked=true;
! 631: vf.krbdom.value='';
! 632: vf.intpwd.value='';
1.12 www 633: }
634: }
635:
636: function clickkrb(vf) {
637: vf.krbdom.value='$krbdefdom';
638: vf.intpwd.value='';
1.15 ! albertel 639: vf.locarg.value='';
1.12 www 640: }
641:
642: function clickint(vf) {
643: vf.krbdom.value='';
1.15 ! albertel 644: vf.locarg.value='';
! 645: }
! 646:
! 647: function clickloc(vf) {
! 648: vf.krbdom.value='';
! 649: vf.intpwd.value='';
1.12 www 650: }
651:
652: function pclose() {
653: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
654: "height=350,width=350,scrollbars=no,menubar=no");
655: parmwin.close();
656: }
657:
658: function pjump(type,dis,value,marker,ret,call) {
659: parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
660: +"&value="+escape(value)+"&marker="+escape(marker)
661: +"&return="+escape(ret)
662: +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
663: "height=350,width=350,scrollbars=no,menubar=no");
664:
665: }
666:
667: function dateset() {
668: if (document.studentform.pres_marker.value=='end') {
669: document.studentform.enddate.value=
670: document.studentform.pres_value.value;
671: }
672: if (document.studentform.pres_marker.value=='start') {
673: document.studentform.startdate.value=
674: document.studentform.pres_value.value;
675: }
676: pclose();
677: }
678:
679: </script>
1.11 www 680: <h3>Personal Data</h3>
681: First Name: <input type=text name=cfirst size=15><br>
682: Middle Name: <input type=text name=cmiddle size=15><br>
683: Last Name: <input type=text name=clast size=15><br>
684: Generation: <input type=text name=cgen size=5><p>
685:
686: ID/Student Number: <input type=text name=cstid size=10><p>
687:
688: Group/Section: <input type=text name=csec size=5><p>
689:
1.12 www 690: <h3>Login Data</h3>
691: Username: <input type=text name=cuname size=15><p>
692: Domain: <input type=text size=10 value=$defdom name=cdomain><p>
693: Note: login settings below will not take effect if the user already exists<p>
1.11 www 694:
695: <input type=radio name=login value=krb onClick="clickkrb(this.form);">
696: Kerberos authenticated with domain
697: <input type=text size=10 name=krbdom onChange="setkrb(this.form);"><p>
698: <input type=radio name=login value=int onClick="clickint(this.form);">
699: Internally authenticated (with initial password
700: <input type=text size=10 name=intpwd onChange="setint(this.form);">)
1.15 ! albertel 701: <p>
! 702: <input type=radio name=login value=loc onClick="clickloc(this.form);" />
! 703: Local Authentication with argument
! 704: <input type=text size=10 name=locarg onChange="setloc(this.form);" />
! 705: </p>
1.11 www 706: <h3>Starting and Ending Dates</h3>
707: <input type="hidden" value='' name="pres_value">
708: <input type="hidden" value='' name="pres_type">
709: <input type="hidden" value='' name="pres_marker">
710: <input type="hidden" value='$today' name=startdate>
711: <input type="hidden" value='$halfyear' name=enddate>
712: <a
713: href="javascript:pjump('date_start','Enrollment Starting Date',document.studentform.startdate.value,'start','studentform.pres','dateset');"
714: >Set Starting Date</a><p>
715:
716: <a
717: href="javascript:pjump('date_end','Enrollment Ending Date',document.studentform.enddate.value,'end','studentform.pres','dateset');"
718: >Set Ending Date</a><p>
1.12 www 719: <input type=button onClick="verify(this.form)" value="Enroll as student"><br>
720: <input type=hidden name=phase value=five>
1.11 www 721: ENDSENROLL
1.10 www 722: }
723:
724: # ========================================================= Menu Phase Two Drop
725:
726: sub menu_phase_two_drop {
727: my $r=shift;
1.11 www 728: my $cid=$ENV{'request.course.id'};
729: my $classlst=&Apache::lonnet::reply
730: ('dump:'.$ENV{'course.'.$cid.'.domain'}.':'.
731: $ENV{'course.'.$cid.'.num'}.':classlist',
732: $ENV{'course.'.$cid.'.home'});
733: my %currentlist=();
734: my $now=time;
735: unless ($classlst=~/^error\:/) {
736: map {
737: my ($name,$value)=split(/\=/,$_);
738: my ($end,$start)=split(/\:/,
739: &Apache::lonnet::unescape($value));
740: my $active=1;
741: if (($end) && ($now>$end)) { $active=0; }
742: if ($active) {
743: $currentlist{&Apache::lonnet::unescape($name)}=1;
744: }
745: } split(/\&/,$classlst);
746: # ----------------------------------------------------------- Print out choices
747: &show_drop_list($r,%currentlist);
748: } else {
749: $r->print(
750: '<font color=red><h3>Could not access classlist: '.$classlst.
751: '</h3></font>');
752: }
753: }
754:
755: # =================================================== Show student list to drop
756:
757: sub show_drop_list {
758: my ($r,%currentlist)=@_;
759: my $cid=$ENV{'request.course.id'};
760:
761: $r->print('<input type=hidden name=phase value=four>');
762: $r->print('<table border=2>');
763: map {
764: my ($sname,$sdom)=split(/\:/,$_);
765: my %reply=&Apache::lonnet::idrget($sdom,$sname);
766: my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid);
767: my @reply=split(/[\&\=]/,&Apache::lonnet::reply(
768: 'get:'.$sdom.':'.$sname.
769: ':environment:firstname&middlename&lastname&generation',
770: &Apache::lonnet::homeserver($sname,$sdom)));
771: $r->print(
772: '<tr><td><input type=checkbox name="drop:'.$_.'"></td><td>'.
773: $sname.'</td><td>'.$sdom.'</td><td>'.
774: $reply{$sname}.'</td><td>'.
775: &Apache::lonnet::unescape($reply[2]).' '.
776: &Apache::lonnet::unescape($reply[3]).', '.
777: &Apache::lonnet::unescape($reply[0]).' '.
778: &Apache::lonnet::unescape($reply[1]).
779: '</td><td>'.
780: $ssec."</td></tr>\n");
781: } sort keys %currentlist;
782: $r->print('</table><br>');
783: $r->print('<input type=submit value="Drop Students">');
1.10 www 784: }
785:
786: # ================================================= Drop/Add from uploaded file
787:
788: sub upfile_drop_add {
789: my $r=shift;
790:
791: &load_tmp_file($r);
792: my @studentdata=&upfile_record_sep();
793:
794: my @keyfields=split(/\,/,$ENV{'form.keyfields'});
795: my $cid=$ENV{'request.course.id'};
796:
1.4 www 797: my %fields=();
798: for (my $i=0;$i<=$ENV{'form.nfields'};$i++) {
1.10 www 799: $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
1.4 www 800: }
801: my $startdate=$ENV{'form.startdate'};
802: my $enddate=$ENV{'form.enddate'};
803: if ($startdate=~/\D/) { $startdate=''; }
804: if ($enddate=~/\D/) { $enddate=''; }
1.5 www 805: my $domain=$ENV{'form.lcdomain'};
806: my $amode='';
807: my $genpwd='';
808: if ($ENV{'form.login'} eq 'krb') {
809: $amode='krb4';
810: $genpwd=$ENV{'form.krbdom'};
811: } elsif ($ENV{'form.login'} eq 'int') {
812: $amode='internal';
813: if ((defined($ENV{'form.intpwd'})) && ($ENV{'form.intpwd'})) {
814: $genpwd=$ENV{'form.intpwd'};
815: }
1.15 ! albertel 816: } elsif ($ENV{'form.login'} eq 'loc') {
! 817: $amode='localauth';
! 818: if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
! 819: $genpwd=$ENV{'form.locarg'};
! 820: }
! 821: }
1.5 www 822: unless (($domain=~/\W/) || ($amode eq '')) {
823: $r->print('<h3>Enrolling Students</h3>');
1.7 www 824: my $count=0;
825: my $flushc=0;
826: my %student=();
1.5 www 827: # ----------------------------------------------------------- Get new classlist
828: # --------------------------------------------------------- Enroll new students
1.2 www 829: map {
1.10 www 830: my %entries=&record_sep($_);
831:
832: unless (($entries{$fields{'username'}} eq '') ||
833: (!defined($entries{$fields{'username'}}))) {
1.4 www 834: my $fname=''; my $mname=''; my $lname=''; my $gen='';
835: if (defined($fields{'names'})) {
836: ($lname,$fname,$mname)=
1.10 www 837: ($entries{$fields{'names'}}=~/([^\,]+)\,\s*(\w+)\s*(.*)$/);
1.4 www 838: } else {
839: if (defined($fields{'fname'})) {
1.10 www 840: $fname=$entries{$fields{'fname'}};
1.4 www 841: }
842: if (defined($fields{'mname'})) {
1.10 www 843: $mname=$entries{$fields{'mname'}};
1.4 www 844: }
845: if (defined($fields{'lname'})) {
1.10 www 846: $lname=$entries{$fields{'lname'}};
1.4 www 847: }
848: if (defined($fields{'gen'})) {
1.10 www 849: $gen=$entries{$fields{'gen'}};
1.4 www 850: }
851: }
1.10 www 852: if ($entries{$fields{'username'}}=~/\W/) {
1.4 www 853: $r->print('<p><b>Unacceptable username: '.
1.10 www 854: $entries{$fields{'username'}}.' for user '.
1.4 www 855: $fname.' '.$mname.' '.$lname.' '.$gen.'</b><p>');
1.5 www 856: } else {
857: my $sec='';
1.10 www 858: my $username=$entries{$fields{'username'}};
1.5 www 859: if (defined($fields{'sec'})) {
1.10 www 860: if (defined($entries{$fields{'sec'}})) {
861: $sec=$entries{$fields{'sec'}};
1.5 www 862: }
863: }
864: my $id='';
865: if (defined($fields{'id'})) {
1.10 www 866: if (defined($entries{$fields{'id'}})) {
867: $id=$entries{$fields{'id'}};
1.5 www 868: }
869: $id=~tr/A-Z/a-z/;
870: }
871: my $password='';
872: if ($genpwd) {
873: $password=$genpwd;
874: } else {
875: if (defined($fields{'ipwd'})) {
1.10 www 876: if ($entries{$fields{'ipwd'}}) {
877: $password=$entries{$fields{'ipwd'}};
1.5 www 878: }
879: }
880: }
1.10 www 881: if ($password) {
882: &dropstudent($domain,$username,$cid,$sec);
1.5 www 883: my $reply=&Apache::lonnet::modifystudent(
884: $domain,$username,$id,$amode,$password,
885: $fname,$mname,$lname,$gen,$sec,$enddate,$startdate);
886: unless ($reply eq 'ok') {
887: $r->print(
888: "<p><b>Error enrolling $username: $reply</b><p>");
1.10 www 889: } else {
1.7 www 890: $count++; $flushc++;
891: $student{$username}=1;
1.6 www 892: $r->print('. ');
1.7 www 893: if ($flushc>15) {
894: $r->rflush;
895: $flushc=0;
896: }
1.6 www 897: }
1.5 www 898: } else {
899: $r->print(
900: "<p><b>No password for $username</b><p>");
901: }
1.4 www 902: }
903: }
904: } @studentdata;
1.7 www 905: $r->print('<p>Processed Students: '.$count);
1.5 www 906: # --------------------------------------------------------------- Drop students
907: if ($ENV{'form.fullup'} eq 'yes') {
908: $r->print('<h3>Dropping Students</h3>');
909: # ------------------------------------------------------- Get current classlist
910: my $classlst=&Apache::lonnet::reply
911: ('dump:'.$ENV{'course.'.$cid.'.domain'}.':'.
912: $ENV{'course.'.$cid.'.num'}.':classlist',
913: $ENV{'course.'.$cid.'.home'});
914: my %currentlist=();
915: my $now=time;
916: unless ($classlst=~/^error\:/) {
1.7 www 917: map {
918: my ($name,$value)=split(/\=/,$_);
1.8 www 919: my ($end,$start)=split(/\:/,
1.7 www 920: &Apache::lonnet::unescape($value));
921: my $active=1;
922: if (($end) && ($now>$end)) { $active=0; }
923: if ($active) {
924: $currentlist{&Apache::lonnet::unescape($name)}=1;
925: }
926: } split(/\&/,$classlst);
1.10 www 927: # ------------------------------------------------ Now got up-to-date classlist
928: map {
929: my %entries=&record_sep($_);
930: unless (($entries{$fields{'username'}} eq '') ||
931: (!defined($entries{$fields{'username'}}))) {
932: delete($currentlist{
933: $entries{$fields{'username'}}.':'.
934: $domain});
935: }
936: } @studentdata;
937: # ----------------------------------------------------------- Print out choices
1.11 www 938: &show_drop_list($r,%currentlist);
1.5 www 939: } else {
940: $r->print(
941: '<font color=red><h3>Could not access classlist: '.$classlst.
942: '</h3></font>');
943: }
944: }
945: # ------------------------------------------------------------------------ Done
1.10 www 946:
947: }
948: }
949:
1.11 www 950: # ================================================================== Phase four
951:
952: sub drop_student_list {
953: my $r=shift;
954: my $count=0;
955: map {
956: if ($_=~/^form\.drop\:/) {
957: my ($dummy,$uname,$udom)=split(/\:/,$_);
958: &dropstudent($udom,$uname,$ENV{'request.course.id'});
959: $r->print('Dropped '.$uname.' at '.$udom.'<br>');
960: $count++;
961: }
962: } keys %ENV;
963: $r->print('<p><b>Dropped '.$count.' student(s).</b>');
964: $r->print('<p>Re-enrollment will re-activate data.');
965: }
966:
1.10 www 967: # ================================================================ Main Handler
968:
969: sub handler {
970: my $r=shift;
971:
972: if ($r->header_only) {
973: $r->content_type('text/html');
974: $r->send_http_header;
975: return OK;
976: }
977:
978: # ----------------------------------------------------- Needs to be in a course
979:
980: if (($ENV{'request.course.fn'}) &&
981: (&Apache::lonnet::allowed('cst',$ENV{'request.course.id'}))) {
982:
983: # ------------------------------------------------------------------ Start page
984: $r->content_type('text/html');
985: $r->send_http_header;
986: &header($r);
987:
988: # --------------------------------------------------- Phase one, initial screen
989: unless ($ENV{'form.phase'}) {
990: &menu_phase_one($r);
991: }
992: # ------------------------------------------------------------------- Phase two
993: if ($ENV{'form.phase'} eq 'two') {
994: if ($ENV{'form.fileupload'}) {
995: &menu_phase_two_upload($r);
996: } elsif ($ENV{'form.enroll'}) {
997: &menu_phase_two_enroll($r);
998: } elsif ($ENV{'form.drop'}) {
999: &menu_phase_two_drop($r);
1000: }
1001: }
1002:
1003:
1004:
1005:
1006: # ----------------------------------------------------------------- Phase three
1007: if ($ENV{'form.phase'} eq 'three') {
1008: if ($ENV{'form.datatoken'}) {
1009: &upfile_drop_add($r);
1.2 www 1010: }
1.11 www 1011: }
1012: # ------------------------------------------------------------------ Phase four
1013: if ($ENV{'form.phase'} eq 'four') {
1014: &drop_student_list($r);
1.12 www 1015: }
1016: # ------------------------------------------------------------------ Phase four
1017: if ($ENV{'form.phase'} eq 'five') {
1018: &enroll_single_student($r);
1.2 www 1019: }
1020: # ------------------------------------------------------------------------- End
1.1 www 1021: $r->print('</form></body></html>');
1022: } else {
1023: # ----------------------------- Not in a course, or not allowed to modify parms
1024: $ENV{'user.error.msg'}=
1025: "/adm/dropadd:cst:0:0:Cannot drop or add students";
1026: return HTTP_NOT_ACCEPTABLE;
1027: }
1028: return OK;
1029: }
1030:
1031: 1;
1032: __END__
1033:
1034:
1035:
1036:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>