File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.83.2.17: download - view: text, annotated - select for diffs
Mon Feb 26 00:28:19 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)
  Blank line added in 1.443 but omitted in 1.369.2.83.2.8 is needed,
  otherwise 3 appears to left of "Course Contents" in breadcrumbs trail.

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

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