--- loncom/interface/Attic/londropadd.pm 2002/05/03 20:38:13 1.40
+++ loncom/interface/Attic/londropadd.pm 2003/07/14 15:25:59 1.74
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to drop and add students in courses
#
-# $Id: londropadd.pm,v 1.40 2002/05/03 20:38:13 matthew Exp $
+# $Id: londropadd.pm,v 1.74 2003/07/14 15:25:59 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -31,49 +31,36 @@
#
# (TeX Content Handler
#
-# YEAR=2000
-# 05/29/00,05/30,10/11 Gerd Kortemeyer)
-#
-# 10/11,10/12,10/16 Gerd Kortemeyer)
-#
-# 11/20,11/21,11/22,11/23,11/24,11/25,11/27,11/28,
-# 12/08,12/12 Gerd Kortemeyer)
-#
-# 12/26,12/27,12/28,
-# YEAR=2001
-# 01/01/01,01/15,02/10,02/13,02/14,02/22 Gerd Kortemeyer
-# 8/6 Scott Harrison
-# Guy Albertelli
-# 9/25 Gerd Kortemeyer
-# 12/19 Guy Albertelli
-# YEAR=2002
-# 1/4 Gerd Kortemeyer
+###############################################################
+###############################################################
package Apache::londropadd;
use strict;
use Apache::lonnet();
use Apache::loncommon();
+use Apache::lonhtmlcommon();
use Apache::Constants qw(:common :http REDIRECT);
+use Spreadsheet::WriteExcel;
-# ================================================================ Print header
-
+###############################################################
+###############################################################
sub header {
+ my $bodytag=&Apache::loncommon::bodytag('Enrollment Manager');
return(<
-
$ENV{'course.'.$ENV{'request.course.id'}.'.description'}
-Enrollment Manager
+$bodytag
+ + Enroll a single student + +
+ + Modify student data + +
+ + View Classlist + +
+ + Drop Students + +
+END } -sub phase_two_header { +############################################################### +############################################################### +sub print_upload_manager_header { my ($r,$datatoken,$distotal,$krbdefdom)=@_; my $javascript; + if (! exists($ENV{'form.upfile_associate'})) { + $ENV{'form.upfile_associate'} = 'forward'; + } + if ($ENV{'form.associate'} eq 'Reverse Association') { + if ( $ENV{'form.upfile_associate'} ne 'reverse' ) { + $ENV{'form.upfile_associate'} = 'reverse'; + } else { + $ENV{'form.upfile_associate'} = 'forward'; + } + } if ($ENV{'form.upfile_associate'} eq 'reverse') { - $javascript=&phase_two_javascript_reverse_associate(); + $javascript=&upload_manager_javascript_reverse_associate(); } else { - $javascript=&phase_two_javascript_forward_associate(); + $javascript=&upload_manager_javascript_forward_associate(); } my $javascript_validations=&javascript_validations($krbdefdom); $r->print(<
+
+$date_table +
@@ -463,12 +498,12 @@ LON-CAPA domain: $domform
Disable ID/Student Number Safeguard and Force Change of Conflicting IDs (only do if you know what you are doing)
-Note: for large courses, this operation might be time consuming.
+Note: for large courses, this operation may be time consuming.
ENDPICK
}
# ======================================================= Menu Phase Two Upload
-sub menu_phase_two_upload {
+sub print_upload_manager_form {
my $r=shift;
my $datatoken;
@@ -481,21 +516,25 @@ sub menu_phase_two_upload {
my @records=&Apache::loncommon::upfile_record_sep();
my $total=$#records;
my $distotal=$total+1;
- $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
- my $krbdefdom=$1;
- $krbdefdom=~tr/a-z/A-Z/;
my $today=time;
my $halfyear=$today+15552000;
my $defdom=$r->dir_config('lonDefDomain');
- &phase_two_header($r,$datatoken,$distotal,$krbdefdom);
+ my ($krbdef,$krbdefdom) =
+ &Apache::loncommon::get_kerberos_defaults($defdom);
+ &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom);
my $i;
my $keyfields;
if ($total>=0) {
- my @d=(['username','Username'],['names','Last Name, First Names'],
- ['fname','First Name'],['mname','Middle Names/Initials'],
- ['lname','Last Name'],['gen','Generation'],
- ['id','ID/Student Number'],['sec','Group/Section'],
- ['ipwd','Initial Password']);
+ my @d=(['username','Username'],
+ ['names','Last Name, First Names'],
+ ['fname','First Name'],
+ ['mname','Middle Names/Initials'],
+ ['lname','Last Name'],
+ ['gen','Generation'],
+ ['id','ID/Student Number'],
+ ['sec','Group/Section'],
+ ['ipwd','Initial Password'],
+ ['email','EMail Address']);
if ($ENV{'form.upfile_associate'} eq 'reverse') {
&Apache::loncommon::csv_print_samples($r,\@records);
$i=&Apache::loncommon::csv_print_select_table($r,\@records,\@d);
@@ -508,14 +547,24 @@ sub menu_phase_two_upload {
$keyfields=join(',',sort(keys(%sone)));
}
}
- &phase_two_end($r,$i,$keyfields,$defdom,$today,$halfyear);
+ &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear);
}
# ======================================================= Enroll single student
sub enroll_single_student {
my $r=shift;
+ #
+ # We do the dates first because the action of making them the defaul
+ # in the course is entirely seperate from the action of enrolling the
+ # student. Also, a failure in setting the dates as default is not fatal
+ # to the process of enrolling / modifying a student.
+ my ($startdate,$enddate) = &get_dates_from_form();
+ if ($ENV{'form.makedatesdefault'}) {
+ $r->print(&make_dates_default($startdate,$enddate));
+ }
+
$r->print('
Enrolling '.$ENV{'form.cuname'}." in domain ". + $r->print('
Enrolling '.$ENV{'form.cuname'}." \@ ". $ENV{'form.lcdomain'}.'
'); if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&& ($ENV{'form.lcdomain'})&&($ENV{'form.lcdomain'}!~/\W/)) { @@ -525,7 +574,7 @@ sub enroll_single_student { if (lc($desiredhost) eq 'default') { $desiredhost = undef; } else { - my %home_servers = &Apache::loncommon::get_home_servers($domain); + my %home_servers =&Apache::loncommon::get_library_servers($domain); if (! exists($home_servers{$desiredhost})) { $r->print('Error:'. 'Invalid home server specified'); @@ -537,7 +586,8 @@ sub enroll_single_student { my $amode=''; my $genpwd=''; if ($ENV{'form.login'} eq 'krb') { - $amode='krb4'; + $amode='krb'; + $amode.=$ENV{'form.krbver'}; $genpwd=$ENV{'form.krbarg'}; } elsif ($ENV{'form.login'} eq 'int') { $amode='internal'; @@ -550,17 +600,25 @@ sub enroll_single_student { my $home = &Apache::lonnet::homeserver($ENV{'form.cuname'}, $ENV{'form.lcdomain'}); if ((($amode) && ($genpwd)) || ($home ne 'no_host')) { + # Clean out any old roles the student has in this class. &modifystudent($ENV{'form.lcdomain'},$ENV{'form.cuname'}, $ENV{'request.course.id'},$ENV{'form.csec'}, $desiredhost); - $r->print(&Apache::lonnet::modifystudent( - $ENV{'form.lcdomain'},$ENV{'form.cuname'}, - $ENV{'form.cstid'},$amode,$genpwd, - $ENV{'form.cfirst'},$ENV{'form.cmiddle'}, - $ENV{'form.clast'},$ENV{'form.cgen'}, - $ENV{'form.csec'},$ENV{'form.enddate'}, - $ENV{'form.startdate'},$ENV{'form.forceid'}, - $desiredhost)); + my $login_result = &Apache::lonnet::modifystudent + ($ENV{'form.lcdomain'},$ENV{'form.cuname'}, + $ENV{'form.cstid'},$amode,$genpwd, + $ENV{'form.cfirst'},$ENV{'form.cmiddle'}, + $ENV{'form.clast'},$ENV{'form.cgen'}, + $ENV{'form.csec'},$enddate, + $startdate,$ENV{'form.forceid'}, + $desiredhost); + if ($login_result =~ /^ok/) { + $r->print($login_result); + $r->print("If active, the new role will be available ". + "when the student next logs in to LON-CAPA.
"); + } else { + $r->print("unable to enroll: ".$login_result); + } } else { $r->print('ERROR '.
'Invalid login mode or password. '.
@@ -571,25 +629,211 @@ sub enroll_single_student {
}
}
-# ======================================================= Menu Phase Two Enroll
-sub menu_phase_two_enroll {
+sub setup_date_selectors {
+ my ($starttime,$endtime) = @_;
+ if (! defined($starttime)) {
+ $starttime = time;
+ if (exists($ENV{'course.'.$ENV{'request.course.id'}.
+ '.default_enrollment_start_date'})) {
+ $starttime = $ENV{'course.'.$ENV{'request.course.id'}.
+ '.default_enrollment_start_date'};
+ }
+ }
+ if (! defined($endtime)) {
+ $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);
+ return ($startdateform,$enddateform);
+}
+
+sub get_dates_from_form {
+ my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
+ my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
+ if ($ENV{'form.no_end_date'}) {
+ $enddate = 0;
+ }
+ return ($startdate,$enddate);
+}
+
+sub date_setting_table {
+ my ($starttime,$endtime) = @_;
+ my ($startform,$endform)=&setup_date_selectors($starttime,$endtime);
+ my $dateDefault = '
+$krbform
+
+$intform
+
+$locform
+ ID/Student Number: Group/Section: Username: Domain: $domform Note: login settings below will not take effect if the user already exists
-
-$krbform
-
-$intform
-
-$locform
-
-
+
+$user_data_html
+
+ Group/Section:
+
+$date_table
+
+ID/Student Number:
+
Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
-(only do if you know what you are doing)
-
+
+Current Classlist
+
+END
+ if ($ENV{'form.action'} ne 'modifystudent') {
+ $r->print(<
'.
+ 'Your Excel spreadsheet is ready for download. '.
+ 'Unable to retrieve environment data for '.$sname.
+ 'in domain '.$sdom.' '.
+ 'Please contact your LON-CAPA administrator '.
+ 'regarding this situation.\n";
+ $result .= '
\n";
+ return $result;
+}
+
+sub make_dates_default {
+ my ($startdate,$enddate) = @_;
+ my $result = '';
+ my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
+ my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
+ my $put_result = &Apache::lonnet::put('environment',
+ {'default_enrollment_start_date'=>$startdate,
+ 'default_enrollment_end_date' =>$enddate},$dom,$crs);
+ if ($put_result eq 'ok') {
+ $result .= "Set default start and end dates for course \n";
+ $result .= 'Starting Date '.
+ ''.$startform.' '.
+ ''.$dateDefault.' '." \n";
+ $result .= "Ending Date '.
+ ''.$endform.' '.
+ ''.$perpetual.' '."
";
+ #
+ # Refresh the course environment
+ &Apache::lonnet::coursedescription($ENV{'request.course.id'});
+ } else {
+ $result .= "Unable to set default dates for course:".$put_result.
+ '
';
+ }
+ return $result;
+}
+
+##
+## Single student enrollment routines (some of them)
+##
+sub get_student_username_domain_form {
+ my $r = shift;
+ my $domform = &Apache::loncommon::select_dom_form
+ ($r->dir_config('lonDefDomain'),'cudomain',0);
+ $r->print(<Enroll One Student
+
+
+END
+ return;
+}
+
+sub print_enroll_single_student_form {
my $r=shift;
$r->print("
+Username:
+
+Domain:
+ $domform
+
+
+
+ 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 $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);
- # Print it all out
- $r->print(<
+
+
+First Name:
+
+Middle Name:
+
+Last Name:
+
+Generation:
+
+Home Server:
+ $homeserver_form Password
+Please select an authentication mechanism
+
+
+
+END
+ }
+ my $date_table = &date_setting_table();
+ # Print it all out
+ $r->print(<
+First Name:
+
+
+
+Middle Name:
+
+
+
+Last Name:
+
+
+
+Generation:
+
+
+ Personal Data
-First Name:
-Middle Name:
-Last Name:
-Generation:
-
-Login Data
-Starting and Ending Dates
-
-
-
-
-
-Course Data
+
+ID/Student Number
+
-
+(only do if you know what you are doing)
+Drop Students
");
+ my $cid=$ENV{'request.course.id'};
+ my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
+ if (! defined($classlist)) {
+ $r->print("There are no students currently enrolled.\n");
+ return;
}
+ # Print out the available choices
+ &show_drop_list($r,$classlist,$keylist);
+ return;
}
-# ========================================================= Menu Phase Two Drop
-sub menu_phase_two_drop {
+# ============================================== view classlist
+sub print_html_classlist {
my $r=shift;
- $r->print("Drop Students
");
+ 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(<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);
+ if ($ENV{'form.action'} eq 'modifystudent') {
+ &show_class_list($r,'view','modify','modifystudent',
+ $ENV{'form.Status'},$classlist,$keylist);
+ } else {
+ &show_class_list($r,'view','aboutme','classlist',
+ $ENV{'form.Status'},$classlist,$keylist);
+ }
}
}
# ============================================== view classlist
-sub menu_phase_two_view {
+sub print_formatted_classlist {
my $r=shift;
- $r->print("Current Classlist
");
+ 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 {
- # Print out the available choices
- &show_class_list($r,%currentlist);
+ &show_class_list($r,$mode,'nolink','csv',
+ $ENV{'form.Status'},$classlist,$keylist);
}
}
# =================================================== Show student list to drop
sub show_class_list {
- my ($r,%currentlist)=@_;
+ my ($r,$mode,$linkto,$action,$statusmode,$classlist,$keylist)=@_;
my $cid=$ENV{'request.course.id'};
- $r->print(<
-
+username domain ID
- student name generation section
END
- foreach (sort keys %currentlist) {
- my ($sname,$sdom)=split(/\:/,$_);
- my %reply=&Apache::lonnet::idrget($sdom,$sname);
- my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid);
- my %info=&Apache::lonnet::get('environment',
- ['firstname','middlename',
- 'lastname','generation'],
- $sdom, $sname);
- my ($tmp) = keys(%info);
- if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
- $r->print('
+ username
+
+ domain
+
+ ID
+
+ student name
+
+ section
+
+ ');
+ } elsif ($mode eq 'csv') {
+ if($statusmode eq 'Expired') {
+ $r->print('"Students with expired roles"');
+ }
+ if ($statusmode eq 'Any') {
+ $r->print('"'.join('","',("username","domain","ID","student name",
+ "section","status")).'"'."\n");
} else {
+ $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("'.
- 'Internal error: unable to get environment '.
- 'for '.$sname.' in domain '.$sdom.' \n
+END
+ } elsif ($mode eq 'csv') {
+ # no need to bother with $linkto
+ my @line = ();
+ foreach ($username,$domain,$id,$name,$section) {
+ push @line,&Apache::loncommon::csv_translate($_);
+ }
+ if ($statusmode eq 'Any') {
+ push @line,&Apache::loncommon::csv_translate($status);
+ }
+ my $tmp = $";
+ $" = '","';
+ $r->print("\"@line\"\n");
+ $" = $tmp;
+ } elsif ($mode eq 'excel') {
+ $excel_sheet->write($row++,0,[$username,$domain,$id,
+ $name,$section,$status]);
+ }
+ }
+ 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");
+
+ $domain
+ $id
+ $name
+ $section
+
');
+ } elsif ($mode eq 'excel') {
+ $excel_workbook->close();
+ $r->print('