File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.58: download - view: text, annotated - select for diffs
Thu Sep 15 02:25:12 2016 UTC (7 years, 8 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  - Backport 1.431, 1.432.

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

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