--- loncom/interface/spreadsheet/studentcalc.pm 2003/09/18 20:12:40 1.22 +++ loncom/interface/spreadsheet/studentcalc.pm 2004/11/02 20:48:02 1.26 @@ -1,5 +1,5 @@ # -# $Id: studentcalc.pm,v 1.22 2003/09/18 20:12:40 matthew Exp $ +# $Id: studentcalc.pm,v 1.26 2004/11/02 20:48:02 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -58,6 +58,7 @@ use Apache::Spreadsheet(); use Apache::assesscalc(); use HTML::Entities(); use Time::HiRes; +use Apache::lonlocal; @Apache::studentcalc::ISA = ('Apache::Spreadsheet'); @@ -110,15 +111,11 @@ sub get_title { my @title = (); # # Determine the students name - my %userenv = &Apache::loncoursedata::GetUserName($self->{'name'}, - $self->{'domain'}); - my $name = join(' ', - @userenv{'firstname','middlename','lastname','generation'}); - $name =~ s/\s+$//; - + my $name = &Apache::loncommon::plainname($self->{'name'}, + $self->{'domain'}); push (@title,$name); push (@title,$self->{'coursedesc'}); - push (@title,scalar(localtime(time))); + push (@title,&Apache::lonlocal::locallocaltime(time)); return @title; } @@ -140,7 +137,7 @@ sub get_html_title { sub parent_link { my $self = shift; - return '

Course level sheet

'."\n"; + return '

'.&mt('Course level sheet').'

'."\n"; } sub convenience_links { @@ -173,19 +170,30 @@ sub outsheet_html { my $editing_is_allowed = &Apache::lonnet::allowed('mgr', $ENV{'request.course.id'}); #################################### + # Report any calculation errors # + #################################### + $r->print($self->html_report_error()); + #################################### # Determine table structure # #################################### my $num_uneditable = 26; my $num_left = 52-$num_uneditable; + my %lt=&Apache::lonlocal::texthash( + 'st' => 'Student', + 'im' => 'Import', + 'ca' => 'Calculations', + 'as' => 'Assessment', + 'ro' => 'Row', + ); my $tableheader =<<"END";

- + + $lt{'im'} + $lt{'ca'} END my $label_num = 0; @@ -201,8 +209,8 @@ END $tableheader .="\n"; if ($self->blackout()) { $r->print('

'. - 'Some computations are not available at this time.
'. - 'There are problems whose status you are allowed to view.'. + &mt('Some computations are not available at this time.').'
'. + &mt('There are problems whose status you are not allowed to view.'). '

'."\n"); } else { $r->print($tableheader); @@ -215,7 +223,7 @@ END } # # Print out summary/export row - $r->print(''. + $r->print(''. $self->html_export_row($exportcolor)."\n"); } $r->print("
Student$lt{'st'} - Import - Calculations
Summary0
'.&mt('Summary').'0
\n"); @@ -225,13 +233,13 @@ END $tableheader =<<"END";

- + END } else { $tableheader =<<"END";

Row Assessment
$lt{'ro'} $lt{'as'}
- + END } foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){ @@ -278,7 +286,7 @@ END } if ($self->blackout() && $self->{'blackout_rows'}->{$rownum}>0) { $row_output .= - ''."\n"; + ''."\n"; } else { $row_output .= $self->html_row($num_uneditable,$rownum, $exportcolor,$importcolor). @@ -351,11 +359,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, - ('Sequence or Folder','Assessment title')); + (&mt('Sequence or Folder'),&mt('Assessment title'))); # # Write each assessments row if (scalar(@Sequences)< 1) { @@ -377,12 +385,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 ('Container','Assessment title') { - $worksheet->write($rows_output,$cols_output++,$value); + $worksheet->write($rows_output,$cols_output++,&mt($value)); } $rows_output++; # @@ -519,11 +527,19 @@ sub compute { } $f{$cell} = $resource->{'symb'}.'__&&&__'.$assess_filename; if ($connection->aborted()) { $self->cleanup(); return; } - my $assessSheet = Apache::assesscalc->new($self->{'name'}, - $self->{'domain'}, - $assess_filename, - $resource->{'symb'}); + my $assessSheet; + $assessSheet = Apache::assesscalc->new($self->{'name'}, + $self->{'domain'}, + $assess_filename, + $resource->{'symb'}); my @exportdata = $assessSheet->export_data($r); + # + if ($assessSheet->badcalc()) { + $self->set_calcerror( + &mt('Error computing row for assessment "[_1]" (row [_2]):[_3]', + $assessSheet->get_title(),$rownum,$assessSheet->calcerror())); + } + # if ($connection->aborted()) { $self->cleanup(); return; } if ($assessSheet->blackout()) { $self->blackout(1); @@ -654,11 +670,16 @@ Writes the export data for this student ############################################# sub save_export_data { my $self = shift; - &Apache::assesscalc::save_cached_export_rows($self->{'name'}, - $self->{'domain'}); - return if ($self->temporary()); my $student = $self->{'name'}.':'.$self->{'domain'}; + return if ($self->temporary()); + if ($self->badcalc()){ + # do not save data away when calculations have not been done properly. + delete($Exportrows{$student}); + return; + } return if (! exists($Exportrows{$student})); + &Apache::assesscalc::save_cached_export_rows($self->{'name'}, + $self->{'domain'}); return if (! $self->is_default()); my $key = join(':',($self->{'name'},$self->{'domain'},'studentcalc')).':'; my $timekey = $key.'.time'; @@ -702,9 +723,16 @@ sub export_data { $self->compute($r); } if ($connection->aborted()) { $self->cleanup(); return; } - my @Data = @{$Exportrows{$student}->{'data'}}; - for (my $i=0; $i<=$#Data;$i++) { - $Data[$i]="'".$Data[$i]."'" if ($Data[$i]=~/\D/ && defined($Data[$i])); + my @Data; + if ($self->badcalc()) { + @Data = (); + } else { + @Data = @{$Exportrows{$student}->{'data'}}; + for (my $i=0; $i<=$#Data;$i++) { + if ($Data[$i]=~/\D/ && defined($Data[$i])) { + $Data[$i]="'".$Data[$i]."'"; + } + } } return @Data; }
 Assessment
 $lt{'as'}Unavailable at this time
'.&mt('Unavailable at this time').'