Annotation of loncom/interface/lonnavmaps.pm, revision 1.8
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.8 ! www 12: # 3/1/1,6/1,17/1 Gerd Kortemeyer
1.2 www 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})) {
1.7 www 48: $sofar++;
49: my $tprefix='';
50: if ($hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}}
51: eq 'sequence') {
52: $tprefix='h';
53: }
1.6 www 54: if (defined($rows[$sofar])) {
1.7 www 55: $rows[$sofar].='&'.$tprefix.$rid;
1.6 www 56: } else {
1.7 www 57: $rows[$sofar]=$tprefix.$rid;
1.6 www 58: }
1.2 www 59: if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
1.7 www 60: (defined($hash{'map_finish_'.$hash{'src_'.$rid}})) &&
61: ($tprefix eq 'h')) {
1.2 www 62: my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
63: $sofar=
64: &tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},
65: '&'.$frid.'&');
66: $sofar++;
67: if ($hash{'src_'.$frid}) {
68: my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$frid});
69: if (($brepriv eq '2') || ($brepriv eq 'F')) {
1.7 www 70: my $pprefix='';
71: if ($hash{'src_'.$frid}=~/\.problem$/) {
72: $pprefix='p1';
73: }
1.2 www 74: if (defined($rows[$sofar])) {
1.7 www 75: $rows[$sofar].='&'.$pprefix.$frid;
1.2 www 76: } else {
1.7 www 77: $rows[$sofar]=$pprefix.$frid;
1.2 www 78: }
79: }
80: }
81: }
82: } else {
83: $sofar++;
84: if ($hash{'src_'.$rid}) {
85: my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$rid});
86: if (($brepriv eq '2') || ($brepriv eq 'F')) {
1.7 www 87: my $pprefix='';
88: if ($hash{'src_'.$rid}=~/\.problem$/) {
89: $pprefix='p1';
90: }
1.2 www 91: if (defined($rows[$sofar])) {
1.7 www 92: $rows[$sofar].='&'.$pprefix.$rid;
1.2 www 93: } else {
1.7 www 94: $rows[$sofar]=$pprefix.$rid;
1.2 www 95: }
96: }
97: }
98: }
99:
100: if (defined($hash{'to_'.$rid})) {
101: my $mincond=1;
102: my $next='';
103: map {
104: my $thiscond=
105: &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
106: if ($thiscond>=$mincond) {
107: if ($next) {
108: $next.=','.$_.':'.$thiscond;
109: } else {
110: $next=$_.':'.$thiscond;
111: }
112: if ($thiscond>$mincond) { $mincond=$thiscond; }
113: }
114: } split(/\,/,$hash{'to_'.$rid});
115: map {
116: my ($linkid,$condval)=split(/\:/,$_);
117: if ($condval>=$mincond) {
118: my $now=&tracetable($sofar,$hash{'goesto_'.$linkid},$beenhere);
119: if ($now>$further) { $further=$now; }
120: }
121: } split(/\,/,$next);
122:
123: }
124: }
125: return $further;
126: }
127:
128: # ================================================================ Main Handler
1.1 www 129:
130: sub handler {
1.2 www 131: my $r=shift;
132:
133:
134: # ------------------------------------------- Set document type for header only
135:
136: if ($r->header_only) {
137: if ($ENV{'browser.mathml'}) {
138: $r->content_type('text/xml');
139: } else {
140: $r->content_type('text/html');
141: }
142: $r->send_http_header;
143: return OK;
144: }
145:
146: my $requrl=$r->uri;
147: # ----------------------------------------------------------------- Tie db file
148: if ($ENV{'request.course.fn'}) {
149: my $fn=$ENV{'request.course.fn'};
150: if (-e "$fn.db") {
151: if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) {
152: # ------------------------------------------------------------------- Hash tied
153: my $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}};
154: my $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}};
155: if (($firstres) && ($lastres)) {
156: # ----------------------------------------------------------------- Render page
157:
158: @rows=();
159:
160: &tracetable(0,$firstres,'&'.$lastres.'&');
161: if ($hash{'src_'.$lastres}) {
162: my $brepriv=
163: &Apache::lonnet::allowed('bre',$hash{'src_'.$lastres});
164: if (($brepriv eq '2') || ($brepriv eq 'F')) {
165: $rows[$#rows+1]=''.$lastres;
166: }
167: }
168:
169: # ------------------------------------------------------------------ Page parms
170:
171: my $j;
1.5 www 172: my $i;
1.2 www 173: my $lcm=1;
174: my $contents=0;
175:
176: # ---------------------------------------------- Go through table to get layout
177:
178: for ($i=0;$i<=$#rows;$i++) {
179: if ($rows[$i]) {
180: $contents++;
181: my @colcont=split(/\&/,$rows[$i]);
182: $lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
183: }
184: }
1.5 www 185:
1.2 www 186:
187: unless ($contents) {
188: $r->content_type('text/html');
189: $r->send_http_header;
190: $r->print('<html><body>Empty Map.</body></html>');
191: } else {
192: # ------------------------------------------------------------------ Build page
193:
194: # ---------------------------------------------------------------- Send headers
195:
196: $r->content_type('text/html');
197: $r->send_http_header;
198: $r->print(
199: '<html><head><title>Navigate LON-CAPA Maps</title></head>');
200:
201: $r->print('<body bgcolor="#FFFFFF">'.
1.8 ! www 202: '<script>window.focus();</script>'.
1.6 www 203: '<img align=right src=/adm/lonIcons/lonlogos.gif>'.
1.2 www 204: '<h1>Navigate Course Map</h1>');
1.3 www 205: $r->rflush();
1.2 www 206: # ----------------------------------------------------------------- Start table
207: $r->print('<table cols="'.$lcm.'" border="0">');
208: for ($i=0;$i<=$#rows;$i++) {
209: if ($rows[$i]) {
210: $r->print("\n<tr>");
211: my @colcont=split(/\&/,$rows[$i]);
212: my $avespan=$lcm/($#colcont+1);
213: for ($j=0;$j<=$#colcont;$j++) {
214: my $rid=$colcont[$j];
1.6 www 215: my $add='<td> ';
1.7 www 216: my $adde='</td>';
217: my $hwk='<font color="#223322">';
218: my $hwke='</font>';
1.6 www 219: if ($rid=~/^h(.+)/) {
220: $rid=$1;
221: $add='<th bgcolor="#AAFF55">';
1.7 www 222: $adde='</th>';
223: }
224: if ($rid=~/^p(\d)(.+)/) {
225: my $code=$1;
226: $rid=$2;
227: $hwk='<font color="#999911">';
228: if ($code eq '2') {
229: $hwk='<font color="#999911"><b>';
230: $hwke='</b></font>';
231: }
232: if ($code eq '3') {
233: $hwk='<font color="#229922">';
234: } elsif ($code eq '4') {
235: $hwk='<font color="#992222">';
236: }
1.6 www 237: }
1.7 www 238: $r->print($add.'<a href="'.$hash{'src_'.$rid}.
239: '">'.$hwk.
240: $hash{'title_'.$rid}.$hwke.'</a>'.$adde);
1.2 www 241: }
242: $r->print('</tr>');
243: }
244: }
245: $r->print("\n</table>");
246:
247: $r->print('</body></html>');
248: # -------------------------------------------------------------------- End page
249: }
250: # ------------------------------------------------------------- End render page
251: } else {
252: $r->content_type('text/html');
253: $r->send_http_header;
254: $r->print('<html><body>Coursemap undefined.</body></html>');
255: }
256: # ------------------------------------------------------------------ Untie hash
257: unless (untie(%hash)) {
258: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
259: "Could not untie coursemap $fn (browse).</font>");
260: }
261: # -------------------------------------------------------------------- All done
262: return OK;
263: # ----------------------------------------------- Errors, hash could no be tied
264: }
265: }
266: }
1.3 www 267:
1.2 www 268: $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
269: return HTTP_NOT_ACCEPTABLE;
270: }
1.1 www 271:
272: 1;
273: __END__
1.2 www 274:
275:
276:
277:
278:
279:
280:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>