File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.467: download - view: text, annotated - select for diffs
Sat Feb 18 23:39:16 2017 UTC (7 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Append ?usehttp=1 to link to syllabus where LON-CAPA syllabus is configured
  to use external http:// URL, but LON-CAPA server uses https:// to avoid
  mixed active content issue (see also bug 6662).
- Preview of external http:// URL displayed in separate pop-up window
  instead of in modal window on https:// server.

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

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