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