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