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

1.1       www         1: # The LearningOnline Network with CAPA
1.25      minaeibi    2: # (Publication Handler
                      3: #
1.42    ! stredwic    4: # $Id: lonchart.pm,v 1.41 2002/06/03 19:28:17 albertel 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: 
                     49: package Apache::lonchart;
                     50: 
                     51: use strict;
                     52: use Apache::Constants qw(:common :http);
                     53: use Apache::lonnet();
1.28      albertel   54: use Apache::loncommon();
1.1       www        55: use HTML::TokeParser;
                     56: use GDBM_File;
                     57: 
                     58: # -------------------------------------------------------------- Module Globals
                     59: my %hash;
1.30      minaeibi   60: my %CachData;
1.1       www        61: my @cols;
                     62: my @rowlabels;
                     63: my @students;
1.30      minaeibi   64: my @PreCol;
                     65: my $r;
1.33      minaeibi   66:  
1.1       www        67: # ------------------------------------------------------------- Find out status
                     68: 
1.5       minaeibi   69: sub ExtractStudentData {
                     70:     my ($index,$coid)=@_;
                     71:     my ($sname,$sdom) = split( /\:/, $students[$index] );
1.39      stredwic   72:     my %result=&Apache::lonnet::dump($coid,$sdom,$sname);
1.5       minaeibi   73:     my $ResId;
                     74:     my $Code;
                     75:     my $Tries;
                     76:     my $Wrongs;
1.7       minaeibi   77:     my %TempHash;
1.5       minaeibi   78:     my $Version;
1.10      minaeibi   79:     my $ProbNo;
1.26      minaeibi   80:     my $ProbSolved;
                     81:     my $ProbTotal;
1.22      minaeibi   82:     my $LatestVersion;                     
1.5       minaeibi   83:     my $Str=substr($students[$index].
                     84:             '                                                        ',0,14).' ! '.
                     85:             substr($rowlabels[$index].
                     86:             '                                                        ',0,45).' ! ';
1.39      stredwic   87: 
1.40      stredwic   88:     my($checkForError)=keys (%result);
                     89:     if($checkForError =~ /^(con_lost|error|no_such_host)/i) {
                     90: 	my $PrTot = sprintf( "%5d", $ProbTotal );
                     91: 	my $PrSvd = sprintf( "%5d", $ProbSolved );
                     92: 	$Str .= ' '.'<font color="#000088">'.$PrSvd.'  /'.$PrTot.'</font> ';
                     93: 	return $Str;
                     94:     }
                     95: 
1.39      stredwic   96:     $ProbNo = 0;
                     97:     $ProbTotal = 0;
                     98:     $ProbSolved = 0;
                     99:     my $IterationNo = 0;
                    100:     foreach $ResId (@cols) {
                    101: 	if ($IterationNo == 0) {$IterationNo++; next;}
                    102: 	if (!$ResId) { 
                    103: 	    my $PrNo = sprintf( "%3d", $ProbNo );
                    104: 	    $Str .= ' '.'<font color="#007700">'.$PrNo.'</font> ';
                    105: 	    $ProbSolved += $ProbNo;
                    106: 	    $ProbNo=0;
                    107: 	    next; 
                    108: 	}
                    109: 	$ResId=~/(\d+)\.(\d+)/;
                    110: 	my $meta=$hash{'src_'.$ResId};
                    111: 	my $PartNo = 0;
                    112: 	undef %TempHash;
                    113: 	foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
                    114: 	    if ($_=~/^stores\_(\d+)\_tries$/) {
                    115: 		my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
                    116: 		if ( $TempHash{"$Part"} eq '' ) { 
                    117: 		    $TempHash{"$Part"} = $Part;
                    118: 		    $TempHash{$PartNo}=$Part;
                    119: 		    $TempHash{"$Part.Code"} = ' ';  
                    120: 		    $PartNo++;
                    121: 		}
1.10      minaeibi  122: 	    }
1.39      stredwic  123: 	}
1.11      minaeibi  124: 
1.39      stredwic  125: 	my $Prob = &Apache::lonnet::symbclean(
                    126: 		       &Apache::lonnet::declutter($hash{'map_id_'.$1} ).
1.5       minaeibi  127:                        '___'.$2.'___'.
1.38      www       128:                        &Apache::lonnet::declutter( $hash{'src_'.$ResId} ));
1.39      stredwic  129: 	$Code=' ';
                    130: 	$Tries = 0;
                    131: 	$LatestVersion = $result{"version:$Prob"};
                    132: 
                    133: 	if ( $LatestVersion ) {
                    134: 	    for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) {
                    135: 		my $vkeys = $result{"$Version:keys:$Prob"};
                    136: 		my @keys = split(/\:/,$vkeys);		  
                    137: 
                    138: 		foreach my $Key (@keys) {		  
                    139: 		    if (($Key=~/\.(\w+)\.solved$/) && ($Key!~/^\d+\:/)) {
                    140: 			my $Part = $1;
                    141: 			$Tries = $result{"$Version:$Prob:resource.$Part.tries"};
                    142: 			$TempHash{"$Part.Tries"}=($Tries) ? $Tries : 0;
                    143: 			my $Val = $result{"$Version:$Prob:resource.$Part.solved"};
                    144: 			if ($Val eq 'correct_by_student'){$Code='*';} 
                    145: 			elsif ($Val eq 'correct_by_override'){$Code = '+';}
                    146: 			elsif ($Val eq 'incorrect_attempted'){$Code = '.';} 
                    147: 			elsif ($Val eq 'incorrect_by_override'){$Code = '-';}
                    148: 			elsif ($Val eq 'excused'){$Code = 'x';}
                    149: 			elsif ($Val eq 'ungraded_attempted'){$Code = '#';}
                    150: 			else {$Code = ' ';}
                    151: 
                    152: 			$TempHash{"$Part.Code"} = $Code;
                    153: 		    }
                    154: 		}
                    155: 	    }
1.38      www       156: # Actually append problem to output (all parts)
1.39      stredwic  157: 	    $Str.='<a href="/adm/grades?symb='.
1.38      www       158:                 &Apache::lonnet::escape($Prob).
                    159:                 '&student='.$sname.'&domain='.$sdom.'&command=submission">'; 
1.39      stredwic  160: 	    for ( my $n = 0; $n < $PartNo; $n++ ) {		  
                    161: 		my $part = $TempHash{$n};
                    162: 		my $Code = $TempHash{"$part.Code"};
                    163: 		if ( $Code eq '*') {
                    164: 		    $ProbNo++;
                    165: 		    if (($TempHash{"$part.Tries"}<10) ||
                    166: 			($TempHash{"$part.Tries"} eq '')) {
                    167: 			$TempHash{"$part.Code"}=$TempHash{"$part.Tries"};
                    168: 		    }
1.26      minaeibi  169: 		}
1.39      stredwic  170: 		elsif ( $Code eq '+' ) {$ProbNo++;}
                    171: 		$Str .= $TempHash{"$part.Code"};
                    172: 		if ( $Code ne 'x' ) {$ProbTotal++;}
                    173: 	    }
                    174: 	    $Str.='</a>';
                    175: 	} else {
                    176: 	    for(my $n=0; $n<$PartNo; $n++) {
                    177: 		$Str.=' ';
                    178: 		$ProbTotal++;
1.26      minaeibi  179: 	    }
1.39      stredwic  180: 	}
1.1       www       181:     }
1.39      stredwic  182: 
1.26      minaeibi  183:     my $PrTot = sprintf( "%5d", $ProbTotal );
                    184:     my $PrSvd = sprintf( "%5d", $ProbSolved );
                    185:     $Str .= ' '.'<font color="#000088">'.$PrSvd.'  /'.$PrTot.'</font> ';
