File:  [LON-CAPA] / loncom / interface / lonnavdisplay.pm
Revision 1.29: download - view: text, annotated - select for diffs
Sun Mar 1 20:42:08 2015 UTC (9 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Remove commented out code.

    1: # The LearningOnline Network with CAPA
    2: # Navigate Maps Display Handler
    3: #
    4: # $Id: lonnavdisplay.pm,v 1.29 2015/03/01 20:42:08 raeburn 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 REDIRECT);
   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 Apache::londocs();
   41: 
   42: sub handler {
   43:     my $r = shift;
   44:     real_handler($r);
   45: }
   46: 
   47: sub real_handler {
   48:     my $r = shift;
   49:     # Handle header-only request
   50:     if ($r->header_only) {
   51:         if ($env{'browser.mathml'}) {
   52:             &Apache::loncommon::content_type($r,'text/xml');
   53:         } else {
   54:             &Apache::loncommon::content_type($r,'text/html');
   55:         }
   56:         $r->send_http_header;
   57:         return OK;
   58:     }
   59: 
   60:     # Check for critical messages and redirect if present.  
   61:     my ($redirect,$url) = &Apache::loncommon::critical_redirect(300);
   62:     if ($redirect) {
   63:         &Apache::loncommon::content_type($r,'text/html');
   64:         $r->header_out(Location => $url);
   65:         return REDIRECT;
   66:     }
   67: 
   68: 
   69: 
   70:     # Send header, don't cache this page
   71:     if ($env{'browser.mathml'}) {
   72:         &Apache::loncommon::content_type($r,'text/xml');
   73:     } else {
   74:         &Apache::loncommon::content_type($r,'text/html');
   75:     }
   76:     &Apache::loncommon::no_cache($r);
   77: 
   78:     my %toplinkitems=();
   79: 
   80:     # Create the nav map
   81:     my $navmap = Apache::lonnavmaps::navmap->new();
   82: 
   83:     if (!defined($navmap)) {
   84:         my $requrl = $r->uri;
   85:         $env{'user.error.msg'} = "$requrl:bre:0:0:Course not initialized";
   86:         $env{'user.reinit'} = 1;
   87:         return HTTP_NOT_ACCEPTABLE;
   88:     }
   89:     $r->send_http_header;
   90: 
   91: # ------------------------------------------------------------ Get query string
   92:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['sort','showOnlyHomework','postsymb','register']);
   93:     
   94: # ----------------------------------------------------- Force menu registration
   95:     # Header
   96:     my $course_type = &Apache::loncommon::course_type();
   97:     my $title = $course_type . ' Contents';
   98:     my ($start_page,$args);
   99:     if ($env{'form.register'}) {
  100:         $args = {'force_register' => $env{'form.register'}};
  101:         $start_page = &Apache::loncommon::start_page($title,undef,$args);
  102:     } else {
  103:         my $brcrum = [{href => '/adm/navmaps',
  104:                        text => &mt($course_type . ' Contents'),
  105:                        no_mt => 1},
  106:                      ];
  107:         $args = {'bread_crumbs' => $brcrum};
  108:         $start_page = &Apache::loncommon::start_page($title,undef,$args);
  109:     }
  110:     $r->print($start_page.
  111:               '<script type="text/javascript">'."\n".
  112:               '// <![CDATA['."\n".
  113:               'window.focus();'."\n".
  114:               '// ]]>'."\n".
  115:               '</script>');
  116:     &startContentScreen($r,'navmaps');
  117:     $r->rflush();
  118: 
  119:     # Check that it's defined
  120:     if (!($navmap->courseMapDefined())) {
  121: 	$r->print(&Apache::loncommon::help_open_menu('Navigation Screen','Navigation_Screen',undef,'RAT'));
  122:         $r->print('<span class="LC_error">'.&mt('Coursemap undefined.').
  123: 		  '</span>' .
  124:                   &Apache::loncommon::end_page());
  125:         return OK;
  126:     }
  127: 
  128:     my @resources = $navmap->retrieveResources();
  129:     my $sequenceCount = 0;
  130:     my $problemCount = 0;
  131:     my $notaprobCount = 0;
  132:     my $sequenceId;
  133:     my $notools;
  134:     foreach my $curRes (@resources) {
  135:         if (ref($curRes)) {
  136:             if ($curRes->is_sequence()) {
  137:                 $sequenceCount++;
  138:                 $sequenceId = $curRes->map_pc();
  139:             } elsif ($curRes->is_problem()) {
  140:                 $problemCount ++;
  141:             } else {
  142:                 $notaprobCount ++;
  143:             }
  144:         }
  145:     }
  146:     if (($sequenceCount == 1) && (!$problemCount) && ($notaprobCount <= 1)) {
  147:         $notools = 1;
  148:     }
  149: 
  150:     # If there's only one map in the top-level and we don't
  151:     # already have a filter, automatically display it
  152:     if ($ENV{QUERY_STRING} !~ /filter/) {
  153:         if ($sequenceCount == 1) {
  154:             # The automatic iterator creation in the render call 
  155:             # will pick this up. We know the condition because
  156:             # the defined($env{'form.filter'}) also ensures this
  157:             # is a fresh call.
  158:             $env{'form.filter'} = "$sequenceId";
  159:         }
  160:     }
  161: 
  162:     # Check to see if the student is jumping to next open, do-able problem
  163:     if ($ENV{QUERY_STRING} =~ /^jumpToFirstHomework/) {
  164:         # Find the next homework problem that they can do.
  165:         my $iterator = $navmap->getIterator(undef, undef, undef, 1);
  166:         my $curRes;
  167:         my $foundDoableProblem = 0;
  168:         my $minimumduedate;
  169:         my $now = time();
  170: 	
  171:         while ($curRes = $iterator->next()) {
  172:             if (ref($curRes) && $curRes->is_problem()) {
  173:                 my $status = $curRes->status();
  174: 		my $thisduedate=$curRes->duedate();
  175:                 if ($thisduedate > $now 
  176: 		    && $curRes->completable()) {
  177:                         
  178:                     $foundDoableProblem = 1;
  179: 
  180:                     if (!defined($minimumduedate)
  181:                         || $thisduedate<$minimumduedate) {
  182: 			# Pop open all previous maps
  183: 			my $stack = $iterator->getStack();
  184: 			pop @$stack; # last resource in the stack is the problem
  185: 			# itself, which we don't need in the map stack
  186: 			my @mapPcs = map {$_->map_pc()} @$stack;
  187: 			$env{'form.filter'} = join(',', @mapPcs);
  188: 			
  189: 			# Mark as both "here" and "jump"
  190: 			$env{'form.postsymb'} = $curRes->symb();
  191:                         $minimumduedate=$thisduedate;
  192: 		    }
  193:                 }
  194:             }
  195:         }
  196: 
  197:         # If we found no problems, print a note to that effect.
  198:         if (!$foundDoableProblem) {
  199:             $r->print("<span class=\"LC_info\">"
  200:                      .&mt("All homework assignments have been completed.")
  201:                      ."</span>");
  202:         }
  203:     } else {
  204:         my $link = 'navmaps?jumpToFirstHomework';
  205:         if ($env{'form.register'}) {
  206:             $link .= '&amp;register='.$env{'form.register'}; 
  207:         }
  208:         unless ($notools) {
  209: 	    &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'firsthomework',
  210: 					      'location.href="'.$link.'"',
  211: 					      "Show my first due problem");
  212:         }
  213:     }
  214: 
  215:     my $suppressEmptySequences = 0;
  216:     my $filterFunc = undef;
  217:     my $resource_no_folder_link = 0;
  218: 
  219:     # Display only due homework.
  220:     my $showOnlyHomework = 0;
  221:     if ($env{'form.showOnlyHomework'} eq "1") {
  222:         $showOnlyHomework = 1;
  223:         $suppressEmptySequences = 1;
  224:         $filterFunc = sub { my $res = shift; 
  225:                             return $res->completable() || $res->is_map();
  226:                         };
  227:         my $link = 'navmaps?sort='.$env{'form.sort'};
  228:         if ($env{'form.register'}) {
  229:             $link .= '&amp;register='.$env{'form.register'};
  230:         }
  231: 	&Apache::lonnavmaps::add_linkitem(\%toplinkitems,'everything',
  232: 					  'location.href="'.$link.'"',
  233: 					  'Show everything');
  234:         $r->print("<span class=\"LC_info\">".&mt("Uncompleted Problems")."</span>");
  235:         $env{'form.filter'} = '';
  236:         $env{'form.condition'} = 1;
  237: 	$resource_no_folder_link = 1;
  238:     } else {
  239:         my $link = 'navmaps?sort='.$env{'form.sort'}.'&amp;showOnlyHomework=1';
  240:         if ($env{'form.register'}) {
  241:             $link .= '&amp;register='.$env{'form.register'};
  242:         }
  243:         unless ($notools) {
  244: 	    &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'uncompleted',
  245: 					      'location.href="'.$link.'"',
  246: 					      'Show only uncompleted problems');
  247:         }
  248:     }
  249: 
  250:     my %selected=($env{'form.sort'} => ' selected="selected"');
  251:     my $sort_html;
  252:     unless ($notools) {
  253:         $sort_html=(
  254:               '<form name="sortForm" action="">
  255:                  <span class="LC_nobreak">
  256:                     <input type="hidden" name="showOnlyHomework" value="'.$env{'form.showOnlyHomework'}.'" />
  257:                     '.&mt('Sort by:').'
  258:                     <select name="sort" onchange="document.sortForm.submit()">
  259:                        <option value="default"'.$selected{'default'}.'>'.&mt('Default').'</option>
  260:                        <option value="title"'.$selected{'title'}.'>'.&mt('Title').'</option>
  261:                        <option value="duedate"'.$selected{'duedate'}.'>'.&mt('Due Date').'</option>
  262:                        <option value="discussion"'.$selected{'discussion'}.'>'.&mt('Has New Discussion').'</option>
  263:                     </select>
  264:                     <input type="hidden" name="register" value="'.$env{'form.register'}.'" />
  265:                  </span>
  266:                </form>');
  267:     }
  268:     # renderer call
  269:     my $renderArgs = { 'cols' => [0,1,2,3],
  270: 		       'sort' => $env{'form.sort'},
  271:                        'url' => '/adm/navmaps',
  272:                        'navmap' => $navmap,
  273:                        'suppressNavmap' => 1,
  274:                        'suppressEmptySequences' => $suppressEmptySequences,
  275:                        'filterFunc' => $filterFunc,
  276: 		       'resource_no_folder_link' => $resource_no_folder_link,
  277: 		       'sort_html'=> $sort_html,
  278:                        'r' => $r,
  279:                        'caller' => 'navmapsdisplay',
  280:                        'linkitems' => \%toplinkitems,
  281:                        'notools' => $notools};
  282:                       
  283:     my $render = &Apache::lonnavmaps::render($renderArgs);
  284: 
  285:     # If no resources were printed, print a reassuring message so the
  286:     # user knows there was no error.
  287:     if ($renderArgs->{'counter'} == 0) {
  288:         if ($showOnlyHomework) {
  289:             $r->print("<p><span class=\"LC_info\">".&mt("All homework is currently completed.")."</span></p>");
  290:         } else { # both jumpToFirstHomework and normal use the same: course must be empty
  291:             $r->print("<p><span class=\"LC_info\">".&mt("This course is empty.")."</span></p>");
  292:         }
  293:     }
  294:     &endContentScreen($r);
  295:     $r->print(&Apache::loncommon::end_page());
  296:     $r->rflush();
  297: 
  298:     return OK;
  299: }
  300: 
  301: sub startContentScreen {
  302:     my ($r,$mode)=@_;
  303: 
  304:     $r->print("\n".'<ul class="LC_TabContentBigger" id="mainnav">'."\n");
  305:     $r->print('<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.&mt('Main Content').'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></a></li>'."\n");
  306:     my $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
  307:     my ($suppcount,$errors);
  308:     unless ($allowed) {
  309:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  310:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  311:         ($suppcount,$errors) = &Apache::lonnet::get_numsuppfiles($cnum,$cdom);
  312:     }
  313:     if ($allowed || $suppcount) {
  314:         $r->print('<li '.(($mode eq 'supplemental')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>');
  315:     }
  316:     $r->print('<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.&mt('Content Search').'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></a></li>'."\n");
  317:     $r->print('<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.&mt('Content Index').'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></a></li>'."\n");
  318:     $r->print("\n".'</ul>'."\n");
  319:     $r->print('<div class="LC_Box" style="clear:both;margin:0;"><div id="maincoursedoc" style="margin:0 0;padding:0 0;"><div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">');
  320: }
  321: 
  322: sub endContentScreen {
  323:    my ($r)=@_;
  324:    $r->print('</div></div></div>');
  325: }
  326: 
  327: 1;
  328: __END__
  329: 

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