--- loncom/interface/spreadsheet/classcalc.pm 2003/06/23 16:06:11 1.9 +++ loncom/interface/spreadsheet/classcalc.pm 2003/11/17 19:55:41 1.15 @@ -1,5 +1,5 @@ # -# $Id: classcalc.pm,v 1.9 2003/06/23 16:06:11 matthew Exp $ +# $Id: classcalc.pm,v 1.15 2003/11/17 19:55:41 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -46,6 +46,8 @@ classcalc package Apache::classcalc; use strict; +use warnings FATAL=>'all'; +no warnings 'uninitialized'; use Apache::Constants qw(:common :http); use Apache::loncoursedata(); use Apache::lonhtmlcommon(); @@ -56,6 +58,7 @@ use HTML::Entities(); use Spreadsheet::WriteExcel; use Apache::lonnet; use Time::HiRes; +use Apache::lonlocal; @Apache::classcalc::ISA = ('Apache::Spreadsheet'); @@ -71,6 +74,11 @@ sub initialize { return; } +sub clear_package { + undef(@Students); + &Apache::studentcalc::clear_package(); +} + sub html_header { my $self = shift; my ($toprow,$bottomrow); @@ -79,7 +87,7 @@ sub html_header { ['Enrollment Status',&Apache::lonhtmlcommon::StatusOptions(undef,undef,3)], ['Output Format',&Apache::Spreadsheet::output_selector()]) { my ($name,$selector) = @{$_}; - $toprow .= ''.$name.''; + $toprow .= ''.&mt($name).''; $bottomrow .= ''.$selector.''; } return "

\n\n". @@ -91,7 +99,7 @@ sub html_header { sub get_title { my $self = shift; # Section info should be included - my @title = ($self->{'coursedesc'}, scalar(localtime(time)) ); + my @title = ($self->{'coursedesc'}, &Apache::lonlocal::locallocaltime(time) ); return @title; } @@ -109,26 +117,42 @@ sub parent_link { sub outsheet_html { my $self = shift; my ($r) = @_; + #################################### + # Report any calculation errors # + #################################### + $r->print($self->html_report_error()); ################################### # Determine table structure ################################### + my $importcolor = '#88FF88'; + my $exportcolor = '#BBBBFF'; my $num_uneditable = 26; my $num_left = 52-$num_uneditable; + my %lt=&Apache::lonlocal::texthash( + 'co' => 'Course', + 'im' => 'Import', + 'ca' => 'Calculations', + 'stu' => 'Student', + 'sta' => 'Status', + 'usr' => 'Username', + 'dom' => 'Domain', + 'sec' => 'Section', + ); my $tableheader =<<"END";

- - + + + $lt{'ca'} END my $label_num = 0; foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){ if ($label_num<$num_uneditable) { - $tableheader.=''. - $self->html_template_row($num_uneditable)."\n"); + $r->print(''. + $self->html_template_row($num_uneditable,$importcolor). + "\n"); # # Print out summary/export row - $r->print(''. - $self->html_export_row()."\n"); + $r->print(''. + $self->html_export_row($exportcolor)."\n"); # # Prepare to output rows $tableheader =<<"END";

Course - Import$lt{'co'} + $lt{'im'} - Calculations
'; + $tableheader.=''; } else { $tableheader.=''; } @@ -140,24 +164,25 @@ END $r->print($tableheader); # # Print out template row - $r->print('
Template 
'.&mt('Template').' 
Summary0
'.&mt('Summary').'0
- - - + + + END foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){ if ($label_num<$num_uneditable) { - $tableheader.=''. ''. ''. - $self->html_row($num_uneditable,$rownum)."\n"); + $self->html_row($num_uneditable,$rownum,$exportcolor, + $importcolor). + "\n"); } $r->print("
Rowstudentusernamedomainsectionstatus
$lt{'ro'}$lt{'stu'}$lt{'usr'}$lt{'dom'}$lt{'sec'}$lt{'sta'}'; + $tableheader.=''; } else { $tableheader.=''; } @@ -180,7 +205,9 @@ END ''.$student->{'domain'} .''.$student->{'section'} .''.$student->{'status'} .'

\n"); return; @@ -190,12 +217,12 @@ sub excel_rows { # writes the meat of the spreadsheet to an excel worksheet. Called # by Spreadsheet::outsheet_excel; my $self = shift; - my ($worksheet,$cols_output,$rows_output) = @_; + my ($connection,$worksheet,$cols_output,$rows_output) = @_; # # Write a header row $cols_output = 0; - foreach my $value ('fullname','username','domain','section','status') { - $worksheet->write($rows_output,$cols_output++,$value); + foreach my $value ('Fullname','Username','Domain','Section','Status','ID') { + $worksheet->write($rows_output,$cols_output++,&mt($value)); } $rows_output++; # @@ -209,7 +236,8 @@ sub excel_rows { $student->{'username'}, $student->{'domain'}, $student->{'section'}, - $student->{'status'}); + $student->{'status'}, + $student->{'id'}); $self->excel_output_row($worksheet,$rownum,$rows_output++, @studentdata); } @@ -220,12 +248,11 @@ sub csv_rows { # writes the meat of the spreadsheet to an excel worksheet. Called # by Spreadsheet::outsheet_excel; my $self = shift; - my ($filehandle) = @_; + my ($connection,$filehandle) = @_; # # Write a header row - $self->csv_output_row($filehandle,undef, - ('fullname','username','domain','section','status')); + (&mt('Fullname'),&mt('Username'),&mt('Domain'),&mt('Section'),&mt('Status'),&mt('ID'))); # # Write each students row foreach my $student (@Students) { @@ -236,7 +263,8 @@ sub csv_rows { $student->{'username'}, $student->{'domain'}, $student->{'section'}, - $student->{'status'}); + $student->{'status'}, + $student->{'id'}); $self->csv_output_row($filehandle,$rownum,@studentdata); } return; @@ -245,27 +273,36 @@ sub csv_rows { sub outsheet_recursive_excel { my $self = shift; my ($r) = @_; -} +} sub compute { my $self = shift; my ($r) = @_; + my $connection = $r->connection(); + if ($connection->aborted()) { $self->cleanup(); return; } $self->initialize_safe_space(); my %c = $self->constants(); my %f = $self->formulas(); my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin - ($r,'Spreadsheet Computation Status', - 'Spreadsheet Computation', scalar(@Students)); + ($r,&mt('Spreadsheet Computation Status'), + &mt('Spreadsheet Computation'), scalar(@Students)); &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state, - 'Processing course structure'); + &mt('Processing course structure')); &Apache::studentcalc::initialize_package(); &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state, - 'Processing first student'); + &mt('Processing first student')); foreach my $student (@Students) { + if ($connection->aborted()) { $self->cleanup(); return; } my $sname = $student->{'username'}.':'.$student->{'domain'}; my $studentsheet = Apache::studentcalc->new ($student->{'username'},$student->{'domain'},undef); - my @exportdata = $studentsheet->export_data(); + if ($connection->aborted()) { $self->cleanup(); return; } + my @exportdata = $studentsheet->export_data($r); + if ($studentsheet->badcalc()) { + $self->set_calcerror($sname.' : '. + $studentsheet->calcerror()); + } + if ($connection->aborted()) { $self->cleanup(); return; } my $rownum = $self->get_row_number_from_key($sname); $f{'A'.$rownum} = $sname; $self->{'row_source'}->{$rownum} = $sname;