Annotation of loncom/interface/lonnavmaps.pm, revision 1.144

1.72      bowersj2    1: 
1.2       www         2: # The LearningOnline Network with CAPA
                      3: # Navigate Maps Handler
1.1       www         4: #
1.144   ! bowersj2    5: # $Id: lonnavmaps.pm,v 1.143 2003/02/13 23:44:30 bowersj2 Exp $
1.20      albertel    6: #
                      7: # Copyright Michigan State University Board of Trustees
                      8: #
                      9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                     10: #
                     11: # LON-CAPA is free software; you can redistribute it and/or modify
                     12: # it under the terms of the GNU General Public License as published by
                     13: # the Free Software Foundation; either version 2 of the License, or
                     14: # (at your option) any later version.
                     15: #
                     16: # LON-CAPA is distributed in the hope that it will be useful,
                     17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     19: # GNU General Public License for more details.
                     20: #
                     21: # You should have received a copy of the GNU General Public License
                     22: # along with LON-CAPA; if not, write to the Free Software
                     23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     24: #
                     25: # /home/httpd/html/adm/gpl.txt
                     26: #
                     27: # http://www.lon-capa.org/
                     28: #
1.2       www        29: # (Page Handler
1.1       www        30: #
1.2       www        31: # (TeX Content Handler
1.1       www        32: #
1.2       www        33: # 05/29/00,05/30 Gerd Kortemeyer)
                     34: # 08/30,08/31,09/06,09/14,09/15,09/16,09/19,09/20,09/21,09/23,
                     35: # 10/02,10/10,10/14,10/16,10/18,10/19,10/31,11/6,11/14,11/16 Gerd Kortemeyer)
1.1       www        36: #
1.17      www        37: # 3/1/1,6/1,17/1,29/1,30/1,2/8,9/21,9/24,9/25 Gerd Kortemeyer
1.21      www        38: # YEAR=2002
                     39: # 1/1 Gerd Kortemeyer
1.105     bowersj2   40: # Oct-Nov Jeremy Bowers
1.2       www        41: 
1.1       www        42: package Apache::lonnavmaps;
                     43: 
                     44: use strict;
1.2       www        45: use Apache::Constants qw(:common :http);
1.18      albertel   46: use Apache::loncommon();
1.73      bowersj2   47: use POSIX qw (floor strftime);
1.2       www        48: 
1.130     www        49: my %navmaphash;
                     50: my %parmhash;
                     51: 
1.133     bowersj2   52: # symbolic constants
                     53: sub SYMB { return 1; }
                     54: sub URL { return 2; }
                     55: sub NOTHING { return 3; }
                     56: 
                     57: # Some data
                     58: 
1.140     bowersj2   59: my $resObj = "Apache::lonnavmaps::resource";
                     60: 
1.135     bowersj2   61: # Keep these mappings in sync with lonquickgrades, which uses the colors
                     62: # instead of the icons.
                     63: my %statusIconMap = 
1.140     bowersj2   64:     ( $resObj->NETWORK_FAILURE    => '',
                     65:       $resObj->NOTHING_SET        => '',
                     66:       $resObj->CORRECT            => 'navmap.correct.gif',
                     67:       $resObj->EXCUSED            => 'navmap.correct.gif',
                     68:       $resObj->PAST_DUE_NO_ANSWER => 'navmap.wrong.gif',
                     69:       $resObj->PAST_DUE_ANSWER_LATER => 'navmap.wrong.gif',
                     70:       $resObj->ANSWER_OPEN        => 'navmap.wrong.gif',
                     71:       $resObj->OPEN_LATER         => '',
                     72:       $resObj->TRIES_LEFT         => 'navmap.open.gif',
                     73:       $resObj->INCORRECT          => 'navmap.wrong.gif',
                     74:       $resObj->OPEN               => 'navmap.open.gif',
                     75:       $resObj->ATTEMPTED          => 'navmap.open.gif' );
1.135     bowersj2   76: 
                     77: my %iconAltTags = 
                     78:     ( 'navmap.correct.gif' => 'Correct',
                     79:       'navmap.wrong.gif'   => 'Incorrect',
                     80:       'navmap.open.gif'    => 'Open' );
1.133     bowersj2   81: 
1.136     bowersj2   82: # Defines a status->color mapping, null string means don't color
                     83: my %colormap = 
1.140     bowersj2   84:     ( $resObj->NETWORK_FAILURE        => '',
                     85:       $resObj->CORRECT                => '',
                     86:       $resObj->EXCUSED                => '#3333FF',
                     87:       $resObj->PAST_DUE_ANSWER_LATER  => '',
                     88:       $resObj->PAST_DUE_NO_ANSWER     => '',
                     89:       $resObj->ANSWER_OPEN            => '#006600',
                     90:       $resObj->OPEN_LATER             => '',
                     91:       $resObj->TRIES_LEFT             => '',
                     92:       $resObj->INCORRECT              => '',
                     93:       $resObj->OPEN                   => '',
                     94:       $resObj->NOTHING_SET            => '' );
1.136     bowersj2   95: # And a special case in the nav map; what to do when the assignment
                     96: # is not yet done and due in less then 24 hours
                     97: my $hurryUpColor = "#FF0000";
                     98: 
1.130     www        99: sub cleanup {
                    100:     if (tied(%navmaphash)){
                    101: 	&Apache::lonnet::logthis('Cleanup navmaps: navmaphash');
                    102:         unless (untie(%navmaphash)) {
                    103: 	    &Apache::lonnet::logthis('Failed cleanup navmaps: navmaphash');
                    104:         }
                    105:     }
                    106:     if (tied(%parmhash)){
                    107: 	&Apache::lonnet::logthis('Cleanup navmaps: parmhash');
                    108:         unless (untie(%parmhash)) {
                    109: 	    &Apache::lonnet::logthis('Failed cleanup navmaps: parmhash');
                    110:         }
                    111:     }
                    112: }
                    113: 
1.1       www       114: sub handler {
1.99      bowersj2  115:     my $r = shift;
1.118     bowersj2  116:     real_handler($r);
                    117: }
                    118: 
                    119: sub real_handler {
                    120:     my $r = shift;
1.2       www       121: 
1.51      bowersj2  122:     # Handle header-only request
                    123:     if ($r->header_only) {
                    124:         if ($ENV{'browser.mathml'}) {
                    125:             $r->content_type('text/xml');
                    126:         } else {
                    127:             $r->content_type('text/html');
                    128:         }
                    129:         $r->send_http_header;
                    130:         return OK;
                    131:     }
                    132: 
                    133:     # Send header, don't cache this page
                    134:     if ($ENV{'browser.mathml'}) {
                    135:         $r->content_type('text/xml');
                    136:     } else {
                    137:         $r->content_type('text/html');
                    138:     }
                    139:     &Apache::loncommon::no_cache($r);
                    140:     $r->send_http_header;
                    141: 
1.106     bowersj2  142:     # Create the nav map
1.51      bowersj2  143:     my $navmap = Apache::lonnavmaps::navmap->new(
                    144:                         $ENV{"request.course.fn"}.".db",
1.80      bowersj2  145:                         $ENV{"request.course.fn"}."_parms.db", 1, 1);
1.51      bowersj2  146: 
1.55      bowersj2  147: 
                    148:     if (!defined($navmap)) {
                    149:         my $requrl = $r->uri;
                    150:         $ENV{'user.error.msg'} = "$requrl:bre:0:0:Course not initialized";
                    151:         return HTTP_NOT_ACCEPTABLE;
                    152:     }
1.64      bowersj2  153: 
1.111     bowersj2  154:     $r->print("<html><head>\n");
1.118     bowersj2  155:     $r->print("<title>Navigate Course Contents</title></head>");
1.111     bowersj2  156: 
1.64      bowersj2  157:     # Header
1.111     bowersj2  158:     $r->print(&Apache::loncommon::bodytag('Navigate Course Contents','',
1.64      bowersj2  159:                                           ''));
                    160:     $r->print('<script>window.focus();</script>');
1.101     bowersj2  161: 
1.124     bowersj2  162:     $r->rflush();
                    163: 
                    164:     # Now that we've displayed some stuff to the user, init the navmap
                    165:     $navmap->init();
                    166: 
1.55      bowersj2  167: 
1.95      bowersj2  168:     $r->print('<br>&nbsp;');
                    169:     $r->rflush();
                    170: 
1.55      bowersj2  171:     # Check that it's defined
                    172:     if (!($navmap->courseMapDefined())) {
                    173:         $r->print('<font size="+2" color="red">Coursemap undefined.</font>' .
                    174:                   '</body></html>');
                    175:         return OK;
                    176:     }
                    177: 
1.133     bowersj2  178:     # renderer call
1.140     bowersj2  179:     my $render = render({ 'cols' => [0,1,2,3],
                    180:                           'url' => '/adm/navmaps',
                    181:                           'printKey' => 1,
                    182:                           'r' => $r});
1.133     bowersj2  183: 
1.126     bowersj2  184:     $navmap->untieHashes();
1.51      bowersj2  185: 
1.128     bowersj2  186:     $r->print("</body></html>");
1.134     bowersj2  187:     $r->rflush();
1.59      bowersj2  188: 
1.51      bowersj2  189:     return OK;
                    190: }
                    191: 
                    192: # Convenience functions: Returns a string that adds or subtracts
                    193: # the second argument from the first hash, appropriate for the 
                    194: # query string that determines which folders to recurse on
                    195: sub addToFilter {
                    196:     my $hashIn = shift;
                    197:     my $addition = shift;
                    198:     my %hash = %$hashIn;
                    199:     $hash{$addition} = 1;
                    200: 
                    201:     return join (",", keys(%hash));
                    202: }
                    203: 
                    204: sub removeFromFilter {
                    205:     my $hashIn = shift;
                    206:     my $subtraction = shift;
                    207:     my %hash = %$hashIn;
                    208: 
                    209:     delete $hash{$subtraction};
                    210:     return join(",", keys(%hash));
                    211: }
                    212: 
                    213: # Convenience function: Given a stack returned from getStack on the iterator,
                    214: # return the correct src() value.
                    215: # Later, this should add an anchor when we start putting anchors in pages.
                    216: sub getLinkForResource {
                    217:     my $stack = shift;
                    218:     my $res;
                    219: 
                    220:     # Check to see if there are any pages in the stack
                    221:     foreach $res (@$stack) {
                    222:         if (defined($res) && $res->is_page()) {
                    223:             return $res->src();
                    224:         }
                    225:     }
                    226: 
                    227:     # Failing that, return the src of the last resource that is defined
                    228:     # (when we first recurse on a map, it puts an undefined resource
                    229:     # on the bottom because $self->{HERE} isn't defined yet, and we
                    230:     # want the src for the map anyhow)
                    231:     foreach (@$stack) {
                    232:         if (defined($_)) { $res = $_; }
                    233:     }
                    234: 
                    235:     return $res->src();
                    236: }
                    237: 
1.53      bowersj2  238: # Convenience function: This seperates the logic of how to create
                    239: # the problem text strings ("Due: DATE", "Open: DATE", "Not yet assigned",
                    240: # etc.) into a seperate function. It takes a resource object as the
                    241: # first parameter, and the part number of the resource as the second.
                    242: # It's basically a big switch statement on the status of the resource.
                    243: 
                    244: sub getDescription {
                    245:     my $res = shift;
                    246:     my $part = shift;
1.69      bowersj2  247:     my $status = $res->status($part);
1.53      bowersj2  248: 
                    249:     if ($status == $res->NETWORK_FAILURE) { return ""; }
                    250:     if ($status == $res->NOTHING_SET) {
                    251:         return "Not currently assigned.";
                    252:     }
                    253:     if ($status == $res->OPEN_LATER) {
1.73      bowersj2  254:         return "Open " . timeToHumanString($res->opendate($part));
1.53      bowersj2  255:     }
                    256:     if ($status == $res->OPEN) {
1.79      bowersj2  257:         if ($res->duedate($part)) {
1.73      bowersj2  258:             return "Due " . timeToHumanString($res->duedate($part));
1.66      bowersj2  259:         } else {
                    260:             return "Open, no due date";
                    261:         }
1.53      bowersj2  262:     }
1.54      bowersj2  263:     if ($status == $res->PAST_DUE_ANSWER_LATER) {
1.73      bowersj2  264:         return "Answer open " . timeToHumanString($res->answerdate($part));
1.54      bowersj2  265:     }
                    266:     if ($status == $res->PAST_DUE_NO_ANSWER) {
1.73      bowersj2  267:         return "Was due " . timeToHumanString($res->duedate($part));
1.53      bowersj2  268:     }
                    269:     if ($status == $res->ANSWER_OPEN) {
                    270:         return "Answer available";
                    271:     }
1.59      bowersj2  272:     if ($status == $res->EXCUSED) {
1.66      bowersj2  273:         return "Excused by instructor";
1.59      bowersj2  274:     }
1.69      bowersj2  275:     if ($status == $res->ATTEMPTED) {
                    276:         return "Not yet graded.";
                    277:     }
1.59      bowersj2  278:     if ($status == $res->TRIES_LEFT) {
1.79      bowersj2  279:         my $tries = $res->tries($part);
                    280:         my $maxtries = $res->maxtries($part);
                    281:         my $triesString = "";
                    282:         if ($tries && $maxtries) {
                    283:             $triesString = "<font size=\"-1\"><i>($tries of $maxtries tries used)</i></font>";
                    284:             if ($maxtries > 1 && $maxtries - $tries == 1) {
                    285:                 $triesString = "<b>$triesString</b>";
                    286:             }
                    287:         }
1.66      bowersj2  288:         if ($res->duedate()) {
1.73      bowersj2  289:             return "Due " . timeToHumanString($res->duedate($part)) .
1.66      bowersj2  290:                 " $triesString";
                    291:         } else {
                    292:             return "No due date $triesString";
                    293:         }
1.59      bowersj2  294:     }
1.53      bowersj2  295: }
                    296: 
1.115     bowersj2  297: # Convenience function, so others can use it: Is the problem due in less then
                    298: # 24 hours, and still can be done?
                    299: 
                    300: sub dueInLessThen24Hours {
                    301:     my $res = shift;
                    302:     my $part = shift;
                    303:     my $status = $res->status($part);
                    304: 
                    305:     return ($status == $res->OPEN() || $status == $res->ATTEMPTED() ||
                    306:             $status == $res->TRIES_LEFT()) &&
                    307:            $res->duedate() && $res->duedate() < time()+(24*60*60) &&
                    308:            $res->duedate() > time();
                    309: }
                    310: 
                    311: # Convenience function, so others can use it: Is there only one try remaining for the
                    312: # part, with more then one try to begin with, not due yet and still can be done?
                    313: sub lastTry {
                    314:     my $res = shift;
                    315:     my $part = shift;
                    316: 
                    317:     my $tries = $res->tries($part);
                    318:     my $maxtries = $res->maxtries($part);
                    319:     return $tries && $maxtries && $maxtries > 1 &&
                    320:         $maxtries - $tries == 1 && $res->duedate() &&
                    321:         $res->duedate() > time();
                    322: }
                    323: 
1.101     bowersj2  324: # This puts a human-readable name on the ENV variable.
1.68      bowersj2  325: sub advancedUser {
                    326:     return $ENV{'user.adv'};
                    327: }
                    328: 
1.73      bowersj2  329: 
                    330: # timeToHumanString takes a time number and converts it to a
                    331: # human-readable representation, meant to be used in the following
                    332: # manner:
                    333: # print "Due $timestring"
                    334: # print "Open $timestring"
                    335: # print "Answer available $timestring"
                    336: # Very, very, very, VERY English-only... goodness help a localizer on
                    337: # this func...
1.53      bowersj2  338: sub timeToHumanString {
1.58      albertel  339:     my ($time) = @_;
                    340:     # zero, '0' and blank are bad times
1.73      bowersj2  341:     if (!$time) {
                    342:         return 'never';
                    343:     }
                    344: 
                    345:     my $now = time();
                    346: 
                    347:     my @time = localtime($time);
                    348:     my @now = localtime($now);
                    349: 
                    350:     # Positive = future
                    351:     my $delta = $time - $now;
                    352: 
                    353:     my $minute = 60;
                    354:     my $hour = 60 * $minute;
                    355:     my $day = 24 * $hour;
                    356:     my $week = 7 * $day;
                    357:     my $inPast = 0;
                    358: 
                    359:     # Logic in comments:
                    360:     # Is it now? (extremely unlikely)
                    361:     if ( $delta == 0 ) {
                    362:         return "this instant";
                    363:     }
                    364: 
                    365:     if ($delta < 0) {
                    366:         $inPast = 1;
                    367:         $delta = -$delta;
                    368:     }
                    369: 
                    370:     if ( $delta > 0 ) {
1.101     bowersj2  371: 
1.73      bowersj2  372:         my $tense = $inPast ? " ago" : "";
                    373:         my $prefix = $inPast ? "" : "in ";
1.101     bowersj2  374:         
                    375:         # Less then a minute
1.73      bowersj2  376:         if ( $delta < $minute ) {
                    377:             if ($delta == 1) { return "${prefix}1 second$tense"; }
                    378:             return "$prefix$delta seconds$tense";
                    379:         }
                    380: 
1.101     bowersj2  381:         # Less then an hour
1.73      bowersj2  382:         if ( $delta < $hour ) {
                    383:             # If so, use minutes
                    384:             my $minutes = floor($delta / 60);
                    385:             if ($minutes == 1) { return "${prefix}1 minute$tense"; }
                    386:             return "$prefix$minutes minutes$tense";
                    387:         }
                    388:         
                    389:         # Is it less then 24 hours away? If so,
                    390:         # display hours + minutes
                    391:         if ( $delta < $hour * 24) {
                    392:             my $hours = floor($delta / $hour);
                    393:             my $minutes = floor(($delta % $hour) / $minute);
                    394:             my $hourString = "$hours hours";
                    395:             my $minuteString = ", $minutes minutes";
                    396:             if ($hours == 1) {
                    397:                 $hourString = "1 hour";
                    398:             }
                    399:             if ($minutes == 1) {
                    400:                 $minuteString = ", 1 minute";
                    401:             }
                    402:             if ($minutes == 0) {
                    403:                 $minuteString = "";
                    404:             }
                    405:             return "$prefix$hourString$minuteString$tense";
                    406:         }
                    407: 
                    408:         # Less then 5 days away, display day of the week and
                    409:         # HH:MM
                    410:         if ( $delta < $day * 5 ) {
1.85      bowersj2  411:             my $timeStr = strftime("%A, %b %e at %I:%M %P", localtime($time));
1.73      bowersj2  412:             $timeStr =~ s/12:00 am/midnight/;
                    413:             $timeStr =~ s/12:00 pm/noon/;
                    414:             return ($inPast ? "last " : "next ") .
                    415:                 $timeStr;
                    416:         }
                    417:         
                    418:         # Is it this year?
                    419:         if ( $time[5] == $now[5]) {
                    420:             # Return on Month Day, HH:MM meridian
                    421:             my $timeStr = strftime("on %A, %b %e at %I:%M %P", localtime($time));
                    422:             $timeStr =~ s/12:00 am/midnight/;
                    423:             $timeStr =~ s/12:00 pm/noon/;
                    424:             return $timeStr;
                    425:         }
                    426: 
                    427:         # Not this year, so show the year
                    428:         my $timeStr = strftime("on %A, %b %e %G at %I:%M %P", localtime($time));
                    429:         $timeStr =~ s/12:00 am/midnight/;
                    430:         $timeStr =~ s/12:00 pm/noon/;
                    431:         return $timeStr;
1.58      albertel  432:     }
1.53      bowersj2  433: }
                    434: 
