--- rat/lonuserstate.pm 2013/05/06 18:08:39 1.145 +++ rat/lonuserstate.pm 2013/06/26 21:22:55 1.146 @@ -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.145 2013/05/06 18:08:39 raeburn Exp $ +# $Id: lonuserstate.pm,v 1.146 2013/06/26 21:22:55 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -59,6 +59,7 @@ 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 %randomizationcode; # code used to grade folder for bubblesheet exam my %encurl; # URLs in this folder are supposed to be encrypted my %hiddenurl; # this URL (or complete folder) is supposed to be hidden @@ -140,10 +141,10 @@ sub processversionfile { # Parameters: # uri - URI of the map file. # parent_rid - Resource id in the map of the parent resource (0.0 for the top level map) -# +# courseid - Course id for the course for which the map is being loaded # sub loadmap { - my ($uri,$parent_rid)=@_; + my ($uri,$parent_rid,$courseid)=@_; # Is the map already included? @@ -236,15 +237,28 @@ sub loadmap { # This is handled in the next chunk of code. my @map_ids; + my $codechecked; while (my $token = $parser->get_token) { next if ($token->[0] ne 'S'); # Resource if ($token->[1] eq 'resource') { - my $resource_id = &parse_resource($token,$lpc,$ispage,$uri); + my $resource_id = &parse_resource($token,$lpc,$ispage,$uri,$courseid); if (defined $resource_id) { - push(@map_ids, $resource_id); + push(@map_ids, $resource_id); + unless ($codechecked) { + my $startsymb = + &Apache::lonnet::encode_symb($hash{'map_id_'.$lpc},$resource_id, + $hash{'src_'."$lpc.$resource_id"}); + my $code = + &Apache::lonnet::EXT('resource.0.examcode',$startsymb,undef,undef, + undef,undef,$courseid); + if ($code) { + $randomizationcode{$parent_rid} = $code; + } + $codechecked = 1; + } } # Link @@ -260,6 +274,7 @@ sub loadmap { &parse_condition($token,$lpc); } } + undef($codechecked); # Handle randomization and random selection @@ -289,9 +304,22 @@ sub loadmap { # TODO: Here for sure we need to pass along the username/domain # so that we can impersonate users in lonprintout e.g. + my $setcode; + if (defined($randomizationcode{$parent_rid})) { + if ($env{'form.CODE'} eq '') { + $env{'form.CODE'} = $randomizationcode{$parent_rid}; + $setcode = 1; + } + } + my $rndseed=&Apache::lonnet::rndseed($seed); &Apache::lonnet::setup_random_from_rndseed($rndseed); + if ($setcode) { + undef($env{'form.CODE'}); + undef($setcode); + } + # Take the set of map ids we have decoded and permute them to a # random order based on the seed set above. All of this is # processing the randomorder parameter if it is set, not @@ -352,6 +380,7 @@ sub loadmap { # $lpc - Map nesting level (?) # $ispage - True if this resource is encapsulated in a .page (assembled resourcde). # $uri - URI of the enclosing resource. +# $courseid - Course id of the course containing the resource being parsed. # Returns: # Value of the id attribute of the tag. # @@ -372,7 +401,7 @@ sub loadmap { sub parse_resource { - my ($token,$lpc,$ispage,$uri) = @_; + my ($token,$lpc,$ispage,$uri,$courseid) = @_; # I refuse to countenance code like this that has # such a dirty side effect (and forcing this sub to be called within a loop). @@ -511,7 +540,7 @@ sub parse_resource { if (($turi=~/\.sequence$/) || ($turi=~/\.page$/)) { $hash{'is_map_'.$rid}=1; - &loadmap($turi,$rid); + &loadmap($turi,$rid,$courseid); } return $token->[2]->{'id'}; } @@ -1052,7 +1081,18 @@ sub hiddenurls { # -------------------------------- randomly eliminate the ones that should stay my (undef,$id)=split(/\./,$rid); if ($randompickseed{$rid}) { $id=$randompickseed{$rid}; } + my $setcode; + if (defined($randomizationcode{$rid})) { + if ($env{'form.CODE'} eq '') { + $env{'form.CODE'} = $randomizationcode{$rid}; + $setcode = 1; + } + } my $rndseed=&Apache::lonnet::rndseed($id); # use id instead of symb + if ($setcode) { + undef($env{'form.CODE'}); + undef($setcode); + } &Apache::lonnet::setup_random_from_rndseed($rndseed); my @whichids=&Math::Random::random_permuted_index($#currentrids+1); for (my $i=1;$i<=$rndpick;$i++) { $currentrids[$whichids[$i]]=''; } @@ -1370,7 +1410,7 @@ sub build_tmp_hashes { # sub-maps. - &loadmap($uri,'0.0'); + &loadmap($uri,'0.0',$short); # The code below only executes if there is a starting point for the map> # Q/BUG??? If there is no start resource for the map should that be an error?