Annotation of loncom/interface/lonchart.pm, revision 1.53

1.1       www         1: # The LearningOnline Network with CAPA
1.25      minaeibi    2: # (Publication Handler
                      3: #
1.53    ! stredwic    4: # $Id: lonchart.pm,v 1.52 2002/07/02 21:48:36 stredwic Exp $
1.25      minaeibi    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: #
1.1       www        28: # Homework Performance Chart
                     29: #
                     30: # (Navigate Maps Handler
                     31: #
                     32: # (Page Handler
                     33: #
                     34: # (TeX Content Handler
1.27      minaeibi   35: # YEAR=2000
1.1       www        36: # 05/29/00,05/30 Gerd Kortemeyer)
                     37: # 08/30,08/31,09/06,09/14,09/15,09/16,09/19,09/20,09/21,09/23,
                     38: # 10/02,10/10,10/14,10/16,10/18,10/19,10/31,11/6,11/14,11/16 Gerd Kortemeyer)
1.27      minaeibi   39: # YEAR=2001
1.14      minaeibi   40: # 3/1/1,6/1,17/1,29/1,30/1,31/1 Gerd Kortemeyer)
1.5       minaeibi   41: # 7/10/01 Behrouz Minaei
1.6       www        42: # 9/8 Gerd Kortemeyer
1.27      minaeibi   43: # 10/1, 10/19, 11/17, 11/22, 11/24, 11/28 12/18 Behrouz Minaei
                     44: # YEAR=2002
1.33      minaeibi   45: # 2/1, 2/6, 2/19, 2/28 Behrouz Minaei
1.26      minaeibi   46: #
                     47: ###
1.1       www        48: 
1.51      stredwic   49: =pod
                     50: 
                     51: =cut
                     52: 
1.1       www        53: package Apache::lonchart;
                     54: 
                     55: use strict;
                     56: use Apache::Constants qw(:common :http);
                     57: use Apache::lonnet();
1.28      albertel   58: use Apache::loncommon();
1.1       www        59: use HTML::TokeParser;
                     60: use GDBM_File;
                     61: 
1.51      stredwic   62: #my $jr; 
1.44      stredwic   63: # ----- FORMAT PRINT DATA ----------------------------------------------
1.1       www        64: 
1.44      stredwic   65: sub FormatStudentInformation {
1.51      stredwic   66:     my ($cache,$name,$studentInformation,$spacePadding)=@_;
1.50      stredwic   67:     my $Str='';
1.44      stredwic   68: 
1.49      stredwic   69:     for(my $index=0; $index<(scalar @$studentInformation); $index++) {
1.51      stredwic   70:         if(!&ShouldShowColumn($cache, 'heading'.$index)) {
1.49      stredwic   71:             next;
                     72:         }
                     73: 	my $data=$cache->{$name.':'.$studentInformation->[$index]};
1.44      stredwic   74: 	$Str .= $data;
                     75: 
                     76: 	my @dataLength=split(//,$data);
                     77: 	my $length=scalar @dataLength;
1.49      stredwic   78: 	$Str .= (' 'x($cache->{$studentInformation->[$index].'Length'}-
                     79:                       $length));
1.44      stredwic   80: 	$Str .= $spacePadding;
                     81:     }
                     82: 
                     83:     return $Str;
                     84: }
                     85: 
                     86: sub FormatStudentData {
1.51      stredwic   87:     my ($name,$coid,$studentInformation,$spacePadding,$ChartDB)=@_;
1.43      stredwic   88:     my ($sname,$sdom) = split(/\:/,$name);
                     89:     my $Str;
1.44      stredwic   90:     my %CacheData;
1.43      stredwic   91: 
1.44      stredwic   92:     unless(tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_READER,0640)) {
                     93:         return '';
                     94:     }
1.43      stredwic   95:     # Handle Student information ------------------------------------------
1.44      stredwic   96:     # Handle user data
                     97:     $Str=&FormatStudentInformation(\%CacheData, $name, $studentInformation, 
1.51      stredwic   98:                                    $spacePadding);
1.44      stredwic   99: 
1.43      stredwic  100:     # Handle errors
1.44      stredwic  101:     if($CacheData{$name.':error'} =~ /environment/) {
1.50      stredwic  102:         $Str .= '<br>';
1.44      stredwic  103:         untie(%CacheData);
                    104:         return $Str;
                    105:     }
1.43      stredwic  106: 
1.44      stredwic  107:     if($CacheData{$name.':error'} =~ /course/) {
1.50      stredwic  108:         $Str .= '<br>';
1.44      stredwic  109:         untie(%CacheData);
1.50      stredwic  110:         return $Str;
1.40      stredwic  111:     }
                    112: 
1.43      stredwic  113:     # Handle problem data ------------------------------------------------
1.44      stredwic  114:     my $Version;
                    115:     my $problemsCorrect = 0;
                    116:     my $totalProblems   = 0;
                    117:     my $problemsSolved  = 0;
                    118:     my $numberOfParts   = 0;
                    119:     foreach my $sequence (split(/\:/,$CacheData{'orderedSequences'})) {
1.51      stredwic  120:         if(!&ShouldShowColumn(\%CacheData, 'sequence'.$sequence)) {
1.49      stredwic  121:             next;
                    122:         }
                    123: 
1.44      stredwic  124: 	my $characterCount=0;
                    125: 	foreach my $problemID (split(/\:/,$CacheData{$sequence.':problems'})) {
                    126: 	    my $problem = $CacheData{$problemID.':problem'};
                    127: 	    my $LatestVersion = $CacheData{$name.":version:$problem"};
                    128: 
                    129:             if(!$LatestVersion) {
                    130:                 foreach my $part (split(/\:/,$CacheData{$sequence.':'.
                    131:                                                         $problemID.
                    132:                                                         ':parts'})) {
                    133:                     $Str .= ' ';
                    134:                     $totalProblems++;
                    135:                     $characterCount++;
                    136:                 }
                    137:                 next;
                    138:             }
                    139: 
                    140:             my %partData=undef;
                    141:             #initialize data, displays skips correctly
                    142:             foreach my $part (split(/\:/,$CacheData{$sequence.':'.
                    143:                                                     $problemID.
                    144:                                                     ':parts'})) {
                    145:                 $partData{$part.':tries'}=0;
                    146:                 $partData{$part.':code'}=' ';
                    147:             }
                    148: 	    for(my $Version=1; $Version<=$LatestVersion; $Version++) {
                    149:                 foreach my $part (split(/\:/,$CacheData{$sequence.':'.
                    150:                                                         $problemID.
                    151:                                                         ':parts'})) {
                    152: 
                    153:                     if(!defined($CacheData{$name.":$Version:$problem".
                    154:                                                ":resource.$part.solved"})) {
                    155:                         next;
                    156:                     }
                    157: 
                    158:                     my $tries=0;
                    159:                     my $code=' ';
                    160: 
                    161:                     $tries = $CacheData{$name.":$Version:$problem".
                    162:                                         ":resource.$part.tries"};
                    163:                     $partData{$part.':tries'}=($tries) ? $tries : 0;
                    164: 
                    165:                     my $val = $CacheData{$name.":$Version:$problem".
                    166:                                          ":resource.$part.solved"};
                    167:                     if    ($val eq 'correct_by_student')   {$code = '*';} 
                    168:                     elsif ($val eq 'correct_by_override')  {$code = '+';}
                    169:                     elsif ($val eq 'incorrect_attempted')  {$code = '.';} 
                    170:                     elsif ($val eq 'incorrect_by_override'){$code = '-';}
                    171:                     elsif ($val eq 'excused')              {$code = 'x';}
                    172:                     elsif ($val eq 'ungraded_attempted')   {$code = '#';}
                    173:                     else                                   {$code = ' ';}
                    174:                     $partData{$part.':code'}=$code;
                    175:                 }
                    176:             }
                    177: 
                    178:             $Str.='<a href="/adm/grades?symb='.
                    179:                 &Apache::lonnet::escape($problem).
                    180:                 '&student='.$sname.'&domain='.$sdom.'&command=submission">'; 
                    181:             foreach(split(/\:/,$CacheData{$sequence.':'.$problemID.
                    182:                                           ':parts'})) {
                    183:                 if($partData{$_.':code'} eq '*') {
                    184:                     $problemsCorrect++;
                    185:                     if (($partData{$_.':tries'}<10) &&
                    186:                         ($partData{$_.':tries'} ne '')) {
                    187:                         $partData{$_.':code'}=$partData{$_.':tries'};
                    188:                     }
                    189:                 } elsif($partData{$_.':code'} eq '+') {
                    190:                     $problemsCorrect++;
                    191:                 }
                    192: 
                    193:                 $Str .= $partData{$_.':code'};
                    194:                 $characterCount++;
                    195: 
                    196:                 if($partData{$_.':code'} ne 'x') {
                    197:                     $totalProblems++;
                    198:                 }
                    199:             }
                    200:             $Str.='</a>';
                    201:         }
                    202: 
                    203:         my $spacesNeeded=$CacheData{$sequence.':columnWidth'}-$characterCount;
                    204:         $spacesNeeded -= 3;
                    205:         $Str .= (' 'x$spacesNeeded);
                    206: 
                    207: 	my $outputProblemsCorrect = sprintf( "%3d", $problemsCorrect );
                    208: 	$Str .= '<font color="#007700">'.$outputProblemsCorrect.'</font>';
                    209: 	$problemsSolved += $problemsCorrect;
                    210: 	$problemsCorrect=0;
                    211: 
                    212:         $Str .= $spacePadding;
                    213:     }
1.11      minaeibi  214: 
1.51      stredwic  215:     my $outputProblemsSolved = sprintf( "%4d", $problemsSolved );
                    216:     my $outputTotalProblems  = sprintf( "%4d", $totalProblems );
                    217:     $Str .= '<font color="#000088">'.$outputProblemsSolved.
                    218: 	    ' / '.$outputTotalProblems.'</font><br>';
1.39      stredwic  219: 
1.44      stredwic  220:     untie(%CacheData);
                    221:     return $Str;
                    222: }