1.51      bowersj2  435: 
1.133     bowersj2  436: =pod
                    437: 
                    438: =head1 navmap renderer
                    439: 
                    440: The navmaprenderer package provides a sophisticated rendering of the standard navigation maps interface into HTML. The provided nav map handler is actually just a glorified call to this. 
                    441: 
                    442: Because of the large number of parameters this function presents, instead of passing it arguments as is normal, pass it in an anonymous hash with the given options. This is because there is no obvious order you may wish to override these in and a hash is easier to read and understand then "undef, undef, undef, 1, undef, undef, renderButton, undef, 0" when you mostly want default behaviors.
                    443: 
                    444: The package provides a function called 'render', called as Apache::lonnavmaps::renderer->render({}).
1.51      bowersj2  445: 
1.133     bowersj2  446: =head2 Overview of Columns
1.51      bowersj2  447: 
1.133     bowersj2  448: The renderer will build an HTML table for the navmap and return it. The table is consists of several columns, and a row for each resource (or possibly each part). You tell the renderer how many columns to create and what to place in each column, optionally using one or more of the preparent columns, and the renderer will assemble the table.
1.51      bowersj2  449: 
1.133     bowersj2  450: Any additional generally useful column types should be placed in the renderer code here, so anybody can use it anywhere else. Any code specific to the current application (such as the addition of <input> elements in a column) should be placed in the code of the thing using the renderer.
1.51      bowersj2  451: 
1.133     bowersj2  452: At the core of the renderer is the array reference COLS (see Example section below for how to pass this correctly). The COLS array will consist of entries of one of two types of things: Either an integer representing one of the pre-packaged column types, or a sub reference that takes a resource reference, a part number, and a reference to the argument hash passed to the renderer, and returns a string that will be inserted into the HTML representation as it.
1.51      bowersj2  453: 
1.133     bowersj2  454: The pre-packaged column names are refered to by constants in the Apache::lonnavmaps::renderer namespace. The following currently exist:
1.51      bowersj2  455: 
1.133     bowersj2  456: =over 4
1.51      bowersj2  457: 
1.133     bowersj2  458: =item * B<resource>: The general info about the resource: Link, icon for the type, etc. The first column in the standard nav map display. This column also accepts the following parameter in the renderer hash:
1.51      bowersj2  459: 
                    460: =over 4
                    461: 
1.133     bowersj2  462: =item * B<resource_nolink>: If true, the resource will not be linked. Default: false, resource will have links.
                    463: 
                    464: =item * B<resource_part_count>: If true (default), the resource will show a part count if the full part list is not displayed. If false, the resource will never show a part count.
                    465: 
1.144   ! bowersj2  466: =item * B<resource_no_folder_link>: If true, the resource's folder will not be clickable to open or close it. Default is false.
        !           467: 
1.133     bowersj2  468: =back
1.51      bowersj2  469: 
1.133     bowersj2  470: =item B<communication_status>: Whether there is discussion on the resource, email for the user, or (lumped in here) perl errors in the execution of the problem. This is the second column in the main nav map.
1.51      bowersj2  471: 
1.133     bowersj2  472: =item B<quick_status>: An icon for the status of a problem, with four possible states: Correct, incorrect, open, or none (not open yet, not a problem). The third column of the standard navmap.
1.51      bowersj2  473: 
1.133     bowersj2  474: =item B<long_status>: A text readout of the details of the current status of the problem, such as "Due in 22 hours". The fourth column of the standard navmap.
1.51      bowersj2  475: 
1.133     bowersj2  476: =back
1.51      bowersj2  477: 
1.133     bowersj2  478: If you add any others please be sure to document them here.
1.51      bowersj2  479: 
1.133     bowersj2  480: An example of a column renderer that will show the ID number of a resource, along with the part name if any:
1.51      bowersj2  481: 
1.133     bowersj2  482:  sub { 
                    483:   my ($resource, $part, $params) = @_;   
                    484:   if ($part) { return '<td>' . $resource->{ID} . ' ' . $part . '</td>'; }
                    485:   return '<td>' . $resource->{ID} . '</td>';
                    486:  }
1.51      bowersj2  487: 
1.133     bowersj2  488: Note these functions are responsible for the TD tags, which allow them to override vertical and horizontal alignment, etc.
1.130     www       489: 
1.133     bowersj2  490: =head2 Parameters
1.115     bowersj2  491: 
1.140     bowersj2  492: Most of these parameters are only useful if you are *not* using the folder interface (i.e., the default first column), which is probably the common case. If you are using this interface, then you should be able to get away with just using 'cols' (to specify the columns shown), 'url' (necessary for the folders to link to the current screen correctly), and possibly 'queryString' if your app calls for it. In that case, maintaining the state of the folders will be done automatically.
                    493: 
1.133     bowersj2  494: =over 4
1.51      bowersj2  495: 
1.144   ! bowersj2  496: =item * B<iterator>: A reference to a fresh ::iterator to use from the navmaps. The rendering will reflect the options passed to the iterator, so you can use that to just render a certain part of the course, if you like. If one is not passed, the renderer will attempt to construct one from ENV{'form.filter'} and ENV{'form.condition'} information, plus the 'iterator_map' parameter if any.
        !           497: 
        !           498: =item * B<iterator_map>: If you are letting the renderer do the iterator handling, you can instruct the renderer to render only a particular map by passing it the source of the map you want to process, like '/res/103/jerf/navmap.course.sequence'.
1.140     bowersj2  499: 
                    500: =item * B<navmap>: A reference to a navmap, used only if an iterator is not passed in. If this is necessary to make an iterator but it is not passed in, a new one will be constructed based on ENV info. This is useful to do basic error checking before passing it off to render.
1.92      bowersj2  501: 
1.133     bowersj2  502: =item * B<cols>: An array reference
1.92      bowersj2  503: 
1.133     bowersj2  504: =item * B<showParts>: A flag. If yes (default), a line for the resource itself, and a line for each part will be displayed. If not, only one line for each resource will be displayed.
1.51      bowersj2  505: 
1.133     bowersj2  506: =item * B<condenseParts>: A flag. If yes (default), if all parts of the problem have the same status and that status is Nothing Set, Correct, or Network Failure, then only one line will be displayed for that resource anyhow. If no, all parts will always be displayed. If showParts is 0, this is ignored.
1.55      bowersj2  507: 
1.140     bowersj2  508: =item * B<jumpCount>: A string identifying the URL to place the anchor 'curloc' at. Default to no anchor at all. It is the responsibility of the renderer user to ensure that the #curloc is in the URL. By default, determined through the use of the ENV{} 'jump' and 'jumpType' information.
1.84      bowersj2  509: 
1.140     bowersj2  510: =item * B<hereURL>: A URL identifying where to place the 'here' marker. By default, will pull this from the ENV{'form.here*'} info.
1.51      bowersj2  511: 
1.140     bowersj2  512: =item * B<hereSymb>: A Symb identifying where to place the 'here' marker. Default same as hereURL.
1.115     bowersj2  513: 
1.133     bowersj2  514: =item * B<indentString>: A string identifying the indentation string to use. By default, this is a 25 pixel whitespace image with no alt text.
1.55      bowersj2  515: 
1.133     bowersj2  516: =item * B<queryString>: A string which will be prepended to the query string used when the folders are opened or closed.
1.51      bowersj2  517: 
1.133     bowersj2  518: =item * B<url>: The url the folders will link to, which should be the current page. Required if the resource info column is shown.
1.51      bowersj2  519: 
1.140     bowersj2  520: =item * B<currentJumpIndex>: Describes the currently-open row number to cause the browser to jump to, because the user just opened that folder. By default, pulled from the Jump information in the ENV{'form.*'}.
1.139     bowersj2  521: 
                    522: =item * B<r>: The standard Apache response object. If you pass this to the render, it will use it to flush the table every 20 rows and handle the rendering itself.
                    523: 
1.140     bowersj2  524: =item * B<printKey>: If true, print the key that appears on the top of the standard navmaps. Default is false.
                    525: 
                    526: =item * B<printCloseAll>: If true, print the "Close all folders" or "open all folders" links. Default is true.
                    527: 
1.143     bowersj2  528: =item * B<filterFunc>: A function that takes the resource object as its only parameter and returns a true or false value. If true, the resource is displayed. If false, it is simply skipped in the display. By default, all resources are showne.
                    529: 
1.133     bowersj2  530: =back
1.51      bowersj2  531: 
1.133     bowersj2  532: =head2 Additional Info
1.51      bowersj2  533: 
1.133     bowersj2  534: In addition to the parameters you can pass to the renderer, which will be passed through unchange to the column renderers, the renderer will generate the following information which your renderer may find useful:
1.59      bowersj2  535: 
1.133     bowersj2  536: =over 4
1.59      bowersj2  537: 
1.133     bowersj2  538: =back
1.59      bowersj2  539: 
1.133     bowersj2  540: =cut
1.59      bowersj2  541: 
1.133     bowersj2  542: sub resource { return 0; }
                    543: sub communication_status { return 1; }
                    544: sub quick_status { return 2; }
                    545: sub long_status { return 3; }
1.124     bowersj2  546: 
1.133     bowersj2  547: # Data for render_resource
1.51      bowersj2  548: 
1.133     bowersj2  549: sub render_resource {
                    550:     my ($resource, $part, $params) = @_;
1.51      bowersj2  551: 
1.133     bowersj2  552:     my $nonLinkedText = ''; # stuff after resource title not in link
1.51      bowersj2  553: 
1.134     bowersj2  554:     my $link = $params->{"resourceLink"};
                    555:     my $src = $resource->src();
                    556:     my $it = $params->{"iterator"};
1.133     bowersj2  557:     my $filter = $it->{FILTER};
                    558: 
                    559:     my $title = $resource->compTitle();
                    560:     if ($src =~ /^\/uploaded\//) {
                    561:         $nonLinkedText=$title;
                    562:         $title = '';
                    563:     }
                    564:     my $partLabel = "";
                    565:     my $newBranchText = "";
                    566:     
                    567:     # If this is a new branch, label it so
                    568:     if ($params->{'isNewBranch'}) {
                    569:         $newBranchText = "<img src='/adm/lonIcons/branch.gif' border='0' />";
1.51      bowersj2  570:     }
                    571: 
1.133     bowersj2  572:     # links to open and close the folder
                    573:     my $linkopen = "<a href='$link'>";
                    574:     my $linkclose = "</a>";
1.51      bowersj2  575: 
1.133     bowersj2  576:     # Default icon: HTML page
                    577:     my $icon = "<img src='/adm/lonIcons/html.gif' alt='' border='0' />";
                    578:     
                    579:     if ($resource->is_problem()) {
                    580:         if ($part eq "0" || $params->{'condensed'}) {
                    581:             $icon = '<img src="/adm/lonIcons/problem.gif" alt="" border="0" />';
                    582:         } else {
                    583:             $icon = $params->{'indentString'};
                    584:         }
                    585:     }
1.51      bowersj2  586: 
1.133     bowersj2  587:     # Display the correct map icon to open or shut map
                    588:     if ($resource->is_map()) {
                    589:         my $mapId = $resource->map_pc();
                    590:         my $nowOpen = !defined($filter->{$mapId});
                    591:         if ($it->{CONDITION}) {
                    592:             $nowOpen = !$nowOpen;
                    593:         }
1.144   ! bowersj2  594: 
        !           595:         if (!$params->{'resource_no_folder_link'}) {
        !           596:             $icon = 'navmap.folder.' . ($nowOpen ? 'closed' : 'open') . '.gif';
        !           597:             $icon = "<img src='/adm/lonIcons/$icon' alt='' border='0' />";
        !           598: 
        !           599:             $linkopen = "<a href='" . $params->{'url'} . '?' . 
        !           600:                 $params->{'queryString'} . '&filter=';
        !           601:             $linkopen .= ($nowOpen xor $it->{CONDITION}) ?
        !           602:                 addToFilter($filter, $mapId) :
        !           603:                 removeFromFilter($filter, $mapId);
        !           604:             $linkopen .= "&condition=" . $it->{CONDITION} . '&hereType='
        !           605:                 . $params->{'hereType'} . '&here=' .
        !           606:                 &Apache::lonnet::escape($params->{'here'}) . 
        !           607:                 '&jumpType=' . SYMB() . '&jump=' .
        !           608:                 &Apache::lonnet::escape($resource->symb()) . 
        !           609:                 "&folderManip=1'>";
        !           610:         } else {
        !           611:             # Don't allow users to manipulate folder
        !           612:             $icon = 'navmap.folder.' . ($nowOpen ? 'closed' : 'open') .
        !           613:                 '.nomanip.gif';
        !           614:             $icon = "<img src='/adm/lonIcons/$icon' alt='' border='0' />";
        !           615: 
        !           616:             $linkopen = "";
        !           617:             $linkclose = "";
        !           618:         }
1.133     bowersj2  619:     }
1.51      bowersj2  620: 
1.133     bowersj2  621:     if ($resource->randomout()) {
                    622:         $nonLinkedText .= ' <i>(hidden)</i> ';
                    623:     }
                    624:     
                    625:     # We're done preparing and finally ready to start the rendering
                    626:     my $result = "<td align='left' valign='center'>";
1.140     bowersj2  627: 
                    628:     my $indentLevel = $params->{'indentLevel'};
                    629:     if ($newBranchText) { $indentLevel--; }
                    630: 
1.133     bowersj2  631:     # print indentation
1.140     bowersj2  632:     for (my $i = 0; $i < $indentLevel; $i++) {
1.133     bowersj2  633:         $result .= $params->{'indentString'};
1.84      bowersj2  634:     }
                    635: 
1.133     bowersj2  636:     # Decide what to display
                    637:     $result .= "$newBranchText$linkopen$icon$linkclose";
                    638:     
                    639:     my $curMarkerBegin = '';
                    640:     my $curMarkerEnd = '';
1.51      bowersj2  641: 
1.133     bowersj2  642:     # Is this the current resource?
                    643:     if (!$params->{'displayedHereMarker'} &&
                    644:         (($params->{'hereType'} == SYMB() && 
                    645:           $resource->symb() eq $params->{'here'}) ||
                    646:          ($params->{'hereType'} == URL() &&
                    647:           $resource->src() eq $params->{'here'}))) {
                    648:         $curMarkerBegin = '<font color="red" size="+2">&gt; </font>';
                    649:         $curMarkerEnd = '<font color="red" size="+2">&lt;</font>';
1.51      bowersj2  650:     }
                    651: 
1.133     bowersj2  652:     if ($resource->is_problem() && $part ne "0" && 
                    653:         !$params->{'condensed'}) {
                    654:         $partLabel = " (Part $part)";
                    655:         $title = "";
1.51      bowersj2  656:     }
                    657: 
1.133     bowersj2  658:     if ($params->{'multipart'} && $params->{'condensed'}) {
                    659:         $nonLinkedText .= ' (' . $resource->countParts() . ' parts)';
1.51      bowersj2  660:     }
                    661: 
1.144   ! bowersj2  662:     if (!$params->{'resource_nolink'}) {
        !           663:         $result .= "  $curMarkerBegin<a href='$link'>$title$partLabel</a>$curMarkerEnd $nonLinkedText</td>";
        !           664:     } else {
        !           665:         $result .= "  $curMarkerBegin$title$partLabel$curMarkerEnd $nonLinkedText</td>";
        !           666:     }
1.51      bowersj2  667: 
1.133     bowersj2  668:     return $result;
                    669: }
1.51      bowersj2  670: 
1.133     bowersj2  671: sub render_communication_status {
                    672:     my ($resource, $part, $params) = @_;
1.134     bowersj2  673:     my $discussionHTML = ""; my $feedbackHTML = ""; my $errorHTML = "";
                    674: 
                    675:     my $link = $params->{"resourceLink"};
                    676:     my $linkopen = "<a href='$link'>";
                    677:     my $linkclose = "</a>";
                    678: 
                    679:     if ($resource->hasDiscussion()) {
                    680:         $discussionHTML = $linkopen .
                    681:             '<img border="0" src="/adm/lonMisc/chat.gif" />' .
                    682:             $linkclose;
                    683:     }
                    684:     
                    685:     if ($resource->getFeedback()) {
                    686:         my $feedback = $resource->getFeedback();
                    687:         foreach (split(/\,/, $feedback)) {
                    688:             if ($_) {
                    689:                 $feedbackHTML .= '&nbsp;<a href="/adm/email?display='
                    690:                     . &Apache::lonnet::escape($_) . '">'
                    691:                     . '<img src="/adm/lonMisc/feedback.gif" '
                    692:                     . 'border="0" /></a>';
                    693:             }
                    694:         }
                    695:     }
                    696:     
                    697:     if ($resource->getErrors()) {
                    698:         my $errors = $resource->getErrors();
                    699:         foreach (split(/,/, $errors)) {
                    700:             if ($_) {
                    701:                 $errorHTML .= '&nbsp;<a href="/adm/email?display='
                    702:                     . &Apache::lonnet::escape($_) . '">'
                    703:                     . '<img src="/adm/lonMisc/bomb.gif" '
                    704:                     . 'border="0" /></a>';
                    705:             }
                    706:         }
                    707:     }
                    708: 
                    709:     return "<td width=\"75\" align=\"left\" valign=\"center\">$discussionHTML$feedbackHTML$errorHTML&nbsp;</td>";
                    710: 
1.133     bowersj2  711: }
                    712: sub render_quick_status {
                    713:     my ($resource, $part, $params) = @_;
1.135     bowersj2  714:     my $result = "";
                    715:     my $firstDisplayed = !$params->{'condensed'} && 
                    716:         $params->{'multipart'} && $part eq "0";
                    717: 
                    718:     my $link = $params->{"resourceLink"};
                    719:     my $linkopen = "<a href='$link'>";
                    720:     my $linkclose = "</a>";
                    721: 
                    722:     if ($resource->is_problem() &&
                    723:         !$firstDisplayed) {
                    724:         my $icon = $statusIconMap{$resource->status($part)};
                    725:         my $alt = $iconAltTags{$icon};
                    726:         if ($icon) {
                    727:             $result .= "<td width='30' valign='center' width='50' align='right'>$linkopen<img width='25' height='25' src='/adm/lonIcons/$icon' border='0' alt='$alt' />$linkclose</td>\n";
                    728:         } else {
                    729:             $result .= "<td width='30'>&nbsp;</td>\n";
                    730:         }
                    731:     } else { # not problem, no icon
                    732:         $result .= "<td width='30'>&nbsp;</td>\n";
                    733:     }
                    734: 
                    735:     return $result;
1.133     bowersj2  736: }
                    737: sub render_long_status {
                    738:     my ($resource, $part, $params) = @_;
1.136     bowersj2  739:     my $result = "<td align='right' valign='center'>\n";
                    740:     my $firstDisplayed = !$params->{'condensed'} && 
                    741:         $params->{'multipart'} && $part eq "0";
                    742:                 
                    743:     my $color;
                    744:     if ($resource->is_problem()) {
                    745:         $color = $colormap{$resource->status};
                    746:         
                    747:         if (dueInLessThen24Hours($resource, $part) ||
                    748:             lastTry($resource, $part)) {
                    749:             $color = $hurryUpColor;
                    750:         }
                    751:     }
                    752:     
                    753:     if ($resource->kind() eq "res" &&
                    754:         $resource->is_problem() &&
                    755:         !$firstDisplayed) {
                    756:         if ($color) {$result .= "<font color=\"$color\"><b>"; }
                    757:         $result .= getDescription($resource, $part);
                    758:         if ($color) {$result .= "</b></font>"; }
                    759:     }
                    760:     if ($resource->is_map() && advancedUser() && $resource->randompick()) {
                    761:         $result .= '(randomly select ' . $resource->randompick() .')';
                    762:     }
                    763:     
                    764:     $result .= "&nbsp;</td>\n";
                    765:     
                    766:     return $result;
1.51      bowersj2  767: }
                    768: 
