File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.540: download - view: text, annotated - select for diffs
Fri Oct 6 02:04:47 2023 UTC (7 months, 4 weeks ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6979.
  "View As" form in Functions menu includes domain dropdown list if users in
  course are from more than one domain; domain in hidden input tag otherwise

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

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