1.43      stredwic  223: 
1.44      stredwic  224: sub CreateTableHeadings {
1.51      stredwic  225:     my ($CacheData,$studentInformation,$headings,$spacePadding)=@_;
1.53    ! stredwic  226:     my $Str='<tr>';
1.43      stredwic  227: 
1.44      stredwic  228:     for(my $index=0; $index<(scalar @$headings); $index++) {
1.51      stredwic  229:         if(!&ShouldShowColumn($CacheData, 'heading'.$index)) {
1.49      stredwic  230:             next;
                    231:         }
                    232: 
1.53    ! stredwic  233:         $Str .= '<td align="left"><pre>';
1.44      stredwic  234: 	my $data=$$headings[$index];
                    235: 	$Str .= $data;
                    236: 
                    237: 	my @dataLength=split(//,$data);
                    238: 	my $length=scalar @dataLength;
                    239: 	$Str .= (' 'x($CacheData->{$$studentInformation[$index].'Length'}-
                    240:                       $length));
                    241: 	$Str .= $spacePadding;
1.53    ! stredwic  242:         $Str .= '</pre></td>';
1.44      stredwic  243:     }
                    244: 
                    245:     foreach my $sequence (split(/\:/,$CacheData->{'orderedSequences'})) {
1.51      stredwic  246:         if(!&ShouldShowColumn($CacheData, 'sequence'.$sequence)) {
1.49      stredwic  247:             next;
                    248:         }
                    249: 
1.53    ! stredwic  250:         $Str .= '<td align="left"><pre>';
1.49      stredwic  251:         my $name = $CacheData->{$sequence.':title'};
                    252: 	$Str .= $name;
1.44      stredwic  253: 	my @titleLength=split(//,$CacheData->{$sequence.':title'});
                    254: 	my $leftover=$CacheData->{$sequence.':columnWidth'}-
                    255:                      (scalar @titleLength);
                    256: 	$Str .= (' 'x$leftover);
                    257: 	$Str .= $spacePadding;
1.53    ! stredwic  258:         $Str .= '</pre></td>';
1.1       www       259:     }
1.39      stredwic  260: 
1.53    ! stredwic  261:     $Str .= '<td>Total Solved/Total Problems</td>';
        !           262:     $Str .= '</tr></tbody></table>';
1.11      minaeibi  263: 
1.43      stredwic  264:     return $Str;
                    265: }
                    266: 
1.49      stredwic  267: sub CreateColumnSelectionBox {
1.51      stredwic  268:     my ($CacheData,$studentInformation,$headings,$spacePadding)=@_;
1.46      stredwic  269: 
1.49      stredwic  270:     my $missing=0;
1.50      stredwic  271:     my $notThere='<tr><td align="right"><b>Select column to view:</b>';
1.49      stredwic  272:     my $name;
1.50      stredwic  273:     $notThere .= '<td align="left">';
1.49      stredwic  274:     $notThere .= '<select name="reselect" size="4" multiple="true">'."\n";
1.46      stredwic  275: 
                    276:     for(my $index=0; $index<(scalar @$headings); $index++) {
1.51      stredwic  277:         if(&ShouldShowColumn($CacheData, 'heading'.$index)) {
1.49      stredwic  278:             next;
                    279:         }
                    280:         $name = $headings->[$index];
                    281:         $notThere .= '<option value="heading'.$index.'">';
                    282:         $notThere .= $name.'</option>'."\n";
                    283:         $missing++;
                    284:     }
                    285: 
                    286:     foreach my $sequence (split(/\:/,$CacheData->{'orderedSequences'})) {
1.51      stredwic  287:         if(&ShouldShowColumn($CacheData, 'sequence'.$sequence)) {
1.49      stredwic  288:             next;
                    289:         }
                    290:         $name = $CacheData->{$sequence.':title'};
                    291:         $notThere .= '<option value="sequence'.$sequence.'">';
                    292:         $notThere .= $name.'</option>'."\n";
                    293:         $missing++;
                    294:     }
                    295: 
                    296:     if($missing) {
1.50      stredwic  297:         $notThere .= '</select>';
1.49      stredwic  298:     } else {
1.50      stredwic  299:         $notThere='<tr><td>';
1.49      stredwic  300:     }
                    301: 
1.50      stredwic  302:     return $notThere.'</td></tr></tbody></table>';
1.49      stredwic  303: }
                    304: 
                    305: sub CreateColumnSelectors {
1.51      stredwic  306:     my ($CacheData,$studentInformation,$headings,$spacePadding)=@_;
1.46      stredwic  307: 
1.49      stredwic  308:     my $found=0;
                    309:     my ($name, $length, $position);
1.53    ! stredwic  310:     my $present='<table border="0" cellpadding="0" cellspacing="0">';
        !           311:     $present .= '</tbody><tr>';
1.49      stredwic  312:     for(my $index=0; $index<(scalar @$headings); $index++) {
1.51      stredwic  313:         if(!&ShouldShowColumn($CacheData, 'heading'.$index)) {
1.49      stredwic  314:             next;
                    315:         }
1.53    ! stredwic  316:         $present .= '<td align="center">';
1.49      stredwic  317:         $name = $headings->[$index];
                    318:         $present .= '<input type="checkbox" checked="on" ';
                    319:         $present .= 'name="heading'.$index.'">';
1.53    ! stredwic  320:         $present .= '</td>';
1.49      stredwic  321:         $found++;
1.46      stredwic  322:     }
                    323: 
                    324:     foreach my $sequence (split(/\:/,$CacheData->{'orderedSequences'})) {
1.51      stredwic  325:         if(!&ShouldShowColumn($CacheData, 'sequence'.$sequence)) {
1.49      stredwic  326:             next;
                    327:         }
1.53    ! stredwic  328:         $present .= '<td align="center">';
1.49      stredwic  329:         $name = $CacheData->{$sequence.':title'};
                    330:         $present .= '<input type="checkbox" checked="on" ';
                    331:         $present .= 'name="sequence'.$sequence.'">';
1.53    ! stredwic  332:         $present .= '</td>';
1.49      stredwic  333:         $found++;
                    334:     }
                    335: 
                    336:     if($found) {
                    337:         $present  = $present;
                    338:     } else {
1.53    ! stredwic  339:         $present = '<td></td>';
1.46      stredwic  340:     }
                    341: 
1.53    ! stredwic  342:     return $present.'</tr></form>'."\n";;
1.46      stredwic  343: }
                    344: 
1.43      stredwic  345: sub CreateForm {
1.51      stredwic  346:     my ($CacheData)=@_;
1.43      stredwic  347:     my $OpSel1='';
                    348:     my $OpSel2='';
                    349:     my $OpSel3='';
1.51      stredwic  350:     my $Status = $CacheData->{'form.status'};
1.43      stredwic  351:     if ( $Status eq 'Any' ) { $OpSel3='selected'; }
                    352:     elsif ($Status eq 'Expired' ) { $OpSel2 = 'selected'; }
                    353:     else { $OpSel1 = 'selected'; }
                    354: 
1.50      stredwic  355:     my $Ptr .= '<form name="stat" method="post" action="/adm/chart" >'."\n";
                    356:     $Ptr .= '<table border="0"><tbody>';
                    357:     $Ptr .= '<tr><td align="right">';
                    358:     $Ptr .= '</td><td align="left">';
1.51      stredwic  359:     $Ptr .= '<input type="submit" name="recalculate" ';
1.50      stredwic  360:     $Ptr .= 'value="Recalculate Chart"/>'."\n";
1.43      stredwic  361:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
1.50      stredwic  362:     $Ptr .= '<input type="submit" name="refresh" ';
1.51      stredwic  363:     $Ptr .= 'value="Refresh Chart"/>'."\n";
                    364:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
                    365:     $Ptr .= '<input type="submit" name="reset" ';
                    366:     $Ptr .= 'value="Reset Selections"/></td>'."\n";
1.50      stredwic  367:     $Ptr .= '</tr><tr><td align="right">';
                    368:     $Ptr .= '<b> Sort by: </b>'."\n";
                    369:     $Ptr .= '</td><td align="left">';
1.44      stredwic  370:     $Ptr .= '<input type="submit" name="sort" value="User Name" />'."\n";
1.43      stredwic  371:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
1.44      stredwic  372:     $Ptr .= '<input type="submit" name="sort" value="Last Name" />'."\n";
1.43      stredwic  373:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
1.44      stredwic  374:     $Ptr .= '<input type="submit" name="sort" value="Section"/>'."\n";
1.50      stredwic  375:     $Ptr .= '</td></tr><tr><td align="right">';
1.43      stredwic  376:     $Ptr .= '<b> Student Status: &nbsp; </b>'."\n".
1.50      stredwic  377:             '</td><td align="left">'.
1.43      stredwic  378:             '<select name="status">'. 
                    379:             '<option '.$OpSel1.' >Active</option>'."\n".
                    380:             '<option '.$OpSel2.' >Expired</option>'."\n".
                    381: 	    '<option '.$OpSel3.' >Any</option> </select> '."\n";
1.50      stredwic  382:     $Ptr .= '</td></tr>';
1.44      stredwic  383: 
                    384:     return $Ptr;
                    385: }
                    386: 
                    387: sub CreateLegend {
1.50      stredwic  388:     my $Str = "<p><pre>".
                    389:               "1..9: correct by student in 1..9 tries\n".
1.44      stredwic  390:               "   *: correct by student in more than 9 tries\n".
                    391: 	      "   +: correct by override\n".
                    392:               "   -: incorrect by override\n".
                    393: 	      "   .: incorrect attempted\n".
                    394: 	      "   #: ungraded attempted\n".
                    395:               "    : not attempted\n".
1.50      stredwic  396: 	      "   x: excused".
                    397:               "</pre><p>"; 
1.44      stredwic  398:     return $Str;
                    399: }
                    400: 
                    401: sub StartDocument {
                    402:     my $Str = '';
                    403:     $Str .= '<html>';
                    404:     $Str .= '<head><title>';
                    405:     $Str .= 'LON-CAPA Assessment Chart</title></head>';
                    406:     $Str .= '<body bgcolor="#FFFFFF">';
                    407:     $Str .= '<script>window.focus();</script>';
                    408:     $Str .= '<img align=right src=/adm/lonIcons/lonlogos.gif>';
1.52      stredwic  409:     $Str .= '<h1>Assessment Chart</h1>';
                    410:     $Str .= '<h3>'.localtime().'</h3>';
1.50      stredwic  411:     $Str .= '<h1>'.$ENV{'course.'.$ENV{'request.course.id'}.'.description'};
                    412:     $Str .= '</h1>';
1.44      stredwic  413: 
                    414:     return $Str;
                    415: }
                    416: 
                    417: # ----- END FORMAT PRINT DATA ------------------------------------------
                    418: 
                    419: # ----- DOWNLOAD INFORMATION -------------------------------------------
                    420: 
                    421: sub DownloadPrerequisiteData {
                    422:     my ($courseID, $c)=@_;
                    423:     my ($courseDomain,$courseNumber)=split(/\_/,$courseID);
                    424: 
                    425:     my %classlist=&Apache::lonnet::dump('classlist',$courseDomain,
                    426:                                         $courseNumber);
                    427:     my ($checkForError)=keys (%classlist);
                    428:     if($checkForError =~ /^(con_lost|error|no_such_host)/i) {
                    429:         return \%classlist;
                    430:     }
                    431: 
                    432:     foreach my $name (keys(%classlist)) {
                    433:         if($c->aborted()) {
                    434:             $classlist{'error'}='aborted';
                    435:             return \%classlist;
                    436:         }
                    437: 
                    438:         my ($studentName,$studentDomain) = split(/\:/,$name);
                    439:         # Download student environment data, specifically the full name and id.
                    440:         my %studentInformation=&Apache::lonnet::get('environment',
                    441:                                                     ['lastname','generation',
                    442:                                                      'firstname','middlename',
                    443:                                                      'id'],
                    444:                                                     $studentDomain,
                    445:                                                     $studentName);
                    446:         $classlist{$name.':studentInformation'}=\%studentInformation;
                    447: 
                    448:         if($c->aborted()) {
                    449:             $classlist{'error'}='aborted';
                    450:             return \%classlist;
                    451:         }
                    452: 
                    453:         #Section
                    454:         my %section=&Apache::lonnet::dump('roles',$studentDomain,$studentName);
                    455:         $classlist{$name.':section'}=\%section;
                    456:     }
                    457: 
                    458:     return \%classlist;
1.1       www       459: }
                    460: 
1.44      stredwic  461: sub DownloadStudentCourseInformation {
                    462:     my ($name,$courseID)=@_;
                    463:     my ($studentName,$studentDomain) = split(/\:/,$name);
                    464: 
                    465:     # Download student course data
                    466:     my %courseData=&Apache::lonnet::dump($courseID,$studentDomain,
                    467: 					 $studentName);
                    468:     return \%courseData;
                    469: }
                    470: 
                    471: # ----- END DOWNLOAD INFORMATION ---------------------------------------
                    472: 
                    473: # ----- END PROCESSING FUNCTIONS ---------------------------------------
                    474: 
                    475: sub ProcessTopResourceMap {
                    476:     my ($ChartDB,$c)=@_;
                    477:     my %hash;
                    478:     my $fn=$ENV{'request.course.fn'};
                    479:     if(-e "$fn.db") {
                    480: 	my $tieTries=0;
                    481: 	while($tieTries < 3) {
                    482: 	    if(tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) {
                    483: 		last;
                    484: 	    }
                    485: 	    $tieTries++;
                    486: 	    sleep 1;
1.43      stredwic  487: 	}
1.44      stredwic  488: 	if($tieTries >= 3) {
                    489:             return 'Coursemap undefined.';
                    490:         }
                    491:     } else {
                    492:         return 'Can not open Coursemap.';
1.43      stredwic  493:     }
                    494: 
1.44      stredwic  495:     my %CacheData;
                    496:     unless(tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_WRCREAT,0640)) {
                    497:         untie(%hash);
                    498: 	return 'Could not tie cache hash.';
                    499:     }
                    500: 
                    501:     my (@sequences, @currentResource, @finishResource);
                    502:     my ($currentSequence, $currentResourceID, $lastResourceID);
                    503: 
                    504:     $currentResourceID=$hash{'ids_/res/'.$ENV{'request.course.uri'}};
1.46      stredwic  505:     push(@currentResource, $currentResourceID);
1.44      stredwic  506:     $lastResourceID=-1;
                    507:     $currentSequence=-1;
                    508:     my $topLevelSequenceNumber = $currentSequence;
                    509: 
                    510:     while(1) {
                    511:         if($c->aborted()) {
                    512:             last;
                    513:         }
                    514: 	# HANDLE NEW SEQUENCE!
                    515: 	#if page || sequence
                    516: 	if(defined($hash{'map_pc_'.$hash{'src_'.$currentResourceID}})) {
                    517: 	    push(@sequences, $currentSequence);
                    518: 	    push(@currentResource, $currentResourceID);
                    519: 	    push(@finishResource, $lastResourceID);
                    520: 
                    521: 	    $currentSequence=$hash{'map_pc_'.$hash{'src_'.$currentResourceID}};
1.51      stredwic  522: 
                    523:             # Mark sequence as containing problems.  If it doesn't, then
                    524:             # it will be removed when processing for this sequence is
                    525:             # complete.  This allows the problems in a sequence
                    526:             # to be outputed before problems in the subsequences
                    527:             if(!defined($CacheData{'orderedSequences'})) {
                    528:                 $CacheData{'orderedSequences'}=$currentSequence;
                    529:             } else {
                    530:                 $CacheData{'orderedSequences'}.=':'.$currentSequence;
                    531:             }
                    532: 
1.44      stredwic  533: 	    $lastResourceID=$hash{'map_finish_'.
                    534: 				  $hash{'src_'.$currentResourceID}};
                    535: 	    $currentResourceID=$hash{'map_start_'.
                    536: 				     $hash{'src_'.$currentResourceID}};
                    537: 
                    538: 	    if(!($currentResourceID) || !($lastResourceID)) {
                    539: 		$currentSequence=pop(@sequences);
                    540: 		$currentResourceID=pop(@currentResource);
                    541: 		$lastResourceID=pop(@finishResource);
                    542: 		if($currentSequence eq $topLevelSequenceNumber) {
                    543: 		    last;
                    544: 		}
                    545: 	    }
                    546: 	}
                    547: 
                    548: 	# Handle gradable resources: exams, problems, etc
                    549: 	$currentResourceID=~/(\d+)\.(\d+)/;
                    550:         my $partA=$1;
                    551:         my $partB=$2;
                    552: 	if($hash{'src_'.$currentResourceID}=~
                    553: 	   /\.(problem|exam|quiz|assess|survey|form)$/ &&
                    554: 	   $partA eq $currentSequence) {
                    555: 	    my $Problem = &Apache::lonnet::symbclean(
                    556: 			  &Apache::lonnet::declutter($hash{'map_id_'.$partA}).
                    557: 			  '___'.$partB.'___'.
                    558: 			  &Apache::lonnet::declutter($hash{'src_'.
                    559: 							 $currentResourceID}));
                    560: 
                    561: 	    $CacheData{$currentResourceID.':problem'}=$Problem;
                    562: 	    if(!defined($CacheData{$currentSequence.':problems'})) {
                    563: 		$CacheData{$currentSequence.':problems'}=$currentResourceID;
                    564: 	    } else {
                    565: 		$CacheData{$currentSequence.':problems'}.=
                    566: 		    ':'.$currentResourceID;
                    567: 	    }
                    568: 
                    569:             #Get Parts for problem
                    570: 	    my $meta=$hash{'src_'.$currentResourceID};
                    571: 	    foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
                    572: 		if($_=~/^stores\_(\d+)\_tries$/) {
                    573: 		    my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
                    574:                     if(!defined($CacheData{$currentSequence.':'.
                    575:                                           $currentResourceID.':parts'})) {
                    576:                         $CacheData{$currentSequence.':'.$currentResourceID.
                    577:                                    ':parts'}=$Part;
                    578:                     } else {
                    579:                         $CacheData{$currentSequence.':'.$currentResourceID.
                    580:                                    ':parts'}.=':'.$Part;
                    581:                     }
                    582: 		}
                    583: 	    }
                    584: 	}
                    585: 
                    586: 	#if resource == finish resource
                    587: 	if($currentResourceID eq $lastResourceID) {
                    588: 	    #pop off last resource of sequence
                    589: 	    $currentResourceID=pop(@currentResource);
                    590: 	    $lastResourceID=pop(@finishResource);
                    591: 
                    592: 	    if(defined($CacheData{$currentSequence.':problems'})) {
                    593: 		# Capture sequence information here
                    594: 		$CacheData{$currentSequence.':title'}=
                    595: 		    $hash{'title_'.$currentResourceID};
                    596: 
                    597:                 my $totalProblems=0;
1.47      stredwic  598:                 foreach my $currentProblem (split(/\:/,
                    599:                                                $CacheData{$currentSequence.
1.44      stredwic  600:                                                ':problems'})) {
1.47      stredwic  601:                     foreach (split(/\:/,$CacheData{$currentSequence.':'.
                    602:                                                    $currentProblem.
                    603:                                                    ':parts'})) {
1.44      stredwic  604:                         $totalProblems++;
                    605:                     }
                    606:                 }
                    607: 		my @titleLength=split(//,$CacheData{$currentSequence.
                    608:                                                     ':title'});
                    609:                 # $extra is 3 for problems correct and 3 for space
                    610:                 # between problems correct and problem output
                    611:                 my $extra = 6;
                    612: 		if(($totalProblems + $extra) > (scalar @titleLength)) {
                    613: 		    $CacheData{$currentSequence.':columnWidth'}=
                    614:                         $totalProblems + $extra;
                    615: 		} else {
                    616: 		    $CacheData{$currentSequence.':columnWidth'}=
                    617:                         (scalar @titleLength);
                    618: 		}
1.51      stredwic  619: 	    } else {
                    620:                 $CacheData{'orderedSequences'}=~s/$currentSequence//;
                    621:                 $CacheData{'orderedSequences'}=~s/::/:/g;
                    622:                 $CacheData{'orderedSequences'}=~s/^:|:$//g;
                    623:             }
1.44      stredwic  624: 
                    625: 	    $currentSequence=pop(@sequences);
                    626: 	    if($currentSequence eq $topLevelSequenceNumber) {
                    627: 		last;
                    628: 	    }
                    629: 	}
1.43      stredwic  630: 
1.44      stredwic  631: 	# MOVE!!!
                    632: 	#move to next resource
                    633: 	unless(defined($hash{'to_'.$currentResourceID})) {
                    634: 	    # big problem, need to handle.  Next is probably wrong
                    635: 	    last;
                    636: 	}
                    637: 	my @nextResources=();
                    638: 	foreach (split(/\,/,$hash{'to_'.$currentResourceID})) {
                    639: 	    push(@nextResources, $hash{'goesto_'.$_});
                    640: 	}
                    641: 	push(@currentResource, @nextResources);
1.46      stredwic  642: 	# Set the next resource to be processed
                    643: 	$currentResourceID=pop(@currentResource);
1.44      stredwic  644:     }
1.5       minaeibi  645: 
1.44      stredwic  646:     unless (untie(%hash)) {
                    647:         &Apache::lonnet::logthis("<font color=blue>WARNING: ".
                    648:                                  "Could not untie coursemap $fn (browse)".
                    649:                                  ".</font>"); 
                    650:     }
