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