--- rat/lonuserstate.pm 2006/05/30 17:15:10 1.114 +++ rat/lonuserstate.pm 2007/10/29 18:51:00 1.119.2.1 @@ -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.114 2006/05/30 17:15:10 www Exp $ +# $Id: lonuserstate.pm,v 1.119.2.1 2007/10/29 18:51:00 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -42,7 +42,6 @@ use Safe::Hole; use Opcode; use Apache::lonenc; use Fcntl qw(:flock); -use lib '/home/httpd/lib/perl/'; use LONCAPA; @@ -53,7 +52,8 @@ my %hash; # The big tied hash my %parmhash;# The hash with the parameters my @cond; # Array with all of the conditions my $errtext; # variable with all errors -my $retfurl; # variable with the very first URL in the course +my $retfrid; # variable with the very first RID in the course +my $retfurl; # first URL my %randompick; # randomly picked resources my %randompickseed; # optional seed for randomly picking resources my %encurl; # URLs in this folder are supposed to be encrypted @@ -234,7 +234,9 @@ sub loadmap { my $rid=$lpc.'.'.$token->[2]->{'id'}; $hash{'kind_'.$rid}='cond'; - $cond[$#cond+1]=$token->[2]->{'value'}; + my $condition = $token->[2]->{'value'}; + $condition =~ s/[\n\r]+/ /gs; + push(@cond, $condition); $hash{'condid_'.$rid}=$#cond; if ($token->[2]->{'type'}) { $cond[$#cond].=':'.$token->[2]->{'type'}; @@ -298,7 +300,7 @@ sub loadmap { $randompick{$referid}=$token->[2]->{'value'}; } if ($token->[2]->{'name'}=~/^parameter_(0_)*randompickseed$/) { - $randompick{$referid}=$token->[2]->{'value'}; + $randompickseed{$referid}=$token->[2]->{'value'}; } if ($token->[2]->{'name'}=~/^parameter_(0_)*encrypturl$/) { if ($token->[2]->{'value'}=~/^yes$/i) { @@ -363,10 +365,9 @@ sub traceroute { my $encrypt=&Apache::lonnet::EXT('resource.0.encrypturl',$symb); if ($encflag || lc($encrypt) eq 'yes') { $encurl{$rid}=1; } - if (($retfurl eq '') && ($hash{'src_'.$rid}) + if (($retfrid eq '') && ($hash{'src_'.$rid}) && ($hash{'src_'.$rid}!~/\.sequence$/)) { - $retfurl=$hash{'src_'.$rid}.(($hash{'src_'.$rid}=~/\?/)?'&':'?'). - 'symb='.$symb; + $retfrid=$rid; } if (defined($hash{'conditions_'.$rid})) { $hash{'conditions_'.$rid}=simplify( @@ -573,7 +574,7 @@ sub readmap { undef %randompick; undef %hiddenurl; undef %encurl; - $retfurl=''; + $retfrid=''; if ($lock && (tie(%hash,'GDBM_File',"$fn.db",&GDBM_WRCREAT(),0640)) && (tie(%parmhash,'GDBM_File',$fn.'_parms.db',&GDBM_WRCREAT(),0640))) { %hash=(); @@ -591,6 +592,7 @@ sub readmap { &Apache::lonnet::appenv("request.course.id" => $short, "request.course.fn" => $fn, "request.course.uri" => $uri); + $env{'request.course.id'}=$short; &traceroute('0',$hash{'map_start_'.$uri},'&'); &accinit($uri,$short,$fn); &hiddenurls(); @@ -612,6 +614,14 @@ sub readmap { } # ----------------------------------------------- Close hashes to finally store # --------------------------------- Routine must pass this point, no early outs + $hash{'first_rid'}=$retfrid; + my ($mapid,$resid)=split(/\./,$retfrid); + $hash{'first_mapurl'}=$hash{'map_id_'.$mapid}; + my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$hash{'src_'.$retfrid}); + $retfurl=&add_get_param($hash{'src_'.$retfrid},{ 'symb' => $symb }); + if ($hash{'encrypted_'.$retfrid}) { + $retfurl=&Apache::lonenc::encrypted($retfurl,(&Apache::lonnet::allowed('adv') ne 'F')); + } $hash{'first_url'}=$retfurl; unless ((untie(%hash)) && (untie(%parmhash))) { &Apache::lonnet::logthis("WARNING: ". @@ -686,8 +696,9 @@ sub evalstate { if (-e $fn) { my @conditions=(); { - open(my $fh,$fn); + open(my $fh,"<$fn"); @conditions=<$fh>; + close($fh); } my $safeeval = new Safe; my $safehole = new Safe::Hole;