Diff for /loncom/interface/lonnavmaps.pm between versions 1.261 and 1.297

version 1.261, 2004/06/15 14:12:56 version 1.297, 2004/09/21 20:44:16
Line 83  my %colormap = Line 83  my %colormap =
 # is not yet done and due in less then 24 hours  # is not yet done and due in less then 24 hours
 my $hurryUpColor = "#FF0000";  my $hurryUpColor = "#FF0000";
   
   sub launch_win {
       my ($mode,$script,$toplinkitems)=@_;
       my $result;
       if ($script ne 'no') {
    $result.='<script type="text/javascript">';
       }
       $result.='function launch_navmapwin() {
                    newWindow=open(\'/adm/navmaps?launchExternal\',\'loncapanav\',\'width=400,height=600,scrollbars=1\');
                  }';
       if ($mode eq 'now') {
    $result.="\nlaunch_navmapwin();\n";
       }
       if ($script ne 'no') {
    $result.='</script>';
       }
       if ($mode eq 'link') {
    &add_linkitem($toplinkitems,'launchnav','launch_navmapwin()',
         "Launch navigation window");
       }
       return $result;
   }
   
   sub close {
       if ($ENV{'environment.remotenavmap'} ne 'on') { return ''; }
       return(<<ENDCLOSE);
   <script type="text/javascript">
   window.status='Accessing Nav Control';
   menu=window.open("/adm/rat/empty.html","loncapanav",
                    "height=600,width=400,scrollbars=1");
   window.status='Closing Nav Control';
   menu.close();
   window.status='Done.';
   </script>
   ENDCLOSE
   }
   
   sub nav_control_js {
       my $nav=($ENV{'environment.remotenavmap'} eq 'on');
       return (<<NAVCONTROL);
       var w_loncapanav_flag="$nav";
   
   
   function gonav(url) {
      if (w_loncapanav_flag != 1) {
         gopost(url,'');
      }  else {
         navwindow=window.open(url,
                     "loncapanav","height=600,width=400,scrollbars=1"); 
      }
   }
   NAVCONTROL
   }
   
   sub update {
       if ($ENV{'environment.remotenavmap'} ne 'on') { return ''; }
       if (!$ENV{'request.course.id'}) { return ''; }
       if ($ENV{'REQUEST_URI'}=~m|^/adm/navmaps|) { return ''; }
       return(<<ENDUPDATE);
   <form name="navform"></form>
   <script type="text/javascript">
   this.document.navform.action='/adm/navmaps#curloc';
   this.document.navform.target='loncapanav';
   this.document.navform.submit();
   </script>
   ENDUPDATE
   }
   
 sub handler {  sub handler {
     my $r = shift;      my $r = shift;
     real_handler($r);      real_handler($r);
Line 111  sub real_handler { Line 178  sub real_handler {
     &Apache::loncommon::no_cache($r);      &Apache::loncommon::no_cache($r);
     $r->send_http_header;      $r->send_http_header;
   
       my %toplinkitems=();
   
       if ($ENV{QUERY_STRING} eq 'collapseExternal') {
    &Apache::lonnet::put('environment',{'remotenavmap' => 'off'});
    &Apache::lonnet::appenv('environment.remotenavmap' => 'off');
    my $menu=&Apache::lonmenu::reopenmenu();
    my $navstatus=&Apache::lonmenu::get_nav_status();
    if ($menu) {
       $menu=(<<MENU)
                swmenu=$menu
                swmenu.clearTimeout(swmenu.menucltim);
        $navstatus
   MENU
           } else {
       my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
       my $mainwindow='window.open('.$nothing.',"loncapaclient","",false);';
       $menu=(<<MENU)
                swmenu=$mainwindow
        $navstatus
   MENU
    }
    $r->print(<<"ENDSUBM");
    <html>
           <head>
     <script type="text/javascript">
        function submitthis() {
       $menu
       self.close();
       }
   
      </script>
           </head>
    <body bgcolor="#FFFFFF" onLoad="submitthis()"></body>
           </html>
   ENDSUBM
           return;
       }
       if ($ENV{QUERY_STRING} eq 'launchExternal') {
    &Apache::lonnet::put('environment',{'remotenavmap' => 'on'});
    &Apache::lonnet::appenv('environment.remotenavmap' => 'on');
       }
   
     # Create the nav map      # Create the nav map
     my $navmap = Apache::lonnavmaps::navmap->new();      my $navmap = Apache::lonnavmaps::navmap->new();
   
Line 123  sub real_handler { Line 232  sub real_handler {
     $r->print("<html><head>\n");      $r->print("<html><head>\n");
     $r->print("<title>".&mt('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','sort','showOnlyHomework']);
           
 # ----------------------------------------------------- Force menu registration  # ----------------------------------------------------- Force menu registration
     my $addentries='';      my $addentries='';
       my $more_unload;
       my $body_only='';
       if ($ENV{'environment.remotenavmap'} eq 'on') {
    $r->print('<script type="text/javascript">
                         function collapse() {
                            this.document.location="/adm/navmaps?collapseExternal";
                         }
                      </script>');
   # FIXME need to be smarter to only catch window close events
   # $more_unload="collapse()"
    $body_only=1;
       }
     if ($ENV{'form.register'}) {      if ($ENV{'form.register'}) {
        $addentries=' onLoad="'.&Apache::lonmenu::loadevents().   $addentries=' onLoad="'.&Apache::lonmenu::loadevents().
    '" onUnload="'.&Apache::lonmenu::unloadevents().'"';      '" onUnload="'.&Apache::lonmenu::unloadevents().';'.
        $r->print(&Apache::lonmenu::registerurl(1));      $more_unload.'"';
    $r->print(&Apache::lonmenu::registerurl(1));
       } else {
    $addentries=' onUnload="'.$more_unload.'"';
     }      }
   
     # Header      # Header
     $r->print('</head>'.      $r->print('</head>'.
               &Apache::loncommon::bodytag('Navigate Course Contents','',                &Apache::loncommon::bodytag('Navigate Course Contents','',
                                     $addentries,'','',$ENV{'form.register'}));    $addentries,$body_only,'',
     $ENV{'form.register'}));
     $r->print('<script>window.focus();</script>');      $r->print('<script>window.focus();</script>');
        
     $r->rflush();      $r->rflush();
   
     # Check that it's defined      # Check that it's defined
     if (!($navmap->courseMapDefined())) {      if (!($navmap->courseMapDefined())) {
    $r->print(&Apache::loncommon::help_open_menu('','Navigation Screen','Navigation_Screen','',undef,'RAT'));
         $r->print('<font size="+2" color="red">Coursemap undefined.</font>' .          $r->print('<font size="+2" color="red">Coursemap undefined.</font>' .
                   '</body></html>');                    '</body></html>');
         return OK;          return OK;
Line 172  sub real_handler { Line 298  sub real_handler {
         }          }
     }      }
   
       if ($ENV{QUERY_STRING} eq 'launchExternal') {
    $r->print('
             <form name="returnwin" action="/adm/flip?postdata=return%3a" 
                   method="post" target="loncapaclient">
             </form>');
    $r->print('
             <script type="text/javascript">
                 this.document.returnwin.submit();
             </script>');
       }
   
       if ($ENV{'environment.remotenavmap'} ne 'on') {
    $r->print(&launch_win('link','yes',\%toplinkitems));
       } 
       if ($ENV{'environment.remotenavmap'} eq 'on') {
    &add_linkitem(\%toplinkitems,'closenav','collapse()',
         "Close navigation window");
       } 
   
     my $jumpToFirstHomework = 0;      my $jumpToFirstHomework = 0;
     # Check to see if the student is jumping to next open, do-able problem      # Check to see if the student is jumping to next open, do-able problem
     if ($ENV{QUERY_STRING} eq 'jumpToFirstHomework') {      if ($ENV{QUERY_STRING} =~ /^jumpToFirstHomework/) {
         $jumpToFirstHomework = 1;          $jumpToFirstHomework = 1;
         # Find the next homework problem that they can do.          # Find the next homework problem that they can do.
         my $iterator = $navmap->getIterator(undef, undef, undef, 1);          my $iterator = $navmap->getIterator(undef, undef, undef, 1);
Line 207  sub real_handler { Line 352  sub real_handler {
             $r->print("<font size='+2'>All homework assignments have been completed.</font><br /><br />");              $r->print("<font size='+2'>All homework assignments have been completed.</font><br /><br />");
         }          }
     } else {      } else {
         $r->print("<a href='navmaps?jumpToFirstHomework'>" .   &add_linkitem(\%toplinkitems,'firsthomework',
        &mt("Go To My First Homework Problem")."</a>&nbsp;&nbsp;&nbsp;&nbsp;");        'location.href="navmaps?jumpToFirstHomework"',
         "Show Me My First Homework Problem");
     }      }
   
     my $suppressEmptySequences = 0;      my $suppressEmptySequences = 0;
Line 217  sub real_handler { Line 363  sub real_handler {
   
     # Display only due homework.      # Display only due homework.
     my $showOnlyHomework = 0;      my $showOnlyHomework = 0;
     if ($ENV{QUERY_STRING} eq 'showOnlyHomework') {      if ($ENV{'form.showOnlyHomework'} eq "1") {
         $showOnlyHomework = 1;          $showOnlyHomework = 1;
         $suppressEmptySequences = 1;          $suppressEmptySequences = 1;
         $filterFunc = sub { my $res = shift;           $filterFunc = sub { my $res = shift; 
                             return $res->completable() || $res->is_map();                              return $res->completable() || $res->is_map();
                         };                          };
    &add_linkitem(\%toplinkitems,'everything',
        'location.href="navmaps?sort='.$ENV{'form.sort'}.'"',
         "Show Everything");
         $r->print("<p><font size='+2'>".&mt("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'>" .   &add_linkitem(\%toplinkitems,'uncompleted',
        &mt("Show Only Uncompleted Homework")."</a>&nbsp;&nbsp;&nbsp;&nbsp;");        'location.href="navmaps?sort='.$ENV{'form.sort'}.
     }            '&showOnlyHomework=1"',
         "Show Only Uncompleted Homework");
       }
   
       my %selected=($ENV{'form.sort'} => 'selected=on');
       my $sort_html=("<form>
                    <nobr>
                       <input type=\"hidden\" name=\"showOnlyHomework\" value=\"".$ENV{'form.showOnlyHomework'}."\" />
                       <input type=\"submit\" value=\"".&mt('Sort by:')."\" />
                       <select name=\"sort\">
                          <option value=\"default\" $selected{'default'}>".&mt('Default')."</option>
                          <option value=\"title\"   $selected{'title'}  >".&mt('Title')."</option>
                          <option value=\"duedate\" $selected{'duedate'}>".&mt('Duedate')."</option>
                          <option value=\"discussion\" $selected{'discussion'}>".&mt('Has Discussion')."</option>
                       </select>
                    </nobr>
                  </form>");
     # renderer call      # renderer call
     my $renderArgs = { 'cols' => [0,1,2,3],      my $renderArgs = { 'cols' => [0,1,2,3],
          'sort' => $ENV{'form.sort'},
                        'url' => '/adm/navmaps',                         'url' => '/adm/navmaps',
                        'navmap' => $navmap,                         'navmap' => $navmap,
                        'suppressNavmap' => 1,                         'suppressNavmap' => 1,
                        'suppressEmptySequences' => $suppressEmptySequences,                         'suppressEmptySequences' => $suppressEmptySequences,
                        'filterFunc' => $filterFunc,                         'filterFunc' => $filterFunc,
        'resource_no_folder_link' => $resource_no_folder_link,         'resource_no_folder_link' => $resource_no_folder_link,
                        'r' => $r};         'sort_html'=> $sort_html,
                          'r' => $r,
                          'caller' => 'navmapsdisplay',
                          'linkitems' => \%toplinkitems};
     my $render = render($renderArgs);      my $render = render($renderArgs);
     $navmap->untieHashes();      $navmap->untieHashes();
   
Line 512  sub timeToHumanString { Line 680  sub timeToHumanString {
         }          }
   
         # 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 %Y at %I:%M %P", localtime($time));
         $timeStr =~ s/12:00 am/00:00/;          $timeStr =~ s/12:00 am/00:00/;
         $timeStr =~ s/12:00 pm/noon/;          $timeStr =~ s/12:00 pm/noon/;
         return $timeStr;          return $timeStr;
Line 958  sub render_resource { Line 1126  sub render_resource {
   
     if ($resource->is_problem() && $part ne '0' &&       if ($resource->is_problem() && $part ne '0' && 
         !$params->{'condensed'}) {          !$params->{'condensed'}) {
  my $displaypart=&Apache::lonnet::EXT('resource.'.$part.'.display',   my $displaypart=$resource->part_display($part);
      $resource->symb());  
  unless ($displaypart) { $displaypart=$part; }  
         $partLabel = " (Part: $displaypart)";          $partLabel = " (Part: $displaypart)";
  $link.='#'.&Apache::lonnet::escape($part);   $link.='#'.&Apache::lonnet::escape($part);
         $title = "";          $title = "";
Line 970  sub render_resource { Line 1136  sub render_resource {
         $nonLinkedText .= ' (' . $resource->countParts() . ' parts)';          $nonLinkedText .= ' (' . $resource->countParts() . ' parts)';
     }      }
   
     if (!$params->{'resource_nolink'} && !$resource->is_sequence()) {      my $target;
         $result .= "  $curMarkerBegin<a href='$link'>$title$partLabel</a>$curMarkerEnd $nonLinkedText</td>";      if ($ENV{'environment.remotenavmap'} eq 'on') {
    $target=' target="loncapaclient" ';
       }
       if (!$params->{'resource_nolink'} && !$resource->is_sequence() && !$resource->is_empty_sequence) {
           $result .= "  $curMarkerBegin<a $target 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 1174  sub setDefault { Line 1344  sub setDefault {
     return $val;      return $val;
 }  }
   
   sub cmp_title {
       my ($atitle,$btitle) = (lc($_[0]->compTitle),lc($_[1]->compTitle));
       $atitle=~s/^\s*//;
       $btitle=~s/^\s*//;
       return $atitle cmp $btitle;
   }
   
 sub render {  sub render {
     my $args = shift;      my $args = shift;
     &Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});      &Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});
Line 1259  sub render { Line 1436  sub render {
         # We only need to do this if we need to open the maps to show the          # We only need to do this if we need to open the maps to show the
         # current position. This will change the counter so we can't count          # current position. This will change the counter so we can't count
         # for the jump marker with this loop.          # for the jump marker with this loop.
         while (($curRes = $mapIterator->next()) && !$found) {          while ($here && ($curRes = $mapIterator->next()) && !$found) {
             if (ref($curRes) && $curRes->symb() eq $here) {              if (ref($curRes) && $curRes->symb() eq $here) {
                 my $mapStack = $mapIterator->getStack();                  my $mapStack = $mapIterator->getStack();
                                   
Line 1359  sub render { Line 1536  sub render {
     }      }
   
     if ($printCloseAll && !$args->{'resource_no_folder_link'}) {      if ($printCloseAll && !$args->{'resource_no_folder_link'}) {
    my ($link,$text);
         if ($condition) {          if ($condition) {
             $result.="<a href=\"navmaps?condition=0&filter=&$queryString" .      $link='"navmaps?condition=0&filter=&'.$queryString.
                 "&here=" . Apache::lonnet::escape($here) .   '&here='.&Apache::lonnet::escape($here).'"';
                 "\">".&mt('Close All Folders')."</a>";      $text='Close All Folders';
           } else {
       $link='"navmaps?condition=1&filter=&'.$queryString.
    '&here='.&Apache::lonnet::escape($here).'"';
       $text='Open All Folders';
           }
    if ($args->{'caller'} eq 'navmapsdisplay') {
       &add_linkitem($args->{'linkitems'},'changefolder',
     'location.href='.$link,$text);
    } else {
       $result.='<a href='.$link.'>'.&mt($text).'</a>';
    }
           $result .= "\n";
       }
   
       # Check for any unread discussions in all resources.
       if ($args->{'caller'} eq 'navmapsdisplay') {
    &add_linkitem($args->{'linkitems'},'clearbubbles',
         'document.clearbubbles.submit()',
         'Mark all posts read');
    my $time=time;
    $result .= (<<END);
       <form name="clearbubbles" method="post" action="/adm/feedback">
    <input type="hidden" name="navurl" value="$ENV{'QUERY_STRING'}" />
    <input type="hidden" name="navtime" value="$time" />
   END
           if ($args->{'sort'} eq 'discussion') { 
       my $totdisc = 0;
       my $haveDisc = '';
       my @allres=$navmap->retrieveResources();
       foreach my $resource (@allres) {
    if ($resource->hasDiscussion()) {
       my $ressymb;
       if ($resource->symb() =~ m-(___adm/\w+/\w+)/(\d+)/bulletinboard$-) {
    $ressymb = 'bulletin___'.$2.$1.'/'.$2.'/bulletinboard';
       } else {
    $ressymb = $resource->symb();
       }
       $haveDisc .= $ressymb.':';
       $totdisc ++;
    }
       }
       if ($totdisc > 0) {
    $haveDisc =~ s/:$//;
    my $navurl = $ENV{'QUERY_STRING'};
    $result .= (<<END);
    <input type="hidden" name="navmaps" value="$haveDisc" />
       </form>
   END
               }
    }
    $result.='</form>';
       }
   
       if ($args->{'caller'} eq 'navmapsdisplay') {
           $result .= '<table><tr><td>'.
                      &Apache::loncommon::help_open_menu('','Navigation Screen','Navigation_Screen','',undef,'RAT').'</td>';
    if ($ENV{'environment.remotenavmap'} ne 'on') {
       $result .= '<td>&nbsp;</td>'; 
         } else {          } else {
             $result.="<a href=\"navmaps?condition=1&filter=&$queryString" .      $result .= '</tr><tr>'; 
                 "&here=" . Apache::lonnet::escape($here) .   
                 "\">".&mt('Open All Folders')."</a>";  
         }          }
         $result .= "<br /><br />\n";   $result.=&show_linkitems($args->{'linkitems'});
     }              if ($args->{'sort_html'}) {
       if ($ENV{'environment.remotenavmap'} ne 'on') {
    $result.='<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>'.
       '<td align="right">'.$args->{'sort_html'}.'</td></tr>';
       } else {
    $result.='</tr><tr><td align="left"><br />'.
       $args->{'sort_html'}.'</td></tr>';
       }
    }
           $result .= '</table>';
       } elsif ($args->{'sort_html'}) { 
           $result.=$args->{'sort_html'}; 
       }
   
       $result .= "<br />\n";
     if ($r) {      if ($r) {
         $r->print($result);          $r->print($result);
         $r->rflush();          $r->rflush();
Line 1442  sub render { Line 1689  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($closeAllPages)) {      my @resources;
       my $code='';# sub { !(shift->is_map();) };
       if ($args->{'sort'} eq 'title') {
           my $oldFilterFunc = $filterFunc;
    my $filterFunc= 
       sub {
    my ($res)=@_;
    if ($res->is_map()) { return 0;}
    return &$oldFilterFunc($res);
       };
    @resources=$navmap->retrieveResources(undef,$filterFunc);
    @resources= sort { &cmp_title($a,$b) } @resources;
       } elsif ($args->{'sort'} eq 'duedate') {
    my $oldFilterFunc = $filterFunc;
    my $filterFunc= 
       sub {
    my ($res)=@_;
    if (!$res->is_problem()) { return 0;}
    return &$oldFilterFunc($res);
       };
    @resources=$navmap->retrieveResources(undef,$filterFunc);
    @resources= sort {
       if ($a->duedate ne $b->duedate) {
           return $a->duedate cmp $b->duedate;
       }
       my $value=&cmp_title($a,$b);
       return $value;
    } @resources;
       } elsif ($args->{'sort'} eq 'discussion') {
    my $oldFilterFunc = $filterFunc;
    my $filterFunc= 
       sub {
    my ($res)=@_;
    if (!$res->hasDiscussion() &&
       !$res->getFeedback() &&
       !$res->getErrors()) { return 0;}
    return &$oldFilterFunc($res);
       };
    @resources=$navmap->retrieveResources(undef,$filterFunc);
    @resources= sort { &cmp_title($a,$b) } @resources;
       } else {
    #unknow sort mechanism or default
    undef($args->{'sort'});
       }
   
   
       while (1) {
    if ($args->{'sort'}) {
       $curRes = shift(@resources);
    } else {
       $curRes = $it->next($closeAllPages);
    }
    if (!$curRes) { last; }
   
         # 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 1556  sub render { Line 1856  sub render {
   
             # Set up some data about the parts that the cols might want              # Set up some data about the parts that the cols might want
             my $filter = $it->{FILTER};              my $filter = $it->{FILTER};
             my $stack = $it->getStack();      my $src;
             my $src = getLinkForResource($stack);      if ($args->{'sort'}) {
    $src = $curRes->src(); # FIXME this is wrong for .pages
       } else {
    my $stack = $it->getStack();
    $src=getLinkForResource($stack);
       }
             my $anchor='';              my $anchor='';
             if ($src=~s/(\#.*$)//) {              if ($src=~s/(\#.*)$//) {
  $anchor=$1;   $anchor=$1;
     }      }
             my $srcHasQuestion = $src =~ /\?/;              my $srcHasQuestion = $src =~ /\?/;
Line 1567  sub render { Line 1872  sub render {
                 ($srcHasQuestion?'&':'?') .                  ($srcHasQuestion?'&':'?') .
                 'symb=' . &Apache::lonnet::escape($curRes->symb()).                  'symb=' . &Apache::lonnet::escape($curRes->symb()).
  $anchor;   $anchor;
               
             # Now, display each column.              # Now, display each column.
             foreach my $col (@$cols) {              foreach my $col (@$cols) {
                 my $colHTML = '';                  my $colHTML = '';
Line 1638  if (location.href.indexOf('#curloc')==-1 Line 1943  if (location.href.indexOf('#curloc')==-1
     return $result;      return $result;
 }  }
   
   sub add_linkitem {
       my ($linkitems,$name,$cmd,$text)=@_;
       $$linkitems{$name}{'cmd'}=$cmd;
       $$linkitems{$name}{'text'}=&mt($text);
   }
   
   sub show_linkitems {
       my ($linkitems)=@_;
       my @linkorder = ("launchnav","closenav","firsthomework","everything",
        "uncompleted","changefolder","clearbubbles");
       
       my $result .= (<<ENDBLOCK);
                 <td align="left">
   <script type="text/javascript">
       function changeNavDisplay () {
    var navchoice = document.linkitems.toplink[document.linkitems.toplink.selectedIndex].value;
   ENDBLOCK
       foreach my $link (@linkorder) {
    $result.= "if (navchoice == '$link') {".
       $linkitems->{$link}{'cmd'}."}\n";
       }
       $result.='}
                 </script>
                      <form name="linkitems" method="post">
                          <nobr><select name="toplink">'."\n";
       foreach my $link (@linkorder) {
    if (defined($linkitems->{$link})) {
       if ($linkitems->{$link}{'text'} ne '') {
    $result .= ' <option value="'.$link.'">'.
       $linkitems->{$link}{'text'}."</option>\n";
       }
    }
       }
       $result .= '</select>&nbsp;<input type="button" name="chgnav"
                      value="Go" onClick="javascript:changeNavDisplay()" />
                   </nobr></form></td>'."\n";
       return $result;
   }
   
 1;  1;
   
 package Apache::lonnavmaps::navmap;  package Apache::lonnavmaps::navmap;
Line 1844  sub generate_email_discuss_status { Line 2188  sub generate_email_discuss_status {
           
     foreach my $msgid (split(/\&/, $keys)) {      foreach my $msgid (split(/\&/, $keys)) {
  $msgid=&Apache::lonnet::unescape($msgid);   $msgid=&Apache::lonnet::unescape($msgid);
  my $plain=&Apache::lonnet::unescape(&Apache::lonnet::unescape($msgid));   if ((!$emailstatus{$msgid}) || ($emailstatus{$msgid} eq 'new')) {
  if ($plain=~/(Error|Feedback) \[([^\]]+)\]/) {      my $plain=
     my ($what,$url)=($1,$2);   &Apache::lonnet::unescape(&Apache::lonnet::unescape($msgid));
     my %status=      if ($plain=~/(Error|Feedback) \[([^\]]+)\]/) {
  &Apache::lonnet::get('email_status',[$msgid]);   my ($what,$url)=($1,$2);
     if ($status{$msgid}=~/^error\:/) {   
  $status{$msgid}='';   
     }  
       
     if (($status{$msgid} eq 'new') ||   
  (!$status{$msgid})) {   
  if ($what eq 'Error') {   if ($what eq 'Error') {
     $error{$url}.=','.$msgid;       $error{$url}.=','.$msgid; 
  } else {   } else {
Line 1864  sub generate_email_discuss_status { Line 2202  sub generate_email_discuss_status {
  }   }
     }      }
           
       #url's of resources that have feedbacks
     $self->{FEEDBACK} = \%feedback;      $self->{FEEDBACK} = \%feedback;
     $self->{ERROR_MSG} = \%error; # what is this? JB      #or errors
       $self->{ERROR_MSG} = \%error;
     $self->{DISCUSSION_TIME} = \%discussiontime;      $self->{DISCUSSION_TIME} = \%discussiontime;
     $self->{EMAIL_STATUS} = \%emailstatus;      $self->{EMAIL_STATUS} = \%emailstatus;
     $self->{LAST_READ} = \%lastreadtime;      $self->{LAST_READ} = \%lastreadtime;
Line 1941  sub hasDiscussion { Line 2281  sub hasDiscussion {
 # backward compatibility (bulletin boards used to be 'wrapped')  # backward compatibility (bulletin boards used to be 'wrapped')
     my $ressymb = $symb;      my $ressymb = $symb;
     if ($ressymb =~ m|adm/(\w+)/(\w+)/(\d+)/bulletinboard$|) {      if ($ressymb =~ m|adm/(\w+)/(\w+)/(\d+)/bulletinboard$|) {
         unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {          unless ($ressymb =~ m|adm/wrapper/adm|) {
             $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';              $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
         }          }
     }      }
Line 1949  sub hasDiscussion { Line 2289  sub hasDiscussion {
     if ( defined ( $self->{LAST_READ}->{$ressymb} ) ) {      if ( defined ( $self->{LAST_READ}->{$ressymb} ) ) {
         return $self->{DISCUSSION_TIME}->{$ressymb} > $self->{LAST_READ}->{$ressymb};          return $self->{DISCUSSION_TIME}->{$ressymb} > $self->{LAST_READ}->{$ressymb};
     } else {      } else {
         return $self->{DISCUSSION_TIME}->{$ressymb} >  $self->{LAST_CHECK};  #        return $self->{DISCUSSION_TIME}->{$ressymb} >  $self->{LAST_CHECK}; # v.1.1 behavior 
           return $self->{DISCUSSION_TIME}->{$ressymb} >  0; # in 1.2 will display speech bubble icons for all items with posts until marked as read (even if read in v 1.1).
     }      }
 }  }
   
Line 2021  sub getById { Line 2362  sub getById {
 sub getBySymb {  sub getBySymb {
     my $self = shift;      my $self = shift;
     my $symb = shift;      my $symb = shift;
   
     my ($mapUrl, $id, $filename) = &Apache::lonnet::decode_symb($symb);      my ($mapUrl, $id, $filename) = &Apache::lonnet::decode_symb($symb);
     my $map = $self->getResourceByUrl($mapUrl);      my $map = $self->getResourceByUrl($mapUrl);
     return $self->getById($map->map_pc() . '.' . $id);      my $returnvalue = undef;
       if (ref($map)) {
           $returnvalue = $self->getById($map->map_pc() .'.'.$id);
       }
       return $returnvalue;
 }  }
   
 sub getByMapPc {  sub getByMapPc {
Line 2217  in the filter function. Line 2563  in the filter function.
   
 =cut  =cut
   
   
 sub getResourceByUrl {  sub getResourceByUrl {
     my $self = shift;      my $self = shift;
     my $resUrl = shift;      my $resUrl = shift;
Line 3244  sub is_sequence { Line 3591  sub is_sequence {
 sub is_survey {  sub is_survey {
     my $self = shift();      my $self = shift();
     my $part = shift();      my $part = shift();
     if ($self->src() =~ /\.(survey)$/) {      if ($self->parmval('type',$part) eq 'survey') {
         return 1;          return 1;
     }      }
     if ($self->parmval('type',$part) eq 'survey') {      if ($self->src() =~ /\.(survey)$/) {
         return 1;          return 1;
     }      }
     return 0;      return 0;
 }  }
   
   sub is_empty_sequence {
       my $self=shift;
       my $src = $self->src();
       return !$self->is_page() && $self->navHash("is_map_", 1) && !$self->navHash("map_type_" . $self->map_pc());
   }
   
 # Private method: Shells out to the parmval in the nav map, handler parts.  # Private method: Shells out to the parmval in the nav map, handler parts.
 sub parmval {  sub parmval {
     my $self = shift;      my $self = shift;
Line 3476  sub weight { Line 3829  sub weight {
  $self->symb(), $ENV{'user.domain'},   $self->symb(), $ENV{'user.domain'},
  $ENV{'user.name'},    $ENV{'user.name'}, 
  $ENV{'request.course.sec'});   $ENV{'request.course.sec'});
   }
   sub part_display {
       my $self= shift(); my $partID = shift();
       if (! defined($partID)) { $partID = '0'; }
       my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',
                                        $self->symb);
       if (! defined($display) || $display eq '') {
           $display = $partID;
       }
       return $display;
 }  }
   
 # Multiple things need this  # Multiple things need this
Line 3566  Returns the number of parts of the probl Line 3928  Returns the number of parts of the probl
 for single part problems, returns 1. For multipart, it returns the  for single part problems, returns 1. For multipart, it returns the
 number of parts in the problem, not including psuedo-part 0.   number of parts in the problem, not including psuedo-part 0. 
   
   =item * B<countResponses>():
   
   Returns the total number of responses in the problem a student can answer.
   
   =item * B<responseTypes>():
   
   Returns a hash whose keys are the response types.  The values are the number 
   of times each response type is used.  This is for the I<entire> problem, not 
   just a single part.
   
 =item * B<multipart>():  =item * B<multipart>():
   
 Returns true if the problem is multipart, false otherwise. Use this instead  Returns true if the problem is multipart, false otherwise. Use this instead
Line 3612  sub countParts { Line 3984  sub countParts {
     return scalar(@{$parts}); # + $delta;      return scalar(@{$parts}); # + $delta;
 }  }
   
   sub countResponses {
       my $self = shift;
       my $count;
       foreach my $part (@{$self->parts()}) {
           $count+= scalar($self->responseIds($part));
       }
       return $count;
   }
   
   sub responseTypes {
       my $self = shift;
       my %responses;
       foreach my $part ($self->parts()) {
           foreach my $responsetype ($self->responseType($part)) {
               $responses{$responsetype}++ if (defined($responsetype));
           }
       }
       return %responses;
   }
   
 sub multipart {  sub multipart {
     my $self = shift;      my $self = shift;
     return $self->countParts() > 1;      return $self->countParts() > 1;
Line 3699  sub extractParts { Line 4091  sub extractParts {
         }          }
                   
   
           # These hashes probably do not need names that end with "Hash"....
         my %responseIdHash;          my %responseIdHash;
         my %responseTypeHash;          my %responseTypeHash;
   
Line 3733  sub extractParts { Line 4126  sub extractParts {
                 }                  }
             }              }
         }          }
    my $resorder = &Apache::lonnet::metadata($self->src(),'responseorder');
           #
           # Reorder the arrays in the %responseIdHash and %responseTypeHash
    if ($resorder) {
       my @resorder=split(/,/,$resorder);
       foreach my $part (keys(%responseIdHash)) {
    my $i=0;
    my %resids = map { ($_,$i++) } @{ $responseIdHash{$part} };
    my @neworder;
    foreach my $possibleid (@resorder) {
       if (exists($resids{$possibleid})) {
    push(@neworder,$resids{$possibleid});
       }
    }
    my @ids;
    my @type;
    foreach my $element (@neworder) {
       push (@ids,$responseIdHash{$part}->[$element]);
       push (@type,$responseTypeHash{$part}->[$element]);
    }
    $responseIdHash{$part}=\@ids;
    $responseTypeHash{$part}=\@type;
       }
    }
         $self->{RESPONSE_IDS} = \%responseIdHash;          $self->{RESPONSE_IDS} = \%responseIdHash;
         $self->{RESPONSE_TYPES} = \%responseTypeHash;          $self->{RESPONSE_TYPES} = \%responseTypeHash;
     }      }
Line 3926  sub getCompletionStatus { Line 4343  sub getCompletionStatus {
   
     # Left as separate 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_scantron') {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; }
     if ($status eq 'incorrect_by_override') {return $self->INCORRECT_BY_OVERRIDE; }      if ($status eq 'incorrect_by_override') {return $self->INCORRECT_BY_OVERRIDE; }
Line 4076  sub status { Line 4494  sub status {
   
     if ($dateStatus == PAST_DUE_ANSWER_LATER ||      if ($dateStatus == PAST_DUE_ANSWER_LATER ||
         $dateStatus == PAST_DUE_NO_ANSWER ) {          $dateStatus == PAST_DUE_NO_ANSWER ) {
         return $dateStatus;           return $suppressFeedback ? ANSWER_SUBMITTED : $dateStatus; 
     }      }
   
     if ($dateStatus == ANSWER_OPEN) {      if ($dateStatus == ANSWER_OPEN) {

Removed from v.1.261  
changed lines
  Added in v.1.297


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