--- rat/lonuserstate.pm 2006/03/03 22:32:49 1.107
+++ rat/lonuserstate.pm 2006/05/30 17:15:10 1.114
@@ -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.107 2006/03/03 22:32:49 albertel Exp $
+# $Id: lonuserstate.pm,v 1.114 2006/05/30 17:15:10 www 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,9 @@ use Safe::Hole;
use Opcode;
use Apache::lonenc;
use Fcntl qw(:flock);
+use lib '/home/httpd/lib/perl/';
+use LONCAPA;
+
# ---------------------------------------------------- Globals for this package
@@ -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);
}
}
@@ -390,8 +396,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,
@@ -413,16 +418,18 @@ sub accinit {
foreach my $key (keys(%hash)) {
if ($key=~/^conditions/) {
my $expr=$hash{$key};
+ # try to find and factor out common sub-expressions
foreach my $sub ($expr=~m/(\(\([_\.\d]+(?:\&[_\.\d]+)+\)(?:\|\([_\.\d]+(?:\&[_\.\d]+)+\))+\))/g) {
my $orig=$sub;
- $sub=~/\(\(([_\.\d]+\&(:?[_\.\d]+\&)*)(?:[_\.\d]+\&*)+\)(?:\|\(\1(?:[_\.\d]+\&*)+\))+\)/;
- my $factor=$1;
- $sub=~s/$factor//g;
+
+ my ($factor) = ($sub=~/\(\(([_\.\d]+\&(:?[_\.\d]+\&)*)(?:[_\.\d]+\&*)+\)(?:\|\(\1(?:[_\.\d]+\&*)+\))+\)/);
+ next if (!defined($factor));
+
+ $sub=~s/\Q$factor\E//g;
$sub=~s/^\(/\($factor\(/;
$sub.=')';
$sub=simplify($sub);
- $orig=~s/(\W)/\\$1/g;
- $expr=~s/$orig/$sub/;
+ $expr=~s/\Q$orig\E/$sub/;
}
$hash{$key}=$expr;
unless (defined($captured{$expr})) {
@@ -436,10 +443,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);
}
}
}
@@ -543,14 +550,14 @@ sub hiddenurls {
sub readmap {
my $short=shift;
$short=~s/^\///;
- my %cenv=&Apache::lonnet::coursedescription($short);
+ my %cenv=&Apache::lonnet::coursedescription($short,{'freshen_cache'=>1});
my $fn=$cenv{'fn'};
my $uri;
$short=~s/\//\_/g;
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');
@@ -590,8 +597,12 @@ sub readmap {
}
# ------------------------------------------------------- Put versions into src
foreach my $key (keys(%hash)) {
- if ($key=~/^src\_/) {
+ if ($key=~/^src_/) {
$hash{$key}=&putinversion($hash{$key});
+ } elsif ($key =~ /^(map_(?:start|finish|pc)_)(.*)/) {
+ my ($type, $url) = ($1,$2);
+ my $value = $hash{$key};
+ $hash{$type.&putinversion($url)}=$value;
}
}
# ---------------------------------------------------------------- Encrypt URLs
@@ -675,7 +686,7 @@ sub evalstate {
if (-e $fn) {
my @conditions=();
{
- my $fh=Apache::File->new($fn);
+ open(my $fh,$fn);
@conditions=<$fh>;
}
my $safeeval = new Safe;