File:  [LON-CAPA] / loncom / interface / lonnavmaps.pm
Revision 1.7: download - view: text, annotated - select for diffs
Tue Jan 16 22:19:18 2001 UTC (23 years, 5 months ago) by www
Branches: MAIN
CVS tags: HEAD
Different color for homework problems

    1: # The LearningOnline Network with CAPA
    2: # Navigate Maps Handler
    3: #
    4: # (Page Handler
    5: #
    6: # (TeX Content Handler
    7: #
    8: # 05/29/00,05/30 Gerd Kortemeyer)
    9: # 08/30,08/31,09/06,09/14,09/15,09/16,09/19,09/20,09/21,09/23,
   10: # 10/02,10/10,10/14,10/16,10/18,10/19,10/31,11/6,11/14,11/16 Gerd Kortemeyer)
   11: #
   12: # 3/1/1,6/1 Gerd Kortemeyer
   13: 
   14: package Apache::lonnavmaps;
   15: 
   16: use strict;
   17: use Apache::Constants qw(:common :http);
   18: use Apache::lonnet();
   19: use HTML::TokeParser;
   20: use GDBM_File;
   21: 
   22: # -------------------------------------------------------------- Module Globals
   23: my %hash;
   24: my @rows;
   25: 
   26: # ------------------------------------------------------------------ Euclid gcd
   27: 
   28: sub euclid {
   29:     my ($e,$f)=@_;
   30:     my $a; my $b; my $r;
   31:     if ($e>$f) { $b=$e; $r=$f; } else { $r=$e; $b=$f; }
   32:     while ($r!=0) {
   33: 	$a=$b; $b=$r;
   34:         $r=$a%$b;
   35:     }
   36:     return $b;
   37: }
   38: 
   39: # ------------------------------------------------------------ Build page table
   40: 
   41: sub tracetable {
   42:     my ($sofar,$rid,$beenhere)=@_;
   43:     my $further=$sofar;
   44:     unless ($beenhere=~/\&$rid\&/) {
   45:        $beenhere.=$rid.'&';  
   46: 
   47:        if (defined($hash{'is_map_'.$rid})) {
   48:            $sofar++;
   49:            my $tprefix='';
   50:            if ($hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}} 
   51:             eq 'sequence') { 
   52:                $tprefix='h'; 
   53:            }
   54:            if (defined($rows[$sofar])) {
   55:               $rows[$sofar].='&'.$tprefix.$rid;
   56:            } else {
   57:               $rows[$sofar]=$tprefix.$rid;
   58:            }
   59:            if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
   60:                (defined($hash{'map_finish_'.$hash{'src_'.$rid}})) &&
   61:                ($tprefix eq 'h')) {
   62:               my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
   63: 	      $sofar=
   64:                 &tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},
   65:                 '&'.$frid.'&');
   66:               $sofar++;
   67:               if ($hash{'src_'.$frid}) {
   68:                my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$frid});
   69:                if (($brepriv eq '2') || ($brepriv eq 'F')) {
   70: 		 my $pprefix='';
   71:                  if ($hash{'src_'.$frid}=~/\.problem$/) {
   72: 		     $pprefix='p1';
   73:                  }
   74:                  if (defined($rows[$sofar])) {
   75:                    $rows[$sofar].='&'.$pprefix.$frid;
   76:                  } else {
   77:                    $rows[$sofar]=$pprefix.$frid;
   78:                  }
   79: 	       }
   80: 	      }
   81: 	   }
   82:        } else {
   83:           $sofar++;
   84:           if ($hash{'src_'.$rid}) {
   85:            my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$rid});
   86:            if (($brepriv eq '2') || ($brepriv eq 'F')) {
   87: 	     my $pprefix='';
   88:              if ($hash{'src_'.$rid}=~/\.problem$/) {
   89: 	         $pprefix='p1';
   90:              }
   91:              if (defined($rows[$sofar])) {
   92:                 $rows[$sofar].='&'.$pprefix.$rid;
   93:              } else {
   94:                $rows[$sofar]=$pprefix.$rid;
   95:              }
   96: 	   }
   97:           }
   98:        }
   99: 
  100:        if (defined($hash{'to_'.$rid})) {
  101: 	  my $mincond=1;
  102:           my $next='';
  103:           map {
  104:               my $thiscond=
  105:       &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
  106:               if ($thiscond>=$mincond) {
  107: 		  if ($next) {
  108: 		      $next.=','.$_.':'.$thiscond;
  109:                   } else {
  110:                       $next=$_.':'.$thiscond;
  111: 		  }
  112:                   if ($thiscond>$mincond) { $mincond=$thiscond; }
  113: 	      }
  114:           } split(/\,/,$hash{'to_'.$rid});
  115:           map {
  116:               my ($linkid,$condval)=split(/\:/,$_);
  117:               if ($condval>=$mincond) {
  118:                 my $now=&tracetable($sofar,$hash{'goesto_'.$linkid},$beenhere);
  119:                 if ($now>$further) { $further=$now; }
  120: 	      }
  121:           } split(/\,/,$next);
  122: 
  123:        }
  124:     }
  125:     return $further;
  126: }
  127: 
  128: # ================================================================ Main Handler
  129: 
  130: sub handler {
  131:   my $r=shift;
  132: 
  133: 
  134: # ------------------------------------------- Set document type for header only
  135: 
  136:   if ($r->header_only) {
  137:        if ($ENV{'browser.mathml'}) {
  138:            $r->content_type('text/xml');
  139:        } else {
  140:            $r->content_type('text/html');
  141:        }
  142:        $r->send_http_header;
  143:        return OK;
  144:    }
  145: 
  146:   my $requrl=$r->uri;
  147: # ----------------------------------------------------------------- Tie db file
  148:   if ($ENV{'request.course.fn'}) {
  149:       my $fn=$ENV{'request.course.fn'};
  150:       if (-e "$fn.db") {
  151:           if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) {
  152: # ------------------------------------------------------------------- Hash tied
  153:               my $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}};
  154:               my $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}};
  155:               if (($firstres) && ($lastres)) {
  156: # ----------------------------------------------------------------- Render page
  157: 
  158:                   @rows=();
  159: 
  160:                   &tracetable(0,$firstres,'&'.$lastres.'&');
  161:                   if ($hash{'src_'.$lastres}) {
  162:                      my $brepriv=
  163:                         &Apache::lonnet::allowed('bre',$hash{'src_'.$lastres});
  164:                      if (($brepriv eq '2') || ($brepriv eq 'F')) {
  165:                         $rows[$#rows+1]=''.$lastres;
  166: 		     }
  167: 		  }
  168: 
  169: # ------------------------------------------------------------------ Page parms
  170: 
  171:                   my $j;
  172:                   my $i;
  173:                   my $lcm=1;
  174:                   my $contents=0;
  175: 
  176: # ---------------------------------------------- Go through table to get layout
  177: 
  178:                   for ($i=0;$i<=$#rows;$i++) {
  179: 		     if ($rows[$i]) {
  180: 		      $contents++;
  181:                       my @colcont=split(/\&/,$rows[$i]);
  182:                       $lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
  183:                      } 
  184:                   }
  185: 
  186: 
  187:                   unless ($contents) {
  188:                       $r->content_type('text/html');
  189:                       $r->send_http_header;
  190:                       $r->print('<html><body>Empty Map.</body></html>');
  191:                   } else {
  192: # ------------------------------------------------------------------ Build page
  193: 
  194: # ---------------------------------------------------------------- Send headers
  195: 
  196:                           $r->content_type('text/html');
  197:                           $r->send_http_header;
  198:                           $r->print(
  199:                    '<html><head><title>Navigate LON-CAPA Maps</title></head>');
  200: 
  201: 			  $r->print('<body bgcolor="#FFFFFF">'.
  202:                            '<img align=right src=/adm/lonIcons/lonlogos.gif>'.
  203:                                     '<h1>Navigate Course Map</h1>');
  204:                           $r->rflush();
  205: # ----------------------------------------------------------------- Start table
  206:                       $r->print('<table cols="'.$lcm.'" border="0">');
  207:                       for ($i=0;$i<=$#rows;$i++) {
  208: 			if ($rows[$i]) {
  209:                           $r->print("\n<tr>");
  210:                           my @colcont=split(/\&/,$rows[$i]);
  211:                           my $avespan=$lcm/($#colcont+1);
  212:                           for ($j=0;$j<=$#colcont;$j++) {
  213:                               my $rid=$colcont[$j];
  214:                               my $add='<td>&nbsp;&nbsp;';
  215:                               my $adde='</td>';
  216:                               my $hwk='<font color="#223322">';
  217:                               my $hwke='</font>';
  218:                               if ($rid=~/^h(.+)/) {
  219: 				  $rid=$1;
  220:                                   $add='<th bgcolor="#AAFF55">';
  221:                                   $adde='</th>';
  222:                               }
  223:                               if ($rid=~/^p(\d)(.+)/) {
  224:                                   my $code=$1;
  225:                                   $rid=$2;
  226:                                   $hwk='<font color="#999911">';
  227:                                   if ($code eq '2') {
  228:                                      $hwk='<font color="#999911"><b>';
  229:                                      $hwke='</b></font>';
  230:                                   }
  231:                                   if ($code eq '3') {
  232:                                      $hwk='<font color="#229922">';
  233:                                   } elsif ($code eq '4') {
  234:                                      $hwk='<font color="#992222">';
  235:                                   }
  236:                               }
  237:                               $r->print($add.'<a href="'.$hash{'src_'.$rid}.
  238:                                 '">'.$hwk.
  239:                                 $hash{'title_'.$rid}.$hwke.'</a>'.$adde);
  240:                           }
  241:                           $r->print('</tr>');
  242: 		        }
  243:                       }
  244:                       $r->print("\n</table>");
  245: 
  246:                       $r->print('</body></html>');
  247: # -------------------------------------------------------------------- End page
  248:                   }                  
  249: # ------------------------------------------------------------- End render page
  250:               } else {
  251:                   $r->content_type('text/html');
  252:                   $r->send_http_header;
  253: 		  $r->print('<html><body>Coursemap undefined.</body></html>');
  254:               }
  255: # ------------------------------------------------------------------ Untie hash
  256:               unless (untie(%hash)) {
  257:                    &Apache::lonnet::logthis("<font color=blue>WARNING: ".
  258:                        "Could not untie coursemap $fn (browse).</font>"); 
  259:               }
  260: # -------------------------------------------------------------------- All done
  261: 	      return OK;
  262: # ----------------------------------------------- Errors, hash could no be tied
  263:           }
  264:       } 
  265:   }
  266: 
  267:   $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
  268:   return HTTP_NOT_ACCEPTABLE; 
  269: }
  270: 
  271: 1;
  272: __END__
  273: 
  274: 
  275: 
  276: 
  277: 
  278: 
  279: 

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