File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.501: download - view: text, annotated - select for diffs
Mon Feb 17 23:04:18 2020 UTC (4 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- "View Source" icon/link shown for section-specific roles with vxc priv.

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

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