Annotation of rat/lonpage.pm, revision 1.6
1.1 www 1: # The LearningOnline Network with CAPA
2: # Page Handler
3: #
4: # (TeX Content Handler
5: #
6: # 05/29/00,05/30 Gerd Kortemeyer)
1.6 ! www 7: # 08/30,08/31,09/06,09/14,09/15,09/16 Gerd Kortemeyer
1.1 www 8:
9: package Apache::lonpage;
10:
11: use strict;
12: use Apache::Constants qw(:common :http);
13: use Apache::lonnet();
1.6 ! www 14: use HTML::TokeParser;
1.1 www 15: use GDBM_File;
16:
1.2 www 17: # -------------------------------------------------------------- Module Globals
18: my %hash;
19: my @rows;
1.6 ! www 20:
! 21: # ------------------------------------------------------------------ Euclid gcd
! 22:
! 23: sub euclid {
! 24: my ($e,$f)=@_;
! 25: my $a; my $b; my $r;
! 26: if ($e>$f) { $b=$e; $r=$f; } else { $r=$e; $b=$f; }
! 27: while ($r!=0) {
! 28: $a=$b; $b=$r;
! 29: $r=$a%$b;
! 30: }
! 31: return $b;
! 32: }
1.2 www 33:
34: # ------------------------------------------------------------ Build page table
35:
36: sub tracetable {
37: my ($sofar,$rid,$beenhere)=@_;
38: my $further=$sofar;
39: unless ($beenhere=~/\&$rid\&/) {
40: $beenhere.=$rid.'&';
41:
42: if (defined($hash{'is_map_'.$rid})) {
43: if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
44: (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
1.4 www 45: my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
46: $sofar=
1.2 www 47: &tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},
1.3 www 48: '&'.$frid.'&');
1.4 www 49: $sofar++;
50: if ($hash{'src_'.$frid}) {
1.3 www 51: my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$frid});
52: if (($brepriv eq '2') || ($brepriv eq 'F')) {
53: if (defined($rows[$sofar])) {
54: $rows[$sofar].='&'.$frid;
55: } else {
56: $rows[$sofar]=$frid;
57: }
58: }
1.4 www 59: }
1.2 www 60: }
61: } else {
1.4 www 62: $sofar++;
63: if ($hash{'src_'.$rid}) {
1.3 www 64: my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$rid});
65: if (($brepriv eq '2') || ($brepriv eq 'F')) {
66: if (defined($rows[$sofar])) {
1.2 www 67: $rows[$sofar].='&'.$rid;
1.3 www 68: } else {
1.2 www 69: $rows[$sofar]=$rid;
1.3 www 70: }
71: }
1.4 www 72: }
1.2 www 73: }
74:
75: if (defined($hash{'to_'.$rid})) {
76: map {
77: my $now=&tracetable($sofar,$hash{'goesto_'.$_},$beenhere);
78: if ($now>$further) { $further=$now; }
79: } split(/\,/,$hash{'to_'.$rid});
80: }
81: }
82: return $further;
83: }
84:
1.1 www 85: # ================================================================ Main Handler
86:
87: sub handler {
88: my $r=shift;
89:
1.3 www 90: # ------------------------------------------- Set document type for header only
1.1 www 91:
1.3 www 92: if ($r->header_only) {
93: if ($ENV{'browser.mathml'}) {
94: $r->content_type('text/xml');
95: } else {
96: $r->content_type('text/html');
97: }
98: $r->send_http_header;
99: return OK;
100: }
1.1 www 101:
102: my $requrl=$r->uri;
103: # ----------------------------------------------------------------- Tie db file
104: if ($ENV{'request.course.fn'}) {
105: my $fn=$ENV{'request.course.fn'};
106: if (-e "$fn.db") {
107: if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_WRCREAT,0640)) {
108: # ------------------------------------------------------------------- Hash tied
109: my $firstres=$hash{'map_start_'.$requrl};
110: my $lastres=$hash{'map_finish_'.$requrl};
111: if (($firstres) && ($lastres)) {
112: # ----------------------------------------------------------------- Render page
113:
1.3 www 114: @rows=();
1.2 www 115:
116: &tracetable(0,$firstres,'&'.$lastres.'&');
1.4 www 117: if ($hash{'src_'.$lastres}) {
118: my $brepriv=
119: &Apache::lonnet::allowed('bre',$hash{'src_'.$lastres});
120: if (($brepriv eq '2') || ($brepriv eq 'F')) {
121: $rows[$#rows+1]=''.$lastres;
122: }
123: }
1.2 www 124:
125: my $i;
1.4 www 126: my $j;
1.6 ! www 127: my $lcm=1;
! 128: my $contents=0;
! 129:
! 130: my %ssibody=();
! 131: my %ssibgcolor=();
! 132: my %ssitext=();
! 133: my %ssilink=();
! 134: my %ssivlink=();
! 135: my %ssialink=();
! 136: my %cellemb=();
1.3 www 137:
138: # --------------------------------------------- Get SSI output, post parameters
139:
1.2 www 140: for ($i=0;$i<=$#rows;$i++) {
1.4 www 141: if ($rows[$i]) {
1.6 ! www 142: $contents++;
1.3 www 143: my @colcont=split(/\&/,$rows[$i]);
1.6 ! www 144: $lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
1.3 www 145: map {
146: my $src=$hash{'src_'.$_};
1.5 www 147: $src=~/\.(\w+)$/;
1.3 www 148: $cellemb{$_}=Apache::lonnet::fileembstyle($1);
149: if ($cellemb{$_} eq 'ssi') {
150: # --------------------------------------------------------- This is an SSI cell
1.5 www 151: my $prefix=$_.'_';
152: my %posthash=('request.prefix' => $prefix);
153: map {
154: if ($_=~/^form.$prefix/) {
155: my $name=$_;
156: $name=~s/^form.$prefix//;
157: $posthash{$name}=$ENV{$_};
158: }
159: } keys %ENV;
160: my $output=Apache::lonnet::ssi($src,%posthash);
1.6 ! www 161: my $parser=HTML::TokeParser->new(\$output);
! 162: my $token;
! 163: my $bodydef=0;
! 164: while (($bodydef==0) &&
! 165: ($token=$parser->get_token)) {
! 166: if ($token->[1] eq 'body') {
! 167: $bodydef=1
! 168: }
! 169: if ($token->[1] eq 'meta') {
! 170: }
! 171: if ($token->[1] eq 'script') {
! 172: }
! 173: if ($token->[1] eq 'basefont') {
! 174: }
! 175: }
! 176: if ($output=~/\<body[^\>]*\>(.*)/si) {
! 177: $output=$1;
! 178: }
! 179: $output=~s/\<\/body\>.*//si;
1.5 www 180: $ssibody{$_}=$output;
1.3 www 181:
182: # ---------------------------------------------------------------- End SSI cell
183: }
184: } @colcont;
1.4 www 185: }
1.2 www 186: }
1.6 ! www 187: unless ($contents) {
1.3 www 188: $r->content_type('text/html');
189: $r->send_http_header;
190: $r->print('<html><body>Empty page.</body></html>');
191: } else {
192: # ------------------------------------------------------------------ Build page
1.4 www 193: $r->content_type('text/html');
194: $r->send_http_header;
195: $r->print('<html><body>');
196:
1.6 ! www 197: $r->print('<table cols="'.$lcm.'" border="1">');
1.5 www 198: for ($i=0;$i<=$#rows;$i++) {
199: if ($rows[$i]) {
1.4 www 200: $r->print("\n<tr>");
201: my @colcont=split(/\&/,$rows[$i]);
1.6 ! www 202: my $avespan=$lcm/($#colcont+1);
! 203: for ($j=0;$j<=$#colcont;$j++) {
! 204: my $rid=$colcont[$j];
! 205: $r->print('<td colspan="'.$avespan.'"');
! 206: if ($cellemb{$rid} eq 'ssi') {
! 207: $r->print('>'.$ssibody{$rid});
! 208: } elsif ($cellemb{$rid} eq 'img') {
! 209: $r->print('><img src="'.
! 210: $hash{'src_'.$rid}.'">');
! 211: }
! 212: $r->print('</td>');
1.4 www 213: }
214: $r->print('</tr>');
1.5 www 215: }
1.4 www 216: }
217: $r->print("\n</table>");
1.5 www 218:
1.4 www 219: $r->print('</body></html>');
1.3 www 220: # -------------------------------------------------------------------- End page
221: }
1.1 www 222: # ------------------------------------------------------------- End render page
223: } else {
1.3 www 224: $r->content_type('text/html');
225: $r->send_http_header;
226: $r->print('<html><body>Page undefined.</body></html>');
1.1 www 227: }
228: # ------------------------------------------------------------------ Untie hash
229: unless (untie(%hash)) {
230: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
231: "Could not untie coursemap $fn (browse).</font>");
232: }
233: # -------------------------------------------------------------------- All done
234: return OK;
235: # ----------------------------------------------- Errors, hash could no be tied
236: }
237: }
238: }
239: $ENV{'user.error.msg'}="$requrl:bre:1:1:Course not initialized";
240: return HTTP_NOT_ACCEPTABLE;
241: }
242:
243: 1;
244: __END__
245:
246:
247:
248:
249:
250:
251:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>