File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.538: download - view: text, annotated - select for diffs
Thu Sep 28 15:56:48 2023 UTC (8 months, 1 week ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6979 Work in progress.
  Reduce width of "View As" form in Functions menu by removing dropdown
  list for domain, and only displaying textbox for either username or ID
  (radio buttons to toggle between the two). Default domain is course's
  domain.

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.538 2023/09/28 15:56:48 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,$righticon);
 1085:             my %lt = &Apache::lonlocal::texthash(
 1086:                                                  view => 'View',
 1087:                                                  upda => 'Update',
 1088:             );
 1089:             if ($env{'request.user_in_effect'} =~ /^($match_username):($match_domain)$/) {
 1090:                 ($vuname,$vudom) = ($1,$2);
 1091:                 unless (&Apache::lonnet::is_advanced_user($vudom,$vuname)) {
 1092:                     $vid = (&Apache::lonnet::idrget($vudom,$vuname))[1];
 1093:                 }
 1094:                 $viewas = $env{'request.user_in_effect'};
 1095:                 $text = $lt{'upda'};
 1096:                 $change = 'off';
 1097:                 $visibility = 'inline';
 1098:                 $leftvis = 'none';
 1099:                 $defdom = $vudom;
 1100:                 $righticon = '&#10006;';
 1101:             } else {
 1102:                 $text = $lt{'view'};
 1103:                 $change = 'on';
 1104:                 $visibility = 'none';
 1105:                 $leftvis = 'inline';
 1106:                 $defdom = $cdom;
 1107:             }
 1108:             my $sellink = &Apache::loncommon::selectstudent_link('userview','vuname','vudom','','','vuidentifier');
 1109:             my $selscript=&Apache::loncommon::studentbrowser_javascript();
 1110:             my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}),'<>&"');
 1111:             my $input = &mt('[_1]Username:[_2] or [_3]ID:[_4] | ',
 1112:                             '<label><input type="radio" name="vuidentifier" value="uname" checked="checked" onclick="javascript:toggleIdentifier(this.form);" />',
 1113:                             '</label><input name="vuname" type="text" size="6" value="'.$vuname.'" id="LC_vuname" />',
 1114:                             '<label><input type="radio" name="vuidentifier" value="uid" onclick="javascript:toggleIdentifier(this.form);" />',
 1115:                             '</label><input name="vid" type="hidden" size="6" value="'.$vid.'" id="LC_vid" />').
 1116:                         '<input name="vudom" type="hidden" value="'.$defdom.'" />'.
 1117:                         '<input name="LC_viewas" type="hidden" value="'.$viewas.'" />',
 1118:                         '<input name="symb" type="hidden" value="'.$shownsymb.'" />';
 1119:             my $chooser = <<END;
 1120: $selscript
 1121: <a href="javascript:toggleViewAsUser('$change');" class="LC_menubuttons_link">
 1122: <span id="usexpand" class="LC_menubuttons_inline_text" style="display:$leftvis">&#9658;&nbsp;</span>
 1123: </a>
 1124: <fieldset id="LC_selectuser" style="display:$visibility">
 1125: <form name="userview" action="" method="post" onsubmit="event.preventDefault(); return validCourseUser(this,'$change');">
 1126: <span class="LC_menubuttons_inline_text LC_nobreak">
 1127: $input
 1128: $sellink
 1129: </span>
 1130: &nbsp;<input type="submit" value="$text" />
 1131: </form>
 1132: </fieldset>
 1133: <a href="javascript:toggleViewAsUser('$change');" class="LC_menubuttons_link">
 1134: <span id="uscollapse" class="LC_menubuttons_inline_text">$righticon</span>
 1135: </a>
 1136: END
 1137:             &switch('','',7,5,'viewuser.png','View As','user[_1]',
 1138:                     'toggleViewAsUser('."'$change'".')',
 1139:                     'View As','','',$chooser);
 1140:         }
 1141: # End view as user check
 1142: 
 1143:     }
 1144: # End course context
 1145: 
 1146: # Prepare the rest of the buttons
 1147:         my ($menuitems,$got_prt,$got_wishlist,$crsauthor);
 1148:         if ($const_space) {
 1149: #
 1150: # We are in construction space
 1151: #
 1152: 
 1153:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
 1154: 	    my ($udom,$uname,$thisdisfn) =
 1155: 		($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
 1156:             my $crsauthor;
 1157:             if (($env{'request.course.id'}) &&
 1158:                 ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
 1159:                 ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
 1160:                 $crsauthor = 1;
 1161:             }
 1162:             my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
 1163:             if ($currdir =~ m-/$-) {
 1164:                 $is_const_dir = 1;
 1165:                 if (($thisdisfn eq '') && ($crsauthor)) {
 1166:                     $is_const_dir = 2;
 1167:                 }
 1168:                 my $esc_currdir = &Apache::loncommon::escape_single($currdir);
 1169:                 $menuitems=(<<ENDMENUITEMS);
 1170: s&6&3&pub.png&Publish&dir[_2]&gocstr('/adm/publish','$esc_currdir')&Publish this Directory
 1171: s&7&4&docs-22x22.png&Edit Metadata&defaults[_1]&gopost('${esc_currdir}default.meta','')&Edit metadata for this Directory
 1172: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','$esc_currdir')&Print contents of directory
 1173: s&7&1&del.png&Delete&dir[_3]&gocstr('/adm/cfile?action=delete','$esc_currdir')&Delete this Directory
 1174: ENDMENUITEMS
 1175:             } else {
 1176:                 $currdir =~ s|[^/]+$||;
 1177: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
 1178: 		my $esc_currdir = &Apache::loncommon::escape_single($currdir);
 1179:                 my $pubfile = "/res/$udom/$uname/$thisdisfn";
 1180:                 my $candelete = 1;
 1181:                 if (-e $londocroot.$pubfile) {
 1182:                     unless (&Apache::lonnet::metadata($pubfile,'obsolete')) {
 1183:                         undef($candelete);
 1184:                     }
 1185:                 }
 1186: #
 1187: # Probably should be in mydesk.tab
 1188: #
 1189:                 if (($crsauthor) && ($pubfile eq "/res/$udom/$uname/default.rights")) {
 1190:                     $menuitems=(<<ENDMENUITEMS);
 1191: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
 1192: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
 1193: ENDMENUITEMS
 1194:                 } else {
 1195:                     $menuitems=(<<ENDMENUITEMS);
 1196: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
 1197: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
 1198: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
 1199: s&7&3&copy.png&Copy&resource[_4]&gocstr('/adm/cfile?action=copy','/priv/$udom/$uname/$cleandisfn')&Copy this resource
 1200: ENDMENUITEMS
 1201:                 }
 1202: #
 1203: # Rename and Delete only available if obsolete or unpublished
 1204: #
 1205:                 if ($candelete) {
 1206:                     $menuitems .= (<<ENDMENUITEMS);
 1207: s&7&4&rename.png&Rename&resource[_5]&gocstr('/adm/cfile?action=rename','/priv/$udom/$uname/$cleandisfn')&Rename this resource
 1208: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
 1209: ENDMENUITEMS
 1210:                 }
 1211:                 $menuitems .= (<<ENDMENUITEMS);
 1212: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
 1213: ENDMENUITEMS
 1214:             }
 1215:                 if (ref($bread_crumbs) eq 'ARRAY') {
 1216:                     &Apache::lonhtmlcommon::clear_breadcrumbs();
 1217:                     foreach my $crumb (@{$bread_crumbs}){
 1218:                         &Apache::lonhtmlcommon::add_breadcrumb($crumb);
 1219:                     }
 1220:                 }
 1221:         } elsif ( defined($env{'request.course.id'}) && 
 1222: 		 $env{'request.symb'} ne '' ) {
 1223: #
 1224: # We are in a course and looking at a registered URL
 1225: # Should probably be in mydesk.tab
 1226: #
 1227:             $menuitems = "c&3&1";
 1228:             if ($ltiscope eq 'resource') {
 1229: # Suppress display of backward arrow for LTI Provider if scope is resource.
 1230: # Suppress display of forward arrow for LTI Provider if scope is resource.
 1231:             } elsif ($ltiscope eq 'map') {
 1232: # Suppress display of backward arrow for LTI Provider if scope is map and this is first resource.
 1233: # Suppress display of forward arrow for LTI Provider if scope is map and this is the last resource.
 1234:                 my $showforw = 1;
 1235:                 my $showback = 1;
 1236:                 my $navmap = Apache::lonnavmaps::navmap->new();
 1237:                 if (ref($navmap)) {
 1238:                     my $mapres = $navmap->getResourceByUrl($ltiuri);
 1239:                     if (ref($mapres)) {
 1240:                         if ($navmap->isLastResource($mapres,$env{'request.symb'})) {
 1241:                             $showforw = 0;
 1242:                         }
 1243:                         if ($navmap->isFirstResource($mapres,$env{'request.symb'})) {
 1244:                             $showback = 0;
 1245:                         }
 1246:                     }
 1247:                 }
 1248:                 if ($showback) {
 1249:                     $menuitems.="
 1250: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1";
 1251:                 }
 1252:                 if ($showforw) {
 1253:                     $menuitems.="
 1254: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3";
 1255:                 }
 1256:             } elsif (($crstype ne 'Placement') || ($env{'request.role.adv'})) {
 1257:                 $menuitems.="
 1258: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
 1259: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3";
 1260:             } else {
 1261: # Suppress display of backward arrow for Placement Tests
 1262: # Suppress display of forward arrow for Placement Tests if this is the last resource.
 1263:                 my $showforw = 1;
 1264:                 if ($env{'request.symb'}) {
 1265:                     my $navmap = Apache::lonnavmaps::navmap->new();
 1266:                     if (ref($navmap)) {
 1267:                         if (&Apache::lonplacementtest::is_lastres($env{'request.symb'},$navmap)) {
 1268:                             $showforw = 0;
 1269:                         }
 1270:                     }
 1271:                 }
 1272:                 if ($showforw) {
 1273:                     $menuitems.="
 1274: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3";
 1275:                 }
 1276:             }
 1277: 	    $menuitems .= (<<ENDMENUITEMS);
 1278: 
 1279: c&6&3
 1280: c&8&1
 1281: c&8&2
 1282: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
 1283: ENDMENUITEMS
 1284:             $got_prt = 1;
 1285:             if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
 1286:                 && (!$env{'request.enc'})) {
 1287:                 my $privurl = $env{'request.uri'};
 1288:                 $privurl =~ s{^/res/}{/priv/};
 1289:                 my ($cnum,$cdom) = &Apache::loncommon::crsauthor_url($privurl);
 1290:                 if ($cnum) {
 1291:                     $crsauthor = 1;
 1292:                 } else {
 1293:                     # wishlist is only available for users with access to resource-pool
 1294:                     # and links can only be set for resources within the resource-pool
 1295:                     $menuitems .= (<<ENDMENUITEMS);
 1296: 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
 1297: ENDMENUITEMS
 1298:                     $got_wishlist = 1;
 1299:                 }
 1300:             }
 1301: 
 1302: my $currentURL = &Apache::loncommon::get_symb();
 1303: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
 1304: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
 1305: $menuitems.="s&9&3&";
 1306: if(length($annotation) > 0){
 1307: 	$menuitems.="anot2.png";
 1308: }else{
 1309: 	$menuitems.="anot.png";
 1310: }
 1311: $menuitems.="&Notes&&annotate()&";
 1312: $menuitems.="Make notes and annotations about this resource&&1\n";
 1313: my $is_mobile;
 1314: if ($env{'browser.mobile'}) {
 1315:     $is_mobile = 1;
 1316: }
 1317: 
 1318:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
 1319: 		if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) &&
 1320:                     ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/(docs/|default_\d+\.page$)}) &&
 1321:                     ($env{'request.noversionuri'} !~ m{^/adm/.+/ext\.tool$})) {
 1322: 		    $menuitems.=(<<ENDREALRES);
 1323: s&6&3&catalog.png&Info&info[_1]&catalog_info(currentURL,'$is_mobile')&Show Metadata
 1324: ENDREALRES
 1325:                 }
 1326:                 unless (($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/(docs/|default_\d+\.page$)}) ||
 1327:                         ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) ||
 1328:                         ($env{'request.noversionuri'} =~ m{^/adm/.+/ext\.tool$})) {
 1329:                     $menuitems.=(<<ENDREALRES);
 1330: s&8&1&eval.png&Evaluate&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
 1331: ENDREALRES
 1332:                 }
 1333:                 unless ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) {
 1334:                     $menuitems.=(<<ENDREALRES);
 1335: 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
 1336: ENDREALRES
 1337:                 }
 1338: 	    }
 1339:         }
 1340: 	if ($env{'request.uri'} =~ /^\/res/) {
 1341:             unless ($got_prt) {
 1342: 	        $menuitems .= (<<ENDMENUITEMS);
 1343: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
 1344: ENDMENUITEMS
 1345:                 $got_prt = 1;
 1346:             }
 1347:             unless (($got_wishlist) || ($crsauthor)) {
 1348:                 if (($env{'user.adv'}) && (!$env{'request.enc'})) {
 1349:                     # wishlist is only available for users with access to resource-pool
 1350:                     $menuitems .= (<<ENDMENUITEMS);
 1351: 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
 1352: ENDMENUITEMS
 1353:                     $got_wishlist = 1;
 1354:                 }
 1355: 	    }
 1356:         }
 1357:         my $buttons='';
 1358:         foreach (split(/\n/,$menuitems)) {
 1359: 	    my ($command,@rest)=split(/\&/,$_);
 1360:             my $idx=10*$rest[0]+$rest[1];
 1361:             if (&hidden_button_check() eq 'yes') {
 1362:                 if ($idx == 21 ||$idx == 23) {
 1363:                     $buttons.=&switch('','',@rest);
 1364:                 } else {
 1365:                     $buttons.=&clear(@rest);
 1366:                 }
 1367:             } else {  
 1368:                 if ($command eq 's') {
 1369: 	            $buttons.=&switch('','',@rest);
 1370:                 } else {
 1371:                     $buttons.=&clear(@rest);
 1372:                 }
 1373:             }
 1374:         }
 1375:         my ($showprogress,$linkprotout);
 1376:         if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
 1377:             $showprogress = &placement_progress();
 1378:         }
 1379:         if ($env{'request.deeplink.login'}) {
 1380:             $linkprotout = &linkprot_exit();
 1381:         }
 1382: 
 1383: 	my $addremote=0;
 1384: 	foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
 1385: 
 1386:     if ($addremote) {
 1387:         my ($countdown,$buttonshide);
 1388:         if ($env{'request.filename'} =~ /\.page$/) {
 1389:             my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
 1390:             if (ref($breadcrumb_tools{'tools'}) eq 'ARRAY') {
 1391:                 $countdown = $breadcrumb_tools{'tools'}->[0];
 1392:             }
 1393:             $buttonshide = $pagebuttonshide;
 1394:         } else {
 1395:             $countdown = &countdown_timer();
 1396:             $buttonshide = &hidden_button_check();
 1397:         }
 1398:         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
 1399: 
 1400:             &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1401:                 'navigation', @inlineremote[21,23]);
 1402: 
 1403:         if ($buttonshide eq 'yes') {
 1404:             if ($countdown) {
 1405:                 &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
 1406:             }
 1407:             if ($linkprotout) {
 1408:                 &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
 1409:             }
 1410:             if ($showprogress) {
 1411:                 &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$showprogress);
 1412:             }
 1413:         } else {
 1414:             my @tools = @inlineremote[93,91,81,82,83];
 1415:             if ($countdown) {
 1416:                 unshift(@tools,$countdown);
 1417:             }
 1418:             if ($linkprotout) {
 1419:                 unshift(@tools,$linkprotout);
 1420:             }
 1421:             &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1422:                 'tools',@tools);
 1423: 
 1424:             #publish button in construction space
 1425:             if ($env{'request.state'} eq 'construct'){
 1426:                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1427:                      'advtools', $inlineremote[63]);
 1428:             } else {
 1429:                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1430:                      'tools', $inlineremote[63]);
 1431:             }
 1432:             &advtools_crumbs(@inlineremote);
 1433:         }
 1434:     } else {
 1435:         if ($showprogress) {
 1436:             &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$showprogress);
 1437:         }
 1438:         if ($linkprotout) {
 1439:             &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
 1440:         }
 1441:     }
 1442:     my ($topic_help,$topic_help_text);
 1443:     if ($is_const_dir == 2) {
 1444:         if ((($ENV{'SERVER_PORT'} == 443) || 
 1445:              ($Apache::lonnet::protocol{$Apache::lonnet::perlvar{'lonHostID'}} eq 'https')) && 
 1446:             (&Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},'webdav'))) {
 1447:             $topic_help = 'Authoring_WebDAV,Authoring_WebDAV_Mac_10v6,Authoring_WebDAV_Mac_10v10,'.
 1448:                           'Authoring_WebDAV_Windows_v7,Authoring_WebDAV_Linux_Centos';
 1449:             $topic_help_text = 'About WebDAV access';
 1450:         }
 1451:     }
 1452:     if (ref($showncrumbsref)) {
 1453:         $$showncrumbsref = 1;
 1454:     }
 1455:     return   &Apache::lonhtmlcommon::scripttag('', 'start')
 1456:            . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'','','','',$topic_help,$topic_help_text)
 1457:            . &Apache::lonhtmlcommon::scripttag('', 'end');
 1458: }
 1459: 
 1460: sub get_editbutton {
 1461:     my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg,$hostname) = @_;
 1462:     my $jscall;
 1463:     if (($forceview) && ($env{'form.todocs'})) {
 1464:         my ($folderpath,$command,$navmap);
 1465:         if ($env{'request.symb'}) {
 1466:             $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'},\$navmap);
 1467:         } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
 1468:             $folderpath = $env{'form.folderpath'};
 1469:             $command = '&forcesupplement=1';
 1470:         }
 1471:         $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
 1472:         $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
 1473:     } else {
 1474:         my $suppanchor;
 1475:         if ($env{'form.folderpath'}) {
 1476:             $suppanchor = $env{'form.anchor'};
 1477:         }
 1478:         my $shownsymb;
 1479:         if ($env{'request.symb'}) {
 1480:             $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
 1481:         }
 1482:         $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
 1483:                                                 $forceedit,$forcereg,$env{'request.symb'},$shownsymb,
 1484:                                                 &escape($env{'form.folderpath'}),
 1485:                                                 &escape($env{'form.title'}),$hostname,
 1486:                                                 $env{'form.idx'},&escape($env{'form.suppurl'}),
 1487:                                                 $env{'form.todocs'},$suppanchor);
 1488:     }
 1489:     if ($jscall) {
 1490:         my $icon = 'pcstr.png';
 1491:         my $label = 'Edit';
 1492:         if ($forceview) {
 1493:             $icon = 'tolastloc.png';
 1494:             $label = 'Exit Editing';
 1495:         }
 1496:         &switch('','',6,1,$icon,$label,'resource[_2]',
 1497:                 $jscall,"Edit this resource");
 1498:         return 1;
 1499:     }
 1500:     return;
 1501: }
 1502: 
 1503: sub prepare_functions {
 1504:     my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs,$hostname) = @_;
 1505:     unless ($env{'request.registered'}) {
 1506:         undef(@inlineremote);
 1507:     }
 1508:     my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
 1509:         $forceview);
 1510: 
 1511:     if ($env{'request.course.id'}) {
 1512:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 1513:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1514:         $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
 1515:     }
 1516: 
 1517:     my $editbutton = '';
 1518:     my $viewsrcbutton = '';
 1519:     my $clientip = &Apache::lonnet::get_requestor_ip();
 1520: #
 1521: # Determine whether or not to display 'Edit' or 'View Source' icon/button
 1522: #
 1523:     if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
 1524:         my $blocked = &Apache::loncommon::blocking_status('about',$clientip,$2,$1);
 1525:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
 1526:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1527:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
 1528:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
 1529:         if (($cfile) && ($home ne '') && ($home ne 'no_host') && (!$blocked)) {
 1530:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1531:                                           $forceedit,$forceview,$forcereg);
 1532:         }
 1533:     } elsif ((!$env{'request.course.id'}) &&
 1534:              ($env{'user.author'}) && ($env{'request.filename'}) &&
 1535:              ($env{'request.role'} !~/^(aa|ca|au)/)) {
 1536: #
 1537: # Currently do not have the role of author or co-author.
 1538: # Do we have authoring privileges for the resource?
 1539: #
 1540:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
 1541:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1542:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
 1543:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
 1544:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
 1545:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1546:                                           $forceedit,$forceview,$forcereg);
 1547:         }
 1548:     } elsif ($env{'request.course.id'}) {
 1549: #
 1550: # This applies in course context
 1551: #
 1552:         if (($perms{'mdc'}) &&
 1553:             (($resurl =~ m{^/?public/$cdom/$cnum/syllabus}) ||
 1554:              ($resurl =~ m{^/?uploaded/$cdom/$cnum/portfolio/syllabus/}) ||
 1555:              (($resurl =~ m{^/?uploaded/$cdom/$cnum/default_\d+\.sequence$}) && ($env{'form.navmap'})))) {
 1556:             if ($resurl =~ m{^/}) {
 1557:                 $cfile = $resurl;
 1558:             } else {
 1559:                 $cfile = "/$resurl";
 1560:             }
 1561:             $home = &Apache::lonnet::homeserver($cnum,$cdom);
 1562:             if ($env{'form.forceedit'}) {
 1563:                 $forceview = 1;
 1564:             } else {
 1565:                 $forceedit = 1;
 1566:             }
 1567:             if ($cfile =~ m{^/uploaded/$cdom/$cnum/default_\d+\.sequence$}) {
 1568:                 my $text = 'Edit Folder';
 1569:                 &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
 1570:                         "gocmd('/adm/coursedocs','direct')",
 1571:                         'Folder/Page Content');
 1572:                 $editbutton = 1;
 1573:             } else {
 1574:                 $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1575:                                               $forceedit,$forceview,$forcereg,
 1576:                                               $hostname);
 1577:             }
 1578:         } elsif (($resurl eq '/adm/extresedit') &&
 1579:                  (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
 1580:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1581:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
 1582:                                                $env{'form.symb'});
 1583:             if ($cfile ne '') {
 1584:                 $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1585:                                               $forceedit,$forceview,$forcereg);
 1586:             }
 1587:         } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
 1588:                  (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
 1589:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1590:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
 1591:                                                $env{'form.symb'});
 1592:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1593:                                           $forceedit,$forceview,$forcereg);
 1594:         } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
 1595:                  ($resurl ne '/cgi-bin/printout.pl')) {
 1596:             if ($env{'request.filename'}) {
 1597:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
 1598:                 ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1599:                     &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
 1600:                         &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
 1601:                 if ($cfile ne '') {
 1602:                     $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1603:                                                   $forceedit,$forceview,$forcereg,
 1604:                                                   $hostname);
 1605:                 }
 1606:                 if ((($cfile eq '') || (!$editbutton)) &&
 1607:                     ($resurl =~ /$LONCAPA::assess_re/)) {
 1608:                     my $showurl = &Apache::lonnet::clutter($resurl);
 1609:                     my $crs_sec = $env{'request.course.id'} . (($env{'request.course.sec'} ne '')
 1610:                                                               ? "/$env{'request.course.sec'}"
 1611:                                                               : '');
 1612:                     if ((&Apache::lonnet::allowed('cre','/')) &&
 1613:                         (&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open')) {
 1614:                         $viewsrcbutton = 1;
 1615:                     } elsif (&Apache::lonnet::allowed('vxc',$crs_sec)) {
 1616:                         if ($showurl =~ m{^\Q/res/$cdom/\E($match_username)/}) {
 1617:                             my $auname = $1;
 1618:                             if (($env{'request.course.adhocsrcaccess'} ne '') &&
 1619:                                 (grep(/^\Q$auname\E$/,split(/,/,$env{'request.course.adhocsrcaccess'})))) {
 1620:                                 $viewsrcbutton = 1;
 1621:                             } elsif ((&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open') &&
 1622:                                      (&Apache::lonnet::allowed('bre',$crs_sec))) {
 1623:                                 $viewsrcbutton = 1;
 1624:                             }
 1625:                         }
 1626:                     }
 1627:                     if ($viewsrcbutton) {
 1628:                         &switch('','',6,1,'pcstr.png','View Source','resource[_2]','open_source()',
 1629:                                 'View source code');
 1630:                     }
 1631:                 }
 1632:             }
 1633:         }
 1634:     }
 1635: # End determination of 'Edit' icon/button display
 1636: 
 1637:     if ($env{'request.course.id'}) {
 1638: # This applies to about me page for users in a course
 1639:         if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
 1640:             my ($sdom,$sname) = ($1,$2);
 1641:             unless (&Apache::lonnet::is_course($sdom,$sname)) {
 1642:                 my $blocked = &Apache::loncommon::blocking_status('about',$clientip,$sname,$sdom);
 1643:                 unless ($blocked) {
 1644:                     &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
 1645:                             '',
 1646:                             "go('/adm/email?compose=individual&amp;recname=$sname&amp;recdom=$sdom')",
 1647:                                 'Send message to specific user');
 1648:                 }
 1649:             }
 1650:             my $hideprivileged = 1;
 1651:             if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
 1652:                                            $hideprivileged)) {
 1653:                 foreach my $priv ('vsa','vgr','srm') {
 1654:                     $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
 1655:                     if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
 1656:                         $perms{$priv} =
 1657:                             &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
 1658:                     }
 1659:                 }
 1660:                 if ($perms{'vsa'}) {
 1661:                     &switch('','',6,5,'trck-22x22.png','Activity',
 1662:                             '',
 1663:                             "go('/adm/trackstudent?selected_student=$sname:$sdom')",
 1664:                             'View recent activity by this person');
 1665:                 }
 1666:                 if ($perms{'vgr'}) {
 1667:                     &switch('','',6,6,'rsrv-22x22.png','Reservations',
 1668:                             '',
 1669:                             "go('/adm/slotrequest?command=showresv&amp;origin=aboutme&amp;uname=$sname&amp;udom=$sdom')",
 1670:                             'Slot reservation history');
 1671:                 }
 1672:                 if ($perms{'srm'}) {
 1673:                     &switch('','',6,7,'contact-new-22x22.png','Records',
 1674:                             '',
 1675:                             "go('/adm/email?recordftf=retrieve&amp;recname=$sname&amp;recdom=$sdom')",
 1676:                             'Add records');
 1677:                 }
 1678:             }
 1679:         }
 1680:         if (($env{'form.folderpath'} =~ /^supplemental/) &&
 1681:             (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
 1682:             (($resurl =~ m{^/adm/wrapper/ext/}) ||
 1683:              ($resurl =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) ||
 1684:              ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
 1685:              ($resurl eq '/adm/supplemental') ||
 1686:              ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
 1687:              ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
 1688:             my @folders=split('&',$env{'form.folderpath'});
 1689:             if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
 1690:                 my $suppanchor;
 1691:                 if ($resurl =~ m{^/adm/wrapper/ext/}) {
 1692:                     $suppanchor = $env{'form.anchor'};
 1693:                 }
 1694:                 my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
 1695:                 my $link = '/adm/coursedocs?command=direct&amp;forcesupplement=1&amp;supppath='.
 1696:                            "$esc_path&amp;anchor=$suppanchor";
 1697:                 if ($env{'request.use_absolute'} ne '') {
 1698:                     $link = $env{'request.use_absolute'}.$link;
 1699:                 }
 1700:                 &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
 1701:                         "location.href='$link'",'Folder/Page Content');
 1702:             }
 1703:         }
 1704:     }
 1705: 
 1706: # End checking for items for about me page for users in a course
 1707:     if ($docscrumbs) {
 1708:         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
 1709:         &advtools_crumbs(@inlineremote);
 1710:         return $editbutton;
 1711:     } elsif ($env{'request.registered'}) {
 1712:         return $editbutton || $viewsrcbutton;
 1713:     } else {
 1714:         if (ref($bread_crumbs) eq 'ARRAY') {
 1715:             if (@inlineremote > 0) {
 1716:                 if (ref($advtools) eq 'ARRAY') {
 1717:                     @{$advtools} = @inlineremote;
 1718:                 }
 1719:             }
 1720:             return;
 1721:         } elsif (@inlineremote > 0) {
 1722:             &Apache::lonhtmlcommon::clear_breadcrumb_tools();
 1723:             &advtools_crumbs(@inlineremote);
 1724:             return   &Apache::lonhtmlcommon::scripttag('', 'start')
 1725:                    . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
 1726:                    . &Apache::lonhtmlcommon::scripttag('', 'end');
 1727:         }
 1728:     }
 1729: }
 1730: 
 1731: sub advtools_crumbs {
 1732:     my @funcs = @_;
 1733:     if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
 1734:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1735:             'advtools', @funcs[61,64,65,66,67,74]);
 1736:     } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
 1737:         if ($env{'request.state'} eq 'construct') {
 1738:             &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1739:                 'advtools', @funcs[61,73,74,71,72]);
 1740:         } else {
 1741:             &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1742:                 'advtools', @funcs[61,71,72,73,74,75,92]);
 1743:         }
 1744:     } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
 1745:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1746:             'advtools', $funcs[61]);
 1747:     }
 1748:     return;
 1749: }
 1750: 
 1751: # ================================================================== Raw Config
 1752: 
 1753: sub clear {
 1754:     my ($row,$col)=@_;
 1755:     $inlineremote[10*$row+$col]='';
 1756:     return ''; 
 1757: }
 1758: 
 1759: # ============================================ Switch a button or create a link
 1760: # Switch acts on the javascript that is executed when a button is clicked.  
 1761: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
 1762: 
 1763: sub switch {
 1764:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak,$form)=@_;
 1765:     $act=~s/\$uname/$uname/g;
 1766:     $act=~s/\$udom/$udom/g;
 1767:     $top=&mt($top);
 1768:     $bot=&mt($bot);
 1769:     $desc=&mt($desc);
 1770:     my $idx=10*$row+$col;
 1771:     $category_members{$cat}.=':'.$idx;
 1772: 
 1773: # Inline Menu
 1774:     if ($nobreak==2) { return ''; }
 1775:     my $text=$top.' '.$bot;
 1776:     $text=~s/\s*\-\s*//gs;
 1777: 
 1778:     my $pic=
 1779: 	   '<img alt="'.$text.'" src="'.
 1780: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
 1781: 	   '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
 1782:     if ($env{'browser.interface'} eq 'faketextual') {
 1783: # Main Menu
 1784: 	   if ($nobreak==3) {
 1785: 	       $inlineremote[$idx]="\n".
 1786: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
 1787: 		   '</td><td align="left">'.
 1788: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
 1789: 	   } elsif ($nobreak) {
 1790: 	       $inlineremote[$idx]="\n<tr>".
 1791: 		   '<td align="left">'.
 1792: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
 1793:                     <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>';
 1794: 	   } else {
 1795: 	       $inlineremote[$idx]="\n<tr>".
 1796: 		   '<td align="left">'.
 1797: 		   '<a href="javascript:'.$act.';">'.$pic.
 1798: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
 1799: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
 1800: 	   }
 1801:     } else {
 1802: # Inline Menu
 1803:         my @tools = (93,91,81,82,83);
 1804:         unless ($env{'request.state'} eq 'construct') {
 1805:             push(@tools,63);
 1806:         }
 1807:         if ((($env{'environment.icons'} eq 'iconsonly') ||
 1808:              ($env{'environment.icons'} eq '') && ($env{'request.lti.login'})) &&
 1809:             (grep(/^$idx$/,@tools))) {
 1810:             $inlineremote[$idx] =
 1811:         '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
 1812:         } else {
 1813:             $inlineremote[$idx] =
 1814:        '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
 1815:        '<span class="LC_menubuttons_inline_text">'.$top.'&nbsp;</span></a>'.$form;
 1816:         }
 1817:     }
 1818:     return '';
 1819: }
 1820: 
 1821: sub secondlevel {
 1822:     my $output='';
 1823:     my 
 1824:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
 1825:     if ($prt eq 'any') {
 1826: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1827:     } elsif ($prt=~/^r(\w+)/) {
 1828:         if ($rol eq $1) {
 1829:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1830:         }
 1831:     }
 1832:     return $output;
 1833: }
 1834: 
 1835: sub inlinemenu {
 1836:     undef(@inlineremote);
 1837:     undef(%category_members);
 1838: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
 1839:     &rawconfig(1);
 1840:     my $output='<table><tr>';
 1841:     for (my $col=1; $col<=2; $col++) {
 1842:         $output.='<td class="LC_mainmenu_col_fieldset">';
 1843:         for (my $row=1; $row<=8; $row++) {
 1844:             foreach my $cat (keys(%category_members)) {
 1845:                if ($category_positions{$cat} ne "$col,$row") { next; }
 1846:                #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
 1847:                $output.='<div class="LC_Box LC_400Box">';
 1848: 	       $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
 1849:                $output.='<table>';
 1850:                my %active=();
 1851:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
 1852:                   if ($inlineremote[$menu_item]) {
 1853:                      $active{$menu_item}=1;
 1854:                   }
 1855:                }  
 1856:                foreach my $item (sort(keys(%active))) {
 1857:                   $output.=$inlineremote[$item];
 1858:                }
 1859:                $output.='</table>';
 1860:                $output.='</div>';
 1861:             }
 1862:          }
 1863:          $output.="</td>";
 1864:     }
 1865:     $output.="</tr></table>";
 1866:     return $output;
 1867: }
 1868: 
 1869: sub rawconfig {
 1870: #
 1871: # This evaluates mydesk.tab
 1872: # Need to add more positions and more privileges to deal with all
 1873: # menu items.
 1874: #
 1875:     my $textualoverride=shift;
 1876:     my $output='';
 1877:     return '' unless $textualoverride;
 1878:     my $uname=$env{'user.name'};
 1879:     my $udom=$env{'user.domain'};
 1880:     my $adv=$env{'user.adv'};
 1881:     my $show_course=&Apache::loncommon::show_course();
 1882:     my $author=$env{'user.author'};
 1883:     my $crs='';
 1884:     my $crstype='';
 1885:     if ($env{'request.course.id'}) {
 1886:        $crs='/'.$env{'request.course.id'};
 1887:        if ($env{'request.course.sec'}) {
 1888: 	   $crs.='_'.$env{'request.course.sec'};
 1889:        }
 1890:        $crs=~s/\_/\//g;
 1891:        $crstype = &Apache::loncommon::course_type();
 1892:     }
 1893:     my $pub=($env{'request.state'} eq 'published');
 1894:     my $con=($env{'request.state'} eq 'construct');
 1895:     my $rol=$env{'request.role'};
 1896:     my $requested_domain;
 1897:     if ($rol) {
 1898:        $requested_domain = $env{'request.role.domain'};
 1899:     }
 1900:     foreach my $line (@desklines) {
 1901:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
 1902:         $prt=~s/\$uname/$uname/g;
 1903:         $prt=~s/\$udom/$udom/g;
 1904:         if ($prt =~ /\$crs/) {
 1905:             next unless ($env{'request.course.id'});
 1906:             next if ($crstype eq 'Community');
 1907:             $prt=~s/\$crs/$crs/g;
 1908:         } elsif ($prt =~ /\$cmty/) {
 1909:             next unless ($env{'request.course.id'});
 1910:             next if ($crstype ne 'Community');
 1911:             $prt=~s/\$cmty/$crs/g;
 1912:         }
 1913:         if ($prt =~ m/\$requested_domain/) {
 1914:             if ((!$requested_domain) && ($pro eq 'pbre') && ($env{'user.adv'})) {
 1915:                 $prt=~s/\$requested_domain/$env{'user.domain'}/g;
 1916:             } else {
 1917:                 $prt=~s/\$requested_domain/$requested_domain/g;
 1918:             }
 1919:         }
 1920:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
 1921:         if ($pro eq 'clear') {
 1922: 	    $output.=&clear($row,$col);
 1923:         } elsif ($pro eq 'any') {
 1924:                $output.=&secondlevel(
 1925: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1926: 	} elsif ($pro eq 'smp') {
 1927:             unless ($adv) {
 1928:                $output.=&secondlevel(
 1929:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1930:             }
 1931:         } elsif ($pro eq 'adv') {
 1932:             if ($adv) {
 1933:                $output.=&secondlevel(
 1934: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1935:             }
 1936: 	} elsif ($pro eq 'shc') {
 1937:             if ($show_course) {
 1938:                $output.=&secondlevel(
 1939:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1940:             }
 1941:         } elsif ($pro eq 'nsc') {
 1942:             if (!$show_course) {
 1943:                $output.=&secondlevel(
 1944: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1945:             }
 1946:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
 1947:             my $priv = $1;
 1948:             if ($priv =~ /^mdc(Course|Community)/) {
 1949:                 if ($crstype eq $1) {
 1950:                     $priv = 'mdc';
 1951:                 } else {
 1952:                     next;
 1953:                 }
 1954:             }
 1955:             if ((($priv eq 'bre') && (&Apache::lonnet::allowed($priv,$prt) eq 'F')) ||
 1956:                 (($priv ne 'bre') && (&Apache::lonnet::allowed($priv,$prt)))) {
 1957:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1958:             }
 1959:         } elsif ($pro eq 'course')  {
 1960:             if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
 1961:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1962: 	    }
 1963:         } elsif ($pro eq 'community')  {
 1964:             if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
 1965:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1966:             }
 1967:         } elsif ($pro =~ /^courseenv_(.*)$/) {
 1968:             my $key = $1;
 1969:             if ($crstype ne 'Community') {
 1970:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
 1971:                 if ($key eq 'canuse_pdfforms') {
 1972:                     if ($env{'request.course.id'} && $coursepref eq '') {
 1973:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
 1974:                         $coursepref = $domdefs{'canuse_pdfforms'};
 1975:                     }
 1976:                 }
 1977:                 if ($coursepref) { 
 1978:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1979:                 }
 1980:             }
 1981:         } elsif ($pro =~ /^communityenv_(.*)$/) {
 1982:             my $key = $1;
 1983:             if ($crstype eq 'Community') {
 1984:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
 1985:                 if ($key eq 'canuse_pdfforms') {
 1986:                     if ($env{'request.course.id'} && $coursepref eq '') {
 1987:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
 1988:                         $coursepref = $domdefs{'canuse_pdfforms'};
 1989:                     }
 1990:                 }
 1991:                 if ($coursepref) { 
 1992:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1993:                 }
 1994:             }
 1995:         } elsif ($pro =~ /^course_(.*)$/) {
 1996:             # Check for permissions inside of a course
 1997:             if (($env{'request.course.id'}) && ($crstype ne 'Community') && 
 1998:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 1999:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 2000:                  )) {
 2001:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 2002: 	    }
 2003:         } elsif ($pro =~ /^community_(.*)$/) {
 2004:             # Check for permissions inside of a community
 2005:             if (($env{'request.course.id'}) && ($crstype eq 'Community') &&   
 2006:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 2007:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 2008:                  )) {
 2009:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 2010:             }
 2011:         } elsif ($pro eq 'author') {
 2012:             if ($author) {
 2013:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
 2014:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
 2015:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
 2016:                     # Check that we are on the correct machine
 2017:                     my $cadom=$requested_domain;
 2018:                     my $caname=$env{'user.name'};
 2019:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
 2020: 		       ($cadom,$caname)=
 2021:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
 2022:                     }                       
 2023:                     $act =~ s/\$caname/$caname/g;
 2024:                     $act =~ s/\$cadom/$cadom/g;
 2025:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
 2026: 		    my $allowed=0;
 2027: 		    my @ids=&Apache::lonnet::current_machine_ids();
 2028: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 2029: 		    if ($allowed) {
 2030:                         $output.=&switch($caname,$cadom,
 2031:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
 2032:                     }
 2033:                 }
 2034:             }
 2035:         } elsif ($pro eq 'tools') {
 2036:             my @tools = ('aboutme','blog','portfolio');
 2037:             if (grep(/^\Q$prt\E$/,@tools)) {
 2038:                 if (!&Apache::lonnet::usertools_access($env{'user.name'},
 2039:                                                        $env{'user.domain'},
 2040:                                                        $prt,undef,'tools')) {
 2041:                     $output.=&clear($row,$col);
 2042:                     next;
 2043:                 }
 2044:             } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
 2045:                 if (($prt eq 'reqcrsnsc') && ($show_course))   {
 2046:                     next;
 2047:                 }
 2048:                 if (($prt eq 'reqcrsshc') && (!$show_course)) {
 2049:                     next;
 2050:                 }
 2051:                 my $showreqcrs = &check_for_rcrs();
 2052:                 if (!$showreqcrs) {
 2053:                     $output.=&clear($row,$col);
 2054:                     next;
 2055:                 }
 2056:             }
 2057:             $prt='any';
 2058:             $output.=&secondlevel(
 2059:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 2060:         }
 2061:     }
 2062:     return $output;
 2063: }
 2064: 
 2065: sub check_for_rcrs {
 2066:     my $showreqcrs = 0;
 2067:     my @reqtypes = ('official','unofficial','community','textbook','placement');
 2068:     foreach my $type (@reqtypes) {
 2069:         if (&Apache::lonnet::usertools_access($env{'user.name'},
 2070:                                               $env{'user.domain'},
 2071:                                               $type,undef,'requestcourses')) {
 2072:             $showreqcrs = 1;
 2073:             last;
 2074:         }
 2075:     }
 2076:     if (!$showreqcrs) {
 2077:         foreach my $type (@reqtypes) {
 2078:             if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
 2079:                 my @domains = split(',',$env{'environment.reqcrsotherdom.'.$type});
 2080:                 foreach my $entry (@domains) {
 2081:                     my ($extdom,$extopt) = split(':',$entry);
 2082:                     if (&Apache::lonnet::will_trust('reqcrs',$env{'user.domain'},$extdom)) {
 2083:                         $showreqcrs = 1;
 2084:                         last;
 2085:                     }
 2086:                 }
 2087:                 if ($showreqcrs) {
 2088:                     last;
 2089:                 }
 2090:             }
 2091:         }
 2092:     }
 2093:     return $showreqcrs;
 2094: }
 2095: 
 2096: sub dc_popup_js {
 2097:     my %lt = &Apache::lonlocal::texthash(
 2098:                                           more => '(More ...)',
 2099:                                           less => '(Less ...)',
 2100:                                         );
 2101:     return <<"END";
 2102: 
 2103: function showCourseID() {
 2104:     document.getElementById('dccid').style.display='block';
 2105:     document.getElementById('dccid').style.textAlign='left';
 2106:     document.getElementById('dccid').style.textFace='normal';
 2107:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
 2108:     return;
 2109: }
 2110: 
 2111: function hideCourseID() {
 2112:     document.getElementById('dccid').style.display='none';
 2113:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
 2114:     return;
 2115: }
 2116: 
 2117: END
 2118: 
 2119: }
 2120: 
 2121: sub countdown_toggle_js {
 2122:     return <<"END";
 2123: 
 2124: function toggleCountdown() {
 2125:     var countdownid = document.getElementById('duedatecountdown');
 2126:     var currstyle = countdownid.style.display;
 2127:     if (currstyle == 'inline') {
 2128:         countdownid.style.display = 'none';
 2129:         document.getElementById('ddcountcollapse').innerHTML='';
 2130:         document.getElementById('ddcountexpand').innerHTML='&#9668;&nbsp;';
 2131:     } else {
 2132:         countdownid.style.display = 'inline';
 2133:         document.getElementById('ddcountcollapse').innerHTML='&#9658;&nbsp;';
 2134:         document.getElementById('ddcountexpand').innerHTML='';
 2135:     }
 2136:     return;
 2137: }
 2138: 
 2139: END
 2140: }
 2141: 
 2142: # This creates a "done button" for timed events.  The confirmation box is a jQuery
 2143: # dialog widget. If the interval parameter requires a proctor key for the timed 
 2144: # event to be marked done, there will also be a textbox where that can be entered. 
 2145: # Clicking OK will set the value of LC_interval_done to 'true', and, if needed will 
 2146: # set the value of LC_interval_done_proctorpass to the text entered in that box, 
 2147: # and submit the corresponding form.
 2148: # 
 2149: # The &zero_time() routine in lonhomework.pm is called when a page is rendered if
 2150: # LC_interval_done is true.
 2151: #
 2152: sub done_button_js {
 2153:     my ($type,$width,$height,$proctor,$donebuttontext) = @_;
 2154:     return unless (($type eq 'map') || ($type eq 'resource'));
 2155:     my %lt = &Apache::lonlocal::texthash(
 2156:                  title    => 'WARNING!',
 2157:                  preamble => 'You are trying to end this timed event early.',
 2158:                  map      => 'Confirming that you are done will cause the time to expire and prevent you from changing any answers in the current folder.',
 2159:                  resource => 'Confirming that you are done will cause the time to expire for this question, and prevent you from changing your answer(s).', 
 2160:                  okdone   => 'Click "OK" if you are completely finished.',
 2161:                  cancel   => 'Click "Cancel" to continue working.',
 2162:                  proctor  => 'Ask a proctor to enter the key, then click "OK" if you are completely finished.',
 2163:                  ok       => 'OK',
 2164:                  exit     => 'Cancel',
 2165:                  key      => 'Key:',
 2166:                  nokey    => 'A proctor key is required', 
 2167:     );
 2168:     my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}));
 2169:     my $navmap = Apache::lonnavmaps::navmap->new(); 
 2170:     my ($missing,$tried) = (0,0);
 2171:     if (ref($navmap)) {
 2172:         my @resources=();
 2173:         if ($type eq 'map') {
 2174:             my ($mapurl,$rid,$resurl)=&Apache::lonnet::decode_symb($env{'request.symb'});
 2175:             if ($env{'request.symb'} =~ /\.page$/) {
 2176:                 @resources=$navmap->retrieveResources($resurl,sub { $_[0]->is_problem() });
 2177:             } else {
 2178:                 @resources=$navmap->retrieveResources($mapurl,sub { $_[0]->is_problem() });
 2179:             }
 2180:         } else {
 2181:             my $res = $navmap->getBySymb($env{'request.symb'});
 2182:             if (ref($res)) {
 2183:                 if ($res->is_problem()) {
 2184:                     push(@resources,$res);
 2185:                 }
 2186:             }
 2187:         }
 2188:         foreach my $res (@resources) {
 2189:             if (ref($res->parts()) eq 'ARRAY') {
 2190:                 foreach my $part (@{$res->parts()}) {
 2191:                     if (!$res->tries($part)) {
 2192:                         $missing++;
 2193:                     } else {
 2194:                         $tried++;
 2195:                     }
 2196:                 }
 2197:             }
 2198:         }
 2199:     }
 2200:     if ($missing) {
 2201:         $lt{'miss'} .= '<p class="LC_error">';
 2202:         if ($type eq 'map') {
 2203:             $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,question part,question parts] in this folder.',$missing);
 2204:         } else {
 2205:             $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,part] in this question.',$missing);
 2206:         }
 2207:         if ($missing > 1) {
 2208:             $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit answers for them.').'</span>';
 2209:         } else {
 2210:             $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit an answer for it.').'</p>';
 2211:         }
 2212:     }
 2213:     $donebuttontext = &HTML::Entities::encode($donebuttontext,'<>&"');
 2214:     if ($proctor) {
 2215:         if ($height !~ /^\d+$/) {
 2216:             $height = 400;
 2217:             if ($missing) {
 2218:                 $height += 60; 
 2219:             }
 2220:         }
 2221:         if ($width !~ /^\d+$/) {
 2222:             $width = 400;
 2223:             if ($missing) {
 2224:                 $width += 60;
 2225:             }
 2226:         }
 2227:         return <<END;
 2228: <form method="post" name="LCdoneButton" action="">
 2229:     <input type="hidden" name="LC_interval_done" value="" />
 2230:     <input type="hidden" name="LC_interval_done_proctorpass" value="" />
 2231:     <input type="hidden" name="symb" value="$shownsymb" />
 2232:     <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
 2233: </form>
 2234: 
 2235: <div id="LC_done-confirm" title="$lt{'title'}">
 2236:   <p>$lt{'preamble'} $lt{$type}</p>
 2237:   $lt{'miss'}
 2238:   <p>$lt{'proctor'}</p>
 2239:   <form name="LCdoneButtonProctor" action="">
 2240:     <label>$lt{'key'}<input type="password" name="LC_interval_done_proctorkey" value="" /></label>
 2241:     <input type="submit" tabindex="-1" style="position:absolute; top:-1000px" />
 2242:   </form>
 2243:   <p>$lt{'cancel'}</p>
 2244: </div>
 2245: 
 2246: <script type="text/javascript">
 2247: // <![CDATA[
 2248:     \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
 2249:     \$( "#LC_done-confirm-opener" ).on("click", function() {
 2250:         \$( "#LC_done-confirm" ).dialog("open");
 2251:         \$( "#LC_done-confirm" ).dialog({
 2252:             height: $height,
 2253:             width: $width,
 2254:             modal: true,
 2255:             resizable: false,
 2256:             buttons: [
 2257:                 {
 2258:                     text: "$lt{'ok'}",
 2259:                     click: function() {
 2260:                         var proctorkey = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
 2261:                         if ((proctorkey == '') || (proctorkey == null)) {
 2262:                             alert("$lt{'nokey'}"); 
 2263:                         } else { 
 2264:                             \$( '[name="LC_interval_done"]' )[0].value = 'true';
 2265:                             \$( '[name="LC_interval_done_proctorpass"]' )[0].value = proctorkey;
 2266:                             \$( '[name="LCdoneButton"]' )[0].submit();
 2267:                         }
 2268:                     },
 2269:                 },
 2270:                 {
 2271:                     text: "$lt{'exit'}",
 2272:                     click: function() {
 2273:                         \$("#LC_done-confirm").dialog( "close" );
 2274:                     }
 2275:                 }
 2276:             ],
 2277:             close: function() {
 2278:                 \$( '[name="LC_interval_done_proctorkey"]' )[0].value = '';
 2279:             }
 2280:         });
 2281:         \$( "#LC_done-confirm" ).find( "form" ).on( "submit", function( event ) {
 2282:             event.preventDefault();
 2283:             \$( '[name="LC_interval_done"]' )[0].value = 'true';
 2284:             \$( '[name="LC_interval_done_proctorpass"]' )[0].value = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
 2285:             \$( '[name="LCdoneButton"]' )[0].submit();
 2286:         });
 2287: });
 2288: 
 2289: // ]]>
 2290: </script>
 2291: 
 2292: END
 2293:     } else {
 2294:         if ($height !~ /^\d+$/) {
 2295:             $height = 320;
 2296:             if ($missing) {
 2297:                 $height += 60;
 2298:             }
 2299:         }
 2300:         if ($width !~ /^\d+$/) {
 2301:             $width = 320;
 2302:             if ($missing) {
 2303:                 $width += 60;
 2304:             }
 2305:         }
 2306:         if ($missing) {
 2307:             $lt{'miss'} = '</p>'.$lt{'miss'}.'<p>';
 2308:         }
 2309:         return <<END;
 2310: 
 2311: <form method="post" name="LCdoneButton" action="">
 2312:     <input type="hidden" name="LC_interval_done" value="" />
 2313:     <input type="hidden" name="symb" value="$shownsymb" />
 2314:     <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
 2315: </form>
 2316: 
 2317: <div id="LC_done-confirm" title="$lt{'title'}">
 2318:     <p>$lt{'preamble'} $lt{$type} $lt{'miss'} $lt{'okdone'} $lt{'cancel'}</p>
 2319: </div>
 2320: 
 2321: <script type="text/javascript">
 2322: // <![CDATA[
 2323: \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
 2324: \$( "#LC_done-confirm-opener" ).click(function() {
 2325:     \$( "#LC_done-confirm" ).dialog( "open" );
 2326:     \$( "#LC_done-confirm" ).dialog({
 2327:       resizable: false,
 2328:       height: $height,
 2329:       width: $width,
 2330:       modal: true,
 2331:       buttons: [
 2332:                  {
 2333:                     text: "$lt{'ok'}",
 2334:                     click: function() {
 2335:                         \$( this ).dialog( "close" );
 2336:                         \$( '[name="LC_interval_done"]' )[0].value = 'true';
 2337:                         \$( '[name="LCdoneButton"]' )[0].submit();
 2338:                     },
 2339:                  },
 2340:                  {
 2341:                      text: "$lt{'exit'}",
 2342:                      click: function() {
 2343:                          \$( this ).dialog( "close" );
 2344:                      },
 2345:                   },
 2346:                ],
 2347:        });
 2348: });
 2349: // ]]>
 2350: </script>
 2351: 
 2352: END
 2353:     }
 2354: }
 2355: 
 2356: sub view_as_js {
 2357:     my ($url,$symb) = @_;
 2358:     my %lt = &Apache::lonlocal::texthash(
 2359:                 ente => 'Enter a username or a student/employee ID',
 2360:                 info => 'Information you entered does not match a valid course user',
 2361:     );
 2362:     &js_escape(\%lt);
 2363:     return <<"END";
 2364: 
 2365: function toggleViewAsUser(change) {
 2366:     if (document.getElementById('LC_selectuser')) {
 2367:         var seluserid = document.getElementById('LC_selectuser');
 2368:         var currstyle = seluserid.style.display;
 2369:         if (change == 'off') {
 2370:             document.userview.elements['LC_viewas'].value = '';
 2371:             document.userview.elements['vuname'].value = '';
 2372:             document.userview.elements['vid'].value = '';
 2373:             document.userview.submit();
 2374:             return;
 2375:         }
 2376:         if ((document.getElementById('usexpand')) && (document.getElementById('uscollapse'))) {
 2377:             if (currstyle == 'inline') {
 2378:                 seluserid.style.display = 'none';
 2379:                 document.getElementById('usexpand').innerHTML='&#9658;&nbsp;';
 2380:                 document.getElementById('uscollapse').innerHTML='';
 2381:             } else {
 2382:                 seluserid.style.display = 'inline';
 2383:                 document.getElementById('usexpand').innerHTML='';
 2384:                 document.getElementById('uscollapse').innerHTML='&#9668;&nbsp;';
 2385:                 toggleIdentifier(document.userview);
 2386:             }
 2387:         }
 2388:     }
 2389:     return;
 2390: }
 2391: 
 2392: function validCourseUser(form,change) {
 2393:     var possuname = form.elements['vuname'].value;
 2394:     var possuid = form.elements['vid'].value;
 2395:     var possudom = form.elements['vudom'].value;
 2396:     if ((possuname == '') && (possuid == '')) {
 2397:         if (change == 'off') {
 2398:             form.elements['LC_viewas'].value = '';
 2399:             form.submit();
 2400:         } else {
 2401:             alert("$lt{'ente'}");
 2402:         }
 2403:         return;
 2404:     }
 2405:     var http = new XMLHttpRequest();
 2406:     var url = "/adm/courseuser";
 2407:     var params = "uname="+possuname+"&uid="+possuid+"&udom="+possudom;
 2408:     http.open("POST", url, true);
 2409:     http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 2410:     http.onreadystatechange = function() {
 2411:         if (http.readyState == 4 && http.status == 200) {
 2412:             var data = JSON.parse(http.responseText);
 2413:             if (Array.isArray(data.match)) {
 2414:                var len = data.match.length;
 2415:                if (len == 2) {
 2416:                    if (data.match[0] != '' && data.match[1] != '') {
 2417:                        form.elements['LC_viewas'].value = data.match[0]+':'+data.match[1];
 2418:                        form.submit(); 
 2419:                    }
 2420:                } else {
 2421:                    alert("$lt{'info'}");
 2422:                }
 2423:             }
 2424:         }
 2425:         return;
 2426:     }
 2427:     http.send(params);
 2428:     return false;
 2429: }
 2430: 
 2431: function toggleIdentifier(form) {
 2432:     if ((document.getElementById('LC_vuname')) && (document.getElementById('LC_vid'))) {
 2433:         var radioelem = form.elements['vuidentifier'];
 2434:         if (radioelem.length > 0) {
 2435:             var i;
 2436:             for (i=0; i<radioelem.length; i++) {
 2437:                 if (radioelem[i].checked == true) {
 2438:                     if (radioelem[i].value == 'uname') {
 2439:                         document.getElementById('LC_vuname').type = 'text';
 2440:                         document.getElementById('LC_vid').type = 'hidden';
 2441:                         document.getElementById('LC_vid').value = '';
 2442:                     } else {
 2443:                         document.getElementById('LC_vuname').type = 'hidden';
 2444:                         document.getElementById('LC_vuname').value = '';
 2445:                         document.getElementById('LC_vid').type = 'text';
 2446:                     }
 2447:                     break;
 2448:                 }
 2449:             }
 2450:         }
 2451:     }
 2452:     return;
 2453: }
 2454: 
 2455: END
 2456: }
 2457: 
 2458: sub utilityfunctions {
 2459:     my ($httphost) = @_;
 2460:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
 2461:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
 2462:     if ($currenturl =~ m{^/adm/wrapper/ext/}) {
 2463:         if ($env{'request.external.querystring'}) {
 2464:             $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
 2465:         }
 2466:         my ($anchor) = ($env{'request.symb'} =~ /(\#[^\#]+)$/);
 2467:         if (($anchor) && ($currenturl !~ /\Q$anchor\E$/)) {
 2468:             $currenturl .= $1;
 2469:         }
 2470:     }
 2471:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
 2472: 
 2473:     my $dc_popup_cid;
 2474:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
 2475:                         $env{'course.'.$env{'request.course.id'}.
 2476:                                  '.domain'}.'/'})) {
 2477:         $dc_popup_cid = &dc_popup_js();
 2478:     }
 2479: 
 2480:     my $start_page_annotate = 
 2481:         &Apache::loncommon::start_page('Annotator',undef,
 2482: 				       {'only_body' => 1,
 2483: 					'js_ready'  => 1,
 2484: 					'bgcolor'   => '#BBBBBB',
 2485: 					'add_entries' => {
 2486: 					    'onload' => 'javascript:document.goannotate.submit();'}});
 2487: 
 2488:     my $end_page_annotate = 
 2489:         &Apache::loncommon::end_page({'js_ready' => 1});
 2490: 
 2491:     my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
 2492: 
 2493:     my $esc_url=&escape($currenturl);
 2494:     my $esc_symb=&escape($currentsymb);
 2495:     my $newname = &mt('New Name');
 2496: 
 2497:     my $countdown = &countdown_toggle_js();
 2498: 
 2499:     my $viewuser;
 2500:     if (($env{'request.course.id'}) &&
 2501:         ($env{'request.symb'} ne '') &&
 2502:         ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
 2503:         my $canview;
 2504:         foreach my $priv ('msg','vgr') {
 2505:             $canview = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
 2506:             if (!$canview && $env{'request.course.sec'} ne '') {
 2507:                 $canview =
 2508:                     &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
 2509:             }
 2510:             last if ($canview);
 2511:         }
 2512:         if ($canview) {
 2513:             $viewuser = &view_as_js($esc_url,$esc_symb);
 2514:         }
 2515:     }
 2516: 
 2517:     my ($ltitarget,$deeplinktarget);
 2518:     if ($env{'request.lti.login'}) {
 2519:         $ltitarget = $env{'request.lti.target'};
 2520:     }
 2521:     if ($env{'request.deeplink.login'}) {
 2522:         $deeplinktarget = $env{'request.deeplink.target'};
 2523:     }
 2524: 
 2525:     my $annotateurl = '/adm/annotation';
 2526:     if ($httphost) {
 2527:         $annotateurl = '/adm/annotations';
 2528:     }
 2529:     my $hostvar = '
 2530: function setLCHost() {
 2531:     var lcHostname="";
 2532: ';
 2533:     if ($httphost =~ m{^https?\://}) {
 2534:         $hostvar .= '    var lcServer="'.$httphost.'";'."\n".
 2535:                     '    var hostReg = /^https?:\/\/([^\/]+)$/i;'."\n".
 2536:                     '    var match = hostReg.exec(lcServer);'."\n".
 2537:                     '    if (match.length) {'."\n".
 2538:                     '        if (match[1] == location.hostname) {'."\n".
 2539:                     '            lcHostname=lcServer;'."\n".
 2540:                     '        }'."\n".
 2541:                     '    }'."\n";
 2542:     }
 2543:     
 2544:     $hostvar .= '    return lcHostname;'."\n".
 2545: '}'."\n";
 2546: 
 2547: return (<<ENDUTILITY)
 2548:     $hostvar
 2549:     var currentURL=unescape("$esc_url");
 2550:     var reloadURL=unescape("$esc_url");
 2551:     var currentSymb=unescape("$esc_symb");
 2552: 
 2553: $dc_popup_cid
 2554: 
 2555: $jumptores
 2556: 
 2557: function gopost(url,postdata) {
 2558:    if (url!='') {
 2559:       var lcHostname = setLCHost();
 2560:       this.document.server.action=lcHostname+url;
 2561:       this.document.server.postdata.value=postdata;
 2562:       this.document.server.command.value='';
 2563:       this.document.server.url.value='';
 2564:       this.document.server.symb.value='';
 2565:       this.document.server.submit();
 2566:    }
 2567: }
 2568: 
 2569: function gocmd(url,cmd) {
 2570:    if (url!='') {
 2571:       var lcHostname = setLCHost();
 2572:       this.document.server.action=lcHostname+url;
 2573:       this.document.server.postdata.value='';
 2574:       this.document.server.command.value=cmd;
 2575:       this.document.server.url.value=currentURL;
 2576:       this.document.server.symb.value=currentSymb;
 2577:       this.document.server.submit();
 2578:    }
 2579: }
 2580: 
 2581: function gocstr(url,filename) {
 2582:     if (url == '/adm/cfile?action=delete') {
 2583:         this.document.cstrdelete.filename.value = filename
 2584:         this.document.cstrdelete.submit();
 2585:         return;
 2586:     }
 2587:     if ((url == '/adm/cfile?action=copy') || (url == '/adm/cfile?action=rename')) {
 2588:         this.document.cstrcopy.filename.value = filename;
 2589:         var oldname = filename.substring(filename.lastIndexOf("/") + 1);
 2590:         var newname=prompt('$newname',oldname);
 2591:         if (newname == "" || !newname || newname == oldname)  {
 2592:             return;
 2593:         }
 2594:         if (url == '/adm/cfile?action=rename') {
 2595:             this.document.cstrcopy.action.value = 'rename';
 2596:         } else {
 2597:             this.document.cstrcopy.action.value = 'copy';
 2598:         }
 2599:         this.document.cstrcopy.newfilename.value = newname;
 2600:         this.document.cstrcopy.submit();
 2601:         return;
 2602:     }
 2603:     if (url == '/adm/printout') {
 2604:         this.document.cstrprint.postdata.value = filename
 2605:         this.document.cstrprint.curseed.value = 0;
 2606:         this.document.cstrprint.problemtype.value = 0;
 2607:         if (this.document.lonhomework) {
 2608:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
 2609:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
 2610:             }
 2611:             if (this.document.lonhomework.problemtype) {
 2612: 		if (this.document.lonhomework.problemtype.value) {
 2613: 		    this.document.cstrprint.problemtype.value = 
 2614: 			this.document.lonhomework.problemtype.value;
 2615: 		} else if (this.document.lonhomework.problemtype.options) {
 2616: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
 2617: 			if (this.document.lonhomework.problemtype.options[i].selected) {
 2618: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
 2619: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
 2620: 				}
 2621: 			}
 2622: 		    }
 2623: 		}
 2624: 	    }
 2625: 	}
 2626:         this.document.cstrprint.submit();
 2627:         return;
 2628:     }
 2629:     if (url !='') {
 2630:         this.document.constspace.filename.value = filename;
 2631:         this.document.constspace.action = url;
 2632:         this.document.constspace.submit();
 2633:     }
 2634: }
 2635: 
 2636: function golist(url) {
 2637:    if (url!='' && url!= null) {
 2638:        currentURL = null;
 2639:        currentSymb= null;
 2640:        var lcHostname = setLCHost();
 2641:        var ltitarget = '$ltitarget';
 2642:        var deeplinktarget = '$deeplinktarget';
 2643:        if ((ltitarget == 'iframe') || (deeplinktarget == '_self')) {
 2644:            document.location.href=lcHostname+url;
 2645:        } else {
 2646:            top.location.href=lcHostname+url;
 2647:        }
 2648:    }
 2649: }
 2650: 
 2651: 
 2652: 
 2653: function catalog_info(url,isMobile) {
 2654:     if (isMobile == 1) {
 2655:         openMyModal(url+'.meta?modal=1',500,400,'yes');
 2656:     } else {
 2657:         loncatinfo=window.open(url+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
 2658:     }
 2659: }
 2660: 
 2661: function chat_win() {
 2662:    var lcHostname = setLCHost();
 2663:    lonchat=window.open(lcHostname+'/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
 2664: }
 2665: 
 2666: function group_chat(group) {
 2667:    var lcHostname = setLCHost();
 2668:    var url = lcHostname+'/adm/groupchat?group='+group;
 2669:    var winName = 'LONchat_'+group;
 2670:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 2671: }
 2672: 
 2673: function annotate() {
 2674:    w_Annotator_flag=1;
 2675:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
 2676:    annotator.document.write(
 2677:    '$start_page_annotate'
 2678:   +"<form name='goannotate' target='Annotator' method='post' "
 2679:   +"action='$annotateurl'>"
 2680:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
 2681:   +"<\\/form>"
 2682:   +'$end_page_annotate');
 2683:    annotator.document.close();
 2684: }
 2685: 
 2686: function open_StoredLinks_Import(rat) {
 2687:    var newWin;
 2688:    var lcHostname = setLCHost();
 2689:    if (rat) {
 2690:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
 2691:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
 2692:    }
 2693:    else {
 2694:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import',
 2695:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
 2696:    }
 2697:    newWin.focus();
 2698: }
 2699: 
 2700: function open_source() {
 2701:    sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename='+currentURL,'LONsource',
 2702:                          'height=500,width=600,resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=yes');
 2703: }
 2704: 
 2705: function open_aboutLC() {
 2706:     var isMobile = "$env{'browser.mobile'}";
 2707:     var url = '/adm/about.html';
 2708:     if (isMobile == 1) {
 2709:         openMyModal(url,600,400,'yes');
 2710:     } else {
 2711:         window.open(url,"aboutLONCAPA","height=400,width=600,scrollbars=1,resizable=1,menubar=0,location=1");
 2712:     }
 2713:     return;
 2714: }
 2715: 
 2716: 
 2717: (function (\$) {
 2718:   \$(document).ready(function () {
 2719:     \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
 2720:     /*\@cc_on
 2721:       if (!window.XMLHttpRequest) {
 2722:         \$('.LC_hoverable').each(function () {
 2723:           this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
 2724:           this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
 2725:         });
 2726:       }
 2727:     \@*/
 2728:   });
 2729: }(jQuery));
 2730: 
 2731: $countdown
 2732: 
 2733: $viewuser
 2734: 
 2735: ENDUTILITY
 2736: }
 2737: 
 2738: sub serverform {
 2739:     my $target;
 2740:     unless (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
 2741:         $target = ' target="_top"';
 2742:     }
 2743:     if (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) {
 2744:         $target = ' target="_self"';
 2745:     }
 2746:     return(<<ENDSERVERFORM);
 2747: <form name="server" action="/adm/logout" method="post"$target>
 2748: <input type="hidden" name="postdata" value="none" />
 2749: <input type="hidden" name="command" value="none" />
 2750: <input type="hidden" name="url" value="none" />
 2751: <input type="hidden" name="symb" value="none" />
 2752: </form>
 2753: ENDSERVERFORM
 2754: }
 2755: 
 2756: sub constspaceform {
 2757:     my ($frameset) = @_;
 2758:     my ($target,$printtarget);
 2759:     if ($frameset) {
 2760:         $target = ' target="_parent"';
 2761:         $printtarget = ' target="_parent"';
 2762:     } else {
 2763:         unless ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
 2764:                 (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
 2765:             $target = ' target="_top"';
 2766:             $printtarget = ' target="_top"';
 2767:         }
 2768:     }
 2769:     return(<<ENDCONSTSPACEFORM);
 2770: <form name="constspace" action="/adm/logout" method="post"$target>
 2771: <input type="hidden" name="filename" value="" />
 2772: </form>
 2773: <form name="cstrdelete" action="/adm/cfile" method="post"$target>
 2774: <input type="hidden" name="action" value="delete" /> 
 2775: <input type="hidden" name="filename" value="" />
 2776: </form>
 2777: <form name="cstrprint" action="/adm/printout" method="post"$printtarget>
 2778: <input type="hidden" name="postdata" value="" />
 2779: <input type="hidden" name="curseed" value="" />
 2780: <input type="hidden" name="problemtype" value="" />
 2781: </form>
 2782: <form name="cstrcopy" action="/adm/cfile" method="post"$target>
 2783: <input type="hidden" name="action" value="copy" />
 2784: <input type="hidden" name="filename" value="" />
 2785: <input type="hidden" name="newfilename" value="" />
 2786: </form>
 2787: 
 2788: ENDCONSTSPACEFORM
 2789: }
 2790: 
 2791: sub hidden_button_check {
 2792:     if ( $env{'request.course.id'} eq ''
 2793:          || $env{'request.role.adv'} ) {
 2794: 
 2795:         return;
 2796:     }
 2797:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
 2798:     return $buttonshide; 
 2799: }
 2800: 
 2801: sub roles_selector {
 2802:     my ($cdom,$cnum,$httphost,$target,$menucoll,$menuref) = @_;
 2803:     my $crstype = &Apache::loncommon::course_type();
 2804:     my $now = time;
 2805:     my (%courseroles,%seccount,%courseprivs,%roledesc);
 2806:     my $is_cc;
 2807:     my ($js,$form,$switcher,$has_opa_priv);
 2808:     my $ccrole;
 2809:     if ($crstype eq 'Community') {
 2810:         $ccrole = 'co';
 2811:     } else {
 2812:         $ccrole = 'cc';
 2813:     }
 2814:     my ($privref,$gotsymb,$destsymb);
 2815:     my $destinationurl = $ENV{'REQUEST_URI'};
 2816:     if ($destinationurl =~ /(\?|\&)symb=/) {
 2817:         $gotsymb = 1;
 2818:     } elsif ($destinationurl =~ m{^/enc/}) {
 2819:         my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
 2820:         if ($plainurl =~ /(\?|\&)symb=/) {
 2821:             $gotsymb = 1;
 2822:         }
 2823:     }
 2824:     unless ($gotsymb) {
 2825:         $destsymb = &Apache::lonnet::symbread();
 2826:         if ($destsymb ne '') {
 2827:             $destsymb = &Apache::lonenc::check_encrypt($destsymb);
 2828:         }
 2829:     }
 2830:     my $reqprivs = &required_privs();
 2831:     if (ref($reqprivs) eq 'HASH') {
 2832:         my $destination = $destinationurl;
 2833:         $destination =~ s/(\?.*)$//;
 2834:         if (exists($reqprivs->{$destination})) {
 2835:             if ($reqprivs->{$destination} =~ /,/) {
 2836:                 @{$privref} = split(/,/,$reqprivs->{$destination});
 2837:             } else { 
 2838:                 $privref = [$reqprivs->{$destination}];
 2839:             }
 2840:         }
 2841:     }
 2842:     if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
 2843:         my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
 2844:         if ((($start) && ($start<0)) || 
 2845:             (($end) && ($end<$now))  ||
 2846:             (($start) && ($now<$start))) {
 2847:             $is_cc = 0;
 2848:         } else {
 2849:             $is_cc = 1;
 2850:         }
 2851:     }
 2852:     if ($is_cc) {
 2853:         &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs);
 2854:     } elsif ($env{'request.role'} =~ m{^\Qcr/$cdom/$cdom-domainconfig/\E(\w+)\.\Q/$cdom/$cnum\E}) {
 2855:         &get_customadhoc_roles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,\%roledesc,$privref);
 2856:     } else {
 2857:         my %gotnosection;
 2858:         foreach my $item (keys(%env)) {
 2859:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
 2860:                 my $role = $1;
 2861:                 my $sec = $2;
 2862:                 next if ($role eq 'gr');
 2863:                 my ($start,$end) = split(/\./,$env{$item});
 2864:                 next if (($start && $start > $now) || ($end && $end < $now));
 2865:                 if ($sec eq '') {
 2866:                     if (!$gotnosection{$role}) {
 2867:                         $seccount{$role} ++;
 2868:                         $gotnosection{$role} = 1;
 2869:                     }
 2870:                 }
 2871:                 if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
 2872:                     my $cnumsec = $cnum;
 2873:                     if ($sec ne '') {
 2874:                         $cnumsec .= "/$sec";
 2875:                     }
 2876:                     $courseprivs{"$role./$cdom/$cnumsec./"} =
 2877:                         $env{"user.priv.$role./$cdom/$cnumsec./"};
 2878:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
 2879:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
 2880:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
 2881:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
 2882:                 }
 2883:                 if (ref($courseroles{$role}) eq 'ARRAY') {
 2884:                     if ($sec ne '') {
 2885:                         if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
 2886:                             push(@{$courseroles{$role}},$sec);
 2887:                             $seccount{$role} ++;
 2888:                         }
 2889:                     }
 2890:                 } else {
 2891:                     @{$courseroles{$role}} = ();
 2892:                     if ($sec ne '') {
 2893:                         $seccount{$role} ++;
 2894:                         push(@{$courseroles{$role}},$sec);
 2895:                     }
 2896:                 }
 2897:             }
 2898:         }
 2899:     }
 2900:     my @roles_order = ($ccrole,'in','ta','ep','ad','st');
 2901:     my $numdiffsec;
 2902:     if (keys(%seccount) == 1) {
 2903:         foreach my $key (keys(%seccount)) {
 2904:             $numdiffsec = $seccount{$key};
 2905:         }
 2906:     }
 2907:     if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
 2908:         my $targetattr;
 2909:         if ($target ne '') {
 2910:             $targetattr = ' target="'.$target.'"';
 2911:         }
 2912:         my @submenu;
 2913:         $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,
 2914:                             \%roledesc,$privref,$menucoll,$menuref);
 2915:         $form = 
 2916:             '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles"'.$targetattr.'>'."\n".
 2917:             '  <input type="hidden" name="destinationurl" value="'.
 2918:             &HTML::Entities::encode($destinationurl).'" />'."\n".
 2919:             '  <input type="hidden" name="gotorole" value="1" />'."\n".
 2920:             '  <input type="hidden" name="selectrole" value="" />'."\n".
 2921:             '  <input type="hidden" name="switchrole" value="" />'."\n";
 2922:         if ($destsymb ne '') {
 2923:             $form .= '  <input type="hidden" name="destsymb" value="'.
 2924:                         &HTML::Entities::encode($destsymb).'" />'."\n";
 2925:         }
 2926:         $form .= '</form>'."\n";
 2927:         foreach my $role (@roles_order) {
 2928:             my $include;
 2929:             if (defined($courseroles{$role})) {
 2930:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
 2931:                     if ($seccount{$role} > 1) {
 2932:                         $include = 1;
 2933:                     } else {
 2934:                         if ($env{'user.priv.'.$env{'request.role'}."./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
 2935:                             $has_opa_priv = 1;
 2936:                         }
 2937:                     }
 2938:                 } else {
 2939:                     $include = 1;
 2940:                 }
 2941:             }
 2942:             if ($include) {
 2943:                 if ($env{"user.priv.$role./$cdom/$cnum./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
 2944:                     $has_opa_priv = 1;
 2945:                 }
 2946:                 push(@submenu,['javascript:adhocRole('."'$role'".')',
 2947:                                &Apache::lonnet::plaintext($role,$crstype)]);
 2948:             }
 2949:         }
 2950:         foreach my $role (sort(keys(%courseroles))) {
 2951:             if ($role =~ /^cr/) {
 2952:                 my $include;
 2953:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
 2954:                     if ($seccount{$role} > 1) {
 2955:                         $include = 1;
 2956:                     }
 2957:                 } else {
 2958:                     $include = 1; 
 2959:                 }
 2960:                 if ($include) {
 2961:                     my $rolename;
 2962:                     if ($role =~ m{^cr/$cdom/$cdom\-domainconfig/(\w+)(?:/\w+|$)}) {
 2963:                         $rolename = $roledesc{$role};
 2964:                         if ($rolename eq '') {
 2965:                             $rolename = &mt('Helpdesk [_1]',$1);
 2966:                         }
 2967:                     } else {
 2968:                         $rolename = &Apache::lonnet::plaintext($role);
 2969:                     }
 2970:                     if ($env{"user.priv.$role./$cdom/$cnum./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
 2971:                         $has_opa_priv = 1;
 2972:                     }
 2973:                     push(@submenu,['javascript:adhocRole('."'$role'".')',
 2974:                                    $rolename]);
 2975:                 }
 2976:             }
 2977:         }
 2978:         if (@submenu > 0) {
 2979:             $switcher = &create_submenu('#',$target,&mt('Switch role'),\@submenu);
 2980:         }
 2981:     }
 2982:     return ($js,$form,$switcher,$has_opa_priv);
 2983: }
 2984: 
 2985: sub get_all_courseroles {
 2986:     my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
 2987:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
 2988:             (ref($courseprivs) eq 'HASH')) {
 2989:         return;
 2990:     }
 2991:     my ($result,$cached) = 
 2992:         &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
 2993:     if (defined($cached)) {
 2994:         if (ref($result) eq 'HASH') {
 2995:             if ((ref($result->{'roles'}) eq 'HASH') && 
 2996:                 (ref($result->{'seccount'}) eq 'HASH') && 
 2997:                 (ref($result->{'privs'}) eq 'HASH')) {
 2998:                 %{$courseroles} = %{$result->{'roles'}};
 2999:                 %{$seccount} = %{$result->{'seccount'}};
 3000:                 %{$courseprivs} = %{$result->{'privs'}};
 3001:                 return;
 3002:             }
 3003:         }
 3004:     }
 3005:     my %gotnosection;
 3006:     my %adv_roles =
 3007:          &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
 3008:     foreach my $role (keys(%adv_roles)) {
 3009:         my ($urole,$usec) = split(/:/,$role);
 3010:         if (!$gotnosection{$urole}) {
 3011:             $seccount->{$urole} ++;
 3012:             $gotnosection{$urole} = 1;
 3013:         }
 3014:         if (ref($courseroles->{$urole}) eq 'ARRAY') {
 3015:             if ($usec ne '') {
 3016:                 if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
 3017:                     push(@{$courseroles->{$urole}},$usec);
 3018:                     $seccount->{$urole} ++;
 3019:                 }
 3020:             }
 3021:         } else {
 3022:             @{$courseroles->{$urole}} = ();
 3023:             if ($usec ne '') {
 3024:                 $seccount->{$urole} ++;
 3025:                 push(@{$courseroles->{$urole}},$usec);
 3026:             }
 3027:         }
 3028:         my $area = '/'.$cdom.'/'.$cnum;
 3029:         if ($usec ne '') {
 3030:             $area .= '/'.$usec;
 3031:         }
 3032:         if ($role =~ /^cr\//) {
 3033:             &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
 3034:         } else {
 3035:             &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
 3036:         }
 3037:     }
 3038:     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
 3039:     @{$courseroles->{'st'}} = ();
 3040:     &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
 3041:     if (keys(%sections_count) > 0) {
 3042:         push(@{$courseroles->{'st'}},keys(%sections_count));
 3043:         $seccount->{'st'} = scalar(keys(%sections_count));
 3044:     }
 3045:     $seccount->{'st'} ++; # Increment for a section-less student role.  
 3046:     my $rolehash = {
 3047:                      'roles'    => $courseroles,
 3048:                      'seccount' => $seccount,
 3049:                      'privs'    => $courseprivs,
 3050:                    };
 3051:     &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
 3052:     return;
 3053: }
 3054: 
 3055: sub get_customadhoc_roles {
 3056:     my ($cdom,$cnum,$courseroles,$seccount,$courseprivs,$roledesc,$privref) = @_;
 3057:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
 3058:             (ref($courseprivs) eq 'HASH') && (ref($roledesc) eq 'HASH')) {
 3059:         return;
 3060:     }
 3061:     my $is_helpdesk = 0;
 3062:     my $now = time;
 3063:     foreach my $role ('dh','da') {
 3064:         if ($env{"user.role.$role./$cdom/"}) {
 3065:             my ($start,$end)=split(/\./,$env{"user.role.$role./$cdom/"});
 3066:             if (!($start && ($now<$start)) && !($end && ($now>$end))) {
 3067:                 $is_helpdesk = 1;
 3068:                 last;
 3069:             }
 3070:         }
 3071:     }
 3072:     if ($is_helpdesk) {
 3073:         my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum);
 3074:         my %available;
 3075:         if (ref($possroles) eq 'ARRAY') {
 3076:             map { $available{$_} = 1; } @{$possroles};
 3077:         }
 3078:         my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
 3079:         if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
 3080:             if (keys(%{$domdefaults{'adhocroles'}})) {
 3081:                 my $numsec = 1;
 3082:                 my @sections;
 3083:                 my ($allseclist,$cached) =
 3084:                     &Apache::lonnet::is_cached_new('courseseclist',$cdom.'_'.$cnum);
 3085:                 if (defined($cached)) {
 3086:                     if ($allseclist ne '') {
 3087:                         @sections = split(/,/,$allseclist);
 3088:                         $numsec += scalar(@sections);
 3089:                     }
 3090:                 } else {
 3091:                     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
 3092:                     @sections = sort(keys(%sections_count));
 3093:                     $numsec += scalar(@sections);
 3094:                     $allseclist = join(',',@sections);
 3095:                     &Apache::lonnet::do_cache_new('courseseclist',$cdom.'_'.$cnum,$allseclist);
 3096:                 }
 3097:                 my (%adhoc,$gotprivs);
 3098:                 my $prefix = "cr/$cdom/$cdom".'-domainconfig';
 3099:                 foreach my $role (keys(%{$domdefaults{'adhocroles'}})) {
 3100:                     next if (($role eq '') || ($role =~ /\W/));
 3101:                     $seccount->{"$prefix/$role"} = $numsec;
 3102:                     $roledesc->{"$prefix/$role"} = $description->{$role};
 3103:                     if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
 3104:                         if (exists($env{"user.priv.$prefix/$role./$cdom/$cnum./"})) {
 3105:                             $courseprivs->{"$prefix/$role./$cdom/$cnum./"} =
 3106:                                 $env{"user.priv.$prefix/$role./$cdom/$cnum./"};
 3107:                             $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"} =
 3108:                                 $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/"};
 3109:                             $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"} =
 3110:                                 $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/$cnum"};
 3111:                         } else {
 3112:                             unless ($gotprivs) {
 3113:                                 my ($adhocroles,$privscached) =
 3114:                                     &Apache::lonnet::is_cached_new('adhocroles',$cdom);
 3115:                                 if ((defined($privscached)) && (ref($adhocroles) eq 'HASH')) {
 3116:                                     %adhoc = %{$adhocroles};
 3117:                                 } else {
 3118:                                     my $confname = &Apache::lonnet::get_domainconfiguser($cdom);
 3119:                                     my %roledefs = &Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
 3120:                                     foreach my $key (keys(%roledefs)) {
 3121:                                         (undef,my $rolename) = split(/_/,$key);
 3122:                                         if ($rolename ne '') {
 3123:                                             my ($systempriv,$domainpriv,$coursepriv) = split(/\_/,$roledefs{$key});
 3124:                                             $coursepriv = &Apache::lonnet::course_adhocrole_privs($rolename,$cdom,$cnum,$coursepriv);
 3125:                                             $adhoc{$rolename} = join('_',($systempriv,$domainpriv,$coursepriv));
 3126:                                         }
 3127:                                     }
 3128:                                     &Apache::lonnet::do_cache_new('adhocroles',$cdom,\%adhoc);
 3129:                                 }
 3130:                                 $gotprivs = 1;
 3131:                             }
 3132:                             ($courseprivs->{"$prefix/$role./$cdom/$cnum./"},
 3133:                              $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"},
 3134:                              $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"}) =
 3135:                                  split(/\_/,$adhoc{$role});
 3136:                         }
 3137:                     }
 3138:                     if ($available{$role}) {
 3139:                         $courseroles->{"$prefix/$role"} = \@sections;
 3140:                     }
 3141:                 }
 3142:             }
 3143:         }
 3144:     }
 3145:     return;
 3146: }
 3147: 
 3148: sub jump_to_role {
 3149:     my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$roledesc,$privref,
 3150:         $menucoll,$menuref) = @_;
 3151:     my %lt = &Apache::lonlocal::texthash(
 3152:                 this => 'This role has section(s) associated with it.',
 3153:                 ente => 'Enter a specific section.',
 3154:                 orlb => 'Enter a specific section, or leave blank for no section.',
 3155:                 avai => 'Available sections are:',
 3156:                 youe => 'You entered an invalid section choice:',
 3157:                 plst => 'Please try again.',
 3158:                 role => 'The role you selected is not permitted to view the current page.',
 3159:                 swit => 'Switch role, but display Main Menu page instead?',
 3160:     );
 3161:     &js_escape(\%lt);
 3162:     my $js;
 3163:     if (ref($courseroles) eq 'HASH') {
 3164:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
 3165:               '    var numsec = new Array();'."\n".
 3166:               '    var rolesections = new Array();'."\n".
 3167:               '    var rolenames = new Array();'."\n".
 3168:               '    var roleseclist = new Array();'."\n";
 3169:         my @items = keys(%{$courseroles});
 3170:         for (my $i=0; $i<@items; $i++) {
 3171:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
 3172:             my ($secs,$secstr);
 3173:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
 3174:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
 3175:                 $secs = join('","',@sections);
 3176:                 $secstr = join(', ',@sections);
 3177:             }
 3178:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
 3179:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
 3180:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
 3181:         }
 3182:     }
 3183:     my $checkroles = 0;
 3184:     my $fallback = '/adm/menu';
 3185:     my $displaymsg = $lt{'swit'};
 3186:     if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0) && (ref($courseprivs) eq 'HASH')) {
 3187:         my %disallowed;
 3188:         foreach my $role (sort(keys(%{$courseprivs}))) {
 3189:             my $trole;
 3190:             if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
 3191:                 $trole = $1;
 3192:             }
 3193:             if (($trole ne '') && ($trole ne 'cm')) {
 3194:                 $disallowed{$trole} = 1;
 3195:                 foreach my $priv (@{$privref}) { 
 3196:                     if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
 3197:                         delete($disallowed{$trole});
 3198:                         last;
 3199:                     }
 3200:                 }
 3201:             }
 3202:         }
 3203:         if (keys(%disallowed) > 0) {
 3204:             $checkroles = 1;
 3205:             $js .= "    var disallow = new Array('".join("','",keys(%disallowed))."');\n".
 3206:                    "    var rolecheck = 1;\n";
 3207:             if ($menucoll) {
 3208:                 if (ref($menuref) eq 'HASH') {
 3209:                     if ($menuref->{'main'} eq 'n') {
 3210:                         $fallback = '/adm/navmaps';
 3211:                         if (&Apache::loncommon::course_type() eq 'Community') {
 3212:                             $displaymsg = &mt('Switch role, but display Community Contents page instead?');
 3213:                         } else {
 3214:                             $displaymsg = &mt('Switch role, but display Course Contents page instead?');
 3215:                         }
 3216:                         &js_escape(\$displaymsg);
 3217:                     }
 3218:                 }
 3219:             }
 3220:         }
 3221:     }
 3222:     &js_escape(\$fallback);
 3223:     if (!$checkroles) {
 3224:         $js .=  "    var disallow = new Array();\n".
 3225:                 "    rolecheck = 0;\n";
 3226:     }
 3227:     return <<"END";
 3228: <script type="text/javascript">
 3229: //<![CDATA[
 3230: function adhocRole(newrole) {
 3231:     $js
 3232:     if (newrole == '') {
 3233:         return;
 3234:     } 
 3235:     var fullrole = newrole+'./$cdom/$cnum';
 3236:     var selidx = '';
 3237:     for (var i=0; i<rolenames.length; i++) {
 3238:         if (rolenames[i] == newrole) {
 3239:             selidx = i;
 3240:         }
 3241:     }
 3242:     if (rolecheck > 0) {
 3243:         for (var i=0; i<disallow.length; i++) {
 3244:             if (disallow[i] == newrole) {
 3245:                 if (confirm("$lt{'role'}\\n$displaymsg")) {
 3246:                     document.rolechooser.destinationurl.value = '$fallback';
 3247:                 } else {
 3248:                     return;
 3249:                 }
 3250:             }
 3251:         }
 3252:     }
 3253:     var secok = 1;
 3254:     var secchoice = '';
 3255:     if (selidx >= 0) {
 3256:         if (numsec[selidx] > 1) {
 3257:             secok = 0;
 3258:             var numrolesec = rolesections[selidx].length;
 3259:             var msgidx = numsec[selidx] - numrolesec;
 3260:             secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
 3261:             if (secchoice == '') {
 3262:                 if (msgidx > 0) {
 3263:                     secok = 1;
 3264:                 }
 3265:             } else {
 3266:                 for (var j=0; j<rolesections[selidx].length; j++) {
 3267:                     if (rolesections[selidx][j] == secchoice) {
 3268:                         secok = 1;
 3269:                     }
 3270:                 }
 3271:             }
 3272:         } else {
 3273:             if (rolesections[selidx].length == 1) {
 3274:                 secchoice = rolesections[selidx][0];
 3275:             }
 3276:         }
 3277:     }
 3278:     if (secok == 1) {
 3279:         if (secchoice != '') {
 3280:             fullrole += '/'+secchoice;
 3281:         }
 3282:     } else {
 3283:         if (secchoice != null) {
 3284:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
 3285:         }
 3286:         return;
 3287:     }
 3288:     if (fullrole == "$env{'request.role'}") {
 3289:         return;
 3290:     }
 3291:     itemid = retrieveIndex('gotorole');
 3292:     if (itemid != -1) {
 3293:         document.rolechooser.elements[itemid].name = fullrole;
 3294:     }
 3295:     document.rolechooser.switchrole.value = fullrole;
 3296:     document.rolechooser.selectrole.value = '1';
 3297:     document.rolechooser.submit();
 3298:     return;
 3299: }
 3300: 
 3301: function retrieveIndex(item) {
 3302:     for (var i=0;i<document.rolechooser.elements.length;i++) {
 3303:         if (document.rolechooser.elements[i].name == item) {
 3304:             return i;
 3305:         }
 3306:     }
 3307:     return -1;
 3308: }
 3309: // ]]>
 3310: </script>
 3311: END
 3312: }
 3313: 
 3314: sub required_privs {
 3315:     my $privs =  {
 3316:              '/adm/parmset'      => 'opa,vpa',
 3317:              '/adm/courseprefs'  => 'opa,vpa',
 3318:              '/adm/whatsnew'     => 'whn',
 3319:              '/adm/populate'     => 'cst,vpa,vcl',
 3320:              '/adm/trackstudent' => 'vsa',
 3321:              '/adm/statistics'   => 'mgr,vgr',
 3322:              '/adm/setblock'     => 'dcm,vcb',
 3323:              '/adm/coursedocs'   => 'mdc',
 3324:            };
 3325:     unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
 3326:         $privs->{'/adm/classcalc'}   = 'vgr',
 3327:         $privs->{'/adm/assesscalc'}  = 'vgr',
 3328:         $privs->{'/adm/studentcalc'} = 'vgr';
 3329:     }
 3330:     return $privs;
 3331: }
 3332: 
 3333: sub countdown_timer {
 3334:     if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
 3335:         (($env{'request.filename'}=~/$LONCAPA::assess_re/) ||
 3336:          (($env{'request.symb'} =~ /ext\.tool$/) &&
 3337:          (&Apache::lonnet::EXT('resource.0.gradable',$env{'request.symb'}) =~ /^yes$/i)))) {
 3338:         my ($type,$hastimeleft,$slothastime);
 3339:         my $now = time;
 3340:         if ($env{'request.filename'} =~ /\.task$/) {
 3341:             $type = 'Task';
 3342:         } elsif ($env{'request.symb'} =~ /ext\.tool$/) {
 3343:             $type = 'tool';
 3344:         } else {
 3345:             $type = 'problem';
 3346:         }
 3347:         my ($status,$accessmsg,$slot_name,$slot);
 3348:         if ($type eq 'tool') {
 3349:             ($status,$accessmsg,$slot_name,$slot) =
 3350:                 &Apache::lonhomework::check_slot_access('0',$type,$env{'request.symb'},['0']);
 3351:         } else {
 3352:             ($status,$accessmsg,$slot_name,$slot) =
 3353:                 &Apache::lonhomework::check_slot_access('0',$type);
 3354:         }
 3355:         if ($slot_name ne '') {
 3356:             if (ref($slot) eq 'HASH') {
 3357:                 if (($slot->{'starttime'} < $now) &&
 3358:                     ($slot->{'endtime'} > $now)) {
 3359:                     $slothastime = 1;
 3360:                 }
 3361:             }
 3362:         }
 3363:         if ($status ne 'CAN_ANSWER') {
 3364:             return;
 3365:         }
 3366:         my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
 3367:         my @interval=&Apache::lonnet::EXT("resource.0.interval");
 3368:         my ($timelimit,$usesdone,$donebuttontext,$proctor,$secret);
 3369:         if (@interval > 1) {
 3370:             ($timelimit,my $donesuffix) = split(/_/,$interval[0],2);
 3371:             if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) {
 3372:                 $usesdone = 'done';
 3373:                 $donebuttontext = $1;
 3374:                 (undef,$proctor,$secret) = split(/_/,$2);
 3375:             } elsif ($donesuffix =~ /^done(|_.+)$/) {
 3376:                 $donebuttontext = &mt('Done');
 3377:                 ($usesdone,$proctor,$secret) = split(/_/,$donesuffix);
 3378:             }
 3379:             my $first_access=&Apache::lonnet::get_first_access($interval[1]);
 3380:             if ($first_access > 0) {
 3381:                 if ($first_access+$timelimit > time) {
 3382:                     $hastimeleft = 1;
 3383:                 }
 3384:             }
 3385:         }
 3386:         if (($duedate && $duedate > time) ||
 3387:             (!$duedate && $hastimeleft) ||
 3388:             ($slot_name ne '' && $slothastime)) {
 3389:             my ($collapse,$expand,$alttxt,$title,$currdisp,$donebutton);
 3390:             if ((@interval > 1 && $hastimeleft) ||
 3391:                 ($type eq 'Task' && $slothastime)) {
 3392:                 $currdisp = 'inline';
 3393:                 $collapse = '&#9658;&nbsp;';
 3394:                 if ((@interval > 1) && ($hastimeleft)) {
 3395:                     if ($usesdone eq 'done') {
 3396:                         $donebutton = &done_button_js($interval[1],'','',$proctor,$donebuttontext);
 3397:                     }
 3398:                 }
 3399:             } else {
 3400:                 $currdisp = 'none';
 3401:                 $expand = '&#9668;&nbsp;';
 3402:             }
 3403:             unless ($env{'environment.icons'} eq 'iconsonly') {
 3404:                 $alttxt = &mt('Timer');
 3405:                 $title = $alttxt.'&nbsp;';
 3406:             }
 3407:             my $desc = &mt('Countdown to due date/time');
 3408: 
 3409:             return <<END;
 3410: $donebutton
 3411: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
 3412: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
 3413: $collapse
 3414: </span></a>
 3415: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
 3416: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
 3417: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
 3418: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
 3419: END
 3420:         }
 3421:     }
 3422:     return;
 3423: }
 3424: 
 3425: sub placement_progress {
 3426:     my ($totalpoints,$incomplete) = &Apache::lonplacementtest::check_completion(undef,undef,1);
 3427:     my $complete = 100 - $incomplete;
 3428:     return '<span class="LC_placement_prog">'.
 3429:            &mt('Test is [_1]% complete',$complete).'</span>';
 3430: }
 3431: 
 3432: sub linkprot_exit {
 3433:     if (($env{'request.course.id'}) && ($env{'request.deeplink.login'})) {
 3434:         my ($deeplink_symb,$deeplink);
 3435:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 3436:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 3437:         if (($cnum ne '') && ($cdom ne '')) {
 3438:             $deeplink_symb = &Apache::loncommon::deeplink_login_symb($cnum,$cdom);
 3439:             if ($deeplink_symb) {
 3440:                 if ($deeplink_symb =~ /\.(page|sequence)$/) {
 3441:                     my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
 3442:                     my $navmap = Apache::lonnavmaps::navmap->new();
 3443:                     if (ref($navmap)) {
 3444:                         $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
 3445:                     }
 3446:                 } else {
 3447:                     $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
 3448:                 }
 3449:                 if ($deeplink ne '') {
 3450:                     my ($state,$others,$listed,$scope,$protect,$display,$target,$exit) = split(/,/,$deeplink);
 3451:                     my %lt = &Apache::lonlocal::texthash(
 3452:                         title    => 'Exit Tool',
 3453:                         okdone   => 'Click "OK" to exit embedded tool',
 3454:                         cancel   => 'Click "Cancel" to continue working.',
 3455:                         ok       => 'OK',
 3456:                         exit     => 'Cancel',
 3457:                     );
 3458:                     if ($exit) {
 3459:                         my ($show,$text) = split(/:/,$exit);
 3460:                         unless ($show eq 'no') { 
 3461:                             my $height = 250;
 3462:                             my $width = 300;
 3463:                             my $exitbuttontext;
 3464:                             if ($text eq '') { 
 3465:                                 $exitbuttontext = &mt('Exit Tool');
 3466:                             } else {
 3467:                                 $exitbuttontext = $text;
 3468:                             }
 3469:                             return <<END;
 3470: <form method="post" name="LCexitButton" action="/adm/linkexit">
 3471:     <input type="hidden" name="LC_deeplink_exit" value="" />
 3472:     <button id="LC_exit-confirm-opener" type="button">$exitbuttontext</button>
 3473: </form>
 3474: 
 3475: <div id="LC_exit-confirm" title="$lt{'title'}">
 3476:     <p>$lt{'okdone'} $lt{'cancel'}</p>
 3477: </div>
 3478: 
 3479: <script type="text/javascript">
 3480: // <![CDATA[
 3481: \$( "#LC_exit-confirm" ).dialog({ autoOpen: false });
 3482: \$( "#LC_exit-confirm-opener" ).click(function() {
 3483:     \$( "#LC_exit-confirm" ).dialog( "open" );
 3484:     \$( "#LC_exit-confirm" ).dialog({
 3485:       resizable: false,
 3486:       height: $height,
 3487:       width: $width,
 3488:       modal: true,
 3489:       buttons: [
 3490:                  {
 3491:                     text: "$lt{'ok'}",
 3492:                     click: function() {
 3493:                         \$( this ).dialog( "close" );
 3494:                         \$( '[name="LC_deeplink_exit"]' )[0].value = 'true';
 3495:                         \$( '[name="LCexitButton"]' )[0].submit();
 3496:                     },
 3497:                  },
 3498:                  {
 3499:                      text: "$lt{'exit'}",
 3500:                      click: function() {
 3501:                          \$( this ).dialog( "close" );
 3502:                      },
 3503:                   },
 3504:                ],
 3505:        });
 3506: });
 3507: // ]]>
 3508: </script>
 3509: 
 3510: END
 3511:                         }
 3512:                     }
 3513:                 }
 3514:             }
 3515:         }
 3516:     }
 3517:     return;
 3518: }
 3519: 
 3520: # ================================================================ Main Program
 3521: 
 3522: BEGIN {
 3523:     if (! defined($readdesk)) {
 3524:         {
 3525:             my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
 3526:             if ( CORE::open( my $config,"<$tabfile") ) {
 3527:                 while (my $configline=<$config>) {
 3528:                     $configline=(split(/\#/,$configline))[0];
 3529:                     $configline=~s/^\s+//;
 3530:                     chomp($configline);
 3531:                     if ($configline=~/^cat\:/) {
 3532:                         my @entries=split(/\:/,$configline);
 3533:                         $category_positions{$entries[2]}=$entries[1];
 3534:                         $category_names{$entries[2]}=$entries[3];
 3535:                     } elsif ($configline=~/^prim\:/) {
 3536:                         my @entries = (split(/\:/, $configline))[1..7];
 3537:                         push(@primary_menu,\@entries);
 3538:                     } elsif ($configline=~/^primsub\:/) {
 3539:                         my ($parent,@entries) = (split(/\:/, $configline))[1..5];
 3540:                         push(@{$primary_submenu{$parent}},\@entries);
 3541:                     } elsif ($configline=~/^scnd\:/) {
 3542:                         my @entries = (split(/\:/, $configline))[1..6];
 3543:                         push(@secondary_menu,\@entries);
 3544:                     } elsif ($configline=~/^scndsub\:/) {
 3545:                         my ($parent,@entries) = (split(/\:/, $configline))[1..4];
 3546:                         push(@{$secondary_submenu{$parent}},\@entries);
 3547:                     } elsif ($configline) {
 3548:                         push(@desklines,$configline);
 3549:                     }
 3550:                 }
 3551:                 CORE::close($config);
 3552:             }
 3553:         }
 3554:         $readdesk='done';
 3555:     }
 3556: }
 3557: 
 3558: 1;
 3559: __END__
 3560: 

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