Diff for /loncom/interface/Attic/lonchart.pm between versions 1.34 and 1.43

version 1.34, 2002/02/28 23:25:50 version 1.43, 2002/06/05 05:05:38
Line 25 Line 25
 #  #
 # http://www.lon-capa.org/  # http://www.lon-capa.org/
 #  #
 #  
 # Homework Performance Chart  # Homework Performance Chart
 #  #
 # (Navigate Maps Handler  # (Navigate Maps Handler
Line 60  use GDBM_File; Line 59  use GDBM_File;
 my %hash;  my %hash;
 my %CachData;  my %CachData;
 my @cols;  my @cols;
 my @rowlabels;  
 my @students;  
 my @PreCol;  
 my $r;  my $r;
   my $c;
     
 # ------------------------------------------------------------- Find out status  # ------------------------------------------------------------- Find out status
   
 sub ExtractStudentData {  sub ExtractStudentData {
     my ($index,$coid)=@_;      my ($name,$coid)=@_;
     my ($sname,$sdom) = split( /\:/, $students[$index] );      my ($sname,$sdom) = split(/\:/,$name);
     my $shome=&Apache::lonnet::homeserver( $sname,$sdom );            
     my $reply=&Apache::lonnet::reply('dump:'.$sdom.':'.$sname.':'.$coid,$shome );  
     my %result=();  
     my $ResId;      my $ResId;
     my $Code;      my $Code;
     my $Tries;      my $Tries;
     my $Wrongs;      my $Wrongs;
     my %TempHash;      my %TempHash;
     my $Version;      my $Version;
     my $ProbNo;      my $problemsCorrect;
     my $ProbSolved;      my $problemsSolved;
     my $ProbTotal;      my $totalProblems;
     my $LatestVersion;                           my $LatestVersion;
     my $Str=substr($students[$index].      my $Str;
             '                                                        ',0,14).' ! '.  
             substr($rowlabels[$index].      # Handle Student information ------------------------------------------
             '                                                        ',0,45).' ! ';      # Handle errors
     unless ($reply=~/^error\:/) {  #    if($CachData{$name.':error'} =~ /environment/) {
         foreach (split(/\&/,$reply)) {  # my $errorMessage = $CachData{$name.':error'};
             my ($name,$value)=split(/\=/,&Apache::lonnet::unescape($_));  # return '<td>'.$sname.'</td><td>'.$sdom.
             $result{$name}=$value;  #    '</td><td><font color="#000088">'.$errorMessage.'</font></td>';
         }  #    }
  $ProbNo = 0;  
  $ProbTotal = 0;      # Handle user data
         $ProbSolved = 0;      $Str  = '<td><pre>'.$sname.'</pre></td><td><pre>'.$sdom;
  my $IterationNo = 0;      $Str .= '</pre></td><td><pre>'.$CachData{$name.':section'};
         foreach $ResId (@cols) {      $Str .= '</pre></td><td><pre>'.$CachData{$name.':id'};
     if ($IterationNo == 0) {$IterationNo++; next;}      $Str .= '</pre></td><td><pre>'.$CachData{$name.':fullname'};
     if (!$ResId) {       $Str .= '</pre></td>';
  my $PrNo = sprintf( "%3d", $ProbNo );  
  $Str .= ' '.'<font color="#007700">'.$PrNo.'</font> ';      if($CachData{$name.':error'} =~ /course/) {
  $ProbSolved += $ProbNo;   return $Str;
  $ProbNo=0;  # my $errorMessage = 'May have no course data or '.
  next;   #                   $CachData{$name.':error'};
     }  # return '<td>'.$sname.'</td><td>'.$sdom.
             $ResId=~/(\d+)\.(\d+)/;  #    '</td><td><font color="#000088">'.$errorMessage.'</font></td>';
     my $meta=$hash{'src_'.$ResId};      }
     my $PartNo = 0;  
     undef %TempHash;      # Handle problem data ------------------------------------------------
     foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {      $Str .= '<td><pre>';
  if ($_=~/^stores\_(\d+)\_tries$/) {      $problemsCorrect = 0;
                     my $Part=&Apache::lonnet::metadata($meta,$_.'.part');      $totalProblems = 0;
     if ( $TempHash{"$Part"} eq '' ) {       $problemsSolved = 0;
  $TempHash{"$Part"} = $Part;      my $IterationNo = 0;
  $TempHash{$PartNo}=$Part;      foreach $ResId (@cols) {
  $TempHash{"$Part.Code"} = ' ';     if ($IterationNo == 0) {
  $PartNo++;      # Looks to be skipping start resource
     }      $IterationNo++; 
       next;
    }
   
    # ResId is 0 for sequences and pages, 
    # please check tracetable for changes
    if (!$ResId) {
       my $outputProblemsCorrect = sprintf( "%3d", $problemsCorrect );
       $Str .= '<font color="#007700">'.$outputProblemsCorrect.
       '</font></pre></td>';
       $Str .= '<td><pre>';
       $problemsSolved += $problemsCorrect;
       $problemsCorrect=0;
       next; 
    }
   
    # Set $1 and $2
    $ResId=~/(\d+)\.(\d+)/;
    my $meta=$hash{'src_'.$ResId};
    my $numberOfParts = 0;
    undef %TempHash;
    foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
   #----------- Overwrite $1 in next statement ---------------------------------
       if ($_=~/^stores\_(\d+)\_tries$/) {
    my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
    if ( $TempHash{"$Part"} eq '' ) { 
       $TempHash{"$Part"} = $Part;
       $TempHash{$numberOfParts}=$Part;
       $TempHash{"$Part.Code"} = ' ';  
       $numberOfParts++;
  }   }
             }      }
    }
   
             my $Prob = &Apache::lonnet::declutter( $hash{'map_id_'.$1} ).  #----------- Using $1 and $2 -----------------------------------------------
    my $Prob = &Apache::lonnet::symbclean(
          &Apache::lonnet::declutter($hash{'map_id_'.$1} ).
                        '___'.$2.'___'.                         '___'.$2.'___'.
                        &Apache::lonnet::declutter( $hash{'src_'.$ResId} );                         &Apache::lonnet::declutter( $hash{'src_'.$ResId} ));
             $Code=' ';   $Code=' ';
             $Tries = 0;   $Tries = 0;
      $LatestVersion = $result{"version:$Prob"};   $LatestVersion = $CachData{$name.":version:$Prob"};
   
             if ( $LatestVersion ) {   if ( $LatestVersion ) {
  for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) {      for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) {
     my $vkeys = $result{"$Version:keys:$Prob"};   my $vkeys = $CachData{$name.":$Version:keys:$Prob"};
     my @keys = split(/\:/,$vkeys);     my @keys = split(/\:/,$vkeys);  
   
     foreach my $Key (@keys) {     foreach my $Key (@keys) {
  if (($Key=~/\.(\w+)\.solved$/) && ($Key!~/^\d+\:/)) {  #---------------------- Changing $1 -------------------------------------------
     my $Part = $1;      if (($Key=~/\.(\w+)\.solved$/) && ($Key!~/^\d+\:/)) {
     $Tries = $result{"$Version:$Prob:resource.$Part.tries"};  #---------------------- Using $1 -----------------------------------------------
     $TempHash{"$Part.Tries"}=($Tries) ? $Tries : 0;   my $Part = $1;
     my $Val = $result{"$Version:$Prob:resource.$Part.solved"};   $Tries = $CachData{$name.":$Version:$Prob".
     if ($Val eq 'correct_by_student'){$Code='*';}      ":resource.$Part.tries"};
     elsif ($Val eq 'correct_by_override'){$Code = '+';}                           $TempHash{"$Part.Tries"}=($Tries) ? $Tries : 0;
     elsif ($Val eq 'incorrect_attempted'){$Code = '.';}    my $Val = $CachData{$name.":$Version:$Prob".
     elsif ($Val eq 'incorrect_by_override'){$Code = '-';}      ":resource.$Part.solved"};
     elsif ($Val eq 'excused'){$Code = 'x';}   if    ($Val eq 'correct_by_student')   {$Code = '*';} 
     elsif ($Val eq 'ungraded_attempted'){$Code = '#';}   elsif ($Val eq 'correct_by_override')  {$Code = '+';}
     else {$Code = ' ';}   elsif ($Val eq 'incorrect_attempted')  {$Code = '.';} 
     $TempHash{"$Part.Code"} = $Code;   elsif ($Val eq 'incorrect_by_override'){$Code = '-';}
  }   elsif ($Val eq 'excused')              {$Code = 'x';}
          }   elsif ($Val eq 'ungraded_attempted')   {$Code = '#';}
                 }    else                                   {$Code = ' ';}
  for ( my $n = 0; $n < $PartNo; $n++ ) {    
     my $part = $TempHash{$n};   $TempHash{"$Part.Code"} = $Code;
     my $Code = $TempHash{"$part.Code"};      }
                     if ( $Code eq '*') {   }
  $ProbNo++;      }
                         if (($TempHash{"$part.Tries"}<10) ||  # Actually append problem to output (all parts)
                             ($TempHash{"$part.Tries"} eq '')) {      $Str.='<a href="/adm/grades?symb='.
     $TempHash{"$part.Code"}=$TempHash{"$part.Tries"};                  &Apache::lonnet::escape($Prob).
  }                  '&student='.$sname.'&domain='.$sdom.'&command=submission">'; 
                     }      for(my $n = 0; $n < $numberOfParts; $n++) {  
     elsif ( $Code eq '+' ) {$ProbNo++;}   my $part = $TempHash{$n};
     $Str .= $TempHash{"$part.Code"};   my $code2 = $TempHash{"$part.Code"};
     if ( $Code ne 'x' ) {$ProbTotal++;}   if($code2 eq '*') {
       $problemsCorrect++;
   # !!!!!!!!!!!------------------------- Should 10 not be maxtries? ------------
       if (($TempHash{"$part.Tries"}<10) ||
    ($TempHash{"$part.Tries"} eq '')) {
    $TempHash{"$part.Code"}=$TempHash{"$part.Tries"};
       }
    } elsif($code2 eq '+') {
       $problemsCorrect++;
  }   }
             }     
     else {   $Str .= $TempHash{"$part.Code"};
  for(my $n=0; $n<$PartNo; $n++) {  
     $Str.=' ';   if($code2 ne 'x') {
     $ProbTotal++;      $totalProblems++;
  }   }
     }      }
         }       $Str.='</a>';
    } else {
       for(my $n=0; $n<$numberOfParts; $n++) {
    $Str.=' ';
    $totalProblems++;
       }
    }
     }      }
     my $PrTot = sprintf( "%5d", $ProbTotal );  
     my $PrSvd = sprintf( "%5d", $ProbSolved );  
     $Str .= ' '.'<font color="#000088">'.$PrSvd.'  /'.$PrTot.'</font> ';  
   
     return $Str ;      $Str .= '<td><pre><font color="#000088">'.$problemsSolved.
       ' / '.$totalProblems.'</font></pre></td>';
   
       return $Str;
 }  }
   
   sub CreateForm {
       my $OpSel1='';
       my $OpSel2='';
       my $OpSel3='';
       my $Status = $ENV{'form.status'};
       if ( $Status eq 'Any' ) { $OpSel3='selected'; }
       elsif ($Status eq 'Expired' ) { $OpSel2 = 'selected'; }
       else { $OpSel1 = 'selected'; }
   
       my $Ptr = '<form name=stat method=post action="/adm/chart" >'."\n";
       $Ptr .= '<b> Sort by: &nbsp; </b>'."\n";
       $Ptr .= '&nbsp;&nbsp;&nbsp;';
       $Ptr .= '<input type=submit name=sort value="User Name" />'."\n";
       $Ptr .= '&nbsp;&nbsp;&nbsp;';
       $Ptr .= '<input type=submit name=sort value="Last Name" />'."\n";
       $Ptr .= '&nbsp;&nbsp;&nbsp;';
       $Ptr .= '<input type=submit name=sort value="Section"/>'."\n";
       $Ptr .= '<br><br>';
       $Ptr .= '<b> Student Status: &nbsp; </b>'."\n".
               '<select name="status">'. 
               '<option '.$OpSel1.' >Active</option>'."\n".
               '<option '.$OpSel2.' >Expired</option>'."\n".
       '<option '.$OpSel3.' >Any</option> </select> '."\n";
       $Ptr .= '&nbsp;&nbsp;&nbsp;';
       $Ptr .= '<input type=submit name=sort value="Recalculate Chart"/>'."\n";
       $Ptr .= '</form>'."\n";
       $r->print( $Ptr );
   }
   
   sub CreateTableHeadings {
       $r->print('<tr>');
       $r->print('<td>User Name</td>');
       $r->print('<td>Domain</td>');
       $r->print('<td>Section</td>');
       $r->print('<td>PID</td>');
       $r->print('<td>Full Name</td>');
   
       my $ResId;
       my $IterationNo = 0;
       foreach $ResId (@cols) {
    if ($IterationNo == 0) {$IterationNo++; next;}
    if (!$ResId) { 
   #    my $PrNo = sprintf( "%3d", $ProbNo );
   #    $Str .= '<td><font color="#007700">Chapter '.$PrNo.'</font></td>';
       $r->print('<td><font color="#007700">Chapter '.'0'.'</font></td>');
    }
       }
   
       $r->print('</tr>');
       $r->rflush();
   
       return;
   }
   
 # ------------------------------------------------------------ Build page table  # ------------------------------------------------------------ Build page table
   
