--- rat/lonuserstate.pm 2004/04/05 18:25:08 1.72 +++ 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.72 2004/04/05 18:25:08 raeburn 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 @@ -157,11 +160,8 @@ 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')) { - unless ($turi =~/\.page$/) { - $turi='/adm/wrapper'.$turi; - } + if (($embstyle eq 'img') || ($embstyle eq 'emb')) { + $turi='/adm/wrapper'.$turi; } elsif ($turi!~/\.(sequence|page)$/) { $turi='/adm/coursedocs/showdoc'.$turi; } @@ -276,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; + } + } } } @@ -319,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); @@ -341,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}}}; @@ -360,7 +378,7 @@ sub traceroute { .$hash{'undercond_'.$_}.'. '; } } - &traceroute($further,$hash{'goesto_'.$_},$beenhere); + &traceroute($further,$hash{'goesto_'.$_},$beenhere,$encflag,$hdnflag); } } } @@ -454,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}; @@ -498,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); } @@ -523,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))) { @@ -540,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) { @@ -548,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")) {