File:  [LON-CAPA] / loncom / interface / lonstatistics.pm
Revision 1.58: download - view: text, annotated - select for diffs
Sun Jan 12 23:45:47 2003 UTC (21 years, 4 months ago) by minaeibi
Branches: MAIN
CVS tags: HEAD
To fix bug #1052:
in the pulldown menu, The "percentage Graph" changed into "Correct-problems Plot".

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

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