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

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

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