--- loncom/interface/lonstatistics.pm	2005/02/25 23:23:47	1.117
+++ loncom/interface/lonstatistics.pm	2005/03/18 00:19:35	1.121
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonstatistics.pm,v 1.117 2005/02/25 23:23:47 matthew Exp $
+# $Id: lonstatistics.pm,v 1.121 2005/03/18 00:19:35 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -50,7 +50,6 @@ use vars qw(
     @FullClasslist 
     @Students
     @Sections 
-    @SelectedSections
     %StudentData
     @StudentDataOrder
     @SelectedStudentData
@@ -124,8 +123,6 @@ undef the following package variables:
 
 =item @Sections
 
-=item @SelectedSections
-
 =item %StudentData
 
 =item @StudentDataOrder
@@ -148,7 +145,6 @@ sub clear_classlist_variables {
     undef(@FullClasslist);
     undef(@Students);
     undef(@Sections);
-    undef(@SelectedSections);
     undef(%StudentData);
     undef(@SelectedStudentData);
     undef($curr_student);
@@ -174,8 +170,6 @@ the following package variables:
 
 =item @Sections
 
-=item @SelectedSections
-
 =item %StudentData
 
 =item @SelectedStudentData
@@ -205,23 +199,11 @@ sub PrepareClasslist {
     my $cnum = $ENV{'course.'.$cid.'.num'};
     my ($classlist,$field_names) = &Apache::loncoursedata::get_classlist($cid,
                                                                   $cdom,$cnum);
-    if (exists($ENV{'form.Section'})) {
-        if (ref($ENV{'form.Section'})) {
-            @SelectedSections = @{$ENV{'form.Section'}};
-        } elsif ($ENV{'form.Section'} !~ /^\s*$/) {
-            @SelectedSections = ($ENV{'form.Section'});
-        }
-    }
-    @SelectedSections = ('all') if (! @SelectedSections);
-    foreach (@SelectedSections) {
-        if ($_ eq 'all') {
-            @SelectedSections = ('all');
-        }
-    }
+    my @selected_sections = &get_selected_sections();
     #
     # Deal with instructors with restricted section access
     if ($ENV{'request.course.sec'} !~ /^\s*$/) {
-        @SelectedSections = ($ENV{'request.course.sec'});
+        @selected_sections = ($ENV{'request.course.sec'});
     }
     #
     # Set up %StudentData
@@ -262,7 +244,7 @@ sub PrepareClasslist {
         $Sections{$section}++;
         #
         # Only put in the list those students we are interested in
-        foreach my $sect (@SelectedSections) {
+        foreach my $sect (@selected_sections) {
             if ( (($sect eq 'all') || 
                   ($section eq $sect)) &&
                  (($studenthash->{'status'} eq $enrollment_status) || 
@@ -334,6 +316,70 @@ sub PrepareClasslist {
     return;
 }
 
+#######################################################
+#######################################################
+
+=pod
+
+=item get_selected_sections
+
+Returns an array of the selected sections
+
+=cut
+
+#######################################################
+#######################################################
+sub get_selected_sections {
+    my @selected_sections;
+    if (exists($ENV{'form.Section'})) {
+        if (ref($ENV{'form.Section'})) {
+            @selected_sections = @{$ENV{'form.Section'}};
+        } elsif ($ENV{'form.Section'} !~ /^\s*$/) {
+            @selected_sections = ($ENV{'form.Section'});
+        }
+    }
+    @selected_sections = ('all') if (! @selected_sections);
+    foreach (@selected_sections) {
+        if ($_ eq 'all') {
+            @selected_sections = ('all');
+        }
+    }
+    #
+    # Deal with instructors with restricted section access
+    if ($ENV{'request.course.sec'} !~ /^\s*$/) {
+        @selected_sections = ($ENV{'request.course.sec'});
+    }
+    return @selected_sections;
+}
+
+#######################################################
+#######################################################
+
+=pod
+
+=item &section_and_enrollment_description
+
+=cut
+
+#######################################################
+#######################################################
+sub section_and_enrollment_description {
+    my @sections = &Apache::lonstatistics::get_selected_sections();
+    my $description = &mt('Unable to determine section and enrollment');
+    if (scalar(@sections) == 1 && $sections[0] ne 'all') {
+        $description = &mt('Section [_1]. [_2] enrollment status.',
+                           $sections[0],$ENV{'form.Status'});
+    } elsif (scalar(@sections) && $sections[0] eq 'all') {
+        $description = &mt('All sections. [_1] enrollment status.',
+                           $ENV{'form.Status'});
+    } elsif (scalar(@sections)) {
+        my $lastsection = pop(@sections);
+        $description = &mt('Sections [_1] and [_2]. [_3] enrollment status.',
+                           join(', ',@sections),$lastsection,
+                           $ENV{'form.Status'});
+    }
+    return $description;
+}
 
 #######################################################
 #######################################################
@@ -500,6 +546,12 @@ sub get_selected_maps {
     } else {
         @selected_maps = ('all');
     }
+    foreach my $map (@selected_maps) {
+        if ($map eq 'all') {
+            @selected_maps = ('all');
+            last;
+        }
+    }
     return @selected_maps;
 }
 
@@ -535,7 +587,7 @@ sub selected_sequences_with_assessments
                                                sub { shift->is_map(); },1,0,1);
     my @sequences_with_assessments;
     for my $sequence ($navmap->getById('0.0'), @sequences) {
-	if ($navmap->hasResource($sequence,sub { shift->is_problem(); }, 0)){
+	if ($navmap->hasResource($sequence,sub { shift->is_problem(); },0,1)){
             push(@sequences_with_assessments,$sequence);
         }
     }
@@ -599,21 +651,10 @@ sub map_select {
     }
     $form .= 'size="'.$numvisible.'" >'."\n";
     #
-    # Deal with 'all'
-    foreach (@selected_maps) {
-        if ($_ eq 'all') {
-            @selected_maps = ('all');
-            last;
-        }
-    }
-    #
     # Put in option for 'all'
     $form .= '    <option value="all" ';
-    foreach (@selected_maps) {
-        if ($_ eq 'all') {
-            $form .= 'selected ';
-            last;
-        }
+    if ($selected_maps[0] eq 'all') {
+        $form .= 'selected ';
     }
     $form .= ">all</option>\n";
     #
@@ -649,7 +690,7 @@ sub map_select {
 Returns html for a selection box allowing the user to choose one (or more) 
 of the sections in the course.  
 
-Uses the package variables @Sections and @SelectedSections
+Uses the package variables @Sections
 =over 4
 
 =item $elementname The name of the HTML form element
@@ -686,7 +727,7 @@ sub SectionSelect {
     # Loop through the sequences
     foreach my $s (@Sections) {
         $Str .= '    <option value="'.$s.'" ';
-        foreach (@SelectedSections) {
+        foreach (&get_selected_sections()) {
             if ($s eq $_) {
                 $Str .= 'selected ';
                 last;
@@ -731,8 +772,9 @@ sub DisplayClasslist {
     my @Fields = ('fullname','username','domain','id','section','status');
     #
     $Str = '';
+    my @selected_sections = &get_selected_sections();
     if (! @Students) {
-        if ($SelectedSections[0] eq 'all') { 
+        if ($selected_sections[0] eq 'all') { 
             if (lc($ENV{'form.Status'}) eq 'any') {
                 $Str .= '<h2>'.
                     &mt('There are no students in the course.').