1.1       www       651: 
1.44      stredwic  652:     unless (untie(%CacheData)) {
                    653:         &Apache::lonnet::logthis("<font color=blue>WARNING: ".
                    654:                                  "Could not untie Cache Hash (browse)".
                    655:                                  ".</font>"); 
1.1       www       656:     }
1.44      stredwic  657: 
                    658:     return 'OK';
1.1       www       659: }
1.33      minaeibi  660: 
1.44      stredwic  661: sub ProcessSection {
                    662:     my ($sectionData, $courseid,$ActiveFlag)=@_;
1.33      minaeibi  663:     $courseid=~s/\_/\//g;
                    664:     $courseid=~s/^(\w)/\/$1/;
1.39      stredwic  665: 
1.41      albertel  666:     my $cursection='-1';
                    667:     my $oldsection='-1';
                    668:     my $status='Expired';
1.44      stredwic  669:     my $section='';
                    670:     foreach my $key (keys (%$sectionData)) {
                    671: 	my $value = $sectionData->{$key};
1.33      minaeibi  672:         if ($key=~/^$courseid(?:\/)*(\w+)*\_st$/) {
1.44      stredwic  673: 	    $section=$1;
                    674: 	    if($key eq $courseid.'_st') {
                    675: 		$section='';
                    676: 	    }
1.39      stredwic  677: 	    my ($dummy,$end,$start)=split(/\_/,$value);
1.41      albertel  678: 	    my $now=time;
                    679: 	    my $notactive=0;
1.43      stredwic  680: 	    if ($start) {
                    681: 		if($now<$start) {
                    682: 		    $notactive=1;
                    683: 		}
                    684: 	    }
                    685: 	    if($end) {
                    686: 		if ($now>$end) {
                    687: 		    $notactive=1;
                    688: 		}
                    689: 	    }
                    690: 	    if($notactive == 0) {
                    691: 		$status='Active';
                    692: 		$cursection=$section;
1.44      stredwic  693: 		last;
1.43      stredwic  694: 	    }
                    695: 	    if($notactive == 1) {
                    696: 		$oldsection=$section;
                    697: 	    }
                    698: 	}
                    699:     }
                    700:     if($status eq $ActiveFlag) {
                    701: 	if($cursection eq '-1') {
                    702: 	    return $oldsection;
                    703: 	}
                    704: 	return $cursection;
                    705:     }
                    706:     if($ActiveFlag eq 'Any') {
                    707: 	if($cursection eq '-1') {
                    708: 	    return $oldsection;
                    709: 	}
                    710: 	return $cursection;
1.41      albertel  711:     }
1.36      minaeibi  712:     return '-1';
1.33      minaeibi  713: }
                    714: 
