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

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

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