Diff for /loncom/interface/lonnavmaps.pm between versions 1.538 and 1.552

version 1.538, 2017/12/21 03:50:57 version 1.552, 2021/07/14 03:58:17
Line 71  processed. Line 71  processed.
   
 Apache::lonnavmaps provides an object model for manipulating this  Apache::lonnavmaps provides an object model for manipulating this
 information in a higher-level fashion than directly manipulating   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-  that aren't necessarily stored in the Big Hash, but are a per-
 resource sort of value, like whether there is any feedback on   resource sort of value, like whether there is any feedback on 
 a given resource.  a given resource.
Line 92  graded for named user(s) or specific COD Line 92  graded for named user(s) or specific COD
 domain, or CODE can be passed as arguments when creating a new   domain, or CODE can be passed as arguments when creating a new 
 navmap object.  navmap object.
   
 Note if you want things like "due dates for another student,  Note if you want things like "due dates for another student",
 you would use the EXT function instead of lonnavmaps.  you would use the EXT function instead of lonnavmaps.
 That said, the lonnavmaps module can still help, because many  That said, the lonnavmaps module can still help, because many
 things, such as the course structure, are usually constant  things, such as the course structure, are usually constant
Line 592  sub getLinkForResource { Line 592  sub getLinkForResource {
     my $anchor;      my $anchor;
     if ($res->is_page()) {      if ($res->is_page()) {
  foreach my $item (@$stack) { if (defined($item)) { $anchor = $item; }  }   foreach my $item (@$stack) { if (defined($item)) { $anchor = $item; }  }
  $anchor=&escape($anchor->shown_symb());   if ($anchor->encrypted() && !&advancedUser()) {
       $anchor='LC_'.$anchor->id();
    } else {
       $anchor=&escape($anchor->shown_symb());
    }
  return ($res->link(),$res->shown_symb(),$anchor);   return ($res->link(),$res->shown_symb(),$anchor);
     }      }
             # in case folder was skipped over as "only sequence"              # in case folder was skipped over as "only sequence"
Line 702  sub getDescription { Line 706  sub getDescription {
     }      }
     if (($status == $res->ANSWER_OPEN || $status == $res->PARTIALLY_CORRECT)      if (($status == $res->ANSWER_OPEN || $status == $res->PARTIALLY_CORRECT)
  && $res->handgrade($part) ne 'yes') {   && $res->handgrade($part) ne 'yes') {
         return &Apache::lonhtmlcommon::direct_parm_link(&mt("Answer available"),$res->symb(),'answerdate,duedate',$part);          my $msg = &mt('Answer available');
           my $parmlist = 'answerdate,duedate';
           if (($res->is_tool) && ($res->is_gradable())) {
               if (($status == $res->PARTIALLY_CORRECT) && ($res->parmval('retrypartial',$part))) {
                   $msg = &mt('Grade received');
                   $parmlist = 'retrypartial';
               } else {
                   $msg = &mt('Grade available');
               }
           }
           return &Apache::lonhtmlcommon::direct_parm_link($msg,$res->symb(),$parmlist,$part);
     }      }
     if ($status == $res->EXCUSED) {      if ($status == $res->EXCUSED) {
         return &mt("Excused by instructor");          return &mt("Excused by instructor");
Line 953  sub render_resource { Line 967  sub render_resource {
         $newBranchText = "<img src='$location/branch.gif' alt=".mt('Branch')." />";          $newBranchText = "<img src='$location/branch.gif' alt=".mt('Branch')." />";
     }      }
   
     # links to open and close the folder  
   
     my $whitespace = $location.'/whitespace_21.gif';      my $whitespace = $location.'/whitespace_21.gif';
     my $linkopen = "<img src='$whitespace' alt='' />"."<a href=\"$link\">";      my ($nomodal,$linkopen,$linkclose);
     my $linkclose = "</a>";      unless ($resource->is_map() || $params->{'resource_nolink'}) {
           $linkopen = "<img src='$whitespace' alt='' />";
           $linkclose = "</a>";
           if (($params->{'modalLink'}) && (!$resource->is_sequence())) {
               if ($link =~m{^(?:|/adm/wrapper)/ext/([^#]+)}) {
                   my $exturl = $1;
                   if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
                       $nomodal = 1;
                   }
               } elsif (($link eq "/public/$LONCAPA::match_domain/$LONCAPA::match_courseid/syllabus") &&
                        ($env{'request.course.id'}) && ($ENV{'SERVER_PORT'} == 443) &&
                        ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
                   $nomodal = 1;
               }
               my $esclink = &js_escape($link);
               if ($nomodal) {
                   $linkopen .= "<a href=\"#\" onclick=\"javascript:window.open('$esclink','resourcepreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1'); return false;\" />";
               } else {
                   $linkopen .= "<a href=\"$link\" onclick=\"javascript:openMyModal('$esclink',600,500,'yes','true'); return false;\">";
               }
           } else {
               $linkopen .= "<a href=\"$link\">";
           }
       }
   
     # Default icon: unknown page      # Default icon: unknown page
     my $icon = "<img class=\"LC_contentImage\" src='$location/unknown.gif' alt='' />";      my $icon = "<img class=\"LC_contentImage\" src='$location/unknown.gif' alt='' />";
Line 1005  sub render_resource { Line 1040  sub render_resource {
                 '&amp;jump=' .                  '&amp;jump=' .
                 &escape($resource->symb()) .                   &escape($resource->symb()) . 
                 "&amp;folderManip=1\">";                  "&amp;folderManip=1\">";
               $linkclose = '</a>';
         } else {          } else {
             # Don't allow users to manipulate folder              # Don't allow users to manipulate folder
             $icon = "navmap.$folderType." . ($nowOpen ? 'closed' : 'open') . '.gif';              $icon = "navmap.$folderType." . ($nowOpen ? 'closed' : 'open') . '.gif';
             $icon = "<img class=\"LC_space\" src='$whitespace' alt='' />"."<img class=\"LC_contentImage\" src='$location/$icon' alt=\"".($nowOpen ? &mt('Open Folder') : &mt('Close Folder')).' '.$title."\" />";              $icon = "<img class=\"LC_space\" src='$whitespace' alt='' />"."<img class=\"LC_contentImage\" src='$location/$icon' alt=\"".($nowOpen ? &mt('Open Folder') : &mt('Close Folder')).' '.$title."\" />";
             if ($params->{'caller'} eq 'sequence') {              if ($params->{'caller'} eq 'sequence') {
                 $linkopen = "<a href=\"$link\">";                  $linkopen = "<a href=\"$link\">";
                   $linkclose = '</a>';
             } else {              } else {
                 $linkopen = "";                  $linkopen = "";
                 $linkclose = "";                  $linkclose = "";
Line 1030  sub render_resource { Line 1066  sub render_resource {
         }          }
         if ($params->{'mapHidden'} || $resource->randomout()) {          if ($params->{'mapHidden'} || $resource->randomout()) {
             $nonLinkedText .= ' <span class="LC_warning">('.&mt('hidden').')</span> ';              $nonLinkedText .= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
           } elsif ($params->{'mapUnlisted'}) {
               $nonLinkedText .= ' <span class="LC_warning">('.&mt('unlisted').')</span> ';
         }          }
     } else {      } else {
         if ($resource->randomout()) {          if ($resource->randomout()) {
             $nonLinkedText .= ' <span class="LC_warning">('.&mt('hidden').')</span> ';              $nonLinkedText .= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
           } elsif (($resource->deeplink($params->{caller}) eq 'absent') ||
                    ($resource->deeplink($params->{caller}) eq 'grades')) {
               $nonLinkedText .= ' <span class="LC_warning">('.&mt('unlisted').')</span> ';
         }          }
     }      }
     if (!$resource->condval()) {      if (!$resource->condval()) {
Line 1084  sub render_resource { Line 1125  sub render_resource {
     }      }
   
     if (!$params->{'resource_nolink'} && !$resource->is_sequence() && !$resource->is_empty_sequence) {      if (!$params->{'resource_nolink'} && !$resource->is_sequence() && !$resource->is_empty_sequence) {
         $result .= "$curMarkerBegin<a href=\"$link\">$title$partLabel</a>$curMarkerEnd$editmapLink$nonLinkedText</td>";          $linkclose = '</a>';
     } else {          if ($params->{'modalLink'}) {
         $result .= "$curMarkerBegin$linkopen$title$partLabel</a>$curMarkerEnd$editmapLink$nonLinkedText</td>";              my $esclink = &js_escape($link);
               if ($nomodal) {
                   $linkopen = "<a href=\"#\" onclick=\"javascript:window.open('$esclink','resourcepreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1'); return false;\" />";
               } else {
                   $linkopen = "<a href=\"$link\" onclick=\"javascript:openMyModal('$esclink',600,500,'yes','true'); return false;\">";
               }
           } else {
               $linkopen = "<a href=\"$link\">";
           }
     }      }
       $result .= "$curMarkerBegin$linkopen$title$partLabel$linkclose$curMarkerEnd$editmapLink$nonLinkedText</td>";
   
     return $result;      return $result;
 }  }
Line 1348  sub render { Line 1398  sub render {
         # Without renaming the filterfunc, the server seems to go into          # Without renaming the filterfunc, the server seems to go into
         # an infinite loop          # an infinite loop
         my $oldFilterFunc = $filterFunc;          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') &&
                                 &$oldFilterFunc($res);};                                  &$oldFilterFunc($res);};
     }      }
   
Line 1442  sub render { Line 1494  sub render {
         if ($args->{'iterator_map'}) {          if ($args->{'iterator_map'}) {
             my $map = $args->{'iterator_map'};              my $map = $args->{'iterator_map'};
             $map = $navmap->getResourceByUrl($map);              $map = $navmap->getResourceByUrl($map);
             my $firstResource = $map->map_start();              if (ref($map)) {
             my $finishResource = $map->map_finish();                  my $firstResource = $map->map_start();
                   my $finishResource = $map->map_finish();
             $args->{'iterator'} = $it = $navmap->getIterator($firstResource, $finishResource, $filterHash, $condition);                  $args->{'iterator'} = $it = $navmap->getIterator($firstResource, $finishResource, $filterHash, $condition);
               } else {
                   return;
               }
         } else {          } else {
             $args->{'iterator'} = $it = $navmap->getIterator(undef, undef, $filterHash, $condition,undef,$args->{'include_top_level_map'});              $args->{'iterator'} = $it = $navmap->getIterator(undef, undef, $filterHash, $condition,undef,$args->{'include_top_level_map'});
         }          }
Line 1725  END Line 1780  END
         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};          $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
     }      }
   
       my $inhibitmenu;
       if ($args->{'modalLink'}) {
           $inhibitmenu = '&amp;inhibitmenu=yes';
       }
   
     while (1) {      while (1) {
  if ($args->{'sort'}) {   if ($args->{'sort'}) {
     $curRes = shift(@resources);      $curRes = shift(@resources);
Line 1760  END Line 1820  END
   
         # If this is an empty sequence and we're filtering them, continue on          # If this is an empty sequence and we're filtering them, continue on
         $args->{'mapHidden'} = 0;          $args->{'mapHidden'} = 0;
           $args->{'mapUnlisted'} = 0;
         if (($curRes->is_map()) && (!$curRes->{DATA}->{HAS_VISIBLE_CHILDREN})) {          if (($curRes->is_map()) && (!$curRes->{DATA}->{HAS_VISIBLE_CHILDREN})) {
             if ($args->{'suppressEmptySequences'}) {              if ($args->{'suppressEmptySequences'}) {
                 next;                  next;
Line 1772  END Line 1833  END
                     } else {                      } else {
                         next;                          next;
                     }                      }
                   } else {
                       my $deeplink = $navmap->get_mapparam(undef,$mapname,"0.deeplink");
                       if ($deeplink =~ /^(absent|grades),/) {
                           if ($userCanSeeHidden) {
                               $args->{'mapUnlisted'} = 1;
                           } else {
                               next;
                           }
                       }
                 }                  }
             }              }
         }          }
Line 1834  END Line 1904  END
     $args->{'condensed'} = 1;      $args->{'condensed'} = 1;
  }   }
             }              }
         }           }
                       # If deep-link parameter is set (and is not set to full) suppress link
           # unless privileged user, or calling context is sequence, and parameter
           # set at map level
           if ((!$curRes->deeplink($args->{'caller'})) ||
               ($curRes->deeplink($args->{'caller'}) =~ /^full,/) || &advancedUser()) {
               $args->{'resource_nolink'} = 0;
           } else {
               $args->{'resource_nolink'} = 1;
           }
   
         # If the multipart problem was condensed, "forget" it was multipart          # If the multipart problem was condensed, "forget" it was multipart
         if (scalar(@parts) == 1) {          if (scalar(@parts) == 1) {
             $args->{'multipart'} = 0;              $args->{'multipart'} = 0;
Line 1861  END Line 1940  END
             if ($env{'request.course.id'}) {              if ($env{'request.course.id'}) {
                 if (($is_ssl) && ($src =~ m{^\Q/public/$cdom/$cnum/syllabus\E($|\?)}) &&                  if (($is_ssl) && ($src =~ m{^\Q/public/$cdom/$cnum/syllabus\E($|\?)}) &&
                     ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {                      ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
                     if ($hostname ne '') {                      unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
                         $src = 'http://'.$hostname.$src;                          if ($hostname ne '') {
                               $src = 'http://'.$hostname.$src;
                           }
                           $src .= ($srcHasQuestion? '&amp;' : '?') . 'usehttp=1';
                           $srcHasQuestion = 1;
                     }                      }
                     $src .= ($srcHasQuestion? '&amp;' : '?') . 'usehttp=1';  
                     $srcHasQuestion = 1;  
                 } elsif (($is_ssl) && ($src =~ m{^\Q/adm/wrapper/ext/\E(?!https:)})) {                  } elsif (($is_ssl) && ($src =~ m{^\Q/adm/wrapper/ext/\E(?!https:)})) {
                     if ($hostname ne '') {                      unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
                         $src = 'http://'.$hostname.$src;                          if ($hostname ne '') {
                               $src = 'http://'.$hostname.$src;
                           }
                           $src .= ($srcHasQuestion? '&amp;' : '?') . 'usehttp=1';
                           $srcHasQuestion = 1;
                     }                      }
                 }                  }
             }              }
Line 1878  END Line 1963  END
     } else {      } else {
         $args->{"resourceLink"} = $src.          $args->{"resourceLink"} = $src.
     ($srcHasQuestion?'&amp;':'?') .      ($srcHasQuestion?'&amp;':'?') .
     'symb=' . &escape($symb).$anchor;      'symb=' . &escape($symb).$inhibitmenu.$anchor;
     }      }
  }   }
         # Now, we've decided what parts to show. Loop through them and          # Now, we've decided what parts to show. Loop through them and