1.44      stredwic  715: sub ProcessStudentInformation {
                    716:     my ($CacheData,$studentInformation,$section,$date,$name,$courseID,$c)=@_;
                    717:     my ($studentName,$studentDomain) = split(/\:/,$name);
                    718: 
                    719:     $CacheData->{$name.':username'}=$studentName;
                    720:     $CacheData->{$name.':domain'}=$studentDomain;
                    721:     $CacheData->{$name.':date'}=$date;
                    722: 
                    723:     my ($checkForError)=keys(%$studentInformation);
                    724:     if($checkForError =~ /^(con_lost|error|no_such_host)/i) {
                    725: 	$CacheData->{$name.':error'}=
                    726: 	    'Could not download student environment data.';
                    727: 	$CacheData->{$name.':fullname'}='';
                    728: 	$CacheData->{$name.':id'}='';
                    729:     } else {
                    730: 	$CacheData->{$name.':fullname'}=&ProcessFullName(
                    731:                                           $studentInformation->{'lastname'},
                    732: 				          $studentInformation->{'generation'},
                    733: 				          $studentInformation->{'firstname'},
                    734:                                           $studentInformation->{'middlename'});
                    735: 	$CacheData->{$name.':id'}=$studentInformation->{'id'};
                    736:     }
                    737: 
                    738:     # Get student's section number
1.51      stredwic  739:     my $sec=&ProcessSection($section, $courseID, $CacheData->{'form.status'});
1.44      stredwic  740:     if($sec != -1) {
                    741: 	$CacheData->{$name.':section'}=$sec;
                    742:     } else {
                    743: 	$CacheData->{$name.':section'}='';
                    744:     }
                    745: 
                    746:     return 0;
                    747: }
                    748: 
                    749: sub ProcessClassList {
                    750:     my ($classlist,$courseID,$ChartDB,$c)=@_;
                    751:     my @names=();
                    752: 
                    753:     my %CacheData;
                    754:     if(tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_WRCREAT,0640)) {
                    755:         foreach my $name (keys(%$classlist)) {
1.48      stredwic  756:             if($name =~ /\:section/ || $name =~ /\:studentInformation/ ||
                    757:                $name eq '') {
1.44      stredwic  758:                 next;
                    759:             }
                    760:             if($c->aborted()) {
                    761:                 last;
                    762:             }
                    763:             push(@names,$name);
                    764:             &ProcessStudentInformation(
                    765:                                     \%CacheData,
                    766:                                     $classlist->{$name.':studentInformation'},
                    767:                                     $classlist->{$name.':section'},
                    768:                                     $classlist->{$name},
                    769:                                     $name,$courseID,$c);
                    770:         }
                    771: 
                    772: 	untie(%CacheData);
                    773:     }
                    774: 
                    775:     return @names;
                    776: }
                    777: 
                    778: # ----- END PROCESSING FUNCTIONS ---------------------------------------
                    779: 
                    780: # ----- HELPER FUNCTIONS -----------------------------------------------
                    781: 
                    782: sub SpaceColumns {
                    783:     my ($students,$studentInformation,$headings,$ChartDB)=@_;
                    784: 
                    785:     my %CacheData;
                    786:     if(tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_WRCREAT,0640)) {
                    787:         # Initialize Lengths
                    788:         for(my $index=0; $index<(scalar @$headings); $index++) {
                    789: 	    my @titleLength=split(//,$$headings[$index]);
                    790: 	    $CacheData{$$studentInformation[$index].'Length'}=
                    791:                 scalar @titleLength;
                    792: 	}
                    793: 
                    794:         foreach my $name (@$students) {
                    795:             foreach (@$studentInformation) {
                    796: 		my @dataLength=split(//,$CacheData{$name.':'.$_});
                    797: 		my $length=scalar @dataLength;
                    798: 		if($length > $CacheData{$_.'Length'}) {
                    799: 		    $CacheData{$_.'Length'}=$length;
                    800: 		}
                    801:             }
                    802:         }
                    803:         untie(%CacheData);
                    804:     }
                    805: 
                    806:     return;
                    807: }
                    808: 
1.43      stredwic  809: sub ProcessFullName {
1.44      stredwic  810:     my ($lastname, $generation, $firstname, $middlename)=@_;
1.43      stredwic  811:     my $Str = '';
                    812: 
1.44      stredwic  813:     if($lastname ne '') {
                    814: 	$Str .= $lastname.' ';
                    815: 	if($generation ne '') {
                    816: 	    $Str .= $generation;
1.43      stredwic  817: 	} else {
                    818: 	    chop($Str);
                    819: 	}
                    820: 	$Str .= ', ';
1.44      stredwic  821: 	if($firstname ne '') {
                    822: 	    $Str .= $firstname.' ';
1.43      stredwic  823: 	}
1.44      stredwic  824: 	if($middlename ne '') {
                    825: 	    $Str .= $middlename;
1.40      stredwic  826: 	} else {
1.43      stredwic  827: 	    chop($Str);
1.44      stredwic  828: 	    if($firstname eq '') {
1.43      stredwic  829: 		chop($Str);
1.31      minaeibi  830: 	    }
1.30      minaeibi  831: 	}
1.43      stredwic  832:     } else {
1.44      stredwic  833: 	if($firstname ne '') {
                    834: 	    $Str .= $firstname.' ';
1.43      stredwic  835: 	}
1.44      stredwic  836: 	if($middlename ne '') {
                    837: 	    $Str .= $middlename.' ';
1.43      stredwic  838: 	}
1.44      stredwic  839: 	if($generation ne '') {
                    840: 	    $Str .= $generation;
1.43      stredwic  841: 	} else {
                    842: 	    chop($Str);
                    843: 	}
                    844:     }
                    845: 
                    846:     return $Str;
                    847: }
1.30      minaeibi  848: 
1.44      stredwic  849: sub SortStudents {
1.48      stredwic  850:     my ($students,$CacheData)=@_;
1.44      stredwic  851: 
                    852:     my @sorted1Students=();
1.48      stredwic  853:     foreach (@$students) {
1.44      stredwic  854:         my ($end,$start)=split(/\:/,$CacheData->{$_.':date'});
                    855:         my $active=1;
                    856:         my $now=time;
1.51      stredwic  857:         my $Status=$CacheData->{'form.status'};
1.44      stredwic  858:         $Status = ($Status) ? $Status : 'Active';
                    859:         if((($end) && $now > $end) && (($Status eq 'Active'))) { 
                    860:             $active=0; 
                    861:         }
                    862:         if(($Status eq 'Expired') && ($end == 0 || $now < $end)) {
                    863:             $active=0;
                    864:         }
                    865:         if($active) {
                    866:             push(@sorted1Students, $_);
                    867:         }
1.43      stredwic  868:     }
1.1       www       869: 
1.51      stredwic  870:     my $Pos = $CacheData->{'form.sort'};
1.43      stredwic  871:     my %sortData;
                    872:     if($Pos eq 'Last Name') {
1.44      stredwic  873: 	for(my $index=0; $index<scalar @sorted1Students; $index++) {
                    874: 	    $sortData{$CacheData->{$sorted1Students[$index].':fullname'}}=
                    875: 		$sorted1Students[$index];
1.43      stredwic  876: 	}
                    877:     } elsif($Pos eq 'Section') {
1.44      stredwic  878: 	for(my $index=0; $index<scalar @sorted1Students; $index++) {
                    879: 	    $sortData{$CacheData->{$sorted1Students[$index].':section'}.
                    880: 		      $sorted1Students[$index]}=$sorted1Students[$index];
1.43      stredwic  881: 	}
                    882:     } else {
                    883: 	# Sort by user name
1.44      stredwic  884: 	for(my $index=0; $index<scalar @sorted1Students; $index++) {
                    885: 	    $sortData{$sorted1Students[$index]}=$sorted1Students[$index];
1.43      stredwic  886: 	}
                    887:     }
                    888: 
                    889:     my @order = ();
1.48      stredwic  890:     foreach my $key (sort(keys(%sortData))) {
1.43      stredwic  891: 	push (@order,$sortData{$key});
                    892:     }
1.33      minaeibi  893: 
1.43      stredwic  894:     return @order;
1.30      minaeibi  895: }
1.1       www       896: 
1.44      stredwic  897: sub TestCacheData {
                    898:     my ($ChartDB)=@_;
                    899:     my $isCached=-1;
                    900:     my %testData;
                    901:     my $tieTries=0;
1.43      stredwic  902: 
1.51      stredwic  903:     if ((-e "$ChartDB") && (!defined($ENV{'form.recalculate'}))) {
1.44      stredwic  904: 	$isCached = 1;
                    905:     } else {
                    906: 	$isCached = 0;
1.43      stredwic  907:     }
                    908: 
1.51      stredwic  909:     while($tieTries < 10) {
1.44      stredwic  910:         my $result=0;
                    911:         if($isCached) {
                    912:             $result=tie(%testData,'GDBM_File',$ChartDB,&GDBM_READER,0640);
                    913:         } else {
                    914:             $result=tie(%testData,'GDBM_File',$ChartDB,&GDBM_NEWDB,0640);
                    915:         }
                    916:         if($result) {
                    917:             last;
                    918:         }
                    919:         $tieTries++;
                    920:         sleep 1;
                    921:     }
1.51      stredwic  922:     if($tieTries >= 10) {
1.44      stredwic  923:         return -1;
1.43      stredwic  924:     }
                    925: 
1.44      stredwic  926:     untie(%testData);
1.30      minaeibi  927: 
1.44      stredwic  928:     return $isCached;
1.43      stredwic  929: }
1.30      minaeibi  930: 
1.44      stredwic  931: sub ExtractStudentData {
                    932:     my ($courseData, $name, $ChartDB)=@_;
                    933: 
                    934:     my %CacheData;
                    935:     if(tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_WRCREAT,0640)) {
                    936:         my ($checkForError) = keys(%$courseData);
                    937:         if($checkForError =~ /^(con_lost|error|no_such_host)/i) {
                    938:             $CacheData{$name.':error'}='Could not download course data.';
                    939:         } else {
                    940:             foreach my $key (keys (%$courseData)) {
                    941:                 $CacheData{$name.':'.$key}=$courseData->{$key};
                    942:             }
1.48      stredwic  943:             if(defined($CacheData{'NamesOfStudents'})) {
                    944:                 $CacheData{'NamesOfStudents'}.=':::'.$name;
                    945:             } else {
                    946:                 $CacheData{'NamesOfStudents'}=$name;
                    947:             }
1.44      stredwic  948:         }
                    949:         untie(%CacheData);
1.30      minaeibi  950:     }
1.1       www       951: 
1.44      stredwic  952:     return;
                    953: }
                    954: 
