Diff for /loncom/interface/lonnavmaps.pm between versions 1.228 and 1.258

version 1.228, 2003/09/17 17:30:41 version 1.258, 2004/04/13 15:49:42
Line 25 Line 25
 #  #
 # http://www.lon-capa.org/  # http://www.lon-capa.org/
 #  #
 # (Page Handler  ###
 #  
 # (TeX Content Handler  
 #  
 # 05/29/00,05/30 Gerd Kortemeyer)  
 # 08/30,08/31,09/06,09/14,09/15,09/16,09/19,09/20,09/21,09/23,  
 # 10/02,10/10,10/14,10/16,10/18,10/19,10/31,11/6,11/14,11/16 Gerd Kortemeyer)  
 #  
 # 3/1/1,6/1,17/1,29/1,30/1,2/8,9/21,9/24,9/25 Gerd Kortemeyer  
 # YEAR=2002  
 # 1/1 Gerd Kortemeyer  
 # Oct-Nov Jeremy Bowers  
 # YEAR=2003  
 # Jeremy Bowers ... lots of days  
   
 package Apache::lonnavmaps;  package Apache::lonnavmaps;
   
Line 46  use strict; Line 33  use strict;
 use Apache::Constants qw(:common :http);  use Apache::Constants qw(:common :http);
 use Apache::loncommon();  use Apache::loncommon();
 use Apache::lonmenu();  use Apache::lonmenu();
   use Apache::lonlocal;
 use POSIX qw (floor strftime);  use POSIX qw (floor strftime);
 use Data::Dumper; # for debugging, not always used  use Data::Dumper; # for debugging, not always used
   
