File:  [LON-CAPA] / loncom / interface / lonstatistics.pm
Revision 1.37: download - view: text, annotated - select for diffs
Tue Jul 30 21:31:48 2002 UTC (21 years, 11 months ago) by stredwic
Branches: MAIN
CVS tags: HEAD
Fixed the problem gathering the correct data to be used for the analysis.
The problem stemmed mostly to the correct use of the result from ssi.

    1: # The LearningOnline Network with CAPA
    2: # (Publication Handler
    3: #
    4: # $Id: lonstatistics.pm,v 1.37 2002/07/30 21:31:48 stredwic 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::lonchart;
   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:     &CheckFormElement($cache, 'Status', 'Status', 'Active');
   77:     &CheckFormElement($cache, 'postdata', 'reportSelected', 'Class list');
   78:     &CheckFormElement($cache, 'reportSelected', 'reportSelected', 
   79:                       'Class list');
   80:     $cache->{'reportSelected'} = 
   81:         &Apache::lonnet::unescape($cache->{'reportSelected'});
   82:     &CheckFormElement($cache, 'DownloadAll', 'DownloadAll', 'false');
   83:     &CheckFormElement($cache, 'sort', 'sort', 'fullname');
   84:     &CheckFormElement($cache, 'download', 'download', 'false');
   85: 
   86:     if(defined($ENV{'form.CreateStudentAssessment'}) ||
   87:        defined($ENV{'form.NextStudent'}) ||
   88:        defined($ENV{'form.PreviousStudent'})) {
   89:         $cache->{'reportSelected'} = 'Student Assessment';
   90:     }
   91:     if(defined($ENV{'form.NextStudent'})) {
   92:         $cache->{'StudentAssessmentMove'} = 'next';
   93:     } elsif(defined($ENV{'form.PreviousStudent'})) {
   94:         $cache->{'StudentAssessmentMove'} = 'previous';
   95:     } else {
   96:         $cache->{'StudentAssessmentMove'} = 'selected';
   97:     }
   98:     &CheckFormElement($cache, 'StudentAssessmentStudent', 
   99:                       'StudentAssessmentStudent', 'All Students');
  100:     $cache->{'StudentAssessmentStudent'} = 
  101:         &Apache::lonnet::unescape($cache->{'StudentAssessmentStudent'});
  102:     &CheckFormElement($cache, 'DefaultColumns', 'DefaultColumns', 'false');
  103: 
  104:     if(defined($ENV{'form.Section'})) {
  105:         my @sectionsSelected = (ref($ENV{'form.Section'}) ?
  106:                                @{$ENV{'form.Section'}} :
  107:                                 ($ENV{'form.Section'}));
  108:         $cache->{'sectionsSelected'} = join(':', @sectionsSelected);
  109:     } elsif(!defined($cache->{'sectionsSelected'})) {
  110:         $cache->{'sectionsSelected'} = $cache->{'sectionList'};
  111:     }
  112: 
  113:     my @headingColumns=();
  114:     my @sequenceColumns=();
  115:     my $foundColumn = 0;
  116:     if(defined($ENV{'form.ReselectColumns'})) {
  117:         my @reselected = (ref($ENV{'form.ReselectColumns'}) ? 
  118:                           @{$ENV{'form.ReselectColumns'}}
  119:                           : ($ENV{'form.ReselectColumns'}));
  120:         foreach (@reselected) {
  121:             if(/HeadingColumn/) {
  122:                 push(@headingColumns, $_);
  123:                 $foundColumn = 1;
  124:             } elsif(/SequenceColumn/) {
  125:                 push(@sequenceColumns, $_);
  126:                 $foundColumn = 1;
  127:             }
  128:         }
  129:     }
  130: 
  131:     $cache->{'reportKey'} = 'false';
  132:     if($cache->{'reportSelected'} eq 'Analyze') {
  133:         $cache->{'reportKey'} = 'Analyze';
  134:     }
  135: 
  136:     foreach (keys(%ENV)) {
  137:         if(/form\.Analyze/) {
  138:             $cache->{'reportSelected'} = 'Analyze';
  139:             $cache->{'reportKey'} = 'Analyze';
  140:             my $data;
  141:             (undef, $data)=split(':::', $_);
  142:             $cache->{'AnalyzeInfo'}=$data;
  143:             
  144:             &CheckFormElement($cache, 'Interval', 'Interval', '1');
  145:         } elsif(/form\.HeadingColumn/) {
  146:             my $value = $_;
  147:             $value =~ s/form\.//;
  148:             push(@headingColumns, $value);
  149:             $foundColumn=1;
  150:         } elsif(/form\.SequenceColumn/) {
  151:             my $value = $_;
  152:             $value =~ s/form\.//;
  153:             push(@sequenceColumns, $value);
  154:             $foundColumn=1;
  155:         }
  156:     }
  157: 
  158:     if($foundColumn) {
  159:         $cache->{'HeadingsFound'} = join(':', @headingColumns);
  160:         $cache->{'SequencesFound'} = join(':', @sequenceColumns);;
  161:     }
  162:     if(!defined($cache->{'HeadingsFound'}) || 
  163:        $cache->{'DefaultColumns'} ne 'false') {
  164:         $cache->{'HeadingsFound'}='HeadingColumnFull Name';
  165:     }
  166:     if(!defined($cache->{'SequencesFound'}) ||
  167:        $cache->{'DefaultColumns'} ne 'false') {
  168:         $cache->{'SequencesFound'}='All Sequences';
  169:     }
  170:     $cache->{'DefaultColumns'} = 'false';
  171: 
  172:     return;
  173: 
  174:     # Select page to display
  175:     if(defined($ENV{'form.ProblemStatistics'}) ||
  176:        defined($ENV{'form.ProblemStatisticsRecalculate'}) || 
  177:        defined($ENV{'form.DisplayCSVFormat'})) {
  178:         $cache->{'GoToPage'} = 'ProblemStatistics';
  179:         &CheckFormElement($cache, 'DisplayCSVFormat',
  180:                           'DisplayFormat', 'Display Table Format');
  181:         &CheckFormElement($cache, 'Ascend','ProblemStatisticsAscend',
  182:                           'Ascending');
  183:         &CheckFormElement($cache, 'Maps', 'ProblemStatisticsMap', 
  184:                           'All Maps');
  185:     } elsif(defined($ENV{'form.ProblemAnalysis'})) {
  186:         $cache->{'GoToPage'} = 'ProblemAnalysis';
  187:         &CheckFormElement($cache, 'Interval', 'Interval', '1');
  188:     } elsif(defined($ENV{'form.DoDiffGraph'})) {
  189:         $cache->{'GoToPage'} = 'DoDiffGraph';
  190:     } elsif(defined($ENV{'form.PercentWrongGraph'})) {
  191:         $cache->{'GoToPage'} = 'PercentWrongGraph';
  192:     } elsif(defined($ENV{'form.ActivityLog'})) {
  193:         $cache->{'GoToPage'} = 'ActivityLog';
  194:     } else {
  195:         $cache->{'GoToPage'} = 'Menu';
  196:     }
  197: 
  198:     &CheckFormElement($cache, 'Status', 'Status', 'Active');
  199: 
  200:     return;
  201: }
  202: 
  203: =pod
  204: 
  205: =item &SortStudents()
  206: 
  207: Determines which students to display and in which order.  Which are 
  208: displayed are determined by their status(active/expired).  The order
  209: is determined by the sort button pressed (default to username).  The
  210: type of sorting is username, lastname, or section.
  211: 
  212: =over 4
  213: 
  214: Input: $students, $CacheData
  215: 
  216: $students: A array pointer to a list of students (username:domain)
  217: 
  218: $CacheData: A pointer to the hash tied to the cached data
  219: 
  220: Output: \@order
  221: 
  222: @order: An ordered list of students (username:domain)
  223: 
  224: =back
  225: 
  226: =cut
  227: 
  228: sub SortStudents {
  229:     my ($cache)=@_;
  230: 
  231:     my @students = split(':::',$cache->{'NamesOfStudents'});
  232:     my @sorted1Students=();
  233:     foreach (@students) {
  234:         if($cache->{'Status'} eq 'Any' || 
  235:            $cache->{$_.':Status'} eq $cache->{'Status'}) {
  236:             push(@sorted1Students, $_);
  237:         }
  238:     }
  239: 
  240:     my $sortBy = '';
  241:     if(defined($cache->{'sort'})) {
  242:         $sortBy = ':'.$cache->{'sort'};
  243:     }
  244:     my @order = sort { $cache->{$a.$sortBy} cmp $cache->{$b.$sortBy} ||
  245:                        $cache->{$a.':fullname'} cmp $cache->{$b.':fullname'} } 
  246:                 @sorted1Students;
  247: 
  248:     return \@order;
  249: }
  250: 
  251: =pod
  252: 
  253: =item &SpaceColumns()
  254: 
  255: Determines the width of all the columns in the chart.  It is based on
  256: the max of the data for that column and its header.
  257: 
  258: =over 4
  259: 
  260: Input: $students, $studentInformation, $headings, $ChartDB
  261: 
  262: $students: An array pointer to a list of students (username:domain)
  263: 
  264: $studentInformatin: The type of data for the student information.  It is
  265: used as part of the key in $CacheData.
  266: 
  267: $headings: The name of the student information columns.
  268: 
  269: $ChartDB: The name of the cache database which is opened for read/write.
  270: 
  271: Output: None - All data stored in cache.
  272: 
  273: =back
  274: 
  275: =cut
  276: 
  277: sub SpaceColumns {
  278:     my ($students,$studentInformation,$headings,$cache)=@_;
  279: 
  280:     # Initialize Lengths
  281:     for(my $index=0; $index<(scalar @$headings); $index++) {
  282:         my @titleLength=split(//,$headings->[$index]);
  283:         $cache->{$studentInformation->[$index].':columnWidth'}=
  284:             scalar @titleLength;
  285:     }
  286: 
  287:     foreach my $name (@$students) {
  288:         foreach (@$studentInformation) {
  289:             my @dataLength=split(//,$cache->{$name.':'.$_});
  290:             my $length=(scalar @dataLength);
  291:             if($length > $cache->{$_.':columnWidth'}) {
  292:                 $cache->{$_.':columnWidth'}=$length;
  293:             }
  294:         }
  295:     }
  296: 
  297:     return;
  298: }
  299: 
  300: sub PrepareData {
  301:     my ($c, $cacheDB, $studentInformation, $headings)=@_;
  302: 
  303:     # Test for access to the cache data
  304:     my $courseID=$ENV{'request.course.id'};
  305:     my $isRecalculate=0;
  306:     if(defined($ENV{'form.Recalculate'})) {
  307:         $isRecalculate=1;
  308:     }
  309: 
  310:     my $isCached = &Apache::loncoursedata::TestCacheData($cacheDB, 
  311:                                                          $isRecalculate);
  312:     if($isCached < 0) {
  313:         return "Unable to tie hash to db file.";
  314:     }
  315: 
  316:     # Download class list information if not using cached data
  317:     my %cache;
  318:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT,0640)) {
  319:         return "Unable to tie hash to db file.";
  320:     }
  321: 
  322:     if(!$isCached) {
  323:         my $processTopResourceMapReturn=
  324:             &Apache::loncoursedata::ProcessTopResourceMap(\%cache, $c);
  325:         if($processTopResourceMapReturn ne 'OK') {
  326:             untie(%cache);
  327:             return $processTopResourceMapReturn;
  328:         }
  329:     }
  330: 
  331:     if($c->aborted()) {
  332:         untie(%cache);
  333:         return 'aborted'; 
  334:     }
  335: 
  336:     my $classlist=&Apache::loncoursedata::DownloadClasslist($courseID,
  337:                                                 $cache{'ClasslistTimestamp'},
  338:                                                 $c);
  339:     foreach (keys(%$classlist)) {
  340:         if(/^(con_lost|error|no_such_host)/i) {
  341:             untie(%cache);
  342:             return "Error getting student data.";
  343:         }
  344:     }
  345: 
  346:     if($c->aborted()) {
  347:         untie(%cache);
  348:         return 'aborted'; 
  349:     }
  350: 
  351:     # Active is a temporary solution, remember to change
  352:     Apache::loncoursedata::ProcessClasslist(\%cache,$classlist,$courseID,$c);
  353:     if($c->aborted()) {
  354:         untie(%cache);
  355:         return 'aborted'; 
  356:     }
  357: 
  358:     &ProcessFormData(\%cache);
  359:     my $students = &SortStudents(\%cache);
  360:     &SpaceColumns($students, $studentInformation, $headings, \%cache);
  361:     $cache{'updateTime:columnWidth'}=24;
  362: 
  363:     if($cache{'download'} ne 'false') {
  364:         my $who = $cache{'download'};
  365:         my $courseData = 
  366:             &Apache::loncoursedata::DownloadCourseInformation(
  367:                                              $who, $courseID, 
  368:                                              $cache{$who.':lastDownloadTime'});
  369:         &Apache::loncoursedata::ProcessStudentData(\%cache, $courseData, $who);
  370:         $cache{'download'} = 'false';
  371:     } elsif($cache{'DownloadAll'} ne 'false') {
  372:         my @allStudents;
  373:         if($cache{'DownloadAll'} eq 'sorted') {
  374:             @allStudents = @$students;
  375:         } else {
  376:             @allStudents = split(':::', $cache{'NamesOfStudents'});
  377:         }
  378:         foreach (@allStudents) {
  379:             my $courseData = 
  380:                 &Apache::loncoursedata::DownloadCourseInformation(
  381:                                              $_, $courseID, 
  382:                                              $cache{$_.':lastDownloadTime'});
  383:             &Apache::loncoursedata::ProcessStudentData(\%cache, $courseData, 
  384:                                                        $_);
  385:             if($c->aborted()) {
  386:                 untie(%cache);
  387:                 return 'aborted'; 
  388:             }
  389:         }
  390:         $cache{'DownloadAll'} = 'false';
  391:     }
  392: 
  393:     if($c->aborted()) {
  394:         untie(%cache);
  395:         return 'aborted'; 
  396:     }
  397: 
  398:     untie(%cache);
  399: 
  400:     return ('OK', $students);
  401: }
  402: 
  403: 
  404: # Create progress
  405: sub Create_PrgWin {
  406:     my ($r)=@_;
  407:     $r->print(<<ENDPOP);
  408:     <script>
  409:     popwin=open('','popwin','width=400,height=100');
  410:     popwin.document.writeln('<html><body bgcolor="#88DDFF">'+
  411:       '<title>LON-CAPA Statistics</title>'+
  412:       '<h4>Computation Progress</h4>'+
  413:       '<form name=popremain>'+
  414:       '<input type=text size=35 name=remaining value=Starting></form>'+
  415:       '</body></html>');
  416:     popwin.document.close();
  417:     </script>
  418: ENDPOP
  419: 
  420:     $r->rflush();
  421: }
  422: 
  423: # update progress
  424: sub Update_PrgWin {
  425:     my ($totalStudents,$index,$name,$r)=@_;
  426:     $r->print('<script>popwin.document.popremain.remaining.value="'.
  427:               'Computing '.$index.'/'.$totalStudents.': '.
  428:               $name.'";</script>');
  429:     $r->rflush();
  430: }
  431: 
  432: # close Progress Line
  433: sub Close_PrgWin {
  434:     my ($r)=@_;
  435:     $r->print('<script>popwin.close()</script>');
  436:     $r->rflush(); 
  437: }
  438: 
  439: 
  440: sub BuildClasslist {
  441:     my ($cacheDB,$students,$studentInformation,$headings)=@_;
  442: 
  443:     my %cache;
  444:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
  445:         return '<html><body>Unable to tie database.</body></html>';
  446:     }
  447: 
  448:     my $Str='';
  449:     $Str .= '<table border="0"><tr><td bgcolor="#777777">'."\n";
  450:     $Str .= '<table border="0" cellpadding="3"><tr bgcolor="#e6ffff">'."\n";
  451: 
  452:     my $displayString = '<td align="left"><a href="/adm/statistics?';
  453:     $displayString .= 'sort=LINKDATA">DISPLAYDATA&nbsp</a></td>'."\n";
  454:     $Str .= &Apache::lonhtmlcommon::CreateHeadings(\%cache, $studentInformation,
  455:                                                    $headings, $displayString);
  456:     $Str .= '</tr>'."\n";
  457:     my $alternate=0;
  458:     foreach (@$students) {
  459:         my ($username, $domain) = split(':', $_);
  460:         if($alternate) {
  461:             $Str .= '<tr bgcolor="#ffffe6">';
  462:         } else {
  463:             $Str .= '<tr bgcolor="#ffffc6">';
  464:         }
  465:         $alternate = ($alternate + 1) % 2;
  466:         foreach my $data (@$studentInformation) {
  467:             $Str .= '<td>';
  468:             if($data eq 'fullname') {
  469:                 $Str .= '<a href="/adm/statistics?reportSelected=';
  470:                 $Str .= &Apache::lonnet::escape('Student Assessment');
  471:                 $Str .= '&StudentAssessmentStudent=';
  472:                 $Str .= &Apache::lonnet::escape($cache{$_.':'.$data}).'">';
  473:                 $Str .= $cache{$_.':'.$data}.'&nbsp';
  474:                 $Str .= '</a>';
  475:             } elsif($data eq 'updateTime') {
  476:                 $Str .= '<a href="/adm/statistics?reportSelected=';
  477:                 $Str .= &Apache::lonnet::escape('Class list');
  478:                 $Str .= '&download='.$_.'">';
  479:                 $Str .= $cache{$_.':'.$data}.'&nbsp';
  480:                 $Str .= '&nbsp</a>';
  481:             } else {
  482:                 $Str .= $cache{$_.':'.$data}.'&nbsp';
  483:             }
  484: 
  485:             $Str .= '</td>'."\n";
  486:         }
  487:     }
  488: 
  489:     $Str .= '</tr>'."\n";
  490:     $Str .= '</table></td></tr></table>'."\n";
  491: 
  492:     untie(%cache);
  493: 
  494:     return $Str;
  495: }
  496: 
  497: sub CreateMainMenu {
  498:     my ($status, $reports)=@_;
  499: 
  500:     my $Str = '';
  501: 
  502:     $Str .= '<table border="0"><tbody><tr>'."\n";
  503:     $Str .= '<td></td><td></td>'."\n";
  504:     $Str .= '<td align="center"><b>Analysis Reports:</b></td>'."\n";
  505:     $Str .= '<td align="center"><b>Student Status:</b></td></tr>'."\n";
  506:     $Str .= '<tr>'."\n";
  507:     $Str .= '<td align="center"><input type="submit" name="Refresh" ';
  508:     $Str .= 'value="Refresh" /></td>'."\n";
  509:     $Str .= '<td align="center"><input type="submit" name="DownloadAll" ';
  510:     $Str .= 'value="Update All Student Data" /></td>'."\n";
  511:     $Str .= '<td align="center">';
  512:     $Str .= '<select name="reportSelected" onchange="document.';
  513:     $Str .= 'Statistics.submit()">'."\n";
  514: 
  515:     foreach (sort(keys(%$reports))) {
  516:         next if($_ eq 'reportSelected');
  517:         $Str .= '<option name="'.$_.'"';
  518:         if($reports->{'reportSelected'} eq $reports->{$_}) {
  519:             $Str .= ' selected=""';
  520:         }
  521:         $Str .= '>'.$reports->{$_}.'</option>'."\n";
  522:     }
  523:     $Str .= '</select></td>'."\n";
  524: 
  525:     $Str .= '<td align="center">';
  526:     $Str .= &Apache::lonhtmlcommon::StatusOptions($status, 'Statistics');
  527:     $Str .= '</td>'."\n";
  528: 
  529:     $Str .= '</tr></tbody></table>'."\n";
  530:     $Str .= '<hr>'."\n";
  531: 
  532:     return $Str;
  533: }
  534: 
  535: sub BuildStatistics {
  536:     my ($r)=@_;
  537: 
  538:     my $c = $r->connection;
  539:     my @studentInformation=('fullname','section','id','domain','username',
  540:                             'updateTime');
  541:     my @headings=('Full Name', 'Section', 'PID', 'Domain', 'User Name',
  542:                   'Last Updated');
  543:     my $spacing = '   ';
  544:     my %reports = ('classlist'          => 'Class list',
  545:                    'problem_statistics' => 'Problem Statistics',
  546:                    'student_assessment' => 'Student Assessment',
  547:                    'reportSelected'     => 'Class list');
  548: 
  549:     my %cache;
  550:     my $courseID=$ENV{'request.course.id'};
  551:     my $cacheDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
  552:                   "_$ENV{'user.domain'}_$courseID\_statistics.db";
  553: 
  554:     my ($returnValue, $students) = &PrepareData($c, $cacheDB, 
  555:                                                 \@studentInformation, 
  556:                                                 \@headings);
  557:     if($returnValue ne 'OK') {
  558:         $r->print('<html><body>'.$returnValue."\n".'</body></html>');
  559:         return OK;
  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'} = 'Problem Analysis';
  574:         }
  575: 
  576:         $r->print(&Apache::lonhtmlcommon::Title('LON-CAPA Statistics'));
  577:         $r->print('<form name="Statistics" ');
  578:         $r->print('method="post" action="/adm/statistics">');
  579:         $r->print(&CreateMainMenu($cache{'Status'}, \%reports));
  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 'Problem Analysis') {
  594:         $r->print(
  595:               &Apache::lonproblemanalysis::BuildProblemAnalysisPage($cacheDB));
  596:     } elsif($GoToPage eq 'Student Assessment') {
  597:         $r->print(
  598:             &Apache::lonstudentassessment::BuildStudentAssessmentPage($cacheDB,
  599:                                                           $students,
  600:                                                           $courseID,
  601:                                                           'Statistics',
  602:                                                           \@headings,
  603:                                                           $spacing,
  604:                                                           \@studentInformation,
  605:                                                           $r, $c));
  606:     } elsif($GoToPage eq 'Analyze') {
  607:         $r->print(&Apache::lonproblemanalysis::BuildAnalyzePage($cacheDB, 
  608:                                                                 $students, 
  609:                                                                 $courseID,$r));
  610:     } elsif($GoToPage eq 'DoDiffGraph') {
  611:         &Apache::lonproblemstatistics::BuildDiffGraph($r);
  612:     } elsif($GoToPage eq 'PercentWrongGraph') {
  613:         &Apache::lonproblemstatistics::BuildWrongGraph($r);
  614:     } elsif($GoToPage eq 'Class list') {
  615:         $r->print(&BuildClasslist($cacheDB, $students, \@studentInformation,
  616:                                   \@headings));
  617:     }
  618: 
  619:     $r->print('</form>'."\n");
  620:     $r->print("\n".'</body>'."\n".'</html>');
  621:     $r->rflush();
  622: 
  623:     return OK;
  624: }
  625: 
  626: # ================================================================ Main Handler
  627: 
  628: sub handler {
  629:     my $r=shift;
  630: 
  631: #    $jr = $r;
  632: 
  633:     unless(&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
  634:         $ENV{'user.error.msg'}=
  635:         $r->uri.":vgr:0:0:Cannot view grades for complete course";
  636:         return HTTP_NOT_ACCEPTABLE; 
  637:     }
  638: 
  639:     # Set document type for header only
  640:     if($r->header_only) {
  641:         if ($ENV{'browser.mathml'}) {
  642:             $r->content_type('text/xml');
  643:         } else {
  644:             $r->content_type('text/html');
  645:         }
  646:         &Apache::loncommon::no_cache($r);
  647:         $r->send_http_header;
  648:         return OK;
  649:     }
  650: 
  651:     unless($ENV{'request.course.fn'}) {
  652: 	my $requrl=$r->uri;
  653:         $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
  654:         return HTTP_NOT_ACCEPTABLE; 
  655:     }
  656: 
  657:     $r->content_type('text/html');
  658:     $r->send_http_header;
  659: 
  660:     &BuildStatistics($r);
  661: 
  662:     return OK;
  663: }
  664: 1;
  665: __END__
  666: 

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