File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.407: download - view: text, annotated - select for diffs
Thu Jan 3 20:16:22 2013 UTC (11 years, 4 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Course Requests item removed from "Personal" drop-down list, as it is
  now included in Functions menu on roles/courses page.
- Coding style $array[index] preferred to @array[index] when index is a
  single, scalar, value.

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

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