Line 106  sub real_handler { Line 94  sub real_handler {
     # Handle header-only request      # Handle header-only request
     if ($r->header_only) {      if ($r->header_only) {
         if ($ENV{'browser.mathml'}) {          if ($ENV{'browser.mathml'}) {
             $r->content_type('text/xml');              &Apache::loncommon::content_type($r,'text/xml');
         } else {          } else {
             $r->content_type('text/html');              &Apache::loncommon::content_type($r,'text/html');
         }          }
         $r->send_http_header;          $r->send_http_header;
         return OK;          return OK;
Line 116  sub real_handler { Line 104  sub real_handler {
   
     # Send header, don't cache this page      # Send header, don't cache this page
     if ($ENV{'browser.mathml'}) {      if ($ENV{'browser.mathml'}) {
         $r->content_type('text/xml');          &Apache::loncommon::content_type($r,'text/xml');
     } else {      } else {
         $r->content_type('text/html');          &Apache::loncommon::content_type($r,'text/html');
     }      }
     &Apache::loncommon::no_cache($r);      &Apache::loncommon::no_cache($r);
     $r->send_http_header;      $r->send_http_header;
Line 126  sub real_handler { Line 114  sub real_handler {
     # Create the nav map      # Create the nav map
     my $navmap = Apache::lonnavmaps::navmap->new();      my $navmap = Apache::lonnavmaps::navmap->new();
   
   
     if (!defined($navmap)) {      if (!defined($navmap)) {
         my $requrl = $r->uri;          my $requrl = $r->uri;
         $ENV{'user.error.msg'} = "$requrl:bre:0:0:Course not initialized";          $ENV{'user.error.msg'} = "$requrl:bre:0:0:Course not initialized";
Line 134  sub real_handler { Line 121  sub real_handler {
     }      }
   
     $r->print("<html><head>\n");      $r->print("<html><head>\n");
     $r->print("<title>Navigate Course Contents</title>");      $r->print("<title>".&mt('Navigate Course Contents')."</title>");
 # ------------------------------------------------------------ Get query string  # ------------------------------------------------------------ Get query string
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['register']);      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['register']);
           
Line 221  sub real_handler { Line 208  sub real_handler {
         }          }
     } else {      } else {
         $r->print("<a href='navmaps?jumpToFirstHomework'>" .          $r->print("<a href='navmaps?jumpToFirstHomework'>" .
                   "Go To My First Homework Problem</a>&nbsp;&nbsp;&nbsp;&nbsp;");         &mt("Go To My First Homework Problem")."</a>&nbsp;&nbsp;&nbsp;&nbsp;");
     }      }
   
     my $suppressEmptySequences = 0;      my $suppressEmptySequences = 0;
Line 236  sub real_handler { Line 223  sub real_handler {
         $filterFunc = sub { my $res = shift;           $filterFunc = sub { my $res = shift; 
                             return $res->completable() || $res->is_map();                              return $res->completable() || $res->is_map();
                         };                          };
         $r->print("<p><font size='+2'>Uncompleted Homework</font></p>");          $r->print("<p><font size='+2'>".&mt("Uncompleted Homework")."</font></p>");
         $ENV{'form.filter'} = '';          $ENV{'form.filter'} = '';
         $ENV{'form.condition'} = 1;          $ENV{'form.condition'} = 1;
  $resource_no_folder_link = 1;   $resource_no_folder_link = 1;
     } else {      } else {
         $r->print("<a href='navmaps?showOnlyHomework'>" .          $r->print("<a href='navmaps?showOnlyHomework'>" .
                   "Show Only Uncompleted Homework</a>&nbsp;&nbsp;&nbsp;&nbsp;");         &mt("Show Only Uncompleted Homework")."</a>&nbsp;&nbsp;&nbsp;&nbsp;");
     }      }
   
     # renderer call      # renderer call
Line 261  sub real_handler { Line 248  sub real_handler {
     # user knows there was no error.      # user knows there was no error.
     if ($renderArgs->{'counter'} == 0) {      if ($renderArgs->{'counter'} == 0) {
         if ($showOnlyHomework) {          if ($showOnlyHomework) {
             $r->print("<p><font size='+1'>All homework is currently completed.</font></p>");              $r->print("<p><font size='+1'>".&mt("All homework is currently completed").".</font></p>");
         } else { # both jumpToFirstHomework and normal use the same: course must be empty          } else { # both jumpToFirstHomework and normal use the same: course must be empty
             $r->print("<p><font size='+1'>This course is empty.</font></p>");              $r->print("<p><font size='+1'>This course is empty.</font></p>");
         }          }
Line 303  sub getLinkForResource { Line 290  sub getLinkForResource {
   
     # Check to see if there are any pages in the stack      # Check to see if there are any pages in the stack
     foreach $res (@$stack) {      foreach $res (@$stack) {
         if (defined($res) && $res->is_page()) {          if (defined($res)) {
             return $res->src();      if ($res->is_page()) {
    return $res->src();
       }
               # in case folder was skipped over as "only sequence"
       my ($map,$id,$src)=&Apache::lonnet::decode_symb($res->symb());
       if ($map=~/\.page$/) {
    return &Apache::lonnet::clutter($map).'#'.
       &Apache::lonnet::escape(&Apache::lonnet::declutter($src));
       }
         }          }
     }      }
   
Line 319  sub getLinkForResource { Line 314  sub getLinkForResource {
     return $res->src();      return $res->src();
 }  }
   
 # Convenience function: This seperates the logic of how to create  # Convenience function: This separates the logic of how to create
 # the problem text strings ("Due: DATE", "Open: DATE", "Not yet assigned",  # the problem text strings ("Due: DATE", "Open: DATE", "Not yet assigned",
 # etc.) into a seperate function. It takes a resource object as the  # etc.) into a separate function. It takes a resource object as the
 # first parameter, and the part number of the resource as the second.  # first parameter, and the part number of the resource as the second.
 # It's basically a big switch statement on the status of the resource.  # It's basically a big switch statement on the status of the resource.
   
Line 331  sub getDescription { Line 326  sub getDescription {
     my $status = $res->status($part);      my $status = $res->status($part);
   
     if ($status == $res->NETWORK_FAILURE) {       if ($status == $res->NETWORK_FAILURE) { 
         return "Having technical difficulties; please check status later";           return &mt("Having technical difficulties; please check status later"); 
     }      }
     if ($status == $res->NOTHING_SET) {      if ($status == $res->NOTHING_SET) {
         return "Not currently assigned.";          return &mt("Not currently assigned.");
     }      }
     if ($status == $res->OPEN_LATER) {      if ($status == $res->OPEN_LATER) {
         return "Open " . timeToHumanString($res->opendate($part));          return "Open " . timeToHumanString($res->opendate($part));
     }      }
     if ($status == $res->OPEN) {      if ($status == $res->OPEN) {
         if ($res->duedate($part)) {          if ($res->duedate($part)) {
             return "Due " . timeToHumanString($res->duedate($part));              return &mt("Due")."  " .timeToHumanString($res->duedate($part));
         } else {          } else {
             return "Open, no due date";              return &mt("Open, no due date");
         }          }
     }      }
     if ($status == $res->PAST_DUE_ANSWER_LATER) {      if ($status == $res->PAST_DUE_ANSWER_LATER) {
         return "Answer open " . timeToHumanString($res->answerdate($part));          return &mt("Answer open")." " . timeToHumanString($res->answerdate($part));
     }      }
     if ($status == $res->PAST_DUE_NO_ANSWER) {      if ($status == $res->PAST_DUE_NO_ANSWER) {
         return "Was due " . timeToHumanString($res->duedate($part));          return &mt("Was due")." " . timeToHumanString($res->duedate($part));
     }      }
     if ($status == $res->ANSWER_OPEN) {      if ($status == $res->ANSWER_OPEN) {
         return "Answer available";          return &mt("Answer available");
     }      }
     if ($status == $res->EXCUSED) {      if ($status == $res->EXCUSED) {
         return "Excused by instructor";          return &mt("Excused by instructor");
     }      }
     if ($status == $res->ATTEMPTED) {      if ($status == $res->ATTEMPTED) {
         return "Answer submitted, not yet graded.";          return &mt("Answer submitted, not yet graded");
     }      }
     if ($status == $res->TRIES_LEFT) {      if ($status == $res->TRIES_LEFT) {
         my $tries = $res->tries($part);          my $tries = $res->tries($part);
Line 371  sub getDescription { Line 366  sub getDescription {
                 $triesString = "<b>$triesString</b>";                  $triesString = "<b>$triesString</b>";
             }              }
         }          }
         if ($res->duedate()) {          if ($res->duedate($part)) {
             return "Due " . timeToHumanString($res->duedate($part)) .              return &mt("Due")." " . timeToHumanString($res->duedate($part)) .
                 " $triesString";                  " $triesString";
         } else {          } else {
             return "No due date $triesString";              return &mt("No due date")." $triesString";
         }          }
     }      }
     if ($status == $res->ANSWER_SUBMITTED) {      if ($status == $res->ANSWER_SUBMITTED) {
         return 'Answer submitted';          return &mt('Answer submitted');
     }      }
 }  }
   
 # Convenience function, so others can use it: Is the problem due in less then  # Convenience function, so others can use it: Is the problem due in less then
 # 24 hours, and still can be done?  # 24 hours, and still can be done?
   
 sub dueInLessThen24Hours {  sub dueInLessThan24Hours {
     my $res = shift;      my $res = shift;
     my $part = shift;      my $part = shift;
     my $status = $res->status($part);      my $status = $res->status($part);
   
     return ($status == $res->OPEN() ||      return ($status == $res->OPEN() ||
             $status == $res->TRIES_LEFT()) &&              $status == $res->TRIES_LEFT()) &&
            $res->duedate() && $res->duedate() < time()+(24*60*60) &&      $res->duedate($part) && $res->duedate($part) < time()+(24*60*60) &&
            $res->duedate() > time();      $res->duedate($part) > time();
 }  }
   
 # Convenience function, so others can use it: Is there only one try remaining for the  # Convenience function, so others can use it: Is there only one try remaining for the
Line 406  sub lastTry { Line 401  sub lastTry {
     my $tries = $res->tries($part);      my $tries = $res->tries($part);
     my $maxtries = $res->maxtries($part);      my $maxtries = $res->maxtries($part);
     return $tries && $maxtries && $maxtries > 1 &&      return $tries && $maxtries && $maxtries > 1 &&
         $maxtries - $tries == 1 && $res->duedate() &&          $maxtries - $tries == 1 && $res->duedate($part) &&
         $res->duedate() > time();          $res->duedate($part) > time();
 }  }
   
 # This puts a human-readable name on the ENV variable.  # This puts a human-readable name on the ENV variable.
Line 429  sub timeToHumanString { Line 424  sub timeToHumanString {
     my ($time) = @_;      my ($time) = @_;
     # zero, '0' and blank are bad times      # zero, '0' and blank are bad times
     if (!$time) {      if (!$time) {
         return 'never';          return &mt('never');
     }      }
       unless (&Apache::lonlocal::current_language()=~/^en/) {
    return &Apache::lonlocal::locallocaltime($time);
       } 
     my $now = time();      my $now = time();
   
     my @time = localtime($time);      my @time = localtime($time);
Line 499  sub timeToHumanString { Line 496  sub timeToHumanString {
         # HH:MM          # HH:MM
         if ( $delta < $day * 5 ) {          if ( $delta < $day * 5 ) {
             my $timeStr = strftime("%A, %b %e at %I:%M %P", localtime($time));              my $timeStr = strftime("%A, %b %e at %I:%M %P", localtime($time));
             $timeStr =~ s/12:00 am/midnight/;              $timeStr =~ s/12:00 am/00:00/;
             $timeStr =~ s/12:00 pm/noon/;              $timeStr =~ s/12:00 pm/noon/;
             return ($inPast ? "last " : "next ") .              return ($inPast ? "last " : "next ") .
                 $timeStr;                  $timeStr;
Line 509  sub timeToHumanString { Line 506  sub timeToHumanString {
         if ( $time[5] == $now[5]) {          if ( $time[5] == $now[5]) {
             # Return on Month Day, HH:MM meridian              # Return on Month Day, HH:MM meridian
             my $timeStr = strftime("on %A, %b %e at %I:%M %P", localtime($time));              my $timeStr = strftime("on %A, %b %e at %I:%M %P", localtime($time));
             $timeStr =~ s/12:00 am/midnight/;              $timeStr =~ s/12:00 am/00:00/;
             $timeStr =~ s/12:00 pm/noon/;              $timeStr =~ s/12:00 pm/noon/;
             return $timeStr;              return $timeStr;
         }          }
   
         # Not this year, so show the year          # Not this year, so show the year
         my $timeStr = strftime("on %A, %b %e %G at %I:%M %P", localtime($time));          my $timeStr = strftime("on %A, %b %e %G at %I:%M %P", localtime($time));
         $timeStr =~ s/12:00 am/midnight/;          $timeStr =~ s/12:00 am/00:00/;
         $timeStr =~ s/12:00 pm/noon/;          $timeStr =~ s/12:00 pm/noon/;
         return $timeStr;          return $timeStr;
     }      }
Line 867  sub render_resource { Line 864  sub render_resource {
     my $filter = $it->{FILTER};      my $filter = $it->{FILTER};
   
     my $title = $resource->compTitle();      my $title = $resource->compTitle();
     if ($src =~ /^\/uploaded\//) {  
         $nonLinkedText=$title;  
         $title = '';  
     }  
     my $partLabel = "";      my $partLabel = "";
     my $newBranchText = "";      my $newBranchText = "";
           
Line 893  sub render_resource { Line 887  sub render_resource {
             $icon = $params->{'indentString'};              $icon = $params->{'indentString'};
         }          }
     } else {      } else {
  my $curfext= (split (/\./,$resource->src))[-1];   $icon = "<img src='".&Apache::loncommon::icon($resource->src).
  my $embstyle = &Apache::loncommon::fileembstyle($curfext);      "' alt='' border='0' />";
  # The unless conditional that follows is a bit of overkill  
  if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {  
     $icon = "<img src='/adm/lonIcons/$curfext.gif' alt='' border='0' />";  
  }  
     }      }
   
     # Display the correct map icon to open or shut map      # Display the correct map icon to open or shut map
Line 968  sub render_resource { Line 958  sub render_resource {
   
     if ($resource->is_problem() && $part ne '0' &&       if ($resource->is_problem() && $part ne '0' && 
         !$params->{'condensed'}) {          !$params->{'condensed'}) {
         $partLabel = " (Part $part)";   my $displaypart=&Apache::lonnet::EXT('resource.'.$part.'.display',
        $resource->symb());
    unless ($displaypart) { $displaypart=$part; }
           $partLabel = " (Part: $displaypart)";
    $link.='#'.&Apache::lonnet::escape($part);
         $title = "";          $title = "";
     }      }
   
Line 976  sub render_resource { Line 970  sub render_resource {
         $nonLinkedText .= ' (' . $resource->countParts() . ' parts)';          $nonLinkedText .= ' (' . $resource->countParts() . ' parts)';
     }      }
   
     if (!$params->{'resource_nolink'} && $src !~ /^\/uploaded\// &&      if (!$params->{'resource_nolink'} && !$resource->is_sequence()) {
  !$resource->is_sequence()) {  
         $result .= "  $curMarkerBegin<a href='$link'>$title$partLabel</a>$curMarkerEnd $nonLinkedText</td>";          $result .= "  $curMarkerBegin<a href='$link'>$title$partLabel</a>$curMarkerEnd $nonLinkedText</td>";
     } else {      } else {
         $result .= "  $curMarkerBegin$title$partLabel$curMarkerEnd $nonLinkedText</td>";          $result .= "  $curMarkerBegin$title$partLabel$curMarkerEnd $nonLinkedText</td>";
Line 1014  sub render_communication_status { Line 1007  sub render_communication_status {
           
     if ($resource->getErrors()) {      if ($resource->getErrors()) {
         my $errors = $resource->getErrors();          my $errors = $resource->getErrors();
           my $errorcount = 0;
         foreach (split(/,/, $errors)) {          foreach (split(/,/, $errors)) {
               last if ($errorcount>=10); # Only output 10 bombs maximum
             if ($_) {              if ($_) {
                   $errorcount++;
                 $errorHTML .= '&nbsp;<a href="/adm/email?display='                  $errorHTML .= '&nbsp;<a href="/adm/email?display='
                     . &Apache::lonnet::escape($_) . '">'                      . &Apache::lonnet::escape($_) . '">'
                     . '<img src="/adm/lonMisc/bomb.gif" '                      . '<img src="/adm/lonMisc/bomb.gif" '
Line 1067  sub render_long_status { Line 1063  sub render_long_status {
     if ($resource->is_problem()) {      if ($resource->is_problem()) {
         $color = $colormap{$resource->status};          $color = $colormap{$resource->status};
                   
         if (dueInLessThen24Hours($resource, $part) ||          if (dueInLessThan24Hours($resource, $part) ||
             lastTry($resource, $part)) {              lastTry($resource, $part)) {
             $color = $hurryUpColor;              $color = $hurryUpColor;
         }          }
Line 1119  my @statuses = ($resObj->CORRECT, $resOb Line 1115  my @statuses = ($resObj->CORRECT, $resOb
 use Data::Dumper;  use Data::Dumper;
 sub render_parts_summary_status {  sub render_parts_summary_status {
     my ($resource, $part, $params) = @_;      my ($resource, $part, $params) = @_;
     if (!$resource->is_problem()) { return '<td></td>'; }      if (!$resource->is_problem() && !$resource->contains_problem) { return '<td></td>'; }
     if ($params->{showParts}) {       if ($params->{showParts}) { 
  return '<td></td>';   return '<td></td>';
     }      }
   
     my $td = "<td align='right'>\n";      my $td = "<td align='right'>\n";
     my $endtd = "</td>\n";      my $endtd = "</td>\n";
       my @probs;
   
     # If there is a single part, just show the simple status      if ($resource->contains_problem) {
     if ($resource->singlepart()) {   @probs=$resource->retrieveResources($resource,sub { $_[0]->is_problem() },1,0);
  my $status = $resource->simpleStatus('0');      } else {
  return $td . "<font color='" . $statusColors{$status} . "'>"   @probs=($resource);
     . $statusStrings{$status} . "</font>" . $endtd;      }
     }      my $return;
       my %overallstatus;
     # Now we can be sure the $part doesn't really matter.      my $totalParts;
     my $statusCount = $resource->simpleStatusCount();      foreach my $resource (@probs) {
     my @counts;   # If there is a single part, just show the simple status
     foreach my $status(@statuses) {   if ($resource->singlepart()) {
  # decouple display order from the simpleStatusCount order      my $status = $resource->simpleStatus(${$resource->parts}[0]);
  my $slot = Apache::lonnavmaps::resource::statusToSlot($status);      $overallstatus{$status}++;
  if ($statusCount->[$slot]) {      $totalParts++;
     push @counts, "<font color='" . $statusColors{$status} .      next;
  "'>" . $statusCount->[$slot] . ' '   }
    # Now we can be sure the $part doesn't really matter.
    my $statusCount = $resource->simpleStatusCount();
    my @counts;
    foreach my $status (@statuses) {
       # decouple display order from the simpleStatusCount order
       my $slot = Apache::lonnavmaps::resource::statusToSlot($status);
       if ($statusCount->[$slot]) {
    $overallstatus{$status}+=$statusCount->[$slot];
    $totalParts+=$statusCount->[$slot];
       }
    }
       }
       $return.= $td . $totalParts . ' parts: ';
       foreach my $status (@statuses) {
    if ($overallstatus{$status}) {
       $return.="<font color='" . $statusColors{$status} .
    "'>" . $overallstatus{$status} . ' '
  . $statusStrings{$status} . "</font>";   . $statusStrings{$status} . "</font>";
  }   }
     }      }
       $return.= $endtd;
     return $td . $resource->countParts() . ' parts: ' . join (', ', @counts) . $endtd;      return $return;
 }  }
   
 my @preparedColumns = (\&render_resource, \&render_communication_status,  my @preparedColumns = (\&render_resource, \&render_communication_status,
Line 1182  sub render { Line 1196  sub render {
     my $jump = $args->{'jump'};      my $jump = $args->{'jump'};
     my $here = $args->{'here'};      my $here = $args->{'here'};
     my $suppressNavmap = setDefault($args->{'suppressNavmap'}, 0);      my $suppressNavmap = setDefault($args->{'suppressNavmap'}, 0);
       my $closeAllPages = setDefault($args->{'closeAllPages'}, 0);
     my $currentJumpDelta = 2; # change this to change how many resources are displayed      my $currentJumpDelta = 2; # change this to change how many resources are displayed
                              # before the current resource when using #current                               # before the current resource when using #current
   
Line 1290  sub render { Line 1305  sub render {
             $args->{'iterator'} = $it = $navmap->getIterator(undef, undef, $filterHash, $condition);              $args->{'iterator'} = $it = $navmap->getIterator(undef, undef, $filterHash, $condition);
         }          }
     }      }
       
     # (re-)Locate the jump point, if any      # (re-)Locate the jump point, if any
     # Note this does not take filtering or hidden into account... need      # Note this does not take filtering or hidden into account... need
     # to be fixed?      # to be fixed?
Line 1328  sub render { Line 1343  sub render {
         $result.='<tr><td align="right" valign="bottom">Key:&nbsp;&nbsp;</td>';          $result.='<tr><td align="right" valign="bottom">Key:&nbsp;&nbsp;</td>';
         if ($navmap->{LAST_CHECK}) {          if ($navmap->{LAST_CHECK}) {
             $result .=               $result .= 
                 '<img src="/adm/lonMisc/chat.gif"> New discussion since '.                  '<img src="/adm/lonMisc/chat.gif"> '.&mt('New discussion since').' '.
                 strftime("%A, %b %e at %I:%M %P", localtime($navmap->{LAST_CHECK})).                  strftime("%A, %b %e at %I:%M %P", localtime($navmap->{LAST_CHECK})).
                 '</td><td align="center" valign="bottom">&nbsp;&nbsp;'.                  '</td><td align="center" valign="bottom">&nbsp;&nbsp;'.
                 '<img src="/adm/lonMisc/feedback.gif"> New message (click to open)<p>'.                  '<img src="/adm/lonMisc/feedback.gif"> '.&mt('New message (click to open)').'<p>'.
                 '</td>';                   '</td>'; 
         } else {          } else {
             $result .= '<td align="center" valign="bottom">&nbsp;&nbsp;'.              $result .= '<td align="center" valign="bottom">&nbsp;&nbsp;'.
                 '<img src="/adm/lonMisc/chat.gif"> Discussions</td><td align="center" valign="bottom">'.                  '<img src="/adm/lonMisc/chat.gif"> '.&mt('Discussions').'</td><td align="center" valign="bottom">'.
                 '&nbsp;&nbsp;<img src="/adm/lonMisc/feedback.gif"> New message (click to open)'.                  '&nbsp;&nbsp;<img src="/adm/lonMisc/feedback.gif"> '.&mt('New message (click to open)').
                 '</td>';                   '</td>'; 
         }          }
   
Line 1347  sub render { Line 1362  sub render {
         if ($condition) {          if ($condition) {
             $result.="<a href=\"navmaps?condition=0&filter=&$queryString" .              $result.="<a href=\"navmaps?condition=0&filter=&$queryString" .
                 "&here=" . Apache::lonnet::escape($here) .                  "&here=" . Apache::lonnet::escape($here) .
                 "\">Close All Folders</a>";                  "\">".&mt('Close All Folders')."</a>";
         } else {          } else {
             $result.="<a href=\"navmaps?condition=1&filter=&$queryString" .              $result.="<a href=\"navmaps?condition=1&filter=&$queryString" .
                 "&here=" . Apache::lonnet::escape($here) .                   "&here=" . Apache::lonnet::escape($here) . 
                 "\">Open All Folders</a>";                  "\">".&mt('Open All Folders')."</a>";
         }          }
         $result .= "<br /><br />\n";          $result .= "<br /><br />\n";
     }          }    
Line 1427  sub render { Line 1442  sub render {
     $args->{'here'} = $here;      $args->{'here'} = $here;
   
     $args->{'indentLevel'} = -1; # first BEGIN_MAP takes this to 0      $args->{'indentLevel'} = -1; # first BEGIN_MAP takes this to 0
     while ($curRes = $it->next()) {      while ($curRes = $it->next($closeAllPages)) {
         # Maintain indentation level.          # Maintain indentation level.
         if ($curRes == $it->BEGIN_MAP() ||          if ($curRes == $it->BEGIN_MAP() ||
             $curRes == $it->BEGIN_BRANCH() ) {              $curRes == $it->BEGIN_BRANCH() ) {
Line 1543  sub render { Line 1558  sub render {
             my $filter = $it->{FILTER};              my $filter = $it->{FILTER};
             my $stack = $it->getStack();              my $stack = $it->getStack();
             my $src = getLinkForResource($stack);              my $src = getLinkForResource($stack);
                           my $anchor='';
               if ($src=~s/(\#.*$)//) {
    $anchor=$1;
       }
             my $srcHasQuestion = $src =~ /\?/;              my $srcHasQuestion = $src =~ /\?/;
             $args->{"resourceLink"} = $src.              $args->{"resourceLink"} = $src.
                 ($srcHasQuestion?'&':'?') .                  ($srcHasQuestion?'&':'?') .
                 'symb=' . &Apache::lonnet::escape($curRes->symb());                  'symb=' . &Apache::lonnet::escape($curRes->symb()).
    $anchor;
                           
             # Now, display each column.              # Now, display each column.
             foreach my $col (@$cols) {              foreach my $col (@$cols) {
Line 1584  sub render { Line 1603  sub render {
     # If we have the connection, make sure the user is still connected      # If we have the connection, make sure the user is still connected
     my $c = $r->connection;      my $c = $r->connection;
     if ($c->aborted()) {      if ($c->aborted()) {
  Apache::lonnet::logthis("navmaps aborted");  
  # Who cares what we do, nobody will see it anyhow.   # Who cares what we do, nobody will see it anyhow.
  return '';   return '';
     }      }
Line 1599  sub render { Line 1617  sub render {
     # it's quite likely this might fix other browsers, too, and       # it's quite likely this might fix other browsers, too, and 
     # certainly won't hurt anything.      # certainly won't hurt anything.
     if ($displayedJumpMarker) {      if ($displayedJumpMarker) {
         $result .= "<script>setTimeout(\"location += '#curloc';\", 0)</script>\n";          $result .= "
   <script>
   if (location.href.indexOf('#curloc')==-1) {
       setTimeout(\"location += '#curloc';\", 0)
   }
   </script>";
     }      }
   
     $result .= "</table>";      $result .= "</table>";
Line 2101  sub parmval_real { Line 2124  sub parmval_real {
   
 # ----------------------------------------------------- fourth , check default  # ----------------------------------------------------- fourth , check default
   
     my $default=&Apache::lonnet::metadata($fn,$rwhat.'.default');      my $meta_rwhat=$rwhat;
       $meta_rwhat=~s/\./_/g;
       my $default=&Apache::lonnet::metadata($fn,$meta_rwhat);
       if (defined($default)) { return $default}
       $default=&Apache::lonnet::metadata($fn,'parameter_'.$meta_rwhat);
     if (defined($default)) { return $default}      if (defined($default)) { return $default}
   
 # --------------------------------------------------- fifth , cascade up parts  # --------------------------------------------------- fifth , cascade up parts
Line 2156  want to know is if I<any> resources matc Line 2183  want to know is if I<any> resources matc
 parameter will allow you to avoid potentially expensive enumeration of  parameter will allow you to avoid potentially expensive enumeration of
 all matching resources.  all matching resources.
   
 =item * B<hasResources>(map, filterFunc, recursive):  =item * B<hasResource>(map, filterFunc, recursive):
   
 Convience method for  Convience method for
   
Line 2344  consisting entirely of empty resources e Line 2371  consisting entirely of empty resources e
 ending resource, will cause a lot of BRANCH_STARTs and BRANCH_ENDs,  ending resource, will cause a lot of BRANCH_STARTs and BRANCH_ENDs,
 but only one resource will be returned.  but only one resource will be returned.
   
   =back
   
 =head2 Normal Usage  =head2 Normal Usage
   
 Normal usage of the iterator object is to do the following:  Normal usage of the iterator object is to do the following:
Line 2364  the depth of the iterator to see when it Line 2393  the depth of the iterator to see when it
 code. It is difficult to get right and harder to understand then  code. It is difficult to get right and harder to understand then
 this. They should be migrated to this new style.  this. They should be migrated to this new style.
   
 =back  
   
 =cut  =cut
   
 # Here are the tokens for the iterator:  # Here are the tokens for the iterator:
Line 2502  sub new { Line 2529  sub new {
     }      }
   
     # Check: Was this only one resource, a map?      # Check: Was this only one resource, a map?
     if ($resourceCount == 1 && $resource->is_map() && !$self->{FORCE_TOP}) {       if ($resourceCount == 1 && $resource->is_sequence() && !$self->{FORCE_TOP}) { 
         my $firstResource = $resource->map_start();          my $firstResource = $resource->map_start();
         my $finishResource = $resource->map_finish();          my $finishResource = $resource->map_finish();
         return           return 
Line 2535  sub new { Line 2562  sub new {
   
 sub next {  sub next {
     my $self = shift;      my $self = shift;
       my $closeAllPages=shift;
     if ($self->{FINISHED}) {      if ($self->{FINISHED}) {
  return END_ITERATOR();   return END_ITERATOR();
     }      }
Line 2549  sub next { Line 2576  sub next {
   
     if ($self->{RECURSIVE_ITERATOR_FLAG}) {      if ($self->{RECURSIVE_ITERATOR_FLAG}) {
         # grab the next from the recursive iterator           # grab the next from the recursive iterator 
         my $next = $self->{RECURSIVE_ITERATOR}->next();          my $next = $self->{RECURSIVE_ITERATOR}->next($closeAllPages);
   
         # is it a begin or end map? If so, update the depth          # is it a begin or end map? If so, update the depth
         if ($next == BEGIN_MAP() ) { $self->{RECURSIVE_DEPTH}++; }          if ($next == BEGIN_MAP() ) { $self->{RECURSIVE_DEPTH}++; }
Line 2663  sub next { Line 2690  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_map() &&      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})) {
         $self->{RECURSIVE_ITERATOR_FLAG} = 1;          $self->{RECURSIVE_ITERATOR_FLAG} = 1;
         my $firstResource = $self->{HERE}->map_start();          my $firstResource = $self->{HERE}->map_start();
Line 2681  sub next { Line 2708  sub next {
     my $browsePriv = $self->{HERE}->browsePriv();      my $browsePriv = $self->{HERE}->browsePriv();
     if (!$self->{HERE}->src() ||       if (!$self->{HERE}->src() || 
         (!($browsePriv eq 'F') && !($browsePriv eq '2')) ) {          (!($browsePriv eq 'F') && !($browsePriv eq '2')) ) {
         return $self->next();          return $self->next($closeAllPages);
     }      }
   
     return $self->{HERE};      return $self->{HERE};
Line 2733  package Apache::lonnavmaps::DFSiterator; Line 2760  package Apache::lonnavmaps::DFSiterator;
 #  useful for pre-processing of some kind, and is in fact used by the main  #  useful for pre-processing of some kind, and is in fact used by the main
 #  iterator that way, but that's about it.  #  iterator that way, but that's about it.
 # One could imagine merging this into the init routine of the main iterator,  # One could imagine merging this into the init routine of the main iterator,
 #  but this might as well be left seperate, since it is possible some other  #  but this might as well be left separate, since it is possible some other
 #  use might be found for it. - Jeremy  #  use might be found for it. - Jeremy
   
 # Unlike the main iterator, this DOES return all resources, even blank ones.  # Unlike the main iterator, this DOES return all resources, even blank ones.
Line 3150  Returns true if the resource is a sequen Line 3177  Returns true if the resource is a sequen
   
 =cut  =cut
   
   sub hasResource {
      my $self = shift;
      return $self->{NAV_MAP}->hasResource(@_);
   }
   
   sub retrieveResources {
      my $self = shift;
      return $self->{NAV_MAP}->retrieveResources(@_);
   }
   
 sub is_html {  sub is_html {
     my $self=shift;      my $self=shift;
Line 3166  sub is_page { Line 3202  sub is_page {
 sub is_problem {  sub is_problem {
     my $self=shift;      my $self=shift;
     my $src = $self->src();      my $src = $self->src();
     return ($src =~ /problem$/);      return ($src =~ /\.(problem|exam|quiz|assess|survey|form|library)$/)
   }
   sub contains_problem {
       my $self=shift;
       if ($self->is_page()) {
    my $hasProblem=$self->hasResource($self,sub { $_[0]->is_problem() },1);
    return $hasProblem;
       }
       return 0;
 }  }
 sub is_sequence {  sub is_sequence {
     my $self=shift;      my $self=shift;
Line 3366  sub opendate { Line 3410  sub opendate {
 }  }
 sub problemstatus {  sub problemstatus {
     (my $self, my $part) = @_;      (my $self, my $part) = @_;
     return $self->parmval("problemstatus", $part);      return lc $self->parmval("problemstatus", $part);
 }  }
 sub sig {  sub sig {
     (my $self, my $part) = @_;      (my $self, my $part) = @_;
Line 3544  sub responseType { Line 3588  sub responseType {
     my $part = shift;      my $part = shift;
   
     $self->extractParts();      $self->extractParts();
     return $self->{RESPONSE_TYPES}->{$part};      if (defined($self->{RESPONSE_TYPES}->{$part})) {
    return @{$self->{RESPONSE_TYPES}->{$part}};
       } else {
    return undef;
       }
 }  }
   
 sub responseIds {  sub responseIds {
Line 3552  sub responseIds { Line 3600  sub responseIds {
     my $part = shift;      my $part = shift;
   
     $self->extractParts();      $self->extractParts();
     return $self->{RESPONSE_IDS}->{$part};      if (defined($self->{RESPONSE_IDS}->{$part})) {
    return @{$self->{RESPONSE_IDS}->{$part}};
       } else {
    return undef;
       }
 }  }
   
 # Private function: Extracts the parts information, both part names and  # Private function: Extracts the parts information, both part names and
Line 3569  sub extractParts { Line 3621  sub extractParts {
   
     # Retrieve part count, if this is a problem      # Retrieve part count, if this is a problem
     if ($self->is_problem()) {      if ($self->is_problem()) {
    my $partorder = &Apache::lonnet::metadata($self->src(), 'partorder');
         my $metadata = &Apache::lonnet::metadata($self->src(), 'packages');          my $metadata = &Apache::lonnet::metadata($self->src(), 'packages');
         if (!$metadata) {  
             $self->{RESOURCE_ERROR} = 1;  
             $self->{PARTS} = [];  
             $self->{PART_TYPE} = {};  
             return;  
         }  
         foreach (split(/\,/,$metadata)) {  
             if ($_ =~ /^part_(.*)$/) {  
                 my $part = $1;  
                 # This floods the logs if it blows up  
                 if (defined($parts{$part})) {  
                     Apache::lonnet::logthis("$part multiply defined in metadata for " . $self->symb());  
                   }  
   
                 # check to see if part is turned off.   if ($partorder) {
       my @parts;
                 if (!Apache::loncommon::check_if_partid_hidden($part, $self->symb())) {      for my $part (split (/,/,$partorder)) {
                     $parts{$part} = 1;   if (!Apache::loncommon::check_if_partid_hidden($part, $self->symb())) {
                 }      push @parts, $part;
             }      $parts{$part} = 1;
    }
       }
       $self->{PARTS} = \@parts;
    } else {
       if (!$metadata) {
    $self->{RESOURCE_ERROR} = 1;
    $self->{PARTS} = [];
    $self->{PART_TYPE} = {};
    return;
       }
       foreach (split(/\,/,$metadata)) {
    if ($_ =~ /^part_(.*)$/) {
       my $part = $1;
       # This floods the logs if it blows up
       if (defined($parts{$part})) {
    &Apache::lonnet::logthis("$part multiply defined in metadata for " . $self->symb());
       }
       
       # check to see if part is turned off.
       
       if (!Apache::loncommon::check_if_partid_hidden($part, $self->symb())) {
    $parts{$part} = 1;
       }
    }
       }
       my @sortedParts = sort keys %parts;
       $self->{PARTS} = \@sortedParts;
         }          }
                   
           
         my @sortedParts = sort keys %parts;  
         $self->{PARTS} = \@sortedParts;  
   
         my %responseIdHash;          my %responseIdHash;
         my %responseTypeHash;          my %responseTypeHash;
Line 3606  sub extractParts { Line 3670  sub extractParts {
         }          }
   
         # Now, the unfortunate thing about this is that parts, part name, and          # Now, the unfortunate thing about this is that parts, part name, and
         # response if are delimited by underscores, but both the part          # response id are delimited by underscores, but both the part
         # name and response id can themselves have underscores in them.          # name and response id can themselves have underscores in them.
         # So we have to use our knowlege of part names to figure out           # So we have to use our knowlege of part names to figure out 
         # where the part names begin and end, and even then, it is possible          # where the part names begin and end, and even then, it is possible
Line 3618  sub extractParts { Line 3682  sub extractParts {
                 my $partIdSoFar = '';                  my $partIdSoFar = '';
                 my @partChunks = split /_/, $partStuff;                  my @partChunks = split /_/, $partStuff;
                 my $i = 0;                  my $i = 0;
   
                 for ($i = 0; $i < scalar(@partChunks); $i++) {                  for ($i = 0; $i < scalar(@partChunks); $i++) {
                     if ($partIdSoFar) { $partIdSoFar .= '_'; }                      if ($partIdSoFar) { $partIdSoFar .= '_'; }
                     $partIdSoFar .= $partChunks[$i];                      $partIdSoFar .= $partChunks[$i];
Line 3626  sub extractParts { Line 3689  sub extractParts {
                         my @otherChunks = @partChunks[$i+1..$#partChunks];                          my @otherChunks = @partChunks[$i+1..$#partChunks];
                         my $responseId = join('_', @otherChunks);                          my $responseId = join('_', @otherChunks);
                         push @{$responseIdHash{$partIdSoFar}}, $responseId;                          push @{$responseIdHash{$partIdSoFar}}, $responseId;
                         $responseTypeHash{$partIdSoFar} = $responseType;                          push @{$responseTypeHash{$partIdSoFar}}, $responseType;
                         last;  
                     }                      }
                 }                  }
             }              }
         }          }
   
         $self->{RESPONSE_IDS} = \%responseIdHash;          $self->{RESPONSE_IDS} = \%responseIdHash;
         $self->{RESPONSE_TYPES} = \%responseTypeHash;          $self->{RESPONSE_TYPES} = \%responseTypeHash;
     }      }
Line 3824  sub getCompletionStatus { Line 3885  sub getCompletionStatus {
   
     my $status = $self->queryRestoreHash('solved', shift);      my $status = $self->queryRestoreHash('solved', shift);
   
     # Left as seperate if statements in case we ever do more with this      # Left as separate if statements in case we ever do more with this
     if ($status eq 'correct_by_student') {return $self->CORRECT;}      if ($status eq 'correct_by_student') {return $self->CORRECT;}
     if ($status eq 'correct_by_override') {return $self->CORRECT_BY_OVERRIDE; }      if ($status eq 'correct_by_override') {return $self->CORRECT_BY_OVERRIDE; }
     if ($status eq 'incorrect_attempted') {return $self->INCORRECT; }      if ($status eq 'incorrect_attempted') {return $self->INCORRECT; }
Line 3945  sub status { Line 4006  sub status {
     #if ($self->{RESOURCE_ERROR}) { return NETWORK_FAILURE; }      #if ($self->{RESOURCE_ERROR}) { return NETWORK_FAILURE; }
     if ($completionStatus == NETWORK_FAILURE) { return NETWORK_FAILURE; }      if ($completionStatus == NETWORK_FAILURE) { return NETWORK_FAILURE; }
   
     my $suppressFeedback = lc($self->parmval("problemstatus", $part)) eq 'no';      my $suppressFeedback = $self->problemstatus($part) eq 'no';
       # If there's an answer date and we're past it, don't
       # suppress the feedback; student should know
       if ($self->answerdate($part) && $self->answerdate($part) < time()) {
    $suppressFeedback = 0;
       }
   
     # There are a few whole rows we can dispose of:      # There are a few whole rows we can dispose of:
     if ($completionStatus == CORRECT ||      if ($completionStatus == CORRECT ||

Removed from v.1.228  
changed lines
  Added in v.1.258


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