1: # The LearningOnline Network with CAPA
2: # Navigate Maps Handler
3: #
4: # (Page Handler
5: #
6: # (TeX Content Handler
7: #
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)
11: #
12: # 3/1/1,6/1,17/1,29/1 Gerd Kortemeyer
13:
14: package Apache::lonnavmaps;
15:
16: use strict;
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: # ------------------------------------------------------------- Find out status
40:
41: sub astatus {
42: my $rid=shift;
43: my $code=1;
44: my $ctext='';
45: $rid=~/(\d+)\.(\d+)/;
46: my $symb=&Apache::lonnet::escape(
47: &Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.
48: &Apache::lonnet::declutter($hash{'src_'.$rid}));
49: my $answer=&Apache::lonnet::reply(
50: "restore:$ENV{'user.domain'}:$ENV{'user.name'}:".
51: $ENV{'request.course.id'}.":$symb",
52: "$ENV{'user.home'}");
53: my %returnhash=();
54: map {
55: my ($name,$value)=split(/\=/,$_);
56: $returnhash{&Apache::lonnet::unescape($name)}=
57: &Apache::lonnet::unescape($value);
58: } split(/\&/,$answer);
59: if ($returnhash{'version'}) {
60: my $version;
61: for ($version=1;$version<=$returnhash{'version'};$version++) {
62: map {
63: $returnhash{$_}=$returnhash{$version.':'.$_};
64: } split(/\:/,$returnhash{$version.':keys'});
65: }
66: map {
67: if (($_=~/\.(\w+)\.solved$/) && ($_!~/^\d+\:/)) {
68: my $part=$1;
69: if ($returnhash{$_} eq 'correct_by_student') {
70: unless ($code==2) { $code=3; }
71: $ctext.='Part '.$part.': solved';
72: } elsif ($returnhash{$_} eq 'correct_by_override') {
73: unless ($code==2) { $code=3; }
74: $ctext.='Part '.$part.': override';
75: } elsif ($returnhash{$_} eq 'incorrect_attempted') {
76: $code=2;
77: $ctext.='Part '.$part.': '.
78: $returnhash{'resource.'.$part.'.tries'}.' attempt(s)';
79: } elsif ($returnhash{$_} eq 'incorrect_by_override') {
80: $code=2;
81: $ctext.='Part '.$part.': override';
82: } elsif ($returnhash{$_} eq 'excused') {
83: unless ($code==2) { $code=3; }
84: $ctext.='Part '.$part.': excused';
85: }
86: }
87: } keys %returnhash;
88: }
89: return 'p'.$code.'"'.$ctext.'"';
90: }
91:
92: # ------------------------------------------------------------ Build page table
93:
94: sub tracetable {
95: my ($sofar,$rid,$beenhere)=@_;
96: my $further=$sofar;
97: unless ($beenhere=~/\&$rid\&/) {
98: $beenhere.=$rid.'&';
99:
100: if (defined($hash{'is_map_'.$rid})) {
101: $sofar++;
102: my $tprefix='';
103: if ($hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}}
104: eq 'sequence') {
105: $tprefix='h';
106: }
107: if (defined($rows[$sofar])) {
108: $rows[$sofar].='&'.$tprefix.$rid;
109: } else {
110: $rows[$sofar]=$tprefix.$rid;
111: }
112: if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
113: (defined($hash{'map_finish_'.$hash{'src_'.$rid}})) &&
114: ($tprefix eq 'h')) {
115: my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
116: $sofar=
117: &tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},
118: '&'.$frid.'&');
119: $sofar++;
120: if ($hash{'src_'.$frid}) {
121: my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$frid});
122: if (($brepriv eq '2') || ($brepriv eq 'F')) {
123: my $pprefix='';
124: if ($hash{'src_'.$frid}=~
125: /\.(problem|exam|quiz|assess|survey|form)$/) {
126: $pprefix=&astatus($frid);
127:
128: }
129: if (defined($rows[$sofar])) {
130: $rows[$sofar].='&'.$pprefix.$frid;
131: } else {
132: $rows[$sofar]=$pprefix.$frid;
133: }
134: }
135: }
136: }
137: } else {
138: $sofar++;
139: if ($hash{'src_'.$rid}) {
140: my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$rid});
141: if (($brepriv eq '2') || ($brepriv eq 'F')) {
142: my $pprefix='';
143: if ($hash{'src_'.$rid}=~
144: /\.(problem|exam|quiz|assess|survey|form)$/) {
145: $pprefix=&astatus($rid);
146: }
147: if (defined($rows[$sofar])) {
148: $rows[$sofar].='&'.$pprefix.$rid;
149: } else {
150: $rows[$sofar]=$pprefix.$rid;
151: }
152: }
153: }
154: }
155:
156: if (defined($hash{'to_'.$rid})) {
157: my $mincond=1;
158: my $next='';
159: map {
160: my $thiscond=
161: &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
162: if ($thiscond>=$mincond) {
163: if ($next) {
164: $next.=','.$_.':'.$thiscond;
165: } else {
166: $next=$_.':'.$thiscond;
167: }
168: if ($thiscond>$mincond) { $mincond=$thiscond; }
169: }
170: } split(/\,/,$hash{'to_'.$rid});
171: map {
172: my ($linkid,$condval)=split(/\:/,$_);
173: if ($condval>=$mincond) {
174: my $now=&tracetable($sofar,$hash{'goesto_'.$linkid},$beenhere);
175: if ($now>$further) { $further=$now; }
176: }
177: } split(/\,/,$next);
178:
179: }
180: }
181: return $further;
182: }
183:
184: # ================================================================ Main Handler
185:
186: sub handler {
187: my $r=shift;
188:
189:
190: # ------------------------------------------- Set document type for header only
191:
192: if ($r->header_only) {
193: if ($ENV{'browser.mathml'}) {
194: $r->content_type('text/xml');
195: } else {
196: $r->content_type('text/html');
197: }
198: $r->send_http_header;
199: return OK;
200: }
201:
202: my $requrl=$r->uri;
203: # ----------------------------------------------------------------- Tie db file
204: if ($ENV{'request.course.fn'}) {
205: my $fn=$ENV{'request.course.fn'};
206: if (-e "$fn.db") {
207: if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) {
208: # ------------------------------------------------------------------- Hash tied
209: my $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}};
210: my $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}};
211: if (($firstres) && ($lastres)) {
212: # ----------------------------------------------------------------- Render page
213:
214: @rows=();
215:
216: &tracetable(0,$firstres,'&'.$lastres.'&');
217: if ($hash{'src_'.$lastres}) {
218: my $brepriv=
219: &Apache::lonnet::allowed('bre',$hash{'src_'.$lastres});
220: if (($brepriv eq '2') || ($brepriv eq 'F')) {
221: $rows[$#rows+1]=''.$lastres;
222: }
223: }
224:
225: # ------------------------------------------------------------------ Page parms
226:
227: my $j;
228: my $i;
229: my $lcm=1;
230: my $contents=0;
231:
232: # ---------------------------------------------- Go through table to get layout
233:
234: for ($i=0;$i<=$#rows;$i++) {
235: if ($rows[$i]) {
236: $contents++;
237: my @colcont=split(/\&/,$rows[$i]);
238: $lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
239: }
240: }
241:
242:
243: unless ($contents) {
244: $r->content_type('text/html');
245: $r->send_http_header;
246: $r->print('<html><body>Empty Map.</body></html>');
247: } else {
248: # ------------------------------------------------------------------ Build page
249:
250: # ---------------------------------------------------------------- Send headers
251:
252: $r->content_type('text/html');
253: $r->send_http_header;
254: $r->print(
255: '<html><head><title>Navigate LON-CAPA Maps</title></head>');
256:
257: $r->print('<body bgcolor="#FFFFFF">'.
258: '<script>window.focus();</script>'.
259: '<img align=right src=/adm/lonIcons/lonlogos.gif>'.
260: '<h1>Navigate Course Map</h1>');
261: $r->rflush();
262: # ----------------------------------------------------------------- Start table
263: $r->print('<table cols="'.$lcm.'" border="0">');
264: for ($i=0;$i<=$#rows;$i++) {
265: if ($rows[$i]) {
266: $r->print("\n<tr>");
267: my @colcont=split(/\&/,$rows[$i]);
268: my $avespan=$lcm/($#colcont+1);
269: for ($j=0;$j<=$#colcont;$j++) {
270: my $rid=$colcont[$j];
271: my $add='<td> ';
272: my $adde='</td>';
273: my $hwk='<font color="#223322">';
274: my $hwke='</font>';
275: if ($rid=~/^h(.+)/) {
276: $rid=$1;
277: $add='<th bgcolor="#AAFF55">';
278: $adde='</th>';
279: }
280: if ($rid=~/^p(\d)\"([\w\: \(\)]*)\"(.+)/) {
281: my $code=$1;
282: my $ctext=$2;
283: $rid=$3;
284: $hwk='<font color="#888811"><b>';
285: $hwke='</b></font>';
286: if ($code eq '2') {
287: $hwk='<font color="#992222"><b>';
288: $hwke='</b> ('.$ctext.')</font>';
289: }
290: if ($code eq '3') {
291: $hwk='<font color="#229922"><b>';
292: $hwke='</b> ('.$ctext.')</font>';
293: }
294: }
295: $r->print($add.'<a href="'.$hash{'src_'.$rid}.
296: '">'.$hwk.
297: $hash{'title_'.$rid}.$hwke.'</a>'.$adde);
298: }
299: $r->print('</tr>');
300: }
301: }
302: $r->print("\n</table>");
303:
304: $r->print('</body></html>');
305: # -------------------------------------------------------------------- End page
306: }
307: # ------------------------------------------------------------- End render page
308: } else {
309: $r->content_type('text/html');
310: $r->send_http_header;
311: $r->print('<html><body>Coursemap undefined.</body></html>');
312: }
313: # ------------------------------------------------------------------ Untie hash
314: unless (untie(%hash)) {
315: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
316: "Could not untie coursemap $fn (browse).</font>");
317: }
318: # -------------------------------------------------------------------- All done
319: return OK;
320: # ----------------------------------------------- Errors, hash could no be tied
321: }
322: }
323: }
324:
325: $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
326: return HTTP_NOT_ACCEPTABLE;
327: }
328:
329: 1;
330: __END__
331:
332:
333:
334:
335:
336:
337:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>