File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.42: download - view: text, annotated - select for diffs
Sun May 26 22:42:06 2013 UTC (11 years ago) by raeburn
Branches: version_2_11_X
- For 2.11
  -Backport 1.415

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

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