Diff for /loncom/interface/lonstatistics.pm between versions 1.128 and 1.134

version 1.128, 2006/02/14 16:05:37 version 1.134, 2006/05/11 20:05:02
Line 49  use Apache::Constants qw(:common :http); Line 49  use Apache::Constants qw(:common :http);
 use vars qw(  use vars qw(
     @FullClasslist       @FullClasslist 
     @Students      @Students
     @Sections       @Sections
       @Groups 
     %StudentData      %StudentData
     @StudentDataOrder      @StudentDataOrder
     @SelectedStudentData      @SelectedStudentData
Line 88  use Apache::longradinganalysis(); Line 89  use Apache::longradinganalysis();
   
 =item @Sections The sections available in this class  =item @Sections The sections available in this class
   
   =item @Groups The groups available in the class
   
 =item $curr_student The student currently being examined  =item $curr_student The student currently being examined
   
 =item $prev_student The student previous in the classlist  =item $prev_student The student previous in the classlist
Line 124  undef the following package variables: Line 127  undef the following package variables:
   
 =item @Sections  =item @Sections
   
   =item @Groups
   
 =item %StudentData  =item %StudentData
   
 =item @StudentDataOrder  =item @StudentDataOrder
Line 146  sub clear_classlist_variables { Line 151  sub clear_classlist_variables {
     undef(@FullClasslist);      undef(@FullClasslist);
     undef(@Students);      undef(@Students);
     undef(@Sections);      undef(@Sections);
       undef(@Groups);
     undef(%StudentData);      undef(%StudentData);
     undef(@SelectedStudentData);      undef(@SelectedStudentData);
     undef($curr_student);      undef($curr_student);
Line 171  the following package variables: Line 177  the following package variables:
   
 =item @Sections  =item @Sections
   
   =item @Groups 
   
 =item %StudentData  =item %StudentData
   
 =item @SelectedStudentData  =item @SelectedStudentData
Line 201  sub PrepareClasslist { Line 209  sub PrepareClasslist {
     my ($classlist,$field_names) = &Apache::loncoursedata::get_classlist($cdom,      my ($classlist,$field_names) = &Apache::loncoursedata::get_classlist($cdom,
  $cnum);   $cnum);
     my @selected_sections = &get_selected_sections();      my @selected_sections = &get_selected_sections();
       my @selected_groups = &get_selected_groups();
     #      #
     # Deal with instructors with restricted section access      # Deal with instructors with restricted section access
     if ($env{'request.course.sec'} !~ /^\s*$/) {      if ($env{'request.course.sec'} !~ /^\s*$/) {
Line 208  sub PrepareClasslist { Line 217  sub PrepareClasslist {
     }      }
     #      #
     # Set up %StudentData      # Set up %StudentData
     @StudentDataOrder = qw/fullname username domain id section status comments/;      @StudentDataOrder = qw/fullname username domain id section status groups comments/;
     foreach my $field (@StudentDataOrder) {      foreach my $field (@StudentDataOrder) {
         $StudentData{$field}->{'title'} = &mt($field);          $StudentData{$field}->{'title'} = &mt($field);
         $StudentData{$field}->{'base_width'} = length(&mt($field));          $StudentData{$field}->{'base_width'} = length(&mt($field));
Line 220  sub PrepareClasslist { Line 229  sub PrepareClasslist {
     $enrollment_status = 'Active';      $enrollment_status = 'Active';
     $enrollment_status = $env{'form.Status'} if (exists($env{'form.Status'}));      $enrollment_status = $env{'form.Status'} if (exists($env{'form.Status'}));
     #      #
       # Get groupmembership
       my ($classgroups,$studentgroups);
       my %curr_groups = &Apache::loncommon::coursegroups($cdom,$cnum);
       if (%curr_groups) {
           ($classgroups,$studentgroups) = 
       &Apache::loncoursedata::get_group_memberships($classlist,
                                                             $field_names,
     $cdom,$cnum);
       }
       my $now = time;
   
     # Process the classlist      # Process the classlist
     while (my ($student,$student_data) = each (%$classlist)) {      while (my ($student,$student_data) = each (%$classlist)) {
         my $studenthash = ();          my $studenthash = ();
Line 234  sub PrepareClasslist { Line 254  sub PrepareClasslist {
                 $StudentData{$field}->{'width'} = $length;                   $StudentData{$field}->{'width'} = $length; 
             }              }
         }          }
           my @studentsgroups = &Apache::loncoursedata::get_students_groups
                                                      ($student,$enrollment_status,
                                                       $classgroups);
           if (@studentsgroups) {
               $studenthash->{'groups'} = join(', ',@studentsgroups);
               $studenthash->{'groupref'} = \@studentsgroups;
           } else {
               $studenthash->{'groups'} = 'none';
               $studenthash->{'groupref'} = []; 
           }
         push (@FullClasslist,$studenthash);          push (@FullClasslist,$studenthash);
         #          #
         # Build up a list of sections          # Build up a list of sections
Line 251  sub PrepareClasslist { Line 281  sub PrepareClasslist {
                  (($studenthash->{'status'} eq $enrollment_status) ||                    (($studenthash->{'status'} eq $enrollment_status) || 
                   ($enrollment_status eq 'Any'))                     ($enrollment_status eq 'Any')) 
                  ){                   ){
                 push (@Students,$studenthash);                  my $groupcheck = 0;
                 last;                  if (grep(/^all$/,@selected_groups)) {
                       push(@Students,$studenthash);
                       last;
                   } elsif (grep(/^none$/,@selected_groups)) {
                       if ($studenthash->{'groups'} eq 'none') {
                           push(@Students,$studenthash);
                           last;
                       }     
                   } else {
                       foreach my $group (@selected_groups) {
                           if (grep(/^$group$/,@studentsgroups)) {
                               push(@Students,$studenthash);
                               $groupcheck = 1;
                               last;
                           }
                       }
                       if ($groupcheck) {
                           last;
                       }
                   }
             }              }
         }          }
     }      }
Line 264  sub PrepareClasslist { Line 313  sub PrepareClasslist {
         @Sections = sort {$a cmp $b} keys(%Sections);          @Sections = sort {$a cmp $b} keys(%Sections);
         unshift(@Sections,'all'); # Put 'all' at the front of the list          unshift(@Sections,'all'); # Put 'all' at the front of the list
     }      }
       # Sort the groups
       @Groups = sort {$a cmp $b} keys(%{$studentgroups});
       unshift(@Groups,'all'); # Put 'all' at the front of the list
   
     #      #
     # Sort the Students      # Sort the Students
     my $sortby = 'fullname';      my $sortby = 'fullname';
Line 347  sub get_selected_sections { Line 400  sub get_selected_sections {
   
 #######################################################  #######################################################
 #######################################################  #######################################################
                                                                                       
   =pod
                                                                                       
   =item get_selected_groups
                                                                                       
   Returns an array of the selected groups
                                                                                       
   =cut
                                                                                       
   #######################################################
   #######################################################
   sub get_selected_groups {
       my @selected_groups =
           &Apache::loncommon::get_env_multiple('form.Group');
       @selected_groups = ('all') if (! @selected_groups);
       foreach my $grp (@selected_groups) {
           if ($grp eq 'all') {
               @selected_groups = ('all');
               last;
           }
       }
       return @selected_groups;
   }
                                                                                       
 =pod  =pod
   
 =item &section_and_enrollment_description  =item &section_and_enrollment_description
   
 Returns a string describing the currenly selected section(s) and   Returns a string describing the currently selected section(s), group(s) and 
 enrollment status.    enrollment status.  
   
 Inputs: mode = 'plaintext' or 'localized'  (defaults to 'localized')  Inputs: mode = 'plaintext' or 'localized'  (defaults to 'localized')
Line 367  sub section_and_enrollment_description { Line 443  sub section_and_enrollment_description {
     my ($mode) = @_;      my ($mode) = @_;
     if (! defined($mode)) { $mode = 'localized'; }      if (! defined($mode)) { $mode = 'localized'; }
     my @sections = &Apache::lonstatistics::get_selected_sections();      my @sections = &Apache::lonstatistics::get_selected_sections();
       my @groups = &Apache::lonstatistics::get_selected_groups();
     my $description;      my $description;
     if ($mode eq 'localized') {      if ($mode eq 'localized') {
         $description = &mt('Unable to determine section and enrollment');          $description = &mt('Unable to determine section, groups and enrollment');
     } elsif ($mode eq 'plaintext') {      } elsif ($mode eq 'plaintext') {
         $description = 'Unable to determine section and enrollment';          $description = 'Unable to determine section, groups and enrollment';
     } else {      } else {
         $description = 'Bad parameter passed to lonstatistics::section_and_enrollment_description';          $description = 'Bad parameter passed to lonstatistics::section_and_enrollment_description';
         &Apache::lonnet::logthis($description);          &Apache::lonnet::logthis($description);
     }      }
     if (scalar(@sections) == 1 && $sections[0] ne 'all') {      $description = &section_or_group_text($mode,'section',@sections).
    ' '.&section_or_group_text($mode,'group',@groups);
       if ($mode eq 'localized') {
           $description .= &mt(' [_1] enrollment status.',$env{'form.Status'});
       } elsif ($mode eq 'plaintext') {
           $description .= ' '.$env{'form.Status'}.' enrollment status.';
       }
       return $description;
   }
   
   #######################################################
   #######################################################
   
   sub section_or_group_text {
       my ($mode,$type,@items) = @_;
       my $text;
       my %phrases = ();
       %{$phrases{'section'}} = (
                                 single => 'Section',
                                 all => 'All sections',
                                 plural => 'Sections',
                                );
       %{$phrases{'group'}} = (
                                 single => 'Group',
                                 all => 'All groups',
                                 plural => 'Groups',
                                );
       if (scalar(@items) == 1 && $items[0] ne 'all') {
         if ($mode eq 'localized') {          if ($mode eq 'localized') {
             $description = &mt('Section [_1]. [_2] enrollment status.',              $text = &mt('[_1] [_2].',$phrases{$type}{single},$items[0]);
                                $sections[0],$env{'form.Status'});  
         } elsif ($mode eq 'plaintext') {          } elsif ($mode eq 'plaintext') {
             $description = 'Section '.$sections[0].'. '.              $text = $phrases{$type}{single}.' '.$items[0].'.';
                 $env{'form.Status'}.' enrollment status.';  
         }          }
     } elsif (scalar(@sections) && $sections[0] eq 'all') {      } elsif (scalar(@items) && $items[0] eq 'all') {
         if ($mode eq 'localized') {          if ($mode eq 'localized') {
             $description = &mt('All sections. [_1] enrollment status.',              $text = &mt('[_1].',$phrases{$type}{all});
                                $env{'form.Status'});  
         } elsif ($mode eq 'plaintext') {          } elsif ($mode eq 'plaintext') {
             $description = 'All sections. '.              $text = $phrases{$type}{all}.'.';
                 $env{'form.Status'}.' enrollment status.';  
         }          }
     } elsif (scalar(@sections)) {      } elsif (scalar(@items)) {
         my $lastsection = pop(@sections);          my $lastitem = pop(@items);
         if ($mode eq 'localized') {          if ($mode eq 'localized') {
             $description = &mt('Sections [_1] and [_2]. [_3] enrollment status.',              $text = &mt('[_1] [_2] and [_3].',$phrases{$type}{plural},
                                join(', ',@sections),$lastsection,                          join(', ',@items),$lastitem);
                                $env{'form.Status'});  
         } elsif ($mode eq 'plaintext') {          } elsif ($mode eq 'plaintext') {
             $description =               $text = $phrases{$type}{plural}.' '.join(', ',@items).' and '.
                 'Sections '.join(', ',@sections).' and '.$lastsection.'. '.                      $lastitem.'.';
                 $env{'form.Status'}.' enrollment status.';  
         }          }
     }      }
     return $description;      return $text;
 }  }
   
 #######################################################  
 #######################################################  
   
 =pod  =pod
   
Line 758  sub SectionSelect { Line 855  sub SectionSelect {
     return $Str;      return $Str;
 }  }
   
   ##############################################
   ##############################################
                                                                                       
   =pod
                                                                                       
   =item &GroupSelect($elementname,$status,$numvisible)
                                                                                       
   Returns html for a selection box allowing the user to choose one (or more)
   of the groups in the course.
                                                                                       
   Uses the package variables @Groups
   =over 4
                                                                                       
   =item $elementname The name of the HTML form element
                                                                                       
   =item $status 'multiple' or 'single' selection box
                                                                                       
   =item $numvisible The number of options to be visible
                                                                                       
   =back
                                                                                       
   =cut
                                                                                       
   ##############################################
   ##############################################
   sub GroupSelect {
       my ($elementname,$status,$numvisible)=@_;
       if ($numvisible < 1) {
           return;
       }
       #
       # Make sure we have the data we need to continue
       if (! @Groups) {
           &PrepareClasslist();
       }
       #
       # Build the form element
       my $Str = "\n";
       $Str .= '<select name="'.$elementname.'" ';
       if ($status ne 'single') {
           $Str .= 'multiple="true" ';
       }
       $Str .= 'size="'.$numvisible.'" >'."\n";
       #
       # Loop through the groups
       foreach my $s (@Groups) {
           $Str .= '    <option value="'.$s.'" ';
           foreach my $group (&get_selected_groups()) {
               if ($s eq $group) {
                   $Str .= 'selected ';
                   last;
               }
           }
           $Str .= '>'.$s."</option>\n";
       }
       $Str .= "</select>\n";
   }
   
   
 ##################################################  ##################################################
 ##################################################  ##################################################
 sub DisplayClasslist {  sub DisplayClasslist {
Line 767  sub DisplayClasslist { Line 923  sub DisplayClasslist {
     #      #
     # Output some of the standard interface components      # Output some of the standard interface components
     my $Str;      my $Str;
     $Str .= &Apache::lonhtmlcommon::breadcrumbs(undef,'Select One Student');      $Str .= &Apache::lonhtmlcommon::breadcrumbs('Select One Student');
     $Str .= '<p><table cellspacing="5">'."\n";      $Str .= '<p><table cellspacing="5">'."\n";
     $Str .= '<tr>';      $Str .= '<tr>';
     $Str .= '<th align="center"><b>'.&mt('Sections').'</b></th>';      $Str .= '<th align="center"><b>'.&mt('Sections').'</b></th>';
       $Str .= '<th align="center"><b>'.&mt('Groups').'</b></th>';
     $Str .= '<th align="center"><b>'.&mt('Enrollment Status').'</b></th>';      $Str .= '<th align="center"><b>'.&mt('Enrollment Status').'</b></th>';
     $Str .= '</tr>'.$/;      $Str .= '</tr>'.$/;
     $Str .= '<tr>';      $Str .= '<tr>';
     $Str .= '<td>'.      $Str .= '<td>'.
         &Apache::lonstatistics::SectionSelect('Section','multiple',5).          &Apache::lonstatistics::SectionSelect('Section','multiple',5).
         '</td>';          '</td>';
       $Str .=  '<td>'.
           &Apache::lonstatistics::GroupSelect('Group','multiple',5).
           '</td>';
     $Str .= '<td>'.      $Str .= '<td>'.
         &Apache::lonhtmlcommon::StatusOptions(undef,undef,5).          &Apache::lonhtmlcommon::StatusOptions(undef,undef,5).
         '</td>';          '</td>';
Line 788  sub DisplayClasslist { Line 948  sub DisplayClasslist {
     $r->print($Str);      $r->print($Str);
     $r->rflush();      $r->rflush();
     #      #
     my @Fields = ('fullname','username','domain','id','section','status');      my @Fields = ('fullname','username','domain','id','section','status','groups');
     #      #
     $Str = '';      $Str = '';
     my @selected_sections = &get_selected_sections();      my @selected_sections = &get_selected_sections();
Line 990  sub handler { Line 1150  sub handler {
     td.essay          { border: 1px solid gray; }      td.essay          { border: 1px solid gray; }
 </style>  </style>
 ENDSTYLE  ENDSTYLE
     my $html=&Apache::lonxml::xmlbegin();        
     $r->print($html.'<head><title>'.      $r->print(&Apache::loncommon::start_page('Course Statistics and Charts',
               &mt('Course Statistics and Charts').       $style));
               '</title>'.$style.  
               "</head>\n".  
               &Apache::loncommon::bodytag('Course Statistics and Charts'));  
     $r->rflush();      $r->rflush();
     #       # 
     # Either print out a menu for them or send them to a report      # Either print out a menu for them or send them to a report
Line 1007  ENDSTYLE Line 1164  ENDSTYLE
                                             bug=>'Statistics and Charts'});                                              bug=>'Statistics and Charts'});
     if (! exists($env{'form.reportSelected'}) ||       if (! exists($env{'form.reportSelected'}) || 
         $env{'form.reportSelected'} eq '') {          $env{'form.reportSelected'} eq '') {
         $r->print(&Apache::lonhtmlcommon::breadcrumbs          $r->print(&Apache::lonhtmlcommon::breadcrumbs('Statistics Main Page').
                   (undef,&mt('Statistics Main Page')).  
                   &CreateMainMenu());                    &CreateMainMenu());
     } else {      } else {
     #      #
Line 1025  ENDSTYLE Line 1181  ENDSTYLE
                           'retrieved until the database is restarted.  '.                            'retrieved until the database is restarted.  '.
                           'Your data is intact but cannot be displayed '.                            'Your data is intact but cannot be displayed '.
                           'at this time.').'</p>');                            'at this time.').'</p>');
             $r->print('</body></html>');              $r->print(&Apache::loncommon::end_page());
             return;              return;
         }          }
         #          #
Line 1093  ENDSTYLE Line 1249  ENDSTYLE
         #          #
         $r->print("</form>\n");          $r->print("</form>\n");
     }      }
     $r->print("</body>\n</html>\n");      $r->print(&Apache::loncommon::end_page());
     $r->rflush();      $r->rflush();
     #      #
     return OK;      return OK;

Removed from v.1.128  
changed lines
  Added in v.1.134


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>