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

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

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