--- loncom/interface/lonnavmaps.pm 2002/03/26 15:16:24 1.34 +++ loncom/interface/lonnavmaps.pm 2002/09/09 17:20:14 1.50 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.34 2002/03/26 15:16:24 www Exp $ +# $Id: lonnavmaps.pm,v 1.50 2002/09/09 17:20:14 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -67,6 +67,10 @@ my %courseopt; my %useropt; my %parmhash; +# This parameter keeps track of whether obtaining the user's information +# failed, which the colorizer in astatus can use +my $networkFailedFlag = 0; + # ------------------------------------------------------------------ Euclid gcd sub euclid { @@ -191,12 +195,18 @@ sub astatus { my %opendate=(); my %answerdate=(); # need to always check part 0's open/due/answer status - foreach (sort(split(/\,/,&Apache::lonnet::metadata($hash{'src_'.$rid},'keys')))) { + foreach (sort(split(/\,/,&Apache::lonnet::metadata($hash{'src_'.$rid},'allpossiblekeys')))) { if ($_=~/^parameter\_(.*)\_opendate$/) { my $part=$1; $duedate{$part}=&parmval($part.'.duedate',$symb); $opendate{$part}=&parmval($part.'.opendate',$symb); $answerdate{$part}=&parmval($part.'.answerdate',$symb); + if (&parmval($part.'.opendate.type',$symb) eq 'date_interval') { + $opendate{$part}=$duedate{$part}-$opendate{$part}; + } + if (&parmval($part.'.answerdate.type',$symb) eq 'date_interval') { + $answerdate{$part}=$duedate{$part}+$answerdate{$part}; + } } } my $now=time; @@ -339,7 +349,7 @@ sub tracetable { my ($sofar,$rid,$beenhere,$showtypes,$indent,$linkid)=@_; my $newshowtypes=$showtypes; my $further=$sofar; - #$Apache::lonxml::debug=1; +# $Apache::lonxml::debug=1; &Apache::lonxml::debug("$rid ; $linkid ; $sofar ; $beenhere ; ".$hash{'src_'.$rid}); if ($beenhere=~/\&$rid\&/) { return $further; } $beenhere.=$rid.'&'; @@ -411,10 +421,10 @@ sub handler { if ($ENV{'request.course.fn'}) { $fn=$ENV{'request.course.fn'}; if (-e "$fn.db") { - if ((tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) && + if ((tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640)) && (tie(%parmhash,'GDBM_File', $ENV{'request.course.fn'}.'_parms.db', - &GDBM_READER,0640))) { + &GDBM_READER(),0640))) { $hashtied=1; } } @@ -434,8 +444,10 @@ sub handler { &Apache::loncommon::no_cache($r); $r->send_http_header; - my $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}}; - my $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}}; + my $firstres=$hash{'map_start_'. + &Apache::lonnet::clutter($ENV{'request.course.uri'})}; + my $lastres=$hash{'map_finish_'. + &Apache::lonnet::clutter($ENV{'request.course.uri'})}; if (!(($firstres) && ($lastres))) { $r->print('Coursemap undefined.'); } else { @@ -456,9 +468,9 @@ sub handler { my ($cdom,$cnum)=split(/\_/,$cid); my $userprefix=$uname.'_'.$udom.'_'; - + unless ($uhome eq 'no_host') { -# -------------------------------------------------------------- Get coursedata +# ------------------------------------------------- Get coursedata (if present) unless ((time-$courserdatas{$cid.'.last_cache'})<240) { my $reply=&Apache::lonnet::reply('dump:'.$cdom.':'.$cnum. ':resourcedata',$chome); @@ -466,6 +478,11 @@ sub handler { $courserdatas{$cid}=$reply; $courserdatas{$cid.'.last_cache'}=time; } + # check to see if network failed + elsif ( $reply=~/no.such.host/i || $reply=~/con.*lost/i ) + { + $networkFailedFlag = 1; + } } foreach (split(/\&/,$courserdatas{$cid})) { my ($name,$value)=split(/\=/,$_); @@ -489,13 +506,7 @@ sub handler { @rows=(); - &tracetable(0,$firstres,'&'.$lastres.'&','',0); - if ($hash{'src_'.$lastres}) { - my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$lastres}); - if (($brepriv eq '2') || ($brepriv eq 'F')) { - $rows[$#rows+1]=''.$lastres; - } - } + &tracetable(0,$firstres,'&','',0); # ------------------------------------------------------------------ Page parms @@ -567,16 +578,19 @@ sub handler { } } # ----------------------------------------------------------- Start Page Output - $r->print('Navigate LON-CAPA Maps'); - $r->print('print( + 'Navigate Course Map'); if (($currenturl=~/^\/res/) && ($currenturl!~/^\/res\/adm/)) { - $r->print(' onLoad="window.location.hash='."'curloc'".'"'); + $bodytagadd='onLoad="window.location.hash='."'curloc'".'"'; } - $r->print('>'. - ''. - '

