version 1.3, 2011/10/06 10:56:49
|
version 1.6, 2011/11/29 11:50:53
|
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 95 my %cenv; # Course environment.
|
Line 98 my %cenv; # Course environment.
|
|
|
sub simplify { |
sub simplify { |
my $expression=shift; |
my $expression=shift; |
my $prior = ''; # This is safe as a null expression is pretty optimal. |
|
|
|
while ($prior ne $expression) { |
|
$prior = $expression; # Stop when the substitutions below do nothing. |
|
# (0&1) = 1 |
# (0&1) = 1 |
$expression=~s/\(0\&([_\.\d]+)\)/$1/g; |
$expression=~s/\(0\&([_\.\d]+)\)/$1/g; |
# (8)=8 |
# (8)=8 |
Line 115 sub simplify {
|
Line 115 sub simplify {
|
# ((5&3)|(4&6))|(1&2)=(5&3)|(4&6)|(1&2) |
# ((5&3)|(4&6))|(1&2)=(5&3)|(4&6)|(1&2) |
$expression=~ |
$expression=~ |
s/\((\([_\.\d]+(?:\&[_\.\d]+)*\))((?:\|\([_\.\d]+(?:\&[_\.\d]+)*\))+)\)\|(\([_\.\d]+(?:\&[_\.\d]+)*\))/\($1$2\|$3\)/g; |
s/\((\([_\.\d]+(?:\&[_\.\d]+)*\))((?:\|\([_\.\d]+(?:\&[_\.\d]+)*\))+)\)\|(\([_\.\d]+(?:\&[_\.\d]+)*\))/\($1$2\|$3\)/g; |
} |
|
|
|
return $expression; |
return $expression; |
} |
} |
|
|
Line 373 sub append_version {
|
Line 374 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 405 sub hiddenurls {
|
Line 432 sub hiddenurls {
|
my (undef,$id)=split(/\./,$rid); |
my (undef,$id)=split(/\./,$rid); |
if ($randompickseed{$rid}) { $id=$randompickseed{$rid}; } |
if ($randompickseed{$rid}) { $id=$randompickseed{$rid}; } |
my $rndseed=&Apache::lonnet::rndseed($id, $courseid, $udom, $uname, \%cenv); # use id instead of symb |
my $rndseed=&Apache::lonnet::rndseed($id, $courseid, $udom, $uname, \%cenv); # use id instead of symb |
&Apache::lonnet::logthis("lonmap random seed: $rndseed"); |
|
&Apache::lonnet::setup_random_from_rndseed($rndseed); |
&Apache::lonnet::setup_random_from_rndseed($rndseed); |
my @whichids=&Math::Random::random_permuted_index($#currentrids+1); |
my @whichids=&Math::Random::random_permuted_index($#currentrids+1); |
for (my $i=1;$i<=$rndpick;$i++) { $currentrids[$whichids[$i]]=''; } |
for (my $i=1;$i<=$rndpick;$i++) { $currentrids[$whichids[$i]]=''; } |
Line 1208 sub read_map {
|
Line 1234 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 1286 sub read_map {
|
Line 1313 sub read_map {
|
# |
# |
|
|
if ($randomize) { |
if ($randomize) { |
if (!$env{'request.role.adv'}) { |
if (!&has_advanced_role($username, $userdomain) ) { |
my $seed; |
my $seed; |
|
|
# In the advanced role, the map's random seed |
# In the advanced role, the map's random seed |
Line 1308 sub read_map {
|
Line 1335 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 1316 sub read_map {
|
Line 1347 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 1341 sub read_map {
|
Line 1370 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 1387 sub loadmap {
|
Line 1417 sub loadmap {
|
%encurl = (); |
%encurl = (); |
%hiddenurl = (); |
%hiddenurl = (); |
%parmhash = (); |
%parmhash = (); |
@cond = (); |
@cond = ('true:normal'); # Initial value for cond 0. |
$retfrid = ''; |
$retfrid = ''; |
$username = ''; |
$username = ''; |
$userdomain = ''; |
$userdomain = ''; |
Line 1400 sub loadmap {
|
Line 1430 sub loadmap {
|
$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; |
} |
} |
&Apache::lonnet::logthis("Course environment: \n" . Dumper(\%cenv)); |
|
|
$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 1447 sub loadmap {
|
Line 1476 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', $target_hash); |
|
|
# |
# |