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