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

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

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