Annotation of loncom/interface/lonnavdisplay.pm, revision 1.32

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

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