--- rat/lonuserstate.pm 2006/02/23 18:08:43 1.104 +++ rat/lonuserstate.pm 2006/02/28 20:56:40 1.106 @@ -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.104 2006/02/23 18:08:43 albertel Exp $ +# $Id: lonuserstate.pm,v 1.106 2006/02/28 20:56:40 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -93,9 +93,9 @@ sub processversionfile { my %versions=&Apache::lonnet::dump('resourceversions', $cenv{'domain'}, $cenv{'num'}); - foreach (keys %versions) { - if ($_=~/^error\:/) { return; } - $hash{'version_'.$_}=$versions{$_}; + foreach my $ver (keys(%versions)) { + if ($ver=~/^error\:/) { return; } + $hash{'version_'.$ver}=$versions{$ver}; } } @@ -319,21 +319,21 @@ sub loadmap { sub simplify { my $expression=shift; # (0&1) = 1 - $expression=~s/\(0\&(\d+)\)/$1/g; + $expression=~s/\(0\&([_\.\d]+)\)/$1/g; # (8)=8 - $expression=~s/\((\d+)\)/$1/g; + $expression=~s/\(([_\.\d]+)\)/$1/g; # 8&8=8 - $expression=~s/(\D)(\d+)\&\2(\D)/$1$2$3/g; + $expression=~s/([^_\.\d])([_\.\d]+)\&\2([^_\.\d])/$1$2$3/g; # 8|8=8 - $expression=~s/(\D)(\d+)\|\2(\D)/$1$2$3/g; + $expression=~s/([^_\.\d])([_\.\d]+)\|\2([^_\.\d])/$1$2$3/g; # (5&3)&4=5&3&4 - $expression=~s/\((\d+)((?:\&\d+)+)\)\&(\d+\D)/$1$2\&$3/g; + $expression=~s/\(([_\.\d]+)((?:\&[_\.\d]+)+)\)\&([_\.\d]+[^_\.\d])/$1$2\&$3/g; # (((5&3)|(4&6)))=((5&3)|(4&6)) -# $expression=~ -# s/\((\(\(\d+(?:\&\d+)*\)(?:\|\(\d+(?:\&\d+)*\))+\))\)/$1/g; + $expression=~ + s/\((\(\([_\.\d]+(?:\&[_\.\d]+)*\)(?:\|\([_\.\d]+(?:\&[_\.\d]+)*\))+\))\)/$1/g; # ((5&3)|(4&6))|(1&2)=(5&3)|(4&6)|(1&2) $expression=~ - s/\((\(\d+(?:\&\d+)*\))((?:\|\(\d+(?:\&\d+)*\))+)\)\|(\(\d+(?:\&\d+)*\))/\($1$2\|$3\)/g; + s/\((\([_\.\d]+(?:\&[_\.\d]+)*\))((?:\|\([_\.\d]+(?:\&[_\.\d]+)*\))+)\)\|(\([_\.\d]+(?:\&[_\.\d]+)*\))/\($1$2\|$3\)/g; return $expression; } @@ -368,7 +368,7 @@ sub traceroute { } else { $hash{'conditions_'.$rid}=$sofar; } - $newsofar=$hash{'conditions_'.$rid}; + $newsofar='_'.$rid; if (defined($hash{'is_map_'.$rid})) { if (defined($hash{'map_start_'.$hash{'src_'.$rid}})) { $sofar=$newsofar= @@ -379,18 +379,18 @@ sub traceroute { } } if (defined($hash{'to_'.$rid})) { - foreach (split(/\,/,$hash{'to_'.$rid})) { + foreach my $id (split(/\,/,$hash{'to_'.$rid})) { my $further=$sofar; - if ($hash{'undercond_'.$_}) { - if (defined($hash{'condid_'.$hash{'undercond_'.$_}})) { - $further=simplify('('.$further.')&('. - $hash{'condid_'.$hash{'undercond_'.$_}}.')'); + if ($hash{'undercond_'.$id}) { + if (defined($hash{'condid_'.$hash{'undercond_'.$id}})) { + $further=simplify('('.'_'.$rid.')&('. + $hash{'condid_'.$hash{'undercond_'.$id}}.')'); } else { $errtext.='Undefined condition ID: ' - .$hash{'undercond_'.$_}.'. '; + .$hash{'undercond_'.$id}.'. '; } } - $newsofar=&traceroute($further,$hash{'goesto_'.$_},$beenhere, + $newsofar=&traceroute($further,$hash{'goesto_'.$id},$beenhere, $encflag,$hdnflag); } } @@ -409,9 +409,9 @@ sub accinit { foreach my $key (keys(%hash)) { if ($key=~/^conditions/) { my $expr=$hash{$key}; - foreach my $sub ($expr=~m/(\(\(\d+(?:\&\d+)+\)(?:\|\(\d+(?:\&\d+)+\))+\))/g) { + foreach my $sub ($expr=~m/(\(\([_\.\d]+(?:\&[_\.\d]+)+\)(?:\|\([_\.\d]+(?:\&[_\.\d]+)+\))+\))/g) { my $orig=$sub; - $sub=~/\(\((\d+\&(:?\d+\&)*)(?:\d+\&*)+\)(?:\|\(\1(?:\d+\&*)+\))+\)/; + $sub=~/\(\(([_\.\d]+\&(:?[_\.\d]+\&)*)(?:[_\.\d]+\&*)+\)(?:\|\(\1(?:[_\.\d]+\&*)+\))+\)/; my $factor=$1; $sub=~s/$factor//g; $sub=~s/^\(/\($factor\(/; @@ -456,7 +456,7 @@ sub accinit { my $replace=$1; my $regexp=$replace; #$regexp=~s/\|/\\\|/g; - $acchash{'acc.res.'.$short.'.'.$uripath}=~ + $acchash{'acc.res.'.$short.'.'.$uripath} =~ s/\Q$regexp\E/$replace\|$uricond/; } else { $acchash{'acc.res.'.$short.'.'.$uripath}.= @@ -486,8 +486,8 @@ sub hiddenurls { my $mpc=$hash{'map_pc_'.$hash{'src_'.$rid}}; # ------------------------------------------- put existing resources into array my @currentrids=(); - foreach (sort(keys(%hash))) { - if ($_=~/^src_($mpc\.\d+)/) { + foreach my $key (sort(keys(%hash))) { + if ($key=~/^src_($mpc\.\d+)/) { if ($hash{'src_'.$1}) { push @currentrids, $1; } } } @@ -585,15 +585,15 @@ sub readmap { &hiddenurls(); } # ------------------------------------------------------- Put versions into src - foreach (keys %hash) { - if ($_=~/^src\_/) { - $hash{$_}=&putinversion($hash{$_}); + foreach my $key (keys(%hash)) { + if ($key=~/^src\_/) { + $hash{$key}=&putinversion($hash{$key}); } } # ---------------------------------------------------------------- Encrypt URLs - foreach (keys %encurl) { -# $hash{'src_'.$_}=&Apache::lonenc::encrypted($hash{'src_'.$_}); - $hash{'encrypted_'.$_}=1; + foreach my $id (keys(%encurl)) { +# $hash{'src_'.$id}=&Apache::lonenc::encrypted($hash{'src_'.$id}); + $hash{'encrypted_'.$id}=1; } # ----------------------------------------------- Close hashes to finally store # --------------------------------- Routine must pass this point, no early outs