1.11      minaeibi  186: 
1.10      minaeibi  187:     return $Str ;
1.1       www       188: }
                    189: 
1.5       minaeibi  190: 
1.1       www       191: # ------------------------------------------------------------ Build page table
                    192: 
                    193: sub tracetable {
                    194:     my ($rid,$beenhere)=@_;
                    195:     unless ($beenhere=~/\&$rid\&/) {
                    196:        $beenhere.=$rid.'&';  
1.7       minaeibi  197: # new ... updating the map according to sequence and page
1.1       www       198:        if (defined($hash{'is_map_'.$rid})) {
1.7       minaeibi  199: 	   my $cmap=$hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}};
                    200:            if ( $cmap eq 'sequence' || $cmap eq 'page' ) { 
1.1       www       201:                $cols[$#cols+1]=0; 
                    202:            }
                    203:            if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
                    204:                (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
                    205:               my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
                    206: 
                    207:                 &tracetable($hash{'map_start_'.$hash{'src_'.$rid}},
                    208:                 '&'.$frid.'&');
                    209: 
                    210:               if ($hash{'src_'.$frid}) {
                    211:                  if ($hash{'src_'.$frid}=~
                    212:                                  /\.(problem|exam|quiz|assess|survey|form)$/) {
                    213: 		     $cols[$#cols+1]=$frid;
                    214:                  }
                    215: 	      }
                    216: 
                    217: 	   }
                    218:        } else {
                    219:           if ($hash{'src_'.$rid}) {
                    220:              if ($hash{'src_'.$rid}=~
                    221:                                  /\.(problem|exam|quiz|assess|survey|form)$/) {
                    222: 	         $cols[$#cols+1]=$rid;
                    223:              }
                    224:           }
                    225:        }
                    226:        if (defined($hash{'to_'.$rid})) {
1.31      minaeibi  227:           foreach (split(/\,/,$hash{'to_'.$rid})){
1.1       www       228:               &tracetable($hash{'goesto_'.$_},$beenhere);
1.31      minaeibi  229:           }
1.1       www       230:        }
                    231:     }
                    232: }
1.33      minaeibi  233: 
                    234: sub usection {
1.36      minaeibi  235:     my ($udom,$unam,$courseid,$ActiveFlag)=@_;
1.33      minaeibi  236:     $courseid=~s/\_/\//g;
                    237:     $courseid=~s/^(\w)/\/$1/;
1.39      stredwic  238: 
                    239:     my %result=&Apache::lonnet::dump('roles',$udom,$unam);
1.40      stredwic  240: 
                    241:     my($checkForError)=keys (%result);
                    242:     if($checkForError =~ /^(con_lost|error|no_such_host)/i) {
                    243: 	return -1;
                    244:     }
1.41      albertel  245:     my $cursection='-1';
                    246:     my $oldsection='-1';
                    247:     my $status='Expired';
1.39      stredwic  248:     foreach my $key (keys (%result)) {
                    249: 	my $value = $result{$key};
1.33      minaeibi  250:         if ($key=~/^$courseid(?:\/)*(\w+)*\_st$/) {
                    251:             my $section=$1;
                    252:             if ($key eq $courseid.'_st') { $section=''; }
1.39      stredwic  253: 	    my ($dummy,$end,$start)=split(/\_/,$value);
1.41      albertel  254: 	    my $now=time;
                    255: 	    my $notactive=0;
                    256: 	    if ($start) { if ($now<$start) { $notactive=1; } }
                    257: 	    if ($end) { if ($now>$end) { $notactive=1; } }
                    258: 	    if ($notactive == 0) { $status='Active';$cursection=$section;}
                    259: 	    if ($notactive == 1) { $oldsection=$section;}
1.33      minaeibi  260:         }
1.34      minaeibi  261:     }
1.41      albertel  262:     if ($status eq $ActiveFlag) {
                    263:       if ($cursection eq '-1') { return $oldsection; }
                    264:       return $cursection;
                    265:     }
                    266:     if ($ActiveFlag eq 'Any') { 
                    267:       if ($cursection eq '-1') { return $oldsection; }
                    268:       return $cursection;
                    269:     }
1.36      minaeibi  270:     return '-1';
1.33      minaeibi  271: }
                    272: 
1.30      minaeibi  273: sub BuildChart {
                    274: # ----------------------- Get first and last resource, see if there is anything
                    275:     my $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}};
                    276:     my $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}};
                    277:     if (($firstres) && ($lastres)) {
                    278: # ----------------------------------------------------------------- Render page
                    279: 	my $cid=$ENV{'request.course.id'};
                    280:         my $chome=$ENV{'course.'.$cid.'.home'};
                    281:         my ($cdom,$cnum)=split(/\_/,$cid);
                    282: # ---------------------------------------------- Read class list and row labels
1.39      stredwic  283: 	my %classlist=&Apache::lonnet::dump('classlist',$cdom,$cnum);
1.40      stredwic  284: 
                    285: 	my($checkForError)=keys (%classlist);
                    286: 	if($checkForError =~ /^(con_lost|error|no_such_host)/i) {
                    287: 	    $r->print('<h1>Could not access course data</h1>');
                    288: 	} else {
                    289: 	    my $now=time;
1.41      albertel  290: 	    foreach my $name (sort(keys(%classlist))) {
1.40      stredwic  291: 		my $value=$classlist{$name};
                    292: 		my ($end,$start)=split(/\:/,$value);
                    293: 		my $active=1;
                    294: 		my $Status=$ENV{'form.status'};
                    295: 		$Status = ($Status) ? $Status : 'Active';
                    296: 		if ( ( ($end) && $now > $end ) && 
                    297: 		     ( ($Status eq 'Active') ) ) { $active=0; }
                    298: 		if ( ($Status eq 'Expired') && 
                    299: 		     ($end == 0 || $now < $end) ) { $active=0; }
                    300: 		if ($active) {
                    301: 		    my $thisindex=$#students+1;
                    302: 		    $students[$thisindex]=$name;
                    303: 		    my ($sname,$sdom)=split(/\:/,$name);
                    304: 		    $PreCol[$thisindex]=$sname.':';
                    305: 		    my $ssec=&usection($sdom,$sname,$cid,$Status);
                    306: 		    if ($ssec==-1) {
                    307: 			$rowlabels[$thisindex]=
                    308: 			    'Data not available: '.$name;
                    309: 		    } else {
                    310: 			my %reply=&Apache::lonnet::idrget($sdom,$sname);
1.41      albertel  311: 			my %name=&Apache::lonnet::get('environment',
1.40      stredwic  312: 						       ['lastname','generation'
                    313: 						       ,'firstname'
                    314: 						       ,'middlename'],
                    315: 						       $sdom,$sname);
1.42    ! stredwic  316: 			my $name=$name{'lastname'};
        !           317: 			if ($name{'generation'}) {$name.=" $name{generation}";}
1.41      albertel  318: 			$name.=',';
1.42    ! stredwic  319: 			if ($name{'firstname'}) {$name.=" $name{firstname}";}
        !           320: 			if ($name{'middlename'}) {$name.=" $name{middlename}";}
1.41      albertel  321: 			if ($name eq ',') {$name='';}
1.40      stredwic  322: 			#$ssec=(int($ssec)) ? int($ssec) : $ssec;
                    323: 			my $sec=sprintf('%3s',$ssec);
                    324: 			$rowlabels[$thisindex]=$sec.' '.$reply{$sname}.' ';
1.41      albertel  325: 			$PreCol[$thisindex] .= $name.':'.$sec;
                    326: 			$rowlabels[$thisindex].=$name.' ';
1.30      minaeibi  327: 		    }
                    328: 		}
1.31      minaeibi  329: 	    }
1.30      minaeibi  330: 	}
                    331: 
                    332: 	my $allstudents=$#students+1;
                    333: 	$r->print('<h3>'.$allstudents.' students</h3>');
                    334: 	&CreateForm();
                    335: 	$r->rflush();
1.24      minaeibi  336: 
1.30      minaeibi  337: # --------------- Find all assessments and put them into some linear-like order
                    338: 	&tracetable($firstres,'&'.$lastres.'&');
                    339: # ----------------------------------------------------------------- Start table
1.1       www       340: 
1.30      minaeibi  341:         $r->print('<p><pre>');
                    342:  	my $index;
                    343:         for ($index=0;$index<=$#students;$index++) {
                    344: 	    my $Str=&ExtractStudentData($index,$cid);
                    345: 	    $r->print($Str.'<br>');
                    346:             $r->rflush();
                    347: 	    $CachData{$PreCol[$index]}=$Str;
                    348:         }
                    349:         $r->print('</pre>');
                    350:     } else {
                    351: 	$r->print('<h3>Undefined course sequence</h3>');
                    352:     }
                    353: }
