--- loncom/interface/Attic/londropadd.pm 2004/02/20 19:44:59 1.102
+++ loncom/interface/Attic/londropadd.pm 2005/04/19 03:58:23 1.129
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to drop and add students in courses
#
-# $Id: londropadd.pm,v 1.102 2004/02/20 19:44:59 matthew Exp $
+# $Id: londropadd.pm,v 1.129 2005/04/19 03:58:23 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -32,20 +32,22 @@
package Apache::londropadd;
use strict;
-use Apache::lonnet();
+use Apache::lonnet;
use Apache::loncommon();
use Apache::lonhtmlcommon();
use Apache::Constants qw(:common :http REDIRECT);
use Spreadsheet::WriteExcel;
+use Apache::lonstathelpers();
use Apache::lonlocal;
###############################################################
###############################################################
sub header {
+ my $html=&Apache::lonxml::xmlbegin();
my $bodytag=&Apache::loncommon::bodytag('Enrollment Manager');
my $title = &mt('LON-CAPA Enrollment Manager');
return(< ';
+ $menu_html.='';
+ if (exists($menu_item->{'url'})) {
+ $menu_html.=qq{};
+ } else {
+ $menu_html.=
+ qq{};
+ }
+ $menu_html.= &mt($menu_item->{'text'}).'';
+ if (exists($menu_item->{'help'})) {
+ $menu_html.=
+ &Apache::loncommon::help_open_topic($menu_item->{'help'});
+ }
+ $menu_html.='
- - $Text{'enrollone'} - $help{'Course_Add_Student'} -
- - $Text{'modify'} - $help{'Course_Modify_Student_Data'} -
- - $Text{'view'} - $help{'Course_View_Class_List'} -
- - $Text{'drop'} - $help{'Course_Drop_Student'} -
- - $Text{'populate'} - -END + $r->print($menu_html); + return; } ############################################################### @@ -189,17 +205,17 @@ sub print_upload_manager_header { my ($r,$datatoken,$distotal,$krbdefdom)=@_; my $javascript; # - if (! exists($ENV{'form.upfile_associate'})) { - $ENV{'form.upfile_associate'} = 'forward'; + 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'; + 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'; + $env{'form.upfile_associate'} = 'forward'; } } - if ($ENV{'form.upfile_associate'} eq 'reverse') { + if ($env{'form.upfile_associate'} eq 'reverse') { $javascript=&upload_manager_javascript_reverse_associate(); } else { $javascript=&upload_manager_javascript_forward_associate(); @@ -207,8 +223,8 @@ sub print_upload_manager_header { # # Deal with restored settings my $password_choice = ''; - if (exists($ENV{'form.ipwd_choice'}) && - $ENV{'form.ipwd_choice'} ne '') { + if (exists($env{'form.ipwd_choice'}) && + $env{'form.ipwd_choice'} ne '') { # If a column was specified for password, assume it is for an # internal password. This is a bug waiting to be filed (could be # local or krb auth instead of internal) but I do not have the @@ -218,7 +234,7 @@ sub print_upload_manager_header { # my $javascript_validations=&javascript_validations('auth',$krbdefdom, $password_choice); - my $checked=(($ENV{'form.noFirstLine'})?' checked="1"':''); + my $checked=(($env{'form.noFirstLine'})?' checked="1"':''); $r->print('
'.&mt('Enrolling').' '.$ENV{'form.cuname'}." \@ ". - $ENV{'form.lcdomain'}.'
'); - if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&& - ($ENV{'form.lcdomain'})&&($ENV{'form.lcdomain'}!~/\W/)) { + $r->print(''.&mt('Enrolling').' '.$env{'form.cuname'}." \@ ". + $env{'form.lcdomain'}.'
'); + if (($env{'form.cuname'})&&($env{'form.cuname'}!~/\W/)&& + ($env{'form.lcdomain'})&&($env{'form.lcdomain'}!~/\W/)) { # Deal with home server selection - my $domain=$ENV{'form.lcdomain'}; - my $desiredhost = $ENV{'form.lcserver'}; + my $domain=$env{'form.lcdomain'}; + my $desiredhost = $env{'form.lcserver'}; if (lc($desiredhost) eq 'default') { $desiredhost = undef; } else { @@ -729,33 +745,33 @@ sub enroll_single_student { # End of home server selection logic my $amode=''; my $genpwd=''; - if ($ENV{'form.login'} eq 'krb') { + if ($env{'form.login'} eq 'krb') { $amode='krb'; - $amode.=$ENV{'form.krbver'}; - $genpwd=$ENV{'form.krbarg'}; - } elsif ($ENV{'form.login'} eq 'int') { + $amode.=$env{'form.krbver'}; + $genpwd=$env{'form.krbarg'}; + } elsif ($env{'form.login'} eq 'int') { $amode='internal'; - $genpwd=$ENV{'form.intarg'}; - } elsif ($ENV{'form.login'} eq 'loc') { + $genpwd=$env{'form.intarg'}; + } elsif ($env{'form.login'} eq 'loc') { $amode='localauth'; - $genpwd=$ENV{'form.locarg'}; + $genpwd=$env{'form.locarg'}; if (!$genpwd) { $genpwd=" "; } } - my $home = &Apache::lonnet::homeserver($ENV{'form.cuname'}, - $ENV{'form.lcdomain'}); + 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'}, + &modifystudent($env{'form.lcdomain'},$env{'form.cuname'}, + $env{'request.course.id'},$env{'form.csec'}, $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); + ($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,$env{'form.emailaddress'}); if ($login_result =~ /^ok/) { $r->print($login_result); $r->print("".&mt('If active, the new role will be available when the student next logs in to LON-CAPA.')."
"); @@ -769,7 +785,7 @@ sub enroll_single_student { } else { $r->print(&mt('Invalid login mode or password.').' '); } - $r->print(''.&mt('Unable to enroll').' '.$ENV{'form.cuname'}.'.'); + $r->print(''.&mt('Unable to enroll').' '.$env{'form.cuname'}.'.'); } } else { $r->print(&mt('Invalid username or domain')); @@ -780,10 +796,10 @@ sub setup_date_selectors { my ($starttime,$endtime,$mode) = @_; if (! defined($starttime)) { $starttime = time; - unless ($mode eq 'createcourse') { - if (exists($ENV{'course.'.$ENV{'request.course.id'}. + unless ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') { + if (exists($env{'course.'.$env{'request.course.id'}. '.default_enrollment_start_date'})) { - $starttime = $ENV{'course.'.$ENV{'request.course.id'}. + $starttime = $env{'course.'.$env{'request.course.id'}. '.default_enrollment_start_date'}; } } @@ -791,9 +807,9 @@ sub setup_date_selectors { if (! defined($endtime)) { $endtime = time+(6*30*24*60*60); # 6 months from now, approx unless ($mode eq 'createcourse') { - if (exists($ENV{'course.'.$ENV{'request.course.id'}. + if (exists($env{'course.'.$env{'request.course.id'}. '.default_enrollment_end_date'})) { - $endtime = $ENV{'course.'.$ENV{'request.course.id'}. + $endtime = $env{'course.'.$env{'request.course.id'}. '.default_enrollment_end_date'}; } } @@ -804,12 +820,20 @@ sub setup_date_selectors { my $enddateform = &Apache::lonhtmlcommon::date_setter('studentform', 'enddate', $endtime); - if ($mode eq 'createcourse') { + if ($mode eq 'create_enrolldates') { $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs', - 'startdate', + 'startenroll', $starttime); $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs', - 'enddate', + 'endenroll', + $endtime); + } + if ($mode eq 'create_defaultdates') { + $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs', + 'startaccess', + $starttime); + $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs', + 'endaccess', $endtime); } return ($startdateform,$enddateform); @@ -818,7 +842,7 @@ sub setup_date_selectors { 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'}) { + if ($env{'form.no_end_date'}) { $enddate = 0; } return ($startdate,$enddate); @@ -830,7 +854,7 @@ sub date_setting_table { my $dateDefault = ''.&mt('Starting Date').' | '. @@ -853,8 +880,8 @@ sub date_setting_table { 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 $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); @@ -862,7 +889,7 @@ sub make_dates_default { $result .= "Set default start and end dates for course
'.$_.' | ');
- foreach (split(/\,/,$coursepersonnel{$_})) {
- my ($puname,$pudom)=split(/\:/,$_);
+ #
+ if (! defined($env{'form.output'}) ||
+ $env{'form.output'} !~ /^(csv|excel|html)$/ ) {
+ $env{'form.output'} = 'html';
+ }
+ #
+ $r->print('
-$CCL
-
-END
- if ($ENV{'form.action'} ne 'modifystudent') {
- my %lt=&Apache::lonlocal::texthash(
- 'ef' => "Excel format",
- 'ss' => "Student Status",
- );
- $r->print(< \n");
+ if ($env{'form.action'} ne 'modifystudent') {
+ my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
+ 'excel' => "Excel",
+ 'html' => 'HTML');
+ my $output_selector = '';
+ $r->print(&mt('Output Format: [_1]',$output_selector).(' 'x3));
}
- $r->print($status_select." '.&mt('Current Class List').''); my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist(); if (! defined($classlist)) { $r->print(&mt('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','modifystudent', - $ENV{'form.Status'},$classlist,$keylist); + if ($env{'form.action'} eq 'modifystudent') { + &show_class_list($r,'view','modify', + $env{'form.Status'},$classlist,$keylist); } else { - &show_class_list($r,'view','aboutme','classlist', - $ENV{'form.Status'},$classlist,$keylist); + &show_class_list($r,$env{'form.output'},'aboutme', + $env{'form.Status'},$classlist,$keylist); } } } -# ============================================== view classlist -sub print_formatted_classlist { - my $r=shift; - my $mode = shift; - my $cid=$ENV{'request.course.id'}; - my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist(); - if (! defined($classlist)) { - $r->print(&mt('There are no students currently enrolled.')."\n"); - } else { - &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,$action,$statusmode,$classlist,$keylist)=@_; - my $cid=$ENV{'request.course.id'}; + my ($r,$mode,$linkto,$statusmode,$classlist,$keylist)=@_; + my $cid=$env{'request.course.id'}; # # Variables for excel output - my ($excel_workbook, $excel_sheet, $excel_filename,$row); + my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format); # - my $sortby = $ENV{'form.sortby'}; - if ($sortby !~ /^(username|domain|section|fullname|id)$/) { + # Variables for csv output + my ($CSVfile,$CSVfilename); + # + my $sortby = $env{'form.sortby'}; + if ($sortby !~ /^(username|domain|section|fullname|id|start|end|type)$/) { $sortby = 'username'; } # Print out header - if ($mode eq 'view') { + unless ($mode eq 'autoenroll') { + $r->print(<
$cellentry | \n ");
+ } else {
+ $r->print(" | ".(++$studentcount)." | \n ");
+ }
if ($linkto eq 'nothing') {
$r->print($username);
} elsif ($linkto eq 'aboutme') {
@@ -1302,33 +1430,65 @@ END
| $id |
$name |
$section |
-$start |
+ $end |
+
END
} elsif ($mode eq 'csv') {
+ next if (! defined($CSVfile));
# no need to bother with $linkto
+ if (! defined($start) || $start == 0) {
+ $start = &mt('none');
+ } else {
+ $start = &Apache::lonlocal::locallocaltime($start);
+ }
+ if (! defined($end) || $end == 0) {
+ $end = &mt('none');
+ } else {
+ $end = &Apache::lonlocal::locallocaltime($end);
+ }
my @line = ();
- foreach ($username,$domain,$id,$name,$section) {
+ foreach ($username,$domain,$id,$name,$section,$start,$end) {
push @line,&Apache::loncommon::csv_translate($_);
}
if ($statusmode eq 'Any') {
push @line,&Apache::loncommon::csv_translate($status);
}
- my $tmp = $";
- $" = '","';
- $r->print("\"@line\"\n");
- $" = $tmp;
+ print $CSVfile '"'.join('","',@line).'"'."\n";
} elsif ($mode eq 'excel') {
- $excel_sheet->write($row++,0,[$username,$domain,$id,
- $name,$section,$status]);
+ $excel_sheet->write($row,0,[$username,$domain,$id,
+ $name,$section]);
+ my $col = 5;
+ foreach my $time ($start,$end) {
+ if (defined($time) && $time != 0) {
+ $excel_sheet->write($row,$col++,
+ &Apache::lonstathelpers::calc_serial($time),
+ $format->{'date'});
+ } else {
+ $excel_sheet->write($row,$col++,'none');
+ }
+ }
+ $excel_sheet->write($row,$col++,$status);
+ $row++;
}
}
- if ($mode eq 'view') {
+ if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
$r->print(''); } elsif ($mode eq 'excel') { $excel_workbook->close(); $r->print(' '. &mt('Your Excel spreadsheet').' '.&mt('is ready for download').'. '."\n"); + } elsif ($mode eq 'csv') { + close($CSVfile); + $r->print(''. + &mt('Your CSV file').' is ready for download.'. + "\n"); + $r->rflush(); + } + if ($mode eq 'autoenroll') { + return ($studentcount,$autocount,$manualcount,$lockcount,$unlockcount); } + return; } @@ -1339,9 +1499,9 @@ 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'}; - my $sortby = $ENV{'form.sortby'}; + 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', @@ -1387,9 +1547,9 @@ sub print_modify_student_form { } my $date_table = &date_setting_table($starttime,$endtime); # - if (! exists($ENV{'form.Status'}) || - $ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) { - $ENV{'form.Status'} = 'crap'; + if (! exists($env{'form.Status'}) || + $env{'form.Status'} !~ /^(Any|Expired|Active)$/) { + $env{'form.Status'} = 'crap'; } # Make sure student is enrolled in course my %lt=&Apache::lonlocal::texthash( @@ -1416,7 +1576,7 @@ $lt{'odcc'} - +$lt{'mef'} $info{'firstname'} $info{'middlename'} $info{'lastname'} $info{'generation'}, $sname\@$sdom
@@ -1452,21 +1612,21 @@ sub modify_single_student {
my $r = shift;
#
# Remove non alphanumeric values from the section
- $ENV{'form.section'} =~ s/\W//g;
+ $env{'form.section'} =~ s/\W//g;
#
# Do the date defaults first
my ($starttime,$endtime) = &get_dates_from_form();
- if ($ENV{'form.makedatesdefault'}) {
+ if ($env{'form.makedatesdefault'}) {
$r->print(&make_dates_default($starttime,$endtime));
}
# Get the 'sortby' and 'Status' variables so the user goes back to their
# previous screen
- my $sortby = $ENV{'form.sortby'};
- my $status = $ENV{'form.Status'};
+ my $sortby = $env{'form.sortby'};
+ my $status = $env{'form.Status'};
#
# We always need this information
- my $slogin = $ENV{'form.slogin'};
- my $sdom = $ENV{'form.sdomain'};
+ my $slogin = $env{'form.slogin'};
+ my $sdom = $env{'form.sdomain'};
#
# Get the old data
my %old=&Apache::lonnet::get('environment',
@@ -1474,7 +1634,7 @@ sub modify_single_student {
'lastname','generation','id'],
$sdom, $slogin);
$old{'section'} = &Apache::lonnet::getsection($sdom,$slogin,
- $ENV{'request.course.id'});
+ $env{'request.course.id'});
my ($tmp) = keys(%old);
if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
$r->print(&mt('There was an error determining the environment values for')." $slogin \@ $sdom.");
@@ -1483,19 +1643,19 @@ sub modify_single_student {
undef $tmp;
#
# Get the new data
- my $firstname = $ENV{'form.firstname'};
- my $middlename = $ENV{'form.middlename'};
- my $lastname = $ENV{'form.lastname'};
- my $generation = $ENV{'form.generation'};
- my $section = $ENV{'form.section'};
- my $courseid = $ENV{'request.course.id'};
- my $sid = $ENV{'form.id'};
+ my $firstname = $env{'form.firstname'};
+ my $middlename = $env{'form.middlename'};
+ my $lastname = $env{'form.lastname'};
+ my $generation = $env{'form.generation'};
+ my $section = $env{'form.section'};
+ my $courseid = $env{'request.course.id'};
+ my $sid = $env{'form.id'};
my $displayable_starttime = localtime($starttime);
my $displayable_endtime = localtime($endtime);
#
# check for forceid override
if ((defined($old{'id'})) && ($old{'id'} ne '') &&
- ($sid ne $old{'id'}) && (! exists($ENV{'form.forceid'}))) {
+ ($sid ne $old{'id'}) && (! exists($env{'form.forceid'}))) {
$r->print("".&mt('You changed the students id but did not disable the ID change safeguard. The students id will not be changed.')."");
$sid = $old{'id'};
}
@@ -1562,14 +1722,14 @@ END
# 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'},
+ $env{'request.course.id'},
$section,undef);
if ($modify_section_results !~ /^ok/) {
$r->print(&mt('An error occured during the attempt to change the section for this student.')." |