--- rat/lonuserstate.pm 2003/10/29 21:50:41 1.65 +++ rat/lonuserstate.pm 2004/04/26 19:16:45 1.77 @@ -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.65 2003/10/29 21:50:41 www Exp $ +# $Id: lonuserstate.pm,v 1.77 2004/04/26 19:16:45 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -41,6 +41,7 @@ use Apache::lonmsg; use Safe; use Safe::Hole; use Opcode; +use Apache::lonenc; # ---------------------------------------------------- Globals for this package @@ -52,6 +53,8 @@ my $errtext; # variable with all errors my $retfurl; # variable with the very first URL in the course my %randompick; # randomly picked resources my %randompickseed; # optional seed for randomly picking resources +my %encurl; # URLs in this folder are supposed to be encrypted +my %hiddenurl; # this URL (or complete folder) is supposed to be hidden # ----------------------------------- Remove version from URL and store in hash @@ -74,6 +77,9 @@ sub putinversion { if ($hash{'version_'.$uri}) { my $version=$hash{'version_'.$uri}; if ($version eq 'mostrecent') { return $uri; } + if ($version eq &Apache::lonnet::getversion( + &Apache::lonnet::filelocation('',$uri))) + { return $uri; } $uri=~s/\.(\w+)$/\.$version\.$1/; } return $uri; @@ -154,23 +160,27 @@ sub loadmap { if ($token->[2]->{'external'} eq 'true') { # external $turi=~s/^http\:\/\//\/adm\/wrapper\/ext\//; } elsif ($turi=~/^\/*uploaded\//) { # uploaded - if (($embstyle eq 'img') || ($embstyle eq 'emb') - || ($embstyle eq 'ssi')) { + if (($embstyle eq 'img') || ($embstyle eq 'emb')) { $turi='/adm/wrapper'.$turi; } elsif ($turi!~/\.(sequence|page)$/) { $turi='/adm/coursedocs/showdoc'.$turi; } - } else { # normal internal resource - if (($embstyle eq 'img') || ($embstyle eq 'emb')) { - $turi='/adm/wrapper'.$turi; - } + } elsif ($turi=~/\S/) { # normal non-empty internal resource + my $mapdir=$uri; + $mapdir=~s/[^\/]+$//; + $turi=&Apache::lonnet::hreflocation($mapdir,$turi); + if (($embstyle eq 'img') || ($embstyle eq 'emb')) { + $turi='/adm/wrapper'.$turi; + } } } - - if (defined($hash{'ids_'.$turi})) { - $hash{'ids_'.$turi}.=','.$rid; +# Store reverse lookup, remove query string + my $idsuri=$turi; + $idsuri=~s/\?.+$//; + if (defined($hash{'ids_'.$idsuri})) { + $hash{'ids_'.$idsuri}.=','.$rid; } else { - $hash{'ids_'.$turi}=''.$rid; + $hash{'ids_'.$idsuri}=''.$rid; } if @@ -266,15 +276,25 @@ sub loadmap { } else { $hash{'param_'.$referid}=''.$newparam; } - if ($token->[2]->{'name'} eq 'parameter_mapalias') { + if ($token->[2]->{'name'}=~/^parameter_(0_)*mapalias$/) { $hash{'mapalias_'.$token->[2]->{'value'}}=$referid; } - if ($token->[2]->{'name'} eq 'parameter_randompick') { + if ($token->[2]->{'name'}=~/^parameter_(0_)*randompick$/) { $randompick{$referid}=$token->[2]->{'value'}; } - if ($token->[2]->{'name'} eq 'parameter_randompickseed') { + if ($token->[2]->{'name'}=~/^parameter_(0_)*randompickseed$/) { $randompick{$referid}=$token->[2]->{'value'}; } + if ($token->[2]->{'name'}=~/^parameter_(0_)*encrypturl$/) { + if ($token->[2]->{'value'}=~/^yes$/i) { + $encurl{$referid}=1; + } + } + if ($token->[2]->{'name'}=~/^parameter_(0_)*hiddenresource$/) { + if ($token->[2]->{'value'}=~/^yes$/i) { + $hiddenurl{$referid}=1; + } + } } } @@ -309,10 +329,16 @@ sub simplify { # -------------------------------------------------------- Build condition hash sub traceroute { - my ($sofar,$rid,$beenhere)=@_; + my ($sofar,$rid,$beenhere,$encflag,$hdnflag)=@_; $sofar=simplify($sofar); unless ($beenhere=~/\&$rid\&/) { $beenhere.=$rid.'&'; + if ($hdnflag) { + $hiddenurl{$rid}=1; + } + if ($encflag) { + $encurl{$rid}=1; + } if (($retfurl eq '') && ($hash{'src_'.$rid}) && ($hash{'src_'.$rid}!~/\.sequence$/)) { my ($mapid,$resid)=split(/\./,$rid); @@ -331,7 +357,9 @@ sub traceroute { } if (defined($hash{'is_map_'.$rid})) { if (defined($hash{'map_start_'.$hash{'src_'.$rid}})) { - &traceroute($sofar,$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}}}; @@ -350,7 +378,7 @@ sub traceroute { .$hash{'undercond_'.$_}.'. '; } } - &traceroute($further,$hash{'goesto_'.$_},$beenhere); + &traceroute($further,$hash{'goesto_'.$_},$beenhere,$encflag,$hdnflag); } } } @@ -444,9 +472,9 @@ sub accinit { "request.course.uri" => $courseuri); } -# ------------------------------------- Selectively delete from randompick maps +# ---------------- Selectively delete from randompick maps and hidden url parms -sub pickrandom { +sub hiddenurls { my $randomoutentry=''; foreach my $rid (keys %randompick) { my $rndpick=$randompick{$rid}; @@ -488,6 +516,18 @@ sub pickrandom { } } } +# ------------------------------ take care of explicitly hidden urls or folders + foreach my $rid (keys %hiddenurl) { + $hash{'randomout_'.$rid}=1; + my ($mapid,$resid)=split(/\./,$rid); + $randomoutentry.='&'. + &Apache::lonnet::symbclean( + &Apache::lonnet::declutter($hash{'map_id_'.$mapid}). + '___'.$resid.'___'. + &Apache::lonnet::declutter($hash{'src_'.$rid}) + ).'&'; + } +# --------------------------------------- append randomout entry to environment if ($randomoutentry) { &Apache::lonnet::appenv('acc.randomout' => $randomoutentry); } @@ -513,6 +553,8 @@ sub readmap { unlink($fn.'.state'); unlink($fn.'parms.db'); undef %randompick; + undef %hiddenurl; + undef %encurl; $retfurl=''; if ((tie(%hash,'GDBM_File',"$fn.db",&GDBM_WRCREAT(),0640)) && (tie(%parmhash,'GDBM_File',$fn.'_parms.db',&GDBM_WRCREAT(),0640))) { @@ -530,7 +572,7 @@ sub readmap { if (defined($hash{'map_start_'.$uri})) { &traceroute('0',$hash{'map_start_'.$uri},'&'); &accinit($uri,$short,$fn); - &pickrandom(); + &hiddenurls(); } # ------------------------------------------------------- Put versions into src foreach (keys %hash) { @@ -538,10 +580,17 @@ sub readmap { $hash{$_}=&putinversion($hash{$_}); } } +# ---------------------------------------------------------------- Encrypt URLs + foreach (keys %encurl) { + $hash{'src_'.$_}=&Apache::lonenc::encrypted($hash{'src_'.$_}); + } +# ----------------------------------------------- Close hashes to finally store +# --------------------------------- Routine must pass this point, no early outs unless ((untie(%hash)) && (untie(%parmhash))) { &Apache::lonnet::logthis("WARNING: ". "Could not untie coursemap $fn for $uri."); } +# ---------------------------------------------------- Store away initial state { my $cfh; if ($cfh=Apache::File->new(">$fn.state")) {