--- loncom/interface/lonstatistics.pm	2002/08/13 15:01:07	1.43
+++ loncom/interface/lonstatistics.pm	2002/08/30 15:35:08	1.49
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # (Publication Handler
 #
-# $Id: lonstatistics.pm,v 1.43 2002/08/13 15:01:07 stredwic Exp $
+# $Id: lonstatistics.pm,v 1.49 2002/08/30 15:35:08 stredwic Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -47,6 +47,7 @@ use Apache::lonhtmlcommon;
 use Apache::lonproblemanalysis;
 use Apache::lonproblemstatistics;
 use Apache::lonstudentassessment;
+use Apache::lonpercentage;
 use HTML::TokeParser;
 use GDBM_File;
 
@@ -82,6 +83,20 @@ sub ProcessFormData{
     &CheckFormElement($cache, 'DownloadAll', 'DownloadAll', 'false');
     &CheckFormElement($cache, 'sort', 'sort', 'fullname');
     &CheckFormElement($cache, 'download', 'download', 'false');
+    &CheckFormElement($cache, 'StatisticsMaps', 
+                      'StatisticsMaps', 'All Maps');
+    &CheckFormElement($cache, 'StatisticsProblemSelect',
+		      'StatisticsProblemSelect', 'All Problems');
+    &CheckFormElement($cache, 'StatisticsPartSelect',
+		      'StatisticsPartSelect', 'All Parts');
+    if(defined($ENV{'form.Section'})) {
+        my @sectionsSelected = (ref($ENV{'form.Section'}) ?
+                               @{$ENV{'form.Section'}} :
+                                ($ENV{'form.Section'}));
+        $cache->{'sectionsSelected'} = join(':', @sectionsSelected);
+    } elsif(!defined($cache->{'sectionsSelected'})) {
+        $cache->{'sectionsSelected'} = $cache->{'sectionList'};
+    }
 
     # student assessment
     if(defined($ENV{'form.CreateStudentAssessment'}) ||
@@ -102,15 +117,6 @@ sub ProcessFormData{
         &Apache::lonnet::unescape($cache->{'StudentAssessmentStudent'});
     &CheckFormElement($cache, 'DefaultColumns', 'DefaultColumns', 'false');
 
-    if(defined($ENV{'form.Section'})) {
-        my @sectionsSelected = (ref($ENV{'form.Section'}) ?
-                               @{$ENV{'form.Section'}} :
-                                ($ENV{'form.Section'}));
-        $cache->{'sectionsSelected'} = join(':', @sectionsSelected);
-    } elsif(!defined($cache->{'sectionsSelected'})) {
-        $cache->{'sectionsSelected'} = $cache->{'sectionList'};
-    }
-
     # Problem analysis
     &CheckFormElement($cache, 'Interval', 'Interval', '1');
 
@@ -119,11 +125,12 @@ sub ProcessFormData{
                       'DisplayFormat', 'Display Table Format');
     &CheckFormElement($cache, 'ProblemStatisticsAscend',
                       'ProblemStatisticsAscend', 'Ascending');
-    &CheckFormElement($cache, 'ProblemStatisticsMaps', 
-                      'ProblemStatisticsMaps', 'All Maps');
     &CheckFormElement($cache, 'ProblemStatisticsSort',
                       'ProblemStatisticsSort', 'Homework Sets Order');
-    &CheckFormElement($cache, 'DisplayLegend', 'DisplayLegend', 'Hide Legend');
+    &CheckFormElement($cache, 'DisplayLegend', 'DisplayLegend', 
+		      'Hide Legend');
+    &CheckFormElement($cache, 'SortProblems', 'SortProblems', 
+                      'Sort Within Sequence');
 
     # Search only form elements
     my @headingColumns=();
@@ -358,41 +365,40 @@ sub PrepareData {
     &SpaceColumns($students, $studentInformation, $headings, \%cache);
     $cache{'updateTime:columnWidth'}=24;
 
-    if($cache{'download'} ne 'false') {
-        my @who = ($cache{'download'});
+    my $download = $cache{'download'};
+    my $downloadAll = $cache{'DownloadAll'};
+    my @allStudents=();
+    if($download ne 'false') {
         $cache{'download'} = 'false';
+    } elsif($downloadAll ne 'false') {
+        $cache{'DownloadAll'} = 'false';
+        if($downloadAll eq 'sorted') {
+            @allStudents = @$students;
+        } else {
+            @allStudents = split(':::', $cache{'NamesOfStudents'});
+        }
+    }
+
+    untie(%cache);
+
+    if($download ne 'false') {
+        my @who = ($download);
         if(&Apache::loncoursedata::DownloadStudentCourseData(\@who, 'false', 
                                                              $cacheDB, 'true', 
                                                              'false', $courseID,
                                                              $r, $c) ne 'OK') {
-            untie(%cache);
             return 'Stop at download individual';
         }
-    } elsif($cache{'DownloadAll'} ne 'false') {
-        $cache{'DownloadAll'} = 'false';
-        my @allStudents;
-        if($cache{'DownloadAll'} eq 'sorted') {
-            @allStudents = @$students;
-        } else {
-            @allStudents = split(':::', $cache{'NamesOfStudents'});
-        }
+    } elsif($downloadAll ne 'false') {
         if(&Apache::loncoursedata::DownloadStudentCourseData(\@allStudents, 
                                                              'false', 
                                                              $cacheDB, 'true', 
                                                              'true', $courseID,
                                                              $r, $c) ne 'OK') {
-            untie(%cache);
             return 'Stop at download all';
         }
     }
 
-    if($c->aborted()) {
-        untie(%cache);
-        return 'aborted'; 
-    }
-
-    untie(%cache);
-
     return ('OK', $students);
 }
 
@@ -507,6 +513,7 @@ sub BuildStatistics {
     my %reports = ('classlist'          => 'Class list',
                    'problem_statistics' => 'Problem Statistics',
                    'student_assessment' => 'Student Assessment',
+		   'percentage'         => 'Percentage Graphs',
 #                   'activitylog'        => 'Activity Log',
                    'reportSelected'     => 'Class list');
 
@@ -515,7 +522,7 @@ sub BuildStatistics {
     my $cacheDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
                   "_$ENV{'user.domain'}_$courseID\_statistics.db";
 
-    $r->print(&Apache::lonhtmlcommon::Title('LON-CAPA Statistics'));
+    $r->print(&Apache::lonhtmlcommon::Title('Course Statistics and Charts'));
 
     my ($returnValue, $students) = &PrepareData($c, $cacheDB, 
                                                 \@studentInformation, 
@@ -542,7 +549,7 @@ sub BuildStatistics {
         }
 
         if(defined($cache{'OptionResponses'})) {
-            $reports{'problem_analysis'} = 'Problem Analysis';
+            $reports{'problem_analysis'} = 'Option Response Analysis';
         }
 
         $r->print('<form name="Statistics" ');
@@ -562,7 +569,7 @@ sub BuildStatistics {
                                                                   $students, 
                                                                   $courseID, 
                                                                   $c,$r);
-    } elsif($GoToPage eq 'Problem Analysis') {
+    } elsif($GoToPage eq 'Option Response Analysis') {
         &Apache::lonproblemanalysis::BuildProblemAnalysisPage($cacheDB, $r);
     } elsif($GoToPage eq 'Student Assessment') {
         &Apache::lonstudentassessment::BuildStudentAssessmentPage($cacheDB,
@@ -581,10 +588,14 @@ sub BuildStatistics {
         $courseDescription =~ s/\ /"_"/eg;
         &Apache::lonproblemstatistics::BuildGraphicChart($GoToPage, $cacheDB,
                                                          $courseDescription,
-                                                         $r);
+                                                         $students, $courseID,
+                                                         $r, $c);
     } elsif($GoToPage eq 'Class list') {
         &BuildClasslist($cacheDB, $students, \@studentInformation,
                         \@headings, $r);
+    } elsif($GoToPage eq 'Percentage Graphs') {
+	&Apache::lonpercentage::BuildPercentageGraph($cacheDB, $students,
+						     $courseID, $c, $r);
     }
 
     $r->print('</form>'."\n");