--- rat/lonuserstate.pm 2005/01/19 20:18:44 1.78.2.1 +++ rat/lonuserstate.pm 2004/10/26 23:00:11 1.81 @@ -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.78.2.1 2005/01/19 20:18:44 albertel Exp $ +# $Id: lonuserstate.pm,v 1.81 2004/10/26 23:00:11 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -289,7 +289,7 @@ sub loadmap { } if ($token->[2]->{'name'}=~/^parameter_(0_)*encrypturl$/) { if ($token->[2]->{'value'}=~/^yes$/i) { - $hiddenurl{$referid}=1; + $encurl{$referid}=1; } } if ($token->[2]->{'name'}=~/^parameter_(0_)*hiddenresource$/) { @@ -332,24 +332,19 @@ sub simplify { sub traceroute { my ($sofar,$rid,$beenhere,$encflag,$hdnflag)=@_; - $sofar=simplify($sofar); + my $newsofar=$sofar=simplify($sofar); unless ($beenhere=~/\&$rid\&/) { $beenhere.=$rid.'&'; - if ($hdnflag) { - $hiddenurl{$rid}=1; - } - if ($encflag) { - $encurl{$rid}=1; - } + my ($mapid,$resid)=split(/\./,$rid); + my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$hash{'src_'.$rid}); + 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}) - && ($hash{'src_'.$rid}!~/\.sequence$/)) { - my ($mapid,$resid)=split(/\./,$rid); - $retfurl=$hash{'src_'.$rid}. - (($hash{'src_'.$rid}=~/\?/)?'&':'?').'symb='. - &Apache::lonnet::symbclean( - &Apache::lonnet::declutter($hash{'map_id_'.$mapid}). - '___'.$resid.'___'. - &Apache::lonnet::declutter($hash{'src_'.$rid})); + && ($hash{'src_'.$rid}!~/\.sequence$/)) { + $retfurl=$hash{'src_'.$rid}.(($hash{'src_'.$rid}=~/\?/)?'&':'?'). + 'symb='.$symb; } if (defined($hash{'conditions_'.$rid})) { $hash{'conditions_'.$rid}=simplify( @@ -357,15 +352,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})) { @@ -380,10 +374,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 @@ -468,10 +464,7 @@ sub accinit { my $courseuri=$uri; $courseuri=~s/^\/res\///; &Apache::lonnet::delenv('(acc\.|httpref\.)'); - &Apache::lonnet::appenv(%acchash, - "request.course.id" => $short, - "request.course.fn" => $fn, - "request.course.uri" => $courseuri); + &Apache::lonnet::appenv(%acchash); } # ---------------- Selectively delete from randompick maps and hidden url parms @@ -572,6 +565,9 @@ sub readmap { $hash{'is_map_0.0'}=1; loadmap($uri); if (defined($hash{'map_start_'.$uri})) { + &Apache::lonnet::appenv("request.course.id" => $short, + "request.course.fn" => $fn, + "request.course.uri" => $uri); &traceroute('0',$hash{'map_start_'.$uri},'&'); &accinit($uri,$short,$fn); &hiddenurls(); @@ -622,39 +618,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;