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

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.7! raeburn     4: # $Id: lonnavdisplay.pm,v 1.22.4.6 2015/03/11 15:43:40 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.7! 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.22.4.6  raeburn    52:         &Apache::loncommon::content_type($r,'text/html');
1.1       albertel   53:         $r->send_http_header;
                     54:         return OK;
                     55:     }
                     56: 
1.22.4.5  raeburn    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.22.4.6  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') {
1.1       albertel   70:         &Apache::loncommon::content_type($r,'text/html');
1.22.4.6  raeburn    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:         }
1.1       albertel   84:     }
                     85: 
                     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.22.4.6  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.
                    120:               '<script type="text/javascript">window.focus();</script>');
1.20      raeburn   121:     &startContentScreen($r,'navmaps');
1.1       albertel  122:     $r->rflush();
                    123: 
                    124:     # Check that it's defined
                    125:     if (!($navmap->courseMapDefined())) {
                    126: 	$r->print(&Apache::loncommon::help_open_menu('Navigation Screen','Navigation_Screen',undef,'RAT'));
                    127:         $r->print('<span class="LC_error">'.&mt('Coursemap undefined.').
                    128: 		  '</span>' .
                    129:                   &Apache::loncommon::end_page());
                    130:         return OK;
                    131:     }
                    132: 
1.22.4.6  raeburn   133:     my %toplinkitems=();
1.21      raeburn   134:     my @resources = $navmap->retrieveResources();
                    135:     my $sequenceCount = 0;
                    136:     my $problemCount = 0;
                    137:     my $notaprobCount = 0;
                    138:     my $sequenceId;
                    139:     my $notools;
                    140:     foreach my $curRes (@resources) {
                    141:         if (ref($curRes)) {
                    142:             if ($curRes->is_sequence()) {
1.1       albertel  143:                 $sequenceCount++;
                    144:                 $sequenceId = $curRes->map_pc();
1.21      raeburn   145:             } elsif ($curRes->is_problem()) {
                    146:                 $problemCount ++;
                    147:             } else {
                    148:                 $notaprobCount ++;
1.1       albertel  149:             }
                    150:         }
1.21      raeburn   151:     }
                    152:     if (($sequenceCount == 1) && (!$problemCount) && ($notaprobCount <= 1)) {
                    153:         $notools = 1;
                    154:     }
                    155: 
                    156:     # If there's only one map in the top-level and we don't
                    157:     # already have a filter, automatically display it
                    158:     if ($ENV{QUERY_STRING} !~ /filter/) {
1.1       albertel  159:         if ($sequenceCount == 1) {
                    160:             # The automatic iterator creation in the render call 
                    161:             # will pick this up. We know the condition because
                    162:             # the defined($env{'form.filter'}) also ensures this
                    163:             # is a fresh call.
                    164:             $env{'form.filter'} = "$sequenceId";
                    165:         }
                    166:     }
                    167: 
                    168:     # Check to see if the student is jumping to next open, do-able problem
                    169:     if ($ENV{QUERY_STRING} =~ /^jumpToFirstHomework/) {
                    170:         # Find the next homework problem that they can do.
                    171:         my $iterator = $navmap->getIterator(undef, undef, undef, 1);
                    172:         my $curRes;
                    173:         my $foundDoableProblem = 0;
                    174:         my $minimumduedate;
1.2       albertel  175:         my $now = time();
                    176: 	
1.1       albertel  177:         while ($curRes = $iterator->next()) {
                    178:             if (ref($curRes) && $curRes->is_problem()) {
                    179:                 my $status = $curRes->status();
1.2       albertel  180: 		my $thisduedate=$curRes->duedate();
                    181:                 if ($thisduedate > $now 
                    182: 		    && $curRes->completable()) {
1.1       albertel  183:                         
                    184:                     $foundDoableProblem = 1;
                    185: 
1.2       albertel  186:                     if (!defined($minimumduedate)
                    187:                         || $thisduedate<$minimumduedate) {
1.1       albertel  188: 			# Pop open all previous maps
                    189: 			my $stack = $iterator->getStack();
                    190: 			pop @$stack; # last resource in the stack is the problem
                    191: 			# itself, which we don't need in the map stack
                    192: 			my @mapPcs = map {$_->map_pc()} @$stack;
                    193: 			$env{'form.filter'} = join(',', @mapPcs);
                    194: 			
                    195: 			# Mark as both "here" and "jump"
                    196: 			$env{'form.postsymb'} = $curRes->symb();
                    197:                         $minimumduedate=$thisduedate;
                    198: 		    }
                    199:                 }
                    200:             }
                    201:         }
                    202: 
                    203:         # If we found no problems, print a note to that effect.
                    204:         if (!$foundDoableProblem) {
1.7       schulted  205:             $r->print("<span class=\"LC_info\">"
1.4       bisitz    206:                      .&mt("All homework assignments have been completed.")
1.7       schulted  207:                      ."</span>");
1.1       albertel  208:         }
                    209:     } else {
1.17      raeburn   210:         my $link = 'navmaps?jumpToFirstHomework';
                    211:         if ($env{'form.register'}) {
                    212:             $link .= '&amp;register='.$env{'form.register'}; 
                    213:         }
1.21      raeburn   214:         unless ($notools) {
                    215: 	    &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'firsthomework',
                    216: 					      'location.href="'.$link.'"',
                    217: 					      "Show my first due problem");
                    218:         }
