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