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

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

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