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

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # Navigate Maps Handler
                      3: #
1.13.6.2! raeburn     4: # $Id: lonnavdisplay.pm,v 1.13.6.1 2010/10/04 21:27:20 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;
                     33: use Apache::Constants qw(:common :http);
                     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.2       albertel   40: use Time::HiRes qw( gettimeofday tv_interval );
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:     #my $t0=[&gettimeofday()];
                     50:     # Handle header-only request
                     51:     if ($r->header_only) {
                     52:         if ($env{'browser.mathml'}) {
                     53:             &Apache::loncommon::content_type($r,'text/xml');
                     54:         } else {
                     55:             &Apache::loncommon::content_type($r,'text/html');
                     56:         }
                     57:         $r->send_http_header;
                     58:         return OK;
                     59:     }
                     60: 
                     61:     # Send header, don't cache this page
                     62:     if ($env{'browser.mathml'}) {
                     63:         &Apache::loncommon::content_type($r,'text/xml');
                     64:     } else {
                     65:         &Apache::loncommon::content_type($r,'text/html');
                     66:     }
                     67:     &Apache::loncommon::no_cache($r);
                     68: 
                     69:     my %toplinkitems=();
                     70:     &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'blank','',
                     71: 				      "Select Action");
                     72:     if ($ENV{QUERY_STRING} eq 'collapseExternal') {
                     73: 	&Apache::lonnet::put('environment',{'remotenavmap' => 'off'});
1.3       raeburn    74: 	&Apache::lonnet::appenv({'environment.remotenavmap' => 'off'});
1.1       albertel   75: 	my $menu=&Apache::lonmenu::reopenmenu();
                     76: 	my $navstatus=&Apache::lonmenu::get_nav_status();
                     77: 	if ($menu) {
                     78: 	    $menu=(<<MENU)
                     79:              swmenu=$menu
                     80:              swmenu.clearTimeout(swmenu.menucltim);
                     81: 	     $navstatus
                     82: MENU
                     83:         } else {
                     84: 	    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
                     85: 	    my $mainwindow='window.open('.$nothing.',"loncapaclient","",false);';
                     86: 	    $menu=(<<MENU)
                     87:              swmenu=$mainwindow
                     88: 	     $navstatus
                     89: MENU
                     90: 	}
                     91:         $r->send_http_header;
                     92: 	my $js =<<"ENDSUBM";
                     93: 	  <script type="text/javascript">
                     94:  	    function submitthis() {
                     95: 		    $menu
                     96: 		    self.close();
                     97: 	    }
                     98: 	
                     99:   	  </script>
                    100: ENDSUBM
                    101:         $r->print(&Apache::loncommon::start_page(undef,$js,
                    102: 						 {'only_body' => 1,
                    103: 						  'bgcolor'   => '#FFFFFF',
                    104: 						  'add_entries' => 
                    105: 						      {'onload' =>
                    106: 							   "submitthis()"}}).
                    107: 		  &Apache::loncommon::end_page());
                    108: 
                    109:         return OK;
                    110:     }
                    111:     if ($ENV{QUERY_STRING} =~ /^launchExternal/) {
                    112: 	&Apache::lonnet::put('environment',{'remotenavmap' => 'on'});
1.3       raeburn   113: 	&Apache::lonnet::appenv({'environment.remotenavmap' => 'on'});
1.1       albertel  114:  	my $menu=&Apache::lonmenu::reopenmenu();
                    115: 	my $navstatus=&Apache::lonmenu::get_nav_status();
                    116: 	if ($menu) {
                    117: 	    $r->print(<<MENU);
                    118:              <script type="text/javascript">
                    119:              swmenu=$menu
                    120:              swmenu.clearTimeout(swmenu.menucltim);
                    121: 	     $navstatus
                    122:              </script>
                    123: MENU
                    124:         }
                    125:    }
                    126:     if ($ENV{QUERY_STRING} eq 'turningOffExternal') {
                    127: 	$env{'environment.remotenavmap'}='off';
                    128:     }
                    129: 
                    130:     # Create the nav map
                    131:     my $navmap = Apache::lonnavmaps::navmap->new();
                    132: 
                    133:     if (!defined($navmap)) {
                    134:         my $requrl = $r->uri;
                    135:         $env{'user.error.msg'} = "$requrl:bre:0:0:Course not initialized";
1.5       raeburn   136:         $env{'user.reinit'} = 1;
1.1       albertel  137:         return HTTP_NOT_ACCEPTABLE;
                    138:     }
                    139:     $r->send_http_header;
                    140: 
                    141: # ------------------------------------------------------------ Get query string
