File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.419: download - view: text, annotated - select for diffs
Tue Aug 13 11:26:38 2013 UTC (10 years, 9 months ago) by bisitz
Branches: MAIN
CVS tags: HEAD
Improve internationalization:
Do not translate again already translated phrases.
(incl. corrected rev. 1.286)

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

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