1.49      stredwic  955: sub ShouldShowColumn {
1.51      stredwic  956:     my ($cache,$test)=@_;
1.49      stredwic  957: 
1.51      stredwic  958:     if($cache->{'form.reset'} eq 'true') {
1.49      stredwic  959:         return 1;
                    960:     }
                    961: 
1.51      stredwic  962:     my $headings=$cache->{'form.headings'};
                    963:     my $sequences=$cache->{'form.sequences'};
                    964:     if($headings eq 'ALLHEADINGS' || $sequences eq 'ALLSEQUENCES' ||
                    965:        $headings=~/$test/ || $sequences=~/$test/) {
1.49      stredwic  966:         return 1;
                    967:     }
                    968: 
1.51      stredwic  969: #    my $reselected=$cache->{'form.reselect'};
                    970: #    if($reselected=~/$test/) {
                    971: #        return 1;
                    972: #    }
                    973: 
                    974:     return 0;
1.49      stredwic  975: }
                    976: 
1.51      stredwic  977: sub ProcessFormData {
                    978:     my ($ChartDB)=@_;
                    979:     my %CacheData;
                    980: 
                    981:     if(tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_WRCREAT,0640)) {
                    982:         if(defined($ENV{'form.sort'})) {
                    983:             $CacheData{'form.sort'}=$ENV{'form.sort'};
                    984:         } elsif(!defined($CacheData{'form.sort'})) {
                    985:             $CacheData{'form.sort'}='username';
                    986:         }
                    987: 
                    988:         # Ignore $ENV{'form.refresh'}
                    989:         # Ignore $ENV{'form.recalculate'}
                    990: 
                    991:         if(defined($ENV{'form.status'})) {
                    992:             $CacheData{'form.status'}=$ENV{'form.status'};
                    993:         } elsif(!defined($CacheData{'form.status'})) {
                    994:             $CacheData{'form.status'}='Active';
                    995:         }
                    996: 
                    997:         my @headings=();
                    998:         my @sequences=();
                    999:         my $found=0;
                   1000:         foreach (keys(%ENV)) {
                   1001:             if(/form\.heading/) {
                   1002:                 $found++;
                   1003:                 push(@headings, $_);
                   1004:             } elsif(/form\.sequence/) {
                   1005:                 $found++;
                   1006:                 push(@sequences, $_);
                   1007:             } elsif(/form\./) {
                   1008:                 $found++;
                   1009:             }
                   1010:         }
                   1011: 
                   1012:         if($found) {
                   1013:             $CacheData{'form.headings'}=join(":::",@headings);
                   1014:             $CacheData{'form.sequences'}=join(":::",@sequences);
                   1015:         }
                   1016: 
                   1017:         if(defined($ENV{'form.reselect'})) {
                   1018:             my @reselected = (ref($ENV{'form.reselect'}) ? 
                   1019:                               @{$ENV{'form.reselect'}}
                   1020:                               : ($ENV{'form.reselect'}));
                   1021:             foreach (@reselected) {
                   1022:                 if(/heading/) {
                   1023:                     $CacheData{'form.headings'}.=":::".$_;
                   1024:                 } elsif(/sequence/) {
                   1025:                     $CacheData{'form.sequences'}.=":::".$_;
                   1026:                 }
                   1027:             }
1.49      stredwic 1028:         }
1.51      stredwic 1029: 
                   1030:         if(defined($ENV{'form.reset'})) {
                   1031:             $CacheData{'form.reset'}='true';
                   1032:             $CacheData{'form.status'}='Active';
                   1033:             $CacheData{'form.sort'}='username';
                   1034:             $CacheData{'form.headings'}='ALLHEADINGS';
                   1035:             $CacheData{'form.sequences'}='ALLSEQUENCES';
                   1036:         } else {
                   1037:             $CacheData{'form.reset'}='false';
                   1038:         }
                   1039: 
                   1040:         untie(%CacheData);
1.49      stredwic 1041:     }
1.51      stredwic 1042: 
                   1043:     return;
