--- rat/lonuserstate.pm 2005/11/15 18:27:52 1.98 +++ rat/lonuserstate.pm 2006/02/23 18:17:37 1.105 @@ -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.98 2005/11/15 18:27:52 albertel Exp $ +# $Id: lonuserstate.pm,v 1.105 2006/02/23 18:17:37 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -166,8 +166,7 @@ sub loadmap { } elsif ($turi=~/^\/*uploaded\//) { # uploaded if (($embstyle eq 'img') || ($embstyle eq 'emb') - || ($embstyle eq 'ign') - || ($embstyle eq 'unk')) { + || ($embstyle eq 'wrp')) { $turi='/adm/wrapper'.$turi; } elsif ($embstyle eq 'ssi') { #do nothing with these @@ -178,7 +177,9 @@ sub loadmap { my $mapdir=$uri; $mapdir=~s/[^\/]+$//; $turi=&Apache::lonnet::hreflocation($mapdir,$turi); - if (($embstyle eq 'img') || ($embstyle eq 'emb')) { + if (($embstyle eq 'img') + || ($embstyle eq 'emb') + || ($embstyle eq 'wrp')) { $turi='/adm/wrapper'.$turi; } } @@ -317,20 +318,22 @@ sub loadmap { sub simplify { my $expression=shift; +# (0&1) = 1 + $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; + 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; } @@ -365,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= @@ -380,7 +383,7 @@ sub traceroute { my $further=$sofar; if ($hash{'undercond_'.$_}) { if (defined($hash{'condid_'.$hash{'undercond_'.$_}})) { - $further=simplify('('.$further.')&('. + $further=simplify('('.'_'.$rid.')&('. $hash{'condid_'.$hash{'undercond_'.$_}}.')'); } else { $errtext.='Undefined condition ID: ' @@ -403,13 +406,12 @@ sub accinit { my %captured=(); my $condcounter=0; $acchash{'acc.cond.'.$short.'.0'}=0; - foreach (keys %hash) { - if ($_=~/^conditions/) { - my $expr=$hash{$_}; - foreach ($expr=~m/(\(\(\d+(?:\&\d+)+\)(?:\|\(\d+(?:\&\d+)+\))+\))/g) { - my $sub=$_; - my $orig=$_; - $sub=~/\(\((\d+\&(:?\d+\&)*)(?:\d+\&*)+\)(?:\|\(\1(?:\d+\&*)+\))+\)/; + foreach my $key (keys(%hash)) { + if ($key=~/^conditions/) { + my $expr=$hash{$key}; + foreach my $sub ($expr=~m/(\(\([_\.\d]+(?:\&[_\.\d]+)+\)(?:\|\([_\.\d]+(?:\&[_\.\d]+)+\))+\))/g) { + my $orig=$sub; + $sub=~/\(\(([_\.\d]+\&(:?[_\.\d]+\&)*)(?:[_\.\d]+\&*)+\)(?:\|\(\1(?:[_\.\d]+\&*)+\))+\)/; my $factor=$1; $sub=~s/$factor//g; $sub=~s/^\(/\($factor\(/; @@ -418,17 +420,17 @@ sub accinit { $orig=~s/(\W)/\\$1/g; $expr=~s/$orig/$sub/; } - $hash{$_}=$expr; + $hash{$key}=$expr; unless (defined($captured{$expr})) { $condcounter++; $captured{$expr}=$condcounter; $acchash{'acc.cond.'.$short.'.'.$condcounter}=$expr; } - } elsif ($_=~/^param_(\d+)\.(\d+)/) { + } elsif ($key=~/^param_(\d+)\.(\d+)/) { my $prefix=&Apache::lonnet::encode_symb($hash{'map_id_'.$1},$2, $hash{'src_'.$1.'.'.$2}); - foreach (split(/\&/,$hash{$_})) { - my ($typename,$value)=split(/\=/,$_); + foreach my $param (split(/\&/,$hash{$key})) { + my ($typename,$value)=split(/\=/,$param); my ($type,$name)=split(/\:/,$typename); $parmhash{$prefix.'.'.&Apache::lonnet::unescape($name)}= &Apache::lonnet::unescape($value); @@ -437,17 +439,12 @@ sub accinit { } } } - foreach (keys %hash) { - if ($_=~/^ids/) { - foreach (split(/\,/,$hash{$_})) { - my $resid=$_; + foreach my $key (keys(%hash)) { + if ($key=~/^ids/) { + foreach my $resid (split(/\,/,$hash{$key})) { my $uri=$hash{'src_'.$resid}; - $uri=~s/^\/adm\/wrapper//; - $uri=&Apache::lonnet::declutter($uri); - my @uriparts=split(/\//,$uri); - my $urifile=$uriparts[$#uriparts]; - $#uriparts--; - my $uripath=join('/',@uriparts); + my ($uripath,$urifile) = + &Apache::lonnet::split_uri_for_cond($uri); if ($uripath) { my $uricond='0'; if (defined($hash{'conditions_'.$resid})) { @@ -459,8 +456,8 @@ sub accinit { my $replace=$1; my $regexp=$replace; #$regexp=~s/\|/\\\|/g; - $acchash{'acc.res.'.$short.'.'.$uripath} - =~s/\Q$regexp\E/$replace\|$uricond/; + $acchash{'acc.res.'.$short.'.'.$uripath} =~ + s/\Q$regexp\E/$replace\|$uricond/; } else { $acchash{'acc.res.'.$short.'.'.$uripath}.= $urifile.':'.$uricond.'&';