File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.62: download - view: text, annotated - select for diffs
Sat Oct 29 02:54:04 2016 UTC (7 years, 7 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  - Modify changes in rev. 1.369.2.56 backport of 1.436, so countdown timer
    is displayed in a composite page.

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

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