1.13.6.1  raeburn   142:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['sort','showOnlyHomework','postsymb','register']);
1.1       albertel  143:     
                    144: # ----------------------------------------------------- Force menu registration
                    145:     my $body_only='';
                    146:     my $js;
                    147:     if ($env{'environment.remotenavmap'} eq 'on') {
                    148: 	$js='<script type="text/javascript">
                    149:                 function collapse() {
                    150:                    this.document.location="/adm/navmaps?collapseExternal";
                    151:                 }
                    152:              </script>';
                    153: 	$body_only=1;
                    154:     }
                    155: 
                    156:     # Header
                    157:     my $course_type = &Apache::loncommon::course_type();
1.13.6.2! raeburn   158:     my ($title,$breadcrumb_text,$start_page,$args);
1.13      raeburn   159:     if ($course_type eq 'Community') {
                    160:         $title = 'Community Contents';
                    161:         $breadcrumb_text = &mt('Community Contents');
                    162:     } else {
                    163:         $title = 'Course Contents';
                    164:         $breadcrumb_text = &mt('Course Contents');
                    165:     }
1.13.6.1  raeburn   166:     if ($env{'form.register'}) {
                    167:         $args = {'force_register' => $env{'form.register'},
                    168:                  'only_body'      => $body_only};
                    169:         $start_page = &Apache::loncommon::start_page($title,$js,$args);
                    170:     } else {
                    171:         my $brcrum = [{href => '/adm/navmaps',
                    172:                        text => $breadcrumb_text,
                    173:                        no_mt => 1},
                    174:                      ];
                    175:         $args = {'bread_crumbs' => $brcrum,
                    176:                  'only_body'    => $body_only};
                    177:         $start_page = &Apache::loncommon::start_page($title,$js,$args);
                    178:     }
1.13.6.2! raeburn   179:     $r->print($start_page.
        !           180:               '<script type="text/javascript">window.focus();</script>');
