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