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

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # Navigate Maps Handler
                      3: #
1.19    ! www         4: # $Id: lonnavdisplay.pm,v 1.18 2010/06/24 14:21:39 bisitz 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.19    ! www        40: use Apache::londocs();
1.2       albertel   41: use Time::HiRes qw( gettimeofday tv_interval );
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:     #my $t0=[&gettimeofday()];
                     51:     # Handle header-only request
                     52:     if ($r->header_only) {
                     53:         if ($env{'browser.mathml'}) {
                     54:             &Apache::loncommon::content_type($r,'text/xml');
                     55:         } else {
                     56:             &Apache::loncommon::content_type($r,'text/html');
                     57:         }
                     58:         $r->send_http_header;
                     59:         return OK;
                     60:     }
                     61: 
                     62:     # Send header, don't cache this page
                     63:     if ($env{'browser.mathml'}) {
                     64:         &Apache::loncommon::content_type($r,'text/xml');
                     65:     } else {
                     66:         &Apache::loncommon::content_type($r,'text/html');
                     67:     }
                     68:     &Apache::loncommon::no_cache($r);
                     69: 
                     70:     my %toplinkitems=();
                     71: 
                     72:     # Create the nav map
                     73:     my $navmap = Apache::lonnavmaps::navmap->new();
                     74: 
                     75:     if (!defined($navmap)) {
                     76:         my $requrl = $r->uri;
                     77:         $env{'user.error.msg'} = "$requrl:bre:0:0:Course not initialized";
1.5       raeburn    78:         $env{'user.reinit'} = 1;
1.1       albertel   79:         return HTTP_NOT_ACCEPTABLE;
                     80:     }
                     81:     $r->send_http_header;
                     82: 
                     83: # ------------------------------------------------------------ Get query string
1.17      raeburn    84:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['sort','showOnlyHomework','postsymb','register']);
1.1       albertel   85:     
                     86: # ----------------------------------------------------- Force menu registration
                     87:     # Header
                     88:     my $course_type = &Apache::loncommon::course_type();
1.15      droeschl   89:     my $title = $course_type . ' Contents';
1.17      raeburn    90:     my ($start_page,$args);
                     91:     if ($env{'form.register'}) {
                     92:         $args = {'force_register' => $env{'form.register'}};
                     93:         $start_page = &Apache::loncommon::start_page($title,undef,$args);
                     94:     } else {
                     95:         my $brcrum = [{href => '/adm/navmaps',
                     96:                        text => &mt($course_type . ' Contents'),
                     97:                        no_mt => 1},
                     98:                      ];
                     99:         $args = {'bread_crumbs' => $brcrum};
                    100:         $start_page = &Apache::loncommon::start_page($title,undef,$args);
                    101:     }
                    102:     $r->print($start_page.
                    103:               '<script type="text/javascript">window.focus();</script>');
