File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.543: download - view: text, annotated - select for diffs
Wed Dec 13 22:12:16 2023 UTC (5 months, 3 weeks ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Links to search or browse Resource Space added to dropdown displayed when
  hovering over name at top left of any LON-CAPA page.

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

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