--- loncom/interface/spreadsheet/assesscalc.pm 2003/05/29 13:39:38 1.11 +++ loncom/interface/spreadsheet/assesscalc.pm 2003/12/05 22:24:20 1.17.2.3 @@ -1,5 +1,5 @@ # -# $Id: assesscalc.pm,v 1.11 2003/05/29 13:39:38 matthew Exp $ +# $Id: assesscalc.pm,v 1.17.2.3 2003/12/05 22:24:20 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -48,6 +48,7 @@ use Apache::Constants qw(:common :http); use Apache::lonnet; use Apache::loncommon; use Apache::Spreadsheet; +use Apache::loncoursedata(); use HTML::Entities(); use Spreadsheet::WriteExcel; use GDBM_File; @@ -125,6 +126,7 @@ sub clear_package { sub initialize { &clear_package(); + &Apache::loncoursedata::clear_internal_caches(); } ######################################################## @@ -140,12 +142,15 @@ sub initialize { ######################################################## sub initialize_package { my ($sname,$sdomain) = @_; - $current_course = $ENV{'request.course.id'}; $current_name = $sname; $current_domain = $sdomain; - undef(%courseopt); + if ($current_course ne $ENV{'request.course.id'}) { + $current_course = $ENV{'request.course.id'}; + undef(%courseopt); + } &load_cached_export_rows(); &load_parameter_caches(); + &Apache::loncoursedata::clear_internal_caches(); } ######################################################## @@ -245,7 +250,7 @@ this user and course. ################################################## sub parmval { my $self = shift; - my ($what,$symb,$uname,$udom,$csec)=@_; + my ($what,$symb,$uname,$udom,$csec,$recurse)=@_; $uname = $self->{'name'} if (! defined($uname)); $udom = $self->{'domain'} if (! defined($udom)); $csec = $self->{'section'} if (! defined($csec)); @@ -310,9 +315,12 @@ sub parmval { if ($part eq '') { $part='0'; } my $newwhat=$rwhat; $newwhat=~s/\Q$space\E/$part/; - my $partgeneral=$self->parmval($newwhat,$symb,$uname,$udom,$csec); + my $partgeneral=$self->parmval($newwhat,$symb,$uname,$udom,$csec,1); if (defined($partgeneral)) { return $partgeneral; } } + if ($recurse) { return undef; } + my $pack_def=&Apache::lonnet::packages_tab_default($fn,'resource.'.$what); + if (defined($pack_def)) { return $pack_def; } #nothing defined return ''; } @@ -332,11 +340,11 @@ sub get_html_title { sub get_title { my $self = shift; my @title = (); - if (($self->{'usymb'} eq '_feedback') || - ($self->{'usymb'} eq '_evaluation') || - ($self->{'usymb'} eq '_discussion') || - ($self->{'usymb'} eq '_tutoring')) { - my $assess_title = ucfirst($self->{'usymb'}); + if (($self->{'symb'} eq '_feedback') || + ($self->{'symb'} eq '_evaluation') || + ($self->{'symb'} eq '_discussion') || + ($self->{'symb'} eq '_tutoring')) { + my $assess_title = ucfirst($self->{'symb'}); $assess_title =~ s/^_//; push(@title,$assess_title); } else { @@ -366,16 +374,22 @@ 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 = '#FFFFFF'; + my $exportcolor = '#FFFFAA'; my $num_uneditable = 1; my $num_left = 52-$num_uneditable; my $tableheader =<<"END"; - + @@ -383,7 +397,7 @@ END my $label_num = 0; foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){ if ($label_num<$num_uneditable) { - $tableheader .= ''. - $self->html_template_row($num_uneditable)."\n"); + $self->html_template_row($num_uneditable,$importcolor). + "\n"); # # Print out summary/export row $r->print(''. - $self->html_export_row()."\n"); + $self->html_export_row($exportcolor)."\n"); # # Prepare to output rows $tableheader =<<"END"; @@ -409,7 +424,7 @@ END END foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){ if ($label_num<$num_uneditable) { - $tableheader.='
Assessment   Calculations
'; + $tableheader .= ''; } else { $tableheader .= ''; } @@ -396,11 +410,12 @@ END # # Print out template row $r->print('
Template 
Export0
'; + $tableheader.=''; } else { $tableheader.=''; } @@ -422,7 +437,7 @@ END $r->print("
\n".$tableheader); } $r->print(''.$rownum.''. - $self->assess_html_row($rownum)."\n"); + $self->assess_html_row($rownum,$importcolor)."\n"); } $r->print("\n"); return; @@ -430,7 +445,7 @@ END sub assess_html_row { my $self = shift(); - my ($row) = @_; + my ($row,$importcolor) = @_; my $parameter_name = $self->{'formulas'}->{'A'.$row}; my @rowdata = $self->get_row($row); my $num_cols_output = 0; @@ -444,7 +459,7 @@ sub assess_html_row { } foreach my $cell (@rowdata) { if ($num_cols_output < 1) { - $row_html .= ''; + $row_html .= ''; $row_html .= &Apache::Spreadsheet::html_uneditable_cell($cell, '#FFDDDD'); } else { @@ -509,7 +524,7 @@ sub excel_rows { sub compute { my $self = shift; - $self->logthis('computing'); +# $self->logthis('computing'); $self->initialize_safe_space(); ######################################### ######################################### @@ -586,7 +601,10 @@ sub compute { while (my ($parm,$value) = each(%parameters)) { last if ($self->blackout()); next if ($parm !~ /^(parameter_.*)_problemstatus$/); - next if ($parameters{$1.'_answerdate'}blackout(1); @@ -612,6 +630,7 @@ sub compute { # # Save the export data $self->save_export_data(); + $self->save() if ($self->need_to_save()); return; } @@ -729,13 +748,20 @@ sub export_data { ! defined($Exportrows{$symb}->{$self->{'filename'}})) { $self->compute(); } - my @Data = @{$Exportrows{$symb}->{$self->{'filename'}}}; - if ($Data[0] =~ /^(.*)___=___/) { - $self->{'sheetname'} = $1; - $Data[0] =~ s/^(.*)___=___//; - } - 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{$symb}->{$self->{'filename'}}}; + if ($Data[0] =~ /^(.*)___=___/) { + $self->{'sheetname'} = $1; + $Data[0] =~ s/^(.*)___=___//; + } + for (my $i=0;$i<$#Data;$i++) { + if ($Data[$i]=~/\D/ && defined($Data[$i])) { + $Data[$i]="'".$Data[$i]."'"; + } + } } return @Data; } @@ -758,6 +784,11 @@ sub save_export_data { return if ($self->temporary()); my $student = $self->{'name'}.':'.$self->{'domain'}; my $symb = $self->{'symb'}; + if ($self->badcalc()){ + # do not save data away when calculations have not been done properly. + delete($Exportrows{$symb}); + return; + } if (! exists($Exportrows{$symb}) || ! exists($Exportrows{$symb}->{$self->{'filename'}})) { return;