File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.397: download - view: text, annotated - select for diffs
Thu Dec 6 21:43:27 2012 UTC (11 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Supplemental Content area can contain Syllabus and Personal Information
  (aboutme) pages.
- Provide breadcrumbs when these items are accessed via a Supplemental
  Content folder.
- Users with mdc prvilege should also receive "Edit Folder" link in Functions
  area to provide direct access to Content Editor for corresponding Supplemental
  Content folder.

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

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