1.133     bowersj2  769: my @preparedColumns = (\&render_resource, \&render_communication_status,
                    770:                        \&render_quick_status, \&render_long_status);
1.132     bowersj2  771: 
                    772: sub setDefault {
                    773:     my ($val, $default) = @_;
                    774:     if (!defined($val)) { return $default; }
                    775:     return $val;
                    776: }
                    777: 
                    778: sub render {
                    779:     my $args = shift;
1.140     bowersj2  780:     &Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});
                    781:     my $result = '';
                    782: 
1.132     bowersj2  783:     # Configure the renderer.
                    784:     my $cols = $args->{'cols'};
                    785:     if (!defined($cols)) {
                    786:         # no columns, no nav maps.
                    787:         return '';
                    788:     }
1.140     bowersj2  789:     my $mustCloseNavMap = 0;
                    790:     my $navmap;
                    791:     if (defined($args->{'navmap'})) {
                    792:         $navmap = $args->{'navmap'};
                    793:     }
                    794: 
                    795:     my $queryString = $args->{'queryString'};
                    796:     my $jumpToURL = $args->{'jumpToURL'};
                    797:     my $jumpToSymb = $args->{'jumpToSymb'};
                    798:     my $jumpType;
                    799:     my $hereURL = $args->{'hereURL'};
                    800:     my $hereSymb = $args->{'hereSymb'};
                    801:     my $hereType;
                    802:     my $here;
                    803:     my $jump;
                    804:     my $currentJumpIndex = setDefault($args->{'currentJumpIndex'}, 0);    
                    805:     my $currentJumpDelta = 2; # change this to change how many resources are displayed
                    806:                              # before the current resource when using #current
                    807: 
                    808:     # If we were passed 'here' information, we are not rendering
                    809:     # after a folder manipulation, and we were not passed an
                    810:     # iterator, make sure we open the folders to show the "here"
                    811:     # marker
                    812:     my $filterHash = {};
                    813:     # Figure out what we're not displaying
                    814:     foreach (split(/\,/, $ENV{"form.filter"})) {
                    815:         if ($_) {
                    816:             $filterHash->{$_} = "1";
                    817:         }
                    818:     }
                    819: 
                    820:     my $condition = 0;
                    821:     if ($ENV{'form.condition'}) {
                    822:         $condition = 1;
                    823:     }
                    824: 
                    825:     if (!$ENV{'form.folderManip'} && !defined($args->{'iterator'})) {
                    826:         # Step 1: Check to see if we have a navmap
                    827:         if (!defined($navmap)) {
                    828:             $navmap = Apache::lonnavmaps::navmap->new(
                    829:                         $ENV{"request.course.fn"}.".db",
                    830:                         $ENV{"request.course.fn"}."_parms.db", 1, 1);
                    831:             $mustCloseNavMap = 1;
                    832:         }
                    833:         $navmap->init();
                    834: 
                    835:         # Step two: Locate what kind of here marker is necessary
                    836:         # Determine where the "here" marker is and where the screen jumps to.
                    837: 
                    838:         # We're coming from the remote. We have either a url, a symb, or nothing,
                    839:         # and we need to figure out what.
                    840:         # Preference: Symb
                    841:         
                    842:         if ($ENV{'form.symb'}) {
                    843:             $hereType = $jumpType = SYMB();
                    844:             $here = $jump = $ENV{'form.symb'};
                    845:         } elsif ($ENV{'form.postdata'}) {
                    846:             # couldn't find a symb, is there a URL?
                    847:             my $currenturl = $ENV{'form.postdata'};
                    848:             $currenturl=~s/^http\:\/\///;
                    849:             $currenturl=~s/^[^\/]+//;
                    850:             
                    851:             $hereType = $jumpType = URL;
                    852:             $here = $jump = $currenturl;
                    853:         } else {
                    854:             # Nothing
                    855:             $hereType = $jumpType = NOTHING();
                    856:         }
                    857:         # Step three: Ensure the folders are open
                    858:         my $mapIterator = $navmap->getIterator(undef, undef, undef, 1);
                    859:         my $depth = 1;
                    860:         $mapIterator->next(); # discard the first BEGIN_MAP
                    861:         my $curRes = $mapIterator->next();
                    862:         my $counter = 0;
                    863:         my $found = 0;
                    864:         
                    865:         # We only need to do this if we need to open the maps to show the
                    866:         # current position. This will change the counter so we can't count
                    867:         # for the jump marker with this loop.
                    868:         while ($depth > 0 && !$found) {
                    869:             if ($curRes == $mapIterator->BEGIN_MAP()) { $depth++; }
                    870:             if ($curRes == $mapIterator->END_MAP()) { $depth--; }
                    871:             
                    872:             if (ref($curRes) && 
                    873:                 ($hereType == SYMB() && $curRes->symb() eq $here) ||
                    874:                 (ref($curRes) && $hereType == URL() && $curRes->src() eq $here)) {
                    875:                 my $mapStack = $mapIterator->getStack();
                    876:                 
                    877:                 # Ensure the parent maps are open
                    878:                 for my $map (@{$mapStack}) {
                    879:                     if ($condition) {
                    880:                         undef $filterHash->{$map->map_pc()};
                    881:                     } else {
                    882:                         $filterHash->{$map->map_pc()} = 1;
                    883:                     }
                    884:                 }
                    885:                 $found = 1;
                    886:             }
                    887:             
                    888:             $curRes = $mapIterator->next();
                    889:         }            
                    890: 
                    891:         # Since we changed the folders, (re-)locate the jump point, if any
                    892:         $mapIterator = $navmap->getIterator(undef, undef, $filterHash, 0);
                    893:         $depth = 1;
                    894:         $mapIterator->next();
                    895:         $curRes = $mapIterator->next();
                    896:         my $foundJump = 0;
                    897:         
                    898:         while ($depth > 0 && !$foundJump) {
                    899:             if ($curRes == $mapIterator->BEGIN_MAP()) { $depth++; }
                    900:             if ($curRes == $mapIterator->END_MAP()) { $depth--; }
                    901:             if (ref($curRes)) { $counter++; }
                    902:             
                    903:             if (ref($curRes) && 
                    904:                 (($jumpType == SYMB() && $curRes->symb() eq $jump) ||
                    905:                  ($jumpType == URL() && $curRes->src() eq $jump))) {
                    906:                 
                    907:                 # This is why we have to use the main iterator instead of the
                    908:                 # potentially faster DFS: The count has to be the same, so
                    909:                 # the order has to be the same, which DFS won't give us.
                    910:                 $currentJumpIndex = $counter;
                    911:                 $foundJump = 1;
                    912:             }
                    913:             
                    914:             $curRes = $mapIterator->next();
                    915:         }
                    916:     
                    917:     }        
                    918:     if ( !defined($args->{'iterator'}) && $ENV{'form.folderManip'} ) { # we came from a user's manipulation of the nav page
                    919:         # If this is a click on a folder or something, we want to preserve the "here"
                    920:         # from the querystring, and get the new "jump" marker
                    921:         $hereType = $ENV{'form.hereType'};
                    922:         $here = $ENV{'form.here'};
                    923:         $jumpType = $ENV{'form.jumpType'} || NOTHING();
                    924:         $jump = $ENV{'form.jump'};
                    925:     } 
                    926:     
1.132     bowersj2  927:     my $it = $args->{'iterator'};
                    928:     if (!defined($it)) {
1.140     bowersj2  929:         # Construct a default iterator based on $ENV{'form.'} information
                    930:         
                    931:         # Step 1: Check to see if we have a navmap
                    932:         if (!defined($navmap)) {
                    933:             $navmap = Apache::lonnavmaps::navmap->new(
                    934:                         $ENV{"request.course.fn"}.".db",
                    935:                         $ENV{"request.course.fn"}."_parms.db", 1, 1);
                    936:             $mustCloseNavMap = 1;
                    937:         }
                    938:         # Paranoia: Make sure it's ready
                    939:         $navmap->init();
                    940: 
1.144   ! bowersj2  941:         # See if we're being passed a specific map
        !           942:         if ($args->{'iterator_map'}) {
        !           943:             my $map = $args->{'iterator_map'};
        !           944:             $map = &Apache::lonnet::clutter($map);
        !           945:             $map = $navmap->{NAV_HASH}->{'ids_' . $map};
        !           946:             $map = $navmap->getById($map);
        !           947:             my $firstResource = $map->map_start();
        !           948:             my $finishResource = $map->map_finish();
        !           949: 
        !           950:             $args->{'iterator'} = $it = $navmap->getIterator($firstResource, $finishResource, $filterHash, $condition);
        !           951:         } else {
        !           952:             $args->{'iterator'} = $it = $navmap->getIterator(undef, undef, $filterHash, $condition);
        !           953:         }
1.132     bowersj2  954:     }
                    955:     
                    956:     my $showParts = setDefault($args->{'showParts'}, 1);
                    957:     my $condenseParts = setDefault($args->{'condenseParts'}, 1);
1.139     bowersj2  958:     # keeps track of when the current resource is found,
                    959:     # so we can back up a few and put the anchor above the
                    960:     # current resource
                    961:     my $r = $args->{'r'};
1.140     bowersj2  962:     my $printKey = $args->{'printKey'};
                    963:     my $printCloseAll = $args->{'printCloseAll'};
                    964:     if (!defined($printCloseAll)) { $printCloseAll = 1; }
1.143     bowersj2  965:     my $filterFunc = setDefault($args->{'filterFunc'},
                    966:                                 sub {return 1;});
1.144   ! bowersj2  967:     
1.140     bowersj2  968:     # Print key?
                    969:     if ($printKey) {
                    970:         $result .= '<table border="0" cellpadding="2" cellspacing="0">';
                    971:         my $date=localtime;
                    972:         $result.='<tr><td align="right" valign="bottom">Key:&nbsp;&nbsp;</td>';
                    973:         if ($navmap->{LAST_CHECK}) {
                    974:             $result .= 
                    975:                 '<img src="/adm/lonMisc/chat.gif"> New discussion since '.
                    976:                 strftime("%A, %b %e at %I:%M %P", localtime($navmap->{LAST_CHECK})).
                    977:                 '</td><td align="center" valign="bottom">&nbsp;&nbsp;'.
                    978:                 '<img src="/adm/lonMisc/feedback.gif"> New message (click to open)<p>'.
                    979:                 '</td>'; 
                    980:         } else {
                    981:             $result .= '<td align="center" valign="bottom">&nbsp;&nbsp;'.
                    982:                 '<img src="/adm/lonMisc/chat.gif"> Discussions</td><td align="center" valign="bottom">'.
                    983:                 '&nbsp;&nbsp;<img src="/adm/lonMisc/feedback.gif"> New message (click to open)'.
                    984:                 '</td>'; 
                    985:         }
                    986: 
                    987:         $result .= '</tr></table>';
                    988:     }
                    989: 
                    990:     if ($printCloseAll) {
                    991:         if ($condition) {
                    992:             $result.="<a href=\"navmaps?condition=0&filter=&$queryString" .
                    993:                 "&hereType=$hereType&here=" . Apache::lonnet::escape($here) .
                    994:                 "\">Close All Folders</a>";
                    995:         } else {
                    996:             $result.="<a href=\"navmaps?condition=1&filter=&$queryString" .
                    997:                 "&hereType=$hereType&here=" . Apache::lonnet::escape($here) . 
                    998:                 "\">Open All Folders</a>";
                    999:         }
1.143     bowersj2 1000:         $result .= "<br /><br />\n";
1.140     bowersj2 1001:     }    
                   1002: 
                   1003:     if ($r) {
                   1004:         $r->print($result);
                   1005:         $r->rflush();
                   1006:         $result = "";
                   1007:     }
1.132     bowersj2 1008:     # End parameter setting
1.133     bowersj2 1009:             
1.132     bowersj2 1010:     # Data
1.140     bowersj2 1011:     $result .= '<table cellspacing="0" cellpadding="3" border="0" bgcolor="#FFFFFF">' ."\n";
1.132     bowersj2 1012:     my $res = "Apache::lonnavmaps::resource";
                   1013:     my %condenseStatuses =
                   1014:         ( $res->NETWORK_FAILURE    => 1,
                   1015:           $res->NOTHING_SET        => 1,
                   1016:           $res->CORRECT            => 1 );
                   1017:     my @backgroundColors = ("#FFFFFF", "#F6F6F6");
1.133     bowersj2 1018: 
                   1019:     # Shared variables
                   1020:     $args->{'counter'} = 0; # counts the rows
                   1021:     $args->{'indentLevel'} = 0;
                   1022:     $args->{'isNewBranch'} = 0;
                   1023:     $args->{'condensed'} = 0;    
                   1024:     $args->{'indentString'} = setDefault($args->{'indentString'}, "<img src='/adm/lonIcons/whitespace1.gif' width='25' height='1' alt='' border='0' />");
                   1025:     $args->{'displayedHereMarker'} = 0;
1.132     bowersj2 1026: 
1.133     bowersj2 1027:     my $displayedJumpMarker = 0;
1.132     bowersj2 1028:     # Set up iteration.
                   1029:     my $depth = 1;
                   1030:     $it->next(); # discard initial BEGIN_MAP
                   1031:     my $curRes = $it->next();
                   1032:     my $now = time();
                   1033:     my $in24Hours = $now + 24 * 60 * 60;
                   1034:     my $rownum = 0;
                   1035: 
1.141     bowersj2 1036:     # export "here" marker information
                   1037:     $args->{'here'} = $here;
                   1038:     $args->{'hereType'} = $hereType;
                   1039: 
