--- loncom/interface/statistics/lonproblemstatistics.pm	2005/03/08 17:40:39	1.100
+++ loncom/interface/statistics/lonproblemstatistics.pm	2005/03/14 20:28:22	1.102
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonproblemstatistics.pm,v 1.100 2005/03/08 17:40:39 matthew Exp $
+# $Id: lonproblemstatistics.pm,v 1.102 2005/03/14 20:28:22 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -721,11 +721,17 @@ sub BuildProblemStatisticsPage {
         return;
     }
     if (exists($ENV{'form.Excel'})) {
+        $r->print('<h4>'.
+                  &Apache::lonstatistics::section_and_enrollment_description().
+                  '</h4>');
         &Excel_output($r);
     } else { 
         $r->print('<input type="submit" name="Excel" value="'.
                   &mt('Produce Excel Output').'" />'.'&nbsp;'x5);
         $r->rflush();
+        $r->print('<h4>'.
+                  &Apache::lonstatistics::section_and_enrollment_description().
+                  '</h4>');
         my $count = 0;
         foreach my $seq (@sequences) {
             my @resources = 
@@ -1264,30 +1270,13 @@ sub Excel_output {
     &compute_all_statistics($r);
     my $c = $r->connection;
     return if ($c->aborted());
+    #
+    my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
     ##
     ## Create the excel workbook
-    my $filename = '/prtspool/'.
-        $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
-        time.'_'.rand(1000000000).'.xls';
-    my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
-    #
-    # Create sheet
-    my $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
-    #
-    # Check for errors
-    if (! defined($excel_workbook)) {
-        $r->log_error("Error creating excel spreadsheet $filename: $!");
-        $r->print(&mt("Problems creating new Excel file.  ".
-                  "This error has been logged.  ".
-                  "Please alert your LON-CAPA administrator."));
-        return 0;
-    }
-    #
-    # The excel spreadsheet stores temporary data in files, then put them
-    # together.  If needed we should be able to disable this (memory only).
-    # The temporary directory must be specified before calling 'addworksheet'.
-    # File::Temp is used to determine the temporary directory.
-    $excel_workbook->set_tempdir($Apache::lonnet::tmpdir);
+    my ($excel_workbook,$filename,$format) =
+        &Apache::loncommon::create_workbook($r);
+    return if (! defined($excel_workbook));
     #
     # Add a worksheet
     my $sheetname = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
@@ -1296,8 +1285,6 @@ sub Excel_output {
     }
     my $excel_sheet = $excel_workbook->addworksheet(
         &Apache::loncommon::clean_excel_name($sheetname));
-    #
-    my $format = &Apache::loncommon::define_excel_formats($excel_workbook);
     ##
     ## Begin creating excel sheet
     ##
@@ -1313,9 +1300,9 @@ sub Excel_output {
     my $sectionstring = '';
     $excel_sheet->write($rows_output,$cols_output++,
                         &Apache::lonstathelpers::sections_description
-                            (@Apache::lonstatistics::SelectedSections),
+                            (&Apache::lonstatistics::get_selected_sections()),
                         $format->{'h3'});
-    $cols_output += scalar(@Apache::lonstatistics::SelectedSections);
+    $cols_output += scalar(&Apache::lonstatistics::get_selected_sections());
     #
     # Time restrictions
     my $time_string;
@@ -1556,7 +1543,7 @@ sub get_statistics {
     my $courseid = $ENV{'request.course.id'};
     #
     my $data = &Apache::loncoursedata::get_problem_statistics
-                        (\@Apache::lonstatistics::SelectedSections,
+                        ([&Apache::lonstatistics::get_selected_sections()],
                          $Apache::lonstatistics::enrollment_status,
                          $symb,$part,$courseid,$starttime,$endtime);
     $data->{'symb'}        = $symb;
@@ -1574,7 +1561,7 @@ sub get_statistics {
     #
     # Store in metadata if computations were done for all students
     if ($data->{'num_students'} > 1) {
-        my @Sections = @Apache::lonstatistics::SelectedSections;
+        my @Sections = &Apache::lonstatistics::get_selected_sections();
         my $sections = '"'.join(' ',@Sections).'"';
         $sections =~ s/&+/_/g;  # Ensure no special characters
         $data->{'sections'}=$sections;
@@ -1634,7 +1621,7 @@ sub compute_discrimination_factor {
     my $ranking = 
         &Apache::loncoursedata::rank_students_by_scores_on_resources
         (\@Resources,
-         \@Apache::lonstatistics::SelectedSections,
+         [&Apache::lonstatistics::get_selected_sections()],
          $Apache::lonstatistics::enrollment_status,undef,
          $starttime,$endtime);
     #
@@ -1699,7 +1686,7 @@ sub compute_sequence_statistics {
     # First compute statistics based on student scores
     my ($smin,$smax,$sMean,$sSTD,$scount,$sMAX) = 
         &Apache::loncoursedata::score_stats
-                    (\@Apache::lonstatistics::SelectedSections,
+                    ([&Apache::lonstatistics::get_selected_sections()],
                      $Apache::lonstatistics::enrollment_status,
                      \@Resources,$starttime,$endtime,undef);
     $SeqStat{$symb}->{'title'}  = $seq->compTitle;
@@ -1714,7 +1701,7 @@ sub compute_sequence_statistics {
     # 'correct' is taken to mean 
     my ($cmin,$cmax,$cMean,$cSTD,$ccount)=
         &Apache::loncoursedata::count_stats
-        (\@Apache::lonstatistics::SelectedSections,
+        ([&Apache::lonstatistics::get_selected_sections()],
          $Apache::lonstatistics::enrollment_status,
          \@Resources,$starttime,$endtime,undef);
     my $K = $part_count;