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

1.481     foxr        1: # The LearningOnline Network with CAPA
1.2       www         2: # Navigate Maps Handler
1.1       www         3: #
1.542   ! raeburn     4: # $Id: lonnavmaps.pm,v 1.541 2018/01/31 14:05:12 raeburn Exp $
1.20      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.245     www        28: ###
1.2       www        29: 
1.416     jms        30: =pod
                     31: 
                     32: =head1 NAME
                     33: 
1.435     raeburn    34: Apache::lonnavmaps - Subroutines to handle and render the navigation
1.416     jms        35: 
                     36: =head1 SYNOPSIS
                     37: 
                     38: Handles navigational maps.
                     39: 
                     40: The main handler generates the navigational listing for the course,
                     41: the other objects export this information in a usable fashion for
                     42: other modules.
                     43: 
                     44: 
                     45: This is part of the LearningOnline Network with CAPA project
                     46: described at http://www.lon-capa.org.
                     47: 
                     48: 
                     49: =head1 OVERVIEW
                     50: 
1.439     wenzelju   51: X<lonnavmaps, overview> When a user enters a course, LON-CAPA examines the
1.416     jms        52: course structure and caches it in what is often referred to as the
                     53: "big hash" X<big hash>. You can see it if you are logged into
1.532     raeburn    54: LON-CAPA, in a course, by going to /adm/test. The content of 
                     55: the hash will be under the heading "Big Hash".
                     56: 
                     57: Access to /adm/test is controlled by a domain configuration, 
                     58: which a Domain Coordinator will set for a server's default domain
                     59: via: Main Menu > Set domain configuration > Display (Access to 
                     60: server status pages checked), and entering a username:domain
                     61: or IP address in the "Show user environment" row. Users with
                     62: an unexpired domain coordinator role in the server's domain
                     63: automatically receive access to /adm/test.
1.416     jms        64: 
                     65: Big Hash contains, among other things, how resources are related
                     66: to each other (next/previous), what resources are maps, which 
                     67: resources are being chosen to not show to the student (for random
                     68: selection), and a lot of other things that can take a lot of time
                     69: to compute due to the amount of data that needs to be collected and
                     70: processed.
                     71: 
                     72: Apache::lonnavmaps provides an object model for manipulating this
                     73: information in a higher-level fashion than directly manipulating 
1.541     raeburn    74: the hash. It also provides access to several auxiliary functions 
1.416     jms        75: that aren't necessarily stored in the Big Hash, but are a per-
                     76: resource sort of value, like whether there is any feedback on 
                     77: a given resource.
                     78: 
                     79: Apache::lonnavmaps also abstracts away branching, and someday, 
                     80: conditions, for the times where you don't really care about those
                     81: things.
                     82: 
                     83: Apache::lonnavmaps also provides fairly powerful routines for
                     84: rendering navmaps, and last but not least, provides the navmaps
                     85: view for when the user clicks the NAV button.
                     86: 
1.532     raeburn    87: B<Note>: Apache::lonnavmaps by default will show information 
                     88: for the "currently logged in user".  However, if information
                     89: about resources is needed for a different user, e.g., a bubblesheet
                     90: exam which uses randomorder, or randompick needs to be printed or 
                     91: graded for named user(s) or specific CODEs, then the username,
                     92: domain, or CODE can be passed as arguments when creating a new 
                     93: navmap object.
                     94: 
1.541     raeburn    95: Note if you want things like "due dates for another student",
1.532     raeburn    96: you would use the EXT function instead of lonnavmaps.
                     97: That said, the lonnavmaps module can still help, because many
                     98: things, such as the course structure, are usually constant
1.416     jms        99: between users, and Apache::lonnavmaps can help by providing
                    100: symbs for the EXT call.
                    101: 
                    102: The rest of this file will cover the provided rendering routines, 
                    103: which can often be used without fiddling with the navmap object at
                    104: all, then documents the Apache::lonnavmaps::navmap object, which
                    105: is the key to accessing the Big Hash information, covers the use
                    106: of the Iterator (which provides the logic for traversing the 
                    107: somewhat-complicated Big Hash data structure), documents the
1.532     raeburn   108: Apache::lonnavmaps::Resource objects that are returned singularly
                    109: by: getBySymb(), getById(), getByMapPc(), and getResourceByUrl()
                    110: (can also be as an array), or in an array by retrieveResources().
1.416     jms       111: 
                    112: =head1 Subroutine: render
                    113: 
                    114: The navmap renderer package provides a sophisticated rendering of the
                    115: standard navigation maps interface into HTML. The provided nav map
                    116: handler is actually just a glorified call to this.
                    117: 
                    118: Because of the large number of parameters this function accepts,
                    119: instead of passing it arguments as is normal, pass it in an anonymous
                    120: hash with the desired options.
                    121: 
                    122: The package provides a function called 'render', called as
                    123: Apache::lonnavmaps::render({}).
                    124: 
                    125: =head2 Overview of Columns
                    126: 
                    127: The renderer will build an HTML table for the navmap and return
                    128: it. The table consists of several columns, and a row for each
                    129: resource (or possibly each part). You tell the renderer how many
                    130: columns to create and what to place in each column, optionally using
                    131: one or more of the prepared columns, and the renderer will assemble
                    132: the table.
                    133: 
                    134: Any additional generally useful column types should be placed in the
                    135: renderer code here, so anybody can use it anywhere else. Any code
                    136: specific to the current application (such as the addition of <input>
                    137: elements in a column) should be placed in the code of the thing using
                    138: the renderer.
                    139: 
                    140: At the core of the renderer is the array reference COLS (see Example
                    141: section below for how to pass this correctly). The COLS array will
                    142: consist of entries of one of two types of things: Either an integer
                    143: representing one of the pre-packaged column types, or a sub reference
                    144: that takes a resource reference, a part number, and a reference to the
                    145: argument hash passed to the renderer, and returns a string that will
                    146: be inserted into the HTML representation as it.
                    147: 
                    148: All other parameters are ways of either changing how the columns
                    149: are printing, or which rows are shown.
                    150: 
                    151: The pre-packaged column names are refered to by constants in the
                    152: Apache::lonnavmaps namespace. The following currently exist:
                    153: 
                    154: =over 4
                    155: 
                    156: =item * B<Apache::lonnavmaps::resource>:
                    157: 
                    158: The general info about the resource: Link, icon for the type, etc. The
                    159: first column in the standard nav map display. This column provides the
                    160: indentation effect seen in the B<NAV> screen. This column also accepts
                    161: the following parameters in the renderer hash:
                    162: 
                    163: =over 4
                    164: 
                    165: =item * B<resource_nolink>: default false
                    166: 
                    167: If true, the resource will not be linked. By default, all non-folder
                    168: resources are linked.
                    169: 
                    170: =item * B<resource_part_count>: default true
                    171: 
                    172: If true, the resource will show a part count B<if> the full
                    173: part list is not displayed. (See "condense_parts" later.) If false,
                    174: the resource will never show a part count.
                    175: 
                    176: =item * B<resource_no_folder_link>:
                    177: 
                    178: If true, the resource's folder will not be clickable to open or close
                    179: it. Default is false. True implies printCloseAll is false, since you
                    180: can't close or open folders when this is on anyhow.
                    181: 
1.493     raeburn   182: =item * B<map_no_edit_link>:
                    183: 
                    184: If true, the title of the folder or page will not be followed by an
                    185: icon/link to direct editing of a folder or composite page, originally
                    186: added via the Course Editor.
                    187: 
1.416     jms       188: =back
                    189: 
                    190: =item * B<Apache::lonnavmaps::communication_status>:
                    191: 
                    192: Whether there is discussion on the resource, email for the user, or
                    193: (lumped in here) perl errors in the execution of the problem. This is
                    194: the second column in the main nav map.
                    195: 
                    196: =item * B<Apache::lonnavmaps::quick_status>:
                    197: 
                    198: An icon for the status of a problem, with five possible states:
                    199: Correct, incorrect, open, awaiting grading (for a problem where the
                    200: computer's grade is suppressed, or the computer can't grade, like
                    201: essay problem), or none (not open yet, not a problem). The
                    202: third column of the standard navmap.
                    203: 
                    204: =item * B<Apache::lonnavmaps::long_status>:
                    205: 
                    206: A text readout of the details of the current status of the problem,
                    207: such as "Due in 22 hours". The fourth column of the standard navmap.
                    208: 
                    209: =item * B<Apache::lonnavmaps::part_status_summary>:
                    210: 
                    211: A text readout summarizing the status of the problem. If it is a
                    212: single part problem, will display "Correct", "Incorrect", 
                    213: "Not yet open", "Open", "Attempted", or "Error". If there are
                    214: multiple parts, this will output a string that in HTML will show a
                    215: status of how many parts are in each status, in color coding, trying
                    216: to match the colors of the icons within reason.
1.1       www       217: 
1.416     jms       218: Note this only makes sense if you are I<not> showing parts. If 
                    219: C<showParts> is true (see below), this column will not output
                    220: anything. 
1.2       www       221: 
1.416     jms       222: =back
1.133     bowersj2  223: 
1.416     jms       224: If you add any others please be sure to document them here.
1.133     bowersj2  225: 
1.416     jms       226: An example of a column renderer that will show the ID number of a
                    227: resource, along with the part name if any:
1.140     bowersj2  228: 
1.416     jms       229:  sub { 
                    230:   my ($resource, $part, $params) = @_;   
                    231:   if ($part) { return '<td>' . $resource->{ID} . ' ' . $part . '</td>'; }
                    232:   return '<td>' . $resource->{ID} . '</td>';
                    233:  }
1.135     bowersj2  234: 
1.416     jms       235: Note these functions are responsible for the TD tags, which allow them
                    236: to override vertical and horizontal alignment, etc.
1.133     bowersj2  237: 
1.416     jms       238: =head2 Parameters
1.130     www       239: 
1.416     jms       240: Minimally, you should be
                    241: able to get away with just using 'cols' (to specify the columns
                    242: shown), 'url' (necessary for the folders to link to the current screen
                    243: correctly), and possibly 'queryString' if your app calls for it. In
                    244: that case, maintaining the state of the folders will be done
                    245: automatically.
1.268     albertel  246: 
1.416     jms       247: =over 4
1.268     albertel  248: 
1.483     raeburn   249: =item * B<iterator>: default: constructs one from %env
1.51      bowersj2  250: 
1.416     jms       251: A reference to a fresh ::iterator to use from the navmaps. The
                    252: rendering will reflect the options passed to the iterator, so you can
                    253: use that to just render a certain part of the course, if you like. If
                    254: one is not passed, the renderer will attempt to construct one from
                    255: env{'form.filter'} and env{'form.condition'} information, plus the
                    256: 'iterator_map' parameter if any.
1.51      bowersj2  257: 
1.416     jms       258: =item * B<iterator_map>: default: not used
1.51      bowersj2  259: 
1.416     jms       260: If you are letting the renderer do the iterator handling, you can
                    261: instruct the renderer to render only a particular map by passing it
                    262: the source of the map you want to process, like
                    263: '/res/103/jerf/navmap.course.sequence'.
1.51      bowersj2  264: 
1.416     jms       265: =item * B<include_top_level_map>: default: false
1.51      bowersj2  266: 
1.416     jms       267: If you need to include the top level map (meaning the course) in the
                    268: rendered output set this to true
1.51      bowersj2  269: 
1.416     jms       270: =item * B<navmap>: default: constructs one from %env
1.51      bowersj2  271: 
1.416     jms       272: A reference to a navmap, used only if an iterator is not passed in. If
                    273: this is necessary to make an iterator but it is not passed in, a new
                    274: one will be constructed based on env info. This is useful to do basic
                    275: error checking before passing it off to render.
1.51      bowersj2  276: 
1.416     jms       277: =item * B<r>: default: must be passed in
1.53      bowersj2  278: 
1.416     jms       279: The standard Apache response object. This must be passed to the
                    280: renderer or the course hash will be locked.
1.53      bowersj2  281: 
1.416     jms       282: =item * B<cols>: default: empty (useless)
1.407     raeburn   283: 
1.416     jms       284: An array reference
1.53      bowersj2  285: 
1.416     jms       286: =item * B<showParts>:default true
1.115     bowersj2  287: 
1.416     jms       288: A flag. If true, a line for the resource itself, and a line
                    289: for each part will be displayed. If not, only one line for each
                    290: resource will be displayed.
1.115     bowersj2  291: 
1.416     jms       292: =item * B<condenseParts>: default true
1.115     bowersj2  293: 
1.416     jms       294: A flag. If true, if all parts of the problem have the same
                    295: status and that status is Nothing Set, Correct, or Network Failure,
                    296: then only one line will be displayed for that resource anyhow. If no,
                    297: all parts will always be displayed. If showParts is 0, this is
                    298: ignored.
1.115     bowersj2  299: 
1.416     jms       300: =item * B<jumpCount>: default: determined from %env
1.115     bowersj2  301: 
1.416     jms       302: A string identifying the URL to place the anchor 'curloc' at.
                    303: It is the responsibility of the renderer user to
                    304: ensure that the #curloc is in the URL. By default, determined through
                    305: the use of the env{} 'jump' information, and should normally "just
                    306: work" correctly.
1.177     www       307: 
1.416     jms       308: =item * B<here>: default: empty string
1.68      bowersj2  309: 
1.416     jms       310: A Symb identifying where to place the 'here' marker. The empty
                    311: string means no marker.
1.73      bowersj2  312: 
1.416     jms       313: =item * B<indentString>: default: 25 pixel whitespace image
1.347     www       314: 
1.416     jms       315: A string identifying the indentation string to use. 
1.347     www       316: 
1.416     jms       317: =item * B<queryString>: default: empty
1.346     foxr      318: 
1.416     jms       319: A string which will be prepended to the query string used when the
                    320: folders are opened or closed. You can use this to pass
                    321: application-specific values.
1.73      bowersj2  322: 
1.416     jms       323: =item * B<url>: default: none
1.73      bowersj2  324: 
1.416     jms       325: The url the folders will link to, which should be the current
                    326: page. Required if the resource info column is shown, and you 
                    327: are allowing the user to open and close folders.
1.73      bowersj2  328: 
1.416     jms       329: =item * B<currentJumpIndex>: default: no jumping
1.73      bowersj2  330: 
1.416     jms       331: Describes the currently-open row number to cause the browser to jump
                    332: to, because the user just opened that folder. By default, pulled from
                    333: the Jump information in the env{'form.*'}.
1.73      bowersj2  334: 
1.416     jms       335: =item * B<printKey>: default: false
1.101     bowersj2  336: 
1.416     jms       337: If true, print the key that appears on the top of the standard
                    338: navmaps.
1.73      bowersj2  339: 
1.416     jms       340: =item * B<printCloseAll>: default: true
1.73      bowersj2  341: 
1.416     jms       342: If true, print the "Close all folders" or "open all folders"
                    343: links.
1.403     albertel  344: 
1.416     jms       345: =item * B<filterFunc>: default: sub {return 1;} (accept everything)
1.346     foxr      346: 
1.416     jms       347: A function that takes the resource object as its only parameter and
                    348: returns a true or false value. If true, the resource is displayed. If
                    349: false, it is simply skipped in the display.
1.346     foxr      350: 
1.416     jms       351: =item * B<suppressEmptySequences>: default: false
1.346     foxr      352: 
1.416     jms       353: If you're using a filter function, and displaying sequences to orient
                    354: the user, then frequently some sequences will be empty. Setting this to
                    355: true will cause those sequences not to display, so as not to confuse the
                    356: user into thinking that if the sequence is there there should be things
                    357: under it; for example, see the "Show Uncompleted Homework" view on the
                    358: B<NAV> screen.
1.73      bowersj2  359: 
1.416     jms       360: =item * B<suppressNavmaps>: default: false
1.53      bowersj2  361: 
1.416     jms       362: If true, will not display Navigate Content resources. 
1.51      bowersj2  363: 
1.416     jms       364: =back
1.133     bowersj2  365: 
1.416     jms       366: =head2 Additional Info
1.174     albertel  367: 
1.416     jms       368: In addition to the parameters you can pass to the renderer, which will
                    369: be passed through unchange to the column renderers, the renderer will
                    370: generate the following information which your renderer may find
                    371: useful:
1.174     albertel  372: 
1.416     jms       373: =over 4
1.174     albertel  374: 
1.416     jms       375: =item * B<counter>: 
1.133     bowersj2  376: 
1.416     jms       377: Contains the number of rows printed. Useful after calling the render 
                    378: function, as you can detect whether anything was printed at all.
1.216     bowersj2  379: 
1.416     jms       380: =item * B<isNewBranch>:
1.216     bowersj2  381: 
1.416     jms       382: Useful for renderers: If this resource is currently the first resource
                    383: of a new branch, this will be true. The Resource column (leftmost in the
                    384: navmaps screen) uses this to display the "new branch" icon 
1.216     bowersj2  385: 
1.416     jms       386: =back
1.216     bowersj2  387: 
1.416     jms       388: =cut
1.216     bowersj2  389: 
                    390: 
1.416     jms       391: =head1 SUBROUTINES
1.216     bowersj2  392: 
1.416     jms       393: =over
1.216     bowersj2  394: 
1.416     jms       395: =item update()
1.133     bowersj2  396: 
1.416     jms       397: =item addToFilter()
1.133     bowersj2  398: 
1.416     jms       399: Convenience functions: Returns a string that adds or subtracts
                    400: the second argument from the first hash, appropriate for the 
                    401: query string that determines which folders to recurse on
1.174     albertel  402: 
1.416     jms       403: =item removeFromFilter()
1.51      bowersj2  404: 
1.416     jms       405: =item getLinkForResource()
1.51      bowersj2  406: 
1.416     jms       407: Convenience function: Given a stack returned from getStack on the iterator,
                    408: return the correct src() value.
1.174     albertel  409: 
1.416     jms       410: =item getDescription()
1.174     albertel  411: 
1.416     jms       412: Convenience function: This separates the logic of how to create
                    413: the problem text strings ("Due: DATE", "Open: DATE", "Not yet assigned",
                    414: etc.) into a separate function. It takes a resource object as the
                    415: first parameter, and the part number of the resource as the second.
                    416: It's basically a big switch statement on the status of the resource.
1.174     albertel  417: 
1.416     jms       418: =item dueInLessThan24Hours()
1.216     bowersj2  419: 
1.416     jms       420: Convenience function, so others can use it: Is the problem due in less than 24 hours, and still can be done?
1.51      bowersj2  421: 
1.416     jms       422: =item lastTry()
1.51      bowersj2  423: 
1.416     jms       424: Convenience function, so others can use it: Is there only one try remaining for the
                    425: part, with more than one try to begin with, not due yet and still can be done?
1.51      bowersj2  426: 
1.416     jms       427: =item advancedUser()
1.51      bowersj2  428: 
1.416     jms       429: This puts a human-readable name on the env variable.
1.51      bowersj2  430: 
1.416     jms       431: =item timeToHumanString()
1.51      bowersj2  432: 
1.416     jms       433: timeToHumanString takes a time number and converts it to a
                    434: human-readable representation, meant to be used in the following
                    435: manner:
1.174     albertel  436: 
1.416     jms       437: =over 4
1.51      bowersj2  438: 
1.416     jms       439: =item * print "Due $timestring"
1.133     bowersj2  440: 
1.416     jms       441: =item * print "Open $timestring"
1.133     bowersj2  442: 
1.416     jms       443: =item * print "Answer available $timestring"
1.144     bowersj2  444: 
1.133     bowersj2  445: =back
1.51      bowersj2  446: 
1.416     jms       447: Very, very, very, VERY English-only... goodness help a localizer on
                    448: this func...
1.174     albertel  449: 
1.417     jms       450: =item resource()
1.174     albertel  451: 
1.417     jms       452: returns 0
1.51      bowersj2  453: 
1.417     jms       454: =item communication_status()
1.51      bowersj2  455: 
1.417     jms       456: returns 1
1.174     albertel  457: 
1.417     jms       458: =item quick_status()
1.51      bowersj2  459: 
1.417     jms       460: returns 2
1.225     bowersj2  461: 
1.417     jms       462: =item long_status()
1.225     bowersj2  463: 
1.417     jms       464: returns 3
1.225     bowersj2  465: 
1.417     jms       466: =item part_status_summary()
1.51      bowersj2  467: 
1.417     jms       468: returns 4
1.51      bowersj2  469: 
1.417     jms       470: =item render_resource()
1.51      bowersj2  471: 
1.417     jms       472: =item render_communication_status()
1.51      bowersj2  473: 
1.417     jms       474: =item render_quick_status()
                    475: 
                    476: =item render_long_status()
                    477: 
                    478: =item render_parts_summary_status()
                    479: 
                    480: =item setDefault()
                    481: 
                    482: =item cmp_title()
                    483: 
                    484: =item render()
                    485: 
                    486: =item add_linkitem()
                    487: 
1.476     raeburn   488: =item show_linkitems_toolbar()
1.130     www       489: 
1.416     jms       490: =back
1.115     bowersj2  491: 
1.416     jms       492: =cut
1.140     bowersj2  493: 
1.416     jms       494: package Apache::lonnavmaps;
1.51      bowersj2  495: 
1.416     jms       496: use strict;
                    497: use GDBM_File;
                    498: use Apache::loncommon();
                    499: use Apache::lonenc();
                    500: use Apache::lonlocal;
                    501: use Apache::lonnet;
1.465     foxr      502: use Apache::lonmap;
1.443     foxr      503: 
1.535     raeburn   504: use POSIX qw (ceil floor strftime);
1.416     jms       505: use Time::HiRes qw( gettimeofday tv_interval );
                    506: use LONCAPA;
                    507: use DateTime();
1.486     raeburn   508: use HTML::Entities;
1.465     foxr      509: 
                    510: # For debugging
                    511: 
1.499     raeburn   512: #use Data::Dumper;
1.465     foxr      513: 
                    514: 
1.416     jms       515: # symbolic constants
                    516: sub SYMB { return 1; }
                    517: sub URL { return 2; }
                    518: sub NOTHING { return 3; }
1.174     albertel  519: 
1.416     jms       520: # Some data
1.174     albertel  521: 
1.416     jms       522: my $resObj = "Apache::lonnavmaps::resource";
1.174     albertel  523: 
1.443     foxr      524: # Keep these mappings in sync with lonquickgrades, which usesthe colors
1.416     jms       525: # instead of the icons.
                    526: my %statusIconMap = 
                    527:     (
                    528:      $resObj->CLOSED       => '',
                    529:      $resObj->OPEN         => 'navmap.open.gif',
                    530:      $resObj->CORRECT      => 'navmap.correct.gif',
                    531:      $resObj->PARTIALLY_CORRECT      => 'navmap.partial.gif',
                    532:      $resObj->INCORRECT    => 'navmap.wrong.gif',
                    533:      $resObj->ATTEMPTED    => 'navmap.ellipsis.gif',
                    534:      $resObj->ERROR        => ''
                    535:      );
1.401     albertel  536: 
1.438     wenzelju  537: my %iconAltTags =   #texthash does not work here
1.439     wenzelju  538:     ( 'navmap.correct.gif'  => 'Correct',
                    539:       'navmap.wrong.gif'    => 'Incorrect',
1.462     christia  540:       'navmap.open.gif'     => 'Is Open',
1.439     wenzelju  541:       'navmap.partial.gif'  => 'Partially Correct',
                    542:       'navmap.ellipsis.gif' => 'Attempted',
                    543:      );
1.401     albertel  544: 
1.416     jms       545: # Defines a status->color mapping, null string means don't color
                    546: my %colormap = 
                    547:     ( $resObj->NETWORK_FAILURE        => '',
                    548:       $resObj->CORRECT                => '',
                    549:       $resObj->EXCUSED                => '#3333FF',
                    550:       $resObj->PAST_DUE_ANSWER_LATER  => '',
                    551:       $resObj->PAST_DUE_NO_ANSWER     => '',
                    552:       $resObj->ANSWER_OPEN            => '#006600',
                    553:       $resObj->OPEN_LATER             => '',
                    554:       $resObj->TRIES_LEFT             => '',
                    555:       $resObj->INCORRECT              => '',
                    556:       $resObj->OPEN                   => '',
                    557:       $resObj->NOTHING_SET            => '',
                    558:       $resObj->ATTEMPTED              => '',
1.450     raeburn   559:       $resObj->CREDIT_ATTEMPTED       => '',
1.416     jms       560:       $resObj->ANSWER_SUBMITTED       => '',
                    561:       $resObj->PARTIALLY_CORRECT      => '#006600'
                    562:       );
                    563: # And a special case in the nav map; what to do when the assignment
                    564: # is not yet done and due in less than 24 hours
                    565: my $hurryUpColor = "#FF0000";
1.174     albertel  566: 
1.416     jms       567: sub addToFilter {
                    568:     my $hashIn = shift;
                    569:     my $addition = shift;
                    570:     my %hash = %$hashIn;
                    571:     $hash{$addition} = 1;
1.174     albertel  572: 
1.416     jms       573:     return join (",", keys(%hash));
                    574: }
1.174     albertel  575: 
1.416     jms       576: sub removeFromFilter {
                    577:     my $hashIn = shift;
                    578:     my $subtraction = shift;
                    579:     my %hash = %$hashIn;
1.174     albertel  580: 
1.416     jms       581:     delete $hash{$subtraction};
                    582:     return join(",", keys(%hash));
                    583: }
1.174     albertel  584: 
1.416     jms       585: sub getLinkForResource {
                    586:     my $stack = shift;
                    587:     my $res;
1.174     albertel  588: 
1.416     jms       589:     # Check to see if there are any pages in the stack
                    590:     foreach $res (@$stack) {
                    591:         if (defined($res)) {
                    592: 	    my $anchor;
                    593: 	    if ($res->is_page()) {
                    594: 		foreach my $item (@$stack) { if (defined($item)) { $anchor = $item; }  }
                    595: 		$anchor=&escape($anchor->shown_symb());
                    596: 		return ($res->link(),$res->shown_symb(),$anchor);
                    597: 	    }
                    598:             # in case folder was skipped over as "only sequence"
                    599: 	    my ($map,$id,$src)=&Apache::lonnet::decode_symb($res->symb());
                    600: 	    if ($map=~/\.page$/) {
                    601: 		my $url=&Apache::lonnet::clutter($map);
1.437     foxr      602: 		$anchor=&escape($res->shown_symb());
1.416     jms       603: 		return ($url,$res->shown_symb(),$anchor);
                    604: 	    }
                    605:         }
                    606:     }
1.174     albertel  607: 
1.416     jms       608:     # Failing that, return the src of the last resource that is defined
                    609:     # (when we first recurse on a map, it puts an undefined resource
                    610:     # on the bottom because $self->{HERE} isn't defined yet, and we
                    611:     # want the src for the map anyhow)
                    612:     foreach my $item (@$stack) {
                    613:         if (defined($item)) { $res = $item; }
                    614:     }
1.174     albertel  615: 
1.416     jms       616:     if ($res) {
                    617: 	return ($res->link(),$res->shown_symb());
                    618:     }
                    619:     return;
                    620: }
1.174     albertel  621: 
1.417     jms       622: 
1.140     bowersj2  623: 
1.416     jms       624: sub getDescription {
                    625:     my $res = shift;
                    626:     my $part = shift;
                    627:     my $status = $res->status($part);
1.92      bowersj2  628: 
1.416     jms       629:     my $open = $res->opendate($part);
                    630:     my $due = $res->duedate($part);
                    631:     my $answer = $res->answerdate($part);
1.164     bowersj2  632: 
1.416     jms       633:     if ($status == $res->NETWORK_FAILURE) { 
                    634:         return &mt("Having technical difficulties; please check status later"); 
                    635:     }
                    636:     if ($status == $res->NOTHING_SET) {
1.494     raeburn   637:         return &Apache::lonhtmlcommon::direct_parm_link(&mt('Not currently assigned'),$res->symb(),'opendate',$part);
1.416     jms       638:     }
                    639:     if ($status == $res->OPEN_LATER) {
1.467     www       640:         return &mt("Open [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($open,'start'),$res->symb(),'opendate',$part));
1.416     jms       641:     }
1.509     raeburn   642:     my $slotinfo;
1.432     raeburn   643:     if ($res->simpleStatus($part) == $res->OPEN) {
                    644:         unless (&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) {
                    645:             my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
1.509     raeburn   646:             my $slotmsg;
1.432     raeburn   647:             if ($slot_status == $res->UNKNOWN) {
1.509     raeburn   648:                 $slotmsg = &mt('Reservation status unknown');
1.432     raeburn   649:             } elsif ($slot_status == $res->RESERVED) {
1.509     raeburn   650:                 $slotmsg = &mt('Reserved - ends [_1]',
1.433     bisitz    651:                            timeToHumanString($slot_time,'end'));
1.432     raeburn   652:             } elsif ($slot_status == $res->RESERVED_LOCATION) {
1.509     raeburn   653:                 $slotmsg = &mt('Reserved - specific location(s) - ends [_1]',
1.433     bisitz    654:                            timeToHumanString($slot_time,'end'));
1.432     raeburn   655:             } elsif ($slot_status == $res->RESERVED_LATER) {
1.509     raeburn   656:                 $slotmsg = &mt('Reserved - next open [_1]',
1.433     bisitz    657:                            timeToHumanString($slot_time,'start'));
1.432     raeburn   658:             } elsif ($slot_status == $res->RESERVABLE) {
1.509     raeburn   659:                 $slotmsg = &mt('Reservable, reservations close [_1]',
1.433     bisitz    660:                            timeToHumanString($slot_time,'end'));
1.538     raeburn   661:             } elsif ($slot_status == $res->NEEDS_CHECKIN) {
                    662:                 $slotmsg = &mt('Reserved, check-in needed - ends [_1]',
                    663:                            timeToHumanString($slot_time,'end'));
1.432     raeburn   664:             } elsif ($slot_status == $res->RESERVABLE_LATER) {
1.509     raeburn   665:                 $slotmsg = &mt('Reservable, reservations open [_1]',
1.433     bisitz    666:                            timeToHumanString($slot_time,'start'));
1.432     raeburn   667:             } elsif ($slot_status == $res->NOT_IN_A_SLOT) {
1.509     raeburn   668:                 $slotmsg = &mt('Reserve a time/place to work');
1.432     raeburn   669:             } elsif ($slot_status == $res->NOTRESERVABLE) {
1.509     raeburn   670:                 $slotmsg = &mt('Reservation not available');
1.432     raeburn   671:             } elsif ($slot_status == $res->WAITING_FOR_GRADE) {
1.509     raeburn   672:                 $slotmsg = &mt('Submission in grading queue');
                    673:             }
                    674:             if ($slotmsg) {
                    675:                 if ($res->is_task() || !$due) {
                    676:                      return $slotmsg;
                    677:                 }
                    678:                 $slotinfo = ('&nbsp;' x 2).'('.$slotmsg.')';
1.432     raeburn   679:             }
                    680:         }
                    681:     }
1.416     jms       682:     if ($status == $res->OPEN) {
                    683:         if ($due) {
                    684: 	    if ($res->is_practice()) {
1.509     raeburn   685: 		return &mt("Closes [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($due,'start'),$res->symb(),'duedate',$part)).$slotinfo;
1.416     jms       686: 	    } else {
1.509     raeburn   687: 		return &mt("Due [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($due,'end'),$res->symb(),'duedate',$part)).$slotinfo;
1.416     jms       688: 	    }
                    689:         } else {
1.509     raeburn   690:             return &Apache::lonhtmlcommon::direct_parm_link(&mt("Open, no due date"),$res->symb(),'duedate',$part).$slotinfo;
1.416     jms       691:         }
                    692:     }
                    693:     if ($status == $res->PAST_DUE_ANSWER_LATER) {
1.467     www       694:         return &mt("Answer open [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($answer,'start'),$res->symb(),'answerdate',$part));
1.416     jms       695:     }
                    696:     if ($status == $res->PAST_DUE_NO_ANSWER) {
                    697: 	if ($res->is_practice()) {
1.467     www       698: 	    return &mt("Closed [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($due,'start'),$res->symb(),'answerdate,duedate',$part));
1.416     jms       699: 	} else {
1.467     www       700: 	    return &mt("Was due [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($due,'end'),$res->symb(),'answerdate,duedate',$part));
1.416     jms       701: 	}
                    702:     }
                    703:     if (($status == $res->ANSWER_OPEN || $status == $res->PARTIALLY_CORRECT)
                    704: 	&& $res->handgrade($part) ne 'yes') {
1.539     raeburn   705:         my $msg = &mt('Answer available');
                    706:         my $parmlist = 'answerdate,duedate';
                    707:         if (($res->is_tool) && ($res->is_gradable())) {
                    708:             if (($status == $res->PARTIALLY_CORRECT) && ($res->parmval('retrypartial',$part))) {
                    709:                 $msg = &mt('Grade received');
                    710:                 $parmlist = 'retrypartial';
                    711:             } else {
                    712:                 $msg = &mt('Grade available');
                    713:             }
                    714:         }
                    715:         return &Apache::lonhtmlcommon::direct_parm_link($msg,$res->symb(),$parmlist,$part);
1.416     jms       716:     }
                    717:     if ($status == $res->EXCUSED) {
                    718:         return &mt("Excused by instructor");
                    719:     }
                    720:     if ($status == $res->ATTEMPTED) {
1.444     raeburn   721:         if ($res->is_anonsurvey($part) || $res->is_survey($part)) {
                    722:             return &mt("Survey submission recorded");
                    723:         } else {
                    724:             return &mt("Answer submitted, not yet graded");
                    725:         }
1.416     jms       726:     }
1.450     raeburn   727:     if ($status == $res->CREDIT_ATTEMPTED) {
                    728:         if ($res->is_anonsurvey($part) || $res->is_survey($part)) {
                    729:             return &mt("Credit for survey submission");
                    730:         }
                    731:     }
1.416     jms       732:     if ($status == $res->TRIES_LEFT) {
                    733:         my $tries = $res->tries($part);
                    734:         my $maxtries = $res->maxtries($part);
                    735:         my $triesString = "";
                    736:         if ($tries && $maxtries) {
1.488     bisitz    737:             $triesString = '<span class="LC_fontsize_medium"><i>('.&mt('[_1] of [quant,_2,try,tries] used',$tries,$maxtries).')</i></span>';
1.416     jms       738:             if ($maxtries > 1 && $maxtries - $tries == 1) {
                    739:                 $triesString = "<b>$triesString</b>";
                    740:             }
                    741:         }
                    742:         if ($due) {
1.467     www       743:             return &mt("Due [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($due,'end'),$res->symb(),'duedate',$part)) .
1.416     jms       744:                 " $triesString";
                    745:         } else {
1.455     www       746:             return &Apache::lonhtmlcommon::direct_parm_link(&mt("No due date"),$res->symb(),'duedate',$part)." $triesString";
1.416     jms       747:         }
                    748:     }
                    749:     if ($status == $res->ANSWER_SUBMITTED) {
                    750:         return &mt('Answer submitted');
                    751:     }
                    752: }
1.92      bowersj2  753: 
1.51      bowersj2  754: 
1.416     jms       755: sub dueInLessThan24Hours {
                    756:     my $res = shift;
                    757:     my $part = shift;
                    758:     my $status = $res->status($part);
1.55      bowersj2  759: 
1.416     jms       760:     return ($status == $res->OPEN() ||
                    761:             $status == $res->TRIES_LEFT()) &&
                    762: 	    $res->duedate($part) && $res->duedate($part) < time()+(24*60*60) &&
                    763: 	    $res->duedate($part) > time();
                    764: }
1.84      bowersj2  765: 
1.417     jms       766: 
1.416     jms       767: sub lastTry {
                    768:     my $res = shift;
                    769:     my $part = shift;
1.115     bowersj2  770: 
1.416     jms       771:     my $tries = $res->tries($part);
                    772:     my $maxtries = $res->maxtries($part);
                    773:     return $tries && $maxtries && $maxtries > 1 &&
                    774:         $maxtries - $tries == 1 && $res->duedate($part) &&
                    775:         $res->duedate($part) > time();
                    776: }
1.55      bowersj2  777: 
1.51      bowersj2  778: 
1.416     jms       779: sub advancedUser {
                    780:     return $env{'request.role.adv'};
                    781: }
1.51      bowersj2  782: 
1.416     jms       783: sub timeToHumanString {
                    784:     my ($time,$type,$format) = @_;
1.153     bowersj2  785: 
1.416     jms       786:     # zero, '0' and blank are bad times
                    787:     if (!$time) {
                    788:         return &mt('never');
                    789:     }
                    790:     unless (&Apache::lonlocal::current_language()=~/^en/) {
                    791: 	return &Apache::lonlocal::locallocaltime($time);
                    792:     } 
                    793:     my $now = time();
1.174     albertel  794: 
1.416     jms       795:     # Positive = future
                    796:     my $delta = $time - $now;
1.190     bowersj2  797: 
1.416     jms       798:     my $minute = 60;
                    799:     my $hour = 60 * $minute;
                    800:     my $day = 24 * $hour;
                    801:     my $week = 7 * $day;
                    802:     my $inPast = 0;
1.190     bowersj2  803: 
1.416     jms       804:     # Logic in comments:
                    805:     # Is it now? (extremely unlikely)
                    806:     if ( $delta == 0 ) {
                    807:         return "this instant";
                    808:     }
1.174     albertel  809: 
1.416     jms       810:     if ($delta < 0) {
                    811:         $inPast = 1;
                    812:         $delta = -$delta;
                    813:     }
1.143     bowersj2  814: 
1.416     jms       815:     if ( $delta > 0 ) {
1.51      bowersj2  816: 
1.416     jms       817:         my $tense = $inPast ? " ago" : "";
                    818:         my $prefix = $inPast ? "" : "in ";
                    819:         
                    820:         # Less than a minute
                    821:         if ( $delta < $minute ) {
                    822:             if ($delta == 1) { return "${prefix}1 second$tense"; }
                    823:             return "$prefix$delta seconds$tense";
                    824:         }
1.51      bowersj2  825: 
1.416     jms       826:         # Less than an hour
                    827:         if ( $delta < $hour ) {
1.464     raeburn   828:             # If so, use minutes; or minutes, seconds (if format requires)
1.416     jms       829:             my $minutes = floor($delta / 60);
1.464     raeburn   830:             if (($format ne '') && ($format =~ /\%(T|S)/)) {
                    831:                 my $display;
                    832:                 if ($minutes == 1) {
                    833:                     $display = "${prefix}1 minute";
                    834:                 } else {
                    835:                     $display = "$prefix$minutes minutes";
                    836:                 }
                    837:                 my $seconds = $delta % $minute;
                    838:                 if ($seconds == 0) {
                    839:                     $display .= $tense;
                    840:                 } elsif ($seconds == 1) {
                    841:                     $display .= ", 1 second$tense";
                    842:                 } else {
                    843:                     $display .= ", $seconds seconds$tense";
                    844:                 }
                    845:                 return $display;
                    846:             }
1.416     jms       847:             if ($minutes == 1) { return "${prefix}1 minute$tense"; }
                    848:             return "$prefix$minutes minutes$tense";
                    849:         }
                    850:         
                    851:         # Is it less than 24 hours away? If so,
1.464     raeburn   852:         # display hours + minutes, (and + seconds, if format specified it)  
1.416     jms       853:         if ( $delta < $hour * 24) {
                    854:             my $hours = floor($delta / $hour);
                    855:             my $minutes = floor(($delta % $hour) / $minute);
                    856:             my $hourString = "$hours hours";
                    857:             my $minuteString = ", $minutes minutes";
                    858:             if ($hours == 1) {
                    859:                 $hourString = "1 hour";
                    860:             }
                    861:             if ($minutes == 1) {
                    862:                 $minuteString = ", 1 minute";
                    863:             }
                    864:             if ($minutes == 0) {
                    865:                 $minuteString = "";
                    866:             }
1.464     raeburn   867:             if (($format ne '') && ($format =~ /\%(T|S)/)) {
                    868:                 my $display = "$prefix$hourString$minuteString";
                    869:                 my $seconds = $delta-(($hours * $hour)+($minutes * $minute));
                    870:                 if ($seconds == 0) {
                    871:                     $display .= $tense;
                    872:                 } elsif ($seconds == 1) {
                    873:                     $display .= ", 1 second$tense";
                    874:                 } else {
                    875:                     $display .= ", $seconds seconds$tense";
                    876:                 }
                    877:                 return $display;
                    878:             }
1.416     jms       879:             return "$prefix$hourString$minuteString$tense";
                    880:         }
1.174     albertel  881: 
1.464     raeburn   882:         # Date/time is more than 24 hours away
                    883: 
1.416     jms       884: 	my $dt = DateTime->from_epoch(epoch => $time)
                    885: 	                 ->set_time_zone(&Apache::lonlocal::gettimezone());
1.216     bowersj2  886: 
1.464     raeburn   887: 	# If there's a caller supplied format, use it, unless it only displays
                    888:         # H:M:S or H:M.
1.145     bowersj2  889: 
1.464     raeburn   890: 	if (($format ne '') && ($format ne '%T') && ($format ne '%R')) {
1.416     jms       891: 	    my $timeStr = $dt->strftime($format);
                    892: 	    return $timeStr.' ('.$dt->time_zone_short_name().')';
                    893: 	}
1.216     bowersj2  894: 
1.416     jms       895:         # Less than 5 days away, display day of the week and
                    896:         # HH:MM
1.216     bowersj2  897: 
1.416     jms       898:         if ( $delta < $day * 5 ) {
                    899:             my $timeStr = $dt->strftime("%A, %b %e at %I:%M %P (%Z)");
                    900:             $timeStr =~ s/12:00 am/00:00/;
                    901:             $timeStr =~ s/12:00 pm/noon/;
                    902:             return ($inPast ? "last " : "this ") .
                    903:                 $timeStr;
                    904:         }
                    905:         
                    906: 	my $conjunction='on';
                    907: 	if ($type eq 'start') {
                    908: 	    $conjunction='at';
                    909: 	} elsif ($type eq 'end') {
                    910: 	    $conjunction='by';
                    911: 	}
                    912:         # Is it this year?
                    913: 	my $dt_now = DateTime->from_epoch(epoch => $now)
                    914: 	                     ->set_time_zone(&Apache::lonlocal::gettimezone());
                    915:         if ( $dt->year() == $dt_now->year()) {
                    916:             # Return on Month Day, HH:MM meridian
                    917:             my $timeStr = $dt->strftime("$conjunction %A, %b %e at %I:%M %P (%Z)");
                    918:             $timeStr =~ s/12:00 am/00:00/;
                    919:             $timeStr =~ s/12:00 pm/noon/;
                    920:             return $timeStr;
                    921:         }
1.59      bowersj2  922: 
1.416     jms       923:         # Not this year, so show the year
                    924:         my $timeStr = 
                    925: 	    $dt->strftime("$conjunction %A, %b %e %Y at %I:%M %P (%Z)");
                    926:         $timeStr =~ s/12:00 am/00:00/;
                    927:         $timeStr =~ s/12:00 pm/noon/;
                    928:         return $timeStr;
                    929:     }
                    930: }
1.59      bowersj2  931: 
                    932: 
1.133     bowersj2  933: sub resource { return 0; }
                    934: sub communication_status { return 1; }
                    935: sub quick_status { return 2; }
                    936: sub long_status { return 3; }
1.225     bowersj2  937: sub part_status_summary { return 4; }
1.51      bowersj2  938: 
1.133     bowersj2  939: sub render_resource {
                    940:     my ($resource, $part, $params) = @_;
1.51      bowersj2  941: 
1.477     raeburn   942:     my $editmapLink;
1.133     bowersj2  943:     my $nonLinkedText = ''; # stuff after resource title not in link
1.51      bowersj2  944: 
1.134     bowersj2  945:     my $link = $params->{"resourceLink"};
1.512     raeburn   946:     if ($resource->ext()) {
                    947:         $link =~ s/\#.+(\?)/$1/g;
                    948:     }
1.306     foxr      949: 
                    950:     #  The URL part is not escaped at this point, but the symb is... 
                    951: 
1.134     bowersj2  952:     my $src = $resource->src();
                    953:     my $it = $params->{"iterator"};
1.133     bowersj2  954:     my $filter = $it->{FILTER};
                    955: 
                    956:     my $title = $resource->compTitle();
1.258     albertel  957: 
1.133     bowersj2  958:     my $partLabel = "";
                    959:     my $newBranchText = "";
1.298     albertel  960:     my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
1.133     bowersj2  961:     # If this is a new branch, label it so
                    962:     if ($params->{'isNewBranch'}) {
1.429     droeschl  963:         $newBranchText = "<img src='$location/branch.gif' alt=".mt('Branch')." />";
1.51      bowersj2  964:     }
                    965: 
1.133     bowersj2  966:     # links to open and close the folder
1.306     foxr      967: 
1.427     droeschl  968:     my $whitespace = $location.'/whitespace_21.gif';
1.540     raeburn   969:     my $linkopen = "<img src='$whitespace' alt='' />";
                    970:     my $nomodal;
                    971:     if (($params->{'modalLink'}) && (!$resource->is_sequence())) {
                    972:         if ($link =~m{^(?:|/adm/wrapper)/ext/([^#]+)}) {
                    973:             my $exturl = $1;
                    974:             if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
                    975:                 $nomodal = 1;
                    976:             }
                    977:         } elsif (($link eq "/public/$LONCAPA::match_domain/$LONCAPA::match_courseid/syllabus") &&
                    978:                  ($env{'request.course.id'}) && ($ENV{'SERVER_PORT'} == 443) &&
                    979:                  ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
                    980:              $nomodal = 1;
                    981:         }
                    982:         my $esclink = &js_escape($link);
                    983:         if ($nomodal) {
                    984:             $linkopen .= "<a href=\"#\" onclick=\"javascript:window.open('$esclink','resourcepreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1'); return false;\" />";
                    985:         } else {
                    986:             $linkopen .= "<a href=\"$link\" onclick=\"javascript:openMyModal('$esclink',600,500,'yes','true'); return false;\">";
                    987:         }
                    988:     } else {
                    989:         $linkopen .= "<a href=\"$link\">";
                    990:     }
1.133     bowersj2  991:     my $linkclose = "</a>";
1.51      bowersj2  992: 
1.204     albertel  993:     # Default icon: unknown page
1.426     droeschl  994:     my $icon = "<img class=\"LC_contentImage\" src='$location/unknown.gif' alt='' />";
1.133     bowersj2  995:     
                    996:     if ($resource->is_problem()) {
1.192     bowersj2  997:         if ($part eq '0' || $params->{'condensed'}) {
1.426     droeschl  998: 	    $icon = '<img class="LC_contentImage" src="'.$location.'/';
1.389     albertel  999: 	    if ($resource->is_task()) {
                   1000: 		$icon .= 'task.gif" alt="'.&mt('Task');
                   1001: 	    } else {
                   1002: 		$icon .= 'problem.gif" alt="'.&mt('Problem');
                   1003: 	    }
1.426     droeschl 1004: 	    $icon .='" />';
1.133     bowersj2 1005:         } else {
                   1006:             $icon = $params->{'indentString'};
                   1007:         }
1.204     albertel 1008:     } else {
1.426     droeschl 1009: 	$icon = "<img class=\"LC_contentImage\" src='".&Apache::loncommon::icon($resource->src)."' alt='' />";
1.133     bowersj2 1010:     }
1.51      bowersj2 1011: 
1.133     bowersj2 1012:     # Display the correct map icon to open or shut map
                   1013:     if ($resource->is_map()) {
                   1014:         my $mapId = $resource->map_pc();
                   1015:         my $nowOpen = !defined($filter->{$mapId});
                   1016:         if ($it->{CONDITION}) {
                   1017:             $nowOpen = !$nowOpen;
                   1018:         }
1.426     droeschl 1019: 	
1.205     bowersj2 1020: 	my $folderType = $resource->is_sequence() ? 'folder' : 'page';
1.362     www      1021:         my $title=$resource->title;
1.426     droeschl 1022: 		$title=~s/\"/\&qout;/g;
1.144     bowersj2 1023:         if (!$params->{'resource_no_folder_link'}) {
1.205     bowersj2 1024:             $icon = "navmap.$folderType." . ($nowOpen ? 'closed' : 'open') . '.gif';
1.426     droeschl 1025:             $icon = "<img src='$location/arrow." . ($nowOpen ? 'closed' : 'open') . ".gif' alt='' />"
                   1026:                     ."<img class=\"LC_contentImage\" src='$location/$icon' alt=\""
                   1027:                     .($nowOpen ? &mt('Open Folder') : &mt('Close Folder')).' '.$title."\" />";			
1.349     foxr     1028:             $linkopen = "<a href=\"" . $params->{'url'} . '?' . 
1.392     albertel 1029:                 $params->{'queryString'} . '&amp;filter=';
1.144     bowersj2 1030:             $linkopen .= ($nowOpen xor $it->{CONDITION}) ?
                   1031:                 addToFilter($filter, $mapId) :
                   1032:                 removeFromFilter($filter, $mapId);
1.392     albertel 1033:             $linkopen .= "&amp;condition=" . $it->{CONDITION} . '&amp;hereType='
                   1034:                 . $params->{'hereType'} . '&amp;here=' .
1.384     www      1035:                 &escape($params->{'here'}) . 
1.392     albertel 1036:                 '&amp;jump=' .
1.384     www      1037:                 &escape($resource->symb()) . 
1.392     albertel 1038:                 "&amp;folderManip=1\">";
1.306     foxr     1039: 
1.144     bowersj2 1040:         } else {
                   1041:             # Don't allow users to manipulate folder
1.426     droeschl 1042:             $icon = "navmap.$folderType." . ($nowOpen ? 'closed' : 'open') . '.gif';
1.427     droeschl 1043:             $icon = "<img class=\"LC_space\" src='$whitespace' alt='' />"."<img class=\"LC_contentImage\" src='$location/$icon' alt=\"".($nowOpen ? &mt('Open Folder') : &mt('Close Folder')).' '.$title."\" />";
1.533     raeburn  1044:             if ($params->{'caller'} eq 'sequence') {
                   1045:                 $linkopen = "<a href=\"$link\">";
                   1046:             } else {
                   1047:                 $linkopen = "";
                   1048:                 $linkclose = "";
                   1049:             }
1.144     bowersj2 1050:         }
1.525     raeburn  1051:         if (((&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) ||
                   1052:               (&Apache::lonnet::allowed('cev',$env{'request.course.id'}))) &&
1.477     raeburn  1053:             ($resource->symb=~/\_\_\_[^\_]+\_\_\_uploaded/)) {
1.493     raeburn  1054:             if (!$params->{'map_no_edit_link'}) {
                   1055:                 my $icon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
                   1056:                 $editmapLink='&nbsp;'.
1.495     raeburn  1057:                          '<a href="/adm/coursedocs?command=directnav&amp;symb='.&escape($resource->symb()).'">'.
1.477     raeburn  1058:                          '<img src="'.$icon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
                   1059:                          '</a>';
1.493     raeburn  1060:             }
1.477     raeburn  1061:         }
1.518     raeburn  1062:         if ($params->{'mapHidden'} || $resource->randomout()) {
                   1063:             $nonLinkedText .= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
                   1064:         }
                   1065:     } else {
                   1066:         if ($resource->randomout()) {
                   1067:             $nonLinkedText .= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
                   1068:         }
1.133     bowersj2 1069:     }
1.342     albertel 1070:     if (!$resource->condval()) {
1.458     bisitz   1071:         $nonLinkedText .= ' <span class="LC_info">('.&mt('conditionally hidden').')</span> ';
1.342     albertel 1072:     }
1.413     www      1073:     if (($resource->is_practice()) && ($resource->is_raw_problem())) {
1.488     bisitz   1074:         $nonLinkedText .=' <span class="LC_info"><b>'.&mt('not graded').'</b></span>';
1.412     www      1075:     }
1.426     droeschl 1076: 
1.133     bowersj2 1077:     # We're done preparing and finally ready to start the rendering
1.426     droeschl 1078:     my $result = '<td class="LC_middle">';
                   1079:     my $newfolderType = $resource->is_sequence() ? 'folder' : 'page';
                   1080: 	
1.140     bowersj2 1081:     my $indentLevel = $params->{'indentLevel'};
                   1082:     if ($newBranchText) { $indentLevel--; }
                   1083: 
1.133     bowersj2 1084:     # print indentation
1.140     bowersj2 1085:     for (my $i = 0; $i < $indentLevel; $i++) {
1.133     bowersj2 1086:         $result .= $params->{'indentString'};
1.84      bowersj2 1087:     }
                   1088: 
1.133     bowersj2 1089:     # Decide what to display
                   1090:     $result .= "$newBranchText$linkopen$icon$linkclose";
                   1091:     
                   1092:     my $curMarkerBegin = '';
                   1093:     my $curMarkerEnd = '';
1.51      bowersj2 1094: 
1.133     bowersj2 1095:     # Is this the current resource?
1.158     bowersj2 1096:     if (!$params->{'displayedHereMarker'} && 
                   1097:         $resource->symb() eq $params->{'here'} ) {
1.477     raeburn  1098:         unless ($resource->is_map()) {
                   1099:             $curMarkerBegin = '<span class="LC_current_nav_location">';
                   1100:             $curMarkerEnd = '</span>';
                   1101:         }
1.424     schulted 1102: 	$params->{'displayedHereMarker'} = 1;
1.51      bowersj2 1103:     }
                   1104: 
1.192     bowersj2 1105:     if ($resource->is_problem() && $part ne '0' && 
1.133     bowersj2 1106:         !$params->{'condensed'}) {
1.274     matthew  1107: 	my $displaypart=$resource->part_display($part);
1.363     albertel 1108:         $partLabel = " (".&mt('Part: [_1]', $displaypart).")";
1.384     www      1109: 	if ($link!~/\#/) { $link.='#'.&escape($part); }
1.133     bowersj2 1110:         $title = "";
1.51      bowersj2 1111:     }
                   1112: 
1.163     bowersj2 1113:     if ($params->{'condensed'} && $resource->countParts() > 1) {
1.363     albertel 1114:         $nonLinkedText .= ' ('.&mt('[_1] parts', $resource->countParts()).')';
1.51      bowersj2 1115:     }
                   1116: 
1.266     raeburn  1117:     if (!$params->{'resource_nolink'} && !$resource->is_sequence() && !$resource->is_empty_sequence) {
1.540     raeburn  1118:         $linkclose = '</a>';
                   1119:         if ($params->{'modalLink'}) {
                   1120:             my $esclink = &js_escape($link);
                   1121:             if ($nomodal) {
                   1122:                 $linkopen = "<a href=\"#\" onclick=\"javascript:window.open('$esclink','resourcepreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1'); return false;\" />";
                   1123:             } else {
                   1124:                 $linkopen = "<a href=\"$link\" onclick=\"javascript:openMyModal('$esclink',600,500,'yes','true'); return false;\">";
                   1125:             }
                   1126:         } else {
                   1127:             $linkopen = "<a href=\"$link\">";
                   1128:         }
1.144     bowersj2 1129:     }
1.540     raeburn  1130:     $result .= "$curMarkerBegin$linkopen$title$partLabel$linkclose$curMarkerEnd$editmapLink$nonLinkedText</td>";
1.51      bowersj2 1131: 
1.133     bowersj2 1132:     return $result;
                   1133: }
1.51      bowersj2 1134: 
1.133     bowersj2 1135: sub render_communication_status {
                   1136:     my ($resource, $part, $params) = @_;
1.134     bowersj2 1137:     my $discussionHTML = ""; my $feedbackHTML = ""; my $errorHTML = "";
                   1138: 
                   1139:     my $link = $params->{"resourceLink"};
1.445     droeschl 1140:     my $linkopen = "<a href=\"$link\">";
1.134     bowersj2 1141:     my $linkclose = "</a>";
1.298     albertel 1142:     my $location=&Apache::loncommon::lonhttpdurl("/adm/lonMisc");
1.477     raeburn  1143: 
1.134     bowersj2 1144:     if ($resource->hasDiscussion()) {
                   1145:         $discussionHTML = $linkopen .
1.442     wenzelju 1146:             '<img alt="'.&mt('New Discussion').'" src="'.$location.'/chat.gif" title="'.&mt('New Discussion').'"/>' .
1.134     bowersj2 1147:             $linkclose;
                   1148:     }
                   1149:     
                   1150:     if ($resource->getFeedback()) {
                   1151:         my $feedback = $resource->getFeedback();
1.394     raeburn  1152:         foreach my $msgid (split(/\,/, $feedback)) {
                   1153:             if ($msgid) {
1.445     droeschl 1154:                 $feedbackHTML .= '&nbsp;<a href="/adm/email?display='
1.394     raeburn  1155:                     . &escape($msgid) . '">'
1.442     wenzelju 1156:                     . '<img alt="'.&mt('New E-mail').'" src="'.$location.'/feedback.gif" title="'.&mt('New E-mail').'"/></a>';
1.134     bowersj2 1157:             }
                   1158:         }
                   1159:     }
                   1160:     
                   1161:     if ($resource->getErrors()) {
                   1162:         my $errors = $resource->getErrors();
1.254     matthew  1163:         my $errorcount = 0;
1.394     raeburn  1164:         foreach my $msgid (split(/,/, $errors)) {
1.254     matthew  1165:             last if ($errorcount>=10); # Only output 10 bombs maximum
1.394     raeburn  1166:             if ($msgid) {
1.254     matthew  1167:                 $errorcount++;
1.445     droeschl 1168:                 $errorHTML .= '&nbsp;<a href="/adm/email?display='
1.394     raeburn  1169:                     . &escape($msgid) . '">'
1.442     wenzelju 1170:                     . '<img alt="'.&mt('New Error').'" src="'.$location.'/bomb.gif" title="'.&mt('New Error').'"/></a>';
1.134     bowersj2 1171:             }
                   1172:         }
1.197     bowersj2 1173:     }
                   1174: 
                   1175:     if ($params->{'multipart'} && $part != '0') {
                   1176: 	$discussionHTML = $feedbackHTML = $errorHTML = '';
1.134     bowersj2 1177:     }
1.426     droeschl 1178:     return "<td class=\"LC_middle\">$discussionHTML$feedbackHTML$errorHTML&nbsp;</td>";
1.134     bowersj2 1179: 
1.133     bowersj2 1180: }
                   1181: sub render_quick_status {
                   1182:     my ($resource, $part, $params) = @_;
1.135     bowersj2 1183:     my $result = "";
                   1184:     my $firstDisplayed = !$params->{'condensed'} && 
                   1185:         $params->{'multipart'} && $part eq "0";
                   1186: 
                   1187:     my $link = $params->{"resourceLink"};
1.445     droeschl 1188:     my $linkopen = "<a href=\"$link\">";
1.135     bowersj2 1189:     my $linkclose = "</a>";
1.426     droeschl 1190: 	
                   1191: 	$result .= '<td class="LC_middle">';
1.537     raeburn  1192:     if ($resource->is_gradable() &&
1.135     bowersj2 1193:         !$firstDisplayed) {
1.224     bowersj2 1194:         my $icon = $statusIconMap{$resource->simpleStatus($part)};
1.135     bowersj2 1195:         my $alt = $iconAltTags{$icon};
                   1196:         if ($icon) {
1.298     albertel 1197: 	    my $location=
                   1198: 		&Apache::loncommon::lonhttpdurl("/adm/lonIcons/$icon");
1.438     wenzelju 1199: 		$result .= $linkopen.'<img src="'.$location.'" alt="'.&mt($alt).'" title="'.&mt($alt).'" />'.$linkclose;            
1.135     bowersj2 1200:         } else {
1.426     droeschl 1201:             $result .= "&nbsp;";
1.135     bowersj2 1202:         }
                   1203:     } else { # not problem, no icon
1.426     droeschl 1204:         $result .= "&nbsp;";
1.135     bowersj2 1205:     }
1.426     droeschl 1206: 	$result .= "</td>\n";
1.135     bowersj2 1207:     return $result;
1.133     bowersj2 1208: }
                   1209: sub render_long_status {
                   1210:     my ($resource, $part, $params) = @_;
1.426     droeschl 1211:     my $result = '<td class="LC_middle LC_right">';
1.136     bowersj2 1212:     my $firstDisplayed = !$params->{'condensed'} && 
                   1213:         $params->{'multipart'} && $part eq "0";
                   1214:                 
                   1215:     my $color;
1.488     bisitz   1216:     my $info = '';
1.537     raeburn  1217:     if ($resource->is_gradable() || $resource->is_practice()) {
1.136     bowersj2 1218:         $color = $colormap{$resource->status};
1.502     raeburn  1219: 
                   1220:         if (dueInLessThan24Hours($resource, $part)) {
1.136     bowersj2 1221:             $color = $hurryUpColor;
1.488     bisitz   1222:             $info = ' title="'.&mt('Due in less than 24 hours!').'"';
1.502     raeburn  1223:         } elsif (lastTry($resource, $part)) {
                   1224:             unless (($resource->problemstatus($part) eq 'no') ||
                   1225:                     ($resource->problemstatus($part) eq 'no_feedback_ever')) {
                   1226:                 $color = $hurryUpColor;
                   1227:                 $info = ' title="'.&mt('One try remaining!').'"';
                   1228:             }
                   1229:          }
1.136     bowersj2 1230:     }
1.537     raeburn  1231: 
                   1232:     if (($resource->kind() eq "res") &&
                   1233:         ($resource->is_raw_problem() || $resource->is_gradable()) &&
1.463     raeburn  1234:         !$firstDisplayed) {
1.488     bisitz   1235:         if ($color) {$result .= '<span style="color:'.$color.'"'.$info.'><b>'; }
1.136     bowersj2 1236:         $result .= getDescription($resource, $part);
1.488     bisitz   1237:         if ($color) {$result .= "</b></span>"; }
1.136     bowersj2 1238:     }
1.402     albertel 1239:     if ($resource->is_map() && &advancedUser() && $resource->randompick()) {
1.400     albertel 1240:         $result .= &mt('(randomly select [_1])', $resource->randompick());
                   1241:     }
                   1242:     if ($resource->is_map() && &advancedUser() && $resource->randomorder()) {
                   1243:         $result .= &mt('(randomly ordered)');
1.136     bowersj2 1244:     }
1.210     bowersj2 1245: 
1.213     bowersj2 1246:     # Debugging code
                   1247:     #$result .= " " . $resource->awarded($part) . '/' . $resource->weight($part) .
                   1248:     #	' - Part: ' . $part;
                   1249: 
1.210     bowersj2 1250:     $result .= "</td>\n";
1.136     bowersj2 1251:     
                   1252:     return $result;
1.51      bowersj2 1253: }
                   1254: 
1.227     bowersj2 1255: # Colors obtained by taking the icons, matching the colors, and
                   1256: # possibly reducing the Value (HSV) of the color, if it's too bright
                   1257: # for text, generally by one third or so.
1.225     bowersj2 1258: my %statusColors = 
                   1259:     (
                   1260:      $resObj->CLOSED => '#000000',
1.227     bowersj2 1261:      $resObj->OPEN   => '#998b13',
                   1262:      $resObj->CORRECT => '#26933f',
                   1263:      $resObj->INCORRECT => '#c48207',
                   1264:      $resObj->ATTEMPTED => '#a87510',
1.225     bowersj2 1265:      $resObj->ERROR => '#000000'
                   1266:      );
                   1267: my %statusStrings = 
                   1268:     (
                   1269:      $resObj->CLOSED => 'Not yet open',
                   1270:      $resObj->OPEN   => 'Open',
                   1271:      $resObj->CORRECT => 'Correct',
                   1272:      $resObj->INCORRECT => 'Incorrect',
                   1273:      $resObj->ATTEMPTED => 'Attempted',
                   1274:      $resObj->ERROR => 'Network Error'
                   1275:      );
                   1276: my @statuses = ($resObj->CORRECT, $resObj->ATTEMPTED, $resObj->INCORRECT, $resObj->OPEN, $resObj->CLOSED, $resObj->ERROR);
                   1277: 
                   1278: sub render_parts_summary_status {
                   1279:     my ($resource, $part, $params) = @_;
1.537     raeburn  1280:     if (!$resource->is_gradable() && !$resource->contains_problem) { return '<td></td>'; }
1.225     bowersj2 1281:     if ($params->{showParts}) { 
                   1282: 	return '<td></td>';
                   1283:     }
                   1284: 
                   1285:     my $td = "<td align='right'>\n";
                   1286:     my $endtd = "</td>\n";
1.256     albertel 1287:     my @probs;
1.225     bowersj2 1288: 
1.256     albertel 1289:     if ($resource->contains_problem) {
                   1290: 	@probs=$resource->retrieveResources($resource,sub { $_[0]->is_problem() },1,0);
                   1291:     } else {
                   1292: 	@probs=($resource);
                   1293:     }
                   1294:     my $return;
                   1295:     my %overallstatus;
                   1296:     my $totalParts;
                   1297:     foreach my $resource (@probs) {
                   1298: 	# If there is a single part, just show the simple status
                   1299: 	if ($resource->singlepart()) {
                   1300: 	    my $status = $resource->simpleStatus(${$resource->parts}[0]);
                   1301: 	    $overallstatus{$status}++;
                   1302: 	    $totalParts++;
                   1303: 	    next;
                   1304: 	}
                   1305: 	# Now we can be sure the $part doesn't really matter.
                   1306: 	my $statusCount = $resource->simpleStatusCount();
                   1307: 	my @counts;
                   1308: 	foreach my $status (@statuses) {
                   1309: 	    # decouple display order from the simpleStatusCount order
                   1310: 	    my $slot = Apache::lonnavmaps::resource::statusToSlot($status);
                   1311: 	    if ($statusCount->[$slot]) {
                   1312: 		$overallstatus{$status}+=$statusCount->[$slot];
                   1313: 		$totalParts+=$statusCount->[$slot];
                   1314: 	    }
                   1315: 	}
                   1316:     }
                   1317:     $return.= $td . $totalParts . ' parts: ';
                   1318:     foreach my $status (@statuses) {
1.488     bisitz   1319:         if ($overallstatus{$status}) {
                   1320:             $return.='<span style="color:' . $statusColors{$status}
                   1321:                    . '">' . $overallstatus{$status} . ' '
                   1322:                    . $statusStrings{$status} . '</span>';
                   1323:         }
1.225     bowersj2 1324:     }
1.256     albertel 1325:     $return.= $endtd;
                   1326:     return $return;
1.225     bowersj2 1327: }
                   1328: 
1.133     bowersj2 1329: my @preparedColumns = (\&render_resource, \&render_communication_status,
1.225     bowersj2 1330:                        \&render_quick_status, \&render_long_status,
                   1331: 		       \&render_parts_summary_status);
1.132     bowersj2 1332: 
                   1333: sub setDefault {
                   1334:     my ($val, $default) = @_;
                   1335:     if (!defined($val)) { return $default; }
                   1336:     return $val;
                   1337: }
                   1338: 
1.296     albertel 1339: sub cmp_title {
                   1340:     my ($atitle,$btitle) = (lc($_[0]->compTitle),lc($_[1]->compTitle));
                   1341:     $atitle=~s/^\s*//;
                   1342:     $btitle=~s/^\s*//;
                   1343:     return $atitle cmp $btitle;
                   1344: }
                   1345: 
1.132     bowersj2 1346: sub render {
                   1347:     my $args = shift;
1.140     bowersj2 1348:     &Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});
                   1349:     my $result = '';
1.132     bowersj2 1350:     # Configure the renderer.
                   1351:     my $cols = $args->{'cols'};
                   1352:     if (!defined($cols)) {
                   1353:         # no columns, no nav maps.
                   1354:         return '';
                   1355:     }
1.140     bowersj2 1356:     my $navmap;
                   1357:     if (defined($args->{'navmap'})) {
                   1358:         $navmap = $args->{'navmap'};
                   1359:     }
                   1360: 
1.158     bowersj2 1361:     my $r = $args->{'r'};
1.140     bowersj2 1362:     my $queryString = $args->{'queryString'};
1.159     bowersj2 1363:     my $jump = $args->{'jump'};
1.158     bowersj2 1364:     my $here = $args->{'here'};
1.153     bowersj2 1365:     my $suppressNavmap = setDefault($args->{'suppressNavmap'}, 0);
1.256     albertel 1366:     my $closeAllPages = setDefault($args->{'closeAllPages'}, 0);
1.140     bowersj2 1367:     my $currentJumpDelta = 2; # change this to change how many resources are displayed
                   1368:                              # before the current resource when using #current
                   1369: 
                   1370:     # If we were passed 'here' information, we are not rendering
                   1371:     # after a folder manipulation, and we were not passed an
                   1372:     # iterator, make sure we open the folders to show the "here"
                   1373:     # marker
                   1374:     my $filterHash = {};
                   1375:     # Figure out what we're not displaying
1.394     raeburn  1376:     foreach my $item (split(/\,/, $env{"form.filter"})) {
                   1377:         if ($item) {
                   1378:             $filterHash->{$item} = "1";
1.140     bowersj2 1379:         }
                   1380:     }
                   1381: 
1.191     bowersj2 1382:     # Filter: Remember filter function and add our own filter: Refuse
                   1383:     # to show hidden resources unless the user can see them.
                   1384:     my $userCanSeeHidden = advancedUser();
                   1385:     my $filterFunc = setDefault($args->{'filterFunc'},
                   1386:                                 sub {return 1;});
                   1387:     if (!$userCanSeeHidden) {
                   1388:         # Without renaming the filterfunc, the server seems to go into
                   1389:         # an infinite loop
                   1390:         my $oldFilterFunc = $filterFunc;
                   1391:         $filterFunc = sub { my $res = shift; return !$res->randomout() && 
                   1392:                                 &$oldFilterFunc($res);};
                   1393:     }
                   1394: 
1.140     bowersj2 1395:     my $condition = 0;
1.320     albertel 1396:     if ($env{'form.condition'}) {
1.140     bowersj2 1397:         $condition = 1;
                   1398:     }
                   1399: 
1.320     albertel 1400:     if (!$env{'form.folderManip'} && !defined($args->{'iterator'})) {
1.140     bowersj2 1401:         # Step 1: Check to see if we have a navmap
                   1402:         if (!defined($navmap)) {
1.221     bowersj2 1403:             $navmap = Apache::lonnavmaps::navmap->new();
1.340     albertel 1404: 	    if (!defined($navmap)) {
1.423     raeburn  1405: 		# no longer in course
1.388     albertel 1406: 		return '<span class="LC_error">'.&mt('No course selected').'</span><br />
1.362     www      1407:                         <a href="/adm/roles">'.&mt('Select a course').'</a><br />';
1.340     albertel 1408: 	    }
                   1409: 	}
1.140     bowersj2 1410: 
                   1411:         # Step two: Locate what kind of here marker is necessary
                   1412:         # Determine where the "here" marker is and where the screen jumps to.
                   1413: 
1.332     albertel 1414:         if ($env{'form.postsymb'} ne '') {
1.320     albertel 1415:             $here = $jump = &Apache::lonnet::symbclean($env{'form.postsymb'});
1.332     albertel 1416:         } elsif ($env{'form.postdata'} ne '') {
1.140     bowersj2 1417:             # couldn't find a symb, is there a URL?
1.320     albertel 1418:             my $currenturl = $env{'form.postdata'};
1.158     bowersj2 1419:             #$currenturl=~s/^http\:\/\///;
                   1420:             #$currenturl=~s/^[^\/]+//;
1.533     raeburn  1421:             unless ($args->{'caller'} eq 'sequence') {
                   1422:                 $here = $jump = &Apache::lonnet::symbread($currenturl);
                   1423:             }
1.331     albertel 1424: 	}
1.533     raeburn  1425: 	if (($here eq '') && ($args->{'caller'} ne 'sequence')) {
1.317     albertel 1426: 	    my $last;
1.320     albertel 1427: 	    if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
1.317     albertel 1428:                     &GDBM_READER(),0640)) {
                   1429: 		$last=$hash{'last_known'};
                   1430: 		untie(%hash);
                   1431: 	    }
                   1432: 	    if ($last) { $here = $jump = $last; }
                   1433: 	}
1.158     bowersj2 1434: 
1.140     bowersj2 1435:         # Step three: Ensure the folders are open
                   1436:         my $mapIterator = $navmap->getIterator(undef, undef, undef, 1);
1.222     bowersj2 1437:         my $curRes;
1.140     bowersj2 1438:         my $found = 0;
                   1439:         
                   1440:         # We only need to do this if we need to open the maps to show the
                   1441:         # current position. This will change the counter so we can't count
                   1442:         # for the jump marker with this loop.
1.294     albertel 1443:         while ($here && ($curRes = $mapIterator->next()) && !$found) {
1.158     bowersj2 1444:             if (ref($curRes) && $curRes->symb() eq $here) {
1.140     bowersj2 1445:                 my $mapStack = $mapIterator->getStack();
                   1446:                 
                   1447:                 # Ensure the parent maps are open
                   1448:                 for my $map (@{$mapStack}) {
                   1449:                     if ($condition) {
                   1450:                         undef $filterHash->{$map->map_pc()};
                   1451:                     } else {
                   1452:                         $filterHash->{$map->map_pc()} = 1;
                   1453:                     }
                   1454:                 }
                   1455:                 $found = 1;
                   1456:             }
                   1457:         }            
1.159     bowersj2 1458:     }        
1.140     bowersj2 1459: 
1.320     albertel 1460:     if ( !defined($args->{'iterator'}) && $env{'form.folderManip'} ) { # we came from a user's manipulation of the nav page
1.140     bowersj2 1461:         # If this is a click on a folder or something, we want to preserve the "here"
                   1462:         # from the querystring, and get the new "jump" marker
1.320     albertel 1463:         $here = $env{'form.here'};
                   1464:         $jump = $env{'form.jump'};
1.140     bowersj2 1465:     } 
                   1466:     
1.132     bowersj2 1467:     my $it = $args->{'iterator'};
                   1468:     if (!defined($it)) {
1.320     albertel 1469:         # Construct a default iterator based on $env{'form.'} information
1.140     bowersj2 1470:         
                   1471:         # Step 1: Check to see if we have a navmap
                   1472:         if (!defined($navmap)) {
1.221     bowersj2 1473:             $navmap = Apache::lonnavmaps::navmap->new();
1.423     raeburn  1474:             if (!defined($navmap)) {
                   1475:                 # no longer in course
                   1476:                 return '<span class="LC_error">'.&mt('No course selected').'</span><br />
                   1477:                         <a href="/adm/roles">'.&mt('Select a course').'</a><br />';
                   1478:             }
1.140     bowersj2 1479:         }
                   1480: 
1.144     bowersj2 1481:         # See if we're being passed a specific map
                   1482:         if ($args->{'iterator_map'}) {
                   1483:             my $map = $args->{'iterator_map'};
1.145     bowersj2 1484:             $map = $navmap->getResourceByUrl($map);
1.144     bowersj2 1485:             my $firstResource = $map->map_start();
                   1486:             my $finishResource = $map->map_finish();
                   1487: 
                   1488:             $args->{'iterator'} = $it = $navmap->getIterator($firstResource, $finishResource, $filterHash, $condition);
                   1489:         } else {
1.401     albertel 1490:             $args->{'iterator'} = $it = $navmap->getIterator(undef, undef, $filterHash, $condition,undef,$args->{'include_top_level_map'});
1.144     bowersj2 1491:         }
1.132     bowersj2 1492:     }
1.256     albertel 1493: 
1.159     bowersj2 1494:     # (re-)Locate the jump point, if any
1.191     bowersj2 1495:     # Note this does not take filtering or hidden into account... need
                   1496:     # to be fixed?
1.159     bowersj2 1497:     my $mapIterator = $navmap->getIterator(undef, undef, $filterHash, 0);
1.222     bowersj2 1498:     my $curRes;
1.159     bowersj2 1499:     my $foundJump = 0;
                   1500:     my $counter = 0;
                   1501:     
1.222     bowersj2 1502:     while (($curRes = $mapIterator->next()) && !$foundJump) {
1.159     bowersj2 1503:         if (ref($curRes)) { $counter++; }
                   1504:         
                   1505:         if (ref($curRes) && $jump eq $curRes->symb()) {
                   1506:             
                   1507:             # This is why we have to use the main iterator instead of the
                   1508:             # potentially faster DFS: The count has to be the same, so
                   1509:             # the order has to be the same, which DFS won't give us.
                   1510:             $args->{'currentJumpIndex'} = $counter;
                   1511:             $foundJump = 1;
                   1512:         }
                   1513:     }
                   1514: 
1.132     bowersj2 1515:     my $showParts = setDefault($args->{'showParts'}, 1);
                   1516:     my $condenseParts = setDefault($args->{'condenseParts'}, 1);
1.139     bowersj2 1517:     # keeps track of when the current resource is found,
                   1518:     # so we can back up a few and put the anchor above the
                   1519:     # current resource
1.140     bowersj2 1520:     my $printKey = $args->{'printKey'};
                   1521:     my $printCloseAll = $args->{'printCloseAll'};
                   1522:     if (!defined($printCloseAll)) { $printCloseAll = 1; }
1.425     schulted 1523:    
1.140     bowersj2 1524:     # Print key?
                   1525:     if ($printKey) {
                   1526:         $result .= '<table border="0" cellpadding="2" cellspacing="0">';
                   1527:         $result.='<tr><td align="right" valign="bottom">Key:&nbsp;&nbsp;</td>';
1.298     albertel 1528: 	my $location=&Apache::loncommon::lonhttpdurl("/adm/lonMisc");
1.140     bowersj2 1529:         if ($navmap->{LAST_CHECK}) {
                   1530:             $result .= 
1.434     bisitz   1531:                 '<img src="'.$location.'/chat.gif" alt="" /> '.&mt('New discussion since').' '.
1.140     bowersj2 1532:                 strftime("%A, %b %e at %I:%M %P", localtime($navmap->{LAST_CHECK})).
                   1533:                 '</td><td align="center" valign="bottom">&nbsp;&nbsp;'.
1.434     bisitz   1534:                 '<img src="'.$location.'/feedback.gif" alt="" /> '.&mt('New message (click to open)').'<p>'.
1.140     bowersj2 1535:                 '</td>'; 
                   1536:         } else {
                   1537:             $result .= '<td align="center" valign="bottom">&nbsp;&nbsp;'.
1.434     bisitz   1538:                 '<img src="'.$location.'/chat.gif" alt="" /> '.&mt('Discussions').'</td><td align="center" valign="bottom">'.
                   1539:                 '&nbsp;&nbsp;<img src="'.$location.'/feedback.gif" alt="" /> '.&mt('New message (click to open)').
1.140     bowersj2 1540:                 '</td>'; 
                   1541:         }
                   1542: 
                   1543:         $result .= '</tr></table>';
                   1544:     }
                   1545: 
1.172     bowersj2 1546:     if ($printCloseAll && !$args->{'resource_no_folder_link'}) {
1.281     albertel 1547: 	my ($link,$text);
1.140     bowersj2 1548:         if ($condition) {
1.446     raeburn  1549: 	    $link='navmaps?condition=0&amp;filter=&amp;'.$queryString.
1.449     bisitz   1550: 		'&amp;here='.&escape($here);
1.377     www      1551: 	    $text='Close all folders';
1.140     bowersj2 1552:         } else {
1.446     raeburn  1553: 	    $link='navmaps?condition=1&amp;filter=&amp;'.$queryString.
1.449     bisitz   1554: 		'&amp;here='.&escape($here);
1.377     www      1555: 	    $text='Open all folders';
1.281     albertel 1556:         }
1.446     raeburn  1557:         if ($env{'form.register'}) {
                   1558:             $link .= '&amp;register='.$env{'form.register'};
                   1559:         }
1.281     albertel 1560: 	if ($args->{'caller'} eq 'navmapsdisplay') {
1.478     raeburn  1561:             unless ($args->{'notools'}) {
                   1562:                 &add_linkitem($args->{'linkitems'},'changefolder',
                   1563:                               "location.href='$link'",$text);
                   1564:             }
1.281     albertel 1565: 	} else {
1.446     raeburn  1566: 	    $result.= '<a href="'.$link.'">'.&mt($text).'</a>';
1.281     albertel 1567: 	}
1.266     raeburn  1568:         $result .= "\n";
                   1569:     }
1.140     bowersj2 1570: 
1.266     raeburn  1571:     # Check for any unread discussions in all resources.
1.478     raeburn  1572:     if (($args->{'caller'} eq 'navmapsdisplay') && (!$args->{'notools'})) {
1.296     albertel 1573: 	&add_linkitem($args->{'linkitems'},'clearbubbles',
                   1574: 		      'document.clearbubbles.submit()',
                   1575: 		      'Mark all posts read');
1.297     albertel 1576: 	my $time=time;
1.486     raeburn  1577:         my $querystr = &HTML::Entities::encode($ENV{'QUERY_STRING'},'<>&"');
1.296     albertel 1578: 	$result .= (<<END);
                   1579:     <form name="clearbubbles" method="post" action="/adm/feedback">
1.486     raeburn  1580: 	<input type="hidden" name="navurl" value="$querystr" />
1.297     albertel 1581: 	<input type="hidden" name="navtime" value="$time" />
1.296     albertel 1582: END
1.446     raeburn  1583:         if ($env{'form.register'}) {
                   1584:             $result .= '<input type="hidden" name="register" value="'.$env{'form.register'}.'" />';
                   1585:         }
1.296     albertel 1586:         if ($args->{'sort'} eq 'discussion') { 
                   1587: 	    my $totdisc = 0;
                   1588: 	    my $haveDisc = '';
                   1589: 	    my @allres=$navmap->retrieveResources();
                   1590: 	    foreach my $resource (@allres) {
                   1591: 		if ($resource->hasDiscussion()) {
1.323     albertel 1592: 		    $haveDisc .= $resource->wrap_symb().':';
1.296     albertel 1593: 		    $totdisc ++;
1.267     albertel 1594: 		}
                   1595: 	    }
1.296     albertel 1596: 	    if ($totdisc > 0) {
                   1597: 		$haveDisc =~ s/:$//;
                   1598: 		$result .= (<<END);
                   1599: 	<input type="hidden" name="navmaps" value="$haveDisc" />
                   1600:     </form>
                   1601: END
                   1602:             }
1.297     albertel 1603: 	}
                   1604: 	$result.='</form>';
1.478     raeburn  1605:     }
                   1606:     if (($args->{'caller'} eq 'navmapsdisplay') &&
1.525     raeburn  1607:         ((&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) ||
                   1608:          (&Apache::lonnet::allowed('cev',$env{'request.course.id'})))) {
1.478     raeburn  1609:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   1610:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   1611:         if ($env{'course.'.$env{'request.course.id'}.'.url'} eq 
                   1612:             "uploaded/$cdom/$cnum/default.sequence") {
                   1613:             &add_linkitem($args->{'linkitems'},'edittoplevel',
                   1614:                           "javascript:gocmd('/adm/coursedocs','editdocs');",
                   1615:                           'Content Editor');
1.475     raeburn  1616:         }
1.266     raeburn  1617:     }
1.276     albertel 1618: 
1.281     albertel 1619:     if ($args->{'caller'} eq 'navmapsdisplay') {
1.476     raeburn  1620:         $result .= &show_linkitems_toolbar($args,$condition);
1.281     albertel 1621:     } elsif ($args->{'sort_html'}) { 
                   1622:         $result.=$args->{'sort_html'}; 
                   1623:     }
1.276     albertel 1624: 
1.425     schulted 1625:     #$result .= "<br />\n";
1.140     bowersj2 1626:     if ($r) {
                   1627:         $r->print($result);
                   1628:         $r->rflush();
                   1629:         $result = "";
                   1630:     }
1.132     bowersj2 1631:     # End parameter setting
1.425     schulted 1632:     
                   1633:     $result .= "<br />\n";
                   1634: 
1.132     bowersj2 1635:     # Data
1.431     schulted 1636:     $result.=&Apache::loncommon::start_data_table("LC_tableOfContent");    
1.426     droeschl 1637: 
1.132     bowersj2 1638:     my $res = "Apache::lonnavmaps::resource";
                   1639:     my %condenseStatuses =
                   1640:         ( $res->NETWORK_FAILURE    => 1,
                   1641:           $res->NOTHING_SET        => 1,
                   1642:           $res->CORRECT            => 1 );
1.133     bowersj2 1643: 
                   1644:     # Shared variables
                   1645:     $args->{'counter'} = 0; # counts the rows
                   1646:     $args->{'indentLevel'} = 0;
                   1647:     $args->{'isNewBranch'} = 0;
1.426     droeschl 1648:     $args->{'condensed'} = 0;   
                   1649: 
1.428     droeschl 1650:     my $location = &Apache::loncommon::lonhttpdurl("/adm/lonIcons/whitespace_21.gif");
1.426     droeschl 1651:     $args->{'indentString'} = setDefault($args->{'indentString'}, "<img src='$location' alt='' />");
1.133     bowersj2 1652:     $args->{'displayedHereMarker'} = 0;
1.132     bowersj2 1653: 
1.518     raeburn  1654:     # If we're suppressing empty sequences, look for them here.
                   1655:     # We also do this even if $args->{'suppressEmptySequences'}
                   1656:     # is not true, so we can hide empty sequences for which the
                   1657:     # hiddenresource parameter is set to yes (at map level), or
                   1658:     # mark as hidden for users who have $userCanSeeHidden.  
                   1659:     # Use DFS for speed, since structure actually doesn't matter,
                   1660:     # except what map has what resources.
                   1661: 
                   1662:     my $dfsit = Apache::lonnavmaps::DFSiterator->new($navmap,
                   1663:                                                      $it->{FIRST_RESOURCE},
                   1664:                                                      $it->{FINISH_RESOURCE},
                   1665:                                                      {}, undef, 1);
                   1666:     my $depth = 0;
                   1667:     $dfsit->next();
                   1668:     my $curRes = $dfsit->next();
                   1669:     while ($depth > -1) {
                   1670:         if ($curRes == $dfsit->BEGIN_MAP()) { $depth++; }
                   1671:         if ($curRes == $dfsit->END_MAP()) { $depth--; }
                   1672: 
                   1673:         if (ref($curRes)) { 
                   1674:             # Parallel pre-processing: Do sequences have non-filtered-out children?
                   1675:             if ($curRes->is_map()) {
                   1676:                 $curRes->{DATA}->{HAS_VISIBLE_CHILDREN} = 0;
                   1677:                 # Sequences themselves do not count as visible children,
                   1678:                 # unless those sequences also have visible children.
                   1679:                 # This means if a sequence appears, there's a "promise"
                   1680:                 # that there's something under it if you open it, somewhere.
                   1681:             } elsif ($curRes->src()) {
                   1682:                 # Not a sequence: if it's filtered, ignore it, otherwise
                   1683:                 # rise up the stack and mark the sequences as having children
                   1684:                 if (&$filterFunc($curRes)) {
                   1685:                     for my $sequence (@{$dfsit->getStack()}) {
                   1686:                         $sequence->{DATA}->{HAS_VISIBLE_CHILDREN} = 1;
1.190     bowersj2 1687:                     }
                   1688:                 }
                   1689:             }
                   1690:         }
1.518     raeburn  1691:     } continue {
                   1692:         $curRes = $dfsit->next();
1.190     bowersj2 1693:     }
                   1694: 
1.133     bowersj2 1695:     my $displayedJumpMarker = 0;
1.132     bowersj2 1696:     # Set up iteration.
                   1697:     my $now = time();
                   1698:     my $in24Hours = $now + 24 * 60 * 60;
                   1699:     my $rownum = 0;
                   1700: 
1.141     bowersj2 1701:     # export "here" marker information
                   1702:     $args->{'here'} = $here;
                   1703: 
1.222     bowersj2 1704:     $args->{'indentLevel'} = -1; # first BEGIN_MAP takes this to 0
1.270     albertel 1705:     my @resources;
                   1706:     my $code='';# sub { !(shift->is_map();) };
                   1707:     if ($args->{'sort'} eq 'title') {
1.276     albertel 1708:         my $oldFilterFunc = $filterFunc;
                   1709: 	my $filterFunc= 
                   1710: 	    sub {
                   1711: 		my ($res)=@_;
                   1712: 		if ($res->is_map()) { return 0;}
                   1713: 		return &$oldFilterFunc($res);
                   1714: 	    };
                   1715: 	@resources=$navmap->retrieveResources(undef,$filterFunc);
1.296     albertel 1716: 	@resources= sort { &cmp_title($a,$b) } @resources;
                   1717:     } elsif ($args->{'sort'} eq 'duedate') {
                   1718: 	my $oldFilterFunc = $filterFunc;
                   1719: 	my $filterFunc= 
                   1720: 	    sub {
                   1721: 		my ($res)=@_;
                   1722: 		if (!$res->is_problem()) { return 0;}
                   1723: 		return &$oldFilterFunc($res);
                   1724: 	    };
                   1725: 	@resources=$navmap->retrieveResources(undef,$filterFunc);
1.289     raeburn  1726: 	@resources= sort {
1.270     albertel 1727: 	    if ($a->duedate ne $b->duedate) {
                   1728: 	        return $a->duedate cmp $b->duedate;
                   1729: 	    }
1.296     albertel 1730: 	    my $value=&cmp_title($a,$b);
                   1731: 	    return $value;
1.270     albertel 1732: 	} @resources;
1.296     albertel 1733:     } elsif ($args->{'sort'} eq 'discussion') {
                   1734: 	my $oldFilterFunc = $filterFunc;
                   1735: 	my $filterFunc= 
                   1736: 	    sub {
                   1737: 		my ($res)=@_;
                   1738: 		if (!$res->hasDiscussion() &&
                   1739: 		    !$res->getFeedback() &&
                   1740: 		    !$res->getErrors()) { return 0;}
                   1741: 		return &$oldFilterFunc($res);
                   1742: 	    };
                   1743: 	@resources=$navmap->retrieveResources(undef,$filterFunc);
                   1744: 	@resources= sort { &cmp_title($a,$b) } @resources;
1.276     albertel 1745:     } else {
                   1746: 	#unknow sort mechanism or default
                   1747: 	undef($args->{'sort'});
1.270     albertel 1748:     }
                   1749: 
1.527     raeburn  1750:     # Determine if page will be served with https in case
                   1751:     # it contains a syllabus which uses an external URL
                   1752:     # which points at an http site.
                   1753: 
1.529     raeburn  1754:     my ($is_ssl,$cdom,$cnum,$hostname);
1.527     raeburn  1755:     if ($ENV{'SERVER_PORT'} == 443) {
                   1756:         $is_ssl = 1;
1.530     raeburn  1757:         if ($r) {
                   1758:             $hostname = $r->hostname();
                   1759:         } else {
                   1760:             $hostname = $ENV{'SERVER_NAME'};
                   1761:         }
1.527     raeburn  1762:     }
                   1763:     if ($env{'request.course.id'}) {
                   1764:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   1765:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   1766:     }
1.276     albertel 1767: 
1.540     raeburn  1768:     my $inhibitmenu;
                   1769:     if ($args->{'modalLink'}) {
                   1770:         $inhibitmenu = '&amp;inhibitmenu=yes';
                   1771:     }
                   1772: 
1.270     albertel 1773:     while (1) {
                   1774: 	if ($args->{'sort'}) {
                   1775: 	    $curRes = shift(@resources);
                   1776: 	} else {
                   1777: 	    $curRes = $it->next($closeAllPages);
                   1778: 	}
                   1779: 	if (!$curRes) { last; }
                   1780: 
1.132     bowersj2 1781:         # Maintain indentation level.
                   1782:         if ($curRes == $it->BEGIN_MAP() ||
                   1783:             $curRes == $it->BEGIN_BRANCH() ) {
1.133     bowersj2 1784:             $args->{'indentLevel'}++;
1.132     bowersj2 1785:         }
                   1786:         if ($curRes == $it->END_MAP() ||
                   1787:             $curRes == $it->END_BRANCH() ) {
1.133     bowersj2 1788:             $args->{'indentLevel'}--;
1.132     bowersj2 1789:         }
                   1790:         # Notice new branches
                   1791:         if ($curRes == $it->BEGIN_BRANCH()) {
1.133     bowersj2 1792:             $args->{'isNewBranch'} = 1;
                   1793:         }
                   1794: 
                   1795:         # If this isn't an actual resource, continue on
                   1796:         if (!ref($curRes)) {
                   1797:             next;
1.132     bowersj2 1798:         }
1.133     bowersj2 1799: 
1.143     bowersj2 1800:         # If this has been filtered out, continue on
                   1801:         if (!(&$filterFunc($curRes))) {
                   1802:             $args->{'isNewBranch'} = 0; # Don't falsely remember this
                   1803:             next;
                   1804:         } 
1.132     bowersj2 1805: 
1.190     bowersj2 1806:         # If this is an empty sequence and we're filtering them, continue on
1.518     raeburn  1807:         $args->{'mapHidden'} = 0;
                   1808:         if (($curRes->is_map()) && (!$curRes->{DATA}->{HAS_VISIBLE_CHILDREN})) {
                   1809:             if ($args->{'suppressEmptySequences'}) {
                   1810:                 next;
                   1811:             } else {
                   1812:                 my $mapname = &Apache::lonnet::declutter($curRes->src());
                   1813:                 $mapname = &Apache::lonnet::deversion($mapname); 
                   1814:                 if (lc($navmap->get_mapparam(undef,$mapname,"0.hiddenresource")) eq 'yes') {
                   1815:                     if ($userCanSeeHidden) {
                   1816:                         $args->{'mapHidden'} = 1;
                   1817:                     } else {
                   1818:                         next;
                   1819:                     }
                   1820:                 }
                   1821:             }
1.190     bowersj2 1822:         }
                   1823: 
1.153     bowersj2 1824:         # If we're suppressing navmaps and this is a navmap, continue on
                   1825:         if ($suppressNavmap && $curRes->src() =~ /^\/adm\/navmaps/) {
                   1826:             next;
                   1827:         }
                   1828: 
1.191     bowersj2 1829:         $args->{'counter'}++;
                   1830: 
1.132     bowersj2 1831:         # Does it have multiple parts?
1.133     bowersj2 1832:         $args->{'multipart'} = 0;
                   1833:         $args->{'condensed'} = 0;
1.132     bowersj2 1834:         my @parts;
                   1835:             
                   1836:         # Decide what parts to show.
1.133     bowersj2 1837:         if ($curRes->is_problem() && $showParts) {
1.132     bowersj2 1838:             @parts = @{$curRes->parts()};
1.192     bowersj2 1839:             $args->{'multipart'} = $curRes->multipart();
1.132     bowersj2 1840:             
                   1841:             if ($condenseParts) { # do the condensation
1.133     bowersj2 1842:                 if (!$args->{'condensed'}) {
1.132     bowersj2 1843:                     # Decide whether to condense based on similarity
1.192     bowersj2 1844:                     my $status = $curRes->status($parts[0]);
                   1845:                     my $due = $curRes->duedate($parts[0]);
                   1846:                     my $open = $curRes->opendate($parts[0]);
1.132     bowersj2 1847:                     my $statusAllSame = 1;
                   1848:                     my $dueAllSame = 1;
                   1849:                     my $openAllSame = 1;
1.192     bowersj2 1850:                     for (my $i = 1; $i < scalar(@parts); $i++) {
1.132     bowersj2 1851:                         if ($curRes->status($parts[$i]) != $status){
                   1852:                             $statusAllSame = 0;
                   1853:                         }
                   1854:                         if ($curRes->duedate($parts[$i]) != $due ) {
                   1855:                             $dueAllSame = 0;
                   1856:                         }
                   1857:                         if ($curRes->opendate($parts[$i]) != $open) {
                   1858:                             $openAllSame = 0;
                   1859:                         }
                   1860:                     }
                   1861:                     # $*allSame is true if all the statuses were
                   1862:                     # the same. Now, if they are all the same and
                   1863:                     # match one of the statuses to condense, or they
                   1864:                     # are all open with the same due date, or they are
                   1865:                     # all OPEN_LATER with the same open date, display the
                   1866:                     # status of the first non-zero part (to get the 'correct'
                   1867:                     # status right, since 0 is never 'correct' or 'open').
                   1868:                     if (($statusAllSame && defined($condenseStatuses{$status})) ||
                   1869:                         ($dueAllSame && $status == $curRes->OPEN && $statusAllSame)||
                   1870:                         ($openAllSame && $status == $curRes->OPEN_LATER && $statusAllSame) ){
1.192     bowersj2 1871:                         @parts = ($parts[0]);
1.133     bowersj2 1872:                         $args->{'condensed'} = 1;
1.132     bowersj2 1873:                     }
                   1874:                 }
1.198     bowersj2 1875: 		# Multipart problem with one part: always "condense" (happens
                   1876: 		#  to match the desirable behavior)
                   1877: 		if ($curRes->countParts() == 1) {
                   1878: 		    @parts = ($parts[0]);
                   1879: 		    $args->{'condensed'} = 1;
                   1880: 		}
1.132     bowersj2 1881:             }
1.157     bowersj2 1882:         } 
1.132     bowersj2 1883:             
                   1884:         # If the multipart problem was condensed, "forget" it was multipart
                   1885:         if (scalar(@parts) == 1) {
1.133     bowersj2 1886:             $args->{'multipart'} = 0;
1.192     bowersj2 1887:         } else {
                   1888:             # Add part 0 so we display it correctly.
                   1889:             unshift @parts, '0';
1.132     bowersj2 1890:         }
1.310     albertel 1891: 	
                   1892: 	{
                   1893: 	    my ($src,$symb,$anchor,$stack);
                   1894: 	    if ($args->{'sort'}) {
                   1895: 		my $it = $navmap->getIterator(undef, undef, undef, 1);
                   1896: 		while ( my $res=$it->next()) {
                   1897: 		    if (ref($res) &&
                   1898: 			$res->symb() eq  $curRes->symb()) { last; }
                   1899: 		}
                   1900: 		$stack=$it->getStack();
                   1901: 	    } else {
                   1902: 		$stack=$it->getStack();
                   1903: 	    }
                   1904: 	    ($src,$symb,$anchor)=getLinkForResource($stack);
1.527     raeburn  1905:             my $srcHasQuestion = $src =~ /\?/;
                   1906:             if ($env{'request.course.id'}) {
1.529     raeburn  1907:                 if (($is_ssl) && ($src =~ m{^\Q/public/$cdom/$cnum/syllabus\E($|\?)}) &&
1.527     raeburn  1908:                     ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.528     raeburn  1909:                     if ($hostname ne '') {
                   1910:                         $src = 'http://'.$hostname.$src;
                   1911:                     }
1.527     raeburn  1912:                     $src .= ($srcHasQuestion? '&amp;' : '?') . 'usehttp=1';
                   1913:                     $srcHasQuestion = 1;
1.529     raeburn  1914:                 } elsif (($is_ssl) && ($src =~ m{^\Q/adm/wrapper/ext/\E(?!https:)})) {
                   1915:                     if ($hostname ne '') {
                   1916:                         $src = 'http://'.$hostname.$src;
                   1917:                     }
1.527     raeburn  1918:                 }
                   1919:             }
1.310     albertel 1920: 	    if (defined($anchor)) { $anchor='#'.$anchor; }
1.533     raeburn  1921: 	    if (($args->{'caller'} eq 'sequence') && ($curRes->is_map())) {
                   1922: 	        $args->{"resourceLink"} = $src.($srcHasQuestion?'&amp;':'?') .'navmap=1';
                   1923: 	    } else {
                   1924: 	        $args->{"resourceLink"} = $src.
                   1925: 		    ($srcHasQuestion?'&amp;':'?') .
1.540     raeburn  1926: 		    'symb=' . &escape($symb).$inhibitmenu.$anchor;
1.533     raeburn  1927: 	    }
1.310     albertel 1928: 	}
1.132     bowersj2 1929:         # Now, we've decided what parts to show. Loop through them and
                   1930:         # show them.
1.192     bowersj2 1931:         foreach my $part (@parts) {
1.132     bowersj2 1932:             $rownum ++;
                   1933:             
1.431     schulted 1934:             $result .= &Apache::loncommon::start_data_table_row();
1.134     bowersj2 1935: 
                   1936:             # Set up some data about the parts that the cols might want
                   1937:             my $filter = $it->{FILTER};
1.270     albertel 1938: 
1.132     bowersj2 1939:             # Now, display each column.
                   1940:             foreach my $col (@$cols) {
1.139     bowersj2 1941:                 my $colHTML = '';
                   1942:                 if (ref($col)) {
                   1943:                     $colHTML .= &$col($curRes, $part, $args);
                   1944:                 } else {
                   1945:                     $colHTML .= &{$preparedColumns[$col]}($curRes, $part, $args);
                   1946:                 }
1.132     bowersj2 1947: 
1.133     bowersj2 1948:                 # If this is the first column and it's time to print
                   1949:                 # the anchor, do so
                   1950:                 if ($col == $cols->[0] && 
                   1951:                     $args->{'counter'} == $args->{'currentJumpIndex'} - 
1.139     bowersj2 1952:                     $currentJumpDelta) {
                   1953:                     # Jam the anchor after the <td> tag;
                   1954:                     # necessary for valid HTML (which Mozilla requires)
                   1955:                     $colHTML =~ s/\>/\>\<a name="curloc" \/\>/;
1.133     bowersj2 1956:                     $displayedJumpMarker = 1;
                   1957:                 }
1.139     bowersj2 1958:                 $result .= $colHTML . "\n";
1.132     bowersj2 1959:             }
1.431     schulted 1960:             $result .= &Apache::loncommon::end_data_table_row();
1.140     bowersj2 1961:             $args->{'isNewBranch'} = 0;
1.139     bowersj2 1962:         }
1.153     bowersj2 1963: 
1.139     bowersj2 1964:         if ($r && $rownum % 20 == 0) {
                   1965:             $r->print($result);
                   1966:             $result = "";
                   1967:             $r->rflush();
1.132     bowersj2 1968:         }
1.156     bowersj2 1969:     } continue {
1.208     bowersj2 1970: 	if ($r) {
                   1971: 	    # If we have the connection, make sure the user is still connected
                   1972: 	    my $c = $r->connection;
                   1973: 	    if ($c->aborted()) {
                   1974: 		# Who cares what we do, nobody will see it anyhow.
                   1975: 		return '';
                   1976: 	    }
                   1977: 	}
1.132     bowersj2 1978:     }
1.486     raeburn  1979: 
                   1980:     $result.=&Apache::loncommon::end_data_table();
1.132     bowersj2 1981:     
1.134     bowersj2 1982:     # Print out the part that jumps to #curloc if it exists
1.159     bowersj2 1983:     # delay needed because the browser is processing the jump before
                   1984:     # it finishes rendering, so it goes to the wrong place!
                   1985:     # onload might be better, but this routine has no access to that.
                   1986:     # On mozilla, the 0-millisecond timeout seems to prevent this;
                   1987:     # it's quite likely this might fix other browsers, too, and 
                   1988:     # certainly won't hurt anything.
1.139     bowersj2 1989:     if ($displayedJumpMarker) {
1.449     bisitz   1990:         $result .= &Apache::lonhtmlcommon::scripttag("
1.247     albertel 1991: if (location.href.indexOf('#curloc')==-1) {
                   1992:     setTimeout(\"location += '#curloc';\", 0)
                   1993: }
1.449     bisitz   1994: ");
1.134     bowersj2 1995:     }
                   1996: 
1.140     bowersj2 1997:     if ($r) {
                   1998:         $r->print($result);
                   1999:         $result = "";
                   2000:         $r->rflush();
                   2001:     }
                   2002:         
1.132     bowersj2 2003:     return $result;
                   2004: }
                   2005: 
1.281     albertel 2006: sub add_linkitem {
                   2007:     my ($linkitems,$name,$cmd,$text)=@_;
                   2008:     $$linkitems{$name}{'cmd'}=$cmd;
                   2009:     $$linkitems{$name}{'text'}=&mt($text);
                   2010: }
                   2011: 
1.430     schulted 2012: sub show_linkitems_toolbar {
1.476     raeburn  2013:     my ($args,$condition) = @_;
1.478     raeburn  2014:     my $result;
1.476     raeburn  2015:     if (ref($args) eq 'HASH') {
                   2016:         if (ref($args->{'linkitems'}) eq 'HASH') {
1.478     raeburn  2017:             my $numlinks = scalar(keys(%{$args->{'linkitems'}}));
                   2018:             if ($numlinks > 1) {
                   2019:                 $result = '<td>'.
                   2020:                           &Apache::loncommon::help_open_menu('Navigation Screen','Navigation_Screen',
                   2021:                                                              undef,'RAT').
                   2022:                           '</td>'.
                   2023:                           '<td>&nbsp;</td>'.
                   2024:                           '<td class="LC_middle">'.&mt('Tools:').'</td>';
                   2025:             }
                   2026:             $result .= '<td align="left">'."\n".
                   2027:                        '<ul id="LC_toolbar">';
1.476     raeburn  2028:             my @linkorder = ('firsthomework','everything','uncompleted',
                   2029:                              'changefolder','clearbubbles','edittoplevel');
                   2030:             foreach my $link (@linkorder) {
                   2031:                 if (ref($args->{'linkitems'}{$link}) eq 'HASH') {
                   2032:                     if ($args->{'linkitems'}{$link}{'text'} ne '') {
                   2033:                         $args->{'linkitems'}{$link}{'cmd'}=~s/"/'/g;
                   2034:                         if ($args->{'linkitems'}{$link}{'cmd'}) {
1.478     raeburn  2035:                             my $link_id = 'LC_content_toolbar_'.$link;
1.476     raeburn  2036:                             if ($link eq 'changefolder') {
                   2037:                                 if ($condition) {
                   2038:                                     $link_id='LC_content_toolbar_changefolder_toggled';
                   2039:                                 } else {
                   2040:                                     $link_id='LC_content_toolbar_changefolder';
                   2041:                                 }
                   2042:                             }
                   2043:                             $result .= '<li><a href="#" '.
                   2044:                                        'onclick="'.$args->{'linkitems'}{$link}{'cmd'}.'" '.
                   2045:                                        'id="'.$link_id.'" '.
                   2046:                                        'class="LC_toolbarItem" '.
                   2047:                                        'title="'.$args->{'linkitems'}{$link}{'text'}.'">'.
                   2048:                                        '</a></li>'."\n";
1.446     raeburn  2049:                         }
                   2050:                     }
                   2051:                 }
                   2052:             }
1.476     raeburn  2053:             $result .= '</ul>'.
1.486     raeburn  2054:                        '</td>';
1.478     raeburn  2055:             if (($numlinks==1) && (exists($args->{'linkitems'}{'edittoplevel'}))) {
                   2056:                 $result .= '<td><a href="'.$args->{'linkitems'}{'edittoplevel'}{'cmd'}.'">'.
                   2057:                            &mt('Content Editor').'</a></td>';
                   2058:             }
1.476     raeburn  2059:         }
                   2060:         if ($args->{'sort_html'}) {
                   2061:             $result .= '<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>'.
                   2062:                        '<td align="right">'.$args->{'sort_html'}.'</td>';
1.446     raeburn  2063:         }
1.430     schulted 2064:     }
1.478     raeburn  2065:     if ($result) {
                   2066:         $result = "<table><tr>$result</tr></table>";
                   2067:     }
1.430     schulted 2068:     return $result;
                   2069: }
                   2070: 
1.133     bowersj2 2071: 1;
                   2072: 
1.418     jms      2073: 
                   2074: 
                   2075: 
                   2076: 
                   2077: 
                   2078: 
                   2079: 
                   2080: 
1.133     bowersj2 2081: package Apache::lonnavmaps::navmap;
                   2082: 
                   2083: =pod
                   2084: 
1.216     bowersj2 2085: =head1 Object: Apache::lonnavmaps::navmap
1.133     bowersj2 2086: 
1.217     bowersj2 2087: =head2 Overview
1.133     bowersj2 2088: 
1.217     bowersj2 2089: The navmap object's job is to provide access to the resources
                   2090: in the course as Apache::lonnavmaps::resource objects, and to
                   2091: query and manage the relationship between those resource objects.
                   2092: 
                   2093: Generally, you'll use the navmap object in one of three basic ways.
                   2094: In order of increasing complexity and power:
                   2095: 
                   2096: =over 4
                   2097: 
1.358     albertel 2098: =item * C<$navmap-E<gt>getByX>, where X is B<Id>, B<Symb> or B<MapPc> and getResourceByUrl. This provides
1.217     bowersj2 2099:     various ways to obtain resource objects, based on various identifiers.
                   2100:     Use this when you want to request information about one object or 
                   2101:     a handful of resources you already know the identities of, from some
                   2102:     other source. For more about Ids, Symbs, and MapPcs, see the
                   2103:     Resource documentation. Note that Url should be a B<last resort>,
1.358     albertel 2104:     not your first choice; it only really works when there is only one
1.217     bowersj2 2105:     instance of the resource in the course, which only applies to
1.358     albertel 2106:     maps, and even that may change in the future (see the B<getResourceByUrl>
                   2107:     documentation for more details.)
1.217     bowersj2 2108: 
                   2109: =item * C<my @resources = $navmap-E<gt>retrieveResources(args)>. This
                   2110:     retrieves resources matching some criterion and returns them
                   2111:     in a flat array, with no structure information. Use this when
                   2112:     you are manipulating a series of resources, based on what map
                   2113:     the are in, but do not care about branching, or exactly how
                   2114:     the maps and resources are related. This is the most common case.
                   2115: 
                   2116: =item * C<$it = $navmap-E<gt>getIterator(args)>. This allows you traverse
                   2117:     the course's navmap in various ways without writing the traversal
                   2118:     code yourself. See iterator documentation below. Use this when
                   2119:     you need to know absolutely everything about the course, including
                   2120:     branches and the precise relationship between maps and resources.
                   2121: 
                   2122: =back
                   2123: 
                   2124: =head2 Creation And Destruction
                   2125: 
                   2126: To create a navmap object, use the following function:
1.133     bowersj2 2127: 
                   2128: =over 4
                   2129: 
1.221     bowersj2 2130: =item * B<Apache::lonnavmaps::navmap-E<gt>new>():
1.133     bowersj2 2131: 
1.221     bowersj2 2132: Creates a new navmap object. Returns the navmap object if this is
                   2133: successful, or B<undef> if not.
1.174     albertel 2134: 
1.216     bowersj2 2135: =back
                   2136: 
                   2137: =head2 Methods
                   2138: 
                   2139: =over 4
                   2140: 
1.174     albertel 2141: =item * B<getIterator>(first, finish, filter, condition):
                   2142: 
                   2143: See iterator documentation below.
1.133     bowersj2 2144: 
                   2145: =cut
                   2146: 
                   2147: use strict;
                   2148: use GDBM_File;
1.320     albertel 2149: use Apache::lonnet;
1.397     albertel 2150: use LONCAPA;
1.133     bowersj2 2151: 
                   2152: sub new {
                   2153:     # magic invocation to create a class instance
                   2154:     my $proto = shift;
                   2155:     my $class = ref($proto) || $proto;
                   2156:     my $self = {};
1.501     raeburn  2157:     bless($self);		# So we can call change_user if necessary
1.133     bowersj2 2158: 
1.453     www      2159:     $self->{USERNAME} = shift || $env{'user.name'};
                   2160:     $self->{DOMAIN}   = shift || $env{'user.domain'};
1.491     raeburn  2161:     $self->{CODE}     = shift;
1.496     raeburn  2162:     $self->{NOHIDE} = shift;
1.453     www      2163: 
1.465     foxr     2164: 
                   2165: 
1.133     bowersj2 2166:     # Resource cache stores navmap resources as we reference them. We generate
                   2167:     # them on-demand so we don't pay for creating resources unless we use them.
                   2168:     $self->{RESOURCE_CACHE} = {};
                   2169: 
                   2170:     # Network failure flag, if we accessed the course or user opt and
                   2171:     # failed
                   2172:     $self->{NETWORK_FAILURE} = 0;
                   2173: 
1.465     foxr     2174:     # We can only tie the nav hash as done below if the username/domain
                   2175:     # match the env one. Otherwise change_user does everything we need...since we can't
1.501     raeburn  2176:     # assume there are course hashes for the specific requested user:domain
                   2177:     # Note: change_user is also called if we need the nav hash when printing CODEd 
                   2178:     # assignments or printing an exam, in which the enclosing folder for the items in
                   2179:     # the exam has hidden set.
1.465     foxr     2180:     #
1.133     bowersj2 2181: 
1.501     raeburn  2182:     if (($self->{USERNAME} eq $env{'user.name'}) && ($self->{DOMAIN} eq $env{'user.domain'}) &&
                   2183:          !$self->{CODE} && !$self->{NOHIDE}) {
1.465     foxr     2184: 	
                   2185: 	# tie the nav hash
                   2186: 	
                   2187: 	my %navmaphash;
                   2188: 	my %parmhash;
                   2189: 	my $courseFn = $env{"request.course.fn"};
                   2190: 	if (!(tie(%navmaphash, 'GDBM_File', "${courseFn}.db",
                   2191: 		  &GDBM_READER(), 0640))) {
                   2192: 	    return undef;
                   2193: 	}
                   2194: 	
                   2195: 	if (!(tie(%parmhash, 'GDBM_File', "${courseFn}_parms.db",
                   2196: 		  &GDBM_READER(), 0640)))
                   2197: 	{
                   2198: 	    untie %{$self->{PARM_HASH}};
                   2199: 	    return undef;
                   2200: 	}
                   2201: 	
                   2202: 	$self->{NAV_HASH} = \%navmaphash;
                   2203: 	$self->{PARM_HASH} = \%parmhash;
                   2204: 	$self->{PARM_CACHE} = {};
                   2205:     } else {
1.496     raeburn  2206: 	$self->change_user($self->{USERNAME}, $self->{DOMAIN},  $self->{CODE}, $self->{NOHIDE});
1.133     bowersj2 2207:     }
1.470     foxr     2208: 
1.465     foxr     2209:     return $self;
                   2210: }
                   2211: 
                   2212: #
                   2213: #  In some instances it is useful to be able to dynamically change the
                   2214: # username/domain associated with a navmap (e.g. to navigate for someone
                   2215: # else besides the current user...if sufficiently privileged.
                   2216: # Parameters:
                   2217: #    user  - New user.
                   2218: #    domain- Domain the user belongs to.
1.491     raeburn  2219: #    code  - Anonymous CODE in use.
1.465     foxr     2220: # Implicit inputs:
                   2221: #   
                   2222: sub change_user {
                   2223:     my $self = shift;
                   2224:     $self->{USERNAME} = shift;
                   2225:     $self->{DOMAIN}   = shift;
1.491     raeburn  2226:     $self->{CODE}     = shift;
1.496     raeburn  2227:     $self->{NOHIDE}   = shift;
1.465     foxr     2228: 
                   2229:     # If the hashes are already tied make sure to break that bond:
                   2230: 
                   2231:     untie %{$self->{NAV_HASH}}; 
                   2232:     untie %{$self->{PARM_HASH}};
                   2233: 
                   2234:     # The assumption is that we have to
                   2235:     # use lonmap here to re-read the hash and from it reconstruct
                   2236:     # new big and parameter hashes.  An implicit assumption at this time
                   2237:     # is that the course file is probably not created locally yet
                   2238:     # an that we will therefore just read without tying.
                   2239: 
                   2240:     my ($cdom, $cnum) = split(/\_/, $env{'request.course.id'});
                   2241: 
                   2242:     my %big_hash;
1.496     raeburn  2243:     &Apache::lonmap::loadmap($cnum, $cdom, $self->{USERNAME}, $self->{DOMAIN}, $self->{CODE}, $self->{NOHIDE}, \%big_hash);
1.465     foxr     2244:     $self->{NAV_HASH} = \%big_hash;
                   2245: 
1.470     foxr     2246: 
                   2247: 
1.514     raeburn  2248:     # Now clear the parm cache and reconstruct the parm hash from the big_hash
1.465     foxr     2249:     # param.xxxx keys.
                   2250: 
                   2251:     $self->{PARM_CACHE} = {};
1.133     bowersj2 2252:     
1.465     foxr     2253:     my %parm_hash = {};
1.504     raeburn  2254:     foreach my $key (keys(%big_hash)) {
1.465     foxr     2255: 	if ($key =~ /^param\./) {
                   2256: 	    my $param_key = $key;
                   2257: 	    $param_key =~ s/^param\.//;
                   2258: 	    $parm_hash{$param_key} = $big_hash{$key};
                   2259: 	}
1.133     bowersj2 2260:     }
                   2261: 
1.465     foxr     2262:     $self->{PARM_HASH} = \%parm_hash;
                   2263: 
1.500     raeburn  2264: }
1.133     bowersj2 2265: 
1.221     bowersj2 2266: sub generate_course_user_opt {
1.133     bowersj2 2267:     my $self = shift;
1.221     bowersj2 2268:     if ($self->{COURSE_USER_OPT_GENERATED}) { return; }
1.133     bowersj2 2269: 
1.453     www      2270:     my $uname=$self->{USERNAME};
                   2271:     my $udom=$self->{DOMAIN};
                   2272: 
1.320     albertel 2273:     my $cid=$env{'request.course.id'};
1.326     albertel 2274:     my $cdom=$env{'course.'.$cid.'.domain'};
                   2275:     my $cnum=$env{'course.'.$cid.'.num'};
1.221     bowersj2 2276:     
1.133     bowersj2 2277: # ------------------------------------------------- Get coursedata (if present)
1.326     albertel 2278:     my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
                   2279:     # Check for network failure
                   2280:     if (!ref($courseopt)) {
                   2281: 	if ( $courseopt =~ /no.such.host/i || $courseopt =~ /con_lost/i) {
1.324     albertel 2282: 	    $self->{NETWORK_FAILURE} = 1;
1.221     bowersj2 2283: 	}
1.326     albertel 2284: 	undef($courseopt);
                   2285:     }
1.325     albertel 2286: 
1.133     bowersj2 2287: # --------------------------------------------------- Get userdata (if present)
1.325     albertel 2288: 	
1.326     albertel 2289:     my $useropt=&Apache::lonnet::get_userresdata($uname,$udom);
                   2290:     # Check for network failure
                   2291:     if (!ref($useropt)) {
                   2292: 	if ( $useropt =~ /no.such.host/i || $useropt =~ /con_lost/i) {
1.324     albertel 2293: 	    $self->{NETWORK_FAILURE} = 1;
1.221     bowersj2 2294: 	}
1.326     albertel 2295: 	undef($useropt);
1.221     bowersj2 2296:     }
                   2297: 
1.326     albertel 2298:     $self->{COURSE_OPT} = $courseopt;
                   2299:     $self->{USER_OPT} = $useropt;
                   2300: 
1.221     bowersj2 2301:     $self->{COURSE_USER_OPT_GENERATED} = 1;
                   2302:     
                   2303:     return;
                   2304: }
                   2305: 
1.485     foxr     2306: 
                   2307: 
1.221     bowersj2 2308: sub generate_email_discuss_status {
                   2309:     my $self = shift;
1.259     raeburn  2310:     my $symb = shift;
1.221     bowersj2 2311:     if ($self->{EMAIL_DISCUSS_GENERATED}) { return; }
1.133     bowersj2 2312: 
1.320     albertel 2313:     my $cid=$env{'request.course.id'};
1.326     albertel 2314:     my $cdom=$env{'course.'.$cid.'.domain'};
                   2315:     my $cnum=$env{'course.'.$cid.'.num'};
1.221     bowersj2 2316:     
1.454     www      2317:     my %emailstatus = &Apache::lonnet::dump('email_status',$self->{DOMAIN},$self->{USERNAME});
1.221     bowersj2 2318:     my $logoutTime = $emailstatus{'logout'};
1.320     albertel 2319:     my $courseLeaveTime = $emailstatus{'logout_'.$env{'request.course.id'}};
1.221     bowersj2 2320:     $self->{LAST_CHECK} = (($courseLeaveTime > $logoutTime) ?
                   2321: 			   $courseLeaveTime : $logoutTime);
                   2322:     my %discussiontime = &Apache::lonnet::dump('discussiontimes', 
                   2323: 					       $cdom, $cnum);
1.259     raeburn  2324:     my %lastread = &Apache::lonnet::dump('nohist_'.$cid.'_discuss',
1.453     www      2325:                                         $self->{DOMAIN},$self->{USERNAME},'lastread');
1.259     raeburn  2326:     my %lastreadtime = ();
1.504     raeburn  2327:     foreach my $key (keys(%lastread)) {
1.394     raeburn  2328:         my $shortkey = $key;
                   2329:         $shortkey =~ s/_lastread$//;
                   2330:         $lastreadtime{$shortkey} = $lastread{$key};
1.259     raeburn  2331:     }
                   2332: 
1.221     bowersj2 2333:     my %feedback=();
                   2334:     my %error=();
1.453     www      2335:     my @keys = &Apache::lonnet::getkeys('nohist_email',$self->{DOMAIN},
                   2336: 					$self->{USERNAME});
1.221     bowersj2 2337:     
1.325     albertel 2338:     foreach my $msgid (@keys) {
1.295     albertel 2339: 	if ((!$emailstatus{$msgid}) || ($emailstatus{$msgid} eq 'new')) {
1.395     raeburn  2340:             my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid,
1.536     raeburn  2341:                 $symb,$error) = &Apache::lonmsg::unpackmsgid(&LONCAPA::escape($msgid));
1.396     raeburn  2342:             &Apache::lonenc::check_decrypt(\$symb); 
                   2343:             if (($fromcid ne '') && ($fromcid ne $cid)) {
                   2344:                 next;
                   2345:             }
1.395     raeburn  2346:             if (defined($symb)) {
                   2347:                 if (defined($error) && $error == 1) {
                   2348:                     $error{$symb}.=','.$msgid;
                   2349:                 } else {
                   2350:                     $feedback{$symb}.=','.$msgid;
                   2351:                 }
                   2352:             } else {
                   2353:                 my $plain=
                   2354:                     &LONCAPA::unescape(&LONCAPA::unescape($msgid));
                   2355:                 if ($plain=~/ \[([^\]]+)\]\:/) {
                   2356:                     my $url=$1;
                   2357:                     if ($plain=~/\:Error \[/) {
                   2358:                         $error{$url}.=','.$msgid;
                   2359:                     } else {
                   2360:                         $feedback{$url}.=','.$msgid;
                   2361:                     }
                   2362:                 }
                   2363:             }
1.221     bowersj2 2364: 	}
1.211     bowersj2 2365:     }
1.221     bowersj2 2366:     
1.395     raeburn  2367:     #symbs of resources that have feedbacks (will be urls pre-2.3)
1.221     bowersj2 2368:     $self->{FEEDBACK} = \%feedback;
1.395     raeburn  2369:     #or errors (will be urls pre 2.3)
1.295     albertel 2370:     $self->{ERROR_MSG} = \%error;
1.221     bowersj2 2371:     $self->{DISCUSSION_TIME} = \%discussiontime;
                   2372:     $self->{EMAIL_STATUS} = \%emailstatus;
1.259     raeburn  2373:     $self->{LAST_READ} = \%lastreadtime;
1.221     bowersj2 2374:     
                   2375:     $self->{EMAIL_DISCUSS_GENERATED} = 1;
                   2376: }
                   2377: 
                   2378: sub get_user_data {
                   2379:     my $self = shift;
                   2380:     if ($self->{RETRIEVED_USER_DATA}) { return; }
1.211     bowersj2 2381: 
1.221     bowersj2 2382:     # Retrieve performance data on problems
1.320     albertel 2383:     my %student_data = Apache::lonnet::currentdump($env{'request.course.id'},
1.453     www      2384: 						   $self->{DOMAIN},
                   2385: 						   $self->{USERNAME});
1.221     bowersj2 2386:     $self->{STUDENT_DATA} = \%student_data;
1.133     bowersj2 2387: 
1.221     bowersj2 2388:     $self->{RETRIEVED_USER_DATA} = 1;
1.133     bowersj2 2389: }
                   2390: 
1.354     raeburn  2391: sub get_discussion_data {
                   2392:     my $self = shift;
                   2393:     if ($self->{RETRIEVED_DISCUSSION_DATA}) {
1.366     albertel 2394: 	return $self->{DISCUSSION_DATA};
1.354     raeburn  2395:     }
1.366     albertel 2396: 
                   2397:     $self->generate_email_discuss_status();    
                   2398: 
1.354     raeburn  2399:     my $cid=$env{'request.course.id'};
                   2400:     my $cdom=$env{'course.'.$cid.'.domain'};
                   2401:     my $cnum=$env{'course.'.$cid.'.num'};
                   2402:     # Retrieve discussion data for resources in course
1.367     albertel 2403:     my %discussion_data = &Apache::lonnet::dumpstore($cid,$cdom,$cnum);
1.366     albertel 2404: 
                   2405: 
1.354     raeburn  2406:     $self->{DISCUSSION_DATA} = \%discussion_data;
                   2407:     $self->{RETRIEVED_DISCUSSION_DATA} = 1;
                   2408:     return $self->{DISCUSSION_DATA};
                   2409: }
                   2410: 
                   2411: 
1.133     bowersj2 2412: # Internal function: Takes a key to look up in the nav hash and implements internal
                   2413: # memory caching of that key.
                   2414: sub navhash {
                   2415:     my $self = shift; my $key = shift;
                   2416:     return $self->{NAV_HASH}->{$key};
                   2417: }
                   2418: 
1.217     bowersj2 2419: =pod
                   2420: 
                   2421: =item * B<courseMapDefined>(): Returns true if the course map is defined, 
                   2422:     false otherwise. Undefined course maps indicate an error somewhere in
                   2423:     LON-CAPA, and you will not be able to proceed with using the navmap.
                   2424:     See the B<NAV> screen for an example of using this.
                   2425: 
                   2426: =cut
                   2427: 
1.133     bowersj2 2428: # Checks to see if coursemap is defined, matching test in old lonnavmaps
                   2429: sub courseMapDefined {
                   2430:     my $self = shift;
1.320     albertel 2431:     my $uri = &Apache::lonnet::clutter($env{'request.course.uri'});
1.133     bowersj2 2432: 
                   2433:     my $firstres = $self->navhash("map_start_$uri");
                   2434:     my $lastres = $self->navhash("map_finish_$uri");
                   2435:     return $firstres && $lastres;
                   2436: }
                   2437: 
                   2438: sub getIterator {
                   2439:     my $self = shift;
                   2440:     my $iterator = Apache::lonnavmaps::iterator->new($self, shift, shift,
1.314     albertel 2441:                                                      shift, undef, shift,
                   2442: 						     shift, shift);
1.133     bowersj2 2443:     return $iterator;
                   2444: }
                   2445: 
                   2446: # Private method: Does the given resource (as a symb string) have
                   2447: # current discussion? Returns 0 if chat/mail data not extracted.
                   2448: sub hasDiscussion {
                   2449:     my $self = shift;
                   2450:     my $symb = shift;
1.221     bowersj2 2451:     $self->generate_email_discuss_status();
                   2452: 
1.133     bowersj2 2453:     if (!defined($self->{DISCUSSION_TIME})) { return 0; }
                   2454: 
                   2455:     #return defined($self->{DISCUSSION_TIME}->{$symb});
1.259     raeburn  2456: 
1.323     albertel 2457:     # backward compatibility (bulletin boards used to be 'wrapped')
                   2458:     my $ressymb = $self->wrap_symb($symb);
1.259     raeburn  2459:     if ( defined ( $self->{LAST_READ}->{$ressymb} ) ) {
                   2460:         return $self->{DISCUSSION_TIME}->{$ressymb} > $self->{LAST_READ}->{$ressymb};
                   2461:     } else {
1.266     raeburn  2462: #        return $self->{DISCUSSION_TIME}->{$ressymb} >  $self->{LAST_CHECK}; # v.1.1 behavior 
                   2463:         return $self->{DISCUSSION_TIME}->{$ressymb} >  0; # in 1.2 will display speech bubble icons for all items with posts until marked as read (even if read in v 1.1).
1.259     raeburn  2464:     }
1.133     bowersj2 2465: }
                   2466: 
1.366     albertel 2467: sub last_post_time {
                   2468:     my $self = shift;
                   2469:     my $symb = shift;
                   2470:     my $ressymb = $self->wrap_symb($symb);
                   2471:     return $self->{DISCUSSION_TIME}->{$ressymb};
                   2472: }
                   2473: 
1.393     raeburn  2474: sub discussion_info {
1.366     albertel 2475:     my $self = shift;
                   2476:     my $symb = shift;
1.393     raeburn  2477:     my $filter = shift;
1.366     albertel 2478: 
                   2479:     $self->get_discussion_data();
1.372     raeburn  2480: 
1.366     albertel 2481:     my $ressymb = $self->wrap_symb($symb);
1.372     raeburn  2482:     # keys used to store bulletinboard postings use 'unwrapped' symb. 
1.397     albertel 2483:     my $discsymb = &escape($self->unwrap_symb($ressymb));
1.372     raeburn  2484:     my $version = $self->{DISCUSSION_DATA}{'version:'.$discsymb};
1.366     albertel 2485:     if (!$version) { return; }
                   2486: 
                   2487:     my $prevread = $self->{LAST_READ}{$ressymb};
                   2488: 
1.393     raeburn  2489:     my $count = 0;
1.366     albertel 2490:     my $hiddenflag = 0;
                   2491:     my $deletedflag = 0;
1.393     raeburn  2492:     my ($hidden,$deleted,%info);
1.366     albertel 2493: 
                   2494:     for (my $id=$version; $id>0; $id--) {
1.372     raeburn  2495: 	my $vkeys=$self->{DISCUSSION_DATA}{$id.':keys:'.$discsymb};
1.366     albertel 2496: 	my @keys=split(/:/,$vkeys);
                   2497: 	if (grep(/^hidden$/ ,@keys)) {
                   2498: 	    if (!$hiddenflag) {
1.372     raeburn  2499: 		$hidden = $self->{DISCUSSION_DATA}{$id.':'.$discsymb.':hidden'};
1.366     albertel 2500: 		$hiddenflag = 1;
                   2501: 	    }
                   2502: 	} elsif (grep(/^deleted$/,@keys)) {
                   2503: 	    if (!$deletedflag) {
1.372     raeburn  2504: 		$deleted = $self->{DISCUSSION_DATA}{$id.':'.$discsymb.':deleted'};
1.366     albertel 2505: 		$deletedflag = 1;
                   2506: 	    }
                   2507: 	} else {
1.393     raeburn  2508: 	    if (($hidden !~/\.$id\./) && ($deleted !~/\.$id\./)) {
                   2509:                 if ($filter eq 'unread') {
                   2510: 		    if ($prevread >= $self->{DISCUSSION_DATA}{$id.':'.$discsymb.':timestamp'}) {
                   2511:                         next;
                   2512:                     }
                   2513:                 }
                   2514: 		$count++;
                   2515: 		$info{$count}{'subject'} =
                   2516: 		    $self->{DISCUSSION_DATA}{$id.':'.$discsymb.':subject'};
                   2517:                 $info{$count}{'id'} = $id;
                   2518:                 $info{$count}{'timestamp'} = $self->{DISCUSSION_DATA}{$id.':'.$discsymb.':timestamp'};
                   2519:             }
1.366     albertel 2520: 	}
                   2521:     }
                   2522:     if (wantarray) {
1.393     raeburn  2523: 	return ($count,%info);
1.366     albertel 2524:     }
1.393     raeburn  2525:     return $count;
1.366     albertel 2526: }
                   2527: 
1.321     raeburn  2528: sub wrap_symb {
1.322     albertel 2529:     my $self = shift;
1.321     raeburn  2530:     my $symb = shift;
1.373     albertel 2531:     if ($symb =~ m-___(adm/[^/]+/[^/]+/)(\d+)(/bulletinboard)$-) {
1.322     albertel 2532:         unless ($symb =~ m|adm/wrapper/adm|) {
                   2533:             $symb = 'bulletin___'.$2.'___adm/wrapper/'.$1.$2.$3;
1.321     raeburn  2534:         }
                   2535:     }
1.322     albertel 2536:     return $symb;
1.321     raeburn  2537: }
                   2538: 
1.372     raeburn  2539: sub unwrap_symb {
                   2540:     my $self = shift;
                   2541:     my $ressymb = shift;
                   2542:     my $discsymb = $ressymb;
1.373     albertel 2543:     if ($ressymb =~ m-^(bulletin___\d+___)adm/wrapper/(adm/[^/]+/[^/]+/\d+/bulletinboard)$-) {
1.372     raeburn  2544:          $discsymb = $1.$2;
                   2545:     }
                   2546:     return $discsymb;
                   2547: }
                   2548: 
1.322     albertel 2549: # Private method: Does the given resource (as a symb string) have
                   2550: # current feedback? Returns the string in the feedback hash, which
                   2551: # will be false if it does not exist.
                   2552: 
1.133     bowersj2 2553: sub getFeedback { 
                   2554:     my $self = shift;
                   2555:     my $symb = shift;
1.395     raeburn  2556:     my $source = shift;
1.133     bowersj2 2557: 
1.221     bowersj2 2558:     $self->generate_email_discuss_status();
                   2559: 
1.133     bowersj2 2560:     if (!defined($self->{FEEDBACK})) { return ""; }
                   2561:     
1.395     raeburn  2562:     my $feedback;
                   2563:     if ($self->{FEEDBACK}->{$symb}) {
                   2564:         $feedback = $self->{FEEDBACK}->{$symb};
                   2565:         if ($self->{FEEDBACK}->{$source}) {
                   2566:             $feedback .= ','.$self->{FEEDBACK}->{$source};
                   2567:         }
                   2568:     } else {
                   2569:         if ($self->{FEEDBACK}->{$source}) {
                   2570:             $feedback = $self->{FEEDBACK}->{$source};
                   2571:         }
                   2572:     }
                   2573:     return $feedback;
1.133     bowersj2 2574: }
                   2575: 
                   2576: # Private method: Get the errors for that resource (by source).
                   2577: sub getErrors { 
                   2578:     my $self = shift;
1.395     raeburn  2579:     my $symb = shift;
1.133     bowersj2 2580:     my $src = shift;
1.221     bowersj2 2581: 
                   2582:     $self->generate_email_discuss_status();
                   2583: 
1.133     bowersj2 2584:     if (!defined($self->{ERROR_MSG})) { return ""; }
1.395     raeburn  2585: 
                   2586:     my $errors;
                   2587:     if ($self->{ERROR_MSG}->{$symb}) {
                   2588:         $errors = $self->{ERROR_MSG}->{$symb};
                   2589:         if ($self->{ERROR_MSG}->{$src}) {
                   2590:             $errors .= ','.$self->{ERROR_MSG}->{$src};
                   2591:         }
                   2592:     } else {
                   2593:         if ($self->{ERROR_MSG}->{$src}) {
                   2594:             $errors = $self->{ERROR_MSG}->{$src};
                   2595:         }
                   2596:     }
                   2597:     return $errors;
1.133     bowersj2 2598: }
                   2599: 
                   2600: =pod
                   2601: 
1.174     albertel 2602: =item * B<getById>(id):
                   2603: 
                   2604: Based on the ID of the resource (1.1, 3.2, etc.), get a resource
                   2605: object for that resource. This method, or other methods that use it
                   2606: (as in the resource object) is the only proper way to obtain a
                   2607: resource object.
1.133     bowersj2 2608: 
1.194     bowersj2 2609: =item * B<getBySymb>(symb):
                   2610: 
                   2611: Based on the symb of the resource, get a resource object for that
                   2612: resource. This is one of the proper ways to get a resource object.
                   2613: 
1.448     raeburn  2614: =item * B<getByMapPc>(map_pc):
1.194     bowersj2 2615: 
                   2616: Based on the map_pc of the resource, get a resource object for
                   2617: the given map. This is one of the proper ways to get a resource object.
                   2618: 
1.133     bowersj2 2619: =cut
                   2620: 
                   2621: # The strategy here is to cache the resource objects, and only construct them
                   2622: # as we use them. The real point is to prevent reading any more from the tied
1.398     banghart 2623: # hash than we have to, which should hopefully alleviate speed problems.
1.133     bowersj2 2624: 
                   2625: sub getById {
                   2626:     my $self = shift;
                   2627:     my $id = shift;
                   2628: 
                   2629:     if (defined ($self->{RESOURCE_CACHE}->{$id}))
                   2630:     {
                   2631:         return $self->{RESOURCE_CACHE}->{$id};
                   2632:     }
                   2633: 
                   2634:     # resource handles inserting itself into cache.
                   2635:     # Not clear why the quotes are necessary, but as of this
                   2636:     # writing it doesn't work without them.
                   2637:     return "Apache::lonnavmaps::resource"->new($self, $id);
1.132     bowersj2 2638: }
1.133     bowersj2 2639: 
1.172     bowersj2 2640: sub getBySymb {
                   2641:     my $self = shift;
                   2642:     my $symb = shift;
1.277     matthew  2643: 
1.228     albertel 2644:     my ($mapUrl, $id, $filename) = &Apache::lonnet::decode_symb($symb);
1.172     bowersj2 2645:     my $map = $self->getResourceByUrl($mapUrl);
1.277     matthew  2646:     my $returnvalue = undef;
                   2647:     if (ref($map)) {
                   2648:         $returnvalue = $self->getById($map->map_pc() .'.'.$id);
                   2649:     }
                   2650:     return $returnvalue;
1.194     bowersj2 2651: }
                   2652: 
                   2653: sub getByMapPc {
                   2654:     my $self = shift;
                   2655:     my $map_pc = shift;
                   2656:     my $map_id = $self->{NAV_HASH}->{'map_id_' . $map_pc};
                   2657:     $map_id = $self->{NAV_HASH}->{'ids_' . $map_id};
                   2658:     return $self->getById($map_id);
1.172     bowersj2 2659: }
                   2660: 
1.133     bowersj2 2661: =pod
                   2662: 
1.174     albertel 2663: =item * B<firstResource>():
                   2664: 
                   2665: Returns a resource object reference corresponding to the first
                   2666: resource in the navmap.
1.133     bowersj2 2667: 
                   2668: =cut
                   2669: 
                   2670: sub firstResource {
                   2671:     my $self = shift;
                   2672:     my $firstResource = $self->navhash('map_start_' .
1.320     albertel 2673:                      &Apache::lonnet::clutter($env{'request.course.uri'}));
1.133     bowersj2 2674:     return $self->getById($firstResource);
1.132     bowersj2 2675: }
1.133     bowersj2 2676: 
                   2677: =pod
                   2678: 
1.174     albertel 2679: =item * B<finishResource>():
                   2680: 
                   2681: Returns a resource object reference corresponding to the last resource
                   2682: in the navmap.
1.133     bowersj2 2683: 
                   2684: =cut
                   2685: 
                   2686: sub finishResource {
                   2687:     my $self = shift;
                   2688:     my $firstResource = $self->navhash('map_finish_' .
1.320     albertel 2689:                      &Apache::lonnet::clutter($env{'request.course.uri'}));
1.133     bowersj2 2690:     return $self->getById($firstResource);
1.132     bowersj2 2691: }
1.133     bowersj2 2692: 
                   2693: # Parmval reads the parm hash and cascades the lookups. parmval_real does
                   2694: # the actual lookup; parmval caches the results.
                   2695: sub parmval {
                   2696:     my $self = shift;
1.399     albertel 2697:     my ($what,$symb,$recurse)=@_;
1.133     bowersj2 2698:     my $hashkey = $what."|||".$symb;
1.459     foxr     2699:     my $cache = $self->{PARM_CACHE};
1.133     bowersj2 2700:     if (defined($self->{PARM_CACHE}->{$hashkey})) {
1.411     raeburn  2701:         if (ref($self->{PARM_CACHE}->{$hashkey}) eq 'ARRAY') { 
                   2702:             if (defined($self->{PARM_CACHE}->{$hashkey}->[0])) {
                   2703:                 if (wantarray) {
                   2704:                     return @{$self->{PARM_CACHE}->{$hashkey}};
                   2705:                 } else {
                   2706:                     return $self->{PARM_CACHE}->{$hashkey}->[0];
                   2707:                 }
                   2708:             }
                   2709:         } else {
                   2710:             return $self->{PARM_CACHE}->{$hashkey};
                   2711:         }
1.133     bowersj2 2712:     }
1.515     raeburn  2713: 
1.399     albertel 2714:     my $result = $self->parmval_real($what, $symb, $recurse);
1.133     bowersj2 2715:     $self->{PARM_CACHE}->{$hashkey} = $result;
1.405     albertel 2716:     if (wantarray) {
1.411     raeburn  2717:         return @{$result};
1.405     albertel 2718:     }
                   2719:     return $result->[0];
1.132     bowersj2 2720: }
                   2721: 
1.485     foxr     2722: 
1.133     bowersj2 2723: sub parmval_real {
                   2724:     my $self = shift;
1.219     albertel 2725:     my ($what,$symb,$recurse) = @_;
1.133     bowersj2 2726: 
1.485     foxr     2727: 
1.221     bowersj2 2728:     # Make sure the {USER_OPT} and {COURSE_OPT} hashes are populated
                   2729:     $self->generate_course_user_opt();
                   2730: 
1.320     albertel 2731:     my $cid=$env{'request.course.id'};
                   2732:     my $csec=$env{'request.course.sec'};
1.350     raeburn  2733:     my $cgroup='';
                   2734:     my @cgrps=split(/:/,$env{'request.course.groups'});
                   2735:     if (@cgrps > 0) {
                   2736:         @cgrps = sort(@cgrps);
                   2737:         $cgroup = $cgrps[0];
                   2738:     } 
1.453     www      2739:     my $uname=$self->{USERNAME};
                   2740:     my $udom=$self->{DOMAIN};
1.133     bowersj2 2741: 
1.405     albertel 2742:     unless ($symb) { return ['']; }
1.133     bowersj2 2743:     my $result='';
                   2744: 
1.226     www      2745:     my ($mapname,$id,$fn)=&Apache::lonnet::decode_symb($symb);
1.383     albertel 2746:     $mapname = &Apache::lonnet::deversion($mapname);
1.537     raeburn  2747:     my $toolsymb = '';
                   2748:     if ($fn =~ /ext\.tool$/) {
                   2749:         $toolsymb = $symb;
                   2750:     }
1.515     raeburn  2751:     my ($recursed,@recurseup); 
                   2752:     
1.133     bowersj2 2753: # ----------------------------------------------------- Cascading lookup scheme
                   2754:     my $rwhat=$what;
                   2755:     $what=~s/^parameter\_//;
                   2756:     $what=~s/\_/\./;
                   2757: 
                   2758:     my $symbparm=$symb.'.'.$what;
1.515     raeburn  2759:     my $recurseparm=$mapname.'___(rec).'.$what;
1.133     bowersj2 2760:     my $mapparm=$mapname.'___(all).'.$what;
1.325     albertel 2761:     my $usercourseprefix=$cid;
1.515     raeburn  2762:     
1.485     foxr     2763: 
                   2764: 
1.350     raeburn  2765:     my $grplevel=$usercourseprefix.'.['.$cgroup.'].'.$what;
                   2766:     my $grplevelr=$usercourseprefix.'.['.$cgroup.'].'.$symbparm;
1.515     raeburn  2767:     my $grpleveli=$usercourseprefix.'.['.$cgroup.'].'.$recurseparm;
1.350     raeburn  2768:     my $grplevelm=$usercourseprefix.'.['.$cgroup.'].'.$mapparm;
                   2769: 
1.485     foxr     2770: 
1.133     bowersj2 2771:     my $seclevel= $usercourseprefix.'.['.$csec.'].'.$what;
                   2772:     my $seclevelr=$usercourseprefix.'.['.$csec.'].'.$symbparm;
1.515     raeburn  2773:     my $secleveli=$usercourseprefix.'.['.$csec.'].'.$recurseparm;
1.133     bowersj2 2774:     my $seclevelm=$usercourseprefix.'.['.$csec.'].'.$mapparm;
                   2775: 
1.485     foxr     2776: 
1.133     bowersj2 2777:     my $courselevel= $usercourseprefix.'.'.$what;
                   2778:     my $courselevelr=$usercourseprefix.'.'.$symbparm;
1.515     raeburn  2779:     my $courseleveli=$usercourseprefix.'.'.$recurseparm;
1.133     bowersj2 2780:     my $courselevelm=$usercourseprefix.'.'.$mapparm;
                   2781: 
1.485     foxr     2782: 
1.133     bowersj2 2783:     my $useropt = $self->{USER_OPT};
                   2784:     my $courseopt = $self->{COURSE_OPT};
                   2785:     my $parmhash = $self->{PARM_HASH};
                   2786: 
                   2787: # ---------------------------------------------------------- first, check user
                   2788:     if ($uname and defined($useropt)) {
1.405     albertel 2789:         if (defined($$useropt{$courselevelr})) { return [$$useropt{$courselevelr},'resource']; }
                   2790:         if (defined($$useropt{$courselevelm})) { return [$$useropt{$courselevelm},'map']; }
1.515     raeburn  2791:         if (defined($$useropt{$courseleveli})) { return [$$useropt{$courseleveli},'map']; }
                   2792:         unless ($recursed) {
                   2793:             @recurseup = $self->recurseup_maps($mapname);
                   2794:             $recursed = 1;
                   2795:         }
                   2796:         foreach my $item (@recurseup) {
                   2797:             my $norecursechk=$usercourseprefix.'.'.$item.'___(all).'.$what;
1.526     raeburn  2798:             if (defined($$useropt{$norecursechk})) {
                   2799:                 if ($what =~ /\.(encrypturl|hiddenresource)$/) {
                   2800:                     return [$$useropt{$norecursechk},'map'];
                   2801:                 } else {
                   2802:                     last;
                   2803:                 }
                   2804:             }
1.515     raeburn  2805:             my $recursechk=$usercourseprefix.'.'.$item.'___(rec).'.$what;
                   2806:             if (defined($$useropt{$recursechk})) { return [$$useropt{$recursechk},'map']; } 
                   2807:         }
1.405     albertel 2808:         if (defined($$useropt{$courselevel})) { return [$$useropt{$courselevel},'course']; }
1.133     bowersj2 2809:     }
                   2810: 
                   2811: # ------------------------------------------------------- second, check course
1.350     raeburn  2812:     if ($cgroup ne '' and defined($courseopt)) {
1.405     albertel 2813:         if (defined($$courseopt{$grplevelr})) { return [$$courseopt{$grplevelr},'resource']; }
                   2814:         if (defined($$courseopt{$grplevelm})) { return [$$courseopt{$grplevelm},'map']; }
1.515     raeburn  2815:         if (defined($$courseopt{$grpleveli})) { return [$$courseopt{$grpleveli},'map']; } 
                   2816:         unless ($recursed) {
                   2817:             @recurseup = $self->recurseup_maps($mapname);
                   2818:             $recursed = 1;
                   2819:         }
                   2820:         foreach my $item (@recurseup) {
                   2821:             my $norecursechk=$usercourseprefix.'.['.$cgroup.'].'.$item.'___(all).'.$what;
1.526     raeburn  2822:             if (defined($$courseopt{$norecursechk})) {
                   2823:                 if ($what =~ /\.(encrypturl|hiddenresource)$/) {
                   2824:                     return [$$courseopt{$norecursechk},'map'];
                   2825:                 } else {
                   2826:                    last;
                   2827:                 }
                   2828:             }
1.515     raeburn  2829:             my $recursechk=$usercourseprefix.'.['.$cgroup.'].'.$item.'___(rec).'.$what;
                   2830:             if (defined($$courseopt{$recursechk})) { return [$$courseopt{$recursechk},'map']; }      
                   2831:         }
1.405     albertel 2832:         if (defined($$courseopt{$grplevel})) { return [$$courseopt{$grplevel},'course']; }
1.350     raeburn  2833:     }
                   2834: 
1.515     raeburn  2835:     if ($csec ne '' and defined($courseopt)) {
1.405     albertel 2836:         if (defined($$courseopt{$seclevelr})) { return [$$courseopt{$seclevelr},'resource']; }
                   2837:         if (defined($$courseopt{$seclevelm})) { return [$$courseopt{$seclevelm},'map']; }
1.515     raeburn  2838:         if (defined($$courseopt{$secleveli})) { return [$$courseopt{$secleveli},'map']; } 
                   2839:         unless ($recursed) {
                   2840:             @recurseup = $self->recurseup_maps($mapname);
                   2841:             $recursed = 1;
                   2842:         }
                   2843:         foreach my $item (@recurseup) {
                   2844:             my $norecursechk=$usercourseprefix.'.['.$csec.'].'.$item.'___(all).'.$what;
1.526     raeburn  2845:             if (defined($$courseopt{$norecursechk})) {
                   2846:                 if ($what =~ /\.(encrypturl|hiddenresource)$/) {
                   2847:                     return [$$courseopt{$norecursechk},'map'];
                   2848:                 } else {
                   2849:                     last;
                   2850:                 }
                   2851:             }
1.515     raeburn  2852:             my $recursechk=$usercourseprefix.'.['.$csec.'].'.$item.'___(rec).'.$what;
                   2853:             if (defined($$courseopt{$recursechk})) { return [$$courseopt{$recursechk},'map']; }
                   2854:         }
1.405     albertel 2855:         if (defined($$courseopt{$seclevel})) { return [$$courseopt{$seclevel},'course']; }
1.133     bowersj2 2856:     }
                   2857: 
                   2858:     if (defined($courseopt)) {
1.405     albertel 2859:         if (defined($$courseopt{$courselevelr})) { return [$$courseopt{$courselevelr},'resource']; }
1.133     bowersj2 2860:     }
                   2861: 
                   2862: # ----------------------------------------------------- third, check map parms
                   2863: 
                   2864:     my $thisparm=$$parmhash{$symbparm};
1.405     albertel 2865:     if (defined($thisparm)) { return [$thisparm,'map']; }
1.133     bowersj2 2866: 
                   2867: # ----------------------------------------------------- fourth , check default
                   2868: 
1.246     albertel 2869:     my $meta_rwhat=$rwhat;
                   2870:     $meta_rwhat=~s/\./_/g;
1.537     raeburn  2871:     my $default=&Apache::lonnet::metadata($fn,$meta_rwhat,$toolsymb);
1.405     albertel 2872:     if (defined($default)) { return [$default,'resource']}
1.537     raeburn  2873:     $default=&Apache::lonnet::metadata($fn,'parameter_'.$meta_rwhat,$toolsymb);
1.405     albertel 2874:     if (defined($default)) { return [$default,'resource']}
1.315     albertel 2875: # --------------------------------------------------- fifth, check more course
                   2876:     if (defined($courseopt)) {
1.405     albertel 2877:         if (defined($$courseopt{$courselevelm})) { return [$$courseopt{$courselevelm},'map']; }
1.515     raeburn  2878:         if (defined($$courseopt{$courseleveli})) { return [$$courseopt{$courseleveli},'map']; }
                   2879:         unless ($recursed) {
                   2880:             @recurseup = $self->recurseup_maps($mapname);
                   2881:             $recursed = 1;
                   2882:         }
                   2883:         foreach my $item (@recurseup) {
                   2884:             my $norecursechk=$usercourseprefix.'.'.$item.'___(all).'.$what;
1.526     raeburn  2885:             if (defined($$courseopt{$norecursechk})) {
                   2886:                 if ($what =~ /\.(encrypturl|hiddenresource)$/) {
                   2887:                     return [$$courseopt{$norecursechk},'map'];
                   2888:                 } else {
                   2889:                     last;
                   2890:                 }
                   2891:             }
1.515     raeburn  2892:             my $recursechk=$usercourseprefix.'.'.$item.'___(rec).'.$what;
                   2893:             if (defined($$courseopt{$recursechk})) {
                   2894:                 return [$$courseopt{$recursechk},'map'];
                   2895:             }
                   2896:         }
1.405     albertel 2897:         if (defined($$courseopt{$courselevel})) {
                   2898:            my $ret = [$$courseopt{$courselevel},'course'];
                   2899:            return $ret;
                   2900:        }
1.315     albertel 2901:     }
                   2902: # --------------------------------------------------- sixth , cascade up parts
1.133     bowersj2 2903: 
                   2904:     my ($space,@qualifier)=split(/\./,$rwhat);
                   2905:     my $qualifier=join('.',@qualifier);
                   2906:     unless ($space eq '0') {
1.160     albertel 2907: 	my @parts=split(/_/,$space);
                   2908: 	my $id=pop(@parts);
                   2909: 	my $part=join('_',@parts);
                   2910: 	if ($part eq '') { $part='0'; }
1.405     albertel 2911:        my @partgeneral=$self->parmval($part.".$qualifier",$symb,1);
                   2912:        if (defined($partgeneral[0])) { return \@partgeneral; }
1.133     bowersj2 2913:     }
1.405     albertel 2914:     if ($recurse) { return []; }
1.537     raeburn  2915:     my $pack_def=&Apache::lonnet::packages_tab_default($fn,'resource.'.$rwhat,$toolsymb);
1.405     albertel 2916:     if (defined($pack_def)) { return [$pack_def,'resource']; }
                   2917:     return [''];
1.145     bowersj2 2918: }
1.515     raeburn  2919: 
                   2920: sub recurseup_maps {
                   2921:     my ($self,$mapname) = @_;
                   2922:     my @recurseup;
1.517     raeburn  2923:     if ($mapname) {
1.519     raeburn  2924:         my $res = $self->getResourceByUrl($mapname);
                   2925:         if (ref($res)) {
                   2926:             my @pcs = split(/,/,$res->map_hierarchy());
                   2927:             shift(@pcs);
                   2928:             if (@pcs) {
                   2929:                 @recurseup = map { &Apache::lonnet::declutter($self->getByMapPc($_)->src()); } reverse(@pcs);
                   2930:             }
1.517     raeburn  2931:         }
1.515     raeburn  2932:     }
                   2933:     return @recurseup;
                   2934: }
                   2935: 
1.533     raeburn  2936: sub recursed_crumbs {
1.535     raeburn  2937:     my ($self,$mapurl,$restitle) = @_;
1.533     raeburn  2938:     my (@revmapinfo,@revmapres);
                   2939:     my $mapres = $self->getResourceByUrl($mapurl);
                   2940:     if (ref($mapres)) {
1.534     raeburn  2941:         @revmapres = map { $self->getByMapPc($_); } split(/,/,$mapres->map_breadcrumbs());
1.533     raeburn  2942:         shift(@revmapres);
                   2943:     }
1.535     raeburn  2944:     my $allowedlength = 60;
                   2945:     my $minlength = 5;
                   2946:     my $allowedtitle = 30;
                   2947:     if (($env{'environment.icons'} eq 'iconsonly') && (!$env{'browser.mobile'})) {
                   2948:         $allowedlength = 100;
                   2949:         $allowedtitle = 70;
                   2950:     }
                   2951:     if (length($restitle) > $allowedtitle) {
                   2952:         $restitle = &truncate_crumb_text($restitle,$allowedtitle);
                   2953:     }
                   2954:     my $totallength = length($restitle);
                   2955:     my @links;
                   2956: 
1.533     raeburn  2957:     foreach my $map (@revmapres) {
                   2958:         my $pc = $map->map_pc();
                   2959:         next if ((!$pc) || ($pc == 1));
1.535     raeburn  2960:         push(@links,$map);
1.534     raeburn  2961:         push(@revmapinfo,{'href' => $map->link().'?navmap=1','text' => $map->title(),'no_mt' => 1,});
1.535     raeburn  2962:         $totallength += length($map->title());
                   2963:     }
                   2964:     my $numlinks = scalar(@links);
                   2965:     if ($numlinks) {
                   2966:         if ($totallength - $allowedlength > 0) {
                   2967:             my $available = $allowedlength - length($restitle);
                   2968:             my $avg = POSIX::ceil($available/$numlinks);
                   2969:             if ($avg < $minlength) {
                   2970:                 $avg = $minlength;
                   2971:             }
                   2972:             @revmapinfo = ();
                   2973:             foreach my $map (@links) {
                   2974:                 my $showntitle = &truncate_crumb_text($map->title(),$avg);
                   2975:                 if ($showntitle ne '') {
                   2976:                     push(@revmapinfo,{'href' => $map->link().'?navmap=1','text' => $showntitle,'no_mt' => 1,});
                   2977:                 }
                   2978:             }
                   2979:         }
                   2980:     }
                   2981:     if ($restitle ne '') {
                   2982:         push(@revmapinfo,{'text' => $restitle, 'no_mt' => 1});
1.533     raeburn  2983:     }
                   2984:     return @revmapinfo;
                   2985: }
                   2986: 
1.535     raeburn  2987: sub truncate_crumb_text {
                   2988:     my ($title,$limit) = @_;
                   2989:     my $showntitle = '';
                   2990:     if (length($title) > $limit) {
                   2991:         my @words = split(/\b\s*/,$title);
                   2992:         if (@words == 1) {
                   2993:             $showntitle = substr($title,0,$limit).' ...';
                   2994:         } else {
                   2995:             my $linklength = 0;
                   2996:             my $num = 0;
                   2997:             foreach my $word (@words) {
                   2998:                 $linklength += 1+length($word);
                   2999:                 if ($word eq '-') {
                   3000:                     $showntitle =~ s/ $//;
                   3001:                     $showntitle .= $word;
                   3002:                 } elsif ($linklength > $limit) {
                   3003:                     if ($num < @words) {
                   3004:                         $showntitle .= $word.' ...';
                   3005:                         last;
                   3006:                     } else {
                   3007:                         $showntitle .= $word;
                   3008:                     }
                   3009:                 } else {
                   3010:                     $showntitle .= $word.' ';
                   3011:                 }
                   3012:             }
                   3013:             $showntitle =~ s/ $//;
                   3014:         }
                   3015:         return $showntitle;
                   3016:     } else {
                   3017:         return $title;
                   3018:     }
                   3019: }
                   3020: 
1.485     foxr     3021: #
                   3022: #  Determines the open/close dates for printing a map that
                   3023: #  encloses a resource.
                   3024: #
                   3025: sub map_printdates {
                   3026:     my ($self, $res, $part) = @_;
                   3027: 
                   3028: 
                   3029: 
                   3030: 
                   3031: 
1.518     raeburn  3032:     my $opendate = $self->get_mapparam($res->symb(),'',"$part.printstartdate");
                   3033:     my $closedate= $self->get_mapparam($res->symb(),'',"$part.printenddate");
1.485     foxr     3034: 
                   3035: 
                   3036:     return ($opendate, $closedate);
                   3037: }
                   3038: 
                   3039: sub get_mapparam {
1.518     raeburn  3040:     my ($self, $symb, $mapname, $what) = @_;
1.485     foxr     3041: 
                   3042:     # Ensure the course option hash is populated:
                   3043: 
                   3044:     $self->generate_course_user_opt();
                   3045: 
                   3046:     # Get the course id and section if there is one.
                   3047: 
                   3048:     my $cid=$env{'request.course.id'};
                   3049:     my $csec=$env{'request.course.sec'};
                   3050:     my $cgroup='';
                   3051:     my @cgrps=split(/:/,$env{'request.course.groups'});
                   3052:     if (@cgrps > 0) {
                   3053:         @cgrps = sort(@cgrps);
                   3054:         $cgroup = $cgrps[0];
                   3055:     } 
                   3056:     my $uname=$self->{USERNAME};
                   3057:     my $udom=$self->{DOMAIN};
                   3058: 
1.518     raeburn  3059:     unless ($symb || $mapname) { return; }
1.485     foxr     3060:     my $result='';
1.516     raeburn  3061:     my ($recursed,@recurseup);
1.485     foxr     3062: 
                   3063: 
                   3064:     # Figure out which map we are in.
                   3065: 
1.518     raeburn  3066:     if ($symb && !$mapname) {
                   3067:         my ($id,$fn);
                   3068:         ($mapname,$id,$fn)=&Apache::lonnet::decode_symb($symb);
                   3069:         $mapname = &Apache::lonnet::deversion($mapname);
                   3070:     }
1.485     foxr     3071: 
                   3072: 
                   3073:     my $rwhat=$what;
                   3074:     $what=~s/^parameter\_//;
                   3075:     $what=~s/\_/\./;
                   3076: 
                   3077:     # Build the hash keys for the lookup:
                   3078: 
                   3079:     my $mapparm=$mapname.'___(all).'.$what;
1.515     raeburn  3080:     my $recurseparm=$mapname.'___(rec).'.$what; 
1.485     foxr     3081:     my $usercourseprefix=$cid;
                   3082: 
                   3083: 
1.515     raeburn  3084:     my $grplevelm    = "$usercourseprefix.[$cgroup].$mapparm";
                   3085:     my $seclevelm    = "$usercourseprefix.[$csec].$mapparm";
                   3086:     my $courselevelm = "$usercourseprefix.$mapparm";
                   3087: 
                   3088:     my $grpleveli    = "$usercourseprefix.[$cgroup].$recurseparm";
                   3089:     my $secleveli    = "$usercourseprefix.[$csec].$recurseparm";
                   3090:     my $courseleveli = "$usercourseprefix.$recurseparm";
1.485     foxr     3091: 
                   3092:     # Get handy references to the hashes we need in $self:
                   3093: 
                   3094:     my $useropt = $self->{USER_OPT};
                   3095:     my $courseopt = $self->{COURSE_OPT};
                   3096:     my $parmhash = $self->{PARM_HASH};
                   3097: 
                   3098:     # Check per user 
                   3099: 
                   3100: 
                   3101: 
                   3102:     if ($uname and defined($useropt)) {
1.515     raeburn  3103: 	if (defined($$useropt{$courselevelm})) {
                   3104: 	    return $$useropt{$courselevelm};
1.485     foxr     3105: 	}
1.515     raeburn  3106:         if (defined($$useropt{$courseleveli})) {
                   3107:             return $$useropt{$courseleveli};
                   3108:         }
1.516     raeburn  3109:         unless ($recursed) {
                   3110:             @recurseup = $self->recurseup_maps($mapname);
                   3111:             $recursed = 1;
                   3112:         }
                   3113:         foreach my $item (@recurseup) {
                   3114:             my $norecursechk=$usercourseprefix.'.'.$item.'___(all).'.$what;
1.526     raeburn  3115:             if (defined($$useropt{$norecursechk})) {
                   3116:                 if ($what =~ /\.(encrypturl|hiddenresource)$/) {
                   3117:                     return $$useropt{$norecursechk};
                   3118:                 } else {
                   3119:                     last;
                   3120:                 }
                   3121:             }
1.516     raeburn  3122:             my $recursechk=$usercourseprefix.'.'.$item.'___(rec).'.$what;
                   3123:             if (defined($$useropt{$recursechk})) {
                   3124:                 return $$useropt{$recursechk};
                   3125:             }
                   3126:         }
1.485     foxr     3127:     }
                   3128: 
                   3129:     # Check course -- group
                   3130: 
                   3131: 
                   3132: 
                   3133:     if ($cgroup ne '' and defined ($courseopt)) {
1.515     raeburn  3134: 	if (defined($$courseopt{$grplevelm})) {
                   3135: 	    return $$courseopt{$grplevelm};
1.485     foxr     3136: 	}
1.515     raeburn  3137:         if (defined($$courseopt{$grpleveli})) {
                   3138:             return $$courseopt{$grpleveli};
                   3139:         }
1.516     raeburn  3140:         unless ($recursed) {
                   3141:             @recurseup = $self->recurseup_maps($mapname);
                   3142:             $recursed = 1;
                   3143:         }
                   3144:         foreach my $item (@recurseup) {
                   3145:             my $norecursechk=$usercourseprefix.'.['.$cgroup.'].'.$item.'___(all).'.$what;
1.526     raeburn  3146:             if (defined($$courseopt{$norecursechk})) {
                   3147:                 if ($what =~ /\.(encrypturl|hiddenresource)$/) {
                   3148:                     return $$courseopt{$norecursechk};
                   3149:                 } else {
                   3150:                     last;
                   3151:                 }
                   3152:             }
1.516     raeburn  3153:             my $recursechk=$usercourseprefix.'.['.$cgroup.'].'.$item.'___(rec).'.$what;
                   3154:             if (defined($$courseopt{$recursechk})) {
                   3155:                 return $$courseopt{$recursechk};
                   3156:             }
                   3157:         }
1.485     foxr     3158:     }
                   3159: 
                   3160:     # Check course -- section
                   3161: 
                   3162: 
1.516     raeburn  3163:     if ($csec ne '' and defined($courseopt)) {
1.515     raeburn  3164: 	if (defined($$courseopt{$seclevelm})) {
                   3165: 	    return $$courseopt{$seclevelm};
1.485     foxr     3166: 	}
1.515     raeburn  3167:         if (defined($$courseopt{$secleveli})) {
                   3168:             return $$courseopt{$secleveli};
                   3169:         }
1.516     raeburn  3170:         unless ($recursed) {
                   3171:             @recurseup = $self->recurseup_maps($mapname);
                   3172:             $recursed = 1;
                   3173:         }
                   3174:         foreach my $item (@recurseup) {
                   3175:             my $norecursechk=$usercourseprefix.'.['.$csec.'].'.$item.'___(all).'.$what;
1.526     raeburn  3176:             if (defined($$courseopt{$norecursechk})) {
                   3177:                 if ($what =~ /\.(encrypturl|hiddenresource)$/) {
                   3178:                     return $$courseopt{$norecursechk};
                   3179:                 } else {
                   3180:                     last;
                   3181:                 }
                   3182:             }
1.516     raeburn  3183:             my $recursechk=$usercourseprefix.'.['.$csec.'].'.$item.'___(rec).'.$what;
                   3184:             if (defined($$courseopt{$recursechk})) {
                   3185:                 return $$courseopt{$recursechk};
                   3186:             }
                   3187:         }
1.485     foxr     3188:     }
                   3189:     # Check the map parameters themselves:
                   3190: 
1.518     raeburn  3191:     if ($symb) {
                   3192:         my $symbparm=$symb.'.'.$what;
                   3193:         my $thisparm = $$parmhash{$symbparm};
                   3194:         if (defined($thisparm)) {
                   3195: 	    return $thisparm;
                   3196:         }
1.485     foxr     3197:     }
                   3198: 
                   3199: 
                   3200:     # Additional course parameters:
                   3201: 
                   3202:     if (defined($courseopt)) {
1.515     raeburn  3203: 	if (defined($$courseopt{$courselevelm})) {
                   3204: 	    return $$courseopt{$courselevelm};
1.485     foxr     3205: 	}
1.516     raeburn  3206:         unless ($recursed) {
                   3207:             @recurseup = $self->recurseup_maps($mapname);
                   3208:             $recursed = 1;
                   3209:         }
                   3210:         if (@recurseup) {
                   3211:             foreach my $item (@recurseup) {
                   3212:                 my $norecursechk=$usercourseprefix.'.'.$item.'___(all).'.$what;
1.526     raeburn  3213:                 if (defined($$courseopt{$norecursechk})) {
                   3214:                     if ($what =~ /\.(encrypturl|hiddenresource)$/) {
                   3215:                         return $$courseopt{$norecursechk};
                   3216:                     } else {
                   3217:                         last;
                   3218:                     }
                   3219:                 }
1.516     raeburn  3220:                 my $recursechk=$usercourseprefix.'.'.$item.'___(rec).'.$what;
                   3221:                 if (defined($$courseopt{$recursechk})) {
                   3222:                     return $$courseopt{$recursechk};
                   3223:                 }
                   3224:             }
                   3225:         }
1.485     foxr     3226:     }
1.516     raeburn  3227:     return undef;		# Undefined if we got here.
1.485     foxr     3228: }
                   3229: 
                   3230: sub course_printdates {
                   3231:     my ($self, $symb,  $part) = @_;
                   3232: 
                   3233: 
                   3234:     my $opendate  = $self->getcourseparam($symb, $part . '.printstartdate');
                   3235:     my $closedate = $self->getcourseparam($symb, $part . '.printenddate');
                   3236:     return ($opendate, $closedate);
                   3237: 
                   3238: }
                   3239: 
                   3240: sub getcourseparam {
                   3241:     my ($self, $symb, $what) = @_;
                   3242: 
                   3243:     $self->generate_course_user_opt(); # If necessary populate the hashes.
                   3244: 
                   3245:     my $uname = $self->{USERNAME};
                   3246:     my $udom  = $self->{DOMAIN};
                   3247:     
                   3248:     # Course, section, group ids come from the env:
                   3249: 
                   3250:     my $cid   = $env{'request.course.id'};
                   3251:     my $csec  = $env{'request.course.sec'};
                   3252:     my $cgroup = '';		# Assume no group
                   3253: 
                   3254:     my @cgroups = split(/:/, $env{'request.course.groups'});
                   3255:     if(@cgroups > 0) {
                   3256: 	@cgroups = sort(@cgroups);
                   3257: 	$cgroup  = $cgroups[0];	# There is a course group. 
                   3258:    }
                   3259:     my ($mapname,$id,$fn)=&Apache::lonnet::decode_symb($symb);
                   3260:     $mapname = &Apache::lonnet::deversion($mapname);
                   3261: 
                   3262:     #
                   3263:     # Make the various lookup keys:
                   3264:     #
                   3265: 
                   3266:     $what=~s/^parameter\_//;
                   3267:     $what=~s/\_/\./;
                   3268: 
                   3269:     # Local refs to the hashes we're going to look at:
                   3270: 
                   3271:     my $useropt   = $self->{USER_OPT};
                   3272:     my $courseopt = $self->{COURSE_OPT};
                   3273: 
                   3274:     # 
                   3275:     # We want the course level stuff from the way
                   3276:     # parmval_real operates 
1.513     raeburn  3277:     # TODO: Factor some of this stuff out of
1.485     foxr     3278:     # both parmval_real and here
                   3279:     #
                   3280:     my $courselevel = $cid . '.' .  $what;
                   3281:     my $grplevel    = $cid . '.[' . $cgroup   . ']' . $what;
                   3282:     my $seclevel    = $cid . '.[' . $csec     . ']' . $what;
                   3283: 
                   3284: 
                   3285:     # Try for the user's course level option:
                   3286: 
                   3287:     if ($uname and defined($useropt)) {
                   3288: 	if (defined($$useropt{$courselevel})) {
                   3289: 	    return $$useropt{$courselevel};
                   3290: 	}
                   3291:     }
                   3292:     # Try for the group's course level option:
                   3293: 
1.513     raeburn  3294:     if ($cgroup ne '' and defined($courseopt)) {
1.485     foxr     3295: 	if (defined($$courseopt{$grplevel})) {
                   3296: 	    return $$courseopt{$grplevel};
                   3297: 	}
                   3298:     }
                   3299: 
                   3300:     #  Try for section level parameters:
                   3301: 
1.513     raeburn  3302:     if ($csec ne '' and defined($courseopt)) {
1.485     foxr     3303: 	if (defined($$courseopt{$seclevel})) {
                   3304: 	    return $$courseopt{$seclevel};
                   3305: 	}
                   3306:     }
1.513     raeburn  3307:     # Try for 'additional' course parameters:
1.485     foxr     3308: 
                   3309:     if (defined($courseopt)) {
                   3310: 	if (defined($$courseopt{$courselevel})) {
                   3311: 	    return $$courseopt{$courselevel};
                   3312: 	}
                   3313:     }
                   3314:     return undef;
                   3315: 
                   3316: }
                   3317: 
1.145     bowersj2 3318: 
1.174     albertel 3319: =pod
1.145     bowersj2 3320: 
1.352     raeburn  3321: =item * B<getResourceByUrl>(url,multiple):
1.145     bowersj2 3322: 
1.352     raeburn  3323: Retrieves a resource object by URL of the resource, unless the optional
1.398     banghart 3324: multiple parameter is included in which case an array of resource 
1.352     raeburn  3325: objects is returned. If passed a resource object, it will simply return  
                   3326: it, so it is safe to use this method in code like
                   3327: "$res = $navmap->getResourceByUrl($res)"
                   3328: if you're not sure if $res is already an object, or just a URL. If the
                   3329: resource appears multiple times in the course, only the first instance 
                   3330: will be returned (useful for maps), unless the multiple parameter has
                   3331: been included, in which case all instances are returned in an array.
1.174     albertel 3332: 
1.505     raeburn  3333: =item * B<retrieveResources>(map, filterFunc, recursive, bailout, showall, noblockcheck):
1.174     albertel 3334: 
                   3335: The map is a specification of a map to retreive the resources from,
                   3336: either as a url or as an object. The filterFunc is a reference to a
                   3337: function that takes a resource object as its one argument and returns
                   3338: true if the resource should be included, or false if it should not
                   3339: be. If recursive is true, the map will be recursively examined,
                   3340: otherwise it will not be. If bailout is true, the function will return
1.314     albertel 3341: as soon as it finds a resource, if false it will finish. If showall is
1.505     raeburn  3342: true it will not hide maps that contain nothing but one other map. The 
                   3343: noblockcheck arg is propagated to become the sixth arg in the call to
                   3344: lonnet::allowed when checking a resource's availability during collection
                   3345: of resources using the iterator. noblockcheck needs to be true if 
                   3346: retrieveResources() was called by a routine that itself was called by 
                   3347: lonnet::allowed, in order to avoid recursion.  By default the map  
                   3348: is the top-level map of the course, filterFunc is a function that 
                   3349: always returns 1, recursive is true, bailout is false, showall is
                   3350: false. The resources will be returned in a list containing the
                   3351: resource objects for the corresponding resources, with B<no structure 
                   3352: information> in the list; regardless of branching, recursion, etc.,
                   3353: it will be a flat list.
1.174     albertel 3354: 
                   3355: Thus, this is suitable for cases where you don't want the structure,
                   3356: just a list of all resources. It is also suitable for finding out how
                   3357: many resources match a given description; for this use, if all you
                   3358: want to know is if I<any> resources match the description, the bailout
                   3359: parameter will allow you to avoid potentially expensive enumeration of
                   3360: all matching resources.
1.145     bowersj2 3361: 
1.318     albertel 3362: =item * B<hasResource>(map, filterFunc, recursive, showall):
1.145     bowersj2 3363: 
1.398     banghart 3364: Convenience method for
1.146     bowersj2 3365: 
1.318     albertel 3366:  scalar(retrieveResources($map, $filterFunc, $recursive, 1, $showall)) > 0
1.146     bowersj2 3367: 
1.174     albertel 3368: which will tell whether the map has resources matching the description
                   3369: in the filter function.
1.146     bowersj2 3370: 
1.352     raeburn  3371: =item * B<usedVersion>(url):
                   3372: 
                   3373: Retrieves version infomation for a url. Returns the version (a number, or 
                   3374: the string "mostrecent") for resources which have version information in  
                   3375: the big hash.
1.448     raeburn  3376: 
1.145     bowersj2 3377: =cut
                   3378: 
1.277     matthew  3379: 
1.145     bowersj2 3380: sub getResourceByUrl {
                   3381:     my $self = shift;
                   3382:     my $resUrl = shift;
1.352     raeburn  3383:     my $multiple = shift;
1.145     bowersj2 3384: 
                   3385:     if (ref($resUrl)) { return $resUrl; }
                   3386: 
                   3387:     $resUrl = &Apache::lonnet::clutter($resUrl);
                   3388:     my $resId = $self->{NAV_HASH}->{'ids_' . $resUrl};
1.352     raeburn  3389:     if (!$resId) { return ''; }
                   3390:     if ($multiple) {
                   3391:         my @resources = ();
                   3392:         my @resIds = split (/,/, $resId);
                   3393:         foreach my $id (@resIds) {
1.353     raeburn  3394:             my $resourceId = $self->getById($id);
                   3395:             if ($resourceId) { 
                   3396:                 push(@resources,$resourceId);
1.352     raeburn  3397:             }
                   3398:         }
                   3399:         return @resources;
                   3400:     } else {
                   3401:         if ($resId =~ /,/) {
                   3402:             $resId = (split (/,/, $resId))[0];
                   3403:         }
                   3404:         return $self->getById($resId);
1.145     bowersj2 3405:     }
                   3406: }
                   3407: 
                   3408: sub retrieveResources {
                   3409:     my $self = shift;
                   3410:     my $map = shift;
                   3411:     my $filterFunc = shift;
                   3412:     if (!defined ($filterFunc)) {
                   3413:         $filterFunc = sub {return 1;};
                   3414:     }
                   3415:     my $recursive = shift;
                   3416:     if (!defined($recursive)) { $recursive = 1; }
                   3417:     my $bailout = shift;
                   3418:     if (!defined($bailout)) { $bailout = 0; }
1.314     albertel 3419:     my $showall = shift;
1.506     raeburn  3420:     my $noblockcheck = shift;
1.145     bowersj2 3421:     # Create the necessary iterator.
                   3422:     if (!ref($map)) { # assume it's a url of a map.
1.172     bowersj2 3423:         $map = $self->getResourceByUrl($map);
1.145     bowersj2 3424:     }
                   3425: 
1.213     bowersj2 3426:     # If nothing was passed, assume top-level map
                   3427:     if (!$map) {
                   3428: 	$map = $self->getById('0.0');
                   3429:     }
                   3430: 
1.145     bowersj2 3431:     # Check the map's validity.
1.213     bowersj2 3432:     if (!$map->is_map()) {
1.145     bowersj2 3433:         # Oh, to throw an exception.... how I'd love that!
                   3434:         return ();
                   3435:     }
                   3436: 
1.146     bowersj2 3437:     # Get an iterator.
                   3438:     my $it = $self->getIterator($map->map_start(), $map->map_finish(),
1.314     albertel 3439:                                 undef, $recursive, $showall);
1.146     bowersj2 3440: 
                   3441:     my @resources = ();
                   3442: 
1.400     albertel 3443:     if (&$filterFunc($map)) {
                   3444: 	push(@resources, $map);
                   3445:     }
                   3446: 
1.146     bowersj2 3447:     # Run down the iterator and collect the resources.
1.222     bowersj2 3448:     my $curRes;
                   3449: 
1.505     raeburn  3450:     while ($curRes = $it->next(undef,$noblockcheck)) {
1.146     bowersj2 3451:         if (ref($curRes)) {
                   3452:             if (!&$filterFunc($curRes)) {
                   3453:                 next;
                   3454:             }
                   3455: 
1.400     albertel 3456:             push(@resources, $curRes);
1.146     bowersj2 3457: 
                   3458:             if ($bailout) {
                   3459:                 return @resources;
                   3460:             }
                   3461:         }
                   3462: 
                   3463:     }
                   3464: 
                   3465:     return @resources;
                   3466: }
                   3467: 
                   3468: sub hasResource {
                   3469:     my $self = shift;
                   3470:     my $map = shift;
                   3471:     my $filterFunc = shift;
                   3472:     my $recursive = shift;
1.318     albertel 3473:     my $showall = shift;
1.146     bowersj2 3474:     
1.318     albertel 3475:     return scalar($self->retrieveResources($map, $filterFunc, $recursive, 1, $showall)) > 0;
1.133     bowersj2 3476: }
1.51      bowersj2 3477: 
1.352     raeburn  3478: sub usedVersion {
                   3479:     my $self = shift;
                   3480:     my $linkurl = shift;
                   3481:     return $self->navhash("version_$linkurl");
                   3482: }
                   3483: 
1.542   ! raeburn  3484: sub isFirstResource {
        !          3485:     my $self = shift;
        !          3486:     my $map = shift;
        !          3487:     my $symb = shift;
        !          3488:     return unless (ref($map));
        !          3489:     my $isfirst;
        !          3490:     my $firstResource = $map->map_start();
        !          3491:     if (ref($firstResource)) {
        !          3492:         if ((!$firstResource->is_map()) && ($firstResource->src() ne ''))  {
        !          3493:             if ($firstResource->symb() eq $symb) {
        !          3494:                 $isfirst = 1;
        !          3495:             } else {
        !          3496:                 $isfirst = 0;
        !          3497:             }
        !          3498:         } else {
        !          3499:             my $it = $self->getIterator($firstResource,undef,undef,1);
        !          3500:             while ( my $res=$it->next()) {
        !          3501:                 if ((ref($res)) && ($res->src() ne '') && (!$res->is_map())) {
        !          3502:                     if ($res->symb() eq $symb) {
        !          3503:                         $isfirst = 1;
        !          3504:                     } else {
        !          3505:                         $isfirst = 0;
        !          3506:                     }
        !          3507:                     last;
        !          3508:                 }
        !          3509:             }
        !          3510:         }
        !          3511:     }
        !          3512:     return $isfirst;
        !          3513: }
        !          3514: 
        !          3515: sub isLastResource {
        !          3516:     my $self = shift;
        !          3517:     my $map = shift;
        !          3518:     my $symb = shift;
        !          3519:     return unless (ref($map));
        !          3520:     my $islast;
        !          3521:     my $lastResource = $map->map_finish();
        !          3522:     if (ref($lastResource)) {
        !          3523:         if ((!$lastResource->is_map()) && ($lastResource->src() ne ''))  {
        !          3524:             if ($lastResource->symb() eq $symb) {
        !          3525:                 $islast = 1;
        !          3526:             } else {
        !          3527:                 $islast = 0;
        !          3528:             }
        !          3529:         } else {
        !          3530:             my $currRes = $self->getBySymb($symb);
        !          3531:             if (ref($currRes)) {
        !          3532:                 my $it = $self->getIterator($currRes,undef,undef,1);
        !          3533:                 while ( my $res=$it->next()) {
        !          3534:                     if ((ref($res)) && ($res->src() ne '') && (!$res->is_map())) {
        !          3535:                         if ($res->symb() eq $symb) {
        !          3536:                             $islast = 1;
        !          3537:                         } else {
        !          3538:                             $islast = 0;
        !          3539:                         }
        !          3540:                         last;
        !          3541:                     }
        !          3542:                 }
        !          3543:             }
        !          3544:         }
        !          3545:     }
        !          3546:     return $islast;
        !          3547: }
        !          3548: 
1.51      bowersj2 3549: 1;
                   3550: 
                   3551: package Apache::lonnavmaps::iterator;
1.365     albertel 3552: use Scalar::Util qw(weaken);
1.320     albertel 3553: use Apache::lonnet;
                   3554: 
1.51      bowersj2 3555: =pod
                   3556: 
                   3557: =back
                   3558: 
1.174     albertel 3559: =head1 Object: navmap Iterator
1.51      bowersj2 3560: 
1.174     albertel 3561: An I<iterator> encapsulates the logic required to traverse a data
                   3562: structure. navmap uses an iterator to traverse the course map
                   3563: according to the criteria you wish to use.
                   3564: 
                   3565: To obtain an iterator, call the B<getIterator>() function of a
                   3566: B<navmap> object. (Do not instantiate Apache::lonnavmaps::iterator
                   3567: directly.) This will return a reference to the iterator:
1.51      bowersj2 3568: 
                   3569: C<my $resourceIterator = $navmap-E<gt>getIterator();>
                   3570: 
                   3571: To get the next thing from the iterator, call B<next>:
                   3572: 
                   3573: C<my $nextThing = $resourceIterator-E<gt>next()>
                   3574: 
                   3575: getIterator behaves as follows:
                   3576: 
                   3577: =over 4
                   3578: 
1.174     albertel 3579: =item * B<getIterator>(firstResource, finishResource, filterHash, condition, forceTop, returnTopMap):
                   3580: 
                   3581: All parameters are optional. firstResource is a resource reference
                   3582: corresponding to where the iterator should start. It defaults to
                   3583: navmap->firstResource() for the corresponding nav map. finishResource
                   3584: corresponds to where you want the iterator to end, defaulting to
                   3585: navmap->finishResource(). filterHash is a hash used as a set
                   3586: containing strings representing the resource IDs, defaulting to
                   3587: empty. Condition is a 1 or 0 that sets what to do with the filter
1.205     bowersj2 3588: hash: If a 0, then only resources that exist IN the filterHash will be
1.174     albertel 3589: recursed on. If it is a 1, only resources NOT in the filterHash will
                   3590: be recursed on. Defaults to 0. forceTop is a boolean value. If it is
                   3591: false (default), the iterator will only return the first level of map
                   3592: that is not just a single, 'redirecting' map. If true, the iterator
                   3593: will return all information, starting with the top-level map,
                   3594: regardless of content. returnTopMap, if true (default false), will
                   3595: cause the iterator to return the top-level map object (resource 0.0)
                   3596: before anything else.
                   3597: 
                   3598: Thus, by default, only top-level resources will be shown. Change the
                   3599: condition to a 1 without changing the hash, and all resources will be
                   3600: shown. Changing the condition to 1 and including some values in the
                   3601: hash will allow you to selectively suppress parts of the navmap, while
                   3602: leaving it on 0 and adding things to the hash will allow you to
                   3603: selectively add parts of the nav map. See the handler code for
                   3604: examples.
                   3605: 
                   3606: The iterator will return either a reference to a resource object, or a
                   3607: token representing something in the map, such as the beginning of a
                   3608: new branch. The possible tokens are:
                   3609: 
                   3610: =over 4
1.51      bowersj2 3611: 
1.222     bowersj2 3612: =item * B<END_ITERATOR>:
                   3613: 
                   3614: The iterator has returned all that it's going to. Further calls to the
                   3615: iterator will just produce more of these. This is a "false" value, and
                   3616: is the only false value the iterator which will be returned, so it can
                   3617: be used as a loop sentinel.
                   3618: 
1.217     bowersj2 3619: =item * B<BEGIN_MAP>:
1.51      bowersj2 3620: 
1.174     albertel 3621: A new map is being recursed into. This is returned I<after> the map
                   3622: resource itself is returned.
1.51      bowersj2 3623: 
1.217     bowersj2 3624: =item * B<END_MAP>:
1.174     albertel 3625: 
                   3626: The map is now done.
1.51      bowersj2 3627: 
1.217     bowersj2 3628: =item * B<BEGIN_BRANCH>:
1.70      bowersj2 3629: 
1.174     albertel 3630: A branch is now starting. The next resource returned will be the first
                   3631: in that branch.
1.70      bowersj2 3632: 
1.217     bowersj2 3633: =item * B<END_BRANCH>:
1.70      bowersj2 3634: 
1.174     albertel 3635: The branch is now done.
1.51      bowersj2 3636: 
                   3637: =back
                   3638: 
1.174     albertel 3639: The tokens are retreivable via methods on the iterator object, i.e.,
                   3640: $iterator->END_MAP.
1.70      bowersj2 3641: 
1.174     albertel 3642: Maps can contain empty resources. The iterator will automatically skip
                   3643: over such resources, but will still treat the structure
                   3644: correctly. Thus, a complicated map with several branches, but
                   3645: consisting entirely of empty resources except for one beginning or
                   3646: ending resource, will cause a lot of BRANCH_STARTs and BRANCH_ENDs,
                   3647: but only one resource will be returned.
1.116     bowersj2 3648: 
1.242     matthew  3649: =back
                   3650: 
1.222     bowersj2 3651: =head2 Normal Usage
                   3652: 
                   3653: Normal usage of the iterator object is to do the following:
                   3654: 
                   3655:  my $it = $navmap->getIterator([your params here]);
                   3656:  my $curRes;
                   3657:  while ($curRes = $it->next()) {
                   3658:    [your logic here]
                   3659:  }
                   3660: 
                   3661: Note that inside of the loop, it's frequently useful to check if
                   3662: "$curRes" is a reference or not with the reference function; only
                   3663: resource objects will be references, and any non-references will 
                   3664: be the tokens described above.
                   3665: 
1.505     raeburn  3666: The next() routine can take two (optional) arguments:
                   3667: closeAllPages - if true will not recurse down a .page
                   3668: noblockcheck - passed to browsePriv() for passing as sixth arg to
                   3669: call to lonnet::allowed. This needs to be set if retrieveResources
                   3670: was already called from another routine called within lonnet::allowed, 
                   3671: so as to prevent recursion.
                   3672: 
1.506     raeburn  3673: Also note there is some old code floating around that tries to track
1.222     bowersj2 3674: the depth of the iterator to see when it's done; do not copy that 
1.398     banghart 3675: code. It is difficult to get right and harder to understand than
1.222     bowersj2 3676: this. They should be migrated to this new style.
1.51      bowersj2 3677: 
                   3678: =cut
                   3679: 
                   3680: # Here are the tokens for the iterator:
                   3681: 
1.222     bowersj2 3682: sub END_ITERATOR { return 0; }
1.51      bowersj2 3683: sub BEGIN_MAP { return 1; }    # begining of a new map
                   3684: sub END_MAP { return 2; }      # end of the map
                   3685: sub BEGIN_BRANCH { return 3; } # beginning of a branch
                   3686: sub END_BRANCH { return 4; }   # end of a branch
1.89      bowersj2 3687: sub FORWARD { return 1; }      # go forward
                   3688: sub BACKWARD { return 2; }
1.51      bowersj2 3689: 
1.96      bowersj2 3690: sub min {
                   3691:     (my $a, my $b) = @_;
                   3692:     if ($a < $b) { return $a; } else { return $b; }
                   3693: }
                   3694: 
1.94      bowersj2 3695: sub new {
                   3696:     # magic invocation to create a class instance
                   3697:     my $proto = shift;
                   3698:     my $class = ref($proto) || $proto;
                   3699:     my $self = {};
                   3700: 
1.300     albertel 3701:     weaken($self->{NAV_MAP} = shift);
1.94      bowersj2 3702:     return undef unless ($self->{NAV_MAP});
                   3703: 
1.454     www      3704:     $self->{USERNAME} = $self->{NAV_MAP}->{USERNAME};
                   3705:     $self->{DOMAIN}   = $self->{NAV_MAP}->{DOMAIN};
                   3706: 
1.94      bowersj2 3707:     # Handle the parameters
                   3708:     $self->{FIRST_RESOURCE} = shift || $self->{NAV_MAP}->firstResource();
                   3709:     $self->{FINISH_RESOURCE} = shift || $self->{NAV_MAP}->finishResource();
                   3710: 
                   3711:     # If the given resources are just the ID of the resource, get the
                   3712:     # objects
                   3713:     if (!ref($self->{FIRST_RESOURCE})) { $self->{FIRST_RESOURCE} = 
                   3714:              $self->{NAV_MAP}->getById($self->{FIRST_RESOURCE}); }
                   3715:     if (!ref($self->{FINISH_RESOURCE})) { $self->{FINISH_RESOURCE} = 
                   3716:              $self->{NAV_MAP}->getById($self->{FINISH_RESOURCE}); }
                   3717: 
                   3718:     $self->{FILTER} = shift;
                   3719: 
                   3720:     # A hash, used as a set, of resource already seen
                   3721:     $self->{ALREADY_SEEN} = shift;
                   3722:     if (!defined($self->{ALREADY_SEEN})) { $self->{ALREADY_SEEN} = {} };
                   3723:     $self->{CONDITION} = shift;
                   3724: 
1.116     bowersj2 3725:     # Do we want to automatically follow "redirection" maps?
                   3726:     $self->{FORCE_TOP} = shift;
                   3727: 
1.162     bowersj2 3728:     # Do we want to return the top-level map object (resource 0.0)?
                   3729:     $self->{RETURN_0} = shift;
                   3730:     # have we done that yet?
                   3731:     $self->{HAVE_RETURNED_0} = 0;
                   3732: 
1.94      bowersj2 3733:     # Now, we need to pre-process the map, by walking forward and backward
                   3734:     # over the parts of the map we're going to look at.
1.96      bowersj2 3735: 
1.97      bowersj2 3736:     # The processing steps are exactly the same, except for a few small 
                   3737:     # changes, so I bundle those up in the following list of two elements:
                   3738:     # (direction_to_iterate, VAL_name, next_resource_method_to_call,
                   3739:     # first_resource).
                   3740:     # This prevents writing nearly-identical code twice.
                   3741:     my @iterations = ( [FORWARD(), 'TOP_DOWN_VAL', 'getNext', 
                   3742:                         'FIRST_RESOURCE'],
                   3743:                        [BACKWARD(), 'BOT_UP_VAL', 'getPrevious', 
                   3744:                         'FINISH_RESOURCE'] );
                   3745: 
1.98      bowersj2 3746:     my $maxDepth = 0; # tracks max depth
                   3747: 
1.116     bowersj2 3748:     # If there is only one resource in this map, and it's a map, we
                   3749:     # want to remember that, so the user can ask for the first map
                   3750:     # that isn't just a redirector.
                   3751:     my $resource; my $resourceCount = 0;
                   3752: 
1.209     bowersj2 3753:     # Documentation on this algorithm can be found in the CVS repository at 
                   3754:     # /docs/lonnavdocs; these "**#**" markers correspond to documentation
                   3755:     # in that file.
1.107     bowersj2 3756:     # **1**
                   3757: 
1.97      bowersj2 3758:     foreach my $pass (@iterations) {
                   3759:         my $direction = $pass->[0];
                   3760:         my $valName = $pass->[1];
                   3761:         my $nextResourceMethod = $pass->[2];
                   3762:         my $firstResourceName = $pass->[3];
                   3763: 
                   3764:         my $iterator = Apache::lonnavmaps::DFSiterator->new($self->{NAV_MAP}, 
                   3765:                                                             $self->{FIRST_RESOURCE},
                   3766:                                                             $self->{FINISH_RESOURCE},
                   3767:                                                             {}, undef, 0, $direction);
1.96      bowersj2 3768:     
1.97      bowersj2 3769:         # prime the recursion
                   3770:         $self->{$firstResourceName}->{DATA}->{$valName} = 0;
1.222     bowersj2 3771: 	$iterator->next();
1.97      bowersj2 3772:         my $curRes = $iterator->next();
1.222     bowersj2 3773: 	my $depth = 1;
                   3774:         while ($depth > 0) {
                   3775: 	    if ($curRes == $iterator->BEGIN_MAP()) { $depth++; }
                   3776: 	    if ($curRes == $iterator->END_MAP()) { $depth--; }
                   3777: 
1.97      bowersj2 3778:             if (ref($curRes)) {
1.116     bowersj2 3779:                 # If there's only one resource, this will save it
1.117     bowersj2 3780:                 # we have to filter empty resources from consideration here,
                   3781:                 # or even "empty", redirecting maps have two (start & finish)
                   3782:                 # or three (start, finish, plus redirector)
                   3783:                 if($direction == FORWARD && $curRes->src()) { 
                   3784:                     $resource = $curRes; $resourceCount++; 
                   3785:                 }
1.97      bowersj2 3786:                 my $resultingVal = $curRes->{DATA}->{$valName};
                   3787:                 my $nextResources = $curRes->$nextResourceMethod();
1.116     bowersj2 3788:                 my $nextCount = scalar(@{$nextResources});
1.104     bowersj2 3789: 
1.116     bowersj2 3790:                 if ($nextCount == 1) { # **3**
1.97      bowersj2 3791:                     my $current = $nextResources->[0]->{DATA}->{$valName} || 999999999;
                   3792:                     $nextResources->[0]->{DATA}->{$valName} = min($resultingVal, $current);
                   3793:                 }
                   3794:                 
1.116     bowersj2 3795:                 if ($nextCount > 1) { # **4**
1.97      bowersj2 3796:                     foreach my $res (@{$nextResources}) {
                   3797:                         my $current = $res->{DATA}->{$valName} || 999999999;
                   3798:                         $res->{DATA}->{$valName} = min($current, $resultingVal + 1);
                   3799:                     }
                   3800:                 }
                   3801:             }
1.96      bowersj2 3802:             
1.107     bowersj2 3803:             # Assign the final val (**2**)
1.97      bowersj2 3804:             if (ref($curRes) && $direction == BACKWARD()) {
1.98      bowersj2 3805:                 my $finalDepth = min($curRes->{DATA}->{TOP_DOWN_VAL},
                   3806:                                      $curRes->{DATA}->{BOT_UP_VAL});
                   3807:                 
                   3808:                 $curRes->{DATA}->{DISPLAY_DEPTH} = $finalDepth;
                   3809:                 if ($finalDepth > $maxDepth) {$maxDepth = $finalDepth;}
1.190     bowersj2 3810:             }
1.222     bowersj2 3811: 
                   3812: 	    $curRes = $iterator->next();
1.96      bowersj2 3813:         }
                   3814:     }
1.94      bowersj2 3815: 
1.116     bowersj2 3816:     # Check: Was this only one resource, a map?
1.255     albertel 3817:     if ($resourceCount == 1 && $resource->is_sequence() && !$self->{FORCE_TOP}) { 
1.116     bowersj2 3818:         my $firstResource = $resource->map_start();
                   3819:         my $finishResource = $resource->map_finish();
1.500     raeburn  3820: 	return Apache::lonnavmaps::iterator->new($self->{NAV_MAP}, $firstResource,
                   3821: 						 $finishResource, $self->{FILTER},
                   3822: 						 $self->{ALREADY_SEEN}, 
                   3823: 						 $self->{CONDITION},
                   3824: 						 $self->{FORCE_TOP});
1.116     bowersj2 3825:     }
                   3826: 
1.98      bowersj2 3827:     # Set up some bookkeeping information.
                   3828:     $self->{CURRENT_DEPTH} = 0;
                   3829:     $self->{MAX_DEPTH} = $maxDepth;
                   3830:     $self->{STACK} = [];
                   3831:     $self->{RECURSIVE_ITERATOR_FLAG} = 0;
1.222     bowersj2 3832:     $self->{FINISHED} = 0; # When true, the iterator has finished
1.98      bowersj2 3833: 
                   3834:     for (my $i = 0; $i <= $self->{MAX_DEPTH}; $i++) {
                   3835:         push @{$self->{STACK}}, [];
                   3836:     }
                   3837: 
1.107     bowersj2 3838:     # Prime the recursion w/ the first resource **5**
1.98      bowersj2 3839:     push @{$self->{STACK}->[0]}, $self->{FIRST_RESOURCE};
                   3840:     $self->{ALREADY_SEEN}->{$self->{FIRST_RESOURCE}->{ID}} = 1;
                   3841: 
                   3842:     bless ($self);
                   3843:     return $self;
                   3844: }
                   3845: 
                   3846: sub next {
                   3847:     my $self = shift;
1.256     albertel 3848:     my $closeAllPages=shift;
1.505     raeburn  3849:     my $noblockcheck = shift;
1.222     bowersj2 3850:     if ($self->{FINISHED}) {
                   3851: 	return END_ITERATOR();
                   3852:     }
                   3853: 
1.162     bowersj2 3854:     # If we want to return the top-level map object, and haven't yet,
                   3855:     # do so.
                   3856:     if ($self->{RETURN_0} && !$self->{HAVE_RETURNED_0}) {
                   3857:         $self->{HAVE_RETURNED_0} = 1;
1.470     foxr     3858: 	my $nextTopLevel = $self->{NAV_MAP}->getById('0.0');
1.162     bowersj2 3859:         return $self->{NAV_MAP}->getById('0.0');
                   3860:     }
1.401     albertel 3861:     if ($self->{RETURN_0} && !$self->{HAVE_RETURNED_0_BEGIN_MAP}) {
                   3862: 	$self->{HAVE_RETURNED_0_BEGIN_MAP} = 1;
                   3863: 	return $self->BEGIN_MAP();
                   3864:     }
1.98      bowersj2 3865: 
                   3866:     if ($self->{RECURSIVE_ITERATOR_FLAG}) {
                   3867:         # grab the next from the recursive iterator 
1.256     albertel 3868:         my $next = $self->{RECURSIVE_ITERATOR}->next($closeAllPages);
1.98      bowersj2 3869: 
                   3870:         # is it a begin or end map? If so, update the depth
                   3871:         if ($next == BEGIN_MAP() ) { $self->{RECURSIVE_DEPTH}++; }
                   3872:         if ($next == END_MAP() ) { $self->{RECURSIVE_DEPTH}--; }
                   3873: 
                   3874:         # Are we back at depth 0? If so, stop recursing
                   3875:         if ($self->{RECURSIVE_DEPTH} == 0) {
                   3876:             $self->{RECURSIVE_ITERATOR_FLAG} = 0;
                   3877:         }
                   3878:         return $next;
                   3879:     }
                   3880: 
                   3881:     if (defined($self->{FORCE_NEXT})) {
                   3882:         my $tmp = $self->{FORCE_NEXT};
                   3883:         $self->{FORCE_NEXT} = undef;
                   3884:         return $tmp;
                   3885:     }
                   3886: 
                   3887:     # Have we not yet begun? If not, return BEGIN_MAP and
                   3888:     # remember we've started.
                   3889:     if ( !$self->{STARTED} ) { 
                   3890:         $self->{STARTED} = 1;
                   3891:         return $self->BEGIN_MAP();
                   3892:     }
                   3893: 
                   3894:     # Here's the guts of the iterator.
                   3895:     
                   3896:     # Find the next resource, if any.
                   3897:     my $found = 0;
                   3898:     my $i = $self->{MAX_DEPTH};
                   3899:     my $newDepth;
                   3900:     my $here;
                   3901:     while ( $i >= 0 && !$found ) {
1.107     bowersj2 3902:         if ( scalar(@{$self->{STACK}->[$i]}) > 0 ) { # **6**
                   3903:             $here = pop @{$self->{STACK}->[$i]}; # **7**
1.98      bowersj2 3904:             $found = 1;
                   3905:             $newDepth = $i;
                   3906:         }
                   3907:         $i--;
                   3908:     }
                   3909: 
                   3910:     # If we still didn't find anything, we're done.
                   3911:     if ( !$found ) {
                   3912:         # We need to get back down to the correct branch depth
                   3913:         if ( $self->{CURRENT_DEPTH} > 0 ) {
                   3914:             $self->{CURRENT_DEPTH}--;
                   3915:             return END_BRANCH();
                   3916:         } else {
1.222     bowersj2 3917: 	    $self->{FINISHED} = 1;
1.98      bowersj2 3918:             return END_MAP();
                   3919:         }
                   3920:     }
                   3921: 
1.104     bowersj2 3922:     # If this is not a resource, it must be an END_BRANCH marker we want
                   3923:     # to return directly.
1.107     bowersj2 3924:     if (!ref($here)) { # **8**
1.104     bowersj2 3925:         if ($here == END_BRANCH()) { # paranoia, in case of later extension
                   3926:             $self->{CURRENT_DEPTH}--;
                   3927:             return $here;
                   3928:         }
                   3929:     }
                   3930: 
                   3931:     # Otherwise, it is a resource and it's safe to store in $self->{HERE}
                   3932:     $self->{HERE} = $here;
                   3933: 
1.98      bowersj2 3934:     # Get to the right level
                   3935:     if ( $self->{CURRENT_DEPTH} > $newDepth ) {
                   3936:         push @{$self->{STACK}->[$newDepth]}, $here;
                   3937:         $self->{CURRENT_DEPTH}--;
                   3938:         return END_BRANCH();
                   3939:     }
                   3940:     if ( $self->{CURRENT_DEPTH} < $newDepth) {
                   3941:         push @{$self->{STACK}->[$newDepth]}, $here;
                   3942:         $self->{CURRENT_DEPTH}++;
                   3943:         return BEGIN_BRANCH();
                   3944:     }
                   3945: 
                   3946:     # If we made it here, we have the next resource, and we're at the
                   3947:     # right branch level. So let's examine the resource for where
                   3948:     # we can get to from here.
                   3949: 
                   3950:     # So we need to look at all the resources we can get to from here,
                   3951:     # categorize them if we haven't seen them, remember if we have a new
                   3952:     my $nextUnfiltered = $here->getNext();
1.470     foxr     3953: 
                   3954: 
1.104     bowersj2 3955:     my $maxDepthAdded = -1;
                   3956:     
1.98      bowersj2 3957:     for (@$nextUnfiltered) {
                   3958:         if (!defined($self->{ALREADY_SEEN}->{$_->{ID}})) {
1.104     bowersj2 3959:             my $depth = $_->{DATA}->{DISPLAY_DEPTH};
                   3960:             push @{$self->{STACK}->[$depth]}, $_;
1.98      bowersj2 3961:             $self->{ALREADY_SEEN}->{$_->{ID}} = 1;
1.104     bowersj2 3962:             if ($maxDepthAdded < $depth) { $maxDepthAdded = $depth; }
1.98      bowersj2 3963:         }
                   3964:     }
1.104     bowersj2 3965: 
                   3966:     # Is this the end of a branch? If so, all of the resources examined above
1.398     banghart 3967:     # led to lower levels than the one we are currently at, so we push a END_BRANCH
1.104     bowersj2 3968:     # marker onto the stack so we don't forget.
                   3969:     # Example: For the usual A(BC)(DE)F case, when the iterator goes down the
                   3970:     # BC branch and gets to C, it will see F as the only next resource, but it's
                   3971:     # one level lower. Thus, this is the end of the branch, since there are no
                   3972:     # more resources added to this level or above.
1.111     bowersj2 3973:     # We don't do this if the examined resource is the finish resource,
                   3974:     # because the condition given above is true, but the "END_MAP" will
                   3975:     # take care of things and we should already be at depth 0.
1.104     bowersj2 3976:     my $isEndOfBranch = $maxDepthAdded < $self->{CURRENT_DEPTH};
1.111     bowersj2 3977:     if ($isEndOfBranch && $here != $self->{FINISH_RESOURCE}) { # **9**
1.104     bowersj2 3978:         push @{$self->{STACK}->[$self->{CURRENT_DEPTH}]}, END_BRANCH();
                   3979:     }
                   3980: 
1.98      bowersj2 3981:     # That ends the main iterator logic. Now, do we want to recurse
                   3982:     # down this map (if this resource is a map)?
1.256     albertel 3983:     if ( ($self->{HERE}->is_sequence() || (!$closeAllPages && $self->{HERE}->is_page())) &&
1.98      bowersj2 3984:         (defined($self->{FILTER}->{$self->{HERE}->map_pc()}) xor $self->{CONDITION})) {
                   3985:         $self->{RECURSIVE_ITERATOR_FLAG} = 1;
                   3986:         my $firstResource = $self->{HERE}->map_start();
                   3987:         my $finishResource = $self->{HERE}->map_finish();
                   3988:         $self->{RECURSIVE_ITERATOR} = 
                   3989:             Apache::lonnavmaps::iterator->new($self->{NAV_MAP}, $firstResource,
                   3990:                                               $finishResource, $self->{FILTER},
1.314     albertel 3991:                                               $self->{ALREADY_SEEN},
                   3992: 					      $self->{CONDITION},
                   3993: 					      $self->{FORCE_TOP});
1.98      bowersj2 3994:     }
                   3995: 
1.116     bowersj2 3996:     # If this is a blank resource, don't actually return it.
1.117     bowersj2 3997:     # Should you ever find you need it, make sure to add an option to the code
                   3998:     #  that you can use; other things depend on this behavior.
1.505     raeburn  3999:     my $browsePriv = $self->{HERE}->browsePriv($noblockcheck);
1.138     bowersj2 4000:     if (!$self->{HERE}->src() || 
                   4001:         (!($browsePriv eq 'F') && !($browsePriv eq '2')) ) {
1.256     albertel 4002:         return $self->next($closeAllPages);
1.116     bowersj2 4003:     }
                   4004: 
1.98      bowersj2 4005:     return $self->{HERE};
                   4006: 
                   4007: }
                   4008: 
                   4009: =pod
                   4010: 
1.174     albertel 4011: The other method available on the iterator is B<getStack>, which
                   4012: returns an array populated with the current 'stack' of maps, as
                   4013: references to the resource objects. Example: This is useful when
                   4014: making the navigation map, as we need to check whether we are under a
                   4015: page map to see if we need to link directly to the resource, or to the
                   4016: page. The first elements in the array will correspond to the top of
                   4017: the stack (most inclusive map).
1.98      bowersj2 4018: 
                   4019: =cut
                   4020: 
                   4021: sub getStack {
                   4022:     my $self=shift;
                   4023: 
                   4024:     my @stack;
                   4025: 
                   4026:     $self->populateStack(\@stack);
                   4027: 
                   4028:     return \@stack;
                   4029: }
                   4030: 
                   4031: # Private method: Calls the iterators recursively to populate the stack.
                   4032: sub populateStack {
                   4033:     my $self=shift;
                   4034:     my $stack = shift;
                   4035: 
                   4036:     push @$stack, $self->{HERE} if ($self->{HERE});
                   4037: 
                   4038:     if ($self->{RECURSIVE_ITERATOR_FLAG}) {
                   4039:         $self->{RECURSIVE_ITERATOR}->populateStack($stack);
                   4040:     }
1.94      bowersj2 4041: }
                   4042: 
                   4043: 1;
                   4044: 
                   4045: package Apache::lonnavmaps::DFSiterator;
1.365     albertel 4046: use Scalar::Util qw(weaken);
1.320     albertel 4047: use Apache::lonnet;
                   4048: 
1.100     bowersj2 4049: # Not documented in the perldoc: This is a simple iterator that just walks
                   4050: #  through the nav map and presents the resources in a depth-first search
                   4051: #  fashion, ignorant of conditionals, randomized resources, etc. It presents
                   4052: #  BEGIN_MAP and END_MAP, but does not understand branches at all. It is
                   4053: #  useful for pre-processing of some kind, and is in fact used by the main
                   4054: #  iterator that way, but that's about it.
                   4055: # One could imagine merging this into the init routine of the main iterator,
1.251     www      4056: #  but this might as well be left separate, since it is possible some other
1.100     bowersj2 4057: #  use might be found for it. - Jeremy
1.94      bowersj2 4058: 
1.117     bowersj2 4059: # Unlike the main iterator, this DOES return all resources, even blank ones.
                   4060: #  The main iterator needs them to correctly preprocess the map.
                   4061: 
1.94      bowersj2 4062: sub BEGIN_MAP { return 1; }    # begining of a new map
                   4063: sub END_MAP { return 2; }      # end of the map
                   4064: sub FORWARD { return 1; }      # go forward
                   4065: sub BACKWARD { return 2; }
                   4066: 
1.100     bowersj2 4067: # Params: Nav map ref, first resource id/ref, finish resource id/ref,
                   4068: #         filter hash ref (or undef), already seen hash or undef, condition
                   4069: #         (as in main iterator), direction FORWARD or BACKWARD (undef->forward).
1.51      bowersj2 4070: sub new {
                   4071:     # magic invocation to create a class instance
                   4072:     my $proto = shift;
                   4073:     my $class = ref($proto) || $proto;
                   4074:     my $self = {};
                   4075: 
1.300     albertel 4076:     weaken($self->{NAV_MAP} = shift);
1.51      bowersj2 4077:     return undef unless ($self->{NAV_MAP});
                   4078: 
1.454     www      4079:     $self->{USERNAME} = $self->{NAV_MAP}->{USERNAME};
                   4080:     $self->{DOMAIN}   = $self->{NAV_MAP}->{DOMAIN};
                   4081: 
1.51      bowersj2 4082:     $self->{FIRST_RESOURCE} = shift || $self->{NAV_MAP}->firstResource();
                   4083:     $self->{FINISH_RESOURCE} = shift || $self->{NAV_MAP}->finishResource();
                   4084: 
                   4085:     # If the given resources are just the ID of the resource, get the
                   4086:     # objects
                   4087:     if (!ref($self->{FIRST_RESOURCE})) { $self->{FIRST_RESOURCE} = 
                   4088:              $self->{NAV_MAP}->getById($self->{FIRST_RESOURCE}); }
                   4089:     if (!ref($self->{FINISH_RESOURCE})) { $self->{FINISH_RESOURCE} = 
                   4090:              $self->{NAV_MAP}->getById($self->{FINISH_RESOURCE}); }
                   4091: 
                   4092:     $self->{FILTER} = shift;
                   4093: 
                   4094:     # A hash, used as a set, of resource already seen
                   4095:     $self->{ALREADY_SEEN} = shift;
1.140     bowersj2 4096:      if (!defined($self->{ALREADY_SEEN})) { $self->{ALREADY_SEEN} = {} };
1.63      bowersj2 4097:     $self->{CONDITION} = shift;
1.89      bowersj2 4098:     $self->{DIRECTION} = shift || FORWARD();
1.51      bowersj2 4099: 
1.100     bowersj2 4100:     # Flag: Have we started yet?
1.51      bowersj2 4101:     $self->{STARTED} = 0;
                   4102: 
                   4103:     # Should we continue calling the recursive iterator, if any?
                   4104:     $self->{RECURSIVE_ITERATOR_FLAG} = 0;
                   4105:     # The recursive iterator, if any
                   4106:     $self->{RECURSIVE_ITERATOR} = undef;
                   4107:     # Are we recursing on a map, or a branch?
                   4108:     $self->{RECURSIVE_MAP} = 1; # we'll manually unset this when recursing on branches
                   4109:     # And the count of how deep it is, so that this iterator can keep track of
                   4110:     # when to pick back up again.
                   4111:     $self->{RECURSIVE_DEPTH} = 0;
                   4112: 
                   4113:     # For keeping track of our branches, we maintain our own stack
1.100     bowersj2 4114:     $self->{STACK} = [];
1.51      bowersj2 4115: 
                   4116:     # Start with the first resource
1.89      bowersj2 4117:     if ($self->{DIRECTION} == FORWARD) {
1.100     bowersj2 4118:         push @{$self->{STACK}}, $self->{FIRST_RESOURCE};
1.89      bowersj2 4119:     } else {
1.100     bowersj2 4120:         push @{$self->{STACK}}, $self->{FINISH_RESOURCE};
1.89      bowersj2 4121:     }
1.51      bowersj2 4122: 
                   4123:     bless($self);
                   4124:     return $self;
                   4125: }
                   4126: 
                   4127: sub next {
                   4128:     my $self = shift;
                   4129:     
                   4130:     # Are we using a recursive iterator? If so, pull from that and
                   4131:     # watch the depth; we want to resume our level at the correct time.
1.98      bowersj2 4132:     if ($self->{RECURSIVE_ITERATOR_FLAG}) {
1.51      bowersj2 4133:         # grab the next from the recursive iterator
                   4134:         my $next = $self->{RECURSIVE_ITERATOR}->next();
                   4135:         
                   4136:         # is it a begin or end map? Update depth if so
                   4137:         if ($next == BEGIN_MAP() ) { $self->{RECURSIVE_DEPTH}++; }
                   4138:         if ($next == END_MAP() ) { $self->{RECURSIVE_DEPTH}--; }
                   4139: 
                   4140:         # Are we back at depth 0? If so, stop recursing.
                   4141:         if ($self->{RECURSIVE_DEPTH} == 0) {
                   4142:             $self->{RECURSIVE_ITERATOR_FLAG} = 0;
                   4143:         }
                   4144:         
                   4145:         return $next;
                   4146:     }
                   4147: 
                   4148:     # Is there a current resource to grab? If not, then return
1.100     bowersj2 4149:     # END_MAP, which will end the iterator.
                   4150:     if (scalar(@{$self->{STACK}}) == 0) {
                   4151:         return $self->END_MAP();
1.51      bowersj2 4152:     }
                   4153: 
                   4154:     # Have we not yet begun? If not, return BEGIN_MAP and 
                   4155:     # remember that we've started.
                   4156:     if ( !$self->{STARTED} ) {
                   4157:         $self->{STARTED} = 1;
                   4158:         return $self->BEGIN_MAP;
                   4159:     }
                   4160: 
                   4161:     # Get the next resource in the branch
1.100     bowersj2 4162:     $self->{HERE} = pop @{$self->{STACK}};
1.52      bowersj2 4163: 
1.100     bowersj2 4164:     # remember that we've seen this, so we don't return it again later
1.51      bowersj2 4165:     $self->{ALREADY_SEEN}->{$self->{HERE}->{ID}} = 1;
                   4166:     
                   4167:     # Get the next possible resources
1.90      bowersj2 4168:     my $nextUnfiltered;
1.89      bowersj2 4169:     if ($self->{DIRECTION} == FORWARD()) {
1.90      bowersj2 4170:         $nextUnfiltered = $self->{HERE}->getNext();
1.89      bowersj2 4171:     } else {
1.90      bowersj2 4172:         $nextUnfiltered = $self->{HERE}->getPrevious();
1.89      bowersj2 4173:     }
1.51      bowersj2 4174:     my $next = [];
                   4175: 
                   4176:     # filter the next possibilities to remove things we've 
1.100     bowersj2 4177:     # already seen.
1.394     raeburn  4178:     foreach my $item (@$nextUnfiltered) {
                   4179:         if (!defined($self->{ALREADY_SEEN}->{$item->{ID}})) {
                   4180:             push @$next, $item;
1.52      bowersj2 4181:         }
1.51      bowersj2 4182:     }
                   4183: 
                   4184:     while (@$next) {
1.100     bowersj2 4185:         # copy the next possibilities over to the stack
                   4186:         push @{$self->{STACK}}, shift @$next;
1.51      bowersj2 4187:     }
                   4188: 
                   4189:     # If this is a map and we want to recurse down it... (not filtered out)
1.70      bowersj2 4190:     if ($self->{HERE}->is_map() && 
1.63      bowersj2 4191:          (defined($self->{FILTER}->{$self->{HERE}->map_pc()}) xor $self->{CONDITION})) { 
1.51      bowersj2 4192:         $self->{RECURSIVE_ITERATOR_FLAG} = 1;
                   4193:         my $firstResource = $self->{HERE}->map_start();
                   4194:         my $finishResource = $self->{HERE}->map_finish();
                   4195: 
                   4196:         $self->{RECURSIVE_ITERATOR} =
1.94      bowersj2 4197:           Apache::lonnavmaps::DFSiterator->new ($self->{NAV_MAP}, $firstResource, 
1.63      bowersj2 4198:                      $finishResource, $self->{FILTER}, $self->{ALREADY_SEEN},
1.91      bowersj2 4199:                                              $self->{CONDITION}, $self->{DIRECTION});
1.51      bowersj2 4200:     }
                   4201: 
                   4202:     return $self->{HERE};
1.190     bowersj2 4203: }
                   4204: 
                   4205: # Identical to the full iterator methods of the same name. Hate to copy/paste
                   4206: # but I also hate to "inherit" either iterator from the other.
                   4207: 
                   4208: sub getStack {
                   4209:     my $self=shift;
                   4210: 
                   4211:     my @stack;
                   4212: 
                   4213:     $self->populateStack(\@stack);
                   4214: 
                   4215:     return \@stack;
                   4216: }
                   4217: 
                   4218: # Private method: Calls the iterators recursively to populate the stack.
                   4219: sub populateStack {
                   4220:     my $self=shift;
                   4221:     my $stack = shift;
                   4222: 
                   4223:     push @$stack, $self->{HERE} if ($self->{HERE});
                   4224: 
                   4225:     if ($self->{RECURSIVE_ITERATOR_FLAG}) {
                   4226:         $self->{RECURSIVE_ITERATOR}->populateStack($stack);
                   4227:     }
1.51      bowersj2 4228: }
                   4229: 
1.1       www      4230: 1;
1.2       www      4231: 
1.51      bowersj2 4232: package Apache::lonnavmaps::resource;
1.365     albertel 4233: use Scalar::Util qw(weaken);
1.51      bowersj2 4234: use Apache::lonnet;
                   4235: 
                   4236: =pod
                   4237: 
1.217     bowersj2 4238: =head1 Object: resource 
1.51      bowersj2 4239: 
1.217     bowersj2 4240: X<resource, navmap object>
1.174     albertel 4241: A resource object encapsulates a resource in a resource map, allowing
                   4242: easy manipulation of the resource, querying the properties of the
                   4243: resource (including user properties), and represents a reference that
                   4244: can be used as the canonical representation of the resource by
                   4245: lonnavmap clients like renderers.
                   4246: 
                   4247: A resource only makes sense in the context of a navmap, as some of the
                   4248: data is stored in the navmap object.
                   4249: 
                   4250: You will probably never need to instantiate this object directly. Use
                   4251: Apache::lonnavmaps::navmap, and use the "start" method to obtain the
                   4252: starting resource.
1.51      bowersj2 4253: 
1.188     bowersj2 4254: Resource objects respect the parameter_hiddenparts, which suppresses 
                   4255: various parts according to the wishes of the map author. As of this
                   4256: writing, there is no way to override this parameter, and suppressed
                   4257: parts will never be returned, nor will their response types or ids be
                   4258: stored.
                   4259: 
1.217     bowersj2 4260: =head2 Overview
1.51      bowersj2 4261: 
1.217     bowersj2 4262: A B<Resource> is the most granular type of object in LON-CAPA that can
                   4263: be included in a course. It can either be a particular resource, like
                   4264: an HTML page, external resource, problem, etc., or it can be a
                   4265: container sequence, such as a "page" or a "map".
                   4266: 
                   4267: To see a sequence from the user's point of view, please see the
                   4268: B<Creating a Course: Maps and Sequences> chapter of the Author's
                   4269: Manual.
                   4270: 
                   4271: A Resource Object, once obtained from a navmap object via a B<getBy*>
                   4272: method of the navmap, or from an iterator, allows you to query
                   4273: information about that resource.
                   4274: 
                   4275: Generally, you do not ever want to create a resource object yourself,
                   4276: so creation has been left undocumented. Always retrieve resources
                   4277: from navmap objects.
                   4278: 
                   4279: =head3 Identifying Resources
                   4280: 
                   4281: X<big hash>Every resource is identified by a Resource ID in the big hash that is
                   4282: unique to that resource for a given course. X<resource ID, in big hash>
                   4283: The Resource ID has the form #.#, where the first number is the same
                   4284: for every resource in a map, and the second is unique. For instance,
                   4285: for a course laid out like this:
                   4286: 
                   4287:  * Problem 1
                   4288:  * Map
                   4289:    * Resource 2
                   4290:    * Resource 3
                   4291: 
                   4292: C<Problem 1> and C<Map> will share a first number, and C<Resource 2>
                   4293: C<Resource 3> will share a first number. The second number may end up
                   4294: re-used between the two groups.
                   4295: 
                   4296: The resource ID is only used in the big hash, but can be used in the
                   4297: context of a course to identify a resource easily. (For instance, the
                   4298: printing system uses it to record which resources from a sequence you 
                   4299: wish to print.)
                   4300: 
                   4301: X<symb> X<resource, symb>
                   4302: All resources also have B<symb>s, which uniquely identify a resource
                   4303: in a course. Many internal LON-CAPA functions expect a symb. A symb
                   4304: carries along with it the URL of the resource, and the map it appears
1.398     banghart 4305: in. Symbs are much larger than resource IDs.
1.51      bowersj2 4306: 
                   4307: =cut
                   4308: 
                   4309: sub new {
                   4310:     # magic invocation to create a class instance
                   4311:     my $proto = shift;
                   4312:     my $class = ref($proto) || $proto;
                   4313:     my $self = {};
                   4314: 
1.300     albertel 4315:     weaken($self->{NAV_MAP} = shift);
1.51      bowersj2 4316:     $self->{ID} = shift;
                   4317: 
1.454     www      4318:     $self->{USERNAME} = $self->{NAV_MAP}->{USERNAME};
                   4319:     $self->{DOMAIN}   = $self->{NAV_MAP}->{DOMAIN};
                   4320: 
1.51      bowersj2 4321:     # Store this new resource in the parent nav map's cache.
                   4322:     $self->{NAV_MAP}->{RESOURCE_CACHE}->{$self->{ID}} = $self;
1.66      bowersj2 4323:     $self->{RESOURCE_ERROR} = 0;
1.51      bowersj2 4324: 
1.479     raeburn  4325:     $self->{DUEDATE_CACHE} = undef;
                   4326: 
1.51      bowersj2 4327:     # A hash that can be used by two-pass algorithms to store data
                   4328:     # about this resource in. Not used by the resource object
                   4329:     # directly.
                   4330:     $self->{DATA} = {};
1.508     damieng  4331:     
1.51      bowersj2 4332:     bless($self);
                   4333:     
1.508     damieng  4334:     # This is a speed optimization, to avoid calling symb() too often.
                   4335:     $self->{SYMB} = $self->symb();
1.515     raeburn  4336: 
1.51      bowersj2 4337:     return $self;
                   4338: }
                   4339: 
1.70      bowersj2 4340: # private function: simplify the NAV_HASH lookups we keep doing
                   4341: # pass the name, and to automatically append my ID, pass a true val on the
                   4342: # second param
                   4343: sub navHash {
                   4344:     my $self = shift;
                   4345:     my $param = shift;
                   4346:     my $id = shift;
1.441     raeburn  4347:     my $arg = $param . ($id?$self->{ID}:"");
1.451     raeburn  4348:     if (ref($self) && ref($self->{NAV_MAP}) && defined($arg)) {
1.441     raeburn  4349:         return $self->{NAV_MAP}->navhash($arg);
                   4350:     }
                   4351:     return;
1.70      bowersj2 4352: }
                   4353: 
1.51      bowersj2 4354: =pod
                   4355: 
1.217     bowersj2 4356: =head2 Methods
1.70      bowersj2 4357: 
1.217     bowersj2 4358: Once you have a resource object, here's what you can do with it:
                   4359: 
                   4360: =head3 Attribute Retrieval
                   4361: 
                   4362: Every resource has certain attributes that can be retrieved and used:
1.70      bowersj2 4363: 
                   4364: =over 4
                   4365: 
1.217     bowersj2 4366: =item * B<ID>: Every resource has an ID that is unique for that
                   4367:     resource in the course it is in. The ID is actually in the hash
                   4368:     representing the resource, so for a resource object $res, obtain
                   4369:     it via C<$res->{ID}).
                   4370: 
1.174     albertel 4371: =item * B<compTitle>:
                   4372: 
                   4373: Returns a "composite title", that is equal to $res->title() if the
                   4374: resource has a title, and is otherwise the last part of the URL (e.g.,
                   4375: "problem.problem").
                   4376: 
                   4377: =item * B<ext>:
                   4378: 
                   4379: Returns true if the resource is external.
                   4380: 
                   4381: =item * B<kind>:
                   4382: 
                   4383: Returns the kind of the resource from the compiled nav map.
                   4384: 
                   4385: =item * B<randomout>:
1.106     bowersj2 4386: 
1.174     albertel 4387: Returns true if this resource was chosen to NOT be shown to the user
                   4388: by the random map selection feature. In other words, this is usually
                   4389: false.
1.70      bowersj2 4390: 
1.174     albertel 4391: =item * B<randompick>:
1.70      bowersj2 4392: 
1.400     albertel 4393: Returns the number of randomly picked items for a map if the randompick
                   4394: feature is being used on the map. 
                   4395: 
                   4396: =item * B<randomorder>:
                   4397: 
                   4398: Returns true for a map if the randomorder feature is being used on the
                   4399: map.
1.70      bowersj2 4400: 
1.174     albertel 4401: =item * B<src>:
1.51      bowersj2 4402: 
1.174     albertel 4403: Returns the source for the resource.
1.70      bowersj2 4404: 
1.174     albertel 4405: =item * B<symb>:
1.70      bowersj2 4406: 
1.174     albertel 4407: Returns the symb for the resource.
1.70      bowersj2 4408: 
1.174     albertel 4409: =item * B<title>:
1.70      bowersj2 4410: 
1.174     albertel 4411: Returns the title of the resource.
                   4412: 
1.51      bowersj2 4413: =back
                   4414: 
                   4415: =cut
                   4416: 
                   4417: # These info functions can be used directly, as they don't return
                   4418: # resource information.
1.85      bowersj2 4419: sub comesfrom { my $self=shift; return $self->navHash("comesfrom_", 1); }
1.303     albertel 4420: sub encrypted { my $self=shift; return $self->navHash("encrypted_", 1); }
1.70      bowersj2 4421: sub ext { my $self=shift; return $self->navHash("ext_", 1) eq 'true:'; }
1.85      bowersj2 4422: sub from { my $self=shift; return $self->navHash("from_", 1); }
1.217     bowersj2 4423: # considered private and undocumented
1.51      bowersj2 4424: sub goesto { my $self=shift; return $self->navHash("goesto_", 1); }
                   4425: sub kind { my $self=shift; return $self->navHash("kind_", 1); }
1.68      bowersj2 4426: sub randomout { my $self=shift; return $self->navHash("randomout_", 1); }
                   4427: sub randompick { 
                   4428:     my $self = shift;
1.410     raeburn  4429:     my $randompick = $self->parmval('randompick');
                   4430:     return $randompick;
1.68      bowersj2 4431: }
1.400     albertel 4432: sub randomorder { 
                   4433:     my $self = shift;
1.410     raeburn  4434:     my $randomorder = $self->parmval('randomorder');
                   4435:     return ($randomorder =~ /^yes$/i);
1.400     albertel 4436: }
1.303     albertel 4437: sub link {
                   4438:     my $self=shift;
                   4439:     if ($self->encrypted()) { return &Apache::lonenc::encrypted($self->src); }
                   4440:     return $self->src;
                   4441: }
1.51      bowersj2 4442: sub src { 
                   4443:     my $self=shift;
                   4444:     return $self->navHash("src_", 1);
                   4445: }
1.303     albertel 4446: sub shown_symb {
                   4447:     my $self=shift;
1.508     damieng  4448:     if ($self->encrypted()) {return &Apache::lonenc::encrypted($self->{SYMB});}
                   4449:     return $self->{SYMB};
1.303     albertel 4450: }
1.328     www      4451: sub id {
                   4452:     my $self=shift;
                   4453:     return $self->{ID};
                   4454: }
                   4455: sub enclosing_map_src {
                   4456:     my $self=shift;
                   4457:     (my $first, my $second) = $self->{ID} =~ /(\d+).(\d+)/;
                   4458:     return $self->navHash('map_id_'.$first);
                   4459: }
1.51      bowersj2 4460: sub symb {
                   4461:     my $self=shift;
1.523     damieng  4462:     if (defined $self->{SYMB}) { return $self->{SYMB}; }
1.51      bowersj2 4463:     (my $first, my $second) = $self->{ID} =~ /(\d+).(\d+)/;
                   4464:     my $symbSrc = &Apache::lonnet::declutter($self->src());
1.223     albertel 4465:     my $symb = &Apache::lonnet::declutter($self->navHash('map_id_'.$first)) 
1.51      bowersj2 4466:         . '___' . $second . '___' . $symbSrc;
1.223     albertel 4467:     return &Apache::lonnet::symbclean($symb);
1.51      bowersj2 4468: }
1.321     raeburn  4469: sub wrap_symb {
                   4470:     my $self = shift;
1.508     damieng  4471:     return $self->{NAV_MAP}->wrap_symb($self->{SYMB});
1.321     raeburn  4472: }
1.213     bowersj2 4473: sub title { 
                   4474:     my $self=shift; 
                   4475:     if ($self->{ID} eq '0.0') {
                   4476: 	# If this is the top-level map, return the title of the course
                   4477: 	# since this map can not be titled otherwise.
1.320     albertel 4478: 	return $env{'course.'.$env{'request.course.id'}.'.description'};
1.213     bowersj2 4479:     }
                   4480:     return $self->navHash("title_", 1); }
1.217     bowersj2 4481: # considered private and undocumented
1.70      bowersj2 4482: sub to { my $self=shift; return $self->navHash("to_", 1); }
1.301     albertel 4483: sub condition {
                   4484:     my $self=shift;
                   4485:     my $undercond=$self->navHash("undercond_", 1);
                   4486:     if (!defined($undercond)) { return 1; };
                   4487:     my $condid=$self->navHash("condid_$undercond");
                   4488:     if (!defined($condid)) { return 1; };
                   4489:     my $condition=&Apache::lonnet::directcondval($condid);
                   4490:     return $condition;
                   4491: }
1.342     albertel 4492: sub condval {
                   4493:     my $self=shift;
1.359     albertel 4494:     my ($pathname,$filename) = 
                   4495: 	&Apache::lonnet::split_uri_for_cond($self->src());
1.342     albertel 4496: 
                   4497:     my $match=($env{'acc.res.'.$env{'request.course.id'}.'.'.$pathname}=~
                   4498: 	       /\&\Q$filename\E\:([\d\|]+)\&/);
                   4499:     if ($match) {
                   4500: 	return &Apache::lonnet::condval($1);
                   4501:     }
                   4502:     return 0;
                   4503: }
1.106     bowersj2 4504: sub compTitle {
                   4505:     my $self = shift;
                   4506:     my $title = $self->title();
1.176     www      4507:     $title=~s/\&colon\;/\:/gs;
1.106     bowersj2 4508:     if (!$title) {
                   4509:         $title = $self->src();
                   4510:         $title = substr($title, rindex($title, '/') + 1);
                   4511:     }
                   4512:     return $title;
                   4513: }
1.399     albertel 4514: 
1.70      bowersj2 4515: =pod
                   4516: 
                   4517: B<Predicate Testing the Resource>
                   4518: 
                   4519: These methods are shortcuts to deciding if a given resource has a given property.
                   4520: 
                   4521: =over 4
                   4522: 
1.174     albertel 4523: =item * B<is_map>:
                   4524: 
                   4525: Returns true if the resource is a map type.
                   4526: 
                   4527: =item * B<is_problem>:
1.70      bowersj2 4528: 
1.174     albertel 4529: Returns true if the resource is a problem type, false
                   4530: otherwise. (Looks at the extension on the src field; might need more
                   4531: to work correctly.)
1.70      bowersj2 4532: 
1.174     albertel 4533: =item * B<is_page>:
1.70      bowersj2 4534: 
1.174     albertel 4535: Returns true if the resource is a page.
                   4536: 
                   4537: =item * B<is_sequence>:
                   4538: 
                   4539: Returns true if the resource is a sequence.
1.70      bowersj2 4540: 
                   4541: =back
                   4542: 
                   4543: =cut
                   4544: 
1.256     albertel 4545: sub hasResource {
                   4546:    my $self = shift;
                   4547:    return $self->{NAV_MAP}->hasResource(@_);
                   4548: }
                   4549: 
                   4550: sub retrieveResources {
                   4551:    my $self = shift;
                   4552:    return $self->{NAV_MAP}->retrieveResources(@_);
                   4553: }
1.70      bowersj2 4554: 
1.369     albertel 4555: sub is_exam {
                   4556:     my ($self,$part) = @_;
1.410     raeburn  4557:     my $type = $self->parmval('type',$part);
                   4558:     if ($type eq 'exam') {
1.369     albertel 4559:         return 1;
                   4560:     }
                   4561:     if ($self->src() =~ /\.(exam)$/) {
                   4562:         return 1;
                   4563:     }
                   4564:     return 0;
                   4565: }
1.70      bowersj2 4566: sub is_html {
1.51      bowersj2 4567:     my $self=shift;
                   4568:     my $src = $self->src();
1.70      bowersj2 4569:     return ($src =~ /html$/);
1.51      bowersj2 4570: }
1.70      bowersj2 4571: sub is_map { my $self=shift; return defined($self->navHash("is_map_", 1)); }
                   4572: sub is_page {
1.51      bowersj2 4573:     my $self=shift;
                   4574:     my $src = $self->src();
1.205     bowersj2 4575:     return $self->navHash("is_map_", 1) && 
                   4576: 	$self->navHash("map_type_" . $self->map_pc()) eq 'page';
1.51      bowersj2 4577: }
1.361     albertel 4578: sub is_practice {
                   4579:     my $self=shift;
                   4580:     my ($part) = @_;
1.410     raeburn  4581:     my $type = $self->parmval('type',$part);
                   4582:     if ($type eq 'practice') {
1.361     albertel 4583:         return 1;
                   4584:     }
                   4585:     return 0;
                   4586: }
1.70      bowersj2 4587: sub is_problem {
1.51      bowersj2 4588:     my $self=shift;
                   4589:     my $src = $self->src();
1.466     www      4590:     if ($src =~ /$LONCAPA::assess_re/) {
1.361     albertel 4591: 	return !($self->is_practice());
                   4592:     }
                   4593:     return 0;
1.256     albertel 4594: }
1.537     raeburn  4595: sub is_tool {
                   4596:     my $self=shift;
                   4597:     my $src = $self->src();
                   4598:     return ($src =~ /ext\.tool$/);
                   4599: }
                   4600: sub is_gradable {
                   4601:     my $self=shift;
                   4602:     my $src = $self->src();
                   4603:     if (($src =~ /$LONCAPA::assess_re/) ||
                   4604:         (($self->is_tool()) && ($self->parmval('gradable',0) =~ /^yes$/i))) {
                   4605:         return !($self->is_practice());
                   4606:     }
                   4607: }
1.443     foxr     4608: #
                   4609: #  The has below is the set of status that are considered 'incomplete'
                   4610: #
                   4611: my %incomplete_hash = 
                   4612: (
                   4613:  TRIES_LEFT()     => 1,
                   4614:  OPEN()           => 1,
                   4615:  ATTEMPTED()      => 1
                   4616: 
                   4617:  );
                   4618: #
                   4619: #  Return tru if a problem is incomplete... for now incomplete means that
                   4620: #  any part of the problem is incomplete. 
                   4621: #  Note that if the resources is not a problem, 0 is returned.
                   4622: #
                   4623: sub is_incomplete {
                   4624:     my $self = shift;
                   4625:     if ($self->is_problem()) {
                   4626: 	foreach my $part (@{$self->parts()}) {
                   4627: 	    if (exists($incomplete_hash{$self->status($part)})) {
                   4628: 		return 1;
                   4629: 	    }
                   4630: 	}
                   4631:     }
                   4632:     return 0;
                   4633:        
                   4634: }
1.413     www      4635: sub is_raw_problem {
                   4636:     my $self=shift;
                   4637:     my $src = $self->src();
1.466     www      4638:     if ($src =~ /$LONCAPA::assess_re/) {
1.413     www      4639:         return 1;
                   4640:     }
                   4641:     return 0;
                   4642: }
                   4643: 
1.256     albertel 4644: sub contains_problem {
                   4645:     my $self=shift;
                   4646:     if ($self->is_page()) {
                   4647: 	my $hasProblem=$self->hasResource($self,sub { $_[0]->is_problem() },1);
                   4648: 	return $hasProblem;
                   4649:     }
                   4650:     return 0;
1.51      bowersj2 4651: }
1.401     albertel 4652: sub map_contains_problem {
                   4653:     my $self=shift;
                   4654:     if ($self->is_map()) {
                   4655: 	my $has_problem=
                   4656: 	    $self->hasResource($self,sub { $_[0]->is_problem() },1);
                   4657: 	return $has_problem;
                   4658:     }
                   4659:     return 0;
                   4660: }
1.70      bowersj2 4661: sub is_sequence {
1.51      bowersj2 4662:     my $self=shift;
1.205     bowersj2 4663:     return $self->navHash("is_map_", 1) && 
1.426     droeschl 4664:     $self->navHash("map_type_" . $self->map_pc()) eq 'sequence';
1.51      bowersj2 4665: }
1.261     matthew  4666: sub is_survey {
                   4667:     my $self = shift();
                   4668:     my $part = shift();
1.410     raeburn  4669:     my $type = $self->parmval('type',$part);
1.444     raeburn  4670:     if (($type eq 'survey') || ($type eq 'surveycred')) {
1.261     matthew  4671:         return 1;
                   4672:     }
1.263     albertel 4673:     if ($self->src() =~ /\.(survey)$/) {
1.261     matthew  4674:         return 1;
                   4675:     }
                   4676:     return 0;
                   4677: }
1.444     raeburn  4678: sub is_anonsurvey {
                   4679:     my $self = shift();
                   4680:     my $part = shift();
                   4681:     my $type = $self->parmval('type',$part);
                   4682:     if (($type eq 'anonsurvey') || ($type eq 'anonsurveycred')) {
                   4683:         return 1;
                   4684:     }
                   4685:     return 0;
                   4686: }
1.360     albertel 4687: sub is_task {
                   4688:     my $self=shift;
                   4689:     my $src = $self->src();
                   4690:     return ($src =~ /\.(task)$/)
                   4691: }
1.51      bowersj2 4692: 
1.266     raeburn  4693: sub is_empty_sequence {
                   4694:     my $self=shift;
                   4695:     my $src = $self->src();
                   4696:     return !$self->is_page() && $self->navHash("is_map_", 1) && !$self->navHash("map_type_" . $self->map_pc());
                   4697: }
                   4698: 
1.101     bowersj2 4699: # Private method: Shells out to the parmval in the nav map, handler parts.
1.51      bowersj2 4700: sub parmval {
                   4701:     my $self = shift;
                   4702:     my $what = shift;
1.185     bowersj2 4703:     my $part = shift;
                   4704:     if (!defined($part)) { 
                   4705:         $part = '0'; 
                   4706:     }
1.508     damieng  4707:     return $self->{NAV_MAP}->parmval($part.'.'.$what, $self->{SYMB});
1.51      bowersj2 4708: }
                   4709: 
1.70      bowersj2 4710: =pod
                   4711: 
                   4712: B<Map Methods>
                   4713: 
1.174     albertel 4714: These methods are useful for getting information about the map
                   4715: properties of the resource, if the resource is a map (B<is_map>).
1.70      bowersj2 4716: 
                   4717: =over 4
                   4718: 
1.174     albertel 4719: =item * B<map_finish>:
                   4720: 
                   4721: Returns a reference to a resource object corresponding to the finish
                   4722: resource of the map.
1.70      bowersj2 4723: 
1.174     albertel 4724: =item * B<map_pc>:
1.70      bowersj2 4725: 
1.174     albertel 4726: Returns the pc value of the map, which is the first number that
                   4727: appears in the resource ID of the resources in the map, and is the
                   4728: number that appears around the middle of the symbs of the resources in
                   4729: that map.
1.70      bowersj2 4730: 
1.174     albertel 4731: =item * B<map_start>:
                   4732: 
                   4733: Returns a reference to a resource object corresponding to the start
                   4734: resource of the map.
                   4735: 
                   4736: =item * B<map_type>:
                   4737: 
                   4738: Returns a string with the type of the map in it.
1.70      bowersj2 4739: 
1.497     raeburn  4740: =item * B<map_hierarchy>:
1.448     raeburn  4741: 
                   4742: Returns a string with a comma-separated ordered list of map_pc IDs
                   4743: for the hierarchy of maps containing a map, with the top level
                   4744: map first, then descending to deeper levels, with the enclosing map last.
                   4745: 
1.534     raeburn  4746: =item * B<map_breadcrumbs>:
                   4747: 
                   4748: Same as map_hierarchy, except maps containing only a single itemm if
                   4749: it's a map, or containing no items are omitted, unless it's the top
                   4750: level map (map_pc = 1), which is always included.
                   4751: 
1.70      bowersj2 4752: =back
1.51      bowersj2 4753: 
1.70      bowersj2 4754: =cut
1.51      bowersj2 4755: 
                   4756: sub map_finish {
                   4757:     my $self = shift;
                   4758:     my $src = $self->src();
1.381     albertel 4759:     $src = &Apache::lonnet::clutter($src);
1.51      bowersj2 4760:     my $res = $self->navHash("map_finish_$src", 0);
                   4761:     $res = $self->{NAV_MAP}->getById($res);
                   4762:     return $res;
                   4763: }
1.70      bowersj2 4764: sub map_pc {
                   4765:     my $self = shift;
1.381     albertel 4766:     my $src = $self->src();
1.70      bowersj2 4767:     return $self->navHash("map_pc_$src", 0);
                   4768: }
1.51      bowersj2 4769: sub map_start {
                   4770:     my $self = shift;
                   4771:     my $src = $self->src();
1.381     albertel 4772:     $src = &Apache::lonnet::clutter($src);
1.51      bowersj2 4773:     my $res = $self->navHash("map_start_$src", 0);
                   4774:     $res = $self->{NAV_MAP}->getById($res);
                   4775:     return $res;
                   4776: }
                   4777: sub map_type {
                   4778:     my $self = shift;
                   4779:     my $pc = $self->map_pc();
                   4780:     return $self->navHash("map_type_$pc", 0);
                   4781: }
1.448     raeburn  4782: sub map_hierarchy {
                   4783:     my $self = shift;
                   4784:     my $pc = $self->map_pc();
                   4785:     return $self->navHash("map_hierarchy_$pc", 0);
                   4786: }
1.534     raeburn  4787: sub map_breadcrumbs {
                   4788:     my $self = shift;
                   4789:     my $pc = $self->map_pc();
                   4790:     return $self->navHash("map_breadcrumbs_$pc", 0);
                   4791: }
1.51      bowersj2 4792: 
                   4793: #####
                   4794: # Property queries
                   4795: #####
                   4796: 
                   4797: # These functions will be responsible for returning the CORRECT
                   4798: # VALUE for the parameter, no matter what. So while they may look
1.398     banghart 4799: # like direct calls to parmval, they can be more than that.
1.51      bowersj2 4800: # So, for instance, the duedate function should use the "duedatetype"
1.398     banghart 4801: # information, rather than the resource object user.
1.51      bowersj2 4802: 
                   4803: =pod
                   4804: 
                   4805: =head2 Resource Parameters
                   4806: 
1.174     albertel 4807: In order to use the resource parameters correctly, the nav map must
                   4808: have been instantiated with genCourseAndUserOptions set to true, so
                   4809: the courseopt and useropt is read correctly. Then, you can call these
                   4810: functions to get the relevant parameters for the resource. Each
                   4811: function defaults to part "0", but can be directed to another part by
                   4812: passing the part as the parameter.
                   4813: 
                   4814: These methods are responsible for getting the parameter correct, not
                   4815: merely reflecting the contents of the GDBM hashes. As we move towards
                   4816: dates relative to other dates, these methods should be updated to
                   4817: reflect that. (Then, anybody using these methods will not have to update
                   4818: their code.)
                   4819: 
                   4820: =over 4
                   4821: 
1.485     foxr     4822: 
1.459     foxr     4823: =item * B<printable>
                   4824: 
                   4825: returns true if the current date is such that the 
                   4826: specified resource part is printable.
                   4827: 
1.485     foxr     4828: 
1.459     foxr     4829: =item * B<resprintable>
                   4830: 
                   4831: Returns true if all parts in the resource are printable making the
                   4832: entire resource printable.
                   4833: 
                   4834: =item * B<acc>
1.174     albertel 4835: 
                   4836: Get the Client IP/Name Access Control information.
1.51      bowersj2 4837: 
1.174     albertel 4838: =item * B<answerdate>:
1.51      bowersj2 4839: 
1.174     albertel 4840: Get the answer-reveal date for the problem.
                   4841: 
1.211     bowersj2 4842: =item * B<awarded>: 
                   4843: 
                   4844: Gets the awarded value for the problem part. Requires genUserData set to
                   4845: true when the navmap object was created.
                   4846: 
1.174     albertel 4847: =item * B<duedate>:
                   4848: 
                   4849: Get the due date for the problem.
                   4850: 
                   4851: =item * B<tries>:
                   4852: 
                   4853: Get the number of tries the student has used on the problem.
                   4854: 
                   4855: =item * B<maxtries>:
                   4856: 
                   4857: Get the number of max tries allowed.
                   4858: 
                   4859: =item * B<opendate>:
1.51      bowersj2 4860: 
1.174     albertel 4861: Get the open date for the problem.
1.51      bowersj2 4862: 
1.174     albertel 4863: =item * B<sig>:
1.51      bowersj2 4864: 
1.174     albertel 4865: Get the significant figures setting.
1.51      bowersj2 4866: 
1.174     albertel 4867: =item * B<tol>:
1.51      bowersj2 4868: 
1.174     albertel 4869: Get the tolerance for the problem.
1.51      bowersj2 4870: 
1.174     albertel 4871: =item * B<tries>:
1.51      bowersj2 4872: 
1.174     albertel 4873: Get the number of tries the user has already used on the problem.
1.51      bowersj2 4874: 
1.174     albertel 4875: =item * B<type>:
1.51      bowersj2 4876: 
1.174     albertel 4877: Get the question type for the problem.
1.70      bowersj2 4878: 
1.174     albertel 4879: =item * B<weight>:
1.51      bowersj2 4880: 
1.174     albertel 4881: Get the weight for the problem.
1.51      bowersj2 4882: 
                   4883: =back
                   4884: 
                   4885: =cut
                   4886: 
1.485     foxr     4887: 
                   4888: 
                   4889: 
1.459     foxr     4890: sub printable {
                   4891: 
                   4892:     my ($self, $part) = @_;
                   4893: 
                   4894:     #  The following cases apply:
1.487     foxr     4895:     #  - If a start date is not set, it is replaced by the open date.
                   4896:     #  - Ditto for start/open replaced by content open.
                   4897:     #  - If neither start nor printdates are set the part is printable.
1.459     foxr     4898:     #  - Start date set but no end date: Printable if now >= start date.
                   4899:     #  - End date set but no start date: Printable if now <= end date.
                   4900:     #  - both defined: printable if start <= now <= end
                   4901:     #
1.487     foxr     4902: 
                   4903:     # Get the print open/close dates for the resource.
                   4904: 
                   4905:     my $start = $self->parmval("printstartdate", $part);
                   4906:     my $end   = $self->parmval("printenddate", $part);
                   4907: 
                   4908:     if (!$start) {
                   4909: 	$start = $self->parmval("opendate", $part);
                   4910:     }
                   4911:     if (!$start) {
                   4912: 	$start = $self->parmval("contentopen", $part);
                   4913:     }
                   4914: 
                   4915: 
1.459     foxr     4916:     my $now  = time();
                   4917: 
1.487     foxr     4918: 
1.459     foxr     4919:     my $startok = 1;
                   4920:     my $endok   = 1;
                   4921: 
1.460     foxr     4922:     if ((defined $start) && ($start ne '')) {
1.459     foxr     4923: 	$startok = $start <= $now;
                   4924:     }
1.460     foxr     4925:     if ((defined $end) && ($end != '')) {
1.459     foxr     4926: 	$endok = $end >= $now;
                   4927:     }
                   4928:     return $startok && $endok;
                   4929: }
                   4930: 
                   4931: sub resprintable {
                   4932:     my $self = shift;
                   4933: 
                   4934:     # get parts...or realize there are no parts.
                   4935: 
1.460     foxr     4936:     my $partsref = $self->parts();
                   4937:     my @parts    = @$partsref;
                   4938: 
1.489     raeburn  4939:     if (!@parts) {
1.459     foxr     4940: 	return $self->printable(0);
                   4941:     } else {
1.460     foxr     4942: 	foreach my $part  (@parts) {
                   4943: 	    if (!$self->printable($part)) { 
                   4944: 		return 0; 
                   4945: 	    }
1.459     foxr     4946: 	}
                   4947: 	return 1;
                   4948:     }
                   4949: }
                   4950: 
1.51      bowersj2 4951: sub acc {
                   4952:     (my $self, my $part) = @_;
1.410     raeburn  4953:     my $acc = $self->parmval("acc", $part);
                   4954:     return $acc;
1.51      bowersj2 4955: }
                   4956: sub answerdate {
                   4957:     (my $self, my $part) = @_;
                   4958:     # Handle intervals
1.410     raeburn  4959:     my $answerdatetype = $self->parmval("answerdate.type", $part);
                   4960:     my $answerdate = $self->parmval("answerdate", $part);
                   4961:     my $duedate = $self->parmval("duedate", $part);
                   4962:     if ($answerdatetype eq 'date_interval') {
                   4963:         $answerdate = $duedate + $answerdate; 
1.51      bowersj2 4964:     }
1.410     raeburn  4965:     return $answerdate;
1.106     bowersj2 4966: }
1.211     bowersj2 4967: sub awarded { 
                   4968:     my $self = shift; my $part = shift;
1.221     bowersj2 4969:     $self->{NAV_MAP}->get_user_data();
1.211     bowersj2 4970:     if (!defined($part)) { $part = '0'; }
1.508     damieng  4971:     return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$part.'.awarded'};
1.211     bowersj2 4972: }
1.432     raeburn  4973: sub taskversion {
                   4974:     my $self = shift; my $part = shift;
                   4975:     $self->{NAV_MAP}->get_user_data();
                   4976:     if (!defined($part)) { $part = '0'; }
1.508     damieng  4977:     return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$part.'.version'};
1.432     raeburn  4978: }
                   4979: sub taskstatus {
                   4980:     my $self = shift; my $part = shift;
                   4981:     $self->{NAV_MAP}->get_user_data();
                   4982:     if (!defined($part)) { $part = '0'; }
1.508     damieng  4983:     return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$self->taskversion($part).'.'.$part.'.status'};
1.432     raeburn  4984: }
                   4985: sub solved {
                   4986:     my $self = shift; my $part = shift;
                   4987:     $self->{NAV_MAP}->get_user_data();
                   4988:     if (!defined($part)) { $part = '0'; }
1.508     damieng  4989:     return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$part.'.solved'};
1.432     raeburn  4990: }
                   4991: sub checkedin {
                   4992:     my $self = shift; my $part = shift;
                   4993:     $self->{NAV_MAP}->get_user_data();
                   4994:     if (!defined($part)) { $part = '0'; }
                   4995:     if ($self->is_task()) {
                   4996:         my $version = $self->taskversion($part);
1.508     damieng  4997:         return ($self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$version .'.'.$part.'.checkedin'},$self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$version .'.'.$part.'.checkedin.slot'});
1.432     raeburn  4998:     } else {
1.508     damieng  4999:         return ($self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$part.'.checkedin'},$self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$part.'.checkedin.slot'});
1.432     raeburn  5000:     }
                   5001: }
1.382     albertel 5002: # this should work exactly like the copy in lonhomework.pm
1.459     foxr     5003: # Why is there a copy in lonhomework?  Why not centralized?
                   5004: #
                   5005: #  TODO: Centralize duedate.
                   5006: #
                   5007: 
1.51      bowersj2 5008: sub duedate {
                   5009:     (my $self, my $part) = @_;
1.479     raeburn  5010:     if (defined ($self->{DUEDATE_CACHE}->{$part})) {
                   5011:         return $self->{DUEDATE_CACHE}->{$part};
                   5012:     }
1.382     albertel 5013:     my $date;
1.406     albertel 5014:     my @interval=$self->parmval("interval", $part);
1.382     albertel 5015:     my $due_date=$self->parmval("duedate", $part);
1.520     raeburn  5016:     if ($interval[0] =~ /^(\d+)/) {
                   5017:         my $timelimit = $1;
                   5018:         my $first_access=&Apache::lonnet::get_first_access($interval[1],
                   5019:                                                            $self->{SYMB});
1.382     albertel 5020: 	if (defined($first_access)) {
1.520     raeburn  5021:             my $interval = $first_access+$timelimit;
1.404     albertel 5022: 	    $date = (!$due_date || $interval < $due_date) ? $interval 
                   5023:                                                           : $due_date;
1.382     albertel 5024: 	} else {
                   5025: 	    $date = $due_date;
                   5026: 	}
                   5027:     } else {
                   5028: 	$date = $due_date;
1.260     albertel 5029:     }
1.479     raeburn  5030:     $self->{DUEDATE_CACHE}->{$part} = $date;
1.382     albertel 5031:     return $date;
1.51      bowersj2 5032: }
1.334     albertel 5033: sub handgrade {
                   5034:     (my $self, my $part) = @_;
1.399     albertel 5035:     my @response_ids = $self->responseIds($part);
                   5036:     if (@response_ids) {
                   5037: 	foreach my $response_id (@response_ids) {
1.410     raeburn  5038:             my $handgrade = $self->parmval("handgrade",$part.'_'.$response_id);
                   5039: 	    if (lc($handgrade) eq 'yes') {
1.399     albertel 5040: 		return 'yes';
                   5041: 	    }
                   5042: 	}
                   5043:     }
1.410     raeburn  5044:     my $handgrade = $self->parmval("handgrade", $part);
                   5045:     return $handgrade;
1.334     albertel 5046: }
1.51      bowersj2 5047: sub maxtries {
                   5048:     (my $self, my $part) = @_;
1.410     raeburn  5049:     my $maxtries = $self->parmval("maxtries", $part);
                   5050:     return $maxtries;
1.51      bowersj2 5051: }
                   5052: sub opendate {
                   5053:     (my $self, my $part) = @_;
1.410     raeburn  5054:     my $opendatetype = $self->parmval("opendate.type", $part);
                   5055:     my $opendate = $self->parmval("opendate", $part); 
                   5056:     if ($opendatetype eq 'date_interval') {
                   5057:         my $duedate = $self->duedate($part);
                   5058:         $opendate = $duedate - $opendate; 
1.51      bowersj2 5059:     }
1.410     raeburn  5060:     return $opendate;
1.51      bowersj2 5061: }
1.185     bowersj2 5062: sub problemstatus {
                   5063:     (my $self, my $part) = @_;
1.410     raeburn  5064:     my $problemstatus = $self->parmval("problemstatus", $part);
                   5065:     return lc($problemstatus);
1.185     bowersj2 5066: }
1.51      bowersj2 5067: sub sig {
                   5068:     (my $self, my $part) = @_;
1.410     raeburn  5069:     my $sig = $self->parmval("sig", $part);
                   5070:     return $sig;
1.51      bowersj2 5071: }
                   5072: sub tol {
                   5073:     (my $self, my $part) = @_;
1.410     raeburn  5074:     my $tol = $self->parmval("tol", $part);
                   5075:     return $tol;
1.51      bowersj2 5076: }
1.410     raeburn  5077: sub tries {
1.108     bowersj2 5078:     my $self = shift; 
                   5079:     my $tries = $self->queryRestoreHash('tries', shift);
                   5080:     if (!defined($tries)) { return '0';}
1.51      bowersj2 5081:     return $tries;
                   5082: }
1.70      bowersj2 5083: sub type {
                   5084:     (my $self, my $part) = @_;
1.410     raeburn  5085:     my $type = $self->parmval("type", $part);
                   5086:     return $type;
1.70      bowersj2 5087: }
1.109     bowersj2 5088: sub weight { 
                   5089:     my $self = shift; my $part = shift;
1.211     bowersj2 5090:     if (!defined($part)) { $part = '0'; }
1.409     raeburn  5091:     my $weight = &Apache::lonnet::EXT('resource.'.$part.'.weight',
1.508     damieng  5092:                                 $self->{SYMB}, $self->{DOMAIN},
1.453     www      5093:                                 $self->{USERNAME},
1.409     raeburn  5094:                                 $env{'request.course.sec'});
                   5095:     return $weight;
1.274     matthew  5096: }
                   5097: sub part_display {
                   5098:     my $self= shift(); my $partID = shift();
                   5099:     if (! defined($partID)) { $partID = '0'; }
                   5100:     my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',
1.514     raeburn  5101:                                      $self->{SYMB});
1.274     matthew  5102:     if (! defined($display) || $display eq '') {
                   5103:         $display = $partID;
                   5104:     }
                   5105:     return $display;
1.70      bowersj2 5106: }
1.432     raeburn  5107: sub slot_control {
                   5108:     my $self=shift(); my $part = shift();
                   5109:     if (!defined($part)) { $part = '0'; }
                   5110:     my $useslots = $self->parmval("useslots", $part);
                   5111:     my $availablestudent = $self->parmval("availablestudent", $part);
                   5112:     my $available = $self->parmval("available", $part); 
                   5113:     return ($useslots,$availablestudent,$available);
                   5114: }
1.51      bowersj2 5115: 
                   5116: # Multiple things need this
                   5117: sub getReturnHash {
                   5118:     my $self = shift;
                   5119:     
                   5120:     if (!defined($self->{RETURN_HASH})) {
1.524     damieng  5121:         #my %tmpHash  = &Apache::lonnet::restore($self->{SYMB},undef,$self->{DOMAIN},$self->{USERNAME});
                   5122:         #$self->{RETURN_HASH} = \%tmpHash;
                   5123:         # When info is retrieved for several resources (as when rendering a directory),
                   5124:         # it is much faster to use the user profile dump and avoid repeated lonnet requests
                   5125:         # (especially since lonnet::currentdump is using Lond directly whenever possible,
                   5126:         # and lonnet::restore is not at this point).
                   5127:         $self->{NAV_MAP}->get_user_data();
                   5128:         $self->{RETURN_HASH} = $self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}};
1.51      bowersj2 5129:     }
                   5130: }       
                   5131: 
                   5132: ######
                   5133: # Status queries
                   5134: ######
                   5135: 
                   5136: # These methods query the status of problems.
                   5137: 
                   5138: # If we need to count parts, this function determines the number of
                   5139: # parts from the metadata. When called, it returns a reference to a list
                   5140: # of strings corresponding to the parts. (Thus, using it in a scalar context
                   5141: # tells you how many parts you have in the problem:
                   5142: # $partcount = scalar($resource->countParts());
                   5143: # Don't use $self->{PARTS} directly because you don't know if it's been
                   5144: # computed yet.
                   5145: 
                   5146: =pod
                   5147: 
                   5148: =head2 Resource misc
                   5149: 
                   5150: Misc. functions for the resource.
                   5151: 
                   5152: =over 4
                   5153: 
1.174     albertel 5154: =item * B<hasDiscussion>:
1.59      bowersj2 5155: 
1.174     albertel 5156: Returns a false value if there has been discussion since the user last
                   5157: logged in, true if there has. Always returns false if the discussion
                   5158: data was not extracted when the nav map was constructed.
                   5159: 
1.366     albertel 5160: =item * B<last_post_time>:
                   5161: 
                   5162: Returns a false value if there hasn't been discussion otherwise returns
                   5163: unix timestamp of last time a discussion posting (or edit) was made.
                   5164: 
1.393     raeburn  5165: =item * B<discussion_info>:
1.366     albertel 5166: 
1.393     raeburn  5167: optional argument is a filter (currently can be 'unread');
                   5168: returns in scalar context the count of the number of discussion postings.
1.366     albertel 5169: 
                   5170: returns in list context both the count of postings and a hash ref
1.393     raeburn  5171: containing information about the postings (subject, id, timestamp) in a hash.
                   5172: 
                   5173: Default is to return counts for all postings.  However if called with a second argument set to 'unread', will return information about only unread postings.
1.366     albertel 5174: 
1.174     albertel 5175: =item * B<getFeedback>:
                   5176: 
                   5177: Gets the feedback for the resource and returns the raw feedback string
                   5178: for the resource, or the null string if there is no feedback or the
                   5179: email data was not extracted when the nav map was constructed. Usually
                   5180: used like this:
1.59      bowersj2 5181: 
1.394     raeburn  5182:  for my $url (split(/\,/, $res->getFeedback())) {
                   5183:     my $link = &escape($url);
1.59      bowersj2 5184:     ...
                   5185: 
                   5186: and use the link as appropriate.
                   5187: 
                   5188: =cut
                   5189: 
                   5190: sub hasDiscussion {
                   5191:     my $self = shift;
1.508     damieng  5192:     return $self->{NAV_MAP}->hasDiscussion($self->{SYMB});
1.59      bowersj2 5193: }
                   5194: 
1.366     albertel 5195: sub last_post_time {
                   5196:     my $self = shift;
1.508     damieng  5197:     return $self->{NAV_MAP}->last_post_time($self->{SYMB});
1.366     albertel 5198: }
                   5199: 
1.393     raeburn  5200: sub discussion_info {
                   5201:     my ($self,$filter) = @_;
1.508     damieng  5202:     return $self->{NAV_MAP}->discussion_info($self->{SYMB},$filter);
1.366     albertel 5203: }
                   5204: 
1.59      bowersj2 5205: sub getFeedback {
                   5206:     my $self = shift;
1.124     bowersj2 5207:     my $source = $self->src();
1.508     damieng  5208:     my $symb = $self->{SYMB};
1.125     bowersj2 5209:     if ($source =~ /^\/res\//) { $source = substr $source, 5; }
1.395     raeburn  5210:     return $self->{NAV_MAP}->getFeedback($symb,$source);
1.124     bowersj2 5211: }
                   5212: 
                   5213: sub getErrors {
                   5214:     my $self = shift;
                   5215:     my $source = $self->src();
1.508     damieng  5216:     my $symb = $self->{SYMB};
1.124     bowersj2 5217:     if ($source =~ /^\/res\//) { $source = substr $source, 5; }
1.395     raeburn  5218:     return $self->{NAV_MAP}->getErrors($symb,$source);
1.59      bowersj2 5219: }
                   5220: 
                   5221: =pod
                   5222: 
1.174     albertel 5223: =item * B<parts>():
1.51      bowersj2 5224: 
1.174     albertel 5225: Returns a list reference containing sorted strings corresponding to
1.193     bowersj2 5226: each part of the problem. Single part problems have only a part '0'.
                   5227: Multipart problems do not return their part '0', since they typically
                   5228: do not really matter. 
1.174     albertel 5229: 
                   5230: =item * B<countParts>():
                   5231: 
                   5232: Returns the number of parts of the problem a student can answer. Thus,
                   5233: for single part problems, returns 1. For multipart, it returns the
1.193     bowersj2 5234: number of parts in the problem, not including psuedo-part 0. 
1.51      bowersj2 5235: 
1.290     matthew  5236: =item * B<countResponses>():
                   5237: 
                   5238: Returns the total number of responses in the problem a student can answer.
                   5239: 
                   5240: =item * B<responseTypes>():
                   5241: 
                   5242: Returns a hash whose keys are the response types.  The values are the number 
                   5243: of times each response type is used.  This is for the I<entire> problem, not 
                   5244: just a single part.
                   5245: 
1.192     bowersj2 5246: =item * B<multipart>():
                   5247: 
1.193     bowersj2 5248: Returns true if the problem is multipart, false otherwise. Use this instead
                   5249: of countParts if all you want is multipart/not multipart.
1.192     bowersj2 5250: 
1.187     bowersj2 5251: =item * B<responseType>($part):
                   5252: 
                   5253: Returns the response type of the part, without the word "response" on the
                   5254: end. Example return values: 'string', 'essay', 'numeric', etc.
                   5255: 
1.193     bowersj2 5256: =item * B<responseIds>($part):
1.187     bowersj2 5257: 
1.193     bowersj2 5258: Retreives the response IDs for the given part as an array reference containing
                   5259: strings naming the response IDs. This may be empty.
1.187     bowersj2 5260: 
1.51      bowersj2 5261: =back
                   5262: 
                   5263: =cut
                   5264: 
                   5265: sub parts {
                   5266:     my $self = shift;
                   5267: 
1.192     bowersj2 5268:     if ($self->ext) { return []; }
1.537     raeburn  5269:     if (($self->is_tool()) &&
                   5270:         ($self->is_gradable())) { return ['0']; }
1.67      bowersj2 5271: 
1.51      bowersj2 5272:     $self->extractParts();
                   5273:     return $self->{PARTS};
                   5274: }
                   5275: 
                   5276: sub countParts {
                   5277:     my $self = shift;
                   5278:     
                   5279:     my $parts = $self->parts();
1.191     bowersj2 5280: 
                   5281:     # If I left this here, then it's not necessary.
                   5282:     #my $delta = 0;
                   5283:     #for my $part (@$parts) {
                   5284:     #    if ($part eq '0') { $delta--; }
                   5285:     #}
1.66      bowersj2 5286: 
                   5287:     if ($self->{RESOURCE_ERROR}) {
                   5288:         return 0;
                   5289:     }
                   5290: 
1.191     bowersj2 5291:     return scalar(@{$parts}); # + $delta;
1.192     bowersj2 5292: }
                   5293: 
1.290     matthew  5294: sub countResponses {
                   5295:     my $self = shift;
                   5296:     my $count;
1.293     matthew  5297:     foreach my $part (@{$self->parts()}) {
                   5298:         $count+= scalar($self->responseIds($part));
1.290     matthew  5299:     }
                   5300:     return $count;
                   5301: }
                   5302: 
                   5303: sub responseTypes {
                   5304:     my $self = shift;
1.291     albertel 5305:     my %responses;
1.368     raeburn  5306:     foreach my $part (@{$self->parts()}) {
1.290     matthew  5307:         foreach my $responsetype ($self->responseType($part)) {
1.291     albertel 5308:             $responses{$responsetype}++ if (defined($responsetype));
1.290     matthew  5309:         }
                   5310:     }
1.291     albertel 5311:     return %responses;
1.290     matthew  5312: }
                   5313: 
1.192     bowersj2 5314: sub multipart {
                   5315:     my $self = shift;
                   5316:     return $self->countParts() > 1;
1.51      bowersj2 5317: }
                   5318: 
1.225     bowersj2 5319: sub singlepart {
                   5320:     my $self = shift;
                   5321:     return $self->countParts() == 1;
                   5322: }
                   5323: 
1.187     bowersj2 5324: sub responseType {
1.184     bowersj2 5325:     my $self = shift;
                   5326:     my $part = shift;
                   5327: 
                   5328:     $self->extractParts();
1.235     albertel 5329:     if (defined($self->{RESPONSE_TYPES}->{$part})) {
                   5330: 	return @{$self->{RESPONSE_TYPES}->{$part}};
                   5331:     } else {
                   5332: 	return undef;
                   5333:     }
1.187     bowersj2 5334: }
                   5335: 
1.193     bowersj2 5336: sub responseIds {
1.187     bowersj2 5337:     my $self = shift;
                   5338:     my $part = shift;
                   5339: 
                   5340:     $self->extractParts();
1.235     albertel 5341:     if (defined($self->{RESPONSE_IDS}->{$part})) {
                   5342: 	return @{$self->{RESPONSE_IDS}->{$part}};
                   5343:     } else {
                   5344: 	return undef;
                   5345:     }
1.184     bowersj2 5346: }
                   5347: 
                   5348: # Private function: Extracts the parts information, both part names and
1.187     bowersj2 5349: # part types, and saves it. 
1.51      bowersj2 5350: sub extractParts { 
                   5351:     my $self = shift;
                   5352:     
1.153     bowersj2 5353:     return if (defined($self->{PARTS}));
1.67      bowersj2 5354:     return if ($self->ext);
1.51      bowersj2 5355: 
                   5356:     $self->{PARTS} = [];
                   5357: 
1.181     bowersj2 5358:     my %parts;
                   5359: 
1.82      bowersj2 5360:     # Retrieve part count, if this is a problem
1.531     raeburn  5361:     if ($self->is_raw_problem()) {
1.240     albertel 5362: 	my $partorder = &Apache::lonnet::metadata($self->src(), 'partorder');
1.152     matthew  5363:         my $metadata = &Apache::lonnet::metadata($self->src(), 'packages');
1.181     bowersj2 5364: 
1.239     bowersj2 5365: 	if ($partorder) {
                   5366: 	    my @parts;
                   5367: 	    for my $part (split (/,/,$partorder)) {
1.508     damieng  5368: 		if (!Apache::loncommon::check_if_partid_hidden($part, $self->{SYMB})) {
1.239     bowersj2 5369: 		    push @parts, $part;
1.241     albertel 5370: 		    $parts{$part} = 1;
1.239     bowersj2 5371: 		}
                   5372: 	    }
                   5373: 	    $self->{PARTS} = \@parts;
                   5374: 	} else {
                   5375: 	    if (!$metadata) {
                   5376: 		$self->{RESOURCE_ERROR} = 1;
                   5377: 		$self->{PARTS} = [];
                   5378: 		$self->{PART_TYPE} = {};
                   5379: 		return;
                   5380: 	    }
1.394     raeburn  5381: 	    foreach my $entry (split(/\,/,$metadata)) {
                   5382: 		if ($entry =~ /^(?:part|Task)_(.*)$/) {
1.239     bowersj2 5383: 		    my $part = $1;
                   5384: 		    # This floods the logs if it blows up
                   5385: 		    if (defined($parts{$part})) {
1.508     damieng  5386: 			&Apache::lonnet::logthis("$part multiply defined in metadata for " . $self->{SYMB});
1.241     albertel 5387: 		    }
1.239     bowersj2 5388: 		    
                   5389: 		    # check to see if part is turned off.
                   5390: 		    
1.508     damieng  5391: 		    if (!Apache::loncommon::check_if_partid_hidden($part, $self->{SYMB})) {
1.239     bowersj2 5392: 			$parts{$part} = 1;
                   5393: 		    }
                   5394: 		}
                   5395: 	    }
1.504     raeburn  5396: 	    my @sortedParts = sort(keys(%parts));
1.239     bowersj2 5397: 	    $self->{PARTS} = \@sortedParts;
1.51      bowersj2 5398:         }
1.82      bowersj2 5399:         
1.187     bowersj2 5400: 
1.284     matthew  5401:         # These hashes probably do not need names that end with "Hash"....
1.187     bowersj2 5402:         my %responseIdHash;
                   5403:         my %responseTypeHash;
                   5404: 
1.189     bowersj2 5405: 
                   5406:         # Init the responseIdHash
1.394     raeburn  5407:         foreach my $part (@{$self->{PARTS}}) {
                   5408:             $responseIdHash{$part} = [];
1.189     bowersj2 5409:         }
                   5410: 
1.187     bowersj2 5411:         # Now, the unfortunate thing about this is that parts, part name, and
1.239     bowersj2 5412:         # response id are delimited by underscores, but both the part
1.187     bowersj2 5413:         # name and response id can themselves have underscores in them.
                   5414:         # So we have to use our knowlege of part names to figure out 
                   5415:         # where the part names begin and end, and even then, it is possible
                   5416:         # to construct ambiguous situations.
1.504     raeburn  5417:         foreach my $data (split(/,/, $metadata)) {
1.379     albertel 5418:             if ($data =~ /^([a-zA-Z]+)response_(.*)/
                   5419: 		|| $data =~ /^(Task)_(.*)/) {
1.187     bowersj2 5420:                 my $responseType = $1;
                   5421:                 my $partStuff = $2;
                   5422:                 my $partIdSoFar = '';
1.504     raeburn  5423:                 my @partChunks = split(/_/, $partStuff);
1.187     bowersj2 5424:                 my $i = 0;
                   5425:                 for ($i = 0; $i < scalar(@partChunks); $i++) {
                   5426:                     if ($partIdSoFar) { $partIdSoFar .= '_'; }
                   5427:                     $partIdSoFar .= $partChunks[$i];
                   5428:                     if ($parts{$partIdSoFar}) {
                   5429:                         my @otherChunks = @partChunks[$i+1..$#partChunks];
                   5430:                         my $responseId = join('_', @otherChunks);
1.379     albertel 5431: 			if ($self->is_task()) {
                   5432: 			    push(@{$responseIdHash{$partIdSoFar}},
                   5433: 				 $partIdSoFar);
                   5434: 			} else {
                   5435: 			    push(@{$responseIdHash{$partIdSoFar}},
                   5436: 				 $responseId);
                   5437: 			}
                   5438:                         push(@{$responseTypeHash{$partIdSoFar}},
                   5439: 			     $responseType);
1.187     bowersj2 5440:                     }
                   5441:                 }
                   5442:             }
                   5443:         }
1.264     albertel 5444: 	my $resorder = &Apache::lonnet::metadata($self->src(),'responseorder');
1.284     matthew  5445:         #
                   5446:         # Reorder the arrays in the %responseIdHash and %responseTypeHash
1.264     albertel 5447: 	if ($resorder) {
                   5448: 	    my @resorder=split(/,/,$resorder);
                   5449: 	    foreach my $part (keys(%responseIdHash)) {
1.286     albertel 5450: 		my $i=0;
                   5451: 		my %resids = map { ($_,$i++) } @{ $responseIdHash{$part} };
1.264     albertel 5452: 		my @neworder;
                   5453: 		foreach my $possibleid (@resorder) {
                   5454: 		    if (exists($resids{$possibleid})) {
1.286     albertel 5455: 			push(@neworder,$resids{$possibleid});
1.264     albertel 5456: 		    }
                   5457: 		}
1.286     albertel 5458: 		my @ids;
                   5459: 		my @type;
                   5460: 		foreach my $element (@neworder) {
                   5461: 		    push (@ids,$responseIdHash{$part}->[$element]);
                   5462: 		    push (@type,$responseTypeHash{$part}->[$element]);
                   5463: 		}
                   5464: 		$responseIdHash{$part}=\@ids;
                   5465: 		$responseTypeHash{$part}=\@type;
1.264     albertel 5466: 	    }
                   5467: 	}
1.187     bowersj2 5468:         $self->{RESPONSE_IDS} = \%responseIdHash;
                   5469:         $self->{RESPONSE_TYPES} = \%responseTypeHash;
1.154     bowersj2 5470:     }
                   5471: 
1.51      bowersj2 5472:     return;
                   5473: }
                   5474: 
                   5475: =pod
                   5476: 
                   5477: =head2 Resource Status
                   5478: 
1.174     albertel 5479: Problem resources have status information, reflecting their various
                   5480: dates and completion statuses.
1.51      bowersj2 5481: 
1.174     albertel 5482: There are two aspects to the status: the date-related information and
                   5483: the completion information.
1.51      bowersj2 5484: 
1.174     albertel 5485: Idiomatic usage of these two methods would probably look something
                   5486: like
1.51      bowersj2 5487: 
1.394     raeburn  5488:  foreach my $part ($resource->parts()) {
                   5489:     my $dateStatus = $resource->getDateStatus($part);
                   5490:     my $completionStatus = $resource->getCompletionStatus($part);
1.51      bowersj2 5491: 
1.70      bowersj2 5492:     or
                   5493: 
1.394     raeburn  5494:     my $status = $resource->status($part);
1.70      bowersj2 5495: 
1.51      bowersj2 5496:     ... use it here ...
                   5497:  }
                   5498: 
1.174     albertel 5499: Which you use depends on exactly what you are looking for. The
                   5500: status() function has been optimized for the nav maps display and may
                   5501: not precisely match what you need elsewhere.
1.101     bowersj2 5502: 
1.174     albertel 5503: The symbolic constants shown below can be accessed through the
                   5504: resource object: C<$res->OPEN>.
1.101     bowersj2 5505: 
1.51      bowersj2 5506: =over 4
                   5507: 
1.174     albertel 5508: =item * B<getDateStatus>($part):
                   5509: 
                   5510: ($part defaults to 0). A convenience function that returns a symbolic
                   5511: constant telling you about the date status of the part. The possible
                   5512: return values are:
1.51      bowersj2 5513: 
                   5514: =back
                   5515: 
                   5516: B<Date Codes>
                   5517: 
                   5518: =over 4
                   5519: 
1.174     albertel 5520: =item * B<OPEN_LATER>:
                   5521: 
                   5522: The problem will be opened later.
                   5523: 
                   5524: =item * B<OPEN>:
                   5525: 
                   5526: Open and not yet due.
                   5527: 
1.51      bowersj2 5528: 
1.174     albertel 5529: =item * B<PAST_DUE_ANSWER_LATER>:
1.51      bowersj2 5530: 
1.174     albertel 5531: The due date has passed, but the answer date has not yet arrived.
1.59      bowersj2 5532: 
1.174     albertel 5533: =item * B<PAST_DUE_NO_ANSWER>:
1.54      bowersj2 5534: 
1.174     albertel 5535: The due date has passed and there is no answer opening date set.
1.51      bowersj2 5536: 
1.174     albertel 5537: =item * B<ANSWER_OPEN>:
1.51      bowersj2 5538: 
1.174     albertel 5539: The answer date is here.
                   5540: 
                   5541: =item * B<NETWORK_FAILURE>:
                   5542: 
                   5543: The information is unknown due to network failure.
1.51      bowersj2 5544: 
                   5545: =back
                   5546: 
                   5547: =cut
                   5548: 
                   5549: # Apparently the compiler optimizes these into constants automatically
1.54      bowersj2 5550: sub OPEN_LATER             { return 0; }
                   5551: sub OPEN                   { return 1; }
                   5552: sub PAST_DUE_NO_ANSWER     { return 2; }
                   5553: sub PAST_DUE_ANSWER_LATER  { return 3; }
                   5554: sub ANSWER_OPEN            { return 4; }
1.432     raeburn  5555: sub NOTHING_SET            { return 5; }
1.54      bowersj2 5556: sub NETWORK_FAILURE        { return 100; }
                   5557: 
                   5558: # getDateStatus gets the date status for a given problem part. 
                   5559: # Because answer date, due date, and open date are fully independent
                   5560: # (i.e., it is perfectly possible to *only* have an answer date), 
                   5561: # we have to completely cover the 3x3 maxtrix of (answer, due, open) x
                   5562: # (past, future, none given). This function handles this with a decision
                   5563: # tree. Read the comments to follow the decision tree.
1.51      bowersj2 5564: 
                   5565: sub getDateStatus {
                   5566:     my $self = shift;
                   5567:     my $part = shift;
                   5568:     $part = "0" if (!defined($part));
1.54      bowersj2 5569: 
                   5570:     # Always return network failure if there was one.
1.51      bowersj2 5571:     return $self->NETWORK_FAILURE if ($self->{NAV_MAP}->{NETWORK_FAILURE});
                   5572: 
                   5573:     my $now = time();
                   5574: 
1.53      bowersj2 5575:     my $open = $self->opendate($part);
                   5576:     my $due = $self->duedate($part);
                   5577:     my $answer = $self->answerdate($part);
                   5578: 
                   5579:     if (!$open && !$due && !$answer) {
                   5580:         # no data on the problem at all
                   5581:         # should this be the same as "open later"? think multipart.
                   5582:         return $self->NOTHING_SET;
                   5583:     }
1.59      bowersj2 5584:     if (!$open || $now < $open) {return $self->OPEN_LATER}
                   5585:     if (!$due || $now < $due) {return $self->OPEN}
                   5586:     if ($answer && $now < $answer) {return $self->PAST_DUE_ANSWER_LATER}
                   5587:     if ($answer) { return $self->ANSWER_OPEN; }
1.54      bowersj2 5588:     return PAST_DUE_NO_ANSWER;
1.51      bowersj2 5589: }
                   5590: 
                   5591: =pod
                   5592: 
                   5593: B<>
                   5594: 
                   5595: =over 4
                   5596: 
1.174     albertel 5597: =item * B<getCompletionStatus>($part):
1.51      bowersj2 5598: 
1.174     albertel 5599: ($part defaults to 0.) A convenience function that returns a symbolic
                   5600: constant telling you about the completion status of the part, with the
                   5601: following possible results:
                   5602: 
                   5603: =back
1.51      bowersj2 5604: 
                   5605: B<Completion Codes>
                   5606: 
                   5607: =over 4
                   5608: 
1.174     albertel 5609: =item * B<NOT_ATTEMPTED>:
                   5610: 
                   5611: Has not been attempted at all.
                   5612: 
                   5613: =item * B<INCORRECT>:
                   5614: 
                   5615: Attempted, but wrong by student.
1.51      bowersj2 5616: 
1.174     albertel 5617: =item * B<INCORRECT_BY_OVERRIDE>:
1.51      bowersj2 5618: 
1.174     albertel 5619: Attempted, but wrong by instructor override.
1.51      bowersj2 5620: 
1.174     albertel 5621: =item * B<CORRECT>:
1.51      bowersj2 5622: 
1.174     albertel 5623: Correct or correct by instructor.
1.51      bowersj2 5624: 
1.174     albertel 5625: =item * B<CORRECT_BY_OVERRIDE>:
1.51      bowersj2 5626: 
1.174     albertel 5627: Correct by instructor override.
1.51      bowersj2 5628: 
1.174     albertel 5629: =item * B<EXCUSED>:
                   5630: 
                   5631: Excused. Not yet implemented.
                   5632: 
                   5633: =item * B<NETWORK_FAILURE>:
                   5634: 
                   5635: Information not available due to network failure.
                   5636: 
                   5637: =item * B<ATTEMPTED>:
                   5638: 
                   5639: Attempted, and not yet graded.
1.69      bowersj2 5640: 
1.450     raeburn  5641: =item * B<CREDIT_ATTEMPTED>:
                   5642: 
                   5643: Attempted, and credit received for attempt (survey and anonymous survey only).
                   5644: 
1.537     raeburn  5645: =item * B<INCORRECT_BY_PASSBACK>:
                   5646: 
                   5647: Attempted, but wrong for LTI Tool Provider by passback of grade
                   5648: 
                   5649: =item * B<CORRECT_BY_PASSBACK>:
                   5650: 
                   5651: Correct for LTI Tool Provider by passback of grade
                   5652: 
1.51      bowersj2 5653: =back
                   5654: 
                   5655: =cut
                   5656: 
1.53      bowersj2 5657: sub NOT_ATTEMPTED         { return 10; }
                   5658: sub INCORRECT             { return 11; }
                   5659: sub INCORRECT_BY_OVERRIDE { return 12; }
                   5660: sub CORRECT               { return 13; }
                   5661: sub CORRECT_BY_OVERRIDE   { return 14; }
                   5662: sub EXCUSED               { return 15; }
1.69      bowersj2 5663: sub ATTEMPTED             { return 16; }
1.450     raeburn  5664: sub CREDIT_ATTEMPTED      { return 17; }
1.537     raeburn  5665: sub INCORRECT_BY_PASSBACK { return 18; }
                   5666: sub CORRECT_BY_PASSBACK   { return 19; }
1.51      bowersj2 5667: 
                   5668: sub getCompletionStatus {
                   5669:     my $self = shift;
1.332     albertel 5670:     my $part = shift;
1.51      bowersj2 5671:     return $self->NETWORK_FAILURE if ($self->{NAV_MAP}->{NETWORK_FAILURE});
                   5672: 
1.332     albertel 5673:     my $status = $self->queryRestoreHash('solved', $part);
1.51      bowersj2 5674: 
1.251     www      5675:     # Left as separate if statements in case we ever do more with this
1.51      bowersj2 5676:     if ($status eq 'correct_by_student') {return $self->CORRECT;}
1.288     albertel 5677:     if ($status eq 'correct_by_scantron') {return $self->CORRECT;}
1.332     albertel 5678:     if ($status eq 'correct_by_override') {
                   5679: 	return $self->CORRECT_BY_OVERRIDE;
                   5680:     }
1.537     raeburn  5681:     if ($status eq 'correct_by_passback') {
                   5682:         return $self->CORRECT_BY_PASSBACK;
                   5683:     }
1.51      bowersj2 5684:     if ($status eq 'incorrect_attempted') {return $self->INCORRECT; }
                   5685:     if ($status eq 'incorrect_by_override') {return $self->INCORRECT_BY_OVERRIDE; }
1.537     raeburn  5686:     if ($status eq 'incorrect_by_passback') {return $self->INCORRECT_BY_PASSBACK; }
1.51      bowersj2 5687:     if ($status eq 'excused') {return $self->EXCUSED; }
1.69      bowersj2 5688:     if ($status eq 'ungraded_attempted') {return $self->ATTEMPTED; }
1.450     raeburn  5689:     if ($status eq 'credit_attempted') {
                   5690:         if ($self->is_anonsurvey($part) || $self->is_survey($part)) {
                   5691:             return $self->CREDIT_ATTEMPTED;
                   5692:         } else {
                   5693:             return $self->ATTEMPTED;
                   5694:         }
                   5695:     }
1.51      bowersj2 5696:     return $self->NOT_ATTEMPTED;
1.108     bowersj2 5697: }
                   5698: 
                   5699: sub queryRestoreHash {
                   5700:     my $self = shift;
                   5701:     my $hashentry = shift;
                   5702:     my $part = shift;
1.185     bowersj2 5703:     $part = "0" if (!defined($part) || $part eq '');
1.108     bowersj2 5704:     return $self->NETWORK_FAILURE if ($self->{NAV_MAP}->{NETWORK_FAILURE});
                   5705: 
                   5706:     $self->getReturnHash();
                   5707: 
                   5708:     return $self->{RETURN_HASH}->{'resource.'.$part.'.'.$hashentry};
1.51      bowersj2 5709: }
                   5710: 
                   5711: =pod
                   5712: 
                   5713: B<Composite Status>
                   5714: 
1.174     albertel 5715: Along with directly returning the date or completion status, the
                   5716: resource object includes a convenience function B<status>() that will
                   5717: combine the two status tidbits into one composite status that can
1.191     bowersj2 5718: represent the status of the resource as a whole. This method represents
                   5719: the concept of the thing we want to display to the user on the nav maps
                   5720: screen, which is a combination of completion and open status. The precise logic is
1.174     albertel 5721: documented in the comments of the status method. The following results
                   5722: may be returned, all available as methods on the resource object
1.185     bowersj2 5723: ($res->NETWORK_FAILURE): In addition to the return values that match
                   5724: the date or completion status, this function can return "ANSWER_SUBMITTED"
                   5725: if that problemstatus parameter value is set to No, suppressing the
                   5726: incorrect/correct feedback.
1.51      bowersj2 5727: 
                   5728: =over 4
                   5729: 
1.174     albertel 5730: =item * B<NETWORK_FAILURE>:
                   5731: 
                   5732: The network has failed and the information is not available.
1.51      bowersj2 5733: 
1.174     albertel 5734: =item * B<NOTHING_SET>:
1.53      bowersj2 5735: 
1.174     albertel 5736: No dates have been set for this problem (part) at all. (Because only
                   5737: certain parts of a multi-part problem may be assigned, this can not be
                   5738: collapsed into "open later", as we do not know a given part will EVER
                   5739: be opened. For single part, this is the same as "OPEN_LATER".)
1.51      bowersj2 5740: 
1.174     albertel 5741: =item * B<CORRECT>:
1.51      bowersj2 5742: 
1.174     albertel 5743: For any reason at all, the part is considered correct.
1.54      bowersj2 5744: 
1.174     albertel 5745: =item * B<EXCUSED>:
1.51      bowersj2 5746: 
1.174     albertel 5747: For any reason at all, the problem is excused.
1.51      bowersj2 5748: 
1.174     albertel 5749: =item * B<PAST_DUE_NO_ANSWER>:
1.51      bowersj2 5750: 
1.174     albertel 5751: The problem is past due, not considered correct, and no answer date is
                   5752: set.
1.51      bowersj2 5753: 
1.174     albertel 5754: =item * B<PAST_DUE_ANSWER_LATER>:
1.51      bowersj2 5755: 
1.174     albertel 5756: The problem is past due, not considered correct, and an answer date in
                   5757: the future is set.
1.51      bowersj2 5758: 
1.174     albertel 5759: =item * B<ANSWER_OPEN>:
                   5760: 
                   5761: The problem is past due, not correct, and the answer is now available.
                   5762: 
                   5763: =item * B<OPEN_LATER>:
                   5764: 
                   5765: The problem is not yet open.
                   5766: 
                   5767: =item * B<TRIES_LEFT>:
                   5768: 
                   5769: The problem is open, has been tried, is not correct, but there are
                   5770: tries left.
                   5771: 
                   5772: =item * B<INCORRECT>:
                   5773: 
                   5774: The problem is open, and all tries have been used without getting the
                   5775: correct answer.
                   5776: 
                   5777: =item * B<OPEN>:
                   5778: 
                   5779: The item is open and not yet tried.
                   5780: 
                   5781: =item * B<ATTEMPTED>:
                   5782: 
                   5783: The problem has been attempted.
1.69      bowersj2 5784: 
1.450     raeburn  5785: =item * B<CREDIT_ATTEMPTED>:
                   5786: 
                   5787: The problem has been attempted, and credit given for the attempt (survey and anonymous survey only).
                   5788: 
1.185     bowersj2 5789: =item * B<ANSWER_SUBMITTED>:
                   5790: 
                   5791: An answer has been submitted, but the student should not see it.
                   5792: 
1.51      bowersj2 5793: =back
                   5794: 
                   5795: =cut
                   5796: 
1.432     raeburn  5797: sub TRIES_LEFT        { return 20; }
                   5798: sub ANSWER_SUBMITTED  { return 21; }
                   5799: sub PARTIALLY_CORRECT { return 22; }
                   5800: 
                   5801: sub RESERVED_LATER    { return 30; }
                   5802: sub RESERVED          { return 31; }
                   5803: sub RESERVED_LOCATION { return 32; }
                   5804: sub RESERVABLE        { return 33; }
                   5805: sub RESERVABLE_LATER  { return 34; }
                   5806: sub NOTRESERVABLE     { return 35; }
                   5807: sub NOT_IN_A_SLOT     { return 36; }
                   5808: sub NEEDS_CHECKIN     { return 37; }
                   5809: sub WAITING_FOR_GRADE { return 38; }
                   5810: sub UNKNOWN           { return 39; }
1.51      bowersj2 5811: 
                   5812: sub status {
                   5813:     my $self = shift;
                   5814:     my $part = shift;
                   5815:     if (!defined($part)) { $part = "0"; }
                   5816:     my $completionStatus = $self->getCompletionStatus($part);
                   5817:     my $dateStatus = $self->getDateStatus($part);
                   5818: 
                   5819:     # What we have is a two-dimensional matrix with 4 entries on one
                   5820:     # dimension and 5 entries on the other, which we want to colorize,
1.54      bowersj2 5821:     # plus network failure and "no date data at all".
1.51      bowersj2 5822: 
1.222     bowersj2 5823:     #if ($self->{RESOURCE_ERROR}) { return NETWORK_FAILURE; }
1.53      bowersj2 5824:     if ($completionStatus == NETWORK_FAILURE) { return NETWORK_FAILURE; }
1.51      bowersj2 5825: 
1.408     raeburn  5826:     my $suppressFeedback = 0;
                   5827:     if (($self->problemstatus($part) eq 'no') ||
                   5828:         ($self->problemstatus($part) eq 'no_feedback_ever')) {
                   5829:         $suppressFeedback = 1;
                   5830:     }
1.236     bowersj2 5831:     # If there's an answer date and we're past it, don't
                   5832:     # suppress the feedback; student should know
1.330     albertel 5833:     if ($self->duedate($part) && $self->duedate($part) < time() &&
                   5834: 	$self->answerdate($part) && $self->answerdate($part) < time()) {
1.236     bowersj2 5835: 	$suppressFeedback = 0;
                   5836:     }
1.185     bowersj2 5837: 
1.51      bowersj2 5838:     # There are a few whole rows we can dispose of:
1.53      bowersj2 5839:     if ($completionStatus == CORRECT ||
1.537     raeburn  5840:         $completionStatus == CORRECT_BY_OVERRIDE ||
                   5841:         $completionStatus == CORRECT_BY_PASSBACK ) {
1.332     albertel 5842: 	if ( $suppressFeedback ) { return ANSWER_SUBMITTED }
                   5843: 	my $awarded=$self->awarded($part);
                   5844: 	if ($awarded < 1 && $awarded > 0) {
                   5845:             return PARTIALLY_CORRECT;
                   5846: 	} elsif ($awarded<1) {
                   5847: 	    return INCORRECT;
                   5848: 	}
                   5849: 	return CORRECT; 
1.69      bowersj2 5850:     }
                   5851: 
1.343     albertel 5852:     # If it's WRONG... and not open
                   5853:     if ( ($completionStatus == INCORRECT || 
1.537     raeburn  5854: 	  $completionStatus == INCORRECT_BY_OVERRIDE ||
                   5855: 	  $completionStatus == INCORRECT_BY_PASSBACK)
1.343     albertel 5856: 	 && (!$self->opendate($part) ||  $self->opendate($part) > time()) ) {
                   5857: 	return INCORRECT;
                   5858:     }
                   5859: 
1.69      bowersj2 5860:     if ($completionStatus == ATTEMPTED) {
                   5861:         return ATTEMPTED;
1.53      bowersj2 5862:     }
                   5863: 
1.450     raeburn  5864:     if ($completionStatus == CREDIT_ATTEMPTED) {
                   5865:         return CREDIT_ATTEMPTED;
                   5866:     }
                   5867: 
1.53      bowersj2 5868:     # If it's EXCUSED, then return that no matter what
                   5869:     if ($completionStatus == EXCUSED) {
                   5870:         return EXCUSED; 
1.51      bowersj2 5871:     }
                   5872: 
1.53      bowersj2 5873:     if ($dateStatus == NOTHING_SET) {
                   5874:         return NOTHING_SET;
1.51      bowersj2 5875:     }
                   5876: 
1.69      bowersj2 5877:     # Now we're down to a 4 (incorrect, incorrect_override, not_attempted)
                   5878:     # by 4 matrix (date statuses).
1.51      bowersj2 5879: 
1.54      bowersj2 5880:     if ($dateStatus == PAST_DUE_ANSWER_LATER ||
1.59      bowersj2 5881:         $dateStatus == PAST_DUE_NO_ANSWER ) {
1.272     albertel 5882:         return $suppressFeedback ? ANSWER_SUBMITTED : $dateStatus; 
1.51      bowersj2 5883:     }
                   5884: 
1.53      bowersj2 5885:     if ($dateStatus == ANSWER_OPEN) {
                   5886:         return ANSWER_OPEN;
1.51      bowersj2 5887:     }
                   5888: 
                   5889:     # Now: (incorrect, incorrect_override, not_attempted) x 
                   5890:     # (open_later), (open)
                   5891:     
1.53      bowersj2 5892:     if ($dateStatus == OPEN_LATER) {
                   5893:         return OPEN_LATER;
1.51      bowersj2 5894:     }
                   5895: 
                   5896:     # If it's WRONG...
1.537     raeburn  5897:     if ($completionStatus == INCORRECT || $completionStatus == INCORRECT_BY_OVERRIDE ||
                   5898:         $completionStatus == INCORRECT_BY_PASSBACK) {
1.51      bowersj2 5899:         # and there are TRIES LEFT:
1.79      bowersj2 5900:         if ($self->tries($part) < $self->maxtries($part) || !$self->maxtries($part)) {
1.222     bowersj2 5901:             return $suppressFeedback ? ANSWER_SUBMITTED : TRIES_LEFT;
1.51      bowersj2 5902:         }
1.185     bowersj2 5903:         return $suppressFeedback ? ANSWER_SUBMITTED : INCORRECT; # otherwise, return orange; student can't fix this
1.51      bowersj2 5904:     }
                   5905: 
                   5906:     # Otherwise, it's untried and open
1.473     raeburn  5907:     return OPEN;
1.224     bowersj2 5908: }
                   5909: 
1.432     raeburn  5910: sub check_for_slot {
                   5911:     my $self = shift;
                   5912:     my $part = shift;
1.508     damieng  5913:     my $symb = $self->{SYMB};
1.432     raeburn  5914:     my ($use_slots,$available,$availablestudent) = $self->slot_control($part);
                   5915:     if (($use_slots ne '') && ($use_slots !~ /^\s*no\s*$/i)) {
                   5916:         my @slots = (split(/:/,$availablestudent),split(/:/,$available));
                   5917:         my $cid=$env{'request.course.id'};
                   5918:         my $cdom=$env{'course.'.$cid.'.domain'};
                   5919:         my $cnum=$env{'course.'.$cid.'.num'};
                   5920:         my $now = time;
1.473     raeburn  5921:         my $num_usable_slots = 0;
1.522     raeburn  5922:         my ($checkedin,$checkedinslot,%consumed_uniq,%slots);
1.432     raeburn  5923:         if (@slots > 0) {
1.522     raeburn  5924:             %slots=&Apache::lonnet::get('slots',[@slots],$cdom,$cnum);
1.432     raeburn  5925:             if (&Apache::lonnet::error(%slots)) {
                   5926:                 return (UNKNOWN);
                   5927:             }
1.473     raeburn  5928:             my @sorted_slots = &Apache::loncommon::sorted_slots(\@slots,\%slots,'starttime');
1.432     raeburn  5929:             foreach my $slot_name (@sorted_slots) {
1.473     raeburn  5930:                 next if (!defined($slots{$slot_name}) || !ref($slots{$slot_name}));
1.432     raeburn  5931:                 my $end = $slots{$slot_name}->{'endtime'};
                   5932:                 my $start = $slots{$slot_name}->{'starttime'};
                   5933:                 my $ip = $slots{$slot_name}->{'ip'};
                   5934:                 if ($self->simpleStatus() == OPEN) {
                   5935:                     if ($end > $now) {
1.473     raeburn  5936:                         if ($start > $now) {
                   5937:                             return (RESERVED_LATER,$start,$slot_name);
                   5938:                         } else {
                   5939:                             if ($ip ne '') {
                   5940:                                 if (!&Apache::loncommon::check_ip_acc($ip)) {
1.503     raeburn  5941:                                     return (RESERVED_LOCATION,$end,$slot_name);
1.432     raeburn  5942:                                 }
                   5943:                             }
1.473     raeburn  5944:                             my @proctors;
                   5945:                             if ($slots{$slot_name}->{'proctor'} ne '') {
                   5946:                                 @proctors = split(',',$slots{$slot_name}->{'proctor'});
                   5947:                             }
                   5948:                             if (@proctors > 0) {
                   5949:                                 ($checkedin,$checkedinslot) = $self->checkedin();
                   5950:                                 unless ((grep(/^\Q$checkedin\E/,@proctors)) &&
                   5951:                                         ($checkedinslot eq $slot_name)) {
1.538     raeburn  5952:                                     return (NEEDS_CHECKIN,$end,$slot_name); 
1.472     raeburn  5953:                                 }
1.432     raeburn  5954:                             }
1.473     raeburn  5955:                             return (RESERVED,$end,$slot_name);
1.432     raeburn  5956:                         }
                   5957:                     }
1.473     raeburn  5958:                 } elsif ($end > $now) {
                   5959:                     $num_usable_slots ++;
1.432     raeburn  5960:                 }
                   5961:             }
1.522     raeburn  5962:             my ($is_correct,$wait_for_grade);
1.432     raeburn  5963:             if ($self->is_task()) {
                   5964:                 my $taskstatus = $self->taskstatus();
                   5965:                 $is_correct = (($taskstatus eq 'pass') || 
                   5966:                                ($self->solved() =~ /^correct_/));
1.522     raeburn  5967:                 unless ($taskstatus =~ /^(?:pass|fail)$/) {
                   5968:                     $wait_for_grade = 1;
                   5969:                 }
1.432     raeburn  5970:             } else {
1.522     raeburn  5971:                 unless ($self->completable()) {
                   5972:                     $wait_for_grade = 1;
                   5973:                 }
                   5974:                 unless (($self->problemstatus($part) eq 'no') ||
                   5975:                         ($self->problemstatus($part) eq 'no_feedback_ever')) {
                   5976:                     $is_correct = ($self->solved($part) =~ /^correct_/);
                   5977:                     $wait_for_grade = 0;
                   5978:                 }
1.432     raeburn  5979:             }
                   5980:             ($checkedin,$checkedinslot) = $self->checkedin();
                   5981:             if ($checkedin) {
1.522     raeburn  5982:                 if (ref($slots{$checkedinslot}) eq 'HASH') {
                   5983:                     $consumed_uniq{$checkedinslot} = $slots{$checkedinslot}{'uniqueperiod'};
                   5984:                 }
                   5985:                 if ($wait_for_grade) {
1.432     raeburn  5986:                     return (WAITING_FOR_GRADE);
                   5987:                 } elsif ($is_correct) {
                   5988:                     return (CORRECT); 
                   5989:                 }
                   5990:             }
1.473     raeburn  5991:             if ($num_usable_slots) {
                   5992:                 return(NOT_IN_A_SLOT);
                   5993:             }
                   5994:         }
                   5995:         my $reservable = &Apache::lonnet::get_reservable_slots($cnum,$cdom,$env{'user.name'},
                   5996:                                                                $env{'user.domain'});
                   5997:         if (ref($reservable) eq 'HASH') {
1.511     raeburn  5998:             my ($map) = &Apache::lonnet::decode_symb($symb);
1.473     raeburn  5999:             if ((ref($reservable->{'now_order'}) eq 'ARRAY') && (ref($reservable->{'now'}) eq 'HASH')) {
1.474     raeburn  6000:                 foreach my $slot (reverse (@{$reservable->{'now_order'}})) {
1.510     raeburn  6001:                     my $canuse;
                   6002:                     if ($reservable->{'now'}{$slot}{'symb'} eq '') {
                   6003:                         $canuse = 1;
                   6004:                     } else {
                   6005:                         my %oksymbs;
                   6006:                         my @slotsymbs = split(/\s*,\s*/,$reservable->{'now'}{$slot}{'symb'});
                   6007:                         map { $oksymbs{$_} = 1; } @slotsymbs;
                   6008:                         if ($oksymbs{$symb}) {
                   6009:                             $canuse = 1;
                   6010:                         } else {
                   6011:                             foreach my $item (@slotsymbs) {
                   6012:                                 if ($item =~ /\.(page|sequence)$/) {
                   6013:                                     (undef,undef, my $sloturl) = &Apache::lonnet::decode_symb($item);
                   6014:                                     if (($map ne '') && ($map eq $sloturl)) {
                   6015:                                         $canuse = 1;
                   6016:                                         last;
                   6017:                                     }
                   6018:                                 }
                   6019:                             }
                   6020:                         }
                   6021:                     }
                   6022:                     if ($canuse) {
1.522     raeburn  6023:                         if ($checkedin) {
                   6024:                             if (ref($consumed_uniq{$checkedinslot}) eq 'ARRAY') {
                   6025:                                 my ($uniqstart,$uniqend)=@{$consumed_uniq{$checkedinslot}};
                   6026:                                 if ($reservable->{'now'}{$slot}{'uniqueperiod'} =~ /^(\d+),(\d+)$/) {
                   6027:                                     my ($new_uniq_start,$new_uniq_end) = ($1,$2);
                   6028:                                     next if (!
                   6029:                                         ($uniqstart < $new_uniq_start && $uniqend < $new_uniq_start) ||
                   6030:                                         ($uniqstart > $new_uniq_end   &&  $uniqend > $new_uniq_end  ));
                   6031:                                 }
                   6032:                             }
                   6033:                         }
1.473     raeburn  6034:                         return(RESERVABLE,$reservable->{'now'}{$slot}{'endreserve'});
                   6035:                     }
                   6036:                 }
1.432     raeburn  6037:             }
1.473     raeburn  6038:             if ((ref($reservable->{'future_order'}) eq 'ARRAY') && (ref($reservable->{'future'}) eq 'HASH')) {
1.474     raeburn  6039:                 foreach my $slot (@{$reservable->{'future_order'}}) {
1.510     raeburn  6040:                     my $canuse;
                   6041:                     if ($reservable->{'future'}{$slot}{'symb'} eq '') {
                   6042:                         $canuse = 1;
                   6043:                     } elsif ($reservable->{'future'}{$slot}{'symb'} =~ /,/) {
                   6044:                         my %oksymbs;
                   6045:                         my @slotsymbs = split(/\s*,\s*/,$reservable->{'future'}{$slot}{'symb'});
                   6046:                         map { $oksymbs{$_} = 1; } @slotsymbs;
                   6047:                         if ($oksymbs{$symb}) {
                   6048:                             $canuse = 1;
                   6049:                         } else {
                   6050:                             foreach my $item (@slotsymbs) {
                   6051:                                 if ($item =~ /\.(page|sequence)$/) {
                   6052:                                     (undef,undef, my $sloturl) = &Apache::lonnet::decode_symb($item);
                   6053:                                     if (($map ne '') && ($map eq $sloturl)) {
                   6054:                                         $canuse = 1;
                   6055:                                         last;
                   6056:                                     }
                   6057:                                 }
                   6058:                             }
                   6059:                         }
                   6060:                     } elsif ($reservable->{'future'}{$slot}{'symb'} eq $symb) {
                   6061:                         $canuse = 1;
                   6062:                     }
                   6063:                     if ($canuse) {
1.522     raeburn  6064:                         if ($checkedin) {
                   6065:                             if (ref($consumed_uniq{$checkedinslot}) eq 'ARRAY') {
                   6066:                                 my ($uniqstart,$uniqend)=@{$consumed_uniq{$checkedinslot}};
                   6067:                                 if ($reservable->{'future'}{$slot}{'uniqueperiod'} =~ /^(\d+),(\d+)$/) {
                   6068:                                     my ($new_uniq_start,$new_uniq_end) = ($1,$2);
                   6069:                                     next if (!
                   6070:                                         ($uniqstart < $new_uniq_start && $uniqend < $new_uniq_start) ||
                   6071:                                         ($uniqstart > $new_uniq_end   &&  $uniqend > $new_uniq_end  ));
                   6072:                                 }
                   6073:                             }
                   6074:                         }
1.473     raeburn  6075:                         return(RESERVABLE_LATER,$reservable->{'future'}{$slot}{'startreserve'});
                   6076:                     }
                   6077:                 }
1.432     raeburn  6078:             }
                   6079:         }
1.473     raeburn  6080:         return(NOTRESERVABLE);
1.432     raeburn  6081:     }
                   6082:     return;
                   6083: }
                   6084: 
1.224     bowersj2 6085: sub CLOSED { return 23; }
                   6086: sub ERROR { return 24; }
                   6087: 
                   6088: =pod
                   6089: 
                   6090: B<Simple Status>
                   6091: 
                   6092: Convenience method B<simpleStatus> provides a "simple status" for the resource.
                   6093: "Simple status" corresponds to "which icon is shown on the
                   6094: Navmaps". There are six "simple" statuses:
                   6095: 
                   6096: =over 4
                   6097: 
                   6098: =item * B<CLOSED>: The problem is currently closed. (No icon shown.)
                   6099: 
                   6100: =item * B<OPEN>: The problem is open and unattempted.
                   6101: 
                   6102: =item * B<CORRECT>: The problem is correct for any reason.
                   6103: 
                   6104: =item * B<INCORRECT>: The problem is incorrect and can still be
                   6105: completed successfully.
                   6106: 
                   6107: =item * B<ATTEMPTED>: The problem has been attempted, but the student
                   6108: does not know if they are correct. (The ellipsis icon.)
                   6109: 
                   6110: =item * B<ERROR>: There is an error retrieving information about this
                   6111: problem.
                   6112: 
                   6113: =back
                   6114: 
                   6115: =cut
                   6116: 
                   6117: # This hash maps the composite status to this simple status, and
                   6118: # can be used directly, if you like
                   6119: my %compositeToSimple = 
                   6120:     (
                   6121:       NETWORK_FAILURE()       => ERROR,
                   6122:       NOTHING_SET()           => CLOSED,
                   6123:       CORRECT()               => CORRECT,
1.332     albertel 6124:       PARTIALLY_CORRECT()     => PARTIALLY_CORRECT,
1.224     bowersj2 6125:       EXCUSED()               => CORRECT,
                   6126:       PAST_DUE_NO_ANSWER()    => INCORRECT,
                   6127:       PAST_DUE_ANSWER_LATER() => INCORRECT,
                   6128:       ANSWER_OPEN()           => INCORRECT,
                   6129:       OPEN_LATER()            => CLOSED,
                   6130:       TRIES_LEFT()            => OPEN,
                   6131:       INCORRECT()             => INCORRECT,
                   6132:       OPEN()                  => OPEN,
                   6133:       ATTEMPTED()             => ATTEMPTED,
1.450     raeburn  6134:       CREDIT_ATTEMPTED()      => CORRECT,
1.224     bowersj2 6135:       ANSWER_SUBMITTED()      => ATTEMPTED
                   6136:      );
                   6137: 
                   6138: sub simpleStatus {
                   6139:     my $self = shift;
                   6140:     my $part = shift;
                   6141:     my $status = $self->status($part);
                   6142:     return $compositeToSimple{$status};
1.225     bowersj2 6143: }
                   6144: 
                   6145: =pod
                   6146: 
                   6147: B<simpleStatusCount> will return an array reference containing, in
                   6148: this order, the number of OPEN, CLOSED, CORRECT, INCORRECT, ATTEMPTED,
                   6149: and ERROR parts the given problem has.
                   6150: 
                   6151: =cut
                   6152:     
                   6153: # This maps the status to the slot we want to increment
                   6154: my %statusToSlotMap = 
                   6155:     (
                   6156:      OPEN()      => 0,
                   6157:      CLOSED()    => 1,
                   6158:      CORRECT()   => 2,
                   6159:      INCORRECT() => 3,
                   6160:      ATTEMPTED() => 4,
                   6161:      ERROR()     => 5
                   6162:      );
                   6163: 
                   6164: sub statusToSlot { return $statusToSlotMap{shift()}; }
                   6165: 
                   6166: sub simpleStatusCount {
                   6167:     my $self = shift;
                   6168: 
                   6169:     my @counts = (0, 0, 0, 0, 0, 0, 0);
                   6170:     foreach my $part (@{$self->parts()}) {
                   6171: 	$counts[$statusToSlotMap{$self->simpleStatus($part)}]++;
                   6172:     }
                   6173: 
                   6174:     return \@counts;
1.191     bowersj2 6175: }
                   6176: 
                   6177: =pod
                   6178: 
                   6179: B<Completable>
                   6180: 
                   6181: The completable method represents the concept of I<whether the student can
                   6182: currently do the problem>. If the student can do the problem, which means
                   6183: that it is open, there are tries left, and if the problem is manually graded
                   6184: or the grade is suppressed via problemstatus, the student has not tried it
                   6185: yet, then the method returns 1. Otherwise, it returns 0, to indicate that 
                   6186: either the student has tried it and there is no feedback, or that for
                   6187: some reason it is no longer completable (not open yet, successfully completed,
                   6188: out of tries, etc.). As an example, this is used as the filter for the
                   6189: "Uncompleted Homework" option for the nav maps.
                   6190: 
                   6191: If this does not quite meet your needs, do not fiddle with it (unless you are
                   6192: fixing it to better match the student's conception of "completable" because
                   6193: it's broken somehow)... make a new method.
                   6194: 
                   6195: =cut
                   6196: 
                   6197: sub completable {
                   6198:     my $self = shift;
                   6199:     if (!$self->is_problem()) { return 0; }
                   6200:     my $partCount = $self->countParts();
                   6201: 
                   6202:     foreach my $part (@{$self->parts()}) {
                   6203:         if ($part eq '0' && $partCount != 1) { next; }
                   6204:         my $status = $self->status($part);
                   6205:         # "If any of the parts are open, or have tries left (implies open),
                   6206:         # and it is not "attempted" (manually graded problem), it is
                   6207:         # not "complete"
1.216     bowersj2 6208: 	if ($self->getCompletionStatus($part) == ATTEMPTED() ||
1.450     raeburn  6209:             $self->getCompletionStatus($part) == CREDIT_ATTEMPTED() ||
1.216     bowersj2 6210: 	    $status == ANSWER_SUBMITTED() ) {
                   6211: 	    # did this part already, as well as we can
                   6212: 	    next;
                   6213: 	}
                   6214: 	if ($status == OPEN() || $status == TRIES_LEFT()) {
                   6215: 	    return 1;
                   6216: 	}
1.191     bowersj2 6217:     }
                   6218:         
                   6219:     # If all the parts were complete, so was this problem.
1.216     bowersj2 6220:     return 0;
1.51      bowersj2 6221: }
                   6222: 
                   6223: =pod
                   6224: 
1.507     raeburn  6225: B<Answerable>
                   6226: 
                   6227: The answerable method differs from the completable method in its handling of problem parts
                   6228: for which feedback on correctness is suppressed, but the student still has tries left, and
                   6229: the problem part is not past due, (i.e., the student could submit a different answer if
                   6230: he/she so chose). For that case completable will return 0, whereas answerable will return 1.
                   6231: 
                   6232: =cut
                   6233: 
                   6234: sub answerable {
                   6235:     my $self = shift;
                   6236:     if (!$self->is_problem()) { return 0; }
                   6237:     my $partCount = $self->countParts();
                   6238:     foreach my $part (@{$self->parts()}) {
                   6239:         if ($part eq '0' && $partCount != 1) { next; }
                   6240:         my $status = $self->status($part);
                   6241:         if ($self->getCompletionStatus($part) == ATTEMPTED() ||
                   6242:             $self->getCompletionStatus($part) == CREDIT_ATTEMPTED() ||
                   6243:             $status == ANSWER_SUBMITTED() ) {
                   6244:             if ($self->tries($part) < $self->maxtries($part) || !$self->maxtries($part)) {
                   6245:                 return 1;
                   6246:             }
                   6247:         }
                   6248:         if ($status == OPEN() || $status == TRIES_LEFT() || $status == NETWORK_FAILURE()) {
                   6249:             return 1;
                   6250:         }
                   6251:     }
                   6252:     # None of the parts were answerable, so neither is this problem.
                   6253:     return 0;
                   6254: }
                   6255: 
                   6256: =pod
                   6257: 
1.51      bowersj2 6258: =head2 Resource/Nav Map Navigation
                   6259: 
                   6260: =over 4
                   6261: 
1.174     albertel 6262: =item * B<getNext>():
                   6263: 
                   6264: Retreive an array of the possible next resources after this
                   6265: one. Always returns an array, even in the one- or zero-element case.
                   6266: 
                   6267: =item * B<getPrevious>():
1.85      bowersj2 6268: 
1.174     albertel 6269: Retreive an array of the possible previous resources from this
                   6270: one. Always returns an array, even in the one- or zero-element case.
1.51      bowersj2 6271: 
                   6272: =cut
                   6273: 
                   6274: sub getNext {
                   6275:     my $self = shift;
                   6276:     my @branches;
                   6277:     my $to = $self->to();
1.85      bowersj2 6278:     foreach my $branch ( split(/,/, $to) ) {
1.51      bowersj2 6279:         my $choice = $self->{NAV_MAP}->getById($branch);
1.342     albertel 6280:         #if (!$choice->condition()) { next; }
1.51      bowersj2 6281:         my $next = $choice->goesto();
                   6282:         $next = $self->{NAV_MAP}->getById($next);
                   6283: 
1.131     bowersj2 6284:         push @branches, $next;
1.85      bowersj2 6285:     }
                   6286:     return \@branches;
                   6287: }
                   6288: 
                   6289: sub getPrevious {
                   6290:     my $self = shift;
                   6291:     my @branches;
                   6292:     my $from = $self->from();
1.504     raeburn  6293:     foreach my $branch ( split(/,/, $from)) {
1.85      bowersj2 6294:         my $choice = $self->{NAV_MAP}->getById($branch);
                   6295:         my $prev = $choice->comesfrom();
                   6296:         $prev = $self->{NAV_MAP}->getById($prev);
                   6297: 
1.131     bowersj2 6298:         push @branches, $prev;
1.51      bowersj2 6299:     }
                   6300:     return \@branches;
1.131     bowersj2 6301: }
                   6302: 
                   6303: sub browsePriv {
                   6304:     my $self = shift;
1.505     raeburn  6305:     my $noblockcheck = shift;
1.131     bowersj2 6306:     if (defined($self->{BROWSE_PRIV})) {
                   6307:         return $self->{BROWSE_PRIV};
                   6308:     }
                   6309: 
1.311     albertel 6310:     $self->{BROWSE_PRIV} = &Apache::lonnet::allowed('bre',$self->src(),
1.508     damieng  6311: 						    $self->{SYMB},undef,
1.505     raeburn  6312:                                                     undef,$noblockcheck);
1.51      bowersj2 6313: }
                   6314: 
                   6315: =pod
1.2       www      6316: 
1.51      bowersj2 6317: =back
1.2       www      6318: 
1.51      bowersj2 6319: =cut
1.2       www      6320: 
1.51      bowersj2 6321: 1;
1.2       www      6322: 
1.51      bowersj2 6323: __END__
1.2       www      6324: 
                   6325: 

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