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