File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.79.2.1: download - view: text, annotated - select for diffs
Sun Jan 19 00:54:47 2020 UTC (4 years, 4 months ago) by raeburn
Branches: version_2_11_3_msu
Diff to branchpoint 1.369.2.79: preferred, unified
- For 2.11.3 (modified)
  Include changes in 1.435, 1.437, 1.438, 1.440, 1.441, 1.442, 1.448, 1.449,
  1.450, 1.471, 1.472, 1.500

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.369.2.79.2.1 2020/01/19 00:54:47 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: #
   29: 
   30: =head1 NAME
   31: 
   32: Apache::lonmenu
   33: 
   34: =head1 SYNOPSIS
   35: 
   36: Loads contents of /home/httpd/lonTabs/mydesk.tab, 
   37: used to generate inline menu, and Main Menu page. 
   38: 
   39: This is part of the LearningOnline Network with CAPA project
   40: described at http://www.lon-capa.org.
   41: 
   42: =head1 GLOBAL VARIABLES
   43: 
   44: =over
   45: 
   46: =item @desklines
   47: 
   48: Each element of this array contains a line of mydesk.tab that doesn't start with
   49: cat, prim or scnd. 
   50: It gets filled in the BEGIN block of this module.
   51: 
   52: =item %category_names
   53: 
   54: The keys of this hash are the abbreviations used in mydesk.tab in those lines that 
   55: start with cat, the values are strings representing titles. 
   56: It gets filled in the BEGIN block of this module.
   57: 
   58: =item %category_members
   59: 
   60: TODO 
   61: 
   62: =item %category_positions
   63: 
   64: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
   65: start with cat, its values are position vectors (column, row). 
   66: It gets filled in the BEGIN block of this module.
   67: 
   68: =item $readdesk
   69: 
   70: Indicates that mydesk.tab has been read. 
   71: It is set to 'done' in the BEGIN block of this module.
   72: 
   73: =item @primary_menu
   74: 
   75: The elements of this array reference arrays that are made up of the components
   76: of those lines of mydesk.tab that start with prim:.
   77: It is used by primary_menu() to generate the corresponding menu.
   78: It gets filled in the BEGIN block of this module.
   79: 
   80: =item %primary_sub_menu
   81: 
   82: The keys of this hash reference are the names of items in the primary_menu array 
   83: which have sub-menus.  For each key, the corresponding value is a reference to
   84: an array containing components extracted from lines in mydesk.tab which begin
   85: with primsub:.
   86: This hash, which is used by primary_menu to generate sub-menus, is populated in
   87: the BEGIN block.
   88: 
   89: =item @secondary_menu
   90: 
   91: The elements of this array reference arrays that are made up of the components
   92: of those lines of mydesk.tab that start with scnd.
   93: It is used by secondary_menu() to generate the corresponding menu.
   94: It gets filled in the BEGIN block of this module.
   95: 
   96: =back
   97: 
   98: =head1 SUBROUTINES
   99: 
  100: =over
  101: 
  102: =item prep_menuitems(\@menuitem)
  103: 
  104: This routine wraps a menuitem in proper HTML. It is used by primary_menu() and 
  105: secondary_menu().
  106: 
  107: =item primary_menu()
  108: 
  109: This routine evaluates @primary_menu and returns a two item array, 
  110: with the array elements containing XHTML for the left and right sides of 
  111: the menu that contains the following links: About, Message, Roles, Help, Logout 
  112: @primary_menu is filled within the BEGIN block of this module with 
  113: entries from mydesk.tab
  114: 
  115: =item secondary_menu()
  116: 
  117: Same as primary_menu() but operates on @secondary_menu.
  118: 
  119: =item create_submenu()
  120: 
  121: Creates XHTML for unordered list of sub-menu items which belong to a
  122: particular top-level menu item. Uses hover pseudo class in css to display
  123: dropdown list when mouse hovers over top-level item. Support for IE6
  124: (no hover psuedo class) via LC_hoverable class for <li> tag for top-
  125: level item, which employs jQuery to handle behavior on mouseover.
  126: 
  127: Inputs: 6 - (a) link and (b) target for anchor href in top level item,
  128:             (c) title for text wrapped by anchor tag in top level item.
  129:             (d) reference to array of arrays of sub-menu items.
  130:             (e) boolean to indicate whether to call &mt() to translate
  131:                 name of menu item,
  132:             (f) optional class for <li> element in primary menu, for which
  133:                 sub menu is being generated.
  134: 
  135: The underlying datastructure used in (d) contains data from mydesk.tab.
  136: It consists of an array which has an array for each item appearing in
  137: the menu (e.g. [["link", "title", "condition"]] for a single-item menu).
  138: create_submenu() supports also the creation of XHTML for nested dropdown
  139: menus represented by unordered lists. This is done by replacing the
  140: scalar used for the link with an arrayreference containing the menuitems
  141: for the nested menu. This can be done recursively so that the next menu
  142: may also contain nested submenus.
  143: 
  144:  Example:
  145:  [                                                                                      # begin of datastructure
  146:         ["/home/", "Home", "condition1"],               # 1st item of the 1st layer menu
  147:         [                                                                               # 2nd item of the 1st layer menu
  148:                 [                                                                       # anon. array for nested menu
  149:                         ["/path1", "Path1", undef],     # 1st item of the 2nd layer menu
  150:                         ["/path2", "Path2", undef],     # 2nd item of the 2nd layer menu
  151:                         [                                                               # 3rd item of the 2nd layer menu
  152:                                 [[...], [...], ..., [...]],     # containing another menu layer
  153:                                 "Sub-Sub-Menu",                         # title for this container
  154:                                 undef
  155:                         ]
  156:                 ],                                                                      # end of array/nested menu
  157:                 "Sub-Menu",                                                     # title for the container item
  158:                 undef
  159:         ]                                                                               # end of 2nd item of the 1st layer menu
  160: ]
  161: 
  162: 
  163: =item innerregister()
  164: 
  165: This gets called in order to register a URL in the body of the document
  166: 
  167: =item loadevents()
  168: 
  169: =item unloadevents()
  170: 
  171: =item startupremote()
  172: 
  173: =item setflags()
  174: 
  175: =item maincall()
  176: 
  177: =item load_remote_msg()
  178: 
  179: =item get_menu_name()
  180: 
  181: =item reopenmenu()
  182: 
  183: =item open()
  184: 
  185: Open the menu
  186: 
  187: =item clear()
  188: 
  189: =item switch()
  190: 
  191: Switch a button or create a link
  192: Switch acts on the javascript that is executed when a button is clicked.  
  193: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
  194: 
  195: =item secondlevel()
  196: 
  197: =item openmenu()
  198: 
  199: =item inlinemenu()
  200: 
  201: =item rawconfig()
  202: 
  203: =item utilityfunctions()
  204: 
  205: Output from this routine is a number of javascript functions called by
  206: items in the inline menu, and in some cases items in the Main Menu page. 
  207: 
  208: =item serverform()
  209: 
  210: =item constspaceform()
  211: 
  212: =item get_nav_status()
  213: 
  214: =item hidden_button_check()
  215: 
  216: =item roles_selector()
  217: 
  218: =item jump_to_role()
  219: 
  220: =back
  221: 
  222: =cut
  223: 
  224: package Apache::lonmenu;
  225: 
  226: use strict;
  227: use Apache::lonnet;
  228: use Apache::lonhtmlcommon();
  229: use Apache::loncommon();
  230: use Apache::lonenc();
  231: use Apache::lonlocal;
  232: use Apache::lonmsg();
  233: use LONCAPA qw(:DEFAULT :match);
  234: use HTML::Entities();
  235: use Apache::lonwishlist();
  236: 
  237: use vars qw(@desklines %category_names %category_members %category_positions 
  238:             $readdesk @primary_menu %primary_submenu @secondary_menu %secondary_submenu);
  239: 
  240: my @inlineremote;
  241: 
  242: sub prep_menuitem {
  243:     my ($menuitem) = @_;
  244:     return '' unless(ref($menuitem) eq 'ARRAY');
  245:     my $link;
  246:     if ($$menuitem[1]) { # graphical Link
  247:         $link = "<img class=\"LC_noBorder\""
  248:               . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\"" 
  249:               . " alt=\"" . &mt($$menuitem[2]) . "\" />";
  250:     } else {             # textual Link
  251:         $link = &mt($$menuitem[3]);
  252:     }
  253:     return '<li><a' 
  254:            # highlighting for new messages
  255:            . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '') 
  256:            . qq| href="$$menuitem[0]" target="_top">$link</a></li>|;
  257: }
  258: 
  259: # primary_menu() evaluates @primary_menu and returns a two item array,
  260: # with the array elements containing XHTML for the left and right sides of 
  261: # the menu that contains the following links:
  262: # Personal, About, Message, Roles, Help, Logout
  263: # @primary_menu is filled within the BEGIN block of this module with 
  264: # entries from mydesk.tab
  265: sub primary_menu {
  266:     my %menu;
  267:     # each element of @primary contains following array:
  268:     # (link url, icon path, alt text, link text, condition, position)
  269:     my $public;
  270:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
  271:         || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
  272:         $public = 1;
  273:     }
  274:     foreach my $menuitem (@primary_menu) {
  275:         # evaluate conditions 
  276:         next if    ref($menuitem)       ne 'ARRAY';    #
  277:         next if    $$menuitem[4]        eq 'nonewmsg'  # show links depending on
  278:                 && &Apache::lonmsg::mynewmail();       # whether a new msg 
  279:         next if    $$menuitem[4]        eq 'newmsg'    # arrived or not
  280:                 && !&Apache::lonmsg::mynewmail();      # 
  281:         next if    $$menuitem[4]        !~ /public/    ##we've a public user,
  282:                 && $public;                            ##who should not see all
  283:                                                        ##links
  284:         next if    $$menuitem[4]        eq 'onlypublic'# hide links which are 
  285:                 && !$public;                           # only visible to public
  286:                                                        # users
  287:         next if    $$menuitem[4]        eq 'roles'     ##show links depending on
  288:                 && &Apache::loncommon::show_course();  ##term 'Courses' or 
  289:         next if    $$menuitem[4]        eq 'courses'   ##'Roles' wanted
  290:                 && !&Apache::loncommon::show_course(); ##
  291:         
  292:         my $title = $menuitem->[3];
  293:         my $position = $menuitem->[5];
  294:         if ($position eq '') {
  295:             $position = 'right';
  296:         }
  297:         if (defined($primary_submenu{$title})) {
  298:             my ($link,$target);
  299:             if ($menuitem->[0] ne '') {
  300:                 $link = $menuitem->[0];
  301:                 $target = '_top';
  302:             } else {
  303:                 $link = '#';
  304:             }
  305:             my @primsub;
  306:             if (ref($primary_submenu{$title}) eq 'ARRAY') {
  307:                 foreach my $item (@{$primary_submenu{$title}}) {
  308:                     next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'})); 
  309:                     next if ((($item->[2] eq 'portfolio') || 
  310:                              ($item->[2] eq 'blog')) && 
  311:                              (!&Apache::lonnet::usertools_access('','',$item->[2],
  312:                                                            undef,'tools')));
  313:                     push(@primsub,$item);
  314:                 }
  315:                 if (@primsub > 0) {
  316:                     if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) {
  317:                         $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
  318:                     } else {
  319:                         $title = &mt($title);
  320:                     }
  321:                     $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1);
  322:                 } elsif ($link) {
  323:                     $menu{$position} .= '<li><a href="'.$link.'" target="'.$target.'">'.&mt($title).'</a></li>';
  324:                 }
  325:             }
  326:         } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
  327:             if ($public) {
  328:                 my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
  329:                 my $defdom = &Apache::lonnet::default_login_domain();
  330:                 my $to = &Apache::loncommon::build_recipient_list(undef,
  331:                                                                   'helpdeskmail',
  332:                                                                   $defdom,$origmail);
  333:                 if ($to ne '') {
  334:                     $menu{$position} .= &prep_menuitem($menuitem); 
  335:                 }
  336:             } else {
  337:                 $menu{$position} .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
  338:             }
  339:         } else {
  340:             $menu{$position} .= prep_menuitem($menuitem);
  341:         }
  342:     }
  343:     my @output = ('','');
  344:     if ($menu{'left'} ne '') {
  345:         $output[0] = "<ol class=\"LC_primary_menu LC_floatleft\">$menu{'left'}</ol>";
  346:     }
  347:     if ($menu{'right'} ne '') {
  348:         $output[1] = "<ol class=\"LC_primary_menu LC_floatright LC_right\">$menu{'right'}</ol>";
  349:     }
  350:     return @output;
  351: }
  352: 
  353: #returns hashref {user=>'',dom=>''} containing:
  354: #   own name, domain if user is au
  355: #   name, domain of parent author if user is ca or aa
  356: #empty return if user is not an author or not on homeserver
  357: #
  358: #TODO this should probably be moved somewhere more central
  359: #since it can be used by different parts of the system
  360: sub getauthor{
  361:     return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
  362: 
  363:                         #co- or assistent author?
  364:     my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
  365:                        ? ($1, $2) #domain, username of the parent author
  366:                        : @env{ ('request.role.domain', 'user.name') }; #own domain, username
  367: 
  368:     # current server == home server?
  369:     my $home =  &Apache::lonnet::homeserver($user,$dom);
  370:     foreach (&Apache::lonnet::current_machine_ids()){
  371:         return {user => $user, dom => $dom} if $_ eq $home;
  372:     }
  373: 
  374:     # if wrong server
  375:     return;
  376: }
  377: 
  378: sub secondary_menu {
  379:     my ($httphost) = @_;
  380:     my $menu;
  381: 
  382:     my $crstype = &Apache::loncommon::course_type();
  383:     my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'} 
  384:                                                ? "/$env{'request.course.sec'}"
  385:                                                : '');
  386:     my $canedit       = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
  387:     my $canvieweditor = &Apache::lonnet::allowed('cev', $env{'request.course.id'}); 
  388:     my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
  389:     if ($canviewroster eq 'disabled') {
  390:         undef($canviewroster);
  391:     }
  392:     my $canviewgrps   = &Apache::lonnet::allowed('vcg', $crs_sec);
  393:     my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec);
  394:     my $canviewusers  = &Apache::lonnet::allowed('vcl', $crs_sec);
  395:     my $canviewwnew   = &Apache::lonnet::allowed('whn', $crs_sec);
  396:     my $canviewpara   = &Apache::lonnet::allowed('vpa', $crs_sec);
  397:     my $canmodpara    = &Apache::lonnet::allowed('opa', $crs_sec);
  398:     my $canvgr        = &Apache::lonnet::allowed('vgr', $crs_sec);
  399:     my $canmgr        = &Apache::lonnet::allowed('mgr', $crs_sec);
  400:     my $author        = &getauthor();
  401: 
  402:     my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools);
  403:     $grouptools = 0; 
  404:     if ($env{'request.course.id'}) {
  405:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  406:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  407:         unless ($canedit || $canvieweditor) {
  408:             unless (&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus")) {
  409:                 if (($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) ||
  410:                     ($env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) ||
  411:                     ($env{'course.'.$env{'request.course.id'}.'.updatedsyllabus'}) ||
  412:                     ($env{'request.course.syllabustime'})) {
  413:                     $showsyllabus = 1;
  414:                 }
  415:             }
  416:             if ($env{'request.course.feeds'}) {
  417:                 $showfeeds = 1;
  418:             }
  419:         }
  420:         unless ($canmgr || $canvgr) {
  421:             my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
  422:             if (keys(%slots) > 0) {
  423:                 $showresv = 1;
  424:             }
  425:         }
  426:         if ($env{'request.course.groups'} ne '') {
  427:             foreach my $group (split(/:/,$env{'request.course.groups'})) {
  428:                 next unless ($group =~ /^\w+$/);
  429:                 my @privs = split(/:/,$env{"user.priv.$env{'request.role'}./$cdom/$cnum/$group"});
  430:                 shift(@privs);
  431:                 if (@privs) {
  432:                     $grouptools ++;
  433:                 }
  434:             }
  435:         }
  436:     }
  437: 
  438:     my ($canmodifycoauthor);
  439:     if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
  440:         my $extent = "$env{'user.domain'}/$env{'user.name'}";
  441:         if ((&Apache::lonnet::allowed('cca',$extent)) ||
  442:             (&Apache::lonnet::allowed('caa',$extent))) {
  443:             $canmodifycoauthor = 1;
  444:         }
  445:     }
  446: 
  447:     my ($roleswitcher_js,$roleswitcher_form);
  448: 
  449:     foreach my $menuitem (@secondary_menu) {
  450:         # evaluate conditions 
  451:         next if    ref($menuitem)  ne 'ARRAY';
  452:         next if    $$menuitem[4]   ne 'always'
  453:                 && ($$menuitem[4]  ne 'author' && $$menuitem[4] ne 'cca')
  454:                 && !$env{'request.course.id'};
  455:         next if    $$menuitem[4]   =~ /^crsedit/
  456:                 && (!$canedit && !$canvieweditor);
  457:         next if    $$menuitem[4]  eq 'crseditCourse'
  458:                 && ($crstype eq 'Community');
  459:         next if    $$menuitem[4]  eq 'crseditCommunity'
  460:                 && ($crstype eq 'Course');
  461:         next if    $$menuitem[4]  eq 'nvgr'
  462:                 && $canvgr;
  463:         next if    $$menuitem[4]  eq 'vgr'
  464:                 && !$canvgr;
  465:         next if    $$menuitem[4]   eq 'viewusers'
  466:                 && !$canmodifyuser && !$canviewusers;
  467:         next if    $$menuitem[4]   eq 'noviewusers'
  468:                 && ($canmodifyuser || $canviewusers || !$canviewroster);
  469:         next if    $$menuitem[4]   eq 'mgr'
  470:                 && !$canmgr;
  471:         next if    $$menuitem[4]   eq 'showresv'
  472:                 && !$showresv;
  473:         next if    $$menuitem[4]   eq 'whn'
  474:                 && !$canviewwnew;
  475:         next if    $$menuitem[4]   eq 'params'
  476:                 && (!$canmodpara && !$canviewpara);
  477:         next if    $$menuitem[4]   eq 'nvcg'
  478:                 && ($canviewgrps || !$grouptools);
  479:         next if    $$menuitem[4]   eq 'showsyllabus'
  480:                 && !$showsyllabus;
  481:         next if    $$menuitem[4]   eq 'showfeeds'
  482:                 && !$showfeeds;
  483:         next if    $$menuitem[4]    eq 'author'
  484:                 && !$author;
  485:         next if    $$menuitem[4]    eq 'cca'
  486:                 && !$canmodifycoauthor;
  487: 
  488:         my $title = $menuitem->[3];
  489:         if (defined($secondary_submenu{$title})) {
  490:             my ($link,$target);
  491:             if ($menuitem->[0] ne '') {
  492:                 $link = $menuitem->[0];
  493:                 $target = '_top';
  494:             } else {
  495:                 $link = '#';
  496:             }
  497:             my @scndsub;
  498:             if (ref($secondary_submenu{$title}) eq 'ARRAY') {
  499:                 foreach my $item (@{$secondary_submenu{$title}}) {
  500:                     if (ref($item) eq 'ARRAY') {
  501:                         next if ($item->[2] eq 'vgr' && !$canvgr);
  502:                         next if ($item->[2] eq 'opa' && !$canmodpara);
  503:                         next if ($item->[2] eq 'vpa' && !$canviewpara);
  504:                         next if ($item->[2] eq 'viewusers' && !($canmodifyuser || $canviewusers));
  505:                         next if ($item->[2] eq 'mgr' && !$canmgr);
  506:                         next if ($item->[2] eq 'vcg' && !$canviewgrps);
  507:                         next if ($item->[2] eq 'crsedit' && !$canedit && !$canvieweditor);
  508:                         next if ($item->[2] eq 'params' && !$canmodpara && !$canviewpara);
  509:                         next if ($item->[2] eq 'author' && !$author);
  510:                         next if ($item->[2] eq 'cca' && !$canmodifycoauthor);
  511:                         push(@scndsub,$item); 
  512:                     }
  513:                 }
  514:                 if (@scndsub > 0) {
  515:                     $menu .= &create_submenu($link,$target,$title,\@scndsub,1);
  516:                 } elsif ($link ne '#') {
  517:                     $menu .= '<li><a href="'.$link.'" target="'.$target.'">'.&mt($title).'</a></li>';
  518:                 }
  519:             }
  520:         } elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
  521:             # special treatment for role selector
  522:             ($roleswitcher_js,$roleswitcher_form,my $switcher) =
  523:                 &roles_selector(
  524:                         $env{'course.' . $env{'request.course.id'} . '.domain'},
  525:                         $env{'course.' . $env{'request.course.id'} . '.num'},
  526:                         $httphost
  527:                 );
  528:             $menu .= $switcher;
  529:         } else {
  530:             if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) {
  531:                 my $url = $$menuitem[0];
  532:                 $url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum};
  533:                 if (&Apache::lonnet::is_on_map($url)) {
  534:                     unless ($$menuitem[0] =~ /(\?|\&)register=1/) {
  535:                         $$menuitem[0] .= (($$menuitem[0]=~/\?/)? '&' : '?').'register=1';
  536:                     }
  537:                 } else {
  538:                     $$menuitem[0] =~ s{\&?register=1}{};
  539:                 }
  540:                 if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://}) {
  541:                     if (($ENV{'SERVER_PORT'} == 443) || ($env{'request.use_absolute'} =~ m{^https://})) {
  542:                         unless (&Apache::lonnet::uses_sts()) {
  543:                             unless ($$menuitem[0] =~ m{^https?://}) {
  544:                                 $$menuitem[0] = 'http://'.$ENV{'SERVER_NAME'}.$$menuitem[0];
  545:                             }
  546:                             unless ($$menuitem[0] =~ /(\&|\?)usehttp=1/) {
  547:                                 $$menuitem[0] .= (($$menuitem[0]=~/\?/) ? '&' : '?').'usehttp=1';
  548:                             }
  549:                         }
  550:                     }
  551:                 }
  552:                 $$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"');
  553:             }
  554:             $menu .= &prep_menuitem(\@$menuitem);
  555:         }
  556:     }
  557:     if ($menu =~ /\[url\].*\[symb\]/) {
  558:         my $escurl  = &escape( &Apache::lonenc::check_encrypt(
  559:                              $env{'request.noversionuri'}));
  560: 
  561:         my $escsymb = &escape( &Apache::lonenc::check_encrypt(
  562:                              $env{'request.symb'})); 
  563: 
  564:         if (    $env{'request.state'} eq 'construct'
  565:             and (   $env{'request.noversionuri'} eq '' 
  566:                  || !defined($env{'request.noversionuri'}))) 
  567:         {
  568:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
  569:             ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
  570:             $escurl  = &escape($escurl);
  571:         }
  572:         $menu =~ s/\[url\]/$escurl/g;
  573:         $menu =~ s/\[symb\]/$escsymb/g;
  574:     }
  575:     $menu =~ s/\[uname\]/$$author{user}/g;
  576:     $menu =~ s/\[udom\]/$$author{dom}/g;
  577:     if ($env{'request.course.id'}) {  
  578:         $menu =~ s/\[cnum\]/$cnum/g;
  579:         $menu =~ s/\[cdom\]/$cdom/g;
  580:     }
  581:     if ($menu) {
  582:         $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>";
  583:     }
  584:     if ($roleswitcher_form) {
  585:         $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
  586:     }
  587:     return $menu;
  588: }
  589: 
  590: sub create_submenu {
  591:     my ($link,$target,$title,$submenu,$translate,$addclass) = @_;
  592:     return unless (ref($submenu) eq 'ARRAY');
  593:     my $disptarget;
  594:     if ($target ne '') {
  595:         $disptarget = ' target="'.$target.'"';
  596:     }
  597:     my $menu = '<li class="LC_hoverable '.$addclass.'">'.
  598:                '<a href="'.$link.'"'.$disptarget.'>'.
  599:                '<span class="LC_nobreak">'.$title.
  600:                '<span class="LC_fontsize_small" style="font-weight:normal;">'.
  601:                ' &#9660;</span></span></a>'.
  602:                '<ul>';
  603: 
  604:     # $link and $title are only used in the initial string written in $menu
  605:     # as seen above, not needed for nested submenus
  606:     $menu .= &build_submenu($target, $submenu, $translate, '1');
  607:     $menu .= '</ul></li>';
  608: 
  609:     return $menu;
  610: }
  611: 
  612: # helper routine for create_submenu
  613: # build the dropdown (and nested submenus) recursively
  614: # see perldoc create_submenu documentation for further information
  615: sub build_submenu {
  616:     my ($target, $submenu, $translate, $first_level) = @_;
  617:     unless (@{$submenu}) {
  618:         return '';
  619:     }
  620: 
  621:     my $menu = '';
  622:     my $count = 0;
  623:     my $numsub = scalar(@{$submenu});
  624:     foreach my $item (@{$submenu}) {
  625:         $count ++;
  626:         if (ref($item) eq 'ARRAY') {
  627:             my $href = $item->[0];
  628:             my $bordertop;
  629:             my $borderbot;
  630:             my $title;
  631: 
  632:             if ($translate) {
  633:                  $title = &mt($item->[1]);
  634:             } else {
  635:                 $title = $item->[1];
  636:             }
  637: 
  638:             if ($count == 1 && !$first_level) {
  639:                 $bordertop = 'border-top: 1px solid black;';
  640:             }
  641:             if ($count == $numsub) {
  642:                 $borderbot = 'border-bottom: 1px solid black;';
  643:             }
  644: 
  645:             # href is a reference to another submenu
  646:             if (ref($href) eq 'ARRAY') {
  647:                 $menu .= '<li style="margin:0;padding:0;'.$bordertop . $borderbot . '">';
  648:                 $menu .= '<p><span class="LC_primary_menu_innertitle">'
  649:                                         . $title . '</span><span class="LC_primary_menu_innerarrow">&#9654;</span></p>';
  650:                 $menu .= '<ul>';
  651:                 $menu .= &build_submenu($target, $href, $translate);
  652:                 $menu .= '</ul>';
  653:                 $menu .= '</li>';
  654:             } else {    # href is the actual hyperlink and does not represent another submenu
  655:                         # for the current menu title
  656:                 if ($href =~ /(aboutme|rss\.html)$/) {
  657:                     next unless (($env{'user.name'} ne '') && ($env{'user.domain'} ne ''));
  658:                     $href =~ s/\[domain\]/$env{'user.domain'}/g;
  659:                     $href =~ s/\[user\]/$env{'user.name'}/g;
  660:                 } elsif (($href =~ m{^/adm/preferences\?}) && ($href =~ /\[returnurl\]/)) {
  661:                     my $returnurl = $ENV{'REQUEST_URI'};
  662:                     if ($ENV{'REQUEST_URI'} =~ m{/adm/preferences\?action=(?:changedomcoord|authorsettings)\&returnurl=([^\&]+)$}) {
  663:                         $returnurl = $1;
  664:                     }
  665:                     if (($returnurl =~ m{^/adm/createuser($|\?action=)}) ||
  666:                         ($returnurl =~ m{^/priv/$match_domain/$match_username}) ||
  667:                         ($returnurl =~ m{^/res(/?$|/$match_domain/$match_username)})) {
  668:                         $returnurl =~ s{\?.*$}{};
  669:                         $returnurl = '&amp;returnurl='.&HTML::Entities::encode($returnurl,'"<>&\'');
  670:                     } else {
  671:                         undef($returnurl);
  672:                     }
  673:                     $href =~ s/\[returnurl\]/$returnurl/;
  674:                 }
  675:                 unless (($href eq '') || ($href =~ /^\#/)) {
  676:                     $target = ' target="_top"';
  677:                 }
  678: 
  679:                 $menu .= '<li style="margin:0;padding:0;'. $bordertop . $borderbot .'">';
  680:                 $menu .= '<a href="'.$href.'"'.$target.'>' .  $title . '</a>';
  681:                 $menu .= '</li>';
  682:             }
  683:         }
  684:     }
  685:     return $menu;
  686: }
  687: 
  688: sub registerurl {
  689:     my ($forcereg) = @_;
  690:     my $result = '';
  691:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  692:     my $force_title='';
  693:     if ($env{'request.state'} eq 'construct') {
  694:         $force_title=&Apache::lonxml::display_title();
  695:     }
  696:     if (($env{'environment.remote'} ne 'on') ||
  697:         ((($env{'request.publicaccess'}) ||
  698:          (!&Apache::lonnet::is_on_map(
  699:            &unescape($env{'request.noversionuri'})))) &&
  700:         (!$forcereg))) {
  701:         return
  702:         $result
  703:        .'<script type="text/javascript">'."\n"
  704:        .'// <![CDATA['."\n"
  705:        .'function LONCAPAreg(){;} function LONCAPAstale(){}'."\n"
  706:        .'// ]]>'."\n"
  707:        .'</script>'
  708:        .$force_title;
  709:     }
  710: # Graphical display after login only
  711:     if ($env{'request.registered'} && !$forcereg) { return ''; }
  712:     $result.=&innerregister($forcereg);
  713:     return $result.$force_title;
  714: }
  715: 
  716: sub innerregister {
  717:     my ($forcereg,$bread_crumbs,$group,$pagebuttonshide,$hostname) = @_;
  718:     my $const_space = ($env{'request.state'} eq 'construct');
  719:     my $is_const_dir = 0;
  720: 
  721:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  722: 
  723:     $env{'request.registered'} = 1;
  724: 
  725:     my $noremote = ($env{'environment.remote'} ne 'on');
  726: 
  727:     undef(@inlineremote);
  728: 
  729:     my $reopen=&Apache::lonmenu::reopenmenu();
  730: 
  731:     my $newmail='';
  732: 
  733:     if (&Apache::lonmsg::newmail() && !$noremote) {
  734:         # We have new mail and remote is up
  735:         $newmail= 'swmenu.setstatus("you have","messages");';
  736:     }
  737: 
  738:     my ($mapurl,$resurl,$crstype,$navmap);
  739: 
  740:     if ($env{'request.course.id'}) {
  741: #
  742: #course_type:  Course or Community
  743: #
  744:         $crstype = &Apache::loncommon::course_type();
  745:         if ($env{'request.symb'}) {
  746:             my $ignorenull;
  747:             unless ($env{'request.noversionuri'} eq '/adm/navmaps') {
  748:                 $ignorenull = 1;
  749:             }
  750:             my $symb = &Apache::lonnet::symbread('','',$ignorenull);
  751:             ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb($symb);
  752:             my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
  753: 
  754:             my $maptitle = &Apache::lonnet::gettitle($mapurl);
  755:             my $restitle = &Apache::lonnet::gettitle($symb);
  756: 
  757:             my (@crumbs,@mapcrumbs);
  758:             if (($env{'request.noversionuri'} ne '/adm/navmaps') && ($mapurl ne '') &&
  759:                 ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'})) {
  760:                 $navmap = Apache::lonnavmaps::navmap->new();
  761:                 if (ref($navmap)) {
  762:                     @mapcrumbs = $navmap->recursed_crumbs($mapurl,$restitle);
  763:                 }
  764:             }
  765:             unless (($forcereg) && 
  766:                     ($env{'request.noversionuri'} eq '/adm/navmaps') &&
  767:                     ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
  768:                 @crumbs = ({text  => $crstype.' Contents', 
  769:                             href  => "Javascript:gopost('/adm/navmaps','')"});
  770:             }
  771:             if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { 
  772:                 if (@mapcrumbs) {
  773:                     push(@crumbs,@mapcrumbs);
  774:                 } else {
  775:                     push(@crumbs, {text  => '...',
  776:                                    no_mt => 1});
  777:                 }
  778:             }
  779: 
  780:             unless ((@mapcrumbs) || (!$maptitle) || ($maptitle eq 'default.sequence') ||
  781:                     ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
  782:                 push @crumbs, {text => $maptitle, no_mt => 1,
  783:                                href => &Apache::lonnet::clutter($mapurl).'?navmap=1'};
  784:             }
  785:             if ($restitle && !@mapcrumbs) {
  786:                 push(@crumbs,{text => $restitle, no_mt => 1});
  787:             }
  788:             my @tools;
  789:             if ($env{'request.filename'} =~ /\.page$/) {
  790:                 my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
  791:                 if (ref($breadcrumb_tools{'tools'}) eq 'ARRAY') {
  792:                     @tools = @{$breadcrumb_tools{'tools'}};
  793:                 }
  794:             }
  795:             &Apache::lonhtmlcommon::clear_breadcrumbs();
  796:             &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
  797:             if (@tools) {
  798:                 &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',@tools);
  799:             }
  800:         } else {
  801:             $resurl = $env{'request.noversionuri'};
  802:             my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
  803:             my $title = &mt('View Resource');
  804:             if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) {
  805:                 &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']);
  806:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
  807:                 if ($env{'form.title'}) {
  808:                     $title = $env{'form.title'};
  809:                 }
  810:                 my $trail;
  811:                 if ($env{'form.folderpath'}) {
  812:                     &prepare_functions($resurl,$forcereg,$group,undef,undef,1,$hostname);
  813:                     ($trail) =
  814:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
  815:                 } else {
  816:                     &Apache::lonhtmlcommon::add_breadcrumb(
  817:                     {text  => "Supplemental $crstype Content",
  818:                      href  => "javascript:gopost('/adm/supplemental','')"});
  819:                     $title = &mt('View Resource');
  820:                     ($trail) =
  821:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
  822:                 }
  823:                 return $trail;
  824:             } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) {
  825:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
  826:                 &prepare_functions('/public'.$courseurl."/syllabus",
  827:                                    $forcereg,$group,undef,undef,1,$hostname);
  828:                 $title = &mt('Syllabus File');
  829:                 my ($trail) =
  830:                     &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,$hostname);
  831:                 return $trail;
  832:             }
  833:             unless ($env{'request.state'} eq 'construct') {
  834:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
  835:                 &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
  836:             }
  837:         }
  838:     } elsif (! $const_space){
  839:         #a situation when we're looking at a resource outside of context of a 
  840:         #course or construction space (e.g. with cumulative rights)
  841:         &Apache::lonhtmlcommon::clear_breadcrumbs();
  842:         unless ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
  843:             &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
  844:         }
  845:     }
  846:     my $timesync   = ( $noremote ? '' : 'swmenu.syncclock(1000*'.time.');' );
  847: # =============================================================================
  848: # ============================ This is for URLs that actually can be registered
  849:     if ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/})
  850:                        || ($forcereg)) {
  851: 
  852:         my %swtext;
  853:         if ($noremote) {
  854:             %swtext = &get_inline_text();
  855:         } else {
  856:             %swtext = &get_rc_text();
  857:         }
  858:         my $hwkadd='';
  859: 
  860:         my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
  861:             $forceview,$editbutton);
  862:         if (($resurl =~ m{^/adm/($match_domain)/($match_username)/aboutme$}) ||
  863:             ($env{'request.role'} !~/^(aa|ca|au)/)) {
  864:             if (($env{'environment.remote'} eq 'on') && ($env{'request.symb'})) {
  865:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
  866:             }
  867:             $editbutton = &prepare_functions($resurl,$forcereg,$group,'','','',$hostname);
  868:         }
  869:         if ($editbutton eq '') {
  870:             $editbutton = &clear(6,1);
  871:         }
  872: 
  873: #
  874: # This applies in course context
  875: #
  876:         if ($env{'request.course.id'}) {
  877:             $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  878:             $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  879:             $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
  880:             $perms{'cev'} = &Apache::lonnet::allowed('cev',$env{'request.course.id'});
  881:             my @privs;
  882:             if ($env{'request.symb'} ne '') {
  883:                 if ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
  884:                     push(@privs,('mgr','vgr'));
  885:                 }
  886:                 push(@privs,('opa','vpa'));
  887:             }
  888:             foreach my $priv (@privs) {
  889:                 $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
  890:                 if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
  891:                     $perms{$priv} =
  892:                         &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
  893:                 }
  894:             }
  895: #
  896: # Determine whether or not to show Grades and Submissions buttons
  897: #
  898:             if ($env{'request.symb'} ne '' &&
  899:                 $env{'request.filename'}=~/$LONCAPA::assess_re/) {
  900:                 if ($perms{'mgr'}) {
  901:                     $hwkadd.= &switch('','',7,2,'pgrd.png','Content Grades',
  902:                                       'grades[_4]',
  903:                                       "gocmd('/adm/grades','gradingmenu')",
  904:                                       'Content Grades');
  905:                 } elsif ($perms{'vgr'}) {
  906:                     $hwkadd .= &switch('','',7,2,'subm.png','Content Submissions',
  907:                                        'missions[_1]',
  908:                                        "gocmd('/adm/grades','submission')",
  909:                                        'Content Submissions');
  910:                 }
  911:             }
  912:             if (($env{'request.symb'} ne '') && (($perms{'opa'}) || ($perms{'vpa'}))) {
  913:                 $hwkadd .= &switch('','',7,3,'pparm.png','Content Settings',
  914:                                    'parms[_2]',"gocmd('/adm/parmset','set')",
  915:                                    'Content Settings');
  916:             }
  917: # End grades/submissions check
  918: 
  919: #
  920: # This applies to items inside a folder/page modifiable in the course.
  921: #
  922:             if (($env{'request.symb'}=~/^uploaded/) && (($perms{'mdc'}) || ($perms{'cev'}))) {
  923:                 my $text = 'Edit Folder';
  924:                 if (($mapurl =~ /\.page$/) ||
  925:                     ($env{'request.symb'}=~
  926:                          m{uploaded/$cdom/$cnum/default_\d+\.page$}))  {
  927:                     $text = 'Edit Page';
  928:                 }
  929:                 $hwkadd .= &switch('','',7,4,'docs-22x22.png',$text,'parms[_2]',
  930:                                    "gocmd('/adm/coursedocs','direct')",
  931:                                    'Folder/Page Content');
  932:             }
  933: # End modifiable folder/page container check
  934:         }
  935: # End course context
  936: 
  937: # Prepare the rest of the buttons
  938:         my ($menuitems,$got_prt,$got_wishlist,$cstritems);
  939:         if ($const_space) {
  940: #
  941: # We are in construction space
  942: #
  943: 
  944:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
  945: 	    my ($udom,$uname,$thisdisfn) =
  946: 		($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
  947:             my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
  948:             if ($currdir =~ m-/$-) {
  949:                 $is_const_dir = 1;
  950:                 if ($thisdisfn eq '') {
  951:                     $is_const_dir = 2;
  952:                 }
  953:             } else {
  954:                 $currdir =~ s|[^/]+$||;
  955: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
  956: 		my $esc_currdir = &Apache::loncommon::escape_single($currdir);
  957: #
  958: # Probably should be in mydesk.tab
  959: #
  960:                 $menuitems=(<<ENDMENUITEMS);
  961: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
  962: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
  963: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
  964: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
  965: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
  966: ENDMENUITEMS
  967:                 unless ($noremote) {
  968:                     $cstritems = $menuitems;
  969:                     undef($menuitems);
  970:                 }
  971:             }
  972:             if (ref($bread_crumbs) eq 'ARRAY') {
  973:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
  974:                 foreach my $crumb (@{$bread_crumbs}){
  975:                      &Apache::lonhtmlcommon::add_breadcrumb($crumb);
  976:                 }
  977:             }
  978:         } elsif ( defined($env{'request.course.id'}) && 
  979: 		 $env{'request.symb'} ne '' ) {
  980: #
  981: # We are in a course and looking at a registered URL
  982: # Should probably be in mydesk.tab
  983: #
  984: 
  985: 	    $menuitems=(<<ENDMENUITEMS);
  986: c&3&1
  987: s&2&1&back.png&$swtext{'back'}&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
  988: s&2&3&forw.png&$swtext{'forw'}&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3
  989: c&6&3
  990: c&8&1
  991: c&8&2
  992: s&8&3&prt.png&$swtext{'prt'}&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  993: ENDMENUITEMS
  994:             $got_prt = 1;
  995:             if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
  996:                 && (!$env{'request.enc'})) {
  997:                 # wishlist is only available for users with access to resource-pool
  998:                 # and links can only be set for resources within the resource-pool
  999:                 $menuitems .= (<<ENDMENUITEMS);
 1000: s&9&1&alnk.png&$swtext{'alnk'}&linkstor[_1]&set_wishlistlink('',currentURL)&Save a link for this resource in my personal Stored Links repository&&1
 1001: ENDMENUITEMS
 1002:                 $got_wishlist = 1;
 1003:             }
 1004: 
 1005: my $currentURL = &Apache::loncommon::get_symb();
 1006: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
 1007: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
 1008: $menuitems.="s&9&3&";
 1009: if(length($annotation) > 0){
 1010: 	$menuitems.="anot2.png";
 1011: }else{
 1012: 	$menuitems.="anot.png";
 1013: }
 1014: $menuitems.="&$swtext{'anot'}&tations[_1]&annotate()&";
 1015: $menuitems.="Make notes and annotations about this resource&&1\n";
 1016: my $is_mobile;
 1017: if ($env{'browser.mobile'}) {
 1018:     $is_mobile = 1;
 1019: }
 1020: 
 1021:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio|ext\.tool)(\?|$)/) {
 1022: 		if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) {
 1023: 		    $menuitems.=(<<ENDREALRES);
 1024: s&6&3&catalog.png&$swtext{'catalog'}&info[_1]&catalog_info('$is_mobile')&Show Metadata
 1025: ENDREALRES
 1026:                 }
 1027:                 unless (($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/docs/}) ||
 1028:                         ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/})) { 
 1029: 	            $menuitems.=(<<ENDREALRES);
 1030: s&8&1&eval.png&$swtext{'eval'}&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
 1031: ENDREALRES
 1032:                 }
 1033:                 unless ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) {
 1034:                     $menuitems.=(<<ENDREALRES);
 1035: s&8&2&fdbk.png&$swtext{'fdbk'}&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
 1036: ENDREALRES
 1037:                 }
 1038: 	    }
 1039:         }
 1040: 	if ($env{'request.uri'} =~ /^\/res/) {
 1041:             unless ($got_prt) {
 1042: 	        $menuitems .= (<<ENDMENUITEMS);
 1043: s&8&3&prt.png&$swtext{'prt'}&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
 1044: ENDMENUITEMS
 1045:                 $got_prt = 1;
 1046:             }
 1047:             unless ($got_wishlist) {
 1048:                 if (($env{'user.adv'}) && (!$env{'request.enc'})) {
 1049:                     # wishlist is only available for users with access to resource-pool
 1050:                     $menuitems .= (<<ENDMENUITEMS);
 1051: s&9&1&alnk.png&$swtext{'alnk'}&linkstor[_1]&set_wishlistlink('',currentURL)&Save a link for this resource in your personal Stored Links repository&&1
 1052: ENDMENUITEMS
 1053:                     $got_wishlist = 1;
 1054:                 }
 1055:             }
 1056: 	}
 1057:         unless ($got_prt) {
 1058:             $menuitems .= (<<ENDMENUITEMS);
 1059: c&8&3
 1060: ENDMENUITEMS
 1061:         }
 1062:         unless ($got_wishlist) {
 1063:             $menuitems .= (<<ENDMENUITEMS);
 1064: c&9&1
 1065: ENDMENUITEMS
 1066:         }
 1067:         my $buttons='';
 1068:         foreach (split(/\n/,$menuitems)) {
 1069: 	    my ($command,@rest)=split(/\&/,$_);
 1070:             my $idx=10*$rest[0]+$rest[1];
 1071:             if (&hidden_button_check() eq 'yes') {
 1072:                 if ($idx == 21 ||$idx == 23) {
 1073:                     $buttons.=&switch('','',@rest);
 1074:                 } else {
 1075:                     $buttons.=&clear(@rest);
 1076:                 }
 1077:             } else {  
 1078:                 if ($command eq 's') {
 1079: 	            $buttons.=&switch('','',@rest);
 1080:                 } else {
 1081:                     $buttons.=&clear(@rest);
 1082:                 }
 1083:             }
 1084:         }
 1085:         if ($noremote) {
 1086: 	    my $addremote=0;
 1087: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
 1088:             if ($addremote) {
 1089:                 my ($countdown,$buttonshide);
 1090:                 if ($env{'request.filename'} =~ /\.page$/) {
 1091:                     my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
 1092:                     if (ref($breadcrumb_tools{'tools'}) eq 'ARRAY') {
 1093:                         $countdown = $breadcrumb_tools{'tools'}->[0];
 1094:                     }
 1095:                     $buttonshide = $pagebuttonshide;
 1096:                 } else {
 1097:                     $countdown = &countdown_timer();
 1098:                     $buttonshide = &hidden_button_check();
 1099:                 }
 1100: 
 1101:                 &Apache::lonhtmlcommon::clear_breadcrumb_tools();
 1102: 
 1103:                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1104:                     'navigation', @inlineremote[21,23]);
 1105: 
 1106:                 if ($buttonshide eq 'yes') {
 1107:                     if ($countdown) {
 1108:                         &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
 1109:                     }
 1110:                 } else {
 1111:                     my @tools = @inlineremote[93,91,81,82,83];
 1112:                     if ($countdown) {
 1113:                         unshift(@tools,$countdown);
 1114:                     }
 1115:                     &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1116:                         'tools',@tools);
 1117: 
 1118:                     #publish button in construction space
 1119:                     if ($env{'request.state'} eq 'construct'){
 1120:                         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1121:                             'advtools', $inlineremote[63]);
 1122:                     } else {
 1123:                         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1124:                             'tools', $inlineremote[63]);
 1125:                     }
 1126:                     &advtools_crumbs(@inlineremote);
 1127:                 }
 1128:             }
 1129:             my ($topic_help,$topic_help_text);
 1130:             if ($is_const_dir == 2) {
 1131:                 if ((($ENV{'SERVER_PORT'} == 443) ||
 1132:                      ($Apache::lonnet::protocol{$Apache::lonnet::perlvar{'lonHostID'}} eq 'https')) &&
 1133:                      (&Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},'webdav'))) {
 1134:                     $topic_help = 'Authoring_WebDAV,Authoring_WebDAV_Mac_10v6,Authoring_WebDAV_Mac_10v10,'.
 1135:                                  'Authoring_WebDAV_Windows_v7,Authoring_WebDAV_Linux_Centos';
 1136:                     $topic_help_text = 'About WebDAV access';
 1137:                 }
 1138:             }
 1139:             return   &Apache::lonhtmlcommon::scripttag('', 'start')
 1140:                    . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'','','','',$topic_help,$topic_help_text)
 1141:                    . &Apache::lonhtmlcommon::scripttag('', 'end');
 1142: 
 1143:         } else {
 1144:             my $cstrcrumbs;
 1145:             if ($const_space) {
 1146:                 foreach (split(/\n/,$cstritems)) {
 1147:                     my ($command,@rest)=split(/\&/,$_);
 1148:                     my $idx=10*$rest[0]+$rest[1];
 1149:                     &switch('','',@rest);
 1150:                 }
 1151:                 &Apache::lonhtmlcommon::add_breadcrumb_tool('advtools',
 1152:                                                             @inlineremote[63,61,71,72]);
 1153: 
 1154:                 $cstrcrumbs = &Apache::lonhtmlcommon::scripttag('', 'start')
 1155:                              .&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
 1156:                              .&Apache::lonhtmlcommon::scripttag('', 'end');
 1157:             }
 1158:             my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
 1159:             $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
 1160:             my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
 1161:             my $navstatus=&get_nav_status();
 1162:             my $clearcstr;
 1163: 
 1164:             if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
 1165:             return <<ENDREGTHIS;
 1166: 
 1167: <script type="text/javascript">
 1168: // <![CDATA[
 1169: // BEGIN LON-CAPA Internal
 1170: var swmenu=null;
 1171: 
 1172:     function LONCAPAreg() {
 1173:           swmenu=$reopen;
 1174:           swmenu.clearTimeout(swmenu.menucltim);
 1175:           $timesync
 1176:           $newmail
 1177:           $buttons
 1178:           swmenu.currentURL="$requri";
 1179:           swmenu.reloadURL=swmenu.currentURL+window.location.search;
 1180:           swmenu.currentSymb="$cursymb";
 1181:           swmenu.reloadSymb="$cursymb";
 1182:           swmenu.currentStale=0;
 1183:           $navstatus
 1184:           $hwkadd
 1185:           $editbutton
 1186:     }
 1187: 
 1188:     function LONCAPAstale() {
 1189:           swmenu=$reopen
 1190:           swmenu.currentStale=1;
 1191:           if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) {
 1192:              swmenu.switchbutton
 1193:              (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
 1194:           }
 1195:           swmenu.clearbut(7,2);
 1196:           swmenu.clearbut(7,3);
 1197:           swmenu.menucltim=swmenu.setTimeout(
 1198:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
 1199:  'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
 1200:                           2000);
 1201:       }
 1202: 
 1203: // END LON-CAPA Internal
 1204: // ]]>
 1205: </script>
 1206: 
 1207: $cstrcrumbs
 1208: ENDREGTHIS
 1209:         }
 1210:     } else {
 1211:        unless ($noremote) {
 1212: # Not registered, graphical
 1213:            return (<<ENDDONOTREGTHIS);
 1214: 
 1215: <script type="text/javascript">
 1216: // <![CDATA[
 1217: // BEGIN LON-CAPA Internal
 1218: var swmenu=null;
 1219: 
 1220:     function LONCAPAreg() {
 1221:           swmenu=$reopen
 1222:           $timesync
 1223:           swmenu.currentStale=1;
 1224:           swmenu.clearbut(2,1);
 1225:           swmenu.clearbut(2,3);
 1226:           swmenu.clearbut(8,1);
 1227:           swmenu.clearbut(8,2);
 1228:           swmenu.clearbut(8,3);
 1229:           swmenu.clearbut(9,1);
 1230:           if (swmenu.currentURL) {
 1231:              swmenu.switchbutton
 1232:               (3,1,'reload.gif','return','location','go(currentURL)');
 1233:           } else {
 1234:               swmenu.clearbut(3,1);
 1235:           }
 1236:     }
 1237: 
 1238:     function LONCAPAstale() {
 1239:     }
 1240: 
 1241: // END LON-CAPA Internal
 1242: // ]]>
 1243: </script>
 1244: ENDDONOTREGTHIS
 1245: 
 1246:         }
 1247:         return '';
 1248:     }
 1249: }
 1250: 
 1251: sub get_inline_text {
 1252:     my %text = (
 1253:                  pgrd     => 'Content Grades',
 1254:                  subm     => 'Content Submissions',
 1255:                  pparm    => 'Content Settings',
 1256:                  docs     => 'Folder/Page Content',
 1257:                  pcstr    => 'Edit',
 1258:                  prt      => 'Print',
 1259:                  alnk     => 'Stored Links',
 1260:                  anot     => 'Notes',
 1261:                  catalog  => 'Info',
 1262:                  eval     => 'Evaluate',
 1263:                  fdbk     => 'Feedback',
 1264:     );
 1265:     return %text;
 1266: }
 1267: 
 1268: sub get_rc_text {
 1269:     my %text = (
 1270:                    pgrd    => 'problem[_1]',
 1271:                    subm    => 'view sub-[_1]',
 1272:                    pparm   => 'problem[_2]',
 1273:                    pcstr   => 'edit[_1]',
 1274:                    prt     => 'prepare[_1]',
 1275:                    back    => 'backward[_1]',
 1276:                    forw    => 'forward[_1]',
 1277:                    alnk    => 'add to[_1]',
 1278:                    anot    => 'anno-[_1]',
 1279:                    catalog => 'catalog[_2]',
 1280:                    eval    => 'evaluate[_1]',
 1281:                    fdbk    => 'feedback[_1]',
 1282:     );
 1283:     return %text;
 1284: }
 1285: 
 1286: sub loadevents() {
 1287:     if ($env{'request.state'} eq 'construct' ||
 1288:         $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
 1289:     return 'LONCAPAreg();';
 1290: }
 1291: 
 1292: sub unloadevents() {
 1293:     if ($env{'request.state'} eq 'construct' ||
 1294:         $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
 1295:     return 'LONCAPAstale();';
 1296: }
 1297: 
 1298: sub startupremote {
 1299:     my ($lowerurl)=@_;
 1300:     unless ($env{'environment.remote'} eq 'on') {
 1301:         return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
 1302:     }
 1303: #
 1304: # The Remote actually gets launched!
 1305: #
 1306:     my $configmenu=&rawconfig();
 1307:     my $esclowerurl=&escape($lowerurl);
 1308:     my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
 1309:     return(<<ENDREMOTESTARTUP);
 1310: <script type="text/javascript">
 1311: // <![CDATA[
 1312: var timestart;
 1313: function wheelswitch() {
 1314:     if (typeof(document.wheel) != 'undefined') {
 1315:         if (typeof(document.wheel.spin) != 'undefined') {
 1316:             var date=new Date();
 1317:             var waited=Math.round(30-((date.getTime()-timestart)/1000));
 1318:             document.wheel.spin.value=$message;
 1319:         }
 1320:     }
 1321:    if (window.status=='|') {
 1322:       window.status='/';
 1323:    } else {
 1324:       if (window.status=='/') {
 1325:          window.status='-';
 1326:       } else {
 1327:          if (window.status=='-') {
 1328:             window.status='\\\\';
 1329:          } else {
 1330:             if (window.status=='\\\\') { window.status='|'; }
 1331:          }
 1332:       }
 1333:    }
 1334: }
 1335: 
 1336: // ---------------------------------------------------------- The wait function
 1337: var canceltim;
 1338: function wait() {
 1339:    if ((menuloaded==1) || (tim==1)) {
 1340:       window.status='Done.';
 1341:       if (tim==0) {
 1342:          clearTimeout(canceltim);
 1343:          $configmenu
 1344:          window.location='$lowerurl';
 1345:       } else {
 1346:           window.location='/adm/remote?action=collapse&url=$esclowerurl';
 1347:       }
 1348:    } else {
 1349:       wheelswitch();
 1350:       setTimeout('wait();',200);
 1351:    }
 1352: }
 1353: 
 1354: function main() {
 1355:    canceltim=setTimeout('tim=1;',30000);
 1356:    window.status='-';
 1357:    var date=new Date();
 1358:    timestart=date.getTime();
 1359:    wait();
 1360: }
 1361: 
 1362: // ]]>
 1363: </script>
 1364: ENDREMOTESTARTUP
 1365: }
 1366: 
 1367: sub setflags() {
 1368:     return(<<ENDSETFLAGS);
 1369: <script type="text/javascript">
 1370: // <![CDATA[
 1371:     menuloaded=0;
 1372:     tim=0;
 1373: // ]]>
 1374: </script>
 1375: ENDSETFLAGS
 1376: }
 1377: 
 1378: sub maincall() {
 1379:     unless ($env{'environment.remote'} eq 'on') { return ''; }
 1380:     return(<<ENDMAINCALL);
 1381: <script type="text/javascript">
 1382: // <![CDATA[
 1383:     main();
 1384: // ]]>
 1385: </script>
 1386: ENDMAINCALL
 1387: }
 1388: 
 1389: sub load_remote_msg {
 1390:     my ($lowerurl)=@_;
 1391: 
 1392:     unless ($env{'environment.remote'} eq 'on') { return ''; }
 1393: 
 1394:     my $esclowerurl=&escape($lowerurl);
 1395:     my $link=&mt('[_1]Continue[_2] on in Inline Menu mode'
 1396:                 ,'<a href="/adm/remote?action=collapse&amp;url='.$esclowerurl.'">'
 1397:                 ,'</a>');
 1398:     return(<<ENDREMOTEFORM);
 1399: <p>
 1400: <form name="wheel">
 1401: <input name="spin" type="text" size="60" />
 1402: </form>
 1403: </p>
 1404: <p>$link</p>
 1405: ENDREMOTEFORM
 1406: }
 1407: 
 1408: sub get_menu_name {
 1409:     my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
 1410:     $hostid =~ s/\W//g;
 1411:     return 'LCmenu'.$hostid;
 1412: }
 1413: 
 1414: 
 1415: sub reopenmenu {
 1416:    unless ($env{'environment.remote'} eq 'on') { return ''; }
 1417:    my $menuname = &get_menu_name();
 1418:    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
 1419:    return('window.open('.$nothing.',"'.$menuname.'","",false);');
 1420: }
 1421: 
 1422: 
 1423: sub open {
 1424:     my $returnval='';
 1425:     unless ($env{'environment.remote'} eq 'on') {
 1426:         return
 1427:         '<script type="text/javascript">'."\n"
 1428:        .'// <![CDATA['."\n"
 1429:        .'self.name="loncapaclient";'."\n"
 1430:        .'// ]]>'."\n"
 1431:        .'</script>';
 1432:     }
 1433:     my $menuname = &get_menu_name();
 1434: 
 1435: #    unless (shift eq 'unix') {
 1436: # resizing does not work on linux because of virtual desktop sizes
 1437: #       $returnval.=(<<ENDRESIZE);
 1438: #if (window.screen) {
 1439: #    self.resizeTo(screen.availWidth-215,screen.availHeight-55);
 1440: #    self.moveTo(190,15);
 1441: #}
 1442: #ENDRESIZE
 1443: #    }
 1444:     $returnval=(<<ENDOPEN);
 1445: // <![CDATA[
 1446: window.status='Opening LON-CAPA Remote Control';
 1447: var menu=window.open("/res/adm/pages/menu.html?inhibitmenu=yes","$menuname",
 1448: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
 1449: self.name='loncapaclient';
 1450: // ]]>
 1451: ENDOPEN
 1452:     return '<script type="text/javascript">'.$returnval.'</script>';
 1453: }
 1454: 
 1455: sub get_editbutton {
 1456:     my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg,$hostname) = @_;
 1457:     my $jscall;
 1458:     if (($forceview) && ($env{'form.todocs'})) {
 1459:         my ($folderpath,$command,$navmap);
 1460:         if ($env{'request.symb'}) {
 1461:             $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'},\$navmap);
 1462:         } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
 1463:             $folderpath = $env{'form.folderpath'};
 1464:             $command = '&forcesupplement=1';
 1465:         }
 1466:         $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
 1467:         $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
 1468:     } else {
 1469:         my $suppanchor;
 1470:         if ($env{'form.folderpath'}) {
 1471:             $suppanchor = $env{'form.anchor'};
 1472:         }
 1473:         $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
 1474:                                                 $forceedit,$forcereg,$env{'request.symb'},
 1475:                                                 &escape($env{'form.folderpath'}),
 1476:                                                 &escape($env{'form.title'}),$hostname,
 1477:                                                 $env{'form.idx'},&escape($env{'form.suppurl'}),
 1478:                                                 $env{'form.todocs'},$suppanchor);
 1479:     }
 1480:     if ($jscall) {
 1481:         my $icon = 'pcstr.png';
 1482:         my $label = 'Edit';
 1483:         if ($forceview) {
 1484:             $icon = 'tolastloc.png';
 1485:             $label = 'Exit Editing';
 1486:         }
 1487:         my $infunc = 1;
 1488:         my $clearbutton;
 1489:         if ($env{'environment.remote'} eq 'on') {
 1490:             if ($cfile =~ m{^/priv/}) {
 1491:                 undef($infunc);
 1492:                 $label = 'edit';
 1493:             } else {
 1494:                 $clearbutton = 1;
 1495:             }
 1496:         }
 1497:         my $editor = &switch('','',6,1,$icon,$label,'resource[_2]',
 1498:                              $jscall,"Edit this resource",'','',$infunc);
 1499:         if ($infunc) {
 1500:             return 1;
 1501:         } elsif ($clearbutton) {
 1502:             return &clear(6,1);
 1503:         } else {
 1504:             return $editor;
 1505:         }
 1506:     }
 1507:     return;
 1508: }
 1509: 
 1510: sub prepare_functions {
 1511:     my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs,$hostname,$forbodytag) = @_;
 1512:     unless ($env{'request.registered'}) {
 1513:         undef(@inlineremote);
 1514:     }
 1515:     my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
 1516:         $forceview);
 1517: 
 1518:     if ($env{'request.course.id'}) {
 1519:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 1520:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1521:         $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
 1522:     }
 1523: 
 1524:     my $editbutton = '';
 1525:     my $viewsrcbutton = '';
 1526: #
 1527: # Determine whether or not to display 'Edit' or 'View Source' icon/button
 1528: #
 1529:     if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
 1530:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
 1531:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1532:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
 1533:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
 1534:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
 1535:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1536:                                           $forceedit,$forceview,$forcereg);
 1537:         }
 1538:     } elsif ((!$env{'request.course.id'}) &&
 1539:              ($env{'user.author'}) && ($env{'request.filename'}) &&
 1540:              ($env{'request.role'} !~/^(aa|ca|au)/)) {
 1541: #
 1542: # Currently do not have the role of author or co-author.
 1543: # Do we have authoring privileges for the resource?
 1544: #
 1545:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
 1546:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1547:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
 1548:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
 1549:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
 1550:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1551:                                           $forceedit,$forceview,$forcereg);
 1552:         }
 1553:     } elsif ($env{'request.course.id'}) {
 1554: #
 1555: # This applies in course context
 1556: #
 1557:         if (($perms{'mdc'}) &&
 1558:             (($resurl =~ m{^/?public/$cdom/$cnum/syllabus}) ||
 1559:             ($resurl =~ m{^/?uploaded/$cdom/$cnum/portfolio/syllabus/}) || 
 1560:             (($resurl =~ m{^/?uploaded/$cdom/$cnum/default_\d+\.sequence$}) && ($env{'form.navmap'})))) {
 1561:             if ($resurl =~ m{^/}) {
 1562:                 $cfile = $resurl;
 1563:             } else {
 1564:                 $cfile = "/$resurl";
 1565:             }
 1566:             $home = &Apache::lonnet::homeserver($cnum,$cdom);
 1567:             if ($env{'form.forceedit'}) {
 1568:                 $forceview = 1;
 1569:             } else {
 1570:                 $forceedit = 1;
 1571:             }
 1572:             if ($cfile =~ m{^/uploaded/$cdom/$cnum/default_\d+\.sequence$}) {
 1573:                 my $text = 'Edit Folder';
 1574:                 &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
 1575:                         "gocmd('/adm/coursedocs','direct')",
 1576:                         'Folder/Page Content');
 1577:                 $editbutton = 1;
 1578:             } else {
 1579:                 $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1580:                                               $forceedit,$forceview,$forcereg,
 1581:                                               $hostname);
 1582:             }
 1583:         } elsif (($resurl eq '/adm/extresedit') &&
 1584:                  (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
 1585:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1586:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
 1587:                                                $env{'form.symb'});
 1588:             if ($cfile ne '') {
 1589:                 $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1590:                                               $forceedit,$forceview,$forcereg,
 1591:                                               $env{'form.title'},$env{'form.suppurl'});
 1592:             }
 1593:         } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
 1594:                  (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
 1595:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1596:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
 1597:                                                $env{'form.symb'});
 1598:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1599:                                           $forceedit,$forceview,$forcereg);
 1600:         } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
 1601:                  ($resurl ne '/cgi-bin/printout.pl')) {
 1602:             if ($env{'request.filename'}) {
 1603:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
 1604:                 ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1605:                     &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
 1606:                         &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
 1607:                 if ($cfile ne '') {
 1608:                     $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1609:                                                   $forceedit,$forceview,$forcereg);
 1610:                 }
 1611:                 if ((($cfile eq '') || (!$editbutton)) &&
 1612:                     ($resurl =~ /$LONCAPA::assess_re/)) {
 1613:                     my $showurl = &Apache::lonnet::clutter($resurl);
 1614:                     if ((&Apache::lonnet::allowed('cre','/')) &&
 1615:                         (&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open')) {
 1616:                         $viewsrcbutton = 1;
 1617:                     } elsif (&Apache::lonnet::allowed('vxc',$env{'request.course.id'})) {
 1618:                         if ($showurl =~ m{^\Q/res/$cdom/\E($match_username)/}) {
 1619:                             my $auname = $1;
 1620:                             if (($env{'request.course.adhocsrcaccess'} ne '') &&
 1621:                                 (grep(/^\Q$auname\E$/,split(/,/,$env{'request.course.adhocsrcaccess'})))) {
 1622:                                 $viewsrcbutton = 1;
 1623:                             } elsif ((&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open') &&
 1624:                                      (&Apache::lonnet::allowed('bre','/'))) {
 1625:                                 $viewsrcbutton = 1;
 1626:                             }
 1627:                         }
 1628:                     }
 1629:                     if ($viewsrcbutton) {
 1630:                         &switch('','',6,1,'pcstr.png','View Source','resource[_2]','open_source()',
 1631:                                 'View source code');
 1632:                     }
 1633:                 }
 1634:             }
 1635:         }
 1636:     }
 1637: # End determination of 'Edit' icon/button display
 1638: 
 1639:     if ($env{'request.course.id'}) {
 1640: # This applies to about me page for users in a course
 1641:         if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
 1642:             my ($sdom,$sname) = ($1,$2);
 1643:             unless (&Apache::lonnet::is_course($sdom,$sname)) {
 1644:                 &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
 1645:                         '',
 1646:                         "go('/adm/email?compose=individual&amp;recname=$sname&amp;recdom=$sdom')",
 1647:                             'Send message to specific user','','',1);
 1648:             }
 1649:             my $hideprivileged = 1;
 1650:             if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
 1651:                                            $hideprivileged)) {
 1652:                 foreach my $priv ('vsa','vgr','srm') {
 1653:                     $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
 1654:                     if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
 1655:                         $perms{$priv} =
 1656:                             &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
 1657:                     }
 1658:                 }
 1659:                 if ($perms{'vsa'}) {
 1660:                     &switch('','',6,5,'trck-22x22.png','Activity',
 1661:                             '',
 1662:                             "go('/adm/trackstudent?selected_student=$sname:$sdom')",
 1663:                             'View recent activity by this person','','',1);
 1664:                 }
 1665:                 if ($perms{'vgr'}) {
 1666:                     &switch('','',6,6,'rsrv-22x22.png','Reservations',
 1667:                             '',
 1668:                             "go('/adm/slotrequest?command=showresv&amp;origin=aboutme&amp;uname=$sname&amp;udom=$sdom')",
 1669:                             'Slot reservation history','','',1);
 1670:                 }
 1671:                 if ($perms{'srm'}) {
 1672:                     &switch('','',6,7,'contact-new-22x22.png','Records',
 1673:                             '',
 1674:                             "go('/adm/email?recordftf=retrieve&amp;recname=$sname&amp;recdom=$sdom')",
 1675:                             'Add records','','',1);
 1676:                 }
 1677:             }
 1678:         }
 1679:         if (($env{'form.folderpath'} =~ /^supplemental/) &&
 1680:             (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
 1681:             (($resurl =~ m{^/adm/wrapper/ext/}) ||
 1682:              ($resurl =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) ||
 1683:              ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
 1684:              ($resurl eq '/adm/supplemental') ||
 1685:              ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
 1686:              ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
 1687:             my @folders=split('&',$env{'form.folderpath'});
 1688:             if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
 1689:                 my $suppanchor;
 1690:                 if ($resurl =~ m{^/adm/wrapper/ext/}) {
 1691:                     $suppanchor = $env{'form.anchor'};
 1692:                 }
 1693:                 my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
 1694:                 my $link = '/adm/coursedocs?command=direct&amp;forcesupplement=1&amp;supppath='.
 1695:                            "$esc_path&amp;anchor=$suppanchor";
 1696:                 if ($env{'request.use_absolute'} ne '') {
 1697:                     $link = $env{'request.use_absolute'}.$link;
 1698:                 }
 1699:                 &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
 1700:                         "location.href='$link'",'Folder/Page Content');
 1701:             }
 1702:         }
 1703:     }
 1704: 
 1705: # End checking for items for about me page for users in a course
 1706:     if ($docscrumbs) {
 1707:         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
 1708:         &advtools_crumbs(@inlineremote);
 1709:         return $editbutton;
 1710:     } elsif (($env{'request.registered'}) && (!ref($forbodytag))) {
 1711:         return $editbutton || $viewsrcbutton;
 1712:     } else {
 1713:         if (ref($bread_crumbs) eq 'ARRAY') {
 1714:             if (@inlineremote > 0) {
 1715:                 if (ref($advtools) eq 'ARRAY') {
 1716:                     @{$advtools} = @inlineremote;
 1717:                 }
 1718:             }
 1719:             return;
 1720:         } elsif (@inlineremote > 0) {
 1721:             &Apache::lonhtmlcommon::clear_breadcrumb_tools();
 1722:             &advtools_crumbs(@inlineremote);
 1723:             if (ref($forbodytag)) {
 1724:                 $$forbodytag =
 1725:                     &Apache::lonhtmlcommon::scripttag('', 'start')
 1726:                    .&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
 1727:                    .&Apache::lonhtmlcommon::scripttag('', 'end');
 1728:             }
 1729:             return;
 1730:         }
 1731:     }
 1732: }
 1733: 
 1734: sub advtools_crumbs {
 1735:     my @funcs = @_;
 1736:     if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
 1737:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1738:             'advtools', @funcs[61,64,65,66,67,74]);
 1739:     } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
 1740:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1741:             'advtools', @funcs[61,71,72,73,74,92]);
 1742:     } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
 1743:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1744:             'advtools', $funcs[61]);
 1745:     }
 1746: }
 1747: 
 1748: # ================================================================== Raw Config
 1749: 
 1750: sub clear {
 1751:     my ($row,$col)=@_;
 1752:     if ($env{'environment.remote'} eq 'on') {
 1753:        if (($row<1) || ($row>13)) { return ''; }
 1754:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
 1755:     } else {
 1756:         $inlineremote[10*$row+$col]='';
 1757:         return '';
 1758:     }
 1759: }
 1760: 
 1761: # ============================================ Switch a button or create a link
 1762: # Switch acts on the javascript that is executed when a button is clicked.  
 1763: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
 1764: 
 1765: sub switch {
 1766:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak,$infunc)=@_;
 1767:     $act=~s/\$uname/$uname/g;
 1768:     $act=~s/\$udom/$udom/g;
 1769:     $top=&mt($top);
 1770:     $bot=&mt($bot);
 1771:     $desc=&mt($desc);
 1772:     my $idx=10*$row+$col;
 1773:     $category_members{$cat}.=':'.$idx;
 1774: 
 1775:     if (($env{'environment.remote'} eq 'on') && (!$infunc)) {
 1776:         if (($row<1) || ($row>13)) { return ''; }
 1777:         if ($env{'request.state'} eq 'construct') {
 1778:             my $text = $top.' '.$bot;
 1779:             $text=~s/\s*\-\s*//gs;
 1780:             my $pic = '<img alt="'.$text.'" src="'.
 1781:                       &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
 1782:                       '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
 1783:            $inlineremote[$idx] =
 1784:                '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.
 1785:                $pic.'<span class="LC_menubuttons_inline_text">'.$top.'&nbsp;</span></a>';
 1786:         }
 1787: # Remote
 1788:         $img=~s/\.png$/\.gif/;
 1789:         return "\n".
 1790:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
 1791:     }
 1792: 
 1793: # Inline Menu
 1794:     if ($nobreak==2) { return ''; }
 1795:     my $text=$top.' '.$bot;
 1796:     $text=~s/\s*\-\s*//gs;
 1797: 
 1798:     my $pic=
 1799: 	   '<img alt="'.$text.'" src="'.
 1800: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
 1801: 	   '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
 1802:     if ($env{'browser.interface'} eq 'faketextual') {
 1803: # Main Menu
 1804: 	   if ($nobreak==3) {
 1805: 	       $inlineremote[$idx]="\n".
 1806: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
 1807: 		   '</td><td align="left">'.
 1808: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
 1809: 	   } elsif ($nobreak) {
 1810: 	       $inlineremote[$idx]="\n<tr>".
 1811: 		   '<td align="left">'.
 1812: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
 1813:                     <td class="LC_menubuttons_text" align="left"><a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$text.'</span></a></td>';
 1814: 	   } else {
 1815: 	       $inlineremote[$idx]="\n<tr>".
 1816: 		   '<td align="left">'.
 1817: 		   '<a href="javascript:'.$act.';">'.$pic.
 1818: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
 1819: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
 1820: 	   }
 1821:     } else {
 1822: # Inline Menu
 1823:         my @tools = (93,91,81,82,83);
 1824:         unless ($env{'request.state'} eq 'construct') {
 1825:             push(@tools,63);
 1826:         }
 1827:         if (($env{'environment.icons'} eq 'iconsonly') &&
 1828:             (grep(/^$idx$/,@tools))) {
 1829:             $inlineremote[$idx] =
 1830:         '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
 1831:         } else {
 1832:             $inlineremote[$idx] =
 1833:        '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
 1834:        '<span class="LC_menubuttons_inline_text">'.$top.'&nbsp;</span></a>';
 1835:         }
 1836:     }
 1837:     return '';
 1838: }
 1839: 
 1840: sub secondlevel {
 1841:     my $output='';
 1842:     my 
 1843:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
 1844:     if ($prt eq 'any') {
 1845: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1846:     } elsif ($prt=~/^r(\w+)/) {
 1847:         if ($rol eq $1) {
 1848:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1849:         }
 1850:     }
 1851:     return $output;
 1852: }
 1853: 
 1854: sub openmenu {
 1855:     my $menuname = &get_menu_name();
 1856:     unless ($env{'environment.remote'} eq 'on') { return ''; }
 1857:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
 1858:     return "window.open(".$nothing.",'".$menuname."');";
 1859: }
 1860: 
 1861: sub inlinemenu {
 1862:     undef(@inlineremote);
 1863:     undef(%category_members);
 1864: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
 1865:     &rawconfig(1);
 1866:     my $output='<table><tr>';
 1867:     for (my $col=1; $col<=2; $col++) {
 1868:         $output.='<td class="LC_mainmenu_col_fieldset">';
 1869:         for (my $row=1; $row<=8; $row++) {
 1870:             foreach my $cat (keys(%category_members)) {
 1871:                if ($category_positions{$cat} ne "$col,$row") { next; }
 1872:                #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
 1873:                $output.='<div class="LC_Box LC_400Box">';
 1874: 	       $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
 1875:                $output.='<table>';
 1876:                my %active=();
 1877:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
 1878:                   if ($inlineremote[$menu_item]) {
 1879:                      $active{$menu_item}=1;
 1880:                   }
 1881:                }  
 1882:                foreach my $item (sort(keys(%active))) {
 1883:                   $output.=$inlineremote[$item];
 1884:                }
 1885:                $output.='</table>';
 1886:                $output.='</div>';
 1887:             }
 1888:          }
 1889:          $output.="</td>";
 1890:     }
 1891:     $output.="</tr></table>";
 1892:     return $output;
 1893: }
 1894: 
 1895: sub rawconfig {
 1896: #
 1897: # This evaluates mydesk.tab
 1898: # Need to add more positions and more privileges to deal with all
 1899: # menu items.
 1900: #
 1901:     my $textualoverride=shift;
 1902:     my $output='';
 1903:     if ($env{'environment.remote'} eq 'on') {
 1904:        $output.=
 1905:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
 1906: "\nwindow.status='Configuring Remote Control ';";
 1907:     } else {
 1908:         unless ($textualoverride) { return ''; }
 1909:     }
 1910:     my $uname=$env{'user.name'};
 1911:     my $udom=$env{'user.domain'};
 1912:     my $adv=$env{'user.adv'};
 1913:     my $show_course=&Apache::loncommon::show_course();
 1914:     my $author=$env{'user.author'};
 1915:     my $crs='';
 1916:     my $crstype='';
 1917:     if ($env{'request.course.id'}) {
 1918:        $crs='/'.$env{'request.course.id'};
 1919:        if ($env{'request.course.sec'}) {
 1920: 	   $crs.='_'.$env{'request.course.sec'};
 1921:        }
 1922:        $crs=~s/\_/\//g;
 1923:        $crstype = &Apache::loncommon::course_type();
 1924:     }
 1925:     my $pub=($env{'request.state'} eq 'published');
 1926:     my $con=($env{'request.state'} eq 'construct');
 1927:     my $rol=$env{'request.role'};
 1928:     my $requested_domain;
 1929:     if ($rol) {
 1930:        $requested_domain = $env{'request.role.domain'};
 1931:     }
 1932:     foreach my $line (@desklines) {
 1933:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
 1934:         $prt=~s/\$uname/$uname/g;
 1935:         $prt=~s/\$udom/$udom/g;
 1936:         if ($prt =~ /\$crs/) {
 1937:             next unless ($env{'request.course.id'});
 1938:             next if ($crstype eq 'Community');
 1939:             $prt=~s/\$crs/$crs/g;
 1940:         } elsif ($prt =~ /\$cmty/) {
 1941:             next unless ($env{'request.course.id'});
 1942:             next if ($crstype ne 'Community');
 1943:             $prt=~s/\$cmty/$crs/g;
 1944:         }
 1945:         if ($prt =~ m/\$requested_domain/) {
 1946:             if ((!$requested_domain) && ($pro eq 'pbre') && ($env{'user.adv'})) {
 1947:                 $prt=~s/\$requested_domain/$env{'user.domain'}/g;
 1948:             } else {
 1949:                 $prt=~s/\$requested_domain/$requested_domain/g;
 1950:             }
 1951:         }
 1952:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
 1953:         if ($pro eq 'clear') {
 1954: 	    $output.=&clear($row,$col);
 1955:         } elsif ($pro eq 'any') {
 1956:                $output.=&secondlevel(
 1957: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1958: 	} elsif ($pro eq 'smp') {
 1959:             unless ($adv) {
 1960:                $output.=&secondlevel(
 1961:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1962:             }
 1963:         } elsif ($pro eq 'adv') {
 1964:             if ($adv) {
 1965:                $output.=&secondlevel(
 1966: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1967:             }
 1968: 	} elsif ($pro eq 'shc') {
 1969:             if ($show_course) {
 1970:                $output.=&secondlevel(
 1971:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1972:             }
 1973:         } elsif ($pro eq 'nsc') {
 1974:             if (!$show_course) {
 1975:                $output.=&secondlevel(
 1976: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1977:             }
 1978:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
 1979:             my $priv = $1;
 1980:             if ($priv =~ /^mdc(Course|Community)/) {
 1981:                 if ($crstype eq $1) {
 1982:                     $priv = 'mdc';
 1983:                 } else {
 1984:                     next;
 1985:                 }
 1986:             }
 1987:             if ((($priv eq 'bre') && (&Apache::lonnet::allowed($priv,$prt) eq 'F')) ||
 1988:                 (($priv ne 'bre') && (&Apache::lonnet::allowed($priv,$prt)))) {
 1989:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1990:             }
 1991:         } elsif ($pro eq 'course')  {
 1992:             if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
 1993:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1994: 	    }
 1995:         } elsif ($pro eq 'community')  {
 1996:             if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
 1997:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1998:             }
 1999:         } elsif ($pro =~ /^courseenv_(.*)$/) {
 2000:             my $key = $1;
 2001:             if ($crstype ne 'Community') {
 2002:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
 2003:                 if ($key eq 'canuse_pdfforms') {
 2004:                     if ($env{'request.course.id'} && $coursepref eq '') {
 2005:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
 2006:                         $coursepref = $domdefs{'canuse_pdfforms'};
 2007:                     }
 2008:                 }
 2009:                 if ($coursepref) { 
 2010:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 2011:                 }
 2012:             }
 2013:         } elsif ($pro =~ /^communityenv_(.*)$/) {
 2014:             my $key = $1;
 2015:             if ($crstype eq 'Community') {
 2016:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
 2017:                 if ($key eq 'canuse_pdfforms') {
 2018:                     if ($env{'request.course.id'} && $coursepref eq '') {
 2019:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
 2020:                         $coursepref = $domdefs{'canuse_pdfforms'};
 2021:                     }
 2022:                 }
 2023:                 if ($coursepref) { 
 2024:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 2025:                 }
 2026:             }
 2027:         } elsif ($pro =~ /^course_(.*)$/) {
 2028:             # Check for permissions inside of a course
 2029:             if (($env{'request.course.id'}) && ($crstype ne 'Community') && 
 2030:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 2031:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 2032:                  )) {
 2033:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 2034: 	    }
 2035:         } elsif ($pro =~ /^community_(.*)$/) {
 2036:             # Check for permissions inside of a community
 2037:             if (($env{'request.course.id'}) && ($crstype eq 'Community') &&   
 2038:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 2039:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 2040:                  )) {
 2041:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 2042:             }
 2043:         } elsif ($pro eq 'author') {
 2044:             if ($author) {
 2045:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
 2046:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
 2047:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
 2048:                     # Check that we are on the correct machine
 2049:                     my $cadom=$requested_domain;
 2050:                     my $caname=$env{'user.name'};
 2051:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
 2052: 		       ($cadom,$caname)=
 2053:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
 2054:                     }                       
 2055:                     $act =~ s/\$caname/$caname/g;
 2056:                     $act =~ s/\$cadom/$cadom/g;
 2057:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
 2058: 		    my $allowed=0;
 2059: 		    my @ids=&Apache::lonnet::current_machine_ids();
 2060: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 2061: 		    if ($allowed) {
 2062:                         $output.=&switch($caname,$cadom,
 2063:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
 2064:                     }
 2065:                 }
 2066:             }
 2067:         } elsif ($pro eq 'tools') {
 2068:             my @tools = ('aboutme','blog','portfolio');
 2069:             if (grep(/^\Q$prt\E$/,@tools)) {
 2070:                 if (!&Apache::lonnet::usertools_access($env{'user.name'},
 2071:                                                        $env{'user.domain'},
 2072:                                                        $prt,undef,'tools')) {
 2073:                     $output.=&clear($row,$col);
 2074:                     next;
 2075:                 }
 2076:             } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
 2077:                 if (($prt eq 'reqcrsnsc') && ($show_course))   {
 2078:                     next;
 2079:                 }
 2080:                 if (($prt eq 'reqcrsshc') && (!$show_course)) {
 2081:                     next;
 2082:                 }
 2083:                 my $showreqcrs = &check_for_rcrs();
 2084:                 if (!$showreqcrs) {
 2085:                     $output.=&clear($row,$col);
 2086:                     next;
 2087:                 }
 2088:             }
 2089:             $prt='any';
 2090:             $output.=&secondlevel(
 2091:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 2092:         }
 2093:     }
 2094:     if ($env{'environment.remote'} eq 'on') {
 2095:         $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
 2096:         if (&Apache::lonmsg::newmail()) {
 2097:             $output.='swmenu.setstatus("you have","messages");';
 2098:         }
 2099:     }
 2100:     return $output;
 2101: }
 2102: 
 2103: sub check_for_rcrs {
 2104:     my $showreqcrs = 0;
 2105:     my @reqtypes = ('official','unofficial','community','textbook');
 2106:     foreach my $type (@reqtypes) {
 2107:         if (&Apache::lonnet::usertools_access($env{'user.name'},
 2108:                                               $env{'user.domain'},
 2109:                                               $type,undef,'requestcourses')) {
 2110:             $showreqcrs = 1;
 2111:             last;
 2112:         }
 2113:     }
 2114:     if (!$showreqcrs) {
 2115:         foreach my $type (@reqtypes) {
 2116:             if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
 2117:                 $showreqcrs = 1;
 2118:                 last;
 2119:             }
 2120:         }
 2121:     }
 2122:     return $showreqcrs;
 2123: }
 2124: 
 2125: # ======================================================================= Close
 2126: 
 2127: sub close {
 2128:     unless ($env{'environment.remote'} eq 'on') { return ''; }
 2129:     my $menuname = &get_menu_name();
 2130:     return(<<ENDCLOSE);
 2131: <script type="text/javascript">
 2132: // <![CDATA[
 2133: window.status='Accessing Remote Control';
 2134: menu=window.open("/adm/rat/empty.html","$menuname",
 2135:                  "height=350,width=150,scrollbars=no,menubar=no");
 2136: window.status='Disabling Remote Control';
 2137: menu.active=0;
 2138: menu.autologout=0;
 2139: window.status='Closing Remote Control';
 2140: menu.close();
 2141: window.status='Done.';
 2142: // ]]>
 2143: </script>
 2144: ENDCLOSE
 2145: }
 2146: 
 2147: sub dc_popup_js {
 2148:     my %lt = &Apache::lonlocal::texthash(
 2149:                                           more => '(More ...)',
 2150:                                           less => '(Less ...)',
 2151:                                         );
 2152:     return <<"END";
 2153: 
 2154: function showCourseID() {
 2155:     document.getElementById('dccid').style.display='block';
 2156:     document.getElementById('dccid').style.textAlign='left';
 2157:     document.getElementById('dccid').style.textFace='normal';
 2158:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
 2159:     return;
 2160: }
 2161: 
 2162: function hideCourseID() {
 2163:     document.getElementById('dccid').style.display='none';
 2164:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
 2165:     return;
 2166: }
 2167: 
 2168: END
 2169: 
 2170: }
 2171: 
 2172: sub countdown_toggle_js {
 2173:     return <<"END";
 2174: 
 2175: function toggleCountdown() {
 2176:     var countdownid = document.getElementById('duedatecountdown');
 2177:     var currstyle = countdownid.style.display;
 2178:     if (currstyle == 'inline') {
 2179:         countdownid.style.display = 'none';
 2180:         document.getElementById('ddcountcollapse').innerHTML='';
 2181:         document.getElementById('ddcountexpand').innerHTML='&#9668;&nbsp;';
 2182:     } else {
 2183:         countdownid.style.display = 'inline';
 2184:         document.getElementById('ddcountcollapse').innerHTML='&#9658;&nbsp;';
 2185:         document.getElementById('ddcountexpand').innerHTML='';
 2186:     }
 2187:     return;
 2188: }
 2189: 
 2190: END
 2191: }
 2192: 
 2193: # This creates a "done button" for timed events.  The confirmation box is a jQuery
 2194: # dialog widget. If the interval parameter requires a proctor key for the timed
 2195: # event to be marked done, there will also be a textbox where that can be entered.
 2196: # Clicking OK will set the value of LC_interval_done to 'true', and, if needed will
 2197: # set the value of LC_interval_done_proctorpass to the text entered in that box,
 2198: # and submit the corresponding form.
 2199: #
 2200: # The &zero_time() routine in lonhomework.pm is called when a page is rendered if
 2201: # LC_interval_done is true.
 2202: #
 2203: sub done_button_js {
 2204:     my ($type,$width,$height,$proctor,$donebuttontext) = @_;
 2205:     return unless (($type eq 'map') || ($type eq 'resource'));
 2206:     my %lt = &Apache::lonlocal::texthash(
 2207:                  title    => 'WARNING!',
 2208:                  preamble => 'You are trying to end this timed event early.',
 2209:                  map      => 'Confirming that you are done will cause the time to expire and prevent you from changing any answers in the current folder.',
 2210:                  resource => 'Confirming that you are done will cause the time to expire for this question, and prevent you from changing your answer(s).',
 2211:                  okdone   => 'Click "OK" if you are completely finished.',
 2212:                  cancel   => 'Click "Cancel" to continue working.',
 2213:                  proctor  => 'Ask a proctor to enter the key, then click "OK" if you are completely finished.',
 2214:                  ok       => 'OK',
 2215:                  exit     => 'Cancel',
 2216:                  key      => 'Key:',
 2217:                  nokey    => 'A proctor key is required',
 2218:     );
 2219:     my $navmap = Apache::lonnavmaps::navmap->new();
 2220:     my ($missing,$tried) = (0,0);
 2221:     if (ref($navmap)) {
 2222:         my @resources=();
 2223:         if ($type eq 'map') {
 2224:             my ($mapurl,$rid,$resurl)=&Apache::lonnet::decode_symb($env{'request.symb'});
 2225:             if ($env{'request.symb'} =~ /\.page$/) {
 2226:                 @resources=$navmap->retrieveResources($resurl,sub { $_[0]->is_problem() });
 2227:             } else {
 2228:                 @resources=$navmap->retrieveResources($mapurl,sub { $_[0]->is_problem() });
 2229:             }
 2230:         } else {
 2231:             my $res = $navmap->getBySymb($env{'request.symb'});
 2232:             if (ref($res)) {
 2233:                 if ($res->is_problem()) {
 2234:                     push(@resources,$res);
 2235:                 }
 2236:             }
 2237:         }
 2238:         foreach my $res (@resources) {
 2239:             if (ref($res->parts()) eq 'ARRAY') {
 2240:                 foreach my $part (@{$res->parts()}) {
 2241:                     if (!$res->tries($part)) {
 2242:                         $missing++;
 2243:                     } else {
 2244:                         $tried++;
 2245:                     }
 2246:                 }
 2247:             }
 2248:         }
 2249:     }
 2250:     if ($missing) {
 2251:         $lt{'miss'} .= '<p class="LC_error">';
 2252:         if ($type eq 'map') {
 2253:             $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,question part,question parts] in this folder.',$missing);
 2254:         } else {
 2255:             $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,part] in this question.',$missing);
 2256:         }
 2257:         if ($missing > 1) {
 2258:             $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit answers for them.').'</span>';
 2259:         } else {
 2260:             $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit an answer for it.').'</p>';
 2261:         }
 2262:     }
 2263:     $donebuttontext = &HTML::Entities::encode($donebuttontext,'<>&"');
 2264:     if ($proctor) {
 2265:         if ($height !~ /^\d+$/) {
 2266:             $height = 400;
 2267:             if ($missing) {
 2268:                 $height += 60;
 2269:             }
 2270:         }
 2271:         if ($width !~ /^\d+$/) {
 2272:             $width = 400;
 2273:             if ($missing) {
 2274:                 $width += 60;
 2275:             }
 2276:         }
 2277:         return <<END;
 2278: <form method="post" name="LCdoneButton" action="">
 2279:     <input type="hidden" name="LC_interval_done" value="" />
 2280:     <input type="hidden" name="LC_interval_done_proctorpass" value="" />
 2281:     <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
 2282: </form>
 2283: 
 2284: <div id="LC_done-confirm" title="$lt{'title'}">
 2285:   <p>$lt{'preamble'} $lt{$type}</p>
 2286:   $lt{'miss'}
 2287:   <p>$lt{'proctor'}</p>
 2288:   <form name="LCdoneButtonProctor" action="">
 2289:     <label>$lt{'key'}<input type="password" name="LC_interval_done_proctorkey" value="" /></label>
 2290:     <input type="submit" tabindex="-1" style="position:absolute; top:-1000px" />
 2291:   </form>
 2292:   <p>$lt{'cancel'}</p>
 2293: </div>
 2294: 
 2295: <script type="text/javascript">
 2296: // <![CDATA[
 2297:     \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
 2298:     \$( "#LC_done-confirm-opener" ).on("click", function() {
 2299:         \$( "#LC_done-confirm" ).dialog("open");
 2300:         \$( "#LC_done-confirm" ).dialog({
 2301:             height: $height,
 2302:             width: $width,
 2303:             modal: true,
 2304:             resizable: false,
 2305:             buttons: [
 2306:                 {
 2307:                     text: "$lt{'ok'}",
 2308:                     click: function() {
 2309:                         var proctorkey = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
 2310:                         if ((proctorkey == '') || (proctorkey == null)) {
 2311:                             alert("$lt{'nokey'}");
 2312:                         } else {
 2313:                             \$( '[name="LC_interval_done"]' )[0].value = 'true';
 2314:                             \$( '[name="LC_interval_done_proctorpass"]' )[0].value = proctorkey;
 2315:                             \$( '[name="LCdoneButton"]' )[0].submit();
 2316:                         }
 2317:                     },
 2318:                 },
 2319:                 {
 2320:                     text: "$lt{'exit'}",
 2321:                     click: function() {
 2322:                         \$("#LC_done-confirm").dialog( "close" );
 2323:                     }
 2324:                 }
 2325:             ],
 2326:             close: function() {
 2327:                 \$( '[name="LC_interval_done_proctorkey"]' )[0].value = '';
 2328:             }
 2329:         });
 2330:         \$( "#LC_done-confirm" ).find( "form" ).on( "submit", function( event ) {
 2331:             event.preventDefault();
 2332:             \$( '[name="LC_interval_done"]' )[0].value = 'true';
 2333:             \$( '[name="LC_interval_done_proctorpass"]' )[0].value = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
 2334:             \$( '[name="LCdoneButton"]' )[0].submit();
 2335:         });
 2336: });
 2337: 
 2338: // ]]>
 2339: </script>
 2340: 
 2341: END
 2342:     } else {
 2343:         if ($height !~ /^\d+$/) {
 2344:             $height = 320;
 2345:             if ($missing) {
 2346:                 $height += 60;
 2347:             }
 2348:         }
 2349:         if ($width !~ /^\d+$/) {
 2350:             $width = 320;
 2351:             if ($missing) {
 2352:                 $width += 60;
 2353:             }
 2354:         }
 2355:         if ($missing) {
 2356:             $lt{'miss'} = '</p>'.$lt{'miss'}.'<p>';
 2357:         }
 2358:         return <<END;
 2359: 
 2360: <form method="post" name="LCdoneButton" action="">
 2361:     <input type="hidden" name="LC_interval_done" value="" />
 2362:     <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
 2363: </form>
 2364: 
 2365: <div id="LC_done-confirm" title="$lt{'title'}">
 2366:     <p>$lt{'preamble'} $lt{$type} $lt{'miss'} $lt{'okdone'} $lt{'cancel'}</p>
 2367: </div>
 2368: 
 2369: <script type="text/javascript">
 2370: // <![CDATA[
 2371: \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
 2372: \$( "#LC_done-confirm-opener" ).click(function() {
 2373:     \$( "#LC_done-confirm" ).dialog( "open" );
 2374:     \$( "#LC_done-confirm" ).dialog({
 2375:       resizable: false,
 2376:       height: $height,
 2377:       width: $width,
 2378:       modal: true,
 2379:       buttons: [
 2380:                  {
 2381:                     text: "$lt{'ok'}",
 2382:                     click: function() {
 2383:                         \$( this ).dialog( "close" );
 2384:                         \$( '[name="LC_interval_done"]' )[0].value = 'true';
 2385:                         \$( '[name="LCdoneButton"]' )[0].submit();
 2386:                     },
 2387:                  },
 2388:                  {
 2389:                      text: "$lt{'exit'}",
 2390:                      click: function() {
 2391:                          \$( this ).dialog( "close" );
 2392:                      },
 2393:                   },
 2394:                ],
 2395:        });
 2396: });
 2397: // ]]>
 2398: </script>
 2399: 
 2400: END
 2401:     }
 2402: }
 2403: 
 2404: sub utilityfunctions {
 2405:     my ($httphost) = @_;
 2406:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
 2407:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
 2408:     if ($currenturl =~ m{^/adm/wrapper/ext/}) {
 2409:         if ($env{'request.external.querystring'}) {
 2410:             $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
 2411:         }
 2412:         my ($anchor) = ($env{'request.symb'} =~ /(\#[^\#]+)$/);
 2413:         if (($anchor) && ($currenturl !~ /\Q$anchor\E$/)) {
 2414:             $currenturl .= $1;
 2415:         }
 2416:     }
 2417:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
 2418:     
 2419:     my $dc_popup_cid;
 2420:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
 2421:                         $env{'course.'.$env{'request.course.id'}.
 2422:                                  '.domain'}.'/'})) {
 2423:         $dc_popup_cid = &dc_popup_js();
 2424:     }
 2425: 
 2426:     my $start_page_annotate = 
 2427:         &Apache::loncommon::start_page('Annotator',undef,
 2428: 				       {'only_body' => 1,
 2429: 					'js_ready'  => 1,
 2430: 					'bgcolor'   => '#BBBBBB',
 2431: 					'add_entries' => {
 2432: 					    'onload' => 'javascript:document.goannotate.submit();'}});
 2433: 
 2434:     my $end_page_annotate = 
 2435:         &Apache::loncommon::end_page({'js_ready' => 1});
 2436: 
 2437:     my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
 2438: 
 2439:     my $esc_url=&escape($currenturl);
 2440:     my $esc_symb=&escape($currentsymb);
 2441: 
 2442:     my $countdown = &countdown_toggle_js();
 2443: 
 2444:     my $annotateurl = '/adm/annotation';
 2445:     if ($httphost) {
 2446:         $annotateurl = '/adm/annotations';
 2447:     }
 2448:     my $hostvar = '
 2449: function setLCHost() {
 2450:     var lcHostname="";
 2451: ';
 2452:     if ($httphost =~ m{^https?\://}) {
 2453:         $hostvar .= '    var lcServer="'.$httphost.'";'."\n".
 2454:                     '    var hostReg = /^https?:\/\/([^\/]+)$/i;'."\n".
 2455:                     '    var match = hostReg.exec(lcServer);'."\n".
 2456:                     '    if (match.length) {'."\n".
 2457:                     '        if (match[1] == location.hostname) {'."\n".
 2458:                     '            lcHostname=lcServer;'."\n".
 2459:                     '        }'."\n".
 2460:                     '    }'."\n";
 2461:     }
 2462: 
 2463:     $hostvar .= '    return lcHostname;'."\n".
 2464: '}'."\n";
 2465: 
 2466: return (<<ENDUTILITY)
 2467:     $hostvar
 2468:     var currentURL=unescape("$esc_url");
 2469:     var reloadURL=unescape("$esc_url");
 2470:     var currentSymb=unescape("$esc_symb");
 2471: 
 2472: $dc_popup_cid
 2473: 
 2474: $jumptores
 2475: 
 2476: function gopost(url,postdata) {
 2477:    if (url!='') {
 2478:       var lcHostname = setLCHost();
 2479:       this.document.server.action=lcHostname+url;
 2480:       this.document.server.postdata.value=postdata;
 2481:       this.document.server.command.value='';
 2482:       this.document.server.url.value='';
 2483:       this.document.server.symb.value='';
 2484:       this.document.server.submit();
 2485:    }
 2486: }
 2487: 
 2488: function gocmd(url,cmd) {
 2489:    if (url!='') {
 2490:       var lcHostname = setLCHost();
 2491:       this.document.server.action=lcHostname+url;
 2492:       this.document.server.postdata.value='';
 2493:       this.document.server.command.value=cmd;
 2494:       this.document.server.url.value=currentURL;
 2495:       this.document.server.symb.value=currentSymb;
 2496:       this.document.server.submit();
 2497:    }
 2498: }
 2499: 
 2500: function gocstr(url,filename) {
 2501:     if (url == '/adm/cfile?action=delete') {
 2502:         this.document.cstrdelete.filename.value = filename
 2503:         this.document.cstrdelete.submit();
 2504:         return;
 2505:     }
 2506:     if (url == '/adm/printout') {
 2507:         this.document.cstrprint.postdata.value = filename
 2508:         this.document.cstrprint.curseed.value = 0;
 2509:         this.document.cstrprint.problemtype.value = 0;
 2510:         if (this.document.lonhomework) {
 2511:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
 2512:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
 2513:             }
 2514:             if (this.document.lonhomework.problemtype) {
 2515: 		if (this.document.lonhomework.problemtype.value) {
 2516: 		    this.document.cstrprint.problemtype.value = 
 2517: 			this.document.lonhomework.problemtype.value;
 2518: 		} else if (this.document.lonhomework.problemtype.options) {
 2519: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
 2520: 			if (this.document.lonhomework.problemtype.options[i].selected) {
 2521: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
 2522: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
 2523: 				}
 2524: 			}
 2525: 		    }
 2526: 		}
 2527: 	    }
 2528: 	}
 2529:         this.document.cstrprint.submit();
 2530:         return;
 2531:     }
 2532:     if (url !='') {
 2533:         this.document.constspace.filename.value = filename;
 2534:         this.document.constspace.action = url;
 2535:         this.document.constspace.submit();
 2536:     }
 2537: }
 2538: 
 2539: function golist(url) {
 2540:    if (url!='' && url!= null) {
 2541:        currentURL = null;
 2542:        currentSymb= null;
 2543:        var lcHostname = setLCHost();
 2544:        top.location.href=lcHostname+url;
 2545:    }
 2546: }
 2547: 
 2548: 
 2549: 
 2550: function catalog_info(isMobile) {
 2551:     if (isMobile == 1) {
 2552:         openMyModal(window.location.pathname+'.meta?modal=1',500,400,'yes');
 2553:     } else {
 2554:         loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
 2555:     }
 2556: }
 2557: 
 2558: function chat_win() {
 2559:    var lcHostname = setLCHost();
 2560:    lonchat=window.open(lcHostname+'/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
 2561: }
 2562: 
 2563: function group_chat(group) {
 2564:    var lcHostname = setLCHost();
 2565:    var url = lcHostname+'/adm/groupchat?group='+group;
 2566:    var winName = 'LONchat_'+group;
 2567:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 2568: }
 2569: 
 2570: function annotate() {
 2571:    w_Annotator_flag=1;
 2572:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
 2573:    annotator.document.write(
 2574:    '$start_page_annotate'
 2575:   +"<form name='goannotate' target='Annotator' method='post' "
 2576:   +"action='$annotateurl'>"
 2577:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
 2578:   +"<\\/form>"
 2579:   +'$end_page_annotate');
 2580:    annotator.document.close();
 2581: }
 2582: 
 2583: function open_StoredLinks_Import(rat) {
 2584:    var newWin;
 2585:    var lcHostname = setLCHost();
 2586:    if (rat) {
 2587:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
 2588:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
 2589:    }
 2590:    else {
 2591:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import',
 2592:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
 2593:    }
 2594:    newWin.focus();
 2595: }
 2596: 
 2597: function open_source() {
 2598:    sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename='+currentURL,'LONsource',
 2599:                          'height=500,width=600,resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=yes');
 2600: }
 2601: 
 2602: (function (\$) {
 2603:   \$(document).ready(function () {
 2604:     \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
 2605:     /*\@cc_on
 2606:       if (!window.XMLHttpRequest) {
 2607:         \$('.LC_hoverable').each(function () {
 2608:           this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
 2609:           this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
 2610:         });
 2611:       }
 2612:     \@*/
 2613:   });
 2614: }(jQuery));
 2615: 
 2616: $countdown
 2617: 
 2618: ENDUTILITY
 2619: }
 2620: 
 2621: sub serverform {
 2622:     return(<<ENDSERVERFORM);
 2623: <form name="server" action="/adm/logout" method="post" target="_top">
 2624: <input type="hidden" name="postdata" value="none" />
 2625: <input type="hidden" name="command" value="none" />
 2626: <input type="hidden" name="url" value="none" />
 2627: <input type="hidden" name="symb" value="none" />
 2628: </form>
 2629: ENDSERVERFORM
 2630: }
 2631: 
 2632: sub constspaceform {
 2633:     return(<<ENDCONSTSPACEFORM);
 2634: <form name="constspace" action="/adm/logout" method="post" target="_top">
 2635: <input type="hidden" name="filename" value="" />
 2636: </form>
 2637: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
 2638: <input type="hidden" name="action" value="delete" /> 
 2639: <input type="hidden" name="filename" value="" />
 2640: </form>
 2641: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
 2642: <input type="hidden" name="postdata" value="" />
 2643: <input type="hidden" name="curseed" value="" />
 2644: <input type="hidden" name="problemtype" value="" />
 2645: </form>
 2646: 
 2647: ENDCONSTSPACEFORM
 2648: }
 2649: 
 2650: sub get_nav_status {
 2651:     my $navstatus="swmenu.w_loncapanav_flag=";
 2652:     if ($env{'environment.remotenavmap'} eq 'on') {
 2653:         $navstatus.="1";
 2654:     } else {
 2655:         $navstatus.="-1";
 2656:     }
 2657:     return $navstatus;
 2658: }
 2659: 
 2660: sub hidden_button_check {
 2661:     if ( $env{'request.course.id'} eq ''
 2662:          || $env{'request.role.adv'} ) {
 2663: 
 2664:         return;
 2665:     }
 2666:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
 2667:     return $buttonshide; 
 2668: }
 2669: 
 2670: sub roles_selector {
 2671:     my ($cdom,$cnum,$httphost) = @_;
 2672:     my $crstype = &Apache::loncommon::course_type();
 2673:     my $now = time;
 2674:     my (%courseroles,%seccount,%courseprivs,%roledesc);
 2675:     my $is_cc;
 2676:     my ($js,$form,$switcher);
 2677:     my $ccrole;
 2678:     if ($crstype eq 'Community') {
 2679:         $ccrole = 'co';
 2680:     } else {
 2681:         $ccrole = 'cc';
 2682:     }
 2683:     my ($privref,$gotsymb,$destsymb);
 2684:     my $destinationurl = $ENV{'REQUEST_URI'};
 2685:     if ($destinationurl =~ /(\?|\&)symb=/) {
 2686:         $gotsymb = 1;
 2687:     } elsif ($destinationurl =~ m{^/enc/}) {
 2688:         my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
 2689:         if ($plainurl =~ /(\?|\&)symb=/) {
 2690:             $gotsymb = 1;
 2691:         }
 2692:     }
 2693:     unless ($gotsymb) {
 2694:         $destsymb = &Apache::lonnet::symbread();
 2695:         if ($destsymb ne '') {
 2696:             $destsymb = &Apache::lonenc::check_encrypt($destsymb);
 2697:         }
 2698:     }
 2699:     my $reqprivs = &required_privs();
 2700:     if (ref($reqprivs) eq 'HASH') {
 2701:         my $destination = $destinationurl;
 2702:         $destination =~ s/(\?.*)$//;
 2703:         if (exists($reqprivs->{$destination})) {
 2704:             if ($reqprivs->{$destination} =~ /,/) {
 2705:                 @{$privref} = split(/,/,$reqprivs->{$destination});
 2706:             } else {
 2707:                 $privref = [$reqprivs->{$destination}];
 2708:             }
 2709:         }
 2710:     }
 2711:     if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
 2712:         my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
 2713:         if ((($start) && ($start<0)) || 
 2714:             (($end) && ($end<$now))  ||
 2715:             (($start) && ($now<$start))) {
 2716:             $is_cc = 0;
 2717:         } else {
 2718:             $is_cc = 1;
 2719:         }
 2720:     }
 2721:     if ($is_cc) {
 2722:         &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs);
 2723:     } elsif ($env{'request.role'} =~ m{^\Qcr/$cdom/$cdom-domainconfig/\E(\w+)\.\Q/$cdom/$cnum\E}) {
 2724:         &get_customadhoc_roles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,\%roledesc,$privref);
 2725:     } else {
 2726:         my %gotnosection;
 2727:         foreach my $item (keys(%env)) {
 2728:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
 2729:                 my $role = $1;
 2730:                 my $sec = $2;
 2731:                 next if ($role eq 'gr');
 2732:                 my ($start,$end) = split(/\./,$env{$item});
 2733:                 next if (($start && $start > $now) || ($end && $end < $now));
 2734:                 if ($sec eq '') {
 2735:                     if (!$gotnosection{$role}) {
 2736:                         $seccount{$role} ++;
 2737:                         $gotnosection{$role} = 1;
 2738:                     }
 2739:                 }
 2740:                 if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
 2741:                     my $cnumsec = $cnum;
 2742:                     if ($sec ne '') {
 2743:                         $cnumsec .= "/$sec";
 2744:                     }
 2745:                     $courseprivs{"$role./$cdom/$cnumsec./"} =
 2746:                         $env{"user.priv.$role./$cdom/$cnumsec./"};
 2747:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
 2748:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
 2749:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
 2750:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
 2751:                 }
 2752:                 if (ref($courseroles{$role}) eq 'ARRAY') {
 2753:                     if ($sec ne '') {
 2754:                         if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
 2755:                             push(@{$courseroles{$role}},$sec);
 2756:                             $seccount{$role} ++;
 2757:                         }
 2758:                     }
 2759:                 } else {
 2760:                     @{$courseroles{$role}} = ();
 2761:                     if ($sec ne '') {
 2762:                         $seccount{$role} ++;
 2763:                         push(@{$courseroles{$role}},$sec);
 2764:                     }
 2765:                 }
 2766:             }
 2767:         }
 2768:     }
 2769:     my @roles_order = ($ccrole,'in','ta','ep','ad','st');
 2770:     my $numdiffsec;
 2771:     if (keys(%seccount) == 1) {
 2772:         foreach my $key (keys(%seccount)) {
 2773:             $numdiffsec = $seccount{$key};
 2774:         }
 2775:     }
 2776:     if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
 2777:         my @submenu;
 2778:         $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,\%roledesc,$privref);
 2779:         $form = 
 2780:             '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles">'."\n".
 2781:             '  <input type="hidden" name="destinationurl" value="'.
 2782:             &HTML::Entities::encode($destinationurl).'" />'."\n".
 2783:             '  <input type="hidden" name="gotorole" value="1" />'."\n".
 2784:             '  <input type="hidden" name="selectrole" value="" />'."\n".
 2785:             '  <input type="hidden" name="switchrole" value="" />'."\n";
 2786:         if ($destsymb ne '') {
 2787:             $form .= '   <input type="hidden" name="destsymb" value="'.
 2788:                          &HTML::Entities::encode($destsymb).'" />'."\n";
 2789:         }
 2790:         $form .= '</form>'."\n";
 2791:         foreach my $role (@roles_order) {
 2792:             my $include;
 2793:             if (defined($courseroles{$role})) {
 2794:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
 2795:                     if ($seccount{$role} > 1) {
 2796:                         $include = 1;
 2797:                     }
 2798:                 } else {
 2799:                     $include = 1;
 2800:                 }
 2801:             }
 2802:             if ($include) {
 2803:                 push(@submenu,['javascript:adhocRole('."'$role'".')',
 2804:                                &Apache::lonnet::plaintext($role,$crstype)]);
 2805:             }
 2806:         }
 2807:         foreach my $role (sort(keys(%courseroles))) {
 2808:             if ($role =~ /^cr/) {
 2809:                 my $include;
 2810:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
 2811:                     if ($seccount{$role} > 1) {
 2812:                         $include = 1;
 2813:                     }
 2814:                 } else {
 2815:                     $include = 1;
 2816:                 }
 2817:                 if ($include) {
 2818:                     my $rolename;
 2819:                     if ($role =~ m{^cr/$cdom/$cdom\-domainconfig/(\w+)(?:/\w+|$)}) {
 2820:                         $rolename = $roledesc{$role};
 2821:                         if ($rolename eq '') {
 2822:                             $rolename = &mt('Helpdesk [_1]',$1);
 2823:                         }
 2824:                     } else {
 2825:                         $rolename = &Apache::lonnet::plaintext($role);
 2826:                     }
 2827:                     push(@submenu,['javascript:adhocRole('."'$role'".')',
 2828:                                    $rolename]);
 2829:                 }
 2830:             }
 2831:         }
 2832:         if (@submenu > 0) {
 2833:             $switcher = &create_submenu('','',&mt('Switch role'),\@submenu);
 2834:         }
 2835:     }
 2836:     return ($js,$form,$switcher);
 2837: }
 2838: 
 2839: sub get_all_courseroles {
 2840:     my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
 2841:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
 2842:             (ref($courseprivs) eq 'HASH')) {
 2843:         return;
 2844:     }
 2845:     my ($result,$cached) = 
 2846:         &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
 2847:     if (defined($cached)) {
 2848:         if (ref($result) eq 'HASH') {
 2849:             if ((ref($result->{'roles'}) eq 'HASH') && 
 2850:                 (ref($result->{'seccount'}) eq 'HASH') && 
 2851:                 (ref($result->{'privs'}) eq 'HASH')) {
 2852:                 %{$courseroles} = %{$result->{'roles'}};
 2853:                 %{$seccount} = %{$result->{'seccount'}};
 2854:                 %{$courseprivs} = %{$result->{'privs'}};
 2855:                 return;
 2856:             }
 2857:         }
 2858:     }
 2859:     my %gotnosection;
 2860:     my %adv_roles =
 2861:          &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
 2862:     foreach my $role (keys(%adv_roles)) {
 2863:         my ($urole,$usec) = split(/:/,$role);
 2864:         if (!$gotnosection{$urole}) {
 2865:             $seccount->{$urole} ++;
 2866:             $gotnosection{$urole} = 1;
 2867:         }
 2868:         if (ref($courseroles->{$urole}) eq 'ARRAY') {
 2869:             if ($usec ne '') {
 2870:                 if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
 2871:                     push(@{$courseroles->{$urole}},$usec);
 2872:                     $seccount->{$urole} ++;
 2873:                 }
 2874:             }
 2875:         } else {
 2876:             @{$courseroles->{$urole}} = ();
 2877:             if ($usec ne '') {
 2878:                 $seccount->{$urole} ++;
 2879:                 push(@{$courseroles->{$urole}},$usec);
 2880:             }
 2881:         }
 2882:         my $area = '/'.$cdom.'/'.$cnum;
 2883:         if ($usec ne '') {
 2884:             $area .= '/'.$usec;
 2885:         }
 2886:         if ($role =~ /^cr\//) {
 2887:             &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
 2888:         } else {
 2889:             &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
 2890:         }
 2891:     }
 2892:     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
 2893:     @{$courseroles->{'st'}} = ();
 2894:     &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
 2895:     if (keys(%sections_count) > 0) {
 2896:         push(@{$courseroles->{'st'}},keys(%sections_count));
 2897:         $seccount->{'st'} = scalar(keys(%sections_count));
 2898:     }
 2899:     $seccount->{'st'} ++; # Increment for a section-less student role.
 2900:     my $rolehash = {
 2901:                      'roles'    => $courseroles,
 2902:                      'seccount' => $seccount,
 2903:                      'privs'    => $courseprivs,
 2904:                    };
 2905:     &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
 2906:     return;
 2907: }
 2908: 
 2909: sub get_customadhoc_roles {
 2910:     my ($cdom,$cnum,$courseroles,$seccount,$courseprivs,$roledesc,$privref) = @_;
 2911:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
 2912:             (ref($courseprivs) eq 'HASH') && (ref($roledesc) eq 'HASH')) {
 2913:         return;
 2914:     }
 2915:     my $is_helpdesk = 0;
 2916:     my $now = time;
 2917:     foreach my $role ('dh','da') {
 2918:         if ($env{"user.role.$role./$cdom/"}) {
 2919:             my ($start,$end)=split(/\./,$env{"user.role.$role./$cdom/"});
 2920:             if (!($start && ($now<$start)) && !($end && ($now>$end))) {
 2921:                 $is_helpdesk = 1;
 2922:                 last;
 2923:             }
 2924:         }
 2925:     }
 2926:     if ($is_helpdesk) {
 2927:         my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum);
 2928:         my %available;
 2929:         if (ref($possroles) eq 'ARRAY') {
 2930:             map { $available{$_} = 1; } @{$possroles};
 2931:         }
 2932:         my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
 2933:         if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
 2934:             if (keys(%{$domdefaults{'adhocroles'}})) {
 2935:                 my $numsec = 1;
 2936:                 my @sections;
 2937:                 my ($allseclist,$cached) =
 2938:                     &Apache::lonnet::is_cached_new('courseseclist',$cdom.'_'.$cnum);
 2939:                 if (defined($cached)) {
 2940:                     if ($allseclist ne '') {
 2941:                         @sections = split(/,/,$allseclist);
 2942:                         $numsec += scalar(@sections);
 2943:                     }
 2944:                 } else {
 2945:                     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
 2946:                     @sections = sort(keys(%sections_count));
 2947:                     $numsec += scalar(@sections);
 2948:                     $allseclist = join(',',@sections);
 2949:                     &Apache::lonnet::do_cache_new('courseseclist',$cdom.'_'.$cnum,$allseclist);
 2950:                 }
 2951:                 my (%adhoc,$gotprivs);
 2952:                 my $prefix = "cr/$cdom/$cdom".'-domainconfig';
 2953:                 foreach my $role (keys(%{$domdefaults{'adhocroles'}})) {
 2954:                     next if (($role eq '') || ($role =~ /\W/));
 2955:                     $seccount->{"$prefix/$role"} = $numsec;
 2956:                     $roledesc->{"$prefix/$role"} = $description->{$role};  
 2957:                     if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
 2958:                         if (exists($env{"user.priv.$prefix/$role./$cdom/$cnum./"})) {
 2959:                             $courseprivs->{"$prefix/$role./$cdom/$cnum./"} =
 2960:                                 $env{"user.priv.$prefix/$role./$cdom/$cnum./"};
 2961:                             $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"} =
 2962:                                 $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/"};
 2963:                             $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"} =
 2964:                                 $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/$cnum"};
 2965:                         } else {
 2966:                             unless ($gotprivs) {
 2967:                                 my ($adhocroles,$privscached) =
 2968:                                     &Apache::lonnet::is_cached_new('adhocroles',$cdom);
 2969:                                 if ((defined($privscached)) && (ref($adhocroles) eq 'HASH')) {
 2970:                                     %adhoc = %{$adhocroles};
 2971:                                 } else {
 2972:                                     my $confname = &Apache::lonnet::get_domainconfiguser($cdom);
 2973:                                     my %roledefs = &Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
 2974:                                     foreach my $key (keys(%roledefs)) {
 2975:                                         (undef,my $rolename) = split(/_/,$key);
 2976:                                         if ($rolename ne '') {
 2977:                                             my ($systempriv,$domainpriv,$coursepriv) = split(/\_/,$roledefs{$key});
 2978:                                             $coursepriv = &Apache::lonnet::course_adhocrole_privs($rolename,$cdom,$cnum,$coursepriv);
 2979:                                             $adhoc{$rolename} = join('_',($systempriv,$domainpriv,$coursepriv));
 2980:                                         }
 2981:                                     }
 2982:                                     &Apache::lonnet::do_cache_new('adhocroles',$cdom,\%adhoc);
 2983:                                 }
 2984:                                 $gotprivs = 1;
 2985:                             }
 2986:                             ($courseprivs->{"$prefix/$role./$cdom/$cnum./"},
 2987:                              $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"},
 2988:                              $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"}) =
 2989:                                  split(/\_/,$adhoc{$role});
 2990:                         }
 2991:                     }
 2992:                     if ($available{$role}) {
 2993:                         $courseroles->{"$prefix/$role"} = \@sections;
 2994:                     }
 2995:                 }
 2996:             }
 2997:         }
 2998:     }
 2999:     return;
 3000: }
 3001: 
 3002: sub jump_to_role {
 3003:     my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$roledesc,$privref) = @_;
 3004:     my %lt = &Apache::lonlocal::texthash(
 3005:                 this => 'This role has section(s) associated with it.',
 3006:                 ente => 'Enter a specific section.',
 3007:                 orlb => 'Enter a specific section, or leave blank for no section.',
 3008:                 avai => 'Available sections are:',
 3009:                 youe => 'You entered an invalid section choice:',
 3010:                 plst => 'Please try again.',
 3011:                 role => 'The role you selected is not permitted to view the current page.',
 3012:                 swit => 'Switch role, but display Main Menu page instead?',
 3013:     );
 3014:     my $js;
 3015:     if (ref($courseroles) eq 'HASH') {
 3016:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
 3017:               '    var numsec = new Array();'."\n".
 3018:               '    var rolesections = new Array();'."\n".
 3019:               '    var rolenames = new Array();'."\n".
 3020:               '    var roleseclist = new Array();'."\n";
 3021:         my @items = keys(%{$courseroles});
 3022:         for (my $i=0; $i<@items; $i++) {
 3023:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
 3024:             my ($secs,$secstr);
 3025:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
 3026:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
 3027:                 $secs = join('","',@sections);
 3028:                 $secstr = join(', ',@sections);
 3029:             }
 3030:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
 3031:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
 3032:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
 3033:         }
 3034:     }
 3035:     my $checkroles = 0;
 3036:     if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0) && (ref($courseprivs) eq 'HASH')) {
 3037:         my %disallowed;
 3038:         foreach my $role (sort(keys(%{$courseprivs}))) {
 3039:             my $trole;
 3040:             if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
 3041:                 $trole = $1;
 3042:             }
 3043:             if (($trole ne '') && ($trole ne 'cm')) {
 3044:                 $disallowed{$trole} = 1;
 3045:                 foreach my $priv (@{$privref}) { 
 3046:                     if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
 3047:                         delete($disallowed{$trole});
 3048:                         last;
 3049:                     }
 3050:                 }
 3051:             }
 3052:         }
 3053:         if (keys(%disallowed) > 0) {
 3054:             $checkroles = 1;
 3055:             $js .= "    var disallow = new Array('".join("','",keys(%disallowed))."');\n".
 3056:                    "    var rolecheck = 1;\n";
 3057:         }
 3058:     }
 3059:     if (!$checkroles) {
 3060:         $js .=  "    var disallow = new Array();\n".
 3061:                 "    rolecheck = 0;\n";
 3062:     }
 3063:     return <<"END";
 3064: <script type="text/javascript">
 3065: //<![CDATA[
 3066: function adhocRole(newrole) {
 3067:     $js
 3068:     if (newrole == '') {
 3069:         return;
 3070:     } 
 3071:     var fullrole = newrole+'./$cdom/$cnum';
 3072:     var selidx = '';
 3073:     for (var i=0; i<rolenames.length; i++) {
 3074:         if (rolenames[i] == newrole) {
 3075:             selidx = i;
 3076:         }
 3077:     }
 3078:     if (rolecheck > 0) {
 3079:         for (var i=0; i<disallow.length; i++) {
 3080:             if (disallow[i] == newrole) {
 3081:                 if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
 3082:                     document.rolechooser.destinationurl.value = '/adm/menu';
 3083:                 } else {
 3084:                     return;
 3085:                 }
 3086:             }
 3087:         }
 3088:     }
 3089:     var secok = 1;
 3090:     var secchoice = '';
 3091:     if (selidx >= 0) {
 3092:         if (numsec[selidx] > 1) {
 3093:             secok = 0;
 3094:             var numrolesec = rolesections[selidx].length;
 3095:             var msgidx = numsec[selidx] - numrolesec;
 3096:             secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
 3097:             if (secchoice == '') {
 3098:                 if (msgidx > 0) {
 3099:                     secok = 1;
 3100:                 }
 3101:             } else {
 3102:                 for (var j=0; j<rolesections[selidx].length; j++) {
 3103:                     if (rolesections[selidx][j] == secchoice) {
 3104:                         secok = 1;
 3105:                     }
 3106:                 }
 3107:             }
 3108:         } else {
 3109:             if (rolesections[selidx].length == 1) {
 3110:                 secchoice = rolesections[selidx][0];
 3111:             }
 3112:         }
 3113:     }
 3114:     if (secok == 1) {
 3115:         if (secchoice != '') {
 3116:             fullrole += '/'+secchoice;
 3117:         }
 3118:     } else {
 3119:         document.rolechooser.elements[roleitem].selectedIndex = 0;
 3120:         if (secchoice != null) {
 3121:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
 3122:         }
 3123:         return;
 3124:     }
 3125:     if (fullrole == "$env{'request.role'}") {
 3126:         return;
 3127:     }
 3128:     itemid = retrieveIndex('gotorole');
 3129:     if (itemid != -1) {
 3130:         document.rolechooser.elements[itemid].name = fullrole;
 3131:     }
 3132:     document.rolechooser.switchrole.value = fullrole;
 3133:     document.rolechooser.selectrole.value = '1';
 3134:     document.rolechooser.submit();
 3135:     return;
 3136: }
 3137: 
 3138: function retrieveIndex(item) {
 3139:     for (var i=0;i<document.rolechooser.elements.length;i++) {
 3140:         if (document.rolechooser.elements[i].name == item) {
 3141:             return i;
 3142:         }
 3143:     }
 3144:     return -1;
 3145: }
 3146: // ]]>
 3147: </script>
 3148: END
 3149: }
 3150: 
 3151: sub required_privs {
 3152:     my $privs =  {
 3153:              '/adm/parmset'      => 'opa,vpa',
 3154:              '/adm/courseprefs'  => 'opa,vpa',
 3155:              '/adm/whatsnew'     => 'whn',
 3156:              '/adm/populate'     => 'cst,vpa,vcl',
 3157:              '/adm/trackstudent' => 'vsa',
 3158:              '/adm/statistics'   => 'mgr,vgr',
 3159:              '/adm/setblock'     => 'dcm,vcb',
 3160:              '/adm/coursedocs'   => 'mdc',
 3161:            };
 3162:     unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
 3163:         $privs->{'/adm/classcalc'}   = 'vgr',
 3164:         $privs->{'/adm/assesscalc'}  = 'vgr',
 3165:         $privs->{'/adm/studentcalc'} = 'vgr';
 3166:     }
 3167:     return $privs;
 3168: }
 3169: 
 3170: sub countdown_timer {
 3171:     if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
 3172:         ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
 3173:         my ($type,$hastimeleft,$slothastime);
 3174:         my $now = time;
 3175:         if ($env{'request.filename'} =~ /\.task$/) {
 3176:             $type = 'Task';
 3177:         } else {
 3178:             $type = 'problem';
 3179:         }
 3180:         my ($status,$accessmsg,$slot_name,$slot) =
 3181:             &Apache::lonhomework::check_slot_access('0',$type);
 3182:         if ($slot_name ne '') {
 3183:             if (ref($slot) eq 'HASH') {
 3184:                 if (($slot->{'starttime'} < $now) &&
 3185:                     ($slot->{'endtime'} > $now)) {
 3186:                     $slothastime = 1;
 3187:                 }
 3188:             }
 3189:         }
 3190:         if ($status ne 'CAN_ANSWER') {
 3191:             return;
 3192:         }
 3193:         my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
 3194:         my @interval=&Apache::lonnet::EXT("resource.0.interval");
 3195:         my ($timelimit,$usesdone,$donebuttontext,$proctor,$secret);
 3196:         if (@interval > 1) {
 3197:             ($timelimit,my $donesuffix) = split(/_/,$interval[0],2);
 3198:             if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) {
 3199:                 $usesdone = 'done';
 3200:                 $donebuttontext = $1;
 3201:                 (undef,$proctor,$secret) = split(/_/,$2);
 3202:             } elsif ($donesuffix =~ /^done(|_.+)$/) {
 3203:                 $donebuttontext = &mt('Done');
 3204:                 ($usesdone,$proctor,$secret) = split(/_/,$donesuffix);
 3205:             }
 3206:             my $first_access=&Apache::lonnet::get_first_access($interval[1]);
 3207:             if ($first_access > 0) {
 3208:                 if ($first_access+$timelimit > time) {
 3209:                     $hastimeleft = 1;
 3210:                 }
 3211:             }
 3212:         }
 3213:         if (($duedate && $duedate > time) ||
 3214:             (!$duedate && $hastimeleft) ||
 3215:             ($slot_name ne '' && $slothastime)) {
 3216:             my ($collapse,$expand,$alttxt,$title,$currdisp,$donebutton);
 3217:             if ((@interval > 1 && $hastimeleft) ||
 3218:                 ($type eq 'Task' && $slothastime)) {
 3219:                 $currdisp = 'inline';
 3220:                 $collapse = '&#9658;&nbsp;';
 3221:                 if ((@interval > 1) && ($hastimeleft)) {
 3222:                     if ($usesdone eq 'done') {
 3223:                         $donebutton = &done_button_js($interval[1],'','',$proctor,$donebuttontext);
 3224:                     }
 3225:                 }
 3226:             } else {
 3227:                 $currdisp = 'none';
 3228:                 $expand = '&#9668;&nbsp;';
 3229:             }
 3230:             unless ($env{'environment.icons'} eq 'iconsonly') {
 3231:                 $alttxt = &mt('Timer');
 3232:                 $title = $alttxt.'&nbsp;';
 3233:             }
 3234:             my $desc = &mt('Countdown to due date/time');
 3235:             return <<END;
 3236: $donebutton
 3237: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
 3238: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
 3239: $collapse
 3240: </span></a>
 3241: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
 3242: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
 3243: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
 3244: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
 3245: END
 3246:         }
 3247:     }
 3248:     return;
 3249: }
 3250: 
 3251: # ================================================================ Main Program
 3252: 
 3253: BEGIN {
 3254:     if (! defined($readdesk)) {
 3255:         {
 3256:             my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
 3257:             if ( CORE::open( my $config,"<$tabfile") ) {
 3258:                 while (my $configline=<$config>) {
 3259:                     $configline=(split(/\#/,$configline))[0];
 3260:                     $configline=~s/^\s+//;
 3261:                     chomp($configline);
 3262:                     if ($configline=~/^cat\:/) {
 3263:                         my @entries=split(/\:/,$configline);
 3264:                         $category_positions{$entries[2]}=$entries[1];
 3265:                         $category_names{$entries[2]}=$entries[3];
 3266:                     } elsif ($configline=~/^prim\:/) {
 3267:                         my @entries = (split(/\:/, $configline))[1..6];
 3268:                         push(@primary_menu,\@entries);
 3269:                     } elsif ($configline=~/^primsub\:/) {
 3270:                         my ($parent,@entries) = (split(/\:/, $configline))[1..4];
 3271:                         push(@{$primary_submenu{$parent}},\@entries);
 3272:                     } elsif ($configline=~/^scnd\:/) {
 3273:                         my @entries = (split(/\:/, $configline))[1..5];
 3274:                         push(@secondary_menu,\@entries);
 3275:                     } elsif ($configline=~/^scndsub\:/) {
 3276:                         my ($parent,@entries) = (split(/\:/, $configline))[1..4];
 3277:                         push(@{$secondary_submenu{$parent}},\@entries);
 3278:                     } elsif ($configline) {
 3279:                         push(@desklines,$configline);
 3280:                     }
 3281:                 }
 3282:                 CORE::close($config);
 3283:             }
 3284:         }
 3285:         $readdesk='done';
 3286:     }
 3287: }
 3288: 
 3289: 1;
 3290: __END__
 3291: 

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