File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.66: download - view: text, annotated - select for diffs
Tue Nov 29 15:19:49 2016 UTC (7 years, 6 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  - Backport 1.462, 1.463

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

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