File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.515: download - view: text, annotated - select for diffs
Fri May 6 19:36:09 2022 UTC (2 years ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6069

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

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