--- loncom/interface/Attic/londropadd.pm 2002/09/17 15:52:44 1.50
+++ loncom/interface/Attic/londropadd.pm 2003/06/20 18:34:52 1.67
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to drop and add students in courses
#
-# $Id: londropadd.pm,v 1.50 2002/09/17 15:52:44 matthew Exp $
+# $Id: londropadd.pm,v 1.67 2003/06/20 18:34:52 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -41,6 +41,7 @@ use Apache::lonnet();
use Apache::loncommon();
use Apache::lonhtmlcommon();
use Apache::Constants qw(:common :http REDIRECT);
+use Spreadsheet::WriteExcel;
###############################################################
###############################################################
@@ -92,7 +93,7 @@ sub modifystudent {
}
}
if ($result eq '') {
- $result eq 'Unable to find section for this student';
+ $result = 'Unable to find section for this student';
} else {
$result =~ s/(ok:)+/ok/g;
}
@@ -212,6 +213,7 @@ sub javascript_validations {
my %param = ( formname => 'studentform',
kerb_def_dom => $krbdefdom );
my $authheader = &Apache::loncommon::authform_header(%param);
+ my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
return (< Enrolling '.$ENV{'form.cuname'}." in domain ".
+ $r->print(' Enrolling '.$ENV{'form.cuname'}." \@ ".
$ENV{'form.lcdomain'}.' If active, the new role will be available ".
+ "when the student next logs in to LON-CAPA. ERROR '.
'Invalid login mode or password. '.
@@ -619,19 +634,40 @@ sub enroll_single_student {
sub print_enroll_single_student_form {
my $r=shift;
$r->print("Enrolling Student
');
- $r->print('Enroll One Student
");
- my ($krbdefdom) = $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
- $krbdefdom=~tr/a-z/A-Z/;
my $today = time;
my $halfyear = $today+15552000;
my $defdom=$r->dir_config('lonDefDomain');
- my $javascript_validations=&javascript_validations($krbdefdom);
# Set up authentication forms
- my %param = ( formname => 'document.studentform');
+ my ($krbdef,$krbdefdom) =
+ &Apache::loncommon::get_kerberos_defaults($defdom);
+ my $javascript_validations=&javascript_validations($krbdefdom);
+ my %param = ( formname => 'document.studentform',
+ kerb_def_dom => $krbdefdom,
+ kerb_def_auth => $krbdef
+ );
my $krbform = &Apache::loncommon::authform_kerberos(%param);
my $intform = &Apache::loncommon::authform_internal(%param);
my $locform = &Apache::loncommon::authform_local(%param);
# Set up domain selection form
my $domform = &domain_form($defdom);
+ my $starttime = 'now';
+ if (exists($ENV{'course.'.$ENV{'request.course.id'}.
+ '.default_enrollment_start_date'})) {
+ $starttime = $ENV{'course.'.$ENV{'request.course.id'}.
+ '.default_enrollment_start_date'};
+ }
+ my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
+ if (exists($ENV{'course.'.$ENV{'request.course.id'}.
+ '.default_enrollment_end_date'})) {
+ $endtime = $ENV{'course.'.$ENV{'request.course.id'}.
+ '.default_enrollment_end_date'};
+ }
+ my $startdateform = &Apache::lonhtmlcommon::date_setter('studentform',
+ 'startdate',
+ $starttime);
+ my $enddateform = &Apache::lonhtmlcommon::date_setter('studentform',
+ 'enddate',
+ $endtime);
# Print it all out
$r->print(<
Starting Date | $startdateform |
Ending Date | $enddateform |
@@ -726,179 +759,223 @@ END return; } -# =================================================== get the current classlist -sub get_current_classlist { - my ($domain,$identifier) = @_; - # domain is the domain the class is being run in - # identifier is the internal, unique identifier for the class. - my %currentlist=(); - my $now=time; - my %results=&Apache::lonnet::dump('classlist',$domain,$identifier); - my ($tmp) = keys(%results); - if ($tmp !~ /^(con_lost|error|no_such_host)/i) { - foreach my $student (keys(%results)) { - # Extract the start and end dates - my ($end,$start)=split(/\:/,$results{$student}); - # If the class isn't over, put it in the list - unless (($end) && ($now>$end)) { - $currentlist{$student}=1; - } - } - return (undef,%currentlist); - } else { - $tmp =~ s/^error://; - return ($tmp,undef); - } -} - # ========================================================= Menu Phase Two Drop -sub menu_phase_two_drop { +sub print_drop_menu { my $r=shift; $r->print("
ERROR:$error"); - } - } elsif (!defined(%currentlist)) { + my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist(); + if (! defined($classlist)) { $r->print("There are no students currently enrolled.\n"); - } else { - # Print out the available choices - &show_drop_list($r,%currentlist); + return; } + # Print out the available choices + &show_drop_list($r,$classlist,$keylist); + return; } # ============================================== view classlist sub print_html_classlist { my $r=shift; + if (! exists($ENV{'form.sortby'})) { + $ENV{'form.sortby'} = 'username'; + } + if ($ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) { + $ENV{'form.Status'} = 'Active'; + } + my $status_select = &Apache::lonhtmlcommon::StatusOptions + ($ENV{'form.Status'},'studentform'); $r->print(<
-Current Classlist -CSV format -
+Current Classlist + +END + if ($ENV{'form.action'} ne 'modifystudent') { + $r->print(<ERROR:$error"); - } - } elsif (!defined(%currentlist)) { + my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist(); + if (! defined($classlist)) { $r->print("There are no students currently enrolled.\n"); } else { # Print out the available choices if ($ENV{'form.action'} eq 'modifystudent') { - &show_class_list($r,'view','modify',%currentlist); + &show_class_list($r,'view','modify','modifystudent', + $ENV{'form.Status'},$classlist,$keylist); } else { - &show_class_list($r,'view','aboutme',%currentlist); + &show_class_list($r,'view','aboutme','classlist', + $ENV{'form.Status'},$classlist,$keylist); } } } # ============================================== view classlist -sub print_csv_classlist { +sub print_formatted_classlist { my $r=shift; + my $mode = shift; my $cid=$ENV{'request.course.id'}; - my ($error,%currentlist)=&get_current_classlist - ($ENV{'course.'.$cid.'.domain'},$ENV{'course.'.$cid.'.num'}); - if (defined($error)) { - if ($error =~ /^No such file or directory/) { - $r->print("There are no students currently enrolled.\n"); - } else { - $r->print("
ERROR:$error"); - } - } elsif (!defined(%currentlist)) { + my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist(); + if (! defined($classlist)) { $r->print("There are no students currently enrolled.\n"); } else { - &show_class_list($r,'csv','nolink',%currentlist); + &show_class_list($r,$mode,'nolink','csv', + $ENV{'form.Status'},$classlist,$keylist); } } # =================================================== Show student list to drop sub show_class_list { - my ($r,$mode,$linkto,%currentlist)=@_; + my ($r,$mode,$linkto,$action,$statusmode,$classlist,$keylist)=@_; my $cid=$ENV{'request.course.id'}; + # + # Variables for excel output + my ($excel_workbook, $excel_sheet, $excel_filename,$row); + # + my $sortby = $ENV{'form.sortby'}; + if ($sortby !~ /^(username|domain|section|fullname|id)$/) { + $sortby = 'username'; + } # Print out header if ($mode eq 'view') { if ($linkto eq 'aboutme') { - $r->print('Select a user name to view the users page.'); + $r->print('Select a user name to view the users personal page.'); } elsif ($linkto eq 'modify') { $r->print('Select a user name to modify the students information'); } $r->print(<
username | domain | ID | -student name | generation | section | ||||
---|---|---|---|---|---|---|---|---|---|
+ username + | + domain + | + ID + | + student name + | + section + | +|||||
'. - 'Internal error: unable to get environment '. - 'for '.$sname.' in domain '.$sdom.' | |||||||||
\n "); - if ($linkto eq 'nothing') { - $r->print($sname); - } elsif ($linkto eq 'aboutme') { - $r->print(&Apache::loncommon::aboutmewrapper($sname,$sname, - $sdom)); - } elsif ($linkto eq 'modify') { - $r->print(''.$sname."\n"); - } - $r->print(<<"END"); + $r->print('"'.join('","',("username","domain","ID","student name", + "section")).'"'."\n"); + } + } elsif ($mode eq 'excel') { + # Create the excel spreadsheet + $excel_filename = '/prtspool/'. + $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'. + time.'_'.rand(1000000000).'.xls'; + $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'. + $excel_filename); + $excel_workbook->set_tempdir('/home/httpd/perl/tmp'); + $excel_sheet = $excel_workbook->addworksheet('classlist'); + # + my $description = 'Classlist for '. + $ENV{'course.'.$ENV{'request.course.id'}.'.description'}; + $excel_sheet->write($row++,0,$description); + # + $excel_sheet->write($row++,0,["username","domain","ID", + "student name","section","status"]); + } + # + # Sort the students + my %index; + my $i; + foreach (@$keylist) { + $index{$_} = $i++; + } + my $index = $index{$sortby}; + my $second = $index{'username'}; + my $third = $index{'domain'}; + my @Sorted_Students = sort { + lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index]) + || + lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second]) + || + lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third]) + } (keys(%$classlist)); + foreach my $student (@Sorted_Students) { + my $username = $classlist->{$student}->[$index{'username'}]; + my $domain = $classlist->{$student}->[$index{'domain'}]; + my $section = $classlist->{$student}->[$index{'section'}]; + my $name = $classlist->{$student}->[$index{'fullname'}]; + my $id = $classlist->{$student}->[$index{'id'}]; + my $status = $classlist->{$student}->[$index{'status'}]; + next if (($statusmode ne 'Any') && ($status ne $statusmode)); + if ($mode eq 'view') { + $r->print(" | |||||||||
\n "); + if ($linkto eq 'nothing') { + $r->print($username); + } elsif ($linkto eq 'aboutme') { + $r->print(&Apache::loncommon::aboutmewrapper($username, + $username, + $domain)); + } elsif ($linkto eq 'modify') { + $r->print(''. + $username."\n"); + } + $r->print(<<"END"); | -$sdom | -$reply{$sname} | -$info{'lastname'}, $info{'firstname'} $info{'middlename'} | -$info{'generation'} | -$ssec | +$domain | +$id | +$name | +$section |
'. + 'Your Excel spreadsheet is ready for download.
'."\n"); + } } @@ -908,14 +985,14 @@ END sub print_modify_student_form { my $r = shift(); &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['sdom','sname']); - - my $sname = $ENV{'form.sname'}; - my $sdom = $ENV{'form.sdom'}; + ['sdom','sname']); + my $sname = $ENV{'form.sname'}; + my $sdom = $ENV{'form.sdom'}; + my $sortby = $ENV{'form.sortby'}; # determine the students name information my %info=&Apache::lonnet::get('environment', ['firstname','middlename', - 'lastname','generation'], + 'lastname','generation','id'], $sdom, $sname); my ($tmp) = keys(%info); if ($tmp =~ /^(con_lost|error|no_such_host)/i) { @@ -936,12 +1013,25 @@ sub print_modify_student_form { my $enddateform = &Apache::lonhtmlcommon::date_setter('studentform', 'enddate', $endtime); + # + if (! exists($ENV{'form.Status'}) || + $ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) { + $ENV{'form.Status'} = 'crap'; + } # Make sure student is enrolled in course $r->print(<@@ -955,6 +1045,12 @@ $info{'lastname'} $info{'generation'}, $
+Student ID: +
+ +Disable ID/Student Number Safeguard and Force Change of Conflicting IDs +(only do if you know what you are doing) +
Section:
First name | $firstname | |
Middle name | $middlename | |
Last name | $lastname | |
Generation | $generation |
Field | +Old Value | +New Value | +
---|---|---|
First name | +$old{'firstname'} | +$firstname | +
Middle name | +$old{'middlename'} | +$middlename | +
Last name | +$old{'lastname'} | +$lastname | +
Generation | +$old{'generation'} | +$generation | +
ID | +$old{'id'} | +$sid | +
Section | +$old{'section'} | +$section | +
Section | $section |
Start Time | $displayable_starttime |
End Time | $displayable_endtime |
END
- # send request(s) to modify data
- my $roleresults = 'refused';
- #my $roleresults = &Apache::lonnet::assignrole($sdom,$sname,
- # $courseid.'/'.$section,
- # 'st',
- # $endtime,$starttime);
- if ($roleresults =~/refused/) {
+ #
+ # Send request(s) to modify data (final undef is for 'desiredhost',
+ # which is a moot point because the student already has an account.
+ my $modify_section_results = &modifystudent($sdom,$slogin,
+ $ENV{'request.course.id'},
+ $section,undef);
+ if ($modify_section_results !~ /^ok/) {
+ $r->print("An error occured during the attempt to change the ".
+ "section for this student.
+
+
+
+Modify another students data
");
+ }
+ my $roleresults = &Apache::lonnet::modifystudent
+ ($sdom,$slogin,$sid,undef,undef,$firstname,$middlename,$lastname,
+ $generation,$section,$endtime,$starttime,$ENV{'form.forceid'});
+ if ($roleresults eq 'refused' ) {
$r->print("Your request to change the role information for this ".
- "student was refused.");
+ "student was refused. You do not appear to have ".
+ "sufficient authority to change student information.");
} elsif ($roleresults !~ /ok/) {
$r->print("An error occurred during the attempt to change the role".
- " information for this student. The error reported was ".
+ " information for this student.
".
+ "The error reported was ".
$roleresults);
+ &Apache::lonnet::logthis("londropadd:failed attempt to modify student".
+ " data for ".$slogin." \@ ".$sdom." by ".
+ $ENV{'user.name'}." \@ ".$ENV{'user.domain'}.
+ ":".$roleresults);
} else { # everything is okay!
- $r->print("Student role updated successfully.");
+ $r->print("Student information updated successfully.
".
+ "The student must log out and log in again to see ".
+ "these changes.");
}
- #
$r->print(<