File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.71.4.6: download - view: text, annotated - select for diffs
Wed Feb 6 18:52:54 2019 UTC (5 years, 2 months ago) by raeburn
Branches: version_2_11_2_msu
Diff to branchpoint 1.369.2.71: preferred, unified
- For 2.11.2 (modified).
  - Include changes in 1.496

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

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