1.132     bowersj2 1040:     while ($depth > 0) {
                   1041:         if ($curRes == $it->BEGIN_MAP()) { $depth++; }
                   1042:         if ($curRes == $it->END_MAP()) { $depth--; }
                   1043: 
                   1044:         # Maintain indentation level.
                   1045:         if ($curRes == $it->BEGIN_MAP() ||
                   1046:             $curRes == $it->BEGIN_BRANCH() ) {
1.133     bowersj2 1047:             $args->{'indentLevel'}++;
1.132     bowersj2 1048:         }
                   1049:         if ($curRes == $it->END_MAP() ||
                   1050:             $curRes == $it->END_BRANCH() ) {
1.133     bowersj2 1051:             $args->{'indentLevel'}--;
1.132     bowersj2 1052:         }
                   1053:         # Notice new branches
                   1054:         if ($curRes == $it->BEGIN_BRANCH()) {
1.133     bowersj2 1055:             $args->{'isNewBranch'} = 1;
                   1056:         }
                   1057: 
                   1058:         # If this isn't an actual resource, continue on
                   1059:         if (!ref($curRes)) {
                   1060:             $curRes = $it->next();
                   1061:             next;
1.132     bowersj2 1062:         }
1.133     bowersj2 1063: 
                   1064:         $args->{'counter'}++;
1.143     bowersj2 1065: 
                   1066:         # If this has been filtered out, continue on
                   1067:         if (!(&$filterFunc($curRes))) {
                   1068:             $curRes = $it->next();
                   1069:             $args->{'isNewBranch'} = 0; # Don't falsely remember this
                   1070:             next;
                   1071:         } 
1.132     bowersj2 1072: 
                   1073:         # Does it have multiple parts?
1.133     bowersj2 1074:         $args->{'multipart'} = 0;
                   1075:         $args->{'condensed'} = 0;
1.132     bowersj2 1076:         my @parts;
                   1077:             
                   1078:         # Decide what parts to show.
1.133     bowersj2 1079:         if ($curRes->is_problem() && $showParts) {
1.132     bowersj2 1080:             @parts = @{$curRes->parts()};
1.133     bowersj2 1081:             $args->{'multipart'} = scalar(@parts) > 1;
1.132     bowersj2 1082:             
                   1083:             if ($condenseParts) { # do the condensation
                   1084:                 if (!$curRes->opendate("0")) {
                   1085:                     @parts = ("0");
1.133     bowersj2 1086:                     $args->{'condensed'} = 1;
1.132     bowersj2 1087:                 }
1.133     bowersj2 1088:                 if (!$args->{'condensed'}) {
1.132     bowersj2 1089:                     # Decide whether to condense based on similarity
                   1090:                     my $status = $curRes->status($parts[1]);
                   1091:                     my $due = $curRes->duedate($parts[1]);
                   1092:                     my $open = $curRes->opendate($parts[1]);
                   1093:                     my $statusAllSame = 1;
                   1094:                     my $dueAllSame = 1;
                   1095:                     my $openAllSame = 1;
                   1096:                     for (my $i = 2; $i < scalar(@parts); $i++) {
                   1097:                         if ($curRes->status($parts[$i]) != $status){
                   1098:                             $statusAllSame = 0;
                   1099:                         }
                   1100:                         if ($curRes->duedate($parts[$i]) != $due ) {
                   1101:                             $dueAllSame = 0;
                   1102:                         }
                   1103:                         if ($curRes->opendate($parts[$i]) != $open) {
                   1104:                             $openAllSame = 0;
                   1105:                         }
                   1106:                     }
                   1107:                     # $*allSame is true if all the statuses were
                   1108:                     # the same. Now, if they are all the same and
                   1109:                     # match one of the statuses to condense, or they
                   1110:                     # are all open with the same due date, or they are
                   1111:                     # all OPEN_LATER with the same open date, display the
                   1112:                     # status of the first non-zero part (to get the 'correct'
                   1113:                     # status right, since 0 is never 'correct' or 'open').
                   1114:                     if (($statusAllSame && defined($condenseStatuses{$status})) ||
                   1115:                         ($dueAllSame && $status == $curRes->OPEN && $statusAllSame)||
                   1116:                         ($openAllSame && $status == $curRes->OPEN_LATER && $statusAllSame) ){
                   1117:                         @parts = ($parts[1]);
1.133     bowersj2 1118:                         $args->{'condensed'} = 1;
1.132     bowersj2 1119:                     }
                   1120:                     
                   1121:                 }
                   1122:             }
                   1123:             
                   1124:         } else {
                   1125:             # Not showing parts
                   1126:             @parts = ("0"); # show main part only
                   1127:         }
                   1128: 
                   1129:         # If the multipart problem was condensed, "forget" it was multipart
                   1130:         if (scalar(@parts) == 1) {
1.133     bowersj2 1131:             $args->{'multipart'} = 0;
1.132     bowersj2 1132:         }
                   1133: 
                   1134:         # In the event of a network error, display one part.
                   1135:         # If this is a single part, we can at least show the correct
                   1136:         # status, but if it's multipart, we're lost, since we can't
                   1137:         # retreive the metadata to count the parts
                   1138:         if ($curRes->{RESOURCE_ERROR}) {
                   1139:             @parts = ("0");
                   1140:         }
                   1141: 
                   1142:         # Now, we've decided what parts to show. Loop through them and
                   1143:         # show them.
                   1144:         foreach my $part (@parts) {
                   1145:             $rownum ++;
                   1146:             my $backgroundColor = $backgroundColors[$rownum % scalar(@backgroundColors)];
                   1147:             
                   1148:             $result .= "  <tr bgcolor='$backgroundColor'>\n";
1.134     bowersj2 1149: 
                   1150:             # Set up some data about the parts that the cols might want
                   1151:             my $filter = $it->{FILTER};
                   1152:             my $stack = $it->getStack();
                   1153:             my $src = getLinkForResource($stack);
                   1154:             
                   1155:             my $srcHasQuestion = $src =~ /\?/;
                   1156:             $args->{"resourceLink"} = $src.
                   1157:                 ($srcHasQuestion?'&':'?') .
1.137     bowersj2 1158:                 'symb=' . &Apache::lonnet::escape($curRes->symb());
1.132     bowersj2 1159:             
                   1160:             # Now, display each column.
                   1161:             foreach my $col (@$cols) {
1.139     bowersj2 1162:                 my $colHTML = '';
                   1163:                 if (ref($col)) {
                   1164:                     $colHTML .= &$col($curRes, $part, $args);
                   1165:                 } else {
                   1166:                     $colHTML .= &{$preparedColumns[$col]}($curRes, $part, $args);
                   1167:                 }
1.132     bowersj2 1168: 
1.133     bowersj2 1169:                 # If this is the first column and it's time to print
                   1170:                 # the anchor, do so
                   1171:                 if ($col == $cols->[0] && 
                   1172:                     $args->{'counter'} == $args->{'currentJumpIndex'} - 
1.139     bowersj2 1173:                     $currentJumpDelta) {
                   1174:                     # Jam the anchor after the <td> tag;
                   1175:                     # necessary for valid HTML (which Mozilla requires)
                   1176:                     $colHTML =~ s/\>/\>\<a name="curloc" \/\>/;
1.133     bowersj2 1177:                     $displayedJumpMarker = 1;
                   1178:                 }
1.139     bowersj2 1179:                 $result .= $colHTML . "\n";
1.132     bowersj2 1180:             }
1.139     bowersj2 1181:             $result .= "    </tr>\n";
1.140     bowersj2 1182:             $args->{'isNewBranch'} = 0;
1.139     bowersj2 1183:         }
                   1184:         
                   1185:         if ($r && $rownum % 20 == 0) {
                   1186:             $r->print($result);
                   1187:             $result = "";
                   1188:             $r->rflush();
1.132     bowersj2 1189:         }
                   1190:         
                   1191:         $curRes = $it->next();
                   1192:     }
                   1193:     
1.134     bowersj2 1194:     # Print out the part that jumps to #curloc if it exists
1.139     bowersj2 1195:     if ($displayedJumpMarker) {
                   1196:         $result .= "<script>location += \"#curloc\";</script>\n";
1.134     bowersj2 1197:     }
                   1198: 
1.132     bowersj2 1199:     $result .= "</table>";
1.140     bowersj2 1200:     
                   1201:     if ($r) {
                   1202:         $r->print($result);
                   1203:         $result = "";
                   1204:         $r->rflush();
                   1205:     }
                   1206:         
                   1207:     if ($mustCloseNavMap) { $navmap->untieHashes(); } 
1.132     bowersj2 1208: 
                   1209:     return $result;
                   1210: }
                   1211: 
1.133     bowersj2 1212: 1;
                   1213: 
                   1214: package Apache::lonnavmaps::navmap;
                   1215: 
                   1216: =pod
                   1217: 
                   1218: lonnavmaps provides functions and objects for dealing with the compiled course hashes generated when a user enters the course, the Apache handler for the "Navigation Map" button, and a flexible prepared renderer for navigation maps that are easy to use anywhere.
                   1219: 
                   1220: =head1 navmap object: Encapsulating the compiled nav map
                   1221: 
                   1222: navmap is an object that encapsulates a compiled course map and provides a reasonable interface to it.
                   1223: 
                   1224: Most notably it provides a way to navigate the map sensibly and a flexible iterator that makes it easy to write various renderers based on nav maps.
                   1225: 
                   1226: You must obtain resource objects through the navmap object.
                   1227: 
                   1228: =head2 Methods
                   1229: 
                   1230: =over 4
                   1231: 
                   1232: =item * B<new>(navHashFile, parmHashFile, genCourseAndUserOptions, genMailDiscussStatus): Binds a new navmap object to the compiled nav map hash and parm hash given as filenames. genCourseAndUserOptions is a flag saying whether the course options and user options hash should be generated. This is for when you are using the parameters of the resources that require them; see documentation in resource object documentation. genMailDiscussStatus causes the nav map to retreive information about the email and discussion status of resources. Returns the navmap object if this is successful, or B<undef> if not. You must check for undef; errors will occur when you try to use the other methods otherwise.
                   1233: 
                   1234: =item * B<getIterator>(first, finish, filter, condition): See iterator documentation below.
                   1235: 
                   1236: =cut
                   1237: 
                   1238: use strict;
                   1239: use GDBM_File;
                   1240: 
                   1241: sub new {
                   1242:     # magic invocation to create a class instance
                   1243:     my $proto = shift;
                   1244:     my $class = ref($proto) || $proto;
                   1245:     my $self = {};
                   1246: 
                   1247:     $self->{NAV_HASH_FILE} = shift;
                   1248:     $self->{PARM_HASH_FILE} = shift;
                   1249:     $self->{GENERATE_COURSE_USER_OPT} = shift;
                   1250:     $self->{GENERATE_EMAIL_DISCUSS_STATUS} = shift;
                   1251: 
                   1252:     # Resource cache stores navmap resources as we reference them. We generate
                   1253:     # them on-demand so we don't pay for creating resources unless we use them.
                   1254:     $self->{RESOURCE_CACHE} = {};
                   1255: 
                   1256:     # Network failure flag, if we accessed the course or user opt and
                   1257:     # failed
                   1258:     $self->{NETWORK_FAILURE} = 0;
                   1259: 
                   1260:     # tie the nav hash
                   1261: 
                   1262:     if (!(tie(%navmaphash, 'GDBM_File', $self->{NAV_HASH_FILE},
                   1263:               &GDBM_READER(), 0640))) {
                   1264:         return undef;
                   1265:     }
                   1266:     
                   1267:     if (!(tie(%parmhash, 'GDBM_File', $self->{PARM_HASH_FILE},
                   1268:               &GDBM_READER(), 0640)))
                   1269:     {
                   1270:         untie $self->{PARM_HASH};
                   1271:         return undef;
                   1272:     }
                   1273: 
                   1274:     $self->{HASH_TIED} = 1;
                   1275:     $self->{NAV_HASH} = \%navmaphash;
                   1276:     $self->{PARM_HASH} = \%parmhash;
1.140     bowersj2 1277:     $self->{INITED} = 0;
1.133     bowersj2 1278: 
                   1279:     bless($self);
                   1280:         
                   1281:     return $self;
                   1282: }
                   1283: 
                   1284: sub init {
                   1285:     my $self = shift;
1.140     bowersj2 1286:     if ($self->{INITED}) { return; }
1.133     bowersj2 1287: 
                   1288:     # If the course opt hash and the user opt hash should be generated,
                   1289:     # generate them
                   1290:     if ($self->{GENERATE_COURSE_USER_OPT}) {
                   1291:         my $uname=$ENV{'user.name'};
                   1292:         my $udom=$ENV{'user.domain'};
                   1293:         my $uhome=$ENV{'user.home'};
                   1294:         my $cid=$ENV{'request.course.id'};
                   1295:         my $chome=$ENV{'course.'.$cid.'.home'};
                   1296:         my ($cdom,$cnum)=split(/\_/,$cid);
                   1297:         
                   1298:         my $userprefix=$uname.'_'.$udom.'_';
                   1299:         
                   1300:         my %courserdatas; my %useropt; my %courseopt; my %userrdatas;
                   1301:         unless ($uhome eq 'no_host') { 
                   1302: # ------------------------------------------------- Get coursedata (if present)
                   1303:             unless ((time-$courserdatas{$cid.'.last_cache'})<240) {
                   1304:                 my $reply=&Apache::lonnet::reply('dump:'.$cdom.':'.$cnum.
                   1305:                                                  ':resourcedata',$chome);
                   1306:                 if ($reply!~/^error\:/) {
                   1307:                     $courserdatas{$cid}=$reply;
                   1308:                     $courserdatas{$cid.'.last_cache'}=time;
                   1309:                 }
                   1310:                 # check to see if network failed
                   1311:                 elsif ( $reply=~/no.such.host/i || $reply=~/con.*lost/i )
                   1312:                 {
                   1313:                     $self->{NETWORK_FAILURE} = 1;
                   1314:                 }
                   1315:             }
                   1316:             foreach (split(/\&/,$courserdatas{$cid})) {
                   1317:                 my ($name,$value)=split(/\=/,$_);
                   1318:                 $courseopt{$userprefix.&Apache::lonnet::unescape($name)}=
                   1319:                     &Apache::lonnet::unescape($value);
                   1320:             }
                   1321: # --------------------------------------------------- Get userdata (if present)
                   1322:             unless ((time-$userrdatas{$uname.'___'.$udom.'.last_cache'})<240) {
                   1323:                 my $reply=&Apache::lonnet::reply('dump:'.$udom.':'.$uname.':resourcedata',$uhome);
                   1324:                 if ($reply!~/^error\:/) {
                   1325:                     $userrdatas{$uname.'___'.$udom}=$reply;
                   1326:                     $userrdatas{$uname.'___'.$udom.'.last_cache'}=time;
                   1327:                 }
                   1328:                 # check to see if network failed
                   1329:                 elsif ( $reply=~/no.such.host/i || $reply=~/con.*lost/i )
                   1330:                 {
                   1331:                     $self->{NETWORK_FAILURE} = 1;
                   1332:                 }
                   1333:             }
                   1334:             foreach (split(/\&/,$userrdatas{$uname.'___'.$udom})) {
                   1335:                 my ($name,$value)=split(/\=/,$_);
                   1336:                 $useropt{$userprefix.&Apache::lonnet::unescape($name)}=
                   1337:                     &Apache::lonnet::unescape($value);
                   1338:             }
                   1339:             $self->{COURSE_OPT} = \%courseopt;
                   1340:             $self->{USER_OPT} = \%useropt;
                   1341:         }
                   1342:     }   
                   1343: 
                   1344:     if ($self->{GENERATE_EMAIL_DISCUSS_STATUS}) {
                   1345:         my $cid=$ENV{'request.course.id'};
                   1346:         my ($cdom,$cnum)=split(/\_/,$cid);
                   1347:         
                   1348:         my %emailstatus = &Apache::lonnet::dump('email_status');
                   1349:         my $logoutTime = $emailstatus{'logout'};
                   1350:         my $courseLeaveTime = $emailstatus{'logout_'.$ENV{'request.course.id'}};
                   1351:         $self->{LAST_CHECK} = ($courseLeaveTime < $logoutTime ?
                   1352:                                $courseLeaveTime : $logoutTime);
                   1353:         my %discussiontime = &Apache::lonnet::dump('discussiontimes', 
                   1354:                                                    $cdom, $cnum);
                   1355:         my %feedback=();
                   1356:         my %error=();
                   1357:         my $keys = &Apache::lonnet::reply('keys:'.
                   1358:                                           $ENV{'user.domain'}.':'.
                   1359:                                           $ENV{'user.name'}.':nohist_email',
                   1360:                                           $ENV{'user.home'});
                   1361: 
                   1362:         foreach my $msgid (split(/\&/, $keys)) {
                   1363:             $msgid=&Apache::lonnet::unescape($msgid);
                   1364:             my $plain=&Apache::lonnet::unescape(&Apache::lonnet::unescape($msgid));
                   1365:             if ($plain=~/(Error|Feedback) \[([^\]]+)\]/) {
                   1366:                 my ($what,$url)=($1,$2);
                   1367:                 my %status=
                   1368:                     &Apache::lonnet::get('email_status',[$msgid]);
                   1369:                 if ($status{$msgid}=~/^error\:/) { 
                   1370:                     $status{$msgid}=''; 
                   1371:                 }
                   1372:                 
                   1373:                 if (($status{$msgid} eq 'new') || 
                   1374:                     (!$status{$msgid})) { 
                   1375:                     if ($what eq 'Error') {
                   1376:                         $error{$url}.=','.$msgid; 
                   1377:                     } else {
                   1378:                         $feedback{$url}.=','.$msgid;
                   1379:                     }
                   1380:                 }
                   1381:             }
                   1382:         }
                   1383:         
                   1384:         $self->{FEEDBACK} = \%feedback;
                   1385:         $self->{ERROR_MSG} = \%error; # what is this? JB
                   1386:         $self->{DISCUSSION_TIME} = \%discussiontime;
                   1387:         $self->{EMAIL_STATUS} = \%emailstatus;
                   1388:         
                   1389:     }    
                   1390: 
                   1391:     $self->{PARM_CACHE} = {};
1.140     bowersj2 1392:     $self->{INITED} = 1;
1.133     bowersj2 1393: }
                   1394: 
                   1395: # Internal function: Takes a key to look up in the nav hash and implements internal
                   1396: # memory caching of that key.
                   1397: sub navhash {
                   1398:     my $self = shift; my $key = shift;
                   1399:     return $self->{NAV_HASH}->{$key};
                   1400: }
                   1401: 
                   1402: # Checks to see if coursemap is defined, matching test in old lonnavmaps
                   1403: sub courseMapDefined {
                   1404:     my $self = shift;
                   1405:     my $uri = &Apache::lonnet::clutter($ENV{'request.course.uri'});
                   1406: 
                   1407:     my $firstres = $self->navhash("map_start_$uri");
                   1408:     my $lastres = $self->navhash("map_finish_$uri");
                   1409:     return $firstres && $lastres;
                   1410: }
                   1411: 
                   1412: sub getIterator {
                   1413:     my $self = shift;
                   1414:     my $iterator = Apache::lonnavmaps::iterator->new($self, shift, shift,
                   1415:                                                      shift, undef, shift);
                   1416:     return $iterator;
                   1417: }
                   1418: 
                   1419: # unties the hash when done
                   1420: sub untieHashes {
                   1421:     my $self = shift;
                   1422:     untie %{$self->{NAV_HASH}} if ($self->{HASH_TIED});
                   1423:     untie %{$self->{PARM_HASH}} if ($self->{HASH_TIED});
                   1424:     $self->{HASH_TIED} = 0;
                   1425: }
                   1426: 
                   1427: # when the object is destroyed, be sure to untie all the hashes we tied.
                   1428: sub DESTROY {
                   1429:     my $self = shift;
                   1430:     $self->untieHashes();
                   1431: }
                   1432: 
                   1433: # Private method: Does the given resource (as a symb string) have
                   1434: # current discussion? Returns 0 if chat/mail data not extracted.
                   1435: sub hasDiscussion {
                   1436:     my $self = shift;
                   1437:     my $symb = shift;
                   1438:     if (!defined($self->{DISCUSSION_TIME})) { return 0; }
                   1439: 
                   1440:     #return defined($self->{DISCUSSION_TIME}->{$symb});
                   1441:     return $self->{DISCUSSION_TIME}->{$symb} >
                   1442:            $self->{LAST_CHECK};
                   1443: }
                   1444: 
                   1445: # Private method: Does the given resource (as a symb string) have
                   1446: # current feedback? Returns the string in the feedback hash, which
                   1447: # will be false if it does not exist.
                   1448: sub getFeedback { 
                   1449:     my $self = shift;
                   1450:     my $symb = shift;
                   1451: 
                   1452:     if (!defined($self->{FEEDBACK})) { return ""; }
                   1453:     
                   1454:     return $self->{FEEDBACK}->{$symb};
                   1455: }
                   1456: 
                   1457: # Private method: Get the errors for that resource (by source).
                   1458: sub getErrors { 
                   1459:     my $self = shift;
                   1460:     my $src = shift;
                   1461:     
                   1462:     if (!defined($self->{ERROR_MSG})) { return ""; }
                   1463:     return $self->{ERROR_MSG}->{$src};
                   1464: }
                   1465: 
                   1466: =pod
                   1467: 
                   1468: =item * B<getById>(id): Based on the ID of the resource (1.1, 3.2, etc.), get a resource object for that resource. This method, or other methods that use it (as in the resource object) is the only proper way to obtain a resource object.
                   1469: 
                   1470: =cut
                   1471: 
                   1472: # The strategy here is to cache the resource objects, and only construct them
                   1473: # as we use them. The real point is to prevent reading any more from the tied
                   1474: # hash then we have to, which should hopefully alleviate speed problems.
                   1475: # Caching is just an incidental detail I throw in because it makes sense.
                   1476: 
                   1477: sub getById {
                   1478:     my $self = shift;
                   1479:     my $id = shift;
                   1480: 
                   1481:     if (defined ($self->{RESOURCE_CACHE}->{$id}))
                   1482:     {
                   1483:         return $self->{RESOURCE_CACHE}->{$id};
                   1484:     }
                   1485: 
                   1486:     # resource handles inserting itself into cache.
                   1487:     # Not clear why the quotes are necessary, but as of this
                   1488:     # writing it doesn't work without them.
                   1489:     return "Apache::lonnavmaps::resource"->new($self, $id);
1.132     bowersj2 1490: }
1.133     bowersj2 1491: 
                   1492: =pod
                   1493: 
                   1494: =item * B<firstResource>(): Returns a resource object reference corresponding to the first resource in the navmap.
                   1495: 
                   1496: =cut
                   1497: 
                   1498: sub firstResource {
                   1499:     my $self = shift;
                   1500:     my $firstResource = $self->navhash('map_start_' .
                   1501:                      &Apache::lonnet::clutter($ENV{'request.course.uri'}));
                   1502:     return $self->getById($firstResource);
1.132     bowersj2 1503: }
1.133     bowersj2 1504: 
                   1505: =pod
                   1506: 
                   1507: =item * B<finishResource>(): Returns a resource object reference corresponding to the last resource in the navmap.
                   1508: 
                   1509: =cut
                   1510: 
                   1511: sub finishResource {
                   1512:     my $self = shift;
                   1513:     my $firstResource = $self->navhash('map_finish_' .
                   1514:                      &Apache::lonnet::clutter($ENV{'request.course.uri'}));
                   1515:     return $self->getById($firstResource);
1.132     bowersj2 1516: }
1.133     bowersj2 1517: 
                   1518: # Parmval reads the parm hash and cascades the lookups. parmval_real does
                   1519: # the actual lookup; parmval caches the results.
                   1520: sub parmval {
                   1521:     my $self = shift;
                   1522:     my ($what,$symb)=@_;
                   1523:     my $hashkey = $what."|||".$symb;
                   1524: 
                   1525:     if (defined($self->{PARM_CACHE}->{$hashkey})) {
                   1526:         return $self->{PARM_CACHE}->{$hashkey};
                   1527:     }
                   1528: 
                   1529:     my $result = $self->parmval_real($what, $symb);
                   1530:     $self->{PARM_CACHE}->{$hashkey} = $result;
                   1531:     return $result;
1.132     bowersj2 1532: }
                   1533: 
