File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.84: download - view: text, annotated - select for diffs
Tue Jul 2 18:35:28 2024 UTC (3 days, 10 hours ago) by raeburn
Branches: version_2_11_X
- For 2.11
  Backport 1.523, 1.527, 1.544, 1.547, 1.548

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

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