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

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

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