File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.83.2.18: download - view: text, annotated - select for diffs
Wed Feb 28 19:08:32 2024 UTC (3 months, 1 week ago) by raeburn
Branches: version_2_11_4_msu
Diff to branchpoint 1.369.2.83: preferred, unified
- For 2.11.4 (modified)
  Include changes in 1.542

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.369.2.83.2.18 2024/02/28 19:08:32 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,$target,$listclass,$linkattr)
  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,$target,$listclass,$linkattr) = @_;
  244:     return '' unless(ref($menuitem) eq 'ARRAY');
  245:     my ($link,$targetattr);
  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:     if ($target ne '') {
  254:         $targetattr = ' target="'.$target.'"';
  255:     }
  256:     return ($listclass?'<li class="'.$listclass.'">':'<li>').'<a'
  257:            # highlighting for new messages
  258:            . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '') 
  259:            . qq| href="$$menuitem[0]"$targetattr $linkattr>$link</a></li>|;
  260: }
  261: 
  262: # primary_menu() evaluates @primary_menu and returns a two item array,
  263: # with the array elements containing XHTML for the left and right sides of 
  264: # the menu that contains the following links:
  265: # Personal, About, Message, Roles, Help, Logout
  266: # @primary_menu is filled within the BEGIN block of this module with 
  267: # entries from mydesk.tab
  268: sub primary_menu {
  269:     my ($crstype,$ltimenu,$menucoll,$menuref,$links_disabled,$links_target,$collapsible) = @_;
  270:     my (%menu,%ltiexc,%menuopts);
  271:     # each element of @primary contains following array:
  272:     # (link url, icon path, alt text, link text, condition, position)
  273:     my $public;
  274:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
  275:         || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
  276:         $public = 1;
  277:     }
  278:     my $lti;
  279:     if ($env{'request.lti.login'}) {
  280:         $lti = 1;
  281:         if (ref($ltimenu) eq 'HASH') {
  282:             foreach my $item ('fullname','logout') {
  283:                 unless ($ltimenu->{$item}) {
  284:                     $ltiexc{$item} = 1;
  285:                 }
  286:             }
  287:         }
  288:     }
  289:     my ($listclass,$linkattr,$target);
  290:     if ($links_disabled) {
  291:         $listclass = 'LCisDisabled';
  292:         $linkattr = 'aria-disabled="true"';
  293:     }
  294:     if ($links_target ne '') {
  295:         $target = $links_target;
  296:     } else {    
  297:         my ($ltitarget,$deeplinktarget);
  298:         if ($env{'request.lti.login'}) {
  299:              $ltitarget = $env{'request.lti.target'};
  300:         }
  301:         if ($env{'request.deeplink.login'}) {
  302:             $deeplinktarget = $env{'request.deeplink.target'};
  303:         }
  304:         if (($ltitarget eq 'iframe') || ($deeplinktarget eq '_self')) {
  305:             $target = '_self';
  306:         } else {
  307:             $target = '_top';
  308:         }
  309:     }
  310:     if (($menucoll) && (ref($menuref) eq 'HASH')) {
  311:         %menuopts = %{$menuref};
  312:     }
  313:     foreach my $menuitem (@primary_menu) {
  314:         # evaluate conditions 
  315:         next if    ref($menuitem)       ne 'ARRAY';    #
  316:         next if    $$menuitem[4]        eq 'nonewmsg'  # show links depending on
  317:                 && &Apache::lonmsg::mynewmail();       # whether a new msg 
  318:         next if    $$menuitem[4]        eq 'newmsg'    # arrived or not
  319:                 && !&Apache::lonmsg::mynewmail();      # 
  320:         next if    $$menuitem[4]        !~ /public/    ##we've a public user,
  321:                 && $public;                            ##who should not see all
  322:                                                        ##links
  323:         next if    $$menuitem[4]        eq 'onlypublic'# hide links which are 
  324:                 && !$public;                           # only visible to public
  325:                                                        # users
  326:         next if    $$menuitem[4]        eq 'roles'     ##show links depending on
  327:                 && (&Apache::loncommon::show_course()  ##term 'Courses' or 
  328:                 || $lti);                              ##'Roles' wanted
  329:         next if    $$menuitem[4]        eq 'courses'   ##and not LTI access
  330:                 && (!&Apache::loncommon::show_course()
  331:                 || $lti);
  332:         next if    $$menuitem[4]        eq 'notlti'
  333:                 && $lti;
  334:         next if    $$menuitem[4]        eq 'ltiexc'
  335:                 && exists($ltiexc{lc($menuitem->[3])});
  336:         my $title = $menuitem->[3];
  337:         my $position = $menuitem->[5];
  338:         if ($position eq '') {
  339:             $position = 'right';
  340:         }
  341:         if ($env{'request.course.id'} && $menucoll) {
  342:             if (($menuitem->[6]) && (!$menuopts{$menuitem->[6]})) {
  343:                 if ($menuitem->[6] eq 'pers') {
  344:                     if ($menuopts{'name'} && !$ltiexc{'fullname'} &&
  345:                         $env{'user.name'} && $env{'user.domain'}) {
  346:                         $menu{$position} .= '<li><a href="#">'.
  347:                             &Apache::loncommon::plainname($env{'user.name'},
  348:                                                           $env{'user.domain'}).'</a></li>';
  349:                         next;
  350:                     } else {
  351:                         next;
  352:                     }
  353:                 } else {
  354:                     next;
  355:                 }
  356:             }
  357:         }
  358:         if (defined($primary_submenu{$title})) {
  359:             my $link;
  360:             if ($menuitem->[0] ne '') {
  361:                 $link = $menuitem->[0];
  362:             } else {
  363:                 $link = '#';
  364:             }
  365:             my @primsub;
  366:             if (ref($primary_submenu{$title}) eq 'ARRAY') {
  367:                 foreach my $item (@{$primary_submenu{$title}}) {
  368:                     next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'})); 
  369:                     next if ((($item->[2] eq 'portfolio') || 
  370:                              ($item->[2] eq 'blog')) && 
  371:                              (!&Apache::lonnet::usertools_access('','',$item->[2],
  372:                                                            undef,'tools')));
  373:                     if (($item->[2] eq 'browsepub') && ($item->[0] eq '/res/')) {
  374:                         if ($env{'request.role'} =~ /^au\./) {
  375:                             $item->[0] .= $env{'request.role.domain'}.'/?launch=1';
  376:                         } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
  377:                             $item->[0] .= $1.'/'.$2.'/?launch=1';
  378:                         } elsif (&Apache::lonnet::allowed('bre',$env{'user.domain'})) {
  379:                             $item->[0] .= $env{'user.domain'}.'/?launch=1';
  380:                         } elsif (&Apache::lonnet::allowed('bro','/res/')) {
  381:                             $item->[0] .= '?launch=1';
  382:                         } else {
  383:                             next;
  384:                         }
  385:                     }
  386:                     if ($env{'request.course.id'} && $menucoll) {
  387:                         next if ($item->[3]) && (!$menuopts{$item->[3]});
  388:                     }
  389:                     push(@primsub,$item);
  390:                 }
  391:                 if ($title eq 'Personal') {
  392:                     if ($env{'user.name'} && $env{'user.domain'} && !$ltiexc{'fullname'}) {
  393:                         unless (($env{'request.course.id'}) && ($menucoll) && (!$menuopts{'name'})) {
  394:                             $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
  395:                         }
  396:                     }
  397:                     next if (($env{'request.course.id'}) && ($menucoll) && ($title eq 'Personal') &&
  398:                              (!@primsub));
  399:                     if ($title eq 'Personal') {
  400:                         $title = &mt($title);
  401:                     }
  402:                 } else {
  403:                     $title = &mt($title);
  404:                 }
  405:                 if (@primsub > 0) {
  406:                     $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1,undef,$listclass,$linkattr);
  407:                 } elsif ($link) {
  408:                     $menu{$position} .= ($listclass?'<li class="'.$listclass.'">':'<li>').
  409:                                         '<a href="'.$link.'" target="'.$target.'" '.$linkattr.'>'.$title.'</a></li>';
  410:                 }
  411:             }
  412:         } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
  413:             if ($public) {
  414:                 my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
  415:                 my $defdom = &Apache::lonnet::default_login_domain();
  416:                 my $to = &Apache::loncommon::build_recipient_list(undef,
  417:                                                                   'helpdeskmail',
  418:                                                                   $defdom,$origmail);
  419:                 if ($to ne '') {
  420:                     $menu{$position} .= &prep_menuitem($menuitem,$target,$listclass,$linkattr); 
  421:                 }
  422:             } else {
  423:                 $menu{$position} .= ($listclass?'<li class="'.$listclass.'">':'<li>').
  424:                                     &Apache::loncommon::top_nav_help('Help',$linkattr).
  425:                                     '</li>';
  426:             }
  427:         } elsif ($$menuitem[3] eq 'Log In') {
  428:             if ($public) {
  429:                 if (&Apache::lonnet::get_saml_landing()) {
  430:                     $$menuitem[0] = '/adm/login';
  431:                 }
  432:             }
  433:             $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr);
  434:         } else {
  435:             $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr);
  436:         }
  437:     }
  438:     my @output = ('','');
  439:     if ($menu{'left'} ne '') {
  440:         if ($collapsible) {
  441:             $menu{'left'} = ($listclass?'<li class="'.$listclass.'">':'<li>').
  442:                             '&nbsp;</li>'.$menu{'left'};
  443:         }
  444:         $output[0] = "<ol class=\"LC_primary_menu LC_floatleft\">$menu{'left'}</ol>";
  445:     }
  446:     if ($menu{'right'} ne '') {
  447:         $output[1] = "<ol class=\"LC_primary_menu LC_floatright LC_right\">$menu{'right'}</ol>";
  448:     }
  449:     return @output;
  450: }
  451: 
  452: #returns hashref {user=>'',dom=>''} containing:
  453: #   own name, domain if user is au
  454: #   name, domain of parent author if user is ca or aa
  455: #empty return if user is not an author or not on homeserver
  456: #
  457: #TODO this should probably be moved somewhere more central
  458: #since it can be used by different parts of the system
  459: sub getauthor{
  460:     return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
  461: 
  462:                         #co- or assistent author?
  463:     my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
  464:                        ? ($1, $2) #domain, username of the parent author
  465:                        : @env{ ('request.role.domain', 'user.name') }; #own domain, username
  466: 
  467:     # current server == home server?
  468:     my $home =  &Apache::lonnet::homeserver($user,$dom);
  469:     foreach (&Apache::lonnet::current_machine_ids()){
  470:         return {user => $user, dom => $dom} if $_ eq $home;
  471:     }
  472: 
  473:     # if wrong server
  474:     return;
  475: }
  476: 
  477: sub secondary_menu {
  478:     my ($httphost,$ltiscope,$ltimenu,$noprimary,$menucoll,$menuref,
  479:         $links_disabled,$links_target) = @_;
  480:     my $menu;
  481: 
  482:     my $crstype = &Apache::loncommon::course_type();
  483:     my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'} 
  484:                                                ? "/$env{'request.course.sec'}"
  485:                                                : '');
  486:     my $canedit       = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
  487:     my $canvieweditor = &Apache::lonnet::allowed('cev', $env{'request.course.id'}); 
  488:     my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
  489:     if ($canviewroster eq 'disabled') {
  490:         undef($canviewroster);
  491:     }
  492:     my $canviewgrps   = &Apache::lonnet::allowed('vcg', $crs_sec);
  493:     my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec);
  494:     my $canviewusers  = &Apache::lonnet::allowed('vcl', $crs_sec);
  495:     my $canviewwnew   = &Apache::lonnet::allowed('whn', $crs_sec);
  496:     my $canviewpara   = &Apache::lonnet::allowed('vpa', $crs_sec);
  497:     my $canmodpara    = &Apache::lonnet::allowed('opa', $crs_sec);
  498:     my $canvgr        = &Apache::lonnet::allowed('vgr', $crs_sec);
  499:     my $canmgr        = &Apache::lonnet::allowed('mgr', $crs_sec);
  500:     my $canplc        = &Apache::lonnet::allowed('plc', $crs_sec);
  501:     my $author        = &getauthor();
  502: 
  503:     my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools,
  504:         $lti,$ltimapres,%ltiexc,%menuopts);
  505:     $grouptools = 0; 
  506:     if ($env{'request.course.id'}) {
  507:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  508:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  509:         unless ($canedit || $canvieweditor) {
  510:             unless (&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus")) {
  511:                 if (($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) ||
  512:                     ($env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) ||
  513:                     ($env{'course.'.$env{'request.course.id'}.'.updatedsyllabus'}) ||
  514:                     ($env{'request.course.syllabustime'})) {
  515:                     $showsyllabus = 1;
  516:                 }
  517:             }
  518:             if ($env{'request.course.feeds'}) {
  519:                 $showfeeds = 1;
  520:             }
  521:         }
  522:         unless ($canmgr || $canvgr) {
  523:             my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
  524:             if (keys(%slots) > 0) {
  525:                 $showresv = 1;
  526:             }
  527:         }
  528:         if ($env{'request.course.groups'} ne '') {
  529:             foreach my $group (split(/:/,$env{'request.course.groups'})) {
  530:                 next unless ($group =~ /^\w+$/);
  531:                 my @privs = split(/:/,$env{"user.priv.$env{'request.role'}./$cdom/$cnum/$group"});
  532:                 shift(@privs);
  533:                 if (@privs) {
  534:                     $grouptools ++;
  535:                 }
  536:             }
  537:         }
  538:         if ($env{'request.lti.login'}) {
  539:             $lti = 1;
  540:             if (ref($ltimenu) eq 'HASH') {
  541:                 foreach my $item ('fullname','coursetitle','role','logout','grades') {
  542:                     unless ($ltimenu->{$item}) {
  543:                         $ltiexc{$item} = 1;
  544:                     }
  545:                 }
  546:             }
  547:             if (($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
  548:                 $ltimapres = 1;
  549:             }
  550:         }
  551:     }
  552:     if (($menucoll) && (ref($menuref) eq 'HASH')) {
  553:         %menuopts = %{$menuref};
  554:     }
  555: 
  556:     my ($listclass,$linkattr,$target);
  557:     if ($links_disabled) {
  558:         $listclass = 'LCisDisabled';
  559:         $linkattr = 'aria-disabled="true"';
  560:     }
  561: 
  562:     my ($canmodifycoauthor);
  563:     if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
  564:         my $extent = "$env{'user.domain'}/$env{'user.name'}";
  565:         if ((&Apache::lonnet::allowed('cca',$extent)) ||
  566:             (&Apache::lonnet::allowed('caa',$extent))) {
  567:             $canmodifycoauthor = 1;
  568:         }
  569:     }
  570: 
  571:     my ($roleswitcher_js,$roleswitcher_form);
  572:     if ($links_target ne '') {
  573:         $target = $links_target;
  574:     } else {
  575:         my ($ltitarget,$deeplinktarget);
  576:         if ($env{'request.lti.login'}) {
  577:             $ltitarget = $env{'request.lti.target'};
  578:         }
  579:         if ($env{'request.deeplink.login'}) {
  580:             $deeplinktarget = $env{'request.deeplink.target'};
  581:         }
  582:         if (($ltitarget eq 'iframe') || ($deeplinktarget eq '_self')) {
  583:             $target = '_self';
  584:         } else {
  585:             $target = '_top';
  586:         }
  587:     }
  588: 
  589:     foreach my $menuitem (@secondary_menu) {
  590:         # evaluate conditions 
  591:         next if    ref($menuitem)  ne 'ARRAY';
  592:         next if    $$menuitem[4]   ne 'always'
  593:                 && ($$menuitem[4]  ne 'author' && $$menuitem[4] ne 'cca')
  594:                 && !$env{'request.course.id'};
  595:         next if    $$menuitem[4]   =~ /^crsedit/
  596:                 && (!$canedit && !$canvieweditor);
  597:         next if    $$menuitem[4]  eq 'crseditCourse'
  598:                 && ($crstype eq 'Community');
  599:         next if    $$menuitem[4]  eq 'crseditCommunity'
  600:                 && ($crstype eq 'Course');
  601:         next if    $$menuitem[4]  eq 'nvgr'
  602:                 && ($canvgr || $ltiexc{'grades'});
  603:         next if    $$menuitem[4]  eq 'vgr'
  604:                 && !$canvgr;
  605:         next if    $$menuitem[4]   eq 'viewusers'
  606:                 && !$canmodifyuser && !$canviewusers;
  607:         next if    $$menuitem[4]   eq 'noviewusers'
  608:                 && ($canmodifyuser || $canviewusers || !$canviewroster);
  609:         next if    $$menuitem[4]   eq 'mgr'
  610:                 && !$canmgr;
  611:         next if    $$menuitem[4]   eq 'showresv'
  612:                 && !$showresv;
  613:         next if    $$menuitem[4]   eq 'whn'
  614:                 && !$canviewwnew;
  615:         next if    $$menuitem[4]   eq 'params'
  616:                 && (!$canmodpara && !$canviewpara);
  617:         next if    $$menuitem[4]   eq 'nvcg'
  618:                 && ($canviewgrps || !$grouptools);
  619:         next if    $$menuitem[4]   eq 'showsyllabus'
  620:                 && !$showsyllabus;
  621:         next if    $$menuitem[4]   eq 'showfeeds'
  622:                 && !$showfeeds;
  623:         next if     $$menuitem[4]  eq 'plc'
  624:                 && !$canplc;
  625:         next if    $$menuitem[4]    eq 'author'
  626:                 && !$author;
  627:         next if    $$menuitem[4]    eq 'cca'
  628:                 && !$canmodifycoauthor;
  629:         next if    $$menuitem[4]    eq 'notltimapres'
  630:                 && $ltimapres;
  631:         next if    $$menuitem[4]    eq 'notlti'
  632:                 && $lti;
  633:         next if    $$menuitem[4]    eq 'lti'
  634:                 && (!$lti || !$noprimary);
  635:         next if    $$menuitem[3]    eq 'Logout'
  636:                 && $ltiexc{'logout'};
  637: 
  638:         my $title = $menuitem->[3];
  639:         if ($env{'request.course.id'} && $menucoll) {
  640:             if ($$menuitem[5] eq 'main') {
  641:                 next if ($menuopts{$$menuitem[5]} eq 'n');
  642:             } elsif ($$menuitem[5] ne 'roles') {
  643:                 next if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]}));
  644:             }
  645:         }
  646:         if (defined($secondary_submenu{$title})) {
  647:             my $link;
  648:             if ($menuitem->[0] ne '') {
  649:                 $link = $menuitem->[0];
  650:             } else {
  651:                 $link = '#';
  652:             }
  653:             my @scndsub;
  654:             if (ref($secondary_submenu{$title}) eq 'ARRAY') {
  655:                 foreach my $item (@{$secondary_submenu{$title}}) {
  656:                     if (ref($item) eq 'ARRAY') {
  657:                         next if ($item->[2] eq 'vgr' && !$canvgr);
  658:                         next if ($item->[2] eq 'opa' && !$canmodpara);
  659:                         next if ($item->[2] eq 'vpa' && !$canviewpara);
  660:                         next if ($item->[2] eq 'viewusers' && !($canmodifyuser || $canviewusers));
  661:                         next if ($item->[2] eq 'mgr' && !$canmgr);
  662:                         next if ($item->[2] eq 'vcg' && !$canviewgrps);
  663:                         next if ($item->[2] eq 'crsedit' && !$canedit && !$canvieweditor);
  664:                         next if ($item->[2] eq 'params' && !$canmodpara && !$canviewpara);
  665:                         next if ($item->[2] eq 'author' && !$author);
  666:                         next if ($item->[2] eq 'cca' && !$canmodifycoauthor);
  667:                         next if ($item->[2] eq 'lti' && !$lti);
  668:                         if ($item->[2] =~ /^lti(portfolio|wishlist|blog)$/) {
  669:                             my $tool = $1;
  670:                             next if !$lti;
  671:                             next if (!&Apache::lonnet::usertools_access('','',$tool,
  672:                                                                         undef,'tools'));
  673:                         }
  674:                         push(@scndsub,$item); 
  675:                     }
  676:                 }
  677:                 if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'}) {
  678:                     unless ($ltiexc{'fullname'}) {
  679:                         $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
  680:                     }
  681:                 }
  682:                 if (@scndsub > 0) {
  683:                     $menu .= &create_submenu($link,$target,&mt($title),\@scndsub,1,undef,
  684:                                              $listclass,$linkattr);
  685:                 } elsif ($link ne '#') {
  686:                     $menu .= ($listclass?'<li class="'.$listclass.'">':'<li>').
  687:                              '<a href="'.$link.'" target="'.$target.'" '.$linkattr.'>'.
  688:                              &mt($title).'</a></li>';
  689:                 }
  690:             }
  691:         } elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
  692:             # special treatment for role selector
  693:             my ($switcher,$has_opa_priv);
  694:             ($roleswitcher_js,$roleswitcher_form,$switcher,$has_opa_priv) =
  695:                 &roles_selector(
  696:                         $env{'course.' . $env{'request.course.id'} . '.domain'},
  697:                         $env{'course.' . $env{'request.course.id'} . '.num'},
  698:                         $httphost,$target,$menucoll,$menuref
  699:                 );
  700:             if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]})) {
  701:                 next unless ($has_opa_priv);
  702:             }
  703:             $menu .= $switcher;
  704:         } else {
  705:             if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) {
  706:                 my $url = $$menuitem[0];
  707:                 $url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum};
  708:                 if (&Apache::lonnet::is_on_map($url)) {
  709:                     unless ($$menuitem[0] =~ /(\?|\&)register=1/) {
  710:                         $$menuitem[0] .= (($$menuitem[0]=~/\?/)? '&' : '?').'register=1';
  711:                     }
  712:                 } else {
  713:                     $$menuitem[0] =~ s{\&?register=1}{};
  714:                 }
  715:                 if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://}) {
  716:                     if (($ENV{'SERVER_PORT'} == 443) || ($env{'request.use_absolute'} =~ m{^https://})) {
  717:                         unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl())) {
  718:                             unless ($$menuitem[0] =~ m{^https?://}) {
  719:                                 $$menuitem[0] = 'http://'.$ENV{'SERVER_NAME'}.$$menuitem[0];
  720:                             }
  721:                             unless ($$menuitem[0] =~ /(\&|\?)usehttp=1/) {
  722:                                 $$menuitem[0] .= (($$menuitem[0]=~/\?/) ? '&' : '?').'usehttp=1';
  723:                             }
  724:                         }
  725:                     }
  726:                 }
  727:                 $$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"');
  728:             }
  729:             $menu .= &prep_menuitem(\@$menuitem,$target,$listclass,$linkattr);
  730:         }
  731:     }
  732:     if ($menu =~ /\[url\].*\[symb\]/) {
  733:         my $escurl  = &escape( &Apache::lonenc::check_encrypt(
  734:                              $env{'request.noversionuri'}));
  735: 
  736:         my $escsymb = &escape( &Apache::lonenc::check_encrypt(
  737:                              $env{'request.symb'})); 
  738: 
  739:         if (    $env{'request.state'} eq 'construct'
  740:             and (   $env{'request.noversionuri'} eq '' 
  741:                  || !defined($env{'request.noversionuri'}))) 
  742:         {
  743:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
  744:             ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
  745:             $escurl  = &escape($escurl);
  746:         }
  747:         $menu =~ s/\[url\]/$escurl/g;
  748:         $menu =~ s/\[symb\]/$escsymb/g;
  749:     }
  750:     $menu =~ s/\[uname\]/$$author{user}/g;
  751:     $menu =~ s/\[udom\]/$$author{dom}/g;
  752:     $menu =~ s/\[javascript\]/javascript:/g;
  753:     if ($env{'request.course.id'}) {  
  754:         $menu =~ s/\[cnum\]/$cnum/g;
  755:         $menu =~ s/\[cdom\]/$cdom/g;
  756:     }
  757:     if ($menu) {
  758:         $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>";
  759:     }
  760:     if ($roleswitcher_form) {
  761:         $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
  762:     }
  763:     return $menu;
  764: }
  765: 
  766: sub create_submenu {
  767:     my ($link,$target,$title,$submenu,$translate,$addclass,$listclass,$linkattr) = @_;
  768:     return unless (ref($submenu) eq 'ARRAY');
  769:     my $targetattr;
  770:     if (($target ne '') && ($link ne '#')) {
  771:         $targetattr = ' target="'.$target.'"';
  772:     }
  773:     my $menu = '<li class="LC_hoverable '.$addclass.'">'.
  774:                '<a href="'.$link.'"'.$targetattr.'>'.
  775:                '<span class="LC_nobreak">'.$title.
  776:                '<span class="LC_fontsize_small" style="font-weight:normal;">'.
  777:                ' &#9660;</span></span></a>'.
  778:                '<ul>';
  779: 
  780:     # $link and $title are only used in the initial string written in $menu
  781:     # as seen above, not needed for nested submenus
  782:     $menu .= &build_submenu($target, $submenu, $translate, '1', $listclass, $linkattr);
  783:     $menu .= '</ul></li>';
  784: 
  785:     return $menu;
  786: }
  787: 
  788: # helper routine for create_submenu
  789: # build the dropdown (and nested submenus) recursively
  790: # see perldoc create_submenu documentation for further information
  791: sub build_submenu {
  792:     my ($target, $submenu, $translate, $first_level, $listclass, $linkattr) = @_;
  793:     unless (@{$submenu}) {
  794:         return '';
  795:     }
  796: 
  797:     my $menu = '';
  798:     my $count = 0;
  799:     my $numsub = scalar(@{$submenu});
  800:     foreach my $item (@{$submenu}) {
  801:         $count ++;
  802:         if (ref($item) eq 'ARRAY') {
  803:             my $href = $item->[0];
  804:             my $bordertop;
  805:             my $borderbot;
  806:             my $title;
  807: 
  808:             if ($translate) {
  809:                  $title = &mt($item->[1]);
  810:             } else {
  811:                 $title = $item->[1];
  812:             }
  813: 
  814:             if ($count == 1 && !$first_level) {
  815:                 $bordertop = 'border-top: 1px solid black;';
  816:             }
  817:             if ($count == $numsub) {
  818:                 $borderbot = 'border-bottom: 1px solid black;';
  819:             }
  820: 
  821:             # href is a reference to another submenu
  822:             if (ref($href) eq 'ARRAY') {
  823:                 $menu .= '<li style="margin:0;padding:0;'.$bordertop . $borderbot . '">';
  824:                 $menu .= '<p><span class="LC_primary_menu_innertitle">'
  825:                                         . $title . '</span><span class="LC_primary_menu_innerarrow">&#9654;</span></p>';
  826:                 $menu .= '<ul>';
  827:                 $menu .= &build_submenu($target, $href, $translate);
  828:                 $menu .= '</ul>';
  829:                 $menu .= '</li>';
  830:             } else {    # href is the actual hyperlink and does not represent another submenu
  831:                         # for the current menu title
  832:                 if ($href =~ /(aboutme|rss\.html)$/) {
  833:                     next unless (($env{'user.name'} ne '') && ($env{'user.domain'} ne ''));
  834:                     $href =~ s/\[domain\]/$env{'user.domain'}/g;
  835:                     $href =~ s/\[user\]/$env{'user.name'}/g;
  836:                 } elsif (($href =~ m{^/adm/preferences\?}) && ($href =~ /\[returnurl\]/)) {
  837:                     my $returnurl = $ENV{'REQUEST_URI'};
  838:                     if ($ENV{'REQUEST_URI'} =~ m{/adm/preferences\?action=(?:changedomcoord|authorsettings)\&returnurl=([^\&]+)$}) {
  839:                         $returnurl = $1;
  840:                     }
  841:                     if (($returnurl =~ m{^/adm/createuser($|\?action=)}) ||
  842:                         ($returnurl =~ m{^/priv/$match_domain/$match_username}) ||
  843:                         ($returnurl =~ m{^/res(/?$|/$match_domain/$match_username)})) {
  844:                         $returnurl =~ s{\?.*$}{};
  845:                         $returnurl = '&amp;returnurl='.&HTML::Entities::encode($returnurl,'"<>&\'');
  846:                     } else {
  847:                         undef($returnurl);
  848:                     }
  849:                     $href =~ s/\[returnurl\]/$returnurl/;
  850:                 }
  851:                 my $targetattr;
  852:                 unless (($href eq '') || ($href =~ /^\#/)) {
  853:                     if ($target ne '') {
  854:                         $targetattr = ' target="'.$target.'"';
  855:                     }
  856:                 }
  857: 
  858:                 $menu .= '<li ';
  859:                 $menu .= ($listclass?'class="'.$listclass.'" ':'');
  860:                 $menu .= 'style="margin:0;padding:0;'. $bordertop . $borderbot .'">';
  861:                 $menu .= '<a href="'.$href.'"'.$targetattr.' '.$linkattr.'>' .  $title . '</a>';
  862:                 $menu .= '</li>';
  863:             }
  864:         }
  865:     }
  866:     return $menu;
  867: }
  868: 
  869: sub registerurl {
  870:     my ($forcereg) = @_;
  871:     my $result = '';
  872:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  873:     my $force_title='';
  874:     if ($env{'request.state'} eq 'construct') {
  875:         $force_title=&Apache::lonxml::display_title();
  876:     }
  877:     if (($env{'environment.remote'} ne 'on') ||
  878:         ((($env{'request.publicaccess'}) ||
  879:          (!&Apache::lonnet::is_on_map(
  880:            &unescape($env{'request.noversionuri'})))) &&
  881:         (!$forcereg))) {
  882:         return
  883:         $result
  884:        .'<script type="text/javascript">'."\n"
  885:        .'// <![CDATA['."\n"
  886:        .'function LONCAPAreg(){;} function LONCAPAstale(){}'."\n"
  887:        .'// ]]>'."\n"
  888:        .'</script>'
  889:        .$force_title;
  890:     }
  891: # Graphical display after login only
  892:     if ($env{'request.registered'} && !$forcereg) { return ''; }
  893:     $result.=&innerregister($forcereg);
  894:     return $result.$force_title;
  895: }
  896: 
  897: sub innerregister {
  898:     my ($forcereg,$bread_crumbs,$group,$pagebuttonshide,$hostname,
  899:         $ltiscope,$ltiuri,$showncrumbsref) = @_;
  900:     my $const_space = ($env{'request.state'} eq 'construct');
  901:     my $is_const_dir = 0;
  902: 
  903:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  904: 
  905:     $env{'request.registered'} = 1;
  906: 
  907:     my $noremote = ($env{'environment.remote'} ne 'on');
  908: 
  909:     undef(@inlineremote);
  910: 
  911:     my $reopen=&Apache::lonmenu::reopenmenu();
  912: 
  913:     my $newmail='';
  914: 
  915:     if (&Apache::lonmsg::newmail() && !$noremote) {
  916:         # We have new mail and remote is up
  917:         $newmail= 'swmenu.setstatus("you have","messages");';
  918:     }
  919: 
  920:     my ($mapurl,$resurl,$crstype,$navmap);
  921: 
  922:     if ($env{'request.course.id'}) {
  923: #
  924: #course_type:  Course or Community
  925: #
  926:         $crstype = &Apache::loncommon::course_type();
  927:         if ($env{'request.symb'}) {
  928:             my $ignorenull;
  929:             unless ($env{'request.noversionuri'} eq '/adm/navmaps') {
  930:                 $ignorenull = 1;
  931:             }
  932:             my $symb = &Apache::lonnet::symbread('','',$ignorenull);
  933:             ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb($symb);
  934:             my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
  935: 
  936:             my $maptitle = &Apache::lonnet::gettitle($mapurl);
  937:             my $restitle = &Apache::lonnet::gettitle($symb);
  938: 
  939:             my (@crumbs,@mapcrumbs);
  940:             if (($env{'request.noversionuri'} ne '/adm/navmaps') && ($mapurl ne '')) { 
  941:                 unless ($ltiscope eq 'resource') {
  942:                     if (($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) &&
  943:                         !(($ltiscope eq 'map') && (&Apache::lonnet::clutter($resurl) eq $ltiuri))) {
  944:                         $navmap = Apache::lonnavmaps::navmap->new();
  945:                         if (ref($navmap)) {
  946:                             @mapcrumbs = $navmap->recursed_crumbs($mapurl,$restitle);
  947:                         }
  948:                     }
  949:                 }
  950:             }
  951:             unless (($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
  952:                 @crumbs = ({text  => $crstype.' Contents', 
  953:                             href  => "Javascript:gopost('/adm/navmaps','')"});
  954:             }
  955:             if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { 
  956:                 if (@mapcrumbs) {
  957:                     push(@crumbs,@mapcrumbs);
  958:                 } elsif (($ltiscope ne 'map') && ($ltiscope ne 'resource')) {
  959:                     push(@crumbs, {text  => '...',
  960:                                    no_mt => 1});
  961:                 }
  962:             }
  963: 
  964:             unless ((@mapcrumbs) || (!$maptitle) || ($maptitle eq 'default.sequence') ||
  965:                     ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) ||
  966:                     ($ltiscope eq 'resource')) { 
  967:                 push @crumbs, {text => $maptitle, no_mt => 1,
  968:                                href => &Apache::lonnet::clutter($mapurl).'?navmap=1'};
  969:             }
  970:             if ($restitle && !@mapcrumbs) {
  971:                 push(@crumbs,{text => $restitle, no_mt => 1});
  972:             }
  973:             my @tools;
  974:             if ($env{'request.filename'} =~ /\.page$/) {
  975:                 my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
  976:                 if (ref($breadcrumb_tools{'tools'}) eq 'ARRAY') {
  977:                     @tools = @{$breadcrumb_tools{'tools'}};
  978:                 }
  979:             }
  980:             &Apache::lonhtmlcommon::clear_breadcrumbs();
  981:             &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
  982:             if (@tools) {
  983:                 &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',@tools);
  984:             }
  985:         } else {
  986:             $resurl = $env{'request.noversionuri'};
  987:             my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
  988:             my $title = &mt('View Resource');
  989:             if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) {
  990:                 &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']);
  991:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
  992:                 if ($env{'form.title'}) {
  993:                     $title = $env{'form.title'};
  994:                 }
  995:                 my ($trail,$cnum,$cdom);
  996:                 if ($env{'form.folderpath'}) {
  997:                     $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  998:                     $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  999:                     &Apache::loncommon::validate_folderpath(1,'',$cnum,$cdom);
 1000:                 }
 1001:                 if ($env{'form.folderpath'}) {
 1002:                     &prepare_functions($resurl,$forcereg,$group,undef,undef,1,$hostname);
 1003:                     $title = &HTML::Entities::encode($title,'\'"<>&');
 1004:                     ($trail) =
 1005:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
 1006:                 } else {
 1007:                     &Apache::lonhtmlcommon::add_breadcrumb(
 1008:                     {text  => "Supplemental $crstype Content",
 1009:                      href  => "javascript:gopost('/adm/supplemental','')"});
 1010:                     $title = &HTML::Entities::encode(&mt('View Resource'),'\'"<>&');
 1011:                     ($trail) =
 1012:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
 1013:                 }
 1014:                 if (ref($showncrumbsref)) {
 1015:                     $$showncrumbsref = 1;
 1016:                 }
 1017:                 return $trail;
 1018:             } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) {
 1019:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
 1020:                 &prepare_functions('/public'.$courseurl."/syllabus",
 1021:                                    $forcereg,$group,undef,undef,1,$hostname);
 1022:                 $title = &HTML::Entities::encode(&mt('Syllabus File'),'\'"<>&');  
 1023:                 my ($trail) =
 1024:                     &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
 1025:                 if (ref($showncrumbsref)) {
 1026:                     $$showncrumbsref = 1;
 1027:                 }
 1028:                 return $trail;
 1029:             } elsif (($resurl eq '/public'.$courseurl.'/syllabus') &&
 1030:                      ($env{'form.folderpath'})) {
 1031:                 if ($env{'form.title'}) {
 1032:                     $title = $env{'form.title'};
 1033:                 } else {
 1034:                     $title = 'Syllabus';
 1035:                 }
 1036:                 &prepare_functions($resurl,$forcereg,$group,undef,undef,1,$hostname);
 1037:                 $title = &HTML::Entities::encode($title,'\'"<>&');
 1038:                 my ($trail) =
 1039:                     &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
 1040:                 return $trail;
 1041:             }
 1042:             unless ($env{'request.state'} eq 'construct') {
 1043:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
 1044:                 &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
 1045:             }
 1046:         }
 1047:     } elsif (! $const_space){
 1048:         #a situation when we're looking at a resource outside of context of a 
 1049:         #course or construction space (e.g. with cumulative rights)
 1050:         &Apache::lonhtmlcommon::clear_breadcrumbs();
 1051:         unless ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
 1052:             &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
 1053:         }
 1054:     }
 1055:     my $timesync   = ( $noremote ? '' : 'swmenu.syncclock(1000*'.time.');' );
 1056: # =============================================================================
 1057: # ============================ This is for URLs that actually can be registered
 1058:     if ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/})
 1059:                        || ($forcereg)) {
 1060: 
 1061:         my %swtext;
 1062:         if ($noremote) {
 1063:             %swtext = &get_inline_text();
 1064:         } else {
 1065:             %swtext = &get_rc_text();
 1066:         }
 1067:         my $hwkadd='';
 1068: 
 1069:         my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
 1070:             $forceview,$editbutton);
 1071:         if (($resurl =~ m{^/adm/($match_domain)/($match_username)/aboutme$}) ||
 1072:             ($env{'request.role'} !~/^(aa|ca|au)/)) {
 1073:             if (($env{'environment.remote'} eq 'on') && ($env{'request.symb'})) {
 1074:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
 1075:             }
 1076:             $editbutton = &prepare_functions($resurl,$forcereg,$group,'','','',$hostname);
 1077:         }
 1078:         if ($editbutton eq '') {
 1079:             $editbutton = &clear(6,1);
 1080:         }
 1081: 
 1082: #
 1083: # This applies in course context
 1084: #
 1085:         if ($env{'request.course.id'}) {
 1086:             $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 1087:             $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1088:             $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
 1089:             $perms{'cev'} = &Apache::lonnet::allowed('cev',$env{'request.course.id'});
 1090:             my @privs;
 1091:             my $gradable_exttool;
 1092:             if ($env{'request.symb'} ne '') {
 1093:                 if ($env{'request.noversionuri'} =~ m{^/adm/$cdom/$cnum/(\d+)/ext\.tool$}) {
 1094:                     if (&Apache::lonnet::EXT('resource.0.gradable') =~ /^yes$/i) {
 1095:                         $gradable_exttool = 1;
 1096:                          push(@privs,('mgr','vgr'));
 1097:                     }
 1098:                 } elsif ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
 1099:                     push(@privs,('mgr','vgr'));
 1100:                 }
 1101:                 push(@privs,('opa','vpa'));
 1102:             }
 1103:             foreach my $priv (@privs) {
 1104:                 $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
 1105:                 if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
 1106:                     $perms{$priv} =
 1107:                         &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
 1108:                 }
 1109:             }
 1110: #
 1111: # Determine whether or not to show Grades and Submissions buttons
 1112: #
 1113:             if (($env{'request.symb'} ne '') &&
 1114:                 (($env{'request.filename'}=~/$LONCAPA::assess_re/) || ($gradable_exttool))) {
 1115:                 if ($perms{'mgr'}) {
 1116:                     $hwkadd.= &switch('','',7,2,'pgrd.png','Content Grades',
 1117:                                       'grades[_4]',
 1118:                                       "gocmd('/adm/grades','gradingmenu')",
 1119:                                       'Content Grades');
 1120:                 } elsif ($perms{'vgr'}) {
 1121:                     $hwkadd .= &switch('','',7,2,'subm.png','Content Submissions',
 1122:                                        'missions[_1]',
 1123:                                        "gocmd('/adm/grades','submission')",
 1124:                                        'Content Submissions');
 1125:                 }
 1126:             }
 1127:             if (($env{'request.symb'} ne '') && (($perms{'opa'}) || ($perms{'vpa'}))) {
 1128:                 $hwkadd .= &switch('','',7,3,'pparm.png','Content Settings',
 1129:                                    'parms[_2]',"gocmd('/adm/parmset','set')",
 1130:                                    'Content Settings');
 1131:             }
 1132: # End grades/submissions check
 1133: 
 1134: #
 1135: # This applies to items inside a folder/page modifiable in the course.
 1136: #
 1137:             if (($env{'request.symb'}=~/^uploaded/) && (($perms{'mdc'}) || ($perms{'cev'}))) {
 1138:                 my $text = 'Edit Folder';
 1139:                 if (($mapurl =~ /\.page$/) ||
 1140:                     ($env{'request.symb'}=~
 1141:                          m{uploaded/$cdom/$cnum/default_\d+\.page$}))  {
 1142:                     $text = 'Edit Page';
 1143:                 }
 1144:                 $hwkadd .= &switch('','',7,4,'docs-22x22.png',$text,'parms[_2]',
 1145:                                    "gocmd('/adm/coursedocs','direct')",
 1146:                                    'Folder/Page Content');
 1147:             }
 1148: # End modifiable folder/page container check
 1149: 
 1150: #
 1151: # Determine whether to show View As button for shortcut to display problem, answer, and submissions
 1152: #
 1153: 
 1154:         if (($env{'request.symb'} ne '') &&
 1155:             ($env{'request.filename'}=~/$LONCAPA::assess_re/) &&
 1156:             (($perms{'mgr'}) || ($perms{'vgr'}))) {
 1157:             my ($viewas,$text,$change,$visibility,$vuname,$vudom,$vid,$leftvis,$defdom,
 1158:                 $domselector,$righticon);
 1159:             my %lt = &Apache::lonlocal::texthash(
 1160:                                                  view => 'View',
 1161:                                                  upda => 'Update',
 1162:             );
 1163:             my $possdomstr = $env{'course.'.$env{'request.course.id'}.'.internal.userdomains'};
 1164:             if ($possdomstr =~ /,/) {
 1165:                 my @possdoms = split(/,/,$possdomstr);
 1166:                 if ($env{'request.user_in_effect'} =~ /^$match_username:($match_domain)$/) {
 1167:                     $defdom = $1;
 1168:                 } elsif (grep(/^\Q$cdom\E$/,@possdoms)) {
 1169:                     $defdom = $cdom;
 1170:                 } elsif (&Apache::lonnet::domain($possdoms[0]) ne '') {
 1171:                     $defdom = $possdoms[0];
 1172:                 }
 1173:                 $domselector = &Apache::loncommon::select_dom_form($defdom,'vudom','','','',\@possdoms);
 1174:             } elsif (($possdomstr ne '') && (&Apache::lonnet::domain($possdomstr) ne '')) {
 1175:                 if ($env{'request.user_in_effect'} =~ /^$match_username:($match_domain)$/) {
 1176:                     $defdom = $1;
 1177:                 } else {
 1178:                     $defdom = $possdomstr;
 1179:                 }
 1180:             }
 1181:             if ($env{'request.user_in_effect'} =~ /^($match_username):($match_domain)$/) {
 1182:                 ($vuname,$vudom) = ($1,$2);
 1183:                 unless (&Apache::lonnet::is_advanced_user($vudom,$vuname)) {
 1184:                     $vid = (&Apache::lonnet::idrget($vudom,$vuname))[1];
 1185:                 }
 1186:                 $viewas = $env{'request.user_in_effect'};
 1187:                 $text = $lt{'upda'};
 1188:                 $change = 'off';
 1189:                 $visibility = 'inline';
 1190:                 $leftvis = 'none';
 1191:                 $defdom = $vudom;
 1192:                 $righticon = '&#10006;';
 1193:             } else {
 1194:                 $text = $lt{'view'};
 1195:                 $change = 'on';
 1196:                 $visibility = 'none';
 1197:                 $leftvis = 'inline';
 1198:                 if ($defdom eq '') {
 1199:                     $defdom = $cdom;
 1200:                 }
 1201:             }
 1202:             my $sellink = &Apache::loncommon::selectstudent_link('userview','vuname','vudom','','','vuidentifier');
 1203:             my $selscript=&Apache::loncommon::studentbrowser_javascript();
 1204:             my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}),'<>&"');
 1205:             my $input;
 1206:             my @items = (
 1207:                          '<label><input type="radio" name="vuidentifier" value="uname" checked="checked" onclick="javascript:toggleIdentifier(this.form);" />',
 1208:                          '</label><input name="vuname" type="text" size="6" value="'.$vuname.'" id="LC_vuname" />',
 1209:                          '<label><input type="radio" name="vuidentifier" value="uid" onclick="javascript:toggleIdentifier(this.form);" />',
 1210:                          '</label><input name="vid" type="hidden" size="6" value="'.$vid.'" id="LC_vid" />'
 1211:                         );
 1212:             if ($domselector) {
 1213:                 push(@items,$domselector);
 1214:                 $input = &mt('[_1]User:[_2] or [_3]ID:[_4] at [_5] | ',@items);
 1215:             } else {
 1216:                 $input = &mt('[_1]Username:[_2] or [_3]ID:[_4] | ',@items).
 1217:                          '<input name="vudom" type="hidden" value="'.$defdom.'" />';
 1218:             }
 1219:             $input .= '<input name="LC_viewas" type="hidden" value="'.$viewas.'" />',
 1220:                       '<input name="symb" type="hidden" value="'.$shownsymb.'" />';
 1221:             my $chooser = <<END;
 1222: $selscript
 1223: <a href="javascript:toggleViewAsUser('$change');" class="LC_menubuttons_link">
 1224: <span id="usexpand" class="LC_menubuttons_inline_text" style="display:$leftvis">&#9658;&nbsp;</span>
 1225: </a>
 1226: <fieldset id="LC_selectuser" style="display:$visibility">
 1227: <form name="userview" action="" method="post" onsubmit="event.preventDefault(); return validCourseUser(this,'$change');">
 1228: <span class="LC_menubuttons_inline_text LC_nobreak">
 1229: $input
 1230: $sellink
 1231: </span>
 1232: &nbsp;<input type="submit" value="$text" />
 1233: </form>
 1234: </fieldset>
 1235: <a href="javascript:toggleViewAsUser('$change');" class="LC_menubuttons_link">
 1236: <span id="uscollapse" class="LC_menubuttons_inline_text">$righticon</span>
 1237: </a>
 1238: END
 1239:             &switch('','',7,5,'viewuser.png','View As','user[_1]',
 1240:                     'toggleViewAsUser('."'$change'".')',
 1241:                     'View As','','','',$chooser);
 1242:         }
 1243: # End view as user check
 1244: 
 1245:         }
 1246: # End course context
 1247: 
 1248: # Prepare the rest of the buttons
 1249:         my ($menuitems,$got_prt,$got_wishlist,$cstritems);
 1250:         if ($const_space) {
 1251: #
 1252: # We are in construction space
 1253: #
 1254: 
 1255:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
 1256: 	    my ($udom,$uname,$thisdisfn) =
 1257: 		($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
 1258:             my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
 1259:             if ($currdir =~ m-/$-) {
 1260:                 $is_const_dir = 1;
 1261:                 if ($thisdisfn eq '') {
 1262:                     $is_const_dir = 2;
 1263:                 }
 1264:             } else {
 1265:                 $currdir =~ s|[^/]+$||;
 1266: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
 1267: 		my $esc_currdir = &Apache::loncommon::escape_single($currdir);
 1268: #
 1269: # Probably should be in mydesk.tab
 1270: #
 1271:                 $menuitems=(<<ENDMENUITEMS);
 1272: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
 1273: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
 1274: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
 1275: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
 1276: ENDMENUITEMS
 1277: 
 1278: #
 1279: # Print only makes sense for certain mime types
 1280: #
 1281:                 if ($thisdisfn=~/\.(xml|html|htm|xhtml|xhtm|tex)$/ || $thisdisfn=~/$LONCAPA::assess_re/) {
 1282:                     $menuitems .= (<<ENDMENUITEMS);
 1283: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
 1284: ENDMENUITEMS
 1285:                 }
 1286:                 unless ($noremote) {
 1287:                     $cstritems = $menuitems;
 1288:                     undef($menuitems);
 1289:                 }
 1290:             }
 1291:             if (ref($bread_crumbs) eq 'ARRAY') {
 1292:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
 1293:                 foreach my $crumb (@{$bread_crumbs}){
 1294:                      &Apache::lonhtmlcommon::add_breadcrumb($crumb);
 1295:                 }
 1296:             }
 1297:         } elsif ( defined($env{'request.course.id'}) && 
 1298: 		 $env{'request.symb'} ne '' ) {
 1299: #
 1300: # We are in a course and looking at a registered URL
 1301: # Should probably be in mydesk.tab
 1302: #
 1303:             $menuitems = "c&3&1";
 1304:             if ($ltiscope eq 'resource') {
 1305: # Suppress display of backward arrow for LTI Provider if scope is resource.
 1306: # Suppress display of forward arrow for LTI Provider if scope is resource.
 1307:             } elsif ($ltiscope eq 'map') {
 1308: # Suppress display of backward arrow for LTI Provider if scope is map and this is first resource.
 1309: # Suppress display of forward arrow for LTI Provider if scope is map and this is the last resource.
 1310:                 my $showforw = 1;
 1311:                 my $showback = 1;
 1312:                 my $navmap = Apache::lonnavmaps::navmap->new();
 1313:                 if (ref($navmap)) {
 1314:                     my $mapres = $navmap->getResourceByUrl($ltiuri);
 1315:                     if (ref($mapres)) {
 1316:                         if ($navmap->isLastResource($mapres,$env{'request.symb'})) {
 1317:                             $showforw = 0;
 1318:                         }
 1319:                         if ($navmap->isFirstResource($mapres,$env{'request.symb'})) {
 1320:                             $showback = 0;
 1321:                         }
 1322:                     }
 1323:                 }
 1324:                 if ($showback) {
 1325:                     $menuitems.="
 1326: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1";
 1327:                 }
 1328:                 if ($showforw) {
 1329:                     $menuitems.="
 1330: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3";
 1331:                 }
 1332:             } else {
 1333:                 $menuitems.="
 1334: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
 1335: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3";
 1336:             }
 1337:             $menuitems .= (<<ENDMENUITEMS);
 1338: 
 1339: c&6&3
 1340: c&8&2
 1341: s&8&3&prt.png&$swtext{'prt'}&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
 1342: ENDMENUITEMS
 1343:             $got_prt = 1;
 1344:             if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
 1345:                 && (!$env{'request.enc'})) {
 1346:                 # wishlist is only available for users with access to resource-pool
 1347:                 # and links can only be set for resources within the resource-pool
 1348:                 $menuitems .= (<<ENDMENUITEMS);
 1349: 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
 1350: ENDMENUITEMS
 1351:                 $got_wishlist = 1;
 1352:             }
 1353: 
 1354: my $currentURL = &Apache::loncommon::get_symb();
 1355: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
 1356: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
 1357: $menuitems.="s&9&3&";
 1358: if(length($annotation) > 0){
 1359: 	$menuitems.="anot2.png";
 1360: }else{
 1361: 	$menuitems.="anot.png";
 1362: }
 1363: $menuitems.="&$swtext{'anot'}&tations[_1]&annotate()&";
 1364: $menuitems.="Make notes and annotations about this resource&&1\n";
 1365: my $is_mobile;
 1366: if ($env{'browser.mobile'}) {
 1367:     $is_mobile = 1;
 1368: }
 1369: 
 1370:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
 1371: 		if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) &&
 1372:                     ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/(docs/|default_\d+\.page$)}) &&
 1373:                     ($env{'request.noversionuri'} !~ m{^/adm/.+/ext\.tool$})) {
 1374: 		    $menuitems.=(<<ENDREALRES);
 1375: s&6&3&catalog.png&$swtext{'catalog'}&info[_1]&catalog_info(currentURL,'$is_mobile')&Show Metadata
 1376: ENDREALRES
 1377:                 }
 1378:                 unless (($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/(docs/|default_\d+\.page$)}) ||
 1379:                         ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) ||
 1380:                         ($env{'request.noversionuri'} =~ m{^/adm/.+/ext\.tool$})) { 
 1381: 	            $menuitems.=(<<ENDREALRES);
 1382: s&8&1&eval.png&$swtext{'eval'}&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
 1383: ENDREALRES
 1384:                 }
 1385:                 unless ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) {
 1386:                     $menuitems.=(<<ENDREALRES);
 1387: 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
 1388: ENDREALRES
 1389:                 }
 1390: 	    }
 1391:         }
 1392: 	if ($env{'request.uri'} =~ /^\/res/) {
 1393:             unless ($got_prt) {
 1394: 	        $menuitems .= (<<ENDMENUITEMS);
 1395: s&8&3&prt.png&$swtext{'prt'}&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
 1396: ENDMENUITEMS
 1397:                 $got_prt = 1;
 1398:             }
 1399:             unless ($got_wishlist) {
 1400:                 if (($env{'user.adv'}) && (!$env{'request.enc'})) {
 1401:                     # wishlist is only available for users with access to resource-pool
 1402:                     $menuitems .= (<<ENDMENUITEMS);
 1403: 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
 1404: ENDMENUITEMS
 1405:                     $got_wishlist = 1;
 1406:                 }
 1407:             }
 1408: 	}
 1409:         unless ($got_prt) {
 1410:             $menuitems .= (<<ENDMENUITEMS);
 1411: c&8&3
 1412: ENDMENUITEMS
 1413:         }
 1414:         unless ($got_wishlist) {
 1415:             $menuitems .= (<<ENDMENUITEMS);
 1416: c&9&1
 1417: ENDMENUITEMS
 1418:         }
 1419:         my $buttons='';
 1420:         foreach (split(/\n/,$menuitems)) {
 1421: 	    my ($command,@rest)=split(/\&/,$_);
 1422:             my $idx=10*$rest[0]+$rest[1];
 1423:             if (&hidden_button_check() eq 'yes') {
 1424:                 if ($idx == 21 ||$idx == 23) {
 1425:                     $buttons.=&switch('','',@rest);
 1426:                 } else {
 1427:                     $buttons.=&clear(@rest);
 1428:                 }
 1429:             } else {  
 1430:                 if ($command eq 's') {
 1431: 	            $buttons.=&switch('','',@rest);
 1432:                 } else {
 1433:                     $buttons.=&clear(@rest);
 1434:                 }
 1435:             }
 1436:         }
 1437:         my $linkprotout;
 1438:         if ($env{'request.deeplink.login'}) {
 1439:             $linkprotout = &linkprot_exit();
 1440:         }
 1441:         if ($noremote) {
 1442: 	    my $addremote=0;
 1443: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
 1444:             if ($addremote) {
 1445:                 my ($countdown,$buttonshide);
 1446:                 if ($env{'request.filename'} =~ /\.page$/) {
 1447:                     my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
 1448:                     if (ref($breadcrumb_tools{'tools'}) eq 'ARRAY') {
 1449:                         $countdown = $breadcrumb_tools{'tools'}->[0];
 1450:                     }
 1451:                     $buttonshide = $pagebuttonshide;
 1452:                 } else {
 1453:                     $countdown = &countdown_timer();
 1454:                     $buttonshide = &hidden_button_check();
 1455:                 }
 1456: 
 1457:                 &Apache::lonhtmlcommon::clear_breadcrumb_tools();
 1458: 
 1459:                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1460:                     'navigation', @inlineremote[21,23]);
 1461: 
 1462:                 if ($buttonshide eq 'yes') {
 1463:                     if ($countdown) {
 1464:                         &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
 1465:                     }
 1466:                     if ($linkprotout) {
 1467:                         &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
 1468:                     }
 1469:                 } else {
 1470:                     my @tools = @inlineremote[93,91,81,82,83];
 1471:                     if ($countdown) {
 1472:                         unshift(@tools,$countdown);
 1473:                     }
 1474:                     if ($linkprotout) {
 1475:                         unshift(@tools,$linkprotout);
 1476:                     }
 1477:                     &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1478:                         'tools',@tools);
 1479: 
 1480:                     #publish button in construction space
 1481:                     if ($env{'request.state'} eq 'construct'){
 1482:                         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1483:                             'advtools', $inlineremote[63]);
 1484:                     } else {
 1485:                         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1486:                             'tools', $inlineremote[63]);
 1487:                     }
 1488:                     &advtools_crumbs(@inlineremote);
 1489:                 }
 1490:             } else {
 1491:                 if ($linkprotout) {
 1492:                     &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
 1493:                 }
 1494:             }
 1495:             my ($topic_help,$topic_help_text);
 1496:             if ($is_const_dir == 2) {
 1497:                 if ((($ENV{'SERVER_PORT'} == 443) ||
 1498:                      ($Apache::lonnet::protocol{$Apache::lonnet::perlvar{'lonHostID'}} eq 'https')) &&
 1499:                      (&Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},'webdav'))) {
 1500:                     $topic_help = 'Authoring_WebDAV,Authoring_WebDAV_Mac_10v6,Authoring_WebDAV_Mac_10v10,'.
 1501:                                  'Authoring_WebDAV_Windows_v7,Authoring_WebDAV_Linux_Centos';
 1502:                     $topic_help_text = 'About WebDAV access';
 1503:                 }
 1504:             }
 1505:             if (ref($showncrumbsref)) {
 1506:                 $$showncrumbsref = 1;
 1507:             }
 1508:             return   &Apache::lonhtmlcommon::scripttag('', 'start')
 1509:                    . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'','','','',$topic_help,$topic_help_text)
 1510:                    . &Apache::lonhtmlcommon::scripttag('', 'end');
 1511: 
 1512:         } else {
 1513:             my $cstrcrumbs;
 1514:             if ($const_space) {
 1515:                 foreach (split(/\n/,$cstritems)) {
 1516:                     my ($command,@rest)=split(/\&/,$_);
 1517:                     my $idx=10*$rest[0]+$rest[1];
 1518:                     &switch('','',@rest);
 1519:                 }
 1520:                 &Apache::lonhtmlcommon::add_breadcrumb_tool('advtools',
 1521:                                                             @inlineremote[63,61,71,72]);
 1522: 
 1523:                 $cstrcrumbs = &Apache::lonhtmlcommon::scripttag('', 'start')
 1524:                              .&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
 1525:                              .&Apache::lonhtmlcommon::scripttag('', 'end');
 1526:             }
 1527:             my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
 1528:             $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
 1529:             my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
 1530:             my $navstatus=&get_nav_status();
 1531:             my $clearcstr;
 1532: 
 1533:             if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
 1534:             return <<ENDREGTHIS;
 1535: 
 1536: <script type="text/javascript">
 1537: // <![CDATA[
 1538: // BEGIN LON-CAPA Internal
 1539: var swmenu=null;
 1540: 
 1541:     function LONCAPAreg() {
 1542:           swmenu=$reopen;
 1543:           swmenu.clearTimeout(swmenu.menucltim);
 1544:           $timesync
 1545:           $newmail
 1546:           $buttons
 1547:           swmenu.currentURL="$requri";
 1548:           swmenu.reloadURL=swmenu.currentURL+window.location.search;
 1549:           swmenu.currentSymb="$cursymb";
 1550:           swmenu.reloadSymb="$cursymb";
 1551:           swmenu.currentStale=0;
 1552:           $navstatus
 1553:           $hwkadd
 1554:           $editbutton
 1555:     }
 1556: 
 1557:     function LONCAPAstale() {
 1558:           swmenu=$reopen
 1559:           swmenu.currentStale=1;
 1560:           if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) {
 1561:              swmenu.switchbutton
 1562:              (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
 1563:           }
 1564:           swmenu.clearbut(7,2);
 1565:           swmenu.clearbut(7,3);
 1566:           swmenu.menucltim=swmenu.setTimeout(
 1567:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
 1568:  'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
 1569:                           2000);
 1570:       }
 1571: 
 1572: // END LON-CAPA Internal
 1573: // ]]>
 1574: </script>
 1575: 
 1576: $cstrcrumbs
 1577: ENDREGTHIS
 1578:         }
 1579:     } else {
 1580:        unless ($noremote) {
 1581: # Not registered, graphical
 1582:            return (<<ENDDONOTREGTHIS);
 1583: 
 1584: <script type="text/javascript">
 1585: // <![CDATA[
 1586: // BEGIN LON-CAPA Internal
 1587: var swmenu=null;
 1588: 
 1589:     function LONCAPAreg() {
 1590:           swmenu=$reopen
 1591:           $timesync
 1592:           swmenu.currentStale=1;
 1593:           swmenu.clearbut(2,1);
 1594:           swmenu.clearbut(2,3);
 1595:           swmenu.clearbut(8,1);
 1596:           swmenu.clearbut(8,2);
 1597:           swmenu.clearbut(8,3);
 1598:           swmenu.clearbut(9,1);
 1599:           if (swmenu.currentURL) {
 1600:              swmenu.switchbutton
 1601:               (3,1,'reload.gif','return','location','go(currentURL)');
 1602:           } else {
 1603:               swmenu.clearbut(3,1);
 1604:           }
 1605:     }
 1606: 
 1607:     function LONCAPAstale() {
 1608:     }
 1609: 
 1610: // END LON-CAPA Internal
 1611: // ]]>
 1612: </script>
 1613: ENDDONOTREGTHIS
 1614: 
 1615:         }
 1616:         return '';
 1617:     }
 1618: }
 1619: 
 1620: sub get_inline_text {
 1621:     my %text = (
 1622:                  pgrd     => 'Content Grades',
 1623:                  subm     => 'Content Submissions',
 1624:                  pparm    => 'Content Settings',
 1625:                  docs     => 'Folder/Page Content',
 1626:                  pcstr    => 'Edit',
 1627:                  prt      => 'Print',
 1628:                  alnk     => 'Stored Links',
 1629:                  anot     => 'Notes',
 1630:                  catalog  => 'Info',
 1631:                  eval     => 'Evaluate',
 1632:                  fdbk     => 'Feedback',
 1633:     );
 1634:     return %text;
 1635: }
 1636: 
 1637: sub get_rc_text {
 1638:     my %text = (
 1639:                    pgrd    => 'problem[_1]',
 1640:                    subm    => 'view sub-[_1]',
 1641:                    pparm   => 'problem[_2]',
 1642:                    pcstr   => 'edit[_1]',
 1643:                    prt     => 'prepare[_1]',
 1644:                    back    => 'backward[_1]',
 1645:                    forw    => 'forward[_1]',
 1646:                    alnk    => 'add to[_1]',
 1647:                    anot    => 'anno-[_1]',
 1648:                    catalog => 'catalog[_2]',
 1649:                    eval    => 'evaluate[_1]',
 1650:                    fdbk    => 'feedback[_1]',
 1651:     );
 1652:     return %text;
 1653: }
 1654: 
 1655: sub loadevents() {
 1656:     if ($env{'request.state'} eq 'construct' ||
 1657:         $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
 1658:     return 'LONCAPAreg();';
 1659: }
 1660: 
 1661: sub unloadevents() {
 1662:     if ($env{'request.state'} eq 'construct' ||
 1663:         $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
 1664:     return 'LONCAPAstale();';
 1665: }
 1666: 
 1667: sub startupremote {
 1668:     my ($lowerurl)=@_;
 1669:     unless ($env{'environment.remote'} eq 'on') {
 1670:         return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
 1671:     }
 1672: #
 1673: # The Remote actually gets launched!
 1674: #
 1675:     my $configmenu=&rawconfig();
 1676:     my $esclowerurl=&escape($lowerurl);
 1677:     my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
 1678:     return(<<ENDREMOTESTARTUP);
 1679: <script type="text/javascript">
 1680: // <![CDATA[
 1681: var timestart;
 1682: function wheelswitch() {
 1683:     if (typeof(document.wheel) != 'undefined') {
 1684:         if (typeof(document.wheel.spin) != 'undefined') {
 1685:             var date=new Date();
 1686:             var waited=Math.round(30-((date.getTime()-timestart)/1000));
 1687:             document.wheel.spin.value=$message;
 1688:         }
 1689:     }
 1690:    if (window.status=='|') {
 1691:       window.status='/';
 1692:    } else {
 1693:       if (window.status=='/') {
 1694:          window.status='-';
 1695:       } else {
 1696:          if (window.status=='-') {
 1697:             window.status='\\\\';
 1698:          } else {
 1699:             if (window.status=='\\\\') { window.status='|'; }
 1700:          }
 1701:       }
 1702:    }
 1703: }
 1704: 
 1705: // ---------------------------------------------------------- The wait function
 1706: var canceltim;
 1707: function wait() {
 1708:    if ((menuloaded==1) || (tim==1)) {
 1709:       window.status='Done.';
 1710:       if (tim==0) {
 1711:          clearTimeout(canceltim);
 1712:          $configmenu
 1713:          window.location='$lowerurl';
 1714:       } else {
 1715:           window.location='/adm/remote?action=collapse&url=$esclowerurl';
 1716:       }
 1717:    } else {
 1718:       wheelswitch();
 1719:       setTimeout('wait();',200);
 1720:    }
 1721: }
 1722: 
 1723: function main() {
 1724:    canceltim=setTimeout('tim=1;',30000);
 1725:    window.status='-';
 1726:    var date=new Date();
 1727:    timestart=date.getTime();
 1728:    wait();
 1729: }
 1730: 
 1731: // ]]>
 1732: </script>
 1733: ENDREMOTESTARTUP
 1734: }
 1735: 
 1736: sub setflags() {
 1737:     return(<<ENDSETFLAGS);
 1738: <script type="text/javascript">
 1739: // <![CDATA[
 1740:     menuloaded=0;
 1741:     tim=0;
 1742: // ]]>
 1743: </script>
 1744: ENDSETFLAGS
 1745: }
 1746: 
 1747: sub maincall() {
 1748:     unless ($env{'environment.remote'} eq 'on') { return ''; }
 1749:     return(<<ENDMAINCALL);
 1750: <script type="text/javascript">
 1751: // <![CDATA[
 1752:     main();
 1753: // ]]>
 1754: </script>
 1755: ENDMAINCALL
 1756: }
 1757: 
 1758: sub load_remote_msg {
 1759:     my ($lowerurl)=@_;
 1760: 
 1761:     unless ($env{'environment.remote'} eq 'on') { return ''; }
 1762: 
 1763:     my $esclowerurl=&escape($lowerurl);
 1764:     my $link=&mt('[_1]Continue[_2] on in Inline Menu mode'
 1765:                 ,'<a href="/adm/remote?action=collapse&amp;url='.$esclowerurl.'">'
 1766:                 ,'</a>');
 1767:     return(<<ENDREMOTEFORM);
 1768: <p>
 1769: <form name="wheel">
 1770: <input name="spin" type="text" size="60" />
 1771: </form>
 1772: </p>
 1773: <p>$link</p>
 1774: ENDREMOTEFORM
 1775: }
 1776: 
 1777: sub get_menu_name {
 1778:     my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
 1779:     $hostid =~ s/\W//g;
 1780:     return 'LCmenu'.$hostid;
 1781: }
 1782: 
 1783: 
 1784: sub reopenmenu {
 1785:    unless ($env{'environment.remote'} eq 'on') { return ''; }
 1786:    my $menuname = &get_menu_name();
 1787:    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
 1788:    return('window.open('.$nothing.',"'.$menuname.'","",false);');
 1789: }
 1790: 
 1791: 
 1792: sub open {
 1793:     my $returnval='';
 1794:     unless ($env{'environment.remote'} eq 'on') {
 1795:         return
 1796:         '<script type="text/javascript">'."\n"
 1797:        .'// <![CDATA['."\n"
 1798:        .'self.name="loncapaclient";'."\n"
 1799:        .'// ]]>'."\n"
 1800:        .'</script>';
 1801:     }
 1802:     my $menuname = &get_menu_name();
 1803: 
 1804: #    unless (shift eq 'unix') {
 1805: # resizing does not work on linux because of virtual desktop sizes
 1806: #       $returnval.=(<<ENDRESIZE);
 1807: #if (window.screen) {
 1808: #    self.resizeTo(screen.availWidth-215,screen.availHeight-55);
 1809: #    self.moveTo(190,15);
 1810: #}
 1811: #ENDRESIZE
 1812: #    }
 1813:     $returnval=(<<ENDOPEN);
 1814: // <![CDATA[
 1815: window.status='Opening LON-CAPA Remote Control';
 1816: var menu=window.open("/res/adm/pages/menu.html?inhibitmenu=yes","$menuname",
 1817: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
 1818: self.name='loncapaclient';
 1819: // ]]>
 1820: ENDOPEN
 1821:     return '<script type="text/javascript">'.$returnval.'</script>';
 1822: }
 1823: 
 1824: sub get_editbutton {
 1825:     my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg,$hostname) = @_;
 1826:     my $jscall;
 1827:     if (($forceview) && ($env{'form.todocs'})) {
 1828:         my ($folderpath,$command,$navmap);
 1829:         if ($env{'request.symb'}) {
 1830:             $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'},\$navmap);
 1831:         } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
 1832:             $folderpath = $env{'form.folderpath'};
 1833:             $command = '&forcesupplement=1';
 1834:         }
 1835:         $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
 1836:         $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
 1837:     } else {
 1838:         my $suppanchor;
 1839:         if ($env{'form.folderpath'}) {
 1840:             $suppanchor = $env{'form.anchor'};
 1841:         }
 1842:         my $shownsymb;
 1843:         if ($env{'request.symb'}) {
 1844:             $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
 1845:         }
 1846:         $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
 1847:                                                 $forceedit,$forcereg,$env{'request.symb'},$shownsymb,
 1848:                                                 &escape($env{'form.folderpath'}),
 1849:                                                 &escape($env{'form.title'}),$hostname,
 1850:                                                 $env{'form.idx'},&escape($env{'form.suppurl'}),
 1851:                                                 $env{'form.todocs'},$suppanchor);
 1852:     }
 1853:     if ($jscall) {
 1854:         my $icon = 'pcstr.png';
 1855:         my $label = 'Edit';
 1856:         if ($forceview) {
 1857:             $icon = 'tolastloc.png';
 1858:             $label = 'Exit Editing';
 1859:         }
 1860:         my $infunc = 1;
 1861:         my $clearbutton;
 1862:         if ($env{'environment.remote'} eq 'on') {
 1863:             if ($cfile =~ m{^/priv/}) {
 1864:                 undef($infunc);
 1865:                 $label = 'edit';
 1866:             } else {
 1867:                 $clearbutton = 1;
 1868:             }
 1869:         }
 1870:         my $editor = &switch('','',6,1,$icon,$label,'resource[_2]',
 1871:                              $jscall,"Edit this resource",'','',$infunc);
 1872:         if ($infunc) {
 1873:             return 1;
 1874:         } elsif ($clearbutton) {
 1875:             return &clear(6,1);
 1876:         } else {
 1877:             return $editor;
 1878:         }
 1879:     }
 1880:     return;
 1881: }
 1882: 
 1883: sub prepare_functions {
 1884:     my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs,$hostname,$forbodytag) = @_;
 1885:     unless ($env{'request.registered'}) {
 1886:         undef(@inlineremote);
 1887:     }
 1888:     my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
 1889:         $forceview);
 1890: 
 1891:     if ($env{'request.course.id'}) {
 1892:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 1893:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1894:         $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
 1895:     }
 1896: 
 1897:     my $editbutton = '';
 1898:     my $viewsrcbutton = '';
 1899:     my $clientip = &Apache::lonnet::get_requestor_ip();
 1900: #
 1901: # Determine whether or not to display 'Edit' or 'View Source' icon/button
 1902: #
 1903:     if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
 1904:         my $blocked = &Apache::loncommon::blocking_status('about',$clientip,$2,$1);
 1905:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
 1906:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1907:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
 1908:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
 1909:         if (($cfile) && ($home ne '') && ($home ne 'no_host') && (!$blocked)) {
 1910:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1911:                                           $forceedit,$forceview,$forcereg);
 1912:         }
 1913:     } elsif ((!$env{'request.course.id'}) &&
 1914:              ($env{'user.author'}) && ($env{'request.filename'}) &&
 1915:              ($env{'request.role'} !~/^(aa|ca|au)/)) {
 1916: #
 1917: # Currently do not have the role of author or co-author.
 1918: # Do we have authoring privileges for the resource?
 1919: #
 1920:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
 1921:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1922:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
 1923:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
 1924:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
 1925:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1926:                                           $forceedit,$forceview,$forcereg);
 1927:         }
 1928:     } elsif ($env{'request.course.id'}) {
 1929: #
 1930: # This applies in course context
 1931: #
 1932:         if (($perms{'mdc'}) &&
 1933:             (($resurl =~ m{^/?public/$cdom/$cnum/syllabus}) ||
 1934:             ($resurl =~ m{^/?uploaded/$cdom/$cnum/portfolio/syllabus/}) || 
 1935:             (($resurl =~ m{^/?uploaded/$cdom/$cnum/default_\d+\.sequence$}) && ($env{'form.navmap'})))) {
 1936:             if ($resurl =~ m{^/}) {
 1937:                 $cfile = $resurl;
 1938:             } else {
 1939:                 $cfile = "/$resurl";
 1940:             }
 1941:             $home = &Apache::lonnet::homeserver($cnum,$cdom);
 1942:             if ($env{'form.forceedit'}) {
 1943:                 $forceview = 1;
 1944:             } else {
 1945:                 $forceedit = 1;
 1946:             }
 1947:             if ($cfile =~ m{^/uploaded/$cdom/$cnum/default_\d+\.sequence$}) {
 1948:                 my $text = 'Edit Folder';
 1949:                 &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
 1950:                         "gocmd('/adm/coursedocs','direct')",
 1951:                         'Folder/Page Content');
 1952:                 $editbutton = 1;
 1953:             } else {
 1954:                 $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1955:                                               $forceedit,$forceview,$forcereg,
 1956:                                               $hostname);
 1957:             }
 1958:         } elsif (($resurl eq '/adm/extresedit') &&
 1959:                  (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
 1960:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1961:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
 1962:                                                $env{'form.symb'});
 1963:             if ($cfile ne '') {
 1964:                 $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1965:                                               $forceedit,$forceview,$forcereg,
 1966:                                               $env{'form.title'},$env{'form.suppurl'});
 1967:             }
 1968:         } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
 1969:                  (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
 1970:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1971:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
 1972:                                                $env{'form.symb'});
 1973:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1974:                                           $forceedit,$forceview,$forcereg);
 1975:         } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
 1976:                  ($resurl ne '/cgi-bin/printout.pl')) {
 1977:             if ($env{'request.filename'}) {
 1978:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
 1979:                 ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1980:                     &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
 1981:                         &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
 1982:                 if ($cfile ne '') {
 1983:                     $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1984:                                                   $forceedit,$forceview,$forcereg);
 1985:                 }
 1986:                 if ((($cfile eq '') || (!$editbutton)) &&
 1987:                     ($resurl =~ /$LONCAPA::assess_re/)) {
 1988:                     my $showurl = &Apache::lonnet::clutter($resurl);
 1989:                     my $crs_sec = $env{'request.course.id'} . (($env{'request.course.sec'} ne '')
 1990:                                                               ? "/$env{'request.course.sec'}"
 1991:                                                               : '');
 1992:                     if ((&Apache::lonnet::allowed('cre','/')) &&
 1993:                         (&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open')) {
 1994:                         $viewsrcbutton = 1;
 1995:                     } elsif (&Apache::lonnet::allowed('vxc',$crs_sec)) {
 1996:                         if ($showurl =~ m{^\Q/res/$cdom/\E($match_username)/}) {
 1997:                             my $auname = $1;
 1998:                             if (($env{'request.course.adhocsrcaccess'} ne '') &&
 1999:                                 (grep(/^\Q$auname\E$/,split(/,/,$env{'request.course.adhocsrcaccess'})))) {
 2000:                                 $viewsrcbutton = 1;
 2001:                             } elsif ((&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open') &&
 2002:                                      (&Apache::lonnet::allowed('bre',$crs_sec))) {
 2003:                                 $viewsrcbutton = 1;
 2004:                             }
 2005:                         }
 2006:                     }
 2007:                     if ($viewsrcbutton) {
 2008:                         &switch('','',6,1,'pcstr.png','View Source','resource[_2]','open_source()',
 2009:                                 'View source code');
 2010:                     }
 2011:                 }
 2012:             }
 2013:         }
 2014:     }
 2015: # End determination of 'Edit' icon/button display
 2016: 
 2017:     if ($env{'request.course.id'}) {
 2018: # This applies to about me page for users in a course
 2019:         if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
 2020:             my ($sdom,$sname) = ($1,$2);
 2021:             unless (&Apache::lonnet::is_course($sdom,$sname)) {
 2022:                 my $blocked = &Apache::loncommon::blocking_status('about',$clientip,$sname,$sdom);
 2023:                 unless ($blocked) {
 2024:                     &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
 2025:                             '',
 2026:                             "go('/adm/email?compose=individual&amp;recname=$sname&amp;recdom=$sdom')",
 2027:                                 'Send message to specific user','','',1);
 2028:                 }
 2029:             }
 2030:             my $hideprivileged = 1;
 2031:             if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
 2032:                                            $hideprivileged)) {
 2033:                 foreach my $priv ('vsa','vgr','srm') {
 2034:                     $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
 2035:                     if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
 2036:                         $perms{$priv} =
 2037:                             &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
 2038:                     }
 2039:                 }
 2040:                 if ($perms{'vsa'}) {
 2041:                     &switch('','',6,5,'trck-22x22.png','Activity',
 2042:                             '',
 2043:                             "go('/adm/trackstudent?selected_student=$sname:$sdom')",
 2044:                             'View recent activity by this person','','',1);
 2045:                 }
 2046:                 if ($perms{'vgr'}) {
 2047:                     &switch('','',6,6,'rsrv-22x22.png','Reservations',
 2048:                             '',
 2049:                             "go('/adm/slotrequest?command=showresv&amp;origin=aboutme&amp;uname=$sname&amp;udom=$sdom')",
 2050:                             'Slot reservation history','','',1);
 2051:                 }
 2052:                 if ($perms{'srm'}) {
 2053:                     &switch('','',6,7,'contact-new-22x22.png','Records',
 2054:                             '',
 2055:                             "go('/adm/email?recordftf=retrieve&amp;recname=$sname&amp;recdom=$sdom')",
 2056:                             'Add records','','',1);
 2057:                 }
 2058:             }
 2059:         }
 2060:         if (($env{'form.folderpath'} =~ /^supplemental/) &&
 2061:             (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
 2062:             (($resurl =~ m{^/adm/wrapper/ext/}) ||
 2063:              ($resurl =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) ||
 2064:              ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
 2065:              ($resurl eq '/adm/supplemental') ||
 2066:              ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
 2067:              ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
 2068:             my @folders=split('&',$env{'form.folderpath'});
 2069:             if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
 2070:                 my $suppanchor;
 2071:                 if ($resurl =~ m{^/adm/wrapper/ext/}) {
 2072:                     $suppanchor = $env{'form.anchor'};
 2073:                 }
 2074:                 my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
 2075:                 my $link = '/adm/coursedocs?command=direct&amp;forcesupplement=1&amp;supppath='.
 2076:                            "$esc_path&amp;anchor=$suppanchor";
 2077:                 if ($env{'request.use_absolute'} ne '') {
 2078:                     $link = $env{'request.use_absolute'}.$link;
 2079:                 }
 2080:                 &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
 2081:                         "location.href='$link'",'Folder/Page Content');
 2082:             }
 2083:         }
 2084:     }
 2085: 
 2086: # End checking for items for about me page for users in a course
 2087:     if ($docscrumbs) {
 2088:         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
 2089:         &advtools_crumbs(@inlineremote);
 2090:         return $editbutton;
 2091:     } elsif (($env{'request.registered'}) && (!ref($forbodytag))) {
 2092:         return $editbutton || $viewsrcbutton;
 2093:     } else {
 2094:         if (ref($bread_crumbs) eq 'ARRAY') {
 2095:             if (@inlineremote > 0) {
 2096:                 if (ref($advtools) eq 'ARRAY') {
 2097:                     @{$advtools} = @inlineremote;
 2098:                 }
 2099:             }
 2100:             return;
 2101:         } elsif (@inlineremote > 0) {
 2102:             &Apache::lonhtmlcommon::clear_breadcrumb_tools();
 2103:             &advtools_crumbs(@inlineremote);
 2104:             if (ref($forbodytag)) {
 2105:                 $$forbodytag =
 2106:                     &Apache::lonhtmlcommon::scripttag('', 'start')
 2107:                    .&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
 2108:                    .&Apache::lonhtmlcommon::scripttag('', 'end');
 2109:             }
 2110:             return;
 2111:         }
 2112:     }
 2113: }
 2114: 
 2115: sub advtools_crumbs {
 2116:     my @funcs = @_;
 2117:     if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
 2118:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 2119:             'advtools', @funcs[61,64,65,66,67,74]);
 2120:     } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
 2121:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 2122:             'advtools', @funcs[61,71,72,73,74,75,92]);
 2123:     } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
 2124:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 2125:             'advtools', $funcs[61]);
 2126:     }
 2127: }
 2128: 
 2129: # ================================================================== Raw Config
 2130: 
 2131: sub clear {
 2132:     my ($row,$col)=@_;
 2133:     if ($env{'environment.remote'} eq 'on') {
 2134:        if (($row<1) || ($row>13)) { return ''; }
 2135:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
 2136:     } else {
 2137:         $inlineremote[10*$row+$col]='';
 2138:         return '';
 2139:     }
 2140: }
 2141: 
 2142: # ============================================ Switch a button or create a link
 2143: # Switch acts on the javascript that is executed when a button is clicked.  
 2144: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
 2145: 
 2146: sub switch {
 2147:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak,$infunc,$form)=@_;
 2148:     $act=~s/\$uname/$uname/g;
 2149:     $act=~s/\$udom/$udom/g;
 2150:     $top=&mt($top);
 2151:     $bot=&mt($bot);
 2152:     $desc=&mt($desc);
 2153:     my $idx=10*$row+$col;
 2154:     $category_members{$cat}.=':'.$idx;
 2155: 
 2156:     if (($env{'environment.remote'} eq 'on') && (!$infunc)) {
 2157:         if (($row<1) || ($row>13)) { return ''; }
 2158:         if ($env{'request.state'} eq 'construct') {
 2159:             my $text = $top.' '.$bot;
 2160:             $text=~s/\s*\-\s*//gs;
 2161:             my $pic = '<img alt="'.$text.'" src="'.
 2162:                       &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
 2163:                       '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
 2164:            $inlineremote[$idx] =
 2165:                '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.
 2166:                $pic.'<span class="LC_menubuttons_inline_text">'.$top.'&nbsp;</span></a>';
 2167:         }
 2168: # Remote
 2169:         $img=~s/\.png$/\.gif/;
 2170:         return "\n".
 2171:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
 2172:     }
 2173: 
 2174: # Inline Menu
 2175:     if ($nobreak==2) { return ''; }
 2176:     my $text=$top.' '.$bot;
 2177:     $text=~s/\s*\-\s*//gs;
 2178: 
 2179:     my $pic=
 2180: 	   '<img alt="'.$text.'" src="'.
 2181: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
 2182: 	   '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
 2183:     if ($env{'browser.interface'} eq 'faketextual') {
 2184: # Main Menu
 2185: 	   if ($nobreak==3) {
 2186: 	       $inlineremote[$idx]="\n".
 2187: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
 2188: 		   '</td><td align="left">'.
 2189: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
 2190: 	   } elsif ($nobreak) {
 2191: 	       $inlineremote[$idx]="\n<tr>".
 2192: 		   '<td align="left">'.
 2193: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
 2194:                     <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>';
 2195: 	   } else {
 2196: 	       $inlineremote[$idx]="\n<tr>".
 2197: 		   '<td align="left">'.
 2198: 		   '<a href="javascript:'.$act.';">'.$pic.
 2199: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
 2200: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
 2201: 	   }
 2202:     } else {
 2203: # Inline Menu
 2204:         my @tools = (93,91,81,82,83);
 2205:         unless ($env{'request.state'} eq 'construct') {
 2206:             push(@tools,63);
 2207:         }
 2208:         if ((($env{'environment.icons'} eq 'iconsonly') ||
 2209:              ($env{'environment.icons'} eq '') && ($env{'request.lti.login'})) &&
 2210:             (grep(/^$idx$/,@tools))) {
 2211:             $inlineremote[$idx] =
 2212:         '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
 2213:         } else {
 2214:             $inlineremote[$idx] =
 2215:        '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
 2216:        '<span class="LC_menubuttons_inline_text">'.$top.'&nbsp;</span></a>'.$form;
 2217:         }
 2218:     }
 2219:     return '';
 2220: }
 2221: 
 2222: sub secondlevel {
 2223:     my $output='';
 2224:     my 
 2225:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
 2226:     if ($prt eq 'any') {
 2227: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 2228:     } elsif ($prt=~/^r(\w+)/) {
 2229:         if ($rol eq $1) {
 2230:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 2231:         }
 2232:     }
 2233:     return $output;
 2234: }
 2235: 
 2236: sub openmenu {
 2237:     my $menuname = &get_menu_name();
 2238:     unless ($env{'environment.remote'} eq 'on') { return ''; }
 2239:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
 2240:     return "window.open(".$nothing.",'".$menuname."');";
 2241: }
 2242: 
 2243: sub inlinemenu {
 2244:     undef(@inlineremote);
 2245:     undef(%category_members);
 2246: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
 2247:     &rawconfig(1);
 2248:     my $output='<table><tr>';
 2249:     for (my $col=1; $col<=2; $col++) {
 2250:         $output.='<td class="LC_mainmenu_col_fieldset">';
 2251:         for (my $row=1; $row<=8; $row++) {
 2252:             foreach my $cat (keys(%category_members)) {
 2253:                if ($category_positions{$cat} ne "$col,$row") { next; }
 2254:                #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
 2255:                $output.='<div class="LC_Box LC_400Box">';
 2256: 	       $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
 2257:                $output.='<table>';
 2258:                my %active=();
 2259:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
 2260:                   if ($inlineremote[$menu_item]) {
 2261:                      $active{$menu_item}=1;
 2262:                   }
 2263:                }  
 2264:                foreach my $item (sort(keys(%active))) {
 2265:                   $output.=$inlineremote[$item];
 2266:                }
 2267:                $output.='</table>';
 2268:                $output.='</div>';
 2269:             }
 2270:          }
 2271:          $output.="</td>";
 2272:     }
 2273:     $output.="</tr></table>";
 2274:     return $output;
 2275: }
 2276: 
 2277: sub rawconfig {
 2278: #
 2279: # This evaluates mydesk.tab
 2280: # Need to add more positions and more privileges to deal with all
 2281: # menu items.
 2282: #
 2283:     my $textualoverride=shift;
 2284:     my $output='';
 2285:     if ($env{'environment.remote'} eq 'on') {
 2286:        $output.=
 2287:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
 2288: "\nwindow.status='Configuring Remote Control ';";
 2289:     } else {
 2290:         unless ($textualoverride) { return ''; }
 2291:     }
 2292:     my $uname=$env{'user.name'};
 2293:     my $udom=$env{'user.domain'};
 2294:     my $adv=$env{'user.adv'};
 2295:     my $show_course=&Apache::loncommon::show_course();
 2296:     my $author=$env{'user.author'};
 2297:     my $crs='';
 2298:     my $crstype='';
 2299:     if ($env{'request.course.id'}) {
 2300:        $crs='/'.$env{'request.course.id'};
 2301:        if ($env{'request.course.sec'}) {
 2302: 	   $crs.='_'.$env{'request.course.sec'};
 2303:        }
 2304:        $crs=~s/\_/\//g;
 2305:        $crstype = &Apache::loncommon::course_type();
 2306:     }
 2307:     my $pub=($env{'request.state'} eq 'published');
 2308:     my $con=($env{'request.state'} eq 'construct');
 2309:     my $rol=$env{'request.role'};
 2310:     my $requested_domain;
 2311:     if ($rol) {
 2312:        $requested_domain = $env{'request.role.domain'};
 2313:     }
 2314:     foreach my $line (@desklines) {
 2315:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
 2316:         $prt=~s/\$uname/$uname/g;
 2317:         $prt=~s/\$udom/$udom/g;
 2318:         if ($prt =~ /\$crs/) {
 2319:             next unless ($env{'request.course.id'});
 2320:             next if ($crstype eq 'Community');
 2321:             $prt=~s/\$crs/$crs/g;
 2322:         } elsif ($prt =~ /\$cmty/) {
 2323:             next unless ($env{'request.course.id'});
 2324:             next if ($crstype ne 'Community');
 2325:             $prt=~s/\$cmty/$crs/g;
 2326:         }
 2327:         if ($prt =~ m/\$requested_domain/) {
 2328:             if ((!$requested_domain) && ($pro eq 'pbre') && ($env{'user.adv'})) {
 2329:                 $prt=~s/\$requested_domain/$env{'user.domain'}/g;
 2330:             } else {
 2331:                 $prt=~s/\$requested_domain/$requested_domain/g;
 2332:             }
 2333:         }
 2334:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
 2335:         if ($pro eq 'clear') {
 2336: 	    $output.=&clear($row,$col);
 2337:         } elsif ($pro eq 'any') {
 2338:                $output.=&secondlevel(
 2339: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 2340: 	} elsif ($pro eq 'smp') {
 2341:             unless ($adv) {
 2342:                $output.=&secondlevel(
 2343:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 2344:             }
 2345:         } elsif ($pro eq 'adv') {
 2346:             if ($adv) {
 2347:                $output.=&secondlevel(
 2348: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 2349:             }
 2350: 	} elsif ($pro eq 'shc') {
 2351:             if ($show_course) {
 2352:                $output.=&secondlevel(
 2353:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 2354:             }
 2355:         } elsif ($pro eq 'nsc') {
 2356:             if (!$show_course) {
 2357:                $output.=&secondlevel(
 2358: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 2359:             }
 2360:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
 2361:             my $priv = $1;
 2362:             if ($priv =~ /^mdc(Course|Community)/) {
 2363:                 if ($crstype eq $1) {
 2364:                     $priv = 'mdc';
 2365:                 } else {
 2366:                     next;
 2367:                 }
 2368:             }
 2369:             if ((($priv eq 'bre') && (&Apache::lonnet::allowed($priv,$prt) eq 'F')) ||
 2370:                 (($priv ne 'bre') && (&Apache::lonnet::allowed($priv,$prt)))) {
 2371:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 2372:             }
 2373:         } elsif ($pro eq 'course')  {
 2374:             if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
 2375:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 2376: 	    }
 2377:         } elsif ($pro eq 'community')  {
 2378:             if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
 2379:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 2380:             }
 2381:         } elsif ($pro =~ /^courseenv_(.*)$/) {
 2382:             my $key = $1;
 2383:             if ($crstype ne 'Community') {
 2384:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
 2385:                 if ($key eq 'canuse_pdfforms') {
 2386:                     if ($env{'request.course.id'} && $coursepref eq '') {
 2387:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
 2388:                         $coursepref = $domdefs{'canuse_pdfforms'};
 2389:                     }
 2390:                 }
 2391:                 if ($coursepref) { 
 2392:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 2393:                 }
 2394:             }
 2395:         } elsif ($pro =~ /^communityenv_(.*)$/) {
 2396:             my $key = $1;
 2397:             if ($crstype eq 'Community') {
 2398:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
 2399:                 if ($key eq 'canuse_pdfforms') {
 2400:                     if ($env{'request.course.id'} && $coursepref eq '') {
 2401:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
 2402:                         $coursepref = $domdefs{'canuse_pdfforms'};
 2403:                     }
 2404:                 }
 2405:                 if ($coursepref) { 
 2406:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 2407:                 }
 2408:             }
 2409:         } elsif ($pro =~ /^course_(.*)$/) {
 2410:             # Check for permissions inside of a course
 2411:             if (($env{'request.course.id'}) && ($crstype ne 'Community') && 
 2412:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 2413:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 2414:                  )) {
 2415:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 2416: 	    }
 2417:         } elsif ($pro =~ /^community_(.*)$/) {
 2418:             # Check for permissions inside of a community
 2419:             if (($env{'request.course.id'}) && ($crstype eq 'Community') &&   
 2420:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 2421:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 2422:                  )) {
 2423:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 2424:             }
 2425:         } elsif ($pro eq 'author') {
 2426:             if ($author) {
 2427:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
 2428:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
 2429:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
 2430:                     # Check that we are on the correct machine
 2431:                     my $cadom=$requested_domain;
 2432:                     my $caname=$env{'user.name'};
 2433:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
 2434: 		       ($cadom,$caname)=
 2435:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
 2436:                     }                       
 2437:                     $act =~ s/\$caname/$caname/g;
 2438:                     $act =~ s/\$cadom/$cadom/g;
 2439:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
 2440: 		    my $allowed=0;
 2441: 		    my @ids=&Apache::lonnet::current_machine_ids();
 2442: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 2443: 		    if ($allowed) {
 2444:                         $output.=&switch($caname,$cadom,
 2445:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
 2446:                     }
 2447:                 }
 2448:             }
 2449:         } elsif ($pro eq 'tools') {
 2450:             my @tools = ('aboutme','blog','portfolio');
 2451:             if (grep(/^\Q$prt\E$/,@tools)) {
 2452:                 if (!&Apache::lonnet::usertools_access($env{'user.name'},
 2453:                                                        $env{'user.domain'},
 2454:                                                        $prt,undef,'tools')) {
 2455:                     $output.=&clear($row,$col);
 2456:                     next;
 2457:                 }
 2458:             } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
 2459:                 if (($prt eq 'reqcrsnsc') && ($show_course))   {
 2460:                     next;
 2461:                 }
 2462:                 if (($prt eq 'reqcrsshc') && (!$show_course)) {
 2463:                     next;
 2464:                 }
 2465:                 my $showreqcrs = &check_for_rcrs();
 2466:                 if (!$showreqcrs) {
 2467:                     $output.=&clear($row,$col);
 2468:                     next;
 2469:                 }
 2470:             }
 2471:             $prt='any';
 2472:             $output.=&secondlevel(
 2473:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 2474:         }
 2475:     }
 2476:     if ($env{'environment.remote'} eq 'on') {
 2477:         $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
 2478:         if (&Apache::lonmsg::newmail()) {
 2479:             $output.='swmenu.setstatus("you have","messages");';
 2480:         }
 2481:     }
 2482:     return $output;
 2483: }
 2484: 
 2485: sub check_for_rcrs {
 2486:     my $showreqcrs = 0;
 2487:     my @reqtypes = ('official','unofficial','community','textbook');
 2488:     foreach my $type (@reqtypes) {
 2489:         if (&Apache::lonnet::usertools_access($env{'user.name'},
 2490:                                               $env{'user.domain'},
 2491:                                               $type,undef,'requestcourses')) {
 2492:             $showreqcrs = 1;
 2493:             last;
 2494:         }
 2495:     }
 2496:     if (!$showreqcrs) {
 2497:         foreach my $type (@reqtypes) {
 2498:             if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
 2499:                 $showreqcrs = 1;
 2500:                 last;
 2501:             }
 2502:         }
 2503:     }
 2504:     return $showreqcrs;
 2505: }
 2506: 
 2507: # ======================================================================= Close
 2508: 
 2509: sub close {
 2510:     unless ($env{'environment.remote'} eq 'on') { return ''; }
 2511:     my $menuname = &get_menu_name();
 2512:     return(<<ENDCLOSE);
 2513: <script type="text/javascript">
 2514: // <![CDATA[
 2515: window.status='Accessing Remote Control';
 2516: menu=window.open("/adm/rat/empty.html","$menuname",
 2517:                  "height=350,width=150,scrollbars=no,menubar=no");
 2518: window.status='Disabling Remote Control';
 2519: menu.active=0;
 2520: menu.autologout=0;
 2521: window.status='Closing Remote Control';
 2522: menu.close();
 2523: window.status='Done.';
 2524: // ]]>
 2525: </script>
 2526: ENDCLOSE
 2527: }
 2528: 
 2529: sub dc_popup_js {
 2530:     my %lt = &Apache::lonlocal::texthash(
 2531:                                           more => '(More ...)',
 2532:                                           less => '(Less ...)',
 2533:                                         );
 2534:     return <<"END";
 2535: 
 2536: function showCourseID() {
 2537:     document.getElementById('dccid').style.display='block';
 2538:     document.getElementById('dccid').style.textAlign='left';
 2539:     document.getElementById('dccid').style.textFace='normal';
 2540:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
 2541:     return;
 2542: }
 2543: 
 2544: function hideCourseID() {
 2545:     document.getElementById('dccid').style.display='none';
 2546:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
 2547:     return;
 2548: }
 2549: 
 2550: END
 2551: 
 2552: }
 2553: 
 2554: sub countdown_toggle_js {
 2555:     return <<"END";
 2556: 
 2557: function toggleCountdown() {
 2558:     var countdownid = document.getElementById('duedatecountdown');
 2559:     var currstyle = countdownid.style.display;
 2560:     if (currstyle == 'inline') {
 2561:         countdownid.style.display = 'none';
 2562:         document.getElementById('ddcountcollapse').innerHTML='';
 2563:         document.getElementById('ddcountexpand').innerHTML='&#9668;&nbsp;';
 2564:     } else {
 2565:         countdownid.style.display = 'inline';
 2566:         document.getElementById('ddcountcollapse').innerHTML='&#9658;&nbsp;';
 2567:         document.getElementById('ddcountexpand').innerHTML='';
 2568:     }
 2569:     return;
 2570: }
 2571: 
 2572: END
 2573: }
 2574: 
 2575: # This creates a "done button" for timed events.  The confirmation box is a jQuery
 2576: # dialog widget. If the interval parameter requires a proctor key for the timed
 2577: # event to be marked done, there will also be a textbox where that can be entered.
 2578: # Clicking OK will set the value of LC_interval_done to 'true', and, if needed will
 2579: # set the value of LC_interval_done_proctorpass to the text entered in that box,
 2580: # and submit the corresponding form.
 2581: #
 2582: # The &zero_time() routine in lonhomework.pm is called when a page is rendered if
 2583: # LC_interval_done is true.
 2584: #
 2585: sub done_button_js {
 2586:     my ($type,$width,$height,$proctor,$donebuttontext) = @_;
 2587:     return unless (($type eq 'map') || ($type eq 'resource'));
 2588:     my %lt = &Apache::lonlocal::texthash(
 2589:                  title    => 'WARNING!',
 2590:                  preamble => 'You are trying to end this timed event early.',
 2591:                  map      => 'Confirming that you are done will cause the time to expire and prevent you from changing any answers in the current folder.',
 2592:                  resource => 'Confirming that you are done will cause the time to expire for this question, and prevent you from changing your answer(s).',
 2593:                  okdone   => 'Click "OK" if you are completely finished.',
 2594:                  cancel   => 'Click "Cancel" to continue working.',
 2595:                  proctor  => 'Ask a proctor to enter the key, then click "OK" if you are completely finished.',
 2596:                  ok       => 'OK',
 2597:                  exit     => 'Cancel',
 2598:                  key      => 'Key:',
 2599:                  nokey    => 'A proctor key is required',
 2600:     );
 2601:     my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}));
 2602:     my $navmap = Apache::lonnavmaps::navmap->new();
 2603:     my ($missing,$tried) = (0,0);
 2604:     if (ref($navmap)) {
 2605:         my @resources=();
 2606:         if ($type eq 'map') {
 2607:             my ($mapurl,$rid,$resurl)=&Apache::lonnet::decode_symb($env{'request.symb'});
 2608:             if ($env{'request.symb'} =~ /\.page$/) {
 2609:                 @resources=$navmap->retrieveResources($resurl,sub { $_[0]->is_problem() });
 2610:             } else {
 2611:                 @resources=$navmap->retrieveResources($mapurl,sub { $_[0]->is_problem() });
 2612:             }
 2613:         } else {
 2614:             my $res = $navmap->getBySymb($env{'request.symb'});
 2615:             if (ref($res)) {
 2616:                 if ($res->is_problem()) {
 2617:                     push(@resources,$res);
 2618:                 }
 2619:             }
 2620:         }
 2621:         foreach my $res (@resources) {
 2622:             if (ref($res->parts()) eq 'ARRAY') {
 2623:                 foreach my $part (@{$res->parts()}) {
 2624:                     if (!$res->tries($part)) {
 2625:                         $missing++;
 2626:                     } else {
 2627:                         $tried++;
 2628:                     }
 2629:                 }
 2630:             }
 2631:         }
 2632:     }
 2633:     if ($missing) {
 2634:         $lt{'miss'} .= '<p class="LC_error">';
 2635:         if ($type eq 'map') {
 2636:             $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,question part,question parts] in this folder.',$missing);
 2637:         } else {
 2638:             $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,part] in this question.',$missing);
 2639:         }
 2640:         if ($missing > 1) {
 2641:             $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit answers for them.').'</span>';
 2642:         } else {
 2643:             $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit an answer for it.').'</p>';
 2644:         }
 2645:     }
 2646:     $donebuttontext = &HTML::Entities::encode($donebuttontext,'<>&"');
 2647:     if ($proctor) {
 2648:         if ($height !~ /^\d+$/) {
 2649:             $height = 400;
 2650:             if ($missing) {
 2651:                 $height += 60;
 2652:             }
 2653:         }
 2654:         if ($width !~ /^\d+$/) {
 2655:             $width = 400;
 2656:             if ($missing) {
 2657:                 $width += 60;
 2658:             }
 2659:         }
 2660:         return <<END;
 2661: <form method="post" name="LCdoneButton" action="">
 2662:     <input type="hidden" name="LC_interval_done" value="" />
 2663:     <input type="hidden" name="LC_interval_done_proctorpass" value="" />
 2664:     <input type="hidden" name="symb" value="$shownsymb" />
 2665:     <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
 2666: </form>
 2667: 
 2668: <div id="LC_done-confirm" title="$lt{'title'}">
 2669:   <p>$lt{'preamble'} $lt{$type}</p>
 2670:   $lt{'miss'}
 2671:   <p>$lt{'proctor'}</p>
 2672:   <form name="LCdoneButtonProctor" action="">
 2673:     <label>$lt{'key'}<input type="password" name="LC_interval_done_proctorkey" value="" /></label>
 2674:     <input type="submit" tabindex="-1" style="position:absolute; top:-1000px" />
 2675:   </form>
 2676:   <p>$lt{'cancel'}</p>
 2677: </div>
 2678: 
 2679: <script type="text/javascript">
 2680: // <![CDATA[
 2681:     \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
 2682:     \$( "#LC_done-confirm-opener" ).on("click", function() {
 2683:         \$( "#LC_done-confirm" ).dialog("open");
 2684:         \$( "#LC_done-confirm" ).dialog({
 2685:             height: $height,
 2686:             width: $width,
 2687:             modal: true,
 2688:             resizable: false,
 2689:             buttons: [
 2690:                 {
 2691:                     text: "$lt{'ok'}",
 2692:                     click: function() {
 2693:                         var proctorkey = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
 2694:                         if ((proctorkey == '') || (proctorkey == null)) {
 2695:                             alert("$lt{'nokey'}");
 2696:                         } else {
 2697:                             \$( '[name="LC_interval_done"]' )[0].value = 'true';
 2698:                             \$( '[name="LC_interval_done_proctorpass"]' )[0].value = proctorkey;
 2699:                             \$( '[name="LCdoneButton"]' )[0].submit();
 2700:                         }
 2701:                     },
 2702:                 },
 2703:                 {
 2704:                     text: "$lt{'exit'}",
 2705:                     click: function() {
 2706:                         \$("#LC_done-confirm").dialog( "close" );
 2707:                     }
 2708:                 }
 2709:             ],
 2710:             close: function() {
 2711:                 \$( '[name="LC_interval_done_proctorkey"]' )[0].value = '';
 2712:             }
 2713:         });
 2714:         \$( "#LC_done-confirm" ).find( "form" ).on( "submit", function( event ) {
 2715:             event.preventDefault();
 2716:             \$( '[name="LC_interval_done"]' )[0].value = 'true';
 2717:             \$( '[name="LC_interval_done_proctorpass"]' )[0].value = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
 2718:             \$( '[name="LCdoneButton"]' )[0].submit();
 2719:         });
 2720: });
 2721: 
 2722: // ]]>
 2723: </script>
 2724: 
 2725: END
 2726:     } else {
 2727:         if ($height !~ /^\d+$/) {
 2728:             $height = 320;
 2729:             if ($missing) {
 2730:                 $height += 60;
 2731:             }
 2732:         }
 2733:         if ($width !~ /^\d+$/) {
 2734:             $width = 320;
 2735:             if ($missing) {
 2736:                 $width += 60;
 2737:             }
 2738:         }
 2739:         if ($missing) {
 2740:             $lt{'miss'} = '</p>'.$lt{'miss'}.'<p>';
 2741:         }
 2742:         return <<END;
 2743: 
 2744: <form method="post" name="LCdoneButton" action="">
 2745:     <input type="hidden" name="LC_interval_done" value="" />
 2746:     <input type="hidden" name="symb" value="$shownsymb" />
 2747:     <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
 2748: </form>
 2749: 
 2750: <div id="LC_done-confirm" title="$lt{'title'}">
 2751:     <p>$lt{'preamble'} $lt{$type} $lt{'miss'} $lt{'okdone'} $lt{'cancel'}</p>
 2752: </div>
 2753: 
 2754: <script type="text/javascript">
 2755: // <![CDATA[
 2756: \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
 2757: \$( "#LC_done-confirm-opener" ).click(function() {
 2758:     \$( "#LC_done-confirm" ).dialog( "open" );
 2759:     \$( "#LC_done-confirm" ).dialog({
 2760:       resizable: false,
 2761:       height: $height,
 2762:       width: $width,
 2763:       modal: true,
 2764:       buttons: [
 2765:                  {
 2766:                     text: "$lt{'ok'}",
 2767:                     click: function() {
 2768:                         \$( this ).dialog( "close" );
 2769:                         \$( '[name="LC_interval_done"]' )[0].value = 'true';
 2770:                         \$( '[name="LCdoneButton"]' )[0].submit();
 2771:                     },
 2772:                  },
 2773:                  {
 2774:                      text: "$lt{'exit'}",
 2775:                      click: function() {
 2776:                          \$( this ).dialog( "close" );
 2777:                      },
 2778:                   },
 2779:                ],
 2780:        });
 2781: });
 2782: // ]]>
 2783: </script>
 2784: 
 2785: END
 2786:     }
 2787: }
 2788: 
 2789: sub view_as_js {
 2790:     my ($url,$symb) = @_;
 2791:     my %lt = &Apache::lonlocal::texthash(
 2792:                 ente => 'Enter a username or a student/employee ID',
 2793:                 info => 'Information you entered does not match a valid course user',
 2794:     );
 2795:     &js_escape(\%lt);
 2796:     return <<"END";
 2797: 
 2798: function toggleViewAsUser(change) {
 2799:     if (document.getElementById('LC_selectuser')) {
 2800:         var seluserid = document.getElementById('LC_selectuser');
 2801:         var currstyle = seluserid.style.display;
 2802:         if (change == 'off') {
 2803:             document.userview.elements['LC_viewas'].value = '';
 2804:             document.userview.elements['vuname'].value = '';
 2805:             document.userview.elements['vid'].value = '';
 2806:             document.userview.submit();
 2807:             return;
 2808:         }
 2809:         if ((document.getElementById('usexpand')) && (document.getElementById('uscollapse'))) {
 2810:             if (currstyle == 'inline') {
 2811:                 seluserid.style.display = 'none';
 2812:                 document.getElementById('usexpand').innerHTML='&#9658;&nbsp;';
 2813:                 document.getElementById('uscollapse').innerHTML='';
 2814:             } else {
 2815:                 seluserid.style.display = 'inline';
 2816:                 document.getElementById('usexpand').innerHTML='';
 2817:                 document.getElementById('uscollapse').innerHTML='&#9668;&nbsp;';
 2818:                 toggleIdentifier(document.userview);
 2819:             }
 2820:         }
 2821:     }
 2822:     return;
 2823: }
 2824: 
 2825: function validCourseUser(form,change) {
 2826:     var possuname = form.elements['vuname'].value;
 2827:     var possuid = form.elements['vid'].value;
 2828:     var domelem = form.elements['vudom'];
 2829:     var possudom = '';
 2830:     if ((domelem.tagName === 'INPUT') && ((domelem.type === 'text') || (domelem.type === 'hidden'))) {
 2831:         possudom = domelem.value;
 2832:     } else if (domelem.tagName === 'SELECT') {
 2833:         possudom = domelem.options[domelem.selectedIndex].value;
 2834:     }
 2835:     if ((possuname == '') && (possuid == '')) {
 2836:         if (change == 'off') {
 2837:             form.elements['LC_viewas'].value = '';
 2838:             form.submit();
 2839:         } else {
 2840:             alert("$lt{'ente'}");
 2841:         }
 2842:         return;
 2843:     }
 2844:     var http = new XMLHttpRequest();
 2845:     var url = "/adm/courseuser";
 2846:     var params = "uname="+possuname+"&uid="+possuid+"&udom="+possudom;
 2847:     http.open("POST", url, true);
 2848:     http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 2849:     http.onreadystatechange = function() {
 2850:         if (http.readyState == 4 && http.status == 200) {
 2851:             var data = JSON.parse(http.responseText);
 2852:             if (Array.isArray(data.match)) {
 2853:                var len = data.match.length;
 2854:                if (len == 2) {
 2855:                    if (data.match[0] != '' && data.match[1] != '') {
 2856:                        form.elements['LC_viewas'].value = data.match[0]+':'+data.match[1];
 2857:                        form.submit();
 2858:                    }
 2859:                } else {
 2860:                    alert("$lt{'info'}");
 2861:                }
 2862:             }
 2863:         }
 2864:         return;
 2865:     }
 2866:     http.send(params);
 2867:     return false;
 2868: }
 2869: 
 2870: function toggleIdentifier(form) {
 2871:     if ((document.getElementById('LC_vuname')) && (document.getElementById('LC_vid'))) {
 2872:         var radioelem = form.elements['vuidentifier'];
 2873:         if (radioelem.length > 0) {
 2874:             var i;
 2875:             for (i=0; i<radioelem.length; i++) {
 2876:                 if (radioelem[i].checked == true) {
 2877:                     if (radioelem[i].value == 'uname') {
 2878:                         document.getElementById('LC_vuname').type = 'text';
 2879:                         document.getElementById('LC_vid').type = 'hidden';
 2880:                         document.getElementById('LC_vid').value = '';
 2881:                     } else {
 2882:                         document.getElementById('LC_vuname').type = 'hidden';
 2883:                         document.getElementById('LC_vuname').value = '';
 2884:                         document.getElementById('LC_vid').type = 'text';
 2885:                     }
 2886:                     break;
 2887:                 }
 2888:             }
 2889:         }
 2890:     }
 2891:     return;
 2892: }
 2893: 
 2894: END
 2895: }
 2896: 
 2897: sub utilityfunctions {
 2898:     my ($httphost) = @_;
 2899:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
 2900:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
 2901:     if ($currenturl =~ m{^/adm/wrapper/ext/}) {
 2902:         if ($env{'request.external.querystring'}) {
 2903:             $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
 2904:         }
 2905:         my ($anchor) = ($env{'request.symb'} =~ /(\#[^\#]+)$/);
 2906:         if (($anchor) && ($currenturl !~ /\Q$anchor\E$/)) {
 2907:             $currenturl .= $1;
 2908:         }
 2909:     }
 2910:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
 2911:     
 2912:     my $dc_popup_cid;
 2913:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
 2914:                         $env{'course.'.$env{'request.course.id'}.
 2915:                                  '.domain'}.'/'})) {
 2916:         $dc_popup_cid = &dc_popup_js();
 2917:     }
 2918: 
 2919:     my $start_page_annotate = 
 2920:         &Apache::loncommon::start_page('Annotator',undef,
 2921: 				       {'only_body' => 1,
 2922: 					'js_ready'  => 1,
 2923: 					'bgcolor'   => '#BBBBBB',
 2924: 					'add_entries' => {
 2925: 					    'onload' => 'javascript:document.goannotate.submit();'}});
 2926: 
 2927:     my $end_page_annotate = 
 2928:         &Apache::loncommon::end_page({'js_ready' => 1});
 2929: 
 2930:     my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
 2931: 
 2932:     my $esc_url=&escape($currenturl);
 2933:     my $esc_symb=&escape($currentsymb);
 2934: 
 2935:     my $countdown = &countdown_toggle_js();
 2936: 
 2937:     my $viewuser;
 2938:     if (($env{'request.course.id'}) &&
 2939:         ($env{'request.symb'} ne '') &&
 2940:         ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
 2941:         my $canview;
 2942:         foreach my $priv ('msg','vgr') {
 2943:             $canview = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
 2944:             if (!$canview && $env{'request.course.sec'} ne '') {
 2945:                 $canview =
 2946:                     &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
 2947:             }
 2948:             last if ($canview);
 2949:         }
 2950:         if ($canview) {
 2951:             $viewuser = &view_as_js($esc_url,$esc_symb);
 2952:         }
 2953:     }
 2954: 
 2955:     my ($ltitarget,$deeplinktarget);
 2956:     if ($env{'request.lti.login'}) {
 2957:         $ltitarget = $env{'request.lti.target'};
 2958:     }
 2959:     if ($env{'request.deeplink.login'}) {
 2960:         $deeplinktarget = $env{'request.deeplink.target'};
 2961:     }
 2962: 
 2963:     my $annotateurl = '/adm/annotation';
 2964:     if ($httphost) {
 2965:         $annotateurl = '/adm/annotations';
 2966:     }
 2967:     my $hostvar = '
 2968: function setLCHost() {
 2969:     var lcHostname="";
 2970: ';
 2971:     if ($httphost =~ m{^https?\://}) {
 2972:         $hostvar .= '    var lcServer="'.$httphost.'";'."\n".
 2973:                     '    var hostReg = /^https?:\/\/([^\/]+)$/i;'."\n".
 2974:                     '    var match = hostReg.exec(lcServer);'."\n".
 2975:                     '    if (match.length) {'."\n".
 2976:                     '        if (match[1] == location.hostname) {'."\n".
 2977:                     '            lcHostname=lcServer;'."\n".
 2978:                     '        }'."\n".
 2979:                     '    }'."\n";
 2980:     }
 2981: 
 2982:     $hostvar .= '    return lcHostname;'."\n".
 2983: '}'."\n";
 2984: 
 2985: return (<<ENDUTILITY)
 2986:     $hostvar
 2987:     var currentURL=unescape("$esc_url");
 2988:     var reloadURL=unescape("$esc_url");
 2989:     var currentSymb=unescape("$esc_symb");
 2990: 
 2991: $dc_popup_cid
 2992: 
 2993: $jumptores
 2994: 
 2995: function gopost(url,postdata) {
 2996:    if (url!='') {
 2997:       var lcHostname = setLCHost();
 2998:       this.document.server.action=lcHostname+url;
 2999:       this.document.server.postdata.value=postdata;
 3000:       this.document.server.command.value='';
 3001:       this.document.server.url.value='';
 3002:       this.document.server.symb.value='';
 3003:       this.document.server.submit();
 3004:    }
 3005: }
 3006: 
 3007: function gocmd(url,cmd) {
 3008:    if (url!='') {
 3009:       var lcHostname = setLCHost();
 3010:       this.document.server.action=lcHostname+url;
 3011:       this.document.server.postdata.value='';
 3012:       this.document.server.command.value=cmd;
 3013:       this.document.server.url.value=currentURL;
 3014:       this.document.server.symb.value=currentSymb;
 3015:       this.document.server.submit();
 3016:    }
 3017: }
 3018: 
 3019: function gocstr(url,filename) {
 3020:     if (url == '/adm/cfile?action=delete') {
 3021:         this.document.cstrdelete.filename.value = filename
 3022:         this.document.cstrdelete.submit();
 3023:         return;
 3024:     }
 3025:     if (url == '/adm/printout') {
 3026:         this.document.cstrprint.postdata.value = filename
 3027:         this.document.cstrprint.curseed.value = 0;
 3028:         this.document.cstrprint.problemtype.value = 0;
 3029:         if (this.document.lonhomework) {
 3030:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
 3031:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
 3032:             }
 3033:             if (this.document.lonhomework.problemtype) {
 3034: 		if (this.document.lonhomework.problemtype.value) {
 3035: 		    this.document.cstrprint.problemtype.value = 
 3036: 			this.document.lonhomework.problemtype.value;
 3037: 		} else if (this.document.lonhomework.problemtype.options) {
 3038: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
 3039: 			if (this.document.lonhomework.problemtype.options[i].selected) {
 3040: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
 3041: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
 3042: 				}
 3043: 			}
 3044: 		    }
 3045: 		}
 3046: 	    }
 3047: 	}
 3048:         this.document.cstrprint.submit();
 3049:         return;
 3050:     }
 3051:     if (url !='') {
 3052:         this.document.constspace.filename.value = filename;
 3053:         this.document.constspace.action = url;
 3054:         this.document.constspace.submit();
 3055:     }
 3056: }
 3057: 
 3058: function golist(url) {
 3059:    if (url!='' && url!= null) {
 3060:        currentURL = null;
 3061:        currentSymb= null;
 3062:        var lcHostname = setLCHost();
 3063:        var ltitarget = '$ltitarget';
 3064:        var deeplinktarget = '$deeplinktarget';
 3065:        if ((ltitarget == 'iframe') || (deeplinktarget == '_self')) {
 3066:            document.location.href=lcHostname+url;
 3067:        } else {
 3068:            top.location.href=lcHostname+url;
 3069:        }
 3070:    }
 3071: }
 3072: 
 3073: 
 3074: 
 3075: function catalog_info(url,isMobile) {
 3076:     if (isMobile == 1) {
 3077:         openMyModal(url+'.meta?modal=1',500,400,'yes');
 3078:     } else {
 3079:         loncatinfo=window.open(url+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
 3080:     }
 3081: }
 3082: 
 3083: function chat_win() {
 3084:    var lcHostname = setLCHost();
 3085:    lonchat=window.open(lcHostname+'/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
 3086: }
 3087: 
 3088: function group_chat(group) {
 3089:    var lcHostname = setLCHost();
 3090:    var url = lcHostname+'/adm/groupchat?group='+group;
 3091:    var winName = 'LONchat_'+group;
 3092:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 3093: }
 3094: 
 3095: function annotate() {
 3096:    w_Annotator_flag=1;
 3097:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
 3098:    annotator.document.write(
 3099:    '$start_page_annotate'
 3100:   +"<form name='goannotate' target='Annotator' method='post' "
 3101:   +"action='$annotateurl'>"
 3102:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
 3103:   +"<\\/form>"
 3104:   +'$end_page_annotate');
 3105:    annotator.document.close();
 3106: }
 3107: 
 3108: function open_StoredLinks_Import(rat) {
 3109:    var newWin;
 3110:    var lcHostname = setLCHost();
 3111:    if (rat) {
 3112:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
 3113:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
 3114:    }
 3115:    else {
 3116:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import',
 3117:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
 3118:    }
 3119:    newWin.focus();
 3120: }
 3121: 
 3122: function open_source() {
 3123:    sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename='+currentURL,'LONsource',
 3124:                          'height=500,width=600,resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=yes');
 3125: }
 3126: 
 3127: function open_aboutLC() {
 3128:     var isMobile = "$env{'browser.mobile'}";
 3129:     var url = '/adm/about.html';
 3130:     if (isMobile == 1) {
 3131:         openMyModal(url,600,400,'yes');
 3132:     } else {
 3133:         window.open(url,"aboutLONCAPA","height=400,width=600,scrollbars=1,resizable=1,menubar=0,location=1");
 3134:     }
 3135:     return;
 3136: }
 3137: 
 3138: (function (\$) {
 3139:   \$(document).ready(function () {
 3140:     \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
 3141:     /*\@cc_on
 3142:       if (!window.XMLHttpRequest) {
 3143:         \$('.LC_hoverable').each(function () {
 3144:           this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
 3145:           this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
 3146:         });
 3147:       }
 3148:     \@*/
 3149:   });
 3150: }(jQuery));
 3151: 
 3152: $countdown
 3153: 
 3154: $viewuser
 3155: 
 3156: ENDUTILITY
 3157: }
 3158: 
 3159: sub serverform {
 3160:     my $target;
 3161:     if (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) {
 3162:         $target = ' target="_self"';
 3163:     } else {
 3164:         $target = ' target="_top"';
 3165:     }
 3166:     return(<<ENDSERVERFORM);
 3167: <form name="server" action="/adm/logout" method="post"$target>
 3168: <input type="hidden" name="postdata" value="none" />
 3169: <input type="hidden" name="command" value="none" />
 3170: <input type="hidden" name="url" value="none" />
 3171: <input type="hidden" name="symb" value="none" />
 3172: </form>
 3173: ENDSERVERFORM
 3174: }
 3175: 
 3176: sub constspaceform {
 3177:     my ($frameset) = @_;
 3178:     my ($target,$printtarget);
 3179:     if ($frameset) {
 3180:         $target = ' target="_parent"';
 3181:         $printtarget = ' target="_parent"';
 3182:     } else {
 3183:         unless ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) || 
 3184:                 (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
 3185:             $target = ' target="_top"';
 3186:             $printtarget = ' target="_top"';
 3187:         }
 3188:     }
 3189:     return(<<ENDCONSTSPACEFORM);
 3190: <form name="constspace" action="/adm/logout" method="post"$target>
 3191: <input type="hidden" name="filename" value="" />
 3192: </form>
 3193: <form name="cstrdelete" action="/adm/cfile" method="post"$target>
 3194: <input type="hidden" name="action" value="delete" /> 
 3195: <input type="hidden" name="filename" value="" />
 3196: </form>
 3197: <form name="cstrprint" action="/adm/printout" method="post"$printtarget>
 3198: <input type="hidden" name="postdata" value="" />
 3199: <input type="hidden" name="curseed" value="" />
 3200: <input type="hidden" name="problemtype" value="" />
 3201: </form>
 3202: 
 3203: ENDCONSTSPACEFORM
 3204: }
 3205: 
 3206: sub get_nav_status {
 3207:     my $navstatus="swmenu.w_loncapanav_flag=";
 3208:     if ($env{'environment.remotenavmap'} eq 'on') {
 3209:         $navstatus.="1";
 3210:     } else {
 3211:         $navstatus.="-1";
 3212:     }
 3213:     return $navstatus;
 3214: }
 3215: 
 3216: sub hidden_button_check {
 3217:     if ( $env{'request.course.id'} eq ''
 3218:          || $env{'request.role.adv'} ) {
 3219: 
 3220:         return;
 3221:     }
 3222:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
 3223:     return $buttonshide; 
 3224: }
 3225: 
 3226: sub roles_selector {
 3227:     my ($cdom,$cnum,$httphost,$target,$menucoll,$menuref) = @_;
 3228:     my $crstype = &Apache::loncommon::course_type();
 3229:     my $now = time;
 3230:     my (%courseroles,%seccount,%courseprivs,%roledesc);
 3231:     my $is_cc;
 3232:     my ($js,$form,$switcher,$has_opa_priv);
 3233:     my $ccrole;
 3234:     if ($crstype eq 'Community') {
 3235:         $ccrole = 'co';
 3236:     } else {
 3237:         $ccrole = 'cc';
 3238:     }
 3239:     my ($privref,$gotsymb,$destsymb);
 3240:     my $destinationurl = $ENV{'REQUEST_URI'};
 3241:     if ($destinationurl =~ /(\?|\&)symb=/) {
 3242:         $gotsymb = 1;
 3243:     } elsif ($destinationurl =~ m{^/enc/}) {
 3244:         my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
 3245:         if ($plainurl =~ /(\?|\&)symb=/) {
 3246:             $gotsymb = 1;
 3247:         }
 3248:     }
 3249:     unless ($gotsymb) {
 3250:         $destsymb = &Apache::lonnet::symbread();
 3251:         if ($destsymb ne '') {
 3252:             $destsymb = &Apache::lonenc::check_encrypt($destsymb);
 3253:         }
 3254:     }
 3255:     my $reqprivs = &required_privs();
 3256:     if (ref($reqprivs) eq 'HASH') {
 3257:         my $destination = $destinationurl;
 3258:         $destination =~ s/(\?.*)$//;
 3259:         if (exists($reqprivs->{$destination})) {
 3260:             if ($reqprivs->{$destination} =~ /,/) {
 3261:                 @{$privref} = split(/,/,$reqprivs->{$destination});
 3262:             } else {
 3263:                 $privref = [$reqprivs->{$destination}];
 3264:             }
 3265:         }
 3266:     }
 3267:     if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
 3268:         my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
 3269:         if ((($start) && ($start<0)) || 
 3270:             (($end) && ($end<$now))  ||
 3271:             (($start) && ($now<$start))) {
 3272:             $is_cc = 0;
 3273:         } else {
 3274:             $is_cc = 1;
 3275:         }
 3276:     }
 3277:     if ($is_cc) {
 3278:         &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs);
 3279:     } elsif ($env{'request.role'} =~ m{^\Qcr/$cdom/$cdom-domainconfig/\E(\w+)\.\Q/$cdom/$cnum\E}) {
 3280:         &get_customadhoc_roles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,\%roledesc,$privref);
 3281:     } else {
 3282:         my %gotnosection;
 3283:         foreach my $item (keys(%env)) {
 3284:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
 3285:                 my $role = $1;
 3286:                 my $sec = $2;
 3287:                 next if ($role eq 'gr');
 3288:                 my ($start,$end) = split(/\./,$env{$item});
 3289:                 next if (($start && $start > $now) || ($end && $end < $now));
 3290:                 if ($sec eq '') {
 3291:                     if (!$gotnosection{$role}) {
 3292:                         $seccount{$role} ++;
 3293:                         $gotnosection{$role} = 1;
 3294:                     }
 3295:                 }
 3296:                 if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
 3297:                     my $cnumsec = $cnum;
 3298:                     if ($sec ne '') {
 3299:                         $cnumsec .= "/$sec";
 3300:                     }
 3301:                     $courseprivs{"$role./$cdom/$cnumsec./"} =
 3302:                         $env{"user.priv.$role./$cdom/$cnumsec./"};
 3303:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
 3304:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
 3305:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
 3306:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
 3307:                 }
 3308:                 if (ref($courseroles{$role}) eq 'ARRAY') {
 3309:                     if ($sec ne '') {
 3310:                         if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
 3311:                             push(@{$courseroles{$role}},$sec);
 3312:                             $seccount{$role} ++;
 3313:                         }
 3314:                     }
 3315:                 } else {
 3316:                     @{$courseroles{$role}} = ();
 3317:                     if ($sec ne '') {
 3318:                         $seccount{$role} ++;
 3319:                         push(@{$courseroles{$role}},$sec);
 3320:                     }
 3321:                 }
 3322:             }
 3323:         }
 3324:     }
 3325:     my @roles_order = ($ccrole,'in','ta','ep','ad','st');
 3326:     my $numdiffsec;
 3327:     if (keys(%seccount) == 1) {
 3328:         foreach my $key (keys(%seccount)) {
 3329:             $numdiffsec = $seccount{$key};
 3330:         }
 3331:     }
 3332:     if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
 3333:         my $targetattr;
 3334:         if ($target ne '') {
 3335:             $targetattr = ' target="'.$target.'"';
 3336:         }
 3337:         my @submenu;
 3338:         $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,
 3339:                             \%roledesc,$privref,$menucoll,$menuref);
 3340:         $form = 
 3341:             '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles"'.$targetattr.'>'."\n".
 3342:             '  <input type="hidden" name="destinationurl" value="'.
 3343:             &HTML::Entities::encode($destinationurl).'" />'."\n".
 3344:             '  <input type="hidden" name="gotorole" value="1" />'."\n".
 3345:             '  <input type="hidden" name="selectrole" value="" />'."\n".
 3346:             '  <input type="hidden" name="switchrole" value="" />'."\n";
 3347:         if ($destsymb ne '') {
 3348:             $form .= '   <input type="hidden" name="destsymb" value="'.
 3349:                          &HTML::Entities::encode($destsymb).'" />'."\n";
 3350:         }
 3351:         $form .= '</form>'."\n";
 3352:         foreach my $role (@roles_order) {
 3353:             my $include;
 3354:             if (defined($courseroles{$role})) {
 3355:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
 3356:                     if ($seccount{$role} > 1) {
 3357:                         $include = 1;
 3358:                     } else {
 3359:                         if ($env{'user.priv.'.$env{'request.role'}."./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
 3360:                             $has_opa_priv = 1;
 3361:                         }
 3362:                     }
 3363:                 } else {
 3364:                     $include = 1;
 3365:                 }
 3366:             }
 3367:             if ($include) {
 3368:                 if ($env{"user.priv.$role./$cdom/$cnum./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
 3369:                     $has_opa_priv = 1;
 3370:                 }
 3371:                 push(@submenu,['javascript:adhocRole('."'$role'".')',
 3372:                                &Apache::lonnet::plaintext($role,$crstype)]);
 3373:             }
 3374:         }
 3375:         foreach my $role (sort(keys(%courseroles))) {
 3376:             if ($role =~ /^cr/) {
 3377:                 my $include;
 3378:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
 3379:                     if ($seccount{$role} > 1) {
 3380:                         $include = 1;
 3381:                     }
 3382:                 } else {
 3383:                     $include = 1;
 3384:                 }
 3385:                 if ($include) {
 3386:                     my $rolename;
 3387:                     if ($role =~ m{^cr/$cdom/$cdom\-domainconfig/(\w+)(?:/\w+|$)}) {
 3388:                         $rolename = $roledesc{$role};
 3389:                         if ($rolename eq '') {
 3390:                             $rolename = &mt('Helpdesk [_1]',$1);
 3391:                         }
 3392:                     } else {
 3393:                         $rolename = &Apache::lonnet::plaintext($role);
 3394:                     }
 3395:                     if ($env{"user.priv.$role./$cdom/$cnum./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
 3396:                         $has_opa_priv = 1;
 3397:                     }
 3398:                     push(@submenu,['javascript:adhocRole('."'$role'".')',
 3399:                                    $rolename]);
 3400:                 }
 3401:             }
 3402:         }
 3403:         if (@submenu > 0) {
 3404:             $switcher = &create_submenu('#',$target,&mt('Switch role'),\@submenu);
 3405:         }
 3406:     }
 3407:     return ($js,$form,$switcher,$has_opa_priv);
 3408: }
 3409: 
 3410: sub get_all_courseroles {
 3411:     my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
 3412:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
 3413:             (ref($courseprivs) eq 'HASH')) {
 3414:         return;
 3415:     }
 3416:     my ($result,$cached) = 
 3417:         &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
 3418:     if (defined($cached)) {
 3419:         if (ref($result) eq 'HASH') {
 3420:             if ((ref($result->{'roles'}) eq 'HASH') && 
 3421:                 (ref($result->{'seccount'}) eq 'HASH') && 
 3422:                 (ref($result->{'privs'}) eq 'HASH')) {
 3423:                 %{$courseroles} = %{$result->{'roles'}};
 3424:                 %{$seccount} = %{$result->{'seccount'}};
 3425:                 %{$courseprivs} = %{$result->{'privs'}};
 3426:                 return;
 3427:             }
 3428:         }
 3429:     }
 3430:     my %gotnosection;
 3431:     my %adv_roles =
 3432:          &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
 3433:     foreach my $role (keys(%adv_roles)) {
 3434:         my ($urole,$usec) = split(/:/,$role);
 3435:         if (!$gotnosection{$urole}) {
 3436:             $seccount->{$urole} ++;
 3437:             $gotnosection{$urole} = 1;
 3438:         }
 3439:         if (ref($courseroles->{$urole}) eq 'ARRAY') {
 3440:             if ($usec ne '') {
 3441:                 if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
 3442:                     push(@{$courseroles->{$urole}},$usec);
 3443:                     $seccount->{$urole} ++;
 3444:                 }
 3445:             }
 3446:         } else {
 3447:             @{$courseroles->{$urole}} = ();
 3448:             if ($usec ne '') {
 3449:                 $seccount->{$urole} ++;
 3450:                 push(@{$courseroles->{$urole}},$usec);
 3451:             }
 3452:         }
 3453:         my $area = '/'.$cdom.'/'.$cnum;
 3454:         if ($usec ne '') {
 3455:             $area .= '/'.$usec;
 3456:         }
 3457:         if ($role =~ /^cr\//) {
 3458:             &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
 3459:         } else {
 3460:             &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
 3461:         }
 3462:     }
 3463:     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
 3464:     @{$courseroles->{'st'}} = ();
 3465:     &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
 3466:     if (keys(%sections_count) > 0) {
 3467:         push(@{$courseroles->{'st'}},keys(%sections_count));
 3468:         $seccount->{'st'} = scalar(keys(%sections_count));
 3469:     }
 3470:     $seccount->{'st'} ++; # Increment for a section-less student role.
 3471:     my $rolehash = {
 3472:                      'roles'    => $courseroles,
 3473:                      'seccount' => $seccount,
 3474:                      'privs'    => $courseprivs,
 3475:                    };
 3476:     &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
 3477:     return;
 3478: }
 3479: 
 3480: sub get_customadhoc_roles {
 3481:     my ($cdom,$cnum,$courseroles,$seccount,$courseprivs,$roledesc,$privref) = @_;
 3482:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
 3483:             (ref($courseprivs) eq 'HASH') && (ref($roledesc) eq 'HASH')) {
 3484:         return;
 3485:     }
 3486:     my $is_helpdesk = 0;
 3487:     my $now = time;
 3488:     foreach my $role ('dh','da') {
 3489:         if ($env{"user.role.$role./$cdom/"}) {
 3490:             my ($start,$end)=split(/\./,$env{"user.role.$role./$cdom/"});
 3491:             if (!($start && ($now<$start)) && !($end && ($now>$end))) {
 3492:                 $is_helpdesk = 1;
 3493:                 last;
 3494:             }
 3495:         }
 3496:     }
 3497:     if ($is_helpdesk) {
 3498:         my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum);
 3499:         my %available;
 3500:         if (ref($possroles) eq 'ARRAY') {
 3501:             map { $available{$_} = 1; } @{$possroles};
 3502:         }
 3503:         my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
 3504:         if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
 3505:             if (keys(%{$domdefaults{'adhocroles'}})) {
 3506:                 my $numsec = 1;
 3507:                 my @sections;
 3508:                 my ($allseclist,$cached) =
 3509:                     &Apache::lonnet::is_cached_new('courseseclist',$cdom.'_'.$cnum);
 3510:                 if (defined($cached)) {
 3511:                     if ($allseclist ne '') {
 3512:                         @sections = split(/,/,$allseclist);
 3513:                         $numsec += scalar(@sections);
 3514:                     }
 3515:                 } else {
 3516:                     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
 3517:                     @sections = sort(keys(%sections_count));
 3518:                     $numsec += scalar(@sections);
 3519:                     $allseclist = join(',',@sections);
 3520:                     &Apache::lonnet::do_cache_new('courseseclist',$cdom.'_'.$cnum,$allseclist);
 3521:                 }
 3522:                 my (%adhoc,$gotprivs);
 3523:                 my $prefix = "cr/$cdom/$cdom".'-domainconfig';
 3524:                 foreach my $role (keys(%{$domdefaults{'adhocroles'}})) {
 3525:                     next if (($role eq '') || ($role =~ /\W/));
 3526:                     $seccount->{"$prefix/$role"} = $numsec;
 3527:                     $roledesc->{"$prefix/$role"} = $description->{$role};  
 3528:                     if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
 3529:                         if (exists($env{"user.priv.$prefix/$role./$cdom/$cnum./"})) {
 3530:                             $courseprivs->{"$prefix/$role./$cdom/$cnum./"} =
 3531:                                 $env{"user.priv.$prefix/$role./$cdom/$cnum./"};
 3532:                             $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"} =
 3533:                                 $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/"};
 3534:                             $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"} =
 3535:                                 $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/$cnum"};
 3536:                         } else {
 3537:                             unless ($gotprivs) {
 3538:                                 my ($adhocroles,$privscached) =
 3539:                                     &Apache::lonnet::is_cached_new('adhocroles',$cdom);
 3540:                                 if ((defined($privscached)) && (ref($adhocroles) eq 'HASH')) {
 3541:                                     %adhoc = %{$adhocroles};
 3542:                                 } else {
 3543:                                     my $confname = &Apache::lonnet::get_domainconfiguser($cdom);
 3544:                                     my %roledefs = &Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
 3545:                                     foreach my $key (keys(%roledefs)) {
 3546:                                         (undef,my $rolename) = split(/_/,$key);
 3547:                                         if ($rolename ne '') {
 3548:                                             my ($systempriv,$domainpriv,$coursepriv) = split(/\_/,$roledefs{$key});
 3549:                                             $coursepriv = &Apache::lonnet::course_adhocrole_privs($rolename,$cdom,$cnum,$coursepriv);
 3550:                                             $adhoc{$rolename} = join('_',($systempriv,$domainpriv,$coursepriv));
 3551:                                         }
 3552:                                     }
 3553:                                     &Apache::lonnet::do_cache_new('adhocroles',$cdom,\%adhoc);
 3554:                                 }
 3555:                                 $gotprivs = 1;
 3556:                             }
 3557:                             ($courseprivs->{"$prefix/$role./$cdom/$cnum./"},
 3558:                              $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"},
 3559:                              $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"}) =
 3560:                                  split(/\_/,$adhoc{$role});
 3561:                         }
 3562:                     }
 3563:                     if ($available{$role}) {
 3564:                         $courseroles->{"$prefix/$role"} = \@sections;
 3565:                     }
 3566:                 }
 3567:             }
 3568:         }
 3569:     }
 3570:     return;
 3571: }
 3572: 
 3573: sub jump_to_role {
 3574:     my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$roledesc,$privref,
 3575:         $menucoll,$menuref) = @_;
 3576:     my %lt = &Apache::lonlocal::texthash(
 3577:                 this => 'This role has section(s) associated with it.',
 3578:                 ente => 'Enter a specific section.',
 3579:                 orlb => 'Enter a specific section, or leave blank for no section.',
 3580:                 avai => 'Available sections are:',
 3581:                 youe => 'You entered an invalid section choice:',
 3582:                 plst => 'Please try again.',
 3583:                 role => 'The role you selected is not permitted to view the current page.',
 3584:                 swit => 'Switch role, but display Main Menu page instead?',
 3585:     );
 3586:     &js_escape(\%lt);
 3587:     my $js;
 3588:     if (ref($courseroles) eq 'HASH') {
 3589:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
 3590:               '    var numsec = new Array();'."\n".
 3591:               '    var rolesections = new Array();'."\n".
 3592:               '    var rolenames = new Array();'."\n".
 3593:               '    var roleseclist = new Array();'."\n";
 3594:         my @items = keys(%{$courseroles});
 3595:         for (my $i=0; $i<@items; $i++) {
 3596:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
 3597:             my ($secs,$secstr);
 3598:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
 3599:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
 3600:                 $secs = join('","',@sections);
 3601:                 $secstr = join(', ',@sections);
 3602:             }
 3603:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
 3604:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
 3605:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
 3606:         }
 3607:     }
 3608:     my $checkroles = 0;
 3609:     my $fallback = '/adm/menu';
 3610:     my $displaymsg = $lt{'swit'};
 3611:     if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0) && (ref($courseprivs) eq 'HASH')) {
 3612:         my %disallowed;
 3613:         foreach my $role (sort(keys(%{$courseprivs}))) {
 3614:             my $trole;
 3615:             if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
 3616:                 $trole = $1;
 3617:             }
 3618:             if (($trole ne '') && ($trole ne 'cm')) {
 3619:                 $disallowed{$trole} = 1;
 3620:                 foreach my $priv (@{$privref}) { 
 3621:                     if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
 3622:                         delete($disallowed{$trole});
 3623:                         last;
 3624:                     }
 3625:                 }
 3626:             }
 3627:         }
 3628:         if (keys(%disallowed) > 0) {
 3629:             $checkroles = 1;
 3630:             $js .= "    var disallow = new Array('".join("','",keys(%disallowed))."');\n".
 3631:                    "    var rolecheck = 1;\n";
 3632:             if ($menucoll) {
 3633:                 if (ref($menuref) eq 'HASH') {
 3634:                     if ($menuref->{'main'} eq 'n') {
 3635:                         $fallback = '/adm/navmaps';
 3636:                         if (&Apache::loncommon::course_type() eq 'Community') {
 3637:                             $displaymsg = &mt('Switch role, but display Community Contents page instead?');
 3638:                         } else {
 3639:                             $displaymsg = &mt('Switch role, but display Course Contents page instead?');
 3640:                         }
 3641:                         &js_escape(\$displaymsg);
 3642:                     }
 3643:                 }
 3644:             }
 3645:         }
 3646:     }
 3647:     &js_escape(\$fallback);
 3648:     if (!$checkroles) {
 3649:         $js .=  "    var disallow = new Array();\n".
 3650:                 "    rolecheck = 0;\n";
 3651:     }
 3652:     return <<"END";
 3653: <script type="text/javascript">
 3654: //<![CDATA[
 3655: function adhocRole(newrole) {
 3656:     $js
 3657:     if (newrole == '') {
 3658:         return;
 3659:     } 
 3660:     var fullrole = newrole+'./$cdom/$cnum';
 3661:     var selidx = '';
 3662:     for (var i=0; i<rolenames.length; i++) {
 3663:         if (rolenames[i] == newrole) {
 3664:             selidx = i;
 3665:         }
 3666:     }
 3667:     if (rolecheck > 0) {
 3668:         for (var i=0; i<disallow.length; i++) {
 3669:             if (disallow[i] == newrole) {
 3670:                 if (confirm("$lt{'role'}\\n$displaymsg")) {
 3671:                     document.rolechooser.destinationurl.value = '$fallback';
 3672:                 } else {
 3673:                     return;
 3674:                 }
 3675:             }
 3676:         }
 3677:     }
 3678:     var secok = 1;
 3679:     var secchoice = '';
 3680:     if (selidx >= 0) {
 3681:         if (numsec[selidx] > 1) {
 3682:             secok = 0;
 3683:             var numrolesec = rolesections[selidx].length;
 3684:             var msgidx = numsec[selidx] - numrolesec;
 3685:             secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
 3686:             if (secchoice == '') {
 3687:                 if (msgidx > 0) {
 3688:                     secok = 1;
 3689:                 }
 3690:             } else {
 3691:                 for (var j=0; j<rolesections[selidx].length; j++) {
 3692:                     if (rolesections[selidx][j] == secchoice) {
 3693:                         secok = 1;
 3694:                     }
 3695:                 }
 3696:             }
 3697:         } else {
 3698:             if (rolesections[selidx].length == 1) {
 3699:                 secchoice = rolesections[selidx][0];
 3700:             }
 3701:         }
 3702:     }
 3703:     if (secok == 1) {
 3704:         if (secchoice != '') {
 3705:             fullrole += '/'+secchoice;
 3706:         }
 3707:     } else {
 3708:         document.rolechooser.elements[roleitem].selectedIndex = 0;
 3709:         if (secchoice != null) {
 3710:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
 3711:         }
 3712:         return;
 3713:     }
 3714:     if (fullrole == "$env{'request.role'}") {
 3715:         return;
 3716:     }
 3717:     itemid = retrieveIndex('gotorole');
 3718:     if (itemid != -1) {
 3719:         document.rolechooser.elements[itemid].name = fullrole;
 3720:     }
 3721:     document.rolechooser.switchrole.value = fullrole;
 3722:     document.rolechooser.selectrole.value = '1';
 3723:     document.rolechooser.submit();
 3724:     return;
 3725: }
 3726: 
 3727: function retrieveIndex(item) {
 3728:     for (var i=0;i<document.rolechooser.elements.length;i++) {
 3729:         if (document.rolechooser.elements[i].name == item) {
 3730:             return i;
 3731:         }
 3732:     }
 3733:     return -1;
 3734: }
 3735: // ]]>
 3736: </script>
 3737: END
 3738: }
 3739: 
 3740: sub required_privs {
 3741:     my $privs =  {
 3742:              '/adm/parmset'      => 'opa,vpa',
 3743:              '/adm/courseprefs'  => 'opa,vpa',
 3744:              '/adm/whatsnew'     => 'whn',
 3745:              '/adm/populate'     => 'cst,vpa,vcl',
 3746:              '/adm/trackstudent' => 'vsa',
 3747:              '/adm/statistics'   => 'mgr,vgr',
 3748:              '/adm/setblock'     => 'dcm,vcb',
 3749:              '/adm/coursedocs'   => 'mdc',
 3750:            };
 3751:     unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
 3752:         $privs->{'/adm/classcalc'}   = 'vgr',
 3753:         $privs->{'/adm/assesscalc'}  = 'vgr',
 3754:         $privs->{'/adm/studentcalc'} = 'vgr';
 3755:     }
 3756:     return $privs;
 3757: }
 3758: 
 3759: sub countdown_timer {
 3760:     if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
 3761:         (($env{'request.filename'}=~/$LONCAPA::assess_re/) ||
 3762:          (($env{'request.symb'} =~ /ext\.tool$/) &&
 3763:          (&Apache::lonnet::EXT('resource.0.gradable',$env{'request.symb'}) =~ /^yes$/i)))) {
 3764:         my ($type,$hastimeleft,$slothastime);
 3765:         my $now = time;
 3766:         if ($env{'request.filename'} =~ /\.task$/) {
 3767:             $type = 'Task';
 3768:         } elsif ($env{'request.symb'} =~ /ext\.tool$/) {
 3769:             $type = 'tool';
 3770:         } else {
 3771:             $type = 'problem';
 3772:         }
 3773:         my ($status,$accessmsg,$slot_name,$slot);
 3774:         if ($type eq 'tool') {
 3775:             ($status,$accessmsg,$slot_name,$slot) =
 3776:                 &Apache::lonhomework::check_slot_access('0',$type,$env{'request.symb'},['0']);
 3777:         } else {
 3778:             ($status,$accessmsg,$slot_name,$slot) =
 3779:                 &Apache::lonhomework::check_slot_access('0',$type);
 3780:         }
 3781:         if ($slot_name ne '') {
 3782:             if (ref($slot) eq 'HASH') {
 3783:                 if (($slot->{'starttime'} < $now) &&
 3784:                     ($slot->{'endtime'} > $now)) {
 3785:                     $slothastime = 1;
 3786:                 }
 3787:             }
 3788:         }
 3789:         if ($status ne 'CAN_ANSWER') {
 3790:             return;
 3791:         }
 3792:         my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
 3793:         my @interval=&Apache::lonnet::EXT("resource.0.interval");
 3794:         my ($timelimit,$usesdone,$donebuttontext,$proctor,$secret);
 3795:         if (@interval > 1) {
 3796:             ($timelimit,my $donesuffix) = split(/_/,$interval[0],2);
 3797:             if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) {
 3798:                 $usesdone = 'done';
 3799:                 $donebuttontext = $1;
 3800:                 (undef,$proctor,$secret) = split(/_/,$2);
 3801:             } elsif ($donesuffix =~ /^done(|_.+)$/) {
 3802:                 $donebuttontext = &mt('Done');
 3803:                 ($usesdone,$proctor,$secret) = split(/_/,$donesuffix);
 3804:             }
 3805:             my $first_access=&Apache::lonnet::get_first_access($interval[1]);
 3806:             if ($first_access > 0) {
 3807:                 if ($first_access+$timelimit > time) {
 3808:                     $hastimeleft = 1;
 3809:                 }
 3810:             }
 3811:         }
 3812:         if (($duedate && $duedate > time) ||
 3813:             (!$duedate && $hastimeleft) ||
 3814:             ($slot_name ne '' && $slothastime)) {
 3815:             my ($collapse,$expand,$alttxt,$title,$currdisp,$donebutton);
 3816:             if ((@interval > 1 && $hastimeleft) ||
 3817:                 ($type eq 'Task' && $slothastime)) {
 3818:                 $currdisp = 'inline';
 3819:                 $collapse = '&#9658;&nbsp;';
 3820:                 if ((@interval > 1) && ($hastimeleft)) {
 3821:                     if ($usesdone eq 'done') {
 3822:                         $donebutton = &done_button_js($interval[1],'','',$proctor,$donebuttontext);
 3823:                     }
 3824:                 }
 3825:             } else {
 3826:                 $currdisp = 'none';
 3827:                 $expand = '&#9668;&nbsp;';
 3828:             }
 3829:             unless ($env{'environment.icons'} eq 'iconsonly') {
 3830:                 $alttxt = &mt('Timer');
 3831:                 $title = $alttxt.'&nbsp;';
 3832:             }
 3833:             my $desc = &mt('Countdown to due date/time');
 3834:             return <<END;
 3835: $donebutton
 3836: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
 3837: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
 3838: $collapse
 3839: </span></a>
 3840: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
 3841: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
 3842: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
 3843: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
 3844: END
 3845:         }
 3846:     }
 3847:     return;
 3848: }
 3849: 
 3850: sub linkprot_exit {
 3851:     if (($env{'request.course.id'}) && ($env{'request.deeplink.login'})) {
 3852:         my ($deeplink_symb,$deeplink);
 3853:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 3854:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 3855:         if (($cnum ne '') && ($cdom ne '')) {
 3856:             $deeplink_symb = &Apache::loncommon::deeplink_login_symb($cnum,$cdom);
 3857:             if ($deeplink_symb) {
 3858:                 if ($deeplink_symb =~ /\.(page|sequence)$/) {
 3859:                     my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
 3860:                     my $navmap = Apache::lonnavmaps::navmap->new();
 3861:                     if (ref($navmap)) {
 3862:                         $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
 3863:                     }
 3864:                 } else {
 3865:                     $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
 3866:                 }
 3867:                 if ($deeplink ne '') {
 3868:                     my ($state,$others,$listed,$scope,$protect,$display,$target,$exit) = split(/,/,$deeplink);
 3869:                     my %lt = &Apache::lonlocal::texthash(
 3870:                         title    => 'Exit Tool',
 3871:                         okdone   => 'Click "OK" to exit embedded tool',
 3872:                         cancel   => 'Click "Cancel" to continue working.',
 3873:                         ok       => 'OK',
 3874:                         exit     => 'Cancel',
 3875:                     );
 3876:                     if ($exit) {
 3877:                         my ($show,$text) = split(/:/,$exit);
 3878:                         unless ($show eq 'no') {
 3879:                             my $height = 250;
 3880:                             my $width = 300;
 3881:                             my $exitbuttontext;
 3882:                             if ($text eq '') {
 3883:                                 $exitbuttontext = &mt('Exit Tool');
 3884:                             } else {
 3885:                                 $exitbuttontext = $text;
 3886:                             }
 3887:                             return <<END;
 3888: <form method="post" name="LCexitButton" action="/adm/linkexit">
 3889:     <input type="hidden" name="LC_deeplink_exit" value="" />
 3890:     <button id="LC_exit-confirm-opener" type="button">$exitbuttontext</button>
 3891: </form>
 3892: 
 3893: <div id="LC_exit-confirm" title="$lt{'title'}">
 3894:     <p>$lt{'okdone'} $lt{'cancel'}</p>
 3895: </div>
 3896: 
 3897: <script type="text/javascript">
 3898: // <![CDATA[
 3899: \$( "#LC_exit-confirm" ).dialog({ autoOpen: false });
 3900: \$( "#LC_exit-confirm-opener" ).click(function() {
 3901:     \$( "#LC_exit-confirm" ).dialog( "open" );
 3902:     \$( "#LC_exit-confirm" ).dialog({
 3903:       resizable: false,
 3904:       height: $height,
 3905:       width: $width,
 3906:       modal: true,
 3907:       buttons: [
 3908:                  {
 3909:                     text: "$lt{'ok'}",
 3910:                     click: function() {
 3911:                         \$( this ).dialog( "close" );
 3912:                         \$( '[name="LC_deeplink_exit"]' )[0].value = 'true';
 3913:                         \$( '[name="LCexitButton"]' )[0].submit();
 3914:                     },
 3915:                  },
 3916:                  {
 3917:                      text: "$lt{'exit'}",
 3918:                      click: function() {
 3919:                          \$( this ).dialog( "close" );
 3920:                      },
 3921:                   },
 3922:                ],
 3923:        });
 3924: });
 3925: // ]]>
 3926: </script>
 3927: 
 3928: END
 3929:                         }
 3930:                     }
 3931:                 }
 3932:             }
 3933:         }
 3934:     }
 3935:     return;
 3936: }
 3937: 
 3938: # ================================================================ Main Program
 3939: 
 3940: BEGIN {
 3941:     if (! defined($readdesk)) {
 3942:         {
 3943:             my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
 3944:             if ( CORE::open( my $config,"<$tabfile") ) {
 3945:                 while (my $configline=<$config>) {
 3946:                     $configline=(split(/\#/,$configline))[0];
 3947:                     $configline=~s/^\s+//;
 3948:                     chomp($configline);
 3949:                     if ($configline=~/^cat\:/) {
 3950:                         my @entries=split(/\:/,$configline);
 3951:                         $category_positions{$entries[2]}=$entries[1];
 3952:                         $category_names{$entries[2]}=$entries[3];
 3953:                     } elsif ($configline=~/^prim\:/) {
 3954:                         my @entries = (split(/\:/, $configline))[1..7];
 3955:                         push(@primary_menu,\@entries);
 3956:                     } elsif ($configline=~/^primsub\:/) {
 3957:                         my ($parent,@entries) = (split(/\:/, $configline))[1..5];
 3958:                         push(@{$primary_submenu{$parent}},\@entries);
 3959:                     } elsif ($configline=~/^scnd\:/) {
 3960:                         my @entries = (split(/\:/, $configline))[1..6];
 3961:                         push(@secondary_menu,\@entries);
 3962:                     } elsif ($configline=~/^scndsub\:/) {
 3963:                         my ($parent,@entries) = (split(/\:/, $configline))[1..4];
 3964:                         push(@{$secondary_submenu{$parent}},\@entries);
 3965:                     } elsif ($configline) {
 3966:                         push(@desklines,$configline);
 3967:                     }
 3968:                 }
 3969:                 CORE::close($config);
 3970:             }
 3971:         }
 3972:         $readdesk='done';
 3973:     }
 3974: }
 3975: 
 3976: 1;
 3977: __END__
 3978: 

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