File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.416: download - view: text, annotated - select for diffs
Wed Jun 26 04:25:41 2013 UTC (10 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Scope and sanity checking.

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

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