1.1       www       354: 
1.30      minaeibi  355: sub CreateForm {
1.33      minaeibi  356:     my $OpSel1='';
                    357:     my $OpSel2='';
1.36      minaeibi  358:     my $OpSel3='';
                    359:     my $Status = $ENV{'form.status'};
                    360:     if ( $Status eq 'Any' ) { $OpSel3='selected'; }
                    361:     elsif ($Status eq 'Expired' ) { $OpSel2 = 'selected'; }
1.33      minaeibi  362:     else { $OpSel1 = 'selected'; }
                    363: 
1.30      minaeibi  364:     my $Ptr = '<form name=stat method=post action="/adm/chart" >'."\n";
                    365:     $Ptr .= '<b> Sort by: &nbsp; </b>'."\n";
                    366:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
1.33      minaeibi  367:     $Ptr .= '<input type=submit name=sort value="User Name" />'."\n";
1.30      minaeibi  368:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
                    369:     $Ptr .= '<input type=submit name=sort value="Last Name" />'."\n";
                    370:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
                    371:     $Ptr .= '<input type=submit name=sort value="Section"/>'."\n";
1.33      minaeibi  372:     $Ptr .= '<br><br>';
1.36      minaeibi  373:     $Ptr .= '<b> Student Status: &nbsp; </b>'."\n".
                    374:             '<select name="status">'. 
                    375:             '<option '.$OpSel1.' >Active</option>'."\n".
                    376:             '<option '.$OpSel2.' >Expired</option>'."\n".
                    377: 	    '<option '.$OpSel3.' >Any</option> </select> '."\n";
1.33      minaeibi  378:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
1.30      minaeibi  379:     $Ptr .= '<input type=submit name=sort value="Recalculate Chart"/>'."\n";
                    380:     $Ptr .= '</form>'."\n";
                    381:     $r->print( $Ptr );
                    382: }
