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