Diff for /loncom/interface/lonnavmaps.pm between versions 1.29 and 1.46

version 1.29, 2002/03/15 21:40:27 version 1.46, 2002/09/02 19:35:31
Line 239  sub astatus { Line 239  sub astatus {
  my $status=$returnhash{'resource.'.$_.'.solved'};   my $status=$returnhash{'resource.'.$_.'.solved'};
   
  if ($status eq 'correct_by_student') {   if ($status eq 'correct_by_student') {
     if ($code==0) { $code=3; } else { $code=4; }      if ($code==0||$code==3) { $code=3; } else { $code=4; }
     $ctext.=' solved';      $ctext.=' solved';
  } elsif ($status eq 'correct_by_override') {   } elsif ($status eq 'correct_by_override') {
     if ($code==0) { $code=3; } else { $code=4; }      if ($code==0||$code==3) { $code=3; } else { $code=4; }
     $ctext.=' override';      $ctext.=' override';
  } elsif ($status eq 'incorrect_attempted') {   } elsif ($status eq 'incorrect_attempted') {
     if ($code!=4 && $code!=3) { $code=2; }      if ($code!=4 && $code!=3) { $code=2; }
Line 258  sub astatus { Line 258  sub astatus {
     if ($code==3) { $code=4; }      if ($code==3) { $code=4; }
     $ctext.=' override';      $ctext.=' override';
  } elsif ($status eq 'excused') {   } elsif ($status eq 'excused') {
     if ($code==0) { $code=3; } else { $code=4; }      if ($code==0||$code==3) { $code=3; } else { $code=4; }
     $ctext.=' excused';      $ctext.=' excused';
  } else {   } else {
     if ($code==0) { $code=1; }      if ($code==0) { $code=1; }
Line 268  sub astatus { Line 268  sub astatus {
     return 'p'.$code.$tcode.'"'.$ctext.'"';      return 'p'.$code.$tcode.'"'.$ctext.'"';
 }  }
   
 # ------------------------------------------------------------ Build page table  
   
 sub tracetable {  sub addresource {
     my ($sofar,$rid,$beenhere)=@_;      my ($resource,$sofar,$rid,$showtypes,$indent,$linkid)=@_;
     my $further=$sofar;      if ($showtypes eq 'problems') {
     unless ($beenhere=~/\&$rid\&/) {   if ($resource!~/\.(problem|exam|quiz|assess|survey|form)$/) {
  $beenhere.=$rid.'&';        return;
    }
  if (defined($hash{'is_map_'.$rid})) {      }
     $sofar++;      my $brepriv=&Apache::lonnet::allowed('bre',$resource);
     my $tprefix='';      if ($hash{'src_'.$rid}) {
     if ($hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}}    if (($brepriv eq '2') || ($brepriv eq 'F')) {
  eq 'sequence') {       my $pprefix='';
  $tprefix='h';       if ($resource=~/\.(problem|exam|quiz|assess|survey|form)$/) {
    $pprefix=&astatus($rid);
       }
       $$sofar++;
       if ($indent) { $pprefix='i'.$indent.','.$pprefix; }
       if ($linkid) { $pprefix='l'.$linkid.','.$pprefix; }
       if (defined($rows[$$sofar])) {
    $rows[$$sofar].='&'.$pprefix.$rid;
     } else {      } else {
  # it's a page we need to grab out the problems only   $rows[$$sofar]=$pprefix.$rid;
     }      }
     if (defined($rows[$sofar])) {   }
  $rows[$sofar].='&'.$tprefix.$rid;      }
   }
   
   sub followlinks () {
       my ($rid,$sofar,$beenhere,$further,$showtypes,$indent,$linkid)=@_;
       my $mincond=1;
       my $next='';
       foreach (split(/\,/,$hash{'to_'.$rid})) {
    my $thiscond=
       &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
    if ($thiscond>=$mincond) {
       if ($next) {
    $next.=','.$_.':'.$thiscond;
     } else {      } else {
  $rows[$sofar]=$tprefix.$rid;   $next=$_.':'.$thiscond;
     }      }
     if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&      if ($thiscond>$mincond) { $mincond=$thiscond; }
  (defined($hash{'map_finish_'.$hash{'src_'.$rid}})) &&   }
  ($tprefix eq 'h')) {      }
  my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};      my $col=0;
  $sofar=      &Apache::lonxml::debug("following links -$next-");
     &tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},      foreach (split(/\,/,$next)) {
  '&'.$frid.'&');   my ($nextlinkid,$condval)=split(/\:/,$_);
  $sofar++;   if ($condval>=$mincond) {
  if ($hash{'src_'.$frid}) {      my $now=&tracetable($sofar,$hash{'goesto_'.$nextlinkid},
     my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$frid});   $beenhere,$showtypes,$indent,$linkid);
     if (($brepriv eq '2') || ($brepriv eq 'F')) {      if ($now>$further) {
  my $pprefix='';   if ($col>0) {
  if ($hash{'src_'.$frid}=~      my $string;
     /\.(problem|exam|quiz|assess|survey|form)$/) {      for(my $i=0;$i<$col;$i++) { $string.='&'; }
     $pprefix=&astatus($frid);      for(my $i=$further+1;$now-1>$i;$i++) {
    $rows[$i]=$string.$rows[$i];
  }  
  if (defined($rows[$sofar])) {  
     $rows[$sofar].='&'.$pprefix.$frid;  
  } else {  
     $rows[$sofar]=$pprefix.$frid;  
  }  
     }      }
  }   }
    $further=$now;
     }      }
    }
    $col++;
       }
       return $further;
   }
   # ------------------------------------------------------------ Build page table
   
   sub tracetable {
       my ($sofar,$rid,$beenhere,$showtypes,$indent,$linkid)=@_;
       my $newshowtypes=$showtypes;
       my $further=$sofar;
   # $Apache::lonxml::debug=1;
       &Apache::lonxml::debug("$rid ; $linkid ; $sofar ; $beenhere ; ".$hash{'src_'.$rid});
       if ($beenhere=~/\&$rid\&/) { return $further; }
       $beenhere.=$rid.'&';
   
       if (defined($hash{'is_map_'.$rid})) {
    $sofar++;
    my $tprefix='';
    if ($hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}}
       eq 'sequence') {
       $tprefix='h';
    } elsif ($hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}}
    eq 'page') {
       $tprefix='j';
       if ($indent) { $tprefix='i'.$indent.','.$tprefix; }
       if ($linkid) { $tprefix='l'.$linkid.','.$tprefix; }
       $newshowtypes='problems';
       $indent++;
       #if in a .page continue to link the encompising .page
       if (!$linkid) { $linkid=$rid; }
    }
    if (defined($rows[$sofar])) {
       $rows[$sofar].='&'.$tprefix.$rid;
  } else {   } else {
     $sofar++;      $rows[$sofar]=$tprefix.$rid;
     if ($hash{'src_'.$rid}) {  
  my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$rid});  
  if (($brepriv eq '2') || ($brepriv eq 'F')) {  
     my $pprefix='';  
     if ($hash{'src_'.$rid}=~  
  /\.(problem|exam|quiz|assess|survey|form)$/) {  
  $pprefix=&astatus($rid);  
     }  
     if (defined($rows[$sofar])) {  
  $rows[$sofar].='&'.$pprefix.$rid;  
     } else {  
  $rows[$sofar]=$pprefix.$rid;  
     }  
  }  
     }  
  }   }
    if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
  if (defined($hash{'to_'.$rid})) {      (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
     my $mincond=1;      my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
     my $next='';      $sofar=&tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},
     foreach (split(/\,/,$hash{'to_'.$rid})) {         '&'.$frid.'&',$newshowtypes,$indent,$linkid);
  my $thiscond=      &addresource($hash{'src_'.$frid},\$sofar,$frid,$newshowtypes,
     &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});   $indent,$linkid);
  if ($thiscond>=$mincond) {      if ($tprefix =~ /j$/) { $indent--; $linkid=''; }
     if ($next) {  
  $next.=','.$_.':'.$thiscond;  
     } else {  
  $next=$_.':'.$thiscond;  
     }  
     if ($thiscond>$mincond) { $mincond=$thiscond; }  
  }  
     }  
     foreach (split(/\,/,$next)) {  
  my ($linkid,$condval)=split(/\:/,$_);  
  if ($condval>=$mincond) {  
     my $now=&tracetable($sofar,$hash{'goesto_'.$linkid},$beenhere);  
     if ($now>$further) { $further=$now; }  
  }  
     }  
  }   }
       } else {
    &addresource($hash{'src_'.$rid},\$sofar,$rid,$showtypes,
        $indent,$linkid);
     }      }
   
       if (defined($hash{'to_'.$rid})) {
    $further=&followlinks($rid,$sofar,$beenhere,$further,$showtypes,
         $indent,$linkid);
       }
   
     return $further;      return $further;
 }  }
   
