--- loncom/interface/spreadsheet/studentcalc.pm 2003/05/19 15:48:18 1.3 +++ loncom/interface/spreadsheet/studentcalc.pm 2003/08/01 13:33:41 1.16 @@ -1,5 +1,5 @@ # -# $Id: studentcalc.pm,v 1.3 2003/05/19 15:48:18 matthew Exp $ +# $Id: studentcalc.pm,v 1.16 2003/08/01 13:33:41 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -64,12 +64,25 @@ my %Exportrows = (); my $current_course; +sub initialize { + &Apache::assesscalc::initialize(); + &initialize_sequence_cache(); +} + sub initialize_package { $current_course = $ENV{'request.course.id'}; &initialize_sequence_cache(); &load_cached_export_rows(); } +sub ensure_correct_sequence_data { + if ($current_course ne $ENV{'request.course.id'}) { + &initialize_sequence_cache(); + $current_course = $ENV{'request.course.id'}; + } + return; +} + sub initialize_sequence_cache { # # Set up the sequences and assessments @@ -91,14 +104,25 @@ sub clear_package { sub get_title { my $self = shift; - my $title = ''; + my @title = (); + # + # Determine the students name my %userenv = &Apache::loncoursedata::GetUserName($self->{'name'}, $self->{'domain'}); - &Apache::lonnet::logthis('userenv = '.join(' ',%userenv)); - my $name = - join(' ',@userenv{'firstname','middlename','lastname','generation'}); + my $name = join(' ', + @userenv{'firstname','middlename','lastname','generation'}); $name =~ s/\s+$//; - $title .= '

'.$name; + + push (@title,$name); + push (@title,$self->{'coursedesc'}); + push (@title,scalar(localtime(time))); + return @title; +} + +sub get_html_title { + my $self = shift; + my ($name,$desc,$time) = $self->get_title(); + my $title = '

'.$name; if ($ENV{'user.name'} ne $self->{'name'} && $ENV{'user.domain'} ne $self->{'domain'}) { $title .= &Apache::loncommon::aboutmewrapper @@ -106,8 +130,8 @@ sub get_title { $self->{'name'},$self->{'domain'}); } $title .= "

\n"; - $title .= '

'.$self->{'coursedesc'}."

\n"; - $title .= '

'.localtime(time).'

'; + $title .= '

'.$desc."

\n"; + $title .= '

'.$time.'

'; return $title; } @@ -120,9 +144,29 @@ sub parent_link { return $link; } +sub convenience_links { + my $self = shift; + my ($resource) = @_; + my $symb = &Apache::lonnet::escape($resource->{'symb'}); + my $result = <<"END"; + + + + + + + + + +END + return $result; +} + sub outsheet_html { my $self = shift; my ($r) = @_; + my $importcolor = '#FFFFAA'; + my $exportcolor = '#88FF88'; #################################### # Get the list of assessment files # #################################### @@ -139,7 +183,7 @@ sub outsheet_html { - @@ -148,7 +192,7 @@ END my $label_num = 0; foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){ if ($label_num<$num_uneditable) { - $tableheader .='\n"; - # - $r->print($tableheader); - # - # Print out template row - $r->print(''. - $self->html_template_row($num_uneditable)."\n"); - # - # Print out summary/export row - $r->print(''. - $self->html_export_row()."\n"); + if ($self->blackout()) { + $r->print('

'. + 'Some computations are not available at this time.
'. + 'There are problems whose status you are allowed to view.'. + '

'."\n"); + } else { + $r->print($tableheader); + # + # Print out template row + if (exists($ENV{'request.role.adv'}) && $ENV{'request.role.adv'}) { + $r->print(''. + $self->html_template_row($num_uneditable, + $importcolor)."\n"); + } + # + # Print out summary/export row + $r->print(''. + $self->html_export_row($exportcolor)."\n"); + } $r->print("
Student + Import Calculations'; + $tableheader .=''; } else { $tableheader .=''; } @@ -156,24 +200,41 @@ END $label_num++; } $tableheader .="
Template 
Export0
Template 
Summary0
\n"); # # Prepare to output rows - $tableheader =<<"END"; + if (exists($ENV{'request.role.adv'}) && $ENV{'request.role.adv'}) { + $tableheader =<<"END";

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

+