1.133     bowersj2 1534: sub parmval_real {
                   1535:     my $self = shift;
                   1536:     my ($what,$symb) = @_;
                   1537: 
                   1538:     my $cid=$ENV{'request.course.id'};
                   1539:     my $csec=$ENV{'request.course.sec'};
                   1540:     my $uname=$ENV{'user.name'};
                   1541:     my $udom=$ENV{'user.domain'};
                   1542: 
                   1543:     unless ($symb) { return ''; }
                   1544:     my $result='';
                   1545: 
                   1546:     my ($mapname,$id,$fn)=split(/\_\_\_/,$symb);
                   1547: 
                   1548: # ----------------------------------------------------- Cascading lookup scheme
                   1549:     my $rwhat=$what;
                   1550:     $what=~s/^parameter\_//;
                   1551:     $what=~s/\_/\./;
                   1552: 
                   1553:     my $symbparm=$symb.'.'.$what;
                   1554:     my $mapparm=$mapname.'___(all).'.$what;
                   1555:     my $usercourseprefix=$uname.'_'.$udom.'_'.$cid;
                   1556: 
                   1557:     my $seclevel= $usercourseprefix.'.['.$csec.'].'.$what;
                   1558:     my $seclevelr=$usercourseprefix.'.['.$csec.'].'.$symbparm;
                   1559:     my $seclevelm=$usercourseprefix.'.['.$csec.'].'.$mapparm;
                   1560: 
                   1561:     my $courselevel= $usercourseprefix.'.'.$what;
                   1562:     my $courselevelr=$usercourseprefix.'.'.$symbparm;
                   1563:     my $courselevelm=$usercourseprefix.'.'.$mapparm;
                   1564: 
                   1565:     my $useropt = $self->{USER_OPT};
                   1566:     my $courseopt = $self->{COURSE_OPT};
                   1567:     my $parmhash = $self->{PARM_HASH};
                   1568: 
                   1569: # ---------------------------------------------------------- first, check user
                   1570:     if ($uname and defined($useropt)) {
                   1571:         if (defined($$useropt{$courselevelr})) { return $$useropt{$courselevelr}; }
                   1572:         if (defined($$useropt{$courselevelm})) { return $$useropt{$courselevelm}; }
                   1573:         if (defined($$useropt{$courselevel})) { return $$useropt{$courselevel}; }
                   1574:     }
                   1575: 
                   1576: # ------------------------------------------------------- second, check course
                   1577:     if ($csec and defined($courseopt)) {
                   1578:         if (defined($$courseopt{$seclevelr})) { return $$courseopt{$seclevelr}; }
                   1579:         if (defined($$courseopt{$seclevelm})) { return $$courseopt{$seclevelm}; }
                   1580:         if (defined($$courseopt{$seclevel})) { return $$courseopt{$seclevel}; }
                   1581:     }
                   1582: 
                   1583:     if (defined($courseopt)) {
                   1584:         if (defined($$courseopt{$courselevelr})) { return $$courseopt{$courselevelr}; }
                   1585:         if (defined($$courseopt{$courselevelm})) { return $$courseopt{$courselevelm}; }
                   1586:         if (defined($$courseopt{$courselevel})) { return $$courseopt{$courselevel}; }
                   1587:     }
                   1588: 
                   1589: # ----------------------------------------------------- third, check map parms
                   1590: 
                   1591:     my $thisparm=$$parmhash{$symbparm};
                   1592:     if (defined($thisparm)) { return $thisparm; }
                   1593: 
                   1594: # ----------------------------------------------------- fourth , check default
                   1595: 
                   1596:     my $default=&Apache::lonnet::metadata($fn,$rwhat.'.default');
                   1597:     if (defined($default)) { return $default}
                   1598: 
                   1599: # --------------------------------------------------- fifth , cascade up parts
                   1600: 
                   1601:     my ($space,@qualifier)=split(/\./,$rwhat);
                   1602:     my $qualifier=join('.',@qualifier);
                   1603:     unless ($space eq '0') {
                   1604:         my ($part,$id)=split(/\_/,$space);
                   1605:         if ($id) {
                   1606:             my $partgeneral=$self->parmval($part.".$qualifier",$symb);
                   1607:             if (defined($partgeneral)) { return $partgeneral; }
                   1608:         } else {
                   1609:             my $resourcegeneral=$self->parmval("0.$qualifier",$symb);
                   1610:             if (defined($resourcegeneral)) { return $resourcegeneral; }
                   1611:         }
                   1612:     }
                   1613:     return '';
                   1614: }
1.51      bowersj2 1615: 
                   1616: 1;
                   1617: 
                   1618: package Apache::lonnavmaps::iterator;
                   1619: 
                   1620: =pod
                   1621: 
                   1622: =back
                   1623: 
                   1624: =head1 navmap Iterator
                   1625: 
                   1626: An I<iterator> encapsulates the logic required to traverse a data structure. navmap uses an iterator to traverse the course map according to the criteria you wish to use.
                   1627: 
                   1628: To obtain an iterator, call the B<getIterator>() function of a B<navmap> object. (Do not instantiate Apache::lonnavmaps::iterator directly.) This will return a reference to the iterator:
                   1629: 
                   1630: C<my $resourceIterator = $navmap-E<gt>getIterator();>
                   1631: 
                   1632: To get the next thing from the iterator, call B<next>:
                   1633: 
                   1634: C<my $nextThing = $resourceIterator-E<gt>next()>
                   1635: 
                   1636: getIterator behaves as follows:
                   1637: 
                   1638: =over 4
                   1639: 
1.116     bowersj2 1640: =item * B<getIterator>(firstResource, finishResource, filterHash, condition, forceTop): All parameters are optional. firstResource is a resource reference corresponding to where the iterator should start. It defaults to navmap->firstResource() for the corresponding nav map. finishResource corresponds to where you want the iterator to end, defaulting to navmap->finishResource(). filterHash is a hash used as a set containing strings representing the resource IDs, defaulting to empty. Condition is a 1 or 0 that sets what to do with the filter hash: If a 0, then only resource that exist IN the filterHash will be recursed on. If it is a 1, only resources NOT in the filterHash will be recursed on. Defaults to 0. forceTop is a boolean value. If it is false (default), the iterator will only return the first level of map that is not just a single, 'redirecting' map. If true, the iterator will return all information, starting with the top-level map, regardless of content.
1.51      bowersj2 1641: 
1.101     bowersj2 1642: Thus, by default, only top-level resources will be shown. Change the condition to a 1 without changing the hash, and all resources will be shown. Changing the condition to 1 and including some values in the hash will allow you to selectively suppress parts of the navmap, while leaving it on 0 and adding things to the hash will allow you to selectively add parts of the nav map. See the handler code for examples.
1.51      bowersj2 1643: 
                   1644: The iterator will return either a reference to a resource object, or a token representing something in the map, such as the beginning of a new branch. The possible tokens are:
                   1645: 
                   1646: =over 4
                   1647: 
1.70      bowersj2 1648: =item * BEGIN_MAP: A new map is being recursed into. This is returned I<after> the map resource itself is returned.
                   1649: 
                   1650: =item * END_MAP: The map is now done.
                   1651: 
                   1652: =item * BEGIN_BRANCH: A branch is now starting. The next resource returned will be the first in that branch.
                   1653: 
                   1654: =item * END_BRANCH: The branch is now done.
1.51      bowersj2 1655: 
                   1656: =back
                   1657: 
1.70      bowersj2 1658: The tokens are retreivable via methods on the iterator object, i.e., $iterator->END_MAP.
                   1659: 
1.116     bowersj2 1660: Maps can contain empty resources. The iterator will automatically skip over such resources, but will still treat the structure correctly. Thus, a complicated map with several branches, but consisting entirely of empty resources except for one beginning or ending resource, will cause a lot of BRANCH_STARTs and BRANCH_ENDs, but only one resource will be returned.
                   1661: 
1.70      bowersj2 1662: =back
1.51      bowersj2 1663: 
                   1664: =cut
                   1665: 
                   1666: # Here are the tokens for the iterator:
                   1667: 
                   1668: sub BEGIN_MAP { return 1; }    # begining of a new map
                   1669: sub END_MAP { return 2; }      # end of the map
                   1670: sub BEGIN_BRANCH { return 3; } # beginning of a branch
                   1671: sub END_BRANCH { return 4; }   # end of a branch
1.89      bowersj2 1672: sub FORWARD { return 1; }      # go forward
                   1673: sub BACKWARD { return 2; }
1.51      bowersj2 1674: 
1.96      bowersj2 1675: sub min {
                   1676:     (my $a, my $b) = @_;
                   1677:     if ($a < $b) { return $a; } else { return $b; }
                   1678: }
                   1679: 
1.107     bowersj2 1680: # In the CVS repository, documentation of this algorithm is included 
                   1681: # in /doc/lonnavdocs, as a PDF and .tex source. Markers like **1**
                   1682: # will reference the same location in the text as the part of the
                   1683: # algorithm is running through.
                   1684: 
