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

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

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