File:  [LON-CAPA] / loncom / interface / lonstatistics.pm
Revision 1.165: download - view: text, annotated - select for diffs
Tue Nov 10 19:28:32 2020 UTC (3 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, HEAD
- Load CSS file(s) for resource when using (a) Student Submission Reports
  (only one problem selected), or and (b)Detailed Problem Analysis when
  "Show problem" is checked, or when using Submission Time Plots.

    1: # The LearningOnline Network with CAPA
    2: #
    3: # $Id: lonstatistics.pm,v 1.165 2020/11/10 19:28:32 raeburn Exp $
    4: #
    5: # Copyright Michigan State University Board of Trustees
    6: #
    7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    8: #
    9: # LON-CAPA is free software; you can redistribute it and/or modify
   10: # it under the terms of the GNU General Public License as published by
   11: # the Free Software Foundation; either version 2 of the License, or
   12: # (at your option) any later version.
   13: #
   14: # LON-CAPA is distributed in the hope that it will be useful,
   15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17: # GNU General Public License for more details.
   18: #
   19: # You should have received a copy of the GNU General Public License
   20: # along with LON-CAPA; if not, write to the Free Software
   21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   22: #
   23: # /home/httpd/html/adm/gpl.txt
   24: #
   25: # http://www.lon-capa.org/
   26: #
   27: # (Navigate problems for statistical reports
   28: #
   29: ###
   30: 
   31: 
   32: 
   33: package Apache::lonstatistics;
   34: 
   35: use strict;
   36: use Apache::Constants qw(:common :http);
   37: use vars qw(
   38:     @FullClasslist 
   39:     @Students
   40:     @Sections
   41:     @Groups 
   42:     %StudentData
   43:     @StudentDataOrder
   44:     @SelectedStudentData
   45:     $enrollment_status);
   46: 
   47: use Apache::lonnet;
   48: use Apache::lonhomework;
   49: use Apache::loncommon;
   50: use Apache::loncoursedata;
   51: use Apache::lonhtmlcommon;
   52: use Apache::lonmysql;
   53: use Apache::lonlocal;
   54: use Apache::longroup;
   55: use Time::HiRes;
   56: #
   57: # Statistics Packages
   58: use Apache::lonproblemanalysis();
   59: use Apache::lonsubmissiontimeanalysis();
   60: use Apache::loncorrectproblemplot();
   61: use Apache::lonproblemstatistics();
   62: use Apache::lonstudentassessment();
   63: use Apache::lonpercentage;
   64: use Apache::lonstudentsubmissions();
   65: use Apache::lonsurveyreports();
   66: use Apache::longradinganalysis();
   67: use Apache::lonquickgrades();
   68: use LONCAPA;
   69: 
   70: #
   71: # Classlist variables
   72: #
   73: my $curr_student;
   74: my $prev_student;
   75: my $next_student;
   76: 
   77: 
   78: sub clear_classlist_variables {
   79:     undef(@FullClasslist);
   80:     undef(@Students);
   81:     undef(@Sections);
   82:     undef(@Groups);
   83:     undef(%StudentData);
   84:     undef(@SelectedStudentData);
   85:     undef($curr_student);
   86:     undef($prev_student);
   87:     undef($next_student);
   88: }
   89: 
   90: 
   91: sub PrepareClasslist {
   92:     my %Sections;
   93:     &clear_classlist_variables();
   94:     #
   95:     # Retrieve the classlist
   96:     my $cid  = $env{'request.course.id'};
   97:     my $cdom = $env{'course.'.$cid.'.domain'};
   98:     my $cnum = $env{'course.'.$cid.'.num'};
   99:     my ($classlist,$field_names) = &Apache::loncoursedata::get_classlist($cdom,
  100: 									$cnum);
  101:     my @selected_sections = &get_selected_sections();
  102:     my @selected_groups = &get_selected_groups();
  103:     #
  104:     # Deal with instructors with restricted section access
  105:     if ($env{'request.course.sec'} !~ /^\s*$/) {
  106:         @selected_sections = ($env{'request.course.sec'});
  107:     }
  108:     #
  109:     # Set up %StudentData
  110:     @StudentDataOrder = qw/fullname username domain id section status groups comments/;
  111:     foreach my $field (@StudentDataOrder) {
  112:         $StudentData{$field}->{'title'} = &mt($field);
  113:         $StudentData{$field}->{'base_width'} = length(&mt($field));
  114:         $StudentData{$field}->{'width'} = 
  115:                                $StudentData{$field}->{'base_width'};
  116:     }
  117:     #
  118:     # get the status requested
  119:     $enrollment_status = 'Active';
  120:     $enrollment_status = $env{'form.Status'} if (exists($env{'form.Status'}));
  121:     #
  122:     # Get groupmembership
  123:     my ($classgroups,$studentgroups);
  124:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
  125:     if (%curr_groups) {
  126:         ($classgroups,$studentgroups) = 
  127: 	    &Apache::loncoursedata::get_group_memberships($classlist,
  128:                                                           $field_names,
  129: 							  $cdom,$cnum);
  130:     }
  131:     my $now = time;
  132: 
  133:     # Process the classlist
  134:     while (my ($student,$student_data) = each (%$classlist)) {
  135:         my $studenthash = ();
  136:         for (my $i=0; $i< scalar(@$field_names);$i++) {
  137:             my $field = $field_names->[$i];
  138:             # Store the data
  139:             $studenthash->{$field}=$student_data->[$i];
  140:             # Keep track of the width of the fields
  141:             next if (! exists($StudentData{$field}));
  142:             my $length = length($student_data->[$i]);
  143:             if ($StudentData{$field}->{'width'} < $length) {
  144:                 $StudentData{$field}->{'width'} = $length; 
  145:             }
  146:         }
  147:         my @studentsgroups = &Apache::loncoursedata::get_students_groups
  148:                                                    ($student,$enrollment_status,
  149:                                                     $classgroups);
  150:         if (@studentsgroups) {
  151:             $studenthash->{'groups'} = join(', ',@studentsgroups);
  152:             $studenthash->{'groupref'} = \@studentsgroups;
  153:         } else {
  154:             $studenthash->{'groups'} = 'none';
  155:             $studenthash->{'groupref'} = []; 
  156:         }
  157:         push (@FullClasslist,$studenthash);
  158:         #
  159:         # Build up a list of sections
  160:         my $section = $studenthash->{'section'};
  161:         if (! defined($section) || $section =~/^\s*$/ || $section == -1) {
  162:             $studenthash->{'section'} = 'none';
  163:             $section = $studenthash->{'section'};
  164:         }
  165:         $Sections{$section}++;
  166:         #
  167:         # Only put in the list those students we are interested in
  168:         foreach my $sect (@selected_sections) {
  169:             if ( (($sect eq 'all') || 
  170:                   ($section eq $sect)) &&
  171:                  (($studenthash->{'status'} eq $enrollment_status) || 
  172:                   ($enrollment_status eq 'Any')) 
  173:                  ){
  174:                 my $groupcheck = 0;
  175:                 if (grep(/^all$/,@selected_groups)) {
  176:                     push(@Students,$studenthash);
  177:                     last;
  178:                 } elsif (grep(/^none$/,@selected_groups)) {
  179:                     if ($studenthash->{'groups'} eq 'none') {
  180:                         push(@Students,$studenthash);
  181:                         last;
  182:                     }     
  183:                 } else {
  184:                     foreach my $group (@selected_groups) {
  185:                         if (grep(/^$group$/,@studentsgroups)) {
  186:                             push(@Students,$studenthash);
  187:                             $groupcheck = 1;
  188:                             last;
  189:                         }
  190:                     }
  191:                     if ($groupcheck) {
  192:                         last;
  193:                     }
  194:                 }
  195:             }
  196:         }
  197:     }
  198:     #
  199:     # Put the consolidated section data in the right place
  200:     if ($env{'request.course.sec'} !~ /^\s*$/) {
  201:         @Sections = ($env{'request.course.sec'});
  202:     } else {
  203:         @Sections = sort {
  204: 	    if ($a == $a && $b == $b ) { return $a <=> $b; }
  205: 	    return $a cmp $b;
  206: 	} keys(%Sections);
  207: 
  208:         unshift(@Sections,'all'); # Put 'all' at the front of the list
  209:     }
  210:     # Sort the groups
  211:     @Groups = sort {$a cmp $b} keys(%{$studentgroups});
  212:     unshift(@Groups,'all'); # Put 'all' at the front of the list
  213: 
  214:     #
  215:     # Sort the Students
  216:     my $sortby = 'fullname';
  217:     $sortby = $env{'form.sort'} if (exists($env{'form.sort'}));
  218:     my @TmpStudents = sort { lc($a->{$sortby}) cmp lc($b->{$sortby}) ||
  219:                              lc($a->{'fullname'}) cmp lc($b->{'fullname'}) ||
  220: 			     lc($a->{'username'}) cmp lc($b->{'username'}) } @Students;
  221:     @Students = @TmpStudents;
  222:     # 
  223:     # Now deal with that current student thing....
  224:     $curr_student = undef;
  225:     if (exists($env{'form.SelectedStudent'})) {
  226:         my ($current_uname,$current_dom) = 
  227:             split(':',$env{'form.SelectedStudent'});
  228:         my $i;
  229:         for ($i = 0; $i<=$#Students; $i++) {
  230:             next if (($Students[$i]->{'username'} ne $current_uname) || 
  231:                      ($Students[$i]->{'domain'}   ne $current_dom));
  232:             $curr_student = $Students[$i];
  233:             last; # If we get here, we have our student.
  234:         }
  235:         if (defined($curr_student)) {
  236:             if ($i == 0) {
  237:                 $prev_student = undef;
  238:             } else {
  239:                 $prev_student = $Students[$i-1];
  240:             }
  241:             if ($i == $#Students) {
  242:                 $next_student = undef;
  243:             } else {
  244:                 $next_student = $Students[$i+1];
  245:             }
  246:         }
  247:     }
  248:     #
  249:     if (exists($env{'form.StudentData'})) {
  250: 	@SelectedStudentData = 
  251: 	    &Apache::loncommon::get_env_multiple('form.StudentData');
  252:     } else {
  253:         @SelectedStudentData = ('username');
  254:     }
  255:     foreach (@SelectedStudentData) {
  256:         if ($_ eq 'all') {
  257:             @SelectedStudentData = ('all');
  258:             last;
  259:         }
  260:     }
  261:     #
  262:     return;
  263: }
  264: 
  265: 
  266: sub get_selected_sections {
  267:     my @selected_sections = 
  268: 	&Apache::loncommon::get_env_multiple('form.Section');
  269:     @selected_sections = ('all') if (! @selected_sections);
  270:     foreach (@selected_sections) {
  271:         if ($_ eq 'all') {
  272:             @selected_sections = ('all');
  273:         }
  274:     }
  275:     #
  276:     # Deal with instructors with restricted section access
  277:     if ($env{'request.course.sec'} !~ /^\s*$/) {
  278:         @selected_sections = ($env{'request.course.sec'});
  279:     }
  280:     return @selected_sections;
  281: }
  282: 
  283: 
  284: sub get_selected_groups {
  285:     my @selected_groups =
  286:         &Apache::loncommon::get_env_multiple('form.Group');
  287:     @selected_groups = ('all') if (! @selected_groups);
  288:     foreach my $grp (@selected_groups) {
  289:         if ($grp eq 'all') {
  290:             @selected_groups = ('all');
  291:             last;
  292:         }
  293:     }
  294:     return @selected_groups;
  295: }
  296:                                                                                     
  297: 
  298: 
  299: sub section_and_enrollment_description {
  300:     my ($mode) = @_;
  301:     if (! defined($mode)) { $mode = 'localized'; }
  302:     my @sections = &Apache::lonstatistics::get_selected_sections();
  303:     my @groups = &Apache::lonstatistics::get_selected_groups();
  304:     my $description;
  305:     if ($mode eq 'localized') {
  306:         $description = &mt('Unable to determine section, groups and access status');
  307:     } elsif ($mode eq 'plaintext') {
  308:         $description = 'Unable to determine section, groups and access status';
  309:     } else {
  310:         $description = 'Bad parameter passed to lonstatistics::section_and_enrollment_description';
  311:         &Apache::lonnet::logthis($description);
  312:     }
  313:     $description = &section_or_group_text($mode,'section',@sections).
  314: 	' '.&section_or_group_text($mode,'group',@groups);
  315:     if ($mode eq 'localized') {
  316:         $description .= ' '.&mt($env{'form.Status'}.' access status.');
  317:     } elsif ($mode eq 'plaintext') {
  318:         $description .= ' '.$env{'form.Status'}.' access status.';
  319:     }
  320:     return $description;
  321: }
  322: 
  323: 
  324: 
  325: 
  326: sub section_or_group_text {
  327:     my ($mode,$type,@items) = @_;
  328:     my $text;
  329:     my %phrases = ();
  330:     %{$phrases{'section'}} = (
  331:                               single => 'Section',
  332:                               all => 'All sections',
  333:                               plural => 'Sections',
  334:                              );
  335:     %{$phrases{'group'}} = (
  336:                               single => 'Group',
  337:                               all => 'All groups',
  338:                               plural => 'Groups',
  339:                              );
  340:     if (scalar(@items) == 1 && $items[0] ne 'all') {
  341:         if ($mode eq 'localized') {
  342:             $text = &mt($phrases{$type}{single}.' [_1].',$items[0]);
  343:         } elsif ($mode eq 'plaintext') {
  344:             $text = $phrases{$type}{single}.' '.$items[0].'.';
  345: 
  346:         }
  347:     } elsif (scalar(@items) && $items[0] eq 'all') {
  348:         if ($mode eq 'localized') {
  349:             $text = &mt($phrases{$type}{all}.'.');
  350:         } elsif ($mode eq 'plaintext') {
  351:             $text = $phrases{$type}{all}.'.';
  352:         }
  353:     } elsif (scalar(@items)) {
  354:         my $lastitem = pop(@items);
  355:         if ($mode eq 'localized') {
  356:             $text = &mt($phrases{$type}{plural}.' [_1] and [_2].',
  357:                         join(', ',@items),$lastitem);
  358:         } elsif ($mode eq 'plaintext') {
  359:             $text = $phrases{$type}{plural}.' '.join(', ',@items).' and '.
  360:                     $lastitem.'.';
  361:         }
  362:     }
  363:     return $text;
  364: }
  365: 
  366: 
  367: sub get_students {
  368:     if (! @Students) {
  369:         &PrepareClasslist();
  370:     }
  371:     return @Students;
  372: }
  373: 
  374: 
  375: 
  376: sub current_student { 
  377:     return $curr_student;
  378: }
  379: 
  380: 
  381: 
  382: sub previous_student { 
  383:     return $prev_student;
  384: }
  385: 
  386: 
  387: 
  388: sub next_student { 
  389:     return $next_student;
  390: }
  391: 
  392: 
  393: 
  394: sub StudentDataSelect {
  395:     my ($elementname,$status,$numvisible)=@_;
  396:     if ($numvisible < 1) {
  397:         return;
  398:     }
  399:     #
  400:     # Build the form element
  401:     my $Str = "\n";
  402:     $Str .= '<select name="'.$elementname.'" ';
  403:     if ($status ne 'single') {
  404:         $Str .= 'multiple="multiple" ';
  405:     }
  406:     $Str .= 'size="'.$numvisible.'" >'."\n";
  407:     #
  408:     # Deal with 'all'
  409:     $Str .= '    <option value="all"';
  410:     foreach (@SelectedStudentData) {
  411:         if ($_ eq 'all') {
  412:             $Str .= ' selected="selected"';
  413:             last;
  414:         }
  415:     }
  416:     $Str .= '>'.&mt('all')."</option>\n";
  417:     #
  418:     # Loop through the student data fields
  419:     foreach my $item (@StudentDataOrder) {
  420:         $Str .= '    <option value="'.$item.'"';
  421:         foreach (@SelectedStudentData) {
  422:             if ($item eq $_ ) {
  423:                 $Str .= ' selected="selected"';
  424:                 last;
  425:             }
  426:         }
  427:         $Str .= '>'.&mt($item)."</option>\n";
  428:     }
  429:     $Str .= "</select>\n";
  430:     return $Str;
  431: }
  432: 
  433: 
  434: 
  435: sub get_selected_maps {
  436:     my ($elementname) = @_;
  437:     my @selected_maps = 
  438: 	&Apache::loncommon::get_env_multiple('form.'.$elementname);
  439:     @selected_maps = ('all') if (! @selected_maps);
  440:     foreach my $map (@selected_maps) {
  441:         if ($map eq 'all') {
  442:             @selected_maps = ('all');
  443:             last;
  444:         }
  445:     }
  446:     return @selected_maps;
  447: }
  448: 
  449: 
  450: 
  451: 
  452: sub selected_sequences_with_assessments {
  453:     my ($mode) = @_;
  454:     $mode = 'selected' if (! defined($mode));
  455:     my $navmap = Apache::lonnavmaps::navmap->new();
  456:     if (!defined($navmap)) {
  457:         return ('Can not open Coursemap');
  458:     }
  459:     #
  460:     my @sequences = $navmap->retrieveResources(undef,
  461:                                                sub { shift->is_map(); },1,0,1);
  462:     my $toplevelseq = $navmap->getById('0.0');
  463:     if (!grep(/^\Q$toplevelseq\E$/,@sequences)) {
  464:         unshift(@sequences,$toplevelseq);
  465:     }
  466: 
  467:     my @sequences_with_assessments;
  468:     foreach my $sequence (@sequences) {
  469: 	if ($navmap->hasResource($sequence,sub { shift->is_gradable(); },0,1)){
  470:             push(@sequences_with_assessments,$sequence);
  471:         }
  472:     }
  473:     #
  474:     my @sequences_to_show;
  475:     foreach my $sequence (@sequences_with_assessments) {
  476:         if ($mode eq 'all') {
  477:             push (@sequences_to_show,$sequence);
  478:         } elsif ($mode eq 'selected') {
  479:             foreach my $map_symb (&get_selected_maps('Maps')) {
  480:                 if ($sequence->symb eq $map_symb || $map_symb eq 'all'){
  481:                     push (@sequences_to_show,$sequence);
  482:                     last; # Only put it in once
  483:                 }
  484:             }
  485:         }
  486: 
  487:     }
  488:     return $navmap,@sequences_to_show;
  489: }
  490: 
  491: 
  492: sub map_select {
  493:     my ($elementname,$status,$numvisible)=@_;
  494:     if ($numvisible < 1) {
  495:         return;
  496:     }
  497:     #
  498:     # Set up array of selected items
  499:     my @selected_maps = &get_selected_maps($elementname);
  500:     #
  501:     # Build the form element
  502:     my $form = "\n";
  503:     $form .= '<select name="'.$elementname.'" ';
  504:     if ($status ne 'single') {
  505:         $form .= 'multiple="multiple" ';
  506:     }
  507:     $form .= 'size="'.$numvisible.'" >'."\n";
  508:     #
  509:     # Put in option for 'all'
  510:     $form .= '    <option value="all"';
  511:     if ($selected_maps[0] eq 'all') {
  512:         $form .= ' selected="selected"';
  513:     }
  514:     $form .= '>'.&mt('all').'</option>'."\n";
  515:     #
  516:     # Loop through the sequences
  517:     my @sequences = &selected_sequences_with_assessments('all');
  518:     my $navmap;
  519:     if (!ref($sequences[0])) {
  520:         return $sequences[0];
  521:     } else {
  522:         $navmap = shift(@sequences);
  523:     }
  524:     foreach my $seq (@sequences){
  525:         $form .= '    <option value="'.$seq->symb.'"';
  526:         foreach (@selected_maps) {
  527:             if ($seq->symb eq $_) {
  528:                 $form .= ' selected="selected"';
  529:                 last;
  530:             }
  531:         }
  532:         $form .= '>'.$seq->compTitle."</option>\n";
  533:     }
  534:     $form .= "</select>\n";
  535:     return $form;
  536: }
  537: 
  538: 
  539: sub SectionSelect {
  540:     my ($elementname,$status,$numvisible)=@_;
  541:     if ($numvisible < 1) {
  542:         return;
  543:     }
  544:     #
  545:     # Make sure we have the data we need to continue
  546:     if (! @Sections) {
  547:         &PrepareClasslist()
  548:     }
  549:     #
  550:     # Make sure course's student table is up to date
  551:     if (@Sections) {
  552:         &Apache::loncoursedata::ensure_current_sections();
  553:     }
  554:     #
  555:     # Build the form element
  556:     my $Str = "\n";
  557:     $Str .= '<select name="'.$elementname.'" ';
  558:     if ($status ne 'single') {
  559:         $Str .= 'multiple="multiple" ';
  560:     }
  561:     $Str .= 'size="'.$numvisible.'" >'."\n";
  562:     #
  563:     # Loop through the sequences
  564:     foreach my $s (@Sections) {
  565:         $Str .= '    <option value="'.$s.'"';
  566:         foreach (&get_selected_sections()) {
  567:             if ($s eq $_) {
  568:                 $Str .= ' selected="selected"';
  569:                 last;
  570:             }
  571:         }
  572:         $Str .= '>'.$s."</option>\n";
  573:     }
  574:     $Str .= "</select>\n";
  575:     return $Str;
  576: }
  577: 
  578: 
  579: sub GroupSelect {
  580:     my ($elementname,$status,$numvisible)=@_;
  581:     if ($numvisible < 1) {
  582:         return;
  583:     }
  584:     #
  585:     # Make sure we have the data we need to continue
  586:     if (! @Groups) {
  587:         &PrepareClasslist();
  588:     }
  589:     #
  590:     # Make sure course's groupnames and studentgroups tables
  591:     # are up to date.
  592:     #
  593:     if (@Groups) {
  594:         &Apache::loncoursedata::ensure_current_groups();
  595:         &Apache::loncoursedata::ensure_current_students_groups();
  596:     }
  597:     #
  598:     # Build the form element
  599:     my $Str = "\n";
  600:     $Str .= '<select name="'.$elementname.'" ';
  601:     if ($status ne 'single') {
  602:         $Str .= 'multiple="multiple" ';
  603:     }
  604:     $Str .= 'size="'.$numvisible.'" >'."\n";
  605:     #
  606:     # Loop through the groups
  607:     foreach my $s (@Groups) {
  608:         $Str .= '    <option value="'.$s.'"';
  609:         foreach my $group (&get_selected_groups()) {
  610:             if ($s eq $group) {
  611:                 $Str .= ' selected="selected"';
  612:                 last;
  613:             }
  614:         }
  615:         $Str .= '>'.$s."</option>\n";
  616:     }
  617:     $Str .= "</select>\n";
  618: }
  619: 
  620: 
  621: 
  622: 
  623: sub DisplayClasslist {
  624:     my ($r)=@_;
  625:     &Apache::lonhtmlcommon::add_breadcrumb
  626:         ({text=>'Select One Student'});
  627:     #
  628:     # Output some of the standard interface components
  629:     my $Str;
  630:     $Str .= &Apache::lonhtmlcommon::breadcrumbs('Select One Student');
  631:     $Str .= '<table cellspacing="5">'."\n";
  632:     $Str .= '<tr>';
  633:     $Str .= '<th align="center"><b>'.&mt('Sections').'</b></th>';
  634:     $Str .= '<th align="center"><b>'.&mt('Groups').'</b></th>';
  635:     $Str .= '<th align="center"><b>'.&mt('Access Status').'</b></th>';
  636:     $Str .= '</tr>'.$/;
  637:     $Str .= '<tr>';
  638:     $Str .= '<td>'.
  639:         &Apache::lonstatistics::SectionSelect('Section','multiple',5).
  640:         '</td>';
  641:     $Str .=  '<td>'.
  642:         &Apache::lonstatistics::GroupSelect('Group','multiple',5).
  643:         '</td>';
  644:     $Str .= '<td>'.
  645:         &Apache::lonhtmlcommon::StatusOptions(undef,undef,5).
  646:         '</td>';
  647:     
  648:     $Str .= '</tr>'.$/;
  649:     $Str .= '</table>';
  650:     $Str .= '<input type="submit" name="selectstudent" value="'.
  651:         &mt('Update Display').'" />';
  652:     $r->print($Str);
  653:     $r->rflush();
  654:     #
  655:     my @Fields = ('fullname','username','domain','id','section','status','groups');
  656:     #
  657:     $Str = '';
  658:     my @selected_sections = &get_selected_sections();
  659:     if (! @Students) {
  660:         if ($selected_sections[0] eq 'all') { 
  661:             if (lc($env{'form.Status'}) eq 'active') {
  662:                 $Str .= '<p class="LC_info">'.
  663:                 &mt('There are no currently enrolled students in the course.').
  664:                     '</p>';
  665:             } elsif (lc($env{'form.Status'}) eq 'expired') {
  666:                 $Str .= '<p class="LC_info">'.
  667:                     &mt('There are no previously enrolled students in the course.').
  668:                         '</p>';
  669:             } elsif (lc($env{'form.Status'}) eq 'future') {
  670:                 $Str .= '<p class="LC_info">'.
  671:                     &mt('There are no students with future access in the course.').
  672:                         '</p>';
  673:             } else { # 'any' and any others
  674:                $Str .= '<p class="LC_info">'.
  675:                     &mt('There are no students in the course.').
  676:                     '</p>';
  677:             }
  678:         } else { 
  679:             if (lc($env{'form.Status'}) eq 'active') {
  680:                 $Str .= '<p class="LC_info">'.
  681:                     &mt('There are no currently enrolled students in the selected sections.').
  682:                     '</p>';
  683:             } elsif (lc($env{'form.Status'}) eq 'expired') {
  684:                 $Str .= '<p class="LC_info">'.
  685:                     &mt('There are no previously enrolled students in the selected sections.').
  686:                     '</p>';
  687:             } elsif (lc($env{'form.Status'}) eq 'future') {
  688:                 $Str .= '<p class="LC_info">'.
  689:                     &mt('There are no students with future access in the selected sections.').
  690:                         '</p>';
  691:             } else { # 'any' and any others
  692:                 $Str .= '<p class="LC_info">'.
  693:                     &mt('There are no students in the selected sections.').
  694:                     '</p>';
  695:             }
  696:         }
  697:         $Str.= '<p>'
  698:               .'<a href="/adm/statistics?reportSelected=student_assessment">'
  699:               .&mt('Return to the chart').'</a>'
  700:               .'</p>';
  701:         $r->print($Str);
  702:         $r->rflush();
  703:         return;
  704:     }
  705: 
  706:     $Str .= '<h2>'.&mt('Select One Student').'</h2>'
  707:            .'<p>'.&mt("Click on a student's name or username to view their chart.").'</p>'
  708:            .&Apache::loncommon::start_data_table()
  709:            .&Apache::loncommon::start_data_table_header_row();
  710:     foreach my $field (@Fields) {
  711:         $Str .= '<th><a href="/adm/statistics?'.
  712:             'reportSelected=student_assessment&amp;'.
  713:             'selectstudent=1&amp;'.
  714:             'sort='.$field.'">'.&mt($field).
  715:             '</a></th>';
  716:     }
  717:     $Str .= &Apache::loncommon::end_data_table_header_row();
  718:     #
  719:     foreach my $student (@Students) { # @Students is a package variable
  720:         my $sname = $student->{'username'}.':'.$student->{'domain'};
  721:         $Str .= &Apache::loncommon::start_data_table_row();
  722:         #
  723:         foreach my $field (@Fields) {
  724:             $Str .= '<td>';
  725:             if ($field eq 'fullname' || $field eq 'username') {
  726:                 $Str .= '<a href="/adm/statistics?reportSelected=';
  727:                 $Str .= &escape('student_assessment');
  728:                 $Str .= '&amp;sort='.&escape($env{'form.sort'});
  729:                 $Str .= '&amp;SelectedStudent=';
  730:                 $Str .= &escape($sname).'">';
  731:                 $Str .= $student->{$field};
  732:                 $Str .= '</a>';
  733:             } elsif ($field eq 'status') {
  734:                 $Str .= &mt($student->{$field});
  735:             } else {
  736:                 if ($student->{$field} eq 'none') {
  737:                     $Str .= &mt('none')
  738:                 } else {
  739:                     $Str .= $student->{$field};
  740:                 }
  741:             }
  742:             $Str .= '</td>';
  743:         }
  744:         $Str .= &Apache::loncommon::end_data_table_row();
  745:     }
  746:     $Str .= &Apache::loncommon::end_data_table();
  747:     #
  748:     $r->print($Str);
  749:     $r->rflush();
  750:     #
  751:     return;
  752: }
  753: 
  754: 
  755: 
  756: sub CreateMainMenu {
  757:     #
  758:     # Define menu data
  759:     my @reports = (
  760: 	    {categorytitle => 'Statistics and Analyses',
  761:          items => [
  762:             {url => '/adm/statistics?reportSelected=problem_statistics',
  763: 			 permission => 'F',
  764:              icon => 'document-open.png',
  765:              linktext => ('Overall Problem Statistics'),
  766:              linktitle => ('Student performance statistics on all problems.')},
  767:        
  768:             {url => '/adm/statistics?reportSelected=problem_analysis',
  769: 			 permission => 'F',
  770:              icon => 'prob_ana.png',
  771:              linktext => ('Detailed Problem Analysis'),
  772:              linktitle => ('Detailed statistics and graphs of student performance on problems.')},
  773:          ]},
  774:         {categorytitle => 'Plots',
  775:          items => [
  776:             {url => '/adm/statistics?reportSelected=submissiontime_analysis',
  777: 			 permission => 'F',
  778:              icon => 'subtimpl.png',
  779:              linktext => ('Submission Time Plots'),
  780:              linktitle => ('Display and analysis of submission times on assessments.')},
  781:       
  782:             {url => '/adm/statistics?reportSelected=correct_problems_plot',
  783: 			 permission => 'F',
  784:              icon => 'coprplot.png',
  785:              linktext => ('Correct Problems Plot'),
  786:              linktitle => ('Display a histogram of student performance in the course.')},
  787:          ]},
  788:         {categorytitle => 'Reports',
  789:          items => [
  790:             {url => '/adm/statistics?reportSelected=student_submission_reports',
  791: 			 permission => 'F',
  792:              icon => 'edit-copy.png',
  793:              linktext => ('Student Submission Reports'),
  794:              linktitle => ('Prepare reports of student submissions.')},
  795:                     
  796:             {url => '/adm/statistics?reportSelected=survey_reports',
  797: 			 permission => 'F',
  798:              icon => 'survey_rep.png',
  799: 			 linktext => ('Survey Reports'),
  800:              linktitle => ('Prepare reports on survey results.')},
  801:          ]});
  802:     
  803: return &Apache::lonhtmlcommon::generate_menu(@reports);
  804:  
  805: }
  806: 
  807: 
  808: 
  809: sub handler {
  810:     my $r=shift;
  811:     my $c = $r->connection();
  812:     #
  813:     # Check for access
  814:     if (! &Apache::lonnet::allowed('vgr',$env{'request.course.id'})) {
  815:         $env{'user.error.msg'}=
  816:             $r->uri.":vgr:0:0:Cannot view grades for complete course";
  817:         if (! &Apache::lonnet::allowed('vgr',
  818:                       $env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
  819:             $env{'user.error.msg'}=
  820:                 $r->uri.":vgr:0:0:Cannot view grades with given role";
  821:             return HTTP_NOT_ACCEPTABLE;
  822:         }
  823:     }
  824:     #
  825:     # Send the header
  826:     &Apache::loncommon::no_cache($r);
  827:     &Apache::loncommon::content_type($r,'text/html');
  828:     $r->send_http_header;
  829:     if ($r->header_only) { return OK; }
  830:     #
  831:     # Extract form elements from query string
  832:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  833:                                             ['sort','reportSelected',
  834:                                              'SelectedStudent']);
  835:     my $GoToPage = $env{'form.reportSelected'};
  836:  
  837:     #
  838:     # Give the LON-CAPA page header
  839:     my $style = <<ENDSTYLE;
  840: <style type="text/css">
  841:     ul.sub_studentans { list-style-type: none }
  842:     ul.sub_correctans { list-style-type: none }
  843:     tr.even           { background-color: \#CCCCCC }
  844:     td.essay          { border: 1px solid gray; }
  845: </style>
  846: ENDSTYLE
  847: 
  848:     my $head_extra = $style;
  849:     if (($env{'form.reportSelected'} eq 'student_submission_reports') &&
  850:         ($env{'form.renderprob'})) {
  851:         my @Symbs = &Apache::lonstathelpers::get_selected_symbs('problemchoice');
  852:         if (scalar(@Symbs) == 1) {
  853:             $head_extra .= &Apache::loncommon::css_links($Symbs[0]);
  854:         }
  855:     } elsif ($env{'form.reportSelected'} eq 'submissiontime_analysis') {
  856:         my ($navmap,$current_problem) =
  857:             &Apache::lonsubmissiontimeanalysis::get_current_problem();
  858:         if (ref($current_problem) eq 'HASH') {
  859:             my $symb = $current_problem->{'symb'};
  860:             if ($symb) {
  861:                 $head_extra .= &Apache::loncommon::css_links($symb);
  862:             }
  863:         }
  864:     } elsif (($env{'form.reportSelected'} eq 'problem_analysis') &&
  865:               ($env{'form.show_prob'})) {
  866:         my $problem_types = &Apache::lonproblemanalysis::analyzable_types();
  867:         my ($navmap,$current_problem) =
  868:             &Apache::lonproblemanalysis::get_current_problem($problem_types);
  869:         if (ref($current_problem) eq 'HASH') {
  870:             my $symb = $current_problem->{'symb'};
  871:             my $res = $current_problem->{'resource'};
  872:             if ($symb) {
  873:                 $head_extra .= &Apache::loncommon::css_links($symb);
  874:             }
  875:         }
  876:     }
  877:     $r->print(&Apache::loncommon::start_page('Course Statistics and Charts',
  878: 					     $head_extra));
  879:     $r->rflush();
  880:     # 
  881:     # Either print out a menu for them or send them to a report
  882:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  883:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/statistics',
  884:                                             title=>'Statistics',
  885:                                             text =>'Statistics',
  886:                                             faq=>139,
  887:                                             bug=>'Statistics and Charts'});
  888:     if ($GoToPage eq '') {
  889:         $r->print(&Apache::lonhtmlcommon::breadcrumbs('Statistics Main Page'));
  890:         &Apache::lonquickgrades::startGradeScreen($r,'statistics');
  891:         $r->print(&CreateMainMenu());
  892:     } else {
  893:     #
  894:         if (! &Apache::lonmysql::verify_sql_connection()) {
  895:             my $serveradmin = $r->dir_config('lonAdmEMail');
  896:             $r->print('<p class="LC_error">'.
  897:                       &mt('Unable to connect to database!').
  898:                       '</p>');
  899:             $r->print('<p>'
  900:                      .&mt('Please notify the server administrator [_1]',
  901:                          ,'<b>'.$serveradmin.'</b>')
  902:                      .'</p>');
  903:             $r->print('<p>'.
  904:                       &mt('Course Statistics and Charts cannot be '.
  905:                           'retrieved until the database is restarted. '.
  906:                           'Your data is intact but cannot be displayed '.
  907:                           'at this time.').'</p>');
  908:             $r->print(&Apache::loncommon::end_page());
  909:             return;
  910:         }
  911:         #
  912:         # Clean out the caches
  913:         if (exists($env{'form.ClearCache'})) {
  914:             &Apache::loncoursedata::delete_caches($env{'request.course.id'});
  915:         }
  916:         #
  917:         # Begin form output
  918:         $r->print('<form name="Statistics" ');
  919:         if ($GoToPage eq 'student_submission_reports') {
  920:             $r->print('onsubmit="return checkanon();" ');
  921:         }
  922:         $r->print('method="post" action="/adm/statistics">');
  923:         $r->rflush();
  924:         $r->print('<input type="hidden" name="reportSelected" value="'.
  925:                   $GoToPage.'" />');
  926:         if($GoToPage eq 'activitylog') {
  927: #        &Apache::lonproblemstatistics::Activity();
  928:         } elsif($GoToPage eq 'problem_statistics') {
  929:             &Apache::lonhtmlcommon::add_breadcrumb
  930:                 ({href=>'/adm/statistics?reportselected=problem_statistics',
  931:                   text=>'Overall Problem Statistics'});
  932:             &Apache::lonproblemstatistics::BuildProblemStatisticsPage($r,$c);
  933:         } elsif($GoToPage eq 'problem_analysis') {
  934:             &Apache::lonhtmlcommon::add_breadcrumb
  935:                 ({href=>'/adm/statistics?reportselected=problem_analysis',
  936:                   text=>'Detailed Problem Analysis'});
  937:             &Apache::lonproblemanalysis::BuildProblemAnalysisPage($r,$c);
  938:         } elsif($GoToPage eq 'submissiontime_analysis') {
  939:             &Apache::lonhtmlcommon::add_breadcrumb
  940:                 ({href=>
  941:                       '/adm/statistics?reportselected=submissiontime_analysis',
  942:                       text=>'Submission Time Plots'});
  943:             &Apache::lonsubmissiontimeanalysis::BuildSubmissionTimePage($r,$c);
  944:         } elsif($GoToPage eq 'student_submission_reports') {
  945:             &Apache::lonhtmlcommon::add_breadcrumb
  946:                 ({href=>
  947:                   '/adm/statistics?reportselected=student_submission_reports',
  948:                   text=>'Student Submission Reports'});
  949:             &Apache::lonstudentsubmissions::BuildStudentSubmissionsPage($r,$c);
  950:         } elsif($GoToPage eq 'survey_reports') {
  951:             &Apache::lonhtmlcommon::add_breadcrumb
  952:                 ({href=>
  953:                   '/adm/statistics?reportselected=survey_reports',
  954:                   text=>'Survey Reports'});
  955:             &Apache::lonsurveyreports::BuildSurveyReportsPage($r,$c);
  956:         } elsif($GoToPage eq 'correct_problems_plot') {
  957:             &Apache::lonhtmlcommon::add_breadcrumb
  958:                 ({href=>'/adm/statistics?reportselected=correct_problems_plot',
  959:                   text=>'Correct Problems Plot'});
  960:             &Apache::loncorrectproblemplot::BuildCorrectProblemsPage($r,$c);
  961:         } elsif($GoToPage eq 'student_assessment') {
  962:             &Apache::lonhtmlcommon::clear_breadcrumbs();
  963:             &Apache::lonhtmlcommon::add_breadcrumb
  964:                 ({href=>'/adm/statistics?reportselected=student_assessment',
  965:                   text=>'Chart'});
  966:             &Apache::lonstudentassessment::BuildStudentAssessmentPage($r,$c);
  967:         } elsif($GoToPage eq 'grading_analysis') {
  968:             &Apache::lonhtmlcommon::add_breadcrumb
  969:                 ({href=>'/adm/statistics?reportselected=grading_anaylsis',
  970:                   text=>'Grading Analysis'});
  971:             &Apache::longradinganalysis::build_grading_analysis_page($r,$c);
  972: 	}
  973:         #
  974:         $r->print("</form>\n");
  975:     }
  976:     &Apache::lonquickgrades::endGradeScreen($r);
  977:     $r->print(&Apache::loncommon::end_page());
  978:     $r->rflush();
  979:     #
  980:     return OK;
  981: }
  982: 
  983: 1;
  984: 
  985: __END__
  986: 
  987: =pod
  988: 
  989: =head1 NAME
  990: 
  991: lonstatistics
  992: 
  993: =head1 SYNOPSIS
  994: 
  995: Main handler for statistics and chart.
  996: 
  997: This is part of the LearningOnline Network with CAPA project
  998: described at http://www.lon-capa.org.
  999: 
 1000: 
 1001: =head1 PACKAGE VARIABLES
 1002: 
 1003: =over
 1004: 
 1005: =item @FullClasslist The full classlist
 1006: 
 1007: =item @Students The students we are concerned with for this invocation
 1008: 
 1009: =item @Sections The sections available in this class
 1010: 
 1011: =item @Groups The groups available in the class
 1012: 
 1013: =item $curr_student The student currently being examined
 1014: 
 1015: =item $prev_student The student previous in the classlist
 1016: 
 1017: =item $next_student The student next in the classlist
 1018: 
 1019: =back
 1020: 
 1021: =head1 SUBROUTINES
 1022: 
 1023: =over
 1024: 
 1025: =item &clear_classlist_variables()
 1026: 
 1027: undef the following package variables:
 1028: 
 1029: =over 4
 1030: 
 1031: =item * @FullClasslist
 1032: 
 1033: =item * @Students
 1034: 
 1035: =item * @Sections
 1036: 
 1037: =item * @Groups
 1038: 
 1039: =item * %StudentData
 1040: 
 1041: =item * @StudentDataOrder
 1042: 
 1043: =item * @SelectedStudentData
 1044: 
 1045: =item * $curr_student
 1046: 
 1047: =item * $prev_student
 1048: 
 1049: =item * $next_student
 1050: 
 1051: =back
 1052: 
 1053: =item &PrepareClasslist()
 1054: 
 1055: Build up the classlist information.  The classlist information is kept in
 1056: the following package variables:
 1057: 
 1058: =over 4 
 1059: 
 1060: =item * @FullClasslist
 1061: 
 1062: =item * @Students
 1063: 
 1064: =item * @Sections
 1065: 
 1066: =item * @Groups 
 1067: 
 1068: =item * %StudentData
 1069: 
 1070: =item * @SelectedStudentData
 1071: 
 1072: =item * $curr_student
 1073: 
 1074: =item * $prev_student
 1075: 
 1076: =item * $next_student
 1077: 
 1078: =back
 1079: 
 1080: $curr_student, $prev_student, and $next_student may not be defined, depending
 1081: upon the calling context.
 1082: 
 1083: =item get_selected_sections()
 1084: 
 1085: Returns an array of the selected sections
 1086: 
 1087: =item get_selected_groups()
 1088:                                                                                     
 1089: Returns an array of the selected groups
 1090: 
 1091: =item &section_and_enrollment_description()
 1092: 
 1093: Returns a string describing the currently selected section(s), group(s) and 
 1094: access status.  
 1095: 
 1096: Inputs: mode = 'plaintext' or 'localized'  (defaults to 'localized')
 1097:     'plaintext' is used for example in Excel spreadsheets.
 1098: Returns: scalar description string.
 1099: 
 1100: =item section_or_group_text()
 1101: 
 1102: =item get_students()
 1103: 
 1104: Returns a list of the selected students
 1105: 
 1106: =item &current_student()
 1107: 
 1108: Returns a pointer to a hash containing data about the currently
 1109: selected student.
 1110: 
 1111: =item &previous_student()
 1112: 
 1113: Returns a pointer to a hash containing data about the student prior
 1114: in the list of students.  Or something. 
 1115: 
 1116: =item &next_student()
 1117: 
 1118: Returns a pointer to a hash containing data about the next student
 1119: to be viewed. 
 1120: 
 1121: =item &StudentDataSelect($elementname,$status,$numvisible,$selected)
 1122: 
 1123: Returns html for a selection box allowing the user to choose one (or more) 
 1124: of the fields of student data available (fullname, username, id, section, etc)
 1125: 
 1126: =over 4
 1127: 
 1128: =item * $elementname The name of the HTML form element
 1129: 
 1130: =item * $status 'multiple' or 'single' selection box
 1131: 
 1132: =item * $numvisible The number of options to be visible
 1133: 
 1134: =back
 1135: 
 1136: =item &get_selected_maps($elementname)
 1137: 
 1138: Input: Name of the <select> form element used to specify the maps.
 1139: 
 1140: Returns: Array of symbs of selected maps or the description 'all'.
 1141:    If form.$elementname does not exist, 'all' is returned.
 1142: 
 1143: =item &selected_sequences_with_assessments()
 1144: 
 1145: Retrieve the sequences which were selected by the user to show.  
 1146: 
 1147: Input: $mode: scalar.  Either 'selected' or 'all'.  If not specified,
 1148:     'selected' is used.
 1149: 
 1150: Returns: an array containing a navmap object and navmap resources, 
 1151:     or an array containing a scalar with an error message.
 1152: 
 1153: =item &map_select($elementname,$status,$numvisible,$restriction) 
 1154: 
 1155: Returns html for a selection box allowing the user to choose one (or more) 
 1156: of the sequences in the course.  The values of the sequences are the symbs.
 1157: If the top sequence is selected, the value 'top' will result.
 1158: 
 1159: =over 4
 1160: 
 1161: =item * $elementname The name of the HTML form element
 1162: 
 1163: =item * $status 'multiple' or 'single' selection box
 1164: 
 1165: =item * $numvisible The number of options to be visible
 1166: 
 1167: =back
 1168: 
 1169: =item &SectionSelect($elementname,$status,$numvisible) 
 1170: 
 1171: Returns html for a selection box allowing the user to choose one (or more) 
 1172: of the sections in the course.  
 1173: 
 1174: Uses the package variables @Sections
 1175: 
 1176: =over 4
 1177: 
 1178: =item * $elementname The name of the HTML form element
 1179: 
 1180: =item * $status 'multiple' or 'single' selection box
 1181: 
 1182: =item * $numvisible The number of options to be visible
 1183: 
 1184: =back
 1185: 
 1186: =item &GroupSelect($elementname,$status,$numvisible)
 1187:                                                                                     
 1188: Returns html for a selection box allowing the user to choose one (or more)
 1189: of the groups in the course.
 1190:                                                                                     
 1191: Uses the package variables @Groups
 1192: 
 1193: =over 4
 1194:                                                                                     
 1195: =item * $elementname The name of the HTML form element
 1196:                                                                                     
 1197: =item * $status 'multiple' or 'single' selection box
 1198:                                                                                     
 1199: =item * $numvisible The number of options to be visible
 1200:                                                                                     
 1201: =back
 1202: 
 1203: =item CreateMainMenu()
 1204: 
 1205: =back
 1206: 
 1207: =cut
 1208: 

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