File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.422: download - view: text, annotated - select for diffs
Sun Nov 24 15:32:39 2013 UTC (10 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Consistent wording style for tool tip for items on right side of inline menu
  ('my evaluation' and 'my Stored Links').
- Don't display feedback or evaluation link/icons for resource types which don't
  support them (i.e., "wrapped" items -- external resources and uploaded PDFs).

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

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