1.49      stredwic 1044: }
                   1045: 
1.44      stredwic 1046: # ----- END HELPER FUNCTIONS --------------------------------------------
                   1047: 
                   1048: sub BuildChart {
                   1049:     my ($r)=@_;
                   1050:     my $c = $r->connection;
1.1       www      1051: 
1.44      stredwic 1052:     # Start the lonchart document
                   1053:     $r->content_type('text/html');
                   1054:     $r->send_http_header;
                   1055:     $r->print(&StartDocument());
                   1056:     $r->rflush();
1.43      stredwic 1057: 
1.44      stredwic 1058:     # Test for access to the CacheData
                   1059:     my $isCached=0;
1.43      stredwic 1060:     my $cid=$ENV{'request.course.id'};
                   1061:     my $ChartDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
                   1062:                   "_$ENV{'user.domain'}_$cid\_chart.db";
1.44      stredwic 1063: 
                   1064:     $isCached=&TestCacheData($ChartDB);
                   1065:     if($isCached < 0) {
                   1066:         $r->print("Unable to tie hash to db file");
                   1067:         $r->rflush();
                   1068:         return;
                   1069:     }
1.51      stredwic 1070:     &ProcessFormData($ChartDB);
1.44      stredwic 1071: 
                   1072:     # Download class list information if not using cached data
1.48      stredwic 1073:     my %CacheData;
1.44      stredwic 1074:     my @students=();
                   1075:     my @studentInformation=('username','domain','section','id','fullname');
                   1076:     my @headings=('User Name','Domain','Section','PID','Full Name');
                   1077:     my $spacePadding='   ';
                   1078:     if(!$isCached) {
                   1079:         my $processTopResourceMapReturn=&ProcessTopResourceMap($ChartDB,$c);
                   1080:         if($processTopResourceMapReturn ne 'OK') {
                   1081:             $r->print($processTopResourceMapReturn);
                   1082:             return;
                   1083:         }
                   1084:         if($c->aborted()) { return; }
                   1085:         my $classlist=&DownloadPrerequisiteData($cid, $c);
                   1086:         my ($checkForError)=keys(%$classlist);
                   1087:         if($checkForError =~ /^(con_lost|error|no_such_host)/i ||
                   1088:            defined($classlist->{'error'})) {
                   1089:             return;
                   1090:         }
                   1091:         if($c->aborted()) { return; }
                   1092:         @students=&ProcessClassList($classlist,$cid,$ChartDB,$c);
                   1093:         if($c->aborted()) { return; }
                   1094:         &SpaceColumns(\@students,\@studentInformation,\@headings,
                   1095:                       $ChartDB);
                   1096:         if($c->aborted()) { return; }
1.48      stredwic 1097:     } else {
                   1098:         if(!$c->aborted() && tie(%CacheData,'GDBM_File',$ChartDB,
                   1099:                                  &GDBM_READER,0640)) {
                   1100:             @students=split(/:::/,$CacheData{'NamesOfStudents'});
                   1101:         }
1.44      stredwic 1102:     }
                   1103: 
                   1104:     # Sort students and print out table desciptive data
                   1105:     if(tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_READER,0640)) {
1.48      stredwic 1106:         if(!$c->aborted()) { @students=&SortStudents(\@students,\%CacheData); }
1.50      stredwic 1107:         if(!$c->aborted()) { $r->print('<h1>'.(scalar @students).
                   1108:                                        ' students</h1>'); }
                   1109: 	if(!$c->aborted()) { $r->rflush(); }
1.44      stredwic 1110: 	if(!$c->aborted()) { $r->print(&CreateLegend()); }
1.51      stredwic 1111: 	if(!$c->aborted()) { $r->print(&CreateForm(\%CacheData)); }
1.49      stredwic 1112: 	if(!$c->aborted()) { $r->print(&CreateColumnSelectionBox(
                   1113:                                                        \%CacheData,
                   1114:                                                        \@studentInformation, 
                   1115: 						       \@headings, 
                   1116:                                                        $spacePadding)); }
                   1117: 	if(!$c->aborted()) { $r->print(&CreateColumnSelectors(
                   1118:                                                        \%CacheData,
                   1119:                                                        \@studentInformation, 
                   1120: 						       \@headings, 
                   1121:                                                        $spacePadding)); }
1.44      stredwic 1122: 	if(!$c->aborted()) { $r->print(&CreateTableHeadings(
                   1123:                                                          \%CacheData,
                   1124:                                                          \@studentInformation, 
                   1125: 							 \@headings, 
                   1126: 							 $spacePadding)); }
1.49      stredwic 1127: 	if(!$c->aborted()) { $r->rflush(); }
1.44      stredwic 1128: 	untie(%CacheData);
1.43      stredwic 1129:     } else {
1.44      stredwic 1130: 	$r->print("Init2: Unable to tie hash to db file");
                   1131: 	return;
1.43      stredwic 1132:     }
                   1133: 
                   1134:     my @updateStudentList = ();
