Annotation of loncom/interface/londropadd.pm, revision 1.68
1.1 www 1: # The LearningOnline Network with CAPA
2: # Handler to drop and add students in courses
3: #
1.68 ! matthew 4: # $Id: londropadd.pm,v 1.67 2003/06/20 18:34:52 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 />";
! 663: } else {
! 664: $result .= "Unable to set default dates for course:".$put_result.
! 665: '<br />';
! 666: }
! 667: return $result;
! 668: }
! 669:
1.10 www 670: # ======================================================= Menu Phase Two Enroll
1.50 matthew 671: sub print_enroll_single_student_form {
1.10 www 672: my $r=shift;
1.40 matthew 673: $r->print("<h3>Enroll One Student</h3>");
1.26 matthew 674: my $today = time;
675: my $halfyear = $today+15552000;
1.11 www 676: my $defdom=$r->dir_config('lonDefDomain');
1.64 albertel 677: # Set up authentication forms
678: my ($krbdef,$krbdefdom) =
679: &Apache::loncommon::get_kerberos_defaults($defdom);
1.24 albertel 680: my $javascript_validations=&javascript_validations($krbdefdom);
1.64 albertel 681: my %param = ( formname => 'document.studentform',
682: kerb_def_dom => $krbdefdom,
683: kerb_def_auth => $krbdef
684: );
1.28 matthew 685: my $krbform = &Apache::loncommon::authform_kerberos(%param);
686: my $intform = &Apache::loncommon::authform_internal(%param);
687: my $locform = &Apache::loncommon::authform_local(%param);
1.29 matthew 688: # Set up domain selection form
1.31 matthew 689: my $domform = &domain_form($defdom);
1.68 ! matthew 690: my $date_table = &date_setting_table();
1.28 matthew 691: # Print it all out
1.50 matthew 692: $r->print(<<END);
693: <input type="hidden" name="action" value="enrollstudent">
694: <input type="hidden" name="state" value="done">
695:
1.28 matthew 696: <script type="text/javascript" language="Javascript">
1.12 www 697: function verify(vf) {
698: var founduname=0;
699: var foundpwd=0;
700: var foundname=0;
701: var foundid=0;
702: var foundsec=0;
703: var tw;
1.26 matthew 704: if ((typeof(vf.cuname.value) !="undefined") && (vf.cuname.value!='') &&
1.31 matthew 705: (typeof(vf.lcdomain.value)!="undefined") && (vf.lcdomain.value!='')) {
1.12 www 706: founduname=1;
707: }
1.14 harris41 708: if ((typeof(vf.cfirst.value)!="undefined") && (vf.cfirst.value!='') &&
1.26 matthew 709: (typeof(vf.clast.value) !="undefined") && (vf.clast.value!='')) {
1.12 www 710: foundname=1;
711: }
1.14 harris41 712: if ((typeof(vf.csec.value)!="undefined") && (vf.csec.value!='')) {
1.12 www 713: foundsec=1;
714: }
1.14 harris41 715: if ((typeof(vf.cstid.value)!="undefined") && (vf.cstid.value!='')) {
1.12 www 716: foundid=1;
717: }
718: if (founduname==0) {
719: alert('You need to specify at least the username and domain fields');
720: return;
721: }
1.24 albertel 722: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
1.12 www 723: }
724:
1.24 albertel 725: $javascript_validations
1.12 www 726:
1.24 albertel 727: function clearpwd(vf) {
728: //nothing else needs clearing
1.15 albertel 729: }
730:
1.12 www 731: </script>
1.11 www 732: <h3>Personal Data</h3>
1.50 matthew 733: <table>
734: <tr><td>First Name:</td><td> <input type="text" name="cfirst" size="15"></td></tr>
735: <tr><td>Middle Name:</td><td> <input type="text" name="cmiddle" size="15"></td></tr>
736: <tr><td>Last Name: </td><td><input type="text" name="clast" size="15"></td></tr>
737: <tr><td>Generation: </td><td><input type="text" name="cgen" size="5"> </td></tr>
738: </table>
1.11 www 739:
1.12 www 740: <h3>Login Data</h3>
1.26 matthew 741: <p>Username: <input type="text" name="cuname" size="15"></p>
1.29 matthew 742: <p>Domain: $domform</p>
1.26 matthew 743: <p>Note: login settings below will not take effect if the user already exists
744: </p><p>
1.28 matthew 745: $krbform
1.26 matthew 746: </p><p>
1.28 matthew 747: $intform
1.26 matthew 748: </p><p>
1.28 matthew 749: $locform
1.26 matthew 750: </p><p>
1.50 matthew 751:
752: <h3>Course Data</h3>
753:
754: <p>Group/Section: <input type="text" name="csec" size="5" />
755: <p>
1.68 ! matthew 756: $date_table
1.50 matthew 757: </p>
758: <h3>ID/Student Number</h3>
759: <p>
760: ID/Student Number: <input type="text" name="cstid" size="10">
1.26 matthew 761: </p><p>
762: <input type="checkbox" name="forceid" value="yes">
1.18 www 763: Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
1.50 matthew 764: (only do if you know what you are doing)
765: </p><p>
766: <input type="button" onClick="verify(this.form)" value="Enroll as student">
1.26 matthew 767: </p>
1.50 matthew 768: END
769: return;
1.10 www 770: }
771:
772: # ========================================================= Menu Phase Two Drop
1.51 matthew 773: sub print_drop_menu {
1.10 www 774: my $r=shift;
1.40 matthew 775: $r->print("<h3>Drop Students</h3>");
1.11 www 776: my $cid=$ENV{'request.course.id'};
1.56 matthew 777: my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
778: if (! defined($classlist)) {
1.27 matthew 779: $r->print("There are no students currently enrolled.\n");
1.51 matthew 780: return;
1.25 matthew 781: }
1.51 matthew 782: # Print out the available choices
1.56 matthew 783: &show_drop_list($r,$classlist,$keylist);
1.51 matthew 784: return;
1.11 www 785: }
786:
1.40 matthew 787: # ============================================== view classlist
1.50 matthew 788: sub print_html_classlist {
1.40 matthew 789: my $r=shift;
1.57 matthew 790: if (! exists($ENV{'form.sortby'})) {
791: $ENV{'form.sortby'} = 'username';
792: }
1.59 matthew 793: if ($ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) {
1.57 matthew 794: $ENV{'form.Status'} = 'Active';
795: }
796: my $status_select = &Apache::lonhtmlcommon::StatusOptions
797: ($ENV{'form.Status'},'studentform');
1.48 matthew 798: $r->print(<<END);
1.58 matthew 799: <input type="hidden" name="action" value="$ENV{'form.action'}" />
1.57 matthew 800: <input type="hidden" name="state" value="" />
1.50 matthew 801: <p>
1.57 matthew 802: <font size="+1">Current Classlist</font>
803:
1.59 matthew 804: END
805: if ($ENV{'form.action'} ne 'modifystudent') {
806: $r->print(<<END);
1.57 matthew 807: <font size="+1">
808: <a href="javascript:document.studentform.state.value='csv';document.studentform.submit();">CSV format</a>
1.61 matthew 809:
1.60 matthew 810: <a href="javascript:document.studentform.state.value='excel';document.studentform.submit();">Excel format</a>
1.57 matthew 811: </font>
812:
1.61 matthew 813: Student Status:
1.48 matthew 814: END
1.59 matthew 815: }
816: $r->print($status_select."</p>\n");
1.40 matthew 817: my $cid=$ENV{'request.course.id'};
1.56 matthew 818: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
819: if (! defined($classlist)) {
1.40 matthew 820: $r->print("There are no students currently enrolled.\n");
821: } else {
822: # Print out the available choices
1.50 matthew 823: if ($ENV{'form.action'} eq 'modifystudent') {
1.53 matthew 824: &show_class_list($r,'view','modify','modifystudent',
1.57 matthew 825: $ENV{'form.Status'},$classlist,$keylist);
1.50 matthew 826: } else {
1.53 matthew 827: &show_class_list($r,'view','aboutme','classlist',
1.57 matthew 828: $ENV{'form.Status'},$classlist,$keylist);
1.50 matthew 829: }
1.41 matthew 830: }
831: }
832:
833: # ============================================== view classlist
1.60 matthew 834: sub print_formatted_classlist {
1.41 matthew 835: my $r=shift;
1.60 matthew 836: my $mode = shift;
1.41 matthew 837: my $cid=$ENV{'request.course.id'};
1.56 matthew 838: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
839: if (! defined($classlist)) {
1.41 matthew 840: $r->print("There are no students currently enrolled.\n");
841: } else {
1.60 matthew 842: &show_class_list($r,$mode,'nolink','csv',
1.57 matthew 843: $ENV{'form.Status'},$classlist,$keylist);
1.40 matthew 844: }
845: }
846:
847: # =================================================== Show student list to drop
848: sub show_class_list {
1.56 matthew 849: my ($r,$mode,$linkto,$action,$statusmode,$classlist,$keylist)=@_;
1.40 matthew 850: my $cid=$ENV{'request.course.id'};
1.60 matthew 851: #
852: # Variables for excel output
853: my ($excel_workbook, $excel_sheet, $excel_filename,$row);
854: #
1.53 matthew 855: my $sortby = $ENV{'form.sortby'};
856: if ($sortby !~ /^(username|domain|section|fullname|id)$/) {
857: $sortby = 'username';
858: }
1.42 matthew 859: # Print out header
1.41 matthew 860: if ($mode eq 'view') {
1.50 matthew 861: if ($linkto eq 'aboutme') {
1.56 matthew 862: $r->print('Select a user name to view the users personal page.');
1.50 matthew 863: } elsif ($linkto eq 'modify') {
864: $r->print('Select a user name to modify the students information');
865: }
1.41 matthew 866: $r->print(<<END);
1.59 matthew 867:
1.53 matthew 868: <input type="hidden" name="sortby" value="$sortby" />
1.59 matthew 869: <input type="hidden" name="sname" value="" />
870: <input type="hidden" name="sdom" value="" />
1.40 matthew 871: <p>
872: <table border=2>
1.53 matthew 873: <tr><th>
1.57 matthew 874: <a href="javascript:document.studentform.sortby.value='username';document.studentform.submit();">username</a>
1.53 matthew 875: </th><th>
1.57 matthew 876: <a href="javascript:document.studentform.sortby.value='domain';document.studentform.submit();">domain</a>
1.53 matthew 877: </th><th>
1.57 matthew 878: <a href="javascript:document.studentform.sortby.value='id';document.studentform.submit();">ID</a>
1.53 matthew 879: </th><th>
1.57 matthew 880: <a href="javascript:document.studentform.sortby.value='fullname';document.studentform.submit();">student name</a>
1.53 matthew 881: </th><th>
1.57 matthew 882: <a href="javascript:document.studentform.sortby.value='section';document.studentform.submit();">section</a>
1.53 matthew 883: </th>
884: </tr>
1.40 matthew 885: END
1.41 matthew 886: } elsif ($mode eq 'csv') {
1.58 matthew 887: if($statusmode eq 'Expired') {
888: $r->print('"Students with expired roles"');
889: }
890: if ($statusmode eq 'Any') {
891: $r->print('"'.join('","',("username","domain","ID","student name",
892: "section","status")).'"'."\n");
893: } else {
894: $r->print('"'.join('","',("username","domain","ID","student name",
895: "section")).'"'."\n");
896: }
1.60 matthew 897: } elsif ($mode eq 'excel') {
898: # Create the excel spreadsheet
899: $excel_filename = '/prtspool/'.
900: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
901: time.'_'.rand(1000000000).'.xls';
902: $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.
903: $excel_filename);
904: $excel_workbook->set_tempdir('/home/httpd/perl/tmp');
905: $excel_sheet = $excel_workbook->addworksheet('classlist');
906: #
907: my $description = 'Classlist for '.
908: $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
909: $excel_sheet->write($row++,0,$description);
910: #
911: $excel_sheet->write($row++,0,["username","domain","ID",
912: "student name","section","status"]);
1.41 matthew 913: }
1.56 matthew 914: #
915: # Sort the students
916: my %index;
917: my $i;
918: foreach (@$keylist) {
919: $index{$_} = $i++;
920: }
921: my $index = $index{$sortby};
922: my $second = $index{'username'};
923: my $third = $index{'domain'};
1.53 matthew 924: my @Sorted_Students = sort {
1.56 matthew 925: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
926: ||
927: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
928: ||
929: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
930: } (keys(%$classlist));
1.53 matthew 931: foreach my $student (@Sorted_Students) {
1.56 matthew 932: my $username = $classlist->{$student}->[$index{'username'}];
933: my $domain = $classlist->{$student}->[$index{'domain'}];
934: my $section = $classlist->{$student}->[$index{'section'}];
935: my $name = $classlist->{$student}->[$index{'fullname'}];
936: my $id = $classlist->{$student}->[$index{'id'}];
937: my $status = $classlist->{$student}->[$index{'status'}];
1.57 matthew 938: next if (($statusmode ne 'Any') && ($status ne $statusmode));
1.51 matthew 939: if ($mode eq 'view') {
940: $r->print("<tr>\n <td>\n ");
941: if ($linkto eq 'nothing') {
942: $r->print($username);
943: } elsif ($linkto eq 'aboutme') {
944: $r->print(&Apache::loncommon::aboutmewrapper($username,
945: $username,
946: $domain));
947: } elsif ($linkto eq 'modify') {
1.59 matthew 948: $r->print('<a href="'.
949: "javascript:document.studentform.sname.value='".
950: $username.
951: "';document.studentform.sdom.value='".$domain.
952: "';document.studentform.state.value='selected".
953: "';document.studentform.submit();".'">'.
1.53 matthew 954: $username."</a>\n");
1.50 matthew 955: }
1.51 matthew 956: $r->print(<<"END");
1.50 matthew 957: </td>
1.51 matthew 958: <td>$domain</td>
959: <td>$id</td>
960: <td>$name</td>
961: <td>$section</td>
1.40 matthew 962: </tr>
963: END
1.51 matthew 964: } elsif ($mode eq 'csv') {
965: # no need to bother with $linkto
966: my @line = ();
967: foreach ($username,$domain,$id,$name,$section) {
968: push @line,&Apache::loncommon::csv_translate($_);
1.58 matthew 969: }
970: if ($statusmode eq 'Any') {
971: push @line,&Apache::loncommon::csv_translate($status);
1.41 matthew 972: }
1.51 matthew 973: my $tmp = $";
974: $" = '","';
975: $r->print("\"@line\"\n");
976: $" = $tmp;
1.60 matthew 977: } elsif ($mode eq 'excel') {
978: $excel_sheet->write($row++,0,[$username,$domain,$id,
979: $name,$section,$status]);
1.40 matthew 980: }
981: }
1.60 matthew 982: if ($mode eq 'view') {
983: $r->print('</table><br>');
984: } elsif ($mode eq 'excel') {
985: $excel_workbook->close();
986: $r->print('<p><a href="'.$excel_filename.'">'.
987: 'Your Excel spreadsheet</a> is ready for download.</p>'."\n");
988: }
1.40 matthew 989: }
990:
1.50 matthew 991:
992: #
993: # print out form for modification of a single students data
994: #
995: sub print_modify_student_form {
996: my $r = shift();
997: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.59 matthew 998: ['sdom','sname']);
1.53 matthew 999: my $sname = $ENV{'form.sname'};
1000: my $sdom = $ENV{'form.sdom'};
1001: my $sortby = $ENV{'form.sortby'};
1.50 matthew 1002: # determine the students name information
1003: my %info=&Apache::lonnet::get('environment',
1004: ['firstname','middlename',
1.52 matthew 1005: 'lastname','generation','id'],
1.50 matthew 1006: $sdom, $sname);
1007: my ($tmp) = keys(%info);
1008: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1009: $r->print('<font color="#ff0000" size="+2">Error</font>'.
1010: '<p>'.
1011: 'Unable to retrieve environment data for '.$sname.
1012: 'in domain '.$sdom.'</p><p>'.
1013: 'Please contact your LON-CAPA administrator '.
1014: 'regarding this situation.</p></body></html>');
1015: return;
1016: }
1017: # determine the students starting and ending times and section
1018: my ($starttime,$endtime,$section) = &get_enrollment_data($sname,$sdom);
1019: # Deal with date forms
1.68 ! matthew 1020: my $date_table = &date_setting_table($starttime,$endtime);
1.59 matthew 1021: #
1022: if (! exists($ENV{'form.Status'}) ||
1023: $ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) {
1024: $ENV{'form.Status'} = 'crap';
1025: }
1.50 matthew 1026: # Make sure student is enrolled in course
1027: $r->print(<<END);
1.52 matthew 1028: <p>
1029: <font size="+1">
1030: Only domain coordinators can change a users password.
1031: </font>
1032: </p>
1.50 matthew 1033: <input type="hidden" name="slogin" value="$sname" />
1034: <input type="hidden" name="sdomain" value="$sdom" />
1035: <input type="hidden" name="action" value="modifystudent" />
1.53 matthew 1036: <input type="hidden" name="state" value="done" />
1037: <input type="hidden" name="sortby" value="$sortby" />
1.59 matthew 1038: <input type="hidden" name="Status" value="$ENV{'form.Status'}" />
1039:
1.50 matthew 1040: <h2>Modify Enrollment for $info{'firstname'} $info{'middlename'}
1041: $info{'lastname'} $info{'generation'}, $sname\@$sdom</h2>
1042: <p>
1043: <b>Student Name</b>
1044: <table>
1045: <tr><th>First</th><th>Middle</th><th>Last</th><th>Generation</th></tr>
1046: <tr><td>
1047: <input type="text" name="firstname" value="$info{'firstname'}" /></td><td>
1048: <input type="text" name="middlename" value="$info{'middlename'}" /></td><td>
1049: <input type="text" name="lastname" value="$info{'lastname'}" /></td><td>
1050: <input type="text" name="generation" value="$info{'generation'}" /></td></tr>
1051: </table>
1052: </p><p>
1.52 matthew 1053: <b>Student ID</b>: <input type="text" name="id" value="$info{'id'}" size="12"/>
1054: </p><p>
1.53 matthew 1055: <input type="checkbox" name="forceid" >
1056: Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
1057: (only do if you know what you are doing)
1058: </p><p>
1.50 matthew 1059: <b>Section</b>: <input type="text" name="section" value="$section" size="4"/>
1060: </p>
1.68 ! matthew 1061: <p>$date_table</p>
1.50 matthew 1062: <input type="submit" value="Submit Modifications" />
1063: </body></html>
1064: END
1065: return;
1066: }
1067:
1068: #
1069: # modify a single students section
1070: #
1071: sub modify_single_student {
1072: my $r = shift;
1.68 ! matthew 1073: #
! 1074: # Do the date defaults first
! 1075: my ($starttime,$endtime) = &get_dates_from_form();
! 1076: if ($ENV{'form.makedatesdefault'}) {
! 1077: $r->print(&make_dates_default($starttime,$endtime));
! 1078: }
1.59 matthew 1079: # Get the 'sortby' and 'Status' variables so the user goes back to their
1080: # previous screen
1.53 matthew 1081: my $sortby = $ENV{'form.sortby'};
1.59 matthew 1082: my $status = $ENV{'form.Status'};
1.53 matthew 1083: #
1084: # We always need this information
1085: my $slogin = $ENV{'form.slogin'};
1086: my $sdom = $ENV{'form.sdomain'};
1087: #
1088: # Get the old data
1089: my %old=&Apache::lonnet::get('environment',
1090: ['firstname','middlename',
1091: 'lastname','generation','id'],
1092: $sdom, $slogin);
1.59 matthew 1093: $old{'section'} = &Apache::lonnet::getsection($sdom,$slogin,
1094: $ENV{'request.course.id'});
1.53 matthew 1095: my ($tmp) = keys(%old);
1096: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1097: $r->print("There was an error determining the environment values ".
1098: " for $slogin \@ $sdom.");
1099: return;
1100: }
1101: undef $tmp;
1102: #
1103: # Get the new data
1.50 matthew 1104: my $firstname = $ENV{'form.firstname'};
1105: my $middlename = $ENV{'form.middlename'};
1106: my $lastname = $ENV{'form.lastname'};
1107: my $generation = $ENV{'form.generation'};
1108: my $section = $ENV{'form.section'};
1109: my $courseid = $ENV{'request.course.id'};
1.52 matthew 1110: my $sid = $ENV{'form.id'};
1.50 matthew 1111: my $displayable_starttime = localtime($starttime);
1112: my $displayable_endtime = localtime($endtime);
1.53 matthew 1113: #
1114: # check for forceid override
1.63 matthew 1115: if ((defined($old{'id'})) && ($old{'id'} ne '') &&
1116: ($sid ne $old{'id'}) && (! exists($ENV{'form.forceid'}))) {
1.53 matthew 1117: $r->print("<font color=\"ff0000\">You changed the students id ".
1118: " but did not disable the ID change safeguard.".
1119: " The students id will not be changed.</font>");
1120: $sid = $old{'id'};
1121: }
1122: #
1.50 matthew 1123: # talk to the user about what we are going to do
1124: $r->print(<<END);
1.53 matthew 1125: <h2>Modifying data for user $slogin \@ $sdom </h2>
1.50 matthew 1126: <h3>Student Information</h3>
1.53 matthew 1127: <table rules="rows" border="1" cellpadding="3" >
1128: <tr>
1129: <th> Field </th>
1130: <th> Old Value </th>
1131: <th> New Value </th>
1132: </tr>
1133: <tr>
1134: <td> <b>First name</b> </td>
1135: <td> $old{'firstname'} </td>
1136: <td> $firstname </td>
1137: </tr><tr>
1138: <td> <b>Middle name</b> </td>
1139: <td> $old{'middlename'} </td>
1140: <td> $middlename </td>
1141: </tr><tr>
1142: <td> <b>Last name</b> </td>
1143: <td> $old{'lastname'} </td>
1144: <td> $lastname </td>
1145: </tr><tr>
1146: <td> <b>Generation</b> </td>
1147: <td> $old{'generation'} </td>
1148: <td> $generation </td>
1149: </tr><tr>
1150: <td> <b>ID</b> </td>
1151: <td> $old{'id'} </td>
1152: <td> $sid </td>
1.59 matthew 1153: </tr><tr>
1154: <td> <b>Section</b> </td>
1155: <td> $old{'section'} </td>
1156: <td> $section</td>
1.53 matthew 1157: </tr>
1.50 matthew 1158: </table>
1159: <h3>Role Information</h3>
1160: <table>
1.68 ! matthew 1161: <tr><td align="right"><b>Start Time:</b></td><td> $displayable_starttime </td></tr>
! 1162: <tr><td align="right"><b>End Time:</b></td><td> $displayable_endtime </td></tr>
1.50 matthew 1163: </table>
1.52 matthew 1164: <p>
1.50 matthew 1165: END
1.53 matthew 1166: #
1.63 matthew 1167: # Send request(s) to modify data (final undef is for 'desiredhost',
1168: # which is a moot point because the student already has an account.
1169: my $modify_section_results = &modifystudent($sdom,$slogin,
1170: $ENV{'request.course.id'},
1171: $section,undef);
1172: if ($modify_section_results !~ /^ok/) {
1173: $r->print("An error occured during the attempt to change the ".
1174: "section for this student.<br />");
1175: }
1.52 matthew 1176: my $roleresults = &Apache::lonnet::modifystudent
1.53 matthew 1177: ($sdom,$slogin,$sid,undef,undef,$firstname,$middlename,$lastname,
1178: $generation,$section,$endtime,$starttime,$ENV{'form.forceid'});
1179: if ($roleresults eq 'refused' ) {
1.50 matthew 1180: $r->print("Your request to change the role information for this ".
1.53 matthew 1181: "student was refused. You do not appear to have ".
1182: "sufficient authority to change student information.");
1.50 matthew 1183: } elsif ($roleresults !~ /ok/) {
1184: $r->print("An error occurred during the attempt to change the role".
1.52 matthew 1185: " information for this student. <br />".
1186: "The error reported was ".
1.50 matthew 1187: $roleresults);
1.53 matthew 1188: &Apache::lonnet::logthis("londropadd:failed attempt to modify student".
1189: " data for ".$slogin." \@ ".$sdom." by ".
1190: $ENV{'user.name'}." \@ ".$ENV{'user.domain'}.
1191: ":".$roleresults);
1.50 matthew 1192: } else { # everything is okay!
1.52 matthew 1193: $r->print("Student information updated successfully. <br />".
1194: "The student must log out and log in again to see ".
1195: "these changes.");
1.50 matthew 1196: }
1197: $r->print(<<END);
1.52 matthew 1198: </p><p>
1.59 matthew 1199: <input type="hidden" name="action" value="modifystudent" />
1200: <input type="hidden" name="sortby" value="$sortby" />
1201: <input type="hidden" name="Status" value="$status" />
1202: <a href="javascript:document.studentform.submit();">Modify another students data</a>
1.50 matthew 1203: </body></html>
1204: END
1205: return;
1206: }
1207:
1208: sub get_enrollment_data {
1209: my ($sname,$sdomain) = @_;
1210: my $courseid = $ENV{'request.course.id'};
1211: $courseid =~ s:_:/:g;
1212: my %roles = &Apache::lonnet::dump('roles',$sdomain,$sname);
1213: my ($tmp) = keys(%roles);
1214: # Bail out if we were unable to get the students roles
1215: return "666" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
1216: # Go through the roles looking for enrollment in this course
1217: my ($end,$start) = (undef,undef);
1218: my $section = '';
1219: my $count = scalar(keys(%roles));
1220: while (my ($course,$role) = each(%roles)) {
1221: if ($course=~ /^\/$courseid\/*\s*(\w+)*_st$/ ) {
1222: #
1223: # Get active role
1224: $section=$1;
1225: (undef,$end,$start)=split(/\_/,$role);
1226: my $now=time;
1227: my $notactive=0;
1228: if ($start) {
1229: if ($now<$start) { $notactive=1; }
1230: }
1231: if ($end) {
1232: if ($now>$end) { $notactive=1; }
1233: }
1234: unless ($notactive) { return ($start,$end,$section); }
1235: }
1236: }
1237: return ($start,$end,$section);
1238: }
1239:
1.56 matthew 1240: #################################################
1241: #################################################
1242:
1243: =pod
1244:
1245: =item show_drop_list
1246:
1247: Display a list of students to drop
1248: Inputs:
1249:
1250: =over 4
1251:
1252: =item $r, Apache request
1253:
1254: =item $classlist, hash pointer returned from loncoursedata::get_classlist();
1255:
1256: =item $keylist, array pointer returned from loncoursedata::get_classlist()
1257: which describes the order elements are stored in the %$classlist values.
1258:
1259: =item $nosort, if true, sorting links are omitted.
1260:
1261: =back
1262:
1263: =cut
1264:
1265: #################################################
1266: #################################################
1.11 www 1267: sub show_drop_list {
1.56 matthew 1268: my ($r,$classlist,$keylist,$nosort)=@_;
1.11 www 1269: my $cid=$ENV{'request.course.id'};
1.59 matthew 1270: if (! exists($ENV{'form.sortby'})) {
1271: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1272: ['sortby']);
1273: }
1.54 matthew 1274: my $sortby = $ENV{'form.sortby'};
1275: if ($sortby !~ /^(username|domain|section|fullname|id)$/) {
1276: $sortby = 'username';
1277: }
1.56 matthew 1278: #
1.54 matthew 1279: my $action = "drop";
1280: $r->print(<<END);
1281: <input type="hidden" name="sortby" value="$sortby" />
1282: <input type="hidden" name="action" value="$action" />
1.50 matthew 1283: <input type="hidden" name="state" value="done" />
1.32 matthew 1284: <script>
1.51 matthew 1285: function checkAll(field) {
1.32 matthew 1286: for (i = 0; i < field.length; i++)
1287: field[i].checked = true ;
1288: }
1289:
1.51 matthew 1290: function uncheckAll(field) {
1.32 matthew 1291: for (i = 0; i < field.length; i++)
1292: field[i].checked = false ;
1293: }
1294: </script>
1295: <p>
1.26 matthew 1296: <input type="hidden" name="phase" value="four">
1.56 matthew 1297: END
1298:
1299: if ($nosort) {
1300: $r->print(<<END);
1301: <table border=2>
1302: <tr>
1303: <th> </th>
1304: <th>username</th>
1305: <th>domain</th>
1306: <th>ID</th>
1307: <th>student name</th>
1308: <th>section</th>
1309: </tr>
1310: END
1311:
1312: } else {
1313: $r->print(<<END);
1.26 matthew 1314: <table border=2>
1.54 matthew 1315: <tr><th> </th>
1316: <th>
1317: <a href="/adm/dropadd?action=$action&sortby=username">username</a>
1318: </th><th>
1319: <a href="/adm/dropadd?action=$action&sortby=domain">domain</a>
1320: </th><th>
1321: <a href="/adm/dropadd?action=$action&sortby=id">ID</a>
1322: </th><th>
1323: <a href="/adm/dropadd?action=$action&sortby=fullname">student name</a>
1324: </th><th>
1325: <a href="/adm/dropadd?action=$action&sortby=section">section</a>
1326: </th>
1327: </tr>
1.26 matthew 1328: END
1.56 matthew 1329: }
1330: #
1331: # Sort the students
1332: my %index;
1333: my $i;
1334: foreach (@$keylist) {
1335: $index{$_} = $i++;
1336: }
1337: my $index = $index{$sortby};
1338: my $second = $index{'username'};
1339: my $third = $index{'domain'};
1.54 matthew 1340: my @Sorted_Students = sort {
1.56 matthew 1341: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
1342: ||
1343: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
1344: ||
1345: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
1346: } (keys(%$classlist));
1.54 matthew 1347: foreach my $student (@Sorted_Students) {
1.52 matthew 1348: my $error;
1.56 matthew 1349: my $username = $classlist->{$student}->[$index{'username'}];
1350: my $domain = $classlist->{$student}->[$index{'domain'}];
1351: my $section = $classlist->{$student}->[$index{'section'}];
1352: my $name = $classlist->{$student}->[$index{'fullname'}];
1353: my $id = $classlist->{$student}->[$index{'id'}];
1354: my $status = $classlist->{$student}->[$index{'status'}];
1.51 matthew 1355: next if ($status ne 'Active');
1356: #
1357: $r->print(<<"END");
1.26 matthew 1358: <tr>
1.51 matthew 1359: <td><input type="checkbox" name="droplist" value="$student"></td>
1360: <td>$username</td>
1361: <td>$domain</td>
1362: <td>$id</td>
1363: <td>$name</td>
1364: <td>$section</td>
1.26 matthew 1365: </tr>
1366: END
1.25 matthew 1367: }
1368: $r->print('</table><br>');
1.32 matthew 1369: $r->print(<<"END");
1370: </p><p>
1371: <input type="button" value="check all" onclick="javascript:checkAll(document.studentform.droplist)">
1372: <input type="button" value="uncheck all" onclick="javascript:uncheckAll(document.studentform.droplist)">
1373: <p><input type=submit value="Drop Students"></p>
1374: END
1.51 matthew 1375: return;
1.10 www 1376: }
1377:
1.48 matthew 1378: #
1379: # Print out the initial form to get the courselist file
1380: #
1381: sub print_first_courselist_upload_form {
1382: my $r=shift;
1383: my $upfile_select=&Apache::loncommon::upfile_select_html();
1384: my $create_classlist_help =
1385: &Apache::loncommon::help_open_topic("Course_Create_Class_List",
1386: "How do I create a class list from a spreadsheet");
1387: my $create_csv_help =
1388: &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1389: "How do I create a CSV file from a spreadsheet");
1390: $r->print(<<ENDUPFORM);
1391: <input type=hidden name=phase value=two>
1392: <h3>Upload a courselist</h3>
1393: $upfile_select
1.50 matthew 1394: <p>
1395: <input type=submit name="fileupload" value="Upload Courselist">
1396: <input type="hidden" name="action" value="upload" />
1397: <input type="hidden" name="state" value="got_file" />
1398: </p>
1.48 matthew 1399: $create_classlist_help <br />
1400: $create_csv_help
1401: </body></html>
1402: ENDUPFORM
1403: return;
1404: }
1405:
1.10 www 1406: # ================================================= Drop/Add from uploaded file
1407: sub upfile_drop_add {
1408: my $r=shift;
1.24 albertel 1409: &Apache::loncommon::load_tmp_file($r);
1410: my @studentdata=&Apache::loncommon::upfile_record_sep();
1.26 matthew 1411: my @keyfields = split(/\,/,$ENV{'form.keyfields'});
1412: my $cid = $ENV{'request.course.id'};
1.25 matthew 1413: my %fields=();
1.26 matthew 1414: for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
1.25 matthew 1415: if ($ENV{'form.upfile_associate'} eq 'reverse') {
1416: if ($ENV{'form.f'.$i} ne 'none') {
1417: $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
1418: }
1419: } else {
1420: $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
1421: }
1422: }
1.26 matthew 1423: #
1.68 ! matthew 1424: my ($startdate,$enddate) = &get_dates_from_form();
! 1425: if ($ENV{'form.makedatesdefault'}) {
! 1426: $r->print(&make_dates_default($startdate,$enddate));
! 1427: }
1.31 matthew 1428: # Determine domain and desired host (home server)
1.25 matthew 1429: my $domain=$ENV{'form.lcdomain'};
1.31 matthew 1430: my $desiredhost = $ENV{'form.lcserver'};
1431: if (lc($desiredhost) eq 'default') {
1432: $desiredhost = undef;
1433: } else {
1.45 matthew 1434: my %home_servers = &Apache::loncommon::get_library_servers($domain);
1.31 matthew 1435: if (! exists($home_servers{$desiredhost})) {
1436: $r->print('<font color="#ff0000">Error:</font>'.
1437: 'Invalid home server specified');
1438: return;
1439: }
1440: }
1.26 matthew 1441: # Determine authentication mechanism
1442: my $amode = '';
1443: my $genpwd = '';
1.25 matthew 1444: if ($ENV{'form.login'} eq 'krb') {
1.47 albertel 1445: $amode='krb';
1446: $amode.=$ENV{'form.krbver'};
1.28 matthew 1447: $genpwd=$ENV{'form.krbarg'};
1.25 matthew 1448: } elsif ($ENV{'form.login'} eq 'int') {
1449: $amode='internal';
1.28 matthew 1450: if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
1451: $genpwd=$ENV{'form.intarg'};
1.25 matthew 1452: }
1453: } elsif ($ENV{'form.login'} eq 'loc') {
1454: $amode='localauth';
1455: if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
1456: $genpwd=$ENV{'form.locarg'};
1457: }
1458: }
1459: unless (($domain=~/\W/) || ($amode eq '')) {
1.26 matthew 1460: #######################################
1461: ## Enroll Students ##
1462: #######################################
1.25 matthew 1463: $r->print('<h3>Enrolling Students</h3>');
1464: my $count=0;
1465: my $flushc=0;
1466: my %student=();
1.26 matthew 1467: # Get new classlist
1.25 matthew 1468: foreach (@studentdata) {
1469: my %entries=&Apache::loncommon::record_sep($_);
1.26 matthew 1470: # Determine student name
1.25 matthew 1471: unless (($entries{$fields{'username'}} eq '') ||
1472: (!defined($entries{$fields{'username'}}))) {
1.26 matthew 1473: my ($fname, $mname, $lname,$gen) = ('','','','');
1.25 matthew 1474: if (defined($fields{'names'})) {
1.26 matthew 1475: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
1476: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
1.25 matthew 1477: } else {
1478: if (defined($fields{'fname'})) {
1479: $fname=$entries{$fields{'fname'}};
1480: }
1481: if (defined($fields{'mname'})) {
1482: $mname=$entries{$fields{'mname'}};
1483: }
1484: if (defined($fields{'lname'})) {
1485: $lname=$entries{$fields{'lname'}};
1486: }
1487: if (defined($fields{'gen'})) {
1488: $gen=$entries{$fields{'gen'}};
1489: }
1490: }
1491: if ($entries{$fields{'username'}}=~/\W/) {
1492: $r->print('<p><b>Unacceptable username: '.
1.10 www 1493: $entries{$fields{'username'}}.' for user '.
1.4 www 1494: $fname.' '.$mname.' '.$lname.' '.$gen.'</b><p>');
1.25 matthew 1495: } else {
1.26 matthew 1496: # determine section number
1.25 matthew 1497: my $sec='';
1498: my $username=$entries{$fields{'username'}};
1499: if (defined($fields{'sec'})) {
1500: if (defined($entries{$fields{'sec'}})) {
1501: $sec=$entries{$fields{'sec'}};
1502: }
1503: }
1.26 matthew 1504: # determine student id number
1.25 matthew 1505: my $id='';
1506: if (defined($fields{'id'})) {
1507: if (defined($entries{$fields{'id'}})) {
1508: $id=$entries{$fields{'id'}};
1509: }
1510: $id=~tr/A-Z/a-z/;
1511: }
1.26 matthew 1512: # determine student password
1.25 matthew 1513: my $password='';
1514: if ($genpwd) {
1515: $password=$genpwd;
1516: } else {
1517: if (defined($fields{'ipwd'})) {
1518: if ($entries{$fields{'ipwd'}}) {
1519: $password=$entries{$fields{'ipwd'}};
1520: }
1521: }
1522: }
1.56 matthew 1523: # Clean up whitespace
1524: foreach (\$domain,\$username,\$id,\$fname,\$mname,
1525: \$lname,\$gen,\$sec) {
1526: $$_ =~ s/(\s+$|^\s+)//g;
1527: }
1.25 matthew 1528: if ($password) {
1.33 matthew 1529: &modifystudent($domain,$username,$cid,$sec,
1530: $desiredhost);
1.25 matthew 1531: my $reply=&Apache::lonnet::modifystudent
1532: ($domain,$username,$id,$amode,$password,
1533: $fname,$mname,$lname,$gen,$sec,$enddate,
1.31 matthew 1534: $startdate,$ENV{'form.forceid'},$desiredhost);
1.26 matthew 1535: if ($reply ne 'ok') {
1536: $r->print('<p><b>'.
1537: 'Error enrolling '.$username.': '.
1538: $reply.'</b></p>');
1.10 www 1539: } else {
1.7 www 1540: $count++; $flushc++;
1541: $student{$username}=1;
1.6 www 1542: $r->print('. ');
1.7 www 1543: if ($flushc>15) {
1544: $r->rflush;
1545: $flushc=0;
1546: }
1.6 www 1547: }
1.25 matthew 1548: } else {
1549: $r->print("<p><b>No password for $username</b><p>");
1550: }
1551: }
1.26 matthew 1552: }
1553: } # end of foreach (@studentdata)
1.55 matthew 1554: $r->print('<p>Processed Students: '.$count.'</p>');
1555: $r->print("<p>If active, the new role will be available when the ".
1556: "students next log in to LON-CAPA.</p>");
1.26 matthew 1557: #####################################
1558: # Drop students #
1559: #####################################
1.25 matthew 1560: if ($ENV{'form.fullup'} eq 'yes') {
1561: $r->print('<h3>Dropping Students</h3>');
1.26 matthew 1562: # Get current classlist
1.56 matthew 1563: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
1564: if (! defined($classlist)) {
1565: $r->print("There are no students currently enrolled.\n");
1566: } else {
1567: # Remove the students we just added from the list of students.
1.25 matthew 1568: foreach (@studentdata) {
1569: my %entries=&Apache::loncommon::record_sep($_);
1570: unless (($entries{$fields{'username'}} eq '') ||
1571: (!defined($entries{$fields{'username'}}))) {
1.56 matthew 1572: delete($classlist->{$entries{$fields{'username'}}.
1.26 matthew 1573: ':'.$domain});
1.25 matthew 1574: }
1575: }
1.56 matthew 1576: # Print out list of dropped students.
1577: &show_drop_list($r,$classlist,$keylist,'nosort');
1.25 matthew 1578: }
1579: }
1.26 matthew 1580: } # end of unless
1.10 www 1581: }
1582:
1.11 www 1583: # ================================================================== Phase four
1584: sub drop_student_list {
1585: my $r=shift;
1586: my $count=0;
1.35 matthew 1587: my @droplist;
1588: if (ref($ENV{'form.droplist'})) {
1589: @droplist = @{$ENV{'form.droplist'}};
1590: } else {
1591: @droplist = ($ENV{'form.droplist'});
1592: }
1593: foreach (@droplist) {
1.26 matthew 1594: my ($uname,$udom)=split(/\:/,$_);
1.56 matthew 1595: # drop student
1.35 matthew 1596: my $result = &modifystudent($udom,$uname,$ENV{'request.course.id'});
1.37 matthew 1597: if ($result eq 'ok' || $result eq 'ok:') {
1.54 matthew 1598: $r->print('Dropped '.$uname.' @ '.$udom.'<br>');
1.59 matthew 1599: $count++;
1.35 matthew 1600: } else {
1.54 matthew 1601: $r->print('Error dropping '.$uname.' @ '.$udom.': '.$result.
1.35 matthew 1602: '<br />');
1603: }
1.20 harris41 1604: }
1.11 www 1605: $r->print('<p><b>Dropped '.$count.' student(s).</b>');
1.59 matthew 1606: $r->print('<p>Re-enrollment will re-activate data.') if ($count);
1.11 www 1607: }
1608:
1.50 matthew 1609: ###################################################################
1610: ###################################################################
1611:
1612: =pod
1613:
1614: =item &handler
1615:
1616: The typical handler you see in all these modules. Takes $r, the
1617: http request, as an argument.
1618:
1619: The response to the request is governed by two form variables
1620:
1621: form.action form.state response
1622: ---------------------------------------------------
1623: undefined undefined print main menu
1624: upload undefined print courselist upload menu
1625: upload got_file deal with uploaded file,
1626: print the upload managing menu
1627: upload enrolling enroll students based on upload
1628: drop undefined print the classlist ready to drop
1629: drop done drop the selected students
1630: enrollstudent undefined print single student enroll menu
1631: enrollstudent enrolling enroll student
1632: classlist undefined print html classlist
1633: classlist csv print csv classlist
1634: modifystudent undefined print classlist to select student to modify
1635: modifystudent selected print modify student menu
1636: modifystudent done make modifications to student record
1637:
1638: =cut
1639:
1640: ###################################################################
1641: ###################################################################
1.10 www 1642: sub handler {
1.26 matthew 1643: my $r=shift;
1644: if ($r->header_only) {
1645: $r->content_type('text/html');
1646: $r->send_http_header;
1647: return OK;
1648: }
1.48 matthew 1649: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.50 matthew 1650: ['action','state']);
1.26 matthew 1651: # Needs to be in a course
1.50 matthew 1652: if (! (($ENV{'request.course.fn'}) &&
1653: (&Apache::lonnet::allowed('cst',$ENV{'request.course.id'})))) {
1654: # Not in a course, or not allowed to modify parms
1655: $ENV{'user.error.msg'}=
1656: "/adm/dropadd:cst:0:0:Cannot drop or add students";
1657: return HTTP_NOT_ACCEPTABLE;
1658: }
1659: #
1660: # Only output the header information if they did not request csv format
1661: #
1662: if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) {
1663: $r->content_type('text/csv');
1664: } else {
1.26 matthew 1665: # Start page
1.50 matthew 1666: $r->content_type('text/html');
1.26 matthew 1667: $r->send_http_header;
1.50 matthew 1668: $r->print(&header());
1669: }
1670: #
1671: # Main switch on form.action and form.state, as appropriate
1672: if (! exists($ENV{'form.action'})) {
1673: &print_main_menu($r);
1674: } elsif ($ENV{'form.action'} eq 'upload') {
1675: if (! exists($ENV{'form.state'})) {
1676: &print_first_courselist_upload_form($r);
1677: } elsif ($ENV{'form.state'} eq 'got_file') {
1678: &print_upload_manager_form($r);
1679: } elsif ($ENV{'form.state'} eq 'enrolling') {
1.26 matthew 1680: if ($ENV{'form.datatoken'}) {
1681: &upfile_drop_add($r);
1.50 matthew 1682: } else {
1683: # Hmmm, this is an error
1.26 matthew 1684: }
1.50 matthew 1685: } else {
1686: &print_first_courselist_upload_form($r);
1.26 matthew 1687: }
1.50 matthew 1688: } elsif ($ENV{'form.action'} eq 'drop') {
1689: if (! exists($ENV{'form.state'})) {
1.51 matthew 1690: &print_drop_menu($r);
1.50 matthew 1691: } elsif ($ENV{'form.state'} eq 'done') {
1.26 matthew 1692: &drop_student_list($r);
1.50 matthew 1693: } else {
1.55 matthew 1694: &print_drop_menu($r);
1.26 matthew 1695: }
1.50 matthew 1696: } elsif ($ENV{'form.action'} eq 'enrollstudent') {
1697: if (! exists($ENV{'form.state'})) {
1698: &print_enroll_single_student_form($r);
1699: } elsif ($ENV{'form.state'} eq 'enrolling') {
1.26 matthew 1700: &enroll_single_student($r);
1.50 matthew 1701: } else {
1702: &print_enroll_single_student_form($r);
1.26 matthew 1703: }
1.50 matthew 1704: } elsif ($ENV{'form.action'} eq 'classlist') {
1705: if (! exists($ENV{'form.state'})) {
1706: &print_html_classlist($r);
1707: } elsif ($ENV{'form.state'} eq 'csv') {
1.60 matthew 1708: &print_formatted_classlist($r,'csv');
1709: } elsif ($ENV{'form.state'} eq 'excel') {
1710: &print_formatted_classlist($r,'excel');
1.50 matthew 1711: } else {
1712: &print_html_classlist($r);
1713: }
1714: } elsif ($ENV{'form.action'} eq 'modifystudent') {
1715: if (! exists($ENV{'form.state'})) {
1716: &print_html_classlist($r);
1717: } elsif ($ENV{'form.state'} eq 'selected') {
1718: &print_modify_student_form($r);
1719: } elsif ($ENV{'form.state'} eq 'done') {
1720: &modify_single_student($r);
1721: } else {
1722: &print_html_classlist($r);
1723: }
1724: } else {
1725: # We should not end up here, but I guess it is possible
1726: &Apache::lonnet::logthis("Undetermined state in londropadd.pm. ".
1727: "form.action = ".$ENV{'form.action'}.
1728: "Someone should fix this.");
1729: &print_main_menu($r);
1730: }
1731: #
1732: # Finish up
1733: if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) {
1734: $r->print("\n");
1.26 matthew 1735: } else {
1.50 matthew 1736: $r->print('</form></body></html>');
1.26 matthew 1737: }
1738: return OK;
1.1 www 1739: }
1740:
1.50 matthew 1741: ###################################################################
1742: ###################################################################
1743:
1.1 www 1744: 1;
1745: __END__
1.50 matthew 1746:
1.1 www 1747:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>