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