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

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.10.2.3! (raeburn    4:: # $Id: lonnavdisplay.pm,v 1.22.4.10.2.2 2023/01/20 23:04:26 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.
1.22.4.10.2.1  (raeburn   58::     my ($redirect,$url) = &Apache::loncommon::critical_redirect(300,'contents');
1.22.4.5  raeburn    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.8  raeburn    65: # ------------------------------------------------------------ Get query string
                     66:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['sort',
                     67:                                                                   'showOnlyHomework',
1.22.4.10.2.2  (raeburn   68::                                                                   'postsymb']);
1.22.4.6  raeburn    69:     # Check if course needs to be re-initialized
                     70:     my $loncaparev = $r->dir_config('lonVersion');
                     71:     my ($result,@reinit) = &Apache::loncommon::needs_coursereinit($loncaparev);
1.22.4.8  raeburn    72:     my %prog_state=();
                     73:     my $closure;
1.22.4.6  raeburn    74: 
                     75:     if ($result eq 'switch') {
1.1       albertel   76:         &Apache::loncommon::content_type($r,'text/html');
1.22.4.6  raeburn    77:         $r->send_http_header;
                     78:         $r->print(&Apache::loncommon::check_release_result(@reinit));
                     79:         return OK;
1.22.4.10.2.3! (raeburn   80::     }
        !            81::     my ($cid,$cnum,$cdom);
        !            82::     if ($result) {
        !            83::         $cid = $env{'request.course.id'};
        !            84::         $cnum = $env{'course.'.$cid.'.num'};
        !            85::         $cdom = $env{'course.'.$cid.'.domain'};
        !            86::     }
        !            87::     if (($result eq 'main') || ($result eq 'both')) {    
1.22.4.8  raeburn    88:         &Apache::loncommon::content_type($r,'text/html');
                     89:         $r->send_http_header;
                     90:         &startpage($r);
                     91:         my $preamble = '<div id="LC_update_'.$cid.'" class="LC_info">'.
                     92:                        '<br />'.
                     93:                        &mt('Your course session is being updated because of recent changes by course personnel.').
1.22.4.10  raeburn    94:                        ' '.&mt('Please be patient').'.<br /></div>'.
1.22.4.8  raeburn    95:                        '<div style="padding:0;clear:both;margin:0;border:0"></div>';
                     96:         $closure = <<ENDCLOSE;
                     97: <script type="text/javascript">
                     98: // <![CDATA[
                     99: \$("#LC_update_$cid").hide('slow');
                    100: // ]]>
                    101: </script>
                    102: ENDCLOSE
                    103:         %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,undef,$preamble);
                    104:         &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Updating course'));
                    105:         $r->rflush();
                    106:         my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum",\%prog_state,$r);
1.22.4.10  raeburn   107:         &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Finished!'));
1.22.4.6  raeburn   108:         if ($ferr) {
1.22.4.8  raeburn   109:             &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
                    110:             $r->print($closure.&Apache::loncommon::end_page());
1.22.4.6  raeburn   111:             my $requrl = $r->uri;
                    112:             $env{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
                    113:             $env{'user.reinit'} = 1;
                    114:             return HTTP_NOT_ACCEPTABLE;
                    115:         }
1.1       albertel  116:     }
1.22.4.10.2.3! (raeburn  117::     if (($result eq 'both') || ($result eq 'supp')) {
        !           118::         my $possdel;
        !           119::         if ($result eq 'supp') {
        !           120::             $possdel = 1;
        !           121::         }
        !           122::         my ($supplemental,$refs_updated) = &Apache::loncommon::get_supplemental($cnum,$cdom,'',$possdel);
        !           123::         unless ($refs_updated) {
        !           124::             &Apache::loncommon::set_supp_httprefs($cnum,$cdom,$supplemental,$possdel);
        !           125::         }
        !           126::     }
1.1       albertel  127: 
                    128:     # Create the nav map
                    129:     my $navmap = Apache::lonnavmaps::navmap->new();
                    130: 
                    131:     if (!defined($navmap)) {
1.22.4.8  raeburn   132:         if ($result eq 'update') {
                    133:             &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
                    134:             $r->print($closure.&Apache::loncommon::end_page());
                    135:         }
1.1       albertel  136:         my $requrl = $r->uri;
                    137:         $env{'user.error.msg'} = "$requrl:bre:0:0:Course not initialized";
1.5       raeburn   138:         $env{'user.reinit'} = 1;
1.1       albertel  139:         return HTTP_NOT_ACCEPTABLE;
                    140:     }
1.22.4.6  raeburn   141: 
1.22.4.8  raeburn   142:     if ($result eq 'update') {
                    143:         $r->rflush();
                    144:         &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
                    145:         $r->print($closure);
                    146:         $r->rflush();
1.17      raeburn   147:     } else {
1.22.4.8  raeburn   148:         # Send header, don't cache this page
                    149:         &Apache::loncommon::content_type($r,'text/html');
                    150:         $r->send_http_header;
                    151:         &startpage($r);
1.17      raeburn   152:     }
1.22.4.8  raeburn   153: 
1.20      raeburn   154:     &startContentScreen($r,'navmaps');
1.22.4.8  raeburn   155:     unless ($result eq 'update') {
                    156:         $r->rflush();
                    157:     }
1.1       albertel  158: 
                    159:     # Check that it's defined
                    160:     if (!($navmap->courseMapDefined())) {
                    161: 	$r->print(&Apache::loncommon::help_open_menu('Navigation Screen','Navigation_Screen',undef,'RAT'));
                    162:         $r->print('<span class="LC_error">'.&mt('Coursemap undefined.').
                    163: 		  '</span>' .
                    164:                   &Apache::loncommon::end_page());
                    165:         return OK;
                    166:     }
                    167: 
1.22.4.6  raeburn   168:     my %toplinkitems=();
1.21      raeburn   169:     my @resources = $navmap->retrieveResources();
                    170:     my $sequenceCount = 0;
                    171:     my $problemCount = 0;
                    172:     my $notaprobCount = 0;
                    173:     my $sequenceId;
                    174:     my $notools;
                    175:     foreach my $curRes (@resources) {
                    176:         if (ref($curRes)) {
                    177:             if ($curRes->is_sequence()) {
1.1       albertel  178:                 $sequenceCount++;
                    179:                 $sequenceId = $curRes->map_pc();
1.21      raeburn   180:             } elsif ($curRes->is_problem()) {
                    181:                 $problemCount ++;
                    182:             } else {
                    183:                 $notaprobCount ++;
1.1       albertel  184:             }
                    185:         }
1.21      raeburn   186:     }
                    187:     if (($sequenceCount == 1) && (!$problemCount) && ($notaprobCount <= 1)) {
                    188:         $notools = 1;
                    189:     }
                    190: 
                    191:     # If there's only one map in the top-level and we don't
                    192:     # already have a filter, automatically display it
                    193:     if ($ENV{QUERY_STRING} !~ /filter/) {
1.1       albertel  194:         if ($sequenceCount == 1) {
                    195:             # The automatic iterator creation in the render call 
                    196:             # will pick this up. We know the condition because
                    197:             # the defined($env{'form.filter'}) also ensures this
                    198:             # is a fresh call.
                    199:             $env{'form.filter'} = "$sequenceId";
                    200:         }
                    201:     }
                    202: 
                    203:     # Check to see if the student is jumping to next open, do-able problem
                    204:     if ($ENV{QUERY_STRING} =~ /^jumpToFirstHomework/) {
                    205:         # Find the next homework problem that they can do.
                    206:         my $iterator = $navmap->getIterator(undef, undef, undef, 1);
                    207:         my $curRes;
                    208:         my $foundDoableProblem = 0;
                    209:         my $minimumduedate;
1.2       albertel  210:         my $now = time();
                    211: 	
1.1       albertel  212:         while ($curRes = $iterator->next()) {
                    213:             if (ref($curRes) && $curRes->is_problem()) {
                    214:                 my $status = $curRes->status();
1.2       albertel  215: 		my $thisduedate=$curRes->duedate();
                    216:                 if ($thisduedate > $now 
                    217: 		    && $curRes->completable()) {
1.1       albertel  218:                         
                    219:                     $foundDoableProblem = 1;
                    220: 
1.2       albertel  221:                     if (!defined($minimumduedate)
                    222:                         || $thisduedate<$minimumduedate) {
1.1       albertel  223: 			# Pop open all previous maps
                    224: 			my $stack = $iterator->getStack();
                    225: 			pop @$stack; # last resource in the stack is the problem
                    226: 			# itself, which we don't need in the map stack
                    227: 			my @mapPcs = map {$_->map_pc()} @$stack;
                    228: 			$env{'form.filter'} = join(',', @mapPcs);
                    229: 			
                    230: 			# Mark as both "here" and "jump"
                    231: 			$env{'form.postsymb'} = $curRes->symb();
                    232:                         $minimumduedate=$thisduedate;
                    233: 		    }
                    234:                 }
                    235:             }
                    236:         }
                    237: 
                    238:         # If we found no problems, print a note to that effect.
                    239:         if (!$foundDoableProblem) {
1.7       schulted  240:             $r->print("<span class=\"LC_info\">"
1.4       bisitz    241:                      .&mt("All homework assignments have been completed.")
1.7       schulted  242:                      ."</span>");
1.1       albertel  243:         }
                    244:     } else {
1.22.4.9  raeburn   245:         my $link = '/adm/navmaps?jumpToFirstHomework';
1.21      raeburn   246:         unless ($notools) {
                    247: 	    &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'firsthomework',
                    248: 					      'location.href="'.$link.'"',
                    249: 					      "Show my first due problem");
                    250:         }
1.1       albertel  251:     }
                    252: 
                    253:     my $suppressEmptySequences = 0;
                    254:     my $filterFunc = undef;
                    255:     my $resource_no_folder_link = 0;
                    256: 
                    257:     # Display only due homework.
                    258:     my $showOnlyHomework = 0;
                    259:     if ($env{'form.showOnlyHomework'} eq "1") {
                    260:         $showOnlyHomework = 1;
                    261:         $suppressEmptySequences = 1;
                    262:         $filterFunc = sub { my $res = shift; 
                    263:                             return $res->completable() || $res->is_map();
                    264:                         };
1.22.4.9  raeburn   265:         my $link = '/adm/navmaps?sort='.$env{'form.sort'};
1.1       albertel  266: 	&Apache::lonnavmaps::add_linkitem(\%toplinkitems,'everything',
1.17      raeburn   267: 					  'location.href="'.$link.'"',
                    268: 					  'Show everything');
1.7       schulted  269:         $r->print("<span class=\"LC_info\">".&mt("Uncompleted Problems")."</span>");
1.1       albertel  270:         $env{'form.filter'} = '';
                    271:         $env{'form.condition'} = 1;
                    272: 	$resource_no_folder_link = 1;
                    273:     } else {
1.22.4.9  raeburn   274:         my $link = '/adm/navmaps?sort='.$env{'form.sort'}.'&amp;showOnlyHomework=1';
1.21      raeburn   275:         unless ($notools) {
                    276: 	    &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'uncompleted',
                    277: 					      'location.href="'.$link.'"',
                    278: 					      'Show only uncompleted problems');
                    279:         }
1.1       albertel  280:     }
                    281: 
1.10      bisitz    282:     my %selected=($env{'form.sort'} => ' selected="selected"');
1.21      raeburn   283:     my $sort_html;
                    284:     unless ($notools) {
                    285:         $sort_html=(
                    286:               '<form name="sortForm" action="">
1.17      raeburn   287:                  <span class="LC_nobreak">
                    288:                     <input type="hidden" name="showOnlyHomework" value="'.$env{'form.showOnlyHomework'}.'" />
                    289:                     '.&mt('Sort by:').'
1.18      bisitz    290:                     <select name="sort" onchange="document.sortForm.submit()">
1.17      raeburn   291:                        <option value="default"'.$selected{'default'}.'>'.&mt('Default').'</option>
                    292:                        <option value="title"'.$selected{'title'}.'>'.&mt('Title').'</option>
1.22.4.3  raeburn   293:                        <option value="duedate"'.$selected{'duedate'}.'>'.&mt('Due Date').'</option>
1.17      raeburn   294:                        <option value="discussion"'.$selected{'discussion'}.'>'.&mt('Has New Discussion').'</option>
1.1       albertel  295:                     </select>
1.9       bisitz    296:                  </span>
1.17      raeburn   297:                </form>');
1.21      raeburn   298:     }
1.1       albertel  299:     # renderer call
                    300:     my $renderArgs = { 'cols' => [0,1,2,3],
                    301: 		       'sort' => $env{'form.sort'},
                    302:                        'url' => '/adm/navmaps',
                    303:                        'navmap' => $navmap,
                    304:                        'suppressNavmap' => 1,
                    305:                        'suppressEmptySequences' => $suppressEmptySequences,
                    306:                        'filterFunc' => $filterFunc,
                    307: 		       'resource_no_folder_link' => $resource_no_folder_link,
                    308: 		       'sort_html'=> $sort_html,
                    309:                        'r' => $r,
                    310:                        'caller' => 'navmapsdisplay',
1.21      raeburn   311:                        'linkitems' => \%toplinkitems,
                    312:                        'notools' => $notools};
                    313:                       
1.1       albertel  314:     my $render = &Apache::lonnavmaps::render($renderArgs);
                    315: 
                    316:     # If no resources were printed, print a reassuring message so the
                    317:     # user knows there was no error.
                    318:     if ($renderArgs->{'counter'} == 0) {
                    319:         if ($showOnlyHomework) {
1.7       schulted  320:             $r->print("<p><span class=\"LC_info\">".&mt("All homework is currently completed.")."</span></p>");
1.1       albertel  321:         } else { # both jumpToFirstHomework and normal use the same: course must be empty
1.7       schulted  322:             $r->print("<p><span class=\"LC_info\">".&mt("This course is empty.")."</span></p>");
1.1       albertel  323:         }
                    324:     }
1.20      raeburn   325:     &endContentScreen($r);
1.1       albertel  326:     $r->print(&Apache::loncommon::end_page());
                    327:     $r->rflush();
                    328: 
                    329:     return OK;
                    330: }
                    331: 
1.22.4.8  raeburn   332: sub startpage {
                    333:     my ($r) = @_;
                    334: # ----------------------------------------------------- Force menu registration
                    335:     # Header
                    336:     my $course_type = &Apache::loncommon::course_type();
                    337:     my $title = $course_type . ' Contents';
1.22.4.10.2.2  (raeburn  338::     my $brcrum = [{href => '/adm/navmaps',
                    339::                    text => &mt($course_type . ' Contents'),
                    340::                    no_mt => 1},
                    341::                  ];
                    342::     my $args = {'bread_crumbs' => $brcrum};
                    343::     my $start_page = &Apache::loncommon::start_page($title,undef,$args);
1.22.4.8  raeburn   344:     $r->print($start_page.
                    345:               '<script type="text/javascript">'."\n".
                    346:               '// <![CDATA['."\n".
                    347:               'window.focus();'."\n".
                    348:               '// ]]>'."\n".
                    349:               '</script>');
                    350:     return;
                    351: }
                    352: 
1.20      raeburn   353: sub startContentScreen {
                    354:     my ($r,$mode)=@_;
                    355: 
                    356:     $r->print("\n".'<ul class="LC_TabContentBigger" id="mainnav">'."\n");
1.22      www       357:     $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.10.2.3! (raeburn  358::     my $supptab;
        !           359::     if ($env{'request.role.adv'}) {
        !           360::         $supptab = 1;
        !           361::     } else {
1.22.4.2  raeburn   362:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    363:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.22.4.10.2.3! (raeburn  364::         $supptab = &Apache::lonnet::has_unhidden_suppfiles($cnum,$cdom);
1.22.4.2  raeburn   365:     }
1.22.4.10.2.3! (raeburn  366::     if ($supptab) {
1.22.4.2  raeburn   367:         $r->print('<li '.(($mode eq 'supplemental')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>');
                    368:     }
1.20      raeburn   369:     $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");
                    370:     $r->print("\n".'</ul>'."\n");
                    371:     $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;">');
                    372: }
                    373: 
                    374: sub endContentScreen {
                    375:    my ($r)=@_;
                    376:    $r->print('</div></div></div>');
                    377: }
                    378: 
1.1       albertel  379: 1;
                    380: __END__
                    381: 

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