File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.529: download - view: text, annotated - select for diffs
Sat Oct 29 14:47:00 2022 UTC (19 months, 1 week ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Entity encoding for last item in breadcrumbs trail.

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

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