File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.417: download - view: text, annotated - select for diffs
Wed Jul 3 16:44:20 2013 UTC (10 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Do not show "Reservation" item in secondary menu if no slots have ever
  been created in a course.

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

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