--- loncom/interface/lonstatistics.pm	2002/08/21 17:18:08	1.47
+++ loncom/interface/lonstatistics.pm	2002/10/21 00:19:39	1.52
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # (Publication Handler
 #
-# $Id: lonstatistics.pm,v 1.47 2002/08/21 17:18:08 www Exp $
+# $Id: lonstatistics.pm,v 1.52 2002/10/21 00:19:39 minaeibi 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;
 
@@ -84,6 +85,10 @@ sub ProcessFormData{
     &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'}} :
@@ -122,7 +127,8 @@ sub ProcessFormData{
                       'ProblemStatisticsAscend', 'Ascending');
     &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');
 
@@ -318,14 +324,14 @@ sub PrepareData {
         return "Unable to tie hash to db file.";
     }
 
-    if(!$isCached) {
+#    if(!$isCached) {
         my $processTopResourceMapReturn=
-            &Apache::loncoursedata::ProcessTopResourceMap(\%cache, $c, $r);
+            &Apache::loncoursedata::ProcessTopResourceMap(\%cache, $c);
         if($processTopResourceMapReturn ne 'OK') {
             untie(%cache);
             return $processTopResourceMapReturn;
         }
-    }
+ #   }
 
     if($c->aborted()) {
         untie(%cache);
@@ -359,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);
 }
 
@@ -504,10 +509,13 @@ sub BuildStatistics {
                             'updateTime');
     my @headings=('Full Name', 'Section', 'PID', 'Domain', 'User Name',
                   'Last Updated');
-    my $spacing = '   ';
+    my $spacing = '   '; 
+#    my $spacing = '     ';
+
     my %reports = ('classlist'          => 'Class list',
                    'problem_statistics' => 'Problem Statistics',
                    'student_assessment' => 'Student Assessment',
+		   'percentage'         => 'Percentage Graphs',
 #                   'activitylog'        => 'Activity Log',
                    'reportSelected'     => 'Class list');
 
@@ -587,6 +595,9 @@ sub BuildStatistics {
     } 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");
@@ -603,6 +614,13 @@ sub handler {
 
 #    $jr = $r;
 
+    my $loaderror=&Apache::lonnet::overloaderror($r);
+    if ($loaderror) { return $loaderror; }
+    $loaderror=
+       &Apache::lonnet::overloaderror($r,
+         $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
+    if ($loaderror) { return $loaderror; }
+
     unless(&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
         $ENV{'user.error.msg'}=
         $r->uri.":vgr:0:0:Cannot view grades for complete course";