version 1.5, 2011/10/21 10:10:07
|
version 1.10, 2013/05/30 04:02:02
|
Line 40 use HTML::TokeParser;
|
Line 40 use HTML::TokeParser;
|
|
|
use LONCAPA; |
use LONCAPA; |
use Apache::lonnet; |
use Apache::lonnet; |
|
use Apache::lonlocal; |
|
|
use Data::Dumper; |
use Data::Dumper; |
|
|
|
|
Line 68 my $retfrid;
|
Line 70 my $retfrid;
|
|
|
my $username; # User for whom the map is being read. |
my $username; # User for whom the map is being read. |
my $userdomain; # Domain the user lives in. |
my $userdomain; # Domain the user lives in. |
|
my $short_name; # Course shortname. |
my %mapalias_cache; # Keeps track of map aliases -> resources detects duplicates. |
my %mapalias_cache; # Keeps track of map aliases -> resources detects duplicates. |
my %cenv; # Course environment. |
my %cenv; # Course environment. |
|
|
Line 292 sub process_versions {
|
Line 295 sub process_versions {
|
# |
# |
sub versionerror { |
sub versionerror { |
my ($uri, $used, $unused) = @_; |
my ($uri, $used, $unused) = @_; |
my ($uri,$usedversion,$unusedversion)=@_; |
|
return '<br />'. |
return '<br />'. |
&mt('Version discrepancy: resource [_1] included in both version [_2] and version [_3]. Using version [_2].', |
&mt('Version discrepancy: resource [_1] included in both version [_2] and version [_3]. Using version [_2].', |
$uri,$used,$unused).'<br />'; |
$uri,$used,$unused).'<br />'; |
Line 371 sub append_version {
|
Line 373 sub append_version {
|
return $uri; |
return $uri; |
|
|
} |
} |
|
#------------------------------------------------------------------------------ |
|
# |
|
# Misc. utilities that don't fit into the other classifications. |
|
|
|
# Determine if the specified user has an 'advanced' role in a course. |
|
# Parameters: |
|
# cenv - reference to a course environment. |
|
# username - Name of the user we care about. |
|
# domain - Domain in which the user is defined. |
|
# Returns: |
|
# 0 - User does not have an advanced role in the course. |
|
# 1 - User does have an advanced role in the course. |
|
# |
|
sub has_advanced_role { |
|
my ($username, $domain) = @_; |
|
|
|
my %adv_roles = &Apache::lonnet::get_course_adv_roles($short_name); |
|
my $merged_username = $username . ':' . $domain; |
|
foreach my $user (values %adv_roles) { |
|
if ($merged_username eq $user) { |
|
return 1; |
|
} |
|
} |
|
return 0; |
|
} |
|
|
#-------------------------------------------------------------------------------- |
#-------------------------------------------------------------------------------- |
# Post processing subs: |
# Post processing subs: |
sub hiddenurls { |
sub hiddenurls { |
Line 772 sub parse_param {
|
Line 800 sub parse_param {
|
# $lpc - Map nesting level (?) |
# $lpc - Map nesting level (?) |
# $ispage - True if this resource is encapsulated in a .page (assembled resourcde). |
# $ispage - True if this resource is encapsulated in a .page (assembled resourcde). |
# $uri - URI of the enclosing resource. |
# $uri - URI of the enclosing resource. |
|
# $code - CODE for which resource is being parsed (CODEd assignments). |
# $hash - Reference to the hash we are building. |
# $hash - Reference to the hash we are building. |
# |
# |
# Returns: |
# Returns: |
Line 794 sub parse_param {
|
Line 823 sub parse_param {
|
# |
# |
|
|
sub parse_resource { |
sub parse_resource { |
my ($token,$lpc,$ispage,$uri, $hash) = @_; |
my ($token,$lpc,$ispage,$uri,$code,$hash) = @_; |
|
|
# I refuse to countenance code like this that has |
# I refuse to countenance code like this that has |
# such a dirty side effect (and forcing this sub to be called within a loop). |
# such a dirty side effect (and forcing this sub to be called within a loop). |
Line 941 sub parse_resource {
|
Line 970 sub parse_resource {
|
if (($turi=~/\.sequence$/) || |
if (($turi=~/\.sequence$/) || |
($turi=~/\.page$/)) { |
($turi=~/\.page$/)) { |
$hash->{'is_map_'.$rid}='1'; # String in lonuserstate. |
$hash->{'is_map_'.$rid}='1'; # String in lonuserstate. |
&read_map($turi,$rid, $hash); |
&read_map($turi,$rid,$code,$hash); |
} |
} |
return $token->[2]->{'id'}; |
return $token->[2]->{'id'}; |
} |
} |
Line 1149 sub parse_mapalias_param {
|
Line 1178 sub parse_mapalias_param {
|
# $parent_rid - map number qualified id of the parent of the map being read. |
# $parent_rid - map number qualified id of the parent of the map being read. |
# For the top level course map this is 0.0. For the first nested |
# For the top level course map this is 0.0. For the first nested |
# map 1.n where n is the id of the resource within the |
# map 1.n where n is the id of the resource within the |
# top level map and so on. |
# top level map and so on. |
|
# $code - CODE for which map is being read (CODEd assignments). |
# $hash - Reference to a hash that will become the big hash for the course |
# $hash - Reference to a hash that will become the big hash for the course |
# This hash is modified as per the map description. |
# This hash is modified as per the map description. |
# Side-effects: |
# Side-effects: |
Line 1159 sub parse_mapalias_param {
|
Line 1189 sub parse_mapalias_param {
|
# |
# |
# |
# |
sub read_map { |
sub read_map { |
my ($uri, $parent_rid, $hash) = @_; |
my ($uri, $parent_rid, $code, $hash) = @_; |
|
|
|
|
# Check for duplication: A map may only be included once. |
# Check for duplication: A map may only be included once. |
Line 1205 sub read_map {
|
Line 1235 sub read_map {
|
|
|
my $ispage = ($filename =~/\.page$/); |
my $ispage = ($filename =~/\.page$/); |
unless ($ispage || ($filename =~ /\.sequence$/)) { |
unless ($ispage || ($filename =~ /\.sequence$/)) { |
|
&Apache::lonnet::logthis("invalid: $filename : $uri"); |
throw Error::Simple(&mt("<br />Invalid map: <tt>[_1]</tt>", $filename)); |
throw Error::Simple(&mt("<br />Invalid map: <tt>[_1]</tt>", $filename)); |
} |
} |
|
|
Line 1259 sub read_map {
|
Line 1290 sub read_map {
|
# Resource |
# Resource |
|
|
if ($token->[1] eq 'resource') { |
if ($token->[1] eq 'resource') { |
my $resource_id = &parse_resource($token,$lmap_no,$ispage,$uri, $hash); |
my $resource_id = &parse_resource($token,$lmap_no,$ispage,$uri,$code,$hash); |
if (defined $resource_id) { |
if (defined $resource_id) { |
push(@map_ids, $resource_id); |
push(@map_ids, $resource_id); |
} |
} |
Line 1283 sub read_map {
|
Line 1314 sub read_map {
|
# |
# |
|
|
if ($randomize) { |
if ($randomize) { |
if (!$env{'request.role.adv'}) { |
if (!&has_advanced_role($username, $userdomain) || $code) { |
my $seed; |
my $seed; |
|
|
# In the advanced role, the map's random seed |
# In the advanced role, the map's random seed |
Line 1305 sub read_map {
|
Line 1336 sub read_map {
|
} |
} |
|
|
|
|
my $rndseed=&Apache::lonnet::rndseed($seed, $username, $userdomain); |
my $rndseed=&Apache::lonnet::rndseed($seed, '', |
|
$userdomain, $username, |
|
\%cenv); |
|
|
|
|
&Apache::lonnet::setup_random_from_rndseed($rndseed); |
&Apache::lonnet::setup_random_from_rndseed($rndseed); |
|
|
# Take the set of map ids we have decoded and permute them to a |
# Take the set of map ids we have decoded and permute them to a |
Line 1313 sub read_map {
|
Line 1348 sub read_map {
|
# processing the randomorder parameter if it is set, not |
# processing the randomorder parameter if it is set, not |
# randompick. |
# randompick. |
|
|
@map_ids=&math::Random::random_permutation(@map_ids); |
@map_ids=&Math::Random::random_permutation(@map_ids); |
} |
} |
|
|
|
|
my $from = shift(@map_ids); |
my $from = shift(@map_ids); |
my $from_rid = $lmap_no.'.'.$from; |
my $from_rid = $lmap_no.'.'.$from; |
$hash->{'map_start_'.$uri} = $from_rid; |
$hash->{'map_start_'.$uri} = $from_rid; |
Line 1338 sub read_map {
|
Line 1371 sub read_map {
|
$hash->{'type_'.$from_rid}='finish'; |
$hash->{'type_'.$from_rid}='finish'; |
} |
} |
|
|
|
|
# The last parsing pass parses the <mapalias> tags that associate a name |
# The last parsing pass parses the <mapalias> tags that associate a name |
# with resource ids. |
# with resource ids. |
|
|
Line 1364 sub read_map {
|
Line 1398 sub read_map {
|
# $cdom - Domain in which the course is evaluated. |
# $cdom - Domain in which the course is evaluated. |
# $uname - Name of the user for whom the course is being read |
# $uname - Name of the user for whom the course is being read |
# $udom - Name of the domain of the user for whom the course is being read. |
# $udom - Name of the domain of the user for whom the course is being read. |
|
# $code - CODE for which course is being read (CODEd assignments) |
# $target_hash- Reference to the target hash into which all of this is read. |
# $target_hash- Reference to the target hash into which all of this is read. |
# Note tht some of the hash entries we need to build require knowledge of the |
# Note tht some of the hash entries we need to build require knowledge of the |
# course URI.. these are expected to be filled in by the caller. |
# course URI.. these are expected to be filled in by the caller. |
Line 1372 sub read_map {
|
Line 1407 sub read_map {
|
# |
# |
# |
# |
sub loadmap { |
sub loadmap { |
my ($cnum, $cdom, $uname, $udom, $target_hash) = @_; |
my ($cnum, $cdom, $uname, $udom, $code, $target_hash) = @_; |
|
|
|
|
|
|
# Clear the auxillary hashes and the cond array. |
# Clear the auxiliary hashes and the cond array. |
|
|
|
|
%randompick = (); |
%randompick = (); |
Line 1390 sub loadmap {
|
Line 1425 sub loadmap {
|
$userdomain = ''; |
$userdomain = ''; |
%mapalias_cache = (); |
%mapalias_cache = (); |
%cenv = (); |
%cenv = (); |
|
$map_number = 0; |
|
|
|
|
# |
# |
|
|
$username = $uname; |
$username = $uname; |
$userdomain = $udom; |
$userdomain = $udom; |
|
|
my $short_name = $cdom .'/' . $cnum; |
$short_name = $cdom .'/' . $cnum; |
my $retfurl; |
my $retfurl; |
|
|
try { |
try { |
|
|
|
|
# Get the information we need about the course. |
# Get the information we need about the course. |
# Return without filling in anything if we can't get any info: |
# Return without filling in anything if we can't get any info: |
|
|
%cenv = &Apache::lonnet::coursedescription($short_name, |
%cenv = &Apache::lonnet::coursedescription($short_name, |
{'freshen_cache' => 1, |
{'freshen_cache' => 1, |
'user' => $uname}); |
'user' => $uname}); |
|
|
unless ($cenv{'url'}) { |
unless ($cenv{'url'}) { |
&Apache::lonnet::logthis("lonmap::loadmap failed: $cnum/$cdom - did not get url"); |
&Apache::lonnet::logthis("lonmap::loadmap failed: $cnum/$cdom - did not get url"); |
return; |
return; |
} |
} |
|
|
$course_id = $cdom . '_' . $cnum; # Long course id. |
$course_id = $cdom . '_' . $cnum; # Long course id. |
|
|
# Load the version information into the hash |
# Load the version information into the hash |
|
|
|
|
&process_versions(\%cenv, $target_hash); |
&process_versions(\%cenv, $target_hash); |
|
|
|
|
Line 1443 sub loadmap {
|
Line 1478 sub loadmap {
|
$target_hash->{'context.userdom'} = $userdomain; |
$target_hash->{'context.userdom'} = $userdomain; |
$target_hash->{'context.courseid'} = $course_id; |
$target_hash->{'context.courseid'} = $course_id; |
|
|
&read_map($course_uri, '0.0', $target_hash); |
|
|
&read_map($course_uri, '0.0', $code, $target_hash); |
|
|
# |
# |
|
|
Line 1495 sub loadmap {
|
Line 1531 sub loadmap {
|
|
|
|
|
&merge_hash($target_hash, 'randompick', \%randompick); |
&merge_hash($target_hash, 'randompick', \%randompick); |
&merge_hash($target_hash, 'randompickseed', \%randompick); |
&merge_hash($target_hash, 'randompickseed', \%randompickseed); |
&merge_hash($target_hash, 'randomorder', \%randomorder); |
&merge_hash($target_hash, 'randomorder', \%randomorder); |
&merge_hash($target_hash, 'encurl', \%encurl); |
&merge_hash($target_hash, 'encurl', \%encurl); |
&merge_hash($target_hash, 'hiddenurl', \%hiddenurl); |
&merge_hash($target_hash, 'hiddenurl', \%hiddenurl); |