File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.533: download - view: text, annotated - select for diffs
Thu Jul 6 16:55:43 2023 UTC (10 months, 4 weeks ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- call to LONCAPA::ltiutils::lti_provider_scope() was moved from lonmenu.pm
  to loncommon.pm in rev. 1.490 and rev. 1.1316 respectively (4/27/2018).

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

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