Annotation of loncom/interface/londropadd.pm, revision 1.39
1.1 www 1: # The LearningOnline Network with CAPA
2: # Handler to drop and add students in courses
3: #
1.39 ! matthew 4: # $Id: londropadd.pm,v 1.38 2002/05/03 16:30:48 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.39 ! matthew 702: if ($error =~ /^No such file or directory/) {
! 703: $r->print("There are no students currently enrolled.\n");
! 704: } else {
! 705: $r->print("<pre>ERROR:$error</pre>");
! 706: }
1.38 matthew 707: } elsif (!defined(%currentlist)) {
1.27 matthew 708: $r->print("There are no students currently enrolled.\n");
1.26 matthew 709: } else {
710: # Print out the available choices
1.25 matthew 711: &show_drop_list($r,%currentlist);
712: }
1.11 www 713: }
714:
715: # =================================================== Show student list to drop
716: sub show_drop_list {
717: my ($r,%currentlist)=@_;
718: my $cid=$ENV{'request.course.id'};
1.26 matthew 719: $r->print(<<'END');
1.32 matthew 720: <script>
721: function checkAll(field)
722: {
723: for (i = 0; i < field.length; i++)
724: field[i].checked = true ;
725: }
726:
727: function uncheckAll(field)
728: {
729: for (i = 0; i < field.length; i++)
730: field[i].checked = false ;
731: }
732: </script>
733: <p>
1.26 matthew 734: <input type="hidden" name="phase" value="four">
735: <table border=2>
736: <tr><th> </th><th>username</th><th>domain</th>
737: <th>ID</th><th>student name</th><th>generation</th>
738: <th>section</th></tr>
739: END
1.25 matthew 740: foreach (sort keys %currentlist) {
741: my ($sname,$sdom)=split(/\:/,$_);
742: my %reply=&Apache::lonnet::idrget($sdom,$sname);
743: my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid);
1.26 matthew 744: my %info=&Apache::lonnet::get('environment',
745: ['firstname','middlename',
746: 'lastname','generation'],
747: $sdom, $sname);
748: my ($tmp) = keys(%info);
749: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
750: $r->print('<tr><td colspan="7"><font color="red">'.
751: 'Internal error: unable to get environment '.
752: 'for '.$sname.' in domain '.$sdom.'</font></td></tr>');
753: } else {
754: $r->print(<<"END");
755: <tr>
756: <td><input type="checkbox" name="droplist" value="$_"></td>
757: <td>$sname</td>
758: <td>$sdom</td>
759: <td>$reply{$sname}</td>
760: <td>$info{'lastname'}, $info{'firstname'} $info{'middlename'}</td>
761: <td>$info{'generation'}</td>
762: <td>$ssec</td>
763: </tr>
764: END
765: }
1.25 matthew 766: }
767: $r->print('</table><br>');
1.32 matthew 768: $r->print(<<"END");
769: </p><p>
770: <input type="button" value="check all" onclick="javascript:checkAll(document.studentform.droplist)">
771: <input type="button" value="uncheck all" onclick="javascript:uncheckAll(document.studentform.droplist)">
772: <p><input type=submit value="Drop Students"></p>
773: END
1.10 www 774: }
775:
776: # ================================================= Drop/Add from uploaded file
777: sub upfile_drop_add {
778: my $r=shift;
1.24 albertel 779: &Apache::loncommon::load_tmp_file($r);
780: my @studentdata=&Apache::loncommon::upfile_record_sep();
1.26 matthew 781: my @keyfields = split(/\,/,$ENV{'form.keyfields'});
782: my $cid = $ENV{'request.course.id'};
1.25 matthew 783: my %fields=();
1.26 matthew 784: for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
1.25 matthew 785: if ($ENV{'form.upfile_associate'} eq 'reverse') {
786: if ($ENV{'form.f'.$i} ne 'none') {
787: $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
788: }
789: } else {
790: $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
791: }
792: }
1.26 matthew 793: #
794: my $startdate = $ENV{'form.startdate'};
795: my $enddate = $ENV{'form.enddate'};
1.25 matthew 796: if ($startdate=~/\D/) { $startdate=''; }
1.26 matthew 797: if ($enddate=~/\D/) { $enddate=''; }
1.31 matthew 798: # Determine domain and desired host (home server)
1.25 matthew 799: my $domain=$ENV{'form.lcdomain'};
1.31 matthew 800: my $desiredhost = $ENV{'form.lcserver'};
801: if (lc($desiredhost) eq 'default') {
802: $desiredhost = undef;
803: } else {
804: my %home_servers = &Apache::loncommon::get_home_servers($domain);
805: if (! exists($home_servers{$desiredhost})) {
806: $r->print('<font color="#ff0000">Error:</font>'.
807: 'Invalid home server specified');
808: return;
809: }
810: }
1.26 matthew 811: # Determine authentication mechanism
812: my $amode = '';
813: my $genpwd = '';
1.25 matthew 814: if ($ENV{'form.login'} eq 'krb') {
815: $amode='krb4';
1.28 matthew 816: $genpwd=$ENV{'form.krbarg'};
1.25 matthew 817: } elsif ($ENV{'form.login'} eq 'int') {
818: $amode='internal';
1.28 matthew 819: if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
820: $genpwd=$ENV{'form.intarg'};
1.25 matthew 821: }
822: } elsif ($ENV{'form.login'} eq 'loc') {
823: $amode='localauth';
824: if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
825: $genpwd=$ENV{'form.locarg'};
826: }
827: }
828: unless (($domain=~/\W/) || ($amode eq '')) {
1.26 matthew 829: #######################################
830: ## Enroll Students ##
831: #######################################
1.25 matthew 832: $r->print('<h3>Enrolling Students</h3>');
833: my $count=0;
834: my $flushc=0;
835: my %student=();
1.26 matthew 836: # Get new classlist
1.25 matthew 837: foreach (@studentdata) {
838: my %entries=&Apache::loncommon::record_sep($_);
1.26 matthew 839: # Determine student name
1.25 matthew 840: unless (($entries{$fields{'username'}} eq '') ||
841: (!defined($entries{$fields{'username'}}))) {
1.26 matthew 842: my ($fname, $mname, $lname,$gen) = ('','','','');
1.25 matthew 843: if (defined($fields{'names'})) {
1.26 matthew 844: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
845: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
1.25 matthew 846: } else {
847: if (defined($fields{'fname'})) {
848: $fname=$entries{$fields{'fname'}};
849: }
850: if (defined($fields{'mname'})) {
851: $mname=$entries{$fields{'mname'}};
852: }
853: if (defined($fields{'lname'})) {
854: $lname=$entries{$fields{'lname'}};
855: }
856: if (defined($fields{'gen'})) {
857: $gen=$entries{$fields{'gen'}};
858: }
859: }
860: if ($entries{$fields{'username'}}=~/\W/) {
861: $r->print('<p><b>Unacceptable username: '.
1.10 www 862: $entries{$fields{'username'}}.' for user '.
1.4 www 863: $fname.' '.$mname.' '.$lname.' '.$gen.'</b><p>');
1.25 matthew 864: } else {
1.26 matthew 865: # determine section number
1.25 matthew 866: my $sec='';
867: my $username=$entries{$fields{'username'}};
868: if (defined($fields{'sec'})) {
869: if (defined($entries{$fields{'sec'}})) {
870: $sec=$entries{$fields{'sec'}};
871: }
872: }
1.26 matthew 873: # determine student id number
1.25 matthew 874: my $id='';
875: if (defined($fields{'id'})) {
876: if (defined($entries{$fields{'id'}})) {
877: $id=$entries{$fields{'id'}};
878: }
879: $id=~tr/A-Z/a-z/;
880: }
1.26 matthew 881: # determine student password
1.25 matthew 882: my $password='';
883: if ($genpwd) {
884: $password=$genpwd;
885: } else {
886: if (defined($fields{'ipwd'})) {
887: if ($entries{$fields{'ipwd'}}) {
888: $password=$entries{$fields{'ipwd'}};
889: }
890: }
891: }
892: if ($password) {
1.33 matthew 893: &modifystudent($domain,$username,$cid,$sec,
894: $desiredhost);
1.25 matthew 895: my $reply=&Apache::lonnet::modifystudent
896: ($domain,$username,$id,$amode,$password,
897: $fname,$mname,$lname,$gen,$sec,$enddate,
1.31 matthew 898: $startdate,$ENV{'form.forceid'},$desiredhost);
1.26 matthew 899: if ($reply ne 'ok') {
900: $r->print('<p><b>'.
901: 'Error enrolling '.$username.': '.
902: $reply.'</b></p>');
1.10 www 903: } else {
1.7 www 904: $count++; $flushc++;
905: $student{$username}=1;
1.6 www 906: $r->print('. ');
1.7 www 907: if ($flushc>15) {
908: $r->rflush;
909: $flushc=0;
910: }
1.6 www 911: }
1.25 matthew 912: } else {
913: $r->print("<p><b>No password for $username</b><p>");
914: }
915: }
1.26 matthew 916: }
917: } # end of foreach (@studentdata)
1.25 matthew 918: $r->print('<p>Processed Students: '.$count);
1.26 matthew 919: #####################################
920: # Drop students #
921: #####################################
1.25 matthew 922: if ($ENV{'form.fullup'} eq 'yes') {
923: $r->print('<h3>Dropping Students</h3>');
1.26 matthew 924: # Get current classlist
1.27 matthew 925: my ($error,%currentlist)=&get_current_classlist
1.26 matthew 926: ($ENV{'course.'.$cid.'.domain'},
927: $ENV{'course.'.$cid.'.num'});
1.27 matthew 928: if (defined($error)) {
929: $r->print('<pre>ERROR:$error</pre>');
930: }
1.26 matthew 931: if (defined(%currentlist)) {
932: # Drop the students
1.25 matthew 933: foreach (@studentdata) {
934: my %entries=&Apache::loncommon::record_sep($_);
935: unless (($entries{$fields{'username'}} eq '') ||
936: (!defined($entries{$fields{'username'}}))) {
1.26 matthew 937: delete($currentlist{$entries{$fields{'username'}}.
938: ':'.$domain});
1.25 matthew 939: }
940: }
1.26 matthew 941: # Print out list of dropped students
1.25 matthew 942: &show_drop_list($r,%currentlist);
943: } else {
1.27 matthew 944: $r->print("There are no students currently enrolled.\n");
1.25 matthew 945: }
946: }
1.26 matthew 947: } # end of unless
1.10 www 948: }
949:
1.11 www 950: # ================================================================== Phase four
951: sub drop_student_list {
952: my $r=shift;
953: my $count=0;
1.35 matthew 954: my @droplist;
955: if (ref($ENV{'form.droplist'})) {
956: @droplist = @{$ENV{'form.droplist'}};
957: } else {
958: @droplist = ($ENV{'form.droplist'});
959: }
960: foreach (@droplist) {
1.26 matthew 961: my ($uname,$udom)=split(/\:/,$_);
1.35 matthew 962: my $result = &modifystudent($udom,$uname,$ENV{'request.course.id'});
1.37 matthew 963: if ($result eq 'ok' || $result eq 'ok:') {
1.35 matthew 964: $r->print('Dropped '.$uname.' at '.$udom.'<br>');
965: } else {
966: $r->print('Error dropping '.$uname.' at '.$udom.': '.$result.
967: '<br />');
968: }
1.26 matthew 969: $count++;
1.20 harris41 970: }
1.11 www 971: $r->print('<p><b>Dropped '.$count.' student(s).</b>');
972: $r->print('<p>Re-enrollment will re-activate data.');
973: }
974:
1.10 www 975: # ================================================================ Main Handler
976: sub handler {
1.26 matthew 977: my $r=shift;
978: if ($r->header_only) {
979: $r->content_type('text/html');
980: $r->send_http_header;
981: return OK;
982: }
983: # Needs to be in a course
984: if (($ENV{'request.course.fn'}) &&
985: (&Apache::lonnet::allowed('cst',$ENV{'request.course.id'}))) {
986: # Start page
987: $r->content_type('text/html');
988: $r->send_http_header;
1.27 matthew 989: $r->print(&header());
1.26 matthew 990: # Phase one, initial screen
991: unless ($ENV{'form.phase'}) {
992: &menu_phase_one($r);
993: }
994: # Phase two
995: if ($ENV{'form.associate'} eq 'Reverse Association') {
996: $ENV{'form.phase'} = 'two';
997: if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
998: $ENV{'form.upfile_associate'} = 'reverse';
999: } else {
1000: $ENV{'form.upfile_associate'} = 'forward';
1001: }
1002: }
1003: if ($ENV{'form.phase'} eq 'two') {
1004: if ($ENV{'form.fileupload'}) {
1005: &menu_phase_two_upload($r);
1006: } elsif ($ENV{'form.enroll'}) {
1007: &menu_phase_two_enroll($r);
1008: } elsif ($ENV{'form.drop'}) {
1009: &menu_phase_two_drop($r);
1010: }
1011: }
1012: # Phase three
1013: if ($ENV{'form.phase'} eq 'three') {
1014: if ($ENV{'form.datatoken'}) {
1015: &upfile_drop_add($r);
1016: }
1017: }
1018: # Phase four
1019: if ($ENV{'form.phase'} eq 'four') {
1020: &drop_student_list($r);
1021: }
1022: # Phase five
1023: if ($ENV{'form.phase'} eq 'five') {
1024: &enroll_single_student($r);
1025: }
1026: # End
1027: $r->print('</form></body></html>');
1028: } else {
1029: # Not in a course, or not allowed to modify parms
1030: $ENV{'user.error.msg'}=
1031: "/adm/dropadd:cst:0:0:Cannot drop or add students";
1032: return HTTP_NOT_ACCEPTABLE;
1033: }
1034: return OK;
1.1 www 1035: }
1036:
1037: 1;
1038: __END__
1039:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>