Annotation of rat/lonpage.pm, revision 1.4
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.3 www 7: # 08/30,08/31,09/06,09/14 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)=@_;
! 81: $r->print('<td colspan="'.$colspan.'">');
! 82: $r->print($hash{'src_'.$rid});
! 83: $r->print('</td>');
! 84: }
1.2 www 85:
1.1 www 86: # ================================================================ Main Handler
87:
88: sub handler {
89: my $r=shift;
90:
1.3 www 91: # ------------------------------------------- Set document type for header only
1.1 www 92:
1.3 www 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: }
1.1 www 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:
1.3 www 115: @rows=();
1.2 www 116:
117: &tracetable(0,$firstres,'&'.$lastres.'&');
1.4 ! www 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: }
1.2 www 125:
126: my $i;
1.4 ! www 127: my $j;
1.3 www 128: my $maxcols=-1;
129:
130: # --------------------------------------------- Get SSI output, post parameters
131:
1.2 www 132: for ($i=0;$i<=$#rows;$i++) {
1.4 ! www 133: if ($rows[$i]) {
1.3 www 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;
1.4 ! www 146: }
1.2 www 147: }
1.3 www 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
1.4 ! www 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>');
1.3 www 174: # -------------------------------------------------------------------- End page
175: }
1.1 www 176: # ------------------------------------------------------------- End render page
177: } else {
1.3 www 178: $r->content_type('text/html');
179: $r->send_http_header;
180: $r->print('<html><body>Page undefined.</body></html>');
1.1 www 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>