Annotation of loncom/interface/londropadd.pm, revision 1.125
1.1 www 1: # The LearningOnline Network with CAPA
2: # Handler to drop and add students in courses
3: #
1.125 ! albertel 4: # $Id: londropadd.pm,v 1.124 2005/01/31 11:27:14 www 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: #
1.50 matthew 29: ###############################################################
1.82 www 30: ##############################################################
1.1 www 31:
32: package Apache::londropadd;
33:
34: use strict;
1.24 albertel 35: use Apache::lonnet();
36: use Apache::loncommon();
1.50 matthew 37: use Apache::lonhtmlcommon();
1.1 www 38: use Apache::Constants qw(:common :http REDIRECT);
1.60 matthew 39: use Spreadsheet::WriteExcel;
1.110 matthew 40: use Apache::lonstathelpers();
1.86 www 41: use Apache::lonlocal;
1.1 www 42:
1.50 matthew 43: ###############################################################
44: ###############################################################
1.10 www 45: sub header {
1.125 ! albertel 46: my $html=&Apache::lonxml::xmlbegin();
1.102 matthew 47: my $bodytag=&Apache::loncommon::bodytag('Enrollment Manager');
1.88 matthew 48: my $title = &mt('LON-CAPA Enrollment Manager');
1.27 matthew 49: return(<<ENDHEAD);
1.125 ! albertel 50: $html
1.1 www 51: <head>
1.88 matthew 52: <title>$title</title>
1.1 www 53: </head>
1.46 www 54: $bodytag
1.40 matthew 55: <form method="post" enctype="multipart/form-data"
56: action="/adm/dropadd" name="studentform">
1.1 www 57: ENDHEAD
1.10 www 58: }
59:
1.50 matthew 60: ###############################################################
61: ###############################################################
62: # Drop student from all sections of a course, except optional $csec
1.26 matthew 63: sub modifystudent {
1.33 matthew 64: my ($udom,$unam,$courseid,$csec,$desiredhost)=@_;
1.26 matthew 65: # if $csec is undefined, drop the student from all the courses matching
66: # this one. If $csec is defined, drop them from all other sections of
67: # this course and add them to section $csec
1.25 matthew 68: $courseid=~s/\_/\//g;
69: $courseid=~s/^(\w)/\/$1/;
1.26 matthew 70: my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
71: my ($tmp) = keys(%roles);
72: # Bail out if we were unable to get the students roles
1.35 matthew 73: return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
1.26 matthew 74: # Go through the roles looking for enrollment in this course
1.35 matthew 75: my $result = '';
1.26 matthew 76: foreach my $course (keys(%roles)) {
1.35 matthew 77: if ($course=~/^$courseid(?:\/)*(?:\s+)*(\w+)*\_st$/) {
1.26 matthew 78: # We are in this course
1.25 matthew 79: my $section=$1;
1.26 matthew 80: $section='' if ($course eq $courseid.'_st');
1.87 matthew 81: if (defined($csec) && $section eq $csec) {
1.71 matthew 82: $result .= 'ok:';
83: } elsif ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
1.27 matthew 84: my (undef,$end,$start)=split(/\_/,$roles{$course});
1.25 matthew 85: my $now=time;
1.50 matthew 86: # if this is an active role
1.27 matthew 87: if (!($start && ($now<$start)) || !($end && ($now>$end))) {
1.25 matthew 88: my $reply=&Apache::lonnet::modifystudent
1.70 matthew 89: # dom name id mode pass f m l g
90: ($udom,$unam,'', '', '',undef,undef,undef,undef,
1.33 matthew 91: $section,time,undef,undef,$desiredhost);
1.35 matthew 92: $result .= $reply.':';
1.25 matthew 93: }
1.10 www 94: }
95: }
1.20 harris41 96: }
1.35 matthew 97: if ($result eq '') {
1.62 matthew 98: $result = 'Unable to find section for this student';
1.37 matthew 99: } else {
100: $result =~ s/(ok:)+/ok/g;
1.35 matthew 101: }
102: return $result;
1.10 www 103: }
104:
1.50 matthew 105: ###############################################################
106: ###############################################################
107: # build a domain and server selection form
1.31 matthew 108: sub domain_form {
109: my ($defdom) = @_;
110: # Set up domain and server selection forms
111: #
112: # Get the domains
113: my @domains = &Apache::loncommon::get_domains();
114: # build up the menu information to be passed to
115: # &Apache::loncommon::linked_select_forms
116: my %select_menus;
117: foreach my $dom (@domains) {
118: # set up the text for this domain
119: $select_menus{$dom}->{'text'}= $dom;
120: # we want a choice of 'default' as the default in the second menu
121: $select_menus{$dom}->{'default'}= 'default';
122: $select_menus{$dom}->{'select2'}->{'default'} = 'default';
123: # Now build up the other items in the second menu
1.45 matthew 124: my %servers = &Apache::loncommon::get_library_servers($dom);
1.31 matthew 125: foreach my $server (keys(%servers)) {
126: $select_menus{$dom}->{'select2'}->{$server}
127: = "$server $servers{$server}";
128: }
129: }
130: my $result = &Apache::loncommon::linked_select_forms
131: ('studentform',' with home server ',$defdom,
132: 'lcdomain','lcserver',\%select_menus);
133: return $result;
134: }
135:
1.50 matthew 136: ###############################################################
137: ###############################################################
138: # Menu Phase One
139: sub print_main_menu {
1.121 matthew 140: my ($r,$enrl_permission,$view_permission)=@_;
141: #
1.113 raeburn 142: my ($cdom,$cnum) = split/_/,$ENV{'request.course.id'};
1.121 matthew 143: my @menu =
144: (
1.122 matthew 145: { text => 'Upload a class list',
1.121 matthew 146: help => 'Course_Create_Class_List',
147: action => 'upload',
148: permission => $enrl_permission,
149: },
150: { text => 'Enroll a single student',
151: help => 'Course_Add_Student',
152: action => 'enrollstudent',
153: permission => $enrl_permission,
154: },
155: { text => 'Modify student data',
156: help => 'Course_Modify_Student_Data',
157: action => 'modifystudent',
158: permission => $enrl_permission,
159: },
160: { text => 'View Class List',
161: help => 'Course_View_Class_List',
162: action => 'classlist',
163: permission => $view_permission,
164: },
165: { text => 'Drop Students',
166: help => 'Course_Drop_Student',
167: action => 'drop',
168: permission => $enrl_permission,
169: },
170: { text => 'Automated Enrollment Manager',
171: permission => &Apache::lonnet::auto_run($cnum,$cdom),
172: url => '/adm/populate',
173: },
174: );
175: my $menu_html = '';
176: foreach my $menu_item (@menu) {
177: next if (! $menu_item->{'permission'});
178: $menu_html.='<p>';
179: $menu_html.='<font size="+1">';
180: if (exists($menu_item->{'url'})) {
181: $menu_html.=qq{<a href="$menu_item->{'url'}">};
182: } else {
183: $menu_html.=
184: qq{<a href="/adm/dropadd?action=$menu_item->{'action'}">};
185: }
186: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
187: if (exists($menu_item->{'help'})) {
188: $menu_html.=
189: &Apache::loncommon::help_open_topic($menu_item->{'help'});
190: }
191: $menu_html.='</p>'.$/;
1.113 raeburn 192: }
1.121 matthew 193: $r->print($menu_html);
194: return;
1.10 www 195: }
196:
1.50 matthew 197: ###############################################################
198: ###############################################################
1.89 matthew 199: sub hidden_input {
200: my ($name,$value) = @_;
201: return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n";
202: }
203:
1.50 matthew 204: sub print_upload_manager_header {
1.23 albertel 205: my ($r,$datatoken,$distotal,$krbdefdom)=@_;
1.24 albertel 206: my $javascript;
1.99 matthew 207: #
1.50 matthew 208: if (! exists($ENV{'form.upfile_associate'})) {
209: $ENV{'form.upfile_associate'} = 'forward';
210: }
211: if ($ENV{'form.associate'} eq 'Reverse Association') {
212: if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
213: $ENV{'form.upfile_associate'} = 'reverse';
214: } else {
215: $ENV{'form.upfile_associate'} = 'forward';
216: }
217: }
1.24 albertel 218: if ($ENV{'form.upfile_associate'} eq 'reverse') {
1.50 matthew 219: $javascript=&upload_manager_javascript_reverse_associate();
1.24 albertel 220: } else {
1.50 matthew 221: $javascript=&upload_manager_javascript_forward_associate();
1.24 albertel 222: }
1.99 matthew 223: #
224: # Deal with restored settings
225: my $password_choice = '';
226: if (exists($ENV{'form.ipwd_choice'}) &&
227: $ENV{'form.ipwd_choice'} ne '') {
228: # If a column was specified for password, assume it is for an
229: # internal password. This is a bug waiting to be filed (could be
230: # local or krb auth instead of internal) but I do not have the
231: # time to mess around with this now.
232: $password_choice = 'int';
233: }
234: #
235: my $javascript_validations=&javascript_validations('auth',$krbdefdom,
236: $password_choice);
1.82 www 237: my $checked=(($ENV{'form.noFirstLine'})?' checked="1"':'');
1.88 matthew 238: $r->print('<h3>'.&mt('Uploading Class List')."</h3>\n".
239: "<hr>\n".
240: '<h3>'.&mt('Identify fields')."</h3>\n");
241: $r->print("<p>\n".
242: &mt('Total number of records found in file: [_1].',$distotal).
243: "\n".
244: "</p><hr>\n");
1.94 sakharuk 245: $r->print(&mt('Enter as many fields as you can. The system will inform you and bring you back to this page if the data selected is insufficient to enroll students in your class.')."<hr>\n");
1.89 matthew 246: $r->print(&hidden_input('action','upload').
247: &hidden_input('state','got_file').
248: &hidden_input('associate','').
249: &hidden_input('datatoken',$datatoken).
250: &hidden_input('fileupload',$ENV{'form.fileupload'}).
251: &hidden_input('upfiletype',$ENV{'form.upfiletype'}).
252: &hidden_input('upfile_associate',$ENV{'form.upfile_associate'}));
253: $r->print('<input type="button" value="Reverse Association" '.
254: 'name="'.&mt('Reverse Association').'" '.
255: 'onClick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />');
256: $r->print('<input type="checkbox" name="noFirstLine" $checked />'.
257: &mt('Ignore First Line'));
258: $r->print("<hr />\n".
259: '<script type="text/javascript" language="Javascript">'."\n".
260: $javascript."\n".$javascript_validations.'</script>');
1.24 albertel 261: }
262:
1.50 matthew 263: ###############################################################
264: ###############################################################
1.24 albertel 265: sub javascript_validations {
1.96 raeburn 266: my ($mode,$krbdefdom,$curr_authtype,$curr_authfield)=@_;
1.89 matthew 267: my $authheader;
268: if ($mode eq 'auth') {
269: my %param = ( formname => 'studentform',
1.99 matthew 270: kerb_def_dom => $krbdefdom,
271: curr_authtype => $curr_authtype);
1.89 matthew 272: $authheader = &Apache::loncommon::authform_header(%param);
1.91 raeburn 273: } elsif ($mode eq 'createcourse') {
274: my %param = ( formname => 'ccrs',
1.99 matthew 275: kerb_def_dom => $krbdefdom,
276: curr_authtype => $curr_authtype );
1.91 raeburn 277: $authheader = &Apache::loncommon::authform_header(%param);
1.96 raeburn 278: } elsif ($mode eq 'modifycourse') {
279: my %param = ( formname => 'cmod',
280: kerb_def_dom => $krbdefdom,
281: mode => 'modifycourse',
282: curr_authtype => $curr_authtype,
283: curr_autharg => $curr_authfield );
284: $authheader = &Apache::loncommon::authform_header(%param);
1.89 matthew 285: }
1.96 raeburn 286:
1.91 raeburn 287:
1.89 matthew 288: my %alert = &Apache::lonlocal::texthash
289: (username => 'You need to specify the username field.',
290: authen => 'You must choose an authentication type.',
291: krb => 'You need to specify the Kerberos domain.',
292: ipass => 'You need to specify the initial password.',
293: name => 'The optional name field was not specified.',
294: snum => 'The optional student number field was not specified.',
295: section => 'The optional section or group field was not specified.',
296: email => 'The optional email address field was not specified.',
297: continue => 'Continue enrollment?',
298: );
299:
300: # my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
301: my $function_name =(<<END);
1.73 www 302: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail) {
1.89 matthew 303: END
1.97 raeburn 304: my $auth_checks;
1.96 raeburn 305: if ($mode eq 'createcourse') {
306: $auth_checks .= (<<END);
1.97 raeburn 307: if (vf.autoadds[0].checked == true) {
1.96 raeburn 308: if (current.radiovalue == null || current.radiovalue == 'nochange') {
309: alert('$alert{'authen'}');
310: return;
311: }
312: }
313: END
314: } else {
1.91 raeburn 315: $auth_checks .= (<<END);
1.97 raeburn 316: var foundatype=0;
1.3 www 317: if (founduname==0) {
1.89 matthew 318: alert('$alert{'username'}');
1.3 www 319: return;
320: }
1.61 matthew 321: // alert('current.radiovalue = '+current.radiovalue);
1.119 albertel 322: if (current.radiovalue == null || current.radiovalue == '' || current.radiovalue == 'nochange') {
1.28 matthew 323: // They did not check any of the login radiobuttons.
1.89 matthew 324: alert('$alert{'authen'}');
1.28 matthew 325: return;
326: }
1.96 raeburn 327: END
328: }
1.97 raeburn 329: if ($mode eq 'createcourse') {
330: $auth_checks .= "
331: if ( (vf.autoadds[0].checked == true) &&
332: (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') ) {
333: ";
334: } elsif ($mode eq 'modifycourse') {
335: $auth_checks .= "
336: if (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') {
337: ";
338: }
1.96 raeburn 339: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
1.97 raeburn 340: $auth_checks .= (<<END);
341: var alertmsg = '';
342: switch (current.radiovalue) {
343: case 'krb':
344: alertmsg = '$alert{'krb'}';
345: break;
346: default:
347: alertmsg = '';
1.96 raeburn 348: }
1.97 raeburn 349: if (alertmsg != '') {
350: alert(alertmsg);
351: return;
1.96 raeburn 352: }
353: }
354: END
355: } else {
356: $auth_checks .= (<<END);
1.28 matthew 357: foundatype=1;
1.29 matthew 358: if (current.argfield == null || current.argfield == '') {
1.28 matthew 359: var alertmsg = '';
1.29 matthew 360: switch (current.value) {
1.28 matthew 361: case 'krb':
1.89 matthew 362: alertmsg = '$alert{'krb'}';
1.28 matthew 363: break;
364: case 'loc':
365: case 'fsys':
1.89 matthew 366: alertmsg = '$alert{'ipass'}';
1.28 matthew 367: break;
368: case 'fsys':
369: alertmsg = '';
370: break;
371: default:
372: alertmsg = '';
1.3 www 373: }
1.28 matthew 374: if (alertmsg != '') {
375: alert(alertmsg);
1.3 www 376: return;
377: }
378: }
1.89 matthew 379: END
1.96 raeburn 380: }
1.91 raeburn 381: my $optional_checks = '';
1.96 raeburn 382: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
1.91 raeburn 383: $optional_checks = (<<END);
384: vf.submit();
385: }
386: END
387: } else {
388: $optional_checks = (<<END);
1.89 matthew 389: var message='';
390: if (foundname==0) {
391: message='$alert{'name'}';
1.24 albertel 392: }
1.89 matthew 393: if (foundid==0) {
394: if (message!='') {
395: message+='\\n';
396: }
397: message+='$alert{'snum'}';
398: }
399: if (foundsec==0) {
400: if (message!='') {
401: message+='\\n';
402: }
403: message+='$alert{'section'}';
404: }
405: if (foundemail==0) {
406: if (message!='') {
407: message+='\\n';
408: }
409: message+='$alert{'email'}';
1.74 matthew 410: }
411: if (message!='') {
1.89 matthew 412: message+= '\\n$alert{'continue'}';
413: if (confirm(message)) {
414: vf.state.value='enrolling';
415: vf.submit();
416: }
1.74 matthew 417: } else {
1.89 matthew 418: vf.state.value='enrolling';
419: vf.submit();
1.74 matthew 420: }
421: }
1.89 matthew 422: END
1.91 raeburn 423: }
1.89 matthew 424: my $result = $function_name;
1.96 raeburn 425: if ( ($mode eq 'auth') || ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
1.89 matthew 426: $result .= $auth_checks;
427: }
428: $result .= $optional_checks;
1.96 raeburn 429: if ( ($mode eq 'auth') || ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
1.89 matthew 430: $result .= $authheader;
431: }
432: return $result;
1.74 matthew 433: }
434:
1.50 matthew 435: ###############################################################
436: ###############################################################
437: sub upload_manager_javascript_forward_associate {
1.24 albertel 438: return(<<ENDPICK);
439: function verify(vf) {
440: var founduname=0;
441: var foundpwd=0;
442: var foundname=0;
443: var foundid=0;
444: var foundsec=0;
1.73 www 445: var foundemail=0;
1.24 albertel 446: var tw;
447: for (i=0;i<=vf.nfields.value;i++) {
448: tw=eval('vf.f'+i+'.selectedIndex');
449: if (tw==1) { founduname=1; }
450: if ((tw>=2) && (tw<=6)) { foundname=1; }
451: if (tw==7) { foundid=1; }
452: if (tw==8) { foundsec=1; }
453: if (tw==9) { foundpwd=1; }
1.73 www 454: if (tw==10) { foundemail=1; }
1.24 albertel 455: }
1.73 www 456: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail);
1.24 albertel 457: }
458:
1.49 matthew 459: //
460: // vf = this.form
461: // tf = column number
462: //
463: // values of nw
464: //
465: // 0 = none
466: // 1 = username
467: // 2 = names (lastname, firstnames)
468: // 3 = fname (firstname)
469: // 4 = mname (middlename)
470: // 5 = lname (lastname)
471: // 6 = gen (generation)
472: // 7 = id
473: // 8 = section
474: // 9 = ipwd (password)
1.73 www 475: // 10 = email address
476:
1.24 albertel 477: function flip(vf,tf) {
478: var nw=eval('vf.f'+tf+'.selectedIndex');
479: var i;
1.49 matthew 480: // make sure no other columns are labeled the same as this one
1.24 albertel 481: for (i=0;i<=vf.nfields.value;i++) {
482: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
483: eval('vf.f'+i+'.selectedIndex=0;')
484: }
485: }
1.49 matthew 486: // If we set this to 'lastname, firstnames', clear out all the ones
487: // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
1.24 albertel 488: if (nw==2) {
489: for (i=0;i<=vf.nfields.value;i++) {
490: if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
491: (eval('vf.f'+i+'.selectedIndex')<=6)) {
492: eval('vf.f'+i+'.selectedIndex=0;')
493: }
494: }
495: }
1.49 matthew 496: // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
497: // clear out any that are set to 'lastname, firstnames' (2)
1.24 albertel 498: if ((nw>=3) && (nw<=6)) {
499: for (i=0;i<=vf.nfields.value;i++) {
500: if (eval('vf.f'+i+'.selectedIndex')==2) {
501: eval('vf.f'+i+'.selectedIndex=0;')
502: }
503: }
504: }
1.49 matthew 505: // If we set the password, make the password form below correspond to
506: // the new value.
1.24 albertel 507: if (nw==9) {
1.28 matthew 508: changed_radio('int',document.studentform);
509: set_auth_radio_buttons('int',document.studentform);
510: vf.intarg.value='';
511: vf.krbarg.value='';
1.24 albertel 512: vf.locarg.value='';
513: }
514: }
515:
516: function clearpwd(vf) {
517: var i;
518: for (i=0;i<=vf.nfields.value;i++) {
519: if (eval('vf.f'+i+'.selectedIndex')==9) {
520: eval('vf.f'+i+'.selectedIndex=0;')
521: }
522: }
523: }
524:
525: ENDPICK
526: }
527:
1.50 matthew 528: ###############################################################
529: ###############################################################
530: sub upload_manager_javascript_reverse_associate {
1.24 albertel 531: return(<<ENDPICK);
532: function verify(vf) {
533: var founduname=0;
534: var foundpwd=0;
535: var foundname=0;
536: var foundid=0;
537: var foundsec=0;
538: var tw;
539: for (i=0;i<=vf.nfields.value;i++) {
540: tw=eval('vf.f'+i+'.selectedIndex');
541: if (i==0 && tw!=0) { founduname=1; }
542: if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
543: if (i==6 && tw!=0) { foundid=1; }
544: if (i==7 && tw!=0) { foundsec=1; }
545: if (i==8 && tw!=0) { foundpwd=1; }
546: }
547: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
548: }
549:
550: function flip(vf,tf) {
551: var nw=eval('vf.f'+tf+'.selectedIndex');
552: var i;
553: // picked the all one one name field, reset the other name ones to blank
554: if (tf==1 && nw!=0) {
555: for (i=2;i<=5;i++) {
556: eval('vf.f'+i+'.selectedIndex=0;')
557: }
558: }
559: //picked one of the piecewise name fields, reset the all in
560: //one field to blank
561: if ((tf>=2) && (tf<=5) && (nw!=0)) {
562: eval('vf.f1.selectedIndex=0;')
563: }
564: // intial password specified, pick internal authentication
565: if (tf==8 && nw!=0) {
1.28 matthew 566: changed_radio('int',document.studentform);
567: set_auth_radio_buttons('int',document.studentform);
568: vf.krbarg.value='';
569: vf.intarg.value='';
1.24 albertel 570: vf.locarg.value='';
571: }
572: }
573:
574: function clearpwd(vf) {
575: var i;
576: if (eval('vf.f8.selectedIndex')!=0) {
577: eval('vf.f8.selectedIndex=0;')
578: }
579: }
1.2 www 580: ENDPICK
1.23 albertel 581: }
1.10 www 582:
1.50 matthew 583: ###############################################################
584: ###############################################################
585: sub print_upload_manager_footer {
1.23 albertel 586: my ($r,$i,$keyfields,$defdom,$today,$halfyear)=@_;
1.64 albertel 587:
588: my ($krbdef,$krbdefdom) =
589: &Apache::loncommon::get_kerberos_defaults($defdom);
590: my %param = ( formname => 'document.studentform',
591: kerb_def_dom => $krbdefdom,
592: kerb_def_auth => $krbdef
593: );
1.99 matthew 594: if (exists($ENV{'form.ipwd_choice'}) &&
595: defined($ENV{'form.ipwd_choice'}) &&
596: $ENV{'form.ipwd_choice'} ne '') {
597: $param{'curr_authtype'} = 'int';
598: }
1.28 matthew 599: my $krbform = &Apache::loncommon::authform_kerberos(%param);
600: my $intform = &Apache::loncommon::authform_internal(%param);
601: my $locform = &Apache::loncommon::authform_local(%param);
1.31 matthew 602: my $domform = &domain_form($defdom);
1.68 matthew 603: my $date_table = &date_setting_table();
1.90 matthew 604: my $Str = "</table>\n";
605: $Str .= &hidden_input('nfields',$i);
606: $Str .= &hidden_input('keyfields',$keyfields);
607: $Str .= '<h3>'.&mt('Login Type')."</h3>\n";
608: $Str .= "<p>\n".
609: &mt('Note: this will not take effect if the user already exists').
610: "</p><p>\n";
611: $Str .= $krbform."\n</p><p>\n".
612: $intform."\n</p><p>\n".
613: $locform."\n</p>\n";
614: $Str .= '<h3>'.&mt('LON-CAPA Domain for Students')."</h3>\n";
615: $Str .= "<p>\n".&mt('LON-CAPA domain: [_1]',$domform)."\n</p>\n";
616: $Str .= "<h3>".&mt('Starting and Ending Dates')."</h3>\n";
617: $Str .= "<p>\n".$date_table."</p>\n";
618: $Str .= "<h3>".&mt('Full Update')."</h3>\n";
619: $Str .= '<input type="checkbox" name="fullup" value="yes">'.
620: ' '.&mt('Full update (also print list of users not enrolled anymore)').
621: "</p>\n";
622: $Str .= "<h3>".&mt('Student Number')."</h3>\n";
623: $Str .= "<p>\n".'<input type="checkbox" name="forceid" value="yes">';
624: $Str .= &mt('Disable ID/Student Number Safeguard and Force Change '.
625: 'of Conflicting IDs (only do if you know what you are doing)').
626: "\n</p><p>\n";
627: $Str .= '<input type="button" onClick="javascript:verify(this.form)" '.
1.95 albertel 628: 'value="Update Class List" />'."<br />\n";
1.90 matthew 629: $Str .= &mt('Note: for large courses, this operation may be time '.
630: 'consuming');
631: $r->print($Str);
632: return;
1.23 albertel 633: }
1.24 albertel 634:
1.90 matthew 635: ###############################################################
636: ###############################################################
1.50 matthew 637: sub print_upload_manager_form {
1.23 albertel 638: my $r=shift;
1.99 matthew 639:
1.82 www 640: my $firstLine;
1.24 albertel 641: my $datatoken;
642: if (!$ENV{'form.datatoken'}) {
1.90 matthew 643: $datatoken=&Apache::loncommon::upfile_store($r);
1.24 albertel 644: } else {
1.90 matthew 645: $datatoken=$ENV{'form.datatoken'};
646: &Apache::loncommon::load_tmp_file($r);
1.24 albertel 647: }
648: my @records=&Apache::loncommon::upfile_record_sep();
1.90 matthew 649: if($ENV{'form.noFirstLine'}){
650: $firstLine=shift(@records);
651: }
1.23 albertel 652: my $total=$#records;
653: my $distotal=$total+1;
654: my $today=time;
655: my $halfyear=$today+15552000;
1.99 matthew 656: #
657: # Restore memorized settings
658: &Apache::loncommon::restore_course_settings
659: ('enrollment_upload',{ 'username_choice' => 'scalar', # column settings
660: 'names_choice' => 'scalar',
661: 'fname_choice' => 'scalar',
662: 'mname_choice' => 'scalar',
663: 'lname_choice' => 'scalar',
664: 'gen_choice' => 'scalar',
665: 'id_choice' => 'scalar',
666: 'sec_choice' => 'scalar',
667: 'ipwd_choice' => 'scalar',
668: 'email_choice' => 'scalar',
669: });
670: #
671: # Determine kerberos parameters as appropriate
1.85 matthew 672: my $defdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
1.64 albertel 673: my ($krbdef,$krbdefdom) =
674: &Apache::loncommon::get_kerberos_defaults($defdom);
1.99 matthew 675: #
1.50 matthew 676: &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom);
1.24 albertel 677: my $i;
678: my $keyfields;
1.23 albertel 679: if ($total>=0) {
1.99 matthew 680: my @field=
681: (['username',&mt('Username'), $ENV{'form.username_choice'}],
682: ['names',&mt('Last Name, First Names'),$ENV{'form.names_choice'}],
683: ['fname',&mt('First Name'), $ENV{'form.fname_choice'}],
684: ['mname',&mt('Middle Names/Initials'),$ENV{'form.mname_choice'}],
685: ['lname',&mt('Last Name'), $ENV{'form.lname_choice'}],
686: ['gen', &mt('Generation'), $ENV{'form.gen_choice'}],
687: ['id', &mt('ID/Student Number'),$ENV{'form.id_choice'}],
688: ['sec', &mt('Group/Section'), $ENV{'form.sec_choice'}],
689: ['ipwd', &mt('Initial Password'),$ENV{'form.ipwd_choice'}],
690: ['email',&mt('EMail Address'), $ENV{'form.email_choice'}]);
1.24 albertel 691: if ($ENV{'form.upfile_associate'} eq 'reverse') {
692: &Apache::loncommon::csv_print_samples($r,\@records);
1.90 matthew 693: $i=&Apache::loncommon::csv_print_select_table($r,\@records,
694: \@field);
695: foreach (@field) {
696: $keyfields.=$_->[0].',';
697: }
1.24 albertel 698: chop($keyfields);
699: } else {
1.90 matthew 700: unshift(@field,['none','']);
701: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
702: \@field);
1.24 albertel 703: my %sone=&Apache::loncommon::record_sep($records[0]);
704: $keyfields=join(',',sort(keys(%sone)));
1.23 albertel 705: }
706: }
1.50 matthew 707: &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear);
1.10 www 708: }
709:
1.90 matthew 710: ###############################################################
711: ###############################################################
1.12 www 712: sub enroll_single_student {
713: my $r=shift;
1.80 matthew 714: # Remove non alphanumeric values from section
715: $ENV{'form.csec'}=~s/\W//g;
1.68 matthew 716: #
717: # We do the dates first because the action of making them the defaul
1.107 www 718: # in the course is entirely separate from the action of enrolling the
1.68 matthew 719: # student. Also, a failure in setting the dates as default is not fatal
720: # to the process of enrolling / modifying a student.
721: my ($startdate,$enddate) = &get_dates_from_form();
722: if ($ENV{'form.makedatesdefault'}) {
723: $r->print(&make_dates_default($startdate,$enddate));
724: }
725:
1.94 sakharuk 726: $r->print('<h3>'.&mt('Enrolling Student').'</h3>');
727: $r->print('<p>'.&mt('Enrolling').' '.$ENV{'form.cuname'}." \@ ".
1.34 matthew 728: $ENV{'form.lcdomain'}.'</p>');
1.12 www 729: if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&
1.31 matthew 730: ($ENV{'form.lcdomain'})&&($ENV{'form.lcdomain'}!~/\W/)) {
731: # Deal with home server selection
732: my $domain=$ENV{'form.lcdomain'};
733: my $desiredhost = $ENV{'form.lcserver'};
734: if (lc($desiredhost) eq 'default') {
735: $desiredhost = undef;
736: } else {
1.45 matthew 737: my %home_servers =&Apache::loncommon::get_library_servers($domain);
1.31 matthew 738: if (! exists($home_servers{$desiredhost})) {
1.94 sakharuk 739: $r->print('<font color="#ff0000">'.&mt('Error').':</font>'.
740: &mt('Invalid home server specified'));
1.31 matthew 741: return;
742: }
743: }
1.94 sakharuk 744: $r->print(" ".&mt('with server')." $desiredhost :") if (defined($desiredhost));
1.31 matthew 745: # End of home server selection logic
1.12 www 746: my $amode='';
747: my $genpwd='';
748: if ($ENV{'form.login'} eq 'krb') {
1.47 albertel 749: $amode='krb';
750: $amode.=$ENV{'form.krbver'};
1.28 matthew 751: $genpwd=$ENV{'form.krbarg'};
1.12 www 752: } elsif ($ENV{'form.login'} eq 'int') {
1.26 matthew 753: $amode='internal';
1.28 matthew 754: $genpwd=$ENV{'form.intarg'};
1.15 albertel 755: } elsif ($ENV{'form.login'} eq 'loc') {
756: $amode='localauth';
757: $genpwd=$ENV{'form.locarg'};
758: if (!$genpwd) { $genpwd=" "; }
759: }
1.34 matthew 760: my $home = &Apache::lonnet::homeserver($ENV{'form.cuname'},
761: $ENV{'form.lcdomain'});
762: if ((($amode) && ($genpwd)) || ($home ne 'no_host')) {
1.55 matthew 763: # Clean out any old roles the student has in this class.
1.33 matthew 764: &modifystudent($ENV{'form.lcdomain'},$ENV{'form.cuname'},
765: $ENV{'request.course.id'},$ENV{'form.csec'},
766: $desiredhost);
1.55 matthew 767: my $login_result = &Apache::lonnet::modifystudent
768: ($ENV{'form.lcdomain'},$ENV{'form.cuname'},
769: $ENV{'form.cstid'},$amode,$genpwd,
770: $ENV{'form.cfirst'},$ENV{'form.cmiddle'},
771: $ENV{'form.clast'},$ENV{'form.cgen'},
1.67 matthew 772: $ENV{'form.csec'},$enddate,
773: $startdate,$ENV{'form.forceid'},
1.124 www 774: $desiredhost,$ENV{'form.emailaddress'});
1.55 matthew 775: if ($login_result =~ /^ok/) {
776: $r->print($login_result);
1.94 sakharuk 777: $r->print("<p> ".&mt('If active, the new role will be available when the student next logs in to LON-CAPA.')."</p>");
1.55 matthew 778: } else {
1.94 sakharuk 779: $r->print(&mt('unable to enroll').": ".$login_result);
1.55 matthew 780: }
1.12 www 781: } else {
1.94 sakharuk 782: $r->print('<p><font color="#ff0000">'.&mt('ERROR').'</font> ');
1.79 matthew 783: if ($amode =~ /^krb/) {
1.94 sakharuk 784: $r->print(&mt('Missing Kerberos domain information.').' ');
1.79 matthew 785: } else {
1.94 sakharuk 786: $r->print(&mt('Invalid login mode or password.').' ');
1.79 matthew 787: }
1.94 sakharuk 788: $r->print('<b>'.&mt('Unable to enroll').' '.$ENV{'form.cuname'}.'.</b></p>');
1.79 matthew 789: }
1.12 www 790: } else {
1.94 sakharuk 791: $r->print(&mt('Invalid username or domain'));
1.26 matthew 792: }
1.12 www 793: }
794:
1.68 matthew 795: sub setup_date_selectors {
1.91 raeburn 796: my ($starttime,$endtime,$mode) = @_;
1.68 matthew 797: if (! defined($starttime)) {
798: $starttime = time;
1.114 raeburn 799: unless ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1.91 raeburn 800: if (exists($ENV{'course.'.$ENV{'request.course.id'}.
1.68 matthew 801: '.default_enrollment_start_date'})) {
1.91 raeburn 802: $starttime = $ENV{'course.'.$ENV{'request.course.id'}.
1.68 matthew 803: '.default_enrollment_start_date'};
1.91 raeburn 804: }
1.68 matthew 805: }
806: }
807: if (! defined($endtime)) {
808: $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1.91 raeburn 809: unless ($mode eq 'createcourse') {
810: if (exists($ENV{'course.'.$ENV{'request.course.id'}.
1.68 matthew 811: '.default_enrollment_end_date'})) {
1.91 raeburn 812: $endtime = $ENV{'course.'.$ENV{'request.course.id'}.
1.68 matthew 813: '.default_enrollment_end_date'};
1.91 raeburn 814: }
1.68 matthew 815: }
816: }
817: my $startdateform = &Apache::lonhtmlcommon::date_setter('studentform',
818: 'startdate',
819: $starttime);
820: my $enddateform = &Apache::lonhtmlcommon::date_setter('studentform',
821: 'enddate',
822: $endtime);
1.114 raeburn 823: if ($mode eq 'create_enrolldates') {
824: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
825: 'startenroll',
826: $starttime);
827: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
828: 'endenroll',
829: $endtime);
830: }
831: if ($mode eq 'create_defaultdates') {
1.91 raeburn 832: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1.114 raeburn 833: 'startaccess',
1.91 raeburn 834: $starttime);
835: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1.114 raeburn 836: 'endaccess',
1.91 raeburn 837: $endtime);
838: }
1.68 matthew 839: return ($startdateform,$enddateform);
840: }
841:
842: sub get_dates_from_form {
843: my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
844: my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
845: if ($ENV{'form.no_end_date'}) {
846: $enddate = 0;
847: }
848: return ($startdate,$enddate);
849: }
850:
851: sub date_setting_table {
1.91 raeburn 852: my ($starttime,$endtime,$mode) = @_;
853: my ($startform,$endform)=&setup_date_selectors($starttime,$endtime,$mode);
1.68 matthew 854: my $dateDefault = '<nobr>'.
1.94 sakharuk 855: '<input type="checkbox" name="makedatesdefault" /> '.
856: &mt('make these dates the default for future enrollment');
1.114 raeburn 857: if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1.91 raeburn 858: $dateDefault = ' ';
859: }
1.68 matthew 860: my $perpetual = '<nobr><input type="checkbox" name="no_end_date"';
861: if (defined($endtime) && $endtime == 0) {
862: $perpetual .= ' checked';
863: }
1.94 sakharuk 864: $perpetual.= ' /> '.&mt('no ending date').'</nobr>';
1.114 raeburn 865: if ($mode eq 'create_enrolldates') {
866: $perpetual = ' ';
867: }
1.68 matthew 868: my $result = '';
869: $result .= "<table>\n";
1.94 sakharuk 870: $result .= '<tr><td align="right">'.&mt('Starting Date').'</td>'.
1.68 matthew 871: '<td>'.$startform.'</td>'.
872: '<td>'.$dateDefault.'</td>'."</tr>\n";
1.94 sakharuk 873: $result .= '<tr><td align="right">'.&mt('Ending Date').'</td>'.
1.68 matthew 874: '<td>'.$endform.'</td>'.
875: '<td>'.$perpetual.'</td>'."</tr>\n";
876: $result .= "</table>\n";
877: return $result;
878: }
879:
880: sub make_dates_default {
881: my ($startdate,$enddate) = @_;
882: my $result = '';
883: my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
884: my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
885: my $put_result = &Apache::lonnet::put('environment',
886: {'default_enrollment_start_date'=>$startdate,
887: 'default_enrollment_end_date' =>$enddate},$dom,$crs);
888: if ($put_result eq 'ok') {
889: $result .= "Set default start and end dates for course<br />";
1.69 matthew 890: #
891: # Refresh the course environment
892: &Apache::lonnet::coursedescription($ENV{'request.course.id'});
1.68 matthew 893: } else {
1.94 sakharuk 894: $result .= &mt('Unable to set default dates for course').":".$put_result.
1.68 matthew 895: '<br />';
896: }
897: return $result;
898: }
899:
1.74 matthew 900: ##
901: ## Single student enrollment routines (some of them)
902: ##
903: sub get_student_username_domain_form {
904: my $r = shift;
905: my $domform = &Apache::loncommon::select_dom_form
1.85 matthew 906: ($ENV{'course.'.$ENV{'request.course.id'}.'.domain'},'cudomain',0);
1.94 sakharuk 907: my %lt=&Apache::lonlocal::texthash(
908: 'eos' => "Enroll One Student",
909: 'usr' => "Username",
910: 'dom' => "Domain",
911: 'been' => "Begin Enrollment",
912: );
1.74 matthew 913: $r->print(<<END);
914: <input type="hidden" name="action" value="enrollstudent" />
915: <input type="hidden" name="state" value="gotusername" />
1.94 sakharuk 916: <h3>$lt{'eos'}</h3>
1.74 matthew 917: <table>
1.94 sakharuk 918: <tr><th>$lt{'usr'}:</th>
1.74 matthew 919: <td><input type="text" name="cuname" size="15" /></td></tr>
1.94 sakharuk 920: <tr><th>$lt{'dom'}:</th>
1.74 matthew 921: <td>$domform</td></tr>
922: <tr><th> </th>
923: <td>
1.94 sakharuk 924: <input type="submit" name="Begin Enrollment" value="$lt{'been'}" />
1.74 matthew 925: </td></tr>
926: </table>
1.120 albertel 927: <script type="text/javascript">
928: // the if prevents the script error if the browser can not handle this
929: if ( document.studentform.cuname ) { document.studentform.cuname.focus(); }
930: </script>
1.74 matthew 931: END
932: return;
933: }
934:
1.50 matthew 935: sub print_enroll_single_student_form {
1.10 www 936: my $r=shift;
1.94 sakharuk 937: $r->print("<h3>".&mt('Enroll One Student')."</h3>");
1.74 matthew 938: #
939: my $username = $ENV{'form.cuname'};
940: my $domain = $ENV{'form.cudomain'};
1.123 albertel 941: $username=~s/\W//gs;
942: $domain=~s/\W//gs;
1.74 matthew 943: my $home = &Apache::lonnet::homeserver($username,$domain);
944: # $new_user flags whether we are creating a new user or using an old one
945: my $new_user = 1;
946: if ($home ne 'no_host') {
947: $new_user = 0;
948: }
949: #
950: my $user_data_html = '';
951: my $javascript_validations = '';
952: if ($new_user) {
1.85 matthew 953: my $defdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
1.74 matthew 954: # Set up authentication forms
955: my ($krbdef,$krbdefdom) =
1.75 matthew 956: &Apache::loncommon::get_kerberos_defaults($domain);
1.89 matthew 957: $javascript_validations=&javascript_validations('auth',$krbdefdom);
1.74 matthew 958: my %param = ( formname => 'document.studentform',
959: kerb_def_dom => $krbdefdom,
960: kerb_def_auth => $krbdef
961: );
962: my $krbform = &Apache::loncommon::authform_kerberos(%param);
963: my $intform = &Apache::loncommon::authform_internal(%param);
964: my $locform = &Apache::loncommon::authform_local(%param);
965: #
966: # Set up domain selection form
967: my $homeserver_form = '';
968: my %servers = &Apache::loncommon::get_library_servers($domain);
969: $homeserver_form = '<select name="lcserver" size="1">'."\n".
970: '<option value="default" selected>default</option>'."\n";
971: while (my ($servername,$serverdescription) = each (%servers)) {
972: $homeserver_form .= '<option value="'.$servername.'">'.
973: $serverdescription."</option>\n";
974: }
975: $homeserver_form .= "</select>\n";
976: #
977: #
1.94 sakharuk 978: my %lt=&Apache::lonlocal::texthash(
979: 'udf' => "User Data for",
980: 'fn' => "First Name",
981: 'mn' => "Middle Name",
982: 'ln' => "Last Name",
983: 'gen' => "Generation",
984: 'hs' => "Home Server",
985: 'pswd' => "Password",
986: 'psam' => "Please select an authentication mechanism",
1.124 www 987: 'mail' => "Email Address"
1.94 sakharuk 988: );
1.74 matthew 989: $user_data_html = <<END;
1.94 sakharuk 990: <h3>$lt{'udf'} $username\@$domain</h3>
1.74 matthew 991: <table>
1.94 sakharuk 992: <tr><th>$lt{'fn'}:</th>
1.74 matthew 993: <td><input type="text" name="cfirst" size="15"></td></tr>
1.94 sakharuk 994: <tr><th>$lt{'mn'}:</th>
1.74 matthew 995: <td><input type="text" name="cmiddle" size="15"></td></tr>
1.94 sakharuk 996: <tr><th>$lt{'ln'}:</th>
1.74 matthew 997: <td><input type="text" name="clast" size="15"></td></tr>
1.94 sakharuk 998: <tr><th>$lt{'gen'}:</th>
1.74 matthew 999: <td><input type="text" name="cgen" size="5"> </td></tr>
1.94 sakharuk 1000: <tr><th>$lt{'hs'}:</th>
1.74 matthew 1001: <td>$homeserver_form</td></tr>
1.124 www 1002: <tr><th>$lt{'mail'}:</th>
1003: <td><input type="text" name="emailaddress" size="20" /></td></tr>
1.74 matthew 1004: </table>
1.94 sakharuk 1005: <h3>$lt{'pswd'}</h3>
1006: $lt{'psam'}
1.74 matthew 1007: <table>
1008: <p>
1009: $krbform
1.75 matthew 1010: <br />
1.74 matthew 1011: $intform
1.75 matthew 1012: <br />
1.74 matthew 1013: $locform
1014: </p>
1015: END
1016: } else {
1017: # User already exists. Do not worry about authentication
1018: my %uenv = &Apache::lonnet::dump('environment',$domain,$username);
1.89 matthew 1019: $javascript_validations = &javascript_validations('noauth');
1.94 sakharuk 1020: my %lt=&Apache::lonlocal::texthash(
1021: 'udf' => "User Data for",
1022: 'fn' => "First Name",
1023: 'mn' => "Middle Name",
1024: 'ln' => "Last Name",
1025: 'gen' => "Generation",
1.124 www 1026: 'mail' => "Email Address",
1.94 sakharuk 1027: );
1.74 matthew 1028: $user_data_html = <<END;
1.94 sakharuk 1029: <h3>$lt{'udf'} $username\@$domain</h3>
1.74 matthew 1030: <input type="hidden" name="lcserver" value="default" />
1031: <table>
1.94 sakharuk 1032: <tr><th>$lt{'fn'}:</th>
1.74 matthew 1033: <td>
1034: <input type="text" name="cfirst" value="$uenv{'firstname'}" size="15" />
1035: </td></tr>
1.94 sakharuk 1036: <tr><th>$lt{'mn'}:</th>
1.74 matthew 1037: <td>
1038: <input type="text" name="cmiddle" value="$uenv{'middlename'}" size="15" />
1039: </td></tr>
1.94 sakharuk 1040: <tr><th>$lt{'ln'}:</th>
1.74 matthew 1041: <td>
1042: <input type="text" name="clast"value="$uenv{'lastname'}" size="15" />
1043: </td></tr>
1.94 sakharuk 1044: <tr><th>$lt{'gen'}:</th>
1.74 matthew 1045: <td>
1046: <input type="text" name="cgen" value="$uenv{'generation'}" size="5" />
1047: </td></tr>
1.124 www 1048: <tr><th>$lt{'mail'}:</th>
1049: <td>
1050: <input type="text" name="emailaddress" value="$uenv{'permanentemail'}" size="20" />
1051: </td></tr>
1.74 matthew 1052: </table>
1053: END
1054: }
1.68 matthew 1055: my $date_table = &date_setting_table();
1.74 matthew 1056: # Print it all out
1.94 sakharuk 1057: my %lt=&Apache::lonlocal::texthash(
1058: 'cd' => "Course Data",
1059: 'gs' => "Group/Section",
1060: 'idsn' => "ID/Student Number",
1061: 'disn' => "Disable ID/Student Number Safeguard and Force Change of Conflicting IDs (only do if you know what you are doing)",
1062: 'eas' => "Enroll as student",
1063: );
1.50 matthew 1064: $r->print(<<END);
1.74 matthew 1065: <input type="hidden" name="action" value="enrollstudent" />
1066: <input type="hidden" name="state" value="done" />
1067: <input type="hidden" name="cuname" value="$username" />
1068: <input type="hidden" name="lcdomain" value="$domain" />
1.28 matthew 1069: <script type="text/javascript" language="Javascript">
1.12 www 1070: function verify(vf) {
1071: var founduname=0;
1072: var foundpwd=0;
1073: var foundname=0;
1074: var foundid=0;
1075: var foundsec=0;
1076: var tw;
1.26 matthew 1077: if ((typeof(vf.cuname.value) !="undefined") && (vf.cuname.value!='') &&
1.31 matthew 1078: (typeof(vf.lcdomain.value)!="undefined") && (vf.lcdomain.value!='')) {
1.12 www 1079: founduname=1;
1080: }
1.14 harris41 1081: if ((typeof(vf.cfirst.value)!="undefined") && (vf.cfirst.value!='') &&
1.26 matthew 1082: (typeof(vf.clast.value) !="undefined") && (vf.clast.value!='')) {
1.12 www 1083: foundname=1;
1084: }
1.14 harris41 1085: if ((typeof(vf.csec.value)!="undefined") && (vf.csec.value!='')) {
1.12 www 1086: foundsec=1;
1087: }
1.14 harris41 1088: if ((typeof(vf.cstid.value)!="undefined") && (vf.cstid.value!='')) {
1.12 www 1089: foundid=1;
1090: }
1091: if (founduname==0) {
1092: alert('You need to specify at least the username and domain fields');
1093: return;
1094: }
1.24 albertel 1095: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
1.12 www 1096: }
1097:
1.24 albertel 1098: $javascript_validations
1.12 www 1099:
1.24 albertel 1100: function clearpwd(vf) {
1101: //nothing else needs clearing
1.15 albertel 1102: }
1103:
1.12 www 1104: </script>
1.11 www 1105:
1.74 matthew 1106: $user_data_html
1.50 matthew 1107:
1.94 sakharuk 1108: <h3>$lt{'cd'}</h3>
1.50 matthew 1109:
1.94 sakharuk 1110: <p>$lt{'gs'}: <input type="text" name="csec" size="5" />
1.50 matthew 1111: <p>
1.68 matthew 1112: $date_table
1.50 matthew 1113: </p>
1.94 sakharuk 1114: <h3>$lt{'idsn'}</h3>
1.50 matthew 1115: <p>
1.94 sakharuk 1116: $lt{'idsn'}: <input type="text" name="cstid" size="10">
1.26 matthew 1117: </p><p>
1118: <input type="checkbox" name="forceid" value="yes">
1.94 sakharuk 1119: $lt{'disn'}
1.50 matthew 1120: </p><p>
1.94 sakharuk 1121: <input type="button" onClick="verify(this.form)" value="$lt{'eas'}">
1.26 matthew 1122: </p>
1.50 matthew 1123: END
1124: return;
1.10 www 1125: }
1126:
1127: # ========================================================= Menu Phase Two Drop
1.51 matthew 1128: sub print_drop_menu {
1.10 www 1129: my $r=shift;
1.92 sakharuk 1130: $r->print("<h3>".&mt('Drop Students')."</h3>");
1.11 www 1131: my $cid=$ENV{'request.course.id'};
1.56 matthew 1132: my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
1133: if (! defined($classlist)) {
1.94 sakharuk 1134: $r->print(&mt('There are no students currently enrolled.')."\n");
1.51 matthew 1135: return;
1.25 matthew 1136: }
1.51 matthew 1137: # Print out the available choices
1.56 matthew 1138: &show_drop_list($r,$classlist,$keylist);
1.51 matthew 1139: return;
1.11 www 1140: }
1141:
1.40 matthew 1142: # ============================================== view classlist
1.50 matthew 1143: sub print_html_classlist {
1.103 matthew 1144: my ($r,$mode) = @_;
1.57 matthew 1145: if (! exists($ENV{'form.sortby'})) {
1146: $ENV{'form.sortby'} = 'username';
1147: }
1.59 matthew 1148: if ($ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) {
1.57 matthew 1149: $ENV{'form.Status'} = 'Active';
1150: }
1151: my $status_select = &Apache::lonhtmlcommon::StatusOptions
1.103 matthew 1152: ($ENV{'form.Status'});
1.100 www 1153: my $cid=$ENV{'request.course.id'};
1154: my $cdom=$ENV{'course.'.$cid.'.domain'};
1155: my $cnum=$ENV{'course.'.$cid.'.num'};
1.103 matthew 1156: #
1157: # List course personnel
1.100 www 1158: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.110 matthew 1159: #
1160: if (! defined($ENV{'form.output'}) ||
1161: $ENV{'form.output'} !~ /^(csv|excel|html)$/ ) {
1162: $ENV{'form.output'} = 'html';
1163: }
1164: #
1.103 matthew 1165: $r->print('<br /><table border="2">');
1.110 matthew 1166: foreach my $role (sort keys %coursepersonnel) {
1167: next if ($role =~ /^\s*$/);
1168: $r->print('<tr><td>'.$role.'</td><td>');
1169: foreach my $user (split(',',$coursepersonnel{$role})) {
1170: my ($puname,$pudom)=split(':',$user);
1.100 www 1171: $r->print(' '.&Apache::loncommon::aboutmewrapper(
1.110 matthew 1172: &Apache::loncommon::plainname($puname,
1173: $pudom),
1174: $puname,$pudom));
1.100 www 1175: }
1176: $r->print('</td></tr>');
1177: }
1178: $r->print('</table>');
1.103 matthew 1179: #
1180: # Interface output
1181: $r->print('<input type="hidden" name="action" value="'.
1182: $ENV{'form.action'}.'" />');
1183: $r->print("<p>\n");
1.59 matthew 1184: if ($ENV{'form.action'} ne 'modifystudent') {
1.103 matthew 1185: my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
1186: 'excel' => "Excel",
1187: 'html' => 'HTML');
1.110 matthew 1188: my $output_selector = '<select size="1" name="output" >';
1.103 matthew 1189: foreach my $outputformat ('html','csv','excel') {
1190: my $option = '<option value="'.$outputformat.'" ';
1.110 matthew 1191: if ($outputformat eq $ENV{'form.output'}) {
1.104 matthew 1192: $option .= 'selected ';
1.103 matthew 1193: }
1194: $option .='>'.$lt{$outputformat}.'</option>';
1195: $output_selector .= "\n".$option;
1196: }
1197: $output_selector .= '</select>';
1198: $r->print(&mt('Output Format: [_1]',$output_selector).(' 'x3));
1.59 matthew 1199: }
1.103 matthew 1200: $r->print(&mt('Student Status: [_1]',$status_select)."\n");
1.105 matthew 1201: $r->print('<input type="submit" value="'.&mt('Update Display').'" />'.
1202: "\n</p>\n");
1.103 matthew 1203: #
1204: # Print the classlist
1205: $r->print('<h2>'.&mt('Current Class List').'</h2>');
1.56 matthew 1206: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
1207: if (! defined($classlist)) {
1.94 sakharuk 1208: $r->print(&mt('There are no students currently enrolled.')."\n");
1.40 matthew 1209: } else {
1210: # Print out the available choices
1.50 matthew 1211: if ($ENV{'form.action'} eq 'modifystudent') {
1.110 matthew 1212: &show_class_list($r,'view','modify',
1.57 matthew 1213: $ENV{'form.Status'},$classlist,$keylist);
1.110 matthew 1214: } else {
1215: &show_class_list($r,$ENV{'form.output'},'aboutme',
1.103 matthew 1216: $ENV{'form.Status'},$classlist,$keylist);
1.50 matthew 1217: }
1.41 matthew 1218: }
1219: }
1220:
1.40 matthew 1221: # =================================================== Show student list to drop
1222: sub show_class_list {
1.110 matthew 1223: my ($r,$mode,$linkto,$statusmode,$classlist,$keylist)=@_;
1.40 matthew 1224: my $cid=$ENV{'request.course.id'};
1.60 matthew 1225: #
1226: # Variables for excel output
1.104 matthew 1227: my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
1.60 matthew 1228: #
1.103 matthew 1229: # Variables for csv output
1230: my ($CSVfile,$CSVfilename);
1231: #
1.53 matthew 1232: my $sortby = $ENV{'form.sortby'};
1.114 raeburn 1233: if ($sortby !~ /^(username|domain|section|fullname|id|start|end|type)$/) {
1.53 matthew 1234: $sortby = 'username';
1235: }
1.42 matthew 1236: # Print out header
1.114 raeburn 1237: unless ($mode eq 'autoenroll') {
1238: $r->print(<<END);
1239: <input type="hidden" name="state" value="$ENV{'form.state'}" />
1240: END
1241: }
1.103 matthew 1242: $r->print(<<END);
1243: <input type="hidden" name="sortby" value="$sortby" />
1244: END
1.114 raeburn 1245: if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll') {
1.50 matthew 1246: if ($linkto eq 'aboutme') {
1.94 sakharuk 1247: $r->print(&mt('Select a user name to view the users personal page.'));
1.50 matthew 1248: } elsif ($linkto eq 'modify') {
1.94 sakharuk 1249: $r->print(&mt('Select a user name to modify the students information'));
1.50 matthew 1250: }
1.94 sakharuk 1251: my %lt=&Apache::lonlocal::texthash(
1.110 matthew 1252: 'usrn' => "username",
1253: 'dom' => "domain",
1254: 'sn' => "student name",
1255: 'sec' => "section",
1256: 'start' => "start date",
1257: 'end' => "end date",
1.115 raeburn 1258: 'type' => "enroll type/action"
1.94 sakharuk 1259: );
1.114 raeburn 1260: unless ($mode eq 'autoenroll') {
1261: $r->print(<<END);
1.59 matthew 1262: <input type="hidden" name="sname" value="" />
1263: <input type="hidden" name="sdom" value="" />
1.114 raeburn 1264: END
1265: }
1.115 raeburn 1266: $r->print("
1.40 matthew 1267: <p>
1268: <table border=2>
1.115 raeburn 1269: <tr>
1270: ");
1271: if ($mode eq 'autoenroll') {
1272: $r->print("
1273: <th><a href=\"javascript:document.studentform.sortby.value='type';document.studentform.submit();\">$lt{'type'}</a></th>
1274: ");
1275: } else {
1276: $r->print("
1277: <th>Count</th>
1278: ");
1279: }
1280: $r->print(<<END);
1281: <th>
1.94 sakharuk 1282: <a href="javascript:document.studentform.sortby.value='username';document.studentform.submit();">$lt{'usrn'}</a>
1.53 matthew 1283: </th><th>
1.94 sakharuk 1284: <a href="javascript:document.studentform.sortby.value='domain';document.studentform.submit();">$lt{'dom'}</a>
1.53 matthew 1285: </th><th>
1.57 matthew 1286: <a href="javascript:document.studentform.sortby.value='id';document.studentform.submit();">ID</a>
1.53 matthew 1287: </th><th>
1.94 sakharuk 1288: <a href="javascript:document.studentform.sortby.value='fullname';document.studentform.submit();">$lt{'sn'}</a>
1.53 matthew 1289: </th><th>
1.94 sakharuk 1290: <a href="javascript:document.studentform.sortby.value='section';document.studentform.submit();">$lt{'sec'}</a>
1.110 matthew 1291: </th><th>
1292: <a href="javascript:document.studentform.sortby.value='start';document.studentform.submit();">$lt{'start'}</a>
1293: </th><th>
1294: <a href="javascript:document.studentform.sortby.value='end';document.studentform.submit();">$lt{'end'}</a>
1.53 matthew 1295: </th>
1.115 raeburn 1296: </tr>
1.40 matthew 1297: END
1.41 matthew 1298: } elsif ($mode eq 'csv') {
1.103 matthew 1299: #
1300: # Open a file
1301: $CSVfilename = '/prtspool/'.
1302: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
1303: time.'_'.rand(1000000000).'.csv';
1304: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
1305: $r->log_error("Couldn't open $CSVfilename for output $!");
1306: $r->print("Problems occured in writing the csv file. ".
1307: "This error has been logged. ".
1308: "Please alert your LON-CAPA administrator.");
1309: $CSVfile = undef;
1310: }
1311: #
1312: # Write headers and data to file
1.58 matthew 1313: if($statusmode eq 'Expired') {
1.103 matthew 1314: print $CSVfile '"'.&mt('Students with expired roles').'"'."\n";
1.58 matthew 1315: }
1316: if ($statusmode eq 'Any') {
1.103 matthew 1317: print $CSVfile '"'.join('","',map {
1318: &Apache::loncommon::csv_translate(&mt($_))
1319: } ("username","domain","ID","student name",
1.110 matthew 1320: "section","start date","end date","status")).'"'."\n";
1.58 matthew 1321: } else {
1.103 matthew 1322: print $CSVfile '"'.join('","',map {
1323: &Apache::loncommon::csv_translate(&mt($_))
1324: } ("username","domain","ID","student name",
1.110 matthew 1325: "section","start date","end date")).'"'."\n";
1.58 matthew 1326: }
1.60 matthew 1327: } elsif ($mode eq 'excel') {
1328: # Create the excel spreadsheet
1329: $excel_filename = '/prtspool/'.
1330: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
1331: time.'_'.rand(1000000000).'.xls';
1332: $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.
1333: $excel_filename);
1334: $excel_workbook->set_tempdir('/home/httpd/perl/tmp');
1.104 matthew 1335: #
1336: $format = &Apache::loncommon::define_excel_formats($excel_workbook);
1.60 matthew 1337: $excel_sheet = $excel_workbook->addworksheet('classlist');
1338: #
1.76 albertel 1339: my $description = 'Class List for '.
1.60 matthew 1340: $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
1.104 matthew 1341: $excel_sheet->write($row++,0,$description,$format->{'h1'});
1.60 matthew 1342: #
1343: $excel_sheet->write($row++,0,["username","domain","ID",
1.110 matthew 1344: "student name","section",
1345: "start date","end date","status"],
1346: $format->{'bold'});
1.41 matthew 1347: }
1.56 matthew 1348: #
1349: # Sort the students
1350: my %index;
1351: my $i;
1352: foreach (@$keylist) {
1353: $index{$_} = $i++;
1354: }
1355: my $index = $index{$sortby};
1356: my $second = $index{'username'};
1357: my $third = $index{'domain'};
1.53 matthew 1358: my @Sorted_Students = sort {
1.56 matthew 1359: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
1360: ||
1361: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
1362: ||
1363: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
1364: } (keys(%$classlist));
1.108 matthew 1365: my $studentcount = 0;
1.115 raeburn 1366: my $autocount = 0;
1367: my $manualcount = 0;
1368: my $unlockcount = 0;
1369: my $lockcount = 0;
1.53 matthew 1370: foreach my $student (@Sorted_Students) {
1.110 matthew 1371: my $sdata = $classlist->{$student};
1372: my $username = $sdata->[$index{'username'}];
1373: my $domain = $sdata->[$index{'domain'}];
1374: my $section = $sdata->[$index{'section'}];
1375: my $name = $sdata->[$index{'fullname'}];
1376: my $id = $sdata->[$index{'id'}];
1377: my $status = $sdata->[$index{'status'}];
1378: my $start = $sdata->[$index{'start'}];
1379: my $end = $sdata->[$index{'end'}];
1.115 raeburn 1380: my $type = $sdata->[$index{'type'}];
1.57 matthew 1381: next if (($statusmode ne 'Any') && ($status ne $statusmode));
1.114 raeburn 1382: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
1383: if (! defined($start) || $start == 0) {
1384: $start = &mt('none');
1385: } else {
1386: $start = &Apache::lonlocal::locallocaltime($start);
1387: }
1388: if (! defined($end) || $end == 0) {
1389: $end = &mt('none');
1390: } else {
1391: $end = &Apache::lonlocal::locallocaltime($end);
1392: }
1.115 raeburn 1393: $r->print("<tr>\n ");
1394: if ($mode eq 'autoenroll') {
1395: my $lockedtype = $sdata->[$index{'lockedtype'}];
1396: $studentcount++;
1397: my $cellentry;
1398: if ($type eq 'auto') {
1399: $cellentry = '<b>'.&mt('auto').'</b> <input type="checkbox" name="chgauto" value="'.$username.':'.$domain.'" /> Change';
1400: $autocount ++;
1401: } else {
1.118 raeburn 1402: $cellentry = '<table border="0" cellspacing="0"><tr><td rowspan="2"><b>'.&mt('manual').'</b></td><td><nobr><input type="checkbox" name="chgmanual" value="'.$username.':'.$domain.'" /> Change</nobr></td></tr><tr><td><nobr>';
1.115 raeburn 1403: $manualcount ++;
1404: if ($lockedtype) {
1405: $cellentry .= '<input type="checkbox" name="unlockchg" value="'.$username.':'.$domain.'" /> '.&mt('Unlock');
1406: $unlockcount ++;
1407: } else {
1408: $cellentry .= '<input type="checkbox" name="lockchg" value="'.$username.':'.$domain.'" /> '.&mt('Lock');
1409: $lockcount ++;
1410: }
1.118 raeburn 1411: $cellentry .= '</nobr></td></tr></table>';
1.115 raeburn 1412: }
1413: $r->print("<td>$cellentry<td>\n ");
1414: } else {
1415: $r->print("<td>".(++$studentcount)."</td><td>\n ");
1416: }
1.51 matthew 1417: if ($linkto eq 'nothing') {
1418: $r->print($username);
1419: } elsif ($linkto eq 'aboutme') {
1420: $r->print(&Apache::loncommon::aboutmewrapper($username,
1421: $username,
1422: $domain));
1423: } elsif ($linkto eq 'modify') {
1.59 matthew 1424: $r->print('<a href="'.
1425: "javascript:document.studentform.sname.value='".
1426: $username.
1427: "';document.studentform.sdom.value='".$domain.
1428: "';document.studentform.state.value='selected".
1429: "';document.studentform.submit();".'">'.
1.53 matthew 1430: $username."</a>\n");
1.50 matthew 1431: }
1.51 matthew 1432: $r->print(<<"END");
1.50 matthew 1433: </td>
1.51 matthew 1434: <td>$domain</td>
1435: <td>$id</td>
1436: <td>$name</td>
1437: <td>$section</td>
1.110 matthew 1438: <td>$start</td>
1439: <td>$end</td>
1.115 raeburn 1440: </tr>
1.114 raeburn 1441: END
1.51 matthew 1442: } elsif ($mode eq 'csv') {
1.103 matthew 1443: next if (! defined($CSVfile));
1.51 matthew 1444: # no need to bother with $linkto
1.114 raeburn 1445: if (! defined($start) || $start == 0) {
1446: $start = &mt('none');
1447: } else {
1448: $start = &Apache::lonlocal::locallocaltime($start);
1449: }
1450: if (! defined($end) || $end == 0) {
1451: $end = &mt('none');
1452: } else {
1453: $end = &Apache::lonlocal::locallocaltime($end);
1454: }
1.51 matthew 1455: my @line = ();
1.110 matthew 1456: foreach ($username,$domain,$id,$name,$section,$start,$end) {
1.51 matthew 1457: push @line,&Apache::loncommon::csv_translate($_);
1.58 matthew 1458: }
1459: if ($statusmode eq 'Any') {
1460: push @line,&Apache::loncommon::csv_translate($status);
1.41 matthew 1461: }
1.103 matthew 1462: print $CSVfile '"'.join('","',@line).'"'."\n";
1.60 matthew 1463: } elsif ($mode eq 'excel') {
1.110 matthew 1464: $excel_sheet->write($row,0,[$username,$domain,$id,
1465: $name,$section]);
1466: my $col = 5;
1467: foreach my $time ($start,$end) {
1468: $excel_sheet->write($row,$col++,
1469: &Apache::lonstathelpers::calc_serial($time),
1470: $format->{'date'});
1471: }
1472: $excel_sheet->write($row,$col++,$status);
1473: $row++;
1.40 matthew 1474: }
1475: }
1.114 raeburn 1476: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
1.60 matthew 1477: $r->print('</table><br>');
1478: } elsif ($mode eq 'excel') {
1479: $excel_workbook->close();
1480: $r->print('<p><a href="'.$excel_filename.'">'.
1.94 sakharuk 1481: &mt('Your Excel spreadsheet').'</a> '.&mt('is ready for download').'.</p>'."\n");
1.103 matthew 1482: } elsif ($mode eq 'csv') {
1483: close($CSVfile);
1484: $r->print('<a href="'.$CSVfilename.'">'.
1485: &mt('Your CSV file').'</a> is ready for download.'.
1486: "\n");
1487: $r->rflush();
1.60 matthew 1488: }
1.114 raeburn 1489: if ($mode eq 'autoenroll') {
1.115 raeburn 1490: return ($studentcount,$autocount,$manualcount,$lockcount,$unlockcount);
1.114 raeburn 1491: }
1.115 raeburn 1492: return;
1.40 matthew 1493: }
1494:
1.50 matthew 1495:
1496: #
1497: # print out form for modification of a single students data
1498: #
1499: sub print_modify_student_form {
1500: my $r = shift();
1501: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.59 matthew 1502: ['sdom','sname']);
1.53 matthew 1503: my $sname = $ENV{'form.sname'};
1504: my $sdom = $ENV{'form.sdom'};
1505: my $sortby = $ENV{'form.sortby'};
1.50 matthew 1506: # determine the students name information
1507: my %info=&Apache::lonnet::get('environment',
1508: ['firstname','middlename',
1.52 matthew 1509: 'lastname','generation','id'],
1.50 matthew 1510: $sdom, $sname);
1511: my ($tmp) = keys(%info);
1512: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.94 sakharuk 1513: $r->print('<font color="#ff0000" size="+2">'.&mt('Error').'</font>'.
1.50 matthew 1514: '<p>'.
1.94 sakharuk 1515: &mt('Unable to retrieve environment data for').' '.$sname.
1516: &mt('in domain').' '.$sdom.'</p><p>'.
1517: &mt('Please contact your LON-CAPA administrator regarding this situation.').'</p></body></html>');
1.50 matthew 1518: return;
1519: }
1520: # determine the students starting and ending times and section
1521: my ($starttime,$endtime,$section) = &get_enrollment_data($sname,$sdom);
1.87 matthew 1522: if ($starttime =~ /^error/) {
1.94 sakharuk 1523: $r->print('<h2>'&mt('Error').'</h2>');
1.87 matthew 1524: $r->print('<p>'.$starttime.'</p>');
1525: return;
1526: }
1.101 matthew 1527: #
1.50 matthew 1528: # Deal with date forms
1.101 matthew 1529: my $current_date_description = '';
1530: my $textdate = '';
1531:
1532: if (! defined($starttime) || $starttime == 0) {
1533: $current_date_description = &mt('Current Starting Date: not set').
1534: '<br />';
1535: } else {
1536: $current_date_description =
1537: &mt('Current Starting Date: [_1]',
1538: &Apache::lonlocal::locallocaltime($starttime)).'<br />';
1539: }
1540: if (! defined($endtime) || $endtime == 0) {
1541: $current_date_description.= &mt('Current Ending Date: not set').
1542: '<br />';
1543: } else {
1544: $current_date_description.=
1545: &mt('Current Ending Date: [_1]',
1546: &Apache::lonlocal::locallocaltime($endtime)).'<br />';
1547:
1548: }
1.68 matthew 1549: my $date_table = &date_setting_table($starttime,$endtime);
1.59 matthew 1550: #
1551: if (! exists($ENV{'form.Status'}) ||
1552: $ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) {
1553: $ENV{'form.Status'} = 'crap';
1554: }
1.94 sakharuk 1555: # Make sure student is enrolled in course
1556: my %lt=&Apache::lonlocal::texthash(
1557: 'mef' => "Modify Enrollment for",
1558: 'odcc' => "Only domain coordinators can change a users password.",
1559: 'sn' => "Student Name",
1560: 'fn' => "First",
1561: 'mn' => "Middle",
1562: 'ln' => "Last",
1563: 'gen' => "Generation",
1564: 'sid' => "Student ID",
1565: 'disn' => "Disable ID/Student Number Safeguard and Force Change of Conflicting IDs (only do if you know what you are doing)",
1566: 'sec' => "Section",
1567: 'sm' => "Submit Modifications",
1568: );
1.50 matthew 1569: $r->print(<<END);
1.52 matthew 1570: <p>
1571: <font size="+1">
1.94 sakharuk 1572: $lt{'odcc'}
1.52 matthew 1573: </font>
1574: </p>
1.50 matthew 1575: <input type="hidden" name="slogin" value="$sname" />
1576: <input type="hidden" name="sdomain" value="$sdom" />
1577: <input type="hidden" name="action" value="modifystudent" />
1.53 matthew 1578: <input type="hidden" name="state" value="done" />
1579: <input type="hidden" name="sortby" value="$sortby" />
1.59 matthew 1580: <input type="hidden" name="Status" value="$ENV{'form.Status'}" />
1.94 sakharuk 1581: <h2>$lt{'mef'} $info{'firstname'} $info{'middlename'}
1.50 matthew 1582: $info{'lastname'} $info{'generation'}, $sname\@$sdom</h2>
1583: <p>
1.94 sakharuk 1584: <b>$lt{'sn'}</b>
1.50 matthew 1585: <table>
1.94 sakharuk 1586: <tr><th>$lt{'fn'}</th><th>$lt{'mn'}</th><th>$lt{'ln'}</th><th>$lt{'gen'}</th></tr>
1.50 matthew 1587: <tr><td>
1588: <input type="text" name="firstname" value="$info{'firstname'}" /></td><td>
1589: <input type="text" name="middlename" value="$info{'middlename'}" /></td><td>
1590: <input type="text" name="lastname" value="$info{'lastname'}" /></td><td>
1591: <input type="text" name="generation" value="$info{'generation'}" /></td></tr>
1592: </table>
1593: </p><p>
1.94 sakharuk 1594: <b>$lt{'sid'}</b>: <input type="text" name="id" value="$info{'id'}" size="12"/>
1.52 matthew 1595: </p><p>
1.53 matthew 1596: <input type="checkbox" name="forceid" >
1.94 sakharuk 1597: $lt{'disn'}
1.53 matthew 1598: </p><p>
1.101 matthew 1599: <b>$lt{'sec'}</b>: <input type="text" name="section" value="$section" size="14"/>
1.50 matthew 1600: </p>
1.101 matthew 1601: <p>$current_date_description</p>
1.68 matthew 1602: <p>$date_table</p>
1.94 sakharuk 1603: <input type="submit" value="$lt{'sm'}" />
1.50 matthew 1604: </body></html>
1605: END
1606: return;
1607: }
1608:
1609: #
1610: # modify a single students section
1611: #
1612: sub modify_single_student {
1613: my $r = shift;
1.68 matthew 1614: #
1.80 matthew 1615: # Remove non alphanumeric values from the section
1616: $ENV{'form.section'} =~ s/\W//g;
1.77 matthew 1617: #
1.68 matthew 1618: # Do the date defaults first
1619: my ($starttime,$endtime) = &get_dates_from_form();
1620: if ($ENV{'form.makedatesdefault'}) {
1621: $r->print(&make_dates_default($starttime,$endtime));
1622: }
1.59 matthew 1623: # Get the 'sortby' and 'Status' variables so the user goes back to their
1624: # previous screen
1.53 matthew 1625: my $sortby = $ENV{'form.sortby'};
1.59 matthew 1626: my $status = $ENV{'form.Status'};
1.53 matthew 1627: #
1628: # We always need this information
1629: my $slogin = $ENV{'form.slogin'};
1630: my $sdom = $ENV{'form.sdomain'};
1631: #
1632: # Get the old data
1633: my %old=&Apache::lonnet::get('environment',
1634: ['firstname','middlename',
1635: 'lastname','generation','id'],
1636: $sdom, $slogin);
1.59 matthew 1637: $old{'section'} = &Apache::lonnet::getsection($sdom,$slogin,
1638: $ENV{'request.course.id'});
1.53 matthew 1639: my ($tmp) = keys(%old);
1640: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.94 sakharuk 1641: $r->print(&mt('There was an error determining the environment values for')." $slogin \@ $sdom.");
1.53 matthew 1642: return;
1643: }
1644: undef $tmp;
1645: #
1646: # Get the new data
1.50 matthew 1647: my $firstname = $ENV{'form.firstname'};
1648: my $middlename = $ENV{'form.middlename'};
1649: my $lastname = $ENV{'form.lastname'};
1650: my $generation = $ENV{'form.generation'};
1651: my $section = $ENV{'form.section'};
1652: my $courseid = $ENV{'request.course.id'};
1.52 matthew 1653: my $sid = $ENV{'form.id'};
1.50 matthew 1654: my $displayable_starttime = localtime($starttime);
1655: my $displayable_endtime = localtime($endtime);
1.53 matthew 1656: #
1657: # check for forceid override
1.63 matthew 1658: if ((defined($old{'id'})) && ($old{'id'} ne '') &&
1659: ($sid ne $old{'id'}) && (! exists($ENV{'form.forceid'}))) {
1.94 sakharuk 1660: $r->print("<font color=\"ff0000\">".&mt('You changed the students id but did not disable the ID change safeguard. The students id will not be changed.')."</font>");
1.53 matthew 1661: $sid = $old{'id'};
1662: }
1663: #
1.50 matthew 1664: # talk to the user about what we are going to do
1.94 sakharuk 1665: my %lt=&Apache::lonlocal::texthash(
1666: 'mdu' => "Modifying data for user",
1667: 'si' => "Student Information",
1668: 'fd' => "Field",
1669: 'ov' => "Old Value",
1670: 'nv' => "New Value",
1671: 'fn' => "First name",
1672: 'mn' => "Middle name",
1673: 'ln' => "Last name",
1674: 'gen' => "Generation",
1675: 'sec' => "Section",
1676: 'ri' => "Role Information",
1677: 'st' => "Start Time",
1678: 'et' => "End Time",
1679: );
1.50 matthew 1680: $r->print(<<END);
1.94 sakharuk 1681: <h2>$lt{'mdu'} $slogin \@ $sdom </h2>
1682: <h3>$lt{'si'}</h3>
1.53 matthew 1683: <table rules="rows" border="1" cellpadding="3" >
1684: <tr>
1.94 sakharuk 1685: <th> $lt{'fd'} </th>
1686: <th> $lt{'ov'} </th>
1687: <th> $lt{'nv'} </th>
1.53 matthew 1688: </tr>
1689: <tr>
1.94 sakharuk 1690: <td> <b>$lt{'fn'}</b> </td>
1.53 matthew 1691: <td> $old{'firstname'} </td>
1692: <td> $firstname </td>
1693: </tr><tr>
1.94 sakharuk 1694: <td> <b>$lt{'mn'}</b> </td>
1.53 matthew 1695: <td> $old{'middlename'} </td>
1696: <td> $middlename </td>
1697: </tr><tr>
1.94 sakharuk 1698: <td> <b>$lt{'ln'}</b> </td>
1.53 matthew 1699: <td> $old{'lastname'} </td>
1700: <td> $lastname </td>
1701: </tr><tr>
1.94 sakharuk 1702: <td> <b>$lt{'gen'}</b> </td>
1.53 matthew 1703: <td> $old{'generation'} </td>
1704: <td> $generation </td>
1705: </tr><tr>
1706: <td> <b>ID</b> </td>
1707: <td> $old{'id'} </td>
1708: <td> $sid </td>
1.59 matthew 1709: </tr><tr>
1.94 sakharuk 1710: <td> <b>$lt{'sec'}</b> </td>
1.59 matthew 1711: <td> $old{'section'} </td>
1712: <td> $section</td>
1.53 matthew 1713: </tr>
1.50 matthew 1714: </table>
1.94 sakharuk 1715: <h3>$lt{'ri'}</h3>
1.50 matthew 1716: <table>
1.94 sakharuk 1717: <tr><td align="right"><b>$lt{'st'}:</b></td><td> $displayable_starttime </td></tr>
1718: <tr><td align="right"><b>$lt{'et'}:</b></td><td> $displayable_endtime </td></tr>
1.50 matthew 1719: </table>
1.52 matthew 1720: <p>
1.50 matthew 1721: END
1.53 matthew 1722: #
1.63 matthew 1723: # Send request(s) to modify data (final undef is for 'desiredhost',
1724: # which is a moot point because the student already has an account.
1725: my $modify_section_results = &modifystudent($sdom,$slogin,
1726: $ENV{'request.course.id'},
1727: $section,undef);
1728: if ($modify_section_results !~ /^ok/) {
1.94 sakharuk 1729: $r->print(&mt('An error occured during the attempt to change the section for this student.')."<br />");
1.63 matthew 1730: }
1.52 matthew 1731: my $roleresults = &Apache::lonnet::modifystudent
1.53 matthew 1732: ($sdom,$slogin,$sid,undef,undef,$firstname,$middlename,$lastname,
1733: $generation,$section,$endtime,$starttime,$ENV{'form.forceid'});
1734: if ($roleresults eq 'refused' ) {
1.94 sakharuk 1735: $r->print(&mt('Your request to change the role information for this student was refused. You do not appear to have sufficient authority to change student information.'));
1.50 matthew 1736: } elsif ($roleresults !~ /ok/) {
1.94 sakharuk 1737: $r->print(&mt('An error occurred during the attempt to change the role information for this student.')." <br />".
1738: &mt('The error reported was')." ".
1.50 matthew 1739: $roleresults);
1.53 matthew 1740: &Apache::lonnet::logthis("londropadd:failed attempt to modify student".
1741: " data for ".$slogin." \@ ".$sdom." by ".
1742: $ENV{'user.name'}." \@ ".$ENV{'user.domain'}.
1743: ":".$roleresults);
1.50 matthew 1744: } else { # everything is okay!
1.94 sakharuk 1745: $r->print(&mt('Student information updated successfully.')." <br />".
1746: &mt('The student must log out and log in again to see these changes.'));
1.50 matthew 1747: }
1.94 sakharuk 1748: my $Masd=&mt('Modify another students data');
1.50 matthew 1749: $r->print(<<END);
1.52 matthew 1750: </p><p>
1.59 matthew 1751: <input type="hidden" name="action" value="modifystudent" />
1752: <input type="hidden" name="sortby" value="$sortby" />
1753: <input type="hidden" name="Status" value="$status" />
1.94 sakharuk 1754: <a href="javascript:document.studentform.submit();">$Masd</a>
1.50 matthew 1755: </body></html>
1756: END
1757: return;
1758: }
1759:
1760: sub get_enrollment_data {
1761: my ($sname,$sdomain) = @_;
1762: my $courseid = $ENV{'request.course.id'};
1763: $courseid =~ s:_:/:g;
1764: my %roles = &Apache::lonnet::dump('roles',$sdomain,$sname);
1765: my ($tmp) = keys(%roles);
1766: # Bail out if we were unable to get the students roles
1.87 matthew 1767: return ('error'.$tmp) if ($tmp =~ /^(con_lost|error|no_such_host)/i);
1.50 matthew 1768: # Go through the roles looking for enrollment in this course
1769: my ($end,$start) = (undef,undef);
1770: my $section = '';
1771: my $count = scalar(keys(%roles));
1772: while (my ($course,$role) = each(%roles)) {
1773: if ($course=~ /^\/$courseid\/*\s*(\w+)*_st$/ ) {
1774: #
1775: # Get active role
1776: $section=$1;
1777: (undef,$end,$start)=split(/\_/,$role);
1778: my $now=time;
1779: my $notactive=0;
1780: if ($start) {
1781: if ($now<$start) { $notactive=1; }
1782: }
1783: if ($end) {
1784: if ($now>$end) { $notactive=1; }
1785: }
1786: unless ($notactive) { return ($start,$end,$section); }
1787: }
1788: }
1789: return ($start,$end,$section);
1790: }
1791:
1.56 matthew 1792: #################################################
1793: #################################################
1794:
1795: =pod
1796:
1797: =item show_drop_list
1798:
1799: Display a list of students to drop
1800: Inputs:
1801:
1802: =over 4
1803:
1804: =item $r, Apache request
1805:
1806: =item $classlist, hash pointer returned from loncoursedata::get_classlist();
1807:
1808: =item $keylist, array pointer returned from loncoursedata::get_classlist()
1809: which describes the order elements are stored in the %$classlist values.
1810:
1811: =item $nosort, if true, sorting links are omitted.
1812:
1813: =back
1814:
1815: =cut
1816:
1817: #################################################
1818: #################################################
1.11 www 1819: sub show_drop_list {
1.56 matthew 1820: my ($r,$classlist,$keylist,$nosort)=@_;
1.11 www 1821: my $cid=$ENV{'request.course.id'};
1.59 matthew 1822: if (! exists($ENV{'form.sortby'})) {
1823: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1824: ['sortby']);
1825: }
1.54 matthew 1826: my $sortby = $ENV{'form.sortby'};
1.110 matthew 1827: if ($sortby !~ /^(username|domain|section|fullname|id|start|end)$/) {
1.54 matthew 1828: $sortby = 'username';
1829: }
1.56 matthew 1830: #
1.54 matthew 1831: my $action = "drop";
1832: $r->print(<<END);
1833: <input type="hidden" name="sortby" value="$sortby" />
1834: <input type="hidden" name="action" value="$action" />
1.50 matthew 1835: <input type="hidden" name="state" value="done" />
1.32 matthew 1836: <script>
1.51 matthew 1837: function checkAll(field) {
1.32 matthew 1838: for (i = 0; i < field.length; i++)
1839: field[i].checked = true ;
1840: }
1841:
1.51 matthew 1842: function uncheckAll(field) {
1.32 matthew 1843: for (i = 0; i < field.length; i++)
1844: field[i].checked = false ;
1845: }
1846: </script>
1847: <p>
1.26 matthew 1848: <input type="hidden" name="phase" value="four">
1.56 matthew 1849: END
1850:
1.110 matthew 1851: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
1852: 'dom' => "domain",
1853: 'sn' => "student name",
1854: 'sec' => "section",
1855: 'start' => "start date",
1856: 'end' => "end date",
1857: );
1.56 matthew 1858: if ($nosort) {
1859: $r->print(<<END);
1860: <table border=2>
1861: <tr>
1862: <th> </th>
1.94 sakharuk 1863: <th>$lt{'usrn'}</th>
1864: <th>$lt{'dom'}</th>
1.56 matthew 1865: <th>ID</th>
1.94 sakharuk 1866: <th>$lt{'sn'}</th>
1867: <th>$lt{'sec'}</th>
1.110 matthew 1868: <th>$lt{'start'}</th>
1869: <th>$lt{'end'}</th>
1.56 matthew 1870: </tr>
1871: END
1872:
1873: } else {
1874: $r->print(<<END);
1.26 matthew 1875: <table border=2>
1.54 matthew 1876: <tr><th> </th>
1877: <th>
1.94 sakharuk 1878: <a href="/adm/dropadd?action=$action&sortby=username">$lt{'usrn'}</a>
1.54 matthew 1879: </th><th>
1.94 sakharuk 1880: <a href="/adm/dropadd?action=$action&sortby=domain">$lt{'dom'}</a>
1.54 matthew 1881: </th><th>
1882: <a href="/adm/dropadd?action=$action&sortby=id">ID</a>
1883: </th><th>
1.94 sakharuk 1884: <a href="/adm/dropadd?action=$action&sortby=fullname">$lt{'sn'}</a>
1.54 matthew 1885: </th><th>
1.94 sakharuk 1886: <a href="/adm/dropadd?action=$action&sortby=section">$lt{'sec'}</a>
1.110 matthew 1887: </th><th>
1888: <a href="/adm/dropadd?action=$action&sortby=start">$lt{'start'}</a>
1889: </th><th>
1890: <a href="/adm/dropadd?action=$action&sortby=end">$lt{'end'}</a>
1.54 matthew 1891: </th>
1892: </tr>
1.26 matthew 1893: END
1.56 matthew 1894: }
1895: #
1896: # Sort the students
1897: my %index;
1898: my $i;
1899: foreach (@$keylist) {
1900: $index{$_} = $i++;
1901: }
1902: my $index = $index{$sortby};
1903: my $second = $index{'username'};
1904: my $third = $index{'domain'};
1.54 matthew 1905: my @Sorted_Students = sort {
1.56 matthew 1906: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
1907: ||
1908: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
1909: ||
1910: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
1911: } (keys(%$classlist));
1.54 matthew 1912: foreach my $student (@Sorted_Students) {
1.52 matthew 1913: my $error;
1.110 matthew 1914: my $sdata = $classlist->{$student};
1915: my $username = $sdata->[$index{'username'}];
1916: my $domain = $sdata->[$index{'domain'}];
1917: my $section = $sdata->[$index{'section'}];
1918: my $name = $sdata->[$index{'fullname'}];
1919: my $id = $sdata->[$index{'id'}];
1920: my $start = $sdata->[$index{'start'}];
1921: my $end = $sdata->[$index{'end'}];
1922: if (! defined($start) || $start == 0) {
1923: $start = &mt('none');
1924: } else {
1925: $start = &Apache::lonlocal::locallocaltime($start);
1926: }
1927: if (! defined($end) || $end == 0) {
1928: $end = &mt('none');
1929: } else {
1930: $end = &Apache::lonlocal::locallocaltime($end);
1931: }
1932: my $status = $sdata->[$index{'status'}];
1.51 matthew 1933: next if ($status ne 'Active');
1934: #
1935: $r->print(<<"END");
1.26 matthew 1936: <tr>
1.51 matthew 1937: <td><input type="checkbox" name="droplist" value="$student"></td>
1938: <td>$username</td>
1939: <td>$domain</td>
1940: <td>$id</td>
1941: <td>$name</td>
1942: <td>$section</td>
1.110 matthew 1943: <td>$start</td>
1944: <td>$end</td>
1.26 matthew 1945: </tr>
1946: END
1.25 matthew 1947: }
1948: $r->print('</table><br>');
1.111 matthew 1949: %lt=&Apache::lonlocal::texthash(
1.94 sakharuk 1950: 'dp' => "Drop Students",
1951: 'ca' => "check all",
1952: 'ua' => "uncheck all",
1953: );
1.32 matthew 1954: $r->print(<<"END");
1955: </p><p>
1.94 sakharuk 1956: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)">
1957: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)">
1958: <p><input type=submit value="$lt{'dp'}"></p>
1.32 matthew 1959: END
1.51 matthew 1960: return;
1.10 www 1961: }
1962:
1.48 matthew 1963: #
1964: # Print out the initial form to get the courselist file
1965: #
1966: sub print_first_courselist_upload_form {
1967: my $r=shift;
1.88 matthew 1968: my $str;
1969: $str = '<input type="hidden" name="phase" value="two">';
1970: $str .= '<input type="hidden" name="action" value="upload" />';
1971: $str .= '<input type="hidden" name="state" value="got_file" />';
1972: $str .= "<h3>".&mt('Upload a class list')."</h3>\n";
1973: $str .= &Apache::loncommon::upfile_select_html();
1974: $str .= "<p>\n";
1975: $str .= '<input type="submit" name="fileupload" value="'.
1976: &mt('Upload class list').'">'."\n";
1977: $str .= '<input type="checkbox" name="noFirstLine" /> '.
1978: &mt('Ignore First Line')."</p>\n";
1979: $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List",
1.92 sakharuk 1980: &mt("How do I create a class list from a spreadsheet")).
1.88 matthew 1981: "<br />\n";
1982: $str .= &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1.92 sakharuk 1983: &mt("How do I create a CSV file from a spreadsheet")).
1.88 matthew 1984: "<br />\n";
1985: $str .= "</body>\n</html>\n";
1986: $r->print($str);
1.48 matthew 1987: return;
1988: }
1989:
1.10 www 1990: # ================================================= Drop/Add from uploaded file
1991: sub upfile_drop_add {
1992: my $r=shift;
1.24 albertel 1993: &Apache::loncommon::load_tmp_file($r);
1994: my @studentdata=&Apache::loncommon::upfile_record_sep();
1.82 www 1995: if($ENV{'form.noFirstLine'}){shift(@studentdata);}
1.26 matthew 1996: my @keyfields = split(/\,/,$ENV{'form.keyfields'});
1997: my $cid = $ENV{'request.course.id'};
1.25 matthew 1998: my %fields=();
1.26 matthew 1999: for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
1.25 matthew 2000: if ($ENV{'form.upfile_associate'} eq 'reverse') {
2001: if ($ENV{'form.f'.$i} ne 'none') {
2002: $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
2003: }
2004: } else {
2005: $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
2006: }
2007: }
1.99 matthew 2008: #
2009: # Store the field choices away
2010: foreach my $field (qw/username names
2011: fname mname lname gen id sec ipwd email/) {
2012: $ENV{'form.'.$field.'_choice'}=$fields{$field};
2013: }
2014: &Apache::loncommon::store_course_settings('enrollment_upload',
2015: { 'username_choice' => 'scalar',
2016: 'names_choice' => 'scalar',
2017: 'fname_choice' => 'scalar',
2018: 'mname_choice' => 'scalar',
2019: 'lname_choice' => 'scalar',
2020: 'gen_choice' => 'scalar',
2021: 'id_choice' => 'scalar',
2022: 'sec_choice' => 'scalar',
2023: 'ipwd_choice' => 'scalar',
2024: 'email_choice' => 'scalar' });
2025:
1.26 matthew 2026: #
1.68 matthew 2027: my ($startdate,$enddate) = &get_dates_from_form();
2028: if ($ENV{'form.makedatesdefault'}) {
2029: $r->print(&make_dates_default($startdate,$enddate));
2030: }
1.31 matthew 2031: # Determine domain and desired host (home server)
1.25 matthew 2032: my $domain=$ENV{'form.lcdomain'};
1.31 matthew 2033: my $desiredhost = $ENV{'form.lcserver'};
2034: if (lc($desiredhost) eq 'default') {
2035: $desiredhost = undef;
2036: } else {
1.45 matthew 2037: my %home_servers = &Apache::loncommon::get_library_servers($domain);
1.31 matthew 2038: if (! exists($home_servers{$desiredhost})) {
1.88 matthew 2039: $r->print('<font color="#ff0000">'.&mt('Error').'</font>'.
2040: &mt('Invalid home server specified'));
2041: $r->print("</body>\n</html>\n");
1.31 matthew 2042: return;
2043: }
2044: }
1.26 matthew 2045: # Determine authentication mechanism
2046: my $amode = '';
2047: my $genpwd = '';
1.25 matthew 2048: if ($ENV{'form.login'} eq 'krb') {
1.47 albertel 2049: $amode='krb';
2050: $amode.=$ENV{'form.krbver'};
1.28 matthew 2051: $genpwd=$ENV{'form.krbarg'};
1.25 matthew 2052: } elsif ($ENV{'form.login'} eq 'int') {
2053: $amode='internal';
1.28 matthew 2054: if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
2055: $genpwd=$ENV{'form.intarg'};
1.25 matthew 2056: }
2057: } elsif ($ENV{'form.login'} eq 'loc') {
2058: $amode='localauth';
2059: if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
2060: $genpwd=$ENV{'form.locarg'};
1.79 matthew 2061: }
2062: }
2063: if ($amode =~ /^krb/) {
2064: if (! defined($genpwd) || $genpwd eq '') {
2065: $r->print('<font color="red" size="+1">'.
1.88 matthew 2066: &mt('Unable to enroll students').'</font> '.
2067: &mt('No Kerberos domain was specified.').'</p>');
1.79 matthew 2068: $amode = ''; # This causes the loop below to be skipped
1.25 matthew 2069: }
2070: }
2071: unless (($domain=~/\W/) || ($amode eq '')) {
1.26 matthew 2072: #######################################
2073: ## Enroll Students ##
2074: #######################################
1.88 matthew 2075: $r->print('<h3>'.&mt('Enrolling Students')."</h3>\n<p>\n");
1.25 matthew 2076: my $count=0;
2077: my $flushc=0;
2078: my %student=();
1.26 matthew 2079: # Get new classlist
1.25 matthew 2080: foreach (@studentdata) {
2081: my %entries=&Apache::loncommon::record_sep($_);
1.26 matthew 2082: # Determine student name
1.25 matthew 2083: unless (($entries{$fields{'username'}} eq '') ||
2084: (!defined($entries{$fields{'username'}}))) {
1.26 matthew 2085: my ($fname, $mname, $lname,$gen) = ('','','','');
1.25 matthew 2086: if (defined($fields{'names'})) {
1.26 matthew 2087: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
2088: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
1.25 matthew 2089: } else {
2090: if (defined($fields{'fname'})) {
2091: $fname=$entries{$fields{'fname'}};
2092: }
2093: if (defined($fields{'mname'})) {
2094: $mname=$entries{$fields{'mname'}};
2095: }
2096: if (defined($fields{'lname'})) {
2097: $lname=$entries{$fields{'lname'}};
2098: }
2099: if (defined($fields{'gen'})) {
2100: $gen=$entries{$fields{'gen'}};
2101: }
2102: }
2103: if ($entries{$fields{'username'}}=~/\W/) {
1.88 matthew 2104: $r->print('<br />'.
2105: &mt('<b>[_1]</b>: Unacceptable username for user [_2] [_3] [_4] [_5]',
2106: $entries{$fields{'username'}},$fname,$mname,$lname,$gen).
2107: '</b>');
1.25 matthew 2108: } else {
1.26 matthew 2109: # determine section number
1.25 matthew 2110: my $sec='';
2111: my $username=$entries{$fields{'username'}};
2112: if (defined($fields{'sec'})) {
2113: if (defined($entries{$fields{'sec'}})) {
2114: $sec=$entries{$fields{'sec'}};
2115: }
2116: }
1.80 matthew 2117: # remove non alphanumeric values from section
2118: $sec =~ s/\W//g;
1.26 matthew 2119: # determine student id number
1.25 matthew 2120: my $id='';
2121: if (defined($fields{'id'})) {
2122: if (defined($entries{$fields{'id'}})) {
2123: $id=$entries{$fields{'id'}};
2124: }
2125: $id=~tr/A-Z/a-z/;
2126: }
1.73 www 2127: # determine email address
2128: my $email='';
2129: if (defined($fields{'email'})) {
2130: if (defined($entries{$fields{'email'}})) {
2131: $email=$entries{$fields{'email'}};
2132: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
2133: }
2134: }
1.26 matthew 2135: # determine student password
1.25 matthew 2136: my $password='';
2137: if ($genpwd) {
2138: $password=$genpwd;
2139: } else {
2140: if (defined($fields{'ipwd'})) {
2141: if ($entries{$fields{'ipwd'}}) {
2142: $password=$entries{$fields{'ipwd'}};
2143: }
2144: }
2145: }
1.56 matthew 2146: # Clean up whitespace
2147: foreach (\$domain,\$username,\$id,\$fname,\$mname,
2148: \$lname,\$gen,\$sec) {
2149: $$_ =~ s/(\s+$|^\s+)//g;
2150: }
1.84 albertel 2151: if ($password || $ENV{'form.login'} eq 'loc') {
1.33 matthew 2152: &modifystudent($domain,$username,$cid,$sec,
2153: $desiredhost);
1.25 matthew 2154: my $reply=&Apache::lonnet::modifystudent
2155: ($domain,$username,$id,$amode,$password,
2156: $fname,$mname,$lname,$gen,$sec,$enddate,
1.73 www 2157: $startdate,$ENV{'form.forceid'},$desiredhost,
2158: $email);
1.26 matthew 2159: if ($reply ne 'ok') {
1.72 matthew 2160: $reply =~ s/^error://;
1.88 matthew 2161: $r->print('<br />'.
2162: &mt('<b>[_1]</b>: Unable to enroll: [_2]',$username,$reply));
1.10 www 2163: } else {
1.7 www 2164: $count++; $flushc++;
2165: $student{$username}=1;
1.6 www 2166: $r->print('. ');
1.7 www 2167: if ($flushc>15) {
2168: $r->rflush;
2169: $flushc=0;
2170: }
1.6 www 2171: }
1.25 matthew 2172: } else {
1.88 matthew 2173: $r->print('<br />'.
2174: &mt('<b>[_1]</b>: Unable to enroll. No password specified.',$username)
2175: );
1.25 matthew 2176: }
2177: }
1.26 matthew 2178: }
2179: } # end of foreach (@studentdata)
1.88 matthew 2180: $r->print("</p>\n<p>\n".&mt('Processed [_1] student(s).',$count).
2181: "</p>\n");
2182: $r->print("<p>\n".
2183: &mt('If active, the new role will be available when the '.
2184: 'students next log in to LON-CAPA.')."</p>\n");
1.26 matthew 2185: #####################################
2186: # Drop students #
2187: #####################################
1.25 matthew 2188: if ($ENV{'form.fullup'} eq 'yes') {
1.88 matthew 2189: $r->print('<h3>'.&mt('Dropping Students')."</h3>\n");
1.26 matthew 2190: # Get current classlist
1.56 matthew 2191: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
2192: if (! defined($classlist)) {
1.88 matthew 2193: $r->print(&mt('There are no students currently enrolled.').
2194: "\n");
1.56 matthew 2195: } else {
2196: # Remove the students we just added from the list of students.
1.25 matthew 2197: foreach (@studentdata) {
2198: my %entries=&Apache::loncommon::record_sep($_);
2199: unless (($entries{$fields{'username'}} eq '') ||
2200: (!defined($entries{$fields{'username'}}))) {
1.56 matthew 2201: delete($classlist->{$entries{$fields{'username'}}.
1.26 matthew 2202: ':'.$domain});
1.25 matthew 2203: }
2204: }
1.56 matthew 2205: # Print out list of dropped students.
2206: &show_drop_list($r,$classlist,$keylist,'nosort');
1.25 matthew 2207: }
2208: }
1.26 matthew 2209: } # end of unless
1.10 www 2210: }
2211:
1.11 www 2212: # ================================================================== Phase four
2213: sub drop_student_list {
2214: my $r=shift;
2215: my $count=0;
1.35 matthew 2216: my @droplist;
2217: if (ref($ENV{'form.droplist'})) {
2218: @droplist = @{$ENV{'form.droplist'}};
2219: } else {
2220: @droplist = ($ENV{'form.droplist'});
2221: }
2222: foreach (@droplist) {
1.26 matthew 2223: my ($uname,$udom)=split(/\:/,$_);
1.56 matthew 2224: # drop student
1.35 matthew 2225: my $result = &modifystudent($udom,$uname,$ENV{'request.course.id'});
1.37 matthew 2226: if ($result eq 'ok' || $result eq 'ok:') {
1.88 matthew 2227: $r->print(&mt('Dropped [_1]',$uname.'@'.$udom).'<br>');
1.59 matthew 2228: $count++;
1.35 matthew 2229: } else {
1.88 matthew 2230: $r->print(
2231: &mt('Error dropping [_1]:[_2]',$uname.'@'.$udom,$result).
1.35 matthew 2232: '<br />');
2233: }
1.20 harris41 2234: }
1.88 matthew 2235: $r->print('<p><b>'.&mt('Dropped [_1] student(s).',$count).'</b></p>');
2236: $r->print('<p>'.&mt('Re-enrollment will re-activate data.')) if ($count);
1.11 www 2237: }
2238:
1.50 matthew 2239: ###################################################################
2240: ###################################################################
2241:
2242: =pod
2243:
2244: =item &handler
2245:
2246: The typical handler you see in all these modules. Takes $r, the
2247: http request, as an argument.
2248:
2249: The response to the request is governed by two form variables
2250:
2251: form.action form.state response
2252: ---------------------------------------------------
2253: undefined undefined print main menu
2254: upload undefined print courselist upload menu
2255: upload got_file deal with uploaded file,
2256: print the upload managing menu
2257: upload enrolling enroll students based on upload
2258: drop undefined print the classlist ready to drop
2259: drop done drop the selected students
1.74 matthew 2260: enrollstudent undefined print student username domain form
2261: enrollstudent gotusername print single student enroll menu
1.50 matthew 2262: enrollstudent enrolling enroll student
2263: classlist undefined print html classlist
2264: classlist csv print csv classlist
2265: modifystudent undefined print classlist to select student to modify
2266: modifystudent selected print modify student menu
2267: modifystudent done make modifications to student record
2268:
2269: =cut
2270:
2271: ###################################################################
2272: ###################################################################
1.10 www 2273: sub handler {
1.26 matthew 2274: my $r=shift;
2275: if ($r->header_only) {
1.86 www 2276: &Apache::loncommon::content_type($r,'text/html');
1.26 matthew 2277: $r->send_http_header;
2278: return OK;
2279: }
1.48 matthew 2280: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.50 matthew 2281: ['action','state']);
1.102 matthew 2282:
2283: &Apache::lonhtmlcommon::clear_breadcrumbs();
2284: &Apache::lonhtmlcommon::add_breadcrumb
2285: ({href=>"/adm/dropadd",
2286: text=>"Enrollment Manager",
2287: faq=>9,bug=>'Instructor Interface',});
1.26 matthew 2288: # Needs to be in a course
1.121 matthew 2289: if (! ($ENV{'request.course.fn'})) {
2290: # Not in a course
1.50 matthew 2291: $ENV{'user.error.msg'}=
2292: "/adm/dropadd:cst:0:0:Cannot drop or add students";
2293: return HTTP_NOT_ACCEPTABLE;
2294: }
2295: #
1.121 matthew 2296: my $view_permission =
2297: &Apache::lonnet::allowed('vcl',$ENV{'request.course.id'});
2298: my $enrl_permission =
2299: &Apache::lonnet::allowed('cst',$ENV{'request.course.id'});
2300: if (! $view_permission && ! $enrl_permission) {
2301: $ENV{'user.error.msg'}=
2302: "/adm/dropadd:cst:0:0:Cannot drop or add students";
2303: return HTTP_NOT_ACCEPTABLE;
2304: }
2305: #
1.50 matthew 2306: # Only output the header information if they did not request csv format
2307: #
1.102 matthew 2308: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2309: ['state','action']);
1.103 matthew 2310: # Start page
2311: &Apache::loncommon::content_type($r,'text/html');
2312: $r->send_http_header;
2313: $r->print(&header());
1.50 matthew 2314: #
2315: # Main switch on form.action and form.state, as appropriate
2316: if (! exists($ENV{'form.action'})) {
1.102 matthew 2317: $r->print(&Apache::lonhtmlcommon::breadcrumbs
2318: (undef,'Enrollment Manager'));
1.121 matthew 2319: &print_main_menu($r,$enrl_permission,$view_permission);
2320: } elsif ($ENV{'form.action'} eq 'upload' && $enrl_permission) {
1.102 matthew 2321: &Apache::lonhtmlcommon::add_breadcrumb
2322: ({href=>'/adm/dropadd?action=upload&state=',
1.106 matthew 2323: text=>"Upload Classlist"});
1.102 matthew 2324: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.117 albertel 2325: (undef,'Upload Classlist','Course_Create_Class_List'));
1.50 matthew 2326: if (! exists($ENV{'form.state'})) {
2327: &print_first_courselist_upload_form($r);
2328: } elsif ($ENV{'form.state'} eq 'got_file') {
2329: &print_upload_manager_form($r);
2330: } elsif ($ENV{'form.state'} eq 'enrolling') {
1.26 matthew 2331: if ($ENV{'form.datatoken'}) {
2332: &upfile_drop_add($r);
1.50 matthew 2333: } else {
2334: # Hmmm, this is an error
1.26 matthew 2335: }
1.50 matthew 2336: } else {
2337: &print_first_courselist_upload_form($r);
1.26 matthew 2338: }
1.121 matthew 2339: } elsif ($ENV{'form.action'} eq 'drop' && $enrl_permission) {
1.102 matthew 2340: &Apache::lonhtmlcommon::add_breadcrumb
2341: ({href=>'/adm/dropadd?action=drop',
1.106 matthew 2342: text=>"Drop Students"});
1.102 matthew 2343: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.117 albertel 2344: (undef,'Drop Students','Course_Drop_Student'));
1.50 matthew 2345: if (! exists($ENV{'form.state'})) {
1.51 matthew 2346: &print_drop_menu($r);
1.50 matthew 2347: } elsif ($ENV{'form.state'} eq 'done') {
1.26 matthew 2348: &drop_student_list($r);
1.50 matthew 2349: } else {
1.55 matthew 2350: &print_drop_menu($r);
1.26 matthew 2351: }
1.121 matthew 2352: } elsif ($ENV{'form.action'} eq 'enrollstudent' && $enrl_permission) {
1.102 matthew 2353: &Apache::lonhtmlcommon::add_breadcrumb
2354: ({href=>'/adm/dropadd?action=enrollstudent',
1.106 matthew 2355: text=>"Enroll Student"});
1.102 matthew 2356: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.117 albertel 2357: (undef,'Enroll Student','Course_Add_Student'));
1.50 matthew 2358: if (! exists($ENV{'form.state'})) {
1.74 matthew 2359: &get_student_username_domain_form($r);
2360: } elsif ($ENV{'form.state'} eq 'gotusername') {
1.50 matthew 2361: &print_enroll_single_student_form($r);
2362: } elsif ($ENV{'form.state'} eq 'enrolling') {
1.26 matthew 2363: &enroll_single_student($r);
1.50 matthew 2364: } else {
1.74 matthew 2365: &get_student_username_domain_form($r);
1.26 matthew 2366: }
1.121 matthew 2367: } elsif ($ENV{'form.action'} eq 'classlist' && $view_permission) {
1.102 matthew 2368: &Apache::lonhtmlcommon::add_breadcrumb
2369: ({href=>'/adm/dropadd?action=classlist',
1.106 matthew 2370: text=>"View Classlist"});
1.102 matthew 2371: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.117 albertel 2372: (undef,'View Classlist','Course_View_Class_List'));
1.50 matthew 2373: if (! exists($ENV{'form.state'})) {
1.103 matthew 2374: &print_html_classlist($r,undef);
1.50 matthew 2375: } elsif ($ENV{'form.state'} eq 'csv') {
1.103 matthew 2376: &print_html_classlist($r,'csv');
1.60 matthew 2377: } elsif ($ENV{'form.state'} eq 'excel') {
1.103 matthew 2378: &print_html_classlist($r,'excel');
1.50 matthew 2379: } else {
1.103 matthew 2380: &print_html_classlist($r,undef);
1.50 matthew 2381: }
1.121 matthew 2382: } elsif ($ENV{'form.action'} eq 'modifystudent' && $enrl_permission) {
1.102 matthew 2383: &Apache::lonhtmlcommon::add_breadcrumb
2384: ({href=>'/adm/dropadd?action=modifystudent',
1.106 matthew 2385: text=>"Modify Student Data"});
1.102 matthew 2386: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.117 albertel 2387: (undef,'Modify Student Data','Course_Modify_Student_Data'));
1.50 matthew 2388: if (! exists($ENV{'form.state'})) {
2389: &print_html_classlist($r);
2390: } elsif ($ENV{'form.state'} eq 'selected') {
2391: &print_modify_student_form($r);
2392: } elsif ($ENV{'form.state'} eq 'done') {
2393: &modify_single_student($r);
2394: } else {
2395: &print_html_classlist($r);
2396: }
2397: } else {
2398: # We should not end up here, but I guess it is possible
2399: &Apache::lonnet::logthis("Undetermined state in londropadd.pm. ".
2400: "form.action = ".$ENV{'form.action'}.
2401: "Someone should fix this.");
1.102 matthew 2402: $r->print(&Apache::lonhtmlcommon::breadcrumbs
2403: (undef,'Enrollment Manager'));
1.121 matthew 2404: &print_main_menu($r,$enrl_permission,$view_permission);
1.50 matthew 2405: }
2406: #
2407: # Finish up
1.103 matthew 2408: $r->print('</form></body></html>');
1.26 matthew 2409: return OK;
1.1 www 2410: }
2411:
1.50 matthew 2412: ###################################################################
2413: ###################################################################
2414:
1.1 www 2415: 1;
2416: __END__
1.50 matthew 2417:
1.1 www 2418:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>