File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.83.2.4: download - view: text, annotated - select for diffs
Fri Jul 8 16:08:05 2022 UTC (22 months, 3 weeks ago) by raeburn
Branches: version_2_11_4_msu
Diff to branchpoint 1.369.2.83: preferred, unified
- For 2.11.4 (modified)
  Include changes in 1.524, 1.525, 1.526

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

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