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

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

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