1.44      stredwic 1135:     my $courseData;
1.50      stredwic 1136:     $r->print('<pre>');
1.44      stredwic 1137:     foreach (@students) {
                   1138:         if($c->aborted()) {
                   1139:             last;
                   1140:         }
                   1141: 
                   1142:         if(!$isCached) {
                   1143:             $courseData=&DownloadStudentCourseInformation($_, $cid);
1.50      stredwic 1144:             if($c->aborted()) { last; }
1.44      stredwic 1145:             push(@updateStudentList, $_);
                   1146:             &ExtractStudentData($courseData, $_, $ChartDB);
                   1147:         }
1.51      stredwic 1148:         $r->print(&FormatStudentData($_, $cid, \@studentInformation,
1.44      stredwic 1149:                                      $spacePadding, $ChartDB));
                   1150:         $r->rflush();
1.43      stredwic 1151:     }
                   1152: 
1.50      stredwic 1153:     if(!$isCached && tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_WRCREAT,0640)) {
                   1154:         $CacheData{'NamesOfStudents'}=join(":::", @updateStudentList);
                   1155: #		    $CacheData{'NamesOfStudents'}=
                   1156: #		            &Apache::lonnet::arrayref2str(\@updateStudentList);
                   1157:         untie(%CacheData);
                   1158:     }
                   1159: 
                   1160:     $r->print('</pre></body></html>');
