File:  [LON-CAPA] / loncom / interface / lonstatistics.pm
Revision 1.53: download - view: text, annotated - select for diffs
Tue Oct 22 16:30:34 2002 UTC (21 years, 7 months ago) by minaeibi
Branches: MAIN
CVS tags: HEAD
Fixed bug #752
Add total points to each homework set totaL

    1: # The LearningOnline Network with CAPA
    2: # (Publication Handler
    3: #
    4: # $Id: lonstatistics.pm,v 1.53 2002/10/22 16:30:34 minaeibi 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:     }
  249:     my @order = sort { $cache->{$a.$sortBy} cmp $cache->{$b.$sortBy} ||
  250:                        $cache->{$a.':fullname'} cmp $cache->{$b.':fullname'} } 
  251:                 @sorted1Students;
  252: 
  253:     return \@order;
  254: }
  255: 
  256: =pod
  257: 
  258: =item &SpaceColumns()
  259: 
  260: Determines the width of all the columns in the chart.  It is based on
  261: the max of the data for that column and its header.
  262: 
  263: =over 4
  264: 
  265: Input: $students, $studentInformation, $headings, $ChartDB
  266: 
  267: $students: An array pointer to a list of students (username:domain)
  268: 
  269: $studentInformatin: The type of data for the student information.  It is
  270: used as part of the key in $CacheData.
  271: 
  272: $headings: The name of the student information columns.
  273: 
  274: $ChartDB: The name of the cache database which is opened for read/write.
  275: 
  276: Output: None - All data stored in cache.
  277: 
  278: =back
  279: 
  280: =cut
  281: 
  282: sub SpaceColumns {
  283:     my ($students,$studentInformation,$headings,$cache)=@_;
  284: 
  285:     # Initialize Lengths
  286:     for(my $index=0; $index<(scalar @$headings); $index++) {
  287:         my @titleLength=split(//,$headings->[$index]);
  288:         $cache->{$studentInformation->[$index].':columnWidth'}=
  289:             scalar @titleLength;
  290:     }
  291: 
  292:     foreach my $name (@$students) {
  293:         foreach (@$studentInformation) {
  294:             my @dataLength=split(//,$cache->{$name.':'.$_});
  295:             my $length=(scalar @dataLength);
  296:             if($length > $cache->{$_.':columnWidth'}) {
  297:                 $cache->{$_.':columnWidth'}=$length;
  298:             }
  299:         }
  300:     }
  301: 
  302:     return;
  303: }
  304: 
  305: sub PrepareData {
  306:     my ($c, $cacheDB, $studentInformation, $headings,$r)=@_;
  307: 
  308:     # Test for access to the cache data
  309:     my $courseID=$ENV{'request.course.id'};
  310:     my $isRecalculate=0;
  311:     if(defined($ENV{'form.Recalculate'})) {
  312:         $isRecalculate=1;
  313:     }
  314: 
  315:     my $isCached = &Apache::loncoursedata::TestCacheData($cacheDB, 
  316:                                                          $isRecalculate);
  317:     if($isCached < 0) {
  318:         return "Unable to tie hash to db file.";
  319:     }
  320: 
  321:     # Download class list information if not using cached data
  322:     my %cache;
  323:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
  324:         return "Unable to tie hash to db file.";
  325:     }
  326: 
  327: #    if(!$isCached) {
  328:         my $processTopResourceMapReturn=
  329:             &Apache::loncoursedata::ProcessTopResourceMap(\%cache, $c);
  330:         if($processTopResourceMapReturn ne 'OK') {
  331:             untie(%cache);
  332:             return $processTopResourceMapReturn;
  333:         }
  334:  #   }
  335: 
  336:     if($c->aborted()) {
  337:         untie(%cache);
  338:         return 'aborted'; 
  339:     }
  340: 
  341:     my $classlist=&Apache::loncoursedata::DownloadClasslist($courseID,
  342:                                                 $cache{'ClasslistTimestamp'},
  343:                                                 $c);
  344:     foreach (keys(%$classlist)) {
  345:         if(/^(con_lost|error|no_such_host)/i) {
  346:             untie(%cache);
  347:             return "Error getting student data.";
  348:         }
  349:     }
  350: 
  351:     if($c->aborted()) {
  352:         untie(%cache);
  353:         return 'aborted'; 
  354:     }
  355: 
  356:     # Active is a temporary solution, remember to change
  357:     Apache::loncoursedata::ProcessClasslist(\%cache,$classlist,$courseID,$c);
  358:     if($c->aborted()) {
  359:         untie(%cache);
  360:         return 'aborted'; 
  361:     }
  362: 
  363:     &ProcessFormData(\%cache);
  364:     my $students = &SortStudents(\%cache);
  365:     &SpaceColumns($students, $studentInformation, $headings, \%cache);
  366:     $cache{'updateTime:columnWidth'}=24;
  367: 
  368:     my $download = $cache{'download'};
  369:     my $downloadAll = $cache{'DownloadAll'};
  370:     my @allStudents=();
  371:     if($download ne 'false') {
  372:         $cache{'download'} = 'false';
  373:     } elsif($downloadAll ne 'false') {
  374:         $cache{'DownloadAll'} = 'false';
  375:         if($downloadAll eq 'sorted') {
  376:             @allStudents = @$students;
  377:         } else {
  378:             @allStudents = split(':::', $cache{'NamesOfStudents'});
  379:         }
  380:     }
  381: 
  382:     untie(%cache);
  383: 
  384:     if($download ne 'false') {
  385:         my @who = ($download);
  386:         if(&Apache::loncoursedata::DownloadStudentCourseData(\@who, 'false', 
  387:                                                              $cacheDB, 'true', 
  388:                                                              'false', $courseID,
  389:                                                              $r, $c) ne 'OK') {
  390:             return 'Stop at download individual';
  391:         }
  392:     } elsif($downloadAll ne 'false') {
  393:         if(&Apache::loncoursedata::DownloadStudentCourseData(\@allStudents, 
  394:                                                              'false', 
  395:                                                              $cacheDB, 'true', 
  396:                                                              'true', $courseID,
  397:                                                              $r, $c) ne 'OK') {
  398:             return 'Stop at download all';
  399:         }
  400:     }
  401: 
  402:     return ('OK', $students);
  403: }
  404: 
  405: sub BuildClasslist {
  406:     my ($cacheDB,$students,$studentInformation,$headings,$r)=@_;
  407: 
  408:     my %cache;
  409:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
  410:         return '<html><body>Unable to tie database.</body></html>';
  411:     }
  412: 
  413:     my $Str='';
  414:     $Str .= '<table border="0"><tr><td bgcolor="#777777">'."\n";
  415:     $Str .= '<table border="0" cellpadding="3"><tr bgcolor="#e6ffff">'."\n";
  416: 
  417:     my $displayString = '<td align="left"><a href="/adm/statistics?';
  418:     $displayString .= 'sort=LINKDATA">DISPLAYDATA&nbsp</a></td>'."\n";
  419:     $Str .= &Apache::lonhtmlcommon::CreateHeadings(\%cache, 
  420:                                                    $studentInformation,
  421:                                                    $headings, $displayString);
  422:     $Str .= '</tr>'."\n";
  423: 
  424:     my $alternate=0;
  425:     foreach (@$students) {
  426:         my ($username, $domain) = split(':', $_);
  427:         if($alternate) {
  428:             $Str .= '<tr bgcolor="#ffffe6">';
  429:         } else {
  430:             $Str .= '<tr bgcolor="#ffffc6">';
  431:         }
  432:         $alternate = ($alternate + 1) % 2;
  433:         foreach my $data (@$studentInformation) {
  434:             $Str .= '<td>';
  435:             if($data eq 'fullname') {
  436:                 $Str .= '<a href="/adm/statistics?reportSelected=';
  437:                 $Str .= &Apache::lonnet::escape('Student Assessment');
  438:                 $Str .= '&StudentAssessmentStudent=';
  439:                 $Str .= &Apache::lonnet::escape($cache{$_.':'.$data}).'">';
  440:                 $Str .= $cache{$_.':'.$data}.'&nbsp';
  441:                 $Str .= '</a>';
  442:             } elsif($data eq 'updateTime') {
  443:                 $Str .= '<a href="/adm/statistics?reportSelected=';
  444:                 $Str .= &Apache::lonnet::escape('Class list');
  445:                 $Str .= '&download='.$_.'">';
  446:                 $Str .= $cache{$_.':'.$data}.'&nbsp';
  447:                 $Str .= '&nbsp</a>';
  448:             } else {
  449:                 $Str .= $cache{$_.':'.$data}.'&nbsp';
  450:             }
  451: 
  452:             $Str .= '</td>'."\n";
  453:         }
  454:     }
  455: 
  456:     $Str .= '</tr>'."\n";
  457:     $Str .= '</table></td></tr></table>'."\n";
  458:     $r->print($Str);
  459:     $r->rflush();
  460: 
  461:     untie(%cache);
  462: 
  463:     return;
  464: }
  465: 
  466: sub CreateMainMenu {
  467:     my ($status, $reports)=@_;
  468: 
  469:     my $Str = '';
  470: 
  471:     $Str .= '<table border="0"><tbody><tr>'."\n";
  472:     $Str .= '<td></td><td></td>'."\n";
  473:     $Str .= '<td align="center"><b>Analysis Reports:</b></td>'."\n";
  474:     $Str .= '<td align="center"><b>Student Status:</b></td></tr>'."\n";
  475:     $Str .= '<tr>'."\n";
  476:     $Str .= '<td align="center"><input type="submit" name="Refresh" ';
  477:     $Str .= 'value="Refresh" /></td>'."\n";
  478:     $Str .= '<td align="center"><input type="submit" name="DownloadAll" ';
  479:     $Str .= 'value="Update All Student Data" /></td>'."\n";
  480:     $Str .= '<td align="center">';
  481:     $Str .= '<select name="reportSelected" onchange="document.';
  482:     $Str .= 'Statistics.submit()">'."\n";
  483: 
  484:     foreach (sort(keys(%$reports))) {
  485:         next if($_ eq 'reportSelected');
  486:         $Str .= '<option name="'.$_.'"';
  487:         if($reports->{'reportSelected'} eq $reports->{$_}) {
  488:             $Str .= ' selected=""';
  489:         }
  490:         $Str .= '>'.$reports->{$_}.'</option>'."\n";
  491:     }
  492:     $Str .= '</select></td>'."\n";
  493: 
  494:     $Str .= '<td align="center">';
  495:     $Str .= &Apache::lonhtmlcommon::StatusOptions($status, 'Statistics');
  496:     $Str .= '</td>'."\n";
  497: 
  498:     $Str .= '</tr></tbody></table>'."\n";
  499:     $Str .= '<hr>'."\n";
  500: 
  501:     return $Str;
  502: }
  503: 
  504: sub BuildStatistics {
  505:     my ($r)=@_;
  506: 
  507:     my $c = $r->connection;
  508:     my @studentInformation=('fullname','section','id','domain','username',
  509:                             'updateTime');
  510:     my @headings=('Full Name', 'Section', 'PID', 'Domain', 'User Name',
  511:                   'Last Updated');
  512:     my $spacing = '   '; 
  513: 
  514:     my %reports = ('classlist'          => 'Class list',
  515:                    'problem_statistics' => 'Problem Statistics',
  516:                    'student_assessment' => 'Student Assessment',
  517: 		   'percentage'         => 'Percentage Graphs',
  518: #                   'activitylog'        => 'Activity Log',
  519:                    'reportSelected'     => 'Class list');
  520: 
  521:     my %cache;
  522:     my $courseID=$ENV{'request.course.id'};
  523:     my $cacheDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
  524:                   "_$ENV{'user.domain'}_$courseID\_statistics.db";
  525: 
  526:     $r->print(&Apache::lonhtmlcommon::Title('Course Statistics and Charts'));
  527: 
  528:     my ($returnValue, $students) = &PrepareData($c, $cacheDB, 
  529:                                                 \@studentInformation, 
  530:                                                 \@headings,$r);
  531:     if($returnValue ne 'OK') {
  532:         $r->print($returnValue."\n".'</body></html>');
  533:         return OK;
  534:     }
  535:     if(!$c->aborted()) {
  536:         &Apache::loncoursedata::CheckForResidualDownload($cacheDB, 
  537:                                                          'true', 'true',
  538:                                                          $courseID,
  539:                                                          $r, $c);
  540:     }
  541: 
  542:     my $GoToPage;
  543:     if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
  544:         $GoToPage = $cache{'reportSelected'};
  545:         $reports{'reportSelected'} = $cache{'reportSelected'};
  546:         if(defined($cache{'reportKey'}) && 
  547:            !exists($reports{$cache{'reportKey'}}) && 
  548:            $cache{'reportKey'} ne 'false') {
  549:             $reports{$cache{'reportKey'}} = $cache{'reportSelected'};
  550:         }
  551: 
  552:         if(defined($cache{'OptionResponses'})) {
  553:             $reports{'problem_analysis'} = 'Option Response Analysis';
  554:         }
  555: 
  556:         $r->print('<form name="Statistics" ');
  557:         $r->print('method="post" action="/adm/statistics">');
  558:         $r->print(&CreateMainMenu($cache{'Status'}, \%reports));
  559:         $r->rflush();
  560:         untie(%cache);
  561:     } else {
  562:         $r->print('<html><body>Unable to tie database.</body></html>');
  563:         return OK;
  564:     }
  565: 
  566:     if($GoToPage eq 'Activity Log') {
  567:         &Apache::lonproblemstatistics::Activity();
  568:     } elsif($GoToPage eq 'Problem Statistics') {
  569:         &Apache::lonproblemstatistics::BuildProblemStatisticsPage($cacheDB, 
  570:                                                                   $students, 
  571:                                                                   $courseID, 
  572:                                                                   $c,$r);
  573:     } elsif($GoToPage eq 'Option Response Analysis') {
  574:         &Apache::lonproblemanalysis::BuildProblemAnalysisPage($cacheDB, $r);
  575:     } elsif($GoToPage eq 'Student Assessment') {
  576:         &Apache::lonstudentassessment::BuildStudentAssessmentPage($cacheDB,
  577:                                                           $students,
  578:                                                           $courseID,
  579:                                                           'Statistics',
  580:                                                           \@headings,
  581:                                                           $spacing,
  582:                                                           \@studentInformation,
  583:                                                           $r, $c);
  584:     } elsif($GoToPage eq 'Analyze') {
  585:         &Apache::lonproblemanalysis::BuildAnalyzePage($cacheDB, $students, 
  586:                                                       $courseID, $r);
  587:     } elsif($GoToPage eq 'DoDiffGraph' || $GoToPage eq 'PercentWrongGraph') {
  588:         my $courseDescription = $ENV{'course.'.$courseID.'.description'};
  589:         $courseDescription =~ s/\ /"_"/eg;
  590:         &Apache::lonproblemstatistics::BuildGraphicChart($GoToPage, $cacheDB,
  591:                                                          $courseDescription,
  592:                                                          $students, $courseID,
  593:                                                          $r, $c);
  594:     } elsif($GoToPage eq 'Class list') {
  595:         &BuildClasslist($cacheDB, $students, \@studentInformation,
  596:                         \@headings, $r);
  597:     } elsif($GoToPage eq 'Percentage Graphs') {
  598: 	&Apache::lonpercentage::BuildPercentageGraph($cacheDB, $students,
  599: 						     $courseID, $c, $r);
  600:     }
  601: 
  602:     $r->print('</form>'."\n");
  603:     $r->print("\n".'</body>'."\n".'</html>');
  604:     $r->rflush();
  605: 
  606:     return OK;
  607: }
  608: 
  609: # ================================================================ Main Handler
  610: 
  611: sub handler {
  612:     my $r=shift;
  613: 
  614: #    $jr = $r;
  615: 
  616:     my $loaderror=&Apache::lonnet::overloaderror($r);
  617:     if ($loaderror) { return $loaderror; }
  618:     $loaderror=
  619:        &Apache::lonnet::overloaderror($r,
  620:          $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
  621:     if ($loaderror) { return $loaderror; }
  622: 
  623:     unless(&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
  624:         $ENV{'user.error.msg'}=
  625:         $r->uri.":vgr:0:0:Cannot view grades for complete course";
  626:         return HTTP_NOT_ACCEPTABLE; 
  627:     }
  628: 
  629:     # Set document type for header only
  630:     if($r->header_only) {
  631:         if ($ENV{'browser.mathml'}) {
  632:             $r->content_type('text/xml');
  633:         } else {
  634:             $r->content_type('text/html');
  635:         }
  636:         &Apache::loncommon::no_cache($r);
  637:         $r->send_http_header;
  638:         return OK;
  639:     }
  640: 
  641:     unless($ENV{'request.course.fn'}) {
  642: 	my $requrl=$r->uri;
  643:         $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
  644:         return HTTP_NOT_ACCEPTABLE; 
  645:     }
  646: 
  647:     $r->content_type('text/html');
  648:     $r->send_http_header;
  649: 
  650:     &BuildStatistics($r);
  651: 
  652:     return OK;
  653: }
  654: 1;
  655: __END__
  656: 

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