File:  [LON-CAPA] / loncom / interface / lonstatistics.pm
Revision 1.55.2.1: download - view: text, annotated - select for diffs
Mon Jan 13 20:34:24 2003 UTC (21 years, 4 months ago) by albertel
Branches: version_0_6
CVS tags: version_0_6_2
- backport 1.57 and 1.58

    1: # The LearningOnline Network with CAPA
    2: # (Publication Handler
    3: #
    4: # $Id: lonstatistics.pm,v 1.55.2.1 2003/01/13 20:34:24 albertel Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: # (Navigate problems for statistical reports
   29: # YEAR=2001
   30: # 5/5,7/9,7/25/1,8/11,9/13,9/26,10/5,10/9,10/22,10/26 Behrouz Minaei
   31: # 11/1,11/4,11/16,12/14,12/16,12/18,12/20,12/31 Behrouz Minaei
   32: # YEAR=2002
   33: # 1/22,2/1,2/6,2/25,3/2,3/6,3/17,3/21,3/22,3/26,4/7,5/6 Behrouz Minaei
   34: # 5/12,5/14,5/15,5/19,5/26,7/16,25/7,29/7  Behrouz Minaei
   35: #
   36: ###
   37: 
   38: package Apache::lonstatistics;
   39: 
   40: use strict;
   41: use Apache::Constants qw(:common :http);
   42: use Apache::lonnet();
   43: use Apache::lonhomework;
   44: use Apache::loncommon;
   45: use Apache::loncoursedata;
   46: use Apache::lonhtmlcommon;
   47: use Apache::lonproblemanalysis;
   48: use Apache::lonproblemstatistics;
   49: use Apache::lonstudentassessment;
   50: use Apache::lonpercentage;
   51: use HTML::TokeParser;
   52: use GDBM_File;
   53: 
   54: 
   55: sub CheckFormElement {
   56:     my ($cache, $ENVName, $cacheName, $default)=@_;
   57: 
   58:     if(defined($ENV{'form.'.$ENVName})) {
   59:         $cache->{$cacheName} = $ENV{'form.'.$ENVName};
   60:     } elsif(!defined($cache->{$cacheName})) {
   61:         $cache->{$cacheName} = $default;
   62:     }
   63: 
   64:     return;
   65: }
   66: 
   67: sub ProcessFormData{
   68:     my ($cache)=@_;
   69: 
   70:     $cache->{'reportKey'} = 'false';
   71: 
   72:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
   73:                                             ['sort','download',
   74:                                              'reportSelected',
   75:                                              'StudentAssessmentStudent',
   76:                                              'ProblemStatisticsSort']);
   77:     &CheckFormElement($cache, 'Status', 'Status', 'Active');
   78:     &CheckFormElement($cache, 'postdata', 'reportSelected', 'Class list');
   79:     &CheckFormElement($cache, 'reportSelected', 'reportSelected', 
   80:                       'Class list');
   81:     $cache->{'reportSelected'} = 
   82:         &Apache::lonnet::unescape($cache->{'reportSelected'});
   83:     &CheckFormElement($cache, 'DownloadAll', 'DownloadAll', 'false');
   84:     &CheckFormElement($cache, 'sort', 'sort', 'fullname');
   85:     &CheckFormElement($cache, 'download', 'download', 'false');
   86:     &CheckFormElement($cache, 'StatisticsMaps', 
   87:                       'StatisticsMaps', 'All Maps');
   88:     &CheckFormElement($cache, 'StatisticsProblemSelect',
   89: 		      'StatisticsProblemSelect', 'All Problems');
   90:     &CheckFormElement($cache, 'StatisticsPartSelect',
   91: 		      'StatisticsPartSelect', 'All Parts');
   92:     if(defined($ENV{'form.Section'})) {
   93:         my @sectionsSelected = (ref($ENV{'form.Section'}) ?
   94:                                @{$ENV{'form.Section'}} :
   95:                                 ($ENV{'form.Section'}));
   96:         $cache->{'sectionsSelected'} = join(':', @sectionsSelected);
   97:     } elsif(!defined($cache->{'sectionsSelected'})) {
   98:         $cache->{'sectionsSelected'} = $cache->{'sectionList'};
   99:     }
  100: 
  101:     # student assessment
  102:     if(defined($ENV{'form.CreateStudentAssessment'}) ||
  103:        defined($ENV{'form.NextStudent'}) ||
  104:        defined($ENV{'form.PreviousStudent'})) {
  105:         $cache->{'reportSelected'} = 'Student Assessment';
  106:     }
  107:     if(defined($ENV{'form.NextStudent'})) {
  108:         $cache->{'StudentAssessmentMove'} = 'next';
  109:     } elsif(defined($ENV{'form.PreviousStudent'})) {
  110:         $cache->{'StudentAssessmentMove'} = 'previous';
  111:     } else {
  112:         $cache->{'StudentAssessmentMove'} = 'selected';
  113:     }
  114:     &CheckFormElement($cache, 'StudentAssessmentStudent', 
  115:                       'StudentAssessmentStudent', 'All Students');
  116:     $cache->{'StudentAssessmentStudent'} = 
  117:         &Apache::lonnet::unescape($cache->{'StudentAssessmentStudent'});
  118:     &CheckFormElement($cache, 'DefaultColumns', 'DefaultColumns', 'false');
  119: 
  120:     # Problem analysis
  121:     &CheckFormElement($cache, 'Interval', 'Interval', '1');
  122: 
  123:     # ProblemStatistcs
  124:     &CheckFormElement($cache, 'DisplayCSVFormat',
  125:                       'DisplayFormat', 'Display Table Format');
  126:     &CheckFormElement($cache, 'ProblemStatisticsAscend',
  127:                       'ProblemStatisticsAscend', 'Ascending');
  128:     &CheckFormElement($cache, 'ProblemStatisticsSort',
  129:                       'ProblemStatisticsSort', 'Homework Sets Order');
  130:     &CheckFormElement($cache, 'DisplayLegend', 'DisplayLegend', 
  131: 		      'Hide Legend');
  132:     &CheckFormElement($cache, 'SortProblems', 'SortProblems', 
  133:                       'Sort Within Sequence');
  134: 
  135:     # Search only form elements
  136:     my @headingColumns=();
  137:     my @sequenceColumns=();
  138:     my $foundColumn = 0;
  139:     if(defined($ENV{'form.ReselectColumns'})) {
  140:         my @reselected = (ref($ENV{'form.ReselectColumns'}) ? 
  141:                           @{$ENV{'form.ReselectColumns'}}
  142:                           : ($ENV{'form.ReselectColumns'}));
  143:         foreach (@reselected) {
  144:             if(/HeadingColumn/) {
  145:                 push(@headingColumns, $_);
  146:                 $foundColumn = 1;
  147:             } elsif(/SequenceColumn/) {
  148:                 push(@sequenceColumns, $_);
  149:                 $foundColumn = 1;
  150:             }
  151:         }
  152:     }
  153: 
  154:     $cache->{'reportKey'} = 'false';
  155:     if($cache->{'reportSelected'} eq 'Analyze') {
  156:         $cache->{'reportKey'} = 'Analyze';
  157:     } elsif($cache->{'reportSelected'} eq 'DoDiffGraph') {
  158:         $cache->{'reportKey'} = 'DoDiffGraph';
  159:     } elsif($cache->{'reportSelected'} eq 'PercentWrongGraph') {
  160:         $cache->{'reportKey'} = 'PercentWrongGraph';
  161:     }
  162: 
  163:     if(defined($ENV{'form.DoDiffGraph'})) {
  164:         $cache->{'reportSelected'} = 'DoDiffGraph';
  165:         $cache->{'reportKey'} = 'DoDiffGraph';
  166:     } elsif(defined($ENV{'form.PercentWrongGraph'})) {
  167:         $cache->{'reportSelected'} = 'PercentWrongGraph';
  168:         $cache->{'reportKey'} = 'PercentWrongGraph';
  169:     }
  170: 
  171:     foreach (keys(%ENV)) {
  172:         if(/form\.Analyze/) {
  173:             $cache->{'reportSelected'} = 'Analyze';
  174:             $cache->{'reportKey'} = 'Analyze';
  175:             my $data;
  176:             (undef, $data)=split(':::', $_);
  177:             $cache->{'AnalyzeInfo'}=$data;
  178:         } elsif(/form\.HeadingColumn/) {
  179:             my $value = $_;
  180:             $value =~ s/form\.//;
  181:             push(@headingColumns, $value);
  182:             $foundColumn=1;
  183:         } elsif(/form\.SequenceColumn/) {
  184:             my $value = $_;
  185:             $value =~ s/form\.//;
  186:             push(@sequenceColumns, $value);
  187:             $foundColumn=1;
  188:         }
  189:     }
  190: 
  191:     if($foundColumn) {
  192:         $cache->{'HeadingsFound'} = join(':', @headingColumns);
  193:         $cache->{'SequencesFound'} = join(':', @sequenceColumns);;
  194:     }
  195:     if(!defined($cache->{'HeadingsFound'}) || 
  196:        $cache->{'DefaultColumns'} ne 'false') {
  197:         $cache->{'HeadingsFound'}='HeadingColumnFull Name';
  198:     }
  199:     if(!defined($cache->{'SequencesFound'}) ||
  200:        $cache->{'DefaultColumns'} ne 'false') {
  201:         $cache->{'SequencesFound'}='All Sequences';
  202:     }
  203:     $cache->{'DefaultColumns'} = 'false';
  204: 
  205:     return;
  206: }
  207: 
  208: =pod
  209: 
  210: =item &SortStudents()
  211: 
  212: Determines which students to display and in which order.  Which are 
  213: displayed are determined by their status(active/expired).  The order
  214: is determined by the sort button pressed (default to username).  The
  215: type of sorting is username, lastname, or section.
  216: 
  217: =over 4
  218: 
  219: Input: $students, $CacheData
  220: 
  221: $students: A array pointer to a list of students (username:domain)
  222: 
  223: $CacheData: A pointer to the hash tied to the cached data
  224: 
  225: Output: \@order
  226: 
  227: @order: An ordered list of students (username:domain)
  228: 
  229: =back
  230: 
  231: =cut
  232: 
  233: sub SortStudents {
  234:     my ($cache)=@_;
  235: 
  236:     my @students = split(':::',$cache->{'NamesOfStudents'});
  237:     my @sorted1Students=();
  238:     foreach (@students) {
  239:         if($cache->{'Status'} eq 'Any' || 
  240:            $cache->{$_.':Status'} eq $cache->{'Status'}) {
  241:             push(@sorted1Students, $_);
  242:         }
  243:     }
  244: 
  245:     my $sortBy = '';
  246:     if(defined($cache->{'sort'})) {
  247:         $sortBy = ':'.$cache->{'sort'};
  248:     } else {
  249:         $sortBy = ':fullname';
  250:     }
  251:     my @order = sort { lc($cache->{$a.$sortBy}) cmp lc($cache->{$b.$sortBy}) ||
  252:                        lc($cache->{$a.':fullname'}) cmp lc($cache->{$b.':fullname'}) } 
  253:                 @sorted1Students;
  254: 
  255:     return \@order;
  256: }
  257: 
  258: =pod
  259: 
  260: =item &SpaceColumns()
  261: 
  262: Determines the width of all the columns in the chart.  It is based on
  263: the max of the data for that column and its header.
  264: 
  265: =over 4
  266: 
  267: Input: $students, $studentInformation, $headings, $ChartDB
  268: 
  269: $students: An array pointer to a list of students (username:domain)
  270: 
  271: $studentInformatin: The type of data for the student information.  It is
  272: used as part of the key in $CacheData.
  273: 
  274: $headings: The name of the student information columns.
  275: 
  276: $ChartDB: The name of the cache database which is opened for read/write.
  277: 
  278: Output: None - All data stored in cache.
  279: 
  280: =back
  281: 
  282: =cut
  283: 
  284: sub SpaceColumns {
  285:     my ($students,$studentInformation,$headings,$cache)=@_;
  286: 
  287:     # Initialize Lengths
  288:     for(my $index=0; $index<(scalar @$headings); $index++) {
  289:         my @titleLength=split(//,$headings->[$index]);
  290:         $cache->{$studentInformation->[$index].':columnWidth'}=
  291:             scalar @titleLength;
  292:     }
  293: 
  294:     foreach my $name (@$students) {
  295:         foreach (@$studentInformation) {
  296:             my @dataLength=split(//,$cache->{$name.':'.$_});
  297:             my $length=(scalar @dataLength);
  298:             if($length > $cache->{$_.':columnWidth'}) {
  299:                 $cache->{$_.':columnWidth'}=$length;
  300:             }
  301:         }
  302:     }
  303: 
  304:     return;
  305: }
  306: 
  307: sub PrepareData {
  308:     my ($c, $cacheDB, $studentInformation, $headings,$r)=@_;
  309: 
  310:     # Test for access to the cache data
  311:     my $courseID=$ENV{'request.course.id'};
  312:     my $isRecalculate=0;
  313:     if(defined($ENV{'form.Recalculate'})) {
  314:         $isRecalculate=1;
  315:     }
  316: 
  317:     my $isCached = &Apache::loncoursedata::TestCacheData($cacheDB,
  318:                                                          $isRecalculate);
  319:     if($isCached < 0) {
  320:         return "Unable to tie hash to db file.";
  321:     }
  322: 
  323:     # Download class list information if not using cached data
  324:     my %cache;
  325:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
  326:         return "Unable to tie hash to db file.";
  327:     }
  328: 
  329: #    if(!$isCached) {
  330:         my $processTopResourceMapReturn=
  331:             &Apache::loncoursedata::ProcessTopResourceMap(\%cache, $c);
  332:         if($processTopResourceMapReturn ne 'OK') {
  333:             untie(%cache);
  334:             return $processTopResourceMapReturn;
  335:         }
  336:  #   }
  337: 
  338:     if($c->aborted()) {
  339:         untie(%cache);
  340:         return 'aborted'; 
  341:     }
  342: 
  343:     my $classlist=&Apache::loncoursedata::DownloadClasslist($courseID,
  344:                                                 $cache{'ClasslistTimestamp'},
  345:                                                 $c);
  346:     foreach (keys(%$classlist)) {
  347:         if(/^(con_lost|error|no_such_host)/i) {
  348:             untie(%cache);
  349:             return "Error getting student data.";
  350:         }
  351:     }
  352: 
  353:     if($c->aborted()) {
  354:         untie(%cache);
  355:         return 'aborted'; 
  356:     }
  357: 
  358:     # Active is a temporary solution, remember to change
  359:     Apache::loncoursedata::ProcessClasslist(\%cache,$classlist,$courseID,$c);
  360:     if($c->aborted()) {
  361:         untie(%cache);
  362:         return 'aborted'; 
  363:     }
  364: 
  365:     &ProcessFormData(\%cache);
  366:     my $students = &SortStudents(\%cache);
  367:     &SpaceColumns($students, $studentInformation, $headings, \%cache);
  368:     $cache{'updateTime:columnWidth'}=24;
  369: 
  370:     my $download = $cache{'download'};
  371:     my $downloadAll = $cache{'DownloadAll'};
  372:     my @allStudents=();
  373:     if($download ne 'false') {
  374:         $cache{'download'} = 'false';
  375:     } elsif($downloadAll ne 'false') {
  376:         $cache{'DownloadAll'} = 'false';
  377:         if($downloadAll eq 'sorted') {
  378:             @allStudents = @$students;
  379:         } else {
  380:             @allStudents = split(':::', $cache{'NamesOfStudents'});
  381:         }
  382:     }
  383: 
  384:     untie(%cache);
  385: 
  386:     if($download ne 'false') {
  387:         my @who = ($download);
  388:         if(&Apache::loncoursedata::DownloadStudentCourseData(\@who, 'false',
  389:                                                              $cacheDB, 'true',
  390:                                                              'false', $courseID,
  391:                                                              $r, $c) ne 'OK') {
  392:             return 'Stop at download individual';
  393:         }
  394:     } elsif($downloadAll ne 'false') {
  395:         if(&Apache::loncoursedata::DownloadStudentCourseData(\@allStudents,
  396:                                                              'false',
  397:                                                              $cacheDB, 'true',
  398:                                                              'true', $courseID,
  399:                                                              $r, $c) ne 'OK') {
  400:             return 'Stop at download all';
  401:         }
  402:     }
  403: 
  404:     return ('OK', $students);
  405: }
  406: 
  407: sub BuildClasslist {
  408:     my ($cacheDB,$students,$studentInformation,$headings,$r)=@_;
  409: 
  410:     my %cache;
  411:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
  412:         return '<html><body>Unable to tie database.</body></html>';
  413:     }
  414: 
  415: #    my $Ptr = '';
  416: #    $Ptr .= '<table border="0"><tbody>';
  417: #    $Ptr .= '<tr><td align="right"><b>Select Sections</b>';
  418: #    $Ptr .= '</td>'."\n";
  419: #    $Ptr .= '<td align="left">'."\n";
  420: #    my @sectionsSelected = split(':',$cache{'sectionsSelected'});
  421: #    my @sections = split(':',$cache{'sectionList'});
  422: #    $Ptr .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections,
  423: #                                                          \@sectionsSelected,
  424: #                                                          'Statistics');
  425: #    $Ptr .= '</td></tr></table><br>';
  426: #    $r->print($Ptr);
  427: #    $r->rflush();
  428: #    my %mySections = ();
  429: #    foreach (@sections) { $mySections{$_} = 'True'; }
  430: #    $r->print("<br>$cache{'sectionsSelected'}<br>");
  431: 
  432:     my $Str='';
  433:     $Str .= '<table border="0"><tr><td bgcolor="#777777">'."\n";
  434:     $Str .= '<table border="0" cellpadding="3"><tr bgcolor="#e6ffff">'."\n";
  435: 
  436:     my $displayString = '<td align="left"><a href="/adm/statistics?';
  437:     $displayString .= 'sort=LINKDATA">DISPLAYDATA&nbsp</a></td>'."\n";
  438:     $Str .= &Apache::lonhtmlcommon::CreateHeadings(\%cache,
  439:                                                    $studentInformation,
  440:                                                    $headings, $displayString);
  441:     $Str .= '</tr>'."\n";
  442: 
  443:     my $alternate=0;
  444:     foreach (@$students) {
  445: #        if ($mySections{$cache{$_.':'.'section'}} ne 'True') {next;}
  446:         my ($username, $domain) = split(':', $_);
  447:         if($alternate) {
  448:             $Str .= '<tr bgcolor="#ffffe6">';
  449:         } else {
  450:             $Str .= '<tr bgcolor="#ffffc6">';
  451:         }
  452:         $alternate = ($alternate + 1) % 2;
  453:         foreach my $data (@$studentInformation) {
  454:             $Str .= '<td>';
  455:             if($data eq 'fullname') {
  456:                 $Str .= '<a href="/adm/statistics?reportSelected=';
  457:                 $Str .= &Apache::lonnet::escape('Student Assessment');
  458:                 $Str .= '&StudentAssessmentStudent=';
  459:                 $Str .= &Apache::lonnet::escape($cache{$_.':'.$data}).'">';
  460:                 $Str .= $cache{$_.':'.$data}.'&nbsp';
  461:                 $Str .= '</a>';
  462:             } elsif($data eq 'updateTime') {
  463:                 $Str .= '<a href="/adm/statistics?reportSelected=';
  464:                 $Str .= &Apache::lonnet::escape('Class list');
  465:                 $Str .= '&download='.$_.'">';
  466:                 $Str .= $cache{$_.':'.$data}.'&nbsp';
  467:                 $Str .= '&nbsp</a>';
  468:             } else {
  469:                 $Str .= $cache{$_.':'.$data}.'&nbsp';
  470:             }
  471: 
  472:             $Str .= '</td>'."\n";
  473:         }
  474:     }
  475: 
  476:     $Str .= '</tr>'."\n";
  477:     $Str .= '</table></td></tr></table>'."\n";
  478:     $r->print($Str);
  479:     $r->rflush();
  480: 
  481:     untie(%cache);
  482: 
  483:     return;
  484: }
  485: 
  486: sub CreateMainMenu {
  487:     my ($status, $reports)=@_;
  488: 
  489:     my $Str = '';
  490: 
  491:     $Str .= '<table border="0"><tbody><tr>'."\n";
  492:     $Str .= '<td></td><td></td>'."\n";
  493:     $Str .= '<td align="center"><b>Select a Report</b></td>'."\n";
  494:     $Str .= '<td align="center"><b>Student Status</b></td></tr>'."\n";
  495:     $Str .= '<tr>'."\n";
  496:     $Str .= '<td align="center"><input type="submit" name="Refresh" ';
  497:     $Str .= 'value="Refresh" /></td>'."\n";
  498:     $Str .= '<td align="center"><input type="submit" name="DownloadAll" ';
  499:     $Str .= 'value="Update All Student Data" /></td>'."\n";
  500:     $Str .= '<td align="center">';
  501:     $Str .= '<select name="reportSelected" onchange="document.';
  502:     $Str .= 'Statistics.submit()">'."\n";
  503: 
  504:     foreach (sort(keys(%$reports))) {
  505:         next if($_ eq 'reportSelected');
  506:         $Str .= '<option name="'.$_.'"';
  507:         if($reports->{'reportSelected'} eq $reports->{$_}) {
  508:             $Str .= ' selected=""';
  509:         }
  510:         $Str .= '>'.$reports->{$_}.'</option>'."\n";
  511:     }
  512:     $Str .= '</select></td>'."\n";
  513: 
  514:     $Str .= '<td align="center">';
  515:     $Str .= &Apache::lonhtmlcommon::StatusOptions($status, 'Statistics');
  516:     $Str .= '</td>'."\n";
  517: 
  518:     $Str .= '</tr></tbody></table>'."\n";
  519:     $Str .= '<hr>'."\n";
  520: 
  521:     return $Str;
  522: }
  523: 
  524: sub BuildStatistics {
  525:     my ($r)=@_;
  526: 
  527:     my $c = $r->connection;
  528:     my @studentInformation=('fullname','section','id','domain','username',
  529:                             'updateTime');
  530:     my @headings=('Full Name', 'Section', 'PID', 'Domain', 'User Name',
  531:                   'Last Updated');
  532:     my $spacing = '   ';
  533: 
  534:     my %reports = ('classlist'          => 'Class list',
  535:                    'problem_statistics' => 'Problem Statistics',
  536:                    'student_assessment' => 'Student Assessment',
  537: 		   'percentage'         => 'Correct-problems Plot',
  538: #                   'activitylog'        => 'Activity Log',
  539:                    'reportSelected'     => 'Class list');
  540: 
  541:     my %cache;
  542:     my $courseID=$ENV{'request.course.id'};
  543:     my $cacheDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
  544:                   "_$ENV{'user.domain'}_$courseID\_statistics.db";
  545: 
  546:     $r->print(&Apache::lonhtmlcommon::Title('Course Statistics and Charts'));
  547: 
  548:     my ($returnValue, $students) = &PrepareData($c, $cacheDB,
  549:                                                 \@studentInformation,
  550:                                                 \@headings,$r);
  551:     if($returnValue ne 'OK') {
  552:         $r->print($returnValue."\n".'</body></html>');
  553:         return OK;
  554:     }
  555:     if(!$c->aborted()) {
  556:         &Apache::loncoursedata::CheckForResidualDownload($cacheDB,
  557:                                                          'true', 'true',
  558:                                                          $courseID,
  559:                                                          $r, $c);
  560:     }
  561: 
  562:     my $GoToPage;
  563:     if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
  564:         $GoToPage = $cache{'reportSelected'};
  565:         $reports{'reportSelected'} = $cache{'reportSelected'};
  566:         if(defined($cache{'reportKey'}) &&
  567:            !exists($reports{$cache{'reportKey'}}) &&
  568:            $cache{'reportKey'} ne 'false') {
  569:             $reports{$cache{'reportKey'}} = $cache{'reportSelected'};
  570:         }
  571: 
  572:         if(defined($cache{'OptionResponses'})) {
  573:             $reports{'problem_analysis'} = 'Option Response Analysis';
  574:         }
  575: 
  576:         $r->print('<form name="Statistics" ');
  577:         $r->print('method="post" action="/adm/statistics">');
  578:         $r->print(&CreateMainMenu($cache{'Status'}, \%reports));
  579:         $r->rflush();
  580:         untie(%cache);
  581:     } else {
  582:         $r->print('<html><body>Unable to tie database.</body></html>');
  583:         return OK;
  584:     }
  585: 
  586:     if($GoToPage eq 'Activity Log') {
  587:         &Apache::lonproblemstatistics::Activity();
  588:     } elsif($GoToPage eq 'Problem Statistics') {
  589:         &Apache::lonproblemstatistics::BuildProblemStatisticsPage($cacheDB,
  590:                                                                   $students,
  591:                                                                   $courseID,
  592:                                                                   $c,$r);
  593:     } elsif($GoToPage eq 'Option Response Analysis') {
  594:         &Apache::lonproblemanalysis::BuildProblemAnalysisPage($cacheDB, $r);
  595:     } elsif($GoToPage eq 'Student Assessment') {
  596:         &Apache::lonstudentassessment::BuildStudentAssessmentPage($cacheDB,
  597:                                                           $students,
  598:                                                           $courseID,
  599:                                                           'Statistics',
  600:                                                           \@headings,
  601:                                                           $spacing,
  602:                                                           \@studentInformation,
  603:                                                           $r, $c);
  604:     } elsif($GoToPage eq 'Analyze') {
  605:         &Apache::lonproblemanalysis::BuildAnalyzePage($cacheDB, $students,
  606:                                                       $courseID, $r);
  607:     } elsif($GoToPage eq 'DoDiffGraph' || $GoToPage eq 'PercentWrongGraph') {
  608:         my $courseDescription = $ENV{'course.'.$courseID.'.description'};
  609:         $courseDescription =~ s/\ /"_"/eg;
  610:         &Apache::lonproblemstatistics::BuildGraphicChart($GoToPage, $cacheDB,
  611:                                                          $courseDescription,
  612:                                                          $students, $courseID,
  613:                                                          $r, $c);
  614:     } elsif($GoToPage eq 'Class list') {
  615:         &BuildClasslist($cacheDB, $students, \@studentInformation,
  616:                         \@headings, $r);
  617:     } elsif($GoToPage eq 'Correct-problems Plot') {
  618: 	&Apache::lonpercentage::BuildPercentageGraph($cacheDB, $students,
  619: 						     $courseID, $c, $r);
  620:     }
  621: 
  622:     $r->print('</form>'."\n");
  623:     $r->print("\n".'</body>'."\n".'</html>');
  624:     $r->rflush();
  625: 
  626:     return OK;
  627: }
  628: 
  629: # ================================================================ Main Handler
  630: 
  631: sub handler {
  632:     my $r=shift;
  633: 
  634: #    $jr = $r;
  635: 
  636:     my $loaderror=&Apache::lonnet::overloaderror($r);
  637:     if ($loaderror) { return $loaderror; }
  638:     $loaderror=
  639:        &Apache::lonnet::overloaderror($r,
  640:          $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
  641:     if ($loaderror) { return $loaderror; }
  642: 
  643:     unless(&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
  644:         $ENV{'user.error.msg'}=
  645:         $r->uri.":vgr:0:0:Cannot view grades for complete course";
  646:         return HTTP_NOT_ACCEPTABLE;
  647:     }
  648: 
  649:     # Set document type for header only
  650:     if($r->header_only) {
  651:         if ($ENV{'browser.mathml'}) {
  652:             $r->content_type('text/xml');
  653:         } else {
  654:             $r->content_type('text/html');
  655:         }
  656:         &Apache::loncommon::no_cache($r);
  657:         $r->send_http_header;
  658:         return OK;
  659:     }
  660: 
  661:     unless($ENV{'request.course.fn'}) {
  662: 	my $requrl=$r->uri;
  663:         $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
  664:         return HTTP_NOT_ACCEPTABLE;
  665:     }
  666: 
  667:     $r->content_type('text/html');
  668:     $r->send_http_header;
  669: 
  670:     &BuildStatistics($r);
  671: 
  672:     return OK;
  673: }
  674: 1;
  675: __END__
  676: 

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