Annotation of rat/lonpage.pm, revision 1.5
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.5 ! www 7: # 08/30,08/31,09/06,09/14,09/15 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();
14: use GDBM_File;
15:
1.2 www 16: # -------------------------------------------------------------- Module Globals
17: my %hash;
18: my @rows;
1.4 www 19:
20: my %ssibody=();
21: my %ssibgcolor=();
22: my %ssitext=();
23: my %ssilink=();
24: my %ssivlink=();
25: my %ssialink=();
26: my %cellemb=();
1.2 www 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}}))) {
1.4 www 39: my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
40: $sofar=
1.2 www 41: &tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},
1.3 www 42: '&'.$frid.'&');
1.4 www 43: $sofar++;
44: if ($hash{'src_'.$frid}) {
1.3 www 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: }
1.4 www 53: }
1.2 www 54: }
55: } else {
1.4 www 56: $sofar++;
57: if ($hash{'src_'.$rid}) {
1.3 www 58: my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$rid});
59: if (($brepriv eq '2') || ($brepriv eq 'F')) {
60: if (defined($rows[$sofar])) {
1.2 www 61: $rows[$sofar].='&'.$rid;
1.3 www 62: } else {
1.2 www 63: $rows[$sofar]=$rid;
1.3 www 64: }
65: }
1.4 www 66: }
1.2 www 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:
1.4 www 79: sub cell {
80: my ($r,$colspan,$rid)=@_;
1.5 ! www 81: $r->print('<td colspan="'.$colspan.'"');
! 82: if ($cellemb{$rid} eq 'ssi') {
! 83: $r->print('>'.$ssibody{$rid});
! 84: } elsif ($cellemb{$rid} eq 'img') {
! 85: $r->print('><img src="'.$hash{'src_'.$rid}.'">');
! 86: }
1.4 www 87: $r->print('</td>');
88: }
1.2 www 89:
1.1 www 90: # ================================================================ Main Handler
91:
92: sub handler {
93: my $r=shift;
94:
1.3 www 95: # ------------------------------------------- Set document type for header only
1.1 www 96:
1.3 www 97: if ($r->header_only) {
98: if ($ENV{'browser.mathml'}) {
99: $r->content_type('text/xml');
100: } else {
101: $r->content_type('text/html');
102: }
103: $r->send_http_header;
104: return OK;
105: }
1.1 www 106:
107: my $requrl=$r->uri;
108: # ----------------------------------------------------------------- Tie db file
109: if ($ENV{'request.course.fn'}) {
110: my $fn=$ENV{'request.course.fn'};
111: if (-e "$fn.db") {
112: if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_WRCREAT,0640)) {
113: # ------------------------------------------------------------------- Hash tied
114: my $firstres=$hash{'map_start_'.$requrl};
115: my $lastres=$hash{'map_finish_'.$requrl};
116: if (($firstres) && ($lastres)) {
117: # ----------------------------------------------------------------- Render page
118:
1.3 www 119: @rows=();
1.2 www 120:
121: &tracetable(0,$firstres,'&'.$lastres.'&');
1.4 www 122: if ($hash{'src_'.$lastres}) {
123: my $brepriv=
124: &Apache::lonnet::allowed('bre',$hash{'src_'.$lastres});
125: if (($brepriv eq '2') || ($brepriv eq 'F')) {
126: $rows[$#rows+1]=''.$lastres;
127: }
128: }
1.2 www 129:
130: my $i;
1.4 www 131: my $j;
1.3 www 132: my $maxcols=-1;
133:
134: # --------------------------------------------- Get SSI output, post parameters
135:
1.2 www 136: for ($i=0;$i<=$#rows;$i++) {
1.4 www 137: if ($rows[$i]) {
1.3 www 138: my @colcont=split(/\&/,$rows[$i]);
139: $maxcols=$#colcont>$maxcols?$#colcont:$maxcols;
140: map {
141: my $src=$hash{'src_'.$_};
1.5 ! www 142: $src=~/\.(\w+)$/;
1.3 www 143: $cellemb{$_}=Apache::lonnet::fileembstyle($1);
144: if ($cellemb{$_} eq 'ssi') {
145: # --------------------------------------------------------- This is an SSI cell
1.5 ! www 146: my $prefix=$_.'_';
! 147: my %posthash=('request.prefix' => $prefix);
! 148: map {
! 149: if ($_=~/^form.$prefix/) {
! 150: my $name=$_;
! 151: $name=~s/^form.$prefix//;
! 152: $posthash{$name}=$ENV{$_};
! 153: }
! 154: } keys %ENV;
! 155: my $output=Apache::lonnet::ssi($src,%posthash);
! 156:
! 157: $ssibody{$_}=$output;
1.3 www 158:
159: # ---------------------------------------------------------------- End SSI cell
160: }
161: } @colcont;
1.4 www 162: }
1.2 www 163: }
1.3 www 164: if ($maxcols<0) {
165: $r->content_type('text/html');
166: $r->send_http_header;
167: $r->print('<html><body>Empty page.</body></html>');
168: } else {
169: # ------------------------------------------------------------------ Build page
1.4 www 170: $maxcols++;
171: $r->content_type('text/html');
172: $r->send_http_header;
173: $r->print('<html><body>');
174:
175: $r->print('<table cols="'.$maxcols.'" rows="'.
1.5 ! www 176: $#rows.'" border="0">');
! 177: for ($i=0;$i<=$#rows;$i++) {
! 178: if ($rows[$i]) {
1.4 www 179: $r->print("\n<tr>");
180: my @colcont=split(/\&/,$rows[$i]);
181: my $avespan=int($maxcols/($#colcont+1));
182: my $lastspan=$maxcols-$avespan*$#colcont;
183: for ($j=0;$j<$#colcont;$j++) {
184: &cell($r,$avespan,$colcont[$j]);
185: }
186: &cell($r,$lastspan,$colcont[$#colcont]);
187: $r->print('</tr>');
1.5 ! www 188: }
1.4 www 189: }
190: $r->print("\n</table>");
1.5 ! www 191:
1.4 www 192: $r->print('</body></html>');
1.3 www 193: # -------------------------------------------------------------------- End page
194: }
1.1 www 195: # ------------------------------------------------------------- End render page
196: } else {
1.3 www 197: $r->content_type('text/html');
198: $r->send_http_header;
199: $r->print('<html><body>Page undefined.</body></html>');
1.1 www 200: }
201: # ------------------------------------------------------------------ Untie hash
202: unless (untie(%hash)) {
203: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
204: "Could not untie coursemap $fn (browse).</font>");
205: }
206: # -------------------------------------------------------------------- All done
207: return OK;
208: # ----------------------------------------------- Errors, hash could no be tied
209: }
210: }
211: }
212: $ENV{'user.error.msg'}="$requrl:bre:1:1:Course not initialized";
213: return HTTP_NOT_ACCEPTABLE;
214: }
215:
216: 1;
217: __END__
218:
219:
220:
221:
222:
223:
224:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>