1.94      bowersj2 1685: sub new {
                   1686:     # magic invocation to create a class instance
                   1687:     my $proto = shift;
                   1688:     my $class = ref($proto) || $proto;
                   1689:     my $self = {};
                   1690: 
                   1691:     $self->{NAV_MAP} = shift;
                   1692:     return undef unless ($self->{NAV_MAP});
                   1693: 
                   1694:     # Handle the parameters
                   1695:     $self->{FIRST_RESOURCE} = shift || $self->{NAV_MAP}->firstResource();
                   1696:     $self->{FINISH_RESOURCE} = shift || $self->{NAV_MAP}->finishResource();
                   1697: 
                   1698:     # If the given resources are just the ID of the resource, get the
                   1699:     # objects
                   1700:     if (!ref($self->{FIRST_RESOURCE})) { $self->{FIRST_RESOURCE} = 
                   1701:              $self->{NAV_MAP}->getById($self->{FIRST_RESOURCE}); }
                   1702:     if (!ref($self->{FINISH_RESOURCE})) { $self->{FINISH_RESOURCE} = 
                   1703:              $self->{NAV_MAP}->getById($self->{FINISH_RESOURCE}); }
                   1704: 
                   1705:     $self->{FILTER} = shift;
                   1706: 
                   1707:     # A hash, used as a set, of resource already seen
                   1708:     $self->{ALREADY_SEEN} = shift;
                   1709:     if (!defined($self->{ALREADY_SEEN})) { $self->{ALREADY_SEEN} = {} };
                   1710:     $self->{CONDITION} = shift;
                   1711: 
1.116     bowersj2 1712:     # Do we want to automatically follow "redirection" maps?
                   1713:     $self->{FORCE_TOP} = shift;
                   1714: 
1.94      bowersj2 1715:     # Now, we need to pre-process the map, by walking forward and backward
                   1716:     # over the parts of the map we're going to look at.
1.96      bowersj2 1717: 
1.97      bowersj2 1718:     # The processing steps are exactly the same, except for a few small 
                   1719:     # changes, so I bundle those up in the following list of two elements:
                   1720:     # (direction_to_iterate, VAL_name, next_resource_method_to_call,
                   1721:     # first_resource).
                   1722:     # This prevents writing nearly-identical code twice.
                   1723:     my @iterations = ( [FORWARD(), 'TOP_DOWN_VAL', 'getNext', 
                   1724:                         'FIRST_RESOURCE'],
                   1725:                        [BACKWARD(), 'BOT_UP_VAL', 'getPrevious', 
                   1726:                         'FINISH_RESOURCE'] );
                   1727: 
1.98      bowersj2 1728:     my $maxDepth = 0; # tracks max depth
                   1729: 
1.116     bowersj2 1730:     # If there is only one resource in this map, and it's a map, we
                   1731:     # want to remember that, so the user can ask for the first map
                   1732:     # that isn't just a redirector.
                   1733:     my $resource; my $resourceCount = 0;
                   1734: 
1.107     bowersj2 1735:     # **1**
                   1736: 
1.97      bowersj2 1737:     foreach my $pass (@iterations) {
                   1738:         my $direction = $pass->[0];
                   1739:         my $valName = $pass->[1];
                   1740:         my $nextResourceMethod = $pass->[2];
                   1741:         my $firstResourceName = $pass->[3];
                   1742: 
                   1743:         my $iterator = Apache::lonnavmaps::DFSiterator->new($self->{NAV_MAP}, 
                   1744:                                                             $self->{FIRST_RESOURCE},
                   1745:                                                             $self->{FINISH_RESOURCE},
                   1746:                                                             {}, undef, 0, $direction);
1.96      bowersj2 1747:     
1.97      bowersj2 1748:         # prime the recursion
                   1749:         $self->{$firstResourceName}->{DATA}->{$valName} = 0;
1.98      bowersj2 1750:         my $depth = 0;
1.97      bowersj2 1751:         $iterator->next();
                   1752:         my $curRes = $iterator->next();
1.98      bowersj2 1753:         while ($depth > -1) {
1.97      bowersj2 1754:             if ($curRes == $iterator->BEGIN_MAP()) { $depth++; }
                   1755:             if ($curRes == $iterator->END_MAP()) { $depth--; }
1.96      bowersj2 1756:         
1.97      bowersj2 1757:             if (ref($curRes)) {
1.116     bowersj2 1758:                 # If there's only one resource, this will save it
1.117     bowersj2 1759:                 # we have to filter empty resources from consideration here,
                   1760:                 # or even "empty", redirecting maps have two (start & finish)
                   1761:                 # or three (start, finish, plus redirector)
                   1762:                 if($direction == FORWARD && $curRes->src()) { 
                   1763:                     $resource = $curRes; $resourceCount++; 
                   1764:                 }
1.97      bowersj2 1765:                 my $resultingVal = $curRes->{DATA}->{$valName};
                   1766:                 my $nextResources = $curRes->$nextResourceMethod();
1.116     bowersj2 1767:                 my $nextCount = scalar(@{$nextResources});
1.104     bowersj2 1768: 
1.116     bowersj2 1769:                 if ($nextCount == 1) { # **3**
1.97      bowersj2 1770:                     my $current = $nextResources->[0]->{DATA}->{$valName} || 999999999;
                   1771:                     $nextResources->[0]->{DATA}->{$valName} = min($resultingVal, $current);
                   1772:                 }
                   1773:                 
1.116     bowersj2 1774:                 if ($nextCount > 1) { # **4**
1.97      bowersj2 1775:                     foreach my $res (@{$nextResources}) {
                   1776:                         my $current = $res->{DATA}->{$valName} || 999999999;
                   1777:                         $res->{DATA}->{$valName} = min($current, $resultingVal + 1);
                   1778:                     }
                   1779:                 }
                   1780:             }
1.96      bowersj2 1781:             
1.107     bowersj2 1782:             # Assign the final val (**2**)
1.97      bowersj2 1783:             if (ref($curRes) && $direction == BACKWARD()) {
1.98      bowersj2 1784:                 my $finalDepth = min($curRes->{DATA}->{TOP_DOWN_VAL},
                   1785:                                      $curRes->{DATA}->{BOT_UP_VAL});
                   1786:                 
                   1787:                 $curRes->{DATA}->{DISPLAY_DEPTH} = $finalDepth;
                   1788:                 if ($finalDepth > $maxDepth) {$maxDepth = $finalDepth;}
                   1789:                 }
1.97      bowersj2 1790:             $curRes = $iterator->next();
1.96      bowersj2 1791:         }
                   1792:     }
1.94      bowersj2 1793: 
1.116     bowersj2 1794:     # Check: Was this only one resource, a map?
                   1795:     if ($resourceCount == 1 && $resource->is_map() && !$self->{FORCE_TOP}) { 
                   1796:         my $firstResource = $resource->map_start();
                   1797:         my $finishResource = $resource->map_finish();
                   1798:         return 
                   1799:             Apache::lonnavmaps::iterator->new($self->{NAV_MAP}, $firstResource,
                   1800:                                               $finishResource, $self->{FILTER},
                   1801:                                               $self->{ALREADY_SEEN}, 
                   1802:                                               $self->{CONDITION}, 0);
                   1803:         
                   1804:     }
                   1805: 
1.98      bowersj2 1806:     # Set up some bookkeeping information.
                   1807:     $self->{CURRENT_DEPTH} = 0;
                   1808:     $self->{MAX_DEPTH} = $maxDepth;
                   1809:     $self->{STACK} = [];
                   1810:     $self->{RECURSIVE_ITERATOR_FLAG} = 0;
                   1811: 
                   1812:     for (my $i = 0; $i <= $self->{MAX_DEPTH}; $i++) {
                   1813:         push @{$self->{STACK}}, [];
                   1814:     }
                   1815: 
1.107     bowersj2 1816:     # Prime the recursion w/ the first resource **5**
1.98      bowersj2 1817:     push @{$self->{STACK}->[0]}, $self->{FIRST_RESOURCE};
                   1818:     $self->{ALREADY_SEEN}->{$self->{FIRST_RESOURCE}->{ID}} = 1;
                   1819: 
                   1820:     bless ($self);
                   1821: 
                   1822:     return $self;
                   1823: }
                   1824: 
                   1825: sub next {
                   1826:     my $self = shift;
                   1827: 
                   1828:     if ($self->{RECURSIVE_ITERATOR_FLAG}) {
                   1829:         # grab the next from the recursive iterator 
                   1830:         my $next = $self->{RECURSIVE_ITERATOR}->next();
                   1831: 
                   1832:         # is it a begin or end map? If so, update the depth
                   1833:         if ($next == BEGIN_MAP() ) { $self->{RECURSIVE_DEPTH}++; }
                   1834:         if ($next == END_MAP() ) { $self->{RECURSIVE_DEPTH}--; }
                   1835: 
                   1836:         # Are we back at depth 0? If so, stop recursing
                   1837:         if ($self->{RECURSIVE_DEPTH} == 0) {
                   1838:             $self->{RECURSIVE_ITERATOR_FLAG} = 0;
                   1839:         }
                   1840: 
                   1841:         return $next;
                   1842:     }
                   1843: 
                   1844:     if (defined($self->{FORCE_NEXT})) {
                   1845:         my $tmp = $self->{FORCE_NEXT};
                   1846:         $self->{FORCE_NEXT} = undef;
                   1847:         return $tmp;
                   1848:     }
                   1849: 
                   1850:     # Have we not yet begun? If not, return BEGIN_MAP and
                   1851:     # remember we've started.
                   1852:     if ( !$self->{STARTED} ) { 
                   1853:         $self->{STARTED} = 1;
                   1854:         return $self->BEGIN_MAP();
                   1855:     }
                   1856: 
                   1857:     # Here's the guts of the iterator.
                   1858:     
                   1859:     # Find the next resource, if any.
                   1860:     my $found = 0;
                   1861:     my $i = $self->{MAX_DEPTH};
                   1862:     my $newDepth;
                   1863:     my $here;
                   1864:     while ( $i >= 0 && !$found ) {
1.107     bowersj2 1865:         if ( scalar(@{$self->{STACK}->[$i]}) > 0 ) { # **6**
                   1866:             $here = pop @{$self->{STACK}->[$i]}; # **7**
1.98      bowersj2 1867:             $found = 1;
                   1868:             $newDepth = $i;
                   1869:         }
                   1870:         $i--;
                   1871:     }
                   1872: 
                   1873:     # If we still didn't find anything, we're done.
                   1874:     if ( !$found ) {
                   1875:         # We need to get back down to the correct branch depth
                   1876:         if ( $self->{CURRENT_DEPTH} > 0 ) {
                   1877:             $self->{CURRENT_DEPTH}--;
                   1878:             return END_BRANCH();
                   1879:         } else {
                   1880:             return END_MAP();
                   1881:         }
                   1882:     }
                   1883: 
1.104     bowersj2 1884:     # If this is not a resource, it must be an END_BRANCH marker we want
                   1885:     # to return directly.
1.107     bowersj2 1886:     if (!ref($here)) { # **8**
1.104     bowersj2 1887:         if ($here == END_BRANCH()) { # paranoia, in case of later extension
                   1888:             $self->{CURRENT_DEPTH}--;
                   1889:             return $here;
                   1890:         }
                   1891:     }
                   1892: 
                   1893:     # Otherwise, it is a resource and it's safe to store in $self->{HERE}
                   1894:     $self->{HERE} = $here;
                   1895: 
1.98      bowersj2 1896:     # Get to the right level
                   1897:     if ( $self->{CURRENT_DEPTH} > $newDepth ) {
                   1898:         push @{$self->{STACK}->[$newDepth]}, $here;
                   1899:         $self->{CURRENT_DEPTH}--;
                   1900:         return END_BRANCH();
                   1901:     }
                   1902:     if ( $self->{CURRENT_DEPTH} < $newDepth) {
                   1903:         push @{$self->{STACK}->[$newDepth]}, $here;
                   1904:         $self->{CURRENT_DEPTH}++;
                   1905:         return BEGIN_BRANCH();
                   1906:     }
                   1907: 
                   1908:     # If we made it here, we have the next resource, and we're at the
                   1909:     # right branch level. So let's examine the resource for where
                   1910:     # we can get to from here.
                   1911: 
                   1912:     # So we need to look at all the resources we can get to from here,
                   1913:     # categorize them if we haven't seen them, remember if we have a new
                   1914:     my $nextUnfiltered = $here->getNext();
1.104     bowersj2 1915:     my $maxDepthAdded = -1;
                   1916:     
1.98      bowersj2 1917:     for (@$nextUnfiltered) {
                   1918:         if (!defined($self->{ALREADY_SEEN}->{$_->{ID}})) {
1.104     bowersj2 1919:             my $depth = $_->{DATA}->{DISPLAY_DEPTH};
                   1920:             push @{$self->{STACK}->[$depth]}, $_;
1.98      bowersj2 1921:             $self->{ALREADY_SEEN}->{$_->{ID}} = 1;
1.104     bowersj2 1922:             if ($maxDepthAdded < $depth) { $maxDepthAdded = $depth; }
1.98      bowersj2 1923:         }
                   1924:     }
1.104     bowersj2 1925: 
                   1926:     # Is this the end of a branch? If so, all of the resources examined above
                   1927:     # led to lower levels then the one we are currently at, so we push a END_BRANCH
                   1928:     # marker onto the stack so we don't forget.
                   1929:     # Example: For the usual A(BC)(DE)F case, when the iterator goes down the
                   1930:     # BC branch and gets to C, it will see F as the only next resource, but it's
                   1931:     # one level lower. Thus, this is the end of the branch, since there are no
                   1932:     # more resources added to this level or above.
1.111     bowersj2 1933:     # We don't do this if the examined resource is the finish resource,
                   1934:     # because the condition given above is true, but the "END_MAP" will
                   1935:     # take care of things and we should already be at depth 0.
1.104     bowersj2 1936:     my $isEndOfBranch = $maxDepthAdded < $self->{CURRENT_DEPTH};
1.111     bowersj2 1937:     if ($isEndOfBranch && $here != $self->{FINISH_RESOURCE}) { # **9**
1.104     bowersj2 1938:         push @{$self->{STACK}->[$self->{CURRENT_DEPTH}]}, END_BRANCH();
                   1939:     }
                   1940: 
1.98      bowersj2 1941:     # That ends the main iterator logic. Now, do we want to recurse
                   1942:     # down this map (if this resource is a map)?
                   1943:     if ($self->{HERE}->is_map() &&
                   1944:         (defined($self->{FILTER}->{$self->{HERE}->map_pc()}) xor $self->{CONDITION})) {
                   1945:         $self->{RECURSIVE_ITERATOR_FLAG} = 1;
                   1946:         my $firstResource = $self->{HERE}->map_start();
                   1947:         my $finishResource = $self->{HERE}->map_finish();
                   1948: 
                   1949:         $self->{RECURSIVE_ITERATOR} = 
                   1950:             Apache::lonnavmaps::iterator->new($self->{NAV_MAP}, $firstResource,
                   1951:                                               $finishResource, $self->{FILTER},
                   1952:                                               $self->{ALREADY_SEEN}, $self->{CONDITION});
                   1953:     }
                   1954: 
1.116     bowersj2 1955:     # If this is a blank resource, don't actually return it.
1.117     bowersj2 1956:     # Should you ever find you need it, make sure to add an option to the code
                   1957:     #  that you can use; other things depend on this behavior.
1.138     bowersj2 1958:     my $browsePriv = $self->{HERE}->browsePriv();
                   1959:     if (!$self->{HERE}->src() || 
                   1960:         (!($browsePriv eq 'F') && !($browsePriv eq '2')) ) {
1.116     bowersj2 1961:         return $self->next();
                   1962:     }
                   1963: 
1.98      bowersj2 1964:     return $self->{HERE};
                   1965: 
                   1966: }
                   1967: 
                   1968: =pod
                   1969: 
                   1970: The other method available on the iterator is B<getStack>, which returns an array populated with the current 'stack' of maps, as references to the resource objects. Example: This is useful when making the navigation map, as we need to check whether we are under a page map to see if we need to link directly to the resource, or to the page. The first elements in the array will correspond to the top of the stack (most inclusive map).
                   1971: 
                   1972: =cut
                   1973: 
                   1974: sub getStack {
                   1975:     my $self=shift;
                   1976: 
                   1977:     my @stack;
                   1978: 
                   1979:     $self->populateStack(\@stack);
                   1980: 
                   1981:     return \@stack;
                   1982: }
                   1983: 
                   1984: # Private method: Calls the iterators recursively to populate the stack.
                   1985: sub populateStack {
                   1986:     my $self=shift;
                   1987:     my $stack = shift;
                   1988: 
                   1989:     push @$stack, $self->{HERE} if ($self->{HERE});
                   1990: 
                   1991:     if ($self->{RECURSIVE_ITERATOR_FLAG}) {
                   1992:         $self->{RECURSIVE_ITERATOR}->populateStack($stack);
                   1993:     }
1.94      bowersj2 1994: }
                   1995: 
                   1996: 1;
                   1997: 
                   1998: package Apache::lonnavmaps::DFSiterator;
                   1999: 
1.100     bowersj2 2000: # Not documented in the perldoc: This is a simple iterator that just walks
                   2001: #  through the nav map and presents the resources in a depth-first search
                   2002: #  fashion, ignorant of conditionals, randomized resources, etc. It presents
                   2003: #  BEGIN_MAP and END_MAP, but does not understand branches at all. It is
                   2004: #  useful for pre-processing of some kind, and is in fact used by the main
                   2005: #  iterator that way, but that's about it.
                   2006: # One could imagine merging this into the init routine of the main iterator,
                   2007: #  but this might as well be left seperate, since it is possible some other
                   2008: #  use might be found for it. - Jeremy
1.94      bowersj2 2009: 
1.117     bowersj2 2010: # Unlike the main iterator, this DOES return all resources, even blank ones.
                   2011: #  The main iterator needs them to correctly preprocess the map.
                   2012: 
1.94      bowersj2 2013: sub BEGIN_MAP { return 1; }    # begining of a new map
                   2014: sub END_MAP { return 2; }      # end of the map
                   2015: sub FORWARD { return 1; }      # go forward
                   2016: sub BACKWARD { return 2; }
                   2017: 
1.100     bowersj2 2018: # Params: Nav map ref, first resource id/ref, finish resource id/ref,
                   2019: #         filter hash ref (or undef), already seen hash or undef, condition
                   2020: #         (as in main iterator), direction FORWARD or BACKWARD (undef->forward).
1.51      bowersj2 2021: sub new {
                   2022:     # magic invocation to create a class instance
                   2023:     my $proto = shift;
                   2024:     my $class = ref($proto) || $proto;
                   2025:     my $self = {};
                   2026: 
                   2027:     $self->{NAV_MAP} = shift;
                   2028:     return undef unless ($self->{NAV_MAP});
                   2029: 
                   2030:     $self->{FIRST_RESOURCE} = shift || $self->{NAV_MAP}->firstResource();
                   2031:     $self->{FINISH_RESOURCE} = shift || $self->{NAV_MAP}->finishResource();
                   2032: 
                   2033:     # If the given resources are just the ID of the resource, get the
                   2034:     # objects
                   2035:     if (!ref($self->{FIRST_RESOURCE})) { $self->{FIRST_RESOURCE} = 
                   2036:              $self->{NAV_MAP}->getById($self->{FIRST_RESOURCE}); }
                   2037:     if (!ref($self->{FINISH_RESOURCE})) { $self->{FINISH_RESOURCE} = 
                   2038:              $self->{NAV_MAP}->getById($self->{FINISH_RESOURCE}); }
                   2039: 
                   2040:     $self->{FILTER} = shift;
                   2041: 
                   2042:     # A hash, used as a set, of resource already seen
                   2043:     $self->{ALREADY_SEEN} = shift;
1.140     bowersj2 2044:      if (!defined($self->{ALREADY_SEEN})) { $self->{ALREADY_SEEN} = {} };
1.63      bowersj2 2045:     $self->{CONDITION} = shift;
1.89      bowersj2 2046:     $self->{DIRECTION} = shift || FORWARD();
1.51      bowersj2 2047: 
1.100     bowersj2 2048:     # Flag: Have we started yet?
1.51      bowersj2 2049:     $self->{STARTED} = 0;
                   2050: 
                   2051:     # Should we continue calling the recursive iterator, if any?
                   2052:     $self->{RECURSIVE_ITERATOR_FLAG} = 0;
                   2053:     # The recursive iterator, if any
                   2054:     $self->{RECURSIVE_ITERATOR} = undef;
                   2055:     # Are we recursing on a map, or a branch?
                   2056:     $self->{RECURSIVE_MAP} = 1; # we'll manually unset this when recursing on branches
                   2057:     # And the count of how deep it is, so that this iterator can keep track of
                   2058:     # when to pick back up again.
                   2059:     $self->{RECURSIVE_DEPTH} = 0;
                   2060: 
                   2061:     # For keeping track of our branches, we maintain our own stack
1.100     bowersj2 2062:     $self->{STACK} = [];
1.51      bowersj2 2063: 
                   2064:     # Start with the first resource
1.89      bowersj2 2065:     if ($self->{DIRECTION} == FORWARD) {
1.100     bowersj2 2066:         push @{$self->{STACK}}, $self->{FIRST_RESOURCE};
1.89      bowersj2 2067:     } else {
1.100     bowersj2 2068:         push @{$self->{STACK}}, $self->{FINISH_RESOURCE};
1.89      bowersj2 2069:     }
1.51      bowersj2 2070: 
                   2071:     bless($self);
                   2072:     return $self;
                   2073: }
                   2074: 
                   2075: sub next {
                   2076:     my $self = shift;
                   2077:     
                   2078:     # Are we using a recursive iterator? If so, pull from that and
                   2079:     # watch the depth; we want to resume our level at the correct time.
1.98      bowersj2 2080:     if ($self->{RECURSIVE_ITERATOR_FLAG}) {
1.51      bowersj2 2081:         # grab the next from the recursive iterator
                   2082:         my $next = $self->{RECURSIVE_ITERATOR}->next();
                   2083:         
                   2084:         # is it a begin or end map? Update depth if so
                   2085:         if ($next == BEGIN_MAP() ) { $self->{RECURSIVE_DEPTH}++; }
                   2086:         if ($next == END_MAP() ) { $self->{RECURSIVE_DEPTH}--; }
                   2087: 
                   2088:         # Are we back at depth 0? If so, stop recursing.
                   2089:         if ($self->{RECURSIVE_DEPTH} == 0) {
                   2090:             $self->{RECURSIVE_ITERATOR_FLAG} = 0;
                   2091:         }
                   2092:         
                   2093:         return $next;
                   2094:     }
                   2095: 
                   2096:     # Is there a current resource to grab? If not, then return
1.100     bowersj2 2097:     # END_MAP, which will end the iterator.
                   2098:     if (scalar(@{$self->{STACK}}) == 0) {
                   2099:         return $self->END_MAP();
1.51      bowersj2 2100:     }
                   2101: 
                   2102:     # Have we not yet begun? If not, return BEGIN_MAP and 
                   2103:     # remember that we've started.
                   2104:     if ( !$self->{STARTED} ) {
                   2105:         $self->{STARTED} = 1;
                   2106:         return $self->BEGIN_MAP;
                   2107:     }
                   2108: 
                   2109:     # Get the next resource in the branch
1.100     bowersj2 2110:     $self->{HERE} = pop @{$self->{STACK}};
1.52      bowersj2 2111: 
1.100     bowersj2 2112:     # remember that we've seen this, so we don't return it again later
1.51      bowersj2 2113:     $self->{ALREADY_SEEN}->{$self->{HERE}->{ID}} = 1;
                   2114:     
                   2115:     # Get the next possible resources
1.90      bowersj2 2116:     my $nextUnfiltered;
1.89      bowersj2 2117:     if ($self->{DIRECTION} == FORWARD()) {
1.90      bowersj2 2118:         $nextUnfiltered = $self->{HERE}->getNext();
1.89      bowersj2 2119:     } else {
1.90      bowersj2 2120:         $nextUnfiltered = $self->{HERE}->getPrevious();
1.89      bowersj2 2121:     }
1.51      bowersj2 2122:     my $next = [];
                   2123: 
                   2124:     # filter the next possibilities to remove things we've 
1.100     bowersj2 2125:     # already seen.
1.51      bowersj2 2126:     foreach (@$nextUnfiltered) {
1.52      bowersj2 2127:         if (!defined($self->{ALREADY_SEEN}->{$_->{ID}})) {
                   2128:             push @$next, $_;
                   2129:         }
1.51      bowersj2 2130:     }
                   2131: 
                   2132:     while (@$next) {
1.100     bowersj2 2133:         # copy the next possibilities over to the stack
                   2134:         push @{$self->{STACK}}, shift @$next;
1.51      bowersj2 2135:     }
                   2136: 
                   2137:     # If this is a map and we want to recurse down it... (not filtered out)
1.70      bowersj2 2138:     if ($self->{HERE}->is_map() && 
1.63      bowersj2 2139:          (defined($self->{FILTER}->{$self->{HERE}->map_pc()}) xor $self->{CONDITION})) { 
1.51      bowersj2 2140:         $self->{RECURSIVE_ITERATOR_FLAG} = 1;
                   2141:         my $firstResource = $self->{HERE}->map_start();
                   2142:         my $finishResource = $self->{HERE}->map_finish();
                   2143: 
                   2144:         $self->{RECURSIVE_ITERATOR} =
1.94      bowersj2 2145:           Apache::lonnavmaps::DFSiterator->new ($self->{NAV_MAP}, $firstResource, 
1.63      bowersj2 2146:                      $finishResource, $self->{FILTER}, $self->{ALREADY_SEEN},
1.91      bowersj2 2147:                                              $self->{CONDITION}, $self->{DIRECTION});
1.51      bowersj2 2148:     }
                   2149: 
                   2150:     return $self->{HERE};
                   2151: }
                   2152: 
1.1       www      2153: 1;
1.2       www      2154: 
1.51      bowersj2 2155: package Apache::lonnavmaps::resource;
                   2156: 
                   2157: use Apache::lonnet;
                   2158: 
                   2159: =pod
                   2160: 
                   2161: =head1 Object: resource
                   2162: 
                   2163: A resource object encapsulates a resource in a resource map, allowing easy manipulation of the resource, querying the properties of the resource (including user properties), and represents a reference that can be used as the canonical representation of the resource by lonnavmap clients like renderers.
                   2164: 
                   2165: A resource only makes sense in the context of a navmap, as some of the data is stored in the navmap object.
                   2166: 