1.1       albertel  181:      
                    182:     $r->rflush();
                    183: 
                    184:     # Check that it's defined
                    185:     if (!($navmap->courseMapDefined())) {
                    186: 	$r->print(&Apache::loncommon::help_open_menu('Navigation Screen','Navigation_Screen',undef,'RAT'));
                    187:         $r->print('<span class="LC_error">'.&mt('Coursemap undefined.').
                    188: 		  '</span>' .
                    189:                   &Apache::loncommon::end_page());
                    190:         return OK;
                    191:     }
                    192: 
                    193:     # See if there's only one map in the top-level, if we don't
                    194:     # already have a filter... if so, automatically display it
                    195:     # (older code; should use retrieveResources)
                    196:     if ($ENV{QUERY_STRING} !~ /filter/) {
                    197:         my $iterator = $navmap->getIterator(undef, undef, undef, 0);
                    198:         my $curRes;
                    199:         my $sequenceCount = 0;
                    200:         my $sequenceId;
                    201:         while ($curRes = $iterator->next()) {
                    202:             if (ref($curRes) && $curRes->is_sequence()) {
                    203:                 $sequenceCount++;
                    204:                 $sequenceId = $curRes->map_pc();
                    205:             }
                    206:         }
                    207:         
                    208:         if ($sequenceCount == 1) {
                    209:             # The automatic iterator creation in the render call 
                    210:             # will pick this up. We know the condition because
                    211:             # the defined($env{'form.filter'}) also ensures this
                    212:             # is a fresh call.
                    213:             $env{'form.filter'} = "$sequenceId";
                    214:         }
                    215:     }
                    216: 
                    217:     if ($ENV{QUERY_STRING} eq 'launchExternal') {
                    218: 	$r->print('
                    219:           <form name="returnwin" action="/adm/flip?postdata=navlaunch%3a" 
                    220:                 method="post" target="loncapaclient">
                    221:           </form>');
                    222: 	$r->print('
                    223:           <script type="text/javascript">
                    224:               this.document.returnwin.submit();
                    225:           </script>');
                    226:     }
                    227: 
                    228:     if ($env{'environment.remotenavmap'} ne 'on') {
                    229: 	$r->print(&launch_win('link','yes',\%toplinkitems));
                    230:     } 
                    231:     if ($env{'environment.remotenavmap'} eq 'on') {
                    232: 	&Apache::lonnavmaps::add_linkitem(\%toplinkitems,'closenav',
                    233: 					  'collapse()',
                    234: 					  "Close navigation window");
                    235:     } 
                    236: 
                    237: 
                    238:     # Check to see if the student is jumping to next open, do-able problem
                    239:     if ($ENV{QUERY_STRING} =~ /^jumpToFirstHomework/) {
                    240:         # Find the next homework problem that they can do.
                    241:         my $iterator = $navmap->getIterator(undef, undef, undef, 1);
                    242:         my $curRes;
                    243:         my $foundDoableProblem = 0;
                    244:         my $minimumduedate;
1.2       albertel  245:         my $now = time();
                    246: 	
1.1       albertel  247:         while ($curRes = $iterator->next()) {
                    248:             if (ref($curRes) && $curRes->is_problem()) {
                    249:                 my $status = $curRes->status();
1.2       albertel  250: 		my $thisduedate=$curRes->duedate();
                    251:                 if ($thisduedate > $now 
                    252: 		    && $curRes->completable()) {
1.1       albertel  253:                         
                    254:                     $foundDoableProblem = 1;
                    255: 
1.2       albertel  256:                     if (!defined($minimumduedate)
                    257:                         || $thisduedate<$minimumduedate) {
1.1       albertel  258: 			# Pop open all previous maps
                    259: 			my $stack = $iterator->getStack();
                    260: 			pop @$stack; # last resource in the stack is the problem
                    261: 			# itself, which we don't need in the map stack
                    262: 			my @mapPcs = map {$_->map_pc()} @$stack;
                    263: 			$env{'form.filter'} = join(',', @mapPcs);
                    264: 			
                    265: 			# Mark as both "here" and "jump"
                    266: 			$env{'form.postsymb'} = $curRes->symb();
                    267:                         $minimumduedate=$thisduedate;
                    268: 		    }
                    269:                 }
                    270:             }
                    271:         }
                    272: 
                    273:         # If we found no problems, print a note to that effect.
                    274:         if (!$foundDoableProblem) {
1.7       schulted  275:             $r->print("<span class=\"LC_info\">"
1.4       bisitz    276:                      .&mt("All homework assignments have been completed.")
1.7       schulted  277:                      ."</span>");
1.1       albertel  278:         }
                    279:     } else {
1.13.6.1  raeburn   280:         my $link = 'navmaps?jumpToFirstHomework';
                    281:         if ($env{'form.register'}) {
                    282:             $link .= '&amp;register='.$env{'form.register'};
                    283:         }
1.1       albertel  284: 	&Apache::lonnavmaps::add_linkitem(\%toplinkitems,'firsthomework',
1.13.6.1  raeburn   285: 					  'location.href="'.$link.'"',
1.1       albertel  286: 					  "Show my first due problem");
                    287:     }
                    288: 
                    289:     my $suppressEmptySequences = 0;
                    290:     my $filterFunc = undef;
                    291:     my $resource_no_folder_link = 0;
                    292: 
                    293:     # Display only due homework.
                    294:     my $showOnlyHomework = 0;
                    295:     if ($env{'form.showOnlyHomework'} eq "1") {
                    296:         $showOnlyHomework = 1;
                    297:         $suppressEmptySequences = 1;
                    298:         $filterFunc = sub { my $res = shift; 
                    299:                             return $res->completable() || $res->is_map();
                    300:                         };
1.13.6.1  raeburn   301:         my $link = 'navmaps?sort='.$env{'form.sort'};
                    302:         if ($env{'form.register'}) {
                    303:             $link .= '&amp;register='.$env{'form.register'};
                    304:         }
1.1       albertel  305: 	&Apache::lonnavmaps::add_linkitem(\%toplinkitems,'everything',
1.13.6.1  raeburn   306: 					  'location.href="'.$link.'"',
1.1       albertel  307: 					  "Show everything");
1.7       schulted  308:         $r->print("<span class=\"LC_info\">".&mt("Uncompleted Problems")."</span>");
1.1       albertel  309:         $env{'form.filter'} = '';
                    310:         $env{'form.condition'} = 1;
                    311: 	$resource_no_folder_link = 1;
                    312:     } else {
1.13.6.2! raeburn   313:         my $link = 'navmaps?sort='.$env{'form.sort'}.'&amp;showOnlyHomework=1';
        !           314:         if ($env{'form.register'}) {
        !           315:             $link .= '&amp;register='.$env{'form.register'};
        !           316:         }
1.1       albertel  317: 	&Apache::lonnavmaps::add_linkitem(\%toplinkitems,'uncompleted',
1.13.6.2! raeburn   318: 					  'location.href="'.$link.'"',
1.1       albertel  319: 					  "Show only uncompleted problems");
                    320:     }
                    321: 
1.10      bisitz    322:     my %selected=($env{'form.sort'} => ' selected="selected"');
1.13.6.1  raeburn   323:     my $sort_html=('<form name="sortForm" action="">
                    324:                  <span class="LC_nobreak">
                    325:                     <input type="hidden" name="showOnlyHomework" value="'.$env{'form.showOnlyHomework'}.'" />
                    326:                     '.&mt('Sort by:').'
                    327:                     <select name="sort" onchange="document.sortForm.submit()">
1.13.6.2! raeburn   328:                        <option value="default"'.$selected{'default'}.'>'.&mt('Default').'</option>
        !           329:                        <option value="title"'.$selected{'title'}.'>'.&mt('Title').'</option>
1.13.6.1  raeburn   330:                        <option value="duedate"'.$selected{'duedate'}.'>'.&mt('Duedate').'</option>
                    331:                        <option value="discussion"'.$selected{'discussion'}.'>'.&mt('Has New Discussion').'</option>
1.1       albertel  332:                     </select>
1.13.6.1  raeburn   333:                     <input type="hidden" name="register" value="'.$env{'form.register'}.'" />
1.9       bisitz    334:                  </span>
1.13.6.1  raeburn   335:                </form>');
1.1       albertel  336:     # renderer call
                    337:     my $renderArgs = { 'cols' => [0,1,2,3],
                    338: 		       'sort' => $env{'form.sort'},
                    339:                        'url' => '/adm/navmaps',
                    340:                        'navmap' => $navmap,
                    341:                        'suppressNavmap' => 1,
                    342:                        'suppressEmptySequences' => $suppressEmptySequences,
                    343:                        'filterFunc' => $filterFunc,
                    344: 		       'resource_no_folder_link' => $resource_no_folder_link,
                    345: 		       'sort_html'=> $sort_html,
                    346:                        'r' => $r,
                    347:                        'caller' => 'navmapsdisplay',
                    348:                        'linkitems' => \%toplinkitems};
                    349:     my $render = &Apache::lonnavmaps::render($renderArgs);
                    350: 
                    351:     # If no resources were printed, print a reassuring message so the
                    352:     # user knows there was no error.
                    353:     if ($renderArgs->{'counter'} == 0) {
                    354:         if ($showOnlyHomework) {
1.7       schulted  355:             $r->print("<p><span class=\"LC_info\">".&mt("All homework is currently completed.")."</span></p>");
1.1       albertel  356:         } else { # both jumpToFirstHomework and normal use the same: course must be empty
1.7       schulted  357:             $r->print("<p><span class=\"LC_info\">".&mt("This course is empty.")."</span></p>");
1.1       albertel  358:         }
                    359:     }
                    360:     #my $td=&tv_interval($t0);
                    361:     #$r->print("<br />$td");
                    362: 
                    363:     $r->print(&Apache::loncommon::end_page());
                    364:     $r->rflush();
                    365: 
                    366:     return OK;
                    367: }
                    368: 
                    369: sub launch_win {
                    370:     my ($mode,$script,$toplinkitems,$firsttime)=@_;
                    371:     my $result;
                    372:     if ($script ne 'no') {
                    373: 	$result.='<script type="text/javascript">';
                    374:     }
                    375:     if ($firsttime) {
                    376: 	$result.='function launch_navmapwin() {
                    377:                  newWindow=open(\'/adm/navmaps?launchExternalRoles\',\'loncapanav\',\'width=400,height=600,scrollbars=1\');
                    378:                }';
                    379:     } else {
                    380: 	$result.='function launch_navmapwin() {
                    381:                  newWindow=open(\'/adm/navmaps?launchExternal\',\'loncapanav\',\'width=400,height=600,scrollbars=1\');
                    382:                }';
                    383:     }
                    384:     if ($mode eq 'now') {
                    385: 	$result.="\nlaunch_navmapwin();\n";
                    386:     }
                    387:     if ($script ne 'no') {
                    388: 	$result.='</script>';
                    389:     }
                    390:     if ($mode eq 'link') {
                    391: 	&Apache::lonnavmaps::add_linkitem($toplinkitems,'launchnav',
                    392: 					  'launch_navmapwin()',
                    393: 					  "Launch navigation window");
                    394:     }
                    395:     return $result;
                    396: }
                    397: 
                    398: 1;
                    399: __END__
                    400: 

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