1.30      minaeibi 1161:     $r->rflush();
1.1       www      1162: 
1.43      stredwic 1163:     return;
1.30      minaeibi 1164: }
1.1       www      1165: 
1.30      minaeibi 1166: # ================================================================ Main Handler
1.1       www      1167: 
1.30      minaeibi 1168: sub handler {
1.44      stredwic 1169:     my $r=shift;
1.51      stredwic 1170: #    $jr=$r;
1.44      stredwic 1171:     unless(&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
1.30      minaeibi 1172: 	$ENV{'user.error.msg'}=
1.1       www      1173:         $r->uri.":vgr:0:0:Cannot view grades for complete course";
1.30      minaeibi 1174: 	return HTTP_NOT_ACCEPTABLE; 
                   1175:     }
1.44      stredwic 1176: 
                   1177:     # Set document type for header only
                   1178:     if ($r->header_only) {
                   1179:         if($ENV{'browser.mathml'}) {
                   1180:             $r->content_type('text/xml');
                   1181:         } else {
                   1182:             $r->content_type('text/html');
                   1183:         }
                   1184:         &Apache::loncommon::no_cache($r);
                   1185:         $r->send_http_header;
                   1186:         return OK;
                   1187:     }
                   1188:     
                   1189:     unless($ENV{'request.course.fn'}) {
                   1190:         my $requrl=$r->uri;
                   1191:         $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
                   1192:         return HTTP_NOT_ACCEPTABLE; 
                   1193:     }
                   1194: 
                   1195:     &BuildChart($r);
                   1196: 
                   1197:     return OK;
1.1       www      1198: }
                   1199: 1;
                   1200: __END__

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