1.140     bowersj2 2167: You will probably never need to instantiate this object directly. Use Apache::lonnavmaps::navmap, and use the "start" method to obtain the starting resource.
1.51      bowersj2 2168: 
                   2169: =head2 Public Members
                   2170: 
                   2171: resource objects have a hash called DATA ($resourceRef->{DATA}) that you can store whatever you want in. This allows you to easily do two-pass algorithms without worrying about managing your own resource->data hash.
                   2172: 
                   2173: =head2 Methods
                   2174: 
                   2175: =over 4
                   2176: 
1.70      bowersj2 2177: =item * B<new>($navmapRef, $idString): The first arg is a reference to the parent navmap object. The second is the idString of the resource itself. Very rarely, if ever, called directly. Use the nav map->getByID() method.
                   2178: 
                   2179: =back
1.51      bowersj2 2180: 
                   2181: =cut
                   2182: 
                   2183: sub new {
                   2184:     # magic invocation to create a class instance
                   2185:     my $proto = shift;
                   2186:     my $class = ref($proto) || $proto;
                   2187:     my $self = {};
                   2188: 
                   2189:     $self->{NAV_MAP} = shift;
                   2190:     $self->{ID} = shift;
                   2191: 
                   2192:     # Store this new resource in the parent nav map's cache.
                   2193:     $self->{NAV_MAP}->{RESOURCE_CACHE}->{$self->{ID}} = $self;
1.66      bowersj2 2194:     $self->{RESOURCE_ERROR} = 0;
1.51      bowersj2 2195: 
                   2196:     # A hash that can be used by two-pass algorithms to store data
                   2197:     # about this resource in. Not used by the resource object
                   2198:     # directly.
                   2199:     $self->{DATA} = {};
                   2200:    
                   2201:     bless($self);
                   2202:     
                   2203:     return $self;
                   2204: }
                   2205: 
1.70      bowersj2 2206: # private function: simplify the NAV_HASH lookups we keep doing
                   2207: # pass the name, and to automatically append my ID, pass a true val on the
                   2208: # second param
                   2209: sub navHash {
                   2210:     my $self = shift;
                   2211:     my $param = shift;
                   2212:     my $id = shift;
1.115     bowersj2 2213:     return $self->{NAV_MAP}->navhash($param . ($id?$self->{ID}:""));
1.70      bowersj2 2214: }
                   2215: 
1.51      bowersj2 2216: =pod
                   2217: 
1.70      bowersj2 2218: B<Metadata Retreival>
                   2219: 
1.101     bowersj2 2220: These are methods that help you retrieve metadata about the resource: Method names are based on the fields in the compiled course representation.
1.70      bowersj2 2221: 
                   2222: =over 4
                   2223: 
1.106     bowersj2 2224: =item * B<compTitle>: Returns a "composite title", that is equal to $res->title() if the resource has a title, and is otherwise the last part of the URL (e.g., "problem.problem").
                   2225: 
1.70      bowersj2 2226: =item * B<ext>: Returns true if the resource is external.
                   2227: 
                   2228: =item * B<goesto>: Returns the "goesto" value from the compiled nav map. (It is likely you want to use B<getNext> instead.)
                   2229: 
                   2230: =item * B<kind>: Returns the kind of the resource from the compiled nav map.
                   2231: 
1.101     bowersj2 2232: =item * B<randomout>: Returns true if this resource was chosen to NOT be shown to the user by the random map selection feature. In other words, this is usually false.
1.51      bowersj2 2233: 
1.70      bowersj2 2234: =item * B<randompick>: Returns true for a map if the randompick feature is being used on the map. (?)
                   2235: 
                   2236: =item * B<src>: Returns the source for the resource.
                   2237: 
                   2238: =item * B<symb>: Returns the symb for the resource.
                   2239: 
                   2240: =item * B<title>: Returns the title of the resource.
                   2241: 
                   2242: =item * B<to>: Returns the "to" value from the compiled nav map. (It is likely you want to use B<getNext> instead.)
1.51      bowersj2 2243: 
                   2244: =back
                   2245: 
                   2246: =cut
                   2247: 
                   2248: # These info functions can be used directly, as they don't return
                   2249: # resource information.
1.85      bowersj2 2250: sub comesfrom { my $self=shift; return $self->navHash("comesfrom_", 1); }
1.70      bowersj2 2251: sub ext { my $self=shift; return $self->navHash("ext_", 1) eq 'true:'; }
1.85      bowersj2 2252: sub from { my $self=shift; return $self->navHash("from_", 1); }
1.51      bowersj2 2253: sub goesto { my $self=shift; return $self->navHash("goesto_", 1); }
                   2254: sub kind { my $self=shift; return $self->navHash("kind_", 1); }
1.68      bowersj2 2255: sub randomout { my $self=shift; return $self->navHash("randomout_", 1); }
                   2256: sub randompick { 
                   2257:     my $self = shift;
                   2258:     return $self->{NAV_MAP}->{PARM_HASH}->{$self->symb .
                   2259:                                                '.0.parameter_randompick'};
                   2260: }
1.51      bowersj2 2261: sub src { 
                   2262:     my $self=shift;
                   2263:     return $self->navHash("src_", 1);
                   2264: }
                   2265: sub symb {
                   2266:     my $self=shift;
                   2267:     (my $first, my $second) = $self->{ID} =~ /(\d+).(\d+)/;
                   2268:     my $symbSrc = &Apache::lonnet::declutter($self->src());
                   2269:     return &Apache::lonnet::declutter(
                   2270:          $self->navHash('map_id_'.$first)) 
                   2271:         . '___' . $second . '___' . $symbSrc;
                   2272: }
1.70      bowersj2 2273: sub title { my $self=shift; return $self->navHash("title_", 1); }
                   2274: sub to { my $self=shift; return $self->navHash("to_", 1); }
1.106     bowersj2 2275: sub compTitle {
                   2276:     my $self = shift;
                   2277:     my $title = $self->title();
                   2278:     if (!$title) {
                   2279:         $title = $self->src();
                   2280:         $title = substr($title, rindex($title, '/') + 1);
                   2281:     }
                   2282:     return $title;
                   2283: }
1.70      bowersj2 2284: =pod
                   2285: 
                   2286: B<Predicate Testing the Resource>
                   2287: 
                   2288: These methods are shortcuts to deciding if a given resource has a given property.
                   2289: 
                   2290: =over 4
                   2291: 
                   2292: =item * B<is_map>: Returns true if the resource is a map type.
                   2293: 
                   2294: =item * B<is_problem>: Returns true if the resource is a problem type, false otherwise. (Looks at the extension on the src field; might need more to work correctly.)
                   2295: 
                   2296: =item * B<is_page>: Returns true if the resource is a page.
                   2297: 
1.101     bowersj2 2298: =item * B<is_sequence>: Returns true if the resource is a sequence.
1.70      bowersj2 2299: 
                   2300: =back
                   2301: 
                   2302: =cut
                   2303: 
                   2304: 
                   2305: sub is_html {
1.51      bowersj2 2306:     my $self=shift;
                   2307:     my $src = $self->src();
1.70      bowersj2 2308:     return ($src =~ /html$/);
1.51      bowersj2 2309: }
1.70      bowersj2 2310: sub is_map { my $self=shift; return defined($self->navHash("is_map_", 1)); }
                   2311: sub is_page {
1.51      bowersj2 2312:     my $self=shift;
                   2313:     my $src = $self->src();
1.70      bowersj2 2314:     return ($src =~ /page$/);
1.51      bowersj2 2315: }
1.70      bowersj2 2316: sub is_problem {
1.51      bowersj2 2317:     my $self=shift;
                   2318:     my $src = $self->src();
1.70      bowersj2 2319:     return ($src =~ /problem$/);
1.51      bowersj2 2320: }
1.70      bowersj2 2321: sub is_sequence {
1.51      bowersj2 2322:     my $self=shift;
                   2323:     my $src = $self->src();
1.70      bowersj2 2324:     return ($src =~ /sequence$/);
1.51      bowersj2 2325: }
                   2326: 
1.101     bowersj2 2327: # Private method: Shells out to the parmval in the nav map, handler parts.
1.51      bowersj2 2328: sub parmval {
                   2329:     my $self = shift;
                   2330:     my $what = shift;
                   2331:     my $part = shift || "0";
                   2332:     return $self->{NAV_MAP}->parmval($part.'.'.$what, $self->symb());
                   2333: }
                   2334: 
1.70      bowersj2 2335: =pod
                   2336: 
                   2337: B<Map Methods>
                   2338: 
                   2339: These methods are useful for getting information about the map properties of the resource, if the resource is a map (B<is_map>).
                   2340: 
                   2341: =over 4
                   2342: 
                   2343: =item * B<map_finish>: Returns a reference to a resource object corresponding to the finish resource of the map.
                   2344: 
                   2345: =item * B<map_pc>: Returns the pc value of the map, which is the first number that appears in the resource ID of the resources in the map, and is the number that appears around the middle of the symbs of the resources in that map.
                   2346: 
                   2347: =item * B<map_start>: Returns a reference to a resource object corresponding to the start resource of the map.
                   2348: 
                   2349: =item * B<map_type>: Returns a string with the type of the map in it.
                   2350: 
                   2351: =back
1.51      bowersj2 2352: 
1.70      bowersj2 2353: =cut
1.51      bowersj2 2354: 
                   2355: sub map_finish {
                   2356:     my $self = shift;
                   2357:     my $src = $self->src();
1.144   ! bowersj2 2358:     $src = Apache::lonnet::clutter($src);
1.51      bowersj2 2359:     my $res = $self->navHash("map_finish_$src", 0);
                   2360:     $res = $self->{NAV_MAP}->getById($res);
                   2361:     return $res;
                   2362: }
1.70      bowersj2 2363: sub map_pc {
                   2364:     my $self = shift;
                   2365:     my $src = $self->src();
                   2366:     return $self->navHash("map_pc_$src", 0);
                   2367: }
1.51      bowersj2 2368: sub map_start {
                   2369:     my $self = shift;
                   2370:     my $src = $self->src();
1.144   ! bowersj2 2371:     $src = Apache::lonnet::clutter($src);
1.51      bowersj2 2372:     my $res = $self->navHash("map_start_$src", 0);
                   2373:     $res = $self->{NAV_MAP}->getById($res);
                   2374:     return $res;
                   2375: }
                   2376: sub map_type {
                   2377:     my $self = shift;
                   2378:     my $pc = $self->map_pc();
                   2379:     return $self->navHash("map_type_$pc", 0);
                   2380: }
                   2381: 
                   2382: 
                   2383: 
                   2384: #####
                   2385: # Property queries
                   2386: #####
                   2387: 
                   2388: # These functions will be responsible for returning the CORRECT
                   2389: # VALUE for the parameter, no matter what. So while they may look
                   2390: # like direct calls to parmval, they can be more then that.
                   2391: # So, for instance, the duedate function should use the "duedatetype"
                   2392: # information, rather then the resource object user.
                   2393: 
                   2394: =pod
                   2395: 
                   2396: =head2 Resource Parameters
                   2397: 
