--- rat/lonuserstate.pm 2006/05/11 23:54:06 1.110 +++ rat/lonuserstate.pm 2006/07/07 22:01:25 1.118 @@ -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.110 2006/05/11 23:54:06 albertel Exp $ +# $Id: lonuserstate.pm,v 1.118 2006/07/07 22:01:25 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -33,6 +33,7 @@ package Apache::lonuserstate; use strict; use HTML::TokeParser; use Apache::lonnet; +use Apache::lonlocal; use Apache::loncommon(); use GDBM_File; use Apache::lonmsg; @@ -41,6 +42,8 @@ use Safe::Hole; use Opcode; use Apache::lonenc; use Fcntl qw(:flock); +use LONCAPA; + # ---------------------------------------------------- Globals for this package @@ -49,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 @@ -103,8 +107,10 @@ sub processversionfile { sub loadmap { my $uri=shift; - if ($hash{'map_pc_'.$uri}) { return; } - + if ($hash{'map_pc_'.$uri}) { + $errtext.=&mt('
Multiple use of sequence/page [_1]! The course will not function properly.',$uri); + return; + } $pc++; my $lpc=$pc; $hash{'map_pc_'.$uri}=$lpc; @@ -117,7 +123,7 @@ sub loadmap { unless (($fn=~/\.sequence$/) || ($fn=~/\.page$/)) { - $errtext.="Invalid map: $fn\n"; + $errtext.=&mt("
Invalid map: [_1]",$fn); return; } @@ -277,9 +283,9 @@ sub loadmap { } $name=~s/^.*_([^_]*)$/$1/; my $newparam= - &Apache::lonnet::escape($token->[2]->{'type'}).':'. - &Apache::lonnet::escape($part.'.'.$name).'='. - &Apache::lonnet::escape($token->[2]->{'value'}); + &escape($token->[2]->{'type'}).':'. + &escape($part.'.'.$name).'='. + &escape($token->[2]->{'value'}); if (defined($hash{'param_'.$referid})) { $hash{'param_'.$referid}.='&'.$newparam; } else { @@ -310,7 +316,7 @@ sub loadmap { } } else { - $errtext.='Map not loaded: The file ('.$fn.') does not exist. '; + $errtext.=&mt('
Map not loaded: The file [_1] does not exist.',$fn); } } @@ -357,10 +363,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( @@ -390,8 +395,7 @@ sub traceroute { $further=simplify('('.'_'.$rid.')&('. $hash{'condid_'.$hash{'undercond_'.$id}}.')'); } else { - $errtext.='Undefined condition ID: ' - .$hash{'undercond_'.$id}.'. '; + $errtext.=&mt('
Undefined condition ID: [_1]',$hash{'undercond_'.$id}); } } $newsofar=&traceroute($further,$hash{'goesto_'.$id},$beenhere, @@ -438,10 +442,10 @@ sub accinit { foreach my $param (split(/\&/,$hash{$key})) { my ($typename,$value)=split(/\=/,$param); my ($type,$name)=split(/\:/,$typename); - $parmhash{$prefix.'.'.&Apache::lonnet::unescape($name)}= - &Apache::lonnet::unescape($value); - $parmhash{$prefix.'.'.&Apache::lonnet::unescape($name).'.type'}= - &Apache::lonnet::unescape($type); + $parmhash{$prefix.'.'.&unescape($name)}= + &unescape($value); + $parmhash{$prefix.'.'.&unescape($name).'.type'}= + &unescape($type); } } } @@ -552,7 +556,7 @@ sub readmap { unless ($uri=$cenv{'url'}) { &Apache::lonnet::logthis("WARNING: ". "Could not load course $short."); - return 'No course data available.'; + return ('',&mt('No course data available.'));; } @cond=('true:normal'); @@ -568,7 +572,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=(); @@ -586,6 +590,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(); @@ -595,10 +600,8 @@ sub readmap { if ($key=~/^src_/) { $hash{$key}=&putinversion($hash{$key}); } elsif ($key =~ /^(map_(?:start|finish|pc)_)(.*)/) { - &Apache::lonnet::logthis($key); my ($type, $url) = ($1,$2); my $value = $hash{$key}; - delete($hash{$key}); $hash{$type.&putinversion($url)}=$value; } } @@ -609,6 +612,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: ". @@ -683,8 +694,9 @@ sub evalstate { if (-e $fn) { my @conditions=(); { - my $fh=Apache::File->new($fn); + open(my $fh,"<$fn"); @conditions=<$fh>; + close($fh); } my $safeeval = new Safe; my $safehole = new Safe::Hole;