--- rat/lonuserstate.pm 2004/10/26 15:10:42 1.79 +++ rat/lonuserstate.pm 2004/12/06 21:41:01 1.83 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Construct and maintain state and binary representation of course for user # -# $Id: lonuserstate.pm,v 1.79 2004/10/26 15:10:42 albertel Exp $ +# $Id: lonuserstate.pm,v 1.83 2004/12/06 21:41:01 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -150,10 +150,11 @@ sub loadmap { $hash{'version_'.$turi}=$1; } } + my $title=$token->[2]->{'title'}; + $title=~s/\&colon\;/\:/gs; &Apache::lonnet::do_cache(\%Apache::lonnet::titlecache, &Apache::lonnet::encode_symb($uri,$token->[2]->{'id'}, - $turi), - $token->[2]->{'title'},'title'); + $turi),$title,'title'); unless ($ispage) { $turi=~/\.(\w+)$/; my $embstyle=&Apache::loncommon::fileembstyle($1); @@ -332,13 +333,13 @@ sub simplify { sub traceroute { my ($sofar,$rid,$beenhere,$encflag,$hdnflag)=@_; - $sofar=simplify($sofar); + my $newsofar=$sofar=simplify($sofar); unless ($beenhere=~/\&$rid\&/) { $beenhere.=$rid.'&'; my ($mapid,$resid)=split(/\./,$rid); my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$hash{'src_'.$rid}); - my $encrypt=&Apache::lonnet::EXT('resource.0.hiddenresource',$symb); - if ($hdnflag || lc($encrypt) eq 'yes') { $hiddenurl{$rid}=1; } + my $hidden=&Apache::lonnet::EXT('resource.0.hiddenresource',$symb); + if ($hdnflag || lc($hidden) eq 'yes') { $hiddenurl{$rid}=1; } my $encrypt=&Apache::lonnet::EXT('resource.0.encrypturl',$symb); if ($encflag || lc($encrypt) eq 'yes') { $encurl{$rid}=1; } if (($retfurl eq '') && ($hash{'src_'.$rid}) @@ -352,15 +353,14 @@ sub traceroute { } else { $hash{'conditions_'.$rid}=$sofar; } + $newsofar=$hash{'conditions_'.$rid}; if (defined($hash{'is_map_'.$rid})) { if (defined($hash{'map_start_'.$hash{'src_'.$rid}})) { - &traceroute($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},'&', - $encflag || $encurl{$rid}, - $hdnflag || $hiddenurl{$rid}); - if (defined($hash{'map_finish_'.$hash{'src_'.$rid}})) { - $sofar= - $hash{'conditions_'.$hash{'map_finish_'.$hash{'src_'.$rid}}}; - } + $sofar=$newsofar= + &traceroute($sofar, + $hash{'map_start_'.$hash{'src_'.$rid}},'&', + $encflag || $encurl{$rid}, + $hdnflag || $hiddenurl{$rid}); } } if (defined($hash{'to_'.$rid})) { @@ -375,10 +375,12 @@ sub traceroute { .$hash{'undercond_'.$_}.'. '; } } - &traceroute($further,$hash{'goesto_'.$_},$beenhere,$encflag,$hdnflag); + $newsofar=&traceroute($further,$hash{'goesto_'.$_},$beenhere, + $encflag,$hdnflag); } } } + return $newsofar; } # ------------------------------ Cascading conditions, quick access, parameters @@ -579,7 +581,8 @@ sub readmap { } # ---------------------------------------------------------------- Encrypt URLs foreach (keys %encurl) { - $hash{'src_'.$_}=&Apache::lonenc::encrypted($hash{'src_'.$_}); +# $hash{'src_'.$_}=&Apache::lonenc::encrypted($hash{'src_'.$_}); + $hash{'encrypted_'.$_}=1; } # ----------------------------------------------- Close hashes to finally store # --------------------------------- Routine must pass this point, no early outs @@ -617,39 +620,37 @@ sub readmap { # ------------------------------------------------------- Evaluate state string sub evalstate { - my $fn=$ENV{'request.course.fn'}.'.state'; - my $state='2'; + my $state=''; if (-e $fn) { - my @conditions=(); - { - my $fh=Apache::File->new($fn); - @conditions=<$fh>; - } - my $safeeval = new Safe; - my $safehole = new Safe::Hole; - $safeeval->permit("entereval"); - $safeeval->permit(":base_math"); - $safeeval->deny(":base_io"); - $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT'); - foreach (@conditions) { - my $line=$_; - chomp($line); - my ($condition,$weight)=split(/\:/,$_); - if ($safeeval->reval($condition)) { - if ($weight eq 'force') { - $state.='3'; - } else { - $state.='2'; - } - } else { - if ($weight eq 'stop') { - $state.='0'; - } else { - $state.='1'; - } - } - } + my @conditions=(); + { + my $fh=Apache::File->new($fn); + @conditions=<$fh>; + } + my $safeeval = new Safe; + my $safehole = new Safe::Hole; + $safeeval->permit("entereval"); + $safeeval->permit(":base_math"); + $safeeval->deny(":base_io"); + $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT'); + foreach my $line (@conditions) { + chomp($line); + my ($condition,$weight)=split(/\:/,$line); + if ($safeeval->reval($condition)) { + if ($weight eq 'force') { + $state.='3'; + } else { + $state.='2'; + } + } else { + if ($weight eq 'stop') { + $state.='0'; + } else { + $state.='1'; + } + } + } } &Apache::lonnet::appenv('user.state.'.$ENV{'request.course.id'} => $state); return $state;