File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.2: download - view: text, annotated - select for diffs
Thu Aug 31 10:14:08 2000 UTC (23 years, 8 months ago) by www
Branches: MAIN
CVS tags: HEAD
New versions development

    1: # The LearningOnline Network with CAPA
    2: # Page Handler
    3: #
    4: # (TeX Content Handler
    5: #
    6: # 05/29/00,05/30 Gerd Kortemeyer)
    7: # 08/30,08/31 Gerd Kortemeyer
    8: 
    9: package Apache::lonpage;
   10: 
   11: use strict;
   12: use Apache::Constants qw(:common :http);
   13: use Apache::lonnet();
   14: use GDBM_File;
   15: 
   16: # -------------------------------------------------------------- Module Globals
   17: my %hash;
   18: my @rows;
   19: 
   20: # ------------------------------------------------------------ Build page table
   21: 
   22: sub tracetable {
   23:     my ($sofar,$rid,$beenhere)=@_;
   24:     my $further=$sofar;
   25:     unless ($beenhere=~/\&$rid\&/) {
   26:        $beenhere.=$rid.'&';  
   27: 
   28:        if (defined($hash{'is_map_'.$rid})) {
   29:            if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
   30:                (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
   31: 	       $sofar=
   32:                 &tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},
   33:                 '&'.$hash{'map_finish_'.$hash{'src_'.$rid}}.'&');
   34:                $sofar++;
   35:                if (defined($rows[$sofar])) {
   36:                    $rows[$sofar].='&'.$hash{'map_finish_'.$hash{'src_'.$rid}};
   37:                } else {
   38:                    $rows[$sofar]=$hash{'map_finish_'.$hash{'src_'.$rid}};
   39:                }
   40: 	   }
   41:        } else {
   42:            $sofar++;
   43:            if (defined($rows[$sofar])) {
   44:                $rows[$sofar].='&'.$rid;
   45:            } else {
   46:                $rows[$sofar]=$rid;
   47:            }
   48:        }
   49: 
   50:        if (defined($hash{'to_'.$rid})) {
   51:           map {
   52:               my $now=&tracetable($sofar,$hash{'goesto_'.$_},$beenhere);
   53:               if ($now>$further) { $further=$now; }
   54:           } split(/\,/,$hash{'to_'.$rid});
   55:        }
   56:     }
   57:     return $further;
   58: }
   59: 
   60: 
   61: # ================================================================ Main Handler
   62: 
   63: sub handler {
   64:   my $r=shift;
   65: 
   66: # ----------------------------------------------------------- Set document type
   67: 
   68:   if ($ENV{'browser.mathml'}) {
   69:     $r->content_type('text/xml');
   70:   } else {
   71:     $r->content_type('text/html');
   72:   }
   73:   $r->send_http_header;
   74: 
   75:   return OK if $r->header_only;
   76: 
   77:   my $requrl=$r->uri;
   78: # ----------------------------------------------------------------- Tie db file
   79:   if ($ENV{'request.course.fn'}) {
   80:       my $fn=$ENV{'request.course.fn'};
   81:       if (-e "$fn.db") {
   82:           if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_WRCREAT,0640)) {
   83: # ------------------------------------------------------------------- Hash tied
   84:               my $firstres=$hash{'map_start_'.$requrl};
   85:               my $lastres=$hash{'map_finish_'.$requrl};
   86:               if (($firstres) && ($lastres)) {
   87: # ----------------------------------------------------------------- Render page
   88: 
   89: 		  $r->print("<h2>All is cool.</h2>");
   90: 
   91:                   @rows=();
   92:                   &tracetable(0,$firstres,'&'.$lastres.'&');
   93:                   $rows[$#rows+1]=''.$lastres;
   94: 
   95:                   my $i;
   96:                   for ($i=0;$i<=$#rows;$i++) {
   97:                       $r->print($i.' - '.$rows[$i].'<br>');
   98:                   }
   99: 
  100: # ------------------------------------------------------------- End render page
  101:               } else {
  102: 		  $r->print("<h2>Page undefined.</h2>");
  103:               }
  104: # ------------------------------------------------------------------ Untie hash
  105:               unless (untie(%hash)) {
  106:                    &Apache::lonnet::logthis("<font color=blue>WARNING: ".
  107:                        "Could not untie coursemap $fn (browse).</font>"); 
  108:               }
  109: # -------------------------------------------------------------------- All done
  110: 	      return OK;
  111: # ----------------------------------------------- Errors, hash could no be tied
  112:           }
  113:       } 
  114:   }
  115:   $ENV{'user.error.msg'}="$requrl:bre:1:1:Course not initialized";
  116:   return HTTP_NOT_ACCEPTABLE; 
  117: }
  118: 
  119: 1;
  120: __END__
  121: 
  122: 
  123: 
  124: 
  125: 
  126: 
  127: 

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