1.1       www       383: 
1.30      minaeibi  384: sub CacheChart {
1.35      albertel  385:     my %list = ();
1.30      minaeibi  386:     my $count=0;
                    387: 
                    388:     my $Pos = $ENV{'form.sort'};
                    389:     if ( $Pos eq 'Last Name' ) {$Pos=1;}
                    390:     elsif ( $Pos eq 'Section' ) {$Pos=2;}
                    391:     else {$Pos=0;}
                    392: 
                    393:     foreach my $key( keys %CachData) { 
                    394: 	my @Temp=split(/\:/,$key);
                    395: 	my $Use = $Temp[$Pos];
1.35      albertel  396: 	$list{$Use.$key}=$key;
1.30      minaeibi  397: 	$count++;
                    398:     }
1.1       www       399: 
1.35      albertel  400:     my @order = sort(keys(%list));
1.1       www       401: 
1.30      minaeibi  402:     $r->print('<h3>'.$count.' students</h3>');
                    403:     &CreateForm();
                    404:     $r->rflush();
                    405:     
                    406:     $r->print('<p><pre>');
                    407:     for ( my $n; $n < $count; $n++) {
1.35      albertel  408: 	$r->print($CachData{$list{$order[$n]}}.'<br>');
1.30      minaeibi  409:     }	
                    410:     $r->print('</pre>');
                    411: }
