--- rat/lonuserstate.pm 2003/12/15 15:49:23 1.70 +++ rat/lonuserstate.pm 2004/04/23 15:43:41 1.74 @@ -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.70 2003/12/15 15:49:23 www Exp $ +# $Id: lonuserstate.pm,v 1.74 2004/04/23 15:43:41 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 @@ -159,7 +162,9 @@ sub loadmap { } elsif ($turi=~/^\/*uploaded\//) { # uploaded if (($embstyle eq 'img') || ($embstyle eq 'emb') || ($embstyle eq 'ssi')) { - $turi='/adm/wrapper'.$turi; + unless ($turi =~/\.page$/) { + $turi='/adm/wrapper'.$turi; + } } elsif ($turi!~/\.(sequence|page)$/) { $turi='/adm/coursedocs/showdoc'.$turi; } @@ -172,11 +177,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 @@ -281,6 +288,16 @@ sub loadmap { if ($token->[2]->{'name'} eq 'parameter_randompickseed') { $randompick{$referid}=$token->[2]->{'value'}; } + if ($token->[2]->{'name'} eq 'parameter_encrypturl') { + if ($token->[2]->{'value'}=~/^yes$/i) { + $encurl{$referid}=1; + } + } + if ($token->[2]->{'name'} eq 'parameter_hiddenresource') { + if ($token->[2]->{'value'}=~/^yes$/i) { + $hiddenurl{$referid}=1; + } + } } } @@ -450,9 +467,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 +511,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 +548,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 +567,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 +575,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")) {