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