--- loncom/interface/lonnavmaps.pm 2025/01/16 21:26:55 1.509.2.14.2.10 +++ loncom/interface/lonnavmaps.pm 2022/06/11 04:57:08 1.557 @@ -1,8 +1,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.509.2.14.2.10 2025/01/16 21:26:55 raeburn Exp $ - +# $Id: lonnavmaps.pm,v 1.557 2022/06/11 04:57:08 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -52,9 +51,16 @@ described at http://www.lon-capa.org. X When a user enters a course, LON-CAPA examines the course structure and caches it in what is often referred to as the "big hash" X. You can see it if you are logged into -LON-CAPA, in a course, by going to /adm/test. (You may need to -tweak the /home/httpd/lonTabs/htpasswd file to view it.) The -content of the hash will be under the heading "Big Hash". +LON-CAPA, in a course, by going to /adm/test. The content of +the hash will be under the heading "Big Hash". + +Access to /adm/test is controlled by a domain configuration, +which a Domain Coordinator will set for a server's default domain +via: Main Menu > Set domain configuration > Display (Access to +server status pages checked), and entering a username:domain +or IP address in the "Show user environment" row. Users with +an unexpired domain coordinator role in the server's domain +automatically receive access to /adm/test. Big Hash contains, among other things, how resources are related to each other (next/previous), what resources are maps, which @@ -65,7 +71,7 @@ processed. Apache::lonnavmaps provides an object model for manipulating this information in a higher-level fashion than directly manipulating -the hash. It also provides access to several auxilary functions +the hash. It also provides access to several auxiliary functions that aren't necessarily stored in the Big Hash, but are a per- resource sort of value, like whether there is any feedback on a given resource. @@ -78,11 +84,18 @@ Apache::lonnavmaps also provides fairly rendering navmaps, and last but not least, provides the navmaps view for when the user clicks the NAV button. -B: Apache::lonnavmaps I works for the "currently -logged in user"; if you want things like "due dates for another -student" lonnavmaps can not directly retrieve information like -that. You need the EXT function. This module can still help, -because many things, such as the course structure, are constant +B: Apache::lonnavmaps by default will show information +for the "currently logged in user". However, if information +about resources is needed for a different user, e.g., a bubblesheet +exam which uses randomorder, or randompick needs to be printed or +graded for named user(s) or specific CODEs, then the username, +domain, or CODE can be passed as arguments when creating a new +navmap object. + +Note if you want things like "due dates for another student", +you would use the EXT function instead of lonnavmaps. +That said, the lonnavmaps module can still help, because many +things, such as the course structure, are usually constant between users, and Apache::lonnavmaps can help by providing symbs for the EXT call. @@ -92,7 +105,9 @@ all, then documents the Apache::lonnavma is the key to accessing the Big Hash information, covers the use of the Iterator (which provides the logic for traversing the somewhat-complicated Big Hash data structure), documents the -Apache::lonnavmaps::Resource objects that are returned by +Apache::lonnavmaps::Resource objects that are returned singularly +by: getBySymb(), getById(), getByMapPc(), and getResourceByUrl() +(can also be as an array), or in an array by retrieveResources(). =head1 Subroutine: render @@ -534,10 +549,6 @@ my %colormap = $resObj->EXCUSED => '#3333FF', $resObj->PAST_DUE_ANSWER_LATER => '', $resObj->PAST_DUE_NO_ANSWER => '', - $resObj->PAST_DUE_ATMPT_ANS => '', - $resObj->PAST_DUE_ATMPT_NOANS => '', - $resObj->PAST_DUE_NO_ATMT_ANS => '', - $resObj->PAST_DUE_NO_ATMT_NOANS => '', $resObj->ANSWER_OPEN => '#006600', $resObj->OPEN_LATER => '', $resObj->TRIES_LEFT => '', @@ -683,10 +694,10 @@ sub getDescription { return &Apache::lonhtmlcommon::direct_parm_link(&mt("Open, no due date"),$res->symb(),'duedate',$part).$slotinfo; } } - if (($status == $res->PAST_DUE_ANSWER_LATER) || ($status == $res->PAST_DUE_ATMPT_ANS) || ($status == $res->PAST_DUE_NO_ATMT_ANS)) { + if ($status == $res->PAST_DUE_ANSWER_LATER) { return &mt("Answer open [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($answer,'start'),$res->symb(),'answerdate',$part)); } - if (($status == $res->PAST_DUE_NO_ANSWER) || ($status == $res->PAST_DUE_ATMPT_NOANS) || ($status == $res->PAST_DUE_NO_ATMT_NOANS)) { + if ($status == $res->PAST_DUE_NO_ANSWER) { if ($res->is_practice()) { return &mt("Closed [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($due,'start'),$res->symb(),'answerdate,duedate',$part)); } else { @@ -956,8 +967,6 @@ sub render_resource { $newBranchText = ".mt('Branch')."; } - # links to open and close the folder - my $whitespace = $location.'/whitespace_21.gif'; my ($nomodal,$linkopen,$linkclose); unless ($resource->is_map() || $params->{'resource_nolink'}) { @@ -1011,12 +1020,8 @@ sub render_resource { if ($it->{CONDITION}) { $nowOpen = !$nowOpen; } - my $folderType; - if (&advancedUser() && $resource->is_missing_map()) { - $folderType = 'none'; - } else { - $folderType = $resource->is_sequence() ? 'folder' : 'page'; - } + + my $folderType = $resource->is_sequence() ? 'folder' : 'page'; my $title=$resource->title; $title=~s/\"/\&qout;/g; if (!$params->{'resource_no_folder_link'}) { @@ -1049,7 +1054,7 @@ sub render_resource { } } if (((&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) || - (&Apache::lonnet::allowed('cev',$env{'request.course.id'}))) && + (&Apache::lonnet::allowed('cev',$env{'request.course.id'}))) && ($resource->symb=~/\_\_\_[^\_]+\_\_\_uploaded/)) { if (!$params->{'map_no_edit_link'}) { my $icon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png'; @@ -1248,7 +1253,7 @@ sub render_long_status { } } } - + if (($resource->kind() eq "res") && ($resource->is_raw_problem() || $resource->is_gradable()) && !$firstDisplayed) { @@ -1408,7 +1413,7 @@ sub render { # Without renaming the filterfunc, the server seems to go into # an infinite loop my $oldFilterFunc = $filterFunc; - $filterFunc = sub { my $res = shift; return !$res->randomout() && + $filterFunc = sub { my $res = shift; return !$res->randomout() && ($res->deeplink($args->{'caller'}) ne 'absent') && ($res->deeplink($args->{'caller'}) ne 'grades') && !$res->deeplinkout() && @@ -1418,40 +1423,9 @@ sub render { my $condition = 0; if ($env{'form.condition'}) { $condition = 1; - } elsif (($env{'request.deeplink.login'}) && ($env{'request.course.id'}) && (!$userCanSeeHidden)) { - if (!defined($navmap)) { - $navmap = Apache::lonnavmaps::navmap->new(); - } - if (defined($navmap)) { - my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; - my $symb = &Apache::loncommon::symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom); - if ($symb) { - my $deeplink; - my $res = $navmap->getBySymb($symb); - if ($res->is_map()) { - my $mapname = &Apache::lonnet::declutter($res->src()); - $mapname = &Apache::lonnet::deversion($mapname); - $deeplink = $navmap->get_mapparam(undef,$mapname,"0.deeplink"); - } else { - $deeplink = $res->deeplink(); - } - if ($deeplink ne '') { - if ((split(/,/,$deeplink))[1] eq 'hide') { - if ($res->is_map()) { - map { $filterHash->{$_} = 1 if $_ } split(/,/,$res->map_hierarchy()); - } else { - my $mapurl = (&Apache::lonnet::decode_symb($symb))[0]; - my $map = $navmap->getResourceByUrl($mapurl); - map { $filterHash->{$_} = 1 if $_ } split(/,/,$map->map_hierarchy()); - } - } - } - } - } } - if (!$env{'form.folderManip'} && !defined($args->{'iterator'}) && !$args->{'nocurrloc'}) { + if (!$env{'form.folderManip'} && !defined($args->{'iterator'})) { # Step 1: Check to see if we have a navmap if (!defined($navmap)) { $navmap = Apache::lonnavmaps::navmap->new(); @@ -1472,11 +1446,11 @@ sub render { my $currenturl = $env{'form.postdata'}; #$currenturl=~s/^http\:\/\///; #$currenturl=~s/^[^\/]+//; - unless ($args->{'caller'} eq 'sequence') { + unless ($args->{'caller'} eq 'sequence') { $here = $jump = &Apache::lonnet::symbread($currenturl); } } - if (($here eq '') && ($args->{'caller'} ne 'sequence')) { + if (($here eq '') && ($args->{'caller'} ne 'sequence')) { my $last; if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db', &GDBM_READER(),0640)) { @@ -1490,7 +1464,7 @@ sub render { my $mapIterator = $navmap->getIterator(undef, undef, undef, 1); my $curRes; my $found = 0; - my $here_is_navmaps = 0; + my $here_is_navmaps = 0; if ($here =~ m{___\d+___adm/navmaps$}) { $here_is_navmaps = 1; } @@ -1658,22 +1632,16 @@ END } $result.=''; } - if (($args->{'caller'} eq 'navmapsdisplay') && ($env{'request.course.id'})) { + if (($args->{'caller'} eq 'navmapsdisplay') && + ((&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) || + (&Apache::lonnet::allowed('cev',$env{'request.course.id'})))) { my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; - if ($env{'course.'.$env{'request.course.id'}.'.url'} eq + if ($env{'course.'.$env{'request.course.id'}.'.url'} eq "uploaded/$cdom/$cnum/default.sequence") { - if ((&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) || - (&Apache::lonnet::allowed('cev',$env{'request.course.id'}))) { - &add_linkitem($args->{'linkitems'},'edittoplevel', - "javascript:gocmd('/adm/coursedocs','editdocs');", - 'Content Editor'); - } - if ($counter) { - &add_linkitem($args->{'linkitems'},'printout', - "javascript:gopost('/adm/printout','/adm/navmaps');", - 'Prepare a printable document'); - } + &add_linkitem($args->{'linkitems'},'edittoplevel', + "javascript:gocmd('/adm/coursedocs','editdocs');", + 'Content Editor'); } } @@ -1716,35 +1684,14 @@ END # We also do this even if $args->{'suppressEmptySequences'} # is not true, so we can hide empty sequences for which the # hiddenresource parameter is set to yes (at map level), or - # mark as hidden for users who have $userCanSeeHidden. + # mark as hidden for users who have $userCanSeeHidden. # Use DFS for speed, since structure actually doesn't matter, # except what map has what resources. - # - # To ensure the "Selected Resources from selected folder in course" - # printout generation option will work in sessions launched via a - # deep link, the value of $args->{'filterFunc'} included in the - # call to lonnavmaps::render() is omitted from the filter function - # used with the DFS Iterator when $args->{'caller'} is 'printout'. - # - # As a result $sequence->{DATA}->{HAS_VISIBLE_CHILDREN} can be - # set to 1 for folder(s) which include resources only accessible - # for sessions launched via a deep link, when the current session - # is of that type. my $dfsit = Apache::lonnavmaps::DFSiterator->new($navmap, $it->{FIRST_RESOURCE}, $it->{FINISH_RESOURCE}, {}, undef, 1); - - my $dfsFilterFunc; - if ($args->{'caller'} eq 'printout') { - $dfsFilterFunc = sub { my $res = shift; return !$res->randomout() && - ($res->deeplink($args->{'caller'}) ne 'absent') && - ($res->deeplink($args->{'caller'}) ne 'grades') && - !$res->deeplinkout();}; - } else { - $dfsFilterFunc = $filterFunc; - } my $depth = 0; $dfsit->next(); my $curRes = $dfsit->next(); @@ -1752,7 +1699,7 @@ END if ($curRes == $dfsit->BEGIN_MAP()) { $depth++; } if ($curRes == $dfsit->END_MAP()) { $depth--; } - if (ref($curRes)) { + if (ref($curRes)) { # Parallel pre-processing: Do sequences have non-filtered-out children? if ($curRes->is_map()) { $curRes->{DATA}->{HAS_VISIBLE_CHILDREN} = 0; @@ -1763,9 +1710,8 @@ END } elsif ($curRes->src()) { # Not a sequence: if it's filtered, ignore it, otherwise # rise up the stack and mark the sequences as having children - if (&$dfsFilterFunc($curRes)) { + if (&$filterFunc($curRes)) { for my $sequence (@{$dfsit->getStack()}) { - next unless ($sequence->is_map()); $sequence->{DATA}->{HAS_VISIBLE_CHILDREN} = 1; } } @@ -1895,7 +1841,7 @@ END next; } else { my $mapname = &Apache::lonnet::declutter($curRes->src()); - $mapname = &Apache::lonnet::deversion($mapname); + $mapname = &Apache::lonnet::deversion($mapname); if (lc($navmap->get_mapparam(undef,$mapname,"0.hiddenresource")) eq 'yes') { if ($userCanSeeHidden) { $args->{'mapHidden'} = 1; @@ -1990,7 +1936,7 @@ END } else { $args->{'resource_nolink'} = 1; } - + # If the multipart problem was condensed, "forget" it was multipart if (scalar(@parts) == 1) { $args->{'multipart'} = 0; @@ -2034,13 +1980,13 @@ END } } if (defined($anchor)) { $anchor='#'.$anchor; } - if (($args->{'caller'} eq 'sequence') && ($curRes->is_map())) { - $args->{"resourceLink"} = $src.($srcHasQuestion?'&':'?') .'navmap=1'; - } else { + if (($args->{'caller'} eq 'sequence') && ($curRes->is_map())) { + $args->{"resourceLink"} = $src.($srcHasQuestion?'&':'?') .'navmap=1'; + } else { $args->{"resourceLink"} = $src. ($srcHasQuestion?'&':'?') . 'symb=' . &escape($symb).$inhibitmenu.$anchor; - } + } } # Now, we've decided what parts to show. Loop through them and # show them. @@ -2142,7 +2088,7 @@ sub show_linkitems_toolbar { $result .= ''."\n". '
    '; my @linkorder = ('firsthomework','everything','uncompleted', - 'changefolder','clearbubbles','printout','edittoplevel'); + 'changefolder','clearbubbles','edittoplevel'); foreach my $link (@linkorder) { if (ref($args->{'linkitems'}{$link}) eq 'HASH') { if ($args->{'linkitems'}{$link}{'text'} ne '') { @@ -2274,17 +2220,10 @@ sub new { $self->{USERNAME} = shift || $env{'user.name'}; $self->{DOMAIN} = shift || $env{'user.domain'}; - $self->{SECTION} = shift; $self->{CODE} = shift; - $self->{NOHIDE} = shift; + $self->{NOHIDE} = shift; - if (($self->{SECTION} eq '') && ($env{'request.course.sec'} ne '')) { - if (($self->{USERNAME} eq $env{'user.name'}) && - ($self->{USERNAME} eq $env{'user.domain'})) { - $self->{SECTION} = $env{'request.course.sec'}; - } - } # Resource cache stores navmap resources as we reference them. We generate # them on-demand so we don't pay for creating resources unless we use them. @@ -2326,7 +2265,7 @@ sub new { $self->{PARM_HASH} = \%parmhash; $self->{PARM_CACHE} = {}; } else { - $self->change_user($self->{USERNAME}, $self->{DOMAIN}, $self->{SECTION}, $self->{CODE}, $self->{NOHIDE}); + $self->change_user($self->{USERNAME}, $self->{DOMAIN}, $self->{CODE}, $self->{NOHIDE}); } return $self; @@ -2337,17 +2276,15 @@ sub new { # username/domain associated with a navmap (e.g. to navigate for someone # else besides the current user...if sufficiently privileged. # Parameters: -# user - New user. -# domain - Domain to which the user belongs. -# section - Section to which the user belongs. -# code - Anonymous CODE in use. +# user - New user. +# domain- Domain the user belongs to. +# code - Anonymous CODE in use. # Implicit inputs: # sub change_user { my $self = shift; $self->{USERNAME} = shift; $self->{DOMAIN} = shift; - $self->{SECTION} = shift; $self->{CODE} = shift; $self->{NOHIDE} = shift; @@ -2370,7 +2307,7 @@ sub change_user { - # Now clear the parm cache and reconstruct the parm hash fromt he big_hash + # Now clear the parm cache and reconstruct the parm hash from the big_hash # param.xxxx keys. $self->{PARM_CACHE} = {}; @@ -2835,6 +2772,7 @@ sub parmval { return $self->{PARM_CACHE}->{$hashkey}; } } + my $result = $self->parmval_real($what, $symb, $recurse); $self->{PARM_CACHE}->{$hashkey} = $result; if (wantarray) { @@ -2853,7 +2791,7 @@ sub parmval_real { $self->generate_course_user_opt(); my $cid=$env{'request.course.id'}; - my $csec=$self->{SECTION}; + my $csec=$env{'request.course.sec'}; my $cgroup=''; my @cgrps=split(/:/,$env{'request.course.groups'}); if (@cgrps > 0) { @@ -2872,29 +2810,35 @@ sub parmval_real { if ($fn =~ /ext\.tool$/) { $toolsymb = $symb; } + my ($recursed,@recurseup); + # ----------------------------------------------------- Cascading lookup scheme my $rwhat=$what; $what=~s/^parameter\_//; $what=~s/\_/\./; my $symbparm=$symb.'.'.$what; + my $recurseparm=$mapname.'___(rec).'.$what; my $mapparm=$mapname.'___(all).'.$what; my $usercourseprefix=$cid; - + my $grplevel=$usercourseprefix.'.['.$cgroup.'].'.$what; my $grplevelr=$usercourseprefix.'.['.$cgroup.'].'.$symbparm; + my $grpleveli=$usercourseprefix.'.['.$cgroup.'].'.$recurseparm; my $grplevelm=$usercourseprefix.'.['.$cgroup.'].'.$mapparm; my $seclevel= $usercourseprefix.'.['.$csec.'].'.$what; my $seclevelr=$usercourseprefix.'.['.$csec.'].'.$symbparm; + my $secleveli=$usercourseprefix.'.['.$csec.'].'.$recurseparm; my $seclevelm=$usercourseprefix.'.['.$csec.'].'.$mapparm; my $courselevel= $usercourseprefix.'.'.$what; my $courselevelr=$usercourseprefix.'.'.$symbparm; + my $courseleveli=$usercourseprefix.'.'.$recurseparm; my $courselevelm=$usercourseprefix.'.'.$mapparm; @@ -2906,6 +2850,23 @@ sub parmval_real { if ($uname and defined($useropt)) { if (defined($$useropt{$courselevelr})) { return [$$useropt{$courselevelr},'resource']; } if (defined($$useropt{$courselevelm})) { return [$$useropt{$courselevelm},'map']; } + if (defined($$useropt{$courseleveli})) { return [$$useropt{$courseleveli},'map']; } + unless ($recursed) { + @recurseup = $self->recurseup_maps($mapname); + $recursed = 1; + } + foreach my $item (@recurseup) { + my $norecursechk=$usercourseprefix.'.'.$item.'___(all).'.$what; + if (defined($$useropt{$norecursechk})) { + if ($what =~ /\.(encrypturl|hiddenresource)$/) { + return [$$useropt{$norecursechk},'map']; + } else { + last; + } + } + my $recursechk=$usercourseprefix.'.'.$item.'___(rec).'.$what; + if (defined($$useropt{$recursechk})) { return [$$useropt{$recursechk},'map']; } + } if (defined($$useropt{$courselevel})) { return [$$useropt{$courselevel},'course']; } } @@ -2913,12 +2874,46 @@ sub parmval_real { if ($cgroup ne '' and defined($courseopt)) { if (defined($$courseopt{$grplevelr})) { return [$$courseopt{$grplevelr},'resource']; } if (defined($$courseopt{$grplevelm})) { return [$$courseopt{$grplevelm},'map']; } + if (defined($$courseopt{$grpleveli})) { return [$$courseopt{$grpleveli},'map']; } + unless ($recursed) { + @recurseup = $self->recurseup_maps($mapname); + $recursed = 1; + } + foreach my $item (@recurseup) { + my $norecursechk=$usercourseprefix.'.['.$cgroup.'].'.$item.'___(all).'.$what; + if (defined($$courseopt{$norecursechk})) { + if ($what =~ /\.(encrypturl|hiddenresource)$/) { + return [$$courseopt{$norecursechk},'map']; + } else { + last; + } + } + my $recursechk=$usercourseprefix.'.['.$cgroup.'].'.$item.'___(rec).'.$what; + if (defined($$courseopt{$recursechk})) { return [$$courseopt{$recursechk},'map']; } + } if (defined($$courseopt{$grplevel})) { return [$$courseopt{$grplevel},'course']; } } - if ($csec and defined($courseopt)) { + if ($csec ne '' and defined($courseopt)) { if (defined($$courseopt{$seclevelr})) { return [$$courseopt{$seclevelr},'resource']; } if (defined($$courseopt{$seclevelm})) { return [$$courseopt{$seclevelm},'map']; } + if (defined($$courseopt{$secleveli})) { return [$$courseopt{$secleveli},'map']; } + unless ($recursed) { + @recurseup = $self->recurseup_maps($mapname); + $recursed = 1; + } + foreach my $item (@recurseup) { + my $norecursechk=$usercourseprefix.'.['.$csec.'].'.$item.'___(all).'.$what; + if (defined($$courseopt{$norecursechk})) { + if ($what =~ /\.(encrypturl|hiddenresource)$/) { + return [$$courseopt{$norecursechk},'map']; + } else { + last; + } + } + my $recursechk=$usercourseprefix.'.['.$csec.'].'.$item.'___(rec).'.$what; + if (defined($$courseopt{$recursechk})) { return [$$courseopt{$recursechk},'map']; } + } if (defined($$courseopt{$seclevel})) { return [$$courseopt{$seclevel},'course']; } } @@ -2942,6 +2937,25 @@ sub parmval_real { # --------------------------------------------------- fifth, check more course if (defined($courseopt)) { if (defined($$courseopt{$courselevelm})) { return [$$courseopt{$courselevelm},'map']; } + if (defined($$courseopt{$courseleveli})) { return [$$courseopt{$courseleveli},'map']; } + unless ($recursed) { + @recurseup = $self->recurseup_maps($mapname); + $recursed = 1; + } + foreach my $item (@recurseup) { + my $norecursechk=$usercourseprefix.'.'.$item.'___(all).'.$what; + if (defined($$courseopt{$norecursechk})) { + if ($what =~ /\.(encrypturl|hiddenresource)$/) { + return [$$courseopt{$norecursechk},'map']; + } else { + last; + } + } + my $recursechk=$usercourseprefix.'.'.$item.'___(rec).'.$what; + if (defined($$courseopt{$recursechk})) { + return [$$courseopt{$recursechk},'map']; + } + } if (defined($$courseopt{$courselevel})) { my $ret = [$$courseopt{$courselevel},'course']; return $ret; @@ -2966,7 +2980,7 @@ sub parmval_real { } sub recurseup_maps { - my ($self,$mapname,$getsymb) = @_; + my ($self,$mapname) = @_; my @recurseup; if ($mapname) { my $res = $self->getResourceByUrl($mapname); @@ -2974,11 +2988,7 @@ sub recurseup_maps { my @pcs = split(/,/,$res->map_hierarchy()); shift(@pcs); if (@pcs) { - if ($getsymb) { - @recurseup = map { &Apache::lonnet::declutter($self->getByMapPc($_)->symb()); } reverse(@pcs); - } else { - @recurseup = map { &Apache::lonnet::declutter($self->getByMapPc($_)->src()); } reverse(@pcs); - } + @recurseup = map { &Apache::lonnet::declutter($self->getByMapPc($_)->src()); } reverse(@pcs); } } } @@ -3010,12 +3020,8 @@ sub recursed_crumbs { my $pc = $map->map_pc(); next if ((!$pc) || ($pc == 1)); push(@links,$map); - my $text = $map->title(); - if ($text eq '') { - $text = '...'; - } - push(@revmapinfo,{'href' => $env{'request.use_absolute'}.$map->link().'?navmap=1','text' => $text,'no_mt' => 1,}); - $totallength += length($text); + push(@revmapinfo,{'href' => $env{'request.use_absolute'}.$map->link().'?navmap=1','text' => $map->title(),'no_mt' => 1,}); + $totallength += length($map->title()); } my $numlinks = scalar(@links); if ($numlinks) { @@ -3027,11 +3033,7 @@ sub recursed_crumbs { } @revmapinfo = (); foreach my $map (@links) { - my $title = $map->title(); - if ($title eq '') { - $title = '...'; - } - my $showntitle = &truncate_crumb_text($title,$avg); + my $showntitle = &truncate_crumb_text($map->title(),$avg); if ($showntitle ne '') { push(@revmapinfo,{'href' => $env{'request.use_absolute'}.$map->link().'?navmap=1','text' => $showntitle,'no_mt' => 1,}); } @@ -3090,7 +3092,7 @@ sub map_printdates { my $opendate = $self->get_mapparam($res->symb(),'',"$part.printstartdate"); - my $closedate= $self->get_mapparam($res->symb(),'', "$part.printenddate"); + my $closedate= $self->get_mapparam($res->symb(),'',"$part.printenddate"); return ($opendate, $closedate); @@ -3106,7 +3108,7 @@ sub get_mapparam { # Get the course id and section if there is one. my $cid=$env{'request.course.id'}; - my $csec=$self->{SECTION}; + my $csec=$env{'request.course.sec'}; my $cgroup=''; my @cgrps=split(/:/,$env{'request.course.groups'}); if (@cgrps > 0) { @@ -3120,6 +3122,7 @@ sub get_mapparam { my $result=''; my ($recursed,@recurseup); + # Figure out which map we are in. if ($symb && !$mapname) { @@ -3128,21 +3131,25 @@ sub get_mapparam { $mapname = &Apache::lonnet::deversion($mapname); } + my $rwhat=$what; $what=~s/^parameter\_//; $what=~s/\_/\./; # Build the hash keys for the lookup: - my $symbparm=$symb.'.'.$what; my $mapparm=$mapname.'___(all).'.$what; + my $recurseparm=$mapname.'___(rec).'.$what; my $usercourseprefix=$cid; - my $grplevel = "$usercourseprefix.[$cgroup].$mapparm"; - my $seclevel = "$usercourseprefix.[$csec].$mapparm"; - my $courselevel = "$usercourseprefix.$mapparm"; - + my $grplevelm = "$usercourseprefix.[$cgroup].$mapparm"; + my $seclevelm = "$usercourseprefix.[$csec].$mapparm"; + my $courselevelm = "$usercourseprefix.$mapparm"; + + my $grpleveli = "$usercourseprefix.[$cgroup].$recurseparm"; + my $secleveli = "$usercourseprefix.[$csec].$recurseparm"; + my $courseleveli = "$usercourseprefix.$recurseparm"; # Get handy references to the hashes we need in $self: @@ -3155,22 +3162,29 @@ sub get_mapparam { if ($uname and defined($useropt)) { - if (defined($$useropt{$courselevel})) { - return $$useropt{$courselevel}; + if (defined($$useropt{$courselevelm})) { + return $$useropt{$courselevelm}; } - if ($what =~ /\.(encrypturl|hiddenresource)$/) { - unless ($recursed) { - @recurseup = $self->recurseup_maps($mapname); - $recursed = 1; - } - foreach my $item (@recurseup) { - my $norecursechk=$usercourseprefix.'.'.$item.'___(all).'.$what; - if (defined($$useropt{$norecursechk})) { - if ($what =~ /\.(encrypturl|hiddenresource)$/) { - return $$useropt{$norecursechk}; - } + if (defined($$useropt{$courseleveli})) { + return $$useropt{$courseleveli}; + } + unless ($recursed) { + @recurseup = $self->recurseup_maps($mapname); + $recursed = 1; + } + foreach my $item (@recurseup) { + my $norecursechk=$usercourseprefix.'.'.$item.'___(all).'.$what; + if (defined($$useropt{$norecursechk})) { + if ($what =~ /\.(encrypturl|hiddenresource)$/) { + return $$useropt{$norecursechk}; + } else { + last; } } + my $recursechk=$usercourseprefix.'.'.$item.'___(rec).'.$what; + if (defined($$useropt{$recursechk})) { + return $$useropt{$recursechk}; + } } } @@ -3179,48 +3193,59 @@ sub get_mapparam { if ($cgroup ne '' and defined ($courseopt)) { - if (defined($$courseopt{$grplevel})) { - return $$courseopt{$grplevel}; + if (defined($$courseopt{$grplevelm})) { + return $$courseopt{$grplevelm}; } - if ($what =~ /\.(encrypturl|hiddenresource)$/) { - unless ($recursed) { - @recurseup = $self->recurseup_maps($mapname); - $recursed = 1; - } - foreach my $item (@recurseup) { - my $norecursechk=$usercourseprefix.'.['.$cgroup.'].'.$item.'___(all).'.$what; - if (defined($$courseopt{$norecursechk})) { - if ($what =~ /\.(encrypturl|hiddenresource)$/) { - return $$courseopt{$norecursechk}; - } + if (defined($$courseopt{$grpleveli})) { + return $$courseopt{$grpleveli}; + } + unless ($recursed) { + @recurseup = $self->recurseup_maps($mapname); + $recursed = 1; + } + foreach my $item (@recurseup) { + my $norecursechk=$usercourseprefix.'.['.$cgroup.'].'.$item.'___(all).'.$what; + if (defined($$courseopt{$norecursechk})) { + if ($what =~ /\.(encrypturl|hiddenresource)$/) { + return $$courseopt{$norecursechk}; + } else { + last; } } + my $recursechk=$usercourseprefix.'.['.$cgroup.'].'.$item.'___(rec).'.$what; + if (defined($$courseopt{$recursechk})) { + return $$courseopt{$recursechk}; + } } } # Check course -- section - - - - if ($csec and defined($courseopt)) { - if (defined($$courseopt{$seclevel})) { - return $$courseopt{$seclevel}; + if ($csec ne '' and defined($courseopt)) { + if (defined($$courseopt{$seclevelm})) { + return $$courseopt{$seclevelm}; } - if ($what =~ /\.(encrypturl|hiddenresource)$/) { - unless ($recursed) { - @recurseup = $self->recurseup_maps($mapname); - $recursed = 1; - } - foreach my $item (@recurseup) { - my $norecursechk=$usercourseprefix.'.['.$csec.'].'.$item.'___(all).'.$what; - if (defined($$courseopt{$norecursechk})) { - if ($what =~ /\.(encrypturl|hiddenresource)$/) { - return $$courseopt{$norecursechk}; - } + if (defined($$courseopt{$secleveli})) { + return $$courseopt{$secleveli}; + } + unless ($recursed) { + @recurseup = $self->recurseup_maps($mapname); + $recursed = 1; + } + foreach my $item (@recurseup) { + my $norecursechk=$usercourseprefix.'.['.$csec.'].'.$item.'___(all).'.$what; + if (defined($$courseopt{$norecursechk})) { + if ($what =~ /\.(encrypturl|hiddenresource)$/) { + return $$courseopt{$norecursechk}; + } else { + last; } } + my $recursechk=$usercourseprefix.'.['.$csec.'].'.$item.'___(rec).'.$what; + if (defined($$courseopt{$recursechk})) { + return $$courseopt{$recursechk}; + } } } # Check the map parameters themselves: @@ -3229,7 +3254,7 @@ sub get_mapparam { my $symbparm=$symb.'.'.$what; my $thisparm = $$parmhash{$symbparm}; if (defined($thisparm)) { - return $thisparm; + return $thisparm; } } @@ -3237,25 +3262,34 @@ sub get_mapparam { # Additional course parameters: if (defined($courseopt)) { - if (defined($$courseopt{$courselevel})) { - return $$courseopt{$courselevel}; + if (defined($$courseopt{$courselevelm})) { + return $$courseopt{$courselevelm}; } - if ($what =~ /\.(encrypturl|hiddenresource)$/) { - unless ($recursed) { - @recurseup = $self->recurseup_maps($mapname); - $recursed = 1; - } + if (defined($$courseopt{$courseleveli})) { + return $$courseopt{$courseleveli}; + } + unless ($recursed) { + @recurseup = $self->recurseup_maps($mapname); + $recursed = 1; + } + if (@recurseup) { foreach my $item (@recurseup) { my $norecursechk=$usercourseprefix.'.'.$item.'___(all).'.$what; if (defined($$courseopt{$norecursechk})) { if ($what =~ /\.(encrypturl|hiddenresource)$/) { return $$courseopt{$norecursechk}; + } else { + last; } } + my $recursechk=$usercourseprefix.'.'.$item.'___(rec).'.$what; + if (defined($$courseopt{$recursechk})) { + return $$courseopt{$recursechk}; + } } } } - return undef; # Unefined if we got here. + return undef; # Undefined if we got here. } sub course_printdates { @@ -3275,11 +3309,11 @@ sub getcourseparam { my $uname = $self->{USERNAME}; my $udom = $self->{DOMAIN}; - my $csec = $self->{SECTION}; - # Course and group ids come from the env: + # Course, section, group ids come from the env: my $cid = $env{'request.course.id'}; + my $csec = $env{'request.course.sec'}; my $cgroup = ''; # Assume no group my @cgroups = split(/:/, $env{'request.course.groups'}); @@ -3297,10 +3331,6 @@ sub getcourseparam { $what=~s/^parameter\_//; $what=~s/\_/\./; - - my $symbparm = $symb . '.' . $what; - my $mapparm=$mapname.'___(all).'.$what; - # Local refs to the hashes we're going to look at: my $useropt = $self->{USER_OPT}; @@ -4378,7 +4408,7 @@ sub new { # This is a speed optimization, to avoid calling symb() too often. $self->{SYMB} = $self->symb(); - + return $self; } @@ -4505,7 +4535,7 @@ sub enclosing_map_src { } sub symb { my $self=shift; - if (defined($self->{SYMB})) { return $self->{SYMB}; } + if (defined $self->{SYMB}) { return $self->{SYMB}; } (my $first, my $second) = $self->{ID} =~ /(\d+).(\d+)/; my $symbSrc = &Apache::lonnet::declutter($self->src()); my $symb = &Apache::lonnet::declutter($self->navHash('map_id_'.$first)) @@ -4709,11 +4739,6 @@ sub is_sequence { return $self->navHash("is_map_", 1) && $self->navHash("map_type_" . $self->map_pc()) eq 'sequence'; } -sub is_missing_map { - my $self=shift; - return $self->navHash("is_map_", 1) && - $self->navHash("map_type_" . $self->map_pc()) eq 'none'; -} sub is_survey { my $self = shift(); my $part = shift(); @@ -5063,10 +5088,10 @@ sub duedate { my $date; my @interval=$self->parmval("interval", $part); my $due_date=$self->parmval("duedate", $part); - if ($interval[0] =~ /(\d+)/) { + if ($interval[0] =~ /^(\d+)/) { my $timelimit = $1; my $first_access=&Apache::lonnet::get_first_access($interval[1], - $self->{SYMB}); + $self->{SYMB}); if (defined($first_access)) { my $interval = $first_access+$timelimit; $date = (!$due_date || $interval < $due_date) ? $interval @@ -5141,7 +5166,7 @@ sub weight { my $weight = &Apache::lonnet::EXT('resource.'.$part.'.weight', $self->{SYMB}, $self->{DOMAIN}, $self->{USERNAME}, - $self->{SECTION}); + $env{'request.course.sec'}); return $weight; } sub part_display { @@ -5208,8 +5233,14 @@ sub getReturnHash { my $self = shift; if (!defined($self->{RETURN_HASH})) { - my %tmpHash = &Apache::lonnet::restore($self->{SYMB},undef,$self->{DOMAIN},$self->{USERNAME}); - $self->{RETURN_HASH} = \%tmpHash; + #my %tmpHash = &Apache::lonnet::restore($self->{SYMB},undef,$self->{DOMAIN},$self->{USERNAME}); + #$self->{RETURN_HASH} = \%tmpHash; + # When info is retrieved for several resources (as when rendering a directory), + # it is much faster to use the user profile dump and avoid repeated lonnet requests + # (especially since lonnet::currentdump is using Lond directly whenever possible, + # and lonnet::restore is not at this point). + $self->{NAV_MAP}->get_user_data(); + $self->{RETURN_HASH} = $self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}; } } @@ -5609,6 +5640,7 @@ The problem will be opened later. Open and not yet due. + =item * B: The due date has passed, but the answer date has not yet arrived. @@ -5621,26 +5653,6 @@ The due date has passed and there is no The answer date is here. -=item * B: - -No dates have been set for this problem at all. - -=item * B: - -The due date has passed, feedback is suppressed, the problem was attempted, and the answer date has not yet arrived. - -=item * B: - -The due date has passed, feedback is suppressed, the problem was attempted, and there is no answer opening date set. - -=item * B: - -The due date has passed, feedback is suppressed, the problem was not attempted, and the answer date has not yet arrived. - -=item * B: - -The due date has passed, feedback is suppressed, the problem was not attempted, and there is no answer opening date set. - =item * B: The information is unknown due to network failure. @@ -5656,10 +5668,6 @@ sub PAST_DUE_NO_ANSWER { return 2; } sub PAST_DUE_ANSWER_LATER { return 3; } sub ANSWER_OPEN { return 4; } sub NOTHING_SET { return 5; } -sub PAST_DUE_ATMPT_ANS { return 6; } -sub PAST_DUE_ATMPT_NOANS { return 7; } -sub PAST_DUE_NO_ATMT_ANS { return 8; } -sub PAST_DUE_NO_ATMT_NOANS { return 9; } sub NETWORK_FAILURE { return 100; } # getDateStatus gets the date status for a given problem part. @@ -5863,26 +5871,6 @@ set. The problem is past due, not considered correct, and an answer date in the future is set. -=item * B: - -The problem is past due, feedback is suppressed, the problem was -attempted and an answer date in the future is set. - -=item * B: - -The problem is past due, feedback is suppressed, the problem was -attempted and no answer date is set. - -=item * B: - -The problem is past due, feedback is suppressed, the problem was -not attempted and an answer date in the future is set. - -=item * B: - -The problem is past due, feedback is suppressed, the problem was -not attempted and no answer date is set. - =item * B: The problem is past due, not correct, and the answer is now available. @@ -5966,18 +5954,7 @@ sub status { if ($completionStatus == CORRECT || $completionStatus == CORRECT_BY_OVERRIDE || $completionStatus == CORRECT_BY_PASSBACK ) { - if ( $suppressFeedback ) { - if ($dateStatus == PAST_DUE_ANSWER_LATER || - $dateStatus == PAST_DUE_NO_ANSWER ) { - if ($dateStatus == PAST_DUE_ANSWER_LATER) { - return PAST_DUE_ATMPT_ANS; - } else { - return PAST_DUE_ATMPT_NOANS; - } - } else { - return ANSWER_SUBMITTED; - } - } + if ( $suppressFeedback ) { return ANSWER_SUBMITTED } my $awarded=$self->awarded($part); if ($awarded < 1 && $awarded > 0) { return PARTIALLY_CORRECT; @@ -5990,7 +5967,7 @@ sub status { # If it's WRONG... and not open if ( ($completionStatus == INCORRECT || $completionStatus == INCORRECT_BY_OVERRIDE || - $completionStatus == INCORRECT_BY_PASSBACK) + $completionStatus == INCORRECT_BY_PASSBACK) && (!$self->opendate($part) || $self->opendate($part) > time()) ) { return INCORRECT; } @@ -6017,23 +5994,7 @@ sub status { if ($dateStatus == PAST_DUE_ANSWER_LATER || $dateStatus == PAST_DUE_NO_ANSWER ) { - if ($suppressFeedback) { - if ($completionStatus == NOT_ATTEMPTED) { - if ($dateStatus == PAST_DUE_ANSWER_LATER) { - return PAST_DUE_NO_ATMT_ANS; - } else { - return PAST_DUE_NO_ATMT_NOANS; - } - } else { - if ($dateStatus == PAST_DUE_ANSWER_LATER) { - return PAST_DUE_ATMPT_ANS; - } else { - return PAST_DUE_ATMPT_NOANS; - } - } - } else { - return $dateStatus; - } + return $suppressFeedback ? ANSWER_SUBMITTED : $dateStatus; } if ($dateStatus == ANSWER_OPEN) { @@ -6149,12 +6110,29 @@ sub check_for_slot { my $reservable = &Apache::lonnet::get_reservable_slots($cnum,$cdom,$env{'user.name'}, $env{'user.domain'}); if (ref($reservable) eq 'HASH') { + my ($map) = &Apache::lonnet::decode_symb($symb); if ((ref($reservable->{'now_order'}) eq 'ARRAY') && (ref($reservable->{'now'}) eq 'HASH')) { foreach my $slot (reverse (@{$reservable->{'now_order'}})) { my $canuse; - if (($reservable->{'now'}{$slot}{'symb'} eq '') || - ($reservable->{'now'}{$slot}{'symb'} eq $symb)) { + if ($reservable->{'now'}{$slot}{'symb'} eq '') { $canuse = 1; + } else { + my %oksymbs; + my @slotsymbs = split(/\s*,\s*/,$reservable->{'now'}{$slot}{'symb'}); + map { $oksymbs{$_} = 1; } @slotsymbs; + if ($oksymbs{$symb}) { + $canuse = 1; + } else { + foreach my $item (@slotsymbs) { + if ($item =~ /\.(page|sequence)$/) { + (undef,undef, my $sloturl) = &Apache::lonnet::decode_symb($item); + if (($map ne '') && ($map eq $sloturl)) { + $canuse = 1; + last; + } + } + } + } } if ($canuse) { if ($checkedin) { @@ -6175,8 +6153,26 @@ sub check_for_slot { if ((ref($reservable->{'future_order'}) eq 'ARRAY') && (ref($reservable->{'future'}) eq 'HASH')) { foreach my $slot (@{$reservable->{'future_order'}}) { my $canuse; - if (($reservable->{'future'}{$slot}{'symb'} eq '') || - ($reservable->{'future'}{$slot}{'symb'} eq $symb)) { + if ($reservable->{'future'}{$slot}{'symb'} eq '') { + $canuse = 1; + } elsif ($reservable->{'future'}{$slot}{'symb'} =~ /,/) { + my %oksymbs; + my @slotsymbs = split(/\s*,\s*/,$reservable->{'future'}{$slot}{'symb'}); + map { $oksymbs{$_} = 1; } @slotsymbs; + if ($oksymbs{$symb}) { + $canuse = 1; + } else { + foreach my $item (@slotsymbs) { + if ($item =~ /\.(page|sequence)$/) { + (undef,undef, my $sloturl) = &Apache::lonnet::decode_symb($item); + if (($map ne '') && ($map eq $sloturl)) { + $canuse = 1; + last; + } + } + } + } + } elsif ($reservable->{'future'}{$slot}{'symb'} eq $symb) { $canuse = 1; } if ($canuse) { @@ -6244,10 +6240,6 @@ my %compositeToSimple = EXCUSED() => CORRECT, PAST_DUE_NO_ANSWER() => INCORRECT, PAST_DUE_ANSWER_LATER() => INCORRECT, - PAST_DUE_ATMPT_ANS() => ATTEMPTED, - PAST_DUE_ATMPT_NOANS() => ATTEMPTED, - PAST_DUE_NO_ATMT_ANS() => CLOSED, - PAST_DUE_NO_ATMT_NOANS() => CLOSED, ANSWER_OPEN() => INCORRECT, OPEN_LATER() => CLOSED, TRIES_LEFT() => OPEN,