File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.553: download - view: text, annotated - select for diffs
Tue May 14 15:53:17 2024 UTC (4 weeks ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6990. Correct link for "Export" icon in Functions menu for directory
  listing by author for own Authoring Space.

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

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