File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.83.2.9: download - view: text, annotated - select for diffs
Sat Sep 2 15:56:34 2023 UTC (9 months ago) by raeburn
Branches: version_2_11_4_msu
Diff to branchpoint 1.369.2.83: preferred, unified
- For 2.11.4 (modified)
  Include a change in 1.484, not included in earlier 1.484 changes present
  in 1.369.2.83.2.1 and 1.369.2.83.2.8

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

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