Annotation of loncom/interface/lonnavmaps.pm, revision 1.2
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: # ------------------------------------------------------------ Add to symb list
! 150:
! 151: my $i;
! 152: my %symbhash=();
! 153: for ($i=0;$i<=$#rows;$i++) {
! 154: if ($rows[$i]) {
! 155: my @colcont=split(/\&/,$rows[$i]);
! 156: map {
! 157: $symbhash{$hash{'src_'.$_}}='';
! 158: } @colcont;
! 159: }
! 160: }
! 161: &Apache::lonnet::symblist($requrl,%symbhash);
! 162:
! 163: # ------------------------------------------------------------------ Page parms
! 164:
! 165: my $j;
! 166: my $lcm=1;
! 167: my $contents=0;
! 168:
! 169: # ---------------------------------------------- Go through table to get layout
! 170:
! 171: for ($i=0;$i<=$#rows;$i++) {
! 172: if ($rows[$i]) {
! 173: $contents++;
! 174: my @colcont=split(/\&/,$rows[$i]);
! 175: $lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
! 176: }
! 177: }
! 178:
! 179: unless ($contents) {
! 180: $r->content_type('text/html');
! 181: $r->send_http_header;
! 182: $r->print('<html><body>Empty Map.</body></html>');
! 183: } else {
! 184: # ------------------------------------------------------------------ Build page
! 185:
! 186: # ---------------------------------------------------------------- Send headers
! 187:
! 188: $r->content_type('text/html');
! 189: $r->send_http_header;
! 190: $r->print(
! 191: '<html><head><title>Navigate LON-CAPA Maps</title></head>');
! 192:
! 193: $r->print('<body bgcolor="#FFFFFF">'.
! 194: '<h1>Navigate Course Map</h1>');
! 195:
! 196: # ----------------------------------------------------------------- Start table
! 197: $r->print('<table cols="'.$lcm.'" border="0">');
! 198: for ($i=0;$i<=$#rows;$i++) {
! 199: if ($rows[$i]) {
! 200: $r->print("\n<tr>");
! 201: my @colcont=split(/\&/,$rows[$i]);
! 202: my $avespan=$lcm/($#colcont+1);
! 203: for ($j=0;$j<=$#colcont;$j++) {
! 204: my $rid=$colcont[$j];
! 205: $r->print('<td><a href="'.
! 206: $hash{'src_'.$rid}.'">'.
! 207: $hash{'title_'.$rid}.'</a>');
! 208: $r->print('</td>');
! 209: }
! 210: $r->print('</tr>');
! 211: }
! 212: }
! 213: $r->print("\n</table>");
! 214:
! 215: $r->print('</body></html>');
! 216: # -------------------------------------------------------------------- End page
! 217: }
! 218: # ------------------------------------------------------------- End render page
! 219: } else {
! 220: $r->content_type('text/html');
! 221: $r->send_http_header;
! 222: $r->print('<html><body>Coursemap undefined.</body></html>');
! 223: }
! 224: # ------------------------------------------------------------------ Untie hash
! 225: unless (untie(%hash)) {
! 226: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
! 227: "Could not untie coursemap $fn (browse).</font>");
! 228: }
! 229: # -------------------------------------------------------------------- All done
! 230: return OK;
! 231: # ----------------------------------------------- Errors, hash could no be tied
! 232: }
! 233: }
! 234: }
! 235: $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
! 236: return HTTP_NOT_ACCEPTABLE;
! 237: }
1.1 www 238:
239: 1;
240: __END__
1.2 ! www 241:
! 242:
! 243:
! 244:
! 245:
! 246:
! 247:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>