Line 385  sub handler { Line 411  sub handler {
     if ($ENV{'request.course.fn'}) {      if ($ENV{'request.course.fn'}) {
  $fn=$ENV{'request.course.fn'};   $fn=$ENV{'request.course.fn'};
  if (-e "$fn.db") {   if (-e "$fn.db") {
     if ((tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) &&      if ((tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640)) &&
  (tie(%parmhash,'GDBM_File',   (tie(%parmhash,'GDBM_File',
      $ENV{'request.course.fn'}.'_parms.db',       $ENV{'request.course.fn'}.'_parms.db',
      &GDBM_READER,0640))) {       &GDBM_READER(),0640))) {
  $hashtied=1;   $hashtied=1;
     }      }
  }   }
Line 408  sub handler { Line 434  sub handler {
     &Apache::loncommon::no_cache($r);      &Apache::loncommon::no_cache($r);
     $r->send_http_header;      $r->send_http_header;
   
     my $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}};      my $firstres=$hash{'map_start_'.
     my $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}};             &Apache::lonnet::clutter($ENV{'request.course.uri'})};
       my $lastres=$hash{'map_finish_'.
              &Apache::lonnet::clutter($ENV{'request.course.uri'})};
     if (!(($firstres) && ($lastres))) {      if (!(($firstres) && ($lastres))) {
  $r->print('<html><body>Coursemap undefined.</body></html>');   $r->print('<html><body>Coursemap undefined.</body></html>');
     } else {      } else {
Line 463  sub handler { Line 491  sub handler {
   
  @rows=();   @rows=();
   
  &tracetable(0,$firstres,'&'.$lastres.'&');   &tracetable(0,$firstres,'&','',0);
  if ($hash{'src_'.$lastres}) {  
     my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$lastres});  
     if (($brepriv eq '2') || ($brepriv eq 'F')) {  
  $rows[$#rows+1]=''.$lastres;  
     }  
  }  
   
 # ------------------------------------------------------------------ Page parms  # ------------------------------------------------------------------ Page parms
   
Line 482  sub handler { Line 504  sub handler {
   
  for ($i=0;$i<=$#rows;$i++) {   for ($i=0;$i<=$#rows;$i++) {
     if ($rows[$i]) {      if ($rows[$i]) {
    &Apache::lonxml::debug("Row $i is:".$rows[$i]);
  $contents++;   $contents++;
  my @colcont=split(/\&/,$rows[$i]);   my @colcont=split(/\&/,$rows[$i]);
  $lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));   $lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
Line 540  sub handler { Line 563  sub handler {
  }   }
     }      }
 # ----------------------------------------------------------- Start Page Output  # ----------------------------------------------------------- Start Page Output
     $r->print('<html><head><title>Navigate LON-CAPA Maps</title></head>');              my $bodytagadd='';
     $r->print('<body bgcolor="#FFFFFF"');      $r->print(
                      '<html><head><title>Navigate Course Map</title></head>');
     if (($currenturl=~/^\/res/) &&      if (($currenturl=~/^\/res/) &&
  ($currenturl!~/^\/res\/adm/)) {   ($currenturl!~/^\/res\/adm/)) {
  $r->print(' onLoad="window.location.hash='."'curloc'".'"');   $bodytagadd='onLoad="window.location.hash='."'curloc'".'"';
     }      }
     $r->print('><script>window.focus();</script>'.      $r->print(&Apache::loncommon::bodytag('Navigate Course Map','',
       '<img align=right src=/adm/lonIcons/lonlogos.gif>'.                                                    $bodytagadd));
       '<h1>Navigate Course Map</h1>'.      $r->print('<script>window.focus();</script>');
       "<h3>$date</h3>");      my $desc=$ENV{'course.'.$ENV{'request.course.id'}.'.description'};
       if (defined($desc)) { $r->print("<h2>$desc</h2>\n"); }
       $r->print("<h3>$date</h3>\n");
     $r->rflush();      $r->rflush();
     $r->print('<img src="/adm/lonMisc/chat.gif"> New discussion since '.      $r->print('<img src="/adm/lonMisc/chat.gif"> New discussion since '.
       localtime($lastcheck).        localtime($lastcheck).
Line 581  sub handler { Line 607  sub handler {
     $r->print("\n<tr>");      $r->print("\n<tr>");
     my @colcont=split(/\&/,$rows[$i]);      my @colcont=split(/\&/,$rows[$i]);
     my $avespan=$lcm/($#colcont+1);      my $avespan=$lcm/($#colcont+1);
   
       # for each item I wish to print on this row...
     for ($j=0;$j<=$#colcont;$j++) {      for ($j=0;$j<=$#colcont;$j++) {
    my $indent;my $indentstr;
    my $linkid;
  my $rid=$colcont[$j];   my $rid=$colcont[$j];
  my $add='<td>&nbsp;&nbsp;';                          $rid=~/(\d+)\.(\d+)$/;
    my $src=
      &Apache::lonnet::declutter($hash{'src_'.$1.'.'.$2});
    my $symb=
     &Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.$src;
    my $add='<td>';
  my $adde='</td>';   my $adde='</td>';
  my $hwk='<font color="#223322">';   my $hwk='<font color="#223322">';
  my $hwke='</font>';   my $hwke='</font>';
    if ($rid=~/^l(\d+\.\d+),(.+)/) { $linkid=$1; $rid=$2; }
    if ($rid=~/^i(\d+),(.+)/) { $indent=$1; $rid=$2; }
  if ($rid=~/^h(.+)/) {   if ($rid=~/^h(.+)/) {
     $rid=$1;      $rid=$1;
     $add='<th bgcolor="#AAFF55"><a name="'.$rid.'">';      $add='<th bgcolor="#AAFF55"><a name="'.$rid.'">';
     $adde='</th>';      $adde='</th>';
                               if (($ENV{'user.adv'}) && 
    ($parmhash{$symb.'.0.parameter_randompick'})) {
                                  $adde=' (randomly select '.
      $parmhash{$symb.'.0.parameter_randompick'}.
                                      ')</th>';
                               }
  }   }
    if ($rid=~/^j(.+)/) { $rid=$1; }
  if ($rid=~/^p(\d)(\d)\"([\w\: \(\)\/\,]*)\"(.+)/) {   if ($rid=~/^p(\d)(\d)\"([\w\: \(\)\/\,]*)\"(.+)/) {
     # sub astatus describes what code/tcode mean      # sub astatus describes what code/tcode mean
     my $code=$1;      my $code=$1;
Line 603  sub handler { Line 647  sub handler {
     }      }
     if ($code eq '3') {      if ($code eq '3') {
  $add='<td bgcolor="#AAFFAA">';   $add='<td bgcolor="#AAFFAA">';
       } elsif ($code eq '4') {
    $add='<td bgcolor="#E0FFAA">';
     } else {      } else {
  $add='<td bgcolor="#FFAAAA">';   $add='<td bgcolor="#CCCCFF">';
  if ($tcode eq '2') {   if ($tcode eq '2') {
     $add='<td bgcolor="#FFFFAA">';      $add='<td bgcolor="#FFFFAA">';
  }   }
Line 618  sub handler { Line 664  sub handler {
     if ($code eq '1') {      if ($code eq '1') {
  $hwke='</b> ('.$ctext.')</font>';   $hwke='</b> ('.$ctext.')</font>';
     }      }
     if ($code eq '2') {      if ($code eq '2' || $code eq '4') {
  $hwk='<font color="#992222"><b>';   $hwk='<font color="#992222"><b>';
  $hwke='</b> ('.$ctext.')</font>';   $hwke='</b> ('.$ctext.')</font>';
     }      }
Line 626  sub handler { Line 672  sub handler {
  $hwk='<font color="#229922"><b>';   $hwk='<font color="#229922"><b>';
  $hwke='</b> ('.$ctext.')</font>';   $hwke='</b> ('.$ctext.')</font>';
     }      }
     if ($code eq '4') {  
  $hwk='<font color="#229922"><b>';  
  $hwke='</b> ('.$ctext.')</font>';  
     }  
  }   }
  if ($hash{'src_'.$rid} eq $currenturl) {   if ($rid && $hash{'src_'.$rid} eq $currenturl) {
     $add=$add.'<a name="curloc"></a>'.      $add=$add.'<a name="curloc"></a>'.
  '<font color=red size=+2><b>&gt; </b></font>';   '<font color=red size=+2><b>&gt; </b></font>';
     $adde=      $adde=
  '<font color=red size=+2><b> &lt;</b></font>'.$adde;   '<font color=red size=+2><b> &lt;</b></font>'.$adde;
  }   }
  my $src=  
     &Apache::lonnet::declutter($hash{'src_'.$rid});  
  $rid=~/^(\d+)\.(\d+)$/;  
  my $symb=  
     &Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.$src;  
  if ($discussiontimes{$symb}>$lastcheck) {   if ($discussiontimes{$symb}>$lastcheck) {
     $adde=      $adde=
  '<img border=0 src="/adm/lonMisc/chat.gif">'.   '<img border=0 src="/adm/lonMisc/chat.gif">'.
Line 669  sub handler { Line 706  sub handler {
  }   }
     }      }
  }   }
  $r->print($add.'<a href="'.$hash{'src_'.$rid}.   if ($indent) {
   '">'.$hwk.      my $is="&nbsp;&nbsp;";
   $hash{'title_'.$rid}.$hwke.'</a>'.$adde);      for(my $i=-1;$i<$indent;$i++) { $indentstr.=$is; }
    }
    if (!$linkid) { $linkid=$rid; }
                           if ($hash{'randomout_'.$rid}) {
                               $adde=' <i>(hidden)</i>'.$adde;
                           }
    $r->print($add.$indentstr);
    if ($rid) {
       $r->print('<a href="'.$hash{'src_'.$linkid}.
                                         (($hash{'src_'.$linkid}=~/\?/)?'&':'?').
                                         'symb='.&Apache::lonnet::escape($symb)
                                          .'">'.
         $hwk.$hash{'title_'.$rid}.$hwke.'</a>');
    }
    $r->print($adde);
     }      }
     $r->print('</tr>');      $r->print('</tr>');
  }   }

Removed from v.1.29  
changed lines
  Added in v.1.46


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