1.19    ! www       104:     &Apache::londocs::startContentScreen($r,'navmaps');
1.1       albertel  105:     $r->rflush();
                    106: 
                    107:     # Check that it's defined
                    108:     if (!($navmap->courseMapDefined())) {
                    109: 	$r->print(&Apache::loncommon::help_open_menu('Navigation Screen','Navigation_Screen',undef,'RAT'));
                    110:         $r->print('<span class="LC_error">'.&mt('Coursemap undefined.').
                    111: 		  '</span>' .
                    112:                   &Apache::loncommon::end_page());
                    113:         return OK;
                    114:     }
                    115: 
                    116:     # See if there's only one map in the top-level, if we don't
                    117:     # already have a filter... if so, automatically display it
                    118:     # (older code; should use retrieveResources)
                    119:     if ($ENV{QUERY_STRING} !~ /filter/) {
                    120:         my $iterator = $navmap->getIterator(undef, undef, undef, 0);
                    121:         my $curRes;
                    122:         my $sequenceCount = 0;
                    123:         my $sequenceId;
                    124:         while ($curRes = $iterator->next()) {
                    125:             if (ref($curRes) && $curRes->is_sequence()) {
                    126:                 $sequenceCount++;
                    127:                 $sequenceId = $curRes->map_pc();
                    128:             }
                    129:         }
                    130:         
                    131:         if ($sequenceCount == 1) {
                    132:             # The automatic iterator creation in the render call 
                    133:             # will pick this up. We know the condition because
                    134:             # the defined($env{'form.filter'}) also ensures this
                    135:             # is a fresh call.
                    136:             $env{'form.filter'} = "$sequenceId";
                    137:         }
                    138:     }
                    139: 
                    140:     # Check to see if the student is jumping to next open, do-able problem
                    141:     if ($ENV{QUERY_STRING} =~ /^jumpToFirstHomework/) {
                    142:         # Find the next homework problem that they can do.
                    143:         my $iterator = $navmap->getIterator(undef, undef, undef, 1);
                    144:         my $curRes;
                    145:         my $foundDoableProblem = 0;
                    146:         my $minimumduedate;
1.2       albertel  147:         my $now = time();
                    148: 	
1.1       albertel  149:         while ($curRes = $iterator->next()) {
                    150:             if (ref($curRes) && $curRes->is_problem()) {
                    151:                 my $status = $curRes->status();
1.2       albertel  152: 		my $thisduedate=$curRes->duedate();
                    153:                 if ($thisduedate > $now 
                    154: 		    && $curRes->completable()) {
1.1       albertel  155:                         
                    156:                     $foundDoableProblem = 1;
                    157: 
1.2       albertel  158:                     if (!defined($minimumduedate)
                    159:                         || $thisduedate<$minimumduedate) {
1.1       albertel  160: 			# Pop open all previous maps
                    161: 			my $stack = $iterator->getStack();
                    162: 			pop @$stack; # last resource in the stack is the problem
                    163: 			# itself, which we don't need in the map stack
                    164: 			my @mapPcs = map {$_->map_pc()} @$stack;
                    165: 			$env{'form.filter'} = join(',', @mapPcs);
                    166: 			
                    167: 			# Mark as both "here" and "jump"
                    168: 			$env{'form.postsymb'} = $curRes->symb();
                    169:                         $minimumduedate=$thisduedate;
                    170: 		    }
                    171:                 }
                    172:             }
                    173:         }
                    174: 
                    175:         # If we found no problems, print a note to that effect.
                    176:         if (!$foundDoableProblem) {
1.7       schulted  177:             $r->print("<span class=\"LC_info\">"
1.4       bisitz    178:                      .&mt("All homework assignments have been completed.")
1.7       schulted  179:                      ."</span>");
1.1       albertel  180:         }
                    181:     } else {
1.17      raeburn   182:         my $link = 'navmaps?jumpToFirstHomework';
                    183:         if ($env{'form.register'}) {
                    184:             $link .= '&amp;register='.$env{'form.register'}; 
                    185:         }
1.1       albertel  186: 	&Apache::lonnavmaps::add_linkitem(\%toplinkitems,'firsthomework',
1.17      raeburn   187: 					  'location.href="'.$link.'"',
1.1       albertel  188: 					  "Show my first due problem");
                    189:     }
                    190: 
                    191:     my $suppressEmptySequences = 0;
                    192:     my $filterFunc = undef;
                    193:     my $resource_no_folder_link = 0;
                    194: 
                    195:     # Display only due homework.
                    196:     my $showOnlyHomework = 0;
                    197:     if ($env{'form.showOnlyHomework'} eq "1") {
                    198:         $showOnlyHomework = 1;
                    199:         $suppressEmptySequences = 1;
                    200:         $filterFunc = sub { my $res = shift; 
                    201:                             return $res->completable() || $res->is_map();
                    202:                         };
1.17      raeburn   203:         my $link = 'navmaps?sort='.$env{'form.sort'};
                    204:         if ($env{'form.register'}) {
                    205:             $link .= '&amp;register='.$env{'form.register'};
                    206:         }
1.1       albertel  207: 	&Apache::lonnavmaps::add_linkitem(\%toplinkitems,'everything',
1.17      raeburn   208: 					  'location.href="'.$link.'"',
                    209: 					  'Show everything');
1.7       schulted  210:         $r->print("<span class=\"LC_info\">".&mt("Uncompleted Problems")."</span>");
1.1       albertel  211:         $env{'form.filter'} = '';
                    212:         $env{'form.condition'} = 1;
                    213: 	$resource_no_folder_link = 1;
                    214:     } else {
1.17      raeburn   215:         my $link = 'navmaps?sort='.$env{'form.sort'}.'&amp;showOnlyHomework=1';
                    216:         if ($env{'form.register'}) {
                    217:             $link .= '&amp;register='.$env{'form.register'};
                    218:         }
1.1       albertel  219: 	&Apache::lonnavmaps::add_linkitem(\%toplinkitems,'uncompleted',
1.17      raeburn   220: 					  'location.href="'.$link.'"',
                    221: 					  'Show only uncompleted problems');
1.1       albertel  222:     }
                    223: 
