File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.437: download - view: text, annotated - select for diffs
Mon Sep 14 13:45:01 2015 UTC (8 years, 8 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6763. If interval ("Time-Limit") parameter has "_done" appended to
  the time limit in seconds, the "done" button will be displayed.

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

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