File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.423: download - view: text, annotated - select for diffs
Tue Nov 26 00:25:32 2013 UTC (10 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- generate xhtml that satisifies w3c validation in cases where there is no
  authenticated user (i.e., name of user etc. absent from left of primary menu).

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

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