RowAssessment
Row Assessment
+ +END + } foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){ if ($label_num<$num_uneditable) { $tableheader.=''; if ($editing_is_allowed) { $row_output .= ''; + $row_output .= ''; $row_output .= ''; } else { $row_output .= ''; } - $row_output .= $self->html_row($num_uneditable,$rownum). - "\n"; + if ($self->blackout() && $self->{'blackout_rows'}->{$rownum}>0) { + $row_output .= + ''."\n"; + } else { + $row_output .= $self->html_row($num_uneditable,$rownum, + $exportcolor,$importcolor). + "\n"; + } $r->print($row_output); } $r->print("
 Assessment'; @@ -199,23 +260,31 @@ END my $row_output = '
'.$rownum.''.$self->convenience_links($resource).''. ''. - $resource->{'title'}.'
'; + '&usymb='.&Apache::lonnet::escape($resource->{'symb'}). + '">'.$resource->{'title'}.'
'; $row_output .= &assess_file_selector($rownum, $assess_filename, \@AssessFileNames). '
Go To'; $row_output .= ''.$resource->{'title'}.'
Unavailable at this time
\n"); @@ -279,42 +348,69 @@ sub modify_cell { return; } -sub outsheet_csv { - my $self = shift; - my ($r) = @_; -} -sub outsheet_excel { - my $self = shift; - my ($r) = @_; -} -sub outsheet_recursive_excel { - my $self = shift; - my ($r) = @_; -} - -sub display { +sub csv_rows { + # writes the meat of the spreadsheet to an excel worksheet. Called + # by Spreadsheet::outsheet_excel; my $self = shift; - my ($r) = @_; - $self->compute(); - $self->outsheet_html($r); + my ($filehandle) = @_; + # + # Write a header row + $self->csv_output_row($filehandle,undef, + ('Sequence or Folder','Assessment title')); + # + # Write each assessments row + if (scalar(@Sequences)< 1) { + &initialize_sequence_cache(); + } + foreach my $Sequence (@Sequences) { + next if ($Sequence->{'num_assess'} < 1); + foreach my $resource (@{$Sequence->{'contents'}}) { + my $rownum = $self->get_row_number_from_key($resource->{'symb'}); + my @assessdata = ($Sequence->{'title'}, + $resource->{'title'}); + $self->csv_output_row($filehandle,$rownum,@assessdata); + } + } return; } -sub set_row_sources { +sub excel_rows { + # writes the meat of the spreadsheet to an excel worksheet. Called + # by Spreadsheet::outsheet_excel; my $self = shift; - while (my ($cell,$value) = each(%{$self->{'formulas'}})) { - next if ($cell !~ /^A(\d+)/ && $1 > 0); - my $row = $1; - (undef,$value) = split('__&&&__',$value); - $value = 'Default' if (! defined($value)); - $self->{'row_source'}->{$row} = $value; + my ($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); + } + $rows_output++; + # + # Write each assessments row + if (scalar(@Sequences)< 1) { + &initialize_sequence_cache(); + } + foreach my $Sequence (@Sequences) { + next if ($Sequence->{'num_assess'} < 1); + foreach my $resource (@{$Sequence->{'contents'}}) { + my $rownum = $self->get_row_number_from_key($resource->{'symb'}); + my @assessdata = ($Sequence->{'title'}, + $resource->{'title'}); + $self->excel_output_row($worksheet,$rownum,$rows_output++, + @assessdata); + } } return; } +sub outsheet_recursive_excel { + my $self = shift; + my ($r) = @_; +} + sub compute { my $self = shift; - $self->logthis('computing'); if (! defined($current_course) || $current_course ne $ENV{'request.course.id'}) { $current_course = $ENV{'request.course.id'}; @@ -356,6 +452,10 @@ sub compute { $assess_filename, $resource->{'symb'}); my @exportdata = $assessSheet->export_data(); + if ($assessSheet->blackout()) { + $self->blackout(1); + $self->{'blackout_rows'}->{$rownum} = 1; + } # # Be sure not to disturb the formulas in the 'A' column my $data = shift(@exportdata); @@ -385,6 +485,20 @@ sub compute { $Exportrows{$student}->{'data'} = \@exportarray; # save export row $self->save_export_data(); + # + $self->save() if ($self->need_to_save()); + return; +} + +sub set_row_sources { + my $self = shift; + while (my ($cell,$value) = each(%{$self->{'formulas'}})) { + next if ($cell !~ /^A(\d+)/ && $1 > 0); + my $row = $1; + (undef,$value) = split('__&&&__',$value); + $value = 'Default' if (! defined($value)); + $self->{'row_source'}->{$row} = $value; + } return; } @@ -396,6 +510,7 @@ sub set_row_numbers { next if ($row == 0); my ($symb,undef) = split('__&&&__',$formula); $self->{'row_numbers'}->{$symb} = $row; + $self->{'maxrow'} = $1 if ($1 > $self->{'maxrow'}); } } @@ -464,6 +579,7 @@ Writes the export data for this student ############################################# sub save_export_data { my $self = shift; + return if ($self->temporary()); my $student = $self->{'name'}.':'.$self->{'domain'}; return if (! exists($Exportrows{$student})); return if (! $self->is_default()); @@ -472,7 +588,7 @@ sub save_export_data { my $newstore = join('___;___', @{$Exportrows{$student}->{'data'}}); $newstore = '___=___'.$newstore; - &Apache::lonnet::put('nohist_calculatedsheets', + my $result= &Apache::lonnet::put('nohist_calculatedsheets', { $key => $newstore, $timekey => $Exportrows{$student}->{'time'} }, $self->{'cdom'}, @@ -498,6 +614,11 @@ sub export_data { my $self = shift; my $student = $self->{'name'}.':'.$self->{'domain'}; if (! exists($Exportrows{$student}) || + ! defined($Exportrows{$student}) || + ! exists($Exportrows{$student}->{'data'}) || + ! defined($Exportrows{$student}->{'data'}) || + ! exists($Exportrows{$student}->{'time'}) || + ! defined($Exportrows{$student}->{'time'}) || ! $self->check_expiration_time($Exportrows{$student}->{'time'})) { $self->compute(); }