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