Line 1907  END Line 1992  END
                     $currentJumpDelta) {                      $currentJumpDelta) {
                     # Jam the anchor after the <td> tag;                      # Jam the anchor after the <td> tag;
                     # necessary for valid HTML (which Mozilla requires)                      # necessary for valid HTML (which Mozilla requires)
                     $colHTML =~ s/\>/\>\<a name="curloc" \/\>/;                      $colHTML =~ s/\>/\>\<a name="curloc" \>\<\/a\>/;
                     $displayedJumpMarker = 1;                      $displayedJumpMarker = 1;
                 }                  }
                 $result .= $colHTML . "\n";                  $result .= $colHTML . "\n";
Line 2913  sub recursed_crumbs { Line 2998  sub recursed_crumbs {
         my $pc = $map->map_pc();          my $pc = $map->map_pc();
         next if ((!$pc) || ($pc == 1));          next if ((!$pc) || ($pc == 1));
         push(@links,$map);          push(@links,$map);
         push(@revmapinfo,{'href' => $map->link().'?navmap=1','text' => $map->title(),'no_mt' => 1,});          push(@revmapinfo,{'href' => $env{'request.use_absolute'}.$map->link().'?navmap=1','text' => $map->title(),'no_mt' => 1,});
         $totallength += length($map->title());          $totallength += length($map->title());
     }      }
     my $numlinks = scalar(@links);      my $numlinks = scalar(@links);
