File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.527: download - view: text, annotated - select for diffs
Tue Sep 13 12:22:14 2022 UTC (20 months, 3 weeks ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- In course context, switch server to resource's home server opens new tab
  when editing published resource, and ca role is loaded,  when user's domain
  (by default) disallows session hosting of domain's users in resource's domain.
- New arg (skip_enc_check) in redirect args , used by loncommon::headtag()
  it true, omit application of check_encrypt().
- New seventh item ($shownsymb) in args for lonhtmlcommon::jump_to_editres()

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

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