File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.47: download - view: text, annotated - select for diffs
Sat Sep 7 21:08:58 2013 UTC (10 years, 10 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  - Backport 1.421

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

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