File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.537: download - view: text, annotated - select for diffs
Wed Sep 27 14:07:47 2023 UTC (8 months, 1 week ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Breadcrumbs trail for Syllabus in Supplemental Content set to use Minimal
  template.

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

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