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