Navigate Course Map

'. - "

$date

"); + $r->print(&Apache::loncommon::bodytag('Navigate Course Map','', + $bodytagadd)); + $r->print(''); + my $desc=$ENV{'course.'.$ENV{'request.course.id'}.'.description'}; + if (defined($desc)) { $r->print("

$desc

\n"); } + $r->print("

$date

\n"); $r->rflush(); $r->print(' New discussion since '. localtime($lastcheck). @@ -585,6 +599,15 @@ sub handler { ($currenturl!~/^\/res\/adm/)) { $r->print('Current Location

'); } + + # Handle a network error + + if ($networkFailedFlag) + { + $r->print('

LON-CAPA network failure.

'."\n"); + $r->print("

LON-CAPA's network is having difficulties, some problem" . + " information, such as due dates, will not be available."); + } # ----------------------------------------------------- The little content list for ($i=0;$i<=$#rows;$i++) { if ($rows[$i]) { @@ -608,10 +631,17 @@ sub handler { $r->print("\n"); my @colcont=split(/\&/,$rows[$i]); my $avespan=$lcm/($#colcont+1); + + # for each item I wish to print on this row... for ($j=0;$j<=$#colcont;$j++) { my $indent;my $indentstr; my $linkid; my $rid=$colcont[$j]; + $rid=~/(\d+)\.(\d+)$/; + my $src= + &Apache::lonnet::declutter($hash{'src_'.$1.'.'.$2}); + my $symb= + &Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.$src; my $add=''; my $adde=''; my $hwk=''; @@ -622,6 +652,12 @@ sub handler { $rid=$1; $add=''; $adde=''; + if (($ENV{'user.adv'}) && + ($parmhash{$symb.'.0.parameter_randompick'})) { + $adde=' (randomly select '. + $parmhash{$symb.'.0.parameter_randompick'}. + ')'; + } } if ($rid=~/^j(.+)/) { $rid=$1; } if ($rid=~/^p(\d)(\d)\"([\w\: \(\)\/\,]*)\"(.+)/) { @@ -630,19 +666,36 @@ sub handler { my $tcode=$2; my $ctext=$3; $rid=$4; - if ($tcode eq '1') { + + # will open later + if ($tcode eq '1') { $add=''; } + + # solved/correct if ($code eq '3') { $add=''; - } elsif ($code eq '4') { + } elsif ($code eq '4') { # partially correct $add=''; } else { - $add=''; - if ($tcode eq '2') { + # not attempted + + # we end up here on network failure, so pick a neutral + # color if the network failed instead of bright red. + if ( $networkFailedFlag ) + { + $add = ''; + } + else + { + $add=''; + } + + if ($tcode eq '2') { # open, not past due $add=''; } - if ($tcode eq '4') { + + if ($tcode eq '4') { # due in next 24 hours $add=''; $adde=''; } @@ -660,6 +713,10 @@ sub handler { $hwk=''; $hwke=' ('.$ctext.')'; } + if ($networkFailedFlag) + { + $hwke=' (status unavailable)'; + } } if ($rid && $hash{'src_'.$rid} eq $currenturl) { $add=$add.''. @@ -667,11 +724,6 @@ sub handler { $adde= ' <'.$adde; } - my $src= - &Apache::lonnet::declutter($hash{'src_'.$rid}); - $rid=~/^(\d+)\.(\d+)$/; - my $symb= - &Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.$src; if ($discussiontimes{$symb}>$lastcheck) { $adde= ''. @@ -704,10 +756,15 @@ sub handler { for(my $i=-1;$i<$indent;$i++) { $indentstr.=$is; } } if (!$linkid) { $linkid=$rid; } + if ($hash{'randomout_'.$rid}) { + $adde=' (hidden)'.$adde; + } $r->print($add.$indentstr); if ($rid) { $r->print(''. + (($hash{'src_'.$linkid}=~/\?/)?'&':'?'). + 'symb='.&Apache::lonnet::escape($symb) + .'">'. $hwk.$hash{'title_'.$rid}.$hwke.''); } $r->print($adde);