1.1       www       412: 
1.30      minaeibi  413: sub Start {
                    414:     undef %hash;
                    415:     undef %CachData;
                    416:     undef @students;
                    417:     undef @cols;
                    418:     undef @rowlabels;
                    419:     undef @PreCol;
                    420: 
                    421:     $r->print('<html><head><title>'.
                    422:               'LON-CAPA Assessment Chart</title></head>');
                    423:     $r->print('<body bgcolor="#FFFFFF">'.
                    424:               '<script>window.focus();</script>'.
                    425:               '<img align=right src=/adm/lonIcons/lonlogos.gif>'.
                    426:               '<h1>Assessment Chart</h1>');
1.1       www       427: # ---------------------------------------------------------------- Course title
1.30      minaeibi  428:     $r->print('<h1>'.$ENV{'course.'.$ENV{'request.course.id'}.
                    429:               '.description'}.'</h1><h3>'.localtime().
                    430:               "</h3><p><pre>1..9: correct by student in 1..9 tries\n".
                    431:               "   *: correct by student in more than 9 tries\n".
                    432: 	      "   +: correct by override\n".
                    433:               "   -: incorrect by override\n".
                    434: 	      "   .: incorrect attempted\n".
                    435: 	      "   #: ungraded attempted\n".
                    436:               "    : not attempted\n".
                    437: 	      "   x: excused</pre><p>"); 
1.1       www       438: # ------------------------------- This is going to take a while, produce output
1.30      minaeibi  439:     $r->rflush();
1.1       www       440: 
1.30      minaeibi  441:     my $cid=$ENV{'request.course.id'};
                    442:     my $ChartDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
                    443:                   "_$ENV{'user.domain'}_$cid\_chart.db";
                    444: 
                    445:     if ((-e "$ChartDB") && ($ENV{'form.sort'} ne 'Recalculate Chart')) {
                    446: 	if (tie(%CachData,'GDBM_File',"$ChartDB",&GDBM_READER,0640)) {
                    447: 	    &CacheChart();
                    448: 	}
                    449: 	else {
                    450: 	    $r->print("Unable to tie hash to db file");
                    451: 	}
                    452:     }
                    453:     else {
                    454: 	if (tie(%CachData,'GDBM_File',$ChartDB,&GDBM_WRCREAT,0640)) {
                    455: 	    foreach (keys %CachData) {delete $CachData{$_};}
                    456: 	    &BuildChart();
                    457: 	}
                    458: 	else {
                    459: 	    $r->print("Unable to tie hash to db file");
                    460: 	}
1.1       www       461:     }
1.30      minaeibi  462:     untie(%CachData);
                    463: }
