File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.83.2.11: download - view: text, annotated - select for diffs
Fri Oct 6 02:16:46 2023 UTC (7 months, 3 weeks ago) by raeburn
Branches: version_2_11_4_msu
Diff to branchpoint 1.369.2.83: preferred, unified
- For 2.11.4 (modified)
  Include changes in 1.536, 1.537, 1.538, 1.539, 1.540

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

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