1.1       albertel  219:     }
                    220: 
                    221:     my $suppressEmptySequences = 0;
                    222:     my $filterFunc = undef;
                    223:     my $resource_no_folder_link = 0;
                    224: 
                    225:     # Display only due homework.
                    226:     my $showOnlyHomework = 0;
                    227:     if ($env{'form.showOnlyHomework'} eq "1") {
                    228:         $showOnlyHomework = 1;
                    229:         $suppressEmptySequences = 1;
                    230:         $filterFunc = sub { my $res = shift; 
                    231:                             return $res->completable() || $res->is_map();
                    232:                         };
1.17      raeburn   233:         my $link = 'navmaps?sort='.$env{'form.sort'};
                    234:         if ($env{'form.register'}) {
                    235:             $link .= '&amp;register='.$env{'form.register'};
                    236:         }
1.1       albertel  237: 	&Apache::lonnavmaps::add_linkitem(\%toplinkitems,'everything',
1.17      raeburn   238: 					  'location.href="'.$link.'"',
                    239: 					  'Show everything');
1.7       schulted  240:         $r->print("<span class=\"LC_info\">".&mt("Uncompleted Problems")."</span>");
1.1       albertel  241:         $env{'form.filter'} = '';
                    242:         $env{'form.condition'} = 1;
                    243: 	$resource_no_folder_link = 1;
                    244:     } else {
1.17      raeburn   245:         my $link = 'navmaps?sort='.$env{'form.sort'}.'&amp;showOnlyHomework=1';
                    246:         if ($env{'form.register'}) {
                    247:             $link .= '&amp;register='.$env{'form.register'};
                    248:         }
1.21      raeburn   249:         unless ($notools) {
                    250: 	    &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'uncompleted',
                    251: 					      'location.href="'.$link.'"',
                    252: 					      'Show only uncompleted problems');
                    253:         }
1.1       albertel  254:     }
                    255: 
1.10      bisitz    256:     my %selected=($env{'form.sort'} => ' selected="selected"');
1.21      raeburn   257:     my $sort_html;
                    258:     unless ($notools) {
                    259:         $sort_html=(
                    260:               '<form name="sortForm" action="">
1.17      raeburn   261:                  <span class="LC_nobreak">
                    262:                     <input type="hidden" name="showOnlyHomework" value="'.$env{'form.showOnlyHomework'}.'" />
                    263:                     '.&mt('Sort by:').'
1.18      bisitz    264:                     <select name="sort" onchange="document.sortForm.submit()">
1.17      raeburn   265:                        <option value="default"'.$selected{'default'}.'>'.&mt('Default').'</option>
                    266:                        <option value="title"'.$selected{'title'}.'>'.&mt('Title').'</option>
1.22.4.3  raeburn   267:                        <option value="duedate"'.$selected{'duedate'}.'>'.&mt('Due Date').'</option>
1.17      raeburn   268:                        <option value="discussion"'.$selected{'discussion'}.'>'.&mt('Has New Discussion').'</option>
1.1       albertel  269:                     </select>
1.17      raeburn   270:                     <input type="hidden" name="register" value="'.$env{'form.register'}.'" />
1.9       bisitz    271:                  </span>
1.17      raeburn   272:                </form>');
1.21      raeburn   273:     }
1.1       albertel  274:     # renderer call
                    275:     my $renderArgs = { 'cols' => [0,1,2,3],
                    276: 		       'sort' => $env{'form.sort'},
                    277:                        'url' => '/adm/navmaps',
                    278:                        'navmap' => $navmap,
                    279:                        'suppressNavmap' => 1,
                    280:                        'suppressEmptySequences' => $suppressEmptySequences,
                    281:                        'filterFunc' => $filterFunc,
                    282: 		       'resource_no_folder_link' => $resource_no_folder_link,
                    283: 		       'sort_html'=> $sort_html,
                    284:                        'r' => $r,
                    285:                        'caller' => 'navmapsdisplay',
1.21      raeburn   286:                        'linkitems' => \%toplinkitems,
                    287:                        'notools' => $notools};
                    288:                       
1.1       albertel  289:     my $render = &Apache::lonnavmaps::render($renderArgs);
                    290: 
                    291:     # If no resources were printed, print a reassuring message so the
                    292:     # user knows there was no error.
                    293:     if ($renderArgs->{'counter'} == 0) {
                    294:         if ($showOnlyHomework) {
1.7       schulted  295:             $r->print("<p><span class=\"LC_info\">".&mt("All homework is currently completed.")."</span></p>");
1.1       albertel  296:         } else { # both jumpToFirstHomework and normal use the same: course must be empty
1.7       schulted  297:             $r->print("<p><span class=\"LC_info\">".&mt("This course is empty.")."</span></p>");
1.1       albertel  298:         }
                    299:     }
1.20      raeburn   300:     &endContentScreen($r);
1.1       albertel  301:     $r->print(&Apache::loncommon::end_page());
                    302:     $r->rflush();
                    303: 
                    304:     return OK;
                    305: }
                    306: 
1.20      raeburn   307: sub startContentScreen {
                    308:     my ($r,$mode)=@_;
                    309: 
                    310:     $r->print("\n".'<ul class="LC_TabContentBigger" id="mainnav">'."\n");
1.22      www       311:     $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   312:     my $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
                    313:     my ($suppcount,$errors);
                    314:     unless ($allowed) {
                    315:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    316:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    317:         ($suppcount,$errors) = &Apache::lonnet::get_numsuppfiles($cnum,$cdom);
                    318:     }
                    319:     if ($allowed || $suppcount) {
                    320:         $r->print('<li '.(($mode eq 'supplemental')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>');
                    321:     }
1.20      raeburn   322:     $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");
                    323:     $r->print("\n".'</ul>'."\n");
                    324:     $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;">');
                    325: }
                    326: 
                    327: sub endContentScreen {
                    328:    my ($r)=@_;
                    329:    $r->print('</div></div></div>');
                    330: }
                    331: 
1.1       albertel  332: 1;
                    333: __END__
                    334: 

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