1.1       www       464: 
1.30      minaeibi  465: # ================================================================ Main Handler
1.1       www       466: 
1.30      minaeibi  467: sub handler {
                    468:     $r=shift;
                    469:     if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
                    470: # ------------------------------------------- Set document type for header only
                    471: 	if ($r->header_only) {
                    472: 	    if ($ENV{'browser.mathml'}) {
                    473: 		$r->content_type('text/xml');
                    474: 	    } else {
                    475: 		$r->content_type('text/html');
                    476: 	    }
                    477: 	    &Apache::loncommon::no_cache($r);
                    478: 	    $r->send_http_header;
                    479: 	    return OK;
                    480: 	}
1.1       www       481: 
1.30      minaeibi  482: 	my $requrl=$r->uri;
                    483: # ----------------------------------------------------------------- Tie db file
                    484: 	if ($ENV{'request.course.fn'}) {
                    485: 	    my $fn=$ENV{'request.course.fn'};
                    486: 	    if (-e "$fn.db") {
                    487: 		if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) {
                    488: # ------------------------------------------------------------------- Hash tied
                    489: # ---------------------------------------------------------------- Send headers
                    490: 		    $r->content_type('text/html');
                    491: 		    $r->send_http_header;
                    492: 		    &Start();
                    493: 		    $r->print('</body></html>');                 
1.1       www       494: # ------------------------------------------------------------- End render page
1.30      minaeibi  495: 		} else {
                    496: 		    $r->content_type('text/html');
                    497: 		    $r->send_http_header;
                    498: 		    $r->print('<html><body>Coursemap undefined.</body></html>');
                    499: 		}
1.1       www       500: # ------------------------------------------------------------------ Untie hash
1.30      minaeibi  501: 		unless (untie(%hash)) {
                    502: 		    &Apache::lonnet::logthis("<font color=blue>WARNING: ".
                    503: 			     "Could not untie coursemap $fn (browse).</font>"); 
                    504: 		}
1.1       www       505: 
                    506: # -------------------------------------------------------------------- All done
1.30      minaeibi  507: 		return OK;
1.1       www       508: # ----------------------------------------------- Errors, hash could no be tied
1.30      minaeibi  509: 	    }
                    510: 	} else {
                    511: 	    $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
                    512: 	    return HTTP_NOT_ACCEPTABLE; 
                    513: 	}
                    514:     } else {
                    515: 	$ENV{'user.error.msg'}=
1.1       www       516:         $r->uri.":vgr:0:0:Cannot view grades for complete course";
1.30      minaeibi  517: 	return HTTP_NOT_ACCEPTABLE; 
                    518:     }
1.1       www       519: }
                    520: 1;
                    521: __END__

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