Line 224  sub tracetable { Line 317  sub tracetable {
     }      }
 }  }
   
   sub usection {
 sub usection2 {  
     my ($udom,$unam,$courseid,$ActiveFlag)=@_;      my ($udom,$unam,$courseid,$ActiveFlag)=@_;
     $courseid=~s/\_/\//g;      $courseid=~s/\_/\//g;
     $courseid=~s/^(\w)/\/$1/;      $courseid=~s/^(\w)/\/$1/;
     foreach my $elem(split(/\&/,&Apache::lonnet::reply('dump:'.$udom.':'.$unam.':roles',  
                      &Apache::lonnet::homeserver($unam,$udom)))) {      my %result=&Apache::lonnet::dump('roles',$udom,$unam);
         my ($key,$value)=split(/\=/,$elem);  
         $key=&Apache::lonnet::unescape($key);      my($checkForError)=keys (%result);
       if($checkForError =~ /^(con_lost|error|no_such_host)/i) {
    return -1;
       }
   
       my $cursection='-1';
       my $oldsection='-1';
       my $status='Expired';
       foreach my $key (keys (%result)) {
    my $value = $result{$key};
         if ($key=~/^$courseid(?:\/)*(\w+)*\_st$/) {          if ($key=~/^$courseid(?:\/)*(\w+)*\_st$/) {
             my $section=$1;              my $section=$1;
             if ($key eq $courseid.'_st') { $section=''; }              if ($key eq $courseid.'_st') { $section=''; }
     my ($dummy,$end,$start)=split(/\_/,&Apache::lonnet::unescape($value));      my ($dummy,$end,$start)=split(/\_/,$value);
             my $now=time;      my $now=time;
             my $notactive=0;      my $notactive=0;
             if ($start) {      if ($start) {
  if ($now<$start) { $notactive=1; }   if($now<$start) {
             }      $notactive=1;
             if ($end) {   }
                 if ($now>$end) { $notactive=1; }      }
             }       if($end) {
     if ($ActiveFlag == 1) { $notactive=0; }   if ($now>$end) {
             unless ($notactive) { return $section; }      $notactive=1;
         }   }
       }
       if($notactive == 0) {
    $status='Active';
    $cursection=$section;
       }
       if($notactive == 1) {
    $oldsection=$section;
       }
    }
       }
       if($status eq $ActiveFlag) {
    if($cursection eq '-1') {
       return $oldsection;
    }
    return $cursection;
       }
       if($ActiveFlag eq 'Any') {
    if($cursection eq '-1') {
       return $oldsection;
    }
    return $cursection;
     }      }
     return '-1';      return '-1';
 }  }
   
   sub ProcessFullName {
       my ($name)=@_;
       my $Str = '';
   
       if($CachData{$name.':lastname'} ne '') {
    $Str .= $CachData{$name.':lastname'}.' ';
    if($CachData{$name.':generation'} ne '') {
       $Str .= $CachData{$name.':generation'};
    } else {
       chop($Str);
    }
    $Str .= ', ';
    if($CachData{$name.':firstname'} ne '') {
       $Str .= $CachData{$name.':firstname'}.' ';
    }
    if($CachData{$name.':middlename'} ne '') {
       $Str .= $CachData{$name.':middlename'};
    } else {
       chop($Str);
       if($CachData{$name.'firstname'} eq '') {
    chop($Str);
       }
    }
       } else {
    if($CachData{$name.':firstname'} ne '') {
       $Str .= $CachData{$name.':firstname'}.' ';
    }
    if($CachData{$name.':middlename'} ne '') {
       $Str .= $CachData{$name.':middlename'}.' ';
    }
    if($CachData{$name.':generation'} ne '') {
       $Str .= $CachData{$name.':generation'};
    } else {
       chop($Str);
    }
       }
   
 sub usection {      return $Str;
     my ($udom,$unam,$courseid)=@_;  
     $courseid=~s/\_/\//g;  
     $courseid=~s/^(\w)/\/$1/;  
     foreach (split(/\&/,&Apache::lonnet::reply('dump:'.  
              $udom.':'.$unam.':roles',  
              &Apache::lonnet::homeserver($unam,$udom)))){  
         my ($key,$value)=split(/\=/,$_);  
         $key=&Apache::lonnet::unescape($key);  
         if ($key=~/^$courseid(?:\/)*(\w+)*\_st$/) {  
             my $section=$1;  
             if ($key eq $courseid.'_st') { $section=''; }  
     my ($dummy,$end,$start)=split(/\_/,&Apache::lonnet::unescape($value));  
 #            $section=($section) ? $section : '(none)';  
 #            $section=(int($section)) ? int($section) : $section;  
 #            $r->print($unam.'...'.$section.'<br>');  
     return $section;  
         }  
     }  
     #} split(/\&/,&Apache::lonnet::reply('dump:'.$udom.':'.$unam.':roles',  
     #                    &Apache::lonnet::homeserver($unam,$udom)));  
     return '';  
 }  }
   
 sub BuildChart {  sub DownloadStudentInformation {
 # ----------------------- Get first and last resource, see if there is anything      my ($name,$courseID)=@_;
     my $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}};      my ($studentName,$studentDomain) = split(/\:/,$name);
     my $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}};      my $checkForError;
     if (($firstres) && ($lastres)) {      my $key;
 # ----------------------------------------------------------------- Render page      my $Status=$CachData{$name.':Status'};
  my $cid=$ENV{'request.course.id'};  
         my $chome=$ENV{'course.'.$cid.'.home'};  #-----------------------------------------------------------------
         my ($cdom,$cnum)=split(/\_/,$cid);      # Download student environment data, specifically the full name and id.
 # ---------------------------------------------- Read class list and row labels      my %studentInformation=&Apache::lonnet::get('environment',
  my $classlst=&Apache::lonnet::reply   ['lastname','generation',
                             ('dump:'.$cdom.':'.$cnum.':classlist',$chome);   'firstname','middlename',
  my $now=time;   'id'],
  unless ($classlst=~/^error\:/) {   $studentDomain,$studentName);
     foreach my $KeyPoint(sort split(/\&/,$classlst)) {      if($c->aborted()) {
  my ($name,$value)=split(/\=/,$KeyPoint);   return;
  my ($end,$start)=split(/\:/,&Apache::lonnet::unescape($value));      }
  my $active=1;      ($checkForError)=keys (%studentInformation);
  if (($end) && ($now>$end)) { $active=0; }      if($checkForError =~ /^(con_lost|error|no_such_host)/i) {
    $CachData{$name.':error'}=
  if ($ENV{'form.active'} eq 'All Students') { $active=1; }      'Could not download student environment data.';
   # return;
  if ($active) {   $CachData{$name.':lastname'}='';
     my $thisindex=$#students+1;   $CachData{$name.':generation'}='';
     $name=&Apache::lonnet::unescape($name);   $CachData{$name.':firstname'}='';
     $students[$thisindex]=$name;   $CachData{$name.':middlename'}='';
     my ($sname,$sdom)=split(/\:/,$name);   $CachData{$name.':fullname'}='';
     $PreCol[$thisindex]=$sname.':';   $CachData{$name.':id'}='';
       } else {
     my $ssec=&usection($sdom,$sname,$cid);#,$active);   $CachData{$name.':lastname'}=$studentInformation{'lastname'};
    $CachData{$name.':generation'}=$studentInformation{'generation'};
     if ($ssec==-1) {   $CachData{$name.':firstname'}=$studentInformation{'firstname'};
  $rowlabels[$thisindex]=   $CachData{$name.':middlename'}=$studentInformation{'middlename'};
     'Data not available: '.$name;   $CachData{$name.':fullname'}=&ProcessFullName($name);
     } else {   $CachData{$name.':id'}=$studentInformation{'id'};
  my %reply=&Apache::lonnet::idrget($sdom,$sname);      }
  my $reply=&Apache::lonnet::reply('get:'.$sdom.':'.$sname.  
                                   ':environment:lastname&generation&firstname&middlename',  
                                   &Apache::lonnet::homeserver($sname,$sdom));  
  #$ssec=(int($ssec)) ? int($ssec) : $ssec;  
  my $sec=sprintf('%3s',$ssec);  
  $rowlabels[$thisindex]=$sec.' '.$reply{$sname}.' ';  
  $PreCol[$thisindex] .= $reply.':'.$sec;  
  my $i=0;  
  foreach (split(/\&/,$reply)) {  
     $i++;  
     if ( $_ ne '') {  
  $rowlabels[$thisindex].=&Apache::lonnet::unescape($_).' ';  
     }  
     if ($i == 2) {  
  chop($rowlabels[$thisindex]);  
  $rowlabels[$thisindex].=', ';  
     }  
  }  
     }  
  }  
     }  
   
  } else {      # Download student course data
     $r->print('<h1>Could not access course data</h1>');      my %courseData=&Apache::lonnet::dump($courseID,$studentDomain,
    $studentName);
       if($c->aborted()) {
    return;
       }
       ($checkForError)=keys (%courseData);
       if($checkForError =~ /^(con_lost|error|no_such_host)/i) {
    $CachData{$name.':error'}='Could not download course data.';
   # return;
       } else {
    foreach $key (keys (%courseData)) {
       $CachData{$name.':'.$key}=$courseData{$key};
  }   }
       }
   
  my $allstudents=$#students+1;      # Get student's section number
  $r->print('<h3>'.$allstudents.' students</h3>');      my $sec=&usection($studentDomain, $studentName, $courseID, $Status);
  &CreateForm();      if($sec != -1) {
  $r->rflush();   $CachData{$name.':section'}=sprintf('%3s',$sec);
       } else {
    $CachData{$name.':section'}='';
       }
   
 # --------------- Find all assessments and put them into some linear-like order      return;
  &tracetable($firstres,'&'.$lastres.'&');  }
 # ----------------------------------------------------------------- Start table  
   
         $r->print('<p><pre>');  sub SortStudents {
   my $index;  # --------------------------------------------------------------- Sort Students
         for ($index=0;$index<=$#students;$index++) {      my $Pos = $ENV{'form.sort'};
     my $Str=&ExtractStudentData($index,$cid);      my @students = split(/:::/,$CachData{'NamesOfStudents'});
     $r->print($Str.'<br>');      my %sortData;
             $r->rflush();  
     $CachData{$PreCol[$index]}=$Str;      if($Pos eq 'Last Name') {
         }   for(my $index=0; $index<$#students+1; $index++) {
         $r->print('</pre>');      $sortData{$CachData{$students[$index].':fullname'}}=
    $students[$index];
    }
       } elsif($Pos eq 'Section') {
    for(my $index=0; $index<$#students+1; $index++) {
       $sortData{$CachData{$students[$index].':section'}.
         $students[$index]}=$students[$index];
    }
     } else {      } else {
  $r->print('<h3>Undefined course sequence</h3>');   # Sort by user name
    for(my $index=0; $index<$#students+1; $index++) {
       $sortData{$students[$index]}=$students[$index];
    }
     }      }
 }  
   
 sub CreateForm {      my @order = ();
     my $OpSel1='';      foreach my $key (sort keys(%sortData)) {
     my $OpSel2='';   push (@order,$sortData{$key});
     if ( $ENV{'form.active'} eq 'All Students' ) { $OpSel2='selected'; }      }
     else { $OpSel1 = 'selected'; }  
   
     my $Ptr = '<form name=stat method=post action="/adm/chart" >'."\n";      return @order;
     $Ptr .= '<b> Sort by: &nbsp; </b>'."\n";  
     $Ptr .= '&nbsp;&nbsp;&nbsp;';  
     $Ptr .= '<input type=submit name=sort value="User Name" />'."\n";  
     $Ptr .= '&nbsp;&nbsp;&nbsp;';  
     $Ptr .= '<input type=submit name=sort value="Last Name" />'."\n";  
     $Ptr .= '&nbsp;&nbsp;&nbsp;';  
     $Ptr .= '<input type=submit name=sort value="Section"/>'."\n";  
     $Ptr .= '<br><br>';  
     $Ptr .= '<b> Activation Area: &nbsp; </b>'."\n".  
             '<select name="active"> <option '.$OpSel1.' >Active Students</option>'."\n".  
     '<option '.$OpSel2.'>All Students</option> </select> '."\n";  
     $Ptr .= '&nbsp;&nbsp;&nbsp;';  
     $Ptr .= '<input type=submit name=sort value="Recalculate Chart"/>'."\n";  
     $Ptr .= '</form>'."\n";  
     $r->print( $Ptr );  
 }  }
   
 sub CacheChart {  sub CollectClasslist {
     my @list = ();  # -------------------------------------------------------------- Get class list
     my $count=0;      my $cid=$ENV{'request.course.id'};
       my $chome=$ENV{'course.'.$cid.'.home'};
       my ($cdom,$cnum)=split(/\_/,$cid);
       my %classlist=&Apache::lonnet::dump('classlist',$cdom,$cnum);
       my @names = ();
   
       my($checkForError)=keys (%classlist);
       if($checkForError =~ /^(con_lost|error|no_such_host)/i) {
    $r->print('<h1>Could not access course data</h1>');
    push (@names, 'error');
    return @names;
       }
   
     my $Pos = $ENV{'form.sort'};  # ------------------------------------- Calculate Status and number of students
     if ( $Pos eq 'Last Name' ) {$Pos=1;}      my $now=time;
     elsif ( $Pos eq 'Section' ) {$Pos=2;}      foreach my $name (sort(keys(%classlist))) {
     else {$Pos=0;}   my $value=$classlist{$name};
    my ($end,$start)=split(/\:/,$value);
    my $active=1;
    my $Status=$ENV{'form.status'};
    $Status = ($Status) ? $Status : 'Active';
    if((($end) && $now > $end) && (($Status eq 'Active'))) { 
       $active=0; 
    }
    if(($Status eq 'Expired') && ($end == 0 || $now < $end)) {
       $active=0;
    }
    if($active) {
       push(@names,$name);
       $CachData{$name.':Status'}=$Status;
    }
       }
   
       $CachData{'NamesOfStudents'}=join(":::",@names);
   
       return @names;
   }
   
     foreach my $key( keys %CachData) {   sub BuildChart {
  my @Temp=split(/\:/,$key);  # ----------------------- Get first and last resource, see if there is anything
  my $Use = $Temp[$Pos];      my $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}};
  $list[$count]=$Use.$key.'*'.$CachData{$key};      my $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}};
  $count++;      if (!($firstres) || !($lastres)) {
    $r->print('<h3>Undefined course sequence</h3>');
    return;
     }      }
   
     @list = sort (@list);  # --------------- Find all assessments and put them into some linear-like order
       &tracetable($firstres,'&'.$lastres.'&');
   
     $r->print('<h3>'.$count.' students</h3>');  # ----------------------------------------------------------------- Render page
     &CreateForm();      &CreateForm();
   
       my $cid=$ENV{'request.course.id'};
       my $ChartDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
                     "_$ENV{'user.domain'}_$cid\_chart.db";
       my $isCached = 0;
       my @students;
       if ((-e "$ChartDB") && ($ENV{'form.sort'} ne 'Recalculate Chart')) {
    if (tie(%CachData,'GDBM_File',"$ChartDB",&GDBM_READER,0640)) {
       $isCached = 1;
       @students=&SortStudents();
    } else {
       $r->print("Unable to tie hash to db file");
       $r->rflush();
       return;
    }
       } else {
    if (tie(%CachData,'GDBM_File',$ChartDB,&GDBM_NEWDB,0640)) {
       $isCached = 0;
       @students=&CollectClasslist();
       if($students[0] eq 'error') {
    return;
       }
    } else {
       $r->print("Unable to tie hash to db file");
       return;
    }
       }
   
       $r->print('<h3>'.($#students+1).' students</h3>');
     $r->rflush();      $r->rflush();
       
     $r->print('<p><pre>');  # ----------------------------------------------------------------- Start table
     for ( my $n; $n < $count; $n++) {      $r->print('<table><tbody>');
  my ($dummy, $Line) = split(/\*/,$list[$n]);  #    &CreateTableHeadings();
  $r->print($Line.'<br>');      my @updateStudentList = ();
     }      foreach my $student (@students) {
     $r->print('</pre>');   if($c->aborted()) {
       if($isCached == 0) {
    $CachData{'NamesOfStudents'}=join(":::",@updateStudentList);
       }
       last;
    }
    if($isCached == 0) {
       &DownloadStudentInformation($student,$cid);
       push (@updateStudentList, $student);
    }
    my $Str=&ExtractStudentData($student,$cid);
    $r->print('<tr>'.$Str.'</tr>');
       }
       $r->print('</tbody></table>');
   
       untie(%CachData);
   
       return;
 }  }
   
 sub Start {  sub Start {
     undef %hash;      $r->print('<head><title>'.
     undef %CachData;  
     undef @students;  
     undef @cols;  
     undef @rowlabels;  
     undef @PreCol;  
   
     $r->print('<html><head><title>'.  
               'LON-CAPA Assessment Chart</title></head>');                'LON-CAPA Assessment Chart</title></head>');
     $r->print('<body bgcolor="#FFFFFF">'.      $r->print('<body bgcolor="#FFFFFF">'.
               '<script>window.focus();</script>'.                '<script>window.focus();</script>'.
Line 444  sub Start { Line 640  sub Start {
 # ------------------------------- This is going to take a while, produce output  # ------------------------------- This is going to take a while, produce output
     $r->rflush();      $r->rflush();
   
     my $cid=$ENV{'request.course.id'};      &BuildChart();
     my $ChartDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".  
                   "_$ENV{'user.domain'}_$cid\_chart.db";  
   
     if ((-e "$ChartDB") && ($ENV{'form.sort'} ne 'Recalculate Chart')) {      $r->print('</body>');
  if (tie(%CachData,'GDBM_File',"$ChartDB",&GDBM_READER,0640)) {  
     &CacheChart();      return;
  }  
  else {  
     $r->print("Unable to tie hash to db file");  
  }  
     }  
     else {  
  if (tie(%CachData,'GDBM_File',$ChartDB,&GDBM_WRCREAT,0640)) {  
     foreach (keys %CachData) {delete $CachData{$_};}  
     &BuildChart();  
  }  
  else {  
     $r->print("Unable to tie hash to db file");  
  }  
     }  
     untie(%CachData);  
 }  }
   
 # ================================================================ Main Handler  # ================================================================ Main Handler
   
 sub handler {  sub handler {
       undef %hash;
       undef %CachData;
       undef @cols;
   
     $r=shift;      $r=shift;
       $c = $r->connection;
     if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {      if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
 # ------------------------------------------- Set document type for header only  # ------------------------------------------- Set document type for header only
  if ($r->header_only) {   if ($r->header_only) {
Line 495  sub handler { Line 679  sub handler {
 # ---------------------------------------------------------------- Send headers  # ---------------------------------------------------------------- Send headers
     $r->content_type('text/html');      $r->content_type('text/html');
     $r->send_http_header;      $r->send_http_header;
       $r->print('<html>');
     &Start();      &Start();
     $r->print('</body></html>');                       $r->print('</html>');
       $r->rflush();
 # ------------------------------------------------------------- End render page  # ------------------------------------------------------------- End render page
  } else {   } else {
     $r->content_type('text/html');      $r->content_type('text/html');
Line 525  sub handler { Line 711  sub handler {
 }  }
 1;  1;
 __END__  __END__
   
   
   
   
   
   
   

Removed from v.1.34  
changed lines
  Added in v.1.43


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