Annotation of loncom/interface/londropadd.pm, revision 1.60
1.1 www 1: # The LearningOnline Network with CAPA
2: # Handler to drop and add students in courses
3: #
1.60 ! matthew 4: # $Id: londropadd.pm,v 1.59 2002/10/16 18:45:10 matthew Exp $
1.17 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 www 28: # (Handler to set parameters for assessments
29: #
30: # (Handler to resolve ambiguous file locations
31: #
32: # (TeX Content Handler
33: #
1.50 matthew 34: ###############################################################
35: ###############################################################
1.1 www 36:
37: package Apache::londropadd;
38:
39: use strict;
1.24 albertel 40: use Apache::lonnet();
41: use Apache::loncommon();
1.50 matthew 42: use Apache::lonhtmlcommon();
1.1 www 43: use Apache::Constants qw(:common :http REDIRECT);
1.60 ! matthew 44: use Spreadsheet::WriteExcel;
1.1 www 45:
1.50 matthew 46: ###############################################################
47: ###############################################################
1.10 www 48: sub header {
1.46 www 49: my $bodytag=&Apache::loncommon::bodytag('Enrollment Manager');
1.27 matthew 50: return(<<ENDHEAD);
1.1 www 51: <html>
52: <head>
1.40 matthew 53: <title>LON-CAPA Enrollment Manager</title>
1.1 www 54: </head>
1.46 www 55: $bodytag
1.40 matthew 56: <form method="post" enctype="multipart/form-data"
57: action="/adm/dropadd" name="studentform">
1.1 www 58: ENDHEAD
1.10 www 59: }
60:
1.50 matthew 61: ###############################################################
62: ###############################################################
63: # Drop student from all sections of a course, except optional $csec
1.26 matthew 64: sub modifystudent {
1.33 matthew 65: my ($udom,$unam,$courseid,$csec,$desiredhost)=@_;
1.26 matthew 66: # if $csec is undefined, drop the student from all the courses matching
67: # this one. If $csec is defined, drop them from all other sections of
68: # this course and add them to section $csec
1.25 matthew 69: $courseid=~s/\_/\//g;
70: $courseid=~s/^(\w)/\/$1/;
1.26 matthew 71: my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
72: my ($tmp) = keys(%roles);
73: # Bail out if we were unable to get the students roles
1.35 matthew 74: return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
1.26 matthew 75: # Go through the roles looking for enrollment in this course
1.35 matthew 76: my $result = '';
1.26 matthew 77: foreach my $course (keys(%roles)) {
1.35 matthew 78: if ($course=~/^$courseid(?:\/)*(?:\s+)*(\w+)*\_st$/) {
1.26 matthew 79: # We are in this course
1.25 matthew 80: my $section=$1;
1.26 matthew 81: $section='' if ($course eq $courseid.'_st');
1.35 matthew 82: if ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
1.27 matthew 83: my (undef,$end,$start)=split(/\_/,$roles{$course});
1.25 matthew 84: my $now=time;
1.50 matthew 85: # if this is an active role
1.27 matthew 86: if (!($start && ($now<$start)) || !($end && ($now>$end))) {
1.25 matthew 87: my $reply=&Apache::lonnet::modifystudent
1.33 matthew 88: ($udom,$unam,'','','','','','','',
89: $section,time,undef,undef,$desiredhost);
1.35 matthew 90: $result .= $reply.':';
1.25 matthew 91: }
1.10 www 92: }
93: }
1.20 harris41 94: }
1.35 matthew 95: if ($result eq '') {
96: $result eq 'Unable to find section for this student';
1.37 matthew 97: } else {
98: $result =~ s/(ok:)+/ok/g;
1.35 matthew 99: }
100: return $result;
1.10 www 101: }
102:
1.50 matthew 103: ###############################################################
104: ###############################################################
105: # build a domain and server selection form
1.31 matthew 106: sub domain_form {
107: my ($defdom) = @_;
108: # Set up domain and server selection forms
109: #
110: # Get the domains
111: my @domains = &Apache::loncommon::get_domains();
112: # build up the menu information to be passed to
113: # &Apache::loncommon::linked_select_forms
114: my %select_menus;
115: foreach my $dom (@domains) {
116: # set up the text for this domain
117: $select_menus{$dom}->{'text'}= $dom;
118: # we want a choice of 'default' as the default in the second menu
119: $select_menus{$dom}->{'default'}= 'default';
120: $select_menus{$dom}->{'select2'}->{'default'} = 'default';
121: # Now build up the other items in the second menu
1.45 matthew 122: my %servers = &Apache::loncommon::get_library_servers($dom);
1.31 matthew 123: foreach my $server (keys(%servers)) {
124: $select_menus{$dom}->{'select2'}->{$server}
125: = "$server $servers{$server}";
126: }
127: }
128: my $result = &Apache::loncommon::linked_select_forms
129: ('studentform',' with home server ',$defdom,
130: 'lcdomain','lcserver',\%select_menus);
131: return $result;
132: }
133:
1.50 matthew 134: ###############################################################
135: ###############################################################
136: # Menu Phase One
137: sub print_main_menu {
1.10 www 138: my $r=shift;
1.48 matthew 139: $r->print(<<END);
140: <p>
1.50 matthew 141: <font size="+1">
142: <a href="/adm/dropadd?action=upload">Upload a course list</a>
143: </font>
144: </p><p>
145: <font size="+1">
146: <a href="/adm/dropadd?action=enrollstudent">Enroll a single student</a>
147: </font>
1.48 matthew 148: </p><p>
1.50 matthew 149: <font size="+1">
150: <a href="/adm/dropadd?action=modifystudent">Modify student data</a>
151: </font>
1.48 matthew 152: </p><p>
1.50 matthew 153: <font size="+1">
154: <a href="/adm/dropadd?action=classlist">View Classlist</a>
155: </font>
1.48 matthew 156: </p><p>
1.50 matthew 157: <font size="+1">
158: <a href="/adm/dropadd?action=drop">Drop Students</a>
159: </font>
1.48 matthew 160: </p>
161: END
1.10 www 162: }
163:
1.50 matthew 164: ###############################################################
165: ###############################################################
166: sub print_upload_manager_header {
1.23 albertel 167: my ($r,$datatoken,$distotal,$krbdefdom)=@_;
1.24 albertel 168: my $javascript;
1.50 matthew 169: if (! exists($ENV{'form.upfile_associate'})) {
170: $ENV{'form.upfile_associate'} = 'forward';
171: }
172: if ($ENV{'form.associate'} eq 'Reverse Association') {
173: if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
174: $ENV{'form.upfile_associate'} = 'reverse';
175: } else {
176: $ENV{'form.upfile_associate'} = 'forward';
177: }
178: }
1.24 albertel 179: if ($ENV{'form.upfile_associate'} eq 'reverse') {
1.50 matthew 180: $javascript=&upload_manager_javascript_reverse_associate();
1.24 albertel 181: } else {
1.50 matthew 182: $javascript=&upload_manager_javascript_forward_associate();
1.24 albertel 183: }
184: my $javascript_validations=&javascript_validations($krbdefdom);
1.10 www 185: $r->print(<<ENDPICK);
1.40 matthew 186: <h3>Uploading Class List</h3>
1.2 www 187: <hr>
188: <h3>Identify fields</h3>
1.22 albertel 189: Total number of records found in file: $distotal <hr />
190: Enter as many fields as you can. The system will inform you and bring you back
191: to this page if the data selected is insufficient to run your class.<hr />
1.36 albertel 192: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.50 matthew 193: <input type="hidden" name="action" value="upload" />
194: <input type="hidden" name="state" value="got_file" />
1.36 albertel 195: <input type="hidden" name="associate" value="" />
1.26 matthew 196: <input type="hidden" name="datatoken" value="$datatoken" />
1.24 albertel 197: <input type="hidden" name="fileupload" value="$ENV{'form.fileupload'}" />
198: <input type="hidden" name="upfiletype" value="$ENV{'form.upfiletype'}" />
1.26 matthew 199: <input type="hidden" name="upfile_associate"
200: value="$ENV{'form.upfile_associate'}" />
1.24 albertel 201: <hr />
1.28 matthew 202: <script type="text/javascript" language="Javascript">
1.24 albertel 203: $javascript
204: $javascript_validations
205: </script>
206: ENDPICK
207: }
208:
1.50 matthew 209: ###############################################################
210: ###############################################################
1.24 albertel 211: sub javascript_validations {
212: my ($krbdefdom)=@_;
1.28 matthew 213: my %param = ( formname => 'studentform',
214: kerb_def_dom => $krbdefdom );
215: my $authheader = &Apache::loncommon::authform_header(%param);
1.24 albertel 216: return (<<ENDPICK);
217: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec) {
1.3 www 218: var foundatype=0;
219: var message='';
220: if (founduname==0) {
1.28 matthew 221: alert('You need to specify the username field');
1.3 www 222: return;
223: }
1.29 matthew 224: if (current.radiovalue == null || current.radiovalue == 'nochange') {
1.28 matthew 225: // They did not check any of the login radiobuttons.
226: alert('You must choose an authentication type');
227: return;
228: }
229: foundatype=1;
1.29 matthew 230: if (current.argfield == null || current.argfield == '') {
1.28 matthew 231: var alertmsg = '';
1.29 matthew 232: switch (current.value) {
1.28 matthew 233: case 'krb':
234: alertmsg = 'You need to specify the Kerberos domain';
235: break;
236: case 'loc':
237: case 'fsys':
238: alertmsg = 'You need to specify the initial password';
239: break;
240: case 'fsys':
241: alertmsg = '';
242: break;
243: default:
244: alertmsg = '';
1.3 www 245: }
1.28 matthew 246: if (alertmsg != '') {
247: alert(alertmsg);
1.3 www 248: return;
249: }
250: }
1.28 matthew 251:
1.3 www 252: if (foundname==0) { message='No name fields specified. '; }
253: if (foundid==0) { message+='No ID or student number field specified. '; }
254: if (foundsec==0) { message+='No section or group field specified. '; }
1.4 www 255: if (vf.startdate.value=='') {
256: message+='No starting date set. ';
1.3 www 257: }
1.4 www 258: if (vf.enddate.value=='') {
259: message+='No ending date set. ';
260: }
261: if ((vf.enddate.value!='') && (vf.startdate.value!='')) {
1.10 www 262: if (Math.round(vf.enddate.value)<Math.round(vf.startdate.value)) {
1.4 www 263: alert('Ending date is before starting date');
264: return;
265: }
266: }
267: if (message!='') {
268: message+='Continue enrollment?';
269: if (confirm(message)) {
270: pclose();
1.50 matthew 271: vf.state.value='enrolling';
1.4 www 272: vf.submit();
273: }
274: } else {
275: pclose();
1.50 matthew 276: vf.state.value='enrolling';
1.4 www 277: vf.submit();
1.24 albertel 278: }
1.3 www 279: }
280:
281:
1.4 www 282: function pclose() {
283: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
284: "height=350,width=350,scrollbars=no,menubar=no");
285: parmwin.close();
286: }
287:
288: function pjump(type,dis,value,marker,ret,call) {
289: parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
290: +"&value="+escape(value)+"&marker="+escape(marker)
291: +"&return="+escape(ret)
292: +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
293: "height=350,width=350,scrollbars=no,menubar=no");
294:
295: }
296:
297: function dateset() {
298: if (document.studentform.pres_marker.value=='end') {
299: document.studentform.enddate.value=
300: document.studentform.pres_value.value;
301: }
302: if (document.studentform.pres_marker.value=='start') {
303: document.studentform.startdate.value=
304: document.studentform.pres_value.value;
305: }
306: pclose();
307: }
1.3 www 308:
1.28 matthew 309: $authheader
1.24 albertel 310: ENDPICK
1.28 matthew 311:
1.24 albertel 312: }
313:
1.50 matthew 314: ###############################################################
315: ###############################################################
316: sub upload_manager_javascript_forward_associate {
1.24 albertel 317: return(<<ENDPICK);
318: function verify(vf) {
319: var founduname=0;
320: var foundpwd=0;
321: var foundname=0;
322: var foundid=0;
323: var foundsec=0;
324: var tw;
325: for (i=0;i<=vf.nfields.value;i++) {
326: tw=eval('vf.f'+i+'.selectedIndex');
327: if (tw==1) { founduname=1; }
328: if ((tw>=2) && (tw<=6)) { foundname=1; }
329: if (tw==7) { foundid=1; }
330: if (tw==8) { foundsec=1; }
331: if (tw==9) { foundpwd=1; }
332: }
333: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
334: }
335:
1.49 matthew 336: //
337: // vf = this.form
338: // tf = column number
339: //
340: // values of nw
341: //
342: // 0 = none
343: // 1 = username
344: // 2 = names (lastname, firstnames)
345: // 3 = fname (firstname)
346: // 4 = mname (middlename)
347: // 5 = lname (lastname)
348: // 6 = gen (generation)
349: // 7 = id
350: // 8 = section
351: // 9 = ipwd (password)
352: //
1.24 albertel 353: function flip(vf,tf) {
354: var nw=eval('vf.f'+tf+'.selectedIndex');
355: var i;
1.49 matthew 356: // make sure no other columns are labeled the same as this one
1.24 albertel 357: for (i=0;i<=vf.nfields.value;i++) {
358: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
359: eval('vf.f'+i+'.selectedIndex=0;')
360: }
361: }
1.49 matthew 362: // If we set this to 'lastname, firstnames', clear out all the ones
363: // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
1.24 albertel 364: if (nw==2) {
365: for (i=0;i<=vf.nfields.value;i++) {
366: if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
367: (eval('vf.f'+i+'.selectedIndex')<=6)) {
368: eval('vf.f'+i+'.selectedIndex=0;')
369: }
370: }
371: }
1.49 matthew 372: // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
373: // clear out any that are set to 'lastname, firstnames' (2)
1.24 albertel 374: if ((nw>=3) && (nw<=6)) {
375: for (i=0;i<=vf.nfields.value;i++) {
376: if (eval('vf.f'+i+'.selectedIndex')==2) {
377: eval('vf.f'+i+'.selectedIndex=0;')
378: }
379: }
380: }
1.49 matthew 381: // If we set the password, make the password form below correspond to
382: // the new value.
1.24 albertel 383: if (nw==9) {
1.28 matthew 384: changed_radio('int',document.studentform);
385: set_auth_radio_buttons('int',document.studentform);
386: vf.intarg.value='';
387: vf.krbarg.value='';
1.24 albertel 388: vf.locarg.value='';
389: }
390: }
391:
392: function clearpwd(vf) {
393: var i;
394: for (i=0;i<=vf.nfields.value;i++) {
395: if (eval('vf.f'+i+'.selectedIndex')==9) {
396: eval('vf.f'+i+'.selectedIndex=0;')
397: }
398: }
399: }
400:
401: ENDPICK
402: }
403:
1.50 matthew 404: ###############################################################
405: ###############################################################
406: sub upload_manager_javascript_reverse_associate {
1.24 albertel 407: return(<<ENDPICK);
408: function verify(vf) {
409: var founduname=0;
410: var foundpwd=0;
411: var foundname=0;
412: var foundid=0;
413: var foundsec=0;
414: var tw;
415: for (i=0;i<=vf.nfields.value;i++) {
416: tw=eval('vf.f'+i+'.selectedIndex');
417: if (i==0 && tw!=0) { founduname=1; }
418: if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
419: if (i==6 && tw!=0) { foundid=1; }
420: if (i==7 && tw!=0) { foundsec=1; }
421: if (i==8 && tw!=0) { foundpwd=1; }
422: }
423: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
424: }
425:
426: function flip(vf,tf) {
427: var nw=eval('vf.f'+tf+'.selectedIndex');
428: var i;
429: // picked the all one one name field, reset the other name ones to blank
430: if (tf==1 && nw!=0) {
431: for (i=2;i<=5;i++) {
432: eval('vf.f'+i+'.selectedIndex=0;')
433: }
434: }
435: //picked one of the piecewise name fields, reset the all in
436: //one field to blank
437: if ((tf>=2) && (tf<=5) && (nw!=0)) {
438: eval('vf.f1.selectedIndex=0;')
439: }
440: // intial password specified, pick internal authentication
441: if (tf==8 && nw!=0) {
1.28 matthew 442: changed_radio('int',document.studentform);
443: set_auth_radio_buttons('int',document.studentform);
444: vf.krbarg.value='';
445: vf.intarg.value='';
1.24 albertel 446: vf.locarg.value='';
447: }
448: }
449:
450: function clearpwd(vf) {
451: var i;
452: if (eval('vf.f8.selectedIndex')!=0) {
453: eval('vf.f8.selectedIndex=0;')
454: }
455: }
1.2 www 456: ENDPICK
1.23 albertel 457: }
1.10 www 458:
1.50 matthew 459: ###############################################################
460: ###############################################################
461: sub print_upload_manager_footer {
1.23 albertel 462: my ($r,$i,$keyfields,$defdom,$today,$halfyear)=@_;
1.28 matthew 463: my %param = ( formname => 'document.studentform');
464: my $krbform = &Apache::loncommon::authform_kerberos(%param);
465: my $intform = &Apache::loncommon::authform_internal(%param);
466: my $locform = &Apache::loncommon::authform_local(%param);
1.31 matthew 467: my $domform = &domain_form($defdom);
1.23 albertel 468: $r->print(<<ENDPICK);
1.3 www 469: </table>
1.10 www 470: <input type=hidden name=nfields value=$i>
471: <input type=hidden name=keyfields value="$keyfields">
1.3 www 472: <h3>Login Type</h3>
1.15 albertel 473: <p>Note: this will not take effect if the user already exists</p>
474: <p>
1.28 matthew 475: $krbform
1.15 albertel 476: </p>
477: <p>
1.28 matthew 478: $intform
1.15 albertel 479: </p>
480: <p>
1.28 matthew 481: $locform
1.15 albertel 482: </p>
1.5 www 483: <h3>LON-CAPA Domain for Students</h3>
1.29 matthew 484: LON-CAPA domain: $domform <p>
1.5 www 485: <h3>Starting and Ending Dates</h3>
1.26 matthew 486: <input type="hidden" value='' name="pres_value" >
487: <input type="hidden" value='' name="pres_type" >
488: <input type="hidden" value='' name="pres_marker" >
489: <input type="hidden" value='$today' name="startdate" >
490: <input type="hidden" value='$halfyear' name="enddate" >
1.4 www 491: <a
492: href="javascript:pjump('date_start','Enrollment Starting Date',document.studentform.startdate.value,'start','studentform.pres','dateset');"
493: >Set Starting Date</a><p>
494:
495: <a
496: href="javascript:pjump('date_end','Enrollment Ending Date',document.studentform.enddate.value,'end','studentform.pres','dateset');"
497: >Set Ending Date</a><p>
1.5 www 498: <h3>Full Update</h3>
499: <input type=checkbox name=fullup value=yes> Full update
1.11 www 500: (also print list of users not enrolled anymore)<p>
1.18 www 501: <h3>ID/Student Number</h3>
502: <input type=checkbox name=forceid value=yes>
503: Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
1.19 www 504: (only do if you know what you are doing)<p>
1.36 albertel 505: <input type="button" onClick="javascript:verify(this.form)" value="Update Courselist" /><br />
1.50 matthew 506: Note: for large courses, this operation may be time consuming.
1.3 www 507: ENDPICK
1.23 albertel 508: }
1.24 albertel 509:
1.23 albertel 510: # ======================================================= Menu Phase Two Upload
1.50 matthew 511: sub print_upload_manager_form {
1.23 albertel 512: my $r=shift;
1.26 matthew 513:
1.24 albertel 514: my $datatoken;
515: if (!$ENV{'form.datatoken'}) {
1.26 matthew 516: $datatoken=&Apache::loncommon::upfile_store($r);
1.24 albertel 517: } else {
1.26 matthew 518: $datatoken=$ENV{'form.datatoken'};
519: &Apache::loncommon::load_tmp_file($r);
1.24 albertel 520: }
521: my @records=&Apache::loncommon::upfile_record_sep();
1.23 albertel 522: my $total=$#records;
523: my $distotal=$total+1;
524: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
525: my $krbdefdom=$1;
526: $krbdefdom=~tr/a-z/A-Z/;
527: my $today=time;
528: my $halfyear=$today+15552000;
529: my $defdom=$r->dir_config('lonDefDomain');
1.50 matthew 530: &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom);
1.24 albertel 531: my $i;
532: my $keyfields;
1.23 albertel 533: if ($total>=0) {
1.50 matthew 534: my @d=(['username','Username'],
535: ['names','Last Name, First Names'],
536: ['fname','First Name'],
537: ['mname','Middle Names/Initials'],
538: ['lname','Last Name'],
539: ['gen','Generation'],
540: ['id','ID/Student Number'],
541: ['sec','Group/Section'],
1.24 albertel 542: ['ipwd','Initial Password']);
543: if ($ENV{'form.upfile_associate'} eq 'reverse') {
544: &Apache::loncommon::csv_print_samples($r,\@records);
545: $i=&Apache::loncommon::csv_print_select_table($r,\@records,\@d);
546: foreach (@d) { $keyfields.=$_->[0].','; }
547: chop($keyfields);
548: } else {
549: unshift(@d,['none','']);
550: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,\@d);
551: my %sone=&Apache::loncommon::record_sep($records[0]);
552: $keyfields=join(',',sort(keys(%sone)));
1.23 albertel 553: }
554: }
1.50 matthew 555: &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear);
1.10 www 556: }
557:
1.12 www 558: # ======================================================= Enroll single student
559: sub enroll_single_student {
560: my $r=shift;
561: $r->print('<h3>Enrolling Student</h3>');
1.54 matthew 562: $r->print('<p>Enrolling '.$ENV{'form.cuname'}." \@ ".
1.34 matthew 563: $ENV{'form.lcdomain'}.'</p>');
1.12 www 564: if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&
1.31 matthew 565: ($ENV{'form.lcdomain'})&&($ENV{'form.lcdomain'}!~/\W/)) {
566: # Deal with home server selection
567: my $domain=$ENV{'form.lcdomain'};
568: my $desiredhost = $ENV{'form.lcserver'};
569: if (lc($desiredhost) eq 'default') {
570: $desiredhost = undef;
571: } else {
1.45 matthew 572: my %home_servers =&Apache::loncommon::get_library_servers($domain);
1.31 matthew 573: if (! exists($home_servers{$desiredhost})) {
574: $r->print('<font color="#ff0000">Error:</font>'.
575: 'Invalid home server specified');
576: return;
577: }
578: }
1.34 matthew 579: $r->print(" with server $desiredhost :") if (defined($desiredhost));
1.31 matthew 580: # End of home server selection logic
1.12 www 581: my $amode='';
582: my $genpwd='';
583: if ($ENV{'form.login'} eq 'krb') {
1.47 albertel 584: $amode='krb';
585: $amode.=$ENV{'form.krbver'};
1.28 matthew 586: $genpwd=$ENV{'form.krbarg'};
1.12 www 587: } elsif ($ENV{'form.login'} eq 'int') {
1.26 matthew 588: $amode='internal';
1.28 matthew 589: $genpwd=$ENV{'form.intarg'};
1.15 albertel 590: } elsif ($ENV{'form.login'} eq 'loc') {
591: $amode='localauth';
592: $genpwd=$ENV{'form.locarg'};
593: if (!$genpwd) { $genpwd=" "; }
594: }
1.34 matthew 595: my $home = &Apache::lonnet::homeserver($ENV{'form.cuname'},
596: $ENV{'form.lcdomain'});
597: if ((($amode) && ($genpwd)) || ($home ne 'no_host')) {
1.55 matthew 598: # Clean out any old roles the student has in this class.
1.33 matthew 599: &modifystudent($ENV{'form.lcdomain'},$ENV{'form.cuname'},
600: $ENV{'request.course.id'},$ENV{'form.csec'},
601: $desiredhost);
1.55 matthew 602: my $login_result = &Apache::lonnet::modifystudent
603: ($ENV{'form.lcdomain'},$ENV{'form.cuname'},
604: $ENV{'form.cstid'},$amode,$genpwd,
605: $ENV{'form.cfirst'},$ENV{'form.cmiddle'},
606: $ENV{'form.clast'},$ENV{'form.cgen'},
607: $ENV{'form.csec'},$ENV{'form.enddate'},
608: $ENV{'form.startdate'},$ENV{'form.forceid'},
609: $desiredhost);
610: if ($login_result =~ /^ok/) {
611: $r->print($login_result);
612: $r->print("<p> If active, the new role will be available ".
613: "when the student next logs in to LON-CAPA.</p>");
614: } else {
615: $r->print("unable to enroll: ".$login_result);
616: }
1.12 www 617: } else {
1.34 matthew 618: $r->print('<p><font color="#ff0000">ERROR</font> '.
619: 'Invalid login mode or password. '.
620: 'Unable to enroll '.$ENV{'form.cuname'}.'.</p>');
1.12 www 621: }
622: } else {
623: $r->print('Invalid username or domain');
1.26 matthew 624: }
1.12 www 625: }
626:
1.10 www 627: # ======================================================= Menu Phase Two Enroll
1.50 matthew 628: sub print_enroll_single_student_form {
1.10 www 629: my $r=shift;
1.40 matthew 630: $r->print("<h3>Enroll One Student</h3>");
1.26 matthew 631: my ($krbdefdom) = $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
1.11 www 632: $krbdefdom=~tr/a-z/A-Z/;
1.26 matthew 633: my $today = time;
634: my $halfyear = $today+15552000;
1.11 www 635: my $defdom=$r->dir_config('lonDefDomain');
1.24 albertel 636: my $javascript_validations=&javascript_validations($krbdefdom);
1.28 matthew 637: # Set up authentication forms
638: my %param = ( formname => 'document.studentform');
639: my $krbform = &Apache::loncommon::authform_kerberos(%param);
640: my $intform = &Apache::loncommon::authform_internal(%param);
641: my $locform = &Apache::loncommon::authform_local(%param);
1.29 matthew 642: # Set up domain selection form
1.31 matthew 643: my $domform = &domain_form($defdom);
1.28 matthew 644: # Print it all out
1.50 matthew 645: $r->print(<<END);
646: <input type="hidden" name="action" value="enrollstudent">
647: <input type="hidden" name="state" value="done">
648:
1.28 matthew 649: <script type="text/javascript" language="Javascript">
1.12 www 650: function verify(vf) {
651: var founduname=0;
652: var foundpwd=0;
653: var foundname=0;
654: var foundid=0;
655: var foundsec=0;
656: var tw;
1.26 matthew 657: if ((typeof(vf.cuname.value) !="undefined") && (vf.cuname.value!='') &&
1.31 matthew 658: (typeof(vf.lcdomain.value)!="undefined") && (vf.lcdomain.value!='')) {
1.12 www 659: founduname=1;
660: }
1.14 harris41 661: if ((typeof(vf.cfirst.value)!="undefined") && (vf.cfirst.value!='') &&
1.26 matthew 662: (typeof(vf.clast.value) !="undefined") && (vf.clast.value!='')) {
1.12 www 663: foundname=1;
664: }
1.14 harris41 665: if ((typeof(vf.csec.value)!="undefined") && (vf.csec.value!='')) {
1.12 www 666: foundsec=1;
667: }
1.14 harris41 668: if ((typeof(vf.cstid.value)!="undefined") && (vf.cstid.value!='')) {
1.12 www 669: foundid=1;
670: }
671: if (founduname==0) {
672: alert('You need to specify at least the username and domain fields');
673: return;
674: }
1.24 albertel 675: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
1.12 www 676: }
677:
1.24 albertel 678: $javascript_validations
1.12 www 679:
1.24 albertel 680: function clearpwd(vf) {
681: //nothing else needs clearing
1.15 albertel 682: }
683:
1.12 www 684: </script>
1.11 www 685: <h3>Personal Data</h3>
1.50 matthew 686: <table>
687: <tr><td>First Name:</td><td> <input type="text" name="cfirst" size="15"></td></tr>
688: <tr><td>Middle Name:</td><td> <input type="text" name="cmiddle" size="15"></td></tr>
689: <tr><td>Last Name: </td><td><input type="text" name="clast" size="15"></td></tr>
690: <tr><td>Generation: </td><td><input type="text" name="cgen" size="5"> </td></tr>
691: </table>
1.11 www 692:
1.12 www 693: <h3>Login Data</h3>
1.26 matthew 694: <p>Username: <input type="text" name="cuname" size="15"></p>
1.29 matthew 695: <p>Domain: $domform</p>
1.26 matthew 696: <p>Note: login settings below will not take effect if the user already exists
697: </p><p>
1.28 matthew 698: $krbform
1.26 matthew 699: </p><p>
1.28 matthew 700: $intform
1.26 matthew 701: </p><p>
1.28 matthew 702: $locform
1.26 matthew 703: </p><p>
1.50 matthew 704:
705: <h3>Course Data</h3>
706:
707: <p>Group/Section: <input type="text" name="csec" size="5" />
708: <p>
709: <!-- Date setting form elements -->
710: <input type="hidden" name="pres_value" value='' />
711: <input type="hidden" name="pres_type" value='' />
712: <input type="hidden" name="pres_marker" value='' />
713: <input type="hidden" name="startdate" value='$today' />
714: <input type="hidden" name="enddate" value='$halfyear' />
1.26 matthew 715: </p><p>
1.11 www 716: <a
717: href="javascript:pjump('date_start','Enrollment Starting Date',document.studentform.startdate.value,'start','studentform.pres','dateset');"
1.26 matthew 718: >Set Starting Date</a>
719: </p><p>
1.11 www 720: <a
721: href="javascript:pjump('date_end','Enrollment Ending Date',document.studentform.enddate.value,'end','studentform.pres','dateset');"
1.26 matthew 722: >Set Ending Date</a>
1.50 matthew 723: </p>
724: <h3>ID/Student Number</h3>
725: <p>
726: ID/Student Number: <input type="text" name="cstid" size="10">
1.26 matthew 727: </p><p>
728: <input type="checkbox" name="forceid" value="yes">
1.18 www 729: Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
1.50 matthew 730: (only do if you know what you are doing)
731: </p><p>
732: <input type="button" onClick="verify(this.form)" value="Enroll as student">
1.26 matthew 733: </p>
1.50 matthew 734: END
735: return;
1.10 www 736: }
737:
738: # ========================================================= Menu Phase Two Drop
1.51 matthew 739: sub print_drop_menu {
1.10 www 740: my $r=shift;
1.40 matthew 741: $r->print("<h3>Drop Students</h3>");
1.11 www 742: my $cid=$ENV{'request.course.id'};
1.56 matthew 743: my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
744: if (! defined($classlist)) {
1.27 matthew 745: $r->print("There are no students currently enrolled.\n");
1.51 matthew 746: return;
1.25 matthew 747: }
1.51 matthew 748: # Print out the available choices
1.56 matthew 749: &show_drop_list($r,$classlist,$keylist);
1.51 matthew 750: return;
1.11 www 751: }
752:
1.40 matthew 753: # ============================================== view classlist
1.50 matthew 754: sub print_html_classlist {
1.40 matthew 755: my $r=shift;
1.57 matthew 756: if (! exists($ENV{'form.sortby'})) {
757: $ENV{'form.sortby'} = 'username';
758: }
1.59 matthew 759: if ($ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) {
1.57 matthew 760: $ENV{'form.Status'} = 'Active';
761: }
762: my $status_select = &Apache::lonhtmlcommon::StatusOptions
763: ($ENV{'form.Status'},'studentform');
1.48 matthew 764: $r->print(<<END);
1.58 matthew 765: <input type="hidden" name="action" value="$ENV{'form.action'}" />
1.57 matthew 766: <input type="hidden" name="state" value="" />
1.50 matthew 767: <p>
1.57 matthew 768: <font size="+1">Current Classlist</font>
769:
1.59 matthew 770: END
771: if ($ENV{'form.action'} ne 'modifystudent') {
772: $r->print(<<END);
1.57 matthew 773: <font size="+1">
774: <a href="javascript:document.studentform.state.value='csv';document.studentform.submit();">CSV format</a>
1.60 ! matthew 775: <a href="javascript:document.studentform.state.value='excel';document.studentform.submit();">Excel format</a>
1.57 matthew 776: </font>
777:
1.48 matthew 778: END
1.59 matthew 779: }
780: $r->print($status_select."</p>\n");
1.40 matthew 781: my $cid=$ENV{'request.course.id'};
1.56 matthew 782: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
783: if (! defined($classlist)) {
1.40 matthew 784: $r->print("There are no students currently enrolled.\n");
785: } else {
786: # Print out the available choices
1.50 matthew 787: if ($ENV{'form.action'} eq 'modifystudent') {
1.53 matthew 788: &show_class_list($r,'view','modify','modifystudent',
1.57 matthew 789: $ENV{'form.Status'},$classlist,$keylist);
1.50 matthew 790: } else {
1.53 matthew 791: &show_class_list($r,'view','aboutme','classlist',
1.57 matthew 792: $ENV{'form.Status'},$classlist,$keylist);
1.50 matthew 793: }
1.41 matthew 794: }
795: }
796:
797: # ============================================== view classlist
1.60 ! matthew 798: sub print_formatted_classlist {
1.41 matthew 799: my $r=shift;
1.60 ! matthew 800: my $mode = shift;
1.41 matthew 801: my $cid=$ENV{'request.course.id'};
1.56 matthew 802: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
803: if (! defined($classlist)) {
1.41 matthew 804: $r->print("There are no students currently enrolled.\n");
805: } else {
1.60 ! matthew 806: &show_class_list($r,$mode,'nolink','csv',
1.57 matthew 807: $ENV{'form.Status'},$classlist,$keylist);
1.40 matthew 808: }
809: }
810:
811: # =================================================== Show student list to drop
812: sub show_class_list {
1.56 matthew 813: my ($r,$mode,$linkto,$action,$statusmode,$classlist,$keylist)=@_;
1.40 matthew 814: my $cid=$ENV{'request.course.id'};
1.60 ! matthew 815: #
! 816: # Variables for excel output
! 817: my ($excel_workbook, $excel_sheet, $excel_filename,$row);
! 818: #
1.53 matthew 819: my $sortby = $ENV{'form.sortby'};
820: if ($sortby !~ /^(username|domain|section|fullname|id)$/) {
821: $sortby = 'username';
822: }
1.42 matthew 823: # Print out header
1.41 matthew 824: if ($mode eq 'view') {
1.50 matthew 825: if ($linkto eq 'aboutme') {
1.56 matthew 826: $r->print('Select a user name to view the users personal page.');
1.50 matthew 827: } elsif ($linkto eq 'modify') {
828: $r->print('Select a user name to modify the students information');
829: }
1.41 matthew 830: $r->print(<<END);
1.59 matthew 831:
1.53 matthew 832: <input type="hidden" name="sortby" value="$sortby" />
1.59 matthew 833: <input type="hidden" name="sname" value="" />
834: <input type="hidden" name="sdom" value="" />
1.40 matthew 835: <p>
836: <table border=2>
1.53 matthew 837: <tr><th>
1.57 matthew 838: <a href="javascript:document.studentform.sortby.value='username';document.studentform.submit();">username</a>
1.53 matthew 839: </th><th>
1.57 matthew 840: <a href="javascript:document.studentform.sortby.value='domain';document.studentform.submit();">domain</a>
1.53 matthew 841: </th><th>
1.57 matthew 842: <a href="javascript:document.studentform.sortby.value='id';document.studentform.submit();">ID</a>
1.53 matthew 843: </th><th>
1.57 matthew 844: <a href="javascript:document.studentform.sortby.value='fullname';document.studentform.submit();">student name</a>
1.53 matthew 845: </th><th>
1.57 matthew 846: <a href="javascript:document.studentform.sortby.value='section';document.studentform.submit();">section</a>
1.53 matthew 847: </th>
848: </tr>
1.40 matthew 849: END
1.41 matthew 850: } elsif ($mode eq 'csv') {
1.58 matthew 851: if($statusmode eq 'Expired') {
852: $r->print('"Students with expired roles"');
853: }
854: if ($statusmode eq 'Any') {
855: $r->print('"'.join('","',("username","domain","ID","student name",
856: "section","status")).'"'."\n");
857: } else {
858: $r->print('"'.join('","',("username","domain","ID","student name",
859: "section")).'"'."\n");
860: }
1.60 ! matthew 861: } elsif ($mode eq 'excel') {
! 862: # Create the excel spreadsheet
! 863: $excel_filename = '/prtspool/'.
! 864: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
! 865: time.'_'.rand(1000000000).'.xls';
! 866: $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.
! 867: $excel_filename);
! 868: $excel_workbook->set_tempdir('/home/httpd/perl/tmp');
! 869: $excel_sheet = $excel_workbook->addworksheet('classlist');
! 870: #
! 871: my $description = 'Classlist for '.
! 872: $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
! 873: $excel_sheet->write($row++,0,$description);
! 874: #
! 875: $excel_sheet->write($row++,0,["username","domain","ID",
! 876: "student name","section","status"]);
1.41 matthew 877: }
1.56 matthew 878: #
879: # Sort the students
880: my %index;
881: my $i;
882: foreach (@$keylist) {
883: $index{$_} = $i++;
884: }
885: my $index = $index{$sortby};
886: my $second = $index{'username'};
887: my $third = $index{'domain'};
1.53 matthew 888: my @Sorted_Students = sort {
1.56 matthew 889: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
890: ||
891: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
892: ||
893: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
894: } (keys(%$classlist));
1.53 matthew 895: foreach my $student (@Sorted_Students) {
1.56 matthew 896: my $username = $classlist->{$student}->[$index{'username'}];
897: my $domain = $classlist->{$student}->[$index{'domain'}];
898: my $section = $classlist->{$student}->[$index{'section'}];
899: my $name = $classlist->{$student}->[$index{'fullname'}];
900: my $id = $classlist->{$student}->[$index{'id'}];
901: my $status = $classlist->{$student}->[$index{'status'}];
1.57 matthew 902: next if (($statusmode ne 'Any') && ($status ne $statusmode));
1.51 matthew 903: if ($mode eq 'view') {
904: $r->print("<tr>\n <td>\n ");
905: if ($linkto eq 'nothing') {
906: $r->print($username);
907: } elsif ($linkto eq 'aboutme') {
908: $r->print(&Apache::loncommon::aboutmewrapper($username,
909: $username,
910: $domain));
911: } elsif ($linkto eq 'modify') {
1.59 matthew 912: $r->print('<a href="'.
913: "javascript:document.studentform.sname.value='".
914: $username.
915: "';document.studentform.sdom.value='".$domain.
916: "';document.studentform.state.value='selected".
917: "';document.studentform.submit();".'">'.
1.53 matthew 918: $username."</a>\n");
1.50 matthew 919: }
1.51 matthew 920: $r->print(<<"END");
1.50 matthew 921: </td>
1.51 matthew 922: <td>$domain</td>
923: <td>$id</td>
924: <td>$name</td>
925: <td>$section</td>
1.40 matthew 926: </tr>
927: END
1.51 matthew 928: } elsif ($mode eq 'csv') {
929: # no need to bother with $linkto
930: my @line = ();
931: foreach ($username,$domain,$id,$name,$section) {
932: push @line,&Apache::loncommon::csv_translate($_);
1.58 matthew 933: }
934: if ($statusmode eq 'Any') {
935: push @line,&Apache::loncommon::csv_translate($status);
1.41 matthew 936: }
1.51 matthew 937: my $tmp = $";
938: $" = '","';
939: $r->print("\"@line\"\n");
940: $" = $tmp;
1.60 ! matthew 941: } elsif ($mode eq 'excel') {
! 942: $excel_sheet->write($row++,0,[$username,$domain,$id,
! 943: $name,$section,$status]);
1.40 matthew 944: }
945: }
1.60 ! matthew 946: if ($mode eq 'view') {
! 947: $r->print('</table><br>');
! 948: } elsif ($mode eq 'excel') {
! 949: $excel_workbook->close();
! 950: $r->print('<p><a href="'.$excel_filename.'">'.
! 951: 'Your Excel spreadsheet</a> is ready for download.</p>'."\n");
! 952: }
1.40 matthew 953: }
954:
1.50 matthew 955:
956: #
957: # print out form for modification of a single students data
958: #
959: sub print_modify_student_form {
960: my $r = shift();
961: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.59 matthew 962: ['sdom','sname']);
1.53 matthew 963: my $sname = $ENV{'form.sname'};
964: my $sdom = $ENV{'form.sdom'};
965: my $sortby = $ENV{'form.sortby'};
1.50 matthew 966: # determine the students name information
967: my %info=&Apache::lonnet::get('environment',
968: ['firstname','middlename',
1.52 matthew 969: 'lastname','generation','id'],
1.50 matthew 970: $sdom, $sname);
971: my ($tmp) = keys(%info);
972: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
973: $r->print('<font color="#ff0000" size="+2">Error</font>'.
974: '<p>'.
975: 'Unable to retrieve environment data for '.$sname.
976: 'in domain '.$sdom.'</p><p>'.
977: 'Please contact your LON-CAPA administrator '.
978: 'regarding this situation.</p></body></html>');
979: return;
980: }
981: # determine the students starting and ending times and section
982: my ($starttime,$endtime,$section) = &get_enrollment_data($sname,$sdom);
983: # Deal with date forms
984: my $startdateform = &Apache::lonhtmlcommon::date_setter('studentform',
985: 'startdate',
986: $starttime);
987: my $enddateform = &Apache::lonhtmlcommon::date_setter('studentform',
988: 'enddate',
989: $endtime);
1.59 matthew 990: #
991: if (! exists($ENV{'form.Status'}) ||
992: $ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) {
993: $ENV{'form.Status'} = 'crap';
994: }
1.50 matthew 995: # Make sure student is enrolled in course
996: $r->print(<<END);
1.52 matthew 997: <p>
998: <font size="+1">
999: Only domain coordinators can change a users password.
1000: </font>
1001: </p>
1.50 matthew 1002: <input type="hidden" name="slogin" value="$sname" />
1003: <input type="hidden" name="sdomain" value="$sdom" />
1004: <input type="hidden" name="action" value="modifystudent" />
1.53 matthew 1005: <input type="hidden" name="state" value="done" />
1006: <input type="hidden" name="sortby" value="$sortby" />
1.59 matthew 1007: <input type="hidden" name="Status" value="$ENV{'form.Status'}" />
1008:
1.50 matthew 1009: <h2>Modify Enrollment for $info{'firstname'} $info{'middlename'}
1010: $info{'lastname'} $info{'generation'}, $sname\@$sdom</h2>
1011: <p>
1012: <b>Student Name</b>
1013: <table>
1014: <tr><th>First</th><th>Middle</th><th>Last</th><th>Generation</th></tr>
1015: <tr><td>
1016: <input type="text" name="firstname" value="$info{'firstname'}" /></td><td>
1017: <input type="text" name="middlename" value="$info{'middlename'}" /></td><td>
1018: <input type="text" name="lastname" value="$info{'lastname'}" /></td><td>
1019: <input type="text" name="generation" value="$info{'generation'}" /></td></tr>
1020: </table>
1021: </p><p>
1.52 matthew 1022: <b>Student ID</b>: <input type="text" name="id" value="$info{'id'}" size="12"/>
1023: </p><p>
1.53 matthew 1024: <input type="checkbox" name="forceid" >
1025: Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
1026: (only do if you know what you are doing)
1027: </p><p>
1.50 matthew 1028: <b>Section</b>: <input type="text" name="section" value="$section" size="4"/>
1029: </p><p>
1030: <table>
1031: <tr><td align="right"><b>Starting Date:</b></td><td>$startdateform</td></tr>
1032: <tr><td align="right"><b>Ending Date:</b></td><td>$enddateform</td></tr>
1033: </table>
1034: </p>
1035: <input type="submit" value="Submit Modifications" />
1036: </body></html>
1037: END
1038: return;
1039: }
1040:
1041: #
1042: # modify a single students section
1043: #
1044: sub modify_single_student {
1045: my $r = shift;
1.59 matthew 1046: # Get the 'sortby' and 'Status' variables so the user goes back to their
1047: # previous screen
1.53 matthew 1048: my $sortby = $ENV{'form.sortby'};
1.59 matthew 1049: my $status = $ENV{'form.Status'};
1.53 matthew 1050: #
1051: # We always need this information
1052: my $slogin = $ENV{'form.slogin'};
1053: my $sdom = $ENV{'form.sdomain'};
1054: #
1055: # Get the old data
1056: my %old=&Apache::lonnet::get('environment',
1057: ['firstname','middlename',
1058: 'lastname','generation','id'],
1059: $sdom, $slogin);
1.59 matthew 1060: $old{'section'} = &Apache::lonnet::getsection($sdom,$slogin,
1061: $ENV{'request.course.id'});
1.53 matthew 1062: my ($tmp) = keys(%old);
1063: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1064: $r->print("There was an error determining the environment values ".
1065: " for $slogin \@ $sdom.");
1066: return;
1067: }
1068: undef $tmp;
1069: #
1070: # Get the new data
1.50 matthew 1071: my $firstname = $ENV{'form.firstname'};
1072: my $middlename = $ENV{'form.middlename'};
1073: my $lastname = $ENV{'form.lastname'};
1074: my $generation = $ENV{'form.generation'};
1075: my $section = $ENV{'form.section'};
1076: my $courseid = $ENV{'request.course.id'};
1.52 matthew 1077: my $sid = $ENV{'form.id'};
1.50 matthew 1078: my $starttime = &Apache::lonhtmlcommon::get_date_from_form('startdate',
1079: time);
1080: my $endtime = &Apache::lonhtmlcommon::get_date_from_form('enddate',
1081: time);
1082: my $displayable_starttime = localtime($starttime);
1083: my $displayable_endtime = localtime($endtime);
1.53 matthew 1084: #
1085: # check for forceid override
1086: if (($sid ne $old{'id'}) && (! exists($ENV{'form.forceid'}))) {
1087: $r->print("<font color=\"ff0000\">You changed the students id ".
1088: " but did not disable the ID change safeguard.".
1089: " The students id will not be changed.</font>");
1090: $sid = $old{'id'};
1091: }
1092: #
1.50 matthew 1093: # talk to the user about what we are going to do
1094: $r->print(<<END);
1.53 matthew 1095: <h2>Modifying data for user $slogin \@ $sdom </h2>
1.50 matthew 1096: <h3>Student Information</h3>
1.53 matthew 1097: <table rules="rows" border="1" cellpadding="3" >
1098: <tr>
1099: <th> Field </th>
1100: <th> Old Value </th>
1101: <th> New Value </th>
1102: </tr>
1103: <tr>
1104: <td> <b>First name</b> </td>
1105: <td> $old{'firstname'} </td>
1106: <td> $firstname </td>
1107: </tr><tr>
1108: <td> <b>Middle name</b> </td>
1109: <td> $old{'middlename'} </td>
1110: <td> $middlename </td>
1111: </tr><tr>
1112: <td> <b>Last name</b> </td>
1113: <td> $old{'lastname'} </td>
1114: <td> $lastname </td>
1115: </tr><tr>
1116: <td> <b>Generation</b> </td>
1117: <td> $old{'generation'} </td>
1118: <td> $generation </td>
1119: </tr><tr>
1120: <td> <b>ID</b> </td>
1121: <td> $old{'id'} </td>
1122: <td> $sid </td>
1.59 matthew 1123: </tr><tr>
1124: <td> <b>Section</b> </td>
1125: <td> $old{'section'} </td>
1126: <td> $section</td>
1.53 matthew 1127: </tr>
1.50 matthew 1128: </table>
1129: <h3>Role Information</h3>
1130: <table>
1131: <tr><td>Start Time </td><td> $displayable_starttime </td></tr>
1132: <tr><td>End Time </td><td> $displayable_endtime </td></tr>
1133: </table>
1.52 matthew 1134: <p>
1.50 matthew 1135: END
1.53 matthew 1136: #
1.52 matthew 1137: # Send request(s) to modify data
1138: my $roleresults = &Apache::lonnet::modifystudent
1.53 matthew 1139: ($sdom,$slogin,$sid,undef,undef,$firstname,$middlename,$lastname,
1140: $generation,$section,$endtime,$starttime,$ENV{'form.forceid'});
1141: if ($roleresults eq 'refused' ) {
1.50 matthew 1142: $r->print("Your request to change the role information for this ".
1.53 matthew 1143: "student was refused. You do not appear to have ".
1144: "sufficient authority to change student information.");
1.50 matthew 1145: } elsif ($roleresults !~ /ok/) {
1146: $r->print("An error occurred during the attempt to change the role".
1.52 matthew 1147: " information for this student. <br />".
1148: "The error reported was ".
1.50 matthew 1149: $roleresults);
1.53 matthew 1150: &Apache::lonnet::logthis("londropadd:failed attempt to modify student".
1151: " data for ".$slogin." \@ ".$sdom." by ".
1152: $ENV{'user.name'}." \@ ".$ENV{'user.domain'}.
1153: ":".$roleresults);
1.50 matthew 1154: } else { # everything is okay!
1.52 matthew 1155: $r->print("Student information updated successfully. <br />".
1156: "The student must log out and log in again to see ".
1157: "these changes.");
1.50 matthew 1158: }
1159: $r->print(<<END);
1.52 matthew 1160: </p><p>
1.59 matthew 1161: <input type="hidden" name="action" value="modifystudent" />
1162: <input type="hidden" name="sortby" value="$sortby" />
1163: <input type="hidden" name="Status" value="$status" />
1164: <a href="javascript:document.studentform.submit();">Modify another students data</a>
1.50 matthew 1165: </body></html>
1166: END
1167: return;
1168: }
1169:
1170: sub get_enrollment_data {
1171: my ($sname,$sdomain) = @_;
1172: my $courseid = $ENV{'request.course.id'};
1173: $courseid =~ s:_:/:g;
1174: my %roles = &Apache::lonnet::dump('roles',$sdomain,$sname);
1175: my ($tmp) = keys(%roles);
1176: # Bail out if we were unable to get the students roles
1177: return "666" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
1178: # Go through the roles looking for enrollment in this course
1179: my ($end,$start) = (undef,undef);
1180: my $section = '';
1181: my $count = scalar(keys(%roles));
1182: while (my ($course,$role) = each(%roles)) {
1183: &Apache::lonnet::logthis('course = '.$course.' role = '.$role);
1184: if ($course=~ /^\/$courseid\/*\s*(\w+)*_st$/ ) {
1185: #
1186: # Get active role
1187: $section=$1;
1188: (undef,$end,$start)=split(/\_/,$role);
1189: my $now=time;
1190: my $notactive=0;
1191: if ($start) {
1192: if ($now<$start) { $notactive=1; }
1193: }
1194: if ($end) {
1195: if ($now>$end) { $notactive=1; }
1196: }
1197: unless ($notactive) { return ($start,$end,$section); }
1198: }
1199: }
1200: return ($start,$end,$section);
1201: }
1202:
1.56 matthew 1203: #################################################
1204: #################################################
1205:
1206: =pod
1207:
1208: =item show_drop_list
1209:
1210: Display a list of students to drop
1211: Inputs:
1212:
1213: =over 4
1214:
1215: =item $r, Apache request
1216:
1217: =item $classlist, hash pointer returned from loncoursedata::get_classlist();
1218:
1219: =item $keylist, array pointer returned from loncoursedata::get_classlist()
1220: which describes the order elements are stored in the %$classlist values.
1221:
1222: =item $nosort, if true, sorting links are omitted.
1223:
1224: =back
1225:
1226: =cut
1227:
1228: #################################################
1229: #################################################
1.11 www 1230: sub show_drop_list {
1.56 matthew 1231: my ($r,$classlist,$keylist,$nosort)=@_;
1.11 www 1232: my $cid=$ENV{'request.course.id'};
1.59 matthew 1233: if (! exists($ENV{'form.sortby'})) {
1234: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1235: ['sortby']);
1236: }
1.54 matthew 1237: my $sortby = $ENV{'form.sortby'};
1238: if ($sortby !~ /^(username|domain|section|fullname|id)$/) {
1239: $sortby = 'username';
1240: }
1.56 matthew 1241: #
1.54 matthew 1242: my $action = "drop";
1243: $r->print(<<END);
1244: <input type="hidden" name="sortby" value="$sortby" />
1245: <input type="hidden" name="action" value="$action" />
1.50 matthew 1246: <input type="hidden" name="state" value="done" />
1.32 matthew 1247: <script>
1.51 matthew 1248: function checkAll(field) {
1.32 matthew 1249: for (i = 0; i < field.length; i++)
1250: field[i].checked = true ;
1251: }
1252:
1.51 matthew 1253: function uncheckAll(field) {
1.32 matthew 1254: for (i = 0; i < field.length; i++)
1255: field[i].checked = false ;
1256: }
1257: </script>
1258: <p>
1.26 matthew 1259: <input type="hidden" name="phase" value="four">
1.56 matthew 1260: END
1261:
1262: if ($nosort) {
1263: $r->print(<<END);
1264: <table border=2>
1265: <tr>
1266: <th> </th>
1267: <th>username</th>
1268: <th>domain</th>
1269: <th>ID</th>
1270: <th>student name</th>
1271: <th>section</th>
1272: </tr>
1273: END
1274:
1275: } else {
1276: $r->print(<<END);
1.26 matthew 1277: <table border=2>
1.54 matthew 1278: <tr><th> </th>
1279: <th>
1280: <a href="/adm/dropadd?action=$action&sortby=username">username</a>
1281: </th><th>
1282: <a href="/adm/dropadd?action=$action&sortby=domain">domain</a>
1283: </th><th>
1284: <a href="/adm/dropadd?action=$action&sortby=id">ID</a>
1285: </th><th>
1286: <a href="/adm/dropadd?action=$action&sortby=fullname">student name</a>
1287: </th><th>
1288: <a href="/adm/dropadd?action=$action&sortby=section">section</a>
1289: </th>
1290: </tr>
1.26 matthew 1291: END
1.56 matthew 1292: }
1293: #
1294: # Sort the students
1295: my %index;
1296: my $i;
1297: foreach (@$keylist) {
1298: $index{$_} = $i++;
1299: }
1300: my $index = $index{$sortby};
1301: my $second = $index{'username'};
1302: my $third = $index{'domain'};
1.54 matthew 1303: my @Sorted_Students = sort {
1.56 matthew 1304: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
1305: ||
1306: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
1307: ||
1308: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
1309: } (keys(%$classlist));
1.54 matthew 1310: foreach my $student (@Sorted_Students) {
1.52 matthew 1311: my $error;
1.56 matthew 1312: my $username = $classlist->{$student}->[$index{'username'}];
1313: my $domain = $classlist->{$student}->[$index{'domain'}];
1314: my $section = $classlist->{$student}->[$index{'section'}];
1315: my $name = $classlist->{$student}->[$index{'fullname'}];
1316: my $id = $classlist->{$student}->[$index{'id'}];
1317: my $status = $classlist->{$student}->[$index{'status'}];
1.51 matthew 1318: next if ($status ne 'Active');
1319: #
1320: $r->print(<<"END");
1.26 matthew 1321: <tr>
1.51 matthew 1322: <td><input type="checkbox" name="droplist" value="$student"></td>
1323: <td>$username</td>
1324: <td>$domain</td>
1325: <td>$id</td>
1326: <td>$name</td>
1327: <td>$section</td>
1.26 matthew 1328: </tr>
1329: END
1.25 matthew 1330: }
1331: $r->print('</table><br>');
1.32 matthew 1332: $r->print(<<"END");
1333: </p><p>
1334: <input type="button" value="check all" onclick="javascript:checkAll(document.studentform.droplist)">
1335: <input type="button" value="uncheck all" onclick="javascript:uncheckAll(document.studentform.droplist)">
1336: <p><input type=submit value="Drop Students"></p>
1337: END
1.51 matthew 1338: return;
1.10 www 1339: }
1340:
1.48 matthew 1341: #
1342: # Print out the initial form to get the courselist file
1343: #
1344: sub print_first_courselist_upload_form {
1345: my $r=shift;
1346: my $upfile_select=&Apache::loncommon::upfile_select_html();
1347: my $create_classlist_help =
1348: &Apache::loncommon::help_open_topic("Course_Create_Class_List",
1349: "How do I create a class list from a spreadsheet");
1350: my $create_csv_help =
1351: &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1352: "How do I create a CSV file from a spreadsheet");
1353: $r->print(<<ENDUPFORM);
1354: <input type=hidden name=phase value=two>
1355: <h3>Upload a courselist</h3>
1356: $upfile_select
1.50 matthew 1357: <p>
1358: <input type=submit name="fileupload" value="Upload Courselist">
1359: <input type="hidden" name="action" value="upload" />
1360: <input type="hidden" name="state" value="got_file" />
1361: </p>
1.48 matthew 1362: $create_classlist_help <br />
1363: $create_csv_help
1364: </body></html>
1365: ENDUPFORM
1366: return;
1367: }
1368:
1.10 www 1369: # ================================================= Drop/Add from uploaded file
1370: sub upfile_drop_add {
1371: my $r=shift;
1.24 albertel 1372: &Apache::loncommon::load_tmp_file($r);
1373: my @studentdata=&Apache::loncommon::upfile_record_sep();
1.26 matthew 1374: my @keyfields = split(/\,/,$ENV{'form.keyfields'});
1375: my $cid = $ENV{'request.course.id'};
1.25 matthew 1376: my %fields=();
1.26 matthew 1377: for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
1.25 matthew 1378: if ($ENV{'form.upfile_associate'} eq 'reverse') {
1379: if ($ENV{'form.f'.$i} ne 'none') {
1380: $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
1381: }
1382: } else {
1383: $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
1384: }
1385: }
1.26 matthew 1386: #
1387: my $startdate = $ENV{'form.startdate'};
1388: my $enddate = $ENV{'form.enddate'};
1.25 matthew 1389: if ($startdate=~/\D/) { $startdate=''; }
1.26 matthew 1390: if ($enddate=~/\D/) { $enddate=''; }
1.31 matthew 1391: # Determine domain and desired host (home server)
1.25 matthew 1392: my $domain=$ENV{'form.lcdomain'};
1.31 matthew 1393: my $desiredhost = $ENV{'form.lcserver'};
1394: if (lc($desiredhost) eq 'default') {
1395: $desiredhost = undef;
1396: } else {
1.45 matthew 1397: my %home_servers = &Apache::loncommon::get_library_servers($domain);
1.31 matthew 1398: if (! exists($home_servers{$desiredhost})) {
1399: $r->print('<font color="#ff0000">Error:</font>'.
1400: 'Invalid home server specified');
1401: return;
1402: }
1403: }
1.26 matthew 1404: # Determine authentication mechanism
1405: my $amode = '';
1406: my $genpwd = '';
1.25 matthew 1407: if ($ENV{'form.login'} eq 'krb') {
1.47 albertel 1408: $amode='krb';
1409: $amode.=$ENV{'form.krbver'};
1.28 matthew 1410: $genpwd=$ENV{'form.krbarg'};
1.25 matthew 1411: } elsif ($ENV{'form.login'} eq 'int') {
1412: $amode='internal';
1.28 matthew 1413: if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
1414: $genpwd=$ENV{'form.intarg'};
1.25 matthew 1415: }
1416: } elsif ($ENV{'form.login'} eq 'loc') {
1417: $amode='localauth';
1418: if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
1419: $genpwd=$ENV{'form.locarg'};
1420: }
1421: }
1422: unless (($domain=~/\W/) || ($amode eq '')) {
1.26 matthew 1423: #######################################
1424: ## Enroll Students ##
1425: #######################################
1.25 matthew 1426: $r->print('<h3>Enrolling Students</h3>');
1427: my $count=0;
1428: my $flushc=0;
1429: my %student=();
1.26 matthew 1430: # Get new classlist
1.25 matthew 1431: foreach (@studentdata) {
1432: my %entries=&Apache::loncommon::record_sep($_);
1.26 matthew 1433: # Determine student name
1.25 matthew 1434: unless (($entries{$fields{'username'}} eq '') ||
1435: (!defined($entries{$fields{'username'}}))) {
1.26 matthew 1436: my ($fname, $mname, $lname,$gen) = ('','','','');
1.25 matthew 1437: if (defined($fields{'names'})) {
1.26 matthew 1438: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
1439: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
1.25 matthew 1440: } else {
1441: if (defined($fields{'fname'})) {
1442: $fname=$entries{$fields{'fname'}};
1443: }
1444: if (defined($fields{'mname'})) {
1445: $mname=$entries{$fields{'mname'}};
1446: }
1447: if (defined($fields{'lname'})) {
1448: $lname=$entries{$fields{'lname'}};
1449: }
1450: if (defined($fields{'gen'})) {
1451: $gen=$entries{$fields{'gen'}};
1452: }
1453: }
1454: if ($entries{$fields{'username'}}=~/\W/) {
1455: $r->print('<p><b>Unacceptable username: '.
1.10 www 1456: $entries{$fields{'username'}}.' for user '.
1.4 www 1457: $fname.' '.$mname.' '.$lname.' '.$gen.'</b><p>');
1.25 matthew 1458: } else {
1.26 matthew 1459: # determine section number
1.25 matthew 1460: my $sec='';
1461: my $username=$entries{$fields{'username'}};
1462: if (defined($fields{'sec'})) {
1463: if (defined($entries{$fields{'sec'}})) {
1464: $sec=$entries{$fields{'sec'}};
1465: }
1466: }
1.26 matthew 1467: # determine student id number
1.25 matthew 1468: my $id='';
1469: if (defined($fields{'id'})) {
1470: if (defined($entries{$fields{'id'}})) {
1471: $id=$entries{$fields{'id'}};
1472: }
1473: $id=~tr/A-Z/a-z/;
1474: }
1.26 matthew 1475: # determine student password
1.25 matthew 1476: my $password='';
1477: if ($genpwd) {
1478: $password=$genpwd;
1479: } else {
1480: if (defined($fields{'ipwd'})) {
1481: if ($entries{$fields{'ipwd'}}) {
1482: $password=$entries{$fields{'ipwd'}};
1483: }
1484: }
1485: }
1.56 matthew 1486: # Clean up whitespace
1487: foreach (\$domain,\$username,\$id,\$fname,\$mname,
1488: \$lname,\$gen,\$sec) {
1489: $$_ =~ s/(\s+$|^\s+)//g;
1490: }
1.25 matthew 1491: if ($password) {
1.33 matthew 1492: &modifystudent($domain,$username,$cid,$sec,
1493: $desiredhost);
1.25 matthew 1494: my $reply=&Apache::lonnet::modifystudent
1495: ($domain,$username,$id,$amode,$password,
1496: $fname,$mname,$lname,$gen,$sec,$enddate,
1.31 matthew 1497: $startdate,$ENV{'form.forceid'},$desiredhost);
1.26 matthew 1498: if ($reply ne 'ok') {
1499: $r->print('<p><b>'.
1500: 'Error enrolling '.$username.': '.
1501: $reply.'</b></p>');
1.10 www 1502: } else {
1.7 www 1503: $count++; $flushc++;
1504: $student{$username}=1;
1.6 www 1505: $r->print('. ');
1.7 www 1506: if ($flushc>15) {
1507: $r->rflush;
1508: $flushc=0;
1509: }
1.6 www 1510: }
1.25 matthew 1511: } else {
1512: $r->print("<p><b>No password for $username</b><p>");
1513: }
1514: }
1.26 matthew 1515: }
1516: } # end of foreach (@studentdata)
1.55 matthew 1517: $r->print('<p>Processed Students: '.$count.'</p>');
1518: $r->print("<p>If active, the new role will be available when the ".
1519: "students next log in to LON-CAPA.</p>");
1.26 matthew 1520: #####################################
1521: # Drop students #
1522: #####################################
1.25 matthew 1523: if ($ENV{'form.fullup'} eq 'yes') {
1524: $r->print('<h3>Dropping Students</h3>');
1.26 matthew 1525: # Get current classlist
1.56 matthew 1526: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
1527: if (! defined($classlist)) {
1528: $r->print("There are no students currently enrolled.\n");
1529: } else {
1530: # Remove the students we just added from the list of students.
1.25 matthew 1531: foreach (@studentdata) {
1532: my %entries=&Apache::loncommon::record_sep($_);
1533: unless (($entries{$fields{'username'}} eq '') ||
1534: (!defined($entries{$fields{'username'}}))) {
1.56 matthew 1535: delete($classlist->{$entries{$fields{'username'}}.
1.26 matthew 1536: ':'.$domain});
1.25 matthew 1537: }
1538: }
1.56 matthew 1539: # Print out list of dropped students.
1540: &show_drop_list($r,$classlist,$keylist,'nosort');
1.25 matthew 1541: }
1542: }
1.26 matthew 1543: } # end of unless
1.10 www 1544: }
1545:
1.11 www 1546: # ================================================================== Phase four
1547: sub drop_student_list {
1548: my $r=shift;
1549: my $count=0;
1.35 matthew 1550: my @droplist;
1551: if (ref($ENV{'form.droplist'})) {
1552: @droplist = @{$ENV{'form.droplist'}};
1553: } else {
1554: @droplist = ($ENV{'form.droplist'});
1555: }
1556: foreach (@droplist) {
1.26 matthew 1557: my ($uname,$udom)=split(/\:/,$_);
1.56 matthew 1558: # drop student
1.35 matthew 1559: my $result = &modifystudent($udom,$uname,$ENV{'request.course.id'});
1.37 matthew 1560: if ($result eq 'ok' || $result eq 'ok:') {
1.54 matthew 1561: $r->print('Dropped '.$uname.' @ '.$udom.'<br>');
1.59 matthew 1562: $count++;
1.35 matthew 1563: } else {
1.54 matthew 1564: $r->print('Error dropping '.$uname.' @ '.$udom.': '.$result.
1.35 matthew 1565: '<br />');
1566: }
1.20 harris41 1567: }
1.11 www 1568: $r->print('<p><b>Dropped '.$count.' student(s).</b>');
1.59 matthew 1569: $r->print('<p>Re-enrollment will re-activate data.') if ($count);
1.11 www 1570: }
1571:
1.50 matthew 1572: ###################################################################
1573: ###################################################################
1574:
1575: =pod
1576:
1577: =item &handler
1578:
1579: The typical handler you see in all these modules. Takes $r, the
1580: http request, as an argument.
1581:
1582: The response to the request is governed by two form variables
1583:
1584: form.action form.state response
1585: ---------------------------------------------------
1586: undefined undefined print main menu
1587: upload undefined print courselist upload menu
1588: upload got_file deal with uploaded file,
1589: print the upload managing menu
1590: upload enrolling enroll students based on upload
1591: drop undefined print the classlist ready to drop
1592: drop done drop the selected students
1593: enrollstudent undefined print single student enroll menu
1594: enrollstudent enrolling enroll student
1595: classlist undefined print html classlist
1596: classlist csv print csv classlist
1597: modifystudent undefined print classlist to select student to modify
1598: modifystudent selected print modify student menu
1599: modifystudent done make modifications to student record
1600:
1601: =cut
1602:
1603: ###################################################################
1604: ###################################################################
1.10 www 1605: sub handler {
1.26 matthew 1606: my $r=shift;
1607: if ($r->header_only) {
1608: $r->content_type('text/html');
1609: $r->send_http_header;
1610: return OK;
1611: }
1.48 matthew 1612: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.50 matthew 1613: ['action','state']);
1.26 matthew 1614: # Needs to be in a course
1.50 matthew 1615: if (! (($ENV{'request.course.fn'}) &&
1616: (&Apache::lonnet::allowed('cst',$ENV{'request.course.id'})))) {
1617: # Not in a course, or not allowed to modify parms
1618: $ENV{'user.error.msg'}=
1619: "/adm/dropadd:cst:0:0:Cannot drop or add students";
1620: return HTTP_NOT_ACCEPTABLE;
1621: }
1622: #
1623: # Only output the header information if they did not request csv format
1624: #
1625: if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) {
1626: $r->content_type('text/csv');
1627: } else {
1.26 matthew 1628: # Start page
1.50 matthew 1629: $r->content_type('text/html');
1.26 matthew 1630: $r->send_http_header;
1.50 matthew 1631: $r->print(&header());
1632: }
1633: #
1634: # Main switch on form.action and form.state, as appropriate
1635: if (! exists($ENV{'form.action'})) {
1636: &print_main_menu($r);
1637: } elsif ($ENV{'form.action'} eq 'upload') {
1638: if (! exists($ENV{'form.state'})) {
1639: &print_first_courselist_upload_form($r);
1640: } elsif ($ENV{'form.state'} eq 'got_file') {
1641: &print_upload_manager_form($r);
1642: } elsif ($ENV{'form.state'} eq 'enrolling') {
1.26 matthew 1643: if ($ENV{'form.datatoken'}) {
1644: &upfile_drop_add($r);
1.50 matthew 1645: } else {
1646: # Hmmm, this is an error
1.26 matthew 1647: }
1.50 matthew 1648: } else {
1649: &print_first_courselist_upload_form($r);
1.26 matthew 1650: }
1.50 matthew 1651: } elsif ($ENV{'form.action'} eq 'drop') {
1652: if (! exists($ENV{'form.state'})) {
1.51 matthew 1653: &print_drop_menu($r);
1.50 matthew 1654: } elsif ($ENV{'form.state'} eq 'done') {
1.26 matthew 1655: &drop_student_list($r);
1.50 matthew 1656: } else {
1.55 matthew 1657: &print_drop_menu($r);
1.26 matthew 1658: }
1.50 matthew 1659: } elsif ($ENV{'form.action'} eq 'enrollstudent') {
1660: if (! exists($ENV{'form.state'})) {
1661: &print_enroll_single_student_form($r);
1662: } elsif ($ENV{'form.state'} eq 'enrolling') {
1.26 matthew 1663: &enroll_single_student($r);
1.50 matthew 1664: } else {
1665: &print_enroll_single_student_form($r);
1.26 matthew 1666: }
1.50 matthew 1667: } elsif ($ENV{'form.action'} eq 'classlist') {
1668: if (! exists($ENV{'form.state'})) {
1669: &print_html_classlist($r);
1670: } elsif ($ENV{'form.state'} eq 'csv') {
1.60 ! matthew 1671: &print_formatted_classlist($r,'csv');
! 1672: } elsif ($ENV{'form.state'} eq 'excel') {
! 1673: &print_formatted_classlist($r,'excel');
1.50 matthew 1674: } else {
1675: &print_html_classlist($r);
1676: }
1677: } elsif ($ENV{'form.action'} eq 'modifystudent') {
1678: if (! exists($ENV{'form.state'})) {
1679: &print_html_classlist($r);
1680: } elsif ($ENV{'form.state'} eq 'selected') {
1681: &print_modify_student_form($r);
1682: } elsif ($ENV{'form.state'} eq 'done') {
1683: &modify_single_student($r);
1684: } else {
1685: &print_html_classlist($r);
1686: }
1687: } else {
1688: # We should not end up here, but I guess it is possible
1689: &Apache::lonnet::logthis("Undetermined state in londropadd.pm. ".
1690: "form.action = ".$ENV{'form.action'}.
1691: "Someone should fix this.");
1692: &print_main_menu($r);
1693: }
1694: #
1695: # Finish up
1696: if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) {
1697: $r->print("\n");
1.26 matthew 1698: } else {
1.50 matthew 1699: $r->print('</form></body></html>');
1.26 matthew 1700: }
1701: return OK;
1.1 www 1702: }
1703:
1.50 matthew 1704: ###################################################################
1705: ###################################################################
1706:
1.1 www 1707: 1;
1708: __END__
1.50 matthew 1709:
1.1 www 1710:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>