Line 2928  sub recursed_crumbs { Line 3013  sub recursed_crumbs {
             foreach my $map (@links) {              foreach my $map (@links) {
                 my $showntitle = &truncate_crumb_text($map->title(),$avg);                  my $showntitle = &truncate_crumb_text($map->title(),$avg);
                 if ($showntitle ne '') {                  if ($showntitle ne '') {
                     push(@revmapinfo,{'href' => $map->link().'?navmap=1','text' => $showntitle,'no_mt' => 1,});                      push(@revmapinfo,{'href' => $env{'request.use_absolute'}.$map->link().'?navmap=1','text' => $showntitle,'no_mt' => 1,});
                 }                  }
             }              }
         }          }
Line 3158  sub get_mapparam { Line 3243  sub get_mapparam {
  if (defined($$courseopt{$courselevelm})) {   if (defined($$courseopt{$courselevelm})) {
     return $$courseopt{$courselevelm};      return $$courseopt{$courselevelm};
  }   }
           if (defined($$courseopt{$courseleveli})) {
               return $$courseopt{$courseleveli};
           }
         unless ($recursed) {          unless ($recursed) {
             @recurseup = $self->recurseup_maps($mapname);              @recurseup = $self->recurseup_maps($mapname);
             $recursed = 1;              $recursed = 1;
Line 3436  sub usedVersion { Line 3524  sub usedVersion {
     return $self->navhash("version_$linkurl");      return $self->navhash("version_$linkurl");
 }  }
   
   sub isFirstResource {
       my $self = shift;
       my $map = shift;
       my $symb = shift;
       return unless (ref($map));
       my $isfirst;
       my $firstResource = $map->map_start();
       if (ref($firstResource)) {
           if ((!$firstResource->is_map()) && ($firstResource->src() ne ''))  {
               if ($firstResource->symb() eq $symb) {
                   $isfirst = 1;
               } else {
                   $isfirst = 0;
               }
           } else {
               my $it = $self->getIterator($firstResource,undef,undef,1);
               while ( my $res=$it->next()) {
                   if ((ref($res)) && ($res->src() ne '') && (!$res->is_map())) {
                       if ($res->symb() eq $symb) {
                           $isfirst = 1;
                       } else {
                           $isfirst = 0;
                       }
                       last;
                   }
               }
           }
       }
       return $isfirst;
   }
   
   sub isLastResource {
       my $self = shift;
       my $map = shift;
       my $symb = shift;
       return unless (ref($map));
       my $islast;
       my $lastResource = $map->map_finish();
       if (ref($lastResource)) {
           if ((!$lastResource->is_map()) && ($lastResource->src() ne ''))  {
               if ($lastResource->symb() eq $symb) {
                   $islast = 1;
               } else {
                   $islast = 0;
               }
           } else {
               my $currRes = $self->getBySymb($symb);
               if (ref($currRes)) {
                   my $it = $self->getIterator($currRes,undef,undef,1);
                   while ( my $res=$it->next()) {
                       if ((ref($res)) && ($res->src() ne '') && (!$res->is_map())) {
                           if ($res->symb() eq $symb) {
                               $islast = 1;
                           } else {
                               $islast = 0;
                           }
                           last;
                       }
                   }
               }
           }
       }
       return $islast;
   }
   
 1;  1;
   
 package Apache::lonnavmaps::iterator;  package Apache::lonnavmaps::iterator;
Line 3871  sub next { Line 4024  sub next {
     # That ends the main iterator logic. Now, do we want to recurse      # That ends the main iterator logic. Now, do we want to recurse
     # down this map (if this resource is a map)?      # down this map (if this resource is a map)?
     if ( ($self->{HERE}->is_sequence() || (!$closeAllPages && $self->{HERE}->is_page())) &&      if ( ($self->{HERE}->is_sequence() || (!$closeAllPages && $self->{HERE}->is_page())) &&
         (defined($self->{FILTER}->{$self->{HERE}->map_pc()}) xor $self->{CONDITION})) {          (defined($self->{FILTER}->{$self->{HERE}->map_pc()}) xor $self->{CONDITION}) &&
           ($env{'request.role.adv'} || !$self->{HERE}->randomout())) {
         $self->{RECURSIVE_ITERATOR_FLAG} = 1;          $self->{RECURSIVE_ITERATOR_FLAG} = 1;
         my $firstResource = $self->{HERE}->map_start();          my $firstResource = $self->{HERE}->map_start();
         my $finishResource = $self->{HERE}->map_finish();          my $finishResource = $self->{HERE}->map_finish();
Line 4582  sub is_task { Line 4736  sub is_task {
   
 sub is_empty_sequence {  sub is_empty_sequence {
     my $self=shift;      my $self=shift;
     my $src = $self->src();  
     return !$self->is_page() && $self->navHash("is_map_", 1) && !$self->navHash("map_type_" . $self->map_pc());      return !$self->is_page() && $self->navHash("is_map_", 1) && !$self->navHash("map_type_" . $self->map_pc());
 }  }
   
Line 5002  sub slot_control { Line 5155  sub slot_control {
     my $available = $self->parmval("available", $part);       my $available = $self->parmval("available", $part); 
     return ($useslots,$availablestudent,$available);      return ($useslots,$availablestudent,$available);
 }  }
   sub deeplink {
       my ($self,$caller) = @_;
       my $value = $self->parmval("deeplink");
       if ($value) {
           my @deeplink = split(/,/,$value);
           if ($caller eq 'sequence') {
               if ($deeplink[1] ne 'res') {
                   return;
               }
           }
           return $deeplink[0];
       }
       return;
   }
   
 # Multiple things need this  # Multiple things need this
 sub getReturnHash {  sub getReturnHash {

Removed from v.1.538  
changed lines
  Added in v.1.552


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>