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