File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.427: download - view: text, annotated - select for diffs
Sat Feb 22 18:12:09 2014 UTC (10 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Consistent behavior for Content Library items on Main Menu page and
  Content Library Search page when no role selected.

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

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