1.10      bisitz    224:     my %selected=($env{'form.sort'} => ' selected="selected"');
1.18      bisitz    225:     my $sort_html=('<form name="sortForm" action="">
1.17      raeburn   226:                  <span class="LC_nobreak">
                    227:                     <input type="hidden" name="showOnlyHomework" value="'.$env{'form.showOnlyHomework'}.'" />
                    228:                     '.&mt('Sort by:').'
1.18      bisitz    229:                     <select name="sort" onchange="document.sortForm.submit()">
1.17      raeburn   230:                        <option value="default"'.$selected{'default'}.'>'.&mt('Default').'</option>
                    231:                        <option value="title"'.$selected{'title'}.'>'.&mt('Title').'</option>
                    232:                        <option value="duedate"'.$selected{'duedate'}.'>'.&mt('Duedate').'</option>
                    233:                        <option value="discussion"'.$selected{'discussion'}.'>'.&mt('Has New Discussion').'</option>
1.1       albertel  234:                     </select>
1.17      raeburn   235:                     <input type="hidden" name="register" value="'.$env{'form.register'}.'" />
1.9       bisitz    236:                  </span>
1.17      raeburn   237:                </form>');
1.1       albertel  238:     # renderer call
                    239:     my $renderArgs = { 'cols' => [0,1,2,3],
                    240: 		       'sort' => $env{'form.sort'},
                    241:                        'url' => '/adm/navmaps',
                    242:                        'navmap' => $navmap,
                    243:                        'suppressNavmap' => 1,
                    244:                        'suppressEmptySequences' => $suppressEmptySequences,
                    245:                        'filterFunc' => $filterFunc,
                    246: 		       'resource_no_folder_link' => $resource_no_folder_link,
                    247: 		       'sort_html'=> $sort_html,
                    248:                        'r' => $r,
                    249:                        'caller' => 'navmapsdisplay',
                    250:                        'linkitems' => \%toplinkitems};
                    251:     my $render = &Apache::lonnavmaps::render($renderArgs);
                    252: 
                    253:     # If no resources were printed, print a reassuring message so the
                    254:     # user knows there was no error.
                    255:     if ($renderArgs->{'counter'} == 0) {
                    256:         if ($showOnlyHomework) {
1.7       schulted  257:             $r->print("<p><span class=\"LC_info\">".&mt("All homework is currently completed.")."</span></p>");
1.1       albertel  258:         } else { # both jumpToFirstHomework and normal use the same: course must be empty
1.7       schulted  259:             $r->print("<p><span class=\"LC_info\">".&mt("This course is empty.")."</span></p>");
1.1       albertel  260:         }
                    261:     }
                    262:     #my $td=&tv_interval($t0);
                    263:     #$r->print("<br />$td");
1.19    ! www       264:     &Apache::londocs::endContentScreen($r);
1.1       albertel  265:     $r->print(&Apache::loncommon::end_page());
                    266:     $r->rflush();
                    267: 
                    268:     return OK;
                    269: }
                    270: 
                    271: 1;
                    272: __END__
                    273: 

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