--- rat/lonuserstate.pm 2007/06/08 19:33:06 1.118.2.1
+++ rat/lonuserstate.pm 2007/06/28 23:26:38 1.118.2.2
@@ -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.118.2.1 2007/06/08 19:33:06 albertel Exp $
+# $Id: lonuserstate.pm,v 1.118.2.2 2007/06/28 23:26:38 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -56,6 +56,7 @@ my $retfrid; # variable with the very fi
my $retfurl; # first URL
my %randompick; # randomly picked resources
my %randompickseed; # optional seed for randomly picking resources
+my %randomorder; # maps to order contents randomly
my %encurl; # URLs in this folder are supposed to be encrypted
my %hiddenurl; # this URL (or complete folder) is supposed to be hidden
@@ -106,7 +107,7 @@ sub processversionfile {
# --------------------------------------------------------- Loads map from disk
sub loadmap {
- my $uri=shift;
+ my ($uri,$parent_rid)=@_;
if ($hash{'map_pc_'.$uri}) {
$errtext.=&mt('
Multiple use of sequence/page [_1]! The course will not function properly.',$uri);
return;
@@ -138,6 +139,16 @@ sub loadmap {
my $parser = HTML::TokeParser->new(\$instr);
$parser->attr_encoded(1);
+ # first get all parameters
+ while (my $token = $parser->get_token) {
+ next if ($token->[0] ne 'S');
+ if ($token->[1] eq 'param') {
+ &parse_param($token,$lpc);
+ }
+ }
+ #reset parser
+ $parser = HTML::TokeParser->new(\$instr);
+ $parser->attr_encoded(1);
my $linkpc=0;
@@ -145,7 +156,8 @@ sub loadmap {
$hash{'map_type_'.$lpc}=$1;
- my $randomize=1;
+ my $randomize = ($randomorder{$parent_rid} =~ /^yes$/i);
+
my @map_ids;
while (my $token = $parser->get_token) {
next if ($token->[0] ne 'S');
@@ -158,12 +170,16 @@ sub loadmap {
$token->[2]->{'condition'});
} elsif ($token->[1] eq 'condition' && !$randomize) {
&parse_condition($token,$lpc);
- } elsif ($token->[1] eq 'param') {
- &parse_param($token,$lpc);
- }
+ }
}
if ($randomize) {
+ my $seed = (split(/\./,$parent_rid))[1];
+ if ($randompickseed{$parent_rid}) {
+ $seed = $randompickseed{$parent_rid};
+ }
+ my $rndseed=&Apache::lonnet::rndseed($seed);
+ &Apache::lonnet::setup_random_from_rndseed($rndseed);
my @map_ids=&Math::Random::random_permutation(@map_ids);
my $from = shift(@map_ids);
my $from_rid = $lpc.'.'.$from;
@@ -265,7 +281,7 @@ sub parse_resource {
if (($turi=~/\.sequence$/) ||
($turi=~/\.page$/)) {
$hash{'is_map_'.$rid}=1;
- &loadmap($turi);
+ &loadmap($turi,$rid);
}
return $token->[2]->{'id'};
}
@@ -342,7 +358,11 @@ sub parse_param {
$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_)*randomorder$/) {
+ $randomorder{$referid}=$token->[2]->{'value'};
+ &Apache::lonnet::logthis("roing $referid ".$randomorder{$referid});
}
if ($token->[2]->{'name'}=~/^parameter_(0_)*encrypturl$/) {
if ($token->[2]->{'value'}=~/^yes$/i) {
@@ -621,7 +641,7 @@ sub readmap {
$hash{'title_0.0'}=&Apache::lonnet::metadata($uri,'title');
$hash{'ids_'.$furi}='0.0';
$hash{'is_map_0.0'}=1;
- loadmap($uri);
+ loadmap($uri,'0.0');
if (defined($hash{'map_start_'.$uri})) {
&Apache::lonnet::appenv("request.course.id" => $short,
"request.course.fn" => $fn,