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