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