--- rat/lonuserstate.pm 2003/12/15 15:26:26 1.69 +++ rat/lonuserstate.pm 2004/04/23 23:01:35 1.76 @@ -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.69 2003/12/15 15:26:26 www Exp $ +# $Id: lonuserstate.pm,v 1.76 2004/04/23 23:01:35 albertel 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,13 +160,12 @@ 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; } - } elsif ($turi) { # normal non-empty internal resource + } elsif ($turi=~/\S/) { # normal non-empty internal resource my $mapdir=$uri; $mapdir=~s/[^\/]+$//; $turi=&Apache::lonnet::hreflocation($mapdir,$turi); @@ -172,11 +174,13 @@ sub loadmap { } } } - - 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 @@ -272,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; + } + } } } @@ -450,9 +464,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}; @@ -494,6 +508,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); } @@ -519,6 +545,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))) { @@ -536,7 +564,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) { @@ -544,10 +572,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")) {