File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.548: download - view: text, annotated - select for diffs
Thu Apr 18 17:53:15 2024 UTC (5 weeks, 1 day ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Access to Authoring Space Configuration from Functions menu instead of
  Settings in inline menu when Authoring Space accessed in course context.

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

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