1.70      bowersj2 2398: In order to use the resource parameters correctly, the nav map must have been instantiated with genCourseAndUserOptions set to true, so the courseopt and useropt is read correctly. Then, you can call these functions to get the relevant parameters for the resource. Each function defaults to part "0", but can be directed to another part by passing the part as the parameter.
1.51      bowersj2 2399: 
                   2400: These methods are responsible for getting the parameter correct, not merely reflecting the contents of the GDBM hashes. As we move towards dates relative to other dates, these methods should be updated to reflect that. (Then, anybody using these methods won't have to update their code.)
                   2401: 
                   2402: =over 4
                   2403: 
                   2404: =item * B<acc>: Get the Client IP/Name Access Control information.
                   2405: 
                   2406: =item * B<answerdate>: Get the answer-reveal date for the problem.
                   2407: 
                   2408: =item * B<duedate>: Get the due date for the problem.
                   2409: 
                   2410: =item * B<tries>: Get the number of tries the student has used on the problem.
                   2411: 
                   2412: =item * B<maxtries>: Get the number of max tries allowed.
                   2413: 
                   2414: =item * B<opendate>: Get the open date for the problem.
                   2415: 
                   2416: =item * B<sig>: Get the significant figures setting.
                   2417: 
                   2418: =item * B<tol>: Get the tolerance for the problem.
                   2419: 
1.70      bowersj2 2420: =item * B<tries>: Get the number of tries the user has already used on the problem.
                   2421: 
1.51      bowersj2 2422: =item * B<type>: Get the question type for the problem.
                   2423: 
                   2424: =item * B<weight>: Get the weight for the problem.
                   2425: 
                   2426: =back
                   2427: 
                   2428: =cut
                   2429: 
                   2430: sub acc {
                   2431:     (my $self, my $part) = @_;
                   2432:     return $self->parmval("acc", $part);
                   2433: }
                   2434: sub answerdate {
                   2435:     (my $self, my $part) = @_;
                   2436:     # Handle intervals
                   2437:     if ($self->parmval("answerdate.type", $part) eq 'date_interval') {
                   2438:         return $self->duedate($part) + 
                   2439:             $self->parmval("answerdate", $part);
                   2440:     }
                   2441:     return $self->parmval("answerdate", $part);
1.106     bowersj2 2442: }
1.108     bowersj2 2443: sub awarded { my $self = shift; return $self->queryRestoreHash('awarded', shift); }
1.51      bowersj2 2444: sub duedate {
                   2445:     (my $self, my $part) = @_;
                   2446:     return $self->parmval("duedate", $part);
                   2447: }
                   2448: sub maxtries {
                   2449:     (my $self, my $part) = @_;
                   2450:     return $self->parmval("maxtries", $part);
                   2451: }
                   2452: sub opendate {
                   2453:     (my $self, my $part) = @_;
                   2454:     if ($self->parmval("opendate.type", $part) eq 'date_interval') {
                   2455:         return $self->duedate($part) -
                   2456:             $self->parmval("opendate", $part);
                   2457:     }
                   2458:     return $self->parmval("opendate");
                   2459: }
                   2460: sub sig {
                   2461:     (my $self, my $part) = @_;
                   2462:     return $self->parmval("sig", $part);
                   2463: }
                   2464: sub tol {
                   2465:     (my $self, my $part) = @_;
                   2466:     return $self->parmval("tol", $part);
                   2467: }
1.108     bowersj2 2468: sub tries { 
                   2469:     my $self = shift; 
                   2470:     my $tries = $self->queryRestoreHash('tries', shift);
                   2471:     if (!defined($tries)) { return '0';}
1.51      bowersj2 2472:     return $tries;
                   2473: }
1.70      bowersj2 2474: sub type {
                   2475:     (my $self, my $part) = @_;
                   2476:     return $self->parmval("type", $part);
                   2477: }
1.109     bowersj2 2478: sub weight { 
                   2479:     my $self = shift; my $part = shift;
1.70      bowersj2 2480:     return $self->parmval("weight", $part);
                   2481: }
1.51      bowersj2 2482: 
                   2483: # Multiple things need this
                   2484: sub getReturnHash {
                   2485:     my $self = shift;
                   2486:     
                   2487:     if (!defined($self->{RETURN_HASH})) {
1.84      bowersj2 2488:         my %tmpHash  = &Apache::lonnet::restore($self->symb());
1.51      bowersj2 2489:         $self->{RETURN_HASH} = \%tmpHash;
                   2490:     }
                   2491: }       
                   2492: 
                   2493: ######
                   2494: # Status queries
                   2495: ######
                   2496: 
                   2497: # These methods query the status of problems.
                   2498: 
                   2499: # If we need to count parts, this function determines the number of
                   2500: # parts from the metadata. When called, it returns a reference to a list
                   2501: # of strings corresponding to the parts. (Thus, using it in a scalar context
                   2502: # tells you how many parts you have in the problem:
                   2503: # $partcount = scalar($resource->countParts());
                   2504: # Don't use $self->{PARTS} directly because you don't know if it's been
                   2505: # computed yet.
                   2506: 
                   2507: =pod
                   2508: 
                   2509: =head2 Resource misc
                   2510: 
                   2511: Misc. functions for the resource.
                   2512: 
                   2513: =over 4
                   2514: 
1.59      bowersj2 2515: =item * B<hasDiscussion>: Returns a false value if there has been discussion since the user last logged in, true if there has. Always returns false if the discussion data was not extracted when the nav map was constructed.
                   2516: 
                   2517: =item * B<getFeedback>: Gets the feedback for the resource and returns the raw feedback string for the resource, or the null string if there is no feedback or the email data was not extracted when the nav map was constructed. Usually used like this:
                   2518: 
                   2519:  for (split(/\,/, $res->getFeedback())) {
                   2520:     my $link = &Apache::lonnet::escape($_);
                   2521:     ...
                   2522: 
                   2523: and use the link as appropriate.
                   2524: 
                   2525: =cut
                   2526: 
                   2527: sub hasDiscussion {
                   2528:     my $self = shift;
                   2529:     return $self->{NAV_MAP}->hasDiscussion($self->symb());
                   2530: }
                   2531: 
                   2532: sub getFeedback {
                   2533:     my $self = shift;
1.124     bowersj2 2534:     my $source = $self->src();
1.125     bowersj2 2535:     if ($source =~ /^\/res\//) { $source = substr $source, 5; }
1.124     bowersj2 2536:     return $self->{NAV_MAP}->getFeedback($source);
                   2537: }
                   2538: 
                   2539: sub getErrors {
                   2540:     my $self = shift;
                   2541:     my $source = $self->src();
                   2542:     if ($source =~ /^\/res\//) { $source = substr $source, 5; }
                   2543:     return $self->{NAV_MAP}->getErrors($source);
1.59      bowersj2 2544: }
                   2545: 
                   2546: =pod
                   2547: 
1.142     bowersj2 2548: =item * B<parts>(): Returns a list reference containing sorted strings corresponding to each part of the problem. To count the number of parts, use the list in a scalar context, and subtract one if greater than two. (One part problems have a part 0. Multi-parts have a part 0, plus a part for each part. Filtering part 0 if you want it is up to you.)
1.51      bowersj2 2549: 
1.70      bowersj2 2550: =item * B<countParts>(): Returns the number of parts of the problem a student can answer. Thus, for single part problems, returns 1. For multipart, it returns the number of parts in the problem, not including psuedo-part 0. Thus, B<parts> may return an array with fewer parts in it then countParts might lead you to believe.
1.51      bowersj2 2551: 
                   2552: =back
                   2553: 
                   2554: =cut
                   2555: 
                   2556: sub parts {
                   2557:     my $self = shift;
                   2558: 
1.67      bowersj2 2559:     if ($self->ext) { return ['0']; }
                   2560: 
1.51      bowersj2 2561:     $self->extractParts();
                   2562:     return $self->{PARTS};
                   2563: }
                   2564: 
                   2565: sub countParts {
                   2566:     my $self = shift;
                   2567:     
                   2568:     my $parts = $self->parts();
1.66      bowersj2 2569: 
                   2570:     if ($self->{RESOURCE_ERROR}) {
                   2571:         return 0;
                   2572:     }
                   2573: 
                   2574:     if (scalar(@{$parts}) < 2) { return 1;}
1.51      bowersj2 2575: 
                   2576:     return scalar(@{$parts}) - 1;
                   2577: }
                   2578: 
                   2579: # Private function: Extracts the parts information and saves it
                   2580: sub extractParts { 
                   2581:     my $self = shift;
                   2582:     
                   2583:     return if ($self->{PARTS});
1.67      bowersj2 2584:     return if ($self->ext);
1.51      bowersj2 2585: 
                   2586:     $self->{PARTS} = [];
                   2587: 
1.82      bowersj2 2588:     # Retrieve part count, if this is a problem
                   2589:     if ($self->is_problem()) {
                   2590:         my $metadata = &Apache::lonnet::metadata($self->src(), 'allpossiblekeys');
                   2591:         if (!$metadata) {
                   2592:             $self->{RESOURCE_ERROR} = 1;
                   2593:             $self->{PARTS} = [];
                   2594:             return;
                   2595:         }
                   2596:         
                   2597:         foreach (split(/\,/,$metadata)) {
                   2598:             if ($_ =~ /^parameter\_(.*)\_opendate$/) {
                   2599:                 push @{$self->{PARTS}}, $1;
                   2600:             }
1.51      bowersj2 2601:         }
1.82      bowersj2 2602:         
                   2603:         
                   2604:         # Is this possible to do in one line? - Jeremy
                   2605:         my @sortedParts = sort @{$self->{PARTS}};
                   2606:         $self->{PARTS} = \@sortedParts;
1.51      bowersj2 2607:     }
                   2608: 
                   2609:     return;
                   2610: }
                   2611: 
                   2612: =pod
                   2613: 
                   2614: =head2 Resource Status
                   2615: 
1.101     bowersj2 2616: Problem resources have status information, reflecting their various dates and completion statuses. 
1.51      bowersj2 2617: 
                   2618: There are two aspects to the status: the date-related information and the completion information.
                   2619: 
                   2620: Idiomatic usage of these two methods would probably look something like
                   2621: 
                   2622:  foreach ($resource->parts()) {
                   2623:     my $dateStatus = $resource->getDateStatus($_);
                   2624:     my $completionStatus = $resource->getCompletionStatus($_);
                   2625: 
1.70      bowersj2 2626:     or
                   2627: 
                   2628:     my $status = $resource->status($_);
                   2629: 
1.51      bowersj2 2630:     ... use it here ...
                   2631:  }
                   2632: 
1.101     bowersj2 2633: Which you use depends on exactly what you are looking for. The status() function has been optimized for the nav maps display and may not precisely match what you need elsewhere.
                   2634: 
                   2635: The symbolic constants shown below can be accessed through the resource object: $res->OPEN.
                   2636: 
1.51      bowersj2 2637: =over 4
                   2638: 
1.70      bowersj2 2639: =item * B<getDateStatus>($part): ($part defaults to 0). A convenience function that returns a symbolic constant telling you about the date status of the part. The possible return values are:
1.51      bowersj2 2640: 
                   2641: =back
                   2642: 
                   2643: B<Date Codes>
                   2644: 
                   2645: =over 4
                   2646: 
                   2647: =item * B<OPEN_LATER>: The problem will be opened later.
                   2648: 
                   2649: =item * B<OPEN>: Open and not yet due.
                   2650: 
1.59      bowersj2 2651: 
1.54      bowersj2 2652: =item * B<PAST_DUE_ANSWER_LATER>: The due date has passed, but the answer date has not yet arrived.
                   2653: 
                   2654: =item * B<PAST_DUE_NO_ANSWER>: The due date has passed and there is no answer opening date set.
1.51      bowersj2 2655: 
                   2656: =item * B<ANSWER_OPEN>: The answer date is here.
                   2657: 
                   2658: =item * B<NETWORK_FAILURE>: The information is unknown due to network failure.
                   2659: 
                   2660: =back
                   2661: 
                   2662: =cut
                   2663: 
                   2664: # Apparently the compiler optimizes these into constants automatically
1.54      bowersj2 2665: sub OPEN_LATER             { return 0; }
                   2666: sub OPEN                   { return 1; }
                   2667: sub PAST_DUE_NO_ANSWER     { return 2; }
                   2668: sub PAST_DUE_ANSWER_LATER  { return 3; }
                   2669: sub ANSWER_OPEN            { return 4; }
                   2670: sub NOTHING_SET            { return 5; } 
                   2671: sub NETWORK_FAILURE        { return 100; }
                   2672: 
                   2673: # getDateStatus gets the date status for a given problem part. 
                   2674: # Because answer date, due date, and open date are fully independent
                   2675: # (i.e., it is perfectly possible to *only* have an answer date), 
                   2676: # we have to completely cover the 3x3 maxtrix of (answer, due, open) x
                   2677: # (past, future, none given). This function handles this with a decision
                   2678: # tree. Read the comments to follow the decision tree.
1.51      bowersj2 2679: 
                   2680: sub getDateStatus {
                   2681:     my $self = shift;
                   2682:     my $part = shift;
                   2683:     $part = "0" if (!defined($part));
1.54      bowersj2 2684: 
                   2685:     # Always return network failure if there was one.
1.51      bowersj2 2686:     return $self->NETWORK_FAILURE if ($self->{NAV_MAP}->{NETWORK_FAILURE});
                   2687: 
                   2688:     my $now = time();
                   2689: 
1.53      bowersj2 2690:     my $open = $self->opendate($part);
                   2691:     my $due = $self->duedate($part);
                   2692:     my $answer = $self->answerdate($part);
                   2693: 
                   2694:     if (!$open && !$due && !$answer) {
                   2695:         # no data on the problem at all
                   2696:         # should this be the same as "open later"? think multipart.
                   2697:         return $self->NOTHING_SET;
                   2698:     }
1.59      bowersj2 2699:     if (!$open || $now < $open) {return $self->OPEN_LATER}
                   2700:     if (!$due || $now < $due) {return $self->OPEN}
                   2701:     if ($answer && $now < $answer) {return $self->PAST_DUE_ANSWER_LATER}
                   2702:     if ($answer) { return $self->ANSWER_OPEN; }
1.54      bowersj2 2703:     return PAST_DUE_NO_ANSWER;
1.51      bowersj2 2704: }
                   2705: 
                   2706: =pod
                   2707: 
                   2708: B<>
                   2709: 
                   2710: =over 4
                   2711: 
                   2712: =item * B<getCompletionStatus>($part): ($part defaults to 0.) A convenience function that returns a symbolic constant telling you about the completion status of the part, with the following possible results:
                   2713: 
                   2714: =back 
                   2715: 
                   2716: B<Completion Codes>
                   2717: 
                   2718: =over 4
                   2719: 
                   2720: =item * B<NOT_ATTEMPTED>: Has not been attempted at all.
                   2721: 
                   2722: =item * B<INCORRECT>: Attempted, but wrong by student.
                   2723: 
                   2724: =item * B<INCORRECT_BY_OVERRIDE>: Attempted, but wrong by instructor override.
                   2725: 
                   2726: =item * B<CORRECT>: Correct or correct by instructor.
                   2727: 
                   2728: =item * B<CORRECT_BY_OVERRIDE>: Correct by instructor override.
                   2729: 
                   2730: =item * B<EXCUSED>: Excused. Not yet implemented.
                   2731: 
                   2732: =item * B<NETWORK_FAILURE>: Information not available due to network failure.
                   2733: 
1.69      bowersj2 2734: =item * B<ATTEMPTED>: Attempted, and not yet graded.
                   2735: 
1.51      bowersj2 2736: =back
                   2737: 
                   2738: =cut
                   2739: 
1.53      bowersj2 2740: sub NOT_ATTEMPTED         { return 10; }
                   2741: sub INCORRECT             { return 11; }
                   2742: sub INCORRECT_BY_OVERRIDE { return 12; }
                   2743: sub CORRECT               { return 13; }
                   2744: sub CORRECT_BY_OVERRIDE   { return 14; }
                   2745: sub EXCUSED               { return 15; }
1.69      bowersj2 2746: sub ATTEMPTED             { return 16; }
1.51      bowersj2 2747: 
                   2748: sub getCompletionStatus {
                   2749:     my $self = shift;
                   2750:     return $self->NETWORK_FAILURE if ($self->{NAV_MAP}->{NETWORK_FAILURE});
                   2751: 
1.108     bowersj2 2752:     my $status = $self->queryRestoreHash('solved', shift);
1.51      bowersj2 2753: 
                   2754:     # Left as seperate if statements in case we ever do more with this
                   2755:     if ($status eq 'correct_by_student') {return $self->CORRECT;}
                   2756:     if ($status eq 'correct_by_override') {return $self->CORRECT_BY_OVERRIDE; }
                   2757:     if ($status eq 'incorrect_attempted') {return $self->INCORRECT; }
                   2758:     if ($status eq 'incorrect_by_override') {return $self->INCORRECT_BY_OVERRIDE; }
                   2759:     if ($status eq 'excused') {return $self->EXCUSED; }
1.69      bowersj2 2760:     if ($status eq 'ungraded_attempted') {return $self->ATTEMPTED; }
1.51      bowersj2 2761:     return $self->NOT_ATTEMPTED;
1.108     bowersj2 2762: }
                   2763: 
                   2764: sub queryRestoreHash {
                   2765:     my $self = shift;
                   2766:     my $hashentry = shift;
                   2767:     my $part = shift;
                   2768:     $part = "0" if (!defined($part));
                   2769:     return $self->NETWORK_FAILURE if ($self->{NAV_MAP}->{NETWORK_FAILURE});
                   2770: 
                   2771:     $self->getReturnHash();
                   2772: 
                   2773:     return $self->{RETURN_HASH}->{'resource.'.$part.'.'.$hashentry};
1.51      bowersj2 2774: }
                   2775: 
                   2776: =pod
                   2777: 
                   2778: B<Composite Status>
                   2779: 
1.101     bowersj2 2780: Along with directly returning the date or completion status, the resource object includes a convenience function B<status>() that will combine the two status tidbits into one composite status that can represent the status of the resource as a whole. The precise logic is documented in the comments of the status method. The following results may be returned, all available as methods on the resource object ($res->NETWORK_FAILURE):
1.51      bowersj2 2781: 
                   2782: =over 4
                   2783: 
1.70      bowersj2 2784: =item * B<NETWORK_FAILURE>: The network has failed and the information is not available.
1.51      bowersj2 2785: 
1.70      bowersj2 2786: =item * B<NOTHING_SET>: No dates have been set for this problem (part) at all. (Because only certain parts of a multi-part problem may be assigned, this can not be collapsed into "open later", as we don't know a given part will EVER be opened. For single part, this is the same as "OPEN_LATER".)
1.53      bowersj2 2787: 
1.70      bowersj2 2788: =item * B<CORRECT>: For any reason at all, the part is considered correct.
1.51      bowersj2 2789: 
1.70      bowersj2 2790: =item * B<EXCUSED>: For any reason at all, the problem is excused.
1.51      bowersj2 2791: 
1.70      bowersj2 2792: =item * B<PAST_DUE_NO_ANSWER>: The problem is past due, not considered correct, and no answer date is set.
1.54      bowersj2 2793: 
1.70      bowersj2 2794: =item * B<PAST_DUE_ANSWER_LATER>: The problem is past due, not considered correct, and an answer date in the future is set.
1.51      bowersj2 2795: 
1.70      bowersj2 2796: =item * B<ANSWER_OPEN>: The problem is past due, not correct, and the answer is now available.
1.51      bowersj2 2797: 
1.70      bowersj2 2798: =item * B<OPEN_LATER>: The problem is not yet open.
1.51      bowersj2 2799: 
1.70      bowersj2 2800: =item * B<TRIES_LEFT>: The problem is open, has been tried, is not correct, but there are tries left.
1.51      bowersj2 2801: 
1.70      bowersj2 2802: =item * B<INCORRECT>: The problem is open, and all tries have been used without getting the correct answer.
1.51      bowersj2 2803: 
1.70      bowersj2 2804: =item * B<OPEN>: The item is open and not yet tried.
1.51      bowersj2 2805: 
1.70      bowersj2 2806: =item * B<ATTEMPTED>: The problem has been attempted.
1.69      bowersj2 2807: 
1.51      bowersj2 2808: =back
                   2809: 
                   2810: =cut
                   2811: 
                   2812: sub TRIES_LEFT { return 10; }
                   2813: 
                   2814: sub status {
                   2815:     my $self = shift;
                   2816:     my $part = shift;
                   2817:     if (!defined($part)) { $part = "0"; }
                   2818:     my $completionStatus = $self->getCompletionStatus($part);
                   2819:     my $dateStatus = $self->getDateStatus($part);
                   2820: 
                   2821:     # What we have is a two-dimensional matrix with 4 entries on one
                   2822:     # dimension and 5 entries on the other, which we want to colorize,
1.54      bowersj2 2823:     # plus network failure and "no date data at all".
1.51      bowersj2 2824: 
1.53      bowersj2 2825:     if ($completionStatus == NETWORK_FAILURE) { return NETWORK_FAILURE; }
1.51      bowersj2 2826: 
                   2827:     # There are a few whole rows we can dispose of:
1.53      bowersj2 2828:     if ($completionStatus == CORRECT ||
                   2829:         $completionStatus == CORRECT_BY_OVERRIDE ) {
1.69      bowersj2 2830:         return CORRECT; 
                   2831:     }
                   2832: 
                   2833:     if ($completionStatus == ATTEMPTED) {
                   2834:         return ATTEMPTED;
1.53      bowersj2 2835:     }
                   2836: 
                   2837:     # If it's EXCUSED, then return that no matter what
                   2838:     if ($completionStatus == EXCUSED) {
                   2839:         return EXCUSED; 
1.51      bowersj2 2840:     }
                   2841: 
1.53      bowersj2 2842:     if ($dateStatus == NOTHING_SET) {
                   2843:         return NOTHING_SET;
1.51      bowersj2 2844:     }
                   2845: 
1.69      bowersj2 2846:     # Now we're down to a 4 (incorrect, incorrect_override, not_attempted)
                   2847:     # by 4 matrix (date statuses).
1.51      bowersj2 2848: 
1.54      bowersj2 2849:     if ($dateStatus == PAST_DUE_ANSWER_LATER ||
1.59      bowersj2 2850:         $dateStatus == PAST_DUE_NO_ANSWER ) {
1.54      bowersj2 2851:         return $dateStatus; 
1.51      bowersj2 2852:     }
                   2853: 
1.53      bowersj2 2854:     if ($dateStatus == ANSWER_OPEN) {
                   2855:         return ANSWER_OPEN;
1.51      bowersj2 2856:     }
                   2857: 
                   2858:     # Now: (incorrect, incorrect_override, not_attempted) x 
                   2859:     # (open_later), (open)
                   2860:     
1.53      bowersj2 2861:     if ($dateStatus == OPEN_LATER) {
                   2862:         return OPEN_LATER;
1.51      bowersj2 2863:     }
                   2864: 
                   2865:     # If it's WRONG...
1.53      bowersj2 2866:     if ($completionStatus == INCORRECT || $completionStatus == INCORRECT_BY_OVERRIDE) {
1.51      bowersj2 2867:         # and there are TRIES LEFT:
1.79      bowersj2 2868:         if ($self->tries($part) < $self->maxtries($part) || !$self->maxtries($part)) {
1.53      bowersj2 2869:             return TRIES_LEFT;
1.51      bowersj2 2870:         }
1.53      bowersj2 2871:         return INCORRECT; # otherwise, return orange; student can't fix this
1.51      bowersj2 2872:     }
                   2873: 
                   2874:     # Otherwise, it's untried and open
1.53      bowersj2 2875:     return OPEN; 
1.51      bowersj2 2876: }
                   2877: 
                   2878: =pod
                   2879: 
                   2880: =head2 Resource/Nav Map Navigation
                   2881: 
                   2882: =over 4
                   2883: 
1.101     bowersj2 2884: =item * B<getNext>(): Retreive an array of the possible next resources after this one. Always returns an array, even in the one- or zero-element case. 
1.85      bowersj2 2885: 
1.101     bowersj2 2886: =item * B<getPrevious>(): Retreive an array of the possible previous resources from this one. Always returns an array, even in the one- or zero-element case. 
1.51      bowersj2 2887: 
                   2888: =cut
                   2889: 
                   2890: sub getNext {
                   2891:     my $self = shift;
                   2892:     my @branches;
                   2893:     my $to = $self->to();
1.85      bowersj2 2894:     foreach my $branch ( split(/,/, $to) ) {
1.51      bowersj2 2895:         my $choice = $self->{NAV_MAP}->getById($branch);
                   2896:         my $next = $choice->goesto();
                   2897:         $next = $self->{NAV_MAP}->getById($next);
                   2898: 
1.131     bowersj2 2899:         push @branches, $next;
1.85      bowersj2 2900:     }
                   2901:     return \@branches;
                   2902: }
                   2903: 
                   2904: sub getPrevious {
                   2905:     my $self = shift;
                   2906:     my @branches;
                   2907:     my $from = $self->from();
                   2908:     foreach my $branch ( split /,/, $from) {
                   2909:         my $choice = $self->{NAV_MAP}->getById($branch);
                   2910:         my $prev = $choice->comesfrom();
                   2911:         $prev = $self->{NAV_MAP}->getById($prev);
                   2912: 
1.131     bowersj2 2913:         push @branches, $prev;
1.51      bowersj2 2914:     }
                   2915:     return \@branches;
1.131     bowersj2 2916: }
                   2917: 
                   2918: sub browsePriv {
                   2919:     my $self = shift;
                   2920:     if (defined($self->{BROWSE_PRIV})) {
                   2921:         return $self->{BROWSE_PRIV};
                   2922:     }
                   2923: 
                   2924:     $self->{BROWSE_PRIV} = &Apache::lonnet::allowed('bre', $self->src());
1.51      bowersj2 2925: }
                   2926: 
                   2927: =pod
1.2       www      2928: 
1.51      bowersj2 2929: =back
1.2       www      2930: 
1.51      bowersj2 2931: =cut
1.2       www      2932: 
1.51      bowersj2 2933: 1;
1.2       www      2934: 
1.51      bowersj2 2935: __END__
1.2       www      2936: 
                   2937: 

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