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