File:  [LON-CAPA] / loncom / interface / lonstatistics.pm
Revision 1.74: download - view: text, annotated - select for diffs
Tue Jun 3 18:10:33 2003 UTC (21 years ago) by matthew
Branches: MAIN
CVS tags: conference_2003, HEAD
Remove mention of correct problems plot and option response analysis.

    1: # The LearningOnline Network with CAPA
    2: #
    3: # $Id: lonstatistics.pm,v 1.74 2003/06/03 18:10:33 matthew 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: =pod
   32: 
   33: =head1 NAME
   34: 
   35: lonstatistics
   36: 
   37: =head1 SYNOPSIS
   38: 
   39: Main handler for statistics and chart.
   40: 
   41: =head1 PACKAGES USED
   42: 
   43:     use strict;
   44:     use Apache::Constants qw(:common :http);
   45:     use Apache::lonnet();
   46:     use Apache::lonhomework;
   47:     use Apache::loncommon;
   48:     use Apache::loncoursedata;
   49:     use Apache::lonhtmlcommon;
   50:     use Apache::lonproblemanalysis;
   51:     use Apache::lonproblemstatistics;
   52:     use Apache::lonstudentassessment;
   53:     use Apache::lonpercentage;
   54:     use Apache::lonmysql;
   55: =over 4
   56: 
   57: =cut
   58: 
   59: package Apache::lonstatistics;
   60: 
   61: use strict;
   62: use Apache::Constants qw(:common :http);
   63: use vars qw(
   64:     @FullClasslist 
   65:     @Students
   66:     @Sections 
   67:     @SelectedSections
   68:     %StudentData
   69:     @StudentDataOrder
   70:     @SelectedStudentData
   71:     $top_map 
   72:     @Sequences 
   73:     @SelectedMaps
   74:     @Assessments);
   75: 
   76: use Apache::lonnet();
   77: use Apache::lonhomework;
   78: use Apache::loncommon;
   79: use Apache::loncoursedata;
   80: use Apache::lonhtmlcommon;
   81: use Apache::lonproblemanalysis();
   82: use Apache::lonproblemstatistics();
   83: use Apache::lonstudentassessment();
   84: use Apache::lonpercentage;
   85: use Apache::lonmysql;
   86: use Time::HiRes;
   87: 
   88: #######################################################
   89: #######################################################
   90: 
   91: =pod
   92: 
   93: =item Package Variables
   94: 
   95: =item @FullClasslist The full classlist
   96: 
   97: =item @Students The students we are concerned with for this invocation
   98: 
   99: =item @Sections The sections available in this class
  100: 
  101: =item $curr_student The student currently being examined
  102: 
  103: =item $prev_student The student previous in the classlist
  104: 
  105: =item $next_student The student next in the classlist
  106: 
  107: =over
  108: 
  109: =cut 
  110: 
  111: #######################################################
  112: #######################################################
  113: #
  114: # Classlist variables
  115: #
  116: my $curr_student;
  117: my $prev_student;
  118: my $next_student;
  119: 
  120: #######################################################
  121: #######################################################
  122: 
  123: =pod
  124: 
  125: =item &clear_classlist_variables()
  126: 
  127: undef the following package variables:
  128: 
  129: =over
  130: 
  131: =item @FullClasslist
  132: 
  133: =item @Students
  134: 
  135: =item @Sections
  136: 
  137: =item @SelectedSections
  138: 
  139: =item %StudentData
  140: 
  141: =item @StudentDataOrder
  142: 
  143: =item @SelectedStudentData
  144: 
  145: =item $curr_student
  146: 
  147: =item $prev_student
  148: 
  149: =item $next_student
  150: 
  151: =back
  152: 
  153: =cut
  154: 
  155: #######################################################
  156: #######################################################
  157: sub clear_classlist_variables {
  158:     undef(@FullClasslist);
  159:     undef(@Students);
  160:     undef(@Sections);
  161:     undef(@SelectedSections);
  162:     undef(%StudentData);
  163:     undef(@SelectedStudentData);
  164:     undef($curr_student);
  165:     undef($prev_student);
  166:     undef($next_student);
  167: }
  168: 
  169: #######################################################
  170: #######################################################
  171: 
  172: =pod
  173: 
  174: =item &PrepareClasslist()
  175: 
  176: Build up the classlist information.  The classlist information is kept in
  177: the following package variables:
  178: 
  179: =over
  180: 
  181: =item @FullClasslist
  182: 
  183: =item @Students
  184: 
  185: =item @Sections
  186: 
  187: =item @SelectedSections
  188: 
  189: =item %StudentData
  190: 
  191: =item @SelectedStudentData
  192: 
  193: =item $curr_student
  194: 
  195: =item $prev_student
  196: 
  197: =item $next_student
  198: 
  199: =back
  200: 
  201: $curr_student, $prev_student, and $next_student may not be defined, depending
  202: upon the calling context.
  203: 
  204: =cut
  205: 
  206: #######################################################
  207: #######################################################
  208: sub PrepareClasslist {
  209:     my %Sections;
  210:     &clear_classlist_variables();
  211:     #
  212:     # Retrieve the classlist
  213:     my $cid  = $ENV{'request.course.id'};
  214:     my $cdom = $ENV{'course.'.$cid.'.domain'};
  215:     my $cnum = $ENV{'course.'.$cid.'.num'};
  216:     my ($classlist,$field_names) = &Apache::loncoursedata::get_classlist($cid,
  217:                                                                   $cdom,$cnum);
  218:     if (exists($ENV{'form.Section'})) {
  219:         if (ref($ENV{'form.Section'})) {
  220:             @SelectedSections = @{$ENV{'form.Section'}};
  221:         } elsif ($ENV{'form.Section'} !~ /^\s*$/) {
  222:             @SelectedSections = ($ENV{'form.Section'});
  223:         }
  224:     }
  225:     @SelectedSections = ('all') if (! @SelectedSections);
  226:     foreach (@SelectedSections) {
  227:         if ($_ eq 'all') {
  228:             @SelectedSections = ('all');
  229:         }
  230:     }
  231:     #
  232:     # Deal with instructors with restricted section access
  233:     if ($ENV{'request.course.sec'} !~ /^\s*$/) {
  234:         @SelectedSections = ($ENV{'request.course.sec'});
  235:     }
  236:     #
  237:     # Set up %StudentData
  238:     @StudentDataOrder = qw/fullname username domain id section status/;
  239:     foreach my $field (@StudentDataOrder) {
  240:         $StudentData{$field}->{'title'} = $field;
  241:         $StudentData{$field}->{'base_width'} = length($field);
  242:         $StudentData{$field}->{'width'} = 
  243:                                $StudentData{$field}->{'base_width'};
  244:     }
  245:     #
  246:     # get the status requested
  247:     my $requested_status = 'Active';
  248:     $requested_status = $ENV{'form.Status'} if (exists($ENV{'form.Status'}));
  249:     #
  250:     # Process the classlist
  251:     while (my ($student,$student_data) = each (%$classlist)) {
  252:         my $studenthash = ();
  253:         for (my $i=0; $i< scalar(@$field_names);$i++) {
  254:             my $field = $field_names->[$i];
  255:             # Store the data
  256:             $studenthash->{$field}=$student_data->[$i];
  257:             # Keep track of the width of the fields
  258:             next if (! exists($StudentData{$field}));
  259:             my $length = length($student_data->[$i]);
  260:             if ($StudentData{$field}->{'width'} < $length) {
  261:                 $StudentData{$field}->{'width'} = $length; 
  262:             }
  263:         }
  264:         push (@FullClasslist,$studenthash);
  265:         #
  266:         # Build up a list of sections
  267:         my $section = $studenthash->{'section'};
  268:         if (! defined($section) || $section =~/^\s*$/ || $section == -1) {
  269:             $studenthash->{'section'} = 'none';
  270:             $section = $studenthash->{'section'};
  271:         }
  272:         $Sections{$section}++;
  273:         #
  274:         # Only put in the list those students we are interested in
  275:         foreach my $sect (@SelectedSections) {
  276:             if ( (($sect eq 'all') || 
  277:                   ($section eq $sect)) &&
  278:                  (($studenthash->{'status'} eq $requested_status) || 
  279:                   ($requested_status eq 'Any')) 
  280:                  ){
  281:                 push (@Students,$studenthash);
  282:                 last;
  283:             }
  284:         }
  285:     }
  286:     #
  287:     # Put the consolidated section data in the right place
  288:     if ($ENV{'request.course.sec'} !~ /^\s*$/) {
  289:         @Sections = ($ENV{'request.course.sec'});
  290:     } else {
  291:         @Sections = sort {$a cmp $b} keys(%Sections);
  292:         unshift(@Sections,'all'); # Put 'all' at the front of the list
  293:     }
  294:     #
  295:     # Sort the Students
  296:     my $sortby = 'fullname';
  297:     $sortby = $ENV{'form.sort'} if (exists($ENV{'form.sort'}));
  298:     my @TmpStudents = sort { $a->{$sortby} cmp $b->{$sortby} ||
  299:                              $a->{'fullname'} cmp $b->{'fullname'} } @Students;
  300:     @Students = @TmpStudents;
  301:     # 
  302:     # Now deal with that current student thing....
  303:     $curr_student = undef;
  304:     if (exists($ENV{'form.SelectedStudent'})) {
  305:         my ($current_uname,$current_dom) = 
  306:             split(':',$ENV{'form.SelectedStudent'});
  307:         my $i;
  308:         for ($i = 0; $i<=$#Students; $i++) {
  309:             next if (($Students[$i]->{'username'} ne $current_uname) || 
  310:                      ($Students[$i]->{'domain'}   ne $current_dom));
  311:             $curr_student = $Students[$i];
  312:             last; # If we get here, we have our student.
  313:         }
  314:         if (defined($curr_student)) {
  315:             if ($i == 0) {
  316:                 $prev_student = undef;
  317:             } else {
  318:                 $prev_student = $Students[$i-1];
  319:             }
  320:             if ($i == $#Students) {
  321:                 $next_student = undef;
  322:             } else {
  323:                 $next_student = $Students[$i+1];
  324:             }
  325:         }
  326:     }
  327:     #
  328:     if (exists($ENV{'form.StudentData'})) {
  329:         if (ref($ENV{'form.StudentData'}) eq 'ARRAY') {
  330:             @SelectedStudentData = @{$ENV{'form.StudentData'}};
  331:         } else {
  332:             @SelectedStudentData = ($ENV{'form.StudentData'});
  333:         }
  334:     } else {
  335:         @SelectedStudentData = ('username');
  336:     }
  337:     foreach (@SelectedStudentData) {
  338:         if ($_ eq 'all') {
  339:             @SelectedStudentData = ('all');
  340:             last;
  341:         }
  342:     }
  343:     #
  344:     return;
  345: }
  346: 
  347: 
  348: #######################################################
  349: #######################################################
  350: 
  351: =pod
  352: 
  353: =item get_students
  354: 
  355: Returns a list of the selected students
  356: 
  357: =cut
  358: 
  359: #######################################################
  360: #######################################################
  361: sub get_students {
  362:     if (! @Students) {
  363:         &PrepareClasslist()
  364:     }
  365:     return @Students;
  366: }
  367: 
  368: #######################################################
  369: #######################################################
  370: 
  371: =pod
  372: 
  373: =item &current_student()
  374: 
  375: Returns a pointer to a hash containing data about the currently
  376: selected student.
  377: 
  378: =cut
  379: 
  380: #######################################################
  381: #######################################################
  382: sub current_student { 
  383:     return $curr_student;
  384: }
  385: 
  386: #######################################################
  387: #######################################################
  388: 
  389: =pod
  390: 
  391: =item &previous_student()
  392: 
  393: Returns a pointer to a hash containing data about the student prior
  394: in the list of students.  Or something.  
  395: 
  396: =cut
  397: 
  398: #######################################################
  399: #######################################################
  400: sub previous_student { 
  401:     return $prev_student;
  402: }
  403: 
  404: #######################################################
  405: #######################################################
  406: 
  407: =pod
  408: 
  409: =item &next_student()
  410: 
  411: Returns a pointer to a hash containing data about the next student
  412: to be viewed.
  413: 
  414: =cut
  415: 
  416: #######################################################
  417: #######################################################
  418: sub next_student { 
  419:     return $next_student;
  420: }
  421: 
  422: #######################################################
  423: #######################################################
  424: 
  425: =pod
  426: 
  427: =item &clear_sequence_variables()
  428: 
  429: =cut
  430: 
  431: #######################################################
  432: #######################################################
  433: sub clear_sequence_variables {
  434:     undef($top_map);
  435:     undef(@Sequences);
  436:     undef(@Assessments);
  437: }
  438: 
  439: #######################################################
  440: #######################################################
  441: 
  442: =pod
  443: 
  444: =item &SetSelectedMaps($elementname)
  445: 
  446: Sets the @SelectedMaps array from $ENV{'form.'.$elementname};
  447: 
  448: =cut
  449: 
  450: #######################################################
  451: #######################################################
  452: sub SetSelectedMaps {
  453:     my $elementname = shift;
  454:     if (exists($ENV{'form.'.$elementname})) {
  455:         if (ref($ENV{'form.'.$elementname})) {
  456:             @SelectedMaps = @{$ENV{'form.'.$elementname}};
  457:         } else {
  458:             @SelectedMaps = ($ENV{'form.'.$elementname});
  459:         }
  460:     } else {
  461:         @SelectedMaps = ('all');
  462:     }
  463: }
  464: 
  465: 
  466: #######################################################
  467: #######################################################
  468: 
  469: =pod
  470: 
  471: =item &Sequences_with_Assess()
  472: 
  473: Returns an array containing the subset of @Sequences which contain
  474: assessments.
  475: 
  476: =cut
  477: 
  478: #######################################################
  479: #######################################################
  480: sub Sequences_with_Assess {
  481:     my @Sequences_to_Show;
  482:     foreach my $map_symb (@SelectedMaps) {
  483:         foreach my $sequence (@Sequences) {
  484:             next if ($sequence->{'symb'} ne $map_symb && $map_symb ne 'all');
  485:             next if ($sequence->{'num_assess'} < 1);
  486:             push (@Sequences_to_Show,$sequence);
  487:         }
  488:     }
  489:     return @Sequences_to_Show;
  490: }
  491: 
  492: #######################################################
  493: #######################################################
  494: 
  495: =pod
  496: 
  497: =item &PrepareCourseData($r)
  498: 
  499: =cut
  500: 
  501: #######################################################
  502: #######################################################
  503: sub PrepareCourseData {
  504:     my ($r) = @_;
  505:     &clear_sequence_variables();
  506:     my ($top,$sequences,$assessments) = 
  507:         &Apache::loncoursedata::get_sequence_assessment_data();
  508:     if (! defined($top) || ! ref($top)) {
  509:         # There has been an error, better report it
  510:         &Apache::lonnet::logthis('top is undefined');
  511:         return;
  512:     }
  513:     $top_map = $top if (ref($top));
  514:     @Sequences = @{$sequences} if (ref($sequences) eq 'ARRAY');
  515:     @Assessments = @{$assessments} if (ref($assessments) eq 'ARRAY');
  516:     #
  517:     # Compute column widths
  518:     foreach my $seq (@Sequences) {
  519:         my $name_length = length($seq->{'title'});
  520:         my $num_parts = $seq->{'num_assess_parts'};
  521:         #
  522:         # The number of columns needed for the summation text: 
  523:         #    " 1/5" = 1+3 columns, " 10/99" = 1+5 columns
  524:         my $sum_length = 1+1+2*(length($num_parts));
  525:         my $num_col = $num_parts+$sum_length;
  526:         if ($num_col < $name_length) {
  527:             $num_col = $name_length;
  528:         }
  529:         $seq->{'base_width'} = $name_length;
  530:         $seq->{'width'} = $num_col;
  531:     }
  532:     return;
  533: }
  534: 
  535: #######################################################
  536: #######################################################
  537: 
  538: =pod
  539: 
  540: =item &log_sequence($sequence,$recursive,$padding)
  541: 
  542: Write data about the sequence to a logfile.  If $recursive is not
  543: undef the data is written recursively.  $padding is used for recursive
  544: calls.
  545: 
  546: =cut
  547: 
  548: #######################################################
  549: #######################################################
  550: sub log_sequence {
  551:     my ($seq,$recursive,$padding) = @_;
  552:     $padding = '' if (! defined($padding));
  553:     if (ref($seq) ne 'HASH') {
  554:         &Apache::lonnet::logthis('log_sequence passed bad sequnce');
  555:         return;
  556:     }
  557:     &Apache::lonnet::logthis($padding.'sequence '.$seq->{'title'});
  558:     while (my($key,$value) = each(%$seq)) {
  559:         next if ($key eq 'contents');
  560:         if (ref($value) eq 'ARRAY') {
  561:             for (my $i=0;$i< scalar(@$value);$i++) {
  562:                 &Apache::lonnet::logthis($padding.$key.'['.$i.']='.
  563:                                          $value->[$i]);
  564:             }
  565:         } else {
  566:             &Apache::lonnet::logthis($padding.$key.'='.$value);
  567:         }
  568:     }
  569:     if (defined($recursive)) {
  570:         &Apache::lonnet::logthis($padding.'-'x20);
  571:         &Apache::lonnet::logthis($padding.'contains:');
  572:         foreach my $item (@{$seq->{'contents'}}) {
  573:             if ($item->{'type'} eq 'container') {
  574:                 &log_sequence($item,$recursive,$padding.'    ');
  575:             } else {
  576:                 &Apache::lonnet::logthis($padding.'title = '.$item->{'title'});
  577:                 while (my($key,$value) = each(%$item)) {
  578:                     next if ($key eq 'title');
  579:                     if (ref($value) eq 'ARRAY') {
  580:                         for (my $i=0;$i< scalar(@$value);$i++) {
  581:                             &Apache::lonnet::logthis($padding.$key.'['.$i.']='.
  582:                                                      $value->[$i]);
  583:                         }
  584:                     } else {
  585:                         &Apache::lonnet::logthis($padding.$key.'='.$value);
  586:                     }
  587:                 }
  588:             }
  589:         }
  590:         &Apache::lonnet::logthis($padding.'end contents of '.$seq->{'title'});
  591:         &Apache::lonnet::logthis($padding.'-'x20);
  592:     }
  593:     return;
  594: }
  595: 
  596: ##############################################
  597: ##############################################
  598: 
  599: =pod 
  600: 
  601: =item &StudentDataSelect($elementname,$status,$numvisible,$selected)
  602: 
  603: Returns html for a selection box allowing the user to choose one (or more) 
  604: of the fields of student data available (fullname, username, id, section, etc)
  605: 
  606: =over 4
  607: 
  608: =item $elementname The name of the HTML form element
  609: 
  610: =item $status 'multiple' or 'single' selection box
  611: 
  612: =item $numvisible The number of options to be visible
  613: 
  614: =back
  615: 
  616: =cut
  617: 
  618: ##############################################
  619: ##############################################
  620: sub StudentDataSelect {
  621:     my ($elementname,$status,$numvisible)=@_;
  622:     if ($numvisible < 1) {
  623:         return;
  624:     }
  625:     #
  626:     # Build the form element
  627:     my $Str = "\n";
  628:     $Str .= '<select name="'.$elementname.'" ';
  629:     if ($status ne 'single') {
  630:         $Str .= 'multiple="true" ';
  631:     }
  632:     $Str .= 'size="'.$numvisible.'" >'."\n";
  633:     #
  634:     # Deal with 'all'
  635:     $Str .= '    <option value="all" ';
  636:     foreach (@SelectedStudentData) {
  637:         if ($_ eq 'all') {
  638:             $Str .= 'selected ';
  639:             last;
  640:         }
  641:     }
  642:     $Str .= ">all</option>\n";
  643:     #
  644:     # Loop through the student data fields
  645:     foreach my $item (@StudentDataOrder) {
  646:         $Str .= '    <option value="'.$item.'" ';
  647:         foreach (@SelectedStudentData) {
  648:             if ($item eq $_ ) {
  649:                 $Str .= 'selected ';
  650:                 last;
  651:             }
  652:         }
  653:         $Str .= '>'.$item."</option>\n";
  654:     }
  655:     $Str .= "</select>\n";
  656:     return $Str;
  657: }
  658: 
  659: ##############################################
  660: ##############################################
  661: 
  662: =pod 
  663: 
  664: =item &MapSelect($elementname,$status,$numvisible,$restriction) 
  665: 
  666: Returns html for a selection box allowing the user to choose one (or more) 
  667: of the sequences in the course.  The values of the sequences are the symbs.
  668: If the top sequence is selected, the value 'top' will result.
  669: 
  670: =over 4
  671: 
  672: =item $elementname The name of the HTML form element
  673: 
  674: =item $status 'multiple' or 'single' selection box
  675: 
  676: =item $numvisible The number of options to be visible
  677: 
  678: =item $restriction Code reference to subroutine which returns true or 
  679: false.  The code must expect a reference to a sequence data structure.
  680: 
  681: =back
  682: 
  683: =cut
  684: 
  685: ##############################################
  686: ##############################################
  687: sub MapSelect {
  688:     my ($elementname,$status,$numvisible,$restriction)=@_;
  689:     if ($numvisible < 1) {
  690:         return;
  691:     }
  692:     #
  693:     # Set up array of selected items
  694:     &SetSelectedMaps($elementname);
  695:     #
  696:     # Set up the restriction call
  697:     if (! defined($restriction)) {
  698:         $restriction = sub { 1; };
  699:     }
  700:     #
  701:     # Build the form element
  702:     my $Str = "\n";
  703:     $Str .= '<select name="'.$elementname.'" ';
  704:     if ($status ne 'single') {
  705:         $Str .= 'multiple="true" ';
  706:     }
  707:     $Str .= 'size="'.$numvisible.'" >'."\n";
  708:     #
  709:     # Deal with 'all'
  710:     foreach (@SelectedMaps) {
  711:         if ($_ eq 'all') {
  712:             @SelectedMaps = ('all');
  713:             last;
  714:         }
  715:     }
  716:     #
  717:     # Put in option for 'all'
  718:     $Str .= '    <option value="all" ';
  719:     foreach (@SelectedMaps) {
  720:         if ($_ eq 'all') {
  721:             $Str .= 'selected ';
  722:             last;
  723:         }
  724:     }
  725:     $Str .= ">all</option>\n";
  726:     #
  727:     # Loop through the sequences
  728:     foreach my $seq (@Sequences) {
  729:         next if (! $restriction->($seq));
  730:         $Str .= '    <option value="'.$seq->{'symb'}.'" ';
  731:         foreach (@SelectedMaps) {
  732:             if ($seq->{'symb'} eq $_) {
  733:                 $Str .= 'selected ';
  734:                 last;
  735:             }
  736:         }
  737:         $Str .= '>'.$seq->{'title'}."</option>\n";
  738:     }
  739:     $Str .= "</select>\n";
  740:     return $Str;
  741: }
  742: 
  743: ##############################################
  744: ##############################################
  745: 
  746: =pod 
  747: 
  748: =item &SectionSelect($elementname,$status,$numvisible) 
  749: 
  750: Returns html for a selection box allowing the user to choose one (or more) 
  751: of the sections in the course.  
  752: 
  753: Uses the package variables @Sections and @SelectedSections
  754: =over 4
  755: 
  756: =item $elementname The name of the HTML form element
  757: 
  758: =item $status 'multiple' or 'single' selection box
  759: 
  760: =item $numvisible The number of options to be visible
  761: 
  762: =back
  763: 
  764: =cut
  765: 
  766: ##############################################
  767: ##############################################
  768: sub SectionSelect {
  769:     my ($elementname,$status,$numvisible)=@_;
  770:     if ($numvisible < 1) {
  771:         return;
  772:     }
  773:     #
  774:     # Make sure we have the data we need to continue
  775:     if (! @Sections) {
  776:         &PrepareClasslist()
  777:     }
  778:     #
  779:     # Build the form element
  780:     my $Str = "\n";
  781:     $Str .= '<select name="'.$elementname.'" ';
  782:     if ($status ne 'single') {
  783:         $Str .= 'multiple="true" ';
  784:     }
  785:     $Str .= 'size="'.$numvisible.'" >'."\n";
  786:     #
  787:     # Loop through the sequences
  788:     foreach my $s (@Sections) {
  789:         $Str .= '    <option value="'.$s.'" ';
  790:         foreach (@SelectedSections) {
  791:             if ($s eq $_) {
  792:                 $Str .= 'selected ';
  793:                 last;
  794:             }
  795:         }
  796:         $Str .= '>'.$s."</option>\n";
  797:     }
  798:     $Str .= "</select>\n";
  799:     return $Str;
  800: }
  801: 
  802: ##################################################
  803: ##################################################
  804: sub DisplayClasslist {
  805:     my ($r)=@_;
  806:     #
  807:     my @Fields = ('fullname','username','domain','id','section');
  808:     #
  809:     my $Str='';
  810:     $Str .= '<table border="0"><tr><td bgcolor="#777777">'."\n";
  811:     $Str .= '<table border="0" cellpadding="3"><tr bgcolor="#e6ffff">'."\n";
  812:     foreach my $field (@Fields) {
  813:         $Str .= '<th><a href="/adm/statistics?reportSelected=classlist&sort='.$field.'">'.$field.
  814:             '</a></th>';
  815:     }
  816:     $Str .= '</tr>'."\n";
  817:     #
  818:     my $alternate = 0;
  819:     foreach my $student (@Students) { # @Students is a package variable
  820:         my $sname = $student->{'username'}.':'.$student->{'domain'};
  821:         if($alternate) {
  822:             $Str .= '<tr bgcolor="#ffffe6">';
  823:         } else {
  824:             $Str .= '<tr bgcolor="#ffffc6">';
  825:         }
  826:         $alternate = ($alternate + 1) % 2;
  827:         #
  828:         foreach my $field (@Fields) {
  829:             $Str .= '<td>';
  830:             if ($field eq 'fullname') {
  831:                 $Str .= '<a href="/adm/statistics?reportSelected=';
  832:                 $Str .= &Apache::lonnet::escape('student_assessment');
  833:                 $Str .= '&sort='.&Apache::lonnet::escape($ENV{'form.sort'});
  834:                 $Str .= '&SelectedStudent=';
  835:                 $Str .= &Apache::lonnet::escape($sname).'">';
  836:                 $Str .= $student->{$field}.'&nbsp';
  837:                 $Str .= '</a>';
  838:             } else {
  839:                 $Str .= $student->{$field};
  840:             }
  841:             $Str .= '</td>';
  842:         }
  843:         $Str .= "</tr>\n";
  844:     }
  845:     $Str .= '</table></td></tr></table>'."\n";
  846:     #
  847:     $r->print($Str);
  848:     $r->rflush();
  849:     #
  850:     return;
  851: }
  852: 
  853: ##############################################
  854: ##############################################
  855: sub CreateMainMenu {
  856:     my ($status,$reports,$current)=@_;
  857:     #
  858:     my $Str = '';
  859:     #
  860:     $Str .= '<table border="0"><tbody><tr>'."\n";
  861:     $Str .= '<td></td>'."\n";
  862:     $Str .= '<td align="center"><b>Select a Report</b></td>'."\n";
  863:     $Str .= '<td></td>'."\n";
  864:     $Str .= '<td></td>'."\n";
  865:     $Str .= '<tr>'."\n";
  866:     #
  867:     $Str .= '<td align="center">'.
  868:         '<input type="submit" name="Refresh" value="Update Display" />'.
  869:             "</td>\n";
  870:     #
  871:     $Str .= '<td align="center">';
  872:     $Str .= '<select name="reportSelected" >'."\n";
  873:     foreach (sort(keys(%$reports))) {
  874:         $Str .= '<option value="'.$_.'"';
  875:         if($current eq $_) {
  876:             $Str .= ' selected';
  877:         }
  878:         $Str .= '>'.$reports->{$_}.'</option>'."\n";
  879:     }
  880:     $Str .= '</select></td>'."\n";
  881:     #
  882:     $Str .= '<td>'.('&nbsp;'x30).'</td>';
  883:     $Str .= '<td align="center">'.
  884:         '<input type="submit" name="ClearCache" value="Clear Caches" />'.
  885:             "</td>\n";
  886:     $Str .= '</tr></tbody></table>'."\n";
  887:     $Str .= '<hr>'."\n";
  888:     #
  889:     return $Str;
  890: }
  891: 
  892: ##############################################
  893: ##############################################
  894: sub handler {
  895:     my $r=shift;
  896:     my $c = $r->connection();
  897:     #
  898:     # Check for overloading
  899:     my $loaderror=&Apache::lonnet::overloaderror($r);
  900:     if ($loaderror) { return $loaderror; }
  901:     $loaderror=
  902:        &Apache::lonnet::overloaderror($r,
  903:          $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
  904:     if ($loaderror) { return $loaderror; }
  905:     #
  906:     # Check for access
  907:     if (! &Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
  908:         $ENV{'user.error.msg'}=
  909:             $r->uri.":vgr:0:0:Cannot view grades for complete course";
  910:         if (! &Apache::lonnet::allowed('vgr',
  911:                       $ENV{'request.course.id'}.'/'.$ENV{'request.course.sec'})) {
  912:             $ENV{'user.error.msg'}=
  913:                 $r->uri.":vgr:0:0:Cannot view grades with given role";
  914:             return HTTP_NOT_ACCEPTABLE;
  915:         }
  916:     }
  917:     #
  918:     # Set document type for header only
  919:     if($r->header_only) {
  920:         if ($ENV{'browser.mathml'}) {
  921:             $r->content_type('text/xml');
  922:         } else {
  923:             $r->content_type('text/html');
  924:         }
  925:         &Apache::loncommon::no_cache($r);
  926:         $r->send_http_header;
  927:         return OK;
  928:     }
  929:     #
  930:     # Send the header
  931:     $r->content_type('text/html');
  932:     $r->send_http_header;
  933:     #
  934:     # Extract form elements from query string
  935:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  936:                                             ['sort','reportSelected',
  937:                                              'SelectedStudent']);
  938:     if (! exists($ENV{'form.reportSelected'})) {
  939:         $ENV{'form.reportSelected'} = 'student_assessment';
  940:     }
  941:     #
  942:     # Give the LON-CAPA page header
  943:     $r->print(&Apache::lonhtmlcommon::Title('Course Statistics and Charts'));
  944:     $r->rflush();
  945:     #
  946:     if (! &Apache::lonmysql::verify_sql_connection()) {
  947:         my $serveradmin = $r->dir_config('lonAdmEMail');
  948:         $r->print(<<END);
  949: <h2><font color="Red">Unable to connect to database!</font></h2>
  950: <p>
  951: Please notify the server administrator <b>$serveradmin</b>.
  952: </p><p>
  953: Course Statistics and Charts cannot be retrieved until the database is
  954: restarted.  Your data is intact but cannot be displayed at this time.
  955: </p>
  956: </body>
  957: </html>
  958: END
  959:         return;
  960:     }
  961:     #
  962:     # Clean out the caches
  963:     if (exists($ENV{'form.ClearCache'})) {
  964:         &Apache::loncoursedata::delete_caches($ENV{'requres.course.id'});
  965:     }
  966:     #
  967:     # Set up the statistics and chart environment
  968:     &PrepareClasslist();
  969:     &PrepareCourseData($r);
  970:     #
  971:     # Begin form output
  972:     $r->print('<form name="Statistics" ');
  973:     $r->print('method="post" action="/adm/statistics">');
  974:     #
  975:     # Print main menu
  976:     my %reports = ('classlist'          => 'Class list',
  977:                    'problem_statistics' => 'Problem Statistics',
  978:                    'student_assessment' => 'Problem Status Chart',
  979: #                   'percentage'         => 'Correct-problems Plot',
  980: #                   'option_response'    => 'Option Response Analysis',
  981: #                   'activitylog'        => 'Activity Log',
  982:                    );
  983:     $r->print(&CreateMainMenu($ENV{'form.status'},
  984:                               \%reports,$ENV{'form.reportSelected'}));
  985:     $r->rflush();
  986:     #
  987:     my $GoToPage = $ENV{'form.reportSelected'};
  988:     if($GoToPage eq 'activitylog') {
  989: #        &Apache::lonproblemstatistics::Activity();
  990:     } elsif($GoToPage eq 'problem_statistics') {
  991:         &Apache::lonproblemstatistics::BuildProblemStatisticsPage($r,$c);
  992:     } elsif($GoToPage eq 'option_response') {
  993: #        &Apache::lonproblemanalysis::BuildProblemAnalysisPage($r,$c);
  994:     } elsif($GoToPage eq 'student_assessment') {
  995:         &Apache::lonstudentassessment::BuildStudentAssessmentPage($r,$c);
  996:     } elsif($GoToPage eq 'DoDiffGraph' || $GoToPage eq 'PercentWrongGraph') {
  997: #        &Apache::lonproblemstatistics::BuildGraphicChart($r,$c);
  998:     } elsif($GoToPage eq 'classlist') {
  999:         &DisplayClasslist($r);
 1000:     } elsif($GoToPage eq 'Correct-problems Plot') {
 1001: #	&Apache::lonpercentage::BuildPercentageGraph($r,$c);
 1002:     }
 1003:     #
 1004:     $r->print("</form>\n");
 1005:     $r->print("</body>\n</html>\n");
 1006:     $r->rflush();
 1007:     #
 1008:     return OK;
 1009: }
 1010: 
 1011: 1;
 1012: 
 1013: #######################################################
 1014: #######################################################
 1015: 
 1016: =pod
 1017: 
 1018: =back
 1019: 
 1020: =cut
 1021: 
 1022: #######################################################
 1023: #######################################################
 1024: 
 1025: __END__
 1026: 

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