File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.4: download - view: text, annotated - select for diffs
Thu Sep 14 20:10:39 2000 UTC (23 years, 7 months ago) by www
Branches: MAIN
CVS tags: HEAD
Table output

    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,09/06,09/14 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: my %ssibody=();
   21: my %ssibgcolor=();
   22: my %ssitext=();
   23: my %ssilink=();
   24: my %ssivlink=();
   25: my %ssialink=();
   26: my %cellemb=();
   27: 
   28: # ------------------------------------------------------------ Build page table
   29: 
   30: sub tracetable {
   31:     my ($sofar,$rid,$beenhere)=@_;
   32:     my $further=$sofar;
   33:     unless ($beenhere=~/\&$rid\&/) {
   34:        $beenhere.=$rid.'&';  
   35: 
   36:        if (defined($hash{'is_map_'.$rid})) {
   37:            if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
   38:                (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
   39:               my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
   40: 	      $sofar=
   41:                 &tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},
   42:                 '&'.$frid.'&');
   43:               $sofar++;
   44:               if ($hash{'src_'.$frid}) {
   45:                my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$frid});
   46:                if (($brepriv eq '2') || ($brepriv eq 'F')) {
   47:                  if (defined($rows[$sofar])) {
   48:                    $rows[$sofar].='&'.$frid;
   49:                  } else {
   50:                    $rows[$sofar]=$frid;
   51:                  }
   52: 	       }
   53: 	      }
   54: 	   }
   55:        } else {
   56:           $sofar++;
   57:           if ($hash{'src_'.$rid}) {
   58:            my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$rid});
   59:            if (($brepriv eq '2') || ($brepriv eq 'F')) {
   60:              if (defined($rows[$sofar])) {
   61:                $rows[$sofar].='&'.$rid;
   62:              } else {
   63:                $rows[$sofar]=$rid;
   64:              }
   65: 	   }
   66:           }
   67:        }
   68: 
   69:        if (defined($hash{'to_'.$rid})) {
   70:           map {
   71:               my $now=&tracetable($sofar,$hash{'goesto_'.$_},$beenhere);
   72:               if ($now>$further) { $further=$now; }
   73:           } split(/\,/,$hash{'to_'.$rid});
   74:        }
   75:     }
   76:     return $further;
   77: }
   78: 
   79: sub cell {
   80:     my ($r,$colspan,$rid)=@_;
   81:     $r->print('<td colspan="'.$colspan.'">');
   82:     $r->print($hash{'src_'.$rid});
   83:     $r->print('</td>');
   84: }
   85: 
   86: # ================================================================ Main Handler
   87: 
   88: sub handler {
   89:   my $r=shift;
   90: 
   91: # ------------------------------------------- Set document type for header only
   92: 
   93:   if ($r->header_only) {
   94:        if ($ENV{'browser.mathml'}) {
   95:            $r->content_type('text/xml');
   96:        } else {
   97:            $r->content_type('text/html');
   98:        }
   99:        $r->send_http_header;
  100:        return OK;
  101:    }
  102: 
  103:   my $requrl=$r->uri;
  104: # ----------------------------------------------------------------- Tie db file
  105:   if ($ENV{'request.course.fn'}) {
  106:       my $fn=$ENV{'request.course.fn'};
  107:       if (-e "$fn.db") {
  108:           if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_WRCREAT,0640)) {
  109: # ------------------------------------------------------------------- Hash tied
  110:               my $firstres=$hash{'map_start_'.$requrl};
  111:               my $lastres=$hash{'map_finish_'.$requrl};
  112:               if (($firstres) && ($lastres)) {
  113: # ----------------------------------------------------------------- Render page
  114: 
  115:                   @rows=();
  116: 
  117:                   &tracetable(0,$firstres,'&'.$lastres.'&');
  118:                   if ($hash{'src_'.$lastres}) {
  119:                      my $brepriv=
  120:                         &Apache::lonnet::allowed('bre',$hash{'src_'.$lastres});
  121:                      if (($brepriv eq '2') || ($brepriv eq 'F')) {
  122:                         $rows[$#rows+1]=''.$lastres;
  123: 		     }
  124: 		  }
  125: 
  126:                   my $i;
  127:                   my $j;
  128:                   my $maxcols=-1;
  129: 
  130: # --------------------------------------------- Get SSI output, post parameters
  131: 
  132:                   for ($i=0;$i<=$#rows;$i++) {
  133: 		     if ($rows[$i]) {
  134:                       my @colcont=split(/\&/,$rows[$i]);
  135:                       $maxcols=$#colcont>$maxcols?$#colcont:$maxcols;
  136:                       map {
  137:                           my $src=$hash{'src_'.$_};
  138:                           $src=~/\.\w+$/;
  139:                           $cellemb{$_}=Apache::lonnet::fileembstyle($1);
  140:                           if ($cellemb{$_} eq 'ssi') {
  141: # --------------------------------------------------------- This is an SSI cell
  142: 
  143: # ---------------------------------------------------------------- End SSI cell
  144:                           }
  145:                       } @colcont;
  146:                      } 
  147:                   }
  148:                   if ($maxcols<0) {
  149:                       $r->content_type('text/html');
  150:                       $r->send_http_header;
  151:                       $r->print('<html><body>Empty page.</body></html>');
  152:                   } else {
  153: # ------------------------------------------------------------------ Build page
  154:                       $maxcols++;
  155:                       $r->content_type('text/html');
  156:                       $r->send_http_header;
  157:                       $r->print('<html><body>');
  158:  
  159:                       $r->print('<table cols="'.$maxcols.'" rows="'.
  160:                                  $#rows.'" border=1>');
  161:                       for ($i=2;$i<=$#rows;$i++) {
  162:                           $r->print("\n<tr>");
  163:                           my @colcont=split(/\&/,$rows[$i]);
  164:                           my $avespan=int($maxcols/($#colcont+1));
  165:                           my $lastspan=$maxcols-$avespan*$#colcont;
  166:                           for ($j=0;$j<$#colcont;$j++) {
  167:                               &cell($r,$avespan,$colcont[$j]);
  168:                           }
  169:                           &cell($r,$lastspan,$colcont[$#colcont]);
  170:                           $r->print('</tr>');
  171:                       }
  172:                       $r->print("\n</table>");
  173:                       $r->print('</body></html>');
  174: # -------------------------------------------------------------------- End page
  175:                   }                  
  176: # ------------------------------------------------------------- End render page
  177:               } else {
  178:                   $r->content_type('text/html');
  179:                   $r->send_http_header;
  180: 		  $r->print('<html><body>Page undefined.</body></html>');
  181:               }
  182: # ------------------------------------------------------------------ Untie hash
  183:               unless (untie(%hash)) {
  184:                    &Apache::lonnet::logthis("<font color=blue>WARNING: ".
  185:                        "Could not untie coursemap $fn (browse).</font>"); 
  186:               }
  187: # -------------------------------------------------------------------- All done
  188: 	      return OK;
  189: # ----------------------------------------------- Errors, hash could no be tied
  190:           }
  191:       } 
  192:   }
  193:   $ENV{'user.error.msg'}="$requrl:bre:1:1:Course not initialized";
  194:   return HTTP_NOT_ACCEPTABLE; 
  195: }
  196: 
  197: 1;
  198: __END__
  199: 
  200: 
  201: 
  202: 
  203: 
  204: 
  205: 

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