File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.40: download - view: text, annotated - select for diffs
Sun May 12 17:51:47 2013 UTC (11 years ago) by raeburn
Branches: version_2_11_X
- For 2.11
  - Changes in 1.413 omitted from earlier 1.369.2.39 backport.

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

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