File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.83.2.6: download - view: text, annotated - select for diffs
Sat Jan 21 21:40:54 2023 UTC (16 months, 2 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.528, 1.529

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

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