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