File:  [LON-CAPA] / loncom / interface / lonnavdisplay.pm
Revision 1.16: download - view: text, annotated - select for diffs
Wed Mar 17 15:59:38 2010 UTC (14 years, 3 months ago) by droeschl
Branches: MAIN
CVS tags: HEAD
Fixed a bug that caused the display of 2 breadcrumblines (1 of which erroneous) if course contents was the first resource in course.

    1: # The LearningOnline Network with CAPA
    2: # Navigate Maps Handler
    3: #
    4: # $Id: lonnavdisplay.pm,v 1.16 2010/03/17 15:59:38 droeschl Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: ###
   29: 
   30: package Apache::lonnavdisplay;
   31: 
   32: use strict;
   33: use Apache::Constants qw(:common :http);
   34: use Apache::lonmenu();
   35: use Apache::loncommon();
   36: use Apache::lonnavmaps();
   37: use Apache::lonhtmlcommon();
   38: use Apache::lonnet;
   39: use Apache::lonlocal;
   40: use Time::HiRes qw( gettimeofday tv_interval );
   41: 
   42: sub handler {
   43:     my $r = shift;
   44:     real_handler($r);
   45: }
   46: 
   47: sub real_handler {
   48:     my $r = shift;
   49:     #my $t0=[&gettimeofday()];
   50:     # Handle header-only request
   51:     if ($r->header_only) {
   52:         if ($env{'browser.mathml'}) {
   53:             &Apache::loncommon::content_type($r,'text/xml');
   54:         } else {
   55:             &Apache::loncommon::content_type($r,'text/html');
   56:         }
   57:         $r->send_http_header;
   58:         return OK;
   59:     }
   60: 
   61:     # Send header, don't cache this page
   62:     if ($env{'browser.mathml'}) {
   63:         &Apache::loncommon::content_type($r,'text/xml');
   64:     } else {
   65:         &Apache::loncommon::content_type($r,'text/html');
   66:     }
   67:     &Apache::loncommon::no_cache($r);
   68: 
   69:     my %toplinkitems=();
   70:     &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'blank','',
   71: 				      "Select Action");
   72: 
   73:     # Create the nav map
   74:     my $navmap = Apache::lonnavmaps::navmap->new();
   75: 
   76:     if (!defined($navmap)) {
   77:         my $requrl = $r->uri;
   78:         $env{'user.error.msg'} = "$requrl:bre:0:0:Course not initialized";
   79:         $env{'user.reinit'} = 1;
   80:         return HTTP_NOT_ACCEPTABLE;
   81:     }
   82:     $r->send_http_header;
   83: 
   84: # ------------------------------------------------------------ Get query string
   85:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['sort','showOnlyHomework','postsymb']);
   86:     
   87: # ----------------------------------------------------- Force menu registration
   88:     # Header
   89:     my $course_type = &Apache::loncommon::course_type();
   90:     my $title = $course_type . ' Contents';
   91:     my $breadcrumb_text = mt($course_type . ' Contents');
   92:     $r->print(&Apache::loncommon::start_page($title, '',
   93:                          { 'bread_crumbs'    => [{text => $breadcrumb_text }],}));
   94: #SD
   95:     $r->print('<script type="text/javascript">window.focus();</script>');
   96:      
   97:     $r->rflush();
   98: 
   99:     # Check that it's defined
  100:     if (!($navmap->courseMapDefined())) {
  101: 	$r->print(&Apache::loncommon::help_open_menu('Navigation Screen','Navigation_Screen',undef,'RAT'));
  102:         $r->print('<span class="LC_error">'.&mt('Coursemap undefined.').
  103: 		  '</span>' .
  104:                   &Apache::loncommon::end_page());
  105:         return OK;
  106:     }
  107: 
  108:     # See if there's only one map in the top-level, if we don't
  109:     # already have a filter... if so, automatically display it
  110:     # (older code; should use retrieveResources)
  111:     if ($ENV{QUERY_STRING} !~ /filter/) {
  112:         my $iterator = $navmap->getIterator(undef, undef, undef, 0);
  113:         my $curRes;
  114:         my $sequenceCount = 0;
  115:         my $sequenceId;
  116:         while ($curRes = $iterator->next()) {
  117:             if (ref($curRes) && $curRes->is_sequence()) {
  118:                 $sequenceCount++;
  119:                 $sequenceId = $curRes->map_pc();
  120:             }
  121:         }
  122:         
  123:         if ($sequenceCount == 1) {
  124:             # The automatic iterator creation in the render call 
  125:             # will pick this up. We know the condition because
  126:             # the defined($env{'form.filter'}) also ensures this
  127:             # is a fresh call.
  128:             $env{'form.filter'} = "$sequenceId";
  129:         }
  130:     }
  131: 
  132:     # Check to see if the student is jumping to next open, do-able problem
  133:     if ($ENV{QUERY_STRING} =~ /^jumpToFirstHomework/) {
  134:         # Find the next homework problem that they can do.
  135:         my $iterator = $navmap->getIterator(undef, undef, undef, 1);
  136:         my $curRes;
  137:         my $foundDoableProblem = 0;
  138:         my $minimumduedate;
  139:         my $now = time();
  140: 	
  141:         while ($curRes = $iterator->next()) {
  142:             if (ref($curRes) && $curRes->is_problem()) {
  143:                 my $status = $curRes->status();
  144: 		my $thisduedate=$curRes->duedate();
  145:                 if ($thisduedate > $now 
  146: 		    && $curRes->completable()) {
  147:                         
  148:                     $foundDoableProblem = 1;
  149: 
  150:                     if (!defined($minimumduedate)
  151:                         || $thisduedate<$minimumduedate) {
  152: 			# Pop open all previous maps
  153: 			my $stack = $iterator->getStack();
  154: 			pop @$stack; # last resource in the stack is the problem
  155: 			# itself, which we don't need in the map stack
  156: 			my @mapPcs = map {$_->map_pc()} @$stack;
  157: 			$env{'form.filter'} = join(',', @mapPcs);
  158: 			
  159: 			# Mark as both "here" and "jump"
  160: 			$env{'form.postsymb'} = $curRes->symb();
  161:                         $minimumduedate=$thisduedate;
  162: 		    }
  163:                 }
  164:             }
  165:         }
  166: 
  167:         # If we found no problems, print a note to that effect.
  168:         if (!$foundDoableProblem) {
  169:             $r->print("<span class=\"LC_info\">"
  170:                      .&mt("All homework assignments have been completed.")
  171:                      ."</span>");
  172:         }
  173:     } else {
  174: 	&Apache::lonnavmaps::add_linkitem(\%toplinkitems,'firsthomework',
  175: 					  'location.href="navmaps?jumpToFirstHomework"',
  176: 					  "Show my first due problem");
  177:     }
  178: 
  179:     my $suppressEmptySequences = 0;
  180:     my $filterFunc = undef;
  181:     my $resource_no_folder_link = 0;
  182: 
  183:     # Display only due homework.
  184:     my $showOnlyHomework = 0;
  185:     if ($env{'form.showOnlyHomework'} eq "1") {
  186:         $showOnlyHomework = 1;
  187:         $suppressEmptySequences = 1;
  188:         $filterFunc = sub { my $res = shift; 
  189:                             return $res->completable() || $res->is_map();
  190:                         };
  191: 	&Apache::lonnavmaps::add_linkitem(\%toplinkitems,'everything',
  192: 					  'location.href="navmaps?sort='.$env{'form.sort'}.'"',
  193: 					  "Show everything");
  194:         $r->print("<span class=\"LC_info\">".&mt("Uncompleted Problems")."</span>");
  195:         $env{'form.filter'} = '';
  196:         $env{'form.condition'} = 1;
  197: 	$resource_no_folder_link = 1;
  198:     } else {
  199: 	&Apache::lonnavmaps::add_linkitem(\%toplinkitems,'uncompleted',
  200: 					  'location.href="navmaps?sort='.$env{'form.sort'}.
  201: 					  '&showOnlyHomework=1"',
  202: 					  "Show only uncompleted problems");
  203:     }
  204: 
  205:     my %selected=($env{'form.sort'} => ' selected="selected"');
  206:     my $sort_html=("<form name=\"sortForm\">
  207:                  <span class=\"LC_nobreak\">
  208:                     <input type=\"hidden\" name=\"showOnlyHomework\" value=\"".$env{'form.showOnlyHomework'}."\" />
  209:                     ".&mt('Sort by:')."
  210:                     <select name=\"sort\" onChange=\"document.sortForm.submit()\">
  211:                        <option value=\"default\"$selected{'default'}>".&mt('Default')."</option>
  212:                        <option value=\"title\"$selected{'title'}  >".&mt('Title')."</option>
  213:                        <option value=\"duedate\"$selected{'duedate'}>".&mt('Duedate')."</option>
  214:                        <option value=\"discussion\"$selected{'discussion'}>".&mt('Has New Discussion')."</option>
  215:                     </select>
  216:                  </span>
  217:                </form>");
  218:     # renderer call
  219:     my $renderArgs = { 'cols' => [0,1,2,3],
  220: 		       'sort' => $env{'form.sort'},
  221:                        'url' => '/adm/navmaps',
  222:                        'navmap' => $navmap,
  223:                        'suppressNavmap' => 1,
  224:                        'suppressEmptySequences' => $suppressEmptySequences,
  225:                        'filterFunc' => $filterFunc,
  226: 		       'resource_no_folder_link' => $resource_no_folder_link,
  227: 		       'sort_html'=> $sort_html,
  228:                        'r' => $r,
  229:                        'caller' => 'navmapsdisplay',
  230:                        'linkitems' => \%toplinkitems};
  231:     my $render = &Apache::lonnavmaps::render($renderArgs);
  232: 
  233:     # If no resources were printed, print a reassuring message so the
  234:     # user knows there was no error.
  235:     if ($renderArgs->{'counter'} == 0) {
  236:         if ($showOnlyHomework) {
  237:             $r->print("<p><span class=\"LC_info\">".&mt("All homework is currently completed.")."</span></p>");
  238:         } else { # both jumpToFirstHomework and normal use the same: course must be empty
  239:             $r->print("<p><span class=\"LC_info\">".&mt("This course is empty.")."</span></p>");
  240:         }
  241:     }
  242:     #my $td=&tv_interval($t0);
  243:     #$r->print("<br />$td");
  244: 
  245:     $r->print(&Apache::loncommon::end_page());
  246:     $r->rflush();
  247: 
  248:     return OK;
  249: }
  250: 
  251: 1;
  252: __END__
  253: 

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