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

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

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