File:  [LON-CAPA] / loncom / interface / lonnavdisplay.pm
Revision 1.48: download - view: text, annotated - select for diffs
Tue May 27 23:35:38 2025 UTC (5 weeks, 1 day ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, HEAD
- Text shown when course contents listing for Main Content tab is empty
  differs depending on whether there is any unhiddent Supplemental Content.

    1: # The LearningOnline Network with CAPA
    2: # Navigate Maps Display Handler
    3: #
    4: # $Id: lonnavdisplay.pm,v 1.48 2025/05/27 23:35:38 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: use Apache::lonuserstate;
   42: use LONCAPA::ltiutils;
   43: use LONCAPA;
   44: 
   45: sub handler {
   46:     my $r = shift;
   47:     real_handler($r);
   48: }
   49: 
   50: sub real_handler {
   51:     my $r = shift;
   52:     # Handle header-only request
   53:     if ($r->header_only) {
   54:         &Apache::loncommon::content_type($r,'text/html');
   55:         $r->send_http_header;
   56:         return OK;
   57:     }
   58: 
   59:     # Check for critical messages and redirect if present.  
   60:     my ($redirect,$url) = &Apache::loncommon::critical_redirect(300,'contents');
   61:     if ($redirect) {
   62:         &Apache::loncommon::content_type($r,'text/html');
   63:         $r->header_out(Location => $url);
   64:         return REDIRECT;
   65:     }
   66: 
   67: # ------------------------------------------------------------ Get query string
   68:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['sort',
   69:                                                                   'showOnlyHomework',
   70:                                                                   'postsymb']);
   71:     # Check if course needs to be re-initialized
   72:     my $loncaparev = $r->dir_config('lonVersion');
   73:     my ($result,@reinit) = &Apache::loncommon::needs_coursereinit($loncaparev);
   74:     my %prog_state=();
   75:     my $closure;
   76: 
   77:     if ($result eq 'switch') {
   78:         &Apache::loncommon::content_type($r,'text/html');
   79:         $r->send_http_header;
   80:         $r->print(&Apache::loncommon::check_release_result(@reinit));
   81:         return OK;
   82:     }
   83:     my ($cid,$cnum,$cdom);
   84:     if ($result) {
   85:         $cid = $env{'request.course.id'};
   86:         $cnum = $env{'course.'.$cid.'.num'};
   87:         $cdom = $env{'course.'.$cid.'.domain'};
   88:     }
   89:     if (($result eq 'main') || ($result eq 'both')) {
   90:         &Apache::loncommon::content_type($r,'text/html');
   91:         $r->send_http_header;
   92:         &startpage($r);
   93:         my $preamble = '<div id="LC_update_'.$cid.'" class="LC_info">'.
   94:                        '<br />'.
   95:                        &mt('Your course session is being updated because of recent changes by course personnel.').
   96:                        ' '.&mt('Please be patient').'.<br /></div>'.
   97:                        '<div style="padding:0;clear:both;margin:0;border:0"></div>';
   98:         $closure = <<ENDCLOSE;
   99: <script type="text/javascript">
  100: // <![CDATA[
  101: \$("#LC_update_$cid").hide('slow');
  102: // ]]>
  103: </script>
  104: ENDCLOSE
  105:         %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,undef,$preamble);
  106:         &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Updating course'));
  107:         $r->rflush();
  108:         my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum",\%prog_state,$r);
  109:         &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Finished!'));
  110:         if ($ferr) {
  111:             &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
  112:             $r->print($closure.&Apache::loncommon::end_page());
  113:             my $requrl = $r->uri;
  114:             $env{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
  115:             $env{'user.reinit'} = 1;
  116:             return HTTP_NOT_ACCEPTABLE;
  117:         }
  118:     }
  119:     if (($result eq 'both') || ($result eq 'supp')) {
  120:         my $possdel;
  121:         if ($result eq 'supp') {
  122:             $possdel = 1;
  123:         }
  124:         my ($supplemental,$refs_updated) = &Apache::loncommon::get_supplemental($cnum,$cdom,'',$possdel);
  125:         unless ($refs_updated) {
  126:             &Apache::loncommon::set_supp_httprefs($cnum,$cdom,$supplemental,$possdel);
  127:         }
  128:     }
  129: 
  130:     my $course_type = &Apache::loncommon::course_type();
  131:     if (($course_type eq 'Placement') && (!$env{'request.role.adv'})) { 
  132:         my $furl = &Apache::lonpageflip::first_accessible_resource();
  133:         if (($result eq 'main') || ($result eq 'both')) {
  134:             &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
  135:             $r->print($closure.&Apache::loncommon::end_page());
  136:             return OK;
  137:         } else {
  138:             unless ($furl eq '/adm/navmaps') {
  139:                 &Apache::loncommon::content_type($r,'text/html');
  140:                 $r->header_out(Location => $furl);
  141:                 return REDIRECT;
  142:             }
  143:         }
  144:     }
  145: 
  146:     if ($env{'request.lti.login'}) {
  147:         if ($env{'request.lti.uri'} ne '') {
  148:             my $cid = $env{'request.course.id'};
  149:             my $cnum = $env{'course.'.$cid.'.num'};
  150:             my $cdom = $env{'course.'.$cid.'.domain'};
  151:             my ($scope,$url) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},$cdom,$cnum);
  152:             if (($scope eq 'map') || ($scope eq 'resource')) {
  153:                 &Apache::loncommon::content_type($r,'text/html');
  154:                 $r->header_out(Location => $url);
  155:                 return REDIRECT;
  156:             }
  157:         }
  158:     }
  159: 
  160:     # Create the nav map
  161:     my $navmap = Apache::lonnavmaps::navmap->new();
  162: 
  163:     if (!defined($navmap)) {
  164:         if (($result eq 'main') || ($result eq 'both')) {
  165:             &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
  166:             $r->print($closure.&Apache::loncommon::end_page());
  167:         }
  168:         my $requrl = $r->uri;
  169:         $env{'user.error.msg'} = "$requrl:bre:0:0:Course not initialized";
  170:         $env{'user.reinit'} = 1;
  171:         return HTTP_NOT_ACCEPTABLE;
  172:     }
  173: 
  174:     if (($result eq 'main') || ($result eq 'both')) {
  175:         $r->rflush();
  176:         &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
  177:         $r->print($closure);
  178:         $r->rflush();
  179:     } else {
  180:         # Send header, don't cache this page
  181:         &Apache::loncommon::content_type($r,'text/html');
  182:         $r->send_http_header;
  183:         &startpage($r);
  184:     }
  185: 
  186:     &startContentScreen($r,'navmaps',$course_type);
  187:     unless (($result eq 'main') || ($result eq 'both')) {
  188:         $r->rflush();
  189:     }
  190: 
  191:     # Check that it's defined
  192:     if (!($navmap->courseMapDefined())) {
  193: 	$r->print(&Apache::loncommon::help_open_menu('Navigation Screen','Navigation_Screen',undef,'RAT'));
  194:         $r->print('<span class="LC_error">'.&mt('Coursemap undefined.').
  195: 		  '</span>' .
  196:                   &Apache::loncommon::end_page());
  197:         return OK;
  198:     }
  199: 
  200:     my %toplinkitems=();
  201:     my @resources = $navmap->retrieveResources();
  202:     my $sequenceCount = 0;
  203:     my $problemCount = 0;
  204:     my $notaprobCount = 0;
  205:     my $sequenceId;
  206:     my $notools;
  207:     foreach my $curRes (@resources) {
  208:         if (ref($curRes)) {
  209:             if ($curRes->is_sequence()) {
  210:                 $sequenceCount++;
  211:                 $sequenceId = $curRes->map_pc();
  212:             } elsif ($curRes->is_problem()) {
  213:                 $problemCount ++;
  214:             } else {
  215:                 $notaprobCount ++;
  216:             }
  217:         }
  218:     }
  219:     if (($sequenceCount == 1) && (!$problemCount) && ($notaprobCount <= 1)) {
  220:         $notools = 1;
  221:     }
  222: 
  223:     # If there's only one map in the top-level and we don't
  224:     # already have a filter, automatically display it
  225:     if ($ENV{QUERY_STRING} !~ /filter/) {
  226:         if ($sequenceCount == 1) {
  227:             # The automatic iterator creation in the render call 
  228:             # will pick this up. We know the condition because
  229:             # the defined($env{'form.filter'}) also ensures this
  230:             # is a fresh call.
  231:             $env{'form.filter'} = "$sequenceId";
  232:         }
  233:     }
  234: 
  235:     # Check to see if the student is jumping to next open, do-able problem
  236:     if ($ENV{QUERY_STRING} =~ /^jumpToFirstHomework/) {
  237:         # Find the next homework problem that they can do.
  238:         my $iterator = $navmap->getIterator(undef, undef, undef, 1);
  239:         my $curRes;
  240:         my $foundDoableProblem = 0;
  241:         my $minimumduedate;
  242:         my $now = time();
  243: 	
  244:         while ($curRes = $iterator->next()) {
  245:             if (ref($curRes) && $curRes->is_problem()) {
  246:                 my $status = $curRes->status();
  247: 		my $thisduedate=$curRes->duedate();
  248:                 if ($thisduedate > $now 
  249: 		    && $curRes->completable()) {
  250:                         
  251:                     $foundDoableProblem = 1;
  252: 
  253:                     if (!defined($minimumduedate)
  254:                         || $thisduedate<$minimumduedate) {
  255: 			# Pop open all previous maps
  256: 			my $stack = $iterator->getStack();
  257: 			pop @$stack; # last resource in the stack is the problem
  258: 			# itself, which we don't need in the map stack
  259: 			my @mapPcs = map {$_->map_pc()} @$stack;
  260: 			$env{'form.filter'} = join(',', @mapPcs);
  261: 			
  262: 			# Mark as both "here" and "jump"
  263: 			$env{'form.postsymb'} = $curRes->symb();
  264:                         $minimumduedate=$thisduedate;
  265: 		    }
  266:                 }
  267:             }
  268:         }
  269: 
  270:         # If we found no problems, print a note to that effect.
  271:         if (!$foundDoableProblem) {
  272:             $r->print("<span class=\"LC_info\">"
  273:                      .&mt("All homework assignments have been completed.")
  274:                      ."</span>");
  275:         }
  276:     } else {
  277:         my $link = '/adm/navmaps?jumpToFirstHomework';
  278:         unless ($notools) {
  279: 	    &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'firsthomework',
  280: 					      'location.href="'.$link.'"',
  281: 					      "Show my first due problem");
  282:         }
  283:     }
  284: 
  285:     my $suppressEmptySequences = 0;
  286:     my $filterFunc = undef;
  287:     my $resource_no_folder_link = 0;
  288: 
  289:     # Display only due homework.
  290:     my $showOnlyHomework = 0;
  291:     if ($env{'form.showOnlyHomework'} eq "1") {
  292:         $showOnlyHomework = 1;
  293:         $suppressEmptySequences = 1;
  294:         $filterFunc = sub { my $res = shift; 
  295:                             return $res->completable() || $res->is_map();
  296:                         };
  297:         my $link = '/adm/navmaps?sort='.$env{'form.sort'};
  298: 	&Apache::lonnavmaps::add_linkitem(\%toplinkitems,'everything',
  299: 					  'location.href="'.$link.'"',
  300: 					  'Show everything');
  301:         $r->print("<span class=\"LC_info\">".&mt("Uncompleted Problems")."</span>");
  302:         $env{'form.filter'} = '';
  303:         $env{'form.condition'} = 1;
  304: 	$resource_no_folder_link = 1;
  305:     } else {
  306:         my $link = '/adm/navmaps?sort='.$env{'form.sort'}.'&amp;showOnlyHomework=1';
  307:         unless ($notools) {
  308: 	    &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'uncompleted',
  309: 					      'location.href="'.$link.'"',
  310: 					      'Show only uncompleted problems');
  311:         }
  312:     }
  313: 
  314:     my %selected=($env{'form.sort'} => ' selected="selected"');
  315:     my $sort_html;
  316:     unless ($notools) {
  317:         $sort_html=(
  318:               '<form name="sortForm" action="">
  319:                  <span class="LC_nobreak">
  320:                     <input type="hidden" name="showOnlyHomework" value="'.$env{'form.showOnlyHomework'}.'" />
  321:                     <label for="LC_navmap_sort">'.&mt('Sort by:').'</label>
  322:                     <select name="sort" id="LC_navmap_sort">
  323:                        <option value="default"'.$selected{'default'}.'>'.&mt('Default').'</option>
  324:                        <option value="title"'.$selected{'title'}.'>'.&mt('Title').'</option>
  325:                        <option value="duedate"'.$selected{'duedate'}.'>'.&mt('Due Date').'</option>
  326:                        <option value="discussion"'.$selected{'discussion'}.'>'.&mt('Has New Discussion').'</option>
  327:                     </select>
  328:                     <input type="submit" value="'.&mt('Go').'" />
  329:                  </span>
  330:                </form>');
  331:     }
  332:     # renderer call
  333:     my $renderArgs = { 'cols' => [0,1,2,3],
  334: 		       'sort' => $env{'form.sort'},
  335:                        'url' => '/adm/navmaps',
  336:                        'navmap' => $navmap,
  337:                        'suppressNavmap' => 1,
  338:                        'suppressEmptySequences' => $suppressEmptySequences,
  339:                        'filterFunc' => $filterFunc,
  340: 		       'resource_no_folder_link' => $resource_no_folder_link,
  341: 		       'sort_html'=> $sort_html,
  342:                        'r' => $r,
  343:                        'caller' => 'navmapsdisplay',
  344:                        'linkitems' => \%toplinkitems,
  345:                        'notools' => $notools};
  346:                       
  347:     my $render = &Apache::lonnavmaps::render($renderArgs);
  348: 
  349:     # If no resources were printed, print a reassuring message so the
  350:     # user knows there was no error.
  351:     if ($renderArgs->{'counter'} == 0) {
  352:         my $noresmsg;
  353:         if ($showOnlyHomework) {
  354:             $noresmsg = &mt('All homework is currently completed.');
  355:         } else { # both jumpToFirstHomework and normal use the same: course must be empty
  356:             $noresmsg = &mt('This course is empty.');
  357:             if (($renderArgs->{'deeplinknolist'}) &&
  358:                 ($env{'request.course.deeponlyprot'})) {
  359:                 my ($linkprot,$currmatch,$othermatches,@names);
  360:                 if ($env{'request.linkprot'}) {
  361:                     ($linkprot) = split(/:/,$env{'request.linkprot'});
  362:                 }
  363:                 foreach my $launcher (split(/&/,$env{'request.course.deeponlyprot'})) {
  364:                     my ($name,$itemnums) = split(/:/,$launcher);
  365:                     my @nums = split(/,/,$itemnums);
  366:                     if (($linkprot) &&
  367:                         (grep(/^\Q$linkprot\E$/,@nums))) {
  368:                         $currmatch = &LONCAPA::unescape($name);
  369:                         if (@nums > 1) {
  370:                             $othermatches = 1;
  371:                         }
  372:                     } else {
  373:                         push(@names,&LONCAPA::unescape($name));
  374:                     }
  375:                 }
  376:                 my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  377:                 my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  378:                 my $has_supp = &Apache::lonnet::has_unhidden_suppfiles($cnum,$cdom);
  379:                 if ($linkprot) {
  380:                     if ($currmatch) {
  381:                         if ($has_supp) {
  382:                             $noresmsg = &mt('No main content available when accessed using the link you followed from [_1].',
  383:                                             $currmatch);
  384:                         } else {
  385:                             $noresmsg = &mt('No content available when accessed using the link you followed from [_1].',
  386:                                             $currmatch);
  387:                         }
  388:                         if ($othermatches) {
  389:                             $noresmsg = '<br />';
  390:                             if ($has_supp) {
  391:                                 $noresmsg .= &mt('Main content may be available by following a different link from [_1].',
  392:                                                  $currmatch);
  393:                             } else {
  394:                                 $noresmsg .= &mt('Content may be available by following a different link from [_1].',
  395:                                                  $currmatch); 
  396:                             }
  397:                         }
  398:                     } else {
  399:                         if ($has_supp) {
  400:                             $noresmsg = &mt('No main content available using the link you followed.');
  401:                         } else {
  402:                             $noresmsg = &mt('No content available using the link you followed.');
  403:                         }
  404:                     }
  405:                 } elsif (@names > 0) {
  406:                     if ($has_supp) {
  407:                         $noresmsg = &mt('No main content available from direct login to this course.');
  408:                     } else {
  409:                         $noresmsg = &mt('No content available from direct login to this course.');
  410:                     }
  411:                 }
  412:                 if (@names == 1) {
  413:                     $noresmsg .= '<br />';
  414:                     if ($has_supp) {
  415:                         $noresmsg .= &mt('Main content is likely available by following links from [_1]',
  416:                                          $names[0]);
  417:                     } else {
  418:                         $noresmsg .= &mt('Content is likely available by following links from [_1]',
  419:                                          $names[0]);
  420:                     }
  421:                 } elsif (@names > 1) {
  422:                     $noresmsg .= '<br />';
  423:                     if ($has_supp) {
  424:                         $noresmsg .= &mt('Main content is likely available by following links from the following: [_1]',
  425:                                          join(', ',@names));
  426:                     } else {
  427:                         $noresmsg .= &mt('Content is likely available by following links from the following: [_1]',
  428:                                          join(', ',@names));
  429:                     }
  430:                 }
  431:             }
  432:         }
  433:         $r->print('<p><span class="LC_info">'.$noresmsg.'</span></p>');
  434:     }
  435:     &endContentScreen($r);
  436:     $r->print(&Apache::loncommon::end_page());
  437:     $r->rflush();
  438: 
  439:     return OK;
  440: }
  441: 
  442: sub startpage {
  443:     my ($r) = @_;
  444: # ----------------------------------------------------- Force menu registration
  445:     # Header
  446:     my $course_type = &Apache::loncommon::course_type();
  447:     my $title = $course_type . ' Contents';
  448:     my $brcrum = [{href => '/adm/navmaps',
  449:                    text => &mt($course_type . ' Contents'),
  450:                    no_mt => 1},
  451:                  ];
  452:     my $args = {'bread_crumbs' => $brcrum};
  453:     $r->print(&Apache::loncommon::start_page($title,undef,$args).
  454:               '<script type="text/javascript">'."\n".
  455:               '// <![CDATA['."\n".
  456:               'window.focus();'."\n".
  457:               '// ]]>'."\n".
  458:               '</script>');
  459:     return;
  460: }
  461: 
  462: sub startContentScreen {
  463:     my ($r,$mode,$course_type)=@_;
  464: 
  465:     $r->print("\n".'<div class="LC_landmark" role="main">'.
  466:               '<ul class="LC_TabContentBigger" id="mainnav">'."\n");
  467:     $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");
  468:     my $supptab;
  469:     if ($env{'request.role.adv'}) {
  470:         $supptab = 1;
  471:     } else {
  472:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  473:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  474:         $supptab = &Apache::lonnet::has_unhidden_suppfiles($cnum,$cdom);
  475:     }
  476:     if ($supptab) {
  477:         $r->print('<li '.(($mode eq 'supplemental')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>');
  478:     }
  479:     unless ($course_type eq 'Placement') {
  480:         $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");
  481:         $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");
  482:     }
  483:     $r->print("\n".'</ul>'."\n");
  484:     $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;">');
  485: }
  486: 
  487: sub endContentScreen {
  488:    my ($r)=@_;
  489:    $r->print('</div></div></div></div>');
  490: }
  491: 
  492: 1;
  493: __END__
  494: 

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