--- rat/lonuserstate.pm 2000/10/31 19:31:42 1.14 +++ rat/lonuserstate.pm 2000/11/01 22:21:36 1.15 @@ -11,7 +11,7 @@ # 7/1,7/3,7/4,7/7,7/8,7/10 Gerd Kortemeyer) # # 7/15,7/17,7/18,8/1,8/2,8/4,8/5,8/21,8/22,8/23,8/30, -# 9/2,9/4,9/29,9/30,10/2,10/11,10/30,10/31 Gerd Kortemeyer +# 9/2,9/4,9/29,9/30,10/2,10/11,10/30,10/31,11/1 Gerd Kortemeyer package Apache::lonuserstate; @@ -22,6 +22,9 @@ use HTML::TokeParser; use Apache::lonnet(); use GDBM_File; use Apache::lonmsg; +use Safe; +use Opcode; + # ---------------------------------------------------- Globals for this package @@ -352,9 +355,50 @@ sub readmap { "Could not tie coursemap $fn for $uri."); } &Apache::lonmsg::author_res_msg($ENV{'request.course.uri'},$errtext); + &evalstate(); return $errtext; } - + +# ------------------------------------------------------- Evaluate state string + +sub evalstate { + my $safeeval = new Safe; + my $fn=$ENV{'request.course.fn'}.'.state'; + my $state='2'; + if (-e $fn) { + my @conditions=(); + { + my $fh=Apache::File->new($fn); + @conditions=<$fh>; + } + $safeeval->permit("entereval"); + $safeeval->permit(":base_math"); + $safeeval->deny(":base_io"); + $safeeval->share_from('Apache::lonnet',['&varval']); + map { + my $line=$_; + chomp($line); + my ($condition,$weight)=split(/\:/,$_); + $condition=~s/\&([\w\.]+)/\&varval\(\'$1\'\)/g; + if ($safeeval->reval($condition)) { + if ($weight eq 'force') { + $state.='3'; + } else { + $state.='2'; + } + } else { + if ($weight eq 'stop') { + $state.='0'; + } else { + $state.='1'; + } + } + } @conditions; + } + &Apache::lonnet::appenv('user.state.'.$ENV{'request.course.id'} => $state); + return $state; +} + 1; __END__