File:  [LON-CAPA] / loncom / interface / lonnavdisplay.pm
Revision 1.40: download - view: text, annotated - select for diffs
Wed Oct 19 00:03:10 2022 UTC (18 months, 3 weeks ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6975
  Folders and Resources in Supplemental Content area can be hidden using
  Course Editor.

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

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